1 // Univariate Polynomial operations.
9 #define CL_GV_NO_RANGECHECKS
10 #define CL_SV_NO_RANGECHECKS
11 #include "cln/univpoly.h"
17 #include "cln/output.h"
21 cl_symbol cl_univpoly_varname_key = (cl_symbol)(cl_string)"variable name";
23 // Prepare for looking into a polynomial.
24 #define DeclarePoly(type,x) \
25 const type& __tmp_##x = *(const type*) &(x).rep; \
26 const type& x = __tmp_##x;
27 #define DeclareMutablePoly(type,x) \
28 type& __tmp_##x = *(type*) &(x).rep; \
33 // Four different implementations of the polynomial operations, for efficiency:
34 #include "cl_UP_number.h" // polynomials over number rings
35 #include "cl_UP_MI.h" // polynomials over modular integer rings
36 #include "cl_UP_GF2.h" // polynomials over the modular integer ring GF(2)
37 #include "cl_UP_gen.h" // polynomials over all other rings
41 static void cl_univpoly_ring_destructor (cl_heap* pointer)
43 (*(cl_heap_univpoly_ring*)pointer).~cl_heap_univpoly_ring();
46 cl_class cl_class_univpoly_ring = {
47 cl_univpoly_ring_destructor,
48 cl_class_flags_univpoly_ring
51 cl_heap_univpoly_ring::cl_heap_univpoly_ring (const cl_ring& r, cl_univpoly_setops* setopv, cl_univpoly_addops* addopv, cl_univpoly_mulops* mulopv, cl_univpoly_modulops* modulopv, cl_univpoly_polyops* polyopv)
52 : setops (setopv), addops (addopv), mulops (mulopv), modulops (modulopv), polyops (polyopv),
55 refcount = 0; // will be incremented by the `cl_univpoly_ring' constructor
56 type = &cl_class_univpoly_ring;
60 // Create a new univariate polynomial ring.
62 cl_heap_univpoly_ring* cl_make_univpoly_ring (const cl_ring& r)
64 if (r.pointer_type()->flags & cl_class_flags_number_ring)
65 return new cl_heap_num_univpoly_ring(r);
66 else if (r.pointer_type()->flags & cl_class_flags_modint_ring) {
67 if (((cl_heap_modint_ring*)r.heappointer)->modulus == 2)
68 return new cl_heap_gf2_univpoly_ring(r);
70 return new cl_heap_modint_univpoly_ring(r);
72 return new cl_heap_gen_univpoly_ring(r);