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
1
vote
1 answer

Hoare Triples - Weakest Precondition / Strongest Postcondition

Is this correct, for weakest pre-condition respectively strongest post-condition? {P} x = x-x; {x'=x} P: x = 0 {true} y = y-y; {Q} Q: y = 0 Edit: I started by applying this as follows: {true} y = y - y {Q} ==> sp(y = y-y; true) = ∃x,y = x-x ∧…
user452306
  • 139
  • 4
  • 9
1
vote
1 answer

How to prove an iterative loop with computations in frama-c wp?

I have my test code (to study the WP loop invariants) which adds two long integers with each digit's representation in an array cell: int main(int argc, const char * argv[]) { char a[32], b[32];//size can be very big memset(a, 0,…
SeregASM
  • 75
  • 12
1
vote
1 answer

Which hoare-triples is correct?

Lets say there is a method that takes two arguments balance and price, that only does the following: if(price < balance) { balance = balance - price; } I feel like there are two possible ways to write this in a hoare-triple: (| price=p0 ^…
Ferus
  • 1,080
  • 3
  • 12
  • 17
1
vote
0 answers

Write a loop invariant for partial correctness of Hoare Triple

I am new to the world of logic. I am learning Hoare Logic and Partial & Total correctness of programs. I tried alot to solve the below question but failed. Write a loop invariant P to show partial correctness for the Hoare triple {x = ¬x ∧ y = ¬y…
Ajmal Razeel
  • 1,663
  • 7
  • 27
  • 51
1
vote
1 answer

Loop invariant Hoare Logic

I have a program, where I should find a loop invariant and then provide a proof. {x>=0 && y>=0} // precondition res:=0; i:=0; while (i
nlimits
  • 103
  • 1
  • 12
1
vote
0 answers

Hoare Logic for Repeat Until

How can we prove a program in repeat until using Hoare Logic? I've found a rule like this: {P} S {R}, {R ^ ~B -> P}, {R ^ B -> Q} For {P} repeat S until B {Q} But I still can't find any explanatiom how I can use this rule For example in this…
1
vote
1 answer

Hoare triple with unknown variable in postcondition

I am reasoning about an Hoare Logic's exercise. I should find all the boolean expressions B and all the programs S and P which satisfy the triple {true} if B then S; if B then P; {a >= 0}, assuming that the evaluation of B cannot modify the store,…
childerico
  • 89
  • 6
0
votes
0 answers

Term for statements with vacuous weakest precondition

It seems like the class of statement, postcondition pairs (S, R) such that the weakest precondition wp(S, R) is true is a particularly interesting one (being in some sense “always” true). Is there a term for this set or property?
user2141650
  • 2,827
  • 1
  • 15
  • 23
0
votes
1 answer

Invariant for Hoare-Logic on RandomSearch

I'm trying to proof the following RandomSeach-Algorithm and to figure out the invariant for the loop. Since the function randomIndex(..) creates a random number I cannot use an invariant like ≥ 0 ∧ < − 1 ⇒ [] ≠ e . That means, all elements…
Schrello
  • 27
  • 5
0
votes
1 answer

How to resolve a contradiction using Hoare-Logic in LinearSearch

I'm trying to proof the following LinearSearch using the Hoare-Logic, but I get a contradiction proofing (1) => (2). I belive that my invariant should be different. Currently I'm using {s ≥ 0 & s < i → f[s] ≠ value} as invariant. That means all…
Schrello
  • 27
  • 5
0
votes
1 answer

solving quantifier-free VC using z3

I was reading this research paper: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.365.9467&rep=rep1&type=pdf So, in summary, they are transforming the quantified horn clauses to quantifier-free horn clauses by instantiation (via…
user8616916
  • 73
  • 1
  • 7
0
votes
2 answers

is this loop invariant and post condition correct?

I was trying to write a loop invariant and post condition for this code: sum = 0; for (i = 0; i < 10; ++i) ++sum; sum = 10 is the obvious post condition here. But a friend told me that i = sum is also a loop invariant and sum = 12 is also a post…
JRR
  • 6,014
  • 6
  • 39
  • 59
0
votes
1 answer

Program Correctness, Invariants and Predicate Logic for selection sort

I'm trying to prove the correctness of the Selection sort, in which I should use only the mathematical predicate logic to prove program correctness, I'm finding it difficult to write the English statements given below as Predicates and proceed…
Akash Tadwai
  • 100
  • 1
  • 9
0
votes
2 answers

Encountering an infinite loop in quicksort(hoare), but I don't seem to find the issue

So, I wrote a quicksort algorythm and a hoare-partition algorythm. Somehow when I try to run the example case in main (), it hangs up on quickSort(test, 0,3). There seems to be an infinite loop. I don't see how to fix it, since the two functions…