-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmore-computer-algebra.html
More file actions
3996 lines (3984 loc) · 121 KB
/
more-computer-algebra.html
File metadata and controls
3996 lines (3984 loc) · 121 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><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="#processes-env">process and environment</a> | <a href="#libraries-namespaces">libraries and namespaces</a> | <a href="#reflection">reflection</a></p>
<p><a href="#vectors">vectors</a> | <a href="#matrices">matrices</a> | <a href="#combinatorics">combinatorics</a> | <a href="#number-theory">number theory</a> | <a href="#elliptic-curves">elliptic curves</a> | <a href="#rational-algebraic-numbers">rational and algebraic numbers</a> | <a href="#polynomials">polynomials</a> | <a href="#special-functions">special functions</a> | <a href="#permutations">permutations</a> | <a href="#groups">groups</a> | <a href="#subgroups">subgroups</a> | <a href="#group-homomorphisms">group homomorphisms</a> | <a href="#actions">actions</a></p>
<table class="wiki-content-table">
<tr>
<th></th>
<th><a href="#pari-gp">pari/gp</a></th>
<th><a href="#magma">magma</a></th>
<th><a href="#gap">gap</a></th>
<th><a href="#singular">singular</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>2.7</em></span></td>
<td><span style="color: gray"><em>2.21</em></span></td>
<td><span style="color: gray"><em>4.7</em></span></td>
<td><span style="color: gray"><em>4.0</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>$ gp <span style="white-space: pre-wrap;">--</span>version</td>
<td> </td>
<td>$ gap -h</td>
<td>$ singular -vb</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>pari/gp</th>
<th>magma</th>
<th>gap</th>
<th>singular</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 hello.gp<br />
print("Hello, World!")<br />
quit<br />
<br />
$ gp -q hello.gp<br />
Hello, World!</td>
<td> </td>
<td> </td>
<td>$ singular -b <span style="color: gray"><em>foo</em></span>.sing</td>
</tr>
<tr>
<td><a name="repl"></a><a href="#repl-note">repl</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>$ gp</td>
<td><a href="http://magma.maths.usyd.edu.au/calc/">online calculator</a></td>
<td>$ gap</td>
<td>$ singular</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>...</em></span> }<br />
<br />
<span style="color: gray"><em>braces cannot be nested</em></span></td>
<td> </td>
<td>function( ) <span style="color: gray"><em>...</em></span> end<br />
if then <span style="color: gray"><em>...</em></span> elif then <span style="color: gray"><em>...</em></span> else <span style="color: gray"><em>...</em></span> fi<br />
while do <span style="color: gray"><em>...</em></span> od<br />
for do <span style="color: gray"><em>...</em></span> od</td>
<td>{ <span style="color: gray"><em>...</em></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>newline or</em></span> ;<br />
<br />
<span style="color: gray"><em>Newlines don't separate statements inside braces.</em></span><br />
<br />
<span style="color: gray"><em>A semicolon suppresses echoing value of previous expression.</em></span></td>
<td>;<br />
<br />
<span style="color: gray"><em>A line can be broken anywhere, even inside a numeric literal or string, if the newline is preceded by a backslash:</em> \</span></td>
<td>;<br />
<br />
<span style="color: gray"><em>Two trailing semicolons</em> ;; <em>suppress echoing value of previous expression.</em></span></td>
<td>;</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>1 + 1 <span style="color: gray">\\ addition</span></td>
<td>1 + 1; <span style="color: gray"><span style="white-space: pre-wrap;">//</span> addition</span></td>
<td>1 + 1; <span style="color: gray"># addition</span></td>
<td>// <span style="color: gray"><em>comment</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>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>comment line<br />
another comment</em></span> */</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>pari/gp</th>
<th>magma</th>
<th>gap</th>
<th>singular</th>
</tr>
<tr>
<td><a name="assignment"></a><a href="#assignment-note">assignment</a></td>
<td>x = 3.14</td>
<td>a := 3;</td>
<td>a := 3;</td>
<td>int a;<br />
a = 3;<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> It is an error to assign to undeclared variable.</span></td>
</tr>
<tr>
<td><a name="parallel-assignment"></a><a href="#parallel-assignment-note">parallel assignment</a></td>
<td>[a, b] = [3, 4]</td>
<td> </td>
<td><span style="color: gray"><em>none</em></span></td>
<td>int a, b;<br />
a, b = 3, 4;</td>
</tr>
<tr>
<td><a name="compound-assignment"></a><a href="#compound-assignment-note">compound assignment</a></td>
<td>+= -= *= /= \= \/= %=<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">\\</span> bit operations:</span><br />
<span style="white-space: pre-wrap;"><<= >>=</span></td>
<td> </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="incr-decr"></a><a href="#incr-decr-note">increment and decrement</a></td>
<td><span style="color: gray"><em>postmodifiers:</em></span><br />
x++ x<span style="white-space: pre-wrap;">--</span></td>
<td> </td>
<td><span style="color: gray"><em>none</em></span></td>
<td><span style="white-space: pre-wrap;">x++ x--</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><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="id-as-val"></a><a href="#id-as-val-note">identifier as value</a></td>
<td>x = 3<br />
y = 'x</td>
<td> </td>
<td> </td>
<td> </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> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="local-var"></a><a href="#local-var-note">local variable</a></td>
<td>tmp = 19<br />
<br />
add(x, y, z) = {<br />
<span style="white-space: pre-wrap;"> </span><span style="color: gray"><span style="white-space: pre-wrap;">\\</span> don't overwrite global tmp:</span><br />
<span style="white-space: pre-wrap;"> </span>my(tmp = x + y);<br />
<span style="white-space: pre-wrap;"> </span>tmp + z<br />
}<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">\\</span> local keyword declares dynamic scope</span></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="null"></a><a href="#null-note">null</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> </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><span style="color: gray"><em>none</em></span></td>
<td> </td>
<td> </td>
<td> </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> </td>
<td><span style="color: gray"><em>error</em></span></td>
<td> </td>
</tr>
<tr>
<td><a name="rm-var-binding"></a><a href="#rm-var-binding-note">remove variable binding</a></td>
<td>kill(x)</td>
<td>delete x;</td>
<td> </td>
<td> </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>if x lt 0 then -x; else x; end if;</td>
<td> </td>
<td> </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>pari/gp</th>
<th>magma</th>
<th>gap</th>
<th>singular</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>1 0</td>
<td>true false</td>
<td>true false</td>
<td>1 0</td>
</tr>
<tr>
<td><a name="falsehoods"></a><a href="#falsehoods-note">falsehoods</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>0<br />
0.0<br />
Mod(0, 5)<br />
Pol([0])<br />
[0, 0, 0]<br />
[0, 0; 0, 0]<br />
[[0, 0], 0]</td>
<td>false</td>
<td>false</td>
<td>0</td>
</tr>
<tr>
<td><a name="logical-op"></a><a href="#logical-op-note">logical operators</a></td>
<td>@@&& </td>
<td> !@</td>
<td>not true or (true and false);</td>
<td>not true or (true and false)</td>
<td>! 1 @</td>
<td>@@ (1 && 0)</td>
</tr>
<tr>
<td><a name="relational-op"></a><a href="#relational-op-note">relational operators</a></td>
<td>== != > < >= <=</td>
<td>eq ne lt gt le ge<br />
<br />
<span style="color: gray">eq <em>raises an error when the operands are of different type.</em></span><br />
<br />
<span style="color: gray">cmpeq <em>does not.</em></span></td>
<td><span style="white-space: pre-wrap;">=</span> <> < > <= >=</td>
<td>== != < > <= >=<br />
<br />
<> <span style="color: gray"><em>is a synonym for</em></span> !=</td>
</tr>
<tr>
<td><a name="arith-op"></a><a href="#arith-op-note">arithmetic operators</a></td>
<td>+ - * / %</td>
<td>+ - * / mod</td>
<td>+ - * / mod<br />
<br />
<span style="color: gray"><em>the operators</em> + - * / <em>are overloaded for integers, rationals, and floats; other arithmetic functions aren't and there are no implicit conversions; use constructors to convert:</em></span><br />
Rat(3.1)<br />
Float(3)<br />
Float(31/10)</td>
<td><span style="color: gray"><em>Operators are for integers only unless<br />
base ring with coefficient field is declared.</em></span><br />
<span style="white-space: pre-wrap;">+ - * / %</span><br />
<br />
<span style="color: gray">mod <em>is synonym for</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>a \ b<br />
divrem(a, b)[1]<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">\\</span> rounded integer division:</span><br />
a \/ b</td>
<td>a := 7;<br />
b := 3;<br />
<br />
div(a, b);</td>
<td>QuoInt(a, b);</td>
<td>int a, b = 7, 3;<br />
a div b;<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> a / b also performs integer division when<br />
<span style="white-space: pre-wrap;">//</span> no base ring is declared.</span></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>error</em></span></td>
<td><span style="color: gray"><em>User error</em></span></td>
<td><span style="color: gray"><em>error</em></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>7 / 3</td>
<td> </td>
<td><span style="color: gray"><em>depending upon the types of a and b, the value can be an exact rational, a machine float, or an arbitrary precision float:</em></span><br />
a / b</td>
<td>ring r = real,(x,y,z),(dp);<br />
<br />
3.1 / 7.2;</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>error</em></span></td>
<td><span style="color: gray"><em>Runtime error</em></span></td>
<td><span style="color: gray"><em>error</em></span></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</td>
<td>2 ^ 32;</td>
<td>2 ^ 32</td>
<td>2 ^ 16<br />
2 ** 16</td>
</tr>
<tr>
<td><a name="sqrt"></a><a href="#sqrt-note">sqrt</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>sqrt(2)</td>
<td>Sqrt(2);</td>
<td>2.0 ^ 0.5</td>
<td><span style="color: gray"><em>none</em></span></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>1.000 * I</td>
<td> </td>
<td><span style="color: gray">-1.0 ^ 0.5 <em>evaluates to</em> -1.</span></td>
<td><span style="color: gray"><em>none</em></span></td>
</tr>
<tr>
<td><a name="transcendental-func"></a><a href="#transcendental-func-note">transcendental functions</a></td>
<td>exp log <span style="color: gray"><em>none</em></span><br />
sin cos tan<br />
asin acos atan<br />
<span style="color: gray"><em>none</em></span></td>
<td>Exp Log<br />
Sin Cos Tan<br />
Arcsin Arccos Arctan<br />
Arctan2</td>
<td><span style="color: gray"><em>arguments must be floats; no implicit conversion of integers to floats:</em></span><br />
Exp Log<br />
Sin Cos Tan<br />
Asin Acos Atan<br />
Atan2(<span style="color: gray"><em>y</em></span>, <span style="color: gray"><em>x</em></span>)</td>
<td><span style="color: gray"><em>none</em></span></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 exp(1)</td>
<td> </td>
<td>FLOAT.PI FLOAT.E</td>
<td>LIB "general.lib";<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> print specified number of digits:</span><br />
number_pi(100);<br />
number_e(100);</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>truncate(x)<br />
round(x)<br />
floor(x)<br />
ceil(x)</td>
<td> </td>
<td>Trunc Round Floor Ceil</td>
<td> </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(x)<br />
sign(x)</td>
<td> </td>
<td>AbsInt<br />
<span style="color: gray"><em>no absolute value for floats?</em></span><br />
SignInt<br />
SignFloat</td>
<td>LIB "general.lib";<br />
<br />
absValue(-7);<br />
<br />
ring r = real,(x,y,z),(dp);<br />
absValue(-7.1);</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>modular arithmetic with warning</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>error</em></span></td>
<td> </td>
<td><span style="color: gray"># prints as inf:</span><br />
FLOAT.INFINTY</td>
<td> </td>
</tr>
<tr>
<td><a name="rational-construction"></a><a href="#rational-construction-note">rational construction</a></td>
<td>2 / 7</td>
<td>2 / 7;</td>
<td>2 / 7</td>
<td> </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>x = 2 / 7<br />
numerator(x)<br />
denominator(x)</td>
<td>Numerator(2 / 7);<br />
Denominator(2 / 7 );</td>
<td>x := 2 / 7;<br />
NumeratorRat(x);<br />
DenominatorRat(x);</td>
<td> </td>
</tr>
<tr>
<td><a name="decimal-approx"></a><a href="#decimal-approx-note">decimal approximation</a></td>
<td>2 / 7 + 0.<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">\\</span> change precision to 100:</span><br />
\p 100<br />
2 / 7 + 0.</td>
<td> </td>
<td> </td>
<td> </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 + 3 * I</td>
<td> </td>
<td><span style="color: gray"><em>none</em></span></td>
<td> </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>real(z) imag(z)<br />
arg(z) abs(z)<br />
conj(z)</td>
<td> </td>
<td><span style="color: gray"><em>none</em></span></td>
<td> </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>random(100)<br />
random(1.0)</td>
<td>Random(0, 99);<br />
<span style="color: gray"><em>??</em></span></td>
<td>rs := RandomSource(IsMersenneTwister);<br />
Random(rs, 0, 99);<br />
<span style="color: gray"><em>??</em></span></td>
<td> </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>setrand(17)<br />
getrand()</td>
<td>SetSeed(42);<br />
seed := GetSeed(();</td>
<td>rs := RandomSource(IsMersenneTwister, 17);<br />
State(rs);</td>
<td> </td>
</tr>
<tr>
<td><a name="bit-op"></a><a href="#bit-op-note">bit operators</a></td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">\\</span> left shift:</span><br />
5 <span style="white-space: pre-wrap;"><<</span> 1<br />
<span style="color: gray"><span style="white-space: pre-wrap;">\\</span> right shift:</span><br />
5 <span style="white-space: pre-wrap;">>></span> 1</td>
<td> </td>
<td><span style="color: gray"><em>none</em></span></td>
<td> </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> </td>
<td> </td>
<td><span style="color: gray"><em>none</em></span></td>
<td> </td>
</tr>
<tr>
<td><a name="radix"></a><a href="#radix-note">radix</a></td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">\\</span> 42 as powers of 7 up to 9th power:</span><br />
42 + O(7^10)</td>
<td>IntegerToString(42, 7);</td>
<td><span style="color: gray"><em>none</em></span></td>
<td> </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"><span style="white-space: pre-wrap;">\\</span> base 10:</span><br />
digits(1234)<br />
<span style="color: gray"><span style="white-space: pre-wrap;">\\</span> base 2:</span><br />
digits(1234, 2)<br />
<span style="color: gray"><span style="white-space: pre-wrap;">\\</span> number of digits in base 10:</span><br />
sizedigits(1234)</td>
<td> </td>
<td>ListOfDigits(1234);<br />
<br />
<span style="color: gray"># other bases?</span></td>
<td> </td>
</tr>
<tr>
<th colspan="5"><a name="strings"></a><a href="#strings-note">strings</a></th>
</tr>
<tr>
<th></th>
<th>pari/gp</th>
<th>magma</th>
<th>gap</th>
<th>singular</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>"don't say \"no\""</td>
<td>"don't say \"no\""</td>
<td>string s = "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>no; use \n escape</em></span></td>
<td><span style="color: gray"><em>A line break in a string literal results in a newline in the string unless preceded by a backslash.</em></span></td>
<td><span style="color: gray"><em>no</em></span></td>
<td><span style="color: gray"><em>Yes; runaway strings are possible; there is a predefined string variable newline which contains a single newline character.</em></span></td>
</tr>
<tr>
<td><a name="str-literal-esc"></a><a href="#str-literal-esc-note">literal escapes</a></td>
<td>\n \t \" \\</td>
<td>\" \\ \n \r \t</td>
<td>\b \c \n \r \" \' \\ \<span style="color: gray"><em>ooo</em></span><br />
<br />
<span style="color: gray"><em>when writing to a buffered output stream, encountering a</em> \c <em>causes a flush of output.</em></span></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>Str("one ", "two ", "three")<br />
concat("one ", "two ", "three")</td>
<td>"one " cat "two " cat "three";<br />
"one " * "two " * "three";<br />
&cat ["one ", "two ", "three "];<br />
&* ["one ", "two ", "three "];</td>
<td>Concatenation("one ", "two ", "three");</td>
<td>string s = "one" + "two" + "three";</td>
</tr>
<tr>
<td><a name="str-replicate"></a><a href="#str-replicate-note">replicate</a></td>
<td> </td>
<td>hbar := "-" ^ 80;</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="translate-case"></a><a href="#translate-case-note">translate case</a></td>
<td> </td>
<td> </td>
<td>UppercaseString("foo");<br />
LowercaseString("FOO");</td>
<td> </td>
</tr>
<tr>
<td><a name="trim"></a><a href="#trim-note">trim</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td> </td>
<td> </td>
<td><span style="color: gray"><em>none</em></span></td>
<td> </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>Str(8)<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">\\</span> implicit conversion to string:</span><br />
concat("value: ", 8)</td>
<td>"value: " * IntegerToString(8);</td>
<td>Concatenation("value: ", String(8));</td>
<td>"value: " + string(8)</td>
</tr>
<tr>
<td><a name="str-to-num"></a><a href="#str-to-num-note">string to number</a></td>
<td>7 + eval("12")<br />
73.9 + eval(".037")</td>
<td> </td>
<td>7 + Int("12");<br />
73.9 + Float(".037");</td>
<td> </td>
</tr>
<tr>
<td><a name="str-join"></a><a href="#str-join-note">string join</a></td>
<td> </td>
<td> </td>
<td>a := ["foo", "bar", "baz"];<br />
JoinStringsWithSeparator(a, ","); </td>
<td> </td>
</tr>
<tr>
<td><a name="split"></a><a href="#split-note">split</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td> </td>
<td>Split("foo,bar,baz", ",");</td>
<td>SplitString("foo,bar,baz", ",");</td>
<td> </td>
</tr>
<tr>
<td><a name="str-subst"></a><a href="#str-subst-note">substitute</a></td>
<td> </td>
<td> </td>
<td><span style="color: gray"># replace all occurrences:</span><br />
ReplacedString("do re mi mi", "mi", "ma");</td>
<td> </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>length("hello")<br />
#"hello"</td>
<td># "hello";</td>
<td>Length("hello");</td>
<td>size("hello");</td>
</tr>
<tr>
<td><a name="index-substr"></a><a href="#index-substr-note">index of substring</a></td>
<td> </td>
<td>Index("hello", "el");<br />
Position("hello", "el");<br />
<span style="color: gray">/* both return 0 if substring not found */</span></td>
<td> </td>
<td><span style="color: gray">// evaluates to 2:</span><br />
find("hello", "el");</td>
</tr>
<tr>
<td><a name="extract-substr"></a><a href="#extract-substr-note">extract substring</a></td>
<td> </td>
<td>Substring("hello", 2, 2);</td>
<td>s := "hello";<br />
s{[2..3]};</td>
<td><span style="color: gray">// start index and substring length:</span><br />
"hello"[2, 2]</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> </td>
<td> </td>
<td>'h'</td>
<td> </td>
</tr>
<tr>
<td><a name="lookup-char"></a><a href="#lookup-char-note">character lookup</a></td>
<td> </td>
<td> </td>
<td>s := "hello";<br />
<span style="color: gray"># the character 'h':</span><br />
s[1];<br />
<br />
<span style="color: gray"># cannot use index notation on string literal</span></td>
<td><span style="color: gray">// the character h:</span><br />
"hello"[1]</td>
</tr>
<tr>
<td><a name="chr-ord"></a><a href="#chr-ord-note">chr and ord</a></td>
<td>Strchr([65])<br />
Vecsmall("A")</td>
<td> </td>
<td>CharInt(65)<br />
IntChar('A')</td>
<td> </td>
</tr>
<tr>
<td><a name="delete-char"></a><a href="#delete-char-note">delete characters</a></td>
<td> </td>
<td> </td>
<td>s := "disemvowel me";<br />
<span style="color: gray"># no retval; modifies s in place:</span><br />
RemoveCharacters(s, "aeiou"); </td>
<td> </td>
</tr>
<tr>
<th colspan="5"><a name="arrays"></a><a href="#arrays-note">arrays</a></th>
</tr>
<tr>
<th></th>
<th>pari/gp</th>
<th>magma</th>
<th>gap</th>
<th>singular</th>
</tr>
<tr>
<td><a name="array-literal"></a><a href="#array-literal-note">literal</a></td>
<td><span style="color: gray">\\ [1, 2, 3] is a vector literal:</span><br />
List([1, 2, 3])</td>
<td>a := [1, 2, 3];</td>
<td>[1, 2, 3];<br />
<br />
<span style="color: gray"># creates array with gap at fourth index;<br />
# reading a[4] causes an error:</span><br />
a := [1, 2, 3, , 5];</td>
<td>list a= 1, 2, 3;<br />
list a = list(1, 2, 3);<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> Singular lists are fixed length.</span></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(List([1, 2, 3]))<br />
#List([1, 2, 3])</td>
<td># [1, 2, 3];</td>
<td>Length([1, 2, 3]);</td>
<td>size(a);</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 />
List([1, 2, 3])[1]</td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">//</span> indices start at one:</span><br />
[6, 7, 8][1];</td>
<td><span style="color: gray"># indices start at one:</span><br />
a := [1, 2, 3];<br />
a[1];</td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">//</span> indices start at one:</span><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>listput(a, 7, 1)</td>
<td>a[1] := 7;</td>
<td>a[1] := 7;</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>out of allowed range error</em></span></td>
<td><span style="color: gray"><em>Runtime error on lookup.</em></span><br />
<br />
<span style="color: gray"><em>For update, size of array is increased if necessary; runtime error to look up unassigned slot in between assigned slots.</em></span></td>
<td><span style="color: gray"><em>Lookups result in errors; arrays can have gaps which also cause lookup errors.<br />
<br />
An update will expand the array, possibly creating gaps.</em></span></td>
<td><span style="color: gray"><em>error</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"><em>none</em></span></td>
<td> </td>
<td><span style="color: gray"># returns 3:</span><br />
Position([7, 8, 9, 9], 9);<br />
<br />
<span style="color: gray"># returns [3, 4]:</span><br />
Positions([7, 8, 9, 9], 9);</td>
<td> </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><span style="color: gray"><em>none</em></span></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"><em>none</em></span></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 = List([6, 7, 8])<br />
listput(a, 9)<br />
elem = listpop(a)</td>
<td>a := [6, 7, 8];<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> a not modified:</span><br />
a2 := Append(a, 9);<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> a2 not modified:</span><br />
a3 := Prune(a2);<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> a modified:</span><br />
Append(~a, 9);<br />
Prune(~a);</td>
<td>a = [6, 7, 8];<br />
Add(a, 9);<br />
elem := Remove(a);</td>
<td>list a = list(6, 7, 8);<br />
list a2 = insert(a, 9, size(a));<br />
int popme = a2[size(a2)];<br />
list a3 = delete(a2, size(a2));</td>
</tr>
<tr>
<td><a name="array-front"></a><a href="#array-front-note">manipulate front</a></td>
<td>a = List([6, 7, 8]);<br />
listinsert(a, 5, 1);<br />
elem = a[1];<br />
listpop(a, 1);</td>
<td> </td>
<td> </td>
<td> </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>List([1, 2, 3])[1]</td>
<td> </td>
<td> </td>
<td> </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><span style="color: gray"><em>none</em></span></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="array-cons"></a><a href="#array-cons-note">cons</a></td>
<td>a = List([1, 2, 3]);<br />
listinsert(a, 1, 1);</td>
<td> </td>
<td> </td>
<td> </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>concat(List([1, 2, 3]), List([4, 5, 6]))</td>
<td> </td>
<td>Concatenation([1, 2, 3], [4, 5, 6]);</td>
<td>list a1 = 1, 2, 3;<br />
list a2 = 4, 5, 6;<br />
list a3 = a1 + a2;</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> </td>
<td> </td>
<td> </td>
<td> </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> </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>a = List([1, 2, 3])<br />
<br />
for(i=1, length(a), print(a[i]))</td>
<td> </td>
<td>Perform([1, 2, 3], function(x) Print(x); Print("\n"); end);</td>
<td> </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>a = List([1, 2, 3])<br />
a2 = listcreate()<br />
while(i > 0, listput(a2, a[i]); i--)</td>
<td> </td>
<td>Reversed([1, 2, 3])</td>
<td> </td>
</tr>
<tr>
<td><a name="sort-array"></a><a href="#sort-array-note">sort</a></td>
<td>a = List([3,1,4,2])<br />
listsort(a)<br />
a</td>
<td> </td>
<td>A := [3, 1, 4, 2]<br />
Sort(A);</td>
<td> </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>Set([1, 2, 2, 3])</td>
<td> </td>
<td>Set([1, 2, 2, 3]);<br />
Unique([1, 2, 2, 3]);</td>
<td> </td>
</tr>
<tr>
<td><a name="membership"></a><a href="#membership-note">membership</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">\\</span> returns 1-based index of first occurrence<br />
<span style="white-space: pre-wrap;">\\</span> or 0 if not found:</span><br />
setsearch([1, 2, 3], 2)</td>
<td> </td>
<td>2 in [1, 2, 3]</td>
<td> </td>
</tr>
<tr>
<td><a name="intersection"></a><a href="#intersection-note">intersection</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>setintersect([1, 2], [2, 3, 4])</td>
<td> </td>
<td>Intersection(Set([1, 2]), Set([2, 3, 4]));</td>
<td> </td>
</tr>
<tr>
<td><a name="union"></a><a href="#union-note">union</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>setunion([1, 2], [2, 3, 4])</td>
<td> </td>
<td>Union(Set([1, 2]), Set([2, 3, 4]));</td>
<td> </td>