Symbolic algebra and Mathematics with Xcas

Renée De Graeve, Bernard Parisse
University of Grenoble I

© 2002, 2007 Renée De Graeve, Bernard Parisse


Chapter 1  Index


Chapter 2  The CAS functions

2.1  Symbolic constants : e pi infinity i

e is the number exp(1);
pi is the number π.
infinity is unsigned ∞.
+infinity is +∞.
-infinity is −∞.
i is the complex number i.

2.2  Booleans

2.3  Operators bit to bit

2.4  Strings

2.5  Write an integer in a b basis: convert

convert or convertir can do different kind of conversions depending on the option given as the second argument.

To convert an integer n into the list of its coefficients in a basis b, the option is base. The arguments of convert or convertir are an integer n, base and b the value of the basis.
convert or convertir returns the list of coefficients in a b basis of the integer n Input :


Output :


To check the answer, input expr("0173") or horner(revlist([3,7,1]),8) or convert([3,7,1],base,8) and output is 123
Input :


Output :


To convert the list of coefficients in a basis b of an integer n, the option is also base. convert or convertir returns the integer n.
Input :




Output :


Input :




Output :


2.6  Integers (and Gaussian Integers)

For all functions in this section, you can use Gaussian integers (numbers of the form a+ib, where a and b in ℤ) in the place of integers.

2.7  Combinatory analysis

2.8  Rationals

2.9  Real numbers

2.10  Permutations

A permutation p of size n is a bijection from [0..n−1] on [0..n−1] and is represented by the list : [p(0),p(1),p(2)...p(n−1)].
For example, the permutation p represented by [1,3,2,0] is the application from [0,1,2,3] on [0,1,2,3] defined by :

p(0)=1, p(1)=3, p(2)=2,  p(3)=0 

A cycle c of size p is represented by the list [a0,...,ap−1] (0≤ akn−1) it is the permutation such that

c(ai)=ai+1  for (i=0..p−2),    c(ap−1)=a0,     c(k)=k  otherwise

A cycle c is represented by a list and a cycle decomposition is represented by a list of lists.
For example, the cycle c represented by the list [3,2,1] is the permutation c defined by c(3)=2, c(2)=1, c(1)=3, c(0)=0 (i.e. the permutation represented by the list [0,3,1,2]).

2.11  Complex numbers

Note that complex numbers are also used to represent a point in the plan or a 1-d function graph.

2.12  Algebraic expressions

2.13  Values of un

2.14  Operators or infixed functions

An operator is an infixed function.

2.15  Functions and expressions with symbolic variables

2.16  Functions

2.17  Derivation and applications.

2.18  Integration

2.19  Limits

2.20  Rewriting transcendental and trigonometric expressions

2.21  Trigonometry

2.22  Fourier transformation

2.23  Exponentials and Logarithms

2.24  Polynomials

A polynomial of one variable is represented either by a symbolic expression or by the list of it’s coefficients by decreasing powers order (dense representation). In the latter case, to avoid confusion with other kinds of list

Note that polynomials represented as lists of coefficients are always written in decreassing powers order even if increasing power is checked in cas configuration.

A polynomial of several variables is represented

2.25  Arithmetic and polynomials

Polynomials are represented by expressions or by list of coefficients by decreasing power order. In the first case, for instructions requiring a main variable (like extended gcd computations), the variable used by default is x if not specified. For modular coefficients in ℤ/nℤ, use % n for each coefficient of the list or apply it to the expression defining the polynomial.

2.26  Orthogonal polynomials

2.27  Gröbner basis and Gröbner reduction

2.28  Rational fractions

2.29  Exact roots of a polynomial

2.30  Exact roots and poles

2.31  Computing in ℤ/pℤ or in ℤ/pℤ[x]

The way to compute over ℤ/pℤ or over ℤ/pℤ[x] depends on the syntax mode :


2.32  Compute in ℤ/pℤ[x] using Maple syntax

2.33  Taylor and asymptotic expansions

2.34  Intervals

2.35  Sequences

2.36  Sets

2.37  Lists and vectors

2.38  Functions for vectors

2.39  Statistic functions : mean,variance,stddev, stddevp,median,quantile,quartiles,boxwhisker

The functions described here may be used if the statistic serie is contained in a list. See also section 2.42.31 for matrices and chapter ?? for weighted lists.

Define the list A by:


Outputs :

  1. 11/2 for mean(A)
  2. sqrt(143/12) for stddev(A)
  3. 0 for min(A)
  4. [1.0] for quantile(A,0.1)
  5. [2.0] for quantile(A,0.25)
  6. [5.0] for median(A) or for quantile(A,0.5)
  7. [8.0] for quantile(A,0.75)
  8. [9.0] for quantile(A,0.9)
  9. 11 for max(A)
  10. [[0.0],[2.0],[5.0],[8.0],[11.0]] for quartiles(A)

2.40  Table with string as index : table

A table is an associative container (or map), it is used to store informations associated to indexes which are much more general than integers, like strings or sequences. It may be used for example to store a table of phone numbers indexed by names.
In Xcas, the indexes in a table may be any kind of Xcas objects. Access is done by a binary search algorithm, where the sorting function first sorts by type then uses an order for each type (e.g. < for numeric types, lexicographic order for strings, etc.)
table takes as argument a list or a sequence of equalities index_name=element_value.
table returns this table.
Input :


Input :


Output :


Input :


Output :


If you assign T[n]:= ... where T is a variable name and n an integer

2.41  Usual matrix

A matrix is represented by a list of lists, all having the same size. In the Xcas answers, the matrix delimiters are [] (bold brackets). For example, [1,2,3] is the matrix [[1,2,3]] with only one row, unlike [1,2,3] (normal brackets) which is the list [1,2,3].
In this document, the input notation ([[1,2,3]]) will be used for input and output.

2.42  Arithmetic and matrix

2.43  Linear algebra

2.44  Linear Programmation

Linear programming problems are maximization problem of a linear functional under linear equality or inequality constraints. The most simple case can be solved directly by the so-called simplex algorithm. Most cases requires to solve an auxiliary linear programming problem to find an initial vertex for the simplex algorithm.

2.45  Different matrix norm

2.46  Matrix reduction

2.47  Isometries

2.48  Matrix factorizations

Note that most matrix factorization algorithms are implemented numerically, only a few of them will work symbolically.

2.49  Quadratic forms

2.50  Multivariate calculus

2.51  Equations

2.52  Linear systems

In this paragraph, we call "augmented matrix" of the system A · X=B (or matrix "representing" the system A · X=B), the matrix obtained by gluing the column vector B or −B to the right of the matrix A, as with border(A,tran(B)).

2.53  Differential equations

This section is limited to symbolic (or exact) solutions of differential equations. For numeric solutions of differential equations, see odesolve. For graphic representation of solutions of differential equations, see plotfield, plotode and interactive_plotode.

2.54  Other functions

Chapter 3  Graphs

Most graph instructions take expressions as arguments. A few exceptions (mostly maple-compatibility instructions) also accept functions. Some optional arguments, like color, thickness, can be used as optional attributes in all graphic instructions. They are described below.

3.1  Graph and geometric objects attributes

There are two kinds of attributes: global attributes of a graphic scene and individual attributes.

3.2  Graph of a function : plotfunc funcplot DrawFunc Graph

3.3  2d graph for Maple compatibility : plot

plot(f(x),x) draws the graph of y=f(x). The second argument may specify the range of values x=xmin..xmax. One can also plot a function instead of an expression using the syntax plot(f,xmin..xmax). plot accepts an optional argument to specify the step used in x for the discretisation with xstep= or the number of points of the discretization with nstep=.
Input :


Output :

the graph of y=x^2-2

Input :




Output :

a polygonal line which is a bad representation of y=x^2-2



3.4  3d surfaces for Maple compatibility plot3d

plot3d takes three arguments : a function of two variables or an expression of two variables or a list of three functions of two variables or a list of three expressions of two variables and the names of these two variables with an optional range (for expressions) or the ranges (for functions).
plot3d(f(x,y),x,y) (resp plot3d([f(u,v),g(u,v),h(u,v)],u,v)) draws the surface z=f(x,y) (resp x=f(u,v),y=g(u,v),z=h(u,v)). The syntax plot3d(f(x,y),x=x0..x1,y=y0..y1) or plot3d(f,x0..x1,y0..y1) specifies which part of surface will be computed (otherwise default values are taken from the graph configuration).
Input :


Output :

The surface z=x*y

Input :


Output :

The cone x=v*cos(u),y=v*sin(u),z=v

Input :


Output :

A portion of the cone x=v*cos(u),y=v*sin(u),z=v

3.5  Graph of a line and tangent to a graph

3.6  Graph of inequations with 2 variables : plotinequation inequationplot

plotinequation([f1(x,y)<a1,,y)<ak],[x=x1..x2,y=y1..y2]) draws the points of the plane whose coordinates satisfy the inequations of 2 variables :

,    x1≤ x ≤ x2, y1 ≤ y ≤ y

Input :

plotinequation(x^2-y^2<3, [x=-2..2,y=-2..2],xstep=0.1,ystep=0.1)

Output :

the filled portion enclosing the origin and limited by the hyperbola x^2-y^2=3

Input :

plotinequation([x+y>3,x^2<y], [x-2..2,y=-1..10],xstep=0.2,ystep=0.2)

Output :

the filled portion of the plane defined by -2<x<2,y<10,x+y>3,y>x^2

Note that if the ranges for x and y are not specified, Xcas takes the default values of X-,X+,Y-,Y+ defined in the general graphic configuration (CfgGraphic configuration).

3.7  Graph of the area below a curve : plotarea areaplot

3.8  Contour lines: plotcontour contourplot

plotcontour(f(x,y),[x,y]) (or DrwCtour(f(x,y),[x,y]) or
contourplot(f(x,y),[x,y])) draws the contour lines of the surface defined by z=f(x,y) for z=−10, z=−8, .., z=0, z=2, .., z=10. You may specify the desired contour lines by a list of values of z given as third argument.
Input :

plotcontour(x^2+y^2,[x=-3..3,y=-3..3],[1,2,3], display=[green,red,black]+[filled$3])

Output :

the graph of the three ellipses x^2-y^2=n for n=1,2,3; the zones between these ellipses are filled with the color green,red or black

Input :


Output :

the graph of 11 hyperbolas x^2-y^2=n for n=-10,-8,..10

If you want to draw the surface in 3-d representation, input plotfunc(f(x,y),[x,y]), see 3.2.2):

plotfunc( x^2-y^2,[x,y])

Output :

A 3D representation of z=x^2+y^2

3.9  2-d graph of a 2-d function with colors : plotdensity densityplot

plotdensity(f(x,y),[x,y]) or densityplot(f(x,y),[x,y]) draws the graph of z=f(x,y) in the plane where the values of z are represented by the rainbow colors. The optional argument z=zmin..zmax specifies the range of z corresponding to the full rainbow, if it is not specified, it is deduced from the minimum and maximum value of f on the discretisation. The discretisation may be specified by optional xstep=... and ystep=... or nstep=... arguments.
Input :

plotdensity(x^2-y^2,[x=-2..2,y=-2..2], xstep=0.1,ystep=0.1)

Output :

A 2D graph where each hyperbola defined by x^2-y^2=z has a color from the rainbow

Remark : A rectangle representing the scale of colors is displayed below the graph.

3.10  Implicit graph: plotimplicit implicitplot

plotimplicit or implicitplot draws curves or surfaces defined by an implicit expression or equation. If the option unfactored is given as last argument, the original expression is taken unmodified. Otherwise, the expression is normalized, then replaced by the factorization of the numerator of it’s normalization.

Each factor of the expression corresponds to a component of the implicit curve or surface. For each factor, Xcas tests if it is of total degree less or equal to 2, in that case conic or quadric is called. Otherwise the numeric implicit solver is called.

Optional step and ranges arguments may be passed to the numeric implicit solver, note that they are dismissed for each component that is a conic or a quadric.

3.11  Parametric curves and surfaces : plotparam paramplot DrawParm

3.12  Curve defined in polar coordinates : plotpolar polarplot DrawPol courbe_polaire

Let Et be an expression depending of the variable t.
plotpolar(Et,t) draws the polar representation of the curve defined by ρ=Et for θ=t, that is in cartesian coordinates the curve (Et cos(t),Et sin(t)). The range of the parameter may be specified by replacing the second argument by t=tmin..tmax. The discretisation parameter may be specified by an optional tstep=... argument.


Output :

The spiral ρ=t is plotted



or :


Output :

A polygon line approaching the spiral ρ=t is plotted

3.13  Graph of a recurrent sequence : plotseq seqplot graphe_suite

Let f(x) be an expression depending of the variable x (resp. f(t) an expression depending of the variable t).
plotseq(f(x),a,n) (resp. plotseq(f(t),t=a,n)) draws the line y=x, the graph of y=f(x) (resp y=f(t)) and the n first terms of the recurrent sequence defined by : u0=a, un=f(un−1). The a value may be replaced by a list of 3 elements, [a,x,x+] where x..x+ will be passed as x range for the graph computation.
Input :


Output :

the graph of y=sqrt(1+x), of y=x and of the 5 first terms of the sequence u_0=3 and u_n=sqrt(1+u_(n-1))

3.14  Tangent field : plotfield fieldplot

Input :


Output :

Segments with slope 4*sin(t*y), representing tangents, are plotting in different points

With two variables x,y, input :


3.15  Plotting a solution of a differential equation : plotode odeplot

Let f(t,y) be an expression depending of two variables t and y.

Input :


Output :

The graph of the solution of y’=sin(t,y) crossing through the point (0,1)

Input :

S:=odeplot([h-0.3*h*p, 0.3*h*p-p], [t,h,p],[0,0.3,0.7])

Output, the graph in the space of the solution of :

[h,p]′=[h−0.3 h*p, 0.3 h*pp]    [h,p](0)=[0.3,0.7] 

To have a 2-d graph (in the plane), use the option plane

S:=odeplot([h-0.3*h*p, 0.3*h*p-p], [t,h,p],[0,0.3,0.7],plane)

To compute the values of the solution, see the section ??.

3.16  Interactive plotting of solutions of a differential equation : interactive_plotode interactive_odeplot

Let f(t,y) be an expression depending of two varaiables t and y.
interactive_plotode(f(t,y),[t,y]) draws the tangent field of the differential equation y′=f(t,y) in a new window. In this window, one can click on a point to get the plot of the solution of y′=f(t,y) crossing through this point.
You can further click to display several solutions. To stop press the Esc key.
Input :


Output :

The tangent field is plotted with the solutions of y’=sin(t,y) crossing through the points defined by mouse clicks

3.17  Animated graphs (2D, 3D or "4D")

Xcas can display animated 2D, 3D or "4D" graphs. This is done first by computing a sequence of graphic objects, then after completion, by displaying the sequence in a loop.

Chapter 4  Numerical computations

Real numbers may have an exact representation (e.g. rationals, symbolic expressions involving square roots or constants like π, ...) or approximate representation, which means that the real is represented by a rational (with a denominator that is a power of the basis of the representation) close to the real. Inside Xcas, the standard scientific notation is used for approximate representation, that is a mantissa (with a point as decimal separator) optionnally followed by the letter e and an integer exponent.

Note that the real number 10−4 is an exact number but 1e−4 is an approximate representation of this number.

4.1  Floating point representation.

In this section, we explain how real numbers are represented.

4.2  Approx. evaluation : evalf approx and Digits

evalf or approx evaluates to a numeric approximation (if possible).
Input :


Output, if in the cas configuration (Cfg menu) Digits=7 (that is hardware floats are used, and 7 digits are displayed) :


You can change the number of digits in a commandline by assigning the variable DIGITS or Digits. Input :


Output :


Input :


Output :


Input :


Output :


Input :


Output :


4.3  Numerical algorithms

4.4  Solve equations with fsolve nSolve

fsolve or nSolve solves numeric equations (unlike solve or proot, it is not limited to polynomial equations) of the form:

f(x)=0,    x ∈ ]a,b

fsolve or de nSolve accepts a last optional argument, the name of an iterative algorithm to be used by the GSL solver. The different methods are explained in the following section.

4.5  Solve systems with fsolve

Xcas provides six methods (inherited from the GSL) to solve numeric systems of equations of the form f(x)=0:

All methods use an iteration of Newton kind


The four methods hybrid*_solver use also a method of gradient descent when the Newton iteration would make a too large step. The length of the step is computed without scaling for hybrid_solver and hybridj_solver or with scaling (computed from f′(xn)) for hybrids_solver and hybridsj_solver.

4.6  Numeric roots of a polynomial : proot

proot takes as argument a squarefree polynomial, either in symbolic form or as a list of polynomial coefficients (written by decreasing order).
proot returns a list of the numeric roots of this polynomial.
To find the numeric roots of P(x)=x3+1, input :


or :


Output :


To find the numeric roots of x2−3, input :


or :


Output :


4.7  Numeric factorization of a matrix : cholesky qr lu svd

Matrix numeric factorizations of

are described in section 2.48.

Chapter 5  Unit objects and physical constants

The Phys menu contains:

5.1  Unit objects

5.2  Constants

This document was translated from LATEX by HEVEA.