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

Return the vector of coefficients of the polynomial resulting from the addition of a polynomial to another polynomial of arbitrary degrees. More...

Detailed Description

Return the vector of coefficients of the polynomial resulting from the addition of a polynomial to another polynomial of arbitrary degrees.

See the documentation of pm_polynomial for details of the implementation.

Parameters
[out]add: 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 addition of the polynomial lhs of arbitrary degree to another polynomial rhs of arbitrary degree.
By definition, the degree of the add polynomial is size(add) - 1.
[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 addition, 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 addition, 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.


Possible calling interfaces

call setPolyAdd(add(1 : max(size(lhs), size(rhs))), lhs(:), rhs(:))
Return the vector of coefficients of the polynomial resulting from the addition of a polynomial to an...
This module contains procedures and generic interfaces for performing various mathematical operations...
Warning
The condition 0 < size(rhs) must hold for the corresponding input arguments.
The condition 0 < size(lhs) must hold for the corresponding input arguments.
The condition size(add) == max(size(lhs), size(rhs)) must hold for the corresponding input arguments.
The condition lhs(size(lhs)) /= 0. must hold for the corresponding input arguments.
The condition rhs(size(rhs)) /= 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
getPolyAdd
setPolyAdd
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_ADD \
3block; \
4 TYPE(RKG), allocatable :: Lhs(:), Rhs(:), Add(:); \
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("allocate(Add(1 : max(size(Lhs), size(Rhs))))"); \
13 allocate(Add(1 : max(size(Lhs), size(Rhs)))); \
14 call disp%show("call setPolyAdd(Add, Lhs, Rhs)"); \
15 call setPolyAdd(Add, Lhs, Rhs); \
16 call disp%show("getPolyStr(Add)"); \
17 call disp%show( getPolyStr(Add) ); \
18 call disp%skip(); \
19end block;
20
21program example
22
23 use pm_kind, only: SK, IK
24 use pm_kind, only: RKG => RKS ! all processor real and complex kinds are supported.
25 use pm_io, only: display_type
26 use pm_polynomial, only: setPolyAdd
27 use pm_polynomial, only: getPolyStr
28
29 implicit none
30
31 integer(IK) :: lenQuo
32 type(display_type) :: disp
33 disp = display_type(file = "main.out.F90")
34
35#define LHS [real(RKG) :: +1., +1.]
36#define RHS [real(RKG) :: -1., +1.]
37#define TYPE real
38SET_POLY_ADD
39
40#define LHS [real(RKG) :: 2., 3., 1.]
41#define RHS [real(RKG) :: 1., 1.]
42#define TYPE real
43SET_POLY_ADD
44
45#define LHS [real(RKG) :: -42., 0., -12., 1.]
46#define RHS [real(RKG) :: 1., -2., 1.]
47#define TYPE real
48SET_POLY_ADD
49
50#define LHS [real(RKG) :: -42., 0., -12., 1.]
51#define RHS [real(RKG) :: -2., 1.]
52#define TYPE real
53SET_POLY_ADD
54
55
56#define LHS cmplx([real(RKG) :: -4., 0., -2., 1.], -[real(RKG) :: -4., 0., -2., 1.], RKG)
57#define RHS cmplx([real(RKG) :: -3., 1.], -[real(RKG) :: -3., 1.], RKG)
58#define TYPE complex
59SET_POLY_ADD
60
61#define LHS cmplx([real(RKG) :: 2., 3., 1.], -[real(RKG) :: 2., 3., 1.], RKG)
62#define RHS cmplx([real(RKG) :: 1., 1.], -[real(RKG) :: 1., 1.], RKG)
63#define TYPE complex
64SET_POLY_ADD
65
66#define LHS cmplx([real(RKG) :: -42., 0., -12., 1.], -[real(RKG) :: -42., 0., -12., 1.], RKG)
67#define RHS cmplx([real(RKG) :: 1., -2., 1.], -[real(RKG) :: 1., -2., 1.], RKG)
68#define TYPE complex
69SET_POLY_ADD
70
71#define LHS cmplx([real(RKG) :: -42., 0., -12., 1.], -[real(RKG) :: -42., 0., -12., 1.], RKG)
72#define RHS cmplx([real(RKG) :: -2., 1.], -[real(RKG) :: -2., 1.])
73#define TYPE complex
74SET_POLY_ADD
75
76end 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)
31.x^0 + 1.x^1
4getPolyStr(Rhs)
5-1.x^0 + 1.x^1
6allocate(Add(1 : max(size(Lhs), size(Rhs))))
7call setPolyAdd(Add, Lhs, Rhs)
8getPolyStr(Add)
90.x^0 + 2.x^1
10
11
12getPolyStr(Lhs)
132.x^0 + 3.x^1 + 1.x^2
14getPolyStr(Rhs)
151.x^0 + 1.x^1
16allocate(Add(1 : max(size(Lhs), size(Rhs))))
17call setPolyAdd(Add, Lhs, Rhs)
18getPolyStr(Add)
193.x^0 + 4.x^1 + 1.x^2
20
21
22getPolyStr(Lhs)
23-42.x^0 + 0.x^1 - 12.x^2 + 1.x^3
24getPolyStr(Rhs)
251.x^0 - 2.x^1 + 1.x^2
26allocate(Add(1 : max(size(Lhs), size(Rhs))))
27call setPolyAdd(Add, Lhs, Rhs)
28getPolyStr(Add)
29-41.x^0 - 2.x^1 - 11.x^2 + 1.x^3
30
31
32getPolyStr(Lhs)
33-42.x^0 + 0.x^1 - 12.x^2 + 1.x^3
34getPolyStr(Rhs)
35-2.x^0 + 1.x^1
36allocate(Add(1 : max(size(Lhs), size(Rhs))))
37call setPolyAdd(Add, Lhs, Rhs)
38getPolyStr(Add)
39-44.x^0 + 1.x^1 - 12.x^2 + 1.x^3
40
41
42getPolyStr(Lhs)
43(-4.,4.)x^0 + (0.,-0.)x^1 + (-2.,2.)x^2 + (1.,-1.)x^3
44getPolyStr(Rhs)
45(-3.,3.)x^0 + (1.,-1.)x^1
46allocate(Add(1 : max(size(Lhs), size(Rhs))))
47call setPolyAdd(Add, Lhs, Rhs)
48getPolyStr(Add)
49(-7.,7.)x^0 + (1.,-1.)x^1 + (-2.,2.)x^2 + (1.,-1.)x^3
50
51
52getPolyStr(Lhs)
53(2.,-2.)x^0 + (3.,-3.)x^1 + (1.,-1.)x^2
54getPolyStr(Rhs)
55(1.,-1.)x^0 + (1.,-1.)x^1
56allocate(Add(1 : max(size(Lhs), size(Rhs))))
57call setPolyAdd(Add, Lhs, Rhs)
58getPolyStr(Add)
59(3.,-3.)x^0 + (4.,-4.)x^1 + (1.,-1.)x^2
60
61
62getPolyStr(Lhs)
63(-42.,42.)x^0 + (0.,-0.)x^1 + (-12.,12.)x^2 + (1.,-1.)x^3
64getPolyStr(Rhs)
65(1.,-1.)x^0 + (-2.,2.)x^1 + (1.,-1.)x^2
66allocate(Add(1 : max(size(Lhs), size(Rhs))))
67call setPolyAdd(Add, Lhs, Rhs)
68getPolyStr(Add)
69(-41.,41.)x^0 + (-2.,2.)x^1 + (-11.,11.)x^2 + (1.,-1.)x^3
70
71
72getPolyStr(Lhs)
73(-42.,42.)x^0 + (0.,-0.)x^1 + (-12.,12.)x^2 + (1.,-1.)x^3
74getPolyStr(Rhs)
75(-2.,2.)x^0 + (1.,-1.)x^1
76allocate(Add(1 : max(size(Lhs), size(Rhs))))
77call setPolyAdd(Add, Lhs, Rhs)
78getPolyStr(Add)
79(-44.,44.)x^0 + (1.,-1.)x^1 + (-12.,12.)x^2 + (1.,-1.)x^3
80
81
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 1179 of file pm_polynomial.F90.


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