13857
|
1 |
(* Title: HOL/Hoare/ExamplesAbort.thy
|
|
2 |
ID: $Id$
|
|
3 |
Author: Tobias Nipkow
|
|
4 |
Copyright 1998 TUM
|
|
5 |
|
|
6 |
Some small examples for programs that may abort.
|
|
7 |
Currently only show the absence of abort.
|
|
8 |
*)
|
|
9 |
|
13856
|
10 |
theory ExamplesAbort = HoareAbort:
|
|
11 |
|
|
12 |
syntax guarded_com :: "'bool \<Rightarrow> 'a com \<Rightarrow> 'a com" ("_ \<rightarrow> _" 60)
|
|
13 |
translations "P \<rightarrow> c" == "IF P THEN c ELSE Abort FI"
|
|
14 |
|
|
15 |
lemma "VARS x y z::nat
|
|
16 |
{y = z & z \<noteq> 0} z \<noteq> 0 \<rightarrow> x := y div z {x = 1}"
|
|
17 |
by vcg_simp
|
|
18 |
|
|
19 |
lemma "VARS (a::int list) i
|
|
20 |
{True}
|
|
21 |
i := 0;
|
|
22 |
WHILE i < length a
|
|
23 |
INV {i <= length a}
|
|
24 |
DO i < length a \<rightarrow> a := a[i := 7];
|
|
25 |
i := i+1
|
|
26 |
OD
|
|
27 |
{True}"
|
|
28 |
apply vcg_simp
|
|
29 |
apply arith
|
|
30 |
done
|
|
31 |
|
|
32 |
end
|