The Problem
What else?
The Hierarchy
Compositionality
Simulation
A Hierarchy of Semantics for Non-deterministic Term Rewriting Systems Juan Rodr´ıguez Hortal´a
Declarative Programming Group Dept. Sistemas Inform´ aticos y Computaci´ on Universidad Complutense de Madrid
FSTTCS 2008 Bangalore, December 2008
The End
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The End
The Ingredients Functional programming + Laziness + Non-determinism Programs heads(x : y : xs) → (x, y) repeat(x) → x : repeat(x) coin → 0 coin → 1
Expressions & Values heads(0 : 1 : repeat(2)) _ (0, 1) coin _ 0 coin _ 1
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The End
The Ingredients Functional programming + Laziness + Non-determinism Expressions & Values
Programs heads(x : y : xs) → (x, y) repeat(x) → x : repeat(x) coin → 0 coin → 1
heads(0 : 1 : repeat(2)) _ (0, 1) coin _ 0 coin _ 1
Functional Logic Programming (FLP) - Toy, Curry (Constructor-based) Term Rewriting Systems (TRS) - Maude
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The Decision
Laziness +
Non-determinism
=⇒
Semantic alternatives
The End
The Problem
What else?
The Hierarchy
The Decision (ii) :
Compositionality
Simulation
The End
Laziness + Non-determinism =⇒ Semantic alternatives
“Operational” perspective When is it time to fix a (partial) value for each argument? heads(x : y : xs) → (x, y), repeat(x) → x : repeat(x), coin → 0, coin → 1
The Problem
What else?
The Hierarchy
The Decision (ii) :
Compositionality
Simulation
The End
Laziness + Non-determinism =⇒ Semantic alternatives
“Operational” perspective When is it time to fix a (partial) value for each argument? heads(x : y : xs) → (x, y), repeat(x) → x : repeat(x), coin → 0, coin → 1
Call-time choice ⇐= FLP On parameter passing heads(repeat(coin)) → heads(repeat(0)) →∗ heads(0 : 0 :⊥) → (0, 0) 6→∗ (0, 1)
vs.
Run-time choice ⇐= TRS As they are used heads(repeat(coin)) →∗ heads(coin : coin : repeat(coin)) → (coin, coin) →∗ (0, 0) →∗ (0, 1)
Rewriting + Sharing
Rewriting
The Problem
What else?
The Hierarchy
The Decision (iii) :
Compositionality
Simulation
The End
Laziness + Non-determinism =⇒ Semantic alternatives
Denotational perspective Which domain is used to instantiate the program rules? heads(x : y : xs) → (x, y), repeat(x) → x : repeat(x), coin → 0, coin → 1
The Problem
What else?
The Hierarchy
The Decision (iii) :
Compositionality
Simulation
The End
Laziness + Non-determinism =⇒ Semantic alternatives
Denotational perspective Which domain is used to instantiate the program rules? heads(x : y : xs) → (x, y), repeat(x) → x : repeat(x), coin → 0, coin → 1
Singular semantics ⇐= FLP Variables go to values heads(repeat(coin)) → heads(repeat(0)) →∗ heads(0 : 0 :⊥) → (0, 0) 6→∗ (0, 1)
vs.
Plural semantics ⇐=??? TRS Variables go to sets of values heads(repeat(coin)) → heads(repeat({0, 1})) →∗ heads({0 : 1 :⊥, 1 : 0 :⊥, 0 : 0 :⊥, 1 : 1 :⊥, }) → {(0, 0), (0, 1), (1, 0), (1, 1)}
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The Mistake The Folklore
Call-time choice ∼ Singular semantics X
The End
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The Mistake The Folklore
Call-time choice ∼ Singular semantics X Run-time choice ∼ Plural semantics
f (c(x)) → (x, x), x ? y → x, x ? y → y
The End
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The Mistake The Folklore
Call-time choice ∼ Singular semantics X Run-time choice ∼ Plural semantics
f (c(x)) → (x, x), x ? y → x, x ? y → y
The End
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The End
The Mistake The Folklore
Call-time choice ∼ Singular semantics X Run-time choice ∼ Plural semantics
f (c(x)) → (x, x), x ? y → x, x ? y → y Run-time choice Argument values are fixed as they are used f (c(0)?c(1)) → f (c(0)) → (0, 0) → f (c(1)) → (1, 1)
vs.
Plural semantics Variables go to sets of values f (c(0)?c(1)) → f ({c(0), c(1)}) → ({0, 1}, {0, 1}) →∗ (0, 0) →∗ (0, 1) →∗ (1, 0) →∗ (1, 1)
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The End
The Mistake The Folklore
Call-time choice ∼ Singular semantics X Run-time choice ∼ Plural semantics
f (c(x)) → (x, x), x ? y → x, x ? y → y Run-time choice ⇐= TRS Argument values are fixed as they are used f (c(0)?c(1)) → f (c(0)) → (0, 0) → f (c(1)) → (1, 1)
vs.
Plural semantics 6⇐= TRS Variables go to sets of values f (c(0)?c(1)) → f ({c(0), c(1)}) → ({0, 1}, {0, 1}) →∗ (0, 0) →∗ (0, 1) →∗ (1, 0) →∗ (1, 1)
Run-time choice 6= Plural semantics
The Problem
What else?
The Hierarchy
Compositionality
What else?
Just remember Run-time 6= choice
Plural semantics
Simulation
The End
The Problem
What else?
The Hierarchy
Compositionality
What else?
Besides ... inclusion Run-time ( choice
Plural semantics
Simulation
The End
The Problem
What else?
The Hierarchy
Compositionality
Simulation
What else?
Besides ... hierarchy Call-time ( choice
Run-time ( choice
Plural semantics
The End
The Problem
What else?
The Hierarchy
Compositionality
Simulation
What else?
Besides ... compositional? Call-time choice Compositional
(
Run-time choice
(
Plural semantics Compositional
The End
The Problem
What else?
The Hierarchy
Compositionality
Simulation
What else?
Besides ... compositional? Call-time choice
(
Run-time choice
Compositional
(
Plural semantics Compositional
Not Compositional
The End
The Problem
What else?
The Hierarchy
Compositionality
Simulation
What else?
Besides ... implementation Call-time ( choice ⇑ Rewriting + Sharing
Run-time ( choice ⇑ Rewriting
Plural semantics New!!!
The End
The Problem
What else?
The Hierarchy
Compositionality
Simulation
What else?
Besides ... implementation Call-time ( choice ⇑ Rewriting + Sharing
Run-time ( choice ⇑ Rewriting
⇒ simulation
Plural semantics New!!!
The End
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The Formulations
Call-time choice - CRWL (B)
e_⊥
(RR)
x_x
(DC)
e1 _ t1 . . . e n _ tn c(e1 , . . . , en ) _ c(t1 , . . . , tn )
(OR)
e1 _ t1 θ . . . en _ tn θ rθ _ t f (e1 , . . . , en ) _ t
x∈V c ∈ CS n , ti ∈ CTerm ⊥ θ ∈ CSubst⊥
The End
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The Formulations, the interesting rules
Given f (t1 , . . . , tn ) → r) ∈ P: Call-time choice - CRWL (OR)
e1 _ t1 θ . . . en _ tn θ rθ _ t f (e1 , . . . , en ) _ t
θ ∈ CSubst⊥
The End
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The Formulations, the interesting rules
Given f (t1 , . . . , tn ) → r) ∈ P: Call-time choice - CRWL (OR)
e1 _ t1 θ . . . en _ tn θ rθ _ t f (e1 , . . . , en ) _ t
θ ∈ CSubst⊥
Run-time choice - Term Rewriting f (t1 , . . . , tn )σ → rσ
σ ∈ Subst
The End
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The Formulations, the interesting rules Given f (t1 , . . . , tn ) → r) ∈ P: Call-time choice - CRWL (OR)
e1 _ t1 θ . . . en _ tn θ rθ _ t f (e1 , . . . , en ) _ t
θ ∈ CSubst⊥
Run-time choice - Term Rewriting f (t1 , . . . , tn )σ → rσ
σ ∈ Subst
Plural semantics - πCRWL e1 _ t1 θ11 en _ tn θn1 ... ... ... (POR) e1 _ t1 θ1m1 en _ tn θnmn rθ _ t f (e1 , . . . , en ) _ t ?{θ11 , . . . , θ1m1 } ] . . . ] ?{θn1 , . . . , θnmn } = θ ∈ CSubst?⊥
The End
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The End
The Hierarchy Call-time ( choice
Run-time ( choice
Plural semantics
[[e]]S = set of values for e under S ∈ {sg (CRWL), rw, pl (πCRWL)} For any program P, any expression e and any value t [[e]]sg
⊆ ⊆ [[e]]rw [[e]]pl 6 ⊇ 6⊇
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The End
The Hierarchy Call-time ( choice
Run-time ( choice
Plural semantics
[[e]]S = set of values for e under S ∈ {sg (CRWL), rw, pl (πCRWL)} For any program P, any expression e and any value t [[e]]sg
⊆ ⊆ [[e]]rw [[e]]pl 6 ⊇ 6⊇
Example P = {f (c(x)) → (x, x), x ? y → x, x ? y → y} Exp f (c(0?1)) f (c(0?1)) f (c(0)?c(1))
Value (0,0) (0,1) (0,1)
CRWL X
Rw X X
πCRWL X X X
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The End
Compositionality A desirable property . . . Compositionality : Exps with the same values are interchangeable [ [[C[e]]]pl = [[C[t1 ? . . . ? tn ]]]pl {t1 ,...,tn }⊆[[e]]pl
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The End
Compositionality A desirable property . . . Compositionality : Exps with the same values are interchangeable [ [[C[e]]]pl = [[C[t1 ? . . . ? tn ]]]pl {t1 ,...,tn }⊆[[e]]pl
∀S ∈ {sg, rw, pl}, [[c(0?1)]]S = [[c(0)?c(1)]]S
but [[f (c(0?1))]]rt ) [[f (c(0)?c(1))]]rt !!! ... becomes fundamental in a value-based language
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The End
Compositionality A desirable property . . . Compositionality : Exps with the same values are interchangeable [ [[C[e]]]pl = [[C[t1 ? . . . ? tn ]]]pl {t1 ,...,tn }⊆[[e]]pl
∀S ∈ {sg, rw, pl}, [[c(0?1)]]S = [[c(0)?c(1)]]S
but [[f (c(0?1))]]rt ) [[f (c(0)?c(1))]]rt !!! ... becomes fundamental in a value-based language Philosophy : “all I know about an expression is its set of values” ⇒ useful to encode collecting problems (read the paper!!!) CRWL and πCRWL are compositional ⇒ good for value-based langs Term rewriting isn’t ⇒ good for other langs and purposes
The Problem
What else?
The Hierarchy
Compositionality
Simulation
Simulation - Neither run-time can simulate call-time nor vice versa
The End
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The End
Simulation - Neither run-time can simulate call-time nor vice versa - But run-time simulates plural easily: just postpone pattern matching Example f (c(x)) → (x, x) =⇒ f (y) → if match(y) then (project(y), project(y)), match(c(x)) → true, project(c(x)) → x
And now: f (c(0) ? c(1)) → if match(c(0)?c(1)) then d(project(c(0)?c(1)), project(c(0)?c(1))) →∗ (0, 1)
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The End
Simulation - Neither run-time can simulate call-time nor vice versa - But run-time simulates plural easily: just postpone pattern matching Example f (c(x)) → (x, x) =⇒ f (y) → if match(y) then (project(y), project(y)), match(c(x)) → true, project(c(x)) → x
And now: f (c(0) ? c(1)) → if match(c(0)?c(1)) then d(project(c(0)?c(1)), project(c(0)?c(1))) →∗ (0, 1)
A verified simulation rw [[e]]pl P = [[e]]pST (P)
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The Contributions
- Run-time choice 6= Plural semantics - Formulation - πCRWL - [[e]]sg ( [[e]]rw ( [[e]]pl - πCRWL is compositional: hence, with CRWL suitable for a value-based language
- Simulation of πCRWL with term rewriting
The End
The Problem
What else?
The Hierarchy
Compositionality
Simulation
The Future
Advances πCRWL implemented in Maude through the transformation: https://gpd.sip.ucm.es/trac/gpd/wiki/ PluralSemantics/Maude Not optimized but verified and easy to develop For experimenting and looking for programming idioms
TODO - Some kind of sharing is needed to improve efficiency - Combination of singular and plural functions
The End