+ All Categories
Home > Documents > Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU...

Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU...

Date post: 19-Jan-2016
Category:
Upload: stuart-marsh
View: 217 times
Download: 0 times
Share this document with a friend
25
Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University
Transcript
Page 1: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

Supercompilation and Normalisation by Evaluation

Gavin Mendel-Gleason & Geoff Hamilton

Lero@DCUDublin City University

Page 2: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

Why Bother?

Wanted to figure out when one thing was like another.

Thought that Supercompilation's intuitive process trees might have a deeper meaning.

Normalisation is a well used framework for finding canonical terms

Normalisation is stuck in a terminating world

Page 3: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

Normalisation

In the Curry Howard setting, normalisation is cut elimation and proof simplification.

We can tell if two proofs are the same if they are synatically identical after normalisation.

Normalisation just requires the application of appropriate reduction rules.

Page 4: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

Curry-Howard Correspondance

We try to draw a correspondance between the world of proofs and the world of programs

Proofs <=> Programs

Propositions <=> Types

Page 5: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

System F

System F is a simple language with an interesting type system.

It allows quantification over types: implicational monadic second order logic.

Λ A . (λ x : A . x) : A . A→A∀ It is strongly normalising, so we can find a

“value” for any program by applying reduction rules.

Page 6: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

What does it mean to reduce?

Page 7: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

System F - Extended

Types {A,B,C} := 1| X | A→B | X.A | A+B | ∀A*B X.A

Terms {r,s,t} := x | f | () | λx:A.t | Λ X.t | r s | r A | inl(t,B) | inr(t,A) | (t,s) | in(t,A) | out(t,A) | split r as x1,x2 in s | case r of inl(x1) => s ; inr(x2) =>t

Ctx {G} := . | G,X | G,x:A

D = a map from function constants to terms.

Page 8: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

What have we done?

Everything there is representable except unfolding.

We can do sums, products and even least and greatest fixed points without extension – using a church encoding – but it's slow

We've gained general recursion, lost normalisation.

Cut evaluation into two peices!

Page 9: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

We can't compare anymore

We can still compare programs for syntactic equality, but it doesn't tell us anything about the unfolding behaviour.

We want a behavioural model of the program.

Let's see how things unfold

Page 10: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

When is one thing like another?

Morris contextual equivalence says that we want to know that C[e] = C[e'] for any context C.

It's hard to quantify over contexts.

Gordon tells us about another path – we can treat functional programs as a transition system.

Equivalence becomes a question of bisimulation.

Page 11: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

Two players, internal and external

“A point to watch is to make a distinction between internal and external behaviour” - Plotkin

We don't know what free variables are going to do except for what their type says.

This is how supercompilation has always built process trees – nothing new.

Our graph is built from a term t, using [t]

Page 12: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

Transition System

T = (S,A,:SxAxS)

A a set of actions – here determined by the language

S a set of states – which are terms

Page 13: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

Creating the Graph

Page 14: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

Example

data Nat = Z | S Nat deriving Show

f x a b c d = case (case x of Z -> a S x' -> b) of Z -> c S x' -> dg x a b c d = case x of Z -> (case a of Z -> c S x' -> d) S x' -> (case b of Z -> c S x' -> d)

Page 15: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.
Page 16: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.
Page 17: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

A Difference without a distinction

Well known that we can distribute case – but we see it plainly here. Just compare edge labels and leaves to match.

Where do these transitions come from? They came from one-hole evaluation contexts – or

atomic experiments that define the reduction semantics.

Case [] of ... | Split [] as ... | [] b

Page 18: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

For Infinity

data Nat = Z | S Nat

inf = S inf

inf2 = S (S inf2)

Obviously: inf ~ inf2

Page 19: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.
Page 20: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

Arbitrary Bisimulation

To show that a~b Whenever (a,a') in G1, then (b,b') in G2 and

a'~b'

Whenever (b,b') in G2, then (a,a') in G1,and a'~b'

Page 21: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

Use Park's Principle

We do this by coming up with a monotone relation, that we can use to replace ~, then we can easily show that it is a subset of ~ hence we can show ~

In practice this just means we have to be careful to have done something, before reusing our hypothesis.

That is: assume a~b but make sure we have a transition before using it.

Page 22: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

Composition of Graphs

Page 23: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

Composition is Bisimilar

[t] • [s] ~ [t s] [t] • T ~ [t T]

We can go back and forth between splitting out separate graphs and combining into one.

Page 24: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

Pending Questions

Equivalence of process trees should give a contextual equivalence – we shouldn't need to show improvement, but I've yet to prove this.

Do we need the improvement theorem? In the f 0 = 42 example [Bird], we have equational

rewriting going wrong, but we don't have a replacement of one normal form for an equivalent normal form.

What fragments will we get normal forms for?

Page 25: Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Lero@DCU Dublin City University.

{- Also called min on natural numbers -}join :: CoTrue -> CoTrue -> CoTruejoin T b = Tjoin a T = Tjoin (D a) (D b) = D (join a b)

ex :: (Nat -> CoTrue) -> NatStream -> CoTrueex p (SCons x s) = D (join (p x) (ex p s))

{- Also called min on natural numbers -}join :: CoTrue -> CoTrue -> CoTruejoin T b = Tjoin a T = Tjoin (D a) (D b) = D (join a b)

ex :: (Nat -> CoTrue) -> NatStream -> CoTrueex p (SCons x s) = D (join (p x) (ex p s))

{- Also called min on natural numbers -}join :: CoTrue -> CoTrue -> CoTruejoin T b = Tjoin a T = Tjoin (D a) (D b) = D (join a b)

ex :: (Nat -> CoTrue) -> NatStream -> CoTrueex p (SCons x s) = D (join (p x) (ex p s))

data CoTrue = T | D CoTrue

true = Tfalse = D false

eq Z Z = trueeq (S x) (S y) = eq x yeq x y = false


Recommended