Lecture 9: Lazy PCF

Teacher: Thomas Ehrhard

Lecture 9

ehrhard at irif.fr www.irif.fr/~ehrhard

Connection between syntax and semantics:

  1. Programming language ⟶ a version of Plotkin’s PCF with lazy integers
  2. What is a model of linear logic?
    • Scott model of LL
    • Adequacy theorem

Denotational semantics

1969 - Dana Scott (Logician), Christopher Stratchey (Computer scientist) met in Oxford

Christopher Stratchey wondered what is the meaning of a program, independently on the programming language. He had equations on datatypes, but no solution in Set.

When Dana Scott met him, he has the idea of interpreting types as complete lattices and programs as continuous functions

Logicians Curry-Howard: Programs ⟺ Proofs

Jean-Yves Girard: denotational interpretation of System F ⟶ Coherence Spaces

PCF (Programming language with Computable Functions): abstract programming language to study the relation between syntax and semantics.

PCF:
  • simply typed λ-calculus
  • with a ground type for integers (booleans encoded as integers)
  • basic functions (suc,pred, conditional)
  • fixpoint constructions ⟶ full recursion

NB: PCF is a Turing-complete language

LPCF (Lazy PCF)

Syntax

Types:
A,B,ιAB
Terms:
M,N,P,x0suc(M)if (M,Nif M=0,x.Pif M=sucx)λxA.M(M)Nfix xA.M

Typing rules

Typing context Γ(x1:A1,,xn:An)

Typing judgement ΓM:A

Rules:

Γ,x:Ax:AΓ0:ιΓM:ιΓsuc(M):ιΓM:ιΓN:AΓ,x:ιP:AΓif (M,N,x.P):AΓ,x:AM:BΓλxA.M:ABΓM:ABΓN:AΓ(M)N:BΓ,x:AM:AΓfix xA.M:A

Example: define addition:

add(x, 0) = x
add(x, S(y)) = S(add(x,y))

i.e, for a given x:

add_x(0) = x
add_x(S(y)) = S(add_x(y))
addλxι.fix aιι.λyι. if (y,x,z.suc((a)z))

β-reduction

Rewriting relation on terms:

(λxA.M)NβM[N/x] if (0,N,x.P)βNif (sucM,N,x.P)βP[M/x] fix xA.MβM[fix xA.M/x]

And then, it goes through context:

MβMsuc(M)βsuc(M) MβM if (M,N,x.P)β if (M,N,x.P) NβN if (M,N,x.P)β if (M,N,x.P) MβM(M)Nβ(M)NNβN(M)Nβ(M)N

etc…

Why “lazy”?

Let Ωιfix xι.x

ΩιβΩιβΩιβ

It’s a fully undefined term. But

suc(Ωι)

is such that

if (sucΩι,0,x.0)β0

Whereas in ordinary PCF, you have a term n for each integer, and

sucnβn+1

So that:

suc(Ωι)βsuc(Ωι)β

And in ordinary PCF:

if (0,M,x.N)βMif (n+1,M,x.N)βN[n/x]

Whereas in LPCF, if statements don’t need to have a integer value as first argument to reduce, which enables if (sucΩι,0,x.0) to (weakly) terminate.

Subject Reduction

Th (Subject reduction): If ΓM:A and MβM, then ΓM:A

Lemma (Substitution lemma): if Γ,x:AM:B and ΓN:A, then ΓM[N/x]:B

Notation: we denote by β the reflexive-transitive closure of β.

Th (Confluence): If MβM1 and MβM2, then there exists M0 s.t. M1βM0 and M2βM0

MββM1βM2βM0

NB: Local confluence:

MββM1βM2βM0

+ Strong normalization is enough (modulo Neumann’s lemma) to have confluence

But if you don’t have strong normalization, then local confluence is not enough, as shown by this example:

%3 A A B B A->B C C A->C C->A E E C->E

Th: If β satisfies the diamond property, then β satisfies it too:

MββM1βM2βM0MββM1βM2βM0

But we don’t have the diamond property (cf. picture)

Parallel reductions: Tait/Martin-Löf’s method

Idea: Introduce a rewriting relation ρ such that

βρβ

(which implies: ρ=β)

which satisfies:

MρρM1ρM2ρM0

where MρM means that you reduce an arbitrary number of redexes ocurring in M, but no redex created during this process.

Ex:

(λx.(x)0)(λy.y)βρ as well(λy.y)0βbut NOT ρ as it’s a created redex!0

Definition of ρ

xρx0ρ0MρMsuc(M)ρsuc(M)MρMNρNPρP if (M,N,x.P)ρ if (M,N,x.P)NρN if (0,N,x.M)ρNMρMPρP if (sucM,N,x.P)ρP[M/x] MρMNρN(M)Nρ(M)N MρMλxA.MρλxA.MMρMNρN(λxA.M)NρM[N/x] MρMfix xA.Mρfix xA.MMρMfix xA.MρM[fix xA.M/x]

BUT NOT:

MρsucMPρP if (M,N,x.P)ρP[M/x]

Lemma 1: MρM

Lemma 2: MρM and NρN, then M[N/x]ρM[N/x]

Proof: by induction on the derivation MρM.

Th: If MρMi for i=1,2 , there exists M0 such that MiρM0 for i=1,2.

Proof: By induction on the max of the sizes of the deduction trees of MρM1 and MM2.

  1. Assume M=(P)Q

    MρM1 and MρM2

    there are the following possibilities:

    • PρPi and QρQi and Mi=(Pi)Qi

      By IH, there is P0,Q0 such that

      PiρP0 and QiρQ0i=1,2

      Then

      Miρ(P0)Q0
    • P=λyA.H

      (cf. picture)


Lemma: if MρM and NρN then M[N/x]ρM[N/x]

Induction on the derivation of MρM

cf. picture

LPCF

Weak head reduction βwh:

it’s a reduction strategy

Any term contains at most one redex for this reduction.

Rules for βwh:

MβwhM if (M,N,x.P)βwh if (M,N,x.P)if (0,N,x.P)βwhNif (sucM,N,x.P)βwhP[M/x]MβwhM(M)Nβwh(M)N(λxA.M)NβwhM[N/x]fix xA.MβwhM[fix xA.M/x]

Forbidden: reduce N in

  • (M)N
  • λxA.N
  • if (M,N,x.P), if (M,P,x.N)
  • sucN

Th (Completeness of βwh): Assume M:ι

  • Mβ0Mβwh0
  • MβsucNMβwhsucN

Model of LL

What is a model of LL? A symmetric monoidal category

,,1,λ,ρ,α,γ

which is closed

X,Y(XY,ev)

such that

f(ZX,Y),!cur(f)(Z,XY)

such that

(XY)XevYZXcur(f)×idf

commutes.

On top of that: we have a dualizing object for which we have -autonomy:

ηXZ=cur(evγ)(X,(XZ)Z)X(XZ)γ(XZ)XevZ

for all Z, this is a natural transformation.

ηX is an iso for all X

X(X⊸⊥)⊸⊥
X⊸⊥:

linear negation

We have a functor:

():op

Moreover, is cartesian: there is a terminal object , binary products (X1&X2,pr1,pr2) inducing a bifunctor

&:{×(X1,X2)X1&X2

is also co-cartesian ⟹ there is an initial object 0= and coproducts

X1X2=(X1&X2)inipri

where

pri:X1&X2X1pri:X1(X1)(X1&X2)X1X2

We have a functor:

!:

such that (!,der,dig) is a comonad:

derX(!X,X)digX(!X,!!X)

On top of that, we’d like to state that

!=1!(X1&X2)=!X1!X2

So we introduce:

m0(1,!) is an isomX1,X22(!X1!X2,!(X1&X2)) is a natural iso

+ monoidality diagrams:

(!X1!X2)!X3mX1,X22!X3α!X1,!X2,!X3!(X1&X2)!X3!X1(!X2!X3)

cf. pictures

Derived structures

Weakening and contraction

ΓΓ,?AΓ,?A,?AΓ,?A

comes from the fact that !X has a canonical structure of commutative comonoid with wfX(!X,1) (weakening free) and cfX(!X,!X!X) (contraction free)

Leave a comment