Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ch. 8 bubblesort exercise & ch. 9 exercises. #19

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions Lab08/students-proposal/Parmeggiani/bubblesort_dp.smv
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
MODULE main
VAR
arr: array 0..4 of 1..5;
swapped: boolean;
i: 0..4;
pc: 1..7;

ASSIGN
init(arr[0]) := 4;
init(arr[1]) := 1;
init(arr[2]) := 3;
init(arr[3]) := 2;
init(arr[4]) := 5;
init(pc) := 2;
init(i) := 0;

next(pc) :=
case
pc=1 & swapped: 2;
pc=1: 7;
pc=2: 3;
pc=3 & i < 4: 4;
pc=3: 1;
-- pc=4 & i=0 & arr[i - 1] > arr[i]: 5;
pc=4 & i=1 & arr[0] > arr[1]: 5;
pc=4 & i=2 & arr[1] > arr[2]: 5;
pc=4 & i=3 & arr[2] > arr[3]: 5;
pc=4 & i=4 & arr[3] > arr[4]: 5;
pc=4: 3;
pc=5: 6;
pc=6: 3;
pc=7: 7;
esac;

next(swapped) :=
case
pc=2: FALSE;
pc=6: TRUE;
TRUE: swapped;
esac;

next(i) :=
case
pc=3 & i=0: 1;
pc=3 & i=1: 2;
pc=3 & i=2: 3;
pc=3 & i=3: 4;
pc=3 & i=4: 0;
TRUE: i;
esac;

next(arr[0]) :=
case
-- pc=5 & i=0: arr[0 - 1];
pc=5 & i=1: arr[1];
TRUE: arr[0];
esac;
next(arr[1]) :=
case
pc=5 & i=1: arr[0];
pc=5 & i=2: arr[2];
TRUE: arr[1];
esac;
next(arr[2]) :=
case
pc=5 & i=2: arr[1];
pc=5 & i=3: arr[3];
TRUE: arr[2];
esac;
next(arr[3]) :=
case
pc=5 & i=3: arr[2];
pc=5 & i=4: arr[4];
TRUE: arr[3];
esac;
next(arr[4]) :=
case
pc=5 & i=4: arr[3];
-- pc=5 & i=5: arr[4 + 1];
TRUE: arr[4];
esac;


LTLSPEC !F(G(pc=7)) -- the program ends (does not go in loop pc=7)

LTLSPEC !(F(
arr[0] = 1 &
arr[1] = 2 &
arr[2] = 3 &
arr[3] = 4 &
arr[4] = 5 &
pc = 7
) & (F(G(pc=7)))) -- not (the program loops in pc=7 with a sorted array)
111 changes: 111 additions & 0 deletions Lab09/students-proposals/Parmeggiani/ferryman4.smv
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
MODULE main
VAR
-- the man and the three items
fox : {right,left};
chicken : {right,left};
caterpillar : {right,left};
lettuce : {right,left};
man : {right,left};
-- possible moves
move : {f, c, t, l, e};

DEFINE
carry_fox := move=f;
carry_chicken := move=c;
carry_caterpillar := move=t;
carry_lettuce := move=l;
no_carry := move=e;

ASSIGN
init(fox) := right;
init(chicken) := right;
init(caterpillar) := right;
init(lettuce) := right;
init(man) := right;

init(move) := {f, c, t, l, e};


TRANS
next(man) != next(fox) -> next(move) != f
TRANS
next(man) != next(chicken) -> next(move) != c
TRANS
next(man) != next(caterpillar) -> next(move) != t
TRANS
next(man) != next(lettuce) -> next(move) != l

TRANS
carry_fox -> (
next(man) != man &
next(fox) != fox &
next(chicken) = chicken &
next(caterpillar) = caterpillar &
next(lettuce) = lettuce
)
TRANS
carry_chicken -> (
next(man) != man &
next(chicken) != chicken &
next(fox) = fox &
next(caterpillar) = caterpillar &
next(lettuce) = lettuce
)
TRANS
carry_caterpillar -> (
next(man) != man &
next(caterpillar) != caterpillar &
next(fox) = fox &
next(chicken) = chicken &
next(lettuce) = lettuce
)
TRANS
carry_lettuce -> (
next(man) != man &
next(lettuce) != lettuce &
next(fox) = fox &
next(chicken) = chicken &
next(caterpillar) = caterpillar
)
TRANS
no_carry -> (
next(man) != man &
next(lettuce) = lettuce &
next(fox) = fox &
next(chicken) = chicken &
next(caterpillar) = caterpillar
)

INVAR
(fox = chicken | chicken = caterpillar) -> chicken = man
INVAR
(chicken = caterpillar | caterpillar = lettuce) -> caterpillar = man

DEFINE
goal := fox = left &
chicken = left &
caterpillar = left &
lettuce = left;

CTLSPEC !EF goal
CTLSPEC EF goal

-- how come they both are true?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

-- nuXmv > check_ltlspec
-- specification !( F goal) is true
-- specification F goal is true
-- i am so confused

-- nuXmv > check_ctlspec
--******** WARNING ********
--Fair states set of the finite state machine is empty.
--This might make results of model checking not trustable.
--******** END WARNING ********
-- specification !(EF goal) is true
--******** WARNING ********
--Fair states set of the finite state machine is empty.
--This might make results of model checking not trustable.
--******** END WARNING ********
-- specification EF goal is true

-- more confusion
123 changes: 123 additions & 0 deletions Lab09/students-proposals/Parmeggiani/hanoi5.smv
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
MODULE main
VAR
d1 : {left,middle,right}; -- smallest
d2 : {left,middle,right};
d3 : {left,middle,right};
d4 : {left,middle,right};
d5 : {left,middle,right}; -- largest
move : 1..5; -- possible moves

DEFINE
move_d1 := move=1;
move_d2 := move=2;
move_d3 := move=3;
move_d4 := move=4;
move_d5 := move=5;

-- di is clear iff it can move to a different pole
clear_d1 := TRUE;

clear_d2 := d2!=d1;
clear_d3 := d3!=d1 & d3!=d2;
clear_d4 := d4!=d1 & d4!=d2 & d4!=d3;
clear_d5 := d5!=d1 & d5!=d2 & d5!=d3 & d5!=d4;

-- initially all items are on the left pole
INIT
d1 = left &
d2 = left &
d3 = left &
d4 = left &
d5 = left & move = 1;

TRANS
(next(clear_d3) = FALSE) -> (next(move) != 3)

TRANS
(next(clear_d2) = FALSE) -> (next(move) != 2)

TRANS
(next(clear_d1) = FALSE) -> (next(move) != 1)

TRANS
(next(clear_d4) = FALSE) -> (next(move) != 4)

TRANS
(next(clear_d5) = FALSE) -> (next(move) != 5)

TRANS
move_d1 ->
next(d1) != d1 &
next(d2) = d2 &
next(d3) = d3 &
next(d4) = d4 &
next(d5) = d5

TRANS
move_d2 ->
next(d1) = d1 &
next(d2) != d2 &
next(d3) = d3 &
next(d4) = d4 &
next(d5) = d5 &
next(d2) != d1

TRANS
move_d3 ->
next(d1) = d1 &
next(d2) = d2 &
next(d3) != d3 &
next(d4) = d4 &
next(d5) = d5 &
next(d3) != d1 &
next(d3) != d2

TRANS
move_d4 ->
next(d1) = d1 &
next(d2) = d2 &
next(d3) = d3 &
next(d5) = d5 &
next(d4) != d4 &
next(d4) != d1 &
next(d4) != d2 &
next(d4) != d3

TRANS
move_d5 ->
next(d1) = d1 &
next(d2) = d2 &
next(d3) = d3 &
next(d4) = d4 &
next(d5) != d5 &
next(d5) != d4 &
next(d5) != d1 &
next(d5) != d2 &
next(d5) != d3

TRANS
(next(clear_d1) & next(clear_d2) & next(clear_d3)) -> next(move) != 3
TRANS
(next(clear_d1) & next(clear_d2) & next(clear_d4)) -> next(move) != 4
TRANS
(next(clear_d1) & next(clear_d2) & next(clear_d5)) -> next(move) != 5
TRANS
(next(clear_d1) & next(clear_d3) & next(clear_d4)) -> next(move) != 4
TRANS
(next(clear_d1) & next(clear_d3) & next(clear_d5)) -> next(move) != 5
TRANS
(next(clear_d1) & next(clear_d4) & next(clear_d5)) -> next(move) != 5
TRANS
(next(clear_d2) & next(clear_d3) & next(clear_d4)) -> next(move) != 4
TRANS
(next(clear_d2) & next(clear_d3) & next(clear_d5)) -> next(move) != 5
TRANS
(next(clear_d2) & next(clear_d4) & next(clear_d5)) -> next(move) != 5
TRANS
(next(clear_d3) & next(clear_d4) & next(clear_d5)) -> next(move) != 5



-- spec to find a solution to the problem
LTLSPEC
! F(d1=right & d2=right & d3=right & d4=right & d5=right)
Loading