Documentation

Complexitylib.Classes.PCP.Internal.NumEnc

Numbering a structured index #

The index types of Dinur's construction are built from a few formers: a pair of indices, a choice between two, an optional one, a tuple. Fintype numbers such a type too, but by an enumeration no algorithm can follow. This module numbers them explicitly instead: a pair is numbered by mixed radix, a choice by offsetting the second summand, a tuple by its digits.

The decoding is partial — a number out of range names nothing — which is what makes the numbering compose without needing any type to be inhabited.

Main definitions #

Main results #

An explicit numbering of a finite type: every value has a number below card, and every number below card names a value.

  • card :

    How many values there are.

  • enc : α

    The number of a value.

  • dec : Option α

    The value a number names, if any.

  • enc_lt (a : α) : enc a < card α

    Numbers are below the count.

  • dec_enc (a : α) : dec (enc a) = some a

    Decoding a number back gives the value.

  • enc_dec (i : ) (a : α) : dec i = some aenc a = i

    And a number in range is the number of what it names.

  • dec_isSome (i : ) : i < card α(dec i).isSome = true

    Every number below the count names something.

Instances
    theorem Complexity.NumEnc.dec_eq_none_of_le {α : Type} [NumEnc α] {i : } (h : card α i) :
    def Complexity.NumEnc.get {α : Type} [NumEnc α] {i : } (h : i < card α) :
    α

    The value a number in range names.

    Equations
    Instances For
      @[simp]
      theorem Complexity.NumEnc.dec_get {α : Type} [NumEnc α] {i : } (h : i < card α) :
      dec i = some (get h)
      @[simp]
      theorem Complexity.NumEnc.enc_get {α : Type} [NumEnc α] {i : } (h : i < card α) :
      enc (get h) = i
      @[simp]
      theorem Complexity.NumEnc.get_enc {α : Type} [NumEnc α] (a : α) :
      get = a

      The count is the number of values.

      The numbering, as an equivalence with an initial segment.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        noncomputable def Complexity.NumEnc.equivFinCard (α : Type) [Fintype α] [NumEnc α] :

        The numbering, as an equivalence with Fin of the type's own cardinality — a drop-in replacement for Fintype.equivFin that an algorithm can follow.

        Equations
        Instances For
          @[simp]
          theorem Complexity.NumEnc.val_equivFinCard (α : Type) [Fintype α] [NumEnc α] (a : α) :
          ((equivFinCard α) a) = enc a

          The formers #

          @[instance_reducible]
          Equations
          • One or more equations did not get rendered due to their size.
          @[instance_reducible]
          Equations
          • One or more equations did not get rendered due to their size.
          @[instance_reducible]
          Equations
          theorem Complexity.NumEnc.prod_lt {α β : Type} [NumEnc α] [NumEnc β] (a : α) (b : β) :
          enc a * card β + enc b < card α * card β
          theorem Complexity.NumEnc.prod_div {α β : Type} [NumEnc α] [NumEnc β] (a : α) (b : β) :
          (enc a * card β + enc b) / card β = enc a
          theorem Complexity.NumEnc.prod_mod {α β : Type} [NumEnc α] [NumEnc β] (a : α) (b : β) :
          (enc a * card β + enc b) % card β = enc b
          @[instance_reducible]
          instance Complexity.NumEnc.instProd {α β : Type} [NumEnc α] [NumEnc β] :
          NumEnc (α × β)
          Equations
          • One or more equations did not get rendered due to their size.
          @[instance_reducible]
          instance Complexity.NumEnc.instSum {α β : Type} [NumEnc α] [NumEnc β] :
          NumEnc (α β)
          Equations
          • One or more equations did not get rendered due to their size.
          @[instance_reducible]
          Equations
          • One or more equations did not get rendered due to their size.
          @[reducible]
          noncomputable def Complexity.NumEnc.ofFintype (α : Type) [Fintype α] :

          Any finite type is numbered by its own enumeration. For a type whose size is a constant, that is all an algorithm needs: the numbering is a lookup on a bounded key.

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