174 val cla_modifiers: (Args.T list -> (Proof.context attribute * Args.T list)) list |
174 val cla_modifiers: (Args.T list -> (Proof.context attribute * Args.T list)) list |
175 val cla_meth: (claset -> tactic) -> Proof.context -> Proof.method |
175 val cla_meth: (claset -> tactic) -> Proof.context -> Proof.method |
176 val cla_meth': (claset -> int -> tactic) -> Proof.context -> Proof.method |
176 val cla_meth': (claset -> int -> tactic) -> Proof.context -> Proof.method |
177 val cla_method: (claset -> tactic) -> Args.src -> Proof.context -> Proof.method |
177 val cla_method: (claset -> tactic) -> Args.src -> Proof.context -> Proof.method |
178 val cla_method': (claset -> int -> tactic) -> Args.src -> Proof.context -> Proof.method |
178 val cla_method': (claset -> int -> tactic) -> Args.src -> Proof.context -> Proof.method |
179 val single_tac: claset -> thm list -> int -> tactic |
|
180 val setup: (theory -> theory) list |
179 val setup: (theory -> theory) list |
181 end; |
180 end; |
182 |
181 |
183 structure ClasetThyData: CLASET_THY_DATA = |
182 structure ClasetThyData: CLASET_THY_DATA = |
184 struct |
183 struct |
1088 (introN, cla_attr (op addXIs) (op addIs) (op addSIs), "introduction rule"), |
1087 (introN, cla_attr (op addXIs) (op addIs) (op addSIs), "introduction rule"), |
1089 (delruleN, del_attr, "delete rule")]; |
1088 (delruleN, del_attr, "delete rule")]; |
1090 |
1089 |
1091 |
1090 |
1092 |
1091 |
1093 (** single rule proof method **) |
1092 (** proof methods **) |
1094 |
1093 |
1095 (* utils *) |
1094 (* get nets (appropriate order for semi-automatic methods) *) |
1096 |
1095 |
1097 fun resolve_from_seq_tac rq i st = Seq.flat (Seq.map (fn r => rtac r i st) rq); |
1096 local |
|
1097 val imp_elim_netpair = insert (0, 0) ([], [imp_elim]) empty_netpair; |
|
1098 val not_elim_netpair = insert (0, 0) ([], [Data.not_elim]) empty_netpair; |
|
1099 in |
|
1100 fun get_nets (CS {safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair, ...}) = |
|
1101 [imp_elim_netpair, safe0_netpair, safep_netpair, not_elim_netpair, haz_netpair, dup_netpair, xtra_netpair]; |
|
1102 end; |
|
1103 |
|
1104 |
|
1105 (* METHOD_CLASET' *) |
|
1106 |
|
1107 fun METHOD_CLASET' tac = |
|
1108 Method.METHOD (FIRSTGOAL o (fn facts => CLASET' (fn cs => tac cs facts))); |
|
1109 |
|
1110 |
|
1111 val trace_rules = ref false; |
|
1112 |
|
1113 local |
|
1114 |
|
1115 fun trace rules i = |
|
1116 if not (! trace_rules) then () |
|
1117 else Pretty.writeln (Pretty.big_list ("trying standard rule(s) on goal #" ^ string_of_int i ^ ":") |
|
1118 (map Display.pretty_thm rules)); |
|
1119 |
|
1120 |
1098 fun order_rules xs = map snd (Tactic.orderlist xs); |
1121 fun order_rules xs = map snd (Tactic.orderlist xs); |
1099 |
1122 |
1100 fun find_rules concl nets = |
1123 fun find_rules concl nets = |
1101 let fun rules_of (inet, _) = order_rules (Net.unify_term inet concl) |
1124 let fun rules_of (inet, _) = order_rules (Net.unify_term inet concl) |
1102 in flat (map rules_of nets) end; |
1125 in flat (map rules_of nets) end; |
1107 fun may_unify net = Net.unify_term net o Logic.strip_assums_concl o #prop o Thm.rep_thm; |
1130 fun may_unify net = Net.unify_term net o Logic.strip_assums_concl o #prop o Thm.rep_thm; |
1108 fun erules_of (_, enet) = order_rules (may_unify enet fact); |
1131 fun erules_of (_, enet) = order_rules (may_unify enet fact); |
1109 in flat (map erules_of nets) end; |
1132 in flat (map erules_of nets) end; |
1110 |
1133 |
1111 |
1134 |
1112 (* trace rules *) |
1135 fun some_rule_tac cs facts = |
1113 |
|
1114 val trace_rules = ref false; |
|
1115 |
|
1116 fun print_rules rules i = |
|
1117 if not (! trace_rules) then () |
|
1118 else |
|
1119 Pretty.writeln (Pretty.big_list ("trying standard rule(s) on goal #" ^ string_of_int i ^ ":") |
|
1120 (map Display.pretty_thm rules)); |
|
1121 |
|
1122 |
|
1123 (* single_tac *) |
|
1124 |
|
1125 val imp_elim_netpair = insert (0, 0) ([], [imp_elim]) empty_netpair; |
|
1126 val not_elim_netpair = insert (0, 0) ([], [Data.not_elim]) empty_netpair; |
|
1127 |
|
1128 fun single_tac cs facts = |
|
1129 let |
1136 let |
1130 val CS {safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair, ...} = cs; |
1137 val nets = get_nets cs; |
1131 val nets = [imp_elim_netpair, safe0_netpair, safep_netpair, |
|
1132 not_elim_netpair, haz_netpair, dup_netpair, xtra_netpair]; |
|
1133 val erules = find_erules facts nets; |
1138 val erules = find_erules facts nets; |
1134 |
1139 |
1135 val tac = SUBGOAL (fn (goal, i) => |
1140 val tac = SUBGOAL (fn (goal, i) => |
1136 let |
1141 let |
1137 val irules = find_rules (Logic.strip_assums_concl goal) nets; |
1142 val irules = find_rules (Logic.strip_assums_concl goal) nets; |
1138 val rules = erules @ irules; |
1143 val rules = erules @ irules; |
1139 val ruleq = Method.forward_chain facts rules; |
1144 val ruleq = Method.forward_chain facts rules; |
1140 in |
1145 in trace rules i; fn st => Seq.flat (Seq.map (fn rule => Tactic.rtac rule i st) ruleq) end); |
1141 print_rules rules i; |
|
1142 fn st => Seq.flat (Seq.map (fn rule => Tactic.rtac rule i st) ruleq) end); |
|
1143 in tac end; |
1146 in tac end; |
1144 |
1147 |
1145 val single = Method.METHOD (FIRSTGOAL o (fn facts => CLASET' (fn cs => single_tac cs facts))); |
1148 in |
1146 |
1149 val some_rule = METHOD_CLASET' some_rule_tac; |
1147 |
1150 end; |
1148 |
1151 |
1149 (** more proof methods **) |
1152 |
1150 |
1153 (* intro / elim methods *) |
1151 (* contradiction *) |
1154 |
|
1155 local |
|
1156 |
|
1157 fun intro_elim_tac netpair_of _ [] cs facts = |
|
1158 Method.same_tac facts THEN' FIRST' (map (biresolve_from_nets_tac o netpair_of) (get_nets cs)) |
|
1159 | intro_elim_tac _ res_tac rules _ facts = |
|
1160 Method.same_tac facts THEN' res_tac rules; |
|
1161 |
|
1162 val intro_tac = intro_elim_tac (fn (inet, _) => (inet, Net.empty)) resolve_tac; |
|
1163 val elim_tac = intro_elim_tac (fn (_, enet) => (Net.empty, enet)) eresolve_tac; |
|
1164 |
|
1165 in |
|
1166 val intro = METHOD_CLASET' o intro_tac; |
|
1167 val elim = METHOD_CLASET' o elim_tac; |
|
1168 end; |
|
1169 |
|
1170 |
|
1171 (* contradiction method *) |
1152 |
1172 |
1153 val contradiction = Method.METHOD (fn facts => |
1173 val contradiction = Method.METHOD (fn facts => |
1154 FIRSTGOAL (Method.same_tac facts THEN' contr_tac)); |
1174 FIRSTGOAL (Method.same_tac facts THEN' contr_tac)); |
1155 |
1175 |
1156 |
1176 |
1182 |
1202 |
1183 |
1203 |
1184 (** setup_methods **) |
1204 (** setup_methods **) |
1185 |
1205 |
1186 val setup_methods = Method.add_methods |
1206 val setup_methods = Method.add_methods |
1187 [("single", Method.no_args single, "apply standard rule (single step)"), |
1207 [("default", Method.no_args some_rule, "apply some standard rule"), |
1188 ("default", Method.no_args single, "apply standard rule (single step)"), |
1208 ("some_rule", Method.no_args some_rule, "apply some standard rule"), |
|
1209 ("intro", Method.thms_args intro, "apply some introduction rule"), |
|
1210 ("elim", Method.thms_args elim, "apply some elimination rule"), |
1189 ("contradiction", Method.no_args contradiction, "proof by contradiction"), |
1211 ("contradiction", Method.no_args contradiction, "proof by contradiction"), |
1190 ("safe_tac", cla_method safe_tac, "safe_tac (improper!)"), |
1212 ("safe_tac", cla_method safe_tac, "safe_tac (improper!)"), |
1191 ("safe_step_tac", cla_method' safe_step_tac, "safe_step_tac (improper!)"), |
1213 ("safe_step_tac", cla_method' safe_step_tac, "safe_step_tac (improper!)"), |
1192 ("step_tac", cla_method' step_tac, "step_tac (improper!)"), |
1214 ("step_tac", cla_method' step_tac, "step_tac (improper!)"), |
1193 ("fast", cla_method' fast_tac, "classical prover (depth-first)"), |
1215 ("fast", cla_method' fast_tac, "classical prover (depth-first)"), |