a graph based definition of distillation
play

A Graph-Based Definition of Distillation Geoff Hamilton Gavin - PowerPoint PPT Presentation

A Graph-Based Definition of Distillation Geoff Hamilton Gavin Mendel-Gleason {hamilton,ggleason}@computing.dcu.ie Lero@DCU School of Computing Dublin City University Dublin, Ireland META 2010 Geoff Hamilton, Gavin Mendel-Gleason A


  1. A Graph-Based Definition of Distillation Geoff Hamilton Gavin Mendel-Gleason {hamilton,ggleason}@computing.dcu.ie Lero@DCU School of Computing Dublin City University Dublin, Ireland META 2010 Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  2. Background This work is inspired by the supercompilation transformation algorithm developed by Turchin. Although originally developed in the 1960s/70s, supercompilation did not become more widely known outside Russia until much later: Published only in less accessible journals. Defined on the unconventional language Refal. Supercompilation became more widely known through the positive supercompilation algorithm (Sørensen, Glück and Jones): Simplified algorithm. Defined on a more familiar functional language. Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  3. Motivation Only linear improvements in performance are possible using the positive supercompilation algorithm. Transformations such as the following are therefore not possible: nrev xs where nrev = λ xs . case xs of [] ⇒ [] | x ′ : xs ′ ⇒ app ( nrev xs ′ ) ( x ′ : []) app = λ xs .λ ys . case xs of [] ⇒ ys | x ′ : xs ′ ⇒ x ′ : ( app xs ′ ys ) ⇓ arev xs where λ xs . arev ′ xs [] arev = arev ′ = λ xs .λ ys . case xs of [] ⇒ ys | x ′ : xs ′ ⇒ arev ′ xs ′ ( x ′ : ys ) Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  4. Language Syntax We use the following higher-order functional language: prog ::= e 0 where f 1 = e 1 . . . f k = e k Program e ::= v Variable | c e 1 . . . e k Constructor | f Function Call | λ v . e λ -Abstraction | e 0 e 1 Application | case e 0 of p 1 ⇒ e 1 | · · · | p k ⇒ e k Case Expression p ::= c v 1 . . . v k Pattern The operational semantics of this language is normal-order reduction. Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  5. Positive Supercompilation Central concept is that of driving, which constructs a potentially infinite process tree, representing all possible computations of the program by normal order reduction. Generalization is required to ensure the termination of driving. Folding can be performed on encountering an instance of a previously encountered term, thus producing a finite partial process tree. A (hopefully) more efficient recursive program can be extracted from the resulting partial process tree. Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  6. Process Trees e → t 1 , . . . , t n is the process tree with root labelled e and n children which are the subtrees t 1 , . . . , t n respectively. root ( t ) denotes the root node of process tree t . t ( α ) denotes the label of node α within process tree t . anc ( t , α ) denotes the set of ancestors of node α within t . t { α := t ′ } denotes the tree obtained by replacing the subtree with root α in t by the tree t ′ . Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  7. Expression Instance An expression e ′ is an instance of expression e , denoted by e ⋖ e e ′ , if there is a substitution θ such that e θ ≡ e ′ . When an instance is encountered, a repeat node is constructed. e ��� α denotes a repeat node where the expression e is an instance of the label of node α . Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  8. Expression Embedding The homeomorphic embedding relation � e is a well-quasi order which provides a so-called whistle to stop driving due to potential divergence, and to indicate that generalization should be performed. e � e ( e ′ [ v / v ′ ]) e 1 ⊳ e e 2 e 1 ⊲ ⊳ e e 2 ⊳ e λ v ′ . e ′ e 1 � e e 2 e 1 � e e 2 λ v . e ⊲ ∀ i ∈ { 1 . . . n } . e i � e e ′ ∃ i ∈ { 1 . . . n } . e � e e i i ⊳ e φ ( e ′ 1 , . . . , e ′ e ⊳ e φ ( e 1 , . . . , e n ) φ ( e 1 , . . . , e n ) ⊲ n ) e 0 � e e ′ ∀ i ∈ { 1 . . . n } . ∃ θ i . p i ≡ ( p ′ i θ i ) ∧ e i � e ( e ′ i θ i ) 0 ⊳ e ( case e ′ 0 of p ′ 1 : e ′ 1 | . . . | p ′ n : e ′ ( case e 0 of p 1 : e 1 | . . . | p n : e n ) ⊲ n ) e 1 � e e 2 iff ∃ θ. e 1 θ ⊲ ⊳ e e 2 Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  9. Expression Generalization A generalization of expressions e and e ′ is a triple ( e g , θ, θ ′ ) where e g θ ≡ e and e g θ ′ ≡ e ′ . ( φ ( e g 1 , . . . , e g n ) , � n i = 1 θ i , � n i = 1 θ ′ if e � e e ′  i ) ,   where e = φ ( e 1 , . . . , e n )   e ⊓ e e ′ =  e ′ = φ ( e ′ 1 , . . . , e ′ n ) ( e g i , θ i , θ ′ i ) = e i ⊓ e e ′   i   ( v , [ e / v ] , [ e ′ / v ]) , otherwise  Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  10. Expression Generalization When we encounter an expression e ′ which is a coupling of a previously encountered expression e , we perform generalization. To represent the result of generalization, we introduce a let construct of the form let v 1 = e 1 , . . . , v n = e n in e 0 into our language. The expression e is replaced by its generalized form, which is constructed using the abstract e operation: abstract e ( e , e ′ ) = let v 1 = e 1 , . . . , v n = e n in e g where e ⊓ e e ′ = ( e g , { v 1 := e 1 , . . . , v n := e n } , θ ) Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  11. Positive Supercompilation: Algorithm If the partially constructed process tree t contains a node β in which the redex is a function, the node is processed as follows: if ∃ α ∈ anc ( t , β ) . t ( α ) ⋖ e t ( β ) then t { β := t ( β ) ��� α } else if ∃ α ∈ anc ( t , β ) . t ( α ) � e t ( β ) then t { α := S [ [ abstract e ( t ( α ) , t ( β ))] ] } else t { β := t ( β ) → S [ [ unfold ( t ( β ))] ] } Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  12. Positive Supercompilation: Example nrev xs Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  13. Positive Supercompilation: Example nrev xs case xs of . . . Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  14. Positive Supercompilation: Example nrev xs case xs of . . . xs = [] [] Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  15. Positive Supercompilation: Example nrev xs case xs of . . . xs = x ′ : xs ′ xs = [] app ( nrev xs ′ ) ( x ′ : []) [] Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  16. Positive Supercompilation: Example nrev xs case xs of . . . xs = x ′ : xs ′ xs = [] app ( nrev xs ′ ) ( x ′ : []) [] case ( nrev xs ′ ) of . . . Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  17. Positive Supercompilation: Example nrev xs case xs of . . . xs = x ′ : xs ′ xs = [] app ( nrev xs ′ ) ( x ′ : []) [] case ( nrev xs ′ ) of . . . case ( case xs ′ of . . . ) of . . . Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  18. Positive Supercompilation: Example nrev xs case xs of . . . xs = x ′ : xs ′ xs = [] app ( nrev xs ′ ) ( x ′ : []) [] case ( nrev xs ′ ) of . . . case ( case xs ′ of . . . ) of . . . xs ′ = [] x ′ : [] Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  19. Positive Supercompilation: Example nrev xs case xs of . . . xs = x ′ : xs ′ xs = [] app ( nrev xs ′ ) ( x ′ : []) [] case ( nrev xs ′ ) of . . . case ( case xs ′ of . . . ) of . . . xs ′ = x ′′ : xs ′′ xs ′ = [] x ′ : [] case ( app ( nrev xs ′′ ) ( x ′′ : [])) of . . . Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  20. Positive Supercompilation: Example nrev xs case xs of . . . xs = x ′ : xs ′ xs = [] app ( nrev xs ′ ) ( x ′ : []) [] case ( nrev xs ′ ) of . . . case ( case xs ′ of . . . ) of . . . xs ′ = x ′′ : xs ′′ xs ′ = [] x ′ : [] case ( app ( nrev xs ′′ ) ( x ′′ : [])) of . . . case ( case ( nrev xs ′′ ) of . . . ) of . . . Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  21. Positive Supercompilation: Example nrev xs case xs of . . . xs = x ′ : xs ′ xs = [] app ( nrev xs ′ ) ( x ′ : []) [] let vs = nrev xs ′ in case vs of . . . Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  22. Positive Supercompilation: Example nrev xs case xs of . . . xs = x ′ : xs ′ xs = [] app ( nrev xs ′ ) ( x ′ : []) [] let vs = nrev xs ′ in case vs of . . . nrev xs ′ Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  23. Positive Supercompilation: Example nrev xs case xs of . . . xs = x ′ : xs ′ xs = [] app ( nrev xs ′ ) ( x ′ : []) [] let vs = nrev xs ′ in case vs of . . . nrev xs ′ case vs of . . . Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

  24. Positive Supercompilation: Example nrev xs case xs of . . . xs = x ′ : xs ′ xs = [] app ( nrev xs ′ ) ( x ′ : []) [] let vs = nrev xs ′ in case vs of . . . nrev xs ′ case vs of . . . vs = [] x ′ : [] Geoff Hamilton, Gavin Mendel-Gleason A Graph-Based Definition of Distillation

Recommend


More recommend