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
2
votes
0 answers

Hoare Logic Loop variant on user specified value

I have the following problem: pre-condition is True int n = askUser(); int i = 0; while(i
user3603634
  • 95
  • 2
  • 11
2
votes
1 answer

Can we design inference rules about separation logic in Z3 and use it to proof some props automatically?

Can we design inference rules and axioms about separation logic in z3 and use it to proof some props automatically? For example," x=y /\ (x |-> z) |- x=y /\ (y |-> z)"
lgbo
  • 221
  • 3
  • 14
2
votes
1 answer

Proving correctness of algorithm

I was wondering if anyone could help me answer this question. It is from a previous exam paper and I could do with knowing the answer ready for this years exam. This question seems so simple that I am getting completely lost, what exactly is it…
1
vote
1 answer

Proving correctness and termination of an (imperative) algorithm using Isabelle

I'm an undergraduate student trying to prove correctness and termination of imperative version of Euclidean gcd and Euclidean extended gcd algorithm. I used IMP language to implement the first one and Hoare logic to prove correctness and…
Hamed
  • 13
  • 3
1
vote
1 answer

Validity of Hoare triple with unknown variable in program and post-condition?

I'm unsure about the value of x in this Hoare triple: { a = 0 } while (x > a) do (x := x − 1) { x = 0 }. I have 2 potential ideas for how to prove whether this Hoare triple is valid or not: Assuming x is 0, the Hoare triple is valid, or Assuming x…
1
vote
1 answer

Using Hoare-Rules to show PRECONDITION implies POSTCONDITION in a simple program (just 2 assignments)

Using the Hoare-Rules I want to show that I can imply {x >= 0} --> {a + y = x} PROGRAMM // PRECONDITION {x >= 0} a = x; y = 0; // POSTCONDITION {a + y = x} Using the assignment rules I get // PRECONDITION {x >= 0} {x + 0 = x} // assignment…
knowledge
  • 941
  • 1
  • 11
  • 26
1
vote
0 answers

Finding out the correctness of a "while-loop" using hoare-logic

I currently am struggling to figure out, how to show that a program, which includes a loop, is correct. I am working on the basis of wp, vc and pc. The loops in question are: wp(while(i= n) wp(while(true) x=4; |x=4) where…
1
vote
0 answers

Structural Operational Semantics and Axiomatic Semantics (Hoare Logic)

I was reading through the book "SEMANTICS WITH APPLICATIONS- A FORMAL INTRODUCTION"- http://www.cs.ru.nl/~herman/onderwijs/semantics2019/wiley.pdf and had a few questions regarding it: In Ex.2.22, p.39, it is asked to show that the structural…
MrCrypto
  • 11
  • 1
1
vote
1 answer

Getting Error: Maximum Recursion Depth Exceeded in Comparison

I was trying to write the QuickSort algorithm using the Hoare Partition Scheme. I'm pretty sure my Partition function is correct. I use a variable 'Swaps' to indicate the movement of the left pivot towards the right and the movement of the right…
shailesh
  • 43
  • 1
  • 7
1
vote
1 answer

How to demonstrate the correctness of a program with a while cycle using Hoare's logic?

How can I demonstrate through Hoare logic the correctness of a program that has a while cycle. It would be fascinating that some one develop it with any example, due to as my problem to solve is: Precondition={n>0} cont := n; sum := 0; while cont…
1
vote
0 answers

Proof of a if statement total correctness

The program I need to prove is if(x>y){ z=x; }else{ z=y; } And I need to show that (where the P here should be the program above) is vaild, what I can do is to prove its partial correctness, but how to prove its total correctness? Here is…
Roy Shell
  • 23
  • 4
1
vote
1 answer

Where can I find more complicated examples of using Hoare logic to verify programs in Isabelle/HOL?

Where can I find more complicated examples of using Hoare logic to verify programs in Isabelle/HOL? I recently learned about this aspect of using Hoare logic for program verification in Isabelle/HOL. I found that the examples in this tutorial are…
contall
  • 51
  • 3
1
vote
1 answer

How to verify that function with Hoare Triple?

As the title says, how can I verify the function below with the Hoare Triple? I read various lectures about it but I can't figure out how to do it. int uguaglianza_insiemi(elem_lista_t *insieme_A, elem_lista_t *insieme_B) { …
1
vote
1 answer

Hoare Logic | What post-condition is valid when there is an infinite loop?

My teacher told me the following statement is valid: {x > 3} while true (x := 3) {x = 3} Why is this statement valid? Is it because the post-condition never gets checked, or will the post-condition now count as an invariant check? In short: can the…
ToTheMax
  • 981
  • 8
  • 18
1
vote
1 answer

Finding a loop invariant - Hoare Triple

From the following code, I need to deduce/choose a loop invariant. (|true|) x = 0 ; s = 0 ; while ( x <= n ) { s = s + x ; x = x + 1 ; } (|s = n(n + 1)/2|) Solution given was s = (x-1)*x/2 ∧ (x ≤ n +1) I don't quite understand how it has…
user6797155