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 Monand
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 lax
2.
Γ⊢E:A lax,Γx:A true⊢F:C laxΓ⊢<E/x>F:C lax
We now introduce a new proposition ◯A Monad:
Introduction rule (I):
Γ⊢E:A laxΓ⊢{E}:◯A true
Elimination rules (E):
Γ⊢M:◯A true,Γx:A true⊢F:C laxΓ⊢let−−−{x}=Min−−F:C lax
Summarize 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>F
Let’s Write Some Proofs/Programs
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)⊃◯B
such that
bind(return z)f=fz
To proof return:
A⊃◯A
we have:
λx.{x}
To proof bind:
◯A⊃(A⊃◯B)⊃◯B
we have:
λx.λf.{let−−−{x′}=xin−− let−−−{y}=fx′in−− y}
To proof
bind(return x)f=fx
we 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