doc-src/TutorialI/Types/Records.thy
author paulson
Thu, 06 Dec 2001 13:00:25 +0100
changeset 12407 70ebb59264f1
parent 12156 d2758965362e
child 12409 25bf458af885
permissions -rw-r--r--
record extend and truncate exercises
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
     1
(*  Title:      HOL/ex/Records.thy
8db249f786ee for the records section
paulson
parents:
diff changeset
     2
    ID:         $Id$
8db249f786ee for the records section
paulson
parents:
diff changeset
     3
    Author:     Wolfgang Naraschewski and Markus Wenzel, TU Muenchen
8db249f786ee for the records section
paulson
parents:
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
8db249f786ee for the records section
paulson
parents:
diff changeset
     5
*)
8db249f786ee for the records section
paulson
parents:
diff changeset
     6
8db249f786ee for the records section
paulson
parents:
diff changeset
     7
header {* Extensible Records  *}
8db249f786ee for the records section
paulson
parents:
diff changeset
     8
8db249f786ee for the records section
paulson
parents:
diff changeset
     9
theory Records = Main:
8db249f786ee for the records section
paulson
parents:
diff changeset
    10
8db249f786ee for the records section
paulson
parents:
diff changeset
    11
subsection {* Points *}
8db249f786ee for the records section
paulson
parents:
diff changeset
    12
8db249f786ee for the records section
paulson
parents:
diff changeset
    13
record point =
8db249f786ee for the records section
paulson
parents:
diff changeset
    14
  Xcoord :: int
8db249f786ee for the records section
paulson
parents:
diff changeset
    15
  Ycoord :: int
8db249f786ee for the records section
paulson
parents:
diff changeset
    16
8db249f786ee for the records section
paulson
parents:
diff changeset
    17
text {*
8db249f786ee for the records section
paulson
parents:
diff changeset
    18
 Apart many other things, above record declaration produces the
8db249f786ee for the records section
paulson
parents:
diff changeset
    19
 following theorems:
8db249f786ee for the records section
paulson
parents:
diff changeset
    20
*}
8db249f786ee for the records section
paulson
parents:
diff changeset
    21
11428
332347b9b942 tidying the index
paulson
parents: 11389
diff changeset
    22
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
    23
thm "point.simps"
8db249f786ee for the records section
paulson
parents:
diff changeset
    24
text {*
8db249f786ee for the records section
paulson
parents:
diff changeset
    25
Incomprehensible equations: the selectors Xcoord and Ycoord, also "more";
8db249f786ee for the records section
paulson
parents:
diff changeset
    26
Updates, make, make_scheme and equality introduction (extensionality)
8db249f786ee for the records section
paulson
parents:
diff changeset
    27
*}
8db249f786ee for the records section
paulson
parents:
diff changeset
    28
8db249f786ee for the records section
paulson
parents:
diff changeset
    29
thm "point.iffs"
8db249f786ee for the records section
paulson
parents:
diff changeset
    30
text {*
8db249f786ee for the records section
paulson
parents:
diff changeset
    31
@{thm[display] point.iffs}
8db249f786ee for the records section
paulson
parents:
diff changeset
    32
%%\rulename{point.iffs}
8db249f786ee for the records section
paulson
parents:
diff changeset
    33
Simplify equations involving Xcoord, Ycoord (and presumably also both Xcoord and Ycoord)
8db249f786ee for the records section
paulson
parents:
diff changeset
    34
*}
8db249f786ee for the records section
paulson
parents:
diff changeset
    35
8db249f786ee for the records section
paulson
parents:
diff changeset
    36
thm "point.update_defs"
8db249f786ee for the records section
paulson
parents:
diff changeset
    37
text {*
8db249f786ee for the records section
paulson
parents:
diff changeset
    38
@{thm[display] point.update_defs}
8db249f786ee for the records section
paulson
parents:
diff changeset
    39
%%\rulename{point.update_defs}
8db249f786ee for the records section
paulson
parents:
diff changeset
    40
Definitions of updates to Xcoord and Ycoord, also "more"
8db249f786ee for the records section
paulson
parents:
diff changeset
    41
*}
8db249f786ee for the records section
paulson
parents:
diff changeset
    42
8db249f786ee for the records section
paulson
parents:
diff changeset
    43
text {*
8db249f786ee for the records section
paulson
parents:
diff changeset
    44
 The set of theorems @{thm [source] point.simps} is added
8db249f786ee for the records section
paulson
parents:
diff changeset
    45
 automatically to the standard simpset, @{thm [source] point.iffs} is
8db249f786ee for the records section
paulson
parents:
diff changeset
    46
 added to the Classical Reasoner and Simplifier context.
8db249f786ee for the records section
paulson
parents:
diff changeset
    47
*}
8db249f786ee for the records section
paulson
parents:
diff changeset
    48
8db249f786ee for the records section
paulson
parents:
diff changeset
    49
text {* Exchanging Xcoord and Ycoord yields a different type: we must
8db249f786ee for the records section
paulson
parents:
diff changeset
    50
unfortunately write the fields in a canonical order.*}
8db249f786ee for the records section
paulson
parents:
diff changeset
    51
8db249f786ee for the records section
paulson
parents:
diff changeset
    52
8db249f786ee for the records section
paulson
parents:
diff changeset
    53
constdefs 
8db249f786ee for the records section
paulson
parents:
diff changeset
    54
  pt1 :: point
11711
ecdfd237ffee fixed numerals;
wenzelm
parents: 11428
diff changeset
    55
   "pt1 == (| Xcoord = 999, Ycoord = 23 |)"
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
    56
8db249f786ee for the records section
paulson
parents:
diff changeset
    57
  pt2 :: "(| Xcoord :: int, Ycoord :: int |)" 
11711
ecdfd237ffee fixed numerals;
wenzelm
parents: 11428
diff changeset
    58
   "pt2 == (| Xcoord = -45, Ycoord = 97 |)" 
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
    59
8db249f786ee for the records section
paulson
parents:
diff changeset
    60
8db249f786ee for the records section
paulson
parents:
diff changeset
    61
subsubsection {* Some lemmas about records *}
8db249f786ee for the records section
paulson
parents:
diff changeset
    62
8db249f786ee for the records section
paulson
parents:
diff changeset
    63
text {* Basic simplifications. *}
8db249f786ee for the records section
paulson
parents:
diff changeset
    64
8db249f786ee for the records section
paulson
parents:
diff changeset
    65
lemma "Xcoord (| Xcoord = a, Ycoord = b |) = a"
8db249f786ee for the records section
paulson
parents:
diff changeset
    66
by simp -- "selection"
8db249f786ee for the records section
paulson
parents:
diff changeset
    67
8db249f786ee for the records section
paulson
parents:
diff changeset
    68
lemma "(| Xcoord = a, Ycoord = b |) (| Xcoord:= 0 |) = (| Xcoord = 0, Ycoord = b |)"
8db249f786ee for the records section
paulson
parents:
diff changeset
    69
by simp -- "update"
8db249f786ee for the records section
paulson
parents:
diff changeset
    70
12407
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
    71
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
    72
subsection {* Coloured points: record extension *}
8db249f786ee for the records section
paulson
parents:
diff changeset
    73
8db249f786ee for the records section
paulson
parents:
diff changeset
    74
8db249f786ee for the records section
paulson
parents:
diff changeset
    75
text {*
8db249f786ee for the records section
paulson
parents:
diff changeset
    76
 Records are extensible.
8db249f786ee for the records section
paulson
parents:
diff changeset
    77
 
8db249f786ee for the records section
paulson
parents:
diff changeset
    78
 The name@{text  "more"} is reserved, since it is used for extensibility.
8db249f786ee for the records section
paulson
parents:
diff changeset
    79
*}
8db249f786ee for the records section
paulson
parents:
diff changeset
    80
8db249f786ee for the records section
paulson
parents:
diff changeset
    81
8db249f786ee for the records section
paulson
parents:
diff changeset
    82
datatype colour = Red | Green | Blue
8db249f786ee for the records section
paulson
parents:
diff changeset
    83
8db249f786ee for the records section
paulson
parents:
diff changeset
    84
record cpoint = point +
8db249f786ee for the records section
paulson
parents:
diff changeset
    85
  col :: colour
8db249f786ee for the records section
paulson
parents:
diff changeset
    86
8db249f786ee for the records section
paulson
parents:
diff changeset
    87
8db249f786ee for the records section
paulson
parents:
diff changeset
    88
constdefs 
8db249f786ee for the records section
paulson
parents:
diff changeset
    89
  cpt1 :: cpoint
11711
ecdfd237ffee fixed numerals;
wenzelm
parents: 11428
diff changeset
    90
   "cpt1 == (| Xcoord = 999, Ycoord = 23, col = Green |)"
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
    91
8db249f786ee for the records section
paulson
parents:
diff changeset
    92
8db249f786ee for the records section
paulson
parents:
diff changeset
    93
subsection {* Generic operations *}
8db249f786ee for the records section
paulson
parents:
diff changeset
    94
8db249f786ee for the records section
paulson
parents:
diff changeset
    95
8db249f786ee for the records section
paulson
parents:
diff changeset
    96
text {* Record selection and record update; these are generic! *}
8db249f786ee for the records section
paulson
parents:
diff changeset
    97
8db249f786ee for the records section
paulson
parents:
diff changeset
    98
lemma "Xcoord (| Xcoord = a, Ycoord = b, ... = p |) = a"
8db249f786ee for the records section
paulson
parents:
diff changeset
    99
by simp -- "selection"
8db249f786ee for the records section
paulson
parents:
diff changeset
   100
8db249f786ee for the records section
paulson
parents:
diff changeset
   101
lemma "point.more cpt1 = \<lparr>col = Green\<rparr>"
8db249f786ee for the records section
paulson
parents:
diff changeset
   102
by (simp add: cpt1_def) -- "tail of this record"
8db249f786ee for the records section
paulson
parents:
diff changeset
   103
8db249f786ee for the records section
paulson
parents:
diff changeset
   104
8db249f786ee for the records section
paulson
parents:
diff changeset
   105
lemma "(| Xcoord = a, Ycoord = b, ... = p |) (| Xcoord:= 0 |) = (| Xcoord = 0, Ycoord = b, ... = p |)"
8db249f786ee for the records section
paulson
parents:
diff changeset
   106
by simp -- "update"
8db249f786ee for the records section
paulson
parents:
diff changeset
   107
8db249f786ee for the records section
paulson
parents:
diff changeset
   108
text {*
8db249f786ee for the records section
paulson
parents:
diff changeset
   109
  Record declarations define new type abbreviations:
8db249f786ee for the records section
paulson
parents:
diff changeset
   110
  @{text [display]
8db249f786ee for the records section
paulson
parents:
diff changeset
   111
"    point = (| Xcoord :: int, Ycoord :: int |)
8db249f786ee for the records section
paulson
parents:
diff changeset
   112
    'a point_scheme = (| Xcoord :: int, Ycoord :: int, ... :: 'a |)"}
8db249f786ee for the records section
paulson
parents:
diff changeset
   113
*}
8db249f786ee for the records section
paulson
parents:
diff changeset
   114
8db249f786ee for the records section
paulson
parents:
diff changeset
   115
constdefs
11942
06fac365248d accomodate some recent changes of record package;
wenzelm
parents: 11711
diff changeset
   116
  getX :: "'a point_scheme \<Rightarrow> int"
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
   117
   "getX r == Xcoord r"
11942
06fac365248d accomodate some recent changes of record package;
wenzelm
parents: 11711
diff changeset
   118
  setX :: "['a point_scheme, int] \<Rightarrow> 'a point_scheme"
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
   119
   "setX r a == r (| Xcoord := a |)"
12407
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   120
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
   121
8db249f786ee for the records section
paulson
parents:
diff changeset
   122
8db249f786ee for the records section
paulson
parents:
diff changeset
   123
text {*
8db249f786ee for the records section
paulson
parents:
diff changeset
   124
 \medskip Concrete records are type instances of record schemes.
8db249f786ee for the records section
paulson
parents:
diff changeset
   125
*}
8db249f786ee for the records section
paulson
parents:
diff changeset
   126
11711
ecdfd237ffee fixed numerals;
wenzelm
parents: 11428
diff changeset
   127
lemma "getX (| Xcoord = 64, Ycoord = 36 |) = 64"
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
   128
by (simp add: getX_def) 
8db249f786ee for the records section
paulson
parents:
diff changeset
   129
8db249f786ee for the records section
paulson
parents:
diff changeset
   130
8db249f786ee for the records section
paulson
parents:
diff changeset
   131
text {* \medskip Manipulating the `...' (more) part.  beware: EACH record
8db249f786ee for the records section
paulson
parents:
diff changeset
   132
   has its OWN more field, so a compound name is required! *}
8db249f786ee for the records section
paulson
parents:
diff changeset
   133
8db249f786ee for the records section
paulson
parents:
diff changeset
   134
constdefs
11942
06fac365248d accomodate some recent changes of record package;
wenzelm
parents: 11711
diff changeset
   135
  incX :: "'a point_scheme \<Rightarrow> 'a point_scheme"
11711
ecdfd237ffee fixed numerals;
wenzelm
parents: 11428
diff changeset
   136
  "incX r == \<lparr>Xcoord = (Xcoord r) + 1, Ycoord = Ycoord r, \<dots> = point.more r\<rparr>"
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
   137
8db249f786ee for the records section
paulson
parents:
diff changeset
   138
constdefs
11942
06fac365248d accomodate some recent changes of record package;
wenzelm
parents: 11711
diff changeset
   139
  setGreen :: "[colour, 'a point_scheme] \<Rightarrow> cpoint"
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
   140
  "setGreen cl r == (| Xcoord = Xcoord r, Ycoord = Ycoord r, col = cl |)"
8db249f786ee for the records section
paulson
parents:
diff changeset
   141
8db249f786ee for the records section
paulson
parents:
diff changeset
   142
8db249f786ee for the records section
paulson
parents:
diff changeset
   143
text {* works (I think) for ALL extensions of type point? *}
8db249f786ee for the records section
paulson
parents:
diff changeset
   144
11711
ecdfd237ffee fixed numerals;
wenzelm
parents: 11428
diff changeset
   145
lemma "incX r = setX r ((getX r) + 1)"
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
   146
by (simp add: getX_def setX_def incX_def)
8db249f786ee for the records section
paulson
parents:
diff changeset
   147
8db249f786ee for the records section
paulson
parents:
diff changeset
   148
text {* An equivalent definition. *}
11711
ecdfd237ffee fixed numerals;
wenzelm
parents: 11428
diff changeset
   149
lemma "incX r = r \<lparr>Xcoord := (Xcoord r) + 1\<rparr>"
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
   150
by (simp add: incX_def)
8db249f786ee for the records section
paulson
parents:
diff changeset
   151
8db249f786ee for the records section
paulson
parents:
diff changeset
   152
8db249f786ee for the records section
paulson
parents:
diff changeset
   153
8db249f786ee for the records section
paulson
parents:
diff changeset
   154
text {*
8db249f786ee for the records section
paulson
parents:
diff changeset
   155
 Functions on @{text point} schemes work for type @{text cpoint} as
8db249f786ee for the records section
paulson
parents:
diff changeset
   156
 well.  *}
8db249f786ee for the records section
paulson
parents:
diff changeset
   157
11711
ecdfd237ffee fixed numerals;
wenzelm
parents: 11428
diff changeset
   158
lemma "getX \<lparr>Xcoord = 23, Ycoord = 10, col = Blue\<rparr> = 23"
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
   159
by (simp add: getX_def)
8db249f786ee for the records section
paulson
parents:
diff changeset
   160
8db249f786ee for the records section
paulson
parents:
diff changeset
   161
8db249f786ee for the records section
paulson
parents:
diff changeset
   162
subsubsection {* Non-coercive structural subtyping *}
8db249f786ee for the records section
paulson
parents:
diff changeset
   163
8db249f786ee for the records section
paulson
parents:
diff changeset
   164
text {*
8db249f786ee for the records section
paulson
parents:
diff changeset
   165
 Function @{term setX} can be applied to type @{typ cpoint}, not just type
8db249f786ee for the records section
paulson
parents:
diff changeset
   166
 @{typ point}, and returns a result of the same type!  *}
8db249f786ee for the records section
paulson
parents:
diff changeset
   167
11711
ecdfd237ffee fixed numerals;
wenzelm
parents: 11428
diff changeset
   168
lemma "setX \<lparr>Xcoord = 12, Ycoord = 0, col = Blue\<rparr> 23 =  
ecdfd237ffee fixed numerals;
wenzelm
parents: 11428
diff changeset
   169
            \<lparr>Xcoord = 23, Ycoord = 0, col = Blue\<rparr>"
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
   170
by (simp add: setX_def)
8db249f786ee for the records section
paulson
parents:
diff changeset
   171
8db249f786ee for the records section
paulson
parents:
diff changeset
   172
8db249f786ee for the records section
paulson
parents:
diff changeset
   173
subsection {* Other features *}
8db249f786ee for the records section
paulson
parents:
diff changeset
   174
8db249f786ee for the records section
paulson
parents:
diff changeset
   175
text {* Field names (and order) contribute to record identity. *}
8db249f786ee for the records section
paulson
parents:
diff changeset
   176
8db249f786ee for the records section
paulson
parents:
diff changeset
   177
8db249f786ee for the records section
paulson
parents:
diff changeset
   178
text {* \medskip Polymorphic records. *}
8db249f786ee for the records section
paulson
parents:
diff changeset
   179
8db249f786ee for the records section
paulson
parents:
diff changeset
   180
record 'a polypoint = point +
8db249f786ee for the records section
paulson
parents:
diff changeset
   181
  content :: 'a
8db249f786ee for the records section
paulson
parents:
diff changeset
   182
8db249f786ee for the records section
paulson
parents:
diff changeset
   183
types cpolypoint = "colour polypoint"
8db249f786ee for the records section
paulson
parents:
diff changeset
   184
8db249f786ee for the records section
paulson
parents:
diff changeset
   185
8db249f786ee for the records section
paulson
parents:
diff changeset
   186
subsection {* Equality of records. *}
8db249f786ee for the records section
paulson
parents:
diff changeset
   187
8db249f786ee for the records section
paulson
parents:
diff changeset
   188
lemma "(\<lparr>Xcoord = a, Ycoord = b\<rparr> = \<lparr>Xcoord = a', Ycoord = b'\<rparr>) = (a = a' & b = b')"
8db249f786ee for the records section
paulson
parents:
diff changeset
   189
  -- "simplification of concrete record equality"
8db249f786ee for the records section
paulson
parents:
diff changeset
   190
by simp
8db249f786ee for the records section
paulson
parents:
diff changeset
   191
8db249f786ee for the records section
paulson
parents:
diff changeset
   192
text {* \medskip Surjective pairing *}
8db249f786ee for the records section
paulson
parents:
diff changeset
   193
8db249f786ee for the records section
paulson
parents:
diff changeset
   194
lemma "r = \<lparr>Xcoord = Xcoord r, Ycoord = Ycoord r\<rparr>"
8db249f786ee for the records section
paulson
parents:
diff changeset
   195
by simp
8db249f786ee for the records section
paulson
parents:
diff changeset
   196
8db249f786ee for the records section
paulson
parents:
diff changeset
   197
8db249f786ee for the records section
paulson
parents:
diff changeset
   198
8db249f786ee for the records section
paulson
parents:
diff changeset
   199
lemma "\<lparr>Xcoord = a, Ycoord = b, \<dots> = p\<rparr> = \<lparr>Xcoord = a, Ycoord = b\<rparr>"
8db249f786ee for the records section
paulson
parents:
diff changeset
   200
by auto
8db249f786ee for the records section
paulson
parents:
diff changeset
   201
8db249f786ee for the records section
paulson
parents:
diff changeset
   202
text {*
8db249f786ee for the records section
paulson
parents:
diff changeset
   203
 A rigid record has ()::unit in its  name@{text "more"} part
8db249f786ee for the records section
paulson
parents:
diff changeset
   204
*}
8db249f786ee for the records section
paulson
parents:
diff changeset
   205
8db249f786ee for the records section
paulson
parents:
diff changeset
   206
text {* a polymorphic record equality (covers all possible extensions) *}
8db249f786ee for the records section
paulson
parents:
diff changeset
   207
lemma "r \<lparr>Xcoord := a\<rparr> \<lparr>Ycoord := b\<rparr> = r \<lparr>Ycoord := b\<rparr> \<lparr>Xcoord := a\<rparr>"
8db249f786ee for the records section
paulson
parents:
diff changeset
   208
  -- "introduction of abstract record equality
11389
55e2aef8909b the records section
paulson
parents: 11387
diff changeset
   209
         (order of updates doesn't affect the value)"
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
   210
by simp
8db249f786ee for the records section
paulson
parents:
diff changeset
   211
8db249f786ee for the records section
paulson
parents:
diff changeset
   212
lemma "r \<lparr>Xcoord := a, Ycoord := b\<rparr> = r \<lparr>Ycoord := b, Xcoord := a\<rparr>"
8db249f786ee for the records section
paulson
parents:
diff changeset
   213
  -- "abstract record equality (the same with iterated updates)"
8db249f786ee for the records section
paulson
parents:
diff changeset
   214
by simp
8db249f786ee for the records section
paulson
parents:
diff changeset
   215
8db249f786ee for the records section
paulson
parents:
diff changeset
   216
text {* Showing that repeated updates don't matter *}
8db249f786ee for the records section
paulson
parents:
diff changeset
   217
lemma "r \<lparr>Xcoord := a\<rparr> \<lparr>Xcoord := a'\<rparr> = r \<lparr>Xcoord := a'\<rparr>"
11389
55e2aef8909b the records section
paulson
parents: 11387
diff changeset
   218
by simp
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
   219
8db249f786ee for the records section
paulson
parents:
diff changeset
   220
8db249f786ee for the records section
paulson
parents:
diff changeset
   221
text {* surjective *}
8db249f786ee for the records section
paulson
parents:
diff changeset
   222
8db249f786ee for the records section
paulson
parents:
diff changeset
   223
lemma "r = \<lparr>Xcoord = Xcoord r, Ycoord = Ycoord r, \<dots> = point.more r\<rparr>"
8db249f786ee for the records section
paulson
parents:
diff changeset
   224
by simp
8db249f786ee for the records section
paulson
parents:
diff changeset
   225
8db249f786ee for the records section
paulson
parents:
diff changeset
   226
8db249f786ee for the records section
paulson
parents:
diff changeset
   227
text {*
8db249f786ee for the records section
paulson
parents:
diff changeset
   228
 \medskip Splitting abstract record variables.
8db249f786ee for the records section
paulson
parents:
diff changeset
   229
*}
8db249f786ee for the records section
paulson
parents:
diff changeset
   230
8db249f786ee for the records section
paulson
parents:
diff changeset
   231
lemma "r \<lparr>Xcoord := a\<rparr> = r \<lparr>Xcoord := a'\<rparr> \<Longrightarrow> a = a'"
8db249f786ee for the records section
paulson
parents:
diff changeset
   232
  -- "elimination of abstract record equality (manual proof, by selector)"
8db249f786ee for the records section
paulson
parents:
diff changeset
   233
apply (drule_tac f=Xcoord in arg_cong)
8db249f786ee for the records section
paulson
parents:
diff changeset
   234
    --{* @{subgoals[display,indent=0,margin=65]} *}
8db249f786ee for the records section
paulson
parents:
diff changeset
   235
by simp
8db249f786ee for the records section
paulson
parents:
diff changeset
   236
8db249f786ee for the records section
paulson
parents:
diff changeset
   237
text {*
8db249f786ee for the records section
paulson
parents:
diff changeset
   238
So we replace the ugly manual proof by splitting.  These must be quantified: 
8db249f786ee for the records section
paulson
parents:
diff changeset
   239
  the @{text "!!r"} is \emph{necessary}!  Note the occurrence of more, since
8db249f786ee for the records section
paulson
parents:
diff changeset
   240
  r is polymorphic.
11942
06fac365248d accomodate some recent changes of record package;
wenzelm
parents: 11711
diff changeset
   241
*}  (* FIXME better us cases/induct *)
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
   242
lemma "!!r. r \<lparr>Xcoord := a\<rparr> = r \<lparr>Xcoord := a'\<rparr> \<Longrightarrow> a = a'"
8db249f786ee for the records section
paulson
parents:
diff changeset
   243
apply record_split --{* @{subgoals[display,indent=0,margin=65]} *}
11942
06fac365248d accomodate some recent changes of record package;
wenzelm
parents: 11711
diff changeset
   244
by simp
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
   245
12407
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   246
constdefs
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   247
  cpt2 :: cpoint
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   248
   "cpt2 \<equiv> point.extend pt1 (cpoint.fields Green)"
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   249
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   250
text {*
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   251
@{thm[display] point.defs}
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   252
*};
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   253
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   254
text {*
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   255
@{thm[display] cpoint.defs}
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   256
*};
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   257
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   258
text{*cpt2 is the same as cpt1, but defined by extending point pt1*}
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   259
lemma "cpt1 = cpt2"
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   260
apply (simp add: cpt1_def cpt2_def point.defs cpoint.defs)
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   261
	--{* @{subgoals[display,indent=0,margin=65]} *}
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   262
by (simp add: pt1_def)
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   263
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   264
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   265
lemma "point.truncate cpt2 = pt1"
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   266
by (simp add: pt1_def cpt2_def point.defs)
70ebb59264f1 record extend and truncate
paulson
parents: 12156
diff changeset
   267
11387
8db249f786ee for the records section
paulson
parents:
diff changeset
   268
end