-
Notifications
You must be signed in to change notification settings - Fork 5
/
automatic-simplify.sls
57 lines (47 loc) · 1.81 KB
/
automatic-simplify.sls
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
#!r6rs
(library (mpl automatic-simplify)
(export automatic-simplify)
(import (mpl rnrs-sans)
(mpl misc)
(mpl sum-product-power)
(mpl sub)
(mpl div)
(mpl factorial)
(mpl exp)
(mpl log)
(mpl sin)
(mpl cos)
(mpl tan)
(mpl sqrt))
;; (define (automatic-simplify u)
;; (if (list? u)
;; (let ((v (map automatic-simplify u)))
;; (cond ((power? v) (simplify-power v))
;; ((product? v) (simplify-product v))
;; ((sum? v) (simplify-sum v))
;; ((quotient? v) (simplify-quotient v))
;; ((difference? v) (simplify-difference v))
;; ((factorial? v) (simplify-factorial v))
;; (else v)))
;; u))
(define (kind v)
(and (pair? v)
(car v)))
(define (automatic-simplify u)
(if (list? u)
(let ((v (map automatic-simplify u)))
(cond ((power? v) (simplify-power v))
((product? v) (simplify-product v))
((sum? v) (simplify-sum v))
((quotient? v) (simplify-quotient v))
((difference? v) (simplify-difference v))
((factorial? v) (simplify-factorial v))
( (eq? (kind v) 'exp) (apply exp (cdr v)) )
( (eq? (kind v) 'log) (apply log (cdr v)) )
( (eq? (kind v) 'sin) (apply sin (cdr v)) )
( (eq? (kind v) 'cos) (apply cos (cdr v)) )
( (eq? (kind v) 'tan) (apply tan (cdr v)) )
( (eq? (kind v) 'sqrt) (apply sqrt (cdr v)) )
(else v)))
u))
)