Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Encodings.Rat

Binary encoding of rational numbers #

Turing.MultiTapeTM.encRat encodes a rational number q : ℚ as its framed pair (q.num, q.den) : ℤ × ℕ using Turing.MultiTapeTM.encIntBin and Turing.MultiTapeTM.encNat.

Main definitions #

Main results #

@[reducible, inline]

Binary encoding of rational numerator-denominator pairs (q.num, q.den).

Binary encoding of rational numbers ℚ as (q.num, q.den).

Exact encoded bit length of encRat q.

Every encoded rational uses at least 4 bits.

theorem Turing.MultiTapeTM.length_encRat_le (q : ℚ) {A B : ℕ} (hnum : q.num.natAbs ≤ A) (hden : q.den ≤ B) :
(encRat q).length ≤ 2 * A.size + B.size + 3

Upper bound on (encRat q).length in terms of |q.num| and q.den binary sizes.

The numerator magnitude of q is strictly below 2 ^ (encRat q).length.

The denominator of q is strictly below 2 ^ (encRat q).length.

Encoded length of Rat.divInt a b in terms of the binary lengths of a and b.

Negation preserves the encoded length of a rational number.

Encoded length of q⁻¹ is at most twice that of q.

Encoded length of a * b is at most (encRat a).length + (encRat b).length.

Encoded length of a + b is at most 3 * ((encRat a).length + (encRat b).length).

Encoded length of a - b is at most 3 * ((encRat a).length + (encRat b).length).

Encoded length of a / b is at most (encRat a).length + 2 * (encRat b).length.