forked from seL4/l4v
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Guess_ExI.thy
96 lines (79 loc) · 3.38 KB
/
Guess_ExI.thy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
(*
* Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
*
* SPDX-License-Identifier: BSD-2-Clause
*)
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 "\<lambda>s. ?P" \<Rightarrow> \<open>fail\<close> \<bar> _ \<Rightarrow> \<open>-\<close>)
method in_conj for P Q = (
match (Q) in "P" \<Rightarrow> \<open>-\<close>
| match (Q) in "\<lambda>y. A y \<and> B y" for A B \<Rightarrow>
\<open> match (A) in "(Q' :: 'b)" for Q' \<Rightarrow> \<open>match (B) in "(Q'' :: 'b)" for Q'' \<Rightarrow>
\<open> in_conj P Q' | in_conj P Q''\<close>\<close>\<close>
)
method guess_exI =
(require_determ \<open>(match conclusion in "\<exists>x. Q x" for Q \<Rightarrow>
\<open>match premises in "P y" for P y \<Rightarrow>
\<open>abs_used P, in_conj P Q, rule exI[where x=y]\<close>\<close>)\<close>)
lemma fun_uncurry:
"(P \<longrightarrow> Q \<longrightarrow> R) \<longleftrightarrow> (P \<and> Q) \<longrightarrow> R"
by auto
method guess_spec_inner for P uses I =
((match I in "\<forall>x. C x \<longrightarrow> _ x" for C \<Rightarrow> \<open>in_conj P C\<close> ))
method guess_spec =
(require_determ \<open>(match premises in I:"\<forall>x. _ x \<longrightarrow> _ x" \<Rightarrow>
\<open>match premises in "P y" for P y \<Rightarrow>
\<open>abs_used P, guess_spec_inner P I:I[simplified fun_uncurry],
insert I, drule spec[where x=y]\<close>\<close>)\<close>)
text \<open>Tests and examples\<close>
experiment begin
lemma
assumes Q: "Q x"
shows "P x \<Longrightarrow> \<forall>x. Q x \<longrightarrow> P x \<longrightarrow> R \<Longrightarrow> R"
by (guess_spec, blast intro: Q)
(* Conflicting premises are checked *)
lemma
assumes Q: "Q x"
shows "\<lbrakk> P x; P y \<rbrakk> \<Longrightarrow> \<forall>x. Q x \<longrightarrow> P x \<longrightarrow> R \<Longrightarrow> R"
apply (fails \<open>guess_spec\<close>)
by (blast intro: Q)
(* Conflicts between different conjuncts are checked *)
lemma
assumes Q: "Q x"
shows "\<lbrakk> P x; Q y \<rbrakk> \<Longrightarrow> \<forall>x. Q x \<longrightarrow> P x \<longrightarrow> R \<Longrightarrow> R"
apply (fails \<open>guess_spec\<close>)
by (blast intro: Q)
end
text \<open>Tests and examples\<close>
experiment begin
lemma "P x \<Longrightarrow> \<exists>x. P x"
by guess_exI
lemma
assumes Q: "Q x"
shows "P x \<Longrightarrow> \<exists>x. Q x \<and> P x"
apply guess_exI
by (blast intro: Q)
(* Conflicting premises are checked *)
lemma
assumes Q: "Q x"
shows "\<lbrakk> P x; P y \<rbrakk> \<Longrightarrow> \<exists>x. Q x \<and> P x"
apply (fails \<open>guess_exI\<close>)
by (blast intro: Q)
(* Conflicts between different conjuncts are checked *)
lemma
assumes Q: "Q x"
shows "\<lbrakk> P x; Q y \<rbrakk> \<Longrightarrow> \<exists>x. Q x \<and> P x"
apply (fails \<open>guess_exI\<close>)
by (blast intro: Q)
end
end