src/HOL/Hoare/ExamplesAbort.thy
author paulson <lp15@cam.ac.uk>
Thu, 26 Sep 2024 14:44:37 +0100
changeset 80948 572970d15ab0
parent 72990 db8f94656024
permissions -rw-r--r--
To tiny but maybe useful lemmas (moved in from the AFP, Word_Lib)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13857
11d7c5a8dbb7 *** empty log message ***
nipkow
parents: 13856
diff changeset
     1
(*  Title:      HOL/Hoare/ExamplesAbort.thy
11d7c5a8dbb7 *** empty log message ***
nipkow
parents: 13856
diff changeset
     2
    Author:     Tobias Nipkow
11d7c5a8dbb7 *** empty log message ***
nipkow
parents: 13856
diff changeset
     3
    Copyright   1998 TUM
11d7c5a8dbb7 *** empty log message ***
nipkow
parents: 13856
diff changeset
     4
*)
11d7c5a8dbb7 *** empty log message ***
nipkow
parents: 13856
diff changeset
     5
72990
db8f94656024 tuned document, notably authors and sections;
wenzelm
parents: 42154
diff changeset
     6
section \<open>Some small examples for programs that may abort\<close>
db8f94656024 tuned document, notably authors and sections;
wenzelm
parents: 42154
diff changeset
     7
db8f94656024 tuned document, notably authors and sections;
wenzelm
parents: 42154
diff changeset
     8
theory ExamplesAbort
db8f94656024 tuned document, notably authors and sections;
wenzelm
parents: 42154
diff changeset
     9
  imports Hoare_Logic_Abort
db8f94656024 tuned document, notably authors and sections;
wenzelm
parents: 42154
diff changeset
    10
begin
13856
f5d08c341216 *** empty log message ***
nipkow
parents:
diff changeset
    11
f5d08c341216 *** empty log message ***
nipkow
parents:
diff changeset
    12
lemma "VARS x y z::nat
f5d08c341216 *** empty log message ***
nipkow
parents:
diff changeset
    13
 {y = z & z \<noteq> 0} z \<noteq> 0 \<rightarrow> x := y div z {x = 1}"
f5d08c341216 *** empty log message ***
nipkow
parents:
diff changeset
    14
by vcg_simp
f5d08c341216 *** empty log message ***
nipkow
parents:
diff changeset
    15
13875
12997e3ddd8d *** empty log message ***
nipkow
parents: 13857
diff changeset
    16
lemma
12997e3ddd8d *** empty log message ***
nipkow
parents: 13857
diff changeset
    17
 "VARS a i j
12997e3ddd8d *** empty log message ***
nipkow
parents: 13857
diff changeset
    18
 {k <= length a & i < k & j < k} j < length a \<rightarrow> a[i] := a!j {True}"
42154
478bdcea240a tuned proofs;
wenzelm
parents: 35316
diff changeset
    19
by vcg_simp
13875
12997e3ddd8d *** empty log message ***
nipkow
parents: 13857
diff changeset
    20
13856
f5d08c341216 *** empty log message ***
nipkow
parents:
diff changeset
    21
lemma "VARS (a::int list) i
f5d08c341216 *** empty log message ***
nipkow
parents:
diff changeset
    22
 {True}
f5d08c341216 *** empty log message ***
nipkow
parents:
diff changeset
    23
 i := 0;
f5d08c341216 *** empty log message ***
nipkow
parents:
diff changeset
    24
 WHILE i < length a
f5d08c341216 *** empty log message ***
nipkow
parents:
diff changeset
    25
 INV {i <= length a}
13875
12997e3ddd8d *** empty log message ***
nipkow
parents: 13857
diff changeset
    26
 DO a[i] := 7; i := i+1 OD
13856
f5d08c341216 *** empty log message ***
nipkow
parents:
diff changeset
    27
 {True}"
42154
478bdcea240a tuned proofs;
wenzelm
parents: 35316
diff changeset
    28
by vcg_simp
13856
f5d08c341216 *** empty log message ***
nipkow
parents:
diff changeset
    29
f5d08c341216 *** empty log message ***
nipkow
parents:
diff changeset
    30
end