File: maxima_45.html

package info (click to toggle)
maxima 5.47.0-9
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 193,104 kB
  • sloc: lisp: 434,678; fortran: 14,665; tcl: 10,990; sh: 4,577; makefile: 2,763; ansic: 447; java: 328; python: 262; perl: 201; xml: 60; awk: 28; sed: 15; javascript: 2
file content (275 lines) | stat: -rw-r--r-- 17,433 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
<head>
<title>Maxima 5.47.0 Manual: Introduction to Simplification</title>

<meta name="description" content="Maxima 5.47.0 Manual: Introduction to Simplification">
<meta name="keywords" content="Maxima 5.47.0 Manual: Introduction to Simplification">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="maxima_toc.html#Top" rel="start" title="Top">
<link href="maxima_423.html#Function-and-Variable-Index" rel="index" title="Function and Variable Index">
<link href="maxima_toc.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="maxima_44.html#Simplification" rel="up" title="Simplification">
<link href="maxima_46.html#Functions-and-Variables-for-Simplification" rel="next" title="Functions and Variables for Simplification">
<link href="maxima_44.html#Simplification" rel="previous" title="Simplification">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
body {color: black; background: white;  margin-left: 8%; margin-right: 13%;
      font-family: "FreeSans", sans-serif}
h1 {font-size: 150%; font-family: "FreeSans", sans-serif}
h2 {font-size: 125%; font-family: "FreeSans", sans-serif}
h3 {font-size: 100%; font-family: "FreeSans", sans-serif}
a[href] {color: rgb(0,0,255); text-decoration: none;}
a[href]:hover {background: rgb(220,220,220);}
div.textbox {border: solid; border-width: thin; padding-top: 1em;
    padding-bottom: 1em; padding-left: 2em; padding-right: 2em}
div.titlebox {border: none; padding-top: 1em; padding-bottom: 1em;
    padding-left: 2em; padding-right: 2em; background: rgb(200,255,255);
    font-family: sans-serif}
div.synopsisbox {
    border: none; padding-top: 1em; padding-bottom: 1em; padding-left: 2em;
    padding-right: 2em; background: rgb(255,220,255);}
pre.example {border: 1px solid rgb(180,180,180); padding-top: 1em;
    padding-bottom: 1em; padding-left: 1em; padding-right: 1em;
    background-color: rgb(238,238,255)}
div.spacerbox {border: none; padding-top: 2em; padding-bottom: 2em}
div.image {margin: 0; padding: 1em; text-align: center}
div.categorybox {border: 1px solid gray; padding-top: 1em; padding-bottom: 1em;
    padding-left: 1em; padding-right: 1em; background: rgb(247,242,220)}
img {max-width:80%; max-height: 80%; display: block; margin-left: auto; margin-right: auto}

-->
</style>

<link rel="icon" href="figures/favicon.ico">
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6>"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Introduction-to-Simplification"></a>
<div class="header">
<p>
Next: <a href="maxima_46.html#Functions-and-Variables-for-Simplification" accesskey="n" rel="next">Functions and Variables for Simplification</a>, Up: <a href="maxima_44.html#Simplification" accesskey="u" rel="up">Simplification</a> &nbsp; [<a href="maxima_toc.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="maxima_423.html#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Introduction-to-Simplification-1"></a>
<h3 class="section">9.1 Introduction to Simplification</h3>

<p>Maxima interacts with the user through a cycle of actions called the read-eval-print loop (REPL).
This consists of three steps: reading and parsing, evaluating and simplifying, 
and outputting. Parsing converts a syntactically valid sequence of typed characters into
a internal data structure. Evaluation
replaces variable and function names with their values and simplification rewrites 
expressions to be easier for the user or other programs to understand. Output 
displays results in a variety of different formats and notations.
</p>
<p>Evaluation and simplification sometimes appear to have similar functionality, and
Maxima uses simplification in many cases where other systems use evaluation.
For example, arithmetic both on numbers and on symbolic expressions is simplification, not evaluation:
<code>2+2</code> simplifies to <code>4</code>, <code>2+x+x</code> simplifies to <code>2+2*x</code>, and
<code>sqrt(7)^4</code> simplifies to <code>49</code>.
Evaluation and simplification are interleaved.
For example, <code>factor(integrate(x+1,x))</code> first calls the built-in function <code><a href="maxima_104.html#integrate">integrate</a></code>,
giving <code>x+x*x*2^-1</code>;
that simplifies to <code>x+(1/2)*x^2</code>; this in turn is passed to the <code><a href="maxima_80.html#factor">factor</a></code> function,
which returns <code>(x*(x+2))/2</code>.
</p>
<p>Evaluation is what makes Maxima a programming language: it implements
functions, subroutines, variables, values, loops, assignments and so on.
Evaluation replaces built-in or user-defined function names by their definitions and
variables by their values. This is largely the same as activities of a 
conventional programming language, but extended to work with symbolic mathematical data. 
The system has various optional &quot;flags&quot; which the user can set to control the details of
evaluation. See <a href="maxima_43.html#Functions-and-Variables-for-Evaluation">Functions and Variables for Evaluation</a>.
</p>
<p>Simplification maintains the value of an expression 
while re-formulating its form to be smaller, simpler to understand, or to 
conform to a particular specification (like expanded). For
example, <code>sin(%pi/2)</code> to <code>1</code>, and <code>x+x</code> to <code>2*x</code>.
There are many flags which control simplification. For example,
with <code>triginverses:true</code>, <code>atan(tan(x))</code> does not simplify to <code>x</code>,
but with <code>triginverses:all</code>, it does.
</p>
<p>Simplification can be provided in three ways:
</p><ul>
<li> The internal, built-in automated simplifier,
</li><li> User-written pattern-matching transformations, linked to the simplifier by using
      &quot;tellsimp&quot; or &quot;tellsimpafter&quot; and called automatically,
</li><li> User-written simplification routines adding using the <code>simplifying</code> subsystem.
</li></ul>

<p>The internal simplifier belongs to the heart of Maxima. It is a large and 
complicated collection of programs, and it has been refined over many years and by 
thousands of users. Nevertheless, especially if you are trying out novel ideas or 
unconventional notation, you may find it helpful to make small (or large) changes 
to the program yourself. For details see for example the paper at the end of
<a href="https://people.eecs.berkeley.edu/~fateman/papers/intro5.txt">https://people.eecs.berkeley.edu/~fateman/papers/intro5.txt</a>.
</p>
<p>Maxima internally represents expressions as &quot;trees&quot; with operators or &quot;roots&quot;
like <code>+</code>, <code>*</code> , <code>=</code> and operands (&quot;leaves&quot;) which are variables like
<var>x</var>, <var>y</var>, <var>z</var>, functions
or sub-trees, like <code>x*y</code>. Each operator has a simplification program
associated with it.  <code>+</code> (which also covers binary <code>-</code> since
<code>a-b = a+(-1)*b)</code> and <code>*</code> (which also covers <code>/</code> 
since <code>a/b = a*b^(-1)</code>) have rather elaborate simplification programs. These 
simplification programs (simplus, simptimes, simpexpt, etc.) are called whenever 
the simplifier encounters the respective arithmetic operators in an expression 
tree to be analyzed. 
</p>
<p>The structure of the simplifier dates back to 1965, and many hands have worked 
on it through the years. It is data-directed, or object-oriented in the sense that
it dispatches to the appropriate routine 
depending on the root of some sub-tree of the expression, recursively. This general
approach means that modifications to simplification are generally localized.
In many cases it is straightforward to add an 
operator and its simplification routine without disturbing existing code.
</p>
<p>Maxima also provides a variety of transformation routines that can change the form of an
expression, including <code><a href="maxima_80.html#factor">factor</a></code> (polynomial factorization), <code><a href="maxima_116.html#horner">horner</a></code>
(reorganize a polynomial using Horner&rsquo;s rule), <code><a href="maxima_146.html#partfrac">partfrac</a></code>
(rewrite a rational function as partial fractions),
<code><a href="maxima_57.html#trigexpand">trigexpand</a></code> (apply the sum formulas for trigonometric functions),
and so on.
</p>
<p>Users can also write routines that change the form of an expression.
</p>
<p>Besides this general simplifier operating on algebraic 
expression trees, there are several other representations of expressions in 
Maxima which have separate methods. For example, the
<code><a href="maxima_80.html#rat">rat</a></code> function converts polynomials to vectors of coefficients to
assist in rapid manipulation of such forms. Other representations include
Taylor series and the (rarely used) Poisson series.
</p>
<p>All operators introduced by the user initially have no simplification
programs associated with them.  Maxima does not know anything about
function &quot;f&quot;  and so typing <code>f(a,b)</code> will result in simplifying
<var>a</var>,<var>b</var>, but not <code>f</code>. 
Even some built-in operators have no simplifications. For example,
<code>=</code> does not &quot;simplify&quot; &ndash; it is a place-holder with no
simplification semantics other 
than to simplify its two arguments, in this case referred to as the left and 
right sides. Other parts of Maxima such as the solve program take special 
note of equations, that is, trees with <code>=</code> as the root. 
(Note &ndash; in Maxima, the assignment operation is <code>:</code> . That is, <code>q: 4</code>
sets the value of the symbol <var>q</var> to <code>4</code>.
Function definition is done with <code>:=</code>. )
</p>
<p>The general simplifier returns results with an internal flag indicating the 
expression and each sub-expression has been simplified. This does not 
guarantee that it is unique over all possible equivalent expressions. That&rsquo;s 
too hard (theoretically, not possible given the generality of what can be 
expressed in Maxima). However, some aspects of the expression, such as the 
ordering of terms in a sum or product, are made uniform. This is important 
for the other programs to work properly.
</p>
<p>A number of option variables control simplification. Indeed, simplification
can be turned off entirely using <code>simp:false</code>. However, many
internal routines will not operate correctly with <code>simp:false</code>.
(About the only time it seems plausible to turn off the simplifier 
is in the rare case that you want to over-ride a built-in simplification. 
In that case  you might temporarily disable the simplifier, put in the new 
transformation via <code><a href="maxima_162.html#tellsimp">tellsimp</a></code>, and then re-enable the simplifier
by <code>simp:true</code>.)
</p>
<p>It is more plausible for you to associate user-defined symbolic function names 
or operators with properties (<code><a href="maxima_46.html#additive">additive</a></code>,
<code><a href="maxima_46.html#lassociative">lassociative</a></code>, <code><a href="maxima_46.html#oddfun">oddfun</a></code>, <code><a href="maxima_46.html#antisymmetric">antisymmetric</a></code>,
<code><a href="maxima_46.html#linear">linear</a></code>, <code><a href="maxima_46.html#outative">outative</a></code>, <code><a href="maxima_46.html#commutative">commutative</a></code>, 
<code><a href="maxima_46.html#multiplicative">multiplicative</a></code>, <code><a href="maxima_46.html#rassociative">rassociative</a></code>, <code><a href="maxima_46.html#evenfun">evenfun</a></code>,
<code><a href="maxima_62.html#nary">nary</a></code> and <code><a href="maxima_46.html#symmetric">symmetric</a></code>). These options steer 
the simplifier processing in systematic directions.
</p>
<p>For example, <code>declare(f,oddfun)</code> specifies that <code>f</code> is an odd function.
Maxima will simplify <code>f(-x)</code> to <code>-f(x)</code>. In the case of an even
function, that is <code>declare(g,evenfun)</code>, 
Maxima will simplify <code>g(-x)</code> to <code>g(x)</code>. You can also associate a
programming function with a name such as <code>h(x):=x^2+1</code>. In that case the
evaluator will immediately replace 
<code>h(3)</code> by <code>10</code>, and <code>h(a+1)</code> by <code>(a+1)^2+1</code>, so any properties
of <code>h</code> will be ignored.
</p>
<p>In addition to these directly related properties set up by the user, facts and 
properties from the actual context may have an impact on the simplifier&rsquo;s behavior, 
too. See <a href="maxima_61.html#Introduction-to-Maxima_0027s-Database">Introduction to Maxima's Database</a>.
</p>
<p>Example: <code>sin(n*%pi)</code> is simplified to zero, if <var>n</var> is an integer.
</p>
<div class="example">
<pre class="example">(%i1) sin(n*%pi);
(%o1)                      sin(%pi n)
</pre><pre class="example">(%i2) declare(n, integer);
(%o2)                         done
</pre><pre class="example">(%i3) sin(n*%pi);
(%o3)                           0
</pre></div>

<p>If automated simplification is not sufficient, you can consider a variety of 
built-in, but explicitly called simplfication functions (<code><a href="maxima_80.html#ratsimp">ratsimp</a></code>,
<code><a href="maxima_46.html#expand">expand</a></code>, <code><a href="maxima_80.html#factor">factor</a></code>, <code><a href="maxima_46.html#radcan">radcan</a></code> and others). There are
also flags that will push simplification into one or another direction.
Given <code>demoivre:true</code> the simplifier rewrites 
complex exponentials as trigonometric forms. Given <code>exponentialize:true</code>
the  simplifier tries to do the reverse: rewrite trigonometric forms as complex 
exponentials.
</p>
<p>As everywhere in Maxima, by writing your own functions (be it in the Maxima 
user language or in the implementation language Lisp) and explicitly calling them 
at selected places in the program, you can respond to your individual 
simplification needs. Lisp gives you a handle on all the internal mechanisms, but 
you rarely need this full generality. &quot;Tellsimp&quot; is designed to generate much 
of the Lisp internal interface into the simplifier automatically.
See See <a href="maxima_160.html#Rules-and-Patterns">Rules and Patterns</a>.
</p>
<p>Over the years (Maxima/Macsyma&rsquo;s origins date back to about 1966!) users have 
contributed numerous application packages and tools to extend or alter its 
functional behavior. Various non-standard and &quot;share&quot; packages exist to modify 
or extend simplification as well. You are invited to look into this more 
experimental material where work is still in progress See <a href="maxima_356.html#simplification_002dpkg">simplification-pkg</a>.
</p>
<p>The following appended material is optional on a first reading, and reading it 
is not necessary for productive use of Maxima. It is for the curious user who 
wants to understand what is going on, or the ambitious programmer who might 
wish to change the (open-source) code. Experimentation with redefining Maxima 
Lisp code is easily possible: to change the definition of a Lisp program (say 
the one that simplifies <code>cos()</code>, named <code>simp%cos</code>), you simply
load into Maxima a text file that will overwrite the <code>simp%cos</code> function
from the maxima package.
</p>
<a name="Item_003a-Simplification_002fnode_002fFunctions-and-Variables-for-Simplification"></a><hr>
<div class="header">
<p>
Next: <a href="maxima_46.html#Functions-and-Variables-for-Simplification" accesskey="n" rel="next">Functions and Variables for Simplification</a>, Up: <a href="maxima_44.html#Simplification" accesskey="u" rel="up">Simplification</a> &nbsp; [<a href="maxima_toc.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="maxima_423.html#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>