Return the quotient and remainder of dividing a polynomial with another polynomial of arbitrary degrees.
More...
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 ⛓
4 TYPE(RKG),
allocatable :: dividend(:), divisor(:), quorem(:); \
8 call disp
%show(
"getPolyStr(dividend)"); \
10 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."); \
24 call disp
%show(
"getPolyStr(getPolyAdd(quorem(lenQuo + 1 :), getPolyMul(divisor, quorem(1:lenQuo)))) ! Reconstruct the dividend from the divisor, Quotient, and the Remainder."); \
43 type(display_type) :: disp
46#define DIVIDEND [real(RKG) :: -4., 0., -2., 1.]
47#define DIVISOR [real(RKG) :: -3., 1.]
51#define DIVIDEND [real(RKG) :: 2., 3., 1.]
52#define DIVISOR [real(RKG) :: 1., 1.]
56#define DIVIDEND [real(RKG) :: -42., 0., -12., 1.]
57#define DIVISOR [real(RKG) :: 1., -2., 1.]
61#define DIVIDEND [real(RKG) :: -42., 0., -12., 1.]
62#define DIVISOR [real(RKG) :: -2., 1.]
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)
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)
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)
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.])
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...
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
Generate and return an object of type display_type.
Example Unix compile command via Intel ifort
compiler ⛓
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example Windows Batch compile command via Intel ifort
compiler ⛓
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
Example Unix / MinGW compile command via GNU gfortran
compiler ⛓
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example output ⛓
3-4.x^
0 + 0.x^
1 - 2.x^
2 + 1.x^
3
6allocate(quorem,
mold = dividend)
7call setPolyDiv(dividend, divisor, quorem, lenQuo)
15-9.x^
0 + 0.x^
1 - 2.x^
2 + 1.x^
3
17-4.x^
0 + 0.x^
1 - 2.x^
2 + 1.x^
3
24allocate(quorem,
mold = dividend)
25call setPolyDiv(dividend, divisor, quorem, lenQuo)
39-42.x^
0 + 0.x^
1 - 12.x^
2 + 1.x^
3
42allocate(quorem,
mold = dividend)
43call setPolyDiv(dividend, divisor, quorem, lenQuo)
51-10.x^
0 + 21.x^
1 - 12.x^
2 + 1.x^
3
53-42.x^
0 + 0.x^
1 - 12.x^
2 + 1.x^
3
57-42.x^
0 + 0.x^
1 - 12.x^
2 + 1.x^
3
60allocate(quorem,
mold = dividend)
61call setPolyDiv(dividend, divisor, quorem, lenQuo)
65-20.x^
0 - 10.x^
1 + 1.x^
2
6940.x^
0 + 0.x^
1 - 12.x^
2 + 1.x^
3
71-42.x^
0 + 0.x^
1 - 12.x^
2 + 1.x^
3
75(
-4.,
4.)x^
0 + (
0.,
-0.)x^
1 + (
-2.,
2.)x^
2 + (
1.,
-1.)x^
3
77(
-3.,
3.)x^
0 + (
1.,
-1.)x^
1
78allocate(quorem,
mold = dividend)
79call setPolyDiv(dividend, divisor, quorem, lenQuo)
83(
3.,
0.)x^
0 + (
1.,
0.)x^
1 + (
1.,
0.)x^
2
87(
-9.,
9.)x^
0 + (
0.,
0.)x^
1 + (
-2.,
2.)x^
2 + (
1.,
-1.)x^
3
89(
-4.,
9.)x^
0 + (
0.,
0.)x^
1 + (
-2.,
2.)x^
2 + (
1.,
-1.)x^
3
93(
2.,
-2.)x^
0 + (
3.,
-3.)x^
1 + (
1.,
-1.)x^
2
95(
1.,
-1.)x^
0 + (
1.,
-1.)x^
1
96allocate(quorem,
mold = dividend)
97call setPolyDiv(dividend, divisor, quorem, lenQuo)
101(
2.,
0.)x^
0 + (
1.,
0.)x^
1
105(
2.,
-2.)x^
0 + (
3.,
-3.)x^
1 + (
1.,
-1.)x^
2
107(
2.,
-2.)x^
0 + (
3.,
-3.)x^
1 + (
1.,
-1.)x^
2
111(
-42.,
42.)x^
0 + (
0.,
-0.)x^
1 + (
-12.,
12.)x^
2 + (
1.,
-1.)x^
3
113(
1.,
-1.)x^
0 + (
-2.,
2.)x^
1 + (
1.,
-1.)x^
2
114allocate(quorem,
mold = dividend)
115call setPolyDiv(dividend, divisor, quorem, lenQuo)
119(
-10.,
0.)x^
0 + (
1.,
0.)x^
1
121(
-32.,
32.)x^
0 + (
-21.,
21.)x^
1
123(
-10.,
10.)x^
0 + (
21.,
-21.)x^
1 + (
-12.,
12.)x^
2 + (
1.,
-1.)x^
3
125(
-42.,
42.)x^
0 + (
0.,
0.)x^
1 + (
-12.,
12.)x^
2 + (
1.,
-1.)x^
3
129(
-42.,
42.)x^
0 + (
0.,
-0.)x^
1 + (
-12.,
12.)x^
2 + (
1.,
-1.)x^
3
131(
-2.,
2.)x^
0 + (
1.,
-1.)x^
1
132allocate(quorem,
mold = dividend)
133call setPolyDiv(dividend, divisor, quorem, lenQuo)
137(
-20.,
0.)x^
0 + (
-10.,
0.)x^
1 + (
1.,
0.)x^
2
141(
40.,
-40.)x^
0 + (
0.,
0.)x^
1 + (
-12.,
12.)x^
2 + (
1.,
-1.)x^
3
143(
-42.,
-40.)x^
0 + (
0.,
0.)x^
1 + (
-12.,
12.)x^
2 + (
1.,
-1.)x^
3
- 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.
-
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.
-
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.
- Copyright
- Computational Data Science Lab
- Author:
- Fatemeh Bagheri, Tuesday 11:34 PM, August 10, 2021, Dallas, TX
Definition at line 2209 of file pm_polynomial.F90.