summaryrefslogtreecommitdiff
path: root/stdlib/math.nxs
blob: 77ffc7f50f4e50c44d1cda45ea6c412ee2da6260 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
;; some bootstrapping needed in order to obtain more complicated functions;
;; the power series requires a factorial and integer power function
(bind powi (lambda (x y)
	(if (= y 1)
	x
	(* x (powi x (- y 1)))
	)
))

(bind inv (lambda (x) (/ 1.0 x)))

(bind factorial (lambda (n)
        (if (= n 0) 1 (* n (factorial (- n 1))))))

;; complicated functions
(bind expr (lambda (x y)
	(if (<= y 0)
	1
	(+ (/ (powi x y) (factorial y)) (expr x (- y 1)))
	)
))

(bind exp (lambda (x)
	(expr x 13)
))

(bind sin (lambda (x) x))

(bind cos (lambda (x) x))

(bind tan (lambda (x) (/ (sin x) (cos x))))

(print (exp 1.0))
;(print (ln (exp 1)))