Congruence of Bisimulation in a Non-Deterministic Call-By-Need Lambda Calculus Matthias Mann Johann Wolfgang Goethe-Universit¨ at, Frankfurt, Germany Congruence of Bisimulation – p. 1/21
Lambda Calculi and Equality Abramsky (’90) deterministic, Bisimulation = call-by-name Contextual Equiv. Ariola, Felleisen, deterministic, Conversion Wadler, et al. (’95) call-by-need ( let ) Kutzner, Schmidt- non-deterministic, Contextual Equiv. Schauß (’98) call-by-need ( let ) Moran, Sands, non-deterministic, Contextual Equiv. Carlsson (’99) call-by-need, letrec , case Howe (’89, ’96) class of languages, Bisimulation = no sharing Contextual Equiv. Congruence of Bisimulation – p. 2/21
� � λ ND = non-determinism + sharing Congruence proof non-trivial — language Λ ND simple: E ::= V | ( λx.E ) | ( E E ) | ( let x = E in E ) | ( pick E E ) Approximation ���� ���� ���� ���� n S → − − → λ ≈ λ ND λ ≈ � c � b ⇓ ND = ⇓ ≈ Congruence of Bisimulation – p. 3/21
Reduction Rules of the λ ND -Calculus let x = ( let y = t y in t x ) in s llet − − → let y = t y in ( let x = t x in s ) (llet) lapp ( let x = t x in s ) t − − → let x = t x in ( s t ) (lapp) lbeta ( λx.s ) t − − → let x = t in s (lbeta) let x = λy.r in D [ x ] cp − → let x = λy.r in D [ λy.r ] (cp) ndl ndr pick s t − → s pick s t − − → t (nd) Congruence of Bisimulation – p. 4/21
Non-Determinism and Sharing Sharing like in functional programming languages: Rule (cp) only copies abstractions Avoid duplication of work, in particular of non-deterministic choice points : lbeta ( λx.x + x ) ( pick a b ) − − → let x = pick a b in x + x instead of β ( λx.x + x ) ( pick a b ) − → pick a b + pick a b ☞ Necessary to equate e.g. λx. (2 ∗ x ) and λx. ( x + x ) Congruence of Bisimulation – p. 5/21
Convergence in λ ND n − → is unique up to (nd) Normal-order reduction Weak Head Normal Form (WHNF): L ∗ R [ λx.s ] let -environments: L ∗ R ::= [ ] | let x = e in L ∗ R Convergence: ∗ L ∗ n def t ⇓ L ∗ R [ λx.s ] ⇐ ⇒ t − → R [ λx.s ] Congruence of Bisimulation – p. 6/21
Normal-Order Reduction in λ ND Example: � � ( λx.x ) ( λy. ( λz.q )) r n, lbeta − − − − → let x = (( λy. ( λz.q )) r ) in x n, lbeta − − − − → let x = ( let y = r in ( λz.q )) in x n, llet − − − → let y = r in ( let x = ( λz.q ) in x ) n, cp − − → let y = r in ( let x = ( λz.q ) in ( λz.q )) is a Weak Head Normal Form Congruence of Bisimulation – p. 7/21
Congruences and Program Transformations Congruence of Bisimulation – p. 8/21
Equality and Preorders Contextual Equivalence def s ≃ Λ ND , c t ⇐ ⇒ s � Λ ND , c t ∧ t � Λ ND , c s Contextual Preorder def s � Λ ND , c t ⇐ ⇒ ∀ C : C [ s ] ⇓ = ⇒ C [ t ] ⇓ Similarity? � Λ ND , b � = � Λ ND , c for � Λ ND , b as gfp of � ⇒ s ⇓ L s [ λx.s ′ ] = t ⇓ L t [ λx.t ′ ] ∧ s � Λ ND , b t ⇐ ⇒ � ∀ r : ( L s [ λx.s ′ ]) r � Λ ND , b ( L t [ λx.t ′ ]) r Congruence of Bisimulation – p. 9/21
Counter-Example: Shift let over λ Not correct w.r.t. ≃ c in the λ ND -calculus! For the terms s ≡ λw. let v = pick K K2 in v t ≡ let v = pick K K2 in λw.v s � � Λ ND , c t holds — because of C [ s ] ⇓ ∧ C [ t ] �⇓ with C ≡ let f = [ ] in (( f K ) ( f K ) Ω Ω K ) But: s � Λ ND , b t since s and t both WHNF’s and ∀ r : s r � Λ ND , b t r Congruence of Bisimulation – p. 10/21
From the λ ND - to the λ ≈ -calculus lapp ( let x = t x in s ) t − − → let x = t x in ( s t ) (lapp) lbeta ( λx.s ) t − − → let x = t in s (lbeta) cpa let x = s in t − − → λ ≈ t [ s/x ] where s ≡ λz.q or s ≡ ⊚ (cpa) ndl ndr pick s t − → s pick s t − − → t (nd) stop s − − → λ ≈ ⊚ if s �≡ ⊚ (stop) Congruence of Bisimulation – p. 11/21
Approximation Reduction in λ ≈ Howe’s method: Treatment of rule (llet) avoided Special constant ⊚ to “cut off” evaluation Test for pure abstractions instead of WHNF’s Surface contexts S : No hole under λ Convergence using λ ≈ -reductions in surface contexts: ∗ def S s ⇓ ≈ λx.t ⇐ ⇒ s − → λ ≈ λx.t Notation: val ( s ) = { λx.t | s ⇓ ≈ λx.t } Congruence of Bisimulation – p. 12/21
Bisimulation in the λ ≈ -Calculus Similarity � b is the greatest fixed point w.r.t. s ′ � b t ′ ⇐ ⇒ � s ′ ⇓ ≈ λx.s = ⇒ ∃ λy.t : ( t ′ ⇓ ≈ λy.t ∧ ∀ λx.s : � ∀ r : r ∈ Λ 0 ≈ = ⇒ ( λx.s ) r � b ( λy.t ) r ) Bisimilarity: def s ∼ b t ⇐ ⇒ s � b t ∧ t � b s Congruence of Bisimulation – p. 13/21
Example revisited: Shift let over λ s ≡ λw. let v = pick K K2 in v val ( s ) = { s } let v =[ ] in ..., ndl t ≡ let v = pick K K2 in λw.v − − − − − − − − − − − → cpa let v = K in λw.v − − → λw. K val ( t ) = { λw. K , λw. K2 } Therefore s � � b t , i.e. s and t are not bisimilar : (( s Ω ) Ω ) K ⇓ ≈ but ((( λw. K ) Ω ) Ω ) K �⇓ ≈ (( s Ω ) K ) Ω ⇓ ≈ but ((( λw. K2 ) Ω ) K ) Ω �⇓ ≈ Congruence of Bisimulation – p. 14/21
Similarity and Contextual Preorder Main Theorem: Similarity � b is a precongruence in λ ≈ Due to correspondence of convergence in λ ≈ and λ ND : Theorem: The similarity � b in the λ ≈ -calculus coin- cides with the contextual preorder � Λ ND , c in the λ ND -calculus Congruence of Bisimulation – p. 15/21
Proof Structure Congruence of Bisimulation – p. 16/21
Similarity a Precongruence o via closing let -environments Open extension � b Howe’s precongruence candidate: o b x � � b b ⇐ = x � b o b τ ( a i ) � = a i � � b a ′ i ∧ τ ( a ′ � b b ⇐ i ) � b o from Infer � � b ⊆ � b S , a → λ ≈ s ∧ r � ⇒ s � r − − � b t = � b t which is shown for every reduction rule ( a ) Congruence of Bisimulation – p. 17/21
Howe: Substitution Lemmas Essential for proving reduction rules stable under � � b All terms in Howe’s original — no sharing: � b s ′ ∧ t � � b t ′ = s � ⇒ s [ t/x ] � � b s ′ [ t ′ /x ] In λ ≈ only terms which may be copied: � b s ′ = s � ⇒ s [ ⊚ /x ] � � b s ′ [ ⊚ /x ] � b s ′ ∧ λy.t � � b λy.t ′ = s � ⇒ s [ λy.t/x ] � � b s ′ [ λy.t ′ /x ] Close interplay with rule (cpa) in proof Congruence of Bisimulation – p. 18/21
� � � � Kutzner: Reduction Diagrams Complete Sets of Commuting and Forking Diagrams � r � r a a p p b ′ b ′ b b � t � t a ′ a ′ s s Forking diagrams: (lbeta), (cpa) sound w.r.t. � b n S − → -sequences into − → λ ≈ -sequences and Transform vice versa with commuting diagrams, e.g.: S , cpa n, a n, llet n, a S , cpa − − − → λ ≈ · − − → � − − − → · − − → · − − − → λ ≈ Congruence of Bisimulation – p. 19/21
Conclusion Similarity � b is a precongruence in λ ≈ and therefore equals contextual preorder � Λ ≈ , c Contextual preorders � Λ ND , c and � Λ ≈ , c coincide Bisimilarity a proof tool for contextual equivalence ☞ in a non-deterministic call-by-need lambda-calculus Congruence of Bisimulation – p. 20/21
Future Work Extend to calculus with constructors and case Bisimulation highly non-deterministic: Arrange for better proof search strategy Regard “must”-convergence in definition of � c pick behaves bottom-avoiding because of “may”- convergence only: Compare with amb -calculi Develop SOS rule format according to proof method Congruence of Bisimulation – p. 21/21
Recommend
More recommend