Documentation

Complexity.Computability.Circuit.Rational.Runtime.Encode

Polynomial-time canonical binary encodings of naturals and rationals #

This module bridges the self-delimiting binary encodings Cslib.Circuits.Rational.encodeNat and Cslib.Circuits.Rational.encodeRat from Complexity/Computability/Circuit/Rational/Defs.lean to the fun_prop polynomial-time calculus over Turing.MultiTapeTM.encNat and Turing.MultiTapeTM.encIntBin.

First, encodeNat a is shown to equal List.replicate a.bits.length true ++ false :: a.bits (encodeNat_eq), yielding a polynomial-time certificate encodeNat_polytime. Next, the reduced numerator magnitude, denominator, and sign bit of Rat.divInt a b are expressed in terms of a.natAbs, b.natAbs, and Nat.gcd a.natAbs b.natAbs (divInt_num_abs, divInt_den, divInt_sign, and encodeRat_divInt). Combining binary integer operations with binary_div and binary_gcd then certifies (p, q) ↦ encodeRat (Rat.divInt p q) on binary integer pairs (encodeDivInt_polytime).

Main results #

References #

Mapping · != 0 over the base-2 digits of a recovers a.bits.

encodeNat a is the unary length of a.bits, a false delimiter, and a.bits.

Self-delimiting binary encoding of a binary natural is computable in polynomial time.

Self-delimiting binary encoding of a computed binary natural.

Reduced numerator magnitude of Rat.divInt a b for b ≠ 0.

Reduced denominator of Rat.divInt a b for b ≠ 0.

theorem Cslib.Circuits.Rational.divInt_sign (a b : ℤ) (hb : b ≠ 0) :
decide ((Rat.divInt a b).num < 0) = if a = 0 then false else decide (a < 0) ^^ decide (b < 0)

Sign bit of Rat.divInt a b for b ≠ 0.

Reduced numerator magnitude of Rat.divInt a b for arbitrary integers a, b.

Reduced denominator of Rat.divInt a b for arbitrary integers a, b.

Sign bit of Rat.divInt a b for arbitrary integers a, b.

Explicit expansion of encodeRat (Rat.divInt a b) in terms of integer magnitudes and Nat.gcd.

Encode the reduced rational quotient of two computed binary integers.