3.1. Numbers |

See: Special Numerical Values (IEEE754).

Numbers are the simplest kind of atoms. They are stored as double
precision floating point numbers.

Numerical computations in Lush are usually performed in double precision. Single precision however is used by some number crunching functions, like the matrix calculus operations.

You can type in decimal number using the traditional exponential
notation or using hexadimal numbers preceded by characters **
"0x" **. Here are a few examples of legal numbers:

23 3.14 12e6 ;; equivalent to 12000000 1.2E6 ;; equivalent to 1200000 0x1A ;; equivalent to 26

3.1.0. Elementary Numerical Functions |

The following elementary functions operate on numbers:

3.1.0.0. (+ n1 ... nm) |
[DX] |

Computes the sum of numbers

Example:

? (+ 1 2 3 4) = 10

3.1.0.1. (1+ n) |
[DX] |

Adds 1 to

Example:

? (1+ 4) = 5

3.1.0.2. (- [n1] n2) |
[DX] |

Subtracts

Example:

? (- 2 5) = -3

3.1.0.3. (1- n) |
[DX] |

Subtracts 1 from

Example:

? (1- (+ 4 5)) = 8

3.1.0.4. (* n1 ... nm) |
[DX] |

Computes the product of

Here is a memory intensive way of computing a factorial:

? (apply '* (range 1 5)) = 120

3.1.0.5. (2* n) |
[DX] |

Multiplies

Example:

? (2* (+ 4 5)) = 18

3.1.0.6. (/ [n1] n2) |
[DX] |

Divides

Example:

? (/ 3) = 0.3333

3.1.0.7. (2/ n) |
[DX] |

Divides

Example:

? (2/ 5) = 2.5

3.1.0.8. (** n m) |
[DX] |

Returns

Example:

? (** 2 5) = 32

3.1.0.9. (max l1 ... ln) |
[DX] |

Return the maximum element within

Example:

? (max 2 3 (* 3 3) (+ 4 3)) = 9

3.1.0.10. (min l1 ... ln) |
[DX] |

Return the minimum element within

Example:

? (min 2 3 (* 3 3) (+ 4 3)) = 2

3.1.1. Integer Arithmetic Functions |

Besides the ordinary number operation functions, a few functions deal with integer numbers only. For that purpose we consider only the first 32 bits of the integer part of the number.

3.1.1.0. (div n1 n2) |
[DX] |

Returns the quotient of the Euclidian division of

Example:

? (div 5 2) = 2

3.1.1.1. (mod n1 n2) |
[DX] |

Returns the remainder of the Euclidian division of

Example:

? (mod 5 2) = 1

3.1.1.2. (bitand n1 n2) |
[DX] |

Returns the bitwise AND of integer numbers

3.1.1.3. (bitor n1 n2) |
[DX] |

Returns the bitwise OR of integer numbers

3.1.1.4. (bitxor n1 n2) |
[DX] |

Returns the bitwise exclusive or (XOR) of integer numbers

3.1.1.5. (bitshl n1 n2) |
[DX] |

Shifts the bits of integer

3.1.1.6. (bitshr n1 n2) |
[DX] |

Shifts the bits of integer

3.1.2. Mathematical Numerical Functions |

Most mathematical functions are implemented as DZ functions. DZs are a remnant of a now obsolete compiler for numerical expressions. For more details about DZ functions the corresponding section.

3.1.2.0. (sgn n) |
[DZ] |

Returns +1 if

? (sgn -2) = -1

? (sgn 1.2) = 1

3.1.2.1. (abs n) |
[DZ] |

Returns the absolute value of

? (abs 123.3) = 123.3

? (abs -23.3) = 23.3

3.1.2.2. (int n) |
[DZ] |

Returns the integral part of

? (int -4.5) = -5

? (int 4.5) = 4

3.1.2.3. (sqrt n) |
[DZ] |

Returns the square root of

? (sqrt 15) = 3.873

3.1.2.4. (0-x-1 n) |
[DZ] |

This function implements a piecewise saturated linear function. It returns 0 if

? (0-x-1 -2) = -1

? (0-x-1 0.7) = 0.7

? (0-x-1 1.3) = 1

3.1.2.5. (0-1-0 n) |
[DZ] |

This function implements the indicator function of the -1 to +1 range. It returns 1 if

? (0-1-0 -2) = 0

? (0-1-0 0.7) = 1

3.1.2.6. (sin n) |
[DZ] |

Returns the sine of

? (sin (/ 3.1415 3)) = 0.866

3.1.2.7. (cos n) |
[DZ] |

Returns the cosine of

? (cos (/ 3.1415 3)) = 0.5

3.1.2.8. (tan n) |
[DZ] |

Returns the tangent of

? (tan (/ 3.1415 3)) = 1.7319

3.1.2.9. (atan n) |
[DZ] |

Returns the arc tangent of

? (* 4 (atan 1)) = 3.1416

3.1.2.10. (exp n) |
[DZ] |

Returns the exponential of

? (exp 1) = 2.7183

3.1.2.11. (exp-1 n) |
[DZ] |

Returns the exponential of

? (exp-1 0.5) = 0.6487

3.1.2.12. (log n) |
[DZ] |

Returns the natural logarithm of

? (log 2) = 0.6931

3.1.2.13. (log1+ n) |
[DZ] |

Returns the natural logarithm of

? (log1+ 1) = 0.6931

3.1.2.14. (sinh n) |
[DZ] |

Returns the hyperbolic sine of

? (sinh 1) = 1.1752

3.1.2.15. (cosh n) |
[DZ] |

Returns the hyperbolic cosine of

? (cosh 1) = 1.5431

3.1.2.16. (tanh n) |
[DZ] |

See: (qtanh

Returns the hyperbolic tangent of

? (tanh 1) = 0.7616

3.1.2.17. (qtanh n) |
[DZ] |

See: (tanh

Returns a rational approximation of the hyperbolic tangent of

? (qtanh 1) = 0.7616

3.1.2.18. (qdtanh n) |
[DZ] |

Returns a rational approximation of the derivative of the hyperbolic tangent of

? (qdtanh 1) = 0.42

3.1.2.19. (qstdsigmoid n) |
[DZ] |

See: (qtanh

Returns the value of standard sigmoid at point

3.1.2.20. (qdstdsigmoid n) |
[DZ] |

See: (qdtanh

Returns the value of the derivative of standard sigmoid at point

3.1.2.21. (qexpmx n) |
[DZ] |

Returns a rational approximation of the exponential of minus the absolute value of

? (qexpmx 1) = 0.3679

3.1.2.22. (qdexpmx n) |
[DZ] |

Returns a rational approximation of the derivative of the exponential of minus the absolute value of

? (qdexpmx 1) = 0.3679

3.1.2.23. (qexpmx2 n) |
[DZ] |

Returns a rational approximation of the exponential of minus the square of

? (qexpmx 1) = 0.3679

3.1.2.24. (qdexpmx2 n) |
[DZ] |

Returns a rational approximation of the exponential of minus the square of

? (qdexpmx 1) = 0.3679

3.1.2.25. (solve min max f) |
[DX] |

Simple dichotomical root finder.

Example:

? (solve 1 2 (lambda (x) (- 2 (* x x)) )) = 1.4142

3.1.3. Random Numbers |

Statistical functions are provided for computing random numbers, computing various statistics on list of numbers or performing simple linear regressions.

3.1.3.0. (seed n) |
[DX] |

Sets the random number generator seed. The random generator is replicable. The same seed will produce the same sequence of random numbers. Argument

3.1.3.1. (rand [[a] b]) |
[DX] |

Returns a uniform random number:

- If no arguments are provided,
function
**rand**returns a random number between 0 and 1.

- If argument
**b**only is given, function**rand**returns a random number between**-b**and**b**.

- If both arguments
**a**and**b**, function**rand**returns a random number between**a**and**b**.

Example:

? (rand) = 0.8437

3.1.3.2. (gauss [[m] s]) |
[DX] |

Returns a gaussian number with mean

Example

? (gauss 2) = 1.7561

3.1.4. Hashing |

3.1.4.0. (hashcode expr) |
[DX] |

Returns a string containing a hash code for the lisp expression