Documentation

CslibFrontier.Computability.Complexity.Fagin.Verifier

Existential second-order definable classes are in NP #

The easy direction of Fagin's theorem Fagin, Theorem 6, Immerman, Proposition 7.6: for a fixed existential second-order sentence Φ = ∃ R₁ … Rₖ, φ over a vocabulary, the inputs encoding the finite structures satisfying Φ form a problem in NP. The certificate for an input of encoded length N is a bit string of length blocks * N ^ degree, where a layout (Cslib.Logic.ESO.Sentence.Layout) gives each relation variable its own block of N ^ degree bits and degree bounds the arities. The block of a relation variable is its truth table, indexed like the tables of the input by Cslib.Logic.tupleIndex; since the cardinality n of the structure is at most N, every tuple has a bit, and the unused bits of a block are ignored. Reading the blocks as relations (Cslib.Logic.ESO.Sentence.Layout.certRel) expands the decoded structure by the relation variables, and the verifier (Cslib.Logic.ESO.Sentence.Layout.verifier) checks that the input is well formed and evaluates the first-order part in the expansion. The evaluator (Cslib.Logic.ESO.Sentence.Layout.eval) recurses on the fixed formula and ranges over the n elements at each quantifier, so it is a polynomial-time program for each fixed sentence; fun_prop certifies it with the closure rules of Turing.MultiTapeTM.ComputableInPolyTime.

The sentence and the vocabulary are fixed parameters: the degree of the polynomial time bound depends on the quantifier depth and the arities of the sentence, and the number of relation symbols enters the length of the input. Malformed inputs are rejected by the verifier and are not in the problem. Which certificates are accepted depends on the layout; the problem does not. The converse direction, that every isomorphism-closed problem in NP is existential second-order definable, is not proved here.

Main definitions #

Main results #

References #

Layouts #

A certificate layout for Φ: a block number for each relation variable, and a bound on their arities. A certificate for an input of encoded length N has blocks * N ^ degree bits, block i holding the truth table of relation variable i.

  • blocks : ℕ

    The number of blocks.

  • block : Φ.Var ↪ Fin self.blocks

    The block of each relation variable.

  • degree : ℕ

    A bound on the arities of the relation variables.

  • arity_le (i : Φ.Var) : Φ.arity i ≤ self.degree
Instances For

    The polynomial giving the length of certificates in the encoded length of the input.

    def Cslib.Logic.ESO.Sentence.Layout.position {L : FirstOrder.Language} {Φ : Sentence L} (ℓ : Φ.Layout) (N : ℕ) (i : Φ.Var) (idx : ℕ) :

    The position of the bit of relation variable i at the tuple of index idx, in a certificate for an input of encoded length N.

    theorem Cslib.Logic.ESO.Sentence.Layout.position_injective {L : FirstOrder.Language} {Φ : Sentence L} (ℓ : Φ.Layout) (N : ℕ) {i j : Φ.Var} {idx idx' : ℕ} (h : idx < N ^ ℓ.degree) (h' : idx' < N ^ ℓ.degree) (he : ℓ.position N i idx = ℓ.position N j idx') :
    i = j ∧ idx = idx'

    Positions determine the relation variable and the index of the tuple.

    def Cslib.Logic.ESO.Sentence.Layout.certRel {L : FirstOrder.Language} {Φ : Sentence L} (ℓ : Φ.Layout) (n N : ℕ) (w : List Bool) (i : Φ.Var) :
    Set (Fin (Φ.arity i) → Fin n)

    The relations read from a certificate: relation variable i holds of a tuple when the bit at its position is set; missing bits read as false.

    theorem Cslib.Logic.ESO.Sentence.Layout.exists_certificate {L : FirstOrder.Language} {Φ : Sentence L} (ℓ : Φ.Layout) {n N : ℕ} (hn : n ≤ N) (hN : 0 < N) (R : (i : Φ.Var) → Set (Fin (Φ.arity i) → Fin n)) :
    ∃ (w : List Bool), w.length = Polynomial.eval N ℓ.polynomial ∧ ℓ.certRel n N w = R

    Every family of witness relations has a certificate of the prescribed polynomial length, provided the input-length parameter is positive and bounds the universe size. This is independent of the base language, so it also applies when the base has canonical numeric constants.

    The evaluator #

    @[instance_reducible]

    The expansion of the decoded structure by the relations read from a certificate.

    The position of a variable in the environment: bound variables are numbered, and a sentence has no free variables.

    The value of a term in an environment of bound variables; in a relational language, a term is a variable.

    The index of the tuple of values of a sequence of terms, by recursion on its length.

    def Cslib.Logic.ESO.Sentence.Layout.relBit {L : FirstOrder.Language} {Φ : Sentence L} (ℓ : Φ.Layout) (v : Vocabulary L) (a : EncodedStructure) (N : ℕ) (w : List Bool) {l : ℕ} (R : (L.sum (varLanguage Φ.arity)).Relations l) (idx : ℕ) :

    The bit of a relation symbol at a tuple index: read from the input for a symbol of the vocabulary, from the certificate for a relation variable.

    The evaluator of the first-order part on an input a of encoded length N, a certificate w, and an environment of bound variables: quantifiers range over the a.1 elements.

    The verifier: the input is well formed and the first-order part holds in the expansion of the decoded structure by the certificate relations.

    Correctness #

    theorem Cslib.Logic.ESO.Sentence.Layout.eval_eq_true_iff {L : FirstOrder.Language} {Φ : Sentence L} (ℓ : Φ.Layout) [L.IsRelational] {v : Vocabulary L} {a : EncodedStructure} {N : ℕ} {w : List Bool} {k : ℕ} (φ : (L.sum (varLanguage Φ.arity)).BoundedFormula Empty k) (xs : Fin k → Fin a.1) :
    ℓ.eval v a N w φ (List.ofFn fun (j : Fin k) => ↑(xs j)) = true ↔ φ.Realize default xs

    The evaluator decides truth of the first-order part in the expansion of the decoded structure by the certificate relations.

    The first-order part holds in the expansion by the certificate relations exactly when the evaluator accepts.

    theorem Cslib.Logic.ESO.Sentence.Layout.realize_iff_exists_certificate {L : FirstOrder.Language} {Φ : Sentence L} (ℓ : Φ.Layout) [L.IsRelational] {v : Vocabulary L} {a : EncodedStructure} {N : ℕ} (hn : a.1 ≤ N) (hN : 0 < N) :
    Φ.Realize (Fin a.1) ↔ ∃ (w : List Bool), w.length = ℓ.blocks * N ^ ℓ.degree ∧ ℓ.eval v a N w Φ.matrix [] = true

    A decoded structure satisfies the sentence exactly when some certificate is accepted, for certificate lengths computed from any positive N at least the cardinality.

    The verifier accepts an input with some certificate of the prescribed length exactly when the input is well formed and its decoded structure satisfies the sentence.

    The verifier, with the certificate lengths of the layout, verifies the query language of a class defined by the sentence.

    Polynomial time #

    The evaluator is polynomial-time for each fixed formula, by induction on the formula. The input type is generalized, as the body of a quantifier takes the current element as well.

    Membership in NP #

    The problem of a fixed existential second-order sentence is in NP: the inputs encoding the finite structures satisfying Φ, with respect to the encoding of structures of the vocabulary.

    Existential second-order definable classes are in NP (the easy direction of Fagin's theorem): the query language of a definable class of finite structures is in NP, with respect to the encoding of structures of any vocabulary of the language Fagin, Theorem 6, Immerman, Proposition 7.6.