Program Slicing
                         Model Slicing
          A General Slicing Framework
                            Case Study
                            Conclusion




A General Model Based Slicing Framework

                               Tony Clark

School of Engineering and Information Sciences, Middlesex University


                        September 30, 2011




                           Tony Clark    A General Model Based Slicing Framework
Program Slicing
                                  Model Slicing
                   A General Slicing Framework
                                     Case Study
                                     Conclusion


Contents

  1   Program Slicing

  2   Model Slicing

  3   A General Slicing Framework
        GSF for Programs
        GSF for Models

  4   Case Study

  5   Conclusion


                                    Tony Clark    A General Model Based Slicing Framework
Program Slicing
                             Model Slicing
              A General Slicing Framework
                                Case Study
                                Conclusion


Definition and Use Cases



      What? Slicing is used to reduce the size of programs by
            removing those statements that do not contribute to
            the values of specified variables at a given program
            location.
       Why? Debugging; comprehension; verification.
       How? Static (backwards,forwards); dynamic; conditioned;
            union.




                               Tony Clark    A General Model Based Slicing Framework
Program Slicing
                             Model Slicing
              A General Slicing Framework
                                Case Study
                                Conclusion


Backward Slicing: Example1




   Original                          Criterion                                             Slice
    x = 42
    d = 23                                   d                                    d = 23




                               Tony Clark        A General Model Based Slicing Framework
Program Slicing
                            Model Slicing
             A General Slicing Framework
                               Case Study
                               Conclusion


Backward Slicing: Example2


   Original               Criterion                                                   Slice
    sum=0
    prod=1                                                   prod = 1
    read(i)                                                  read(i)
    while(i<11) {                                            while (i<11) {
      sum=sum+i
      prod=prod*i                                                prod=prod*i
      i=i+1                                                      i=i+1
    }                       prod                             }




                              Tony Clark    A General Model Based Slicing Framework
Program Slicing
                            Model Slicing
             A General Slicing Framework
                               Case Study
                               Conclusion


Dynamic Slicing


   Original               Criterion                                                   Slice
    sum=0
    prod=1
                                                                         prod = 1
    read(i)
                                                                         read(i)
    while(i<11) {
      sum=sum+i
      prod=prod*i
      i=i+1
    }                       prod, pos(next(input))=11




                              Tony Clark    A General Model Based Slicing Framework
Program Slicing
                             Model Slicing
              A General Slicing Framework
                                Case Study
                                Conclusion


Conditioned Slicing




   Original   Criterion                                                         Slice
    read(a)                                                                 read(a)
    if(a<0)
     a=-a
    x=1/a        x, +ve(next(input))                                        x=1/a




                               Tony Clark    A General Model Based Slicing Framework
Program Slicing
                                Model Slicing
                 A General Slicing Framework
                                   Case Study
                                   Conclusion


Unions
   Original                             Criterion                                             Slice
    a = 42                                                                       a = 42
    x = 2
    b = 23 + a                                                                   b = 23 + a
    y = 3
    c = b + 2                                   c                                c = b + 2
    a = 42
    x = 2
    b = 23 + a
    y = 3                                                                                y = 3
    c = b + 2                                   y
    a = 42                                                                       a = 42
    x = 2
    b = 23 + a                                                                   b = 23 + a
    y = 3                                                                        y = 3
    c = b + 2                             y and c                                c = b + 2

                                  Tony Clark        A General Model Based Slicing Framework
Program Slicing
                                  Model Slicing
                   A General Slicing Framework
                                     Case Study
                                     Conclusion


Contents

  1   Program Slicing

  2   Model Slicing

  3   A General Slicing Framework
        GSF for Programs
        GSF for Models

  4   Case Study

  5   Conclusion


                                    Tony Clark    A General Model Based Slicing Framework
Program Slicing
                              Model Slicing
               A General Slicing Framework
                                 Case Study
                                 Conclusion


Definition and Use Cases



      What? erm - drop some bits?
       Why? Model management and comprehension; debugging
            transformations; debugging executable models; model
            verification.
       How? State machines; class diagrams (syntax); specific
            technologies.
     Problem No general definition for model slicing.




                                Tony Clark    A General Model Based Slicing Framework
Program Slicing
                              Model Slicing
               A General Slicing Framework
                                 Case Study
                                 Conclusion


Differences to Programs



     No starting point for execution.
     Static and dynamic slices.
     Multiple languages.
     DSLs, profiles, meta-models.
     Highly structured.
     Weak semantics.
     Links to model transformations; transformation combinations.




                                Tony Clark    A General Model Based Slicing Framework
Program Slicing
                                  Model Slicing
                                                  GSF for Programs
                   A General Slicing Framework
                                                  GSF for Models
                                     Case Study
                                     Conclusion


Contents

  1   Program Slicing

  2   Model Slicing

  3   A General Slicing Framework
        GSF for Programs
        GSF for Models

  4   Case Study

  5   Conclusion


                                    Tony Clark    A General Model Based Slicing Framework
Program Slicing
                                 Model Slicing
                                                 GSF for Programs
                  A General Slicing Framework
                                                 GSF for Models
                                    Case Study
                                    Conclusion


A General Slicing Framework
                                        φ                - σ:Σ
          γ:Γ


                      p




                                                                          x
                                                     q
                          -




                                                 




                                                                              -
                                φ                                         z-
          p                γ :Γ - σ :Σ                       - q               ω:Σ




                                                                            -
                                                       q
                  p




                                                                          y
              ?                                              ?




                                                            -
              




         γ :Γ                                            - σ :Σ
                                φ
            Γ   Syntax domain.
           Σ    Semantic domain.
         p, q   Projections.
            φ   Semantics.
       (x, ω)   Slicing criterion.
                                   Tony Clark    A General Model Based Slicing Framework
Program Slicing
                               Model Slicing
                                               GSF for Programs
                A General Slicing Framework
                                               GSF for Models
                                  Case Study
                                  Conclusion


Key Features

  To set up the framework for a particular domain you will need:
    syntax (Γ) The things you want to slice.
  semantics (Σ, φ) The meaning of the syntax defined as a semantic
               domain and a semantic mapping.
  projections (p, q) Relationships that hold between syntactic and
                semantic elements and that remove items that are
                not of interest.
  criterion (x, ω) The things that remain invariant, defined in terms
                 of the semantic domain.
     products If the syntax and semantic domain also define
              products for elements and projections then there is
              scope for slicing composition.

                                 Tony Clark    A General Model Based Slicing Framework
Program Slicing
                           Model Slicing
                                           GSF for Programs
            A General Slicing Framework
                                           GSF for Models
                              Case Study
                              Conclusion


Semantic Domain for Programs




                             Tony Clark    A General Model Based Slicing Framework
Program Slicing
                               Model Slicing
                                                   GSF for Programs
                A General Slicing Framework
                                                   GSF for Models
                                  Case Study
                                  Conclusion


GSF: Program Example1

   Original                            Criterion                                             Slice
    x = 42
    d = 23                                     d                                    d = 23



  Semantics is σ = {[{x → 41; d → 23}]} The slice criterion requires
  that any trace in σ when projected onto the second step has a
  value for d, so ω = {{d → v } | v ∈ V } Therefore the smallest set
  of traces for which there exists a structural projection is
  σ = {[{d → v } | v ∈ V }]}.



                                 Tony Clark        A General Model Based Slicing Framework
Program Slicing
                                   Model Slicing
                                                   GSF for Programs
                    A General Slicing Framework
                                                   GSF for Models
                                      Case Study
                                      Conclusion


GSF: Program Example2
    Original                Criterion                                         Slice
      sum=0
      prod=1                                                      prod = 1
      read(i)                                                     read(i)
      while(i11) {                                               while (i11) {
        sum=sum+i
        prod=prod*i                                                 prod=prod*i
        i=i+1                                                       i=i+1
      }                      prod                                 }
  Semantics is σ = {[{sum → 0}, {sum → 0; prod → 1}, {sum → 0; prod →
  1; i → v }] + trace(v ) | v ∈ 0 . . . 10} ] where trace(0) = []

         trace(v ) = trace(v − 1) + [{sum →                      i; prod →!v ; i → v }]
                                                       i∈0...v

  Criterion requires that ω = {prod → v | v ∈ V } and x maps each trace onto
  the last maplet for prod.

                                     Tony Clark    A General Model Based Slicing Framework
Program Slicing
                           Model Slicing
                                           GSF for Programs
            A General Slicing Framework
                                           GSF for Models
                              Case Study
                              Conclusion
Modelling Language: Syntax
                             Tony Clark    A General Model Based Slicing Framework
Program Slicing
                           Model Slicing
                                           GSF for Programs
            A General Slicing Framework
                                           GSF for Models
                              Case Study
                              Conclusion
Modelling Language: Semantic Domain
                             Tony Clark    A General Model Based Slicing Framework
Program Slicing
                                  Model Slicing
                   A General Slicing Framework
                                     Case Study
                                     Conclusion


Contents

  1   Program Slicing

  2   Model Slicing

  3   A General Slicing Framework
        GSF for Programs
        GSF for Models

  4   Case Study

  5   Conclusion


                                    Tony Clark    A General Model Based Slicing Framework
Program Slicing
                           Model Slicing
            A General Slicing Framework
                              Case Study
                              Conclusion


Case Study: Use Cases




                             Tony Clark    A General Model Based Slicing Framework
Program Slicing
                            Model Slicing
             A General Slicing Framework
                               Case Study
                               Conclusion


Case Study: Class Model




                              Tony Clark    A General Model Based Slicing Framework
Program Slicing
                             Model Slicing
              A General Slicing Framework
                                Case Study
                                Conclusion


OCL




 c o n t e x t Library :: borrow ( reader , book )
     p r e not hasFine ( reader ) and
     p o s t borrows -  includes ( b |
                b . reader = getReader ( reader ) and
                b . book = getBook ( book ) and
                b . date = date ())




                               Tony Clark    A General Model Based Slicing Framework
Program Slicing
                           Model Slicing
            A General Slicing Framework
                              Case Study
                              Conclusion


Case Study: State Machine




                             Tony Clark    A General Model Based Slicing Framework
Program Slicing
                           Model Slicing
            A General Slicing Framework
                              Case Study
                              Conclusion


Case Study: Sequence Model




                             Tony Clark    A General Model Based Slicing Framework
Program Slicing
                                   Model Slicing
                    A General Slicing Framework
                                      Case Study
                                      Conclusion


A Borrowing Step


  ( s1 , ok = 0 - borrow ( fred , b ) ,f , s6 )
     where
         s1 = ({(0 ,* , Library )[ limit = l ] ,(1 ,* , Book )[ name =n , id =1] ,
                   (2 , initialized , Reader )[ name = fred , id =2]} ,{})
         f = [( s1 , false = 0 - hasFine ( fred ) ,... , s1 ) ,
                ( s1 ,2 = 0 - getReader ( fred ) ,... , s1 ) ,
                ( s1 ,1 = 0 - getBook ( n ) ,... , s1 ) ,
                ( s1 , d = 0 - getDate () ,... , s1 ) ,
                ( s1 ,3 = 0 - new ( Borrows ) ,[] , s2 ) ,
                ( s2 , ok = 3 - setReader (2) ,... , s4 ) ,
              ....]
         s2 = ({(0 ,* , Library )[ limit = l ] ,(1 ,* , Book )[ name =n , id =1] ,
                   (2 , initialized , Reader )[ name = fred , id =2] ,
                   (3 ,* , Borrows )[]} ,{})




                                     Tony Clark    A General Model Based Slicing Framework
Program Slicing
                                 Model Slicing
                  A General Slicing Framework
                                    Case Study
                                    Conclusion


Slicing Criterion


  B ={( s1 , v = l - borrow (r , b ) ,F , s2 ) |
              F - Filmstrip ,
              s1 - Snapshot ,
              s2 - Snapshot ,
              v - Value ,
              l - Id ,
              r - Str ,
              b - Str }

  Use ω = B ∗ as basis for slicing criterion.
  x1 projects a filmstrip to the sequence of borrow steps it contains.



                                   Tony Clark    A General Model Based Slicing Framework
Program Slicing
                              Model Slicing
               A General Slicing Framework
                                 Case Study
                                 Conclusion
Sliced Model
                                Tony Clark    A General Model Based Slicing Framework
Program Slicing
                                Model Slicing
                 A General Slicing Framework
                                   Case Study
                                   Conclusion


Refining the Slice



  {[( s1 , v = l - borrow (r , b ) ,[] , s2 )] |
       s1 - Snapshot ,
       s2 - Snapshot ,
       v - Value ,
       l - Id ,
       r - Str ,
       b - Str }

  The mapping part x2 is a refinement of x1 that maps all nested
  filmstrips to [].




                                  Tony Clark    A General Model Based Slicing Framework
Program Slicing
                              Model Slicing
               A General Slicing Framework
                                 Case Study
                                 Conclusion
Refined Slice
                                Tony Clark    A General Model Based Slicing Framework
Program Slicing
                                  Model Slicing
                   A General Slicing Framework
                                     Case Study
                                     Conclusion


Contents

  1   Program Slicing

  2   Model Slicing

  3   A General Slicing Framework
        GSF for Programs
        GSF for Models

  4   Case Study

  5   Conclusion


                                    Tony Clark    A General Model Based Slicing Framework
Program Slicing
                              Model Slicing
               A General Slicing Framework
                                 Case Study
                                 Conclusion


Issues and Problems



     Constructing slicing transformations: use of existing model
     transformation languages? New languages?
     Projection definition for OCL - requires theorem proving?
     Combination of slices? Consistency of slices?
     Slicing theories?
     Restricted forms of slicing: static, dynamic, conditioned?




                                Tony Clark    A General Model Based Slicing Framework

Model Slicing

  • 1.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion A General Model Based Slicing Framework Tony Clark School of Engineering and Information Sciences, Middlesex University September 30, 2011 Tony Clark A General Model Based Slicing Framework
  • 2.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Contents 1 Program Slicing 2 Model Slicing 3 A General Slicing Framework GSF for Programs GSF for Models 4 Case Study 5 Conclusion Tony Clark A General Model Based Slicing Framework
  • 3.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Definition and Use Cases What? Slicing is used to reduce the size of programs by removing those statements that do not contribute to the values of specified variables at a given program location. Why? Debugging; comprehension; verification. How? Static (backwards,forwards); dynamic; conditioned; union. Tony Clark A General Model Based Slicing Framework
  • 4.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Backward Slicing: Example1 Original Criterion Slice x = 42 d = 23 d d = 23 Tony Clark A General Model Based Slicing Framework
  • 5.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Backward Slicing: Example2 Original Criterion Slice sum=0 prod=1 prod = 1 read(i) read(i) while(i<11) { while (i<11) { sum=sum+i prod=prod*i prod=prod*i i=i+1 i=i+1 } prod } Tony Clark A General Model Based Slicing Framework
  • 6.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Dynamic Slicing Original Criterion Slice sum=0 prod=1 prod = 1 read(i) read(i) while(i<11) { sum=sum+i prod=prod*i i=i+1 } prod, pos(next(input))=11 Tony Clark A General Model Based Slicing Framework
  • 7.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Conditioned Slicing Original Criterion Slice read(a) read(a) if(a<0) a=-a x=1/a x, +ve(next(input)) x=1/a Tony Clark A General Model Based Slicing Framework
  • 8.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Unions Original Criterion Slice a = 42 a = 42 x = 2 b = 23 + a b = 23 + a y = 3 c = b + 2 c c = b + 2 a = 42 x = 2 b = 23 + a y = 3 y = 3 c = b + 2 y a = 42 a = 42 x = 2 b = 23 + a b = 23 + a y = 3 y = 3 c = b + 2 y and c c = b + 2 Tony Clark A General Model Based Slicing Framework
  • 9.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Contents 1 Program Slicing 2 Model Slicing 3 A General Slicing Framework GSF for Programs GSF for Models 4 Case Study 5 Conclusion Tony Clark A General Model Based Slicing Framework
  • 10.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Definition and Use Cases What? erm - drop some bits? Why? Model management and comprehension; debugging transformations; debugging executable models; model verification. How? State machines; class diagrams (syntax); specific technologies. Problem No general definition for model slicing. Tony Clark A General Model Based Slicing Framework
  • 11.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Differences to Programs No starting point for execution. Static and dynamic slices. Multiple languages. DSLs, profiles, meta-models. Highly structured. Weak semantics. Links to model transformations; transformation combinations. Tony Clark A General Model Based Slicing Framework
  • 12.
    Program Slicing Model Slicing GSF for Programs A General Slicing Framework GSF for Models Case Study Conclusion Contents 1 Program Slicing 2 Model Slicing 3 A General Slicing Framework GSF for Programs GSF for Models 4 Case Study 5 Conclusion Tony Clark A General Model Based Slicing Framework
  • 13.
    Program Slicing Model Slicing GSF for Programs A General Slicing Framework GSF for Models Case Study Conclusion A General Slicing Framework φ - σ:Σ γ:Γ p x q - - φ z- p γ :Γ - σ :Σ - q ω:Σ - q p y ? ? - γ :Γ - σ :Σ φ Γ Syntax domain. Σ Semantic domain. p, q Projections. φ Semantics. (x, ω) Slicing criterion. Tony Clark A General Model Based Slicing Framework
  • 14.
    Program Slicing Model Slicing GSF for Programs A General Slicing Framework GSF for Models Case Study Conclusion Key Features To set up the framework for a particular domain you will need: syntax (Γ) The things you want to slice. semantics (Σ, φ) The meaning of the syntax defined as a semantic domain and a semantic mapping. projections (p, q) Relationships that hold between syntactic and semantic elements and that remove items that are not of interest. criterion (x, ω) The things that remain invariant, defined in terms of the semantic domain. products If the syntax and semantic domain also define products for elements and projections then there is scope for slicing composition. Tony Clark A General Model Based Slicing Framework
  • 15.
    Program Slicing Model Slicing GSF for Programs A General Slicing Framework GSF for Models Case Study Conclusion Semantic Domain for Programs Tony Clark A General Model Based Slicing Framework
  • 16.
    Program Slicing Model Slicing GSF for Programs A General Slicing Framework GSF for Models Case Study Conclusion GSF: Program Example1 Original Criterion Slice x = 42 d = 23 d d = 23 Semantics is σ = {[{x → 41; d → 23}]} The slice criterion requires that any trace in σ when projected onto the second step has a value for d, so ω = {{d → v } | v ∈ V } Therefore the smallest set of traces for which there exists a structural projection is σ = {[{d → v } | v ∈ V }]}. Tony Clark A General Model Based Slicing Framework
  • 17.
    Program Slicing Model Slicing GSF for Programs A General Slicing Framework GSF for Models Case Study Conclusion GSF: Program Example2 Original Criterion Slice sum=0 prod=1 prod = 1 read(i) read(i) while(i11) { while (i11) { sum=sum+i prod=prod*i prod=prod*i i=i+1 i=i+1 } prod } Semantics is σ = {[{sum → 0}, {sum → 0; prod → 1}, {sum → 0; prod → 1; i → v }] + trace(v ) | v ∈ 0 . . . 10} ] where trace(0) = [] trace(v ) = trace(v − 1) + [{sum → i; prod →!v ; i → v }] i∈0...v Criterion requires that ω = {prod → v | v ∈ V } and x maps each trace onto the last maplet for prod. Tony Clark A General Model Based Slicing Framework
  • 18.
    Program Slicing Model Slicing GSF for Programs A General Slicing Framework GSF for Models Case Study Conclusion Modelling Language: Syntax Tony Clark A General Model Based Slicing Framework
  • 19.
    Program Slicing Model Slicing GSF for Programs A General Slicing Framework GSF for Models Case Study Conclusion Modelling Language: Semantic Domain Tony Clark A General Model Based Slicing Framework
  • 20.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Contents 1 Program Slicing 2 Model Slicing 3 A General Slicing Framework GSF for Programs GSF for Models 4 Case Study 5 Conclusion Tony Clark A General Model Based Slicing Framework
  • 21.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Case Study: Use Cases Tony Clark A General Model Based Slicing Framework
  • 22.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Case Study: Class Model Tony Clark A General Model Based Slicing Framework
  • 23.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion OCL c o n t e x t Library :: borrow ( reader , book ) p r e not hasFine ( reader ) and p o s t borrows - includes ( b | b . reader = getReader ( reader ) and b . book = getBook ( book ) and b . date = date ()) Tony Clark A General Model Based Slicing Framework
  • 24.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Case Study: State Machine Tony Clark A General Model Based Slicing Framework
  • 25.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Case Study: Sequence Model Tony Clark A General Model Based Slicing Framework
  • 26.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion A Borrowing Step ( s1 , ok = 0 - borrow ( fred , b ) ,f , s6 ) where s1 = ({(0 ,* , Library )[ limit = l ] ,(1 ,* , Book )[ name =n , id =1] , (2 , initialized , Reader )[ name = fred , id =2]} ,{}) f = [( s1 , false = 0 - hasFine ( fred ) ,... , s1 ) , ( s1 ,2 = 0 - getReader ( fred ) ,... , s1 ) , ( s1 ,1 = 0 - getBook ( n ) ,... , s1 ) , ( s1 , d = 0 - getDate () ,... , s1 ) , ( s1 ,3 = 0 - new ( Borrows ) ,[] , s2 ) , ( s2 , ok = 3 - setReader (2) ,... , s4 ) , ....] s2 = ({(0 ,* , Library )[ limit = l ] ,(1 ,* , Book )[ name =n , id =1] , (2 , initialized , Reader )[ name = fred , id =2] , (3 ,* , Borrows )[]} ,{}) Tony Clark A General Model Based Slicing Framework
  • 27.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Slicing Criterion B ={( s1 , v = l - borrow (r , b ) ,F , s2 ) | F - Filmstrip , s1 - Snapshot , s2 - Snapshot , v - Value , l - Id , r - Str , b - Str } Use ω = B ∗ as basis for slicing criterion. x1 projects a filmstrip to the sequence of borrow steps it contains. Tony Clark A General Model Based Slicing Framework
  • 28.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Sliced Model Tony Clark A General Model Based Slicing Framework
  • 29.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Refining the Slice {[( s1 , v = l - borrow (r , b ) ,[] , s2 )] | s1 - Snapshot , s2 - Snapshot , v - Value , l - Id , r - Str , b - Str } The mapping part x2 is a refinement of x1 that maps all nested filmstrips to []. Tony Clark A General Model Based Slicing Framework
  • 30.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Refined Slice Tony Clark A General Model Based Slicing Framework
  • 31.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Contents 1 Program Slicing 2 Model Slicing 3 A General Slicing Framework GSF for Programs GSF for Models 4 Case Study 5 Conclusion Tony Clark A General Model Based Slicing Framework
  • 32.
    Program Slicing Model Slicing A General Slicing Framework Case Study Conclusion Issues and Problems Constructing slicing transformations: use of existing model transformation languages? New languages? Projection definition for OCL - requires theorem proving? Combination of slices? Consistency of slices? Slicing theories? Restricted forms of slicing: static, dynamic, conditioned? Tony Clark A General Model Based Slicing Framework