VIGGNESH_KANDASAMY_ASSINGMENT_5

VIGGNESH_KANDASAMY_ASSINGMENT_5 - SCIENCE OF PROGRAMMING...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
SCIENCE OF PROGRAMMING VIGGNESH KANDASAMY Assignment # 5 CWID:10458478 Q1. Prove partial correctness for the GCD program given in class (nested while statements). Sol: Part A Proof: {a>0 ^ b>0} (GCD(a, b)=GCD( x, y )) y x b a , , {a>0 ^ b>0} GCD(a, b)=GCD(a, b) {a>0 ^ b>0} => true Part B Proof: In the case of Part B we have three while loops. The functions of two while loops are proved to be correct in the following statements. There are two cases: first case is B11 and the second case is B12.Both these cases are evaluated. Case 1: B11 It has two parts in it {x≠y ^ GCD(a,b)=GCD(x,y) ^ x>y} x:=x-y {x≠y ^ GCD(a,b)=GCD(x,y)} ^ {x≠y ^ GCD(a,b)=GCD(x,y) ^x≤y} =>{GCD(a,b) = GCD(x,y)} Sub-Case 1: (x≠y ^ GCD(a,b)=GCD(x,y) ^ x>y) => (x≠y ^ GCD(a,b)=GCD(x,y)) x x-y (x≠y ^ GCD(a,b)=GCD(x,y) ^ x>y) =>(x-y≠y ^ GCD(a,b)=GCD(x-y,y) ) The LHS and RHS of the part 1 are true. Hence it is true Sub-Case 2: (x≠y ^ GCD(a,b)=GCD(x,y)^ x≤y) => (GCD(a,b) = GCD(x,y))
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
SCIENCE OF PROGRAMMING VIGGNESH KANDASAMY Assignment # 5 CWID:10458478 The LHS and RHS of the part 1 are true. Hence it is true Since case 1 and case 2 are true, B11 is also true Case 2: B12 It has two parts in it {GCD(a,b)=GCD(x,y) ^ x≤y ^ y>x} y:=y-x {GCD(a,b)=GCD(x,y) ^ x≤y} ^ (GCD(a,b)=GCD(x,y) ^ x≤y ^ y≤x)=>(GCD(a,b)=GCD(x,y) ^ y≤x) Sub-Case 1 GCD(a,b)=GCD(x,y) ^ x≤y ^ y>x =>(GCD(a,b)=GCD(x,y) ^ x≤y) y y-x GCD(a,b)=GCD(x,y) ^ x≤y ^ y>x=>(GCD(a,b)=GCD(x,y-x)^x≤ y-x) The LHS and RHS of the part 1 are true. Hence it is true Sub-Case2 (GCD(a,b)=GCD(x,y)^x≤y ^ y≤x)=>GCD(a,b)=GCD(x,y) ^ y≤x The LHS and RHS of the part 1 are true. Hence it is true Since case 1 and case 2 are true, B11 is also true To prove B Now to prove B as a whole The two parts(B11 and B12) are evaluated and proved to be true.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/04/2011 for the course CS 536 taught by Professor Cs536 during the Spring '08 term at Illinois Tech.

Page1 / 9

VIGGNESH_KANDASAMY_ASSINGMENT_5 - SCIENCE OF PROGRAMMING...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online