1#ifndef CLASSIC_LinearFun_CC
2#define CLASSIC_LinearFun_CC
38template <
class T,
int N>
40 for(
int i = 0; i <= N; ++i) data[i] = 0.0;
44template <
class T,
int N>
47 for(
int i = 1; i <= N; ++i) data[i] = 0.0;
51template <
class T,
int N>
54 for(
int i = 1; i <= N; ++i) data[i] = 0.0;
58template <
class T,
int N>
61 for(
int i = 1; i <= N; ++i) data[i] = 0.0;
66template <
class T,
int N>
68 return (index > N) ?
T(0) : data[index];
72template <
class T,
int N>
74 if(index <= N) data[index] = value;
78template <
class T,
int N>
inline
84template <
class T,
int N>
inline
90template <
class T,
int N>
93 for(
int i = 0; i <= N; ++i) z.
data[i] = 0.0;
99template <
class T,
int N>
inline
105template <
class T,
int N>
108 for(
int i = 0; i <= N; ++i) z.
data[i] = - data[i];
113template <
class T,
int N>
115 for(
int i = 0; i <= N; ++i) data[i] += rhs.
data[i];
120template <
class T,
int N>
122 for(
int i = 0; i <= N; ++i) data[i] -= rhs.
data[i];
127template <
class T,
int N>
129 return *
this = multiply(rhs);
133template <
class T,
int N>
136 T div =
T(1) / rhs.
data[0];
139 for(
int i = 1; i <= N; ++i) {
140 data[i] = (data[i] - data[0] * rhs.
data[i]) * div;
147template <
class T,
int N>
inline
154template <
class T,
int N>
inline
161template <
class T,
int N>
163 for(
int i = 0; i <= N; ++i) data[i] *= rhs;
168template <
class T,
int N>
170 if(rhs ==
T(0))
throw DivideError(
"LinearFun::operator/=()");
171 for(
int i = 0; i <= N; ++i) data[i] /= rhs;
176template <
class T,
int N>
178 for(
int i = 0; i <= N; ++i) {
179 if(data[i] != rhs.
data[i])
return false;
186template <
class T,
int N>
188 if(data[0] != rhs)
return false;
190 for(
int i = 1; i <= N; ++i) {
191 if(data[i] !=
T(0))
return false;
198template <
class T,
int N>
inline
200 return !(*
this == rhs);
204template <
class T,
int N>
inline
206 return !(*
this == rhs);
210template <
class T,
int N>
213 if(aZero ==
T(0))
throw DivideError(
"LinearFun::inverse()");
215 z.
data[0] =
T(1) / aZero;
217 for(
int i = 1; i <= N; ++i) {
218 z.
data[i] = - data[i] * data[i] * z.
data[0];
230 for(
int i = 1; i <= N; ++i) {
231 z.
data[i] = data[0] * rhs.
data[i] + data[i] * rhs.
data[0];
238template <
class T,
int N>
241 for(
int i = 0; i < N; ++i) z += data[i+1] * rhs[i];
246template <
class T,
int N>
251 for(
int i = 0; i < N; ++i) {
252 for(
int j = 0; j < N; ++i) {
253 z.
data[i+1] += data[j+1] * M[j][i];
261template <
class T,
int N>
266 for(
int i = 0; i <= N; ++i) {
267 for(
int j = 0; j < N; ++i) {
268 z.
data[i] += data[j] * m[j][i];
276template <
class T,
int N>
279 z.
data[0] = series[0];
281 for(
int i = 1; i <= N; ++i) {
282 z.
data[i] = series[1] * data[i];
289template <
class T,
int N>
291 is.flags(std::ios::skipws);
295 if(strcmp(head,
"LinearFun") != 0) {
296 throw FormatError(
"LinearFun::get()",
"Flag word \"Tps\" missing.");
299 int maxOrder, truncOrder, nVar;
300 is >> maxOrder >> truncOrder >> nVar;
303 throw FormatError(
"LinearFun::get()",
"Invalid number of variables.");
317 for(
int var = 0; var < N; var++) {
331 if(fail)
throw FormatError(
"LinearFun::get()",
"File read error");
333 if(order <= 1 && coeff !=
T(0)) {
334 z.
data[index] = coeff;
342template <
class T,
int N>
344 os <<
"LinearFun " << 1 <<
' ' << 1 <<
' ' << N <<
std::endl;
346 os.setf(std::ios::scientific, std::ios::floatfield);
348 for(
int i = 0; i <= N; i++) {
349 if(data[i] !=
T(0)) {
350 os << std::setw(24) << data[i];
352 for(
int v = 1; v <= N; ++v) {
353 os << std::setw(3) << (v == i ? 1 : 0);
360 os << std::setw(24) <<
T(0);
362 for(
int v = 0; v < N; v++) {
363 os << std::setw(3) << (-1);
367 os.
setf(std::ios::fixed, std::ios::floatfield);
375template <
class T,
int N>
inline
382template <
class T,
int N>
inline
389template <
class T,
int N>
inline
396template <
class T,
int N>
inline
403template <
class T,
int N>
inline
410template <
class T,
int N>
inline
417template <
class T,
int N>
inline
423template <
class T,
int N>
inline
429template <
class T,
int N>
inline
436template <
class T,
int N>
inline
443template <
class T,
int N>
inline
450template <
class T,
int N>
inline
456template <
class T,
int N>
inline
462template <
class T,
int N>
inline
468template <
class T,
int N>
inline
474template <
class T,
int N>
inline
LinearFun< T, N > operator-(const LinearFun< T, N > &lhs, const LinearFun< T, N > &rhs)
Subtract.
LinearFun< T, N > operator/(const LinearFun< T, N > &lhs, const LinearFun< T, N > &rhs)
Divide.
LinearFun< T, N > operator+(const LinearFun< T, N > &lhs, const LinearFun< T, N > &rhs)
Add.
std::ostream & operator<<(std::ostream &os, const LinearFun< T, N > &tps)
Insert LinearFun to stream [b]os[/b].
bool operator==(const T &lhs, const LinearFun< T, N > &rhs)
Equality.
LinearFun< T, N > operator*(const LinearFun< T, N > &lhs, const LinearFun< T, N > &rhs)
Multiply.
std::istream & operator>>(std::istream &is, LinearFun< T, N > &tps)
Extract LinearFun from stream [b]is[/b].
bool operator!=(const T &lhs, const LinearFun< T, N > &rhs)
Inequality.
Inform & endl(Inform &inf)
A templated representation for vectors.
Linear map with values of type [b]T[/b] in [b]N[/b] variables.
Linear function in N variables of type T.
LinearFun & operator=(const T &y)
Convert and assign.
const T operator[](int index) const
Get coefficient.
LinearFun & operator-=(const LinearFun &y)
Subtract and assign.
const T getCoefficient(int index) const
Get coefficient.
std::istream & get(std::istream &is)
Read LinearFun on the stream [b]is[/b].
void setCoefficient(int index, const T &value)
Set coefficient.
LinearFun< T, N > substitute(const LinearMap< T, N > &m) const
Substitute.
LinearFun multiply(const LinearFun &y) const
Multiplication truncated to order one.
T evaluate(const FVector< T, N > &) const
Evaluate LinearFun at point.
T data[N+1]
Representation.
LinearFun & operator+=(const LinearFun &y)
Add and assign.
LinearFun taylor(const T series[2]) const
Taylor series.
bool operator!=(const LinearFun &y) const
Inequality operator.
LinearFun operator-() const
Unary minus.
LinearFun operator+() const
Unary plus.
LinearFun & operator/=(const LinearFun &y)
Approximate division and assignation.
bool operator==(const LinearFun &y) const
Equality operator.
LinearFun & operator*=(const LinearFun &y)
Multiply and assign.
static LinearFun makeVariable(int var)
Make variable.
LinearFun()
Default constructor.
LinearFun inverse() const
Approximate reciprocal value 1/(*this).
std::ostream & put(std::ostream &os) const
Write LinearFun on the stream [b]os[/b].
FmtFlags_t setf(FmtFlags_t setbits, FmtFlags_t field)