Question: ( * * * * Exercise: Two Loops * ) ( * * * * * * Exercise: 3 stars, standard ( two _ loops

(**** Exercise: Two Loops *)
(****** Exercise: 3 stars, standard (two_loops)
Here is a pretty inefficient way of adding 3 numbers:
X :=0;
Y :=0;
Z := c;
while X <> a do
X := X +1;
Z := Z +1
end;
while Y <> b do
Y := Y +1;
Z := Z +1
end
Show that it does what it should by completing the
following decorated program.
*)
Definition two_loops_dec (a b c : nat) : decorated :=
<{
{{ True }}->>
{{ FILL_IN_HERE }}
X :=0
{{ FILL_IN_HERE }};
Y :=0
{{ FILL_IN_HERE }};
Z := c
{{ FILL_IN_HERE }};
while X <> a do
{{ FILL_IN_HERE }}->>
{{ FILL_IN_HERE }}
X := X +1
{{ FILL_IN_HERE }};
Z := Z +1
{{ FILL_IN_HERE }}
end
{{ FILL_IN_HERE }}->>
{{ FILL_IN_HERE }};
while Y <> b do
{{ FILL_IN_HERE }}->>
{{ FILL_IN_HERE }}
Y := Y +1
{{ FILL_IN_HERE }};
Z := Z +1
{{ FILL_IN_HERE }}
end
{{ FILL_IN_HERE }}->>
{{ Z = a + b + c }}
}>.
Theorem two_loops : forall a b c,
outer_triple_valid (two_loops_dec a b c).
Proof.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!