Basic Math Tests
Plus
Add numbers.
$ wo 'Plus[1, 2]'
3
$ wo 'Plus[1, 2, 3]'
6
$ wo 'Plus[-1, -2]'
-3
+
$ wo '1+2'
3
$ wo '8 + (-5)'
3
Minus
Make numbers negative.
$ wo 'Minus[5]'
-5
$ wo 'Minus[5, 2]'
Minus::argx: Minus called with 2 arguments; 1 argument is expected.
5 − 2
Subtract
Subtract numbers.
$ wo 'Subtract[5, 2]'
3
-
$ wo '5-2'
3
Times
Multiply numbers.
$ wo 'Times[2, 3]'
6
$ wo 'Times[2, 3, 4]'
24
$ wo 'Times[-2, 3]'
-6
*
$ wo '2*2'
4
$ wo '2 * (-2)'
-4
Divide
Divide numbers.
$ wo 'Divide[6, 2]'
3
$ wo 'Divide[6, 2, 3]'
Divide::argrx: Divide called with 3 arguments; 2 arguments are expected.
Divide[6, 2, 3]
Sign
Returns the sign of a number.
$ wo 'Sign[5]'
1
$ wo 'Sign[0]'
0
$ wo 'Sign[-7]'
-1
Prime
Returns the nth prime number.
$ wo 'Prime[5]'
11
Abs
Returns the absolute value of a number.
$ wo 'Abs[-5]'
5
$ wo 'Abs[5]'
5
$ wo 'Abs[0]'
0
Floor
Rounds down to the nearest integer.
$ wo 'Floor[3.7]'
3
$ wo 'Floor[-3.7]'
-4
$ wo 'Floor[3.2]'
3
$ wo 'Floor[0]'
0
$ wo 'Floor[-0]'
0
$ wo 'Floor[0.5]'
0
$ wo 'Floor[-0.5]'
-1
Ceiling
Rounds up to the nearest integer.
$ wo 'Ceiling[3.2]'
4
$ wo 'Ceiling[-3.2]'
-3
$ wo 'Ceiling[3.7]'
4
$ wo 'Ceiling[0]'
0
$ wo 'Ceiling[-0]'
0
$ wo 'Ceiling[0.5]'
1
$ wo 'Ceiling[-0.5]'
0
Round
Rounds to the nearest integer.
$ wo 'Round[3.5]'
4
$ wo 'Round[3.4]'
3
$ wo 'Round[-3.5]'
-4
$ wo 'Round[-3.4]'
-3
$ wo 'Round[0.5]'
0
$ wo 'Round[-0.5]'
0
$ wo 'Round[0]'
0
$ wo 'Round[-0]'
0
Sqrt
Returns the square root of a number.
$ wo 'Sqrt[16]'
4
$ wo 'Sqrt[0]'
0
Mod
Returns the remainder when dividing the first argument by the second.
$ wo 'Mod[10, 3]'
1
$ wo 'Mod[7, 4]'
3
$ wo 'Mod[15, 5]'
0
$ wo 'Mod[8, 3]'
2
$ wo 'Mod[-1, 3]'
2
$ wo 'Mod[-5, 3]'
1
$ wo 'Mod[10, -3]'
-2
$ wo 'Mod[7.5, 2]'
1.5
$ wo 'Mod[0, 5]'
0
Max
Returns the maximum value from a set of arguments or a list.
Multiple arguments
$ wo 'Max[1, 5, 3]'
5
$ wo 'Max[1, 2]'
2
$ wo 'Max[-5, -2, -8]'
-2
$ wo 'Max[3.14, 2.71, 3.5]'
3.5
$ wo 'Max[1, 2.5, 3]'
3
Single list argument
$ wo 'Max[{1, 5, 3}]'
5
$ wo 'Max[{-10, -5, -20}]'
-5
$ wo 'Max[{3.14, 2.71, 3.5}]'
3.5
Single value
$ wo 'Max[42]'
42
$ wo 'Max[-7]'
-7
Empty list
$ wo 'Max[{}]'
-Infinity
With expressions
$ wo 'Max[2 + 3, 4 * 2, 10 - 1]'
9
$ wo 'Max[{1 + 1, 2 * 2, 3 - 1}]'
4
Min
Returns the minimum value from a set of arguments or a list.
Multiple arguments
$ wo 'Min[1, 5, 3]'
1
$ wo 'Min[1, 2]'
1
$ wo 'Min[-5, -2, -8]'
-8
$ wo 'Min[3.14, 2.71, 3.5]'
2.71
$ wo 'Min[1, 2.5, 3]'
1
Single list argument
$ wo 'Min[{1, 5, 3}]'
1
$ wo 'Min[{-10, -5, -20}]'
-20
$ wo 'Min[{3.14, 2.71, 3.5}]'
2.71
Single value
$ wo 'Min[42]'
42
$ wo 'Min[-7]'
-7
Empty list
$ wo 'Min[{}]'
Infinity
With expressions
$ wo 'Min[2 + 3, 4 * 2, 10 - 1]'
5
$ wo 'Min[{1 + 1, 2 * 2, 3 - 1}]'
2
Sin
Returns the sine of an angle in radians.
$ wo 'Sin[Pi/2]'
1
NumberQ
Returns True if expr is a number, and False otherwise.
$ wo 'NumberQ[2]'
True
MemberQ
Checks if an element is in a list.
$ wo 'MemberQ[{1, 2}, 2]'
True
$ wo 'MemberQ[{1, 2}, 3]'
False
RandomInteger
RandomInteger[]
Randomly gives 0 or 1.
$ wo 'MemberQ[{0, 1}, RandomInteger[]]'
True
RandomInteger[{1, 6}]
Randomly gives a number between 1 and 6.
$ wo 'MemberQ[{1, 2, 3, 4, 5, 6}, RandomInteger[{1, 6}]]'
True
RandomInteger[{1, 6}, 50]
Randomly gives 50 numbers between 1 and 6.
$ wo 'AllTrue[RandomInteger[{1, 6}, 50], 1 <= # <= 6 &]'
True
Power
Power[2, 3]
2 raised to the power of 3 equals 8.
$ wo 'Power[2, 3]'
8
Power[5, 0]
Any number raised to the power of 0 equals 1.
$ wo 'Power[5, 0]'
1
Power[2, -1]
2 raised to the power of -1 equals 0.5 (1/2).
$ wo 'Power[2, -1]'
0.5
Power[4, 0.5]
4 raised to the power of 0.5 equals 2 (square root).
$ wo 'Power[4, 0.5]'
2
Power[10, 2]
10 raised to the power of 2 equals 100.
$ wo 'Power[10, 2]'
100
Power[-2, 3]
-2 raised to the power of 3 equals -8.
$ wo 'Power[-2, 3]'
-8
Power[-2, 2]
-2 raised to the power of 2 equals 4.
$ wo 'Power[-2, 2]'
4
Power[27, 1/3]
27 raised to the power of 1/3 equals approximately 3 (cube root).
$ wo 'Power[27, 1/3]'
2.9999999997
Power[1.5, 2.5]
1.5 raised to the power of 2.5 equals approximately 2.756.
$ wo 'Power[1.5, 2.5]'
2.7556759606
Factorial
Factorial[0]
The factorial of 0 is 1 by definition.
$ wo 'Factorial[0]'
1
Factorial[1]
The factorial of 1 is 1.
$ wo 'Factorial[1]'
1
Factorial[5]
The factorial of 5 is 120 (5! = 5 × 4 × 3 × 2 × 1).
$ wo 'Factorial[5]'
120
Factorial[10]
The factorial of 10 is 3628800.
$ wo 'Factorial[10]'
3628800
Factorial[3]
The factorial of 3 is 6 (3! = 3 × 2 × 1).
$ wo 'Factorial[3]'
6
Factorial[7]
The factorial of 7 is 5040.
$ wo 'Factorial[7]'
5040
Factorial[12]
The factorial of 12 is 479001600.
$ wo 'Factorial[12]'
479001600
Factorial[2]
The factorial of 2 is 2.
$ wo 'Factorial[2]'
2
Factorial[4]
The factorial of 4 is 24 (4! = 4 × 3 × 2 × 1).
$ wo 'Factorial[4]'
24
GCD
GCD[12, 8]
The GCD of 12 and 8 is 4.
$ wo 'GCD[12, 8]'
4
GCD[48, 18]
The GCD of 48 and 18 is 6.
$ wo 'GCD[48, 18]'
6
GCD[100, 50]
The GCD of 100 and 50 is 50.
$ wo 'GCD[100, 50]'
50
GCD[17, 19]
The GCD of 17 and 19 is 1 (coprime numbers).
$ wo 'GCD[17, 19]'
1
GCD[0, 5]
The GCD of 0 and any number n is |n|.
$ wo 'GCD[0, 5]'
5
GCD[15, 25, 35]
The GCD of 15, 25, and 35 is 5.
$ wo 'GCD[15, 25, 35]'
5
GCD[24, 36, 60]
The GCD of 24, 36, and 60 is 12.
$ wo 'GCD[24, 36, 60]'
12
GCD[-12, 8]
The GCD works with negative numbers (GCD of -12 and 8 is 4).
$ wo 'GCD[-12, 8]'
4
GCD[21, 14]
The GCD of 21 and 14 is 7.
$ wo 'GCD[21, 14]'
7