| 
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  | 
*)
  | 
| 
 | 
     8  | 
  | 
| 
16417
 | 
     9  | 
theory ExamplesAbort imports HoareAbort begin
  | 
| 
13856
 | 
    10  | 
  | 
| 
 | 
    11  | 
lemma "VARS x y z::nat
  | 
| 
 | 
    12  | 
 {y = z & z \<noteq> 0} z \<noteq> 0 \<rightarrow> x := y div z {x = 1}"
 | 
| 
 | 
    13  | 
by vcg_simp
  | 
| 
 | 
    14  | 
  | 
| 
13875
 | 
    15  | 
lemma
  | 
| 
 | 
    16  | 
 "VARS a i j
  | 
| 
 | 
    17  | 
 {k <= length a & i < k & j < k} j < length a \<rightarrow> a[i] := a!j {True}"
 | 
| 
 | 
    18  | 
apply vcg_simp
  | 
| 
 | 
    19  | 
done
  | 
| 
 | 
    20  | 
  | 
| 
13856
 | 
    21  | 
lemma "VARS (a::int list) i
  | 
| 
 | 
    22  | 
 {True}
 | 
| 
 | 
    23  | 
 i := 0;
  | 
| 
 | 
    24  | 
 WHILE i < length a
  | 
| 
 | 
    25  | 
 INV {i <= length a}
 | 
| 
13875
 | 
    26  | 
 DO a[i] := 7; i := i+1 OD
  | 
| 
13856
 | 
    27  | 
 {True}"
 | 
| 
 | 
    28  | 
apply vcg_simp
  | 
| 
 | 
    29  | 
done
  | 
| 
 | 
    30  | 
  | 
| 
 | 
    31  | 
end
  |