You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
6.8 KiB

25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
  1. // Univariate Polynomials over the integer numbers.
  2. #ifndef _CL_UNIVPOLY_INTEGER_H
  3. #define _CL_UNIVPOLY_INTEGER_H
  4. #include "cln/ring.h"
  5. #include "cln/univpoly.h"
  6. #include "cln/number.h"
  7. #include "cln/integer_class.h"
  8. #include "cln/integer_ring.h"
  9. namespace cln {
  10. // Normal univariate polynomials with stricter static typing:
  11. // `cl_I' instead of `cl_ring_element'.
  12. #ifdef notyet
  13. typedef cl_UP_specialized<cl_I> cl_UP_I;
  14. typedef cl_univpoly_specialized_ring<cl_I> cl_univpoly_integer_ring;
  15. //typedef cl_heap_univpoly_specialized_ring<cl_I> cl_heap_univpoly_integer_ring;
  16. #else
  17. class cl_heap_univpoly_integer_ring;
  18. class cl_univpoly_integer_ring : public cl_univpoly_ring {
  19. public:
  20. // Default constructor.
  21. cl_univpoly_integer_ring () : cl_univpoly_ring () {}
  22. // Copy constructor.
  23. cl_univpoly_integer_ring (const cl_univpoly_integer_ring&);
  24. // Assignment operator.
  25. cl_univpoly_integer_ring& operator= (const cl_univpoly_integer_ring&);
  26. // Automatic dereferencing.
  27. cl_heap_univpoly_integer_ring* operator-> () const
  28. { return (cl_heap_univpoly_integer_ring*)heappointer; }
  29. };
  30. // Copy constructor and assignment operator.
  31. CL_DEFINE_COPY_CONSTRUCTOR2(cl_univpoly_integer_ring,cl_univpoly_ring)
  32. CL_DEFINE_ASSIGNMENT_OPERATOR(cl_univpoly_integer_ring,cl_univpoly_integer_ring)
  33. class cl_UP_I : public cl_UP {
  34. public:
  35. const cl_univpoly_integer_ring& ring () const { return The(cl_univpoly_integer_ring)(_ring); }
  36. // Conversion.
  37. CL_DEFINE_CONVERTER(cl_ring_element)
  38. // Destructive modification.
  39. void set_coeff (uintL index, const cl_I& y);
  40. void finalize();
  41. // Evaluation.
  42. const cl_I operator() (const cl_I& y) const;
  43. public: // Ability to place an object at a given address.
  44. void* operator new (size_t size) { return malloc_hook(size); }
  45. void* operator new (size_t size, cl_UP_I* ptr) { (void)size; return ptr; }
  46. void operator delete (void* ptr) { free_hook(ptr); }
  47. };
  48. class cl_heap_univpoly_integer_ring : public cl_heap_univpoly_ring {
  49. SUBCLASS_cl_heap_univpoly_ring()
  50. // High-level operations.
  51. void fprint (std::ostream& stream, const cl_UP_I& x)
  52. {
  53. cl_heap_univpoly_ring::fprint(stream,x);
  54. }
  55. cl_boolean equal (const cl_UP_I& x, const cl_UP_I& y)
  56. {
  57. return cl_heap_univpoly_ring::equal(x,y);
  58. }
  59. const cl_UP_I zero ()
  60. {
  61. return The2(cl_UP_I)(cl_heap_univpoly_ring::zero());
  62. }
  63. cl_boolean zerop (const cl_UP_I& x)
  64. {
  65. return cl_heap_univpoly_ring::zerop(x);
  66. }
  67. const cl_UP_I plus (const cl_UP_I& x, const cl_UP_I& y)
  68. {
  69. return The2(cl_UP_I)(cl_heap_univpoly_ring::plus(x,y));
  70. }
  71. const cl_UP_I minus (const cl_UP_I& x, const cl_UP_I& y)
  72. {
  73. return The2(cl_UP_I)(cl_heap_univpoly_ring::minus(x,y));
  74. }
  75. const cl_UP_I uminus (const cl_UP_I& x)
  76. {
  77. return The2(cl_UP_I)(cl_heap_univpoly_ring::uminus(x));
  78. }
  79. const cl_UP_I one ()
  80. {
  81. return The2(cl_UP_I)(cl_heap_univpoly_ring::one());
  82. }
  83. const cl_UP_I canonhom (const cl_I& x)
  84. {
  85. return The2(cl_UP_I)(cl_heap_univpoly_ring::canonhom(x));
  86. }
  87. const cl_UP_I mul (const cl_UP_I& x, const cl_UP_I& y)
  88. {
  89. return The2(cl_UP_I)(cl_heap_univpoly_ring::mul(x,y));
  90. }
  91. const cl_UP_I square (const cl_UP_I& x)
  92. {
  93. return The2(cl_UP_I)(cl_heap_univpoly_ring::square(x));
  94. }
  95. const cl_UP_I expt_pos (const cl_UP_I& x, const cl_I& y)
  96. {
  97. return The2(cl_UP_I)(cl_heap_univpoly_ring::expt_pos(x,y));
  98. }
  99. const cl_UP_I scalmul (const cl_I& x, const cl_UP_I& y)
  100. {
  101. return The2(cl_UP_I)(cl_heap_univpoly_ring::scalmul(cl_ring_element(cl_I_ring,x),y));
  102. }
  103. sintL degree (const cl_UP_I& x)
  104. {
  105. return cl_heap_univpoly_ring::degree(x);
  106. }
  107. const cl_UP_I monomial (const cl_I& x, uintL e)
  108. {
  109. return The2(cl_UP_I)(cl_heap_univpoly_ring::monomial(cl_ring_element(cl_I_ring,x),e));
  110. }
  111. const cl_I coeff (const cl_UP_I& x, uintL index)
  112. {
  113. return The(cl_I)(cl_heap_univpoly_ring::coeff(x,index));
  114. }
  115. const cl_UP_I create (sintL deg)
  116. {
  117. return The2(cl_UP_I)(cl_heap_univpoly_ring::create(deg));
  118. }
  119. void set_coeff (cl_UP_I& x, uintL index, const cl_I& y)
  120. {
  121. cl_heap_univpoly_ring::set_coeff(x,index,cl_ring_element(cl_I_ring,y));
  122. }
  123. void finalize (cl_UP_I& x)
  124. {
  125. cl_heap_univpoly_ring::finalize(x);
  126. }
  127. const cl_I eval (const cl_UP_I& x, const cl_I& y)
  128. {
  129. return The(cl_I)(cl_heap_univpoly_ring::eval(x,cl_ring_element(cl_I_ring,y)));
  130. }
  131. private:
  132. // No need for any constructors.
  133. cl_heap_univpoly_integer_ring ();
  134. };
  135. // Lookup of polynomial rings.
  136. inline const cl_univpoly_integer_ring find_univpoly_ring (const cl_integer_ring& r)
  137. { return The(cl_univpoly_integer_ring) (find_univpoly_ring((const cl_ring&)r)); }
  138. inline const cl_univpoly_integer_ring find_univpoly_ring (const cl_integer_ring& r, const cl_symbol& varname)
  139. { return The(cl_univpoly_integer_ring) (find_univpoly_ring((const cl_ring&)r,varname)); }
  140. // Operations on polynomials.
  141. // Add.
  142. inline const cl_UP_I operator+ (const cl_UP_I& x, const cl_UP_I& y)
  143. { return x.ring()->plus(x,y); }
  144. // Negate.
  145. inline const cl_UP_I operator- (const cl_UP_I& x)
  146. { return x.ring()->uminus(x); }
  147. // Subtract.
  148. inline const cl_UP_I operator- (const cl_UP_I& x, const cl_UP_I& y)
  149. { return x.ring()->minus(x,y); }
  150. // Multiply.
  151. inline const cl_UP_I operator* (const cl_UP_I& x, const cl_UP_I& y)
  152. { return x.ring()->mul(x,y); }
  153. // Squaring.
  154. inline const cl_UP_I square (const cl_UP_I& x)
  155. { return x.ring()->square(x); }
  156. // Exponentiation x^y, where y > 0.
  157. inline const cl_UP_I expt_pos (const cl_UP_I& x, const cl_I& y)
  158. { return x.ring()->expt_pos(x,y); }
  159. // Scalar multiplication.
  160. #if 0 // less efficient
  161. inline const cl_UP_I operator* (const cl_I& x, const cl_UP_I& y)
  162. { return y.ring()->mul(y.ring()->canonhom(x),y); }
  163. inline const cl_UP_I operator* (const cl_UP_I& x, const cl_I& y)
  164. { return x.ring()->mul(x.ring()->canonhom(y),x); }
  165. #endif
  166. inline const cl_UP_I operator* (const cl_I& x, const cl_UP_I& y)
  167. { return y.ring()->scalmul(x,y); }
  168. inline const cl_UP_I operator* (const cl_UP_I& x, const cl_I& y)
  169. { return x.ring()->scalmul(y,x); }
  170. // Coefficient.
  171. inline const cl_I coeff (const cl_UP_I& x, uintL index)
  172. { return x.ring()->coeff(x,index); }
  173. // Destructive modification.
  174. inline void set_coeff (cl_UP_I& x, uintL index, const cl_I& y)
  175. { x.ring()->set_coeff(x,index,y); }
  176. inline void finalize (cl_UP_I& x)
  177. { x.ring()->finalize(x); }
  178. inline void cl_UP_I::set_coeff (uintL index, const cl_I& y)
  179. { ring()->set_coeff(*this,index,y); }
  180. inline void cl_UP_I::finalize ()
  181. { ring()->finalize(*this); }
  182. // Evaluation. (No extension of the base ring allowed here for now.)
  183. inline const cl_I cl_UP_I::operator() (const cl_I& y) const
  184. {
  185. return ring()->eval(*this,y);
  186. }
  187. // Derivative.
  188. inline const cl_UP_I deriv (const cl_UP_I& x)
  189. { return The2(cl_UP_I)(deriv((const cl_UP&)x)); }
  190. #endif
  191. CL_REQUIRE(cl_I_ring)
  192. // Returns the n-th Tchebychev polynomial (n >= 0).
  193. extern const cl_UP_I tschebychev (sintL n);
  194. // Returns the n-th Hermite polynomial (n >= 0).
  195. extern const cl_UP_I hermite (sintL n);
  196. // Returns the n-th Laguerre polynomial (n >= 0).
  197. extern const cl_UP_I laguerre (sintL n);
  198. } // namespace cln
  199. #endif /* _CL_UNIVPOLY_INTEGER_H */