| author | wenzelm |
| Fri, 05 May 2000 22:09:41 +0200 | |
| changeset 8807 | 0046be1769f9 |
| parent 8614 | 30cc975727f1 |
| child 9293 | 3da2533e0a61 |
| 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 |
|
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
9 |
The common case: |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
10 |
|
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
11 |
<goal_facts> |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
12 |
have/show C |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
13 |
obtain a in P[a] <proof> == |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
14 |
|
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
15 |
<goal_facts> |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
16 |
have/show C |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
17 |
proof succeed |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
18 |
def thesis == C |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
19 |
presume that: !!a. P a ==> thesis |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
20 |
from goal_facts show thesis <proof> |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
21 |
next |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
22 |
fix a |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
23 |
assume P a |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
24 |
|
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
25 |
The general case: |
|
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 |
<goal_facts> |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
28 |
have/show !!x. G x ==> C x |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
29 |
obtain a in P[a] <proof> == |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
30 |
|
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
31 |
<goal_facts> |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
32 |
have/show !!x. G x ==> C x |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
33 |
proof succeed |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
34 |
fix x |
| 8543 | 35 |
assume hyps: G x |
| 8094 | 36 |
def thesis == C x |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
37 |
presume that: !!a. P a ==> thesis |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
38 |
from goal_facts show thesis <proof> |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
39 |
next |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
40 |
fix a |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
41 |
assume P a |
| 8094 | 42 |
*) |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
43 |
|
| 8094 | 44 |
signature OBTAIN_DATA = |
45 |
sig |
|
46 |
val that_atts: Proof.context attribute list |
|
47 |
end; |
|
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
48 |
|
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
49 |
signature OBTAIN = |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
50 |
sig |
| 8094 | 51 |
val obtain: ((string list * string option) * Comment.text) list |
52 |
* ((string * Args.src list * (string * (string list * string list)) list) |
|
53 |
* Comment.text) list -> ProofHistory.T -> ProofHistory.T |
|
54 |
val obtain_i: ((string list * typ option) * Comment.text) list |
|
55 |
* ((string * Proof.context attribute list * (term * (term list * term list)) list) |
|
56 |
* Comment.text) list -> ProofHistory.T -> ProofHistory.T |
|
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
57 |
end; |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
58 |
|
| 8094 | 59 |
functor ObtainFun(Data: OBTAIN_DATA): OBTAIN = |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
60 |
struct |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
61 |
|
| 8094 | 62 |
|
63 |
(** obtain(_i) **) |
|
64 |
||
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
65 |
val thatN = "that"; |
| 8543 | 66 |
val hypsN = "hyps"; |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
67 |
|
| 8094 | 68 |
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
|
69 |
let |
| 8543 | 70 |
val _ = Proof.assert_backward state; |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
71 |
|
| 8543 | 72 |
(*obtain vars*) |
| 8094 | 73 |
val (vars_ctxt, vars) = |
74 |
foldl_map prep_vars (Proof.context_of state, map Comment.ignore raw_vars); |
|
75 |
val xs = flat (map fst vars); |
|
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
76 |
|
| 8543 | 77 |
(*obtain asms*) |
| 8094 | 78 |
fun prep_asm (ctxt, (name, src, raw_propps)) = |
79 |
let |
|
80 |
val atts = map (prep_att (ProofContext.theory_of ctxt)) src; |
|
81 |
val (ctxt', propps) = foldl_map prep_propp (ctxt, raw_propps); |
|
82 |
in (ctxt', (name, atts, propps)) end; |
|
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
83 |
|
| 8094 | 84 |
val (asms_ctxt, asms) = foldl_map prep_asm (vars_ctxt, map Comment.ignore raw_asms); |
85 |
val asm_props = flat (map (map fst o #3) asms); |
|
86 |
val _ = ProofContext.warn_extra_tfrees vars_ctxt asms_ctxt; |
|
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
87 |
|
| 8543 | 88 |
(*thesis*) |
89 |
val (prop, (goal_facts, goal)) = Proof.get_goal state; |
|
90 |
||
91 |
val parms = Logic.strip_params prop; |
|
92 |
val parm_names = Term.variantlist (map #1 parms, Term.add_term_names (prop, xs)); |
|
93 |
val parm_types = map #2 parms; |
|
94 |
val parm_vars = map Library.single parm_names ~~ map Some parm_types; |
|
95 |
||
96 |
val frees = map2 Free (parm_names, parm_types); |
|
97 |
val rev_frees = rev frees; |
|
98 |
||
99 |
val hyps = map (fn t => Term.subst_bounds (rev_frees, t)) (Logic.strip_assums_hyp prop); |
|
100 |
val concl = Term.subst_bounds (rev_frees, Logic.strip_assums_concl prop); |
|
101 |
val ((thesis_name, thesis_term), atomic_thesis) = AutoBind.atomic_thesis concl; |
|
102 |
||
| 8094 | 103 |
(*that_prop*) |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
104 |
fun find_free x t = |
| 8614 | 105 |
(case ProofContext.find_free t x of Some (Free a) => Some a | _ => None); |
| 8094 | 106 |
fun occs_var x = Library.get_first (find_free x) asm_props; |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
107 |
val that_prop = |
| 8094 | 108 |
Term.list_all_free (mapfilter occs_var xs, Logic.list_implies (asm_props, atomic_thesis)); |
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
109 |
|
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
110 |
fun after_qed st = |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
111 |
st |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
112 |
|> Proof.next_block |
| 8094 | 113 |
|> Proof.fix_i vars |
114 |
|> Proof.assume_i asms |
|
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
115 |
|> Seq.single; |
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
116 |
in |
| 8094 | 117 |
state |
118 |
|> Method.proof (Some (Method.Basic (K Method.succeed))) |
|
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
119 |
|> Seq.map (fn st => st |
| 8543 | 120 |
|> Proof.fix_i parm_vars |
121 |
|> Proof.assume_i [(hypsN, [], map (rpair ([], [])) hyps)] |
|
| 8094 | 122 |
|> LocalDefs.def_i "" [] ((thesis_name, None), (thesis_term, [])) |
123 |
|> Proof.presume_i [(thatN, Data.that_atts, [(that_prop, ([], []))])] |
|
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
124 |
|> Proof.from_facts goal_facts |
| 8094 | 125 |
|> Proof.show_i after_qed "" [] (atomic_thesis, ([], []))) |
|
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 |
|
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
128 |
|
| 8094 | 129 |
val obtain = ProofHistory.applys o |
130 |
(gen_obtain ProofContext.read_vars ProofContext.read_propp Attrib.local_attribute); |
|
131 |
||
132 |
val obtain_i = ProofHistory.applys o |
|
133 |
(gen_obtain ProofContext.cert_vars ProofContext.cert_propp (K I)); |
|
134 |
||
135 |
||
136 |
||
137 |
(** outer syntax **) |
|
138 |
||
139 |
local structure P = OuterParse and K = OuterSyntax.Keyword in |
|
140 |
||
141 |
val obtainP = |
|
| 8543 | 142 |
OuterSyntax.command "obtain" "generalized existence" |
| 8094 | 143 |
K.prf_asm_goal |
144 |
(Scan.optional |
|
145 |
(P.and_list1 (Scan.repeat1 P.name -- Scan.option (P.$$$ "::" |-- P.typ) -- P.marg_comment) |
|
| 8109 | 146 |
--| P.$$$ "where") [] -- |
| 8094 | 147 |
P.and_list1 ((P.opt_thm_name ":" -- Scan.repeat1 P.propp >> P.triple1) -- P.marg_comment) |
148 |
>> (Toplevel.print oo (Toplevel.proof o obtain))); |
|
149 |
||
| 8109 | 150 |
val _ = OuterSyntax.add_keywords ["where"]; |
| 8094 | 151 |
val _ = OuterSyntax.add_parsers [obtainP]; |
152 |
||
153 |
end; |
|
|
7674
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
154 |
|
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
155 |
|
|
99305245f6bd
The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff
changeset
|
156 |
end; |