Documentation

MIPRE.Foundations.Cost.Binary

The closure library, part V: the binary successor, and unary to binary #

The successor on binary numerals (incBitsProg, PolyTimeFun.inc: flip the leading 1s and the first 0, in two passes as decProg), the conversion of a unary numeral to binary (PolyTimeFun.unaryToBin, a fold of the successor), data as its own encoding, the bits of a number, and the tagging combinator (PolyTimeFun.tagged) for constructors of encoded inductive types (planning/succinct-cook-levin.md, S3).

Data as data #

@[instance_reducible]

Data encode as themselves.

Equations
@[simp]
theorem MIPRE.Cost.encode_data (d : Data) :
encode d = d
@[simp]

Bit strings #

theorem MIPRE.Cost.esize_bitStr_append (l₁ l₂ : BitStr) :
esize (l₁ ++ l₂) + 1 = esize l₁ + esize l₂

The bits of a number, as a polynomial-time function: the encoding is the same.

Equations
Instances For

    The binary successor #

    The successor of a binary numeral (least significant bit first).

    Equations
    Instances For

      The tail of the successor after the leading 1s: [] becomes [1], 0 · r becomes 1 · r.

      Equations
      Instances For
        theorem MIPRE.Cost.incBits_replicate_true (j : ℕ) (rest : BitStr) (hrest : rest = [] ∨ ∃ (r : List Bool), rest = false :: r) :
        theorem MIPRE.Cost.exists_leading_trues (l : BitStr) :
        ∃ (j : ℕ) (rest : BitStr), l = List.replicate j true ++ rest ∧ (rest = [] ∨ ∃ (r : List Bool), rest = false :: r)

        Body of the successor loop: on cons xs acc, if xs is empty stop with (acc, [1]); if its head is 0 stop with (acc, 1 · tail); if its head is 1 continue with (tail, 0 · acc). Reversing the first component onto the second then gives the successor.

        Equations
        Instances For

          The stop on a head 0: (acc, 1 · tail).

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

            The body of the successor loop.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              theorem MIPRE.Cost.Prog.incBitsBody_false (rest acc : BitStr) :
              Eval [(encode (false :: rest)).cons (encode acc)] incBitsBody (Data.nil.cons ((encode acc).cons (encode (true :: rest)))) (esize acc + esize rest + 12)
              theorem MIPRE.Cost.Prog.incBitsLoop_runs (j : ℕ) (rest : BitStr) (hrest : rest = [] ∨ ∃ (r : List Bool), rest = false :: r) (acc : BitStr) (env : Env) (S : ℕ) (hS : esize rest + esize acc + 4 * j ≤ S) :
              ∃ t ≤ (j + 1) * (S + 13), Eval ((encode (List.replicate j true ++ rest)).cons (encode acc) :: env) incBitsBody.loop ((encode (List.replicate j false ++ acc)).cons (encode (incTail rest))) t

              The successor loop on 1^j · rest (with rest empty or starting with 0) from the accumulator acc stops with (0^j · acc, incTail rest).

              The successor on binary numerals, in polynomial time.

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

                A unary numeral to binary, by a fold of the successor.

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

                  Tagged constructors #

                  noncomputable def MIPRE.Cost.PolyTimeFun.tagged {α : Type u_1} {β : Type u_2} [SizedEncoding α] [SizedEncoding β] (k : ℕ) (f : α → β) (h : ∀ (a : α), encode (f a) = (Data.ofNat k).cons (encode a)) :

                  A constructor whose encoding pairs a unary tag with the encoding of its argument.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    @[simp]
                    theorem MIPRE.Cost.PolyTimeFun.tagged_apply {α : Type u_1} {β : Type u_2} [SizedEncoding α] [SizedEncoding β] (k : ℕ) (f : α → β) (h : ∀ (a : α), encode (f a) = (Data.ofNat k).cons (encode a)) (a : α) :
                    (tagged k f h).toFun a = f a