PageRenderTime 36ms CodeModel.GetById 16ms app.highlight 17ms RepoModel.GetById 0ms app.codeStats 0ms

/cln-1.3.2/include/cln/univpoly_complex.h

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