author | Cezary Kaliszyk <kaliszyk@in.tum.de> |
Mon, 07 Dec 2009 15:18:44 +0100 | |
changeset 603 | 7f35355df72e |
parent 598 | ae254a6d685c |
child 685 | b12f0321dfb0 |
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 |
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
365
diff
changeset
|
3 |
exception LIFT_MATCH of string |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
365
diff
changeset
|
4 |
|
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
264
diff
changeset
|
5 |
val quotient_type: ((binding * mixfix) * (typ * term)) list -> Proof.context -> Proof.state |
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
264
diff
changeset
|
6 |
val quotient_type_cmd: (((bstring * mixfix) * string) * string) list -> Proof.context -> Proof.state |
293
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
7 |
|
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
|
8 |
end; |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
9 |
|
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
|
10 |
structure Quotient: QUOTIENT = |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
11 |
struct |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
12 |
|
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
365
diff
changeset
|
13 |
exception LIFT_MATCH of string |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
365
diff
changeset
|
14 |
|
205 | 15 |
(* 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
|
16 |
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
|
17 |
let |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
18 |
val ((rhs, (_ , thm)), lthy') = |
331
345c422b1cb5
updated to Isabelle 22nd November
Christian Urban <urbanc@in.tum.de>
parents:
329
diff
changeset
|
19 |
Local_Theory.define ((name, mx), (Attrib.empty_binding, rhs)) lthy |
135
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
20 |
in |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
21 |
((rhs, thm), lthy') |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
22 |
end |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
23 |
|
503
d2c9a72e52e0
first version of internalised quotient theorems; added FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
447
diff
changeset
|
24 |
fun note (name, thm, attrs) lthy = |
135
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
25 |
let |
503
d2c9a72e52e0
first version of internalised quotient theorems; added FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
447
diff
changeset
|
26 |
val ((_,[thm']), lthy') = Local_Theory.note ((name, attrs), [thm]) lthy |
135
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
27 |
in |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
28 |
(thm', lthy') |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
29 |
end |
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
30 |
|
582
a082e2d138ab
added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents:
529
diff
changeset
|
31 |
fun internal_attr at = Attrib.internal (K at) |
a082e2d138ab
added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents:
529
diff
changeset
|
32 |
|
203
7384115df9fd
added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
33 |
fun theorem after_qed goals ctxt = |
7384115df9fd
added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
34 |
let |
7384115df9fd
added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
35 |
val goals' = map (rpair []) goals |
7384115df9fd
added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
36 |
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
|
37 |
in |
7384115df9fd
added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
38 |
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
|
39 |
end |
135
6f0d14ba096c
started to write code for storing data about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
130
diff
changeset
|
40 |
|
130
8e8ba210f0f7
moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents:
128
diff
changeset
|
41 |
|
329 | 42 |
(* definition of quotient types *) |
43 |
(********************************) |
|
130
8e8ba210f0f7
moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents:
128
diff
changeset
|
44 |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
45 |
(* 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
|
46 |
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
|
47 |
let |
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
48 |
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
|
49 |
|> Variable.variant_frees lthy [rel] |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
50 |
|> map Free |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
51 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
52 |
lambda c |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
53 |
(HOLogic.exists_const rty $ |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
54 |
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
|
55 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
56 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
57 |
(* 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
|
58 |
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
|
59 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
60 |
val typedef_tac = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
61 |
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
|
62 |
rtac @{thm exI}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
63 |
rtac @{thm exI}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
64 |
rtac @{thm refl}] |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
65 |
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
|
66 |
in |
319 | 67 |
Local_Theory.theory_result |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
68 |
(Typedef.add_typedef false NONE |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
69 |
(qty_name, tfrees, mx) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
70 |
(typedef_term rel rty lthy) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
71 |
NONE typedef_tac) lthy |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
72 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
73 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
74 |
(* 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
|
75 |
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
|
76 |
let |
205 | 77 |
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
|
78 |
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
|
79 |
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
|
80 |
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
|
81 |
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
|
82 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
83 |
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
|
84 |
rtac equiv_thm, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
85 |
rtac rep_thm, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
86 |
rtac rep_inv, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
87 |
rtac abs_inv, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
88 |
rtac @{thm exI}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
89 |
rtac @{thm refl}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
90 |
rtac rep_inj] |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
91 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
92 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
93 |
(* proves the QUOT_TYPE theorem *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
94 |
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
|
95 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
96 |
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
|
97 |
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
|
98 |
|> Syntax.check_term lthy |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
99 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
100 |
Goal.prove lthy [] [] goal |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
101 |
(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
|
102 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
103 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
104 |
(* proves the quotient theorem *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
105 |
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
|
106 |
let |
529 | 107 |
val quotient_const = Const (@{const_name "Quotient"}, dummyT) |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
108 |
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
|
109 |
|> Syntax.check_term lthy |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
110 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
111 |
val typedef_quotient_thm_tac = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
112 |
EVERY1 [K (rewrite_goals_tac [abs_def, rep_def]), |
529 | 113 |
rtac @{thm QUOT_TYPE.Quotient}, |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
114 |
rtac quot_type_thm] |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
115 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
116 |
Goal.prove lthy [] [] goal |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
117 |
(K typedef_quotient_thm_tac) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
118 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
119 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
120 |
(* 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
|
121 |
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
|
122 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
123 |
(* generates typedef *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
124 |
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
|
125 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
126 |
(* abs and rep functions *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
127 |
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
|
128 |
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
|
129 |
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
|
130 |
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
|
131 |
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
|
132 |
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
|
133 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
134 |
(* ABS and REP definitions *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
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
|
140 |
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
|
141 |
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
|
142 |
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
|
143 |
||>> 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
|
144 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
145 |
(* quot_type theorem *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
146 |
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
|
147 |
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
|
148 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
149 |
(* quotient theorem *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
150 |
val quotient_thm = typedef_quotient_thm (rel, ABS, REP, ABS_def, REP_def, quot_thm) lthy2 |
529 | 151 |
val quotient_thm_name = Binding.prefix_name "Quotient_" qty_name |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
152 |
|
182
c7eff9882bd8
added data-storage about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
170
diff
changeset
|
153 |
(* storing the quot-info *) |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
154 |
val qty_str = fst (Term.dest_Type abs_ty) |
353
9a0e8ab42ee8
fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
parents:
331
diff
changeset
|
155 |
val lthy3 = quotdata_update qty_str |
9a0e8ab42ee8
fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
parents:
331
diff
changeset
|
156 |
(Logic.varifyT abs_ty, Logic.varifyT rty, rel, equiv_thm) lthy2 |
313 | 157 |
(* FIXME: varifyT should not be used *) |
353
9a0e8ab42ee8
fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
parents:
331
diff
changeset
|
158 |
(* FIXME: the relation needs to be a string, since its type needs *) |
9a0e8ab42ee8
fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
parents:
331
diff
changeset
|
159 |
(* FIXME: to recalculated in for example REGULARIZE *) |
9a0e8ab42ee8
fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
parents:
331
diff
changeset
|
160 |
|
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
161 |
(* storing of the equiv_thm under a name *) |
582
a082e2d138ab
added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents:
529
diff
changeset
|
162 |
val (_, lthy4) = note (Binding.suffix_name "_equivp" qty_name, equiv_thm, |
a082e2d138ab
added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents:
529
diff
changeset
|
163 |
[internal_attr equiv_rules_add]) lthy3 |
182
c7eff9882bd8
added data-storage about the quotients
Christian Urban <urbanc@in.tum.de>
parents:
170
diff
changeset
|
164 |
|
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
165 |
(* interpretation *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
166 |
val bindd = ((Binding.make ("", Position.none)), ([]: Attrib.src list)) |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
167 |
val ((_, [eqn1pre]), lthy5) = Variable.import true [ABS_def] lthy4; |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
168 |
val eqn1i = Thm.prop_of (symmetric eqn1pre) |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
169 |
val ((_, [eqn2pre]), lthy6) = Variable.import true [REP_def] lthy5; |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
170 |
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
|
171 |
|
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
172 |
val exp_morphism = ProofContext.export_morphism lthy6 (ProofContext.init (ProofContext.theory_of lthy6)); |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
173 |
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
|
174 |
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
|
175 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
176 |
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
|
177 |
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
|
178 |
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
|
179 |
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
|
180 |
val exp_i = [(@{const_name QUOT_TYPE}, ((("QUOT_TYPE_I_" ^ (Binding.name_of qty_name)), true), |
170 | 181 |
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
|
182 |
in |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
183 |
lthy6 |
503
d2c9a72e52e0
first version of internalised quotient theorems; added FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
447
diff
changeset
|
184 |
|> note (quot_thm_name, quot_thm, []) |
582
a082e2d138ab
added a theorem list for equivalence theorems
Christian Urban <urbanc@in.tum.de>
parents:
529
diff
changeset
|
185 |
||>> note (quotient_thm_name, quotient_thm, [internal_attr quotient_rules_add]) |
319 | 186 |
||> Local_Theory.theory (fn thy => |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
187 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
188 |
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
|
189 |
(* Not sure if the following context should not be used *) |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
190 |
val (global_eqns2, lthy7) = Variable.import_terms true global_eqns lthy6; |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
191 |
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
|
192 |
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
|
193 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
194 |
|
130
8e8ba210f0f7
moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents:
128
diff
changeset
|
195 |
|
8e8ba210f0f7
moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents:
128
diff
changeset
|
196 |
|
8e8ba210f0f7
moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents:
128
diff
changeset
|
197 |
|
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 |
(* interface and syntax setup *) |
75
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
199 |
|
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 |
(* 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
|
201 |
(* *) |
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
|
202 |
(* - 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
|
203 |
(* - 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
|
204 |
(* - 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
|
205 |
(* - 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
|
206 |
|
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
264
diff
changeset
|
207 |
fun 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
|
208 |
let |
185
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
209 |
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
|
210 |
let |
529 | 211 |
val equivp_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
|
212 |
in |
529 | 213 |
HOLogic.mk_Trueprop (Const (@{const_name equivp}, equivp_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
|
214 |
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
|
215 |
|
185
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
216 |
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
|
217 |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
218 |
fun after_qed thms lthy = |
203
7384115df9fd
added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
219 |
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
|
220 |
in |
203
7384115df9fd
added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
221 |
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
|
222 |
end |
205 | 223 |
|
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
264
diff
changeset
|
224 |
fun quotient_type_cmd spec lthy = |
205 | 225 |
let |
226 |
fun parse_spec (((qty_str, mx), rty_str), rel_str) = |
|
227 |
let |
|
228 |
val qty_name = Binding.name qty_str |
|
293
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
229 |
val rty = Syntax.read_typ lthy rty_str |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
230 |
val rel = Syntax.read_term lthy rel_str |
205 | 231 |
in |
232 |
((qty_name, mx), (rty, rel)) |
|
233 |
end |
|
234 |
in |
|
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
264
diff
changeset
|
235 |
quotient_type (map parse_spec spec) lthy |
205 | 236 |
end |
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
237 |
|
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
|
238 |
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
|
239 |
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
|
240 |
(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
|
241 |
(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
|
242 |
(OuterParse.$$$ "/" |-- OuterParse.term)) |
75
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
243 |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
244 |
val _ = OuterKeyword.keyword "/" |
75
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
245 |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
246 |
val _ = |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
247 |
OuterSyntax.local_theory_to_proof "quotient" |
82 | 248 |
"quotient type definitions (requires equivalence proofs)" |
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
264
diff
changeset
|
249 |
OuterKeyword.thy_goal (quotspec_parser >> 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
|
250 |
|
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
251 |
end; (* structure *) |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
252 |
|
314 | 253 |
open Quotient |