Documentation

Complexitylib.RationalHitting.Internal.BinarySubtract

Rational hitting lists: binary subtract #

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

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

Shift-and-add on explicit little-endian words.

Equations
Instances For

    Registers: 0 multiplicand, 1 multiplier, 2 accumulator, 3 copied addend, 4/5/6 addition scratch, 7 copy scratch.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem Complexity.RationalHitting.StackLanguage.eval_mulLoop (s : Store (Fin 8)) (hf : ∀ (k : Fin 8), 3 ≤ ↑k → s k = []) (A C : ℕ) (hA : (s 0).length + (s 1).length ≤ A) (hC : (s 2).length + (s 1).length * ((s 0).length + (s 1).length) ≤ C) :
      ∃ t ≤ (s 1).length * (A * (7 * C + 34) + 23) + 1, Eval mulLoop s (Function.update (Function.update (Function.update s 0 (List.replicate (s 1).length false ++ s 0)) 1 []) 2 (mulAccWord (s 0) (s 1) (s 2))) t

      The normalized multiplication instruction; the accumulator starts at zero. After execution register 2 is the canonical binary product.

      Equations
      Instances For
        theorem Complexity.RationalHitting.StackLanguage.eval_multiply (s : Store (Fin 8)) (hzero : s 2 = []) (hf : ∀ (k : Fin 8), 3 ≤ ↑k → s k = []) :
        have A := (s 0).length + (s 1).length; have C := (s 1).length * A; ∃ t ≤ (s 1).length * (A * (7 * C + 34) + 23) + 7 * C + 18, Eval multiply s (Function.update (Function.update (Function.update s 0 (List.replicate (s 1).length false ++ s 0)) 1 []) 2 (wordValue (s 0) * wordValue (s 1)).bits) t

        Boolean full-subtractor gate.

        Equations
        Instances For

          The outgoing borrow bit for one full subtractor.

          Equations
          Instances For

            Interpret a Boolean bit as zero or one.

            Equations
            Instances For
              @[irreducible]

              Fixed-width subtraction, returning the overflow borrow. Registers may have leading zeros. Width is exactly the larger input word length.

              Equations
              Instances For

                Branch on the head bit, treating an empty stack as false.

                Equations
                Instances For
                  theorem Complexity.RationalHitting.StackLanguage.eval_readBit {K : Type} [DecidableEq K] (k : K) (f : Bool → Program K) (s v : Store K) (t : ℕ) (h : Eval (f ((s k).headD false)) s v t) :
                  Eval (readBit k f) s v (1 + t)

                  Registers 0,1 input, 2 reverse output, 3 singleton borrow, 4 loop flag.

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