(* * Copyright 2019, Data61 * * This software may be distributed and modified according to the terms of * the BSD 2-Clause license. Note that NO WARRANTY is provided. * See "LICENSE_BSD2.txt" for details. * * @TAG(DATA61_BSD) *) theory Guess_ExI imports Eisbach_Methods Apply_Debug begin (* This file contains the experimental methods guess_exI and guess_spec. Each, as the name suggests, attempts to guess an instantiation for their respective rules. It does so by looking for a matching premise for the quantifying binder, checking that this could be the only match for safety. *) method abs_used for P = (match (P) in "\s. ?P" \ \fail\ \ _ \ \-\) method in_conj for P Q = ( match (Q) in "P" \ \-\ | match (Q) in "\y. A y \ B y" for A B \ \ match (A) in "(Q' :: 'b)" for Q' \ \match (B) in "(Q'' :: 'b)" for Q'' \ \ in_conj P Q' | in_conj P Q''\\\ ) method guess_exI = (require_determ \(match conclusion in "\x. Q x" for Q \ \match premises in "P y" for P y \ \abs_used P, in_conj P Q, rule exI[where x=y]\\)\) lemma fun_uncurry: "(P \ Q \ R) \ (P \ Q) \ R" by auto method guess_spec_inner for P uses I = ((match I in "\x. C x \ _ x" for C \ \in_conj P C\ )) method guess_spec = (require_determ \(match premises in I:"\x. _ x \ _ x" \ \match premises in "P y" for P y \ \abs_used P, guess_spec_inner P I:I[simplified fun_uncurry], insert I, drule spec[where x=y]\\)\) text \Tests and examples\ experiment begin lemma assumes Q: "Q x" shows "P x \ \x. Q x \ P x \ R \ R" by (guess_spec, blast intro: Q) (* Conflicting premises are checked *) lemma assumes Q: "Q x" shows "\ P x; P y \ \ \x. Q x \ P x \ R \ R" apply (fails \guess_spec\) by (blast intro: Q) (* Conflicts between different conjuncts are checked *) lemma assumes Q: "Q x" shows "\ P x; Q y \ \ \x. Q x \ P x \ R \ R" apply (fails \guess_spec\) by (blast intro: Q) end text \Tests and examples\ experiment begin lemma "P x \ \x. P x" by guess_exI lemma assumes Q: "Q x" shows "P x \ \x. Q x \ P x" apply guess_exI by (blast intro: Q) (* Conflicting premises are checked *) lemma assumes Q: "Q x" shows "\ P x; P y \ \ \x. Q x \ P x" apply (fails \guess_exI\) by (blast intro: Q) (* Conflicts between different conjuncts are checked *) lemma assumes Q: "Q x" shows "\ P x; Q y \ \ \x. Q x \ P x" apply (fails \guess_exI\) by (blast intro: Q) end end