//a side-by-side reference sheet//

sheet one: [#grammar-invocation grammar and invocation] | [#var-expr variables and expressions] | [#arithmetic-logic arithmetic and logic] | [#strings strings] | [#arrays arrays] | [#sets sets] | [#arith-seq arithmetic sequences] | [#dictionaries dictionaries] | [#functions functions] | [#execution-control execution control] | [#exceptions exceptions] | [#streams streams] | [#files files] | [#directories directories] | [#libraries-namespaces libraries and namespaces] | [#reflection reflection]

sheet two:] symbolic expressions] | calculus] | equations and unknowns] | optimization] | vectors] | matrices] | combinatorics] | number theory] | polynomials] | trigonometry] | special functions] | permutations] | descriptive statistics] | distributions] | statistical tests]

bar charts] | scatter plots] | line charts] | surface charts] | chart options]

||~ ||~ [#mathematica mathematica]||~ [#sympy sympy]||~ [#sage sage]||~ [#maxima maxima]|| ||# version-used[#version-used-note version used] _ @< >@||##gray|//10.0//##||##gray|//Python 2.7; SymPy 0.7//##||##gray|//6.10//##||##gray|//5.37//##|| ||# show-version[#show-version-note show version] _ @< >@||##gray|//select// About Mathematica //in// Mathematica //menu//##||@@sympy.version@@||$ sage @@–@@version _ _ ##gray|//also displayed on worksheet//##||$ maxima @@–@@version|| ||# implicit-prologue[#implicit-prologue-note implicit prologue]|| ||from sympy import * _ _ ##gray|# enable LaTeX rendering in Jupyter notebook:## _ init_printing() _ _ ##gray|# unknown variables must be declared:## _ x, y = symbols(‘x y’)||##gray|# unknowns other than x must be declared:## _ y = var(‘y’)|| || ||||||||||~ # grammar-invocation[#grammar-invocation-note grammar and invocation]|| ||~ ||~ mathematica||~ sympy||~ sage||~ maxima|| ||# interpreter[#interpreter-note interpreter] _ @< >@||$ cat @@>@@ hello.m _ Print[“Hello, World!”] _ _ $ MathKernel -script hello.m||##gray|//if// foo.py //imports sympy://## _ $ python ##gray|//foo//##.py||$ cat > hello.sage _ print(“Hello, World!”) _ _ $ sage hello.sage||$ cat @@>>@@ hello.max _ print(“Hello, world!”); _ _ $ maxima -b hello.maxima|| ||# repl[#repl-note repl] _ @< >@||$ MathKernel||$ python _ @@>>>@@ from sympy import ||$ sage||$ maxima|| ||# block-delimiters[#block-delimiters-note block delimiters] _ @< >@||( ##gray|//stmt//##; ##gray|//…//##)||: ##gray|//and offside rule//##||: ##gray|//and offside rule//##||block([x: 3, y: 4], x + y); _ _ ##gray|/ Multiple stmts are separated by commas; a list of assignments can be used to set variables local to the block. /##|| ||# stmt-separator[#stmt-separator-note statement separator]||; ##gray|//or sometimes newline//## _ _ ##gray|//A semicolon suppresses echoing value of previous expression.//##||##gray|//newline or//## ; _ _ ##gray|//newlines not separators inside (), [], {}, triple quote literals, or after backslash: @@\@@//##||##gray|//newline or//## ; _ _ ##gray|//newlines not separators inside (), [], {}, triple quote literals, or after backslash: @@\@@//##||; ##gray|//or//## $ _ _ ##gray|//The dollar sign// $ //suppresses output.//##|| ||# eol-comment[#eol-comment-note end-of-line comment] _ @< >@||##gray|//none//##||1 + 1 ##gray|# addition##||1 + 1 ##gray|# addition##||##gray|//none//##|| ||# multiple-line-comment[#multiple-line-comment-note multiple line comment] _ @< >@||1 + ##gray|( addition )## 1||##gray|//none//##||##gray|//none//##||1 + ##gray|/ addition /## 1;|| ||||||||||~ # var-expr[#var-expr-note variables and expressions]|| ||~ ||~ mathematica||~ sympy||~ sage||~ maxima|| ||# assignment[#assignment-note assignment]||a = 3 _ Set[a, 3] _ _ ##gray|( rhs evaluated each time a is accessed: *)## _ a := x + 3 _ SetDelayed[a, x + 3]||a = 3||a = 3||a: 3;|| ||# parallel-assignment[#parallel-assignment-note parallel assignment]||{a, b} = {3, 4} _ Set[{a, b}, {3, 4}]||a, b = 3, 4||a, b = 3, 4||[a, b]: [3, 4]|| ||# compound-assignment[#compound-assignment-note compound assignment]||+= -= *= /= _ ##gray|//corresponding functions://## _ AddTo SubtractFrom TimeBy DivideBy||+= -= = /= @@//=@@ %= ^= @@*=@@||+= -= = /= @@//=@@ %= @@=@@||##gray|//none//##|| ||# incr-decr[#incr-decr-note increment and decrement]||++x @@–@@x _ PreIncrement[x] PreDecrement[x] _ x++ x@@–@@ _ Increment[x] Decrement[x]||##gray|//none//##||##gray|//none//##||##gray|//none//##|| ||# non-referential-id[#non-referential-id-note non-referential identifier]||##gray|//any unassigned identifier is non-referential//##||x, y, z, w = symbols(‘x y z w’)||y, z, w = var(‘y z w’) _ _ ##gray|# x is non-referential unless assigned a value##||##gray|//any unassigned identifier is non-referential//##|| ||# id-as-val[#id-as-val-note identifier as value]||x = 3 _ y = HoldForm[x]|| || ||x: 3; _ y: ‘x;|| ||# global-var[#global-var-note global variable]||##gray|//variables are global by default//##||g1, g2 = 7, 8 _ _ def swap_globals(): _ @<  >@global g1, g2 _ @<  >@g1, g2 = g2, g1||g1, g2 = 7, 8 _ _ def swap_globals(): _ @<  >@global g1, g2 _ @<  >@g1, g2 = g2, g1||##gray|//variables are global by default//##|| ||# local-var[#local-var-note local variable]||Module[{x = 3, y = 4}, Print[x + y]] _ _ ##gray|( makes x and y read-only: )## _ With[{x = 3, y = 4}, Print[x + y]] _ _ ##gray|( Block[ ] declares dynamic scope *)##||##gray|//assignments inside functions are to local variables by default//##||##gray|//assignments inside functions are to local variables by default//##||block([x: 3, y: 4], print(x + y));|| ||# null[#null-note null] _ @< >@||Null||None||None||##gray|//no null value//##|| ||# null-test[#null-test-note null test] _ @< >@||x == Null||x is None||x is None||##gray|//no null value//##|| ||# undef-var[#undef-var-note undefined variable access] _ @< >@||##gray|//treated as an unknown number//##||##gray|//raises// NameError##||##gray|//raises// NameError##||##gray|//treated as an unknown number//##|| ||# rm-var-binding[#rm-var-binding-note remove variable binding]||Clear[x] _ Remove[x]||del x||del x||kill(x);|| ||# cond-expr[#cond-expr-note conditional expression] _ @< >@||If[x > 0, x, -x]||x if x > 0 else -x||x if x > 0 else -x||if x < 0 then -x else x;|| ||||||||||~ # arithmetic-logic[#arithmetic-logic-note arithmetic and logic]|| ||~ ||~ mathematica||~ sympy||~ sage||~ maxima|| ||# true-false[#true-false-note true and false] _ @< >@||True False||True False||True False||true false|| ||# falsehoods[#falsehoods-note falsehoods] _ @< >@||False||False 0 0.0||False None 0 0.0 ‘‘ [] {}|| || ||# logical-op[#logical-op-note logical operators]||! True @@||@@ (True && False) _ Or[Not[True], And[True, False]]||Or(Not(True), And(True, False)) _ _ ##gray|# when arguments are symbols:## _ @@~ x | (y & z)@@|| ||and or not|| ||# relational-expr[#relational-expr-note relational expression]||1 < 2|| || ||is(1 < 2);|| ||# relational-op[#relational-op-note relational operators]||== != > < >= <= _ ##gray|//corresponding functions://## _ Equal Unequal Greater Less GreaterEqual LessEqual||Eq Ne Gt Lt Ge Le _ _ ##gray|# when arguments are symbols:## _ == != > < >= <=||== != > < >= <=||@@=@@ # > < >= <=|| ||# arith-op[#arith-op-note arithmetic operators]||+ - * / Quotient Mod _ ##gray|//adjacent terms are multiplied, so * is not necessary.// Quotient //and// Mod //are functions, not binary infix operators. These functions are also available://## _ Plus Subtract Times Divide||+ - * / ##gray|//??//## % _ _ ##gray|//if an expression contains a symbol, then the above operators are rewritten using the following classes://## _ Add Mul Pow Mod||+ - * / @@//@@ %||+ - * / quotitent() mod() _ _ ##gray|quotient //and// mod //are functions, not binary infix operators.//##|| ||# int-div[#int-div-note integer division] _ @< >@||Quotient[a, b]|| ||7 @@//@@ 3||quotient(7, 3);|| ||# int-div-zero[#int-div-zero-note integer division by zero]||##gray|//dividend is zero://## _ Indeterminate _ ##gray|//otherwise://## _ ComplexInfinity|| ||##gray|//raises// ZeroDivisionError##||##gray|//error//##|| ||# float-div[#float-div-note float division]||##gray|//exact division://## _ a / b|| || ||a / b|| ||# float-div-zero[#float-div-zero-note float division by zero]||##gray|//dividend is zero://## _ Indeterminate _ ##gray|//otherwise://## _ ComplexInfinity|| || ||##gray|//error//##|| ||# power[#power-note power]||2 ^ 32 _ Power[2, 32]||2 @@@@ 32 _ Pow(2, 32)||2 ^ 32 _ 2 @@@@ 32||2 ^ 32; _ 2 @@**@@ 32;|| ||# sqrt[#sqrt-note sqrt]||##gray|//returns symbolic expression://## _ Sqrt[2]||sqrt(2)||sqrt(2)||sqrt(2);|| ||# sqrt-negative-one[#sqrt-negative-one-note sqrt -1] _ @< >@||I||I||I||%i|| ||# transcendental-func[#transcendental-func-note transcendental functions]||Exp Log _ Sin Cos Tan _ ArcSin ArcCos ArcTan _ ArcTan _ ##gray|ArcTan //accepts 1 or 2 arguments//##||exp log _ sin cos tan _ asin acos atan _ atan2||exp log _ sin cos tan _ asin acos atan _ atan2||exp log _ sin cos tan _ asin acos atan _ atan2|| ||# transcendental-const[#transcendental-const-note transcendental constants] _ ##gray|//π and Euler’s number//##||Pi E EulerGamma||pi E||pi e euler_gamma||%pi %e %gamma|| ||# float-truncation[#float-truncation-note float truncation] _ ##gray|//round towards zero, round to nearest integer, round down, round up//##||IntegerPart Round Floor Ceiling||floor _ ceiling||int _ round _ floor _ ceil||truncate _ round _ floor _ ceiling|| ||# absolute-val[#absolute-val-note absolute value] _ ##gray|//and signum//##||Abs Sign||Abs sign||abs sign||abs sign _ _ ##gray|sign //returns// pos, neg, //or// zero##|| ||# int-overflow[#int-overflow-note integer overflow] _ @< >@||##gray|//none, has arbitrary length integer type//##||##gray|//none, has arbitrary length integer type//##||##gray|//none, has arbitrary length integer type//##||##gray|//none, has arbitrary length integer type//##|| ||# float-overflow[#float-overflow-note float overflow] _ @< >@||##gray|//none//##|| || ||##gray|//none//##|| ||# rational-construction[#rational-construction-note rational construction]||2 / 7||Mul(2, Pow(7, -1)) _ Rational(2, 7)||2 / 7||2 / 7|| ||# rational-decomposition[#rational-decomposition-note rational decomposition] _ @< >@||Numerator[2 / 7] _ Denominator[2 / 7]||numer, denom = fraction(Rational(2, 7))||numerator(2 / 7) _ denominator(2 / 7)||num(2 / 7); _ denom(2 / 7);|| ||# decimal-approx[#decimal-approx-note decimal approximation]||N[2 / 7] _ 2 / 7 + 0. _ 2 / 7 @@//@@ N _ N[2 / 7, 100]||N(Rational(2, 7)) _ N(Rational(2, 7), 100)||n(2 / 7) _ n(2 / 7, 100) _ _ ##gray|# synonyms for n:## _ N(2 / 7) _ numerical_approx(2 / 7)||2 / 7, numer;|| ||# complex-construction[#complex-construction-note complex construction] _ @< >@||1 + 3I||1 + 3 * I||1 + 3 * I||1 + 3 * %i;|| ||# complex-decomposition[#complex-decomposition-note complex decomposition] _ ##gray|//real and imaginary part, argument and modulus, conjugate//##||Re Im _ Arg Abs _ Conjugate||re im _ Abs arg _ conjugate||(3 + I).real() _ (3 + I).imag() _ abs(3 + I) _ arg(3 + I) _ (3 + I).conjugate()||realpart imagpart _ cabs carg _ conjugate|| ||# random-num[#random-num-note random number] _ ##gray|//uniform integer, uniform float//##||RandomInteger[{0, 99}] _ RandomReal[]|| || ||random(100); _ random(1.0);|| ||# random-seed[#random-seed-note random seed] _ ##gray|//set, get//##||SeedRandom[17] _ ##gray|//??//##|| || ||setrandomstate(makerandomstate(17)); _ ##gray|//??//##|| ||# bit-op[#bit-op-note bit operators]||BitAnd[5, 1] _ BitOr[5, 1] _ BitXor[5, 1] _ BitNot[5] _ BitShiftLeft[5, 1] _ BitShiftRight[5, 1]|| || ||##gray|//none//##|| ||# binary-octal-hex-literals[#binary-octal-hex-literals-note binary, octal, and hex literals]||2@@@@101010 _ 8@@@@52 _ 16@@@@2a|| || ||ibase: 2; _ 101010; _ _ ibase: 8; _ 52; _ _ ##gray|/* If first hex digit is a letter, prefix a zero: /## _ ibase: 16; _ 2a;|| ||# radix[#radix-note radix]||BaseForm[42, 7] _ BaseForm[760, 10]|| || ||obase: 7; _ 42;|| ||# to-array-of-digits[#to-array-of-digits-note to array of digits]||##gray|( base 10: )## _ IntegerDigits[1234] _ ##gray|( base 2: )## _ IntegerDigits[1234, 2]|| || || || ||||||||||~ # strings[#strings-note strings]|| ||~ ||~ mathematica||~ sympy||~ sage||~ maxima|| ||# str-literal[#str-literal-note string literal] _ @< >@||"don’t say "no"”||##gray|//use//## Python strings]||##gray|//use//## Python strings]||"don’t say "no"”|| ||# newline-in-str-literal[#newline-in-str-literal-note newline in literal] _ @< >@||##gray|//yes//##|| || ||##gray|//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.//##|| ||# str-literal-esc[#str-literal-esc-note literal escapes]||\ " \b \f \n \r \t ##gray|//ooo//##|| || ||" \|| ||# str-concat[#str-concat-note concatenate] _ @< >@||"one “ <> “two “ <> “three”|| || ||concat(“one “, “two “, “three”);|| ||# translate-case[#translate-case-note translate case]||ToUpperCase[“foo”] _ ToLowerCase[“FOO”]|| || ||supcase(“foo”); _ sdowncase(“FOO”);|| ||# trim[#trim-note trim] _ @< >@||StringTrim[“ foo “]|| || ||strim(“ “, “ foo “);|| ||# num-to-str[#num-to-str-note number to string] _ @< >@||"value: “ <> ToString[8]|| || ||concat(“value: “, 8);|| ||# str-to-num[#str-to-num-note string to number]||7 + ToExpression[“12”] _ 73.9 + ToExpression[“.037”]|| || ||7 + parse_string(“12”); _ 73.9 + parse_string(“.037”); _ _ ##gray|/ parse_string raises error if the string does _ not contain valid Maxima code. Use numberp _ predicate to verify that the return value is _ numeric. /##|| ||# str-join[#str-join-note string join]||StringJoin[Riffle[{"foo”, “bar”, “baz”}, “,”]]|| || ||simplode([“foo”, “bar”, “baz”], “,”);|| ||# split[#split-note split] _ @< >@||StringSplit[“foo,bar,baz”, “,”]|| || ||split(“foo,bar,baz”, “,”);|| ||# str-subst[#str-subst-note substitute] _ _ ##gray|//first occurrence, all occurences//## ||s = “do re mi mi” _ re = RegularExpression[“mi”] _ _ StringReplace[s, re -> “ma”, 1] _ StringReplace[s, re -> “ma”]|| || ||ssubst(“mi”, “ma”, “do re mi mi mi”); _ ssubstfirst(“mi”, “ma”, “do re mi mi mi”);|| ||# str-len[#str-len-note length] _ @< >@||StringLength[“hello”]|| || ||slength(“hello”);|| ||# index-substr[#index-substr-note index of substring]||StringPosition[“hello”, “el”]11 _ _ ##gray|( The index of the first character is 1.)## _ _ ##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. )##|| || ||ssearch(“el”, “hello”); _ _ ##gray|/ 1 is index of first character; _ returns false if substring not found /## _|| ||# extract-substr[#extract-substr-note extract substring]||##gray|( “el”: )## _ StringTake[“hello”, {2, 3}]|| || ||substring(“hello”, 2, 4);|| ||# char-literal[#char-literal-note character literal] _ @< >@||##gray|//none//##|| || ||##gray|//none//##|| ||# lookup-char[#lookup-char-note character lookup]||Characters[“hello”]1|| || || || ||# chr-ord[#chr-ord-note chr and ord]||FromCharacterCode[{65}] _ ToCharacterCode[“A”]1|| || ||ascii(65); _ cint(“A”);|| ||# delete-char[#delete-char-note delete characters]||rules = {"a” -> ““, “e” -> ““, “i” -> ““, _ @<  >@"o” -> ““, “u” -> ““} _ StringReplace[“disemvowel me”, rules]|| || || || ||||||||||~ # arrays[#arrays-note arrays]|| ||~ ||~ mathematica||~ sympy||~ sage||~ maxima|| ||# array-literal[#array-literal-note literal]||{1, 2, 3} _ _ List[1, 2, 3]||##gray|//use//## Python lists]||##gray|//use//## Python lists]||[1, 2, 3];|| ||# array-size[#array-size-note size] _ @< >@||Length[{1, 2, 3}]|| || ||length([1, 2, 3]);|| ||# array-lookup[#array-lookup-note lookup]||##gray|( access time is O(1) )## _ ##gray|( indices start at one: )## _ {1, 2, 3}1 _ _ Part[{1, 2, 3}, 1]|| || ||a: [6, 7, 8]; _ a[1];|| ||# array-update[#array-update-note update] _ @< >@||a1 = 7|| || ||a[1]: 7;|| ||# array-out-of-bounds[#array-out-of-bounds-note out-of-bounds behavior]||##gray|//left as unevaluated// Part[] //expression//##|| || ||##gray|//Error for both lookup and update.//##|| ||# array-element-index[#array-element-index-note element index]||##gray|( Position returns list of all positions: )## _ First /@ Position[{7, 8, 9, 9}, 9]|| || ||a: [7, 8, 9, 9]; _ first(sublist_indices(a, lambda([x], x = 9)));|| ||# array-slice[#array-slice-note slice] _ @< >@||{1, 2, 3}1 ;; 2|| || || || ||# array-of-integers-as-index[#array-of-integers-as-index-note array of integers as index]||##gray|( evaluates to {7, 9, 9} )## _ {7, 8, 9}{1, 3, 3}|| || || || ||# array-back[#array-back-note manipulate back]||a = {6,7,8} _ AppendTo[a, 9] _ elem = a[Lengtha] _ a = Delete[a, Length[a]] _ elem|| || || || ||# array-front[#array-front-note manipulate front]||a = {6, 7, 8} _ PrependTo[a, 5] _ elem = a1 _ a = Delete[a, 1] _ elem|| || ||a: [6, 7, 8]; _ push(5, a); _ elem: pop(a);|| ||# array-head[#array-head-note head] _ @< >@||First[{1, 2, 3}]|| || ||first([1, 2, 3]);|| ||# array-tail[#array-tail-note tail] _ @< >@||Rest[{1, 2, 3}]|| || ||rest([1, 2, 3]);|| ||# array-cons[#array-cons-note cons]||##gray|( first arg must be an array )## _ Prepend[{2, 3}, 1]|| || ||cons(1, [2, 3]);|| ||# array-concatenate[#array-concatenate-note concatenate] _ @< >@||Join[{1, 2, 3}, {4, 5, 6}]|| || ||append([1, 2, 3], [4, 5, 6]);|| ||# array-replicate[#array-replicate-note replicate] _ @< >@||tenZeros = Table[0, {i, 0, 9}]|| || ||ten_zeros: makelist(0, 10);|| ||# copy-array[#copy-array-note copy] _ @< >@||a2 = a|| || ||a2: copylist(a);|| ||# iterate-over-array[#iterate-over-array-note iterate] _ @< >@||Do[Print[i], {i, {1, 2, 3}}]|| || ||for i in [1, 2, 3] do print(i);|| ||# reverse-array[#reverse-array-note reverse] _ @< >@||Reverse[{1, 2, 3}]|| || ||reverse([1, 2, 3]);|| ||# sort-array[#sort-array-note sort]||##gray|( original list not modified: )## _ a = Sort[{3, 1, 4, 2}]|| || ||sort([3, 1, 4, 2]);|| ||# dedupe-array[#dedupe-array-note dedupe] _ @< >@||DeleteDuplicates[{1, 2, 2, 3}]|| || ||unique([1, 2, 2, 3]);|| ||# membership[#membership-note membership] _ @< >@||MemberQ[{1, 2, 3}, 2]|| || ||member(7, {1, 2, 3}); _ evalb(7 in {1, 2, 3});|| ||# map[#map-note map]||Map[Function[x, x x], {1, 2, 3}] _ _ Function[x, x x] /@ {1, 2, 3} _ _ ##gray|( if function has Listable attribute, Map is unnecessary: *)## _ sqr[x_] := x * x _ SetAttributes[sqr, Listable] _ sqr[{1, 2, 3, 4}]|| || ||map(lambda([x], x * x), [1, 2, 3]);|| ||# filter[#filter-note filter] _ @< >@||Select[{1, 2, 3}, # > 2 &]|| || ||sublist([1, 2, 3], lambda([x], x > 2));|| ||# reduce[#reduce-note reduce] _ @< >@||Fold[Plus, 0, {1, 2, 3}]|| || || || ||# universal-existential-test[#universal-existential-test-note universal and existential tests]||##gray|//none//##|| || || || ||# min-max-elem[#min-max-elem-note min and max element]||Min[{6, 7, 8}] _ Max[{6, 7, 8}]|| || ||apply(min, [6, 7, 8]); _ apply(max, [6, 7, 8]);|| ||# shuffle-sample[#shuffle-sample-note shuffle and sample]||x = {3, 7, 5, 12, 19, 8, 4} _ _ RandomSample[x] _ RandomSample[x, 3]|| || || || ||# flatten[#flatten-note flatten] _ ##gray|//one level, completely//##||Flatten[{1, {2, {3, 4}}}, 1] _ Flatten[{1, {2, {3, 4}}}]|| || ||##gray|/* completely: /## _ flatten([1, [2, [3, 4]]]);|| ||# zip[#zip-note zip]||##gray|( list of six elements: )## _ Riffle[{1, 2, 3}, {"a”, “b”, “c”}] _ _ ##gray|( list of lists with two elements: )## _ Inner[List, {1, 2, 3}, {"a”, “b”, “c”}, List] _ _ ##gray|( same as Dot[{1, 2, 3}, {2, 3, 4}]: )## _ Inner[Times, {1, 2, 3}, {2, 3, 4}, Plus]|| || ||##gray|/ list of six elements: /## _ join([1, 2, 3], [“a”, “b”, “c”]);|| ||# cartesian-product[#cartesian-product-note cartesian product]||Outer[List, {1, 2, 3}, {"a”, “b”, “c”}]|| || || || ||||||||||~ # sets[#sets-note sets]|| ||~ ||~ mathematica||~ sympy||~ sage||~ maxima|| ||# set-literal[#set-literal-note literal]||##gray|( same as arrays: )## _ {1, 2, 3}||{1, 2, 3}||{1, 2, 3}||{1, 2, 3}|| ||# set-size[#set-size-note size]||Length[{1, 2, 3}]||len({1, 2, 3})||len({1, 2, 3})||cardinality({1, 2, 3});|| ||# array-to-set[#array-to-set-note array to set]||DeleteDuplicates[{1, 2, 2, 3}]||set([1, 2, 3])||set([1, 2, 3])||setify([1, 2, 3]);|| ||# set-to-array[#set-to-array-note set to array]||##gray|//none; sets are arrays//##||list({1, 2, 3})||list({1, 2, 3})||listify({1, 2, 3});|| ||# set-membership[#set-membership-note membership test] _ @< >@||MemberQ[{1, 2, 3}, 7]||7 in {1, 2, 3}||7 in {1, 2, 3}||elementp(7, {1, 2, 3});|| ||# set-subset[#set-subset-note subset test]||SubsetQ[{1, 2, 3}, {1, 2}]||{1, 2} <= {1, 2, 3} _ {1, 2}.issubset({1, 2, 3}) _ _ {1, 2, 3} >= {1, 2} _ {1, 2, 3}.issuperset({1, 2})||{1, 2} <= {1, 2, 3} _ {1, 2}.issubset({1, 2, 3}) _ _ {1, 2, 3} >= {1, 2} _ {1, 2, 3}.issuperset({1, 2})||subsetp({1, 2}, {1, 2, 3});|| ||# set-universal-existential-test[#set-universal-existential-test-note universal and existential tests]|| || || ||every(lambda([x], x > 2), [1, 2, 3]); _ _ some(lambda([x], x > 2), [1, 2, 3]);|| ||# set-union[#set-union-note union]||Union[{1, 2}, {2, 3, 4}]||{1, 2, 3} | {2, 3, 4} _ {1, 2, 3}.union({2, 3, 4})||{1, 2, 3} | {2, 3, 4} _ {1, 2, 3}.union({2, 3, 4})||union({1, 2, 3}, {2, 3, 4});|| ||# set-intersection[#set-intersection-note intersection] _ @< >@||Intersect[{1, 2}, {2, 3, 4}]||{1, 2, 3} & {2, 3, 4} _ {1, 2, 3}.intersection({2, 3, 4})||{1, 2, 3} & {2, 3, 4} _ {1, 2, 3}.intersection({2, 3, 4})||intersection({1, 2, 3}, {2, 3, 4});|| ||# set-diff[#set-diff-note relative complement]||Complement[{1, 2, 3}, {2}]||{1, 2, 3} - {2, 3, 4} _ {1, 2, 3}.difference({2, 3, 4})||{1, 2, 3} - {2, 3, 4} _ {1, 2, 3}.difference({2, 3, 4})||setdifference({1, 2, 3}, {2, 3, 4});|| ||# powerset[#powerset-note powerset]|| || ||set(Set({1, 2, 3}).subsets())||powerset({1, 2, 3});|| ||# set-cartesian-prod[#set-cartesian-prod-note cartesian product]||Outer[List, {1, 2, 3}, {"a”, “b”, “c”}]|| || ||cartesian_product({1, 2, 3}, {"a”, “b”, “c”});|| ||||||||||~ # arith-seq[#arith-seq-note arithmetic sequences]|| ||~ ||~ mathematica||~ sympy||~ sage||~ maxima|| ||[#range unit difference] _ @< >@||Range[1, 100]||range(1, 101)||range(1, 101)||makelist(i, i, 1, 100);|| ||[#arithmetic-sequence-integer difference of 10] _ @< >@||Range[1, 100, 10]||range(1, 100, 10)||range(1, 100, 10)||makelist(i, i, 1, 100, 10);|| ||[#airthmetic-sequence-float difference of 1/10] _ @< >@||Range[1, 100, 1/10]||[1 + Rational(1,10)i for i in range(0, 991)]||[1 + (1/10)i for i in range(0, 991)]||makelist(i, i, 1, 100, 1/10);|| ||||||||||~ # dictionaries[#dictionaries-note dictionaries]|| ||~ ||~ mathematica||~ sympy||~ sage||~ maxima|| ||# dict-literal[#dict-literal-note literal] _ @< >@||d = <|"t” -> 1, “f” -> 0|> _ _ ##gray|( or convert list of rules: )## _ d = Association[{"t” -> 1, “f” -> 0}] _ ##gray|( and back to list of rules: )## _ Normal[d]||##gray|//use//## Python dictionaries]||##gray|//use//## Python dictionaries]||d: [[“t”, 1], [“f”, 0]];|| ||# dict-size[#dict-size-note size] _ @< >@||Length[Keys[d]]|| || ||length(d);|| ||# dict-lookup[#dict-lookup-note lookup] _ @< >@||d[“t”]|| || ||assoc(“t”, d);|| ||# dict-update[#dict-update-note update]||d[“f”] = -1|| || ||d2: cons([“f”, -1], _ @<  >@sublist(d, lambda([p], p[1] # “f”)));|| ||# dict-missing-key[#dict-missing-key-note missing key behavior] _ @< >@||##gray|//Returns a symbolic expression with head “Missing”. If the lookup key was “x”, the expression is:// _ _ @<  >@Missing[“KeyAbsent”, “x”]##|| || ||##gray|assoc //returns// false##|| ||# dict-key-check[#dict-key-check-note is key present] _ @< >@||KeyExistsQ[d, “t”]|| || || || ||# dict-iter[#dict-iter-note iterate] _ @< >@|| || || || || ||# dict-key-val[#dict-key-val-note keys and values as arrays]||Keys[d] _ Values[d]|| || ||map(lambda([p], p[1]), d); _ map(lambda([p], p[2]), d);|| ||# dict-sort-values[#dict-sort-values-note sort by values]||Sort[d]|| || || || ||||||||||~ # functions[#functions-note functions]|| ||~ ||~ mathematica||~ sympy||~ sage||~ maxima|| ||[#function-definition define function]||Add[a, b] := a + b _ _ ##gray|( alternate syntax: )## _ Add = Function[{a, b}, a + b]|| || ||add(a, b) := a + b; _ _ define(add(a, b), a + b); _ _ ##gray|/ block body: /## _ add(a, b) := block(print(“adding”, a, “and”, b), a + b); _ _ ##gray|/ square bracket syntax: /## _ I[row, col] := if row = col then 1 else 0; _ I[10, 10];|| ||[#function-invocation invoke function]||Add[3, 7] _ _ Add @<@@>@ {3, 7} _ _ ##gray|( syntax for unary functions: )## _ 2 @@//@@ Log|| || ||add(3, 7);|| ||# boolean-func-attr[#boolean-func-attr-note boolean function attributes] _ ##gray|//list, set, clear//##||Attributes[add] _ SetAttributes[add, {Orderless, Flat, Listable}] _ ClearAtttibutes[add, Listable]|| || || || ||# undef-func[#undef-func-note undefine function]||Clear[Add]|| || ||remfunction(add);|| ||# redefine-func[#redefine-func-note redefine function]||Add[a, b] := b + a|| || ||add(a, b) := b + a;|| ||# missing-func[#missing-func-note missing function behavior]||##gray|//The expression is left unevaluated. The head is the function name as a symbol, and the parts are the arguments.//##|| || ||##gray|//The expression is left unevaluated.//##|| ||# missing-arg[#missing-arg-note missing argument behavior]||##gray|//The expression is left unevaluated. The head is the function name as a symbol, and the parts are the arguments.//##|| || ||##gray|//Too few arguments error.//##|| ||# extra-arg[#extra-arg-note extra argument behavior]||##gray|//The expression is left unevaluated. The head is the function name as a symbol, and the parts are the arguments.//##|| || ||##gray|//Too many arguments error.//##|| ||# default-arg[#default-arg-note default argument]||Options[myLog] = {base -> 10} _ myLog[x_, OptionsPattern[]] := _ @<  >@N[Log[x]/Log[OptionValue[base]]] _ _ ##gray|( call using default: )## _ myLog[100] _ _ ##gray|( override default: )## _ myLog[100, base -> E]|| || || || ||# retval[#retval-note return value]||##gray|//last expression evaluated, or argument of// Return[]##|| || ||##gray|//last expression evaluated//## _ _ ##gray|//Inside a// block(), //the last expression evaluated or the argument of// return()##|| ||[#anonymous-function anonymous function]||Function[{a, b}, a + b] _ _ (#1 + #2) &|| || ||f: lambda([x, y], x + y); _ _ f(3, 7);|| ||[#variable-number-arguments variable number of arguments]||##gray|( one or more arguments: )## _ add[a@@__@@] := Plus[a] _ _ ##gray|( zero or more arguments: )## _ add[a@@___@@] := Plus[a]|| || ||add([a]) := sum(a[i], i, 1, length(a));|| ||# expand-array[#expand-array-note pass array elements as separate arguments]||Apply[f, {a, b, c}] _ _ f @<@@>@ {x, y, z}||a = [x, y, z] _ f(a)|| ||add(a, b) := a + b; _ apply(add, [3, 7]);|| ||||||||||~ # execution-control[#execution-control-note execution control]|| ||~ ||~ mathematica||~ sympy||~ sage||~ maxima|| ||[#if if]||If[x > 0, _ @<  >@Print[“positive”], _ @<  >@If[x < 0, _ @<  >@@<  >@Print[“negative”], _ @<  >@@<  >@Print[“zero”]]]||##gray|//use//## [http://hyperpolyglot.org/scripting#execution-control Python execution control]||##gray|//use//## [http://hyperpolyglot.org/scripting#execution-control Python execution control]||if x > 0 _ @<  >@then print(“positive”) _ @<  >@else if x < 0 _ @<  >@@<  >@then print(“negative”) _ @<  >@@<  >@else print(“zero”);|| ||[#while while]||i = 0 _ While[i < 10, Print[i]; i++]|| || ||for i: 0 step 1 while i < 10 do print(i);|| ||[#for for]||For[i = 0, i < 10, i++, Print[i]]|| || ||for i: 1 step 1 thru 10 do print(i);|| ||[#break break]||Break[]|| || || || ||[#continue continue]||Continue[]|| || || || ||||||||||~ # exceptions[#exceptions-note exceptions]|| ||~ ||~ mathematica||~ sympy||~ sage||~ maxima|| ||# raise-exc[#raise-exc-note raise exception]||Throw[“failed”]||##gray|//use//## [http://hyperpolyglot.org/scripting#exceptions Python exceptions]||##gray|//use//## [http://hyperpolyglot.org/scripting#exceptions Python exceptions]||error(“failed”);|| ||# handle-exc[#handle-exc-note handle exception]||Print[Catch[Throw[“failed”]]]|| || ||errcatch(error(“failed”));|| ||||||||||~ # streams[#streams-note streams]|| ||~ ||~ mathematica||~ sympy||~ sage||~ maxima|| ||# std-file-handles[#std-file-handles-note standard file handles]||Streams[“stdout”] _ Streams[“stderr”] _ _ ##gray|(* all open file handles: )## _ Streams[]|| || || || ||# write-line-stdout[#write-line-stdout-note write line to stdout]||Print[“hello”]|| || || || ||# open-file[#open-file-note open file for reading]||f = OpenRead[“/etc/hosts”]|| || || || ||# open-file-write[#open-file-write-note open file for writing]||f = OpenWrite[“/tmp/test”]|| || || || ||# open-file-append[#open-file-append-note open file for appending]||f = OpenAppend[“/tmp/test”]|| || || || ||# close-file[#close-file-note close file]||Close[f]|| || || || ||# read-file-str[#read-file-str-note read file into string]||s = ReadString[f]|| || || || ||# write-str[#write-str-note write string]||WriteString[f, “lorem ipsum”]|| || || || ||[#read-file-string-array read file into array of strings]||s = Import[“/etc/hosts”] _ a = StringSplit[s, “\n”]|| || || || ||# seek[#seek-note file handle position] _ _ ##gray|//get, set//##||f = StringToStream[“foo bar baz”] _ _ StreamPosition[f] _ _ ##gray|( beginning of stream: *)## _ SetStreamPosition[f, 0] _ ##gray|(# end of stream: )## _ SetStreamPosition[f, Infinity]|| || || || ||# tmp-file[#tmp-file-note open temporary file]||f = OpenWrite[] _ path = Part[f, 1]|| || || || ||||||||||~ # files[#files-note files]|| ||~ ||~ mathematica||~ sympy||~ sage||~ maxima|| ||# file-test[#file-test-note file exists test, regular file test]||FileExistsQ[“/etc/hosts”] _ FileType[“/etc/hosts”] == File|| || || || ||# file-size[#file-size-note file size]||FileByteCount[“/etc/hosts”]|| || || || ||# readable-writeable-executable[#readable-writable-executable-note is file readable, writable, executable]|| || || || || ||# last-modification-time[#last-modification-time-note last modification time]||FileDate[“/etc/hosts”]|| || || || ||# file-cp-rm-mv[#file-cp-rm-mv-note copy file, remove file, rename file]||CopyFile[“/tmp/foo”, “/tmp/bar”] _ DeleteFile[“/tmp/foo”] _ RenameFile[“/tmp/bar”, “/tmp/foo”]|| || || || ||||||||||~ # directories[#directories-note directories]|| ||~ ||~ mathematica||~ sympy||~ sage||~ maxima|| ||# working-dir[#working-dir-note working directory]||dir = Directory[] _ _ SetDirectory[“/tmp”]|| || || || ||# build-pathname[#build-pathname-note build pathname]||FileNameJoin[{”/etc”, “hosts”}]|| || || || ||# dirname-basename[#dirname-basename-note dirname and basename]||DirectoryName[“/etc/hosts”] _ FileBaseName[“/etc/hosts”]|| || || || ||# absolute-pathname[#absolute-pathname-note absolute pathname]||##gray|( file must exist; _ @<   >@symbolic links are resolved: )## _ AbsoluteFileName[“foo”] _ AbsoluteFileName[“/foo”] _ AbsoluteFileName[“../foo”] _ AbsoluteFileName[“./foo”] _ AbsoluteFileName[“~/foo”]|| || || || ||# glob[#glob-note glob paths]||Function[x, Print[x]] /@ FileNames[“/tmp/”]|| || || || ||# mkdir[#mkdir-note make directory]||CreateDirectory[“/tmp/foo.d”]|| || || || ||# recursive-cp[#recursive-cp-note recursive copy]||CopyDirectory[“/tmp/foo.d”, “/tmp/baz.d”]|| || || || ||# rmdir[#rm-dir-note remove empty directory]||DeleteDirectory[“/tmp/foo.d”]|| || || || ||# rm-rf[#rm-rf-note remove directory and contents]||DeleteDirectory[“/tmp/foo.d”, _ @<  >@DeleteContents -> True]|| || || || ||# dir-test[#dir-test-note directory test]||DirectoryQ[“/etc”]|| || || || ||||||||||~ # libraries-namespaces[#libraries-namespaces-note libraries and namespaces]|| ||~ ||~ mathematica||~ sympy||~ sage||~ maxima|| ||# load-lib[#load-lib-note load library]||Get[“foo.m”]|| || ||load(grobner);|| ||||||||||~ # reflection[#reflection-note reflection]|| ||~ ||~ mathematica||~ sympy||~ sage||~ maxima|| ||[#function-documentation get function documentation]||?Tan _ Information[Tan]||print(solve.@@doc@@) _ _ ##gray|# in IJupyter:## _ solve? _ help(solve)||solve?||describe(solve); _ _ ? solve;|| ||# func-options[#func-options-note function options]||Options[Solve] _ Options[Plot]|| || || || ||# func-src[#func-src-note function source]|| ||import inspect _ _ inspect.getsourcelines(integrate)|| || || ||[#data-type query data type]||Head[x]|| ||type(x)||symbolp(x); _ numberp(7); _ stringp(“seven”); _ listp([1, 2, 3]);|| ||[#list-variables list variables in scope]||Names[$Context <> ““]|| || ||##gray|/ user defined variables: /## _ values; _ _ ##gray|/ user defined functions: */## _ functions;|| ||~ ||~ ##EFEFEF|@@_________________________________________________@@##||~ ##EFEFEF|@@______________________________________________@@##||~ ##EFEFEF|@@______________________________________________@@##||~ ##EFEFEF|@@_________________________________________________@@##||

sheet two:] symbolic expressions] | calculus] | equations and unknowns] | optimization] | vectors] | matrices] | combinatorics] | number theory] | polynomials] | trigonometry] | special functions] | permutations] | descriptive statistics] | distributions] | statistical tests]

bar charts] | scatter plots] | line charts] | surface charts] | chart options]

# version-used-note ++ [#version-used version used]

The version of software used to check the examples in the reference sheet.

# show-version-note ++ [#show-version show version]

How to determine the version of an installation.

# implicit-prologue-note ++ [#implicit-prologue implicit prologue]

Code assumed to have been executed by the examples in the sheet.

# grammar-invocation-note + [#grammar-invocation Grammar and Invocation]

# interpreter-note ++ [#interpreter interpreter]

How to execute a script.

mathematica:

The full path to MathKernel on Mac OS X:

code /Applications/Mathematica.app/Contents/MacOS/MathKernel /code

# repl-note ++ [#repl repl]

How to launch a command line read-eval-print loop for the language.

# block-delimiters-note ++ [#block-delimiters block delimiters]

How blocks are delimited.

# stmt-separator-note ++ [#stmt-separator statement separator]

How statements are separated.

# eol-comment-note ++ [#eol-comment end-of-line comment]

Character used to start a comment that goes to the end of the line.

# multiple-line-comment-note ++ [#multiple-line-comment multiple line comment]

The syntax for a delimited comment which can span lines.

# var-expr-note + [#var-expr Variables and Expressions]

# assignment-note ++ [#assignment assignment]

How to perform assignment.

Mathematica, Sympy, and Pari/GP support the chaining of assignments. For example, in Mathematica one can assign the value 3 to {{x}} and {{y}} with:

code x = y = 3 /code

In Mathematica and Pari/GP, assignments are expressions. In Mathematica, the following code is legal and evaluates to 7:

code (x = 3) + 4 /code

In Mathematica, the {{Set}} function behaves identically to assignment and can be nested:

code Set[a, Set[b, 3]] /code

# delayed-assignment-note ++ [#delayed-assignment delayed assignment]

How to assign an expression to a variable name. The expression is re-evaluated each time the variable is used.

mathematica:

GNU make also supports assignment and delayed assignment, but {{=}} is used for delayed assignment and {{:=}} is used for immediate assignment. This is the opposite of how Mathematica uses the symbols.

The POSIX standard for make only has {{=}} for delayed assignment.

# parallel-assignment-note ++ [#parallel-assignment parallel assignment]

How to assign values in parallel.

Parallel assignment can be used to swap the values held in two variables.

# compound-assignment-note ++ [#compound-assignment compound assignment]

The compound assignment operators.

# incr-decr-note ++ [#incr-decr increment and decrement]

Increment and decrement operators which can be used in expressions.

# non-referential-id-note ++ [#non-referential-id non-referential identifier]

An identifier which does not refer to a value.

A non-referential identifier will usually print as a string containing its name.

Expressions containing non-referential identifiers will not be evaluated, though they may be simplified.

Non-referential identifiers represent “unknowns” or “parameters” when performing algebraic derivations.

# id-as-val-note ++ [#id-as-val identifier as value]

How to get a value referring to an identifier.

The identifier may be the name of a variable containing a value. But the value referring to the identifier is distinct from the value in the variable.

One may manipulate a value referring to an identifier even if it is not the name of a variable.

# global-var-note ++ [#global-var global variable]

How to declare a global variable.

# local-var-note ++ [#local-var local variable]

How to declare a local variable.

pari/gp:

There is {{my}} for declaring a local variable with lexical scope and {{local}} for declaring a variable with dynamic scope.

{{local}} can be used to change the value of a global as seen by any functions which are called while the local scope is in effect.

# null-note ++ [#null null]

The null literal.

# null-test-note ++ [#null-test null test]

How to test if a value is null.

# undef-var-note ++ [#undef-var undefined variable access]

What happens when an undefined variable is used in an expression.

# rm-var-binding-note ++ [#rm-var-binding remove variable binding]

How to remove a variable. Subsequent references to the variable will be treated as if the variable were undefined.

# cond-expr-note ++ [#cond-expr conditional expression]

A conditional expression. # arithmetic-logic-note + [#arithmetic-logic Arithmetic and Logic]

# true-false-note ++ [#true-false true and false]

The boolean literals.

# falsehoods-note ++ [#falsehoods falsehoods]

Values which evaluate to false in a conditional test.

sympy:

Note that the logical operators {{Not}}, {{And}} and {{Or}} do not treat empty collections or {{None}} as false. This is different from the Python logical operators {{not}}, {{and}}, and {{or}}.

pari/gp:

A vector or matrix evaluates to false if all components evaluate to false.

# logical-op-note ++ [#logical-op logical operators]

The Boolean operators.

sympy:

In Python, {{&}}, {{|}}, and {{&}} are bit operators. SymPy has defined {{@@and@@}}, {{@@or@@}}, and {{@@invert@@}} methods to make them Boolean operators for symbols, however.

# relational-op-note ++ [#relational-op relational operators]

The relational operators.

sympy:

The full SymPy names for the relational operators are:

code sympy.Equality # == sympy.Unequality # != sympy.GreaterThan # >= sympy.LessThan # <= sympy.StrictGreaterThan # > sympy.StrictLessThan # < /code

The SymPy functions are attatched to the relational operators {{==}}, {{!=}}, for symbols … using the methods {{@@eq@@}}, {{@@ne@@}}, {{@@ge@@}}, {{@@le@@}}, {{@@gt@@}}, {{@@lt@@}}. The behavior they provide is similar to the default Python behavior, but when one of the arguments is a SymPy expression, a simplification will be attempted before the comparison is made.

# arith-op-note ++ [#arith-op arithmetic operators]

The arithmetic operators.

# int-div-note ++ [#int-div integer division]

How to compute the quotient of two integers.

# int-div-zero-note ++ [#int-div-zero integer division by zero]

The result of dividing an integer by zero.

# float-div-note ++ [#float-div float division]

How to perform float division, even if the arguments are integers.

# float-div-zero-note ++ [#float-div-zero float division by zero]

The result of dividing a float by zero.

# power-note ++ [#power power]

How to compute exponentiation.

Note that zero to a negative power is equivalent to division by zero, and negative numbers to a fractional power may have multiple complex solutions.

# sqrt-note ++ [#sqrt sqrt]

The square root function.

For positive arguments the positive square root is returned.

# sqrt-negative-one-note ++ [#sqrt-negative-one sqrt -1]

How the square root function handles negative arguments.

mathematica:

An uppercase {{I}} is used to enter the imaginary unit, but Mathematica displays it as a lowercase {{i}}.

# transcendental-func-note ++ [#transcendental-func transcendental functions]

The standard transcendental functions such as one might find on a scientific calculator.

The functions are the exponential (not to be confused with exponentiation), natural logarithm, sine, cosine, tangent, arcsine, arccosine, arctangent, and the two argument arctangent.

# transcendental-const-note ++ [#transcendental-const transcendental constants]

The transcendental constants //pi// and //e//.

The transcendental functions can used to computed to compute the transcendental constants:

code pi = acos(-1) pi = 4 * atan(1) e = exp(1) /code

# float-truncation-note ++ [#float-truncation float truncation]

Ways to convert a float to a nearby integer.

# absolute-val-note ++ [#absolute-val absolute value]

How to get the absolute value and signum of a number.

# int-overflow-note ++ [#int-overflow integer overflow]

What happens when the value of an integer expression cannot be stored in an integer.

The languages in this sheet all support arbitrary length integers so the situation does not happen.

# float-overflow-note ++ [#float-overflow float overflow]

What happens when the value of a floating point expression cannot be stored in a float.

# rational-construction-note ++ [#rational-construction rational construction]

How to construct a rational number.

# rational-decomposition-note ++ [#rational-decomposition rational decomposition]

How to extract the numerator and denominator from a rational number.

# decimal-approx-note ++ [#decimal-approx decimal approximation]

How to get a decimal approximation of an irrational number or repeating decimal rational.

# complex-construction-note ++ [#complex-construction complex construction]

How to construct a complex number.

# complex-decomposition-note ++ [#complex-decomposition complex decomposition]

How to extract the real and imaginary part from a complex number; how to extract the argument and modulus; how to get the complex conjugate.

# random-num-note ++ [#random-num random number]

How to generate a random integer or a random float.

pari/gp:

When the argument of {{random()}} is an integer {{n}}, it generates an integer in the range $ {0, …, n - 1} $.

When the argument is a arbitrary precision float, it generates a value in the range {{[0.0, 1.0]}}. The precision of the argument determines the precision of the random number.

# random-seed-note ++ [#random-seed random seed]

How to set or get the random seed.

mathematica:

The seed is not set to the same value at start up.

# bit-op-note ++ [#bit-op bit operators]

# binary-octal-hex-literals-note ++ [#binary-octal-hex-literals binary, octal, and hex literals]

Binary, octal, and hex integer literals.

mathematica:

The notation works for any base from 2 to 36.

# radix-note ++ [#radix radix]

Convert a number to a representation using a given radix.

# to-array-of-digits-note ++ [#to-array-of-digits to array of digits]

Convert a number to an array of digits representing the number.

# strings-note + [#strings Strings]

# str-literal-note ++ [#str-literal string literal]

The syntax for a string literal.

# newline-in-str-literal-note ++ [#newline-in-str-literal newline in literal]

Are newlines permitted in string literals.

# str-literal-esc-note ++ [#str-literal-esc literal escapes]

Escape sequences for putting unusual characters in string literals.

# str-concat-note ++ [#str-concat concatenate]

How to concatenate strings.

# translate-case-note ++ [#translate-case translate case]

How to convert a string to all lower case letters or all upper case letters.

# trim-note ++ [#trim trim]

How to remove whitespace from the beginning or the end of string.

# num-to-str-note ++ [#num-to-str number to string]

How to convert a number to a string.

# str-to-num-note ++ [#str-to-num string to number]

How to parse a number from a string.

# str-join-note ++ [#str-join string join]

How to join an array of strings into a single string, possibly separated by a delimiter.

# split-note ++ [#split split]

How to split a string in to an array of strings. How to specify the delimiter.

# str-subst-note ++ [#str-subst substitute]

How to substitute one or all occurrences of substring with another.

# str-len-note ++ [#str-len length]

How to get the length of a string in characters.

# index-substr-note ++ [#index-substr index of substring]

How to get the index of the first occurrence of a substring.

# extract-substr-note ++ [#extract-substr extract substring]

How to get a substring from a string using character indices.

# char-literal-note ++ [#char-literal character literal]

The syntax for a character literal.

# lookup-char-note ++ [#lookup-char character lookup]

How to get a character from a string by index.

# chr-ord-note ++ [#chr-ord chr and ord]

Convert a character code point to a character or a single character string.

Get the character code point for a character or single character string.

# delete-char-note ++ [#delete-char delete characters]

Delete all occurrences of a set of characters from a string.

# arrays-note + [#arrays Arrays]

||~ section||~ mathematica||~ maple||~ maxima||~ sympy|| ||[#arrays arrays]||List||list||list||list|| ||multidimensional arrays||List||Array||array||##gray|//none//##|| ||[#vectors vectors]||List||Vector||list||Matrix|| ||[#matrices matrices]||List||Matrix||matrix||Matrix||

# array-literal-note ++ [#array-literal literal]

The notation for an array literal.

# array-size-note ++ [#array-size size]

The number of elements in the array.

# array-lookup-note ++ [#array-lookup lookup]

How to access an array element by its index.

# array-update-note ++ [#array-update update]

How to change the value stored at an array index.

# array-out-of-bounds-note ++ [#array-out-of-bounds out-of-bounds behavior]

What happens when an attempt is made to access an element at an out-of-bounds index.

# array-element-index-note ++ [#array-element-index element index]

How to get the index of an element in an array.

# array-slice-note ++ [#array-slice slice]

How to extract a subset of the elements. The indices for the elements must be contiguous.

# array-of-integers-as-index-note ++ [#array-of-integers-as-index array of integers as index]

# array-back-note ++ [#array-back manipulate back]

# array-front-note ++ [#array-front manipulate front]

# array-head-note ++ [#array-head head]

# array-tail-note ++ [#array-tail tail]

# array-cons-note ++ [#array-cons cons]

# array-concatenate-note ++ [#array-concatenate concatenate]

# array-replicate-note ++ [#array-replicate replicate]

# copy-array-note ++ [#copy-array copy]

How to copy an array. Updating the copy will not alter the original.

# iterate-over-array-note ++ [#iterate-over-array iterate]

# reverse-array-note ++ [#reverse-array reverse]

# sort-array-note ++ [#sort-array sort]

# dedupe-array-note ++ [#dedupe-array dedupe]

# membership-note ++ [#membership membership]

How to test whether a value is an element of a list.

# intersection-note ++ [#intersection intersection]

How to to find the intersection of two lists.

# union-note ++ [#union union]

How to find the union of two lists.

# set-diff-note ++ [#set-diff relative complement, symmetric difference]

How to find all elements in one list which are not in another; how to find all elements which are in one of two lists but not both.

# map-note ++ [#map map]

# filter-note ++ [#filter filter]

# reduce-note ++ [#reduce reduce]

# universal-existential-test-note ++ [#universal-existential-test universal and existential tests]

# min-max-elem-note ++ [#min-max-elem min and max element]

# shuffle-sample-note ++ [#shuffle-sample shuffle and sample]

How to shuffle an array. How to extract a random sample from an array without replacement.

# flatten-note ++ [#flatten flatten]

# zip-note ++ [#zip zip]

How to interleave two arrays.

# cartesian-product-note ++ [#cartesian-product cartesian product]

# sets-note + [#sets Sets]

# arith-seq-note + [#arith-seq Arithmetic Sequences]

# dictionaries-note + [#dictionaries Dictionaries]

# record-literal ++ record literal

# record-access ++ record member access

# functions-note + [#functions Functions]

# definition ++ definition

# invocation ++ invocation

# function-value ++ function value

# execution-control-note + [#execution-control Execution Control]

# if ++ if

How to write a branch statement.

mathematica:

The 3rd argument (the else clause) of an //If// expression is optional.

# while ++ while

How to write a conditional loop.

mathematica:

//Do// can be used for a finite unconditional loop:

code Do[Print[foo], {10}] /code

# for ++ for

How to write a C-style for statement.

# break-continue ++ break/continue

How to break out of a loop. How to jump to the next iteration of a loop.

# exceptions-note + [#exceptions Exceptions]

# raise-exc-note ++ [#raise-exc raise exception]

How to raise an exception.

# handle-exc-note ++ [#handle-exc handle exception]

How to handle an exception.

# uncaught-exc-note ++ [#uncaught-exc uncaught exception behavior]

gap:

Calling {{Error()}} invokes the GAP debugger, which is similar to a Lisp debugger. In particular, all the commands available in the GAP REPL are still available. Variables can be inspected and modified while in the debugger but any changes will be lost when the debugger is quitted.

One uses {{quit;}} or {{^D}} to exit the debugger. These commands also cause the top-level GAP REPL exit if used while not in a debugger.

If {{Error()}} is invoked while in the GAP debugger, the debugger will be invoked recursively. One must use {{quit;}} for each level of debugger recursion to return to the top -level GAP REPL.

Use

code brk> Where(4); /code

to print the top four functions on the stack when the error occurred. Use {{DownEnv()}} and {{UpEnv()}} to move down the stack—i.e. from callee to caller—and {{UpEnv()}} to move up the stack. The commands take the number of levels to move down or up:

code brk> DownEnv(2); brk> UpEnv(2); /code

When the debugger is invoked, it will print a message. It may give the user the option of providing a value with the {{return}} statement so that a computation can be continued:

code brk> return 17; /code

# finally ++ finally block

How to write code that executes even if an exception is raised.

# streams-note + [#streams Streams]

# files-note + [#files Files]

# directories-note + [#directories Directories]

# libraries-namespaces-note + [#libraries-namespaces Libraries and Namespaces]

# reflection-note + [#reflection Reflection]

# function-documentation ++ function documentation

How to get the documentation for a function.

# mathematica + [#top Mathematica]

[http://reference.wolfram.com/mathematica/guide/Mathematica.html Mathematica Documentation Center] [http://wolframalpha.com WolframAlpha] [http://mathics.github.io/ Mathics]

# maple + [#top Maple]

http://www.maplesoft.com/support/help/

# maxima + [#top Maxima]

http://maxima.sourceforge.net/docs/manual/maxima.html

# sage + [#top Sage]

http://doc.sagemath.org/html/en/index.html

# sympy + [#top SymPy]

[http://docs.sympy.org/latest/index.html Welcome to SymPy’s documentation!]