A package for a smart math computing in the Ol (Otus Lisp).
The main purpose of this library is to provide a comfortable way to perform complex math evaluations in a programming environment. Yet another math library? Yes and Not.
The Otus Lisp (ol) and (otus algebra) library may provide you very human friendly runtime environment with:
- exact calculations without losing the readability of the program text
- the same calculation results regardless of the platform used (*)
- inexact calculations on demand
- easy switching between fast inexact and ordinary exact calculation modes
You have a choice to:
make; make installinside the project folder,kiss install libol-algebrausing ol-packages repository,- If you don't need the fast inexact math support (the optimized C code for floating point machine types) or you don't have the C compiler available (huh?), just
copy the "otus" folderto the your project path.
A lot of examples available on the Reference page and in the "tests" folder.
$ ol
Welcome to Otus Lisp 2.5
type ',help' to help, ',quit' to end session.
> (import (otus algebra))
;; Library (otus algebra) added
;; Imported (otus algebra)
> (dot-product [1 2 3] [8 -3 5])
17Use infix notation inside Lisp (\\ is a short for macro infix-notation) freely:
> (\\ [1 3 -5] ⨯ [4 -2 -1] )
[-13 -19 -14]
> (\\ (2 + 3) * 4 - 1 )
19Some unicode math symbols (don't forget spaces between regular and unicode math letters) are available:
> (import (otus algebra unicode))
> (define-values (a b c) (values 5 3 -26))
;; All defined
> (define D (\\
b ² − 4 * a * c
))
> D
529
> (define X₁ (\\
(- b + √(D)) / (2 * a)
))
> (print "X₁ = " X₁)
X₁ = 2
> (define X₂ (\\
(- b - √(D)) / (2 * a)
))
> (print "X₂ = " X₂)
X₂ = -13/5
> (print (\\
a * (X₂)² + b * X₂ + c
))
0Don't forget for whitespaces around numbers and math operators.
-
All algebra arrays in Ol are indexed starting from 1. From 1, as mathematicians do! Not from 0, like programmers.
Negative index means "counting from the end of". -
By default all algebra math are exact (it can be changed using environment variables). That means no loss of precision during calculations.
- Some functions (like sin) can't be exact,
- Some functions (like floor) can be exact only,
- Most functions (like sqrt) can be exact and inexact depends on argument(s) exactness.
These and other package features described in detail on the main Reference page.
Good luck and happy calculations!
> (\\ ((((((((2)²)²)²)²)²)²)²)² )
115792089237316195423570985008687907853269984665640564039457584007913129639936In case of inexact (imprecise) calculations, the results of your work may (and will) vary across the same platforms as well, because of fundamental nature of imprecise calculations.