Results 1 to 2 of 2

Math Help - Program Correctness Problem

  1. #1
    Newbie
    Joined
    Mar 2009
    Posts
    6

    Program Correctness Problem

    *** It's not necessarily that this problem is overly difficult but I was just wondering if anyone could help show the clear and correct way to solve this by use of a loop invariant and induction.***

    *Use induction to prove the following program to compute x*y is correct given the initial assertion that x is a non-negative integer and the final asseration that the value returned from mult(x,y) is x*y.

    procedure mult(x,y)

    if(x==0) then return 0
    else return y + mult(x-1, y)
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Member
    Joined
    Jan 2009
    Posts
    108
    Quote Originally Posted by fusion1455 View Post
    *** It's not necessarily that this problem is overly difficult but I was just wondering if anyone could help show the clear and correct way to solve this by use of a loop invariant and induction.***

    *Use induction to prove the following program to compute x*y is correct given the initial assertion that x is a non-negative integer and the final asseration that the value returned from mult(x,y) is x*y.

    procedure mult(x,y)

    if(x==0) then return 0
    else return y + mult(x-1, y)
    base case: x=0

    the procedure returns 0 which is indeed x*y

    inductive step: pass x+1,y

    as x+1 is not 0, follow the else statement. return y plus whatever mult(x+1-1,y) returns. the nested mult() returns 0 so the parent procedure returns y which is y greater than what x*y returned in the base case.
    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, 01:12 PM
  2. Check derivtives for correctness
    Posted in the Calculus Forum
    Replies: 5
    Last Post: January 16th 2011, 12:09 PM
  3. Correctness
    Posted in the Discrete Math Forum
    Replies: 2
    Last Post: September 27th 2009, 09:15 AM
  4. Fixing The Program (Program Correctness)
    Posted in the Discrete Math Forum
    Replies: 2
    Last Post: March 21st 2009, 02:17 PM
  5. Program Correctness Proof
    Posted in the Math Topics Forum
    Replies: 1
    Last Post: February 24th 2009, 10:12 PM

Search Tags


/mathhelpforum @mathhelpforum