correctness of program transformations automating diagram
play

Correctness of Program Transformations: Automating Diagram-Based - PowerPoint PPT Presentation

Correctness of Program Transformations: Automating Diagram-Based Proofs David Sabel Goethe-University Frankfurt am Main, Germany Research supported by the Deutsche Forschungsgemeinschaft (DFG) under grant SA 2908/3-1. Motivation reasoning


  1. Correctness of Program Transformations: Automating Diagram-Based Proofs David Sabel † Goethe-University Frankfurt am Main, Germany † Research supported by the Deutsche Forschungsgemeinschaft (DFG) under grant SA 2908/3-1.

  2. Motivation reasoning on program transformations w.r.t. operational semantics for program calculi with higher-order constructs and recursive bindings, e.g. letrec-expressions : letrec x 1 = s 1 ; . . . ; x n = s n in t extended call-by-need lambda calculi with letrec that model core languages of lazy functional programming languages like Haskell 2/43

  3. Motivation A program transformation is a binary relation on program fragments X:=1 T for (X:=1, X < n, X++) { while X < n { Z := Z + X; Z := Z + X; } X++; } 3/43

  4. Motivation A program transformation is a binary relation on program fragments X:=1 T for (X:=1, X < n, X++) { while X < n { Z := Z + X; Z := Z + X; } X++; } Some applications: Compilers: Optimizations (inlining, partial evaluation,. . . ) Code Refactoring: Transformations to improve readability and maintainability Theorem Provers: Transforming programs in proofs 3/43

  5. Correctness Program transformation T is correct iff T ⊆ ∼ c Contextual equivalence: e ∼ c e ′ iff e ≤ c e ′ and e ≥ c e ′ Contextual preorder: e ≤ c e ′ iff ∀ C : C [ e ] ↓ = ⇒ C [ e ′ ] ↓ ↓ means successful evaluation: sr, ∗ → e ′ and e ′ is a successful result e ↓ := e − − sr where − → is the small-step operational semantics (standard reduction) sr, ∗ sr and − − → is the reflexive-transitive closure of − → 4/43

  6. Convergence Preservation Convergence preservation: e ≤ ↓ e ′ iff e ↓ = ⇒ e ′ ↓ We only consider transformations T such that T ⊆ ≤ ↓ = ⇒ T ⊆ ≤ c No restriction, since the contextual closure of T fulfills this property. A context lemma allows for smaller closures (reduction contexts) T ⊆ ≥ c can be proved by showing T − 1 ⊆ ≤ c program Required task: transformation e e ′ standard standard reduction reduction = ⇒ steps steps e ′′ e ′′′ · successful successful 5/43

  7. Idea of the Diagram Method Base case: For all successful e program transformation e e ′ successful 6/43

  8. Idea of the Diagram Method Base case: For all successful e program transformation e e ′ successful standard reduction steps e ′′ successful 6/43

  9. Idea of the Diagram Method Base case: For all successful e program transformation e e ′ successful standard reduction steps e ′′ successful General case: For all programs e program transformation e e ′ standard reduction e ′′ 6/43

  10. Idea of the Diagram Method Base case: For all successful e program transformation e e ′ successful standard reduction steps e ′′ successful General case: For all programs e program transformation e e ′ standard standard reduction reduction steps e ′′ e ′′′ program transformation steps 6/43

  11. Idea of the Diagram Method Base case: For all successful e Inductive construction program transformation e e ′ e e ′ successful standard reduction steps e ′′ successful General case: For all programs e program transformation e e ′ standard standard reduction reduction steps e ′′ e ′′ e ′′′ program successful transformation steps 6/43

  12. Idea of the Diagram Method Base case: For all successful e Inductive construction program transformation e e ′ e e ′ successful standard reduction steps e ′′′ e ′′ successful General case: For all programs e program transformation e e ′ standard standard reduction reduction steps e ′′ e ′′ e ′′′ program successful transformation steps 6/43

  13. Idea of the Diagram Method Base case: For all successful e Inductive construction program transformation e e ′ e e ′ successful standard reduction steps e ′′′ e ′′ successful General case: For all programs e by the program induction transformation hypothesis e e ′ standard standard reduction reduction steps e 4 e ′′ e ′′ e ′′′ program succ. successful transformation steps 6/43

  14. Idea of the Diagram Method Base case: For all successful e Inductive construction program transformation e e ′ e e ′ successful standard reduction steps e ′′′ e ′′ successful . . . General case: For all programs e program transformation e e ′ standard standard reduction reduction steps e 4 e 5 e ′′ e ′′ e ′′′ program succ. successful successful transformation steps 6/43

  15. Focused Languages and Previous Results The diagram technique was, for instance, used for call-by-need lambda calculi with letrec, data constructors, case, and seq [SSSS08, JFP] and non-determinism [SSS08, MSCS] process calculi with call-by-value [NSSSS07, MFPS] or call-by-need evaluation [SSS11, PPDP] and [SSS12, LICS] reasoning on whether program transformations are improvements w.r.t. the run-time [SSS15, PPDP] and [SSS17, SCP] 7/43

  16. Focused Languages and Previous Results The diagram technique was, for instance, used for call-by-need lambda calculi with letrec, data constructors, case, and seq [SSSS08, JFP] and non-determinism [SSS08, MSCS] process calculi with call-by-value [NSSSS07, MFPS] or call-by-need evaluation [SSS11, PPDP] and [SSS12, LICS] reasoning on whether program transformations are improvements w.r.t. the run-time [SSS15, PPDP] and [SSS17, SCP] Conclusions from these works The diagram method works well The method requires to compute overlaps (error-prone, tedious,...) Automation of the method would be valuable 7/43

  17. Automation of the Diagram-Method compute translate overlaps diagrams calculus description overlaps (I)TRS diagrams program prove termination join transformations overlaps (AProVE/CeTA) Diagram Automated Input calculator induction Structure of the LRSX-Tool 8/43

  18. Representation of the Input compute translate overlaps diagrams calculus description overlaps (I)TRS diagrams program prove termination join transformations overlaps (AProVE/CeTA) Diagram Automated Input calculator induction Structure of the LRSX-Tool 9/43

  19. Requirements on the Meta-Syntax The syntax of extended call-by-need lambda-calculi typically includes: lambda-calculus: variables x , abstractions λx.e , applications ( e e ′ ) data-constructors True , False , Nil , Cons e 1 e 2 ,. . . data-selectors / case-expressions let- and recursive let expressions: letrec x 1 = e 1 , . . . , x n = e n in e 10/43

  20. Requirements on the Meta-Syntax The syntax of extended call-by-need lambda-calculi typically includes: lambda-calculus: variables x , abstractions λx.e , applications ( e e ′ ) data-constructors True , False , Nil , Cons e 1 e 2 ,. . . data-selectors / case-expressions let- and recursive let expressions: letrec x 1 = e 1 , . . . , x n = e n in e Language LRS parametric over F Expressions s ∈ Expr ::= var x | letrec env in s | ( f r 1 . . . r ar ( f ) ) where r i is o i , s i , or x i specified by f ∈ F H.O.-Expressions o ∈ HExpr n ::= x 1 . . . . x n .s Environments env ∈ Env ::= ∅ | x = s ; env 10/43

  21. Requirements on the Meta-Syntax Operational semantics of typical call-by-need calculi (excerpt) Reduction contexts: A ::= [ · ] | ( A e ) R ::= A | letrec Env in A | letrec { x i = A i [ x i +1 ] } n − 1 i =1 , x n = A n , Env , in A [ x 1 ] Standard-reduction rules and some program transformations: (SR,lbeta) R [( λx.e 1 ) e 2 ] → R [ letrec x = e 2 in e 1 ] (SR,llet) letrec Env 1 in letrec Env 2 in e → letrec Env 1 , Env 2 in e . . . (T,cpx) T [ letrec x = y, Env in C [ x ]] → T [ letrec x = y, Env in C [ y ]] T [ letrec Env , Env ′ in e ] → T [ letrec Env ′ in e ] , (T,gc,1) if LetV ars ( Env ) ∩ FV ( e, Env ′ ) = ∅ (T,gc,2) T [ letrec Env in e ] → T [ e ] if LetVars ( Env ) ∩ FV ( e ) = ∅ 11/43

  22. Requirements on the Meta-Syntax Operational semantics of typical call-by-need calculi (excerpt) Reduction contexts: A ::= [ · ] | ( A e ) R ::= A | letrec Env in A | letrec { x i = A i [ x i +1 ] } n − 1 i =1 , x n = A n , Env , in A [ x 1 ] Standard-reduction rules and some program transformations: (SR,lbeta) R [( λx.e 1 ) e 2 ] → R [ letrec x = e 2 in e 1 ] (SR,llet) letrec Env 1 in letrec Env 2 in e → letrec Env 1 , Env 2 in e . . . (T,cpx) T [ letrec x = y, Env in C [ x ]] → T [ letrec x = y, Env in C [ y ]] T [ letrec Env , Env ′ in e ] → T [ letrec Env ′ in e ] , (T,gc,1) if LetV ars ( Env ) ∩ FV ( e, Env ′ ) = ∅ (T,gc,2) T [ letrec Env in e ] → T [ e ] if LetVars ( Env ) ∩ FV ( e ) = ∅ Meta-syntax must be capable to represent: contexts of different classes environments Env i and environment chains { x i = A i [ x i +1 ] } n − 1 i =1 11/43

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