Documentation

DescriptiveComplexity.InductiveCounting.Machine

The inductive-counting machine, abstractly #

The combinatorial heart of Immerman–Szelepcsényi (Immerman 1988, Szelepcsényi 1988): a nondeterministic walk on configurations that reaches an accepting configuration exactly when no target is reachable from a source in a finite graph.

Everything here is about an abstract finite linearly ordered node type V with an edge relation E and source and target predicates S, T; nothing is first-order yet. DescriptiveComplexity.InductiveCounting.Sound and DescriptiveComplexity.InductiveCounting.Complete prove the two directions, and DescriptiveComplexity.TransitiveClosureCompl runs the whole machine inside a single TC by realizing each configuration as a mode together with a tuple of elements.

The algorithm #

Write Rset d for the set of nodes reachable from a source in at most d steps. The counts |Rset d| are computed by inductive counting: knowing |Rset d| exactly, one can certify, for a given node v, whether v ∈ Rset (d+1), by running over all nodes u in order, guessing which belong to Rset d, certifying each guess by a path of length at most d from a source, and checking at the end that exactly |Rset d| of them were certified – which forces the guessed set to be Rset d itself. Counting the v's that pass gives |Rset (d+1)|. The machine accepts when |Rset (d+1)| = |Rset d|, at which point the reachable set is Rset d; since every certified node is checked not to be a target, acceptance means no target is reachable.

The registers #

The machine has eight registers, each holding an element of WithBot V: a node, or a count read through DescriptiveComplexity.orank (so ⊥ is the count 0 and the count m is the m-th value of WithBot V). This uniformity is what lets a register be stored, in the first-order realization, as one tuple of elements together with a finite mode.

Layered reachability #

def DescriptiveComplexity.InductiveCounting.RInLe {V : Type} (E : V → V → Prop) :
ℕ → V → V → Prop

RInLe E n a b: the node b is reachable from a along E in at most n steps.

Equations
Instances For
    Dependency graph
    @[simp]
    theorem DescriptiveComplexity.InductiveCounting.rInLe_zero {V : Type} {E : V → V → Prop} {a b : V} :
    RInLe E 0 a b ↔ a = b
    Dependency graph
    theorem DescriptiveComplexity.InductiveCounting.RInLe.step {V : Type} {E : V → V → Prop} {n : ℕ} {a b : V} (h : RInLe E n a b) :
    RInLe E (n + 1) a b
    Dependency graph
    theorem DescriptiveComplexity.InductiveCounting.RInLe.mono {V : Type} {E : V → V → Prop} {n m : ℕ} {a b : V} (hnm : n ≤ m) (h : RInLe E n a b) :
    RInLe E m a b
    Dependency graph

    Registers, slots and atomic constraints #

    @[reducible, inline]

    The eight registers of the machine.

    Equations
    Instances For
      Dependency graph

      The stage counter: the current layer index d.

      Equations
      Instances For
        Dependency graph

        The count of the current layer, |Rset d|.

        Equations
        Instances For
          Dependency graph

          The count of the next layer being built, |Rset (d+1)|.

          Equations
          Instances For
            Dependency graph
            Dependency graph

            The count of nodes certified in the inner loop.

            Equations
            Instances For
              Dependency graph
              Dependency graph

              The node walked backwards along a certifying path.

              Equations
              Instances For
                Dependency graph

                The countdown of the certifying path's remaining length.

                Equations
                Instances For
                  Dependency graph
                  @[reducible, inline]

                  A slot: a register, read either in the current configuration (false) or in the next one (true).

                  Equations
                  Instances For
                    Dependency graph
                    @[reducible, inline]

                    The slot reading a register in the current configuration.

                    Equations
                    Instances For
                      Dependency graph
                      @[reducible, inline]

                      The slot reading a register in the next configuration.

                      Equations
                      Instances For
                        Dependency graph

                        An atomic constraint relating the registers of two consecutive configurations. Each one is realized, in the first-order construction, by one formula over two tuples of variables.

                        • eqR (a b : Slot) : VAtom

                          Two slots hold the same value.

                        • neqR (a b : Slot) : VAtom

                          Two slots hold different values.

                        • succR (a b : Slot) : VAtom

                          The second slot holds the immediate successor of the first.

                        • edge (a b : Slot) : VAtom

                          The two slots hold nodes joined by an edge.

                        • nedge (a b : Slot) : VAtom

                          The two slots do not hold nodes joined by an edge.

                        • srcR (a : Slot) : VAtom

                          The slot holds a source node.

                        • nsrcR (a : Slot) : VAtom

                          The slot does not hold a source node.

                        • tgtR (a : Slot) : VAtom

                          The slot holds a target node.

                        • ntgtR (a : Slot) : VAtom

                          The slot does not hold a target node.

                        • botNode (a : Slot) : VAtom

                          The slot holds the least node.

                        • topNode (a : Slot) : VAtom

                          The slot holds the greatest node.

                        • isZero (a : Slot) : VAtom

                          The slot holds the count zero.

                        Instances For
                          Dependency graph

                          Configurations and the transition table #

                          The control phases of the machine.

                          • initCount : Phase

                            Scanning all nodes to count the sources, that is |Rset 0|.

                          • inner : Phase

                            The inner loop: at node u, about to certify it or to skip it.

                          • walk : Phase

                            Walking backwards along a certifying path for u.

                          • certDone : Phase

                            The certifying path is complete: count u in and test it against v.

                          • check : Phase

                            The inner loop is over: check that the count matches |Rset d|.

                          • stageEnd : Phase

                            The outer loop is over: c2 holds |Rset (d+1)|.

                          • accept : Phase

                            The accepting phase.

                          Instances For
                            Dependency graph
                            Dependency graph
                            Dependency graph

                            A configuration: a phase, the flag recording whether the current outer node has been found in the next layer, and the eight registers.

                            • phase : Phase

                              The control phase.

                            • flag : Bool

                              The flag: v has been seen to lie in the next layer.

                            • regs : Reg → WithBot V

                              The registers.

                            Instances For
                              Dependency graph

                              The transition table: a list of alternatives, each a list of atomic constraints, for every pair of control states (a phase and the flag). The algorithm of the module docstring is entirely contained here.

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

                                The semantics of the machine #

                                def DescriptiveComplexity.InductiveCounting.EW {V : Type} (E : V → V → Prop) (a b : WithBot V) :

                                Two slots hold nodes joined by an edge.

                                Equations
                                Instances For
                                  Dependency graph

                                  A slot holds a node satisfying a predicate.

                                  Equations
                                  Instances For
                                    Dependency graph

                                    The value a slot reads, from the current and the next register vectors.

                                    Equations
                                    Instances For
                                      Dependency graph
                                      def DescriptiveComplexity.InductiveCounting.VAtom.Holds {V : Type} [LinearOrder V] (E : V → V → Prop) (S T : V → Prop) (x y : Reg → WithBot V) :

                                      What an atomic constraint asserts about two register vectors.

                                      Equations
                                      Instances For
                                        Dependency graph
                                        def DescriptiveComplexity.InductiveCounting.Sat {V : Type} [LinearOrder V] (E : V → V → Prop) (S T : V → Prop) (x y : Reg → WithBot V) (l : List VAtom) :

                                        All the constraints of an alternative hold.

                                        Equations
                                        Instances For
                                          Dependency graph
                                          @[simp]
                                          theorem DescriptiveComplexity.InductiveCounting.sat_nil {V : Type} [LinearOrder V] (E : V → V → Prop) (S T : V → Prop) (x y : Reg → WithBot V) :
                                          Sat E S T x y []
                                          Dependency graph
                                          @[simp]
                                          theorem DescriptiveComplexity.InductiveCounting.sat_cons {V : Type} [LinearOrder V] (E : V → V → Prop) (S T : V → Prop) {a : VAtom} {l : List VAtom} (x y : Reg → WithBot V) :
                                          Sat E S T x y (a :: l) ↔ VAtom.Holds E S T x y a ∧ Sat E S T x y l
                                          Dependency graph
                                          def DescriptiveComplexity.InductiveCounting.CfgStep {V : Type} [LinearOrder V] (E : V → V → Prop) (S T : V → Prop) (s s' : Cfg V) :

                                          One step of the machine: some alternative of the table entry for the two control states is satisfied by the two register vectors.

                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          Instances For
                                            Dependency graph
                                            @[reducible, inline]
                                            abbrev DescriptiveComplexity.InductiveCounting.CfgReach {V : Type} [LinearOrder V] (E : V → V → Prop) (S T : V → Prop) :
                                            Cfg V → Cfg V → Prop

                                            Reachability between configurations.

                                            Equations
                                            Instances For
                                              Dependency graph

                                              The initial configurations: the source scan is about to start, with a zero count and the outer register at the least node.

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