2.2. Eq’s library

max(a, b)

Return the biggest value between a and b

$ eq eval "max( 2, 10.0 )"
10.0
min(a, b)

Return the smallest value between the two elements

$ eq eval "min( 2, 10.0 )"
2
eq(a, b)

Perform a structural (deep) equality comparison

$ eq eval "eq( x + 3, x + 4 )"
false
$ eq eval "eq( x + 3, x + 3 )"
true
if(boolean, then, else)

Return either then or else in function of the first argument. If it’s true, then it return then, if it’s false it return else. If it’s neither true or false, then it return undefined

$ eq eval "if( 3 > 4, lower, greater )"
greater
$ eq eval "if( 3 < 4, lower, greater )"
lower
$ eq eval "if( 3, lower, greater)"
undefined
derivaten(function, var, order)

Derivate order times the function with the given var

$ eq eval "derivaten( x ^ 4 + x ^ 3 / 2 + 15 * x, x, 1 )"
                2  
        3    3.x   
15 + 4.x  + ------ 
              2
$ eq eval "derivaten( x ^ 4 + x ^ 3 / 2 + 15 * x, x, 2 )"
    2    6.x  
12.x  + ----- 
          2
$ eq eval "derivaten( x ^ 4 + x ^ 3 / 2 + 15 * x, x, 3 )"
 3         
--- + 24.x 
 1
modulo(n, p)

give the value of n modulo p

$ eq eval "modulo( 14, 3 )"
2
taylor(formula, derivation var, atPos, order)

Return the taylor expansion of an expression. For exemple to get the taylor expansion of the formula sin(x) + x for the variable x and at 0, you should try :

$ eq exacteval "taylor( sin(x) + x, x, 0, 10 )"
        1    5      1      9     1   3      1     7 
2.x + -----.x  + --------.x  + ----.x  + -------.x  
       120        362880         6         5040
cons(a, b)

Is just the functional version of the :: operator

2.2.1. List functions

concat(alist, anotherList)

Return the concatenation of two lists.

$ eq eval "concat([a, b, c], [1, 2, 3] )"
[ a, b, c, 1, 2, 3 ]
reverse(list)

Return the list reversed

$ eq eval "reverse([a, b, c])"
[ c, b, a ]
length(list)

Return the length (number of elements) of a list

$ eq eval "length([a, b, c, 10])"
4

2.2.2. List-generation functions

listFromTo(beginning, end)

Generate a list containing all the integer from beginning to end (included).

$ eq eval "listFromTo( 12, 30 )"
[ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 ]
listFromToBy(beginning, increment, maximum)

Generate a list of numbers containing all the integers from beginning to end, each value separated by increment.

$ eq eval "listFromToBy( 12, 2, 30 )"
[ 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 ]

2.2.3. Higher-order functions

filter(function, list)

Remove all object which the function doesn’t evaluate to true.

$ eq eval "enough(x) :> x > 50; filter( enough, [100, 2, 4, 51, 50, 60 ] )"
[ 100, 51, 60 ]
map(function, list)

Apply a function to all elements of the list

$ eq eval "mul2(x) :> x * 2; map( mul2, [1, 2, 3, 12] )"
[ 2, 4, 6, 24 ]
foldl(function, accumulator, list)

Function used to perform a left fold on a list. The function should take two parameters : one for an accumulator, and one for an element of the list.

The accumulator is carried over all the elements of the list, and the iterations start at the beginning of the list. One example of the use of fold is to write the equivalent of the reverse function using a left fold :

$ eq eval "foldl( cons, [], [1, 2, 3, 4] )"
[ 4, 3, 2, 1 ]
foldr(function, accumulator, list)

Same as the left fold, but here is the right fold, iterations start from the end of the list to the beginning.

Table Of Contents

Previous topic

2.1. Builtin functions

Next topic

2.3. sum

This Page