45 val rhs_tfrees = Term.add_tfrees set []; |
45 val rhs_tfrees = Term.add_tfrees set []; |
46 val oldT = HOLogic.dest_setT setT handle TYPE _ => |
46 val oldT = HOLogic.dest_setT setT handle TYPE _ => |
47 error ("Not a set type: " ^ quote (Syntax.string_of_typ ctxt setT)); |
47 error ("Not a set type: " ^ quote (Syntax.string_of_typ ctxt setT)); |
48 |
48 |
49 (*goal*) |
49 (*goal*) |
50 val goal_UU_mem = HOLogic.mk_mem (Const (@{const_name UU}, oldT), set); |
50 val goal_UU_mem = HOLogic.mk_Trueprop (HOLogic.mk_mem (Const (@{const_name UU}, oldT), set)); |
51 val goal_nonempty = HOLogic.mk_exists ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), set)); |
51 val goal_nonempty = |
52 val goal_admissible = mk_adm ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), set)); |
52 HOLogic.mk_Trueprop (HOLogic.mk_exists ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), set))); |
53 val goal = HOLogic.mk_Trueprop |
53 val goal_admissible = |
54 (HOLogic.mk_conj (if pcpo then goal_UU_mem else goal_nonempty, goal_admissible)); |
54 HOLogic.mk_Trueprop (mk_adm ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), set))); |
55 |
55 |
56 (*lhs*) |
56 (*lhs*) |
57 val defS = Sign.defaultS thy; |
57 val defS = Sign.defaultS thy; |
58 val lhs_tfrees = map (fn v => (v, the_default defS (AList.lookup (op =) rhs_tfrees v))) vs; |
58 val lhs_tfrees = map (fn v => (v, the_default defS (AList.lookup (op =) rhs_tfrees v))) vs; |
59 val lhs_sorts = map snd lhs_tfrees; |
59 val lhs_sorts = map snd lhs_tfrees; |
105 (("compact_" ^ name, @{thm typedef_compact} OF cpo_thms'), [])]) |
105 (("compact_" ^ name, @{thm typedef_compact} OF cpo_thms'), [])]) |
106 |> snd |
106 |> snd |
107 |> Sign.parent_path |
107 |> Sign.parent_path |
108 end; |
108 end; |
109 |
109 |
110 fun make_pcpo UUmem (type_def, less_def, set_def) theory = |
110 fun make_pcpo UU_mem (type_def, less_def, set_def) theory = |
111 let |
111 let |
112 val UUmem' = fold_rule (the_list set_def) UUmem; |
112 val UU_mem' = fold_rule (the_list set_def) UU_mem; |
113 val pcpo_thms = map (Thm.transfer theory) [type_def, less_def, UUmem']; |
113 val pcpo_thms = map (Thm.transfer theory) [type_def, less_def, UU_mem']; |
114 val theory' = theory |
114 val theory' = theory |
115 |> AxClass.prove_arity (full_tname, lhs_sorts, @{sort pcpo}) |
115 |> AxClass.prove_arity (full_tname, lhs_sorts, @{sort pcpo}) |
116 (Tactic.rtac (@{thm typedef_pcpo} OF pcpo_thms) 1); |
116 (Tactic.rtac (@{thm typedef_pcpo} OF pcpo_thms) 1); |
117 val pcpo_thms' = map (Thm.transfer theory') pcpo_thms; |
117 val pcpo_thms' = map (Thm.transfer theory') pcpo_thms; |
118 in |
118 in |
128 ]) |
128 ]) |
129 |> snd |
129 |> snd |
130 |> Sign.parent_path |
130 |> Sign.parent_path |
131 end; |
131 end; |
132 |
132 |
133 fun pcpodef_result UUmem_admissible theory = |
133 fun pcpodef_result UU_mem admissible = |
134 let |
134 make_po (Tactic.rtac exI 1 THEN Tactic.rtac UU_mem 1) |
135 val UUmem = UUmem_admissible RS conjunct1; |
135 #-> (fn defs => make_cpo admissible defs #> make_pcpo UU_mem defs); |
136 val admissible = UUmem_admissible RS conjunct2; |
|
137 in |
|
138 theory |
|
139 |> make_po (Tactic.rtac exI 1 THEN Tactic.rtac UUmem 1) |
|
140 |-> (fn defs => make_cpo admissible defs #> make_pcpo UUmem defs) |
|
141 end; |
|
142 |
136 |
143 fun cpodef_result nonempty_admissible theory = |
137 fun cpodef_result nonempty admissible = |
144 let |
138 make_po (Tactic.rtac nonempty 1) |
145 val nonempty = nonempty_admissible RS conjunct1; |
139 #-> make_cpo admissible; |
146 val admissible = nonempty_admissible RS conjunct2; |
140 in |
147 in |
141 if pcpo |
148 theory |
142 then (goal_UU_mem, goal_admissible, pcpodef_result) |
149 |> make_po (Tactic.rtac nonempty 1) |
143 else (goal_nonempty, goal_admissible, cpodef_result) |
150 |-> make_cpo admissible |
144 end |
151 end; |
|
152 |
|
153 in (goal, if pcpo then pcpodef_result else cpodef_result) end |
|
154 handle ERROR msg => err_in_cpodef msg name; |
145 handle ERROR msg => err_in_cpodef msg name; |
155 |
146 |
156 |
147 |
157 (* proof interface *) |
148 (* proof interface *) |
158 |
149 |
159 local |
150 local |
160 |
151 |
161 fun gen_pcpodef_proof prep_term pcpo ((def, name), typ, set, opt_morphs) thy = |
152 fun gen_pcpodef_proof prep_term pcpo ((def, name), typ, set, opt_morphs) thy = |
162 let |
153 let |
163 val (goal, pcpodef_result) = |
154 val (goal1, goal2, make_result) = |
164 prepare_pcpodef prep_term pcpo def name typ set opt_morphs thy; |
155 prepare_pcpodef prep_term pcpo def name typ set opt_morphs thy; |
165 fun after_qed [[th]] = ProofContext.theory (pcpodef_result th); |
156 fun after_qed [[th1, th2]] = ProofContext.theory (make_result th1 th2); |
166 in Proof.theorem_i NONE after_qed [[(goal, [])]] (ProofContext.init thy) end; |
157 in Proof.theorem_i NONE after_qed [[(goal1, []), (goal2, [])]] (ProofContext.init thy) end; |
167 |
158 |
168 in |
159 in |
169 |
160 |
170 fun pcpodef_proof x = gen_pcpodef_proof Syntax.check_term true x; |
161 fun pcpodef_proof x = gen_pcpodef_proof Syntax.check_term true x; |
171 fun pcpodef_proof_cmd x = gen_pcpodef_proof Syntax.read_term true x; |
162 fun pcpodef_proof_cmd x = gen_pcpodef_proof Syntax.read_term true x; |