-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathseparate-sin-cos.sls
53 lines (35 loc) · 1.21 KB
/
separate-sin-cos.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
#!r6rs
(library (mpl separate-sin-cos)
(export separate-sin-cos)
(import (mpl rnrs-sans)
(mpl misc)
(mpl arithmetic))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (define (sin? u)
;; (and (pair? u)
;; (eq? (car u) 'sin)))
;; (define (cos? u)
;; (and (pair? u)
;; (eq? (car u) 'cos)))
(define (sin-or-cos? u)
(or (sin? u)
(cos? u)
(and (power? u)
(or (sin? (base u))
(cos? (base u))))))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (separate-sin-cos u)
(cond ( (product? u)
(let loop ((r 1)
(s 1)
(operands (cdr u)))
(if (null? operands)
(list r s)
(let ((operand (car operands)))
(if (sin-or-cos? operand)
(loop r (* s operand) (cdr operands))
(loop (* r operand) s (cdr operands)))))) )
( (sin-or-cos? u) (list 1 u) )
( else (list u 1) )))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
)