0
$\begingroup$

How could you make a proof for

SUBROUTINE COMP(X,Y:Z)

  1. Z <- X

  2. W <- Y

  3. While(W > 0)

    a. Z <- Z+Y

    b. W <- W - 1

  4. Return

END OF SUBROUTINE DIFF

COMPUTES: Z = X + Y^2

LOOP INVARIANT: (Y + W) + Z = X + Y^2

All variables represent non negative integers.

  • 1
    what are we proving here?2017-02-08
  • 0
    Proving the relationship indicated as a loop invariant2017-02-08
  • 0
    Difficult, since $X-Y$ is clearly not what it computes.2017-02-08
  • 0
    Wow, I made a typo, my bad.2017-02-08

0 Answers 0