# Maxima/Printable version

The current, editable version of this book is available in Wikibooks, the open-content textbooks collection, at
https://en.wikibooks.org/wiki/Maxima

# Weaknesses of math software

While Maxima is a very useful software, it suffers from the same issues faced by many other math programs.
* The limit of a discontinuous function at the point of discontinuity
* Branch cuts
* Zero-recognition
* Keeping track of domains of validity

## References

* ↑ Stackexchange : What are well-known weaknesses of CAS/math software?
* ↑ R Fateman : Branch Cuts in Computer Algebra,

# Methods of use

Maxima is flexible software, and can be used with a number of different methods:
* online , without installation
* offline = after installation
** Graphical User Interface (GUI)
** from console ( without GUI)
*** interactive ( also one can load program files using load or bash function)
*** bash mode
Run maxima, use program c.mac and save output to c.txt file:

## References

* ↑ Maxima CAS online by CESGA

# Installation
## Dependencies

* gnuplot,
* tex
** texinfo
** texi2html
** texlive-latex-recommended
* GNU autotools
** automake 1.9
** autoconf2.13
* tk 8.4.
* lisp
** sbcl ( sudo apt-get install sbcl)
* libgmp3-dev
* libreadline5-dev
* libncurses5-dev
* sharutils
* libxmu-dev
* libxaw7-dev
* wxWidgets library for wxMaxima
** libwxgtk3.0-dev
** libwxbase3.0-dev
* compiler is GNU g++ for wxWidgets library
* build-essential
* imagemagick
* ibus-gtk
* ibus-gtk3

## Steps

* Download and install ready made Maxima deb packages
** from Ubuntu repositories ( old versions )
** from other sites
* Compile your own maxima package
* compile maxima from sources ( without creating deb packages )
Now the best is a git method

## From Ubuntu repositories

You can make use of :
* Synaptic ( Graphical package manager)
* apt-get.
In second case write in command line:
This method can get old version which gets some trouble, like
Uninstall such Maxima version

## From PPA
### wxmaxima

From repositiories by Istvan Balhota

## From sources

Before compilation, you should have all dependent packages

### CVS

This procedure does not create a deb package.

### Using git
#### maxima/xmaxima

If you have git and SBCL then :
Now one can run it from inside the source directory.
The result :
Xmaxima can also be run :
or bash file :
wxMaxima is not present now.
Where is Maxima after standard ( as above) installation ?
example result :
Note that it is a different directory then after apt-get installation. One can have 2 ( or more ) versions of Maxima on the disk )

#### wxmaxima
## Problems

* Open a terminal
* type : sudo apt-get install gdb
* after gdb is installed type : gdb wxmaxima
* run and wait until it crashes
* and type : backtrace

## References

* ↑ compiled deb packages for Maxima 5.20.1-1 by Istvan Blahota
* ↑ help from ubuntu community about Maxima
* ↑ How to build your own Maxima package by Andras Somogyi
* ↑ Install from Ubuntu repositories by Mario Rodriguez Riotorto
* ↑ launchpad : blahota wxmaxima
* ↑ How to build Maxima by Rupert Swarbrick

# Symbols

* symbols %z7 and %z9 represent any arbitrary integer value.

# Operators

"=" means syntactic equality. Check : is(equal(a,b))

# Names
## References

* ↑ Maxima by Example: Ch. 1, Introduction to Maxima by Edwin L. Woollett

# Objects

* atom
** number
** name
** string
* list of atoms

# Variables

* global
** global variables category
* local

# Data types

* Numbers
* Strings
* Constants
* Lists
* Arrays
* Structures

# Features

Maxima recognizes certain mathematical properties of:
* functions and variables
* system. There is a list of non-mathematical, system-dependent features. See status.
which called features.
The predicate
returns true if x has the foo property, and false otherwise.
The infolist features is a list of known features. These are
plus any user-defined features.
features is a list of mathematical features.
Example:

## Declare

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.
* antisymmetric, commutative, symmetric : Tells Maxima to recognize a_i as a symmetric or antisymmetric function. commutative is the same as symmetric.
* bindtest : Tells Maxima to trigger an error when a_i is evaluated unbound.
* constant : Tells Maxima to consider a_i a symbolic constant.
* even, odd : Tells Maxima to recognize a_i as an even or odd integer variable.
* evenfun, oddfun : Tells Maxima to recognize a_i as an odd or even function.
* evflag : Makes a_i known to the ev function so that a_i is bound to true during the execution of ev when a_i appears as a flag argument of ev. See evflag.
* evfun : Makes a_i known to ev so that the function named by a_i is applied when a_i appears as a flag argument of ev. See evfun.
* feature : Tells Maxima to recognize a_i as the name of a feature. Other atoms may then be declared to have the a_i property.
* increasing, decreasing : Tells Maxima to recognize a_i as an increasing or decreasing function.
* integer, noninteger : Tells Maxima to recognize a_i as an integer or noninteger variable.
* integervalued : Tells Maxima to recognize a_i as an integer-valued function.
* lassociative, rassociative : Tells Maxima to recognize a_i as a right-associative or left-associative function.
* linear : Equivalent to declaring a_i both outative and additive.
* mainvar : Tells Maxima to consider a_i a "main variable". A main variable succeeds all other constants and variables in the canonical ordering of Maxima expressions, as determined by ordergreatp.
* multiplicative : Tells Maxima to simplify a_i expressions by the substitution a_i(x * y * z * ...) --> a_i(x) * a_i(y) * a_i(z) * .... The substitution is carried out on the first argument only.
* nary : Tells Maxima to recognize a_i as an n-ary function. The nary declaration is not the same as calling the nary function. The sole effect of declare(foo, 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).
* nonarray : Tells Maxima to consider a_i not an array. This declaration prevents multiple evaluation of a subscripted variable name.
* nonscalar : Tells Maxima to consider a_i a nonscalar variable. The usual application is to declare a variable as a symbolic vector or matrix.
* noun : Tells Maxima to parse a_i as a noun. The 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 variable.
* scalar : Tells Maxima to consider a_i a scalar variable.
Declare tells:
* evenp
* oddp
* integerp
* and so on
what to return.
Compare with:
* mode_decalre

# Numbers
## Number types
### Binary numbers
### Complex numbers
#### Argument

Principial value of argument of complex number in turns carg produces results in the range (-pi, pi] . It can be mapped to [0, 2*pi) by adding 2*pi to the negative values
On can order list of complex points according to it's argument :

### rational numbers

* rat
* ratp
Rationalize with limit denominator:

## Predicate functions

Compare :
List of predicate functions ( see p at the end ) :
* abasep
* alphacharp
* alphanumericp
* atom
* bfloatp
* blockmatrixp
* cequal
* cequalignore
* cgreaterp
* cgreaterpignore
* charp
* clessp
* clesspignore
* complex_number_p from to_poly package
* constantp
* constituent
* diagmatrixp
* digitcharp
* disjointp
* elementp
* emptyp
* evenp
* featurep
* floatnump ( compare : isreal_p)
* if
* integerp
* intervalp
* is
* isreal_p from to_poly package
* lcharp
* listp
* listp
* lowercasep
* mapatom
* matrixp
* matrixp
* maybe
* member
* nonnegintegerp
* nonscalarp
* numberp
* oddp
* operatorp
* ordergreatp
* orderlessp
* picture_equalp
* picturep
* poly_depends_p
* poly_grobner_subsetp
* polynomialp
* prederror
* primep
* ratnump
* ratp
* scalarp
* sequal
* sequalignore
* setequalp
* setp
* stringp
* subsetp
* subvarp
* symbolp
* symmetricp
* taylorp
* unknown
* uppercasep
* zeroequiv
* zeromatrixp
* zn_primroot_p
See also :
* declare
** property:
*** rational, irrational, real, imaginary, complex,
*** even, odd,
*** decreasing, increasing
*** evenfun, oddfun

## Number Theory

There are functions and operators useful with integer numbers

### Elementary number theory

In Maxima there are some elementary functions like the factorial n! and the double factorial n!! defined as ${\frac {n!}{k!}}$ where $k$ is the greatest integer less than or equal to $n/2$

#### Divisibility

Some of the most important functions for integer numbers have to do with divisibility:
all of them well documented in help. you can view it with the '?' command.
Function ifactors takes positive integer and returns a list of pairs : prime factor and its exponent. For example :
It means that : $8=2^{3}\,$

#### Other Functions

Continuus fractions :

# Functions
## Definition

For mathematical functions use always
instead of
There is only one small difference between them:
"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 '')."
"Defines a function named f with arguments x_1, …, x_n and function body expr. define always evaluates its second argument (unless explicitly quoted). "

## return

"return doesn't mean the same thing in Maxima as it does in other programming languages. It means only to return a value from a block; that's not enough for what you need here." Robert Dodier
If you wish to make a return from some expression inside the function then you must use block and return.
is itself an expression, and so could take the place of the right hand side of a function definition. Here it may happen that the return happens earlier than the last expression.

## Local variables

The first in the block, may contain a list of variables and variable assignments, such as [a: 3, b, c:], which would cause the three variables a,b,and c to not refer to their global values, but rather have these special values for as long as the code executes inside the block, or inside functions called from inside the block. This is called dynamic binding, since the variables last from the start of the block to the time it exits. Once you return from the block, or throw out of it, the old values (if any) of the variables will be restored. It is certainly a good idea to protect your variables in this way. Note that the assignments in the block variables, are done in parallel. This means, that if you had used c: a in the above, the value of c would have been the value of a at the time you just entered the block, but before a was bound. Thus doing something like:
will protect the external value of a from being altered, but would let you access what that value was. Thus the right hand side of the assignments, is evaluated in the entering context, before any binding occurs. Using just block ([x], ...) would cause the x to have itself as value, just as if it would have if you entered a fresh Maxima session.
See also description by Darren Irvine

## compile

* "The modedeclare statement is important for compiled code
* Compiling can greatly speed numerical code; for mostly symbolic code, the speed up is not great.
* There are some differences between compiled and uncompiled code -- be careful." Barton Willis

### mode_declare

"mode_declare tells the compiler that the compiled code needs not to be generic enough to be able to deal with all kind of objects. If your function only takes floats, but no symbolic arguments the compiled code might run much faster." Gunter Königsmann

## diff
### implicit
# Debugging
## Directories

Start Maxima and type the command:
this will tell you the directory that is being used as your user directory.

## infolists

* is a system variable
* Default value:
* is a list of the names of all of the information lists in Maxima. These are
** labels : All bound %i, %o, and %t labels.
** values : All bound atoms which are user variables, not Maxima options or switches, created by : or :: or functional binding.
** functions : All user-defined functions, created by := or define.
** arrays : All declared and undeclared arrays, created by :, ::, or :=.
** macros : All user-defined macro functions, created by ::=.
** myoptions : All options ever reset by the user (whether or not they are later reset to their default values).
** rules : All user-defined pattern matching and simplification rules, created by tellsimp, tellsimpafter, defmatch, or defrule.
** aliases : All atoms which have a 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.
** 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.)

## reset

reset : resets many (global) system variables
Use:
example output :

## trace

In Maxima :

## manual debugging

print partial results using :
* print
* playback

## values

values:
* is a system variable
* is a list ... which contains the names of currently assigned scalar values which have been set by:
** the user interactively
** by packages which have been loaded"
* initial value is

## dependencies

dependencies :
* is a system variable
* is the list of atoms which have functional dependencies, assigned by:
** depends
** the function dependencies
** gradef

## status

example output:

# Data structures

"Maxima's current array/matrix semantics are a mess, I must say, with at least four different kinds of object (hasharrays, explicit lists, explicit matrices, Lisp arrays) supporting subscripting with varying semantics. "
"Maxima's concept of arrays, lists, and matrices is pretty confused, since various ideas have accreted in the many years of the project... Yes, this is a mess. Sorry about that. These are all interesting ideas, but there is no unifying framework. "

## Array

Maxima has two array types :
* Undeclared arrays ( implemented as Lisp hash tables )
* Declared arrays ( implemented as Lisp arrays )
** created by the array function
** created by the make_array function.
Category: Arrays :
* array
* arrayapply
* arrayinfo
* arraymake
* arrays - global variable
* fillarray
* listarray
* make_array
* rearray
* remarray
* subvar
* use_fast_arrays
See also :
* array functions defined by := and define.

### Undeclared array

Assignment creates an undeclared array.
"If the user assigns to a subscripted variable before declaring the corresponding array, an undeclared array is created. Undeclared arrays, otherwise known as hashed arrays (because hash coding is done on the subscripts), are more general than declared arrays. The user does not declare their maximum size, and they grow dynamically by hashing as more elements are assigned values. The subscripts of undeclared arrays need not even be numbers. However, unless an array is rather sparse, it is probably more efficient to declare it when possible than to leave it undeclared. " ( from Maxima CAS doc)
"created if one does :
(and b is not already an array, a list, or a matrix - if it were one of these an error would be caused since x+1 would not be a valid subscript for an art-q array, a list or a matrix).
Its indices (also known as keys) may be any object. It only takes one key at a time (b[x+1,u]:y would ignore the u). Referencing is done by b[x+1] ==> y^2. Of course the key may be a list, e.g.
would be valid. "( from Maxima CAS doc)

### Declared array

* declare array ( give a name and allocate memmory)
* fill array
* process array

#### array function

Creates an n-dimensional array. Here :
* type can be fixnum for integers of limited size or flonum for floating-point numbers
* n may be less than or equal to 5. The subscripts for the i'th dimension are the integers running from 0 to dim_i.
Because subscripts of array A elements are goes from 0 to dim so array A has :
elements.
The array function can be used to transform an undeclared array into a declared array.

#### arraymake function

The result is an unevaluated array reference.

#### Function: make_array

Creates and returns a Lisp array.
Type may be :
* any
* flonum
* fixnum
* hashed
* functional.
There are n indices, and the i'th index runs from 0 to dim_i - 1.
The advantage of make_array over array is that the return value doesn't have a name, and once a pointer to it goes away, it will also go away. For example, if y: make_array (...) then y points to an object which takes up space, but after y: false, y no longer points to that object, so the object can be garbage collected.
Examples:

## List

Assignment to an element of a list.
Interesting examples by Burkhard Bunk :
Category: Lists :
* append
* assoc
* cons
* copylist
* create_list
* delete
* eighth
* endcons
* fifth
* first
* flatten
* fourth
* fullsetify
* join
* last
* length
* listarith
* listp
* lmax
* lmin
* lreduce
* makelist
* member
* ninth
* permut
* permutations
* pop
* push
* random_permutation
* rest
* reverse
* rreduce
* second
* setify
* seventh
* sixth
* some
* sort
* sublist
* sublist_indices
* tenth
* third
* tree_reduce
* xreduce

## Matrix

"In Maxima, a matrix is implemented as a nested list (namely a list of rows of the matrix)". E.g. :
Construction of matrices from nested lists :
Interesting examples by Burkhard Bunk :
Reference to elements etc:
Element by element operations:
Matrix operations :
Category: Matrices :
* addcol
* addrow
* adjoint
* augcoefmatrix
* cauchy_matrix
* charpoly
* coefmatrix
* col
* columnvector
* covect
* copymatrix
* determinant
* detout
* diag
* diagmatrix
* doallmxops
* domxexpt
* domxmxops
* domxnctimes
* doscmxops
* doscmxplus
* echelon
* eigen
* ematrix
* entermatrix
* genmatrix
* ident
* invert
* list_matrix_entries
* lmxchar
* matrix
* matrix_element_add
* matrix_element_mult
* matrix_element_transpose
* matrixmap
* matrixp
* mattrace
* minor
* ncharpoly
* newdet
* nonscalar
* nonscalarp
* permanent
* rank
* ratmx
* row
* scalarmatrixp
* scalarp
* setelmx
* sparse
* submatrix
* tracematrix
* transpose
* triangularize
* zeromatrix

### Function: matrix

Returns a rectangular matrix which has the rows row_1, …, row_n. Each row is a list of expressions. All rows must be the same length.

### . 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.
This distinguishes it plainly from a decimal point in a floating point number.
The operator . represents noncommutative multiplication and scalar product. When the operands are 1-column or 1-row matrices a and b, the expression a.b is equivalent to sum (a[i]*b[i], i, 1, length(a)). If a and b are not complex, this is the scalar product, also called the inner product or dot product, of a and b. The scalar product is defined as conjugate(a).b when a and b are complex; innerproduct in the eigen package provides the complex scalar product.
When the operands are more general matrices, the product is the matrix product a and b. The number of rows of b must equal the number of columns of a, and the result has number of rows equal to the number of rows of a and number of columns equal to the number of columns of b.
To distinguish . as an arithmetic operator from the decimal point in a floating point number, it may be necessary to leave spaces on either side. For example, 5.e3 is 5000.0 but 5 . e3 is 5 times e3.
There are several flags which govern the simplification of expressions involving ., namely dot0nscsimp, dot0simp, dot1simp, dotassoc, dotconstrules, dotdistrib, dotexptsimp, dotident, and dotscrules." ( from Maxima CAS doc)

## Vectors

Category: Vectors :
* Vectors
* eigen
* express
* nonscalar
* nonscalarp
* scalarp
Category: Package vect
* vect
* scalefactors
* vect_cross
* vectorpotential
* vectorsimp

# Numerical methods
## Newton method

Functions
* newton for equation with function of one variable
* mnewton is an implementation of Newton's method for solving nonlinear equations in one or more variables.

### newton

load :
Code :

### mnewton

One can use Newton method for solving systems of multiple nonlinear functions. It is implemented in mnewton function. See directory :
which uses linsolve_by_lu defined in :
See this image for more code.

# Algorithms
## Stack ( LIFO)

Stack implementation using list:

# Plots
## Complex Functions

* Visualizing Complex Functions with Conformal Mapping ( themaximalist )

### Topologist's sine curve

Topologist's comb :

# Outputs and warnings

* ratprint : false; /* remove "rat :replaced " */
* using $ instead of ; at the end of the line ( not inside function where , ends the line )
* return from the function
* "warning: encountered undefined variable ... in translation." This is warning from compile when function uses global variable without using in in tha arguments list. You have to include the variables in the function's list

# Example programs

* Iteration of complex numbers, stack and drawing a list of points
* Iteration of complex numbers, comparing complex numbers, finding period of cycle
* Drawing Julia set and critical orbit. Computing period
* drawing curves in 2D plane
* drawing points

# Help
### bash

* info maxima

### Maxima commands

* dependencies
* infolists
* describe
* ↑ stackoverflow question : rationalize-number-with-limit-denominator
* ↑ maxima manual : Category Declarations-and-inferences
* ↑ Discussion at Maxima interest list
* ↑ stackoverflow question : difference-between-throw-return-and-break-in-maxima
* ↑ Darren Irvine : local-variables-function-parameters
* ↑ maxima-discuss : compiling-files-written-in-maxima
* ↑ [Maxima] Phantastic Program! One bug - discussion
* ↑ Maxima by Example: Ch. 1, Introduction to Maxima ∗ Edwin L. Woollett August 11, 2009
* ↑ Maxima: Syntax improvements by Stavros Macrakis
* ↑ Maxima: what does Maxima call an “array”? - answer by Robert Dodier
* ↑ the Maxima mailing list : [Maxima] array and matrix? - answer by Robert Dodier
* ↑ Maxima Overview by Burkhard Bunk
* ↑ the Maxima mailing list : [Maxima] array and matrix? - answer by Robert Dodier
* ↑ Maxima Overview by Burkhard Bunk
* ↑ maxima manual : Category Matrices
* ↑ maxima manual : Package vect
* ↑ themaximalist visualizing-complex-functions-by-their-images-over-concentric-circles