29 |
29 |
30 <goal_facts> |
30 <goal_facts> |
31 have/show !!x. G x ==> C x |
31 have/show !!x. G x ==> C x |
32 proof succeed |
32 proof succeed |
33 fix x |
33 fix x |
34 assume antecedent: G x |
34 assume hyps: G x |
35 def thesis == C x |
35 def thesis == C x |
36 presume that: !!a. P a ==> thesis |
36 presume that: !!a. P a ==> thesis |
37 from goal_facts show thesis <proof> |
37 from goal_facts show thesis <proof> |
38 next |
38 next |
39 fix a |
39 fix a |
40 assume P a |
40 assume P a |
41 |
|
42 TODO: |
|
43 - bind terms for goal as well (done?); |
|
44 - improve block structure (admit subsequent occurences of 'next') (no?); |
|
45 - handle general case (easy??); |
|
46 *) |
41 *) |
47 |
42 |
48 signature OBTAIN_DATA = |
43 signature OBTAIN_DATA = |
49 sig |
44 sig |
50 val that_atts: Proof.context attribute list |
45 val that_atts: Proof.context attribute list |
65 |
60 |
66 |
61 |
67 (** obtain(_i) **) |
62 (** obtain(_i) **) |
68 |
63 |
69 val thatN = "that"; |
64 val thatN = "that"; |
|
65 val hypsN = "hyps"; |
70 |
66 |
71 fun gen_obtain prep_vars prep_propp prep_att (raw_vars, raw_asms) state = |
67 fun gen_obtain prep_vars prep_propp prep_att (raw_vars, raw_asms) state = |
72 let |
68 let |
73 (*thesis*) |
69 val _ = Proof.assert_backward state; |
74 val (prop, (goal_facts, goal)) = Proof.get_goal (Proof.assert_backward state); |
|
75 |
70 |
76 val parms = Logic.strip_params prop; (* FIXME unused *) |
71 (*obtain vars*) |
77 val _ = |
|
78 if null parms then () else raise Proof.STATE ("Cannot handle params in goal (yet)", state); |
|
79 val hyps = Logic.strip_assums_hyp prop; (* FIXME unused *) |
|
80 val concl = Logic.strip_assums_concl prop; |
|
81 val ((thesis_name, thesis_term), atomic_thesis) = AutoBind.atomic_thesis concl; |
|
82 |
|
83 (*vars*) |
|
84 val (vars_ctxt, vars) = |
72 val (vars_ctxt, vars) = |
85 foldl_map prep_vars (Proof.context_of state, map Comment.ignore raw_vars); |
73 foldl_map prep_vars (Proof.context_of state, map Comment.ignore raw_vars); |
86 val xs = flat (map fst vars); |
74 val xs = flat (map fst vars); |
87 |
75 |
88 (*asms*) |
76 (*obtain asms*) |
89 fun prep_asm (ctxt, (name, src, raw_propps)) = |
77 fun prep_asm (ctxt, (name, src, raw_propps)) = |
90 let |
78 let |
91 val atts = map (prep_att (ProofContext.theory_of ctxt)) src; |
79 val atts = map (prep_att (ProofContext.theory_of ctxt)) src; |
92 val (ctxt', propps) = foldl_map prep_propp (ctxt, raw_propps); |
80 val (ctxt', propps) = foldl_map prep_propp (ctxt, raw_propps); |
93 in (ctxt', (name, atts, propps)) end; |
81 in (ctxt', (name, atts, propps)) end; |
94 |
82 |
95 val (asms_ctxt, asms) = foldl_map prep_asm (vars_ctxt, map Comment.ignore raw_asms); |
83 val (asms_ctxt, asms) = foldl_map prep_asm (vars_ctxt, map Comment.ignore raw_asms); |
96 val asm_props = flat (map (map fst o #3) asms); |
84 val asm_props = flat (map (map fst o #3) asms); |
97 val _ = ProofContext.warn_extra_tfrees vars_ctxt asms_ctxt; |
85 val _ = ProofContext.warn_extra_tfrees vars_ctxt asms_ctxt; |
|
86 |
|
87 (*thesis*) |
|
88 val (prop, (goal_facts, goal)) = Proof.get_goal state; |
|
89 |
|
90 val parms = Logic.strip_params prop; |
|
91 val parm_names = Term.variantlist (map #1 parms, Term.add_term_names (prop, xs)); |
|
92 val parm_types = map #2 parms; |
|
93 val parm_vars = map Library.single parm_names ~~ map Some parm_types; |
|
94 |
|
95 val frees = map2 Free (parm_names, parm_types); |
|
96 val rev_frees = rev frees; |
|
97 |
|
98 val hyps = map (fn t => Term.subst_bounds (rev_frees, t)) (Logic.strip_assums_hyp prop); |
|
99 val concl = Term.subst_bounds (rev_frees, Logic.strip_assums_concl prop); |
|
100 val ((thesis_name, thesis_term), atomic_thesis) = AutoBind.atomic_thesis concl; |
98 |
101 |
99 (*that_prop*) |
102 (*that_prop*) |
100 fun find_free x t = |
103 fun find_free x t = |
101 (case Proof.find_free t x of Some (Free a) => Some a | _ => None); |
104 (case Proof.find_free t x of Some (Free a) => Some a | _ => None); |
102 fun occs_var x = Library.get_first (find_free x) asm_props; |
105 fun occs_var x = Library.get_first (find_free x) asm_props; |
111 |> Seq.single; |
114 |> Seq.single; |
112 in |
115 in |
113 state |
116 state |
114 |> Method.proof (Some (Method.Basic (K Method.succeed))) |
117 |> Method.proof (Some (Method.Basic (K Method.succeed))) |
115 |> Seq.map (fn st => st |
118 |> Seq.map (fn st => st |
|
119 |> Proof.fix_i parm_vars |
|
120 |> Proof.assume_i [(hypsN, [], map (rpair ([], [])) hyps)] |
116 |> LocalDefs.def_i "" [] ((thesis_name, None), (thesis_term, [])) |
121 |> LocalDefs.def_i "" [] ((thesis_name, None), (thesis_term, [])) |
117 |> Proof.presume_i [(thatN, Data.that_atts, [(that_prop, ([], []))])] |
122 |> Proof.presume_i [(thatN, Data.that_atts, [(that_prop, ([], []))])] |
118 |> Proof.from_facts goal_facts |
123 |> Proof.from_facts goal_facts |
119 |> Proof.show_i after_qed "" [] (atomic_thesis, ([], []))) |
124 |> Proof.show_i after_qed "" [] (atomic_thesis, ([], []))) |
120 end; |
125 end; |