2 minute read

Total Programming LanguagePermalink

E.Coli of Total PLs - Godel’s T: It codifies higher order functions and inductive types (nat)

What does it mean for a PL to exist?Permalink

A PL consists of two parts:

  • Statics: What are the programs?
  • Dynamics: How do we run them?

Basic criterion: Coherence

StaticsPermalink

We will talk about abstract syntax and context-sensitive-conditions on well-formation.

Formal = typing is inductively defined.

We only have information about the types but not the elements themselves.

So we only care about two things, higher order functions, and nat.

τ:=nat|τ1τ2e:=x|z|s(e)|iter(e0x.e1)(e)|λx:τ.e|e1(e2)

So the typing:

Γe:τ

is inductively defined by rules, which is the least relation closed under under some rules

Note: Γ can be viewed as a “context”. It could be written as something like Γ=x1:τ1,x2:τ2,,xn:τn

e.g. natural number

Hypothetical Judgement (Structural):

Note: 1 and 2 are indefeasible. 3, 4, 5 is defeasible (Will be different in substructural type systems).

  1. Reflexivity x:τx:τ

  2. Transitivity if:Γe:τ and Γ,x:τe:τthen:Γ[e/x]e:τ

  3. Weakening if:Γe:τ then Γ,x:τe:τ

  4. Contraction if:Γ,x:τ,y:τe:τthen:Γ,z:τ[z,z/x,y]e:τ

  5. Exchange if:Γ,x:τ,y:τe:τthen:Γ,y:τ,x:τe:τ

DynamicsPermalink

Execute close code (no free variables)

We need to specify:

  • e val
  • States of execution S
  • Transition SS
  • Initial State and final state

Some rules:

  • zero is a value
z val
  • successor is a value
s(e) val
  • function is a value
λx:τ.e val
  • functions can be executed
e2 val(λx:τ.e)(e2)[e2/x]e
  • e1e1e1(e2)e1(e2)
  • eeiterτ(e0;x.e1)(e)iterτ(e0;x.e1)(e)
  • Values are stuck/finished
e vale st e e
  • Determinism/functional language
e1 v st v val and ev

Note: dynamics doesn’t care about types!

Coherence of Dynamics/Statics/Type Safety():

  • Preservation
e:τ and eee:τ
  • Progress
e:τeither e val or e ee
  • Termination
e:τunique v:τ,v val,ev

Here we proof Termination (T(e) means e terminates). According to Godel, if we proof termination, we are proving the consistency of the arithmetic, so we need methods that go beyong the arithmetic (Godel’s incompleteness):

  1. e itself can’t be a variable becasue it is closed
  2. zz val
  3. s(e)s(e) val
  4. λx:τ.eλx:τ.e val
  5. But for e1(e2), even by inductive hypothesis, we know e1v1 and e2v2, and e1:τ2τ,e2:τ2, we can only do e1(e2)v1(e2)=(λx:τ2.e)(e2)[e2/x]e, but we can’t get any further. We do need more info about e!

Therefor we introduct a strong property called hereditary termination: HTτ(e)

  • Want: HTnat(e) implies T(e)
  • Define: HTτ(e) by induction on type τ [Tait’s Method]
    • HTnat(e) iff ez or es(e) with HTnat(e) (it is well-defined because it is the strongest predicate satisfying these rules)
    • HTτ1τ2(e) iff eλx:τ1.e and for every e1 such that HTτ1(e1),HTτ2([e1/x]e) (meaning “type goes down”). To write this in another form, HTτ1τ2(e) iff (if HTτ1(e1),then HTτ2(e(e1)))

And we have Thm(v2):

If e:τ then HTτ(e), and then therefore Tτ(e)

So now for inductive hypothesis, we not only know e1v1 15 and e2v2, but also HTτ2τ(e1) and HTτ2(e2). And because we know that e1 is a λ, we now know that [e2/x]e is HT!

BUT! Thm(v2) is only stating about e being closed terms, but for λ: x:τ1e2:τ2λx:τ1.e2:τ1τ2, e2 is an open term, meaning it is a variable, so our theorm doesn’t quite work. We must account for open terms!

Thm(v3)[Tait]:

If Γe:τ and HTΓ(γ), then HTτ(γ^(e))

So HTΓ(γ) means that if Γ=x1:τ1,x2:τ2,,xn:τn, then γ=x1e1,x2e2,,xnxn (substitution) such that HTτ1(e1),,HTτn(en), and γ^(e) means to do the substitution. So we are good now!

Comments