Congruence in univalent type theory Luis Scoccola lscoccol@uwo.ca University of Western Ontario June 11, 2019
Goals for the talk ◮ Congruence and congruence closure for propositional equality. ◮ Solution of Selsam & de Moura for a non-univalent type theory. ◮ Proposed approach for congruence in the univalent case. ◮ Issues with congruence closure.
Informal definitions Definition A relation R satisfies congruence if ∀ f x i R y i for 0 ≤ i ≤ n ⇒ f ( x 1 , . . . , x n ) R f ( y 1 , . . . , y n ) . The congruence closure of R is the smallest equivalence relation that satisfies congruence and contains R. Example During a proof, determine whether x = y follows from applying reflexivity , symmetry , transitivity , or congruence lemmas to the equalities in our context.
Congruence in dependent type theory Propositional equality is an equivalence relation: refl : x = x inv : x = y → y = x concat : x = y → y = z → x = z Can also prove congruence lemma (for non-dependent function): congr f : ( f : A → B ) → ( x = A y ) → f ( x ) = B f ( y ) . But if f : ( a : A ) → B ( a ), the above doesn’t type check.
A solution: Heterogeneous equality Definition Heterogeneous equality is the inductive family heq : ( A , A ′ : U ) → A → A ′ → U generated by refl : ( A : U ) → ( a : A ) → heq( a , a ) . Selsam & de Moura implement full congruence closure procedure in Lean 3 using heq. Need to assume an axiom to prove the congruence lemmas: ofheq : ( A : U ) → ( x , y : A ) → heq( x , y ) → x = A y . The axiom ofheq implies that paths in U transport trivially: ( e : A = U A ) → a = transport X �→ X ( e , a ) . U can’t be univalent.
Congruence in univalent type theory? Use pathovers . Definition Given a type B : U and a type family X : B → U , the type family pathover : ( b , b ′ : B ) → ( b = b ′ ) → X ( b ) → X ( b ′ ) → U is defined by path induction. � e � x ′ for pathover( b , b ′ , e , x , x ′ ). We write x = B
The congruence lemma I will describe an inductive algorithm that produces: ◮ A pathover type for each dependent family. ◮ A congruence lemma for each dependent function. This is implemented as a tactic in Lean 3. We have to be careful with one thing: Congruence lemmas depend on previous congruence lemmas.
The congruence lemma (cont.) Example Congruence lemma for cons : ( n : N ) → A → vec A ( n ) → vec A (succ( n )) , should have type congr cons ( n , m : N ) ( x , y : A ) ( xs : vec A ( n )) ( ys : vec A ( m )) ( e 1 : n = m ) ( e 2 : x = y ) ( e 3 : xs = � e 1 � ys ) : cons( n , x , xs ) = vec A � congr succ ( e 1 ) � cons( m , y , ys ) where congr succ : ( n , m : N ) → ( n = m ) → succ( n ) = succ( m ).
The algorithm Given context Γ, and dependent function h : ( x 0 : A 0 ) → ( x 1 : A 1 ( x 0 )) → · · · → ( x n : A n ( x 1 , . . . , x n − 1 )) → A n +1 ( x 1 , . . . , x n ) , in context Γ. (1) Decompose the type of h as type families applied to dependent functions: write A i ( x i − 1 ) ≡ C i ( f i ( x i − 1 )) such that ◮ C i is not an application; i , . . . , f k ( i ) ◮ f i is a sequence f 1 of dependent functions. i
The algorithm (cont.) (2) Define the pathovers for the type families C i : Id C i : ≡ λ x i , x ′ i , e i , c , c ′ . congr C i ( x i , x ′ i , e i ) ∗ c = c ′ (3) Define the congruence for all the functions f k i : Recursively. Caveat: Each function might be a composite, so return the composite of the congruences.
The algorithm (cont.) (4) Define the congruence for h : congr h : ( x 0 : C 0 ) → ( x 1 : C 1 ( f 1 ( x 0 ))) → · · · → ( x n : C n ( f n ( x n − 1 ))) ( x ′ 0 : C 0 ) → ( x ′ 1 : C 1 ( f 1 ( x ′ 0 ))) → · · · → ( x ′ n : C n ( f n ( x ′ n − 1 ))) ( e 0 : Id C 0 ) → ( e 1 : Id C 1 (congr f 1 ( e 0 )) → · · · → ( e n : Id C n (congr f n ( e n − 1 )) → Id C n +1 (congr f n +1 ( e n )) , By path induction on the pathovers e 0 , · · · , e n , using refl.
Congruence lemma Also gives us a useful characterization of the identity types of: ◮ structures; ◮ iterated sigmas.
Congruence closure Work in progress: ◮ Must keep a congruence data structure for each type family. ◮ Coherence problems (e.g. congruence of concatenation is concatenation of congruences). ◮ Some of them can be dealt with by working in a cubical type theory (e.g. composite of congruences is definitionally equal to congruence of composites, inverse of inverse is identity). ◮ Different equalities between the same pair of elements: cannot use union-find data structure for congruence closure. Use graphs instead, but this is inefficient. These are not problems if we limit congruence closure to type families that depend on sets.
Thank you for listening!
Recommend
More recommend