author | wenzelm |
Wed, 02 Aug 2000 19:40:14 +0200 | |
changeset 9502 | 50ec59aff389 |
parent 9481 | b16624f1ea38 |
child 10379 | 93630e0c5ae9 |
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 |
|
14 |
assume that: "!!x. P x ==> thesis" |
|
15 |
<chain_facts> have thesis <proof> |
|
16 |
} |
|
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 |
|
8094 | 21 |
signature OBTAIN_DATA = |
22 |
sig |
|
9468 | 23 |
val atomic_thesis: string -> term |
8094 | 24 |
val that_atts: Proof.context attribute list |
25 |
end; |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
26 |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
27 |
signature OBTAIN = |
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
28 |
sig |
8094 | 29 |
val obtain: ((string list * string option) * Comment.text) list |
30 |
* ((string * Args.src list * (string * (string list * string list)) list) |
|
31 |
* Comment.text) list -> ProofHistory.T -> ProofHistory.T |
|
32 |
val obtain_i: ((string list * typ option) * Comment.text) list |
|
33 |
* ((string * Proof.context attribute list * (term * (term list * term list)) list) |
|
34 |
* Comment.text) list -> ProofHistory.T -> ProofHistory.T |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
35 |
end; |
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
36 |
|
8094 | 37 |
functor ObtainFun(Data: OBTAIN_DATA): OBTAIN = |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
38 |
struct |
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
39 |
|
8094 | 40 |
|
9481 | 41 |
(** disch_obtained **) |
9468 | 42 |
|
43 |
fun disch_obtained state parms rule cprops thm = |
|
44 |
let |
|
45 |
val {sign, prop, maxidx, ...} = Thm.rep_thm thm; |
|
46 |
val cparms = map (Thm.cterm_of sign) parms; |
|
47 |
||
48 |
val thm' = thm |
|
49 |
|> Drule.implies_intr_list cprops |
|
50 |
|> Drule.forall_intr_list cparms |
|
51 |
|> Drule.forall_elim_vars (maxidx + 1); |
|
52 |
val elim_tacs = replicate (length cprops) Proof.hard_asm_tac; |
|
53 |
||
54 |
val concl = Logic.strip_assums_concl prop; |
|
55 |
val bads = parms inter (Term.term_frees concl); |
|
56 |
in |
|
57 |
if not (null bads) then |
|
9481 | 58 |
raise Proof.STATE ("Conclusion contains obtained parameters: " ^ |
9468 | 59 |
space_implode " " (map (Sign.string_of_term sign) bads), state) |
60 |
else if not (AutoBind.is_judgment (Logic.strip_assums_concl prop)) then |
|
9481 | 61 |
raise Proof.STATE ("Conclusion is not an object-logic judgment", state) |
9468 | 62 |
else (Tactic.rtac thm' THEN' RANGE elim_tacs) 1 rule |
63 |
end; |
|
64 |
||
65 |
||
66 |
||
8094 | 67 |
(** obtain(_i) **) |
68 |
||
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
69 |
val thatN = "that"; |
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
70 |
|
8094 | 71 |
fun gen_obtain prep_vars prep_propp prep_att (raw_vars, raw_asms) state = |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
72 |
let |
9468 | 73 |
val _ = Proof.assert_forward_or_chain state; |
74 |
val chain_facts = if Proof.is_chain state then Proof.the_facts state else []; |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
75 |
|
8543 | 76 |
(*obtain vars*) |
8094 | 77 |
val (vars_ctxt, vars) = |
78 |
foldl_map prep_vars (Proof.context_of state, map Comment.ignore raw_vars); |
|
79 |
val xs = flat (map fst vars); |
|
9468 | 80 |
val thesisN = Term.variant xs AutoBind.thesisN; |
9293 | 81 |
|
9468 | 82 |
val bind_skolem = ProofContext.bind_skolem vars_ctxt (xs @ [thesisN]); |
9293 | 83 |
fun bind_propp (prop, (pats1, pats2)) = |
84 |
(bind_skolem prop, (map bind_skolem pats1, map bind_skolem pats2)); |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
85 |
|
8543 | 86 |
(*obtain asms*) |
8094 | 87 |
fun prep_asm (ctxt, (name, src, raw_propps)) = |
88 |
let |
|
89 |
val atts = map (prep_att (ProofContext.theory_of ctxt)) src; |
|
90 |
val (ctxt', propps) = foldl_map prep_propp (ctxt, raw_propps); |
|
9293 | 91 |
in (ctxt', ((name, atts, map bind_propp propps), map #1 propps)) end; |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
92 |
|
9293 | 93 |
val (asms_ctxt, asms_result) = foldl_map prep_asm (vars_ctxt, map Comment.ignore raw_asms); |
94 |
val (asms, asm_propss) = Library.split_list asms_result; |
|
95 |
val asm_props = flat asm_propss; |
|
8094 | 96 |
val _ = ProofContext.warn_extra_tfrees vars_ctxt asms_ctxt; |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
97 |
|
8094 | 98 |
(*that_prop*) |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
99 |
fun find_free x t = |
8614 | 100 |
(case ProofContext.find_free t x of Some (Free a) => Some a | _ => None); |
8094 | 101 |
fun occs_var x = Library.get_first (find_free x) asm_props; |
9468 | 102 |
val xs' = mapfilter occs_var xs; |
103 |
val parms = map (bind_skolem o Free) xs'; |
|
104 |
||
105 |
val bound_thesis = bind_skolem (Data.atomic_thesis thesisN); |
|
106 |
val that_prop = Term.list_all_free (xs', Logic.list_implies (asm_props, bound_thesis)); |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
107 |
|
9481 | 108 |
fun export_obtained rule = |
109 |
(disch_obtained state parms rule, fn _ => fn _ => []); |
|
110 |
||
9468 | 111 |
fun after_qed st = st |
112 |
|> Proof.end_block |
|
113 |
|> Seq.map (fn st' => st' |
|
114 |
|> Proof.fix_i vars |
|
9481 | 115 |
|> Proof.assm_i (export_obtained (Proof.the_fact st')) asms); |
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
116 |
in |
8094 | 117 |
state |
9468 | 118 |
|> Proof.enter_forward |
119 |
|> Proof.begin_block |
|
120 |
|> Proof.fix_i [([thesisN], None)] |
|
121 |
|> Proof.assume_i [(thatN, Data.that_atts, [(that_prop, ([], []))])] |
|
122 |
|> Proof.from_facts chain_facts |
|
123 |
|> Proof.have_i after_qed "" [] (bound_thesis, ([], [])) |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
124 |
end; |
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
125 |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
126 |
|
9468 | 127 |
val obtain = ProofHistory.apply o |
8094 | 128 |
(gen_obtain ProofContext.read_vars ProofContext.read_propp Attrib.local_attribute); |
129 |
||
9468 | 130 |
val obtain_i = ProofHistory.apply o |
8094 | 131 |
(gen_obtain ProofContext.cert_vars ProofContext.cert_propp (K I)); |
132 |
||
133 |
||
134 |
||
135 |
(** outer syntax **) |
|
136 |
||
137 |
local structure P = OuterParse and K = OuterSyntax.Keyword in |
|
138 |
||
139 |
val obtainP = |
|
8543 | 140 |
OuterSyntax.command "obtain" "generalized existence" |
8094 | 141 |
K.prf_asm_goal |
142 |
(Scan.optional |
|
143 |
(P.and_list1 (Scan.repeat1 P.name -- Scan.option (P.$$$ "::" |-- P.typ) -- P.marg_comment) |
|
8109 | 144 |
--| P.$$$ "where") [] -- |
8094 | 145 |
P.and_list1 ((P.opt_thm_name ":" -- Scan.repeat1 P.propp >> P.triple1) -- P.marg_comment) |
146 |
>> (Toplevel.print oo (Toplevel.proof o obtain))); |
|
147 |
||
8109 | 148 |
val _ = OuterSyntax.add_keywords ["where"]; |
8094 | 149 |
val _ = OuterSyntax.add_parsers [obtainP]; |
150 |
||
151 |
end; |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
152 |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
153 |
end; |