author | wenzelm |
Thu, 29 Nov 2001 01:51:06 +0100 | |
changeset 12325 | 4966dae8fa62 |
parent 12145 | c38a7efa3afb |
child 12350 | 5fad0e7129c3 |
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 |
8807 | 4 |
License: GPL (GNU GENERAL PUBLIC LICENSE) |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
5 |
|
8543 | 6 |
The 'obtain' language element -- generalized existence at the level of |
7 |
proof texts. |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
8 |
|
9468 | 9 |
<chain_facts> |
10 |
obtain x where "P x" <proof> == |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
11 |
|
9468 | 12 |
{ |
13 |
fix thesis |
|
11021 | 14 |
assume that [intro]: "!!x. P x ==> thesis" |
10379
93630e0c5ae9
improved handling of "that": insert into goal, only declare as Pure "intro";
wenzelm
parents:
9481
diff
changeset
|
15 |
<chain_facts> have thesis <proof (insert that)> |
9468 | 16 |
} |
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" |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
18 |
|
8094 | 19 |
*) |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
20 |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
21 |
signature OBTAIN = |
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
22 |
sig |
11890 | 23 |
val obtain: (string list * string option) list -> |
24 |
((string * Proof.context attribute list) * (string * (string list * string list)) list) list |
|
25 |
-> Proof.state -> Proof.state Seq.seq |
|
26 |
val obtain_i: (string list * typ option) list -> |
|
27 |
((string * Proof.context attribute list) * (term * (term list * term list)) list) list |
|
28 |
-> Proof.state -> Proof.state Seq.seq |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
29 |
end; |
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
30 |
|
10379
93630e0c5ae9
improved handling of "that": insert into goal, only declare as Pure "intro";
wenzelm
parents:
9481
diff
changeset
|
31 |
structure Obtain: OBTAIN = |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
32 |
struct |
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
33 |
|
8094 | 34 |
|
11816 | 35 |
(** export_obtain **) |
9468 | 36 |
|
11816 | 37 |
fun export_obtain state parms rule _ cprops thm = |
9468 | 38 |
let |
39 |
val {sign, prop, maxidx, ...} = Thm.rep_thm thm; |
|
40 |
val cparms = map (Thm.cterm_of sign) parms; |
|
41 |
||
42 |
val thm' = thm |
|
11816 | 43 |
|> Drule.implies_intr_goals cprops |
9468 | 44 |
|> Drule.forall_intr_list cparms |
45 |
|> Drule.forall_elim_vars (maxidx + 1); |
|
11816 | 46 |
val elim_tacs = replicate (length cprops) (Tactic.etac Drule.triv_goal); |
9468 | 47 |
|
48 |
val concl = Logic.strip_assums_concl prop; |
|
49 |
val bads = parms inter (Term.term_frees concl); |
|
50 |
in |
|
51 |
if not (null bads) then |
|
9481 | 52 |
raise Proof.STATE ("Conclusion contains obtained parameters: " ^ |
12055 | 53 |
space_implode " " (map (ProofContext.string_of_term (Proof.context_of state)) bads), state) |
11764 | 54 |
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
|
55 |
raise Proof.STATE ("Conclusions of 'obtain' context must be object-logic judgments", state) |
9468 | 56 |
else (Tactic.rtac thm' THEN' RANGE elim_tacs) 1 rule |
57 |
end; |
|
58 |
||
59 |
||
60 |
||
8094 | 61 |
(** obtain(_i) **) |
62 |
||
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
63 |
val thatN = "that"; |
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
64 |
|
11890 | 65 |
fun gen_obtain prep_vars prep_propp raw_vars raw_asms state = |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
66 |
let |
9468 | 67 |
val _ = Proof.assert_forward_or_chain state; |
68 |
val chain_facts = if Proof.is_chain state then Proof.the_facts state else []; |
|
10464 | 69 |
val thy = Proof.theory_of state; |
11764 | 70 |
val sign = Theory.sign_of thy; |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
71 |
|
8543 | 72 |
(*obtain vars*) |
11890 | 73 |
val (vars_ctxt, vars) = foldl_map prep_vars (Proof.context_of state, raw_vars); |
8094 | 74 |
val xs = flat (map fst vars); |
10582 | 75 |
val fix_ctxt = vars_ctxt |> ProofContext.fix_i vars; |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
76 |
|
8543 | 77 |
(*obtain asms*) |
11890 | 78 |
val (asms_ctxt, proppss) = prep_propp (fix_ctxt, map snd raw_asms); |
10464 | 79 |
val asm_props = flat (map (map fst) proppss); |
11890 | 80 |
val asms = map fst raw_asms ~~ proppss; |
10464 | 81 |
|
10582 | 82 |
val _ = ProofContext.warn_extra_tfrees fix_ctxt asms_ctxt; |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
83 |
|
8094 | 84 |
(*that_prop*) |
10582 | 85 |
val thesisN = Term.variant xs AutoBind.thesisN; |
86 |
val bound_thesis = |
|
11764 | 87 |
ProofContext.bind_skolem fix_ctxt [thesisN] (ObjectLogic.fixed_judgment sign thesisN); |
9468 | 88 |
|
10582 | 89 |
fun occs_var x = Library.get_first (fn t => |
90 |
ProofContext.find_free t (ProofContext.get_skolem fix_ctxt x)) asm_props; |
|
91 |
val raw_parms = map occs_var xs; |
|
92 |
val parms = mapfilter I raw_parms; |
|
93 |
val parm_names = |
|
94 |
mapfilter (fn (Some (Free a), x) => Some (a, x) | _ => None) (raw_parms ~~ xs); |
|
95 |
||
96 |
val that_prop = |
|
97 |
Term.list_all_free (map #1 parm_names, Logic.list_implies (asm_props, bound_thesis)) |
|
98 |
|> Library.curry Logic.list_rename_params (map #2 parm_names); |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
99 |
|
9468 | 100 |
fun after_qed st = st |
101 |
|> Proof.end_block |
|
102 |
|> Seq.map (fn st' => st' |
|
103 |
|> Proof.fix_i vars |
|
11816 | 104 |
|> 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
|
105 |
in |
8094 | 106 |
state |
9468 | 107 |
|> Proof.enter_forward |
108 |
|> Proof.begin_block |
|
109 |
|> Proof.fix_i [([thesisN], None)] |
|
12325 | 110 |
|> Proof.assume_i [((thatN, [RuleContext.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
|
111 |
|> (fn state' => |
93630e0c5ae9
improved handling of "that": insert into goal, only declare as Pure "intro";
wenzelm
parents:
9481
diff
changeset
|
112 |
state' |
93630e0c5ae9
improved handling of "that": insert into goal, only declare as Pure "intro";
wenzelm
parents:
9481
diff
changeset
|
113 |
|> Proof.from_facts chain_facts |
12145 | 114 |
|> Proof.have_i after_qed [(("", []), [(bound_thesis, ([], []))])] |
10379
93630e0c5ae9
improved handling of "that": insert into goal, only declare as Pure "intro";
wenzelm
parents:
9481
diff
changeset
|
115 |
|> Method.refine (Method.Basic (K (Method.insert (Proof.the_facts state'))))) |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
116 |
end; |
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
117 |
|
11890 | 118 |
val obtain = gen_obtain ProofContext.read_vars ProofContext.read_propp; |
119 |
val obtain_i = gen_obtain ProofContext.cert_vars ProofContext.cert_propp; |
|
8094 | 120 |
|
121 |
||
122 |
end; |