Documentation

Complexitylib.RationalHitting.Internal.RationalBinary

Rational hitting lists: rational binary #

Adapted from OpenAI's formalization at revision adc7f1241b42e322a6451854ab7e4b4c146bf78a. Source: https://github.com/openai/math/blob/adc7f1241b42e322a6451854ab7e4b4c146bf78a/lean/OAI/Computability/RationalHitting/RationalBinary.lean

Imports, namespaces, module visibility, documentation, and formatting are adapted for complexitylib. The source theorem statements and mathematical arguments are retained.

theorem Complexity.RationalHitting.StackLanguage.eval_copy9 (s : Store (Fin 12)) (a b : Fin 12) (hab : a ≠ b) (ha : a ≠ 9) (hb : b ≠ 9) (h9 : s 9 = []) :
Eval (copy a b 9) s (Function.update s b (s a)) (7 * (s a).length + 2 * (s b).length + 7)

Euclid followed by two binary divisions, destructively producing the coprime numerator and positive denominator magnitudes.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    theorem Complexity.RationalHitting.StackLanguage.eval_fractionReduce (s : Store (Fin 12)) (hs : FractionScratch s) (h10 : s 10 = []) (h11 : s 11 = []) (hcan0 : (wordValue (s 0)).bits = s 0) (hcan5 : (wordValue (s 5)).bits = s 5) (hb : 0 < wordValue (s 5)) (B : ℕ) (h0 : (s 0).length ≤ B) (h5 : (s 5).length ≤ B) :
    ∃ t ≤ 3000 * (B + 1) ^ 3, Eval fractionReduce s (Function.update (Function.update s 0 (wordValue (s 0) / (wordValue (s 0)).gcd (wordValue (s 5))).bits) 5 (wordValue (s 5) / (wordValue (s 0)).gcd (wordValue (s 5))).bits) t

    Consume a word, emitting its unary length, independently of its bits.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      Canonical output's self-delimiting natural-number encoding, applied to an already canonical little-endian binary word.

      Equations
      Instances For

        Write a self-delimiting binary word with its unary length prefix.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          The sign used by the canonical binary rational encoder.

          theorem Complexity.RationalHitting.StackLanguage.eval_encodeWord_rename {K : Type} [DecidableEq K] (f : Fin 4 → K) (hf : Function.Injective f) (s : Store K) (h2 : s (f 2) = []) (h3 : s (f 3) = []) :
          Eval (Program.rename f encodeWord) s (Function.update (Function.update s (f 0) []) (f 1) (encodedWord (s (f 0)) ++ s (f 1))) (11 * (s (f 0)).length + 7)
          theorem Complexity.RationalHitting.StackLanguage.eval_fractionReduce_rename {K : Type} [DecidableEq K] (f : Fin 12 → K) (hf : Function.Injective f) (s : Store K) (hs : FractionScratch fun (k : Fin 12) => s (f k)) (h10 : s (f 10) = []) (h11 : s (f 11) = []) (A D B : ℕ) (h0 : s (f 0) = A.bits) (h5 : s (f 5) = D.bits) (hD : 0 < D) (ha : A.bits.length ≤ B) (hd : D.bits.length ≤ B) :
          ∃ t ≤ 3000 * (B + 1) ^ 3, Eval (Program.rename f fractionReduce) s (Function.update (Function.update s (f 0) (A / A.gcd D).bits) (f 5) (D / A.gcd D).bits) t

          Registers 12 and 13 hold signed-magnitude signs; 15 stores the canonical result's sign and remains disjoint from the twelve arithmetic registers.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            theorem Complexity.RationalHitting.StackLanguage.eval_fractionSign (s : Store (Fin 16)) (a b : Bool) (h12 : s 12 = [a]) (h13 : s 13 = [b]) :
            ∃ t ≤ 4, Eval fractionSign s (Function.update s 15 ((if s 0 = [] then false else a ^^ b) :: s 15)) t

            Embed fraction-reduction registers into the rational-encoding program.

            Equations
            Instances For

              Registers used when emitting the canonical denominator.

              Equations
              Instances For

                Registers used when emitting the canonical numerator magnitude.

                Equations
                Instances For

                  Full signed canonical rational output. No gcd, comparison or sign oracle occurs in this fixed finite binary-stack program.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    theorem Complexity.RationalHitting.StackLanguage.eval_rationalEncode (s : Store (Fin 16)) (a b : ℤ) (hb : b ≠ 0) (h0 : s 0 = a.natAbs.bits) (h5 : s 5 = b.natAbs.bits) (h12 : s 12 = [decide (a < 0)]) (h13 : s 13 = [decide (b < 0)]) (h15 : s 15 = []) (hs : ∀ (i : Fin 16), ↑i < 12 → i ≠ 0 → i ≠ 5 → s i = []) (B : ℕ) (ha : a.natAbs.bits.length ≤ B) (hd : b.natAbs.bits.length ≤ B) :
                    ∃ t ≤ 3100 * (B + 1) ^ 3, Eval rationalEncode s (Function.update (Function.update (Function.update s 0 []) 5 []) 14 (encodeRat (Rat.divInt a b) ++ s 14)) t

                    Exact final canonical binary fraction, with a cubic bit-time stack implementation. This supplies the output-format obligation of the uniform list generator.