Documentation

Complexitylib.RationalHitting.Internal.BinaryDivision

Rational hitting lists: binary division #

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

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

Subtract the next pair of bits and update the borrow flag.

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

    The register store after one bit-subtraction step.

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

      The final subtraction store, including output and borrow flag.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem Complexity.RationalHitting.StackLanguage.eval_subtractLoop (s : Store (Fin 5)) (c : Bool) (hc : s 3 = [c]) (hf : s 4 = [true]) :
        ∃ t ≤ 15 * ((s 0).length + (s 1).length) + 7, Eval subtractLoop s (subFinish s c) t

        Subtract and compare, destructively. Output register 2 has the little-endian fixed-width modular difference; singleton register 3 is exactly the comparison bit (true iff the first number was smaller).

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          theorem Complexity.RationalHitting.StackLanguage.eval_subtract (s : Store (Fin 5)) :
          ∃ t ≤ 17 * ((s 0).length + (s 1).length) + 2 * (s 2).length + 2 * (s 3).length + 2 * (s 4).length + 19, Eval subtract s (Function.update (Function.update (Function.update (Function.update (Function.update s 0 (subtractWord (s 0) (s 1) false).1) 1 []) 2 []) 3 [(subtractWord (s 0) (s 1) false).2]) 4 []) t

          Subtract when possible, otherwise retain the normalized original word.

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

            Long division, scanning the original numerator most-significant-bit first. The quotient and remainder registers remain ordinary little-endian words.

            Equations
            Instances For
              theorem Complexity.RationalHitting.StackLanguage.extend_transfer_store {K L : Type} [DecidableEq K] [DecidableEq L] (f : K → L) (hf : Function.Injective f) (s : Store K) (S : Store L) (a b : K) :
              Function.extend f (transfer a b s) S = transfer (f a) (f b) (Function.extend f s S)
              theorem Complexity.RationalHitting.StackLanguage.Eval.rename {K L : Type} [DecidableEq K] [DecidableEq L] {p : Program K} {s v : Store K} {t : ℕ} (h : Eval p s v t) (f : K → L) (hf : Function.Injective f) (S : Store L) :

              Uniform register allocation: renaming injectively never changes time and preserves every register outside its finite image.

              theorem Complexity.RationalHitting.StackLanguage.extend_pull_store {K L : Type} (f : K → L) (hf : Function.Injective f) (S : Store L) :
              Function.extend f (fun (k : K) => S (f k)) S = S
              theorem Complexity.RationalHitting.StackLanguage.eval_rename_from {K L : Type} [DecidableEq K] [DecidableEq L] (f : K → L) (hf : Function.Injective f) (S : Store L) {p : Program K} {v : Store K} {t : ℕ} (h : Eval p (fun (k : K) => S (f k)) v t) :