411 REFERENCE · Wikibooks
Maxima/Operators
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Maxima Operators
"Standards are great! That's why there are so many of them, and they change so often."
"What once was forbidden is now required."
– Unknown
Mathematical Notation and Operators
Mathematical notation was conceived of by different contributors and adopted over a period of time until the present . Standards are important. They help ensure that efforts are consistent and predictable. But if there are standards for notation, then these tend to be de facto in the absence of some imposed or adopted contextual guidance. Notation is important as this is the means by which mathematical expressions are composed.
Much of what is now considered "standard" notation was in use before the advent of computers and programming software. Software such as Maxima that has as its purpose "doing" at least some of what is meant by "mathematics," must provide the means by which mathematical expressions can be composed. Standard or conventional mathematical notation in general is not well-suited for this purpose.
Hence, there has been the effort to "shoe horn" expressions into a form that is better suited for composing expressions that conforms to software programming syntax, instead of developing software systems that can compose and interpret the full spectrum of existing mathematical expressions, presumably because the former is technically simpler. There has been more success in the form of output expressions in terms of conforming to standard mathematical notation.
Maxima is mostly about mathematical expressions, and these expressions are composed of operators and atoms. Atoms are relatively the simpler ingredient for use in composing expressions – numerical and string data types, but also identifiers, especially those that are not assigned a value, and hence may be considered variables.
Operators are the ingredient where much of the "heavy lifting" occurs with respect to expression composition, and operators need some means to be expressed. Maxima operators are all some sort of "function" (or in Lisp, a procedure) in the programming language sense of the word. This is important to understand. Even something as simple as the expression of a sum is a based on a function.
For example, consider the Maxima expressions:(%i1) e+3;
(%o1) e+3
(%i2) :lisp #$[e+3]$
((MLIST SIMP) ((MPLUS SIMP) 3 $E))
Notice that a sum is simply the Lisp procedure MPLUS. What is true here for the + operator is true in general – operators are either implicitly or explicitly a function in the programming sense of the word. For those used to conventional mathematical notation, this fact can take some getting used to.
What this means in practice when composing Maxima expressions is that the form of the input may often not resemble what looks like conventional mathematical notation regardless of how well the output or value of the expressions represents the form of conventional mathematical notation. Maxima user interfaces such as wxMaxima and GNU TeXmacs are capable of rendering the output of Maxima expressions in a way that represents conventional mathematical notation quite well.
However, once again, the input expressions in these and similar user interfaces always are explicitly and literally composed of Maxima atoms and operators. There is a sense in which then, Maxima imposes an alternative form of mathematical notation for input purposes. This quite simply put is the current state of affairs with respect to doing what Maxima does using a language and syntax that is compatible with computers. Maxima users have to get used to the fact that, in general, they are in a sense constrained to use a different species of mathematical notation for composing input expressions. Operators are the ingredient where this fact becomes most obvious.
There is a last subsection of this section that provides some insight into the issue of conventional mathematical notation and mathematical computer software systems such as Maxima. This subsection is included for those that have an interest.
Maxima Operators
Maxima operators can be considered as belonging to the same categories as expressions:
Mathematical operators
Programming operators
Object operators
The technical details for some of these operators are found in sections of this book devoted to each of these categories of expressions.
It is worth repeating that built-in Maxima operators and operators defined in packages are, for better or worse, often referred to as functions and not operators. This practice can lead to some confusion as there are also user-defined functions in the programming sense of the word, and then there is the mathematical concept of a function. For the sake of clarity and simplicity, in this book, Maxima operators and operators defined in packages are referred to simply as operators.
Having made that point, it should be noted that users can define new operators with specified precedence, remove or kill existing operator properties, or redefine the precedence of existing operators. Refer to the Maxima Documentation (section 9.1 Introduction to operators) for more information.
The general form of most Maxima operators is: foo (args) where args is a comma separated sequence of arguments – zero, one or many. For example:(%i3) to_lisp (); /* an operator with zero arguments */
Type (to-maxima) to restart, ($quit) to quit Maxima.
:LISP-QUIET
NIL
MAXIMA> (to-maxima)
Returning to Maxima
(%o3) true
(%i4) op ([1,arg]); /* an operator with one argument - a list object */
(%o4) [
(%i5) apply(f, [a1, a2, a3]); /* an operator with multiple arguments */
(%o5) f(a1,a2,a3)
/* A list operator ( [ ) with two operators (op and args) as arguments */
(%i6) [op (%i5), args (%i5)];
(%o6) [apply,[f,[a1,a2,a3]]]The operators op(expr) and args(expr) can be useful for checking the "main" operator of expressions and the arguments of expressions.
Operators as Verbs and Nouns
In Maxima, "verbs" are operators that do what is expected – evaluate their arguments and return a value, while "nouns" are inert names of operators that act simply as data or display symbols without any of the evaluations that would otherwise be expected.
Verbs (Evaluation As Expected)
Maxima operators are verbs by default
As verbs, operators evaluate arguments and return a value
Example: diff(x^3, x) evaluates to 2*x^2
Nouns (Inert Names)
Formed by prefixing a single quote ' to an operator (e.g., 'diff or 'integrate) or by using the nounify(f) operator
Operators as nouns can be changed into verbs by applying the verbify(f) operator
Operators as nouns in expressions can be displayed or manipulated by preventing automatic evaluation or simplification
The evaluation flag nouns used with ev causes ev to evaluate nouns in an expression
Example: 'diff(x^2, x) outputs the inert form rather than 2*x
Refer to the Maxima documentation for the technical details of the noun, nouns, nounify, verbify. and noundisp operators and flags
Some Typical Categories, Descriptions and Examples of Maxima Operators
Maxima often-used operators include a colon ( : ) for assignment, := and define() for function definitions, and block() for multi-line code. Examples include assignments, function definitions, loops or conditionals, and object expressions, as exemplified below: A 10 minute tutorial for solving Math problems with Maxima https://mathblog.com/a-10-minute-tutorial-for-solving-math-problems-with-maxima/Introduction to Maxima for STACK users https://docs.stack-assessment.org/en/CAS/Maxima_background/Maxima Programming https://maxima.sourceforge.io/docs/tutorial/en/gaertner-tutorial-revision/Pages/Programming0002.htm
Variable Assignment and Basic Math Expression Operators:
a : 5; — assigns the value 5 to the name a using a single colon.
poly : expand((x + y)^3); — expands a binomial expression and assigns the value to the name poly.
subst(x = 2, x^2 + y); — substitutes a value into an algebraic expression. Introduction to Maxima https://maxima.sourceforge.io/docs/manual/Introduction-to-Maxima.html
User-Defined Functions and Built-In Operator Expressions:
f(x) := x^2 - 3*x + 2; — defines a single-line function using the := operator.
integrate(f(x), x, 0, 1); — the definite integral of the expression f(x) from 0 to 1.
diff(f(x), x, 2); — calculates the second derivative of f(x) with respect to x. Introduction to Maxima https://maxima.sourceforge.io/docs/manual/intromax.pdfHow to Navigate Maxima and Minima in Machine Learning Optimization https://medium.com/@bragadeeshs/how-to-navigate-maxima-and-minima-in-machine-learning-optimization-5eee9bc67303Customize your CASL code with built-in and user-defined functions https://blogs.sas.com/content/sgf/2018/11/13/customize-your-casl-code-with-built-in-and-user-defined-functions/
Control Flow and Block Programming Operator Expressions:
if x > 0 then print("Positive") else print("Non-positive");— conditional branching expression.
for i : 1 thru 5 do display(i^2); — a standard loop iterating from 1 to 5.
block([s : 0], for i : 1 thru 10 do s : s + i, s); — a local variable block operator that sums numbers from 1 to 10 and returns the final value s. Maxima Expressions https://maths.cnam.fr/Membres/wilk/MathMax/help/Maxima/maxima_6.html
Object Operator Expressions:
Lists and Sets: [1, 2, x, y] builds a list object, while {a, b, c} denotes a set object.
Matrices: matrix([1, 2], [3, 4]) defines a 2x2 matrix object using nested rows of list objects. Introduction to Maxima for STACK users https://moodle.hft-stuttgart.de/question/type/stack/doc/doc.php/CAS/Maxima_background.mdIntroduction to Maxima for STACK users https://docs.stack-assessment.org/en/CAS/Maxima_background/Maxima Expressions https://maxima.sourceforge.io/docs/manual/Expressions.htmlMinimal Maxima https://maxima.sourceforge.io/docs/tutorial/en/minimal-maxima.pdf
Some Additional Examples of Maxima Operators
Mathematical Operators:
(%i7) subst(x = 2, x^2 + y);
(%o7) y+4
(%i8) 40^40/100^20;
(%o8) 1208925819614629174706176
(%i9) factor(%);
(%o9) 2^80
(%i10) diff((a+2)/(a+x),x,1);
(%o10) -((a+2)/(x+a)^2)
(%i11) %,x=2;
(%o11) -(1/(a+2))
(%i12) simp:false;
(simp) false
(%i13) %e^(%i*%pi)+1=0;
(%o13) %e^(%i*%pi)+1=0
(%i14) simp:true;
(simp) true
(%i15) 'integrate(%e^(-x^2),x);
(%o15) integrate(%e^(-x^2),x)
(%i16) test(f):=block([u],u:integrate(f,x),ratsimp(f-diff(u,x)))
(%o16) test(f):=block([u],u:integrate(f,x),ratsimp(f-'diff(u,x)))
(%i17) test(sin(x))
(%o17) 0
(%i18) test(1/(1+x))
(%o18) 0
(%i19) test(1/(1+x^2))
(%o19) 0
(%i20) integrate(sin(x)^3,x)
(%o20) cos(x)^3/3-cos(x)
(%i21) kill(q)$
(%i22) integrate(%e^x/(%e^x+2),x)
(%o22) log(%e^x+2)
(%i23) integrate(1/(x*log(x)),x)
(%o23) log(log(x))
(%i24) integrate(sin(2*x+3),x)
(%o24) -(cos(2*x+3)/2)
(%i25) integrate(%e^x*erf(x),x)
(%o25) %e^x*erf(x)-%e^(1/4)*erf(x-1/2)
(%i26) integrate(x/(x^3+1),x)
(%o26) log(x^2-x+1)/6+atan((2*x-1)/sqrt(3))/sqrt(3)-log(x+1)/3
(%i27) diff(%,x)
(%o27) 2/(3*((2*x-1)^2/3+1))+(2*x-1)/(6*(x^2-x+1))-1/(3*(x+1))
(%i28) ratsimp(%)
(%o28) x/(x^3+1)
(%i29) integrate(x^(5/4)/(x+1)^(5/2),x,0,inf)
(%o29) beta(1/4,9/4)
(%i30) gradef(q(x),sin(x^2))
(%o30) q(x)
(%i31) diff(log(q(r(x))),x)
(%o31) (('diff(r(x),x))*sin(r(x)^2))/q(r(x))
(%i32) integrate(%,x)
(%o32) log(q(r(x)))
Programming Operators:
(%i33) for c:2 next 3*c thru 20 do display (c)$
c=2
c=6
c=18
(%i34) for i:1 thru 10 do if i=3 then return(i);
(%o34) 3
(%i35) t:0$
(%i36) for i:1 while i <= 15 do t:2*t+i;
(%o36) done
(%i37) t;
(%o37) 65519
(%i38) fib[n]:=if n=1 or n=2 then 1 else fib[n-1]+fib[n-2];
(%o38) fib[n]:=if n=1 or n=2 then 1 else fib[n-1]+fib[n-2]
(%i38) fib[1]+fib[2];
(%o38) 2
(%i39) fib[3];
(%o39) 2
(%i40) fib[5];
(%o40) 5
(%i41) eta(mu,nu):=if mu=nu then mu else (if mu>nu then mu-nu else mu+nu);
(%o41) eta(mu,nu):=if mu=nu then mu else if mu>nu then mu-nu else mu+nu
(%i42) eta(5,6);
(%o42) 11
(%i43) eta(eta(7,7),eta(1,2));
(%o43) 4
(%i44) if not 5 >= 2 and 6 <= 5 or 4+1 > 3 then a else b;
(%o44) a
Object Operators:
/* List Objects */
(%i1) my_list: [1, 2, 3, 4, 5];
(my_list) [1,2,3,4,5]
(%i2) op(my_list);
(%o2) "["
(%i3) p:[1,1,2,x^2];
(p) [1,1,2,x^2]
(%i4) args(p);
(%o4) [1,1,2,x^2]
(%i5) nested: [1, [2, 3], [4, [5, 6]]];
(nested) [1,[2,3],[4,[5,6]]]
(%i7) nested[3];
(%o7) [4,[5,6]]
(%i8) op(%);
(%o8) "["
(%i9) first(my_list);
(%o9) 1
(%i10) third(my_list);
(%o10) 3
(%i11) last(my_list);
(%o11) 5
(%i12) L: create_list(i * x, x, [a, b, c], i, [1, 2, 3, 4]);
(L) [a,2*a,3*a,4*a,b,2*b,3*b,4*b,c,2*c,3*c,4*c]
(%i13) apply("+", [1, 2, 3]);
(%o13) 6
(%i17) args('apply("+", [1, 2, 3]));
(%o17) ["+",[1,2,3]]
(%i18) %[2];
(%o18) [1,2,3]
(%i19) A(s):=(3*sqrt(3)/2)*s^2$
(%i20) map(A,my_list);
(%o20) [3^(3/2)/2,2*3^(3/2),3^(7/2)/2,8*3^(3/2),(25*3^(3/2))/2]
/* Declared Arrays */
(%i23) array (y, fixnum, 3);
(%o23) y
(%i25) arrayinfo(y);
(%o25) [complete,1,[3]]
(%i24) array(M, flonum, 3, 3);
(%o24) M
(%i26) arrayinfo(M);
(%o26) [complete,2,[3,3]]
(%i27) y[2]: %pi;
(y[2]) %pi
(%i28) y[3]: %e;
(y[3]) %e
(%i29) listarray(y);
(%o29) [0,0,%pi,%e]
/* Hashed (undeclared) Arrays */
(%i30) a_hashed_array[8] : 998;
(a_hashed_array[8]) 998
(%i31) arrayinfo(a_hashed_array);
(%o31) [hashed,1,[8]]
(%i32) listarray(a_hashed_array);
(%o32) [998]
(%i33) a_hashed_array[12] : x^2;
(a_hashed_array[12]) x^2
(%i34) listarray(a_hashed_array);
(%o34) [998,x^2]
(%i35) another_hashed_array[3^(1/3)]:1;
(%o35) 1
(%i36) arrayinfo(another_hashed_array);
(%o36) [hashed,1,[3^(1/3)]]
(%i37) subvarp (another_hashed_array[1]);
(%o37) true
(%i38) remarray (y,another_hashed_array);
(%o38) [y,another_hashed_array]
/* Lisp Arrays */
(%i39) :lisp (defvar $lisparray (make-array '(3 3) :initial-element 0.0))
$LISPARRAY
(%i40) :lisp (setq $lisparray (make-array '(3 3) :initial-element 0.0))
#2A((0.0 0.0 0.0) (0.0 0.0 0.0) (0.0 0.0 0.0))
(%i41) arrayinfo(lisparray);
(%o41) [declared,2,[2,2]]
(%i42) :lisp (aref $lisparray 0 0)
0.0
(%i42) :lisp (aref $lisparray 2 2)
0.0
(%i43) lisparray[2,2]:77;
(%o43) 77
(%i44) :lisp (aref $lisparray 2 2)
77
(%i45) :lisp (setf (aref $lisparray 2 2) 88)
88
(%i46) :lisp (aref $lisparray 2 2)
88
(%i47) :lisp (defvar $lisparray2 (make-array '(2 3) :initial-contents '((1 2 3) (4 5 6))))
$LISPARRAY2
(%i48) listarray(lisparray2);
(%o48) [1,2,3,4,5,6]
(%i49) :lisp (write $lisparray2)
#2A((1 2 3) (4 5 6))
#2A((1 2 3) (4 5 6))
/* Structures */
(%i50) defstruct(vector3d(x, y, z));
(%o50) [vector3d(x,y,z)]
(%i51) v1:new(vector3d(1.5, -2.0, 3.2));
(v1) vector3d(x=1.5,y=-2.0,z=3.2)
(%i52) v2:vector3d(x = 5, y = 10, z = 15);
(v2) vector3d(x=(x=5),y=(y=10),z=(z=15))
(%i53) v1@x;
(%o53) 1.5
(%i54) v2@z : 7.4;
(%o54) 7.4
Official documentation and guides for operators are available through the Maxima Manual and the Maxima SourceForge Documentation Hub.
Some Information Related to Mathematical Notation
There is no single, universal standard that dictates mathematical notation across all branches of math. Instead, notation varies by discipline, publisher, and sub-field. There are widely accepted conventions and formal frameworks that serve as references. The general topic of mathematical notation is beyond the scope of this book. However, mathematical notation does have some relevance in the context of Maxima as a computer algebra system.
Stephen Wolfram’s perspective in Mathematical Notation: Past and Future traces how symbols evolved from static, human-readable shorthand into active, executable computational language. The historical development moved from additive numerals and natural language prose toward structured operators and variables, while the future shifts toward programmatic, interactive, and "computable" expressions. Mathematical Notation: Past and Future (2000) https://www.stephenwolfram.com/publications/mathematical-notation-past-future/ Quick Notes on Wolfram’s “Mathematic Notation: Past and Future” https://lukegilson.co/2020/04/05/quick-notes-on-wolframs-mathematic-notation-past-and-future/Notes: Mathematical notation https://www.wolframscience.com/nks/notes-12-10--mathematical-notation/Our Mission and the Opportunity of Artifacts from the Future https://writings.stephenwolfram.com/2020/10/our-mission-and-the-opportunity-of-artifacts-from-the-future/
The Past of Mathematical Notation:
Evolution of Symbols: Early counting relied on unary notches and additive systems (like Egyptian hieroglyphs), eventually shifting to Hindu-Arabic base-10 positional numerals.Antique Notations https://library.wolfram.com/infocenter/Demos/4952/
Introduction of Operators: Algebraic variables, plus/minus signs, and calculus notations (such as Leibniz's Dropping In on Gottfried Leibniz https://writings.stephenwolfram.com/2013/05/dropping-in-on-gottfried-leibniz/ and ) emerged primarily during the 16th and 17th centuries to replace cumbersome natural language descriptions.
Standardization Limits: Traditional notation worked well for manual formula writing, but lacked any native capability to generalize into automated, multi-step computations or algorithmic processes. Opinion 64: Make New (Kinds of) Science But Keep the Old, One is Silver, the Other Gold [and their Fusion is Platinum] https://sites.math.rutgers.edu/~zeilberg/Opinion64.html
The Future of Mathematical Notation:
Computational Language: Transitioning from passive text on paper to active, uniform symbolic structures.
Programmatic Models: Replacing traditional passive equations with active programs capable of executing models across physics, biology, and social sciences. Exploring the computational universe with Stephen Wolfram https://physicsworld.com/a/exploring-the-computational-universe-with-stephen-wolfram/
Universal Access: Utilizing interactive, graphical, and automated systems to democratize complex technical thinking much like mass literacy changed society centuries ago.
[1-13] https://www.stephenwolfram.com/publications/mathematical-notation-past-future/
[2-14] https://lukegilson.co/2020/04/05/quick-notes-on-wolframs-mathematic-notation-past-and-future/
[3-15] https://www.wolframscience.com/nks/notes-12-10--mathematical-notation/
[4-16] https://writings.stephenwolfram.com/2020/10/our-mission-and-the-opportunity-of-artifacts-from-the-future/
[5-17] https://library.wolfram.com/infocenter/Demos/4952/
[6-18] https://writings.stephenwolfram.com/2013/05/dropping-in-on-gottfried-leibniz/
[7-19] https://sites.math.rutgers.edu/~zeilberg/Opinion64.html
[8-20] https://physicsworld.com/a/exploring-the-computational-universe-with-stephen-wolfram/
The Future of Notation: Read Stephen Wolfram's Mathematical Notation: Past and Future to learn how the history of notation shapes modern computation. "Now I have to tell you that I had always assumed that mathematical notation was too haphazard to be used as any kind of thing that a computer could reasonably interpret in a rigorous way. But at the beginning of the 1990s we got interested in making Mathematica be able to interact with mathematical notation. And so we realized that we really had to figure out what was going on with mathematical notation.
Neil Soiffer had spent quite a number of years working on editing and interpreting mathematical notation, and when he joined our company in 1991, he started trying to convince me that one really could work with mathematical notation in a reasonable way, for both output and input.
The output side was pretty straightforward: after all, TROFF and TeX already did a moderately good job with that.
The issue was input.
Well, actually, one already learned something from output. One learned that at least at some level, a lot of mathematical notation could be represented in some kind of context-free form. Because one knew that in TeX, for instance, one could set things up in a tree of nested boxes.
But how about input? Well, one of the biggest things was something that always comes up in parsing: if you have a string of text, with operands and operators, how do you tell what groups with what?"
– Stephen Wolfram
0%