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.

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