Rationalize
Finds a simple rational number near x.
Rationalize✓Rationalize(x)the simplest rational within about one machine epsilon of x.Rationalize(x, tolerance)the simplest rational within the given tolerance of x.Rationalize(x, tolerance?)Finds a simple rational number near x.Typed signatures
| Type | Package | Applies |
|---|---|---|
(real, real<0..>?) -> rational | compute-engine | always |
(value, number?) -> value | analyticreplaces compute-engine | always |
(value, number?) -> value | combinatoricsreplaces analytic | always |
Details
- Finds a simple rational number near x.
- With one argument, it finds the simplest fraction within about one machine epsilon of x's current value; a second argument sets an explicit tolerance instead.
- An already-exact rational (or integer) is returned unchanged.
- Builds the approximation via continued fractions, the same technique behind classic approximations like .
Examples
3 more kept as data, checked against the oraclesScope #
The rational with the smallest denominator within 0.001 of -- , not compute-engine's own closer-but-larger-denominator continued-fraction convergent
live ↗A tolerance finer than a double can resolve is still honoured -- the simplest fraction within of itself, not of , which is already away
live ↗Threads element-wise over a list; compute-engine's own Rationalize takes only a single real
live ↗A zero tolerance gives the exact rational the machine double denotes -- 's own dyadic value, , not merely a rational within some epsilon of it
live ↗Applications #
Properties #
Possible issues #
Without enough repeating digits to reach machine precision, it just returns the exact decimal as a fraction rather than snapping to 1/3
live ↗Without a tolerance, a float with no simple fraction nearby still becomes a fraction with a large denominator
live ↗Neat examples #
About
| Examples | 24 |
|---|---|
| Checked against | Wolfram Language 24 agree |
| Crosswalk | Wolfram Language |
See also: Round