SMall Is Beautiful

http://sourceforge.net/projects/smib/

philippe.billet@noos.fr


Table of Contents


1 Introduction

smib stands for SMall Is Beautiful (a small loan to the economist Ernst Friedrich Schumacher) and is a Computer Algebra System (CAS) for Linux. smib is less efficient than other CAS but it is smaller; in fact I wanted to make an educational sofware (smib uses only high school mathematics and some university one), easy to program, easy to understand.
Historically, smib derives from George Weigt’s Eigenmath. Constitutionally, it is a subtle mixture of C++ (or rather C+), of FORTH (for stack) and LISP (for lists). Philosophically, it is an experimental tool in mathematics.
Some fields of application that smib touches:
smib naturally supports tensorial structures, and has a pretty good array management. This facilitates the handling of object of type (xi, f(xi))i ∈ I, I ⊂ ℕ which we call sample, which are fairly well adapted to numerical analysis as we shall see.

This document was written using Lyx.


2 Compilation & use

Compilation

Pre-requisites:
Unzip the archive in a folder of your choice. In the folder source, type ./make, then smib is built (there is a large number of warnings due to g++ since version 4 : since version 0.22 almost all warnings have been suppressed using “-Wno-write-strings” option). After you can link (or copy) the executable in your preferred folder.

Use

Boolean indicators

smib uses some boolean indicators, here after some of those are described:
If indint=1 then Sint uses Simpson scheme, else Riemann scheme.
If autoexpand=1 then expressions are automatically expanded.
If cplxmode=1 then complex exponentials are converted into trigonometric form.
If expomode=1 then trigonometric functions are converted into exponential form.
If ibpmode=1 then integration by part is used.
If opemode=1 then operators are automatically expanded.
prec is iteration number for numerically defined functions.
precdisc is iteration number for discrete moment.
precision is used by quantile.
If simpsonint=1 then numint uses Simpson scheme, else Gauss scheme.
precintgauss is number of point used for Gauss scheme.
precintsimpson is number of point used for Simpson scheme.
We can display those indicators using function
displaysetting(), we can also initialize them using initsetting().


3 Mathematical objects

Notations: in the paragraph, n, m represent integers, d a divisor of an integer, p a prime integer, q a rational number, x a real number, z a complex number, X a vector, M a matrix, P(x) a polynomial, f(x) a function.

3.1 Numbers

Integers

How to define

In smib, an integer is simply a sequence of digits; for negative integer just put minus sign ahead.
Smib proposes also pre-define integers:

Functions acting on integers

Arguments of those functions must be integers, if you want to use variables, automatic evaluation must be stopped using quote(...).

Rational numbers

How to define

In smib, a rational number is the quotient of two integers (two integers separeted by division’s sign).
Smib proposes also a pre-define rational:

Functions acting on rational numbers

Manipulation of rational number is aided by three functions:

Real numbers

How to define

There are three constants defined in smib:
Hence, a real number, in smib, is an integer, or a rational number, or any combination of above constants with integers or rational numbers.
Infinity: There are also minfty (resp. infty) i.e.  − ∞ (resp. ) that are useful to compute limits (or definite integral).
A pseudo-aleatory rational number between 0 and 1 is produced by function
random() (without any argument), it follows uniform distribution. With normrand(x), smib produces pseudo-aleatory number following normal centered distribution with variance equal to x (based on Box-Muller transform).

Functions acting on real numbers

With float(x), smib converts a real number into a number to floating point representation. If the argument is complex, we use the function num(z).
Integer part: floor(x) computes the greater integer function, ceiling(x) the smaller .

Complex numbers

How to define

i is defined by i2 =  − 1, so the definition of a complex number in smib is simple: let x and y two real numbers, then if you type x+i*y you define a complex number.

Functions acting on complex numbers

Let z a complex number:

Functions acting on any type of numbers

Basic operations: +, -, *, /, ^
Exponential & logarithmic function: exp(z), log(z)
Trigonometric functions:
sin(z), cos(z), tan(z), sec(z), csc(z), cot(z)
Inverse trigonometric functions:
arcsin(z), arccos(z), arctan(z)
Hyperbolic trigonometric functions: sh(z), ch(z), th(z), sech(z), csch(z), coth(z)
Inverse hyperbolic trigonometric functions:
argsh(z), argch(z), argth(z=
Guderman functions: gd(z), arggd(z)
Γ and B functions: Gamma(z), Beta(z1,z2)
Error functions: erf(z), erfc(z)
Bessel functions: besseli(z,n), besselj(z,n), besselk(z,n) .

Variables

How to define

A variable is simply a symbol without type (or assignation), for example x or toto.

Functions acting on variables

The above functions operate on variables except arithmetic functions.


3.2 Structures of higher dimensions

Vectors

How to define

A vector is a list of numbers, of variables, in fact if you type (1,2,3) then a vector is created.

Functions acting on vectors

Dimension of a vector: let X=(1,2,3), if you type dim(X) then smib return dimension of X ;
to access the nth component, use bracket:
X[2].
We can also construct an stochastic vector:
noisevector(n), n is the dimension of the vector (each element follows uniform distribution on [ − 1, 1],  normnoisevector(n,s) does the same but with normal centered distribution with variance equal to s.

Matrices

How to define

A matrix is a vector of vectors, for example let M =  1 x y 2 5 z , in smib:
M=((1,x),(y,2),(5,z))

Functions acting on matrices

Transposition: trans(M,i,j) where i, j are indices to transpose (for matrices i = 1 and j = 2, for tensors it is a little bit different).
Determinant of a matrix:
det(M).
Inverse of a matrix:
inv(M).
Frobenius norm:
frobeniusnorm(M).
Product of matrix by vector:
dot(M,X).
Characteristic polynomial:
charpoly(M), here the polynomial variable is x.

Polynomials

How to define

In smib, if you choose a variable x, and if you write for example P=x^2+3*x+5, then P is a polynomial. Some classical polynomials are also defined:

Functions acting on polynomials

Basic operations: +, -, *, ^ (exponent must be an integer)
Degree of a polynomial relatively to a variable:
deg(P(x),x)
Divisibility:
Euclidian division: divpoly(P(x),Q(x),x)
Greater common divisor of polynomials: gcdpoly(P(x),Q(x),x)
Extented greater common divisor of polynomials (Bezout identity) : egcdpoly(P(x),Q(x),R(x),x)
Squarefree factorization of a polynomial : squarefreepoly(P(x),x)
Resultant of polynomials : resultantpoly(P(x),Q(x),x)
Discriminant of a polynomial : discpoly(P(x),x)
Increasing power division: incrdivpoly(P(x),Q(x),x,n)

Samples

How to define

A sample is a set of couples {(xi, f(xi))}i ∈ {0..n}, (f(x),x,a,b,n) build the sample {(Si, 1, Si, 2) = (a + i.b − an, f(a + i.(b − a)n))}i ∈ {0..n}

Functions acting on samples

Ssum(S,T): sum of two samples {(xi, Si, 2 + Ti, 2)}i ∈ {0..n}
Snorm(S): computes:
((i ∈ {0..n}Si, 22), i ∈ {0..n}Si, 2n, (i ∈ {0..n}{Si, 2∥ − i ∈ {0..n}Si, 2n}2))
Sdiff(S,T): difference between two samples{(xi, Si, 2 − Ti, 2)}i ∈ {0..n}
Sproduct(S,T)
: product of two samples{(xi, Si, 2.Ti, 2)}i ∈ {0..n}
Sscalarproduct(z,S): product of a scalar and a sample {(xi, z.Si, 2)}i ∈ {0..n}
Sreal(S): real part of a sample {(xi, ℜ(Si, 2))}i ∈ {0..n}
Simag(S): imaginary part of a sample{(xi, ℑ(Si, 2))}i ∈ {0..n}
Sabs(S): absolute value of a sample {(xi, ∣Si, 2∣)}i ∈ {0..n}
Sarg(S): argument of a sample {(xi, arg(Si, 2))}i ∈ {0..n}
Sd(S)
: derivative of a sample {(xi, Si + 1 − Sixi + 1 − xi)}i ∈ {0..n}(in fact, it is a little bit more complicated because there are some problems at boundary).
Sfracd(S,q,x0): fractional derivative of a sample to a non integer order q at a point x0 (cf. § 5.6.5).
Sint(S): integral of a sample (if indint equals 0 then Sint uses Riemann method, if indint equals 1 then Sint uses Simpson method).
Sdefint(S,a,b): definite integral of a sample (if S is defined on [c, d], integral is computed on [a, b][c, d]).

Sample filtering:
Sfilterxinf(S,a): cancellation of all values less than a
Sfilterxsup(S,a): cancellation of all values greater than a
Sfilterxs(S,a,b): cancellation of all values outside [a, b]
Sample truncation:
Struncatexinf(S,a): truncation of all values less than a
Struncatexsup(S,a): truncation of all values greater than a
Struncatexs(S,a,b): truncation of all values outside [a, b]
N.B.: truncation may reduce dimension of sample.

Sdiscfourier(S,a,b)
: Fourier tranform of sample, here sample must be defined on a symetric interval [ − a, a] the result is defined on [ − b, b], for inverse Fourier transform: Sdiscinvfourier(S,b,a). Sdiscconvolution(S,T,a,b): convolution product of two samples (they must be defined on [ − a, a], and result is defined on [ − b, b].

Sreal2, Simag2, Sabs2, Sarg2, Sproduct2, Ssum2, Sscalarproduct2 are functions for samples defined like this {(xi, yi, f(xi, yi))}i ∈ {0..n}.

With Sdecomp and Srecomp, we can respectively extract a column of a sample, and glue columns (only for 2D samples). With Sdelete, we can delete a column of any sample (cf. Lorenz or Rössler system).

parametricsample
produces a 3D-sample, let (u, v) ∈ [a1, b1] × [a2, b2](v1(u, v), v2(u, v), v3(u, v)), parametricsample((v1(u,v),v2(u,v),v3(u,v)),u,v,-a,-b,n) computes sample
{(v1(u, v), v2(u, v), v3(u, v))}(u, v) ∈ [ − a, a] × [ − b, b]

Tensors

Let gαβ be a metric (in fact a square symetric matrix), g = det(gαβ), and gαβ = Adj(gαβ)g.
Now we can compute Christoffel symbol (or connection coefficient): Γαμν = 12gαβ(gβμ, ν + gβν, μ − gμν, β), Riemann tensor: Rαβγδ = Γαβδ, γ − Γαβγ, δ + ΓαμγΓμβδ − ΓαμδΓμβγ, the Ricci tensor : Rμν = Rαμαν, the Ricci scalar (or Ricci curvature): R = Rμμ, and the Einstein tensor: Gμν = Rμν − 12gμνR.
g, gαβ, Γαμν, Rαβγδ, Rμν, R, and Gμν are computed using function riemann (cf. examples infra)
Now we can define the following operators:
Now some practical examples (tensors are sometimes annoying):

Raising and lowering indices in spherical coordinates:
With the following script:
X=(r,theta,phi)
gdd=((1,0,0),(0,r^2,0),(0,0,r^2*sin(theta)^2))
riemann(gdd,X)
XU=(1,r,0)
print("gdd=",gdd)
print("guu=",guu)
print("XU=",XU)
XD=contr(outer(gdd,XU),2,3)
print("XD=",XD)
YD= (0,-r^2,cos(theta)^2)
print("YD=",YD)
YU=contr(outer(guu,YD),2,3)
print("YU=",YU)
smib gives:
gdd= ((1,0,0),(0,r^2,0),(0,0,r^2*sin(theta)^2))
guu= ((1,0,0),(0,r^(-2),0),(0,0,1/(r^2*sin(theta)^2)))
XU= (1,r,0)
XD= (1,r^3,0)
YD= (0,-r^2,cos(theta)^2)
YU= (0,-1,cos(theta)^2/(r^2*sin(theta)^2))

Polar coordinates and operators:
With the following script, we compute divergence and laplacian (or Laplace operator) in polar coordinates:
X=(r,theta)
V=(V1(X),V2(X))
f=quote(f)
P=(r*cos(theta),r*sin(theta))
print("P=",P)
gdd=firstform(P,X)
print("gdd=",gdd)
riemann(gdd,X)
print("Div(V,X)=",Div(V,X))
print("LaplF(f(X),X)=",LaplF(f(X),X))
V=(r^2*cos(theta),-sin(theta))
print("V=",V)
print("Div(V,X)=",Div(V,X))

And smib gives:
P= (r*cos(theta),r*sin(theta))
gdd= ((1,0),(0,r^2))
Div(V,X)= d(V1((r,theta)),r)+d(V2((r,theta)),theta)+V1((r,theta))/r
LaplF(f(X),X)=
d(d(f((r,theta)),r),r)+d(d(f((r,theta)),theta),theta)/(r^2)
+d(f((r,theta)),r)/r
V= (r^2*cos(theta),-sin(theta))
Div(V,X)= -cos(theta)+3*r*cos(theta)


3.3 Operators & functions

Functions

A function is user-defined transformation, it can act on numbers, vectors,..., variables or functions. For example, identity is simply defined as id(x)=x. As we have already seen, basic operations +, -, *, ^ could be used with any type of structure (numbers, polynomials, matrices, ...), provided that data are consistent; these operations could be used to extend system of existing functions.
N.B.: the argument of arithmetic functions must be an integer
.
Here is the list of functions:
sum(n,n0,n1,f(n)): partial sum (n = n1n = n0f(n))
product(n,n0,n1,f(n)): partial product (n = n1n = n0f(n))
nroot(P,x): numerical computation of roots of a polynomial using Newton method.
simpson(f(x),x,a,b,n): Simpson numerical scheme of integration
numint(f(x),x,a,b,n): numerical scheme of integration, if simpsonint=1, numint uses Simpson scheme, else Gauss scheme.

Operators

An operator is a special style of function, an operator only acts on functions. Here is the list of operators:
simplify(exp): simplification of expression
expand(exp): expansion of expression
limit(f(x),x,x0): limit of f relatively to x at x0
d(f(x),x,n): derivative of f relatively to x to order n
dsolve(F(d(f(x),x),f(x)),f(x),x): first order ordinary differential equation solver
taylor(f(x),x,x0,n): Taylor partial sum of f relatively to x at x0 to order n
integral(f(x),x,n): integral of f relatively to x to order n
ibp(f(x),g(x)): integral by parts of f and g
defint(f(x),x,a,b): integral of f relatively to x on [a, b]
fourier(f(x),x) & invfourier(f(x),x): Fourier transform & inverse ((f)(t) = f(x)e − itxdt &  − 1(f)(t) = f(x)eitxdx ⁄ (2π))
convolution(f(x),g(x)): convolution product
translation(f(x),x,a): f(x − a)
dilatation(f(x),x,a): f(ax)
modulation(f(x),x,a): eiaxf(x)


4 Elements of language

smib is also a programming language, in fact it is a functionnal language weakly typed. It can build functions and programs, a function returns a single result, a program many (or none). For example isodd(n)=test(mod(n,2)==1,1,0) is a function (it returns 1 if n is an integer, 0 else.
genocchiN(n)=prog(temp,test(n==0,1,
limit(temp^(-n)*taylor(2*temp/(exp(temp)+1),
temp,n,0)*n!,temp,infty)))

is a program which n-th computes Genocchi number.

prog

This reserved word must be used to construct a program, syntax is the following:
example(var)=prog(tempvar1,tempvar2,...,tempvarn, do(
action1,
action2,
...
actionn,
return(tempvarj)))

tempvar1,tempvar2,...,tempvarn
are temporary variables of program (it can be a variable, or a temporary program). do(...) define the set of actions to do in the program. return(...) is used to define output of program.

Condition

In a program, if you want to verify a condition, you must use the reserved word test: test(condition, if true, if false).

Writing condition is simple:

Loop

nil

In a program, if an argument is not valued, we can test it with nil, this is usefull, for example, to compute quantile:
quantile(f,x,a,b,y)=prog(temp0,temp1,temp2,temp3,temp4,temp5,temp6,do(
    test(b==nil,temp0=-10.0,temp0=b),
    test(y==nil,temp6=10.0,temp6=y),
    temp1=numint(f,x,minfty,temp0)-a,
    temp2=numint(f,x,minfty,(temp0+temp6)/2)-a,
    temp3=numint(f,x,minfty,temp6)-a,
    temp4=temp1*temp2,
    temp5=temp2*temp3,
    test(abs(temp2) < precision,(temp0+temp6)/2,
        test(and(temp4 < 0,temp5 > 0),quantile(f,x,a,(temp0+temp6)/2,temp0),
            quantile(f,x,a,(temp0+temp6)/2,temp6)))
))

Plotting

smib doesn’t offer plotting function, but it can convert sample into file usable with gnuplot (via qgfe). If one wants to plot xx2 on [ − 2, 2] (2D plotting), just make a file containing called try.txt:
gnuplot2D(num(sample(x^2,x,-2,2,100)))
quit()
In a terminal,
./smib ./try.txt >> output.txt
And then plot with qgfe, this gives:
figure image/output.png
For 3D plotting, one can use gnuplot3D and parametricsample, for example let plot3D.txt the file containing:
m=4
n=6
R=real(spherharm(theta,phi,m,n))
gnuplot3D(parametricsample(
(R*sin(theta)*cos(phi),R*sin(theta)*sin(phi),R*cos(theta))
,phi,theta,-4*pi,-pi,100))
quit()
In a terminal: ./smib ./plot3D.txt >> output3D.txt, so with qgfe:
figure image/plot3D.png
As we shall see later, qgfe is also useful to plot samples. We can use this feature to draw an histograms generated with smib. Here is a small example: we generate a large vector of normal random numbers (mean is null, variance is one), we compute the corresponding histogram, and then we compare this with the normal distribution. So in smib :
s=1
n=10000
Sr=normnoisevector(n,s)
Sh=Shistogram(Sr,I)
gnuplot2D(Sh)
quit()
And qgfe gives :
figure image/histo1.png


5 Applications

smib is certainly one of the smallest computer algebra system, but it is not a simple calculator. Here is the list of discussed topics discribed hereafter:


5.1 Arithmetic & Number theory

5.1.1 Computing famous numbers

Using direct computation

If one wants to compute Mersenne number using Mn = 2n − 1, one must define a function:
mersenneN(n)=2^n-1

then
mersenneN(10) gives 1023.

Using recursive computation

To compute Fibonacci number using F0 = 0,  F1 = 1,  Fn = Fn − 1 + Fn − 2, so in smib:
fibonacciN(n)=test(n==0,0,test(n==1,1,fibonacciN(n-1)+fibonacciN(n-2)))

then
fibonacciN(10) gives 55.

Using generating function

Bernoulli numbers Bn are defined as xex − 1 = n = ∞n = 0Bnxnn!, in smib:
bernoulliN(n)=prog(temp,test(n==0,1,
    limit(temp^(-n)*taylor(temp/(exp(temp)-1),temp,n,0)*n!,temp,infty)))

then
bernoulliN(1) gives -1/2 or bernoulliN(10) gives 5/66.

5.1.2primality tests

Deterministic test: using Wilson formula

This test is very simple to implement:
wilson(n)=test(mod((n-1)!+1,n)==0,1,0)

then
wilson(1111) gives 0, and wilson(13) gives 1.

Probabilistic test: Solovay-Strassen test

This test is harder to implement:
solovaystrassen(n,k)=prog(temp0,temp1,temp2,temp3,temp4,do(
    temp1=0,
    temp4=1,
    test(iseven(n)==1,temp4=0,
        for(temp0,1,k,
            do(temp2=ceiling(random()*(n-1)),
                test(iseven(temp2)==1,temp2=temp2+1),
                    temp3=jacobisymbol(n,temp2)*(-1)^((n-1)(temp2-1)/4),
                    test(or(temp3==0,not(mod(temp2^((n-1)/2)-temp3,n)==0)),
                        do(temp4=0,temp0=k))))),
    return(temp4)
))

Here, we must use law of quadratic reciprocity for Jacobi symbol (this is due to Jacobi symbol definition in smib: it is stupid to compute decomposition into prime factors to test primality of a number).

Then
solovaystrassen(761,14) gives 1 and solovaystrassen(763,14) gives 0.
In fact, those algorithmes are not very efficient in smib for large integers, it is better to use the function
isprime.

5.1.3 properties of arithmetic functions

Let X = (1, 2, 3, 4, 20, 25, 154, 210, 576, 6930, 22464, 54000, 104729, 193440, 523567) a vector of integers. Our aim is to test properties of arithmetic functions on this vector.

Sum over divisors

Here is the list of properties:
The implementation is given by:
print("* a * Sum((n<=N,n|N),(|mu(n)|.phi(n)))=gamma(n) *")
testa(N)=sumoverdivisor(x,N,quote(abs(mobius(x))*eulerphi(x)))-integerkernel(N)
for(ind,1,dim(X),
    print("Sum((n<=",X[ind],",n|N),(|mu|.phi))-gamma(",X[ind],")=",
    testa(X[ind])))
print("* b * Sum((n<=N,n|N),1/n^2)=sigma(N,2)/N^2 *")
testb(N)=sumoverdivisor(x,N,1/x^2)-sigma(N,2)/N^2
for(ind,1,dim(X),
    print("Sum((n<=",X[ind],",n|N),1/n^2)-sigma(",X[ind],",2)/",X[ind],"^2)=",
    testb(X[ind])))
print("* c * Sum((n<=N,n|N),abs(mu(n)))=2^omega(n) *")
testc(N)=sumoverdivisor(x,N,quote(abs(mobius(x))))-2^omega(N)
for(ind,1,dim(X),
    print("Sum((n<=",X[ind],",n|N),abs(mu(n)))-2^omega(",X[ind],")= ",
    testc(X[ind])))
print("* d * Sum((n<=N,n|N),mu(n)*tau(n))=(-1)^omega(n) *")
testd(N)=sumoverdivisor(x,N,quote(mobius(x)*tau(x)))-(-1)^omega(N)
for(ind,1,dim(X),
    print("Sum((n<=",X[ind],",n|N),mu(n)*tau(n))-
    (-1)^omega(",X[ind],") = ",testd(X[ind])))
print("* e * Sum((n<=N,n|N),mu(n)*lamba(n))=2^omega(n) *")
teste(N)=sumoverdivisor(x,N,quote(mobius(x)*liouvillefunction(x)))-2^omega(N)
for(ind,1,dim(X),
    print("Sum((n<=",X[ind],",n|N),mobius(n)*liouvillefunction(n))-
    2^omega(",X[ind],") = ",teste(X[ind])))
print("* f * Sum((n<=N,n|N),sigma(n))=N*Sum((n<=N,n|N),tau(n)/n) *")
testf(N)=sumoverdivisor(x,N,quote(sigma(x,1)))-N*sumoverdivisor(x,N,quote(tau(x)/x))
for(ind,1,dim(X),
    print("Sum((n<=",X[ind],",n|N),sigma(n,1))-Sum((n<=",X[ind],"n|N),
        tau(n)/n) = ",testf(X[ind])))

And smib gives:
* a * Sum((n<=N,n|N),(|mu(n)|.phi(n)))=gamma(n) *
Sum((n<= 1 ,n|N),(|mu|.phi))-gamma( 1 ) = 0
Sum((n<= 2 ,n|N),(|mu|.phi))-gamma( 2 ) = 0
Sum((n<= 3 ,n|N),(|mu|.phi))-gamma( 3 ) = 0
Sum((n<= 4 ,n|N),(|mu|.phi))-gamma( 4 ) = 0
Sum((n<= 20 ,n|N),(|mu|.phi))-gamma( 20 ) = 0
Sum((n<= 25 ,n|N),(|mu|.phi))-gamma( 25 ) = 0
Sum((n<= 154 ,n|N),(|mu|.phi))-gamma( 154 ) = 0
Sum((n<= 210 ,n|N),(|mu|.phi))-gamma( 210 ) = 0
Sum((n<= 576 ,n|N),(|mu|.phi))-gamma( 576 ) = 0
Sum((n<= 6930 ,n|N),(|mu|.phi))-gamma( 6930 ) = 0
Sum((n<= 22464 ,n|N),(|mu|.phi))-gamma( 22464 ) = 0
Sum((n<= 54000 ,n|N),(|mu|.phi))-gamma( 54000 ) = 0
Sum((n<= 104729 ,n|N),(|mu|.phi))-gamma( 104729 ) = 0
Sum((n<= 193440 ,n|N),(|mu|.phi))-gamma( 193440 ) = 0
Sum((n<= 523567 ,n|N),(|mu|.phi))-gamma( 523567 ) = 0
* b * Sum((n<=N,n|N),1/n^2)=sigma(N,2)/N^2 *
Sum((n<= 1 ,n|N),1/n^2)-sigma( 1 ,2)/ 1 ^2) = 0
Sum((n<= 2 ,n|N),1/n^2)-sigma( 2 ,2)/ 2 ^2) = 0
Sum((n<= 3 ,n|N),1/n^2)-sigma( 3 ,2)/ 3 ^2) = 0
Sum((n<= 4 ,n|N),1/n^2)-sigma( 4 ,2)/ 4 ^2) = 0
Sum((n<= 20 ,n|N),1/n^2)-sigma( 20 ,2)/ 20 ^2) = 0
Sum((n<= 25 ,n|N),1/n^2)-sigma( 25 ,2)/ 25 ^2) = 0
Sum((n<= 154 ,n|N),1/n^2)-sigma( 154 ,2)/ 154 ^2) = 0
Sum((n<= 210 ,n|N),1/n^2)-sigma( 210 ,2)/ 210 ^2) = 0
Sum((n<= 576 ,n|N),1/n^2)-sigma( 576 ,2)/ 576 ^2) = 0
Sum((n<= 6930 ,n|N),1/n^2)-sigma( 6930 ,2)/ 6930 ^2) = 0
Sum((n<= 22464 ,n|N),1/n^2)-sigma( 22464 ,2)/ 22464 ^2) = 0
Sum((n<= 54000 ,n|N),1/n^2)-sigma( 54000 ,2)/ 54000 ^2) = 0
Sum((n<= 104729 ,n|N),1/n^2)-sigma( 104729 ,2)/ 104729 ^2) = 0
Sum((n<= 193440 ,n|N),1/n^2)-sigma( 193440 ,2)/ 193440 ^2) = 0
Sum((n<= 523567 ,n|N),1/n^2)-sigma( 523567 ,2)/ 523567 ^2) = 0
* c * Sum((n<=N,n|N),abs(mu(n)))=2^omega(n) *
Sum((n<= 1 ,n|N),abs(mu(n)))-2^omega( 1 ) = 0
Sum((n<= 2 ,n|N),abs(mu(n)))-2^omega( 2 ) = 0
Sum((n<= 3 ,n|N),abs(mu(n)))-2^omega( 3 ) = 0
Sum((n<= 4 ,n|N),abs(mu(n)))-2^omega( 4 ) = 0
Sum((n<= 20 ,n|N),abs(mu(n)))-2^omega( 20 ) = 0
Sum((n<= 25 ,n|N),abs(mu(n)))-2^omega( 25 ) = 0
Sum((n<= 154 ,n|N),abs(mu(n)))-2^omega( 154 ) = 0
Sum((n<= 210 ,n|N),abs(mu(n)))-2^omega( 210 ) = 0
Sum((n<= 576 ,n|N),abs(mu(n)))-2^omega( 576 ) = 0
Sum((n<= 6930 ,n|N),abs(mu(n)))-2^omega( 6930 ) = 0
Sum((n<= 22464 ,n|N),abs(mu(n)))-2^omega( 22464 ) = 0
Sum((n<= 54000 ,n|N),abs(mu(n)))-2^omega( 54000 ) = 0
Sum((n<= 104729 ,n|N),abs(mu(n)))-2^omega( 104729 ) = 0
Sum((n<= 193440 ,n|N),abs(mu(n)))-2^omega( 193440 ) = 0
Sum((n<= 523567 ,n|N),abs(mu(n)))-2^omega( 523567 ) = 0
* d * Sum((n<=N,n|N),mu(n)*tau(n))=(-1)^omega(n) *
Sum((n<= 1 ,n|N),mu(n)*tau(n))-(-1)^omega( 1 ) = 0
Sum((n<= 2 ,n|N),mu(n)*tau(n))-(-1)^omega( 2 ) = 0
Sum((n<= 3 ,n|N),mu(n)*tau(n))-(-1)^omega( 3 ) = 0
Sum((n<= 4 ,n|N),mu(n)*tau(n))-(-1)^omega( 4 ) = 0
Sum((n<= 20 ,n|N),mu(n)*tau(n))-(-1)^omega( 20 ) = 0
Sum((n<= 25 ,n|N),mu(n)*tau(n))-(-1)^omega( 25 ) = 0
Sum((n<= 154 ,n|N),mu(n)*tau(n))-(-1)^omega( 154 ) = 0
Sum((n<= 210 ,n|N),mu(n)*tau(n))-(-1)^omega( 210 ) = 0
Sum((n<= 576 ,n|N),mu(n)*tau(n))-(-1)^omega( 576 ) = 0
Sum((n<= 6930 ,n|N),mu(n)*tau(n))-(-1)^omega( 6930 ) = 0
Sum((n<= 22464 ,n|N),mu(n)*tau(n))-(-1)^omega( 22464 ) = 0
Sum((n<= 54000 ,n|N),mu(n)*tau(n))-(-1)^omega( 54000 ) = 0
Sum((n<= 104729 ,n|N),mu(n)*tau(n))-(-1)^omega( 104729 ) = 0
Sum((n<= 193440 ,n|N),mu(n)*tau(n))-(-1)^omega( 193440 ) = 0
Sum((n<= 523567 ,n|N),mu(n)*tau(n))-(-1)^omega( 523567 ) = 0
* e * Sum((n<=N,n|N),mu(n)*lamba(n))=2^omega(n) *
Sum((n<= 1 ,n|N),mobius(n)*liouvillefunction(n))-2^omega( 1 ) = 0
Sum((n<= 2 ,n|N),mobius(n)*liouvillefunction(n))-2^omega( 2 ) = 0
Sum((n<= 3 ,n|N),mobius(n)*liouvillefunction(n))-2^omega( 3 ) = 0
Sum((n<= 4 ,n|N),mobius(n)*liouvillefunction(n))-2^omega( 4 ) = 0
Sum((n<= 20 ,n|N),mobius(n)*liouvillefunction(n))-2^omega( 20 ) = 0
Sum((n<= 25 ,n|N),mobius(n)*liouvillefunction(n))-2^omega( 25 ) = 0
Sum((n<= 154 ,n|N),mobius(n)*liouvillefunction(n))-2^omega( 154 ) = 0
Sum((n<= 210 ,n|N),mobius(n)*liouvillefunction(n))-2^omega( 210 ) = 0
Sum((n<= 576 ,n|N),mobius(n)*liouvillefunction(n))-2^omega( 576 ) = 0
Sum((n<= 6930 ,n|N),mobius(n)*liouvillefunction(n))-2^omega( 6930 ) = 0
Sum((n<=22464,n|N),mobius(n)*liouvillefunction(n))-2^omega( 22464 ) = 0
Sum((n<=54000,n|N),mobius(n)*liouvillefunction(n))-2^omega( 54000 ) = 0
Sum((n<=104729,n|N),mobius(n)*liouvillefunction(n))-2^omega(104729) = 0
Sum((n<=193440,n|N),mobius(n)*liouvillefunction(n))-2^omega(193440) = 0
Sum((n<=523567,n|N),mobius(n)*liouvillefunction(n))-2^omega(523567) = 0
* f * Sum((n<=N,n|N),sigma(n))=N*Sum((n<=N,n|N),tau(n)/n) *
Sum((n<= 1 ,n|N),sigma(n,1))-Sum((n<= 1 n|N),tau(n)/n) = 0
Sum((n<= 2 ,n|N),sigma(n,1))-Sum((n<= 2 n|N),tau(n)/n) = 0
Sum((n<= 3 ,n|N),sigma(n,1))-Sum((n<= 3 n|N),tau(n)/n) = 0
Sum((n<= 4 ,n|N),sigma(n,1))-Sum((n<= 4 n|N),tau(n)/n) = 0
Sum((n<= 20 ,n|N),sigma(n,1))-Sum((n<= 20 n|N),tau(n)/n) = 0
Sum((n<= 25 ,n|N),sigma(n,1))-Sum((n<= 25 n|N),tau(n)/n) = 0
Sum((n<= 154 ,n|N),sigma(n,1))-Sum((n<= 154 n|N),tau(n)/n) = 0
Sum((n<= 210 ,n|N),sigma(n,1))-Sum((n<= 210 n|N),tau(n)/n) = 0
Sum((n<= 576 ,n|N),sigma(n,1))-Sum((n<= 576 n|N),tau(n)/n) = 0
Sum((n<= 6930 ,n|N),sigma(n,1))-Sum((n<= 6930 n|N),tau(n)/n) = 0
Sum((n<= 22464 ,n|N),sigma(n,1))-Sum((n<= 22464 n|N),tau(n)/n) = 0
Sum((n<= 54000 ,n|N),sigma(n,1))-Sum((n<= 54000 n|N),tau(n)/n) = 0
Sum((n<= 104729 ,n|N),sigma(n,1))-Sum((n<= 104729 n|N),tau(n)/n) = 0
Sum((n<= 193440 ,n|N),sigma(n,1))-Sum((n<= 193440 n|N),tau(n)/n) = 0
Sum((n<= 523567 ,n|N),sigma(n,1))-Sum((n<= 523567 n|N),tau(n)/n) = 0

Product over divisors (or prime divisors)

Here is the list of properties:
The implementation is:
print("* a * product((n<=N,n|N),n)=N^(tau(N)/2) *")
testa(N)=productoverdivisor(x,N,quote(x))-N^(tau(N)/2)
for(ind,1,dim(X),print("Product((n<=",X[ind],",n|N),n)-
    ",X[ind],"^(tau(",X[ind],")/2) =",testa(X[ind])))
print("* b * (-1)^omega(N)*product((n<=N,isprime(n)),n)=
    Sum((n<=N,n|N),mu(n)*sigma(n)) *")
testb(N)=(-1)^omega(N)*productoverprime(x,N,x)-
    sumoverdivisor(x,N,quote(mobius(x)*sigma(x,1)))
for(ind,1,dim(X),print("(-1)^omega(",X[ind],")*Product((n<=",X[ind],",
    isprime(n)), n)-Sum((n<=",X[ind],",n|N),mu(n)*sigma(n)) =",testb(X[ind])))
print("* c * (-1)^omega(N)*product((n<=N,isprime(n)),n-2)=
    Sum((n<=N,n|N),mu(n)*phi(n)) *")
testc(N)=(-1)^omega(N)*productoverprime(x,N,x-2)-
    sumoverdivisor(x,N,quote(mobius(x)*eulerphi(x)))
for(ind,1,dim(X),print("(-1)^omega(",X[ind],")*Product((n<=",X[ind],",
    isprime(n)), n-2)-Sum((n<=",X[ind],",n|N),mu(n)*phi(n)) =",testc(X[ind])))

And smib gives:
* a * product((n<=N,n|N),n)=N^(tau(N)/2) *
Product((n<= 1 ,n|N), n)- 1 ^(tau( 1 )/2) = 0
Product((n<= 2 ,n|N), n)- 2 ^(tau( 2 )/2) = 0
Product((n<= 3 ,n|N), n)- 3 ^(tau( 3 )/2) = 0
Product((n<= 4 ,n|N), n)- 4 ^(tau( 4 )/2) = 0
Product((n<= 20 ,n|N), n)- 20 ^(tau( 20 )/2) = 0
Product((n<= 25 ,n|N), n)- 25 ^(tau( 25 )/2) = 0
Product((n<= 154 ,n|N), n)- 154 ^(tau( 154 )/2) = 0
Product((n<= 210 ,n|N), n)- 210 ^(tau( 210 )/2) = 0
Product((n<= 576 ,n|N), n)- 576 ^(tau( 576 )/2) = 0
Product((n<= 6930 ,n|N), n)- 6930 ^(tau( 6930 )/2) = 0
Product((n<= 22464 ,n|N), n)- 22464 ^(tau( 22464 )/2) = 0
Product((n<= 54000 ,n|N), n)- 54000 ^(tau( 54000 )/2) = 0
Product((n<= 104729 ,n|N), n)- 104729 ^(tau( 104729 )/2) = 0
Product((n<= 193440 ,n|N), n)- 193440 ^(tau( 193440 )/2) = 0
Product((n<= 523567 ,n|N), n)- 523567 ^(tau( 523567 )/2) = 0
* b * (-1)^omega(N)*product((n<=N,isprime(n)),n)=Sum((n<=N,n|N),mu(n)*sigma(n))
(-1)^omega(1)*Product((n<=1,isprime(n)),n)-Sum((n<=1,n|N),mu(n)*sigma(n))=0
(-1)^omega(2)*Product((n<=2,isprime(n)),n)-Sum((n<=2,n|N),mu(n)*sigma(n))=0
(-1)^omega(3)*Product((n<=3,isprime(n)),n)-Sum((n<=3,n|N),mu(n)*sigma(n))=0
(-1)^omega(4)*Product((n<=4,isprime(n)),n)-Sum((n<=4,n|N),mu(n)*sigma(n))=0
(-1)^omega(20)*Product((n<=20,isprime(n)),n)-Sum((n<=20,n|N),mu(n)*sigma(n))=0
(-1)^omega(25)*Product((n<=25,isprime(n)),n)-Sum((n<=25,n|N),mu(n)*sigma(n))=0
(-1)^omega(154)*Product((n<=154,isprime(n)),n)-Sum((n<=154,n|N),mu(n)*sigma(n))=0
(-1)^omega(210)*Product((n<=210,isprime(n)),n)-Sum((n<=210,n|N),mu(n)*sigma(n))=0
(-1)^omega(576)*Product((n<=576,isprime(n)),n)-Sum((n<=576,n|N),mu(n)*sigma(n))=0
(-1)^omega(6930)*Product((n<=6930,isprime(n)),n)-Sum((n<=6930,n|N),mu(n)*sigma(n))=0
(-1)^omega(22464)*Product((n<=22464,isprime(n)),n)-Sum((n<=22464,n|N),mu(n)*sigma(n))=0
(-1)^omega(54000)*Product((n<=54000,isprime(n)),n)-Sum((n<=54000,n|N),mu(n)*sigma(n))=0
(-1)^omega(104729)*Product((n<=104729,isprime(n)),n)-Sum((n<=104729,n|N),mu(n)*sigma(n))=0
(-1)^omega(193440)*Product((n<=193440,isprime(n)),n)-Sum((n<=193440,n|N),mu(n)*sigma(n))=0
(-1)^omega(523567)*Product((n<=523567,isprime(n)),n)-Sum((n<=523567,n|N),mu(n)*sigma(n))=0
* c * (-1)^omega(N)*product((n<=N,isprime(n)),n-2)=Sum((n<=N,n|N),mu(n)*phi(n))
(-1)^omega(1)*Product((n<=1,isprime(n)),n-2)-Sum((n<=1,n|N),mu(n)*phi(n))=0
(-1)^omega(2)*Product((n<=2,isprime(n)),n-2)-Sum((n<=2,n|N),mu(n)*phi(n))=0
(-1)^omega(3)*Product((n<=3,isprime(n)),n-2)-Sum((n<=3,n|N),mu(n)*phi(n))=0
(-1)^omega(4)*Product((n<=4,isprime(n)),n-2)-Sum((n<=4,n|N),mu(n)*phi(n))=0
(-1)^omega(20)*Product((n<=20,isprime(n)),n-2)-Sum((n<=20,n|N),mu(n)*phi(n))=0
(-1)^omega(25)*Product((n<=25,isprime(n)),n-2)-Sum((n<=25,n|N),mu(n)*phi(n))=0
(-1)^omega(154)*Product((n<=154,isprime(n)),n-2)-Sum((n<=154,n|N),mu(n)*phi(n))=0
(-1)^omega(210)*Product((n<=210,isprime(n)),n-2)-Sum((n<=210,n|N),mu(n)*phi(n))=0
(-1)^omega(576)*Product((n<=576,isprime(n)),n-2)-Sum((n<=576,n|N),mu(n)*phi(n))=0
(-1)^omega(6930)*Product((n<=6930,isprime(n)),n-2)-Sum((n<=6930,n|N),mu(n)*phi(n))=0
(-1)^omega(22464)*Product((n<=22464,isprime(n)),n-2)-Sum((n<=22464,n|N),mu(n)*phi(n))=0
(-1)^omega(54000)*Product((n<=54000,isprime(n)),n-2)-Sum((n<=54000,n|N),mu(n)*phi(n))=0
(-1)^omega(104729)*Product((n<=104729,isprime(n)),n-2)-Sum((n<=104729,n|N),mu(n)*phi(n))=0
(-1)^omega(193440)*Product((n<=193440,isprime(n)),n-2)-Sum((n<=193440,n|N),mu(n)*phi(n))=0
(-1)^omega(523567)*Product((n<=523567,isprime(n)), n-2)-Sum((n<=523567,n|N),mu(n)*phi(n))=0

Dirichlet product

Here is the list of properties of Dirichlet product:
And implementation is given by:
print("* a * sigma = id * 1 *")
Sigma(n)=dirichletproduct(1,x,x,n)
for(ind,1,dim(X),print("Sigma(",X[ind],",1)-(id*1)(",X[ind],")=",
    Sigma(X[ind])-sigma(X[ind],1)))
print("* b * phi = mu * id *")
phi(n)=dirichletproduct(quote(mobius(x)),x,x,n)
for(ind,1,dim(X),print("phi(",X[ind],")-(mu*id)(",X[ind],")=",
    phi(X[ind])-eulerphi(X[ind])))
print("* c * sigma = tau * phi *")
tau(n)=dirichletproduct(1,1,x,n)
sigma2(n)=dirichletproduct(quote(tau(x)),quote(eulerphi(x)),x,n)
for(ind,1,dim(X),print("sigma(",X[ind],")-(tau*phi)(",X[ind],",1)=",
    sigma2(X[ind])-sigma(X[ind],1)))
print("* d * id = sigma * mu *")
testd(n)=dirichletproduct(quote(sigma(x,1)),quote(mobius(x)),x,n)-n
for(ind,1,dim(X),print("id(",X[ind],")-(sigma*mu)(",X[ind],")=",
    testd(X[ind])))
print("* e * id = phi * 1 *")
teste(n)=dirichletproduct(1,quote(eulerphi(x)),x,n)-n
for(ind,1,dim(X),print("id(",X[ind],")-(phi*1)(",X[ind],")=",teste(X[ind])))
print("* f * id tau = phi * sigma *")
testf(n)=dirichletproduct(quote(eulerphi(x)),quote(sigma(x,1)),x,n)-n*tau(n)
for(ind,1,dim(X),print("id tau(",X[ind],")-(phi*sigma)(",X[ind],")=",
    testf(X[ind])))
print("* g * id*sigma(n) = Sum((n<=N,n|N),n tau(n)) *")
testg(n)=dirichletproduct(quote(x),quote(sigma(x,1)),x,n)
    sumoverdivisor(x,n,quote(x*tau(x)))
for(ind,1,dim(X),print("(id*sigma)(",X[ind],")-
Sum((n<=",X[ind],"n|N),n*tau(n))=",testg(X[ind])))
print("* h * id^2*sigma(n) = Sum((n<=N,n|N),n sigma(n)) *")
testh(n)=dirichletproduct(quote(x^2),quote(sigma(x,1)),x,n)-
    sumoverdivisor(x,n,quote(x*sigma(x,1)))
for(ind,1,dim(X),print("(id^2*sigma)(",X[ind],")-
    Sum((n<=",X[ind],"n|N),n*sigma(n))=",testh(X[ind])))
print("* i * sigma*sigma(n) = (id tau)*tau *")
testi(n)=dirichletproduct(quote(sigma(x,1)),quote(sigma(x,1)),x,n)-
    dirichletproduct(quote(x*tau(x)),quote(tau(x)),x,n)
for(ind,1,dim(X),print("(sigma*sigma-(id tau)*tau)(",X[ind],")=",
    testi(X[ind])))
X=(1,2,3,4,20,25,154)
print("* j * Sum(n<=N,(tau(n)*mu(n)*lambda(n)))=log(N!) *")
testj(N)=sum(ind,1,N,dirichletproduct(dirichletproduct(quote(tau(x)),
    quote(mobius(x)),x,ind),quote(mangoldt(x)),x,ind))-log(N!)
for(ind,1,dim(X),print("Sum(n<=",X[ind],",(tau*mu*lambda)-
    log(",X[ind],"!) =",num(testj(X[ind]))))

And smib gives:
* a * sigma = id * 1 *
Sigma( 1 ,1)-(id*1)( 1 )= 0
Sigma( 2 ,1)-(id*1)( 2 )= 0
Sigma( 3 ,1)-(id*1)( 3 )= 0
Sigma( 4 ,1)-(id*1)( 4 )= 0
Sigma( 20 ,1)-(id*1)( 20 )= 0
Sigma( 25 ,1)-(id*1)( 25 )= 0
Sigma( 154 ,1)-(id*1)( 154 )= 0
Sigma( 210 ,1)-(id*1)( 210 )= 0
Sigma( 576 ,1)-(id*1)( 576 )= 0
Sigma( 6930 ,1)-(id*1)( 6930 )= 0
Sigma( 22464 ,1)-(id*1)( 22464 )= 0
Sigma( 54000 ,1)-(id*1)( 54000 )= 0
Sigma( 104729 ,1)-(id*1)( 104729 )= 0
Sigma( 193440 ,1)-(id*1)( 193440 )= 0
Sigma( 523567 ,1)-(id*1)( 523567 )= 0
* b * phi = mu * id *
phi( 1 )-(mu*id)( 1 )= 0
phi( 2 )-(mu*id)( 2 )= 0
phi( 3 )-(mu*id)( 3 )= 0
phi( 4 )-(mu*id)( 4 )= 0
phi( 20 )-(mu*id)( 20 )= 0
phi( 25 )-(mu*id)( 25 )= 0
phi( 154 )-(mu*id)( 154 )= 0
phi( 210 )-(mu*id)( 210 )= 0
phi( 576 )-(mu*id)( 576 )= 0
phi( 6930 )-(mu*id)( 6930 )= 0
phi( 22464 )-(mu*id)( 22464 )= 0
phi( 54000 )-(mu*id)( 54000 )= 0
phi( 104729 )-(mu*id)( 104729 )= 0
phi( 193440 )-(mu*id)( 193440 )= 0
phi( 523567 )-(mu*id)( 523567 )= 0
* c * sigma = tau * phi *
sigma( 1 )-(tau*phi)( 1 ,1)= 0
sigma( 2 )-(tau*phi)( 2 ,1)= 0
sigma( 3 )-(tau*phi)( 3 ,1)= 0
sigma( 4 )-(tau*phi)( 4 ,1)= 0
sigma( 20 )-(tau*phi)( 20 ,1)= 0
sigma( 25 )-(tau*phi)( 25 ,1)= 0
sigma( 154 )-(tau*phi)( 154 ,1)= 0
sigma( 210 )-(tau*phi)( 210 ,1)= 0
sigma( 576 )-(tau*phi)( 576 ,1)= 0
sigma( 6930 )-(tau*phi)( 6930 ,1)= 0
sigma( 22464 )-(tau*phi)( 22464 ,1)= 0
sigma( 54000 )-(tau*phi)( 54000 ,1)= 0
sigma( 104729 )-(tau*phi)( 104729 ,1)= 0
sigma( 193440 )-(tau*phi)( 193440 ,1)= 0
sigma( 523567 )-(tau*phi)( 523567 ,1)= 0
* d * id = sigma * mu *
id( 1 )-(sigma*mu)( 1 )= 0
id( 2 )-(sigma*mu)( 2 )= 0
id( 3 )-(sigma*mu)( 3 )= 0
id( 4 )-(sigma*mu)( 4 )= 0
id( 20 )-(sigma*mu)( 20 )= 0
id( 25 )-(sigma*mu)( 25 )= 0
id( 154 )-(sigma*mu)( 154 )= 0
id( 210 )-(sigma*mu)( 210 )= 0
id( 576 )-(sigma*mu)( 576 )= 0
id( 6930 )-(sigma*mu)( 6930 )= 0
id( 22464 )-(sigma*mu)( 22464 )= 0
id( 54000 )-(sigma*mu)( 54000 )= 0
id( 104729 )-(sigma*mu)( 104729 )= 0
id( 193440 )-(sigma*mu)( 193440 )= 0
id( 523567 )-(sigma*mu)( 523567 )= 0
* e * id = phi * 1 *
id( 1 )-(phi*1)( 1 )= 0
id( 2 )-(phi*1)( 2 )= 0
id( 3 )-(phi*1)( 3 )= 0
id( 4 )-(phi*1)( 4 )= 0
id( 20 )-(phi*1)( 20 )= 0
id( 25 )-(phi*1)( 25 )= 0
id( 154 )-(phi*1)( 154 )= 0
id( 210 )-(phi*1)( 210 )= 0
id( 576 )-(phi*1)( 576 )= 0
id( 6930 )-(phi*1)( 6930 )= 0
id( 22464 )-(phi*1)( 22464 )= 0
id( 54000 )-(phi*1)( 54000 )= 0
id( 104729 )-(phi*1)( 104729 )= 0
id( 193440 )-(phi*1)( 193440 )= 0
id( 523567 )-(phi*1)( 523567 )= 0
* f * id tau = phi * sigma *
id tau( 1 )-(phi*sigma)( 1 )= 0
id tau( 2 )-(phi*sigma)( 2 )= 0
id tau( 3 )-(phi*sigma)( 3 )= 0
id tau( 4 )-(phi*sigma)( 4 )= 0
id tau( 20 )-(phi*sigma)( 20 )= 0
id tau( 25 )-(phi*sigma)( 25 )= 0
id tau( 154 )-(phi*sigma)( 154 )= 0
id tau( 210 )-(phi*sigma)( 210 )= 0
id tau( 576 )-(phi*sigma)( 576 )= 0
id tau( 6930 )-(phi*sigma)( 6930 )= 0
id tau( 22464 )-(phi*sigma)( 22464 )= 0
id tau( 54000 )-(phi*sigma)( 54000 )= 0
id tau( 104729 )-(phi*sigma)( 104729 )= 0
id tau( 193440 )-(phi*sigma)( 193440 )= 0
id tau( 523567 )-(phi*sigma)( 523567 )= 0
* g * id*sigma(n) = Sum((n<=N,n|N),n tau(n)) *
(id*sigma)( 1 )-Sum((n<= 1 n|N),n*tau(n))= 0
(id*sigma)( 2 )-Sum((n<= 2 n|N),n*tau(n))= 0
(id*sigma)( 3 )-Sum((n<= 3 n|N),n*tau(n))= 0
(id*sigma)( 4 )-Sum((n<= 4 n|N),n*tau(n))= 0
(id*sigma)( 20 )-Sum((n<= 20 n|N),n*tau(n))= 0
(id*sigma)( 25 )-Sum((n<= 25 n|N),n*tau(n))= 0
(id*sigma)( 154 )-Sum((n<= 154 n|N),n*tau(n))= 0
(id*sigma)( 210 )-Sum((n<= 210 n|N),n*tau(n))= 0
(id*sigma)( 576 )-Sum((n<= 576 n|N),n*tau(n))= 0
(id*sigma)( 6930 )-Sum((n<= 6930 n|N),n*tau(n))= 0
(id*sigma)( 22464 )-Sum((n<= 22464 n|N),n*tau(n))= 0
(id*sigma)( 54000 )-Sum((n<= 54000 n|N),n*tau(n))= 0
(id*sigma)( 104729 )-Sum((n<= 104729 n|N),n*tau(n))= 0
(id*sigma)( 193440 )-Sum((n<= 193440 n|N),n*tau(n))= 0
(id*sigma)( 523567 )-Sum((n<= 523567 n|N),n*tau(n))= 0
* h * id^2*sigma(n) = Sum((n<=N,n|N),n sigma(n)) *
(id^2*sigma)( 1 )-Sum((n<= 1 n|N),n*sigma(n))= 0
(id^2*sigma)( 2 )-Sum((n<= 2 n|N),n*sigma(n))= 0
(id^2*sigma)( 3 )-Sum((n<= 3 n|N),n*sigma(n))= 0
(id^2*sigma)( 4 )-Sum((n<= 4 n|N),n*sigma(n))= 0
(id^2*sigma)( 20 )-Sum((n<= 20 n|N),n*sigma(n))= 0
(id^2*sigma)( 25 )-Sum((n<= 25 n|N),n*sigma(n))= 0
(id^2*sigma)( 154 )-Sum((n<= 154 n|N),n*sigma(n))= 0
(id^2*sigma)( 210 )-Sum((n<= 210 n|N),n*sigma(n))= 0
(id^2*sigma)( 576 )-Sum((n<= 576 n|N),n*sigma(n))= 0
(id^2*sigma)( 6930 )-Sum((n<= 6930 n|N),n*sigma(n))= 0
(id^2*sigma)( 22464 )-Sum((n<= 22464 n|N),n*sigma(n))= 0
(id^2*sigma)( 54000 )-Sum((n<= 54000 n|N),n*sigma(n))= 0
(id^2*sigma)( 104729 )-Sum((n<= 104729 n|N),n*sigma(n))= 0
(id^2*sigma)( 193440 )-Sum((n<= 193440 n|N),n*sigma(n))= 0
(id^2*sigma)( 523567 )-Sum((n<= 523567 n|N),n*sigma(n))= 0
* i * sigma*sigma(n) = (id tau)*tau *
(sigma*sigma-(id tau)*tau)( 1 )= 0
(sigma*sigma-(id tau)*tau)( 2 )= 0
(sigma*sigma-(id tau)*tau)( 3 )= 0
(sigma*sigma-(id tau)*tau)( 4 )= 0
(sigma*sigma-(id tau)*tau)( 20 )= 0
(sigma*sigma-(id tau)*tau)( 25 )= 0
(sigma*sigma-(id tau)*tau)( 154 )= 0
(sigma*sigma-(id tau)*tau)( 210 )= 0
(sigma*sigma-(id tau)*tau)( 576 )= 0
(sigma*sigma-(id tau)*tau)( 6930 )= 0
(sigma*sigma-(id tau)*tau)( 22464 )= 0
(sigma*sigma-(id tau)*tau)( 54000 )= 0
(sigma*sigma-(id tau)*tau)( 104729 )= 0
(sigma*sigma-(id tau)*tau)( 193440 )= 0
(sigma*sigma-(id tau)*tau)( 523567 )= 0
* j * Sum(n<=N,(tau(n)*mu(n)*lambda(n)))=log(N!) *
Sum(n<= 1 ,(tau*mu*lambda)-log( 1 !) = 0
Sum(n<= 2 ,(tau*mu*lambda)-log( 2 !) = 0
Sum(n<= 3 ,(tau*mu*lambda)-log( 3 !) = 0
Sum(n<= 4 ,(tau*mu*lambda)-log( 4 !) = -4.44089e-16
Sum(n<= 20 ,(tau*mu*lambda)-log( 20 !) = 7.10543e-15
Sum(n<= 25 ,(tau*mu*lambda)-log( 25 !) = 1.42109e-14
Sum(n<= 154 ,(tau*mu*lambda)-log( 154 !) = 1.13687e-13


5.1.4Arithmetic equations

Bombieri conjecture

Here, we want to solve the following equation:
x n  +  y n  =  z n ,  n≥3,  x, y, z≤20.
So in smib:
i=1
for(n,3,5,
    for(x,n,20,
        for(y,n,20,
            for(z,n,20,
                test(binomial(x,n)+binomial(y,n)-binomial(z,n)==0,
                    do(print("solution: ",i),
                       print("n=",n),
                       print("x=",x),
                       print("y=",y),
                       print("z=",z),
                       i=i+1
))))))

And the result is:
solution: 1
n= 3
x= 5
y= 5
z= 6
solution: 2
n= 3
x= 10
y= 16
z= 17
solution: 3
n= 3
x= 16
y= 10
z= 17
solution: 4
n= 4
x= 7
y= 7
z= 8
solution: 5
n= 5
x= 9
y= 9
z= 10

4τ(n + 2) = φ(n),  0≤n≤1000

So simply in smib:
for(n,1,1000, test(4*tau(n+2)-eulerphi(n)==0,print(n)))

And the result is:
15
32
60
64
68
90
102
110
130

σ(n, 1) = 2n + 1,  0≤n≤1000

So simply in smib:
for(n,1,1000, test(sigma(n,1)-2*n+1==0,print(n)))

And the result is:
1
2
4
8
16
32
64
128
256
512


5.1.5 Arithmetic & statistic

Let A(n) be the set of n first prime intergers, we want to study skewness and kurtosis of this set. In parallel, using prime number theorem, we can also study asymptotic behaviour of skewness and kurtosis. Using corollary of prime number theorem, let I(p, n) = 1nn1[xln(x) − 1nn1xln(x)dx]pdx, hence kurtosis is given by ku(n) = I(4, n)I(2, n)2 − 3, and skewness by sk(n) = I(3, n)I(2, n)32.

So in smib:
The next prime is define as:
nextprime(n)=test(isprime(n+1)==1,n+1,nextprime(n+1))
The set of n first primes:
listprime(n)=prog(temp,ind,do(
    temp=zero(n),
    for(ind,1,n,
        test(ind==1,
            temp[ind]=2,
            temp[ind]=nextprime(temp[ind-1]))),
    return(temp)))
And asymptotic behaviour by:
I(p,n)=1/n*defint((x*log(x)-1/n*defint(x*log(x),x,1,n))^p,x,1,n)
ku(n)=I(4,n)/I(2,n)^2-3
sk(n)=I(3,n)/I(2,n)^(3/2)

Now we can plot on same graphic:
figure image/ku.png
figure image/sk.png

5.1.6Gould number

The Gould number is defined by: (ln(6403203 + 744)π)2, here we want to compute numerically this number, so in smib:
gould=(log(640320^3+744)/pi)^2
print("gould=",gould)
print("num(gould)=",num(gould))

So the computation gives:
gould= log(262537412640768744)^2/(pi^2)
num(gould)= 163

Here we see a weakness of smib, Gould number is not an integer ...

5.1.7π computation (cooking π in ten lessons)

Here we want to test the following formulas:
  1. Wallis formula: π = 2j = ∞j = 1(2j2)(2j − 1)(2j + 1)
  2. From Wallis formula: π = j = ∞j = 02j + 1j!2(2j + 1)!
  3. Unknown man formula: π = 4(1 − j = ∞j = 1216j2 − 1)
  4. Wang formula: π = 4(183arctan(1239) + 32arctan(11023) − 68arctan(15832) + 
    12arctan(1110443) − 12arctan(14841182) − 100arctan(16826318))
  5. Using ζ Riemann function: π = (6j = ∞j = 11j2)
  6. Using sequence of prime numbers: π = (6j ∈ P11 − 1j2), where P is the set of prime numbers.
  7. Ramanujan formula: 1π = 2(2)9801j = ∞j = 1(4j)!(1103 + 26390j)(j!43964j)
  8. Chudnowsky formula: 1π = 12j = ∞j = 0( − 1)j(6j)!13591409 + 545140134j((3j)!j!3640320(3(j + 1 ⁄ 2)))
  9. Borwein-Borwein-Plouffe formula: π = j = ∞j = 016 − j[48j + 1 − 28j + 4 − 18j + 5 − 18j + 6]
  10. Bellard formula: π = j = ∞j = 0( − 1)j210j[ − 254j + 1 − 14j + 3 + 2810j + 1 − 2610j + 3
     − 2210j + 5 − 2210j + 7 + 110j + 9]
Those ten formulas can be implemented as:
prec=30
print("pi = ",num(pi))
print("Wallis: 2*product(ind,1,prec,(2*ind)^2/((2*ind-1)*(2*ind+1)))-pi=",
num(2*product(ind,1,prec,(2*ind)^2/((2*ind-1)*(2*ind+1)))-pi))
print("From Wallis: sum(ind,0,prec,2^(ind+1)*(ind!)^2/(2*ind+1)!)-pi=",
    num(sum(ind,0,prec,2^(ind+1)*(ind!)^2/(2*ind+1)!)-pi))
print("4*(1-sum(ind,1,prec,2/(16*ind^2-1)))-pi = ",
    num(4*(1-sum(ind,1,prec,2/(16*ind^2-1)))-pi))
print("Wang: 4*(183*arctan(1/239)+32*arctan(1/1023)-
    68*arctan(1/5832)+12*arctan(1/110443)-
    12*arctan(1/4841182)-100*arctan(1/6826318)-pi = ",
    num(4*(183*arctan(1/239)+32*arctan(1/1023)-
        68*arctan(1/5832)+12*arctan(1/110443)
        12*arctan(1/4841182)-100*arctan(1/6826318))-pi))
print("With zeta function: sqrt(6*sum(ind,1,prec,1/ind^2))-pi = ",
    num(sqrt(6*sum(ind,1,prec,1/ind^2))-pi))
print("With prime intergers: sqrt(6*product(ind,1,prec,test(isprime(ind)==1,
    1/(1-ind^(-2)),1))-pi = ",
    num(sqrt(6*product(ind,1,prec,test(isprime(ind)==1,1/(1-ind^(-2)),1)))-pi))
print("Ramanujan: 1/(2*sqrt(2)/9801*sum(ind,1,prec,
    (4*ind)!*(1103+26390*ind)/(ind!^4*396^(4*ind)))-pi = ",
    num(1/(2*sqrt(2)/9801*sum(ind,0,prec,(4*ind)!*
        (1103+26390*ind)/(ind!^4*396^(4*ind))))-pi))
print("Chudnowsky: 1/(12*sum(ind,0,prec,(-1)^ind*(6*ind)!*(13591409+545140134*ind)/
    ((3*ind)!*(ind!)^3*640320^(3*(ind+1/2)))-pi = ",
    num(1/(12*sum(ind,0,prec,(-1)^ind*(6*ind)!*(13591409+545140134*ind)/
        ((3*ind)!*(ind!)^3*640320^(3*(ind+1/2)))))-pi))
print("BBP: sum(ind,0,prec,16^(-ind)*(4/(8*ind+1)-2/(8*ind+4)-
    1/(8*ind+5)-1/(8*ind+6)))-pi = ",
    num(sum(ind,0,prec,16^(-ind)*(4/(8*ind+1)-2/(8*ind+4)-
        1/(8*ind+5)-1/(8*ind+6)))-pi))
print("Bellard: sum(ind,0,prec,(-1)^ind/2^(10*ind)*(-2^5/(4*ind+1)-
    1/(4*ind+3)+2^8/(10*ind+1)-2^6/(10*ind+3)-2^2/(10*ind+5)-
    2^2/(10*ind+7)+1/(10*ind+9))/2^6-pi = ",
    num(sum(ind,0,prec,(-1)^ind/2^(10*ind)*
    (-2^5/(4*ind+1)-1/(4*ind+3)+2^8/(10*ind+1)-2^6/(10*ind+3)-
        2^2/(10*ind+5)-2^2/(10*ind+7)+1/(10*ind+9)))/2^6-pi))

And smib gives :
pi = 3.14159
Wallis : 2*product(ind,1,prec,(2*ind)^2/((2*ind-1)*(2*ind+1)))-pi = -0.0256444
From Wallis : sum(ind,0,prec,2^(ind+1)*(ind!)^2/(2*ind+1)!)-pi = -2.88634e-10
4*(1-sum(ind,1,prec,2/(16*ind^2-1)))-pi = 0.0163923
Wang : 4*(183*arctan(1/239)+32*arctan(1/1023)-68*arctan(1/5832)+
12*arctan(1/110443)-12*arctan(1/4841182)-100*arctan(1/6826318)-pi = 0
With zeta function : sqrt(6*sum(ind,1,prec,1/ind^2))-pi = -0.0314639
With prime intergers :
sqrt(6*product(ind,1,prec,test(isprime(ind)==1,1/(1-ind^(-2)),1))-pi = -0.0113494
Ramanujan : 1/(2*sqrt(2)/9801*
sum(ind,1,prec,(4*ind)!*(1103+26390*ind)/(ind!^4*396^(4*ind)))-pi = 4.44089e-16
Chudnowsky : 1/(12*sum(ind,0,prec,(-1)^ind*(6*ind)!*(13591409+
545140134*ind)/((3*ind)!*(ind!)^3*640320^(3*(ind+1/2)))-pi = 4.44089e-16
BBP : sum(ind,0,prec,16^(-ind)*(4/(8*ind+1)-
2/(8*ind+4)-1/(8*ind+5)-1/(8*ind+6)))-pi = 0
Bellard : sum(ind,0,prec,(-1)^ind/2^(10*ind)*(-2^5/(4*ind+1)
-1/(4*ind+3)+2^8/(10*ind+1)-2^6/(10*ind+3)-2^2/(10*ind+5)-
2^2/(10*ind+7)+1/(10*ind+9))/2^6-pi = 0


5.2 Function manipulation applied to quantum mechanic

5.2.1Operator definition

Here are some operators which are used in quantum mechanic:
So in smib:
opemode=0
f=quote(f)
x=quote(x)
print("Creation ")
aplus(f,x)=(x*f-d(f,x))/sqrt(2)
print("Annihilation")
a(f,x)=(x*f+d(f,x))/sqrt(2)
print("Operator X")
X(f,x)=sqrt(2)*(a(f,x)+aplus(f,x))/2
print("Operator P")
P(f,x)=i*sqrt(2)*(-a(f,x)+aplus(f,x))/2
print("Number of quanta")
N(f,x)=aplus(a(f,x),x)
print(" Hamiltonian")
H(f,x)=N(f,x)+f/2
print("Commutator")
commutator1(f,x)=a(aplus(f,x),x)-aplus(a(f,x),x)
commutator2(f,x)=N(a(f,x),x)-a(N(f,x),x)
commutator3(f,x)=N(aplus(f,x),x)-aplus(N(f,x),x)
commutator4(f,x)=X(P(f,x),x)-P(X(f,x),x)

5.2.2Operator acting on function

Now, we are going to see how operators and commutator act on a function:
[a, a + ](f) = f,
[N, a](f) = a(f),
[N, a + ](f) = a + (f),
[X, P](f) = if,
N(a(f)) = a(N(f) − f),
N(a + (f)) = a + (N(f) + f).

So in smib:
print("Operator X acting on fonction")
X(f(x),x)
print("Operator P acting on fonction")
P(f(x),x)
print("Operator creation acting on fonction")
aplus(f(x),x)
print("Operator annihilation acting on fonction")
a(f(x),x)
print("Operator number of quanta acting on fonction")
N(f(x),x)
print("Operator hamiltonian acting on fonction")
H(f(x),x)
print("Commutator")
print("We note that for all f: [a,aplus](f)=f ")
commutator1(f(x),x)
commutator1(f(x),x)-f(x)
print("We note that for all f: [N,a](f)=-a(f)")
commutator2(f(x),x)
commutator2(f(x),x)+a(f(x),x)
print("We note that for all f:[N,aplus](f)=aplus(f)")
commutator3(f(x),x)
commutator3(f(x),x)-aplus(f(x),x)
print("We note that for all f: [x,p](f)=i*f")
commutator4(f(x),x)
commutator4(f(x),x)-i*f(x)
print("Creation annihilation & number of quanta")
print("We note that for all f: N(a(f,x)=a(N(f,x)-f,x)")
N(a(f(x),x),x) N(a(f(x),x),x)-a(N(f(x),x)-f(x),x)
print("We note that for all f: N(aplus(f,x)=aplus(N(f,x)+f,x)")
N(aplus(f(x),x),x) N(aplus(f(x),x),x)-aplus(N(f(x),x)+f(x),x)

5.2.3 Comparison with analytic solution

Now, we are going to study analytic solution (using Hermite function).
So in smib:
nexp=4
print("Computation of |n> of n in {0..",nexp,"}, and |n> acting on operator:")
print(" N|n>=n*|n>")
print(" H|n>=(n+1/2)*|n>")
print(" Comparison of |n> with analytic solution
g(x,n)=exp(-x^2/2)*hermite(x,n)/sqrt(sqrt(pi)*n!*2^n)")
f=quote(f)
g=quote(g)
g(x,n)=exp(-x^2/2)*hermite(x,n)/sqrt(sqrt(pi)*n!*2^n)
print("We solve a|0>=0")
A=a(f(x),x)
print("<x|0>")
A=dsolve(A,f(x),x)
print("Normalisation L^2 ")
C=1
A=eval(A*pi^(-1/4))
for(ind,1,nexp,do(A=factor(A), print("A = ",A),
print("Action of X: ",factor(X(A,x))),
print("Action of P: ",factor(P(A,x))),
print("Action of N: ",factor(N(A,x))),
print("Action of H: ",factor(H(A,x))),
print("Comparison with analytic solution: ",eval(rationalize(A-g(x,ind-1)))),
A=aplus(A,x)/sqrt(ind),
print("<x|",ind,">=<x|aplus|",ind - 1,">=",A) ))

And smib gives:
Computation of |n> for n in {0.. 5 }, and |n> acting on operator:
N|n>=n*|n>
H|n>=(n+1/2)*|n>
Comparison of |n> with analytic solution
g(x,n)=exp(-x^2/2)*hermite(x,n)/sqrt(sqrt(pi)*n!*2^n)
We solve a|0>=0 <x|0>
Normalisation L^2 A = exp(-1/2*x^2)/(pi^(1/4))
Action of X: x*exp(-1/2*x^2)/(pi^(1/4))
Action of P: i*x*exp(-1/2*x^2)/(pi^(1/4))
Action of N: 0 Action de H: exp(-1/2*x^2)/(2*pi^(1/4))
Comparison with analytic solution: 0
<x| 1 >=<x|aplus| 0 >= 2^(1/2)*x*exp(-1/2*x^2)/(pi^(1/4))
A = 2^(1/2)*x*exp(-1/2*x^2)/(pi^(1/4))
Action of X: 2^(1/2)*x^2*exp(-1/2*x^2)/(pi^(1/4))
Action of P: 2^(1/2)*exp(-1/2*x^2)*(i*x^2-i)/(pi^(1/4))
Action of N: 2^(1/2)*x*exp(-1/2*x^2)/(pi^(1/4))
Action of H: 3*x*exp(-1/2*x^2)/(2^(1/2)*pi^(1/4))
Comparison with analytic solution: 0
<x| 2 >=<x|aplus| 1 >=
-exp(-1/2*x^2)/(2^(1/2)*pi^(1/4))+2^(1/2)*x^2*exp(-1/2*x^2)/(pi^(1/4))
A = exp(-1/2*x^2)*(-1+2*x^2)/(2^(1/2)*pi^(1/4))
Action of X: x*exp(-1/2*x^2)*(-1+2*x^2)/(2^(1/2)*pi^(1/4))
Action of P: i*x*exp(-1/2*x^2)*(-5+2*x^2)/(2^(1/2)*pi^(1/4))
Action of N: 2^(1/2)*exp(-1/2*x^2)*(-1+2*x^2)/(pi^(1/4))
Action of H: 5*exp(-1/2*x^2)*(-1+2*x^2)/(2*2^(1/2)*pi^(1/4))
Comparison with analytic solution: 0
<x| 3 >=<x|aplus| 2 >=
2*x^3*exp(-1/2*x^2)/(3^(1/2)*pi^(1/4))-3^(1/2)*x*exp(-1/2*x^2)/(pi^(1/4))
A = x*exp(-1/2*x^2)*(-3+2*x^2)/(3^(1/2)*pi^(1/4))
Action of X: x^2*exp(-1/2*x^2)*(-3+2*x^2)/(3^(1/2)*pi^(1/4))
Action of P: i*exp(-1/2*x^2)*(3-9*x^2+2*x^4)/(3^(1/2)*pi^(1/4))
Action of N: 3^(1/2)*x*exp(-1/2*x^2)*(-3+2*x^2)/(pi^(1/4))
Action of H: 7*x*exp(-1/2*x^2)*(-3+2*x^2)/(2*3^(1/2)*pi^(1/4))
Comparison with analytic solution: 0
<x| 4 >=<x|aplus| 3 >=
3^(1/2)*exp(-1/2*x^2)/(2*2^(1/2)*pi^(1/4))+
2^(1/2)*x^4*exp(-1/2*x^2)/(3^(1/2)*pi^(1/4))-
2^(1/2)*3^(1/2)*x^2*exp(-1/2*x^2)/(pi^(1/4))
A = exp(-1/2*x^2)*(3-12*x^2+4*x^4)/(2*2^(1/2)*3^(1/2)*pi^(1/4))
Action of X: x*exp(-1/2*x^2)*(3-12*x^2+4*x^4)/(2*2^(1/2)*3^(1/2)*pi^(1/4))
Action of P: i*x*exp(-1/2*x^2)*(27-28*x^2+4*x^4)/(2*2^(1/2)*3^(1/2)*pi^(1/4))
Action of N: 2^(1/2)*exp(-1/2*x^2)*(3-12*x^2+4*x^4)/(3^(1/2)*pi^(1/4))
Action of H: 3*3^(1/2)*exp(-1/2*x^2)*(3-12*x^2+4*x^4)/(4*2^(1/2)*pi^(1/4))
Comparison with analytic solution: 0


5.3 Differential geometry

5.3.1 Curves

Planar curves

Here we want to study parametric planar curves t:[a, b]v⃗(t), we want to compute tangent vector T⃗ = v⃗̇v⃗̇, normal vector N⃗ =  0  − 1 1 0 T⃗, and curvature curR = v⃗̇3∥v⃗̇v⃗̈, so in smib:
curve2D(A,X)=prog(temp,temp1,temp2,
    do(temp1=d(A,X),
    temp2=d(temp1,X),
    T=quote(T),T=simplify(temp1/normP(temp1)),
    N=quote(N),N=inner(((0,-1),(1,0)),T),
    curR=quote(curR),curR=simplify(normP(temp1)^3/cross2P(temp1,temp2))
))

And for a circle:
Circle=(r*cos(t),r*sin(t))
print("Circle’s case:")
curve2D(Circle,t)
print("Tangent vector: T=",T)
print("Normal vector: N=",N)
print("Curvature: curR=",curR)

And the smib gives:
Circle’s case:
Tangent vector: T= (-sin(t),cos(t))
Normal vector: N= (-cos(t),-sin(t))
Curvature: curR= r

3D curves

And in 3D we have the following notions for a 3D parametric curve t:[a, b]v⃗(t), we want to compute: tangent vector T⃗ = v⃗̇v⃗̇, normal vector N⃗ = T⃗̇T⃗̇, binormal vector B⃗ = T⃗N⃗, curvature curR = v⃗̇3∥v⃗̇v⃗̈, and torsion curT = ∥v⃗̇v⃗̈(v⃗̇v⃗̈).\overset...v⃗,  so in smib:
curve3D(A,X)=prog(temp,temp1,temp2,temp3,
    do(temp1=d(A,X),
    temp2=d(temp1,X),
    temp3=d(temp2,X),
    T=quote(T),T=simplify(temp1/normP(temp1)),
    temp=d(T,X),
    N=quote(N),N=simplify(temp/normP(temp)),
    B=quote(B),B=simplify(crossP(T,N)),
    curR=quote(curR),
    curR=simplify(normP(temp1)^3/normP(crossP(temp1,temp2))),
    curT=quote(curT),
    curT=-simplify(normP(crossP(temp1,temp2))/tripleSP(temp1,temp2,temp3))
))

And we apply this to helix:
print("Helix case:")
h=quote(h)
r=quote(r)
Helix=(r*cos(t),r*sin(t),h*t)
curve3D(Helix,t)
print("Tangent vector: T=",T)
print("Normal vector: N=",N)
print("Binormal vector: B=",B)
print("Curvature: curR=",curR)
print("Torsion: curT=",curT)

And smib gives:
Helix case:
Tangent vector:
T= (r*sin(t)/((h^2+r^2)^(1/2)),r*cos(t)/((h^2+r^2)^(1/2)),h/((h^2+r^2)^(1/2)))
Normal vector: N= (cos(t),-sin(t),0)
Binormal vector:
B= (h*sin(t)/((h^2+r^2)^(1/2)),h*cos(t)/((h^2+r^2)^(1/2)),r/((h^2+r^2)^(1/2)))
Curvature: curR= r+h^2/r
Torsion: curT= -(h^2+r^2)^(1/2)/(h*r)


5.3.2Theory of surfaces

After curves, we are logically going to study surfaces, first we start with gaussian theory which is efficient with 2D surfaces, and after with riemannian theory which is efficient in all dimension.
Let S:(u, v)(x1(u, v), x2(u, v), x3(u, v)) be a map discribing a 2D surface, we want to compute:
So in smib:
gauss(A,X)=prog(temp1,temp2,temp11,temp12,temp22,
    do(temp1=d(A,X[1]),
       temp2=d(A,X[2]),
       temp11=d(temp1,X[1]),
       temp12=d(temp1,X[2]),
       temp22=d(temp2,X[2]),
       E=quote(E),E=simplify(dotP(temp1,temp1)),
       F=quote(F),F=simplify(dotP(temp1,temp2)),
       G=quote(G),G=simplify(dotP(temp2,temp2)),
       I=quote(I),I=((E,F),(F,G)),
       g=quote(g),g=simplify(det(I)),
       h=quote(h),
       h=simplify(simplify(crossP(temp1,temp2)/
          sqrt(dotP(crossP(temp1,temp2),crossP(temp1,temp2))))),
       h1=quote(h1),h1=simplify(d(h,X[1])),
       h2=quote(h2),h2=simplify(d(h,X[2])),
       L=quote(L),L=simplify(dotP(h,temp11)),
       M=quote(M),M=simplify(dotP(h,temp12)),
       N=quote(N),N=simplify(dotP(h,temp22)),
       II=quote,II=simplify(((L,M),(M,N))),
       b=quote(b),b=det(II),
       W=quote(W),W=simplify(inner(II,inv(I))),
       H=quote(H),H=simplify(contr(W,1,2)/2),
       K=quote(K),K=simplify(det(W)),
       chi1=quote(chi1),chi2=quote(chi2),
       chi1=simplify(H+sqrt(H^2-K)),
       chi2=simplify(H-sqrt(H^2-K)),
       S=test(chi1==chi2,1,
              2*(arctan(simplify((chi1+chi2)/(chi1-chi2))))/pi),
       C=quote(C),C=2*(log(simplify(sqrt(chi1^2+chi2^2)/2)))/pi
))
We could test too Gauss equations, Gauss theorem, Mainardi-Codazzi equations, and Bonnet theorem, those tests could be implemented as:

    bonnet(E,F,G,L,M,N)=prog(temp1,temp2,
    do(b=simplify(L*N-M^2),
       g=simplify(E*G-F^2),
       G111=simplify((d(E,X[1])*G-2*F*d(F,X[1])+d(E,X[2])*F)/(2*g)),
       G211=simplify((-d(E,X[1])*F-2*E*d(F,X[1])+d(E,X[2])*E)/(2*g)),
       G112=simplify((d(E,X[2])*G-F*d(G,X[1]))/(2*g)),
       G121=G112,
       G212=simplify((d(G,X[1])*E-F*d(E,X[2]))/(2*g)),
       G221=G212,
       G122=simplify(-(d(G,X[2])*F-2*F*d(G,X[2])+d(G,X[1])*G)/(2*g)),
       G222=simplify((d(G,X[2])*E-2*F*d(F,X[2])+d(G,X[1])*F)/(2*g)),
       temp1=simplify(F*b/g),
       temp2=simplify(d(G112,X[1])-d(G111,X[2])+
              G112*G212-G211*G122),
       check(temp1-temp2),
           print("Gauss 1st equation: ok"),
       temp1=simplify(-E*b/g),
       temp2=simplify(d(G212,X[1])-d(G211,X[2])+
              G112*G211-G211*G222+ G212*(G212-G111)),
       check(temp1-temp2),
          print("Gauss 2nd equation: ok"),
       temp1=simplify(G*b/g),
       temp2=simplify(d(G122,X[1])-d(G112,X[2])+
            G111*G122-G212*G122+G112*(G222-G112)),
       check(temp1-temp2),
          print("Gauss 3rd equation: ok"),
       temp1=simplify(F*b/g),
       temp2=simplify(d(G222,X[1])-d(G212,X[2])+G112*G211-G122*G211),
       check(temp1-temp2),
          print("Gauss 4th equation: ok"),
          print("Gauss’s theorem:ok"),
       temp1=simplify(d(L,X[2])-d(M,X[1])),
       temp2=simplify(G112*L+(G212-G111)*M-G211*N),
       check(temp1-temp2),
          print("Mainardi-Codazzi 1st equation: ok"),
       temp1=simplify(d(M,X[2])-d(N,X[1])),
       temp2=simplify(G122*L+(G222-G112)*M-G212*N),
       check(temp1-temp2),
          print("Mainardi-Codazzi 2nd equation: ok"),
          print("Bonnet’s theorem:ok")))

Now, we are going to test it on:

A sphere:
Sphere case: (cos(v)*sin(u),sin(u)*sin(v),cos(u))
First form: I= ((1,0),(0,sin(u)^2))
Determinant of first form: g= sin(u)^2
Normal vector: h= (cos(v)*sin(u),sin(u)*sin(v),cos(u))
Second form: II= ((-1,0),(0,-sin(u)^2))
Weingarten’s operator: W= ((-1,0),(0,-1))
Mean curvature: H= -1
Gaussian curvature: K= 1
Principal curvatures:
chi1: -1
chi2: -1
Shape index: S= 1
Curvedness: C= -log(2)/pi
Gauss 1st equation: ok
Gauss 2nd equation: ok
Gauss 3rd equation: ok
Gauss 4th equation: ok
Gauss ’s theorem:ok
Mainardi-Codazzi 1st equation: ok
Mainardi-Codazzi 2nd equation: ok
Bonnet’s theorem:ok

A cylinder:
Cylinder case: (sin(u),cos(u),v)
First form: I= ((1,0),(0,1))
Determinant of first form: g= 1
Normal vector: h= (-sin(u),-cos(u),0)
Second form: II= ((1,0),(0,0))
Weingarten’s operator: W= ((1,0),(0,0))
Mean curvature: H= 1/2
Gaussian curvature: K= 0
Principal curvatures:
chi1: 1
chi2: 0
Shape index: S= 1/2
Curvedness: C= -2*log(2)/pi
Gauss 1st equation: ok
Gauss 2nd equation: ok
Gauss 3rd equation: ok
Gauss 4th equation: ok
Gauss theorem: ok
Mainardi-Codazzi 1st equation: ok
Mainardi-Codazzi 2nd equation: ok
Bonnet theorem: ok


A torus:
Torus case: (cos(u)+cos(u)*cos(v),cos(v)*sin(u)+sin(u),sin(v))
First form: I= ((1+2*cos(v)+cos(v)^2,0),(0,1))
Determinant of first form: g= 1+2*cos(v)+cos(v)^2
Normal vector: h= (cos(u)*cos(v),cos(v)*sin(u),sin(v))
Second form: II= ((-1-cos(v)+sin(v)^2,0),(0,-1))
Weingarten’s operator: W= ((-cos(v)/(1+2*cos(v)+cos(v)^2)+
sin(v)^2/(1+2*cos(v)+cos(v)^2)-1/(1+2*cos(v)+cos(v)^2),0),(0,-1))
Mean curvature: H= -1/2-cos(v)/(2+4*cos(v)+2*cos(v)^2)+
sin(v)^2/(2+4*cos(v)+2*cos(v)^2)-1/(2+4*cos(v)+2*cos(v)^2)
Gaussian curvature: K= cos(v)/(1+2*cos(v)+cos(v)^2)-sin(v)^2/(1+2*cos(v)+cos(v)^2)+
1/(1+2*cos(v)+cos(v)^2)
Principal curvature:
chi1: -1/2-cos(v)/(2+4*cos(v)+2*cos(v)^2)-cos(v)^2/(2+4*cos(v)+2*cos(v)^2)+
(1/4-cos(v)/(1+2*cos(v)+cos(v)^2)-cos(v)^2/(1+2*cos(v)+cos(v)^2)+
cos(v)^2/((2+4*cos(v)+2*cos(v)^2)^2)+2*cos(v)^3/((2+4*cos(v)+2*cos(v)^2)^2)+
cos(v)^4/((2+4*cos(v)+2*cos(v)^2)^2)+cos(v)/(2+4*cos(v)+2*cos(v)^2)+
cos(v)^2/(2+4*cos(v)+2*cos(v)^2))^(1/2)
chi2: -1+cos(v)/(2+4*cos(v)+2*cos(v)^2)-(1/4-cos(v)/(1+2*cos(v)+cos(v)^2)-
cos(v)^2/(1+2*cos(v)+cos(v)^2)+cos(v)^2/((2+4*cos(v)+2*cos(v)^2)^2)+
2*cos(v)^3/((2+4*cos(v)+2*cos(v)^2)^2)+cos(v)^4/((2+4*cos(v)+2*cos(v)^2)^2)+
cos(v)/(2+4*cos(v)+2*cos(v)^2)+cos(v)^2/(2+4*cos(v)+2*cos(v)^2))^(1/2)+
1/(2+4*cos(v)+2*cos(v)^2)
Shape index: S= 2*arctan(2*(-2-10*cos(v)-18*cos(v)^2-14*cos(v)^3-
4*cos(v)^4)/((1/2-2*cos(v)/(2+4*cos(v)+2*cos(v)^2)-
cos(v)^2/(2+4*cos(v)+2*cos(v)^2)+2*(1/4-cos(v)/(1+2*cos(v)+cos(v)^2)-
cos(v)^2/(1+2*cos(v)+cos(v)^2)+cos(v)^2/((2+4*cos(v)+2*cos(v)^2)^2)+
2*cos(v)^3/((2+4*cos(v)+2*cos(v)^2)^2)+cos(v)^4/((2+4*cos(v)+2*cos(v)^2)^2)+
cos(v)/(2+4*cos(v)+2*cos(v)^2)+cos(v)^2/(2+4*cos(v)+2*cos(v)^2))^(1/2)-
1/(2+4*cos(v)+2*cos(v)^2))*(2+4*cos(v)+2*cos(v)^2)^2))/pi
Curvedness: C= -2*log(2)/pi+log(7/4-2*(1/4-cos(v)/(1+2*cos(v)+cos(v)^2)-
cos(v)^2/(1+2*cos(v)+cos(v)^2)+cos(v)^2/((2+4*cos(v)+2*cos(v)^2)^2)+
2*cos(v)^3/((2+4*cos(v)+2*cos(v)^2)^2)+cos(v)^4/((2+4*cos(v)+
2*cos(v)^2)^2)+cos(v)/(2+4*cos(v)+2*cos(v)^2)+
cos(v)^2/(2+4*cos(v)+2*cos(v)^2))^(1/2)/(2+4*cos(v)+2*cos(v)^2)-
4*(1/4-cos(v)/(1+2*cos(v)+cos(v)^2)-cos(v)^2/(1+2*cos(v)+cos(v)^2)+
cos(v)^2/((2+4*cos(v)+2*cos(v)^2)^2)+2*cos(v)^3/((2+4*cos(v)+2*cos(v)^2)^2+
cos(v)^4/((2+4*cos(v)+2*cos(v)^2)^2)+cos(v)/(2+4*cos(v)+2*cos(v)^2)+
cos(v)^2/(2+4*cos(v)+2*cos(v)^2))^(1/2)*cos(v)/(2+4*cos(v)+2*cos(v)^2)-
2*(1/4-cos(v)/(1+2*cos(v)+cos(v)^2)-cos(v)^2/(1+2*cos(v)+cos(v)^2)+
cos(v)^2/((2+4*cos(v)+2*cos(v)^2)^2)+2*cos(v)^3/((2+4*cos(v)+
2*cos(v)^2)^2)+cos(v)^4/((2+4*cos(v)+2*cos(v)^2)^2)+
cos(v)/(2+4*cos(v)+2*cos(v)^2)+cos(v)^2/(2+4*cos(v)+
2*cos(v)^2))^(1/2)*cos(v)^2/(2+4*cos(v)+2*cos(v)^2)-
2*cos(v)/(1+2*cos(v)+cos(v)^2)-2*cos(v)^2/(1+2*cos(v)+cos(v)^2)+
2*cos(v)/((2+4*cos(v)+2*cos(v)^2)^2)+4*cos(v)^2/((2+4*cos(v)+2*cos(v)^2)^2)
+6*cos(v)^3/((2+4*cos(v)+2*cos(v)^2)^2)+
3*cos(v)^4/((2+4*cos(v)+2*cos(v)^2)^2)+cos(v)/(2+4*cos(v)+2*cos(v)^2)+
3*cos(v)^2/(2+4*cos(v)+2*cos(v)^2)+(1/4-cos(v)/(1+2*cos(v)+cos(v)^2)-
cos(v)^2/(1+2*cos(v)+cos(v)^2)+cos(v)^2/((2+4*cos(v)+2*cos(v)^2)^2)+
2*cos(v)^3/((2+4*cos(v)+2*cos(v)^2)^2)+cos(v)^4/((2+4*cos(v)+2*cos(v)^2)^2)+
cos(v)/(2+4*cos(v)+2*cos(v)^2)+cos(v)^2/(2+4*cos(v)+2*cos(v)^2))^(1/2)+
(2+4*cos(v)+2*cos(v)^2)^(-2)-2/(2+4*cos(v)+2*cos(v)^2))/pi

As we could see simplification felt out for torus... Another smib weakness!

5.3.3Riemannian geometry

Instead of using a parametric representation of a surface, we use notion of metric. Hereafter are some examples in several dimensions, we compute connection coefficient, Riemann tensor, Ricci tensor, Ricci curvature , and Laplace operator.
Nil: ds2 = dx2 + dy2 + ( − xdy + dz)2
X=(x,y,z)
print("Nil")
A=((1,0,0),(0,1+x^2,-x),(0,-x,1))
riemann(A,X)
print("Metric: gdd=",gdd)
print("Connection: GAMUDD=",GAMUDD)
print("Riemann tensor RUDDD=",RUDDD)
print("Ricci tensor RDD=",RDD)
print("Ricci Curvature R=",R)
f=quote(f)
print("LaplF(f(X),X)=",LaplF(f(X),X))
print(" ")

And smib gives:
Metric: gdd= ((1,0,0),(0,1+x^2,-x),(0,-x,1))
Connection: GAMUDD=
(((0,0,0),(0,-x,1/2),(0,1/2,0)),
((0,1/2*x,-1/2),(1/2*x,0,0),(-1/2,0,0)),
((0,-1/2+1/2*x^2,-1/2*x),(-1/2+1/2*x^2,0,0),(-1/2*x,0,0)))
Riemann tensor RUDDD=
((((0,0,0),(0,0,0),(0,0,0)),
((0,-3/4+1/4*x^2,-1/4*x),(3/4-1/4*x^2,0,0),(1/4*x,0,0)),
((0,-1/4*x,1/4),(1/4*x,0,0),(-1/4,0,0))),
(((0,3/4,0),(-3/4,0,0),(0,0,0)),
((0,0,0),(0,0,-1/4*x),(0,1/4*x,0)),
((0,0,0),(0,0,1/4),(0,-1/4,0))),
(((0,x,-1/4),(-x,0,0),(1/4,0,0)),
((0,0,0),(0,0,-1/4-1/4*x^2),(0,1/4+1/4*x^2,0)),
((0,0,0),(0,0,1/4*x),(0,-1/4*x,0))))
Ricci tensor RDD=
((-1/2,0,0),(0,-1/2+1/2*x^2,-1/2*x),(0,-1/2*x,1/2))
Ricci Curvature R= -1/2
LaplF(f(X),X)=
d(d(f((x,y,z)),x),x)+d(d(f((x,y,z)),y),y)+d(d(f((x,y,z)),z),z)+
2*x*d(d(f((x,y,z)),y),z)+x^2*d(d(f((x,y,z)),z),z)

Sol: ds2 = e2xds2 + e − 2xdy2 + dz2
X=(x,y,z)
print("Sol")
A=((exp(2*x),0,0),(0,exp(-2*x),0),(0,0,1))
riemann(A,X)
print("Metric: gdd=",gdd)
print("Connection: GAMUDD=",GAMUDD)
print("Riemann tensor RUDDD=",RUDDD)
print("Ricci tensor RDD=",RDD)
print("Ricci Curvature R=",R)
f=quote(f)
print("LaplF(f(X),X)=",LaplF(f(X),X))

And smib gives:
Sol
Metric: gdd= ((exp(2*x),0,0),(0,exp(-2*x),0),(0,0,1))
Connection: GAMUDD=
(((1,0,0),(0,exp(-4*x),0),(0,0,0)),
((0,-1,0),(-1,0,0),(0,0,0)),
((0,0,0),(0,0,0),(0,0,0)))
Riemann tensor RUDDD=
((((0,0,0),(0,0,0),(0,0,0)),
((0,-2*exp(-4*x),0),(2*exp(-4*x),0,0),(0,0,0)),
((0,0,0),(0,0,0),(0,0,0))),
(((0,2,0),(-2,0,0),(0,0,0)),
((0,0,0),(0,0,0),(0,0,0)),
((0,0,0),(0,0,0),(0,0,0))),
(((0,0,0),(0,0,0),(0,0,0)),
((0,0,0),(0,0,0),(0,0,0)),
((0,0,0),(0,0,0),(0,0,0))))
Ricci tensor RDD= ((-2,0,0),(0,-2*exp(-4*x),0),(0,0,0))
Ricci Curvature R= -4*exp(-2*x)
LaplF(f(X),X)= d(d(f((x,y,z)),z),z)+exp(-2*x)*d(d(f((x,y,z)),x),x)
-2*exp(-2*x)*d(f((x,y,z)),x)+exp(2*x)*d(d(f((x,y,z)),y),y)

Schwarzschild metric:
X=(x1,x2,x3,x4)
gdd=((-x1/(x1-a),0,0,0),(0,-x1^2,0,0),(0,0,-x1^2*sin(x2)^2,0),(0,0,0,-(x1-a)/x1))
print("gdd=",gdd)
riemann(gdd,X)
print("GAMUDD[2,1,2]=",simplify(GAMUDD[2,1,2]))
print("GAMUDD[3,1,3]=",simplify(GAMUDD[3,1,3]))
print("RDD=",simplify(RDD))
print("R=",simplify(R))

smib gives:
gdd= ((-x1/(-a+x1),0,0,0),(0,-x1^2,0,0),(0,0,-x1^2*sin(x2)^2,0),(0,0,0,-1+a/x1))
GAMUDD[2,1,2]= 1/x1
GAMUDD[3,1,3]= 1/x1
RDD= 0
R= 0

The following function allows the testing of some properties of tensors and covariant derivative.
testgdd()=prog(tmp,tmp1,tmp2,tmp3,do(
print("Commutator is anticommutative:"),
test(Commutator(V,W)+Commutator(W,V)==0,
print("Commutator(V,W)+Commutator(W,V)==0: ok"),
print("Commutator(V,W)+Commutator(W,V)==0: ko")), print("Commutator is linear: 1 "),
test(Commutator(V+U,W)-(Commutator(V,W)+Commutator(U,W))==0,
print("Commutator(V+U,W)-(Commutator(V,W)+Commutator(U,W))==0: ok"),
print("Commutator(V+U,W)-(Commutator(V,W)+Commutator(U,W))==0: ko")),
print("Commutator is linear: 2 "),
test(Commutator(V,W+U)-(Commutator(V,W)+Commutator(V,U))==0,
print("Commutator(V,W+U)-(Commutator(V,W)+Commutator(V,U))==0: ok"),
print("Commutator(V,W+U)-(Commutator(V,W)+Commutator(V,U))==0: ko")),
print("Jacobi identity:"),
test(Commutator(Commutator(U,V),W)+Commutator(Commutator(V,W),U)+Commutator(Commutator(W,U),V)==0,
print("Commutator(Commutator(U,V),W)+Commutator(Commutator(V,W),U)+Commutator(Commutator(W,U),V)==0: ok"),
print("Commutator(Commutator(U,V),W)+Commutator(Commutator(V,W),U)+Commutator(Commutator(W,U),V)==0:ko")),
print("Symmetry of covariant derivative: "),
test(DirCovDerVU(V,W)-DirCovDerVU(W,V)-Commutator(W,V)==0,
print("DirCovDerVU(V,W)-DirCovDerVU(W,V)-Commutator(W,V)==0: ok"),
print("DirCovDerVU(V,W)-DirCovDerVU(W,V)-Commutator(W,V)==0: ko")),
print("Composition rule: " ),
test(DirCovDerVU(f(X)*V,W)-f(X)*DirCovDerVU(V,W)-outer(V,contr(outer(d(f(X),X),W),1,2))==0,
print("DirCovDerVU(f(X)*V,W)-f(X)*DirCovDerVU(V,W)-outer(V,contr(outer(d(f(X),X),W),1,2))==0: ok"),
print("DirCovDerVU(f(X)*V,W)-f(X)*DirCovDerVU(V,W)-outer(V,contr(outer(d(f(X),X),W),1,2))==0: ko")),
print("Additivity of covariant derivative: "),
test(DirCovDerVU(U,V+W)-DirCovDerVU(U,V)-DirCovDerVU(U,W)==0,
print("DirCovDerVU(U,V+W)-DirCovDerVU(U,V)-DirCovDerVU(U,W)==0: ok"),
print("DirCovDerVU(U,V+W)-DirCovDerVU(U,V)-DirCovDerVU(U,W)==0: ko")),
test(RUDDD-(1/2*(RUDDD-trans(RUDDD,3,4)))==0,
print("Riemann tensor is antisymmetric on two last indices: ok"),
print("Riemann tensor is antisymmetric on two last indices: ko")), test(contr(outer(guu,RDDDD),2,3)==0,
print("Is metric flat?: Yes"),
print("Is metric flat?: No")),
test(CovDerTUD(CovDerVU(V,X),X)-trans(CovDerTUD(CovDerVU(V,X),X),2,3)-trans(contr(outer(RUDDD,V),2,5),2,3)==0,
print("Covariant derivative is not flat: ok"),
print("Covariant derivative is not flat: ko")),
test(simplify(CovDerTDD(gdd,X))==0,
print("CovDerTDD(gdd,X)=0: ok"),
print("CovDerTDD(gdd,X)=0: ko")),
test(contr(CovDerTUU(GUU,X),2,3)==0,
print("Div(GUU)=0: ok"),
print("Div(GUU)=0: ko")),
print("testgdd: ok")
) )

Now we can apply this to statical-spherical metric, with this script:
a=quote(a)
b=quote(b)
X4=(x0,x1,x2,x3)
W4=(w0(X4),w1(X4),w2(X4),w3(X4))
V4=(v0(X4),v1(X4),v2(X4),v3(X4))
U4=(u0(X4),u1(X4),u2(X4),u3(X4))
V=V4
U=U4
W=W4
X=X4
Staticspherical = ((a(x0,x1), 0, 0, 0), (0, b(x0,x1), 0, 0),
(0, 0, x1^2, 0), (0, 0, 0, x1^2 sin(x2)^2))
riemann(Staticspherical,X)
print("Métrique: gdd=",gdd)
testgdd()

And smib gives:
Métrique: gdd= ((a(x0,x1),0,0,0),(0,b(x0,x1),0,0),
(0,0,x1^2,0),(0,0,0,x1^2*sin(x2)^2))
Commutator is anticommutative:
Commutator(V,W)+Commutator(W,V)==0: ok
Commutator is linear: 1
Commutator(V+U,W)-(Commutator(V,W)+Commutator(U,W))==0: ok
Commutator is linear: 2
Commutator(V,W+U)-(Commutator(V,W)+Commutator(V,U))==0: ok
Jacobi identity:
Commutator(Commutator(U,V),W)+Commutator(Commutator(V,W),U)+Commutator(Commutator(W,U),V)==0: ok
Symmetry of covariant derivative:
DirCovDerVU(V,W)-DirCovDerVU(W,V)-Commutator(W,V)==0: ok
Composition rule:
DirCovDerVU(f(X)*V,W)-f(X)*DirCovDerVU(V,W)-outer(V,contr(outer(d(f(X),X),W),1,2))==0: ok
Additivity of covariant derivative:
DirCovDerVU(U,V+W)-DirCovDerVU(U,V)-DirCovDerVU(U,W)==0: ok
Riemann tensor is antisymmetric on two last indices: ok
Is metric flat?: No
Covariant derivative is not flat: ok
CovDerTDD(gdd,X)=0: ok
Div(GUU)=0: ok
testgdd: ok


5.4 Unidimensional integral calculus

In this chapter, we wants to show how to use symbolic computation of definite integrals (using the function defint).

5.4.1 Classical integrals

Here is a list of classical integrals:
The implementation is given by:
print("defint(carac(x,-3,9),x,minfty,infty)=",
    defint(carac(x,-3,9),x,minfty,infty))
print("defint(exp(-x^2),x,minfty,infty)=",
    defint(exp(-x^2),x,minfty,infty))
print("defint(1/(1+x^2),x,minfty,infty)=",
    defint(1/(1+x^2),x,minfty,infty))
print("defint(sin(x)/x,x,0,infty)=",
    defint(sin(x)/x,x,0,infty))
print("defint(sin(x)/x,x,minfty,infty)=",
    defint(sin(x)/x,x,minfty,infty))
print("defint(exp(-x),x,0,infty)=",
    defint(exp(-x),x,0,infty))

And smib gives:
defint(carac(x,-3,9),x,minfty,infty)= 12
defint(exp(-x^2),x,minfty,infty)= pi^(1/2)
defint(1/(1+x^2),x,minfty,infty)= pi
defint(sin(x)/x,x,0,infty)= 1/2*pi
defint(sin(x)/x,x,minfty,infty)= pi
defint(exp(-x),x,0,infty)= 1


5.4.2Orthogonal polynomial properties

Now, we want to study integralsIP(x, n)w(x)dx and IP(x, n)P(x, m)w(x)dx,for the following orthogonal polynomials:
P(x, n) w(x) I
legendre(x,n) x [ − 1, 1]
laguerre(x,n) e − x [0, ∞]
hermite(x,n) e − x2 [ − ∞, ∞]


In smib:
nop=2
print("Legendre: ")
for(ind,0,nop,print("defint(legendre(x,",ind,"),x,-1,1)=",
    defint(legendre(x,ind),x,-1,1)))
for(ind1,0,nop,for(ind2,0,nop,print("defint(legendre(x,",ind1,")*
    legendre(x,",ind2,"),x,-1,1)=",
    defint(legendre(x,ind1)*legendre(x,ind2),x,-1,1))))
print("Laguerre: ")
for(ind,0,nop,print("defint(laguerre(x,",ind,")*exp(-x),x,0,infty)=",
    defint(laguerre(x,ind)*exp(-x),x,0,infty)))
for(ind1,0,nop,for(ind2,0,nop,print("defint(laguerre(x,",ind1,")*
    laguerre(x,",ind2,")*exp(-x),x,0,infty)=",
    defint(laguerre(x,ind1)*laguerre(x,ind2)*exp(-x),x,0,infty))))
print("Hermite: ")
for(ind,0,nop,print("defint(hermite(x,",ind,")*exp(-x^2),x,minfty,infty)=",
    defint(hermite(x,ind)*exp(-x^2),x,minfty,infty)))
for(ind1,0,nop,for(ind2,0,nop,print("defint(hermite(x,",ind1,")*
    hermite(x,",ind2,")*exp(-x^2),x,minfty,infty)=",
    defint(hermite(x,ind1)*hermite(x,ind2)*exp(-x^2),x,minfty,infty))))

And smib gives:
Legendre:
defint(legendre(x, 0 ),x,-1,1)= 2
defint(legendre(x, 1 ),x,-1,1)= 0
defint(legendre(x, 2 ),x,-1,1)= 0
defint(legendre(x, 0 )*legendre(x, 0 ),x,-1,1)= 2
defint(legendre(x, 0 )*legendre(x, 1 ),x,-1,1)= 0
defint(legendre(x, 0 )*legendre(x, 2 ),x,-1,1)= 0
defint(legendre(x, 1 )*legendre(x, 0 ),x,-1,1)= 0
defint(legendre(x, 1 )*legendre(x, 1 ),x,-1,1)= 2/3
defint(legendre(x, 1 )*legendre(x, 2 ),x,-1,1)= 0
defint(legendre(x, 2 )*legendre(x, 0 ),x,-1,1)= 0
defint(legendre(x, 2 )*legendre(x, 1 ),x,-1,1)= 0
defint(legendre(x, 2 )*legendre(x, 2 ),x,-1,1)= 2/5
Laguerre:
defint(laguerre(x, 0 )*exp(-x),x,0,infty)= 1
defint(laguerre(x, 1 )*exp(-x),x,0,infty)= 0
defint(laguerre(x, 2 )*exp(-x),x,0,infty)= 0
defint(laguerre(x, 0 )*laguerre(x, 0 )*exp(-x),x,0,infty)= 1
defint(laguerre(x, 0 )*laguerre(x, 1 )*exp(-x),x,0,infty)= 0
defint(laguerre(x, 0 )*laguerre(x, 2 )*exp(-x),x,0,infty)= 0
defint(laguerre(x, 1 )*laguerre(x, 0 )*exp(-x),x,0,infty)= 0
defint(laguerre(x, 1 )*laguerre(x, 1 )*exp(-x),x,0,infty)= 1
defint(laguerre(x, 1 )*laguerre(x, 2 )*exp(-x),x,0,infty)= 0
defint(laguerre(x, 2 )*laguerre(x, 0 )*exp(-x),x,0,infty)= 0
defint(laguerre(x, 2 )*laguerre(x, 1 )*exp(-x),x,0,infty)= 0
defint(laguerre(x, 2 )*laguerre(x, 2 )*exp(-x),x,0,infty)= 1
Hermite:
defint(hermite(x, 0 )*exp(-x^2),x,minfty,infty)= pi^(1/2)
defint(hermite(x, 1 )*exp(-x^2),x,minfty,infty)= 0
defint(hermite(x, 2 )*exp(-x^2),x,minfty,infty)= 0
defint(hermite(x, 0 )*hermite(x, 0 )*exp(-x^2),x,minfty,infty)= pi^(1/2)
defint(hermite(x, 0 )*hermite(x, 1 )*exp(-x^2),x,minfty,infty)= 0
defint(hermite(x, 0 )*hermite(x, 2 )*exp(-x^2),x,minfty,infty)= 0
defint(hermite(x, 1 )*hermite(x, 0 )*exp(-x^2),x,minfty,infty)= 0
defint(hermite(x, 1 )*hermite(x, 1 )*exp(-x^2),x,minfty,infty)= 2*pi^(1/2)
defint(hermite(x, 1 )*hermite(x, 2 )*exp(-x^2),x,minfty,infty)= 0
defint(hermite(x, 2 )*hermite(x, 0 )*exp(-x^2),x,minfty,infty)= 0
defint(hermite(x, 2 )*hermite(x, 1 )*exp(-x^2),x,minfty,infty)= 0
defint(hermite(x, 2 )*hermite(x, 2 )*exp(-x^2),x,minfty,infty)= 8*pi^(1/2)

5.4.3Complex path integrals

Let C = {eit, t ∈ [0, 2π]}, we want to compute Cf(z)dz2iπfor the following functions z1z, z↦ln(z), zz.
Then in smib:
C(t)=exp(i*t)
print("C(t)=",C(t))
z=quote("z")
f(z)=1/z
print("f(z)=",f(z))
print("defint(f(C(t))*d(C(t),t),t,0,2*pi)/(2*i*pi)=",
    expand(defint(f(C(t))*d(C(t),t),t,0,2*pi)/(2*i*pi)))

f(z)=log(z)
print("f(z)=",f(z))
print("defint(f(C(t))*d(C(t),t),t,0,2*pi)/(2*i*pi)=",
    expand(defint(f(C(t))*d(C(t),t),t,0,2*pi)/(2*i*pi)))
f(z)=z
print("f(z)=",f(z))
print("defint(f(C(t))*d(C(t),t),t,0,2*pi)/(2*i*pi)=",
    expand(defint(f(C(t))*d(C(t),t),t,0,2*pi)/(2*i*pi)))

And smib gives:
C(t)= exp(i*t)
f(z)= 1/z
defint(f(C(t))*d(C(t),t),t,0,2*pi)/(2*i*pi)= 1
f(z)= log(z)
defint(f(C(t))*d(C(t),t),t,0,2*pi)/(2*i*pi)= 1
f(z)= z
defint(f(C(t))*d(C(t),t),t,0,2*pi)/(2*i*pi)= 0


5.4.4Continous Fourier transform

Elementary functions
Now, we want to study how to use symbolic Fourier transform. First, Fourier transform acting on functions, then on operators, and finally some applications.
And smib gives:
fourier(a,t)= 2*a*pi*dirac(t)
fourier(sin(t),t)= -i*pi*dirac(-1+t)+i*pi*dirac(1+t)
fourier(exp(-a*abs(t)),t)= dilatation(2/(1+t^2),t,1/a)/abs(a)
fourier(log(a*abs(t)),t)= -2*euler*pi*dirac(t)+2*pi*dirac(t)*log(a)-pi/abs(t)
fourier(exp(-t^2),t)= pi^(1/2)*exp(-1/4*t^2)
fourier(exp(i*t^2),t)=
i*pi^(1/2)*exp(-1/4*i*t^2)/(2^(1/2))+pi^(1/2)*exp(-1/4*i*t^2)/(2^(1/2))
fourier(arctan(t),t)= -i*pi*exp(-abs(t))/t
fourier(erf(t),t)= -2*i*exp(-1/4*t^2)/t
fourier(d(f(t),t,2),t) = -t^2*fourier(f(t),t)
expand(fourier(convolution(f(t),g(t)),t)) = fourier(f(t),t) fourier(g(t),t)
fourier(integral(f(t),t),t)= -i*fourier(f(t),t)/t
invfourier(1/fourier(d(dirac(t),t)-dirac(t),t),t)= -1/2*i*exp(t)*sgn(i*t)
d( -1/2*i*exp(t)*sgn(i*t) ,t)- -1/2*i*exp(t)*sgn(i*t) = exp(t)*dirac(i*t)
invfourier(1/fourier(t*d(dirac(t),t)-dirac(t),t),t)= -1/2*dirac(t)
t*d( -1/2*dirac(t) ,t)- -1/2*dirac(t) = 1/2*dirac(t)-1/2*t*d(dirac(t),t)
fourierprod(d(dirac(t),t),t)= -dirac(t)
Fourier transform & convolution product
Convolution product is computed by fg = ℱ − 1(.), we want to test the following properties:
And smib gives:
convolution(f(x),sgn(x))= 2*integral(f(-x),x)
convolution(1/x,1/x)= -pi^2*dirac(x)
convolution(1/x^2,1/x^2)= -pi^2*d(d(dirac(x),x),x)
convolution(exp(-a*x^2),exp(-b*x^2))=
pi^(1/2)*exp(-x^2/(1/a+1/b))/(2*abs(a)^(1/2)*abs(b)^(1/2)*abs(1/(4*a)+1/(4*b))^(1/2))
Fourier transform & Green functions
Here we want to compute Green functions, using partial Fourier transform (let f:(x, t) ∈ R × R + ⟼ℂ, partial Fourier transform in x is defined by F(f)(y, t) = f(x, t)e − ixydx), for heat equation (H) and Schrodinger equation (S).


5.5Vectorial calculus

5.5.1Vectorial integrals

Let a = (12cos(2t),  − 8sin(2t), 16t) be acceleration vector, we want to compute speed vector v, position vector x.
In smib:
t=quote(t)
T=quote(T)
T1=quote(T1)
a=quote(a)
v=quote(v)
r=quote(r)
a=(12*cos(2*t),-8*sin(2*t),16*t)
v=defint(a,t,0,T)
r=defint(v,T,0,T1)
print("acceleration vector a=",a)
print("speed vector v=",v)
print("position vector r=",r)

And smib gives:
acceleration vector a= (12*cos(2*t),-8*sin(2*t),16*t)
speed vector v= (6*sin(2*T),-4+4*cos(2*T),8*T^2)
position vector r= (3-3*cos(2*T1),-4*T1+2*sin(2*T1),8/3*T1^3)

5.5.2Curvilinear integrals

5.5.3 Area integrals

5.5.4 Some famous theorems

Green theorem
We want to test Green theorem: let C = {(cos(t), sin(t)), t ∈ [0, 2π]} a planar closed curve, S such that C = ∂S, S = {(rcos(t), rsin(t)), (r, t) ∈ [0, 1] × [0, 2π]}, P = 2x3 − y3, and Q = x3 + y3, now we want to verify: CPdx + Qdy = S(∂yP − ∂xQ)dS.
So in smib:
r=quote(r)
t=quote(t)
x=quote(x)
y=quote(y)
z=quote(z)
P=2x^3-y^3
Q=x^3+y^3
f=d(Q,x)-d(P,y)
x=r*cos(theta)
y=r*sin(theta)
f=expand(f)
print("integral(d(Q,x)-d(P,y))=",defint(defint(f*r,r,0,1),theta,0,2pi))
t=quote(t)
x=quote(x)
y=quote(y)
z=quote(z)
x=cos(t)
y=sin(t)
P=2x^3-y^3
Q=x^3+y^
f=expand(P*d(x,t)+Q*d(y,t))
print("integral(P*d(x,t)+Q*d(y,t))=",defint(f,t,0,2pi))

And smib gives:
integral(d(Q,x)-d(P,y))= 3/2*pi
integral(P*d(x,t)+Q*d(y,t))= 3/2*pi
Stokes theorem
We propose to evaluate Stokes theorem on two examples:
  1. Let S a map in 3defined by S = {(x, y, 4 − x2 − y2), (x, y) ∈ [ − 1, 1]2}, and F = (y, z, x)
  2. Let S a map in 3 defined by S = {(x, y, (1 − x2 − y2)), (x, y) ∈ [ − 1, 1]2}, and F = (2x − y,  − x2y,  − y2z).
From these assumptions, we want to verify: SF.dr = SF.dS.
So in smib:

Example 1:
print("Map integral")
t=quote(t)
x=quote(x)
y=quote(y)
z=quote(z)
X=(x,y,z)
A=((1,0,0),(0,1,0),(0,0,1))
riemann(A,X)
z=4-x^2-y^2
F=(y,z,x)
S=(x,y,z)
f=expand(dot(Rot(F,X),crossP(d(S,x),d(S,y))))
x=r*cos(theta)
y=r*sin(theta)
print("integral(dot(Rot(F,X),crossP(d(S,x),d(S,y))))=",
    defint(defint(f*r,r,0,2),theta,0,2pi))
print("Curvilinear integral")
t=quote(t)
x=quote(x)
y=quote(y)
z=quote(z)
x=2*cos(t)
y=2*sin(t)
z=4-x^2-y^2
P=F[1]
Q=F[2]
R=F[3]
f=expand(P*d(x,t)+Q*d(y,t)+R*d(z,t))
print("integral(P*d(x,t)+Q*d(y,t)+R*d(z,t))=",defint(f,t,0,2pi))
print(" ")
And smib gives:
Map integral
integral(dot(Rot(F,X),crossP(d(S,x),d(S,y))))= -4*pi
Curvilinear integral
integral(P*d(x,t)+Q*d(y,t)+R*d(z,t))= -4*pi

Example 2:
t=quote(t)
x=quote(x)
y=quote(y)
z=quote(z)
phi=quote(phi)
theta=quote(theta)
X=(x,y,z)
A=((1,0,0),(0,1,0),(0,0,1))
riemann(A,X)
F=(2*x-y,-x^2*y,-y^2*z)
print("Map integral")
z=sqrt(1-x^2-y^2)
S=(x,y,z)
f=expand(dot(Rot(F,X),crossP(d(S,x),d(S,y))/
    sqrt(dot(crossP(d(S,x),d(S,y)),crossP(d(S,x),d(S,y))))))
x=cos(phi)*cos(theta)
y=sin(phi)*cos(theta)
f=simplify(eval(f))
print("integral(dot(Rot(F,X),crossP(d(S,x),d(S,y))))=",
    defint(defint(f*cos(theta),theta,0,pi/2),phi,0,2*pi))
print("Curvilinear integral")
t=quote(t)
x=quote(x)
y=quote(y)
z=quote(z)
x=cos(t)
y=sin(t)
z=sqrt(1-x^2-y^2)
P=F[1]
Q=F[2]
R=F[3]
f=expand(P*d(x,t)+Q*d(y,t)+R*d(z,t))
print("integral(P*d(x,t)+Q*d(y,t)+R*d(z,t))=",defint(f,t,0,2pi))

And smib gives:
Map integral
integral(dot(Rot(F,X),crossP(d(S,x),d(S,y))))= pi
Curvilinear integral
integral(P*d(x,t)+Q*d(y,t)+R*d(z,t))= pi
Gauss-Ostrogradski theorem
We will verify Gauss-Ostrogradski theorem: V.FdV = VF.dS, for V = {(x = rcos(ϑ), y = rsin(ϑ), z), (r, ϑ, z) ∈ [0, 2] × [0, 2π] × [0, 3]}, and F = (4x,  − 2y2, z2).
So in smib:
print("Volumic integral")
r=quote(r)
theta=quote(theta)
t=quote(t)
x=quote(x)
y=quote(y)
z=quote(z)
X=(x,y,z)
A=((1,0,0),(0,1,0),(0,0,1))
riemann(A,X)
A=quote(A)
B=quote(B)
A=(4*x,-2*y^2,z^2)
B=Div(A,X)
print("Switching to cylindrical coordinates")
x=r*cos(theta)
y=r*cos(theta)
print("integral(Div(A,X))=",
    defint(defint(defint(B*r,z,0,3),theta,0,2*pi),r,0,2))
print("Surfacic integral")
t=quote(t)
x=quote(x)
y=quote(y)
z=quote(z)
S1=(x,y,0)
print("S1: lower disk")
AS1=expand(dotP(A,crossP(d(S1,x),d(S1,y))))
x=r*cos(theta)
y=r*sin(theta)
z=0
IS1=defint(defint(expand(AS1*r),r,0,2),theta,0,2pi)
print("IS1=",IS1)
t=quote(t)
x=quote(x)
y=quote(y)
z=quote(z)
S2=(x,y,3)
print("S2: upper disk")
AS2=expand(dotP(A,crossP(d(S2,x),d(S2,y))))
x=r*cos(theta)
y=r*sin(theta)
z=3
IS2=defint(defint(expand(AS2*r),r,0,2),theta,0,2pi)
print("IS2=",IS2)
x=quote(x)
y=quote(y)
z=quote(z)
print("S3: cylindrical part")
S3=(x,sqrt(4-x^2),z)
AS3=dotP(A,crossP(d(S3,x),d(S3,z)))
x=r*cos(theta)
y=r*sin(theta)
r=2
z=quote(z)
IS3=defint(defint(simplify(expand(AS3*r)),theta,0,2pi),z,0,3)
print("IS3=",IS3)
print("IS1+IS2+IS3=",IS1+IS2+IS3)

And smib gives:
Volumic integral
Switching to cylindrical coordinates
integral(Div(A,X))= 84*pi
Surfacic integral
S1: lower disc
IS1= 0
S2: upper disc
IS2= 36*pi
S3: cylindrical part
IS3= 48*pi
IS1+IS2+IS3= 84*pi


5.6Numerical analysis

5.6.1 Samples applied to numerical analysis

Here we want to study the function f:x⟼exp( − x2) using samples. We will look at the following properties:
- first and second order derivative of f (comparison of samples with symbolic computations)
- test if f verifies this differential equation: dfdx − xf = 0
- test if dfdxdx = f (fundamental theorem of analysis).
Here, we choose sampling interval I = [ − 3, 3], and sampling rate N = 200, and here, we measure the error with the function Snorm.

So in smib:
N=200
a=3
f=exp(-x^2)
print("f= ",f)
A=sample(f,x,-a,a,N)
X=sample(x,x,-a,a,N)
SDf=Sd(A)
Df=sample(d(f,x),x,-a,a,N)
print("")
print("First order derivative")
print(Snorm(Sdiff(SDf,Df)))
SD2f=Sd(SDf)
D2f=sample(d(f,x,2),x,-a,a,N)
print("")
print("Second order derivative")
print(Snorm(Sdiff(SD2f,D2f)))
print("")
print("Differential equation:d(f)+2xf=0")
print(Snorm(Ssum(SDf,Sscalarproduct(2,Sproduct(X,A)))))
print("")
print("Fundamental theorem of analysis")
g(x)=Sdefint(SDf,-a,x)
Z=sample(g,x,-a,a,N)
print(Snorm(Sdiff(A,Z)))

And smib gives:
f= exp(-x^2)
First order derivative
(0.00375495,0.000188644,0.000185906)
Second order derivative
(0.0200501,0.00101163,0.000988244)
Differential equation:d(f)+2xf=0
(0.00375495,0.000188644,0.000185906)
Fundamental theorem of analysis
(0.102201,0.0049872,0.0052051)

Here we plot dfdxdx and f:
figure image/Sfundamentalth.png

On the same principle, with f:x⟼sin(x), I = [ − 6, 6], and N = 200, we have:
f= sin(x)
First order derivative
(0.0139451,0.00045642,0.000871306)
Second order derivative
(0.186432,0.00258752,0.0128928)
Fundamental theorem of analysis
(0.309026,0.018506,0.0115169)

Here we must be vigilant because sin( − 6) ≠ 0, so for fundamental theorem, we have the following code:
print("Fundamental theorem of analysis")
g(x)=Sdefint(SDf,-a,x)+sin(-6)
Z=sample(g,x,-a,a,N)
print(Snorm(Sdiff(A,Z)))

And the following plotting:
figure image/Sfund2.png
Here differential equation is d²fdx² + f = 0, so in smib:
print("Differential equation:d^2(f)+f=0")
print(Snorm(Ssum(SD2f,A)))

Result is:
Differential equation:d^2(f)+f=0
(0.186432,0.00258752,0.0128928)

If we plot error:
figure image/Sdiffsin.png

As we shall also see in paragraph on probability and statistics (cf. quantile and median), we can look at the following problem using the sample: let F defined as F(x) = xaf(x)dx, x ∈ [a, b], the problem is to find x such that F(x) = X.

We can also calculate the quantile (and median) of a sample with the following programs:
Squantile(f,a,b,y,errprec)=prog(temp0,temp1,temp2,
    temp3,temp4,temp5,temp6,temp7,do(
    test(b==nil,temp0=f[1,1],temp0=b),
    test(y==nil,temp6=f[dim(f),1],temp6=y),
    test(errprec==nil,temp7=0,temp7=errprec),
    temp1=Sdefint(f,f[1,1],temp0)-a,
    temp2=Sdefint(f,f[1,1],(temp0+temp6)/2)-a,
    temp3=Sdefint(f,f[1,1],temp6)-a,
    temp4=temp1*temp2,
    temp5=temp2*temp3,
    test(abs(abs(temp2)-temp7)==0,(temp0+temp6)/2,
        test(and(temp4 < 0,temp5 > 0),
            Squantile(f,a,(temp0+temp6)/2,temp0,temp6,abs(temp2)),
            Squantile(f,a,(temp0+temp6)/2,temp6,abs(temp2))
        )
    )
))

And
Smedian(f)=Squantile(f,1/2)

We can test it on different function samples:
a=-5
b=5
N=1000
y0=30
f=x^2
print("f = ",f,", a = ",a,", b = ",b)
S=sample(f,x,a,b,N)
A=Squantile(S,y0)
I=Sdefint(S,a,A)
print("y0 = ",y0)
print("quantile = ",A)
print("check = ",I)
print("error = ",abs(y0-I))

And smib gives:
f = x^2 , a = -5 , b = 5
y0 = 30
quantile = -3.27
check = 29.94
error = 0.0599893
a=-5
b=5
N=1000
y0=50
f=x^2
print("f = ",f,", a = ",a,", b = ",b)
S=sample(f,x,a,b,N)
A=Squantile(S,y0)
I=Sdefint(S,a,A)
print("y0 = ",y0)
print("quantile = ",A)
print("check = ",I)
print("error = ",abs(y0-I))

And smib gives:
f = x^2 , a = -5 , b = 5
y0 = 50
quantile = 2.93457
check = 50.1086
error = 0.108583
a=-5
b=5
N=1000
y0=1/2
f=exp(-x^2)
print("f = ",f,", a = ",a,", b = ",b)
S=sample(f,x,a,b,N)
A=Squantile(S,y0)
I=Sdefint(S,a,A)
print("y0 = ",y0)
print("quantile = ",A)
print("check = ",I)
print("error = ",abs(y0-I))

And smib gives:
f = exp(-x^2) , a = -5 , b = 5
y0 = 1/2
quantile = -0.407715
check = 0.503734
error = 0.00373361
a=0.01
b=10
N=1000
y0=10
f=x*log(x)
print("f = ",f,", a = ",a,", b = ",b)
S=sample(f,x,a,b,N)
A=Squantile(S,y0)
I=Sdefint(S,a,A)
print("y0 = ",y0)
print("quantile = ",A)
print("check = ",I)
print("error = ",abs(num(y0-I)))

And smib gives:
f = x*log(x) , a = 0.01 , b = 10
y0 = 10
quantile = 4.47544
check = 9.95704
error = 0.042961

5.6.2 Special functions

Here we must be prudent, we must choose x such that |x| ≤ 10.
Bessel function of first kind: J(x, α)
we choose the following definition:
J(x, α) = j = 0( − 1)k(x2)2j + αj(α + j + 1)
So in smib:
numJ(x,p)=num(sum(k,0,prec,(-1)^k*(x/2)^(2*k+p)/(k!*Gamma(p+k+1))))
Bessel function of second kind: Y(x, α)
we choose the following definition:
Y(x, α) = J(x, α)cos(απ) − J(x,  − α)sin(απ)
So in smib:
numY(x,p)=num((numJ(x,p)*cos(p*pi)-numJ(x,-p))/sin(p*pi))
Bessel modified function of first kind: I(x, α)
we choose the following definition:
I(x, α) = i − αJ(ix, α)
So in smib:
numJ(x,p)=num(sum(k,0,prec,(-1)^k*(x/2)^(2*k+p)/(k!*Gamma(p+k+1))))
Hankel function of first kind: H1(x, α)
we choose the following definition:
H1(x, α) = J(x, α) + iY(x, α)
So in smib:
numH1(x,p)=num(numJ(x,p)+i*numY(x,p))
Hankel function of second kind: H2(x, α)
we choose the following definition:
H2(x, α) = J(x, α) − iY(x, α)
So in smib:
numH2(x,p)=num(numJ(x,p)-i*numY(x,p))
Bessel modified function of second kind: K(x, α)
we choose the following definition:
K(x, α) = π2iα + 1H1(ix, α)
So in smib:
numK(x,p)=num(pi/2*i^(p+1)*numH1(i*x,p))
Airy functions: Ai(x, α) & Bi(x, α)
we choose the following definitions:
Ai(x, α) = { 1π(x3)K(23x32, 13), x > 0( − x3)(J(23( − x)32, 13) + J(23( − x)32,  − 13))
Bi(x, α) = { ( − x3)(I(23( − x)32, 13) + I(23( − x)32,  − 13)), x > 0( − x3)(J(23( − x)32,  − 13) − J(23( − x)32,  − 13))
So in smib:
numAi(x)=test(x>0,num(1/pi*sqrt(x/3)*numK(2*x^(3/2)/3,1/3)),
num(sqrt(-x)/3*(numJ(2*(-x)^(3/2)/3,1/3)+numJ(2*(-x)^(3/2)/3,-1/3))))
numBi(x)=test(x>0,num(sqrt(x/3)*(numI(2*x^(3/2)/3,1/3)+numI(2*x^(3/2)/3,-1/3))),
num(sqrt(-x/3)*(numJ(2*(-x)^(3/2)/3,-1/3)-numJ(2*(-x)^(3/2)/3,1/3))))
Some examples
First some plottings:
figure image/besselJ.png

figure image/besseY.png

And after, some value computations:
numJ(2.5,0)= -0.0483838
numJ(2.5,2)= 0.446059
numJ(-2.5,0)= -0.0483838
numJ(-2.5,2)= 0.446059
numJ(2.5,1/2)= 0.302005
numJ(-2.5,1/2)= 0.302005*i
numY(2.5,1/2)= 0.404278
numY(-2.5,1/2)= -0.404278*i
numY(2.5,3/2)= -0.140294
numY(-2.5,3/2)= -0.140294*i
numN(2.5,1/2)= 0.404278
numN(-2.5,1/2)= -0.404278*i
numN(2.5,3/2)= -0.140294
numN(-2.5,3/2)= -0.140294*i
numH1(2.5,1/2)= 0.302005+0.404278*i
numH1(-2.5,1/2)= 0.404278+0.302005*i
numH1(2.5,3/2)= 0.52508-0.140294*i
numH1(-2.5,3/2)= 0.140294-0.52508*i
numH2(2.5,1/2)= 0.302005-0.404278*i
numH2(-2.5,1/2)= -0.404278+0.302005*i
numH2(2.5,3/2)= 0.52508+0.140294*i
numH2(-2.5,3/2)= -0.140294-0.52508*i
numI(2.5,0)= 3.28984
numI(-2.5,0)= 3.28984
numI(2.5,1/2)= 3.05309-6.66134e-16*i
numI(-2.5,1/2)= 6.66134e-16+3.05309*i
numK(2.5,1/2)= 0.0650659-6.93889e-18*i
numK(-2.5,1/2)= -2.66454e-15-9.65664*i
numK(2.5,3/2)= 0.0910923+2.42861e-16*i
numK(-2.5,3/2)= -1.33227e-15-5.79399*i
numAi(0.25)= 0.291164
numAi(1)= 0.135292+1.12218e-16*i
numAi(-0.25)= 0.418725
numAi(-1)= 0.535561
numBi(1)= 1.20742-6.40988e-17*i
numBi(-0.25)= 0.5014
numBi(-1)= 0.103997

The following examples introduce the section on numerical integration, indeed we are going to study the following integrals:
π20J(2zsin(t), n)dt = π2J(z, n2)2    π0J(2zsin(t), 0)cos(2nt)dt = πJ(z, n)2    π20Y(2zsin(t), 0)cos(2nt)dt = π2J(z, n)Y(z, n)    z0J(t, n)J(z − t,  − n)dt = sin(z)    z0J(t, n)J(z − t, 1 − n)dt = J(z, 0) − cos(z)

And smib gives:
I1(z,n)=numint(numJ(2*z*sin(t),n),t,0,pi/2)-pi/2*numJ(z,n/2)^2
I1(0.5,3)= -4.24834e-15
I1(2,3)= -2.70561e-13
I1(0.5,4)= -6.50521e-19
I1(2,4)= 1.11022e-16
I2(z,n)=numint(numJ(2*z*sin(t),0)*cos(2*n*t),t,0,pi)-pi*numJ(z,n)^2
I2(0.5,3)= -1.69302e-16
I2(2,3)= -1.45717e-16
I2(0.5,4)= -4.68064e-17
I2(2,4)= -1.01048e-16
I3(z,n)=numint(numY(2*z*sin(t),0)*cos(2*n*t),t,0,pi/2)-pi/2*numJ(z,n)*numY(z,n)
I3(0.5,1)= 0.0364192
I3(0.5,2)= 0.0364128
I3(2,1)= 0.0275907
I3(2,2)= 0.027586
I4(z,n)=numint(numJ(t,n)*numJ(z-t,-n),t,0,z)-sin(z)
I4(0,1/2)= 0.00636606*i
I4(0.5,1/2)= Stop: divide by zero
I4(0,1/3)= -0.00413489+0.00716184*i
I4(0.5,1/3)= Stop: divide by zero
I5(z,n)=numint(numJ(t,n)*numJ(z-t,1-n),t,0,z)-(numJ(z,0)-cos(z))
I5(0,1/2)= 0.00636606*i
I5(0.5,1/2)= Stop: divide by zero
I5(0,1/3)= 0
I5(0.5,1/3)= -2.10643e-06
I5(1,1/3)= -7.49049e-06
I5(2,1/3)= -1.74867e-05

As we could see that result are not always good (Simpson scheme), now we make the same exercise using Gauss scheme:
simpsonint=0.
Then smib returns:
I1(z,n)=numint(numJ(2*z*sin(t),n),t,0,pi/2)-pi/2*numJ(z,n/2)^2
I1(0.5,3)= 6.33551e-05
I1(2,3)= 0.00139332
I1(0.5,4)= 8.01996e-06
I1(2,4)= 0.00091048
I2(z,n)=numint(numJ(2*z*sin(t),0)*cos(2*n*t),t,0,pi/2)-pi*numJ(z,n/2)^2
I2(0.5,3)= 0.0125691
I2(2,3)= 0.0157853
I2(0.5,4)= 0.0145211
I2(2,4)= -0.0306763
I3(z,n)=numint(numY(2*z*sin(t),0)*cos(2*n*t),t,0,pi/2)-pi/2*numJ(z,n)*numY(z,n)
I3(0.5,1)= 0.0253421
I3(0.5,2)= 0.0259082
I3(2,1)= 0.0196943
I3(2,2)= 0.0195847
I4(z,n)=numint(numJ(t,n)*numJ(z-t,-n),t,0,z)-sin(z)
I4(0,1/2)= 0.00639231*i
I4(0.5,1/2)= -0.000461072
I4(1,1/2)= -0.000178817
I4(2,1/2)= 7.98167e-05
I4(0,1/3)= -0.00415194+0.00719137*i
I4(0.5,1/3)= 0.00243214
I4(1,1/3)= 0.00587959
I4(2,1/3)= 0.00636122
I5(z,n)=numint(numJ(t,n)*numJ(z-t,1-n),t,0,z)+cos(z)-numJ(z,0)
I5(0,1/2)= 0.00639231*i
I5(0.5,1/2)= -0.000461072
I5(1,1/2)= -0.000178817
I5(2,1/2)= 7.98167e-05
I5(0,1/3)= 0
I5(0.5,1/3)= 1.78261e-05
I5(1,1/3)= 6.37467e-05
I5(2,1/3)= 0.000153571
And using Bessel function of second kind: I(z, n) = z0J(t, n)J(z − t,  − n)dt with qgfe, we obtain:
figure image/intY.png

5.6.3 Numerical interpolation

Here we want to study Lagrange interpolation problem applied to a sample F = (xi, yi)i ∈ {0..k}, we shall use Newton basis polynomials and divide differences.
Newton polynomial is defined by: Nj(x)=i = j − 1i = 0(x − xi); and interpolation is implemanted (using temporary program) as:
newtonpoly(x,F,j)=product(ind,1,j,x-F[ind,1])
newtoninter(F,x)=prog(temp0,temp1,temp2,temp3,temp4,do(
    temp1=Sdecomp(F,2),
    temp4(F)=prog(temp,do(
        temp=zero(dim(F),dim(F)),
        for(ind1,1,dim(F),
            for(ind2,1,dim(F),temp[ind1,ind2]=
                newtonpoly(F[ind1,1],F,ind2-1)
            )
        ),
        return(temp)
    )),
    temp2=dot(inv(temp4(F)),temp1),
    temp3=sum(ind,1,dim(F),temp2[ind]*newtonpoly(x,F,ind-1)),
    return(temp3)
))

Hereafter two small examples:
a=-1.5
b=1.5
n=4
f=tan(x)
F=sample(f,x,a,b,n)
g=newtoninter(F,x)
G=sample(g,x,a,b,n)
Err=Sabs(Sdiff(F,G))
Snorm(Err)

And smib gives:
6.64652e-15
2.13163e-15
2.07157e-15
a=-5
b=5
n=20
f=x^2+1
F=sample(f,x,a,b,n)
g=newtoninter(F,x)
G=sample(g,x,a,b,n)
Err=Sabs(Sdiff(F,G))
Snorm(Err)

And smib gives:
5.69016e-08
5.17097e-09
1.1289e-08

Lagrange interpolation is interesting, but we can do better. For a given sample (xi, yi)i ∈ I⫋ℕ, if we have a model function F(x, A),  A ∈ ℝJ, J⫋ℕ, using a non-linear least squares mean fitting algorithm, we can find A such that i ∈ I|yi − F(xi, A)|2 is minimal. For reasons of simplicity, we use Gauss-Newton method (plus a little subtlety), here is smib program:
LSQfitting(F,g,x,X,M,X0)=prog(G,Di,R,J,RandV,mu,ind2,Rev,Jev,h,fest,Fest,do(
  G=sample(g,x,F[1,1],F[dim(F),1],dim(F)-1),
  Di=transpose(Sdiff(G,F))[2],
  R=sum(ind,1,dim(Di),abs(Di)^2),
  J=d(R,X),
  test(X0==nil,RandV=randvect(dim(X)),RandV=X0),
  mu=0.2,
  for(ind2,1,M,do(
    Rev=prog(temp,do(
    temp=R,
    for(ind,1,dim(X),
      temp=num(subst(RandV[ind],X[ind],temp))),
      return(temp)
    )),
    Jev=prog(temp,do(
      temp=J,
      for(ind,1,dim(X),
      temp=num(subst(RandV[ind],X[ind],temp))),
      return(temp)
    )),
    test(det(outer(Jev,Jev)+mu*unit(dim(X)))==0,
      do(print(\"Singular matrix\"),return(RandV))),
    h=num(dot(inv(outer(Jev,Jev)+mu*unit(dim(X))),-Rev*Jev)),
    RandV=RandV+h
  )),
  fest=prog(temp,do(
  temp=g,
  for(ind,1,dim(X),
    temp=num(subst(RandV[ind],X[ind],temp))),
    return(temp)
  )),
  Fest=sample(fest,x,F[1,1],F[dim(F),1],dim(F)-1),
  print(\"Error=\",Snorm(Sdiff(Fest,F))),
  return(RandV)
))

Hereafter a basic example:
aI=0
bI=10
N=20
M=250
X=(a,b)
g=a*exp(b*x)
f=3*exp(-2*x)
F=sample(f,x,aI,bI,N)
LSQfitting(F,g,x,X,M)

smib gives:
Error= (0.0010457,0.000108982,0.000200484)
2.99944
-1.99851

We can also use this for polynomial interpolation, we choose the model function F(x, A) = ax2 + bx + c, with A = (a, b, c), and a sample of f(x) = x2 − 5x + 1 on [ − 5, 5] so in smib :
a=quote(a)
b=quote(b)
c=quote(c)
aI=-5
bI=5
N=100
M=200
X0=(0,0,0)
X=(a,b,c)
g=a*x^2+b*x+c
f=x^2-5*x+1
F=sample(f,x,aI,bI,N)
LSQfitting(F,g,x,X,M,X0)

And smib gives :
Error= (0.0211269,0.0019833,0.000697003)
0.999908
-5
0.998796

Why not with some noise :
a=quote(a)
b=quote(b)
c=quote(c)
aI=-5
bI=5
N=100
M=200
X0=(0,0,0)
X=(a,b,c)
g=a*x^2+b*x+c
f=x^2-5*x+1
F=sample(f,x,aI,bI,N)
Y=noisevector(dim(F))
Z=Sdecomp(F,1)
A=Sscalarproduct(2,Srecomp(Z,Y))
FErr=Ssum(F,A)
LSQfitting(F,g,x,X,M,X0)

And smib gives :
Error= (90.7331,6.78641,5.95437)
1.79058
-4.98599
0.83041

With a weaker noise :
A=Sscalarproduct(1/2,Srecomp(Z,Y))

And smib gives :
Error=(3.106,0.263857,0.160924)
0.992664
-5.01676
0.966035


5.6.4 Numerical integration

In this chapter, we want to test the function numint using Gauss scheme, this function acts only on real functions of real values.

Integrals on compact

Here one want to compute numericaly the following integrals:
And in smib:
precint=64
print("float(numint(sqrt(x),x,0,1,",precint,")-0.66666667)=",
    float(numint(sqrt(x),x,0,1,precint)-0.66666667))
print("float(numint(x^(3/2),x,0,1,",precint,")-0.4)=",
    float(numint(x^(3/2),x,0,1,precint)-0.4))
print("float(numint(1/(1+x),x,0,1,",precint,")-0.69314718)=",
    float(numint(1/(1+x),x,0,1,precint)-0.69314718))
print("float(numint(1/(1+x^4),x,0,1,",precint,")-0.86697299)=",
    float(numint(1/(1+x^4),x,0,1,precint)-0.86697299))
print("float(numint(1/(1+exp(x)),x,0,1,",precint,")-0.37988551)=",
    float(numint(1/(1+exp(x)),x,0,1,precint)-0.37988551))
print("float(numint(x/(-1+exp(x)),x,0,1,",precint,")-0.77750463)=",
    float(numint(x/(-1+exp(x)),x,0,1,precint)-0.77750463))
print("float(numint(2/(2+sin(10*pi*x)),x,0,1,",precint,")-1.1547005)=",
    float(numint(2/(2+sin(10*pi*x)),x,0,1,precint)-1.1547005))
print("float(numint(1/(x^(1/2)+x^(1/3)),x,0,1,",precint,")-0.84111692)=",
    float(numint(1/(x^(1/2)+x^(1/3)),x,0,1,precint)-0.84111692))

And smib gives:
float(numint(sqrt(x),x,0,1, 64 )-0.66666667)= 5.02022e-05
float(numint(x^(3/2),x,0,1, 64 )-0.4)= 5.02109e-05
float(numint(1/(1+x),x,0,1, 64 )-0.69314718)= 7.53089e-05
float(numint(1/(1+x^4),x,0,1, 64 )-0.86697299)= 7.52964e-05
float(numint(1/(1+exp(x)),x,0,1, 64 )-0.37988551)= 3.85864e-05
float(numint(x/(-1+exp(x)),x,0,1, 64 )-0.77750463)= 7.94248e-05
float(numint(2/(2+sin(10*pi*x)),x,0,1, 64 )-1.1547005)= 9.00555e-05
float(numint(1/(x^(1/2)+x^(1/3)),x,0,1, 64 )-0.84111692)= 0.000645944

Oscillatory integrals

Our aim is to compute:
So in smib:
IE0(n)=test(n==1,-pi/2,-2*n*pi/(n^2-1))
I0(n)=float(numint(x*cos(x)*sin(n*x),x,0,2*pi,precint)-IE0(n))
print("float(numint(x*cos(x)*sin(n*x),x,0,2*pi,",precint,")-
    test(n==1,-pi/2,-2*n*pi/(n^2-1)))")
print("I0(1)=",I0(1))
print("I0(2)=",I0(2))
print("I0(5)=",I0(5))
print("I0(10)=",I0(10))
print("I0(20)=",I0(20))
print("I0(30)=",I0(30))
IE1(n)=2*n*pi/(-n^2+2500)
I1(n)=float(numint(x*cos(50*x)*sin(n*x),x,0,2*pi,precint)-IE1(n))
print("float(numint(x*cos(50*x)*sin(n*x),x,0,2*pi,",precint,")-
    2*n*pi/(-n^2+2500))")
print("I1(1)=",I1(1))
print("I1(2)=",I1(2))
print("I1(5)=",I1(5))
print("I1(10)=",I1(10))
print("I1(20)=",I1(20))
print("I1(30)=",I1(30))
IE2(n)=2*pi^3*besselj(2*pi*n,1)
I2(n)=float(numint(x*sin(n*x)/sqrt(1-(x/(2*pi))^2),x,0,2*pi,precint)-IE2(n))
print("float(numint(x*sin(n*x)/sqrt(1-(x/(2*pi))^2),x,0,2*pi,",precint,")
    -2*pi^3*besselj(2*pi*n,1))")
print("I2(1)=",I2(1))
print("I2(2)=",I2(2))
print("I2(5)=",I2(5))
print("I2(10)=",I2(10))
print("I2(20)=",I2(20))
print("I2(30)=",I2(30))
IE3(n)=-(euler+log(2*n*pi)-numCi(2*n*pi))/n
I3(n)=float(numint(log(x)*sin(n*x),x,0,2*pi,precint)-IE3(n))
print("float(numint(log(x)*sin(n*x),x,0,2*pi,",precint,")+(euler+log(2*n*pi)-
numCi(2*n*pi))/n)")
print("I3(1)=",I3(1))
print("I3(2)=",I3(2))
print("I3(5)=",I3(5))
print("I3(10)=",I3(10))
print("I3(20)=",I3(20))
print("I3(30)=",I3(30))
And smib gives:
float(numint(x*cos(x)*sin(n*x),x,0,2*pi, 64 )-test(n==1,-pi/2,-2*n*pi/(n^2-1)))
I0(1)= 1.31392e-06
I0(2)= 2.62782e-06
I0(5)= 6.56936e-06
I0(10)= 1.31374e-05
I0(20)= 2.62641e-05
I0(30)= 3.91881e-05
float(numint(x*cos(50*x)*sin(n*x),x,0,2*pi, 64 )-2*n*pi/(-n^2+2500))
I1(1)= 0.432059
I1(2)= 0.373099
I1(5)= 0.960425
I1(10)= -1.06404
I1(20)= 0.0403888
I1(30)= -0.886106
float(numint(x*sin(n*x)/sqrt(1-(x/(2*pi))^2),x,0,2*pi,64 )-2*pi^3*besselj(2*pi*n,1))
I2(1)= 4.17247e-10
I2(2)= 8.34481e-10
I2(5)= 2.086e-09
I2(10)= 4.17052e-09
I2(20)= 8.32937e-09
I2(30)= 4.14672e-08
float(numint(log(x)*sin(n*x),x,0,2*pi, 64 )+(euler+log(2*n*pi)-numCi(2*n*pi))/n)
I3(1)= 1.7779e-06
I3(2)= 3.5558e-06
I3(5)= -0.00261902
I3(10)= -4.63637e+21
I3(20)= -5.32994e+45
I3(30)= -5.19826e+59

Integrals on semi-finite interval

Here one want to compute numericaly the following integrals:
And in smib:
precint=15
print("float(numint(exp(-x)/(1+x^4),x,0,infty,",precint,")-0.63047783)=",
    float(numint(exp(-x)/(1+x^4),x,0,infty,precint)-0.63047783))
print("float(numint(exp(-x^2),x,0,infty,",precint,")-sqrt(pi)/2)=",
    float(numint(exp(-x^2),x,0,infty,precint)-sqrt(pi)/2))
precint=32
print("float(numint(exp(-x)/(2*x+100),x,0,infty,",precint,")-0.00980757)=",
    float(numint(exp(-x)/(2*x+100),x,0,infty,precint)-0.00980757))
print("float(numint(1/(x*log(x)^2),x,2,infty,",precint,")*exp(-2)-0.19524753)=",
    float(numint(1/(x*log(x)^2),x,2,infty,precint)*exp(-2)-0.19524753))
print("float(numint(1/(x*log(x)^(3/2)),x,2,infty,",precint,")*exp(-2)-0.32510855)=",
    float(numint(1/(x*log(x)^(3/2)),x,2,infty,precint)*exp(-2)-0.32510855))
print("float(numint(1/x^(1.01),x,2,infty,",precint,")*exp(-2)-13.628)=",
    float(numint(1/x^(1.01),x,2,infty,precint)*exp(-2)-13.628))
print("float(numint(sin(x)/x,x,2,infty,",precint,")*exp(-2)+0.0046984)=",
    float(numint(sin(x)/x,x,2,infty,precint)*exp(-2)+0.0046984))
print("float(numint(cos(pi*x^2/2),x,2,infty,",precint,")*exp(-2)-0.00158973)=",
    float(numint(cos(pi*x^2/2),x,2,infty,precint)*exp(-2)-0.00158973))
print("float(numint(exp(-x^2),x,2,infty,",precint,")*exp(-2)-0.00056103)=",
    float(numint(exp(-x^2),x,2,infty,precint)*exp(-2)-0.00056103))
print("float(numint(sin(x-1)/sqrt(x*(x-2)),x,2,infty,",precint,")*exp(-2)-
    0.16266891)=",
    float(numint(sin(x-1)/sqrt(x*(x-2)),x,2,infty,precint)*exp(-2)-0.16266891))
print("float(numint(x/(-1+exp(x)),x,2,infty,",precint,")*exp(-2)-0.0583349)=",
    float(numint(x/(-1+exp(x)),x,2,infty,precint)*exp(-2)-0.0583349))
And smib gives:
float(numint(exp(-x)/(1+x^4),x,0,infty, 15 )-0.63047783)= -0.00165007
float(numint(exp(-x^2),x,0,infty, 15 )-sqrt(pi)/2)= 0.000124486
float(numint(exp(-x)/(2*x+100),x,0,infty, 32 )-0.00980757)= -1.49801e-08
float(numint(1/(x*log(x)^2),x,2,infty, 32 )*exp(-2)-0.19524753)= -0.0284713
float(numint(1/(x*log(x)^(3/2)),x,2,infty, 32 )*exp(-2)-0.32510855)= -0.124052
float(numint(1/x^(1.01),x,2,infty, 32 )*exp(-2)-13.628)= -13.0902
float(numint(sin(x)/x,x,2,infty, 32 )*exp(-2)+0.0046984)= 0.00384331
float(numint(cos(pi*x^2/2),x,2,infty, 32 )*exp(-2)-0.00158973)= 3.42789
float(numint(exp(-x^2),x,2,infty, 32 )*exp(-2)-0.00056103)= 7.11359e-09
float(numint(sin(x-1)/sqrt(x*(x-2)),x,2,infty, 32 )*exp(-2)-0.16266891)= -0.0614442
float(numint(x/(-1+exp(x)),x,2,infty, 32 )*exp(-2)-0.0583349)= -4.61325e-08

Oscillatory integrals on semi-finite interval

Our aim is to compute:
And in smib:
print("float(numint(exp(-x)*sin(w*x),x,0,infty,",precint,")-w/(1+w^2))")
IE5(w)=w/(1+w^2)
I5(w)=float(numint(exp(-x)*sin(w*x),x,0,infty,precint)-IE5(w))
print("I5(0)=",I5(0))
print("I5(1)=",I5(1))
print("I5(10)=",I5(10))
print("I5(100)=",I5(100))
print("float(numint(sin(w*x)*x/(1+x^2),x,0,infty,",precint,")-
    pi*exp(-w)/2-pi*dirac(x)/2")
IE6(w)=pi*exp(-w)/2-pi*dirac(w)/2
I6(w)=float(numint(sin(w*x)*x/(1+x^2),x,0,infty,precint)-IE6(w))
print("I6(0)=",I6(0))
print("I6(1)=",I6(1))
print("I6(10)=",I6(10))
print("I6(100)=",I6(100))
print("float(numint(sin(w*x)*sin(x/2)^2/x,x,0,infty,",precint,")-
    test(w<1,pi/4,test(w=1,pi/8,0)))")
IE7(w)=test(w<1,pi/4,test(w=1,pi/8,0))
I7(w)=float(numint(sin(w*x)*sin(x/2)^2/x,x,0,infty,precint)-IE7(w))
print("I7(0)=",I7(0))
print("I7(1)=",I7(1))
print("I7(2)=",I7(2))
precint=30
print("float(numint(10*exp(-x)*sin(16*pi*x)/(1+x^2),x,0,infty,",precint,")-
    0.1990228)=",
    float(numint(10*exp(-x)*sin(16*pi*x)/(1+x^2),x,0,infty,precint)-0.1990228))

And smib gives:
float(numint(exp(-x)*sin(w*x),x,0,infty, 32 )-w/(1+w^2))
I5(0)= 0
I5(1)= -4.4943e-09
I5(10)= -0.325256
I5(100)= 0.0952382
float(numint(sin(w*x)*x/(1+x^2),x,0,infty, 32 )-pi*exp(-w)/2-pi*dirac(x)/2
I6(0)= 0
I6(1)= -0.425646
I6(10)= -0.477525
I6(100)= 1.16202
float(numint(sin(w*x)*sin(x/2)^2/x,x,0,infty, 32 )-test(w<1,pi/4,test(w=1,pi/8,0)))
I7(0)= -0.785398
I7(1)= -0.395398
I7(2)= 0.224667
float(numint(10*exp(-x)*sin(16*pi*x)/(1+x^2),x,0,infty, 30 )-0.1990228)= 0.0884981

Miscellanous integrals

Here one want to compute numericaly the following integrals:
And in smib:
precint=256
print("float(numint(exp(x^2*(1-x)^2),x,0,1,",precint,")-1.03414105)=",
    float(numint(exp(x^2*(1-x)^2),x,0,1,precint)-1.03414105))
print("float(numint(cos(t*sin(x)-n*x),x,0,pi,",precint,")/pi)")
t=quote(t)
n=quote(n)
I4(t,n)=float(numint(cos(t*sin(x)-n*x),x,0,pi,precint)/pi)
    print("I4(8,1)-0.23463634=",float(I4(8,1)-0.23463634))

And smib gives:
float(numint(exp(x^2*(1-x)^2),x,0,1, 256 )-1.03414105)= 6.2767e-06
float(numint(cos(t*sin(x)-n*x),x,0,pi, 256 )/pi)
I4(8,1)-0.23463634= 6.85398e-09

Wavelets

Let f and g two real functions with real values, the aim here is to compute numerically: T(f, g, a, b) = 1af(x)g(x + b)/(a)dx with the function numint. So in smib we can build the following function:
wavelet(f,g,x,a,b,n)=prog(temp0,temp1,temp2,temp3,temp4,temp5,
    do(temp5=zero((n+1)^2,3),
    temp2=2*a/n,
    temp3=2*b/n,
    temp4=1,
    for(temp0,1,n+1,
        for(temp1,1,n+1,
        do(temp5[temp4,1]=-a+temp2*(temp0-1),
           temp5[temp4,2]=-b+temp3*(temp1-1),
           test(temp5[temp4,2]==0,
           temp5[temp4,3]=0,
            temp5[temp4,3]=1/temp5[temp4,1]*
            numint(expand(f*conj(dilatation(translation(g,x,temp5[temp4,2])
            ,x,1/temp5[temp4,1]))),x,-20,20,n)),
            temp4=temp4+1)
        )
    ),
    return(temp5)
))

For example, we can apply this to f(x) = sin(x), g(x) = e − x2,  a ∈ [ − 5, 5],  b ∈ [ − 5, 5]
, and n = 31 is the sampling rate (it must be odd to avoid division by zero):
wavelet(sin(x),exp(-x^2),x,5,5,31)

Using qgfe, we have the following graphical representation:
figure image/waveletsin.png


5.6.5Discrete Fourier transform

Elementary functions
Now, we will study the behavior of discrete Fourier transform for the following functions: te − t2, t1(1 + t2), te − ∣t, tsgn(t)e − ∣t, tJ0(t), tsgn(t), t1t, t⟼ln(∣t∣), teit2, and the following properties: (F − 1(f)) = f,  − 1( F(f)) = f, x(F(f)) =  − ix(f)(here we compare symbolic solution with numeric one).
First, we define a function to test properties:
testnumfourier(f,t,a,b,n)=prog(temp1,temp2,temp3,temp4,ind,
    do(print("********************************"),
       print("* f(",t,")=",f,"a=",a,"b=",b,"n=",n),
       print("********************************"),
       temp2=fourier(f),
       print("fourier(",f,",",t,") = ",temp2),
       temp1=zero(n+1,2),
       temp1=sample(f,t,-a,a,n),
       temp3=zero(n+1,2),
       temp3=sample(temp2,t,-b,b,n),
       print("Snorm(Sdiscfourier(",f,",",a,",",b,")-fourier(",f,",",t,")=",
              Snorm(num(Sdiff(Sdiscfourier(temp1,a,b),temp3)))),
       print("Snorm(Sdiscfourier(num(Sdiscinvfourier(",f,",",a,",",b,")),
              ",b,",",a,")-",f,") = ",
              Snorm(num(Sdiff(Sdiscfourier(num(Sdiscinvfourier(temp1,a,b)),b,a),
              temp1)))),
       print("Snorm(Sdiscinvfourier(num(Sdiscfourier(",f,",",a,",",b,")),
              ",b,",",a,")-",f,") = ",
              Snorm(num(Sdiff(Sdiscinvfourier(num(Sdiscfourier(temp1,a,b)),b,a),
              temp1)))),
       temp3=zero(n+1,2),
       temp3=num(Sdiscfourier(temp1,a,b)),
       temp2=d(f,t),
       temp1=sample(temp2,t,-a,a,n),
       temp4=zero(n+1,2),
       for(ind,1,n+1,temp4[ind,1]=temp3[ind,1]),
           for(ind,1,n+1,temp4[ind,2]=i*temp3[ind,1]*temp3[ind,2]),
               print("Snorm(Sdiscinvfourier(i*",t,"*",f,",",b,",",a,")-
               d(",f,",",t,") = ",
               Snorm(num(Sdiff(Sdiscinvfourier(temp4,b,a),temp1)))),
               print(" ")
        ))

Next, we apply this program to selected functions:
a=5
b=2*a
n=51
f(t)=exp(-t^2)
testnumfourier(f(t),t,a,b,n)
g(t)=expand(convolution(f(t),f(t)))
print("convolution(f(t),f(t)) = ",g(t))
Sf=sample(f(t),t,-a,a,n)
Sg=sample(g(t),t,-a,a,n)
print("Snorm(Sdiscconvolution(",f(t),",",f(t),",",a,",",b,")-
    convolution(",f(t),",",f(t),")) = ",
Snorm(num(Sdiff(Sdiscconvolution(Sf,Sf,a,b),Sg))))

And the result is:
********************************
* f( t )= exp(-t^2) a= 5 b= 10 n= 51 *
*******************************
fourier( exp(-t^2) , t ) = pi^(1/2)*exp(-1/4*t^2)
Snorm(Sdiscfourier( exp(-t^2) , 5 , 10 )-fourier( exp(-t^2) , t ) =
(0.443142,0.0348067,0.0506453)
Snorm(Sdiscfourier(num(Sdiscinvfourier( exp(-t^2) , 5 , 10 )), 10 , 5 )-
exp(-t^2) ) =
(0.354049,0.0274153,0.0407308)
Snorm(Sdiscinvfourier(num(Sdiscfourier( exp(-t^2) , 5 , 10 )), 10 , 5 )-
exp(-t^2) ) =
(0.354049,0.0274153,0.0407308)
Snorm(Sdiscinvfourier(i* t * exp(-t^2) , 10 , 5 )-d( exp(-t^2) , t ) =
(0.619336,0.0531368,0.0674757)
convolution(f(t),f(t)) = pi^(1/2)*exp(-1/2*t^2)/(2^(1/2))
Snorm(Sdiscconvolution( exp(-t^2) , exp(-t^2) , 5 , 10 )-
convolution( exp(-t^2) , exp(-t^2) )) =
(0.742598,0.0685593,0.0768405)
a=15
b=2*a
f(t)=1/(1+t^2)
testnumfourier(f(t),t,a,b,n)
g(t)=expand(convolution(f(t),f(t)))
print("convolution(f(t),f(t)) = ",g(t))
Sf=sample(f(t),t,-a,a,n)
Sg=sample(g(t),t,-a,a,n)
print("Snorm(Sdiscconvolution(",f,",",f,",",a,",",b,")-
    convolution(",f(t),",",f(t),")) = ",
    Snorm(num(Sdiff(Sdiscconvolution(Sf,Sf,a,b),Sg))))

And the result is:
********************************
* f( t )= 1/(1+t^2) a= 15 b= 30 n= 51 *
*******************************
fourier( 1/(1+t^2) , t ) = pi*exp(-abs(t))
Snorm(Sdiscfourier( 1/(1+t^2) , 15 , 30 )-fourier( 1/(1+t^2) , t ) =
(6.67913,0.645725,0.664032)
Snorm(Sdiscfourier(num(Sdiscinvfourier( 1/(1+t^2) ,15 ,30 )),30 ,15 )-
1/(1+t^2) ) =
(13.5151,1.3161,1.33437)
Snorm(Sdiscinvfourier(num(Sdiscfourier( 1/(1+t^2) ,15 ,30 )),30 ,15 )-
1/(1+t^2) ) =
(13.5151,1.3161,1.33437)
Snorm(Sdiscinvfourier(i* t * 1/(1+t^2) , 30 , 15 )-d( 1/(1+t^2) , t ) =
(96.852,12.0158,6.00083)
convolution(f(t),f(t)) = pi/(2*(1+1/4*t^2))
Snorm(Sdiscconvolution( 1/(1+t^2) , 1/(1+t^2) , 15 , 30 )-
convolution( 1/(1+t^2) , 1/(1+t^2) )) =
(31.1821,3.82376,2.01925)
f(t)=exp(-abs(t))
testnumfourier(f(t),t,a,b,n)

And the result is:
********************************
* f( t )= exp(-abs(t)) a= 15 b= 30 n= 51 *
*******************************
fourier( exp(-abs(t)) , t ) = 2/(1+t^2)
Snorm(Sdiscfourier(exp(-abs(t)),15,30 )-fourier(exp(-abs(t)),t) =
(5.01712,0.524056,0.457636)
Snorm(Sdiscfourier(num(Sdiscinvfourier(exp(-abs(t)),15,30)),30,15)-
exp(-abs(t)) ) =
(10.2045,0.905532,1.08746)
Snorm(Sdiscinvfourier(num(Sdiscfourier(exp(-abs(t)),15,30)),30,15)-
exp(-abs(t)) ) =
(10.2045,0.905532,1.08746)
Snorm(Sdiscinvfourier(i*t*exp(-abs(t)),30,15)-d(exp(-abs(t)),t) =
(72.5799,8.69548,5.06886)
f(t)=sgn(t)*exp(-abs(t))
testnumfourier(f(t),t,a,b,n)

And the result is:
********************************
* f( t )= exp(-abs(t))*sgn(t) a= 15 b= 30 n= 51 *
*******************************
fourier( exp(-abs(t))*sgn(t) , t ) = -2*i*t/(1+t^2)
Snorm(Sdiscfourier( exp(-abs(t))*sgn(t) , 15 , 30 )-
fourier( exp(-abs(t))*sgn(t) , t ) =
(5.39782,0.693004,0.282954)
Snorm(Sdiscfourier(num(Sdiscinvfourier(exp(-abs(t))*sgn(t),15,30)),30,15)-
exp(-abs(t))*sgn(t) ) =
(10.5348,0.858053,1.18237)
Snorm(Sdiscinvfourier(num(Sdiscfourier(exp(-abs(t))*sgn(t),15,30)),30,15)-
exp(-abs(t))*sgn(t) ) =
(10.5348,0.858053,1.18237)
Snorm(Sdiscinvfourier(i*t*exp(-abs(t))*sgn(t),30,15)-
d( exp(-abs(t))*sgn(t) , t ) =
(73.1423,8.6207,5.34454)
f(t)=besselj(t,0)
testnumfourier(f(t),t,a,b,n)

And the result is:
********************************
* f( t )= besselj(t,0) a= 15 b= 30 n= 51 *
*******************************
fourier( besselj(t,0) , t ) = 2*carac(t,-1,1)/((1-t^2)^(1/2))
Snorm(Sdiscfourier(besselj(t,0),15,30)-fourier(besselj(t,0),t) =
(9.46802,0.688005,1.11829)
Snorm(Sdiscfourier(num(Sdiscinvfourier(besselj(t,0),15,30)),30,15)-
besselj(t,0) ) =
(16.9622,1.81847,1.49203)
Snorm(Sdiscinvfourier(num(Sdiscfourier(besselj(t,0),15,30)),30,15)-
besselj(t,0) ) =
(16.9622,1.81847,1.49203)
Snorm(Sdiscinvfourier(i*t*besselj(t,0),30,15)-d(besselj(t,0),t) =
(130.969,15.8296,8.90423)
f(t)=sgn(t)
testnumfourier(f(t),t,a,b,n)

And the result is:
********************************
* f( t )= sgn(t) a= 15 b= 30 n= 51 *
*******************************
fourier( sgn(t) , t ) = -2*i/t
Snorm(Sdiscfourier( sgn(t) , 15 , 30 )-fourier( sgn(t) , t ) =
(20.6297,1.85462,2.17822)
Snorm(Sdiscfourier(num(Sdiscinvfourier(sgn(t),15,30)),30,15)-sgn(t) ) =
(33.0518,4.16739,1.90812)
Snorm(Sdiscinvfourier(num(Sdiscfourier(sgn(t),15,30)),30,15)-sgn(t) ) =
(33.0518,4.16739,1.90812)
Snorm(Sdiscinvfourier(i* t * sgn(t) ,30,15)-d(sgn(t),t) =
(323.675,37.8883,24.0665)
f(t)=1/t
testnumfourier(f(t),t,a,b,n)
g(t)=expand(convolution(f(t),f(t)))
print("convolution(f(t),f(t)) = ",g(t))
Sf=sample(f(t),t,-a,a,n)
Sg=sample(g(t),t,-a,a,n)
print("Snorm(Sdiscconvolution(",f,",",f,",",a,",",b,")-
    convolution(",f(t),",",f(t),")) = ",
    Snorm(num(Sdiff(Sdiscconvolution(Sf,Sf,a,b),Sg))))

And the result is:
********************************
* f( t )= 1/t a= 15 b= 30 n= 51 *
*******************************
fourier( 1/t , t ) = -i*pi*sgn(t)
Snorm(Sdiscfourier( 1/t , 15 , 30 )-fourier( 1/t , t ) =
(31.0465,3.65496,2.27541)
Snorm(Sdiscfourier(num(Sdiscinvfourier(1/t,15,30)),30,15)- 1/t ) =
(44.7573,3.43926,5.16671)
Snorm(Sdiscinvfourier(num(Sdiscfourier(1/t,15,30)),30,15)- 1/t ) =
(44.7573,3.43926,5.16671)
Snorm(Sdiscinvfourier(i*t*1/t,30,15)-d( 1/t , t ) =
(311.349,34.7573,25.6149)
convolution(f(t),f(t)) = -pi^2*dirac(t)
Snorm(Sdiscconvolution(1/t,1/t,15,30)-convolution(1/t,1/t)) =
(148.74,12.0376,16.7496)
f(t)=log(abs(t))
testnumfourier(f(t),t,a,b,n)

And the result is:
********************************
* f( t )= log(abs(t)) a= 15 b= 30 n= 51
********************************
fourier( log(abs(t)) , t ) = -2*euler*pi*dirac(t)-pi/abs(t)
Snorm(Sdiscfourier( log(abs(t)),15,30)-fourier( log(abs(t)) , t ) =
(84.371,5.04987,10.5543)
Snorm(Sdiscfourier(num(Sdiscinvfourier(log(abs(t)),15,30)),30,15)-
log(abs(t)) ) =
(140.543,17.5647,8.44608)
Snorm(Sdiscinvfourier(num(Sdiscfourier(log(abs(t)),15,30)),30,15)-
log(abs(t)) ) =
(140.543,17.5647,8.44608)
Snorm(Sdiscinvfourier(i*t*log(abs(t)),30,15)-d(log(abs(t)),t) =
(1295.74,171.879,52.394)
a=5
b=2*a
f(t)=exp(i*t^2)
testnumfourier(f(t),t,a,b,n)
g(t)=expand(convolution(f(t),f(t)))
print("convolution(f(t),f(t)) = ",g(t))
Sf=sample(f(t),t,-a,a,n)
Sg=sample(g(t),t,-a,a,n)
print("Snorm(Sdiscconvolution(",f(t),",",f(t),",",a,",",b,")-
    convolution(",f(t),",",f(t),")) = ",
    Snorm(num(Sdiff(Sdiscconvolution(Sf,Sf,a,b),Sg))))

And the result is:
********************************
* f( t )= exp(i*t^2) a= 5 b= 10 n= 51
********************************
fourier( exp(i*t^2) , t ) =
i*pi^(1/2)*exp(-1/4*i*t^2)/(2^(1/2))+pi^(1/2)*exp(-1/4*i*t^2)/(2^(1/2))
Snorm(Sdiscfourier( exp(i*t^2),5,10)-fourier(exp(i*t^2),t) =
(8.11164,0.866755,0.717006)
Snorm(Sdiscfourier(num(Sdiscinvfourier(exp(i*t^2),5,10)),10,5)-
exp(i*t^2) ) =
(7.67046,0.911807,0.547786)
Snorm(Sdiscinvfourier(num(Sdiscfourier(exp(i*t^2),5,10)),10,5)-
exp(i*t^2) ) =
(1.91515,0.174735,0.200005)
Snorm(Sdiscinvfourier(i*t*exp(i*t^2),10,5)-d(exp(i*t^2),t) =
(18.9607,1.71943,1.98926)
convolution(f(t),f(t)) = 1/2*i*pi^(1/2)*exp(1/2*i*t^2)+1/2*pi^(1/2)*exp(1/2*i*t^2)
Snorm(Sdiscconvolution(exp(i*t^2),exp(i*t^2),5,10)-
convolution( exp(i*t^2) , exp(i*t^2) )) =
(3.90963,0.516912,0.163551)
Differential equations
Here we want to solve numerically the following differential equations:
First we compute symbolic solution, and after we compare numeric solution with symbolic solution.

For equation (I):
f=quote(f)
a=5
b=2*a
n=61
A=i*d(f(t),t)+f(t)-dirac(t)
A
FA=fourier(A,t)
SYMA=roots(FA,fourier(f(t),t))
print("symbole: ",SYMA)
SSYMA=sample(SYMA,t,-b,b,n)
print("échantillon: ",num(SSYMA))
IFSSYMA=Sdiscinvfourier(SSYMA,b,a)
print("inversion: ",num(IFSSYMA))
SSf=invfourier(SYMA,t)
print("solution symbolique: ",SSf)
Sf=sample(SSf,t,-a,a,n)
Sn1=Snorm(num(Sdiff(IFSSYMA,Sf)))
print("Erreur I: ",Sn1)
A=Sreal(IFSSYMA)
B=Simag(IFSSYMA)
ASf=Sreal(Sf)
BSf=Simag(Sf)
We plot A, B, ASf, BSf:
figure image/fourode1.png
Here, results are not very good because symbol 11 − t has real singularity.

For equation (II):
Using same script, replacing A=i*d(f(t),t)+f(t)-dirac(t) by A=d(f(t),t,2)-f(t)-dirac(t).
figure image/fourode2.png
Here, results are better because symbol  − 1t2 + 1 has complex singularities.
Pseudo-differential operator
The aim is to study action of pseudo-differential operator on function, in fact we want to implement numerically the following operator:
I(σ, f)(x) = 12πσ(x, ξ).(ξ).eix.ξdξ
where σ is the symbol of operator, and f a function.
Let a an operator, we assume that a depends of a function f, the symbol S of a is defined by Sa(x, y) = e − ixya(eixy), so in smib:
symbol(a,f,x,y)=exp(-i*x*y)*expand(subst(exp(i*x*y),f,a)).
From the symbol, we can calculate the kernel of the operator (the kernel is defined by Kσ(x, y) = 12πei(x − y).ξσ(x, ξ)dξ), thus in smib:
Skernel(s,x,y,a,b,n)=prog(temp0,temp1,temp2,temp3,temp4,temp5,temp6,
     do(temp5=zero((n+1)^2,3),
     temp2=2*a/n,
     temp3=2*b/n,
     temp4=1,
     for(temp0,1,n+1,
          for(temp1,1,n+1,do(
              temp5[temp4,1]=num(-a+temp2*(temp0-1)),
              temp5[temp4,2]=num(-b+temp3*(temp1-1)),
              temp5[temp4,3]=num(1/(2*pi)*Sint(sample(
               expand(exp(i*(temp5[temp4,1]-temp5[temp4,2])*temp6))*
               subst(temp6,y,subst(temp5[temp4,1],x,s)),
              temp6,-(a+b),(a+b),n))),
              temp4=temp4+1)
          )
     ),
     return(temp5)))

This function constructs a sample S ∈ ℝn × ℝn × ℂn.
Now we enter the heart of the matter, here is the implementation of I(σ, f)(x) = 12πσ(x, ξ).(ξ).eix.ξdξ, so in smib:
Spseudodiff(s,f,x,y,b)=prog(temp0,temp1,temp2,temp3,temp4,temp5,
     do(temp4=Sdiscfourier(f,f[dim(f),1],b),
     temp0=zero(dim(f),2),
     test(indnorm==1,temp3=b^degree(s,y)*s*(b^2+y^2)^(-degree(s,y)/2),temp3=s),
          for(temp1,1,dim(f),
              temp0[temp1,1]=f[temp1,1]),
              for(temp1,1,dim(f),
                  temp0[temp1,2]=num(1/(2*pi)*Sint(Sproduct(
                   sample(expand(subst(f[temp1,1],x,temp3)*exp(i*f[temp1,1]*y)),
                          y,-b,b,dim(f)-1),temp4)
              )
          )
     ),
     return(temp0)))
For example, for a(f, x) =  − x22xf + f, implementation is in smib:
a=5
b=4*a
n=101
op(m,x)=m-x^2*d(m,x,2)
s=symbol(op(m(x),x),m(x),x,y)
f=exp(-x^2)
print("Operator: ",op)
print("Symbol: ",s)
print("f: ",f)
print("Theoric solution: ",op(f,x))
g=sample(op(f,x),x,-a,a,n)
f=sample(exp(-x^2),x,-a,a,n)
S2=Spseudodiff(s,f,x,y,b)
print("Deviation to theoric solution: ",Snorm(num(Sdiff(S2,g))))

And the result is:
Operator: m-x^2*d(m,x,2)
Symbol: 1+x^2*y^2
f: exp(-x^2)
Theoric solution: 2*x^2*exp(-x^2)-4*x^4*exp(-x^2)+exp(-x^2)
Deviation to theoric solution: (0.736434,0.0497708,0.0532906)
figure image/pseudoS3.png
Another example would be a(f, x) = ∂2xf + sgn(x).f, in a similar way, smib gives:
Operator: sgn(x)*m+d(m,x,2)
Symbol: -y^2+sgn(x)
f: exp(-x^2)
Theoric solution: 4*x^2*exp(-x^2)+exp(-x^2)*sgn(x)-2*exp(-x^2)
Deviation to theoric solution: (0.732819,0.0389701,0.0612068)
figure image/pseudoS4.png
Wavelets
With the function Swavelet(f,g,x,a,b,n) we can estimate: T(f, g, a, b) = 1af(x)g(x + b)/(a)dx for a sample f and a function g defined on [ − a, a] × [ − b, b](contrary to paragraph 5.6, g can be used for complex-valued function):
Swavelet(f,g,x,a,b,n)=prog(temp0,temp1,temp2,temp3,temp4,temp5,
do(temp5=zero((n+1)^2,3),
   temp2=2*a/n,
   temp3=2*b/n,
   temp4=1,
   for(temp0,1,n+1,
      for(temp1,1,n+1,
         do(temp5[temp4,1]=-a+temp2*(temp0-1),
            temp5[temp4,2]=-b+temp3*(temp1-1),
            test(temp5[temp4,2]==0,
                temp5[temp4,3]=0,
                temp5[temp4,3]=1/temp5[temp4,1]*
                    Sint(Sproduct(f,
                        sample(expand(conj(dilatation(
                            translation(g,x,temp5[temp4,2]),x,1/temp5[temp4,1])))
                        ,x,-f[1,1],f[1,1],dim(f)-1)))),
            temp4=temp4+1)
   )),
   return(temp5)))

For example for: let f(x) = 1[ − 1, 1](x)sin(3x) + 1[ − 2, 2](x)cos(3x) + 1[ − 3, 3](x)sin(4x) + 1[ − 4, 4](x)cos(5x) and g(x) = e − 5ixe − x2, in smib:
f=carac(x,-1,1)*sin(3*x)+carac(x,-2,2)*cos(3*x)+
    carac(x,-3,3)*sin(4*x)+carac(x,-4,4)*cos(5*x)
F=sample(f,x,-5,5,60)
S=Swavelet(F,exp(-5*i*x)*exp(-x^2),x,3,3,21)

Here S is a complex sample, with qgfe, we can plot real part:
figure image/wavelet_real_appl.png
And for imaginary part:
figure image/wavelet_imag_appl.png


5.6.6 Complex analysis

Now, we are going to see how to use Gauss scheme in the context of complex analysis.
First, how to draw a path in the complex plane; the following program solves this problem:
gnuplotcomplexpath(P,N)=prog(C,t,a,b,temp1,temp2,temp3,temp4,do(
    C=P[1],
    t=P[2],
    a=P[3],
    b=P[4],
    temp1=sample(C,t,a,b,N),
    temp2=Sdecomp(Sreal(temp1),2),
    temp3=Sdecomp(Simag(temp1),2),
    temp4=Srecomp(temp2,temp3),
    gnuplot2D(temp4)
))

Now we can test it on C = ((R − r)cos(t) + d.ccos((R − r)tr)) + i((R − r)sin(t) − d.sin((R − r)tr)), r = 3, R = 5, d = 5. So in smib:
a=0
b=6*pi
N=100
r=3
R=5
d=5
C=((R-r)cos(t)+d*cos((R-r)*t/r)+i*((R-r)sin(t)-d*sin((R-r)*t/r)),t,a,b)
Cur=gnuplotcomplexpath(C,N)

With qgfe:
figure image/cplxpath.png

Complex path integral is defined by: Cf(z).dz = [a, b]f(C(t)).C(t).dt, C:[a, b] → ℂ; so in smib:
numcomplexpathint(f,z,P)=prog(C,t,a,b,temp1,do(
    C=P[1],
    t=P[2],
    a=P[3],
    b=P[4],
    temp1=num(numint(subst(C,z,f)*d(C,t),t,a,b)),
    return(temp1)
))

Let C = R.exp(it), R = 1, t ∈ [a, b],  f(z) = 1z, we want to check: Cf(z).dz = 2iπ:
I=num(numcomplexpathint(f,z,C)-2*i*pi)
print("f =",f)
print("I =",I)

And smib gives:
f = 1/z
I = 0.00646429*i

If f(z) = log(z):
f = log(z)
I = -0.0203068 - 0.000138975 i

Index of a path is defined by: Ind(C, z0) = 12iπC1z − z0dz, so in smib:
numindex(P,z0)=prog(temp1,do(
    temp1=num(numcomplexpathint(1/(z-z0),z,P)/(2*i*pi)),
    return(temp1)
))

With this small script:
print("index")
z0=0
I=numindex(C,z0)
print("z0 =",z0," Index = ",I)
z0=2
I=numindex(C,z0)
print("z0 =",z0," Index = ",I)
z0=2*i
I=numindex(C,z0)
print("z0 =",z0," Index = ",I)
a=0
b=6*pi
r=3
R=5
d=5
C=((R-r)cos(t)+d*cos((R-r)*t/r)+i*((R-r)sin(t)-d*sin((R-r)*t/r)),t,a,b)
print("C =",C)
z0=0
I=numindex(C,z0)
print("z0 =",z0," Index = ",I)
z0=5
I=numindex(C,z0)
print("z0 =",z0," Index = ",I)
z0=-5
I=numindex(C,z0)
print("z0 =",z0," Index = ",I)

smib gives:
index
z0 = 0
Index = 1.00103
z0 = 2
Index = -0.00102839+5.37827e-17*i
z0 = 2*i
Index = 0.000213725+0.000456854*i
C = (2*cos(t)+5*cos(2/3*t)+2*i*sin(t)-5*i*sin(2/3*t),t,0,6*pi)
z0 = 0
Index = -2.00354-1.18686e-16*i
z0 = 5
Index = -1.13743-1.08772e-14*i
z0 = -5
Index = -0.500247-5.85538e-16*i

We can also compute number of singularities NSing(f, C) = 12iπCffdz, in smib:
numsing(f,z,P)=prog(temp1,do(
    temp1=num(numcomplexpathint(simplify(d(f,z)/f),z,P)/(2*i*pi)),
    return(temp1)
))

Using this test script:
print("number of singularities")
a=0
b=2*pi
R=2
C=(R*exp(i*t),t,a,b)
print("C =",C)
f=z^2+1
I=numsing(f,z,C)
print("f =",f," I =",I)
f=1/(1+z^2)
I=numsing(f,z,C)
print("f =",f," I =",I)
f=sin(z)
I=numsing(f,z,C)
print("f =",f," I =",I)
f=1/sin(z)
I=numsing(f,z,C)
print("f =",f," I =",I)
f=1/(1+z^3)
I=numsing(f,z,C)
print("f =",f," I =",I)
f=1+z^3
I=numsing(f,z,C)
print("f =",f," I =",I)
f=z-1
I=numsing(f,z,C)
print("f =",f," I =",I)
f=1/(z+1)
I=numsing(f,z,C)
print("f =",f," I =",I)
f=z-1+1/(z+1)
I=numsing(f,z,C)
print("f =",f," I =",I)

and smib gives:
number of singularities
C = (2*exp(i*t),t,0,2*pi)
f = 1+z^2
I = 2.00163+9.75002e-19*i
f = 1/(1+z^2)
I = -2.00163-9.75002e-19*i
f = sin(z)
I = 1.0023+2.13904e-16*i
f = 1/(sin(z))
I = -1.0023-2.13904e-16*i
f = 1/(1+z^3)
I = -3.00261-1.76267e-18*i
f = 1+z^3
I = 3.00261+1.76267e-18*i
f = -1+z
I = 1.00206+5.37827e-17*i
f = 1/(1+z)
I = -1.00053-3.39165e-17*i
f = -1+z+1/(1+z)
I = 1.00153-3.95706e-17*i

N.B.: the final result is not correct, another weakness.


5.6.7Ordinary differential equation

With the operator dsolve, smid can resolve symbolically ordinary differential equation like: q(x)y’ + p(x)y = g(x) (smib simply applies: u(x) = exp(t)q(t)dt and y = (xu(t)g(t)q(t)dt + c)u(x)). As the integrator is a little bit weak, ordinary differential equation can be also solved using numerical method, here we use Euler method (Runge-Kutta method is better... but harder to understand).

smib can solve the following global problem: dX(t)dt = X(t), X(a) = X0, t ∈ [a, b] where X is a scalar or a vector, Euler method can be implemanted as:
eulerode(F,X0,Var,Sample)=prog(a,b,n,dimpb,h,M,ind1,ind2,ind3,ind4,temp,do(
    a=Sample[1],
    b=Sample[2],
    n=Sample[3],
    dimpb=dim(Var),
    h=(b-a)/n,
    M=zero(n+1,dimpb),
    for(ind1,1,n+1,M[ind1,1]=a+(ind1-1)*h),
    for(ind1,1,n+1,
        for(ind2,2,dimpb,
            test(ind1==1,
                test(dim(F)==0,M[ind1,ind2]=num(X0),
                               M[ind1,ind2]=num(X0[ind2-1])),
                test(dim(F)==0,