Question

2. (8 points) A sequence of statements is listed below: b = (a+4)/2 c=2* b-5 d = 3*c+ 7 {d>4} calculate the weakest precondit
0 0
Add a comment Improve this question Transcribed image text
Answer #1

b=(a+4)/2

c=2*b-5

d=3*c+7

Substitute the right hand side of the d=3*c+7  in the postcondition given(d>=4) to get a postcondition for the assignment (c=2*b+5)  then substitute the right hand side of the assignment(c=2*b+5) in that postcondition to get the precondition

Repeat this for every statement in the sequence.The final precondition is the weakest precondition for the sequence.

substitute  d>=4 we get

3*c+7>=4

=>3*c>=-3

=>c>=-1

substitute c>=-1

=>2*b-5>=-1

=>2*b>=4

=>b>=2

now substitute b>=2

(a+4)/2>=2

a+4>=4

a>=0

hence preconditions of each statements are

b=(a+4)/2=>{a>=0}

{b>=2}

c=2*b-5

{c>=-1}

d=3*c+7

{d>=4}

Therefore the weakest precondition of the total sequence is a>=0

if u understand this upvote else post a comment

Add a comment
Know the answer?
Add Answer to:
2. (8 points) A sequence of statements is listed below: b = (a+4)/2 c=2* b-5 d...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT