Вы находитесь на странице: 1из 1

Exercise 5 Axiomatic Semantics

1. Show that the following program is correct {x = X and y = Y} t := x; x := y; y := t; {x = Y and y := X} 2. Prove that the following program is correct: {true} if x > 0 then x := x else x := 0 x {x 0} 3. Show the correctness of the following program: {n > 0} while n > 0 do n := n 1 {n = 0} 4. Prove that the following program is totally correct: {n > 0} i := n; sum := 0; while i > 0 do begin sum := sum + i; i := i 1 end {sum = 1 + 2 + ... + n} 5. Write a program that computes the product of two numbers n and m by repeatedly adding n m-times. Prove that your program is correct. 6. Prove the partial correctness of the following program: {true} i := 1; while a[i] x do i := i + 1 {a[i] = x (j: j 1 a[j] = x i j)}

Вам также может понравиться