Documentation

DescriptiveComplexity.HeadLex

Counting on a block of heads #

A deterministic machine cannot guess a tuple: it has to walk the tuples one at a time. This file gives it the odometer.

DescriptiveComplexity.HeadProgram.lexNextP replaces the tuple held on a block of heads by its lexicographic successor, and exits false when there is none – when the tuple is the greatest. It is the same chain a schoolchild uses to add one: walk the positions from the last, and at the first position that is not at its greatest value, step that head and reset the ones after it.

The one thing a machine cannot do directly is ask whether a head is at the greatest element: that is not a quantifier-free fact of one head. So the block comes with a marker head parked at the greatest element, and the test is the atom "these two heads are equal" – the same device the quantifier sweep of DescriptiveComplexity.HeadEval uses, here shared by every position of the block.

Accordingly the relation DescriptiveComplexity.HeadProgram.lexRel that the gadget runs is stated in terms of the marker's value, not of maximality: it is an honest description of what the machine does whatever the marker holds. Where the marker is known to be at the greatest element, DescriptiveComplexity.HeadProgram.tupSucc_of_lexRel turns it into DescriptiveComplexity.TupSucc, the coordinatewise description of covering in Lex (Fin n → A), and the walk becomes a walk along a finite linear order like any other.

The control graph of an increment #

The control nodes of a lexicographic increment on a block of n heads: test j has found the positions from j on to be at the marker and is about to look at position j - 1; bump j steps position j and resets the rest.

  • test {n : } (j : Fin (n + 1)) : LexNode n

    Positions from j on are at the marker; about to test position j - 1.

  • bump {n : } (j : Fin n) : LexNode n

    Step position j, and reset the positions after it.

Instances For
    Dependency graph
    Dependency graph

    The position a test node is about to look at, if it has not run out.

    Equations
    Instances For
      Dependency graph

      The test node that follows, one position down.

      Equations
      Instances For
        Dependency graph
        Dependency graph
        theorem DescriptiveComplexity.HeadProgram.testPos_eq_some {n : } {j : Fin (n + 1)} {p : } (h : j = p + 1) (hp : p < n) :
        Dependency graph
        theorem DescriptiveComplexity.HeadProgram.testDown_val {n : } {j : Fin (n + 1)} {p : } (h : j = p + 1) :
        (testDown j) = p
        Dependency graph

        The wiring of an increment: at the marker, look one position down; away from it, step that position.

        Equations
        Instances For
          Dependency graph
          noncomputable def DescriptiveComplexity.HeadProgram.bumpMoves {K n : } (blk : Fin nFin K) (j : Fin n) :
          Fin KHeadMove K

          The moves of an increment: step position j of the block and send the positions after it to the least element.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            Dependency graph
            noncomputable def DescriptiveComplexity.HeadProgram.lexFam {L : FirstOrder.Language} {K n : } (blk : Fin nFin K) (mk : Fin K) :

            The fragments of an increment.

            Equations
            Instances For
              Dependency graph
              noncomputable def DescriptiveComplexity.HeadProgram.lexNextP {L : FirstOrder.Language} {K n : } (blk : Fin nFin K) (mk : Fin K) :

              The odometer: replace the tuple on the block by its lexicographic successor, exiting false when every position is at the marker.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                Dependency graph
                def DescriptiveComplexity.HeadProgram.lexRel {K : } {A : Type} [LinearOrder A] {n : } (blk : Fin nFin K) (mk : Fin K) (prot : ) :
                (Fin KA)Bool(Fin KA)Prop

                What an increment runs, stated by the marker's value rather than by maximality: either some position is away from the marker – the last such one is stepped and the positions after it are reset – or all of them are at it and the increment fails.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  Dependency graph
                  def DescriptiveComplexity.HeadProgram.lexFamRel {K : } {A : Type} [LinearOrder A] {n : } (blk : Fin nFin K) (mk : Fin K) (prot : ) :
                  LexNode n(Fin KA)Bool(Fin KA)Prop

                  The relations the fragments of an increment run.

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

                    What the increment runs #

                    theorem DescriptiveComplexity.HeadProgram.runs_lexFam {L : FirstOrder.Language} {K : } {A : Type} [L.Structure A] [LinearOrder A] {n : } (blk : Fin nFin K) (mk : Fin K) (prot : ) (hblk : ∀ (i : Fin n), (blk i) < prot) (c : LexNode n) :
                    (lexFam blk mk c).Runs A prot (lexFamRel blk mk prot c)
                    Dependency graph
                    theorem DescriptiveComplexity.HeadProgram.headLocal2_lexFamRel {K : } {A : Type} [LinearOrder A] {n : } (blk : Fin nFin K) (mk : Fin K) (prot : ) (hblk : ∀ (i : Fin n), (blk i) < prot) (hmk : mk < prot) (c : LexNode n) :
                    HeadLocal2 prot (lexFamRel blk mk prot c)
                    Dependency graph
                    theorem DescriptiveComplexity.HeadProgram.lexRel_local {K : } {A : Type} [LinearOrder A] {n : } (blk : Fin nFin K) (mk : Fin K) (prot : ) (hblk : ∀ (i : Fin n), (blk i) < prot) (hmk : mk < prot) :
                    HeadLocal2 prot (lexRel blk mk prot)
                    Dependency graph

                    The walk of an increment #

                    def DescriptiveComplexity.HeadProgram.lexRelFrom {K : } {A : Type} [LinearOrder A] {n : } (blk : Fin nFin K) (mk : Fin K) (prot jj : ) :
                    (Fin KA)Bool(Fin KA)Prop

                    What the increment runs once the positions from jj on are known to be at the marker: the stepped position is one of those left.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      Dependency graph
                      theorem DescriptiveComplexity.HeadProgram.lexRelFrom_all {K : } {A : Type} [LinearOrder A] {n : } (blk : Fin nFin K) (mk : Fin K) (prot : ) {x : Fin KA} {b : Bool} {y : Fin KA} :
                      lexRelFrom blk mk prot n x b y lexRel blk mk prot x b y
                      Dependency graph
                      theorem DescriptiveComplexity.HeadProgram.lexRelFrom_mono {K : } {A : Type} [LinearOrder A] {n : } (blk : Fin nFin K) (mk : Fin K) (prot : ) {jj jj' : } (h : jj jj') {x : Fin KA} {b : Bool} {y : Fin KA} (hr : lexRelFrom blk mk prot jj x b y) :
                      lexRelFrom blk mk prot jj' x b y
                      Dependency graph
                      theorem DescriptiveComplexity.HeadProgram.lexRelFrom_local {K : } {A : Type} [LinearOrder A] {n : } (blk : Fin nFin K) (mk : Fin K) (prot : ) (hblk : ∀ (i : Fin n), (blk i) < prot) (hmk : mk < prot) (jj : ) :
                      HeadLocal2 prot (lexRelFrom blk mk prot jj)
                      Dependency graph
                      def DescriptiveComplexity.HeadProgram.LexExit {K : } {A : Type} [LinearOrder A] {n : } (blk : Fin nFin K) (mk : Fin K) (prot jj : ) (hjj : jj < n + 1) (x : Fin KA) (b : Bool) (y : Fin KA) :

                      Abbreviation for the walk of an increment.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        Dependency graph
                        theorem DescriptiveComplexity.HeadProgram.lexSound {K : } {A : Type} [LinearOrder A] {n : } {blk : Fin nFin K} {mk : Fin K} {prot : } (hinj : Function.Injective blk) (hblk : ∀ (i : Fin n), (blk i) < prot) (hmk : mk < prot) (jj : ) (hjj : jj < n + 1) (x : Fin KA) :
                        (∀ (i : Fin n), jj ix (blk i) = x mk)∀ (b : Bool) (y : Fin KA), LexExit blk mk prot jj hjj x b ylexRelFrom blk mk prot jj x b y

                        Soundness of the increment: every exit is the one the relation describes.

                        Dependency graph
                        noncomputable def DescriptiveComplexity.HeadProgram.bumpTuple {K : } {A : Type} {n : } (blk : Fin nFin K) (p : Fin n) (x y : Fin KA) :
                        Fin KA

                        The tuple an increment produces at position p: the stepped and reset positions taken from the outcome, everything else left where it was.

                        Equations
                        Instances For
                          Dependency graph
                          theorem DescriptiveComplexity.HeadProgram.bumpTuple_at {K : } {A : Type} {n : } (blk : Fin nFin K) (p : Fin n) (x y : Fin KA) :
                          bumpTuple blk p x y (blk p) = y (blk p)
                          Dependency graph
                          theorem DescriptiveComplexity.HeadProgram.bumpTuple_after {K : } {A : Type} {n : } (blk : Fin nFin K) {p i : Fin n} (hi : p < i) (x y : Fin KA) (hinj : Function.Injective blk) :
                          bumpTuple blk p x y (blk i) = y (blk i)
                          Dependency graph
                          theorem DescriptiveComplexity.HeadProgram.bumpTuple_before {K : } {A : Type} {n : } (blk : Fin nFin K) {p i : Fin n} (hi : i < p) (x y : Fin KA) (hinj : Function.Injective blk) :
                          bumpTuple blk p x y (blk i) = x (blk i)
                          Dependency graph
                          theorem DescriptiveComplexity.HeadProgram.bumpTuple_out {K : } {A : Type} {n : } (blk : Fin nFin K) (p : Fin n) (x y : Fin KA) {h : Fin K} (hh : ∀ (i : Fin n), h blk i) :
                          bumpTuple blk p x y h = x h
                          Dependency graph
                          theorem DescriptiveComplexity.HeadProgram.lexComplete {K : } {A : Type} [LinearOrder A] {n : } {blk : Fin nFin K} {mk : Fin K} {prot : } (hinj : Function.Injective blk) (_hblk : ∀ (i : Fin n), (blk i) < prot) (_hmk : mk < prot) (jj : ) (hjj : jj < n + 1) (x : Fin KA) :
                          (∀ (i : Fin n), jj ix (blk i) = x mk)∀ (b : Bool) (y : Fin KA), lexRelFrom blk mk prot jj x b y∃ (y' : Fin KA), HeadAgree prot y y' LexExit blk mk prot jj hjj x b y'

                          Completeness of the increment: the outcome the relation describes is reached.

                          Dependency graph

                          The odometer #

                          theorem DescriptiveComplexity.HeadProgram.runs_lexNextP {L : FirstOrder.Language} {K : } {A : Type} [L.Structure A] [LinearOrder A] {n : } {blk : Fin nFin K} {mk : Fin K} {prot : } (hinj : Function.Injective blk) (hblk : ∀ (i : Fin n), (blk i) < prot) (hmk : mk < prot) :
                          (lexNextP blk mk).Runs A prot (lexRel blk mk prot)

                          What the odometer runs: the lexicographic successor of the tuple on the block, read through the marker.

                          Dependency graph
                          Dependency graph

                          Reading the increment as a lexicographic step #

                          theorem DescriptiveComplexity.HeadProgram.tupSucc_of_lexRel {K : } {A : Type} [LinearOrder A] {n : } {blk : Fin nFin K} {mk : Fin K} {prot : } {x y : Fin KA} (hmax : ∀ (a : A), a x mk) (h : lexRel blk mk prot x true y) :
                          TupSucc (fun (i : Fin n) => x (blk i)) fun (i : Fin n) => y (blk i)

                          Where the marker holds the greatest element, a successful increment is the lexicographic successor.

                          Dependency graph
                          theorem DescriptiveComplexity.HeadProgram.isTop_of_lexRel {K : } {A : Type} [LinearOrder A] {n : } {blk : Fin nFin K} {mk : Fin K} {prot : } {x y : Fin KA} (hmax : ∀ (a : A), a x mk) (h : lexRel blk mk prot x false y) (i : Fin n) (a : A) :
                          a x (blk i)

                          Where the marker holds the greatest element, a failed increment says the tuple was the greatest.

                          Dependency graph
                          theorem DescriptiveComplexity.HeadProgram.exists_lexRel_succ {K : } {A : Type} [LinearOrder A] {n : } {blk : Fin nFin K} {mk : Fin K} {prot : } {x : Fin KA} [Finite A] (hinj : Function.Injective blk) (hmax : ∀ (a : A), a x mk) (hnotTop : ¬∀ (i : Fin n) (a : A), a x (blk i)) :
                          ∃ (y : Fin KA), lexRel blk mk prot x true y (TupSucc (fun (i : Fin n) => x (blk i)) fun (i : Fin n) => y (blk i)) ∀ (j : Fin K), j < prot(∀ (i : Fin n), j blk i)y j = x j

                          The increment can always be taken where the tuple is not the greatest: the outcome the relation describes exists.

                          Dependency graph
                          theorem DescriptiveComplexity.HeadProgram.lexRel_top {K : } {A : Type} [LinearOrder A] {n : } {blk : Fin nFin K} {mk : Fin K} {prot : } {x : Fin KA} (hmax : ∀ (a : A), a x mk) (hall : ∀ (i : Fin n) (a : A), a x (blk i)) :
                          lexRel blk mk prot x false x

                          The increment fails exactly at the greatest tuple, and then leaves everything alone.

                          Dependency graph
                          theorem DescriptiveComplexity.HeadProgram.agree_of_lexRel {K : } {A : Type} [LinearOrder A] {n : } {blk : Fin nFin K} {mk : Fin K} {prot : } {x y : Fin KA} (h : lexRel blk mk prot x false y) :
                          HeadAgree prot x y

                          A failed increment leaves the heads where they were.

                          Dependency graph