1#ifndef CLASSIC_FTpsMath_HH
2#define CLASSIC_FTpsMath_HH
42template <
class T,
int N>
46template <
class T,
int N>
50template <
class T,
int N>
54template <
class T,
int N>
58template <
class T,
int N>
62template <
class T,
int N>
66template <
class T,
int N>
70template <
class T,
int N>
74template <
class T,
int N>
78template <
class T,
int N>
82template <
class T,
int N>
86template <
class T,
int N>
90template <
class T,
int N>
94template <
class T,
int N>
98template <
class T,
int N>
102template <
class T,
int N>
106template <
class T,
int N>
110template <
class T,
int N>
117template <
class T,
int N>
124 while(y-- > 0) z = z.
multiply(x, trunc);
129 while(y++ < 0) z = z.
multiply(t, trunc);
136template <
class T,
int N>
143 "Square-root of EXACT polynomial must be truncated.");
150 std::cerr <<
"FTps::sqrt(x) called with\nconstant term = " << aZero
156 T two_aZero =
T(2) * aZero;
158 series[0] =
sqrt(aZero);
159 for(
int i = 1; i <= trcOrder; i++) {
160 series[i] = series[i-1] * double(3 - 2 * i) / (two_aZero * double(i));
163 return x.
taylor(series, trcOrder);
167template <
class T,
int N>
174 "Sine of EXACT polynomial must be truncated.");
180 series[0] =
sin(aZero);
181 series[1] =
cos(aZero);
182 for(
int i = 2; i <= trcOrder; i++) {
183 series[i] = - series[i-2] / double(i * (i - 1));
186 return x.
taylor(series, trcOrder);
190template <
class T,
int N>
197 "Cosine of EXACT polynomial must be truncated.");
203 series[0] =
cos(aZero);
204 series[1] = -
sin(aZero);
205 for(
int i = 2; i <= trcOrder; i++) {
206 series[i] = - series[i-2] / double(i * (i - 1));
209 return x.
taylor(series, trcOrder);
213template <
class T,
int N>
218 return sin(x, trunc) /
cos(x, trunc);
221template <
class T,
int N>
228 return cos(x, trunc) /
sin(x, trunc);
232template <
class T,
int N>
236 return cos(x, trunc).inverse();
240template <
class T,
int N>
247 return sin(x, trunc).inverse();
251template <
class T,
int N>
258 "Exponential of EXACT polynomial must be truncated.");
264 series[0] =
exp(aZero);
265 for(
int i = 1; i <= trcOrder; i++) {
266 series[i] = series[i-1] / double(i);
269 return x.
taylor(series, trcOrder);
273template <
class T,
int N>
280 "Logarithm of EXACT polynomial must be truncated.");
286 T a0inv =
T(1) / aZero;
289 series[0] =
log(aZero);
291 for(
int i = 2; i <= trcOrder; i++) {
293 series[i] = ain / double(i);
296 return x.
taylor(series, trcOrder);
300template <
class T,
int N>
307 "Hyperbolic sine of EXACT polynomial must be truncated.");
313 series[0] =
sinh(aZero);
314 series[1] =
cosh(aZero);
315 for(
int i = 2; i <= trcOrder; i++) {
316 series[i] = series[i-2] / double(i * (i - 1));
319 return x.
taylor(series, trcOrder);
323template <
class T,
int N>
330 "Hyperbolic cosine of EXACT polynomial must be truncated.");
336 series[0] =
cosh(aZero);
337 series[1] =
sinh(aZero);
338 for(
int i = 2; i <= trcOrder; i++) {
339 series[i] = series[i-2] / double(i * (i - 1));
342 return x.
taylor(series, trcOrder);
346template <
class T,
int N>
350 return sinh(x, trunc) /
cosh(x, trunc);
354template <
class T,
int N>
361 return cosh(x, trunc) /
sinh(x, trunc);
365template <
class T,
int N>
369 return cosh(x, trunc).inverse();
373template <
class T,
int N>
380 return sinh(x, trunc).inverse();
384template <
class T,
int N>
389 "Error function does not support complex numbers.");
396 "Error function of EXACT polynomial must be truncated.");
405 for(
int i = 2; i <= trcOrder; ++i) {
406 series[i] = - 2.0 / double(i-1) * double((i-2)) * series[i-2] / double(i);
409 return x.
taylor(series, trcOrder);
413template <
class T,
int N>
417 return T(1) -
erf(x, trunc);
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
FLieGenerator< T, N > imag(const FLieGenerator< std::complex< T >, N > &)
Take imaginary part of a complex generator.
FTps< T, N > csc(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Cosecant.
FTps< T, N > exp(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Exponential.
FTps< T, N > pow(const FTps< T, N > &x, int y, int trunc=(FTps< T, N >::EXACT))
Tps x to the power (int y).
FTps< T, N > cot(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Cotangent.
FTps< T, N > sqrt(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Square root.
FTps< T, N > sech(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Hyperbolic secant.
FTps< T, N > erf(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Error function.
FTps< T, N > sin(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Sine.
FTps< T, N > erfc(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Complementary error function.
FTps< T, N > tan(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Tangent.
FTps< T, N > log(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Natural logarithm.
FTps< T, N > csch(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Hyperbolic cosecant.
FTps< T, N > tanh(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Hyperbolic tangent.
FTps< T, N > sinh(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Hyperbolic sine.
FTps< T, N > sec(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Secant.
FTps< T, N > cos(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Cosine.
FTps< T, N > cosh(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Hyperbolic cosine.
FTps< T, N > coth(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Hyperbolic cotangent.
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Inform & endl(Inform &inf)
MMatrix< m_complex > complex(MMatrix< double > real)
Truncated power series in N variables of type T.
FTps inverse(int trunc=EXACT) const
Reciprocal, 1/(*this).
FTps taylor(const Array1D< T > &series, int order) const
Taylor series.
int getMinOrder() const
Get minimum order.
int getTruncOrder() const
Get truncation order.
FTps multiply(const FTps &y, int trunc=EXACT) const
Multiplication.