Fuzuli has several packages which are mostly wrappers of C++ libraries. One of them is the math package. It is math.nfl and stated in /usr/lib/fuzuli/nfl in Linux installations by default.

The math.nfl package simple wraps some basic mathematical functions such as square root, exponential, logarithms, floor, ceil and round as well as trigonometric functions such as sin, cos, tan, atan, acos, etc. These functions are directly inherited from the standard C++ library. A list of functions in the math.nfl package is shown below:

Function | Description | Example | Result |

PI | Returns a short presentation of PI | (let a (sin (/ PI 2))) | 1.0 |

sin | Returns sin of a given reference | (let a (sin 0)) | 0.0 |

cos | Returns cos of a given reference | (let a (cos 0)) | 1.0 |

tan | Returns tan of a given reference | (print (tan 1)) | 1.55741 |

abs | Returns absolute value | (print (abs -5)) | 5 |

sqrt | Returns square root | (print (sqrt 25)) | 5 |

exp | Returns E^x | (print (exp 1)) | 2.71828 |

log | Returns natural logarithm | (print (log (exp 1))) | 1.0 |

log10 | Returns logarithm in base 10 | (print (log10 10)) | 1.0 |

log2 | Returns logarithm in base 2 | (print (log2 2)) | 1.0 |

cosh | Returns hyperbolic cos | (cosh x) | |

sinh | Returns hyperbolic sin | (sinh x) | |

tanh | Returns hyperbolic tan | (tanh x) | |

asin | Returns inverse sine | (asin 1) | |

acos | Returns inverse cosine | (acos 0) | |

atan | Returns inverse tangent | (atan 1.55741) | 1 |

atan2 | Two arguments arctan function | (atan2 1 1) | 0.7853981634 |

pow | Returns a^x | (print (pow 5 2)) | 25 |

ceil | Returns ceil of a given reference | (print (ceil 2.3)) | 3.0 |

floor | Returns floor of a given reference | (print (floor 2.3)) | 2.0 |

round | Returns round of a given reference. (nearest integer) | (print (round 2.3)) | 2.0 |

isinf | Returns 1 if the given reference is either negative or positive infinitive else returns 0 | (print (isinf (/ 19 0))) | 1 |

The table shown above is hopefully enough to introduce our functions in the math package. Any Fuzuli program should include the math package using the (require) expression if any math function shown above is planned to use. Look at the code below:

(require "/usr/lib/fuzuli/nfl/math.nfl") (print (isinf (/ 19 0)))

Although math functions are collected in an external package, Fuzuli supports built-in arithmetic functions. The code shown below is calculating ordinary least squares regression coefficients. As you see, no math functions required and only the arithmetic functions are used.

(let x (list 1 2 3 4 5 6 7 8 9 10)) (let y (list 10 20 30 40 50 60 70 80 90 100)) (function sum (params a) (block (def s FLOAT) (def i INTEGER) (let s 0.0) (for (let i 0) (< i (length a)) (inc i) (let s (+ s (nth a i))) ) (return s) ) ) (function mean (params a) (block (def total FLOAT) (def result FLOAT) (let total (sum a)) (let result (/ total (length a))) (return result) ) ) (function covariance (params c d) (block (def meana FLOAT) (def meanb FLOAT) (def xy FLOAT) (def i INTEGER) (let meana (mean c)) (let meanb (mean d)) (let xy 0.0) (for (let i 0) (< i (length a)) (inc i) (block (let xy (+ xy (* (- (nth c i) meana) (- (nth d i) meanb )))) ) ) (return xy) ) ) (let beta1 (/ (covariance x y) (covariance x x))) (let beta0 (- (mean y) (* beta1 (mean x)))) (print "beta0 " beta0 "\n") (print "beta1 " beta1 "\n")

The result is 0.0 for beta0 and 10.0 for beta1.

See you in next entry. Have fun!