Skip to content

An implementation of various algorithms for approximating real numbers by rationals

License

Notifications You must be signed in to change notification settings

pdemp1729/farey-algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

farey-algorithm

An implementation of various algorithms for approximating real numbers by rationals.

Usage

To import the module, simply do

import rationals

To find the nearest rational approximation accurate to a certain number of decimal places, use the places kwarg:

rationals.best_rational_approximation(
    math.sqrt(2), method="farey", places=5,
)

To find the nearest rational approximation with denominator no larger than some cutoff, use the max_denominator kwarg:

rationals.best_rational_approximation(
    math.sqrt(2), method="farey", max_denominator=1000,
)

The available methods are "farey" and "continued_fraction".

About

An implementation of various algorithms for approximating real numbers by rationals

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages