Mathematic Functions and Operators

The following list includes both WebAssign-specific and commonly used Perl functions and operators that are available when creating questions.

Numerical Operators

Operation

Usage

Notes

Test Numerical Equality

==

Returns true (1) or false (0). Use eq to compare strings.

Test Numerical Inequalities ( ≠ > < ≥ ≤ )

!=
> 
< 
>= 
<=

Returns true (1) or false (0).

To compare strings, use ne, gt, lt, ge, le.

Addition, Subtraction, Multiplication, Division

+   -
*   /

Exponentiation

**

Order of Operations

()

Do not use [] or {}.

Mathematic Functions

Operation

Usage

Notes

Absolute value

abs(n)

Average (mean)
avg(n1,n2,...)
Returns the mean of the values. Argument can be a list or an array.
Example:
$mean = avg(@array_x)
$mean2 = avg(3,4,5)

Greatest Common Divisor

gcd(n1,n2,...)

Argument can be a list or an array.

Least Common Multiple

lcm(n1,n2,...)

Argument can be a list or an array.

Maximum value

max(n1,n2,...)

Returns the greatest value. Argument can be a list or an array.

Minimum value

min(n1,n2,...)

Returns the least value. Argument can be a list or an array.

Pearson's correlation coefficient
corr(@array_x, @array_y)
Returns the correlation between the values in two arrays. The arrays should be the same size.
Sample standard deviation
stdev(n1,n2, ...)
Returns the sample standard deviation of the values. Argument can be a list or an array.
Example:
$s = stdev(@array_x)
Slope of a bivariate linear regression
linregb(@array_x, @array_y)
Returns the slope of a linear regression using the values in two arrays. The arrays should be the same size.
Example:
$slope = linregb(@array_x,@array_y)

Square root

sqrt(n)

n ≥ 0

Sum of array or list
sum(n1,n2,...)
Returns the sum of the array or list. Argument can be a list or an array.
Example:
$total = sum(23,45,56,78)
$total2 = sum(@array_x)
Sum of products
ssxy(@array_x, @array_y)
Returns the sum of the products of the deviations of the values of two arrays. The arrays should be the same size.
Sum of squared deviations
ssx(n1,n2, ...)
Returns the sum of squared deviations about the mean of the values. Argument can be a list or an array.
Example:
$ssofx = ssx(@array_x)
Y intercept of a bivariate linear regression
linrega(@array_x, @array_y)
Returns the y intercept of a linear regression using the values in two arrays. The arrays should be the same size.
Example:
$intercept = linrega(@array_x,@array_y)

Trigonometric Functions

Operation

Usage

Notes

Trigonometric Functions

sin(n)  sec(n)
cos(n)  csc(n)
tan(n)  cot(n)

The value of n must be in radians. Non-canonical values of n might return approximate values.

Inverse Trigononometric Functions

asin(n)  asec(n)
acos(n)  acsc(n)
atan(n)  acot(n)

Returns principal values in radians.

Arctangent of y/x

atan2(y,x)

Returns radians from −π through π.

pi (π)

pi

Degrees to radians

rad(n)

Converts degrees to radians.

Radians to degrees

deg(n)

Converts radians to degrees.

Get canonical angle in degrees

canonicaldeg(n)

Converts angle in degrees to value in range −180 to 180.

Logarithmic Functions

Operation

Usage

Notes

Exponential function

exp(n)

Euler's number raised to n.

Natural Log

log(n)

n > 0

Log (base 10)

log10(n)

n > 0

Combinatoric Functions

Operation

Usage

Notes

Combinations C(n,k)

combination(n,k)

Returns the number of sets of k elements that can be picked from an n-element set.

Permutations P(n,k)

permutation(n,k)

Returns the number of unique (ab is different from ba) sets of k elements that can be picked from an n-element set.

Factorial (n!)

factorial(n)

n must be an integer from 1 through 100.