Jo Devriendt
[Gent-Miguel-Rendl] Common Subexpression Elimination in Automated Constraint Modelling, 2008
+
*
a
x
y
=
0
+
b
=
t
a+x*y=0
b+x*y=t
*
x
y
+
z1
a
=
0
z1
=
a+z1=0
z1=x*y
b+z2=t
z2=x*y
+
z2
b
=
t
z2
=
*
x
y
*
x
y
+
z1
a
=
0
z1
=
a+z1=0
b+z1=t
z1=x*y
+
z1
b
=
t
Extra propagation: assume t=6 and b=0
Standard propagation routines can propagate z=6 and then a=-6
Not possible in two previous slides!
*
x
y
x >= 1
the version with the var or the val?x*y
and y*x
use the same reification var?x xor y xor z
linearizes to x+y+z = 2*aux+1
but aux
is not x xor y xor z
+
*
a
x
=
0
+
b
=
t
a+x*y=0
b+x*y=t
*
x
y
y
+
a
=
0
+
b
=
t
a+x*y=0
b+x*y=t
*
x
y
exploited during simplifications: (p & q) | (p & q) become p & q by a simple ID check
comparison < based on ID (no recursive compares needed)
All commutative expressions have subterms ordered by ID
fixes x+y vs y+x problem (canonicity)
Summarized: DAG of canonical expressions
+
-
Core idea: keep track of a sets of equivalent subexpressions with a canonical representative
Syntactical equivalence
Semantical equivalence
Easy semantical equivalences
equivalent set:
{x*y, y*x, 1+x*y-1, a+b, aux}
Total order on expressions
Smaller expressions are simpler!
Core idea: keep track of a sets of equivalent subexpressions with a canonical representative
Replace all syntactical occurrences of equivalent set with smallest element in set -> canonical representative
equivalent set:
{x*y, y*x, 1+x*y-1, a+b, aux}
Core idea: keep track of a sets of equivalent subexpressions with a canonical representative
+ strong reduction of number of variables/constraint
can avoid unnesting!
Replace all syntactical occurrences of equivalent set with canonical representative.
- more complex
My interpretation from [Gent-Miguel-Rendl]:
Yes. E.g., most duplicates are from quantor unrolling.
will introduce duplicate unrolled instantiations of
but the following equivalent model will not
My interpretation from [Gent-Miguel-Rendl]:
Yes. E.g., most duplicates are from quantor unrolling.
My opinion: No unless the expert generates the low-level constraints
Expecting expert modelers to anticipate and fix this is the same as expecting them to do the transformation to low level constraints.
p <-> alldiff(x,y,z)
p -> alldiff(x,y,z)
~p -> ~alldiff(x,y,z)
E.g., CPMpy's uniform reification transforms
to the following, with common subexpressions,