2023-10-16 12:13:35 +01:00
|
|
|
16 Outubro 2023 - #MFES
|
|
|
|
|
|
|
|
## Alloy4Fun
|
|
|
|
|
|
|
|
```c
|
|
|
|
sig User {
|
|
|
|
follows : set User,
|
|
|
|
sees : set Photo,
|
|
|
|
posts : set Photo,
|
|
|
|
suggested : set User
|
|
|
|
}
|
|
|
|
|
|
|
|
sig Influencer extends User {}
|
|
|
|
|
|
|
|
sig Photo {
|
|
|
|
date : one Day
|
|
|
|
}
|
|
|
|
sig Ad extends Photo {}
|
|
|
|
|
|
|
|
sig Day {}
|
|
|
|
// Specify the following properties.
|
|
|
|
// You can check their correctness with the different commands and
|
|
|
|
// when specifying each property you can assume all the previous ones to be true.
|
|
|
|
|
|
|
|
pred inv1 {
|
|
|
|
// Every image is posted by one user.
|
|
|
|
all y: Photo | some x: User | x->y in posts
|
2023-10-16 12:23:35 +01:00
|
|
|
all x,y : User, z: Photo | x->z in posts and y->z in posts implies x=y
|
|
|
|
|
|
|
|
// or (equivalent to 2nd formula)
|
2023-10-16 12:43:35 +01:00
|
|
|
all x,y : User, z: Photo | x in posts.z and y in posts.z implies x=y
|
2023-10-16 12:23:35 +01:00
|
|
|
|
|
|
|
// or (equivalent to 1st and 2nd formula)
|
2023-10-16 12:43:35 +01:00
|
|
|
all y: Photo | some posts.y
|
|
|
|
all y: Photo | lone posts.y
|
2023-10-16 12:23:35 +01:00
|
|
|
|
|
|
|
// or (equivalent to 1st and 2nd formula)
|
2023-10-16 12:43:35 +01:00
|
|
|
all y:Photo | one posts.y
|
2023-10-16 12:13:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pred inv2 {
|
|
|
|
// Users cannot follow themselves.
|
2023-10-16 12:23:35 +01:00
|
|
|
all x: User | x->x not in follows
|
2023-10-16 12:33:35 +01:00
|
|
|
|
|
|
|
//or
|
2023-10-16 12:43:35 +01:00
|
|
|
all x: User | x not in x.follows
|
2023-10-16 12:13:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pred inv3 {
|
|
|
|
// Users can see ads posted by everyone,
|
|
|
|
// but only see non ads posted by followed users.
|
2023-10-16 12:43:35 +01:00
|
|
|
all x : User, y :Photo | x->y in sees implies (y in Ad) or
|
2023-10-16 12:33:35 +01:00
|
|
|
(all z:User | z->y in posts implies x->z in follows)
|
2023-10-16 12:43:35 +01:00
|
|
|
|
|
|
|
//or
|
|
|
|
all x :User, y :Photo | x in sees.y implies (y in Ad) or
|
|
|
|
(all z:User | z in posts.y implies z in x.follows)
|
|
|
|
|
|
|
|
//or
|
|
|
|
all x :User, y :Photo | x in sees.y implies (y in Ad) or
|
|
|
|
(posts.y in x.follows)
|
|
|
|
|
|
|
|
//or
|
|
|
|
all x :User, y :Photo | x in sees.y implies (y in Ad) or
|
|
|
|
(y in x.follows.posts)
|
|
|
|
|
|
|
|
//or
|
|
|
|
all x :User, y :Photo | x in sees.y implies y in x.follows.posts + Ad
|
2023-10-16 12:53:35 +01:00
|
|
|
|
|
|
|
//or
|
|
|
|
all x :User, y :Photo | y in x.sees implies y in x.follows.posts + Ad
|
|
|
|
|
|
|
|
//or
|
|
|
|
all x :User | x.sees in x.follows.posts + Ad
|
2023-10-16 12:13:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pred inv4 {
|
|
|
|
// If a user posts an ad then all its posts should be labeled as ads.
|
2023-10-16 12:53:35 +01:00
|
|
|
|
2023-10-16 12:13:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pred inv5 {
|
|
|
|
// Influencers are followed by everyone else.
|
2023-10-16 12:53:35 +01:00
|
|
|
all x: Influencer | follows.x = User-x
|
2023-10-16 12:13:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pred inv6 {
|
|
|
|
// Influencers post every day.
|
2023-10-16 12:53:35 +01:00
|
|
|
all x: Influencer, y : Day | x.posts.date = y
|
2023-10-16 12:13:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pred inv7 {
|
|
|
|
// Suggested are other users followed by followed users, but not yet followed.
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pred inv8 {
|
|
|
|
// A user only sees ads from followed or suggested users.
|
|
|
|
|
|
|
|
}
|
|
|
|
```
|