src/HOL/Hoare/HeapSyntax.thy
author wenzelm
Thu, 14 Nov 2024 11:33:51 +0100
changeset 81445 82110cbcf9a1
parent 81189 47a0dfee26ea
permissions -rw-r--r--
disable 2d9b6e32632d for now: unknown problems on macOS;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13875
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/Hoare/HeapSyntax.thy
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
     2
    Author:     Tobias Nipkow
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
     3
    Copyright   2002 TUM
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
     4
*)
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
     5
72990
db8f94656024 tuned document, notably authors and sections;
wenzelm
parents: 35316
diff changeset
     6
section \<open>Heap syntax\<close>
db8f94656024 tuned document, notably authors and sections;
wenzelm
parents: 35316
diff changeset
     7
db8f94656024 tuned document, notably authors and sections;
wenzelm
parents: 35316
diff changeset
     8
theory HeapSyntax
db8f94656024 tuned document, notably authors and sections;
wenzelm
parents: 35316
diff changeset
     9
  imports Hoare_Logic Heap
db8f94656024 tuned document, notably authors and sections;
wenzelm
parents: 35316
diff changeset
    10
begin
13875
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    11
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    12
subsection "Field access and update"
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    13
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    14
syntax
35101
6ce9177d6b38 modernized translations;
wenzelm
parents: 16417
diff changeset
    15
  "_refupdate" :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a ref \<Rightarrow> 'b \<Rightarrow> ('a \<Rightarrow> 'b)"
81189
47a0dfee26ea more inner-syntax markup;
wenzelm
parents: 80914
diff changeset
    16
    (\<open>(\<open>open_block notation=\<open>mixfix Hoare ref update\<close>\<close>_/'((_ \<rightarrow> _)'))\<close> [1000,0] 900)
35101
6ce9177d6b38 modernized translations;
wenzelm
parents: 16417
diff changeset
    17
  "_fassign"  :: "'a ref => id => 'v => 's com"
81189
47a0dfee26ea more inner-syntax markup;
wenzelm
parents: 80914
diff changeset
    18
    (\<open>(\<open>indent=2 notation=\<open>mixfix Hoare ref assignment\<close>\<close>_^._ :=/ _)\<close> [70,1000,65] 61)
35101
6ce9177d6b38 modernized translations;
wenzelm
parents: 16417
diff changeset
    19
  "_faccess"  :: "'a ref => ('a ref \<Rightarrow> 'v) => 'v"
81189
47a0dfee26ea more inner-syntax markup;
wenzelm
parents: 80914
diff changeset
    20
    (\<open>(\<open>open_block notation=\<open>infix Hoare ref access\<close>\<close>_^._)\<close> [65,1000] 65)
13875
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    21
translations
35113
1a0c129bb2e0 modernized translations;
wenzelm
parents: 35101
diff changeset
    22
  "f(r \<rightarrow> v)" == "f(CONST addr r := v)"
1a0c129bb2e0 modernized translations;
wenzelm
parents: 35101
diff changeset
    23
  "p^.f := e" => "f := f(p \<rightarrow> e)"
1a0c129bb2e0 modernized translations;
wenzelm
parents: 35101
diff changeset
    24
  "p^.f" => "f(CONST addr p)"
13875
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    25
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    26
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    27
declare fun_upd_apply[simp del] fun_upd_same[simp] fun_upd_other[simp]
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    28
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    29
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    30
text "An example due to Suzuki:"
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    31
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    32
lemma "VARS v n
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    33
  {w = Ref w0 & x = Ref x0 & y = Ref y0 & z = Ref z0 &
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    34
   distinct[w0,x0,y0,z0]}
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    35
  w^.v := (1::int); w^.n := x;
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    36
  x^.v := 2; x^.n := y;
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    37
  y^.v := 3; y^.n := z;
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    38
  z^.v := 4; x^.n := z
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    39
  {w^.n^.n^.v = 4}"
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    40
by vcg_simp
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    41
12997e3ddd8d *** empty log message ***
nipkow
parents:
diff changeset
    42
end