Symbolic Algebra and Mathematics with Xcas

Renée De Graeve, Bernard Parisse1,
Jay Belanger2
Sections written by Luka Marohnić3

© 2002, 2007 Renée De Graeve, Bernard Parisse
renee.degraeve@wanadoo.fr
bernard.parisse@ujf-grenoble.fr

Contents

Chapter 1  Introduction

1.1  Notations used in this manual

User input in Xcas typically takes one of the following three forms:

Commands that you enter on the command line.
For example, to compute sinπ/4, you can type
sin(pi/4)
The output will be typeset in blue and the messages in green.
Keyboard shortcuts.
These are indicated by separating the prefix key and the standard key with a plus +. For example, to exit an Xcas session, you can type the control key along with the q key, which will be denoted by Ctrl+Q.
Menu commands.
When denoting menu items (which are typeset in sans serif font), the submenus are connected by  ▸ . For example, from within Xcas you can choose the File menu, then choose the Open submenu, and then choose the File item. This will be indicated by File ▸ Open ▸ File.

When describing command syntax, specific values that you enter for arguments are in typewriter font, while argument placeholders that should be replaced by actual values are in italics. Optional arguments will be enclosed by angular brackets. For example, you can find the derivative of an expression with the diff command (see Section 13.2.1), which takes the form diff(expr ⟨,x ⟩) where expr is an expression and x is (optionally) a variable or a list of variables.

In Xcas there exist many synonymous commands (i.e. having different names but the same effect). When a group of synonyms is described, the syntax details are provided only for the first command name and it is implied that the instructions apply to the synonyms as well.

In the index, the entries which are part of Xcas language are written in typewriter font (command names in black and programming keywords in blue) or italics (option names and specific values like color names).

1.2  Interfaces for the giac library

The giac library is a C++ mathematics library. It comes with two interfaces use directly; a graphical interface and a command-line interface. All interfaces can do symbolic and numeric calculations, use giac’s programming language, and have a built in help function.

The graphical interface is called Xcas, and is the most full-featured interface. Xcas has additional help features to make it easy to use, plus it has a built-in spreadsheet, it can do dynamic geometry and it can do turtle graphics. The output given by this interface is typeset; for example:

sqrt(2)
     
2
          

The command-line interface can be run inside a terminal, and in a graphical environment can also draw graphs. The output given by this interface is in text form; for example:

sqrt(2)
sqrt(2)

There is also a web version, which can be run through a javascript-enabled browser (it works best with Firefox), either over the Internet or from local files. Other programs (for example, TeXmacs) have interfaces for the command-line version. Some of these interfaces, such as the two mentioned here, typeset their output.

Chapter 2  Xcas interface

2.1  Entry levels

The Xcas interface can run several independent calculation sessions, each session will be contained in a separate tab. Before you understand the Xcas interface, it would help to be familiar with the components of a session.

Each session can have any number of input levels. Each input level will have a number to the left of it; the number is used to identify the level. Each level can have one of the following:

Command line entry
— This is the default; you can open a new command line with Alt+N.

You can enter a giac command (or a series of commands separated by semicolons) on a command line and send it to be evaluated by hitting enter. The result will then be displayed, and another command line will appear. You can also scroll through the command history with Ctrl+Up and Ctrl+Down.

If the output is a number or an expression, then it will appear in blue text in a small area below the input region; this area will be an expression editor (see Section 2.9). There will be a scrollbar and a small button M to the right of this area, which is a menu providing various options.

If the output is a graphic, then it will appear in a graphing area below the input region. To the right of the graphic will be a control panel which use to manipulate the graphic (see Section 19.1.1).

Expression editor
— See Section 2.9. You can open an expression editor with Alt+E.
2D geometry screen
— See Section 19.1.1. You can open a 2D geometry screen with Alt+G. This level will have a screen, as well as a control panel, menus and a command line to control the screen.
3D geometry screen
— See Section 19.1.1. You can open a 3D geometry screen with Alt+H. This level will have a screen, as well as a control panel, menus and a command line to control the screen.
Turtle graphics screen
— You can open a turtle graphics screen with Alt+D. This level will have a screen, as well as a program editor and command line.
Spreadsheet
— See Section 2.10. You can open a spreadsheet with Alt+T. A spreadsheet can open a graphic screen.
Program editor
— See Section 25.1.1. You can open a program editor with Alt+P.
Comment line
— See Section 2.8.2. You can open a comment line with Alt+C.

Levels can be moved up and down in a session, or even moved to a different session.

The level containing the cursor is the current level. The current level can be evaluated or re-evaluated by typing enter.

You can select a level (for later operations) by clicking on the number in the white box to the left of the level. Once selected, the box containing the number turns black. You can select a range of levels by clicking on the number for the beginning level, and then holding the shift key while you click on the number for the ending level.

You can copy the instructions in a range of levels by selecting the range, and then clicking the middle mouse button on the number of the target level.

2.2  Starting window


Figure 2.1: The initial Xcas window

When you first start Xcas, you get a largely blank window, as shown in Figure 2.1. The first row will consist of the main menus; you can save and load Xcas sessions, configure Xcas and its interface and run various commands with entries from these menus.

The second row will contains tabs; one tab for each session that you are running in Xcas. Each tab will have the name of its session, or Unnamed if the session has no name. The first time you start Xcas, there will be only one session, which will be unnamed.

The third row will contain various buttons.

2.3  Getting help

Xcas is an extensive program, but using it is simplified with several different ways of getting help. The help menu (see section 2.4.4) has several submenus for various forms of help, some of which are mentioned below.

2.4  Menus

The menus provide different ways to work with Xcas and its sessions, as well as ways of inserting functions and constants into the current session. Selecting a menu item corresponding to a function or constant brings up the help index (see section 2.3.3) with the chosen function or constant selected.

2.5  Configuring Xcas

2.6  Printing and saving

2.7  Translating to other computer languages

Xcas can export a session, or parts of a session, to typesetting languages such as LATEX and MathML.

2.8  Entry in Xcas

If you enter a command into Xcas and press Enter, the result will appear in the output box below the input, colored in blue. Any messages generated during the computation will be shown in the box between the input and output, colored in green (the box is otherwise hidden). For example:

integrate(a/(x+a)^2,x=0..inf)

No checks were made for singular points of antiderivative -1/(x+a) for definite integration in [0,+infinity]

     
1           

Note that line breaks in a command entry can be entered by pressing Shift+Enter.

2.9  Editing expressions

You can enter expressions on the command line, but Xcas also has a built-in expression editor that use to enter expressions in two dimensions, the way they normally look when typeset. When you have an expression in the editor, you can also manipulate subexpressions apart from the entire expression.

2.10  Spreadsheets

Chapter 3  CAS building blocks

3.1  Constants

3.2  Sequences, sets and lists

3.3  Variables

3.4  Functions

Chapter 4  Files and directories

4.1  Files

4.2  Directories

Chapter 5  Booleans and strings

5.1  Booleans

5.2  Strings

5.3  Bitwise operators

5.4  Writing an integer in a different base

Chapter 6  Sequences, lists, and sets

6.1  Sequences and lists

6.2  Values of a sequence un

6.3  Operations on lists

6.4  Operations on sets and lists

6.5  Ranges of values

6.6  Intervals

Chapter 7  Numbers

7.1  Integers (and Gaussian Integers)

Xcas can manage integers with unlimited precision, such as the following (see Section 12.1.1):

factorial(100)
     
 9332621544394415268169923885626670049071596826438162         
 1468592963895217599993229915608941463976156518286253         
 697920827223758251185210916864000000000000000000000000          

Gaussian integers are numbers of the form a+ib, where a and b are in ℤ. For most functions in this section, use Gaussian integers in place of integers.

7.2  Rational numbers

7.3  Real numbers

7.4  Complex numbers

Note that complex numbers are also used to represent points in the plane (see Section 26.5.2). Some functions and operators which work on complex numbers also work on points.

7.5  Algebraic numbers

Chapter 8  Operators and functions

8.1  Operators or infixed functions

An operator is an infixed function. For example, the arithmetic functions +, -, *, /, and ^ are operators. (See Section 7.3.2 and Section 7.4.1.)

8.2  Functions and expressions with symbolic variables

8.3  Functions

8.4  Getting information about univariate real functions

Chapter 9  Algebraic expressions

9.1  Evaluation and substitution

9.2  Periodic functions

9.3  Equations

9.4  Utility functions

Chapter 10  Rewriting algebraic expressions

10.1  General rewriting and simplification routines

10.2  Trigonometry

Xcas can evaluate the trigonometric functions in either radians or degrees (see Section 8.3.2). It can also manipulate them algebraically.

10.3  Exponentials and logarithms

10.4  Rewriting transcendental expressions

Chapter 11  Polynomials

11.1  Basic functions for polynomials

11.2  Arithmetic and polynomials

Polynomials are represented by expressions or by lists of coefficients in 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 coefficients in ℤ/nℤ, use % n for each coefficient of the list or apply it to the entire expression defining the polynomial.

11.3  Exact bounds for roots of a polynomial

11.4  Orthogonal polynomials

11.5  Gröbner basis and Gröbner reduction

11.6  Rational functions

11.7  Exact roots and poles

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

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

11.9  Computing in ℤ/pℤ[x] using Maple syntax

You can set Xcas to work in Maple mode rather than native Xcas mode (see Section 2.5.2).

Chapter 12  Combinatorics

12.1  Combinatorial analysis

12.2  Permutations

A permutation p of size n is a bijection from {0,…,n−1} to itself 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 function from [0,1,2,3] to [0,1,2,3] defined by p(0)=1, p(1)=3, p(2)=2, p(3)=0.

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

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

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]).

Chapter 13  Calculus

13.1  Limits

13.2  Derivative

13.3  Integration

13.4  Differential equations

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

13.5  Taylor series and asymptotic expansions

13.6  Z-transform

13.7  Multivariate calculus

13.8  Calculus of variations

Chapter 14  Vectors, matrices, and tables

14.1  Functions for vectors

14.2  Matrices

14.3  Functions for matrices

14.4  Sparse matrices

14.5  Statistics on lists and matrices

Chapter 15  Linear algebra

15.1  Basic matrix operations

15.2  Matrix reduction

15.3  Matrix factorizations

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

15.4  Matrix norms

See Section 14.1.1 for different norms on vectors.

15.5  Isometries

An isometry of ℝn is a distance-preserving map. In ℝ2, the isometries are made up of:

In ℝ3, the isometries are made up of:

An isometry is direct if it preserves orientation (it does not involve a reflection), otherwise it is indirect.

An n× n matrix A determines an isometry of the function f:ℝn→ℝn by f(x)=Ax) is an isometry. Such isometries fix the origin, so they cannot involve translation, can only rotate about the origin, and the line or plane of reflection will pass through the origin.

An isometry in ℝ2 can be characterized by:

An isometry in ℝ3 can be characterized by:

15.6  Quadratic forms

15.7  Linear systems

The augmented matrix of the system A X=b is either the matrix obtained by gluing the column vector b to the right of the matrix A (as with border(A,tran(b))), representing A X=b, or the matrix obtained by gluing the column vector −b to the right of the matrix A, representing A xb=0.

Chapter 16  Optimization

16.1  Linear Programming

Linear programming problems involve maximizing a linear functionals under linear equality or inequality constraints. The simplest case can be solved directly by the so-called simplex algorithm. Most cases require you to solve an auxiliary linear programming problem to find an initial vertex for the simplex algorithm.

16.2  Analytical methods for nonlinear optimization

16.3  Numerical methods for nonlinear optimization

Chapter 17  Interpolation and fitting

17.1  Interpolation

17.2  Curve fitting

Chapter 18  Metric properties of curves

18.1  The center of curvature

Let Γ be a curve in space parameterized by a continuously differentiable function, and M0 be a point on the curve. The curve will have an arclength parameterization; namely, it can be parameterized by a function M(s), where M(0)=M0 and |s| is the length of the curve from M0 to M(s), in the direction of the curve if s>0 and the opposite direction if s<0.

For such a Γ, the vector T(s)=M′(s) will be the unit tangent to the curve at M(s), and N(s)=T′(s) will be perpendicular to the tangent. The circle through M(s) with center at M(s)+N(s) is called the osculating circle to Γ at M(s). Informally, the osculating circle is the circle through M(s) which most closely approximates Γ. The set of all centers of curvature is another curve, called the evolute of Γ.

The radius of the osculating circle is |N(s)| and is called the radius of curvature of Γ at M(s). The reciprocal of this is called the curvature of Γ at M(s).

18.2  Computing the curvature and related values

A curve can be described in Xcas with a parametrization or with a curve object. Various curve objects are described in chapters 26 and 27. The commands in this section can work with curves described either way. You can get the equation of a curve object with the equation command (see Section 26.12.7).

Chapter 19  Graphs

19.1  Generalities

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.

19.2  Graph of a function

19.3  Graph of a line and tangent to a graph

19.4  Area graphs

19.5  Contour and density graphs for surfaces

19.6  Implicit graphs

The plotimplicit or implicitplot command draws curves or surfaces defined by an implicit expression or equation. If the option unfactored is given as the last argument, the original expression is taken unmodified. Otherwise, the expression is normalized, then replaced by the factorization of the numerator of its 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 which 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.

19.7  Parametric curves and surfaces

The plotparam or paramplot or DrawParm command draws parametric curves and surfaces.

19.8  Plotting curves and sequences

19.9  Plotting fields

19.10  Animated graphs

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. To stop or start the animation, click on the button (to the left of Menu).

Chapter 20  Statistics

20.1  One variable statistics

Xcas has several functions to perform statistics. Data is typically given as a list of numbers, such as A:=[0,1,2,3,4,5,6,7,8,9,10,11]. This particular list will be used in several examples. Statistics on matrices are discussed in Section 14.5.2.

20.2  Two variable statistics

20.3  Random numbers

20.4  Density and distribution functions

20.5  Hypothesis testing

Chapter 21  Signal Processing

21.1  Basic functions

21.2  Common operations on signals

21.3  Filters

21.4  Transforms

21.5  Window functions

Chapter 22  Data analysis and machine learning

22.1  Clustering

Clustering is a form of unsupervised machine learning. Xcas can perform hierarchical clustering and k-means clustering.

22.2  Artificial neural networks

This section explains how to create and train feed-forward neural networks in Xcas.

A feed-forward network, more precisely a multilayer perceptron, is comprised of a sequence of at least three neuron layers. The first layer is called the input layer and the last layer is called the output layer. Layers are essentially vectors of numerical data. Each component of such vector corresponds to an activated neuron. The network processes the given input by applying the formula lk+1=fk(WkTlk), where lk is the kth layer of length nk, lk+1 is the (k+1)-th layer of length nk+1, Wk is a nk× nk+1 weight matrix and fk is the activation function at the k+1-th layer (which is applied element-wise). Here k=1,2,…,L−1, where L is the number of layers. Each layer except the final one contains a bias neuron with linear activation. Bias neurons are auxiliary neurons created during construction of the network.

Multilayer perceptrons are trained by using backpropagation to compute the approximate gradient (with respect to the weight parameters in the matrices Wk) of the error function which compares the output to the expected output (or ground truth). Precisely, after training data is fed to the network, the obtained output is compared to the expected output and finally the error is backpropagated to find the weight adjustment enabling the network to predict the expected output more accurately.

The examples in Section 22.2.2 demonstrate how to prepare training data, construct neural networks, train them and test their accuracy.

Remark.

The commands in this section require that giac is linked to GSL.

Chapter 23  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 internally 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) optionally followed by the letter e and an integer exponent.

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

23.1  Floating point representation

This section discusses how real numbers are represented.

23.2  Computing derivatives and integrals

23.3  Solving equations

23.4  Solving differential equations

23.5  Numerical factorization of a matrix

Numeric Cholesky, QR, LU, and SVD factorizations of a matrix can be carried out, as described in Section 15.3.

Chapter 24  Unit objects and physical constants

24.1  Unit objects

24.2  Constants

Chapter 25  Programming

Xcas has a programming language that allows you to write complex programs in several different syntax flavours. This section explains the details of the language, how to enter programs in Xcas (most notably new functions) and how to debug them. In the end, it is briefly explained how to extend and use giac from C++.

25.1  Functions, programs and scripts

25.2  Basic instructions

25.3  Control structures

25.4  Errors

25.5  Other useful instructions

25.6  Debugging

25.7  Linking to and extending the giac library

Chapter 26  2D graphics

26.1  Introduction

26.2  Basic commands

26.3  Display features of graphics

26.4  Geometric demonstrations with sliding parameters

Variables should be unspecified to demonstrate a general geometric result, but need to have specific values when drawing. There are a couple of different approaches to deal with this.

One approach is to use the assume command (see Section 3.3.8). If a variable is assumed to have a value, then that value will be used in graphics but the variable will still be unspecified for calculations. For example:

assume(a=2.1):; A:=point(a+i)

but the variable a will still be treated as a variable in calculations:

distance(0,A)
     

a
2+1
          

Another approach would be to use the point or pointer mode in a geometry screen. If no geometry screen is shown, the command Alt+G or the Geo ▸ New figure 2d menu will open a screen. Clicking on the Mode button right above the graphic screen and choosing pointer or point will put the screen in pointer or point mode. If a point is defined and displayed, such as with A:=point(2.1+i), then clicking on the name of the point (A in this case) with the right mouse button will bring up a configuration screen. As long as there is a point defined with non-symbolic values, there will be a symb box on the configuration screen. Selecting the symb box and choosing OK will be equivalent to the commands:

assume(Ax=[2.1,-8.16901408451,8.16901408451]); assume(Ay=[1,-5.0,5.0]

This brings up two lines beneath the arrows to the right of the screen which can be used to change the assumed values of Ax and Ay. Also, the point A will be redefined as point(Ax,Ay) (see Figure 26.1).


Figure 26.1: A 2D-geometry screen in Xcas

26.5  Points in the plane

26.6  Lines in plane geometry

26.7  Triangles in the plane

See Section 27.6 for triangles in space.

26.8  Quadrilaterals in the plane

See Section 27.7 for quadrilaterals in space.

26.9  Other polygons in the plane

See Section 27.8 for polygons in space.

26.10  Circles

26.11  Other conic sections

26.12  Coordinates in the plane

26.13  Measurements

26.14  Transformations

26.15  Properties

26.16  Harmonic division

26.17  Loci and envelopes

Chapter 27  3D graphics

27.1  Introduction

27.2  The axes

27.3  Points in space

27.4  Lines in space

27.5  Planes in space

See also sections 27.4.6 and 27.4.7 for planes perpendicular and orthogonal to lines and planes.

27.6  Triangles in space

27.7  Quadrilaterals in space

See Section 26.8 for quadrilaterals in the plane.

27.8  Polygons in space

See Section 26.9 for polygons in the plane.

27.9  Circles and conics in space

27.10  3D coordinates

27.11  Properties

27.12  Transformations in space

27.13  Surfaces

27.14  Solids

27.15  Platonic solids

To specify a Platonic solid, Xcas works with the center, a vertex and a third point to specify a plane of symmetry. To speed up calculations, it may be useful to use approximate calculations, which can be ensured with the evalf command. For example, instead of:

centered_cube([0,0,0],[3,2,1],[1,1,0])

it would typically be better to use:

centered_cube(evalf([0,0,0],[3,2,1],[1,1,0]))

since it is faster.

Chapter 28  Multimedia

28.1  Images

28.2  Audio

Xcas has support for audio objects in wav (Waveform Audio File) format. The following commands are provided for working with audio objects.

Index


1
Université de Grenoble, initial translation of parts of the French user manual
2
Full translation and improvements
3
Optimization, signal processing. The graph theory is in a separate manual.

This document was translated from LATEX by HEVEA.