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.

235 lines
6.9 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
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, void* 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. bool 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. bool 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. sintL ldegree (const cl_UP_I& x)
  108. {
  109. return cl_heap_univpoly_ring::ldegree(x);
  110. }
  111. const cl_UP_I monomial (const cl_I& x, uintL e)
  112. {
  113. return The2(cl_UP_I)(cl_heap_univpoly_ring::monomial(cl_ring_element(cl_I_ring,x),e));
  114. }
  115. const cl_I coeff (const cl_UP_I& x, uintL index)
  116. {
  117. return The(cl_I)(cl_heap_univpoly_ring::coeff(x,index));
  118. }
  119. const cl_UP_I create (sintL deg)
  120. {
  121. return The2(cl_UP_I)(cl_heap_univpoly_ring::create(deg));
  122. }
  123. void set_coeff (cl_UP_I& x, uintL index, const cl_I& y)
  124. {
  125. cl_heap_univpoly_ring::set_coeff(x,index,cl_ring_element(cl_I_ring,y));
  126. }
  127. void finalize (cl_UP_I& x)
  128. {
  129. cl_heap_univpoly_ring::finalize(x);
  130. }
  131. const cl_I eval (const cl_UP_I& x, const cl_I& y)
  132. {
  133. return The(cl_I)(cl_heap_univpoly_ring::eval(x,cl_ring_element(cl_I_ring,y)));
  134. }
  135. private:
  136. // No need for any constructors.
  137. cl_heap_univpoly_integer_ring ();
  138. };
  139. // Lookup of polynomial rings.
  140. inline const cl_univpoly_integer_ring find_univpoly_ring (const cl_integer_ring& r)
  141. { return The(cl_univpoly_integer_ring) (find_univpoly_ring((const cl_ring&)r)); }
  142. inline const cl_univpoly_integer_ring find_univpoly_ring (const cl_integer_ring& r, const cl_symbol& varname)
  143. { return The(cl_univpoly_integer_ring) (find_univpoly_ring((const cl_ring&)r,varname)); }
  144. // Operations on polynomials.
  145. // Add.
  146. inline const cl_UP_I operator+ (const cl_UP_I& x, const cl_UP_I& y)
  147. { return x.ring()->plus(x,y); }
  148. // Negate.
  149. inline const cl_UP_I operator- (const cl_UP_I& x)
  150. { return x.ring()->uminus(x); }
  151. // Subtract.
  152. inline const cl_UP_I operator- (const cl_UP_I& x, const cl_UP_I& y)
  153. { return x.ring()->minus(x,y); }
  154. // Multiply.
  155. inline const cl_UP_I operator* (const cl_UP_I& x, const cl_UP_I& y)
  156. { return x.ring()->mul(x,y); }
  157. // Squaring.
  158. inline const cl_UP_I square (const cl_UP_I& x)
  159. { return x.ring()->square(x); }
  160. // Exponentiation x^y, where y > 0.
  161. inline const cl_UP_I expt_pos (const cl_UP_I& x, const cl_I& y)
  162. { return x.ring()->expt_pos(x,y); }
  163. // Scalar multiplication.
  164. #if 0 // less efficient
  165. inline const cl_UP_I operator* (const cl_I& x, const cl_UP_I& y)
  166. { return y.ring()->mul(y.ring()->canonhom(x),y); }
  167. inline const cl_UP_I operator* (const cl_UP_I& x, const cl_I& y)
  168. { return x.ring()->mul(x.ring()->canonhom(y),x); }
  169. #endif
  170. inline const cl_UP_I operator* (const cl_I& x, const cl_UP_I& y)
  171. { return y.ring()->scalmul(x,y); }
  172. inline const cl_UP_I operator* (const cl_UP_I& x, const cl_I& y)
  173. { return x.ring()->scalmul(y,x); }
  174. // Coefficient.
  175. inline const cl_I coeff (const cl_UP_I& x, uintL index)
  176. { return x.ring()->coeff(x,index); }
  177. // Destructive modification.
  178. inline void set_coeff (cl_UP_I& x, uintL index, const cl_I& y)
  179. { x.ring()->set_coeff(x,index,y); }
  180. inline void finalize (cl_UP_I& x)
  181. { x.ring()->finalize(x); }
  182. inline void cl_UP_I::set_coeff (uintL index, const cl_I& y)
  183. { ring()->set_coeff(*this,index,y); }
  184. inline void cl_UP_I::finalize ()
  185. { ring()->finalize(*this); }
  186. // Evaluation. (No extension of the base ring allowed here for now.)
  187. inline const cl_I cl_UP_I::operator() (const cl_I& y) const
  188. {
  189. return ring()->eval(*this,y);
  190. }
  191. // Derivative.
  192. inline const cl_UP_I deriv (const cl_UP_I& x)
  193. { return The2(cl_UP_I)(deriv((const cl_UP&)x)); }
  194. #endif
  195. CL_REQUIRE(cl_I_ring)
  196. // Returns the n-th Tchebychev polynomial (n >= 0).
  197. extern const cl_UP_I tschebychev (sintL n);
  198. // Returns the n-th Hermite polynomial (n >= 0).
  199. extern const cl_UP_I hermite (sintL n);
  200. // Returns the n-th Laguerre polynomial (n >= 0).
  201. extern const cl_UP_I laguerre (sintL n);
  202. } // namespace cln
  203. #endif /* _CL_UNIVPOLY_INTEGER_H */