-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomputer-algebra.html
More file actions
2402 lines (2390 loc) · 91.9 KB
/
computer-algebra.html
File metadata and controls
2402 lines (2390 loc) · 91.9 KB
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 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
<link rel="icon" type="image/gif" href="/favicon.gif"/>
<link rel="apple-touch-icon" sizes="120x120" href="touch-icon-iphone-retina.png" />
<link rel="apple-touch-icon" sizes="152x152" href="touch-icon-ipad-retina.png" />
<title>Lorem Ipsum</title>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<style type="text/css" id="internal-style">
@import url(hyperpolyglot.css);
</style>
<meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
<meta http-equiv="content-language" content="en"/>
</head>
<body>
<div id="container-wrap-wrap">
<div id="container-wrap">
<div id="container">
<div id="header">
<h1><a href="/"><span>Hyperpolyglot</span></a></h1>
</div>
<div id="content-wrap">
<div id="main-content">
<div id="page-title">Lorem Ipsum</div>
<div id="page-content">
<p><em>a side-by-side reference sheet</em></p>
<p><strong>sheet one:</strong> <a href="#grammar-invocation">grammar and invocation</a> | <a href="#var-expr">variables and expressions</a> | <a href="#arithmetic-logic">arithmetic and logic</a> | <a href="#strings">strings</a> | <a href="#arrays">arrays</a> | <a href="#sets">sets</a> | <a href="#arith-seq">arithmetic sequences</a> | <a href="#dictionaries">dictionaries</a> | <a href="#functions">functions</a> | <a href="#execution-control">execution control</a> | <a href="#exceptions">exceptions</a> | <a href="#streams">streams</a> | <a href="#files">files</a> | <a href="#directories">directories</a> | <a href="#libraries-namespaces">libraries and namespaces</a> | <a href="#reflection">reflection</a></p>
<p><strong><a href="/computer-algebra2">sheet two:</a></strong> <a href="/computer-algebra2#symbolic-expr">symbolic expressions</a> | <a href="/computer-algebra2#calculus">calculus</a> | <a href="/computer-algebra2#equations-unknowns">equations and unknowns</a> | <a href="/computer-algebra2#optimization">optimization</a> | <a href="/computer-algebra2#vectors">vectors</a> | <a href="/computer-algebra2#matrices">matrices</a> | <a href="/computer-algebra2#combinatorics">combinatorics</a> | <a href="/computer-algebra2#number-theory">number theory</a> | <a href="/computer-algebra2#polynomials">polynomials</a> | <a href="/computer-algebra2#trigonometry">trigonometry</a> | <a href="/computer-algebra2#special-functions">special functions</a> | <a href="/computer-algebra2#permutations">permutations</a> | <a href="/computer-algebra2#descriptive-statistics">descriptive statistics</a> | <a href="/computer-algebra2#distributions">distributions</a> | <a href="/computer-algebra2#statistical-tests">statistical tests</a></p>
<p><a href="/computer-algebra2#bar-charts">bar charts</a> | <a href="/computer-algebra2#scatter-plots">scatter plots</a> | <a href="/computer-algebra2#line-charts">line charts</a> | <a href="/computer-algebra2#surface-charts">surface charts</a> | <a href="/computer-algebra2#chart-options">chart options</a></p>
<table class="wiki-content-table">
<tr>
<th></th>
<th><a href="#mathematica">mathematica</a></th>
<th><a href="#sympy">sympy</a></th>
<th><a href="#sage">sage</a></th>
<th><a href="#maxima">maxima</a></th>
</tr>
<tr>
<td><a name="version-used"></a><a href="#version-used-note">version used</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td><span style="color: gray"><em>10.0</em></span></td>
<td><span style="color: gray"><em>Python 2.7; SymPy 0.7</em></span></td>
<td><span style="color: gray"><em>6.10</em></span></td>
<td><span style="color: gray"><em>5.37</em></span></td>
</tr>
<tr>
<td><a name="show-version"></a><a href="#show-version-note">show version</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td><span style="color: gray"><em>select</em> About Mathematica <em>in</em> Mathematica <em>menu</em></span></td>
<td><span style="white-space: pre-wrap;">sympy.__version__</span></td>
<td>$ sage <span style="white-space: pre-wrap;">--</span>version<br />
<br />
<span style="color: gray"><em>also displayed on worksheet</em></span></td>
<td>$ maxima <span style="white-space: pre-wrap;">--</span>version</td>
</tr>
<tr>
<td><a name="implicit-prologue"></a><a href="#implicit-prologue-note">implicit prologue</a></td>
<td> </td>
<td>from sympy import *<br />
<br />
<span style="color: gray"># enable LaTeX rendering in Jupyter notebook:</span><br />
init_printing()<br />
<br />
<span style="color: gray"># unknown variables must be declared:</span><br />
x, y = symbols('x y')</td>
<td><span style="color: gray"># unknowns other than x must be declared:</span><br />
y = var('y')</td>
<td> </td>
</tr>
<tr>
<th colspan="5"><a name="grammar-invocation"></a><a href="#grammar-invocation-note">grammar and invocation</a></th>
</tr>
<tr>
<th></th>
<th>mathematica</th>
<th>sympy</th>
<th>sage</th>
<th>maxima</th>
</tr>
<tr>
<td><a name="interpreter"></a><a href="#interpreter-note">interpreter</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>$ cat <span style="white-space: pre-wrap;">></span> hello.m<br />
Print["Hello, World!"]<br />
<br />
$ MathKernel -script hello.m</td>
<td><span style="color: gray"><em>if</em> foo.py <em>imports sympy:</em></span><br />
$ python <span style="color: gray"><em>foo</em></span>.py</td>
<td>$ cat > hello.sage<br />
print("Hello, World!")<br />
<br />
$ sage hello.sage</td>
<td>$ cat <span style="white-space: pre-wrap;">>></span> hello.max<br />
print("Hello, world!");<br />
<br />
$ maxima -b hello.maxima</td>
</tr>
<tr>
<td><a name="repl"></a><a href="#repl-note">repl</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>$ MathKernel</td>
<td>$ python<br />
<span style="white-space: pre-wrap;">>>></span> from sympy import *</td>
<td>$ sage</td>
<td>$ maxima</td>
</tr>
<tr>
<td><a name="block-delimiters"></a><a href="#block-delimiters-note">block delimiters</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>( <span style="color: gray"><em>stmt</em></span>; <span style="color: gray"><em>...</em></span>)</td>
<td>: <span style="color: gray"><em>and offside rule</em></span></td>
<td>: <span style="color: gray"><em>and offside rule</em></span></td>
<td>block([x: 3, y: 4], x + y);<br />
<br />
<span style="color: gray">/* Multiple stmts are separated by commas; a list of assignments can be used to set variables local to the block. */</span></td>
</tr>
<tr>
<td><a name="stmt-separator"></a><a href="#stmt-separator-note">statement separator</a></td>
<td>; <span style="color: gray"><em>or sometimes newline</em></span><br />
<br />
<span style="color: gray"><em>A semicolon suppresses echoing value of previous expression.</em></span></td>
<td><span style="color: gray"><em>newline or</em></span> ;<br />
<br />
<span style="color: gray">//newlines not separators inside (), [], {}, triple quote literals, or after backslash: <span style="white-space: pre-wrap;">\</span>//</span>//</td>
<td><span style="color: gray"><em>newline or</em></span> ;<br />
<br />
<span style="color: gray">//newlines not separators inside (), [], {}, triple quote literals, or after backslash: <span style="white-space: pre-wrap;">\</span>//</span>//</td>
<td>; <span style="color: gray"><em>or</em></span> $<br />
<br />
<span style="color: gray"><em>The dollar sign</em> $ <em>suppresses output.</em></span></td>
</tr>
<tr>
<td><a name="eol-comment"></a><a href="#eol-comment-note">end-of-line comment</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td><span style="color: gray"><em>none</em></span></td>
<td>1 + 1 <span style="color: gray"># addition</span></td>
<td>1 + 1 <span style="color: gray"># addition</span></td>
<td><span style="color: gray"><em>none</em></span></td>
</tr>
<tr>
<td><a name="multiple-line-comment"></a><a href="#multiple-line-comment-note">multiple line comment</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>1 + <span style="color: gray">(* addition *)</span> 1</td>
<td><span style="color: gray"><em>none</em></span></td>
<td><span style="color: gray"><em>none</em></span></td>
<td>1 + <span style="color: gray">/* addition */</span> 1;</td>
</tr>
<tr>
<th colspan="5"><a name="var-expr"></a><a href="#var-expr-note">variables and expressions</a></th>
</tr>
<tr>
<th></th>
<th>mathematica</th>
<th>sympy</th>
<th>sage</th>
<th>maxima</th>
</tr>
<tr>
<td><a name="assignment"></a><a href="#assignment-note">assignment</a></td>
<td>a = 3<br />
Set[a, 3]<br />
<br />
<span style="color: gray">(* rhs evaluated each time a is accessed: *)</span><br />
a := x + 3<br />
SetDelayed[a, x + 3]</td>
<td>a = 3</td>
<td>a = 3</td>
<td>a: 3;</td>
</tr>
<tr>
<td><a name="parallel-assignment"></a><a href="#parallel-assignment-note">parallel assignment</a></td>
<td>{a, b} = {3, 4}<br />
Set[{a, b}, {3, 4}]</td>
<td>a, b = 3, 4</td>
<td>a, b = 3, 4</td>
<td>[a, b]: [3, 4]</td>
</tr>
<tr>
<td><a name="compound-assignment"></a><a href="#compound-assignment-note">compound assignment</a></td>
<td>+= -= *= /=<br />
<span style="color: gray"><em>corresponding functions:</em></span><br />
AddTo SubtractFrom TimeBy DivideBy</td>
<td>+= -= *= /= <span style="white-space: pre-wrap;">//=</span> %= ^= <span style="white-space: pre-wrap;">**=</span></td>
<td>+= -= *= /= <span style="white-space: pre-wrap;">//=</span> %= <span style="white-space: pre-wrap;">**=</span></td>
<td><span style="color: gray"><em>none</em></span></td>
</tr>
<tr>
<td><a name="incr-decr"></a><a href="#incr-decr-note">increment and decrement</a></td>
<td>++x <span style="white-space: pre-wrap;">--</span>x<br />
PreIncrement[x] PreDecrement[x]<br />
x++ x<span style="white-space: pre-wrap;">--</span><br />
Increment[x] Decrement[x]</td>
<td><span style="color: gray"><em>none</em></span></td>
<td><span style="color: gray"><em>none</em></span></td>
<td><span style="color: gray"><em>none</em></span></td>
</tr>
<tr>
<td><a name="non-referential-id"></a><a href="#non-referential-id-note">non-referential identifier</a></td>
<td><span style="color: gray"><em>any unassigned identifier is non-referential</em></span></td>
<td>x, y, z, w = symbols('x y z w')</td>
<td>y, z, w = var('y z w')<br />
<br />
<span style="color: gray"># x is non-referential unless assigned a value</span></td>
<td><span style="color: gray"><em>any unassigned identifier is non-referential</em></span></td>
</tr>
<tr>
<td><a name="id-as-val"></a><a href="#id-as-val-note">identifier as value</a></td>
<td>x = 3<br />
y = HoldForm[x]</td>
<td> </td>
<td> </td>
<td>x: 3;<br />
y: 'x;</td>
</tr>
<tr>
<td><a name="global-var"></a><a href="#global-var-note">global variable</a></td>
<td><span style="color: gray"><em>variables are global by default</em></span></td>
<td>g1, g2 = 7, 8<br />
<br />
def swap_globals():<br />
<span style="white-space: pre-wrap;"> </span>global g1, g2<br />
<span style="white-space: pre-wrap;"> </span>g1, g2 = g2, g1</td>
<td>g1, g2 = 7, 8<br />
<br />
def swap_globals():<br />
<span style="white-space: pre-wrap;"> </span>global g1, g2<br />
<span style="white-space: pre-wrap;"> </span>g1, g2 = g2, g1</td>
<td><span style="color: gray"><em>variables are global by default</em></span></td>
</tr>
<tr>
<td><a name="local-var"></a><a href="#local-var-note">local variable</a></td>
<td>Module[{x = 3, y = 4}, Print[x + y]]<br />
<br />
<span style="color: gray">(* makes x and y read-only: *)</span><br />
With[{x = 3, y = 4}, Print[x + y]]<br />
<br />
<span style="color: gray">(* Block[ ] declares dynamic scope *)</span></td>
<td><span style="color: gray"><em>assignments inside functions are to local variables by default</em></span></td>
<td><span style="color: gray"><em>assignments inside functions are to local variables by default</em></span></td>
<td>block([x: 3, y: 4], print(x + y));</td>
</tr>
<tr>
<td><a name="null"></a><a href="#null-note">null</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>Null</td>
<td>None</td>
<td>None</td>
<td><span style="color: gray"><em>no null value</em></span></td>
</tr>
<tr>
<td><a name="null-test"></a><a href="#null-test-note">null test</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>x == Null</td>
<td>x is None</td>
<td>x is None</td>
<td><span style="color: gray"><em>no null value</em></span></td>
</tr>
<tr>
<td><a name="undef-var"></a><a href="#undef-var-note">undefined variable access</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td><span style="color: gray"><em>treated as an unknown number</em></span></td>
<td><span style="color: gray"><em>raises</em> NameError</span></td>
<td><span style="color: gray"><em>raises</em> NameError</span></td>
<td><span style="color: gray"><em>treated as an unknown number</em></span></td>
</tr>
<tr>
<td><a name="rm-var-binding"></a><a href="#rm-var-binding-note">remove variable binding</a></td>
<td>Clear[x]<br />
Remove[x]</td>
<td>del x</td>
<td>del x</td>
<td>kill(x);</td>
</tr>
<tr>
<td><a name="cond-expr"></a><a href="#cond-expr-note">conditional expression</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>If[x > 0, x, -x]</td>
<td>x if x > 0 else -x</td>
<td>x if x > 0 else -x</td>
<td>if x < 0 then -x else x;</td>
</tr>
<tr>
<th colspan="5"><a name="arithmetic-logic"></a><a href="#arithmetic-logic-note">arithmetic and logic</a></th>
</tr>
<tr>
<th></th>
<th>mathematica</th>
<th>sympy</th>
<th>sage</th>
<th>maxima</th>
</tr>
<tr>
<td><a name="true-false"></a><a href="#true-false-note">true and false</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>True False</td>
<td>True False</td>
<td>True False</td>
<td>true false</td>
</tr>
<tr>
<td><a name="falsehoods"></a><a href="#falsehoods-note">falsehoods</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>False</td>
<td>False 0 0.0</td>
<td>False None 0 0.0 '' [] {}</td>
<td> </td>
</tr>
<tr>
<td><a name="logical-op"></a><a href="#logical-op-note">logical operators</a></td>
<td>! True @</td>
<td>@@ (True && False)<br />
Or[Not[True], And[True, False]]</td>
<td>Or(Not(True), And(True, False))<br />
<br />
<span style="color: gray"># when arguments are symbols:</span><br />
<span style="white-space: pre-wrap;">~ x | (y & z)</span></td>
<td> </td>
<td>and or not</td>
</tr>
<tr>
<td><a name="relational-expr"></a><a href="#relational-expr-note">relational expression</a></td>
<td>1 < 2</td>
<td> </td>
<td> </td>
<td>is(1 < 2);</td>
</tr>
<tr>
<td><a name="relational-op"></a><a href="#relational-op-note">relational operators</a></td>
<td>== != > < >= <=<br />
<span style="color: gray"><em>corresponding functions:</em></span><br />
Equal Unequal Greater Less GreaterEqual LessEqual</td>
<td>Eq Ne Gt Lt Ge Le<br />
<br />
<span style="color: gray"># when arguments are symbols:</span><br />
== != > < >= <=</td>
<td>== != > < >= <=</td>
<td><span style="white-space: pre-wrap;">=</span> # > < >= <=</td>
</tr>
<tr>
<td><a name="arith-op"></a><a href="#arith-op-note">arithmetic operators</a></td>
<td>+ - * / Quotient Mod<br />
<span style="color: gray"><em>adjacent terms are multiplied, so * is not necessary.</em> Quotient <em>and</em> Mod <em>are functions, not binary infix operators. These functions are also available:</em></span><br />
Plus Subtract Times Divide</td>
<td>+ - * / <span style="color: gray"><em>??</em></span> %<br />
<br />
<span style="color: gray"><em>if an expression contains a symbol, then the above operators are rewritten using the following classes:</em></span><br />
Add Mul Pow Mod</td>
<td>+ - * / <span style="white-space: pre-wrap;">//</span> %</td>
<td>+ - * / quotitent() mod()<br />
<br />
<span style="color: gray">quotient <em>and</em> mod <em>are functions, not binary infix operators.</em></span></td>
</tr>
<tr>
<td><a name="int-div"></a><a href="#int-div-note">integer division</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>Quotient[a, b]</td>
<td> </td>
<td>7 <span style="white-space: pre-wrap;">//</span> 3</td>
<td>quotient(7, 3);</td>
</tr>
<tr>
<td><a name="int-div-zero"></a><a href="#int-div-zero-note">integer division by zero</a></td>
<td><span style="color: gray"><em>dividend is zero:</em></span><br />
Indeterminate<br />
<span style="color: gray"><em>otherwise:</em></span><br />
ComplexInfinity</td>
<td> </td>
<td><span style="color: gray"><em>raises</em> ZeroDivisionError</span></td>
<td><span style="color: gray"><em>error</em></span></td>
</tr>
<tr>
<td><a name="float-div"></a><a href="#float-div-note">float division</a></td>
<td><span style="color: gray"><em>exact division:</em></span><br />
a / b</td>
<td> </td>
<td> </td>
<td>a / b</td>
</tr>
<tr>
<td><a name="float-div-zero"></a><a href="#float-div-zero-note">float division by zero</a></td>
<td><span style="color: gray"><em>dividend is zero:</em></span><br />
Indeterminate<br />
<span style="color: gray"><em>otherwise:</em></span><br />
ComplexInfinity</td>
<td> </td>
<td> </td>
<td><span style="color: gray"><em>error</em></span></td>
</tr>
<tr>
<td><a name="power"></a><a href="#power-note">power</a></td>
<td>2 ^ 32<br />
Power[2, 32]</td>
<td>2 <span style="white-space: pre-wrap;">**</span> 32<br />
Pow(2, 32)</td>
<td>2 ^ 32<br />
2 <span style="white-space: pre-wrap;">**</span> 32</td>
<td>2 ^ 32;<br />
2 <span style="white-space: pre-wrap;">**</span> 32;</td>
</tr>
<tr>
<td><a name="sqrt"></a><a href="#sqrt-note">sqrt</a></td>
<td><span style="color: gray"><em>returns symbolic expression:</em></span><br />
Sqrt[2]</td>
<td>sqrt(2)</td>
<td>sqrt(2)</td>
<td>sqrt(2);</td>
</tr>
<tr>
<td><a name="sqrt-negative-one"></a><a href="#sqrt-negative-one-note">sqrt -1</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>I</td>
<td>I</td>
<td>I</td>
<td>%i</td>
</tr>
<tr>
<td><a name="transcendental-func"></a><a href="#transcendental-func-note">transcendental functions</a></td>
<td>Exp Log<br />
Sin Cos Tan<br />
ArcSin ArcCos ArcTan<br />
ArcTan<br />
<span style="color: gray">ArcTan <em>accepts 1 or 2 arguments</em></span></td>
<td>exp log<br />
sin cos tan<br />
asin acos atan<br />
atan2</td>
<td>exp log<br />
sin cos tan<br />
asin acos atan<br />
atan2</td>
<td>exp log<br />
sin cos tan<br />
asin acos atan<br />
atan2</td>
</tr>
<tr>
<td><a name="transcendental-const"></a><a href="#transcendental-const-note">transcendental constants</a><br />
<span style="color: gray"><em>π and Euler's number</em></span></td>
<td>Pi E EulerGamma</td>
<td>pi E</td>
<td>pi e euler_gamma</td>
<td>%pi %e %gamma</td>
</tr>
<tr>
<td><a name="float-truncation"></a><a href="#float-truncation-note">float truncation</a><br />
<span style="color: gray"><em>round towards zero, round to nearest integer, round down, round up</em></span></td>
<td>IntegerPart Round Floor Ceiling</td>
<td>floor<br />
ceiling</td>
<td>int<br />
round<br />
floor<br />
ceil</td>
<td>truncate<br />
round<br />
floor<br />
ceiling</td>
</tr>
<tr>
<td><a name="absolute-val"></a><a href="#absolute-val-note">absolute value</a><br />
<span style="color: gray"><em>and signum</em></span></td>
<td>Abs Sign</td>
<td>Abs sign</td>
<td>abs sign</td>
<td>abs sign<br />
<br />
<span style="color: gray">sign <em>returns</em> pos, neg, <em>or</em> zero</span></td>
</tr>
<tr>
<td><a name="int-overflow"></a><a href="#int-overflow-note">integer overflow</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td><span style="color: gray"><em>none, has arbitrary length integer type</em></span></td>
<td><span style="color: gray"><em>none, has arbitrary length integer type</em></span></td>
<td><span style="color: gray"><em>none, has arbitrary length integer type</em></span></td>
<td><span style="color: gray"><em>none, has arbitrary length integer type</em></span></td>
</tr>
<tr>
<td><a name="float-overflow"></a><a href="#float-overflow-note">float overflow</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td><span style="color: gray"><em>none</em></span></td>
<td> </td>
<td> </td>
<td><span style="color: gray"><em>none</em></span></td>
</tr>
<tr>
<td><a name="rational-construction"></a><a href="#rational-construction-note">rational construction</a></td>
<td>2 / 7</td>
<td>Mul(2, Pow(7, -1))<br />
Rational(2, 7)</td>
<td>2 / 7</td>
<td>2 / 7</td>
</tr>
<tr>
<td><a name="rational-decomposition"></a><a href="#rational-decomposition-note">rational decomposition</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>Numerator[2 / 7]<br />
Denominator[2 / 7]</td>
<td>numer, denom = fraction(Rational(2, 7))</td>
<td>numerator(2 / 7)<br />
denominator(2 / 7)</td>
<td>num(2 / 7);<br />
denom(2 / 7);</td>
</tr>
<tr>
<td><a name="decimal-approx"></a><a href="#decimal-approx-note">decimal approximation</a></td>
<td>N[2 / 7]<br />
2 / 7 + 0.<br />
2 / 7 <span style="white-space: pre-wrap;">//</span> N<br />
N[2 / 7, 100]</td>
<td>N(Rational(2, 7))<br />
N(Rational(2, 7), 100)</td>
<td>n(2 / 7)<br />
n(2 / 7, 100)<br />
<br />
<span style="color: gray"># synonyms for n:</span><br />
N(2 / 7)<br />
numerical_approx(2 / 7)</td>
<td>2 / 7, numer;</td>
</tr>
<tr>
<td><a name="complex-construction"></a><a href="#complex-construction-note">complex construction</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>1 + 3I</td>
<td>1 + 3 * I</td>
<td>1 + 3 * I</td>
<td>1 + 3 * %i;</td>
</tr>
<tr>
<td><a name="complex-decomposition"></a><a href="#complex-decomposition-note">complex decomposition</a><br />
<span style="color: gray"><em>real and imaginary part, argument and modulus, conjugate</em></span></td>
<td>Re Im<br />
Arg Abs<br />
Conjugate</td>
<td>re im<br />
Abs arg<br />
conjugate</td>
<td>(3 + I).real()<br />
(3 + I).imag()<br />
abs(3 + I)<br />
arg(3 + I)<br />
(3 + I).conjugate()</td>
<td>realpart imagpart<br />
cabs carg<br />
conjugate</td>
</tr>
<tr>
<td><a name="random-num"></a><a href="#random-num-note">random number</a><br />
<span style="color: gray"><em>uniform integer, uniform float</em></span></td>
<td>RandomInteger[{0, 99}]<br />
RandomReal[]</td>
<td> </td>
<td> </td>
<td>random(100);<br />
random(1.0);</td>
</tr>
<tr>
<td><a name="random-seed"></a><a href="#random-seed-note">random seed</a><br />
<span style="color: gray"><em>set, get</em></span></td>
<td>SeedRandom[17]<br />
<span style="color: gray"><em>??</em></span></td>
<td> </td>
<td> </td>
<td>set_random_state(make_random_state(17));<br />
<span style="color: gray"><em>??</em></span></td>
</tr>
<tr>
<td><a name="bit-op"></a><a href="#bit-op-note">bit operators</a></td>
<td>BitAnd[5, 1]<br />
BitOr[5, 1]<br />
BitXor[5, 1]<br />
BitNot[5]<br />
BitShiftLeft[5, 1]<br />
BitShiftRight[5, 1]</td>
<td> </td>
<td> </td>
<td><span style="color: gray"><em>none</em></span></td>
</tr>
<tr>
<td><a name="binary-octal-hex-literals"></a><a href="#binary-octal-hex-literals-note">binary, octal, and hex literals</a></td>
<td>2<span style="white-space: pre-wrap;">^^</span>101010<br />
8<span style="white-space: pre-wrap;">^^</span>52<br />
16<span style="white-space: pre-wrap;">^^</span>2a</td>
<td> </td>
<td> </td>
<td>ibase: 2;<br />
101010;<br />
<br />
ibase: 8;<br />
52;<br />
<br />
<span style="color: gray">/* If first hex digit is a letter, prefix a zero: */</span><br />
ibase: 16;<br />
2a;</td>
</tr>
<tr>
<td><a name="radix"></a><a href="#radix-note">radix</a></td>
<td>BaseForm[42, 7]<br />
BaseForm[7^^60, 10]</td>
<td> </td>
<td> </td>
<td>obase: 7;<br />
42;</td>
</tr>
<tr>
<td><a name="to-array-of-digits"></a><a href="#to-array-of-digits-note">to array of digits</a></td>
<td><span style="color: gray">(* base 10: *)</span><br />
IntegerDigits[1234]<br />
<span style="color: gray">(* base 2: *)</span><br />
IntegerDigits[1234, 2]</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th colspan="5"><a name="strings"></a><a href="#strings-note">strings</a></th>
</tr>
<tr>
<th></th>
<th>mathematica</th>
<th>sympy</th>
<th>sage</th>
<th>maxima</th>
</tr>
<tr>
<td><a name="str-literal"></a><a href="#str-literal-note">string literal</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>"don't say \"no\""</td>
<td><span style="color: gray"><em>use</em></span> <a href="/scripting#strings">Python strings</a></td>
<td><span style="color: gray"><em>use</em></span> <a href="/scripting#strings">Python strings</a></td>
<td>"don't say \"no\""</td>
</tr>
<tr>
<td><a name="newline-in-str-literal"></a><a href="#newline-in-str-literal-note">newline in literal</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td><span style="color: gray"><em>yes</em></span></td>
<td> </td>
<td> </td>
<td><span style="color: gray"><em>Newlines are inserted into strings by continuing the string on the next line. However, if the last character on a line inside a string is a backslash, the backslash and the following newline are omitted.</em></span></td>
</tr>
<tr>
<td><a name="str-literal-esc"></a><a href="#str-literal-esc-note">literal escapes</a></td>
<td>\\ \" \b \f \n \r \t \<span style="color: gray"><em>ooo</em></span></td>
<td> </td>
<td> </td>
<td>\" \\</td>
</tr>
<tr>
<td><a name="str-concat"></a><a href="#str-concat-note">concatenate</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>"one " <> "two " <> "three"</td>
<td> </td>
<td> </td>
<td>concat("one ", "two ", "three");</td>
</tr>
<tr>
<td><a name="translate-case"></a><a href="#translate-case-note">translate case</a></td>
<td>ToUpperCase["foo"]<br />
ToLowerCase["FOO"]</td>
<td> </td>
<td> </td>
<td>supcase("foo");<br />
sdowncase("FOO");</td>
</tr>
<tr>
<td><a name="trim"></a><a href="#trim-note">trim</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>StringTrim[" foo "]</td>
<td> </td>
<td> </td>
<td>strim(" ", " foo ");</td>
</tr>
<tr>
<td><a name="num-to-str"></a><a href="#num-to-str-note">number to string</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>"value: " <> ToString[8]</td>
<td> </td>
<td> </td>
<td>concat("value: ", 8);</td>
</tr>
<tr>
<td><a name="str-to-num"></a><a href="#str-to-num-note">string to number</a></td>
<td>7 + ToExpression["12"]<br />
73.9 + ToExpression[".037"]</td>
<td> </td>
<td> </td>
<td>7 + parse_string("12");<br />
73.9 + parse_string(".037");<br />
<br />
<span style="color: gray">/* parse_string raises error if the string does<br />
not contain valid Maxima code. Use numberp<br />
predicate to verify that the return value is<br />
numeric. */</span></td>
</tr>
<tr>
<td><a name="str-join"></a><a href="#str-join-note">string join</a></td>
<td>StringJoin[Riffle[{"foo", "bar", "baz"}, ","]]</td>
<td> </td>
<td> </td>
<td>simplode(["foo", "bar", "baz"], ",");</td>
</tr>
<tr>
<td><a name="split"></a><a href="#split-note">split</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>StringSplit["foo,bar,baz", ","]</td>
<td> </td>
<td> </td>
<td>split("foo,bar,baz", ",");</td>
</tr>
<tr>
<td><a name="str-subst"></a><a href="#str-subst-note">substitute</a><br />
<br />
<span style="color: gray"><em>first occurrence, all occurences</em></span> </td>
<td>s = "do re mi mi"<br />
re = RegularExpression["mi"]<br />
<br />
StringReplace[s, re -> "ma", 1]<br />
StringReplace[s, re -> "ma"]</td>
<td> </td>
<td> </td>
<td>ssubst("mi", "ma", "do re mi mi mi");<br />
ssubstfirst("mi", "ma", "do re mi mi mi");</td>
</tr>
<tr>
<td><a name="str-len"></a><a href="#str-len-note">length</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>StringLength["hello"]</td>
<td> </td>
<td> </td>
<td>slength("hello");</td>
</tr>
<tr>
<td><a name="index-substr"></a><a href="#index-substr-note">index of substring</a></td>
<td>StringPosition["hello", "el"][[1]][[1]]<br />
<br />
<span style="color: gray">(* The index of the first character is 1.*)</span><br />
<br />
<span style="color: gray">(* StringPosition returns an array of pairs, one for each occurrence of the substring. Each pair contains the index of the first and last character of the occurrence. *)</span></td>
<td> </td>
<td> </td>
<td>ssearch("el", "hello");<br />
<br />
<span style="color: gray">/* 1 is index of first character;<br />
returns false if substring not found */</span> _</td>
</tr>
<tr>
<td><a name="extract-substr"></a><a href="#extract-substr-note">extract substring</a></td>
<td><span style="color: gray">(* "el": *)</span><br />
StringTake["hello", {2, 3}]</td>
<td> </td>
<td> </td>
<td>substring("hello", 2, 4);</td>
</tr>
<tr>
<td><a name="char-literal"></a><a href="#char-literal-note">character literal</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td><span style="color: gray"><em>none</em></span></td>
<td> </td>
<td> </td>
<td><span style="color: gray"><em>none</em></span></td>
</tr>
<tr>
<td><a name="lookup-char"></a><a href="#lookup-char-note">character lookup</a></td>
<td>Characters["hello"][[1]]</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="chr-ord"></a><a href="#chr-ord-note">chr and ord</a></td>
<td>FromCharacterCode[{65}]<br />
ToCharacterCode["A"][[1]]</td>
<td> </td>
<td> </td>
<td>ascii(65);<br />
cint("A");</td>
</tr>
<tr>
<td><a name="delete-char"></a><a href="#delete-char-note">delete characters</a></td>
<td>rules = {"a" -> "", "e" -> "", "i" -> "",<br />
<span style="white-space: pre-wrap;"> </span>"o" -> "", "u" -> ""}<br />
StringReplace["disemvowel me", rules]</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th colspan="5"><a name="arrays"></a><a href="#arrays-note">arrays</a></th>
</tr>
<tr>
<th></th>
<th>mathematica</th>
<th>sympy</th>
<th>sage</th>
<th>maxima</th>
</tr>
<tr>
<td><a name="array-literal"></a><a href="#array-literal-note">literal</a></td>
<td>{1, 2, 3}<br />
<br />
List[1, 2, 3]</td>
<td><span style="color: gray"><em>use</em></span> <a href="/scripting#arrays">Python lists</a></td>
<td><span style="color: gray"><em>use</em></span> <a href="/scripting#arrays">Python lists</a></td>
<td>[1, 2, 3];</td>
</tr>
<tr>
<td><a name="array-size"></a><a href="#array-size-note">size</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>Length[{1, 2, 3}]</td>
<td> </td>
<td> </td>
<td>length([1, 2, 3]);</td>
</tr>
<tr>
<td><a name="array-lookup"></a><a href="#array-lookup-note">lookup</a></td>
<td><span style="color: gray">(* access time is O(1) *)</span><br />
<span style="color: gray">(* indices start at one: *)</span><br />
{1, 2, 3}[[1]]<br />
<br />
Part[{1, 2, 3}, 1]</td>
<td> </td>
<td> </td>
<td>a: [6, 7, 8];<br />
a[1];</td>
</tr>
<tr>
<td><a name="array-update"></a><a href="#array-update-note">update</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>a[[1]] = 7</td>
<td> </td>
<td> </td>
<td>a[1]: 7;</td>
</tr>
<tr>
<td><a name="array-out-of-bounds"></a><a href="#array-out-of-bounds-note">out-of-bounds behavior</a></td>
<td><span style="color: gray"><em>left as unevaluated</em> Part[] <em>expression</em></span></td>
<td> </td>
<td> </td>
<td><span style="color: gray"><em>Error for both lookup and update.</em></span></td>
</tr>
<tr>
<td><a name="array-element-index"></a><a href="#array-element-index-note">element index</a></td>
<td><span style="color: gray">(* Position returns list of all positions: *)</span><br />
First /@ Position[{7, 8, 9, 9}, 9]</td>
<td> </td>
<td> </td>
<td>a: [7, 8, 9, 9];<br />
first(sublist_indices(a, lambda([x], x = 9)));</td>
</tr>
<tr>
<td><a name="array-slice"></a><a href="#array-slice-note">slice</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>{1, 2, 3}[[1 ;; 2]]</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="array-of-integers-as-index"></a><a href="#array-of-integers-as-index-note">array of integers as index</a></td>
<td><span style="color: gray">(* evaluates to {7, 9, 9} *)</span><br />
{7, 8, 9}[[{1, 3, 3}]]</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="array-back"></a><a href="#array-back-note">manipulate back</a></td>
<td>a = {6,7,8}<br />
AppendTo[a, 9]<br />
elem = a[[Length[a]]]<br />
a = Delete[a, Length[a]]<br />
elem</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="array-front"></a><a href="#array-front-note">manipulate front</a></td>
<td>a = {6, 7, 8}<br />
PrependTo[a, 5]<br />
elem = a[[1]]<br />
a = Delete[a, 1]<br />
elem</td>
<td> </td>
<td> </td>
<td>a: [6, 7, 8];<br />
push(5, a);<br />
elem: pop(a);</td>
</tr>
<tr>
<td><a name="array-head"></a><a href="#array-head-note">head</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>First[{1, 2, 3}]</td>
<td> </td>
<td> </td>
<td>first([1, 2, 3]);</td>
</tr>
<tr>
<td><a name="array-tail"></a><a href="#array-tail-note">tail</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>Rest[{1, 2, 3}]</td>
<td> </td>
<td> </td>
<td>rest([1, 2, 3]);</td>
</tr>
<tr>
<td><a name="array-cons"></a><a href="#array-cons-note">cons</a></td>
<td><span style="color: gray">(* first arg must be an array *)</span><br />
Prepend[{2, 3}, 1]</td>
<td> </td>
<td> </td>
<td>cons(1, [2, 3]);</td>
</tr>
<tr>
<td><a name="array-concatenate"></a><a href="#array-concatenate-note">concatenate</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>Join[{1, 2, 3}, {4, 5, 6}]</td>
<td> </td>
<td> </td>
<td>append([1, 2, 3], [4, 5, 6]);</td>
</tr>
<tr>
<td><a name="array-replicate"></a><a href="#array-replicate-note">replicate</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>tenZeros = Table[0, {i, 0, 9}]</td>
<td> </td>
<td> </td>
<td>ten_zeros: makelist(0, 10);</td>
</tr>
<tr>
<td><a name="copy-array"></a><a href="#copy-array-note">copy</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>a2 = a</td>
<td> </td>
<td> </td>
<td>a2: copylist(a);</td>
</tr>
<tr>
<td><a name="iterate-over-array"></a><a href="#iterate-over-array-note">iterate</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>Do[Print[i], {i, {1, 2, 3]</td>
<td> </td>
<td> </td>
<td>for i in [1, 2, 3] do print(i);</td>
</tr>
<tr>
<td><a name="reverse-array"></a><a href="#reverse-array-note">reverse</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>Reverse[{1, 2, 3}]</td>
<td> </td>
<td> </td>
<td>reverse([1, 2, 3]);</td>
</tr>
<tr>
<td><a name="sort-array"></a><a href="#sort-array-note">sort</a></td>
<td><span style="color: gray">(* original list not modified: *)</span><br />
a = Sort[{3, 1, 4, 2}]</td>
<td> </td>
<td> </td>
<td>sort([3, 1, 4, 2]);</td>
</tr>
<tr>
<td><a name="dedupe-array"></a><a href="#dedupe-array-note">dedupe</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>DeleteDuplicates[{1, 2, 2, 3}]</td>
<td> </td>
<td> </td>
<td>unique([1, 2, 2, 3]);</td>
</tr>
<tr>
<td><a name="membership"></a><a href="#membership-note">membership</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>MemberQ[{1, 2, 3}, 2]</td>
<td> </td>
<td> </td>
<td>member(7, {1, 2, 3});<br />
evalb(7 in {1, 2, 3});</td>
</tr>
<tr>
<td><a name="map"></a><a href="#map-note">map</a></td>
<td>Map[Function[x, x x], {1, 2, 3}]<br />
<br />
Function[x, x x] /@ {1, 2, 3}<br />
<br />
<span style="color: gray">(* if function has Listable attribute, Map is unnecessary: *)</span><br />
sqr[x_] := x * x<br />
SetAttributes[sqr, Listable]<br />
sqr[{1, 2, 3, 4}]</td>
<td> </td>
<td> </td>
<td>map(lambda([x], x * x), [1, 2, 3]);</td>