SlideShare a Scribd company logo
1 of 41
Download to read offline
Continuation calculus
Bram Geron1 Herman Geuvers1,2
1Eindhoven University of Technology
2Radboud University Nijmegen
Term Rewriting Seminar, May 2013
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 1 / 22
Outline
1 First look
2 Definition
3 Long-term goal
4 Interfaces, not pattern matching
5 The importance of head reduction
6 Relation to lambda calculus
7 Conclusion
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 2 / 22
First look Rules, names, variables, terms
CC is a constrained term rewriting system
Comp.f .g.x
def
−→ f .(g.x)
Comp.AddOne.Fact.4 → AddOne.(Fact.4)
Rules
One definition per name
(max)
No pattern matching
Only head reduction
Consequences
Deterministic
Simple operational semantics
Suitable for modeling
continuations, hence exceptions
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 3 / 22
First look Rules, names, variables, terms
CC is a constrained term rewriting system
rule
Comp
name
(constant)
.f .g.x
variables
def
−→ f .(g.x)
Comp.AddOne.Fact.4
term
→ AddOne.(Fact.4)
term
Rules
One definition per name
(max)
No pattern matching
Only head reduction
Consequences
Deterministic
Simple operational semantics
Suitable for modeling
continuations, hence exceptions
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 3 / 22
First look Rules, names, variables, terms
CC is a constrained term rewriting system
rule
Comp
name
(constant)
.f .g.x
variables
def
−→ f .(g.x)
Comp.AddOne.Fact.4
term
→ AddOne.(Fact.4)
term
Rules
One definition per name
(max)
No pattern matching
Only head reduction
Consequences
Deterministic
Simple operational semantics
Suitable for modeling
continuations, hence exceptions
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 3 / 22
First look Head reduction: continuation passing style
Functions fill in the result in their continuation parameter
Comp.f .g.x
def
−→ f .(g.x)
Comp.AddOne.Fact.4 → AddOne.(Fact).4
Realistic names:
Fact.r.x r.x!
AddOne.r.x r.(x +1)
Fact.(AddOne.r).4 AddOne.r.24
r.25
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
First look Head reduction: continuation passing style
Functions fill in the result in their continuation parameter
Comp.f .g.x
def
−→ f .(g.x)
Comp.AddOne.Fact.4 → AddOne.(Fact).4
Realistic names:
Fact.r.x r.x!
AddOne.r.x r.(x +1)
Fact.(AddOne.r).4 AddOne.r.24
r.25
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
First look Head reduction: continuation passing style
Functions fill in the result in their continuation parameter
Comp.f .g.x
def
−→ f .(g.x)
Comp.AddOne.Fact.4 → AddOne.(Fact).4
Realistic names:
Fact.r.x r.x!
AddOne.r.x r.(x +1)
Fact.(AddOne.r).4 AddOne.r.24
r.25
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
First look Head reduction: continuation passing style
Functions fill in the result in their continuation parameter
Comp.r.f .g.x
def
−→ g.(f .r).x
Comp.r.AddOne.Fact.4 → Fact.(AddOne.r).4
Realistic names:
Fact.r.x r.x!
AddOne.r.x r.(x +1)
Fact.(AddOne.r).4 AddOne.r.24
r.25
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
First look Head reduction: continuation passing style
Functions fill in the result in their continuation parameter
Comp.r.f .g.x
def
−→ g.(f .r).x
Comp.r.AddOne.Fact.4 → Fact.(AddOne.r).4
Realistic names:
Fact.r.x r.x!
AddOne.r.x r.(x +1)
Fact.(AddOne.r).4 AddOne.r.24
r.25
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
Definition
Definitions
There is an infinite set of names, indicated by a capital.
A term is either a name, or two terms combined by a dot.
We write a.b.c as shorthand for (a.b).c.
A program P consists of a set of rules, of the form
Name.variable.··· .variable
def
−→ term over those variables
That rule defines that name.
Each rule defines a different name.
If “N.x1 .··· .xk
def
−→ r” ∈ P, then we reduce N.t → r[t/x].
Term N.x1.··· .xl for l = k does not reduce at all.
There is only head reduction.
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 5 / 22
Definition
Definitions
There is an infinite set of names, indicated by a capital.
A term is either a name, or two terms combined by a dot.
We write a.b.c as shorthand for (a.b).c.
A program P consists of a set of rules, of the form
Name.variable.··· .variable
def
−→ term over those variables
That rule defines that name.
Each rule defines a different name.
If “N.x1 .··· .xk
def
−→ r” ∈ P, then we reduce N.t → r[t/x].
Term N.x1.··· .xl for l = k does not reduce at all.
There is only head reduction.
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 5 / 22
Definition
Definitions
There is an infinite set of names, indicated by a capital.
A term is either a name, or two terms combined by a dot.
We write a.b.c as shorthand for (a.b).c.
A program P consists of a set of rules, of the form
Name.variable.··· .variable
def
−→ term over those variables
That rule defines that name.
Each rule defines a different name.
If “N.x1 .··· .xk
def
−→ r” ∈ P, then we reduce N.t → r[t/x].
Term N.x1.··· .xl for l = k does not reduce at all.
There is only head reduction.
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 5 / 22
Long-term goal
Long-term goal
Formally modeling programming languages
Hopefully as a base for better languages
Operational semantics
Running time: #steps ∼ seconds CPU time
Warning: some unsubstantiated claims
Compositional
Facilitates proving properties
Deterministic by nature
Works with continuations
Explained later
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 6 / 22
Long-term goal
Long-term goal
Formally modeling programming languages
Hopefully as a base for better languages
Operational semantics
Running time: #steps ∼ seconds CPU time
Warning: some unsubstantiated claims
Compositional
Facilitates proving properties
Deterministic by nature
Works with continuations
Explained later
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 6 / 22
Interfaces, not pattern matching
Outline
1 First look
2 Definition
3 Long-term goal
4 Interfaces, not pattern matching
5 The importance of head reduction
6 Relation to lambda calculus
7 Conclusion
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 7 / 22
Interfaces, not pattern matching
Outline
1 First look
2 Definition
3 Long-term goal
4 Interfaces, not pattern matching
5 The importance of head reduction
6 Relation to lambda calculus
7 Conclusion
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 8 / 22
Interfaces, not pattern matching
Natural numbers
Slightly similar to lambda calculus
Zero.z.s
def
−→ z
S.x.z.s
def
−→ s.x
Add.r.x.y
def
−→ y.(r.x).(Add.r.(S.x))
Algorithm:
x +0 = x
x +S(y) = S(x)+y
Add.r.(S.Zero).Zero → Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero)))
→ r.(S.Zero)
Add.r.Zero.(S.Zero) → S.Zero.(r.Zero).(Add.r.(S.Zero))
→ Add.r.(S.Zero).Zero
→ Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero)))
→ r.(S.Zero)
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 9 / 22
Interfaces, not pattern matching
Natural numbers
Slightly similar to lambda calculus
Zero.z.s
def
−→ z
S.x.z.s
def
−→ s.x
Add.r.x.y
def
−→ y.(r.x).(Add.r.(S.x))
Algorithm:
x +0 = x
x +S(y) = S(x)+y
Add.r.(S.Zero).Zero → Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero)))
→ r.(S.Zero)
Add.r.Zero.(S.Zero) → S.Zero.(r.Zero).(Add.r.(S.Zero))
→ Add.r.(S.Zero).Zero
→ Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero)))
→ r.(S.Zero)
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 9 / 22
Interfaces, not pattern matching
Natural numbers
Slightly similar to lambda calculus
Zero.z.s
def
−→ z
S.x.z.s
def
−→ s.x
Add.r.x.y
def
−→ y.(r.x).(Add.r.(S.x))
Algorithm:
x +0 = x
x +S(y) = S(x)+y
What can we feed to Add?
Zero
S.(··· .(S.Zero)···)
Something else?
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 10 / 22
Interfaces, not pattern matching
Natural numbers
Slightly similar to lambda calculus
Zero.z.s
def
−→ z
S.x.z.s
def
−→ s.x
Add.r.x.y
def
−→ y.(r.x).(Add.r.(S.x))
Algorithm:
x +0 = x
x +S(y) = S(x)+y
What can we feed to Add?
Zero
S.(··· .(S.Zero)···)
Something else? Yes!
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 10 / 22
Interfaces, not pattern matching
Natural numbers
Compatible naturals
Zero.z.s
def
−→ z
S.x.z.s
def
−→ s.x
Add.r.x.y
def
−→ y.(r.x).(Add.r.(S.x))
Algorithm:
x +0 = x
x +S(y) = S(x)+y
We define when a term t represents natural number n.
1 t represents 0 if ∀z,s : t.z.s z
Informally: t “behaves the same as” Zero
2 t represents n +1 if ∀z,s : t.z.s s.q, and q represents n
Informally: t “behaves the same as” S.q
With this, we can define LazyFact such that LazyFact.x represents (x!).
(Omitted.)
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 11 / 22
Interfaces, not pattern matching
Natural numbers
Compatible naturals
Zero.z.s
def
−→ z
S.x.z.s
def
−→ s.x
Add.r.x.y
def
−→ y.(r.x).(Add.r.(S.x))
Algorithm:
x +0 = x
x +S(y) = S(x)+y
With this, we can define LazyFact such that LazyFact.x represents (x!).
(Omitted.)
Add.r.Zero.(LazyFact.(S.Zero)) → LazyFact.(S.Zero).(r.Zero).(Add.r.(S.Zero))
Add.r.(S.Zero).Zero
→ Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero)))
→ r.(S.Zero)
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 11 / 22
Interfaces, not pattern matching
Natural numbers
Compatible naturals
Zero.z.s
def
−→ z
S.x.z.s
def
−→ s.x
Add.r.x.y
def
−→ y.(r.x).(Add.r.(S.x))
Algorithm:
x +0 = x
x +S(y) = S(x)+y
With this, we can define LazyFact such that LazyFact.x represents (x!).
(Omitted.)
Add.r.Zero.(LazyFact.(S.Zero)) r.(S.Zero)
Two types of function names
Call-by-value / eager: calculate result, fill in in continuation
Call-by-name / lazy: compatible with Sn.Zero but delayed
computation
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 11 / 22
The importance of head reduction
Outline
1 First look
2 Definition
3 Long-term goal
4 Interfaces, not pattern matching
5 The importance of head reduction
6 Relation to lambda calculus
7 Conclusion
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 12 / 22
The importance of head reduction
Outline
1 First look
2 Definition
3 Long-term goal
4 Interfaces, not pattern matching
5 The importance of head reduction
6 Relation to lambda calculus
7 Conclusion
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 13 / 22
The importance of head reduction
Operational semantics
Lambda calculus (normal order)
Reduction using two instructions on the top level
M N Push N on stack, continue in M
λx.M Pop N off stack, continue in M[N/x]
as presented in [Levy(2001)]
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 14 / 22
The importance of head reduction
Back to modeling programs
Lambda calculus
λx.+ (f x) (g x)
M N Push N on stack,
continue in M
λx.M Pop N off stack,
continue in M[N/x]
Programming language
fun x → (f x) + (g x)
M N Apply function object
to argument
fun x → M Make function object
In “real languages”, functions throw exceptions and have other side effects.
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 15 / 22
The importance of head reduction
Back to modeling programs
Lambda calculus
λx.+ (f x) (g x)
M N Push N on stack,
continue in M
λx.M Pop N off stack,
continue in M[N/x]
Programming language
fun x → (f x) + (g x)
throws exception
now what?
M N Apply function object
to argument
fun x → M Make function object
In “real languages”, functions throw exceptions and have other side effects.
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 15 / 22
The importance of head reduction
Operational semantics
Computational models with control
Lambda calculus + continuations (λC)
Reduction using four instructions on the top level
M N Push N on stack, continue in M
λx.M Pop N off stack, continue in M[N/x]
A M Empty the stack, continue in M
C M Empty the stack, continue in M (λx.S x)
where function S ‘restores’ the previous stack
(details omitted)
Can model exception-like facilities
CPS transformation to transform λC terms to λ terms
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 16 / 22
The importance of head reduction
CPS transformation
λC
CPS transformation
−−−−−−−−−−−→ subset of λ, makes minimal use of stack
Two calculi in action:
λC calculus: M N, λx.M, A M, C M
Expressive
Subset of λ calculus: M N, λx.M
Simpler
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 17 / 22
The importance of head reduction
CPS transformation
λC
CPS transformation
−−−−−−−−−−−→ subset of λ, makes minimal use of stack
Two calculi in action:
λC calculus: M N, λx.M, A M, C M
Expressive
Subset of λ calculus: M N, λx.M
Simpler
What is this subset, really?
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 17 / 22
The importance of head reduction
CPS transformation
λC
CPS transformation
−−−−−−−−−−−→ subset of λ, makes minimal use of stack
Two calculi in action:
λC calculus: M N, λx.M, A M, C M
Expressive
Subset of λ calculus: M N, λx.M
Simpler
What is this subset, really?
Can we describe it?
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 17 / 22
The importance of head reduction
CPS transformation
λC
CPS transformation
−−−−−−−−−−−→ subset of λ, makes minimal use of stack
Two calculi in action:
λC calculus: M N, λx.M, A M, C M
Expressive
Subset of λ calculus: M N, λx.M
Simpler
What is this subset, really?
Can we describe it?
An elegant model of computation, perhaps?
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 17 / 22
The importance of head reduction
Lambda calculus vs. continuation calculus
λC
Four instructions on the top level
M N Push N on stack, continue in M
λx.M Pop N off stack, continue in M[N/x]
A M Empty the stack, continue in M
C M Empty the stack, continue in M (λx.S x)
where function S ‘restores’ the stack
Continuation calculus
One instruction on the top level, using program P
n.t1.··· .tk Empty the stack, continue in r[t/x]
if n.x1 .··· .xk
def
−→ r ∈ P
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 18 / 22
The importance of head reduction
Lambda calculus vs. continuation calculus
λC
Four instructions on the top level
M N Push N on stack, continue in M
λx.M Pop N off stack, continue in M[N/x]
A M Empty the stack, continue in M
C M Empty the stack, continue in M (λx.S x)
where function S ‘restores’ the stack
Continuation calculus
One instruction on the top level, using program P
n.t1.··· .tk Empty the stack, continue in r[t/x]
if n.x1 .··· .xk
def
−→ r ∈ P
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 18 / 22
The importance of head reduction
Continuation calculus
Continuation calculus
One instruction on the top level, using program P
n.t1.··· .tk Continue in r[t/x]
if n.x1 .··· .xk
def
−→ r ∈ P
No stack needed, because
n.t1.··· .tl does not reduce for l = k.
Subterms are not reduced
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 19 / 22
Relation to lambda calculus
Relation to lambda calculus
λ,λC
CPS transformation
−−−−−−−−−−−→ subset of λ
subset of λ
λx to rules∗
−−−−−−−−−−−−−−−−−−−−−−
unfold†
rules to λx
CC
∗ λx to rules: involves a supercombinator transformation
† Unfold rules to λx: first apply a fixed-point elimination to eliminate cyclic references
Catchphrase
CC is more limited than λ,
thus more suitable to model continuations
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 20 / 22
Relation to lambda calculus
Relation to lambda calculus
λ,λC
CPS transformation
−−−−−−−−−−−→ subset of λ
subset of λ
λx to rules∗
−−−−−−−−−−−−−−−−−−−−−−
unfold†
rules to λx
CC
∗ λx to rules: involves a supercombinator transformation
† Unfold rules to λx: first apply a fixed-point elimination to eliminate cyclic references
Catchphrase
CC is more limited than λ,
thus more suitable to model continuations
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 20 / 22
Conclusion
Conclusion
CC is a constrained term rewriting system
CC is deterministic
Only head reduction
As a consequence,
Suitable for control with continuations (exceptions)
CC is similar to a subset of lambda calculus
Allows both eager and lazy function terms
call-by-value vs. call-by-name
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 21 / 22
Appendix
Bibliography
P.B. Levy.
Call-by-push-value.
PhD thesis, Queen Mary, University of London, 2001.
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 22 / 22

More Related Content

What's hot

International Journal of Mathematics and Statistics Invention (IJMSI)
International Journal of Mathematics and Statistics Invention (IJMSI)International Journal of Mathematics and Statistics Invention (IJMSI)
International Journal of Mathematics and Statistics Invention (IJMSI)inventionjournals
 
Argumentation in Artificial Intelligence: 20 years after Dung's work. Right m...
Argumentation in Artificial Intelligence: 20 years after Dung's work. Right m...Argumentation in Artificial Intelligence: 20 years after Dung's work. Right m...
Argumentation in Artificial Intelligence: 20 years after Dung's work. Right m...Federico Cerutti
 
Argumentation in Artificial Intelligence: 20 years after Dung's work. Left ma...
Argumentation in Artificial Intelligence: 20 years after Dung's work. Left ma...Argumentation in Artificial Intelligence: 20 years after Dung's work. Left ma...
Argumentation in Artificial Intelligence: 20 years after Dung's work. Left ma...Federico Cerutti
 
Conflicts between relevance-sensitive revision
Conflicts between relevance-sensitive revisionConflicts between relevance-sensitive revision
Conflicts between relevance-sensitive revisionstellaseremetaki
 
Argumentation in Artificial Intelligence
Argumentation in Artificial IntelligenceArgumentation in Artificial Intelligence
Argumentation in Artificial IntelligenceFederico Cerutti
 
Bodecoban ngobaochau
Bodecoban ngobaochauBodecoban ngobaochau
Bodecoban ngobaochauDuong Tran
 
5.8 Permutations (dynamic slides)
5.8 Permutations (dynamic slides)5.8 Permutations (dynamic slides)
5.8 Permutations (dynamic slides)Jan Plaza
 
Discrete Mathematics - All chapters
Discrete Mathematics - All chapters Discrete Mathematics - All chapters
Discrete Mathematics - All chapters Omnia A. Abdullah
 
5.1 Defining and visualizing functions. Dynamic slides.
5.1 Defining and visualizing functions. Dynamic slides.5.1 Defining and visualizing functions. Dynamic slides.
5.1 Defining and visualizing functions. Dynamic slides.Jan Plaza
 
Darmon Points: an overview
Darmon Points: an overviewDarmon Points: an overview
Darmon Points: an overviewmmasdeu
 
Fundamental Theorem of Calculus
Fundamental Theorem of CalculusFundamental Theorem of Calculus
Fundamental Theorem of Calculusgizemk
 
D. h. fremlin measure theory, volume 5, part 1 (2000, torres fremlin)
D. h. fremlin   measure theory, volume 5, part 1   (2000, torres fremlin)D. h. fremlin   measure theory, volume 5, part 1   (2000, torres fremlin)
D. h. fremlin measure theory, volume 5, part 1 (2000, torres fremlin)Bluewworksblue
 
Truth as a logical connective
Truth as a logical connectiveTruth as a logical connective
Truth as a logical connectiveShunsuke Yatabe
 
Geometry Section 4-3
Geometry Section 4-3Geometry Section 4-3
Geometry Section 4-3Jimbo Lamb
 
Quantum optical models in noncommutative spaces
Quantum optical models in noncommutative spacesQuantum optical models in noncommutative spaces
Quantum optical models in noncommutative spacesSanjib Dey
 

What's hot (19)

10.1.1.226.4381
10.1.1.226.438110.1.1.226.4381
10.1.1.226.4381
 
International Journal of Mathematics and Statistics Invention (IJMSI)
International Journal of Mathematics and Statistics Invention (IJMSI)International Journal of Mathematics and Statistics Invention (IJMSI)
International Journal of Mathematics and Statistics Invention (IJMSI)
 
Argumentation in Artificial Intelligence: 20 years after Dung's work. Right m...
Argumentation in Artificial Intelligence: 20 years after Dung's work. Right m...Argumentation in Artificial Intelligence: 20 years after Dung's work. Right m...
Argumentation in Artificial Intelligence: 20 years after Dung's work. Right m...
 
Argumentation in Artificial Intelligence: 20 years after Dung's work. Left ma...
Argumentation in Artificial Intelligence: 20 years after Dung's work. Left ma...Argumentation in Artificial Intelligence: 20 years after Dung's work. Left ma...
Argumentation in Artificial Intelligence: 20 years after Dung's work. Left ma...
 
Conflicts between relevance-sensitive revision
Conflicts between relevance-sensitive revisionConflicts between relevance-sensitive revision
Conflicts between relevance-sensitive revision
 
Argumentation in Artificial Intelligence
Argumentation in Artificial IntelligenceArgumentation in Artificial Intelligence
Argumentation in Artificial Intelligence
 
Bodecoban ngobaochau
Bodecoban ngobaochauBodecoban ngobaochau
Bodecoban ngobaochau
 
5.8 Permutations (dynamic slides)
5.8 Permutations (dynamic slides)5.8 Permutations (dynamic slides)
5.8 Permutations (dynamic slides)
 
AI Lesson 14
AI Lesson 14AI Lesson 14
AI Lesson 14
 
Discrete Mathematics - All chapters
Discrete Mathematics - All chapters Discrete Mathematics - All chapters
Discrete Mathematics - All chapters
 
5.1 Defining and visualizing functions. Dynamic slides.
5.1 Defining and visualizing functions. Dynamic slides.5.1 Defining and visualizing functions. Dynamic slides.
5.1 Defining and visualizing functions. Dynamic slides.
 
Darmon Points: an overview
Darmon Points: an overviewDarmon Points: an overview
Darmon Points: an overview
 
Chap05
Chap05Chap05
Chap05
 
Fundamental Theorem of Calculus
Fundamental Theorem of CalculusFundamental Theorem of Calculus
Fundamental Theorem of Calculus
 
AI Lesson 15
AI Lesson 15AI Lesson 15
AI Lesson 15
 
D. h. fremlin measure theory, volume 5, part 1 (2000, torres fremlin)
D. h. fremlin   measure theory, volume 5, part 1   (2000, torres fremlin)D. h. fremlin   measure theory, volume 5, part 1   (2000, torres fremlin)
D. h. fremlin measure theory, volume 5, part 1 (2000, torres fremlin)
 
Truth as a logical connective
Truth as a logical connectiveTruth as a logical connective
Truth as a logical connective
 
Geometry Section 4-3
Geometry Section 4-3Geometry Section 4-3
Geometry Section 4-3
 
Quantum optical models in noncommutative spaces
Quantum optical models in noncommutative spacesQuantum optical models in noncommutative spaces
Quantum optical models in noncommutative spaces
 

Similar to Continuation calculus at Term Rewriting Seminar

2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting Poster2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting PosterChelsea Battell
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionEelco Visser
 
Applications of partial differentiation
Applications of partial differentiationApplications of partial differentiation
Applications of partial differentiationVaibhav Tandel
 
The Fundamental theorem of calculus
The Fundamental theorem of calculus The Fundamental theorem of calculus
The Fundamental theorem of calculus AhsanIrshad8
 
Testing Forest-Isomorphism in the Adjacency List Model
Testing Forest-Isomorphismin the Adjacency List ModelTesting Forest-Isomorphismin the Adjacency List Model
Testing Forest-Isomorphism in the Adjacency List Modelirrrrr
 
Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...
Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...
Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...Kenshi Abe
 
Data Science Meetup: DGLARS and Homotopy LASSO for Regression Models
Data Science Meetup: DGLARS and Homotopy LASSO for Regression ModelsData Science Meetup: DGLARS and Homotopy LASSO for Regression Models
Data Science Meetup: DGLARS and Homotopy LASSO for Regression ModelsColleen Farrelly
 
Optimization of probabilistic argumentation with Markov processes
Optimization of probabilistic argumentation with Markov processesOptimization of probabilistic argumentation with Markov processes
Optimization of probabilistic argumentation with Markov processesEmmanuel Hadoux
 
Reciprocity Law For Flat Conformal Metrics With Conical Singularities
Reciprocity Law For Flat Conformal Metrics With Conical SingularitiesReciprocity Law For Flat Conformal Metrics With Conical Singularities
Reciprocity Law For Flat Conformal Metrics With Conical SingularitiesLukasz Obara
 
Fixed point result in menger space with ea property
Fixed point result in menger space with ea propertyFixed point result in menger space with ea property
Fixed point result in menger space with ea propertyAlexander Decker
 
Prime numbers boundary
Prime numbers boundary Prime numbers boundary
Prime numbers boundary Camilo Ulloa
 
The Chase in Database Theory
The Chase in Database TheoryThe Chase in Database Theory
The Chase in Database TheoryJan Hidders
 
Darmon Points for fields of mixed signature
Darmon Points for fields of mixed signatureDarmon Points for fields of mixed signature
Darmon Points for fields of mixed signaturemmasdeu
 
A Theory of the Learnable; PAC Learning
A Theory of the Learnable; PAC LearningA Theory of the Learnable; PAC Learning
A Theory of the Learnable; PAC Learningdhruvgairola
 

Similar to Continuation calculus at Term Rewriting Seminar (20)

Pl vol1
Pl vol1Pl vol1
Pl vol1
 
2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting Poster2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting Poster
 
Unit05 dbms
Unit05 dbmsUnit05 dbms
Unit05 dbms
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint Resolution
 
Applications of partial differentiation
Applications of partial differentiationApplications of partial differentiation
Applications of partial differentiation
 
The Fundamental theorem of calculus
The Fundamental theorem of calculus The Fundamental theorem of calculus
The Fundamental theorem of calculus
 
Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...
Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...
Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...
 
Testing Forest-Isomorphism in the Adjacency List Model
Testing Forest-Isomorphismin the Adjacency List ModelTesting Forest-Isomorphismin the Adjacency List Model
Testing Forest-Isomorphism in the Adjacency List Model
 
Big o
Big oBig o
Big o
 
Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...
Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...
Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...
 
Data Science Meetup: DGLARS and Homotopy LASSO for Regression Models
Data Science Meetup: DGLARS and Homotopy LASSO for Regression ModelsData Science Meetup: DGLARS and Homotopy LASSO for Regression Models
Data Science Meetup: DGLARS and Homotopy LASSO for Regression Models
 
Optimization of probabilistic argumentation with Markov processes
Optimization of probabilistic argumentation with Markov processesOptimization of probabilistic argumentation with Markov processes
Optimization of probabilistic argumentation with Markov processes
 
Reciprocity Law For Flat Conformal Metrics With Conical Singularities
Reciprocity Law For Flat Conformal Metrics With Conical SingularitiesReciprocity Law For Flat Conformal Metrics With Conical Singularities
Reciprocity Law For Flat Conformal Metrics With Conical Singularities
 
H-MLQ
H-MLQH-MLQ
H-MLQ
 
Fixed point result in menger space with ea property
Fixed point result in menger space with ea propertyFixed point result in menger space with ea property
Fixed point result in menger space with ea property
 
Prime numbers boundary
Prime numbers boundary Prime numbers boundary
Prime numbers boundary
 
The Chase in Database Theory
The Chase in Database TheoryThe Chase in Database Theory
The Chase in Database Theory
 
04_AJMS_254_19.pdf
04_AJMS_254_19.pdf04_AJMS_254_19.pdf
04_AJMS_254_19.pdf
 
Darmon Points for fields of mixed signature
Darmon Points for fields of mixed signatureDarmon Points for fields of mixed signature
Darmon Points for fields of mixed signature
 
A Theory of the Learnable; PAC Learning
A Theory of the Learnable; PAC LearningA Theory of the Learnable; PAC Learning
A Theory of the Learnable; PAC Learning
 

Recently uploaded

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Recently uploaded (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Continuation calculus at Term Rewriting Seminar

  • 1. Continuation calculus Bram Geron1 Herman Geuvers1,2 1Eindhoven University of Technology 2Radboud University Nijmegen Term Rewriting Seminar, May 2013 Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 1 / 22
  • 2. Outline 1 First look 2 Definition 3 Long-term goal 4 Interfaces, not pattern matching 5 The importance of head reduction 6 Relation to lambda calculus 7 Conclusion Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 2 / 22
  • 3. First look Rules, names, variables, terms CC is a constrained term rewriting system Comp.f .g.x def −→ f .(g.x) Comp.AddOne.Fact.4 → AddOne.(Fact.4) Rules One definition per name (max) No pattern matching Only head reduction Consequences Deterministic Simple operational semantics Suitable for modeling continuations, hence exceptions Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 3 / 22
  • 4. First look Rules, names, variables, terms CC is a constrained term rewriting system rule Comp name (constant) .f .g.x variables def −→ f .(g.x) Comp.AddOne.Fact.4 term → AddOne.(Fact.4) term Rules One definition per name (max) No pattern matching Only head reduction Consequences Deterministic Simple operational semantics Suitable for modeling continuations, hence exceptions Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 3 / 22
  • 5. First look Rules, names, variables, terms CC is a constrained term rewriting system rule Comp name (constant) .f .g.x variables def −→ f .(g.x) Comp.AddOne.Fact.4 term → AddOne.(Fact.4) term Rules One definition per name (max) No pattern matching Only head reduction Consequences Deterministic Simple operational semantics Suitable for modeling continuations, hence exceptions Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 3 / 22
  • 6. First look Head reduction: continuation passing style Functions fill in the result in their continuation parameter Comp.f .g.x def −→ f .(g.x) Comp.AddOne.Fact.4 → AddOne.(Fact).4 Realistic names: Fact.r.x r.x! AddOne.r.x r.(x +1) Fact.(AddOne.r).4 AddOne.r.24 r.25 Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
  • 7. First look Head reduction: continuation passing style Functions fill in the result in their continuation parameter Comp.f .g.x def −→ f .(g.x) Comp.AddOne.Fact.4 → AddOne.(Fact).4 Realistic names: Fact.r.x r.x! AddOne.r.x r.(x +1) Fact.(AddOne.r).4 AddOne.r.24 r.25 Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
  • 8. First look Head reduction: continuation passing style Functions fill in the result in their continuation parameter Comp.f .g.x def −→ f .(g.x) Comp.AddOne.Fact.4 → AddOne.(Fact).4 Realistic names: Fact.r.x r.x! AddOne.r.x r.(x +1) Fact.(AddOne.r).4 AddOne.r.24 r.25 Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
  • 9. First look Head reduction: continuation passing style Functions fill in the result in their continuation parameter Comp.r.f .g.x def −→ g.(f .r).x Comp.r.AddOne.Fact.4 → Fact.(AddOne.r).4 Realistic names: Fact.r.x r.x! AddOne.r.x r.(x +1) Fact.(AddOne.r).4 AddOne.r.24 r.25 Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
  • 10. First look Head reduction: continuation passing style Functions fill in the result in their continuation parameter Comp.r.f .g.x def −→ g.(f .r).x Comp.r.AddOne.Fact.4 → Fact.(AddOne.r).4 Realistic names: Fact.r.x r.x! AddOne.r.x r.(x +1) Fact.(AddOne.r).4 AddOne.r.24 r.25 Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
  • 11. Definition Definitions There is an infinite set of names, indicated by a capital. A term is either a name, or two terms combined by a dot. We write a.b.c as shorthand for (a.b).c. A program P consists of a set of rules, of the form Name.variable.··· .variable def −→ term over those variables That rule defines that name. Each rule defines a different name. If “N.x1 .··· .xk def −→ r” ∈ P, then we reduce N.t → r[t/x]. Term N.x1.··· .xl for l = k does not reduce at all. There is only head reduction. Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 5 / 22
  • 12. Definition Definitions There is an infinite set of names, indicated by a capital. A term is either a name, or two terms combined by a dot. We write a.b.c as shorthand for (a.b).c. A program P consists of a set of rules, of the form Name.variable.··· .variable def −→ term over those variables That rule defines that name. Each rule defines a different name. If “N.x1 .··· .xk def −→ r” ∈ P, then we reduce N.t → r[t/x]. Term N.x1.··· .xl for l = k does not reduce at all. There is only head reduction. Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 5 / 22
  • 13. Definition Definitions There is an infinite set of names, indicated by a capital. A term is either a name, or two terms combined by a dot. We write a.b.c as shorthand for (a.b).c. A program P consists of a set of rules, of the form Name.variable.··· .variable def −→ term over those variables That rule defines that name. Each rule defines a different name. If “N.x1 .··· .xk def −→ r” ∈ P, then we reduce N.t → r[t/x]. Term N.x1.··· .xl for l = k does not reduce at all. There is only head reduction. Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 5 / 22
  • 14. Long-term goal Long-term goal Formally modeling programming languages Hopefully as a base for better languages Operational semantics Running time: #steps ∼ seconds CPU time Warning: some unsubstantiated claims Compositional Facilitates proving properties Deterministic by nature Works with continuations Explained later Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 6 / 22
  • 15. Long-term goal Long-term goal Formally modeling programming languages Hopefully as a base for better languages Operational semantics Running time: #steps ∼ seconds CPU time Warning: some unsubstantiated claims Compositional Facilitates proving properties Deterministic by nature Works with continuations Explained later Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 6 / 22
  • 16. Interfaces, not pattern matching Outline 1 First look 2 Definition 3 Long-term goal 4 Interfaces, not pattern matching 5 The importance of head reduction 6 Relation to lambda calculus 7 Conclusion Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 7 / 22
  • 17. Interfaces, not pattern matching Outline 1 First look 2 Definition 3 Long-term goal 4 Interfaces, not pattern matching 5 The importance of head reduction 6 Relation to lambda calculus 7 Conclusion Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 8 / 22
  • 18. Interfaces, not pattern matching Natural numbers Slightly similar to lambda calculus Zero.z.s def −→ z S.x.z.s def −→ s.x Add.r.x.y def −→ y.(r.x).(Add.r.(S.x)) Algorithm: x +0 = x x +S(y) = S(x)+y Add.r.(S.Zero).Zero → Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero))) → r.(S.Zero) Add.r.Zero.(S.Zero) → S.Zero.(r.Zero).(Add.r.(S.Zero)) → Add.r.(S.Zero).Zero → Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero))) → r.(S.Zero) Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 9 / 22
  • 19. Interfaces, not pattern matching Natural numbers Slightly similar to lambda calculus Zero.z.s def −→ z S.x.z.s def −→ s.x Add.r.x.y def −→ y.(r.x).(Add.r.(S.x)) Algorithm: x +0 = x x +S(y) = S(x)+y Add.r.(S.Zero).Zero → Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero))) → r.(S.Zero) Add.r.Zero.(S.Zero) → S.Zero.(r.Zero).(Add.r.(S.Zero)) → Add.r.(S.Zero).Zero → Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero))) → r.(S.Zero) Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 9 / 22
  • 20. Interfaces, not pattern matching Natural numbers Slightly similar to lambda calculus Zero.z.s def −→ z S.x.z.s def −→ s.x Add.r.x.y def −→ y.(r.x).(Add.r.(S.x)) Algorithm: x +0 = x x +S(y) = S(x)+y What can we feed to Add? Zero S.(··· .(S.Zero)···) Something else? Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 10 / 22
  • 21. Interfaces, not pattern matching Natural numbers Slightly similar to lambda calculus Zero.z.s def −→ z S.x.z.s def −→ s.x Add.r.x.y def −→ y.(r.x).(Add.r.(S.x)) Algorithm: x +0 = x x +S(y) = S(x)+y What can we feed to Add? Zero S.(··· .(S.Zero)···) Something else? Yes! Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 10 / 22
  • 22. Interfaces, not pattern matching Natural numbers Compatible naturals Zero.z.s def −→ z S.x.z.s def −→ s.x Add.r.x.y def −→ y.(r.x).(Add.r.(S.x)) Algorithm: x +0 = x x +S(y) = S(x)+y We define when a term t represents natural number n. 1 t represents 0 if ∀z,s : t.z.s z Informally: t “behaves the same as” Zero 2 t represents n +1 if ∀z,s : t.z.s s.q, and q represents n Informally: t “behaves the same as” S.q With this, we can define LazyFact such that LazyFact.x represents (x!). (Omitted.) Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 11 / 22
  • 23. Interfaces, not pattern matching Natural numbers Compatible naturals Zero.z.s def −→ z S.x.z.s def −→ s.x Add.r.x.y def −→ y.(r.x).(Add.r.(S.x)) Algorithm: x +0 = x x +S(y) = S(x)+y With this, we can define LazyFact such that LazyFact.x represents (x!). (Omitted.) Add.r.Zero.(LazyFact.(S.Zero)) → LazyFact.(S.Zero).(r.Zero).(Add.r.(S.Zero)) Add.r.(S.Zero).Zero → Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero))) → r.(S.Zero) Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 11 / 22
  • 24. Interfaces, not pattern matching Natural numbers Compatible naturals Zero.z.s def −→ z S.x.z.s def −→ s.x Add.r.x.y def −→ y.(r.x).(Add.r.(S.x)) Algorithm: x +0 = x x +S(y) = S(x)+y With this, we can define LazyFact such that LazyFact.x represents (x!). (Omitted.) Add.r.Zero.(LazyFact.(S.Zero)) r.(S.Zero) Two types of function names Call-by-value / eager: calculate result, fill in in continuation Call-by-name / lazy: compatible with Sn.Zero but delayed computation Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 11 / 22
  • 25. The importance of head reduction Outline 1 First look 2 Definition 3 Long-term goal 4 Interfaces, not pattern matching 5 The importance of head reduction 6 Relation to lambda calculus 7 Conclusion Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 12 / 22
  • 26. The importance of head reduction Outline 1 First look 2 Definition 3 Long-term goal 4 Interfaces, not pattern matching 5 The importance of head reduction 6 Relation to lambda calculus 7 Conclusion Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 13 / 22
  • 27. The importance of head reduction Operational semantics Lambda calculus (normal order) Reduction using two instructions on the top level M N Push N on stack, continue in M λx.M Pop N off stack, continue in M[N/x] as presented in [Levy(2001)] Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 14 / 22
  • 28. The importance of head reduction Back to modeling programs Lambda calculus λx.+ (f x) (g x) M N Push N on stack, continue in M λx.M Pop N off stack, continue in M[N/x] Programming language fun x → (f x) + (g x) M N Apply function object to argument fun x → M Make function object In “real languages”, functions throw exceptions and have other side effects. Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 15 / 22
  • 29. The importance of head reduction Back to modeling programs Lambda calculus λx.+ (f x) (g x) M N Push N on stack, continue in M λx.M Pop N off stack, continue in M[N/x] Programming language fun x → (f x) + (g x) throws exception now what? M N Apply function object to argument fun x → M Make function object In “real languages”, functions throw exceptions and have other side effects. Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 15 / 22
  • 30. The importance of head reduction Operational semantics Computational models with control Lambda calculus + continuations (λC) Reduction using four instructions on the top level M N Push N on stack, continue in M λx.M Pop N off stack, continue in M[N/x] A M Empty the stack, continue in M C M Empty the stack, continue in M (λx.S x) where function S ‘restores’ the previous stack (details omitted) Can model exception-like facilities CPS transformation to transform λC terms to λ terms Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 16 / 22
  • 31. The importance of head reduction CPS transformation λC CPS transformation −−−−−−−−−−−→ subset of λ, makes minimal use of stack Two calculi in action: λC calculus: M N, λx.M, A M, C M Expressive Subset of λ calculus: M N, λx.M Simpler Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 17 / 22
  • 32. The importance of head reduction CPS transformation λC CPS transformation −−−−−−−−−−−→ subset of λ, makes minimal use of stack Two calculi in action: λC calculus: M N, λx.M, A M, C M Expressive Subset of λ calculus: M N, λx.M Simpler What is this subset, really? Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 17 / 22
  • 33. The importance of head reduction CPS transformation λC CPS transformation −−−−−−−−−−−→ subset of λ, makes minimal use of stack Two calculi in action: λC calculus: M N, λx.M, A M, C M Expressive Subset of λ calculus: M N, λx.M Simpler What is this subset, really? Can we describe it? Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 17 / 22
  • 34. The importance of head reduction CPS transformation λC CPS transformation −−−−−−−−−−−→ subset of λ, makes minimal use of stack Two calculi in action: λC calculus: M N, λx.M, A M, C M Expressive Subset of λ calculus: M N, λx.M Simpler What is this subset, really? Can we describe it? An elegant model of computation, perhaps? Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 17 / 22
  • 35. The importance of head reduction Lambda calculus vs. continuation calculus λC Four instructions on the top level M N Push N on stack, continue in M λx.M Pop N off stack, continue in M[N/x] A M Empty the stack, continue in M C M Empty the stack, continue in M (λx.S x) where function S ‘restores’ the stack Continuation calculus One instruction on the top level, using program P n.t1.··· .tk Empty the stack, continue in r[t/x] if n.x1 .··· .xk def −→ r ∈ P Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 18 / 22
  • 36. The importance of head reduction Lambda calculus vs. continuation calculus λC Four instructions on the top level M N Push N on stack, continue in M λx.M Pop N off stack, continue in M[N/x] A M Empty the stack, continue in M C M Empty the stack, continue in M (λx.S x) where function S ‘restores’ the stack Continuation calculus One instruction on the top level, using program P n.t1.··· .tk Empty the stack, continue in r[t/x] if n.x1 .··· .xk def −→ r ∈ P Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 18 / 22
  • 37. The importance of head reduction Continuation calculus Continuation calculus One instruction on the top level, using program P n.t1.··· .tk Continue in r[t/x] if n.x1 .··· .xk def −→ r ∈ P No stack needed, because n.t1.··· .tl does not reduce for l = k. Subterms are not reduced Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 19 / 22
  • 38. Relation to lambda calculus Relation to lambda calculus λ,λC CPS transformation −−−−−−−−−−−→ subset of λ subset of λ λx to rules∗ −−−−−−−−−−−−−−−−−−−−−− unfold† rules to λx CC ∗ λx to rules: involves a supercombinator transformation † Unfold rules to λx: first apply a fixed-point elimination to eliminate cyclic references Catchphrase CC is more limited than λ, thus more suitable to model continuations Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 20 / 22
  • 39. Relation to lambda calculus Relation to lambda calculus λ,λC CPS transformation −−−−−−−−−−−→ subset of λ subset of λ λx to rules∗ −−−−−−−−−−−−−−−−−−−−−− unfold† rules to λx CC ∗ λx to rules: involves a supercombinator transformation † Unfold rules to λx: first apply a fixed-point elimination to eliminate cyclic references Catchphrase CC is more limited than λ, thus more suitable to model continuations Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 20 / 22
  • 40. Conclusion Conclusion CC is a constrained term rewriting system CC is deterministic Only head reduction As a consequence, Suitable for control with continuations (exceptions) CC is similar to a subset of lambda calculus Allows both eager and lazy function terms call-by-value vs. call-by-name Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 21 / 22
  • 41. Appendix Bibliography P.B. Levy. Call-by-push-value. PhD thesis, Queen Mary, University of London, 2001. Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 22 / 22