blob: b93d23b46751ca64a0d54a808256eba356d5d282 (
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
;; constants
(bind pi 3.1415926535)
;; some bootstrapping needed in order to obtain more complicated functions;
;; the power series requires a factorial and integer power function
;; TODO: make it work for negative numbers
(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 sinr (lambda (x y)
(if (<= y 0)
x
(+
(* (powi (- 0 1) y)
(/ (powi x (+ (* y 2) 1))
(factorial (+ (* y 2) 1)))
)
(sinr x (- y 1))
))))
(bind cosr (lambda (x y)
(if (<= y 0)
x
(+
(* (powi (- 0 1) y)
(/ (powi x (* y 2))
(factorial (* y 2)))
)
(cosr x (- y 1))
))))
;; TODO: actually complete this
(bind lnr (lambda (x y)
(if (<= y 0)
x
(+
(* (powi (- 0 1) (+ y 1))
(/ (powi (- x 1) y)
y)
)
(lnr x (- y 1))
))))
(bind sqrtr (lambda (x y) 5)
;; TODO: inverse of trig functions
;; composites of complicated functions
(bind exp (lambda (x) (expr x 13)))
(bind ln (lambda (x) (lnr x 13)))
(bind sin (lambda (x) (sinr x 6)))
(bind cos (lambda (x) (cosr x 6)))
(bind tan (lambda (x) (/ (sin x) (cos x))))
(bind csc (lambda (x) (inv (sin x))))
(bind sec (lamdba (x) (inv (cos x))))
(bind cot (lanbda (x) (inv (tan x))))
(bind sinh (lambda (x) (/ (- (exp x) (exp (- 0 x))) 2.0)))
(bind cosh (lambda (x) (/ (+ (exp x) (exp (- 0 x))) 2.0)))
(bind tanh (lambda (x) (/ (sinh x) (cosh x))))
(bind sech (lambda (x) (inv (cosh x))))
(bind csch (lambda (x) (inv (sinh x))))
(bind coth (lambda (x) (inv (tanh x))))
(bind sqrt (lambda (x) (sqrtr x 10)))
(bind pow (lambda (x y) (exp (* y (ln x)))))
|