Alloy Analyzer



2011   9   23
•          (id:mr_konn / @mr_konn)

                •
                    •
                • Haskell Lover
                • 2010 Summer Intern    PFI


2011   9   23
•   Alloy



                •

                •   Alloy Analyzer
                    http://alloy.mit.edu/alloy4/



2011   9   23
Alloy Analyzer
                •
                    •        →   /



                    •
                    •“   ”


2011   9   23
•       ……

                •
                    •
                    •

2011   9   23
“             ”
                •   Alloy           SAT

                    •
                        •                     (10
                                )

                        •
                •
                    •

2011   9   23
2011   9   23
•
                    •   ,

                •



2011   9   23
•
                    •
                    •
                •
                •
2011   9   23
Alloy
                    enum        {   ,       }
                    enum            {           ,         }
                    abstract sig            {           : one       }

                    abstract sig            {
                           : lone       ,
                           :
                    } {
                      some      => (                =         <=>   .   =   )
                    }



                •
                •
2011   9   23
Alloy                                      (2)
                     one sig     extends            {} {
                                           in
                     }
                     one sig     extends            {} { no         }

                     one sig                          extends           {} {
                           =     <=> ( .        =          =>   .       =      )
                     }

                     pred show {}
                     run show



                •
                •   run : pred

2011   9   23
•
                •

2011   9   23
•
                •

                    •   Yes/No




2011   9   23
Alloy                                 (1)
           module marsandvenus                    abstract sig             {
                                                           :       ,
           enum              {       ,        }
                                                           :   ,
           enum                  {   ,   }
                                                           :       -> one
           enum                  {   ,   }
                                                  } {
                                                    all q :            |
           sig           {
                                                        ((     =       and     =    )
           !         :               -> one
                                                      or (     =       and     =    ))
           }
                                                        <=>        [q] = q.    [this]
                                                  }

                 •
                 •                                     /

2011   9   23
Alloy                        (2)
                •                                   ……
                         one sig          extends    {} {
                               in   and     in
                         }


                    •
                •                                           ……




2011   9   23
pred              (        :   ) {
                    all       :        |
                          .       in       <=> (     .   [   ] =   )
                }
                fact { one             }
                run


                •                 Yes

                •   run



2011   9   23
•
                •

2011   9   23
○   No
                          ○   Yes
                          ×   No
                          ×   Yes

                •
                    YES
2011   9   23
2011   9   23
•
                    •   ……

                    •
                    •
                •            or



2011   9   23
module tour/filesystem

                abstract sig Object {}
                sig Directory extends Object {
                 contents: set Object
                 }
                one sig Root extends Directory {}
                sig File extends Object {}
                sig Alias extends File {to: Object}

                pred show {}
                run show



2011   9   23
……



                •
                    1.   (File)

                    2.

                    3.


2011   9   23
fact FileBelongsSomewhere {
                  all f : File | one d : Directory |
                    f in d.contents
                }

                fact NoRecursiveDirs {
                ! no d : Directory | d in d.contents
                }

                fact RootHasNoSuperDir {
                  no d: Directory | Root in d.contents
                }


                  •   fact :


                  •
                      •                         (      )
2011   9   23
•                                   Directory

                • FileBelongsSomewhere
                fact ObjBelongsSomewhere {
                  all o : Object | one d : Directory | o in d.contents
                }


2011   9   23
……
                •
                • RootHasNoSuperDir
                  ObjBelongsSomewhere

                • all o : Object   all o : Object - Root




2011   9   23
•
                •
                •   ……

2011   9   23
Alloy
                •   Alloy

                •   Object = Directory ⊔ File, Alias ⊆ File

                    •
                •           (   )

                    •   Root        one

                •   contents : Directory          Object

                    •   n                 n

                    •                         1


2011   9   23
•   A+B:A        B

                •   A&B:A        B

                •   A-B:A        B

                •   A in B : A   B   (A ⊆ B)

                    •                 (A∈B)

                •   A = B :A     B



2011   9   23
•   P→Q:              P, Q

                •   A.B :

                    •   A         B



                    •       {(1)} . {1→A, 1→B, 3→B} = {(A), (B)}
                            {1→A, 1→B, 3→B} . {(B)} = {(1), (3)}

                    •

2011   9   23
•   A[B] : B. A

                    •               a.b [c] = c.(a.b)

                    •
                •   ~a :       a

                •   ^a, *a :

                    •   ^{1→2, 2→3} = {1→2, 2→3, 1→3}

                    •   *{1→2, 2→3} = {1→2, 2→3, 1→3, 1→1, 2→2, 3→3}


2011   9   23
•   none :

                    •
                •   univ :

                    •
                •   iden :

                    •   a.iden = a , iden.a = a (forall a)


2011   9   23
•   all x : e | F =    e               x       F

                •   some x : e | F =       x       F

                •   no x : e | F =     x       F

                •   lone x : e | F =               x       F

                •   one x : e | F =            x       F

                    •
2011   9   23
…



                •   /



                •
2011   9   23
fact NoRecursiveDirs {
                ! no d : Directory | d in d.^contents
                }

                fact NoRecursiveAliases {
                ! no a : Alias | a in a.^to
                }



                •
                •
2011   9   23
•



2011   9   23
run
                               pred show {}
                               run show


                • run hoge :      hoge



                 •         show



                 •                       (    )
2011   9   23
pred show {} for 4
                                run show

                •   for n          n

                    •                      n=3

                •
                    •   for 4 but 2 Alias, exactly 1 Directory
                        •   4          2       Alias,        1   Dir

                •
2011   9   23
•       Object   Root

                    •                   …

                •


2011   9   23
assert
                assert TrackableFromRoot {
                  all o : Object | o in Root.^contents
                }

                check TrackableFromRoot




                •                           (               )

                •   check hoge    hoge

                    •   run                          (default: 3)


2011   9   23
•           ……




                • Root Root
                • Object - Root
                          Root.*contents
2011   9   23
assert TrackableFromRoot {
                  all o : Object | o in Root.*contents
                }

                check TrackableFromRoot




                •
                •

2011   9   23
Alloy

                •
                    fact NoRecursiveDirsOrAlias {
                    ! no iden & (^contents + ^to)
                    }
                    fact RootHasNoSuperDir {no contents.Root}
                    fact AllObjBelongSomewhere {
                      all o : Object - Root | some contents.o
                      }
                    assert TrackableFromRoot {
                      Object in Root.*contents
                    }



2011   9   23
• Alloy
                •
                  •
                  • Alloy
                •
2011   9   23
Any Questions?



2011   9   23
2011   9   23

Alloy Analyzer のこと

  • 1.
  • 2.
    (id:mr_konn / @mr_konn) • • • Haskell Lover • 2010 Summer Intern PFI 2011 9 23
  • 3.
    Alloy • • Alloy Analyzer http://alloy.mit.edu/alloy4/ 2011 9 23
  • 4.
    Alloy Analyzer • • → / • •“ ” 2011 9 23
  • 5.
    …… • • • 2011 9 23
  • 6.
    ” • Alloy SAT • • (10 ) • • • 2011 9 23
  • 7.
    2011 9 23
  • 8.
    • , • 2011 9 23
  • 9.
    • • • • 2011 9 23
  • 10.
    Alloy enum { , } enum { , } abstract sig { : one } abstract sig { : lone , : } { some => ( = <=> . = ) } • • 2011 9 23
  • 11.
    Alloy (2) one sig extends {} { in } one sig extends {} { no } one sig extends {} { = <=> ( . = => . = ) } pred show {} run show • • run : pred 2011 9 23
  • 12.
    • 2011 9 23
  • 13.
    • • Yes/No 2011 9 23
  • 14.
    Alloy (1) module marsandvenus abstract sig { : , enum { , } : , enum { , } : -> one enum { , } } { all q : | sig { (( = and = ) ! : -> one or ( = and = )) } <=> [q] = q. [this] } • • / 2011 9 23
  • 15.
    Alloy (2) • …… one sig extends {} { in and in } • • …… 2011 9 23
  • 16.
    pred ( : ) { all : | . in <=> ( . [ ] = ) } fact { one } run • Yes • run 2011 9 23
  • 17.
    • 2011 9 23
  • 18.
    No ○ Yes × No × Yes • YES 2011 9 23
  • 19.
    2011 9 23
  • 20.
    • …… • • • or 2011 9 23
  • 21.
    module tour/filesystem abstract sig Object {} sig Directory extends Object { contents: set Object } one sig Root extends Directory {} sig File extends Object {} sig Alias extends File {to: Object} pred show {} run show 2011 9 23
  • 22.
    …… • 1. (File) 2. 3. 2011 9 23
  • 23.
    fact FileBelongsSomewhere { all f : File | one d : Directory | f in d.contents } fact NoRecursiveDirs { ! no d : Directory | d in d.contents } fact RootHasNoSuperDir { no d: Directory | Root in d.contents } • fact : • • ( ) 2011 9 23
  • 24.
    Directory • FileBelongsSomewhere fact ObjBelongsSomewhere { all o : Object | one d : Directory | o in d.contents } 2011 9 23
  • 25.
    …… • • RootHasNoSuperDir ObjBelongsSomewhere • all o : Object all o : Object - Root 2011 9 23
  • 26.
    • • …… 2011 9 23
  • 27.
    Alloy • Alloy • Object = Directory ⊔ File, Alias ⊆ File • • ( ) • Root one • contents : Directory Object • n n • 1 2011 9 23
  • 28.
    A+B:A B • A&B:A B • A-B:A B • A in B : A B (A ⊆ B) • (A∈B) • A = B :A B 2011 9 23
  • 29.
    P→Q: P, Q • A.B : • A B • {(1)} . {1→A, 1→B, 3→B} = {(A), (B)} {1→A, 1→B, 3→B} . {(B)} = {(1), (3)} • 2011 9 23
  • 30.
    A[B] : B. A • a.b [c] = c.(a.b) • • ~a : a • ^a, *a : • ^{1→2, 2→3} = {1→2, 2→3, 1→3} • *{1→2, 2→3} = {1→2, 2→3, 1→3, 1→1, 2→2, 3→3} 2011 9 23
  • 31.
    none : • • univ : • • iden : • a.iden = a , iden.a = a (forall a) 2011 9 23
  • 32.
    all x : e | F = e x F • some x : e | F = x F • no x : e | F = x F • lone x : e | F = x F • one x : e | F = x F • 2011 9 23
  • 33.
    • / • 2011 9 23
  • 34.
    fact NoRecursiveDirs { ! no d : Directory | d in d.^contents } fact NoRecursiveAliases { ! no a : Alias | a in a.^to } • • 2011 9 23
  • 35.
  • 36.
    run pred show {} run show • run hoge : hoge • show • ( ) 2011 9 23
  • 37.
    pred show {}for 4 run show • for n n • n=3 • • for 4 but 2 Alias, exactly 1 Directory • 4 2 Alias, 1 Dir • 2011 9 23
  • 38.
    Object Root • … • 2011 9 23
  • 39.
    assert assert TrackableFromRoot { all o : Object | o in Root.^contents } check TrackableFromRoot • ( ) • check hoge hoge • run (default: 3) 2011 9 23
  • 40.
    …… • Root Root • Object - Root Root.*contents 2011 9 23
  • 41.
    assert TrackableFromRoot { all o : Object | o in Root.*contents } check TrackableFromRoot • • 2011 9 23
  • 42.
    Alloy • fact NoRecursiveDirsOrAlias { ! no iden & (^contents + ^to) } fact RootHasNoSuperDir {no contents.Root} fact AllObjBelongSomewhere { all o : Object - Root | some contents.o } assert TrackableFromRoot { Object in Root.*contents } 2011 9 23
  • 43.
    • Alloy • • • Alloy • 2011 9 23
  • 44.
  • 45.
    2011 9 23