Skip to content

Commit 21c4a3f

Browse files
committed
fmt
1 parent 23eaa3f commit 21c4a3f

File tree

1 file changed

+36
-39
lines changed

1 file changed

+36
-39
lines changed

src/core/taylor.rkt

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,19 @@
153153
(define node (deref brf))
154154
(match node
155155
[(? (curry equal? var)) (taylor-exact (adder 0) (adder 1))]
156-
[(? number?) (taylor-exact brf)]
157-
[(? symbol?) (taylor-exact brf)]
158-
[`(,const) (taylor-exact brf)]
159-
[`(+ ,arg1 ,arg2) (taylor-add (recurse arg1) (recurse arg2))]
160-
[`(neg ,arg) (taylor-negate (recurse arg))]
161-
[`(* ,left ,right) (taylor-mult (recurse left) (recurse right))]
162-
[`(/ ,num ,den)
163-
#:when (equal? (deref num) 1)
164-
(taylor-invert (recurse den))]
165-
[`(/ ,num ,den) (taylor-quotient (recurse num) (recurse den))]
166-
[`(sqrt ,arg) (taylor-sqrt var (recurse arg))]
167-
[`(cbrt ,arg) (taylor-cbrt var (recurse arg))]
168-
[`(fabs ,arg) (or (taylor-fabs var (recurse arg)) (taylor-exact brf))]
156+
[(? number?) (taylor-exact brf)]
157+
[(? symbol?) (taylor-exact brf)]
158+
[`(,const) (taylor-exact brf)]
159+
[`(+ ,arg1 ,arg2) (taylor-add (recurse arg1) (recurse arg2))]
160+
[`(neg ,arg) (taylor-negate (recurse arg))]
161+
[`(* ,left ,right) (taylor-mult (recurse left) (recurse right))]
162+
[`(/ ,num ,den)
163+
#:when (equal? (deref num) 1)
164+
(taylor-invert (recurse den))]
165+
[`(/ ,num ,den) (taylor-quotient (recurse num) (recurse den))]
166+
[`(sqrt ,arg) (taylor-sqrt var (recurse arg))]
167+
[`(cbrt ,arg) (taylor-cbrt var (recurse arg))]
168+
[`(fabs ,arg) (or (taylor-fabs var (recurse arg)) (taylor-exact brf))]
169169
[`(exp ,arg)
170170
(define arg* (normalize-series (recurse arg)))
171171
(if (positive? (series-offset arg*))
@@ -174,29 +174,29 @@
174174
[`(sin ,arg)
175175
(define arg* (normalize-series (recurse arg)))
176176
(cond
177-
[(positive? (series-offset arg*)) (taylor-exact brf)]
178-
[(= (series-offset arg*) 0)
179-
; Our taylor-sin function assumes that a0 is 0,
180-
; because that way it is especially simple. We correct for this here
181-
; We use the identity sin (x + y) = sin x cos y + cos x sin y
182-
(taylor-add (taylor-mult (taylor-exact (adder `(sin ,(series-ref arg* 0))))
183-
(taylor-cos (zero-series arg*)))
184-
(taylor-mult (taylor-exact (adder `(cos ,(series-ref arg* 0))))
185-
(taylor-sin (zero-series arg*))))]
186-
[else (taylor-sin (zero-series arg*))])]
177+
[(positive? (series-offset arg*)) (taylor-exact brf)]
178+
[(= (series-offset arg*) 0)
179+
; Our taylor-sin function assumes that a0 is 0,
180+
; because that way it is especially simple. We correct for this here
181+
; We use the identity sin (x + y) = sin x cos y + cos x sin y
182+
(taylor-add (taylor-mult (taylor-exact (adder `(sin ,(series-ref arg* 0))))
183+
(taylor-cos (zero-series arg*)))
184+
(taylor-mult (taylor-exact (adder `(cos ,(series-ref arg* 0))))
185+
(taylor-sin (zero-series arg*))))]
186+
[else (taylor-sin (zero-series arg*))])]
187187
[`(cos ,arg)
188188
(define arg* (normalize-series (recurse arg)))
189189
(cond
190-
[(positive? (series-offset arg*)) (taylor-exact brf)]
191-
[(= (series-offset arg*) 0)
192-
; Our taylor-cos function assumes that a0 is 0,
193-
; because that way it is especially simple. We correct for this here
194-
; We use the identity cos (x + y) = cos x cos y - sin x sin y
195-
(taylor-add (taylor-mult (taylor-exact (adder `(cos ,(series-ref arg* 0))))
196-
(taylor-cos (zero-series arg*)))
197-
(taylor-negate (taylor-mult (taylor-exact (adder `(sin ,(series-ref arg* 0))))
198-
(taylor-sin (zero-series arg*)))))]
199-
[else (taylor-cos (zero-series arg*))])]
190+
[(positive? (series-offset arg*)) (taylor-exact brf)]
191+
[(= (series-offset arg*) 0)
192+
; Our taylor-cos function assumes that a0 is 0,
193+
; because that way it is especially simple. We correct for this here
194+
; We use the identity cos (x + y) = cos x cos y - sin x sin y
195+
(taylor-add (taylor-mult (taylor-exact (adder `(cos ,(series-ref arg* 0))))
196+
(taylor-cos (zero-series arg*)))
197+
(taylor-negate (taylor-mult (taylor-exact (adder `(sin ,(series-ref arg* 0))))
198+
(taylor-sin (zero-series arg*)))))]
199+
[else (taylor-cos (zero-series arg*))])]
200200
[`(log ,arg) (taylor-log var (recurse arg))]
201201
[`(pow ,base ,power)
202202
#:when (exact-integer? (deref power))
@@ -398,13 +398,10 @@
398398
(define a0 (deref (series-ref normalized 0)))
399399
(cond
400400
[(or (not (number? a0)) (zero? a0)) #f]
401-
[(and (even? offset) (negative? a0))
402-
(taylor-negate normalized)]
403-
[(and (even? offset) (positive? a0))
404-
normalized]
401+
[(and (even? offset) (negative? a0)) (taylor-negate normalized)]
402+
[(and (even? offset) (positive? a0)) normalized]
405403
[(odd? offset)
406-
(define scale-factor
407-
(adder `(* (fabs ,var) ,(if (negative? a0) -1 1))))
404+
(define scale-factor (adder `(* (fabs ,var) ,(if (negative? a0) -1 1))))
408405
(define new-offset (add1 offset))
409406
(make-series new-offset
410407
(λ (f n)

0 commit comments

Comments
 (0)