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.

227 lines
6.8 KiB

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