The complement of 2SAT in nondeterministic logarithmic space #
A nondeterministic counter program (Cslib.Complexity.TwoSAT.decider) accepts, on the encoding
of a formula φ, exactly when φ ∉ TwoSAT (Cslib.Complexity.TwoSAT.accepts_decider_iff). It
first guesses which of two reasons to look for:
- a clause that is empty or has more than two literals: it guesses the clause and counts its literals;
- a variable
xwith a path fromxto¬xand one back in the implication graph (Cslib.Logic.PL.CNF.Implies) Papadimitriou, Theorem 16.3: it guesses an occurrence ofxand walks fromx, first to¬xand then back tox, giving up after as many steps as the input has bits in each half.
These are all the reasons (Cslib.Complexity.notMem_TwoSAT_iff), by the theorem of Aspvall,
Plass and Tarjan [APT79]. The walk stores its current literal as the position of
an occurrence of its variable and a polarity. A step guesses a clause and one of its literals
ℓ', checks that the clause has one or two literals and that its other literal, or ℓ' itself
for a unit clause, is the negation of the current literal, which is the arc from the current
literal to ℓ' of the implication graph, and moves to ℓ'. Variables are compared digit by
digit through their positions (Cslib.Complexity.TwoSAT.cmpVarCode), so only positions,
counters and flags are stored, all at most the length of the input. The strategy, guessing the
two paths, is that of Papadimitriou, Theorem 16.3; the program, its register
layout and the positional comparison of variables are this library's own.
Main definitions #
Cslib.Complexity.TwoSAT.decider: the nondeterministic counter program.
Main results #
Cslib.Complexity.TwoSAT.accepts_decider_iff: it accepts exactly the formulas outsideTwoSAT.Cslib.Complexity.TwoSAT.exists_decidesInLogSpace_compl: one nondeterministic machine decides the complement ofTwoSATin logarithmic space, every branch halting.
References #
The decider of the complement of TwoSAT. Register 0 holds the choice, register 1 a
scanning position, registers 2, 3 and 4 the occurrence of the starting variable, the
occurrence of the current variable and the current polarity, registers 5, 6 and 7 the
phase, the number of steps and the length of the input, registers 8 to 10 the literals of a
guessed clause, registers 11 and 12 the next literal and the other one, and registers 13
to 15 cursors. Label 102 accepts and label 103 rejects.
Instances For
Registers #
The registers other than the choice.
- p : ℕ
Register
1. - o₀ : ℕ
Register
2. - cur : ℕ
Register
3. - sgn : ℕ
Register
4. - phase : ℕ
Register
5. - steps : ℕ
Register
6. - len : ℕ
Register
7. - q₁ : ℕ
Register
8. - q₂ : ℕ
Register
9. - q₃ : ℕ
Register
10. - o₁ : ℕ
Register
11. - o₂ : ℕ
Register
12. - t₁ : ℕ
Register
13. - t₂ : ℕ
Register
14. - t : ℕ
Register
15.
Instances For
All registers other than the choice are at most B.
Instances For
Halting #
What every halt guarantees: accepting only formulas outside TwoSAT.
Instances For
The bound on the registers: the length of the input, plus one for the choice.
Instances For
Every branch from the rejecting halt.
Every branch from the accepting halt, for a formula outside TwoSAT.
A step to the rejecting halt.
Code placement #
A clause of width zero or more than two #
The width of a clause: from label 10, the run accepts exactly when the clause at the
scanning position is empty or has more than two literals.
Every branch through the decider #
Every branch through deterministic code, then from its end.
A step at a choice: yes for the choice 0 and no for the choice 1.
The length of the bits of a clause.
Every branch looking for a clause of width zero or more than two, from the clauses cs,
halts, accepting only when it finds one.
The walk #
The position pos holds an occurrence of the literal (v, b) of the formula.
Instances For
The registers at the head of the walk: the starting occurrence of a variable x, the
occurrence of the variable v of the current literal and its polarity, the number of steps
within the length of the input, and the paths found so far: from x to the current literal in
the first phase, and from x to ¬x and from ¬x to the current literal in the second.
Instances For
The measure of the walk: the steps left, the first phase counting double.
Instances For
The chosen occurrence becomes the starting one and the current one, with polarity 1.
Every branch choosing the starting occurrence within a clause, from its literals ls,
rejects or reaches the head of the walk.
Every branch choosing the starting occurrence, from the clauses cs, rejects or reaches
the head of the walk.
Checking an arc and moving along it, deterministically: from label 79, with the
occurrences of literals ℓ' and m in registers 11 and 12, the run moves to ℓ' at the
head of the walk when m is the negation of the current literal, and rejects otherwise.
Every branch checking an arc and moving along it: from label 79, with the occurrences
of literals ℓ' and m of a clause c in registers 11 and 12, every branch rejects or moves
to ℓ' when m is the negation of the current literal, in which case the arc exists.
The registers at label 79: the walk unchanged, and the occurrences of two literals ℓ' and
m of the clause c in registers 11 and 12, such that c has no other literal.
Instances For
The registers of the walk agree.
Instances For
Reading a guessed clause, deterministically, up to the guess of its literal ℓ': an
empty clause or one with more than two literals is rejected, the literal of a unit clause is
taken, and the two literals of a clause of width two are placed in registers 8 and 9.
The registers after the guess of ℓ' in a clause of width two.
Instances For
The guess of ℓ' in a clause of width two: the first literal, or the second.
Every branch reading a guessed clause rejects it when it is empty or has more than two
literals, and otherwise guesses its literal ℓ', the other literal being m.
Every branch guessing a clause, from the clauses cs, rejects or reaches label 79 ready
to check one of them.
The registers after the test of the number of steps.
Instances For
The test of the number of steps, deterministically: from label 50, the run continues
to guess a clause when fewer steps than the length of the input were taken.
Every branch of a step of the walk: from label 50, every branch rejects or comes back
to the head of the walk one step further along an arc.
The invariant does not depend on the cursors.
The head of the walk, deterministically: it compares the current variable v with the
starting variable x, and the polarity with the phase.
Every branch from the head of the walk halts, accepting only when both paths are found, or comes back to it with a smaller measure.
Every branch from the head of the walk halts, accepting only when both paths are found.
Every branch from the start #
Every branch of the decider halts, accepting only formulas outside TwoSAT, with
registers at most the length of the input plus one.
An accepting branch #
One branch through deterministic code, with any choices before and after.
One step at a choice, taking the choice b.
A branch guessing a clause of a scanning loop: the code at l₀ reads the scanning
position, the choice at l₀ + 1 inspects the clause at inspect or skips it with the code at
skip.
A branch guessing a literal of a clause, at label 27.
An accepting branch for a clause of width zero or more than two.
A branch along an arc of the implication graph, from label 50 back to the head of the
walk, for a formula whose clauses have one or two literals.
A formula has at most as many occurrences of literals as its encoding has bits.
An accepting branch for a variable x with a path from x to ¬x and one back, for a
formula whose clauses have one or two literals.
The decider accepts exactly the formulas outside TwoSAT: some branch accepts exactly
then.
The complement of TwoSAT is decided in nondeterministic logarithmic space: one
nondeterministic machine decides it within space logarithmic in the length of the encoding,
every branch halting.