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‹
The set of theorems @{thm [source] point.simps} is added
automatically to the standard simpset, @{thm [source] point.iffs} is
added to the Classical Reasoner and Simplifier context.
┉ 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) = 'a point_ext_type›} ›
text‹ 🚫 May not apply term‹getX› to @{term [source] "(xpos' = 2, ypos' = 0)"}
--- type error. ›
text‹┉ Polymorphic records.›
record 'a point'' = point +
content :: 'a
type_synonym cpoint'' = "colour point''"
text‹Updating a record field with an identical value is simplified.› lemma"r(xpos := xpos r) = r" by simp
text‹Only the most recent update to a component survives simplification.› lemma"r(xpos := x, ypos := y, xpos := x') = r(ypos := y, xpos := x')" by simp
text‹
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 🚫‹0› indicates no split, a value greater 🚫‹0› splits up to the given bound of record extension and finally the
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. ›
text‹
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. ›
text‹By default record updates are not ordered by simplification.›
schematic_goal "r(b := x, a:= y) = ?X" by simp
text‹Normalisation towards an update ordering (string ordering of update function names) can
be configured as follows.›
schematic_goal "r(b := y, a := x) = ?X"
supply [[record_sort_updates]] by simp
text‹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.›
setup‹
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.