A decision procedure for equivalence relations Sbastien Michelland - - PowerPoint PPT Presentation

a decision procedure for equivalence relations
SMART_READER_LITE
LIVE PREVIEW

A decision procedure for equivalence relations Sbastien Michelland - - PowerPoint PPT Presentation

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion A decision procedure for equivalence relations Sbastien Michelland with Pierre Corbineau, Lionel Rieg and Karine Altisen July 5, 2020 1 / 14 (CC BY-ND)


slide-1
SLIDE 1

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion

A decision procedure for equivalence relations

Sébastien Michelland with Pierre Corbineau, Lionel Rieg and Karine Altisen July 5, 2020

1 / 14 (CC BY-ND)

slide-2
SLIDE 2

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion

Congruence closure

f = g, x = y, f (x) = z

  • Hypotheses

⊢ g(y) = z

  • Goal

◮ Terms: variable | term term ◮ Deduction rules: Reflexivity Symmetry Transitivity f = g x = y f (x) = g(y) CONGRUENCE ◮ The congruence closure algorithm decides by saturation.

2 / 14 (CC BY-ND)

slide-3
SLIDE 3

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion

Congruence closure: example

f = g, x = y, f (x) = z ⊢ g(y) = z

3 / 14 (CC BY-ND)

slide-4
SLIDE 4

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion

Congruence closure: example

f = g, x = y, f (x) = z ⊢ g(y) = z ◮ Partition terms into equal class: f g x y f (x) g(y) z

3 / 14 (CC BY-ND)

slide-5
SLIDE 5

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion

Congruence closure: example

f = g, x = y, f (x) = z ⊢ g(y) = z ◮ Partition terms into equal class: f g x y f (x) g(y) z ◮ The partition is reflexive, symmetric and transitive, so it saturates three out of four rules

3 / 14 (CC BY-ND)

slide-6
SLIDE 6

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion

Congruence closure: example

f = g, x = y, f (x) = z ⊢ g(y) = z ◮ Partition terms into equal class: f g x y f (x) g(y) z ◮ The partition is reflexive, symmetric and transitive, so it saturates three out of four rules

3 / 14 (CC BY-ND)

slide-7
SLIDE 7

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion

Congruence closure: example

f = g, x = y, f (x) = z ⊢ g(y) = z ◮ Partition terms into equal class: f g x y f (x) g(y) z ◮ The partition is reflexive, symmetric and transitive, so it saturates three out of four rules ◮ No new terms are needed, the input is enough! ◮ Decides in quasi-linear time.

3 / 14 (CC BY-ND)

slide-8
SLIDE 8

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion

Proof generation

[NO05]

◮ "Deciding is cool but not as cool as proving" – Coq, probably f g x y f (x) g(y) z

Hyp Hyp Hyp

CONGRUENCE

We can generate proof trees! ◮ g(y) = z by transitivity, with g(y) = f (x) by congruence (subproofs g = f and y = x)

4 / 14 (CC BY-ND)

slide-9
SLIDE 9

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion

Limitations

[Cor06]

◮ congruence implemented in Coq by Pierre Corbineau (2001) (with extra features) A couple limitations: ◮ In Coq f = g is a definitional equality (not useful) ◮ Propositional equality P = Q is also poor ◮ What about setoids and typeclasses? Let’s try equivalence relations.

5 / 14 (CC BY-ND)

slide-10
SLIDE 10

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion

Equivalence relations... and PERs

◮ Let’s replace = with equivalence relations. ◮ For functions, we’ll use the respectful relation f (R1 ⇒ R2) g ≡ ∀(x, y), x R1 y → f (x) R2 g(y) f (R1 ⇒ R2) g x R1 y f (x) R2 g(y) CONGRUENCE ◮ But R1 ⇒ R2 is only symmetric and transitive, it’s a partial equivalence relation (PER)! Let’s include PERs and improve the partition.

6 / 14 (CC BY-ND)

slide-11
SLIDE 11

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion

Completed relation of a PER

New idea: completed relation

To represent a PER in a partition, consider x ˆ R y ≡ x R x ∨ y R y → x R y. R: Isolated elements nr1 nr2 nr3 Normal equivalence classes x y z u v w ◮ ˆ R is a canonical equivalence relation associated with R

7 / 14 (CC BY-ND)

slide-12
SLIDE 12

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion

Completed relation of a PER

New idea: completed relation

To represent a PER in a partition, consider x ˆ R y ≡ x R x ∨ y R y → x R y. ˆ R: Completed class nr1 nr2 nr3 Normal equivalence classes x y z u v w ◮ ˆ R is a canonical equivalence relation associated with R

7 / 14 (CC BY-ND)

slide-13
SLIDE 13

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion

Implementing the new congruence closure

◮ First version on the command-line ◮ Input: Coq-like text file, output: decision and proof tree ◮ Plus your everyday unit tests and coqc for proofs We already gained some cool expressiveness! Example: ◮ Equality of lists as multisets: =MS ◮ Concatenation preserves =MS: app (=MS⇒=MS⇒=MS) app

8 / 14 (CC BY-ND)

slide-14
SLIDE 14

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion

Relation inclusions

List equality ⊆ Multiset equality ⊆ Set equality ◮ Propagate each equality to larger relations x R1 y R1 ⊆ R2 x R2 y INCLUSION ◮ Fast to saturate, so integrates nicely in the closure! ◮ PER compatibility : R1 ⊑ R2 if operands of R2 can be rewritten with equivalent terms for R1. ◮ R1 ⊑ R2 is equivalent to R1 ⊆ ˆ R2, so we can saturate it!

9 / 14 (CC BY-ND)

slide-15
SLIDE 15

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion

Quantified hypotheses

∀v1 . . . vn, x R y ◮ Very expressive!

◮ Associativity: ∀(l1, l2, l3), l1 + (l2 + l3) = (l1 + l2) + l3 ◮ Commutativity for =MS : ∀(l1, l2), l1 + + l2 =MS l2 + + l1

How to use them in the algorithm? ◮ Main concern: find v1 . . . vn such that x or y is a known term. ◮ We then add x R y and continue saturating (semi-decidable!)

10 / 14 (CC BY-ND)

slide-16
SLIDE 16

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion

Ematching to find v1 . . . vn

∀x, f (e, x) R x − → f e ?x and ?x ◮ Find in a class C of R an instance of a pattern p: p ∼=R C We want to find v1 . . . vn and t ∈ C such that p(v1 . . . vn) R t. ◮ By induction. For the inductive case f pattern1 . . . patternn , look only in classes that contain calls to f with n arguments (maintained like the signature table)

11 / 14 (CC BY-ND)

slide-17
SLIDE 17

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion

Combinatorial issues and termination

◮ Equalities are not oriented: termination issues x = f (e, x) = f (e, f (e, x)) = . . . ◮ Risks of combinatorial explosion (Equivalence forms modulo associativity and commutativity!) Hard questions and SMT heuristics! ◮ Here: we use ematching to find instances and stop after a fixed number of rounds ◮ Inefficient but just as expressive!

12 / 14 (CC BY-ND)

slide-18
SLIDE 18

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion

Conclusion

◮ Extended congruence closure for small-scale automation ◮ Equivalence relations, proofs, inclusions, even quantification ◮ Plugin is on the way, includes typeclasses Early testers welcome, contact us! Future work: ◮ Use the setoid of propositions with iff ◮ Study relationships with SMT

13 / 14 (CC BY-ND)

slide-19
SLIDE 19

Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion

Job offer!

◮ Post-doctoral position, 1 year ◮ Univ. Grenoble-Alpes, VERIMAG (France) ◮ Starting Fall 2020 (flexible) Subject: Coq formalization and proof techniques for distributed algorithms ◮ Contacts:

Karine.Altisen@univ-grenoble-alpes.fr Pierre.Corbineau@univ-grenoble-alpes.fr

14 / 14 (CC BY-ND)

slide-20
SLIDE 20

Bibliography

Pierre Corbineau. Deciding equality in the constructor theory. In International Workshop on Types for Proofs and Programs, pages 78–92. Springer, 2006. Robert Nieuwenhuis and Albert Oliveras. Proof-producing congruence closure. In International Conference on Rewriting Techniques and Applications, pages 453–468. Springer, 2005.

slide-21
SLIDE 21

Coq session example

slide-22
SLIDE 22