author | Christian Urban <urbanc@in.tum.de> |
Mon, 12 Oct 2009 14:30:50 +0200 | |
changeset 75 | 5fe163543bb8 |
parent 71 | 35be65791f1d |
child 79 | c0c41fefeb06 |
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 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
3 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
4 |
structure Quotient = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
5 |
struct |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
6 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
7 |
(* constructs the term lambda (c::rty => bool). EX x. c= rel x *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
8 |
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
|
9 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
10 |
val [x, c] = [("x", rty), ("c", rty --> @{typ bool})] |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
11 |
|> Variable.variant_frees lthy [rel] |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
12 |
|> map Free |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
13 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
14 |
lambda c |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
15 |
(HOLogic.exists_const rty $ |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
16 |
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
|
17 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
18 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
19 |
(* 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
|
20 |
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
|
21 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
22 |
val typedef_tac = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
23 |
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
|
24 |
rtac @{thm exI}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
25 |
rtac @{thm exI}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
26 |
rtac @{thm refl}] |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
27 |
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
|
28 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
29 |
LocalTheory.theory_result |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
30 |
(Typedef.add_typedef false NONE |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
31 |
(qty_name, tfrees, mx) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
32 |
(typedef_term rel rty lthy) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
33 |
NONE typedef_tac) lthy |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
34 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
35 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
36 |
(* 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
|
37 |
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
|
38 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
45 |
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
|
46 |
rtac equiv_thm, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
47 |
rtac rep_thm, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
48 |
rtac rep_inv, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
49 |
rtac abs_inv, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
50 |
rtac @{thm exI}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
51 |
rtac @{thm refl}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
52 |
rtac rep_inj] |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
53 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
54 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
55 |
(* proves the QUOT_TYPE theorem *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
56 |
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
|
57 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
58 |
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
|
59 |
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
|
60 |
|> Syntax.check_term lthy |
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 |
Goal.prove lthy [] [] goal |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
63 |
(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
|
64 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
65 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
66 |
(* proves the quotient theorem *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
67 |
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
|
68 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
|> Syntax.check_term lthy |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
72 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
73 |
val typedef_quotient_thm_tac = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
74 |
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
|
75 |
rtac @{thm QUOT_TYPE.QUOTIENT}, |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
76 |
rtac quot_type_thm] |
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 |
Goal.prove lthy [] [] goal |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
79 |
(K typedef_quotient_thm_tac) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
80 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
81 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
82 |
(* two wrappers for define and note *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
83 |
fun make_def (name, mx, rhs) lthy = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
84 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
85 |
val ((rhs, (_ , thm)), lthy') = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
86 |
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
|
87 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
88 |
((rhs, thm), lthy') |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
89 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
90 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
91 |
fun note_thm (name, thm) lthy = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
92 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
93 |
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
|
94 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
95 |
(thm', lthy') |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
96 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
97 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
98 |
(* main function for constructing the quotient type *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
99 |
fun typedef_main (qty_name, mx, rel, rty, equiv_thm) lthy = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
100 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
101 |
(* generates typedef *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
102 |
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
|
103 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
104 |
(* abs and rep functions *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
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
|
111 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
112 |
(* ABS and REP definitions *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
113 |
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
|
114 |
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
|
115 |
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
|
116 |
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
|
117 |
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
|
118 |
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
|
119 |
val (((ABS, ABS_def), (REP, REP_def)), lthy2) = |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
120 |
lthy1 |> make_def (ABS_name, NoSyn, ABS_trm) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
121 |
||>> make_def (REP_name, NoSyn, REP_trm) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
122 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
123 |
(* quot_type theorem *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
124 |
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
|
125 |
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
|
126 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
127 |
(* quotient theorem *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
128 |
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
|
129 |
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
|
130 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
131 |
(* interpretation *) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
132 |
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
|
133 |
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
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
138 |
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
|
139 |
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
|
140 |
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
|
141 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
142 |
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
|
143 |
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
|
144 |
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
|
145 |
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
|
146 |
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
|
147 |
Expression.Named [ |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
148 |
("R", rel), |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
149 |
("Abs", abs), |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
150 |
("Rep", rep) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
151 |
]))] |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
152 |
in |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
153 |
lthy4 |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
154 |
|> note_thm (quot_thm_name, quot_thm) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
155 |
||>> note_thm (quotient_thm_name, quotient_thm) |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
156 |
||> LocalTheory.theory (fn thy => |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
157 |
let |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
158 |
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
|
159 |
(* 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
|
160 |
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
|
161 |
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
|
162 |
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
|
163 |
end |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
164 |
|
75
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
165 |
(* syntax setup *) |
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
166 |
local structure P = OuterParse in |
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
167 |
|
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
168 |
val quottype_parser = |
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
169 |
(P.type_args -- P.binding) -- |
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
170 |
P.opt_infix -- |
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
171 |
(P.$$$ "=" |-- P.term) -- |
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
172 |
(P.$$$ "/" |-- P.term) |
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
173 |
|
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
174 |
(* |
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
175 |
val _ = |
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
176 |
OuterSyntax.command "quotient" "quotient type definition (requires equivalence proof)" |
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
177 |
OuterKeyword.thy_goal |
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
178 |
(typedef_decl >> (Toplevel.print oo (Toplevel.theory_to_proof o mk_typedef))); |
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
179 |
|
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
180 |
end; |
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
181 |
*) |
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
182 |
|
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
183 |
end; |
5fe163543bb8
started some strange functions
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
184 |
|
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
185 |
end; |
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
186 |
|
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
187 |
open Quotient |