Arrays. Overview Overview of Arrays Creating Arrays Using Arrays.
Solvers: Equality and Arrays Lecture 4 2012
description
Transcript of Solvers: Equality and Arrays Lecture 4 2012
![Page 1: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/1.jpg)
Solvers: Equality and Arrays
Lecture 4 2012
Nikolaj Bjørner Microsoft ResearchDTU Winter course January 5th 2012
![Page 2: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/2.jpg)
PlanThe theory of Un-interpreted functions
The Theory of Arrays
![Page 3: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/3.jpg)
Key Takeaways:
Theory of equality, un-interpreted functions and arrays
Saturation-based decision proceduresA common patternConnections with algorithms used in program analysis
Inference rule formulationDatalog formulation
A reduction approach to decision proceduresThe theory of array reduces to theory of equalities/functions
![Page 4: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/4.jpg)
Deciding Equality
![Page 5: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/5.jpg)
E - The theory of equalityReflexivity: t = t
Symmetry: t = s s = t
Transitivity: t = s s= u t = u
Congruence: t1= s1 .. tn =sn f(t1, …, tn) = f(s1, …, sn)
E – the (infinite) conjunction of these axioms
![Page 6: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/6.jpg)
Congruence Closure
E-satisfiability can be decided with a simple algorithm known as congruence closure.
Congruence closure creates a finite quotient for DC(E + L).
E – Equality axiomsL – Literals: extra equalities in input
![Page 7: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/7.jpg)
Deciding Equality
a = b, b = c, d = e, b = s, d = t, a e, a s
a b c d e s t
![Page 8: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/8.jpg)
Deciding Equality
a = b, b = c, d = e, b = s, d = t, a e, a s
a b c d e s t
![Page 9: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/9.jpg)
Deciding Equality
a = b, b = c, d = e, b = s, d = t, a e, a s
c d e s ta,b
![Page 10: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/10.jpg)
Deciding Equality
a = b, b = c, d = e, b = s, d = t, a e, a s
c d e s ta,b
![Page 11: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/11.jpg)
Deciding Equality
a = b, b = c, d = e, b = s, d = t, a e, a s
d e s ta,b,c
![Page 12: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/12.jpg)
Deciding Equality
a = b, b = c, d = e, b = s, d = t, a e, a s
d e s ta,b,c
![Page 13: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/13.jpg)
d,e
Deciding Equality
a = b, b = c, d = e, b = s, d = t, a e, a s
s ta,b,c
![Page 14: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/14.jpg)
Deciding Equality
a = b, b = c, d = e, b = s, d = t, a e, a s
s ta,b,c d,e
![Page 15: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/15.jpg)
a,b,c,s
Deciding Equality
a = b, b = c, d = e, b = s, d = t, a e, a s
td,e
![Page 16: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/16.jpg)
Deciding Equality
a = b, b = c, d = e, b = s, d = t, a e, a s
td,ea,b,c,s
![Page 17: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/17.jpg)
Deciding Equality
a = b, b = c, d = e, b = s, d = t, a e, a s
a,b,c,s d,e,t
![Page 18: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/18.jpg)
Deciding Equality
a = b, b = c, d = e, b = s, d = t, a e, a s
a,b,c,s d,e,t
![Page 19: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/19.jpg)
Deciding Equality
a = b, b = c, d = e, b = s, d = t, a e, a s
a,b,c,s d,e,t
Unsatisfiable
![Page 20: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/20.jpg)
Deciding Equality
a = b, b = c, d = e, b = s, d = t, a e
a,b,c,s d,e,t
Model construction
![Page 21: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/21.jpg)
Deciding Equality
a = b, b = c, d = e, b = s, d = t, a e
a,b,c,s d,e,t
Model construction|M| = {1 ,2} (universe, aka domain)
1 2
![Page 22: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/22.jpg)
Deciding Equality
a = b, b = c, d = e, b = s, d = t, a e
a,b,c,s d,e,t
Model construction|M| = {1 ,2} (universe, aka domain)
M(a) = 1 (assignment)
1 2
![Page 23: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/23.jpg)
Deciding Equality
a = b, b = c, d = e, b = s, d = t, a e
a,b,c,s d,e,t
Model construction|M| = {1 ,2} (universe, aka domain)
M(a) = 1 (assignment)
1 2
Alternative notation:aM = 1
![Page 24: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/24.jpg)
Deciding Equality
a = b, b = c, d = e, b = s, d = t, a e
a,b,c,s d,e,t
Model construction|M| = {1 ,2} (universe, aka domain)
M(a) = M(b) = M(c) = M(s) = 1
M(d) = M(e) = M(t) = 2
1 2
![Page 25: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/25.jpg)
Deciding Equality:Termination, Soundness, Completeness
Termination: easySoundness
Invariant: all constants in a “ball” are known to be equal.The “ball” merge operation is justified by:
Transitivity and Symmetry rules.Completeness
We can build a model if an inconsistency was not detected.Proof template (by contradiction):
Build a candidate model.Assume a literal was not satisfied.Find contradiction.
![Page 26: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/26.jpg)
Deciding Equality:Termination, Soundness, Completeness
CompletenessWe can build a model if an inconsistency was not detected.Instantiating the template for our procedure:
Assume some literal c = d is not satisfied by our model.That is, M(c) ≠ M(d).This is impossible, c and d must be in the same “ball”.
c,d,…i
M(c) = M(d) = i
![Page 27: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/27.jpg)
Deciding Equality:Termination, Soundness, Completeness
CompletenessWe can build a model if an inconsistency was not detected.Instantiating the template for our procedure:
Assume some literal c ≠ d is not satisfied by our model.That is, M(c) = M(d).Key property: we only check the disequalities after we processed all equalities.This is impossible, c and d must be in the different “balls”
c,… M(c) = i
M(d) = j
i
d,…j
![Page 28: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/28.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, f(a, g(d)) f(b, g(e))
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
![Page 29: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/29.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, f(a, g(d)) f(b, g(e))
First Step: “Naming” subterms
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
![Page 30: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/30.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, f(a, v1) f(b, g(e))v1 g(d)
First Step: “Naming” subterms
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
![Page 31: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/31.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, f(a, v1) f(b, g(e))v1 g(d)
First Step: “Naming” subterms
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
![Page 32: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/32.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, f(a, v1) f(b, v2)v1 g(d), v2 g(e)
First Step: “Naming” subterms
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
![Page 33: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/33.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, f(a, v1) f(b, v2)v1 g(d), v2 g(e)
First Step: “Naming” subterms
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
![Page 34: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/34.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, v3 f(b, v2)v1 g(d), v2 g(e), v3 f(a, v1)
First Step: “Naming” subterms
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
![Page 35: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/35.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, v3 f(b, v2)v1 g(d), v2 g(e), v3 f(a, v1)
First Step: “Naming” subterms
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
![Page 36: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/36.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, v3 v4
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)
First Step: “Naming” subterms
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
![Page 37: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/37.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, v3 v4
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
a,b,c,s d,e,t v1 v2 v3 v4
![Page 38: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/38.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, v3 v4
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
d = e implies g(d) = g(e)
a,b,c,s d,e,t v1 v2 v3 v4
![Page 39: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/39.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, v3 v4
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
d = e implies v1 = v2
a,b,c,s d,e,t v1 v2 v3 v4
![Page 40: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/40.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, v3 v4
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
d = e implies v1 = v2
a,b,c,s d,e,t v1,v2 v3 v4
We say:v1 and v2 are congruent.
![Page 41: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/41.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, v3 v4
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
a = b, v1 = v2 implies f(a, v1) = f(b, v2)
a,b,c,s d,e,t v1,v2 v3 v4
![Page 42: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/42.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, v3 v4
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
a = b, v1 = v2 implies v3 = v4
a,b,c,s d,e,t v1,v2 v3 v4
![Page 43: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/43.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, v3 v4
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
a = b, v1 = v2 implies v3 = v4
a,b,c,s d,e,t v1,v2 v3,v4
![Page 44: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/44.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, v3 v4
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
a,b,c,s d,e,t v1,v2 v3,v4
Unsatisfiable
![Page 45: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/45.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, a v4, v2 v3
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
a,b,c,s d,e,t v1,v2 v3,v4
Changing the problem
![Page 46: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/46.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, a v4, v2 v3
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
a,b,c,s d,e,t v1,v2 v3,v4
![Page 47: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/47.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, a v4, v2 v3
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)
Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)
a,b,c,s d,e,t v1,v2 v3,v4
![Page 48: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/48.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, a v4, v2 v3
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)
Model construction:|M| = {1 ,2 ,3 ,4}
M(a) = M(b) = M(c) = M(s) = 1
M(d) = M(e) = M(t) = 2
M(v1) = M(v2) = 3
M(v3) = M(v4) = 4
a,b,c,s d,e,t v1,v2 v3,v4
1 2 3 4
![Page 49: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/49.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, a v4, v2 v3
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)
Model construction:|M| = {1 ,2 ,3 ,4}
M(a) = M(b) = M(c) = M(s) = 1
M(d) = M(e) = M(t) = 2
M(v1) = M(v2) = 3
M(v3) = M(v4) = 4
a,b,c,s d,e,t v1,v2 v3,v4
1 2 3 4
Missing:Interpretation for f and g.
![Page 50: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/50.jpg)
Deciding Equality + (uninterpreted) Functions
Building the interpretation for function symbols
M(g) is a mapping from |M| to |M|Defined as:
M(g)(i) = j if there is v g(a) s.t.M(a) = i
M(v) = j
= k, otherwise (k is an arbitrary element)Is M(g) well-defined?
![Page 51: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/51.jpg)
Deciding Equality + (uninterpreted) Functions
Building the interpretation for function symbols
M(g) is a mapping from |M| to |M|Defined as:
M(g)(i) = j if there is v g(a) s.t.M(a) = i
M(v) = j
= k, otherwise (k is an arbitrary element)Is M(g) well-defined?
Problem: we may have v g(a) and w g(b) s.t.M(a) = M(b) = 1 and M(v) = 2 ≠ 3 = M(w)So, is M(g)(1) = 2 or M(g)(1) = 3?
![Page 52: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/52.jpg)
Deciding Equality + (uninterpreted) Functions
Building the interpretation for function symbols
M(g) is a mapping from |M| to |M|Defined as:
M(g)(i) = j if there is v g(a) s.t.M(a) = i
M(v) = j
= k, otherwise (k is an arbitrary element)Is M(g) well-defined?
Problem: we may have v g(a) and w g(b) s.t.M(a) = M(b) = 1 and M(v) = 2 ≠ 3 = M(w)So, is M(g)(1) = 2 or M(g)(1) = 3?
This is impossible because of the congruence rule!a and b are in the same “ball”, then so are v and w
![Page 53: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/53.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, a v4, v2 v3
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)
Model construction:|M| = {1 ,2 ,3 ,4}
M(a) = M(b) = M(c) = M(s) = 1
M(d) = M(e) = M(t) = 2
M(v1) = M(v2) = 3
M(v3) = M(v4) = 4
a,b,c,s d,e,t v1,v2 v3,v4
1 2 3 4
![Page 54: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/54.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, a v4, v2 v3
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)Model construction:|M| = {1 ,2 ,3 ,4}
M(a) = M(b) = M(c) = M(s) = 1
M(d) = M(e) = M(t) = 2
M(v1) = M(v2) = 3
M(v3) = M(v4) = 4
M(g)(i) = j if there is v g(a) s.t.M(a) = i
M(v) = j
= k, otherwise
![Page 55: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/55.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, a v4, v2 v3
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)Model construction:|M| = {1 ,2 ,3 ,4}
M(a) = M(b) = M(c) = M(s) = 1
M(d) = M(e) = M(t) = 2
M(v1) = M(v2) = 3
M(v3) = M(v4) = 4
M(g) = {2 →3}
M(g)(i) = j if there is v g(a) s.t.M(a) = i
M(v) = j
= k, otherwise
![Page 56: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/56.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, a v4, v2 v3
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)Model construction:|M| = {1 ,2 ,3 ,4}
M(a) = M(b) = M(c) = M(s) = 1
M(d) = M(e) = M(t) = 2
M(v1) = M(v2) = 3
M(v3) = M(v4) = 4
M(g) = {2 →3}
M(g)(i) = j if there is v g(a) s.t.M(a) = i
M(v) = j
= k, otherwise
![Page 57: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/57.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, a v4, v2 v3
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)Model construction:|M| = {1 ,2 ,3 ,4}
M(a) = M(b) = M(c) = M(s) = 1
M(d) = M(e) = M(t) = 2
M(v1) = M(v2) = 3
M(v3) = M(v4) = 4
M(g) = {2 →3, else →1}
M(g)(i) = j if there is v g(a) s.t.M(a) = i
M(v) = j
= k, otherwise
![Page 58: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/58.jpg)
Deciding Equality + (uninterpreted) Functions
a = b, b = c, d = e, b = s, d = t, a v4, v2 v3
v1 g(d), v2 g(e), v3 f(a, v1) , v4 f(b, v2)Model construction:|M| = {1 ,2 ,3 ,4}
M(a) = M(b) = M(c) = M(s) = 1
M(d) = M(e) = M(t) = 2
M(v1) = M(v2) = 3
M(v3) = M(v4) = 4
M(g) = {2 →3, else →1}M(f) = { (1 ,3) →4, else →1}
M(g)(i) = j if there is v g(a) s.t.M(a) = i
M(v) = j
= k, otherwise
![Page 59: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/59.jpg)
Deciding Equality + (uninterpreted) Functions
What about predicates?
p(a, b), p(c, b)
![Page 60: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/60.jpg)
Deciding Equality + (uninterpreted) Functions
What about predicates?
p(a, b), p(c, b)
fp(a, b) = T, fp (c, b) ≠ T
![Page 61: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/61.jpg)
E-satisfiability - examplef(f(a)) = a, a f(a)
![Page 62: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/62.jpg)
Congruence Closure Graph
![Page 63: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/63.jpg)
Congruence Closure Graph
![Page 64: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/64.jpg)
Congruence Closure Graph
![Page 65: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/65.jpg)
Congruence Closure Graph
![Page 66: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/66.jpg)
Congruence Closure Graph
![Page 67: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/67.jpg)
Congruence Closure Graph
![Page 68: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/68.jpg)
Conguruence Closure GraphRecall congruence rule:
Congruence:
t1= s1 .. tn =sn f(t1, …, tn) = f(s1, …, sn)
![Page 69: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/69.jpg)
Congruence Closure Graph
![Page 70: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/70.jpg)
Congruence Closure Graph
![Page 71: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/71.jpg)
Congruence Closure Graph
![Page 72: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/72.jpg)
Congruence Closure Graph
![Page 73: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/73.jpg)
Congruence Closure Graph
![Page 74: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/74.jpg)
Congruence Closure Graph
![Page 75: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/75.jpg)
Congruence closure graphLet G = (V,E) be a directed graph such that for each vertex v in G, the successors (children) of v are ordered.Let C be any equivalence relation on V.The congruence closure C* of C is the finest equivalence relation on V,
that contains C : v C w then v C* w Closed: If
children(v) = v1 ..vn
children(w) = w1 ..wn Then v C* w v1 C* w1 … vn C* wn
![Page 76: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/76.jpg)
Congruence closure graphFrom literals L to a congruence graph.
For each subterm t in L create a vertex vt
For each function symbol f create vertex vf
If t = f(t1, …, tn), let children(vt) = vf, vt1, …, vtn
From literals L to an initial equivalence CInitially C = { { v } | v V }For each equality t = s L:
Merge equivalence classes for vt and vs
![Page 77: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/77.jpg)
Computing congruence closureFrom the definition, we can read off that Congruence
closure is the least fixed-point of the operator CongClos:
CongClos(C* )(v,w) =
v C w or let v1 .. vn = children(v)
let w1 ..wn = children(w) in CongClos(C*
)(v1, w1) .. CongClos(C*
)(vn, wn)
![Page 78: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/78.jpg)
Computing Congruence closure
Fixed-point characterization suggests (dynamic programming) algorithm:
Maintain root vertex for each equivalence class.Maintain sig(nature) of each vertex:
sig(vf(t1,..,tn)) = root(vf ), root(vt1).. root(vtn) Initialize C* Cwhile v,w V s.t. v C* w, but sig(v) = sig(w):
C* C* with classes for v, w merged
![Page 79: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/79.jpg)
Computing Congruence closure
A more efficient implementation of congruence closureUse union-find for maintaining rootsMaintain use (a list) for set of parent vertices.Set todo = {}def merge(v, w):
C* C* with classes for v, w merged foreach vp use(v), wp use(w):
add vp, wp to todo foreach asserted equality (v,w): merge(v,w)while some v, w todo : remove v, w from todo if v C* w, but sig(v) = sig(w) then merge(v,w)
![Page 80: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/80.jpg)
Using congruence closureBack to the main problem.
E-satisfiability t1 = t2 t3 = t4 t5 t6
Form graph using {t1, t2, t3 , t4 , t5 , t6 }Initialize C from equalitiesCompute C* from CCheck that vt5 C* vt6
![Page 81: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/81.jpg)
Congruence closure algorithmSoundness: C* just simulates axioms of E.
Completeness: From C* build model M.fM(v1, …, vn) = root(v),
if there is a v, such that sig(v) = fM,v1, …, vn fM(v1, …, vn) = *
otherwiseThen all axioms in E are true in M.All equalities in L are true in M.
![Page 82: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/82.jpg)
DPLL(E)Congruence closure just checks satisfiability of conjunction of literals.
How does this fit together with Boolean search DPLL?
DPLL builds partial model M incrementallyUse M to build C*
After every Decision or Propagate, orWhen F is propositionally satisfied by M.
Check that disequalities are satisfied.
![Page 83: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/83.jpg)
E - conflictsRecall Conflict:
Conflict M || F M || F || C if CF, M ⊨T C
A version more useful for theories:
Conflict M || F M || F || C if C M, ⊨T C
![Page 84: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/84.jpg)
E - conflictsExample
M = fff(a) = a, g(b) = c, fffff(a)= a, a f(a) C = fff(a) = a, fffff(a)=a, a f(a)⊨E fff(a) a fffff(a) a a = f(a)
Use C as a conflict clause.
![Page 85: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/85.jpg)
E - conflictsHow can one mine M for E-conflicts?
![Page 86: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/86.jpg)
ConvexityThe theory E is convex.
Convexity: Let L be a set of equalities and disequalitiesIf L ⊨E s1 = t1 … sn = tn Then for some i: L ⊨E si = ti (proof: use soundess and completeness of Congruence Closure).
A consequence:To check satisfiability it suffices to check each disequality in isolation.
![Page 87: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/87.jpg)
Inference rules, Abstract decision procdures, and Datalog Consider Datalog formulation: Rule formulation:
Eq(x,x) .Eq(x,y) :- Eq(y,x).Eq(x,y) :- Eq(x,z), Eq(z,y) .Eq(u,v) :- Eq(x,y), F(x,u), F(y,v) .
F(a,f(a)) . F(b, f(b)) . Eq(a,b) .?- Eq(f(a),f(b)) .
Congruence closure algorithm is “just” an efficient way of computing closure of Eq(_,_).
𝑥∼𝑦𝑦∼𝑥
𝑥∼𝑦 𝑦∼𝑧𝑥∼𝑧
𝑥∼𝑦𝑢≡ 𝑓 (𝑥 ) ,𝑣≡ 𝑓 ( 𝑦 )𝑢∼𝑣
𝑥∼𝑥
![Page 88: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/88.jpg)
Arrays
![Page 89: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/89.jpg)
Why use abstract arrays?def swap(a, i, j): tmp = a[i]; a[i] = a[j]; a[j] = tmp;
new(a)[i] = a[j]new(a)[j] = a[i]k i, k j a[k] = new(a)[k]
def swap(a, i, j): tmp = a[i]; a = write(a,i,a[j]); a= write(a,j,tmp);
def swap(a, i, j): tmp = a[i]; a1= write(a,i,a[j]); a2= write(a1,j,tmp); new(a) = a2
new(a) = let tmp = a[i] a1= write(a,i,a[j]); a2= write(a1,j,tmp); in a2
new(a) = write(write(a,i,a[j]),j,a[i])
new(a)[j] = write(write(a,i,a[j]),j,a[i])[j] = a[i]
new(a)[i] = write(write(a,i,a[j]),j,a[i])[i] = if i = j then a[i] else write(a,i,a[j])[i] =if i = j then a[i] else a[j] =a[j]
![Page 90: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/90.jpg)
Theory of arraysFunctions: F = { read, write }Predicates: P = { = }Convention a[i] means: read(a,i)
Non-extensional arrays TA: a, i, v . write(a,i,v)[i] = va, i, j, v . i j write(a,i,v)[j] = a[j]
Extensional arrays: TEA = TA + a, b. ((i. a[i] = b[i]) a = b)
![Page 91: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/91.jpg)
Array examples
( , , ) [ ] [ ]b write a i v i j b j a j
( , , )( , , )
[ ] [ ]
b write a i vc write a j ww b j v c i b c
![Page 92: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/92.jpg)
Array examples( , , ) [ ] [ ]b write a i v i j b j a j
( , , ) [ ] [ ]b write a i v i j b j a j
Is valid
Is unsat
( , , ) [ ] [ ]( ( , , )[ ] [ ])b write a i v i j b j a ji j write a i v j a j
Is unsat(arrayaxiom)
( , , )[ ] [ ] ( , , )[ ] [ ]b write a i v i ja j b j write a i v j a j
Is unsat(congruence)
![Page 93: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/93.jpg)
Array examplesIs valid
Is unsat
( , , )( , , )
[ ] [ ]
b write a i vc write a j ww b j v c i b c
( , , )( , , )
[ ] [ ]
b write a i vc write a j ww b j v c i b c
![Page 94: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/94.jpg)
Array examplesIs unsat( , , )
( , , )[ ][ ]
b write a i vc write a j ww b jv c ib c
[ ] ( , , )[ ][ ] ( , , )[ ]
w b j write a i v jv c i write a j w i
( , , )[ ] [ ]i j write a i v j a j Array axiom
![Page 95: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/95.jpg)
Array examplesIs unsat( , , )
( , , )[ ] ( , , )[ ][ ] ( , , )[ ]
( , , )[ ] [ ]( , , )[ ] [ ]
b write a i vc write a j ww b j write a i v jv c i write a j w ib ci j write a i v j a ji j write a j w i a i
![Page 96: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/96.jpg)
Array examplesCase:
( , , )( , , )
[ ] ( , , )[ ][ ] ( , , )[ ]
b write a i vc write a j ww b j write a i v jv c i write a j w ib ci j
i j
![Page 97: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/97.jpg)
Array examplesCase:( , , )
( , , )[ ] ( , , )[ ][ ] ( , , )[ ]
( , , )[ ]
b write a i vc write a j ww b j write a i v jv c i write a j w ib ci jwrite a i v i v
i j
Array axiom
![Page 98: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/98.jpg)
Array examplesCase:
( , , )( , , )
[ ] ( , , )[ ][ ] ( , , )[ ]
( , , )[ ]
b write a i vc write a j ww b j write a i v jv c i write a j w ib ci jwrite a i v i vw v
i j
![Page 99: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/99.jpg)
Array examplesCase:
( , , )( , , )
[ ] ( , , )[ ][ ] ( , , )[ ]
( , , )[ ]
b write a i vc write a j ww b j write a i v jv c i write a j w ib ci jwrite a i v i vw vb c
i j
Congruence
![Page 100: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/100.jpg)
Array examples – a few steps
Case:( , , )( , , )
[ ] ( , , )[ ][ ] ( , , )[ ]
( , , )[ ] [ ]( , , )[ ] [ ]
b write a i vc write a j ww b j write a i v jv c i write a j w ib cwrite a i v j a jwrite a j w i a i
i j
![Page 101: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/101.jpg)
Array examplesCase:
( , , )( , , )
[ ] ( , , )[ ] [ ][ ] ( , , )[ ] [ ]
b write a i vc write a j ww b j write a i v j a jv c i write a j w i a ib c
i j
![Page 102: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/102.jpg)
Array examplesCase:
( , , )( , , )
[ ] ( , , )[ ] [ ][ ] ( , , )[ ] [ ]
( . [ ] [ ])
b write a i vc write a j ww b j write a i v j a jv c i write a j w i a ib ck b k c k b c
i j
Extensionality
![Page 103: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/103.jpg)
Array examplesCase:
( , , )( , , )
[ ] ( , , )[ ] [ ][ ] ( , , )[ ] [ ]
( . [ ] [ ])
b write a i vc write a j ww b j write a i v j a jv c i write a j w i a ib c
k b k c k
i j
Extensionality
![Page 104: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/104.jpg)
Array examplesCase:
( , , )( , , )
[ ] ( , , )[ ] [ ][ ] ( , , )[ ] [ ]
[ ] [ ]
b write a i vc write a j ww b j write a i v j a jv c i write a j w i a ib cb k c k
i j
Skolemize
![Page 105: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/105.jpg)
Array examplesCase:
( , , )( , , )
[ ] ( , , )[ ] [ ][ ] ( , , )[ ] [ ]
[ ] [ ]( ( , , )[ ] [ ])( ( , , )[ ] [ ])
b write a i vc write a j ww b j write a i v j a jv c i write a j w i a ib cb k c ki k write a i v k b kj k write a j w k c k
i j
Array axiom
![Page 106: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/106.jpg)
Array examplesCase:
( , , )( , , )
[ ] ( , , )[ ] [ ][ ] ( , , )[ ] [ ]
[ ] [ ]( ( , , )[ ] [ ])( ( , , )[ ] [ ])
b write a i vc write a j ww b j write a i v j a jv c i write a j w i a ib cb k c ki k write a i v k b kj k write a j w k c kyadayadayada
i j
![Page 107: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/107.jpg)
Decision procedures for arraysLet L be literals over F = { read, write }
Find M such that: M ⊨TA L
Basic algorithm, reduce to E: for every sub-term read(a,i), write(b,j,v) in L
i j a = b read(write(b,j,v),i) = read(a,i)read(write(b,j,v),j) = v
Find ME, such thatME ⊨E L AssertedAxioms
![Page 108: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/108.jpg)
Decision procedures for arraysCorrectness of basic algorithm:
ME satisfies array axioms on terms in L.To show that ME can be extended to model for arrays:
From Congurence Closure C* build model:aM = [| *d1 *r1 , *d2 *r2 , *d3 .., else vroot(a) |]Where readM(aM, *di ) = *r1 e.g., *r1 = root(read(root(a),root(i)) under C*
Model satisfies array axioms.For every write(a,i,v) the model satisfies write(a,i,v)[j] = a[j] whenever iM jM (first axiom) and also write(a,i,v)[i] = v (second axiom).vroot(a) was added to make arrays different unless they were forced to be (no extensionality)
![Page 109: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/109.jpg)
Non-extensionalityA non-theorem
a and b need not be equal even if the array axioms hold.
( , , ) [ ]b write a i v a i v a b
![Page 110: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/110.jpg)
Extensional arraysTo enforce:
a, b. ((i. a[i]= b[i]) a = b)
For every pair a, b in L, Add fresh constant iab
Add axiom a b a[iab] b[iab]
![Page 111: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/111.jpg)
Arrays galoreArrays may be more than just read/write.
The constant array:v, i . const(v)[i] = v
Generalized write: a,b,c, i . a[i] = b[i] write(a,b,c)[i] = c[i] a,b,c, i . a[i] b[i] write(a,b,c)[i] = b[i]We now have sets: = const(false), T = const(true), A B = write(,A,B)[i] A B = write(T,A,B)[i]
Ranges:l,u, x . range(l,u)[x] l x u
![Page 112: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/112.jpg)
Arrays galoreClaim: Same kind of reduction to E (and arithmetic) works
Integer ranges, require slightly morerange(l,u)[l-1], range(l,u)[u+1]range(l,u)[l], range(l,u)[u]
Is there a general principle underpinning such extensions?
![Page 113: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/113.jpg)
Arrays galoreConsider a more general formulation. is a conjunction of:
Equalities, disequalities i, j, k . G(i,j,k) F(i,j,k)
Where G is a guard formula comparing indices:And-or formula of i j, i cClaim: We can always eliminate i =j from the guard.
Where F is a general formula with arrays, Restriction: no nested array formulas.
Example: j . if i = j then b[i] = v else b[i] = a[i]Encodes that b = write(a,i,v)
![Page 114: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/114.jpg)
Arrays galore i, j, k . G(i,j,k) F(i,j,k)
Where G is a guard formula comparing indices:And-or formula of i j, i cClaim: We can always eliminate i =j or i = c from the guard.
i, j, k . i = j k c j c’ F(i,j,k) i, k . k c i c F(i,i,k)
![Page 115: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/115.jpg)
Arrays galore i, j, k . G(i,j,k) F(i,j,k)
Where G is a guard formula comparing indices:And-or formula of i j, i cClaim: We can always or from the guard
i, j, k . G(i,j,k) G’(i,j,k) F(i,j,k)
i, j, k . G(i,j,k) F(i,j,k) i, j, k . G’(i,j,k) F(i,j,k)
![Page 116: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/116.jpg)
Arrays galore i, j, k . G(i,j,k) F(i,j,k)
Where G is conjunction of i j, i c
Decision procedure:Collect all c, where a[c] or c = i Instantiate quantifiers by all combinations of such indices.Check for E – satisfiability of ground formula.
Correctness: All quantified formulas are satisfied by C* .
![Page 117: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/117.jpg)
Arrays galore - Arithmetic i, j, k . G(i,j,k) F(i,j,k)
Where G is conjunction of i < j, i < c, i > c
Decision procedure:Collect all c, where a[c], c < i , c > i occurs in formula.For each c, also add c-1, c+1 to collection.Instantiate quantifiers by all combinations of collected indices.Check for ILA + E – satisfiability of ground formula.
![Page 118: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/118.jpg)
Combinatory Array Logic
![Page 119: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/119.jpg)
What else are arrays?Special combinators:
Result: Existential fragment is decidable and in NP by reduction to congruence closure using finite set of instances. ( f belongs to base theory – not arrays)
( , , ) . ( , , [ ])
( ) .
( , ) . ( [ ], [ ])f
write a i v j ite i j v a j
K v j v
map a b j f a j b j
![Page 120: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/120.jpg)
… A different fragment:
Then:
Theory is decidable.
( ) .
( , , ) . ( [ ], [ ], [ ])
( , ) .( [ ] [ ])
.
ite
K v j v
map a b c j ite a j b j c j
map a b j a j b j
I j j
( , , ) ( ( ( ), ), ( ), )itewrite a i v map map K i I K v a
![Page 121: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/121.jpg)
Last combinator for the road…Can I access a default array value?
( )
( ( ))( ( , )) ( ( ), ( ))
( ( , , )) ( )
f
a default
K v vmap a b f a b
write a i v a
Only sound for infinite domains
![Page 122: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/122.jpg)
Let’s use CAL:Simple set and bag operations:
But not cardinality |A|, power-set 2A, …
min
(0)( ){ } ( , ,1){ } ( , , )( , ) [ ][ ]
( , )( , )( , )( , )
( ) ( ( ) 0)( ) ( ( ) )
Bag
Bag
KK falsea write aa write a true
mult a A A aa A A aA B map A BA B map A BA B map A BA B map A B
finite A Afinite A A false
![Page 123: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/123.jpg)
A Basic Decision Procedure
![Page 124: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/124.jpg)
A reduction-based approach
( )?ArraySat T
( ( ) )?Equality ArraySat T Closure
Use saturation rules to reduce arrays to the theory of un-interpreted functions
Extract models for arrays as finite graphs
![Page 125: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/125.jpg)
Array Saturation Rules
a~b – a and b are equal in current contexta≡t – a is a name for the term t
![Page 126: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/126.jpg)
Congruence Closure Rule
![Page 127: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/127.jpg)
Bottlenecks Extensionality axiom is
instantiated on every pair of array variables.
Upwards propagation distributes index over all modifications of same array.
![Page 128: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/128.jpg)
Bottlenecks and Bottleneck:
Extensionality axiom is instantiated on every pair of array variables.
Optimization: Restrict to variables asserted different, or shared.
![Page 129: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/129.jpg)
Bottlenecks and Bottleneck: Upwards
propagation distributes index over all modifications of same array.Optimization: Only use for updates where ancestor has multiple children. Formulas from programs are well-behaved.
![Page 130: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/130.jpg)
The effect on benchmarksThis is where it matters
![Page 131: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/131.jpg)
Saturating for CAL
![Page 132: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/132.jpg)
Saturating K, map,
![Page 133: Solvers: Equality and Arrays Lecture 4 2012](https://reader035.fdocuments.in/reader035/viewer/2022070421/56816186550346895dd11ea6/html5/thumbnails/133.jpg)
Saturating K, map, Rules for map are similar as for store.
Optimization of has to be generalized.
Finite domains…