Alex L.

asked • 06/03/22

Hoare Logic inference

which corresponds to the series 0+1+2+3+ … +n with 0 being the 0th triangular number, 1 being the 1st, 3 being the 2nd, 6 being the 4th and so on. Prove the program is correct using Hoare logic inference rules (precondition and postcondition have been given).

{n>=0}

x := n;

z := 0;

WHILE (x!=0) {

z := z+x;

x := x-1;

}

{z*2=n*(n+1)}


note Start by identifying the loop invariant then apply Hoare logic inference rules

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.