CS195Y Lecture 6

2/6/17

Announcements: Alloy 1 due Thursday 2/9, Lab 1 this week on Tuesday and Wednesday!

Research is limited on how users use Alloy. In this vein, Tim is trying to gather data about how users, especially new users, use tools like Alloy. During the lab, anonymous data will be collected about how you use Alloy. You can opt out of the research at any point and this will not affect your grade.

 sig City {
              roads: set City
            }
            one sig Pvd extends City {}
            ...
            run {}

If we make City abstract then we'll only get named cities. If we take that out then we see unnamed cities
Now we have a model that can show us some instances of cities and roads between them.
But some of the cities have self loops. This doesn't really make any sense so lets remove them.

 fact noloops {
              all c : City |
            }
            run {}
 pred  toPVD[c : City]{
              PVD in c.roads
            }
            run toPVD for 5

What does . actually do? It's the relational join operator. But what does that look like?
Example: roads.roads = all paths of length 2 in the evaluator Board Example: {PVD -> Bos, PVD -> WORC, WORC-> PVD} ° {PVD -> Bos, PVD -> WORC, WORC-> PVD} Look at everything in the cross product of this relation. Match 2nd element on the left with 1st element on the left. ie. WORC -> PVD and PVD -> BOS gives us WORC -> BOS Do this until you can't find any more matches. We'll get lots more practice with this as we go on.

 pred  toAndFromPVD[c : City]{
              c in PVD.roads
              toPVD[c]
            }
            run toAndFromPVD for 5

Now we want two way roads! In three different ways!

 pred twoWayRoadsA{
              all c, d : City |
                c in d.roads iff d in c.roads
            }
 pred twoWayRoadsB{
              all c, d : City |
                d->d in roads iff d->c in roads
            }
 pred twoWayRoadsC{
              roads = ~roads
            }

B is often called predicate calculus style and C is often called relational style calculus
But do we trust Tim that these 2 predicates are equivalent?
Alloy can prove it to us!

 pred twoWayPredsDifferent{
              not (twoWayRoadsB iff twoWayRoadsC)
            }
            run twoWayPredsDifferent for 6

This is really powerful! We just had Alloy check all of the graphs up to size 6 to see if these two predicates are ever not equal. Note that there could be a counterexample for graphs larger than 6 but we are convinced that there is no small counter example.

One last operator:

 pred reachesPVD[c : City]{
              PVD in c.^roads
           }
           run twoWayPredsDifferent for 6

What is this ^ operator and what does it do? ^ is the transitive closure operator. The ^ unfolds all of the dots between roads. This is really helpful when we're talking about reachability.