Questions tagged [hoare-logic]

hoare-logic is a formal system for demonstrating the correctness of programs

What is it?

Hoare-logic is a formal system for demonstrating the correctness of programs.

It uses tripples that express a relation between a pre-condition, a command and a post-condition, and uses a set of axioms and inference rules to draw conclusions on the programme.

See also

52 questions
0
votes
1 answer

What is the loop invariant of the given program

I don't know how to find a loop invariant. I'm not sure where to start. Can anyone find the loop invariant of the given program and explain your method please. {n ≥ 0 ∧ i = 0} while i < n − 1 loop b[i] := a[i + 1]; i:=i + 1 end loop {∀j.(0 ≤ j < n −…
the_martian
  • 632
  • 1
  • 9
  • 21
0
votes
1 answer

Hoare Logic, calculate pre condition

if x < 15: x = x+1 else: x = 0 the post condition is: Q = {0 <= x <= 15} is the correct pre condition P1 = {-1 <= x} or P2 = {0 <= x <= 15} And how can I calculate it?
0
votes
1 answer

Hoare partitioning code used in Quicksort (ref Cormen book) runs into infinite loop

I code Quicksort using Hoare partitioning from the Cormen Algorithms book. I can't spot any mistakes in my code and it looks just like the pseudocode in the book. swapping i, j : 0, 8 -2 2 -5 -3 6 0 1 0 -1 4 swapping i, j : 1, 3 -2 -3 -5 2 6 0 1 0…
Joe Black
  • 625
  • 6
  • 19
0
votes
1 answer

Hoare logic proof

Give a proof that the following is correct. {n != 0} if n<0 then n= -n {n>0} The following inference rule should help {B and P} S {Q}, (not B) and P=>Q --------------------------------- {P}if B then S{Q} I have been looking all over the…
-1
votes
1 answer

Hoare's Partition original method

So I was reading the Hoare's partition part of the Quicksort wiki and it says: With respect to this original description, implementations often make minor but important variations. Notably, the scheme as presented below includes elements equal to…
-1
votes
1 answer

How to find loop invariant?

I was doing exercise about program verification, and I had some difficulties in finding this loop invariant: y = 0; while (y != x) { y = y + 1; } the precondition is x>=0 and the postcondition is x=y In the loop there is just one variable so I…
-3
votes
1 answer

How to prove that Hoare quick works for any array

Trying figure out why Hoare quick sort works correctly. Basically I can't prove to myself that we can not create an array that will cause fail for Hoare sorting algorithm. Prove not necessary to be 100% mathematics. I just want to believe that…
No Name QA
  • 724
  • 1
  • 6
  • 20
1 2 3
4