ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_polynomial::setPolyDiv Interface Reference

Return the quotient and remainder of dividing a polynomial with another polynomial of arbitrary degrees. More...

Detailed Description

Return the quotient and remainder of dividing a polynomial with another polynomial of arbitrary degrees.

See the documentation of pm_polynomial for details of the implementation.

Parameters
[in]dividend: The input contiguous vector of non-zero size of,
  • type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128), or
  • type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
containing the coefficients of the dividend polynomial in the order of increasing power.
By definition, the degree of the dividend polynomial is size(dividend) - 1.
This means that the condition dividend(size(dividend)) /= 0. must hold.
[in]divisor: The input contiguous vector of non-zero size of the same type and kind as dividend, containing the coefficients of the divisor polynomial in the order of increasing power.
By definition, the degree of the divisor polynomial is size(divisor) - 1.
This means that the condition divisor(size(divisor)) /= 0. must hold.
[out]quorem: The output contiguous vector of the same type, kind and size as the input dividend, containing the coefficients of the quotient and remainder polynomials resulting of the polynomial division.
The slice quorem(1 : lenQuo) contains the coefficients of the resulting quotient polynomial, in the order of increasing power.
The slice quorem(lenQuo + 1 :) contains the coefficients of the resulting remainder polynomial, in the order of increasing power.
[out]lenQuo: The output scalar integer of default kind IK containing the length of the vector of coefficients of the resulting quotient.
By definition,
  • If the condition dividend == divisor holds, then lenQuo = size(dividend).
  • If the condition size(dividend) < size(divisor) holds, then lenQuo = 0_IK.
  • If the condition lenQuo == size(dividend) holds, then the remainder of the division is zero, as implied by the empty slice quorem(lenQuo + 1 : size(dividend)).


Possible calling interfaces

call setPolyDiv(dividend(:), divisor(:), quorem(1:size(dividend)), lenQuo)
Return the quotient and remainder of dividing a polynomial with another polynomial of arbitrary degre...
This module contains procedures and generic interfaces for performing various mathematical operations...
Warning
The condition 0 < size(divisor) must hold for the corresponding input arguments.
The condition 0 < size(dividend) must hold for the corresponding input arguments.
The condition size(quorem) == size(dividend) must hold for the corresponding input arguments.
The condition dividend(size(dividend)) /= 0. must hold for the corresponding input arguments.
The condition divisor(size(divisor)) /= 0. must hold for the corresponding input arguments.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
The pure procedure(s) documented herein become impure when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1.
By default, these procedures are pure in release build and impure in debug and testing builds.
See also
getPolySub
setPolySub
getPolySub
setPolySub
setPolyDiv
getPolyMul
setPolyMul


Example usage

1! Define example template macro to avoid duplications. See the example output for actual usage.
2#define SET_POLY_DIV \
3block; \
4 TYPE(RKG), allocatable :: dividend(:), divisor(:), quorem(:); \
5 dividend = DIVIDEND; \
6 divisor = DIVISOR; \
7 call disp%skip(); \
8 call disp%show("getPolyStr(dividend)"); \
9 call disp%show( getPolyStr(dividend) ); \
10 call disp%show("getPolyStr(divisor)"); \
11 call disp%show( getPolyStr(divisor) ); \
12 call disp%show("allocate(quorem, mold = dividend)"); \
13 allocate(quorem, mold = dividend); \
14 call disp%show("call setPolyDiv(dividend, divisor, quorem, lenQuo)"); \
15 call setPolyDiv(dividend, divisor, quorem, lenQuo); \
16 call disp%show("lenQuo - 1 ! Degree of quotient."); \
17 call disp%show( lenQuo - 1 ); \
18 call disp%show("getPolyStr(quorem(1:lenQuo)) ! Quotient."); \
19 call disp%show( getPolyStr(quorem(1:lenQuo)) ); \
20 call disp%show("getPolyStr(quorem(lenQuo + 1 :)) ! Remainder."); \
21 call disp%show( getPolyStr(quorem(lenQuo + 1 :)) ); \
22 call disp%show("getPolyStr(getPolyMul(divisor, quorem(1:lenQuo))) ! Reconstruct the dividend from the divisor, Quotient, and the Remainder."); \
23 call disp%show( getPolyStr(getPolyMul(divisor, quorem(1:lenQuo))) ); \
24 call disp%show("getPolyStr(getPolyAdd(quorem(lenQuo + 1 :), getPolyMul(divisor, quorem(1:lenQuo)))) ! Reconstruct the dividend from the divisor, Quotient, and the Remainder."); \
25 call disp%show( getPolyStr(getPolyAdd(quorem(lenQuo + 1 :), getPolyMul(divisor, quorem(1:lenQuo)))) ); \
26 call disp%skip(); \
27end block;
28
29
30program example
31
32 use pm_kind, only: SK, IK
33 use pm_kind, only: RKG => RKS ! all processor real and complex kinds are supported.
34 use pm_io, only: display_type
35 use pm_polynomial, only: getPolyMul
36 use pm_polynomial, only: getPolyAdd
37 use pm_polynomial, only: setPolyDiv
38 use pm_polynomial, only: getPolyStr
39
40 implicit none
41
42 integer(IK) :: lenQuo
43 type(display_type) :: disp
44 disp = display_type(file = "main.out.F90")
45
46#define DIVIDEND [real(RKG) :: -4., 0., -2., 1.]
47#define DIVISOR [real(RKG) :: -3., 1.]
48#define TYPE real
49SET_POLY_DIV ! [3., 1., 1.], [5.]
50
51#define DIVIDEND [real(RKG) :: 2., 3., 1.]
52#define DIVISOR [real(RKG) :: 1., 1.]
53#define TYPE real
54SET_POLY_DIV
55
56#define DIVIDEND [real(RKG) :: -42., 0., -12., 1.]
57#define DIVISOR [real(RKG) :: 1., -2., 1.]
58#define TYPE real
59SET_POLY_DIV ! [-32, -21]
60
61#define DIVIDEND [real(RKG) :: -42., 0., -12., 1.]
62#define DIVISOR [real(RKG) :: -2., 1.]
63#define TYPE real
64SET_POLY_DIV
65
66#define DIVIDEND cmplx([real(RKG) :: -4., 0., -2., 1.], -[real(RKG) :: -4., 0., -2., 1.], RKG)
67#define DIVISOR cmplx([real(RKG) :: -3., 1.], -[real(RKG) :: -3., 1.], RKG)
68#define TYPE complex
69SET_POLY_DIV
70
71#define DIVIDEND cmplx([real(RKG) :: 2., 3., 1.], -[real(RKG) :: 2., 3., 1.], RKG)
72#define DIVISOR cmplx([real(RKG) :: 1., 1.], -[real(RKG) :: 1., 1.], RKG)
73#define TYPE complex
74SET_POLY_DIV
75
76#define DIVIDEND cmplx([real(RKG) :: -42., 0., -12., 1.], -[real(RKG) :: -42., 0., -12., 1.], RKG)
77#define DIVISOR cmplx([real(RKG) :: 1., -2., 1.], -[real(RKG) :: 1., -2., 1.], RKG)
78#define TYPE complex
79SET_POLY_DIV
80
81#define DIVIDEND cmplx([real(RKG) :: -42., 0., -12., 1.], -[real(RKG) :: -42., 0., -12., 1.], RKG)
82#define DIVISOR cmplx([real(RKG) :: -2., 1.], -[real(RKG) :: -2., 1.])
83#define TYPE complex
84SET_POLY_DIV
85
86end program example
Generate and return the vector of coefficients of the polynomial resulting from the addition of a pol...
Generate and return the vector of coefficients of the polynomial resulting from the multiplication of...
Generate and return a string containing the polynomial expression corresponding to the input polynomi...
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
Definition: pm_kind.F90:567
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2getPolyStr(dividend)
3-4.x^0 + 0.x^1 - 2.x^2 + 1.x^3
4getPolyStr(divisor)
5-3.x^0 + 1.x^1
6allocate(quorem, mold = dividend)
7call setPolyDiv(dividend, divisor, quorem, lenQuo)
8lenQuo - 1 ! Degree of quotient.
9+2
10getPolyStr(quorem(1:lenQuo)) ! Quotient.
113.x^0 + 1.x^1 + 1.x^2
12getPolyStr(quorem(lenQuo + 1 :)) ! Remainder.
135.x^0
14getPolyStr(getPolyMul(divisor, quorem(1:lenQuo))) ! Reconstruct the dividend from the divisor, Quotient, and the Remainder.
15-9.x^0 + 0.x^1 - 2.x^2 + 1.x^3
16getPolyStr(getPolyAdd(quorem(lenQuo + 1 :), getPolyMul(divisor, quorem(1:lenQuo)))) ! Reconstruct the dividend from the divisor, Quotient, and the Remainder.
17-4.x^0 + 0.x^1 - 2.x^2 + 1.x^3
18
19
20getPolyStr(dividend)
212.x^0 + 3.x^1 + 1.x^2
22getPolyStr(divisor)
231.x^0 + 1.x^1
24allocate(quorem, mold = dividend)
25call setPolyDiv(dividend, divisor, quorem, lenQuo)
26lenQuo - 1 ! Degree of quotient.
27+1
28getPolyStr(quorem(1:lenQuo)) ! Quotient.
292.x^0 + 1.x^1
30getPolyStr(quorem(lenQuo + 1 :)) ! Remainder.
310.x^0
32getPolyStr(getPolyMul(divisor, quorem(1:lenQuo))) ! Reconstruct the dividend from the divisor, Quotient, and the Remainder.
332.x^0 + 3.x^1 + 1.x^2
34getPolyStr(getPolyAdd(quorem(lenQuo + 1 :), getPolyMul(divisor, quorem(1:lenQuo)))) ! Reconstruct the dividend from the divisor, Quotient, and the Remainder.
352.x^0 + 3.x^1 + 1.x^2
36
37
38getPolyStr(dividend)
39-42.x^0 + 0.x^1 - 12.x^2 + 1.x^3
40getPolyStr(divisor)
411.x^0 - 2.x^1 + 1.x^2
42allocate(quorem, mold = dividend)
43call setPolyDiv(dividend, divisor, quorem, lenQuo)
44lenQuo - 1 ! Degree of quotient.
45+1
46getPolyStr(quorem(1:lenQuo)) ! Quotient.
47-10.x^0 + 1.x^1
48getPolyStr(quorem(lenQuo + 1 :)) ! Remainder.
49-32.x^0 - 21.x^1
50getPolyStr(getPolyMul(divisor, quorem(1:lenQuo))) ! Reconstruct the dividend from the divisor, Quotient, and the Remainder.
51-10.x^0 + 21.x^1 - 12.x^2 + 1.x^3
52getPolyStr(getPolyAdd(quorem(lenQuo + 1 :), getPolyMul(divisor, quorem(1:lenQuo)))) ! Reconstruct the dividend from the divisor, Quotient, and the Remainder.
53-42.x^0 + 0.x^1 - 12.x^2 + 1.x^3
54
55
56getPolyStr(dividend)
57-42.x^0 + 0.x^1 - 12.x^2 + 1.x^3
58getPolyStr(divisor)
59-2.x^0 + 1.x^1
60allocate(quorem, mold = dividend)
61call setPolyDiv(dividend, divisor, quorem, lenQuo)
62lenQuo - 1 ! Degree of quotient.
63+2
64getPolyStr(quorem(1:lenQuo)) ! Quotient.
65-20.x^0 - 10.x^1 + 1.x^2
66getPolyStr(quorem(lenQuo + 1 :)) ! Remainder.
67-82.x^0
68getPolyStr(getPolyMul(divisor, quorem(1:lenQuo))) ! Reconstruct the dividend from the divisor, Quotient, and the Remainder.
6940.x^0 + 0.x^1 - 12.x^2 + 1.x^3
70getPolyStr(getPolyAdd(quorem(lenQuo + 1 :), getPolyMul(divisor, quorem(1:lenQuo)))) ! Reconstruct the dividend from the divisor, Quotient, and the Remainder.
71-42.x^0 + 0.x^1 - 12.x^2 + 1.x^3
72
73
74getPolyStr(dividend)
75(-4.,4.)x^0 + (0.,-0.)x^1 + (-2.,2.)x^2 + (1.,-1.)x^3
76getPolyStr(divisor)
77(-3.,3.)x^0 + (1.,-1.)x^1
78allocate(quorem, mold = dividend)
79call setPolyDiv(dividend, divisor, quorem, lenQuo)
80lenQuo - 1 ! Degree of quotient.
81+2
82getPolyStr(quorem(1:lenQuo)) ! Quotient.
83(3.,0.)x^0 + (1.,0.)x^1 + (1.,0.)x^2
84getPolyStr(quorem(lenQuo + 1 :)) ! Remainder.
85(5.,0.)x^0
86getPolyStr(getPolyMul(divisor, quorem(1:lenQuo))) ! Reconstruct the dividend from the divisor, Quotient, and the Remainder.
87(-9.,9.)x^0 + (0.,0.)x^1 + (-2.,2.)x^2 + (1.,-1.)x^3
88getPolyStr(getPolyAdd(quorem(lenQuo + 1 :), getPolyMul(divisor, quorem(1:lenQuo)))) ! Reconstruct the dividend from the divisor, Quotient, and the Remainder.
89(-4.,9.)x^0 + (0.,0.)x^1 + (-2.,2.)x^2 + (1.,-1.)x^3
90
91
92getPolyStr(dividend)
93(2.,-2.)x^0 + (3.,-3.)x^1 + (1.,-1.)x^2
94getPolyStr(divisor)
95(1.,-1.)x^0 + (1.,-1.)x^1
96allocate(quorem, mold = dividend)
97call setPolyDiv(dividend, divisor, quorem, lenQuo)
98lenQuo - 1 ! Degree of quotient.
99+1
100getPolyStr(quorem(1:lenQuo)) ! Quotient.
101(2.,0.)x^0 + (1.,0.)x^1
102getPolyStr(quorem(lenQuo + 1 :)) ! Remainder.
103(0.,0.)x^0
104getPolyStr(getPolyMul(divisor, quorem(1:lenQuo))) ! Reconstruct the dividend from the divisor, Quotient, and the Remainder.
105(2.,-2.)x^0 + (3.,-3.)x^1 + (1.,-1.)x^2
106getPolyStr(getPolyAdd(quorem(lenQuo + 1 :), getPolyMul(divisor, quorem(1:lenQuo)))) ! Reconstruct the dividend from the divisor, Quotient, and the Remainder.
107(2.,-2.)x^0 + (3.,-3.)x^1 + (1.,-1.)x^2
108
109
110getPolyStr(dividend)
111(-42.,42.)x^0 + (0.,-0.)x^1 + (-12.,12.)x^2 + (1.,-1.)x^3
112getPolyStr(divisor)
113(1.,-1.)x^0 + (-2.,2.)x^1 + (1.,-1.)x^2
114allocate(quorem, mold = dividend)
115call setPolyDiv(dividend, divisor, quorem, lenQuo)
116lenQuo - 1 ! Degree of quotient.
117+1
118getPolyStr(quorem(1:lenQuo)) ! Quotient.
119(-10.,0.)x^0 + (1.,0.)x^1
120getPolyStr(quorem(lenQuo + 1 :)) ! Remainder.
121(-32.,32.)x^0 + (-21.,21.)x^1
122getPolyStr(getPolyMul(divisor, quorem(1:lenQuo))) ! Reconstruct the dividend from the divisor, Quotient, and the Remainder.
123(-10.,10.)x^0 + (21.,-21.)x^1 + (-12.,12.)x^2 + (1.,-1.)x^3
124getPolyStr(getPolyAdd(quorem(lenQuo + 1 :), getPolyMul(divisor, quorem(1:lenQuo)))) ! Reconstruct the dividend from the divisor, Quotient, and the Remainder.
125(-42.,42.)x^0 + (0.,0.)x^1 + (-12.,12.)x^2 + (1.,-1.)x^3
126
127
128getPolyStr(dividend)
129(-42.,42.)x^0 + (0.,-0.)x^1 + (-12.,12.)x^2 + (1.,-1.)x^3
130getPolyStr(divisor)
131(-2.,2.)x^0 + (1.,-1.)x^1
132allocate(quorem, mold = dividend)
133call setPolyDiv(dividend, divisor, quorem, lenQuo)
134lenQuo - 1 ! Degree of quotient.
135+2
136getPolyStr(quorem(1:lenQuo)) ! Quotient.
137(-20.,0.)x^0 + (-10.,0.)x^1 + (1.,0.)x^2
138getPolyStr(quorem(lenQuo + 1 :)) ! Remainder.
139(-82.,0.)x^0
140getPolyStr(getPolyMul(divisor, quorem(1:lenQuo))) ! Reconstruct the dividend from the divisor, Quotient, and the Remainder.
141(40.,-40.)x^0 + (0.,0.)x^1 + (-12.,12.)x^2 + (1.,-1.)x^3
142getPolyStr(getPolyAdd(quorem(lenQuo + 1 :), getPolyMul(divisor, quorem(1:lenQuo)))) ! Reconstruct the dividend from the divisor, Quotient, and the Remainder.
143(-42.,-40.)x^0 + (0.,0.)x^1 + (-12.,12.)x^2 + (1.,-1.)x^3
144
145
Test:
test_pm_polynomial


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Fatemeh Bagheri, Tuesday 11:34 PM, August 10, 2021, Dallas, TX

Definition at line 2208 of file pm_polynomial.F90.


The documentation for this interface was generated from the following file: