login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Note 04-Apr-2021: This page is abandoned, it's new home is https://fricas.github.io/fricas-notebooks/FriCAS-TaylorSeries.html

Example for multivariate Taylor series expansion

Univariate TaylorSeries

FriCAS can deal with power series in a simple manner.

fricas
(1) -> )version
"FriCAS 1.3.10 compiled at Wed 10 Jan 02:19:45 CET 2024"

fricas
x:=taylor 'x

\label{eq1}x(1)
Type: UnivariateTaylorSeries?(Expression(Integer),x,0)
fricas
sinh(x)

\label{eq2}\begin{array}{@{}l}
\displaystyle
x +{{\frac{1}{6}}\ {{x}^{3}}}+{{\frac{1}{120}}\ {{x}^{5}}}+{{\frac{1}{5
040}}\ {{x}^{7}}}+ 
\
\
\displaystyle
{{\frac{1}{362880}}\ {{x}^{9}}}+{O \left({{x}^{11}}\right)}
(2)
Type: UnivariateTaylorSeries?(Expression(Integer),x,0)

However, sometimes one wants to be more precise with the domain that the object lives in. If, for example, we don't want power series over the general expression domain as exemplified above, we can give the coefficient domain explicitly.

fricas
Z ==> Integer
Type: Void
fricas
Q ==> Fraction Z
Type: Void
fricas
Ux ==> UnivariateTaylorSeries(Q, 'x, 0)
Type: Void
fricas
ux: Ux := 'x

\label{eq3}x(3)
Type: UnivariateTaylorSeries?(Fraction(Integer),x,0)
fricas
sinh(ux)

\label{eq4}\begin{array}{@{}l}
\displaystyle
x +{{\frac{1}{6}}\ {{x}^{3}}}+{{\frac{1}{120}}\ {{x}^{5}}}+{{\frac{1}{5
040}}\ {{x}^{7}}}+ 
\
\
\displaystyle
{{\frac{1}{362880}}\ {{x}^{9}}}+{O \left({{x}^{11}}\right)}
(4)
Type: UnivariateTaylorSeries?(Fraction(Integer),x,0)

Combination of univariate TaylorSeries

The FriCAS interpreter is smart enough to create an appropriate type if two univariate Taylor series interact.

However, as seen below, the resulting domain is something like

Q[[x]][[y]], 
i.e., univariate power series in y with coefficients that are univariate power series in x that have rational coefficients.

fricas
Uy ==> UnivariateTaylorSeries(Q, 'y, 0)
Type: Void
fricas
uy: Uy := 'y

\label{eq5}y(5)
Type: UnivariateTaylorSeries?(Fraction(Integer),y,0)
fricas
cosh(uy)

\label{eq6}\begin{array}{@{}l}
\displaystyle
1 +{{\frac{1}{2}}\ {{y}^{2}}}+{{\frac{1}{24}}\ {{y}^{4}}}+{{\frac{1}{7
20}}\ {{y}^{6}}}+ 
\
\
\displaystyle
{{\frac{1}{40320}}\ {{y}^{8}}}+{{\frac{1}{3628800}}\ {{y}^{10}}}+{O \left({{y}^{11}}\right)}
(6)
Type: UnivariateTaylorSeries?(Fraction(Integer),y,0)
fricas
sinh(ux)*cosh(uy)
There are 31 exposed and 40 unexposed library operations named * having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op * to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.
Cannot find a definition or applicable library operation named * with argument type(s) UnivariateTaylorSeries(Fraction(Integer),x,0) UnivariateTaylorSeries(Fraction(Integer),y,0)
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

As a general rule, the FriCAS interpreter tries to find a "better coefficient domain" if something does not fit into the type of the current object in order to construct a more general domain that can hold the result of the operation.

In the case above that is probably not what we expected or wanted.

Multivariate TaylorSeries in infinitely many variables

There is a domain in FriCAS that is similar to the Polynomial(Q) domain. TaylorSeries(Q) is the domain of power series over Q in infinitely many variables.

With that domain the input is as simple as for univariate power series.

fricas
T ==> TaylorSeries Q
Type: Void
fricas
tx:T := 'x

\label{eq7}x(7)
Type: TaylorSeries(Fraction(Integer))
fricas
ty:T := 'y

\label{eq8}y(8)
Type: TaylorSeries(Fraction(Integer))
fricas
sinh(tx)*cosh(ty)

\label{eq9}\begin{array}{@{}l}
\displaystyle
x +{\left({{\frac{1}{2}}\  x \ {{y}^{2}}}+{{\frac{1}{6}}\ {{x}^{3}}}\right)}+ 
\
\
\displaystyle
{\left({{\frac{1}{24}}\  x \ {{y}^{4}}}+{{\frac{1}{12}}\ {{x}^{3}}\ {{y}^{2}}}+{{\frac{1}{120}}\ {{x}^{5}}}\right)}+ 
\
\
\displaystyle
{\left({
\begin{array}{@{}l}
\displaystyle
{{\frac{1}{720}}\  x \ {{y}^{6}}}+{{\frac{1}{144}}\ {{x}^{3}}\ {{y}^{4}}}+{{\frac{1}{240}}\ {{x}^{5}}\ {{y}^{2}}}+ 
\
\
\displaystyle
{{\frac{1}{5040}}\ {{x}^{7}}}
(9)
Type: TaylorSeries(Fraction(Integer))

Multivariate TaylorSeries in two variables

FriCAS allows to be more precise with multivariate power series. It is possible to create multivariate power series in a given number of variables. Such a construction is, however, a bit more involved.

The domain (named M below') is modelled as a univariate power series over bivariate polynomials where the n-th coefficient of the series is the polynomial consisting of all (bivariate) terms of degree n.

Thus we first have to create a bivariate polynomial domain. From this construction, it should be clear how to create multivariate series in three or more variables.

fricas
vl: List Symbol := ['x, 'y]

\label{eq10}\left[ x , \: y \right](10)
Type: List(Symbol)
fricas
V ==> OrderedVariableList vl
Type: Void
fricas
P ==> SparseMultivariatePolynomial(Q, V)
Type: Void
fricas
M ==> SparseMultivariateTaylorSeries(Q, V, P)
Type: Void
fricas
X: M := monomial(1$M, 'x, 1)

\label{eq11}x(11)
Type: SparseMultivariateTaylorSeries(Fraction(Integer),OrderedVariableList([x,y]),SparseMultivariatePolynomial?(Fraction(Integer),OrderedVariableList([x,y])))
fricas
Y: M := monomial(1$M, 'y, 1)

\label{eq12}y(12)
Type: SparseMultivariateTaylorSeries(Fraction(Integer),OrderedVariableList([x,y]),SparseMultivariatePolynomial?(Fraction(Integer),OrderedVariableList([x,y])))
fricas
sinh(X)*cosh(Y)

\label{eq13}\begin{array}{@{}l}
\displaystyle
x +{\left({{\frac{1}{6}}\ {{x}^{3}}}+{{\frac{1}{2}}\ {{y}^{2}}\  x}\right)}+ 
\
\
\displaystyle
{\left({{\frac{1}{120}}\ {{x}^{5}}}+{{\frac{1}{12}}\ {{y}^{2}}\ {{x}^{3}}}+{{\frac{1}{24}}\ {{y}^{4}}\  x}\right)}+ 
\
\
\displaystyle
{\left({
\begin{array}{@{}l}
\displaystyle
{{\frac{1}{5040}}\ {{x}^{7}}}+{{\frac{1}{240}}\ {{y}^{2}}\ {{x}^{5}}}+{{\frac{1}{144}}\ {{y}^{4}}\ {{x}^{3}}}+ 
\
\
\displaystyle
{{\frac{1}{720}}\ {{y}^{6}}\  x}
(13)
Type: SparseMultivariateTaylorSeries(Fraction(Integer),OrderedVariableList([x,y]),SparseMultivariatePolynomial?(Fraction(Integer),OrderedVariableList([x,y])))

Multivariate Taylor series with unknown coefficients

We want to generate taylor series with unknown coefficients.

fricas
)clear completely
All user variables and function definitions have been cleared. All )browse facility databases have been cleared. Internally cached functions and constructors have been cleared. )clear completely is finished. vl: List Symbol := ['x, 'y];
Type: List(Symbol)
fricas
V ==> OrderedVariableList vl
Type: Void
fricas
Q ==> Expression Integer
Type: Void
fricas
P ==> SparseMultivariatePolynomial(Q, V)
Type: Void
fricas
M ==> SparseMultivariateTaylorSeries(Q, V, P)
Type: Void
fricas
X: M := monomial(1$M, 'x, 1)

\label{eq14}x(14)
Type: SparseMultivariateTaylorSeries(Expression(Integer),OrderedVariableList([x,y]),SparseMultivariatePolynomial?(Expression(Integer),OrderedVariableList([x,y])))
fricas
Y: M := monomial(1$M, 'y, 1)

\label{eq15}y(15)
Type: SparseMultivariateTaylorSeries(Expression(Integer),OrderedVariableList([x,y]),SparseMultivariatePolynomial?(Expression(Integer),OrderedVariableList([x,y])))
fricas
sx:M := recip(1-X)

\label{eq16}1 + x +{{x}^{2}}+{{x}^{3}}+{{x}^{4}}+{{x}^{5}}+{{x}^{6}}+{{x}^{7}}+{{x}^{8}}+{{x}^{9}}+{{x}^{10}}+{O \left({11}\right)}(16)
Type: SparseMultivariateTaylorSeries(Expression(Integer),OrderedVariableList([x,y]),SparseMultivariatePolynomial?(Expression(Integer),OrderedVariableList([x,y])))
fricas
sy:M := recip(1-Y)

\label{eq17}1 + y +{{y}^{2}}+{{y}^{3}}+{{y}^{4}}+{{y}^{5}}+{{y}^{6}}+{{y}^{7}}+{{y}^{8}}+{{y}^{9}}+{{y}^{10}}+{O \left({11}\right)}(17)
Type: SparseMultivariateTaylorSeries(Expression(Integer),OrderedVariableList([x,y]),SparseMultivariatePolynomial?(Expression(Integer),OrderedVariableList([x,y])))
fricas
s1 := sx*sy

\label{eq18}\begin{array}{@{}l}
\displaystyle
1 +{\left(x + y \right)}+{\left({{x}^{2}}+{y \  x}+{{y}^{2}}\right)}+{\left({{x}^{3}}+{y \ {{x}^{2}}}+{{{y}^{2}}\  x}+{{y}^{3}}\right)}+ 
\
\
\displaystyle
{\left({{x}^{4}}+{y \ {{x}^{3}}}+{{{y}^{2}}\ {{x}^{2}}}+{{{y}^{3}}\  x}+{{y}^{4}}\right)}+ 
\
\
\displaystyle
{\left({{x}^{5}}+{y \ {{x}^{4}}}+{{{y}^{2}}\ {{x}^{3}}}+{{{y}^{3}}\ {{x}^{2}}}+{{{y}^{4}}\  x}+{{y}^{5}}\right)}+ 
\
\
\displaystyle
{\left({{x}^{6}}+{y \ {{x}^{5}}}+{{{y}^{2}}\ {{x}^{4}}}+{{{y}^{3}}\ {{x}^{3}}}+{{{y}^{4}}\ {{x}^{2}}}+{{{y}^{5}}\  x}+{{y}^{6}}\right)}+ 
\
\
\displaystyle
{\left({{x}^{7}}+{y \ {{x}^{6}}}+{{{y}^{2}}\ {{x}^{5}}}+{{{y}^{3}}\ {{x}^{4}}}+{{{y}^{4}}\ {{x}^{3}}}+{{{y}^{5}}\ {{x}^{2}}}+{{{y}^{6}}\  x}+{{y}^{7}}\right)}+ 
\
\
\displaystyle
{\left({
\begin{array}{@{}l}
\displaystyle
{{x}^{8}}+{y \ {{x}^{7}}}+{{{y}^{2}}\ {{x}^{6}}}+{{{y}^{3}}\ {{x}^{5}}}+{{{y}^{4}}\ {{x}^{4}}}+{{{y}^{5}}\ {{x}^{3}}}+{{{y}^{6}}\ {{x}^{2}}}+ 
\
\
\displaystyle
{{{y}^{7}}\  x}+{{y}^{8}}
(18)
Type: SparseMultivariateTaylorSeries(Expression(Integer),OrderedVariableList([x,y]),SparseMultivariatePolynomial?(Expression(Integer),OrderedVariableList([x,y])))

We can create power series with unknown coefficients.

fricas
a: Symbol := 'a;
Type: Symbol
fricas
fp(p:P):P == (pp:P := 0; e:=enumerate()$V; for m in monomials p repeat (l:=degree(m,e); pp := pp + elt(a,l)*m);pp)
Function declaration fp : SparseMultivariatePolynomial(Expression( Integer),OrderedVariableList([x,y])) -> SparseMultivariatePolynomial(Expression(Integer), OrderedVariableList([x,y])) has been added to workspace.
Type: Void
fricas
st1: Stream P := coefficients s1;
Type: Stream(SparseMultivariatePolynomial?(Expression(Integer),OrderedVariableList([x,y])))
fricas
ast1: Stream P := map(fp, st1);
fricas
Compiling function fp with type SparseMultivariatePolynomial(
      Expression(Integer),OrderedVariableList([x,y])) -> 
      SparseMultivariatePolynomial(Expression(Integer),
      OrderedVariableList([x,y]))
Type: Stream(SparseMultivariatePolynomial?(Expression(Integer),OrderedVariableList([x,y])))
fricas
a1: M := series ast1;
Type: SparseMultivariateTaylorSeries(Expression(Integer),OrderedVariableList([x,y]),SparseMultivariatePolynomial?(Expression(Integer),OrderedVariableList([x,y])))
fricas
t:=(X+Y-1)*a1;
Type: SparseMultivariateTaylorSeries(Expression(Integer),OrderedVariableList([x,y]),SparseMultivariatePolynomial?(Expression(Integer),OrderedVariableList([x,y])))
fricas
coefficient(t,3)

\label{eq19}\begin{array}{@{}l}
\displaystyle
{{\left(-{a_{3, \: 0}}+{a_{2, \: 0}}\right)}\ {{x}^{3}}}+{{\left(-{a_{2, \: 1}}+{a_{2, \: 0}}+{a_{1, \: 1}}\right)}\  y \ {{x}^{2}}}+ 
\
\
\displaystyle
{{\left(-{a_{1, \: 2}}+{a_{1, \: 1}}+{a_{0, \: 2}}\right)}\ {{y}^{2}}\  x}+{{\left(-{a_{0, \: 3}}+{a_{0, \: 2}}\right)}\ {{y}^{3}}}
(19)
Type: SparseMultivariatePolynomial?(Expression(Integer),OrderedVariableList([x,y]))
fricas
c := concat [coefficients coefficient(t, n) for n in 0..4]

\label{eq20}\begin{array}{@{}l}
\displaystyle
\left[ -{a_{0, \: 0}}, \:{-{a_{1, \: 0}}+{a_{0, \: 0}}}, \:{-{a_{0, \: 1}}+{a_{0, \: 0}}}, \:{-{a_{2, \: 0}}+{a_{1, \: 0}}}, \: \right.
\
\
\displaystyle
\left.{-{a_{1, \: 1}}+{a_{1, \: 0}}+{a_{0, \: 1}}}, \:{-{a_{0, \: 2}}+{a_{0, \: 1}}}, \:{-{a_{3, \: 0}}+{a_{2, \: 0}}}, \: \right.
\
\
\displaystyle
\left.{-{a_{2, \: 1}}+{a_{2, \: 0}}+{a_{1, \: 1}}}, \:{-{a_{1, \: 2}}+{a_{1, \: 1}}+{a_{0, \: 2}}}, \: \right.
\
\
\displaystyle
\left.{-{a_{0, \: 3}}+{a_{0, \: 2}}}, \:{-{a_{4, \: 0}}+{a_{3, \: 0}}}, \:{-{a_{3, \: 1}}+{a_{3, \: 0}}+{a_{2, \: 1}}}, \: \right.
\
\
\displaystyle
\left.{-{a_{2, \: 2}}+{a_{2, \: 1}}+{a_{1, \: 2}}}, \:{-{a_{1, \: 3}}+{a_{1, \: 2}}+{a_{0, \: 3}}}, \: \right.
\
\
\displaystyle
\left.{-{a_{0, \: 4}}+{a_{0, \: 3}}}\right] 
(20)
Type: List(Expression(Integer))
fricas
variables first c

\label{eq21}\left[{a_{0, \: 0}}\right](21)
Type: List(Symbol)
fricas
vars: List Symbol := concat [variables z for z in c]

\label{eq22}\begin{array}{@{}l}
\displaystyle
\left[{a_{0, \: 0}}, \:{a_{0, \: 0}}, \:{a_{1, \: 0}}, \:{a_{0, \: 0}}, \:{a_{0, \: 1}}, \:{a_{1, \: 0}}, \:{a_{2, \: 0}}, \:{a_{0, \: 1}}, \:{a_{1, \: 0}}, \:{a_{1, \: 1}}, \: \right.
\
\
\displaystyle
\left.{a_{0, \: 1}}, \:{a_{0, \: 2}}, \:{a_{2, \: 0}}, \:{a_{3, \: 0}}, \:{a_{1, \: 1}}, \:{a_{2, \: 0}}, \:{a_{2, \: 1}}, \:{a_{0, \: 2}}, \:{a_{1, \: 1}}, \:{a_{1, \: 2}}, \: \right.
\
\
\displaystyle
\left.{a_{0, \: 2}}, \:{a_{0, \: 3}}, \:{a_{3, \: 0}}, \:{a_{4, \: 0}}, \:{a_{2, \: 1}}, \:{a_{3, \: 0}}, \:{a_{3, \: 1}}, \:{a_{1, \: 2}}, \:{a_{2, \: 1}}, \:{a_{2, \: 2}}, \: \right.
\
\
\displaystyle
\left.{a_{0, \: 3}}, \:{a_{1, \: 2}}, \:{a_{1, \: 3}}, \:{a_{0, \: 3}}, \:{a_{0, \: 4}}\right] 
(22)
Type: List(Symbol)
fricas
v: List Symbol := [u for u in members set vars]

\label{eq23}\begin{array}{@{}l}
\displaystyle
\left[{a_{0, \: 0}}, \:{a_{0, \: 1}}, \:{a_{0, \: 2}}, \:{a_{0, \: 3}}, \:{a_{0, \: 4}}, \:{a_{1, \: 0}}, \:{a_{1, \: 1}}, \:{a_{1, \: 2}}, \:{a_{1, \: 3}}, \:{a_{2, \: 0}}, \: \right.
\
\
\displaystyle
\left.{a_{2, \: 1}}, \:{a_{2, \: 2}}, \:{a_{3, \: 0}}, \:{a_{3, \: 1}}, \:{a_{4, \: 0}}\right] 
(23)
Type: List(Symbol)
fricas
es:=cons(a[0,0]-1, rest c)

\label{eq24}\begin{array}{@{}l}
\displaystyle
\left[{{a_{0, \: 0}}- 1}, \:{-{a_{1, \: 0}}+{a_{0, \: 0}}}, \:{-{a_{0, \: 1}}+{a_{0, \: 0}}}, \:{-{a_{2, \: 0}}+{a_{1, \: 0}}}, \: \right.
\
\
\displaystyle
\left.{-{a_{1, \: 1}}+{a_{1, \: 0}}+{a_{0, \: 1}}}, \:{-{a_{0, \: 2}}+{a_{0, \: 1}}}, \:{-{a_{3, \: 0}}+{a_{2, \: 0}}}, \: \right.
\
\
\displaystyle
\left.{-{a_{2, \: 1}}+{a_{2, \: 0}}+{a_{1, \: 1}}}, \:{-{a_{1, \: 2}}+{a_{1, \: 1}}+{a_{0, \: 2}}}, \: \right.
\
\
\displaystyle
\left.{-{a_{0, \: 3}}+{a_{0, \: 2}}}, \:{-{a_{4, \: 0}}+{a_{3, \: 0}}}, \:{-{a_{3, \: 1}}+{a_{3, \: 0}}+{a_{2, \: 1}}}, \: \right.
\
\
\displaystyle
\left.{-{a_{2, \: 2}}+{a_{2, \: 1}}+{a_{1, \: 2}}}, \:{-{a_{1, \: 3}}+{a_{1, \: 2}}+{a_{0, \: 3}}}, \: \right.
\
\
\displaystyle
\left.{-{a_{0, \: 4}}+{a_{0, \: 3}}}\right] 
(24)
Type: List(Expression(Integer))

Unfortunately, removing the semicolon from the end of the following command makes trouble for LaTeX.

fricas
result:=solve([e=0 for e in es], v);
Type: List(List(Equation(Expression(Integer))))

Bill Page: It seems to be a problem with encoding a list of lists.

fricas
for i in result repeat outputAsTex(i)

\label{eq25}\begin{array}{@{}l}
\displaystyle
{{a_{0, \: 0}}= 1}\ {{a_{0, \: 1}}= 1}\ {{a_{0, \: 2}}= 1}\ {{a_{0, \: 3}}= 1}\ {{a_{0, \: 4}}= 1}\ {{a_{1, \: 0}}= 1}\  \cdot \
\
\displaystyle
{{a_{1, \: 1}}= 2}\ {{a_{1, \: 2}}= 3}\ {{a_{1, \: 3}}= 4}\ {{a_{2, \: 0}}= 1}\ {{a_{2, \: 1}}= 3}\ {{a_{2, \: 2}}= 6}\  \cdot \
\
\displaystyle
{{a_{3, \: 0}}= 1}\ {{a_{3, \: 1}}= 4}\ {{a_{4, \: 0}}= 1}
(25)
Type: Void




  Subject:   Be Bold !!
  ( 15 subscribers )  
Please rate this page: