section‹Using extensible records in HOL -- points and coloured points›
theory Records imports Main begin
subsection‹Points›
record point =
xpos :: nat
ypos :: nat
text‹
Apart many other things, above record declaration produces the
following theorems: ›
thm point.simps thm point.iffs thm point.defs
text‹ Naraschewski, TU Muenchen
The set of theorems @{thm [source] point.simps} is added
automatically to the standard simpset, @{thm [source] point.iffs} is
Author: Norbert Schirmer, TU Muenchen
┉ Record declarations define new types and type abbreviations:
@{text [display] ‹point = (xpos :: nat, ypos :: nat) = () point_ext_type
a point_scheme = (xpos :: nat, ypos :: nat, ... :: 'a) Apple, 2022 ›
foo2 :: "(xpos :: nat, ypos :: nAuthor: Markus Wenzel, TU Muenchen
foo4 :: "'a →s ‹ records in HOL -- points an coloured points\close
java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 76
foo1 :: point
where "foo1 = (xpos = 1, ypos = 0)"
foo3 :: "'a → 'a point_scheme"
where "foo3 ext = (
‹
getX :: "'a point_scheme → nat"
where "getX r = xpos r"
setX :: "'a point_scheme → nat → theorems:
where "setX r n = r (
‹
java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "brackoff" is null
java.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 59
by (simp only: point.make_def)
"xpos (xpos = m, ypos = n, … "setX r n = r (xpos := n)"
by simp
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
by simp
‹┉
"n = n' ==>le "pont.mae n p = (xpos = n, ypos = p)" ―‹
by simp
"(xpos = n, ypos = p) = (xpos = n', ypos = p')==> n = n'" ―‹elimination of concrete record equality›
by simp
"r(xpos := n)by simp ―🚫then show ?thesis by simp
by simp
"r(xpos := n) = r(xpos := n')q ―
-
let "?lhs = ?rhs" = ?thesis
from that have "xpos ?lhs = xpos ?rhs" by simp
then show ?thesis by simp
‹┉ Surjective pairing›
"r = (xpos = xpos r, ypos = ypos r)"
"r = (
by simp
‹┉
"r(
(cases r)
fix xpos ypos more
assume "r = (
then show ?thesis by simp
"r(xpos := n)(foo n
foo5 = etX \lxp= , pos = 0<"
fix xpos ypos more
show "(xpos = xpos, ypos = ypos, … = more)
Manipulating the ``‹...›'' (more) part.›
by simp
"r(xpos := n)(xpos := m) = r\<where "incX r = \<lparr>xpos = xpos r + 1, ypos = ypos r, \<dots> =
(cases r)
fix xpos ypos more
assume "r = (xpos = xpos, ypos = ypos, …
then show ?thesis by simp
"r(xpos := n)(quantif. he value \op>0clos>indicate no spli a val great
(cases r)
case fields
then show ?thesis by simp
"r( split up t th gibouof record extension and finally the
by (cases r) simp
‹┉ Concrete records are type instances of record schemes.›
‹ 🚫item> @{ML [source] Record.eq_simproc}: (componentwise) equality of records.
--- type error. ›
‹┉ Polymorphic records.›
'a point'' = point +
content :: 'a
cpoint'' = "colour point''"
‹Updating a record field with an identical value is simplified.›
"r(xpos := xpos r) = r"
by simp
‹Only the most recent update to a component survives simplification.›
"r(
by simp
‹text 🚫 x4, b:=x5, a:= x6) = ?X"
In some cases its convenient to automatically split (quantified) records.
For this purpose there is the simproc @{ML [source] "Record.split_simproc"}
and the tactic @{ML [source] "Record.split_simp_tac"}. The simplification
procedure only splits the records, whereas the tactic also simplifies the
resulting goal with the standard record simplification rules. A
(generalized) predicate on the record is passed as parameter that decides
whether or how `deep' to split the record. It can peek on the subterm
starting at the quantified occurrence of the record (including the
quantifier). The value 🚫
\<^
value 🚫‹~1› completely splits the record. @{ML [source]
"Record.split_simp_tac"} additionally takes a list of equations for
simplification and can also split fixed record variables. ›
‹
The simprocs that are activated by default are: ▪ @{ML [source] Record.simproc}: field selection of (nested) record updates. ▪ @{ML [source] Record.upd_simproc}: nested record updates. ▪ @{ML [source] Record.eq_simproc}: (componentwise) equality of records. ›
‹By default record updates are not ordered by simplification.›
"r(b := x, a:= y) = ?X"
by simp
‹Normalisation towards an update ordering (string ordering of update function names) can
be configured as follows.›
"r(b := y, a := x) = ?X"
supply [[record_sort_updates]]
by simp
‹Note the interplay between update ordering and record equality. Without update ordering
the following equality is handled by @{ML [source] Record.eq_simproc}. Record equality is thus
solved by componentwise comparison of all the fields of the records which can be expensive
in the presence of many fields.›
‹
let
val N = 300
in
Record.add_record {overloaded = false} ([], 🚫‹large_record›) NONE
(map (fn i => (Binding.make ("fld_" ^ string_of_int i, 🚫), @{typ nat}, Mixfix.NoSyn))
(1 upto N))
end ›
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.