2337
|
1 |
(* Title: nominal_dt_alpha.ML
|
|
2 |
Author: Christian Urban
|
|
3 |
Author: Cezary Kaliszyk
|
|
4 |
|
2426
|
5 |
Performing quotient constructions and lifting theorems
|
2337
|
6 |
*)
|
|
7 |
|
|
8 |
signature NOMINAL_DT_QUOT =
|
|
9 |
sig
|
2400
|
10 |
val define_qtypes: (string list * binding * mixfix) list -> typ list -> term list ->
|
2337
|
11 |
thm list -> local_theory -> Quotient_Info.quotdata_info list * local_theory
|
|
12 |
|
2400
|
13 |
val define_qconsts: typ list -> (string * term * mixfix) list -> local_theory ->
|
2337
|
14 |
Quotient_Info.qconsts_info list * local_theory
|
2346
|
15 |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
16 |
val define_qperms: typ list -> string list -> (string * sort) list ->
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
17 |
(string * term * mixfix) list -> thm list -> local_theory -> local_theory
|
2400
|
18 |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
19 |
val define_qsizes: typ list -> string list -> (string * sort) list ->
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
20 |
(string * term * mixfix) list -> local_theory -> local_theory
|
2426
|
21 |
|
2434
|
22 |
val lift_thms: typ list -> thm list -> thm list -> Proof.context -> thm list * Proof.context
|
2475
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
23 |
|
2337
|
24 |
end
|
|
25 |
|
|
26 |
structure Nominal_Dt_Quot: NOMINAL_DT_QUOT =
|
|
27 |
struct
|
|
28 |
|
2475
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
29 |
|
2337
|
30 |
(* defines the quotient types *)
|
2400
|
31 |
fun define_qtypes qtys_descr alpha_tys alpha_trms alpha_equivp_thms lthy =
|
2476
|
32 |
let
|
|
33 |
val qty_args1 = map2 (fn ty => fn trm => (ty, trm, false)) alpha_tys alpha_trms
|
|
34 |
val qty_args2 = (qtys_descr ~~ qty_args1) ~~ alpha_equivp_thms
|
|
35 |
in
|
|
36 |
fold_map Quotient_Type.add_quotient_type qty_args2 lthy
|
|
37 |
end
|
2337
|
38 |
|
2338
|
39 |
|
2337
|
40 |
(* defines quotient constants *)
|
2400
|
41 |
fun define_qconsts qtys consts_specs lthy =
|
2476
|
42 |
let
|
|
43 |
val (qconst_infos, lthy') =
|
|
44 |
fold_map (Quotient_Def.lift_raw_const qtys) consts_specs lthy
|
|
45 |
val phi = ProofContext.export_morphism lthy' lthy
|
|
46 |
in
|
|
47 |
(map (Quotient_Info.transform_qconsts phi) qconst_infos, lthy')
|
|
48 |
end
|
2337
|
49 |
|
|
50 |
|
2400
|
51 |
(* defines the quotient permutations and proves pt-class *)
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
52 |
fun define_qperms qtys qfull_ty_names tvs perm_specs raw_perm_laws lthy =
|
2476
|
53 |
let
|
|
54 |
val lthy1 =
|
|
55 |
lthy
|
|
56 |
|> Local_Theory.exit_global
|
|
57 |
|> Class.instantiation (qfull_ty_names, tvs, @{sort pt})
|
2398
|
58 |
|
2476
|
59 |
val (qs, lthy2) = define_qconsts qtys perm_specs lthy1
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
60 |
|
2476
|
61 |
val ((_, raw_perm_laws'), lthy3) = Variable.importT raw_perm_laws lthy2
|
2398
|
62 |
|
2476
|
63 |
val lifted_perm_laws =
|
|
64 |
map (Quotient_Tacs.lifted lthy3 qtys []) raw_perm_laws'
|
|
65 |
|> Variable.exportT lthy3 lthy2
|
2398
|
66 |
|
2476
|
67 |
fun tac _ =
|
|
68 |
Class.intro_classes_tac [] THEN
|
|
69 |
(ALLGOALS (resolve_tac lifted_perm_laws))
|
|
70 |
in
|
|
71 |
lthy2
|
|
72 |
|> Class.prove_instantiation_exit tac
|
|
73 |
|> Named_Target.theory_init
|
|
74 |
end
|
2346
|
75 |
|
2337
|
76 |
|
2400
|
77 |
(* defines the size functions and proves size-class *)
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
78 |
fun define_qsizes qtys qfull_ty_names tvs size_specs lthy =
|
2476
|
79 |
let
|
|
80 |
val tac = K (Class.intro_classes_tac [])
|
|
81 |
in
|
|
82 |
lthy
|
|
83 |
|> Local_Theory.exit_global
|
|
84 |
|> Class.instantiation (qfull_ty_names, tvs, @{sort size})
|
|
85 |
|> snd o (define_qconsts qtys size_specs)
|
|
86 |
|> Class.prove_instantiation_exit tac
|
|
87 |
|> Named_Target.theory_init
|
|
88 |
end
|
2400
|
89 |
|
2426
|
90 |
|
2475
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
91 |
(* lifts a theorem and cleans all "_raw" parts
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
92 |
from variable names *)
|
2426
|
93 |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
94 |
local
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
95 |
val any = Scan.one (Symbol.not_eof)
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
96 |
val raw = Scan.this_string "_raw"
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
97 |
val exclude =
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
98 |
Scan.repeat (Scan.unless raw any) --| raw >> implode
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
99 |
val parser = Scan.repeat (exclude || any)
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
100 |
in
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
101 |
fun unraw_str s =
|
2476
|
102 |
s |> explode
|
|
103 |
|> Scan.finite Symbol.stopper parser >> implode
|
|
104 |
|> fst
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
105 |
end
|
2426
|
106 |
|
|
107 |
fun unraw_vars_thm thm =
|
2476
|
108 |
let
|
|
109 |
fun unraw_var_str ((s, i), T) = ((unraw_str s, i), T)
|
2426
|
110 |
|
2476
|
111 |
val vars = Term.add_vars (prop_of thm) []
|
|
112 |
val vars' = map (Var o unraw_var_str) vars
|
|
113 |
in
|
|
114 |
Thm.certify_instantiate ([], (vars ~~ vars')) thm
|
|
115 |
end
|
2426
|
116 |
|
|
117 |
fun unraw_bounds_thm th =
|
2476
|
118 |
let
|
|
119 |
val trm = Thm.prop_of th
|
|
120 |
val trm' = Term.map_abs_vars unraw_str trm
|
|
121 |
in
|
|
122 |
Thm.rename_boundvars trm trm' th
|
|
123 |
end
|
2426
|
124 |
|
2434
|
125 |
fun lift_thms qtys simps thms ctxt =
|
|
126 |
(map (Quotient_Tacs.lifted ctxt qtys simps
|
|
127 |
#> unraw_bounds_thm
|
|
128 |
#> unraw_vars_thm
|
|
129 |
#> Drule.zero_var_indexes) thms, ctxt)
|
|
130 |
|
2337
|
131 |
end (* structure *)
|
|
132 |
|