a decision procedure for equivalence relations
play

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)


  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)

  2. Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion Congruence closure f = g , x = y , f ( x ) = z ⊢ g ( y ) = z � �� � � �� � Hypotheses Goal ◮ Terms: � variable � | � term � � term � ◮ Deduction rules: Reflexivity f = g x = y Symmetry C ONGRUENCE f ( x ) = g ( y ) Transitivity ◮ The congruence closure algorithm decides by saturation. 2 / 14 (CC BY-ND)

  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)

  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: x f ( x ) z f g y g ( y ) 3 / 14 (CC BY-ND)

  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: x f ( x ) z f g y g ( y ) ◮ The partition is reflexive, symmetric and transitive, so it saturates three out of four rules 3 / 14 (CC BY-ND)

  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: x f ( x ) z f g y g ( y ) ◮ The partition is reflexive, symmetric and transitive, so it saturates three out of four rules 3 / 14 (CC BY-ND)

  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: x f ( x ) z f g y g ( y ) ◮ 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)

  8. Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion Proof generation [NO05] ◮ "Deciding is cool but not as cool as proving" – Coq, probably x f ( x ) z f Hyp Hyp Hyp C ONGRUENCE g y g ( y ) 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)

  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)

  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 ( R 1 ⇒ R 2 ) g ≡ ∀ ( x , y ) , x R 1 y → f ( x ) R 2 g ( y ) f ( R 1 ⇒ R 2 ) g x R 1 y C ONGRUENCE f ( x ) R 2 g ( y ) ◮ But R 1 ⇒ R 2 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)

  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 . Normal equivalence classes Isolated elements nr 1 y u R : nr 2 x z nr 3 v w ◮ ˆ R is a canonical equivalence relation associated with R 7 / 14 (CC BY-ND)

  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 . Completed class Normal equivalence classes nr 1 y u ˆ R : nr 2 x z nr 3 v w ◮ ˆ R is a canonical equivalence relation associated with R 7 / 14 (CC BY-ND)

  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)

  14. Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion Relation inclusions List equality ⊆ Multiset equality ⊆ Set equality ◮ Propagate each equality to larger relations R 1 ⊆ R 2 x R 1 y I NCLUSION x R 2 y ◮ Fast to saturate, so integrates nicely in the closure! ◮ PER compatibility : R 1 ⊑ R 2 if operands of R 2 can be rewritten with equivalent terms for R 1 . ◮ R 1 ⊑ R 2 is equivalent to R 1 ⊆ ˆ R 2 , so we can saturate it! 9 / 14 (CC BY-ND)

  15. Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion Quantified hypotheses ∀ v 1 . . . v n , x R y ◮ Very expressive! ◮ Associativity: ∀ ( l 1 , l 2 , l 3 ) , l 1 + ( l 2 + l 3 ) = ( l 1 + l 2 ) + l 3 ◮ Commutativity for = MS : ∀ ( l 1 , l 2 ) , l 1 + + l 2 = MS l 2 + + l 1 How to use them in the algorithm? ◮ Main concern: find v 1 . . . v n 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)

  16. Congruence closure Equivalence and inclusions Quantified hypotheses Conclusion Ematching to find v 1 . . . v n ∀ 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 v 1 . . . v n and t ∈ C such that p ( v 1 . . . v n ) R t . ◮ By induction. For the inductive case f � pattern � 1 . . . � pattern � n , look only in classes that contain calls to f with n arguments (maintained like the signature table) 11 / 14 (CC BY-ND)

  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)

  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)

  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)

  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.

  21. Coq session example

Recommend


More recommend