Results 1 to 2 of 2

Math Help - Program Correctness Proof

  1. #1
    Junior Member
    Joined
    Feb 2009
    Posts
    57

    Program Correctness Proof

    Can someone please help!!
    Prove the following program is correct:
    {n > 0}
    count = n;
    sum = 0;
    while count <> 0 do
    sum = sum + count;
    count = count 1;
    end
    {sum = 1 + 2 + + n}
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor
    Grandad's Avatar
    Joined
    Dec 2008
    From
    South Coast of England
    Posts
    2,570
    Thanks
    1

    Program proof

    Hello vexiked
    Quote Originally Posted by vexiked View Post
    Can someone please help!!
    Prove the following program is correct:
    {n > 0}
    count = n;
    sum = 0;
    while count <> 0 do
    sum = sum + count;
    count = count 1;
    end
    {sum = 1 + 2 + + n}
    I'm assuming that you're writing this in pseudocode, rather than any specific language. Then it will work OK, provided the end statement is the usual one that you use to end the while loop. Some writers might prefer to use something like end while or end do here.

    The other small point is that I notice that you've written each statement (except this one and the while statement) ending with a semi-colon. Whereas I wouldn't expect one at the end of the while line, I might have expected one after end. Was that deliberate or did you forget one here? Otherwise, it's fine.

    Grandad
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Proving NFA Correctness
    Posted in the Discrete Math Forum
    Replies: 1
    Last Post: May 3rd 2011, 02:12 PM
  2. Correctness
    Posted in the Discrete Math Forum
    Replies: 2
    Last Post: September 27th 2009, 10:15 AM
  3. Fixing The Program (Program Correctness)
    Posted in the Discrete Math Forum
    Replies: 2
    Last Post: March 21st 2009, 03:17 PM
  4. Program Correctness Problem
    Posted in the Discrete Math Forum
    Replies: 1
    Last Post: March 18th 2009, 07:07 PM
  5. Correctness of a sample function
    Posted in the Math Topics Forum
    Replies: 1
    Last Post: June 25th 2006, 12:32 PM

Search Tags


/mathhelpforum @mathhelpforum