CSSE 373 Formal Methods in Specification and Design

HW2

Purpose: dust off some more discrete math skills, experiment with the Alloy Analyzer

This is a team homework assignment. All work must be done by the team members together. All team members should understand all work submitted. If you have concerns about your own understanding or that of your teammates, please let me know. I want everyone to learn all they can in this course!

  1. Do your work in your Homework Team SVN repository for the course. Your team number and the SVN repository URL are listed in the slides for session 7.

  2. Keep track of how much time you spend on this assignment. You will submit your answers as a pdf file at the end of the homework.
  3. The first set of problems on this homework is based on A.1.1 from Software Abstractions. I modified it a bit to be, uh, less abstract.

    1. Enter the following Alloy model in the Analyzer:

      module homework/hw02_1
      
      sig Person { likes: set Person }
      
      pred show {
        some likes              -- nonempty 
        likes.likes in likes    -- transitive
        no iden & likes         -- irreflexive
        ~likes in likes         -- symmetric
        ~likes.likes in iden    -- functional
        likes.~likes in iden    -- injective
        Person in likes.Person  -- total
        Person in Person.likes  -- onto
        }
      
      run show for 4
      

      Each constraint in the show predicate constrains the likes relation according to one standard property of a binary relation. All of these properties cannot hold at once, so if you execute the run command, Alloy should report No instance found.

    2. Add a fact to the model stating that at least 4 Person atoms exist. Copy and paste that fact into your answers for this homework.
    3. Comment out all but one constraint within the show predicate. (You can use /* ... */ for block comments.) Execute the run command and visualize the results. Use Next to step through the results.

      For each constraint, give a plain-English analogy for the corresponding property. A couple of examples are given below to get you started. (You can also use other sources to look up the properties. Please indicate any external sources used, and please try to see how the Alloy results correspond to the property.)

      1. nonempty: __________________________________
      2. transitive: a friend of my friend is my friend
      3. irreflexive: __________________________________
      4. symmetric: Barney says, "I love you, you love me..."
      5. functional: __________________________________
      6. injective: Only liked by one. Also, "a face only a mother could love"
      7. total: __________________________________
      8. onto: __________________________________
    4. Next you’ll try eliminating one constraint at a time. Uncomment all the constraints. Comment out a single constraint. (You can use -- or // for single line comments.) Execute the run command and see if the constraints can be satisfied with just that single constraint eliminated. Try this for each constraint.

      For each constraint indicate either that the remaining properties are still not satisfiable, or if they are satisfiable, give an example of a satisfying relation. (You can use the Evaluator in the Visualizer to get a textual representation of the likes relation.)

      1. dropping nonempty: __________________________________
      2. dropping transitive: __________________________________
      3. dropping irreflexive: __________________________________
      4. dropping symmetric: __________________________________
      5. dropping functional: __________________________________
      6. dropping injective: __________________________________
      7. dropping total: __________________________________
      8. dropping onto: __________________________________
  4. The second set of problems is based on A.1.2 from Software Abstractions, modified as above.

    In part 2 above, the non-emptiness property was written in relational calculus style as some likes. This says the likes relation has some things in it. Those things are pairs of Persons.

    For this problem, your task will be to write the properties from above in predicate calculus style. Recall (from p. 33–35 of the text) that this style involves identifying some elements and relations and making statements about tuples formed from the elements.

    For example, the non-emptiness property in relational calculus style would be written:

    some p1, p2: Person | p1->p2 in likes
    

    This says that p1 and p2 are Persons and that there is a pair (p1,p2) in the likes relation. Thus, the likes relation is non-empty.

    A cool property of Alloy is that it can check your answers for you. You’ll see how to do that below.

    1. Enter the following Alloy model in the Analyzer:

      module homework/hw02_2
      
      sig Person { likes: set Person }
      
      assert NewNonEmptinessOK {
        some likes iff 
          (some p1, p2: Person | p1->p2 in likes)
      }
      check NewNonEmptinessOK
      
      assert NewTransitivenessOK {
        (likes.likes in likes) iff 
          (no likes)  // replace constraint with your answer
      }
      check NewTransitivenessOK
      
      assert NewIrreflexiveOK {
        (no iden & likes) iff 
          (no likes)  // replace constraint with your answer
      }
      check NewIrreflexiveOK
      
      assert NewSymmetricOK {
        (~likes in likes) iff 
          (no likes)  // replace constraint with your answer
      }
      check NewSymmetricOK
      
      assert NewFunctionalOK {
        (~likes.likes in iden) iff 
          (no likes)  // replace constraint with your answer
      }
      check NewFunctionalOK
      
      assert NewInjectiveOK {
        (likes.~likes in iden) iff 
          (no likes)  // replace constraint with your answer
      }
      check NewInjectiveOK
      
      assert NewTotalOK {
        (Person in likes.Person) iff 
          (no likes)  // replace constraint with your answer
      }
      check NewTotalOK
      
      assert NewOntoOK {
        (Person in Person.likes) iff 
          (no likes)  // replace constraint with your answer
      }
      check NewOntoOK
      
    2. Notice the first assertion at the top of the model, named NewNonEmptinessOK. The body of this assertion is:

      some likes iff 
        (some p1, p2: Person | p1->p2 in likes)
      

      This asserts that the non-emptiness property expressed in the relational calculus style as:

      some likes
      

      is equivalent to the property expressed in the predicate calculus style as:

      (some p1, p2: Person | p1->p2 in likes)
      

      The check NewNonEmptinessOK command tells Alloy to look for counterexamples that disprove the assertion. In Alloy, use the Execute menu to execute the NewNonEmptinessOK check. You should see something like this in the output pane:

      Executing "Check NewNonEmptinessOK"
         Solver=minisat(jni) Bitwidth=4 MaxSeq=4 SkolemDepth=1 Symmetry=20
         91 vars. 12 primary vars. 163 clauses. 4ms.
         No counterexample found. Assertion may be valid. 0ms.
      
    3. Edit the model to replace each (no likes) constraint with an appropriate predicate calculus style one. Execute the check in Alloy to verify that your predicate calculus style constraint is equivalent to the relational calculus one on the left-hand side of the iff.
    4. Copy and paste your predicate calculus style constraints into your answers document. Label them (i.e., “Transitive”, etc.) Please add appropriate line breaks and indentation to the constraints so we can read them easily.
  5. Be sure to document your models and include your name in the comments.
  6. How much time did you spend on this assignment?
  7. Turn in your work by committing both models and a pdf file containing your answers to the HW02 folder in your homework team subversion repository for this course.