{"size": 1220, "ext": "scrbl", "max_stars_repo_path": "scribblings/numerics/integer/continued-fractions.scrbl", "max_stars_repo_name": "bennn/mechanics", "max_stars_repo_stars_event_min_datetime": "2015-05-08T23:10:09.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-05T21:03:02.000Z", "max_issues_repo_path": "scribblings/numerics/integer/continued-fractions.scrbl", "max_issues_repo_name": "bennn/mechanics", "max_issues_repo_issues_event_min_datetime": "2015-05-03T01:32:29.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-23T02:12:53.000Z", "max_forks_repo_path": "scribblings/numerics/integer/continued-fractions.scrbl", "max_forks_repo_name": "bennn/mechanics", "max_forks_repo_forks_event_min_datetime": "2018-01-23T07:39:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-22T22:24:11.000Z"}
{"max_stars_count": 31, "max_issues_count": 28, "max_forks_count": 4, "avg_line_length": 34.8571428571, "max_line_length": 233, "alphanum_fraction": 0.6860655738}
#lang scribble/manual

@require[mechanics/private/numerics/integer/continued-fractions]
@require[scribble/eval]

@title[#:tag "continued-fractions"]{Continued Fractions}
@defmodule[mechanics/private/numerics/integer/continued-fractions]
@(define cf-eval
  (make-base-eval
    '(begin (require mechanics/private/numerics/integer/continued-fractions
                     (only-in racket/math pi)))))

The @hyperlink["http://en.wikipedia.org/wiki/Continued_fraction"]{continued fraction} representation of a real number @tt{n} is a stream of integers @tt{n_0, n_1, n_2 ...} such that @tt{(= n (+ n_0 (/ 1 (+ n_1 (/ 1 (+ n_2 ...))))))}.

@defproc[(continued-fraction [n real?]) (sequenceof integer?)]{
  Return the continued fraction representation of a number.
}

@examples[#:eval cf-eval
  (for/list ([n (continued-fraction pi)]
             [i (in-range 5)])
    n)
]

@defproc[(convergents [i* (sequenceof integer?)]) (sequenceof exact-rational?)]{
  Approximate a continued fraction.
  The @tt{n}th term of the result is the number obtained from the first @tt{n} terms of the continued fraction.
}

@examples[#:eval cf-eval
  (for/list ([n (convergents (continued-fraction pi))]
             [i (in-range 3)])
    n)
]
