{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

VIGGNESH_KANDASAMY_ASSINGMENT_5

# VIGGNESH_KANDASAMY_ASSINGMENT_5 - SCIENCE OF PROGRAMMING...

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

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))

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

View Full Document
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.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern