0% found this document useful (0 votes)
17 views8 pages

Formal Method Detailed Assignment

Formal Method detailed Assignment

Uploaded by

9qnqghw66p
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views8 pages

Formal Method Detailed Assignment

Formal Method detailed Assignment

Uploaded by

9qnqghw66p
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Assignment no 3

Submitted By:
Name: Moneeb Mushtaq
Roll No: 07
Subject: Formal Method
Department: BS-SE 5th
Session: 2021-2025

Submitted to: Khurram Mustafa

Due Date: 06-03-2024

University Of Kotli AJ&K


1. Exercise No 1

• Load academia-1.als.
• Realism Conditions and Default Scopes
• Model Under constrained.
• Check Assertions:
• Verify any assertions present in the model.

The Code:
-- Signatures --
abstract sig Person {}
sig Faculty extends Person {}
abstract sig Student extends Person {}
sig Graduate, Undergrad extends Student {}
sig Instructor in Person {}
sig Course {
taughtby: one Instructor,
enrolled: some Student,
waitlist: set Student}

-- Fact --
fact {
-- All instructors are either Faculty or Graduate Students
all i: Instructor | i in Faculty + Graduate
-- No one is waiting for a course unless someone is enrolled
all c: Course | some c.waitlist => some c.enrolled
-- Graduate students do not teach courses they are enrolled in
-- or waiting to enroll in
all c: Course | c.taughtby !in c.enrolled + c.waitlist
}
-- Realism Constraints
pred RealismConstraints [] {
-- There is a graduate student who is an instructor
some Graduate & Instructor
-- There are at least two courses
#Course >= 2

-- There are at least three undergraduates


#Undergrad > 2}
run RealismConstraints -- for 4

-- Assertions
assert NoWaitingTeacher {
all c: Course | no (c.taughtby & c.waitlist)}
check NoWaitingTeacher for 10
assert NoEnrolledAndWaiting {
all c: Course | no (c.enrolled & c.waitlist)}
check NoEnrolledAndWaiting for 10

2. Exercise 2
• Load academia-2.als.
• Realism Conditions and Default Scopes:
• Model Under constrained.
• Examine various sample instances.
Code:

---------------- Signatures ----------------


abstract sig Person {}
sig Faculty extends Person {}
abstract sig Student extends Person {
id: one Id,
transcript: set Course}
sig Graduate, Undergrad extends Student {}
sig Instructor in Person {}
sig Course {
taughtby: one Instructor,
enrolled: some Student,
waitlist: set Student,
prerequisites: set Course}
sig Id {}
---------------- Fact ----------------
fact {
-- All instructors are either Faculty or Graduate Students
all i: Instructor | i in Faculty+Graduate
-- No one is waiting for a course unless someone is enrolled
all c: Course | some c.waitlist => some c.enrolled
-- Graduate students do not teach courses they are enrolled in
-- or wainting to enroll in
all c: Course | c.taughtby !in c.enrolled + c.waitlist
-- No student is enrolled and on the waitlist for the same course
all c: Course | no (c.enrolled & c.waitlist)
-- No two distinct students have the same ID
all s1, s2: Student | s1 != s2 => s1.id != s2.id
-- A student can only have a course for which they have the prerequisites
all s: Student | s.transcript.prerequisites in s.transcript
-- There are no cycles in the prerequisite dependencies
all c: Course | c !in c.^prerequisites}
------------------- Run ---------------------
pred RealismConstraints [] {
-- There is a graduate student who is an instructor
some Graduate & Instructor
-- There are at least two courses
#Course >= 2
-- There are at least three undergraduates
#Undergrad > 2}
run RealismConstraints for 4
---------------- Assertion ----------------
-- No instructor is on the waitlist for a course that he/she teaches
assert NoWaitingTeacher {
all c: Course | no (c.taughtby & c.waitlist)}
check NoWaitingTeacher for 10
-- A student can only wait to be in a course for which they have the prerequisites
assert AllWaitsHavePrereqs {
all s: Student | (waitlist.s).prerequisites in s.transcript}
check AllWaitsHavePrereqs

3. The executed code and the instance created in alloy family 3.


• Load academia-3.als
• Realism Conditions and Default Scopes
• Manipulating Scopes:
• Additional Questions:

Code:
---------------- Signatures ----------------
abstract sig Person {}
sig Faculty extends Person {}
abstract sig Student extends Person {}
sig Graduate, Undergrad extends Student {}
sig Instructor in Person {}
sig Course {
taughtby: one Instructor,
enrolled: some Student,
waitlist: set Student}
fun teaches : Instructor -> Course { ~taughtby }

---------------- Fact ----------------


fact {
-- All instructors are either Faculty or Graduate Students
all i: Instructor | i in Faculty+Graduate
-- No one is waiting for a course unless someone is enrolled
all c: Course | some c.waitlist => some c.enrolled

-- Graduate students do not teach courses they are enrolled in


-- or wainting to enroll in
all c: Course | c.taughtby !in c.enrolled + c.waitlist}

------------------- Run ---------------------


pred RealismConstraints [] {
-- There is a graduate student who is an instructor
some Graduate & Instructor
-- There are at least two courses
#Course >= 2
-- There are at least three undergraduates
#Undergrad > 2}
run RealismConstraints for 4

---------------- Assertion ----------------


-- Note: to check the assertion below you must comment the run command
-- above first (similarly for the second check)
-- No instructor is on the waitlist for a course that he/she teaches
assert NoWaitingTeacher {
all c: Course | no (c.taughtby & c.waitlist)
}-- check NoWaitingTeacher for 10

-- No student is enrolled and on the waitlist for the same course


fact NoEnrolledAndWaiting {
all c: Course | no (c.enrolled & c.waitlist)}
-- check NoEnrolledAndWaiting for 10

You might also like