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