author | Cezary Kaliszyk <kaliszyk@in.tum.de> |
Sat, 17 Oct 2009 12:31:48 +0200 | |
changeset 122 | 768c5d319a0a |
parent 82 | c3d27aada589 |
child 127 | b054cf6bd179 |
permissions | -rw-r--r-- |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
1 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
2 |
structure Quotient = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
3 |
struct |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
4 |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
5 |
(* 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
|
6 |
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
|
7 |
let |
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
8 |
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
|
9 |
|> Variable.variant_frees lthy [rel] |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
10 |
|> map Free |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
11 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
12 |
lambda c |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
13 |
(HOLogic.exists_const rty $ |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
14 |
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
|
15 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
16 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
17 |
(* 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
|
18 |
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
|
19 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
20 |
val typedef_tac = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
21 |
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
|
22 |
rtac @{thm exI}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
23 |
rtac @{thm exI}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
24 |
rtac @{thm refl}] |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
25 |
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
|
26 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
27 |
LocalTheory.theory_result |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
28 |
(Typedef.add_typedef false NONE |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
29 |
(qty_name, tfrees, mx) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
30 |
(typedef_term rel rty lthy) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
31 |
NONE typedef_tac) lthy |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
32 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
33 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
34 |
(* 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
|
35 |
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
|
36 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
37 |
val unfold_mem = MetaSimplifier.rewrite_rule @{thms mem_def} |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
38 |
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
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
43 |
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
|
44 |
rtac equiv_thm, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
45 |
rtac rep_thm, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
46 |
rtac rep_inv, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
47 |
rtac abs_inv, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
48 |
rtac @{thm exI}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
49 |
rtac @{thm refl}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
50 |
rtac rep_inj] |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
51 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
52 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
53 |
(* proves the QUOT_TYPE theorem *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
54 |
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
|
55 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
56 |
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
|
57 |
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
|
58 |
|> Syntax.check_term lthy |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
59 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
60 |
Goal.prove lthy [] [] goal |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
61 |
(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
|
62 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
63 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
64 |
(* proves the quotient theorem *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
65 |
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
|
66 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
67 |
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
|
68 |
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
|
69 |
|> Syntax.check_term lthy |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
70 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
71 |
val typedef_quotient_thm_tac = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
72 |
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
|
73 |
rtac @{thm QUOT_TYPE.QUOTIENT}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
74 |
rtac quot_type_thm] |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
75 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
76 |
Goal.prove lthy [] [] goal |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
77 |
(K typedef_quotient_thm_tac) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
78 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
79 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
80 |
(* two wrappers for define and note *) |
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
81 |
fun define (name, mx, rhs) lthy = |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
82 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
83 |
val ((rhs, (_ , thm)), lthy') = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
84 |
LocalTheory.define Thm.internalK ((name, mx), (Attrib.empty_binding, rhs)) lthy |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
85 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
86 |
((rhs, thm), lthy') |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
87 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
88 |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
89 |
fun note (name, thm) lthy = |
71
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 ((_,[thm']), lthy') = LocalTheory.note Thm.theoremK ((name, []), [thm]) lthy |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
92 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
93 |
(thm', lthy') |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
94 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
95 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
96 |
(* main function for constructing the quotient type *) |
80 | 97 |
fun mk_typedef_main (qty_name, mx, rel, rty, equiv_thm) lthy = |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
98 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
99 |
(* generates typedef *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
100 |
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
|
101 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
102 |
(* abs and rep functions *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
103 |
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
|
104 |
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
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
110 |
(* ABS and REP definitions *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
111 |
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
|
112 |
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
|
113 |
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
|
114 |
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
|
115 |
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
|
116 |
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
|
117 |
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
|
118 |
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
|
119 |
||>> 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
|
120 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
121 |
(* quot_type theorem *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
122 |
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
|
123 |
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
|
124 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
125 |
(* quotient theorem *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
126 |
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
|
127 |
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
|
128 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
129 |
(* interpretation *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
130 |
val bindd = ((Binding.make ("", Position.none)), ([]: Attrib.src list)) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
131 |
val ((_, [eqn1pre]), lthy3) = Variable.import true [ABS_def] lthy2; |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
132 |
val eqn1i = Thm.prop_of (symmetric eqn1pre) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
133 |
val ((_, [eqn2pre]), lthy4) = Variable.import true [REP_def] lthy3; |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
134 |
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
|
135 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
136 |
val exp_morphism = ProofContext.export_morphism lthy4 (ProofContext.init (ProofContext.theory_of lthy4)); |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
137 |
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
|
138 |
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
|
139 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
140 |
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
|
141 |
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
|
142 |
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
|
143 |
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
|
144 |
val exp_i = [(@{const_name QUOT_TYPE}, ((("QUOT_TYPE_I_" ^ (Binding.name_of qty_name)), true), |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
145 |
Expression.Named [ |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
146 |
("R", rel), |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
147 |
("Abs", abs), |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
148 |
("Rep", rep) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
149 |
]))] |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
150 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
151 |
lthy4 |
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
152 |
|> 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
|
153 |
||>> 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
|
154 |
||> LocalTheory.theory (fn thy => |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
155 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
156 |
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
|
157 |
(* Not sure if the following context should not be used *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
158 |
val (global_eqns2, lthy5) = Variable.import_terms true global_eqns lthy4; |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
159 |
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
|
160 |
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
|
161 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
162 |
|
75
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
163 |
(* syntax setup *) |
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
164 |
local structure P = OuterParse in |
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
165 |
|
81
c8d58e2cda58
slightly modified the parser
Christian Urban <urbanc@in.tum.de>
parents:
80
diff
changeset
|
166 |
fun mk_typedef (qty_name, mx, rty, rel_trm) lthy = |
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
167 |
let |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
168 |
val EQUIV_ty = ([rty, rty] ---> @{typ bool}) --> @{typ bool} |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
169 |
val EQUIV_goal = HOLogic.mk_Trueprop (Const (@{const_name EQUIV}, EQUIV_ty) $ rel_trm) |
80 | 170 |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
171 |
fun after_qed thms lthy = |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
172 |
let |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
173 |
val thm = the_single (flat thms) |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
174 |
in |
80 | 175 |
mk_typedef_main (Binding.name qty_name, mx, rel_trm, rty, thm) 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
|
176 |
end |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
177 |
in |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
178 |
Proof.theorem_i NONE after_qed [[(EQUIV_goal, [])]] lthy |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
179 |
end |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
180 |
|
82 | 181 |
(* FIXME: allow more than one type definition *) |
75
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
182 |
val quottype_parser = |
81
c8d58e2cda58
slightly modified the parser
Christian Urban <urbanc@in.tum.de>
parents:
80
diff
changeset
|
183 |
P.short_ident -- P.opt_infix -- |
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
184 |
(P.$$$ "=" |-- P.typ) -- |
75
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
185 |
(P.$$$ "/" |-- P.term) |
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
186 |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
187 |
fun mk_typedef_cmd (((qstr, mx), rstr), rel_str) lthy = |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
188 |
let |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
189 |
val rty = Syntax.parse_typ lthy rstr |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
190 |
val rel_trm = Syntax.parse_term lthy rel_str |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
191 |
|> Syntax.check_term lthy |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
192 |
in |
81
c8d58e2cda58
slightly modified the parser
Christian Urban <urbanc@in.tum.de>
parents:
80
diff
changeset
|
193 |
mk_typedef (qstr, mx, rty, rel_trm) 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 |
end |
75
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
195 |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
196 |
val _ = OuterKeyword.keyword "/" |
75
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
197 |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
198 |
val _ = |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
199 |
OuterSyntax.local_theory_to_proof "quotient" |
82 | 200 |
"quotient type definitions (requires equivalence proofs)" |
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
201 |
OuterKeyword.thy_goal (quottype_parser >> mk_typedef_cmd) |
75
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
202 |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
203 |
end; (* local *) |
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
204 |
|
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
205 |
end; (* structure *) |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
206 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
207 |
open Quotient |