A Graph-Rewriting & RIMS, Kyoto University) work in ...kmuroya/talks/lola18.pdf · work in...
Transcript of A Graph-Rewriting & RIMS, Kyoto University) work in ...kmuroya/talks/lola18.pdf · work in...
Muroya (U. B’ham. & RIMS, Kyoto U.)
A Graph-Rewriting Perspective of the Beta-Law
Dan R. GhicaTodd Waugh Ambridge
(University of Birmingham)
LOLA 2018 (Oxford), 7 July 2018
Koko Muroya(University of Birmingham
& RIMS, Kyoto University)
work in progress
Muroya (U. B’ham. & RIMS, Kyoto U.)
Call-by-value beta-law
golden standard of (functional) program equivalence and compiler optimisation
“A function can be applied to a value before evaluation without changing the outcome”
2
Muroya (U. B’ham. & RIMS, Kyoto U.)
Call-by-value beta-law
golden standard of (functional) program equivalence and compiler optimisation… respected by most intrinsic/extrinsic language extensions
3
Muroya (U. B’ham. & RIMS, Kyoto U.)
Call-by-value beta-law
golden standard of (functional) program equivalence and compiler optimisation… respected by most intrinsic/extrinsic language extensions
4
basic operations(nat, int, float, ...)
Muroya (U. B’ham. & RIMS, Kyoto U.)
Call-by-value beta-law
golden standard of (functional) program equivalence and compiler optimisation… respected by most intrinsic/extrinsic language extensions
5
algebraicdata structures
Muroya (U. B’ham. & RIMS, Kyoto U.)
Call-by-value beta-law
golden standard of (functional) program equivalence and compiler optimisation… respected by most intrinsic/extrinsic language extensions
6
recursion
Muroya (U. B’ham. & RIMS, Kyoto U.)
Call-by-value beta-law
golden standard of (functional) program equivalence and compiler optimisation… respected by most intrinsic/extrinsic language extensions
7
conditionalstatement
Muroya (U. B’ham. & RIMS, Kyoto U.)
Call-by-value beta-law
golden standard of (functional) program equivalence and compiler optimisation… respected by most intrinsic/extrinsic language extensions
8
algebraic effects& handlers
Muroya (U. B’ham. & RIMS, Kyoto U.)
Call-by-value beta-law
golden standard of (functional) program equivalence and compiler optimisation… respected by most intrinsic/extrinsic language extensions
9
control operators
Muroya (U. B’ham. & RIMS, Kyoto U.)
Call-by-value beta-law
golden standard of (functional) program equivalence and compiler optimisation… respected by most intrinsic/extrinsic language extensions
justification by (operational) semantics, but how?
10
Muroya (U. B’ham. & RIMS, Kyoto U.)
Call-by-value beta-law
golden standard of (functional) program equivalence and compiler optimisation… respected by most intrinsic/extrinsic language extensions
justification by (operational) semantics, but how?
11
Muroya (U. B’ham. & RIMS, Kyoto U.)
Question
Given an extension of untyped λ-calculus,
what semantic property of the extension
validates the call-by-value beta-law?
12
Muroya (U. B’ham. & RIMS, Kyoto U.)
Question
Given an extension of untyped λ-calculus,
what operational-semantic property of the extension
validates the call-by-value beta-law?
13
Muroya (U. B’ham. & RIMS, Kyoto U.)
Question
Given an extension of untyped λ-calculus,
what operational-semantic property of the extension
validates the call-by-value beta-law?
14
Answer?
Muroya (U. B’ham. & RIMS, Kyoto U.)
Question
Given an extension of untyped λ-calculus,
what operational-semantic property of the extension
validates the call-by-value beta-law?
15
Answer?
A formal answer is yet to be stated…
But a graph-rewriting perspective provides:
● a useful & robust method
● key observations
Muroya (U. B’ham. & RIMS, Kyoto U.)
Methodology
Given an operational semantics of an extended λ-calculus:
define the contextual equivalence by:
prove the beta-law:
and observe some sufficient condition.
16
closed term
basic constant
Muroya (U. B’ham. & RIMS, Kyoto U.)
Methodology
Given an operational semantics of an extended λ-calculus:
define the contextual equivalence by:
prove the beta-law:
and observe some sufficient condition.
17
closed term
basic constant
Muroya (U. B’ham. & RIMS, Kyoto U.)
Which operational semantics?
● easy to extend (esp. by nondeterminism, observables)
● easy to prove a contextual equivalence
18
Muroya (U. B’ham. & RIMS, Kyoto U.)
Which operational semantics?
● easy to extend (esp. by nondeterminism, observables)
● easy to prove a contextual equivalence
small-step reduction
19
Muroya (U. B’ham. & RIMS, Kyoto U.)
Which operational semantics?
● easy to extend (esp. by nondeterminism, observables)
● easy to prove a contextual equivalence
small-step reduction
… obscures a sub-term of interest :-(
20
redex searching(i.e. decomposition into evaluation context & redex)
obscures `t`
Muroya (U. B’ham. & RIMS, Kyoto U.)
Which operational semantics?
● easy to extend (esp. by nondeterminism, observables)
● easy to prove a contextual equivalence
small-step “token-guided” graph-rewriting
21
closed term
basic constant
Muroya (U. B’ham. & RIMS, Kyoto U.)
Which operational semantics?
● easy to extend (esp. by nondeterminism, observables)
● easy to prove a contextual equivalence
small-step “token-guided” graph-rewriting
22
graph representationwith unique open edge
closed term
Muroya (U. B’ham. & RIMS, Kyoto U.)
Which operational semantics?
● easy to extend (esp. by nondeterminism, observables)
● easy to prove a contextual equivalence
small-step “token-guided” graph-rewriting
23
distinguished edge/node as
“token”
closed term
graph representationwith unique open edge
Muroya (U. B’ham. & RIMS, Kyoto U.)
● easy to extend (esp. by nondeterminism, observables)
● easy to prove a contextual equivalence
small-step “token-guided” graph-rewriting
● redex searching (moving the token)
● rewriting (replacing a sub-graph)
Which operational semantics?
24
Muroya (U. B’ham. & RIMS, Kyoto U.)
● easy to extend (esp. by nondeterminism, observables)
● easy to prove a contextual equivalence
small-step “token-guided” graph-rewriting
● redex searching (moving the token)
● rewriting (replacing a sub-graph)
Which operational semantics?
25
garbage
Muroya (U. B’ham. & RIMS, Kyoto U.)
Which operational semantics?
● easy to extend (esp. by nondeterminism, observables)
● easy to prove a contextual equivalence
small-step “token-guided” graph-rewriting
… keeps a sub-term of interest traceable :-)
26
Muroya (U. B’ham. & RIMS, Kyoto U.)
Which operational semantics?
● easy to extend (esp. by nondeterminism, observables)
● easy to prove a contextual equivalence
small-step “token-guided” graph-rewriting
● visible interaction between the token and a sub-graph
○ redex searching○ rewriting
step-wise reasoning to prove a contextual equivalence27
vs
27
Muroya (U. B’ham. & RIMS, Kyoto U.)
Methodology
Given operational semantics of an extended λ-calculus:
define the contextual equivalence by:
prove the beta-law:
and observe some sufficient condition.
28
closed term
same basic constants
Muroya (U. B’ham. & RIMS, Kyoto U.)
Case study: linear λ-calculus + “linear” recursion
Given operational semantics:
define the contextual equivalence by:
prove the beta-law:
and observe some sufficient condition.
29
closed term
same basic constants
Muroya (U. B’ham. & RIMS, Kyoto U.)
Case study: linear λ-calculus + “linear” recursion
Given operational semantics:
30
closed term
linear variable
“linear” recursion
basic constant
Muroya (U. B’ham. & RIMS, Kyoto U.)
Case study: linear λ-calculus + “linear” recursion
Given operational semantics:
define the contextual equivalence by:
prove the beta-law:
and observe some sufficient condition.
31
closed term
same basic constants
Muroya (U. B’ham. & RIMS, Kyoto U.)
Case study: linear λ-calculus + “linear” recursion
… prove the beta-law:
32
same “graph-context”with matching
interface
no garbage created
Muroya (U. B’ham. & RIMS, Kyoto U.)
Case study: linear λ-calculus + “linear” recursion
… prove the beta-law by step-wise reasoning:
33
no garbage created
same “graph-context”with matching
interface
Muroya (U. B’ham. & RIMS, Kyoto U.)
Case study: linear λ-calculus + “linear” recursion
… prove the beta-law by step-wise reasoning:
1. redex searching “within”
graph-context
2. rewriting “in” graph-context
3. visiting the hole
34
same “graph-context”with matching
interface
Muroya (U. B’ham. & RIMS, Kyoto U.)
1. redex searching “within” graph-context (1/6)
Case study: linear λ-calculus + “linear” recursion
35
searching stopped
at a value
Muroya (U. B’ham. & RIMS, Kyoto U.)
1. redex searching “within” graph-context (2/6)
Case study: linear λ-calculus + “linear” recursion
36
searching stopped
at a value
Muroya (U. B’ham. & RIMS, Kyoto U.)
1. redex searching “within” graph-context (3/6)
Case study: linear λ-calculus + “linear” recursion
37
a redex found
Muroya (U. B’ham. & RIMS, Kyoto U.)
1. redex searching “within” graph-context (4/6)
Case study: linear λ-calculus + “linear” recursion
38
right-to-left call-by-value
Muroya (U. B’ham. & RIMS, Kyoto U.)
1. redex searching “within” graph-context (5/6)
Case study: linear λ-calculus + “linear” recursion
39
right-to-left call-by-value
Muroya (U. B’ham. & RIMS, Kyoto U.)
1. redex searching “within” graph-context (6/6)
Case study: linear λ-calculus + “linear” recursion
40
a redex found
Muroya (U. B’ham. & RIMS, Kyoto U.)
1. redex searching within graph-context (6 cases)
observation: only one node is inspected at each step
Case study: linear λ-calculus + “linear” recursion
Muroya (U. B’ham. & RIMS, Kyoto U.)
2. rewriting “in” graph-context (1/3)
Case study: linear λ-calculus + “linear” recursion
42
call-by-value beta-reduction
Muroya (U. B’ham. & RIMS, Kyoto U.)
2. rewriting “in” graph-context (2/3)
Case study: linear λ-calculus + “linear” recursion
43
call-by-value beta-reduction
Muroya (U. B’ham. & RIMS, Kyoto U.)
2. rewriting “in” graph-context
observation: the hole is not involved
Case study: linear λ-calculus + “linear” recursion
44
Muroya (U. B’ham. & RIMS, Kyoto U.)
2. rewriting “in” graph-context (3/3)
Case study: linear λ-calculus + “linear” recursion
45
reduction for recursion
Muroya (U. B’ham. & RIMS, Kyoto U.)
2. rewriting “in” graph-context (3/3)
Case study: linear λ-calculus + “linear” recursion
46
reduction for recursion
`G` contains:
● all reachable nodes
from `μ`
● hence,
○ none of the hole
○ or, all of the hole
Muroya (U. B’ham. & RIMS, Kyoto U.)
2. rewriting “in” graph-context (3/3)
Case study: linear λ-calculus + “linear” recursion
47
reduction for recursion
the hole is
● not involved
● or, duplicated as a
part of `G`
Muroya (U. B’ham. & RIMS, Kyoto U.)
2. rewriting “in” graph-context
observation: the hole is not involved, or is duplicated as a
whole
observation 2: each rewriting step is “history-free”
Case study: linear λ-calculus + “linear” recursion
48
Muroya (U. B’ham. & RIMS, Kyoto U.)
3. visiting the hole (1/1)
Case study: linear λ-calculus + “linear” recursion
49
Muroya (U. B’ham. & RIMS, Kyoto U.)
3. visiting the hole (1/1)
Case study: linear λ-calculus + “linear” recursion
50
1
right-to-left call-by-value
Muroya (U. B’ham. & RIMS, Kyoto U.)
3. visiting the hole (1/1)
Case study: linear λ-calculus + “linear” recursion
51
2
searching stopped
at a value
Muroya (U. B’ham. & RIMS, Kyoto U.)
3. visiting the hole (1/1)
Case study: linear λ-calculus + “linear” recursion
52
3
right-to-left call-by-value
Muroya (U. B’ham. & RIMS, Kyoto U.)
3. visiting the hole (1/1)
Case study: linear λ-calculus + “linear” recursion
53
4
searching stopped
at a value
Muroya (U. B’ham. & RIMS, Kyoto U.)
3. visiting the hole (1/1)
Case study: linear λ-calculus + “linear” recursion
54
5a redex found
Muroya (U. B’ham. & RIMS, Kyoto U.)
3. visiting the hole (1/1)
Case study: linear λ-calculus + “linear” recursion
55
6beta-reduction
Muroya (U. B’ham. & RIMS, Kyoto U.)
3. visiting the hole (1/1)
Case study: linear λ-calculus + “linear” recursion
56
6 0
Muroya (U. B’ham. & RIMS, Kyoto U.)
3. visiting the hole (1 case)
observation: the hole is reduced
Case study: linear λ-calculus + “linear” recursion
57
Muroya (U. B’ham. & RIMS, Kyoto U.)
Case study: linear λ-calculus + “linear” recursion
Given operational semantics:
define the contextual equivalence by:
prove the beta-law by step-wise reasoning:
and observe some sufficient condition.
58
closed term
same basic constants
Muroya (U. B’ham. & RIMS, Kyoto U.)
Case study: linear λ-calculus + “linear” recursion
… prove the beta-law by step-wise reasoning,
and observe that:
1. redex searching only inspects one node at each step2. rewriting preserves, duplicates or simply reduces a
beta-redex.3. rewriting is “history-free”.
59
Muroya (U. B’ham. & RIMS, Kyoto U.)
Case studies so far
… prove the beta-law by step-wise reasoning,
and observe that:
1. redex searching only inspects one node at each step2. rewriting preserves, duplicates or simply reduces a
beta-redex.3. rewriting is “history-free”.
60
✓ untyped pure λ-calculus
✓ basic operations, recursion, if-statement
✓ control operators: call/cc, shift/reset
● algebraic effects & handlersmethod needs to be slightly
adjusted
Muroya (U. B’ham. & RIMS, Kyoto U.)
Question
Given an extension of untyped λ-calculus,
what operational-semantic property of the extension
validates the call-by-value beta-law?
61
Answer?
A formal answer is yet to be stated…
But a graph-rewriting perspective provides:
● a useful & robust method
● key observations