Documentation

CslibFrontier.Computability.Complexity.Classes.Space.TQBF.Evaluation

Evaluating quantified Boolean formulas with an explicit stack #

A formula is evaluated by reading its tokens in prefix order (Cslib.Logic.PL.QBF.tokens) with an explicit stack of frames. A frame records an operator whose operands are being evaluated: its token, the value of its first operand once it has returned, and the tokens following the operator. One total step function (Cslib.Complexity.TQBF.step) either reads a token or returns a value:

So the stack is the call stack of the recursive evaluation, and the environment of the recursion is read off the quantifier frames (Cslib.Complexity.TQBF.assignment): during its first pass a quantifier over v sets v to false, during its second pass to true. Every token of the formula is read at least once, so the flag records whether every variable occurrence is bound.

A call on a formula φ returns to the same stack, with the value of φ under the assignment of the stack and the flag updated by the closedness of φ relative to the stack, within Cslib.Complexity.TQBF.callSteps φ < 4 ^ φ.tokens.length steps (Cslib.Complexity.TQBF.exists_iterate_step_call). The evaluator (Cslib.Complexity.TQBF.evaluate) runs the machine from the empty stack for 2 ^ (encQBF φ).length steps and decides TQBF (Cslib.Complexity.TQBF.evaluate_eq_true_iff).

Along every run, the input is a suffix of the tokens of the formula, every frame stores a token of the formula and a suffix of its tokens, and the suffixes stored in the stack are strictly nested, so the stack is no deeper than the number of tokens (Cslib.Complexity.TQBF.Good, Cslib.Complexity.TQBF.good_iterate_step). The time and space of the evaluator on multi-tape machines are in Cslib.Computability.Complexity.Classes.Space.TQBF.Membership.

Main definitions #

Main results #

References #

The stack machine #

A frame of the stack: an operator token whose operands are being evaluated, the value of its first operand (for a quantifier, of its first pass) once it has returned, and the tokens following the operator; for a quantifier, these are its body followed by the rest of the input, to which the second pass rewinds.

Instances For

    The state of the machine.

    • The tokens still to be read.

    • stack : List Frame

      The frames of the operators in progress, the innermost first.

    • value : Option Bool

      The value being returned, or none when the next token is to be read.

    • ok : Bool

      Whether every variable read so far was bound by a quantifier frame.

    Instances For

      Whether a frame is a quantifier over v.

      Instances For

        The value of v given by the innermost quantifier frame over v: false during its first pass, true during its second; none when no frame quantifies over v.

        Instances For

          The assignment of a stack, false on the variables it does not bind.

          Instances For

            One step of the evaluator. See the module docstring for the cases.

            Instances For

              Whether every free variable of φ is bound by a quantifier frame of the stack.

              Instances For

                The number of steps of a call on a formula: one step to read each token, and one step to return into each operator for each of its operands or passes.

                Instances For

                  The assignment of a stack #

                  theorem Cslib.Complexity.TQBF.closedIn_not (stack : List Frame) (φ : Logic.PL.QBF ℕ) :
                  closedIn stack φ.not = closedIn stack φ

                  Closedness of a negation.

                  Every call returns its value #

                  theorem Cslib.Complexity.TQBF.exists_iterate_step_call (φ : Logic.PL.QBF ℕ) (input : List (Logic.PL.QBF.Kind × ℕ)) (stack : List Frame) (ok : Bool) :
                  ∃ T ≤ callSteps φ, step^[T] { input := φ.tokens ++ input, stack := stack, value := none, ok := ok } = { input := input, stack := stack, value := some (Logic.PL.QBF.eval (assignment stack) φ), ok := ok && closedIn stack φ }

                  Every call returns its value. From the tokens of φ followed by input, the machine returns to the same stack, having read the tokens of φ, the value of φ under the assignment of the stack, and the flag updated by the closedness of φ relative to the stack, within callSteps φ steps.

                  The evaluator runs the machine long enough: 2 ^ (encQBF φ).length steps.

                  The evaluator #

                  The initial state on a formula: its tokens, the empty stack, nothing to return, no unbound variable met.

                  Instances For

                    The answer held by a state: whether no unbound variable was met and the value returned is true.

                    Instances For

                      The evaluator: run the machine from the initial state for 2 ^ (encQBF φ).length steps and read the answer.

                      Instances For

                        The evaluator computes closedness and the value.

                        The states of a run #

                        The suffixes stored in a stack are strictly nested above a bound: the input, of length at most r, is no longer than the suffix of the top frame, which is shorter than the suffix of the frame below, and so on, and the suffix of the bottom frame is shorter than n.

                        Instances For
                          theorem Cslib.Complexity.TQBF.Nested.mono {n r r' : ℕ} {stack : List Frame} :
                          Nested n r stack → r' ≤ r → Nested n r' stack

                          Nesting is preserved by a shorter input.

                          The invariant of the runs on the formula φ: the input is a suffix of the tokens of φ, each frame stores a token of φ followed by a suffix of the tokens of φ, and the stored suffixes are nested.

                          Instances For

                            Every state of a run satisfies the invariant.

                            A state satisfying the invariant has at most as many frames as the formula has tokens.