Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-19 08:08:33

0001 // Univariate Polynomials over the integer numbers.
0002 
0003 #ifndef _CL_UNIVPOLY_INTEGER_H
0004 #define _CL_UNIVPOLY_INTEGER_H
0005 
0006 #include "cln/ring.h"
0007 #include "cln/univpoly.h"
0008 #include "cln/number.h"
0009 #include "cln/integer_class.h"
0010 #include "cln/integer_ring.h"
0011 
0012 namespace cln {
0013 
0014 // Normal univariate polynomials with stricter static typing:
0015 // `cl_I' instead of `cl_ring_element'.
0016 
0017 #ifdef notyet
0018 
0019 typedef cl_UP_specialized<cl_I> cl_UP_I;
0020 typedef cl_univpoly_specialized_ring<cl_I> cl_univpoly_integer_ring;
0021 //typedef cl_heap_univpoly_specialized_ring<cl_I> cl_heap_univpoly_integer_ring;
0022 
0023 #else
0024 
0025 class cl_heap_univpoly_integer_ring;
0026 
0027 class cl_univpoly_integer_ring : public cl_univpoly_ring {
0028 public:
0029     // Default constructor.
0030     cl_univpoly_integer_ring () : cl_univpoly_ring () {}
0031     // Copy constructor.
0032     cl_univpoly_integer_ring (const cl_univpoly_integer_ring&);
0033     // Assignment operator.
0034     cl_univpoly_integer_ring& operator= (const cl_univpoly_integer_ring&);
0035     // Automatic dereferencing.
0036     cl_heap_univpoly_integer_ring* operator-> () const
0037     { return (cl_heap_univpoly_integer_ring*)heappointer; }
0038 };
0039 // Copy constructor and assignment operator.
0040 CL_DEFINE_COPY_CONSTRUCTOR2(cl_univpoly_integer_ring,cl_univpoly_ring)
0041 CL_DEFINE_ASSIGNMENT_OPERATOR(cl_univpoly_integer_ring,cl_univpoly_integer_ring)
0042 
0043 class cl_UP_I : public cl_UP {
0044 public:
0045     const cl_univpoly_integer_ring& ring () const { return The(cl_univpoly_integer_ring)(_ring); }
0046     // Conversion.
0047     CL_DEFINE_CONVERTER(cl_ring_element)
0048     // Destructive modification.
0049     void set_coeff (uintL index, const cl_I& y);
0050     void finalize();
0051     // Evaluation.
0052     const cl_I operator() (const cl_I& y) const;
0053 public: // Ability to place an object at a given address.
0054     void* operator new (size_t size) { return malloc_hook(size); }
0055     void* operator new (size_t size, void* ptr) { (void)size; return ptr; }
0056     void operator delete (void* ptr) { free_hook(ptr); }
0057 };
0058 
0059 class cl_heap_univpoly_integer_ring : public cl_heap_univpoly_ring {
0060     SUBCLASS_cl_heap_univpoly_ring()
0061     // High-level operations.
0062     void fprint (std::ostream& stream, const cl_UP_I& x)
0063     {
0064         cl_heap_univpoly_ring::fprint(stream,x);
0065     }
0066     bool equal (const cl_UP_I& x, const cl_UP_I& y)
0067     {
0068         return cl_heap_univpoly_ring::equal(x,y);
0069     }
0070     const cl_UP_I zero ()
0071     {
0072         return The2(cl_UP_I)(cl_heap_univpoly_ring::zero());
0073     }
0074     bool zerop (const cl_UP_I& x)
0075     {
0076         return cl_heap_univpoly_ring::zerop(x);
0077     }
0078     const cl_UP_I plus (const cl_UP_I& x, const cl_UP_I& y)
0079     {
0080         return The2(cl_UP_I)(cl_heap_univpoly_ring::plus(x,y));
0081     }
0082     const cl_UP_I minus (const cl_UP_I& x, const cl_UP_I& y)
0083     {
0084         return The2(cl_UP_I)(cl_heap_univpoly_ring::minus(x,y));
0085     }
0086     const cl_UP_I uminus (const cl_UP_I& x)
0087     {
0088         return The2(cl_UP_I)(cl_heap_univpoly_ring::uminus(x));
0089     }
0090     const cl_UP_I one ()
0091     {
0092         return The2(cl_UP_I)(cl_heap_univpoly_ring::one());
0093     }
0094     const cl_UP_I canonhom (const cl_I& x)
0095     {
0096         return The2(cl_UP_I)(cl_heap_univpoly_ring::canonhom(x));
0097     }
0098     const cl_UP_I mul (const cl_UP_I& x, const cl_UP_I& y)
0099     {
0100         return The2(cl_UP_I)(cl_heap_univpoly_ring::mul(x,y));
0101     }
0102     const cl_UP_I square (const cl_UP_I& x)
0103     {
0104         return The2(cl_UP_I)(cl_heap_univpoly_ring::square(x));
0105     }
0106     const cl_UP_I expt_pos (const cl_UP_I& x, const cl_I& y)
0107     {
0108         return The2(cl_UP_I)(cl_heap_univpoly_ring::expt_pos(x,y));
0109     }
0110     const cl_UP_I scalmul (const cl_I& x, const cl_UP_I& y)
0111     {
0112         return The2(cl_UP_I)(cl_heap_univpoly_ring::scalmul(cl_ring_element(cl_I_ring,x),y));
0113     }
0114     sintL degree (const cl_UP_I& x)
0115     {
0116         return cl_heap_univpoly_ring::degree(x);
0117     }
0118     sintL ldegree (const cl_UP_I& x)
0119     {
0120         return cl_heap_univpoly_ring::ldegree(x);
0121     }
0122     const cl_UP_I monomial (const cl_I& x, uintL e)
0123     {
0124         return The2(cl_UP_I)(cl_heap_univpoly_ring::monomial(cl_ring_element(cl_I_ring,x),e));
0125     }
0126     const cl_I coeff (const cl_UP_I& x, uintL index)
0127     {
0128         return The(cl_I)(cl_heap_univpoly_ring::coeff(x,index));
0129     }
0130     const cl_UP_I create (sintL deg)
0131     {
0132         return The2(cl_UP_I)(cl_heap_univpoly_ring::create(deg));
0133     }
0134     void set_coeff (cl_UP_I& x, uintL index, const cl_I& y)
0135     {
0136         cl_heap_univpoly_ring::set_coeff(x,index,cl_ring_element(cl_I_ring,y));
0137     }
0138     void finalize (cl_UP_I& x)
0139     {
0140         cl_heap_univpoly_ring::finalize(x);
0141     }
0142     const cl_I eval (const cl_UP_I& x, const cl_I& y)
0143     {
0144         return The(cl_I)(cl_heap_univpoly_ring::eval(x,cl_ring_element(cl_I_ring,y)));
0145     }
0146 private:
0147     // No need for any constructors.
0148     cl_heap_univpoly_integer_ring ();
0149 };
0150 
0151 // Lookup of polynomial rings.
0152 inline const cl_univpoly_integer_ring find_univpoly_ring (const cl_integer_ring& r)
0153 { return The(cl_univpoly_integer_ring) (find_univpoly_ring((const cl_ring&)r)); }
0154 inline const cl_univpoly_integer_ring find_univpoly_ring (const cl_integer_ring& r, const cl_symbol& varname)
0155 { return The(cl_univpoly_integer_ring) (find_univpoly_ring((const cl_ring&)r,varname)); }
0156 
0157 // Operations on polynomials.
0158 
0159 // Add.
0160 inline const cl_UP_I operator+ (const cl_UP_I& x, const cl_UP_I& y)
0161     { return x.ring()->plus(x,y); }
0162 
0163 // Negate.
0164 inline const cl_UP_I operator- (const cl_UP_I& x)
0165     { return x.ring()->uminus(x); }
0166 
0167 // Subtract.
0168 inline const cl_UP_I operator- (const cl_UP_I& x, const cl_UP_I& y)
0169     { return x.ring()->minus(x,y); }
0170 
0171 // Multiply.
0172 inline const cl_UP_I operator* (const cl_UP_I& x, const cl_UP_I& y)
0173     { return x.ring()->mul(x,y); }
0174 
0175 // Squaring.
0176 inline const cl_UP_I square (const cl_UP_I& x)
0177     { return x.ring()->square(x); }
0178 
0179 // Exponentiation x^y, where y > 0.
0180 inline const cl_UP_I expt_pos (const cl_UP_I& x, const cl_I& y)
0181     { return x.ring()->expt_pos(x,y); }
0182 
0183 // Scalar multiplication.
0184 #if 0 // less efficient
0185 inline const cl_UP_I operator* (const cl_I& x, const cl_UP_I& y)
0186     { return y.ring()->mul(y.ring()->canonhom(x),y); }
0187 inline const cl_UP_I operator* (const cl_UP_I& x, const cl_I& y)
0188     { return x.ring()->mul(x.ring()->canonhom(y),x); }
0189 #endif
0190 inline const cl_UP_I operator* (const cl_I& x, const cl_UP_I& y)
0191     { return y.ring()->scalmul(x,y); }
0192 inline const cl_UP_I operator* (const cl_UP_I& x, const cl_I& y)
0193     { return x.ring()->scalmul(y,x); }
0194 
0195 // Coefficient.
0196 inline const cl_I coeff (const cl_UP_I& x, uintL index)
0197     { return x.ring()->coeff(x,index); }
0198 
0199 // Destructive modification.
0200 inline void set_coeff (cl_UP_I& x, uintL index, const cl_I& y)
0201     { x.ring()->set_coeff(x,index,y); }
0202 inline void finalize (cl_UP_I& x)
0203     { x.ring()->finalize(x); }
0204 inline void cl_UP_I::set_coeff (uintL index, const cl_I& y)
0205     { ring()->set_coeff(*this,index,y); }
0206 inline void cl_UP_I::finalize ()
0207     { ring()->finalize(*this); }
0208 
0209 // Evaluation. (No extension of the base ring allowed here for now.)
0210 inline const cl_I cl_UP_I::operator() (const cl_I& y) const
0211 {
0212     return ring()->eval(*this,y);
0213 }
0214 
0215 // Derivative.
0216 inline const cl_UP_I deriv (const cl_UP_I& x)
0217     { return The2(cl_UP_I)(deriv((const cl_UP&)x)); }
0218 
0219 #endif
0220 
0221 
0222 // Returns the n-th Tchebychev polynomial (n >= 0).
0223 extern const cl_UP_I tschebychev (sintL n);
0224 
0225 // Returns the n-th Hermite polynomial (n >= 0).
0226 extern const cl_UP_I hermite (sintL n);
0227 
0228 // Returns the n-th Laguerre polynomial (n >= 0).
0229 extern const cl_UP_I laguerre (sintL n);
0230 
0231 }  // namespace cln
0232 
0233 #endif /* _CL_UNIVPOLY_INTEGER_H */