libminizinc
libminizinc copied to clipboard
Common Subexpression Elimination
I am working on a problem with lots of re-occuring common subexpressions. Inspecting the FlatZinc intermediate file, I noticed that the subexpressions are not eliminated. Therefore, I tried to use a let construct to nudge the compiler in CSE direction:
% F[], G[] and D[] are arrays of var bool
constraint
forall(i in ARows, j in ACols, m in BRows, n in BCols) (
let {
array[Products] of var bool: dyad = [F[i,j,k] /\ G[m,n,k] | k in Products];
} in
forall(p in CRows, q in CCols) (
if ((i != p) \/ (j != m) \/ (n != q)) then
iffall([(dyad[k] /\ D[p, q, k]) | k in Products])
else
xorall([(dyad[k] /\ D[p, q, k]) | k in Products])
endif
)
);
This did not help. The FlatZinc code contains all 3-input conjunctions and the compiler replaced my construct by the same result it would create from:
constraint
forall(i in ARows, j in ACols, m in BRows, n in BCols, p in CRows, q in CCols) (
if ((i != p) \/ (j != m) \/ (n != q)) then
iffall([(F[i, j, k] /\ G[m, n, k] /\ D[p, q, k]) | k in Products])
else
xorall([(F[i, j, k] /\ G[m, n, k] /\ D[p, q, k]) | k in Products])
endif
);
Is there a way to achieve common subexpression for my example? Or does it make no sense to attempt this anyhow?
That's AC-CSE on conjunction.