Inversion and division for dyadic numbers #
Inverts a dyadic number at a given (maximum) precision.
Returns the greatest dyadic number with precision at most prec which is less than or equal to 1/x.
For x = 0, returns 0.
This agrees with divAtPrec 1 x prec (see invAtPrec_eq_divAtPrec_one), but is kept as a
separate definition to avoid the unnecessary 1 *-by-numerator step in Rat's division at
runtime.
Equations
- Dyadic.zero.invAtPrec prec = Dyadic.zero
- x.invAtPrec prec = x.toRat.inv.toDyadic prec
Instances For
Divides two dyadic numbers at a given (maximum) precision.
Returns the greatest dyadic number with precision at most prec which is less than or equal
to a/b. For b = 0, returns 0.
Equations
- a.divAtPrec Dyadic.zero prec = Dyadic.zero
- a.divAtPrec b prec = (a.toRat / b.toRat).toDyadic prec
Instances For
If y : Dyadic has precision at most prec and a rational q lies in the half-open
interval [y.toRat, y.toRat + 2 ^ (-prec)), then y is the floor of q at precision
prec, i.e. y = q.toDyadic prec.
For a positive dyadic b, a < (divAtPrec a b prec + 2^(-prec)) * b.
For positive b, divAtPrec a b prec is the unique dyadic with precision at most prec
satisfying both _ * b ≤ a and a < (_ + ofIntWithPrec 1 prec) * b.
For a positive dyadic x, 1 < (invAtPrec x prec + 2^(-prec)) * x.
invAtPrec x prec is the unique dyadic with precision at most prec satisfying
both _ * x ≤ 1 and 1 < (_ + ofIntWithPrec 1 prec) * x, for 0 < x.
The equality divAtPrec a b prec = a * invAtPrec b prec does not hold in general:
a * invAtPrec b prec rounds 1/b first and then multiplies, whereas divAtPrec a b prec
rounds a/b directly. The next two theorems pin the gap asymmetrically:
divAtPrec a b prec - a * 2 ^ (-prec) < a * invAtPrec b prec < divAtPrec a b prec + 2 ^ (-prec).
For nonneg a and positive b, a * invAtPrec b prec is less than 2 ^ (-prec) larger
than divAtPrec a b prec.