121 |
121 |
122 fun err_if state b msg = if b then raise Proof.STATE (msg, state) else (); |
122 fun err_if state b msg = if b then raise Proof.STATE (msg, state) else (); |
123 |
123 |
124 fun calculate final opt_rules print state = |
124 fun calculate final opt_rules print state = |
125 let |
125 let |
126 val facts = Proof.the_facts (Proof.assert_forward state); |
|
127 |
|
128 val strip_assums_concl = Logic.strip_assums_concl o #prop o Thm.rep_thm; |
126 val strip_assums_concl = Logic.strip_assums_concl o #prop o Thm.rep_thm; |
129 val eq_prop = op aconv o pairself (Pattern.eta_contract o strip_assums_concl); |
127 val eq_prop = op aconv o pairself (Pattern.eta_contract o strip_assums_concl); |
130 fun differ thms thms' = not (Library.equal_lists eq_prop (thms, thms')); |
128 fun projection ths th = Library.exists (Library.curry eq_prop th) ths; |
131 |
129 |
132 fun combine thms = |
130 fun combine ths = |
133 let |
131 (case opt_rules of Some rules => rules |
134 val ths = thms @ facts; |
132 | None => |
135 val rs = get_local_rules state; |
133 (case ths of [] => NetRules.rules (get_local_rules state) |
136 val rules = |
134 | th :: _ => NetRules.may_unify (get_local_rules state) (strip_assums_concl th))) |
137 (case ths of [] => NetRules.rules rs |
135 |> Seq.of_list |> Seq.map (Method.multi_resolve ths) |> Seq.flat |
138 | th :: _ => NetRules.may_unify rs (strip_assums_concl th)); |
136 |> Seq.filter (not o projection ths); |
139 val ruleq = Seq.of_list (if_none opt_rules [] @ rules); |
|
140 in Seq.map Library.single (Seq.flat (Seq.map (Method.multi_resolve ths) ruleq)) end; |
|
141 |
137 |
|
138 val facts = Proof.the_facts (Proof.assert_forward state); |
142 val (initial, calculations) = |
139 val (initial, calculations) = |
143 (case get_calculation state of |
140 (case get_calculation state of |
144 None => (true, Seq.single facts) |
141 None => (true, Seq.single facts) |
145 | Some thms => (false, Seq.filter (differ thms) (combine thms))) |
142 | Some calc => (false, Seq.map single (combine (calc @ facts)))); |
146 in |
143 in |
147 err_if state (initial andalso final) "No calculation yet"; |
144 err_if state (initial andalso final) "No calculation yet"; |
148 err_if state (initial andalso is_some opt_rules) "Initial calculation -- no rules to be given"; |
145 err_if state (initial andalso is_some opt_rules) "Initial calculation -- no rules to be given"; |
149 calculations |> Seq.map (fn calc => (print calc; state |> maintain_calculation final calc)) |
146 calculations |> Seq.map (fn calc => (print calc; state |> maintain_calculation final calc)) |
150 end; |
147 end; |