0% found this document useful (0 votes)
54 views22 pages

Calca Reference

The document provides an overview of the key features and capabilities of the Calca computational system. It describes how to perform basic calculations, define variables and functions, work with different number formats and units of measurement, and write calculations over multiple lines using indentation. The document also explains how to control number formatting settings like precision and grouping, as well as how to specify calculations in different cultural conventions.

Uploaded by

jigantic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views22 pages

Calca Reference

The document provides an overview of the key features and capabilities of the Calca computational system. It describes how to perform basic calculations, define variables and functions, work with different number formats and units of measurement, and write calculations over multiple lines using indentation. The document also explains how to control number formatting settings like precision and grouping, as well as how to specify calculations in different cultural conventions.

Uploaded by

jigantic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 22

# Reference

* [Therefore][]
* [Numbers][]
* [Definitions][]
* [Arithmetic][]
* [Functions][]
* [Input][]
* [Units][]
* [Google Search][]
* [Matrices and Vectors][]
* [Ranges][]
* [Map & Reduce][]
* [Logic Programming][]
* [Computer Numbers][]
* [Complex Numbers][]
* [Derivatives][]
* [Standard Library][]
* [Glossary][]

## Therefore

The therefore operator simplifies, as much as it can, the expression to its left.

price * (1 + 10%) => 1.1 price


3 * (1 + 10%) => 3.3

It is a signal to Calca that you want it to perform a Calculation.

If the expression to its left is an undefined variable, then Calca attempts to


solve for that variable by looking back in history for an equation or definition
that uses the variable.

If it successfully solves for the variable, then it gives the simplified solution.

a*x^2 + b*x + c = 0

x => [-0.5 b/a - 0.5*sqrt(b^2 - 4 a*c)/a, -0.5 b/a + 0.5*sqrt(b^2 - 4 a*c)/a]

a => -b/x - c/x^2

If it cannot solve for the variable, then it gives back the left and right hand
sides of the equation that it got closest to solving:

10z + 100x = x^3 + x^2


x => 100 x - x^3 - x^2 == -10 z

Here we can see a limitation of Calca, it can't solve cubic equations (yet).

## Numbers

Numbers are entered just as you would expect.

See the section on [Cultures][] if you are not using English style numbers.
### Infinity

You can input an infinite number using name `Infinity` or the symbol `∞`.

5 / 0 => Infinity
Infinity * 10 => Infinity
∞ * 10 => Infinity
∞ / ∞ => 1

### Output Precision

Numbers are printed using Calca's current number precision which defaults to `4`
decimal places.

You can control the output precision using the `precision` directive:

@precision = 8
pi => 3.14159265

@precision = 1
pi => 3.1

You can also use @p and @prec to save typing:

@p = 1000
pi => 3.14159265358979

@prec = 4
pi => 3.1416

### Output Grouping

By default, number are displayed grouped if greater than `1,000`:

999 => 999


1000 => 1,000
1234567890 => 1,234,567,890

You can control grouping using the @g, @group, or @grouping directives with a value
of `true` or `false`:

@group = false
1234567890 => 1234567890

The character used for grouping is chosen based on your [current culture]
[Cultures].

## Definitions

Definitions assign a value to a name. They are highlighted in bold to make this
clear:

name = 42
long name = -100

Anytime you use that name from then on, the assigned to value will be substituted:

5name => 210


name + long name => -58

### Redefine

Definitions can be redefined:

name => 42

name = 389457

name => 389457

### Summing Definitions

If you want to easily sum a set of definitions, then use the `+=` operator:

sum of all following defs +=


item 1 = 12 things
item 2 = 3 things

sum of all following defs => 15 things

Summing definitions sum all definitions below it until it reaches a block of math
that isn't a definition or is not indented.

## Arithmetic

### Addition and Subtraction

Addition and subtraction use the common operators `+` and `-`:

2 + 3 => 5
2 - 3 => -1

### Multiplication

Multiplications uses an asterisk or a unicode multiply sign:

2 * 3 => 6
2 × 3 => 6

#### Implied Multiplication

Multiplication is also implied when a number is next to a grouped expression:

2(3 + x) => 2 x + 6
2 * (3 + x) => 2 x + 6
It is also implied when a number is next to a variable:

2 x => 2 x
2 * x => 2 x

These implied multiplications bind to the number:

2x/3y => 0.6667 x/y


(2*x) / (3*y) => 0.6667 x/y

This is a different result than if we wrote the multiplications explicitly because


explicit multiplication binds more loosely than implicit.

2*x/3*y => 0.6667 x*y

### Division

Division uses the slash `/`:

2 / 3 => 0.6667

Division by zero produces an infinite answer:

2 / 0 => Infinity

You can also use the symbol `÷` for division:

2 ÷ 3 => 0.6667

### Modulo

Modulo is performed using the `mod` keyword:

2 mod 3 => 2
12 mod 3 => 0

### Exponents

You can raise a number to an exponents using the `^` or `**` operators:

2^3 => 8
a^3 => a^3

a^-3 => a^-3


a^-b => a^(-b)

2**3 => 8
a**-b => a^(-b)

## Functions

You call functions by naming them and passing them a comma separated list of
arguments wrapped in parenthesis:
# Function Definition
fun(x, y) = x^2 + 2y^2

# Function Call
fun(3, 5) => 59

You can also name arguments when you call the function:

fun(y=5, x=3) => 59

All definitions can be converted implicitly to functions:

blend = start +
t * (end - start)

blend(t = 0) => start


blend(t = 0.8) => 0.8 end + 0.2 start
blend(t = 1) => end

Calca creates a default parameter list for a definition that does not specify one.
That list is an ordered list of the variables that occur in the definition. For
`blend` above, this list is `(start, t, end)` since that is the order in which the
variables occurred. Because it's hard to remember this rule, it is highly
recommended that you provide a parameter list when you have more than one variable.

You can specify the parameters manually in definition so that you don't have to
name them every time you want to calculate the function.

blend2(t) = start +
t * (end - start)

blend2(0) => start


blend2(0.8) => 0.8 end + 0.2 start
blend2(1) => end

### Local Definitions

Functions can have local definitions to keep them organized using `let name = value
in` expressions.

rotate(point, angle) =
let x = point[0] in
let y = point[1] in
let ca = cos(angle) in
let sa = sin(angle) in
[x * ca - y * sa,
y * ca + x * sa]

rotate([10, 0], pi/3) => [5, 8.6603]

## Input

Calca files are plain text files. When loaded, they are parsed into a set of lines
or blocks which are evaluated one at a time starting from the top.
### Multiple Lines make Blocks

If you have some math that takes multiple lines of text to write, then just make
sure to indent those extra lines more than the first line. This is similar to
bibliography formats.

long bit of math = this thing +


that thing +
one other thing

long bit of math(


this thing = 100,
that thing = 1)
=> one other thing + 101

### Multiple Statements

You can put multiple statements on one line by separating them with a semicolon:

err(exp, res) = abs((exp - res)/exp); err(10,12) => 0.2; err(10,11) => 0.1

### Markdown

Calca distinguishes between text annotations and calculations. If text is indented,


then it assumed to be a calculation. If it is not, then Calca makes an educated
guess as to whether you meant to make a calculation.

To force Calca to treat a line as code, indent it:

indented definition = true

To force Calca to treat a line as a text annotation, make sure it is unindented and
ends with punctuation.

#### Headings

You can use headings with the standard Markdown of prefixing lines with the `#`
symbol.

### Cultures

Calca defaults to working in an "invariant" culture where numbers have their


decimal place marked using a period.

Other cultures, such as the French, prefer to use commas as the decimal separator.

You can switch Calca's culture any time using the @culture directive. Here is an
example of displaying and inputting numbers in different cultures.

alpha = 3,141.59

@fr-FR

alpha => 3 141,59


alpha^2 => 9 869 587,7281
beta = 12 000,62

@en-US

alpha => 3,141.59


alpha^2 => 9,869,587.7281
beta => 12,000.62

You can find your culture name in Microsoft's table of [language culture names]
[ccodes]. An incorrectly specified culture name makes Calca revert back to the
invariant culture.

[ccodes]: http://msdn.microsoft.com/en-us/library/ee825488(v=cs.20).aspx

## Units

Calca *adores* units and makes it easy for you to specify numbers with units and to
convert between them.

100 ft in m => 30.48 m

6 tablespoons in cups => 0.375 cups

You can even convert between units combined with multiplication and division. For
example, you might have want to calculate the speed of your run today:

distance = 3.1 miles


time = 27 minutes
speed = distance / time in miles/hour
=> 6.8889 miles/hour

Calca has a [database of over 200 units][cunits] covering simple units of length,
mass, volume, time, energy, etc. It even knows about advanced physical units such
as current and voltage:

12 V * 2 A in kW => 0.024 kW
12 V * 2 A in HP => 0.0322 HP

[cunits]: http://calca.io/units

### Make Your Own

Units are really easy to create. I think that there should be a new unit of mass:

franks = 165 lbs

Now I can measure anything in `franks`:

2 ton in franks => 24.2424 franks

mass of earth = 5.972e24 kg in franks


=> 7.9794e22 franks

### Currency
Calca knows about 35 various currencies that are all accessible using their [ISO
4217 code][iso4217].

You can convert between currencies using the unit conversion syntax:

20brl in jpy => ¥401.0173

For some currencies, Calca knows the correct symbol to use. For others, it will
display the ISO 4217 code:

20brl in cny => 25.7675 cny

[iso4217]: http://en.wikipedia.org/wiki/ISO_4217

### Percent

You can use `in %` to display a number as a percent:

21/45 in % => 46.6667%

### Number Base

You can use `in radix` where radix is:

* `bin`, `binary`, `base 2` for base 2


* `oct`, `octal`, `base 8` for base 8
* `dec`, `decimal`, `base 10` for base 10
* `hex`, `hexadecimal`, `base 16` for base 16

200 in hex => 0xC8


200 in octal => 0o310
200 in binary => 0b11001000

### SI Magnitude Prefixes

You can use SI prefixes in the unit conversion to specify your preferred order of
magnitude:

123,456.789012 W in PW => 1.2346e-10 PW


123,456.789012 W in TW => 1.2346e-7 TW
123,456.789012 W in GW => 0.0001 GW
123,456.789012 W in MW => 0.1235 MW
123,456.789012 W in kW => 123.4568 kW
123,456.789012 W in W => 123,456.789 W
123,456.789012 W in cW => 12,345,678.9012 cW
123,456.789012 W in mW => 123,456,789.012 mW
123,456.789012 W in uW => 123,456,789,012 uW
123,456.789012 W in μW => 123,456,789,012 μW
123,456.789012 W in µW => 123,456,789,012 µW
123,456.789012 W in nW => 123,456,789,012,000 nW
123,456.789012 W in pW => 1.2346e17 pW
123,456.789012 W in fW => 1.2346e20 fW
## Google Search

You can query Google from within Calca by writing a variable name and setting it
equal to `?`. Try uncommenting some of the following lines of code:

mass of earth = #?
goog = #?
10 km in miles = #?

This performs a Google search on your behalf and substitutes the `?` with the
result.

## Matrices and Vectors

Scalar Multiplication and Division:

[1, 2, 3] * 10 => [10, 20, 30]


[1, 2, 3] / 10 => [0.1, 0.2, 0.3]

Matrix Multiplication:

[1, 2, 3] * [1; 2; 3] => [14]


[1; 2; 3] * [1, 2, 3] => [1, 2, 3; 2, 4, 6; 3, 6, 9]

All other operators function element-wise:

[1, 6; 3, 8] + [5, 2; 7, 4] => [6, 8; 10, 12]


[1, 6; 3, 8] < [5, 2; 7, 4] => [true, false; true, false]

You can use any expression inside the matrix.

[foo, bar] * 2 => [2 foo, 2 bar]

Matrices are indexed using the `[row, column]` operator or the `[index]` operator.
All indexing begins at 0.

mat = [0, 1; 2, 3]

mat[0,0] => 0
mat[1,1] => 3
mat[1,0] => 2

The index operator uses column-major ordering.

mat[0] => 0
mat[1] => 2
mat[2] => 1

The index can be calculated from the row and column number.

index(row, col) = row + col*2

index(1,0) => 1
mat[index(1,0)] => 2

The transpose of a matrix can be calculated by raising it to the power of `T`:


[1, 2; 3, 4]^T => [1, 3; 2, 4]

### Square Matrices

Square matrices also support having the inverse and determinant found.

mat = [1, 2; 3, 4]

mat^-1 => [-2, 1; 1.5, -0.5]


|mat| => -2

This makes solving linear equations easy:

mat * x = [60; 70]

x => [-50; 55]

The symbolic inverse can also be taken but is limited to matrices whose dimension
is less than 9.

scale = [sx, 0, 0; 0, sy, 0; 0, 0, 1]


translate = [1, 0, tx; 0, 1, ty; 0, 0, 1]

scale * translate * v = [vx; vy; 1]

v => [vx/sx - tx; vy/sy - ty; 1]

### Vectors

A vector is a single column or single row matrix. There are additional operations
to perform on vectors:

Measure the length using `|v|`:

vec = [1, 2, 3]

|vec| => 3.7417

You can use the length to normalize a vector:

vec / |vec| => [0.2673, 0.5345, 0.8018]

The length of a vector defaults to the 2-norm:

|[foo, bar]| => sqrt(|foo|^2 + |bar|^2)

You can also calculate the p-norm of the vector:

||vec|| => 3.7417

||vec||1 => 6
||vec||2 => 3.7417
||vec||3 => 3.3019

The length operator is handy for measuring distances too:


point a = [2 mi, 1 mi]
point b = [-3mi, 10 mi]

|point a - point b| => 10.2956*|mi|

The dot and cross products are also available:

cross([1, 0, 0], [0, 1, 0]) => [0, 0, 1]


dot([1, 0, 0], [0, 1, 0]) => 0

cross([0, 1, 0], vec) => [3, 0, -1]


dot([0, 1, 0], vec) => 2

## Ranges

Ranges represent lists of integers and are specified using minimum and maximum
values, inclusive.

0..3 => 0..3

### Interval Arithmetic

Ranges can be used to represent imprecise measurements by specifying the minimum


and maximum expected values.

For example, we might measure the side of a square room as 10 meters with a
measurement error of 10 cm. This can be represented as the range:

side = (10 - 5/100)..(10 + 5/100) => 9.95..10.05

The area of that room is:

area = side^2 => 99.0025..101.0025

We can see that the area is imprecise: it is anywhere from `99` to `101` meters
squared.

### Indexing Matrices

Ranges can be used to index sub matrices:

big matrix = [1, 2, 3; 4, 5, 6; 7, 8; 9]


big matrix[0..1, 1..2] => [2, 3; 5, 6]

### Generating Data

Using `map`, ranges can be used to generate data.

times ten(x) = 10x


map(times ten, 0..3) => [0, 10, 20, 30]

## Map & Reduce


The map function applies a function to every element of a matrix:

map(cos, [0, pi/4, pi/3])


=> [1, 0.7071, 0.5]

map (10*x, [0, 1, 500])


=> [0, 10, 5,000]

Map can also be used to combine multiple lists by passing them to a function of two
parameters.

map (10*y + x, x = [1, 2], y = [3, 4])


=> [31, 42]

Reduce combines the elements of a matrix using a function that combines an


accumulator and an individual element of the matrix. The result of the reduction of
one element is passed on as the accumulator for the next function:

reduce (g, [1, 2, 3]) => g(g(1, 2), 3)

reduce (acc + x, [1, 2, 3]) => 6


reduce (acc + x + b, [1, 2, 3]) => 2 b + 6

Reduce takes an optional third argument that specifies the initial value of the
accumulator.

reduce (f, [1, 2, 3], 1000) => f(f(f(1,000, 1), 2), 3)

### Replicating Sum and Prod using Reduce

To make using `reduce` simple, here is how you can express the sum and prod
functions in terms of it:

data = [10, 20, 30]

sum (x, data) => 60


reduce (x + y, data) => 60

prod (x, data) => 6,000


reduce (x * y, data) => 6,000

## Logic Programming

And:

true && true => true


true && false => false
1 && 1 => 1
1 && 0 => 0

Or:

true || false => true


false || false => false
1 || 0 => 1
0 || 0 => 0

Not:

!true => false


!(a && (b > 0)) => !a || (b <= 0)

¬true => false


¬(a && (b > 0)) => !a || (b <= 0)

### Comparison

The standard comparison operators are available.

Less than:

2 < 3 => true


3 <= 3 => true
3 ≤ 3 => true

Greater than:

3 > 2 => true


3 >= 3 => true
3 ≥ 3 => true

Equality:

3 == 3 => true
2 == 3 => false

Inequality:

3 != 3 => false
2 != 3 => true
2 ≠ 3 => true

### Conditional Logic

The `if condition then value else other value` expression is used to give alternate
values depending on some logic:

my abs(v) = if v < 0 then -v else v

my abs(-100) => 100


my abs(100) => 100
my abs(x + y) => if x + y < 0 then -x - y else x + y

## Computer Numbers

You can specify numbers in hexadecimal and binary notation:

0xCC => 0xCC


0xFFFF_FFFF => 0xFFFFFFFF
0b101 => 0b101
0b1111_1111 => 0b11111111

These numbers are limited to 32-bits.

Here's a little function to get integral hexadecimal color values in the range [0,
255] from numbers in the range [0, 1].

color = round(f*0xFF)

color(1/3) => 0x55

### Bit operations

You can use the `&` operator to do bitwise AND operations, and the `|` operator for
bitwise OR operations.

0b0101 | 0b1010 => 0b1111


0b0101 & 0b1010 => 0

Don't confuse & and | with the logical && and || operators:

0b0100 | 1 => 0b101


0b0100 || 1 => 0b100
0b0100 & 1 => 0
0b0100 && 1 => 1

## Complex Numbers

You can use the variable i to specify imaginary numbers:

1 + 2i => 2i + 1
i*i => -1
(1+2i)*i => i - 2
i^43 => -i

The square root function works well with imaginary numbers:

sqrt(-10000) => 100i


sqrt(i) => 0.7071i + 0.7071

The `conj` function provides the complex conjugate:

re(z) = 1/2*(z + conj(z))


im(z) = 1/2i*(z - conj(z))

re(3 + 5i) => 3


im(3 + 5i) => 5

## Derivatives

You can take the derivative a function with respect to a variable using the `der`
function:
projectile(t) = 1/2*a*t^2 + v0*t + x0

der(projectile, t) => a*t + v0


der(projectile, a) => 0.5 t^2

You can even specify a derivative to the nth degree using a third argument to
`der`.

der(projectile, t, 2) => a

Sometimes derivatives can only be calculated "piece-wise". In that case, `if`


expressions are used.

func = 3 + |a - 2|
der(func) => if a < 2 then -1 else 1

You can also use the `∂` symbol as a synonym for `der`:

∂(x^2, x) => 2 x

## Standard Library

### abs

The absolute value of an expression can be specified with the `abs` function or by
surrounding the expression with bars `|`:

|-4| => 4
|-x| => |x|

abs(-4) => 4
abs(-x) => |x|

When `abs` is applied to square matrices, it produces the determinant:

|[a, b; c, d]| => a*d - b*c


abs([a, b; c, d]) => a*d - b*c

### acos, asin, atan, atan2

The arc functions produce the inverses of the trigonometric functions:

acos(0.5) in ° => 60°


asin(0.5) in ° => 30°
atan(-1) in ° => -45°

atan2(3, 3) => 0.7854 rad


atan2(3, -3) in ° => 135°

### average, mean

Finds the average value in a sequence of values.

average(85, 92, 95) => average(85, 92, 95)


mean([85, 92, 95]) => 90.6667

### choose, nCr

Calculates the binomial coefficient of two integers:

choose(8, 3) => 56
nCr(8, 3) => 56

choose(8, -1) => 0


choose(8, 0) => 1
choose(8, 1) => 8
choose(8, 8) => 1
choose(8, 9) => 0

nCr(52, 5) => 2,598,960

### conj

Calculates the complex conjugate of a complex number.

conj(3i) => -3i


conj(2 + 3i) => -3i + 2
conj(a) => conj(a)

### cos, sin, tan

These are the standard circular trigonometry functions. Their arguments are in
radians.

cos(0) => 1
cos(pi/3) => 0.5
cos(pi/4) => 0.7071
cos(60°) => 0.5

sin(0) => 0
sin(pi/3) => 0.866
sin(pi/4) => 0.7071

If you specify the units of the angle, Calca will convert it to radians for you.

cos(60°) => 0.5


cos(60 deg) => 0.5
sin(60°) => 0.866

### cosh, sinh, tanh

These are the hyperbolic trigonometry functions. Their arguments are in radians.

cosh(0) => 1
cosh(pi/3) => 1.6003
cosh(pi/4) => 1.3246

sinh(0) => 0
sinh(pi/3) => 1.2494
sinh(pi/4) => 0.8687

### ceil

Returns the ceiling of a number.

ceil(2.1) => 3
ceil(-2.1) => -2

### cross

Returns the 3D cross product of two vectors.

cross([1, 0, 0], [0, 1, 0]) => [0, 0, 1]

### der

Calculates the derivative of a function. See [Derivatives][] for details.

### dot

Calculates the inner product of two matrices:

dot([a, b], [c, d]) => a*c + b*d

dot([1, 0], [0.7, 0.3]) => 0.7

### filter

Filter selects elements from a matrix given a predicate function.

filter(x > 0, [-2, -1, 0, 1, 2]) => [1, 2]


filter(x >= 0, [-2, -1, 0, 1, 2]) => [0, 1, 2]
filter(x < 0, [-2, -1, 0, 1, 2]) => [-2, -1]

### floor

Returns the floor of a number.

floor(2.1) => 2
floor(-2.1) => -3

### inv

Finds the multiplicative inverse of a number or matrix. It is equivalent to raising


to a power of `-1` or dividing `1` by the number.

inv(2) => 0.5


inv(a) => 1/a

inv([1, 2; 3, 4]) => [-2, 1; 1.5, -0.5]


### jacobian

The Jacobian matrix is the matrix of all first-order partial derivatives of a


vector-valued function given by m real-valued component functions.

The Jacobian of 1 function with 2 variables is a 1x2 matrix:

jacobian(2x/y) => [2/y, -2 x/y^2]

The Jacobian of 2 functions of 2 variables is a 2x2 matrix:

jacobian(2x/y, 3x) => [2/y, -2 x/y^2; 3, 0]

The functions can also be specified inside a matrix:

jacobian([2x+y, y/x]) => [2, 1; -y/x^2, 1/x]

You can specify which variables with respect to which the Jacobian should be taken
by passing them as single variable arguments:

jacobian([2x+y, y/x], x, z) => [2, 0; -y/x^2, 0]

### len

`Len` retrieves the number of elements in complex values:

len([1,2]) => 2
len([1,2;3,4,5]) => [2, 3]

len({x:100,y:343}) => 2

len("foo") => 3

### log, log2, log10, ln

Logarithms are specified using the `log` function. It takes two args: the value and
the base of the logarithm.

log(100, 10) => 2


log(x, 10) => log10(x)

log(100, e) => 4.6052


log(x, e) => ln(x)

There are shortcut versions for some common bases:

log2(1000) => 9.9658


log10(1000) => 3
ln(1000) => 6.9078

Logarithms expand multiplication into individual logarithms:

log(x*y, b) => log(x, b) + log(y, b)


log(x/y, b) => log(x, b) - log(y, b)
### map

The map function applies a function to every element of a matrix:

map(cos, [0, pi/4, pi/3])


=> [1, 0.7071, 0.5]

map (10*x, [0, 1, 500])


=> [0, 10, 5,000]

Generate data by passing `map` an integer range.

map(2x, 0..3) => [0, 2, 4, 6]

map(2x, -2..2) => [-4, -2, 0, 2, 4]

map(x*100+y, x=0..4, y=-2..2)


=> [-2, 99, 200, 301, 402]

See [Map & Reduce][] for details.

### max

Finds the argument with the maximum value and returns that value.

max(-11, 222, -1, 11) => 222

You can also pass a matrix whose elements will be scanned for a max value.

max([-1, 0, 2]) => 2

### min

Finds the argument with the minimum value and returns that value.

min(222, -1, -11) => -11

You can also pass a matrix whose elements will be scanned for a min value.

min([-1, 0, 2]) => -1

### prod

The first argument is the function to multiply.

The second argument names the variable to multiply and gives the range.

prod(x, 1..3) => 6


prod(x + a, 1..3) => (a + 1)*(a + 2)*(a + 3)
prod(x + a, a=1..3) => (x + 1)*(x + 2)*(x + 3)

Instead of ranges, you can specify values from a matrix:

prod(x, [1, 2, 3]) => 6


prod(x^2, [1, 2, 3]) => 36
### reduce

Reduce combines the elements of a matrix using a function that combines an


accumulator and an individual element of the matrix. The result of the reduction of
one element is passed on as the accumulator for the next function:

reduce (g, [1, 2, 3]) => g(g(1, 2), 3)

reduce (acc + x, [1, 2, 3]) => 6


reduce (acc + x + b, [1, 2, 3]) => 2 b + 6

### round

Rounds a number to the nearest integer. It uses the standard computer odd/even
rules for numbers half way between integers.

round(2.1) => 2
round(-2.1) => -2

round(1.5) => 2

round(2.5) => 2
round(2.50001) => 3

### sign

Returns either `-1`, `0`, or `1` depending on whether the argument is negative,
zero, or positive.

sign(-100) => -1
sign(0) => 0
sign(100) => 1

### sqrt, √

This is a short cut for writing the square root of a value:

sqrt(9) => 3
sqrt(a) => sqrt(a)
a^0.5 => sqrt(a)

You can also use the `√` symbol:

√(9) => 3

### sum, ∑

Summation is represented with the `sum` function.

The first argument is the function to sum.

The second argument names the variable to sum and gives the range.
sum(x*x, x=1..5) => 55

sq(v) = v^2

sum(sq, x=1..5) => 5 v^2


sum(sq, v=1..5) => 55
sum(sq(x), x=1..5) => 55

If only one argument is passed and it is a matrix, then its elements are summed:

sum([1, 2, 3]) => 6

You can also use the `∑` symbol to perform sums:

∑([1, 2, 3]) => 6

### taylor

Taylor series approximate functions at a point using a polynomial. It's great for
simplifying otherwise complex or hard-to-compute mathematics.

f(x) = sin(x) + cos(x)

taylor(f, x = 0, 1) => x + 1
taylor(f, x = 0, 2) => x - 0.5 x^2 + 1
taylor(f, x = 0, 3) => x - 0.5 x^2 - 0.1667 x^3 + 1

### tod

Displays a time value in hours, minutes, and seconds. This is known as the "time of
day".

The only argument is a value with time units, or number of seconds:

tod(7980) => 2 hr + 13 mins

tod(7980s) => 2 hr + 13 mins

tod(2 hours + 73.5 mins) => 3 hr + 13 mins + 30 s

If the time is negative, it will be interpreted as time before midnight.

tod(-7980) => 21 hr + 47 mins


tod(-2 hours) => 22 hr

### truncate

Truncates a number by removing its non-integer part.

truncate(2.1) => 2
truncate(-2.1) => -2

## Glossary
**Definition** is the assignment of an expression to a name. Definitions can also
include an optional parameter list if they are meant to represent functions.

**Equation** is a set of two expressions that are set equal to each other using the
`=` operator.

**Expression** is an algebraic value comprised of numbers, variables, and operators


manipulating those numbers and variables.

You might also like