Documentation

Complexitylib.Classes.Pairing

Pairing and relation predicates #

This file defines a simple injective pairing pair : List BoolList BoolList Bool used to encode (x, y) as a single binary string for verification by a TM, along with the shared predicates PolyBalanced and pairLang used by FNP, FNL, and other search-problem classes.

Encode a pair of binary strings as a single binary string. Each bit of x is doubled (false ↦ [false, false], true ↦ [true, true]), followed by the separator [false, true], followed by y verbatim. This encoding is injective and computable in linear time.

Equations
Instances For

    Partial inverse to pair. It scans doubled bits until the first separator [false, true], returning the decoded left component together with the remaining suffix. Invalid doubled prefixes return none.

    Equations
    Instances For
      theorem Complexity.pair_cons_eq (b : Bool) (x y : List Bool) :
      pair (b :: x) y = b :: b :: pair x y

      One step of the doubling encoder: pair on b :: x prepends the doubled bit b, b.

      @[simp]
      theorem Complexity.pair_length (x y : List Bool) :
      (pair x y).length = 2 * x.length + 2 + y.length

      |pair x y| = 2·|x| + 2 + |y|. The 2·|x| comes from doubling every bit of x; the +2 is the separator [false, true].

      theorem Complexity.pair_inj {x₁ x₂ y₁ y₂ : List Bool} (h : pair x₁ y₁ = pair x₂ y₂) :
      x₁ = x₂ y₁ = y₂

      pair is injective: if pair x₁ y₁ = pair x₂ y₂ then x₁ = x₂ and y₁ = y₂.

      @[simp]

      unpair? is a left inverse of pair: decoding an encoded pair recovers exactly its two components.

      theorem Complexity.eq_pair_of_unpair?_eq_some {z x y : List Bool} (h : unpair? z = some (x, y)) :
      z = pair x y

      Soundness of the decoder: if unpair? succeeds on z, producing (x, y), then z was exactly the encoding pair x y.

      unpair? z returns some (x, y) if and only if z = pair x y, characterizing exactly which strings are valid pair encodings.

      A binary relation is polynomially balanced if witness length is bounded by a polynomial in the input length. This is the standard "short witness" condition used in the definitions of NP, FNP, FNL, etc.

      Equations
      Instances For

        The pair language (verification language) of a binary relation R: the set of encoded pairs pair(x, y) such that R x y holds.

        Equations
        Instances For
          theorem Complexity.pair_getElem_left_first (x y : List Bool) (i : ) (hi : i < x.length) :
          (pair x y)[2 * i] = x[i]

          In pair x y, the first duplicated copy of x[i] sits at position 2*i.

          theorem Complexity.pair_getElem_left_second (x y : List Bool) (i : ) (hi : i < x.length) :
          (pair x y)[2 * i + 1] = x[i]

          In pair x y, the second duplicated copy of x[i] sits at position 2*i+1.

          The first separator bit in pair x y is false.

          The second separator bit in pair x y is true.

          theorem Complexity.pair_getElem_right (x y : List Bool) (j : ) (hj : j < y.length) :
          (pair x y)[2 * x.length + 2 + j] = y[j]

          In pair x y, the suffix after the separator is exactly y.