2 minute read

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ΓE:A lax means EE as a computational evidence might not terminate. It might not give me AA at the end. Think of it like a “possibility” that EE will give me AA.

{E}{E} a suspended computation of EE.

<E/x>F<E/x>F is a kind of substitution of EE for xx in FF. It is an operration on proof/computation. Will talk about it later.

So we have the following structural rules or judgemental rules about laxlax:

1.

ΓM:A trueΓM:A laxΓM:A trueΓM:A lax

2.

ΓE:A lax,Γx:A trueF:C laxΓ⊢<E/x>F:C laxΓE:A lax,Γx:A trueF:C laxΓ<E/x>F:C lax

We now introduce a new proposition AA Monad:

Introduction rule (II):

ΓE:A laxΓ{E}:A trueΓE:A laxΓ{E}:A true

Elimination rules (EE):

ΓM:A true,Γx:A trueF:C laxΓlet_{x}=Min_F:C laxΓM:A true,Γx:A trueF:C laxΓlet{x}=MinF:C lax

Summarize local reduction and local expansion:

let_{x}={E}in_FR<E/x>Flet{x}={E}inFR<E/x>F M:AE{let_{x}=Min_x}M:AE{let{x}=Minx}

So because EE is type of A laxA lax, according to the second structural rules about laxlax: ΓE:A lax,Γx:A trueF:C laxΓ⊢<E/x>F:C laxΓE:A lax,Γx:A trueF:C laxΓ<E/x>F:C lax, it could be comming from two places:

  1. The first structural rules about laxlax: ΓM:A trueΓM:A laxΓM:A trueΓM:A lax. So EE is MM.

  2. The elimination rules of AA: ΓM:A true,Γx:A trueF:C laxΓlet_{x}=Min_F:C laxΓM:A true,Γx:A trueF:C laxΓlet{x}=MinF:C lax. (Note: Here FF and CC could be anything). So EE is let_{x}=Min_Flet{x}=MinF

So we write: E=M|let_{x}=Min_FE=M|let{x}=MinF

For the elimination rule case, we can see ΓM:A trueΓM:A true. For something have type AA, according to the Introduction rule of AA, it could be that M=EM=E

Therefore, MM is everything as before plus one possibility:

We write: M={E}M={E}

Then we can define <E/x>F<E/x>F:

<E/x>F=<M/x>F=[M/x]For<let_{y}=Min_E/x>F=let_{y}=Min_<E/x>F<E/x>F=<M/x>F=[M/x]For<let{y}=MinE/x>F=let{y}=Min<E/x>F

Let’s Write Some Proofs/ProgramsPermalink

For (A(BC))((AB)C)(A(BC))((AB)C) which is uncurrying, we have the proof: λf.λp.f(first p)(second p)λf.λp.f(first p)(second p)

For ((AB)C)(A(BC))((AB)C)(A(BC)) which is currying, we have the proof: λg.λx.λy.g<x,y>λg.λx.λy.g<x,y>

For monad in functional programming we have two requirements to satisfy:

return:AAbind:A(AB)Breturn:AAbind:A(AB)B

such that

bind(return z)f=fzbind(return z)f=fz

To proof returnreturn:

AAAA

we have:

λx.{x}λx.{x}

To proof bindbind:

A(AB)BA(AB)B

we have:

λx.λf.{let_{x}=xin_ let_{y}=fxin_ y}λx.λf.{let{x}=xin let{y}=fxin y}

To proof

bind(return x)f=fxbind(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