overlapping rules and logic variables in functional logic
play

Overlapping Rules and Logic Variables in Functional Logic Programs - PowerPoint PPT Presentation

ICLP 2006 Overlapping Rules and Logic Variables in Functional Logic Programs Michael Hanus Christian-Albrechts-Universit at Kiel (joint work with Sergio Antoy, Portland State University) F UNCTIONAL L OGIC L ANGUAGES Approach to amalgamate


  1. ICLP 2006 Overlapping Rules and Logic Variables in Functional Logic Programs Michael Hanus Christian-Albrechts-Universit¨ at Kiel (joint work with Sergio Antoy, Portland State University)

  2. F UNCTIONAL L OGIC L ANGUAGES Approach to amalgamate ideas of declarative programming • efficient execution principles of functional languages (determinism, laziness) • flexibility of logic languages (constraints, built-in search) • avoid non-declarative features of Prolog (arithmetic, I/O, cut) • combine best of both worlds in a single model (higher-order functions, declarative I/O, concurrent constraints) • Advantages: ➜ optimal evaluation strategies [JACM’00,ALP’97] ➜ new design patterns [FLOPS’02] ➜ better abstractions for application programming (GUI programming [PADL ’00], web programming [PADL ’01, PPDP’06]) CAU Kiel Michael Hanus 2

  3. F UNCTIONAL L OGIC L ANGUAGES Approach to amalgamate ideas of declarative programming • efficient execution principles of functional languages (determinism, laziness) • flexibility of logic languages (constraints, built-in search) • avoid non-declarative features of Prolog (arithmetic, I/O, cut) • combine best of both worlds in a single model (higher-order functions, declarative I/O, concurrent constraints) • Advantages: ➜ optimal evaluation strategies [JACM’00,ALP’97] ➜ new design patterns [FLOPS’02] ➜ better abstractions for application programming (GUI programming [PADL ’00], web programming [PADL ’01, PPDP’06]) Minimal kernel language for FLP? CAU Kiel Michael Hanus 2

  4. F UNCTIONAL L ANGUAGES ( E . G ., H ASKELL ) CAU Kiel Michael Hanus 3

  5. F UNCTIONAL L ANGUAGES ( E . G ., H ASKELL ) ✓ ✏ [] ++ ys = ys (x:xs) ++ ys = x : xs ++ ys ✒ ✑ CAU Kiel Michael Hanus 3

  6. F UNCTIONAL L ANGUAGES ( E . G ., H ASKELL ) + logic variables (expressive power) ✓ ✏ [] ++ ys = ys (x:xs) ++ ys = x : xs ++ ys ✒ ✑ last xs | ys ++ [x] =:= xs = x where x,ys free CAU Kiel Michael Hanus 3

  7. F UNCTIONAL L ANGUAGES ( E . G ., H ASKELL ) + logic variables (expressive power) ✓ ✏ [] ++ ys = ys (x:xs) ++ ys = x : xs ++ ys ✒ ✑ last xs | ys ++ [x] =:= xs = x where x,ys free ★ + overlapping rules (demand-driven search) ✥ insert e [] = [e] insert e (x:xs) = e : x : xs -- overlapping insert e (x:xs) = x : insert e xs -- rules ✧ ✦ CAU Kiel Michael Hanus 3

  8. F UNCTIONAL L ANGUAGES ( E . G ., H ASKELL ) + logic variables (expressive power) ✓ ✏ [] ++ ys = ys (x:xs) ++ ys = x : xs ++ ys ✒ ✑ last xs | ys ++ [x] =:= xs = x where x,ys free + overlapping rules (demand-driven search) ★ ✥ insert e [] = [e] insert e (x:xs) = e : x : xs -- overlapping insert e (x:xs) = x : insert e xs -- rules perm [] = [] ✧ ✦ perm (x:xs) = insert x (perm xs) perm [1,2,3] [1,2,3] | [1,3,2] | [2,1,3] | ... ❀ = functional logic languages Main result of this paper: only one of these extensions is sufficient! CAU Kiel Michael Hanus 3

  9. T ERM R EWRITING S YSTEMS (TRS) Formal model for functional logic languages: CAU Kiel Michael Hanus 4

  10. T ERM R EWRITING S YSTEMS (TRS) Formal model for functional logic languages: Datatypes ( ≈ admissible values): enumerate all data constructors ✓ ✏ data Bool = True | False data Nat = O | S Nat ✒ ✑ data List = [] | Nat : List CAU Kiel Michael Hanus 4

  11. T ERM R EWRITING S YSTEMS (TRS) Formal model for functional logic languages: Datatypes ( ≈ admissible values): enumerate all data constructors ✓ ✏ data Bool = True | False data Nat = O | S Nat ✒ ✑ data List = [] | Nat : List Rewrite rules : define operations on values f ( t 1 , . . . , t n ) → r patterns defined expression operation (linear data terms) ☛ ✟ → y → False add(O,y) positive(O) ✡ ✠ add(S(x),y) → S(add(x,y)) positive(S(x)) → True Extra variable: rule variable not occurring in left-hand side CAU Kiel Michael Hanus 4

  12. C LASSES OF T ERM R EWRITING S YSTEMS CAU Kiel Michael Hanus 5

  13. C LASSES OF T ERM R EWRITING S YSTEMS Inductively sequential term rewriting systems: ➜ no overlapping left-hand sides in rules ✓ ✏ ➜ operations inductively defi ned on datatypes → True cond(True,x) → x leq(O,x) → False leq(S(x),O) ✒ ✑ leq(S(x),S(y)) → leq(x,y) seven → S(S(S(S(S(S(S(O))))))) CAU Kiel Michael Hanus 5

  14. C LASSES OF T ERM R EWRITING S YSTEMS Inductively sequential term rewriting systems: ➜ no overlapping left-hand sides in rules ✓ ✏ ➜ operations inductively defi ned on datatypes → True cond(True,x) → x leq(O,x) → False leq(S(x),O) ✒ ✑ leq(S(x),S(y)) → leq(x,y) seven → S(S(S(S(S(S(S(O))))))) ✞ ☎ ISX : inductively sequential TRS with extra variables ✝ ✆ smallnum → cond(leq(x,seven),x) CAU Kiel Michael Hanus 5

  15. C LASSES OF T ERM R EWRITING S YSTEMS Inductively sequential term rewriting systems: ➜ no overlapping left-hand sides in rules ✓ ✏ ➜ operations inductively defi ned on datatypes → True cond(True,x) → x leq(O,x) → False leq(S(x),O) ✒ ✑ leq(S(x),S(y)) → leq(x,y) seven → S(S(S(S(S(S(S(O))))))) ✞ ☎ ISX : inductively sequential TRS with extra variables ✝ ✆ smallnum → cond(leq(x,seven),x) OIS : overlapping inductively sequential TRS: ✞ ☎ allow rules with multiple right-hand sides: l → r 1 ? · · · ? r k ✝ ✆ parent(x) → mother(x) ? father(x) CAU Kiel Michael Hanus 5

  16. C LASSES OF T ERM R EWRITING S YSTEMS Inductively sequential term rewriting systems: ➜ no overlapping left-hand sides in rules ✓ ✏ ➜ operations inductively defi ned on datatypes → True cond(True,x) → x leq(O,x) → False leq(S(x),O) ✒ ✑ leq(S(x),S(y)) → leq(x,y) seven → S(S(S(S(S(S(S(O))))))) ✞ ☎ ISX : inductively sequential TRS with extra variables ✝ ✆ smallnum → cond(leq(x,seven),x) OIS : overlapping inductively sequential TRS: ✞ ☎ allow rules with multiple right-hand sides: l → r 1 ? · · · ? r k ✝ ✆ parent(x) → mother(x) ? father(x) Main result: OIS with rewriting ⇐ ⇒ ISX with narrowing CAU Kiel Michael Hanus 5

  17. E VALUATION : R EWRITING VS . N ARROWING Functional evaluation: (lazy) rewriting → → add(S(O),S(O)) S(add(O,S(O))) S(S(O)) CAU Kiel Michael Hanus 6

  18. E VALUATION : R EWRITING VS . N ARROWING Functional evaluation: (lazy) rewriting → → add(S(O),S(O)) S(add(O,S(O))) S(S(O)) Functional logic evaluation: narrowing: guess values + rewriting { x �→ S(S(O)) } add(x,S(O)) =:= S(S(S(O))) ❀ CAU Kiel Michael Hanus 6

  19. E VALUATION : R EWRITING VS . N ARROWING Functional evaluation: (lazy) rewriting → → add(S(O),S(O)) S(add(O,S(O))) S(S(O)) Functional logic evaluation: narrowing: guess values + rewriting { x �→ S(S(O)) } add(x,S(O)) =:= S(S(S(O))) ❀ Needed narrowing: demand-driven variable instantiation and rewriting leq(x,add(O,S(O))) True ❀ { x �→ O } Sound, complete, optimal evaluation strategy [JACM’00] CAU Kiel Michael Hanus 6

  20. E LIMINATING O VERLAPPING R ULES Transformation OE : OIS − → ISX: Replace overlapping rule f ( t n ) → r 1 ? · · · ? r k by: (where V ar ( t n ) = { x 1 , . . . , x l } , y fresh, f ′ new) f ( t n ) → f ′ ( y, x l ) f ′ ( I 1 , x l ) → r 1 . . . f ′ ( I k , x l ) → r k data Ix = I 1 | · · · | I k (index type, e.g., natural numbers) CAU Kiel Michael Hanus 7

  21. E LIMINATING O VERLAPPING R ULES Transformation OE : OIS − → ISX: Replace overlapping rule f ( t n ) → r 1 ? · · · ? r k by: (where V ar ( t n ) = { x 1 , . . . , x l } , y fresh, f ′ new) f ( t n ) → f ′ ( y, x l ) f ′ ( I 1 , x l ) → r 1 . . . f ′ ( I k , x l ) → r k data Ix = I 1 | · · · | I k (index type, e.g., natural numbers) Example: parent(x) → mother(x) ? father(x) OE �→ data Iparent = I0 | I1 parent(x) → parent’(y,x) parent’(IO,x) → mother(x) parent’(I1,x) → father(x) CAU Kiel Michael Hanus 7

  22. E LIMINATING O VERLAPPING R ULES : R ESULTS Proposition: R ∈ OIS ⇒ OE ( R ) ∈ ISX CAU Kiel Michael Hanus 8

  23. E LIMINATING O VERLAPPING R ULES : R ESULTS Proposition: R ∈ OIS ⇒ OE ( R ) ∈ ISX Correctness w.r.t. results computed by needed narrowing: Theorem: R ∈ OIS , R ′ = OE ( R ) , t, s terms of R : ❀ σ ′ s w.r.t. R ′ ⇒ ∃ t NN * NN * ❀ σ s w.r.t. R with σ = V ar ( t ) σ ′ Soundness: t ❀ σ ′ s w.r.t. R ′ with σ = V ar ( t ) σ ′ NN * NN * Completeness: t ❀ σ s w.r.t. R ⇒ ∃ t CAU Kiel Michael Hanus 8

  24. E LIMINATING O VERLAPPING R ULES : R ESULTS Proposition: R ∈ OIS ⇒ OE ( R ) ∈ ISX Correctness w.r.t. results computed by needed narrowing: Theorem: R ∈ OIS , R ′ = OE ( R ) , t, s terms of R : ❀ σ ′ s w.r.t. R ′ ⇒ ∃ t NN * NN * ❀ σ s w.r.t. R with σ = V ar ( t ) σ ′ Soundness: t ❀ σ ′ s w.r.t. R ′ with σ = V ar ( t ) σ ′ NN * NN * Completeness: t ❀ σ s w.r.t. R ⇒ ∃ t ⇒ Implementations need not implement overlapping rules (done in several implementations but without formal justification) CAU Kiel Michael Hanus 8

  25. E LIMINATING L OGIC V ARIABLES → OIS − Transformation XE : ISX − (extra variable elimination) OIS − : overlapping inductively sequential without extra variables Evaluation in OIS − : rewriting (not narrowing) Thus: programs transformed by XE ❀ implementation without handling of logic variables and substitutions CAU Kiel Michael Hanus 9

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend