• Home
  • Queen's University
  • Software Specifications
  • Hoare Logic and Correctness in Software Specifications

Hoare Logic and Correctness in Software Specifications

CISC 223 - Assignment 4 (Winter 2024) Due: Tuesday April 2, 2:00 PM Regulations on assignments · The assignments are graded according to the correctness, preciseness and legibility of the solutions. All handwritten parts, including figures, should be clear and legible. This assignment is marked out of 30 possible marks. . Please submit your solution in onQ before the due time. The submission must be in one of formats: . PDF, .JPG, .PNG, .DOCX. · Important: Assignments are evaluated based only on the files you submit in onQ. Please be careful that you submit the correct files and please verify your submission. Any additional material sent retroactively by email cannot be considered. · The assignment must be based on individual work. Copying solutions from other students is a violation of academic integrity. See the course onQ site for more information. 1. (5 marks) What should the pre-condition P be in each of the following ten correctness statements for the statement to be an instance of Hoare's axiom scheme? All variables are of type int. (a) P { x = 2; } x == 1 (b) P { x = 2; } x > 2 (c) P { x = y + z; } x < y + z (d) P { x = x + y + z; } z > x*x + 2 (e) P { x = x + y + z; } y*y > z + 5 (f) P { x = y + z } Exists(w = 0; w < 10) x + w == 50 (g) P { x = y + z; } ForAll(z = 1; z < 100) x + 2*z > w + 2 (h) P { x = y + z; } ForAll(x = 1; x < z) x + y + 2 < 100 (i) P { x = y + z; } ForAll(y = 1; y < n) Exists(z = 1; z < n) x*y <= 3*z+w (j) P { x = y + z; } ForAll(y = 1; y < n) Exists(x = 1; x < n) x*y <= 3*z+w 2. Verify the validity of the following two correctness statements (a) and (b) by adding all the intermediate assertions, that is, give the proof tableau showing the validity of the correctness statement. All variables are of type int. Also state any mathematical facts used. (a) (2.5 marks) ASSERT( x == - 5 && y <= 7 && z == 0 ) X = x + y; y = y - x; Z = x + Z; ASSERT( y > 3 && z < 4 ) (b) (2.5 marks) ASSERT ( true ) if (x >= y) x = y - 1; else y = y + 1; z = y + 1; ASSERT ( x < y < z ) 3. (5 marks) Select a loop invariant and give a complete proof tableau (that is, add all the intermediate assertions) for the following correctness statement. Also make an