2#define CLASSIC_Tps_CC 1
48template <
class T>
inline
54template <
class T>
inline
81 static void *
operator new(
size_t s,
size_t extra);
82 static void operator delete(
void *);
117template <
class T>
inline
119 return reinterpret_cast<T *
>(
this + 1);
125template <
class T>
inline
127 return new char[s + extra *
sizeof(double)];
135template <
class T>
inline
139 delete []
reinterpret_cast<char *
>(p);
143template <
class T>
inline
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
210 if(--(p->
ref) <= 0)
delete p;
241 rep->data()[0] = rhs;
248 rep->data()[0] =
T(rhs);
273 rep->data()[0] = rhs;
287 int bot =
getSize(minOrder - 1);
289 std::copy(
rep->data() + bot,
rep->data() + top, p->
data() + bot);
302 return rep->data()[index];
309 return rep->data()[index];
328 if(index >
rep->len) {
329 throw CLRangeError(
"Tps::getCoefficients()",
"Monomial index out of range.");
332 return rep->data()[index];
339 if(order >
rep->trcOrd)
return;
341 if(order >
rep->maxOrd) {
350 rep->data()[index] = value;
360 throw SizeError(
"Tps::getCoefficients()",
361 "Inconsistent number of variables.");
374 throw SizeError(
"Tps::getCoefficients()",
375 "Inconsistent number of variables.");
385 p->
data()[var+1] =
T(1);
393 monomial[var] = order;
420 std::transform(
rep->data(),
rep->data() +
rep->len, p->
data(),
432 "Number of variables inconsistent.");
440 int xyLength =
std::min(xLength, yLength);
442 const T *x =
rep->data();
443 const T *y = rhs.
rep->data();
445 std::transform(x, x + xyLength, y, z, std::plus<T>());
446 std::copy(x + xyLength, x + xLength, z + xyLength);
447 std::copy(y + xyLength, y + yLength, z + xyLength);
452 rep->data()[0] += rhs[0];
455 *
this = rhs +
rep->data()[0];
467 "Number of variables inconsistent.");
475 int xyLength =
std::min(xLength, yLength);
478 const T *x =
rep->data();
479 const T *y = rhs.
rep->data();
481 std::transform(x, x + xyLength, y, z, std::minus<T>());
482 std::copy(x + xyLength, x + xLength, z + xyLength);
483 std::transform(y + xyLength, y + yLength, z + xyLength,
489 rep->data()[0] -= rhs[0];
492 *
this = - rhs +
rep->data()[0];
513 rep->data()[0] += rhs;
521 rep->data()[0] -= rhs;
530 std::transform(x, x +
rep->len, x, std::bind(std::multiplies<T>(), std::placeholders::_1, rhs));
539 std::transform(x, x +
rep->len, x, std::bind(std::divides<T>(), std::placeholders::_1, rhs));
555 const T *x =
rep->data();
556 const T *y = rhs.
rep->data();
558 for(
int i = 0; i < xyLength; i++) {
559 if(x[i] != y[i])
return false;
562 for(
int i = xyLength; i < xLength; i++) {
563 if(x[i] !=
T(0))
return false;
566 for(
int i = xyLength; i < yLength; i++) {
567 if(y[i] !=
T(0))
return false;
581 return rep->data()[0] == rhs.
rep->data()[0];
589 const T *x =
rep->data();
591 if(x[0] != rhs)
return false;
593 for(
int i = 1; i <
getSize(); ++i) {
594 if(x[i] !=
T(0))
return false;
603 return !(*
this == rhs);
609 return !(*
this == rhs);
619 throw SizeError(
"Tps::substitute()",
"Matrix not consistent with Tps.");
621 int nRow = M.
nrows();
622 int nCol = M.
ncols();
627 for(
int i = 0; i < nRow; ++i) {
629 for(
int j = 0; j < nCol; ++j) y[i][j+1] = M[i][j];
633 const T *x =
rep->data();
641 for(
int next = 1; next < table.
size();) {
645 next = (s.
order < maxOrd) ? next + 1 : s.
skip;
661 throw SizeError(
"Tps::substitute()",
"VpsMap is inconsistent with Tps.");
664 const T *x =
rep->data();
673 for(
int next = 1; next < table.
size();) {
677 next = (s.
order < maxOrd) ? next + 1 : s.
skip;
690 throw SizeError(
"Tps::evaluate()",
"Vector is inconsistent with Tps.");
693 const T *x =
rep->data();
701 for(
int next = 1; next < table.
size();) {
705 next = (s.
order < maxOrd) ? next + 1 : s.
skip;
722 is.flags(std::ios::skipws);
725 if(strcmp(head,
"Tps") != 0) {
726 throw FormatError(
"Tps::get()",
"Flag word \"Tps\" missing.");
753 for(
int var = 0; var < nVar; var++) {
757 if(p < 0) done =
true;
759 order += monomial[var];
763 if(fail)
throw FormatError(
"Tps::get()",
"File read error");
768 }
else if(index == 0) {
785 std::streamsize old_prec = os.precision(14);
786 os.setf(std::ios::scientific, std::ios::floatfield);
795 for(
int i = 0; i <
getSize(); ++i) {
796 if(
rep->data()[i] !=
T(0)) {
797 os << std::setw(24) <<
rep->data()[i];
799 for(
int var = 0; var < nVar; var++) {
807 os << std::setw(24) <<
T(0);
809 for(
int var = 0; var < nVar; var++) {
810 os << std::setw(3) << (-1);
817 os.setf(std::ios::fixed, std::ios::floatfield);
830 "Number of variables inconsistent.");
835 if(rhs[0] == 0.0) ++cut;
841 if((*
this)[0] == 0.0) ++cut;
848 const T *x =
rep->data();
853 for(
int yOrd = 0; yOrd <= yHig; yOrd++) {
858 for(
int yInd = yBot; yInd < yTop; yInd++) {
859 T y = rhs.
rep->data()[yInd];
861 const int *
prod =
rep->help->getProductArray(yInd);
863 for(
int xInd = 0; xInd < xTop; xInd++) {
864 z[
prod[xInd]] += x[xInd] * y;
876 const T *x =
rep->data();
877 const T y = rhs.
rep->data()[0];
878 T *z = result.
rep->data();
879 std::transform(x, x +
rep->len, z,
880 std::bind(std::multiplies<T>(), std::placeholders::_1, y));
886 const T x =
rep->data()[0];
887 const T *y = rhs.
rep->data();
888 T *z = result.
rep->data();
889 std::transform(y, y +
rep->len, z,
890 std::bind(std::multiplies<T>(), std::placeholders::_1, x));
898 T aZero =
rep->data()[0];
905 T *series =
new T[cut+1];
906 series[0] =
T(1) / aZero;
908 for(
int i = 1; i <= cut; i++) {
909 series[i] = - series[i-1] / aZero;
926 const T *x =
rep->data();
929 const int *product =
rep->help->getProductArray(var + 1);
931 for(
int i =
getSize(maxOrder); i-- > 0;) {
948 throw LogicalError(
"TpsRep::integral()",
"Cannot integrate a constant.");
955 const T *x =
rep->data();
957 const int *product =
rep->help->getProductArray(var + 1);
959 for(
int i =
getSize(maxO - 1); i-- > 0;) {
972 "Cannot multiply a constant by a numbered variable.");
979 const T *x =
rep->data();
981 const int *product =
rep->help->getProductArray(var + 1);
983 for(
int i =
getSize(maxO - 1); i-- > 0;) {
984 z[product[i]] = x[i];
997 throw SizeError(
"TpsRep::scaleMonomials()",
998 "Number of variables inconsistent.");
1005 const T *x =
rep->data();
1006 const T *y = rhs.
rep->data();
1008 std::transform(x, x + p->
len, y, z, std::multiplies<T>());
1016 return Tps<T>(series[0]);
1021 for(
int maxOrder = 1; maxOrder <= order; maxOrder++) {
1023 z[0] = series[order-maxOrder];
1044 return (
rep->help != 0) ?
rep->help->getVariables() : 0;
1056 return rep->help == 0;
1074 if(
rep->help == 0) {
1076 "Cannot get exponents of a constant.");
1079 return rep->help->getExponents(index);
1085 return rep->help ?
rep->help->getOrder(index) : 0;
1091 return rep->help ?
rep->help->getSize(order) : 1;
1095template <
class T>
inline
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
T::PETE_Expr_t::PETE_Return_t prod(const PETE_Expr< T > &expr)
Inform & endl(Inform &inf)
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).