equality-e-graphs

advertisement
Decision Procedures in
First Order Logic
Decision Procedures for
Equality Logic
Constructing Smaller E-Graphs
Daniel Kroening and Ofer Strichman
1
Interlude…

So far we solved UF in three steps:
1.
Reduce UF to Equality Logic E , and
2.
Reduce E to Propositional Logic formula enc Æ trans
OR

2.
Find a small domain to each variable.
3.
Solve propositional formula
Next, we improve the small-domain method by
constructing smaller E-graphs.
Decision Procedures
An algorithmic point of view
2
Smaller E-graphs
UF

So far we first reduced 
constructed the E-graph.
to E and only then

The Clique problem:
UF
n function instances in  
n-clique between f1 ...fn, and a similar clique
between their arguments in GE(E)

New strategy: add to graph functional consistency
constraints ‘as needed’
Decision Procedures
An algorithmic point of view
3
Constructing smaller E-graphs

Let flat(UF) be a formula derived from UF by
replacing each UF instance Fi with a new variable fi

Example:
UF
: F1(G1(x1)
 F2(G2(x2)) Æ x1 = x2
flat(UF)
: f1
 f2
Decision Procedures
An algorithmic point of view
Æ x1 = x2
4
Constructing smaller E-graphs

Recall: to check the satisfiability of
UF1:

F1(x1)  F2(x2) Æ ((x1 = x2) Ç true)
We need to check, according to Bryant’s reduction:
E1:

The following optimization only works with Bryant’s
reduction
Decision Procedures
An algorithmic point of view
5
Constructing smaller E-graphs

Attempt #1: construct GE(E) according to flat(UF)
Note - build GE(E) before Bryant’s reduction!
UF1:
F1(x1)  F2(x2)
flat(UF1):
f1
 f2
{1}
f1
{0}
x1
Æ ((x1 = x2) Ç true)
Æ ((x1 = x2) Ç true)
{2}
f2
{0}
x2
Decision Procedures
An algorithmic point of view
6
Constructing smaller E-graphs

Does the single assignment we have:
x1 = 0, x2 = 0, f1 = 1, f2 = 2
satisfy
E1:
Decision Procedures
An algorithmic point of view
7
Constructing smaller E-graphs

Does the single assignment we have:
x1 = 0, x2 = 0, f1 = 1, f2 = 2
satisfy
E1:
Decision Procedures
An algorithmic point of view
8
Constructing smaller E-graphs

Does the single assignment we have:
x1 = 0, x2 = 0, f1 = 1, f2 = 2
satisfy
E1:
unsatisfied!

So what is missing ?

Answer: the graph fails to represent the fact that, due
to functional consistency
implies x1  x2
Decision Procedures
An algorithmic point of view
9
Constructing smaller E-graphs

Suggestion: if there is a solid edge between fi and fj,
add a solid edge between their arguments
{2}
{3}
f2
f1
{0}
{0,1}
x1
x2

Now the assignment x1 = 0, x2 = 1, f1 = 2, f2 = 3 satisfies
E1

But is this enough ?
Decision Procedures
An algorithmic point of view
10
Constructing smaller E-graphs

Consider:
{1}
z


{1}
{2}
f1
f2
{0}
{0}
x1
x2
x1 = 0, x2 = 0, f1 = 1, z = 1, f2 = 2 does not satisfy E2
So the suggested rule in not enough. So what is the
rule ?
Decision Procedures
An algorithmic point of view
11
Constructing smaller E-graphs

Rule 1: if fi *fj and xi=*xj add a solid edge
between xi and xj
{2}
z
{2}
{3}
f1
f2
{0}
{0,1}
x1
x2

x1 = 0, x2 = 1, f1 = 2, z = 2, f2 = 3 satisfies E2

Anything else ?
Decision Procedures
An algorithmic point of view
12
Constructing smaller E-graphs

Now consider:

for which the graph is the same:
{2}
z
{2}
{3}
f1
f2
{0}
{0,1}
x1
x2

But there is no satisfying assignment here for E3!

So what is missing ?
Decision Procedures
An algorithmic point of view
13
Constructing smaller E-graphs

So what is missing ?

x1 = x2 implies f1 = f2

But with Bryant’s reduction we are not supposed to
worry about this:
When x1 = x2 this
value is not
important

But… we still cannot satisfy E3 from the current
graph. So still, what is missing ?
Decision Procedures
An algorithmic point of view
14
Constructing smaller E-graphs

Recall:

If
is assigned the value of f1, we need to make
sure f1 can satisfy the constraints over

We can do it in two ways:
 Either add an edge f1 = f2 (Range-Allocation will
do the rest)
 Copy all constraints over
to f1.
Decision Procedures
An algorithmic point of view
15
Constructing smaller E-graphs
Recall:

{2,3}
{2}
{2}
z
z
{2,3}
{2,3}
{4}
f1
f2
f1
f2
{0}
{0,1}
{0}
{0,1}
x1
x2
x1
x2

Both options satisfy E3. So what is the rule ?
Decision Procedures
An algorithmic point of view
16
Constructing smaller E-graphs

Rule 2: For fi, fj, i < j, if xi =* xj do one of the
following:
 Add
equality edge (fi,fj)
 Copy all constraints over fj to fi, i.e.


For every Equality Edge (fj,w) add equality edge (fi,w)
For every Disequality Edge (fj,w) add Disequality edge (fi,w)

Choose between the two options heuristically:
typically adding less equality edges is better.

Q: why is this not symmetric ?
Decision Procedures
An algorithmic point of view
17
Constructing smaller E-graphs

Consider
f1
f2
x1
x2

According to Rule 1 we add a Disequality edge
between x1 and x2 only if x1 =* x2

But here we need to allow x1  x2 nevertheless
Decision Procedures
An algorithmic point of view
18
Constructing smaller E-graphs

Rule 3: if both u =* v and u * v do not hold, add a
disequality path between u and v.
f1
f2
x1
x2

These edges are ‘free’: they do not add anything to
the allocated ranges.

Do not add them; ensure diversity in RangeAllocation instead Decision Procedures
An algorithmic point of view
19
Constructing smaller E-graphs
1.
Built the E-Graph corresponding to flatE(UF)
2.
Repeat until no edges are added:
For every pair Fi(xi), Fj(xj) s.t. i < j
1. (Rule 1) if fi *fj and xi=*xj add a solid edge
between xi and xj
2.
(Rule 2) if xi =* xj either add a dashed edge between fi
and fj or copy all constraints from fj to fi
3.
(Rule 3) add free edges
4.
Allocate adequate ranges for the graph
5.
Solve E derived from Bryant’s reduction
Decision Procedures
An algorithmic point of view
20
Small E-Graph: Example
{5}
f2
{4}
f4
{1,2}
{1}
f1
x2
{0}
{3}
f3
State-space=2
x1
Decision Procedures
An algorithmic point of view
21
How would the E-graph look like otherwise?

Originally, we first reduced UF to E.

This added all functional consistency constraints apriori
{0,1,2}
f2
{0,1,2,3}
f4
{0}
f1
{0,4}
x2
State-space=48
{5}
f3 {0,1}
Decision Procedures
An algorithmic point of view
x1
22
Bryant’s vs. Ackermann’s reduction

Why only Bryant’s reduction works in this case?

The short answer:
 Bryant’s:
when the arguments are equal, it doesn’t matter if
f1 and f2 are equal.
 Ackermann’s: giving unique values to f1,f2 makes the
formula unsatisfiable when x1 = x2
(x1 = x2 ! f1 = f2) Æ flat(UF)

The long answer: see lecture notes
Decision Procedures
An algorithmic point of view
23
Download