34 #include "DGtal/base/Common.h"
35 #include "DGtal/math/MPolynomial.h"
36 #include "DGtal/io/readers/MPolynomialReader.h"
40 using namespace DGtal;
49 template <
typename Ring>
54 = mmonomial<Ring>( 3, 1, 0 )
55 + mmonomial<Ring>( 1, 0, 3 )
56 + mmonomial<Ring>( 0, 3, 1 )
57 + mmonomial<Ring>( 0, 0, 3 )
58 + ((Ring)5) * mmonomial<Ring>( 0, 0, 1 );
63 durchblickC(
const double & x,
const double & y,
const double z )
65 return x*x*x*y + x*z*z*z + y*y*y*z + z*z*z + 5.0 * z;
74 unsigned int nbok = 0;
77 trace.
beginBlock (
"Testing block ... Evaluation speed of mpolynomials (naive)" );
78 trace.
info() << setprecision( 15 ) <<
"step is " << step << std::endl;
79 trace.
info() <<
"approximately " << 8.0/(step*step*step) <<
" computations." << std::endl;
82 for (
double x = -1.0; x < 1.0; x += step )
84 for (
double y = -1.0; y < 1.0; y += step )
86 for (
double z = -1.0; z < 1.0; z += step )
90 trace.
info() <<
"Total = " << total << std::endl;
93 trace.
beginBlock (
"Testing block ... Evaluation speed of mpolynomials" );
96 for (
double x = -1.0; x < 1.0; x += step )
99 for (
double y = -1.0; y < 1.0; y += step )
102 for (
double z = -1.0; z < 1.0; z += step )
106 trace.
info() <<
"Total1 = " << total1 << std::endl;
111 for (
double x = -1.0; x < 1.0; x += step )
113 for (
double y = -1.0; y < 1.0; y += step )
115 for (
double z = -1.0; z < 1.0; z += step )
119 trace.
info() <<
"Total2 = " << total2 << std::endl;
121 nbok += fabs( total1 - total ) < 1e-8 ? 1 : 0;
123 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
124 <<
"fabs( total1 - total ) < 1e-8" << std::endl;
125 nbok += fabs( total2 - total ) < 1e-8 ? 1 : 0;
127 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
128 <<
"fabs( total2 - total ) < 1e-8" << std::endl;
130 trace.
info() <<
"For information, ImaGene::Polynomial3 takes 164ms for step=0.01 and 1604ms for step = 0.005." << std::endl;
140 unsigned int nbok = 0;
149 nbok += e == 24592 ? 1 : 0;
151 trace.
info() << derivative<1>(f) << std::endl;
153 trace.
info() << g <<
" and " << h << std::endl;
154 trace.
info() << gcd<double>(g, h) << std::endl;
158 nbok += gcd<double>(g,h) == mmonomial<double>(2) ? 1 : 0;
162 trace.
info() << derivative<0>(l) << std::endl;
163 trace.
info() <<
gcd(l, derivative<0>(l)) <<
" (gcd of two previous polys is 1)" << std::endl;
164 nbok +=
gcd(l, derivative<0>(l)) == 1.0 * mmonomial<double>(0) ? 1 : 0;
166 trace.
info() <<
"Durchblick (x3y+xz3+y3z+z3+5z)= " << durchblick<double>() << std::endl;
169 + mmonomial<double>( 1, 2, 0 ) + mmonomial<double>( 4, 1, 1 );
170 std::cout <<
"Q(x,y,z)=1+xy^2+x^4yz = " << Q << std::endl;
171 std::cout <<
" degree = " << Q.
degree() << std::endl;
172 std::cout <<
" leading = " << Q.
leading() << std::endl;
173 std::cout <<
" Q[0] = " << Q[ 0 ] << std::endl;
174 std::cout <<
" Q[1] = " << Q[ 1 ] << std::endl;
175 std::cout <<
" Q[2] = " << Q[ 2 ] << std::endl;
176 std::cout <<
" Q[3] = " << Q[ 3 ] << std::endl;
177 std::cout <<
" Q[4] = " << Q[ 4 ] << std::endl;
178 std::cout <<
" dQ/dx = " << derivative<0>(Q) << std::endl;
179 std::cout <<
" dQ/dy = " << derivative<1>(Q) << std::endl;
180 std::cout <<
" dQ/dz = " << derivative<2>(Q) << std::endl;
182 P = Xe_k<3,double>( 2, 7 ) + Xe_k<3,double>( 1, 3 );
197 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: Represents a multivariate polynomial, i.e. an element of , where K is some ring or field.
const MPolyNM1 & leading() const
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
MPolynomial< 1, Ring, Alloc > gcd(const MPolynomial< 1, Ring, Alloc > &f, const MPolynomial< 1, Ring, Alloc > &g)
MPolynomial< 3, Ring, std::allocator< Ring > > durchblick()
bool testMPolynomialSpeed(double step=0.01)
double durchblickC(const double &x, const double &y, const double z)