src/HOL/Map.thy
author paulson
Wed, 05 Aug 1998 10:57:25 +0200
changeset 5253 82a5ca6290aa
parent 5195 277831ae7eac
child 5300 2b1ca524ace8
permissions -rw-r--r--
New record type of programs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/Map.thy
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     2
    ID:         $Id$
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     3
    Author:     Tobias Nipkow, based on a theory by David von Oheimb
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     4
    Copyright   1997 TU Muenchen
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     5
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     6
The datatype of `maps' (written ~=>); strongly resembles maps in VDM.
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     7
*)
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     8
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     9
Map = List + Option +
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    10
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    11
types ('a,'b) "~=>" = 'a => 'b option (infixr 0)
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    12
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    13
consts
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    14
empty   :: "'a ~=> 'b"
5195
277831ae7eac Map.update -> map_upd, Unpdate.update -> fun_upd
nipkow
parents: 5183
diff changeset
    15
map_upd :: "('a ~=> 'b) => 'a => 'b => ('a ~=> 'b)"
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    16
           ("_/[_/|->/_]" [900,0,0] 900)
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    17
override:: "('a ~=> 'b) => ('a ~=> 'b) => ('a ~=> 'b)" (infixl "++" 100)
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    18
dom     :: "('a ~=> 'b) => 'a set"
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    19
ran     :: "('a ~=> 'b) => 'b set"
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    20
map_of  :: "('a * 'b)list => 'a ~=> 'b"
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    21
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    22
syntax (symbols)
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    23
  "~=>"     :: [type, type] => type
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    24
               (infixr "\\<leadsto>" 0)
5195
277831ae7eac Map.update -> map_upd, Unpdate.update -> fun_upd
nipkow
parents: 5183
diff changeset
    25
  map_upd    :: "('a ~=> 'b) => 'a => 'b => ('a ~=> 'b)"
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    26
               ("_/[_/\\<mapsto>/_]" [900,0,0] 900)
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    27
  override  :: "('a ~=> 'b) => ('a ~=> 'b) => ('a ~=> 'b)"
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    28
               (infixl "\\<oplus>" 100)
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    29
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    30
defs
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    31
empty_def "empty == %x. None"
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    32
5195
277831ae7eac Map.update -> map_upd, Unpdate.update -> fun_upd
nipkow
parents: 5183
diff changeset
    33
map_upd_def "m[a|->b] == %x. if x=a then Some b else m x"
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    34
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    35
override_def "m1++m2 == %x. case m2 x of None => m1 x | Some y => Some y"
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    36
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    37
dom_def "dom(m) == {a. m a ~= None}"
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    38
ran_def "ran(m) == {b. ? a. m a = Some b}"
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    39
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 3981
diff changeset
    40
primrec
89f162de39cf Adapted to new datatype package.
berghofe
parents: 3981
diff changeset
    41
  "map_of [] = empty"
89f162de39cf Adapted to new datatype package.
berghofe
parents: 3981
diff changeset
    42
  "map_of (p#ps) = (map_of ps)[fst p |-> snd p]"
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    43
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    44
end