-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrational-expand.sls
54 lines (33 loc) · 1.18 KB
/
rational-expand.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
#!r6rs
(library (mpl rational-expand)
(export rational-expand)
(import (mpl rnrs-sans)
(mpl arithmetic)
(mpl algebraic-expand)
(mpl numerator)
(mpl denominator)
(mpl rational-gre)
(mpl rationalize-expression))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (define (rational-expand u)
;; (let ((f (algebraic-expand (numerator u)))
;; (g (algebraic-expand (denominator u))))
;; (if (equal? g 0)
;; #f
;; (let ((h (/ f g)))
;; (if (rational-gre? h)
;; h
;; (rational-expand
;; (rationalize-expression h)))))))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (rational-expand u)
(let ((f (algebraic-expand (numerator u)))
(g (algebraic-expand (denominator u))))
(if (equal? g 0)
#f
(let ((h (rationalize-expression (/ f g))))
(if (equal? h u)
u
(rational-expand h))))))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
)