Code your calculation - Commands

This page describes the input commands for the Code your calculation web application.

General

Commands

write(expr)

Writes the result of expr in the output area of the application.

primes(n)

Writes a list of all primes equal to or smaller than n in the output area of the application.

factorize(n)

Writes a list of all prime factors of integer n in the output area of the application.

reduce(n1,n2)

Reduces or simplifies fraction n1/n2 to lowest terms and writes the result in the output area of the application.

Math commands

e, pi

The variables e and pi represent the irrational numbers e (Euler's number) and π.

pow(a,b)

Returns the value of a to the power of b.

sqrt(a)

Returns the square root of a.

exp(a)

Returns the value of e^a. Example: exp(-1) = 1/e ≈ 0.368.

abs(a)

Returns the absolute value of a. Example: abs(-2) = abs(2) = 2.

ln(a)

Returns the natural logarithm (base e) of a. Example: ln(e) = 1.

lg(a)

Returns the common logarithm (base 10) of a. Example: lg(100) = 2.

log(b,a)

Returns the logarithm of a to base b. Example: log(2,8) = log2(8) = 3.

sin(a), cos(a), tan(a)

Return the sine, cosine and tangent of a (angel a in radians).

arcsin(a), arccos(a), arctan(a)

Return the arcsine, arccosine and arctangent (in radians) of a.

sec(a), csc(a), cot(a)

Return the secant, cosecant and cotangent of a (angel a in radians).

arcsec(a), arccsc(a), arccot(a)

Return the arcsecant, arccosecant and arccotangent (in radians) of a.

sinh(a), cosh(a), tanh(a)

Return the hyperbolic sine, hyperbolic cosine and hyperbolic tangent of a.

arsinh(a), arcosh(a), artanh(a)

Return the area hyperbolic sine, area hyperbolic cosine and area hyperbolic tangent of a.

sech(a), csch(a), coth(a)

Return the hyperbolic secant, hyperbolic cosecant and hyperbolic cotangent of a.

arsech(a), arcsch(a), arcoth(a)

Return the area hyperbolic secant, area hyperbolic cosecant and area hyperbolic cotangent of a.

radtodeg(r)

Converts r in radians to degrees. Example: radtodeg(pi/4) = 45.

degtorad(d)

Converts d in degrees to radians. Example: degtorad(180) = 3.141592653589793.

mod(a,b)

Returns a modulo b, the remainder after a dividing by b. Example: mod(7,2) = 1.

facl(a,n)

Returns the product of a and every nth positive integer less than a. Example: facl(7,2) = 7*5*3*1 = 105.

Default (n=1) is the factorial function. Example: facl(5) = 5*4*3*2*1 = 120.

C(n,k)

Returns the binomial coefficient n choose k. Example: C(5,3) = 5!/(3!2!) = (4*5)/2 = 10.

min(a,b,c,...,n)

Returns the number with the lowest value. Example: min(-10,0,1,6) = -10.

max(a,b,c,...,n)

Returns the number with the highest value. Example: min(-10,0,1,6) = 6.

ceil(a)

Ceiling function. Returns the value of a rounded up to its nearest integer. Example: ceil(2.1) = 3.

floor(a)

Floor function. Returns the value of a rounded down to its nearest integer. Example: floor(2.51) = 2.

round(a,n)

Returns the value of a rounded to n places after the decimal point. Example: round(e,4) = 2.7183.

Default (n=0) returns the value of a rounded to its nearest integer. Examples: round(2.49) = 2,
round(2.5) = 3.

chop(a,n)

Returns the value of a, truncated to n places after the decimal point. Example: chop(2.59,1) = 2.5.

ran(a,b,n)

Returns a random number in [a,b] with n digits after the decimal point. Example: ran(0,3,0) = 0, 1, 2 or 3.

gcd(a,b)

Returns the greatest common divisor (gcd) of a and b. Example: gcd(30,45) = 15.

lcm(a,b)

Returns the least common multiple (lcm) of a and b. Example: lcm(2,6) = 6.