-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaxima_tutorial.html
1504 lines (1488 loc) · 120 KB
/
maxima_tutorial.html
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html><html prefix="dcterms: http://purl.org/dc/terms/">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>A Maxima tutorial</title>
<!--Generated on Mon Dec 11 21:44:50 2023 by LaTeXML (version 0.8.6) http://dlmf.nist.gov/LaTeXML/.-->
<!--Document created on December 11, 2023.-->
<link rel="stylesheet" href="css/latex-schola.css" type="text/css">
<link rel="stylesheet" href="css/ltx-article.css" type="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
</head>
<body>
<nav><a href="index.html">Maxima.st</a><span>→</span><span>A Maxima tutorial</span></nav>
<div class="ltx_page_main">
<div class="ltx_page_content">
<article class="ltx_document ltx_authors_1line">
<h1 class="ltx_title ltx_title_document">A Maxima tutorial</h1>
<div class="ltx_authors">
<span class="ltx_creator ltx_role_author">
<span class="ltx_personname">Jaime E. Villate
<br class="ltx_break"><em class="ltx_emph ltx_font_italic">University of Porto, Portugal</em>
</span></span>
</div>
<div class="ltx_dates">(December 11, 2023)</div>
<div class="ltx_pagination ltx_role_newpage"></div>
<section id="S1" class="ltx_section">
<h2 class="ltx_title ltx_title_section">
<span class="ltx_tag ltx_tag_section">1 </span>Introduction</h2>
<div id="S1.p1" class="ltx_para">
<p class="ltx_p"><em class="ltx_emph ltx_font_italic">Maxima</em> is a <em class="ltx_emph ltx_font_italic">Free Software</em> package for the
manipulation of symbolic and numerical expressions, including
differentiation, integration, Taylor series, Laplace transforms,
ordinary differential equations, systems of linear equations,
polynomials, sets, lists, vectors, matrices and tensors and more. It
can be freely downloaded from its Website
(<a href="https://maxima.sourceforge.net" title="" class="ltx_ref ltx_url ltx_font_typewriter">https://maxima.sourceforge.net</a>) which also includes reference
manuals and tutorials in several languages. There is an active
community of developers and users; questions about Maxima can be sent
to its main mailing-list address at
<span class="ltx_text ltx_font_typewriter">[email protected]</span>.</p>
</div>
<div id="S1.p2" class="ltx_para">
<p class="ltx_p">Maxima is one of the oldest Computer Algebra Systems (CAS). It was
created by MIT’s MAC group in the 1960s and it was initially called
<em class="ltx_emph ltx_font_italic">Macsyma</em> (<em class="ltx_emph ltx_font_italic">project MAC’s SYmbolic
MAnipulator</em>). <em class="ltx_emph ltx_font_italic">Macsyma</em> was originally developed for the
DEC-PDP-10 large-scale computers that were used in various academic
institutions at that time.</p>
</div>
<div id="S1.p3" class="ltx_para">
<p class="ltx_p">In the 1980s, its code was ported to several new platforms and one of
those derived versions was called <em class="ltx_emph ltx_font_italic">Maxima</em>. In 1982 the MIT
decided to sell <em class="ltx_emph ltx_font_italic">Macsyma</em> as proprietary software and
simultaneously Professor William Schelter of the University of Texas
continued to develop the <em class="ltx_emph ltx_font_italic">Maxima</em> version. In the late 1980s
other proprietary CAS systems similar to <em class="ltx_emph ltx_font_italic">Macsyma</em> appeared,
such as <em class="ltx_emph ltx_font_italic">Maple</em> and <em class="ltx_emph ltx_font_italic">Mathematica</em>. In 1998, Professor
Schelter obtained authorization from the DOE (Department of Energy),
which held the copyright for the original version of
<em class="ltx_emph ltx_font_italic">Macsyma</em>, to distribute the source code of <em class="ltx_emph ltx_font_italic">Maxima</em>
as free software. When Professor Schelter passed away in 2001, a
group of volunteers was formed to continue to develop and distribute
<em class="ltx_emph ltx_font_italic">Maxima</em> as free software.</p>
</div>
<div id="S1.p4" class="ltx_para">
<p class="ltx_p">In the case of CAS software, the advantages of free software are very
important. When a method fails or gives very complicated answers it is
quite useful to have access to the details of the underlying
implementation of the methods used. On the other hand, as one’s
research and teaching becomes dependent on the results of a CAS, it is
desirable to have good documentation of the methods involved and its
implementation and to be assured that there are no legal barriers
forbidding the examination and modification of that code.</p>
</div>
</section>
<section id="S2" class="ltx_section">
<h2 class="ltx_title ltx_title_section">
<span class="ltx_tag ltx_tag_section">2 </span>Graphical interfaces for maxima</h2>
<div id="S2.p1" class="ltx_para">
<p class="ltx_p">Maxima is a program that uses a command shell (or a console or text
terminal) to interact with the user. There are also several graphical
interfaces to work with Maxima, such as <em class="ltx_emph ltx_font_italic">wxMaxima</em>, which is a
software package separate from Maxima; you might have to install that
package separately, if it’s not bundled to the package you download to
install Maxima. Two other graphical interfaces, <em class="ltx_emph ltx_font_italic">imaxima</em> and
<em class="ltx_emph ltx_font_italic">Xmaxima</em>, are being developed and distributed together with
Maxima. The left-hand side of Figure <a href="#S2.F1" title="Figure 1 ‣ 2 Graphical interfaces for maxima ‣ A Maxima tutorial" class="ltx_ref"><span class="ltx_text ltx_ref_tag">1</span></a> shows some
commands being run in Xmaxima, and the right-hand side shows the same
commands as being run in imaxima, which runs from within the
<em class="ltx_emph ltx_font_italic">Emacs</em> text editor</p>
</div>
<figure id="S2.F1" class="ltx_figure"><img src="figs/maxima_interfaces.png" style="width:33.978em;max-width:100%;height:auto" id="S2.F1.g1" class="ltx_graphics ltx_centering" alt="Xmaxima’s graphical interface.">
<figcaption class="ltx_caption ltx_centering"><span class="ltx_tag ltx_tag_figure">Figure 1: </span>Xmaxima’s graphical interface.</figcaption>
</figure>
<div id="S2.p2" class="ltx_para">
<p class="ltx_p">The graphical interfaces connect to the Maxima program, send the
commands that the user types to Maxima, and show the result it
returns. Some interfaces, such as wxMaxima and imaxima, convert those
results to a graphic that resembles closer what the user would find in
a textbook, while Xmaxima leaves the result as given by Maxima, namely
simple text that can take several lines in the case of fractions,
powers or long output.</p>
</div>
<div id="S2.p3" class="ltx_para">
<p class="ltx_p">Xmaxima usually opens two windows (Figure <a href="#S2.F1" title="Figure 1 ‣ 2 Graphical interfaces for maxima ‣ A Maxima tutorial" class="ltx_ref"><span class="ltx_text ltx_ref_tag">1</span></a>). One of
them, called the <em class="ltx_emph ltx_font_italic">browser</em>, shows a tutorial and allows the
user to read the manual or other Web pages. The second window is the
<em class="ltx_emph ltx_font_italic">console</em>, where Maxima commands should be written and their
output will appear.</p>
</div>
<div id="S2.p4" class="ltx_para">
<p class="ltx_p">In the “Edit” menu there are options to navigate the list of
previous commands (“previous input”) or to copy and paste text; some
options in the menus can also be accessed with the shortcut keys shown
next to them. Different colors are used to distinguish commands that
have already been processed (in blue) from the command that is being
written and has not yet been sent to Maxima (in green); the results
are shown in black (see Figure <a href="#S2.F1" title="Figure 1 ‣ 2 Graphical interfaces for maxima ‣ A Maxima tutorial" class="ltx_ref"><span class="ltx_text ltx_ref_tag">1</span></a>).</p>
</div>
<div id="S2.p5" class="ltx_para">
<p class="ltx_p">When changing a command already executed or when starting a new
command, care must be taken that what is being written appears in
green or blue, to ensure that it will be sent to Maxima. Sometimes it
may be necessary to use the options “Interrupt” or “Input prompt”,
in the “File” menu to recover the state in which Xmaxima is
accepting commands.</p>
</div>
<div id="S2.p6" class="ltx_para">
<p class="ltx_p">It is also possible to move the prompt symbol to some older entry in
the screen (in blue), change it, and press enter to repeat the same
command with the modifications.</p>
</div>
</section>
<section id="S3" class="ltx_section">
<h2 class="ltx_title ltx_title_section">
<span class="ltx_tag ltx_tag_section">3 </span>Data input and output</h2>
<div id="S3.p1" class="ltx_para">
<p class="ltx_p">When a Maxima session starts, the tag <span class="ltx_text" style="color:#CC3333;">(%i1)</span> will appear, which
refers to <em class="ltx_emph ltx_font_italic">input</em> 1. A valid command should be written next to
that tag, ended with a semi-colon and when the enter key is pressed,
that input will be parsed, simplified, linked to an internal variable
<span class="ltx_text" style="color:#000099;">%i1</span> and its result will be shown following a tag <code class="ltx_verbatim ltx_font_typewriter">(%o1)</code>,
referring to <em class="ltx_emph ltx_font_italic">output</em> 1. That result will also be linked to an
internal variable <span class="ltx_text" style="color:#000099;">%o1</span>. Another tag <span class="ltx_text" style="color:#CC3333;">(%i2)</span> will then
appear, to mark the place where a second command may be written and so
on. The most basic usage of Maxima is as a calculator, as in the
following examples.</p>
</div>
<div id="S3.p2" class="ltx_para">
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i1)</span> <span class="ltx_text" style="color:#000099;">2.5*3.1;
<br class="ltx_break"></span>
(%o1) <math id="S3.p2.m1" class="ltx_Math" alttext="7.75" display="inline"><mn>7.75</mn></math>
<br class="ltx_break">
<span class="ltx_text" style="color:#CC3333;">(%i2)</span> <span class="ltx_text" style="color:#000099;">5.2*log(2);
<br class="ltx_break"></span>
(%o2) <math id="S3.p2.m2" class="ltx_Math" alttext="5.2\,\log 2" display="inline"><mrow><mn>5.2</mn><mspace width=0.166em /><mrow><mi>log</mi><mspace width=0.11em /><mn>2</mn></mrow></mrow></math></p>
</blockquote>
</div>
<div id="S3.p3" class="ltx_para">
<p class="ltx_p">The result <code class="ltx_verbatim ltx_font_typewriter">(%o2)</code> shows
two important aspects of Maxima. First, the natural logarithm of 2 was
not computed, because its result is an irrational number which cannot
be represented exactly with a finite number of numerical digits. The
second important aspect is that the symbol <code class="ltx_verbatim ltx_font_typewriter">*</code> which is always
required when a product is entered and the parenthesis, which have to
be used to specify the argument of a function, were not included in
the output. That happened because, by default, the output is shown in
a mode called display2d, in which the output tries to resemble the way
mathematical expressions are usually shown in books. The expression
“<code class="ltx_verbatim ltx_font_typewriter">5.2 log 2</code>” most probably will be interpreted correctly by a
reader, as the product of 5.2 times the logarithm of 2; however, if
that same ambiguous expression was given as input to Maxima it would
trigger an error, because Maxima syntax requires an operator between
5.2 and the logarithm function, and the argument of the logarithm must
be inside parenthesis. In spite of the form of the output, variable
<span class="ltx_text" style="color:#000099;">%o2</span> has been linked to an expression with correct syntax, so
it can be reused in later Maxima commands without syntax errors.</p>
</div>
<div id="S3.p4" class="ltx_para">
<p class="ltx_p">To look up the documentation of a function or special variable in the
manual, for instance the function <span class="ltx_text" style="color:#000099;">log</span> that was just used, the
describe function is used, which can be abbreviated with a question
mark followed by space and the name of the function:</p>
</div>
<div id="S3.p5" class="ltx_para">
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i3)</span> <span class="ltx_text" style="color:#000099;">? log
<br class="ltx_break"></span>
– Function: log (<x>)
<br class="ltx_break">
Represents the natural (base e) logarithm of <x>.
<br class="ltx_break">
Maxima does not have a built-in function for the base 10 logarithm
or other bases. ’log10(x) := log(x) / log(10)’ is a useful
definition.
<br class="ltx_break">
…</p>
</blockquote>
</div>
</section>
<section id="S4" class="ltx_section">
<h2 class="ltx_title ltx_title_section">
<span class="ltx_tag ltx_tag_section">4 </span>Numbers</h2>
<div id="S4.p1" class="ltx_para">
<p class="ltx_p">Maxima accepts real and complex numbers. Real numbers in Maxima can be
integers, rationals, such as 3/5, or floating-point numbers, for
instance, 2.56 and 25.6e-1, which is a short notation for
<math id="S4.p1.m1" class="ltx_Math" alttext="25.6\times 10^{-1}" display="inline"><mrow><mn>25.6</mn><mo>×</mo><msup><mn>10</mn><mrow><mo>−</mo><mn>1</mn></mrow></msup></mrow></math>. Irrational numbers, such as <code class="ltx_verbatim ltx_font_typewriter">sqrt(2)</code> or
<code class="ltx_verbatim ltx_font_typewriter">log(2)</code> (natural logarithm of 2) are left in that form, without
being approximated by floating-point numbers, and later calculations,
such as <code class="ltx_verbatim ltx_font_typewriter">sqrt(2)^2</code> or <code class="ltx_verbatim ltx_font_typewriter">exp(log(2))</code> will lead to the exact
result 2.</p>
</div>
<div id="S4.p2" class="ltx_para">
<p class="ltx_p">Floating-point numbers are “contagious”; namely, the operations in
which they enter will be carried out in that format. For example, if
instead of writing <span class="ltx_text" style="color:#000099;">log(2)</span> we would write <span class="ltx_text" style="color:#000099;">log(2.0)</span>, the
logarithm would be computed approximately in floating-point. Another
way to force an expression to be computed as a floating-point number
consists on using the function <span class="ltx_text" style="color:#000099;">float</span>. For instance, since the
result <code class="ltx_verbatim ltx_font_typewriter">(%o2)</code> obtained above has been stored in variable
<span class="ltx_text" style="color:#000099;">%o2</span>, to get a floating-point approximation of that result we
would write:</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i4)</span> <span class="ltx_text" style="color:#000099;">float (%o2);
<br class="ltx_break"></span>
(%o4) <math id="S4.p2.m1" class="ltx_Math" alttext="3.604365338911716" display="inline"><mn>3.604365338911716</mn></math></p>
</blockquote>
</div>
<div id="S4.p3" class="ltx_para">
<p class="ltx_p">The function float computed the product <math id="S4.p3.m1" class="ltx_Math" alttext="5.2\,\log(2)" display="inline"><mrow><mn>5.2</mn><mspace width=0.166em /><mrow><mi>log</mi><mspace width=0.11em /><mrow><mo stretchy="false">(</mo><mn>2</mn><mo stretchy="false">)</mo></mrow></mrow></mrow></math> approximately,
using 16 significant digits in floating-point format. The
floating-point format used in Maxima stores each number in 64 binary
bits, which leads to between 15 and 17 significant digits when
expressed in decimal base. That format is known as <em class="ltx_emph ltx_font_italic">double
precision</em>.
</p>
</div>
<div id="S4.p4" class="ltx_para">
<p class="ltx_p">A frequent source of confusion arises from the fact that those numbers
are being represented internally in binary base and not in decimal
base; thus, certain numbers that can be represented in decimal base
with a few digits, for instance 0.1, would need an infinite number of
binary digits to be represented accurately in binary base. It is the
situation as with the fraction 1/3 in decimal base, which in
floating-point form has an infinite number of digits: 0.333…,
while in base 3 that fraction would simply be 0.1.</p>
</div>
<div id="S4.p5" class="ltx_para">
<p class="ltx_p">The fractions that lead to an infinite number of digits are not the
same in the decimal and binary base. Consider the following results,
which would appear in any system that uses binary base and
double-precision format and which might puzzle somebody used to
working with in decimal base:</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i5)</span> <span class="ltx_text" style="color:#000099;">2*0.1;
<br class="ltx_break"></span>
(%o5) <math id="S4.p5.m1" class="ltx_Math" alttext="0.2" display="inline"><mn>0.2</mn></math>
<br class="ltx_break">
<span class="ltx_text" style="color:#CC3333;">(%i6)</span> <span class="ltx_text" style="color:#000099;">6*0.1;
<br class="ltx_break"></span>
(%o6) <math id="S4.p5.m2" class="ltx_Math" alttext="0.6000000000000001" display="inline"><mn>0.6000000000000001</mn></math>
<br class="ltx_break"></p>
</blockquote>
</div>
<div id="S4.p6" class="ltx_para">
<p class="ltx_p">Some computing systems ignore the last digits in the results obtained
from double-precision calculations, showing the result as 0.6, but
whenever binary double-precision is used, the result of 6×0.1 will not
be exactly 0.6.</p>
</div>
<div id="S4.p7" class="ltx_para">
<p class="ltx_p">The best approximation of 1/3 in decimal base, using only 3
significant digits, is <math id="S4.p7.m1" class="ltx_Math" alttext="333/10^{3}=0.333" display="inline"><mrow><mrow><mn>333</mn><mo>/</mo><msup><mn>10</mn><mn>3</mn></msup></mrow><mo>=</mo><mn>0.333</mn></mrow></math>. In binary base, it is
represented as <math id="S4.p7.m2" class="ltx_Math" alttext="n/2^{m}" display="inline"><mrow><mi>n</mi><mo>/</mo><msup><mn>2</mn><mi>m</mi></msup></mrow></math> (<math id="S4.p7.m3" class="ltx_Math" alttext="n" display="inline"><mi>n</mi></math> and <math id="S4.p7.m4" class="ltx_Math" alttext="m" display="inline"><mi>m</mi></math> integers); with the 52 significant
digits used in the double-precision standard, <math id="S4.p7.m5" class="ltx_Math" alttext="n" display="inline"><mi>n</mi></math> has to be less than
<math id="S4.p7.m6" class="ltx_Math" alttext="2^{52}" display="inline"><msup><mn>2</mn><mn>52</mn></msup></math>. Maxima’s function rationalize shows the approximate
representation being used for a number, in the form of a fraction. For
instance the approximation to <math id="S4.p7.m7" class="ltx_Math" alttext="0.1" display="inline"><mn>0.1</mn></math> is</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i7)</span> <span class="ltx_text" style="color:#000099;">rationalize (0.1);
<br class="ltx_break"></span>
(%o7) <math id="S4.p7.m8" class="ltx_Math" alttext="\dfrac{3602879701896397}{36028797018963968}" display="inline"><mstyle displaystyle="true"><mfrac><mn>3602879701896397</mn><mn>36028797018963968</mn></mfrac></mstyle></math></p>
</blockquote>
<p class="ltx_p">where 3602879701896397 is less than <math id="S4.p7.m9" class="ltx_Math" alttext="2^{52}" display="inline"><msup><mn>2</mn><mn>52</mn></msup></math> and bigger than <math id="S4.p7.m10" class="ltx_Math" alttext="2^{51}" display="inline"><msup><mn>2</mn><mn>51</mn></msup></math>,
and the denominator is a power of 2 (<math id="S4.p7.m11" class="ltx_Math" alttext="36028797018963968=2^{55}" display="inline"><mrow><mn>36028797018963968</mn><mo>=</mo><msup><mn>2</mn><mn>55</mn></msup></mrow></math>). That
fraction is not exactly equal to <math id="S4.p7.m12" class="ltx_Math" alttext="0.1" display="inline"><mn>0.1</mn></math>, but it is the best possible
approximation using double-precision.</p>
</div>
<div id="S4.p8" class="ltx_para">
<p class="ltx_p">There is a Maxima specific format which accepts bigger number of
significant digits to represent floating-point numbers, called
<em class="ltx_emph ltx_font_italic">bigfloat</em>. To use it, one should write “b”, instead of
“e” for the exponents; for example, <math id="S4.p8.m1" class="ltx_Math" alttext="2.56\times 10^{20}" display="inline"><mrow><mn>2.56</mn><mo>×</mo><msup><mn>10</mn><mn>20</mn></msup></mrow></math>, written as
2.56e20 would be represented internally in double-precision format,
with 16 significant digits, and any calculations made with it would
result in other double-precision numbers. But if the same number was
written as 2.56b20, it would be stored in the bigfloat format and any
calculations involving it would produce other bogfloat numbers. By
default, bigfloat format uses the same 16 significant digits as
double-precision, but that can be changed by changing the value of the
system variable <span class="ltx_text" style="color:#000099;">fpprec</span> (floating-point precision).</p>
</div>
<div id="S4.p9" class="ltx_para">
<p class="ltx_p">Function <span class="ltx_text" style="color:#000099;">bfloat</span> converts a number into bigfloat. For
example, to show an approximation to result <code class="ltx_verbatim ltx_font_typewriter">(%o2)</code> with 60
significant digits, the following commands can be used:</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i8)</span> <span class="ltx_text" style="color:#000099;">fpprec: 60;
<br class="ltx_break"></span>
(%o8) <math id="S4.p9.m1" class="ltx_Math" alttext="60" display="inline"><mn>60</mn></math>
<br class="ltx_break">
<span class="ltx_text" style="color:#CC3333;">(%i9)</span> <span class="ltx_text" style="color:#000099;">bfloat (%o2);
<br class="ltx_break"></span>
(%o9) <math id="S4.p9.m2" class="ltx_Math" alttext="3.60436533891171573209728052144843624984298344312084369367127\mathrm{b}0" display="inline"><mrow><mn>3.60436533891171573209728052144843624984298344312084369367127</mn><mspace width=0.166em /><mi>b0</mi></mrow></math></p>
</blockquote>
</div>
<div id="S4.p10" class="ltx_para">
<p class="ltx_p">The letter b followed by zero at the end of <code class="ltx_verbatim ltx_font_typewriter">(%o9)</code>
means that the number is stored in bigfloat format and it should be
multiplied by a factor of <math id="S4.p10.m1" class="ltx_Math" alttext="10^{0}=1" display="inline"><mrow><msup><mn>10</mn><mn>0</mn></msup><mo>=</mo><mn>1</mn></mrow></math>.</p>
</div>
<div id="S4.p11" class="ltx_para">
<p class="ltx_p">In the rest of this tutorial we will show all floating-point results
with only 4 significant digits. That is achieved by changing system
variable <span class="ltx_text" style="color:#000099;">fpprintprec</span> from its default value of 0 to 4:</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i10)</span> <span class="ltx_text" style="color:#000099;">fpprintprec: 4;
<br class="ltx_break"></span>
(%o10) <math id="S4.p11.m1" class="ltx_Math" alttext="4" display="inline"><mn>4</mn></math></p>
</blockquote>
</div>
<div id="S4.p12" class="ltx_para">
<p class="ltx_p">Internally, all floating-point double-precision numbers will continue
to have 16 significant digits and bigfloat numbers will have the
number of significant digits set by <span class="ltx_text" style="color:#000099;">fpprec</span>, but whenever a
number has to be printed in the screen, it will be rounded to 4
significant digits. If we would like to see all the significant digits
stored internally, variable <span class="ltx_text" style="color:#000099;">fpprintprec</span> should be set to its
default value of 0.</p>
</div>
</section>
<section id="S5" class="ltx_section">
<h2 class="ltx_title ltx_title_section">
<span class="ltx_tag ltx_tag_section">5 </span>Variables</h2>
<div id="S5.p1" class="ltx_para">
<p class="ltx_p">To associate a value or other objects to a variable, use a colon “:”
and not the equal sign “=”, which is reserved to define mathematical
equations. The name of the variables can be any combination of
letters, numbers and the characters % and _,
but the first character cannot be a number. Maxima is case
sensitive. Here are some examples:</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i11)</span> <span class="ltx_text" style="color:#000099;">a: 2$
<br class="ltx_break"></span>
<span class="ltx_text" style="color:#CC3333;">(%i12)</span> <span class="ltx_text" style="color:#000099;">[b, c]: [-2, -4];
<br class="ltx_break"></span>
(%o12) <math id="S5.p1.m1" class="ltx_Math" alttext="\left[-2,-4\right]" display="inline"><mrow><mo>[</mo><mrow><mo>−</mo><mn>2</mn></mrow><mo>,</mo><mrow><mo>−</mo><mn>4</mn></mrow><mo>]</mo></mrow></math>
<br class="ltx_break">
<span class="ltx_text" style="color:#CC3333;">(%i13)</span> <span class="ltx_text" style="color:#000099;">c;
<br class="ltx_break"></span>
(%o13) <math id="S5.p1.m2" class="ltx_Math" alttext="-4" display="inline"><mrow><mo>−</mo><mn>4</mn></mrow></math>
<br class="ltx_break">
<span class="ltx_text" style="color:#CC3333;">(%i14)</span> <span class="ltx_text" style="color:#000099;">Root1: (-b + sqrt(b^2 - 4*a*c))/(2*a);
<br class="ltx_break"></span>
(%o14) <math id="S5.p1.m3" class="ltx_Math" alttext="2" display="inline"><mn>2</mn></math>
<br class="ltx_break">
<span class="ltx_text" style="color:#CC3333;">(%i15)</span> <span class="ltx_text" style="color:#000099;">d: sqrt(z^2 + a*c);
<br class="ltx_break"></span>
(%o15) <math id="S5.p1.m4" class="ltx_Math" alttext="\sqrt{z^{2}-8}" display="inline"><msqrt><mrow><msup><mi>z</mi><mn>2</mn></msup><mo>−</mo><mn>8</mn></mrow></msqrt></math></p>
</blockquote>
<p class="ltx_p">variables <span class="ltx_text" style="color:#000099;">a</span>, <span class="ltx_text" style="color:#000099;">b</span>, <span class="ltx_text" style="color:#000099;">c</span> and <span class="ltx_text" style="color:#000099;">Root1</span> were
associated to the numerical values 2, <math id="S5.p1.m5" class="ltx_Math" alttext="-2" display="inline"><mrow><mo>−</mo><mn>2</mn></mrow></math>, <math id="S5.p1.m6" class="ltx_Math" alttext="-4" display="inline"><mrow><mo>−</mo><mn>4</mn></mrow></math> and 2, while variable
<span class="ltx_text" style="color:#000099;">d</span> was associated to an expression.</p>
</div>
<div id="S5.p2" class="ltx_para">
<p class="ltx_p">Notice that input <span class="ltx_text" style="color:#CC3333;">(%i11)</span> was ended with a dollar sign $,
rather than a semi-colon. That will make the command to be executed
without showing its result on the screen. In spite of not being
displayed on the screen, that result has been associated to the symbol
<span class="ltx_text" style="color:#000099;">%o11</span> so it can be used later on.</p>
</div>
<div id="S5.p3" class="ltx_para">
<p class="ltx_p">Input <span class="ltx_text" style="color:#CC3333;">(%i12)</span> shows how to associate several variables to
several values with a single command. When the name of a variable is
written, as in input <span class="ltx_text" style="color:#CC3333;">(%i13)</span>, the output will be the value
associated to that variable or the name of the variable itself if it
has not been associated to any value. In <span class="ltx_text" style="color:#CC3333;">(%i14)</span>, the values
associated to <span class="ltx_text" style="color:#000099;">a</span>, <span class="ltx_text" style="color:#000099;">b</span> and <span class="ltx_text" style="color:#000099;">c</span> were replaced and the
result was associated to variable <span class="ltx_text" style="color:#000099;">Root1</span>. If the values
associated to <span class="ltx_text" style="color:#000099;">a</span>, <span class="ltx_text" style="color:#000099;">b</span> or <span class="ltx_text" style="color:#000099;">c</span> are later changed, that
will not affect the value already associated to <span class="ltx_text" style="color:#000099;">Root1</span>.</p>
</div>
<div id="S5.p4" class="ltx_para">
<p class="ltx_p">In <span class="ltx_text" style="color:#CC3333;">(%i15)</span> since <span class="ltx_text" style="color:#000099;">z</span> has not yet been associated to any
value, it is just a symbol and variable <span class="ltx_text" style="color:#000099;">d</span> is then associated to
an expression that depends on that symbol. Variables can be associated
to numerical values, expressions with abstract symbols, equations and
several other objects that will be described in the following
sections. That means that when you add two variables, you could be
adding a mix of numbers, expressions, equations and so on; the result
could lead to some other valid object or to an error it Maxima can not
sum those objects.</p>
</div>
<div id="S5.p5" class="ltx_para">
<p class="ltx_p">To remove the value associated to a variable, the function
<span class="ltx_text" style="color:#000099;">remvalue</span> can be used; in the following example the value
associated to <span class="ltx_text" style="color:#000099;">a</span> is removed and an expression that depends on the
symbol <span class="ltx_text" style="color:#000099;">a</span> is then associated to <span class="ltx_text" style="color:#000099;">Root1</span>:</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i16)</span> <span class="ltx_text" style="color:#000099;">remvalue (a)$
<br class="ltx_break"></span>
<span class="ltx_text" style="color:#CC3333;">(%i17)</span> <span class="ltx_text" style="color:#000099;">Root1: (-b + sqrt(b^2 - 4*a*c))/(2*a);
<br class="ltx_break"></span>
(%o17) <math id="S5.p5.m1" class="ltx_Math" alttext="\dfrac{\sqrt{16\,a+4}+2}{2\,a}" display="inline"><mstyle displaystyle="true"><mfrac><mrow><msqrt><mrow><mrow><mn>16</mn><mspace width=0.166em /><mi>a</mi></mrow><mo>+</mo><mn>4</mn></mrow></msqrt><mo>+</mo><mn>2</mn></mrow><mrow><mn>2</mn><mspace width=0.166em /><mi>a</mi></mrow></mfrac></mstyle></math></p>
</blockquote>
</div>
<div id="S5.p6" class="ltx_para">
<p class="ltx_p">The command <span class="ltx_text" style="color:#000099;">remvalue(all)</span> removes all
values associate variable in an expression by a given value; for
instance, the following 2 commands will show the value of the
expression associated to <span class="ltx_text" style="color:#000099;">Root1</span> when <span class="ltx_text" style="color:#000099;">a</span> equals 1 and then
the floating-point approximation of that irrational number.
</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i18)</span> <span class="ltx_text" style="color:#000099;">subst (a=1, Root1);
<br class="ltx_break"></span>
(%o18) <math id="S5.p6.m1" class="ltx_Math" alttext="\dfrac{2\,\sqrt{5}+2}{2}" display="inline"><mstyle displaystyle="true"><mfrac><mrow><mrow><mn>2</mn><mspace width=0.166em /><msqrt><mn>5</mn></msqrt></mrow><mo>+</mo><mn>2</mn></mrow><mn>2</mn></mfrac></mstyle></math>
<br class="ltx_break">
<span class="ltx_text" style="color:#CC3333;">(%i19)</span> <span class="ltx_text" style="color:#000099;">float(%o18);
<br class="ltx_break"></span>
(%o19) <math id="S5.p6.m2" class="ltx_Math" alttext="3.236" display="inline"><mn>3.236</mn></math></p>
</blockquote>
</div>
<div id="S5.p7" class="ltx_para">
<p class="ltx_p">The objects associated to <span class="ltx_text" style="color:#000099;">a</span> and <span class="ltx_text" style="color:#000099;">Root1</span> are not modified
after <span class="ltx_text" style="color:#CC3333;">(%i18)</span>; <span class="ltx_text" style="color:#000099;">a</span> continues to be an abstract symbol
and <span class="ltx_text" style="color:#000099;">Root1</span> is associated to an expression that depends on the
symbol <span class="ltx_text" style="color:#000099;">a</span>.</p>
</div>
<div id="S5.p8" class="ltx_para">
<p class="ltx_p">Maxima uses several system variables, whose names start by %. Some
examples are the variables <span class="ltx_text" style="color:#000099;">%i2</span> and <span class="ltx_text" style="color:#000099;">%o2</span>, linked to an
input command and its result. The character <span class="ltx_text" style="color:#000099;">%</span> itself
represents the last result obtained. For instance, in <span class="ltx_text" style="color:#CC3333;">(%i19)</span>
it would have been enough to write down <span class="ltx_text" style="color:#000099;">%</span> instead of
<span class="ltx_text" style="color:#000099;">%o18</span>. The two commands <span class="ltx_text" style="color:#CC3333;">(%i18)</span> and <span class="ltx_text" style="color:#CC3333;">(%i19)</span> could
have been combined into a single command
<span class="ltx_text" style="color:#000099;">float(subst
(a=1,Root1))</span>.</p>
</div>
<div id="S5.p9" class="ltx_para">
<p class="ltx_p">A variable can also be associated to an algebraic equation, as in the
following example</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i20)</span> <span class="ltx_text" style="color:#000099;">second_law: F = m*a;
<br class="ltx_break"></span>
(%o20) <math id="S5.p9.m1" class="ltx_Math" alttext="F=a\,m" display="inline"><mrow><mi>F</mi><mo>=</mo><mrow><mi>a</mi><mspace width=0.166em /><mi>m</mi></mrow></mrow></math></p>
</blockquote>
</div>
<div id="S5.p10" class="ltx_para">
<p class="ltx_p">Maxima does some simplifications to the input commands before executing
them. In this last example, the result of that
simplification was to change the order of the product,
to put the two symbols in alphabetical order. If any of the 3 symbols
<span class="ltx_text" style="color:#000099;">F</span>, <span class="ltx_text" style="color:#000099;">m</span> or <span class="ltx_text" style="color:#000099;">a</span> were associated to a value or other
object, that object would have been substituted by the simplifier. To
prevent the value of a variable to be replaced, its name can be
preceded by an apostrophe (<span class="ltx_text" style="color:#000099;">’a</span> refers to the symbol a and not to
any object associated to it).</p>
</div>
<div id="S5.p11" class="ltx_para">
<p class="ltx_p">The following example shows how the equation associated to
<span class="ltx_text" style="color:#000099;">second_law</span> does not change when one of the symbols in it s then
associated to a value</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i21)</span> <span class="ltx_text" style="color:#000099;">a: 3;
<br class="ltx_break"></span>
(%o21) <math id="S5.p11.m1" class="ltx_Math" alttext="3" display="inline"><mn>3</mn></math>
<br class="ltx_break">
<span class="ltx_text" style="color:#CC3333;">(%i22)</span> <span class="ltx_text" style="color:#000099;">second_law;
<br class="ltx_break"></span>
(%o22) <math id="S5.p11.m2" class="ltx_Math" alttext="F=a\,m" display="inline"><mrow><mi>F</mi><mo>=</mo><mrow><mi>a</mi><mspace width=0.166em /><mi>m</mi></mrow></mrow></math></p>
</blockquote>
</div>
<div id="S5.p12" class="ltx_para">
<p class="ltx_p">The function <span class="ltx_text" style="color:#000099;">subst</span> is used to substitute values of the symbols
in <span class="ltx_text" style="color:#000099;">second_law</span>. Several values can be replaced at once, as in
the following example</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i23)</span> <span class="ltx_text" style="color:#000099;">subst([m=2,’a=5], second_law);
<br class="ltx_break"></span>
(%o23) <math id="S5.p12.m1" class="ltx_Math" alttext="F=10" display="inline"><mrow><mi>F</mi><mo>=</mo><mn>10</mn></mrow></math></p>
</blockquote>
</div>
<div id="S5.p13" class="ltx_para">
<p class="ltx_p">The first argument in the <span class="ltx_text" style="color:#000099;">subst</span> command in <span class="ltx_text" style="color:#CC3333;">(%i24)</span> is a
list, whose elements are separated by commas and within square
brackets. The two elements in that list are equations. The apostrophe
pre-pended to the symbol <span class="ltx_text" style="color:#000099;">a</span> prevents it to be replaced by its
associated value. Without the apostrophe, the <span class="ltx_text" style="color:#000099;">subst</span> command
would have been simplified as</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i24)</span> <span class="ltx_text" style="color:#000099;">subst([m=2, 3=5], second_law);
<br class="ltx_break"></span>
(%o24) <math id="S5.p13.m1" class="ltx_Math" alttext="F=2\,a" display="inline"><mrow><mi>F</mi><mo>=</mo><mrow><mn>2</mn><mspace width=0.166em /><mi>a</mi></mrow></mrow></math></p>
</blockquote>
<p class="ltx_p">in which only <span class="ltx_text" style="color:#000099;">m</span> was replaced and the statement “3=5” was
simply ignored.</p>
</div>
</section>
<section id="S6" class="ltx_section">
<h2 class="ltx_title ltx_title_section">
<span class="ltx_tag ltx_tag_section">6 </span>Lists</h2>
<div id="S6.p1" class="ltx_para">
<p class="ltx_p">As seen in the previous section, lists can be created using square
brackets and commas. The following example creates a list with the
squares of the first five natural numbers and associates it to the
variable <span class="ltx_text" style="color:#000099;">squares</span>
</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i25)</span> <span class="ltx_text" style="color:#000099;">squares: [1, 4, 9, 16, 25]$</span></p>
</blockquote>
</div>
<div id="S6.p2" class="ltx_para">
<p class="ltx_p">Many of the operations among numbers can also
be done among lists. For example, let us create another list in which
each element is the square root of the corresponding element of
<span class="ltx_text" style="color:#000099;">squares</span>, multiplied by 3</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i26)</span> <span class="ltx_text" style="color:#000099;">3*sqrt(squares);
<br class="ltx_break"></span>
(%o26) <math id="S6.p2.m1" class="ltx_Math" alttext="\left[3,6,9,12,15\right]" display="inline"><mrow><mo>[</mo><mn>3</mn><mo>,</mo><mn>6</mn><mo>,</mo><mn>9</mn><mo>,</mo><mn>12</mn><mo>,</mo><mn>15</mn><mo>]</mo></mrow></math></p>
</blockquote>
</div>
<div id="S6.p3" class="ltx_para">
<p class="ltx_p">The elements of a list are indexed by integers starting with 1. To
refer to an element in the list, the corresponding index is written
within square brackets; for instance the third element in the list
<span class="ltx_text" style="color:#000099;">squares</span> is</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i27)</span> <span class="ltx_text" style="color:#000099;">squares[3];
<br class="ltx_break"></span>
(%o27) <math id="S6.p3.m1" class="ltx_Math" alttext="9" display="inline"><mn>9</mn></math></p>
</blockquote>
</div>
<div id="S6.p4" class="ltx_para">
<p class="ltx_p">A very useful function to create lists is <span class="ltx_text" style="color:#000099;">makelist</span>. One way to
use it is to expand an expression depending on a dummy index, for
several values of that index. The first argument must be the
expression to be expanded, followed by the dummy index, the initial
value for it, the upper bound for the index values and the increments
between successive values of the index. If the increment is not given,
its default value is 1. Here are two examples:</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i28)</span> <span class="ltx_text" style="color:#000099;">cubes1: makelist ( i^3, i, 1, 5 );
<br class="ltx_break"></span>
(%o28) <math id="S6.p4.m1" class="ltx_Math" alttext="\left[1,8,27,64,125\right]" display="inline"><mrow><mo>[</mo><mn>1</mn><mo>,</mo><mn>8</mn><mo>,</mo><mn>27</mn><mo>,</mo><mn>64</mn><mo>,</mo><mn>125</mn><mo>]</mo></mrow></math>
<br class="ltx_break">
<span class="ltx_text" style="color:#CC3333;">(%i29)</span> <span class="ltx_text" style="color:#000099;">cubes2: makelist ( i^3, i, 2, 6, 0.6);
<br class="ltx_break"></span>
(%o29) <math id="S6.p4.m2" class="ltx_Math" alttext="\left[8,17.58,32.77,54.87,85.18,125.0,175.6\right]" display="inline"><mrow><mo>[</mo><mn>8</mn><mo>,</mo><mn>17.58</mn><mo>,</mo><mn>32.77</mn><mo>,</mo><mn>54.87</mn><mo>,</mo><mn>85.18</mn><mo>,</mo><mn>125.0</mn><mo>,</mo><mn>175.6</mn><mo>]</mo></mrow></math></p>
</blockquote>
</div>
<div id="S6.p5" class="ltx_para">
<p class="ltx_p">The first list has the cubes of 1, 2, 3, 4 and 5. The second one has
the cubes of 2, 2.6, 3.2, 3.8, 4.4, 5.0 and 5.6. Notice that the
elements of <span class="ltx_text" style="color:#000099;">cubes2</span> are shown with only 4 significant digits,
because in <span class="ltx_text" style="color:#CC3333;">(%i10)</span> we changed the value of the system variable
<span class="ltx_text" style="color:#000099;">fpprintprec</span>. In a fresh Maxima session they would be shown with
16 significant digits.</p>
</div>
<div id="S6.p6" class="ltx_para">
<p class="ltx_p">Instead of giving an initial value and an upper bound for the dummy
index, we can give a list of values for it. And any list in Maxima can
have objects of different types. The following example creates a list
with the cubes of 5, the expression <math id="S6.p6.m1" class="ltx_Math" alttext="x^{2}+\sqrt{y}" display="inline"><mrow><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><msqrt><mi>y</mi></msqrt></mrow></math>, <math id="S6.p6.m2" class="ltx_Math" alttext="-3.2" display="inline"><mrow><mo>−</mo><mn>3.2</mn></mrow></math> (in
bigfloat format) and the equation <math id="S6.p6.m3" class="ltx_Math" alttext="E=m\,c^{2}" display="inline"><mrow><mi>E</mi><mo>=</mo><mrow><mi>m</mi><mspace width=0.166em /><msup><mi>c</mi><mn>2</mn></msup></mrow></mrow></math></p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i30)</span> <span class="ltx_text" style="color:#000099;">makelist (i^3, i, [5, x^2+sqrt(y), -3.2b0, E=m*c^2]);
<br class="ltx_break"></span>
(%o30) <math id="S6.p6.m4" class="ltx_Math" alttext="\left[125,\left(\sqrt{y}+x^{2}\right)^{3},-3.277\mathrm{b}1,E^{3}=c^{6}\,m^{3}\right]" display="inline"><mrow><mo>[</mo><mrow><mrow><mn>125</mn><mo>,</mo><msup><mrow><mo>(</mo><mrow><msqrt><mi>y</mi></msqrt><mo>+</mo><msup><mi>x</mi><mn>2</mn></msup></mrow><mo>)</mo></mrow><mn>3</mn></msup><mo>,</mo><mrow><mo>−</mo><mrow><mn>3.277</mn><mspace width=0.166em /><mi>b1</mi></mrow></mrow><mo>,</mo><msup><mi>E</mi><mn>3</mn></msup></mrow><mo>=</mo><mrow><msup><mi>c</mi><mn>6</mn></msup><mspace width=0.166em /><msup><mi>m</mi><mn>3</mn></msup></mrow></mrow><mo>]</mo></mrow></math></p>
</blockquote>
</div>
</section>
<section id="S7" class="ltx_section">
<h2 class="ltx_title ltx_title_section">
<span class="ltx_tag ltx_tag_section">7 </span>Useful constants</h2>
<div id="S7.p1" class="ltx_para">
<p class="ltx_p">There are some system variables associated to predefined mathematical
constants. Most of them have names starting with %. Three of those
variables are <span class="ltx_text" style="color:#000099;">%pi</span> (<math id="S7.p1.m1" class="ltx_Math" alttext="\pi" display="inline"><mi>π</mi></math>, the length of a circumference
divided by its diameter), <span class="ltx_text" style="color:#000099;">%e</span>, the Euler number <math id="S7.p1.m2" class="ltx_Math" alttext="e" display="inline"><mi>e</mi></math>, base of
the natural logarithms, and <span class="ltx_text" style="color:#000099;">%i</span>, which is the imaginary number
<math id="S7.p1.m3" class="ltx_Math" alttext="i=\sqrt{-1}" display="inline"><mrow><mi>i</mi><mo>=</mo><msqrt><mrow><mo>−</mo><mn>1</mn></mrow></msqrt></mrow></math>. Functions <span class="ltx_text" style="color:#000099;">float</span> and <span class="ltx_text" style="color:#000099;">bfloat</span> produce
floating-point approximations of <span class="ltx_text" style="color:#000099;">%pi</span> and <span class="ltx_text" style="color:#000099;">%e</span>.</p>
</div>
<div id="S7.p2" class="ltx_para">
<p class="ltx_p">The following example computes the product between two complex numbers
written using variable <span class="ltx_text" style="color:#000099;">%i</span>.</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i31)</span> <span class="ltx_text" style="color:#000099;">(3 + %i*4)*(2 + %i*5);
<br class="ltx_break"></span>
(%o31) <math id="S7.p2.m1" class="ltx_Math" alttext="\left(4\,\mathrm{i}+3\right)\,\left(5\,\mathrm{i}+2\right)" display="inline"><mrow><mrow><mo>(</mo><mrow><mrow><mn>4</mn><mspace width=0.166em /><mi mathvariant="normal">i</mi></mrow><mo>+</mo><mn>3</mn></mrow><mo rspace="4.2pt">)</mo></mrow><mspace width=0.166em /><mrow><mo>(</mo><mrow><mrow><mn>5</mn><mspace width=0.166em /><mi mathvariant="normal">i</mi></mrow><mo>+</mo><mn>2</mn></mrow><mo>)</mo></mrow></mrow></math></p>
</blockquote>
</div>
<div id="S7.p3" class="ltx_para">
<p class="ltx_p">Function <span class="ltx_text" style="color:#000099;">rectform</span>, which stands for <em class="ltx_emph ltx_font_italic">rectangular form</em>,
would show the previous result separating the real and imaginary
parts:</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i32)</span> <span class="ltx_text" style="color:#000099;">rectform(%);
<br class="ltx_break"></span>
(%o32) <math id="S7.p3.m1" class="ltx_Math" alttext="23\,\mathrm{i}-14" display="inline"><mrow><mrow><mn>23</mn><mspace width=0.166em /><mi mathvariant="normal">i</mi></mrow><mo>−</mo><mn>14</mn></mrow></math></p>
</blockquote>
</div>
</section>
<section id="S8" class="ltx_section">
<h2 class="ltx_title ltx_title_section">
<span class="ltx_tag ltx_tag_section">8 </span>Batch files</h2>
<div id="S8.p1" class="ltx_para">
<p class="ltx_p">The command
<span class="ltx_text" style="color:#000099;">stringout(“filename”,input)</span>
will store all the input commands that have been entered during a
Maxima session, into a file named “filename”. That file can be
loaded in a future Maxima session, to redo all those commands, with
the command <span class="ltx_text" style="color:#000099;">batch(“filename”)</span>. The name
of Maxima <em class="ltx_emph ltx_font_italic">batch</em> files are usually given the extension
<code class="ltx_verbatim ltx_font_typewriter">.mac</code> to identify them as Maxima batch files.</p>
</div>
<div id="S8.p2" class="ltx_para">
<p class="ltx_p">You can also create a Maxima batch file with a text editor. Just write
the input commands (without any <code class="ltx_verbatim ltx_font_typewriter">%i</code> labels) and then
execute it in Maxima with
<span class="ltx_text" style="color:#000099;">batch(“filename”)</span>. That is a useful way
to use Maxima to solve a problem. You write your commands to solve the
problem in a text editor, save them into a file, and without closing
the editor open Maxima in another window and run that file. If there
is an error or you don’t get the result you wanted, you just have to
go back to the editor window, make the necessary modifications, save
them and back in the Maxima window rerun the batch file. Be careful
not to use <span class="ltx_text" style="color:#000099;">%o</span> variables in batch files, because the number
after <span class="ltx_text" style="color:#000099;">%o</span> might be different every time you execute them.</p>
</div>
<div id="S8.p3" class="ltx_para">
<p class="ltx_p">Many additional functionalities of Maxima come into batch files which
you execute in Maxima using
<span class="ltx_text" style="color:#000099;">load(“filename”)</span>. The difference between
<span class="ltx_text" style="color:#000099;">batch</span> and <span class="ltx_text" style="color:#000099;">load</span> is that <span class="ltx_text" style="color:#000099;">load</span> will not show the
result of the commands being executed. Both commands have a predefined
list of directories where they will look for the file with name
“filename”.</p>
</div>
<div id="S8.p4" class="ltx_para">
<p class="ltx_p">Batch files can include any comments, opening with the two characters
<code class="ltx_verbatim ltx_font_typewriter">/*</code> and closing with <code class="ltx_verbatim ltx_font_typewriter">*/</code>. Any commands entered directly
into Maxima or written into a batch file
can contain blank spaces and new lines between numbers, operators,
variables and other objects, in order to make them more
readable.</p>
</div>
<div id="S8.p5" class="ltx_para">
<p class="ltx_p">Some commands that are used repeatedly in different working sessions,
for instance, the definition a frequently used function, can be placed
inside a batch file which can be loaded in future sessions. If the
name of a batch file to be loaded does not include a complete path but
just the file name and that file name does not exist in the current
directory, Maxima will look for it in a set of directories. That set
of directories includes a sub-directory of the users home
directory. The name of that sub-directory can be different in
different systems but it is always stored in Maxima’s system variable
<span class="ltx_text" style="color:#000099;">maxima_userdir</span>. You can look at the value of that variable and
if the referred sub-directory does not exist, created them. Any batch
files you put into that sub-directory can then be loaded into Maxima
by giving its name, independently of the working directory being used
in the current Maxima session.</p>
</div>
<div id="S8.p6" class="ltx_para">
<p class="ltx_p">Every time Maxima starts it tries to load a user’s batch file in that
<span class="ltx_text" style="color:#000099;">maxima_userdir</span>, with the name <span class="ltx_text" style="color:#000099;">maxima-init.mac</span>, before
showing the first input prompt. That means that you can create that
file, if it doesn’t already exist, and add commands that you want to
be used in all your Maxima sessions. For example, the Maxima commands
shown in this document have been executed a computer where there is a
<span class="ltx_text" style="color:#000099;">maxima-init.mac</span> file with the following two lines</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#000099;">ratprint: false$
<br class="ltx_break"></span>
<span class="ltx_text" style="color:#000099;">linel: 66$</span></p>
</blockquote>
</div>
<div id="S8.p7" class="ltx_para">
<p class="ltx_p">The first command prevents Maxima from showing warning messages every
time a floating-point number is replaced by a fraction, something many
Maxima functions do, and the second command limits the maximum length
of output lines to 66 characters. In a <em class="ltx_emph ltx_font_italic">Linux</em> system that
file would be located in <span class="ltx_text ltx_font_typewriter">/home/username/.maxima/</span>.</p>
</div>
<div id="S8.p8" class="ltx_para">
<p class="ltx_p">Any other valid Maxima commands can be placed into that file, but make
extra sure that the commands you put have been testes, because any
errors will prevent Maxima from starting until you remove or correct
that initial batch file.</p>
</div>
</section>
<section id="S9" class="ltx_section">
<h2 class="ltx_title ltx_title_section">
<span class="ltx_tag ltx_tag_section">9 </span>Algebra</h2>
<div id="S9.p1" class="ltx_para">
<p class="ltx_p">Expressions can include mathematical functions as the function cosine
in the following example</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i33)</span> <span class="ltx_text" style="color:#000099;">3*x^2 + 2*cos(t)$</span></p>
</blockquote>
</div>
<div id="S9.p2" class="ltx_para">
<p class="ltx_p">Those expressions can then be manipulated producing new
expressions. In the next example we find the square of the expression
above and add <math id="S9.p2.m1" class="ltx_Math" alttext="x^{3}" display="inline"><msup><mi>x</mi><mn>3</mn></msup></math> to it</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i34)</span> <span class="ltx_text" style="color:#000099;">%^2 + x^3;
<br class="ltx_break"></span>
(%o34) <math id="S9.p2.m2" class="ltx_Math" alttext="\left(3\,x^{2}+2\,\cos t\right)^{2}+x^{3}" display="inline"><mrow><msup><mrow><mo>(</mo><mrow><mrow><mn>3</mn><mspace width=0.166em /><msup><mi>x</mi><mn>2</mn></msup></mrow><mo>+</mo><mrow><mn>2</mn><mspace width=0.166em /><mrow><mi>cos</mi><mspace width=0.11em /><mi>t</mi></mrow></mrow></mrow><mo>)</mo></mrow><mn>2</mn></msup><mo>+</mo><msup><mi>x</mi><mn>3</mn></msup></mrow></math></p>
</blockquote>
</div>
<div id="S9.p3" class="ltx_para">
<p class="ltx_p">As we have already mentioned besides numbers and expressions, other
kind of object we can manipulate is an equation as the following one</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i35)</span> <span class="ltx_text" style="color:#000099;">3*x^3 + 5*x^2 = x - 6;
<br class="ltx_break"></span>
(%o35) <math id="S9.p3.m1" class="ltx_Math" alttext="3\,x^{3}+5\,x^{2}=x-6" display="inline"><mrow><mrow><mrow><mn>3</mn><mspace width=0.166em /><msup><mi>x</mi><mn>3</mn></msup></mrow><mo>+</mo><mrow><mn>5</mn><mspace width=0.166em /><msup><mi>x</mi><mn>2</mn></msup></mrow></mrow><mo>=</mo><mrow><mi>x</mi><mo>−</mo><mn>6</mn></mrow></mrow></math></p>
</blockquote>
</div>
<div id="S9.p4" class="ltx_para">
<p class="ltx_p">Most functions used to manipulate expressions can also be used for
equations. For example, Maxima’s function <span class="ltx_text" style="color:#000099;">allroots</span> finds a
numerical approximation to the roots of a polynomial, such as
<math id="S9.p4.m1" class="ltx_Math" alttext="x^{2}+x-1" display="inline"><mrow><mrow><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><mi>x</mi></mrow><mo>−</mo><mn>1</mn></mrow></math>; if <span class="ltx_text" style="color:#000099;">allroots</span> is given the equation <math id="S9.p4.m2" class="ltx_Math" alttext="x^{2}+x=1" display="inline"><mrow><mrow><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><mi>x</mi></mrow><mo>=</mo><mn>1</mn></mrow></math>, it will
interpreted as <math id="S9.p4.m3" class="ltx_Math" alttext="x^{2}+x-1=0" display="inline"><mrow><mrow><mrow><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><mi>x</mi></mrow><mo>−</mo><mn>1</mn></mrow><mo>=</mo><mn>0</mn></mrow></math> and find the roots of <math id="S9.p4.m4" class="ltx_Math" alttext="x^{2}+x-1" display="inline"><mrow><mrow><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><mi>x</mi></mrow><mo>−</mo><mn>1</mn></mrow></math>. Therefore,
when given the expression in <code class="ltx_verbatim ltx_font_typewriter">(%o35)</code>, <span class="ltx_text" style="color:#000099;">allroots</span> will find
the roots of <math id="S9.p4.m5" class="ltx_Math" alttext="3\,x^{3}+5\,x-x+6" display="inline"><mrow><mrow><mrow><mrow><mn>3</mn><mspace width=0.166em /><msup><mi>x</mi><mn>3</mn></msup></mrow><mo>+</mo><mrow><mn>5</mn><mspace width=0.166em /><mi>x</mi></mrow></mrow><mo>−</mo><mi>x</mi></mrow><mo>+</mo><mn>6</mn></mrow></math></p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i36)</span> <span class="ltx_text" style="color:#000099;">allroots(%o35);
<br class="ltx_break"></span>
(%o36) <math id="S9.p4.m6" class="ltx_Math" alttext="\left[x=0.9073\,\mathrm{i}+0.2776,\;x=0.2776-0.9073\,\mathrm{i},\;x=-2.222\right]" display="inline"><mrow><mo>[</mo><mrow><mrow><mi>x</mi><mo>=</mo><mrow><mrow><mn>0.9073</mn><mspace width=0.166em /><mi mathvariant="normal">i</mi></mrow><mo>+</mo><mn>0.2776</mn></mrow></mrow><mo rspace="5.3pt">,</mo><mrow><mrow><mi>x</mi><mo>=</mo><mrow><mn>0.2776</mn><mo>−</mo><mrow><mn>0.9073</mn><mspace width=0.166em /><mi mathvariant="normal">i</mi></mrow></mrow></mrow><mo rspace="5.3pt">,</mo><mrow><mi>x</mi><mo>=</mo><mrow><mo>−</mo><mn>2.222</mn></mrow></mrow></mrow></mrow><mo>]</mo></mrow></math></p>
</blockquote>
</div>
<div id="S9.p5" class="ltx_para">
<p class="ltx_p">Two of those roots are complex numbers. The three roots are shown as
a list of three equations, instead of just numbers. That way of
presenting the result may seem odd, but it will prove convenient to
interact with other functions of Maxima. For example, to
check that the third root shown is in fact a root of the polynomial
<math id="S9.p5.m1" class="ltx_Math" alttext="3\,x^{3}+5\,x-x+6" display="inline"><mrow><mrow><mrow><mrow><mn>3</mn><mspace width=0.166em /><msup><mi>x</mi><mn>3</mn></msup></mrow><mo>+</mo><mrow><mn>5</mn><mspace width=0.166em /><mi>x</mi></mrow></mrow><mo>−</mo><mi>x</mi></mrow><mo>+</mo><mn>6</mn></mrow></math>, we write</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i37)</span> <span class="ltx_text" style="color:#000099;">subst(%o36[3], 3*x^3+5*x^2-x+6);
<br class="ltx_break"></span>
(%o37) <math id="S9.p5.m2" class="ltx_Math" alttext="7.105\mathrm{e}-15" display="inline"><mrow><mrow><mn>7.105</mn><mspace width=0.166em /><mi mathvariant="normal">e</mi></mrow><mo>−</mo><mn>15</mn></mrow></math></p>
</blockquote>
</div>
<div id="S9.p6" class="ltx_para">
<p class="ltx_p">The notation <span class="ltx_text" style="color:#000099;">%o36[3]</span> means the third
element in the list associated to variable <span class="ltx_text" style="color:#000099;">%o36</span>, which is the
equation <math id="S9.p6.m1" class="ltx_Math" alttext="x=-2.222" display="inline"><mrow><mi>x</mi><mo>=</mo><mrow><mo>−</mo><mn>2.222</mn></mrow></mrow></math> and it is exactly what we need to tell
<span class="ltx_text" style="color:#000099;">subst</span> to substitute <math id="S9.p6.m2" class="ltx_Math" alttext="x" display="inline"><mi>x</mi></math> by <math id="S9.p6.m3" class="ltx_Math" alttext="-2.222" display="inline"><mrow><mo>−</mo><mn>2.222</mn></mrow></math>. It is in fact substituted
to by <math id="S9.p6.m4" class="ltx_Math" alttext="-2.221834293486762" display="inline"><mrow><mo>−</mo><mn>2.221834293486762</mn></mrow></math> which is the value stored in list
<span class="ltx_text" style="color:#000099;">%o36</span>; result <code class="ltx_verbatim ltx_font_typewriter">(%o36)</code> is the exact result rounded to 4
significant digits. The result <code class="ltx_verbatim ltx_font_typewriter">(%o37)</code> is not zero, because
<span class="ltx_text" style="color:#000099;">allroots</span> is a numerical and its results have a numerical error
which in the double-precision format is of the order of <math id="S9.p6.m5" class="ltx_Math" alttext="10^{-15}" display="inline"><msup><mn>10</mn><mrow><mo>−</mo><mn>15</mn></mrow></msup></math>.</p>
</div>
<div id="S9.p7" class="ltx_para">
<p class="ltx_p">There are other functions to find the exact solution to an algebraic
equation without numerical approximations. Function <span class="ltx_text" style="color:#000099;">solve</span> can
find the exact solutions to equation <code class="ltx_verbatim ltx_font_typewriter">%o35</code>, but the result is so
long that rather than showing it to you we will save it in a variable
named <span class="ltx_text" style="color:#000099;">result</span> and will show you only the last root which is
real:</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i38)</span> result: <span class="ltx_text" style="color:#000099;">solve ( 3*x^3 + 5*x^2 = x - 6, x )$
<br class="ltx_break"></span>
<span class="ltx_text" style="color:#CC3333;">(%i39)</span> <span class="ltx_text" style="color:#000099;">xthru (result[3]);
<br class="ltx_break"></span>
(%o39) <math id="S9.p7.m1" class="ltx_Math" alttext="x=\dfrac{\left(3^{\frac{5}{2}}\,\sqrt{13331}-1843\right)^{\frac{2}{3}}+2^{%
\frac{1}{3}}\,\left(17\,2^{\frac{4}{3}}-5\,\left(3^{\frac{5}{2}}\,\sqrt{13331}%
-1843\right)^{\frac{1}{3}}\right)}{9\,2^{\frac{1}{3}}\,\left(3^{\frac{5}{2}}\,%
\sqrt{13331}-1843\right)^{\frac{1}{3}}}" display="inline"><mrow><mi>x</mi><mo>=</mo><mstyle displaystyle="true"><mfrac><mrow><msup><mrow><mo>(</mo><mrow><mrow><msup><mn>3</mn><mfrac><mn>5</mn><mn>2</mn></mfrac></msup><mspace width=0.166em /><msqrt><mn>13331</mn></msqrt></mrow><mo>−</mo><mn>1843</mn></mrow><mo>)</mo></mrow><mfrac><mn>2</mn><mn>3</mn></mfrac></msup><mo>+</mo><mrow><msup><mn>2</mn><mfrac><mn>1</mn><mn>3</mn></mfrac></msup><mspace width=0.166em /><mrow><mo>(</mo><mrow><msup><mn>17 2</mn><mfrac><mn>4</mn><mn>3</mn></mfrac></msup><mo>−</mo><mrow><mn>5</mn><mspace width=0.166em /><msup><mrow><mo>(</mo><mrow><mrow><msup><mn>3</mn><mfrac><mn>5</mn><mn>2</mn></mfrac></msup><mspace width=0.166em /><msqrt><mn>13331</mn></msqrt></mrow><mo>−</mo><mn>1843</mn></mrow><mo>)</mo></mrow><mfrac><mn>1</mn><mn>3</mn></mfrac></msup></mrow></mrow><mo>)</mo></mrow></mrow></mrow><mrow><msup><mn>9 2</mn><mfrac><mn>1</mn><mn>3</mn></mfrac></msup><mspace width=0.166em /><msup><mrow><mo>(</mo><mrow><mrow><msup><mn>3</mn><mfrac><mn>5</mn><mn>2</mn></mfrac></msup><mspace width=0.166em /><msqrt><mn>13331</mn></msqrt></mrow><mo>−</mo><mn>1843</mn></mrow><mo>)</mo></mrow><mfrac><mn>1</mn><mn>3</mn></mfrac></msup></mrow></mfrac></mstyle></mrow></math></p>
</blockquote>
</div>
<div id="S9.p8" class="ltx_para">
<p class="ltx_p">Function <span class="ltx_text" style="color:#000099;">xthru</span> combined the terms in the expression into a
common denominator, without expanding products. In this case that
resulted into a simpler expression. There are other functions to
simplify or show expressions in a different form, including
<span class="ltx_text" style="color:#000099;">ratsimp</span> and <span class="ltx_text" style="color:#000099;">radcan</span>; which one of them gives a simpler
result depends on the expression. And what we mean by simpler is a
matter of personal taste, so we should try all those functions to
decide which result we prefer (they are equivalent, just
different). That is also why it is a good practice to save results
before displaying them.</p>
</div>
<div id="S9.p9" class="ltx_para">
<p class="ltx_p">You can also try to look at the two complex roots in <span class="ltx_text" style="color:#000099;">result</span>,
using function <span class="ltx_text" style="color:#000099;">rectform</span> to separate the real and imaginary
parts.</p>
</div>
<div id="S9.p10" class="ltx_para">
<p class="ltx_p">Systems of linear equations and some nonlinear systems can also be
solved using <span class="ltx_text" style="color:#000099;">solve</span>. The two equations must be given into a
list, as in the following example</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i40)</span> <span class="ltx_text" style="color:#000099;">exp1: (4 + 8)*x1 - 8* x2 = 6 + 4$
<br class="ltx_break"></span>
<span class="ltx_text" style="color:#CC3333;">(%i41)</span> <span class="ltx_text" style="color:#000099;">exp2: (2 + 8 + 5 + 1)*x2 - 8*x1 = -4$
<br class="ltx_break"></span>
<span class="ltx_text" style="color:#CC3333;">(%i42)</span> <span class="ltx_text" style="color:#000099;">solve ( [exp1, exp2], [x1, x2] );
<br class="ltx_break"></span>
(%o42) <math id="S9.p10.m1" class="ltx_Math" alttext="\left[\;\left[x1=1,\;x2=\dfrac{1}{4}\right]\;\right]" display="inline"><mrow><mo>[</mo><mrow><mo lspace="5.3pt">[</mo><mrow><mrow><mrow><mi>x</mi><mspace width=0.166em /><mn>1</mn></mrow><mo>=</mo><mn>1</mn></mrow><mo rspace="5.3pt">,</mo><mrow><mrow><mi>x</mi><mspace width=0.166em /><mn>2</mn></mrow><mo>=</mo><mstyle displaystyle="true"><mfrac><mn>1</mn><mn>4</mn></mfrac></mstyle></mrow></mrow><mo rspace="5.3pt">]</mo></mrow><mo>]</mo></mrow></math></p>
</blockquote>
</div>
<div id="S9.p11" class="ltx_para">
<p class="ltx_p">There are two features of <span class="ltx_text" style="color:#000099;">solve</span> involved in the previous
example. First, instead of 2 equations, we provided two expressions;
every expression given to <span class="ltx_text" style="color:#000099;">solve</span> is then interpreted as that
expression being equal to zero. Second, there is an optional argument,
after the equations, with the variable or list of variables to be
solved; if given, the number of variables must be equal to the number
of equations. In the examples we have given there is no need to name
the variables, because those variables are the only ones that appear
in the equations. However, in some cases the name of the variables is
necessary; for instance to solve just one equation <math id="S9.p11.m1" class="ltx_Math" alttext="x/y^{2}=\sqrt{z}" display="inline"><mrow><mrow><mi>x</mi><mo>/</mo><msup><mi>y</mi><mn>2</mn></msup></mrow><mo>=</mo><msqrt><mi>z</mi></msqrt></mrow></math>
with three variables, we must specify what variable we want to get
in terms of the other two.</p>
</div>
<div id="S9.p12" class="ltx_para">
<p class="ltx_p">The result <code class="ltx_verbatim ltx_font_typewriter">(%o42)</code> is a list within another list, because the first
list encloses the values of the variables and the second list
encloses the various possible solutions to the system, which
in this case was only one.</p>
</div>
<div id="S9.p13" class="ltx_para">
<p class="ltx_p">Function <span class="ltx_text" style="color:#000099;">expand</span> will expand products and powers of
expressions, as in the following example</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i43)</span> <span class="ltx_text" style="color:#000099;">expand ((4*x^2*y + 2*y^2)^3);
<br class="ltx_break"></span>
(%o43) <math id="S9.p13.m1" class="ltx_Math" alttext="8\,y^{6}+48\,x^{2}\,y^{5}+96\,x^{4}\,y^{4}+64\,x^{6}\,y^{3}" display="inline"><mrow><mrow><mn>8</mn><mspace width=0.166em /><msup><mi>y</mi><mn>6</mn></msup></mrow><mo>+</mo><mrow><mn>48</mn><mspace width=0.166em /><msup><mi>x</mi><mn>2</mn></msup><mspace width=0.166em /><msup><mi>y</mi><mn>5</mn></msup></mrow><mo>+</mo><mrow><mn>96</mn><mspace width=0.166em /><msup><mi>x</mi><mn>4</mn></msup><mspace width=0.166em /><msup><mi>y</mi><mn>4</mn></msup></mrow><mo>+</mo><mrow><mn>64</mn><mspace width=0.166em /><msup><mi>x</mi><mn>6</mn></msup><mspace width=0.166em /><msup><mi>y</mi><mn>3</mn></msup></mrow></mrow></math></p>
</blockquote>
</div>
<div id="S9.p14" class="ltx_para">
<p class="ltx_p">Function <span class="ltx_text" style="color:#000099;">subst</span>, which we used before to substitute numerical
values, can also be used to substitute other expressions. In the next
example we substitute <math id="S9.p14.m1" class="ltx_Math" alttext="x" display="inline"><mi>x</mi></math> by <math id="S9.p14.m2" class="ltx_Math" alttext="1/z" display="inline"><mrow><mn>1</mn><mo>/</mo><mi>z</mi></mrow></math>, and <math id="S9.p14.m3" class="ltx_Math" alttext="y" display="inline"><mi>y</mi></math> by <math id="S9.p14.m4" class="ltx_Math" alttext="\sqrt{z}" display="inline"><msqrt><mi>z</mi></msqrt></math> in the
expression <code class="ltx_verbatim ltx_font_typewriter">(%o43)</code></p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i44)</span> <span class="ltx_text" style="color:#000099;">subst([x=1/z, y=sqrt(z)], %o43);
<br class="ltx_break"></span>
(%o44) <math id="S9.p14.m5" class="ltx_Math" alttext="8\,z^{3}+48\,\sqrt{z}+\dfrac{96}{z^{2}}+\dfrac{64}{z^{\frac{9}{2}}}" display="inline"><mrow><mrow><mn>8</mn><mspace width=0.166em /><msup><mi>z</mi><mn>3</mn></msup></mrow><mo>+</mo><mrow><mn>48</mn><mspace width=0.166em /><msqrt><mi>z</mi></msqrt></mrow><mo>+</mo><mstyle displaystyle="true"><mfrac><mn>96</mn><msup><mi>z</mi><mn>2</mn></msup></mfrac></mstyle><mo>+</mo><mstyle displaystyle="true"><mfrac><mn>64</mn><msup><mi>z</mi><mfrac><mn>9</mn><mn>2</mn></mfrac></msup></mfrac></mstyle></mrow></math></p>
</blockquote>
</div>
<div id="S9.p15" class="ltx_para">
<p class="ltx_p">We will now simplify that result with <span class="ltx_text" style="color:#000099;">ratsimp</span> and save it into
a variable <span class="ltx_text" style="color:#000099;">r</span></p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i45)</span> <span class="ltx_text" style="color:#000099;">r: ratsimp(%);
<br class="ltx_break"></span>
(%o45) <math id="S9.p15.m1" class="ltx_Math" alttext="\dfrac{\sqrt{z}\,\left(8\,z^{7}+96\,z^{2}\right)+48\,z^{5}+64}{z^{\frac{9}{2}}}" display="inline"><mstyle displaystyle="true"><mfrac><mrow><mrow><msqrt><mi>z</mi></msqrt><mspace width=0.166em /><mrow><mo>(</mo><mrow><mrow><mn>8</mn><mspace width=0.166em /><msup><mi>z</mi><mn>7</mn></msup></mrow><mo>+</mo><mrow><mn>96</mn><mspace width=0.166em /><msup><mi>z</mi><mn>2</mn></msup></mrow></mrow><mo>)</mo></mrow></mrow><mo>+</mo><mrow><mn>48</mn><mspace width=0.166em /><msup><mi>z</mi><mn>5</mn></msup></mrow><mo>+</mo><mn>64</mn></mrow><msup><mi>z</mi><mfrac><mn>9</mn><mn>2</mn></mfrac></msup></mfrac></mstyle></math></p>
</blockquote>
</div>
<div id="S9.p16" class="ltx_para">
<p class="ltx_p">Algebraic expressions are represented internally as lists; hence, some
Maxima functions for lists can also be used with expressions. For
instance, function <span class="ltx_text" style="color:#000099;">length</span> gives the length of a list and it can
also be used to compute the number of terms in an expression; for
instance,</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i46)</span> <span class="ltx_text" style="color:#000099;">length(r);
<br class="ltx_break"></span>
(%o46) <math id="S9.p16.m1" class="ltx_Math" alttext="2" display="inline"><mn>2</mn></math></p>
</blockquote>
</div>
<div id="S9.p17" class="ltx_para">
<p class="ltx_p">Since the expression <span class="ltx_text" style="color:#000099;">r</span> was combined into a single fraction, the corresponding list has two elements, the numerator
and denominator of that fraction. However, the two elements of the
expression cannot be obtained with <span class="ltx_text" style="color:#000099;">r[1]</span> and <span class="ltx_text" style="color:#000099;">r[2]</span> as we
have previously done with regular lists. In this case we have to use
the functions <span class="ltx_text" style="color:#000099;">first</span> and <span class="ltx_text" style="color:#000099;">second</span>. The following command
shows the numerator of <span class="ltx_text" style="color:#000099;">r</span></p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i47)</span> <span class="ltx_text" style="color:#000099;">first(r);
<br class="ltx_break"></span>
(%o47) <math id="S9.p17.m1" class="ltx_Math" alttext="\sqrt{z}\,\left(8\,z^{7}+96\,z^{2}\right)+48\,z^{5}+64" display="inline"><mrow><mrow><msqrt><mi>z</mi></msqrt><mspace width=0.166em /><mrow><mo>(</mo><mrow><mrow><mn>8</mn><mspace width=0.166em /><msup><mi>z</mi><mn>7</mn></msup></mrow><mo>+</mo><mrow><mn>96</mn><mspace width=0.166em /><msup><mi>z</mi><mn>2</mn></msup></mrow></mrow><mo>)</mo></mrow></mrow><mo>+</mo><mrow><mn>48</mn><mspace width=0.166em /><msup><mi>z</mi><mn>5</mn></msup></mrow><mo>+</mo><mn>64</mn></mrow></math></p>
</blockquote>
<p class="ltx_p">and the length of that expression is</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i48)</span> <span class="ltx_text" style="color:#000099;">length(%);
<br class="ltx_break"></span>
(%o48) <math id="S9.p17.m2" class="ltx_Math" alttext="3" display="inline"><mn>3</mn></math></p>
</blockquote>
<p class="ltx_p">because it is the sum of three other expressions.</p>
</div>
<div id="S9.p18" class="ltx_para">
<p class="ltx_p">A Maxima expression that cannot be further separated into other
sub-expressions, for instance <math id="S9.p18.m1" class="ltx_Math" alttext="x" display="inline"><mi>x</mi></math> or <math id="S9.p18.m2" class="ltx_Math" alttext="-3.5" display="inline"><mrow><mo>−</mo><mn>3.5</mn></mrow></math>, is dubbed an
<em class="ltx_emph ltx_font_italic">atom</em>; functions that expect a list as its argument will
usually trigger an error when they are given an atom as the argument.
Function <span class="ltx_text" style="color:#000099;">atom</span> tells whether the argument given is an atom or
not.</p>
</div>
<div id="S9.p19" class="ltx_para">
<p class="ltx_p">A very useful function to manipulate lists or expressions is <span class="ltx_text" style="color:#000099;">map</span>,
which will apply a given function to each element in a
list. Here is an example: suppose we have the following expression,
which we will save into a variable <span class="ltx_text" style="color:#000099;">f</span></p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i49)</span> <span class="ltx_text" style="color:#000099;">f: (x+y)^2 / (x-y)^2;
<br class="ltx_break"></span>
(%o49) <math id="S9.p19.m1" class="ltx_Math" alttext="\dfrac{\left(y+x\right)^{2}}{\left(x-y\right)^{2}}" display="inline"><mstyle displaystyle="true"><mfrac><msup><mrow><mo>(</mo><mrow><mi>y</mi><mo>+</mo><mi>x</mi></mrow><mo>)</mo></mrow><mn>2</mn></msup><msup><mrow><mo>(</mo><mrow><mi>x</mi><mo>−</mo><mi>y</mi></mrow><mo>)</mo></mrow><mn>2</mn></msup></mfrac></mstyle></math></p>
</blockquote>
</div>
<div id="S9.p20" class="ltx_para">
<p class="ltx_p">We now would like to expand the squares in the numerator and
denominator, but if we try to expand <span class="ltx_text" style="color:#000099;">f</span>, the result is the
following</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i50)</span> <span class="ltx_text" style="color:#000099;">expand (f);
<br class="ltx_break"></span>
(%o50) <math id="S9.p20.m1" class="ltx_Math" alttext="\dfrac{y^{2}}{y^{2}-2\,x\,y+x^{2}}+\dfrac{2\,x\,y}{y^{2}-2\,x\,y+x^{2}}+\dfrac%
{x^{2}}{y^{2}-2\,x\,y+x^{2}}" display="inline"><mrow><mstyle displaystyle="true"><mfrac><msup><mi>y</mi><mn>2</mn></msup><mrow><mrow><msup><mi>y</mi><mn>2</mn></msup><mo>−</mo><mrow><mn>2</mn><mspace width=0.166em /><mi>x</mi><mspace width=0.166em /><mi>y</mi></mrow></mrow><mo>+</mo><msup><mi>x</mi><mn>2</mn></msup></mrow></mfrac></mstyle><mo>+</mo><mstyle displaystyle="true"><mfrac><mrow><mn>2</mn><mspace width=0.166em /><mi>x</mi><mspace width=0.166em /><mi>y</mi></mrow><mrow><mrow><msup><mi>y</mi><mn>2</mn></msup><mo>−</mo><mrow><mn>2</mn><mspace width=0.166em /><mi>x</mi><mspace width=0.166em /><mi>y</mi></mrow></mrow><mo>+</mo><msup><mi>x</mi><mn>2</mn></msup></mrow></mfrac></mstyle><mo>+</mo><mstyle displaystyle="true"><mfrac><msup><mi>x</mi><mn>2</mn></msup><mrow><mrow><msup><mi>y</mi><mn>2</mn></msup><mo>−</mo><mrow><mn>2</mn><mspace width=0.166em /><mi>x</mi><mspace width=0.166em /><mi>y</mi></mrow></mrow><mo>+</mo><msup><mi>x</mi><mn>2</mn></msup></mrow></mfrac></mstyle></mrow></math></p>
</blockquote>
</div>
<div id="S9.p21" class="ltx_para">
<p class="ltx_p">The fraction was also expanded into 3 other fractions, which is not
what we wanted. If we map <span class="ltx_text" style="color:#000099;">expand</span> to the two terms of the
fraction, the numerator and denominator will be expanded separately
giving the following result</p>
<blockquote class="ltx_quote ltx_role_verse">
<p class="ltx_p"><span class="ltx_text" style="color:#CC3333;">(%i51)</span> <span class="ltx_text" style="color:#000099;">map (expand, f);
<br class="ltx_break"></span>
(%o51) <math id="S9.p21.m1" class="ltx_Math" alttext="\dfrac{y^{2}+2\,x\,y+x^{2}}{y^{2}-2\,x\,y+x^{2}}" display="inline"><mstyle displaystyle="true"><mfrac><mrow><msup><mi>y</mi><mn>2</mn></msup><mo>+</mo><mrow><mn>2</mn><mspace width=0.166em /><mi>x</mi><mspace width=0.166em /><mi>y</mi></mrow><mo>+</mo><msup><mi>x</mi><mn>2</mn></msup></mrow><mrow><mrow><msup><mi>y</mi><mn>2</mn></msup><mo>−</mo><mrow><mn>2</mn><mspace width=0.166em /><mi>x</mi><mspace width=0.166em /><mi>y</mi></mrow></mrow><mo>+</mo><msup><mi>x</mi><mn>2</mn></msup></mrow></mfrac></mstyle></math></p>
</blockquote>
</div>
</section>
<section id="S10" class="ltx_section">
<h2 class="ltx_title ltx_title_section">
<span class="ltx_tag ltx_tag_section">10 </span>Trigonometry</h2>
<div id="S10.p1" class="ltx_para">
<p class="ltx_p">Table <a href="#S10.T1" title="Table 1 ‣ 10 Trigonometry ‣ A Maxima tutorial" class="ltx_ref"><span class="ltx_text ltx_ref_tag">1</span></a> shows the names of the main trigonometric
functions in Maxima. Angles are given in radians, and not in degrees.</p>
</div>
<figure id="S10.T1" class="ltx_table">
<figcaption class="ltx_caption ltx_centering"><span class="ltx_tag ltx_tag_table">Table 1: </span>Trigonometric functions</figcaption>
<table class="ltx_tabular ltx_centering ltx_guessed_headers ltx_align_middle">
<thead class="ltx_thead">
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left ltx_th ltx_th_column ltx_border_tt" style="padding-bottom:8.0pt;"><span class="ltx_text ltx_font_bold">Function<span class="ltx_text ltx_phantom"><span style="visibility:hidden">mm</span></span></span></td>
<td class="ltx_td ltx_align_left ltx_th ltx_th_column ltx_border_tt" style="padding-bottom:8.0pt;"><span class="ltx_text ltx_font_bold">Description</span></td>
</tr>
</thead>
<tbody class="ltx_tbody">
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left ltx_border_t" style="padding-bottom:8.0pt;"><span class="ltx_text" style="color:#000099;">sin(x)</span></td>
<td class="ltx_td ltx_align_left ltx_border_t" style="padding-bottom:8.0pt;">Sin</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left" style="padding-bottom:8.0pt;"><span class="ltx_text" style="color:#000099;">cos(x)</span></td>
<td class="ltx_td ltx_align_left" style="padding-bottom:8.0pt;">Cosine</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left" style="padding-bottom:8.0pt;"><span class="ltx_text" style="color:#000099;">tan(x)</span></td>
<td class="ltx_td ltx_align_left" style="padding-bottom:8.0pt;">Tangent</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left" style="padding-bottom:8.0pt;"><span class="ltx_text" style="color:#000099;">sec(x)</span></td>
<td class="ltx_td ltx_align_left" style="padding-bottom:8.0pt;">Secant</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left" style="padding-bottom:8.0pt;"><span class="ltx_text" style="color:#000099;">csc(x)</span></td>
<td class="ltx_td ltx_align_left" style="padding-bottom:8.0pt;">Cosecant</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left" style="padding-bottom:8.0pt;"><span class="ltx_text" style="color:#000099;">cot(x)</span></td>
<td class="ltx_td ltx_align_left" style="padding-bottom:8.0pt;">Cotangent</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left" style="padding-bottom:8.0pt;"><span class="ltx_text" style="color:#000099;">asin(x)</span></td>
<td class="ltx_td ltx_align_left" style="padding-bottom:8.0pt;">Arc sine</td>