Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 3 ( 1 8 pts . ) : Loopy square root Below we give, in Dafny syntax, the square root method which should be

Problem 3(18 pts.): Loopy square root
Below we give, in Dafny syntax, the square root method which should be computing the square root of a number.a) Test this code by creating the Main() method and calling loopysqrt() with arguments like 4,25,30, etc. to convince yourself that this algorithm appears to be working correctly. In your answer, describe your tests and the corresponding output. (2 pts.)b) Yet, the code given above fails to verify with Dafny. One of the reasons for this is that it is actually incorrect. More specifically, this code may produce the result which does not comply with the specification. Write a test (or tests) that reveals the bug. In your answer, describe your test(s), the corresponding outputs, and the bug that you found. Also, indicate which part of the specification is violated. (2 pts.)c) Now, make this code correct by changing the precondition. In your answer, describe the change and show the output of the re-run of the same tests you ran before. (2 pts.)d) Does your Dafny code verify now? Why or why not? If it doesn't verify, does it mean that your code still has bugs in it?(2 pts.)e) If your Dafny code doesn't verify, uncomment invariant and/or decreases annotations and supply the actual invariant and/or decrementing function. Make sure your code now verifies. In your answer, describe how you guessed the invariant and/or the decrementing function. Explain why your code was failing Dafny verification earlier but does verify now, despite the fact that you have not made any changes to your actual code (annotations are not part of the code).(2 pts.)f) Submit your final Dafny code. (2 pts., autograded)g) Use computational induction to prove by hand the total correctness of the final version of your Dafny code. (6 pts.)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions

Question

3. Are our bosses always right? If not, what should we do?

Answered: 1 week ago

Question

2. What, according to Sergey, was strange at this meeting?

Answered: 1 week ago