Congruence of Bisimulation in a Non-Deterministic Call-By-Need Lambda Calculus Matthias Mann Johann Wolfgang Goethe-Universität, Frankfurt, Germany Congruence of Bisimulation p. 1/21
Lambda Calculi and Equality Abramsky ( 90) Ariola, Felleisen, Wadler, et al. ( 95) Kutzner, Schmidt- Schauß ( 98) Moran, Sands, Carlsson ( 99) Howe ( 89, 96) deterministic, call-by-name deterministic, call-by-need (let) non-deterministic, call-by-need (let) non-deterministic, call-by-need, letrec, case class of languages, no sharing Bisimulation = Contextual Equiv. Conversion Contextual Equiv. Contextual Equiv. Bisimulation = 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) Congruence of Bisimulation p. 3/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) λ ND Congruence of Bisimulation p. 3/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) n c λ ND Congruence of Bisimulation p. 3/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) n Approximation c λ ND λ Congruence of Bisimulation p. 3/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 c λ ND λ S λ b Congruence of Bisimulation p. 3/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 c λ ND λ S λ 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) (let x = t x in s) t lapp let x = t x in (s t) (λx.s) t lbeta let x = t in s let x = λy.r in D[x] cp let x = λy.r in D[λy.r] (llet) (lapp) (lbeta) (cp) pick s t ndl s pick s t ndr 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 Congruence of Bisimulation p. 5/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: (λx.x + x) (pick a b) lbeta let x = pick a b in x + x instead of (λx.x + x) (pick a b) β pick a b + pick a b Congruence of Bisimulation p. 5/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: (λx.x + x) (pick a b) lbeta 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 Normal-order reduction n is unique up to (nd) Weak Head Normal Form (WHNF): L R [λx.s] let-environments: L R ::= [ ] let x = e in L R Convergence: t L R[λx.s] def t n L R[λx.s] Congruence of Bisimulation p. 6/21
Normal-Order Reduction in λ ND Example: (λx.x) ( (λy.(λz.q)) r ) Congruence of Bisimulation p. 7/21
Normal-Order Reduction in λ ND Example: (λx.x) ( (λy.(λz.q)) r ) Congruence of Bisimulation p. 7/21
Normal-Order Reduction in λ ND Example: (λx.x) ( (λy.(λz.q)) r ) n, lbeta let x = ((λy.(λz.q)) r) in x Congruence of Bisimulation p. 7/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 Congruence of Bisimulation p. 7/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) Congruence of Bisimulation p. 7/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 s ΛND, c t def s ΛND, c t t ΛND, c s Contextual Preorder s ΛND, c t def C : C[s] = C[t] Congruence of Bisimulation p. 9/21
Equality and Preorders Contextual Equivalence s ΛND, c t def s ΛND, c t t ΛND, c s Contextual Preorder s ΛND, c t def C : C[s] = C[t] Similarity? ΛND, b ΛND, c for ΛND, b as gfp of s ΛND, b t s L s [λx.s ] = ( t L t [λx.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! Congruence of Bisimulation p. 10/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 Congruence of Bisimulation p. 10/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) Congruence of Bisimulation p. 10/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 let x = (let y = t y in t x ) in s llet let y = t y in (let x = t x in s) (let x = t x in s) t lapp let x = t x in (s t) (λx.s) t lbeta let x = t in s let x = λy.r in D[x] cp let x = λy.r in D[λy.r] (llet) (lapp) (lbeta) (cp) pick s t ndl s pick s t ndr t (nd) Congruence of Bisimulation p. 11/21
From the λ ND - to the λ -calculus let x = (let y = t y in t x ) in s llet let y = t y in (let x = t x in s) (let x = t x in s) t lapp let x = t x in (s t) (λx.s) t lbeta let x = t in s let x = λy.r in D[x] cp let x = λy.r in D[λy.r] (llet) (lapp) (lbeta) (cp) pick s t ndl s pick s t ndr t (nd) s stop λ if s (stop) Congruence of Bisimulation p. 11/21
From the λ ND - to the λ -calculus let x = (let y = t y in t x ) in s llet let y = t y in (let x = t x in s) (let x = t x in s) t lapp let x = t x in (s t) (λx.s) t lbeta let x = t in s let x = λy.r in D[x] cp let x = λy.r in D[λy.r] (llet) (lapp) (lbeta) (cp) pick s t ndl s pick s t ndr t (nd) s stop λ if s (stop) Congruence of Bisimulation p. 11/21
From the λ ND - to the λ -calculus let x = (let y = t y in t x ) in s llet let y = t y in (let x = t x in s) (let x = t x in s) t lapp let x = t x in (s t) (λx.s) t lbeta let x = t in s let x = s in t cpa λ t[s/x] where s λz.q or s (llet) (lapp) (lbeta) (cpa) pick s t ndl s pick s t ndr t (nd) s stop λ if s (stop) Congruence of Bisimulation p. 11/21
From the λ ND - to the λ -calculus let x = (let y = t y in t x ) in s llet let y = t y in (let x = t x in s) (let x = t x in s) t lapp let x = t x in (s t) (λx.s) t lbeta let x = t in s let x = s in t cpa λ t[s/x] where s λz.q or s (llet) (lapp) (lbeta) (cpa) pick s t ndl s pick s t ndr t (nd) s stop λ if s (stop) Congruence of Bisimulation p. 11/21
From the λ ND - to the λ -calculus (let x = t x in s) t lapp let x = t x in (s t) (λx.s) t lbeta let x = t in s let x = s in t cpa λ t[s/x] where s λz.q or s (lapp) (lbeta) (cpa) pick s t ndl s pick s t ndr t (nd) s stop λ 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 λ Congruence of Bisimulation p. 12/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: s λx.t def s 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 λx.s : ( s λx.s = λy.t : (t λy.t r : r Λ 0 = (λx.s) r b (λy.t) r) ) Congruence of Bisimulation p. 13/21
Bisimulation in the λ -Calculus Similarity b is the greatest fixed point w.r.t. s b t λx.s : ( s λx.s = λy.t : (t λy.t r : r Λ 0 = (λx.s) r b (λy.t) r) ) Bisimilarity: s b t def 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} t let v = pick K K2 in λw.v let v = K in λw.v cpa λw.k val(t) = {λw.k, λw.k2} let v=[ ] in..., ndl Congruence of Bisimulation p. 14/21
Example revisited: Shift let over λ s λw.let v = pick K K2 in v val(s) = {s} t let v = pick K K2 in λw.v let v=[ ] in..., ndl let v = K in λw.v cpa λw.k val(t) = {λw.k, λw.k2} Therefore s b t, i.e. s and t are not bisimilar: ((s Ω) Ω) K ((s Ω) K) Ω but (((λw.k) Ω) Ω) 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 coincides 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 Open extension o b via closing let-environments Howe s precongruence candidate: x b b = x o b b τ(a i ) b b = a i b a i τ(a i ) b o b Infer b b o from r S, a λ s r b t = s 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: s b s t b t = s[t/x] b s [t /x] In λ only terms which may be copied: s b s = s[ /x] b s [ /x] s b s λy.t b λy.t = 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 p a r p a r b b b b s a t s a t Congruence of Bisimulation p. 19/21
Kutzner: Reduction Diagrams Complete Sets of Commuting and Forking Diagrams p a r p a r b b b b s a t s a t Forking diagrams: (lbeta), (cpa) sound w.r.t. b Transform n -sequences into S λ -sequences and 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 Congruence of Bisimulation p. 20/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