Questions tagged [hoare-logic]

Questions about Hoare's logical framework for program correctness proofs and variants.

83 questions
7
votes
1 answer

Hoare logic - total correctness of loops

Consider a while loop of the form : $\texttt{while (C) {S}}$ with $\texttt{C}$ the condition and $\texttt{S}$ the body of the loop. Let $\texttt{I}$ and $\texttt{V}$ respectively be an invariant and a variant of this loop. The rule for total…
Dory
  • 73
  • 5
6
votes
3 answers

Intuitive explanation of Hoare assignment axiom

$\small\textit{''The obvious things are the most difficult to understand''}$ May be the question does not make sense, but let me ask it anyway. The Hoare assignment axiom is $$ \dfrac{}{\{Q[v \mapsto expr]\} \;\; v:=expr \;\; \{Q\}} $$ Is there an…
Ayrat
  • 1,065
  • 1
  • 8
  • 23
2
votes
1 answer

Bottleneck in Hoare Logic unable to arrive at my {P} from {Q}

{Q} = {n>0} C1 = i := 1; C2 = c := 1; C3 = p := 0; {P} = {i<=n, p = fib(i-1), c = fib(i)} My lack of understanding towards the rule of consequence in hoare logic is blocking me from find the solution which i hope someone can shed some light on how…
Jerry Sui
  • 23
  • 3
2
votes
1 answer

Hoare logic - invariant of loop

I am trying to prove partial corectness of following program: {s = 0 and j = 0} while j <= n do begin { s + j = (j - 1)j/2 and j <= n + 1} s := s + j; { s = (j-1)j/2 and j <= n + 1} { s = j(j+1)/2 and j + 1 <= n + 1} j := j + 1; { s…
user54001
1
vote
1 answer

How to prove $c = a + b$ using Program Verification Techniques

I am trying to prove an elementary thing, but it seems at some point you get down to atoms where you can't prove anything else. This is why I am wondering about proving $c = a + b$, it seems like an atom. \begin{align} \{a, b\}\\ c = a + b\\ …
Lance
  • 2,213
  • 1
  • 17
  • 31
1
vote
1 answer

Hoare-Logic: Requirements for imperfect data types

Theoretically, Hoare-Logic let's one prove the correctness of an algorithm, given pre- and post-condition. However, as far as I've seen it so far, one idealizes his data-types to a mathematical set like $\mathbb{N}$ or $\mathbb{R}$. So, even though…
Sudix
  • 709
  • 3
  • 12
1
vote
1 answer

Hoare's Axiom Scheme Precondition

I have a question about determining preconditions for Hoare's Axiom Scheme. For example, if we have P { x=2 } x==1 and we are trying to determine the precondition, P, could we just set P as false giving us False { x=2 } x==1. I've read some of the…
1
vote
1 answer

How to determine the pre and post conditions of a program (Hoare-logic)

Problem Below is a program named X: y = 1; while(y < x){ y = 10 * y; } What does this program X do? What are appropriate pre and post conditions? (Assume that x and y are integers). My solution Given a whole number x > 1, X should give us a…
0
votes
0 answers

Why is the strongest postcondition for a program that just allocates x "exists x :: P"

I'm working my way through Leino's "Program Proofs" and I was following as far as the semantics of variable assignment, but I'm not quite sure why this is a valid Hoare triple: {forall x::Q} var x; {exists x :: P} where P is the weakest precondition…
John Gann
  • 101
  • 1
0
votes
0 answers

How to prove a segment of a program (Hoare-logic)

Problem: A segment of a program is shown below: ⋮ _ _ _ _ _ _ z = x - 7; (|z = 5 ∧ n = 4|) ⋮ What is the dashed line hiding? My solution: I think the dashed line is hiding: (|x - 7 = 5|) However, I am not sure if it is the correct solution, it…
0
votes
1 answer

How to find the loop invariant in hoare triples

Hey I am new to Hoare triples, and I can't understand on finding the loop invariants in hypothesis. For example this while loop [x>1 & y>1] WHILE x>0 DO x:=x-1; y:=y+2 END [x+y>5]. The invariant is [2x + y > 5] but I don't understand on how to find…
HelloWorld
  • 103
  • 3
-2
votes
1 answer

Use Hoare axiom for array-componenet assignment to determine the weakest pre-condition

ASSERT( P ) /* determine what is P */ A[i] = A[m]; A[k] = 2; ASSERT( A[i] == x + 5 )