2#define CLASSIC_Tps_CC 1
48template <
class T>
inline
54template <
class T>
inline
85 static void *
operator new(
size_t s,
size_t extra);
86 static void operator delete(
void *);
128template <
class T>
inline
134template <
class T>
inline
136 return ::operator
new(s);
140template <
class T>
inline
142 delete []
reinterpret_cast<TpsRep<T>*
>(p)->dat;
143 ::operator
delete(p);
147template <
class T>
inline
166 std::fill(p->
data() + 0, p->
data() + p->
len, T(0));
171template <
class T>
inline
182 new(&p->
data()[0]) T(0);
187template <
class T>
inline
191 for(
int i = 0; i < len; ++i) {
192 new(&p->
data()[i]) T(data()[i]);
205template <
class T>
inline
212template <
class T>
inline
222 int newref = --(p->
ref);
256 rep->data()[0] = rhs;
263 rep->data()[0] = T(rhs);
288 rep->data()[0] = rhs;
302 int bot =
getSize(minOrder - 1);
304 std::copy(
rep->data() + bot,
rep->data() + top, p->
data() + bot);
317 return rep->data()[index];
324 return rep->data()[index];
343 if(index >
rep->len) {
344 throw CLRangeError(
"Tps::getCoefficients()",
"Monomial index out of range.");
347 return rep->data()[index];
354 if(order >
rep->trcOrd)
return;
356 if(order >
rep->maxOrd) {
365 rep->data()[index] = value;
375 throw SizeError(
"Tps::getCoefficients()",
376 "Inconsistent number of variables.");
389 throw SizeError(
"Tps::getCoefficients()",
390 "Inconsistent number of variables.");
400 p->
data()[var+1] = T(1);
408 monomial[var] = order;
435 std::transform(
rep->data(),
rep->data() +
rep->len, p->
data(),
447 "Number of variables inconsistent.");
455 int xyLength = std::min(xLength, yLength);
457 const T *x =
rep->data();
458 const T *y = rhs.
rep->data();
460 std::transform(x, x + xyLength, y, z, std::plus<T>());
461 std::copy(x + xyLength, x + xLength, z + xyLength);
462 std::copy(y + xyLength, y + yLength, z + xyLength);
467 rep->data()[0] += rhs[0];
470 *
this = rhs +
rep->data()[0];
482 "Number of variables inconsistent.");
490 int xyLength = std::min(xLength, yLength);
493 const T *x =
rep->data();
494 const T *y = rhs.
rep->data();
496 std::transform(x, x + xyLength, y, z, std::minus<T>());
497 std::copy(x + xyLength, x + xLength, z + xyLength);
498 std::transform(y + xyLength, y + yLength, z + xyLength,
504 rep->data()[0] -= rhs[0];
507 *
this = - rhs +
rep->data()[0];
528 rep->data()[0] += rhs;
536 rep->data()[0] -= rhs;
545 std::transform(x, x +
rep->len, x, std::bind(std::multiplies<T>(), std::placeholders::_1, rhs));
552 if(rhs == T(0))
throw DivideError(
"Tps::operator/()");
554 std::transform(x, x +
rep->len, x, std::bind(std::divides<T>(), std::placeholders::_1, rhs));
569 int xyLength =
getSize(std::min(xOrder, yOrder));
570 const T *x =
rep->data();
571 const T *y = rhs.
rep->data();
573 for(
int i = 0; i < xyLength; i++) {
574 if(x[i] != y[i])
return false;
577 for(
int i = xyLength; i < xLength; i++) {
578 if(x[i] != T(0))
return false;
581 for(
int i = xyLength; i < yLength; i++) {
582 if(y[i] != T(0))
return false;
596 return rep->data()[0] == rhs.
rep->data()[0];
604 const T *x =
rep->data();
606 if(x[0] != rhs)
return false;
608 for(
int i = 1; i <
getSize(); ++i) {
609 if(x[i] != T(0))
return false;
618 return !(*
this == rhs);
624 return !(*
this == rhs);
634 throw SizeError(
"Tps::substitute()",
"Matrix not consistent with Tps.");
636 int nRow = M.
nrows();
637 int nCol = M.
ncols();
642 for(
int i = 0; i < nRow; ++i) {
644 for(
int j = 0; j < nCol; ++j) y[i][j+1] = M[i][j];
648 const T *x =
rep->data();
654 product[0] =
Tps<T>(T(1));
656 for(
int next = 1; next < table.
size();) {
660 next = (s.
order < maxOrd) ? next + 1 : s.
skip;
676 throw SizeError(
"Tps::substitute()",
"VpsMap is inconsistent with Tps.");
679 const T *x =
rep->data();
685 product[0] =
Tps<T>(T(1));
688 for(
int next = 1; next < table.
size();) {
692 next = (s.
order < maxOrd) ? next + 1 : s.
skip;
705 throw SizeError(
"Tps::evaluate()",
"Vector is inconsistent with Tps.");
708 const T *x =
rep->data();
716 for(
int next = 1; next < table.
size();) {
720 next = (s.
order < maxOrd) ? next + 1 : s.
skip;
737 is.flags(std::ios::skipws);
740 if(strcmp(head,
"Tps") != 0) {
741 throw FormatError(
"Tps::get()",
"Flag word \"Tps\" missing.");
768 for(
int var = 0; var < nVar; var++) {
772 if(p < 0) done =
true;
774 order += monomial[var];
778 if(fail)
throw FormatError(
"Tps::get()",
"File read error");
783 }
else if(index == 0) {
800 std::streamsize old_prec = os.precision(14);
801 os.setf(std::ios::scientific, std::ios::floatfield);
805 << nVar << std::endl;
808 os << std::setw(24) <<
rep->data()[0] << std::endl;
810 for(
int i = 0; i <
getSize(); ++i) {
811 if(
rep->data()[i] != T(0)) {
812 os << std::setw(24) <<
rep->data()[i];
814 for(
int var = 0; var < nVar; var++) {
822 os << std::setw(24) << T(0);
824 for(
int var = 0; var < nVar; var++) {
825 os << std::setw(3) << (-1);
831 os.precision(old_prec);
832 os.setf(std::ios::fixed, std::ios::floatfield);
845 "Number of variables inconsistent.");
850 if(rhs[0] == 0.0) ++cut;
851 trunc = std::min(trunc, cut);
856 if((*
this)[0] == 0.0) ++cut;
857 trunc = std::min(trunc, cut);
863 const T *x =
rep->data();
868 for(
int yOrd = 0; yOrd <= yHig; yOrd++) {
873 for(
int yInd = yBot; yInd < yTop; yInd++) {
874 T y = rhs.
rep->data()[yInd];
876 const int *
prod =
rep->help->getProductArray(yInd);
878 for(
int xInd = 0; xInd < xTop; xInd++) {
879 z[
prod[xInd]] += x[xInd] * y;
891 const T *x =
rep->data();
892 const T y = rhs.
rep->data()[0];
893 T *z = result.
rep->data();
894 std::transform(x, x +
rep->len, z,
895 std::bind(std::multiplies<T>(), std::placeholders::_1, y));
901 const T x =
rep->data()[0];
902 const T *y = rhs.
rep->data();
903 T *z = result.
rep->data();
904 std::transform(y, y +
rep->len, z,
905 std::bind(std::multiplies<T>(), std::placeholders::_1, x));
913 T aZero =
rep->data()[0];
914 if(aZero == T(0))
throw DivideError(
"Tps::inverse()");
917 return Tps<T>(T(1) / aZero);
920 T *series =
new T[cut+1];
921 series[0] = T(1) / aZero;
923 for(
int i = 1; i <= cut; i++) {
924 series[i] = - series[i-1] / aZero;
941 const T *x =
rep->data();
944 const int *product =
rep->help->getProductArray(var + 1);
946 for(
int i =
getSize(maxOrder); i-- > 0;) {
963 throw LogicalError(
"TpsRep::integral()",
"Cannot integrate a constant.");
967 int maxO = std::min(
rep->maxOrd + 1, trcO);
970 const T *x =
rep->data();
972 const int *product =
rep->help->getProductArray(var + 1);
974 for(
int i =
getSize(maxO - 1); i-- > 0;) {
987 "Cannot multiply a constant by a numbered variable.");
991 int maxO = std::min(
rep->maxOrd + 1, trcO);
994 const T *x =
rep->data();
996 const int *product =
rep->help->getProductArray(var + 1);
998 for(
int i =
getSize(maxO - 1); i-- > 0;) {
999 z[product[i]] = x[i];
1012 throw SizeError(
"TpsRep::scaleMonomials()",
1013 "Number of variables inconsistent.");
1020 const T *x =
rep->data();
1021 const T *y = rhs.
rep->data();
1023 std::transform(x, x + p->
len, y, z, std::multiplies<T>());
1031 return Tps<T>(series[0]);
1036 for(
int maxOrder = 1; maxOrder <= order; maxOrder++) {
1038 z[0] = series[order-maxOrder];
1059 return (
rep->help != 0) ?
rep->help->getVariables() : 0;
1071 return rep->help == 0;
1089 if(
rep->help == 0) {
1091 "Cannot get exponents of a constant.");
1094 return rep->help->getExponents(index);
1100 return rep->help ?
rep->help->getOrder(index) : 0;
1106 return rep->help ?
rep->help->getSize(order) : 1;
1110template <
class T>
inline
T::PETE_Expr_t::PETE_Return_t prod(const PETE_Expr< T > &expr)
int size() const
Get array size.
int nrows() const
Get number of rows.
int ncols() const
Get number of columns.
int getVariables() const
Get number of variables.
Tps< T > & operator=(const Tps< T > &y)
std::ostream & put(std::ostream &os) const
Put Tps to the stream is.
Tps< T > multiply(const Tps< T > &y, int trunc) const
Truncated multiplication.
Tps< T > substitute(const Matrix< T > &M) const
Substitute.
int getSize() const
Get number of coefficients.
static Tps< T > makeMonomial(const TpsMonomial &m, const T &t)
Make monomial.
Tps< T > multiplyVariable(int var) const
Multiply by variable [b]var[/b].
Tps< T > integral(int var) const
Partial integral.
bool operator==(const Tps< T > &y) const
Equality operator.
const TpsMonomial & getExponents(int index) const
Get exponents.
static int getGlobalTruncOrder()
Get global truncation order.
Tps< T > truncate(int trunc)
Truncate.
Tps< T > & operator+=(const Tps< T > &y)
Add and assign.
Tps< T > inverse(int order=truncOrder) const
Reciprocal value.
void setCoefficient(int index, const T &value)
Set coefficient.
Tps< T > filter(int lowOrder, int highOrder) const
Extract orders.
Tps< T > derivative(int var) const
Partial derivative.
static const int EXACT
Representation of infinite precision.
const T operator[](int index) const
Get coefficient.
static void setGlobalTruncOrder(int order)
Set global truncation order.
Tps< T > operator+() const
Unary plus.
static Tps< T > makeVarPower(int nVar, int var, int power)
Make power.
Tps< T > scaleMonomials(const Tps< T > &y) const
Multiply monomial-wise.
Tps< T > Taylor(const T series[], int n) const
Taylor series.
const T getCoefficient(int index) const
Get coefficient.
T evaluate(const Vector< T > &v) const
Substitute.
bool isConstant() const
Test for constant.
static Tps< T > makeVariable(int nVar, int var)
Make variable.
Tps< T > & operator*=(const Tps< T > &y)
Multiply and assign.
Tps< T > operator-() const
Unary minus.
std::istream & get(std::istream &is)
Get Tps from the stream is.
int getTruncOrder() const
Get truncation order.
int getMaxOrder() const
Get maximal order.
int getOrder(int index) const
Get order.
Tps< T > & operator-=(const Tps< T > &y)
Subtract and assign.
bool operator!=(const Tps< T > &y) const
Inequality operator.
Tps< T > & operator/=(const Tps< T > &y)
Divide and assign.
TpsRep< T > & operator=(const TpsRep< T > &)
static TpsRep< T > * create(int maxOrder, int trcOrder, int variables)
static TpsRep< T > * zero()
static void release(TpsRep< T > *)
Truncate power series map.
Bookkeeping class for Tps<T>.
static TpsData * getTpsData(int nOrd, int nVar)
int getSize(int order) const
Exponent array for Tps<T>.
int getIndex() const
Convert.
int getVariables() const
Get variables.
int getOrder() const
Get order.
int getDimension() const
Get dimension (number of Tps<T> components).
A representation for a Taylor series in one variable,.