author | Thomas Sewell <tsewell@nicta.com.au> |
Fri, 11 Sep 2009 18:03:30 +1000 | |
changeset 32748 | 887c68b70f7d |
parent 32745 | 192d58483fdf |
child 32749 | 3282c12a856c |
permissions | -rw-r--r-- |
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31136
diff
changeset
|
1 |
(* Title: HOL/Tools/record.ML |
32745
192d58483fdf
Simplification of various aspects of the IsTuple component
Thomas Sewell <tsewell@nicta.com.au>
parents:
32744
diff
changeset
|
2 |
Authors: Wolfgang Naraschewski, Norbert Schirmer and Markus Wenzel, TU Muenchen |
192d58483fdf
Simplification of various aspects of the IsTuple component
Thomas Sewell <tsewell@nicta.com.au>
parents:
32744
diff
changeset
|
3 |
Thomas Sewell, NICTA |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
4 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
5 |
Extensible records with structural subtyping in HOL. |
5698 | 6 |
*) |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
7 |
|
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31136
diff
changeset
|
8 |
signature BASIC_RECORD = |
5698 | 9 |
sig |
7178 | 10 |
val record_simproc: simproc |
14079
1c22e5499eeb
- record_split_tac now also works for object-level universal quantifier
berghofe
parents:
13904
diff
changeset
|
11 |
val record_eq_simproc: simproc |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
12 |
val record_upd_simproc: simproc |
15273
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
13 |
val record_split_simproc: (term -> int) -> simproc |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
14 |
val record_ex_sel_eq_simproc: simproc |
5698 | 15 |
val record_split_tac: int -> tactic |
15273
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
16 |
val record_split_simp_tac: thm list -> (term -> int) -> int -> tactic |
5713 | 17 |
val record_split_name: string |
5698 | 18 |
val record_split_wrapper: string * wrapper |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
19 |
val print_record_type_abbr: bool ref |
17261 | 20 |
val print_record_type_as_fields: bool ref |
5698 | 21 |
end; |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
22 |
|
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31136
diff
changeset
|
23 |
signature RECORD = |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
24 |
sig |
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31136
diff
changeset
|
25 |
include BASIC_RECORD |
25179 | 26 |
val timing: bool ref |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
27 |
val record_quick_and_dirty_sensitive: bool ref |
8574 | 28 |
val updateN: string |
21363 | 29 |
val updN: string |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
30 |
val ext_typeN: string |
21363 | 31 |
val extN: string |
32 |
val makeN: string |
|
33 |
val moreN: string |
|
34 |
val ext_dest: string |
|
35 |
||
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
36 |
val last_extT: typ -> (string * typ list) option |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
37 |
val dest_recTs : typ -> (string * typ list) list |
26088 | 38 |
val get_extT_fields: theory -> typ -> (string * typ) list * (string * typ) |
39 |
val get_recT_fields: theory -> typ -> (string * typ) list * (string * typ) |
|
40 |
val get_parent: theory -> string -> (typ list * string) option |
|
41 |
val get_extension: theory -> string -> (string * typ list) option |
|
16458 | 42 |
val get_extinjects: theory -> thm list |
43 |
val get_simpset: theory -> simpset |
|
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
44 |
val print_records: theory -> unit |
27278
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
45 |
val read_typ: Proof.context -> string -> (string * sort) list -> typ * (string * sort) list |
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
46 |
val cert_typ: Proof.context -> typ -> (string * sort) list -> typ * (string * sort) list |
26477
ecf06644f6cb
eliminated quiete_mode ref (turned into proper argument);
wenzelm
parents:
26423
diff
changeset
|
47 |
val add_record: bool -> string list * string -> string option -> (string * string * mixfix) list |
16458 | 48 |
-> theory -> theory |
26477
ecf06644f6cb
eliminated quiete_mode ref (turned into proper argument);
wenzelm
parents:
26423
diff
changeset
|
49 |
val add_record_i: bool -> string list * string -> (typ list * string) option |
16458 | 50 |
-> (string * typ * mixfix) list -> theory -> theory |
18708 | 51 |
val setup: theory -> theory |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
52 |
end; |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
53 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
54 |
|
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31136
diff
changeset
|
55 |
structure Record: RECORD = |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
56 |
struct |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
57 |
|
21546 | 58 |
val eq_reflection = thm "eq_reflection"; |
27104
791607529f6d
rep_datatype command now takes list of constructors as input arguments
haftmann
parents:
26957
diff
changeset
|
59 |
val Pair_eq = thm "Product_Type.prod.inject"; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
60 |
val atomize_all = thm "HOL.atomize_all"; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
61 |
val atomize_imp = thm "HOL.atomize_imp"; |
17960 | 62 |
val meta_allE = thm "Pure.meta_allE"; |
63 |
val prop_subst = thm "prop_subst"; |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
64 |
val Pair_sel_convs = [fst_conv,snd_conv]; |
26359 | 65 |
val K_record_comp = @{thm "K_record_comp"}; |
66 |
val K_comp_convs = [@{thm o_apply}, K_record_comp] |
|
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
67 |
val transitive_thm = thm "transitive"; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
68 |
val o_assoc = @{thm "o_assoc"}; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
69 |
val id_apply = @{thm id_apply}; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
70 |
val id_o_apps = [@{thm id_apply}, @{thm id_o}, @{thm o_id}]; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
71 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
72 |
val refl_conj_eq = thm "refl_conj_eq"; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
73 |
val meta_all_sameI = thm "meta_all_sameI"; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
74 |
val meta_iffD2 = thm "meta_iffD2"; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
75 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
76 |
val surject_assistI = @{thm "istuple_surjective_proof_assistI"}; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
77 |
val surject_assist_idE = @{thm "istuple_surjective_proof_assist_idE"}; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
78 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
79 |
val updacc_accessor_eqE = @{thm "update_accessor_accessor_eqE"}; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
80 |
val updacc_updator_eqE = @{thm "update_accessor_updator_eqE"}; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
81 |
val updacc_eq_idI = @{thm "istuple_update_accessor_eq_assist_idI"}; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
82 |
val updacc_eq_triv = @{thm "istuple_update_accessor_eq_assist_triv"}; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
83 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
84 |
val updacc_foldE = @{thm "update_accessor_congruence_foldE"}; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
85 |
val updacc_unfoldE = @{thm "update_accessor_congruence_unfoldE"}; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
86 |
val updacc_noopE = @{thm "update_accessor_noopE"}; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
87 |
val updacc_noop_compE = @{thm "update_accessor_noop_compE"}; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
88 |
val updacc_cong_idI = @{thm "update_accessor_cong_assist_idI"}; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
89 |
val updacc_cong_triv = @{thm "update_accessor_cong_assist_triv"}; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
90 |
val updacc_cong_from_eq = @{thm "istuple_update_accessor_cong_from_eq"}; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
91 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
92 |
val o_eq_dest = thm "o_eq_dest"; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
93 |
val o_eq_id_dest = thm "o_eq_id_dest"; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
94 |
val o_eq_dest_lhs = thm "o_eq_dest_lhs"; |
11832 | 95 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
96 |
(** name components **) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
97 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
98 |
val rN = "r"; |
15215 | 99 |
val wN = "w"; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
100 |
val moreN = "more"; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
101 |
val schemeN = "_scheme"; |
17261 | 102 |
val ext_typeN = "_ext_type"; |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
103 |
val inner_typeN = "_inner_type"; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
104 |
val extN ="_ext"; |
15215 | 105 |
val casesN = "_cases"; |
14709
d01983034ded
tuned HOL/record package; enabled record_upd_simproc by default.
schirmer
parents:
14702
diff
changeset
|
106 |
val ext_dest = "_sel"; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
107 |
val updateN = "_update"; |
15215 | 108 |
val updN = "_upd"; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
109 |
val makeN = "make"; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
110 |
val fields_selN = "fields"; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
111 |
val extendN = "extend"; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
112 |
val truncateN = "truncate"; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
113 |
|
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31136
diff
changeset
|
114 |
(*see typedef.ML*) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
115 |
val RepN = "Rep_"; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
116 |
val AbsN = "Abs_"; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
117 |
|
32335 | 118 |
|
119 |
||
4894 | 120 |
(*** utilities ***) |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
121 |
|
14709
d01983034ded
tuned HOL/record package; enabled record_upd_simproc by default.
schirmer
parents:
14702
diff
changeset
|
122 |
fun but_last xs = fst (split_last xs); |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
123 |
|
19748 | 124 |
fun varifyT midx = |
125 |
let fun varify (a, S) = TVar ((a, midx + 1), S); |
|
126 |
in map_type_tfree varify end; |
|
127 |
||
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
128 |
fun domain_type' T = |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
129 |
domain_type T handle Match => T; |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
130 |
|
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
131 |
fun range_type' T = |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
132 |
range_type T handle Match => T; |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
133 |
|
32335 | 134 |
|
5698 | 135 |
(* messages *) |
136 |
||
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
137 |
fun trace_thm str thm = |
32091
30e2ffbba718
proper context for Display.pretty_thm etc. or old-style versions Display.pretty_thm_global, Display.pretty_thm_without_context etc.;
wenzelm
parents:
31902
diff
changeset
|
138 |
tracing (str ^ (Pretty.string_of (Display.pretty_thm_without_context thm))); |
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
139 |
|
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
140 |
fun trace_thms str thms = |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
141 |
(tracing str; map (trace_thm "") thms); |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
142 |
|
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
143 |
fun trace_term str t = |
26957 | 144 |
tracing (str ^ Syntax.string_of_term_global Pure.thy t); |
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
145 |
|
32335 | 146 |
|
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
147 |
(* timing *) |
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
148 |
|
25179 | 149 |
val timing = ref false; |
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
150 |
fun timeit_msg s x = if !timing then (warning s; timeit x) else x (); |
16379 | 151 |
fun timing_msg s = if !timing then warning s else (); |
17261 | 152 |
|
32335 | 153 |
|
12255 | 154 |
(* syntax *) |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
155 |
|
12247 | 156 |
fun prune n xs = Library.drop (n, xs); |
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30345
diff
changeset
|
157 |
fun prefix_base s = Long_Name.map_base_name (fn bname => s ^ bname); |
11832 | 158 |
|
11927
96f267adc029
provodes induct/cases for use with corresponding Isar methods;
wenzelm
parents:
11923
diff
changeset
|
159 |
val Trueprop = HOLogic.mk_Trueprop; |
96f267adc029
provodes induct/cases for use with corresponding Isar methods;
wenzelm
parents:
11923
diff
changeset
|
160 |
fun All xs t = Term.list_all_free (xs, t); |
4894 | 161 |
|
11934
6c1bf72430b6
derived operations are now: make, extend, truncate (cf. derived_defs);
wenzelm
parents:
11927
diff
changeset
|
162 |
infix 9 $$; |
6c1bf72430b6
derived operations are now: make, extend, truncate (cf. derived_defs);
wenzelm
parents:
11927
diff
changeset
|
163 |
infix 0 :== ===; |
6c1bf72430b6
derived operations are now: make, extend, truncate (cf. derived_defs);
wenzelm
parents:
11927
diff
changeset
|
164 |
infixr 0 ==>; |
6c1bf72430b6
derived operations are now: make, extend, truncate (cf. derived_defs);
wenzelm
parents:
11927
diff
changeset
|
165 |
|
6c1bf72430b6
derived operations are now: make, extend, truncate (cf. derived_defs);
wenzelm
parents:
11927
diff
changeset
|
166 |
val (op $$) = Term.list_comb; |
24255 | 167 |
val (op :==) = PrimitiveDefs.mk_defpair; |
11927
96f267adc029
provodes induct/cases for use with corresponding Isar methods;
wenzelm
parents:
11923
diff
changeset
|
168 |
val (op ===) = Trueprop o HOLogic.mk_eq; |
96f267adc029
provodes induct/cases for use with corresponding Isar methods;
wenzelm
parents:
11923
diff
changeset
|
169 |
val (op ==>) = Logic.mk_implies; |
96f267adc029
provodes induct/cases for use with corresponding Isar methods;
wenzelm
parents:
11923
diff
changeset
|
170 |
|
32335 | 171 |
|
11832 | 172 |
(* morphisms *) |
173 |
||
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
174 |
fun mk_RepN name = suffix ext_typeN (prefix_base RepN name); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
175 |
fun mk_AbsN name = suffix ext_typeN (prefix_base AbsN name); |
11832 | 176 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
177 |
fun mk_Rep name repT absT = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
178 |
Const (suffix ext_typeN (prefix_base RepN name),absT --> repT); |
11832 | 179 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
180 |
fun mk_Abs name repT absT = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
181 |
Const (mk_AbsN name,repT --> absT); |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
182 |
|
32335 | 183 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
184 |
(* constructor *) |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
185 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
186 |
fun mk_extC (name,T) Ts = (suffix extN name, Ts ---> T); |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
187 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
188 |
fun mk_ext (name,T) ts = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
189 |
let val Ts = map fastype_of ts |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
190 |
in list_comb (Const (mk_extC (name,T) Ts),ts) end; |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
191 |
|
32335 | 192 |
|
15215 | 193 |
(* cases *) |
194 |
||
195 |
fun mk_casesC (name,T,vT) Ts = (suffix casesN name, (Ts ---> vT) --> T --> vT) |
|
196 |
||
197 |
fun mk_cases (name,T,vT) f = |
|
17261 | 198 |
let val Ts = binder_types (fastype_of f) |
15215 | 199 |
in Const (mk_casesC (name,T,vT) Ts) $ f end; |
17261 | 200 |
|
32335 | 201 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
202 |
(* selector *) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
203 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
204 |
fun mk_selC sT (c,T) = (c,sT --> T); |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
205 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
206 |
fun mk_sel s (c,T) = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
207 |
let val sT = fastype_of s |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
208 |
in Const (mk_selC sT (c,T)) $ s end; |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
209 |
|
32335 | 210 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
211 |
(* updates *) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
212 |
|
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
213 |
fun mk_updC sfx sT (c,T) = (suffix sfx c, (T --> T) --> sT --> sT); |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
214 |
|
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
215 |
fun mk_upd' sfx c v sT = |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
216 |
let val vT = domain_type (fastype_of v); |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
217 |
in Const (mk_updC sfx sT (c, vT)) $ v end; |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
218 |
|
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
219 |
fun mk_upd sfx c v s = mk_upd' sfx c v (fastype_of s) $ s |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
220 |
|
32335 | 221 |
|
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
222 |
(* types *) |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
223 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
224 |
fun dest_recT (typ as Type (c_ext_type, Ts as (T::_))) = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
225 |
(case try (unsuffix ext_typeN) c_ext_type of |
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31136
diff
changeset
|
226 |
NONE => raise TYPE ("Record.dest_recT", [typ], []) |
15570 | 227 |
| SOME c => ((c, Ts), List.last Ts)) |
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31136
diff
changeset
|
228 |
| dest_recT typ = raise TYPE ("Record.dest_recT", [typ], []); |
5197 | 229 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
230 |
fun is_recT T = |
17261 | 231 |
(case try dest_recT T of NONE => false | SOME _ => true); |
11833 | 232 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
233 |
fun dest_recTs T = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
234 |
let val ((c, Ts), U) = dest_recT T |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
235 |
in (c, Ts) :: dest_recTs U |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
236 |
end handle TYPE _ => []; |
14255 | 237 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
238 |
fun last_extT T = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
239 |
let val ((c, Ts), U) = dest_recT T |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
240 |
in (case last_extT U of |
15531 | 241 |
NONE => SOME (c,Ts) |
242 |
| SOME l => SOME l) |
|
243 |
end handle TYPE _ => NONE |
|
14255 | 244 |
|
17261 | 245 |
fun rec_id i T = |
15273
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
246 |
let val rTs = dest_recTs T |
15570 | 247 |
val rTs' = if i < 0 then rTs else Library.take (i,rTs) |
248 |
in Library.foldl (fn (s,(c,T)) => s ^ c) ("",rTs') end; |
|
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
249 |
|
32335 | 250 |
|
251 |
||
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
252 |
(*** extend theory by record definition ***) |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
253 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
254 |
(** record info **) |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
255 |
|
14255 | 256 |
(* type record_info and parent_info *) |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
257 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
258 |
type record_info = |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
259 |
{args: (string * sort) list, |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
260 |
parent: (typ list * string) option, |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
261 |
fields: (string * typ) list, |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
262 |
extension: (string * typ list), |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
263 |
induct: thm, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
264 |
extdef: thm |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
265 |
}; |
11927
96f267adc029
provodes induct/cases for use with corresponding Isar methods;
wenzelm
parents:
11923
diff
changeset
|
266 |
|
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
267 |
fun make_record_info args parent fields extension induct extdef = |
17261 | 268 |
{args = args, parent = parent, fields = fields, extension = extension, |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
269 |
induct = induct, extdef = extdef}: record_info; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
270 |
|
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
271 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
272 |
type parent_info = |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
273 |
{name: string, |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
274 |
fields: (string * typ) list, |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
275 |
extension: (string * typ list), |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
276 |
induct: thm, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
277 |
extdef: thm |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
278 |
}; |
11927
96f267adc029
provodes induct/cases for use with corresponding Isar methods;
wenzelm
parents:
11923
diff
changeset
|
279 |
|
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
280 |
fun make_parent_info name fields extension induct extdef = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
281 |
{name = name, fields = fields, extension = extension, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
282 |
induct = induct, extdef = extdef}: parent_info; |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
283 |
|
22846 | 284 |
|
285 |
(* theory data *) |
|
5001 | 286 |
|
7178 | 287 |
type record_data = |
288 |
{records: record_info Symtab.table, |
|
289 |
sel_upd: |
|
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
290 |
{selectors: (int * bool) Symtab.table, |
7178 | 291 |
updates: string Symtab.table, |
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
292 |
simpset: Simplifier.simpset, |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
293 |
defset: Simplifier.simpset, |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
294 |
foldcong: Simplifier.simpset, |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
295 |
unfoldcong: Simplifier.simpset}, |
14255 | 296 |
equalities: thm Symtab.table, |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
297 |
extinjects: thm list, |
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
298 |
extsplit: thm Symtab.table, (* maps extension name to split rule *) |
17261 | 299 |
splits: (thm*thm*thm*thm) Symtab.table, (* !!,!,EX - split-equalities,induct rule *) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
300 |
extfields: (string*typ) list Symtab.table, (* maps extension to its fields *) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
301 |
fieldext: (string*typ list) Symtab.table (* maps field to its extension *) |
14255 | 302 |
}; |
7178 | 303 |
|
17261 | 304 |
fun make_record_data |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
305 |
records sel_upd equalities extinjects extsplit splits extfields fieldext = |
17261 | 306 |
{records = records, sel_upd = sel_upd, |
307 |
equalities = equalities, extinjects=extinjects, extsplit = extsplit, splits = splits, |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
308 |
extfields = extfields, fieldext = fieldext }: record_data; |
7178 | 309 |
|
16458 | 310 |
structure RecordsData = TheoryDataFun |
22846 | 311 |
( |
7178 | 312 |
type T = record_data; |
313 |
val empty = |
|
314 |
make_record_data Symtab.empty |
|
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
315 |
{selectors = Symtab.empty, updates = Symtab.empty, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
316 |
simpset = HOL_basic_ss, defset = HOL_basic_ss, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
317 |
foldcong = HOL_basic_ss, unfoldcong = HOL_basic_ss} |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
318 |
Symtab.empty [] Symtab.empty Symtab.empty Symtab.empty Symtab.empty; |
7178 | 319 |
|
6556 | 320 |
val copy = I; |
16458 | 321 |
val extend = I; |
322 |
fun merge _ |
|
7178 | 323 |
({records = recs1, |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
324 |
sel_upd = {selectors = sels1, updates = upds1, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
325 |
simpset = ss1, defset = ds1, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
326 |
foldcong = fc1, unfoldcong = uc1}, |
14255 | 327 |
equalities = equalities1, |
17261 | 328 |
extinjects = extinjects1, |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
329 |
extsplit = extsplit1, |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
330 |
splits = splits1, |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
331 |
extfields = extfields1, |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
332 |
fieldext = fieldext1}, |
7178 | 333 |
{records = recs2, |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
334 |
sel_upd = {selectors = sels2, updates = upds2, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
335 |
simpset = ss2, defset = ds2, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
336 |
foldcong = fc2, unfoldcong = uc2}, |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
337 |
equalities = equalities2, |
17261 | 338 |
extinjects = extinjects2, |
339 |
extsplit = extsplit2, |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
340 |
splits = splits2, |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
341 |
extfields = extfields2, |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
342 |
fieldext = fieldext2}) = |
17261 | 343 |
make_record_data |
7178 | 344 |
(Symtab.merge (K true) (recs1, recs2)) |
345 |
{selectors = Symtab.merge (K true) (sels1, sels2), |
|
346 |
updates = Symtab.merge (K true) (upds1, upds2), |
|
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
347 |
simpset = Simplifier.merge_ss (ss1, ss2), |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
348 |
defset = Simplifier.merge_ss (ds1, ds2), |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
349 |
foldcong = Simplifier.merge_ss (fc1, fc2), |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
350 |
unfoldcong = Simplifier.merge_ss (uc1, uc2)} |
22634 | 351 |
(Symtab.merge Thm.eq_thm_prop (equalities1, equalities2)) |
352 |
(Library.merge Thm.eq_thm_prop (extinjects1, extinjects2)) |
|
353 |
(Symtab.merge Thm.eq_thm_prop (extsplit1,extsplit2)) |
|
17261 | 354 |
(Symtab.merge (fn ((a,b,c,d),(w,x,y,z)) |
355 |
=> Thm.eq_thm (a,w) andalso Thm.eq_thm (b,x) andalso |
|
356 |
Thm.eq_thm (c,y) andalso Thm.eq_thm (d,z)) |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
357 |
(splits1, splits2)) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
358 |
(Symtab.merge (K true) (extfields1,extfields2)) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
359 |
(Symtab.merge (K true) (fieldext1,fieldext2)); |
22846 | 360 |
); |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
361 |
|
22846 | 362 |
fun print_records thy = |
363 |
let |
|
364 |
val {records = recs, ...} = RecordsData.get thy; |
|
26943
aec0d97a01c4
moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents:
26626
diff
changeset
|
365 |
val prt_typ = Syntax.pretty_typ_global thy; |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
366 |
|
22846 | 367 |
fun pretty_parent NONE = [] |
368 |
| pretty_parent (SOME (Ts, name)) = |
|
369 |
[Pretty.block [prt_typ (Type (name, Ts)), Pretty.str " +"]]; |
|
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
370 |
|
22846 | 371 |
fun pretty_field (c, T) = Pretty.block |
372 |
[Pretty.str (Sign.extern_const thy c), Pretty.str " ::", |
|
373 |
Pretty.brk 1, Pretty.quote (prt_typ T)]; |
|
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
374 |
|
22846 | 375 |
fun pretty_record (name, {args, parent, fields, ...}: record_info) = |
376 |
Pretty.block (Pretty.fbreaks (Pretty.block |
|
377 |
[prt_typ (Type (name, map TFree args)), Pretty.str " = "] :: |
|
378 |
pretty_parent parent @ map pretty_field fields)); |
|
379 |
in map pretty_record (Symtab.dest recs) |> Pretty.chunks |> Pretty.writeln end; |
|
5006 | 380 |
|
16458 | 381 |
|
7178 | 382 |
(* access 'records' *) |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
383 |
|
17412 | 384 |
val get_record = Symtab.lookup o #records o RecordsData.get; |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
385 |
|
4890 | 386 |
fun put_record name info thy = |
7178 | 387 |
let |
17261 | 388 |
val {records, sel_upd, equalities, extinjects,extsplit,splits,extfields,fieldext} = |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
389 |
RecordsData.get thy; |
17412 | 390 |
val data = make_record_data (Symtab.update (name, info) records) |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
391 |
sel_upd equalities extinjects extsplit splits extfields fieldext; |
7178 | 392 |
in RecordsData.put data thy end; |
393 |
||
22846 | 394 |
|
7178 | 395 |
(* access 'sel_upd' *) |
396 |
||
16458 | 397 |
val get_sel_upd = #sel_upd o RecordsData.get; |
7178 | 398 |
|
17510 | 399 |
val is_selector = Symtab.defined o #selectors o get_sel_upd; |
17412 | 400 |
val get_updates = Symtab.lookup o #updates o get_sel_upd; |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
401 |
fun get_ss_with_context getss thy = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
402 |
Simplifier.theory_context thy (getss (get_sel_upd thy)); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
403 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
404 |
val get_simpset = get_ss_with_context (#simpset); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
405 |
val get_sel_upd_defs = get_ss_with_context (#defset); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
406 |
val get_foldcong_ss = get_ss_with_context (#foldcong); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
407 |
val get_unfoldcong_ss = get_ss_with_context (#unfoldcong); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
408 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
409 |
fun get_update_details u thy = let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
410 |
val sel_upd = get_sel_upd thy; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
411 |
in case (Symtab.lookup (#updates sel_upd) u) of |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
412 |
SOME s => let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
413 |
val SOME (dep, ismore) = Symtab.lookup (#selectors sel_upd) s; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
414 |
in SOME (s, dep, ismore) end |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
415 |
| NONE => NONE end; |
7178 | 416 |
|
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
417 |
fun put_sel_upd names more depth simps defs (folds, unfolds) thy = |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
418 |
let |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
419 |
val all = names @ [more]; |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
420 |
val sels = map (rpair (depth, false)) names @ [(more, (depth, true))]; |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
421 |
val upds = map (suffix updateN) all ~~ all; |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
422 |
|
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
423 |
val {records, sel_upd = {selectors, updates, simpset, |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
424 |
defset, foldcong, unfoldcong}, |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
425 |
equalities, extinjects, extsplit, splits, extfields, |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
426 |
fieldext} = RecordsData.get thy; |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
427 |
val data = make_record_data records |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
428 |
{selectors = fold Symtab.update_new sels selectors, |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
429 |
updates = fold Symtab.update_new upds updates, |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
430 |
simpset = Simplifier.addsimps (simpset, simps), |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
431 |
defset = Simplifier.addsimps (defset, defs), |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
432 |
foldcong = foldcong addcongs folds, |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
433 |
unfoldcong = unfoldcong addcongs unfolds} |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
434 |
equalities extinjects extsplit splits extfields fieldext; |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
435 |
in RecordsData.put data thy end; |
22846 | 436 |
|
14079
1c22e5499eeb
- record_split_tac now also works for object-level universal quantifier
berghofe
parents:
13904
diff
changeset
|
437 |
(* access 'equalities' *) |
1c22e5499eeb
- record_split_tac now also works for object-level universal quantifier
berghofe
parents:
13904
diff
changeset
|
438 |
|
1c22e5499eeb
- record_split_tac now also works for object-level universal quantifier
berghofe
parents:
13904
diff
changeset
|
439 |
fun add_record_equalities name thm thy = |
1c22e5499eeb
- record_split_tac now also works for object-level universal quantifier
berghofe
parents:
13904
diff
changeset
|
440 |
let |
17261 | 441 |
val {records, sel_upd, equalities, extinjects, extsplit, splits, extfields,fieldext} = |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
442 |
RecordsData.get thy; |
17261 | 443 |
val data = make_record_data records sel_upd |
17412 | 444 |
(Symtab.update_new (name, thm) equalities) extinjects extsplit |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
445 |
splits extfields fieldext; |
14079
1c22e5499eeb
- record_split_tac now also works for object-level universal quantifier
berghofe
parents:
13904
diff
changeset
|
446 |
in RecordsData.put data thy end; |
1c22e5499eeb
- record_split_tac now also works for object-level universal quantifier
berghofe
parents:
13904
diff
changeset
|
447 |
|
17412 | 448 |
val get_equalities =Symtab.lookup o #equalities o RecordsData.get; |
14079
1c22e5499eeb
- record_split_tac now also works for object-level universal quantifier
berghofe
parents:
13904
diff
changeset
|
449 |
|
22846 | 450 |
|
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
451 |
(* access 'extinjects' *) |
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
452 |
|
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
453 |
fun add_extinjects thm thy = |
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
454 |
let |
17261 | 455 |
val {records, sel_upd, equalities, extinjects, extsplit, splits, extfields,fieldext} = |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
456 |
RecordsData.get thy; |
22846 | 457 |
val data = |
458 |
make_record_data records sel_upd equalities (insert Thm.eq_thm_prop thm extinjects) extsplit |
|
459 |
splits extfields fieldext; |
|
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
460 |
in RecordsData.put data thy end; |
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
461 |
|
22634 | 462 |
val get_extinjects = rev o #extinjects o RecordsData.get; |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
463 |
|
22846 | 464 |
|
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
465 |
(* access 'extsplit' *) |
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
466 |
|
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
467 |
fun add_extsplit name thm thy = |
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
468 |
let |
17261 | 469 |
val {records, sel_upd, equalities, extinjects, extsplit, splits, extfields,fieldext} = |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
470 |
RecordsData.get thy; |
17261 | 471 |
val data = make_record_data records sel_upd |
17412 | 472 |
equalities extinjects (Symtab.update_new (name, thm) extsplit) splits |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
473 |
extfields fieldext; |
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
474 |
in RecordsData.put data thy end; |
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
475 |
|
17412 | 476 |
val get_extsplit = Symtab.lookup o #extsplit o RecordsData.get; |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
477 |
|
26088 | 478 |
|
14255 | 479 |
(* access 'splits' *) |
480 |
||
481 |
fun add_record_splits name thmP thy = |
|
482 |
let |
|
17261 | 483 |
val {records, sel_upd, equalities, extinjects, extsplit, splits, extfields,fieldext} = |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
484 |
RecordsData.get thy; |
17261 | 485 |
val data = make_record_data records sel_upd |
17412 | 486 |
equalities extinjects extsplit (Symtab.update_new (name, thmP) splits) |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
487 |
extfields fieldext; |
14255 | 488 |
in RecordsData.put data thy end; |
489 |
||
17412 | 490 |
val get_splits = Symtab.lookup o #splits o RecordsData.get; |
14255 | 491 |
|
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
492 |
|
26088 | 493 |
(* parent/extension of named record *) |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
494 |
|
26088 | 495 |
val get_parent = (Option.join o Option.map #parent) oo (Symtab.lookup o #records o RecordsData.get); |
496 |
val get_extension = Option.map #extension oo (Symtab.lookup o #records o RecordsData.get); |
|
17261 | 497 |
|
14079
1c22e5499eeb
- record_split_tac now also works for object-level universal quantifier
berghofe
parents:
13904
diff
changeset
|
498 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
499 |
(* access 'extfields' *) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
500 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
501 |
fun add_extfields name fields thy = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
502 |
let |
17261 | 503 |
val {records, sel_upd, equalities, extinjects, extsplit,splits, extfields, fieldext} = |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
504 |
RecordsData.get thy; |
17261 | 505 |
val data = make_record_data records sel_upd |
506 |
equalities extinjects extsplit splits |
|
17412 | 507 |
(Symtab.update_new (name, fields) extfields) fieldext; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
508 |
in RecordsData.put data thy end; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
509 |
|
17412 | 510 |
val get_extfields = Symtab.lookup o #extfields o RecordsData.get; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
511 |
|
18858 | 512 |
fun get_extT_fields thy T = |
15059 | 513 |
let |
514 |
val ((name,Ts),moreT) = dest_recT T; |
|
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30345
diff
changeset
|
515 |
val recname = let val (nm::recn::rst) = rev (Long_Name.explode name) |
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30345
diff
changeset
|
516 |
in Long_Name.implode (rev (nm::rst)) end; |
15059 | 517 |
val midx = maxidx_of_typs (moreT::Ts); |
19748 | 518 |
val varifyT = varifyT midx; |
18858 | 519 |
val {records,extfields,...} = RecordsData.get thy; |
18931 | 520 |
val (flds,(more,_)) = split_last (Symtab.lookup_list extfields name); |
17412 | 521 |
val args = map varifyT (snd (#extension (the (Symtab.lookup records recname)))); |
15058 | 522 |
|
19748 | 523 |
val subst = fold (Sign.typ_match thy) (but_last args ~~ but_last Ts) (Vartab.empty); |
15059 | 524 |
val flds' = map (apsnd ((Envir.norm_type subst) o varifyT)) flds; |
525 |
in (flds',(more,moreT)) end; |
|
15058 | 526 |
|
18858 | 527 |
fun get_recT_fields thy T = |
17261 | 528 |
let |
18858 | 529 |
val (root_flds,(root_more,root_moreT)) = get_extT_fields thy T; |
17261 | 530 |
val (rest_flds,rest_more) = |
18858 | 531 |
if is_recT root_moreT then get_recT_fields thy root_moreT |
15059 | 532 |
else ([],(root_more,root_moreT)); |
533 |
in (root_flds@rest_flds,rest_more) end; |
|
534 |
||
15058 | 535 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
536 |
(* access 'fieldext' *) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
537 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
538 |
fun add_fieldext extname_types fields thy = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
539 |
let |
17261 | 540 |
val {records, sel_upd, equalities, extinjects, extsplit, splits, extfields, fieldext} = |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
541 |
RecordsData.get thy; |
17261 | 542 |
val fieldext' = |
17412 | 543 |
fold (fn field => Symtab.update_new (field, extname_types)) fields fieldext; |
17261 | 544 |
val data=make_record_data records sel_upd equalities extinjects extsplit |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
545 |
splits extfields fieldext'; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
546 |
in RecordsData.put data thy end; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
547 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
548 |
|
17412 | 549 |
val get_fieldext = Symtab.lookup o #fieldext o RecordsData.get; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
550 |
|
21962 | 551 |
|
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
552 |
(* parent records *) |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
553 |
|
15531 | 554 |
fun add_parents thy NONE parents = parents |
555 |
| add_parents thy (SOME (types, name)) parents = |
|
12247 | 556 |
let |
557 |
fun err msg = error (msg ^ " parent record " ^ quote name); |
|
12255 | 558 |
|
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
559 |
val {args, parent, fields, extension, induct, extdef} = |
15531 | 560 |
(case get_record thy name of SOME info => info | NONE => err "Unknown"); |
12247 | 561 |
val _ = if length types <> length args then err "Bad number of arguments for" else (); |
12255 | 562 |
|
12247 | 563 |
fun bad_inst ((x, S), T) = |
22578 | 564 |
if Sign.of_sort thy (T, S) then NONE else SOME x |
15570 | 565 |
val bads = List.mapPartial bad_inst (args ~~ types); |
21962 | 566 |
val _ = null bads orelse err ("Ill-sorted instantiation of " ^ commas bads ^ " in"); |
12255 | 567 |
|
12247 | 568 |
val inst = map fst args ~~ types; |
17377 | 569 |
val subst = Term.map_type_tfree (the o AList.lookup (op =) inst o fst); |
15570 | 570 |
val parent' = Option.map (apfst (map subst)) parent; |
12247 | 571 |
val fields' = map (apsnd subst) fields; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
572 |
val extension' = apsnd (map subst) extension; |
12247 | 573 |
in |
12255 | 574 |
add_parents thy parent' |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
575 |
(make_parent_info name fields' extension' induct extdef :: parents) |
12247 | 576 |
end; |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
577 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
578 |
|
21962 | 579 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
580 |
(** concrete syntax for records **) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
581 |
|
22693 | 582 |
(* decode type *) |
583 |
||
584 |
fun decode_type thy t = |
|
585 |
let |
|
23578 | 586 |
fun get_sort xs n = AList.lookup (op =) xs (n: indexname) |> the_default (Sign.defaultS thy); |
22693 | 587 |
val map_sort = Sign.intern_sort thy; |
588 |
in |
|
589 |
Syntax.typ_of_term (get_sort (Syntax.term_sorts map_sort t)) map_sort t |
|
590 |
|> Sign.intern_tycons thy |
|
591 |
end; |
|
592 |
||
593 |
||
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
594 |
(* parse translations *) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
595 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
596 |
fun gen_field_tr mark sfx (t as Const (c, _) $ Const (name, _) $ arg) = |
25705 | 597 |
if c = mark then Syntax.const (suffix sfx name) $ (Abs ("_",dummyT, arg)) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
598 |
else raise TERM ("gen_field_tr: " ^ mark, [t]) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
599 |
| gen_field_tr mark _ t = raise TERM ("gen_field_tr: " ^ mark, [t]); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
600 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
601 |
fun gen_fields_tr sep mark sfx (tm as Const (c, _) $ t $ u) = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
602 |
if c = sep then gen_field_tr mark sfx t :: gen_fields_tr sep mark sfx u |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
603 |
else [gen_field_tr mark sfx tm] |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
604 |
| gen_fields_tr _ mark sfx tm = [gen_field_tr mark sfx tm]; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
605 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
606 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
607 |
fun record_update_tr [t, u] = |
21078 | 608 |
Library.foldr (op $) (rev (gen_fields_tr "_updates" "_update" updateN u), t) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
609 |
| record_update_tr ts = raise TERM ("record_update_tr", ts); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
610 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
611 |
fun update_name_tr (Free (x, T) :: ts) = Free (suffix updateN x, T) $$ ts |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
612 |
| update_name_tr (Const (x, T) :: ts) = Const (suffix updateN x, T) $$ ts |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
613 |
| update_name_tr (((c as Const ("_constrain", _)) $ t $ ty) :: ts) = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
614 |
(c $ update_name_tr [t] $ (Syntax.const "fun" $ ty $ Syntax.const "dummy")) $$ ts |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
615 |
| update_name_tr ts = raise TERM ("update_name_tr", ts); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
616 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
617 |
fun dest_ext_field mark (t as (Const (c,_) $ Const (name,_) $ arg)) = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
618 |
if c = mark then (name,arg) else raise TERM ("dest_ext_field: " ^ mark, [t]) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
619 |
| dest_ext_field _ t = raise TERM ("dest_ext_field", [t]) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
620 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
621 |
fun dest_ext_fields sep mark (trm as (Const (c,_) $ t $ u)) = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
622 |
if c = sep then dest_ext_field mark t::dest_ext_fields sep mark u |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
623 |
else [dest_ext_field mark trm] |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
624 |
| dest_ext_fields _ mark t = [dest_ext_field mark t] |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
625 |
|
21772 | 626 |
fun gen_ext_fields_tr sep mark sfx more ctxt t = |
17261 | 627 |
let |
21772 | 628 |
val thy = ProofContext.theory_of ctxt; |
14709
d01983034ded
tuned HOL/record package; enabled record_upd_simproc by default.
schirmer
parents:
14702
diff
changeset
|
629 |
val msg = "error in record input: "; |
17261 | 630 |
val fieldargs = dest_ext_fields sep mark t; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
631 |
fun splitargs (field::fields) ((name,arg)::fargs) = |
14709
d01983034ded
tuned HOL/record package; enabled record_upd_simproc by default.
schirmer
parents:
14702
diff
changeset
|
632 |
if can (unsuffix name) field |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
633 |
then let val (args,rest) = splitargs fields fargs |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
634 |
in (arg::args,rest) end |
14709
d01983034ded
tuned HOL/record package; enabled record_upd_simproc by default.
schirmer
parents:
14702
diff
changeset
|
635 |
else raise TERM (msg ^ "expecting field " ^ field ^ " but got " ^ name, [t]) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
636 |
| splitargs [] (fargs as (_::_)) = ([],fargs) |
14709
d01983034ded
tuned HOL/record package; enabled record_upd_simproc by default.
schirmer
parents:
14702
diff
changeset
|
637 |
| splitargs (_::_) [] = raise TERM (msg ^ "expecting more fields", [t]) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
638 |
| splitargs _ _ = ([],[]); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
639 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
640 |
fun mk_ext (fargs as (name,arg)::_) = |
18858 | 641 |
(case get_fieldext thy (Sign.intern_const thy name) of |
642 |
SOME (ext,_) => (case get_extfields thy ext of |
|
17261 | 643 |
SOME flds |
644 |
=> let val (args,rest) = |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
645 |
splitargs (map fst (but_last flds)) fargs; |
17261 | 646 |
val more' = mk_ext rest; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
647 |
in list_comb (Syntax.const (suffix sfx ext),args@[more']) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
648 |
end |
15531 | 649 |
| NONE => raise TERM(msg ^ "no fields defined for " |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
650 |
^ ext,[t])) |
15531 | 651 |
| NONE => raise TERM (msg ^ name ^" is no proper field",[t])) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
652 |
| mk_ext [] = more |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
653 |
|
17261 | 654 |
in mk_ext fieldargs end; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
655 |
|
21772 | 656 |
fun gen_ext_type_tr sep mark sfx more ctxt t = |
17261 | 657 |
let |
21772 | 658 |
val thy = ProofContext.theory_of ctxt; |
14709
d01983034ded
tuned HOL/record package; enabled record_upd_simproc by default.
schirmer
parents:
14702
diff
changeset
|
659 |
val msg = "error in record-type input: "; |
17261 | 660 |
val fieldargs = dest_ext_fields sep mark t; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
661 |
fun splitargs (field::fields) ((name,arg)::fargs) = |
14709
d01983034ded
tuned HOL/record package; enabled record_upd_simproc by default.
schirmer
parents:
14702
diff
changeset
|
662 |
if can (unsuffix name) field |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
663 |
then let val (args,rest) = splitargs fields fargs |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
664 |
in (arg::args,rest) end |
14709
d01983034ded
tuned HOL/record package; enabled record_upd_simproc by default.
schirmer
parents:
14702
diff
changeset
|
665 |
else raise TERM (msg ^ "expecting field " ^ field ^ " but got " ^ name, [t]) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
666 |
| splitargs [] (fargs as (_::_)) = ([],fargs) |
14709
d01983034ded
tuned HOL/record package; enabled record_upd_simproc by default.
schirmer
parents:
14702
diff
changeset
|
667 |
| splitargs (_::_) [] = raise TERM (msg ^ "expecting more fields", [t]) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
668 |
| splitargs _ _ = ([],[]); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
669 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
670 |
fun mk_ext (fargs as (name,arg)::_) = |
18858 | 671 |
(case get_fieldext thy (Sign.intern_const thy name) of |
17261 | 672 |
SOME (ext,alphas) => |
18858 | 673 |
(case get_extfields thy ext of |
17261 | 674 |
SOME flds |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
675 |
=> (let |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
676 |
val flds' = but_last flds; |
17261 | 677 |
val types = map snd flds'; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
678 |
val (args,rest) = splitargs (map fst flds') fargs; |
22693 | 679 |
val argtypes = map (Sign.certify_typ thy o decode_type thy) args; |
24867 | 680 |
val midx = fold (fn T => fn i => Int.max (maxidx_of_typ T, i)) |
19748 | 681 |
argtypes 0; |
682 |
val varifyT = varifyT midx; |
|
683 |
val vartypes = map varifyT types; |
|
684 |
||
685 |
val subst = fold (Sign.typ_match thy) (vartypes ~~ argtypes) |
|
686 |
Vartab.empty; |
|
17261 | 687 |
val alphas' = map ((Syntax.term_of_typ (! Syntax.show_sorts)) o |
19748 | 688 |
Envir.norm_type subst o varifyT) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
689 |
(but_last alphas); |
17261 | 690 |
|
691 |
val more' = mk_ext rest; |
|
692 |
in list_comb (Syntax.const (suffix sfx ext),alphas'@[more']) |
|
19750 | 693 |
end handle TYPE_MATCH => raise |
14709
d01983034ded
tuned HOL/record package; enabled record_upd_simproc by default.
schirmer
parents:
14702
diff
changeset
|
694 |
TERM (msg ^ "type is no proper record (extension)", [t])) |
15531 | 695 |
| NONE => raise TERM (msg ^ "no fields defined for " ^ ext,[t])) |
696 |
| NONE => raise TERM (msg ^ name ^" is no proper field",[t])) |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
697 |
| mk_ext [] = more |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
698 |
|
17261 | 699 |
in mk_ext fieldargs end; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
700 |
|
21772 | 701 |
fun gen_adv_record_tr sep mark sfx unit ctxt [t] = |
702 |
gen_ext_fields_tr sep mark sfx unit ctxt t |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
703 |
| gen_adv_record_tr _ _ _ _ _ ts = raise TERM ("gen_record_tr", ts); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
704 |
|
21772 | 705 |
fun gen_adv_record_scheme_tr sep mark sfx ctxt [t, more] = |
706 |
gen_ext_fields_tr sep mark sfx more ctxt t |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
707 |
| gen_adv_record_scheme_tr _ _ _ _ ts = raise TERM ("gen_record_scheme_tr", ts); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
708 |
|
21772 | 709 |
fun gen_adv_record_type_tr sep mark sfx unit ctxt [t] = |
710 |
gen_ext_type_tr sep mark sfx unit ctxt t |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
711 |
| gen_adv_record_type_tr _ _ _ _ _ ts = raise TERM ("gen_record_tr", ts); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
712 |
|
21772 | 713 |
fun gen_adv_record_type_scheme_tr sep mark sfx ctxt [t, more] = |
714 |
gen_ext_type_tr sep mark sfx more ctxt t |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
715 |
| gen_adv_record_type_scheme_tr _ _ _ _ ts = raise TERM ("gen_record_scheme_tr", ts); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
716 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
717 |
val adv_record_tr = gen_adv_record_tr "_fields" "_field" extN HOLogic.unit; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
718 |
val adv_record_scheme_tr = gen_adv_record_scheme_tr "_fields" "_field" extN; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
719 |
|
17261 | 720 |
val adv_record_type_tr = |
721 |
gen_adv_record_type_tr "_field_types" "_field_type" ext_typeN |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
722 |
(Syntax.term_of_typ false (HOLogic.unitT)); |
17261 | 723 |
val adv_record_type_scheme_tr = |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
724 |
gen_adv_record_type_scheme_tr "_field_types" "_field_type" ext_typeN; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
725 |
|
15215 | 726 |
|
24867 | 727 |
val parse_translation = |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
728 |
[("_record_update", record_update_tr), |
17261 | 729 |
("_update_name", update_name_tr)]; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
730 |
|
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
731 |
|
24867 | 732 |
val adv_parse_translation = |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
733 |
[("_record",adv_record_tr), |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
734 |
("_record_scheme",adv_record_scheme_tr), |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
735 |
("_record_type",adv_record_type_tr), |
17261 | 736 |
("_record_type_scheme",adv_record_type_scheme_tr)]; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
737 |
|
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
738 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
739 |
(* print translations *) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
740 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
741 |
val print_record_type_abbr = ref true; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
742 |
val print_record_type_as_fields = ref true; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
743 |
|
25705 | 744 |
fun gen_field_upds_tr' mark sfx (tm as Const (name_field, _) $ k $ u) = |
745 |
let val t = (case k of (Abs (_,_,(Abs (_,_,t)$Bound 0))) |
|
746 |
=> if null (loose_bnos t) then t else raise Match |
|
747 |
| Abs (x,_,t) => if null (loose_bnos t) then t else raise Match |
|
748 |
| _ => raise Match) |
|
749 |
||
750 |
(* (case k of (Const ("K_record",_)$t) => t |
|
751 |
| Abs (x,_,Const ("K_record",_)$t$Bound 0) => t |
|
752 |
| _ => raise Match)*) |
|
753 |
in |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
754 |
(case try (unsuffix sfx) name_field of |
15531 | 755 |
SOME name => |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
756 |
apfst (cons (Syntax.const mark $ Syntax.free name $ t)) (gen_field_upds_tr' mark sfx u) |
15531 | 757 |
| NONE => ([], tm)) |
25705 | 758 |
end |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
759 |
| gen_field_upds_tr' _ _ tm = ([], tm); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
760 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
761 |
fun record_update_tr' tm = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
762 |
let val (ts, u) = gen_field_upds_tr' "_update" updateN tm in |
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
763 |
if null ts then raise Match |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
764 |
else Syntax.const "_record_update" $ u $ |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
765 |
foldr1 (fn (v, w) => Syntax.const "_updates" $ v $ w) (rev ts) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
766 |
end; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
767 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
768 |
fun gen_field_tr' sfx tr' name = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
769 |
let val name_sfx = suffix sfx name |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
770 |
in (name_sfx, fn [t, u] => tr' (Syntax.const name_sfx $ t $ u) | _ => raise Match) end; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
771 |
|
21772 | 772 |
fun record_tr' sep mark record record_scheme unit ctxt t = |
17261 | 773 |
let |
21772 | 774 |
val thy = ProofContext.theory_of ctxt; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
775 |
fun field_lst t = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
776 |
(case strip_comb t of |
17600 | 777 |
(Const (ext,_),args as (_::_)) |
18858 | 778 |
=> (case try (unsuffix extN) (Sign.intern_const thy ext) of |
17261 | 779 |
SOME ext' |
18858 | 780 |
=> (case get_extfields thy ext' of |
17261 | 781 |
SOME flds |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
782 |
=> (let |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
783 |
val (f::fs) = but_last (map fst flds); |
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30345
diff
changeset
|
784 |
val flds' = Sign.extern_const thy f :: map Long_Name.base_name fs; |
17261 | 785 |
val (args',more) = split_last args; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
786 |
in (flds'~~args')@field_lst more end |
19841 | 787 |
handle Library.UnequalLengths => [("",t)]) |
15531 | 788 |
| NONE => [("",t)]) |
789 |
| NONE => [("",t)]) |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
790 |
| _ => [("",t)]) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
791 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
792 |
val (flds,(_,more)) = split_last (field_lst t); |
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
793 |
val _ = if null flds then raise Match else (); |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
794 |
val flds' = map (fn (n,t)=>Syntax.const mark$Syntax.const n$t) flds; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
795 |
val flds'' = foldr1 (fn (x,y) => Syntax.const sep$x$y) flds'; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
796 |
|
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
797 |
in if unit more |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
798 |
then Syntax.const record$flds'' |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
799 |
else Syntax.const record_scheme$flds''$more |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
800 |
end |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
801 |
|
17261 | 802 |
fun gen_record_tr' name = |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
803 |
let val name_sfx = suffix extN name; |
26065 | 804 |
val unit = (fn Const (@{const_syntax "Product_Type.Unity"},_) => true | _ => false); |
21772 | 805 |
fun tr' ctxt ts = record_tr' "_fields" "_field" "_record" "_record_scheme" unit ctxt |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
806 |
(list_comb (Syntax.const name_sfx,ts)) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
807 |
in (name_sfx,tr') |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
808 |
end |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
809 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
810 |
fun print_translation names = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
811 |
map (gen_field_tr' updateN record_update_tr') names; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
812 |
|
19748 | 813 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
814 |
(* record_type_abbr_tr' tries to reconstruct the record name type abbreviation from *) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
815 |
(* the (nested) extension types. *) |
21772 | 816 |
fun record_type_abbr_tr' default_tr' abbr alphas zeta lastExt schemeT ctxt tm = |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
817 |
let |
21772 | 818 |
val thy = ProofContext.theory_of ctxt; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
819 |
(* tm is term representation of a (nested) field type. We first reconstruct the *) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
820 |
(* type from tm so that we can continue on the type level rather then the term level.*) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
821 |
|
15273
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
822 |
(* WORKAROUND: |
17261 | 823 |
* If a record type occurs in an error message of type inference there |
15273
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
824 |
* may be some internal frees donoted by ??: |
17261 | 825 |
* (Const "_tfree",_)$Free ("??'a",_). |
826 |
||
827 |
* This will unfortunately be translated to Type ("??'a",[]) instead of |
|
828 |
* TFree ("??'a",_) by typ_of_term, which will confuse unify below. |
|
15273
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
829 |
* fixT works around. |
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
830 |
*) |
17261 | 831 |
fun fixT (T as Type (x,[])) = |
18858 | 832 |
if String.isPrefix "??'" x then TFree (x,Sign.defaultS thy) else T |
15273
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
833 |
| fixT (Type (x,xs)) = Type (x,map fixT xs) |
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
834 |
| fixT T = T; |
17261 | 835 |
|
22693 | 836 |
val T = fixT (decode_type thy tm); |
19748 | 837 |
val midx = maxidx_of_typ T; |
838 |
val varifyT = varifyT midx; |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
839 |
|
17261 | 840 |
fun mk_type_abbr subst name alphas = |
19748 | 841 |
let val abbrT = Type (name, map (fn a => varifyT (TFree (a, Sign.defaultS thy))) alphas); |
17261 | 842 |
in Syntax.term_of_typ (! Syntax.show_sorts) |
18858 | 843 |
(Sign.extern_typ thy (Envir.norm_type subst abbrT)) end; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
844 |
|
24867 | 845 |
fun match rT T = (Sign.typ_match thy (varifyT rT,T) |
19748 | 846 |
Vartab.empty); |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
847 |
|
32335 | 848 |
in |
849 |
if !print_record_type_abbr then |
|
850 |
(case last_extT T of |
|
851 |
SOME (name, _) => |
|
852 |
if name = lastExt then |
|
853 |
(let |
|
854 |
val subst = match schemeT T |
|
855 |
in |
|
856 |
if HOLogic.is_unitT (Envir.norm_type subst (varifyT (TFree (zeta, Sign.defaultS thy)))) |
|
857 |
then mk_type_abbr subst abbr alphas |
|
858 |
else mk_type_abbr subst (suffix schemeN abbr) (alphas @ [zeta]) |
|
859 |
end handle TYPE_MATCH => default_tr' ctxt tm) |
|
860 |
else raise Match (* give print translation of specialised record a chance *) |
|
861 |
| _ => raise Match) |
|
21772 | 862 |
else default_tr' ctxt tm |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
863 |
end |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
864 |
|
21772 | 865 |
fun record_type_tr' sep mark record record_scheme ctxt t = |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
866 |
let |
21772 | 867 |
val thy = ProofContext.theory_of ctxt; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
868 |
|
22693 | 869 |
val T = decode_type thy t; |
870 |
val varifyT = varifyT (Term.maxidx_of_typ T); |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
871 |
|
18858 | 872 |
fun term_of_type T = Syntax.term_of_typ (!Syntax.show_sorts) (Sign.extern_typ thy T); |
17261 | 873 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
874 |
fun field_lst T = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
875 |
(case T of |
22219
61b5bab471ce
print translation for record types with empty-sorted type variables raise Match instead of producing an error
haftmann
parents:
21962
diff
changeset
|
876 |
Type (ext, args) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
877 |
=> (case try (unsuffix ext_typeN) ext of |
17261 | 878 |
SOME ext' |
18858 | 879 |
=> (case get_extfields thy ext' of |
17261 | 880 |
SOME flds |
18858 | 881 |
=> (case get_fieldext thy (fst (hd flds)) of |
22219
61b5bab471ce
print translation for record types with empty-sorted type variables raise Match instead of producing an error
haftmann
parents:
21962
diff
changeset
|
882 |
SOME (_, alphas) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
883 |
=> (let |
22219
61b5bab471ce
print translation for record types with empty-sorted type variables raise Match instead of producing an error
haftmann
parents:
21962
diff
changeset
|
884 |
val (f :: fs) = but_last flds; |
18858 | 885 |
val flds' = apfst (Sign.extern_const thy) f |
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30345
diff
changeset
|
886 |
:: map (apfst Long_Name.base_name) fs; |
22219
61b5bab471ce
print translation for record types with empty-sorted type variables raise Match instead of producing an error
haftmann
parents:
21962
diff
changeset
|
887 |
val (args', more) = split_last args; |
19748 | 888 |
val alphavars = map varifyT (but_last alphas); |
22219
61b5bab471ce
print translation for record types with empty-sorted type variables raise Match instead of producing an error
haftmann
parents:
21962
diff
changeset
|
889 |
val subst = fold2 (curry (Sign.typ_match thy)) |
61b5bab471ce
print translation for record types with empty-sorted type variables raise Match instead of producing an error
haftmann
parents:
21962
diff
changeset
|
890 |
alphavars args' Vartab.empty; |
61b5bab471ce
print translation for record types with empty-sorted type variables raise Match instead of producing an error
haftmann
parents:
21962
diff
changeset
|
891 |
val flds'' = (map o apsnd) |
61b5bab471ce
print translation for record types with empty-sorted type variables raise Match instead of producing an error
haftmann
parents:
21962
diff
changeset
|
892 |
(Envir.norm_type subst o varifyT) flds'; |
61b5bab471ce
print translation for record types with empty-sorted type variables raise Match instead of producing an error
haftmann
parents:
21962
diff
changeset
|
893 |
in flds'' @ field_lst more end |
61b5bab471ce
print translation for record types with empty-sorted type variables raise Match instead of producing an error
haftmann
parents:
21962
diff
changeset
|
894 |
handle TYPE_MATCH => [("", T)] |
61b5bab471ce
print translation for record types with empty-sorted type variables raise Match instead of producing an error
haftmann
parents:
21962
diff
changeset
|
895 |
| Library.UnequalLengths => [("", T)]) |
61b5bab471ce
print translation for record types with empty-sorted type variables raise Match instead of producing an error
haftmann
parents:
21962
diff
changeset
|
896 |
| NONE => [("", T)]) |
61b5bab471ce
print translation for record types with empty-sorted type variables raise Match instead of producing an error
haftmann
parents:
21962
diff
changeset
|
897 |
| NONE => [("", T)]) |
61b5bab471ce
print translation for record types with empty-sorted type variables raise Match instead of producing an error
haftmann
parents:
21962
diff
changeset
|
898 |
| NONE => [("", T)]) |
61b5bab471ce
print translation for record types with empty-sorted type variables raise Match instead of producing an error
haftmann
parents:
21962
diff
changeset
|
899 |
| _ => [("", T)]) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
900 |
|
22219
61b5bab471ce
print translation for record types with empty-sorted type variables raise Match instead of producing an error
haftmann
parents:
21962
diff
changeset
|
901 |
val (flds, (_, moreT)) = split_last (field_lst T); |
61b5bab471ce
print translation for record types with empty-sorted type variables raise Match instead of producing an error
haftmann
parents:
21962
diff
changeset
|
902 |
val flds' = map (fn (n, T) => Syntax.const mark $ Syntax.const n $ term_of_type T) flds; |
61b5bab471ce
print translation for record types with empty-sorted type variables raise Match instead of producing an error
haftmann
parents:
21962
diff
changeset
|
903 |
val flds'' = foldr1 (fn (x, y) => Syntax.const sep $ x $ y) flds' handle Empty => raise Match; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
904 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
905 |
in if not (!print_record_type_as_fields) orelse null flds then raise Match |
17261 | 906 |
else if moreT = HOLogic.unitT |
907 |
then Syntax.const record$flds'' |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
908 |
else Syntax.const record_scheme$flds''$term_of_type moreT |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
909 |
end |
17261 | 910 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
911 |
|
17261 | 912 |
fun gen_record_type_tr' name = |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
913 |
let val name_sfx = suffix ext_typeN name; |
21772 | 914 |
fun tr' ctxt ts = record_type_tr' "_field_types" "_field_type" |
915 |
"_record_type" "_record_type_scheme" ctxt |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
916 |
(list_comb (Syntax.const name_sfx,ts)) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
917 |
in (name_sfx,tr') |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
918 |
end |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
919 |
|
17261 | 920 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
921 |
fun gen_record_type_abbr_tr' abbr alphas zeta lastExt schemeT name = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
922 |
let val name_sfx = suffix ext_typeN name; |
17261 | 923 |
val default_tr' = record_type_tr' "_field_types" "_field_type" |
924 |
"_record_type" "_record_type_scheme" |
|
21772 | 925 |
fun tr' ctxt ts = |
926 |
record_type_abbr_tr' default_tr' abbr alphas zeta lastExt schemeT ctxt |
|
18858 | 927 |
(list_comb (Syntax.const name_sfx,ts)) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
928 |
in (name_sfx, tr') end; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
929 |
|
32335 | 930 |
|
931 |
||
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
932 |
(** record simprocs **) |
14358 | 933 |
|
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
934 |
val record_quick_and_dirty_sensitive = ref false; |
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
935 |
|
15215 | 936 |
|
18858 | 937 |
fun quick_and_dirty_prove stndrd thy asms prop tac = |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
938 |
if !record_quick_and_dirty_sensitive andalso !quick_and_dirty |
20049 | 939 |
then Goal.prove (ProofContext.init thy) [] [] |
940 |
(Logic.list_implies (map Logic.varify asms,Logic.varify prop)) |
|
29064 | 941 |
(K (SkipProof.cheat_tac @{theory HOL})) |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
942 |
(* standard can take quite a while for large records, thats why |
17261 | 943 |
* we varify the proposition manually here.*) |
20049 | 944 |
else let val prf = Goal.prove (ProofContext.init thy) [] asms prop tac; |
17261 | 945 |
in if stndrd then standard prf else prf end; |
15215 | 946 |
|
17261 | 947 |
fun quick_and_dirty_prf noopt opt () = |
948 |
if !record_quick_and_dirty_sensitive andalso !quick_and_dirty |
|
15215 | 949 |
then noopt () |
950 |
else opt (); |
|
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
951 |
|
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
952 |
fun is_sel_upd_pair thy (Const (s, t)) (Const (u, t')) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
953 |
= case (get_updates thy u) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
954 |
of SOME u_name => u_name = s |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
955 |
| NONE => raise TERM ("is_sel_upd_pair: not update", [Const (u, t')]); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
956 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
957 |
fun mk_comp f g = let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
958 |
val x = fastype_of g; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
959 |
val a = domain_type x; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
960 |
val b = range_type x; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
961 |
val c = range_type (fastype_of f); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
962 |
val T = (b --> c) --> ((a --> b) --> (a --> c)) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
963 |
in Const ("Fun.comp", T) $ f $ g end; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
964 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
965 |
fun mk_comp_id f = let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
966 |
val T = range_type (fastype_of f); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
967 |
in mk_comp (Const ("Fun.id", T --> T)) f end; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
968 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
969 |
fun get_updfuns (upd $ _ $ t) = upd :: get_updfuns t |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
970 |
| get_updfuns _ = []; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
971 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
972 |
fun get_accupd_simps thy term defset intros_tac = let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
973 |
val (acc, [body]) = strip_comb term; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
974 |
val recT = domain_type (fastype_of acc); |
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
975 |
val updfuns = sort_distinct TermOrd.fast_term_ord |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
976 |
(get_updfuns body); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
977 |
fun get_simp upd = let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
978 |
val T = domain_type (fastype_of upd); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
979 |
val lhs = mk_comp acc (upd $ Free ("f", T)); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
980 |
val rhs = if is_sel_upd_pair thy acc upd |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
981 |
then mk_comp (Free ("f", T)) acc else mk_comp_id acc; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
982 |
val prop = HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs)); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
983 |
val othm = Goal.prove (ProofContext.init thy) [] [] prop (fn prems => |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
984 |
EVERY [simp_tac defset 1, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
985 |
REPEAT_DETERM (intros_tac 1), |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
986 |
TRY (simp_tac (HOL_ss addsimps id_o_apps) 1)]); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
987 |
val dest = if is_sel_upd_pair thy acc upd |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
988 |
then o_eq_dest else o_eq_id_dest; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
989 |
in standard (othm RS dest) end; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
990 |
in map get_simp updfuns end; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
991 |
|
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
992 |
structure SymSymTab = Table(type key = string * string |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
993 |
val ord = prod_ord fast_string_ord fast_string_ord); |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
994 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
995 |
fun get_updupd_simp thy defset intros_tac u u' comp = let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
996 |
val f = Free ("f", domain_type (fastype_of u)); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
997 |
val f' = Free ("f'", domain_type (fastype_of u')); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
998 |
val lhs = mk_comp (u $ f) (u' $ f'); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
999 |
val rhs = if comp |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1000 |
then u $ mk_comp f f' |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1001 |
else mk_comp (u' $ f') (u $ f); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1002 |
val prop = HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs)); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1003 |
val othm = Goal.prove (ProofContext.init thy) [] [] prop (fn prems => |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1004 |
EVERY [simp_tac defset 1, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1005 |
REPEAT_DETERM (intros_tac 1), |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1006 |
TRY (simp_tac (HOL_ss addsimps [id_apply]) 1)]); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1007 |
val dest = if comp then o_eq_dest_lhs else o_eq_dest; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1008 |
in standard (othm RS dest) end; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1009 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1010 |
fun get_updupd_simps thy term defset intros_tac = let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1011 |
val recT = fastype_of term; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1012 |
val updfuns = get_updfuns term; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1013 |
val cname = fst o dest_Const; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1014 |
fun getswap u u' = get_updupd_simp thy defset intros_tac u u' |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1015 |
(cname u = cname u'); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1016 |
fun buildswapstoeq upd [] swaps = swaps |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1017 |
| buildswapstoeq upd (u::us) swaps = let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1018 |
val key = (cname u, cname upd); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1019 |
val newswaps = if SymSymTab.defined swaps key then swaps |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1020 |
else SymSymTab.insert (K true) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1021 |
(key, getswap u upd) swaps; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1022 |
in if cname u = cname upd then newswaps |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1023 |
else buildswapstoeq upd us newswaps end; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1024 |
fun swapsneeded [] prev seen swaps = map snd (SymSymTab.dest swaps) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1025 |
| swapsneeded (u::us) prev seen swaps = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1026 |
if Symtab.defined seen (cname u) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1027 |
then swapsneeded us prev seen |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1028 |
(buildswapstoeq u prev swaps) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1029 |
else swapsneeded us (u::prev) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1030 |
(Symtab.insert (K true) (cname u, ()) seen) swaps; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1031 |
in swapsneeded updfuns [] Symtab.empty SymSymTab.empty end; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1032 |
|
32745
192d58483fdf
Simplification of various aspects of the IsTuple component
Thomas Sewell <tsewell@nicta.com.au>
parents:
32744
diff
changeset
|
1033 |
val named_cterm_instantiate = IsTupleSupport.named_cterm_instantiate; |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1034 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1035 |
fun prove_unfold_defs thy ss T ex_simps ex_simprs prop = |
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1036 |
let |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1037 |
val defset = get_sel_upd_defs thy; |
32745
192d58483fdf
Simplification of various aspects of the IsTuple component
Thomas Sewell <tsewell@nicta.com.au>
parents:
32744
diff
changeset
|
1038 |
val in_tac = IsTupleSupport.istuple_intros_tac thy; |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1039 |
val prop' = Envir.beta_eta_contract prop; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1040 |
val (lhs, rhs) = Logic.dest_equals (Logic.strip_assums_concl prop'); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1041 |
val (head, args) = strip_comb lhs; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1042 |
val simps = if length args = 1 |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1043 |
then get_accupd_simps thy lhs defset in_tac |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1044 |
else get_updupd_simps thy lhs defset in_tac; |
16973 | 1045 |
in |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1046 |
Goal.prove (ProofContext.init thy) [] [] prop' (fn prems => |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1047 |
simp_tac (HOL_basic_ss addsimps (simps @ [K_record_comp])) 1 |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1048 |
THEN TRY (simp_tac (HOL_basic_ss addsimps ex_simps |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1049 |
addsimprocs ex_simprs) 1)) |
15203 | 1050 |
end; |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
1051 |
|
15215 | 1052 |
|
15059 | 1053 |
local |
16822 | 1054 |
fun eq (s1:string) (s2:string) = (s1 = s2); |
1055 |
fun has_field extfields f T = |
|
18931 | 1056 |
exists (fn (eN,_) => exists (eq f o fst) (Symtab.lookup_list extfields eN)) |
16822 | 1057 |
(dest_recTs T); |
25705 | 1058 |
|
1059 |
fun K_skeleton n (T as Type (_,[_,kT])) (b as Bound i) (Abs (x,xT,t)) = |
|
1060 |
if null (loose_bnos t) then ((n,kT),(Abs (x,xT,Bound (i+1)))) else ((n,T),b) |
|
1061 |
| K_skeleton n T b _ = ((n,T),b); |
|
1062 |
||
15059 | 1063 |
in |
14255 | 1064 |
(* record_simproc *) |
1065 |
(* Simplifies selections of an record update: |
|
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1066 |
* (1) S (S_update k r) = k (S r) |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1067 |
* (2) S (X_update k r) = S r |
14255 | 1068 |
* The simproc skips multiple updates at once, eg: |
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1069 |
* S (X_update x (Y_update y (S_update k r))) = k (S r) |
14255 | 1070 |
* But be careful in (2) because of the extendibility of records. |
1071 |
* - If S is a more-selector we have to make sure that the update on component |
|
1072 |
* X does not affect the selected subrecord. |
|
1073 |
* - If X is a more-selector we have to make sure that S is not in the updated |
|
17261 | 1074 |
* subrecord. |
14255 | 1075 |
*) |
13462 | 1076 |
val record_simproc = |
29064 | 1077 |
Simplifier.simproc @{theory HOL} "record_simp" ["x"] |
18858 | 1078 |
(fn thy => fn ss => fn t => |
16872 | 1079 |
(case t of (sel as Const (s, Type (_,[domS,rangeS])))$ |
1080 |
((upd as Const (u,Type(_,[_,Type (_,[rT,_])]))) $ k $ r)=> |
|
18858 | 1081 |
if is_selector thy s then |
1082 |
(case get_updates thy u of SOME u_name => |
|
13462 | 1083 |
let |
18858 | 1084 |
val {sel_upd={updates,...},extfields,...} = RecordsData.get thy; |
17261 | 1085 |
|
16872 | 1086 |
fun mk_eq_terms ((upd as Const (u,Type(_,[kT,_]))) $ k $ r) = |
17412 | 1087 |
(case Symtab.lookup updates u of |
15531 | 1088 |
NONE => NONE |
17261 | 1089 |
| SOME u_name |
14255 | 1090 |
=> if u_name = s |
24867 | 1091 |
then (case mk_eq_terms r of |
1092 |
NONE => |
|
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1093 |
let |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1094 |
val rv = ("r",rT) |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1095 |
val rb = Bound 0 |
25705 | 1096 |
val (kv,kb) = K_skeleton "k" kT (Bound 1) k; |
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1097 |
in SOME (upd$kb$rb,kb$(sel$rb),[kv,rv]) end |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1098 |
| SOME (trm,trm',vars) => |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1099 |
let |
25705 | 1100 |
val (kv,kb) = K_skeleton "k" kT (Bound (length vars)) k; |
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1101 |
in SOME (upd$kb$trm,kb$trm',kv::vars) end) |
16822 | 1102 |
else if has_field extfields u_name rangeS |
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1103 |
orelse has_field extfields s (domain_type kT) |
15531 | 1104 |
then NONE |
17261 | 1105 |
else (case mk_eq_terms r of |
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1106 |
SOME (trm,trm',vars) |
17261 | 1107 |
=> let |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1108 |
val (kv,kb) = |
25705 | 1109 |
K_skeleton "k" kT (Bound (length vars)) k; |
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1110 |
in SOME (upd$kb$trm,trm',kv::vars) end |
15531 | 1111 |
| NONE |
17261 | 1112 |
=> let |
1113 |
val rv = ("r",rT) |
|
14255 | 1114 |
val rb = Bound 0 |
25705 | 1115 |
val (kv,kb) = K_skeleton "k" kT (Bound 1) k; |
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1116 |
in SOME (upd$kb$rb,sel$rb,[kv,rv]) end)) |
17261 | 1117 |
| mk_eq_terms r = NONE |
13462 | 1118 |
in |
17261 | 1119 |
(case mk_eq_terms (upd$k$r) of |
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1120 |
SOME (trm,trm',vars) |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1121 |
=> SOME (prove_unfold_defs thy ss domS [] [] |
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
1122 |
(list_all(vars,(Logic.mk_equals (sel$trm, trm'))))) |
15531 | 1123 |
| NONE => NONE) |
13462 | 1124 |
end |
15531 | 1125 |
| NONE => NONE) |
17510 | 1126 |
else NONE |
15531 | 1127 |
| _ => NONE)); |
7178 | 1128 |
|
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1129 |
fun get_upd_acc_cong_thm upd acc thy simpset = let |
32745
192d58483fdf
Simplification of various aspects of the IsTuple component
Thomas Sewell <tsewell@nicta.com.au>
parents:
32744
diff
changeset
|
1130 |
val in_tac = IsTupleSupport.istuple_intros_tac thy; |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1131 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1132 |
val insts = [("upd", cterm_of thy upd), ("acc", cterm_of thy acc)] |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1133 |
val prop = concl_of (named_cterm_instantiate insts updacc_cong_triv); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1134 |
in Goal.prove (ProofContext.init thy) [] [] prop (fn prems => |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1135 |
EVERY [simp_tac simpset 1, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1136 |
REPEAT_DETERM (in_tac 1), |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1137 |
TRY (resolve_tac [updacc_cong_idI] 1)]) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1138 |
end; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1139 |
|
17261 | 1140 |
(* record_upd_simproc *) |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
1141 |
(* simplify multiple updates: |
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1142 |
* (1) "N_update y (M_update g (N_update x (M_update f r))) = |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1143 |
(N_update (y o x) (M_update (g o f) r))" |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
1144 |
* (2) "r(|M:= M r|) = r" |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1145 |
* In both cases "more" updates complicate matters: for this reason |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1146 |
* we omit considering further updates if doing so would introduce |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1147 |
* both a more update and an update to a field within it. |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
1148 |
*) |
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
1149 |
val record_upd_simproc = |
29064 | 1150 |
Simplifier.simproc @{theory HOL} "record_upd_simp" ["x"] |
18858 | 1151 |
(fn thy => fn ss => fn t => |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1152 |
let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1153 |
(* we can use more-updators with other updators as long |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1154 |
as none of the other updators go deeper than any more |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1155 |
updator. min here is the depth of the deepest other |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1156 |
updator, max the depth of the shallowest more updator *) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1157 |
fun include_depth (dep, true) (min, max) = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1158 |
if (min <= dep) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1159 |
then SOME (min, if dep <= max orelse max = ~1 then dep else max) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1160 |
else NONE |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1161 |
| include_depth (dep, false) (min, max) = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1162 |
if (dep <= max orelse max = ~1) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1163 |
then SOME (if min <= dep then dep else min, max) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1164 |
else NONE; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1165 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1166 |
fun getupdseq (term as (upd as Const (u, T)) $ f $ tm) min max = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1167 |
(case get_update_details u thy of |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1168 |
SOME (s, dep, ismore) => |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1169 |
(case include_depth (dep, ismore) (min, max) of |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1170 |
SOME (min', max') => let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1171 |
val (us, bs, _) = getupdseq tm min' max'; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1172 |
in ((upd, s, f) :: us, bs, fastype_of term) end |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1173 |
| NONE => ([], term, HOLogic.unitT)) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1174 |
| NONE => ([], term, HOLogic.unitT)) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1175 |
| getupdseq term _ _ = ([], term, HOLogic.unitT); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1176 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1177 |
val (upds, base, baseT) = getupdseq t 0 ~1; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1178 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1179 |
fun is_upd_noop s (f as Abs (n, T, Const (s', T') $ tm')) tm = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1180 |
if s = s' andalso null (loose_bnos tm') |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1181 |
andalso subst_bound (HOLogic.unit, tm') = tm |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1182 |
then (true, Abs (n, T, Const (s', T') $ Bound 1)) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1183 |
else (false, HOLogic.unit) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1184 |
| is_upd_noop s f tm = (false, HOLogic.unit); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1185 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1186 |
fun get_noop_simps (upd as Const (u, T)) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1187 |
(f as Abs (n, T', (acc as Const (s, T'')) $ _)) = let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1188 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1189 |
val ss = get_sel_upd_defs thy; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1190 |
val uathm = get_upd_acc_cong_thm upd acc thy ss; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1191 |
in [standard (uathm RS updacc_noopE), |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1192 |
standard (uathm RS updacc_noop_compE)] end; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1193 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1194 |
(* if f is constant then (f o g) = f. we know that K_skeleton |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1195 |
only returns constant abstractions thus when we see an |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1196 |
abstraction we can discard inner updates. *) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1197 |
fun add_upd (f as Abs _) fs = [f] |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1198 |
| add_upd f fs = (f :: fs); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1199 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1200 |
(* mk_updterm returns |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1201 |
* (orig-term-skeleton, simplified-skeleton, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1202 |
* variables, duplicate-updates, simp-flag, noop-simps) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1203 |
* |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1204 |
* where duplicate-updates is a table used to pass upward |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1205 |
* the list of update functions which can be composed |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1206 |
* into an update above them, simp-flag indicates whether |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1207 |
* any simplification was achieved, and noop-simps are |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1208 |
* used for eliminating case (2) defined above |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1209 |
*) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1210 |
fun mk_updterm ((upd as Const (u, T), s, f) :: upds) above term = let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1211 |
val (lhs, rhs, vars, dups, simp, noops) = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1212 |
mk_updterm upds (Symtab.update (u, ()) above) term; |
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
1213 |
val (fvar, skelf) = K_skeleton (Long_Name.base_name s) (domain_type T) |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1214 |
(Bound (length vars)) f; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1215 |
val (isnoop, skelf') = is_upd_noop s f term; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1216 |
val funT = domain_type T; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1217 |
fun mk_comp_local (f, f') = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1218 |
Const ("Fun.comp", funT --> funT --> funT) $ f $ f'; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1219 |
in if isnoop |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1220 |
then (upd $ skelf' $ lhs, rhs, vars, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1221 |
Symtab.update (u, []) dups, true, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1222 |
if Symtab.defined noops u then noops |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1223 |
else Symtab.update (u, get_noop_simps upd skelf') noops) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1224 |
else if Symtab.defined above u |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1225 |
then (upd $ skelf $ lhs, rhs, fvar :: vars, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1226 |
Symtab.map_default (u, []) (add_upd skelf) dups, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1227 |
true, noops) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1228 |
else case Symtab.lookup dups u of |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1229 |
SOME fs => |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1230 |
(upd $ skelf $ lhs, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1231 |
upd $ foldr1 mk_comp_local (add_upd skelf fs) $ rhs, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1232 |
fvar :: vars, dups, true, noops) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1233 |
| NONE => (upd $ skelf $ lhs, upd $ skelf $ rhs, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1234 |
fvar :: vars, dups, simp, noops) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1235 |
end |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1236 |
| mk_updterm [] above term = (Bound 0, Bound 0, [("r", baseT)], |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1237 |
Symtab.empty, false, Symtab.empty) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1238 |
| mk_updterm us above term = raise TERM ("mk_updterm match", |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1239 |
map (fn (x, y, z) => x) us); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1240 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1241 |
val (lhs, rhs, vars, dups, simp, noops) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1242 |
= mk_updterm upds Symtab.empty base; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1243 |
val noops' = flat (map snd (Symtab.dest noops)); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1244 |
in |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1245 |
if simp then |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1246 |
SOME (prove_unfold_defs thy ss baseT noops' [record_simproc] |
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
1247 |
(list_all(vars,(Logic.mk_equals (lhs, rhs))))) |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1248 |
else NONE |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1249 |
end) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1250 |
|
15059 | 1251 |
end |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
1252 |
|
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1253 |
|
14255 | 1254 |
(* record_eq_simproc *) |
1255 |
(* looks up the most specific record-equality. |
|
1256 |
* Note on efficiency: |
|
1257 |
* Testing equality of records boils down to the test of equality of all components. |
|
1258 |
* Therefore the complexity is: #components * complexity for single component. |
|
1259 |
* Especially if a record has a lot of components it may be better to split up |
|
1260 |
* the record first and do simplification on that (record_split_simp_tac). |
|
1261 |
* e.g. r(|lots of updates|) = x |
|
1262 |
* |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1263 |
* record_eq_simproc record_split_simp_tac |
17261 | 1264 |
* Complexity: #components * #updates #updates |
1265 |
* |
|
14255 | 1266 |
*) |
14079
1c22e5499eeb
- record_split_tac now also works for object-level universal quantifier
berghofe
parents:
13904
diff
changeset
|
1267 |
val record_eq_simproc = |
29064 | 1268 |
Simplifier.simproc @{theory HOL} "record_eq_simp" ["r = s"] |
18858 | 1269 |
(fn thy => fn _ => fn t => |
14079
1c22e5499eeb
- record_split_tac now also works for object-level universal quantifier
berghofe
parents:
13904
diff
changeset
|
1270 |
(case t of Const ("op =", Type (_, [T, _])) $ _ $ _ => |
15273
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
1271 |
(case rec_id (~1) T of |
15531 | 1272 |
"" => NONE |
18858 | 1273 |
| name => (case get_equalities thy name of |
15531 | 1274 |
NONE => NONE |
1275 |
| SOME thm => SOME (thm RS Eq_TrueI))) |
|
1276 |
| _ => NONE)); |
|
14079
1c22e5499eeb
- record_split_tac now also works for object-level universal quantifier
berghofe
parents:
13904
diff
changeset
|
1277 |
|
14255 | 1278 |
(* record_split_simproc *) |
17261 | 1279 |
(* splits quantified occurrences of records, for which P holds. P can peek on the |
14255 | 1280 |
* subterm starting at the quantified occurrence of the record (including the quantifier) |
15273
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
1281 |
* P t = 0: do not split |
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
1282 |
* P t = ~1: completely split |
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
1283 |
* P t > 0: split up to given bound of record extensions |
14255 | 1284 |
*) |
1285 |
fun record_split_simproc P = |
|
29064 | 1286 |
Simplifier.simproc @{theory HOL} "record_split_simp" ["x"] |
18858 | 1287 |
(fn thy => fn _ => fn t => |
14255 | 1288 |
(case t of (Const (quantifier, Type (_, [Type (_, [T, _]), _])))$trm => |
1289 |
if quantifier = "All" orelse quantifier = "all" orelse quantifier = "Ex" |
|
15273
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
1290 |
then (case rec_id (~1) T of |
15531 | 1291 |
"" => NONE |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1292 |
| name |
17261 | 1293 |
=> let val split = P t |
1294 |
in if split <> 0 then |
|
18858 | 1295 |
(case get_splits thy (rec_id split T) of |
15531 | 1296 |
NONE => NONE |
17261 | 1297 |
| SOME (all_thm, All_thm, Ex_thm,_) |
15531 | 1298 |
=> SOME (case quantifier of |
15273
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
1299 |
"all" => all_thm |
21546 | 1300 |
| "All" => All_thm RS eq_reflection |
1301 |
| "Ex" => Ex_thm RS eq_reflection |
|
15273
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
1302 |
| _ => error "record_split_simproc")) |
15531 | 1303 |
else NONE |
15273
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
1304 |
end) |
15531 | 1305 |
else NONE |
1306 |
| _ => NONE)) |
|
7178 | 1307 |
|
14427 | 1308 |
val record_ex_sel_eq_simproc = |
29064 | 1309 |
Simplifier.simproc @{theory HOL} "record_ex_sel_eq_simproc" ["Ex t"] |
18858 | 1310 |
(fn thy => fn ss => fn t => |
17261 | 1311 |
let |
16973 | 1312 |
fun prove prop = |
18858 | 1313 |
quick_and_dirty_prove true thy [] prop |
1314 |
(fn _ => simp_tac (Simplifier.inherit_context ss (get_simpset thy) |
|
16973 | 1315 |
addsimps simp_thms addsimprocs [record_split_simproc (K ~1)]) 1); |
14959 | 1316 |
|
1317 |
fun mkeq (lr,Teq,(sel,Tsel),x) i = |
|
18858 | 1318 |
if is_selector thy sel then |
17261 | 1319 |
let val x' = if not (loose_bvar1 (x,0)) |
1320 |
then Free ("x" ^ string_of_int i, range_type Tsel) |
|
14959 | 1321 |
else raise TERM ("",[x]); |
1322 |
val sel' = Const (sel,Tsel)$Bound 0; |
|
1323 |
val (l,r) = if lr then (sel',x') else (x',sel'); |
|
1324 |
in Const ("op =",Teq)$l$r end |
|
17510 | 1325 |
else raise TERM ("",[Const (sel,Tsel)]); |
14959 | 1326 |
|
17261 | 1327 |
fun dest_sel_eq (Const ("op =",Teq)$(Const (sel,Tsel)$Bound 0)$X) = |
14959 | 1328 |
(true,Teq,(sel,Tsel),X) |
1329 |
| dest_sel_eq (Const ("op =",Teq)$X$(Const (sel,Tsel)$Bound 0)) = |
|
1330 |
(false,Teq,(sel,Tsel),X) |
|
1331 |
| dest_sel_eq _ = raise TERM ("",[]); |
|
1332 |
||
17261 | 1333 |
in |
1334 |
(case t of |
|
14959 | 1335 |
(Const ("Ex",Tex)$Abs(s,T,t)) => |
16872 | 1336 |
(let val eq = mkeq (dest_sel_eq t) 0; |
14959 | 1337 |
val prop = list_all ([("r",T)], |
1338 |
Logic.mk_equals (Const ("Ex",Tex)$Abs(s,T,eq), |
|
1339 |
HOLogic.true_const)); |
|
15531 | 1340 |
in SOME (prove prop) end |
16872 | 1341 |
handle TERM _ => NONE) |
17261 | 1342 |
| _ => NONE) |
14427 | 1343 |
end) |
1344 |
||
5698 | 1345 |
|
14255 | 1346 |
local |
1347 |
val inductive_atomize = thms "induct_atomize"; |
|
18464 | 1348 |
val inductive_rulify = thms "induct_rulify"; |
14255 | 1349 |
in |
1350 |
(* record_split_simp_tac *) |
|
17261 | 1351 |
(* splits (and simplifies) all records in the goal for which P holds. |
14255 | 1352 |
* For quantified occurrences of a record |
1353 |
* P can peek on the whole subterm (including the quantifier); for free variables P |
|
15273
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
1354 |
* can only peek on the variable itself. |
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
1355 |
* P t = 0: do not split |
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
1356 |
* P t = ~1: completely split |
17261 | 1357 |
* P t > 0: split up to given bound of record extensions |
14255 | 1358 |
*) |
15248
b436486091a6
record_split_simp_tac now can get simp rules as parameter
schirmer
parents:
15215
diff
changeset
|
1359 |
fun record_split_simp_tac thms P i st = |
14255 | 1360 |
let |
18858 | 1361 |
val thy = Thm.theory_of_thm st; |
14255 | 1362 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1363 |
val has_rec = exists_Const |
14255 | 1364 |
(fn (s, Type (_, [Type (_, [T, _]), _])) => |
17261 | 1365 |
(s = "all" orelse s = "All" orelse s = "Ex") andalso is_recT T |
14255 | 1366 |
| _ => false); |
1367 |
||
18011
685d95c793ff
cleaned up nth, nth_update, nth_map and nth_string functions
haftmann
parents:
17960
diff
changeset
|
1368 |
val goal = nth (Thm.prems_of st) (i - 1); |
29265
5b4247055bd7
moved old add_term_vars, add_term_frees etc. to structure OldTerm;
wenzelm
parents:
29064
diff
changeset
|
1369 |
val frees = List.filter (is_recT o type_of) (OldTerm.term_frees goal); |
14255 | 1370 |
|
17261 | 1371 |
fun mk_split_free_tac free induct_thm i = |
18858 | 1372 |
let val cfree = cterm_of thy free; |
14255 | 1373 |
val (_$(_$r)) = concl_of induct_thm; |
18858 | 1374 |
val crec = cterm_of thy r; |
14255 | 1375 |
val thm = cterm_instantiate [(crec,cfree)] induct_thm; |
1376 |
in EVERY [simp_tac (HOL_basic_ss addsimps inductive_atomize) i, |
|
1377 |
rtac thm i, |
|
18464 | 1378 |
simp_tac (HOL_basic_ss addsimps inductive_rulify) i] |
17261 | 1379 |
end; |
14255 | 1380 |
|
17261 | 1381 |
fun split_free_tac P i (free as Free (n,T)) = |
1382 |
(case rec_id (~1) T of |
|
15531 | 1383 |
"" => NONE |
17261 | 1384 |
| name => let val split = P free |
1385 |
in if split <> 0 then |
|
18858 | 1386 |
(case get_splits thy (rec_id split T) of |
15531 | 1387 |
NONE => NONE |
1388 |
| SOME (_,_,_,induct_thm) |
|
1389 |
=> SOME (mk_split_free_tac free induct_thm i)) |
|
1390 |
else NONE |
|
15273
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
1391 |
end) |
15531 | 1392 |
| split_free_tac _ _ _ = NONE; |
14255 | 1393 |
|
15570 | 1394 |
val split_frees_tacs = List.mapPartial (split_free_tac P i) frees; |
17261 | 1395 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1396 |
val simprocs = if has_rec goal then [record_split_simproc P] else []; |
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1397 |
val thms' = K_comp_convs@thms |
17261 | 1398 |
in st |> ((EVERY split_frees_tacs) |
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1399 |
THEN (Simplifier.full_simp_tac (get_simpset thy addsimps thms' addsimprocs simprocs) i)) |
15570 | 1400 |
end handle Empty => Seq.empty; |
14255 | 1401 |
end; |
1402 |
||
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1403 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1404 |
(* record_split_tac *) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1405 |
(* splits all records in the goal, which are quantified by ! or !!. *) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1406 |
fun record_split_tac i st = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1407 |
let |
18858 | 1408 |
val thy = Thm.theory_of_thm st; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1409 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1410 |
val has_rec = exists_Const |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1411 |
(fn (s, Type (_, [Type (_, [T, _]), _])) => |
17261 | 1412 |
(s = "all" orelse s = "All") andalso is_recT T |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1413 |
| _ => false); |
17261 | 1414 |
|
18011
685d95c793ff
cleaned up nth, nth_update, nth_map and nth_string functions
haftmann
parents:
17960
diff
changeset
|
1415 |
val goal = nth (Thm.prems_of st) (i - 1); |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1416 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1417 |
fun is_all t = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1418 |
(case t of (Const (quantifier, _)$_) => |
15273
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
1419 |
if quantifier = "All" orelse quantifier = "all" then ~1 else 0 |
771af451a062
* extended interface of record_split_simp_tac and record_split_simproc
schirmer
parents:
15258
diff
changeset
|
1420 |
| _ => 0); |
17261 | 1421 |
|
1422 |
in if has_rec goal |
|
1423 |
then Simplifier.full_simp_tac |
|
1424 |
(HOL_basic_ss addsimprocs [record_split_simproc is_all]) i st |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1425 |
else Seq.empty |
15570 | 1426 |
end handle Subscript => Seq.empty; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1427 |
|
32335 | 1428 |
|
6358 | 1429 |
(* wrapper *) |
1430 |
||
5707 | 1431 |
val record_split_name = "record_split_tac"; |
1432 |
val record_split_wrapper = (record_split_name, fn tac => record_split_tac ORELSE' tac); |
|
5698 | 1433 |
|
16330 | 1434 |
|
1435 |
||
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
1436 |
(** theory extender interface **) |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
1437 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
1438 |
(* prepare arguments *) |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
1439 |
|
27278
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
1440 |
fun read_raw_parent ctxt raw_T = |
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
1441 |
(case ProofContext.read_typ_abbrev ctxt raw_T of |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
1442 |
Type (name, Ts) => (Ts, name) |
27278
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
1443 |
| T => error ("Bad parent record specification: " ^ Syntax.string_of_typ ctxt T)); |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
1444 |
|
27278
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
1445 |
fun read_typ ctxt raw_T env = |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
1446 |
let |
27278
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
1447 |
val ctxt' = fold (Variable.declare_typ o TFree) env ctxt; |
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
1448 |
val T = Syntax.read_typ ctxt' raw_T; |
29270
0eade173f77e
moved old add_type_XXX, add_term_XXX etc. to structure OldTerm;
wenzelm
parents:
29265
diff
changeset
|
1449 |
val env' = OldTerm.add_typ_tfrees (T, env); |
27278
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
1450 |
in (T, env') end; |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
1451 |
|
27278
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
1452 |
fun cert_typ ctxt raw_T env = |
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
1453 |
let |
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
1454 |
val thy = ProofContext.theory_of ctxt; |
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
1455 |
val T = Type.no_tvars (Sign.certify_typ thy raw_T) handle TYPE (msg, _, _) => error msg; |
29270
0eade173f77e
moved old add_type_XXX, add_term_XXX etc. to structure OldTerm;
wenzelm
parents:
29265
diff
changeset
|
1456 |
val env' = OldTerm.add_typ_tfrees (T, env); |
27278
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
1457 |
in (T, env') end; |
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
1458 |
|
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
1459 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1460 |
(* attributes *) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1461 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1462 |
fun case_names_fields x = RuleCases.case_names ["fields"] x; |
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
24712
diff
changeset
|
1463 |
fun induct_type_global name = [case_names_fields, Induct.induct_type name]; |
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
24712
diff
changeset
|
1464 |
fun cases_type_global name = [case_names_fields, Induct.cases_type name]; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1465 |
|
32335 | 1466 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1467 |
(* tactics *) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1468 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1469 |
fun simp_all_tac ss simps = ALLGOALS (Simplifier.asm_full_simp_tac (ss addsimps simps)); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1470 |
|
17261 | 1471 |
(* do case analysis / induction according to rule on last parameter of ith subgoal |
1472 |
* (or on s if there are no parameters); |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1473 |
* Instatiation of record variable (and predicate) in rule is calculated to |
17261 | 1474 |
* avoid problems with higher order unification. |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1475 |
*) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1476 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1477 |
fun try_param_tac s rule i st = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1478 |
let |
17510 | 1479 |
val cert = cterm_of (Thm.theory_of_thm st); |
18011
685d95c793ff
cleaned up nth, nth_update, nth_map and nth_string functions
haftmann
parents:
17960
diff
changeset
|
1480 |
val g = nth (prems_of st) (i - 1); |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1481 |
val params = Logic.strip_params g; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1482 |
val concl = HOLogic.dest_Trueprop (Logic.strip_assums_concl g); |
18145 | 1483 |
val rule' = Thm.lift_rule (Thm.cprem_of st i) rule; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1484 |
val (P, ys) = strip_comb (HOLogic.dest_Trueprop |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1485 |
(Logic.strip_assums_concl (prop_of rule'))); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1486 |
(* ca indicates if rule is a case analysis or induction rule *) |
15570 | 1487 |
val (x, ca) = (case rev (Library.drop (length params, ys)) of |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1488 |
[] => (head_of (fst (HOLogic.dest_eq (HOLogic.dest_Trueprop |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1489 |
(hd (rev (Logic.strip_assums_hyp (hd (prems_of rule')))))))), true) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1490 |
| [x] => (head_of x, false)); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1491 |
val rule'' = cterm_instantiate (map (pairself cert) (case (rev params) of |
29265
5b4247055bd7
moved old add_term_vars, add_term_frees etc. to structure OldTerm;
wenzelm
parents:
29064
diff
changeset
|
1492 |
[] => (case AList.lookup (op =) (map dest_Free (OldTerm.term_frees (prop_of st))) s of |
15531 | 1493 |
NONE => sys_error "try_param_tac: no such variable" |
1494 |
| SOME T => [(P, if ca then concl else lambda (Free (s, T)) concl), |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1495 |
(x, Free (s, T))]) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1496 |
| (_, T) :: _ => [(P, list_abs (params, if ca then concl |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1497 |
else incr_boundvars 1 (Abs (s, T, concl)))), |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1498 |
(x, list_abs (params, Bound 0))])) rule' |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1499 |
in compose_tac (false, rule'', nprems_of rule) i st end; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1500 |
|
15215 | 1501 |
|
1502 |
(* !!x1 ... xn. ... ==> EX x1 ... xn. P x1 ... xn; |
|
1503 |
instantiates x1 ... xn with parameters x1 ... xn *) |
|
1504 |
fun ex_inst_tac i st = |
|
1505 |
let |
|
18858 | 1506 |
val thy = Thm.theory_of_thm st; |
18011
685d95c793ff
cleaned up nth, nth_update, nth_map and nth_string functions
haftmann
parents:
17960
diff
changeset
|
1507 |
val g = nth (prems_of st) (i - 1); |
15215 | 1508 |
val params = Logic.strip_params g; |
18145 | 1509 |
val exI' = Thm.lift_rule (Thm.cprem_of st i) exI; |
15215 | 1510 |
val (_$(_$x)) = Logic.strip_assums_concl (hd (prems_of exI')); |
18858 | 1511 |
val cx = cterm_of thy (fst (strip_comb x)); |
15215 | 1512 |
|
17261 | 1513 |
in Seq.single (Library.foldl (fn (st,v) => |
1514 |
Seq.hd |
|
1515 |
(compose_tac (false, cterm_instantiate |
|
18858 | 1516 |
[(cx,cterm_of thy (list_abs (params,Bound v)))] exI',1) |
15215 | 1517 |
i st)) (st,((length params) - 1) downto 0)) |
1518 |
end; |
|
1519 |
||
17261 | 1520 |
fun extension_definition full name fields names alphas zeta moreT more vars thy = |
1521 |
let |
|
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30345
diff
changeset
|
1522 |
val base = Long_Name.base_name; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1523 |
val fieldTs = (map snd fields); |
15215 | 1524 |
val alphas_zeta = alphas@[zeta]; |
1525 |
val alphas_zetaTs = map (fn n => TFree (n, HOLogic.typeS)) alphas_zeta; |
|
20071
8f3e1ddb50e6
replaced Term.variant(list) by Name.variant(_list);
wenzelm
parents:
20049
diff
changeset
|
1526 |
val vT = TFree (Name.variant alphas_zeta "'v", HOLogic.typeS); |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1527 |
val extT_name = suffix ext_typeN name |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1528 |
val extT = Type (extT_name, alphas_zetaTs); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1529 |
val fields_more = fields@[(full moreN,moreT)]; |
15215 | 1530 |
val fields_moreTs = fieldTs@[moreT]; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1531 |
val bfields_more = map (apfst base) fields_more; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1532 |
val r = Free (rN,extT) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1533 |
val len = length fields; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1534 |
val idxms = 0 upto len; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1535 |
|
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1536 |
(* before doing anything else, create the tree of new types |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1537 |
that will back the record extension *) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1538 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1539 |
fun mktreeT [] = raise (TYPE ("mktreeT: empty list", [], [])) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1540 |
| mktreeT [T] = T |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1541 |
| mktreeT xs = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1542 |
let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1543 |
val len = length xs; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1544 |
val half = len div 2; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1545 |
val left = List.take (xs, half); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1546 |
val right = List.drop (xs, half); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1547 |
in |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1548 |
HOLogic.mk_prodT (mktreeT left, mktreeT right) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1549 |
end; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1550 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1551 |
fun mktreeV [] = raise (TYPE ("mktreeV: empty list", [], [])) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1552 |
| mktreeV [T] = T |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1553 |
| mktreeV xs = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1554 |
let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1555 |
val len = length xs; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1556 |
val half = len div 2; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1557 |
val left = List.take (xs, half); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1558 |
val right = List.drop (xs, half); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1559 |
in |
32745
192d58483fdf
Simplification of various aspects of the IsTuple component
Thomas Sewell <tsewell@nicta.com.au>
parents:
32744
diff
changeset
|
1560 |
IsTupleSupport.mk_cons_tuple (mktreeV left, mktreeV right) |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1561 |
end; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1562 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1563 |
fun mk_istuple ((thy, i), (left, rght)) = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1564 |
let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1565 |
val suff = if i = 0 then ext_typeN else inner_typeN ^ (string_of_int i); |
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
1566 |
val nm = suffix suff (Long_Name.base_name name); |
32745
192d58483fdf
Simplification of various aspects of the IsTuple component
Thomas Sewell <tsewell@nicta.com.au>
parents:
32744
diff
changeset
|
1567 |
val (isom, cons, thy') = IsTupleSupport.add_istuple_type |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1568 |
(nm, alphas_zeta) (fastype_of left, fastype_of rght) thy; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1569 |
in |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1570 |
((thy', i + 1), cons $ left $ rght) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1571 |
end; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1572 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1573 |
(* trying to create a 1-element istuple will fail, and |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1574 |
is pointless anyway *) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1575 |
fun mk_even_istuple ((thy, i), [arg]) = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1576 |
((thy, i), arg) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1577 |
| mk_even_istuple ((thy, i), args) = |
32745
192d58483fdf
Simplification of various aspects of the IsTuple component
Thomas Sewell <tsewell@nicta.com.au>
parents:
32744
diff
changeset
|
1578 |
mk_istuple ((thy, i), IsTupleSupport.dest_cons_tuple (mktreeV args)); |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1579 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1580 |
fun build_meta_tree_type i thy vars more = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1581 |
let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1582 |
val len = length vars; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1583 |
in |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1584 |
if len < 1 |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1585 |
then raise (TYPE ("meta_tree_type args too short", [], vars)) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1586 |
else if len > 16 |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1587 |
then let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1588 |
fun group16 [] = [] |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1589 |
| group16 xs = Library.take (16, xs) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1590 |
:: group16 (Library.drop (16, xs)); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1591 |
val vars' = group16 vars; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1592 |
val ((thy', i'), composites) = |
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
1593 |
Library.foldl_map mk_even_istuple ((thy, i), vars'); |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1594 |
in |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1595 |
build_meta_tree_type i' thy' composites more |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1596 |
end |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1597 |
else let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1598 |
val ((thy', i'), term) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1599 |
= mk_istuple ((thy, 0), (mktreeV vars, more)); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1600 |
in |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1601 |
(term, thy') |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1602 |
end |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1603 |
end; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1604 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1605 |
val _ = timing_msg "record extension preparing definitions"; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1606 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1607 |
(* 1st stage part 1: introduce the tree of new types *) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1608 |
fun get_meta_tree () = build_meta_tree_type 1 thy vars more; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1609 |
val (ext_body, typ_thy) = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1610 |
timeit_msg "record extension nested type def:" get_meta_tree; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1611 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1612 |
(* prepare declarations and definitions *) |
17261 | 1613 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1614 |
(*fields constructor*) |
15215 | 1615 |
val ext_decl = (mk_extC (name,extT) fields_moreTs); |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1616 |
val ext_spec = list_comb (Const ext_decl,vars@[more]) :== ext_body; |
15215 | 1617 |
|
17261 | 1618 |
fun mk_ext args = list_comb (Const ext_decl, args); |
1619 |
||
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1620 |
(* 1st stage part 2: define the ext constant *) |
16379 | 1621 |
fun mk_defs () = |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1622 |
typ_thy |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1623 |
|> Sign.add_consts_i [Syntax.no_syn (apfst (Binding.name o base) ext_decl)] |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1624 |
|> PureThy.add_defs false [Thm.no_attributes (apfst Binding.name ext_spec)] |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1625 |
val ([ext_def], defs_thy) = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1626 |
timeit_msg "record extension constructor def:" mk_defs; |
17261 | 1627 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1628 |
(* prepare propositions *) |
16379 | 1629 |
val _ = timing_msg "record extension preparing propositions"; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1630 |
val vars_more = vars@[more]; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1631 |
val named_vars_more = (names@[full moreN])~~vars_more; |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
1632 |
val variants = map (fn (Free (x,_))=>x) vars_more; |
15215 | 1633 |
val ext = mk_ext vars_more; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1634 |
val s = Free (rN, extT); |
15215 | 1635 |
val w = Free (wN, extT); |
20071
8f3e1ddb50e6
replaced Term.variant(list) by Name.variant(_list);
wenzelm
parents:
20049
diff
changeset
|
1636 |
val P = Free (Name.variant variants "P", extT-->HOLogic.boolT); |
8f3e1ddb50e6
replaced Term.variant(list) by Name.variant(_list);
wenzelm
parents:
20049
diff
changeset
|
1637 |
val C = Free (Name.variant variants "C", HOLogic.boolT); |
32745
192d58483fdf
Simplification of various aspects of the IsTuple component
Thomas Sewell <tsewell@nicta.com.au>
parents:
32744
diff
changeset
|
1638 |
val intros_tac = IsTupleSupport.istuple_intros_tac defs_thy; |
17261 | 1639 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1640 |
val inject_prop = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1641 |
let val vars_more' = map (fn (Free (x,T)) => Free (x ^ "'",T)) vars_more; |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1642 |
in |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1643 |
((HOLogic.mk_conj (HOLogic.eq_const extT $ |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1644 |
mk_ext vars_more$mk_ext vars_more', HOLogic.true_const)) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1645 |
=== |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1646 |
foldr1 HOLogic.mk_conj |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1647 |
(map HOLogic.mk_eq (vars_more ~~ vars_more') @ [HOLogic.true_const])) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1648 |
end; |
17261 | 1649 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1650 |
val induct_prop = |
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
1651 |
(All (map dest_Free vars_more) (Trueprop (P $ ext)), Trueprop (P $ s)); |
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
1652 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1653 |
val cases_prop = |
17261 | 1654 |
(All (map dest_Free vars_more) |
1655 |
(Trueprop (HOLogic.mk_eq (s,ext)) ==> Trueprop C)) |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1656 |
==> Trueprop C; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1657 |
|
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
1658 |
val split_meta_prop = |
20071
8f3e1ddb50e6
replaced Term.variant(list) by Name.variant(_list);
wenzelm
parents:
20049
diff
changeset
|
1659 |
let val P = Free (Name.variant variants "P", extT-->Term.propT) in |
17261 | 1660 |
Logic.mk_equals |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
1661 |
(All [dest_Free s] (P $ s), All (map dest_Free vars_more) (P $ ext)) |
17261 | 1662 |
end; |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
1663 |
|
17510 | 1664 |
fun prove stndrd = quick_and_dirty_prove stndrd defs_thy; |
1665 |
val prove_standard = quick_and_dirty_prove true defs_thy; |
|
15215 | 1666 |
fun prove_simp stndrd simps = |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1667 |
let val tac = simp_all_tac HOL_ss simps |
15215 | 1668 |
in fn prop => prove stndrd [] prop (K tac) end; |
17261 | 1669 |
|
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1670 |
fun inject_prf () = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1671 |
simplify HOL_ss ( |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1672 |
prove_standard [] inject_prop (fn prems => |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1673 |
EVERY [simp_tac (HOL_basic_ss addsimps [ext_def]) 1, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1674 |
REPEAT_DETERM (resolve_tac [refl_conj_eq] 1 |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1675 |
ORELSE intros_tac 1 |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1676 |
ORELSE resolve_tac [refl] 1)])); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1677 |
|
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
1678 |
val inject = timeit_msg "record extension inject proof:" inject_prf; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1679 |
|
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1680 |
(* We need a surjection property r = (| f = f r, g = g r ... |) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1681 |
to prove other theorems. We haven't given names to the accessors |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1682 |
f, g etc yet however, so we generate an ext structure with |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1683 |
free variables as all arguments and allow the introduction tactic to |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1684 |
operate on it as far as it can. We then use standard to convert |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1685 |
the free variables into unifiable variables and unify them with |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1686 |
(roughly) the definition of the accessor. *) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1687 |
fun surject_prf () = let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1688 |
val cterm_ext = cterm_of defs_thy ext; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1689 |
val start = named_cterm_instantiate [("y", cterm_ext)] |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1690 |
surject_assist_idE; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1691 |
val tactic1 = simp_tac (HOL_basic_ss addsimps [ext_def]) 1 |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1692 |
THEN REPEAT_ALL_NEW intros_tac 1 |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1693 |
val tactic2 = REPEAT (rtac surject_assistI 1 THEN rtac refl 1); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1694 |
val [halfway] = Seq.list_of (tactic1 start); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1695 |
val [surject] = Seq.list_of (tactic2 (standard halfway)); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1696 |
in |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1697 |
surject |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1698 |
end; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1699 |
val surject = timeit_msg "record extension surjective proof:" surject_prf; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1700 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1701 |
fun split_meta_prf () = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1702 |
prove_standard [] split_meta_prop (fn prems => |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1703 |
EVERY [rtac equal_intr_rule 1, Goal.norm_hhf_tac 1, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1704 |
etac meta_allE 1, atac 1, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1705 |
rtac (prop_subst OF [surject]) 1, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1706 |
REPEAT (etac meta_allE 1), atac 1]); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1707 |
val split_meta = timeit_msg "record extension split_meta proof:" split_meta_prf; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1708 |
|
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
1709 |
fun induct_prf () = |
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
1710 |
let val (assm, concl) = induct_prop |
20248 | 1711 |
in prove_standard [assm] concl (fn {prems, ...} => |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1712 |
EVERY [cut_rules_tac [split_meta RS meta_iffD2] 1, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1713 |
resolve_tac prems 2, |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1714 |
asm_simp_tac HOL_ss 1]) end; |
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
1715 |
val induct = timeit_msg "record extension induct proof:" induct_prf; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1716 |
|
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
1717 |
val ([inject',induct',surjective',split_meta',ext_def'], |
18377 | 1718 |
thm_thy) = |
17261 | 1719 |
defs_thy |
29579 | 1720 |
|> (PureThy.add_thms o map (Thm.no_attributes o apfst Binding.name)) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1721 |
[("ext_inject", inject), |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1722 |
("ext_induct", induct), |
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
1723 |
("ext_surjective", surject), |
32748
887c68b70f7d
There's no particular reason to duplicate the extension
Thomas Sewell <tsewell@nicta.com.au>
parents:
32745
diff
changeset
|
1724 |
("ext_split", split_meta)] |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1725 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1726 |
in (thm_thy,extT,induct',inject',split_meta',ext_def') |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1727 |
end; |
17261 | 1728 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1729 |
fun chunks [] [] = [] |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1730 |
| chunks [] xs = [xs] |
15570 | 1731 |
| chunks (l::ls) xs = Library.take (l,xs)::chunks ls (Library.drop (l,xs)); |
17261 | 1732 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1733 |
fun chop_last [] = error "last: list should not be empty" |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1734 |
| chop_last [x] = ([],x) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1735 |
| chop_last (x::xs) = let val (tl,l) = chop_last xs in (x::tl,l) end; |
17261 | 1736 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1737 |
fun subst_last s [] = error "subst_last: list should not be empty" |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1738 |
| subst_last s ([x]) = [s] |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1739 |
| subst_last s (x::xs) = (x::subst_last s xs); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1740 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1741 |
(* mk_recordT builds up the record type from the current extension tpye extT and a list |
17261 | 1742 |
* of parent extensions, starting with the root of the record hierarchy |
1743 |
*) |
|
21078 | 1744 |
fun mk_recordT extT = |
1745 |
fold_rev (fn (parent, Ts) => fn T => Type (parent, subst_last T Ts)) extT; |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1746 |
|
15215 | 1747 |
|
1748 |
||
1749 |
fun obj_to_meta_all thm = |
|
1750 |
let |
|
17261 | 1751 |
fun E thm = case (SOME (spec OF [thm]) handle THM _ => NONE) of |
15531 | 1752 |
SOME thm' => E thm' |
1753 |
| NONE => thm; |
|
15215 | 1754 |
val th1 = E thm; |
1755 |
val th2 = Drule.forall_intr_vars th1; |
|
1756 |
in th2 end; |
|
1757 |
||
1758 |
fun meta_to_obj_all thm = |
|
1759 |
let |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26496
diff
changeset
|
1760 |
val thy = Thm.theory_of_thm thm; |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26496
diff
changeset
|
1761 |
val prop = Thm.prop_of thm; |
15215 | 1762 |
val params = Logic.strip_params prop; |
1763 |
val concl = HOLogic.dest_Trueprop (Logic.strip_assums_concl prop); |
|
22596 | 1764 |
val ct = cterm_of thy |
15215 | 1765 |
(HOLogic.mk_Trueprop (HOLogic.list_all (params, concl))); |
1766 |
val thm' = Seq.hd (REPEAT (rtac allI 1) (Thm.trivial ct)); |
|
1767 |
in |
|
1768 |
Thm.implies_elim thm' thm |
|
1769 |
end; |
|
1770 |
||
1771 |
||
1772 |
||
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1773 |
(* record_definition *) |
25070
e2a39b6526b0
replaced NameSpace.accesses' by NameSpace.external_names (depening on naming);
wenzelm
parents:
24867
diff
changeset
|
1774 |
|
17261 | 1775 |
fun record_definition (args, bname) parent (parents: parent_info list) raw_fields thy = |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1776 |
let |
25070
e2a39b6526b0
replaced NameSpace.accesses' by NameSpace.external_names (depening on naming);
wenzelm
parents:
24867
diff
changeset
|
1777 |
val external_names = NameSpace.external_names (Sign.naming_of thy); |
e2a39b6526b0
replaced NameSpace.accesses' by NameSpace.external_names (depening on naming);
wenzelm
parents:
24867
diff
changeset
|
1778 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1779 |
val alphas = map fst args; |
28965 | 1780 |
val name = Sign.full_bname thy bname; |
1781 |
val full = Sign.full_bname_path thy bname; |
|
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30345
diff
changeset
|
1782 |
val base = Long_Name.base_name; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1783 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1784 |
val (bfields, field_syntax) = split_list (map (fn (x, T, mx) => ((x, T), mx)) raw_fields); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1785 |
|
15570 | 1786 |
val parent_fields = List.concat (map #fields parents); |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1787 |
val parent_chunks = map (length o #fields) parents; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1788 |
val parent_names = map fst parent_fields; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1789 |
val parent_types = map snd parent_fields; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1790 |
val parent_fields_len = length parent_fields; |
20071
8f3e1ddb50e6
replaced Term.variant(list) by Name.variant(_list);
wenzelm
parents:
20049
diff
changeset
|
1791 |
val parent_variants = Name.variant_list [moreN, rN, rN ^ "'", wN] (map base parent_names); |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1792 |
val parent_vars = ListPair.map Free (parent_variants, parent_types); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1793 |
val parent_len = length parents; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1794 |
val parents_idx = (map #name parents) ~~ (0 upto (parent_len - 1)); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1795 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1796 |
val fields = map (apfst full) bfields; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1797 |
val names = map fst fields; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1798 |
val extN = full bname; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1799 |
val types = map snd fields; |
30190 | 1800 |
val alphas_fields = List.foldr OldTerm.add_typ_tfree_names [] types; |
17261 | 1801 |
val alphas_ext = alphas inter alphas_fields; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1802 |
val len = length fields; |
30715
e23e15f52d42
avoid mixing of left/right associative infixes, to make it work with experimental Poly/ML 5.3 branch;
wenzelm
parents:
30364
diff
changeset
|
1803 |
val variants = |
e23e15f52d42
avoid mixing of left/right associative infixes, to make it work with experimental Poly/ML 5.3 branch;
wenzelm
parents:
30364
diff
changeset
|
1804 |
Name.variant_list (moreN :: rN :: (rN ^ "'") :: wN :: parent_variants) (map fst bfields); |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1805 |
val vars = ListPair.map Free (variants, types); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1806 |
val named_vars = names ~~ vars; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1807 |
val idxs = 0 upto (len - 1); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1808 |
val idxms = 0 upto len; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1809 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1810 |
val all_fields = parent_fields @ fields; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1811 |
val all_names = parent_names @ names; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1812 |
val all_types = parent_types @ types; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1813 |
val all_len = parent_fields_len + len; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1814 |
val all_variants = parent_variants @ variants; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1815 |
val all_vars = parent_vars @ vars; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1816 |
val all_named_vars = (parent_names ~~ parent_vars) @ named_vars; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1817 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1818 |
|
20071
8f3e1ddb50e6
replaced Term.variant(list) by Name.variant(_list);
wenzelm
parents:
20049
diff
changeset
|
1819 |
val zeta = Name.variant alphas "'z"; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1820 |
val moreT = TFree (zeta, HOLogic.typeS); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1821 |
val more = Free (moreN, moreT); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1822 |
val full_moreN = full moreN; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1823 |
val bfields_more = bfields @ [(moreN,moreT)]; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1824 |
val fields_more = fields @ [(full_moreN,moreT)]; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1825 |
val vars_more = vars @ [more]; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1826 |
val named_vars_more = named_vars @[(full_moreN,more)]; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1827 |
val all_vars_more = all_vars @ [more]; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1828 |
val all_named_vars_more = all_named_vars @ [(full_moreN,more)]; |
17261 | 1829 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1830 |
(* 1st stage: extension_thy *) |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1831 |
val (extension_thy,extT,ext_induct,ext_inject,ext_split,ext_def) = |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1832 |
thy |
24712
64ed05609568
proper Sign operations instead of Theory aliases;
wenzelm
parents:
24624
diff
changeset
|
1833 |
|> Sign.add_path bname |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1834 |
|> extension_definition full extN fields names alphas_ext zeta moreT more vars; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1835 |
|
17261 | 1836 |
val _ = timing_msg "record preparing definitions"; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1837 |
val Type extension_scheme = extT; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1838 |
val extension_name = unsuffix ext_typeN (fst extension_scheme); |
17261 | 1839 |
val extension = let val (n,Ts) = extension_scheme in (n,subst_last HOLogic.unitT Ts) end; |
1840 |
val extension_names = |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1841 |
(map ((unsuffix ext_typeN) o fst o #extension) parents) @ [extN]; |
15570 | 1842 |
val extension_id = Library.foldl (op ^) ("",extension_names); |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1843 |
|
17261 | 1844 |
|
21078 | 1845 |
fun rec_schemeT n = mk_recordT (map #extension (prune n parents)) extT; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1846 |
val rec_schemeT0 = rec_schemeT 0; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1847 |
|
17261 | 1848 |
fun recT n = |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1849 |
let val (c,Ts) = extension |
21078 | 1850 |
in mk_recordT (map #extension (prune n parents)) (Type (c,subst_last HOLogic.unitT Ts)) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1851 |
end; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1852 |
val recT0 = recT 0; |
17261 | 1853 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1854 |
fun mk_rec args n = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1855 |
let val (args',more) = chop_last args; |
17261 | 1856 |
fun mk_ext' (((name,T),args),more) = mk_ext (name,T) (args@[more]); |
1857 |
fun build Ts = |
|
30190 | 1858 |
List.foldr mk_ext' more (prune n (extension_names ~~ Ts ~~ (chunks parent_chunks args'))) |
17261 | 1859 |
in |
1860 |
if more = HOLogic.unit |
|
1861 |
then build (map recT (0 upto parent_len)) |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1862 |
else build (map rec_schemeT (0 upto parent_len)) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1863 |
end; |
17261 | 1864 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1865 |
val r_rec0 = mk_rec all_vars_more 0; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1866 |
val r_rec_unit0 = mk_rec (all_vars@[HOLogic.unit]) 0; |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1867 |
val r_rec0_Vars = let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1868 |
fun to_Var (Free (c, T)) = Var ((c, 0), T); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1869 |
in mk_rec (map to_Var all_vars_more) 0 end; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1870 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1871 |
fun r n = Free (rN, rec_schemeT n) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1872 |
val r0 = r 0; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1873 |
fun r_unit n = Free (rN, recT n) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1874 |
val r_unit0 = r_unit 0; |
15215 | 1875 |
val w = Free (wN, rec_schemeT 0) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1876 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1877 |
(* prepare print translation functions *) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1878 |
val field_tr's = |
25070
e2a39b6526b0
replaced NameSpace.accesses' by NameSpace.external_names (depening on naming);
wenzelm
parents:
24867
diff
changeset
|
1879 |
print_translation (distinct (op =) (maps external_names (full_moreN :: names))); |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1880 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1881 |
val adv_ext_tr's = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1882 |
let |
25070
e2a39b6526b0
replaced NameSpace.accesses' by NameSpace.external_names (depening on naming);
wenzelm
parents:
24867
diff
changeset
|
1883 |
val trnames = external_names extN; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1884 |
in map (gen_record_tr') trnames end; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1885 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1886 |
val adv_record_type_abbr_tr's = |
25070
e2a39b6526b0
replaced NameSpace.accesses' by NameSpace.external_names (depening on naming);
wenzelm
parents:
24867
diff
changeset
|
1887 |
let val trnames = external_names (hd extension_names); |
e2a39b6526b0
replaced NameSpace.accesses' by NameSpace.external_names (depening on naming);
wenzelm
parents:
24867
diff
changeset
|
1888 |
val lastExt = unsuffix ext_typeN (fst extension); |
17190 | 1889 |
in map (gen_record_type_abbr_tr' name alphas zeta lastExt rec_schemeT0) trnames |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1890 |
end; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1891 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1892 |
val adv_record_type_tr's = |
25070
e2a39b6526b0
replaced NameSpace.accesses' by NameSpace.external_names (depening on naming);
wenzelm
parents:
24867
diff
changeset
|
1893 |
let val trnames = if parent_len > 0 then external_names extN else []; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1894 |
(* avoid conflict with adv_record_type_abbr_tr's *) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1895 |
in map (gen_record_type_tr') trnames |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1896 |
end; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1897 |
|
17261 | 1898 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1899 |
(* prepare declarations *) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1900 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1901 |
val sel_decls = map (mk_selC rec_schemeT0) bfields_more; |
15215 | 1902 |
val upd_decls = map (mk_updC updateN rec_schemeT0) bfields_more; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1903 |
val make_decl = (makeN, all_types ---> recT0); |
17261 | 1904 |
val fields_decl = (fields_selN, types ---> Type extension); |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1905 |
val extend_decl = (extendN, recT0 --> moreT --> rec_schemeT0); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1906 |
val truncate_decl = (truncateN, rec_schemeT0 --> recT0); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1907 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1908 |
(* prepare definitions *) |
17261 | 1909 |
|
1910 |
fun parent_more s = |
|
1911 |
if null parents then s |
|
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30345
diff
changeset
|
1912 |
else mk_sel s (Long_Name.qualify (#name (List.last parents)) moreN, extT); |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1913 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1914 |
fun parent_more_upd v s = |
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
1915 |
if null parents then v$s |
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30345
diff
changeset
|
1916 |
else let val mp = Long_Name.qualify (#name (List.last parents)) moreN; |
15215 | 1917 |
in mk_upd updateN mp v s end; |
17261 | 1918 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1919 |
(*record (scheme) type abbreviation*) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1920 |
val recordT_specs = |
30345 | 1921 |
[(Binding.name (suffix schemeN bname), alphas @ [zeta], rec_schemeT0, Syntax.NoSyn), |
1922 |
(Binding.name bname, alphas, recT0, Syntax.NoSyn)]; |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1923 |
|
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1924 |
val ext_defs = ext_def :: map #extdef parents; |
32745
192d58483fdf
Simplification of various aspects of the IsTuple component
Thomas Sewell <tsewell@nicta.com.au>
parents:
32744
diff
changeset
|
1925 |
val intros_tac = IsTupleSupport.istuple_intros_tac extension_thy; |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1926 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1927 |
(* Theorems from the istuple intros. |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1928 |
This is complex enough to deserve a full comment. |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1929 |
By unfolding ext_defs from r_rec0 we create a tree of constructor |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1930 |
calls (many of them Pair, but others as well). The introduction |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1931 |
rules for update_accessor_eq_assist can unify two different ways |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1932 |
on these constructors. If we take the complete result sequence of |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1933 |
running a the introduction tactic, we get one theorem for each upd/acc |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1934 |
pair, from which we can derive the bodies of our selector and |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1935 |
updator and their convs. *) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1936 |
fun get_access_update_thms () = let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1937 |
val cterm_rec = cterm_of extension_thy r_rec0; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1938 |
val cterm_vrs = cterm_of extension_thy r_rec0_Vars; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1939 |
val insts = [("v", cterm_rec), ("v'", cterm_vrs)]; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1940 |
val init_thm = named_cterm_instantiate insts updacc_eq_triv; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1941 |
val terminal = rtac updacc_eq_idI 1 THEN rtac refl 1; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1942 |
val tactic = simp_tac (HOL_basic_ss addsimps ext_defs) 1 |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1943 |
THEN REPEAT (intros_tac 1 ORELSE terminal); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1944 |
val updaccs = Seq.list_of (tactic init_thm); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1945 |
in |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1946 |
(updaccs RL [updacc_accessor_eqE], |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1947 |
updaccs RL [updacc_updator_eqE], |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1948 |
updaccs RL [updacc_cong_from_eq]) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1949 |
end; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1950 |
val (accessor_thms, updator_thms, upd_acc_cong_assists) = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1951 |
timeit_msg "record getting tree access/updates:" get_access_update_thms; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1952 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1953 |
fun lastN xs = List.drop (xs, parent_fields_len); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1954 |
|
17261 | 1955 |
(*selectors*) |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1956 |
fun mk_sel_spec ((c,T), thm) = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1957 |
let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1958 |
val (acc $ arg) = (fst o HOLogic.dest_eq o HOLogic.dest_Trueprop |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1959 |
o Envir.beta_eta_contract o concl_of) thm; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1960 |
val _ = if (arg aconv r_rec0) then () |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1961 |
else raise TERM ("mk_sel_spec: different arg", [arg]); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1962 |
in |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1963 |
Const (mk_selC rec_schemeT0 (c,T)) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1964 |
:== acc |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1965 |
end; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1966 |
val sel_specs = map mk_sel_spec (fields_more ~~ lastN accessor_thms); |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1967 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1968 |
(*updates*) |
15215 | 1969 |
|
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1970 |
fun mk_upd_spec ((c,T), thm) = |
17261 | 1971 |
let |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1972 |
val (upd $ _ $ arg) = (fst o HOLogic.dest_eq o HOLogic.dest_Trueprop |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1973 |
o Envir.beta_eta_contract o concl_of) thm; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1974 |
val _ = if (arg aconv r_rec0) then () |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1975 |
else raise TERM ("mk_sel_spec: different arg", [arg]); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1976 |
in Const (mk_updC updateN rec_schemeT0 (c,T)) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1977 |
:== upd |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1978 |
end; |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
1979 |
val upd_specs = map mk_upd_spec (fields_more ~~ lastN updator_thms); |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1980 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1981 |
(*derived operations*) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1982 |
val make_spec = Const (full makeN, all_types ---> recT0) $$ all_vars :== |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1983 |
mk_rec (all_vars @ [HOLogic.unit]) 0; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1984 |
val fields_spec = Const (full fields_selN, types ---> Type extension) $$ vars :== |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1985 |
mk_rec (all_vars @ [HOLogic.unit]) parent_len; |
17261 | 1986 |
val extend_spec = |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1987 |
Const (full extendN, recT0-->moreT-->rec_schemeT0) $ r_unit0 $ more :== |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1988 |
mk_rec ((map (mk_sel r_unit0) all_fields) @ [more]) 0; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1989 |
val truncate_spec = Const (full truncateN, rec_schemeT0 --> recT0) $ r0 :== |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1990 |
mk_rec ((map (mk_sel r0) all_fields) @ [HOLogic.unit]) 0; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1991 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
1992 |
(* 2st stage: defs_thy *) |
17261 | 1993 |
|
16379 | 1994 |
fun mk_defs () = |
1995 |
extension_thy |
|
24712
64ed05609568
proper Sign operations instead of Theory aliases;
wenzelm
parents:
24624
diff
changeset
|
1996 |
|> Sign.add_trfuns |
22747
0c9c413b4678
add definitions explicitly to code generator table
haftmann
parents:
22693
diff
changeset
|
1997 |
([],[],field_tr's, []) |
24712
64ed05609568
proper Sign operations instead of Theory aliases;
wenzelm
parents:
24624
diff
changeset
|
1998 |
|> Sign.add_advanced_trfuns |
22747
0c9c413b4678
add definitions explicitly to code generator table
haftmann
parents:
22693
diff
changeset
|
1999 |
([],[],adv_ext_tr's @ adv_record_type_tr's @ adv_record_type_abbr_tr's,[]) |
24712
64ed05609568
proper Sign operations instead of Theory aliases;
wenzelm
parents:
24624
diff
changeset
|
2000 |
|> Sign.parent_path |
64ed05609568
proper Sign operations instead of Theory aliases;
wenzelm
parents:
24624
diff
changeset
|
2001 |
|> Sign.add_tyabbrs_i recordT_specs |
64ed05609568
proper Sign operations instead of Theory aliases;
wenzelm
parents:
24624
diff
changeset
|
2002 |
|> Sign.add_path bname |
64ed05609568
proper Sign operations instead of Theory aliases;
wenzelm
parents:
24624
diff
changeset
|
2003 |
|> Sign.add_consts_i |
30345 | 2004 |
(map2 (fn (x, T) => fn mx => (Binding.name x, T, mx)) |
2005 |
sel_decls (field_syntax @ [Syntax.NoSyn])) |
|
2006 |
|> (Sign.add_consts_i o map (fn (x, T) => (Binding.name x, T, Syntax.NoSyn))) |
|
22747
0c9c413b4678
add definitions explicitly to code generator table
haftmann
parents:
22693
diff
changeset
|
2007 |
(upd_decls @ [make_decl, fields_decl, extend_decl, truncate_decl]) |
29579 | 2008 |
|> ((PureThy.add_defs false o map (Thm.no_attributes o apfst Binding.name)) sel_specs) |
2009 |
||>> ((PureThy.add_defs false o map (Thm.no_attributes o apfst Binding.name)) upd_specs) |
|
2010 |
||>> ((PureThy.add_defs false o map (Thm.no_attributes o apfst Binding.name)) |
|
22747
0c9c413b4678
add definitions explicitly to code generator table
haftmann
parents:
22693
diff
changeset
|
2011 |
[make_spec, fields_spec, extend_spec, truncate_spec]) |
24867 | 2012 |
|-> (fn defs as ((sel_defs, upd_defs), derived_defs) => |
28370 | 2013 |
fold Code.add_default_eqn sel_defs |
2014 |
#> fold Code.add_default_eqn upd_defs |
|
2015 |
#> fold Code.add_default_eqn derived_defs |
|
22747
0c9c413b4678
add definitions explicitly to code generator table
haftmann
parents:
22693
diff
changeset
|
2016 |
#> pair defs) |
0c9c413b4678
add definitions explicitly to code generator table
haftmann
parents:
22693
diff
changeset
|
2017 |
val (((sel_defs, upd_defs), derived_defs), defs_thy) = |
0c9c413b4678
add definitions explicitly to code generator table
haftmann
parents:
22693
diff
changeset
|
2018 |
timeit_msg "record trfuns/tyabbrs/selectors/updates/make/fields/extend/truncate defs:" |
0c9c413b4678
add definitions explicitly to code generator table
haftmann
parents:
22693
diff
changeset
|
2019 |
mk_defs; |
17261 | 2020 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2021 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2022 |
(* prepare propositions *) |
17261 | 2023 |
val _ = timing_msg "record preparing propositions"; |
20071
8f3e1ddb50e6
replaced Term.variant(list) by Name.variant(_list);
wenzelm
parents:
20049
diff
changeset
|
2024 |
val P = Free (Name.variant all_variants "P", rec_schemeT0-->HOLogic.boolT); |
8f3e1ddb50e6
replaced Term.variant(list) by Name.variant(_list);
wenzelm
parents:
20049
diff
changeset
|
2025 |
val C = Free (Name.variant all_variants "C", HOLogic.boolT); |
8f3e1ddb50e6
replaced Term.variant(list) by Name.variant(_list);
wenzelm
parents:
20049
diff
changeset
|
2026 |
val P_unit = Free (Name.variant all_variants "P", recT0-->HOLogic.boolT); |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2027 |
|
17261 | 2028 |
(*selectors*) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2029 |
val sel_conv_props = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2030 |
map (fn (c, x as Free (_,T)) => mk_sel r_rec0 (c,T) === x) named_vars_more; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2031 |
|
17261 | 2032 |
(*updates*) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2033 |
fun mk_upd_prop (i,(c,T)) = |
21226
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
2034 |
let val x' = Free (Name.variant all_variants (base c ^ "'"),T-->T); |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
2035 |
val n = parent_fields_len + i; |
a607ae87ee81
field-update in records is generalised to take a function on the field
schirmer
parents:
21109
diff
changeset
|
2036 |
val args' = nth_map n (K (x'$nth all_vars_more n)) all_vars_more |
15215 | 2037 |
in mk_upd updateN c x' r_rec0 === mk_rec args' 0 end; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2038 |
val upd_conv_props = ListPair.map mk_upd_prop (idxms, fields_more); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2039 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2040 |
(*induct*) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2041 |
val induct_scheme_prop = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2042 |
All (map dest_Free all_vars_more) (Trueprop (P $ r_rec0)) ==> Trueprop (P $ r0); |
17261 | 2043 |
val induct_prop = |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2044 |
(All (map dest_Free all_vars) (Trueprop (P_unit $ r_rec_unit0)), |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2045 |
Trueprop (P_unit $ r_unit0)); |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2046 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2047 |
(*surjective*) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2048 |
val surjective_prop = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2049 |
let val args = map (fn (c,Free (_,T)) => mk_sel r0 (c,T)) all_named_vars_more |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2050 |
in r0 === mk_rec args 0 end; |
17261 | 2051 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2052 |
(*cases*) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2053 |
val cases_scheme_prop = |
17261 | 2054 |
(All (map dest_Free all_vars_more) |
2055 |
(Trueprop (HOLogic.mk_eq (r0,r_rec0)) ==> Trueprop C)) |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2056 |
==> Trueprop C; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2057 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2058 |
val cases_prop = |
17261 | 2059 |
(All (map dest_Free all_vars) |
2060 |
(Trueprop (HOLogic.mk_eq (r_unit0,r_rec_unit0)) ==> Trueprop C)) |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2061 |
==> Trueprop C; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2062 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2063 |
(*split*) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2064 |
val split_meta_prop = |
20071
8f3e1ddb50e6
replaced Term.variant(list) by Name.variant(_list);
wenzelm
parents:
20049
diff
changeset
|
2065 |
let val P = Free (Name.variant all_variants "P", rec_schemeT0-->Term.propT) in |
17261 | 2066 |
Logic.mk_equals |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2067 |
(All [dest_Free r0] (P $ r0), All (map dest_Free all_vars_more) (P $ r_rec0)) |
17261 | 2068 |
end; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2069 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2070 |
val split_object_prop = |
30190 | 2071 |
let fun ALL vs t = List.foldr (fn ((v,T),t) => HOLogic.mk_all (v,T,t)) t vs |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2072 |
in (ALL [dest_Free r0] (P $ r0)) === (ALL (map dest_Free all_vars_more) (P $ r_rec0)) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2073 |
end; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2074 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2075 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2076 |
val split_ex_prop = |
30190 | 2077 |
let fun EX vs t = List.foldr (fn ((v,T),t) => HOLogic.mk_exists (v,T,t)) t vs |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2078 |
in (EX [dest_Free r0] (P $ r0)) === (EX (map dest_Free all_vars_more) (P $ r_rec0)) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2079 |
end; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2080 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2081 |
(*equality*) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2082 |
val equality_prop = |
17261 | 2083 |
let |
2084 |
val s' = Free (rN ^ "'", rec_schemeT0) |
|
2085 |
fun mk_sel_eq (c,Free (_,T)) = mk_sel r0 (c,T) === mk_sel s' (c,T) |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2086 |
val seleqs = map mk_sel_eq all_named_vars_more |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2087 |
in All (map dest_Free [r0,s']) (Logic.list_implies (seleqs,r0 === s')) end; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2088 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2089 |
(* 3rd stage: thms_thy *) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2090 |
|
17510 | 2091 |
fun prove stndrd = quick_and_dirty_prove stndrd defs_thy; |
2092 |
val prove_standard = quick_and_dirty_prove true defs_thy; |
|
17261 | 2093 |
|
15215 | 2094 |
fun prove_simp stndrd ss simps = |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2095 |
let val tac = simp_all_tac ss simps |
15215 | 2096 |
in fn prop => prove stndrd [] prop (K tac) end; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2097 |
|
17510 | 2098 |
val ss = get_simpset defs_thy; |
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
2099 |
|
17261 | 2100 |
fun sel_convs_prf () = map (prove_simp false ss |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2101 |
(sel_defs@accessor_thms)) sel_conv_props; |
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
2102 |
val sel_convs = timeit_msg "record sel_convs proof:" sel_convs_prf; |
15215 | 2103 |
fun sel_convs_standard_prf () = map standard sel_convs |
17261 | 2104 |
val sel_convs_standard = |
2105 |
timeit_msg "record sel_convs_standard proof:" sel_convs_standard_prf; |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2106 |
|
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2107 |
fun upd_convs_prf () = map (prove_simp false ss |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2108 |
(upd_defs@updator_thms)) upd_conv_props; |
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
2109 |
val upd_convs = timeit_msg "record upd_convs proof:" upd_convs_prf; |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2110 |
fun upd_convs_standard_prf () = map standard upd_convs |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2111 |
val upd_convs_standard = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2112 |
timeit_msg "record upd_convs_standard proof:" upd_convs_standard_prf; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2113 |
|
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2114 |
fun get_upd_acc_congs () = let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2115 |
val symdefs = map symmetric (sel_defs @ upd_defs); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2116 |
val fold_ss = HOL_basic_ss addsimps symdefs; |
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
2117 |
val ua_congs = map (standard o simplify fold_ss) upd_acc_cong_assists; |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2118 |
in (ua_congs RL [updacc_foldE], ua_congs RL [updacc_unfoldE]) end; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2119 |
val (fold_congs, unfold_congs) = |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2120 |
timeit_msg "record upd fold/unfold congs:" get_upd_acc_congs; |
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
2121 |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2122 |
val parent_induct = if null parents then [] else [#induct (hd (rev parents))]; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2123 |
|
27217 | 2124 |
fun induct_scheme_prf () = prove_standard [] induct_scheme_prop (fn _ => |
17261 | 2125 |
(EVERY [if null parent_induct |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2126 |
then all_tac else try_param_tac rN (hd parent_induct) 1, |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2127 |
try_param_tac rN ext_induct 1, |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2128 |
asm_simp_tac HOL_basic_ss 1])); |
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
2129 |
val induct_scheme = timeit_msg "record induct_scheme proof:" induct_scheme_prf; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2130 |
|
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
2131 |
fun induct_prf () = |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2132 |
let val (assm, concl) = induct_prop; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2133 |
in |
20248 | 2134 |
prove_standard [assm] concl (fn {prems, ...} => |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2135 |
try_param_tac rN induct_scheme 1 |
27104
791607529f6d
rep_datatype command now takes list of constructors as input arguments
haftmann
parents:
26957
diff
changeset
|
2136 |
THEN try_param_tac "more" @{thm unit.induct} 1 |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2137 |
THEN resolve_tac prems 1) |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2138 |
end; |
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
2139 |
val induct = timeit_msg "record induct proof:" induct_prf; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2140 |
|
15215 | 2141 |
fun cases_scheme_prf_opt () = |
17261 | 2142 |
let |
15215 | 2143 |
val (_$(Pvar$_)) = concl_of induct_scheme; |
17261 | 2144 |
val ind = cterm_instantiate |
18858 | 2145 |
[(cterm_of defs_thy Pvar, cterm_of defs_thy |
15215 | 2146 |
(lambda w (HOLogic.imp$HOLogic.mk_eq(r0,w)$C)))] |
2147 |
induct_scheme; |
|
2148 |
in standard (ObjectLogic.rulify (mp OF [ind, refl])) end; |
|
2149 |
||
2150 |
fun cases_scheme_prf_noopt () = |
|
27217 | 2151 |
prove_standard [] cases_scheme_prop (fn _ => |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2152 |
EVERY [asm_full_simp_tac (HOL_basic_ss addsimps [atomize_all, atomize_imp]) 1, |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2153 |
try_param_tac rN induct_scheme 1, |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2154 |
rtac impI 1, |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2155 |
REPEAT (etac allE 1), |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2156 |
etac mp 1, |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2157 |
rtac refl 1]) |
15215 | 2158 |
val cases_scheme_prf = quick_and_dirty_prf cases_scheme_prf_noopt cases_scheme_prf_opt; |
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
2159 |
val cases_scheme = timeit_msg "record cases_scheme proof:" cases_scheme_prf; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2160 |
|
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
2161 |
fun cases_prf () = |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
2162 |
prove_standard [] cases_prop (fn _ => |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2163 |
try_param_tac rN cases_scheme 1 |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2164 |
THEN simp_all_tac HOL_basic_ss [unit_all_eq1]); |
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
2165 |
val cases = timeit_msg "record cases proof:" cases_prf; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2166 |
|
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2167 |
fun surjective_prf () = let |
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
2168 |
val leaf_ss = get_sel_upd_defs defs_thy |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
2169 |
addsimps (sel_defs @ (o_assoc :: id_o_apps)); |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
2170 |
val init_ss = HOL_basic_ss addsimps ext_defs; |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2171 |
in |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2172 |
prove_standard [] surjective_prop (fn prems => |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2173 |
(EVERY [rtac surject_assist_idE 1, |
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
2174 |
simp_tac init_ss 1, |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2175 |
REPEAT (intros_tac 1 ORELSE |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2176 |
(rtac surject_assistI 1 THEN |
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
2177 |
simp_tac leaf_ss 1))])) |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2178 |
end; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2179 |
val surjective = timeit_msg "record surjective proof:" surjective_prf; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2180 |
|
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
2181 |
fun split_meta_prf () = |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2182 |
prove false [] split_meta_prop (fn prems => |
21687 | 2183 |
EVERY [rtac equal_intr_rule 1, Goal.norm_hhf_tac 1, |
17960 | 2184 |
etac meta_allE 1, atac 1, |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2185 |
rtac (prop_subst OF [surjective]) 1, |
17960 | 2186 |
REPEAT (etac meta_allE 1), atac 1]); |
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
2187 |
val split_meta = timeit_msg "record split_meta proof:" split_meta_prf; |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2188 |
fun split_meta_standardise () = standard split_meta; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2189 |
val split_meta_standard = timeit_msg "record split_meta standard:" |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2190 |
split_meta_standardise; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2191 |
|
15215 | 2192 |
fun split_object_prf_opt () = |
17261 | 2193 |
let |
18858 | 2194 |
val cPI= cterm_of defs_thy (lambda r0 (Trueprop (P$r0))); |
15215 | 2195 |
val (_$Abs(_,_,P$_)) = fst (Logic.dest_equals (concl_of split_meta_standard)); |
18858 | 2196 |
val cP = cterm_of defs_thy P; |
15215 | 2197 |
val split_meta' = cterm_instantiate [(cP,cPI)] split_meta_standard; |
2198 |
val (l,r) = HOLogic.dest_eq (HOLogic.dest_Trueprop split_object_prop); |
|
18858 | 2199 |
val cl = cterm_of defs_thy (HOLogic.mk_Trueprop l); |
2200 |
val cr = cterm_of defs_thy (HOLogic.mk_Trueprop r); |
|
15215 | 2201 |
val thl = assume cl (*All r. P r*) (* 1 *) |
2202 |
|> obj_to_meta_all (*!!r. P r*) |
|
17261 | 2203 |
|> equal_elim split_meta' (*!!n m more. P (ext n m more)*) |
2204 |
|> meta_to_obj_all (*All n m more. P (ext n m more)*) (* 2*) |
|
15215 | 2205 |
|> implies_intr cl (* 1 ==> 2 *) |
2206 |
val thr = assume cr (*All n m more. P (ext n m more)*) |
|
2207 |
|> obj_to_meta_all (*!!n m more. P (ext n m more)*) |
|
17261 | 2208 |
|> equal_elim (symmetric split_meta') (*!!r. P r*) |
15215 | 2209 |
|> meta_to_obj_all (*All r. P r*) |
2210 |
|> implies_intr cr (* 2 ==> 1 *) |
|
17261 | 2211 |
in standard (thr COMP (thl COMP iffI)) end; |
15215 | 2212 |
|
2213 |
fun split_object_prf_noopt () = |
|
27217 | 2214 |
prove_standard [] split_object_prop (fn _ => |
17261 | 2215 |
EVERY [rtac iffI 1, |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2216 |
REPEAT (rtac allI 1), etac allE 1, atac 1, |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2217 |
rtac allI 1, rtac induct_scheme 1,REPEAT (etac allE 1),atac 1]); |
15215 | 2218 |
|
17261 | 2219 |
val split_object_prf = quick_and_dirty_prf split_object_prf_noopt split_object_prf_opt; |
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
2220 |
val split_object = timeit_msg "record split_object proof:" split_object_prf; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2221 |
|
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
2222 |
|
17261 | 2223 |
fun split_ex_prf () = |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2224 |
let |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2225 |
val ss = HOL_basic_ss addsimps [not_ex RS sym, nth simp_thms 1]; |
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
2226 |
val [Pv] = OldTerm.term_vars (prop_of split_object); |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2227 |
val cPv = cterm_of defs_thy Pv; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2228 |
val cP = cterm_of defs_thy (lambda r0 (HOLogic.mk_not (P $ r0))); |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2229 |
val so3 = cterm_instantiate ([(cPv, cP)]) split_object; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2230 |
val so4 = simplify ss so3; |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2231 |
in |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2232 |
prove_standard [] split_ex_prop (fn prems => resolve_tac [so4] 1) |
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2233 |
end; |
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
2234 |
val split_ex = timeit_msg "record split_ex proof:" split_ex_prf; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2235 |
|
17261 | 2236 |
fun equality_tac thms = |
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
2237 |
let val (s'::s::eqs) = rev thms; |
15215 | 2238 |
val ss' = ss addsimps (s'::s::sel_convs_standard); |
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
2239 |
val eqs' = map (simplify ss') eqs; |
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
2240 |
in simp_tac (HOL_basic_ss addsimps (s'::s::eqs')) 1 end; |
17261 | 2241 |
|
27217 | 2242 |
fun equality_prf () = prove_standard [] equality_prop (fn {context, ...} => |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2243 |
fn st => let val [s, s'] = map #1 (rev (Tactic.innermost_params 1 st)) in |
27239 | 2244 |
st |> (res_inst_tac context [((rN, 0), s)] cases_scheme 1 |
2245 |
THEN res_inst_tac context [((rN, 0), s')] cases_scheme 1 |
|
32283 | 2246 |
THEN (Subgoal.FOCUS (fn {prems, ...} => equality_tac prems) context 1)) |
15012
28fa57b57209
Added reference record_definition_quick_and_dirty_sensitive, to
schirmer
parents:
14981
diff
changeset
|
2247 |
(* simp_all_tac ss (sel_convs) would also work but is less efficient *) |
17261 | 2248 |
end); |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
2249 |
val equality = timeit_msg "record equality proof:" equality_prf; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2250 |
|
32335 | 2251 |
val ((([sel_convs', upd_convs', sel_defs', upd_defs', |
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
2252 |
fold_congs', unfold_congs', |
32335 | 2253 |
[split_meta', split_object', split_ex'], derived_defs'], |
2254 |
[surjective', equality']), |
|
2255 |
[induct_scheme', induct', cases_scheme', cases']), thms_thy) = |
|
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2256 |
defs_thy |
29579 | 2257 |
|> (PureThy.add_thmss o map (Thm.no_attributes o apfst Binding.name)) |
15215 | 2258 |
[("select_convs", sel_convs_standard), |
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
2259 |
("update_convs", upd_convs_standard), |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2260 |
("select_defs", sel_defs), |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2261 |
("update_defs", upd_defs), |
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
2262 |
("fold_congs", fold_congs), |
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
2263 |
("unfold_congs", unfold_congs), |
15215 | 2264 |
("splits", [split_meta_standard,split_object,split_ex]), |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2265 |
("defs", derived_defs)] |
29579 | 2266 |
||>> (PureThy.add_thms o map (Thm.no_attributes o apfst Binding.name)) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2267 |
[("surjective", surjective), |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2268 |
("equality", equality)] |
29579 | 2269 |
||>> (PureThy.add_thms o (map o apfst o apfst) Binding.name) |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2270 |
[(("induct_scheme", induct_scheme), induct_type_global (suffix schemeN name)), |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2271 |
(("induct", induct), induct_type_global name), |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2272 |
(("cases_scheme", cases_scheme), cases_type_global (suffix schemeN name)), |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2273 |
(("cases", cases), cases_type_global name)]; |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2274 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2275 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2276 |
val sel_upd_simps = sel_convs' @ upd_convs'; |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2277 |
val sel_upd_defs = sel_defs' @ upd_defs'; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2278 |
val iffs = [ext_inject] |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2279 |
val depth = parent_len + 1; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2280 |
val final_thy = |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2281 |
thms_thy |
18377 | 2282 |
|> (snd oo PureThy.add_thmss) |
29871
74366d50cf2b
Added nitpick_const_simp attribute to recdef and record packages.
blanchet
parents:
29579
diff
changeset
|
2283 |
[((Binding.name "simps", sel_upd_simps), |
31902 | 2284 |
[Simplifier.simp_add, Nitpick_Const_Simps.add]), |
29579 | 2285 |
((Binding.name "iffs", iffs), [iff_add])] |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2286 |
|> put_record name (make_record_info args parent fields extension induct_scheme' ext_def) |
32744
50406c4951d9
Record patch imported and working.
Thomas Sewell <tsewell@nicta.com.au>
parents:
32743
diff
changeset
|
2287 |
|> put_sel_upd names full_moreN depth sel_upd_simps |
32743
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
tsewell@rubicon.NSW.bigpond.net.au
parents:
32335
diff
changeset
|
2288 |
sel_upd_defs (fold_congs', unfold_congs') |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2289 |
|> add_record_equalities extension_id equality' |
15015
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
2290 |
|> add_extinjects ext_inject |
c5768e8c4da4
* record_upd_simproc also simplifies trivial updates:
schirmer
parents:
15012
diff
changeset
|
2291 |
|> add_extsplit extension_name ext_split |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2292 |
|> add_record_splits extension_id (split_meta',split_object',split_ex',induct_scheme') |
17261 | 2293 |
|> add_extfields extension_name (fields @ [(full_moreN,moreT)]) |
2294 |
|> add_fieldext (extension_name,snd extension) (names @ [full_moreN]) |
|
24712
64ed05609568
proper Sign operations instead of Theory aliases;
wenzelm
parents:
24624
diff
changeset
|
2295 |
|> Sign.parent_path; |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2296 |
|
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2297 |
in final_thy |
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2298 |
end; |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2299 |
|
27278
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
2300 |
|
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2301 |
(* add_record *) |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2302 |
|
4895 | 2303 |
(*we do all preparations and error checks here, deferring the real |
2304 |
work to record_definition*) |
|
26477
ecf06644f6cb
eliminated quiete_mode ref (turned into proper argument);
wenzelm
parents:
26423
diff
changeset
|
2305 |
fun gen_add_record prep_typ prep_raw_parent quiet_mode (params, bname) raw_parent raw_fields thy = |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2306 |
let |
17261 | 2307 |
val _ = Theory.requires thy "Record" "record definitions"; |
26477
ecf06644f6cb
eliminated quiete_mode ref (turned into proper argument);
wenzelm
parents:
26423
diff
changeset
|
2308 |
val _ = if quiet_mode then () else writeln ("Defining record " ^ quote bname ^ " ..."); |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2309 |
|
27278
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
2310 |
val ctxt = ProofContext.init thy; |
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
2311 |
|
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2312 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2313 |
(* parents *) |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2314 |
|
27278
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
2315 |
fun prep_inst T = fst (cert_typ ctxt T []); |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2316 |
|
27278
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
2317 |
val parent = Option.map (apfst (map prep_inst) o prep_raw_parent ctxt) raw_parent |
18678 | 2318 |
handle ERROR msg => cat_error msg ("The error(s) above in parent record specification"); |
12247 | 2319 |
val parents = add_parents thy parent []; |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2320 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2321 |
val init_env = |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2322 |
(case parent of |
15531 | 2323 |
NONE => [] |
30190 | 2324 |
| SOME (types, _) => List.foldr OldTerm.add_typ_tfrees [] types); |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2325 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2326 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2327 |
(* fields *) |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2328 |
|
27278
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
2329 |
fun prep_field (c, raw_T, mx) env = |
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
2330 |
let val (T, env') = prep_typ ctxt raw_T env handle ERROR msg => |
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
2331 |
cat_error msg ("The error(s) above occured in record field " ^ quote c) |
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
2332 |
in ((c, T, mx), env') end; |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2333 |
|
27278
129574589734
export read_typ/cert_typ -- version with regular context operations;
wenzelm
parents:
27239
diff
changeset
|
2334 |
val (bfields, envir) = fold_map prep_field raw_fields init_env; |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2335 |
val envir_names = map fst envir; |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2336 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2337 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2338 |
(* args *) |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2339 |
|
22578 | 2340 |
val defaultS = Sign.defaultS thy; |
17485 | 2341 |
val args = map (fn x => (x, AList.lookup (op =) envir x |> the_default defaultS)) params; |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2342 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2343 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2344 |
(* errors *) |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2345 |
|
28965 | 2346 |
val name = Sign.full_bname thy bname; |
17261 | 2347 |
val err_dup_record = |
4890 | 2348 |
if is_none (get_record thy name) then [] |
2349 |
else ["Duplicate definition of record " ^ quote name]; |
|
2350 |
||
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2351 |
val err_dup_parms = |
18964 | 2352 |
(case duplicates (op =) params of |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2353 |
[] => [] |
4890 | 2354 |
| dups => ["Duplicate parameter(s) " ^ commas dups]); |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2355 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2356 |
val err_extra_frees = |
20951
868120282837
gen_rem(s) abandoned in favour of remove / subtract
haftmann
parents:
20484
diff
changeset
|
2357 |
(case subtract (op =) params envir_names of |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2358 |
[] => [] |
4890 | 2359 |
| extras => ["Extra free type variable(s) " ^ commas extras]); |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2360 |
|
4890 | 2361 |
val err_no_fields = if null bfields then ["No fields present"] else []; |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2362 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2363 |
val err_dup_fields = |
18964 | 2364 |
(case duplicates (op =) (map #1 bfields) of |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2365 |
[] => [] |
4890 | 2366 |
| dups => ["Duplicate field(s) " ^ commas_quote dups]); |
2367 |
||
2368 |
val err_bad_fields = |
|
12506 | 2369 |
if forall (not_equal moreN o #1) bfields then [] |
4890 | 2370 |
else ["Illegal field name " ^ quote moreN]; |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2371 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2372 |
val err_dup_sorts = |
18964 | 2373 |
(case duplicates (op =) envir_names of |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2374 |
[] => [] |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2375 |
| dups => ["Inconsistent sort constraints for " ^ commas dups]); |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2376 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2377 |
val errs = |
4890 | 2378 |
err_dup_record @ err_dup_parms @ err_extra_frees @ err_no_fields @ |
2379 |
err_dup_fields @ err_bad_fields @ err_dup_sorts; |
|
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2380 |
in |
14700
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
schirmer
parents:
14643
diff
changeset
|
2381 |
if null errs then () else error (cat_lines errs) ; |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2382 |
thy |> record_definition (args, bname) parent parents bfields |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2383 |
end |
18678 | 2384 |
handle ERROR msg => cat_error msg ("Failed to define record " ^ quote bname); |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2385 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2386 |
val add_record = gen_add_record read_typ read_raw_parent; |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2387 |
val add_record_i = gen_add_record cert_typ (K I); |
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2388 |
|
32335 | 2389 |
|
6358 | 2390 |
(* setup theory *) |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2391 |
|
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2392 |
val setup = |
24712
64ed05609568
proper Sign operations instead of Theory aliases;
wenzelm
parents:
24624
diff
changeset
|
2393 |
Sign.add_trfuns ([], parse_translation, [], []) #> |
64ed05609568
proper Sign operations instead of Theory aliases;
wenzelm
parents:
24624
diff
changeset
|
2394 |
Sign.add_advanced_trfuns ([], adv_parse_translation, [], []) #> |
26496
49ae9456eba9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26477
diff
changeset
|
2395 |
Simplifier.map_simpset (fn ss => |
49ae9456eba9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26477
diff
changeset
|
2396 |
ss addsimprocs [record_simproc, record_upd_simproc, record_eq_simproc]); |
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2397 |
|
32335 | 2398 |
|
6358 | 2399 |
(* outer syntax *) |
2400 |
||
17057 | 2401 |
local structure P = OuterParse and K = OuterKeyword in |
6358 | 2402 |
|
2403 |
val record_decl = |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12590
diff
changeset
|
2404 |
P.type_args -- P.name -- |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12590
diff
changeset
|
2405 |
(P.$$$ "=" |-- Scan.option (P.typ --| P.$$$ "+") -- Scan.repeat1 P.const); |
6358 | 2406 |
|
24867 | 2407 |
val _ = |
17261 | 2408 |
OuterSyntax.command "record" "define extensible record" K.thy_decl |
26477
ecf06644f6cb
eliminated quiete_mode ref (turned into proper argument);
wenzelm
parents:
26423
diff
changeset
|
2409 |
(record_decl >> (fn (x, (y, z)) => Toplevel.theory (add_record false x y z))); |
6358 | 2410 |
|
4867
9be2bf0ce909
package extensible records with structural subtyping in HOL -- still
wenzelm
parents:
diff
changeset
|
2411 |
end; |
5698 | 2412 |
|
6384 | 2413 |
end; |
2414 |
||
32335 | 2415 |
structure Basic_Record: BASIC_RECORD = Record; |
2416 |
open Basic_Record; |