author | skalberg |
Sun, 13 Feb 2005 17:15:14 +0100 | |
changeset 15531 | 08c8dad8e399 |
parent 14981 | e73f8140af78 |
child 15570 | 8d8c70b41bab |
permissions | -rw-r--r-- |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
1 |
(* Title: Pure/Isar/obtain.ML |
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
2 |
ID: $Id$ |
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
3 |
Author: Markus Wenzel, TU Muenchen |
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
4 |
|
8543 | 5 |
The 'obtain' language element -- generalized existence at the level of |
6 |
proof texts. |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
7 |
|
9468 | 8 |
<chain_facts> |
9 |
obtain x where "P x" <proof> == |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
10 |
|
12970 | 11 |
have "!!thesis. (!!x. P x ==> thesis) ==> thesis" |
12 |
proof succeed |
|
9468 | 13 |
fix thesis |
12970 | 14 |
assume that [intro?]: "!!x. P x ==> thesis" |
15 |
<chain_facts> show thesis <proof (insert that)> |
|
16 |
qed |
|
10379
93630e0c5ae9
improved handling of "that": insert into goal, only declare as Pure "intro";
wenzelm
parents:
9481
diff
changeset
|
17 |
fix x assm (obtained) "P x" |
8094 | 18 |
*) |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
19 |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
20 |
signature OBTAIN = |
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
21 |
sig |
11890 | 22 |
val obtain: (string list * string option) list -> |
23 |
((string * Proof.context attribute list) * (string * (string list * string list)) list) list |
|
12970 | 24 |
-> (Proof.context -> string * (string * thm list) list -> unit) * |
25 |
(Proof.context -> thm -> unit) -> Proof.state -> Proof.state Seq.seq |
|
11890 | 26 |
val obtain_i: (string list * typ option) list -> |
27 |
((string * Proof.context attribute list) * (term * (term list * term list)) list) list |
|
12970 | 28 |
-> (Proof.context -> string * (string * thm list) list -> unit) * |
29 |
(Proof.context -> thm -> unit) -> Proof.state -> Proof.state Seq.seq |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
30 |
end; |
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
31 |
|
10379
93630e0c5ae9
improved handling of "that": insert into goal, only declare as Pure "intro";
wenzelm
parents:
9481
diff
changeset
|
32 |
structure Obtain: OBTAIN = |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
33 |
struct |
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
34 |
|
8094 | 35 |
|
11816 | 36 |
(** export_obtain **) |
9468 | 37 |
|
11816 | 38 |
fun export_obtain state parms rule _ cprops thm = |
9468 | 39 |
let |
40 |
val {sign, prop, maxidx, ...} = Thm.rep_thm thm; |
|
41 |
val cparms = map (Thm.cterm_of sign) parms; |
|
42 |
||
43 |
val thm' = thm |
|
11816 | 44 |
|> Drule.implies_intr_goals cprops |
9468 | 45 |
|> Drule.forall_intr_list cparms |
46 |
|> Drule.forall_elim_vars (maxidx + 1); |
|
11816 | 47 |
val elim_tacs = replicate (length cprops) (Tactic.etac Drule.triv_goal); |
9468 | 48 |
|
49 |
val concl = Logic.strip_assums_concl prop; |
|
50 |
val bads = parms inter (Term.term_frees concl); |
|
51 |
in |
|
52 |
if not (null bads) then |
|
9481 | 53 |
raise Proof.STATE ("Conclusion contains obtained parameters: " ^ |
12055 | 54 |
space_implode " " (map (ProofContext.string_of_term (Proof.context_of state)) bads), state) |
11764 | 55 |
else if not (ObjectLogic.is_judgment sign (Logic.strip_assums_concl prop)) then |
10379
93630e0c5ae9
improved handling of "that": insert into goal, only declare as Pure "intro";
wenzelm
parents:
9481
diff
changeset
|
56 |
raise Proof.STATE ("Conclusions of 'obtain' context must be object-logic judgments", state) |
9468 | 57 |
else (Tactic.rtac thm' THEN' RANGE elim_tacs) 1 rule |
58 |
end; |
|
59 |
||
60 |
||
61 |
||
8094 | 62 |
(** obtain(_i) **) |
63 |
||
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
64 |
val thatN = "that"; |
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
65 |
|
12970 | 66 |
fun gen_obtain prep_vars prep_propp raw_vars raw_asms print state = |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
67 |
let |
9468 | 68 |
val _ = Proof.assert_forward_or_chain state; |
69 |
val chain_facts = if Proof.is_chain state then Proof.the_facts state else []; |
|
10464 | 70 |
val thy = Proof.theory_of state; |
11764 | 71 |
val sign = Theory.sign_of thy; |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
72 |
|
8543 | 73 |
(*obtain vars*) |
11890 | 74 |
val (vars_ctxt, vars) = foldl_map prep_vars (Proof.context_of state, raw_vars); |
8094 | 75 |
val xs = flat (map fst vars); |
10582 | 76 |
val fix_ctxt = vars_ctxt |> ProofContext.fix_i vars; |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
77 |
|
8543 | 78 |
(*obtain asms*) |
11890 | 79 |
val (asms_ctxt, proppss) = prep_propp (fix_ctxt, map snd raw_asms); |
10464 | 80 |
val asm_props = flat (map (map fst) proppss); |
11890 | 81 |
val asms = map fst raw_asms ~~ proppss; |
10464 | 82 |
|
10582 | 83 |
val _ = ProofContext.warn_extra_tfrees fix_ctxt asms_ctxt; |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
84 |
|
12970 | 85 |
(*obtain statements*) |
12404 | 86 |
val thesisN = Term.variant xs (Syntax.internal AutoBind.thesisN); |
12970 | 87 |
val bind_thesis = ProofContext.bind_skolem fix_ctxt [thesisN]; |
88 |
val bound_thesis = bind_thesis (ObjectLogic.fixed_judgment sign thesisN); |
|
89 |
val bound_thesis_raw as (bound_thesis_name, _) = |
|
90 |
Term.dest_Free (bind_thesis (Free (thesisN, propT))); |
|
91 |
val bound_thesis_var = |
|
92 |
foldl_aterms (fn (v, Free (x, T)) => if x = bound_thesis_name then (x, T) else v |
|
93 |
| (v, t) => v) (bound_thesis_raw, bound_thesis); |
|
9468 | 94 |
|
10582 | 95 |
fun occs_var x = Library.get_first (fn t => |
96 |
ProofContext.find_free t (ProofContext.get_skolem fix_ctxt x)) asm_props; |
|
97 |
val raw_parms = map occs_var xs; |
|
98 |
val parms = mapfilter I raw_parms; |
|
99 |
val parm_names = |
|
15531 | 100 |
mapfilter (fn (SOME (Free a), x) => SOME (a, x) | _ => NONE) (raw_parms ~~ xs); |
10582 | 101 |
|
102 |
val that_prop = |
|
103 |
Term.list_all_free (map #1 parm_names, Logic.list_implies (asm_props, bound_thesis)) |
|
104 |
|> Library.curry Logic.list_rename_params (map #2 parm_names); |
|
12970 | 105 |
val obtain_prop = |
106 |
Logic.list_rename_params ([AutoBind.thesisN], |
|
107 |
Term.list_all_free ([bound_thesis_var], Logic.mk_implies (that_prop, bound_thesis))); |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
108 |
|
9468 | 109 |
fun after_qed st = st |
15531 | 110 |
|> Method.local_qed false NONE print |
9468 | 111 |
|> Seq.map (fn st' => st' |
112 |
|> Proof.fix_i vars |
|
11816 | 113 |
|> Proof.assm_i (export_obtain state parms (Proof.the_fact st')) asms); |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
114 |
in |
8094 | 115 |
state |
9468 | 116 |
|> Proof.enter_forward |
12970 | 117 |
|> Proof.have_i Seq.single true [(("", []), [(obtain_prop, ([], []))])] |
15531 | 118 |
|> Method.proof (SOME (Method.Basic (K Method.succeed))) |> Seq.hd |
119 |
|> Proof.fix_i [([thesisN], NONE)] |
|
120 |
|> Proof.assume_i [((thatN, [ContextRules.intro_query_local NONE]), [(that_prop, ([], []))])] |
|
10379
93630e0c5ae9
improved handling of "that": insert into goal, only declare as Pure "intro";
wenzelm
parents:
9481
diff
changeset
|
121 |
|> (fn state' => |
12970 | 122 |
state' |
123 |
|> Proof.from_facts chain_facts |
|
124 |
|> Proof.show_i (K I) after_qed false [(("", []), [(bound_thesis, ([], []))])] false |
|
125 |
|> Method.refine (Method.Basic (K (Method.insert (Proof.the_facts state'))))) |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
126 |
end; |
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
127 |
|
11890 | 128 |
val obtain = gen_obtain ProofContext.read_vars ProofContext.read_propp; |
129 |
val obtain_i = gen_obtain ProofContext.cert_vars ProofContext.cert_propp; |
|
8094 | 130 |
|
131 |
end; |