author | Cezary Kaliszyk <kaliszyk@in.tum.de> |
Wed, 04 Nov 2009 15:27:32 +0100 | |
changeset 283 | 5470176d6730 |
parent 264 | d0581fbc096c |
child 290 | a0be84b0c707 |
permissions | -rw-r--r-- |
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
1 |
signature QUOTIENT = |
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
2 |
sig |
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
3 |
val mk_quotient_type: ((binding * mixfix) * (typ * term)) list -> Proof.context -> Proof.state |
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
4 |
val mk_quotient_type_cmd: (((bstring * mixfix) * string) * string) list -> Proof.context -> Proof.state |
128 | 5 |
val define: binding * mixfix * term -> local_theory -> (term * thm) * local_theory |
6 |
val note: binding * thm -> local_theory -> thm * local_theory |
|
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
7 |
end; |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
8 |
|
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
9 |
structure Quotient: QUOTIENT = |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
10 |
struct |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
11 |
|
205 | 12 |
(* wrappers for define, note and theorem_i *) |
135
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
13 |
fun define (name, mx, rhs) lthy = |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
14 |
let |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
15 |
val ((rhs, (_ , thm)), lthy') = |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
16 |
LocalTheory.define Thm.internalK ((name, mx), (Attrib.empty_binding, rhs)) lthy |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
17 |
in |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
18 |
((rhs, thm), lthy') |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
19 |
end |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
20 |
|
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
21 |
fun note (name, thm) lthy = |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
22 |
let |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
23 |
val ((_,[thm']), lthy') = LocalTheory.note Thm.theoremK ((name, []), [thm]) lthy |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
24 |
in |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
25 |
(thm', lthy') |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
26 |
end |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
27 |
|
203
7384115df9fd
added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
28 |
fun theorem after_qed goals ctxt = |
7384115df9fd
added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
29 |
let |
7384115df9fd
added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
30 |
val goals' = map (rpair []) goals |
7384115df9fd
added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
31 |
fun after_qed' thms = after_qed (the_single thms) |
7384115df9fd
added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
32 |
in |
7384115df9fd
added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
33 |
Proof.theorem_i NONE after_qed' [goals'] ctxt |
7384115df9fd
added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
34 |
end |
135
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
35 |
|
130
8e8ba210f0f7
moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents:
128
diff
changeset
|
36 |
|
8e8ba210f0f7
moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents:
128
diff
changeset
|
37 |
(* definition of the quotient type *) |
8e8ba210f0f7
moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents:
128
diff
changeset
|
38 |
(***********************************) |
8e8ba210f0f7
moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents:
128
diff
changeset
|
39 |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
40 |
(* constructs the term lambda (c::rty => bool). EX (x::rty). c = rel x *) |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
41 |
fun typedef_term rel rty lthy = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
42 |
let |
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
43 |
val [x, c] = [("x", rty), ("c", HOLogic.mk_setT rty)] |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
44 |
|> Variable.variant_frees lthy [rel] |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
45 |
|> map Free |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
46 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
47 |
lambda c |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
48 |
(HOLogic.exists_const rty $ |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
49 |
lambda x (HOLogic.mk_eq (c, (rel $ x)))) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
50 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
51 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
52 |
(* makes the new type definitions and proves non-emptyness*) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
53 |
fun typedef_make (qty_name, mx, rel, rty) lthy = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
54 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
55 |
val typedef_tac = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
56 |
EVERY1 [rewrite_goal_tac @{thms mem_def}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
57 |
rtac @{thm exI}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
58 |
rtac @{thm exI}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
59 |
rtac @{thm refl}] |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
60 |
val tfrees = map fst (Term.add_tfreesT rty []) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
61 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
62 |
LocalTheory.theory_result |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
63 |
(Typedef.add_typedef false NONE |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
64 |
(qty_name, tfrees, mx) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
65 |
(typedef_term rel rty lthy) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
66 |
NONE typedef_tac) lthy |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
67 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
68 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
69 |
(* tactic to prove the QUOT_TYPE theorem for the new type *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
70 |
fun typedef_quot_type_tac equiv_thm (typedef_info: Typedef.info) = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
71 |
let |
205 | 72 |
val unfold_mem = MetaSimplifier.rewrite_rule [@{thm mem_def}] |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
73 |
val rep_thm = #Rep typedef_info |> unfold_mem |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
74 |
val rep_inv = #Rep_inverse typedef_info |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
75 |
val abs_inv = #Abs_inverse typedef_info |> unfold_mem |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
76 |
val rep_inj = #Rep_inject typedef_info |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
77 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
78 |
EVERY1 [rtac @{thm QUOT_TYPE.intro}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
79 |
rtac equiv_thm, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
80 |
rtac rep_thm, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
81 |
rtac rep_inv, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
82 |
rtac abs_inv, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
83 |
rtac @{thm exI}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
84 |
rtac @{thm refl}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
85 |
rtac rep_inj] |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
86 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
87 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
88 |
(* proves the QUOT_TYPE theorem *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
89 |
fun typedef_quot_type_thm (rel, abs, rep, equiv_thm, typedef_info) lthy = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
90 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
91 |
val quot_type_const = Const (@{const_name "QUOT_TYPE"}, dummyT) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
92 |
val goal = HOLogic.mk_Trueprop (quot_type_const $ rel $ abs $ rep) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
93 |
|> Syntax.check_term lthy |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
94 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
95 |
Goal.prove lthy [] [] goal |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
96 |
(K (typedef_quot_type_tac equiv_thm typedef_info)) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
97 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
98 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
99 |
(* proves the quotient theorem *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
100 |
fun typedef_quotient_thm (rel, abs, rep, abs_def, rep_def, quot_type_thm) lthy = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
101 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
102 |
val quotient_const = Const (@{const_name "QUOTIENT"}, dummyT) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
103 |
val goal = HOLogic.mk_Trueprop (quotient_const $ rel $ abs $ rep) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
104 |
|> Syntax.check_term lthy |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
105 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
106 |
val typedef_quotient_thm_tac = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
107 |
EVERY1 [K (rewrite_goals_tac [abs_def, rep_def]), |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
108 |
rtac @{thm QUOT_TYPE.QUOTIENT}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
109 |
rtac quot_type_thm] |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
110 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
111 |
Goal.prove lthy [] [] goal |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
112 |
(K typedef_quotient_thm_tac) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
113 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
114 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
115 |
(* main function for constructing the quotient type *) |
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
116 |
fun mk_typedef_main (((qty_name, mx), (rty, rel)), equiv_thm) lthy = |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
117 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
118 |
(* generates typedef *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
119 |
val ((_, typedef_info), lthy1) = typedef_make (qty_name, mx, rel, rty) lthy |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
120 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
121 |
(* abs and rep functions *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
122 |
val abs_ty = #abs_type typedef_info |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
123 |
val rep_ty = #rep_type typedef_info |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
124 |
val abs_name = #Abs_name typedef_info |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
125 |
val rep_name = #Rep_name typedef_info |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
126 |
val abs = Const (abs_name, rep_ty --> abs_ty) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
127 |
val rep = Const (rep_name, abs_ty --> rep_ty) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
128 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
129 |
(* ABS and REP definitions *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
130 |
val ABS_const = Const (@{const_name "QUOT_TYPE.ABS"}, dummyT ) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
131 |
val REP_const = Const (@{const_name "QUOT_TYPE.REP"}, dummyT ) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
132 |
val ABS_trm = Syntax.check_term lthy1 (ABS_const $ rel $ abs) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
133 |
val REP_trm = Syntax.check_term lthy1 (REP_const $ rep) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
134 |
val ABS_name = Binding.prefix_name "ABS_" qty_name |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
135 |
val REP_name = Binding.prefix_name "REP_" qty_name |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
136 |
val (((ABS, ABS_def), (REP, REP_def)), lthy2) = |
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
137 |
lthy1 |> define (ABS_name, NoSyn, ABS_trm) |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
138 |
||>> define (REP_name, NoSyn, REP_trm) |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
139 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
140 |
(* quot_type theorem *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
141 |
val quot_thm = typedef_quot_type_thm (rel, abs, rep, equiv_thm, typedef_info) lthy2 |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
142 |
val quot_thm_name = Binding.prefix_name "QUOT_TYPE_" qty_name |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
143 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
144 |
(* quotient theorem *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
145 |
val quotient_thm = typedef_quotient_thm (rel, ABS, REP, ABS_def, REP_def, quot_thm) lthy2 |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
146 |
val quotient_thm_name = Binding.prefix_name "QUOTIENT_" qty_name |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
147 |
|
182
c7eff9882bd8
added data-storage about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
170
diff
changeset
|
148 |
(* storing the quot-info *) |
254
77ff9624cfd6
fixed the problem with types in map
Christian Urban <urbanc@in.tum.de>
parents:
218
diff
changeset
|
149 |
val lthy3 = quotdata_update (Logic.varifyT abs_ty, Logic.varifyT rty, rel, equiv_thm) lthy2 |
182
c7eff9882bd8
added data-storage about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
170
diff
changeset
|
150 |
|
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
151 |
(* interpretation *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
152 |
val bindd = ((Binding.make ("", Position.none)), ([]: Attrib.src list)) |
182
c7eff9882bd8
added data-storage about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
170
diff
changeset
|
153 |
val ((_, [eqn1pre]), lthy4) = Variable.import true [ABS_def] lthy3; |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
154 |
val eqn1i = Thm.prop_of (symmetric eqn1pre) |
182
c7eff9882bd8
added data-storage about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
170
diff
changeset
|
155 |
val ((_, [eqn2pre]), lthy5) = Variable.import true [REP_def] lthy4; |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
156 |
val eqn2i = Thm.prop_of (symmetric eqn2pre) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
157 |
|
182
c7eff9882bd8
added data-storage about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
170
diff
changeset
|
158 |
val exp_morphism = ProofContext.export_morphism lthy5 (ProofContext.init (ProofContext.theory_of lthy5)); |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
159 |
val exp_term = Morphism.term exp_morphism; |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
160 |
val exp = Morphism.thm exp_morphism; |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
161 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
162 |
val mthd = Method.SIMPLE_METHOD ((rtac quot_thm 1) THEN |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
163 |
ALLGOALS (simp_tac (HOL_basic_ss addsimps [(symmetric (exp ABS_def)), (symmetric (exp REP_def))]))) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
164 |
val mthdt = Method.Basic (fn _ => mthd) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
165 |
val bymt = Proof.global_terminal_proof (mthdt, NONE) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
166 |
val exp_i = [(@{const_name QUOT_TYPE}, ((("QUOT_TYPE_I_" ^ (Binding.name_of qty_name)), true), |
170 | 167 |
Expression.Named [("R", rel), ("Abs", abs), ("Rep", rep) ]))] |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
168 |
in |
182
c7eff9882bd8
added data-storage about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
170
diff
changeset
|
169 |
lthy5 |
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
170 |
|> note (quot_thm_name, quot_thm) |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
171 |
||>> note (quotient_thm_name, quotient_thm) |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
172 |
||> LocalTheory.theory (fn thy => |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
173 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
174 |
val global_eqns = map exp_term [eqn2i, eqn1i]; |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
175 |
(* Not sure if the following context should not be used *) |
182
c7eff9882bd8
added data-storage about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
170
diff
changeset
|
176 |
val (global_eqns2, lthy6) = Variable.import_terms true global_eqns lthy5; |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
177 |
val global_eqns3 = map (fn t => (bindd, t)) global_eqns2; |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
178 |
in ProofContext.theory_of (bymt (Expression.interpretation (exp_i, []) global_eqns3 thy)) end) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
179 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
180 |
|
130
8e8ba210f0f7
moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents:
128
diff
changeset
|
181 |
|
8e8ba210f0f7
moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents:
128
diff
changeset
|
182 |
|
8e8ba210f0f7
moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents:
128
diff
changeset
|
183 |
|
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
184 |
(* interface and syntax setup *) |
75
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
185 |
|
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
186 |
(* the ML-interface takes a list of 4-tuples consisting of *) |
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
187 |
(* *) |
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
188 |
(* - the name of the quotient type *) |
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
189 |
(* - its mixfix annotation *) |
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
190 |
(* - the type to be quotient *) |
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
191 |
(* - the relation according to which the type is quotient *) |
130
8e8ba210f0f7
moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents:
128
diff
changeset
|
192 |
|
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
193 |
fun mk_quotient_type quot_list lthy = |
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
194 |
let |
185
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
195 |
fun mk_goal (rty, rel) = |
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
196 |
let |
148
8e24e65f1e9b
tuned and attempted to store data about the quotients (does not work yet)
Christian Urban <urbanc@in.tum.de>
parents:
135
diff
changeset
|
197 |
val EQUIV_ty = ([rty, rty] ---> @{typ bool}) --> @{typ bool} |
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
198 |
in |
203
7384115df9fd
added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
199 |
HOLogic.mk_Trueprop (Const (@{const_name EQUIV}, EQUIV_ty) $ rel) |
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
200 |
end |
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
201 |
|
185
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
202 |
val goals = map (mk_goal o snd) quot_list |
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
203 |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
204 |
fun after_qed thms lthy = |
203
7384115df9fd
added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
205 |
fold_map mk_typedef_main (quot_list ~~ thms) lthy |> snd |
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
206 |
in |
203
7384115df9fd
added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
207 |
theorem after_qed goals lthy |
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
208 |
end |
205 | 209 |
|
210 |
fun mk_quotient_type_cmd spec lthy = |
|
211 |
let |
|
212 |
fun parse_spec (((qty_str, mx), rty_str), rel_str) = |
|
213 |
let |
|
214 |
val qty_name = Binding.name qty_str |
|
215 |
val rty = Syntax.parse_typ lthy rty_str |> Syntax.check_typ lthy |
|
216 |
val rel = Syntax.parse_term lthy rel_str |> Syntax.check_term lthy |
|
217 |
in |
|
218 |
((qty_name, mx), (rty, rel)) |
|
219 |
end |
|
220 |
in |
|
221 |
mk_quotient_type (map parse_spec spec) lthy |
|
222 |
end |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
223 |
|
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
224 |
val quotspec_parser = |
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
225 |
OuterParse.and_list1 |
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
226 |
(OuterParse.short_ident -- OuterParse.opt_infix -- |
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
227 |
(OuterParse.$$$ "=" |-- OuterParse.typ) -- |
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
228 |
(OuterParse.$$$ "/" |-- OuterParse.term)) |
75
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
229 |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
230 |
val _ = OuterKeyword.keyword "/" |
75
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
231 |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
232 |
val _ = |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
233 |
OuterSyntax.local_theory_to_proof "quotient" |
82 | 234 |
"quotient type definitions (requires equivalence proofs)" |
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
82
diff
changeset
|
235 |
OuterKeyword.thy_goal (quotspec_parser >> mk_quotient_type_cmd) |
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
236 |
|
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
237 |
end; (* structure *) |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
238 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
239 |
open Quotient |