rewriting techniques for
play

Rewriting Techniques for syntax Correctness of Program - PowerPoint PPT Presentation

LR Nondeterminism Overview The calculus LR with true call-by-need evaluation Rewriting Techniques for syntax Correctness of Program Transformations normal order reduction contextual semantics David Sabel and Manfred Schmidt-Schau


  1. LR Nondeterminism Overview The calculus LR with true call-by-need evaluation Rewriting Techniques for syntax Correctness of Program Transformations normal order reduction contextual semantics David Sabel and Manfred Schmidt-Schauß correctness of program transformations ISR 2015 context lemma August 2015 diagram based technique Nondeterminism: the calculus LR choice may-, should- and must-convergence contextual equivalence under nondeterminism Last update: 14. August 2015 1 D. Sabel & M. Schmidt-Schauß · ISR 2015 · Rewriting Techniques for Correctness of Program Transformations 2/57 Nondeterminism Syntax NO-Reduction Contextual Equivalence Diagrams Nondeterminism Syntax NO-Reduction Contextual Equivalence Diagrams LR LR The Calculus LR true call-by-need evaluation with sharing A call-by-need lambda calculus with letrec -expressions letrec no supercombinators (can be expressed by letrec s) very close to real implementations of lazy functional programming languages like Haskell D. Sabel & M. Schmidt-Schauß · ISR 2015 · Rewriting Techniques for Correctness of Program Transformations 3/57 D. Sabel & M. Schmidt-Schauß · ISR 2015 · Rewriting Techniques for Correctness of Program Transformations 4/57

  2. LR Nondeterminism Syntax NO-Reduction Contextual Equivalence Diagrams LR Nondeterminism Syntax NO-Reduction Contextual Equivalence Diagrams Letrec-Expressions Example A letrec -expression is of the form letrec x 1 = e 1 , . . . , x n = e n in e x 1 , . . . , x n pairwise distinct variables x i = e i is a letrec -binding letrec map = λf, xs. case List xs of x 1 = e 1 , . . . , x n = e n is a letrec -environment { Nil → Nil ; the bindings are recursive, i.e. the scope of x i is e, e 1 , . . . , e n ( Cons y ys ) → Cons ( f y ) ( map f ys ) } in map e is the in -expression Abbreviations: environment: { x i = e i } n i =1 meta symbol for environments Env variable-chains: x j = x j − 1 , x j +1 = x j , . . . , x m = x m − 1 are abbreviated with { x i = x i − 1 } m i = j . D. Sabel & M. Schmidt-Schauß · ISR 2015 · Rewriting Techniques for Correctness of Program Transformations 5/57 D. Sabel & M. Schmidt-Schauß · ISR 2015 · Rewriting Techniques for Correctness of Program Transformations 6/57 Nondeterminism Syntax NO-Reduction Contextual Equivalence Diagrams Nondeterminism Syntax NO-Reduction Contextual Equivalence Diagrams LR LR The Calculus LR : Syntax Contexts & Values e, e i ∈ E LR ::= (variable) x Contexts: C ∈ C LR : expression with a hole [ · ] | λx.e (abstraction) | ( e 1 e 2 ) (application) Surface contexts S : the hole is not in an abstraction: | ( c T,i e 1 . . . e ar( c T,i ) ) (constructor application) S ∈ S LR ::= [ · ] | ( S e ) | ( e S ) | ( c T,i e 1 . . . e i − 1 S e i +1 . . . e ar( c T,i ) ) | case T e of { pat T, 1 → e 1 ; . . . ; pat T, | T | → e | T | } (case-expression) | ( seq S e ) | ( seq e S ) | ( case T S of alts ) | seq e 1 e 2 (seq-expression) | ( case T e of { . . . ; ( c T,i x 1 . . . x ar( c T,i ) ) → S ; . . . } ) | letrec x 1 = e 1 , . . . , x n = e n in e (letrec-expression) | ( letrec x 1 = e 1 , . . . , x n = e n in S ) pat T,i ::= ( c T,i x i, 1 . . . x i, ar( c T,i ) ) (pattern) | ( letrec x 1 = e 1 , x i = S, . . . , x n = e n in e ) LR -value : abstraction λx.e or a constructor application ( c e 1 . . . e ar( c ) ) Free- and bound variables (new cases): � n � � FV ( letrec x 1 = e 1 , . . . , x n = e n in e ) = FV ( e ) ∪ FV ( e i ) \ { x 1 , . . . , x n } i =1 � n � BV ( letrec x 1 = e 1 , . . . , x n = e n in e ) = BV ( e ) ∪ � BV ( e i ) ∪ { x 1 , . . . , x n } i =1 D. Sabel & M. Schmidt-Schauß · ISR 2015 · Rewriting Techniques for Correctness of Program Transformations 7/57 D. Sabel & M. Schmidt-Schauß · ISR 2015 · Rewriting Techniques for Correctness of Program Transformations 8/57

  3. LR Nondeterminism Syntax NO-Reduction Contextual Equivalence Diagrams LR Nondeterminism Syntax NO-Reduction Contextual Equivalence Diagrams Reduction Rules Reduction Rules (2) Instead of ( case ) -reduction, there are several sharing variants: Instead of ( β ) -reduction, there are (lbeta) and (cp): For arity n = ar( c T,i ) ≥ 1 : ( y i are fresh variables) (lbeta) C [(( λx.e 1 ) e 2 )] → C [( letrec x = e 2 in e 1 )] (case-c) C [ case T ( c T,i − → e ) of { . . . ; ( c T,i − → z ) → e ′ ; . . . } ] (cp-in) letrec x 1 = ( λx.e ) , { x i = x i − 1 } m i =2 , Env in C [ x m ] i =1 in e ′ )] → C [( letrec { z i = e i } n → letrec x 1 = ( λx.e ) , { x i = x i − 1 } m i =2 , Env in C [( λx.e )] (case-in) letrec x 1 = ( c T,i − → e ) , { x i = x i − 1 } m i =2 , Env (cp-e) letrec x 1 = ( λx.e 1 ) , { x i = x i − 1 } m i =2 , Env , y = C [ x m ] in e 2 in C [ case T x m of { . . . ; ( c T,i − → z ) → e ′ ; . . . } ] → letrec x 1 = ( λx.e 1 ) , { x i = x i − 1 } m i =2 , Env , y = C [( λx.e 1 )] in e 2 → letrec x 1 = ( c T,i − → y ) , { y i = e i } n i =1 , { x i = x i − 1 } m i =2 , Env (lbeta) shares the argument by a letrec i =1 in e ′ )] in C [( letrec { z i = y i } n no substitution of arbitrary expressions (case-e) letrec x 1 = ( c T,i − → e ) , { x i = x i − 1 } m i =2 , u = C [ case T x m of { . . . ; ( c T,i − → (cp) only copies abstractions z ) → e ′ ; . . . } ] , Env in e ′′ → letrec x 1 = ( c T,i − → variable-chains are followed (not removed etc.) y ) , { y i = e i } n i =1 , { x i = x i − 1 } m i =2 , i =1 in e ′ ] , Env in e ′′ u = C [ letrec { z i = y i } n D. Sabel & M. Schmidt-Schauß · ISR 2015 · Rewriting Techniques for Correctness of Program Transformations 9/57 D. Sabel & M. Schmidt-Schauß · ISR 2015 · Rewriting Techniques for Correctness of Program Transformations 10/57 Nondeterminism Syntax NO-Reduction Contextual Equivalence Diagrams Nondeterminism Syntax NO-Reduction Contextual Equivalence Diagrams LR LR Reduction Rules (3) Reduction Rules (4) Instead of ( case ) -reduction, there are several sharing variants: Instead of ( seq ) -reduction, three rules: For arity ar( c T,i ) = 0 : (case-c) C [ case T c T,i of { . . . ; c T,i → e ; . . . } ] → C [ e ] (seq-c) C [( seq v e )] → C [ e ] if v is a value (case-in) letrec x 1 = c T,i , { x i = x i − 1 } m i =2 , Env (seq-in) ( letrec x 1 = ( c − → i =2 , Env in C [( seq x m e ′ )]) e ) , { x i = x i − 1 } m in C [ case T x m of { . . . ; ( c i → e ); . . . } ] → ( letrec x 1 = ( c − → e ) , { x i = x i − 1 } m i =2 , Env in C [ e ′ ]) → letrec x 1 = c T,i , { x i = x i − 1 } m i =2 , Env in C [ e ] (seq-e) ( letrec x 1 = ( c − → e ) , { x i = x i − 1 } m i =2 , Env , y = C [( seq x m e ′ )] in e ′′ ) (case-e) letrec x 1 = c T,i , { x i = x i − 1 } m i =2 , → ( letrec x 1 = ( c − → i =2 , Env , y = C [ e ′ ] in e ′′ ) e ) , { x i = x i − 1 } m u = C [ case T x m of { . . . ; ( c T,i → e ′ ); . . . } ] , Env in e ′′ → letrec x 1 = c T,i , { x i = x i − 1 } m i =2 , . . . , u = C [ e ′ ] , Env in e ′′ Notation: (seq) is the union of (seq-c), (seq-in), (seq-e) Notation: (case) is the union of (case-c), (case-in), (case-e) D. Sabel & M. Schmidt-Schauß · ISR 2015 · Rewriting Techniques for Correctness of Program Transformations 11/57 D. Sabel & M. Schmidt-Schauß · ISR 2015 · Rewriting Techniques for Correctness of Program Transformations 12/57

Recommend


More recommend