2 Use
2.1 Provided Continued Fractions
procedure
n : exact?
procedure
(continued-fraction? v) → boolean?
v : any/c
procedure
procedure
procedure
(exp-cf n) → continued-fraction?
n : exact?
procedure
(ln-cf n) → continued-fraction?
n : exact?
procedure
(sine-cf n) → continued-fraction?
n : exact?
procedure
(cosine-cf n) → continued-fraction?
n : exact?
procedure
n : exact?
procedure
n : exact?
procedure
n : exact?
procedure
n : exact?
procedure
(expt-cf base exponent) → continued-fraction?
base : exact? exponent : exact?
procedure
(champernowne-cf base) → continued-fraction?
base : (and/c exact-integer? (>/c 1))
2.2 Arithmetic Procedures
procedure
(cf+ v ...) → (or/c exact-integer? continued-fraction?)
v : (or/c exact-integer? continued-fraction?)
procedure
(cf- v ...) → (or/c exact-integer? continued-fraction?)
v : (or/c exact-integer? continued-fraction?)
procedure
(cf* v ...) → (or/c exact-integer? continued-fraction?)
v : (or/c exact-integer? continued-fraction?)
procedure
(cf/ v ...) → (or/c exact-integer? continued-fraction?)
v : (or/c exact-integer? continued-fraction?)
> (for/list ((t (cf/ (pi-cf) (phi-cf) (expt-cf 2 1/2))) (i (in-range 20))) t) '(1 2 1 2 7 6 3 1 36 2 36 1 4 2 1 1 3 7 1 3)
2.3 Controlling Behavior
A message is sent to the current-error-port indicating the fact.
The current state is coerced to a rational and the terms of this rational become the rest of the sequence.
procedure
cf : continued-fraction?
> (define ~pi (parameterize ((precision 1000)) (for/list ((t (precision-emit (pi-cf)))) t)))
> ~pi '(3 7 15 1)
> (abs (/ (- pi (cf-terms->rational ~pi)))) 3748629.0878493083
> (parameterize ((precision 3748630)) (for/list ((t (precision-emit (pi-cf)))) t)) '(3 7 15 1 292 1)
> (displayln (parameterize ((precision +inf.0)) (for/list ((t (precision-emit (pi-cf))) (i (in-range 40))) t))) (3 7 15 1 292 1 1 1 2 1 3 1 14 2 1 1 2 2 2 2 1 84 2 1 1 15 3 13 1 4 2 6 6 99 1 2 2 6 3 5)
> (displayln (for/list ((t (pi-cf)) (i (in-range 40))) t)) (3 7 15 1 292 1 1 1 2 1 3 1 14 2 1 1 2 2 2 2 1 84 2 1 1 15 3 13 1 4 2 6 6 99 1 2 2 6 3 5)
2.4 Arithmetic Caveats
> (for/list ((t (cf/ (exp-cf 1) (cf- (phi-cf) (phi-cf)))) (i (in-range 10))) t)
consume limit reached
consume limit reached
'()
> (for/list ((t (cf/ (exp-cf 1) (cf- 2 2))) (i (in-range 10))) t) consume limit reached
'()
> (for/list ((t (cf/ (exp-cf 1) (rational->cf 0))) (i (in-range 10))) t) consume limit reached
'()
> (for/list ((t (cf/ (rational->cf 0) (rational->cf 0)))) t) '()
2.5 Emitting Terms in Specific Number Bases
procedure
(base-emit v b) → continued-fraction?
v : continued-fraction? b : (and/c exact-integer? (>/c 1))
> (define phi (cf/ (cf+ 1 (expt-cf 5 1/2)) 2))
> (for/list ((t (base-emit phi 10)) (i (in-range 20))) t) '(1 6 1 8 0 3 3 9 8 8 7 4 9 8 9 4 8 4 8 2)
> (/ (+ 1 (sqrt 5)) 2) 1.618033988749895
> (for/list ((t (base-emit (rational->cf 1/10) 2)) (i (in-range 20))) t) '(0 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0)
> (for/list ((t (base-emit (rational->cf 2/3) 3))) t) '(0 2)
> (for/list ((t (base-emit (rational->cf 101/3) 3)) (i (in-range 20))) t) '(33 2)
> (for/list ((t (base-emit (cf- (phi-cf) (exp-cf 1)) 10)) (i (in-range 20))) t) '(-1 -1 0 0 -2 -4 -7 -8 -3 -9 -7 0 -9 -1 -5 0 -3 -8 -7 -1)
procedure
(base-consume s b) → continued-fraction?
s : sequence?
b :
(and/c exact-integer? (>/c 1))