Documentation

DescriptiveComplexity.Numbers.Binary

Binary representation of numbers in finite structures #

The binary encoding: a number carried by an instance is given by a set of bit positions, the positions being linearly ordered elements of the structure. This is the honest encoding for problems whose numbers must be exponential in the instance size (SubsetSum, Partition, Knapsack…), where the unary representation of DescriptiveComplexity.Numbers.Unary would change the complexity.

The problems of the catalog reach this layer through DescriptiveComplexity.Numbers.BinRel, which decodes the same bits when the order on positions is a relation symbol of the vocabulary rather than a LinearOrder instance: Knapsack, Partition, Job Sequencing and 0-1 Integer Programming. The choice between this encoding and the unary one is argued in DescriptiveComplexity.Numbers.

Sums of powers of two over a bit predicate #

Positions, decoding and encoding #

noncomputable def DescriptiveComplexity.posRank (P : Type) [Fintype P] [LinearOrder P] (p : P) :

The rank of a bit position: its index in the increasing enumeration of the positions.

Equations
Instances For
    @[simp]
    theorem DescriptiveComplexity.posRank_fin {m : } (p : Fin m) :
    posRank (Fin m) p = p

    On Fin m, which is already the increasing enumeration of itself, the rank of a position is its index. This is what lets a concrete encoder lay its bit positions out as Fin m and read the place values off directly.

    noncomputable def DescriptiveComplexity.binValue (P : Type) [Fintype P] [LinearOrder P] (b : PProp) :

    The number represented in binary by a set of positions: the sum of 2 ^ rank over the set bits. This is the decoding function of the binary representation.

    Equations
    Instances For

      The canonical binary encoding of a number as a set of positions.

      Equations
      Instances For
        noncomputable def DescriptiveComplexity.posBits (P : Type) [Fintype P] [LinearOrder P] (b : PProp) :
        Bool

        The bits of a set of positions, as a function of the rank.

        Equations
        Instances For
          theorem DescriptiveComplexity.posBits_posRank {P : Type} [Fintype P] [LinearOrder P] (b : PProp) (p : P) :
          posBits P b (posRank P p) = true b p

          The decoded number is smaller than 2 ^ #positions.

          Decoding after encoding is the identity, for numbers within range.

          theorem DescriptiveComplexity.testBit_binValue {P : Type} [Fintype P] [LinearOrder P] (b : PProp) (p : P) :
          (binValue P b).testBit (posRank P p) = true b p

          The bits of the decoded number are the original set of positions.

          theorem DescriptiveComplexity.binValue_orderIso {P : Type} [Fintype P] [LinearOrder P] {Q : Type} [Fintype Q] [LinearOrder Q] (e : P ≃o Q) (b : QProp) :
          (binValue P fun (p : P) => b (e p)) = binValue Q b

          The decoded number is invariant under order-isomorphisms of the positions.

          theorem DescriptiveComplexity.binValue_congr {P : Type} [Fintype P] [LinearOrder P] {b b' : PProp} (h : ∀ (p : P), b p b' p) :

          binValue only depends on the extension of the bit predicate.

          theorem DescriptiveComplexity.binValue_lt_binValue_iff {P : Type} [Fintype P] [LinearOrder P] (b b' : PProp) :
          binValue P b < binValue P b' ∃ (p : P), ¬b p b' p ∀ (q : P), p < q → (b q b' q)

          Most-significant-bit comparison: one binary number is smaller than another iff at some position the first has bit 0 and the second bit 1, all higher positions agreeing. This is the Lean counterpart of the FO(≤) formula comparing binary numbers.