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 *);
120template <
class T>
inline
126template <
class T>
inline
131 p->
dat =
new T[extra];
136template <
class T>
inline
138 delete []
reinterpret_cast<TpsRep<T>*
>(p)->dat;
139 delete []
reinterpret_cast<char *
>(p);
143template <
class T>
inline
162 std::fill(p->
data() + 0, p->
data() + p->
len, T(0));
167template <
class T>
inline
178 new(&p->
data()[0]) T(0);
183template <
class T>
inline
187 for(
int i = 0; i < len; ++i) {
188 new(&p->
data()[i]) T(data()[i]);
201template <
class T>
inline
208template <
class T>
inline
218 int newref = --(p->
ref);
220 auto* raw =
reinterpret_cast<char*
>(p);
253 rep->data()[0] = rhs;
260 rep->data()[0] = T(rhs);
285 rep->data()[0] = rhs;
299 int bot =
getSize(minOrder - 1);
301 std::copy(
rep->data() + bot,
rep->data() + top, p->
data() + bot);
314 return rep->data()[index];
321 return rep->data()[index];
340 if(index >
rep->len) {
341 throw CLRangeError(
"Tps::getCoefficients()",
"Monomial index out of range.");
344 return rep->data()[index];
351 if(order >
rep->trcOrd)
return;
353 if(order >
rep->maxOrd) {
362 rep->data()[index] = value;
372 throw SizeError(
"Tps::getCoefficients()",
373 "Inconsistent number of variables.");
386 throw SizeError(
"Tps::getCoefficients()",
387 "Inconsistent number of variables.");
397 p->
data()[var+1] = T(1);
405 monomial[var] = order;
432 std::transform(
rep->data(),
rep->data() +
rep->len, p->
data(),
444 "Number of variables inconsistent.");
452 int xyLength = std::min(xLength, yLength);
454 const T *x =
rep->data();
455 const T *y = rhs.
rep->data();
457 std::transform(x, x + xyLength, y, z, std::plus<T>());
458 std::copy(x + xyLength, x + xLength, z + xyLength);
459 std::copy(y + xyLength, y + yLength, z + xyLength);
464 rep->data()[0] += rhs[0];
467 *
this = rhs +
rep->data()[0];
479 "Number of variables inconsistent.");
487 int xyLength = std::min(xLength, yLength);
490 const T *x =
rep->data();
491 const T *y = rhs.
rep->data();
493 std::transform(x, x + xyLength, y, z, std::minus<T>());
494 std::copy(x + xyLength, x + xLength, z + xyLength);
495 std::transform(y + xyLength, y + yLength, z + xyLength,
501 rep->data()[0] -= rhs[0];
504 *
this = - rhs +
rep->data()[0];
525 rep->data()[0] += rhs;
533 rep->data()[0] -= rhs;
542 std::transform(x, x +
rep->len, x, std::bind(std::multiplies<T>(), std::placeholders::_1, rhs));
549 if(rhs == T(0))
throw DivideError(
"Tps::operator/()");
551 std::transform(x, x +
rep->len, x, std::bind(std::divides<T>(), std::placeholders::_1, rhs));
566 int xyLength =
getSize(std::min(xOrder, yOrder));
567 const T *x =
rep->data();
568 const T *y = rhs.
rep->data();
570 for(
int i = 0; i < xyLength; i++) {
571 if(x[i] != y[i])
return false;
574 for(
int i = xyLength; i < xLength; i++) {
575 if(x[i] != T(0))
return false;
578 for(
int i = xyLength; i < yLength; i++) {
579 if(y[i] != T(0))
return false;
593 return rep->data()[0] == rhs.
rep->data()[0];
601 const T *x =
rep->data();
603 if(x[0] != rhs)
return false;
605 for(
int i = 1; i <
getSize(); ++i) {
606 if(x[i] != T(0))
return false;
615 return !(*
this == rhs);
621 return !(*
this == rhs);
631 throw SizeError(
"Tps::substitute()",
"Matrix not consistent with Tps.");
633 int nRow = M.
nrows();
634 int nCol = M.
ncols();
639 for(
int i = 0; i < nRow; ++i) {
641 for(
int j = 0; j < nCol; ++j) y[i][j+1] = M[i][j];
645 const T *x =
rep->data();
651 product[0] =
Tps<T>(T(1));
653 for(
int next = 1; next < table.
size();) {
657 next = (s.
order < maxOrd) ? next + 1 : s.
skip;
673 throw SizeError(
"Tps::substitute()",
"VpsMap is inconsistent with Tps.");
676 const T *x =
rep->data();
682 product[0] =
Tps<T>(T(1));
685 for(
int next = 1; next < table.
size();) {
689 next = (s.
order < maxOrd) ? next + 1 : s.
skip;
702 throw SizeError(
"Tps::evaluate()",
"Vector is inconsistent with Tps.");
705 const T *x =
rep->data();
713 for(
int next = 1; next < table.
size();) {
717 next = (s.
order < maxOrd) ? next + 1 : s.
skip;
734 is.flags(std::ios::skipws);
737 if(strcmp(head,
"Tps") != 0) {
738 throw FormatError(
"Tps::get()",
"Flag word \"Tps\" missing.");
765 for(
int var = 0; var < nVar; var++) {
769 if(p < 0) done =
true;
771 order += monomial[var];
775 if(fail)
throw FormatError(
"Tps::get()",
"File read error");
780 }
else if(index == 0) {
797 std::streamsize old_prec = os.precision(14);
798 os.setf(std::ios::scientific, std::ios::floatfield);
802 << nVar << std::endl;
805 os << std::setw(24) <<
rep->data()[0] << std::endl;
807 for(
int i = 0; i <
getSize(); ++i) {
808 if(
rep->data()[i] != T(0)) {
809 os << std::setw(24) <<
rep->data()[i];
811 for(
int var = 0; var < nVar; var++) {
819 os << std::setw(24) << T(0);
821 for(
int var = 0; var < nVar; var++) {
822 os << std::setw(3) << (-1);
828 os.precision(old_prec);
829 os.setf(std::ios::fixed, std::ios::floatfield);
842 "Number of variables inconsistent.");
847 if(rhs[0] == 0.0) ++cut;
848 trunc = std::min(trunc, cut);
853 if((*
this)[0] == 0.0) ++cut;
854 trunc = std::min(trunc, cut);
860 const T *x =
rep->data();
865 for(
int yOrd = 0; yOrd <= yHig; yOrd++) {
870 for(
int yInd = yBot; yInd < yTop; yInd++) {
871 T y = rhs.
rep->data()[yInd];
873 const int *
prod =
rep->help->getProductArray(yInd);
875 for(
int xInd = 0; xInd < xTop; xInd++) {
876 z[
prod[xInd]] += x[xInd] * y;
888 const T *x =
rep->data();
889 const T y = rhs.
rep->data()[0];
890 T *z = result.
rep->data();
891 std::transform(x, x +
rep->len, z,
892 std::bind(std::multiplies<T>(), std::placeholders::_1, y));
898 const T x =
rep->data()[0];
899 const T *y = rhs.
rep->data();
900 T *z = result.
rep->data();
901 std::transform(y, y +
rep->len, z,
902 std::bind(std::multiplies<T>(), std::placeholders::_1, x));
910 T aZero =
rep->data()[0];
911 if(aZero == T(0))
throw DivideError(
"Tps::inverse()");
914 return Tps<T>(T(1) / aZero);
917 T *series =
new T[cut+1];
918 series[0] = T(1) / aZero;
920 for(
int i = 1; i <= cut; i++) {
921 series[i] = - series[i-1] / aZero;
938 const T *x =
rep->data();
941 const int *product =
rep->help->getProductArray(var + 1);
943 for(
int i =
getSize(maxOrder); i-- > 0;) {
960 throw LogicalError(
"TpsRep::integral()",
"Cannot integrate a constant.");
964 int maxO = std::min(
rep->maxOrd + 1, trcO);
967 const T *x =
rep->data();
969 const int *product =
rep->help->getProductArray(var + 1);
971 for(
int i =
getSize(maxO - 1); i-- > 0;) {
984 "Cannot multiply a constant by a numbered variable.");
988 int maxO = std::min(
rep->maxOrd + 1, trcO);
991 const T *x =
rep->data();
993 const int *product =
rep->help->getProductArray(var + 1);
995 for(
int i =
getSize(maxO - 1); i-- > 0;) {
996 z[product[i]] = x[i];
1009 throw SizeError(
"TpsRep::scaleMonomials()",
1010 "Number of variables inconsistent.");
1017 const T *x =
rep->data();
1018 const T *y = rhs.
rep->data();
1020 std::transform(x, x + p->
len, y, z, std::multiplies<T>());
1028 return Tps<T>(series[0]);
1033 for(
int maxOrder = 1; maxOrder <= order; maxOrder++) {
1035 z[0] = series[order-maxOrder];
1056 return (
rep->help != 0) ?
rep->help->getVariables() : 0;
1068 return rep->help == 0;
1086 if(
rep->help == 0) {
1088 "Cannot get exponents of a constant.");
1091 return rep->help->getExponents(index);
1097 return rep->help ?
rep->help->getOrder(index) : 0;
1103 return rep->help ?
rep->help->getSize(order) : 1;
1107template <
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,.