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 #
FirstOrder.Language.FinVocab L: the vocabularyLpresented as data – finitely many relation symbols, numbered byFin numSyms, with their arities. Every vocabulary of the catalog qualifies.FirstOrder.Language.FinStruct V: a universe size and a table. The universe isFin (univSize + 1), hence nonempty by construction: complexity notions in this library read a problem only on nonempty finite structures, andFin (n + 1)is moreover already linearly ordered, which is what an ordered reduction needs (≤ᶠᵒ[≤]) with no order to encode.
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
- FirstOrder.Language.tupleIdx c [] = 0
- FirstOrder.Language.tupleIdx c (a :: l) = a + c * FirstOrder.Language.tupleIdx c l
Instances For
Dependency graph
The j-th digit of t in base c.
Equations
- FirstOrder.Language.digitAt c t j = t / c ^ j % c
Instances For
Dependency graph
Dependency graph
Dependency graph
A tuple of digits in base c numbers below c ^ length.
Dependency graph
The digits of the number of a tuple are the tuple back.
Dependency graph
Splitting a remainder along a product of moduli.
Dependency graph
The number of the tuple of the digits of v is v, up to the number
of digits taken. The converse roundtrip of
FirstOrder.Language.digitAt_tupleIdx.
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.
The symbol with a given number, together with its arity.
The number of a symbol.
Reading back the symbol with the number of a symbol gives it back.
Numbering the symbol with a given number gives that number back.
Instances For
Dependency graph
The arity of the symbol with a given number.
Instances For
Dependency graph
The symbol with a given number.
Instances For
Dependency graph
Dependency graph
Dependency graph
Dependency graph
The arity of a symbol, as read from its number, is its arity: the shape in which the dependency is discharged in practice.
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.
The tables of the relations, one row per symbol.
Instances For
Dependency graph
The size of the universe of a concrete finite structure.
Instances For
Dependency graph
The universe of a concrete finite structure: nonempty and linearly ordered by construction.
Instances For
Dependency graph
The table lookup: does the relation R hold of the tuple x?
Equations
Instances For
Dependency graph
Dependency graph
The structure a piece of data denotes.
Equations
- s.instStructure = { funMap := fun {n : ℕ} (f : L.Functions n) => isEmptyElim f, RelMap := fun {n : ℕ} (R : L.Relations n) (x : Fin n → s.Univ) => s.relMapBool R x = true }
Dependency graph
Dependency graph
Equations
- s.decidableRelMap R x = instDecidableEqBool (s.relMapBool R x) true
Dependency graph
Building a concrete structure from a table #
Reading a symbol through its number: a Boolean reading of relations,
applied to the symbol read back from a number, is the reading of the symbol
itself – the one place the arity dependency of
FirstOrder.Language.FinVocab has to be discharged.
Dependency graph
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
Dependency graph
The table is read back as it was written.
Dependency graph
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
The table of FirstOrder.Language.FinStruct.ofEquiv reads the relations of
the structure it was built from.
Dependency graph
The numbering used by FirstOrder.Language.FinStruct.ofEquiv is an
isomorphism onto the structure it builds.
Equations
- FirstOrder.Language.FinStruct.equivOfEquiv V k e = { toEquiv := e, map_fun' := ⋯, map_rel' := ⋯ }
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
Concrete finite structures are a Primcodable type: the object
ComputablePred and REPred are defined on.
Dependency graph
Dependency graph
Dependency graph
Dependency graph
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.
Instances For
Dependency graph
The concrete instances capture the problem: a finite nonempty structure is a yes-instance exactly when some – equivalently, any – numbering of it is. Isomorphism-invariance of a decision problem is what makes this true.
Dependency graph
Every finite nonempty structure is isomorphic to a concrete one.