Optimal optimality? Families and history (Some syntax) Recording the history History and memory T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 1/20 Optimality for Dynamic Patterns Thibaut Balabonski Laboratoire PPS CNRS and Universit´ e Paris Diderot PPDP 2010: July 28
41
Embed
Optimality for Dynamic Patternsblsk/Docs/Balabonski-Talk-PPDP10.pdf · T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 1/20 Optimality for Dynamic Patterns
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
I
Optimal optimality?
Families and history
(Some syntax)
Recording the history
History and memory
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 1/20
Optimalityfor Dynamic Patterns
Thibaut Balabonski
Laboratoire PPSCNRS and Universite Paris Diderot
PPDP 2010: July 28
Computing with data structures
I
Optimal optimality?
Families and history
(Some syntax)
Recording the history
History and memory
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 2/20
type ’a tree =
| Data of ’a
| Node of ’a tree * ’a tree
let rec upd f t = match t with
| Data a -> Data (f a)
| Node l r -> Node (upd f l) (upd f r)
Pattern matching:
• tests the shape.
• extracts substructures.
New polymorphisms
I
Optimal optimality?
Families and history
(Some syntax)
Recording the history
History and memory
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 3/20
• Pattern polymorphism: parameters in patterns.
• Path polymorphism: shape irrelevance.
let rec upd c f t = match t with
| c d -> c (f d)
| x y -> (upd c f x) (upd c f y)
| a -> a
Instantiation of the parameter c
• Constructors like Data.
• Functions building patterns.
Dynam
icpa
ttern
s
New polymorphisms
I
Optimal optimality?
Families and history
(Some syntax)
Recording the history
History and memory
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 3/20
• Pattern polymorphism: parameters in patterns.
• Path polymorphism: shape irrelevance.
let rec upd c f t = match t with
| Data d -> Data (f d)
| x y -> (upd c f x) (upd c f y)
| a -> a
Instantiation of the parameter c
• Constructors like Data.
• Functions building patterns.
Dynam
icpa
ttern
s
New polymorphisms
I
Optimal optimality?
Families and history
(Some syntax)
Recording the history
History and memory
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 3/20
• Pattern polymorphism: parameters in patterns.
• Path polymorphism: shape irrelevance.
let rec upd c f t = match t with
| (fun x -> Node (Data x) (Data )) d ->
| x y -> (upd c f x) (upd c f y)
| a -> a
Instantiation of the parameter c
• Constructors like Data.
• Functions building patterns.
Dynam
icpa
ttern
s
New polymorphisms
I
Optimal optimality?
Families and history
(Some syntax)
Recording the history
History and memory
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 3/20
• Pattern polymorphism: parameters in patterns.
• Path polymorphism: shape irrelevance.
let rec upd c f t = match t with
| Node (Data d) (Data ) -> Node ...
| x y -> (upd c f x) (upd c f y)
| a -> a
Instantiation of the parameter c
• Constructors like Data.
• Functions building patterns.
Dynam
icpa
ttern
s
New polymorphisms
I
Optimal optimality?
Families and history
(Some syntax)
Recording the history
History and memory
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 3/20
• Pattern polymorphism: parameters in patterns.
• Path polymorphism: shape irrelevance.
let rec upd c f t = match t with
| c d -> c (f d)
| x y -> (upd c f x) (upd c f y)
| a -> a
Instantiation of the parameter c
• Constructors like Data.
• Functions building patterns.
Dynam
icpa
ttern
s
Collateral damage
I
Optimal optimality?
Families and history
(Some syntax)
Recording the history
History and memory
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 4/20
Usual compile-time analyzes
| Node l (Data d) ->
| Node (Data d) (Node ) ->
| Node (Node l r) (Node ) ->
This requires static patterns!
Goal
Run-time sharing mechanismsfor dynamic patterns.
Collateral damage
I
Optimal optimality?
Families and history
(Some syntax)
Recording the history
History and memory
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 4/20
Usual compile-time analyzes
| Node l (Data d) ->
| Node (Data d) (Node ) ->
| Node (Node l r) (Node ) ->
This requires static patterns!
Goal
Run-time sharing mechanismsfor dynamic patterns.
Collateral damage
I
Optimal optimality?
Families and history
(Some syntax)
Recording the history
History and memory
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 4/20
Usual compile-time analyzes
| Node l (Data d) ->
| Node (Data d) (Node ) ->
| Node (Node l r) (Node ) ->
This requires static patterns!
Goal
Run-time sharing mechanismsfor dynamic patterns.
Roadmap
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 5/20
1 Is optimal sharing a reasonable solution?
2 Families of terms: learning from history
3 (Some syntax)
4 Recording the history
5 From history to memory
Is optimal sharing a reasonable solution?
There is some mismatch betweentheoretical optimality and practical efficiency.
Families of terms: learning from history
(Some syntax)
Recording the history
From history to memory
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 6/20
The trap of optimality
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 6/20
Sharing
Extra cost
Usual implementations
β-Optimality
The trap of optimality
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 6/20
Sharing
Extra cost
Usual implementations
β-Optimality
The trap of optimality
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 6/20
Sharing
Extra cost
Usual implementations
β-Optimality
Weak reduction
IOptimal optimality?
Families and history
(Some syntax)
Recording the history
History and memory
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 7/20
Usual implementations
• Passing arguments to functions.
• No partial evaluation.
⇒ No evaluation under a binder (λ).
Confluent weak reduction
No reduction betweena bounded variable and its binder.
Families of terms: learning from history
Terms with same history should not be considereddifferent.
Is optimal sharing a reasonable solution?
(Some syntax)
Recording the history
From history to memory
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 8/20
Optimality and history
IFamilies and history
Optimal optimality?
(Some syntax)
Recording the history
History and memory
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 8/20
Optimality commandment
At each step you shall reduce a whole family.
• Family: all redexes sharing a common history.
• History: all events that contributed to thecreation of a redex.
• Redex: REDucible EXpression.
Screening the history
IFamilies and history
Optimal optimality?
(Some syntax)
Recording the history
History and memory
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 9/20
Which reduction steps are relevant?
Back to basics
• analysis of direct contribution.
• how can redexes be created?
And later
• record contributions in labels.
(Some syntax)
Digression: the Weak Pure Pattern Calculus.Simple syntax, complex reduction.
Is optimal sharing a reasonable solution?
Families of terms: learning from history
Recording the history
From history to memory
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 10/20
Syntactic trees
I(Some syntax)
Optimal optimality?
Families and history
Recording the history
History and memory
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 10/20
@
A
λx
Bx x
Syntactic trees
I(Some syntax)
Optimal optimality?
Families and history
Recording the history
History and memory
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 10/20
@
A
λθ
Bx x
Pxc
Pattern matching: a complex operation
I(Some syntax)
Optimal optimality?
Families and history
Recording the history
History and memory
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 11/20
@
λθ
Bxi xj
PP
xi xj Ai Aj
A
B
Ai Aj
Failure
If A and P incompatible, reduction to ⊥.
Partial definition
Matching undefined for improper terms.
Pattern matching: a meta-operation
T. Balabonski — Optimality for Dynamic Patterns PPDP 2010: July 28 — 12/20