Documentation

DescriptiveComplexity.Hierarchy

The polynomial hierarchy, defined by second-order alternation #

The levels Σₖᵖ/Πₖᵖ of the polynomial hierarchy for k ≥ 1 – in particular NP = Σ₁ᵖ and coNP = Π₁ᵖ – are defined here as ComplexityClasses, via Fagin's ([Fagin 1974][fagin1974generalized]) and Stockmeyer's ([Stockmeyer 1976][stockmeyer1976polynomial]) theorems: membership is second-order definability with k alternating quantifier blocks (DescriptiveComplexity.SigmaSODefinable / DescriptiveComplexity.PiSODefinable), and the closure of membership under (ordered) FO reductions is provided by the pullback theorems of DescriptiveComplexity.SecondOrderPull and DescriptiveComplexity.SecondOrderOrdered.

Hardness is defined cofinally: P is hard when every problem of the class reduces (by an ordered FO reduction) to every relational problem that P itself reduces to. For a problem over a relational vocabulary this is equivalent to the usual “everything in the class reduces to P” (DescriptiveComplexity.cofinalHard_iff, with per-class specializations DescriptiveComplexity.hard_sigmaP_succ_iff, DescriptiveComplexity.hard_piP_succ_iff and DescriptiveComplexity.hard_PTIME_iff), and the formulation makes hardness travel forward along reductions even through non-relational vocabularies.

Level 0 is DescriptiveComplexity.PTIME, polynomial time, defined here as definability in the Horn fragment SO-Horn of existential second-order logic ([Grädel 1992][gradel1992capturing]) – the same move as defining NP by Σ₁-definability, and equally a definition rather than an axiom: the library declares no axioms, every theorem depending on nothing beyond Lean's standard propext, Classical.choice and Quot.sound (check with #print axioms). The order-free characterization of PTIME is the Chandra–Harel/Gurevich problem and is not needed here: SO-Horn definability, like ordered FO reductions, is stated over ordered structures.

What level 0 does and does not give. It is a genuine class, closed under (ordered) FO reductions by the shape-preserving pullback of DescriptiveComplexity.SecondOrderHornPull, and Πₖᵖ is the complements of Σₖᵖ at every level (DescriptiveComplexity.mem_piP_iff) – at level 0 by definition, above it by the quantifier duality.

All four inclusions of level 0 into level 1 are proved – PTIMENP, PTIMEcoNP and their complements (DescriptiveComplexity.PTIME_subset_NP, DescriptiveComplexity.PTIME_subset_coNP, DescriptiveComplexity.coPTIME_subset_NP, DescriptiveComplexity.coPTIME_subset_coNP); they live downstream with HORN-SAT, since they go through the Horn discharge and, for the two crossing ones, through the certificate of Horn unsatisfiability of DescriptiveComplexity.Problems.HornSat.Unsat.

That the two zeroth levels coincidePiP 0 = SigmaP 0, polynomial time closed under complement – is proved downstream, as DescriptiveComplexity.piP_zero_eq: it is Grädel's capture theorem at level 0, and its route is the logic-to-logic equivalence of SO-Horn with FO(LFP) (DescriptiveComplexity.lfpDefinable_iff_sigmaSOHornDefinable, in DescriptiveComplexity.FixedPointHorn), a full logic being closed under negation by construction; no machine model is involved.

The level inclusions above 0, the duality Πₖᵖ = co-Σₖᵖ and the class PH are all proved (DescriptiveComplexity.sigmaP_subset_sigmaP_succ, DescriptiveComplexity.mem_piP_iff…).

Congruence of definability in the problem #

Σₖ-definability only depends on the finite instances of a problem.

Πₖ-definability only depends on the finite instances of a problem.

An ordered FO reduction can be transported along an agreement of the source problems on finite structures.

Equations
Instances For

    Cofinal hardness #

    Hardness for a collection of problems, cofinally: every problem of the collection reduces to every relational problem that P reduces to. For P over a relational vocabulary this is the usual notion (see DescriptiveComplexity.hard_sigmaP_succ_iff); this formulation is closed under reductions out of arbitrary vocabularies.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem DescriptiveComplexity.CofinalHard.of_foReduction {Mem : {L₀ : FirstOrder.Language} → [inst : L₀.IsRelational] → DecisionProblem L₀Prop} {L₁ L₂ : FirstOrder.Language} [L₁.IsRelational] [L₂.IsRelational] {P : DecisionProblem L₁} {Q : DecisionProblem L₂} (f : FOReduction P Q) (hP : CofinalHard (fun {L₀ : FirstOrder.Language} [L₀.IsRelational] => Mem) P) :
      CofinalHard (fun {L₀ : FirstOrder.Language} [L₀.IsRelational] => Mem) Q
      theorem DescriptiveComplexity.CofinalHard.of_orderedReduction {Mem : {L₀ : FirstOrder.Language} → [inst : L₀.IsRelational] → DecisionProblem L₀Prop} {L₁ L₂ : FirstOrder.Language} [L₁.IsRelational] [L₂.IsRelational] {P : DecisionProblem L₁} {Q : DecisionProblem L₂} (f : OrderedFOReduction P Q) (hP : CofinalHard (fun {L₀ : FirstOrder.Language} [L₀.IsRelational] => Mem) P) :
      CofinalHard (fun {L₀ : FirstOrder.Language} [L₀.IsRelational] => Mem) Q
      theorem DescriptiveComplexity.CofinalHard.of_relOrderedReduction {Mem : {L₀ : FirstOrder.Language} → [inst : L₀.IsRelational] → DecisionProblem L₀Prop} {L₁ L₂ : FirstOrder.Language} [L₁.IsRelational] [L₂.IsRelational] {P : DecisionProblem L₁} {Q : DecisionProblem L₂} (f : RelOrderedFOReduction P Q) (hP : CofinalHard (fun {L₀ : FirstOrder.Language} [L₀.IsRelational] => Mem) P) :
      CofinalHard (fun {L₀ : FirstOrder.Language} [L₀.IsRelational] => Mem) Q
      theorem DescriptiveComplexity.CofinalHard.congr {Mem : {L₀ : FirstOrder.Language} → [inst : L₀.IsRelational] → DecisionProblem L₀Prop} {L₁ : FirstOrder.Language} [L₁.IsRelational] {P P' : DecisionProblem L₁} (h : ∀ (A : Type) [inst : L₁.Structure A] [Finite A], P.Holds A P'.Holds A) (hP : CofinalHard (fun {L₀ : FirstOrder.Language} [L₀.IsRelational] => Mem) P) :
      CofinalHard (fun {L₀ : FirstOrder.Language} [L₀.IsRelational] => Mem) P'
      theorem DescriptiveComplexity.cofinalHard_iff {L : FirstOrder.Language} [L.IsRelational] (Mem : {L₀ : FirstOrder.Language} → [inst : L₀.IsRelational] → DecisionProblem L₀Prop) (P : DecisionProblem L) :
      CofinalHard (fun {L₀ : FirstOrder.Language} [L₀.IsRelational] => Mem) P ∀ {L'' : FirstOrder.Language} [inst : L''.IsRelational] (Q : DecisionProblem L''), Mem QNonempty (RelOrderedFOReduction Q P)

      Over a relational vocabulary, cofinal hardness is the usual notion: every problem of the collection reduces to P itself. This holds whatever the collection is – the proof only uses reflexivity and transitivity of reductions – so the specializations to the individual classes below (DescriptiveComplexity.hard_sigmaP_succ_iff, DescriptiveComplexity.hard_piP_succ_iff, DescriptiveComplexity.hard_PTIME_iff) are corollaries by definitional unfolding.

      The left-to-right direction is what a user of a hardness result needs, to extract an actual reduction; it is where relationality of P is used, to instantiate the cofinal quantifier at P itself.

      Classes defined by their members #

      def DescriptiveComplexity.ComplexityClass.ofMem (Mem : {L₀ : FirstOrder.Language} → [inst : L₀.IsRelational] → DecisionProblem L₀Prop) (mem_of_foReduction : ∀ {L₁ L₂ : FirstOrder.Language} [inst : L₁.IsRelational] [inst_1 : L₂.IsRelational] {P : DecisionProblem L₁} {Q : DecisionProblem L₂} (a : FOReduction P Q), Mem QMem P) (mem_of_orderedReduction : ∀ {L₁ L₂ : FirstOrder.Language} [inst : L₁.IsRelational] [inst_1 : L₂.IsRelational] {P : DecisionProblem L₁} {Q : DecisionProblem L₂} (a : OrderedFOReduction P Q), Mem QMem P) (mem_congr_finite : ∀ {L₁ : FirstOrder.Language} [inst : L₁.IsRelational] {P Q : DecisionProblem L₁}, (∀ (A : Type) [inst_1 : L₁.Structure A] [Finite A], P.Holds A Q.Holds A) → (Mem P Mem Q)) :

      The complexity class with a given membership predicate, hardness being cofinal hardness for it (DescriptiveComplexity.CofinalHard) – the shape of every logically-defined class of this library. Only the three membership obligations have to be supplied: the hardness half of the closure requirements is discharged uniformly, by DescriptiveComplexity.CofinalHard.of_foReduction and its siblings.

      A class whose hardness is not cofinal hardness for its own members is built by hand instead: DescriptiveComplexity.ComplexityClass.empty, where hardness is outright trivial, and DescriptiveComplexity.PH, whose hardness is stated level by level (an equivalent statement, since membership is the union of the levels, but not a definitional one).

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

        The complement of a class #

        The complement of a complexity class: the problems whose complement belongs to it – the “co-” operator. Closure under reductions is inherited, since a reduction complements (DescriptiveComplexity.FOReduction.compl).

        Equations
        Instances For

          The levels of the hierarchy #

          The class Σₖ₊₁ᵖ, defined by second-order definability with k + 1 alternating blocks starting existentially.

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

            The class Πₖ₊₁ᵖ, defined by second-order definability with k + 1 alternating blocks starting universally.

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

              Polynomial time, by the Horn fragment #

              The class PTIME: the problems definable in the Horn fragment SO-Horn of existential second-order logic ([Grädel 1992][gradel1992capturing]), which captures polynomial time on ordered structures. It is a bona fide DescriptiveComplexity.ComplexityClass because SO-Horn definability is closed under (ordered) first-order reductions – the Horn shape survives the pullback, see DescriptiveComplexity.SecondOrderHornPull.

              This is level 0 of the hierarchy below (DescriptiveComplexity.SigmaP, DescriptiveComplexity.PiP), and it has a complete problem, HORN-SAT (DescriptiveComplexity.HORNSAT_PTIME_complete). That the class is closed under complement – PiP 0 = SigmaP 0 – is DescriptiveComplexity.piP_zero_eq, through the equivalence with FO(LFP).

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

                The hierarchy #

                The Σₖᵖ levels of the polynomial hierarchy: polynomial time at level 0 (DescriptiveComplexity.PTIME, defined by the Horn fragment SO-Horn), second-order definability with k alternations above.

                Equations
                Instances For

                  The Πₖᵖ levels of the polynomial hierarchy; level 0 is co-polynomial time, the complements of the SO-Horn definable problems. That this coincides with DescriptiveComplexity.PTIME is the closure of polynomial time under complement, DescriptiveComplexity.piP_zero_eq – see the module docstring.

                  Equations
                  Instances For
                    @[reducible, inline]

                    NP is Σ₁ᵖ: by definition, the existential-second-order definable problems (Fagin's theorem).

                    Equations
                    Instances For
                      @[reducible, inline]

                      coNP is Π₁ᵖ: the universal-second-order definable problems.

                      Equations
                      Instances For

                        Πₖᵖ consists of the complements of the Σₖᵖ problems, at every level: by definition at level 0, and by the quantifier duality DescriptiveComplexity.piSODefinable_iff_compl above from level 1 on.

                        (That moreover PiP 0 = SigmaP 0 – polynomial time closed under complement – is DescriptiveComplexity.piP_zero_eq: complementing a Horn program needs its least model computed inside the fragment, which is what the translation from FO(LFP) provides.)

                        Σₖ₊₁ᵖ ⊆ Σₖ₊₂ᵖ, by padding. (The level-0 inclusions are proved downstream with HORN-SAT, which their proofs go through: DescriptiveComplexity.PTIME_subset_NP and friends. Uniform monotonicity, j ≤ k → Σⱼᵖ ⊆ Σₖᵖ, therefore also lives there: DescriptiveComplexity.sigmaP_mono.)

                        Σₖ₊₁ᵖ ⊆ Πₖ₊₂ᵖ.

                        Πₖ₊₁ᵖ ⊆ Σₖ₊₂ᵖ.

                        Πₖ₊₁ᵖ ⊆ Πₖ₊₂ᵖ.

                        The polynomial hierarchy: union of all the levels. A problem is PH-hard if it is hard for every level.

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

                          Πₖ₊₁ᵖ ⊆ PH. (At level 0 this is DescriptiveComplexity.piP_zero_subset_PH, which needs PTIMENP and so lives downstream, with HORN-SAT.)

                          A problem's complement is in coNP iff the problem is in NP.

                          Hardness over relational vocabularies #

                          Over a relational vocabulary, cofinal Σₖ₊₁ᵖ-hardness is the usual notion: every Σₖ₊₁-definable problem reduces to P.

                          Over a relational vocabulary, cofinal Πₖ₊₁ᵖ-hardness is the usual notion: every Πₖ₊₁-definable problem reduces to P.

                          Over a relational vocabulary, cofinal PTIME-hardness is the usual notion: every SO-Horn definable problem reduces to P.