Maxima Computer Algebra System Guide
Maxima Computer Algebra System Guide
Version 5.45.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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4 Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5 Data Types and Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
6 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
7 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
8 Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
9 Simplification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
10 Mathematical Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
11 Maxima’s Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
12 Plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
13 File Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
14 Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
15 Special Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
16 Elliptic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
17 Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
18 Differentiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
19 Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
20 Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
21 Differential Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
22 Numerical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
23 Matrices and Linear Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
24 Affine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
25 itensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
26 ctensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
27 atensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
28 Sums, Products, and Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
29 Number Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515
30 Symmetries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537
31 Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 555
32 Runtime Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557
33 Miscellaneous Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565
ii
70 linearalgebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1017
71 lsquares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1031
72 minpack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1041
73 makeOrders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1043
74 mnewton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1045
75 numericalio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1047
76 odepack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1053
77 operatingsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1057
78 opsubst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1059
79 orthopoly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1061
80 pytranslate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1073
81 ratpow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1079
82 romberg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1081
83 simplex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1085
84 simplification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1089
85 solve rec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1099
86 stats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1105
87 stirling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1123
88 stringproc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1125
89 to poly solve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1149
90 unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1169
91 wrstcse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1179
92 zeilberger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1183
93 Error and warning messages . . . . . . . . . . . . . . . . . . . . . . . . . . 1187
94 Command-line options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1191
A Function and Variable Index . . . . . . . . . . . . . . . . . . . . . . . . . . 1193
v
Table of Contents
1 Introduction to Maxima . . . . . . . . . . . . . . . . . . . . . . . . 1
3 Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.1 Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.2 Functions and Variables for Help. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4 Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.1 Introduction to Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.2 Functions and Variables for Command Line . . . . . . . . . . . . . . . . . . . . 15
4.3 Functions and Variables for Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
6 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
6.1 Introduction to Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
6.2 Nouns and Verbs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
6.3 Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
6.4 Inequality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
6.5 Functions and Variables for Expressions. . . . . . . . . . . . . . . . . . . . . . . . 87
vi
7 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
7.1 Introduction to operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
7.2 Arithmetic operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
7.3 Relational operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
7.4 Logical operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
7.5 Operators for Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
7.6 Assignment operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
7.7 User defined operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
8 Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
8.1 Functions and Variables for Evaluation . . . . . . . . . . . . . . . . . . . . . . . 131
9 Simplification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
9.1 Introduction to Simplification. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
9.2 Functions and Variables for Simplification . . . . . . . . . . . . . . . . . . . . 145
12 Plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
12.1 Introduction to Plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
12.2 Plotting Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
12.3 Functions and Variables for Plotting . . . . . . . . . . . . . . . . . . . . . . . . . 210
12.4 Plotting Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
12.5 Gnuplot Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
12.6 Gnuplot pipes Format Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
14 Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
14.1 Introduction to Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
14.2 Functions and Variables for Polynomials . . . . . . . . . . . . . . . . . . . . . 257
17 Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
17.1 Functions and Variables for Limits. . . . . . . . . . . . . . . . . . . . . . . . . . . 319
18 Differentiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
18.1 Functions and Variables for Differentiation . . . . . . . . . . . . . . . . . . . 321
19 Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
19.1 Introduction to Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
19.2 Functions and Variables for Integration . . . . . . . . . . . . . . . . . . . . . . 335
19.3 Introduction to QUADPACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
19.3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
19.4 Functions and Variables for QUADPACK . . . . . . . . . . . . . . . . . . . . 347
20 Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
20.1 Functions and Variables for Equations . . . . . . . . . . . . . . . . . . . . . . . 357
22 Numerical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
22.1 Introduction to fast Fourier transform . . . . . . . . . . . . . . . . . . . . . . . 381
22.2 Functions and Variables for fft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
22.3 Functions and Variables for FFTPACK5 . . . . . . . . . . . . . . . . . . . . . 385
22.4 Functions for numerical solution of equations . . . . . . . . . . . . . . . . 387
22.5 Introduction to numerical solution of differential equations . . . 389
22.6 Functions for numerical solution of differential equations . . . . . 390
24 Affine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
24.1 Introduction to Affine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
24.2 Functions and Variables for Affine . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
25 itensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
25.1 Introduction to itensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
25.1.1 New tensor notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
25.1.2 Indicial tensor manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
25.2 Functions and Variables for itensor . . . . . . . . . . . . . . . . . . . . . . . . . . 433
25.2.1 Managing indexed objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
25.2.2 Tensor symmetries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442
25.2.3 Indicial tensor calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444
25.2.4 Tensors in curved spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448
25.2.5 Moving frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
25.2.6 Torsion and nonmetricity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
25.2.7 Exterior algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
25.2.8 Exporting TeX expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460
25.2.9 Interfacing with ctensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461
25.2.10 Reserved words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
26 ctensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
26.1 Introduction to ctensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
26.2 Functions and Variables for ctensor . . . . . . . . . . . . . . . . . . . . . . . . . . 465
26.2.1 Initialization and setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
26.2.2 The tensors of curved space. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
26.2.3 Taylor series expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470
26.2.4 Frame fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
26.2.5 Algebraic classification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
26.2.6 Torsion and nonmetricity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
26.2.7 Miscellaneous features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
ix
27 atensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
27.1 Introduction to atensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
27.2 Functions and Variables for atensor . . . . . . . . . . . . . . . . . . . . . . . . . . 492
30 Symmetries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537
30.1 Introduction to Symmetries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537
30.2 Functions and Variables for Symmetries . . . . . . . . . . . . . . . . . . . . . 537
30.2.1 Changing bases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537
30.2.2 Changing representations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
30.2.3 Groups and orbits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542
30.2.4 Partitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545
30.2.5 Polynomials and their roots . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546
30.2.6 Resolvents. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547
30.2.7 Miscellaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
31 Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 555
31.1 Functions and Variables for Groups . . . . . . . . . . . . . . . . . . . . . . . . . . 555
35 Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585
35.1 Introduction to Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585
35.1.1 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585
35.1.2 Set Member Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 587
35.1.3 Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588
35.2 Functions and Variables for Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588
38 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657
38.1 Source Level Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657
38.2 Keyword Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 658
38.3 Functions and Variables for Debugging . . . . . . . . . . . . . . . . . . . . . . 659
39 alt-display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665
39.1 Introduction to alt-display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665
39.2 Functions and Variables for alt-display. . . . . . . . . . . . . . . . . . . . . . . 666
40 asympa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671
40.1 Introduction to asympa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671
40.2 Functions and variables for asympa . . . . . . . . . . . . . . . . . . . . . . . . . . 671
42 Bernstein . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675
42.1 Functions and Variables for Bernstein . . . . . . . . . . . . . . . . . . . . . . . 675
xi
43 bitwise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677
43.1 Functions and Variables for bitwise . . . . . . . . . . . . . . . . . . . . . . . . . . 677
44 bode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681
44.1 Functions and Variables for bode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681
45 celine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 685
45.1 Introduction to celine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 685
47 cobyla . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 689
47.1 Introduction to cobyla . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 689
47.2 Functions and Variables for cobyla. . . . . . . . . . . . . . . . . . . . . . . . . . . 689
47.3 Examples for cobyla . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 691
48 combinatorics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693
48.1 Package combinatorics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693
48.2 Functions and Variables for Combinatorics . . . . . . . . . . . . . . . . . . . 693
50 descriptive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 705
50.1 Introduction to descriptive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 705
50.2 Functions and Variables for data manipulation . . . . . . . . . . . . . . . 707
50.3 Functions and Variables for descriptive statistics . . . . . . . . . . . . . 713
50.4 Functions and Variables for statistical graphs . . . . . . . . . . . . . . . . 728
51 diag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 739
51.1 Functions and Variables for diag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 739
52 distrib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 745
52.1 Introduction to distrib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 745
52.2 Functions and Variables for continuous distributions . . . . . . . . . 747
52.3 Functions and Variables for discrete distributions . . . . . . . . . . . . 767
xii
53 draw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 779
53.1 Introduction to draw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 779
53.2 Functions and Variables for draw . . . . . . . . . . . . . . . . . . . . . . . . . . . . 780
53.2.1 Scenes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 780
53.2.2 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 781
53.2.3 Plot options for draw programs . . . . . . . . . . . . . . . . . . . . . . . . . 785
53.2.4 Graphics objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 854
53.3 Functions and Variables for pictures . . . . . . . . . . . . . . . . . . . . . . . . . 884
53.4 Functions and Variables for worldmap . . . . . . . . . . . . . . . . . . . . . . . 886
53.4.1 Variables and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 886
53.4.2 Graphic objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 891
54 drawdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897
54.1 Introduction to drawdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897
54.2 Functions and Variables for drawdf . . . . . . . . . . . . . . . . . . . . . . . . . . 897
54.2.1 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897
55 dynamics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 901
55.1 The dynamics package. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 901
55.2 Graphical analysis of discrete dynamical systems . . . . . . . . . . . . . 901
55.3 Visualization with VTK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 906
55.3.1 Scene options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 908
55.3.2 Scene objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 909
55.3.3 Scene object’s options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 910
56 engineering-format . . . . . . . . . . . . . . . . . . . . . . . . . . 915
56.1 Functions and Variables for engineering-format . . . . . . . . . . . . . . 915
56.2 Known Bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 915
57 ezunits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 917
57.1 Introduction to ezunits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 917
57.2 Introduction to physical constants . . . . . . . . . . . . . . . . . . . . . . . . . . . 918
57.3 Functions and Variables for ezunits . . . . . . . . . . . . . . . . . . . . . . . . . . 920
58 f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 935
58.1 Package f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 935
59 finance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 937
59.1 Introduction to finance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 937
59.2 Functions and Variables for finance . . . . . . . . . . . . . . . . . . . . . . . . . . 937
xiii
60 fractals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 943
60.1 Introduction to fractals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 943
60.2 Definitions for IFS fractals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 943
60.3 Definitions for complex fractals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 944
60.4 Definitions for Koch snowflakes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 945
60.5 Definitions for Peano maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 945
61 ggf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 947
61.1 Functions and Variables for ggf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 947
62 graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 949
62.1 Introduction to graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 949
62.2 Functions and Variables for graphs . . . . . . . . . . . . . . . . . . . . . . . . . . 949
62.2.1 Building graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 949
62.2.2 Graph properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 955
62.2.3 Modifying graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 970
62.2.4 Reading and writing to files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 972
62.2.5 Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 973
63 grobner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 979
63.1 Introduction to grobner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 979
63.1.1 Notes on the grobner package . . . . . . . . . . . . . . . . . . . . . . . . . . . 979
63.1.2 Implementations of admissible monomial orders in grobner . . 979
63.2 Functions and Variables for grobner . . . . . . . . . . . . . . . . . . . . . . . . . 980
63.2.1 Global switches for grobner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 980
63.2.2 Simple operators in grobner . . . . . . . . . . . . . . . . . . . . . . . . . . . . 981
63.2.3 Other functions in grobner. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 981
63.2.4 Standard postprocessing of Groebner Bases . . . . . . . . . . . . . 983
64 hompack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 987
64.1 Introduction to hompack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 987
64.2 Functions and Variables for hompack . . . . . . . . . . . . . . . . . . . . . . . . 987
65 impdiff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 991
65.1 Functions and Variables for impdiff . . . . . . . . . . . . . . . . . . . . . . . . . . 991
66 interpol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 993
66.1 Introduction to interpol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 993
66.2 Functions and Variables for interpol . . . . . . . . . . . . . . . . . . . . . . . . . 993
67 lapack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1001
67.1 Introduction to lapack. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1001
67.2 Functions and Variables for lapack . . . . . . . . . . . . . . . . . . . . . . . . . 1001
xiv
68 lbfgs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1009
68.1 Introduction to lbfgs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1009
68.2 Functions and Variables for lbfgs . . . . . . . . . . . . . . . . . . . . . . . . . . . 1009
69 lindstedt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1015
69.1 Functions and Variables for lindstedt . . . . . . . . . . . . . . . . . . . . . . . 1015
70 linearalgebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1017
70.1 Introduction to linearalgebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1017
70.2 Functions and Variables for linearalgebra . . . . . . . . . . . . . . . . . . . 1019
71 lsquares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1031
71.1 Introduction to lsquares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1031
71.2 Functions and Variables for lsquares . . . . . . . . . . . . . . . . . . . . . . . . 1031
72 minpack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1041
72.1 Introduction to minpack. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1041
72.2 Functions and Variables for minpack . . . . . . . . . . . . . . . . . . . . . . . 1041
73 makeOrders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1043
73.1 Functions and Variables for makeOrders . . . . . . . . . . . . . . . . . . . . 1043
74 mnewton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1045
74.1 Introduction to mnewton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1045
74.2 Functions and Variables for mnewton . . . . . . . . . . . . . . . . . . . . . . . 1045
75 numericalio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1047
75.1 Introduction to numericalio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1047
75.1.1 Plain-text input and output . . . . . . . . . . . . . . . . . . . . . . . . . . . 1047
75.1.2 Separator flag values for input . . . . . . . . . . . . . . . . . . . . . . . . . 1047
75.1.3 Separator flag values for output . . . . . . . . . . . . . . . . . . . . . . . 1047
75.1.4 Binary floating-point input and output . . . . . . . . . . . . . . . . 1048
75.2 Functions and Variables for plain-text input and output . . . . 1048
75.3 Functions and Variables for binary input and output . . . . . . . . 1050
76 odepack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1053
76.1 Introduction to ODEPACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1053
76.1.1 Getting Started with ODEPACK . . . . . . . . . . . . . . . . . . . . . . 1053
76.2 Functions and Variables for odepack . . . . . . . . . . . . . . . . . . . . . . . . 1054
77 operatingsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1057
77.1 Introduction to operatingsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1057
77.2 Directory operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1057
77.3 File operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1057
77.4 Environment operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1057
xv
78 opsubst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1059
78.1 Functions and Variables for opsubst . . . . . . . . . . . . . . . . . . . . . . . . 1059
79 orthopoly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1061
79.1 Introduction to orthogonal polynomials . . . . . . . . . . . . . . . . . . . . . 1061
79.1.1 Getting Started with orthopoly . . . . . . . . . . . . . . . . . . . . . . . . 1061
79.1.2 Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1063
79.1.3 Floating point Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1065
79.1.4 Graphics and orthopoly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1066
79.1.5 Miscellaneous Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1067
79.1.6 Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1068
79.2 Functions and Variables for orthogonal polynomials . . . . . . . . . 1068
80 pytranslate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1073
80.1 Introduction to pytranslate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1073
80.1.1 Tests for pytranslate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1074
80.2 Functions in pytranslate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1074
80.3 Extending pytranslate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1075
81 ratpow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1079
81.1 Functions and Variables for ratpow . . . . . . . . . . . . . . . . . . . . . . . . . 1079
82 romberg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1081
82.1 Functions and Variables for romberg. . . . . . . . . . . . . . . . . . . . . . . . 1081
83 simplex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1085
83.1 Introduction to simplex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1085
83.1.1 Tests for simplex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1085
83.1.1.1 klee minty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1085
83.1.1.2 NETLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1085
83.2 Functions and Variables for simplex . . . . . . . . . . . . . . . . . . . . . . . . 1086
84 simplification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1089
84.1 Introduction to simplification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1089
84.2 Package absimp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1089
84.3 Package facexp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1089
84.4 Package functs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1091
84.5 Package ineq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1094
84.6 Package rducon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1096
84.7 Package scifac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1096
86 stats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1105
86.1 Introduction to stats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1105
86.2 Functions and Variables for inference result . . . . . . . . . . . . . . . . 1105
86.3 Functions and Variables for stats . . . . . . . . . . . . . . . . . . . . . . . . . . . 1107
86.4 Functions and Variables for special distributions . . . . . . . . . . . . 1122
87 stirling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1123
87.1 Functions and Variables for stirling . . . . . . . . . . . . . . . . . . . . . . . . . 1123
88 stringproc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1125
88.1 Introduction to String Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . 1125
88.2 Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1126
88.3 Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1132
88.4 String Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1137
88.5 Octets and Utilities for Cryptography . . . . . . . . . . . . . . . . . . . . . . 1143
90 unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1169
90.1 Introduction to Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1169
90.2 Functions and Variables for Units . . . . . . . . . . . . . . . . . . . . . . . . . . 1170
91 wrstcse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1179
91.1 Introduction to wrstcse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1179
91.2 Functions and Variables for wrstcse. . . . . . . . . . . . . . . . . . . . . . . . . 1179
92 zeilberger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1183
92.1 Introduction to zeilberger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1183
92.1.1 The indefinite summation problem . . . . . . . . . . . . . . . . . . . . . 1183
92.1.2 The definite summation problem . . . . . . . . . . . . . . . . . . . . . . 1183
92.1.3 Verbosity levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1183
92.2 Functions and Variables for zeilberger . . . . . . . . . . . . . . . . . . . . . . 1184
92.3 General global variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1185
92.4 Variables related to the modular test . . . . . . . . . . . . . . . . . . . . . . . 1186
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();". Here’s 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
Examples:
(%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
Chapter 1: Introduction to Maxima 3
(%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)
Maxima knows about complex numbers and numerical constants:
(%i1) cos(%pi);
(%o1) - 1
(%i2) exp(%i*%pi);
(%o2) - 1
Maxima can do differential 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 don’t want a result
printed, you can finish 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.45.0 Manual
0.8
0.6
sin(x)/x
0.4
0.2
-0.2
(%i2) plot2d ([atan(x), erf(x), tanh(x)], [x, -5, 5], [y, -1.5, 2])$
2
atan(x)
erf(x)
1.5 tanh(x)
0.5
-0.5
-1
-1.5
-4 -2 0 2 4
x
Chapter 1: Introduction to Maxima 5
sin(sqrt(y^2+x^2))/sqrt(y^2+x^2)
1
0.8
0.6
0.4
z
0.2
0
-0.2 10
5
-0.4
-10 0
-5 y
0 -5
x 5 -10
10
7
This specifies the testsuite consists of the files "rtest13s" and "rtest14", but "rtest14"
contains two tests that are known to fail: 57 and 63.
bug_report () [Function]
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 "".
build_info () [Function]
Returns a summary of the parameters of the Maxima build, as a Maxima structure
(defined by defstruct). The fields 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.36.1"
Maxima build date: "2015-06-02 11:26:48"
Host type: "x86_64-unknown-linux-gnu"
Lisp implementation type: "GNU Common Lisp (GCL)"
Lisp implementation version: "GCL 2.6.12"
(%i2) x : build_info ()$
(%i3) x@version;
(%o3) 5.36.1
(%i4) x@timestamp;
(%o4) 2015-06-02 11:26:48
(%i5) x@host;
(%o5) x86_64-unknown-linux-gnu
(%i6) x@lisp_name;
(%o6) GNU Common Lisp (GCL)
(%i7) x@lisp_version;
(%o7) GCL 2.6.12
(%i8) x;
(%o8)
Maxima version: "5.36.1"
Maxima build date: "2015-06-02 11:26:48"
Host type: "x86_64-unknown-linux-gnu"
Lisp implementation type: "GNU Common Lisp (GCL)"
Lisp implementation version: "GCL 2.6.12"
Chapter 2: Bug Detection and Reporting 9
The Maxima version string can (here 5.36.1) can look very different:
(%i1) build_info();
(%o1)
Maxima version: "branch_5_37_base_331_g8322940_dirty"
Maxima build date: "2016-01-01 15:37:35"
Host type: "x86_64-unknown-linux-gnu"
Lisp implementation type: "CLISP"
Lisp implementation version: "2.49 (2010-07-07) (built 3605577779) (memory 3660647
In that case, Maxima was not build from a released sourcecode, but directly from the
GIT-checkout of the sourcecode. In the example, the checkout is 331 commits after
the latest GIT tag (usually a Maxima (major) release (5.37 in our example)) and the
abbreviated commit hash of the last commit was "8322940".
Front-ends for maxima can add information about currently being used by setting
the variables maxima_frontend and maxima_frontend_version accordingly.
11
3 Help
3.1 Documentation
The Maxima on-line user’s manual can be viewed in different forms. From the Maxima
interactive prompt, the user’s manual is viewed as plain text by the ? command (i.e., the
describe function). The user’s 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.
The same example, using the symbol gamma, rather than the string:
12 Maxima 5.45.0 Manual
(%i2) apropos(gamma);
(%o2) [%gamma, Gamma, gamma_expand, gammalim, makegamma,
prefer_gamma_incomplete, gamma, gamma-incomplete, gamma_incomplete,
gamma_incomplete_generalized, gamma_incomplete_generalized_regularized,
gamma_incomplete_lower, gamma_incomplete_regularized, log_gamma]
The number of symbols in the current Maxima session. This will vary.
(%i3) length(apropos(""));
(%o3) 2338
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
describe [Function]
describe (string)
describe (string, exact)
describe (string, inexact)
describe(string) is equivalent to describe(string, exact).
describe(string, exact) finds an item with title equal (case-insensitive) to string,
if there is any such item.
Chapter 3: Help 13
describe(string, inexact) finds 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 11.
Example:
(%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
example [Function]
example (topic)
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 file 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:
(%i1) example(append);
(%i2) append([y+x,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],x^2+y^2+z^2)
2 2 2
(%o4) lambda([x, y, z], x + y + z )
(%i5) %(1,2,a)
2
(%o5) a + 5
(%i6) 1+2+a
(%o6) a + 3
(%o6) done
4 Command Line
_ [System variable]
_ is the most recent input expression (e.g., %i1, %i2, %i3, . . . ).
_ is assigned the input expression before the input is simplified or evaluated. However,
the value of _ is simplified (but not evaluated) when it is displayed.
_ is recognized by batch and load. In a file processed by batch, _ has the same
meaning as at the interactive prompt. In a file processed by load, _ is bound to the
input expression most recently evaluated at the interactive prompt or in a batch file;
_ is not bound to the input expressions in the file being processed.
16 Maxima 5.45.0 Manual
% [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 file processed by batch, % has the same
meaning as at the interactive prompt. In a file processed by load, % is bound to the
output expression most recently computed at the interactive prompt or in a batch
file; % is not bound to output expressions in the file 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 first statement in a compound statement, or outside of a compound statement,
%% is undefined.
%% is recognized by batch and load, and it has the same meaning as at the interactive
prompt.
See also %.
Examples:
Chapter 4: Command Line 17
? [Special symbol]
As prefix to a function or variable name, ? signifies that the name is a Lisp name,
not a Maxima name. For example, ?round signifies the Lisp function ROUND. See
Section 37.1 [Lisp and Maxima], page 641, 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.
$ [Input terminator]
The dollar sign $ terminates an input expression, and the most recent output % and
an output label, e.g. %o1, are assigned the result, but the result is not displayed.
See also ;.
Example:
(%i1) 1 + 2 + 3 $
(%i2) %;
(%o2) 6
(%i3) %o1;
(%o3) 6
; [Input terminator]
The semicolon ; terminates an input expression, and the resulting output is displayed.
See also $.
Example:
(%i1) 1 + 2 + 3;
(%o1) 6
inchar [Option variable]
Default value: %i
inchar is the prefix 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 first char of the prefix, the
prefixes inchar, outchar, and linechar should have a different first char. Otherwise
some commands like kill(inlabels) do not work as expected.
See also labels.
Example:
(%i1) inchar: "input";
(%o1) input
Chapter 4: Command Line 19
(input2) expand((a+b)^3);
3 2 2 3
(%o2) b + 3 a b + 3 a b + a
values All bound atoms which are user variables, not Maxima options or
switches, created by : or :: or functional binding.
functions
All user-defined functions, created by := or define.
myoptions
All options ever reset by the user (whether or not they are later reset to
their default values).
aliases All atoms which have an user-defined 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,
dependencies, or gradef functions.
gradefs All functions which have user-defined 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.
structures
All structs defined using defstruct.
let_rule_packages
All user-defined 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.)
20 Maxima 5.45.0 Manual
kill [Function]
kill (a_1, . . . , a_n)
kill (labels)
kill (inlabels, outlabels, linelabels)
kill (n)
kill ([m, n])
kill (values, functions, arrays, . . . )
kill (all)
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 affecting any other elements
of the array.
Several special arguments are recognized. Different 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 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 specific property. Note that facts
declared by assume don’t require a symbol they apply to, therefore aren’t stored as
properties of symbols and therefore aren’t affected by kill.
kill always returns done, even if an argument has no binding.
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 interme-
diate 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.
labels [System variable]
The variable labels is the list of input, output, and intermediate expression labels,
including all previous labels if inchar, outchar, or linechar were redefined.
linechar [Option variable]
Default value: %t
linechar is the prefix 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 first char of the prefix, the
prefixes inchar, outchar, and linechar should have a different first char. Otherwise
some commands like kill(inlabels) do not work as expected.
Intermediate expressions might or might not be displayed. See programmode and
labels.
linenum [System variable]
The line number of the current pair of input and output expressions.
myoptions [System variable]
Default value: []
myoptions is the list of all options ever reset by the user, whether or not they get
reset to their default value.
nolabels [Option variable]
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 affected 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.
22 Maxima 5.45.0 Manual
playback [Function]
playback ()
playback (n)
playback ([m, n])
playback ([m])
playback (input)
playback (slow)
playback (time)
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.
Chapter 4: Command Line 23
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.
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 file 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 affected by the grind option. See grind.
Arguments may be combined, e.g., playback ([5, 10], grind, time, slow).
quit () [Function]
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 657.
The display index separator S can be a string, including an empty string, or false,
indicating the default separator, or any expression. If not a string and not false, the
property value is coerced to a string via string.
If no display index separator is assigned, the default separator is used. The default
separator is a comma. There is no way to change the default separator.
Each symbol has its own value of display_index_separator.
See also put, get, and declare_index_properties.
Examples:
When a symbol A has index display properties, the value of the property display_
index_separator is the string or other expression which is displayed between indices.
The value is assigned by put(A, S, display_index_separator),
(%i1) declare_index_properties (A, [postsuperscript, postsuperscript,
presubscript, presubscript]);
(%o1) done
(%i2) put (A, ";", display_index_separator);
(%o2) ;
(%i3) A[w, x, y, z];
w;x
(%o3) A
y;z
The assigned value is retrieved by get(A, display_index_separator).
(%i1) declare_index_properties (A, [postsuperscript, postsuperscript,
presubscript, presubscript]);
(%o1) done
(%i2) put (A, ";", display_index_separator);
(%o2) ;
(%i3) get (A, display_index_separator);
(%o3) ;
The display index separator S can be a string, including an empty string, or false,
indicating the default separator, or any expression.
(%i1) declare_index_properties (A, [postsuperscript, postsuperscript,
presubscript, presubscript]);
(%o1) done
(%i2) A[w, x, y, z];
w, x
(%o2) A
y, z
(%i3) put (A, "-", display_index_separator);
(%o3) -
(%i4) A[w, x, y, z];
w-x
(%o4) A
y-z
(%i5) put (A, " ", display_index_separator);
(%o5)
Chapter 4: Command Line 29
2
x - x
0.8414709848078965
(%o3) done
display (expr_1, expr_2, . . . ) [Function]
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) = 0.8414709848078965
(%o3) done
display2d [Option variable]
Default value: true
When display2d is true, the console display is an attempt to present mathematical
expressions as they might appear in books and articles, using only letters, num-
bers, and some punctuation characters. This display is sometimes called the "pretty
printer" display.
When display2d is false, the console display is a 1-dimensional or linear form which
is the same as the output produced by grind.
Chapter 4: Command Line 31
When display2d is false, the value of stringdisp is ignored, and strings are always
displayed with quote marks.
See also leftjust to switch between a left justified 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)
display_format_internal [Option variable]
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
dispterms (expr) [Function]
Displays expr in parts one below the other. That is, first 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:
(%i1) dispterms(2*a*sin(x)+%e^x);
+
32 Maxima 5.45.0 Manual
2 a sin(x)
x
%e
(%o1) done
expt (a, b) [Special symbol]
ncexpt (a, b) [Special symbol]
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.
exptdispflag [Option variable]
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
grind (expr) [Function]
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
definition 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.
grind evaluates its argument.
Examples:
(%i1) aa + 1729;
(%o1) aa + 1729
(%i2) grind (%);
aa+1729$
(%o2) done
Chapter 4: Command Line 33
3 2 2 3
(%t4) b + 3 a b + 3 a b + a
3 2 2 3
(%t4) f = b + 3 a b + 3 a b + a
When leftjust is true, equations in 2D-display are drawn left justified rather than
centered.
See also display2d to switch between 1D- and 2D-display.
Example:
(%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
linel [Option variable]
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 affected by
linel.
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:
(%i1) obase : 2;
(%o1) 10
(%i10) 2^8 - 1;
(%o10) 11111111
(%i11) 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
pfeformat [Option variable]
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)
powerdisp [Option variable]
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 first and the highest power last.
Chapter 4: Command Line 39
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)
5.1 Numbers
5.1.1 Introduction to Numbers
Complex numbers
A complex expression is specified 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 simplification of products of complex expressions can be
effected by expanding the product. Simplification of quotients, roots, and other functions
of complex expressions can usually be accomplished by using the realpart, imagpart,
rectform, polarform, abs, carg functions.
(%o2) 2.314069263277927b1
(%i3) bfloat(abs(-%gamma));
(%o3) 5.772156649015329b-1
(%i4) bfloat(log(%phi));
(%o4) 4.812118250596035b-1
(-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
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
(%o3) Embedded line termination
in this string.
(%i4) in this string.";
(%o4) Ignore the line termination characters in this string.
(%i5) s_4 : "Ignore the \
(%o5) false
(%i6) line termination \
(%o6) This is a string.
(%i7) characters in \
(%o7) true
(%i8) this string.";
(%o8) "This is a string."
(%i9) stringdisp : false;
(%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
5.3 Constants
5.3.1 Functions and Variables for Constants
%e [Constant]
%e represents the base of the natural logarithm, also known as Euler’s number. The
numeric value of %e is the double-precision floating-point value 2.718281828459045d0.
%i [Constant]
%i represents the imaginary unit, sqrt(−1).
false [Constant]
false represents the Boolean constant of the same name. Maxima implements false
by the value NIL in Lisp.
%gamma [Constant]
The Euler-Mascheroni constant, 0.5772156649015329 ....
ind [Constant]
ind represents a bounded, indefinite result.
See also limit.
Example:
(%i1) limit (sin(1/x), x, 0);
(%o1) ind
inf [Constant]
inf represents real positive infinity.
infinity [Constant]
infinity represents complex infinity.
minf [Constant]
minf represents real minus (i.e., negative) infinity.
%phi [Constant]
%phi represents the so-called golden mean, (1+sqrt(5))/2. The numeric value of %phi
is the double-precision floating-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.
(%i1) fibtophi (fib (n));
n n
%phi - (1 - %phi)
(%o1) -------------------
2 %phi - 1
Chapter 5: Data Types and Structures 51
zerob [Constant]
zerob represents an infinitesimal below zero. zerob can be used in expressions. limit
simplifies expressions which contain infinitesimals.
See also zeroa and limit.
Chapter 5: Data Types and Structures 53
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,
hashed arrays and 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 infix 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 flag which denotes the type field of the Maxima expression is a list itself, since after it
has been through the simplifier the list would become
((MLIST SIMP) 1 2 7 ((MPLUS SIMP) $X $Y))
[ [Operator]
] [Operator]
[ and ] mark the beginning and end, respectively, of a list.
[ and ] also enclose the subscripts of a list, array, hashed array, or memoizing
function. Note that other than for arrays accessing the nth element of a list may need
an amount of time that is roughly proportional to n, See Section 5.4.3 [Performance
considerations for Lists], page 70.
Note that if an element of a subscripted variable is written to before a list or an array
of this name is declared a hashed array (see Section 5.5 [Arrays], page 72) is created,
not a list.
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
54 Maxima 5.45.0 Manual
assoc [Function]
assoc (key, e, default)
assoc (key, e)
assoc searches for key as the first part of an argument of e and returns the second
part of the first match, if any.
key may be any expression. e must be a nonatomic expression, and every argument
of e must have exactly two parts. assoc returns the second part of the first match-
ing argument of e. Matches are determined by is(key = first(a)) where a is an
argument of e.
If there are two or more matches, only the first is returned. If there are no matches,
default is returned, if specified. Otherwise, false is returned.
See also sublist and member.
Examples:
key may be any expression. e must be a nonatomic expression, and every argument
of e must have exactly two parts. assoc returns the second part of the first matching
argument of e.
(%i1) assoc (f(x), foo(g(x) = y, f(x) = z + 1, h(x) = 2*u));
(%o1) z + 1
If there are two or more matches, only the first is returned.
(%i1) assoc (yy, [xx = 111, yy = 222, yy = 333, yy = 444]);
(%o1) 222
If there are no matches, default is returned, if specified. Otherwise, false is returned.
(%i1) assoc (abc, [[x, 111], [y, 222], [z, 333]], none);
(%o1) none
(%i2) assoc (abc, [[x, 111], [y, 222], [z, 333]]);
(%o2) false
Chapter 5: Data Types and Structures 55
cons [Function]
cons (expr, list)
cons (expr_1, expr_2)
cons (expr, list) returns a new list constructed of the element expr as its first
element, followed by the elements of list. This is analogous to the Lisp language
construction operation "cons".
The Maxima function cons can also be used where the second argument is other than a
list and this might be useful. In this case, cons (expr_1, expr_2) returns an expres-
sion with same operator as expr 2 but with argument cons(expr_1, args(expr_2)).
Examples:
(%i1) cons(a,[b,c,d]);
(%o1) [a, b, c, d]
(%i2) cons(a,f(b,c,d));
(%o2) f(a, b, c, d)
In general, cons applied to a nonlist doesn’t make sense. For instance, cons(a,b^c)
results in an illegal expression, since ’^’ cannot take three arguments.
When inflag is true, cons operates on the internal structure of an expression, oth-
erwise cons operates on the displayed form. Especially when inflag is true, cons
applied to a nonlist sometimes gives a surprising result; for example
(%i1) cons(a,-a), inflag : true;
2
(%o1) - a
(%i2) cons(a,-a), inflag : false;
(%o2) 0
delete [Function]
delete (expr_1, expr_2)
delete (expr_1, expr_2, n)
delete(expr_1, expr_2) removes from expr 2 any arguments of its top-level oper-
ator 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
affected.
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 first 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))];
(%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 ]
Chapter 5: Data Types and Structures 57
endcons [Function]
endcons (expr, list)
endcons (expr_1, expr_2)
endcons (expr, list) returns a new list constructed of the elements of list followed
by expr. The Maxima function endcons can also be used where the second argu-
ment is other than a list and this might be useful. In this case, endcons (expr_1,
expr_2) returns an expression with same operator as expr 2 but with argument
endcons(expr_1, args(expr_2)). Examples:
(%i1) endcons(a,[b,c,d]);
(%o1) [b, c, d, a]
(%i2) endcons(a,f(b,c,d));
(%o2) f(b, c, d, a)
In general, endcons applied to a nonlist doesn’t make sense. For instance,
endcons(a,b^c) results in an illegal expression, since ’^’ cannot take three
arguments.
When inflag is true, endcons operates on the internal structure of an expression,
otherwise endcons operates on the displayed form. Especially when inflag is true,
endcons applied to a nonlist sometimes gives a surprising result; for example
(%i1) endcons(a,-a), inflag : true;
2
(%o1) - a
(%i2) endcons(a,-a), inflag : false;
(%o2) 0
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. One reason
why this may make a difference is that the simplifier re-orders expressions:
(%i1) x+y;
(%o1) y+1
(%i2) first(x+y),inflag : true;
(%o2) x
(%i3) first(x+y),inflag : false;
(%o3) y
The functions second . . . tenth yield the second through the tenth part of their
input argument.
See also firstn and part.
lreduce(F, s) returns F(... F(F(s_1, s_2), s_3), ... s_n). When the optional
argument s 0 is present, the result is equivalent to lreduce(F, cons(s_0, s)).
The function F is first applied to the leftmost list elements, thus the name "lreduce".
See also rreduce, xreduce, and tree_reduce.
Examples:
lreduce without the optional argument.
(%i1) lreduce (f, [1, 2, 3]);
(%o1) f(f(1, 2), 3)
(%i2) lreduce (f, [1, 2, 3, 4]);
(%o2) f(f(f(1, 2), 3), 4)
lreduce with the optional argument.
(%i1) lreduce (f, [1, 2, 3], 4);
(%o1) f(f(f(4, 1), 2), 3)
lreduce applied to built-in binary operators. / is the division operator.
(%i1) lreduce ("^", args ({a, b, c, d}));
b c d
(%o1) ((a ) )
(%i2) lreduce ("/", args ({a, b, c, d}));
a
(%o2) -----
b c d
makelist [Function]
makelist ()
makelist (expr, n)
makelist (expr, i, i_max)
makelist (expr, i, i_0, i_max)
makelist (expr, i, i_0, i_max, step)
makelist (expr, x, list)
The first 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
elements 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]
Chapter 5: Data Types and Structures 63
item can be any Maxima symbol or expression. If the argument list is not bound to
a list, Maxima signals an error.
To remove the first item from a list, see pop.
Examples:
(%i1) ll: [];
(%o1) []
(%i2) push (x, ll);
(%o2) [x]
(%i3) push (x^2+y, ll);
2
(%o3) [y + x , x]
(%i4) a: push ("string", ll);
2
(%o4) [string, y + x , x]
(%i5) pop (ll);
(%o5) string
(%i6) pop (ll);
2
(%o6) y + x
(%i7) pop (ll);
(%o7) x
(%i8) ll;
(%o8) []
(%i9) a;
2
(%o9) [string, y + x , x]
rest [Function]
rest (expr, n)
rest (expr)
Returns expr with its first 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. The first argument expr may
be a list, matrix, or other expression. When expr is an atom, rest signals an error;
when expr is an empty list and partswitch is false, rest signals an error. When
expr is an empty list and partswitch is true, rest returns end.
Applying rest to expression such as f(a,b,c) returns f(b,c). In general, applying
rest to a nonlist doesn’t make sense. For example, because ’^’ requires two argu-
ments, rest(a^b) results in an error message. The functions args and op may be
useful as well, since args(a^b) returns [a,b] and op(a^b) returns ^.
See also firstn and lastn.
(%i1) rest(a+b+c);
(%o1) b+a
(%i2) rest(a+b+c,2);
(%o2) a
(%i3) rest(a+b+c,-2);
(%o3) c
Chapter 5: Data Types and Structures 65
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 undefined. If P(a, b) is something other than true
or false, sort signals an error.
The predicate may be specified as the name of a function or binary infix operator, or
as a lambda expression. If specified 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 modified.
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 defines 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 specified as the name of a function or binary infix operator, or
as a lambda expression. If specified as the name of an operator, the name must be
enclosed in double quotes.
(%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]]
Chapter 5: Data Types and Structures 67
unchanged if there are an odd number of elements. Then repeat until the list is
reduced to a single element, which is the return value.
When the optional argument s 0 is present, the result is equivalent tree_reduce(F,
cons(s_0, s)).
For addition of floating point numbers, tree_reduce may return a sum that has a
smaller rounding error than either rreduce or lreduce.
The elements of s and the partial results may be arranged in a minimum-depth binary
tree, thus the name "tree reduce".
Examples:
tree_reduce applied to a list with an even number of elements.
(%i1) tree_reduce (f, [a, b, c, d]);
(%o1) f(f(a, b), f(c, d))
tree_reduce applied to a list with an odd number of elements.
(%i1) tree_reduce (f, [a, b, c, d, e]);
(%o1) f(f(f(a, b), f(c, d)), e)
unique (L) [Function]
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]
xreduce [Function]
xreduce (F, s)
xreduce (F, s, s_0)
Extends the function F to an n-ary function by composition, or, if F is already n-ary,
applies F to s. When F is not n-ary, xreduce is the same as lreduce. The argument
s is a list.
Functions known to be n-ary include addition +, multiplication *, and, or, max, min,
and append. Functions may also be declared n-ary by declare(F, nary). For these
functions, xreduce is expected to be faster than either rreduce or lreduce.
When the optional argument s 0 is present, the result is equivalent to xreduce(s,
cons(s_0, s)).
Floating point addition is not exactly associative; be that as it may, xreduce applies
Maxima’s n-ary addition when s contains floating point numbers.
Examples:
xreduce applied to a function known to be n-ary. F is called once, with all arguments.
(%i1) declare (F, nary);
(%o1) done
(%i2) F ([L]) := L;
(%o2) F([L]) := L
70 Maxima 5.45.0 Manual
(%o2) done
Another even faster example would be:
(%i1) l:[Test,1,2,3,4];
(%o1) [Test, 1, 2, 3, 4]
(%i2) for i in l do
disp(pop(l));
Test
3
Chapter 5: Data Types and Structures 71
(%o2) done
Beginning traversal with the last element of a list is possible after reversing the list
using reverse (). If the elements of a long list need to be processed in a different order
performance might be increased by converting the list into a declared array first.
Note also that the ending condition of for loops is tested for every iteration which means
that the result of a length should be cached if it is used in the ending condition:
(%i1) l:makelist(i,i,1,100000)$
(%i2) lngth:length(l);
(%o2) 100000
(%i3) x:1;
(%o3) 1
(%i4) for i:1 thru lngth do
x:x+1$
(%i5) x;
(%o5) 100001
72 Maxima 5.45.0 Manual
5.5 Arrays
Maxima supports 3 array-like constructs:
• If one tries to write to an indexed variable without creating a list first an undeclared
array (also named hashed array) is created that grows dynamically and allows numbers,
symbols and strings as indices:
(%i1) a["feww"]:1;
(%o1) 1
(%i2) a[qqwdqwd]:3;
(%o2) 3
(%i3) a[5]:99;
(%o3) 99
(%i4) a[qqwdqwd];
(%o4) 3
(%i5) a[5];
(%o5) 99
(%i6) a["feww"];
(%o6) 1
Since lisp handles hashed arrays and memoizing functions similar to arrays many of
the functions that can be applied to arrays can be applied to them, as well.
• Lists (see makelist allow for fast addition and removal of elements, can be created
without knowing their final size.
• Declared arrays that allow fast access to random elements at the cost that their size
needs to be known at construction time. (See Section 5.4.3 [Performance considerations
for Lists], page 70.)
(%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]]
(%i5) listarray (cc);
z v
(%o5) [-, -]
4 u
Using arrayinfo in order to convert an undeclared array to a declared array:
(%i1) for i:0 thru 10 do a[i]:i^2$
(%i2) indices:map(first,rest(rest(arrayinfo(a))));
(%o2) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
(%i3) array(A,fixnum,length(indices)-1)$
(%i4) fillarray(A,map(lambda([x],a[x]),indices))$
(%i5) listarray(A);
(%o5) [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
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 )]
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) {Lisp Array: #(NIL NIL NIL NIL NIL NIL NIL)}
(%i5) arrays;
(%o5) [aa, bb, cc]
arraysetapply (A, [i_1, . . . , i_n], x) [Function]
Assigns x to A[i_1, ..., i_n], where A is an array and i 1, . . . , i n are integers.
arraysetapply evaluates its arguments.
fillarray (A, B) [Function]
Fills array A from B, which is a list or an array.
If a specific type was declared for A when it was created, it can only be filled with
elements of that same type; it is an error if an attempt is made to copy an element
of a different type.
If the dimensions of the arrays A and B are different, A is filled in row-major order.
If there are not enough elements in B the last element is used to fill out the rest of
A. If there are too many, the remaining ones are ignored.
fillarray returns its first argument.
Examples:
Create an array of 9 elements and fill 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 fill 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) {Lisp Array: #(0 0 0 0 0 0 0 0)}
(%i2) fillarray (a2, [1, 2, 3, 4, 5]);
(%o2) {Lisp Array: #(1 2 3 4 5 5 5 5)}
(%i3) fillarray (a2, [4]);
(%o3) {Lisp Array: #(4 4 4 4 4 4 4 4)}
Chapter 5: Data Types and Structures 77
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:
remarray [Function]
remarray (A_1, . . . , A_n)
remarray (all)
Removes arrays and array associated functions and frees the storage occupied. The
arguments may be declared arrays, 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 clear the cache of a memoizing
function.
remarray returns the list of arrays removed.
remarray quotes its arguments.
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 identified by name (the field name) and the expression as a whole
is identified by its operator (the structure name). A field value can be any expression.
A structure is defined by the defstruct function; the global variable structures is
the list of user-defined structures. The function new creates instances of structures. The
@ operator refers to fields. kill(S) removes the structure definition S, and kill(x@ a)
unbinds the field 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 field represented as an equation, with the field
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 field names.
There is no way to use a field name as a function name, although a field value can be
a lambda expression. Nor can the values of fields be restricted to certain types; any field
can be assigned any kind of expression. There is no way to make some fields accessible or
inaccessible in different contexts; all fields are always visible.
defstruct [Function]
defstruct (S(a_1, . . . , a_n))
defstruct (S(a_1 = v_1, . . . , a_n = v_n))
Define a structure, which is a list of named fields 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 specifies the name of a field. An argument
which is an equation a = v specifies the field name a and its default value v. The
default value can be any expression.
defstruct puts S on the list of user-defined structures, structures.
kill(S) removes S from the list of user-defined structures, and removes the structure
definition.
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)
(%i4) defstruct (bar (v, w, x = 123, y = %pi));
Chapter 5: Data Types and Structures 83
(%i8) u@z;
(%o8) u@z
The field 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
85
6 Expressions
forms of a function are identical when displayed. The global flag 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;
(%o8) bar(52)
(%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 Identifiers
Maxima identifiers may comprise alphabetic characters, plus the numerals 0 through 9, plus
any special character preceded by the backslash \ character.
A numeral may be the first character of an identifier 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 identifier. The alphabetic characters are initially
A through Z, a through z, %, and _.
Chapter 6: Expressions 87
Maxima is case-sensitive. The identifiers foo, FOO, and Foo are distinct. See Section 37.1
[Lisp and Maxima], page 641, for more on this point.
A Maxima identifier 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 641, 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.
aliases is the list of atoms which have an user defined alias (set up by the alias,
ordergreat, orderless functions or by declaring the atom a noun with declare.)
allbut [Keyword]
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 effect of kill(all) except that it does not
kill the symbols a 1, a 2, . . .
box [Function]
box (expr)
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.
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 effectively excluded from computations. rembox
removes the box again.
boxchar is the character used to draw the box in box and in the dpart and lpart
functions.
See also rembox, dpart and lpart.
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) -
90 Maxima 5.45.0 Manual
dispform [Function]
dispform (expr)
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.
(%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
92 Maxima 5.45.0 Manual
(%o5) %e
(%i6) freeof (exp, exp (x));
(%o6) true
A summation or definite integral is free of its dummy variable. An indefinite 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
(%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
listconstvars [Option variable]
Default value: false
When listconstvars is true the list returned by listofvars contains constant
variables, such as %e, %pi, %i or any variables declared as constant that occur in
expr. A variable is declared as constant type via declare, and constantp returns
true for all variables declared as constant. The default is to omit constant variables
from listofvars return value.
listdummyvars [Option variable]
Default value: true
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
96 Maxima 5.45.0 Manual
as given in freeof. "Dummy variables" are mathematical things like the index of a
sum or product, the limit variable, and the definite 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]
listofvars (expr) [Function]
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
lfreeof (list, expr) [Function]
For each member m of list, calls freeof (m, expr). It returns false if any call to
freeof does and true otherwise.
Example:
(%i1) lfreeof ([ a, x], x^2+b);
(%o1) false
(%i2) lfreeof ([ b, x], x^2+b);
(%o2) false
(%i3) lfreeof ([ a, y], x^2+b);
(%o3) true
lpart (label, expr, n_1, . . . , n_k) [Function]
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.
mainvar [Property]
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 isn’t a mainvar, resimplifica-
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.)
noun [Property]
noun is one of the options of the declare command. It makes a function so declared
a "noun", meaning that it won’t be evaluated automatically.
Chapter 6: Expressions 97
Example:
(%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
noundisp [Option variable]
Default value: false
When noundisp is true, nouns display with a single quote. This switch is always
true when displaying function definitions.
nounify (f) [Function]
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 can’t be evaluated for certain arguments. This is
also the form returned if a function call is preceded by a quote.
See also verbify.
nterms (expr) [Function]
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).
op (expr) [Function]
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-defined prefix, binary or
n-ary infix, postfix, matchfix, or nofix 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 a memoizing function or ordinary function ex-
pression, and op returns a symbol.
op observes the value of the global flag inflag.
op evaluates it argument.
See also args.
Examples:
(%i1) stringdisp: true$
(%i2) op (a * b * c);
(%o2) "*"
(%i3) op (a * b + c);
(%o3) "+"
98 Maxima 5.45.0 Manual
operatorp [Function]
operatorp (expr, op)
operatorp (expr, [op_1, . . . , op_n])
operatorp (expr, op) returns true if op is equal to the operator of expr.
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.
(%i1) r+r[0];
(%o1) r + r
0
(%i2) opsubst;
(%o2) true
(%i3) subst (x^2, r, r+r[0]);
2 2
(%o3) x + (x )
0
(%i4) opsubst: not opsubst;
(%o4) false
Chapter 6: Expressions 99
For other built-in operators and all other functions and operators, expressions are
ordered by their arguments (beginning with the first 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 modified 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
(%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", X, a, x]
Effect 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]
Effect of mainvar, constant, and scalar declarations.
(%i1) sort ([aa, foo, bar, bb, baz, quux, cc, dd, A1, B1, C1]);
(%o1) [A1, B1, C1, aa, bar, baz, bb, cc, dd, foo, quux]
(%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, C1, bar, bb, cc, dd, foo, 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, X , foo(1), k, X , foo(k)]
1 k
Chapter 6: Expressions 101
(%t3) - log(sqrt(x + 1) + 1)
2
sin(x )
(%t4) -------
3
b + a
(%t5) -----
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
Chapter 6: Expressions 103
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
(%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
psubst [Function]
psubst (list, expr)
psubst (a, b, expr)
psubst(a, b, expr) is similar to subst. See subst.
In distinction from subst the function psubst makes parallel substitutions, if the
first argument list is a list of equations.
See also sublis for making parallel substitutions and let and letsimp for others
ways to do substitutions.
Example:
The first example shows parallel substitution with psubst. The second example shows
the result for the function subst, which does a serial substitution.
(%i1) psubst ([a^2=b, b=a], sin(a^2) + sin(b));
(%o1) sin(b) + sin(a)
104 Maxima 5.45.0 Manual
rembox [Function]
rembox (expr, unlabelled)
rembox (expr, label)
rembox (expr)
Removes boxes from expr.
Examples:
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);
2 2
b - 2 a b + a
(%o7) -------------------------
b + a 2 b 2 a
2 %e + %e + %e
sqrtdenest (expr) [Function]
Denests sqrt of simple, numerical, binomial surds, where possible. E.g.
(%i1) sqrt(sqrt(3)/2+1)/sqrt(11*sqrt(2)-12);
sqrt(3)
sqrt(------- + 1)
2
(%o1) ---------------------
sqrt(11 sqrt(2) - 12)
(%i2) sqrtdenest(%);
sqrt(3) 1
------- + -
2 2
(%o2) -------------
1/4 3/4
3 2 - 2
Sometimes it helps to apply sqrtdenest more than once, on such as (19601-13860
sqrt(2))^(7/4).
sublis (list, expr) [Function]
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 simplification 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)
sublis_apply_lambda [Option variable]
Default value: true
Controls whether lambda’s substituted are applied in simplification after sublis is
used or whether you have to do an ev to get things to apply. true means do the
application.
Chapter 6: Expressions 107
(%i2) subst(100,g,g[x]+2),subnumsimp:true;
(%o2) 102
subst (a, b, c) [Function]
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
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.
See also at, ev and psubst, as well as let and letsimp.
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:
(%i1) subst([a=b, b=c], a+b);
(%o1) 2 c
108 Maxima 5.45.0 Manual
unorder () [Function]
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 difference 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;
%th(1) - %th(3);
2
(%o4) a + b x
(%i5) unorder();
2 2
(%o5) a - a
(%i6) %th(2);
(%o6) [a]
7 Operators
: 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
Chapter 7: Operators 113
(%i5) 5 ## 3;
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)
** [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 floating point number.
Chapter 7: Operators 117
not [Operator]
The logical negation operator. not is a prefix operator; its operand is a Boolean
expression, and its result is a Boolean value.
not forces evaluation (like is) of its operand.
The global flag 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.
or [Operator]
The logical disjunction operator. or is an n-ary infix 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 flag 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 119
= [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:
120 Maxima 5.45.0 Manual
(%o2) true
:: [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
Chapter 7: Operators 123
::= [Operator]
Macro function definition operator. ::= defines 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.
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 definitions and remove names from
macros.
fundef or dispfun return a macro function definition 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$
124 Maxima 5.45.0 Manual
(%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) ''%;
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 definition operator.
f(x_1, ..., x_n) := expr defines 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 body is evaluated every time the function
is called.
f[x_1, ..., x_n] := expr defines a so-called memoizing function. Its function
body is evaluated just once for each distinct value of its arguments, and that value is
returned, without evaluating the function body, whenever the arguments have those
values again. (A function of this kind is also known as a “array function”.)
f[x_1, ..., x_n](y_1, ..., y_m) := expr is a special case of a memoizing
function. f[x_1, ..., x_n] is a memoizing function which returns a lambda
expression with arguments y_1, ..., y_m. The function body is evaluated once for
each distinct value of x_1, ..., x_n, and the body of the lambda expression is that
value.
When the last or only function argument x n is a list of one element, the function
defined 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 definitions appear in the same namespace; defining a function f within an-
other function g does not automatically limit the scope of f to g. However, local(f)
makes the definition of function f effective only within the block or other compound
expression in which local appears.
If some formal argument x k is a quoted symbol, the function defined 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
Chapter 7: Operators 125
matchfix [Function]
matchfix (ldelimiter, rdelimiter)
matchfix (ldelimiter, rdelimiter, arg_pos, pos)
Declares a matchfix operator with left and right delimiters ldelimiter and rdelimiter.
The delimiters are specified as strings.
A "matchfix" operator is a function of any number of arguments, such that the
arguments occur between matching left and right delimiters. The delimiters may be
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 different from the left delimiter.
A left delimiter can be associated with only one right delimiter; two different matchfix
operators cannot have the same left delimiter.
An existing operator may be redeclared as a matchfix operator without changing its
other properties. In particular, built-in operators such as addition + can be declared
matchfix, but operator functions cannot be defined for built-in operators.
The command matchfix (ldelimiter, rdelimiter, arg_pos, pos) declares the
argument part-of-speech arg pos and result part-of-speech pos, and the delimiters
ldelimiter 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 matchfix operation is an ordinary user-defined function.
The operator function is defined in the usual way with the function definition 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 definition.
The only built-in matchfix operator is the list constructor [ ]. Parentheses ( ) and
double-quotes " " act like matchfix operators, but are not treated as such by the
Maxima parser.
matchfix evaluates its arguments. matchfix returns its first argument, ldelimiter.
Examples:
Chapter 7: Operators 129
(%o5) done
(%i6) !-3, 5-!;
16
(%o6) - --
15
(%i7) "!-" (3, 5);
16
(%o7) - --
15
130 Maxima 5.45.0 Manual
nary [Function]
nary (op)
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
simplifier 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 111.
nofix [Function]
nofix (op)
nofix (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 111.
postfix [Function]
postfix (op)
postfix (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 111.
prefix [Function]
prefix (op)
prefix (op, rbp, rpos, pos)
A prefix operator is one which signifies 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 111.
131
8 Evaluation
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 simplification.
(%i1) sin (17 * %pi) + cos (17 * %pi);
(%o1) - 1
(%i2) '(sin (17 * %pi) + cos (17 * %pi));
(%o2) - 1
Maxima considers floating point operations by its in-built mathematical functions to
be a simplification.
(%i1) sin(1.0);
(%o1) .8414709848078965
(%i2) '(sin(1.0));
(%o2) .8414709848078965
When the global flag noundisp is true, nouns display with a single quote.
(%i1) x:%pi;
(%o1) %pi
(%i2) bfloat(x);
(%o2) 3.141592653589793b0
(%i3) sin(x);
(%o3) 0
(%i4) noundisp;
(%o4) false
(%i5) 'bfloat(x);
(%o5) bfloat(%pi)
Chapter 8: Evaluation 133
(%i6) bfloat('x);
(%o6) x
(%i7) 'sin(x);
(%o7) 0
(%i8) sin('x);
(%o8) sin(x)
(%i9) noundisp : not noundisp;
(%o9) true
(%i10) 'bfloat(x);
(%o10) 'bfloat(%pi)
(%i11) bfloat('x);
(%o11) x
(%i12) 'sin(x);
(%o12) 0
(%i13) sin('x);
(%o13) sin(x)
(%i14)
’’ [Operator]
The quote-quote operator '' (two single quote marks) modifies 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
evaluation is otherwise suppressed, such as in function definitions, lambda expressions,
and expressions quoted by single quote '.
Quote-quote is recognized by batch and load.
See also ev, the single-quote operator [quote], page 131 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];
134 Maxima 5.45.0 Manual
op(cc + aa) = +
(%o3) done
(%i4) ''(aa + cc);
Chapter 8: Evaluation 135
(%o4) 6912
(%i5) display (_, op (_), args (_));
_ = dd + bb
op(dd + bb) = +
(%o5) done
(%t9) foo_2b(x) := %
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
eval [Special symbol]
As an argument in a call to ev (expr), eval causes an extra evaluation of expr. See
ev.
Example:
(%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
Chapter 8: Evaluation 139
(%i5) a,eval,eval;
(%o5) e
evflag [Property]
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 flags 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
(%i8) sum (1/k^2, k, 1, inf);
inf
====
\ 1
(%o8) > --
/ 2
==== k
k = 1
140 Maxima 5.45.0 Manual
evfun [Property]
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 specified, the functions are applied in
the order that they are specified.
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)
(%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
Chapter 8: Evaluation 141
(%i2) 1<2,pred;
(%o2) true
143
9 Simplification
antisymmetric [Property]
If declare(h,antisymmetric) is done, this tells the simplifier 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)
commutative [Property]
If declare(h, commutative) is done, this tells the simplifier 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.
Example:
(%i1) S (b, a);
(%o1) S(b, a)
(%i2) S (a, b) + S (b, a);
(%o2) S(b, a) + S(a, b)
(%i3) declare (S, commutative);
(%o3) done
(%i4) S (b, a);
(%o4) S(a, b)
(%i5) S (a, b) + S (b, a);
(%o5) 2 S(a, b)
(%i6) S (a, c, e, d, b);
(%o6) S(a, b, c, d, e)
evenfun [Property]
oddfun [Property]
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
expand [Function]
expand (expr)
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 efficient 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
150 Maxima 5.45.0 Manual
(%i2) exponentialize:true;
(%o2) true
(%i3) expand(expr,0,0);
2 %i x - %i x
%i (x + 1) (%e - %e )
(%o3) - -------------------------------
2
maxnegex is the largest negative exponent which will be expanded by the expand
command, see also maxposex.
multiplicative [Property]
declare(f, multiplicative) tells the Maxima simplifier that f is multiplicative.
1. If f is univariate, whenever the simplifier encounters f applied to a product,
f distributes over that product. E.g., f(x*y) simplifies to f(x)*f(y). This
simplification is not applied to expressions of the form f('product(...)).
2. If f is a function of 2 or more arguments, multiplicativity is defined as multiplica-
tivity in the first argument to f, e.g., f (g(x) * h(x), x) simplifies to f (g(x)
,x) * f (h(x), x).
multthru [Function]
multthru (expr)
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
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
nary [Property]
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 [function_nary], page 130
function. The sole effect of declare(f, nary) is to instruct the Maxima simplifier
to flatten nested expressions, for example, to simplify foo(x, foo(y, z)) to foo(x,
y, z). See also declare.
Chapter 9: Simplification 155
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)
negdistrib [Option variable]
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 flag, this is one flag you do not
want to set to false as a matter of course or necessarily for other than local use in
your Maxima.
Example:
(%i1) negdistrib;
(%o1) true
(%i2) -(x+y);
(%o2) (- y) - x
(%i3) negdistrib : not negdistrib ;
(%o3) false
(%i4) -(x+y);
(%o4) - (y + x)
opproperties [System variable]
opproperties is the list of the special operator properties recognized by the Maxima
simplifier.
Items are added to the opproperties list by the function define_opproperty.
Example:
(%i1) opproperties;
(%o1) [linear, additive, multiplicative, outative, evenfun,
oddfun, commutative, symmetric, antisymmetric, nary,
lassociative, rassociative]
define_opproperty (property_name, simplifier_fn) [Function]
Declares the symbol property name to be an operator property, which is simplified
by simplifier fn, which may be the name of a Maxima or Lisp function or a lambda
expression. After define_opproperty is called, functions and operators may be de-
clared to have the property name property, and simplifier fn is called to simplify
them.
simplifier fn must be a function of one argument, which is an expression in which the
main operator is declared to have the property name property.
simplifier fn is called with the global flag simp disabled. Therefore simplifier fn must
be able to carry out its simplification without making use of the general simplifier.
define_opproperty appends property name to the global list opproperties.
156 Maxima 5.45.0 Manual
outative [Property]
declare(f, outative) tells the Maxima simplifier that constant factors in the argu-
ment of f can be pulled out.
1. If f is univariate, whenever the simplifier 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 defined 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)
For some expressions radcan is quite time consuming. This is the cost of exploring
certain relationships among the components of the expression for simplifications 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
radexpand [Option variable]
Default value: true
radexpand controls some simplifications 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)
simplifies to 4*x.
More particularly, consider sqrt (x^2).
• If radexpand is all or assume (x > 0) has been executed, sqrt(x^2) simplifies
to x.
• If radexpand is true and domain is real (its default), sqrt(x^2) simplifies to
abs(x).
• If radexpand is false, or radexpand is true and domain is complex, sqrt(x^2)
is not simplified.
Note that domain only matters when radexpand is true.
rassociative [Property]
declare (g, rassociative) tells the Maxima simplifier that g is right-associative.
E.g., g(g(a, b), g(c, d)) simplifies to g(a, g(b, g(c, d))).
scsimp (expr, rule_1, . . . , rule_n) [Function]
Sequential Comparative Simplification (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 simplifications are tried, it returns
the original answer.
example (scsimp) displays some examples.
simp [Option variable]
Default value: true
simp enables simplification. This is the default. 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 simplification is suppressed
only during the evaluation phase of an expression. The flag does not suppress the
simplification which follows the evaluation phase.
158 Maxima 5.45.0 Manual
symmetric [Property]
declare (h, symmetric) tells the Maxima simplifier that h is a symmetric function.
E.g., h (x, z, y) simplifies to h (x, y, z).
commutative is synonymous with symmetric.
10 Mathematical Functions
(%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]
Simplification 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)
162 Maxima 5.45.0 Manual
Integrating and differentiating 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.
(%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
The floor function distributes over lists, matrices and equations. See distribute_
over.
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
The round function distributes over lists, matrices and equations. See distribute_
over.
factorial [Function]
! [Operator]
Represents the factorial function. Maxima treats factorial (x) the same as x!.
For any complex number x, except for negative integers, x! is defined as gamma(x+1).
For an integer x, x! simplifies to the product of the integers from 1 to x inclusive.
0! simplifies to 1. For a real or complex number in float or bigfloat precision x, x!
simplifies to the value of gamma (x+1). For x equal to n/2 where n is an odd integer,
x! simplifies 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 facto-
rials for integer and rational arguments. The functions minfactorial and factcomb
simplifies 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 bigfloat precision.
makegamma substitutes gamma for factorials and related functions.
Maxima knows the derivative of the factorial function and the limits for specific values
like negative integers.
The option variable factorial_expand controls the simplification of expressions like
(n+x)!, where n is an integer.
See also binomial.
172 Maxima 5.45.0 Manual
this transformation, and more complicated transformations of this ilk as well. The
logcontract command "contracts" expressions containing log.
%emode [Option variable]
Default value: true
When %emode is true, %e^(%pi %i x) is simplified as follows.
%e^(%pi %i x) simplifies to cos (%pi x) + %i sin (%pi x) if x is a floating point
number, an integer, or a multiple of 1/2, 1/3, 1/4, or 1/6, and then further simplified.
For other numerical x, %e^(%pi %i x) simplifies 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 simplification of %e^(%pi %i x) is carried out.
(%i1) %emode;
(%o1) true
(%i2) %e^(%pi*%i*1);
(%o2) - 1
(%i3) %e^(%pi*%i*216/144);
(%o3) - %i
(%i4) %e^(%pi*%i*192/144);
sqrt(3) %i 1
(%o4) (- ----------) - -
2 2
(%i5) %e^(%pi*%i*180/144);
%i 1
(%o5) (- -------) - -------
sqrt(2) sqrt(2)
(%i6) %e^(%pi*%i*120/144);
%i sqrt(3)
(%o6) -- - -------
2 2
(%i7) %e^(%pi*%i*121/144);
121 %i %pi
----------
144
(%o7) %e
%enumer [Option variable]
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.
(%i1) %enumer;
(%o1) false
(%i2) numer;
(%o2) false
Chapter 10: Mathematical Functions 175
(%i3) 2*%e;
(%o3) 2 %e
(%i4) %enumer: not %enumer;
(%o4) true
(%i5) 2*%e;
(%o5) 2 %e
(%i6) numer: not numer;
(%o6) true
(%i7) 2*%e;
(%o7) 5.43656365691809
(%i8) 2*%e^1;
(%o8) 5.43656365691809
(%i9) 2*%e^x;
x
(%o9) 2 2.718281828459045
exp (x) [Function]
Represents the exponential function. Instances of exp (x) in input are simplified to
%e^x; exp does not appear in simplified 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 simplified. See %emode.
%enumer, when true causes %e to be replaced by 2.718. . . whenever numer is true.
See %enumer.
(%i1) demoivre;
(%o1) false
(%i2) %e^(a + b*%i);
%i b + a
(%o2) %e
(%i3) demoivre: not demoivre;
(%o3) true
(%i4) %e^(a + b*%i);
a
(%o4) %e (%i sin(b) + cos(b))
li [s] (z) [Function]
Represents the polylogarithm function of order s and argument z, defined by the
infinite series
∞
X zk
Lis (z) =
k=1
ks
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 simplifies to - log (1 - z), which in turn
simplifies to a numerical value if z is a real or complex floating point number or the
numer evaluation flag is present.
176 Maxima 5.45.0 Manual
/
====
i = 1
When logexpand is false, these simplifications are disabled.
(%i1) logexpand : false $
(%i2) log(n^2);
2
(%o2) log(n )
(%i3) log(10*x);
(%o3) log(10 x)
(%i4) log(a/(n + 1));
a
(%o4) log(-----)
n + 1
(%i5) log ('product (X(i), i, 1, n));
n
/===\
! !
(%o5) log( ! ! X(i))
! !
i = 1
(%i2) [sin (%pi * n), cos (%pi * m), sin (%pi/2 * m),
cos (%pi/2 * m)];
m/2
(%o2) [0, 1, 0, (- 1) ]
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$
(%i2) sin (x / 2);
x
(%o2) sin(-)
2
(%i3) halfangles : true$
(%i4) sin (x / 2);
x
floor(-----)
2 %pi
(- 1) sqrt(1 - cos(x))
(%o4) ----------------------------------
sqrt(2)
(%i5) assume(x>0, x<2*%pi)$
(%i6) sin(x / 2);
sqrt(1 - cos(x))
(%o6) ----------------
sqrt(2)
ntrig [Package]
The ntrig package contains a set of simplification 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.
trigreduce [Function]
trigreduce (expr, x)
trigreduce (expr)
Combines products and powers of trigonometric and hyperbolic sin’s and cos’s 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
(%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);
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 187
11 Maxima’s Database
(%i3) c : x;
(%o3) x
(%i4) constantp(c);
(%o4) false
constantp (expr) [Function]
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)
declare (a_1, p_1, a_2, p_2, . . . ) [Function]
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 flag, for some flags 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:
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 first argument only.
alphabetic
Tells Maxima to recognize all characters in a i (which must be a string)
as alphabetic characters.
Chapter 11: Maxima’s Database 191
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 effect 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 first 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.
decreasing [Property]
increasing [Property]
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
even [Property]
odd [Property]
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.
Chapter 11: Maxima’s Database 193
Example:
(%i1) declare(n, even);
(%o1) done
(%i2) askinteger(n, even);
(%o2) yes
(%i3) askinteger(n);
(%o3) yes
(%i4) evenp(n);
(%o4) false
feature [Property]
Maxima understands two distinct types of features, system features and features
which apply to mathematical expressions. See also status for information about sys-
tem features. See also features and featurep for information about mathematical
features.
feature itself is not the name of a function or variable.
features [Declaration]
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
integer noninteger even
odd rational irrational
real imaginary complex
analytic increasing decreasing
oddfun evenfun posfun
constant commutative lassociative
rassociative symmetric antisymmetric
integervalued
194 Maxima 5.45.0 Manual
integervalued [Property]
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
nonarray [Property]
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
nonscalar [Property]
Makes atoms behave as does a list or matrix with respect to the dot operator.
See also declare.
posfun [Property]
declare (f, posfun) declares f to be a positive function. is (f(x) > 0) yields true.
See also declare.
196 Maxima 5.45.0 Manual
printprops [Function]
printprops (a, i)
printprops ([a_1, . . . , a_n], i)
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.
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
rational [Property]
irrational [Property]
declare(a, rational) or declare(a, irrational) tells Maxima to recognize a as
a rational or irrational real variable.
See also declare.
real [Property]
imaginary [Property]
complex [Property]
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.
rem (atom, indicator) [Function]
Removes the property indicated by indicator from atom. rem reverses the effect of
put.
rem returns done if atom had an indicator property when rem was called, or false if
it had no such property.
remove [Function]
remove (a_1, p_1, . . . , a_n, p_n)
remove ([a_1, . . . , a_m], [p_1, . . . , p_n], . . . )
remove ("a", operator)
remove (a, transfun)
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.
198 Maxima 5.45.0 Manual
scalar [Property]
declare(a, scalar) tells Maxima to consider a a scalar variable.
See also declare.
askinteger [Function]
askinteger (expr, integer)
askinteger (expr)
askinteger (expr, even)
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,
Chapter 11: Maxima’s Database 199
(%o6) pos
(%i7) asksign (a[1]);
x = a
1
(%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
p;
(%o10) pos
(%i11) asksign (a - b);
x = a
x = b
x = a
x = b
202 Maxima 5.45.0 Manual
p;
(%o11) neg
context [Option variable]
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 specified
context foo does not yet exist, it is created automatically by a call to newcontext.
The specified context is activated automatically.
See contexts for a general description of the context mechanism.
contexts [Option variable]
Default value: [initial, global]
contexts is a list of the contexts which currently exist, including the currently active
context.
The context mechanism makes it possible for an 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.
deactivate (context_1, . . . , context_n) [Function]
Deactivates the specified contexts context 1, . . . , context n.
facts [Function]
facts (item)
facts ()
If item is the name of a context, facts (item) returns a list of the facts in the
specified 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 different context,
are not listed.
Chapter 11: Maxima’s Database 203
forget [Function]
forget (pred_1, . . . , pred_n)
forget (L)
Removes predicates established by assume. The predicates may be expressions equiv-
alent to (but not necessarily identical to) those previously assumed.
forget (L), where L is a list of predicates, forgets each item on the list.
is (expr) [Function]
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 flag prederror. When
prederror is true, is complains with an error message. Otherwise, is returns
unknown.
ev(expr, pred) (which can be written expr, pred at the interactive prompt) is
equivalent 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
flag 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);
204 Maxima 5.45.0 Manual
newcontext [Function]
newcontext (name)
newcontext ()
Creates a new, empty context, called name, which has global as its only subcontext.
The newly-created context becomes the currently active context.
If name is not specified, a new name is created (via gensym) and returned.
newcontext evaluates its argument. newcontext returns name (if specified) or the
new context name.
supcontext [Function]
supcontext (name, context)
supcontext (name)
supcontext ()
Creates a new context, called name, which has context as a subcontext. context must
exist.
If context is not specified, the current context is assumed.
If name is not specified, a new name is created (via gensym) and returned.
supcontext evaluates its argument. supcontext returns name (if specified) or the
new context name.
The function compare doesn’t 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.
equal (a, b) [Function]
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
flag 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.
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);
Chapter 11: Maxima’s Database 207
(%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
flag 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
(%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
12 Plotting
additional package dynamics, but that package does not have to be loaded; the first
time julia is used, it will be loaded automatically.
Each pixel in the grid is given a color corresponding to the number of iterations it
takes the sequence that starts at that point to move out of the convergence circle of
radius 2 centered at the origin. The number of pixels in the grid is controlled by the
grid plot option (default 30 by 30). The maximum number of iterations is set with
the option iterations. The program sets its own default palette: magenta, violet,
blue, cyan, green, yellow, orange, red, brown and black, but it can be changed by
adding an explicit palette option in the command.
The default domain used goes from -2 to 2 in both axes and can be changed with
the x and y options. By default, the two axes are shown with the same scale, unless
the option yx_ratio is used or the option same_xy is disabled. Other general plot
options are also accepted.
The following example shows a region of the Julia set for the number -0.55 + i0.6.
The option color_bar_tics is used to prevent Gnuplot from adjusting the color box
up to 40, in which case the points corresponding the maximum 36 iterations would
not be black.
(%i1) julia (-0.55, 0.6, [iterations, 36], [x, -0.3, 0.2],
[y, 0.3, 0.9], [grid, 400, 400], [color_bar_tics, 0, 6, 36])$
0.9 36
0.8 30
0.7
24
0.6
y
18
0.5
12
0.4
6
0.3
-0.3 -0.2 -0.1 0 0.1 0.2
x
This program can be called without any arguments, in which case it will use a default
value of 9 iterations per point, a grid with dimensions set by the grid plot option
(default 30 by 30) and a region that extends from -2 to 2 in both axes. The options are
all the same that plot2d accepts, plus an option iterations to change the number
of iterations.
Each pixel in the grid is given a color corresponding to the number of iterations it
takes the sequence starting at zero to move out of the convergence circle of radius
2, centered at the origin. The maximum number of iterations is set by the option
iterations. The program uses its own default palette: magenta,violet, blue, cyan,
green, yellow, orange, red, brown and black, but it can be changed by adding an
explicit palette option in the command. By default, the two axes are shown with
the same scale, unless the option yx_ratio is used or the option same_xy is disabled.
Example:
[grid,400,400])$
(%i1) mandelbrot ([iterations, 30], [x, -2, 1], [y, -1.2, 1.2],
[grid,400,400])$
30
1
25
0.5
20
0 15
y
10
-0.5
5
-1
0
-2 -1.5 -1 -0.5 0 0.5 1
x
plot2d [Function]
plot2d (expr, range_x, options)
plot2d (expr_1=expr_2, range_x, range_y, options)
plot2d ([parametric, expr_x, expr y, range], options)
plot2d ([discrete, points], options)
plot2d ([contour, expr], range_x, range_y, options)
plot2d ([type_1, . . . , type_n], options)
There are 5 types of plots that can be plotted by plot2d:
1. Explicit functions. plot2d (expr, range x, options), where expr is an expression
that depends on only one variable, or the name of a function with one input
parameter and numerical results. range x is a list with three elements, the first
one being the name of the variable that will be shown on the horizontal axis of
the plot, and the other two elements should be two numbers, the first one smaller
than the second, that define the minimum and maximum values to be shown on
the horizontal axis. The name of the variable used in range x must be the same
variable on which expr depends. The result will show in the vertical axis the
corresponding values of the expression or function for each value of the variable
in the horizontal axis.
2. Implicit functions. plot2d (expr 1=expr 2, range x, range y, options), where
expr 1 and expr 2 are two expressions that can depend on one or two variables.
range x and range y must be two lists of three elements that define the ranges
for the variables in the two axes of the plot; the first element of each list is the
name of the corresponding variable, and the other two elements are the minimum
and maximum values for that variable. The two variables on which expr 1 and
expr 2 can depend are those specified by range x and range y. The result will
be a curve or a set of curves where the equation expr 1=expr 2 is true.
3. Parametric functions. plot2d ([parametric, expr x, expr y, range], options),
where expr x and expr y are two expressions that depend on a single parameter.
range must be a three-element list; the first element must be the name of the
parameter on which expr x and expr y depend, and the other two elements must
be the minimum and maximum values for that parameter. The result will be a
curve in which the horizontal and vertical coordinates of each point are the values
of expr x and expr y for a value of the parameter within the range given.
4. Set of points. plot2d ([discrete, points], options), displays a list of points, joined
by segments by default. The horizontal and vertical coordinates of each of those
points can be specified in three different ways: With two lists of the same length,
in which the elements of the first list are the horizontal coordinates of the points
and the second list are the vertical coordinates, or with a list of two-element
lists, each one corresponding to the two coordinates of one of the points, or with
a single list that defines the vertical coordinates of the points; in this last case,
the horizontal coordinates of the n points will be assumed to be the first n natural
numbers.
5. Contour lines. plot2d ([contour, expr], range x, range y, options), where expr
is an expression that depends on two variables. range x and range y will be
lists whose first elements are the names of those two variables, followed by two
numbers that set the minimum and maximum values for them. The first variable
Chapter 12: Plotting 215
will be represented along the horizontal axis and the second along the vertical
axis. The result will be a set of curves along which the given expression has
certain values. If those values are not specified with the option levels, plotd2d
will try to choose, at the most, 8 values of the form d*10^n, where d is either 1,
2 or 5, all of them within the minimum and maximum values of expr within the
given ranges.
At the end of a plot2d command several of the options described in Section 12.4
Plotting Options can be used. Many instances of the 5 types described above can
be combined into a single plot, by putting them inside a list: plot2d ([type 1, . . . ,
type n], options). If one of the types included in the list require range x or range y,
those ranges should come immediately after the list.
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:
1. Explicit function.
0.5
sin(x)
-0.5
-1
-3 -2 -1 0 1 2 3
x
2. Implicit function.
216 Maxima 5.45.0 Manual
0
y
-1
-2
-2 -1 0 1 2
x
3. Parametric function.
(%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]])$
4
cos(t)*((-2*cos(4*t))+%e^cos(t)-sin(t/12)^5)
-1
-2
-4 -3 -2 -1 0 1 2 3 4
sin(t)*((-2*cos(4*t))+%e^cos(t)-sin(t/12)^5)
4. Set of points.
1.2
0.8
y
0.6
0.4
0.2
2 4 6 8 10 12 14 16
x
5. Contour lines.
(%i1) plot2d ([contour, u^3 + v^2], [u, -4, 4], [v, -4, 4])$
4
-40.0
-20.0
3 0.0
20.0
40.0
2 60.0
0
v
-1
-2
-3
-4
-4 -3 -2 -1 0 1 2 3 4
u
If an explicit function grows too fast, the y option can be used to limit the values in
the vertical axis:
218 Maxima 5.45.0 Manual
20
15
10
5
sec(x)
-5
-10
-15
-20
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
x
When the plot box is disabled, no labels are created for the axes. In that case, instead
of using xlabel and ylabel to set the names of the axes, it is better to use option
label, which allows more flexibility. Option yx_ratio is used to change the default
rectangular shape of the plot; in this example the plot will fill a square.
A parabola
x^2-1
x
-2 2
1000
100
10
%e^(3*s)
0.1
0.01
0.001
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
s
1.5
F
G
H
1
0.5
-0.5
-1
-1.5
-1 -0.5 0 0.5 1
u
Plot of a circle, using its parametric representation, together with the function -|x|.
The circle will only look like a circle if the scale in the two axes is the same, which is
done with the option same_xy.
220 Maxima 5.45.0 Manual
1 cos(t), sin(t)
-abs(x)
0.5
-0.5
-1
-1.5
-1 -0.5 0 0.5 1
x
5
y
In the next example a table with three columns is saved in a file “data.txt” which is
then read and the second and third column are plotted on the two axes:
(%i1) display2d:false$
(%i2) with_stdout ("data.txt", for x:0 thru 10 do
print (x, x^2, x^3))$
(%i3) data: read_matrix ("data.txt")$
(%i4) plot2d ([discrete, transpose(data)[2], transpose(data)[3]],
Chapter 12: Plotting 221
1000
800
600
y
400
200
0 20 40 60 80 100
x
1.4 experiment
theory
1.2
1
period (s)
0.8
0.6
0.4
0.2
0 10 20 30 40 50
pendulum's length (cm)
Examples.
Plot of a function of two variables:
(%i1) plot3d (u^2 - v^2, [u, -2, 2], [v, -3, 3], [grid, 100, 100],
nomesh_lines)$
u^2-v^2
4
2
0
-2
z
-4
-6
3
-8 2
-10 -2 1
-1.5 -1 0
-0.5 -1 v
0 0.5 1 -2
u 1.5 2 -3
Use of the z option to limit a function that goes to infinity (in this case the function
is minus infinity 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],
nopalette, [color, magenta])$
log(x^2*y^2)
z -2
-4
-6 2
1.5
1
-8 -2 0.5
-1.5 -1 0
-0.5 -0.5 y
0 0.5 -1
x 1 -1.5
1.5 2 -2
The infinite values of z can also be avoided by choosing a grid that does not fall on
any points where the function is undefined, as in the next example, which also shows
how to change the palette and how to include a color bar that relates colors to values
of the z variable:
Chapter 12: Plotting 223
(%i1) plot3d (log (x^2*y^2), [x, -2, 2], [y, -2, 2],[grid, 29, 29],
[palette, [gradient, red, orange, yellow, green]],
color_bar, [xtics, 1], [ytics, 1], [ztics, 4],
[color_bar_tics, 4])$
log(x^2*y^2)
4 0
-4
0
-8
z -4
-12
-8
2
1
-12 -2
0
-1 y
0 -1
x 1
2 -2
Two surfaces in the same plot. Ranges specific to one of the surfaces can be given
by placing each expression and its ranges in a separate list; global ranges for the
complete plot are also given after the function definitions.
(%i1) plot3d ([[-3*x - y, [x, -2, 2], [y, -2, 2]],
4*sin(3*(x^2 + y^2))/(x^2 + y^2), [x, -3, 3], [y, -3, 3]],
[x, -4, 4], [y, -4, 4])$
(4*sin(3*(y^2+x^2)))/(y^2+x^2)
(-y)-3*x
15
10
5
z
0
-5 4
3
2
-10 -4 1
-3 0
-2 -1 -1 y
0 1 -2
x 2 -3
3 4 -4
Parametric function
8
6
4
2
z 0
-2
-4
25
-6 20
15
10
-8-35 5
-30 -25 0
-20 -15 -5 y
-10 -5 -10
-15
x 0 5 -20
10 -25
0.8
0.6
0.4
0.2
z 0
-0.2
-0.4
0.4
-0.6 0.3
0.2
-0.8-0.8 0.1
-0.6 -0.4 0
-0.2 -0.1 y
0 0.2 0.4 -0.2
x -0.3
0.6 0.8 -0.4
z 0
-2
-4
5
4
-6 -6 3
2
-4 1
-2 0
0 -1 y
2 -2
-3
x 4 -4
6-5
3.5
z 2.5
1.5 4
3.5
11 3
1.5 2.5
2 2 y
2.5
3 1.5
x 3.5
4 1
By setting the elevation equal to zero, a surface can be seen as a map in which each
color represents a different level.
(%i1) plot3d (cos (-x^2 + y^3/4), [x,-4,4], [y,-4,4], [zlabel,""],
[mesh_lines_color,false], [elevation,0], [azimuth,0],
color_bar, [grid,80,80], noztics, [color_bar_tics,1])$
cos(y^3/4-x^2)
4 1
3
2
0
1
0 y
-1 -1
-2
-3
-4
-4 -3 -2 -1 0 1 2 3 4
will not be used and the resulting plot will have 1+4*nticks points (see option nticks).
To have more control on the number of points and their positions, a list of points can
be created and then plotted using the discrete method of plot2d.
color_bar [color bar, symbol], color bar, nocolor bar [Plot option]
Default value: false in plot3d, true in mandelbrot and julia
Where symbol can be either true or false. If true, whenever plot3d, mandelbrot
or julia use a palette to represent different values, a box will be shown on the right,
showing the corresponding between colors and values. The single keywords color_bar
and nocolor_bar can be used as synonyms for [color_bar, true] and [color_bar,
false].
Chapter 12: Plotting 229
color_bar_tics [color bar tics, x1, x2, x3], color bar tics, [Plot option]
nocolor bar tics
Defines the values at which a mark and a number will be placed in the color bar. The
first number is the initial value, the second the increments and the third is the last
value where a mark is placed. The second and third numbers can be omitted. When
only one number is given, it will be used as the increment from an initial value that
will be chosen automatically. The single keyword color_bar_tics removes a value
given previously, making the graphic program use its default for the values of the tics
and nocolor_bar_tics will not show any tics on the color bar.
elevation [elevation, number] [Plot option]
Default value: 60
A plot3d plot can be thought of as starting with the x and y axis in the horizontal
and vertical axis, as in plot2d, and the z axis coming out of the screen. The z axis
is then rotated around the x axis through an angle equal to elevation and then the
new xy plane is rotated around the new z axis through an angle azimuth. This option
sets the value for the elevation, in degrees.
See also azimuth.
grid [grid, integer, integer] [Plot option]
Default value: 30, 30
Sets the number of grid points to use in the x- and y-directions for three-dimensional
plotting or for the julia and mandelbrot programs.
For a way to actually draw a grid See grid2d.
grid2d [grid2d, value], grid2d, nogrid2d [Plot option]
Default value: false
Shows a grid of lines on the xy plane. The points where the grid lines are placed are
the same points where tics are marked in the x and y axes, which can be controlled
with the xtics and ytics options. The single keywords grid2d and nogrid2d can
be used as synonyms for [grid2d, true] and [grid2d, false].
See also grid.
iterations [iterations, value] [Plot option]
Default value: 9
Number of iterations made by the programs mandelbrot and julia.
label [label, [string, x, y], . . . ] [Plot option]
Writes one or several labels in the points with x, y coordinates indicated after each
label.
legend [legend, string_1, . . . , string_n], legend, nolegend [Plot option]
It specifies 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,
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. The single
keyword legend removes any previously defined legends, leaving it to the plotting
program to set up a legend. The keyword nolegend is a synonym for [legend,
false].
230 Maxima 5.45.0 Manual
mesh_lines_color [mesh lines color, color], mesh lines color, [Plot option]
no mesh lines
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.
The single keyword mesh_lines_color removes any previously defined colors, leaving
it to the graphic program to decide what color to use. The keyword no_mesh_lines
is a synonym for [mesh_lines_color, false]
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 modified attribute will be rounded modulo 1.
Gnuplot only uses the first 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.
The single keyword palette removes any palette previously defined, leaving it to
the graphic program to decide the palette to use and nopalette is a synonym for
[palette, false].
run_viewer [run viewer, symbol], run viewer, norun viewer [Plot option]
Default value: true
This option is only used when the plot format is gnuplot and the terminal is default
or when the Gnuplot terminal is set to dumb (see gnuplot_term) and can have a true
or false value.
If the terminal is default, a file maxout_xxx.gnuplot (or other name specified with
gnuplot_out_file) is created with the gnuplot commands necessary to generate the
plot. Option run_viewer controls whether or not Gnuplot will be launched to execute
those commands and show the plot.
Chapter 12: Plotting 233
same_xyz [same xyz , value], same xyz, nosame xyz [Plot option]
It can be either true or false. If true, the scales used in the 3 axes of a 3d plot will
be the same. same_xyz and nosame_xyz are synonyms for [same_xyz, true] and
[same_xyz, false].
xtics [xtics, x1, x2, x3], [xtics, false], xtics, noxtics [Plot option]
Defines the values at which a mark and a number will be placed in the x axis. The
first number is the initial value, the second the increments and the third is the last
value where a mark is placed. The second and third numbers can be omitted, in
which case the first number is the increment from an initial value that will be chosen
by the graphic program. If [xtics, false] is used, no marks or numbers will be
shown along the x axis.
Chapter 12: Plotting 235
The single keyword xtics removes any values previously defined, leaving it to the
graphic program to decide the values to use and noxtics is a synonym for [xtics,
false]
ytics [ytics, y1, y2, y3], [ytics, false], ytics, noytics [Plot option]
Defines the values at which a mark and a number will be placed in the y axis. The
first number is the initial value, the second the increments and the third is the last
value where a mark is placed. The second and third numbers can be omitted, in
which case the first number is the increment from an initial value that will be chosen
by the graphic program. If [ytics, false] is used, no marks or numbers will be
shown along the y axis.
The single keyword ytics removes any values previously defined, leaving it to the
graphic program to decide the values to use and noytics is a synonym for [ytics,
false]
ztics [ztics, z1, z2, z3], [ztics, false], ztics, noztics [Plot option]
Defines the values at which a mark and a number will be placed in the z axis. The
first number is the initial value, the second the increments and the third is the last
value where a mark is placed. The second and third numbers can be omitted, in
which case the first number is the increment from an initial value that will be chosen
by the graphic program. If [ztics, false] is used, no marks or numbers will be
shown along the z axis.
The single keyword ztics removes any values previously defined, leaving it to the
graphic program to decide the values to use and noztics is a synonym for [ztics,
false]
(%o1) ["/tmp/sin.gnuplot"]
In this example, gnuplot_maxout_prt(file) is a function that takes the default file
name, file. It constructs a full file name for the data file by interpolating a random 8-
digit integer with a pad of zeros into the default file name. The directory is determined
by maxima_tempdir (it is “/tmp” in this example).
(%i1) gnuplot_maxout_prt(file) := block([beg,end],
[beg,end] : split(file,"."),
printf(false,"~a_~8,'0d.~a",beg,random(10^8-1),end)) $
(%o2) ["/tmp/maxout68715_09606909.gnuplot"]
By default, the script would have been saved in a file named maxoutXXXXX.gnuplot
(XXXXX=68715 in this example).
238 Maxima 5.45.0 Manual
characters such as ^ and are not printed, but interpreted as formatting characters.
For a list of the formatting characters and their meaning, see the documentation for
enhanced in Gnuplot. The default value for this option is false, which will not treat
any characters as formatting characters.
gnuplot_close () [Function]
Closes the pipe to gnuplot which is used with the gnuplot_pipes format.
gnuplot_restart () [Function]
Closes the pipe to gnuplot which is used with the gnuplot_pipes format and opens
a new pipe.
gnuplot_replot [Function]
gnuplot_replot ()
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.
gnuplot_reset () [Function]
Resets the state of gnuplot used with the gnuplot_pipes format. To update the
gnuplot window call gnuplot_replot after gnuplot_reset.
241
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 finding 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 file is simply an area on a particular storage device which contains data or text. Files
on the disks are figuratively grouped into "directories". A directory is just a list of files.
Commands which deal with files 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 file name is passed to functions like plot2d, save, or writefile and the file
name does not include a path, Maxima stores the file in the current working directory.
The current working directory depends on the system like Windows or Linux and on the
installation.
242 Maxima 5.45.0 Manual
The special variable % and the function %th refer to previous results from the interac-
tive interpreter, not results within the file. The file cannot include :lisp constructs.
batchload returns the path of filename, as a string. batchload evaluates its argu-
ment.
See also batch, and load.
closefile () [Function]
Closes the transcript file opened by writefile or appendfile.
file_search [Function]
file_search (filename)
file_search (filename, pathlist)
file_search searches for the file filename and returns the path to the file (as a string)
if it can be found; otherwise file_search returns false. file_search (filename)
searches in the default search directories, which are specified by the file_search_
maxima, file_search_lisp, and file_search_demo variables.
file_search first checks if the actual name passed exists, before attempting to match
it to “wildcard” file search patterns. See file_search_maxima concerning file search
patterns.
The argument filename can be a path and file name, or just a file name, or, if a file
search directory includes a file search pattern, just the base of the file name (without
an extension). For example,
file_search ("/home/wfs/special/zeta.mac");
file_search ("zeta.mac");
file_search ("zeta");
all find the same file, assuming the file exists and /home/wfs/special/###.mac is in
file_search_maxima.
file_search (filename, pathlist) searches only in the directories specified by
pathlist, 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
244 Maxima 5.45.0 Manual
specified, and not any of the default search directories. Even if there is only one
directory in pathlist, it must still be given as an 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.
file_search_maxima [Option variable]
file_search_lisp [Option variable]
file_search_demo [Option variable]
file_search_usage [Option variable]
file_search_tests [Option variable]
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 file maxima-init.mac so that the file search path is assigned automatically
when Maxima starts. See also Section 32.1 [Introduction for Runtime Environment],
page 557.
Multiple filename extensions and multiple paths can be specified 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.
file_type (filename) [Function]
Returns a guess about the content of filename, based on the filename extension.
filename need not refer to an actual file; no attempt is made to open the file and
inspect the content.
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,
Chapter 13: File Input and Output 245
stringout [Function]
stringout (filename, expr_1, expr_2, expr_3, . . . )
stringout (filename, [m, n])
stringout (filename, input)
stringout (filename, functions)
stringout (filename, values)
stringout writes expressions to a file in the same form the expressions would be
typed for input. The file 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 flag file_output_append governs whether stringout appends or trun-
cates the output file. When file_output_append is true, stringout appends to
the output file. Otherwise, stringout truncates the output file. In either case,
stringout creates the file if it does not yet exist.
The general form of stringout writes the values of one or more expressions to the
output file. Note that if an expression is a variable, only the value of the variable is
written and not the name of the variable. As an 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 (filename, [m, n]) writes the values of input labels m
through n, inclusive.
The special form stringout (filename, input) writes all input labels to the file.
The special form stringout (filename, functions) writes all user-defined func-
tions (named by the global list functions)) to the file.
The special form stringout (filename, values) writes all user-assigned variables
(named by the global list values)) to the file. Each variable is printed as an assign-
ment 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.
with_stdout [Function]
with_stdout (f, expr_1, expr_2, expr_3, . . . )
with_stdout (s, expr_1, expr_2, expr_3, . . . )
Evaluates expr 1, expr 2, expr 3, . . . and writes any output thus generated to a file 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 flag file_output_append governs whether with_stdout appends or trun-
cates the output file f. When file_output_append is true, with_stdout appends
to the output file. Otherwise, with_stdout truncates the output file. In either case,
with_stdout creates the file if it does not yet exist.
with_stdout returns the value of its final argument.
See also writefile and display2d.
(%i1) with_stdout ("tmp.out", for i:5 thru 10 do
Chapter 13: File Input and Output 249