1 #ifndef _UNUMERICALPOLYNOMIAL 2 #define _UNUMERICALPOLYNOMIAL 4 #include "../RingPolynomial/upolynomial.h" 6 #include "urationalfunction.h" 12 template<
class NumericalType>
16 std::vector<NumericalType> coef;
17 std::vector<int> degs;
19 template<
class UnivariatePolynomialOverRealField>
20 NumericalType evaluateRealPolynomial(UnivariatePolynomialOverRealField& A, NumericalType& a) {
23 out = NumericalType(A.leadingCoefficient().get_d());
24 for (
int i=A.degree().get_si()-1; i>-1; i--){
26 if (A.coefficient(i) != 0){
27 out += NumericalType(A.coefficient(i).get_d());
34 value = A.leadingCoefficient();
35 std::complex<double> out(value.realPart().get_d(),value.imaginaryPart().get_d());
36 for (
int i=A.degree().get_si()-1; i>-1; i--){
38 if (!A.coefficient(i).isZero()){
39 value = A.coefficient(i);
40 out += std::complex<double>(value.realPart().get_d(),value.imaginaryPart().get_d());
49 NumericalType value(0);
50 for (
int i=0; i<A.
degree().get_si()+1; i++) {
53 coef.push_back(value);
60 NumericalType value(0);
61 for (
int i=0; i<A.degree().get_si()+1; i++) {
62 value = A.coefficient(i).get_d();
64 coef.push_back(value);
73 NumericalType value(0);
74 for (
int i=0; i<A.degree().get_si()+1; i++) {
75 term = A.coefficient(i);
77 value = evaluateRealPolynomial<DenseUnivariateRationalPolynomial>(term,a);
78 coef.push_back(value);
87 NumericalType value(0);
88 for (
int i=0; i<A.degree().get_si()+1; i++) {
89 term = A.coefficient(i);
91 value = evaluateRealPolynomial< SparseUnivariatePolynomial<RationalNumber> >(term,a);
92 coef.push_back(value);
98 NumericalType value(0);
100 for (
int i=0; i<A.degree().get_si()+1; i++) {
101 cTemp = A.coefficient(i);
102 value = NumericalType(cTemp.realPart().get_d(),cTemp.imaginaryPart().get_d());
103 if (!(value == std::complex<double>(0))){
104 coef.push_back(value);
112 NumericalType value(0);
113 for (
int i=0; i<A.degree().get_si()+1; i++) {
114 term = A.coefficient(i);
116 value = evaluateComplexPolynomial(term,a);
117 coef.push_back(value);
124 int out(degs.back());
127 NumericalType leadingCoefficient() {
128 NumericalType out(coef.back());
131 NumericalType evaluate(
double t){
133 int d = coef.size() - 1;
134 if (d < 0) {
return out; }
135 int e = degs.at(d) - 1;
138 for (
int i = e; i > -1; --i) {
139 out *= NumericalType(t);
141 if (i == degs.at(d)) {
149 std::complex<double> evaluate(std::complex<double> t){
150 std::complex<double> out;
151 int d = coef.size() - 1;
152 if (d < 0) {
return out; }
153 int e = degs.at(d) - 1;
154 out = std::complex<double>(coef.at(d));
156 for (
int i = e; i > -1; --i) {
159 if (i == degs.at(d)) {
160 out += std::complex<double>(coef.at(d));
177 std::vector<complexMPF> coef;
178 std::vector<int> degs;
183 mpc_init2(value.c,4*prec);
186 for (
int i=0; i<A.
degree().get_si()+1; i++) {
187 mpc_set_q(value.c,A.
coefficient(i).get_mpq_t(),zero);
188 if (!(mpc_eq_zero(value.c))){
189 coef.push_back(value);
196 mpc_init2(value.c,4*prec);
199 for (
int i=0; i<A.degree().get_si()+1; i++) {
200 mpc_set_q(value.c,A.coefficient(i).get_mpq_t(),zero);
201 if (!(mpc_eq_zero(value.c))){
202 coef.push_back(value);
208 complexMPF evaluate(complexMPF t,
int prec){
210 mpc_init2(out.c,4*prec);
211 int d = coef.size() - 1;
213 int e = degs.at(d) - 1;
214 mpc_set(out.c,coef.at(d).c);
216 for (
int i = e; i > -1; --i) {
217 mpc_mul(out.c,out.c,t.c);
219 if (i == degs.at(d)) {
220 mpc_add(out.c,out.c,coef.at(d).c);
A sparsely represented univariate polynomial over an arbitrary ring.
Definition: BigPrimeField.hpp:21
An arbitrary-precision complex rational number.
Definition: ComplexRationalNumber.hpp:23
RationalNumber coefficient(int k) const
Get a coefficient of the polynomial.
Definition: urpolynomial.h:199
Integer degree() const
Get degree of the polynomial.
Definition: urpolynomial.h:149
bool isZero() const
Is zero polynomial.
Definition: urpolynomial.h:302
A univariate polynomial with RationalNumber coefficients represented densely.
Definition: urpolynomial.h:16
A univariate polynomial with multi-precision complex coefficients represented sparsely.
Definition: unumericalpolynomial.h:174
A univariate polynomial with numerical coefficients represented sparsely.
Definition: unumericalpolynomial.h:13