Computational Interpretations
Here we will talk about computational interpretations by the example of lax logic. Hope from the example we can have sense of how logic and PL are connected.
Lax and MonandPermalink
Some notations:
Γ⊢E:A lax means E as a computational evidence might not terminate. It might not give me A at the end. Think of it like a “possibility” that E will give me A.
{E} a suspended computation of E.
<E/x>F is a kind of substitution of E for x in F. It is an operration on proof/computation. Will talk about it later.
So we have the following structural rules or judgemental rules about lax:
1.
Γ⊢M:A trueΓ⊢M:A lax2.
Γ⊢E:A lax,Γx:A true⊢F:C laxΓ⊢<E/x>F:C laxWe now introduce a new proposition ◯A Monad:
Introduction rule (I):
Γ⊢E:A laxΓ⊢{E}:◯A trueElimination rules (E):
Γ⊢M:◯A true,Γx:A true⊢F:C laxΓ⊢let_{x}=Min_F:C laxSummarize local reduction and local expansion:
let_{x}={E}in_F⟹R<E/x>F M:◯A⟹E{let_{x}=Min_x}So because E is type of A lax, according to the second structural rules about lax: Γ⊢E:A lax,Γx:A true⊢F:C laxΓ⊢<E/x>F:C lax, it could be comming from two places:
-
The first structural rules about lax: Γ⊢M:A trueΓ⊢M:A lax. So E is M.
-
The elimination rules of ◯A: Γ⊢M:◯A true,Γx:A true⊢F:C laxΓ⊢let_{x}=Min_F:C lax. (Note: Here F and C could be anything). So E is let_{x}=Min_F
So we write: E=M|let_{x}=Min_F
For the elimination rule case, we can see Γ⊢M:◯A true. For something have type ◯A, according to the Introduction rule of ◯A, it could be that M=E
Therefore, M is everything as before plus one possibility:
We write: M=…{E}
Then we can define <E/x>F:
<E/x>F=<M/x>F=[M/x]For<let_{y}=Min_E′/x>F=let_{y}=Min_<E′/x>FLet’s Write Some Proofs/ProgramsPermalink
For (A⊃(B⊃C))⊃((A∧B)⊃C) which is uncurrying, we have the proof: λf.λp.f(first p)(second p)
For ((A∧B)⊃C)⊃(A⊃(B⊃C)) which is currying, we have the proof: λg.λx.λy.g<x,y>
For monad in functional programming we have two requirements to satisfy:
return:A⊃◯Abind:◯A⊃(A⊃◯B)⊃◯Bsuch that
bind(return z)f=fzTo proof return:
A⊃◯Awe have:
λx.{x}To proof bind:
◯A⊃(A⊃◯B)⊃◯Bwe have:
λx.λf.{let_{x′}=xin_ let_{y}=fx′in_ y}To proof
bind(return x)f=fxwe have:
(λx.λf.{let_{x′}=x in_ let_{y}=fx′ in_ y})((λx.{x})z)f={let_{x′}=(λx.{x})z in_ let_{y}=fx′ in_ y}={let_{x′}={z} in_ let_{y}=fx′ in_ y}={let_{y}=fz in_ y}=fz
Comments