Identify and state a suitable variant for the loop

Assignment Help Theory of Computation
Reference no: EM132139350

Question 1

Hoare Logic Semantics

For each of the parts below, justify your answer briefly.
1. For which programs S does {False} S {True} hold?
2. For which programs S does {True} S {False} hold?
3. For which programs S does [True] S [True] hold?

Question 2

Doubling Numbers

The following piece of code is called Half:
x := 0;
y := 0;
while (x < a)
x := x + 2; y := y + 1;

We wish to use Hoare Logic to show that:

{True} Half {x = 2 ∗ y}

In the questions below (and your answers), we may refer to the loop code as Loop, the body of the loop (i.e. x:=x+2;y:=y+1;) as Body, and the initialisation assignments (i.e. x:=0;y:=0;) as Init.

1. Given the desired postcondition {x = 2 ∗ y}, what is a suitable invariant for Loop? (Hint: notice that the postcondition is independent of the value of a.)

2. Prove that your answer to the previous question is indeed a loop invariant. That is, if we call your invariant P , show that {P } Body {P }. Be sure to properly justify each step of your proof.

3. Using the previous result and some more proof steps show that

{True} Half {x = 2 ∗ y}
Be sure to properly justify each step of your proof.

4. To prove total correctness of the program Half, identify and state a suitable variant for the loop. Using the same invariant P as above, the variant E should have the following two properties:

- it should be ≥ 0 when the loop is entered, i.e. P ∧ (x < a) → E ≥ 0
- it should decrease every time the loop body is executed, i.e. [P ∧ (x < a) ∧ E = k] Body [P ∧ E < k] 1

You just need to state the variant, and do not need to prove the two bullet points above (yet).

5. For the variant E you have identified above, give a proof of the premise of the while-rule for total correctness, i.e. give a Hoare-logic proof of [P ∧ (x < a) ∧ E = k] Body [P ∧ E < k] and argue that P ∧ (x < a) → E ≥ 0.

Question 3

Counting Modulo 7

Consider the following code fragment that we refer to as Count below, and we refer to the body of the loop (i.e. the two assignments together with the if-statement) as Body.

while (y < n)
y := y + 1; x := x + 1;
if (x = 7) then x := 0 else x := x

The goal of the exercise is to show that {x < 7}Count{x < 7}

1. Given the desired postcondition, what is a suitable invariant P for the loop? You just need to state the invariant.

2. Give a Hoare Logic proof of the fact that your invariant above is indeed an invariant, i.e. prove the Hoare-triple {P }Body{P }.

3. Hence, or otherwise, give a Hoare-logic proof of the triple {x < 7}Count{x < 7}.

4. Give an example of a precondition P so that the Hoare-triple {P }Count{x < 7} does not hold and justify your answer briefly.

Attachment:- Appendix.rar

Reference no: EM132139350

Questions Cloud

Write two relational algebra expressions : IT244 nderline the appropriate primary keys/foreign keys in the above relations. Write two relational algebra expressions that retrieve.
Should you trust a 3rd-party vendor to handle your backups : Should you trust a 3rd-party Vendor to handle your backups (cloud), or should you do it yourself in-house (on premises)? Why?
How many transactions in this market basket : ITS-632: What items represent Itemset (I)? How many transactions in this market basket? What is the support? What is the confidence?
Calculate increase or decrease in monthly operating income : Question - Calculate the increase or decrease in Boundaries' monthly operating income during 20x5 if the mall store is closed
Identify and state a suitable variant for the loop : Prove that your answer to the previous question is indeed a loop invariant. That is, if we call your invariant P , show that {P } Body {P }
International business environment : Share an example of an ethical dilemma that can occur within the international business environment. Do not repeat examples from the textbook.
Theories of international trade and investment : Articulate the theories of international trade and investment . Give an example of one of the theories.
What is your reaction to harriets suggestion of using debt : Based on the materials presented in the "Risk and Return" video, present a discussion on why the materials are important in financial decision making.
What are the responsibilities of the internal auditors : CASE STUDY - FINANCIAL REPORT ANALYSIS - What are the responsibilities of the Internal Auditors? Have you identify any problem with this company

Reviews

Write a Review

Theory of Computation Questions & Answers

  Design a set of gui interfaces

Design a set of GUI interfaces that support the functional requirements and workflow identified for the use case Pickup Package

  Write a vhdl module to implement an 8-bit serial-in

When En = 1, at the rising edge of the clock, the register shifts right if R = 1or left if R = o.RSI should be the shift-in input if R = 1, and LSI should be the shift-in input if R = o. When En = o, the register holds its state.There should also ..

  Compare and contrast mealy and moore machines

What properties of formal languages would you use (and how) to formally prove that there is no NFA that can accept the language L(M). Explain briefly and show formally, by resorting to problem reduction, that the problem, of deciding whether a Tur..

  Formulate the corresponding coffee-machine decision problem

meeting rooms on university campuses may or may not contain coffee machines. we would like to ensure that every meeting

  Disign a fenite state machine

DISIGN A FENITE STATE MACHINE TO DETECT THE SEQUENCE 10110

  Describe the behavior of the turing machine

For questions 3 to 5, remember that a Turing machine starts in state 1, reading the leftmost nonblank cell.

  Prove the inference rules for functional dependencies

A proof should be made by using the reflexive, augmentation, transitive, decomposition, union, and pseudotransitive rules.

  Derive a contradiction

State your assumptions for a proof by contradiction - Derive a contradiction.

  In an internet retailer you will find a wide range of job

in an internet retailer you will find a wide range of job functions. leaders frequently need to adjust their own

  Create a program that makes an object

Create a class named Pet, after creating the class, create a program that makes an object of the class and prompts the user to enter the name, type, and age of his pet.

  How to express correctness properties in ltl

Express the given correctness properties in LTL. Defne propositions/variables to model the events mentioned in the question. If a parent process calls the blocking waitpid() system call then it is blocked until child process terminates.

  Why are there so many laws relating to hrm practices which

why are there so many laws relating to hrm practices? which are the most important laws in your opinion?what

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd