40 likes | 146 Vues
This document analyzes a specific function, SQ(A), which loops until a condition based on a positive integer A is met. It outlines the process of mathematical induction to verify that the relationship P(n) holds true for all n ≥ 0, demonstrating that Cn = A × Dn remains valid. Through a stepwise approach, beginning with base case P(0) and assuming the predicate holds for n = k, we show it also holds for n = k + 1. This ensures that the function behaves correctly as expected, indicating termination of the loop under specified conditions.
E N D
Function SQ(A) C=0 D=0 While (D A) a. C=C+A b. D=D+1 Return (A) A must be a positive integer if the looping is to end. A few trials with particulars values of A will provide evidence that the function does carry out this task.
Let P(n) be the predicate Cn=A X Dn. Our task is to prove that n 0 P(n) is true. Here n0 is 0. • Step 1: P(0) is the statement C0=A X D0, which is true since the value of both C and D is zero after zero passes through the WHILE loop. • Step 2: Assume P(k) is true : Ck =A X Dk ………(i)
Step 3: To prove Ck+1=A X Dk+1 is true. After a pass through the loop, C is increased by A and D is increased by 1, so Ck+1=Ck + A and Dk+1= Dk +1. LHS P(k+1): Ck+1= Ck + A = A X Dk + A = A (Dk +1) = A Dk+1 By MI it follows that as long as looping occurs Cn=A X Dn. The loop must terminates.