Abstract
Incremental Determinization (ID) decides 2QBF, , by running CDCL over functions instead of values. It builds a Skolem function for one existential at a time, reading it straight off the clauses, and falls back on decisions, conflict analysis and backtracking when the clauses alone do not determine a function. The answer is True with the Skolem functions as a circuit, or False with a counterexample. ID first appears in Rabe & Seshia (2016) and is extended to functional synthesis in Rabe (2019). This note explains the algorithm on two small examples, one True and one False.
The problem
A 2QBF is a formula
where is a CNF over the universal variables and the existential variables . An assignment to is an input, written . For example, means and . The formula is True if every input has a solution: an assignment to that satisfies .
Equivalently, the formula is True if it has Skolem functions: one function per existential, such that holds at every input. The functions are a certificate for True. The certificate for False is a counterexample: an input at which no assignment to satisfies . ID returns one or the other.
The idea
CDCL builds a satisfying assignment one variable at a time. Unit propagation adds the values that clauses force, and decisions add values by choice. When a choice leads to a conflict, a learned clause rules it out and backtracking undoes it.
ID runs the same loop with functions in place of values. Its partial solution is a set of existentials that already have a Skolem function. A variable’s clauses can force its whole function, the way a unit clause forces a value. When nothing is forced, ID chooses a function for some variable. A conflict is an input at which some variable is forced to 1 and to 0 at once. The functions are never written down as tables or circuits: they are read straight off the clauses, as the next section shows.
Two running examples, one True and one False:
is True, and the functions ID finds for it form a half adder. is False: at , clause a forces and clause c forces , which violates e.
Clauses as rules
Every clause is an implication: is equivalent to . When the other literals are all false, the clause forces . This is the reading behind unit propagation. ID applies it to all at once: the rules that force describe as a function of .
’s clauses, read as rules:
| Clause | As a rule | |
|---|---|---|
| a | ||
| b | ||
| c | ||
| d | ||
| e | , once has a function |
Which clauses are rules
For rules to describe an existential as a function of , whether each one fires must depend on alone. Most clauses also mention other existentials, and that breaks this. In clause e, whether is forced depends on . While is unknown, e says nothing about as a function of . Once has a function, its value is fixed by , and so is whether e fires.
So the algorithm keeps a set of existentials that already have a function of . Variables in act as extra inputs: wherever they appear, fixes their value. starts empty and grows one variable at a time. Each new function can be built on the functions already in . is the algorithm’s partial solution, the counterpart of CDCL’s partial assignment, and the answer is True once contains every existential.
The algorithm works on one existential outside at a time: it checks whether that variable’s function is already fixed, chooses a function for one, or finds a conflict on one. From here on, is that variable, an existential outside whose rules are being examined. A clause is a rule for when is its only existential outside . All its other literals are over , so whether it fires depends on alone. is the set of rules for . A clause with two existentials outside is a rule for neither.
In with : a, b and c are rules for , and d is a rule for . Clause e has both ‘s, so it is a rule for neither. Once joins , e becomes the rule .
Antecedents
For , let be ‘s literal on . The antecedent of is
At an assignment where is true, the rule fires: forces , because every other literal of is false. The antecedents are grouped by which value they force:
- : the rules that force
- : the rules that force
- : all of ‘s antecedents
For a set of antecedents, means “some antecedent in it fires”. For example, means “some rule forces ”.
In with :
| forces | belongs to | |||
|---|---|---|---|---|
| a | ||||
| b | ||||
| c | ||||
| d |
On-set, off-set and don’t-cares
The rules for split the inputs into three sets, which together form an incompletely specified function:
| Set | Given by | Meaning |
|---|---|---|
| on-set | must be 1 | |
| off-set | must be 0 | |
| don’t-care set | neither fires | is free |
Two properties of these sets drive the whole algorithm:
- deterministic: the don’t-care set is empty, so at every input some rule for fires;
- conflicted: the on-set and off-set overlap, so at some input the rules force both ways and no function for satisfies them all.
A variable that is deterministic and not conflicted has exactly one function its rules allow: 1 on the on-set, 0 on the off-set, and nothing left over. Such a variable joins . That step determinizes , and the algorithm determinizes the existentials one at a time, which gives it its name. In QBF terms, is then defined by , and its rules are the definition.
at the start:
| 0 | 0 | 0 (b, c) | 0 (d) |
| 0 | 1 | 0 (b) | don’t-care |
| 1 | 0 | 0 (c) | don’t-care |
| 1 | 1 | 1 (a) | don’t-care |
is deterministic and not conflicted, so it joins with the function . is not deterministic.
Over , not over
Antecedents can mention ‘s in , so the three sets are sets over . To see them as sets of inputs, replace each in by its function. In , once joins , rule e is added to ‘s off-set:
That leaves as ‘s don’t-cares.
The algorithm never writes these functions down. is the set of clauses whose variables are all in : the rules of every variable in . They define ‘s functions, so an assignment that satisfies is an together with the values ‘s functions give at that . Every question about ‘s functions is a SAT call over .
The main loop
The loop alternates two steps.
- Propagation: every existential that is deterministic and not conflicted joins .
- Decision: when there is nothing left to propagate, i.e. nothing to extend with, it picks some outside and makes it deterministic. That may let propagation continue.
The choice can be wrong. Clauses linking to existentials outside are not yet rules for , and once those existentials get functions, some variable may become conflicted: at some input, its rules force it both ways. When that happens, conflict analysis learns a clause that rules this out, and backtracking undoes the choices that clause blames.
The loop terminates under one of two conditions:
- True, once every existential is in (i.e., ).
- False, once some clause contains only universals.
def solve(∀X ∃Y. φ):
D, level = {}, 0
while True:
conflict = propagate()
if conflict:
v, M = conflict
L = analyze(v, M)
if L has only universals:
return False
k = highest level of a variable in L
backtrack(k − 1)
add L to φ
elif D == Y:
return True
else:
level += 1
decide(some v not in D) # any v worksThe steps, each with its own section:
propagate()adds deterministic, unconflicted variables to until none is left, or stops early at the first conflicted variable.analyze(v, M)returns a learned clause that follows from and rules the conflict out.backtrack(k − 1)undoes everything above level , including the choice made at level .decide(v)makes deterministic.
Decision levels
- Each decision opens a new level.
- Everything propagated after it carries that level, and so do the clauses the decision itself adds.
- Level 0 holds what follows from alone: the variables determined before any decision, and the learned clauses.
- Backtracking to level undoes everything above , as on CDCL’s trail.
Propagate
Propagation is ID’s counterpart of unit propagation. A unit clause forces the value of one variable. Here, a variable’s rules can force its whole function. Propagation looks for such variables and adds them to , one at a time, until none is left or it finds a conflict.
Two checks
For a variable outside , propagation asks two questions. Each is one SAT call:
| Check | Question | SAT query | Answer |
|---|---|---|---|
| deterministic | Is there an input where none of ‘s rules fires? | UNSAT: deterministic | |
| conflicted | Do ‘s on-set and off-set overlap, i.e. can some input force to 1 and to 0 at once? | SAT: conflict |
The determinism query is just ‘s rules with deleted from them.
The two checks treat differently:
- Determinism ignores ‘s functions. The query leaves ‘s variables free, so it can find a don’t-care at a combination of values that ‘s functions never produce. Such a false “not deterministic” costs one extra decision, nothing more.
- Conflict uses ‘s functions, through . This check has to be exact: a conflict at a combination of values that never happens is not a real conflict.
When the conflict query is SAT, its model is an assignment to at which ‘s rules force both ways. Because the query includes , ‘s values on are the ones ‘s functions give at ‘s . Propagation stops and returns the conflict to conflict analysis.
Adding a variable to
When passes both checks, it joins at the current level. Its rules are now clauses over , so they join and define ‘s function from then on.
Other variables can gain rules as a result. A clause that mentioned and one other existential outside is now a rule for . Only those neighbours need to be checked again.
Pseudocode
def propagate():
queue = Y - D
while queue:
v = queue.pop()
if SAT(¬⋁A_v): # a don't-care: not deterministic yet
continue
M = SAT(𝒟 ∧ ⋁A⁺_v ∧ ⋁A⁻_v) # a model, or None
if M:
return (v, M) # conflict
D.add(v) # at the current level
for u in neighbours(v) - D: # existentials sharing a clause with v
queue.add(u) # u may have gained a rule: check it again
return None # nothing left to propagateExample
at level 0, starting with and queue . The order in which variables are popped doesn’t matter; popping first shows the re-check.
-
Pop . Its only rule is d, so
This is SAT, e.g. at , so is not deterministic and is dropped.
-
Pop . Its rules are a, b and c:
This is UNSAT, so is deterministic. is still empty, so the conflict query is
This is UNSAT too, so joins . shares clause e with , so it goes back into the queue.
-
Pop again. Clause e is now a rule for :
This is SAT at , , so is dropped again. The don’t-care is real: at .
-
The queue is empty. Propagate returns no conflict with , and the loop decides .
In at level 0, both variables are dropped on their first pop:
stays empty.
Decide
When there is nothing left to propagate, every existential outside still has don’t-cares. A decision picks a , and makes it deterministic by adding one rule:
In words: if no rule forces , then . The new antecedent joins , which moves the don’t-cares into the on-set:
| Set | Before | After |
|---|---|---|
| on-set | , i.e. on-set don’t-cares | |
| off-set | unchanged | |
| don’t-cares | neither fires | empty |
So is now deterministic: , which is 0 wherever some rule forces 0 and 1 everywhere else. The rule belongs to the new decision level, so backtracking can remove it again.
Choices left open
Any variable outside can be picked; picking a good one is a heuristic. The default 1 is arbitrary too: the mirror rule fills the don’t-cares with 0 instead, and both are valid.
A decision only fills don’t-cares, so it cannot remove a conflict. The new rule never fires where some rule already forces . If the on-set and off-set already overlap, stays conflicted, and the next propagate reports it.
def decide(v):
A⁺_v.add(¬⋁A⁻_v) # the rule ¬⋁A⁻_v → v, at the current levelExample
In , the decision on comes after has joined , so both clauses on are rules for it:
Neither forces , so the decision adds
Substituting gives ‘s function:
| before | after | |||
|---|---|---|---|---|
| 0 | 0 | 0 | 0 (d) | 0 |
| 0 | 1 | 0 | don’t-care | 1 |
| 1 | 0 | 0 | don’t-care | 1 |
| 1 | 1 | 1 | 0 (e) | 0 |
The two don’t-cares become 1, and the other inputs keep their forced 0. In the next propagate, is deterministic and not conflicted, because its on-set is now exactly the complement of its off-set. It joins , and with every existential in the answer is True.
Why a decision can be wrong
The decision in was safe: every clause on was already a rule for it, so filling the don’t-cares could not violate any of them. That is not always the case. A clause that links to an existential still outside is not a rule for yet, so the decision ignores it. Once that existential gets a function, the clause may need the other value of at an input the decision filled.
shows this. Here is decided first, while is still empty.
-
’s only rule is c, , so the decision makes
In particular, at , which was a don’t-care.
-
Clause d, , also mentions . But is outside , so d is not a rule for , and the decision ignores it.
-
Once is in , d becomes a rule for . At , two rules for fire:
So is conflicted.
The cause is the decision’s choice at . Conflict analysis finds that cause and turns it into a learned clause.
Conflict analysis
Propagate reports a conflict as : at the assignment , one rule forces and another forces . Conflict analysis turns into a learned clause with two properties:
- follows from . Every solution already satisfies it, so adding it changes nothing about what is true.
- is false under . It rules out the combination of values that caused the conflict.
Read as a rule, says what must be different next time. In , the first learned clause is
From to
is already a valid learned clause. The two rules that fire at are clauses of , and they contradict each other there, so no solution agrees with . But is weak: it rules out a single point and mentions every variable in . Conflict analysis shrinks it to the values that actually caused the conflict.
Under , every value has a cause:
| Value | Cause |
|---|---|
| an | none: it is an input |
| a forced by a clause | the other literals of that clause, all false under |
| a whose value came from a decision | none: it was chosen |
Only original and learned clauses count as causes. A decision’s rule is a choice, not a consequence of , and a clause derived from it would make the choice permanent.
The causes form CDCL’s implication graph: values flow from the ‘s through to the conflict on . Conflict analysis starts from the two rules that fire on and walks this graph backwards, replacing forced values by their causes. Each replacement is one resolution step, which is why still follows from . The result is restricted to the values the walk ends on, so rules out every assignment that agrees with on them.
Where the walk stops
The walk replaces only values from the current level that a clause forced. It stops at
- ‘s, which are inputs;
- ‘s from earlier levels, which are settled;
- values at the current level that were chosen rather than forced.
If every it ends on is from level 0, no choice is involved at all. The walk then continues through those ‘s as well, down to the universals.
| contains | Meaning | Next |
|---|---|---|
| only universals | at ‘s , no choice of ‘s works | return False, with that as the counterexample |
| some existential | some choice is to blame | backtrack and add |
Pseudocode
reason(y) is the set of other variables in the clause that forced ‘s value at . It is empty when that value was chosen. reason(v, 1) and reason(v, 0) are the same for the two rules that fire on .
def analyze(v, M):
causes = reason(v, 1) | reason(v, 0) # the two rules for v that fire at M
expand(causes, level) # stops at choices and earlier levels
if all(level_of(y) == 0 for y in causes & Y):
expand(causes, 0) # no choice involved: down to the universals
return ¬M[causes] # the learned clause L
def expand(causes, lvl):
while forced := [y for y in causes & Y if level_of(y) == lvl and reason(y)]:
y = forced[0]
causes.remove(y)
causes |= reason(y) # one resolution stepExample
has two conflicts.
First conflict. At level 1, the decision has made conflicted at
(b): x₁=1, x₂=1 ⟹ y₁=1
(d): y₂=1 ⟹ y₁=0 conflict on y₁
The causes are . No clause of forces : that value was the decision’s choice, so the walk stops there.
mentions , so the decision is to blame, and the solver backtracks.
Second conflict. After backtracking, is decided again, now as . This time is conflicted at
(c): x₁=0 ⟹ y₂=0
(e): x₁=0, y₂=0 ⟹ y₁=1
(a): x₂=0 ⟹ y₁=0 conflict on y₁
The causes start as . Now is not a choice: clause c forces it, because . The walk replaces by :
has only universals, so the answer is False, with counterexample . To check: at , clause a gives , so clause e needs , but clause c needs .
The two conflicts differ in one thing: whether ‘s value at was chosen or forced. That decides whether the walk stops at , and the solver learns and backtracks, or goes through it, and the answer is False.
Backtracking
When contains an existential, some choice is to blame, and backtracking undoes it. Let be the highest decision level among ‘s variables. The solver backtracks to level : every variable that joined above that level leaves it, taking its rules out of , and every rule added by a decision above that level is removed. Then is added to . A decision’s rule is a choice and disappears with its level, but follows from , so it is permanent and belongs to level 0.
as a rule
Usually is the current level, and ‘s only from that level is the variable decided there, since the walk replaced every other variable from that level by its causes. After backtracking, is outside again, while ‘s other ‘s, all from lower levels, are still in it. So is now a rule for . It forces the opposite of the value was given, at exactly the inputs where that choice went wrong, and the next decision on has to respect it. If the walk never reached the latest decision, may contain several ‘s from level , and it becomes a rule once all but one of them are back in .
Learned clauses are never removed, and each one rules out the values behind its conflict for good, so no conflict can happen twice and the loop terminates.
Not CDCL's backjump
CDCL jumps further back, to the second-highest level in , because is unit there and fixes a value at once. Here is one more rule for , which usually does not make deterministic, so there is less to gain from jumping further. The original algorithm (Rabe & Seshia, 2016) goes to , keeping every level below the blamed choice; implementations differ.
Pseudocode
def backtrack(k):
D = {v for v in D if level_of(v) <= k} # later variables leave D
for v in Y:
A⁺_v = {A for A in A⁺_v if level_of(A) <= k} # later decisions are undone
level = kExample
‘s first conflict gave
Its only is , decided at level 1, so the solver backtracks to level 0. leaves , the decision’s rule is removed, and is empty again. With added, has two rules, both forcing 0:
is still a don’t-care for , and has the same rules as at the start, so neither is deterministic. Propagation at level 0 adds nothing, and is decided again:
| first decision | second decision | ||
|---|---|---|---|
| 0 | 0 | 0 (c) | 0 (c) |
| 0 | 1 | 0 (c) | 0 (c) |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 () |
changes only at , where the first choice went wrong. The second decision leads to ‘s second conflict, which ends in False, as shown in Conflict analysis.
Skolem functions
When , the answer is True, and the Skolem functions are already in place. Each variable’s function is its on-set:
So exactly when some rule forcing 1 fires. For a decided variable, contains the decision’s rule, so includes its antecedent .
The off-set is not needed. Every in is deterministic and not conflicted, so at every input exactly one of its on-set and off-set holds, and . The rules forcing 0 still matter: the conflict check tested them against the rules forcing 1, and that check is what makes the on-set alone safe to use.
Building the circuit
A variable’s rules are fixed when it joins . A clause that also mentions a later variable is a rule for that later variable, not for . So mentions only ‘s and ‘s that joined before .
Going through in the order the variables joined, each is therefore built from ‘s and functions that already exist. The result is a circuit of AND, OR and NOT gates with no cycles, and only the ‘s as inputs. Nothing has to be computed after the run: the functions are the rules.
def skolem_functions():
f = {}
for v in join_order: # the order in which variables joined D
f[v] = substitute(⋁A⁺_v, f) # each earlier y becomes f[y]
return fExample
In , joined first. Its only rule forcing 1 is a, , so
joined second. Its rules d and e both force 0, so its only rule forcing 1 is the decision’s:
Together they form a half adder: is the carry of and is the sum bit.
Checking the answer
Each answer comes with a certificate that one SAT call can check:
| Answer | Certificate | SAT query | Must be |
|---|---|---|---|
| True | the functions | : some where the functions violate a clause | UNSAT |
| False | the counterexample | : some ‘s that work at that | UNSAT |
For , no violates once and . For , is UNSAT, as checked at the end of the conflict analysis example.
Functional synthesis
When the answer is False, ID returns a counterexample and no functions. Often functions are wanted anyway: ones that produce a solution at every that has one. This is functional synthesis. The task is to find with
When the 2QBF is True, every has a solution and these are exactly the Skolem functions. ID handles the general case with one change (Rabe, 2019).
One change: conflicts need a solution
A conflict at an without a solution does not matter: no ‘s work there, so no function can do better. The conflict check therefore only looks at ‘s that have a solution. A copy of with fresh existentials says “this has some solution”, independent of ‘s functions, and joins the conflict query:
M = SAT(𝒟 ∧ φ(X, Y′) ∧ ⋁A⁺_v ∧ ⋁A⁻_v) # in propagate: conflicts only where x has a solutionEverything else stays the same: the determinism check, decisions, conflict analysis and backtracking. When the 2QBF is True, the copy rules out no , and the run is unchanged.
At an without a solution, ‘s on-set and off-set may still overlap. joins anyway, and sets it to 1 there.
The answer is always True
A learned clause can no longer contain only universals. follows from , so it holds at every that has a solution, and the conflict query made sure that ‘s has one. Since is false under , it must mention some , so some choice is to blame and the solver backtracks. A clause of with only universals no longer means False either: it only marks ‘s without a solution, which the copy already excludes.
So every run ends with and functions. Their check changes accordingly: must be UNSAT, i.e. no that has a solution breaks the functions.
Example
has a solution at every except 00, the counterexample from conflict analysis.
The first conflict is at , which has a solution (, ), so it still counts. The solver learns the same , backtracks, and decides again, as .
Without synthesis, the second conflict was at . That has no solution, so the conflict query is now UNSAT. joins , every existential is in , and the answer is True. ’s rules forcing 1 are b and e, so
| has a solution | |||||
|---|---|---|---|---|---|
| 0 | 0 | no | 1 | 0 | violates a |
| 0 | 1 | yes | 1 | 0 | satisfied |
| 1 | 0 | yes | 0 | 1 | satisfied |
| 1 | 1 | yes | 1 | 0 | satisfied |
The functions fail only at , where nothing works.
Implementation notes
The sections above say what each SAT call asks. This section is about how the calls are encoded.
Selector variables
The determinism query is already CNF: is ‘s rules with deleted. The conflict query is not, because each antecedent is a conjunction, so is a disjunction of conjunctions. A fresh selector variable per antecedent , with as one binary clause per literal of , turns the disjunction into the single clause .
Local conflict pre-filter
The conflict query includes all of , which grows with . Before running it, check alone, leaving ‘s variables free. If that is UNSAT, so is the full query, and the expensive call is skipped.
Encoding a decision
The decision’s rule is not a clause, since each antecedent in is a conjunction. A helper variable names each antecedent, and then the rule becomes a single clause:
def decide(v):
helpers = []
for A in A⁻_v: # one helper per rule that forces v = 0
h = fresh_variable()
add_clauses(h ↔ A) # h is 1 exactly where this rule fires
D.add(h) # deterministic by construction
helpers.append(h)
add_clause(helpers + [v]) # no helper is 1 → v = 1
for h in helpers:
add_clause([¬h, ¬v]) # some helper is 1 → v = 0All of these clauses belong to the current level and disappear on backtrack. The helpers become internal gates of ‘s function; only the original ‘s are outputs.
The clauses are redundant: already follows from the clause behind . But the determinism check leaves ‘s variables free, so it does not see the helpers’ definitions. Without these clauses it finds a don’t-care that does not exist, calls not deterministic, and the solver decides again, forever.
In , the decision on has two rules forcing 0, d and e, so it gets two helpers:
and the clauses , and .
| 0 | 0 | 0 | 1 | 0 | 0 |
| 0 | 1 | 0 | 0 | 0 | 1 |
| 1 | 0 | 0 | 0 | 0 | 1 |
| 1 | 1 | 1 | 0 | 1 | 0 |
So , the same function as in the Decide example.
Conclusion
Incremental Determinization is CDCL lifted from values to functions. Instead of assigning variables one at a time, it grows a set of existentials that have a Skolem function. Propagation adds the variables that are deterministic and not conflicted, and decisions fill the remaining don’t-cares. When a decision turns out wrong, conflict analysis learns a clause from the assignment where some variable is forced both ways, and backtracking undoes the choice. The run ends with True, where the rules themselves are the Skolem functions, or with False and an at which no ‘s work. With one change to the conflict check, the same loop does functional synthesis.
Propagation does most of the work when many existentials are already defined by their clauses, as Tseitin variables are; decisions are needed only for the rest. This note leaves out what makes the algorithm fast in practice, such as decision heuristics and restarts, which the CADET solver (Rabe & Seshia, 2016) adds on top of the same loop.
ID and CDCL
| CDCL | ID |
|---|---|
| partial assignment | , a set of Skolem functions |
| unit propagation | propagate: determinism and conflict checks |
| decide a value | decide a function: default 1, with carved out |
| conflicting clause | an where both sides fire (witness ) |
| learned clause | the same, derived from |
| all variables assigned → SAT | |
| empty learned clause → UNSAT | learned clause with only universals |
Appendix: Tracing and through solve()
Both runs at a glance. The sections above explain each step.
:
| Step | Level | Result |
|---|---|---|
| propagate | 0 | , so |
| decide | 1 | |
| propagate | 1 | : True |
:
| Step | Level | Result |
|---|---|---|
| propagate | 0 | |
| decide | 1 | |
| propagate | 1 | conflict on at |
| analyze | 1 | : backtrack to level 0 |
| propagate | 0 | ; is now a rule for |
| decide | 1 | |
| propagate | 1 | conflict on at |
| analyze | 1 | , only universals: False at |