Documentation

DescriptiveComplexity.Computability.FinStruct

Finite structures as concrete data #

FirstOrder.Language.FinStruct: a finite structure over a finitely presented relational vocabulary, as a piece of data a machine can hold – a universe Fin (n + 1) and a list of Boolean tables, one per relation symbol. This is the passage from isomorphism classes to a Primcodable type that ComputablePred needs, and it is built once for the whole catalog rather than per problem.

The two ingredients #

The representation decision #

The table is a List (List Bool) – one row per symbol, one entry per tuple, tuples numbered little-endian in base card – and not a dependent function (Fin k → Fin n) → Bool. Dependent function tables are pleasant semantically and painful to prove Primrec facts about, and everything downstream of this file is Primrec facts. Out-of-range lookups return false, so every piece of data denotes a structure and no well-formedness side condition ever has to be carried.

Numbering tuples #

The number of a tuple of digits, little-endian in base c.

Equations
Instances For
    Dependency graph

    The j-th digit of t in base c.

    Equations
    Instances For
      Dependency graph
      Dependency graph
      @[simp]
      theorem FirstOrder.Language.tupleIdx_cons (c a : ℕ) (l : List ℕ) :
      tupleIdx c (a :: l) = a + c * tupleIdx c l
      Dependency graph
      theorem FirstOrder.Language.digitAt_lt {c : ℕ} (hc : 0 < c) (t j : ℕ) :
      digitAt c t j < c
      Dependency graph

      Finitely presented vocabularies #

      A finitely presented relational vocabulary: the relation symbols of L numbered by Fin numSyms, with their arities. Reading a symbol off its number (sym) and numbering a symbol (index) are mutually inverse, so the presentation loses nothing.

      Every vocabulary of the catalog is of this shape: Language.turing has 12 symbols of arity at most 2, Language.finsat 14 of arity at most 3. The presentations are closed under Language.sum (FirstOrder.Language.FinVocab.sum), which is what lets the second-order machinery – whose vocabularies are sums of the instance's with a block's – be encoded by the same means.

      • numSyms : ℕ

        The number of relation symbols.

      • symOf : Fin self.numSyms → (n : ℕ) × L.Relations n

        The symbol with a given number, together with its arity.

      • index {n : ℕ} : L.Relations n → Fin self.numSyms

        The number of a symbol.

      • symOf_index {n : ℕ} (R : L.Relations n) : self.symOf (self.index R) = ⟨n, R⟩

        Reading back the symbol with the number of a symbol gives it back.

      • index_symOf (i : Fin self.numSyms) : self.index (self.symOf i).snd = i

        Numbering the symbol with a given number gives that number back.

      Instances For
        Dependency graph
        @[reducible, inline]

        The arity of the symbol with a given number.

        Equations
        Instances For
          Dependency graph
          @[reducible, inline]

          The symbol with a given number.

          Equations
          Instances For
            Dependency graph

            Concrete finite structures #

            A concrete finite structure over the finitely presented vocabulary V: a universe size and a table of Booleans, one row per relation symbol.

            The universe is Fin (univSize + 1), so it is nonempty by construction; the row of an n-ary symbol is read at the number of the tuple, little-endian in base card. Anything out of range reads false, so every pair of a number and a list of lists of Booleans denotes a structure.

            • univSize : ℕ

              One less than the size of the universe.

            • table : List (List Bool)

              The tables of the relations, one row per symbol.

            Instances For
              Dependency graph
              @[reducible, inline]

              The size of the universe of a concrete finite structure.

              Equations
              Instances For
                Dependency graph
                @[reducible, inline]

                The universe of a concrete finite structure: nonempty and linearly ordered by construction.

                Equations
                Instances For
                  Dependency graph
                  def FirstOrder.Language.FinStruct.relMapBool {L : Language} {V : L.FinVocab} (s : FinStruct V) {n : ℕ} (R : L.Relations n) (x : Fin n → s.Univ) :

                  The table lookup: does the relation R hold of the tuple x?

                  Equations
                  Instances For
                    Dependency graph
                    @[instance_reducible]

                    The structure a piece of data denotes.

                    Equations
                    Dependency graph
                    Dependency graph
                    @[instance_reducible]
                    Equations
                    Dependency graph

                    Building a concrete structure from a table #

                    def FirstOrder.Language.FinStruct.ofTable {L : Language} (V : L.FinVocab) (k : ℕ) (f : {n : ℕ} → L.Relations n → (Fin n → Fin (k + 1)) → Bool) :

                    The concrete structure over a universe Fin (k + 1) whose relations are given by the Boolean function f.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      Dependency graph
                      @[simp]
                      theorem FirstOrder.Language.FinStruct.univSize_ofTable {L : Language} (V : L.FinVocab) (k : ℕ) (f : {n : ℕ} → L.Relations n → (Fin n → Fin (k + 1)) → Bool) :
                      (ofTable V k f).univSize = k
                      Dependency graph
                      def FirstOrder.Language.FinStruct.ofEquiv {L : Language} [L.IsRelational] {A : Type} [L.Structure A] [(n : ℕ) → (R : L.Relations n) → (x : Fin n → A) → Decidable (Structure.RelMap R x)] (V : L.FinVocab) (k : ℕ) (e : Fin (k + 1) ≃ A) :

                      Every finite nonempty structure is presented by a table, along a chosen numbering of its universe: ofTable transported along e, with the numbering itself an L-isomorphism.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        Dependency graph
                        theorem FirstOrder.Language.FinStruct.relMapBool_ofEquiv {L : Language} [L.IsRelational] {A : Type} [L.Structure A] [(n : ℕ) → (R : L.Relations n) → (x : Fin n → A) → Decidable (Structure.RelMap R x)] (V : L.FinVocab) (k : ℕ) (e : Fin (k + 1) ≃ A) {n : ℕ} (R : L.Relations n) (x : Fin n → (ofEquiv V k e).Univ) :
                        (ofEquiv V k e).relMapBool R x = decide (Structure.RelMap R fun (j : Fin n) => e (x j))

                        The table of FirstOrder.Language.FinStruct.ofEquiv reads the relations of the structure it was built from.

                        Dependency graph
                        def FirstOrder.Language.FinStruct.equivOfEquiv {L : Language} [L.IsRelational] {A : Type} [L.Structure A] [(n : ℕ) → (R : L.Relations n) → (x : Fin n → A) → Decidable (Structure.RelMap R x)] (V : L.FinVocab) (k : ℕ) (e : Fin (k + 1) ≃ A) :
                        L.Equiv (ofEquiv V k e).Univ A

                        The numbering used by FirstOrder.Language.FinStruct.ofEquiv is an isomorphism onto the structure it builds.

                        Equations
                        Instances For
                          Dependency graph

                          Concrete instances are a Primcodable type #

                          Everything a machine has to hold about an instance is a natural number and a list of lists of Booleans, so the coding is Mathlib's, with nothing to prove beyond the three projections being primitive recursive.

                          The coding of a concrete finite structure as a pair.

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

                            The set of concrete instances a decision problem denotes. This is the object ComputablePred and REPred are about: a problem is an isomorphism-closed property of finite structures, and the numbering of FirstOrder.Language.FinStruct turns it into a property of a Primcodable type, with nothing to write per problem.

                            Equations
                            Instances For
                              Dependency graph