0% found this document useful (0 votes)
268 views1,048 pages

Maxima 5.30.0 Manual Overview

A full description, full of examples for the usage of the Open Source Software WxMaxima . Really useful both for new and advanced user

Uploaded by

Antonio Gadaleta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
268 views1,048 pages

Maxima 5.30.0 Manual Overview

A full description, full of examples for the usage of the Open Source Software WxMaxima . Really useful both for new and advanced user

Uploaded by

Antonio Gadaleta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1048

Maxima Manual

Ver. 5.30.0
Maxima is a computer algebra system, implemented in Lisp.
Maxima is derived from the Macsyma system, developed at MIT in the years 1968 through
1982 as part of Project MAC. MIT turned over a copy of the Macsyma source code to the
Department of Energy in 1982; that version is now known as DOE Macsyma. A copy of DOE
Macsyma was maintained by Professor William F. Schelter of the University of Texas from
1982 until his death in 2001. In 1998, Schelter obtained permission from the Department
of Energy to release the DOE Macsyma source code under the GNU Public License, and
in 2000 he initiated the Maxima project at SourceForge to maintain and develop DOE
Macsyma, now called Maxima.
i
Short Contents
1 Introduction to Maxima. . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Bug Detection and Reporting . . . . . . . . . . . . . . . . . . . . . . . 7
3 Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4 Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5 Data Types and Structures . . . . . . . . . . . . . . . . . . . . . . . . 35
6 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
7 Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
8 Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
9 Simplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
10 Mathematical Functions . . . . . . . . . . . . . . . . . . . . . . . . . 139
11 Maximas Database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
12 Plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
13 File Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . 211
14 Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
15 Special Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
16 Elliptic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
17 Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
18 Dierentiation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
19 Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
20 Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
21 Dierential Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
22 Numerical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
23 Matrices and Linear Algebra . . . . . . . . . . . . . . . . . . . . . . 357
24 Ane. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
25 itensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
26 ctensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
27 atensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
28 Sums, Products, and Series . . . . . . . . . . . . . . . . . . . . . . . 449
29 Number Theory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469
30 Symmetries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
31 Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501
32 Runtime Environment . . . . . . . . . . . . . . . . . . . . . . . . . . 503
33 Miscellaneous Options . . . . . . . . . . . . . . . . . . . . . . . . . . 507
34 Rules and Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511
35 Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527
ii Maxima 5.30.0 Manual
36 Function Denition . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
37 Program Flow. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581
38 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595
39 asympa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603
40 augmented lagrangian . . . . . . . . . . . . . . . . . . . . . . . . . . 605
41 Bernstein . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607
42 bode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609
43 cobyla . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611
44 contrib ode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615
45 descriptive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
46 diag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653
47 distrib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 661
48 draw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 699
49 drawdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763
50 dynamics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 767
51 ezunits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 777
52 f90. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 793
53 nance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 795
54 fractals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 801
55 ggf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 805
56 graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 807
57 grobner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 837
58 impdi. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 845
59 interpol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 847
60 lapack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 853
61 lbfgs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 861
62 lindstedt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 867
63 linearalgebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 869
64 lsquares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 883
65 minpack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 893
66 makeOrders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 895
67 mnewton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897
68 numericalio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 899
69 opsubst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 905
70 orthopoly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 907
71 romberg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 919
72 simplex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 923
73 simplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 925
iii
74 solve rec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 935
75 stats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 939
76 stirling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 957
77 stringproc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 959
78 to poly solve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 971
79 unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 991
80 zeilberger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1001
81 Indices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1005
A Function and Variable Index . . . . . . . . . . . . . . . . . . . . . 1007
iv Maxima 5.30.0 Manual
v
Table of Contents
1 Introduction to Maxima. . . . . . . . . . . . . . . . . . . . 1
2 Bug Detection and Reporting . . . . . . . . . . . . . . 7
2.1 Functions and Variables for Bug Detection and Reporting . . 7
3 Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.1 Documentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2 Functions and Variables for Help . . . . . . . . . . . . . . . . . . . . . . . . . 9
4 Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.1 Introduction to Command Line. . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.2 Functions and Variables for Command Line . . . . . . . . . . . . . . 13
4.3 Functions and Variables for Display. . . . . . . . . . . . . . . . . . . . . . 23
5 Data Types and Structures . . . . . . . . . . . . . . . . 35
5.1 Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5.1.1 Introduction to Numbers . . . . . . . . . . . . . . . . . . . . . . . 35
5.1.2 Functions and Variables for Numbers. . . . . . . . . . . . 35
5.2 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
5.2.1 Introduction to Strings . . . . . . . . . . . . . . . . . . . . . . . . . 41
5.2.2 Functions and Variables for Strings . . . . . . . . . . . . . 41
5.3 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
5.3.1 Functions and Variables for Constants. . . . . . . . . . . 44
5.4 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
5.4.1 Introduction to Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
5.4.2 Functions and Variables for Lists . . . . . . . . . . . . . . . 47
5.5 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
5.5.1 Functions and Variables for Arrays . . . . . . . . . . . . . . 58
5.6 Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.6.1 Introduction to Structures . . . . . . . . . . . . . . . . . . . . . . 67
5.6.2 Functions and Variables for Structures . . . . . . . . . . 67
6 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
6.1 Introduction to Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
6.2 Nouns and Verbs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
6.3 Identiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
6.4 Inequality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
6.5 Functions and Variables for Expressions . . . . . . . . . . . . . . . . . . 73
vi Maxima 5.30.0 Manual
7 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
7.1 Introduction to operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
7.2 Arithmetic operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
7.3 Relational operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
7.4 Logical operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
7.5 Operators for Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
7.6 Assignment operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
7.7 User dened operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
8 Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
8.1 Functions and Variables for Evaluation . . . . . . . . . . . . . . . . . 115
9 Simplication . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
9.1 Functions and Variables for Simplication. . . . . . . . . . . . . . . 127
10 Mathematical Functions. . . . . . . . . . . . . . . . . 139
10.1 Functions for Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
10.2 Functions for Complex Numbers . . . . . . . . . . . . . . . . . . . . . . 143
10.3 Combinatorial Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
10.4 Root, Exponential and Logarithmic Functions . . . . . . . . . . 148
10.5 Trigonometric Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
10.5.1 Introduction to Trigonometric . . . . . . . . . . . . . . . . 153
10.5.2 Functions and Variables for Trigonometric . . . . . 153
10.6 Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
11 Maximas Database . . . . . . . . . . . . . . . . . . . . . 163
11.1 Introduction to Maximas Database . . . . . . . . . . . . . . . . . . . . 163
11.2 Functions and Variables for Properties . . . . . . . . . . . . . . . . . 163
11.3 Functions and Variables for Facts . . . . . . . . . . . . . . . . . . . . . 173
11.4 Functions and Variables for Predicates . . . . . . . . . . . . . . . . . 179
12 Plotting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
12.1 Introduction to Plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
12.2 Plotting Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
12.3 Functions and Variables for Plotting . . . . . . . . . . . . . . . . . . . 186
12.4 Plotting Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
12.5 Gnuplot Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
12.6 Gnuplot pipes Format Functions . . . . . . . . . . . . . . . . . . . . . . 209
13 File Input and Output . . . . . . . . . . . . . . . . . . 211
13.1 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
13.2 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
13.3 Functions and Variables for File Input and Output . . . . . 212
13.4 Functions and Variables for TeX Output . . . . . . . . . . . . . . . 219
13.5 Functions and Variables for Fortran Output . . . . . . . . . . . . 224
vii
14 Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
14.1 Introduction to Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . 227
14.2 Functions and Variables for Polynomials . . . . . . . . . . . . . . . 227
15 Special Functions . . . . . . . . . . . . . . . . . . . . . . . 255
15.1 Introduction to Special Functions . . . . . . . . . . . . . . . . . . . . . 255
15.2 Bessel Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
15.3 Airy Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
15.4 Gamma and factorial Functions . . . . . . . . . . . . . . . . . . . . . . . 259
15.5 Exponential Integrals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
15.6 Error Function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
15.7 Struve Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
15.8 Hypergeometric Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
15.9 Parabolic Cylinder Functions. . . . . . . . . . . . . . . . . . . . . . . . . . 274
15.10 Functions and Variables for Special Functions . . . . . . . . . 274
16 Elliptic Functions . . . . . . . . . . . . . . . . . . . . . . . 279
16.1 Introduction to Elliptic Functions and Integrals . . . . . . . . 279
16.2 Functions and Variables for Elliptic Functions . . . . . . . . . . 280
16.3 Functions and Variables for Elliptic Integrals . . . . . . . . . . . 282
17 Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
17.1 Functions and Variables for Limits . . . . . . . . . . . . . . . . . . . . 285
18 Dierentiation. . . . . . . . . . . . . . . . . . . . . . . . . . 287
18.1 Functions and Variables for Dierentiation . . . . . . . . . . . . . 287
19 Integration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
19.1 Introduction to Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
19.2 Functions and Variables for Integration . . . . . . . . . . . . . . . . 299
19.3 Introduction to QUADPACK . . . . . . . . . . . . . . . . . . . . . . . . . 309
19.3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
19.4 Functions and Variables for QUADPACK. . . . . . . . . . . . . . 310
20 Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
20.1 Functions and Variables for Equations . . . . . . . . . . . . . . . . . 321
21 Dierential Equations. . . . . . . . . . . . . . . . . . . 339
21.1 Introduction to Dierential Equations . . . . . . . . . . . . . . . . . 339
21.2 Functions and Variables for Dierential Equations . . . . . . 339
viii Maxima 5.30.0 Manual
22 Numerical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
22.1 Introduction to fast Fourier transform . . . . . . . . . . . . . . . . . 343
22.2 Functions and Variables for fast Fourier transform. . . . . . 343
22.3 Functions for numerical solution of equations . . . . . . . . . . . 346
22.4 Introduction to numerical solution of dierential equations
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
22.5 Functions for numerical solution of dierential equations
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
23 Matrices and Linear Algebra . . . . . . . . . . . . 357
23.1 Introduction to Matrices and Linear Algebra . . . . . . . . . . . 357
23.1.1 Dot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
23.1.2 Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
23.1.3 eigen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
23.2 Functions and Variables for Matrices and Linear Algebra
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
24 Ane. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
24.1 Introduction to Ane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
24.2 Functions and Variables for Ane . . . . . . . . . . . . . . . . . . . . . 381
25 itensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
25.1 Introduction to itensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
25.1.1 New tensor notation . . . . . . . . . . . . . . . . . . . . . . . . . 386
25.1.2 Indicial tensor manipulation. . . . . . . . . . . . . . . . . . 386
25.2 Functions and Variables for itensor . . . . . . . . . . . . . . . . . . . . 389
25.2.1 Managing indexed objects . . . . . . . . . . . . . . . . . . . . 389
25.2.2 Tensor symmetries. . . . . . . . . . . . . . . . . . . . . . . . . . . 398
25.2.3 Indicial tensor calculus . . . . . . . . . . . . . . . . . . . . . . . 399
25.2.4 Tensors in curved spaces . . . . . . . . . . . . . . . . . . . . . 404
25.2.5 Moving frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
25.2.6 Torsion and nonmetricity. . . . . . . . . . . . . . . . . . . . . 410
25.2.7 Exterior algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
25.2.8 Exporting TeX expressions . . . . . . . . . . . . . . . . . . . 416
25.2.9 Interfacing with ctensor . . . . . . . . . . . . . . . . . . . . . . 416
25.2.10 Reserved words. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
ix
26 ctensor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
26.1 Introduction to ctensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
26.2 Functions and Variables for ctensor . . . . . . . . . . . . . . . . . . . . 421
26.2.1 Initialization and setup . . . . . . . . . . . . . . . . . . . . . . 421
26.2.2 The tensors of curved space . . . . . . . . . . . . . . . . . . 424
26.2.3 Taylor series expansion. . . . . . . . . . . . . . . . . . . . . . . 426
26.2.4 Frame elds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
26.2.5 Algebraic classication. . . . . . . . . . . . . . . . . . . . . . . 429
26.2.6 Torsion and nonmetricity. . . . . . . . . . . . . . . . . . . . . 432
26.2.7 Miscellaneous features . . . . . . . . . . . . . . . . . . . . . . . 433
26.2.8 Utility functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
26.2.9 Variables used by ctensor . . . . . . . . . . . . . . . . . . . 440
26.2.10 Reserved names . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
26.2.11 Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444
27 atensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
27.1 Introduction to atensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
27.2 Functions and Variables for atensor . . . . . . . . . . . . . . . . . . . . 446
28 Sums, Products, and Series . . . . . . . . . . . . . 449
28.1 Functions and Variables for Sums and Products . . . . . . . . 449
28.2 Introduction to Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
28.3 Functions and Variables for Series . . . . . . . . . . . . . . . . . . . . . 453
28.4 Introduction to Fourier series . . . . . . . . . . . . . . . . . . . . . . . . . 465
28.5 Functions and Variables for Fourier series . . . . . . . . . . . . . . 465
28.6 Functions and Variables for Poisson series . . . . . . . . . . . . . . 467
29 Number Theory . . . . . . . . . . . . . . . . . . . . . . . . 469
29.1 Functions and Variables for Number Theory. . . . . . . . . . . . 469
30 Symmetries . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
30.1 Introduction to Symmetries . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
30.2 Functions and Variables for Symmetries. . . . . . . . . . . . . . . . 483
30.2.1 Changing bases. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
30.2.2 Changing representations . . . . . . . . . . . . . . . . . . . . 487
30.2.3 Groups and orbits . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
30.2.4 Partitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
30.2.5 Polynomials and their roots . . . . . . . . . . . . . . . . . . 492
30.2.6 Resolvents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
30.2.7 Miscellaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
31 Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501
31.1 Functions and Variables for Groups. . . . . . . . . . . . . . . . . . . . 501
x Maxima 5.30.0 Manual
32 Runtime Environment . . . . . . . . . . . . . . . . . . 503
32.1 Introduction for Runtime Environment . . . . . . . . . . . . . . . . 503
32.2 Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
32.3 Functions and Variables for Runtime Environment . . . . . . 503
33 Miscellaneous Options . . . . . . . . . . . . . . . . . . 507
33.1 Introduction to Miscellaneous Options . . . . . . . . . . . . . . . . . 507
33.2 Share . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
33.3 Functions and Variables for Miscellaneous Options . . . . . . 507
34 Rules and Patterns . . . . . . . . . . . . . . . . . . . . . 511
34.1 Introduction to Rules and Patterns . . . . . . . . . . . . . . . . . . . . 511
34.2 Functions and Variables for Rules and Patterns. . . . . . . . . 511
35 Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527
35.1 Introduction to Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527
35.1.1 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527
35.1.2 Set Member Iteration . . . . . . . . . . . . . . . . . . . . . . . . 529
35.1.3 Bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 530
35.1.4 Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531
35.2 Functions and Variables for Sets. . . . . . . . . . . . . . . . . . . . . . . 531
36 Function Denition . . . . . . . . . . . . . . . . . . . . . 553
36.1 Introduction to Function Denition. . . . . . . . . . . . . . . . . . . . 553
36.2 Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
36.2.1 Ordinary functions . . . . . . . . . . . . . . . . . . . . . . . . . . 553
36.2.2 Array functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554
36.3 Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554
36.4 Functions and Variables for Function Denition . . . . . . . . 558
37 Program Flow. . . . . . . . . . . . . . . . . . . . . . . . . . 581
37.1 Lisp and Maxima . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581
37.2 Garbage Collection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582
37.3 Introduction to Program Flow . . . . . . . . . . . . . . . . . . . . . . . . 582
37.4 Functions and Variables for Program Flow . . . . . . . . . . . . . 583
38 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595
38.1 Source Level Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595
38.2 Keyword Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596
38.3 Functions and Variables for Debugging. . . . . . . . . . . . . . . . . 597
39 asympa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603
39.1 Introduction to asympa. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603
39.2 Functions and variables for asympa. . . . . . . . . . . . . . . . . . . . 603
xi
40 augmented lagrangian . . . . . . . . . . . . . . . . . . 605
40.1 Functions and Variables for augmented lagrangian . . . . . . 605
41 Bernstein . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607
41.1 Functions and Variables for Bernstein. . . . . . . . . . . . . . . . . . 607
42 bode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609
42.1 Functions and Variables for bode . . . . . . . . . . . . . . . . . . . . . . 609
43 cobyla . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611
43.1 Introduction to cobyla . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611
43.2 Functions and Variables for cobyla . . . . . . . . . . . . . . . . . . . . 611
43.3 Examples for cobyla . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612
44 contrib ode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615
44.1 Introduction to contrib ode . . . . . . . . . . . . . . . . . . . . . . . . . . . 615
44.2 Functions and Variables for contrib ode . . . . . . . . . . . . . . . . 617
44.3 Possible improvements to contrib ode . . . . . . . . . . . . . . . . . . 620
44.4 Test cases for contrib ode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 620
44.5 References for contrib ode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 620
45 descriptive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
45.1 Introduction to descriptive . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
45.2 Functions and Variables for data manipulation . . . . . . . . . 625
45.3 Functions and Variables for descriptive statistics. . . . . . . . 630
45.4 Functions and Variables for statistical graphs. . . . . . . . . . . 643
46 diag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653
46.1 Functions and Variables for diag . . . . . . . . . . . . . . . . . . . . . . 653
47 distrib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 661
47.1 Introduction to distrib. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 661
47.2 Functions and Variables for continuous distributions . . . . 663
47.3 Functions and Variables for discrete distributions . . . . . . . 687
48 draw. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 699
48.1 Introduction to draw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 699
48.2 Functions and Variables for draw. . . . . . . . . . . . . . . . . . . . . . 699
48.2.1 Scenes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 699
48.2.2 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 700
48.2.3 Graphics options . . . . . . . . . . . . . . . . . . . . . . . . . . . . 702
48.2.4 Graphics objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 740
48.3 Functions and Variables for pictures . . . . . . . . . . . . . . . . . . . 755
48.4 Functions and Variables for worldmap . . . . . . . . . . . . . . . . . 756
48.4.1 Variables and Functions . . . . . . . . . . . . . . . . . . . . . . 757
48.4.2 Graphic objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 759
xii Maxima 5.30.0 Manual
49 drawdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763
49.1 Introduction to drawdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763
49.2 Functions and Variables for drawdf . . . . . . . . . . . . . . . . . . . . 763
49.2.1 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763
50 dynamics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 767
50.1 Introduction to dynamics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 767
50.2 Functions and Variables for dynamics . . . . . . . . . . . . . . . . . . 767
51 ezunits. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 777
51.1 Introduction to ezunits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 777
51.2 Introduction to physical constants . . . . . . . . . . . . . . . . . . . . . 778
51.3 Functions and Variables for ezunits . . . . . . . . . . . . . . . . . . . . 780
52 f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 793
52.1 Functions and Variables for f90. . . . . . . . . . . . . . . . . . . . . . . . 793
53 nance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 795
53.1 Introduction to nance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 795
53.2 Functions and Variables for nance . . . . . . . . . . . . . . . . . . . . 795
54 fractals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 801
54.1 Introduction to fractals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 801
54.2 Denitions for IFS fractals . . . . . . . . . . . . . . . . . . . . . . . . . . . . 801
54.3 Denitions for complex fractals. . . . . . . . . . . . . . . . . . . . . . . . 802
54.4 Denitions for Koch snowakes. . . . . . . . . . . . . . . . . . . . . . . . 803
54.5 Denitions for Peano maps. . . . . . . . . . . . . . . . . . . . . . . . . . . . 803
55 ggf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 805
55.1 Functions and Variables for ggf . . . . . . . . . . . . . . . . . . . . . . . . 805
56 graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 807
56.1 Introduction to graphs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 807
56.2 Functions and Variables for graphs . . . . . . . . . . . . . . . . . . . . 807
56.2.1 Building graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 807
56.2.2 Graph properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . 813
56.2.3 Modifying graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 828
56.2.4 Reading and writing to les . . . . . . . . . . . . . . . . . . 830
56.2.5 Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 831
xiii
57 grobner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 837
57.1 Introduction to grobner. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 837
57.1.1 Notes on the grobner package. . . . . . . . . . . . . . . . . 837
57.1.2 Implementations of admissible monomial orders in
grobner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 837
57.2 Functions and Variables for grobner . . . . . . . . . . . . . . . . . . . 838
57.2.1 Global switches for grobner. . . . . . . . . . . . . . . . . . . 838
57.2.2 Simple operators in grobner . . . . . . . . . . . . . . . . . . 839
57.2.3 Other functions in grobner . . . . . . . . . . . . . . . . . . . 840
57.2.4 Standard postprocessing of Groebner Bases . . . . 841
58 impdi. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 845
58.1 Functions and Variables for impdi. . . . . . . . . . . . . . . . . . . . 845
59 interpol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 847
59.1 Introduction to interpol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 847
59.2 Functions and Variables for interpol . . . . . . . . . . . . . . . . . . . 847
60 lapack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 853
60.1 Introduction to lapack. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 853
60.2 Functions and Variables for lapack . . . . . . . . . . . . . . . . . . . . 853
61 lbfgs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 861
61.1 Introduction to lbfgs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 861
61.2 Functions and Variables for lbfgs . . . . . . . . . . . . . . . . . . . . . . 861
62 lindstedt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 867
62.1 Functions and Variables for lindstedt . . . . . . . . . . . . . . . . . . 867
63 linearalgebra . . . . . . . . . . . . . . . . . . . . . . . . . . . 869
63.1 Introduction to linearalgebra . . . . . . . . . . . . . . . . . . . . . . . . . . 869
63.2 Functions and Variables for linearalgebra . . . . . . . . . . . . . . 871
64 lsquares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 883
64.1 Introduction to lsquares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 883
64.2 Functions and Variables for lsquares . . . . . . . . . . . . . . . . . . . 883
65 minpack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 893
65.1 Introduction to minpack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 893
65.2 Functions and Variables for minpack. . . . . . . . . . . . . . . . . . . 893
66 makeOrders . . . . . . . . . . . . . . . . . . . . . . . . . . . . 895
66.1 Functions and Variables for makeOrders . . . . . . . . . . . . . . . 895
xiv Maxima 5.30.0 Manual
67 mnewton. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897
67.1 Introduction to mnewton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897
67.2 Functions and Variables for mnewton . . . . . . . . . . . . . . . . . . 897
68 numericalio . . . . . . . . . . . . . . . . . . . . . . . . . . . . 899
68.1 Introduction to numericalio . . . . . . . . . . . . . . . . . . . . . . . . . . . 899
68.1.1 Plain-text input and output . . . . . . . . . . . . . . . . . . 899
68.1.2 Separator ag values for input . . . . . . . . . . . . . . . . 899
68.1.3 Separator ag values for output. . . . . . . . . . . . . . . 899
68.1.4 Binary oating-point input and output . . . . . . . . 900
68.2 Functions and Variables for plain-text input and output
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 900
68.3 Functions and Variables for binary input and output . . . . 902
69 opsubst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 905
69.1 Functions and Variables for opsubst . . . . . . . . . . . . . . . . . . . 905
70 orthopoly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 907
70.1 Introduction to orthogonal polynomials . . . . . . . . . . . . . . . . 907
70.1.1 Getting Started with orthopoly . . . . . . . . . . . . . . . 907
70.1.2 Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 909
70.1.3 Floating point Evaluation . . . . . . . . . . . . . . . . . . . . 911
70.1.4 Graphics and orthopoly . . . . . . . . . . . . . . . . . . . . . 912
70.1.5 Miscellaneous Functions. . . . . . . . . . . . . . . . . . . . . . 913
70.1.6 Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 914
70.2 Functions and Variables for orthogonal polynomials . . . . . 914
71 romberg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 919
71.1 Functions and Variables for romberg. . . . . . . . . . . . . . . . . . . 919
72 simplex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 923
72.1 Introduction to simplex. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 923
72.2 Functions and Variables for simplex . . . . . . . . . . . . . . . . . . . 923
73 simplication. . . . . . . . . . . . . . . . . . . . . . . . . . . 925
73.1 Introduction to simplication . . . . . . . . . . . . . . . . . . . . . . . . . 925
73.2 Package absimp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 925
73.3 Package facexp. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 925
73.4 Package functs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 927
73.5 Package ineq. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 930
73.6 Package rducon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 932
73.7 Package scifac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 932
73.8 Package sqdnst. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 933
xv
74 solve rec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 935
74.1 Introduction to solve rec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 935
74.2 Functions and Variables for solve rec . . . . . . . . . . . . . . . . . . 935
75 stats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 939
75.1 Introduction to stats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 939
75.2 Functions and Variables for inference result . . . . . . . . . . . . 939
75.3 Functions and Variables for stats . . . . . . . . . . . . . . . . . . . . . . 941
75.4 Functions and Variables for special distributions . . . . . . . . 955
76 stirling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 957
76.1 Functions and Variables for stirling . . . . . . . . . . . . . . . . . . . . 957
77 stringproc. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 959
77.1 Introduction to string processing . . . . . . . . . . . . . . . . . . . . . . 959
77.2 Functions and Variables for input and output . . . . . . . . . . 960
77.3 Functions and Variables for characters . . . . . . . . . . . . . . . . . 963
77.4 Functions and Variables for strings . . . . . . . . . . . . . . . . . . . . 964
78 to poly solve . . . . . . . . . . . . . . . . . . . . . . . . . . . 971
78.1 Functions and Variables for to poly solve . . . . . . . . . . . . . . 971
79 unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 991
79.1 Introduction to Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 991
79.2 Functions and Variables for Units . . . . . . . . . . . . . . . . . . . . . 992
80 zeilberger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1001
80.1 Introduction to zeilberger . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1001
80.1.0.1 The indenite summation problem . . 1001
80.1.0.2 The denite summation problem. . . . 1001
80.1.1 Verbosity levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1001
80.2 Functions and Variables for zeilberger . . . . . . . . . . . . . . . . 1002
80.3 General global variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1003
80.4 Variables related to the modular test . . . . . . . . . . . . . . . . . 1004
81 Indices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1005
Appendix A Function and Variable Index . . 1007
xvi Maxima 5.30.0 Manual
Chapter 1: Introduction to Maxima 1
1 Introduction to Maxima
Start Maxima with the command "maxima". Maxima will display version information
and a prompt. End each Maxima command with a semicolon. End the session with the
command "quit();". Heres a sample session:
[wfs@chromium]$ maxima
Maxima 5.9.1 http://maxima.sourceforge.net
Using Lisp CMU Common Lisp 19a
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
This is a development version of Maxima. The function bug_report()
provides bug reporting information.
(%i1) factor(10!);
8 4 2
(%o1) 2 3 5 7
(%i2) expand ((x + y)^6);
6 5 2 4 3 3 4 2 5 6
(%o2) y + 6 x y + 15 x y + 20 x y + 15 x y + 6 x y + x
(%i3) factor (x^6 - 1);
2 2
(%o3) (x - 1) (x + 1) (x - x + 1) (x + x + 1)
(%i4) quit();
[wfs@chromium]$
Maxima can search the info pages. Use the describe command to show information
about the command or all the commands and variables containing a string. The question
mark ? (exact search) and double question mark ?? (inexact search) are abbreviations for
describe:
(%i1) ?? integ
0: Functions and Variables for Elliptic Integrals
1: Functions and Variables for Integration
2: Introduction to Elliptic Functions and Integrals
3: Introduction to Integration
4: askinteger (Functions and Variables for Simplification)
5: integerp (Functions and Variables for Miscellaneous Options)
6: integer_partitions (Functions and Variables for Sets)
7: integrate (Functions and Variables for Integration)
8: integrate_use_rootsof (Functions and Variables for Integration)
9: integration_constant_counter (Functions and Variables for
Integration)
10: nonnegintegerp (Functions and Variables for linearalgebra)
Enter space-separated numbers, all or none: 5 4
-- Function: integerp (<expr>)
Returns true if <expr> is a literal numeric integer, otherwise
false.
integerp returns false if its argument is a symbol, even if the
argument is declared integer.
2 Maxima 5.30.0 Manual
Examples:
(%i1) integerp (0);
(%o1) true
(%i2) integerp (1);
(%o2) true
(%i3) integerp (-17);
(%o3) true
(%i4) integerp (0.0);
(%o4) false
(%i5) integerp (1.0);
(%o5) false
(%i6) integerp (%pi);
(%o6) false
(%i7) integerp (n);
(%o7) false
(%i8) declare (n, integer);
(%o8) done
(%i9) integerp (n);
(%o9) false
-- Function: askinteger (<expr>, integer)
-- Function: askinteger (<expr>)
-- Function: askinteger (<expr>, even)
-- Function: askinteger (<expr>, odd)
askinteger (<expr>, integer) attempts to determine from the
assume database whether <expr> is an integer. askinteger
prompts the user if it cannot tell otherwise, and attempt to
install the information in the database if possible. askinteger
(<expr>) is equivalent to askinteger (<expr>, integer).
askinteger (<expr>, even) and askinteger (<expr>, odd)
likewise attempt to determine if <expr> is an even integer or odd
integer, respectively.
(%o1) true
To use a result in later calculations, you can assign it to a variable or refer to it by its
automatically supplied label. In addition, % refers to the most recent calculated result:
(%i1) u: expand ((x + y)^6);
6 5 2 4 3 3 4 2 5 6
(%o1) y + 6 x y + 15 x y + 20 x y + 15 x y + 6 x y + x
(%i2) diff (u, x);
5 4 2 3 3 2 4 5
(%o2) 6 y + 30 x y + 60 x y + 60 x y + 30 x y + 6 x
(%i3) factor (%o2);
5
(%o3) 6 (y + x)
Chapter 1: Introduction to Maxima 3
Maxima knows about complex numbers and numerical constants:
(%i1) cos(%pi);
(%o1) - 1
(%i2) exp(%i*%pi);
(%o2) - 1
Maxima can do dierential and integral calculus:
(%i1) u: expand ((x + y)^6);
6 5 2 4 3 3 4 2 5 6
(%o1) y + 6 x y + 15 x y + 20 x y + 15 x y + 6 x y + x
(%i2) diff (%, x);
5 4 2 3 3 2 4 5
(%o2) 6 y + 30 x y + 60 x y + 60 x y + 30 x y + 6 x
(%i3) integrate (1/(1 + x^3), x);
2 x - 1
2 atan(-------)
log(x - x + 1) sqrt(3) log(x + 1)
(%o3) - --------------- + ------------- + ----------
6 sqrt(3) 3
Maxima can solve linear systems and cubic equations:
(%i1) linsolve ([3*x + 4*y = 7, 2*x + a*y = 13], [x, y]);
7 a - 52 25
(%o1) [x = --------, y = -------]
3 a - 8 3 a - 8
(%i2) solve (x^3 - 3*x^2 + 5*x = 15, x);
(%o2) [x = - sqrt(5) %i, x = sqrt(5) %i, x = 3]
Maxima can solve nonlinear sets of equations. Note that if you dont want a result
printed, you can nish your command with $ instead of ;.
(%i1) eq_1: x^2 + 3*x*y + y^2 = 0$
(%i2) eq_2: 3*x + y = 1$
(%i3) solve ([eq_1, eq_2]);
3 sqrt(5) + 7 sqrt(5) + 3
(%o3) [[y = - -------------, x = -----------],
2 2
3 sqrt(5) - 7 sqrt(5) - 3
[y = -------------, x = - -----------]]
2 2
Maxima can generate plots of one or more functions:
4 Maxima 5.30.0 Manual
(%i1) plot2d (sin(x)/x, [x, -20, 20])$
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
-20 -15 -10 -5 0 5 10 15 20
s
i
n
(
x
)
/
x
x
(%i2) plot2d ([atan(x), erf(x), tanh(x)], [x, -5, 5], [y, -1.5, 2])$
-1.5
-1
-0.5
0
0.5
1
1.5
2
-4 -2 0 2 4
y
x
atan(x)
erf(x)
tanh(x)
Chapter 1: Introduction to Maxima 5
(%i3) plot3d (sin(sqrt(x^2 + y^2))/sqrt(x^2 + y^2),
[x, -12, 12], [y, -12, 12])$
-10
-5
0
5
10
-10
-5
0
5
10
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
z
sin(sqrt(y
2
+x
2
))/sqrt(y
2
+x
2
)
x
y
z
6 Maxima 5.30.0 Manual
Chapter 2: Bug Detection and Reporting 7
2 Bug Detection and Reporting
2.1 Functions and Variables for Bug Detection and
Reporting
Function run testsuite ([options])
Run the Maxima test suite. Tests producing the desired answer are considered
passes, as are tests that do not produce the desired answer, but are marked as
known bugs.
run_testsuite takes the following optional keyword arguments
display all Display all tests. Normally, the tests are not displayed, unless the test
fails. (Defaults to false).
display known bugs
Displays tests that are marked as known bugs. (Default is false).
tests This is a single test or a list of tests that should be run. Each test can
be specied by either a string or a symbol. By default, all tests are run.
The complete set of tests is specied by testsuite_files.
time Display time information. If true, the time taken for each test le is
displayed. If all, the time for each individual test is shown if display_
all is true. The default is false, so no timing information is shown.
For example run_testsuite(display_known_bugs = true, tests=[rtest5]) runs
just test rtest5 and displays the test that are marked as known bugs.
run_testsuite(display_all = true, tests=["rtest1", rtest1a]) will run tests
rtest1 and rtest2, and displays each test.
run_testsuite changes the Maxima environment. Typically a test script executes
kill to establish a known environment (namely one without user-dened functions
and variables) and then denes functions and variables appropriate to the test.
run_testsuite returns done.
Option variable testsuite les
testsuite_files is the set of tests to be run by run_testsuite. It is a list of
names of the les containing the tests to run. If some of the tests in a le are known
to fail, then instead of listing the name of the le, a list containing the le name and
the test numbers that fail is used.
For example, this is a part of the default set of tests:
["rtest13s", ["rtest14", 57, 63]]
This species the testsuite consists of the les "rtest13s" and "rtest14", but "rtest14"
contains two tests that are known to fail: 57 and 63.
8 Maxima 5.30.0 Manual
Function bug report ()
Prints out Maxima and Lisp version numbers, and gives a link to the Maxima project
bug report web page. The version information is the same as reported by build_
info.
When a bug is reported, it is helpful to copy the Maxima and Lisp version information
into the bug report.
bug_report returns an empty string "".
Function build info ()
Returns a summary of the parameters of the Maxima build, as a Maxima structure
(dened by defstruct). The elds of the structure are: version, timestamp, host,
lisp_name, and lisp_version. When the pretty-printer is enabled (via display2d),
the structure is displayed as a short table.
See also bug_report.
Examples:
(%i1) build_info ();
(%o1)
Maxima version: "5.26.0_16_gb72c64c_dirty"
Maxima build date: "2012-01-29 12:29:04"
Host type: "i686-pc-linux-gnu"
Lisp implementation type: "CMU Common Lisp"
Lisp implementation version: "CVS release-19a 19a-release-20040728 + minimal debian patches"
(%i2) x : build_info ()$
(%i3) x@version;
(%o3) 5.26.0_16_gb72c64c_dirty
(%i4) x@timestamp;
(%o4) 2012-01-29 12:29:04
(%i5) x@host;
(%o5) i686-pc-linux-gnu
(%i6) x@lisp_name;
(%o6) CMU Common Lisp
(%i7) x@lisp_version;
(%o7)
CVS release-19a 19a-release-20040728 + minimal debian patches
(%i8) x;
(%o8)
Maxima version: "5.26.0_16_gb72c64c_dirty"
Maxima build date: "2012-01-29 12:29:04"
Host type: "i686-pc-linux-gnu"
Lisp implementation type: "CMU Common Lisp"
Lisp implementation version: "CVS release-19a 19a-release-20040728 + minimal debian patches"
Chapter 3: Help 9
3 Help
3.1 Documentation
The Maxima on-line users manual can be viewed in dierent forms. From the Maxima
interactive prompt, the users manual is viewed as plain text by the ? command (i.e., the
describe function). The users manual is viewed as info hypertext by the info viewer
program and as a web page by any ordinary web browser.
example displays examples for many Maxima functions. For example,
(%i1) example (integrate);
yields
(%i2) test(f):=block([u],u:integrate(f,x),ratsimp(f-diff(u,x)))
(%o2) test(f) := block([u], u : integrate(f, x),
ratsimp(f - diff(u, x)))
(%i3) test(sin(x))
(%o3) 0
(%i4) test(1/(x+1))
(%o4) 0
(%i5) test(1/(x^2+1))
(%o5) 0
and additional output.
3.2 Functions and Variables for Help
Function apropos (string)
Searches for Maxima names which have string appearing anywhere within them.
Thus, apropos (exp) returns a list of all the ags and functions which have exp as
part of their names, such as expand, exp, and exponentialize. Thus if you can only
remember part of the name of something you can use this command to nd the rest
of the name. Similarly, you could say apropos (tr_) to nd a list of many of the
switches relating to the translator, most of which begin with tr_.
apropos("") returns a list with all Maxima names.
apropos returns the empty list [], if no name is found.
Example:
Show all Maxima symbols which have "gamma" in the name:
(%i1) apropos("gamma");
(%o1) [%gamma, gamma, gammalim, gamma_expand, gamma_greek,
gamma_incomplete, gamma_incomplete_generalized,
gamma_incomplete_regularized, Gamma, log_gamma, makegamma,
prefer_gamma_incomplete,
gamma_incomplete_generalized_regularized]
10 Maxima 5.30.0 Manual
Function demo (lename)
Evaluates Maxima expressions in lename and displays the results. demo pauses after
evaluating each expression and continues after the user enters a carriage return. (If
running in Xmaxima, demo may need to see a semicolon ; followed by a carriage
return.)
demo searches the list of directories file_search_demo to nd filename. If the le
has the sux dem, the sux may be omitted. See also file_search.
demo evaluates its argument. demo returns the name of the demonstration le.
Example:
(%i1) demo ("disol");
batching /home/wfs/maxima/share/simplification/disol.dem
At the _ prompt, type ; followed by enter to get next demo
(%i2) load(disol)
_
(%i3) exp1 : a (e (g + f) + b (d + c))
(%o3) a (e (g + f) + b (d + c))
_
(%i4) disolate(exp1, a, b, e)
(%t4) d + c
(%t5) g + f
(%o5) a (%t5 e + %t4 b)
_
Function describe (string)
Function describe (string, exact)
Function describe (string, inexact)
describe(string) is equivalent to describe(string, exact).
describe(string, exact) nds an item with title equal (case-insensitive) to string, if
there is any such item.
describe(string, inexact) nds all documented items which contain string in their
titles. If there is more than one such item, Maxima asks the user to select an item or
items to display.
At the interactive prompt, ? foo (with a space between ? and foo) is equivalent to
describe("foo", exact), and ?? foo is equivalent to describe("foo", inexact).
describe("", inexact) yields a list of all topics documented in the on-line manual.
describe quotes its argument. describe returns true if some documentation is
found, otherwise false.
See also Section 3.1 [Documentation], page 9.
Example:
Chapter 3: Help 11
(%i1) ?? integ
0: Functions and Variables for Elliptic Integrals
1: Functions and Variables for Integration
2: Introduction to Elliptic Functions and Integrals
3: Introduction to Integration
4: askinteger (Functions and Variables for Simplification)
5: integerp (Functions and Variables for Miscellaneous Options)
6: integer_partitions (Functions and Variables for Sets)
7: integrate (Functions and Variables for Integration)
8: integrate_use_rootsof (Functions and Variables for
Integration)
9: integration_constant_counter (Functions and Variables for
Integration)
10: nonnegintegerp (Functions and Variables for linearalgebra)
Enter space-separated numbers, all or none: 7 8
-- Function: integrate (<expr>, <x>)
-- Function: integrate (<expr>, <x>, <a>, <b>)
Attempts to symbolically compute the integral of <expr> with
respect to <x>. integrate (<expr>, <x>) is an indefinite
integral, while integrate (<expr>, <x>, <a>, <b>) is a
definite integral, [...]
-- Option variable: integrate_use_rootsof
Default value: false
When integrate_use_rootsof is true and the denominator of
a rational function cannot be factored, integrate returns
the integral in a form which is a sum over the roots (not yet
known) of the denominator.
[...]
In this example, items 7 and 8 were selected (output is shortened as indicated by
[...]. All or none of the items could have been selected by entering all or none,
which can be abbreviated a or n, respectively.
Function example (topic)
Function example ()
example (topic) displays some examples of topic, which is a symbol or a string. To
get examples for operators like if, do, or lambda the argument must be a string, e.g.
example ("do"). example is not case sensitive. Most topics are function names.
example () returns the list of all recognized topics.
The name of the le containing the examples is given by the global option variable
manual_demo, which defaults to "manual.demo".
example quotes its argument. example returns done unless no examples are found or
there is no argument, in which case example returns the list of all recognized topics.
Examples:
12 Maxima 5.30.0 Manual
(%i1) example(append);
(%i2) append([x+y,0,-3.2],[2.5e+20,x])
(%o2) [y + x, 0, - 3.2, 2.5e+20, x]
(%o2) done
(%i3) example("lambda");
(%i4) lambda([x,y,z],z^2+y^2+x^2)
2 2 2
(%o4) lambda([x, y, z], z + y + x )
(%i5) %(1,2,a)
2
(%o5) a + 5
(%i6) a+2+1
(%o6) a + 3
(%o6) done
Option variable manual demo
Default value: "manual.demo"
manual_demo species the name of the le containing the examples for the function
example. See example.
Chapter 4: Command Line 13
4 Command Line
4.1 Introduction to Command Line
4.2 Functions and Variables for Command Line
System variable
__ is the input expression currently being evaluated. That is, while an input expres-
sion expr is being evaluated, __ is expr.
__ is assigned the input expression before the input is simplied or evaluated. How-
ever, the value of __ is simplied (but not evaluated) when it is displayed.
__ is recognized by batch and load. In a le processed by batch, __ has the same
meaning as at the interactive prompt. In a le processed by load, __ is bound to the
input expression most recently entered at the interactive prompt or in a batch le;
__ is not bound to the input expressions in the le being processed. In particular,
when load (lename) is called from the interactive prompt, __ is bound to load
(lename) while the le is being processed.
See also _ and %.
Examples:
(%i1) print ("I was called as", __);
I was called as print(I was called as, __)
(%o1) print(I was called as, __)
(%i2) foo (__);
(%o2) foo(foo(__))
(%i3) g (x) := (print ("Current input expression =", __), 0);
(%o3) g(x) := (print("Current input expression =", __), 0)
(%i4) [aa : 1, bb : 2, cc : 3];
(%o4) [1, 2, 3]
(%i5) (aa + bb + cc)/(dd + ee + g(x));
cc + bb + aa
Current input expression = --------------
g(x) + ee + dd
6
(%o5) -------
ee + dd
System variable
_ is the most recent input expression (e.g., %i1, %i2, %i3, . . . ).
_ is assigned the input expression before the input is simplied or evaluated. However,
the value of _ is simplied (but not evaluated) when it is displayed.
_ is recognized by batch and load. In a le processed by batch, _ has the same
meaning as at the interactive prompt. In a le processed by load, _ is bound to the
14 Maxima 5.30.0 Manual
input expression most recently evaluated at the interactive prompt or in a batch le;
_ is not bound to the input expressions in the le being processed.
See also __ and %.
Examples:
(%i1) 13 + 29;
(%o1) 42
(%i2) :lisp $_
((MPLUS) 13 29)
(%i2) _;
(%o2) 42
(%i3) sin (%pi/2);
(%o3) 1
(%i4) :lisp $_
((%SIN) ((MQUOTIENT) $%PI 2))
(%i4) _;
(%o4) 1
(%i5) a: 13$
(%i6) b: 29$
(%i7) a + b;
(%o7) 42
(%i8) :lisp $_
((MPLUS) $A $B)
(%i8) _;
(%o8) b + a
(%i9) a + b;
(%o9) 42
(%i10) ev (_);
(%o10) 42
System variable %
% is the output expression (e.g., %o1, %o2, %o3, . . . ) most recently computed by
Maxima, whether or not it was displayed.
% is recognized by batch and load. In a le processed by batch, % has the same
meaning as at the interactive prompt. In a le processed by load, % is bound to the
output expression most recently computed at the interactive prompt or in a batch
le; % is not bound to output expressions in the le being processed.
See also _, %%, and %th.
System variable %%
In compound statements, namely block, lambda, or (s 1, ..., s n), %% is the value
of the previous statement.
At the rst statement in a compound statement, or outside of a compound statement,
%% is undened.
%% is recognized by batch and load, and it has the same meaning as at the interactive
prompt.
Chapter 4: Command Line 15
See also %.
Examples:
The following two examples yield the same result.
(%i1) block (integrate (x^5, x), ev (%%, x=2) - ev (%%, x=1));
21
(%o1) --
2
(%i2) block ([prev], prev: integrate (x^5, x),
ev (prev, x=2) - ev (prev, x=1));
21
(%o2) --
2
A compound statement may comprise other compound statements. Whether a state-
ment be simple or compound, %% is the value of the previous statement.
(%i3) block (block (a^n, %%*42), %%/6);
n
(%o3) 7 a
Within a compound statement, the value of %% may be inspected at a break prompt,
which is opened by executing the break function. For example, entering %%; in the
following example yields 42.
(%i4) block (a: 42, break ())$
Entering a Maxima break point. Type exit; to resume.
_%%;
42
_
Function %th (i)
The value of the ith previous output expression. That is, if the next expression to
be computed is the nth output, %th (m) is the (n - m)th output.
%th is recognized by batch and load. In a le processed by batch, %th has the
same meaning as at the interactive prompt. In a le processed by load, %th refers to
output expressions most recently computed at the interactive prompt or in a batch
le; %th does not refer to output expressions in the le being processed.
See also % and %%.
Example:
%th is useful in batch les or for referring to a group of output expressions. This
example sets s to the sum of the last ve output expressions.
(%i1) 1;2;3;4;5;
(%o1) 1
(%o2) 2
(%o3) 3
(%o4) 4
(%o5) 5
16 Maxima 5.30.0 Manual
(%i6) block (s: 0, for i:1 thru 5 do s: s + %th(i), s);
(%o6) 15
Special symbol ?
As prex to a function or variable name, ? signies that the name is a Lisp name,
not a Maxima name. For example, ?round signies the Lisp function ROUND. See
Section 37.1 [Lisp and Maxima], page 581 for more on this point.
The notation ? word (a question mark followed a word, separated by whitespace) is
equivalent to describe("word"). The question mark must occur at the beginning of
an input line; otherwise it is not recognized as a request for documentation. See also
describe.
Special symbol ??
The notation ?? word (?? followed a word, separated by whitespace) is equivalent to
describe("word", inexact). The question mark must occur at the beginning of an
input line; otherwise it is not recognized as a request for documentation. See also
describe.
Option variable inchar
Default value: %i
inchar is the prex of the labels of expressions entered by the user. Maxima auto-
matically constructs a label for each input expression by concatenating inchar and
linenum.
inchar may be assigned any string or symbol, not necessarily a single character.
Because Maxima internally takes into account only the rst char of the prex, the
prexes inchar, outchar, and linechar should have a dierent rst char. Otherwise
some commands like kill(inlables) do not work as expected.
See also labels.
Example:
(%i1) inchar: "input";
(%o1) input
(input2) expand((a+b)^3);
3 2 2 3
(%o2) b + 3 a b + 3 a b + a
(input3)
System variable infolists
Default value: []
infolists is a list of the names of all of the information lists in Maxima. These are:
labels All bound %i, %o, and %t labels.
values All bound atoms which are user variables, not Maxima options or
switches, created by : or :: or functional binding.
Chapter 4: Command Line 17
functions
All user-dened functions, created by := or define.
arrays All declared and undeclared arrays, created by :, ::, or :=.
macros All user-dened macro functions, created by ::=.
myoptions
All options ever reset by the user (whether or not they are later reset to
their default values).
rules All user-dened pattern matching and simplication rules, created by
tellsimp, tellsimpafter, defmatch, or defrule.
aliases All atoms which have a user-dened alias, created by the alias,
ordergreat, orderless functions or by declaring the atom as a noun
with declare.
dependencies
All atoms which have functional dependencies, created by the depends
or gradef functions.
gradefs All functions which have user-dened derivatives, created by the gradef
function.
props All atoms which have any property other than those mentioned above,
such as properties established by atvalue or matchdeclare , etc., as
well as properties established in the declare function.
let_rule_packages
All user-dened let rule packages plus the special package default_
let_rule_package. (default_let_rule_package is the name of the
rule package used when one is not explicitly set by the user.)
Function kill (a 1, . . . , a n)
Function kill (labels)
Function kill (inlabels, outlabels, linelabels)
Function kill (n)
Function kill ([m, n])
Function kill (values, functions, arrays, . . . )
Function kill (all)
Function kill (allbut (a 1, . . . , a n))
Removes all bindings (value, function, array, or rule) from the arguments a 1, . . . ,
a n. An argument a k may be a symbol or a single array element. When a k is a
single array element, kill unbinds that element without aecting any other elements
of the array.
Several special arguments are recognized. Dierent kinds of arguments may be com-
bined, e.g., kill (inlabels, functions, allbut (foo, bar)).
kill (labels) unbinds all input, output, and intermediate expression labels created
so far. kill (inlabels) unbinds only input labels which begin with the current
value of inchar. Likewise, kill (outlabels) unbinds only output labels which
18 Maxima 5.30.0 Manual
begin with the current value of outchar, and kill (linelabels) unbinds only
intermediate expression labels which begin with the current value of linechar.
kill (n), where n is an integer, unbinds the n most recent input and output labels.
kill ([m, n]) unbinds input and output labels m through n.
kill (infolist), where infolist is any item in infolists (such as values, functions,
or arrays ) unbinds all items in infolist. See also infolists.
kill (all) unbinds all items on all infolists. kill (all) does not reset global vari-
ables to their default values; see reset on this point.
kill (allbut (a 1, ..., a n)) unbinds all items on all infolists except for a 1, . . . ,
a n. kill (allbut (infolist)) unbinds all items except for the ones on infolist, where
infolist is values, functions, arrays, etc.
The memory taken up by a bound property is not released until all symbols are
unbound from it. In particular, to release the memory taken up by the value of
a symbol, one unbinds the output label which shows the bound value, as well as
unbinding the symbol itself.
kill quotes its arguments. The quote-quote operator defeats quotation.
kill (symbol) unbinds all properties of symbol. In contrast, the functions remvalue,
remfunction, remarray, and remrule unbind a specic property.
kill always returns done, even if an argument has no binding.
Function labels (symbol)
System variable labels
Returns the list of input, output, or intermediate expression labels which begin with
symbol. Typically symbol is the value of inchar, outchar, or linechar. The
label character may be given with or without a percent sign, so, for example, i and
%i yield the same result.
If no labels begin with symbol, labels returns an empty list.
The function labels quotes its argument. The quote-quote operator defeats quo-
tation. For example, labels (inchar) returns the input labels which begin with
the current input label character.
The variable labels is the list of input, output, and intermediate expression labels,
including all previous labels if inchar, outchar, or linechar were redened.
By default, Maxima displays the result of each user input expression, giving the result
an output label. The output display is suppressed by terminating the input with $
(dollar sign) instead of ; (semicolon). An output label is constructed and bound to
the result, but not displayed, and the label may be referenced in the same way as
displayed output labels. See also %, %%, and %th.
Intermediate expression labels can be generated by some functions. The option vari-
able programmode controls whether solve and some other functions generate in-
termediate expression labels instead of returning a list of expressions. Some other
functions, such as ldisplay, always generate intermediate expression labels.
See also inchar, outchar, linechar, and infolists.
Chapter 4: Command Line 19
Option variable linechar
Default value: %t
linechar is the prex of the labels of intermediate expressions generated by Max-
ima. Maxima constructs a label for each intermediate expression (if displayed) by
concatenating linechar and linenum.
linechar may be assigned any string or symbol, not necessarily a single character.
Because Maxima internally takes into account only the rst char of the prex, the
prexes inchar, outchar, and linechar should have a dierent rst char. Otherwise
some commands like kill(inlables) do not work as expected.
Intermediate expressions might or might not be displayed. See programmode and
labels.
System variable linenum
The line number of the current pair of input and output expressions.
System variable myoptions
Default value: []
myoptions is the list of all options ever reset by the user, whether or not they get
reset to their default value.
Option variable nolabels
Default value: false
When nolabels is true, input and output result labels (%i and %o, respectively) are
displayed, but the labels are not bound to results, and the labels are not appended to
the labels list. Since labels are not bound to results, garbage collection can recover
the memory taken up by the results.
Otherwise input and output result labels are bound to results, and the labels are
appended to the labels list.
Intermediate expression labels (%t) are not aected by nolabels; whether nolabels
is true or false, intermediate expression labels are bound and appended to the
labels list.
See also batch, load, and labels.
Option variable optionset
Default value: false
When optionset is true, Maxima prints out a message whenever a Maxima option
is reset. This is useful if the user is doubtful of the spelling of some option and wants
to make sure that the variable he assigned a value to was truly an option variable.
Example:
(%i1) optionset:true;
assignment: assigning to option optionset
(%o1) true
(%i2) gamma_expand:true;
assignment: assigning to option gamma_expand
(%o2) true
20 Maxima 5.30.0 Manual
Option variable outchar
Default value: %o
outchar is the prex of the labels of expressions computed by Maxima. Maxima auto-
matically constructs a label for each computed expression by concatenating outchar
and linenum.
outchar may be assigned any string or symbol, not necessarily a single character.
Because Maxima internally takes into account only the rst char of the prex, the
prexes inchar, outchar and linechar should have a dierent rst char. Otherwise
some commands like kill(inlables) do not work as expected.
See also labels.
Example:
(%i1) outchar: "output";
(output1) output
(%i2) expand((a+b)^3);
3 2 2 3
(output2) b + 3 a b + 3 a b + a
(%i3)
Function playback ()
Function playback (n)
Function playback ([m, n])
Function playback ([m])
Function playback (input)
Function playback (slow)
Function playback (time)
Function playback (grind)
Displays input, output, and intermediate expressions, without recomputing them.
playback only displays the expressions bound to labels; any other output (such as
text printed by print or describe, or error messages) is not displayed. See also
labels.
playback quotes its arguments. The quote-quote operator defeats quotation.
playback always returns done.
playback () (with no arguments) displays all input, output, and intermediate expres-
sions generated so far. An output expression is displayed even if it was suppressed by
the $ terminator when it was originally computed.
playback (n) displays the most recent n expressions. Each input, output, and inter-
mediate expression counts as one.
playback ([m, n]) displays input, output, and intermediate expressions with num-
bers from m through n, inclusive.
playback ([m]) is equivalent to playback ([m, m]); this usually prints one pair
of input and output expressions.
playback (input) displays all input expressions generated so far.
Chapter 4: Command Line 21
playback (slow) pauses between expressions and waits for the user to press enter.
This behavior is similar to demo. playback (slow) is useful in conjunction with
save or stringout when creating a secondary-storage le in order to pick out useful
expressions.
playback (time) displays the computation time for each expression.
playback (grind) displays input expressions in the same format as the grind func-
tion. Output expressions are not aected by the grind option. See grind.
Arguments may be combined, e.g., playback ([5, 10], grind, time, slow).
Option variable prompt
Default value: _
prompt is the prompt symbol of the demo function, playback (slow) mode, and the
Maxima break loop (as invoked by break ).
Function quit ()
Terminates the Maxima session. Note that the function must be invoked as quit();
or quit()$, not quit by itself.
To stop a lengthy computation, type control-C. The default action is to return to the
Maxima prompt. If *debugger-hook* is nil, control-C opens the Lisp debugger.
See also Chapter 38 [Debugging], page 595.
Function read (expr 1, . . . , expr n)
Prints expr 1, . . . , expr n, then reads one expression from the console and returns
the evaluated expression. The expression is terminated with a semicolon ; or dollar
sign $.
See also readonly
Example:
(%i1) foo: 42$
(%i2) foo: read ("foo is", foo, " -- enter new value.")$
foo is 42 -- enter new value.
(a+b)^3;
(%i3) foo;
3
(%o3) (b + a)
Function readonly (expr 1, . . . , expr n)
Prints expr 1, . . . , expr n, then reads one expression from the console and returns the
expression (without evaluation). The expression is terminated with a ; (semicolon)
or $ (dollar sign).
See also read.
Examples:
22 Maxima 5.30.0 Manual
(%i1) aa: 7$
(%i2) foo: readonly ("Enter an expression:");
Enter an expression:
2^aa;
aa
(%o2) 2
(%i3) foo: read ("Enter an expression:");
Enter an expression:
2^aa;
(%o3) 128
Function reset ()
Resets many global variables and options, and some other variables, to their default
values.
reset processes the variables on the Lisp list *variable-initial-values*. The
Lisp macro defmvar puts variables on this list (among other actions). Many, but not
all, global variables and options are dened by defmvar, and some variables dened
by defmvar are not global variables or options.
Option variable showtime
Default value: false
When showtime is true, the computation time and elapsed time is printed with each
output expression.
The computation time is always recorded, so time and playback can display the
computation time even when showtime is false.
See also timer.
Function to lisp ()
Enters the Lisp system under Maxima. (to-maxima) returns to Maxima.
Example:
Dene a function and enter the Lisp system under Maxima. The denition is inspected
on the property list, then the function denition is extracted, factored and stored in
the variable $result. The variable can be used in Maxima after returning to Maxima.
(%i1) f(x):=x^2+x;
2
(%o1) f(x) := x + x
(%i2) to_lisp();
Type (to-maxima) to restart, ($quit) to quit Maxima.
MAXIMA> (symbol-plist $f)
(MPROPS (NIL MEXPR ((LAMBDA) ((MLIST) $X)
((MPLUS) ((MEXPT) $X 2) $X))))
MAXIMA> (setq $result ($factor (caddr (mget $f mexpr))))
((MTIMES SIMP FACTORED) $X ((MPLUS SIMP IRREDUCIBLE) 1 $X))
MAXIMA> (to-maxima)
Returning to Maxima
Chapter 4: Command Line 23
(%o2) true
(%i3) result;
(%o3) x (x + 1)
System variable values
Initial value: []
values is a list of all bound user variables (not Maxima options or switches). The
list comprises symbols bound by :, or ::.
If the value of a variable is removed with the commands kill, remove, or remvalue
the variable is deleted from values.
See functions for a list of user dened functions.
Examples:
First, values shows the symbols a, b, and c, but not d, it is not bound to a value,
and not the user function f. The values are removed from the variables. values is
the empty list.
(%i1) [a:99, b::a-90, c:a-b, d, f(x):= x^2];
2
(%o1) [99, 9, 90, d, f(x) := x ]
(%i2) values;
(%o2) [a, b, c]
(%i3) [kill(a), remove(b,value), remvalue(c)];
(%o3) [done, done, [c]]
(%i4) values;
(%o4) []
4.3 Functions and Variables for Display
Option variable %edispag
Default value: false
When %edispflag is true, Maxima displays %e to a negative exponent as a quotient.
For example, %e^-x is displayed as 1/%e^x. See also exptdispflag.
Example:
(%i1) %e^-10;
- 10
(%o1) %e
(%i2) %edispflag:true$
(%i3) %e^-10;
1
(%o3) ----
10
%e
24 Maxima 5.30.0 Manual
Option variable absboxchar
Default value: !
absboxchar is the character used to draw absolute value signs around expressions
which are more than one line tall.
Example:
(%i1) abs((x^3+1));
! 3 !
(%o1) !x + 1!
Function disp (expr 1, expr 2, . . . )
is like display but only the value of the arguments are displayed rather than equa-
tions. This is useful for complicated arguments which dont have names or where only
the value of the argument is of interest and not the name.
See also ldisp and print.
Example:
(%i1) b[1,2]:x-x^2$
(%i2) x:123$
(%i3) disp(x, b[1,2], sin(1.0));
123
2
x - x
.8414709848078965
(%o3) done
Function display (expr 1, expr 2, . . . )
Displays equations whose left side is expr i unevaluated, and whose right side is the
value of the expression centered on the line. This function is useful in blocks and
for statements in order to have intermediate results displayed. The arguments to
display are usually atoms, subscripted variables, or function calls.
See also ldisplay, disp, and ldisp.
Example:
(%i1) b[1,2]:x-x^2$
(%i2) x:123$
(%i3) display(x, b[1,2], sin(1.0));
x = 123
2
b = x - x
1, 2
sin(1.0) = .8414709848078965
(%o3) done
Chapter 4: Command Line 25
Option variable display2d
Default value: true
When display2d is false, the console display is a string (1-dimensional) form rather
than a display (2-dimensional) form.
See also leftjust to switch between a left justied and a centered display of equa-
tions.
Example:
(%i1) x/(x^2+1);
x
(%o1) ------
2
x + 1
(%i2) display2d:false$
(%i3) x/(x^2+1);
(%o3) x/(x^2+1)
Option variable display format internal
Default value: false
When display_format_internal is true, expressions are displayed without being
transformed in ways that hide the internal mathematical representation. The display
then corresponds to what inpart returns rather than part.
Examples:
User part inpart
a-b; a - b a + (- 1) b
a - 1
a/b; - a b
b
1/2
sqrt(x); sqrt(x) x
4 X 4
X*4/3; --- - X
3 3
Function dispterms (expr)
Displays expr in parts one below the other. That is, rst the operator of expr is
displayed, then each term in a sum, or factor in a product, or part of a more general
expression is displayed separately. This is useful if expr is too large to be otherwise
displayed. For example if P1, P2, . . . are very large expressions then the display
program may run out of storage space in trying to display P1 + P2 + ... all at once.
However, dispterms (P1 + P2 + ...) displays P1, then below it P2, etc. When not
using dispterms, if an exponential expression is too wide to be displayed as A^B it
appears as expt (A, B) (or as ncexpt (A, B) in the case of A^^B).
Example:
26 Maxima 5.30.0 Manual
(%i1) dispterms(2*a*sin(x)+%e^x);
+
2 a sin(x)
x
%e
(%o1) done
Special symbol expt (a, b)
Special symbol ncexpt (a, b)
If an exponential expression is too wide to be displayed as a^b it appears as expt (a,
b) (or as ncexpt (a, b) in the case of a^^b).
expt and ncexpt are not recognized in input.
Option variable exptdispag
Default value: true
When exptdispflag is true, Maxima displays expressions with negative exponents
using quotients. See also %edispflag.
Example:
(%i1) exptdispflag:true;
(%o1) true
(%i2) 10^-x;
1
(%o2) ---
x
10
(%i3) exptdispflag:false;
(%o3) false
(%i4) 10^-x;
- x
(%o4) 10
Function grind (expr)
Option variable grind
The function grind prints expr to the console in a form suitable for input to Maxima.
grind always returns done.
When expr is the name of a function or macro, grind prints the function or macro
denition instead of just the name.
See also string, which returns a string instead of printing its output. grind attempts
to print the expression in a manner which makes it slightly easier to read than the
output of string.
Chapter 4: Command Line 27
When the variable grind is true, the output of string and stringout has the same
format as that of grind; otherwise no attempt is made to specially format the output
of those functions. The default value of the variable grind is false.
grind can also be specied as an argument of playback. When grind is present,
playback prints input expressions in the same format as the grind function. Other-
wise, no attempt is made to specially format input expressions.
grind evaluates its argument.
Examples:
(%i1) aa + 1729;
(%o1) aa + 1729
(%i2) grind (%);
aa+1729$
(%o2) done
(%i3) [aa, 1729, aa + 1729];
(%o3) [aa, 1729, aa + 1729]
(%i4) grind (%);
[aa,1729,aa+1729]$
(%o4) done
(%i5) matrix ([aa, 17], [29, bb]);
[ aa 17 ]
(%o5) [ ]
[ 29 bb ]
(%i6) grind (%);
matrix([aa,17],[29,bb])$
(%o6) done
(%i7) set (aa, 17, 29, bb);
(%o7) {17, 29, aa, bb}
(%i8) grind (%);
{17,29,aa,bb}$
(%o8) done
(%i9) exp (aa / (bb + 17)^29);
aa
-----------
29
(bb + 17)
(%o9) %e
(%i10) grind (%);
%e^(aa/(bb+17)^29)$
(%o10) done
(%i11) expr: expand ((aa + bb)^10);
10 9 2 8 3 7 4 6
(%o11) bb + 10 aa bb + 45 aa bb + 120 aa bb + 210 aa bb
5 5 6 4 7 3 8 2
+ 252 aa bb + 210 aa bb + 120 aa bb + 45 aa bb
9 10
+ 10 aa bb + aa
(%i12) grind (expr);
28 Maxima 5.30.0 Manual
bb^10+10*aa*bb^9+45*aa^2*bb^8+120*aa^3*bb^7+210*aa^4*bb^6
+252*aa^5*bb^5+210*aa^6*bb^4+120*aa^7*bb^3+45*aa^8*bb^2
+10*aa^9*bb+aa^10$
(%o12) done
(%i13) string (expr);
(%o13) bb^10+10*aa*bb^9+45*aa^2*bb^8+120*aa^3*bb^7+210*aa^4*bb^6\
+252*aa^5*bb^5+210*aa^6*bb^4+120*aa^7*bb^3+45*aa^8*bb^2+10*aa^9*\
bb+aa^10
(%i14) cholesky (A):= block ([n : length (A), L : copymatrix (A),
p : makelist (0, i, 1, length (A))], for i thru n do
for j : i thru n do
(x : L[i, j], x : x - sum (L[j, k] * L[i, k], k, 1, i - 1),
if i = j then p[i] : 1 / sqrt(x) else L[j, i] : x * p[i]),
for i thru n do L[i, i] : 1 / p[i],
for i thru n do for j : i + 1 thru n do L[i, j] : 0, L)$
(%i15) grind (cholesky);
cholesky(A):=block(
[n:length(A),L:copymatrix(A),
p:makelist(0,i,1,length(A))],
for i thru n do
(for j from i thru n do
(x:L[i,j],x:x-sum(L[j,k]*L[i,k],k,1,i-1),
if i = j then p[i]:1/sqrt(x)
else L[j,i]:x*p[i])),
for i thru n do L[i,i]:1/p[i],
for i thru n do (for j from i+1 thru n do L[i,j]:0),L)$
(%o15) done
(%i16) string (fundef (cholesky));
(%o16) cholesky(A):=block([n:length(A),L:copymatrix(A),p:makelis\
t(0,i,1,length(A))],for i thru n do (for j from i thru n do (x:L\
[i,j],x:x-sum(L[j,k]*L[i,k],k,1,i-1),if i = j then p[i]:1/sqrt(x\
) else L[j,i]:x*p[i])),for i thru n do L[i,i]:1/p[i],for i thru \
n do (for j from i+1 thru n do L[i,j]:0),L)
Option variable ibase
Default value: 10
ibase is the base for integers read by Maxima.
ibase may be assigned any integer between 2 and 36 (decimal), inclusive. When
ibase is greater than 10, the numerals comprise the decimal numerals 0 through 9
plus letters of the alphabet A, B, C, . . . , as needed to make ibase digits in all. Letters
are interpreted as digits only if the rst digit is 0 through 9. Uppercase and lowercase
letters are not distinguished. The numerals for base 36, the largest acceptable base,
comprise 0 through 9 and A through Z.
Whatever the value of ibase, when an integer is terminated by a decimal point, it is
interpreted in base 10.
See also obase.
Examples:
Chapter 4: Command Line 29
ibase less than 10.
(%i1) ibase : 2 $
(%i2) obase;
(%o2) 10
(%i3) 1111111111111111;
(%o3) 65535
ibase greater than 10. Letters are interpreted as digits only if the rst digit is 0
through 9.
(%i1) ibase : 16 $
(%i2) obase;
(%o2) 10
(%i3) 1000;
(%o3) 4096
(%i4) abcd;
(%o4) abcd
(%i5) symbolp (abcd);
(%o5) true
(%i6) 0abcd;
(%o6) 43981
(%i7) symbolp (0abcd);
(%o7) false
When an integer is terminated by a decimal point, it is interpreted in base 10.
(%i1) ibase : 36 $
(%i2) obase;
(%o2) 10
(%i3) 1234;
(%o3) 49360
(%i4) 1234.;
(%o4) 1234
Function ldisp (expr 1, . . . , expr n)
Displays expressions expr 1, . . . , expr n to the console as printed output. ldisp
assigns an intermediate expression label to each argument and returns the list of
labels.
See also disp, display, and ldisplay.
Examples:
(%i1) e: (a+b)^3;
3
(%o1) (b + a)
(%i2) f: expand (e);
3 2 2 3
(%o2) b + 3 a b + 3 a b + a
(%i3) ldisp (e, f);
3
(%t3) (b + a)
30 Maxima 5.30.0 Manual
3 2 2 3
(%t4) b + 3 a b + 3 a b + a
(%o4) [%t3, %t4]
(%i4) %t3;
3
(%o4) (b + a)
(%i5) %t4;
3 2 2 3
(%o5) b + 3 a b + 3 a b + a
Function ldisplay (expr 1, . . . , expr n)
Displays expressions expr 1, . . . , expr n to the console as printed output. Each
expression is printed as an equation of the form lhs = rhs in which lhs is one of the
arguments of ldisplay and rhs is its value. Typically each argument is a variable.
ldisp assigns an intermediate expression label to each equation and returns the list
of labels.
See also display, disp, and ldisp.
Examples:
(%i1) e: (a+b)^3;
3
(%o1) (b + a)
(%i2) f: expand (e);
3 2 2 3
(%o2) b + 3 a b + 3 a b + a
(%i3) ldisplay (e, f);
3
(%t3) e = (b + a)
3 2 2 3
(%t4) f = b + 3 a b + 3 a b + a
(%o4) [%t3, %t4]
(%i4) %t3;
3
(%o4) e = (b + a)
(%i5) %t4;
3 2 2 3
(%o5) f = b + 3 a b + 3 a b + a
Option variable leftjust
Default value: false
When leftjust is true, equations in 2D-display are drawn left justied rather than
centered.
See also display2d to switch between 1D- and 2D-display.
Example:
Chapter 4: Command Line 31
(%i1) expand((x+1)^3);
3 2
(%o1) x + 3 x + 3 x + 1
(%i2) leftjust:true$
(%i3) expand((x+1)^3);
3 2
(%o3) x + 3 x + 3 x + 1
Option variable linel
Default value: 79
linel is the assumed width (in characters) of the console display for the purpose
of displaying expressions. linel may be assigned any value by the user, although
very small or very large values may be impractical. Text printed by built-in Maxima
functions, such as error messages and the output of describe, is not aected by
linel.
Option variable lispdisp
Default value: false
When lispdisp is true, Lisp symbols are displayed with a leading question mark ?.
Otherwise, Lisp symbols are displayed with no leading mark.
Examples:
(%i1) lispdisp: false$
(%i2) ?foo + ?bar;
(%o2) foo + bar
(%i3) lispdisp: true$
(%i4) ?foo + ?bar;
(%o4) ?foo + ?bar
Option variable negsumdispag
Default value: true
When negsumdispflag is true, x - y displays as x - y instead of as - y + x. Setting
it to false causes the special check in display for the dierence of two expressions
to not be done. One application is that thus a + %i*b and a - %i*b may both be
displayed the same way.
Option variable obase
Default value: 10
obase is the base for integers displayed by Maxima.
obase may be assigned any integer between 2 and 36 (decimal), inclusive. When
obase is greater than 10, the numerals comprise the decimal numerals 0 through 9
plus capital letters of the alphabet A, B, C, . . . , as needed. A leading 0 digit is
displayed if the leading digit is otherwise a letter. The numerals for base 36, the
largest acceptable base, comprise 0 through 9, and A through Z.
See also ibase.
Examples:
32 Maxima 5.30.0 Manual
(%i1) obase : 2;
(%o1) 10
(%i2) 2^8 - 1;
(%o10) 11111111
(%i3) obase : 8;
(%o3) 10
(%i4) 8^8 - 1;
(%o4) 77777777
(%i5) obase : 16;
(%o5) 10
(%i6) 16^8 - 1;
(%o6) 0FFFFFFFF
(%i7) obase : 36;
(%o7) 10
(%i8) 36^8 - 1;
(%o8) 0ZZZZZZZZ
Option variable pfeformat
Default value: false
When pfeformat is true, a ratio of integers is displayed with the solidus (forward
slash) character, and an integer denominator n is displayed as a leading multiplicative
term 1/n.
Examples:
(%i1) pfeformat: false$
(%i2) 2^16/7^3;
65536
(%o2) -----
343
(%i3) (a+b)/8;
b + a
(%o3) -----
8
(%i4) pfeformat: true$
(%i5) 2^16/7^3;
(%o5) 65536/343
(%i6) (a+b)/8;
(%o6) 1/8 (b + a)
Option variable powerdisp
Default value: false
When powerdisp is true, a sum is displayed with its terms in order of increasing
power. Thus a polynomial is displayed as a truncated power series, with the constant
term rst and the highest power last.
By default, terms of a sum are displayed in order of decreasing power.
Example:
Chapter 4: Command Line 33
(%i1) powerdisp:true;
(%o1) true
(%i2) x^2+x^3+x^4;
2 3 4
(%o2) x + x + x
(%i3) powerdisp:false;
(%o3) false
(%i4) x^2+x^3+x^4;
4 3 2
(%o4) x + x + x
Function print (expr 1, . . . , expr n)
Evaluates and displays expr 1, . . . , expr n one after another, from left to right, start-
ing at the left edge of the console display.
The value returned by print is the value of its last argument. print does not generate
intermediate expression labels.
See also display, disp, ldisplay, and ldisp. Those functions display one
expression per line, while print attempts to display two or more expressions per line.
To display the contents of a le, see printfile.
Examples:
(%i1) r: print ("(a+b)^3 is", expand ((a+b)^3), "log (a^10/b) is",
radcan (log (a^10/b)))$
3 2 2 3
(a+b)^3 is b + 3 a b + 3 a b + a log (a^10/b) is
10 log(a) - log(b)
(%i2) r;
(%o2) 10 log(a) - log(b)
(%i3) disp ("(a+b)^3 is", expand ((a+b)^3), "log (a^10/b) is",
radcan (log (a^10/b)))$
(a+b)^3 is
3 2 2 3
b + 3 a b + 3 a b + a
log (a^10/b) is
10 log(a) - log(b)
Option variable sqrtdispag
Default value: true
When sqrtdispflag is false, causes sqrt to display with exponent 1/2.
Option variable stardisp
Default value: false
When stardisp is true, multiplication is displayed with an asterisk * between
operands.
34 Maxima 5.30.0 Manual
Option variable ttyo
Default value: false
When ttyoff is true, output expressions are not displayed. Output expressions are
still computed and assigned labels. See labels.
Text printed by built-in Maxima functions, such as error messages and the output of
describe, is not aected by ttyoff.
Chapter 5: Data Types and Structures 35
5 Data Types and Structures
5.1 Numbers
5.1.1 Introduction to Numbers
Complex numbers
A complex expression is specied in Maxima by adding the real part of the expression
to %i times the imaginary part. Thus the roots of the equation x^2 - 4*x + 13 = 0 are 2
+ 3*%i and 2 - 3*%i. Note that simplication of products of complex expressions can be
eected by expanding the product. Simplication of quotients, roots, and other functions
of complex expressions can usually be accomplished by using the realpart, imagpart,
rectform, polarform, abs, carg functions.
5.1.2 Functions and Variables for Numbers
Function boat (expr)
Converts all numbers and functions of numbers in expr to bigoat numbers. The
number of signicant digits in the resulting bigoats is specied by the global variable
fpprec.
When float2bf is false a warning message is printed when a oating point number
is converted into a bigoat number (since this may lead to loss of precision).
Function boatp (expr)
Returns true if expr is a bigoat number, otherwise false.
Option variable bftorat
Default value: false
bftorat controls the conversion of boats to rational numbers. When bftorat is
false, ratepsilon will be used to control the conversion (this results in relatively
small rational numbers). When bftorat is true, the rational number generated will
accurately represent the boat.
Note: bftorat has no eect on the transformation to rational numbers with the
function rationalize.
Example:
(%i1) ratepsilon:1e-4;
(%o1) 1.e-4
(%i2) rat(bfloat(11111/111111)), bftorat:false;
rat replaced 9.99990999991B-2 by 1/10 = 1.0B-1
1
(%o2)/R/ --
36 Maxima 5.30.0 Manual
10
(%i3) rat(bfloat(11111/111111)), bftorat:true;
rat replaced 9.99990999991B-2 by 11111/111111 = 9.99990999991B-2
11111
(%o3)/R/ ------
111111
Option variable bftrunc
Default value: true
bftrunc causes trailing zeroes in non-zero bigoat numbers not to be displayed. Thus,
if bftrunc is false, bfloat (1) displays as 1.000000000000000B0. Otherwise, this
is displayed as 1.0B0.
Function evenp (expr)
Returns true if expr is an even integer. false is returned in all other cases.
Function oat (expr)
Converts integers, rational numbers and bigoats in expr to oating point numbers. It
is also an evflag, float causes non-integral rational numbers and bigoat numbers
to be converted to oating point.
Option variable oat2bf
Default value: true
When float2bf is false, a warning message is printed when a oating point number
is converted into a bigoat number (since this may lead to loss of precision).
Function oatnump (expr)
Returns true if expr is a oating point number, otherwise false.
Option variable fpprec
Default value: 16
fpprec is the number of signicant digits for arithmetic on bigoat numbers. fpprec
does not aect computations on ordinary oating point numbers.
See also bfloat and fpprintprec.
Option variable fpprintprec
Default value: 0
fpprintprec is the number of digits to print when printing an ordinary oat or
bigoat number.
For ordinary oating point numbers, when fpprintprec has a value between 2 and
16 (inclusive), the number of digits printed is equal to fpprintprec. Otherwise,
fpprintprec is 0, or greater than 16, and the number of digits printed is 16.
Chapter 5: Data Types and Structures 37
For bigoat numbers, when fpprintprec has a value between 2 and fpprec (inclu-
sive), the number of digits printed is equal to fpprintprec. Otherwise, fpprintprec
is 0, or greater than fpprec, and the number of digits printed is equal to fpprec.
fpprintprec cannot be 1.
Function integerp (expr)
Returns true if expr is a literal numeric integer, otherwise false.
integerp returns false if its argument is a symbol, even if the argument is declared
integer.
Examples:
(%i1) integerp (0);
(%o1) true
(%i2) integerp (1);
(%o2) true
(%i3) integerp (-17);
(%o3) true
(%i4) integerp (0.0);
(%o4) false
(%i5) integerp (1.0);
(%o5) false
(%i6) integerp (%pi);
(%o6) false
(%i7) integerp (n);
(%o7) false
(%i8) declare (n, integer);
(%o8) done
(%i9) integerp (n);
(%o9) false
Option variable m1pbranch
Default value: false
m1pbranch is the principal branch for -1 to a power. Quantities such as (-1)^(1/3)
(that is, an "odd" rational exponent) and (-1)^(1/4) (that is, an "even" rational
exponent) are handled as follows:
domain:real
(-1)^(1/3): -1
(-1)^(1/4): (-1)^(1/4)
domain:complex
m1pbranch:false m1pbranch:true
(-1)^(1/3) 1/2+%i*sqrt(3)/2
(-1)^(1/4) sqrt(2)/2+%i*sqrt(2)/2
Function nonnegintegerp (n)
Return true if and only if n >= 0 and n is an integer.
38 Maxima 5.30.0 Manual
Function numberp (expr)
Returns true if expr is a literal integer, rational number, oating point number, or
bigoat, otherwise false.
numberp returns false if its argument is a symbol, even if the argument is a sym-
bolic number such as %pi or %i, or declared to be even, odd, integer, rational,
irrational, real, imaginary, or complex.
Examples:
(%i1) numberp (42);
(%o1) true
(%i2) numberp (-13/19);
(%o2) true
(%i3) numberp (3.14159);
(%o3) true
(%i4) numberp (-1729b-4);
(%o4) true
(%i5) map (numberp, [%e, %pi, %i, %phi, inf, minf]);
(%o5) [false, false, false, false, false, false]
(%i6) declare (a, even, b, odd, c, integer, d, rational,
e, irrational, f, real, g, imaginary, h, complex);
(%o6) done
(%i7) map (numberp, [a, b, c, d, e, f, g, h]);
(%o7) [false, false, false, false, false, false, false, false]
Option variable numer
numer causes some mathematical functions (including exponentiation) with numerical
arguments to be evaluated in oating point. It causes variables in expr which have
been given numerals to be replaced by their values. It also sets the float switch on.
See also %enumer.
Examples:
(%i1) [sqrt(2), sin(1), 1/(1+sqrt(3))];
1
(%o1) [sqrt(2), sin(1), -----------]
sqrt(3) + 1
(%i2) [sqrt(2), sin(1), 1/(1+sqrt(3))],numer;
(%o2) [1.414213562373095, .8414709848078965, .3660254037844387]
Option variable numer pbranch
Default value: false
The option variable numer_pbranch controls the numerical evaluation of the power of
a negative integer, rational, or oating point number. When numer_pbranch is true
and the exponent is a oating point number or the option variable numer is true
too, Maxima evaluates the numerical result using the principal branch. Otherwise a
simplied, but not an evaluated result is returned.
Examples:
Chapter 5: Data Types and Structures 39
(%i1) (-2)^0.75;
(%o1) (-2)^0.75
(%i2) (-2)^0.75,numer_pbranch:true;
(%o2) 1.189207115002721*%i-1.189207115002721
(%i3) (-2)^(3/4);
(%o3) (-1)^(3/4)*2^(3/4)
(%i4) (-2)^(3/4),numer;
(%o4) 1.681792830507429*(-1)^0.75
(%i5) (-2)^(3/4),numer,numer_pbranch:true;
(%o5) 1.189207115002721*%i-1.189207115002721
Function numerval (x 1, expr 1, . . . , var n, expr n)
Declares the variables x_1, . . . , x n to have numeric values equal to expr_1, . . . ,
expr_n. The numeric value is evaluated and substituted for the variable in any
expressions in which the variable occurs if the numer ag is true. See also ev.
The expressions expr_1, . . . , expr_n can be any expressions, not necessarily numeric.
Function oddp (expr)
is true if expr is an odd integer. false is returned in all other cases.
Option variable ratepsilon
Default value: 2.0e-15
ratepsilon is the tolerance used in the conversion of oating point numbers to ra-
tional numbers, when the option variable bftorat has the value false. See bftorat
for an example.
Function rationalize (expr)
Convert all double oats and big oats in the Maxima expression expr to their exact
rational equivalents. If you are not familiar with the binary representation of oating
point numbers, you might be surprised that rationalize (0.1) does not equal 1/10.
This behavior isnt special to Maxima the number 1/10 has a repeating, not a
terminating, binary representation.
(%i1) rationalize (0.5);
1
(%o1) -
2
(%i2) rationalize (0.1);
1
(%o2) --
10
(%i3) fpprec : 5$
40 Maxima 5.30.0 Manual
(%i4) rationalize (0.1b0);
209715
(%o4) -------
2097152
(%i5) fpprec : 20$
(%i6) rationalize (0.1b0);
236118324143482260685
(%o6) ----------------------
2361183241434822606848
(%i7) rationalize (sin (0.1*x + 5.6));
x 28
(%o7) sin(-- + --)
10 5
Example use:
(%i1) unitfrac(r) := block([uf : [], q],
if not(ratnump(r)) then
error("The input to unitfrac must be a rational number"),
while r # 0 do (
uf : cons(q : 1/ceiling(1/r), uf),
r : r - q),
reverse(uf))$
(%i2) unitfrac (9/10);
1 1 1
(%o2) [-, -, --]
2 3 15
(%i3) apply ("+", %);
9
(%o3) --
10
(%i4) unitfrac (-9/10);
1
(%o4) [- 1, --]
10
(%i5) apply ("+", %);
9
(%o5) - --
10
(%i6) unitfrac (36/37);
1 1 1 1 1
(%o6) [-, -, -, --, ----]
2 3 8 69 6808
(%i7) apply ("+", %);
36
(%o7) --
37
Function ratnump (expr)
Returns true if expr is a literal integer or ratio of literal integers, otherwise false.
Chapter 5: Data Types and Structures 41
5.2 Strings
5.2.1 Introduction to Strings
Strings (quoted character sequences) are enclosed in double quote marks " for input, and
displayed with or without the quote marks, depending on the global variable stringdisp.
Strings may contain any characters, including embedded tab, newline, and carriage re-
turn characters. The sequence \" is recognized as a literal double quote, and \\ as a literal
backslash. When backslash appears at the end of a line, the backslash and the line termina-
tion (either newline or carriage return and newline) are ignored, so that the string continues
with the next line. No other special combinations of backslash with another character are
recognized; when backslash appears before any character other than ", \, or a line termi-
nation, the backslash is ignored. There is no way to represent a special character (such as
tab, newline, or carriage return) except by embedding the literal character in the string.
There is no character type in Maxima; a single character is represented as a one-character
string.
The stringproc add-on package contains many functions for working with strings.
Examples:
(%i1) s_1 : "This is a string.";
(%o1) This is a string.
(%i2) s_2 : "Embedded \"double quotes\" and backslash \\ characters.";
(%o2) Embedded "double quotes" and backslash \ characters.
(%i3) s_3 : "Embedded line termination
in this string.";
(%o3) Embedded line termination
in this string.
(%i4) s_4 : "Ignore the \
line termination \
characters in \
this string.";
(%o4) Ignore the line termination characters in this string.
(%i5) stringdisp : false;
(%o5) false
(%i6) s_1;
(%o6) This is a string.
(%i7) stringdisp : true;
(%o7) true
(%i8) s_1;
(%o8) "This is a string."
5.2.2 Functions and Variables for Strings
Function concat (arg 1, arg 2, . . . )
Concatenates its arguments. The arguments must evaluate to atoms. The return
value is a symbol if the rst argument is a symbol and a string otherwise.
concat evaluates its arguments. The single quote prevents evaluation.
42 Maxima 5.30.0 Manual
(%i1) y: 7$
(%i2) z: 88$
(%i3) concat (y, z/2);
(%o3) 744
(%i4) concat (y, z/2);
(%o4) y44
A symbol constructed by concat may be assigned a value and appear in expressions.
The :: (double colon) assignment operator evaluates its left-hand side.
(%i5) a: concat (y, z/2);
(%o5) y44
(%i6) a:: 123;
(%o6) 123
(%i7) y44;
(%o7) 123
(%i8) b^a;
y44
(%o8) b
(%i9) %, numer;
123
(%o9) b
Note that although concat (1, 2) looks like a number, it is a string.
(%i10) concat (1, 2) + 3;
(%o10) 12 + 3
Function sconcat (arg 1, arg 2, . . . )
Concatenates its arguments into a string. Unlike concat, the arguments do not need
to be atoms.
(%i1) sconcat ("xx[", 3, "]:", expand ((x+y)^3));
(%o1) xx[3]:y^3+3*x*y^2+3*x^2*y+x^3
Function string (expr)
Converts expr to Maximas linear notation just as if it had been typed in.
The return value of string is a string, and thus it cannot be used in a computation.
Option variable stringdisp
Default value: false
When stringdisp is true, strings are displayed enclosed in double quote marks.
Otherwise, quote marks are not displayed.
stringdisp is always true when displaying a function denition.
Examples:
(%i1) stringdisp: false$
(%i2) "This is an example string.";
(%o2) This is an example string.
(%i3) foo () :=
print ("This is a string in a function definition.");
Chapter 5: Data Types and Structures 43
(%o3) foo() :=
print("This is a string in a function definition.")
(%i4) stringdisp: true$
(%i5) "This is an example string.";
(%o5) "This is an example string."
44 Maxima 5.30.0 Manual
5.3 Constants
5.3.1 Functions and Variables for Constants
Constant %e
%e represents the base of the natural logarithm, also known as Eulers number. The
numeric value of %e is the double-precision oating-point value 2.718281828459045d0.
Constant %i
%i represents the imaginary unit, sqrt(1).
Constant false
false represents the Boolean constant of the same name. Maxima implements false
by the value NIL in Lisp.
Constant %gamma
The Euler-Mascheroni constant, 0.5772156649015329 ....
Constant ind
ind represents a bounded, indenite result.
See also limit.
Example:
(%i1) limit (sin(1/x), x, 0);
(%o1) ind
Constant inf
inf represents real positive innity.
Constant innity
infinity represents complex innity.
Constant minf
minf represents real minus (i.e., negative) innity.
Constant %phi
%phi represents the so-called golden mean, (1+sqrt(5))/2. The numeric value of %phi
is the double-precision oating-point value 1.618033988749895d0.
fibtophi expresses Fibonacci numbers fib(n) in terms of %phi.
By default, Maxima does not know the algebraic properties of %phi. After evaluat-
ing tellrat(%phi^2 - %phi - 1) and algebraic: true, ratsimp can simplify some
expressions containing %phi.
Examples:
fibtophi expresses Fibonacci numbers fib(n) in terms of %phi.
Chapter 5: Data Types and Structures 45
(%i1) fibtophi (fib (n));
n n
%phi - (1 - %phi)
(%o1) -------------------
2 %phi - 1
(%i2) fib (n-1) + fib (n) - fib (n+1);
(%o2) - fib(n + 1) + fib(n) + fib(n - 1)
(%i3) fibtophi (%);
n + 1 n + 1 n n
%phi - (1 - %phi) %phi - (1 - %phi)
(%o3) - --------------------------- + -------------------
2 %phi - 1 2 %phi - 1
n - 1 n - 1
%phi - (1 - %phi)
+ ---------------------------
2 %phi - 1
(%i4) ratsimp (%);
(%o4) 0
By default, Maxima does not know the algebraic properties of %phi. After evaluat-
ing tellrat (%phi^2 - %phi - 1) and algebraic: true, ratsimp can simplify some
expressions containing %phi.
(%i1) e : expand ((%phi^2 - %phi - 1) * (A + 1));
2 2
(%o1) %phi A - %phi A - A + %phi - %phi - 1
(%i2) ratsimp (e);
2 2
(%o2) (%phi - %phi - 1) A + %phi - %phi - 1
(%i3) tellrat (%phi^2 - %phi - 1);
2
(%o3) [%phi - %phi - 1]
(%i4) algebraic : true;
(%o4) true
(%i5) ratsimp (e);
(%o5) 0
Constant %pi
%pi represents the ratio of the perimeter of a circle to its diameter. The numeric
value of %pi is the double-precision oating-point value 3.141592653589793d0.
Constant true
true represents the Boolean constant of the same name. Maxima implements true
by the value T in Lisp.
Constant und
und represents an undened result.
See also limit.
Example:
46 Maxima 5.30.0 Manual
(%i1) limit (x*sin(x), x, inf);
(%o1) und
Constant zeroa
zeroa represents an innitesimal above zero. zeroa can be used in expressions. limit
simplies expressions which contain innitesimals.
See also zerob and limit.
Example:
limit simplies expressions which contain innitesimals:
(%i1) limit(zeroa);
(%o1) 0
(%i2) limit(x+zeroa);
(%o2) x
Constant zerob
zerob represents an innitesimal below zero. zerob can be used in expressions. limit
simplies expressions which contain innitesimals.
See also zeroa and limit.
Chapter 5: Data Types and Structures 47
5.4 Lists
5.4.1 Introduction to Lists
Lists are the basic building block for Maxima and Lisp. All data types other than arrays,
hash tables, numbers are represented as Lisp lists, These Lisp lists have the form
((MPLUS) $A 2)
to indicate an expression a+2. At Maxima level one would see the inx notation a+2.
Maxima also has lists which are printed as
[1, 2, 7, x+y]
for a list with 4 elements. Internally this corresponds to a Lisp list of the form
((MLIST) 1 2 7 ((MPLUS) $X $Y ))
The ag which denotes the type eld of the Maxima expression is a list itself, since after it
has been through the simplier the list would become
((MLIST SIMP) 1 2 7 ((MPLUS SIMP) $X $Y))
5.4.2 Functions and Variables for Lists
Operator [
Operator ]
[ and ] mark the beginning and end, respectively, of a list.
[ and ] also enclose the subscripts of a list, array, hash array, or array function.
Examples:
(%i1) x: [a, b, c];
(%o1) [a, b, c]
(%i2) x[3];
(%o2) c
(%i3) array (y, fixnum, 3);
(%o3) y
(%i4) y[2]: %pi;
(%o4) %pi
(%i5) y[2];
(%o5) %pi
(%i6) z[foo]: bar;
(%o6) bar
(%i7) z[foo];
(%o7) bar
(%i8) g[k] := 1/(k^2+1);
1
(%o8) g := ------
k 2
k + 1
(%i9) g[10];
1
(%o9) ---
101
48 Maxima 5.30.0 Manual
Function append (list 1, . . . , list n)
Returns a single list of the elements of list 1 followed by the elements of list 2, . . .
append also works on general expressions, e.g. append (f(a,b), f(c,d,e)); yields
f(a,b,c,d,e).
Do example(append); for an example.
Function assoc (key, list, default)
Function assoc (key, list)
This function searches for the key in the left hand side of the input list of the form
[x,y,z,...] where each of the list elements is an expression of a binary operand
and 2 elements. For example x=1, 2^3, [a,b] etc. The key is checked against the
rst operand. assoc returns the second operand if the key is found. If the key is not
found it either returns the default value. default is optional and defaults to false.
Function cons (expr, list)
Returns a new list constructed of the element expr as its rst element, followed by
the elements of list. cons also works on other expressions, e.g. cons(x, f(a,b,c));
-> f(x,a,b,c).
Function copylist (list)
Returns a copy of the list list.
Function create list (form, x 1, list 1, . . . , x n, list n)
Create a list by evaluating form with x 1 bound to each element of list 1, and for
each such binding bind x 2 to each element of list 2, . . . The number of elements in
the result will be the product of the number of elements in each list. Each variable
x i must actually be a symbol it will not be evaluated. The list arguments will be
evaluated once at the beginning of the iteration.
(%i1) create_list (x^i, i, [1, 3, 7]);
3 7
(%o1) [x, x , x ]
With a double iteration:
(%i1) create_list ([i, j], i, [a, b], j, [e, f, h]);
(%o1) [[a, e], [a, f], [a, h], [b, e], [b, f], [b, h]]
Instead of list i two args may be supplied each of which should evaluate to a number.
These will be the inclusive lower and upper bounds for the iteration.
(%i1) create_list ([i, j], i, [1, 2, 3], j, 1, i);
(%o1) [[1, 1], [2, 1], [2, 2], [3, 1], [3, 2], [3, 3]]
Note that the limits or list for the j variable can depend on the current value of i.
Function delete (expr 1, expr 2)
Function delete (expr 1, expr 2, n)
delete(expr 1, expr 2) removes from expr 2 any arguments of its top-level operator
which are the same (as determined by "=") as expr 1. Note that "=" tests for formal
equality, not equivalence. Note also that arguments of subexpressions are not aected.
Chapter 5: Data Types and Structures 49
expr 1 may be an atom or a non-atomic expression. expr 2 may be any non-atomic
expression. delete returns a new expression; it does not modify expr 2.
delete(expr 1, expr 2, n) removes from expr 2 the rst n arguments of the top-level
operator which are the same as expr 1. If there are fewer than n such arguments,
then all such arguments are removed.
Examples:
Removing elements from a list.
(%i1) delete (y, [w, x, y, z, z, y, x, w]);
(%o1) [w, x, z, z, x, w]
Removing terms from a sum.
(%i1) delete (sin(x), x + sin(x) + y);
(%o1) y + x
Removing factors from a product.
(%i1) delete (u - x, (u - w)*(u - x)*(u - y)*(u - z));
(%o1) (u - w) (u - y) (u - z)
Removing arguments from an arbitrary expression.
(%i1) delete (a, foo (a, b, c, d, a));
(%o1) foo(b, c, d)
Limit the number of removed arguments.
(%i1) delete (a, foo (a, b, a, c, d, a), 2);
(%o1) foo(b, c, d, a)
Whether arguments are the same as expr 1 is determined by "=". Arguments which
are equal but not "=" are not removed.
(%i1) [is (equal (0, 0)), is (equal (0, 0.0)), is (equal (0, 0b0))];
rat: replaced 0.0 by 0/1 = 0.0
rat replaced 0.0B0 by 0/1 = 0.0B0
(%o1) [true, true, true]
(%i2) [is (0 = 0), is (0 = 0.0), is (0 = 0b0)];
(%o2) [true, false, false]
(%i3) delete (0, [0, 0.0, 0b0]);
(%o3) [0.0, 0.0b0]
(%i4) is (equal ((x + y)*(x - y), x^2 - y^2));
(%o4) true
(%i5) is ((x + y)*(x - y) = x^2 - y^2);
(%o5) false
(%i6) delete ((x + y)*(x - y), [(x + y)*(x - y), x^2 - y^2]);
2 2
(%o6) [x - y ]
Function eighth (expr)
Returns the 8th item of expression or list expr. See first for more details.
Function endcons (expr, list)
Returns a new list consisting of the elements of list followed by expr. endcons also
works on general expressions, e.g. endcons(x, f(a,b,c)); -> f(a,b,c,x).
50 Maxima 5.30.0 Manual
Function fth (expr)
Returns the 5th item of expression or list expr. See first for more details.
Function rst (expr)
Returns the rst part of expr which may result in the rst element of a list, the
rst row of a matrix, the rst term of a sum, etc. Note that first and its related
functions, rest and last, work on the form of expr which is displayed not the form
which is typed on input. If the variable inflag is set to true however, these functions
will look at the internal form of expr. Note that the simplier re-orders expressions.
Thus first(x+y) will be x if inflag is true and y if inflag is false (first(y+x)
gives the same results). The functions second . . . tenth yield the second through
the tenth part of their input argument.
Function fourth (expr)
Returns the 4th item of expression or list expr. See first for more details.
Function join (l, m)
Creates a new list containing the elements of lists l and m, interspersed. The result
has elements [l[1], m[1], l[2], m[2], ...]. The lists l and m may contain any
type of elements.
If the lists are dierent lengths, join ignores elements of the longer list.
Maxima complains if l or m is not a list.
Examples:
(%i1) L1: [a, sin(b), c!, d - 1];
(%o1) [a, sin(b), c!, d - 1]
(%i2) join (L1, [1, 2, 3, 4]);
(%o2) [a, 1, sin(b), 2, c!, 3, d - 1, 4]
(%i3) join (L1, [aa, bb, cc, dd, ee, ff]);
(%o3) [a, aa, sin(b), bb, c!, cc, d - 1, dd]
Function last (expr)
Returns the last part (term, row, element, etc.) of the expr.
Function length (expr)
Returns (by default) the number of parts in the external (displayed) form of expr.
For lists this is the number of elements, for matrices it is the number of rows, and for
sums it is the number of terms (see dispform ).
The length command is aected by the inflag switch. So, e.g. length(a/(b*c));
gives 2 if inflag is false (Assuming exptdispflag is true), but 3 if inflag is true
(the internal representation is essentially a*b^-1*c^-1).
Chapter 5: Data Types and Structures 51
Option variable listarith
Default value: true
If false causes any arithmetic operations with lists to be suppressed; when true, list-
matrix operations are contagious causing lists to be converted to matrices yielding a
result which is always a matrix. However, list-list operations should return lists.
Function listp (expr)
Returns true if expr is a list else false.
Function makelist ()
Function makelist (expr, n)
Function makelist (expr, i, i max)
Function makelist (expr, i, i 0, i max)
Function makelist (expr, i, i 0, i max, step)
Function makelist (expr, x, list)
The rst form, makelist (), creates an empty list. The second form, makelist
(expr), creates a list with expr as its single element. makelist (expr, n) creates a
list of n elements generated from expr.
The most general form, makelist (expr, i, i 0, i max, step), returns the list of ele-
ments obtained when ev (expr, i=j) is applied to the elements j of the sequence: i 0,
i 0 + step, i 0 + 2*step, ..., with |j| less than or equal to |i max|.
The increment step can be a number (positive or negative) or an expression. If it is
omitted, the default value 1 will be used. If both i 0 and step are omitted, they will
both have a default value of 1.
makelist (expr, x, list) returns a list, the jth element of which is equal to ev
(expr, x=list[j]) for j equal to 1 through length (list).
Examples:
(%i1) makelist (concat (x,i), i, 6);
(%o1) [x1, x2, x3, x4, x5, x6]
(%i2) makelist (x=y, y, [a, b, c]);
(%o2) [x = a, x = b, x = c]
(%i3) makelist (x^2, x, 3, 2*%pi, 2);
(%o3) [9, 25]
(%i4) makelist (random(6), 4);
(%o4) [2, 0, 2, 5]
(%i5) flatten (makelist (makelist (i^2, 3), i, 4));
(%o5) [1, 1, 1, 4, 4, 4, 9, 9, 9, 16, 16, 16]
(%i6) flatten (makelist (makelist (i^2, i, 3), 4));
(%o6) [1, 4, 9, 1, 4, 9, 1, 4, 9, 1, 4, 9]
Function member (expr 1, expr 2)
Returns true if is(expr 1 = a) for some element a in args(expr 2), otherwise returns
false.
expr_2 is typically a list, in which case args(expr 2) = expr 2 and is(expr 1 = a)
for some element a in expr_2 is the test.
52 Maxima 5.30.0 Manual
member does not inspect parts of the arguments of expr_2, so it may return false
even if expr_1 is a part of some argument of expr_2.
See also elementp.
Examples:
(%i1) member (8, [8, 8.0, 8b0]);
(%o1) true
(%i2) member (8, [8.0, 8b0]);
(%o2) false
(%i3) member (b, [a, b, c]);
(%o3) true
(%i4) member (b, [[a, b], [b, c]]);
(%o4) false
(%i5) member ([b, c], [[a, b], [b, c]]);
(%o5) true
(%i6) F (1, 1/2, 1/4, 1/8);
1 1 1
(%o6) F(1, -, -, -)
2 4 8
(%i7) member (1/8, %);
(%o7) true
(%i8) member ("ab", ["aa", "ab", sin(1), a + b]);
(%o8) true
Function ninth (expr)
Returns the 9th item of expression or list expr. See first for more details.
Function pop (list)
pop removes the rst element from the list list and returns this element. list must be
a symbol, which is bound to a list and not the list itself.
If the argument list is not bound to a list or the list is empty, Maxima generates an
error message.
See also push for examples.
To use this function, the additional package "basic" must be loaded rst:
load("basic").
Function push (item, list)
push prepends the item item to the list list and returns a copy of the new list. list
must be a symbol, which is bound to a list and not the list itself. item can be any
Maxima symbol or expression.
If the argument list is not bound to a list, Maxima generates an error message.
See also pop to remove the rst item from a list.
load("basic") loads this function.
Examples:
Chapter 5: Data Types and Structures 53
(%i1) load ("basic")$
(%i2) ll: [];
(%o2) []
(%i3) push (x, ll);
(%o3) [x]
(%i4) push (x^2+y, ll);
2
(%o4) [y + x , x]
(%i5) a: push ("string", ll);
2
(%o5) [string, y + x , x]
(%i6) pop (ll);
(%o6) string
(%i7) pop (ll);
2
(%o7) y + x
(%i8) pop (ll);
(%o8) x
(%i9) ll;
(%o9) []
(%i10) a;
2
(%o10) [string, y + x , x]
Function rest (expr, n)
Function rest (expr)
Returns expr with its rst n elements removed if n is positive and its last - n elements
removed if n is negative. If n is 1 it may be omitted. expr may be a list, matrix, or
other expression.
Function reverse (list)
Reverses the order of the members of the list (not the members themselves). reverse
also works on general expressions, e.g. reverse(a=b); gives b=a.
Function second (expr)
Returns the 2nd item of expression or list expr. See first for more details.
Function seventh (expr)
Returns the 7th item of expression or list expr. See first for more details.
Function sixth (expr)
Returns the 6th item of expression or list expr. See first for more details.
54 Maxima 5.30.0 Manual
Function sort (L, P)
Function sort (L)
sort(L, P) sorts a list L according to a predicate P of two arguments which denes
a strict weak order on the elements of L. If P(a, b) is true, then a appears before b
in the result. If neither P(a, b) nor P(b, a) are true, then a and b are equivalent,
and appear in the result in the same order as in the input. That is, sort is a stable
sort.
If P(a, b) and P(b, a) are both true for some elements of L, then P is not a valid
sort predicate, and the result is undened. If P(a, b) is something other than true
or false, sort signals an error.
The predicate may be specied as the name of a function or binary inx operator, or
as a lambda expression. If specied as the name of an operator, the name must be
enclosed in double quotes.
The sorted list is returned as a new object; the argument L is not modied.
sort(L) is equivalent to sort(L, orderlessp).
The default sorting order is ascending, as determined by orderlessp. The predicate
ordergreatp sorts a list in descending order.
All Maxima atoms and expressions are comparable under orderlessp and
ordergreatp.
Operators < and > order numbers, constants, and constant expressions by magni-
tude. Note that orderlessp and ordergreatp do not order numbers, constants, and
constant expressions by magnitude.
ordermagnitudep orders numbers, constants, and constant expressions the same as
<, and all other elements the same as orderlessp.
Examples:
sort sorts a list according to a predicate of two arguments which denes a strict weak
order on the elements of the list.
(%i1) sort ([1, a, b, 2, 3, c], orderlessp);
(%o1) [1, 2, 3, a, b, c]
(%i2) sort ([1, a, b, 2, 3, c], ordergreatp);
(%o2) [c, b, a, 3, 2, 1]
The predicate may be specied as the name of a function or binary inx operator, or
as a lambda expression. If specied as the name of an operator, the name must be
enclosed in double quotes.
Chapter 5: Data Types and Structures 55
(%i1) L : [[1, x], [3, y], [4, w], [2, z]];
(%o1) [[1, x], [3, y], [4, w], [2, z]]
(%i2) foo (a, b) := a[1] > b[1];
(%o2) foo(a, b) := a > b
1 1
(%i3) sort (L, foo);
(%o3) [[4, w], [3, y], [2, z], [1, x]]
(%i4) infix (">>");
(%o4) >>
(%i5) a >> b := a[1] > b[1];
(%o5) a >> b := a > b
1 1
(%i6) sort (L, ">>");
(%o6) [[4, w], [3, y], [2, z], [1, x]]
(%i7) sort (L, lambda ([a, b], a[1] > b[1]));
(%o7) [[4, w], [3, y], [2, z], [1, x]]
sort(L) is equivalent to sort(L, orderlessp).
(%i1) L : [a, 2*b, -5, 7, 1 + %e, %pi];
(%o1) [a, 2 b, - 5, 7, %e + 1, %pi]
(%i2) sort (L);
(%o2) [- 5, 7, %e + 1, %pi, a, 2 b]
(%i3) sort (L, orderlessp);
(%o3) [- 5, 7, %e + 1, %pi, a, 2 b]
The default sorting order is ascending, as determined by orderlessp. The predicate
ordergreatp sorts a list in descending order.
(%i1) L : [a, 2*b, -5, 7, 1 + %e, %pi];
(%o1) [a, 2 b, - 5, 7, %e + 1, %pi]
(%i2) sort (L);
(%o2) [- 5, 7, %e + 1, %pi, a, 2 b]
(%i3) sort (L, ordergreatp);
(%o3) [2 b, a, %pi, %e + 1, 7, - 5]
All Maxima atoms and expressions are comparable under orderlessp and
ordergreatp.
(%i1) L : [11, -17, 29b0, 9*c, 7.55, foo(x, y), -5/2, b + a];
5
(%o1) [11, - 17, 2.9b1, 9 c, 7.55, foo(x, y), - -, b + a]
2
(%i2) sort (L, orderlessp);
5
(%o2) [- 17, - -, 7.55, 11, 2.9b1, b + a, 9 c, foo(x, y)]
2
(%i3) sort (L, ordergreatp);
5
(%o3) [foo(x, y), 9 c, b + a, 2.9b1, 11, 7.55, - -, - 17]
2
Operators < and > order numbers, constants, and constant expressions by magni-
tude. Note that orderlessp and ordergreatp do not order numbers, constants, and
constant expressions by magnitude.
56 Maxima 5.30.0 Manual
(%i1) L : [%pi, 3, 4, %e, %gamma];
(%o1) [%pi, 3, 4, %e, %gamma]
(%i2) sort (L, ">");
(%o2) [4, %pi, 3, %e, %gamma]
(%i3) sort (L, ordergreatp);
(%o3) [%pi, %gamma, %e, 4, 3]
ordermagnitudep orders numbers, constants, and constant expressions the same as
<, and all other elements the same as orderlessp.
(%i1) L : [%i, 1+%i, 2*x, minf, inf, %e, sin(1), 0, 1, 2, 3, 1.0, 1.0b0];
(%o1) [%i, %i + 1, 2 x, minf, inf, %e, sin(1), 0, 1, 2, 3, 1.0,
1.0b0]
(%i2) sort (L, ordermagnitudep);
(%o2) [minf, 0, sin(1), 1, 1.0, 1.0b0, 2, %e, 3, inf, %i,
%i + 1, 2 x]
(%i3) sort (L, orderlessp);
(%o3) [0, 1, 1.0, 2, 3, %e, %i, %i + 1, inf, minf, sin(1),
1.0b0, 2 x]
Function sublist (list, p)
Returns the list of elements of list for which the predicate p returns true.
Example:
(%i1) L: [1, 2, 3, 4, 5, 6];
(%o1) [1, 2, 3, 4, 5, 6]
(%i2) sublist (L, evenp);
(%o2) [2, 4, 6]
Function sublist indices (L, P)
Returns the indices of the elements x of the list L for which the predicate maybe(P(x))
returns true; this excludes unknown as well as false. P may be the name of a function
or a lambda expression. L must be a literal list.
Examples:
(%i1) sublist_indices ([a, b, b, c, 1, 2, b, 3, b],
lambda ([x], x=b));
(%o1) [2, 3, 7, 9]
(%i2) sublist_indices ([a, b, b, c, 1, 2, b, 3, b], symbolp);
(%o2) [1, 2, 3, 4, 7, 9]
(%i3) sublist_indices ([1 > 0, 1 < 0, 2 < 1, 2 > 1, 2 > 0],
identity);
(%o3) [1, 4, 5]
(%i4) assume (x < -1);
(%o4) [x < - 1]
(%i5) map (maybe, [x > 0, x < 0, x < -2]);
(%o5) [false, true, unknown]
(%i6) sublist_indices ([x > 0, x < 0, x < -2], identity);
(%o6) [2]
Chapter 5: Data Types and Structures 57
Function unique (L)
Returns the unique elements of the list L.
When all the elements of L are unique, unique returns a shallow copy of L, not L
itself.
If L is not a list, unique returns L.
Example:
(%i1) unique ([1, %pi, a + b, 2, 1, %e, %pi, a + b, [1]]);
(%o1) [1, 2, %e, %pi, [1], b + a]
Function tenth (expr)
Returns the 10th item of expression or list expr. See first for more details.
Function third (expr)
Returns the 3rd item of expression or list expr. See first for more details.
58 Maxima 5.30.0 Manual
5.5 Arrays
5.5.1 Functions and Variables for Arrays
Function array (name, dim 1, . . . , dim n)
Function array (name, type, dim 1, . . . , dim n)
Function array ([name 1, . . . , name m], dim 1, . . . , dim n)
Creates an n-dimensional array. n may be less than or equal to 5. The subscripts for
the ith dimension are the integers running from 0 to dim i.
array (name, dim 1, ..., dim n) creates a general array.
array (name, type, dim 1, ..., dim n) creates an array, with elements of a speci-
ed type. type can be fixnum for integers of limited size or flonum for oating-point
numbers.
array ([name 1, ..., name m], dim 1, ..., dim n) creates m arrays, all of the
same dimensions.
If the user assigns to a subscripted variable before declaring the corresponding array,
an undeclared array is created. Undeclared arrays, otherwise known as hashed arrays
(because hash coding is done on the subscripts), are more general than declared
arrays. The user does not declare their maximum size, and they grow dynamically
by hashing as more elements are assigned values. The subscripts of undeclared arrays
need not even be numbers. However, unless an array is rather sparse, it is probably
more ecient to declare it when possible than to leave it undeclared. The array
function can be used to transform an undeclared array into a declared array.
Function arrayapply (A, [i 1, . . . , i n])
Evaluates A [i 1, ..., i n], where A is an array and i 1, . . . , i n are integers.
This is reminiscent of apply, except the rst argument is an array instead of a
function.
Function arrayinfo (A)
Returns information about the array A. The argument A may be a declared array,
an undeclared (hashed) array, an array function, or a subscripted function.
For declared arrays, arrayinfo returns a list comprising the atom declared, the
number of dimensions, and the size of each dimension. The elements of the array,
both bound and unbound, are returned by listarray.
For undeclared arrays (hashed arrays), arrayinfo returns a list comprising the atom
hashed, the number of subscripts, and the subscripts of every element which has a
value. The values are returned by listarray.
For array functions, arrayinfo returns a list comprising the atom hashed, the number
of subscripts, and any subscript values for which there are stored function values. The
stored function values are returned by listarray.
Chapter 5: Data Types and Structures 59
For subscripted functions, arrayinfo returns a list comprising the atom hashed, the
number of subscripts, and any subscript values for which there are lambda expressions.
The lambda expressions are returned by listarray.
See also listarray.
Examples:
arrayinfo and listarray applied to a declared array.
(%i1) array (aa, 2, 3);
(%o1) aa
(%i2) aa [2, 3] : %pi;
(%o2) %pi
(%i3) aa [1, 2] : %e;
(%o3) %e
(%i4) arrayinfo (aa);
(%o4) [declared, 2, [2, 3]]
(%i5) listarray (aa);
(%o5) [#####, #####, #####, #####, #####, #####, %e, #####,
#####, #####, #####, %pi]
arrayinfo and listarray applied to an undeclared (hashed) array.
(%i1) bb [FOO] : (a + b)^2;
2
(%o1) (b + a)
(%i2) bb [BAR] : (c - d)^3;
3
(%o2) (c - d)
(%i3) arrayinfo (bb);
(%o3) [hashed, 1, [BAR], [FOO]]
(%i4) listarray (bb);
3 2
(%o4) [(c - d) , (b + a) ]
arrayinfo and listarray applied to an array function.
(%i1) cc [x, y] := y / x;
y
(%o1) cc := -
x, y x
(%i2) cc [u, v];
v
(%o2) -
u
(%i3) cc [4, z];
z
(%o3) -
4
(%i4) arrayinfo (cc);
(%o4) [hashed, 2, [4, z], [u, v]]
60 Maxima 5.30.0 Manual
(%i5) listarray (cc);
z v
(%o5) [-, -]
4 u
arrayinfo and listarray applied to a subscripted function.
(%i1) dd [x] (y) := y ^ x;
x
(%o1) dd (y) := y
x
(%i2) dd [a + b];
b + a
(%o2) lambda([y], y )
(%i3) dd [v - u];
v - u
(%o3) lambda([y], y )
(%i4) arrayinfo (dd);
(%o4) [hashed, 1, [b + a], [v - u]]
(%i5) listarray (dd);
b + a v - u
(%o5) [lambda([y], y ), lambda([y], y )]
Function arraymake (A, [i 1, . . . , i n])
Returns the expression A[i 1, ..., i n]. The result is an unevaluated array refer-
ence.
arraymake is reminiscent of funmake, except the return value is an unevaluated array
reference instead of an unevaluated function call.
Examples:
(%i1) arraymake (A, [1]);
(%o1) A
1
(%i2) arraymake (A, [k]);
(%o2) A
k
(%i3) arraymake (A, [i, j, 3]);
(%o3) A
i, j, 3
(%i4) array (A, fixnum, 10);
(%o4) A
(%i5) fillarray (A, makelist (i^2, i, 1, 11));
(%o5) A
(%i6) arraymake (A, [5]);
(%o6) A
5
(%i7) %;
(%o7) 36
(%i8) L : [a, b, c, d, e];
(%o8) [a, b, c, d, e]
Chapter 5: Data Types and Structures 61
(%i9) arraymake (L, [n]);
(%o9) L
n
(%i10) %, n = 3;
(%o10) c
(%i11) A2 : make_array (fixnum, 10);
(%o11) {Array: #(0 0 0 0 0 0 0 0 0 0)}
(%i12) fillarray (A2, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
(%o12) {Array: #(1 2 3 4 5 6 7 8 9 10)}
(%i13) arraymake (A2, [8]);
(%o13) A2
8
(%i14) %;
(%o14) 9
System variable arrays
Default value: []
arrays is a list of arrays that have been allocated. These comprise arrays declared
by array, hashed arrays constructed by implicit denition (assigning something to
an array element), and array functions dened by := and define. Arrays dened by
make_array are not included.
See also array, arrayapply, arrayinfo, arraymake, fillarray, listarray,
and rearray.
Examples:
(%i1) array (aa, 5, 7);
(%o1) aa
(%i2) bb [FOO] : (a + b)^2;
2
(%o2) (b + a)
(%i3) cc [x] := x/100;
x
(%o3) cc := ---
x 100
(%i4) dd : make_array (any, 7);
(%o4) {Array: #(NIL NIL NIL NIL NIL NIL NIL)}
(%i5) arrays;
(%o5) [aa, bb, cc]
Function arraysetapply (A, [i 1, . . . , i n], x)
Assigns x to A[i 1, ..., i n], where A is an array and i 1, . . . , i n are integers.
arraysetapply evaluates its arguments.
Function llarray (A, B)
Fills array A from B, which is a list or an array.
62 Maxima 5.30.0 Manual
If a specic type was declared for A when it was created, it can only be lled with
elements of that same type; it is an error if an attempt is made to copy an element
of a dierent type.
If the dimensions of the arrays A and B are dierent, A is lled in row-major order.
If there are not enough elements in B the last element is used to ll out the rest of
A. If there are too many, the remaining ones are ignored.
fillarray returns its rst argument.
Examples:
Create an array of 9 elements and ll it from a list.
(%i1) array (a1, fixnum, 8);
(%o1) a1
(%i2) listarray (a1);
(%o2) [0, 0, 0, 0, 0, 0, 0, 0, 0]
(%i3) fillarray (a1, [1, 2, 3, 4, 5, 6, 7, 8, 9]);
(%o3) a1
(%i4) listarray (a1);
(%o4) [1, 2, 3, 4, 5, 6, 7, 8, 9]
When there are too few elements to ll the array, the last element is repeated. When
there are too many elements, the extra elements are ignored.
(%i1) a2 : make_array (fixnum, 8);
(%o1) {Array: #(0 0 0 0 0 0 0 0)}
(%i2) fillarray (a2, [1, 2, 3, 4, 5]);
(%o2) {Array: #(1 2 3 4 5 5 5 5)}
(%i3) fillarray (a2, [4]);
(%o3) {Array: #(4 4 4 4 4 4 4 4)}
(%i4) fillarray (a2, makelist (i, i, 1, 100));
(%o4) {Array: #(1 2 3 4 5 6 7 8)}
Multple-dimension arrays are lled in row-major order.
(%i1) a3 : make_array (fixnum, 2, 5);
(%o1) {Array: #2A((0 0 0 0 0) (0 0 0 0 0))}
(%i2) fillarray (a3, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
(%o2) {Array: #2A((1 2 3 4 5) (6 7 8 9 10))}
(%i3) a4 : make_array (fixnum, 5, 2);
(%o3) {Array: #2A((0 0) (0 0) (0 0) (0 0) (0 0))}
(%i4) fillarray (a4, a3);
(%o4) {Array: #2A((1 2) (3 4) (5 6) (7 8) (9 10))}
Function listarray (A)
Returns a list of the elements of the array A. The argument A may be a declared
array, an undeclared (hashed) array, an array function, or a subscripted function.
Elements are listed in row-major order. That is, elements are sorted according to the
rst index, then according to the second index, and so on. The sorting order of index
values is the same as the order established by orderless.
For undeclared arrays, array functions, and subscripted functions, the elements cor-
respond to the index values returned by arrayinfo.
Chapter 5: Data Types and Structures 63
Unbound elements of declared general arrays (that is, not fixnum and not flonum)
are returned as #####. Unbound elements of declared fixnum or flonum arrays are
returned as 0 or 0.0, respectively. Unbound elements of undeclared arrays, array
functions, and subscripted functions are not returned.
Examples:
listarray and arrayinfo applied to a declared array.
(%i1) array (aa, 2, 3);
(%o1) aa
(%i2) aa [2, 3] : %pi;
(%o2) %pi
(%i3) aa [1, 2] : %e;
(%o3) %e
(%i4) listarray (aa);
(%o4) [#####, #####, #####, #####, #####, #####, %e, #####,
#####, #####, #####, %pi]
(%i5) arrayinfo (aa);
(%o5) [declared, 2, [2, 3]]
listarray and arrayinfo applied to an undeclared (hashed) array.
(%i1) bb [FOO] : (a + b)^2;
2
(%o1) (b + a)
(%i2) bb [BAR] : (c - d)^3;
3
(%o2) (c - d)
(%i3) listarray (bb);
3 2
(%o3) [(c - d) , (b + a) ]
(%i4) arrayinfo (bb);
(%o4) [hashed, 1, [BAR], [FOO]]
listarray and arrayinfo applied to an array function.
(%i1) cc [x, y] := y / x;
y
(%o1) cc := -
x, y x
(%i2) cc [u, v];
v
(%o2) -
u
(%i3) cc [4, z];
z
(%o3) -
4
(%i4) listarray (cc);
z v
(%o4) [-, -]
4 u
64 Maxima 5.30.0 Manual
(%i5) arrayinfo (cc);
(%o5) [hashed, 2, [4, z], [u, v]]
listarray and arrayinfo applied to a subscripted function.
(%i1) dd [x] (y) := y ^ x;
x
(%o1) dd (y) := y
x
(%i2) dd [a + b];
b + a
(%o2) lambda([y], y )
(%i3) dd [v - u];
v - u
(%o3) lambda([y], y )
(%i4) listarray (dd);
b + a v - u
(%o4) [lambda([y], y ), lambda([y], y )]
(%i5) arrayinfo (dd);
(%o5) [hashed, 1, [b + a], [v - u]]
Function make array (type, dim 1, . . . , dim n)
Creates and returns a Lisp array. type may be any, flonum, fixnum, hashed or
functional. There are n indices, and the ith index runs from 0 to dim i 1.
The advantage of make_array over array is that the return value doesnt have a
name, and once a pointer to it goes away, it will also go away. For example, if y:
make_array (...) then y points to an object which takes up space, but after y:
false, y no longer points to that object, so the object can be garbage collected.
Examples:
(%i1) A1 : make_array (fixnum, 10);
(%o1) {Array: #(0 0 0 0 0 0 0 0 0 0)}
(%i2) A1 [8] : 1729;
(%o2) 1729
(%i3) A1;
(%o3) {Array: #(0 0 0 0 0 0 0 0 1729 0)}
(%i4) A2 : make_array (flonum, 10);
(%o4) {Array: #(0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0)}
(%i5) A2 [2] : 2.718281828;
(%o5) 2.718281828
(%i6) A2;
(%o6)
{Array: #(0.0 0.0 2.718281828 0.0 0.0 0.0 0.0 0.0 0.0 0.0)}
(%i7) A3 : make_array (any, 10);
(%o7) {Array: #(NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL)}
(%i8) A3 [4] : x - y - z;
(%o8) - z - y + x
Chapter 5: Data Types and Structures 65
(%i9) A3;
(%o9) {Array: #(NIL NIL NIL NIL ((MPLUS SIMP) $X ((MTIMES SIMP)\
-1 $Y) ((MTIMES SIMP) -1 $Z))
NIL NIL NIL NIL NIL)}
(%i10) A4 : make_array (fixnum, 2, 3, 5);
(%o10) {Array: #3A(((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)))}
(%i11) fillarray (A4, makelist (i, i, 1, 2*3*5));
(%o11) {Array: #3A(((1 2 3 4 5) (6 7 8 9 10) (11 12 13 14 15))
((16 17 18 19 20) (21 22 23 24 25) (26 27 28 29 30)))}
(%i12) A4 [0, 2, 1];
(%o12) 12
Function rearray (A, dim 1, . . . , dim n)
Changes the dimensions of an array. The new array will be lled with the elements of
the old one in row-major order. If the old array was too small, the remaining elements
are lled with false, 0.0 or 0, depending on the type of the array. The type of the
array cannot be changed.
Function remarray (A 1, . . . , A n)
Function remarray (all)
Removes arrays and array associated functions and frees the storage occupied. The
arguments may be declared arrays, undeclared (hashed) arrays, array functions, and
subscripted functions.
remarray (all) removes all items in the global list arrays.
It may be necessary to use this function if it is desired to redene the values in a
hashed array.
remarray returns the list of arrays removed.
remarray quotes its arguments.
Function subvar (x, i)
Evaluates the subscripted expression x[i].
subvar evaluates its arguments.
arraymake (x, [i] constructs the expression x[i], but does not evaluate it.
Examples:
(%i1) x : foo $
(%i2) i : 3 $
(%i3) subvar (x, i);
(%o3) foo
3
(%i4) foo : [aa, bb, cc, dd, ee]$
(%i5) subvar (x, i);
(%o5) cc
66 Maxima 5.30.0 Manual
(%i6) arraymake (x, [i]);
(%o6) foo
3
(%i7) %;
(%o7) cc
Function subvarp (expr)
Returns true if expr is a subscripted variable, for example a[i].
Option variable use fast arrays
If true then only two types of arrays are recognized:
1. The art-q array (t in Common Lisp) which may have several dimensions indexed
by integers, and may hold any Lisp or Maxima object as an entry. To construct
such an array, enter a:make_array(any,3,4); then a will have as value, an array
with twelve slots, and the indexing is zero based.
2. The Hash table array which is the default type of array created if one does
b[x+1]:y^2 (and b is not already an array, a list, or a matrix if it were one
of these an error would be caused since x+1 would not be a valid subscript for
an art-q array, a list or a matrix). Its indices (also known as keys) may be
any object. It only takes one key at a time (b[x+1,u]:y would ignore the u).
Referencing is done by b[x+1] ==> y^2. Of course the key may be a list, e.g.
b[[x+1,u]]:y would be valid. This is incompatible with the old Maxima hash
arrays, but saves consing.
An advantage of storing the arrays as values of the symbol is that the usual conven-
tions about local variables of a function apply to arrays as well. The Hash table type
also uses less consing and is more ecient than the old type of Maxima hashar. To
obtain consistent behaviour in translated and compiled code set translate_fast_
arrays to be true.
Chapter 5: Data Types and Structures 67
5.6 Structures
5.6.1 Introduction to Structures
Maxima provides a simple data aggregate called a structure. A structure is an expression
in which arguments are identied by name (the eld name) and the expression as a whole
is identied by its operator (the structure name). A eld value can be any expression.
A structure is dened by the defstruct function; the global variable structures is
the list of user-dened structures. The function new creates instances of structures. The
@ operator refers to elds. kill(S) removes the structure denition S, and kill(x@ a)
unbinds the eld a of the structure instance x.
In the pretty-printing console display (with display2d equal to true), structure in-
stances are displayed with the value of each eld represented as an equation, with the eld
name on the left-hand side and the value on the right-hand side. (The equation is only a
display construct; only the value is actually stored.) In 1-dimensional display (via grind or
with display2d equal to false), structure instances are displayed without the eld names.
There is no way to use a eld name as a function name, although a eld value can be
a lambda expression. Nor can the values of elds be restricted to certain types; any eld
can be assigned any kind of expression. There is no way to make some elds accessible or
inaccessible in dierent contexts; all elds are always visible.
5.6.2 Functions and Variables for Structures
Global variable structures
structures is the list of user-dened structures dened by defstruct.
Function defstruct (S(a 1, . . . , a n))
Function defstruct (S(a 1 = v 1, . . . , a n = v n))
Dene a structure, which is a list of named elds a 1, . . . , a n associated with a
symbol S. An instance of a structure is just an expression which has operator S and
exactly n arguments. new(S) creates a new instance of structure S.
An argument which is just a symbol a species the name of a eld. An argument
which is an equation a = v species the eld name a and its default value v. The
default value can be any expression.
defstruct puts S on the list of user-dened structures, structures.
kill(S) removes S from the list of user-dened structures, and removes the structure
denition.
Examples:
(%i1) defstruct (foo (a, b, c));
(%o1) [foo(a, b, c)]
(%i2) structures;
(%o2) [foo(a, b, c)]
(%i3) new (foo);
(%o3) foo(a, b, c)
68 Maxima 5.30.0 Manual
(%i4) defstruct (bar (v, w, x = 123, y = %pi));
(%o4) [bar(v, w, x = 123, y = %pi)]
(%i5) structures;
(%o5) [foo(a, b, c), bar(v, w, x = 123, y = %pi)]
(%i6) new (bar);
(%o6) bar(v, w, x = 123, y = %pi)
(%i7) kill (foo);
(%o7) done
(%i8) structures;
(%o8) [bar(v, w, x = 123, y = %pi)]
Function new (S)
Function new (S (v 1, . . . , v n))
new creates new instances of structures.
new(S) creates a new instance of structure S in which each eld is assigned its default
value, if any, or no value at all if no default was specied in the structure denition.
new(S(v 1, ..., v n)) creates a new instance of S in which elds are assigned the
values v 1, . . . , v n.
Examples:
(%i1) defstruct (foo (w, x = %e, y = 42, z));
(%o1) [foo(w, x = %e, y = 42, z)]
(%i2) new (foo);
(%o2) foo(w, x = %e, y = 42, z)
(%i3) new (foo (1, 2, 4, 8));
(%o3) foo(w = 1, x = 2, y = 4, z = 8)
Operator @
@ is the structure eld access operator. The expression x@ a refers to the value of
eld a of the structure instance x. The eld name is not evaluated.
If the eld a in x has not been assigned a value, x@ a evaluates to itself.
kill(x@ a) removes the value of eld a in x.
Examples:
(%i1) defstruct (foo (x, y, z));
(%o1) [foo(x, y, z)]
(%i2) u : new (foo (123, a - b, %pi));
(%o2) foo(x = 123, y = a - b, z = %pi)
(%i3) u@z;
(%o3) %pi
(%i4) u@z : %e;
(%o4) %e
(%i5) u;
(%o5) foo(x = 123, y = a - b, z = %e)
(%i6) kill (u@z);
(%o6) done
(%i7) u;
(%o7) foo(x = 123, y = a - b, z)
Chapter 5: Data Types and Structures 69
(%i8) u@z;
(%o8) u@z
The eld name is not evaluated.
(%i1) defstruct (bar (g, h));
(%o1) [bar(g, h)]
(%i2) x : new (bar);
(%o2) bar(g, h)
(%i3) x@h : 42;
(%o3) 42
(%i4) h : 123;
(%o4) 123
(%i5) x@h;
(%o5) 42
(%i6) x@h : 19;
(%o6) 19
(%i7) x;
(%o7) bar(g, h = 19)
(%i8) h;
(%o8) 123
70 Maxima 5.30.0 Manual
Chapter 6: Expressions 71
6 Expressions
6.1 Introduction to Expressions
There are a number of reserved words which should not be used as variable names. Their
use would cause a possibly cryptic syntax error.
integrate next from diff
in at limit sum
for and elseif then
else do or if
unless product while thru
step
Most things in Maxima are expressions. A sequence of expressions can be made into an
expression by separating them by commas and putting parentheses around them. This is
similar to the C comma expression.
(%i1) x: 3$
(%i2) (x: x+1, x: x^2);
(%o2) 16
(%i3) (if (x > 17) then 2 else 4);
(%o3) 4
(%i4) (if (x > 17) then x: 2 else y: 4, y+x);
(%o4) 20
Even loops in Maxima are expressions, although the value they return is the not too
useful done.
(%i1) y: (x: 1, for i from 1 thru 10 do (x: x*i))$
(%i2) y;
(%o2) done
Whereas what you really want is probably to include a third term in the comma expres-
sion which actually gives back the value.
(%i3) y: (x: 1, for i from 1 thru 10 do (x: x*i), x)$
(%i4) y;
(%o4) 3628800
6.2 Nouns and Verbs
Maxima distinguishes between operators which are "nouns" and operators which are
"verbs". A verb is an operator which can be executed. A noun is an operator which
appears as a symbol in an expression, without being executed. By default, function names
are verbs. A verb can be changed into a noun by quoting the function name or applying the
nounify function. A noun can be changed into a verb by applying the verbify function.
The evaluation ag nouns causes ev to evaluate nouns in an expression.
The verb form is distinguished by a leading dollar sign $ on the corresponding Lisp
symbol. In contrast, the noun form is distinguished by a leading percent sign % on the
corresponding Lisp symbol. Some nouns have special display properties, such as integrate
and derivative (returned by diff ), but most do not. By default, the noun and verb
72 Maxima 5.30.0 Manual
forms of a function are identical when displayed. The global ag noundisp causes Maxima
to display nouns with a leading quote mark .
See also noun, nouns, nounify, and verbify.
Examples:
(%i1) foo (x) := x^2;
2
(%o1) foo(x) := x
(%i2) foo (42);
(%o2) 1764
(%i3) foo (42);
(%o3) foo(42)
(%i4) foo (42), nouns;
(%o4) 1764
(%i5) declare (bar, noun);
(%o5) done
(%i6) bar (x) := x/17;
x
(%o6) bar(x) := --
17
(%i7) bar (52);
(%o7) bar(52)
(%i8) bar (52), nouns;
52
(%o8) --
17
(%i9) integrate (1/x, x, 1, 42);
(%o9) log(42)
(%i10) integrate (1/x, x, 1, 42);
42
/
[ 1
(%o10) I - dx
] x
/
1
(%i11) ev (%, nouns);
(%o11) log(42)
6.3 Identiers
Maxima identiers may comprise alphabetic characters, plus the numerals 0 through 9,
plus any special character preceded by the backslash \ character.
A numeral may be the rst character of an identier if it is preceded by a backslash.
Numerals which are the second or later characters need not be preceded by a backslash.
Characters may be declared alphabetic by the declare function. If so declared, they
need not be preceded by a backslash in an identier. The alphabetic characters are initially
A through Z, a through z, %, and _.
Chapter 6: Expressions 73
Maxima is case-sensitive. The identiers foo, FOO, and Foo are distinct. See Section 37.1
[Lisp and Maxima], page 581 for more on this point.
A Maxima identier is a Lisp symbol which begins with a dollar sign $. Any other Lisp
symbol is preceded by a question mark ? when it appears in Maxima. See Section 37.1 [Lisp
and Maxima], page 581 for more on this point.
Examples:
(%i1) %an_ordinary_identifier42;
(%o1) %an_ordinary_identifier42
(%i2) embedded\ spaces\ in\ an\ identifier;
(%o2) embedded spaces in an identifier
(%i3) symbolp (%);
(%o3) true
(%i4) [foo+bar, foo\+bar];
(%o4) [foo + bar, foo+bar]
(%i5) [1729, \1729];
(%o5) [1729, 1729]
(%i6) [symbolp (foo\+bar), symbolp (\1729)];
(%o6) [true, true]
(%i7) [is (foo\+bar = foo+bar), is (\1729 = 1729)];
(%o7) [false, false]
(%i8) baz\~quux;
(%o8) baz~quux
(%i9) declare ("~", alphabetic);
(%o9) done
(%i10) baz~quux;
(%o10) baz~quux
(%i11) [is (foo = FOO), is (FOO = Foo), is (Foo = foo)];
(%o11) [false, false, false]
(%i12) :lisp (defvar *my-lisp-variable* $foo)
*MY-LISP-VARIABLE*
(%i12) ?\*my\-lisp\-variable\*;
(%o12) foo
6.4 Inequality
Maxima has the inequality operators <, <=, >=, >, #, and notequal. See if for a
description of conditional expressions.
6.5 Functions and Variables for Expressions
Function alias (new name 1, old name 1, . . . , new name n, old name n)
provides an alternate name for a (user or system) function, variable, array, etc. Any
even number of arguments may be used.
System variable aliases
Default value: []
74 Maxima 5.30.0 Manual
aliases is the list of atoms which have a user dened alias (set up by the alias,
ordergreat, orderless functions or by declaring the atom a noun with declare.
)
Keyword allbut
works with the part commands (i.e. part, inpart, substpart, substinpart,
dpart, and lpart ). For example,
(%i1) expr : e + d + c + b + a;
(%o1) e + d + c + b + a
(%i2) part (expr, [2, 5]);
(%o2) d + a
while
(%i1) expr : e + d + c + b + a;
(%o1) e + d + c + b + a
(%i2) part (expr, allbut (2, 5));
(%o2) e + c + b
allbut is also recognized by kill.
(%i1) [aa : 11, bb : 22, cc : 33, dd : 44, ee : 55];
(%o1) [11, 22, 33, 44, 55]
(%i2) kill (allbut (cc, dd));
(%o0) done
(%i1) [aa, bb, cc, dd];
(%o1) [aa, bb, 33, 44]
kill(allbut(a 1, a 2, ...)) has the eect of kill(all) except that it does not
kill the symbols a 1, a 2, . . .
Function args (expr)
Returns the list of arguments of expr, which may be any kind of expression other than
an atom. Only the arguments of the top-level operator are extracted; subexpressions
of expr appear as elements or subexpressions of elements of the list of arguments.
The order of the items in the list may depend on the global ag inflag.
args (expr) is equivalent to substpart ("[", expr, 0). See also substpart, and
op.
Function atom (expr)
Returns true if expr is atomic (i.e. a number, name or string) else false. Thus
atom(5) is true while atom(a[1]) and atom(sin(x)) are false (assuming a[1]
and x are unbound).
Function box (expr)
Function box (expr, a)
Returns expr enclosed in a box. The return value is an expression with box as the
operator and expr as the argument. A box is drawn on the display when display2d
is true.
Chapter 6: Expressions 75
box (expr, a) encloses expr in a box labelled by the symbol a. The label is truncated
if it is longer than the width of the box.
box evaluates its argument. However, a boxed expression does not evaluate to its
content, so boxed expressions are eectively excluded from computations.
boxchar is the character used to draw the box in box and in the dpart and lpart
functions.
Examples:
(%i1) box (a^2 + b^2);
"""""""""
" 2 2"
(%o1) "b + a "
"""""""""
(%i2) a : 1234;
(%o2) 1234
(%i3) b : c - d;
(%o3) c - d
(%i4) box (a^2 + b^2);
""""""""""""""""""""
" 2 "
(%o4) "(c - d) + 1522756"
""""""""""""""""""""
(%i5) box (a^2 + b^2, term_1);
term_1""""""""""""""
" 2 "
(%o5) "(c - d) + 1522756"
""""""""""""""""""""
(%i6) 1729 - box (1729);
""""""
(%o6) 1729 - "1729"
""""""
(%i7) boxchar: "-";
(%o7) -
(%i8) box (sin(x) + cos(y));
-----------------
(%o8) -cos(y) + sin(x)-
-----------------
Option variable boxchar
Default value: "
boxchar is the character used to draw the box in the box and in the dpart and
lpart functions.
All boxes in an expression are drawn with the current value of boxchar; the drawing
character is not stored with the box expression.
Function collapse (expr)
Collapses expr by causing all of its common (i.e., equal) subexpressions to share (i.e.,
use the same cells), thereby saving space. (collapse is a subroutine used by the
76 Maxima 5.30.0 Manual
optimize command.) Thus, calling collapse may be useful after loading in a save
le. You can collapse several expressions together by using collapse ([expr 1, ...,
expr n]). Similarly, you can collapse the elements of the array A by doing collapse
(listarray (A)).
Function disolate (expr, x 1, . . . , x n)
is similar to isolate (expr, x) except that it enables the user to isolate more than
one variable simultaneously. This might be useful, for example, if one were at-
tempting to change variables in a multiple integration, and that variable change
involved two or more of the integration variables. This function is autoloaded from
simplification/disol.mac. A demo is available by demo("disol")$.
Function dispform (expr)
Function dispform (expr, all)
Returns the external representation of expr.
dispform(expr) returns the external representation with respect to the main (top-
level) operator. dispform(expr, all) returns the external representation with re-
spect to all operators in expr.
See also part, inpart, and inflag.
Examples:
The internal representation of - x is "negative one times x" while the external repre-
sentation is "minus x".
(%i1) - x;
(%o1) - x
(%i2) ?format (true, "~S~%", %);
((MTIMES SIMP) -1 $X)
(%o2) false
(%i3) dispform (- x);
(%o3) - x
(%i4) ?format (true, "~S~%", %);
((MMINUS SIMP) $X)
(%o4) false
The internal representation of sqrt(x) is "x to the power 1/2" while the external
representation is "square root of x".
(%i1) sqrt (x);
(%o1) sqrt(x)
(%i2) ?format (true, "~S~%", %);
((MEXPT SIMP) $X ((RAT SIMP) 1 2))
(%o2) false
(%i3) dispform (sqrt (x));
(%o3) sqrt(x)
(%i4) ?format (true, "~S~%", %);
((%SQRT SIMP) $X)
(%o4) false
Use of the optional argument all.
Chapter 6: Expressions 77
(%i1) expr : sin (sqrt (x));
(%o1) sin(sqrt(x))
(%i2) freeof (sqrt, expr);
(%o2) true
(%i3) freeof (sqrt, dispform (expr));
(%o3) true
(%i4) freeof (sqrt, dispform (expr, all));
(%o4) false
Function dpart (expr, n 1, . . . , n k)
Selects the same subexpression as part, but instead of just returning that subex-
pression as its value, it returns the whole expression with the selected subexpression
displayed inside a box. The box is actually part of the expression.
(%i1) dpart (x+y/z^2, 1, 2, 1);
y
(%o1) ---- + x
2
"""
"z"
"""
Option variable exptisolate
Default value: false
exptisolate, when true, causes isolate (expr, var) to examine exponents of
atoms (such as %e) which contain var.
Option variable exptsubst
Default value: false
exptsubst, when true, permits substitutions such as y for %e^x in %e^(a x).
Function freeof (x 1, . . . , x n, expr)
freeof (x 1, expr) returns true if no subexpression of expr is equal to x 1 or if x 1
occurs only as a dummy variable in expr, or if x 1 is neither the noun nor verb form
of any operator in expr, and returns false otherwise.
freeof (x 1, ..., x n, expr) is equivalent to freeof (x 1, expr) and ... and
freeof (x n, expr).
The arguments x 1, . . . , x n may be names of functions and variables, subscripted
names, operators (enclosed in double quotes), or general expressions. freeof evalu-
ates its arguments.
freeof operates only on expr as it stands (after simplication and evaluation) and
does not attempt to determine if some equivalent expression would give a dierent
result. In particular, simplication may yield an equivalent but dierent expression
which comprises some dierent elements than the original form of expr.
78 Maxima 5.30.0 Manual
A variable is a dummy variable in an expression if it has no binding outside of the
expression. Dummy variables recognized by freeof are the index of a sum or product,
the limit variable in limit, the integration variable in the denite integral form of
integrate , the original variable in laplace, formal variables in at expressions,
and arguments in lambda expressions.
The indenite form of integrate is not free of its variable of integration.
Examples:
Arguments are names of functions, variables, subscripted names, operators, and ex-
pressions. freeof (a, b, expr) is equivalent to freeof (a, expr) and freeof (b,
expr).
(%i1) expr: z^3 * cos (a[1]) * b^(c+d);
d + c 3
(%o1) cos(a ) b z
1
(%i2) freeof (z, expr);
(%o2) false
(%i3) freeof (cos, expr);
(%o3) false
(%i4) freeof (a[1], expr);
(%o4) false
(%i5) freeof (cos (a[1]), expr);
(%o5) false
(%i6) freeof (b^(c+d), expr);
(%o6) false
(%i7) freeof ("^", expr);
(%o7) false
(%i8) freeof (w, sin, a[2], sin (a[2]), b*(c+d), expr);
(%o8) true
freeof evaluates its arguments.
(%i1) expr: (a+b)^5$
(%i2) c: a$
(%i3) freeof (c, expr);
(%o3) false
freeof does not consider equivalent expressions. Simplication may yield an equiv-
alent but dierent expression.
(%i1) expr: (a+b)^5$
(%i2) expand (expr);
5 4 2 3 3 2 4 5
(%o2) b + 5 a b + 10 a b + 10 a b + 5 a b + a
(%i3) freeof (a+b, %);
(%o3) true
(%i4) freeof (a+b, expr);
(%o4) false
(%i5) exp (x);
x
(%o5) %e
(%i6) freeof (exp, exp (x));
Chapter 6: Expressions 79
(%o6) true
A summation or denite integral is free of its dummy variable. An indenite integral
is not free of its variable of integration.
(%i1) freeof (i, sum (f(i), i, 0, n));
(%o1) true
(%i2) freeof (x, integrate (x^2, x, 0, 1));
(%o2) true
(%i3) freeof (x, integrate (x^2, x));
(%o3) false
Option variable inag
Default value: false
When inflag is true, functions for part extraction inspect the internal form of expr.
Note that the simplier re-orders expressions. Thus first (x + y) returns x if inflag
is true and y if inflag is false. (first (y + x) gives the same results.)
Also, setting inflag to true and calling part or substpart is the same as calling
inpart or substinpart.
Functions aected by the setting of inflag are: part, substpart, first, rest,
last, length, the for . . . in construct, map, fullmap, maplist, reveal and
pickapart.
Function inpart (expr, n 1, . . . , n k)
is similar to part but works on the internal representation of the expression rather
than the displayed form and thus may be faster since no formatting is done. Care
should be taken with respect to the order of subexpressions in sums and products
(since the order of variables in the internal form is often dierent from that in the
displayed form) and in dealing with unary minus, subtraction, and division (since
these operators are removed from the expression). part (x+y, 0) or inpart (x+y,
0) yield +, though in order to refer to the operator it must be enclosed in "s. For
example ... if inpart (%o9,0) = "+" then ....
Examples:
(%i1) x + y + w*z;
(%o1) w z + y + x
(%i2) inpart (%, 3, 2);
(%o2) z
(%i3) part (%th (2), 1, 2);
(%o3) z
(%i4) limit (f(x)^g(x+1), x, 0, minus);
g(x + 1)
(%o4) limit f(x)
x -> 0-
(%i5) inpart (%, 1, 2);
(%o5) g(x + 1)
80 Maxima 5.30.0 Manual
Function isolate (expr, x)
Returns expr with subexpressions which are sums and which do not contain var
replaced by intermediate expression labels (these being atomic symbols like %t1, %t2,
. . . ). This is often useful to avoid unnecessary expansion of subexpressions which
dont contain the variable of interest. Since the intermediate labels are bound to the
subexpressions they can all be substituted back by evaluating the expression in which
they occur.
exptisolate (default value: false) if true will cause isolate to examine exponents
of atoms (like %e) which contain var.
isolate_wrt_times if true, then isolate will also isolate with respect to products.
See isolate_wrt_times.
Do example (isolate) for examples.
Option variable isolate wrt times
Default value: false
When isolate_wrt_times is true, isolate will also isolate with respect to products.
E.g. compare both settings of the switch on
(%i1) isolate_wrt_times: true$
(%i2) isolate (expand ((a+b+c)^2), c);
(%t2) 2 a
(%t3) 2 b
2 2
(%t4) b + 2 a b + a
2
(%o4) c + %t3 c + %t2 c + %t4
(%i4) isolate_wrt_times: false$
(%i5) isolate (expand ((a+b+c)^2), c);
2
(%o5) c + 2 b c + 2 a c + %t4
Option variable listconstvars
Default value: false
When listconstvars is true, it will cause listofvars to include %e, %pi, %i, and
any variables declared constant in the list it returns if they appear in the expression
listofvars is called on. The default is to omit these.
Option variable listdummyvars
Default value: true
Chapter 6: Expressions 81
When listdummyvars is false, "dummy variables" in the expression will not be
included in the list returned by listofvars. (The meaning of "dummy variables"
is as given in freeof. "Dummy variables" are mathematical things like the index of
a sum or product, the limit variable, and the denite integration variable.)
Example:
(%i1) listdummyvars: true$
(%i2) listofvars (sum(f(i), i, 0, n));
(%o2) [i, n]
(%i3) listdummyvars: false$
(%i4) listofvars (sum(f(i), i, 0, n));
(%o4) [n]
Function listofvars (expr)
Returns a list of the variables in expr.
listconstvars if true causes listofvars to include %e, %pi, %i, and any variables
declared constant in the list it returns if they appear in expr. The default is to omit
these.
See also the option variable listdummyvars to exclude or include "dummy variables"
in the list of variables.
(%i1) listofvars (f (x[1]+y) / g^(2+a));
(%o1) [g, a, x , y]
1
Function lfreeof (list, expr)
For each member m of list, calls freeof (m, expr). It returns false if any call to
freeof does and true otherwise.
Function lpart (label, expr, n 1, . . . , n k)
is similar to dpart but uses a labelled box. A labelled box is similar to the one
produced by dpart but it has a name in the top line.
Property mainvar
You may declare variables to be mainvar. The ordering scale for atoms is essentially:
numbers < constants (e.g., %e, %pi) < scalars < other variables < mainvars. E.g., com-
pare expand ((X+Y)^4) with (declare (x, mainvar), expand ((x+y)^4)). (Note:
Care should be taken if you elect to use the above feature. E.g., if you subtract an
expression in which x is a mainvar from one in which x isnt a mainvar, resimplica-
tion e.g. with ev (expr, simp) may be necessary if cancellation is to occur. Also, if
you save an expression in which x is a mainvar, you probably should also save x.)
Property noun
noun is one of the options of the declare command. It makes a function so declared
a "noun", meaning that it wont be evaluated automatically.
Example:
82 Maxima 5.30.0 Manual
(%i1) factor (12345678);
2
(%o1) 2 3 47 14593
(%i2) declare (factor, noun);
(%o2) done
(%i3) factor (12345678);
(%o3) factor(12345678)
(%i4) %, nouns;
2
(%o4) 2 3 47 14593
Option variable noundisp
Default value: false
When noundisp is true, nouns display with a single quote. This switch is always
true when displaying function denitions.
Function nounify (f )
Returns the noun form of the function name f. This is needed if one wishes to refer
to the name of a verb function as if it were a noun. Note that some verb functions
will return their noun forms if they cant be evaluated for certain arguments. This is
also the form returned if a function call is preceded by a quote.
See also verbify.
Function nterms (expr)
Returns the number of terms that expr would have if it were fully expanded out
and no cancellations or combination of terms occurred. Note that expressions like
sin (expr), sqrt (expr), exp (expr), etc. count as just one term regardless of how
many terms expr has (if it is a sum).
Function op (expr)
Returns the main operator of the expression expr. op (expr) is equivalent to part
(expr, 0).
op returns a string if the main operator is a built-in or user-dened prex, binary or
n-ary inx, postx, matchx, or nox operator. Otherwise, if expr is a subscripted
function expression, op returns the subscripted function; in this case the return value
is not an atom. Otherwise, expr is an array function or ordinary function expression,
and op returns a symbol.
op observes the value of the global ag inflag.
op evaluates it argument.
See also args.
Examples:
Chapter 6: Expressions 83
(%i1) stringdisp: true$
(%i2) op (a * b * c);
(%o2) "*"
(%i3) op (a * b + c);
(%o3) "+"
(%i4) op (sin (a + b));
(%o4) sin
(%i5) op (a!);
(%o5) "!"
(%i6) op (-a);
(%o6) "-"
(%i7) op ([a, b, c]);
(%o7) "["
(%i8) op ((if a > b then c else d));
(%o8) "if"
(%i9) op (foo (a));
(%o9) foo
(%i10) prefix (foo);
(%o10) "foo"
(%i11) op (foo a);
(%o11) "foo"
(%i12) op (F [x, y] (a, b, c));
(%o12) F
x, y
(%i13) op (G [u, v, w]);
(%o13) G
Function operatorp (expr, op)
Function operatorp (expr, [op 1, . . . , op n])
operatorp (expr, op) returns true if op is equal to the operator of expr.
operatorp (expr, [op 1, ..., op n]) returns true if some element op 1, . . . , op n
is equal to the operator of expr.
Option variable opsubst
Default value: true
When opsubst is false, subst does not attempt to substitute into the operator of
an expression. E.g., (opsubst: false, subst (x^2, r, r+r[0])) will work.
Function optimize (expr)
Returns an expression that produces the same value and side eects as expr but
does so more eciently by avoiding the recomputation of common subexpressions.
optimize also has the side eect of "collapsing" its argument so that all common
subexpressions are shared. Do example (optimize) for examples.
Option variable optimprex
Default value: %
optimprefix is the prex used for generated symbols by the optimize command.
84 Maxima 5.30.0 Manual
Function ordergreat (v 1, . . . , v n)
Function orderless (v 1, . . . , v n)
ordergreat changes the canonical ordering of Maxima expressions such that v 1 suc-
ceeds v 2 succeeds . . . succeeds v n, and v n succeeds any other symbol not mentioned
as an argument.
orderless changes the canonical ordering of Maxima expressions such that v 1 pre-
cedes v 2 precedes . . . precedes v n, and v n precedes any other variable not men-
tioned as an argument.
The order established by ordergreat and orderless is dissolved by unorder.
ordergreat and orderless can be called only once each, unless unorder is called;
only the last call to ordergreat and orderless has any eect.
See also ordergreatp.
Function ordergreatp (expr 1, expr 2)
Function orderlessp (expr 1, expr 2)
ordergreatp returns true if expr 1 succeeds expr 2 in the canonical ordering of
Maxima expressions, and false otherwise.
orderlessp returns true if expr 1 precedes expr 2 in the canonical ordering of Max-
ima expressions, and false otherwise.
All Maxima atoms and expressions are comparable under ordergreatp and
orderlessp, although there are isolated examples of expressions for which these
predicates are not transitive; that is a bug.
The canonical ordering of atoms (symbols, literal numbers, and strings) is the follow-
ing.
(integers and oats) precede (bigoats) precede (declared constants) precede (strings)
precede (declared scalars) precede (rst argument to orderless ) precedes . . . pre-
cedes (last argument to orderless) precedes (other symbols) precede (last argument
to ordergreat ) precedes . . . precedes (rst argument to ordergreat) precedes (de-
clared main variables)
For non-atomic expressions, the canonical ordering is derived from the ordering for
atoms. For the built-in + * and ^ operators, the ordering is not easily summarized.
For other built-in operators and all other functions and operators, expressions are
ordered by their arguments (beginning with the rst argument), then by the name
of the operator or function. In the case of subscripted expressions, the subscripted
symbol is considered the operator and the subscript is considered an argument.
The canonical ordering of expressions is modied by the functions ordergreat and
orderless, and the mainvar, constant, and scalar declarations.
See also sort.
Examples:
Ordering ordinary symbols and constants. Note that %pi is not ordered according to
its numerical value.
(%i1) stringdisp : true;
(%o1) true
Chapter 6: Expressions 85
(%i2) sort([%pi, 3b0, 3.0, x, X, "foo", 3, a, 4, "bar", 4.0, 4b0]);
(%o2) [3, 3.0, 4, 4.0, 3.0b0, 4.0b0, %pi, "bar", "foo", a, x, X]
Eect of ordergreat and orderless functions.
(%i1) sort ([M, H, K, T, E, W, G, A, P, J, S]);
(%o1) [A, E, G, H, J, K, M, P, S, T, W]
(%i2) ordergreat (S, J);
(%o2) done
(%i3) orderless (M, H);
(%o3) done
(%i4) sort ([M, H, K, T, E, W, G, A, P, J, S]);
(%o4) [M, H, A, E, G, K, P, T, W, J, S]
Eect of mainvar, constant, and scalar declarations.
(%i1) sort ([aa, foo, bar, bb, baz, quux, cc, dd, A1, B1, C1]);
(%o1) [aa, bar, baz, bb, cc, dd, foo, quux, A1, B1, C1]
(%i2) declare (aa, mainvar);
(%o2) done
(%i3) declare ([baz, quux], constant);
(%o3) done
(%i4) declare ([A1, B1], scalar);
(%o4) done
(%i5) sort ([aa, foo, bar, bb, baz, quux, cc, dd, A1, B1, C1]);
(%o5) [baz, quux, A1, B1, bar, bb, cc, dd, foo, C1, aa]
Ordering non-atomic expressions.
(%i1) sort([1, 2, n, f(1), f(2), f(2, 1), g(1), g(1, 2), g(n),
f(n, 1)]);
(%o1) [1, 2, f(1), g(1), g(1, 2), f(2), f(2, 1), n, g(n),
f(n, 1)]
(%i2) sort ([foo(1), X[1], X[k], foo(k), 1, k]);
(%o2) [1, foo(1), X , k, foo(k), X ]
1 k
Function part (expr, n 1, . . . , n k)
Returns parts of the displayed form of expr. It obtains the part of expr as specied
by the indices n 1, . . . , n k. First part n 1 of expr is obtained, then part n 2 of
that, etc. The result is part n k of . . . part n 2 of part n 1 of expr. If no indices are
specied expr is returned.
part can be used to obtain an element of a list, a row of a matrix, etc.
If the last argument to a part function is a list of indices then several subexpressions
are picked out, each one corresponding to an index of the list. Thus part (x + y +
z, [1, 3]) is z+x.
piece holds the last expression selected when using the part functions. It is set
during the execution of the function and thus may be referred to in the function itself
as shown below.
If partswitch is set to true then end is returned when a selected part of an expression
doesnt exist, otherwise an error message is given.
86 Maxima 5.30.0 Manual
See also inpart, substpart, substinpart, dpart, and lpart.
Examples:
(%i1) part(z+2*y+a,2);
(%o1) 2 y
(%i2) part(z+2*y+a,[1,3]);
(%o2) z + a
(%i3) part(z+2*y+a,2,1);
(%o3) 2
example (part) displays additional examples.
Function partition (expr, x)
Returns a list of two expressions. They are (1) the factors of expr (if it is a product),
the terms of expr (if it is a sum), or the list (if it is a list) which dont contain x and,
(2) the factors, terms, or list which do.
Examples:
(%i1) partition (2*a*x*f(x), x);
(%o1) [2 a, x f(x)]
(%i2) partition (a+b, x);
(%o2) [b + a, 0]
(%i3) partition ([a, b, f(a), c], a);
(%o3) [[b, c], [a, f(a)]]
Option variable partswitch
Default value: false
When partswitch is true, end is returned when a selected part of an expression
doesnt exist, otherwise an error message is given.
Function pickapart (expr, n)
Assigns intermediate expression labels to subexpressions of expr at depth n, an in-
teger. Subexpressions at greater or lesser depths are not assigned labels. pickapart
returns an expression in terms of intermediate expressions equivalent to the original
expression expr.
See also part, dpart, lpart, inpart, and reveal.
Examples:
(%i1) expr: (a+b)/2 + sin (x^2)/3 - log (1 + sqrt(x+1));
2
sin(x ) b + a
(%o1) - log(sqrt(x + 1) + 1) + ------- + -----
3 2
(%i2) pickapart (expr, 0);
2
sin(x ) b + a
(%t2) - log(sqrt(x + 1) + 1) + ------- + -----
3 2
Chapter 6: Expressions 87
(%o2) %t2
(%i3) pickapart (expr, 1);
(%t3) - log(sqrt(x + 1) + 1)
2
sin(x )
(%t4) -------
3
b + a
(%t5) -----
2
(%o5) %t5 + %t4 + %t3
(%i5) pickapart (expr, 2);
(%t6) log(sqrt(x + 1) + 1)
2
(%t7) sin(x )
(%t8) b + a
%t8 %t7
(%o8) --- + --- - %t6
2 3
(%i8) pickapart (expr, 3);
(%t9) sqrt(x + 1) + 1
2
(%t10) x
b + a sin(%t10)
(%o10) ----- - log(%t9) + ---------
2 3
(%i10) pickapart (expr, 4);
(%t11) sqrt(x + 1)
2
sin(x ) b + a
(%o11) ------- + ----- - log(%t11 + 1)
3 2
88 Maxima 5.30.0 Manual
(%i11) pickapart (expr, 5);
(%t12) x + 1
2
sin(x ) b + a
(%o12) ------- + ----- - log(sqrt(%t12) + 1)
3 2
(%i12) pickapart (expr, 6);
2
sin(x ) b + a
(%o12) ------- + ----- - log(sqrt(x + 1) + 1)
3 2
System variable piece
Holds the last expression selected when using the part functions. It is set during the
execution of the function and thus may be referred to in the function itself.
Function psubst (list, expr)
Function psubst (a, b, expr)
psubst(a, b, expr) is simliar to subst. See subst.
In distinction from subst the function psubst makes parallel substitutions, if the
rst argument list is a list of equations.
See also sublis for making parallel substitutions.
Example:
The rst example shows parallel substitution with psubst. The second example shows
the result for the function subst, which does a serial substitution.
(%i4) psubst ([a^2=b, b=a], sin(a^2) + sin(b));
(%o4) sin(b) + sin(a)
(%i5) subst ([a^2=b, b=a], sin(a^2) + sin(b));
(%o5) 2 sin(a)
Function rembox (expr, unlabelled)
Function rembox (expr, label)
Function rembox (expr)
Removes boxes from expr.
rembox (expr, unlabelled) removes all unlabelled boxes from expr.
rembox (expr, label) removes only boxes bearing label.
rembox (expr) removes all boxes, labelled and unlabelled.
Boxes are drawn by the box, dpart, and lpart functions.
Examples:
Chapter 6: Expressions 89
(%i1) expr: (a*d - b*c)/h^2 + sin(%pi*x);
a d - b c
(%o1) sin(%pi x) + ---------
2
h
(%i2) dpart (dpart (expr, 1, 1), 2, 2);
""""""" a d - b c
(%o2) sin("%pi x") + ---------
""""""" """"
" 2"
"h "
""""
(%i3) expr2: lpart (BAR, lpart (FOO, %, 1), 2);
FOO""""""""""" BAR""""""""
" """"""" " "a d - b c"
(%o3) "sin("%pi x")" + "---------"
" """"""" " " """" "
"""""""""""""" " " 2" "
" "h " "
" """" "
"""""""""""
(%i4) rembox (expr2, unlabelled);
BAR""""""""
FOO""""""""" "a d - b c"
(%o4) "sin(%pi x)" + "---------"
"""""""""""" " 2 "
" h "
"""""""""""
(%i5) rembox (expr2, FOO);
BAR""""""""
""""""" "a d - b c"
(%o5) sin("%pi x") + "---------"
""""""" " """" "
" " 2" "
" "h " "
" """" "
"""""""""""
(%i6) rembox (expr2, BAR);
FOO"""""""""""
" """"""" " a d - b c
(%o6) "sin("%pi x")" + ---------
" """"""" " """"
"""""""""""""" " 2"
"h "
""""
(%i7) rembox (expr2);
a d - b c
(%o7) sin(%pi x) + ---------
2
90 Maxima 5.30.0 Manual
h
Function reveal (expr, depth)
Replaces parts of expr at the specied integer depth with descriptive summaries.
Sums and dierences are replaced by Sum(n) where n is the number of operands
of the sum.
Products are replaced by Product(n) where n is the number of operands of the
product.
Exponentials are replaced by Expt.
Quotients are replaced by Quotient.
Unary negation is replaced by Negterm.
Lists are replaced by List(n) where n ist the number of elements of the list.
When depth is greater than or equal to the maximum depth of expr, reveal (expr,
depth) returns expr unmodied.
reveal evaluates its arguments. reveal returns the summarized expression.
Example:
(%i1) e: expand ((a - b)^2)/expand ((exp(a) + exp(b))^2);
2 2
b - 2 a b + a
(%o1) -------------------------
b + a 2 b 2 a
2 %e + %e + %e
(%i2) reveal (e, 1);
(%o2) Quotient
(%i3) reveal (e, 2);
Sum(3)
(%o3) ------
Sum(3)
(%i4) reveal (e, 3);
Expt + Negterm + Expt
(%o4) ------------------------
Product(2) + Expt + Expt
(%i5) reveal (e, 4);
2 2
b - Product(3) + a
(%o5) ------------------------------------
Product(2) Product(2)
2 Expt + %e + %e
(%i6) reveal (e, 5);
2 2
b - 2 a b + a
(%o6) --------------------------
Sum(2) 2 b 2 a
2 %e + %e + %e
(%i7) reveal (e, 6);
Chapter 6: Expressions 91
2 2
b - 2 a b + a
(%o7) -------------------------
b + a 2 b 2 a
2 %e + %e + %e
Function sublis (list, expr)
Makes multiple parallel substitutions into an expression. list is a list of equations.
The left hand side of the equations must be an atom.
The variable sublis_apply_lambda controls simplication after sublis.
See also psubst for making parallel substitutions.
Example:
(%i1) sublis ([a=b, b=a], sin(a) + cos(b));
(%o1) sin(b) + cos(a)
Option variable sublis apply lambda
Default value: true
Controls whether lambdas substituted are applied in simplication after sublis is
used or whether you have to do an ev to get things to apply. true means do the
application.
Option variable subnumsimp
Default value: false
If true then the functions subst and psubst can substitute a subscripted variable
f[x] with a number, when only the symbol f is given.
See also subst.
(%i1) subst(100,g,g[x]+2);
subst: cannot substitute 100 for operator g in expression g
x
-- an error. To debug this try: debugmode(true);
(%i2) subst(100,g,g[x]+2),subnumsimp:true;
(%o2) 102
Function subst (a, b, c)
Substitutes a for b in c. b must be an atom or a complete subexpression of c.
For example, x+y+z is a complete subexpression of 2*(x+y+z)/w while x+y is not.
When b does not have these characteristics, one may sometimes use substpart or
ratsubst (see below). Alternatively, if b is of the form e/f then one could use subst
(a*f, e, c) while if b is of the form e^(1/f) then one could use subst (a^f, e,
c). The subst command also discerns the x^y in x^-y so that subst (a, sqrt(x),
1/sqrt(x)) yields 1/a. a and b may also be operators of an expression enclosed in
double-quotes " or they may be function names. If one wishes to substitute for the
92 Maxima 5.30.0 Manual
independent variable in derivative forms then the at function (see below) should be
used.
subst is an alias for substitute.
The commands subst (eq 1, expr) or subst ([eq 1, ..., eq k], expr) are other
permissible forms. The eq i are equations indicating substitutions to be made. For
each equation, the right side will be substituted for the left in the expression expr.
The equations are substituted in serial from left to right in expr. See the functions
sublis and psubst for making parallel substitutions.
exptsubst if true permits substitutions like y for %e^x in %e^(a*x) to take place.
When opsubst is false, subst will not attempt to substitute into the operator of an
expression. E.g. (opsubst: false, subst (x^2, r, r+r[0])) will work.
Examples:
(%i1) subst (a, x+y, x + (x+y)^2 + y);
2
(%o1) y + x + a
(%i2) subst (-%i, %i, a + b*%i);
(%o2) a - %i b
The substitution is done in serial for a list of equations. Compare this with a parallel
substitution:
(%i3) subst([a=b, b=c], a+b);
(%o3) 2 c
(%i4) sublis([a=b, b=c], a+b);
(%o4) c + b
For further examples, do example (subst).
Function substinpart (x, expr, n 1, . . . , n k)
Similar to substpart, but substinpart works on the internal representation of expr.
Examples:
(%i1) x . diff (f(x), x, 2);
2
d
(%o1) x . (--- (f(x)))
2
dx
(%i2) substinpart (d^2, %, 2);
2
(%o2) x . d
(%i3) substinpart (f1, f[1](x + 1), 0);
(%o3) f1(x + 1)
If the last argument to a part function is a list of indices then several subexpressions
are picked out, each one corresponding to an index of the list. Thus
(%i1) part (x + y + z, [1, 3]);
(%o1) z + x
piece holds the value of the last expression selected when using the part functions.
It is set during the execution of the function and thus may be referred to in the
Chapter 6: Expressions 93
function itself as shown below. If partswitch is set to true then end is returned
when a selected part of an expression doesnt exist, otherwise an error message is
given.
(%i1) expr: 27*y^3 + 54*x*y^2 + 36*x^2*y + y + 8*x^3 + x + 1;
3 2 2 3
(%o1) 27 y + 54 x y + 36 x y + y + 8 x + x + 1
(%i2) part (expr, 2, [1, 3]);
2
(%o2) 54 y
(%i3) sqrt (piece/54);
(%o3) abs(y)
(%i4) substpart (factor (piece), expr, [1, 2, 3, 5]);
3
(%o4) (3 y + 2 x) + y + x + 1
(%i5) expr: 1/x + y/x - 1/z;
1 y 1
(%o5) - - + - + -
z x x
(%i6) substpart (xthru (piece), expr, [2, 3]);
y + 1 1
(%o6) ----- - -
x z
Also, setting the option inflag to true and calling part or substpart is the same
as calling inpart or substinpart.
Function substpart (x, expr, n 1, . . . , n k)
Substitutes x for the subexpression picked out by the rest of the arguments as in
part. It returns the new value of expr. x may be some operator to be substituted
for an operator of expr. In some cases x needs to be enclosed in double-quotes " (e.g.
substpart ("+", a*b, 0) yields b + a).
Example:
(%i1) 1/(x^2 + 2);
1
(%o1) ------
2
x + 2
(%i2) substpart (3/2, %, 2, 1, 2);
1
(%o2) --------
3/2
x + 2
(%i3) a*x + f(b, y);
(%o3) a x + f(b, y)
(%i4) substpart ("+", %, 1, 0);
(%o4) x + f(b, y) + a
Also, setting the option inflag to true and calling part or substpart is the same
as calling inpart or substinpart.
94 Maxima 5.30.0 Manual
Function symbolp (expr)
Returns true if expr is a symbol, else false. In eect, symbolp(x) is equivalent to
the predicate atom(x) and not numberp(x).
See also Section 6.3 [Identiers], page 72.
Function unorder ()
Disables the aliasing created by the last use of the ordering commands ordergreat
and orderless. ordergreat and orderless may not be used more than one time
each without calling unorder. unorder does not substitute back in expressions the
original symbols for the aliases introduced by ordergreat and orderless. Therefore,
after execution of unorder the aliases appear in previous expressions.
See also ordergreat and orderless.
Examples:
ordergreat(a) introduces an alias for the symbol a. Therefore, the dierence of %o2
and %o4 does not vanish. unorder does not substitute back the symbol a and the
alias appears in the output %o7.
(%i1) unorder();
(%o1) []
(%i2) b*x+a^2;
2
(%o2) b x + a
(%i3) ordergreat(a);
(%o3) done
(%i4) b*x+a^2;
2
(%o4) a + b x
(%i5) %th(1)-%th(3);
2 2
(%o5) a - a
(%i6) unorder();
(%o6) [a]
(%i7) %th(2);
2 2
(%o7) _101a - a
Function verbify (f )
Returns the verb form of the function name f. See also verb, noun, and nounify.
Examples:
(%i1) verbify (foo);
(%o1) foo
(%i2) :lisp $%
$FOO
(%i2) nounify (foo);
(%o2) foo
(%i3) :lisp $%
%FOO
Chapter 7: Operators 95
7 Operators
7.1 Introduction to operators
It is possible to dene new operators with specied precedence, to undene existing
operators, or to redene the precedence of existing operators. An operator may be unary
prex or unary postx, binary inx, n-ary inx, matchx, or nox. "Matchx" means a
pair of symbols which enclose their argument or arguments, and "nox" means an operator
which takes no arguments. As examples of the dierent types of operators, there are the
following.
unary prex
negation - a
unary postx
factorial a!
binary inx
exponentiation a^b
n-ary inx addition a + b
matchx list construction [a, b]
(There are no built-in nox operators; for an example of such an operator, see nofix.)
The mechanism to dene a new operator is straightforward. It is only necessary to
declare a function as an operator; the operator function might or might not be dened.
An example of user-dened operators is the following. Note that the explicit function
call "dd" (a) is equivalent to dd a, likewise "<-" (a, b) is equivalent to a <- b. Note also
that the functions "dd" and "<-" are undened in this example.
(%i1) prefix ("dd");
(%o1) dd
(%i2) dd a;
(%o2) dd a
(%i3) "dd" (a);
(%o3) dd a
(%i4) infix ("<-");
(%o4) <-
(%i5) a <- dd b;
(%o5) a <- dd b
(%i6) "<-" (a, "dd" (b));
(%o6) a <- dd b
The Maxima functions which dene new operators are summarized in this table, stating
the default left and right binding powers (lbp and rbp, respectively). (Binding power
determines operator precedence. However, since left and right binding powers can dier,
binding power is somewhat more complicated than precedence.) Some of the operation
denition functions take additional arguments; see the function descriptions for details.
prefix rbp=180
96 Maxima 5.30.0 Manual
postfix lbp=180
infix lbp=180, rbp=180
nary lbp=180, rbp=180
matchfix (binding power not applicable)
nofix (binding power not applicable)
For comparison, here are some built-in operators and their left and right binding powers.
Operator lbp rbp
: 180 20
:: 180 20
:= 180 20
::= 180 20
! 160
!! 160
^ 140 139
. 130 129
* 120
/ 120 120
+ 100 100
- 100 134
= 80 80
# 80 80
> 80 80
>= 80 80
< 80 80
<= 80 80
not 70
and 65
or 60
, 10
$ -1
; -1
remove and kill remove operator properties from an atom. remove ("a", op) removes
only the operator properties of a. kill ("a") removes all properties of a, including the
operator properties. Note that the name of the operator must be enclosed in quotation
marks.
(%i1) infix ("##");
(%o1) ##
(%i2) "##" (a, b) := a^b;
b
(%o2) a ## b := a
(%i3) 5 ## 3;
(%o3) 125
(%i4) remove ("##", op);
(%o4) done
(%i5) 5 ## 3;
Chapter 7: Operators 97
Incorrect syntax: # is not a prefix operator
5 ##
^
(%i5) "##" (5, 3);
(%o5) 125
(%i6) infix ("##");
(%o6) ##
(%i7) 5 ## 3;
(%o7) 125
(%i8) kill ("##");
(%o8) done
(%i9) 5 ## 3;
Incorrect syntax: # is not a prefix operator
5 ##
^
(%i9) "##" (5, 3);
(%o9) ##(5, 3)
7.2 Arithmetic operators
Operator +
Operator -
Operator *
Operator /
Operator ^
The symbols + * / and ^ represent addition, multiplication, division, and exponen-
tiation, respectively. The names of these operators are "+" "*" "/" and "^", which
may appear where the name of a function or operator is required.
The symbols + and - represent unary addition and negation, respectively, and the
names of these operators are "+" and "-", respectively.
Subtraction a - b is represented within Maxima as addition, a + (- b). Expressions
such as a + (- b) are displayed as subtraction. Maxima recognizes "-" only as the
name of the unary negation operator, and not as the name of the binary subtraction
operator.
Division a / b is represented within Maxima as multiplication, a * b^(- 1). Expres-
sions such as a * b^(- 1) are displayed as division. Maxima recognizes "/" as the
name of the division operator.
Addition and multiplication are n-ary, commutative operators. Division and expo-
nentiation are binary, noncommutative operators.
Maxima sorts the operands of commutative operators to construct a canonical rep-
resentation. For internal storage, the ordering is determined by orderlessp. For
display, the ordering for addition is determined by ordergreatp, and for multiplica-
tion, it is the same as the internal ordering.
Arithmetic computations are carried out on literal numbers (integers, rationals, or-
dinary oats, and bigoats). Except for exponentiation, all arithmetic operations on
98 Maxima 5.30.0 Manual
numbers are simplied to numbers. Exponentiation is simplied to a number if either
operand is an ordinary oat or bigoat or if the result is an exact integer or rational;
otherwise an exponentiation may be simplied to sqrt or another exponentiation or
left unchanged.
Floating-point contagion applies to arithmetic computations: if any operand is a
bigoat, the result is a bigoat; otherwise, if any operand is an ordinary oat, the
result is an ordinary oat; otherwise, the operands are rationals or integers and the
result is a rational or integer.
Arithmetic computations are a simplication, not an evaluation. Thus arithmetic is
carried out in quoted (but simplied) expressions.
Arithmetic operations are applied element-by-element to lists when the global ag
listarith is true, and always applied element-by-element to matrices. When one
operand is a list or matrix and another is an operand of some other type, the other
operand is combined with each of the elements of the list or matrix.
Examples:
Addition and multiplication are n-ary, commutative operators. Maxima sorts the
operands to construct a canonical representation. The names of these operators are
"+" and "*".
(%i1) c + g + d + a + b + e + f;
(%o1) g + f + e + d + c + b + a
(%i2) [op (%), args (%)];
(%o2) [+, [g, f, e, d, c, b, a]]
(%i3) c * g * d * a * b * e * f;
(%o3) a b c d e f g
(%i4) [op (%), args (%)];
(%o4) [*, [a, b, c, d, e, f, g]]
(%i5) apply ("+", [a, 8, x, 2, 9, x, x, a]);
(%o5) 3 x + 2 a + 19
(%i6) apply ("*", [a, 8, x, 2, 9, x, x, a]);
2 3
(%o6) 144 a x
Division and exponentiation are binary, noncommutative operators. The names of
these operators are "/" and "^".
(%i1) [a / b, a ^ b];
a b
(%o1) [-, a ]
b
(%i2) [map (op, %), map (args, %)];
(%o2) [[/, ^], [[a, b], [a, b]]]
(%i3) [apply ("/", [a, b]), apply ("^", [a, b])];
a b
(%o3) [-, a ]
b
Subtraction and division are represented internally in terms of addition and multipli-
cation, respectively.
(%i1) [inpart (a - b, 0), inpart (a - b, 1), inpart (a - b, 2)];
Chapter 7: Operators 99
(%o1) [+, a, - b]
(%i2) [inpart (a / b, 0), inpart (a / b, 1), inpart (a / b, 2)];
1
(%o2) [*, a, -]
b
Computations are carried out on literal numbers. Floating-point contagion applies.
(%i1) 17 + b - (1/2)*29 + 11^(2/4);
5
(%o1) b + sqrt(11) + -
2
(%i2) [17 + 29, 17 + 29.0, 17 + 29b0];
(%o2) [46, 46.0, 4.6b1]
Arithmetic computations are a simplication, not an evaluation.
(%i1) simp : false;
(%o1) false
(%i2) (17 + 29*11/7 - 5^3);
29 11 3
(%o2) 17 + ----- - 5
7
(%i3) simp : true;
(%o3) true
(%i4) (17 + 29*11/7 - 5^3);
437
(%o4) - ---
7
Arithmetic is carried out element-by-element for lists (depending on listarith) and
matrices.
(%i1) matrix ([a, x], [h, u]) - matrix ([1, 2], [3, 4]);
[ a - 1 x - 2 ]
(%o1) [ ]
[ h - 3 u - 4 ]
(%i2) 5 * matrix ([a, x], [h, u]);
[ 5 a 5 x ]
(%o2) [ ]
[ 5 h 5 u ]
(%i3) listarith : false;
(%o3) false
(%i4) [a, c, m, t] / [1, 7, 2, 9];
[a, c, m, t]
(%o4) ------------
[1, 7, 2, 9]
(%i5) [a, c, m, t] ^ x;
x
(%o5) [a, c, m, t]
(%i6) listarith : true;
(%o6) true
(%i7) [a, c, m, t] / [1, 7, 2, 9];
c m t
100 Maxima 5.30.0 Manual
(%o7) [a, -, -, -]
7 2 9
(%i8) [a, c, m, t] ^ x;
x x x x
(%o8) [a , c , m , t ]
Operator **
Exponentiation operator. Maxima recognizes ** as the same operator as ^ in input,
and it is displayed as ^ in 1-dimensional output, or by placing the exponent as a
superscript in 2-dimensional output.
The fortran function displays the exponentiation operator as **, whether it was
input as ** or ^.
Examples:
(%i1) is (a**b = a^b);
(%o1) true
(%i2) x**y + x^z;
z y
(%o2) x + x
(%i3) string (x**y + x^z);
(%o3) x^z+x^y
(%i4) fortran (x**y + x^z);
x**z+x**y
(%o4) done
Operator ^^
Noncommutative exponentiation operator. ^^ is the exponentiation operator corre-
sponding to noncommutative multiplication ., just as the ordinary exponentiation
operator ^ corresponds to commutative multiplication *.
Noncommutative exponentiation is displayed by ^^ in 1-dimensional output, and by
placing the exponent as a superscript within angle brackets < > in 2-dimensional
output.
Examples:
(%i1) a . a . b . b . b + a * a * a * b * b;
3 2 <2> <3>
(%o1) a b + a . b
(%i2) string (a . a . b . b . b + a * a * a * b * b);
(%o2) a^3*b^2+a^^2 . b^^3
Operator .
The dot operator, for matrix (non-commutative) multiplication. When "." is used
in this way, spaces should be left on both sides of it, e.g. A . B. This distinguishes it
plainly from a decimal point in a oating point number.
See also dot, dot0nscsimp, dot0simp, dot1simp, dotassoc, dotconstrules,
dotdistrib, dotexptsimp, dotident, and dotscrules.
Chapter 7: Operators 101
7.3 Relational operators
Operator <
Operator <=
Operator >=
Operator >
The symbols < <= >= and > represent less than, less than or equal, greater than or
equal, and greater than, respectively. The names of these operators are "<" "<=" ">="
and ">", which may appear where the name of a function or operator is required.
These relational operators are all binary operators; constructs such as a < b < c are
not recognized by Maxima.
Relational expressions are evaluated to Boolean values by the functions is and maybe,
and the programming constructs if, while, and unless. Relational expressions
are not otherwise evaluated or simplied to Boolean values, although the arguments
of relational expressions are evaluated (when evaluation is not otherwise prevented
by quotation).
When a relational expression cannot be evaluated to true or false, the behavior of
is and if are governed by the global ag prederror. When prederror is true,
is and if trigger an error. When prederror is false, is returns unknown, and if
returns a partially-evaluated conditional expression.
maybe always behaves as if prederror were false, and while and unless always
behave as if prederror were true.
Relational operators do not distribute over lists or other aggregates.
See also =, #, equal, and notequal.
Examples:
Relational expressions are evaluated to Boolean values by some functions and pro-
gramming constructs.
(%i1) [x, y, z] : [123, 456, 789];
(%o1) [123, 456, 789]
(%i2) is (x < y);
(%o2) true
(%i3) maybe (y > z);
(%o3) false
(%i4) if x >= z then 1 else 0;
(%o4) 0
(%i5) block ([S], S : 0, for i:1 while i <= 100 do S : S + i,
return (S));
(%o5) 5050
Relational expressions are not otherwise evaluated or simplied to Boolean values,
although the arguments of relational expressions are evaluated.
(%o1) [123, 456, 789]
(%i2) [x < y, y <= z, z >= y, y > z];
(%o2) [123 < 456, 456 <= 789, 789 >= 456, 456 > 789]
(%i3) map (is, %);
(%o3) [true, true, true, false]
102 Maxima 5.30.0 Manual
7.4 Logical operators
Operator and
The logical conjunction operator. and is an n-ary inx operator; its operands are
Boolean expressions, and its result is a Boolean value.
and forces evaluation (like is ) of one or more operands, and may force evaluation of
all operands.
Operands are evaluated in the order in which they appear. and evaluates only as
many of its operands as necessary to determine the result. If any operand is false,
the result is false and no further operands are evaluated.
The global ag prederror governs the behavior of and when an evaluated operand
cannot be determined to be true or false. and prints an error message when
prederror is true. Otherwise, operands which do not evaluate to true or false
are accepted, and the result is a Boolean expression.
and is not commutative: a and b might not be equal to b and a due to the treatment
of indeterminate operands.
Operator not
The logical negation operator. not is a prex operator; its operand is a Boolean
expression, and its result is a Boolean value.
not forces evaluation (like is) of its operand.
The global ag prederror governs the behavior of not when its operand cannot be
determined to be true or false. not prints an error message when prederror is
true. Otherwise, operands which do not evaluate to true or false are accepted, and
the result is a Boolean expression.
Operator or
The logical disjunction operator. or is an n-ary inx operator; its operands are
Boolean expressions, and its result is a Boolean value.
or forces evaluation (like is ) of one or more operands, and may force evaluation of
all operands.
Operands are evaluated in the order in which they appear. or evaluates only as many
of its operands as necessary to determine the result. If any operand is true, the result
is true and no further operands are evaluated.
The global ag prederror governs the behavior of or when an evaluated operand can-
not be determined to be true or false. or prints an error message when prederror
is true. Otherwise, operands which do not evaluate to true or false are accepted,
and the result is a Boolean expression.
or is not commutative: a or b might not be equal to b or a due to the treatment of
indeterminate operands.
Chapter 7: Operators 103
7.5 Operators for Equations
Operator #
Represents the negation of syntactic equality =.
Note that because of the rules for evaluation of predicate expressions (in particular
because not expr causes evaluation of expr), not a = b is equivalent to is(a # b),
instead of a # b.
Examples:
(%i1) a = b;
(%o1) a = b
(%i2) is (a = b);
(%o2) false
(%i3) a # b;
(%o3) a # b
(%i4) not a = b;
(%o4) true
(%i5) is (a # b);
(%o5) true
(%i6) is (not a = b);
(%o6) true
Operator =
The equation operator.
An expression a = b, by itself, represents an unevaluated equation, which might or
might not hold. Unevaluated equations may appear as arguments to solve and
algsys or some other functions.
The function is evaluates = to a Boolean value. is(a = b) evaluates a = b to true
when a and b are identical. That is, a and b are atoms which are identical, or they
are not atoms and their operators are identical and their arguments are identical.
Otherwise, is(a = b) evaluates to false; it never evaluates to unknown. When is(a
= b) is true, a and b are said to be syntactically equal, in contrast to equivalent
expressions, for which is(equal(a, b)) is true. Expressions can be equivalent and
not syntactically equal.
The negation of = is represented by #. As with =, an expression a # b, by itself, is
not evaluated. is(a # b) evaluates a # b to true or false.
In addition to is, some other operators evaluate = and # to true or false, namely
if, and, or, and not.
Note that because of the rules for evaluation of predicate expressions (in particular
because not expr causes evaluation of expr), not a = b is equivalent to is(a # b),
instead of a # b.
rhs and lhs return the right-hand and left-hand sides, respectively, of an equation
or inequation.
See also equal and notequal.
Examples:
104 Maxima 5.30.0 Manual
An expression a = b, by itself, represents an unevaluated equation, which might or
might not hold.
(%i1) eq_1 : a * x - 5 * y = 17;
(%o1) a x - 5 y = 17
(%i2) eq_2 : b * x + 3 * y = 29;
(%o2) 3 y + b x = 29
(%i3) solve ([eq_1, eq_2], [x, y]);
196 29 a - 17 b
(%o3) [[x = ---------, y = -----------]]
5 b + 3 a 5 b + 3 a
(%i4) subst (%, [eq_1, eq_2]);
196 a 5 (29 a - 17 b)
(%o4) [--------- - --------------- = 17,
5 b + 3 a 5 b + 3 a
196 b 3 (29 a - 17 b)
--------- + --------------- = 29]
5 b + 3 a 5 b + 3 a
(%i5) ratsimp (%);
(%o5) [17 = 17, 29 = 29]
is(a = b) evaluates a = b to true when a and b are syntactically equal (that is,
identical). Expressions can be equivalent and not syntactically equal.
(%i1) a : (x + 1) * (x - 1);
(%o1) (x - 1) (x + 1)
(%i2) b : x^2 - 1;
2
(%o2) x - 1
(%i3) [is (a = b), is (a # b)];
(%o3) [false, true]
(%i4) [is (equal (a, b)), is (notequal (a, b))];
(%o4) [true, false]
Some operators evaluate = and # to true or false.
(%i1) if expand ((x + y)^2) = x^2 + 2 * x * y + y^2 then FOO else
BAR;
(%o1) FOO
(%i2) eq_3 : 2 * x = 3 * x;
(%o2) 2 x = 3 x
(%i3) eq_4 : exp (2) = %e^2;
2 2
(%o3) %e = %e
(%i4) [eq_3 and eq_4, eq_3 or eq_4, not eq_3];
(%o4) [false, true, true]
Because not expr causes evaluation of expr, not a = b is equivalent to is(a # b).
(%i1) [2 * x # 3 * x, not (2 * x = 3 * x)];
(%o1) [2 x # 3 x, true]
(%i2) is (2 * x # 3 * x);
(%o2) true
Chapter 7: Operators 105
7.6 Assignment operators
Operator :
Assignment operator.
When the left-hand side is a simple variable (not subscripted), : evaluates its right-
hand side and associates that value with the left-hand side.
When the left-hand side is a subscripted element of a list, matrix, declared Maxima
array, or Lisp array, the right-hand side is assigned to that element. The subscript
must name an existing element; such objects cannot be extended by naming nonex-
istent elements.
When the left-hand side is a subscripted element of an undeclared Maxima array, the
right-hand side is assigned to that element, if it already exists, or a new element is
allocated, if it does not already exist.
When the left-hand side is a list of simple and/or subscripted variables, the right-hand
side must evaluate to a list, and the elements of the right-hand side are assigned to
the elements of the left-hand side, in parallel.
See also kill and remvalue, which undo the association between the left-hand side
and its value.
Examples:
Assignment to a simple variable.
(%i1) a;
(%o1) a
(%i2) a : 123;
(%o2) 123
(%i3) a;
(%o3) 123
Assignment to an element of a list.
(%i1) b : [1, 2, 3];
(%o1) [1, 2, 3]
(%i2) b[3] : 456;
(%o2) 456
(%i3) b;
(%o3) [1, 2, 456]
Assignment creates an undeclared array.
(%i1) c[99] : 789;
(%o1) 789
(%i2) c[99];
(%o2) 789
(%i3) c;
(%o3) c
(%i4) arrayinfo (c);
(%o4) [hashed, 1, [99]]
(%i5) listarray (c);
(%o5) [789]
Multiple assignment.
106 Maxima 5.30.0 Manual
(%i1) [a, b, c] : [45, 67, 89];
(%o1) [45, 67, 89]
(%i2) a;
(%o2) 45
(%i3) b;
(%o3) 67
(%i4) c;
(%o4) 89
Multiple assignment is carried out in parallel. The values of a and b are exchanged
in this example.
(%i1) [a, b] : [33, 55];
(%o1) [33, 55]
(%i2) [a, b] : [b, a];
(%o2) [55, 33]
(%i3) a;
(%o3) 55
(%i4) b;
(%o4) 33
Operator ::
Assignment operator.
:: is the same as : (which see) except that :: evaluates its left-hand side as well as
its right-hand side.
Examples:
(%i1) x : foo;
(%o1) foo
(%i2) x :: 123;
(%o2) 123
(%i3) foo;
(%o3) 123
(%i4) x : [a, b, c];
(%o4) [a, b, c]
(%i5) x :: [11, 22, 33];
(%o5) [11, 22, 33]
(%i6) a;
(%o6) 11
(%i7) b;
(%o7) 22
(%i8) c;
(%o8) 33
Operator ::=
Macro function denition operator. ::= denes a function (called a "macro" for
historical reasons) which quotes its arguments, and the expression which it returns
(called the "macro expansion") is evaluated in the context from which the macro was
called. A macro function is otherwise the same as an ordinary function.
Chapter 7: Operators 107
macroexpand returns a macro expansion (without evaluating it). macroexpand (foo
(x)) followed by % is equivalent to foo (x) when foo is a macro function.
::= puts the name of the new macro function onto the global list macros. kill,
remove, and remfunction unbind macro function denitions and remove names
from macros.
fundef or dispfun return a macro function denition or assign it to a label, respec-
tively.
Macro functions commonly contain buildq and splice expressions to construct an
expression, which is then evaluated.
Examples
A macro function quotes its arguments, so message (1) shows y - z, not the value of
y - z. The macro expansion (the quoted expression (print ("(2) x is equal to",
x)) is evaluated in the context from which the macro was called, printing message
(2).
(%i1) x: %pi$
(%i2) y: 1234$
(%i3) z: 1729 * w$
(%i4) printq1 (x) ::= block (print ("(1) x is equal to", x),
(print ("(2) x is equal to", x)))$
(%i5) printq1 (y - z);
(1) x is equal to y - z
(2) x is equal to %pi
(%o5) %pi
An ordinary function evaluates its arguments, so message (1) shows the value of y -
z. The return value is not evaluated, so message (2) is not printed until the explicit
evaluation %.
(%i1) x: %pi$
(%i2) y: 1234$
(%i3) z: 1729 * w$
(%i4) printe1 (x) := block (print ("(1) x is equal to", x),
(print ("(2) x is equal to", x)))$
(%i5) printe1 (y - z);
(1) x is equal to 1234 - 1729 w
(%o5) print((2) x is equal to, x)
(%i6) %;
(2) x is equal to %pi
(%o6) %pi
macroexpand returns a macro expansion. macroexpand (foo (x)) followed by % is
equivalent to foo (x) when foo is a macro function.
(%i1) x: %pi$
(%i2) y: 1234$
(%i3) z: 1729 * w$
(%i4) g (x) ::= buildq ([x], print ("x is equal to", x))$
(%i5) macroexpand (g (y - z));
(%o5) print(x is equal to, y - z)
(%i6) %;
108 Maxima 5.30.0 Manual
x is equal to 1234 - 1729 w
(%o6) 1234 - 1729 w
(%i7) g (y - z);
x is equal to 1234 - 1729 w
(%o7) 1234 - 1729 w
Operator :=
The function denition operator. f (x 1, ..., x n) := expr denes a function named
f with arguments x 1, . . . , x n and function body expr. := never evaluates the
function body (unless explicitly evaluated by quote-quote ). The function so dened
may be an ordinary Maxima function (with arguments enclosed in parentheses) or an
array function (with arguments enclosed in square brackets).
When the last or only function argument x n is a list of one element, the function
dened by := accepts a variable number of arguments. Actual arguments are assigned
one-to-one to formal arguments x 1, . . . , x (n - 1), and any further actual arguments,
if present, are assigned to x n as a list.
All function denitions appear in the same namespace; dening a function f within an-
other function g does not automatically limit the scope of f to g. However, local(f)
makes the denition of function f eective only within the block or other compound
expression in which local appears.
If some formal argument x k is a quoted symbol, the function dened by := does
not evaluate the corresponding actual argument. Otherwise all actual arguments are
evaluated.
See also define and ::=.
Examples:
:= never evaluates the function body (unless explicitly evaluated by quote-quote).
(%i1) expr : cos(y) - sin(x);
(%o1) cos(y) - sin(x)
(%i2) F1 (x, y) := expr;
(%o2) F1(x, y) := expr
(%i3) F1 (a, b);
(%o3) cos(y) - sin(x)
(%i4) F2 (x, y) := expr;
(%o4) F2(x, y) := cos(y) - sin(x)
(%i5) F2 (a, b);
(%o5) cos(b) - sin(a)
The function dened by := may be an ordinary Maxima function or an array function.
(%i1) G1 (x, y) := x.y - y.x;
(%o1) G1(x, y) := x . y - y . x
(%i2) G2 [x, y] := x.y - y.x;
(%o2) G2 := x . y - y . x
x, y
When the last or only function argument x n is a list of one element, the function
dened by := accepts a variable number of arguments.
Chapter 7: Operators 109
(%i1) H ([L]) := apply ("+", L);
(%o1) H([L]) := apply("+", L)
(%i2) H (a, b, c);
(%o2) c + b + a
local makes a local function denition.
(%i1) foo (x) := 1 - x;
(%o1) foo(x) := 1 - x
(%i2) foo (100);
(%o2) - 99
(%i3) block (local (foo), foo (x) := 2 * x, foo (100));
(%o3) 200
(%i4) foo (100);
(%o4) - 99
7.7 User dened operators
Function inx (op)
Function inx (op, lbp, rbp)
Function inx (op, lbp, rbp, lpos, rpos, pos)
Declares op to be an inx operator. An inx operator is a function of two arguments,
with the name of the function written between the arguments. For example, the
subtraction operator - is an inx operator.
infix (op) declares op to be an inx operator with default binding powers (left and
right both equal to 180) and parts of speech (left and right both equal to any).
infix (op, lbp, rbp) declares op to be an inx operator with stated left and right
binding powers and default parts of speech (left and right both equal to any).
infix (op, lbp, rbp, lpos, rpos, pos) declares op to be an inx operator with
stated left and right binding powers and parts of speech lpos, rpos, and pos for the
left operand, the right operand, and the operator result, respectively.
"Part of speech", in reference to operator declarations, means expression type. Three
types are recognized: expr, clause, and any, indicating an algebraic expression, a
Boolean expression, or any kind of expression, respectively. Maxima can detect some
syntax errors by comparing the declared part of speech to an actual expression.
The precedence of op with respect to other operators derives from the left and right
binding powers of the operators in question. If the left and right binding powers of
op are both greater the left and right binding powers of some other operator, then op
takes precedence over the other operator. If the binding powers are not both greater
or less, some more complicated relation holds.
The associativity of op depends on its binding powers. Greater left binding power
(lbp) implies an instance of op is evaluated before other operators to its left in an
expression, while greater right binding power (rbp) implies an instance of op is eval-
uated before other operators to its right in an expression. Thus greater lbp makes op
right-associative, while greater rbp makes op left-associative. If lbp is equal to rbp,
op is left-associative.
See also Section 7.1 [Introduction to operators], page 95.
110 Maxima 5.30.0 Manual
Examples:
If the left and right binding powers of op are both greater the left and right binding
powers of some other operator, then op takes precedence over the other operator.
(%i1) :lisp (get $+ lbp)
100
(%i1) :lisp (get $+ rbp)
100
(%i1) infix ("##", 101, 101);
(%o1) ##
(%i2) "##"(a, b) := sconcat("(", a, ",", b, ")");
(%o2) (a ## b) := sconcat("(", a, ",", b, ")")
(%i3) 1 + a ## b + 2;
(%o3) (a,b) + 3
(%i4) infix ("##", 99, 99);
(%o4) ##
(%i5) 1 + a ## b + 2;
(%o5) (a+1,b+2)
Greater lbp makes op right-associative, while greater rbp makes op left-associative.
(%i1) infix ("##", 100, 99);
(%o1) ##
(%i2) "##"(a, b) := sconcat("(", a, ",", b, ")")$
(%i3) foo ## bar ## baz;
(%o3) (foo,(bar,baz))
(%i4) infix ("##", 100, 101);
(%o4) ##
(%i5) foo ## bar ## baz;
(%o5) ((foo,bar),baz)
Maxima can detect some syntax errors by comparing the declared part of speech to
an actual expression.
(%i1) infix ("##", 100, 99, expr, expr, expr);
(%o1) ##
(%i2) if x ## y then 1 else 0;
Incorrect syntax: Found algebraic expression where logical
expression expected
if x ## y then
^
(%i2) infix ("##", 100, 99, expr, expr, clause);
(%o2) ##
(%i3) if x ## y then 1 else 0;
(%o3) if x ## y then 1 else 0
Function matchx (ldelimiter, rdelimiter)
Function matchx (ldelimiter, rdelimiter, arg pos, pos)
Declares a matchx operator with left and right delimiters ldelimiter and rdelimiter.
The delimiters are specied as strings.
A "matchx" operator is a function of any number of arguments, such that the
arguments occur between matching left and right delimiters. The delimiters may be
Chapter 7: Operators 111
any strings, so long as the parser can distinguish the delimiters from the operands
and other expressions and operators. In practice this rules out unparseable delimiters
such as %, ,, $ and ;, and may require isolating the delimiters with white space. The
right delimiter can be the same or dierent from the left delimiter.
A left delimiter can be associated with only one right delimiter; two dierent matchx
operators cannot have the same left delimiter.
An existing operator may be redeclared as a matchx operator without changing its
other properties. In particular, built-in operators such as addition + can be declared
matchx, but operator functions cannot be dened for built-in operators.
The command matchfix (ldelimiter, rdelimiter, arg pos, pos) declares the argu-
ment part-of-speech arg pos and result part-of-speech pos, and the delimiters lde-
limiter and rdelimiter.
"Part of speech", in reference to operator declarations, means expression type. Three
types are recognized: expr, clause, and any, indicating an algebraic expression, a
Boolean expression, or any kind of expression, respectively. Maxima can detect some
syntax errors by comparing the declared part of speech to an actual expression.
The function to carry out a matchx operation is an ordinary user-dened function.
The operator function is dened in the usual way with the function denition operator
:= or define. The arguments may be written between the delimiters, or with the
left delimiter as a quoted string and the arguments following in parentheses. dispfun
(ldelimiter) displays the function denition.
The only built-in matchx operator is the list constructor [ ]. Parentheses ( ) and
double-quotes " " act like matchx operators, but are not treated as such by the
Maxima parser.
matchfix evaluates its arguments. matchfix returns its rst argument, ldelimiter.
Examples:
Delimiters may be almost any strings.
(%i1) matchfix ("@@", "~");
(%o1) @@
(%i2) @@ a, b, c ~;
(%o2) @@a, b, c~
(%i3) matchfix (">>", "<<");
(%o3) >>
(%i4) >> a, b, c <<;
(%o4) >>a, b, c<<
(%i5) matchfix ("foo", "oof");
(%o5) foo
(%i6) foo a, b, c oof;
(%o6) fooa, b, coof
(%i7) >> w + foo x, y oof + z << / @@ p, q ~;
>>z + foox, yoof + w<<
(%o7) ----------------------
@@p, q~
Matchx operators are ordinary user-dened functions.
(%i1) matchfix ("!-", "-!");
112 Maxima 5.30.0 Manual
(%o1) "!-"
(%i2) !- x, y -! := x/y - y/x;
x y
(%o2) !-x, y-! := - - -
y x
(%i3) define (!-x, y-!, x/y - y/x);
x y
(%o3) !-x, y-! := - - -
y x
(%i4) define ("!-" (x, y), x/y - y/x);
x y
(%o4) !-x, y-! := - - -
y x
(%i5) dispfun ("!-");
x y
(%t5) !-x, y-! := - - -
y x
(%o5) done
(%i6) !-3, 5-!;
16
(%o6) - --
15
(%i7) "!-" (3, 5);
16
(%o7) - --
15
Function nary (op)
Function nary (op, bp, arg pos, pos)
An nary operator is used to denote a function of any number of arguments, each
of which is separated by an occurrence of the operator, e.g. A+B or A+B+C. The
nary("x") function is a syntax extension function to declare x to be an nary operator.
Functions may be declared to be nary. If declare(j,nary); is done, this tells the
simplier to simplify, e.g. j(j(a,b),j(c,d)) to j(a, b, c, d).
See also Section 7.1 [Introduction to operators], page 95.
Function nox (op)
Function nox (op, pos)
nofix operators are used to denote functions of no arguments. The mere presence of
such an operator in a command will cause the corresponding function to be evaluated.
For example, when one types "exit;" to exit from a Maxima break, "exit" is behaving
similar to a nofix operator. The function nofix("x") is a syntax extension function
which declares x to be a nofix operator.
See also Section 7.1 [Introduction to operators], page 95.
Chapter 7: Operators 113
Function postx (op)
Function postx (op, lbp, lpos, pos)
postfix operators like the prefix variety denote functions of a single argument, but
in this case the argument immediately precedes an occurrence of the operator in the
input string, e.g. 3!. The postfix("x") function is a syntax extension function to
declare x to be a postfix operator.
See also Section 7.1 [Introduction to operators], page 95.
Function prex (op)
Function prex (op, rbp, rpos, pos)
A prefix operator is one which signies a function of one argument, which argument
immediately follows an occurrence of the operator. prefix("x") is a syntax extension
function to declare x to be a prefix operator.
See also Section 7.1 [Introduction to operators], page 95.
114 Maxima 5.30.0 Manual
Chapter 8: Evaluation 115
8 Evaluation
8.1 Functions and Variables for Evaluation
Operator
The single quote operator prevents evaluation.
Applied to a symbol, the single quote prevents evaluation of the symbol.
Applied to a function call, the single quote prevents evaluation of the function call, al-
though the arguments of the function are still evaluated (if evaluation is not otherwise
prevented). The result is the noun form of the function call.
Applied to a parenthesized expression, the single quote prevents evaluation of all
symbols and function calls in the expression. E.g., (f(x)) means do not evaluate
the expression f(x). f(x) (with the single quote applied to f instead of f(x)) means
return the noun form of f applied to [x].
The single quote does not prevent simplication.
When the global ag noundisp is true, nouns display with a single quote. This
switch is always true when displaying function denitions.
See also the quote-quote operator and nouns.
Examples:
Applied to a symbol, the single quote prevents evaluation of the symbol.
(%i1) aa: 1024;
(%o1) 1024
(%i2) aa^2;
(%o2) 1048576
(%i3) aa^2;
2
(%o3) aa
(%i4) %;
(%o4) 1048576
Applied to a function call, the single quote prevents evaluation of the function call.
The result is the noun form of the function call.
(%i1) x0: 5;
(%o1) 5
(%i2) x1: 7;
(%o2) 7
(%i3) integrate (x^2, x, x0, x1);
218
(%o3) ---
3
(%i4) integrate (x^2, x, x0, x1);
116 Maxima 5.30.0 Manual
7
/
[ 2
(%o4) I x dx
]
/
5
(%i5) %, nouns;
218
(%o5) ---
3
Applied to a parenthesized expression, the single quote prevents evaluation of all
symbols and function calls in the expression.
(%i1) aa: 1024;
(%o1) 1024
(%i2) bb: 19;
(%o2) 19
(%i3) sqrt(aa) + bb;
(%o3) 51
(%i4) (sqrt(aa) + bb);
(%o4) bb + sqrt(aa)
(%i5) %;
(%o5) 51
The single quote does not prevent simplication.
(%i1) sin (17 * %pi) + cos (17 * %pi);
(%o1) - 1
(%i2) (sin (17 * %pi) + cos (17 * %pi));
(%o2) - 1
Maxima considers oating point operations by its in-built mathematical functions to
be a simplication.
(%i1) sin(1.0);
(%o1) .8414709848078965
(%i2) (sin(1.0));
(%o2) .8414709848078965
Operator
The quote-quote operator (two single quote marks) modies evaluation in input
expressions.
Applied to a general expression expr, quote-quote causes the value of expr to be
substituted for expr in the input expression.
Applied to the operator of an expression, quote-quote changes the operator from a
noun to a verb (if it is not already a verb).
The quote-quote operator is applied by the input parser; it is not stored as part
of a parsed input expression. The quote-quote operator is always applied as soon
as it is parsed, and cannot be quoted. Thus quote-quote causes evaluation when
Chapter 8: Evaluation 117
evaluation is otherwise suppressed, such as in function denitions, lambda expressions,
and expressions quoted by single quote .
Quote-quote is recognized by batch and load.
See also the single-quote operator and nouns.
Examples:
Applied to a general expression expr, quote-quote causes the value of expr to be
substituted for expr in the input expression.
(%i1) expand ((a + b)^3);
3 2 2 3
(%o1) b + 3 a b + 3 a b + a
(%i2) [_, _];
3 3 2 2 3
(%o2) [expand((b + a) ), b + 3 a b + 3 a b + a ]
(%i3) [%i1, %i1];
3 3 2 2 3
(%o3) [expand((b + a) ), b + 3 a b + 3 a b + a ]
(%i4) [aa : cc, bb : dd, cc : 17, dd : 29];
(%o4) [cc, dd, 17, 29]
(%i5) foo_1 (x) := aa - bb * x;
(%o5) foo_1(x) := aa - bb x
(%i6) foo_1 (10);
(%o6) cc - 10 dd
(%i7) %;
(%o7) - 273
(%i8) (foo_1 (10));
(%o8) - 273
(%i9) foo_2 (x) := aa - bb * x;
(%o9) foo_2(x) := cc - dd x
(%i10) foo_2 (10);
(%o10) - 273
(%i11) [x0 : x1, x1 : x2, x2 : x3];
(%o11) [x1, x2, x3]
(%i12) x0;
(%o12) x1
(%i13) x0;
(%o13) x2
(%i14) x0;
(%o14) x3
Applied to the operator of an expression, quote-quote changes the operator from a
noun to a verb (if it is not already a verb).
(%i1) declare (foo, noun);
(%o1) done
(%i2) foo (x) := x - 1729;
(%o2) foo(x) := x - 1729
(%i3) foo (100);
(%o3) foo(100)
(%i4) foo (100);
118 Maxima 5.30.0 Manual
(%o4) - 1629
The quote-quote operator is applied by the input parser; it is not stored as part of a
parsed input expression.
(%i1) [aa : bb, cc : dd, bb : 1234, dd : 5678];
(%o1) [bb, dd, 1234, 5678]
(%i2) aa + cc;
(%o2) dd + bb
(%i3) display (_, op (_), args (_));
_ = cc + aa
op(cc + aa) = +
args(cc + aa) = [cc, aa]
(%o3) done
(%i4) (aa + cc);
(%o4) 6912
(%i5) display (_, op (_), args (_));
_ = dd + bb
op(dd + bb) = +
args(dd + bb) = [dd, bb]
(%o5) done
Quote-quote causes evaluation when evaluation is otherwise suppressed, such as in
function denitions, lambda expressions, and expressions quoted by single quote .
(%i1) foo_1a (x) := (integrate (log (x), x));
(%o1) foo_1a(x) := x log(x) - x
(%i2) foo_1b (x) := integrate (log (x), x);
(%o2) foo_1b(x) := integrate(log(x), x)
(%i3) dispfun (foo_1a, foo_1b);
(%t3) foo_1a(x) := x log(x) - x
(%t4) foo_1b(x) := integrate(log(x), x)
(%o4) [%t3, %t4]
(%i5) integrate (log (x), x);
(%o5) x log(x) - x
(%i6) foo_2a (x) := %;
(%o6) foo_2a(x) := x log(x) - x
(%i7) foo_2b (x) := %;
(%o7) foo_2b(x) := %
(%i8) dispfun (foo_2a, foo_2b);
(%t8) foo_2a(x) := x log(x) - x
(%t9) foo_2b(x) := %
Chapter 8: Evaluation 119
(%o9) [%t7, %t8]
(%i10) F : lambda ([u], diff (sin (u), u));
(%o10) lambda([u], diff(sin(u), u))
(%i11) G : lambda ([u], (diff (sin (u), u)));
(%o11) lambda([u], cos(u))
(%i12) (sum (a[k], k, 1, 3) + sum (b[k], k, 1, 3));
(%o12) sum(b , k, 1, 3) + sum(a , k, 1, 3)
k k
(%i13) ((sum (a[k], k, 1, 3)) + (sum (b[k], k, 1, 3)));
(%o13) b + a + b + a + b + a
3 3 2 2 1 1
Function ev (expr, arg 1, . . . , arg n)
Evaluates the expression expr in the environment specied by the arguments arg 1,
. . . , arg n. The arguments are switches (Boolean ags), assignments, equations, and
functions. ev returns the result (another expression) of the evaluation.
The evaluation is carried out in steps, as follows.
1. First the environment is set up by scanning the arguments which may be any or
all of the following.
simp causes expr to be simplied regardless of the setting of the switch
simp which inhibits simplication if false.
noeval suppresses the evaluation phase of ev (see step (4) below). This
is useful in conjunction with the other switches and in causing expr to be
resimplied without being reevaluated.
nouns causes the evaluation of noun forms (typically unevaluated functions
such as integrate or diff) in expr.
expand causes expansion.
expand (m, n) causes expansion, setting the values of maxposex and
maxnegex to m and n respectively.
detout causes any matrix inverses computed in expr to have their determi-
nant kept outside of the inverse rather than dividing through each element.
diff causes all dierentiations indicated in expr to be performed.
derivlist (x, y, z, ...) causes only dierentiations with respect to the
indicated variables. See also derivlist.
risch causes integrals in expr to be evaluated using the Risch algorithm.
See risch. The standard integration routine is invoked when using the
special symbol nouns.
float causes non-integral rational numbers to be converted to oating point.
numer causes some mathematical functions (including exponentiation) with
numerical arguments to be evaluated in oating point. It causes variables
in expr which have been given numervals to be replaced by their values. It
also sets the float switch on.
pred causes predicates (expressions which evaluate to true or false) to be
evaluated.
120 Maxima 5.30.0 Manual
eval causes an extra post-evaluation of expr to occur. (See step (5) below.)
eval may occur multiple times. For each instance of eval, the expression is
evaluated again.
A where A is an atom declared to be an evaluation ag evflag causes A to
be bound to true during the evaluation of expr.
V: expression (or alternately V=expression) causes V to be bound to the
value of expression during the evaluation of expr. Note that if V is a
Maxima option, then expression is used for its value during the evaluation
of expr. If more than one argument to ev is of this type then the binding is
done in parallel. If V is a non-atomic expression then a substitution rather
than a binding is performed.
F where F, a function name, has been declared to be an evaluation function
evfun causes F to be applied to expr.
Any other function names, e.g. sum, cause evaluation of occurrences of those
names in expr as though they were verbs.
In addition a function occurring in expr (say F(x)) may be dened locally
for the purpose of this evaluation of expr by giving F(x) := expression as
an argument to ev.
If an atom not mentioned above or a subscripted variable or subscripted
expression was given as an argument, it is evaluated and if the result is an
equation or assignment then the indicated binding or substitution is per-
formed. If the result is a list then the members of the list are treated as if
they were additional arguments given to ev. This permits a list of equations
to be given (e.g. [X=1, Y=A**2]) or a list of names of equations (e.g., [%t1,
%t2] where %t1 and %t2 are equations) such as that returned by solve.
The arguments of ev may be given in any order with the exception of substi-
tution equations which are handled in sequence, left to right, and evaluation
functions which are composed, e.g., ev (expr, ratsimp, realpart) is handled
as realpart (ratsimp (expr)).
The simp, numer, and float switches may also be set locally in a block, or
globally in Maxima so that they will remain in eect until being reset.
If expr is a canonical rational expression (CRE), then the expression returned by
ev is also a CRE, provided the numer and float switches are not both true.
2. During step (1), a list is made of the non-subscripted variables appearing on the
left side of equations in the arguments or in the value of some arguments if the
value is an equation. The variables (subscripted variables which do not have
associated array functions as well as non-subscripted variables) in the expression
expr are replaced by their global values, except for those appearing in this list.
Usually, expr is just a label or % (as in %i2 in the example below), so this step
simply retrieves the expression named by the label, so that ev may work on it.
3. If any substitutions are indicated by the arguments, they are carried out now.
4. The resulting expression is then re-evaluated (unless one of the arguments was
noeval ) and simplied according to the arguments. Note that any function
calls in expr will be carried out after the variables in it are evaluated and that
ev(F(x)) thus may behave like F(ev(x)).
Chapter 8: Evaluation 121
5. For each instance of eval in the arguments, steps (3) and (4) are repeated.
Examples:
(%i1) sin(x) + cos(y) + (w+1)^2 + diff (sin(w), w);
d 2
(%o1) cos(y) + sin(x) + -- (sin(w)) + (w + 1)
dw
(%i2) ev (%, numer, expand, diff, x=2, y=1);
2
(%o2) cos(w) + w + 2 w + 2.449599732693821
An alternate top level syntax has been provided for ev, whereby one may just type
in its arguments, without the ev(). That is, one may write simply
expr, arg 1, ..., arg n
This is not permitted as part of another expression, e.g., in functions, blocks, etc.
Notice the parallel binding process in the following example.
(%i3) programmode: false;
(%o3) false
(%i4) x+y, x: a+y, y: 2;
(%o4) y + a + 2
(%i5) 2*x - 3*y = 3$
(%i6) -3*x + 2*y = -4$
(%i7) solve ([%o5, %o6]);
Solution
1
(%t7) y = - -
5
6
(%t8) x = -
5
(%o8) [[%t7, %t8]]
(%i8) %o6, %o8;
(%o8) - 4 = - 4
(%i9) x + 1/x > gamma (1/2);
1
(%o9) x + - > sqrt(%pi)
x
(%i10) %, numer, x=1/2;
(%o10) 2.5 > 1.772453850905516
(%i11) %, pred;
(%o11) true
Special symbol eval
As an argument in a call to ev (expr), eval causes an extra evaluation of expr. See
ev.
Example:
122 Maxima 5.30.0 Manual
(%i1) [a:b,b:c,c:d,d:e];
(%o1) [b, c, d, e]
(%i2) a;
(%o2) b
(%i3) ev(a);
(%o3) c
(%i4) ev(a),eval;
(%o4) e
(%i5) a,eval,eval;
(%o5) e
Property evag
When a symbol x has the evflag property, the expressions ev(expr, x) and expr,
x (at the interactive prompt) are equivalent to ev(expr, x = true). That is, x is
bound to true while expr is evaluated.
The expression declare(x, evflag) gives the evflag property to the variable x.
The ags which have the evflag property by default are the following:
algebraic cauchysum demoivre
dotscrules %emode %enumer
exponentialize exptisolate factorflag
float halfangles infeval
isolate_wrt_times keepfloat letrat
listarith logabs logarc
logexpand lognegint
m1pbranch numer_pbranch programmode
radexpand ratalgdenom ratfac
ratmx ratsimpexpons simp
simpproduct simpsum sumexpand
trigexpand
Examples:
(%i1) sin (1/2);
1
(%o1) sin(-)
2
(%i2) sin (1/2), float;
(%o2) 0.479425538604203
(%i3) sin (1/2), float=true;
(%o3) 0.479425538604203
(%i4) simp : false;
(%o4) false
(%i5) 1 + 1;
(%o5) 1 + 1
(%i6) 1 + 1, simp;
(%o6) 2
(%i7) simp : true;
(%o7) true
Chapter 8: Evaluation 123
(%i8) sum (1/k^2, k, 1, inf);
inf
====
\ 1
(%o8) > --
/ 2
==== k
k = 1
(%i9) sum (1/k^2, k, 1, inf), simpsum;
2
%pi
(%o9) ----
6
(%i10) declare (aa, evflag);
(%o10) done
(%i11) if aa = true then YES else NO;
(%o11) NO
(%i12) if aa = true then YES else NO, aa;
(%o12) YES
Property evfun
When a function F has the evfun property, the expressions ev(expr, F) and expr,
F (at the interactive prompt) are equivalent to F(ev(expr)).
If two or more evfun functions F, G, etc., are specied, the functions are applied in
the order that they are specied.
The expression declare(F, evfun) gives the evfun property to the function F. The
functions which have the evfun property by default are the following:
bfloat factor fullratsimp
logcontract polarform radcan
ratexpand ratsimp rectform
rootscontract trigexpand trigreduce
Examples:
(%i1) x^3 - 1;
3
(%o1) x - 1
(%i2) x^3 - 1, factor;
2
(%o2) (x - 1) (x + x + 1)
(%i3) factor (x^3 - 1);
2
(%o3) (x - 1) (x + x + 1)
(%i4) cos(4 * x) / sin(x)^4;
cos(4 x)
(%o4) --------
4
sin (x)
124 Maxima 5.30.0 Manual
(%i5) cos(4 * x) / sin(x)^4, trigexpand;
4 2 2 4
sin (x) - 6 cos (x) sin (x) + cos (x)
(%o5) -------------------------------------
4
sin (x)
(%i6) cos(4 * x) / sin(x)^4, trigexpand, ratexpand;
2 4
6 cos (x) cos (x)
(%o6) - --------- + ------- + 1
2 4
sin (x) sin (x)
(%i7) ratexpand (trigexpand (cos(4 * x) / sin(x)^4));
2 4
6 cos (x) cos (x)
(%o7) - --------- + ------- + 1
2 4
sin (x) sin (x)
(%i8) declare ([F, G], evfun);
(%o8) done
(%i9) (aa : bb, bb : cc, cc : dd);
(%o9) dd
(%i10) aa;
(%o10) bb
(%i11) aa, F;
(%o11) F(cc)
(%i12) F (aa);
(%o12) F(bb)
(%i13) F (ev (aa));
(%o13) F(cc)
(%i14) aa, F, G;
(%o14) G(F(cc))
(%i15) G (F (ev (aa)));
(%o15) G(F(cc))
Option variable infeval
Enables "innite evaluation" mode. ev repeatedly evaluates an expression until it
stops changing. To prevent a variable, say X, from being evaluated away in this
mode, simply include X=X as an argument to ev. Of course expressions such as ev
(X, X=X+1, infeval) will generate an innite loop.
Special symbol noeval
noeval suppresses the evaluation phase of ev. This is useful in conjunction with
other switches and in causing expressions to be resimplied without being reevaluated.
Chapter 8: Evaluation 125
Special symbol nouns
nouns is an evflag. When used as an option to the ev command, nouns converts
all "noun" forms occurring in the expression being evd to "verbs", i.e., evaluates
them. See also noun, nounify, verb, and verbify.
Special symbol pred
As an argument in a call to ev (expr), pred causes predicates (expressions which
evaluate to true or false) to be evaluated. See ev.
Example:
(%i1) 1<2;
(%o1) 1 < 2
(%i2) 1<2,pred;
(%o2) true
126 Maxima 5.30.0 Manual
Chapter 9: Simplication 127
9 Simplication
9.1 Functions and Variables for Simplication
Property additive
If declare(f,additive) has been executed, then:
(1) If f is univariate, whenever the simplier encounters f applied to a sum, f will be
distributed over that sum. I.e. f(y+x) will simplify to f(y)+f(x).
(2) If f is a function of 2 or more arguments, additivity is dened as additivity in
the rst argument to f, as in the case of sum or integrate, i.e. f(h(x)+g(x),x)
will simplify to f(h(x),x)+f(g(x),x). This simplication does not occur when f is
applied to expressions of the form sum(x[i],i,lower-limit,upper-limit).
Example:
(%i1) F3 (a + b + c);
(%o1) F3(c + b + a)
(%i2) declare (F3, additive);
(%o2) done
(%i3) F3 (a + b + c);
(%o3) F3(c) + F3(b) + F3(a)
Property antisymmetric
If declare(h,antisymmetric) is done, this tells the simplier that h is antisymmet-
ric. E.g. h(x,z,y) will simplify to - h(x, y, z). That is, it will give (-1)^n times the
result given by symmetric or commutative, where n is the number of interchanges of
two arguments necessary to convert it to that form.
Examples:
(%i1) S (b, a);
(%o1) S(b, a)
(%i2) declare (S, symmetric);
(%o2) done
(%i3) S (b, a);
(%o3) S(a, b)
(%i4) S (a, c, e, d, b);
(%o4) S(a, b, c, d, e)
(%i5) T (b, a);
(%o5) T(b, a)
(%i6) declare (T, antisymmetric);
(%o6) done
(%i7) T (b, a);
(%o7) - T(a, b)
(%i8) T (a, c, e, d, b);
(%o8) T(a, b, c, d, e)
Function combine (expr)
Simplies the sum expr by combining terms with the same denominator into a single
term.
128 Maxima 5.30.0 Manual
Property commutative
If declare(h, commutative) is done, this tells the simplier that h is a commutative
function. E.g. h(x, z, y) will simplify to h(x, y, z). This is the same as symmetric.
Function demoivre (expr)
Option variable demoivre
The function demoivre (expr) converts one expression without setting the global
variable demoivre.
When the variable demoivre is true, complex exponentials are converted into equiv-
alent expressions in terms of circular functions: exp (a + b*%i) simplies to %e^a *
(cos(b) + %i*sin(b)) if b is free of %i. a and b are not expanded.
The default value of demoivre is false.
exponentialize converts circular and hyperbolic functions to exponential form.
demoivre and exponentialize cannot both be true at the same time.
Function distrib (expr)
Distributes sums over products. It diers from expand in that it works at only the
top level of an expression, i.e., it doesnt recurse and it is faster than expand. It
diers from multthru in that it expands all sums at that level.
Examples:
(%i1) distrib ((a+b) * (c+d));
(%o1) b d + a d + b c + a c
(%i2) multthru ((a+b) * (c+d));
(%o2) (b + a) d + (b + a) c
(%i3) distrib (1/((a+b) * (c+d)));
1
(%o3) ---------------
(b + a) (d + c)
(%i4) expand (1/((a+b) * (c+d)), 1, 0);
1
(%o4) ---------------------
b d + a d + b c + a c
Option variable distribute over
Default value: true
distribute_over controls the mapping of functions over bags like lists, matrices, and
equations. At this time not all Maxima functions have this property. It is possible to
look up this property with the command properties.
The mapping of functions is switched o, when setting distribute_over to the value
false.
Examples:
The sin function maps over a list:
Chapter 9: Simplication 129
(%i1) sin([x,1,1.0]);
(%o1) [sin(x), sin(1), .8414709848078965]
mod is a function with two arguments which maps over lists. Mapping over nested
lists is possible too:
(%i2) mod([x,11,2*a],10);
(%o2) [mod(x, 10), 1, 2 mod(a, 5)]
(%i3) mod([[x,y,z],11,2*a],10);
(%o3) [[mod(x, 10), mod(y, 10), mod(z, 10)], 1, 2 mod(a, 5)]
Mapping of the floor function over a matrix and an equation:
(%i4) floor(matrix([a,b],[c,d]));
[ floor(a) floor(b) ]
(%o4) [ ]
[ floor(c) floor(d) ]
(%i5) floor(a=b);
(%o5) floor(a) = floor(b)
Functions with more than one argument map over any of the arguments or all argu-
ments:
(%i6) expintegral_e([1,2],[x,y]);
(%o6) [[expintegral_e(1, x), expintegral_e(1, y)],
[expintegral_e(2, x), expintegral_e(2, y)]]
Check if a function has the property distribute over:
(%i7) properties(abs);
(%o7) [integral, distributes over bags, noun, rule, gradef]
Option variable domain
Default value: real
When domain is set to complex, sqrt (x^2) will remain sqrt (x^2) instead of re-
turning abs(x).
Property evenfun
Property oddfun
declare(f, evenfun) or declare(f, oddfun) tells Maxima to recognize the function
f as an even or odd function.
Examples:
(%i1) o (- x) + o (x);
(%o1) o(x) + o(- x)
(%i2) declare (o, oddfun);
(%o2) done
(%i3) o (- x) + o (x);
(%o3) 0
(%i4) e (- x) - e (x);
(%o4) e(- x) - e(x)
(%i5) declare (e, evenfun);
(%o5) done
(%i6) e (- x) - e (x);
(%o6) 0
130 Maxima 5.30.0 Manual
Function expand (expr)
Function expand (expr, p, n)
Expand expression expr. Products of sums and exponentiated sums are multiplied
out, numerators of rational expressions which are sums are split into their respective
terms, and multiplication (commutative and non-commutative) are distributed over
addition at all levels of expr.
For polynomials one should usually use ratexpand which uses a more ecient algo-
rithm.
maxnegex and maxposex control the maximum negative and positive exponents, re-
spectively, which will expand.
expand (expr, p, n) expands expr, using p for maxposex and n for maxnegex. This
is useful in order to expand part but not all of an expression.
expon - the exponent of the largest negative power which is automatically expanded
(independent of calls to expand). For example if expon is 4 then (x+1)^(-5) will not
be automatically expanded.
expop - the highest positive exponent which is automatically expanded. Thus
(x+1)^3, when typed, will be automatically expanded only if expop is greater than
or equal to 3. If it is desired to have (x+1)^n expanded where n is greater than
expop then executing expand ((x+1)^n) will work only if maxposex is not less than
n.
expand(expr, 0, 0) causes a resimplication of expr. expr is not reevaluated. In
distinction from ev(expr, noeval) a special representation (e. g. a CRE form) is
removed. See also ev.
The expand ag used with ev causes expansion.
The le share/simplification/facexp.mac contains several related functions (in
particular facsum, factorfacsum and collectterms, which are autoloaded) and
variables (nextlayerfactor and facsum_combine) that provide the user with the
ability to structure expressions by controlled expansion. Brief function descrip-
tions are available in simplification/facexp.usg. A demo is available by doing
demo("facexp").
Examples:
(%i1) expr:(x+1)^2*(y+1)^3;
2 3
(%o1) (x + 1) (y + 1)
(%i2) expand(expr);
2 3 3 3 2 2 2 2 2
(%o2) x y + 2 x y + y + 3 x y + 6 x y + 3 y + 3 x y
2
+ 6 x y + 3 y + x + 2 x + 1
(%i3) expand(expr,2);
2 3 3 3
(%o3) x (y + 1) + 2 x (y + 1) + (y + 1)
(%i4) expr:(x+1)^-2*(y+1)^3;
3
(y + 1)
Chapter 9: Simplication 131
(%o4) --------
2
(x + 1)
(%i5) expand(expr);
3 2
y 3 y 3 y 1
(%o5) ------------ + ------------ + ------------ + ------------
2 2 2 2
x + 2 x + 1 x + 2 x + 1 x + 2 x + 1 x + 2 x + 1
(%i6) expand(expr,2,2);
3
(y + 1)
(%o6) ------------
2
x + 2 x + 1
Resimplify an expression without expansion:
(%i7) expr:(1+x)^2*sin(x);
2
(%o7) (x + 1) sin(x)
(%i8) exponentialize:true;
(%o8) true
(%i9) expand(expr,0,0);
2 %i x - %i x
%i (x + 1) (%e - %e )
(%o9) - -------------------------------
2
Function expandwrt (expr, x 1, . . . , x n)
Expands expression expr with respect to the variables x 1, . . . , x n. All products
involving the variables appear explicitly. The form returned will be free of products of
sums of expressions that are not free of the variables. x 1, . . . , x n may be variables,
operators, or expressions.
By default, denominators are not expanded, but this can be controlled by means of
the switch expandwrt_denom.
This function is autoloaded from simplification/stopex.mac.
Option variable expandwrt denom
Default value: false
expandwrt_denom controls the treatment of rational expressions by expandwrt. If
true, then both the numerator and denominator of the expression will be expanded
according to the arguments of expandwrt, but if expandwrt_denom is false, then
only the numerator will be expanded in that way.
Function expandwrt factored (expr, x 1, . . . , x n)
is similar to expandwrt, but treats expressions that are products somewhat dierently.
expandwrt_factored expands only on those factors of expr that contain the variables
x 1, . . . , x n.
132 Maxima 5.30.0 Manual
This function is autoloaded from simplification/stopex.mac.
Option variable expon
Default value: 0
expon is the exponent of the largest negative power which is automatically expanded
(independent of calls to expand). For example, if expon is 4 then (x+1)^(-5) will
not be automatically expanded.
Function exponentialize (expr)
Option variable exponentialize
The function exponentialize (expr) converts circular and hyperbolic functions in
expr to exponentials, without setting the global variable exponentialize.
When the variable exponentialize is true, all circular and hyperbolic functions are
converted to exponential form. The default value is false.
demoivre converts complex exponentials into circular functions. exponentialize
and demoivre cannot both be true at the same time.
Option variable expop
Default value: 0
expop is the highest positive exponent which is automatically expanded. Thus (x +
1)^3, when typed, will be automatically expanded only if expop is greater than or
equal to 3. If it is desired to have (x + 1)^n expanded where n is greater than expop
then executing expand ((x + 1)^n) will work only if maxposex is not less than n.
Property lassociative
declare (g, lassociative) tells the Maxima simplier that g is left-associative.
E.g., g (g (a, b), g (c, d)) will simplify to g (g (g (a, b), c), d).
Property linear
One of Maximas operator properties. For univariate f so declared, "expansion" f(x
+ y) yields f(x) + f(y), f(a*x) yields a*f(x) takes place where a is a "constant".
For functions of two or more arguments, "linearity" is dened to be as in the case of
sum or integrate, i.e., f (a*x + b, x) yields a*f(x,x) + b*f(1,x) for a and b free
of x.
linear is equivalent to additive and outative. See also opproperties.
Example:
(%i1) sum (F(k) + G(k), k, 1, inf);
inf
====
\
(%o1) > (G(k) + F(k))
/
====
Chapter 9: Simplication 133
k = 1
(%i2) declare (nounify (sum), linear);
(%o2) done
(%i3) sum (F(k) + G(k), k, 1, inf);
inf inf
==== ====
\ \
(%o3) > G(k) + > F(k)
/ /
==== ====
k = 1 k = 1
Option variable maxnegex
Default value: 1000
maxnegex is the largest negative exponent which will be expanded by the expand
command (see also maxposex).
Option variable maxposex
Default value: 1000
maxposex is the largest exponent which will be expanded with the expand command
(see also maxnegex).
Property multiplicative
declare(f, multiplicative) tells the Maxima simplier that f is multiplicative.
1. If f is univariate, whenever the simplier encounters f applied to a product, f
distributes over that product. E.g., f(x*y) simplies to f(x)*f(y).
2. If f is a function of 2 or more arguments, multiplicativity is dened as multiplica-
tivity in the rst argument to f, e.g., f (g(x) * h(x), x) simplies to f (g(x)
,x) * f (h(x), x).
This simplication does not occur when f is applied to expressions of the form product
(x[i], i, m, n).
Example:
(%i1) F2 (a * b * c);
(%o1) F2(a b c)
(%i2) declare (F2, multiplicative);
(%o2) done
(%i3) F2 (a * b * c);
(%o3) F2(a) F2(b) F2(c)
Function multthru (expr)
Function multthru (expr 1, expr 2)
Multiplies a factor (which should be a sum) of expr by the other factors of expr. That
is, expr is f 1 f 2 ... f n where at least one factor, say f i, is a sum of terms. Each
term in that sum is multiplied by the other factors in the product. (Namely all the
134 Maxima 5.30.0 Manual
factors except f i). multthru does not expand exponentiated sums. This function is
the fastest way to distribute products (commutative or noncommutative) over sums.
Since quotients are represented as products multthru can be used to divide sums by
products as well.
multthru (expr 1, expr 2) multiplies each term in expr 2 (which should be a sum
or an equation) by expr 1. If expr 1 is not itself a sum then this form is equivalent
to multthru (expr 1*expr 2).
(%i1) x/(x-y)^2 - 1/(x-y) - f(x)/(x-y)^3;
1 x f(x)
(%o1) - ----- + -------- - --------
x - y 2 3
(x - y) (x - y)
(%i2) multthru ((x-y)^3, %);
2
(%o2) - (x - y) + x (x - y) - f(x)
(%i3) ratexpand (%);
2
(%o3) - y + x y - f(x)
(%i4) ((a+b)^10*s^2 + 2*a*b*s + (a*b)^2)/(a*b*s^2);
10 2 2 2
(b + a) s + 2 a b s + a b
(%o4) ------------------------------
2
a b s
(%i5) multthru (%); /* note that this does not expand (b+a)^10 */
10
2 a b (b + a)
(%o5) - + --- + ---------
s 2 a b
s
(%i6) multthru (a.(b+c.(d+e)+f));
(%o6) a . f + a . c . (e + d) + a . b
(%i7) expand (a.(b+c.(d+e)+f));
(%o7) a . f + a . c . e + a . c . d + a . b
Property nary
declare(f, nary) tells Maxima to recognize the function f as an n-ary function.
The nary declaration is not the same as calling the nary function. The sole eect of
declare(f, nary) is to instruct the Maxima simplier to atten nested expressions,
for example, to simplify foo(x, foo(y, z)) to foo(x, y, z). See also declare.
Example:
(%i1) H (H (a, b), H (c, H (d, e)));
(%o1) H(H(a, b), H(c, H(d, e)))
(%i2) declare (H, nary);
(%o2) done
(%i3) H (H (a, b), H (c, H (d, e)));
(%o3) H(a, b, c, d, e)
Chapter 9: Simplication 135
Option variable negdistrib
Default value: true
When negdistrib is true, -1 distributes over an expression. E.g., -(x + y) becomes
- y - x. Setting it to false will allow - (x + y) to be displayed like that. This is
sometimes useful but be very careful: like the simp ag, this is one ag you do not
want to set to false as a matter of course or necessarily for other than local use in
your Maxima.
System variable opproperties
opproperties is the list of the special operator properties recognized by the Max-
ima simplier: linear, additive, multiplicative, outative, evenfun, oddfun,
commutative, symmetric, antisymmetric, nary, lassociative, rassociative.
Property outative
declare(f, outative) tells the Maxima simplier that constant factors in the argu-
ment of f can be pulled out.
1. If f is univariate, whenever the simplier encounters f applied to a product, that
product will be partitioned into factors that are constant and factors that are not
and the constant factors will be pulled out. E.g., f(a*x) will simplify to a*f(x)
where a is a constant. Non-atomic constant factors will not be pulled out.
2. If f is a function of 2 or more arguments, outativity is dened as in the case of
sum or integrate, i.e., f (a*g(x), x) will simplify to a * f(g(x), x) for a free
of x.
sum, integrate, and limit are all outative.
Example:
(%i1) F1 (100 * x);
(%o1) F1(100 x)
(%i2) declare (F1, outative);
(%o2) done
(%i3) F1 (100 * x);
(%o3) 100 F1(x)
(%i4) declare (zz, constant);
(%o4) done
(%i5) F1 (zz * y);
(%o5) zz F1(y)
Function radcan (expr)
Simplies expr, which can contain logs, exponentials, and radicals, by converting it
into a form which is canonical over a large class of expressions and a given ordering
of variables; that is, all functionally equivalent forms are mapped into a unique form.
For a somewhat larger class of expressions, radcan produces a regular form. Two
equivalent expressions in this class do not necessarily have the same appearance, but
their dierence can be simplied by radcan to zero.
136 Maxima 5.30.0 Manual
For some expressions radcan is quite time consuming. This is the cost of exploring
certain relationships among the components of the expression for simplications based
on factoring and partial-fraction expansions of exponents.
Examples:
(%i1) radcan((log(x+x^2)-log(x))^a/log(1+x)^(a/2));
a/2
(%o1) log(x + 1)
(%i2) radcan((log(1+2*a^x+a^(2*x))/log(1+a^x)));
(%o2) 2
(%i3) radcan((%e^x-1)/(1+%e^(x/2)));
x/2
(%o3) %e - 1
Option variable radexpand
Default value: true
radexpand controls some simplications of radicals.
When radexpand is all, causes nth roots of factors of a product which are powers
of n to be pulled outside of the radical. E.g. if radexpand is all, sqrt (16*x^2)
simplies to 4*x.
More particularly, consider sqrt (x^2).
If radexpand is all or assume (x > 0) has been executed, sqrt(x^2) simplies
to x.
If radexpand is true and domain is real (its default), sqrt(x^2) simplies to
abs(x).
If radexpand is false, or radexpand is true and domain is complex, sqrt(x^2)
is not simplied.
Note that domain only matters when radexpand is true.
Property rassociative
declare (g, rassociative) tells the Maxima simplier that g is right-associative.
E.g., g(g(a, b), g(c, d)) simplies to g(a, g(b, g(c, d))).
Function scsimp (expr, rule 1, . . . , rule n)
Sequential Comparative Simplication (method due to Stoute). scsimp attempts to
simplify expr according to the rules rule 1, . . . , rule n. If a smaller expression is
obtained, the process repeats. Otherwise after all simplications are tried, it returns
the original answer.
example (scsimp) displays some examples.
Chapter 9: Simplication 137
Option variable simp
Default value: true
simp enables simplication. This is the standard. simp is also an evflag, which is
recognized by the function ev. See ev.
When simp is used as an evflag with a value false, the simplication is suppressed
only during the evaluation phase of an expression. The ag can not suppress the
simplication which follows the evaluation phase.
Examples:
The simplication is switched o globally. The expression sin(1.0) is not simplied
to its numerical value. The simp-ag switches the simplication on.
(%i1) simp:false;
(%o1) false
(%i2) sin(1.0);
(%o2) sin(1.0)
(%i3) sin(1.0),simp;
(%o3) .8414709848078965
The simplication is switched on again. The simp-ag cannot suppress the simpli-
cation completely. The output shows a simplied expression, but the variable x has
an unsimplied expression as a value, because the assignment has occurred during
the evaluation phase of the expression.
(%i4) simp:true;
(%o4) true
(%i5) x:sin(1.0),simp:false;
(%o5) .8414709848078965
(%i6) :lisp $X
((%SIN) 1.0)
Property symmetric
declare (h, symmetric) tells the Maxima simplier that h is a symmetric function.
E.g., h (x, z, y) simplies to h (x, y, z).
commutative is synonymous with symmetric.
Function xthru (expr)
Combines all terms of expr (which should be a sum) over a common denominator
without expanding products and exponentiated sums as ratsimp does. xthru cancels
common factors in the numerator and denominator of rational expressions but only
if the factors are explicit.
Sometimes it is better to use xthru before ratsimping an expression in order to
cause explicit factors of the gcd of the numerator and denominator to be canceled
thus simplifying the expression to be ratsimped.
Examples:
(%i1) ((x+2)^20 - 2*y)/(x+y)^20 + (x+y)^(-19) - x/(x+y)^20;
138 Maxima 5.30.0 Manual
20
1 (x + 2) - 2 y x
(%o1) --------- + --------------- - ---------
19 20 20
(y + x) (y + x) (y + x)
(%i2) xthru (%);
20
(x + 2) - y
(%o2) -------------
20
(y + x)
Chapter 10: Mathematical Functions 139
10 Mathematical Functions
10.1 Functions for Numbers
Function abs (z)
The abs function represents the mathematical absolute value function and works
for both numerical and symbolic values. If the argument, z, is a real or complex
number, abs returns the absolute value of z. If possible, symbolic expressions using
the absolute value function are also simplied.
Maxima can dierentiate, integrate and calculate limits for expressions containing
abs. The abs_integrate package further extends Maximas ability to calculate in-
tegrals involving the abs function. See (%i12) in the examples below.
When applied to a list or matrix, abs automatically distributes over the terms. Sim-
ilarly, it distributes over both sides of an equation. To alter this behaviour, see the
variable distribute_over.
Examples:
Calculation of abs for real and complex numbers, including numerical constants and
various innities. The rst example shows how abs distributes over the elements of
a list.
(%i1) abs([-4, 0, 1, 1+%i]);
(%o1) [4, 0, 1, sqrt(2)]
(%i2) abs((1+%i)*(1-%i));
(%o2) 2
(%i3) abs(%e+%i);
2
(%o3) sqrt(%e + 1)
(%i4) abs([inf, infinity, minf]);
(%o4) [inf, inf, inf]
Simplication of expressions containing abs:
(%i5) abs(x^2);
2
(%o5) x
(%i6) abs(x^3);
2
(%o6) x abs(x)
(%i7) abs(abs(x));
(%o7) abs(x)
(%i8) abs(conjugate(x));
(%o8) abs(x)
Integrating and dierentiating with the abs function. Note that more integrals in-
volving the abs function can be performed, if the abs_integrate package is loaded.
The last example shows the Laplace transform of abs: see laplace.
140 Maxima 5.30.0 Manual
(%i9) diff(x*abs(x),x),expand;
(%o9) 2 abs(x)
(%i10) integrate(abs(x),x);
x abs(x)
(%o10) --------
2
(%i11) integrate(x*abs(x),x);
/
[
(%o11) I x abs(x) dx
]
/
(%i12) load(abs_integrate)$
(%i13) integrate(x*abs(x),x);
2 3
x abs(x) x signum(x)
(%o13) --------- - ------------
2 6
(%i14) integrate(abs(x),x,-2,%pi);
2
%pi
(%o14) ---- + 2
2
(%i15) laplace(abs(x),x,s);
1
(%o15) --
2
s
Function ceiling (x)
When x is a real number, return the least integer that is greater than or equal to x.
If x is a constant expression (10 * %pi, for example), ceiling evaluates x using
big oating point numbers, and applies ceiling to the resulting big oat. Because
ceiling uses oating point evaluation, its possible, although unlikely, that ceiling
could return an erroneous value for constant inputs. To guard against errors, the
oating point evaluation is done using three values for fpprec.
For non-constant inputs, ceiling tries to return a simplied value. Here are examples
of the simplications that ceiling knows about:
(%i1) ceiling (ceiling (x));
(%o1) ceiling(x)
(%i2) ceiling (floor (x));
(%o2) floor(x)
(%i3) declare (n, integer)$
Chapter 10: Mathematical Functions 141
(%i4) [ceiling (n), ceiling (abs (n)), ceiling (max (n, 6))];
(%o4) [n, abs(n), max(n, 6)]
(%i5) assume (x > 0, x < 1)$
(%i6) ceiling (x);
(%o6) 1
(%i7) tex (ceiling (a));
$$\left \lceil a \right \rceil$$
(%o7) false
The function ceiling does not automatically map over lists or matrices. Finally, for
all inputs that are manifestly complex, ceiling returns a noun form.
If the range of a function is a subset of the integers, it can be declared to be
integervalued. Both the ceiling and floor functions can use this information;
for example:
(%i1) declare (f, integervalued)$
(%i2) floor (f(x));
(%o2) f(x)
(%i3) ceiling (f(x) - 1);
(%o3) f(x) - 1
Function entier (x)
Returns the largest integer less than or equal to x where x is numeric. fix (as in
fixnum) is a synonym for this, so fix(x) is precisely the same.
Function oor (x)
When x is a real number, return the largest integer that is less than or equal to x.
If x is a constant expression (10 * %pi, for example), floor evaluates x using big
oating point numbers, and applies floor to the resulting big oat. Because floor
uses oating point evaluation, its possible, although unlikely, that floor could return
an erroneous value for constant inputs. To guard against errors, the oating point
evaluation is done using three values for fpprec.
For non-constant inputs, floor tries to return a simplied value. Here are examples
of the simplications that floor knows about:
(%i1) floor (ceiling (x));
(%o1) ceiling(x)
(%i2) floor (floor (x));
(%o2) floor(x)
(%i3) declare (n, integer)$
(%i4) [floor (n), floor (abs (n)), floor (min (n, 6))];
(%o4) [n, abs(n), min(n, 6)]
(%i5) assume (x > 0, x < 1)$
(%i6) floor (x);
(%o6) 0
(%i7) tex (floor (a));
$$\left \lfloor a \right \rfloor$$
(%o7) false
142 Maxima 5.30.0 Manual
The function floor does not automatically map over lists or matrices. Finally, for
all inputs that are manifestly complex, floor returns a noun form.
If the range of a function is a subset of the integers, it can be declared to be
integervalued. Both the ceiling and floor functions can use this information;
for example:
(%i1) declare (f, integervalued)$
(%i2) floor (f(x));
(%o2) f(x)
(%i3) ceiling (f(x) - 1);
(%o3) f(x) - 1
Function x (x)
A synonym for entier (x).
Function lmax (L)
When L is a list or a set, return apply (max, args (L)). When L is not a list or a
set, signal an error. See also lmin and max.
Function lmin (L)
When L is a list or a set, return apply (min, args (L)). When L is not a list or a
set, signal an error. See also lmax and min.
Function max (x 1, . . . , x n)
Return a simplied value for the maximum of the expressions x 1 through x n. When
get (trylevel, maxmin), is 2 or greater, max uses the simplication max (e, -e)
--> |e|. When get (trylevel, maxmin) is 3 or greater, max tries to eliminate
expressions that are between two other arguments; for example, max (x, 2*x, 3*x) -
-> max (x, 3*x). To set the value of trylevel to 2, use put (trylevel, 2, maxmin).
See also min and lmax.
Function min (x 1, . . . , x n)
Return a simplied value for the minimum of the expressions x_1 through x_n. When
get (trylevel, maxmin), is 2 or greater, min uses the simplication min (e, -e)
--> -|e|. When get (trylevel, maxmin) is 3 or greater, min tries to eliminate
expressions that are between two other arguments; for example, min (x, 2*x, 3*x) -
-> min (x, 3*x). To set the value of trylevel to 2, use put (trylevel, 2, maxmin).
See also max and lmin.
Function round (x)
When x is a real number, returns the closest integer to x. Multiples of 1/2 are rounded
to the nearest even integer. Evaluation of x is similar to floor and ceiling.
Chapter 10: Mathematical Functions 143
Function signum (x)
For either real or complex numbers x, the signum function returns 0 if x is zero; for
a nonzero numeric input x, the signum function returns x/abs(x).
For non-numeric inputs, Maxima attempts to determine the sign of the input. When
the sign is negative, zero, or positive, signum returns -1,0, 1, respectively. For all
other values for the sign, signum a simplied but equivalent form. The simplica-
tions include reection (signum(-x) gives -signum(x)) and multiplicative identity
(signum(x*y) gives signum(x) * signum(y)).
The signum function distributes over a list, a matrix, or an equation. See
distribute_over.
10.2 Functions for Complex Numbers
Function cabs (expr)
Calculates the absolute value of an expression representing a complex number. Unlike
the function abs, the cabs function always decomposes its argument into a real and
an imaginary part. If x and y represent real variables or expressions, the cabs function
calculates the absolute value of x + %i*y as
2 2
sqrt(y + x )
The cabs function can use known properties like symmetry properties of complex
functions to help it calculate the absolute value of an expression. If such identities
exist, they can be advertised to cabs using function properties. The symmetries that
cabs understands are: mirror symmetry, conjugate function and complex character-
istic.
cabs is a verb function and is not suitable for symbolic calculations. For such calcula-
tions (including integration, dierentiation and taking limits of expressions containing
absolute values), use abs.
The result of cabs can include the absolute value function, abs, and the arc tangent,
atan2.
When applied to a list or matrix, cabs automatically distributes over the terms.
Similarly, it distributes over both sides of an equation.
For further ways to compute with complex numbers, see the functions rectform,
realpart, imagpart, carg, conjugate and polarform.
Examples:
Examples with sqrt and sin.
(%i1) cabs(sqrt(1+%i*x));
2 1/4
(%o1) (x + 1)
(%i2) cabs(sin(x+%i*y));
2 2 2 2
(%o2) sqrt(cos (x) sinh (y) + sin (x) cosh (y))
The error function, erf, has mirror symmetry, which is used here in the calculation
of the absolute value with a complex argument:
144 Maxima 5.30.0 Manual
(%i3) cabs(erf(x+%i*y));
2
(erf(%i y + x) - erf(%i y - x))
(%o3) sqrt(--------------------------------
4
2
(erf(%i y + x) + erf(%i y - x))
- --------------------------------)
4
Maxima knows complex identities for the Bessel functions, which allow it to compute
the absolute value for complex arguments. Here is an example for bessel_j.
(%i4) cabs(bessel_j(1,%i));
(%o4) abs(bessel_j(1, %i))
Function carg (z)
Returns the complex argument of z. The complex argument is an angle theta in
(-%pi, %pi] such that r exp (theta %i) = z where r is the magnitude of z.
carg is a computational function, not a simplifying function.
See also abs (complex magnitude), polarform, rectform, realpart, and
imagpart.
Examples:
(%i1) carg (1);
(%o1) 0
(%i2) carg (1 + %i);
%pi
(%o2) ---
4
(%i3) carg (exp (%i));
(%o3) 1
(%i4) carg (exp (%pi * %i));
(%o4) %pi
(%i5) carg (exp (3/2 * %pi * %i));
%pi
(%o5) - ---
2
(%i6) carg (17 * exp (2 * %i));
(%o6) 2
Function conjugate (x)
Returns the complex conjugate of x.
(%i1) declare ([aa, bb], real, cc, complex, ii, imaginary);
(%o1) done
(%i2) conjugate (aa + bb*%i);
(%o2) aa - %i bb
Chapter 10: Mathematical Functions 145
(%i3) conjugate (cc);
(%o3) conjugate(cc)
(%i4) conjugate (ii);
(%o4) - ii
(%i5) conjugate (xx + yy);
(%o5) conjugate(yy) + conjugate(xx)
Function imagpart (expr)
Returns the imaginary part of the expression expr.
imagpart is a computational function, not a simplifying function.
See also abs, carg, polarform, rectform, and realpart.
Function polarform (expr)
Returns an expression r %e^(%i theta) equivalent to expr, such that r and theta
are purely real.
Function realpart (expr)
Returns the real part of expr. realpart and imagpart will work on expressions
involving trigonometric and hyperbolic functions, as well as square root, logarithm,
and exponentiation.
Function rectform (expr)
Returns an expression a + b %i equivalent to expr, such that a and b are purely real.
10.3 Combinatorial Functions
Operator !!
The double factorial operator.
For an integer, oat, or rational number n, n!! evaluates to the product n (n-2) (n-
4) (n-6) ... (n - 2 (k-1)) where k is equal to entier (n/2), that is, the largest
integer less than or equal to n/2. Note that this denition does not coincide with
other published denitions for arguments which are not integers.
For an even (or odd) integer n, n!! evaluates to the product of all the consecutive
even (or odd) integers from 2 (or 1) through n inclusive.
For an argument n which is not an integer, oat, or rational, n!! yields a noun form
genfact (n, n/2, 2).
146 Maxima 5.30.0 Manual
Function binomial (x, y)
The binomial coecient x!/(y! (x - y)!). If x and y are integers, then the numer-
ical value of the binomial coecient is computed. If y, or x - y, is an integer, the
binomial coecient is expressed as a polynomial.
Examples:
(%i1) binomial (11, 7);
(%o1) 330
(%i2) 11! / 7! / (11 - 7)!;
(%o2) 330
(%i3) binomial (x, 7);
(x - 6) (x - 5) (x - 4) (x - 3) (x - 2) (x - 1) x
(%o3) -------------------------------------------------
5040
(%i4) binomial (x + 7, x);
(x + 1) (x + 2) (x + 3) (x + 4) (x + 5) (x + 6) (x + 7)
(%o4) -------------------------------------------------------
5040
(%i5) binomial (11, y);
(%o5) binomial(11, y)
Function factcomb (expr)
Tries to combine the coecients of factorials in expr with the factorials themselves
by converting, for example, (n + 1)*n! into (n + 1)!.
sumsplitfact if set to false will cause minfactorial to be applied after a
factcomb.
Function factorial
Operator !
Represents the factorial function. Maxima treats factorial (x) the same as x!.
For any complex number x, except for negative integers, x! is dened as gamma(x+1).
For an integer x, x! simplies to the product of the integers from 1 to x inclusive.
0! simplies to 1. For a real or complex number in oat or bigoat precision x, x!
simplies to the value of gamma (x+1). For x equal to n/2 where n is an odd integer,
x! simplies to a rational factor times sqrt (%pi) (since gamma (1/2) is equal to
sqrt (%pi)).
The option variables factlim and gammalim control the numerical evaluation of
factorials for integer and rational arguments. The functions minfactorial and
factcomb simplies expressions containing factorials.
The functions gamma, bffac, and cbffac are varieties of the gamma function.
bffac and cbffac are called internally by gamma to evaluate the gamma function for
real and complex numbers in bigoat precision.
makegamma substitutes gamma for factorials and related functions.
Maxima knows the derivative of the factorial function and the limits for specic values
like negative integers.
Chapter 10: Mathematical Functions 147
The option variable factorial_expand controls the simplication of expressions like
(n+x)!, where n is an integer.
See also binomial.
The factorial of an integer is simplied to an exact number unless the operand is
greater than factlim. The factorial for real and complex numbers is evaluated in
oat or bigoat precision.
(%i1) factlim:10;
(%o1) 10
(%i2) [0!, (7/2)!, 8!, 20!];
105 sqrt(%pi)
(%o2) [1, -------------, 40320, 20!]
16
(%i3) [4.77!, (1.0+%i)!];
(%o3) [81.44668037931197,
.3430658398165454 %i + .6529654964201665]
(%i4) [2.86b0!, (1.0b0+%i)!];
(%o4) [5.046635586910012b0,
3.430658398165454b-1 %i + 6.529654964201667b-1]
The factorial of a known constant, or general expression is not simplied. Even so it
may be possible to simplify the factorial after evaluating the operand.
(%i1) [(%i + 1)!, %pi!, %e!, (cos(1) + sin(1))!];
(%o1) [(%i + 1)!, %pi!, %e!, (sin(1) + cos(1))!]
(%i2) ev (%, numer, %enumer);
(%o2) [.3430658398165454 %i + .6529654964201665,
7.188082728976031,
4.260820476357003, 1.227580202486819]
Factorials are simplied, not evaluated. Thus x! may be replaced even in a quoted
expression.
(%i1) ([0!, (7/2)!, 4.77!, 8!, 20!]);
105 sqrt(%pi)
(%o1) [1, -------------, 81.44668037931199, 40320,
16
2432902008176640000]
Maxima knows the derivative of the factorial function.
(%i1) diff(x!,x);
(%o1) x! psi (x + 1)
0
The option variable factorial_expand controls expansion and simplication of ex-
pressions with the factorial function.
(%i1) (n+1)!/n!,factorial_expand:true;
(%o1) n + 1
Option variable factlim
Default value: -1
factlim species the highest factorial which is automatically expanded. If it is -1
then all integers are expanded.
148 Maxima 5.30.0 Manual
Option variable factorial expand
Default value: false
The option variable factorial_expand controls the simplication of expressions like
(n+1)!, where n is an integer. See factorial for an example.
Function genfact (x, y, z)
Returns the generalized factorial, dened as x (x-z) (x - 2 z) ... (x - (y - 1) z).
Thus, for integral x, genfact (x, x, 1) = x! and genfact (x, x/2, 2) = x!!.
Function minfactorial (expr)
Examines expr for occurrences of two factorials which dier by an integer.
minfactorial then turns one into a polynomial times the other.
(%i1) n!/(n+2)!;
n!
(%o1) --------
(n + 2)!
(%i2) minfactorial (%);
1
(%o2) ---------------
(n + 1) (n + 2)
Option variable sumsplitfact
Default value: true
When sumsplitfact is false, minfactorial is applied after a factcomb.
10.4 Root, Exponential and Logarithmic Functions
Option variable %e to numlog
Default value: false
When true, r some rational number, and x some expression, %e^(r*log(x)) will
be simplied into x^r . It should be noted that the radcan command also does
this transformation, and more complicated transformations of this ilk as well. The
logcontract command "contracts" expressions containing log.
Option variable %emode
Default value: true
When %emode is true, %e^(%pi %i x) is simplied as follows.
%e^(%pi %i x) simplies to cos (%pi x) + %i sin (%pi x) if x is a oating point
number, an integer, or a multiple of 1/2, 1/3, 1/4, or 1/6, and then further simplied.
For other numerical x, %e^(%pi %i x) simplies to %e^(%pi %i y) where y is x - 2 k
for some integer k such that abs(y) < 1.
When %emode is false, no special simplication of %e^(%pi %i x) is carried out.
Chapter 10: Mathematical Functions 149
Option variable %enumer
Default value: false
When %enumer is true, %e is replaced by its numeric value 2.718. . . whenever numer
is true.
When %enumer is false, this substitution is carried out only if the exponent in %e^x
evaluates to a number.
See also ev and numer.
Function exp (x)
Represents the exponential function. Instances of exp (x) in input are simplied to
%e^x; exp does not appear in simplied expressions.
demoivre if true causes %e^(a + b %i) to simplify to %e^(a (cos(b) + %i sin(b)))
if b is free of %i. See demoivre.
%emode, when true, causes %e^(%pi %i x) to be simplied. See %emode.
%enumer, when true causes %e to be replaced by 2.718. . . whenever numer is true.
See %enumer.
Function li [s] (z)
Represents the polylogarithm function of order s and argument z, dened by the
innite series
Li
s
(z) =

k=1
z
k
k
s
li [1] is - log (1 - z). li [2] and li [3] are the dilogarithm and trilogarithm
functions, respectively.
When the order is 1, the polylogarithm simplies to - log (1 - z), which in turn
simplies to a numerical value if z is a real or complex oating point number or the
numer evaluation ag is present.
When the order is 2 or 3, the polylogarithm simplies to a numerical value if z is a
real oating point number or the numer evaluation ag is present.
Examples:
(%i1) assume (x > 0);
(%o1) [x > 0]
(%i2) integrate ((log (1 - t)) / t, t, 0, x);
(%o2) - li (x)
2
(%i3) li [2] (7);
(%o3) li (7)
2
(%i4) li [2] (7), numer;
(%o4) 1.24827317833392 - 6.113257021832577 %i
(%i5) li [3] (7);
(%o5) li (7)
150 Maxima 5.30.0 Manual
3
(%i6) li [2] (7), numer;
(%o6) 1.24827317833392 - 6.113257021832577 %i
(%i7) L : makelist (i / 4.0, i, 0, 8);
(%o7) [0.0, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0]
(%i8) map (lambda ([x], li [2] (x)), L);
(%o8) [0, .2676526384986274, .5822405249432515,
.9784693966661848, 1.64493407, 2.190177004178597
- .7010261407036192 %i, 2.374395264042415
- 1.273806203464065 %i, 2.448686757245154
- 1.758084846201883 %i, 2.467401098097648
- 2.177586087815347 %i]
(%i9) map (lambda ([x], li [3] (x)), L);
(%o9) [0, .2584613953442624, 0.537213192678042,
.8444258046482203, 1.2020569, 1.642866878950322
- .07821473130035025 %i, 2.060877505514697
- .2582419849982037 %i, 2.433418896388322
- .4919260182322965 %i, 2.762071904015935
- .7546938285978846 %i]
Function log (x)
Represents the natural (base e) logarithm of x.
Maxima does not have a built-in function for the base 10 logarithm or other bases.
log10(x) := log(x) / log(10) is a useful denition.
Simplication and evaluation of logarithms is governed by several global ags:
logexpand
causes log(a^b) to become b*log(a). If it is set to all, log(a*b) will
also simplify to log(a)+log(b). If it is set to super, then log(a/b)
will also simplify to log(a)-log(b) for rational numbers a/b, a#1.
(log(1/b), for b integer, always simplies.) If it is set to false, all of
these simplications will be turned o.
logsimp if false then no simplication of %e to a power containing logs is done.
lognegint
if true implements the rule log(-n) -> log(n)+%i*%pi for n a positive
integer.
%e_to_numlog
when true, r some rational number, and x some expression, the expres-
sion %e^(r*log(x)) will be simplied into x^r. It should be noted that
the radcan command also does this transformation, and more compli-
cated transformations of this as well. The logcontract command "con-
tracts" expressions containing log.
Option variable logabs
Default value: false
Chapter 10: Mathematical Functions 151
When doing indenite integration where logs are generated, e.g. integrate(1/x,x),
the answer is given in terms of log(abs(...)) if logabs is true, but in terms of
log(...) if logabs is false. For denite integration, the logabs:true setting is
used, because here "evaluation" of the indenite integral at the endpoints is often
needed.
Option variable logarc
Function logarc (expr)
When the global variable logarc is true, inverse circular and hyperbolic functions are
replaced by equivalent logarithmic functions. The default value of logarc is false.
The function logarc(expr) carries out that replacement for an expression expr with-
out setting the global variable logarc.
Option variable logconcoep
Default value: false
Controls which coecients are contracted when using logcontract. It may be set to
the name of a predicate function of one argument. E.g. if you like to generate SQRTs,
you can do logconcoeffp:logconfun$ logconfun(m):=featurep(m,integer) or
ratnump(m)$ . Then logcontract(1/2*log(x)); will give log(sqrt(x)).
Function logcontract (expr)
Recursively scans the expression expr, transforming subexpressions of the form
a1*log(b1) + a2*log(b2) + c into log(ratsimp(b1^a1 * b2^a2)) + c
(%i1) 2*(a*log(x) + 2*a*log(y))$
(%i2) logcontract(%);
2 4
(%o2) a log(x y )
The declaration declare(n,integer) causes logcontract(2*a*n*log(x)) to sim-
plify to a*log(x^(2*n)). The coecients that "contract" in this manner are those
such as the 2 and the n here which satisfy featurep(coeff,integer). The user can
control which coecients are contracted by setting the option logconcoeffp to the
name of a predicate function of one argument. E.g. if you like to generate SQRTs,
you can do logconcoeffp:logconfun$ logconfun(m):=featurep(m,integer) or
ratnump(m)$ . Then logcontract(1/2*log(x)); will give log(sqrt(x)).
Option variable logexpand
Default value: true
If true, that is the default value, causes log(a^b) to become b*log(a). If it is
set to all, log(a*b) will also simplify to log(a)+log(b). If it is set to super,
then log(a/b) will also simplify to log(a)-log(b) for rational numbers a/b, a#1.
(log(1/b), for integer b, always simplies.) If it is set to false, all of these simpli-
cations will be turned o.
152 Maxima 5.30.0 Manual
Option variable lognegint
Default value: false
If true implements the rule log(-n) -> log(n)+%i*%pi for n a positive integer.
Option variable logsimp
Default value: true
If false then no simplication of %e to a power containing logs is done.
Function plog (x)
Represents the principal branch of the complex-valued natural logarithm with -%pi
< carg(x) <= +%pi .
Function sqrt (x)
The square root of x. It is represented internally by x^(1/2). See also
rootscontract.
radexpand if true will cause nth roots of factors of a product which are powers of
n to be pulled outside of the radical, e.g. sqrt(16*x^2) will become 4*x only if
radexpand is true.
Chapter 10: Mathematical Functions 153
10.5 Trigonometric Functions
10.5.1 Introduction to Trigonometric
Maxima has many trigonometric functions dened. Not all trigonometric identities are
programmed, but it is possible for the user to add many of them using the pattern matching
capabilities of the system. The trigonometric functions dened in Maxima are: acos,
acosh, acot, acoth, acsc, acsch, asec, asech, asin, asinh, atan, atanh, cos, cosh,
cot, coth, csc, csch, sec, sech, sin, sinh, tan, and tanh. There are a number of
commands especially for handling trigonometric functions, see trigexpand, trigreduce,
and the switch trigsign. Two share packages extend the simplication rules built into
Maxima, ntrig and atrig1. Do describe(command) for details.
10.5.2 Functions and Variables for Trigonometric
Option variable %piargs
Default value: true
When %piargs is true, trigonometric functions are simplied to algebraic constants
when the argument is an integer multiple of , /2, /3, /4, or /6.
Maxima knows some identities which can be applied when , etc., are multiplied by
an integer variable (that is, a symbol declared to be integer).
Examples:
(%i1) %piargs : false$
(%i2) [sin (%pi), sin (%pi/2), sin (%pi/3)];
%pi %pi
(%o2) [sin(%pi), sin(---), sin(---)]
2 3
(%i3) [sin (%pi/4), sin (%pi/5), sin (%pi/6)];
%pi %pi %pi
(%o3) [sin(---), sin(---), sin(---)]
4 5 6
(%i4) %piargs : true$
(%i5) [sin (%pi), sin (%pi/2), sin (%pi/3)];
sqrt(3)
(%o5) [0, 1, -------]
2
(%i6) [sin (%pi/4), sin (%pi/5), sin (%pi/6)];
1 %pi 1
(%o6) [-------, sin(---), -]
sqrt(2) 5 2
(%i7) [cos (%pi/3), cos (10*%pi/3), tan (10*%pi/3),
cos (sqrt(2)*%pi/3)];
1 1 sqrt(2) %pi
(%o7) [-, - -, sqrt(3), cos(-----------)]
2 2 3
Some identities are applied when and /2 are multiplied by an integer variable.
154 Maxima 5.30.0 Manual
(%i1) declare (n, integer, m, even)$
(%i2) [sin (%pi * n), cos (%pi * m), sin (%pi/2 * m),
cos (%pi/2 * m)];
m/2
(%o2) [0, 1, 0, (- 1) ]
Option variable %iargs
Default value: true
When %iargs is true, trigonometric functions are simplied to hyperbolic functions
when the argument is apparently a multiple of the imaginary unit i.
Even when the argument is demonstrably real, the simplication is applied; Maxima
considers only whether the argument is a literal multiple of i.
Examples:
(%i1) %iargs : false$
(%i2) [sin (%i * x), cos (%i * x), tan (%i * x)];
(%o2) [sin(%i x), cos(%i x), tan(%i x)]
(%i3) %iargs : true$
(%i4) [sin (%i * x), cos (%i * x), tan (%i * x)];
(%o4) [%i sinh(x), cosh(x), %i tanh(x)]
Even when the argument is demonstrably real, the simplication is applied.
(%i1) declare (x, imaginary)$
(%i2) [featurep (x, imaginary), featurep (x, real)];
(%o2) [true, false]
(%i3) sin (%i * x);
(%o3) %i sinh(x)
Function acos (x)
Arc Cosine.
Function acosh (x)
Hyperbolic Arc Cosine.
Function acot (x)
Arc Cotangent.
Function acoth (x)
Hyperbolic Arc Cotangent.
Function acsc (x)
Arc Cosecant.
Function acsch (x)
Hyperbolic Arc Cosecant.
Function asec (x)
Arc Secant.
Chapter 10: Mathematical Functions 155
Function asech (x)
Hyperbolic Arc Secant.
Function asin (x)
Arc Sine.
Function asinh (x)
Hyperbolic Arc Sine.
Function atan (x)
Arc Tangent.
Function atan2 (y, x)
yields the value of atan(y/x) in the interval -%pi to %pi.
Function atanh (x)
Hyperbolic Arc Tangent.
Package atrig1
The atrig1 package contains several additional simplication rules for inverse trigono-
metric functions. Together with rules already known to Maxima, the following angles
are fully implemented: 0, %pi/6, %pi/4, %pi/3, and %pi/2. Corresponding angles in
the other three quadrants are also available. Do load(atrig1); to use them.
Function cos (x)
Cosine.
Function cosh (x)
Hyperbolic Cosine.
Function cot (x)
Cotangent.
Function coth (x)
Hyperbolic Cotangent.
Function csc (x)
Cosecant.
Function csch (x)
Hyperbolic Cosecant.
156 Maxima 5.30.0 Manual
Option variable halfangles
Default value: false
When halfangles is true, trigonometric functions of arguments expr/2 are simplied
to functions of expr.
For a real argument x in the interval 0 < x < 2*%pi the sine of the half-angle simplies
to a simple formula:
sqrt(1 - cos(x))
----------------
sqrt(2)
A complicated factor is needed to make this formula correct for all complex arguments
z:
realpart(z)
floor(-----------)
2 %pi
(- 1) (1 - unit_step(- imagpart(z))
realpart(z) realpart(z)
floor(-----------) - ceiling(-----------)
2 %pi 2 %pi
((- 1) + 1))
Maxima knows this factor and similar factors for the functions sin, cos, sinh, and
cosh. For special values of the argument z these factors simplify accordingly.
Examples:
(%i1) halfangles:false;
(%o1) false
(%i2) sin(x/2);
x
(%o2) sin(-)
2
(%i3) halfangles:true;
(%o3) true
(%i4) sin(x/2);
x
floor(-----)
2 %pi
sqrt(1 - cos(x)) (- 1)
(%o4) ----------------------------------
sqrt(2)
(%i5) assume(x>0, x<2*%pi)$
(%i6) sin(x/2);
sqrt(1 - cos(x))
(%o6) ----------------
sqrt(2)
Chapter 10: Mathematical Functions 157
Package ntrig
The ntrig package contains a set of simplication rules that are used to simplify
trigonometric function whose arguments are of the form f (n %pi/10) where f is any
of the functions sin, cos, tan, csc, sec and cot.
Function sec (x)
Secant.
Function sech (x)
Hyperbolic Secant.
Function sin (x)
Sine.
Function sinh (x)
Hyperbolic Sine.
Function tan (x)
Tangent.
Function tanh (x)
Hyperbolic Tangent.
Function trigexpand (expr)
Expands trigonometric and hyperbolic functions of sums of angles and of multiple
angles occurring in expr. For best results, expr should be expanded. To enhance user
control of simplication, this function expands only one level at a time, expanding
sums of angles or multiple angles. To obtain full expansion into sines and cosines
immediately, set the switch trigexpand: true.
trigexpand is governed by the following global ags:
trigexpand
If true causes expansion of all expressions containing sins and coss oc-
curring subsequently.
halfangles
If true causes half-angles to be simplied away.
trigexpandplus
Controls the "sum" rule for trigexpand, expansion of sums (e.g. sin(x
+ y)) will take place only if trigexpandplus is true.
trigexpandtimes
Controls the "product" rule for trigexpand, expansion of products (e.g.
sin(2 x)) will take place only if trigexpandtimes is true.
Examples:
158 Maxima 5.30.0 Manual
(%i1) x+sin(3*x)/sin(x),trigexpand=true,expand;
2 2
(%o1) - sin (x) + 3 cos (x) + x
(%i2) trigexpand(sin(10*x+y));
(%o2) cos(10 x) sin(y) + sin(10 x) cos(y)
Option variable trigexpandplus
Default value: true
trigexpandplus controls the "sum" rule for trigexpand. Thus, when the
trigexpand command is used or the trigexpand switch set to true, expansion of
sums (e.g. sin(x+y)) will take place only if trigexpandplus is true.
Option variable trigexpandtimes
Default value: true
trigexpandtimes controls the "product" rule for trigexpand. Thus, when the
trigexpand command is used or the trigexpand switch set to true, expansion of
products (e.g. sin(2*x)) will take place only if trigexpandtimes is true.
Option variable triginverses
Default value: true
triginverses controls the simplication of the composition of trigonometric and
hyperbolic functions with their inverse functions.
If all, both e.g. atan(tan(x)) and tan(atan(x)) simplify to x.
If true, the arcfun(fun(x)) simplication is turned o.
If false, both the arcfun(fun(x)) and fun(arcfun(x)) simplications are turned o.
Function trigreduce (expr, x)
Function trigreduce (expr)
Combines products and powers of trigonometric and hyperbolic sins and coss of x
into those of multiples of x. It also tries to eliminate these functions when they occur
in denominators. If x is omitted then all variables in expr are used.
See also poissimp.
(%i1) trigreduce(-sin(x)^2+3*cos(x)^2+x);
cos(2 x) cos(2 x) 1 1
(%o1) -------- + 3 (-------- + -) + x - -
2 2 2 2
Option variable trigsign
Default value: true
When trigsign is true, it permits simplication of negative arguments to trigono-
metric functions. E.g., sin(-x) will become -sin(x) only if trigsign is true.
Chapter 10: Mathematical Functions 159
Function trigsimp (expr)
Employs the identities sin (x)
2
+cos (x)
2
= 1 and cosh (x)
2
sinh (x)
2
= 1 to simplify
expressions containing tan, sec, etc., to sin, cos, sinh, cosh.
trigreduce, ratsimp, and radcan may be able to further simplify the result.
demo ("trgsmp.dem") displays some examples of trigsimp.
Function trigrat (expr)
Gives a canonical simplied quasilinear form of a trigonometrical expression; expr is
a rational fraction of several sin, cos or tan, the arguments of them are linear forms
in some variables (or kernels) and %pi/n (n integer) with integer coecients. The
result is a simplied fraction with numerator and denominator linear in sin and cos.
Thus trigrat linearize always when it is possible.
(%i1) trigrat(sin(3*a)/sin(a+%pi/3));
(%o1) sqrt(3) sin(2 a) + cos(2 a) - 1
The following example is taken from Davenport, Siret, and Tournier, Calcul Formel,
Masson (or in English, Addison-Wesley), section 1.5.5, Morley theorem.
(%i1) c : %pi/3 - a - b$
(%i2) bc : sin(a)*sin(3*c)/sin(a+b);
%pi
sin(a) sin(3 (- b - a + ---))
3
(%o2) -----------------------------
sin(b + a)
(%i3) ba : bc, c=a, a=c;
%pi
sin(3 a) sin(b + a - ---)
3
(%o3) -------------------------
%pi
sin(a - ---)
3
(%i4) ac2 : ba^2 + bc^2 - 2*bc*ba*cos(b);
160 Maxima 5.30.0 Manual
2 2 %pi
sin (3 a) sin (b + a - ---)
3
(%o4) ---------------------------
2 %pi
sin (a - ---)
3
%pi
- (2 sin(a) sin(3 a) sin(3 (- b - a + ---)) cos(b)
3
%pi %pi
sin(b + a - ---))/(sin(a - ---) sin(b + a))
3 3
2 2 %pi
sin (a) sin (3 (- b - a + ---))
3
+ -------------------------------
2
sin (b + a)
(%i5) trigrat (ac2);
(%o5) - (sqrt(3) sin(4 b + 4 a) - cos(4 b + 4 a)
- 2 sqrt(3) sin(4 b + 2 a) + 2 cos(4 b + 2 a)
- 2 sqrt(3) sin(2 b + 4 a) + 2 cos(2 b + 4 a)
+ 4 sqrt(3) sin(2 b + 2 a) - 8 cos(2 b + 2 a) - 4 cos(2 b - 2 a)
+ sqrt(3) sin(4 b) - cos(4 b) - 2 sqrt(3) sin(2 b) + 10 cos(2 b)
+ sqrt(3) sin(4 a) - cos(4 a) - 2 sqrt(3) sin(2 a) + 10 cos(2 a)
- 9)/4
Chapter 10: Mathematical Functions 161
10.6 Random Numbers
Function make random state (n)
Function make random state (s)
Function make random state (true)
Function make random state (false)
A random state object represents the state of the random number generator. The
state comprises 627 32-bit words.
make_random_state (n) returns a new random state object created from an integer
seed value equal to n modulo 2^32. n may be negative.
make_random_state (s) returns a copy of the random state s.
make_random_state (true) returns a new random state object, using the current
computer clock time as the seed.
make_random_state (false) returns a copy of the current state of the random num-
ber generator.
Function set random state (s)
Copies s to the random number generator state.
set_random_state always returns done.
Function random (x)
Returns a pseudorandom number. If x is an integer, random (x) returns an integer
from 0 through x - 1 inclusive. If x is a oating point number, random (x) returns
a nonnegative oating point number less than x. random complains with an error if
x is neither an integer nor a oat, or if x is not positive.
The functions make_random_state and set_random_state maintain the state of the
random number generator.
The Maxima random number generator is an implementation of the Mersenne twister
MT 19937.
Examples:
(%i1) s1: make_random_state (654321)$
(%i2) set_random_state (s1);
(%o2) done
(%i3) random (1000);
(%o3) 768
(%i4) random (9573684);
(%o4) 7657880
(%i5) random (2^75);
(%o5) 11804491615036831636390
(%i6) s2: make_random_state (false)$
(%i7) random (1.0);
(%o7) .2310127244107132
(%i8) random (10.0);
(%o8) 4.394553645870825
162 Maxima 5.30.0 Manual
(%i9) random (100.0);
(%o9) 32.28666704056853
(%i10) set_random_state (s2);
(%o10) done
(%i11) random (1.0);
(%o11) .2310127244107132
(%i12) random (10.0);
(%o12) 4.394553645870825
(%i13) random (100.0);
(%o13) 32.28666704056853
Chapter 11: Maximas Database 163
11 Maximas Database
11.1 Introduction to Maximas Database
11.2 Functions and Variables for Properties
Property alphabetic
alphabetic is a property type recognized by declare. The expression declare(s,
alphabetic) tells Maxima to recognize as alphabetic all of the characters in s, which
must be a string.
See also Section 6.3 [Identiers], page 72.
Example:
(%i1) xx\~yy\\@ : 1729;
(%o1) 1729
(%i2) declare ("~@", alphabetic);
(%o2) done
(%i3) xx~yy@ + @yyxx + xx@@yy~;
(%o3) xx@@yy~ + @yyxx + 1729
(%i4) listofvars (%);
(%o4) [@yyxx, xx@@yy~]
Property bindtest
The command declare(x, bindtest tells Maxima to trigger an error when the sym-
bol x is evaluated unbound.
(%i1) aa + bb;
(%o1) bb + aa
(%i2) declare (aa, bindtest);
(%o2) done
(%i3) aa + bb;
aa unbound variable
-- an error. Quitting. To debug this try debugmode(true);
(%i4) aa : 1234;
(%o4) 1234
(%i5) aa + bb;
(%o5) bb + 1234
Property constant
declare(a, constant) declares a to be a constant. The declaration of a symbol to
be constant does not prevent the assignment of a nonconstant value to the symbol.
See constantp and declare.
Example:
164 Maxima 5.30.0 Manual
(%i1) declare(c, constant);
(%o1) done
(%i2) constantp(c);
(%o2) true
(%i3) c : x;
(%o3) x
(%i4) constantp(c);
(%o4) false
Function constantp (expr)
Returns true if expr is a constant expression, otherwise returns false.
An expression is considered a constant expression if its arguments are numbers (in-
cluding rational numbers, as displayed with /R/), symbolic constants such as %pi,
%e, and %i, variables bound to a constant or declared constant by declare, or
functions whose arguments are constant.
constantp evaluates its arguments.
See the property constant which declares a symbol to be constant.
Examples:
(%i1) constantp (7 * sin(2));
(%o1) true
(%i2) constantp (rat (17/29));
(%o2) true
(%i3) constantp (%pi * sin(%e));
(%o3) true
(%i4) constantp (exp (x));
(%o4) false
(%i5) declare (x, constant);
(%o5) done
(%i6) constantp (exp (x));
(%o6) true
(%i7) constantp (foo (x) + bar (%e) + baz (2));
(%o7) false
(%i8)
Function declare (a 1, p 1, a 2, p 2, . . . )
Assigns the atom or list of atoms a i the property or list of properties p i. When a i
and/or p i are lists, each of the atoms gets all of the properties.
declare quotes its arguments. declare always returns done.
As noted in the description for each declaration ag, for some ags featurep(object,
feature) returns true if object has been declared to have feature.
For more information about the features system, see features. To remove a property
from an atom, use remove.
declare recognizes the following properties:
Chapter 11: Maximas Database 165
additive Tells Maxima to simplify a i expressions by the substitution a i(x + y +
z + ...) --> a i(x) + a i(y) + a i(z) + .... The substitution is carried
out on the rst argument only.
alphabetic
Tells Maxima to recognize all characters in a i (which must be a string)
as alphabetic characters.
antisymmetric, commutative, symmetric
Tells Maxima to recognize a i as a symmetric or antisymmetric function.
commutative is the same as symmetric.
bindtest Tells Maxima to trigger an error when a i is evaluated unbound.
constant Tells Maxima to consider a i a symbolic constant.
even, odd Tells Maxima to recognize a i as an even or odd integer variable.
evenfun, oddfun
Tells Maxima to recognize a i as an odd or even function.
evflag Makes a i known to the ev function so that a i is bound to true during the
execution of ev when a i appears as a ag argument of ev. See evflag.
evfun Makes a i known to ev so that the function named by a i is applied when
a i appears as a ag argument of ev. See evfun.
feature Tells Maxima to recognize a i as the name of a feature. Other atoms may
then be declared to have the a i property.
increasing, decreasing
Tells Maxima to recognize a i as an increasing or decreasing function.
integer, noninteger
Tells Maxima to recognize a i as an integer or noninteger variable.
integervalued
Tells Maxima to recognize a i as an integer-valued function.
lassociative, rassociative
Tells Maxima to recognize a i as a right-associative or left-associative
function.
linear Equivalent to declaring a i both outative and additive.
mainvar Tells Maxima to consider a i a "main variable". A main variable succeeds
all other constants and variables in the canonical ordering of Maxima
expressions, as determined by ordergreatp.
multiplicative
Tells Maxima to simplify a i expressions by the substitution a i(x * y *
z * ...) --> a i(x) * a i(y) * a i(z) * .... The substitution is carried
out on the rst argument only.
nary Tells Maxima to recognize a i as an n-ary function.
The nary declaration is not the same as calling the nary function. The
sole eect of declare(foo, nary) is to instruct the Maxima simplier to
166 Maxima 5.30.0 Manual
atten nested expressions, for example, to simplify foo(x, foo(y, z))
to foo(x, y, z).
nonarray Tells Maxima to consider a i not an array. This declaration prevents
multiple evaluation of a subscripted variable name.
nonscalar
Tells Maxima to consider a i a nonscalar variable. The usual application
is to declare a variable as a symbolic vector or matrix.
noun Tells Maxima to parse a i as a noun. The eect of this is to replace
instances of a i with a i or nounify(a i), depending on the context.
outative Tells Maxima to simplify a i expressions by pulling constant factors out
of the rst argument.
When a i has one argument, a factor is considered constant if it is a literal
or declared constant.
When a i has two or more arguments, a factor is considered constant
if the second argument is a symbol and the factor is free of the second
argument.
posfun Tells Maxima to recognize a i as a positive function.
rational, irrational
Tells Maxima to recognize a i as a rational or irrational real variable.
real, imaginary, complex
Tells Maxima to recognize a i as a real, pure imaginary, or complex vari-
able.
scalar Tells Maxima to consider a i a scalar variable.
Examples of the usage of the properties are available in the documentation for each
separate description of a property.
Property decreasing
Property increasing
The commands declare(f, decreasing) or declare(f, increasing tell Maxima to
recognize the function f as an decreasing or increasing function.
See also declare for more properties.
Example:
(%i1) assume(a > b);
(%o1) [a > b]
(%i2) is(f(a) > f(b));
(%o2) unknown
(%i3) declare(f, increasing);
(%o3) done
(%i4) is(f(a) > f(b));
(%o4) true
Chapter 11: Maximas Database 167
Property even
Property odd
declare(a, even) or declare(a, odd) tells Maxima to recognize the symbol a as
an even or odd integer variable. The properties even and odd are not recognized by
the functions evenp, oddp, and integerp.
See also declare and askinteger.
Example:
(%i1) declare(n, even);
(%o1) done
(%i2) askinteger(n, even);
(%o2) yes
(%i3) askinteger(n);
(%o3) yes
(%i4) evenp(n);
(%o4) false
Property feature
Maxima understands two distinct types of features, system features and features which
apply to mathematical expressions. See also status for information about system
features. See also features and featurep for information about mathematical
features.
feature itself is not the name of a function or variable.
Function featurep (a, f )
Attempts to determine whether the object a has the feature f on the basis of the facts
in the current database. If so, it returns true, else false.
Note that featurep returns false when neither f nor the negation of f can be
established.
featurep evaluates its argument.
See also declare and features.
(%i1) declare (j, even)$
(%i2) featurep (j, integer);
(%o2) true
Declaration features
Maxima recognizes certain mathematical properties of functions and variables. These
are called "features".
declare (x, foo) gives the property foo to the function or variable x.
declare (foo, feature) declares a new feature foo. For example, declare ([red,
green, blue], feature) declares three new features, red, green, and blue.
The predicate featurep (x, foo) returns true if x has the foo property, and false
otherwise.
The infolist features is a list of known features. These are
168 Maxima 5.30.0 Manual
integer noninteger even
odd rational irrational
real imaginary complex
analytic increasing decreasing
oddfun evenfun posfun
commutative lassociative rassociative
symmetric antisymmetric
plus any user-dened features.
features is a list of mathematical features. There is also a list of non-mathematical,
system-dependent features. See status.
Example:
(%i1) declare (FOO, feature);
(%o1) done
(%i2) declare (x, FOO);
(%o2) done
(%i3) featurep (x, FOO);
(%o3) true
Function get (a, i)
Retrieves the user property indicated by i associated with atom a or returns false if
a doesnt have property i.
get evaluates its arguments.
See also put and qput.
(%i1) put (%e, transcendental, type);
(%o1) transcendental
(%i2) put (%pi, transcendental, type)$
(%i3) put (%i, algebraic, type)$
(%i4) typeof (expr) := block ([q],
if numberp (expr)
then return (algebraic),
if not atom (expr)
then return (maplist (typeof, expr)),
q: get (expr, type),
if q=false
then errcatch (error(expr,"is not numeric.")) else q)$
(%i5) typeof (2*%e + x*%pi);
x is not numeric.
(%o5) [[transcendental, []], [algebraic, transcendental]]
(%i6) typeof (2*%e + %pi);
(%o6) [transcendental, [algebraic, transcendental]]
Property integer
Property noninteger
declare(a, integer) or declare(a, noninteger) tells Maxima to recognize a as
an integer or noninteger variable.
Chapter 11: Maximas Database 169
See also declare.
Example:
(%i1) declare(n, integer, x, noninteger);
(%o1) done
(%i2) askinteger(n);
(%o2) yes
(%i3) askinteger(x);
(%o3) no
Property integervalued
declare(f, integervalued) tells Maxima to recognize f as an integer-valued func-
tion.
See also declare.
Example:
(%i1) exp(%i)^f(x);
%i f(x)
(%o1) (%e )
(%i2) declare(f, integervalued);
(%o2) done
(%i3) exp(%i)^f(x);
%i f(x)
(%o3) %e
Property nonarray
The command declare(a, nonarray) tells Maxima to consider a not an array. This
declaration prevents multiple evaluation, if a is a subscripted variable.
See also declare.
Example:
(%i1) a:b$ b:c$ c:d$
(%i4) a[x];
(%o4) d
x
(%i5) declare(a, nonarray);
(%o5) done
(%i6) a[x];
(%o6) a
x
Property nonscalar
Makes atoms behave as does a list or matrix with respect to the dot operator.
See also declare.
170 Maxima 5.30.0 Manual
Function nonscalarp (expr)
Returns true if expr is a non-scalar, i.e., it contains atoms declared as non-scalars,
lists, or matrices.
See also the predicate function scalarp and declare.
Property posfun
declare (f, posfun) declares f to be a positive function. is (f(x) > 0) yields true.
See also declare.
Function printprops (a, i)
Function printprops ([a 1, . . . , a n], i)
Function printprops (all, i)
Displays the property with the indicator i associated with the atom a. a may also
be a list of atoms or the atom all in which case all of the atoms with the given
property will be used. For example, printprops ([f, g], atvalue). printprops
is for properties that cannot otherwise be displayed, i.e. for atvalue, atomgrad,
gradef, and matchdeclare.
Function properties (a)
Returns a list of the names of all the properties associated with the atom a.
System variable props
Default value: []
props are atoms which have any property other than those explicitly mentioned in
infolists, such as specied by atvalue, matchdeclare, etc., as well as properties
specied in the declare function.
Function propvars (prop)
Returns a list of those atoms on the props list which have the property indicated by
prop. Thus propvars (atvalue) returns a list of atoms which have atvalues.
Function put (atom, value, indicator)
Assigns value to the property (specied by indicator) of atom. indicator may be the
name of any property, not just a system-dened property.
rem reverses the eect of put.
put evaluates its arguments. put returns value.
See also qput and get.
Examples:
(%i1) put (foo, (a+b)^5, expr);
5
(%o1) (b + a)
(%i2) put (foo, "Hello", str);
Chapter 11: Maximas Database 171
(%o2) Hello
(%i3) properties (foo);
(%o3) [[user properties, str, expr]]
(%i4) get (foo, expr);
5
(%o4) (b + a)
(%i5) get (foo, str);
(%o5) Hello
Function qput (atom, value, indicator)
Assigns value to the property (specied by indicator) of atom. This is the same as
put, except that the arguments are quoted.
See also get.
Example:
(%i1) foo: aa$
(%i2) bar: bb$
(%i3) baz: cc$
(%i4) put (foo, bar, baz);
(%o4) bb
(%i5) properties (aa);
(%o5) [[user properties, cc]]
(%i6) get (aa, cc);
(%o6) bb
(%i7) qput (foo, bar, baz);
(%o7) bar
(%i8) properties (foo);
(%o8) [value, [user properties, baz]]
(%i9) get (foo, baz);
(%o9) bar
Property rational
Property irrational
declare(a, rational) or declare(a, irrational) tells Maxima to recognize a as
a rational or irrational real variable.
See also declare.
Property real
Property imaginary
Property complex
declare(a, real), declare(a, imaginary), or declare(a, complex) tells Maxima
to recognize a as a real, pure imaginary, or complex variable.
See also declare.
172 Maxima 5.30.0 Manual
Function rem (atom, indicator)
Removes the property indicated by indicator from atom. rem reverses the eect of
put.
rem returns done if atom had an indicator property when rem was called, or false if
it had no such property.
Function remove (a 1, p 1, . . . , a n, p n)
Function remove ([a 1, . . . , a m], [p 1, . . . , p n], . . . )
Function remove ("a", operator)
Function remove (a, transfun)
Function remove (all, p)
Removes properties associated with atoms.
remove (a 1, p 1, ..., a n, p n) removes property p_k from atom a_k.
remove ([a 1, ..., a m], [p 1, ..., p n], ...) removes properties p 1, ...,
p n from atoms a 1, . . . , a m. There may be more than one pair of lists.
remove (all, p) removes the property p from all atoms which have it.
The removed properties may be system-dened properties such as function, macro,
or mode_declare. remove does not remove properties dened by put.
A property may be transfun to remove the translated Lisp version of a function.
After executing this, the Maxima version of the function is executed rather than the
translated version.
remove ("a", operator) or, equivalently, remove ("a", op) removes from a the op-
erator properties declared by prefix, infix, nary, postfix, matchfix, or nofix.
Note that the name of the operator must be written as a quoted string.
remove always returns done whether or not an atom has a specied property.
This behavior is unlike the more specic remove functions remvalue, remarray,
remfunction, and remrule.
remove quotes its arguments.
Property scalar
declare(a, scalar) tells Maxima to consider a a scalar variable.
See also declare.
Function scalarp (expr)
Returns true if expr is a number, constant, or variable declared scalar with
declare, or composed entirely of numbers, constants, and such variables, but not
containing matrices or lists.
See also the predicate function nonscalarp.
Chapter 11: Maximas Database 173
11.3 Functions and Variables for Facts
Function activate (context 1, . . . , context n)
Activates the contexts context 1, . . . , context n. The facts in these contexts are then
available to make deductions and retrieve information. The facts in these contexts
are not listed by facts ().
The variable activecontexts is the list of contexts which are active by way of the
activate function.
System variable activecontexts
Default value: []
activecontexts is a list of the contexts which are active by way of the activate
function, as opposed to being active because they are subcontexts of the current
context.
Function askinteger (expr, integer)
Function askinteger (expr)
Function askinteger (expr, even)
Function askinteger (expr, odd)
askinteger (expr, integer) attempts to determine from the assume database
whether expr is an integer. askinteger prompts the user if it cannot tell otherwise,
and attempt to install the information in the database if possible. askinteger
(expr) is equivalent to askinteger (expr, integer).
askinteger (expr, even) and askinteger (expr, odd) likewise attempt to deter-
mine if expr is an even integer or odd integer, respectively.
Function asksign (expr)
First attempts to determine whether the specied expression is positive, negative, or
zero. If it cannot, it asks the user the necessary questions to complete its deduc-
tion. The users answer is recorded in the data base for the duration of the current
computation. The return value of asksign is one of pos, neg, or zero.
Function assume (pred 1, . . . , pred n)
Adds predicates pred 1, . . . , pred n to the current context. If a predicate is inconsis-
tent or redundant with the predicates in the current context, it is not added to the
context. The context accumulates predicates from each call to assume.
assume returns a list whose elements are the predicates added to the context or the
atoms redundant or inconsistent where applicable.
The predicates pred 1, . . . , pred n can only be expressions with the relational opera-
tors < <= equal notequal >= and >. Predicates cannot be literal equality = or literal
inequality # expressions, nor can they be predicate functions such as integerp.
Compound predicates of the form pred 1 and ... and pred n are recognized, but not
pred 1 or ... or pred n. not pred k is recognized if pred k is a relational predicate.
174 Maxima 5.30.0 Manual
Expressions of the form not (pred 1 and pred 2) and not (pred 1 or pred 2) are
not recognized.
Maximas deduction mechanism is not very strong; there are many obvious conse-
quences which cannot be determined by is. This is a known weakness.
assume does not handle predicates with complex numbers. If a predicate contains a
complex number assume returns inconsistent or redunant.
assume evaluates its arguments.
See also is, facts, forget, context, and declare.
Examples:
(%i1) assume (xx > 0, yy < -1, zz >= 0);
(%o1) [xx > 0, yy < - 1, zz >= 0]
(%i2) assume (aa < bb and bb < cc);
(%o2) [bb > aa, cc > bb]
(%i3) facts ();
(%o3) [xx > 0, - 1 > yy, zz >= 0, bb > aa, cc > bb]
(%i4) is (xx > yy);
(%o4) true
(%i5) is (yy < -yy);
(%o5) true
(%i6) is (sinh (bb - aa) > 0);
(%o6) true
(%i7) forget (bb > aa);
(%o7) [bb > aa]
(%i8) prederror : false;
(%o8) false
(%i9) is (sinh (bb - aa) > 0);
(%o9) unknown
(%i10) is (bb^2 < cc^2);
(%o10) unknown
Option variable assumescalar
Default value: true
assumescalar helps govern whether expressions expr for which nonscalarp (expr)
is false are assumed to behave like scalars for certain transformations.
Let expr represent any expression other than a list or a matrix, and let [1, 2, 3]
represent any list or matrix. Then expr . [1, 2, 3] yields [expr, 2 expr, 3 expr]
if assumescalar is true, or scalarp (expr) is true, or constantp (expr) is true.
If assumescalar is true, such expressions will behave like scalars only for commuta-
tive operators, but not for noncommutative multiplication ..
When assumescalar is false, such expressions will behave like non-scalars.
When assumescalar is all, such expressions will behave like scalars for all the op-
erators listed above.
Chapter 11: Maximas Database 175
Option variable assume pos
Default value: false
When assume_pos is true and the sign of a parameter x cannot be determined from
the current context or other considerations, sign and asksign (x) return true. This
may forestall some automatically-generated asksign queries, such as may arise from
integrate or other computations.
By default, a parameter is x such that symbolp (x) or subvarp (x). The class of
expressions considered parameters can be modied to some extent via the variable
assume_pos_pred.
sign and asksign attempt to deduce the sign of expressions from the sign of operands
within the expression. For example, if a and b are both positive, then a + b is also
positive.
However, there is no way to bypass all asksign queries. In particular, when the
asksign argument is a dierence x - y or a logarithm log(x), asksign always re-
quests an input from the user, even when assume_pos is true and assume_pos_pred
is a function which returns true for all arguments.
Option variable assume pos pred
Default value: false
When assume_pos_pred is assigned the name of a function or a lambda expression
of one argument x, that function is called to determine whether x is considered a
parameter for the purpose of assume_pos. assume_pos_pred is ignored when assume_
pos is false.
The assume_pos_pred function is called by sign and asksign with an argument x
which is either an atom, a subscripted variable, or a function call expression. If the
assume_pos_pred function returns true, x is considered a parameter for the purpose
of assume_pos.
By default, a parameter is x such that symbolp (x) or subvarp (x).
See also assume and assume_pos.
Examples:
(%i1) assume_pos: true$
(%i2) assume_pos_pred: symbolp$
(%i3) sign (a);
(%o3) pos
(%i4) sign (a[1]);
(%o4) pnz
(%i5) assume_pos_pred: lambda ([x], display (x), true)$
(%i6) asksign (a);
x = a
(%o6) pos
(%i7) asksign (a[1]);
x = a
1
176 Maxima 5.30.0 Manual
(%o7) pos
(%i8) asksign (foo (a));
x = foo(a)
(%o8) pos
(%i9) asksign (foo (a) + bar (b));
x = foo(a)
x = bar(b)
(%o9) pos
(%i10) asksign (log (a));
x = a
Is a - 1 positive, negative, or zero?
p;
(%o10) pos
(%i11) asksign (a - b);
x = a
x = b
x = a
x = b
Is b - a positive, negative, or zero?
p;
(%o11) neg
Option variable context
Default value: initial
context names the collection of facts maintained by assume and forget. assume
adds facts to the collection named by context, while forget removes facts.
Binding context to a name foo changes the current context to foo. If the specied
context foo does not yet exist, it is created automatically by a call to newcontext.
The specied context is activated automatically.
See contexts for a general description of the context mechanism.
Option variable contexts
Default value: [initial, global]
contexts is a list of the contexts which currently exist, including the currently active
context.
Chapter 11: Maximas Database 177
The context mechanism makes it possible for a user to bind together and name a
collection of facts, called a context. Once this is done, the user can have Maxima
assume or forget large numbers of facts merely by activating or deactivating their
context.
Any symbolic atom can be a context, and the facts contained in that context will be
retained in storage until destroyed one by one by calling forget or destroyed as a
whole by calling kill to destroy the context to which they belong.
Contexts exist in a hierarchy, with the root always being the context global, which
contains information about Maxima that some functions need. When in a given
context, all the facts in that context are "active" (meaning that they are used in
deductions and retrievals) as are all the facts in any context which is a subcontext of
the active context.
When a fresh Maxima is started up, the user is in a context called initial, which
has global as a subcontext.
See also facts, newcontext, supcontext, killcontext, activate, deactivate,
assume, and forget.
Function deactivate (context 1, . . . , context n)
Deactivates the specied contexts context 1, . . . , context n.
Function facts (item)
Function facts ()
If item is the name of a context, facts (item) returns a list of the facts in the specied
context.
If item is not the name of a context, facts (item) returns a list of the facts known
about item in the current context. Facts that are active, but in a dierent context,
are not listed.
facts () (i.e., without an argument) lists the current context.
Function forget (pred 1, . . . , pred n)
Function forget (L)
Removes predicates established by assume. The predicates may be expressions
equivalent to (but not necessarily identical to) those previously assumed.
forget (L), where L is a list of predicates, forgets each item on the list.
Function is (expr)
Attempts to determine whether the predicate expr is provable from the facts in the
assume database.
If the predicate is provably true or false, is returns true or false, respectively.
Otherwise, the return value is governed by the global ag prederror. When
prederror is true, is complains with an error message. Otherwise, is returns
unknown.
178 Maxima 5.30.0 Manual
ev(expr, pred) (which can be written expr, pred at the interactive prompt) is equiv-
alent to is(expr).
See also assume, facts, and maybe.
Examples:
is causes evaluation of predicates.
(%i1) %pi > %e;
(%o1) %pi > %e
(%i2) is (%pi > %e);
(%o2) true
is attempts to derive predicates from the assume database.
(%i1) assume (a > b);
(%o1) [a > b]
(%i2) assume (b > c);
(%o2) [b > c]
(%i3) is (a < b);
(%o3) false
(%i4) is (a > c);
(%o4) true
(%i5) is (equal (a, c));
(%o5) false
If is can neither prove nor disprove a predicate from the assume database, the global
ag prederror governs the behavior of is.
(%i1) assume (a > b);
(%o1) [a > b]
(%i2) prederror: true$
(%i3) is (a > 0);
Maxima was unable to evaluate the predicate:
a > 0
-- an error. Quitting. To debug this try debugmode(true);
(%i4) prederror: false$
(%i5) is (a > 0);
(%o5) unknown
Function killcontext (context 1, . . . , context n)
Kills the contexts context 1, . . . , context n.
If one of the contexts is the current context, the new current context will become the
rst available subcontext of the current context which has not been killed. If the rst
available unkilled context is global then initial is used instead. If the initial
context is killed, a new, empty initial context is created.
killcontext refuses to kill a context which is currently active, either because it is a
subcontext of the current context, or by use of the function activate.
killcontext evaluates its arguments. killcontext returns done.
Chapter 11: Maximas Database 179
Function maybe (expr)
Attempts to determine whether the predicate expr is provable from the facts in the
assume database.
If the predicate is provably true or false, maybe returns true or false, respectively.
Otherwise, maybe returns unknown.
maybe is functionally equivalent to is with prederror: false, but the result is com-
puted without actually assigning a value to prederror.
See also assume, facts, and is.
Examples:
(%i1) maybe (x > 0);
(%o1) unknown
(%i2) assume (x > 1);
(%o2) [x > 1]
(%i3) maybe (x > 0);
(%o3) true
Function newcontext (name)
Creates a new, empty context, called name, which has global as its only subcontext.
The newly-created context becomes the currently active context.
newcontext evaluates its argument. newcontext returns name.
Function sign (expr)
Attempts to determine the sign of expr on the basis of the facts in the current data
base. It returns one of the following answers: pos (positive), neg (negative), zero, pz
(positive or zero), nz (negative or zero), pn (positive or negative), or pnz (positive,
negative, or zero, i.e. nothing known).
Function supcontext (name, context)
Function supcontext (name)
Creates a new context, called name, which has context as a subcontext. context must
exist.
If context is not specied, the current context is assumed.
11.4 Functions and Variables for Predicates
Function charfun (p)
Return 0 when the predicate p evaluates to false; return 1 when the predicate
evaluates to true. When the predicate evaluates to something other than true or
false (unknown), return a noun form.
Examples:
180 Maxima 5.30.0 Manual
(%i1) charfun (x < 1);
(%o1) charfun(x < 1)
(%i2) subst (x = -1, %);
(%o2) 1
(%i3) e : charfun ("and" (-1 < x, x < 1))$
(%i4) [subst (x = -1, e), subst (x = 0, e), subst (x = 1, e)];
(%o4) [0, 1, 0]
Function compare (x, y)
Return a comparison operator op (<, <=, >, >=, =, or #) such that is (x op y) eval-
uates to true; when either x or y depends on %i and x # y, return notcomparable;
when there is no such operator or Maxima isnt able to determine the operator, return
unknown.
Examples:
(%i1) compare (1, 2);
(%o1) <
(%i2) compare (1, x);
(%o2) unknown
(%i3) compare (%i, %i);
(%o3) =
(%i4) compare (%i, %i + 1);
(%o4) notcomparable
(%i5) compare (1/x, 0);
(%o5) #
(%i6) compare (x, abs(x));
(%o6) <=
The function compare doesnt try to determine whether the real domains of its argu-
ments are nonempty; thus
(%i1) compare (acos (x^2 + 1), acos (x^2 + 1) + 1);
(%o1) <
The real domain of acos (x^2 + 1) is empty.
Function equal (a, b)
Represents equivalence, that is, equal value.
By itself, equal does not evaluate or simplify. The function is attempts to evaluate
equal to a Boolean value. is(equal(a, b)) returns true (or false) if and only if a
and b are equal (or not equal) for all possible values of their variables, as determined by
evaluating ratsimp(a - b); if ratsimp returns 0, the two expressions are considered
equivalent. Two expressions may be equivalent even if they are not syntactically equal
(i.e., identical).
When is fails to reduce equal to true or false, the result is governed by the global
ag prederror. When prederror is true, is complains with an error message.
Otherwise, is returns unknown.
In addition to is, some other operators evaluate equal and notequal to true or
false, namely if, and, or, and not.
Chapter 11: Maximas Database 181
The negation of equal is notequal.
Examples:
By itself, equal does not evaluate or simplify.
(%i1) equal (x^2 - 1, (x + 1) * (x - 1));
2
(%o1) equal(x - 1, (x - 1) (x + 1))
(%i2) equal (x, x + 1);
(%o2) equal(x, x + 1)
(%i3) equal (x, y);
(%o3) equal(x, y)
The function is attempts to evaluate equal to a Boolean value. is(equal(a, b))
returns true when ratsimp(a - b) returns 0. Two expressions may be equivalent
even if they are not syntactically equal (i.e., identical).
(%i1) ratsimp (x^2 - 1 - (x + 1) * (x - 1));
(%o1) 0
(%i2) is (equal (x^2 - 1, (x + 1) * (x - 1)));
(%o2) true
(%i3) is (x^2 - 1 = (x + 1) * (x - 1));
(%o3) false
(%i4) ratsimp (x - (x + 1));
(%o4) - 1
(%i5) is (equal (x, x + 1));
(%o5) false
(%i6) is (x = x + 1);
(%o6) false
(%i7) ratsimp (x - y);
(%o7) x - y
(%i8) is (equal (x, y));
(%o8) unknown
(%i9) is (x = y);
(%o9) false
When is fails to reduce equal to true or false, the result is governed by the global
ag prederror.
(%i1) [aa : x^2 + 2*x + 1, bb : x^2 - 2*x - 1];
2 2
(%o1) [x + 2 x + 1, x - 2 x - 1]
(%i2) ratsimp (aa - bb);
(%o2) 4 x + 2
(%i3) prederror : true;
(%o3) true
(%i4) is (equal (aa, bb));
Maxima was unable to evaluate the predicate:
2 2
equal(x + 2 x + 1, x - 2 x - 1)
-- an error. Quitting. To debug this try debugmode(true);
(%i5) prederror : false;
(%o5) false
182 Maxima 5.30.0 Manual
(%i6) is (equal (aa, bb));
(%o6) unknown
Some operators evaluate equal and notequal to true or false.
(%i1) if equal (y, y - 1) then FOO else BAR;
(%o1) BAR
(%i2) eq_1 : equal (x, x + 1);
(%o2) equal(x, x + 1)
(%i3) eq_2 : equal (y^2 + 2*y + 1, (y + 1)^2);
2 2
(%o3) equal(y + 2 y + 1, (y + 1) )
(%i4) [eq_1 and eq_2, eq_1 or eq_2, not eq_1];
(%o4) [false, true, true]
Because not expr causes evaluation of expr, not equal(a, b) is equivalent to
is(notequal(a, b)).
(%i1) [notequal (2*z, 2*z - 1), not equal (2*z, 2*z - 1)];
(%o1) [notequal(2 z, 2 z - 1), true]
(%i2) is (notequal (2*z, 2*z - 1));
(%o2) true
Function notequal (a, b)
Represents the negation of equal(a, b).
Examples:
(%i1) equal (a, b);
(%o1) equal(a, b)
(%i2) maybe (equal (a, b));
(%o2) unknown
(%i3) notequal (a, b);
(%o3) notequal(a, b)
(%i4) not equal (a, b);
(%o4) notequal(a, b)
(%i5) maybe (notequal (a, b));
(%o5) unknown
(%i6) assume (a > b);
(%o6) [a > b]
(%i7) equal (a, b);
(%o7) equal(a, b)
(%i8) maybe (equal (a, b));
(%o8) false
(%i9) notequal (a, b);
(%o9) notequal(a, b)
(%i10) maybe (notequal (a, b));
(%o10) true
Function unknown (expr)
Returns true if and only if expr contains an operator or function not recognized by
the Maxima simplier.
Chapter 11: Maximas Database 183
Function zeroequiv (expr, v)
Tests whether the expression expr in the variable v is equivalent to zero, returning
true, false, or dontknow.
zeroequiv has these restrictions:
1. Do not use functions that Maxima does not know how to dierentiate and eval-
uate.
2. If the expression has poles on the real line, there may be errors in the result (but
this is unlikely to occur).
3. If the expression contains functions which are not solutions to rst order dier-
ential equations (e.g. Bessel functions) there may be incorrect results.
4. The algorithm uses evaluation at randomly chosen points for carefully selected
subexpressions. This is always a somewhat hazardous business, although the
algorithm tries to minimize the potential for error.
For example zeroequiv (sin(2 * x) - 2 * sin(x) * cos(x), x) returns true and
zeroequiv (%e^x + x, x) returns false. On the other hand zeroequiv (log(a *
b) - log(a) - log(b), a) returns dontknow because of the presence of an extra pa-
rameter b.
184 Maxima 5.30.0 Manual
Chapter 12: Plotting 185
12 Plotting
12.1 Introduction to Plotting
Maxima uses an external plotting package to make the plots (see the section on Plotting
formats). The plotting functions calculate a set of points and pass them to the plotting
package together with a set of commands. That information can be passed to the ex-
ternal program either through a pipe or by calling the program with the name of a le
where the data has been saved. The data le is given the name maxout.interface, where
interface is the name of the plotting interface being used (gnuplot, xmaxima, mgnuplot
or gnuplot pipes).
The maxout.interface le, in the cases when it is used, is created in the directory
specied by the system variable maxima_tempdir. That location can be changed; by
assigning to that variable a string that represents a valid directory where Maxima can
create new les.
After a plot has been created, the le maxout.interface can be executed again with
the appropriate external program. If a Maxima plotting command fails to show anything,
that le can be inspected to look for possible sources of problems.
Together with the plotting functions described in this chapter, package Chapter 48
[draw], page 699 adds other functionalities. Note that some plotting options are named
equal in both plotting contexts, but with dierent syntax; if you want to access the draw
information related to these options, you have to type ?? opt, where opt is the name of the
option.
12.2 Plotting Formats
There are currently two external plotting programs that Maxima use: Gnuplot and
Xmaxima. There are various dierent formats for those programs, which can be selected
with the option plot_format (see the Plotting Options section).
The plotting formats are the following:
gnuplot (default on Windows)
Used to launch the external program gnuplot, which must be installed in your system.
All plotting commands and data are saved into the le maxout.gnuplot.
gnuplot pipes (default on non-Windows platforms)
This format is not available in Windows platforms. It is similar to the gnuplot format
except that the commands are sent to gnuplot through a pipe, while the data are
saved into the le maxout.gnuplot_pipes. A single gnuplot process is kept open and
subsequent plot commands will be sent to the same process, replacing previous plots,
unless the gnuplot pipe is closed with the function gnuplot_close. When this format
is used, the function gnuplot_replot can be used to modify a plot that has already
displayed on the screen.
This format should only be used to plot to the screen; for plotting to les it is better
to use the gnuplot format.
186 Maxima 5.30.0 Manual
mgnuplot
Mgnuplot is a Tk-based wrapper around gnuplot. It is included in the Maxima distri-
bution. Mgnuplot oers a rudimentary GUI for gnuplot, but has fewer overall features
than the plain gnuplot interface. Mgnuplot requires an external gnuplot installation
and, in Unix systems, the Tcl/Tk system.
xmaxima
Xmaxima is a Tcl/Tk graphical interface for Maxima that can also be used to display
plots created when Maxima is run from the console or from other graphical interfaces.
To use this format, the xmaxima program, which is distributed together with Maxima,
should be installed. If Maxima is being run from xmaxima itself, this format will make
the plot functions send the data and commands through the same socket used for the
communication between Maxima and Xmaxima. When used from the console or from
other interface, the commands and data will be saved in the le maxout.xmaxima, and
the xmaxima program will be launched with the name of the location of that le as
argument.
In previous versions this format used to be called openmath; that old name will still be
accepted as a synonym for xmaxima.
12.3 Functions and Variables for Plotting
Function contour plot (expr, x range, y range, options, . . . )
It plots the contours (curves of equal value) of expr over the region x range by y range.
Any additional arguments are treated the same as in plot3d.
This function only works when the plot format is either gnuplot or gnuplot_pipes.
The additional package implicit_plot can also be used to plot contours and it works
for any format. See implicit_plot.
Examples:
(%i1) contour_plot (x^2 + y^2, [x, -4, 4], [y, -4, 4])$
30
20
10
-4 -3 -2 -1 0 1 2 3 4
x
-4
-3
-2
-1
0
1
2
3
4
y
Chapter 12: Plotting 187
(%i1) F(x, y) := x^3 + y^2;
3 2
(%o1) F(x, y) := x + y
(%i2) contour_plot (F, [u, -4, 4], [v, -4, 4])$
50
0
-50
-4 -3 -2 -1 0 1 2 3 4
u
-4
-3
-2
-1
0
1
2
3
4
v
You can add any options accepted by plot3d; for instance, the option legend with
a value of false, to remove the legend. Gnuplot chooses, by default, 3 contours to
show. To increase the number of levels, it is necessary to specify a custom gnuplot
preamble:
(%i1) contour_plot (u^3 + v^2, [u, -4, 4], [v, -4, 4],
[legend,false],
[gnuplot_preamble, "set cntrparam levels 12"])$
-4 -3 -2 -1 0 1 2 3 4
u
-4
-3
-2
-1
0
1
2
3
4
v
Function get plot option (keyword, index)
Returns a value of the option with name keyword, stored in the global variable plot_
options. A value of 1 for the index will return the keyword itself; a value of 2 turn
returns the rst parameter following the keyword, and so on.
See also plot_options, set_plot_option and the section on Plotting Options.
188 Maxima 5.30.0 Manual
Function implicit plot (expr, x range, y range)
Function implicit plot ([expr 1, . . . , expr n], x range, y range)
Displays a plot of one or more expressions in implicit form. expr is the expression
to be plotted, x range the range of the horizontal axis and y range the range of
vertical axis. implicit_plot respects global setting for the Gnuplot driver set by
the set plot option function. Options can also be passed to implicit_plot function
as optional arguments.
implicit_plot works by tracking sign changes on the area given by x range and
y range and can fail for complicated expressions.
load(implicit_plot) loads this function.
Example:
(%i1) implicit_plot (x^2 = y^3 - 3*y + 1, [x, -4, 4], [y, -4, 4],
[gnuplot_preamble, "set zeroaxis"]);
-4
-3
-2
-1
0
1
2
3
4
-4 -3 -2 -1 0 1 2 3 4
x
2
= y
3
-3*y+1
Function make transform ([var1, var2, var3], fx, fy, fz)
Returns a function suitable to be used in the option transform_xy of plot3d. The
three variables var1, var2, var3 are three dummy variable names, which represent
the 3 variables given by the plot3d command (rst the two independent variables
and then the function that depends on those two variables). The three functions fx,
fy, fz must depend only on those 3 variables, and will give the corresponding x, y
and z coordinates that should be plotted. There are two transformations dened by
default: polar_to_xy and spherical_to_xyz. See the documentation for those
two transformations.
System function polar to xy
It can be given as value for the transform_xy option of plot3d. Its eect will be to
interpret the two independent variables in plot3d as the distance from the z axis and
the azimuthal angle (polar coordinates), and transform them into x and y coordinates.
Chapter 12: Plotting 189
Function plot2d (plot, x range, . . . , options, . . . )
Function plot2d ([plot 1, . . . , plot n], . . . , options, . . . )
Function plot2d ([plot 1, . . . , plot n], x range, . . . , options, . . . )
Where plot, plot 1, . . . , plot n can be either expressions, function names or a list
with the any of the forms: [discrete, [x1, ..., xn], [y1, ..., yn]], [discrete,
[[x1, y1], ..., [xn, ..., yn]] or [parametric, x expr, y expr, t range].
Displays a plot of one or more expressions as a function of one variable or parameter.
plot2d displays one or several plots in two dimensions. When expressions or function
name are used to dene the plots, they should all depend on only one variable var
and the use of x range will be mandatory, to provide the name of the variable and its
minimum and maximum values; the syntax for x range is: [variable, min, max].
A plot can also be dened in the discrete or parametric forms. The discrete form is
used to plot a set of points with given coordinates. A discrete plot is dened by a list
starting with the keyword discrete, followed by one or two lists of values. If two lists
are given, they must have the same length; the rst list will be interpreted as the x
coordinates of the points to be plotted and the second list as the y coordinates. If
only one list is given after the discrete keyword, each element on the list should also
be a list with two values that correspond to the x and y coordinates of a point.
A parametric plot is dened by a list starting with the keyword parametric, followed
by two expressions or function names and a range for the parameter. The range for
the parameter must be a list with the name of the parameter followed by its minimum
and maximum values: [param, min, max]. The plot will show the path traced out
by the point with coordinates given by the two expressions or functions, as param
increases from min to max.
A range for the vertical axis is an optional argument with the form: [y, min, max]
(the keyword y is always used for the vertical axis). If that option is used, the plot
will show that exact vertical range, independently of the values reached by the plot.
If the vertical range is not specied, it will be set up according to the minimum and
maximum values of the second coordinate of the plot points.
All other options should also be lists, starting with a keyword and followed by one or
more values. See plot_options.
If there are several plots to be plotted, a legend will be written to identity each of
the expressions. The labels that should be used in that legend can be given with
the option legend. If that option is not used, Maxima will create labels from the
expressions or function names.
Examples:
Plot of a common function:
190 Maxima 5.30.0 Manual
(%i1) plot2d (sin(x), [x, -%pi, %pi])$
-1
-0.5
0
0.5
1
-3 -2 -1 0 1 2 3
s
i
n
(
x
)
x
If the functions grows too fast, it might be necessary to limit the values in the vertical
axis using the y option:
(%i1) plot2d (sec(x), [x, -2, 2], [y, -20, 20])$
plot2d: some values were clipped.
-20
-15
-10
-5
0
5
10
15
20
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
s
e
c
(
x
)
x
The aspect of the plot might be dierent depending on the plotting program used.
For instance, when the plot box is disable, Xmaxima will plot the axes using arrows:
Chapter 12: Plotting 191
(%i1) plot2d ( x^2-1, [x, -3, 3], [y, -2, 10],
[box, false], [plot_format, xmaxima])$
x^2-1
x
A plot with a logarithmic scale:
(%i1) plot2d (exp(3*s), [s, -2, 2], [logy])$
0.001
0.01
0.1
1
10
100
1000
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
%
e
^
(
3
*
s
)
s
Plotting functions by name:
(%i1) F(x) := x^2 $
(%i2) :lisp (defun |$g| (x) (m* x x x))
$g
(%i2) H(x) := if x < 0 then x^4 - 1 else 1 - x^5 $
192 Maxima 5.30.0 Manual
(%i3) plot2d ([F, G, H], [u, -1, 1], [y, -1.5, 1.5])$
-1.5
-1
-0.5
0
0.5
1
1.5
-1 -0.5 0 0.5 1
y
u
F
G
H
A plot of the buttery curve, dened parametrically:
(%i1) r: (exp(cos(t))-2*cos(4*t)-sin(t/12)^5)$
(%i2) plot2d([parametric, r*sin(t), r*cos(t),
[t, -8*%pi, 8*%pi], [nticks, 2000]])$
-3
-2
-1
0
1
2
3
4
-4 -3 -2 -1 0 1 2 3 4
c
o
s
(
t
)
*
(
-
2
*
c
o
s
(
4
*
t
)
-
s
i
n
(
t
/
1
2
)
^
5
+
%
e
^
c
o
s
(
t
)
)
sin(t)*(-2*cos(4*t)-sin(t/12)^5+%e^cos(t))
A circle with two turns, when plotted with only 7 points:
Chapter 12: Plotting 193
(%i1) plot2d ([parametric, cos(t), sin(t),
[t, -2*%pi, 2*%pi], [nticks, 8]])$
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
s
i
n
(
t
)
cos(t)
Plot of a common function together with the parametric representation of a circle.
The size of the plot has been adjusted with the x and y options, to make the circle
look round and not deformed as an ellipse. These values work well for the Postscript
terminal used to produce this plot; you might have to adjust the values for your
screen.
(%i1) plot2d([[parametric, cos(t), sin(t),
[t,0,2*%pi], [nticks, 80]],
abs(x)], [x,-2,2], [y, -1.5, 1.5])$
plot2d: some values were clipped.
-1.5
-1
-0.5
0
0.5
1
1.5
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
y
x
cos(t), sin(t)
abs(x)
A plot of a discrete set of points, dening x and y coordinates separately:
194 Maxima 5.30.0 Manual
(%i1) plot2d ([discrete, [10, 20, 30, 40, 50],
[.6, .9, 1.1, 1.3, 1.4]])$
0.5
0.6
0.7
0.8
0.9
1
1.1
1.2
1.3
1.4
10 15 20 25 30 35 40 45 50
y
x
The same points shown in the previous example, dening each point separately and
without any lines joining the points:
(%i1) plot2d([discrete, [[10, .6], [20, .9], [30, 1.1],
[40, 1.3], [50, 1.4]]],
[style, points])$
0.5
0.6
0.7
0.8
0.9
1
1.1
1.2
1.3
1.4
10 15 20 25 30 35 40 45 50
y
x
In this example, a table with three columns is saved in a le data.txt which is then
read and the second and third column are plotted on the two axes:
(%i1) with_stdout ("data.txt", for x:0 thru 10 do
print (x, x^2, x^3))$
(%i2) data: read_matrix ("data.txt")$
Chapter 12: Plotting 195
(%i3) plot2d ([discrete, transpose(data)[2], transpose(data)[3]],
[style,points], [point_type,diamond], [color,red])$
0
200
400
600
800
1000
0 20 40 60 80 100
y
x
A plot of experimental data points together with the theoretical function that predicts
the data:
(%i1) xy: [[10, .6], [20, .9], [30, 1.1], [40, 1.3], [50, 1.4]]$
(%i2) plot2d([[discrete, xy], 2*%pi*sqrt(l/980)], [l,0,50],
[style, points, lines], [color, red, blue],
[point_type, asterisk],
[legend, "experiment", "theory"],
[xlabel, "pendulums length (cm)"],
[ylabel, "period (s)"])$
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
0 10 20 30 40 50
p
e
r
i
o
d

(
s
)
pendulums length (cm)
experiment
theory
See also the section about Plotting Options.
Function plot3d (expr, x range, y range, . . . , options, . . . )
Function plot3d ([expr 1, . . . , expr n], x range, y range, . . . , options, . . . )
Displays a plot of one or more surfaces dened as functions of two variables or in
parametric form.
196 Maxima 5.30.0 Manual
The functions to be plotted may be specied as expressions or function names. The
mouse can be used to rotate the plot looking at the surface from dierent sides.
Examples:
Plot of a common function:
(%i1) plot3d (2^(-u^2 + v^2), [u, -3, 3], [v, -2, 2])$
-3
-2
-1
0
1
2
3
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
0
2
4
6
8
10
12
14
16
z
2^(v^2-u^2)
u
v
z
Use of the z option to limit a function that goes to innity (in this case the function
is minus innity on the x and y axes); this also shows how to plot with only lines and
no shading:
(%i1) plot3d ( log ( x^2*y^2 ), [x, -2, 2], [y, -2, 2], [z, -8, 4],
[palette, false], [color, magenta, blue])$
log(x^2*y^2)
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
x
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
y
-8
-6
-4
-2
0
2
4
z
The innite values of z can also be avoided by choosing a grid that does not fall on
any asymptotes; this example also shows how to select one of the predened palettes,
in this case the fourth one:
Chapter 12: Plotting 197
(%i1) plot3d (log (x^2*y^2), [x, -2, 2], [y, -2, 2],
[grid, 29, 29],
[palette, get_plot_option(palette,5)])$
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
-12
-10
-8
-6
-4
-2
0
2
4
z
log(x^2*y^2)
x
y
z
Two surfaces in the same plot, sharing the same domain; in gnuplot the two surfaces
will use the same palette:
(%i1) plot3d ([2^(-x^2 + y^2), 4*sin(3*(x^2+y^2))/(x^2+y^2),
[x, -3, 3], [y, -2, 2]])$
-3
-2
-1
0
1
2
3
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
-4
-2
0
2
4
6
8
10
12
14
16
z
4*sin(3*(y^2+x^2))/(y^2+x^2)
2^(y^2-x^2)
x
y
z
The same two surfaces, but now with dierent domains; in xmaxima each surface will
use a dierent palette, chosen from the list dened by the option palette:
198 Maxima 5.30.0 Manual
(%i1) plot3d ([[2^(-x^2 + y^2),[x,-2,2],[y,-2,2]],
4*sin(3*(x^2+y^2))/(x^2+y^2),
[x, -3, 3], [y, -2, 2]], [plot_format,xmaxima])$
Plot of a Klein bottle, dened parametrically:
(%i1) expr_1:5*cos(x)*(cos(x/2)*cos(y)+sin(x/2)*sin(2*y)+3.0)-10.0$
(%i2) expr_2:-5*sin(x)*(cos(x/2)*cos(y) + sin(x/2)*sin(2*y) + 3.0)$
(%i3) expr_3: 5*(-sin(x/2)*cos(y) + cos(x/2)*sin(2*y))$
(%i4) plot3d ([expr_1, expr_2, expr_3], [x, -%pi, %pi],
[y, -%pi, %pi], [grid, 40, 40])$
-35
-30
-25
-20
-15
-10
-5
0
5
10
-25
-20
-15
-10
-5
0
5
10
15
20
25
-8
-6
-4
-2
0
2
4
6
8
z
Parametric function
x
y
z
Plot of a spherical harmonic, using of the predened transformations, spherical_to_
xyz, to transform from spherical to rectangular coordinates. See the documentation
for spherical_to_xyz.
Chapter 12: Plotting 199
(%i1) plot3d (sin(2*theta)*cos(phi), [theta, 0, %pi],
[phi, 0, 2*%pi],
[transform_xy, spherical_to_xyz], [grid,30,60])$
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
-0.4
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
z
cos(phi)*sin(2*theta)
x
y
z
Use of the predened function polar_to_xy to transform from cylindrical to rect-
angular coordinates. See the documentation for polar_to_xy. This example also
shows how to eliminate the bounding box and the legend.
(%i1) plot3d (r^.33*cos(th/3), [r, 0, 1], [th, 0, 6*%pi],
[grid, 12, 80],
[transform_xy, polar_to_xy], [box, false],
[legend,false])$
Plot of a sphere using the transformation from spherical to rectangular coordinates. In
xmaxima the three axes are scaled in the same proportion, maintaining the symmetric
shape of the sphere. A palette with dierent shades of a single color is used:
200 Maxima 5.30.0 Manual
(%i1) plot3d ( 5, [theta, 0, %pi], [phi, 0, 2*%pi],
[plot_format,xmaxima],
[transform_xy, spherical_to_xyz],
[palette,[value,0.65,0.7,0.1,0.9]])$
Denition of a function of two-variables using a matrix. Notice the single quote in
the denition of the function, to prevent plot3d from failing when it realizes that the
matrix will require integer indices.
(%i1) M: matrix([1, 2, 3, 4], [1, 2, 3, 2], [1, 2, 3, 4],
[1, 2, 3, 3])$
(%i2) f(x, y) := float(M [round(x), round(y)])$
(%i3) plot3d (f(x,y), [x, 1, 4], [y, 1, 4], [grid, 4, 4])$
apply: subscript must be an integer; found: round(x)
1
1.5
2
2.5
3
3.5
4
1
1.5
2
2.5
3
3.5
4
1
1.5
2
2.5
3
3.5
4
z
M[round(x),round(y)]
x
y
z
Chapter 12: Plotting 201
By setting the elevation equal to zero, a surface can be seen as a map in which
each color represents a dierent level. The option colorbox is used to show the
correspondence among colors and levels, and the mesh lines are disabled to make the
colors easier to see.
(%i1) plot3d (cos (-x^2 + y^3/4), [x, -4, 4], [y, -4, 4],
[mesh_lines_color, false], [elevation, 0], [azimuth, 0],
[colorbox, true], [grid, 150, 150])$
-4 -3 -2 -1 0 1 2 3 4
-4
-3
-2
-1
0
1
2
3
4
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 z
cos(y^3/4-x^2)
x
y
z
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
See also the section about Plotting Options.
System variable plot options
Elements of this list state the default options for plotting. If an option is present
in a plot2d or plot3d call, that value takes precedence over the default option.
Otherwise, the value in plot_options is used. Default options are assigned by set_
plot_option. There are other local options specic to each plotting command, and
not included in this list of global options.
Each element of plot_options is a list of two or more items. The rst item is the
name of the option, and the remainder comprises the value or values assigned to the
option. In some cases, the assigned value is a list, which may include several items.
See also set_plot_option, get_plot_option and the section on Plotting Options.
Function set plot option (option)
Accepts most of the options listed in the section Plotting Options, and saves them
into the global variable plot_options.
set_plot_option evaluates its argument and returns the complete list plot_options
(after modifying the option given).
See also plot_options, get_plot_option and the section on Plotting Options.
Example:
Modication of the grid values.
202 Maxima 5.30.0 Manual
(%i1) set_plot_option ([grid, 30, 40]);
(%o1) [[t, - 3, 3], [grid, 30, 40], [transform_xy, false],
[run_viewer, true], [axes, true], [plot_format, gnuplot_pipes],
[color, blue, red, green, magenta, black, cyan],
[point_type, bullet, circle, plus, times, asterisk, box, square,
triangle, delta, wedge, nabla, diamond, lozenge],
[palette, [hue, 0.25, 0.7, 0.8, 0.5],
[hue, 0.65, 0.8, 0.9, 0.55], [hue, 0.55, 0.8, 0.9, 0.4],
[hue, 0.95, 0.7, 0.8, 0.5]], [gnuplot_term, default],
[gnuplot_out_file, false], [nticks, 29], [adapt_depth, 5],
[gnuplot_preamble, ], [gnuplot_default_term_command,
set term pop], [gnuplot_dumb_term_command, set term dumb 79 22],
[gnuplot_ps_term_command, set size 1.5, 1.5;set term postscript \
eps enhanced color solid 24], [plot_realpart, false]]
System function spherical to xyz
It can be given as value for the transform_xy option of plot3d. Its eect will be to
interpret the two independent variables and the function in plot3d as the spherical
coordinates of a point (rst, the angle with the z axis, then the angle of the xy
projection with the x axis and nally the distance from the origin) and transform
them into x, y and z coordinates.
12.4 Plotting Options
All options consist of a list starting with one of the keywords in this section, followed
by one or more values. Most of the options can be used in any of the plotting commands
(plot2d, plot3d, contour_plot, implicit_plot) or in the function set_plot_option.
The exceptions will be specied in the following list.
Plot option adapt depth [adapt depth, integer]
Default value: 5
The maximum number of splittings used by the adaptive plotting routine.
Plot option axes [axes, symbol]
Default value: true
Where symbol can be either true, false, x or y. If false, no axes will be shown;
if equal to x or y only the x or y axis will be shown, and if it is equal to true, both
axes will be shown. This option is used only by plot2d and implicit plot.
Plot option azimuth [azimuth, number]
Default value: 30
A plot3d plot can be thought of as starting with its x and y axis in the horizontal and
vertical axis, as in plot2d, and the z axis coming out of the paper perpendicularly.
The z axis is then rotated around the x axis an angle equals to elevation and then
the xy plane is rotated around the new z axis an angle azimuth. This option sets the
value for the azimuth, in degrees.
See also elevation.
Chapter 12: Plotting 203
Plot option box [box, symbol]
Default value: true
If set to true, a bounding box will be drawn for the plot; if set to false, no box will
be drawn.
Plot option color [color, color 1, . . . , color n]
Default value: blue, red, green, magenta, black, cyan
In plot2d and implicit_plot, it denes the color (or colors) for the various curves.
In plot3d, it denes the colors used for the mesh lines of the surfaces, when no
palette is being used; one side of the surface will have color color 1 and the other
color 2 (or the same color if there is only one color).
If there are more curves or surfaces than colors, the colors will be repeated in sequence.
When using gnuplot, the colors could be: blue, red, green, magenta, black, or
cyan; in xmaxima the colors can be those or a string starting with the character #
and followed by six hexadecimal digits: two for the red component, two for green
component and two for the blue component. If given the name of an unknown color,
black will be used instead.
Plot option colorbox [colorbox, symbol]
Default value: false
Where symbol can be either true or false. If true, whenever plot3d uses a palette
of dierent colors to represent the dierent values of z, a box will be shown on the
right, indicating the colors used according to the scale of values of z. This option
does not work in xmaxima.
Plot option elevation [elevation, number]
Default value: 60
A plot3d plot can be thought of as starting with its x and y axis in the horizontal and
vertical axis, as in plot2d, and the z axis coming out of the paper perpendicularly.
The z axis is then rotated around the x axis an angle equals to elevation and then
the xy plane is rotated around the new z axis an angle azimuth. This option sets the
value for the elevation, in degrees.
See also azimuth.
Plot option grid [grid, integer, integer]
Default value: 30, 30
Sets the number of grid points to use in the x- and y-directions for three-dimensional
plotting.
Plot option legend [legend, string 1, . . . , string n]
Plot option legend [legend, false]
It species the labels for the plots when various plots are shown. If there are more
plots than the number of labels given, they will be repeated. If given the value false,
204 Maxima 5.30.0 Manual
no legends will be shown. By default, the names of the expressions or functions will
be used, or the words discrete1, discrete2, . . . , for discrete sets of points. This option
can not be set with set_plot_option.
Plot option logx [logx]
Makes the horizontal axes to be scaled logarithmically. It can not be used with
set_plot_option.
Plot option logy [logy]
Makes the vertical axes to be scaled logarithmically. It can not be used with set_
plot_option.
Plot option mesh lines color [mesh lines color, color]
Default value: black
It sets the color used by plot3d to draw the mesh lines, when a palette is being used.
It accepts the same colors as for the option color (see the list of allowed colors in
color). It can also be given a value false to eliminate completely the mesh lines.
Plot option nticks [nticks, integer]
Default value: 29
When plotting functions with plot2d, it is gives the initial number of points used
by the adaptive plotting routine for plotting functions. When plotting parametric
functions with plot2d or plot3d, it sets the number of points that will be shown for
the plot.
Plot option palette [palette, [palette 1], . . . , [palette n]]
Plot option palette [palette, false]
Default value: [hue, 0.25, 0.7, 0.8, 0.5], [hue, 0.65, 0.8, 0.9, 0.55], [hue,
0.55, 0.8, 0.9, 0.4], [hue, 0.95, 0.7, 0.8, 0.5]
It can consist of one palette or a list of several palettes. Each palette is a list with a
keyword followed by four numbers. The rst three numbers, which must be between
0 and 1, dene the hue, saturation and value of a basic color to be assigned to
the minimum value of z. The keyword species which of the three attributes (hue,
saturation or value) will be increased according to the values of z. The last number
indicates the increase corresponding to the maximum value of z. That last number
can be bigger than 1 or negative; the corresponding values of the modied attribute
will be rounded modulo 1.
Gnuplot only uses the rst palette in the list; xmaxima will use the palettes in the
list sequentially, when several surfaces are plotted together; if the number of palettes
is exhausted, they will be repeated sequentially.
The color of the mesh lines will be given by the option mesh_lines_color. If
palette is given the value false, the surfaces will not be shaded but represented
with a mesh of curves only. In that case, the colors of the lines will be determined by
the option color.
Chapter 12: Plotting 205
Plot option plot format [plot format, format]
Default value: gnuplot, in Windows systems, or gnuplot_pipes in other systems.
Where format is one of the following: gnuplot, xmaxima, mgnuplot or gnuplot pipes.
It sets the format to be used for plotting.
Plot option plot realpart [plot realpart, symbol]
Default value: false
If set to true, the functions to be plotted will be considered as complex functions
whose real value should be plotted; this is equivalent to plotting realpart(function).
If set to false, nothing will be plotted when the function does not give a real value.
For instance, when x is negative, log(x) gives a complex value, with real value equal
to log(abs(x)); if plot_realpart were true, log(-5) would be plotted as log(5),
while nothing would be plotted if plot_realpart were false.
Plot option point type [point type, type 1, . . . , type n]
Default value: bullet, circle, plus, times, asterisk, box, square, triangle,
delta, wedge, nabla, diamond, lozenge
In gnuplot, each set of points to be plotted with the style points or linespoints
will be represented with objects taken from this list, in sequential order. If there are
more sets of points than objects in this list, they will be repeated sequentially. The
possible objects that can be used are: bullet, circle, plus, times, asterisk, box,
square, triangle, delta, wedge, nabla, diamond, lozenge
Plot option psle [psle, string]
Saves the plot into a Postscript le with name equal to string, rather than showing
it in the screen. By default, the le will be created in the directory dened by the
variable maxima_tempdir. The value of that variable can be changed to save the le
in a dierent directory.
Plot option run viewer [run viewer, symbol]
Default value: true
Controls whether or not the appropriate viewer for the plot format should be run.
Plot option style [style, type 1, . . . , type1 n]
Plot option style [style, [style 1], . . . , [style n]]
Default value: lines (will plot all sets of points joined with lines of thickness 1 and
the rst color given by the option color ).
The styles that will be used for the various functions or sets of data in a 2d plot. The
word style must be followed by one or more styles. If there are more functions and
data sets than the styles given, the styles will be repeated. Each style can be either
lines for line segments, points for isolated points, linespoints for segments and points,
or dots for small isolated dots. Gnuplot accepts also an impulses style.
206 Maxima 5.30.0 Manual
Each of the styles can be enclosed inside a list with some additional parameters. lines
accepts one or two numbers: the width of the line and an integer that identies a
color. The default color codes are: 1: blue, 2: red, 3: magenta, 4: orange, 5: brown,
6: lime and 7: aqua. If you use Gnuplot with a terminal dierent than X11, those
colors might be dierent; for example, if you use the option [gnuplot term, ps], color
index 4 will correspond to black, instead of orange.
points accepts one two or three parameters; the rst parameter is the radius of the
points, the second parameter is an integer that selects the color, using the same
code used for lines and the third parameter is currently used only by Gnuplot and
it corresponds to several objects instead of points. The default types of objects are:
1: lled circles, 2: open circles, 3: plus signs, 4: x, 5: *, 6: lled squares, 7: open
squares, 8: lled triangles, 9: open triangles, 10: lled inverted triangles, 11: open
inverted triangles, 12: lled lozenges and 13: open lozenges.
linesdots accepts up to four parameters: line width, points radius, color and type of
object to replace the points.
See also color and point_type.
Plot option t [t, min, max]
Default value: -3, 3
Default range for parametric plots.
Plot option transform xy [transform xy, symbol]
Default value: false
Where symbol is either false or the result obtained by using the function transform_
xy. If dierent from false, it will be used to transform the 3 coordinates in plot3d.
See make_transform, polar_to_xy and spherical_to_xyz.
Plot option x [x, min, max]
When used as the rst option in a plot2d command (or any of the rst two in plot3d
), it indicates that the rst independent variable is x and it sets its range. It can also
be used again after the rst option (or after the second option in plot3d) to dene
the eective horizontal domain that will be shown in the plot.
Plot option xlabel [xlabel, string]
Species the string that will label the rst axis; if this option is not used, that label
will be the name of the independent variable, when plotting functions with plot2d or
implicit_plot, or the name of the rst variable, when plotting surfaces with plot3d
or contours with contour_plot, or the rst expression in the case of a parametric
plot. It can not be used with set_plot_option.
Plot option y [y, min, max]
When used as one of the rst two options in plot3d, it indicates that one of the
independent variables is y and it sets its range. Otherwise, it denes the eective
domain of the second variable that will be shown in the plot.
Chapter 12: Plotting 207
Plot option ylabel [ylabel, string]
Species the string that will label the second axis; if this option is not used, that
label will be y, when plotting functions with plot2d or implicit_plot, or the
name of the second variable, when plotting surfaces with plot3d or contours with
contour_plot, or the second expression in the case of a parametric plot. It can not
be used with set_plot_option.
Plot option z [z, min, max]
Used in plot3d to set the eective range of values of z that will be shown in the plot.
Plot option zlabel [zlabel, string]
Species the string that will label the third axis, when using plot3d. If this option
is not used, that label will be z, when plotting surfaces, or the third expression in
the case of a parametric plot. It can not be used with set_plot_option and it will
be ignored by plot2d and implicit_plot.
12.5 Gnuplot Options
There are several plot options specic to gnuplot. All of them consist of a keyword (the
name of the option), followed by a string that should be a valid gnuplot command, to be
passed directly to gnuplot. In most cases, there exist a corresponding plotting option that
will produce a similar result and whose use is more recommended than the gnuplot specic
option.
Plot option gnuplot term
Sets the output terminal type for gnuplot.
default (default value)
Gnuplot output is displayed in a separate graphical window.
dumb
Gnuplot output is displayed in the Maxima console by an "ASCII art" approxi-
mation to graphics.
ps
Gnuplot generates commands in the PostScript page description language. If
the option gnuplot_out_file is set to lename, gnuplot writes the PostScript
commands to lename. Otherwise, it is saved as maxplot.ps le.
any other valid gnuplot term specication
Gnuplot can generate output in many other graphical formats such as png, jpeg,
svg etc. To create plot in all these formats the gnuplot_term can be set to
any supported gnuplot term name (symbol) or even full gnuplot term specica-
tion with any valid options (string). For example [gnuplot_term, png] creates
output in PNG (Portable Network Graphics) format while [gnuplot_term, "png
size 1000,1000"] creates PNG of 1000 x 1000 pixels size. If the option gnuplot_
out_file is set to lename, gnuplot writes the output to lename. Otherwise,
it is saved as maxplot.term le, where term is gnuplot terminal name.
208 Maxima 5.30.0 Manual
Plot option gnuplot out le
When used in conjunction with the gnuplot_term option, it can be used to save the
plot in a le, in one of the graphic formats supported by Gnuplot. If you want to
create a Postscript le, you can use the option psfile instead, which will also work
in Openmath, and does the same thing with just one option.
[gnuplot_term, png], [gnuplot_out_file, "graph3.png"]
Plot option gnuplot pm3d
With a value of false, it can be used to prevent the usage of PM3D mode, which is
enabled by default.
Plot option gnuplot preamble
Inserts gnuplot commands before the plot is drawn. Any valid gnuplot commands may
be used. Multiple commands should be separated with a semi-colon. The example
shown produces a log scale plot. The default value for gnuplot_preamble is the
empty string "".
Plot option gnuplot curve titles
This is an old option that has been replaced by legend described above.
Plot option gnuplot curve styles
This is an obsolete option that has been replaced by style.
Plot option gnuplot default term command
The gnuplot command to set the terminal type for the default terminal. The default
value is "set term pop".
Plot option gnuplot dumb term command
The gnuplot command to set the terminal type for the dumb terminal. The default
value is "set term dumb 79 22", which makes the text output 79 characters by 22
characters.
Plot option gnuplot ps term command
The gnuplot command to set the terminal type for the PostScript terminal. The
default value is "set size 1.5, 1.5; set term postscript eps enhanced color
solid 24", which sets the size to 1.5 times gnuplots default, and the font size to 24,
among other things. See the gnuplot documentation for set term postscript for
more information.
Chapter 12: Plotting 209
12.6 Gnuplot pipes Format Functions
Function gnuplot start ()
Opens the pipe to gnuplot used for plotting with the gnuplot_pipes format. Is not
necessary to manually open the pipe before plotting.
Function gnuplot close ()
Closes the pipe to gnuplot which is used with the gnuplot_pipes format.
Function gnuplot restart ()
Closes the pipe to gnuplot which is used with the gnuplot_pipes format and opens
a new pipe.
Function gnuplot replot ()
Function gnuplot replot (s)
Updates the gnuplot window. If gnuplot_replot is called with a gnuplot command
in a string s, then s is sent to gnuplot before reploting the window.
Function gnuplot reset ()
Resets the state of gnuplot used with the gnuplot_pipes format To update the
gnuplot window call gnuplot_replot after gnuplot_reset.
210 Maxima 5.30.0 Manual
Chapter 13: File Input and Output 211
13 File Input and Output
13.1 Comments
A comment in Maxima input is any text between /* and */.
The Maxima parser treats a comment as whitespace for the purpose of nding tokens
in the input stream; a token always ends at a comment. An input such as a/* foo */b
contains two tokens, a and b, and not a single token ab. Comments are otherwise ignored
by Maxima; neither the content nor the location of comments is stored in parsed input
expressions.
Comments can be nested to arbitrary depth. The /* and */ delimiters form matching
pairs. There must be the same number of /* as there are */.
Examples:
(%i1) /* aa is a variable of interest */ aa : 1234;
(%o1) 1234
(%i2) /* Value of bb depends on aa */ bb : aa^2;
(%o2) 1522756
(%i3) /* User-defined infix operator */ infix ("b");
(%o3) b
(%i4) /* Parses same as a b c, not abc */ a/* foo */b/* bar */c;
(%o4) a b c
(%i5) /* Comments /* can be nested /* to any depth */ */ */ 1 + xyz;
(%o5) xyz + 1
13.2 Files
A le is simply an area on a particular storage device which contains data or text. Files
on the disks are guratively grouped into "directories". A directory is just a list of les.
Commands which deal with les are:
appendfile batch batchload
closefile file_output_append filename_merge
file_search file_search_maxima file_search_lisp
file_search_demo file_search_usage file_search_tests
file_type file_type_lisp file_type_maxima
load load_pathname loadfile
loadprint pathname_directory pathname_name
pathname_type printfile save
stringout with_stdout writefile
When a le name is passed to functions like plot2d, save, or writefile and the
le name does not include a path, Maxima stores the le in the current working directory.
The current working directory depends on the system like Windows or Linux and on the
installation.
212 Maxima 5.30.0 Manual
13.3 Functions and Variables for File Input and Output
Function appendle (lename)
Appends a console transcript to lename. appendfile is the same as writefile,
except that the transcript le, if it exists, is always appended.
closefile closes the transcript le opened by appendfile or writefile.
Function batch (lename)
Function batch (lename, option)
batch(lename) reads Maxima expressions from lename and evaluates them. batch
searches for lename in the list file_search_maxima. See also file_search.
batch(lename, demo) is like demo(lename). In this case batch searches for le-
name in the list file_search_demo. See demo.
batch(lename, test) is like run_testsuite with the option display_all=true.
For this case batch searches lename in the list file_search_maxima and not in the
list file_search_tests like run_testsuite. Furthermore, run_testsuite runs
tests which are in the list testsuite_files. With batch it is possible to run any
le in a test mode, which can be found in the list file_search_maxima. This is
useful, when writing a test le.
lename comprises a sequence of Maxima expressions, each terminated with ; or $.
The special variable % and the function %th refer to previous results within the
le. The le may include :lisp constructs. Spaces, tabs, and newlines in the le are
ignored. A suitable input le may be created by a text editor or by the stringout
function.
batch reads each input expression from lename, displays the input to the console,
computes the corresponding output expression, and displays the output expression.
Input labels are assigned to the input expressions and output labels are assigned to
the output expressions. batch evaluates every input expression in the le unless there
is an error. If user input is requested (by asksign or askinteger, for example)
batch pauses to collect the requisite input and then continue.
It may be possible to halt batch by typing control-C at the console. The eect of
control-C depends on the underlying Lisp implementation.
batch has several uses, such as to provide a reservoir for working command lines, to
give error-free demonstrations, or to help organize ones thinking in solving complex
problems.
batch evaluates its argument. batch returns the path of lename as a string, when
called with no second argument or with the option demo. When called with the option
test, the return value is a an empty list [] or a list with lename and the numbers
of the tests which have failed.
See also load, batchload, and demo.
Chapter 13: File Input and Output 213
Function batchload (lename)
Reads Maxima expressions from lename and evaluates them, without displaying
the input or output expressions and without assigning labels to output expressions.
Printed output (such as produced by print or describe) is displayed, however.
The special variable % and the function %th refer to previous results from the
interactive interpreter, not results within the le. The le cannot include :lisp
constructs.
batchload returns the path of lename, as a string. batchload evaluates its argu-
ment.
See also batch, and load.
Function closele ()
Closes the transcript le opened by writefile or appendfile.
Option variable le output append
Default value: false
file_output_append governs whether le output functions append or truncate their
output le. When file_output_append is true, such functions append to their
output le. Otherwise, the output le is truncated.
save, stringout, and with_stdout respect file_output_append. Other functions
which write output les do not respect file_output_append. In particular, plotting
and translation functions always truncate their output le, and tex and appendfile
always append.
Function lename merge (path, lename)
Constructs a modied path from path and lename. If the nal component of path
is of the form ###.something, the component is replaced with lename.something.
Otherwise, the nal component is simply replaced by lename.
The result is a Lisp pathname object.
Function le search (lename)
Function le search (lename, pathlist)
file_search searches for the le lename and returns the path to the le (as a string)
if it can be found; otherwise file_search returns false. file_search (lename)
searches in the default search directories, which are specied by the file_search_
maxima, file_search_lisp, and file_search_demo variables.
file_search rst checks if the actual name passed exists, before attempting to match
it to wildcard le search patterns. See file_search_maxima concerning le search
patterns.
The argument lename can be a path and le name, or just a le name, or, if a le
search directory includes a le search pattern, just the base of the le name (without
an extension). For example,
214 Maxima 5.30.0 Manual
file_search ("/home/wfs/special/zeta.mac");
file_search ("zeta.mac");
file_search ("zeta");
all nd the same le, assuming the le exists and /home/wfs/special/###.mac is in
file_search_maxima.
file_search (lename, pathlist) searches only in the directories specied by path-
list, which is a list of strings. The argument pathlist supersedes the default search
directories, so if the path list is given, file_search searches only the ones specied,
and not any of the default search directories. Even if there is only one directory in
pathlist, it must still be given as a one-element list.
The user may modify the default search directories. See file_search_maxima.
file_search is invoked by load with file_search_maxima and file_search_lisp
as the search directories.
Option variable le search maxima
Option variable le search lisp
Option variable le search demo
Option variable le search usage
Option variable le search tests
These variables specify lists of directories to be searched by load, demo, and some
other Maxima functions. The default values of these variables name various directories
in the Maxima installation.
The user can modify these variables, either to replace the default values or to append
additional directories. For example,
file_search_maxima: ["/usr/local/foo/###.mac",
"/usr/local/bar/###.mac"]$
replaces the default value of file_search_maxima, while
file_search_maxima: append (file_search_maxima,
["/usr/local/foo/###.mac", "/usr/local/bar/###.mac"])$
appends two additional directories. It may be convenient to put such an expression
in the le maxima-init.mac so that the le search path is assigned automatically
when Maxima starts. See also Section 32.1 [Introduction for Runtime Environment],
page 503.
Multiple lename extensions and multiple paths can be specied by special wildcard
constructions. The string ### expands into the sought-after name, while a comma-
separated list enclosed in curly braces {foo,bar,baz} expands into multiple strings.
For example, supposing the sought-after name is neumann,
"/home/{wfs,gcj}/###.{lisp,mac}"
expands into /home/wfs/neumann.lisp, /home/gcj/neumann.lisp,
/home/wfs/neumann.mac, and /home/gcj/neumann.mac.
Function le type (lename)
Returns a guess about the content of lename, based on the lename extension.
lename need not refer to an actual le; no attempt is made to open the le and
inspect the content.
Chapter 13: File Input and Output 215
The return value is a symbol, either object, lisp, or maxima. If the extension is
matches one of the values in file_type_maxima, file_type returns maxima. If the
extension matches one of the values in file_type_lisp, file_type returns lisp. If
none of the above, file_type returns object.
See also pathname_type.
See file_type_maxima and file_type_lisp for the default values.
Examples:
(%i2) map(file_type,
["test.lisp", "test.mac", "test.dem", "test.txt"]);
(%o2) [lisp, maxima, maxima, object]
Option variable le type lisp
Default value: [l, lsp, lisp]
file_type_lisp is a list of le extensions that maxima recognizes as denoting a Lisp
source le.
See also file_type.
Option variable le type maxima
Default value: [mac, mc, demo, dem, dm1, dm2, dm3, dmt]
file_type_maxima is a list of le extensions that maxima recognizes as denoting a
Maxima source le.
See also file_type.
Function load (lename)
Evaluates expressions in lename, thus bringing variables, functions, and other objects
into Maxima. The binding of any existing object is clobbered by the binding recovered
from lename. To nd the le, load calls file_search with file_search_maxima
and file_search_lisp as the search directories. If load succeeds, it returns the
name of the le. Otherwise load prints an error message.
load works equally well for Lisp code and Maxima code. Files created by save,
translate_file, and compile_file, which create Lisp code, and stringout,
which creates Maxima code, can all be processed by load. load calls loadfile
to load Lisp les and batchload to load Maxima les.
load does not recognize :lisp constructs in Maxima les, and while processing le-
name, the global variables _, __, %, and %th have whatever bindings they had when
load was called.
See also loadfile, batch, batchload, and demo. loadfile processes Lisp les;
batch, batchload, and demo process Maxima les.
See file_search for more detail about the le search mechanism.
load evaluates its argument.
216 Maxima 5.30.0 Manual
System variable load pathname
Default value: false
When a le is loaded with the functions load, loadfile or batchload the system
variable load_pathname is bound to the pathname of the le which is processed.
The variable load_pathname can be accessed from the le during the loading.
Example:
Suppose we have a batchle test.mac in the directory
"/home/dieter/workspace/mymaxima/temp/" with the following commands
print("The value of load_pathname is: ", load_pathname)$
print("End of batchfile")$
then we get the following output
(%i1) load("/home/dieter/workspace/mymaxima/temp/test.mac")$
The value of load_pathname is:
/home/dieter/workspace/mymaxima/temp/test.mac
End of batchfile
Function loadle (lename)
Evaluates Lisp expressions in lename. loadfile does not invoke file_search, so
filename must include the le extension and as much of the path as needed to nd
the le.
loadfile can process les created by save, translate_file, and compile_file.
The user may nd it more convenient to use load instead of loadfile.
Option variable loadprint
Default value: true
loadprint tells whether to print a message when a le is loaded.
When loadprint is true, always print a message.
When loadprint is loadfile, print a message only if a le is loaded by the
function loadfile.
When loadprint is autoload, print a message only if a le is automatically
loaded. See setup_autoload.
When loadprint is false, never print a message.
Function pathname directory (pathname)
Function pathname name (pathname)
Function pathname type (pathname)
These functions return the components of pathname.
Examples:
(%i1) pathname_directory("/home/dieter/maxima/changelog.txt");
(%o1) /home/dieter/maxima/
(%i2) pathname_name("/home/dieter/maxima/changelog.txt");
(%o2) changelog
(%i3) pathname_type("/home/dieter/maxima/changelog.txt");
(%o3) txt
Chapter 13: File Input and Output 217
Function printle (path)
Prints the le named by path to the console. path may be a string or a symbol; if it
is a symbol, it is converted to a string.
If path names a le which is accessible from the current working directory, that le is
printed to the console. Otherwise, printfile attempts to locate the le by appending
path to each of the elements of file_search_usage via filename_merge.
printfile returns path if it names an existing le, or otherwise the result of a
successful lename merge.
Function save (lename, name 1, name 2, name 3, . . . )
Function save (lename, values, functions, labels, . . . )
Function save (lename, [m, n])
Function save (lename, name 1=expr 1, . . . )
Function save (lename, all)
Function save (lename, name 1=expr 1, name 2=expr 2, . . . )
Stores the current values of name 1, name 2, name 3, . . . , in lename. The arguments
are the names of variables, functions, or other objects. If a name has no value or
function associated with it, it is ignored. save returns lename.
save stores data in the form of Lisp expressions. The data stored by save may be
recovered by load (lename). See load.
The global ag file_output_append governs whether save appends or truncates
the output le. When file_output_append is true, save appends to the output le.
Otherwise, save truncates the output le. In either case, save creates the le if it
does not yet exist.
The special form save (lename, values, functions, labels, ...) stores the
items named by values, functions, labels, etc. The names may be any specied
by the variable infolists. values comprises all user-dened variables.
The special form save (lename, [m, n]) stores the values of input and output la-
bels m through n. Note that m and n must be literal integers. Input and output labels
may also be stored one by one, e.g., save ("foo.1", %i42, %o42). save (lename,
labels) stores all input and output labels. When the stored labels are recovered,
they clobber existing labels.
The special form save (lename, name 1=expr 1, name 2=expr 2, ...) stores the
values of expr 1, expr 2, . . . , with names name 1, name 2, . . . It is useful to apply
this form to input and output labels, e.g., save ("foo.1", aa=%o88). The right-hand
side of the equality in this form may be any expression, which is evaluated. This form
does not introduce the new names into the current Maxima environment, but only
stores them in lename.
These special forms and the general form of save may be mixed at will. For example,
save (lename, aa, bb, cc=42, functions, [11, 17]).
The special form save (lename, all) stores the current state of Maxima. This
includes all user-dened variables, functions, arrays, etc., as well as some auto-
matically dened items. The saved items include system variables, such as file_
search_maxima or showtime, if they have been assigned new values by the user; see
myoptions.
218 Maxima 5.30.0 Manual
save evaluates lename and quotes all other arguments.
Function stringout (lename, expr 1, expr 2, expr 3, . . . )
Function stringout (lename, [m, n])
Function stringout (lename, input)
Function stringout (lename, functions)
Function stringout (lename, values)
stringout writes expressions to a le in the same form the expressions would be typed
for input. The le can then be used as input for the batch or demo commands, and
it may be edited for any purpose. stringout can be executed while writefile is in
progress.
The global ag file_output_append governs whether stringout appends or trun-
cates the output le. When file_output_append is true, stringout appends to
the output le. Otherwise, stringout truncates the output le. In either case,
stringout creates the le if it does not yet exist.
The general form of stringout writes the values of one or more expressions to the
output le. Note that if an expression is a variable, only the value of the variable is
written and not the name of the variable. As a useful special case, the expressions
may be input labels (%i1, %i2, %i3, . . . ) or output labels (%o1, %o2, %o3, . . . ).
If grind is true, stringout formats the output using the grind format. Otherwise
the string format is used. See grind and string.
The special form stringout (lename, [m, n]) writes the values of input labels m
through n, inclusive.
The special form stringout (lename, input) writes all input labels to the le.
The special form stringout (lename, functions) writes all user-dened functions
(named by the global list functions) to the le.
The special form stringout (lename, values) writes all user-assigned variables
(named by the global list values) to the le. Each variable is printed as an assignment
statement, with the name of the variable, a colon, and its value. Note that the general
form of stringout does not print variables as assignment statements.
Function with stdout (f, expr 1, expr 2, expr 3, . . . )
Function with stdout (s, expr 1, expr 2, expr 3, . . . )
Evaluates expr 1, expr 2, expr 3, . . . and writes any output thus generated to a le f
or output stream s. The evaluated expressions are not written to the output. Output
may be generated by print, display, grind, among other functions.
The global ag file_output_append governs whether with_stdout appends or trun-
cates the output le f. When file_output_append is true, with_stdout appends
to the output le. Otherwise, with_stdout truncates the output le. In either case,
with_stdout creates the le if it does not yet exist.
with_stdout returns the value of its nal argument.
See also writefile.
Chapter 13: File Input and Output 219
(%i1) with_stdout ("tmp.out", for i:5 thru 10 do
print (i, "! yields", i!))$
(%i2) printfile ("tmp.out")$
5 ! yields 120
6 ! yields 720
7 ! yields 5040
8 ! yields 40320
9 ! yields 362880
10 ! yields 3628800
Function writele (lename)
Begins writing a transcript of the Maxima session to lename. All interaction between
the user and Maxima is then recorded in this le, just as it appears on the console.
As the transcript is printed in the console output format, it cannot be reloaded into
Maxima. To make a le containing expressions which can be reloaded, see save and
stringout. save stores expressions in Lisp form, while stringout stores expressions
in Maxima form.
The eect of executing writefile when lename already exists depends on the un-
derlying Lisp implementation; the transcript le may be clobbered, or the le may be
appended. appendfile always appends to the transcript le.
It may be convenient to execute playback after writefile to save the display of
previous interactions. As playback displays only the input and output variables (%i1,
%o1, etc.), any output generated by a print statement in a function (as opposed to a
return value) is not displayed by playback.
closefile closes the transcript le opened by writefile or appendfile.
13.4 Functions and Variables for TeX Output
Function tex (expr)
Function tex (expr, destination)
Function tex (expr, false)
Function tex (label)
Function tex (label, destination)
Function tex (label, false)
Prints a representation of an expression suitable for the TeX document preparation
system. The result is a fragment of a document, which can be copied into a larger
document but not processed by itself.
tex (expr) prints a TeX representation of expr on the console.
tex (label) prints a TeX representation of the expression named by label and assigns
it an equation label (to be displayed to the left of the expression). The TeX equation
label is the same as the Maxima label.
destination may be an output stream or le name. When destination is a le name,
tex appends its output to the le. The functions openw and opena create output
streams.
220 Maxima 5.30.0 Manual
tex (expr, false) and tex (label, false) return their TeX output as a string.
tex evaluates its rst argument after testing it to see if it is a label. Quote-quote
forces evaluation of the argument, thereby defeating the test and preventing the
label.
See also texput.
Examples:
(%i1) integrate (1/(1+x^3), x);
2 x - 1
2 atan(-------)
log(x - x + 1) sqrt(3) log(x + 1)
(%o1) - --------------- + ------------- + ----------
6 sqrt(3) 3
(%i2) tex (%o1);
$$-{{\log \left(x^2-x+1\right)}\over{6}}+{{\arctan \left({{2\,x-1
}\over{\sqrt{3}}}\right)}\over{\sqrt{3}}}+{{\log \left(x+1\right)
}\over{3}}\leqno{\tt (\%o1)}$$
(%o2) (\%o1)
(%i3) tex (integrate (sin(x), x));
$$-\cos x$$
(%o3) false
(%i4) tex (%o1, "foo.tex");
(%o4) (\%o1)
tex (expr, false) returns its TeX output as a string.
(%i1) S : tex (x * y * z, false);
(%o1) $$x\,y\,z$$
(%i2) S;
(%o2) $$x\,y\,z$$
Function tex1 (e)
Returns a string which represents the TeX output for the expressions e. The TeX
output is not enclosed in delimiters for an equation or any other environment.
Examples:
(%i1) tex1 (sin(x) + cos(x));
(%o1) \sin x+\cos x
Function texput (a, s)
Function texput (a, f )
Function texput (a, s, operator type)
Function texput (a, [s 1, s 2], matchx)
Function texput (a, [s 1, s 2, s 3], matchx)
Assign the TeX output for the atom a, which can be a symbol or the name of an
operator.
texput (a, s) causes the tex function to interpolate the string s into the TeX output
in place of a.
Chapter 13: File Input and Output 221
texput (a, f ) causes the tex function to call the function f to generate TeX output.
f must accept one argument, which is an expression which has operator a, and must
return a string (the TeX output). f may call tex1 to generate TeX output for the
arguments of the input expression.
texput (a, s, operator type), where operator type is prefix, infix, postfix,
nary, or nofix, causes the tex function to interpolate s into the TeX output in place
of a, and to place the interpolated text in the appropriate position.
texput (a, [s 1, s 2], matchfix) causes the tex function to interpolate s 1 and s 2
into the TeX output on either side of the arguments of a. The arguments (if more
than one) are separated by commas.
texput (a, [s 1, s 2, s 3], matchfix) causes the tex function to interpolate s 1
and s 2 into the TeX output on either side of the arguments of a, with s 3 separating
the arguments.
Examples:
Assign TeX output for a variable.
(%i1) texput (me,"\\mu_e");
(%o1) \mu_e
(%i2) tex (me);
$$\mu_e$$
(%o2) false
Assign TeX output for an ordinary function (not an operator).
(%i1) texput (lcm, "\\mathrm{lcm}");
(%o1) \mathrm{lcm}
(%i2) tex (lcm (a, b));
$$\mathrm{lcm}\left(a , b\right)$$
(%o2) false
Call a function to generate TeX output.
(%i1) texfoo (e) := block ([a, b], [a, b] : args (e),
concat("\\left[\\stackrel{",tex1(b),"}{",tex1(a),"}\\right]"))$
(%i2) texput (foo, texfoo);
(%o2) texfoo
(%i3) tex (foo (2^x, %pi));
$$\left[\stackrel{\pi}{2^{x}}\right]$$
(%o3) false
Assign TeX output for a prex operator.
(%i1) prefix ("grad");
(%o1) grad
(%i2) texput ("grad", " \\nabla ", prefix);
(%o2) \nabla
(%i3) tex (grad f);
$$ \nabla f$$
(%o3) false
Assign TeX output for an inx operator.
(%i1) infix ("~");
(%o1) ~
222 Maxima 5.30.0 Manual
(%i2) texput ("~", " \\times ", infix);
(%o2) \times
(%i3) tex (a ~ b);
$$a \times b$$
(%o3) false
Assign TeX output for a postx operator.
(%i1) postfix ("##");
(%o1) ##
(%i2) texput ("##", "!!", postfix);
(%o2) !!
(%i3) tex (x ##);
$$x!!$$
(%o3) false
Assign TeX output for a nary operator.
(%i1) nary ("@@");
(%o1) @@
(%i2) texput ("@@", " \\circ ", nary);
(%o2) \circ
(%i3) tex (a @@ b @@ c @@ d);
$$a \circ b \circ c \circ d$$
(%o3) false
Assign TeX output for a nox operator.
(%i1) nofix ("foo");
(%o1) foo
(%i2) texput ("foo", "\\mathsc{foo}", nofix);
(%o2) \mathsc{foo}
(%i3) tex (foo);
$$\mathsc{foo}$$
(%o3) false
Assign TeX output for a matchx operator.
(%i1) matchfix ("<<", ">>");
(%o1) <<
(%i2) texput ("<<", [" \\langle ", " \\rangle "], matchfix);
(%o2) [ \langle , \rangle ]
(%i3) tex (<<a>>);
$$ \langle a \rangle $$
(%o3) false
(%i4) tex (<<a, b>>);
$$ \langle a , b \rangle $$
(%o4) false
(%i5) texput ("<<", [" \\langle ", " \\rangle ", " \\, | \\,"],
matchfix);
(%o5) [ \langle , \rangle , \, | \,]
(%i6) tex (<<a>>);
$$ \langle a \rangle $$
(%o6) false
(%i7) tex (<<a, b>>);
Chapter 13: File Input and Output 223
$$ \langle a \, | \,b \rangle $$
(%o7) false
Function get tex environment (op)
Function set tex environment (op, before, after)
Customize the TeX environment output by tex. As maintained by these functions,
the TeX environment comprises two strings: one is printed before any other TeX
output, and the other is printed after.
Only the TeX environment of the top-level operator in an expression is output; TeX
environments associated with other operators are ignored.
get_tex_environment returns the TeX enviroment which is applied to the operator
op; returns the default if no other environment has been assigned.
set_tex_environment assigns the TeX environment for the operator op.
Examples:
(%i1) get_tex_environment (":=");
(%o1) [
\begin{verbatim}
, ;
\end{verbatim}
]
(%i2) tex (f (x) := 1 - x);
\begin{verbatim}
f(x):=1-x;
\end{verbatim}
(%o2) false
(%i3) set_tex_environment (":=", "$$", "$$");
(%o3) [$$, $$]
(%i4) tex (f (x) := 1 - x);
$$f(x):=1-x$$
(%o4) false
Function get tex environment default ()
Function set tex environment default (before, after)
Customize the TeX environment output by tex. As maintained by these functions,
the TeX environment comprises two strings: one is printed before any other TeX
output, and the other is printed after.
get_tex_environment_default returns the TeX environment which is applied to
expressions for which the top-level operator has no specic TeX environment (as
assigned by set_tex_environment).
set_tex_environment_default assigns the default TeX environment.
Examples:
(%i1) get_tex_environment_default ();
(%o1) [$$, $$]
224 Maxima 5.30.0 Manual
(%i2) tex (f(x) + g(x));
$$g\left(x\right)+f\left(x\right)$$
(%o2) false
(%i3) set_tex_environment_default ("\\begin{equation}
", "
\\end{equation}");
(%o3) [\begin{equation}
,
\end{equation}]
(%i4) tex (f(x) + g(x));
\begin{equation}
g\left(x\right)+f\left(x\right)
\end{equation}
(%o4) false
13.5 Functions and Variables for Fortran Output
Option variable fortindent
Default value: 0
fortindent controls the left margin indentation of expressions printed out by the
fortran command. 0 gives normal printout (i.e., 6 spaces), and positive values will
causes the expressions to be printed farther to the right.
Function fortran (expr)
Prints expr as a Fortran statement. The output line is indented with spaces. If the
line is too long, fortran prints continuation lines. fortran prints the exponentiation
operator ^ as **, and prints a complex number a + b %i in the form (a,b).
expr may be an equation. If so, fortran prints an assignment statement, assigning the
right-hand side of the equation to the left-hand side. In particular, if the right-hand
side of expr is the name of a matrix, then fortran prints an assignment statement
for each element of the matrix.
If expr is not something recognized by fortran, the expression is printed in grind
format without complaint. fortran does not know about lists, arrays, or functions.
fortindent controls the left margin of the printed lines. 0 is the normal margin (i.e.,
indented 6 spaces). Increasing fortindent causes expressions to be printed further
to the right.
When fortspaces is true, fortran lls out each printed line with spaces to 80
columns.
fortran evaluates its arguments; quoting an argument defeats evaluation. fortran
always returns done.
See also the function f90 for printing one or more expressions as a Fortran 90
program.
Examples:
Chapter 13: File Input and Output 225
(%i1) expr: (a + b)^12$
(%i2) fortran (expr);
(b+a)**12
(%o2) done
(%i3) fortran (x=expr);
x = (b+a)**12
(%o3) done
(%i4) fortran (x=expand (expr));
x = b**12+12*a*b**11+66*a**2*b**10+220*a**3*b**9+495*a**4*b**8+792
1 *a**5*b**7+924*a**6*b**6+792*a**7*b**5+495*a**8*b**4+220*a**9*b
2 **3+66*a**10*b**2+12*a**11*b+a**12
(%o4) done
(%i5) fortran (x=7+5*%i);
x = (7,5)
(%o5) done
(%i6) fortran (x=[1,2,3,4]);
x = [1,2,3,4]
(%o6) done
(%i7) f(x) := x^2$
(%i8) fortran (f);
f
(%o8) done
Option variable fortspaces
Default value: false
When fortspaces is true, fortran lls out each printed line with spaces to 80
columns.
226 Maxima 5.30.0 Manual
Chapter 14: Polynomials 227
14 Polynomials
14.1 Introduction to Polynomials
Polynomials are stored in Maxima either in General Form or as Cannonical Rational
Expressions (CRE) form. The latter is a standard form, and is used internally by operations
such as factor, ratsimp, and so on.
Canonical Rational Expressions constitute a kind of representation which is especially
suitable for expanded polynomials and rational functions (as well as for partially factored
polynomials and rational functions when RATFAC is set to true). In this CRE form an
ordering of variables (from most to least main) is assumed for each expression. Polynomials
are represented recursively by a list consisting of the main variable followed by a series of
pairs of expressions, one for each term of the polynomial. The rst member of each pair is
the exponent of the main variable in that term and the second member is the coecient of
that term which could be a number or a polynomial in another variable again represented
in this form. Thus the principal part of the CRE form of 3*X^2-1 is (X 2 3 0 -1) and that of
2*X*Y+X-3 is (Y 1 (X 1 2) 0 (X 1 1 0 -3)) assuming Y is the main variable, and is (X 1 (Y 1
2 0 1) 0 -3) assuming X is the main variable. "Main"-ness is usually determined by reverse
alphabetical order. The "variables" of a CRE expression neednt be atomic. In fact any
subexpression whose main operator is not + - * / or ^ with integer power will be considered
a "variable" of the expression (in CRE form) in which it occurs. For example the CRE
variables of the expression X+SIN(X+1)+2*SQRT(X)+1 are X, SQRT(X), and SIN(X+1). If
the user does not specify an ordering of variables by using the RATVARS function Maxima
will choose an alphabetic one. In general, CREs represent rational expressions, that is,
ratios of polynomials, where the numerator and denominator have no common factors,
and the denominator is positive. The internal form is essentially a pair of polynomials
(the numerator and denominator) preceded by the variable ordering list. If an expression
to be displayed is in CRE form or if it contains any subexpressions in CRE form, the
symbol /R/ will follow the line label. See the RAT function for converting an expression
to CRE form. An extended CRE form is used for the representation of Taylor series. The
notion of a rational expression is extended so that the exponents of the variables can be
positive or negative rational numbers rather than just positive integers and the coecients
can themselves be rational expressions as described above rather than just polynomials.
These are represented internally by a recursive polynomial form which is similar to and
is a generalization of CRE form, but carries additional information such as the degree of
truncation. As with CRE form, the symbol /T/ follows the line label of such expressions.
14.2 Functions and Variables for Polynomials
Option variable algebraic
Default value: false
algebraic must be set to true in order for the simplication of algebraic integers to
take eect.
228 Maxima 5.30.0 Manual
Option variable berlefact
Default value: true
When berlefact is false then the Kronecker factoring algorithm will be used oth-
erwise the Berlekamp algorithm, which is the default, will be used.
Function bezout (p1, p2, x)
an alternative to the resultant command. It returns a matrix. determinant of this
matrix is the desired resultant.
Examples:
(%i1) bezout(a*x+b, c*x^2+d, x);
[ b c - a d ]
(%o1) [ ]
[ a b ]
(%i2) determinant(%);
2 2
(%o2) a d + b c
(%i3) resultant(a*x+b, c*x^2+d, x);
2 2
(%o3) a d + b c
Function bothcoef (expr, x)
Returns a list whose rst member is the coecient of x in expr (as found by ratcoef if
expr is in CRE form otherwise by coeff) and whose second member is the remaining
part of expr. That is, [A, B] where expr = A*x + B.
Example:
(%i1) islinear (expr, x) := block ([c],
c: bothcoef (rat (expr, x), x),
is (freeof (x, c) and c[1] # 0))$
(%i2) islinear ((r^2 - (x - r)^2)/x, x);
(%o2) true
Function coe (expr, x, n)
Function coe (expr, x)
Returns the coecient of x^n in expr, where expr is a polynomial or a monomial
term in x.
coeff(expr, x^n) is equivalent to coeff(expr, x, n). coeff(expr, x, 0) returns
the remainder of expr which is free of x. If omitted, n is assumed to be 1.
x may be a simple variable or a subscripted variable, or a subexpression of expr which
comprises an operator and all of its arguments.
It may be possible to compute coecients of expressions which are equivalent to expr
by applying expand or factor. coeff itself does not apply expand or factor or any
other function.
coeff distributes over lists, matrices, and equations.
Examples:
coeff returns the coecient x^n in expr.
Chapter 14: Polynomials 229
(%i1) coeff (b^3*a^3 + b^2*a^2 + b*a + 1, a^3);
3
(%o1) b
coeff(expr, x^n) is equivalent to coeff(expr, x, n).
(%i1) coeff (c[4]*z^4 - c[3]*z^3 - c[2]*z^2 + c[1]*z, z, 3);
(%o1) - c
3
(%i2) coeff (c[4]*z^4 - c[3]*z^3 - c[2]*z^2 + c[1]*z, z^3);
(%o2) - c
3
coeff(expr, x, 0) returns the remainder of expr which is free of x.
(%i1) coeff (a*u + b^2*u^2 + c^3*u^3, b, 0);
3 3
(%o1) c u + a u
x may be a simple variable or a subscripted variable, or a subexpression of expr which
comprises an operator and all of its arguments.
(%i1) coeff (h^4 - 2*%pi*h^2 + 1, h, 2);
(%o1) - 2 %pi
(%i2) coeff (v[1]^4 - 2*%pi*v[1]^2 + 1, v[1], 2);
(%o2) - 2 %pi
(%i3) coeff (sin(1+x)*sin(x) + sin(1+x)^3*sin(x)^3, sin(1+x)^3);
3
(%o3) sin (x)
(%i4) coeff ((d - a)^2*(b + c)^3 + (a + b)^4*(c - d), a + b, 4);
(%o4) c - d
coeff itself does not apply expand or factor or any other function.
(%i1) coeff (c*(a + b)^3, a);
(%o1) 0
(%i2) expand (c*(a + b)^3);
3 2 2 3
(%o2) b c + 3 a b c + 3 a b c + a c
(%i3) coeff (%, a);
2
(%o3) 3 b c
(%i4) coeff (b^3*c + 3*a*b^2*c + 3*a^2*b*c + a^3*c, (a + b)^3);
(%o4) 0
(%i5) factor (b^3*c + 3*a*b^2*c + 3*a^2*b*c + a^3*c);
3
(%o5) (b + a) c
(%i6) coeff (%, (a + b)^3);
(%o6) c
coeff distributes over lists, matrices, and equations.
(%i1) coeff ([4*a, -3*a, 2*a], a);
(%o1) [4, - 3, 2]
(%i2) coeff (matrix ([a*x, b*x], [-c*x, -d*x]), x);
230 Maxima 5.30.0 Manual
[ a b ]
(%o2) [ ]
[ - c - d ]
(%i3) coeff (a*u - b*v = 7*u + 3*v, u);
(%o3) a = 7
Function content (p 1, x 1, . . . , x n)
Returns a list whose rst element is the greatest common divisor of the coecients
of the terms of the polynomial p 1 in the variable x n (this is the content) and whose
second element is the polynomial p 1 divided by the content.
Examples:
(%i1) content (2*x*y + 4*x^2*y^2, y);
2
(%o1) [2 x, 2 x y + y]
Function denom (expr)
Returns the denominator of the rational expression expr.
Function divide (p 1, p 2, x 1, . . . , x n)
computes the quotient and remainder of the polynomial p 1 divided by the polynomial
p 2, in a main polynomial variable, x n. The other variables are as in the ratvars
function. The result is a list whose rst element is the quotient and whose second
element is the remainder.
Examples:
(%i1) divide (x + y, x - y, x);
(%o1) [1, 2 y]
(%i2) divide (x + y, x - y);
(%o2) [- 1, 2 x]
Note that y is the main variable in the second example.
Function eliminate ([eqn 1, . . . , eqn n], [x 1, . . . , x k])
Eliminates variables from equations (or expressions assumed equal to zero) by taking
successive resultants. This returns a list of n - k expressions with the k variables
x 1, . . . , x k eliminated. First x 1 is eliminated yielding n - 1 expressions, then x_2
is eliminated, etc. If k = n then a single expression in a list is returned free of the
variables x 1, . . . , x k. In this case solve is called to solve the last resultant for the
last variable.
Example:
(%i1) expr1: 2*x^2 + y*x + z;
2
(%o1) z + x y + 2 x
(%i2) expr2: 3*x + 5*y - z - 1;
(%o2) - z + 5 y + 3 x - 1
(%i3) expr3: z^2 + x - y^2 + 5;
2 2
(%o3) z - y + x + 5
Chapter 14: Polynomials 231
(%i4) eliminate ([expr3, expr2, expr1], [y, z]);
8 7 6 5 4
(%o4) [7425 x - 1170 x + 1299 x + 12076 x + 22887 x
3 2
- 5154 x - 1291 x + 7688 x + 15376]
Function ezgcd (p 1, p 2, p 3, . . . )
Returns a list whose rst element is the greatest common divisor of the polynomials
p 1, p 2, p 3, . . . and whose remaining elements are the polynomials divided by the
greatest common divisor. This always uses the ezgcd algorithm.
See also gcd, gcdex, gcdivide, and poly_gcd.
Examples:
The three polynomials have the greatest common divisor 2*x-3. The gcd is rst
calculated with the function gcd and then with the function ezgcd.
(%i1) p1 : 6*x^3-17*x^2+14*x-3;
3 2
(%o1) 6 x - 17 x + 14 x - 3
(%i2) p2 : 4*x^4-14*x^3+12*x^2+2*x-3;
4 3 2
(%o2) 4 x - 14 x + 12 x + 2 x - 3
(%i3) p3 : -8*x^3+14*x^2-x-3;
3 2
(%o3) - 8 x + 14 x - x - 3
(%i4) gcd(p1, gcd(p2, p3));
(%o4) 2 x - 3
(%i5) ezgcd(p1, p2, p3);
2 3 2 2
(%o5) [2 x - 3, 3 x - 4 x + 1, 2 x - 4 x + 1, - 4 x + x + 1]
Option variable facexpand
Default value: true
facexpand controls whether the irreducible factors returned by factor are in ex-
panded (the default) or recursive (normal CRE) form.
Function factor (expr)
Function factor (expr, p)
Factors the expression expr, containing any number of variables or functions, into
factors irreducible over the integers. factor (expr, p) factors expr over the eld of
rationals with an element adjoined whose minimum polynomial is p.
factor uses ifactors function for factoring integers.
factorflag if false suppresses the factoring of integer factors of rational expressions.
232 Maxima 5.30.0 Manual
dontfactor may be set to a list of variables with respect to which factoring is not
to occur. (It is initially empty). Factoring also will not take place with respect to
any variables which are less important (using the variable ordering assumed for CRE
form) than those on the dontfactor list.
savefactors if true causes the factors of an expression which is a product of factors
to be saved by certain functions in order to speed up later factorizations of expressions
containing some of the same factors.
berlefact if false then the Kronecker factoring algorithm will be used otherwise
the Berlekamp algorithm, which is the default, will be used.
intfaclim if true maxima will give up factorization of integers if no factor is found
after trial divisions and Pollards rho method. If set to false (this is the case when the
user calls factor explicitly), complete factorization of the integer will be attempted.
The users setting of intfaclim is used for internal calls to factor. Thus, intfaclim
may be reset to prevent Maxima from taking an inordinately long time factoring large
integers.
Examples:
(%i1) factor (2^63 - 1);
2
(%o1) 7 73 127 337 92737 649657
(%i2) factor (-8*y - 4*x + z^2*(2*y + x));
(%o2) (2 y + x) (z - 2) (z + 2)
(%i3) -1 - 2*x - x^2 + y^2 + 2*x*y^2 + x^2*y^2;
2 2 2 2 2
(%o3) x y + 2 x y + y - x - 2 x - 1
(%i4) block ([dontfactor: [x]], factor (%/36/(1 + 2*y + y^2)));
2
(x + 2 x + 1) (y - 1)
(%o4) ----------------------
36 (y + 1)
(%i5) factor (1 + %e^(3*x));
x 2 x x
(%o5) (%e + 1) (%e - %e + 1)
(%i6) factor (1 + x^4, a^2 - 2);
2 2
(%o6) (x - a x + 1) (x + a x + 1)
(%i7) factor (-y^2*z^2 - x*z^2 + x^2*y^2 + x^3);
2
(%o7) - (y + x) (z - x) (z + x)
(%i8) (2 + x)/(3 + x)/(b + x)/(c + x)^2;
x + 2
(%o8) ------------------------
2
(x + 3) (x + b) (x + c)
(%i9) ratsimp (%);
Chapter 14: Polynomials 233
4 3
(%o9) (x + 2)/(x + (2 c + b + 3) x
2 2 2 2
+ (c + (2 b + 6) c + 3 b) x + ((b + 3) c + 6 b c) x + 3 b c )
(%i10) partfrac (%, x);
2 4 3
(%o10) - (c - 4 c - b + 6)/((c + (- 2 b - 6) c
2 2 2 2
+ (b + 12 b + 9) c + (- 6 b - 18 b) c + 9 b ) (x + c))
c - 2
- ---------------------------------
2 2
(c + (- b - 3) c + 3 b) (x + c)
b - 2
+ -------------------------------------------------
2 2 3 2
((b - 3) c + (6 b - 2 b ) c + b - 3 b ) (x + b)
1
- ----------------------------------------------
2
((b - 3) c + (18 - 6 b) c + 9 b - 27) (x + 3)
(%i11) map (factor, %);
2
c - 4 c - b + 6 c - 2
(%o11) - ------------------------- - ------------------------
2 2 2
(c - 3) (c - b) (x + c) (c - 3) (c - b) (x + c)
b - 2 1
+ ------------------------ - ------------------------
2 2
(b - 3) (c - b) (x + b) (b - 3) (c - 3) (x + 3)
(%i12) ratsimp ((x^5 - 1)/(x - 1));
4 3 2
(%o12) x + x + x + x + 1
(%i13) subst (a, x, %);
4 3 2
(%o13) a + a + a + a + 1
(%i14) factor (%th(2), %);
2 3 3 2
(%o14) (x - a) (x - a ) (x - a ) (x + a + a + a + 1)
(%i15) factor (1 + x^12);
4 8 4
(%o15) (x + 1) (x - x + 1)
234 Maxima 5.30.0 Manual
(%i16) factor (1 + x^99);
2 6 3
(%o16) (x + 1) (x - x + 1) (x - x + 1)
10 9 8 7 6 5 4 3 2
(x - x + x - x + x - x + x - x + x - x + 1)
20 19 17 16 14 13 11 10 9 7 6
(x + x - x - x + x + x - x - x - x + x + x
4 3 60 57 51 48 42 39 33
- x - x + x + 1) (x + x - x - x + x + x - x
30 27 21 18 12 9 3
- x - x + x + x - x - x + x + 1)
Option variable factorag
Default value: false
When factorflag is false, suppresses the factoring of integer factors of rational
expressions.
Function factorout (expr, x 1, x 2, . . . )
Rearranges the sum expr into a sum of terms of the form f (x 1, x 2, ...)*g where
g is a product of expressions not containing any x i and f is factored.
Note that the option variable keepfloat is ignored by factorout.
Example:
(%i1) expand (a*(x+1)*(x-1)*(u+1)^2);
2 2 2 2 2
(%o1) a u x + 2 a u x + a x - a u - 2 a u - a
(%i2) factorout(%,x);
2
(%o2) a u (x - 1) (x + 1) + 2 a u (x - 1) (x + 1)
+ a (x - 1) (x + 1)
Function factorsum (expr)
Tries to group terms in factors of expr which are sums into groups of terms such that
their sum is factorable. factorsum can recover the result of expand ((x + y)^2 + (z
+ w)^2) but it cant recover expand ((x + 1)^2 + (x + y)^2) because the terms have
variables in common.
Example:
(%i1) expand ((x + 1)*((u + v)^2 + a*(w + z)^2));
2 2 2 2
(%o1) a x z + a z + 2 a w x z + 2 a w z + a w x + v x
2 2 2 2
+ 2 u v x + u x + a w + v + 2 u v + u
(%i2) factorsum (%);
Chapter 14: Polynomials 235
2 2
(%o2) (x + 1) (a (z + w) + (v + u) )
Function fasttimes (p 1, p 2)
Returns the product of the polynomials p 1 and p 2 by using a special algorithm for
multiplication of polynomials. p_1 and p_2 should be multivariate, dense, and nearly
the same size. Classical multiplication is of order n_1 n_2 where n_1 is the degree of
p_1 and n_2 is the degree of p_2. fasttimes is of order max (n_1, n_2)^1.585.
Function fullratsimp (expr)
fullratsimp repeatedly applies ratsimp followed by non-rational simplication to
an expression until no further change occurs, and returns the result.
When non-rational expressions are involved, one call to ratsimp followed as is usual
by non-rational ("general") simplication may not be sucient to return a simplied
result. Sometimes, more than one such call may be necessary. fullratsimp makes
this process convenient.
fullratsimp (expr, x 1, ..., x n) takes one or more arguments similar to ratsimp
and rat.
Example:
(%i1) expr: (x^(a/2) + 1)^2*(x^(a/2) - 1)^2/(x^a - 1);
a/2 2 a/2 2
(x - 1) (x + 1)
(%o1) -----------------------
a
x - 1
(%i2) ratsimp (expr);
2 a a
x - 2 x + 1
(%o2) ---------------
a
x - 1
(%i3) fullratsimp (expr);
a
(%o3) x - 1
(%i4) rat (expr);
a/2 4 a/2 2
(x ) - 2 (x ) + 1
(%o4)/R/ -----------------------
a
x - 1
Function fullratsubst (a, b, c)
is the same as ratsubst except that it calls itself recursively on its result until that
result stops changing. This function is useful when the replacement expression and
the replaced expression have one or more variables in common.
fullratsubst will also accept its arguments in the format of lratsubst. That is,
the rst argument may be a single substitution equation or a list of such equations,
while the second argument is the expression being processed.
236 Maxima 5.30.0 Manual
load ("lrats") loads fullratsubst and lratsubst.
Examples:
(%i1) load ("lrats")$
subst can carry out multiple substitutions. lratsubst is analogous to subst.
(%i2) subst ([a = b, c = d], a + c);
(%o2) d + b
(%i3) lratsubst ([a^2 = b, c^2 = d], (a + e)*c*(a + c));
(%o3) (d + a c) e + a d + b c
If only one substitution is desired, then a single equation may be given as rst
argument.
(%i4) lratsubst (a^2 = b, a^3);
(%o4) a b
fullratsubst is equivalent to ratsubst except that it recurses until its result
stops changing.
(%i5) ratsubst (b*a, a^2, a^3);
2
(%o5) a b
(%i6) fullratsubst (b*a, a^2, a^3);
2
(%o6) a b
fullratsubst also accepts a list of equations or a single equation as rst argu-
ment.
(%i7) fullratsubst ([a^2 = b, b^2 = c, c^2 = a], a^3*b*c);
(%o7) b
(%i8) fullratsubst (a^2 = b*a, a^3);
2
(%o8) a b
fullratsubst may cause an indenite recursion.
(%i9) errcatch (fullratsubst (b*a^2, a^2, a^3));
*** - Lisp stack overflow. RESET
Function gcd (p 1, p 2, x 1, . . . )
Returns the greatest common divisor of p 1 and p 2. The ag gcd determines which
algorithm is employed. Setting gcd to ez, subres, red, or spmod selects the ezgcd,
subresultant prs, reduced, or modular algorithm, respectively. If gcd false then gcd
(p 1, p 2, x) always returns 1 for all x. Many functions (e.g. ratsimp, factor, etc.)
cause gcds to be taken implicitly. For homogeneous polynomials it is recommended
that gcd equal to subres be used. To take the gcd when an algebraic is present, e.g.,
gcd (x^2 - 2*sqrt(2)* x + 2, x - sqrt(2)), the option variable algebraic must
be true and gcd must not be ez.
The gcd ag, default: spmod, if false will also prevent the greatest common divisor
from being taken when expressions are converted to canonical rational expression
(CRE) form. This will sometimes speed the calculation if gcds are not required.
Chapter 14: Polynomials 237
See also ezgcd, gcdex, gcdivide, and poly_gcd.
Example:
(%i1) p1:6*x^3+19*x^2+19*x+6;
3 2
(%o1) 6 x + 19 x + 19 x + 6
(%i2) p2:6*x^5+13*x^4+12*x^3+13*x^2+6*x;
5 4 3 2
(%o2) 6 x + 13 x + 12 x + 13 x + 6 x
(%i3) gcd(p1, p2);
2
(%o3) 6 x + 13 x + 6
(%i4) p1/gcd(p1, p2), ratsimp;
(%o4) x + 1
(%i5) p2/gcd(p1, p2), ratsimp;
3
(%o5) x + x
ezgcd returns a list whose rst element is the greatest common divisor of the poly-
nomials p 1 and p 2, and whose remaining elements are the polynomials divided by
the greatest common divisor.
(%i6) ezgcd(p1, p2);
2 3
(%o6) [6 x + 13 x + 6, x + 1, x + x]
Function gcdex (f, g)
Function gcdex (f, g, x)
Returns a list [a, b, u] where u is the greatest common divisor (gcd) of f and g, and
u is equal to a f + b g. The arguments f and g should be univariate polynomials,
or else polynomials in x a supplied main variable since we need to be in a principal
ideal domain for this to work. The gcd means the gcd regarding f and g as univariate
polynomials with coecients being rational functions in the other variables.
gcdex implements the Euclidean algorithm, where we have a sequence of L[i]:
[a[i], b[i], r[i]] which are all perpendicular to [f, g, -1] and the next one
is built as if q = quotient(r[i]/r[i+1]) then L[i+2]: L[i] - q L[i+1], and it ter-
minates at L[i+1] when the remainder r[i+2] is zero.
The arguments f and g can be integers. For this case the function igcdex is called
by gcdex.
See also ezgcd, gcd, gcdivide, and poly_gcd.
Examples:
(%i1) gcdex (x^2 + 1, x^3 + 4);
2
x + 4 x - 1 x + 4
(%o1)/R/ [- ------------, -----, 1]
17 17
(%i2) % . [x^2 + 1, x^3 + 4, -1];
(%o2)/R/ 0
238 Maxima 5.30.0 Manual
Note that the gcd in the following is 1 since we work in k(y)[x], not the y+1 we
would expect in k[y, x].
(%i1) gcdex (x*(y + 1), y^2 - 1, x);
1
(%o1)/R/ [0, ------, 1]
2
y - 1
Function gcfactor (n)
Factors the Gaussian integer n over the Gaussian integers, i.e., numbers of the form
a + b %i where a and b are rational integers (i.e., ordinary integers). Factors are
normalized by making a and b non-negative.
Function gfactor (expr)
Factors the polynomial expr over the Gaussian integers (that is, the integers with the
imaginary unit %i adjoined). This is like factor (expr, a^2+1) where a is %i.
Example:
(%i1) gfactor (x^4 - 1);
(%o1) (x - 1) (x + 1) (x - %i) (x + %i)
Function gfactorsum (expr)
is similar to factorsum but applies gfactor instead of factor.
Function hipow (expr, x)
Returns the highest explicit exponent of x in expr. x may be a variable or a general
expression. If x does not appear in expr, hipow returns 0.
hipow does not consider expressions equivalent to expr. In particular, hipow does not
expand expr, so hipow (expr, x) and hipow (expand (expr, x)) may yield dierent
results.
Examples:
(%i1) hipow (y^3 * x^2 + x * y^4, x);
(%o1) 2
(%i2) hipow ((x + y)^5, x);
(%o2) 1
(%i3) hipow (expand ((x + y)^5), x);
(%o3) 5
(%i4) hipow ((x + y)^5, x + y);
(%o4) 5
(%i5) hipow (expand ((x + y)^5), x + y);
(%o5) 0
Option variable intfaclim
Default value: true
If true, maxima will give up factorization of integers if no factor is found after trial
divisions and Pollards rho method and factorization will not be complete.
Chapter 14: Polynomials 239
When intfaclim is false (this is the case when the user calls factor explicitly),
complete factorization will be attempted. intfaclim is set to false when factors are
computed in divisors, divsum and totient.
Internal calls to factor respect the user-specied value of intfaclim. Setting
intfaclim to true may reduce the time spent factoring large integers.
Option variable keepoat
Default value: false
When keepfloat is true, prevents oating point numbers from being rationalized
when expressions which contain them are converted to canonical rational expression
(CRE) form.
Note that the function solve and those functions calling it (eigenvalues, for exam-
ple) currently ignore this ag, converting oating point numbers anyway.
Examples:
(%i1) rat(x/2.0);
rat replaced 0.5 by 1/2 = 0.5
x
(%o1)/R/ -
2
(%i2) rat(x/2.0), keepfloat;
(%o2)/R/ 0.5 x
solve ignores keepfloat:
(%i3) solve(1.0-x,x), keepfloat;
rat replaced 1.0 by 1/1 = 1.0
(%o3) [x = 1]
Function lopow (expr, x)
Returns the lowest exponent of x which explicitly appears in expr. Thus
(%i1) lopow ((x+y)^2 + (x+y)^a, x+y);
(%o1) min(a, 2)
Function lratsubst (L, expr)
is analogous to subst (L, expr) except that it uses ratsubst instead of subst.
The rst argument of lratsubst is an equation or a list of equations identical in
format to that accepted by subst. The substitutions are made in the order given by
the list of equations, that is, from left to right.
load ("lrats") loads fullratsubst and lratsubst.
Examples:
(%i1) load ("lrats")$
subst can carry out multiple substitutions. lratsubst is analogous to subst.
240 Maxima 5.30.0 Manual
(%i2) subst ([a = b, c = d], a + c);
(%o2) d + b
(%i3) lratsubst ([a^2 = b, c^2 = d], (a + e)*c*(a + c));
(%o3) (d + a c) e + a d + b c
If only one substitution is desired, then a single equation may be given as rst
argument.
(%i4) lratsubst (a^2 = b, a^3);
(%o4) a b
Option variable modulus
Default value: false
When modulus is a positive number p, operations on rational numbers (as returned by
rat and related functions) are carried out modulo p, using the so-called "balanced"
modulus system in which n modulo p is dened as an integer k in [-(p-1)/2, ...,
0, ..., (p-1)/2] when p is odd, or [-(p/2 - 1), ..., 0, ...., p/2] when p is
even, such that a p + k equals n for some integer a.
If expr is already in canonical rational expression (CRE) form when modulus is reset,
then you may need to re-rat expr, e.g., expr: rat (ratdisrep (expr)), in order to
get correct results.
Typically modulus is set to a prime number. If modulus is set to a positive non-prime
integer, this setting is accepted, but a warning message is displayed. Maxima signals
an error, when zero or a negative integer is assigned to modulus.
Examples:
(%i1) modulus:7;
(%o1) 7
(%i2) polymod([0,1,2,3,4,5,6,7]);
(%o2) [0, 1, 2, 3, - 3, - 2, - 1, 0]
(%i3) modulus:false;
(%o3) false
(%i4) poly:x^6+x^2+1;
6 2
(%o4) x + x + 1
(%i5) factor(poly);
6 2
(%o5) x + x + 1
(%i6) modulus:13;
(%o6) 13
(%i7) factor(poly);
2 4 2
(%o7) (x + 6) (x - 6 x - 2)
(%i8) polymod(%);
6 2
(%o8) x + x + 1
Function num (expr)
Returns the numerator of expr if it is a ratio. If expr is not a ratio, expr is returned.
num evaluates its argument.
Chapter 14: Polynomials 241
Function polydecomp (p, x)
Decomposes the polynomial p in the variable x into the functional composition of
polynomials in x. polydecomp returns a list [p 1, ..., p n] such that
lambda ([x], p_1) (lambda ([x], p_2) (... (lambda ([x], p_n) (x))
...))
is equal to p. The degree of p i is greater than 1 for i less than n.
Such a decomposition is not unique.
Examples:
(%i1) polydecomp (x^210, x);
7 5 3 2
(%o1) [x , x , x , x ]
(%i2) p : expand (subst (x^3 - x - 1, x, x^2 - a));
6 4 3 2
(%o2) x - 2 x - 2 x + x + 2 x - a + 1
(%i3) polydecomp (p, x);
2 3
(%o3) [x - a, x - x - 1]
The following function composes L = [e_1, ..., e_n] as functions in x; it is the
inverse of polydecomp:
compose (L, x) :=
block ([r : x], for e in L do r : subst (e, x, r), r) $
Re-express above example using compose:
(%i3) polydecomp (compose ([x^2 - a, x^3 - x - 1], x), x);
2 3
(%o3) [x - a, x - x - 1]
Note that though compose (polydecomp (p, x), x) always returns p (unexpanded),
polydecomp (compose ([p 1, ..., p n], x), x) does not necessarily return [p 1,
..., p n]:
(%i4) polydecomp (compose ([x^2 + 2*x + 3, x^2], x), x);
2 2
(%o4) [x + 2, x + 1]
(%i5) polydecomp (compose ([x^2 + x + 1, x^2 + x + 1], x), x);
2 2
x + 3 x + 5
(%o5) [------, ------, 2 x + 1]
4 2
Function polymod (p)
Function polymod (p, m)
Converts the polynomial p to a modular representation with respect to the current
modulus which is the value of the variable modulus.
polymod (p, m) species a modulus m to be used instead of the current value of
modulus.
See modulus.
242 Maxima 5.30.0 Manual
Function powers (expr, x)
Gives the powers of x occuring in expr.
load (powers) loads this function.
Function quotient (p 1, p 2)
Function quotient (p 1, p 2, x 1, . . . , x n)
Returns the polynomial p 1 divided by the polynomial p 2. The arguments x 1, . . . ,
x n are interpreted as in ratvars.
quotient returns the rst element of the two-element list returned by divide.
Function rat (expr)
Function rat (expr, x 1, . . . , x n)
Converts expr to canonical rational expression (CRE) form by expanding and com-
bining all terms over a common denominator and cancelling out the greatest common
divisor of the numerator and denominator, as well as converting oating point num-
bers to rational numbers within a tolerance of ratepsilon. The variables are ordered
according to the x 1, . . . , x n, if specied, as in ratvars.
rat does not generally simplify functions other than addition +, subtraction -, mul-
tiplication *, division /, and exponentiation to an integer power, whereas ratsimp
does handle those cases. Note that atoms (numbers and variables) in CRE form are
not the same as they are in the general form. For example, rat(x)- x yields rat(0)
which has a dierent internal representation than 0.
When ratfac is true, rat yields a partially factored form for CRE. During ratio-
nal operations the expression is maintained as fully factored as possible without an
actual call to the factor package. This should always save space and may save some
time in some computations. The numerator and denominator are still made rela-
tively prime (e.g. rat ((x^2 - 1)^4/(x + 1)^2) yields (x - 1)^4 (x + 1)^2), but
the factors within each part may not be relatively prime.
ratprint if false suppresses the printout of the message informing the user of the
conversion of oating point numbers to rational numbers.
keepfloat if true prevents oating point numbers from being converted to rational
numbers.
See also ratexpand and ratsimp.
Examples:
(%i1) ((x - 2*y)^4/(x^2 - 4*y^2)^2 + 1)*(y + a)*(2*y + x) /
(4*y^2 + x^2);
4
(x - 2 y)
(y + a) (2 y + x) (------------ + 1)
2 2 2
(x - 4 y )
(%o1) ------------------------------------
2 2
4 y + x
(%i2) rat (%, y, a, x);
Chapter 14: Polynomials 243
2 a + 2 y
(%o2)/R/ ---------
x + 2 y
Option variable ratalgdenom
Default value: true
When ratalgdenom is true, allows rationalization of denominators with respect to
radicals to take eect. ratalgdenom has an eect only when canonical rational ex-
pressions (CRE) are used in algebraic mode.
Function ratcoef (expr, x, n)
Function ratcoef (expr, x)
Returns the coecient of the expression x^n in the expression expr. If omitted, n is
assumed to be 1.
The return value is free (except possibly in a non-rational sense) of the variables in
x. If no coecient of this type exists, 0 is returned.
ratcoef expands and rationally simplies its rst argument and thus it may produce
answers dierent from those of coeff which is purely syntactic. Thus ratcoef ((x +
1)/y + x, x) returns (y + 1)/y whereas coeff returns 1.
ratcoef (expr, x, 0), viewing expr as a sum, returns a sum of those terms which
do not contain x. Therefore if x occurs to any negative powers, ratcoef should not
be used.
Since expr is rationally simplied before it is examined, coecients may not appear
quite the way they were envisioned.
Example:
(%i1) s: a*x + b*x + 5$
(%i2) ratcoef (s, a + b);
(%o2) x
Function ratdenom (expr)
Returns the denominator of expr, after coercing expr to a canonical rational expres-
sion (CRE). The return value is a CRE.
expr is coerced to a CRE by rat if it is not already a CRE. This conversion may
change the form of expr by putting all terms over a common denominator.
denom is similar, but returns an ordinary expression instead of a CRE. Also, denom
does not attempt to place all terms over a common denominator, and thus some
expressions which are considered ratios by ratdenom are not considered ratios by
denom.
Option variable ratdenomdivide
Default value: true
When ratdenomdivide is true, ratexpand expands a ratio in which the numerator is
a sum into a sum of ratios, all having a common denominator. Otherwise, ratexpand
collapses a sum of ratios into a single ratio, the numerator of which is the sum of the
numerators of each ratio.
Examples:
244 Maxima 5.30.0 Manual
(%i1) expr: (x^2 + x + 1)/(y^2 + 7);
2
x + x + 1
(%o1) ----------
2
y + 7
(%i2) ratdenomdivide: true$
(%i3) ratexpand (expr);
2
x x 1
(%o3) ------ + ------ + ------
2 2 2
y + 7 y + 7 y + 7
(%i4) ratdenomdivide: false$
(%i5) ratexpand (expr);
2
x + x + 1
(%o5) ----------
2
y + 7
(%i6) expr2: a^2/(b^2 + 3) + b/(b^2 + 3);
2
b a
(%o6) ------ + ------
2 2
b + 3 b + 3
(%i7) ratexpand (expr2);
2
b + a
(%o7) ------
2
b + 3
Function ratdi (expr, x)
Dierentiates the rational expression expr with respect to x. expr must be a ra-
tio of polynomials or a polynomial in x. The argument x may be a variable or a
subexpression of expr.
The result is equivalent to diff, although perhaps in a dierent form. ratdiff may
be faster than diff, for rational expressions.
ratdiff returns a canonical rational expression (CRE) if expr is a CRE. Otherwise,
ratdiff returns a general expression.
ratdiff considers only the dependence of expr on x, and ignores any dependencies
established by depends.
Example:
(%i1) expr: (4*x^3 + 10*x - 11)/(x^5 + 5);
Chapter 14: Polynomials 245
3
4 x + 10 x - 11
(%o1) ----------------
5
x + 5
(%i2) ratdiff (expr, x);
7 5 4 2
8 x + 40 x - 55 x - 60 x - 50
(%o2) - ---------------------------------
10 5
x + 10 x + 25
(%i3) expr: f(x)^3 - f(x)^2 + 7;
3 2
(%o3) f (x) - f (x) + 7
(%i4) ratdiff (expr, f(x));
2
(%o4) 3 f (x) - 2 f(x)
(%i5) expr: (a + b)^3 + (a + b)^2;
3 2
(%o5) (b + a) + (b + a)
(%i6) ratdiff (expr, a + b);
2 2
(%o6) 3 b + (6 a + 2) b + 3 a + 2 a
Function ratdisrep (expr)
Returns its argument as a general expression. If expr is a general expression, it is
returned unchanged.
Typically ratdisrep is called to convert a canonical rational expression (CRE) into
a general expression. This is sometimes convenient if one wishes to stop the "conta-
gion", or use rational functions in non-rational contexts.
See also totaldisrep.
Function ratexpand (expr)
Option variable ratexpand
Expands expr by multiplying out products of sums and exponentiated sums, com-
bining fractions over a common denominator, cancelling the greatest common divisor
of the numerator and denominator, then splitting the numerator (if a sum) into its
respective terms divided by the denominator.
The return value of ratexpand is a general expression, even if expr is a canonical
rational expression (CRE).
The switch ratexpand if true will cause CRE expressions to be fully expanded when
they are converted back to general form or displayed, while if it is false then they
will be put into a recursive form. See also ratsimp.
When ratdenomdivide is true, ratexpand expands a ratio in which the numerator is
a sum into a sum of ratios, all having a common denominator. Otherwise, ratexpand
collapses a sum of ratios into a single ratio, the numerator of which is the sum of the
numerators of each ratio.
246 Maxima 5.30.0 Manual
When keepfloat is true, prevents oating point numbers from being rationalized
when expressions which contain them are converted to canonical rational expression
(CRE) form.
Examples:
(%i1) ratexpand ((2*x - 3*y)^3);
3 2 2 3
(%o1) - 27 y + 54 x y - 36 x y + 8 x
(%i2) expr: (x - 1)/(x + 1)^2 + 1/(x - 1);
x - 1 1
(%o2) -------- + -----
2 x - 1
(x + 1)
(%i3) expand (expr);
x 1 1
(%o3) ------------ - ------------ + -----
2 2 x - 1
x + 2 x + 1 x + 2 x + 1
(%i4) ratexpand (expr);
2
2 x 2
(%o4) --------------- + ---------------
3 2 3 2
x + x - x - 1 x + x - x - 1
Option variable ratfac
Default value: false
When ratfac is true, canonical rational expressions (CRE) are manipulated in a
partially factored form.
During rational operations the expression is maintained as fully factored as possi-
ble without calling factor. This should always save space and may save time in
some computations. The numerator and denominator are made relatively prime, for
example rat ((x^2 - 1)^4/(x + 1)^2) yields (x - 1)^4 (x + 1)^2), but the factors
within each part may not be relatively prime.
In the ctensr (Component Tensor Manipulation) package, Ricci, Einstein, Riemann,
and Weyl tensors and the scalar curvature are factored automatically when ratfac is
true. ratfac should only be set for cases where the tensorial components are known
to consist of few terms.
The ratfac and ratweight schemes are incompatible and may not both be used at
the same time.
Function ratnumer (expr)
Returns the numerator of expr, after coercing expr to a canonical rational expression
(CRE). The return value is a CRE.
expr is coerced to a CRE by rat if it is not already a CRE. This conversion may
change the form of expr by putting all terms over a common denominator.
Chapter 14: Polynomials 247
num is similar, but returns an ordinary expression instead of a CRE. Also, num does not
attempt to place all terms over a common denominator, and thus some expressions
which are considered ratios by ratnumer are not considered ratios by num.
Function ratp (expr)
Returns true if expr is a canonical rational expression (CRE) or extended CRE,
otherwise false.
CRE are created by rat and related functions. Extended CRE are created by taylor
and related functions.
Option variable ratprint
Default value: true
When ratprint is true, a message informing the user of the conversion of oating
point numbers to rational numbers is displayed.
Function ratsimp (expr)
Function ratsimp (expr, x 1, . . . , x n)
Simplies the expression expr and all of its subexpressions, including the arguments
to non-rational functions. The result is returned as the quotient of two polynomials
in a recursive form, that is, the coecients of the main variable are polynomials in
the other variables. Variables may include non-rational functions (e.g., sin (x^2 +
1)) and the arguments to any such functions are also rationally simplied.
ratsimp (expr, x 1, ..., x n) enables rational simplication with the specication
of variable ordering as in ratvars.
When ratsimpexpons is true, ratsimp is applied to the exponents of expressions
during simplication.
See also ratexpand. Note that ratsimp is aected by some of the ags which aect
ratexpand.
Examples:
(%i1) sin (x/(x^2 + x)) = exp ((log(x) + 1)^2 - log(x)^2);
2 2
x (log(x) + 1) - log (x)
(%o1) sin(------) = %e
2
x + x
(%i2) ratsimp (%);
1 2
(%o2) sin(-----) = %e x
x + 1
(%i3) ((x - 1)^(3/2) - (x + 1)*sqrt(x - 1))/sqrt((x - 1)*(x + 1));
3/2
(x - 1) - sqrt(x - 1) (x + 1)
(%o3) --------------------------------
sqrt((x - 1) (x + 1))
(%i4) ratsimp (%);
248 Maxima 5.30.0 Manual
2 sqrt(x - 1)
(%o4) - -------------
2
sqrt(x - 1)
(%i5) x^(a + 1/a), ratsimpexpons: true;
2
a + 1
------
a
(%o5) x
Option variable ratsimpexpons
Default value: false
When ratsimpexpons is true, ratsimp is applied to the exponents of expressions
during simplication.
Option variable radsubstag
Default value: false
radsubstflag, if true, permits ratsubst to make substitutions such as u for sqrt
(x) in x.
Function ratsubst (a, b, c)
Substitutes a for b in c and returns the resulting expression. b may be a sum, product,
power, etc.
ratsubst knows something of the meaning of expressions whereas subst does a purely
syntactic substitution. Thus subst (a, x + y, x + y + z) returns x + y + z whereas
ratsubst returns z + a.
When radsubstflag is true, ratsubst makes substitutions for radicals in expressions
which dont explicitly contain them.
ratsubst ignores the value true of the option variable keepfloat.
Examples:
(%i1) ratsubst (a, x*y^2, x^4*y^3 + x^4*y^8);
3 4
(%o1) a x y + a
(%i2) cos(x)^4 + cos(x)^3 + cos(x)^2 + cos(x) + 1;
4 3 2
(%o2) cos (x) + cos (x) + cos (x) + cos(x) + 1
(%i3) ratsubst (1 - sin(x)^2, cos(x)^2, %);
4 2 2
(%o3) sin (x) - 3 sin (x) + cos(x) (2 - sin (x)) + 3
(%i4) ratsubst (1 - cos(x)^2, sin(x)^2, sin(x)^4);
4 2
(%o4) cos (x) - 2 cos (x) + 1
(%i5) radsubstflag: false$
(%i6) ratsubst (u, sqrt(x), x);
Chapter 14: Polynomials 249
(%o6) x
(%i7) radsubstflag: true$
(%i8) ratsubst (u, sqrt(x), x);
2
(%o8) u
Function ratvars (x 1, . . . , x n)
Function ratvars ()
System variable ratvars
Declares main variables x 1, . . . , x n for rational expressions. x n, if present in a
rational expression, is considered the main variable. Otherwise, x [n-1] is considered
the main variable if present, and so on through the preceding variables to x 1, which
is considered the main variable only if none of the succeeding variables are present.
If a variable in a rational expression is not present in the ratvars list, it is given a
lower priority than x 1.
The arguments to ratvars can be either variables or non-rational functions such as
sin(x).
The variable ratvars is a list of the arguments of the function ratvars when it was
called most recently. Each call to the function ratvars resets the list. ratvars ()
clears the list.
Option variable ratvarswitch
Default value: true
Maxima keeps an internal list in the Lisp variable VARLIST of the main variables for
rational expressions. If ratvarswitch is true, every evaluation starts with a fresh list
VARLIST. This is the default behavior. Otherwise, the main variables from previous
evaluations are not removed from the internal list VARLIST.
The main variables, which are declared with the function ratvars are not aected
by the option variable ratvarswitch.
Examples:
If ratvarswitch is true, every evaluation starts with a fresh list VARLIST.
(%i1) ratvarswitch:true$
(%i2) rat(2*x+y^2);
2
(%o2)/R/ y + 2 x
(%i3) :lisp varlist
($X $Y)
(%i3) rat(2*a+b^2);
2
(%o3)/R/ b + 2 a
(%i4) :lisp varlist
($A $B)
If ratvarswitch is false, the main variables from the last evaluation are still present.
250 Maxima 5.30.0 Manual
(%i4) ratvarswitch:false$
(%i5) rat(2*x+y^2);
2
(%o5)/R/ y + 2 x
(%i6) :lisp varlist
($X $Y)
(%i6) rat(2*a+b^2);
2
(%o6)/R/ b + 2 a
(%i7) :lisp varlist
($A $B $X $Y)
Function ratweight (x 1, w 1, . . . , x n, w n)
Function ratweight ()
Assigns a weight w i to the variable x i. This causes a term to be replaced by 0 if
its weight exceeds the value of the variable ratwtlvl (default yields no truncation).
The weight of a term is the sum of the products of the weight of a variable in the
term times its power. For example, the weight of 3 x_1^2 x_2 is 2 w_1 + w_2. Trun-
cation according to ratwtlvl is carried out only when multiplying or exponentiating
canonical rational expressions (CRE).
ratweight () returns the cumulative list of weight assignments.
Note: The ratfac and ratweight schemes are incompatible and may not both be
used at the same time.
Examples:
(%i1) ratweight (a, 1, b, 1);
(%o1) [a, 1, b, 1]
(%i2) expr1: rat(a + b + 1)$
(%i3) expr1^2;
2 2
(%o3)/R/ b + (2 a + 2) b + a + 2 a + 1
(%i4) ratwtlvl: 1$
(%i5) expr1^2;
(%o5)/R/ 2 b + 2 a + 1
System variable ratweights
Default value: []
ratweights is the list of weights assigned by ratweight. The list is cumulative: each
call to ratweight places additional items in the list.
kill (ratweights) and save (ratweights) both work as expected.
Chapter 14: Polynomials 251
Option variable ratwtlvl
Default value: false
ratwtlvl is used in combination with the ratweight function to control the trun-
cation of canonical rational expressions (CRE). For the default value of false, no
truncation occurs.
Function remainder (p 1, p 2)
Function remainder (p 1, p 2, x 1, . . . , x n)
Returns the remainder of the polynomial p 1 divided by the polynomial p 2. The
arguments x 1, . . . , x n are interpreted as in ratvars.
remainder returns the second element of the two-element list returned by divide.
Function resultant (p 1, p 2, x)
The function resultant computes the resultant of the two polynomials p 1 and p 2,
eliminating the variable x. The resultant is a determinant of the coecients of x in
p 1 and p 2, which equals zero if and only if p 1 and p 2 have a non-constant factor
in common.
If p 1 or p 2 can be factored, it may be desirable to call factor before calling
resultant.
The option variable resultant controls which algorithm will be used to compute the
resultant. See the option variable resultant.
The function bezout takes the same arguments as resultant and returns a matrix.
The determinant of the return value is the desired resultant.
Examples:
(%i1) resultant(2*x^2+3*x+1, 2*x^2+x+1, x);
(%o1) 8
(%i2) resultant(x+1, x+1, x);
(%o2) 0
(%i3) resultant((x+1)*x, (x+1), x);
(%o3) 0
(%i4) resultant(a*x^2+b*x+1, c*x + 2, x);
2
(%o4) c - 2 b c + 4 a
(%i5) bezout(a*x^2+b*x+1, c*x+2, x);
[ 2 a 2 b - c ]
(%o5) [ ]
[ c 2 ]
(%i6) determinant(%);
(%o6) 4 a - (2 b - c) c
Option variable resultant
Default value: subres
The option variable resultant controls which algorithm will be used to compute the
resultant with the function resultant. The possible values are:
252 Maxima 5.30.0 Manual
subres for the subresultant polynomial remainder sequence (PRS) algorithm,
mod for the modular resultant algorithm, and
red for the reduced polynomial remainder sequence (PRS) algorithm.
On most problems the default value subres should be best. On some large degree
univariate or bivariate problems mod may be better.
Option variable savefactors
Default value: false
When savefactors is true, causes the factors of an expression which is a product
of factors to be saved by certain functions in order to speed up later factorizations of
expressions containing some of the same factors.
Function showratvars (expr)
Returns a list of the canonical rational expression (CRE) variables in expression expr.
See also ratvars.
Function sqfr (expr)
is similar to factor except that the polynomial factors are "square-free." That is,
they have factors only of degree one. This algorithm, which is also used by the rst
stage of factor, utilizes the fact that a polynomial has in common with its nth
derivative all its factors of degree greater than n. Thus by taking greatest common
divisors with the polynomial of the derivatives with respect to each variable in the
polynomial, all factors of degree greater than 1 can be found.
Example:
(%i1) sqfr (4*x^4 + 4*x^3 - 3*x^2 - 4*x - 1);
2 2
(%o1) (2 x + 1) (x - 1)
Function tellrat (p 1, . . . , p n)
Function tellrat ()
Adds to the ring of algebraic integers known to Maxima the elements which are the
solutions of the polynomials p 1, . . . , p n. Each argument p i is a polynomial with
integer coecients.
tellrat (x) eectively means substitute 0 for x in rational functions.
tellrat () returns a list of the current substitutions.
algebraic must be set to true in order for the simplication of algebraic integers to
take eect.
Maxima initially knows about the imaginary unit %i and all roots of integers.
There is a command untellrat which takes kernels and removes tellrat properties.
When tellrating a multivariate polynomial, e.g., tellrat (x^2 - y^2), there would
be an ambiguity as to whether to substitute y^2 for x^2 or vice versa. Maxima picks
a particular ordering, but if the user wants to specify which, e.g. tellrat (y^2 =
x^2) provides a syntax which says replace y^2 by x^2.
Examples:
Chapter 14: Polynomials 253
(%i1) 10*(%i + 1)/(%i + 3^(1/3));
10 (%i + 1)
(%o1) -----------
1/3
%i + 3
(%i2) ev (ratdisrep (rat(%)), algebraic);
2/3 1/3 2/3 1/3
(%o2) (4 3 - 2 3 - 4) %i + 2 3 + 4 3 - 2
(%i3) tellrat (1 + a + a^2);
2
(%o3) [a + a + 1]
(%i4) 1/(a*sqrt(2) - 1) + a/(sqrt(3) + sqrt(2));
1 a
(%o4) ------------- + -----------------
sqrt(2) a - 1 sqrt(3) + sqrt(2)
(%i5) ev (ratdisrep (rat(%)), algebraic);
(7 sqrt(3) - 10 sqrt(2) + 2) a - 2 sqrt(2) - 1
(%o5) ----------------------------------------------
7
(%i6) tellrat (y^2 = x^2);
2 2 2
(%o6) [y - x , a + a + 1]
Function totaldisrep (expr)
Converts every subexpression of expr from canonical rational expressions (CRE) to
general form and returns the result. If expr is itself in CRE form then totaldisrep
is identical to ratdisrep.
totaldisrep may be useful for ratdisrepping expressions such as equations, lists,
matrices, etc., which have some subexpressions in CRE form.
Function untellrat (x 1, . . . , x n)
Removes tellrat properties from x 1, . . . , x n.
254 Maxima 5.30.0 Manual
Chapter 15: Special Functions 255
15 Special Functions
15.1 Introduction to Special Functions
Special function notation follows:
bessel_j (index, expr) Bessel function, 1st kind
bessel_y (index, expr) Bessel function, 2nd kind
bessel_i (index, expr) Modified Bessel function, 1st kind
bessel_k (index, expr) Modified Bessel function, 2nd kind
hankel_1 (v,z) Hankel function of the 1st kind
hankel_2 (v,z) Hankel function of the 2nd kind
struve_h (v,z) Struve H function
struve_l (v,z) Struve L function
assoc_legendre_p[v,u] (z) Legendre function of degree v and order u
assoc_legendre_q[v,u] (z) Legendre function, 2nd kind
%f[p,q] ([], [], expr) Generalized Hypergeometric function
gamma (z) Gamma function
gamma_greek (a,z) Incomplete gamma function
gamma_incomplete (a,z) Tail of incomplete gamma function
hypergeometric (l1, l2, z) Hypergeometric function
slommel
%m[u,k] (z) Whittaker function, 1st kind
%w[u,k] (z) Whittaker function, 2nd kind
erfc (z) Complement of the erf function
expintegral_e (v,z) Exponential integral E
expintegral_e1 (z) Exponential integral E1
expintegral_ei (z) Exponential integral Ei
expintegral_li (z) Logarithmic integral Li
expintegral_si (z) Exponential integral Si
expintegral_ci (z) Exponential integral Ci
expintegral_shi (z) Exponential integral Shi
expintegral_chi (z) Exponential integral Chi
kelliptic (z) Complete elliptic integral of the first
kind (K)
parabolic_cylinder_d (v,z) Parabolic cylinder D function
15.2 Bessel Functions
Function bessel j (v, z)
The Bessel function of the rst kind of order v and argument z.
bessel_j is dened as
256 Maxima 5.30.0 Manual

k=0
(1)
k
_
z
2
_
v+2 k
k! (v +k + 1)
although the innite series is not used for computations.
Function bessel y (v, z)
The Bessel function of the second kind of order v and argument z.
bessel_y is dened as
cos ( v) J
v
(z) J
v
(z)
sin ( v)
when v is not an integer. When v is an integer n, the limit as v approaches n is taken.
Function bessel i (v, z)
The modied Bessel function of the rst kind of order v and argument z.
bessel_i is dened as

k=0
1
k! (v +k + 1)
_
z
2
_
v+2 k
although the innite series is not used for computations.
Function bessel k (v, z)
The modied Bessel function of the second kind of order v and argument z.
bessel_k is dened as
csc ( v) (I
v
(z) I
v
(z))
2
when v is not an integer. If v is an integer n, then the limit as v approaches n is
taken.
Function hankel 1 (v, z)
The Hankel function of the rst kind of order v and argument z (A&S 9.1.3). hankel_
1 is dened as
bessel_j(v,z) + %i * bessel_y(v,z)
Maxima evaluates hankel_1 numerically for a real order v and complex argument z
in oat precision. The numerical evaluation in bigoat precision and for a complex
order v is not supported.
When besselexpand is true, hankel_1 is expanded in terms of elementary functions
when the order v is half of an odd integer. See besselexpand.
Maxima knows the derivative of hankel_1 wrt the argument z.
Examples:
Numerical evaluation:
Chapter 15: Special Functions 257
(%i1) hankel_1(1,0.5);
(%o1) .2422684576748738 - 1.471472392670243 %i
(%i2) hankel_1(1,0.5+%i);
(%o2) - .2558287994862166 %i - 0.239575601883016
A complex order v is not supported. Maxima returns a noun form:
(%i3) hankel_1(%i,0.5+%i);
(%o3) hankel_1(%i, %i + 0.5)
Expansion of hankel_1 when besselexpand is true:
(%i4) hankel_1(1/2,z),besselexpand:true;
sqrt(2) sin(z) - sqrt(2) %i cos(z)
(%o4) ----------------------------------
sqrt(%pi) sqrt(z)
Derivative of hankel_1 wrt the argument z. The derivative wrt the order v is not
supported. Maxima returns a noun form:
(%i5) diff(hankel_1(v,z),z);
hankel_1(v - 1, z) - hankel_1(v + 1, z)
(%o5) ---------------------------------------
2
(%i6) diff(hankel_1(v,z),v);
d
(%o6) -- (hankel_1(v, z))
dv
Function hankel 2 (v, z)
The Hankel function of the second kind of order v and argument z (A&S 9.1.4).
hankel_2 is dened as
bessel_j(v,z) - %i * bessel_y(v,z)
Maxima evaluates hankel_2 numerically for a real order v and complex argument z
in oat precision. The numerical evaluation in bigoat precision and for a complex
order v is not supported.
When besselexpand is true, hankel_2 is expanded in terms of elementary functions
when the order v is half of an odd integer. See besselexpand.
Maxima knows the derivative of hankel_2 wrt the argument z.
For examples see hankel_1.
Option variable besselexpand
Default value: false
Controls expansion of the Bessel functions when the order is half of an odd integer. In
this case, the Bessel functions can be expanded in terms of other elementary functions.
When besselexpand is true, the Bessel function is expanded.
(%i1) besselexpand: false$
(%i2) bessel_j (3/2, z);
3
(%o2) bessel_j(-, z)
258 Maxima 5.30.0 Manual
2
(%i3) besselexpand: true$
(%i4) bessel_j (3/2, z);
sin(z) cos(z)
sqrt(2) sqrt(z) (------ - ------)
2 z
z
(%o4) ---------------------------------
sqrt(%pi)
Function scaled bessel i (v, z)
The scaled modied Bessel function of the rst kind of order v and argument z. That
is, scaled
b
essel
i
(v, z) = exp(abs(z)) bessel
i
(v, z). This function is particularly
useful for calculating bessel
i
for large z, which is large. However, maxima does not
otherwise know much about this function. For symbolic work, it is probably preferable
to work with the expression exp(-abs(z))*bessel_i(v, z).
Function scaled bessel i0 (z)
Identical to scaled_bessel_i(0,z).
Function scaled bessel i1 (z)
Identical to scaled_bessel_i(1,z).
Function %s [u,v] (z)
Lommels little s[u,v](z) function. Probably Gradshteyn & Ryzhik 8.570.1.
15.3 Airy Functions
The Airy functions Ai(x) and Bi(x) are dened in Abramowitz and Stegun, Handbook
of Mathematical Functions, Section 10.4.
y = Ai(x) and y = Bi(x) are two linearly independent solutions of the Airy dierential
equation diff (y(x), x, 2) - x y(x) = 0.
If the argument x is a real or complex oating point number, the numerical value of the
function is returned.
Function airy ai (x)
The Airy function Ai(x). (A&S 10.4.2)
The derivative diff (airy_ai(x), x) is airy_dai(x).
See also airy_bi, airy_dai, airy_dbi.
Function airy dai (x)
The derivative of the Airy function Ai airy_ai(x).
See airy_ai.
Chapter 15: Special Functions 259
Function airy bi (x)
The Airy function Bi(x). (A&S 10.4.3)
The derivative diff (airy_bi(x), x) is airy_dbi(x).
See airy_ai, airy_dbi.
Function airy dbi (x)
The derivative of the Airy Bi function airy_bi(x).
See airy_ai and airy_bi.
15.4 Gamma and factorial Functions
The gamma function and the related beta, psi and incomplete gamma functions are
dened in Abramowitz and Stegun, Handbook of Mathematical Functions, Chapter 6.
Function bac (expr, n)
Bigoat version of the factorial (shifted gamma) function. The second argument is
how many digits to retain and return, its a good idea to request a couple of extra.
Function bfpsi (n, z, fpprec)
Function bfpsi0 (z, fpprec)
bfpsi is the polygamma function of real argument z and integer order n. bfpsi0 is
the digamma function. bfpsi0 (z, fpprec) is equivalent to bfpsi (0, z, fpprec).
These functions return bigoat values. fpprec is the bigoat precision of the return
value.
Function cbac (z, fpprec)
Complex bigoat factorial.
load ("bffac") loads this function.
Function gamma (z)
The basic denition of the gamma function (A&S 6.1.1) is
(z) =
_

0
t
z1
e
t
dt
Maxima simplies gamma for positive integer and positive and negative rational num-
bers. For half integral values the result is a rational number times sqrt(%pi).
The simplication for integer values is controlled by factlim. For integers greater
than factlim the numerical result of the factorial function, which is used to calcu-
late gamma, will overow. The simplication for rational numbers is controlled by
gammalim to avoid internal overow. See factlim and gammalim.
For negative integers gamma is not dened.
Maxima can evalute gamma numerically for real and complex values in oat and
bigoat precision.
260 Maxima 5.30.0 Manual
gamma has mirror symmetry.
When gamma_expand is true, Maxima expands gamma for arguments z+n and z-n
where n is an integer.
Maxima knows the derivate of gamma.
Examples:
Simplication for integer, half integral, and rational numbers:
(%i1) map(gamma,[1,2,3,4,5,6,7,8,9]);
(%o1) [1, 1, 2, 6, 24, 120, 720, 5040, 40320]
(%i2) map(gamma,[1/2,3/2,5/2,7/2]);
sqrt(%pi) 3 sqrt(%pi) 15 sqrt(%pi)
(%o2) [sqrt(%pi), ---------, -----------, ------------]
2 4 8
(%i3) map(gamma,[2/3,5/3,7/3]);
2 1
2 gamma(-) 4 gamma(-)
2 3 3
(%o3) [gamma(-), ----------, ----------]
3 3 9
Numerical evaluation for real and complex values:
(%i4) map(gamma,[2.5,2.5b0]);
(%o4) [1.329340388179137, 1.3293403881791370205b0]
(%i5) map(gamma,[1.0+%i,1.0b0+%i]);
(%o5) [0.498015668118356 - .1549498283018107 %i,
4.9801566811835604272b-1 - 1.5494982830181068513b-1 %i]
gamma has mirror symmetry:
(%i6) declare(z,complex)$
(%i7) conjugate(gamma(z));
(%o7) gamma(conjugate(z))
Maxima expands gamma(z+n) and gamma(z-n), when gamma_expand is true:
(%i8) gamma_expand:true$
(%i9) [gamma(z+1),gamma(z-1),gamma(z+2)/gamma(z+1)];
gamma(z)
(%o9) [z gamma(z), --------, z + 1]
z - 1
The deriviative of gamma:
(%i10) diff(gamma(z),z);
(%o10) psi (z) gamma(z)
0
See also makegamma.
The Euler-Mascheroni constant is %gamma.
Function log gamma (z)
The natural logarithm of the gamma function.
Chapter 15: Special Functions 261
Function gamma greek (a, z)
The lower incomplete gamma function (A&S 6.5.2):
(a, z) =
_
z
0
t
a1
e
t
dt
See also gamma_incomplete (upper incomplete gamma function).
Function gamma incomplete (a, z)
The incomplete upper gamma function A&S 6.5.3:
(a, z) =
_

z
t
a1
e
t
dt
See also gamma_expand for controlling how gamma_incomplete is expressed in terms
of elementary functions and erfc.
Also see the related functions gamma_incomplete_regularized and gamma_
incomplete_generalized.
Function gamma incomplete regularized (a, z)
The regularized incomplete upper gamma function A&S 6.5.1:
Q (a, z) =
(a, z)
(a)
See also gamma_expand for controlling how gamma_incomplete is expressed in terms
of elementary functions and erfc.
Also see gamma_incomplete.
Function gamma incomplete generalized (a, z1, z1)
The generalized incomplete gamma function.
(a, z
1
, z
2
) =
_
z2
z1
t
a1
e
t
dt
Also see gamma_incomplete and gamma_incomplete_regularized.
Option variable gamma expand
Default value: false
gamma_expand controls expansion of gamma_incomplete. When gamma_expand is
true, gamma_incomplete(v,z) is expanded in terms of z, exp(z), and erfc(z) when
possible.
(%i1) gamma_incomplete(2,z);
(%o1) gamma_incomplete(2, z)
(%i2) gamma_expand:true;
(%o2) true
(%i3) gamma_incomplete(2,z);
- z
262 Maxima 5.30.0 Manual
(%o3) (z + 1) %e
(%i4) gamma_incomplete(3/2,z);
- z sqrt(%pi) erfc(sqrt(z))
(%o4) sqrt(z) %e + -----------------------
2
Option variable gammalim
Default value: 1000000
gammalim controls simplication of the gamma function for integral and rational num-
ber arguments. If the absolute value of the argument is not greater than gammalim,
then simplication will occur. Note that the factlim switch controls simplication
of the result of gamma of an integer argument as well.
Function makegamma (expr)
Transforms instances of binomial, factorial, and beta functions in expr into gamma
functions.
See also makefact.
Function beta (a, b)
The beta function is dened as gamma(a) gamma(b)/gamma(a+b) (A&S 6.2.1).
Maxima simplies the beta function for positive integers and rational numbers, which
sum to an integer. When beta_args_sum_to_integer is true, Maxima simplies also
general expressions which sum to an integer.
For a or b equal to zero the beta function is not dened.
In general the beta function is not dened for negative integers as an argument. The
exception is for a=-n, n a positive integer and b a positive integer with b<=n, it is
possible to dene an analytic continuation. Maxima gives for this case a result.
When beta_expand is true, expressions like beta(a+n,b) and beta(a-n,b) or
beta(a,b+n) and beta(a,b-n) with n an integer are simplied.
Maxima can evaluate the beta function for real and complex values in oat and
bigoat precision. For numerical evaluation Maxima uses log_gamma:
- log_gamma(b + a) + log_gamma(b) + log_gamma(a)
%e
Maxima knows that the beta function is symmetric and has mirror symmetry.
Maxima knows the derivatives of the beta function with respect to a or b.
To express the beta function as a ratio of gamma functions see makegamma.
Examples:
Simplication, when one of the arguments is an integer:
(%i1) [beta(2,3),beta(2,1/3),beta(2,a)];
1 9 1
(%o1) [--, -, ---------]
12 4 a (a + 1)
Simplication for two rational numbers as arguments which sum to an integer:
Chapter 15: Special Functions 263
(%i2) [beta(1/2,5/2),beta(1/3,2/3),beta(1/4,3/4)];
3 %pi 2 %pi
(%o2) [-----, -------, sqrt(2) %pi]
8 sqrt(3)
When setting beta_args_sum_to_integer to true more general expression are sim-
plied, when the sum of the arguments is an integer:
(%i3) beta_args_sum_to_integer:true$
(%i4) beta(a+1,-a+2);
%pi (a - 1) a
(%o4) ------------------
2 sin(%pi (2 - a))
The possible results, when one of the arguments is a negative integer:
(%i5) [beta(-3,1),beta(-3,2),beta(-3,3)];
1 1 1
(%o5) [- -, -, - -]
3 6 3
beta(a+n,b) or beta(a-n) with n an integer simplies when beta_expand is true:
(%i6) beta_expand:true$
(%i7) [beta(a+1,b),beta(a-1,b),beta(a+1,b)/beta(a,b+1)];
a beta(a, b) beta(a, b) (b + a - 1) a
(%o7) [------------, ----------------------, -]
b + a a - 1 b
Beta is not dened, when one of the arguments is zero:
(%i7) beta(0,b);
beta: expected nonzero arguments; found 0, b
-- an error. To debug this try debugmode(true);
Numercial evaluation for real and complex arguments in oat or bigoat precision:
(%i8) beta(2.5,2.3);
(%o8) .08694748611299981
(%i9) beta(2.5,1.4+%i);
(%o9) 0.0640144950796695 - .1502078053286415 %i
(%i10) beta(2.5b0,2.3b0);
(%o10) 8.694748611299969b-2
(%i11) beta(2.5b0,1.4b0+%i);
(%o11) 6.401449507966944b-2 - 1.502078053286415b-1 %i
Beta is symmetric and has mirror symmetry:
(%i14) beta(a,b)-beta(b,a);
(%o14) 0
(%i15) declare(a,complex,b,complex)$
(%i16) conjugate(beta(a,b));
(%o16) beta(conjugate(a), conjugate(b))
The derivative of the beta function wrt a:
264 Maxima 5.30.0 Manual
(%i17) diff(beta(a,b),a);
(%o17) - beta(a, b) (psi (b + a) - psi (a))
0 0
Function beta incomplete (a, b, z)
The basic denition of the incomplete beta function (A&S 6.6.1) is
z
/
[ b - 1 a - 1
I (1 - t) t dt
]
/
0
This denition is possible for realpart(a) > 0 and realpart(b) > 0 and abs(z) < 1.
For other values the incomplete beta function can be dened through a generalized
hypergeometric function:
gamma(a) hypergeometric_generalized([a, 1 - b], [a + 1], z) z
(See functions.wolfram.com for a complete denition of the incomplete beta function.)
For negative integers a = n and positive integers b = m with m <= n the incomplete
beta function is dened through
m - 1 k
==== (1 - m) z
n - 1 \ k
z > -----------
/ k! (n - k)
====
k = 0
Maxima uses this denition to simplify beta_incomplete for a a negative integer.
For a a positive integer, beta_incomplete simplies for any argument b and z and
for b a positive integer for any argument a and z, with the exception of a a negative
integer.
For z = 0 and realpart(a) > 0, beta_incomplete has the specic value zero. For z=1
and realpart(b) > 0, beta_incomplete simplies to the beta function beta(a,b).
Maxima evaluates beta_incomplete numerically for real and complex values in oat
or bigoat precision. For the numerical evaluation an expansion of the incomplete
beta function in continued fractions is used.
When the option variable beta_expand is true, Maxima expands expressions like
beta_incomplete(a+n,b,z) and beta_incomplete(a-n,b,z) where n is a positive
integer.
Maxima knows the derivatives of beta_incomplete with respect to the variables a,
b and z and the integral with respect to the variable z.
Examples:
Simplication for a a positive integer:
Chapter 15: Special Functions 265
(%i1) beta_incomplete(2,b,z);
b
1 - (1 - z) (b z + 1)
(%o1) ----------------------
b (b + 1)
Simplication for b a positive integer:
(%i2) beta_incomplete(a,2,z);
a
(a (1 - z) + 1) z
(%o2) ------------------
a (a + 1)
Simplication for a and b a positive integer:
(%i3) beta_incomplete(3,2,z);
3
(3 (1 - z) + 1) z
(%o3) ------------------
12
a is a negative integer and b <= (a), Maxima simplies:
(%i4) beta_incomplete(-3,1,z);
1
(%o4) - ----
3
3 z
For the specic values z = 0 and z = 1, Maxima simplies:
(%i5) assume(a>0,b>0)$
(%i6) beta_incomplete(a,b,0);
(%o6) 0
(%i7) beta_incomplete(a,b,1);
(%o7) beta(a, b)
Numerical evaluation in oat or bigoat precision:
(%i8) beta_incomplete(0.25,0.50,0.9);
(%o8) 4.594959440269333
(%i9) fpprec:25$
(%i10) beta_incomplete(0.25,0.50,0.9b0);
(%o10) 4.594959440269324086971203b0
For abs(z) > 1 beta_incomplete returns a complex result:
(%i11) beta_incomplete(0.25,0.50,1.7);
(%o11) 5.244115108584249 - 1.45518047787844 %i
Results for more general complex arguments:
(%i14) beta_incomplete(0.25+%i,1.0+%i,1.7+%i);
(%o14) 2.726960675662536 - .3831175704269199 %i
(%i15) beta_incomplete(1/2,5/4*%i,2.8+%i);
(%o15) 13.04649635168716 %i - 5.802067956270001
(%i16)
Expansion, when beta_expand is true:
266 Maxima 5.30.0 Manual
(%i23) beta_incomplete(a+1,b,z),beta_expand:true;
b a
a beta_incomplete(a, b, z) (1 - z) z
(%o23) -------------------------- - -----------
b + a b + a
(%i24) beta_incomplete(a-1,b,z),beta_expand:true;
b a - 1
beta_incomplete(a, b, z) (- b - a + 1) (1 - z) z
(%o24) -------------------------------------- - ---------------
1 - a 1 - a
Derivative and integral for beta_incomplete:
(%i34) diff(beta_incomplete(a, b, z), z);
b - 1 a - 1
(%o34) (1 - z) z
(%i35) integrate(beta_incomplete(a, b, z), z);
b a
(1 - z) z
(%o35) ----------- + beta_incomplete(a, b, z) z
b + a
a beta_incomplete(a, b, z)
- --------------------------
b + a
(%i36) factor(diff(%, z));
(%o36) beta_incomplete(a, b, z)
Function beta incomplete regularized (a, b, z)
The regularized incomplete beta function A&S 6.6.2, dened as
beta_incomplete_regularized(a, b, z) =
beta_incomplete(a, b, z)
------------------------
beta(a, b)
As for beta_incomplete this denition is not complete. See functions.wolfram.com
for a complete denition of beta_incomplete_regularized.
beta_incomplete_regularized simplies a or b a positive integer.
For z = 0 and realpart(a) > 0, beta_incomplete_regularized has the specic value
0. For z=1 and realpart(b) > 0, beta_incomplete_regularized simplies to 1.
Maxima can evaluate beta_incomplete_regularized for real and complex argu-
ments in oat and bigoat precision.
When beta_expand is true, Maxima expands beta_incomplete_regularized for
arguments a +n or a n, where n is an integer.
Maxima knows the derivatives of beta_incomplete_regularized with respect to the
variables a, b, and z and the integral with respect to the variable z.
Examples:
Simplication for a or b a positive integer:
Chapter 15: Special Functions 267
(%i1) beta_incomplete_regularized(2,b,z);
b
(%o1) 1 - (1 - z) (b z + 1)
(%i2) beta_incomplete_regularized(a,2,z);
a
(%o2) (a (1 - z) + 1) z
(%i3) beta_incomplete_regularized(3,2,z);
3
(%o3) (3 (1 - z) + 1) z
For the specic values z = 0 and z = 1, Maxima simplies:
(%i4) assume(a>0,b>0)$
(%i5) beta_incomplete_regularized(a,b,0);
(%o5) 0
(%i6) beta_incomplete_regularized(a,b,1);
(%o6) 1
Numerical evaluation for real and complex arguments in oat and bigoat precision:
(%i7) beta_incomplete_regularized(0.12,0.43,0.9);
(%o7) .9114011367359802
(%i8) fpprec:32$
(%i9) beta_incomplete_regularized(0.12,0.43,0.9b0);
(%o9) 9.1140113673598075519946998779975b-1
(%i10) beta_incomplete_regularized(1+%i,3/3,1.5*%i);
(%o10) .2865367499935403 %i - 0.122995963334684
(%i11) fpprec:20$
(%i12) beta_incomplete_regularized(1+%i,3/3,1.5b0*%i);
(%o12) 2.8653674999354036142b-1 %i - 1.2299596333468400163b-1
Expansion, when beta_expand is true:
(%i13) beta_incomplete_regularized(a+1,b,z);
b a
(1 - z) z
(%o13) beta_incomplete_regularized(a, b, z) - ------------
a beta(a, b)
(%i14) beta_incomplete_regularized(a-1,b,z);
(%o14) beta_incomplete_regularized(a, b, z)
b a - 1
(1 - z) z
- ----------------------
beta(a, b) (b + a - 1)
The derivative and the integral wrt z:
(%i15) diff(beta_incomplete_regularized(a,b,z),z);
b - 1 a - 1
(1 - z) z
(%o15) -------------------
beta(a, b)
(%i16) integrate(beta_incomplete_regularized(a,b,z),z);
268 Maxima 5.30.0 Manual
(%o16) beta_incomplete_regularized(a, b, z) z
b a
(1 - z) z
a (beta_incomplete_regularized(a, b, z) - ------------)
a beta(a, b)
- -------------------------------------------------------
b + a
Function beta incomplete generalized (a, b, z1, z2)
The basic denition of the generalized incomplete beta function is
z2
/
[ b - 1 a - 1
I (1 - t) t dt
]
/
z1
Maxima simplies beta_incomplete_regularized for a and b a positive integer.
For realpart(a) > 0 and z1 = 0 or z2 = 0, Maxima simplies beta_incomplete_
generalized to beta_incomplete. For realpart(b) > 0 and z1 = 1 or z2=1, Maxima
simplies to an expression with beta and beta_incomplete.
Maxima evaluates beta_incomplete_regularized for real and complex values in
oat and bigoat precision.
When beta_expand is true, Maxima expands beta_incomplete_generalized for
a +n and a n, n a positive integer.
Maxima knows the derivative of beta_incomplete_generalized with respect to the
variables a, b, z1, and z2 and the integrals with respect to the variables z1 and z2.
Examples:
Maxima simplies beta_incomplete_generalized for a and b a positive integer:
(%i1) beta_incomplete_generalized(2,b,z1,z2);
b b
(1 - z1) (b z1 + 1) - (1 - z2) (b z2 + 1)
(%o1) -------------------------------------------
b (b + 1)
(%i2) beta_incomplete_generalized(a,2,z1,z2);
a a
(a (1 - z2) + 1) z2 - (a (1 - z1) + 1) z1
(%o2) -------------------------------------------
a (a + 1)
(%i3) beta_incomplete_generalized(3,2,z1,z2);
2 2 2 2
(1 - z1) (3 z1 + 2 z1 + 1) - (1 - z2) (3 z2 + 2 z2 + 1)
(%o3) -----------------------------------------------------------
12
Simplication for specic values z1 = 0, z2 = 0, z1 = 1, or z2 = 1:
Chapter 15: Special Functions 269
(%i4) assume(a > 0, b > 0)$
(%i5) beta_incomplete_generalized(a,b,z1,0);
(%o5) - beta_incomplete(a, b, z1)
(%i6) beta_incomplete_generalized(a,b,0,z2);
(%o6) - beta_incomplete(a, b, z2)
(%i7) beta_incomplete_generalized(a,b,z1,1);
(%o7) beta(a, b) - beta_incomplete(a, b, z1)
(%i8) beta_incomplete_generalized(a,b,1,z2);
(%o8) beta_incomplete(a, b, z2) - beta(a, b)
Numerical evaluation for real arguments in oat or bigoat precision:
(%i9) beta_incomplete_generalized(1/2,3/2,0.25,0.31);
(%o9) .09638178086368676
(%i10) fpprec:32$
(%i10) beta_incomplete_generalized(1/2,3/2,0.25,0.31b0);
(%o10) 9.6381780863686935309170054689964b-2
Numerical evaluation for complex arguments in oat or bigoat precision:
(%i11) beta_incomplete_generalized(1/2+%i,3/2+%i,0.25,0.31);
(%o11) - .09625463003205376 %i - .003323847735353769
(%i12) fpprec:20$
(%i13) beta_incomplete_generalized(1/2+%i,3/2+%i,0.25,0.31b0);
(%o13) - 9.6254630032054178691b-2 %i - 3.3238477353543591914b-3
Expansion for a +n or a n, n a positive integer, when beta_expand is true:
(%i14) beta_expand:true$
(%i15) beta_incomplete_generalized(a+1,b,z1,z2);
b a b a
(1 - z1) z1 - (1 - z2) z2
(%o15) -----------------------------
b + a
a beta_incomplete_generalized(a, b, z1, z2)
+ -------------------------------------------
b + a
(%i16) beta_incomplete_generalized(a-1,b,z1,z2);
beta_incomplete_generalized(a, b, z1, z2) (- b - a + 1)
(%o16) -------------------------------------------------------
1 - a
b a - 1 b a - 1
(1 - z2) z2 - (1 - z1) z1
- -------------------------------------
1 - a
Derivative wrt the variable z1 and integrals wrt z1 and z2:
270 Maxima 5.30.0 Manual
(%i17) diff(beta_incomplete_generalized(a,b,z1,z2),z1);
b - 1 a - 1
(%o17) - (1 - z1) z1
(%i18) integrate(beta_incomplete_generalized(a,b,z1,z2),z1);
(%o18) beta_incomplete_generalized(a, b, z1, z2) z1
+ beta_incomplete(a + 1, b, z1)
(%i19) integrate(beta_incomplete_generalized(a,b,z1,z2),z2);
(%o19) beta_incomplete_generalized(a, b, z1, z2) z2
- beta_incomplete(a + 1, b, z2)
Option variable beta expand
Default value: false
When beta_expand is true, beta(a,b) and related functions are expanded for argu-
ments like a +n or a n, where n is an integer.
Option variable beta args sum to integer
Default value: false
When beta_args_sum_to_integer is true, Maxima simplies beta(a,b), when the
arguments a and b sum to an integer.
Function psi [n](x)
The derivative of log (gamma (x)) of order n+1. Thus, psi[0](x) is the rst deriva-
tive, psi[1](x) is the second derivative, etc.
Maxima does not know how, in general, to compute a numerical value of psi, but
it can compute some exact values for rational args. Several variables control what
range of rational args psi will return an exact value, if possible. See maxpsiposint,
maxpsinegint, maxpsifracnum, and maxpsifracdenom. That is, x must lie between
maxpsinegint and maxpsiposint. If the absolute value of the fractional part of x is
rational and has a numerator less than maxpsifracnum and has a denominator less
than maxpsifracdenom, psi will return an exact value.
The function bfpsi in the bffac package can compute numerical values.
Option variable maxpsiposint
Default value: 20
maxpsiposint is the largest positive value for which psi[n](x) will try to compute
an exact value.
Option variable maxpsinegint
Default value: -10
maxpsinegint is the most negative value for which psi[n](x) will try to compute an
exact value. That is if x is less than maxnegint, psi[n](x) will not return simplied
answer, even if it could.
Option variable maxpsifracnum
Default value: 6
Let x be a rational number less than one of the form p/q. If p is greater than
maxpsifracnum, then psi[n](x) will not try to return a simplied value.
Chapter 15: Special Functions 271
Option variable maxpsifracdenom
Default value: 6
Let x be a rational number less than one of the form p/q. If q is greater than
maxpsifracdenom, then psi[n](x) will not try to return a simplied value.
Function makefact (expr)
Transforms instances of binomial, gamma, and beta functions in expr into factorials.
See also makegamma.
Function numfactor (expr)
Returns the numerical factor multiplying the expression expr, which should be a single
term.
content returns the greatest common divisor (gcd) of all terms in a sum.
(%i1) gamma (7/2);
15 sqrt(%pi)
(%o1) ------------
8
(%i2) numfactor (%);
15
(%o2) --
8
15.5 Exponential Integrals
The Exponential Integral and related funtions are dened in Abramowitz and Stegun,
Handbook of Mathematical Functions, Chapter 5
Function expintegral e1 (z)
The Exponential Integral E1(z) (A&S 5.1.1)
Function expintegral ei (z)
The Exponential Integral Ei(z) (A&S 5.1.2)
Function expintegral li (z)
The Exponential Integral Li(z) (A&S 5.1.3)
Function expintegral e (n,z)
The Exponential Integral En(z) (A&S 5.1.4)
Function expintegral si (z)
The Exponential Integral Si(z) (A&S 5.2.1)
Function expintegral ci (z)
The Exponential Integral Ci(z) (A&S 5.2.2)
272 Maxima 5.30.0 Manual
Function expintegral shi (z)
The Exponential Integral Shi(z) (A&S 5.2.3)
Function expintegral chi (z)
The Exponential Integral Chi(z) (A&S 5.2.4)
Option variable expintrep
Default value: false
Change the representation of the Exponential Integral to gamma incomplete, expin-
tegral e1, expintegral ei, expintegral li, expintegral trig, expintegral hyp
Option variable expintexpand
Default value: false
Expand the Exponential Integral E[n](z) for half integral values in terms of Erfc or
Erf and for positive integers in terms of Ei
15.6 Error Function
The Error function and related funtions are dened in Abramowitz and Stegun, Handbook
of Mathematical Functions, Chapter 7
Function erf (z)
The Error Function erf(z) (A&S 7.1.1)
See also ag erfflag.
Function erfc (z)
The Complementary Error Function erfc(z) (A&S 7.1.2)
erfc(z) = 1-erf(z)
Function er (z)
The Imaginary Error Function.
erfi(z) = -%i*erf(%i*z)
Function erf generalized (z1,z2)
Generalized Error function Erf(z1,z2)
Function fresnel c (z)
The Fresnel Integral C(z) = integrate(cos((%pi/2)*t^2),t,0,z). (A&S 7.3.1)
The simplication fresnel c(-x) = -fresnel c(x) is applied when ag trigsign is true.
The simplication fresnel c(%i*x) = %i*fresnel c(x) is applied when ag %iargs is
true.
See ags erf_representation and hypergeometric_representation.
Chapter 15: Special Functions 273
Function fresnel s (z)
The Fresnel Integral S(z) = integrate(sin((%pi/2)*t^2),t,0,z). (A&S 7.3.2)
The simplication fresnel s(-x) = -fresnel s(x) is applied when ag trigsign is true.
The simplication fresnel s(%i*x) = %i*fresnel s(x) is applied when ag %iargs is
true.
See ags erf_representation and hypergeometric_representation.
Option variable erf representation
Default value: false
When T erfc, er, erf generalized, fresnel s and fresnel c are transformed to erf.
Option variable hypergeometric representation
Default value: false
Enables transformation to a Hypergeometric representation for fresnel s and fresnel c
15.7 Struve Functions
The Struve functions are dened in Abramowitz and Stegun, Handbook of Mathematical
Functions, Chapter 12.
Function struve h (v, z)
The Struve Function H of order v and argument z. (A&S 12.1.1)
Function struve l (v, z)
The Modied Struve Function L of order v and argument z. (A&S 12.2.1)
15.8 Hypergeometric Functions
The Hypergeometric Functions are dened in Abramowitz and Stegun, Handbook of
Mathematical Functions, Chapters 13 and 15.
Maxima has very limited knowledge of these functions. They can be returned from
function hgfred.
Function %m [k,u] (z)
Whittaker M function M[k,u](z) = exp(-z/2)*z^(1/2+u)*M(1/2+u-k,1+2*u,z).
(A&S 13.1.32)
Function %w [k,u] (z)
Whittaker W function. (A&S 13.1.33)
Function %f [p,q] ([a],[b],z)
The pFq(a1,a2,..ap;b1,b2,..bq;z) hypergeometric function, where a a list of length p
and b a list of length q.
274 Maxima 5.30.0 Manual
Function hypergeometric ([a1, ..., ap],[b1, ... ,bq], x)
The hypergeometric function. Unlike Maximas %f hypergeometric function, the func-
tion hypergeometric is a simplifying function; also, hypergeometric supports com-
plex double and big oating point evaluation. For the Gauss hypergeometric function,
that is p = 2 and q = 1, oating point evaluation outside the unit circle is supported,
but in general, it is not supported.
When the option variable expand_hypergeometric is true (default is false) and
one of the arguments a1 through ap is a negative integer (a polynomial case),
hypergeometric returns an expanded polynomial.
Examples:
(%i1) hypergeometric([],[],x);
(%o1) %e^x
Polynomial cases automatically expand when expand_hypergeometric is true:
(%i2) hypergeometric([-3],[7],x);
(%o2) hypergeometric([-3],[7],x)
(%i3) hypergeometric([-3],[7],x), expand_hypergeometric : true;
(%o3) -x^3/504+3*x^2/56-3*x/7+1
Both double oat and big oat evaluation is supported:
(%i4) hypergeometric([5.1],[7.1 + %i],0.42);
(%o4) 1.346250786375334 - 0.0559061414208204 %i
(%i5) hypergeometric([5,6],[8], 5.7 - %i);
(%o5) .007375824009774946 - .001049813688578674 %i
(%i6) hypergeometric([5,6],[8], 5.7b0 - %i), fpprec : 30;
(%o6) 7.37582400977494674506442010824b-3
- 1.04981368857867315858055393376b-3 %i
15.9 Parabolic Cylinder Functions
The Parabolic Cylinder Functions are dened in Abramowitz and Stegun, Handbook of
Mathematical Functions, Chapter 19.
Maxima has very limited knowledge of these functions. They can be returned from
function hgfred.
Function parabolic cylinder d (v, z)
The parabolic cylinder function parabolic_cylinder_d(v,z). (A&s 19.3.1)
15.10 Functions and Variables for Special Functions
Function specint (exp(- s*t) * expr, t)
Compute the Laplace transform of expr with respect to the variable t. The integrand
expr may contain special functions.
The following special functions are handled by specint: incomplete gamma function,
error functions (but not the error function erfi, it is easy to transform erfi e.g. to
Chapter 15: Special Functions 275
the error function erf), exponential integrals, bessel functions (including products of
bessel functions), hankel functions, hermite and the laguerre polynomials.
Furthermore, specint can handle the hypergeometric function %f[p,q]([],[],z),
the whittaker function of the rst kind %m[u,k](z) and of the second kind
%w[u,k](z).
The result may be in terms of