Download presentation
Presentation is loading. Please wait.
1
Rigorous Software Engineering
Assignment 3 (exercise 2, 3.3, 3.5)
2
Exercise 2 abstract sig Student {} sig Graduate extends Student{}
sig Undergraduate extends Student {} sig ID {} sig Major {} sig University {}
3
abstract sig Student { id: one ID, major: one Major, university: lone University, isLegal: Bool, classmates: set Student, }
4
Every student has a unique student ID.
Descriptions Descriptions A student should register at a university, and only registered students are legal students. Every student has a unique student ID. Alloy Alloy fact legal_in_university{ all s: Student | (s.university != none) iff (s.isLegal = True) } fact unique_ids{ all disj s, t: Student | s.id != t.id } fact no_id_without_student{ all i: ID | one s: Student | s.id = i }
5
Graduates and undergraduates are never classmates.
Descriptions Students with the same major who are registered at the same university are regarded as classmates. Graduates and undergraduates are never classmates. Alloy fact classmates_have_same_major_and_uni{ all disj s, t: Student | (s.major = t.major and s.university = t.university and (s in Undergraduate and t in Undergraduate or s in Graduate and t in Graduate) iff (s in t.classmates) }
6
fact no_self_classmate{ all s: Student | s not in s.classmates }
Descriptions Descriptions The classmate relation is not reflexive (a student cannot be his/her own classmate). Visualize the model for 2 Universities, 3 Majors, 3 Students and 3 IDs. Alloy Alloy fact no_self_classmate{ all s: Student | s not in s.classmates } pred show{} run show for 2 University, 3 Major, 3 Student, 3 ID
7
Exercise 3.3 Doris Day’s song
“Everybody loves my baby but my baby don’t love nobody but me” David Gries has pointed out that, from a strictly logical point of view, this implies ‘I am my baby’. Everybody loves my baby (b) pred my_baby[b: Person] { (all p: Person | b in p.loves) and b.loves = Me } assert song { all p: Person | my_baby[p] implies Me = p } My baby don’t love nobody but me
8
Exercise 3.3 Doris Day’s song
“Everybody loves my baby but my baby don’t love nobody but me” David Gries has pointed out that, from a strictly logical point of view, this implies ‘I am my baby’. pred my_baby[b: Person] { (all p: Person | b in p.loves) and b.loves = Me } assert song { all p: Person | my_baby[p] implies Me = p } + b
9
Exercise 3.5 Modeling the Tube
Station: the set of all stations JubileeStation, CentralStation, CircleStation: for each line, a subset of Station jubliee, central, circle: binary relations relating stations on each line to one another if they are directly connected sig Station {} sig JubileeStation in Station { jubilee: set JubileeStation } sig CentralStation in Station { central: set CentralStation sig CircleStation in Station { circle: set CircleStation
10
Exercise 3.5 Modeling the Tube
Stanmore, BakerStreet, Epping: singleton subsets of Station for individual stations one sig Stanmore, BakerStreet, Epping extends Station {}
11
Exercise 3.5 Modeling the Tube
(a) Named stations are on exactly the lines as shown in graphic Jubilee line Central line Circle line Stanmore in (JubileeStation - CentralStation) - CircleStation BakerStreet in (JubileeStation & CircleStation) - CentralStation Epping in (CentralStation - JubileeStation) - CircleStation
12
Exercise 3.5 Modeling the Tube
(b) No station (including those unnamed) is on all three lines Jubilee line Central line Circle line no (JubileeStation & CentralStation & CircleStation)
13
Exercise 3.5 Modeling the Tube
(c) The Circle line forms a circle Jubilee line Central line Circle line ^circle: (s1, s2), (s1, s3), …,(s1, sn), …, (sn-1, sn) all s: CircleStation { one s.circle CircleStation in s.^circle } Every station has one “next” station, including the “last” station. All stations that can be reached starting from s
14
Exercise 3.5 Modeling the Tube
(d) Jubilee is a straight line starting at Stanmore Jubilee line Central line Circle line Stanmore is the starting station, other station in Jubilee can be reached from Stanmore JubileeStation in Stanmore.*jubilee all s: JubileeStation { lone s.jubilee s not in s.^jubilee } Every station has one or zero “next” station All stations that can be reached starting from s
15
Exercise 3.5 Modeling the Tube
(e) there’s a station between Stanmore and BakerStreet Jubilee line Central line Circle line All (A, B) tuples that one can travel from A to B on Jubilee let reach = ^jubilee | some Stanmore.reach & reach.BakerStreet All stations that can be reached starting from Stanmore All stations that can reach BakerStreet
16
Exercise 3.5 Modeling the Tube
(f) It is possible to travel from BakerStreet to Epping Jubilee line Central line Circle line Epping in BakerStreet.^(jubilee + central + circle) All (A, B) tuples that one can travel from A to B All stations that can be reached starting from BakerStreet
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.