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

Generate and return the vector of coefficients of the polynomial resulting from the subtraction of a polynomial to another polynomial of arbitrary degrees. More...

Detailed Description

Generate and return the vector of coefficients of the polynomial resulting from the subtraction of a polynomial to another polynomial of arbitrary degrees.

See the documentation of pm_polynomial for details of the implementation.

Parameters
[in]lhs: 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 left-hand-side polynomial in the subtraction, in the order of increasing power.
By definition, the degree of the lhs polynomial is size(lhs) - 1.
This means that the condition lhs(size(lhs)) /= 0. must hold.
[in]rhs: The input contiguous vector of non-zero size of the same type and kind as lhs, containing the coefficients of the right-hand-side polynomial in the subtraction, in the order of increasing power.
By definition, the degree of the rhs polynomial is size(rhs) - 1.
This means that the condition rhs(size(rhs)) /= 0. must hold.
Returns
sub : The output contiguous vector of the same type and kind as the input lhs, of size max(size(lhs), size(rhs)), containing the coefficients (in the order of increasing power) of the resulting polynomial from the subtraction of the polynomial lhs of arbitrary degree to another polynomial rhs of arbitrary degree.
By definition, the degree of the sub polynomial is size(sub) - 1.


Possible calling interfaces

sub(1 : max(size(lhs), size(rhs))) = getPolySub(lhs(:), rhs(:))
Generate and return the vector of coefficients of the polynomial resulting from the subtraction of a ...
This module contains procedures and generic interfaces for performing various mathematical operations...
Warning
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.
Note
An input empty lhs or rhs vector (of size zero) is interpreted as polynomial of degree zero with the single coefficient being 0.
This behavior is useful for flexibly inverting a polynomial division operation done via setPolyDiv.
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_SUB \
3block; \
4 TYPE(RKG), allocatable :: Lhs(:), Rhs(:), Sub(:); \
5 Lhs = LHS; \
6 Rhs = RHS; \
7 call disp%skip(); \
8 call disp%show("getPolyStr(Lhs)"); \
9 call disp%show( getPolyStr(Lhs) ); \
10 call disp%show("getPolyStr(Rhs)"); \
11 call disp%show( getPolyStr(Rhs) ); \
12 call disp%show("Sub = getPolySub(Lhs, Rhs)"); \
13 Sub = getPolySub(Lhs, Rhs); \
14 call disp%show("getPolyStr(Sub)"); \
15 call disp%show( getPolyStr(Sub) ); \
16 call disp%skip(); \
17end block;
18
19program example
20
21 use pm_kind, only: SK, IK
22 use pm_kind, only: RKG => RKS ! all processor real and complex kinds are supported.
23 use pm_io, only: display_type
24 use pm_polynomial, only: getPolySub
25 use pm_polynomial, only: getPolyStr
26
27 implicit none
28
29 integer(IK) :: lenQuo
30 type(display_type) :: disp
31 disp = display_type(file = "main.out.F90")
32
33#define LHS [real(RKG) :: ]
34#define RHS [real(RKG) :: ]
35#define TYPE real
36SET_POLY_SUB
37
38#define LHS [real(RKG) :: ]
39#define RHS [real(RKG) :: -1., +1.]
40#define TYPE real
41SET_POLY_SUB
42
43#define LHS [real(RKG) :: -1., +1.]
44#define RHS [real(RKG) :: ]
45#define TYPE real
46SET_POLY_SUB
47
48#define LHS [real(RKG) :: +1., +1.]
49#define RHS [real(RKG) :: -1., +1.]
50#define TYPE real
51SET_POLY_SUB
52
53#define LHS [real(RKG) :: 2., 3., 1.]
54#define RHS [real(RKG) :: 1., 1.]
55#define TYPE real
56SET_POLY_SUB
57
58#define LHS [real(RKG) :: -42., 0., -12., 1.]
59#define RHS [real(RKG) :: 1., -2., 1.]
60#define TYPE real
61SET_POLY_SUB
62
63#define LHS [real(RKG) :: -42., 0., -12., 1.]
64#define RHS [real(RKG) :: -2., 1.]
65#define TYPE real
66SET_POLY_SUB
67
68
69#define LHS [complex(RKG) :: ]
70#define RHS [complex(RKG) :: ]
71#define TYPE complex
72SET_POLY_SUB
73
74#define LHS [complex(RKG) :: ]
75#define RHS cmplx([real(RKG) :: -1., +1.], -[real(RKG) :: -1., +1.], RKG)
76#define TYPE complex
77SET_POLY_SUB
78
79#define LHS cmplx([real(RKG) :: -1., +1.], -[real(RKG) :: -1., +1.], RKG)
80#define RHS [complex(RKG) :: ]
81#define TYPE complex
82SET_POLY_SUB
83
84#define LHS cmplx([real(RKG) :: -4., 0., -2., 1.], -[real(RKG) :: -4., 0., -2., 1.], RKG)
85#define RHS cmplx([real(RKG) :: -3., 1.], -[real(RKG) :: -3., 1.], RKG)
86#define TYPE complex
87SET_POLY_SUB
88
89#define LHS cmplx([real(RKG) :: 2., 3., 1.], -[real(RKG) :: 2., 3., 1.], RKG)
90#define RHS cmplx([real(RKG) :: 1., 1.], -[real(RKG) :: 1., 1.], RKG)
91#define TYPE complex
92SET_POLY_SUB
93
94#define LHS cmplx([real(RKG) :: -42., 0., -12., 1.], -[real(RKG) :: -42., 0., -12., 1.], RKG)
95#define RHS cmplx([real(RKG) :: 1., -2., 1.], -[real(RKG) :: 1., -2., 1.], RKG)
96#define TYPE complex
97SET_POLY_SUB
98
99#define LHS cmplx([real(RKG) :: -42., 0., -12., 1.], -[real(RKG) :: -42., 0., -12., 1.], RKG)
100#define RHS cmplx([real(RKG) :: -2., 1.], -[real(RKG) :: -2., 1.])
101#define TYPE complex
102SET_POLY_SUB
103
104end program example
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(Lhs)
3
4getPolyStr(Rhs)
5
6Sub = getPolySub(Lhs, Rhs)
7getPolyStr(Sub)
8
9
10
11getPolyStr(Lhs)
12
13getPolyStr(Rhs)
14-1.x^0 + 1.x^1
15Sub = getPolySub(Lhs, Rhs)
16getPolyStr(Sub)
17-1.x^0 + 1.x^1
18
19
20getPolyStr(Lhs)
21-1.x^0 + 1.x^1
22getPolyStr(Rhs)
23
24Sub = getPolySub(Lhs, Rhs)
25getPolyStr(Sub)
26-1.x^0 + 1.x^1
27
28
29getPolyStr(Lhs)
301.x^0 + 1.x^1
31getPolyStr(Rhs)
32-1.x^0 + 1.x^1
33Sub = getPolySub(Lhs, Rhs)
34getPolyStr(Sub)
350.x^0 + 2.x^1
36
37
38getPolyStr(Lhs)
392.x^0 + 3.x^1 + 1.x^2
40getPolyStr(Rhs)
411.x^0 + 1.x^1
42Sub = getPolySub(Lhs, Rhs)
43getPolyStr(Sub)
443.x^0 + 4.x^1 + 1.x^2
45
46
47getPolyStr(Lhs)
48-42.x^0 + 0.x^1 - 12.x^2 + 1.x^3
49getPolyStr(Rhs)
501.x^0 - 2.x^1 + 1.x^2
51Sub = getPolySub(Lhs, Rhs)
52getPolyStr(Sub)
53-41.x^0 - 2.x^1 - 11.x^2 + 1.x^3
54
55
56getPolyStr(Lhs)
57-42.x^0 + 0.x^1 - 12.x^2 + 1.x^3
58getPolyStr(Rhs)
59-2.x^0 + 1.x^1
60Sub = getPolySub(Lhs, Rhs)
61getPolyStr(Sub)
62-44.x^0 + 1.x^1 - 12.x^2 + 1.x^3
63
64
65getPolyStr(Lhs)
66
67getPolyStr(Rhs)
68
69Sub = getPolySub(Lhs, Rhs)
70getPolyStr(Sub)
71
72
73
74getPolyStr(Lhs)
75
76getPolyStr(Rhs)
77(-1.,1.)x^0 + (1.,-1.)x^1
78Sub = getPolySub(Lhs, Rhs)
79getPolyStr(Sub)
80(-1.,1.)x^0 + (1.,-1.)x^1
81
82
83getPolyStr(Lhs)
84(-1.,1.)x^0 + (1.,-1.)x^1
85getPolyStr(Rhs)
86
87Sub = getPolySub(Lhs, Rhs)
88getPolyStr(Sub)
89(-1.,1.)x^0 + (1.,-1.)x^1
90
91
92getPolyStr(Lhs)
93(-4.,4.)x^0 + (0.,-0.)x^1 + (-2.,2.)x^2 + (1.,-1.)x^3
94getPolyStr(Rhs)
95(-3.,3.)x^0 + (1.,-1.)x^1
96Sub = getPolySub(Lhs, Rhs)
97getPolyStr(Sub)
98(-7.,7.)x^0 + (1.,-1.)x^1 + (-2.,2.)x^2 + (1.,-1.)x^3
99
100
101getPolyStr(Lhs)
102(2.,-2.)x^0 + (3.,-3.)x^1 + (1.,-1.)x^2
103getPolyStr(Rhs)
104(1.,-1.)x^0 + (1.,-1.)x^1
105Sub = getPolySub(Lhs, Rhs)
106getPolyStr(Sub)
107(3.,-3.)x^0 + (4.,-4.)x^1 + (1.,-1.)x^2
108
109
110getPolyStr(Lhs)
111(-42.,42.)x^0 + (0.,-0.)x^1 + (-12.,12.)x^2 + (1.,-1.)x^3
112getPolyStr(Rhs)
113(1.,-1.)x^0 + (-2.,2.)x^1 + (1.,-1.)x^2
114Sub = getPolySub(Lhs, Rhs)
115getPolyStr(Sub)
116(-41.,41.)x^0 + (-2.,2.)x^1 + (-11.,11.)x^2 + (1.,-1.)x^3
117
118
119getPolyStr(Lhs)
120(-42.,42.)x^0 + (0.,-0.)x^1 + (-12.,12.)x^2 + (1.,-1.)x^3
121getPolyStr(Rhs)
122(-2.,2.)x^0 + (1.,-1.)x^1
123Sub = getPolySub(Lhs, Rhs)
124getPolyStr(Sub)
125(-44.,44.)x^0 + (1.,-1.)x^1 + (-12.,12.)x^2 + (1.,-1.)x^3
126
127
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 1382 of file pm_polynomial.F90.


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