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

Index

Chapter 1  Introduction

1.1  Notations used in this manual

In this manual, the information that you enter is typeset in typewriter font. User input typically takes one of three forms:

When describing entering a command, 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 angle brackets. For example, you can find the derivative of an expression with the diff command (see Section 5.19.4), which takes the form diff(expr ⟨,x]) where expr is an expression and x is a variable or list of variables. If the optional variable is omitted, then it will default to x. A specific example is diff(x*sin(x),x).

The index uses different typefaces for different parts of the language. The commands themselves are written with normal characters, command options are written in italics and values of commands or options are written in typewriter font. For example (as you will see later), you can draw a blue parabola with the command

plotfunc(x^2,color = blue)

In the index, you will see

1.2  Interfaces for the giac library

The giac library is a C++ mathematics library. It comes with two interfaces you can 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:
Input:

sqrt(1/2)

Output:

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:
Input:

sqrt(1/2)

Output:

sqrt(2)/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  The Xcas interface

2.1  The 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:

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  The starting window

When you first start Xcas, you get a largely blank window.

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  The 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) 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 translate a session, or parts of a session, to other computer languages; notably LATEX and MathML.

Chapter 3  Entry in Xcas

3.1  Suppressing output: nodisp :;

If you enter a command into Xcas, the result will appear in the output box below the input. If you enter

a:= 2+2

then

4

will appear in the output box.

The nodisp command is used to evaluate an expression and suppress the output.

3.2  Entering comments: comment

You can annotate an Xcas session by adding comments. You can enter a comment on the current line at any time by typing Alt+C. The line will appear in green text and conclude when you type Enter. Comments are not evaluated and so have no output. If you have started entering a command when you begin a comment, the command line with the start of the command will be pushed down so that you can finish it when you complete the comment.

You can open the browser using a comment line by entering the web address beginning with the @ sign. If you enter the comment line

The Xcas homepage is at
@www-fourier.ujf-grenoble.fr/~parisse/giac.html

then the browser will open to the Xcas home page.

To add a comment to a program, rather than a session, you can use the comment command.

Alternatively, any part of a program between // and the end of the line is a comment. So both

bs():= {comment("Hello"); return "Hi there!";}

and

bs():= { // Hello
return "Hi there!";}

are programs with the comment "Hello".

3.3  Editing expressions

You can enter expressions on the command line, but Xcas also has a built-in expression editor that you can 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.

3.4  Previous results: ans

The ans command returns the results of previous commands.

3.5  Spreadsheet

Chapter 4  CAS building blocks

4.1  Numbers

Xcas works with both real and complex numbers. The real numbers can be integers, rational numbers, floating point numbers or symbolic constants.

You can enter an integer by simply typing the digits.
Input:

1234321

Output:

1234321

Alternatively, you can enter an integer in binary (base 2) by prefixing the digits (0 through 1) with 0b, in octal (base 8) by prefixing the digits (0 through 7) with 0 or 0o, and in hexadecimal (base 16) by prefixing the digits (0 through 9 and a through f) with 0x. (See Section 5.4.1.)
Input:

0xab12

Output:

43794

You can enter a rational number as the ratio of two integers.
Input:

123/45

Output:

41
15

The result will be put in lowest terms. If the top is a multiple of the bottom, the result will be an integer.
Input:

123/3

Output:

41

A floating point number is regarded as an approximation to a real number. You can enter a floating point number by writing it out with a decimal point.
Input:

123.45

Output:

123.45

You can also enter a floating point number by entering a sequence of digits, with an optional decimal point, followed by e and then an integer, where the e represents “times 10 to the following power.”
Input:

1234e3

Output:

1234000.0

Floating point numbers with a large number of digits will be printed with e notation; you can control how other floats are displayed (see Section 2.5.7, item 7). An integer or rational number can be converted to a floating point number with evalf (see Section 5.8.1).

A complex number is a number of the form a+bi, where a and b are real numbers. The numbers a and b will be the same type of real number; one type will be converted to the other type if necessary (an integer can be converted to a rational number or a floating point number, and a rational number can be converted to a floating point number).
Input:

3 + 1.1i

Output:

3+1.1i

4.2  Symbolic constants: e pi infinity inf i euler_gamma

Xcas has the standard constants given by built-in symbols, given in the following table.

SymbolValue
e (or %e)the number exp(1)
pi (or %pi)the number π
infinityunsigned ∞
+infinity (or inf)+∞
-infinity (or -inf)−∞
i (or %i)the complex number i
euler_gammaEuler’s constant γ; namely, limn→∞(∑k=1n − ln(n))

Since these numbers cannot be written exactly as standard decimal numbers, they are necessarily left unevaluated in exact results (see Section 2.5.4).
Input:

2*pi

Output:

Input:

2.0*pi

Output:

6.28318530718

You can also use evalf (see Section 5.8.1), for example, to approximate one of the real-valued constants to as many decimal places as you want.
Input:

evalf(pi,50)

Output:

3.1415926535897932384626433832795028841971693993751

4.3  Sequences, sets and lists

4.4  Variables

4.5  Functions

4.6  Directories

Chapter 5  The CAS functions

5.1  Booleans

5.2  Bitwise operators

5.3  Strings

5.4  Writing an integer in a different base

5.5  Integers (and Gaussian Integers)

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

factorial(100)

Output:

9332621544394415268169923885626670049071596826438162
1468592963895217599993229915608941463976156518286253
697920827223758251185210916864000000000000000000000000


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

5.6  Combinatorial analysis

5.7  Rational numbers

5.8  Real numbers

5.9  Permutations

A permutation p of size n is a bijection from [0..n−1] to [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 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 (i=0..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]).

5.10  Complex numbers

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

5.11  Algebraic numbers

5.12  Algebraic expressions

5.13  Values of a sequence un

5.14  Operators or infixed functions

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

5.15  Functions and expressions with symbolic variables

5.16  Functions

5.17  Getting information about functions from ℝ to ℝ

5.18  Limits: limit

The limit command computes limits, both at numbers and infinities, and in the real case it can compute one-sided limits.

Remark:
It is also possible to put x=a as argument instead of x,a; limit(expr,var=pt[,side]) is equivalent to limit(expr,var,pt[,side]).

5.19  Derivation and applications

5.20  Integration

5.21  Multivariate calculus

5.22  Calculus of variations

5.23  Trigonometry

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

5.24  Exponentials and Logarithms

5.25  Rewriting transcendental and trigonometric expressions

5.26  Fourier transformation

5.27  Polynomials

5.28  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.

5.29  Exact bounds for roots of a polynomial

5.30  Orthogonal polynomials

5.31  Gröbner basis and Gröbner reduction

5.32  Rational functions

5.33  Exact roots and poles

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

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