author | wenzelm |
Mon, 12 Oct 2015 21:09:25 +0200 | |
changeset 61417 | e39b85325b41 |
parent 60298 | 7c278b692aae |
child 61477 | e467ae7aa808 |
permissions | -rw-r--r-- |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
1 |
(*:wrap=hard:maxLineLen=78:*) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
2 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
3 |
theory Manual |
61417 | 4 |
imports Base "~~/src/HOL/Eisbach/Eisbach_Tools" |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
5 |
begin |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
6 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
7 |
chapter \<open>The method command\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
8 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
9 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
10 |
The @{command_def method} command provides the ability to write proof |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
11 |
methods by combining existing ones with their usual syntax. Specifically it |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
12 |
allows compound proof methods to be named, and to extend the name space of |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
13 |
basic methods accordingly. Method definitions may abstract over parameters: |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
14 |
terms, facts, or other methods. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
15 |
|
61417 | 16 |
\<^medskip> |
17 |
The syntax diagram below refers to some syntactic categories that |
|
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
18 |
are further defined in @{cite "isabelle-isar-ref"}. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
19 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
20 |
@{rail \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
21 |
@@{command method} name args @'=' method |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
22 |
; |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
23 |
args: term_args? method_args? \<newline> fact_args? decl_args? |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
24 |
; |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
25 |
term_args: @'for' @{syntax "fixes"} |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
26 |
; |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
27 |
method_args: @'methods' (name+) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
28 |
; |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
29 |
fact_args: @'uses' (name+) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
30 |
; |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
31 |
decl_args: @'declares' (name+) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
32 |
\<close>} |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
33 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
34 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
35 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
36 |
section \<open>Basic method definitions\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
37 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
38 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
39 |
Consider the following proof that makes use of usual Isar method |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
40 |
combinators. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
41 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
42 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
43 |
lemma "P \<and> Q \<longrightarrow> P" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
44 |
by ((rule impI, (erule conjE)?) | assumption)+ |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
45 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
46 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
47 |
It is clear that this compound method will be applicable in more cases than |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
48 |
this proof alone. With the @{command method} command we can define a proof |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
49 |
method that makes the above functionality available generally. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
50 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
51 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
52 |
method prop_solver\<^sub>1 = |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
53 |
((rule impI, (erule conjE)?) | assumption)+ |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
54 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
55 |
lemma "P \<and> Q \<and> R \<longrightarrow> P" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
56 |
by prop_solver\<^sub>1 |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
57 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
58 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
59 |
In this example, the facts @{text impI} and @{text conjE} are static. They |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
60 |
are evaluated once when the method is defined and cannot be changed later. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
61 |
This makes the method stable in the sense of \emph{static scoping}: naming |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
62 |
another fact @{text impI} in a later context won't affect the behaviour of |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
63 |
@{text "prop_solver\<^sub>1"}. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
64 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
65 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
66 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
67 |
section \<open>Term abstraction\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
68 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
69 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
70 |
Methods can also abstract over terms using the @{keyword_def "for"} keyword, |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
71 |
optionally providing type constraints. For instance, the following proof |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
72 |
method @{text intro_ex} takes a term @{term y} of any type, which it uses to |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
73 |
instantiate the @{term x}-variable of @{text exI} (existential introduction) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
74 |
before applying the result as a rule. The instantiation is performed here by |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
75 |
Isar's @{attribute_ref "where"} attribute. If the current subgoal is to find |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
76 |
a witness for the given predicate @{term Q}, then this has the effect of |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
77 |
committing to @{term y}. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
78 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
79 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
80 |
method intro_ex for Q :: "'a \<Rightarrow> bool" and y :: 'a = |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
81 |
(rule exI ["where" P = Q and x = y]) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
82 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
83 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
84 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
85 |
The term parameters @{term y} and @{term Q} can be used arbitrarily inside |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
86 |
the method body, as part of attribute applications or arguments to other |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
87 |
methods. The expression is type-checked as far as possible when the method |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
88 |
is defined, however dynamic type errors can still occur when it is invoked |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
89 |
(e.g.\ when terms are instantiated in a parameterized fact). Actual term |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
90 |
arguments are supplied positionally, in the same order as in the method |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
91 |
definition. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
92 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
93 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
94 |
lemma "P a \<Longrightarrow> \<exists>x. P x" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
95 |
by (intro_ex P a) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
96 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
97 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
98 |
section \<open>Fact abstraction\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
99 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
100 |
subsection \<open>Named theorems\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
101 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
102 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
103 |
A @{text "named theorem"} is a fact whose contents are produced dynamically |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
104 |
within the current proof context. The Isar command @{command_ref |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
105 |
"named_theorems"} provides simple access to this concept: it declares a |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
106 |
dynamic fact with corresponding \emph{attribute} for managing |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
107 |
this particular data slot in the context. |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
108 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
109 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
110 |
named_theorems intros |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
111 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
112 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
113 |
So far @{text "intros"} refers to the empty fact. Using the Isar command |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
114 |
@{command_ref "declare"} we may apply declaration attributes to the context. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
115 |
Below we declare both @{text "conjI"} and @{text "impI"} as @{text |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
116 |
"intros"}, adding them to the named theorem slot. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
117 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
118 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
119 |
declare conjI [intros] and impI [intros] |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
120 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
121 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
122 |
We can refer to named theorems as dynamic facts within a particular proof |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
123 |
context, which are evaluated whenever the method is invoked. Instead of |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
124 |
having facts hard-coded into the method, as in @{text prop_solver\<^sub>1}, we can |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
125 |
instead refer to these named theorems. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
126 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
127 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
128 |
named_theorems elims |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
129 |
declare conjE [elims] |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
130 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
131 |
method prop_solver\<^sub>3 = |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
132 |
((rule intros, (erule elims)?) | assumption)+ |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
133 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
134 |
lemma "P \<and> Q \<longrightarrow> P" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
135 |
by prop_solver\<^sub>3 |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
136 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
137 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
138 |
Often these named theorems need to be augmented on the spot, when a method |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
139 |
is invoked. The @{keyword_def "declares"} keyword in the signature of |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
140 |
@{command method} adds the common method syntax @{text "method decl: facts"} |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
141 |
for each named theorem @{text decl}. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
142 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
143 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
144 |
method prop_solver\<^sub>4 declares intros elims = |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
145 |
((rule intros, (erule elims)?) | assumption)+ |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
146 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
147 |
lemma "P \<and> (P \<longrightarrow> Q) \<longrightarrow> Q \<and> P" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
148 |
by (prop_solver\<^sub>4 elims: impE intros: conjI) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
149 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
150 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
151 |
subsection \<open>Simple fact abstraction\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
152 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
153 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
154 |
The @{keyword "declares"} keyword requires that a corresponding dynamic fact |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
155 |
has been declared with @{command_ref named_theorems}. This is useful for |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
156 |
managing collections of facts which are to be augmented with declarations, |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
157 |
but is overkill if we simply want to pass a fact to a method. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
158 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
159 |
We may use the @{keyword_def "uses"} keyword in the method header to provide |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
160 |
a simple fact parameter. In contrast to @{keyword "declares"}, these facts |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
161 |
are always implicitly empty unless augmented when the method is invoked. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
162 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
163 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
164 |
method rule_twice uses my_rule = |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
165 |
(rule my_rule, rule my_rule) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
166 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
167 |
lemma "P \<Longrightarrow> Q \<Longrightarrow> (P \<and> Q) \<and> Q" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
168 |
by (rule_twice my_rule: conjI) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
169 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
170 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
171 |
section \<open>Higher-order methods\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
172 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
173 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
174 |
The \emph{structured concatenation} combinator ``@{text "method\<^sub>1 ; |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
175 |
method\<^sub>2"}'' was introduced in Isabelle2015, motivated by development of |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
176 |
Eisbach. It is similar to ``@{text "method\<^sub>1, method\<^sub>2"}'', but @{text |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
177 |
method\<^sub>2} is invoked on on \emph{all} subgoals that have newly emerged from |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
178 |
@{text method\<^sub>1}. This is useful to handle cases where the number of |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
179 |
subgoals produced by a method is determined dynamically at run-time. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
180 |
\<close> |
61417 | 181 |
|
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
182 |
method conj_with uses rule = |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
183 |
(intro conjI ; intro rule) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
184 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
185 |
lemma |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
186 |
assumes A: "P" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
187 |
shows "P \<and> P \<and> P" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
188 |
by (conj_with rule: A) |
61417 | 189 |
|
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
190 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
191 |
Method definitions may take other methods as arguments, and thus implement |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
192 |
method combinators with prefix syntax. For example, to more usefully exploit |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
193 |
Isabelle's backtracking, the explicit requirement that a method solve all |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
194 |
produced subgoals is frequently useful. This can easily be written as a |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
195 |
\emph{higher-order method} using ``@{text ";"}''. The @{keyword "methods"} |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
196 |
keyword denotes method parameters that are other proof methods to be invoked |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
197 |
by the method being defined. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
198 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
199 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
200 |
method solve methods m = (m ; fail) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
201 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
202 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
203 |
Given some method-argument @{text m}, @{text "solve \<open>m\<close>"} applies the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
204 |
method @{text m} and then fails whenever @{text m} produces any new unsolved |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
205 |
subgoals --- i.e. when @{text m} fails to completely discharge the goal it |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
206 |
was applied to. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
207 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
208 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
209 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
210 |
section \<open>Example\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
211 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
212 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
213 |
With these simple features we are ready to write our first non-trivial proof |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
214 |
method. Returning to the first-order logic example, the following method |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
215 |
definition applies various rules with their canonical methods. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
216 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
217 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
218 |
named_theorems subst |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
219 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
220 |
method prop_solver declares intros elims subst = |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
221 |
(assumption | |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
222 |
(rule intros) | erule elims | |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
223 |
subst subst | subst (asm) subst | |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
224 |
(erule notE ; solve \<open>prop_solver\<close>))+ |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
225 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
226 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
227 |
The only non-trivial part above is the final alternative @{text "(erule notE |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
228 |
; solve \<open>prop_solver\<close>)"}. Here, in the case that all other alternatives |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
229 |
fail, the method takes one of the assumptions @{term "\<not> P"} of the current |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
230 |
goal and eliminates it with the rule @{text notE}, causing the goal to be |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
231 |
proved to become @{term P}. The method then recursively invokes itself on |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
232 |
the remaining goals. The job of the recursive call is to demonstrate that |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
233 |
there is a contradiction in the original assumptions (i.e.\ that @{term P} |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
234 |
can be derived from them). Note this recursive invocation is applied with |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
235 |
the @{method solve} method combinator to ensure that a contradiction will |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
236 |
indeed be shown. In the case where a contradiction cannot be found, |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
237 |
backtracking will occur and a different assumption @{term "\<not> Q"} will be |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
238 |
chosen for elimination. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
239 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
240 |
Note that the recursive call to @{method prop_solver} does not have any |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
241 |
parameters passed to it. Recall that fact parameters, e.g.\ @{text |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
242 |
"intros"}, @{text "elims"}, and @{text "subst"}, are managed by declarations |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
243 |
in the current proof context. They will therefore be passed to any recursive |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
244 |
call to @{method prop_solver} and, more generally, any invocation of a |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
245 |
method which declares these named theorems. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
246 |
|
61417 | 247 |
\<^medskip> |
248 |
After declaring some standard rules to the context, the @{method |
|
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
249 |
prop_solver} becomes capable of solving non-trivial propositional |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
250 |
tautologies.\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
251 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
252 |
lemmas [intros] = |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
253 |
conjI -- \<open>@{thm conjI}\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
254 |
impI -- \<open>@{thm impI}\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
255 |
disjCI -- \<open>@{thm disjCI}\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
256 |
iffI -- \<open>@{thm iffI}\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
257 |
notI -- \<open>@{thm notI}\<close> |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
258 |
|
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
259 |
lemmas [elims] = |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
260 |
impCE -- \<open>@{thm impCE}\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
261 |
conjE -- \<open>@{thm conjE}\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
262 |
disjE -- \<open>@{thm disjE}\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
263 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
264 |
lemma "(A \<or> B) \<and> (A \<longrightarrow> C) \<and> (B \<longrightarrow> C) \<longrightarrow> C" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
265 |
by prop_solver |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
266 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
267 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
268 |
chapter \<open>The match method \label{s:matching}\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
269 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
270 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
271 |
So far we have seen methods defined as simple combinations of other methods. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
272 |
Some familiar programming language concepts have been introduced (i.e.\ |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
273 |
abstraction and recursion). The only control flow has been implicitly the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
274 |
result of backtracking. When designing more sophisticated proof methods this |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
275 |
proves too restrictive and difficult to manage conceptually. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
276 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
277 |
To address this, we introduce the @{method_def "match"} method, which |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
278 |
provides more direct access to the higher-order matching facility at the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
279 |
core of Isabelle. It is implemented as a separate proof method (in |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
280 |
Isabelle/ML), and thus can be directly applied to proofs, however it is most |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
281 |
useful when applied in the context of writing Eisbach method definitions. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
282 |
|
61417 | 283 |
\<^medskip> |
284 |
The syntax diagram below refers to some syntactic categories that |
|
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
285 |
are further defined in @{cite "isabelle-isar-ref"}. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
286 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
287 |
@{rail \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
288 |
@@{method match} kind @'in' (pattern '\<Rightarrow>' cartouche + '\<bar>') |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
289 |
; |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
290 |
kind: |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
291 |
(@'conclusion' | @'premises' ('(' 'local' ')')? | |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
292 |
'(' term ')' | @{syntax thmrefs}) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
293 |
; |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
294 |
pattern: fact_name? term args? \<newline> (@'for' fixes)? |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
295 |
; |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
296 |
fact_name: @{syntax name} @{syntax attributes}? ':' |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
297 |
; |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
298 |
args: '(' (('multi' | 'cut' nat?) + ',') ')' |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
299 |
\<close>} |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
300 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
301 |
Matching allows methods to introspect the goal state, and to implement more |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
302 |
explicit control flow. In the basic case, a term or fact @{text ts} is given |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
303 |
to match against as a \emph{match target}, along with a collection of |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
304 |
pattern-method pairs @{text "(p, m)"}: roughly speaking, when the pattern |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
305 |
@{text p} matches any member of @{text ts}, the \emph{inner} method @{text |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
306 |
m} will be executed. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
307 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
308 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
309 |
lemma |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
310 |
assumes X: |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
311 |
"Q \<longrightarrow> P" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
312 |
"Q" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
313 |
shows P |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
314 |
by (match X in I: "Q \<longrightarrow> P" and I': "Q" \<Rightarrow> \<open>insert mp [OF I I']\<close>) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
315 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
316 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
317 |
In this example we have a structured Isar proof, with the named |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
318 |
assumption @{text "X"} and a conclusion @{term "P"}. With the match method |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
319 |
we can find the local facts @{term "Q \<longrightarrow> P"} and @{term "Q"}, binding them to |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
320 |
separately as @{text "I"} and @{text "I'"}. We then specialize the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
321 |
modus-ponens rule @{thm mp [of Q P]} to these facts to solve the goal. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
322 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
323 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
324 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
325 |
section \<open>Subgoal focus\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
326 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
327 |
text\<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
328 |
In the previous example we were able to match against an assumption out of |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
329 |
the Isar proof state. In general, however, proof subgoals can be |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
330 |
\emph{unstructured}, with goal parameters and premises arising from rule |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
331 |
application. To address this, @{method match} uses \emph{subgoal focusing} |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
332 |
to produce structured goals out of |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
333 |
unstructured ones. In place of fact or term, we may give the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
334 |
keyword @{keyword_def "premises"} as the match target. This causes a subgoal |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
335 |
focus on the first subgoal, lifting local goal parameters to fixed term |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
336 |
variables and premises into hypothetical theorems. The match is performed |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
337 |
against these theorems, naming them and binding them as appropriate. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
338 |
Similarly giving the keyword @{keyword_def "conclusion"} matches against the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
339 |
conclusion of the first subgoal. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
340 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
341 |
An unstructured version of the previous example can then be similarly solved |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
342 |
through focusing. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
343 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
344 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
345 |
lemma "Q \<longrightarrow> P \<Longrightarrow> Q \<Longrightarrow> P" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
346 |
by (match premises in |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
347 |
I: "Q \<longrightarrow> P" and I': "Q" \<Rightarrow> \<open>insert mp [OF I I']\<close>) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
348 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
349 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
350 |
Match variables may be specified by giving a list of @{keyword_ref |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
351 |
"for"}-fixes after the pattern description. This marks those terms as bound |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
352 |
variables, which may be used in the method body. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
353 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
354 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
355 |
lemma "Q \<longrightarrow> P \<Longrightarrow> Q \<Longrightarrow> P" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
356 |
by (match premises in I: "Q \<longrightarrow> A" and I': "Q" for A \<Rightarrow> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
357 |
\<open>match conclusion in A \<Rightarrow> \<open>insert mp [OF I I']\<close>\<close>) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
358 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
359 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
360 |
In this example @{term A} is a match variable which is bound to @{term P} |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
361 |
upon a successful match. The inner @{method match} then matches the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
362 |
now-bound @{term A} (bound to @{term P}) against the conclusion (also @{term |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
363 |
P}), finally applying the specialized rule to solve the goal. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
364 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
365 |
Schematic terms like @{text "?P"} may also be used to specify match |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
366 |
variables, but the result of the match is not bound, and thus cannot be used |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
367 |
in the inner method body. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
368 |
|
61417 | 369 |
\<^medskip> |
370 |
In the following example we extract the predicate of an |
|
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
371 |
existentially quantified conclusion in the current subgoal and search the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
372 |
current premises for a matching fact. If both matches are successful, we |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
373 |
then instantiate the existential introduction rule with both the witness and |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
374 |
predicate, solving with the matched premise. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
375 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
376 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
377 |
method solve_ex = |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
378 |
(match conclusion in "\<exists>x. Q x" for Q \<Rightarrow> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
379 |
\<open>match premises in U: "Q y" for y \<Rightarrow> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
380 |
\<open>rule exI [where P = Q and x = y, OF U]\<close>\<close>) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
381 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
382 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
383 |
The first @{method match} matches the pattern @{term "\<exists>x. Q x"} against the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
384 |
current conclusion, binding the term @{term "Q"} in the inner match. Next |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
385 |
the pattern @{text "Q y"} is matched against all premises of the current |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
386 |
subgoal. In this case @{term "Q"} is fixed and @{term "y"} may be |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
387 |
instantiated. Once a match is found, the local fact @{text U} is bound to |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
388 |
the matching premise and the variable @{term "y"} is bound to the matching |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
389 |
witness. The existential introduction rule @{text "exI:"}~@{thm exI} is then |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
390 |
instantiated with @{term "y"} as the witness and @{term "Q"} as the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
391 |
predicate, with its proof obligation solved by the local fact U (using the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
392 |
Isar attribute @{attribute OF}). The following example is a trivial use of |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
393 |
this method. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
394 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
395 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
396 |
lemma "halts p \<Longrightarrow> \<exists>x. halts x" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
397 |
by solve_ex |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
398 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
399 |
|
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
400 |
subsection \<open>Operating within a focus\<close> |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
401 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
402 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
403 |
Subgoal focusing provides a structured form of a subgoal, allowing for more |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
404 |
expressive introspection of the goal state. This requires some consideration |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
405 |
in order to be used effectively. When the keyword @{keyword "premises"} is |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
406 |
given as the match target, the premises of the subgoal are lifted into |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
407 |
hypothetical theorems, which can be found and named via match patterns. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
408 |
Additionally these premises are stripped from the subgoal, leaving only the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
409 |
conclusion. This renders them inaccessible to standard proof methods which |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
410 |
operate on the premises, such as @{method frule} or @{method erule}. Naive |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
411 |
usage of these methods within a match will most likely not function as the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
412 |
method author intended. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
413 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
414 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
415 |
method my_allE_bad for y :: 'a = |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
416 |
(match premises in I: "\<forall>x :: 'a. ?Q x" \<Rightarrow> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
417 |
\<open>erule allE [where x = y]\<close>) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
418 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
419 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
420 |
Here we take a single parameter @{term y} and specialize the universal |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
421 |
elimination rule (@{thm allE}) to it, then attempt to apply this specialized |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
422 |
rule with @{method erule}. The method @{method erule} will attempt to unify |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
423 |
with a universal quantifier in the premises that matches the type of @{term |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
424 |
y}. Since @{keyword "premises"} causes a focus, however, there are no |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
425 |
subgoal premises to be found and thus @{method my_allE_bad} will always |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
426 |
fail. If focusing instead left the premises in place, using methods |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
427 |
like @{method erule} would lead to unintended behaviour, specifically during |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
428 |
backtracking. In our example, @{method erule} could choose an alternate |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
429 |
premise while backtracking, while leaving @{text I} bound to the original |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
430 |
match. In the case of more complex inner methods, where either @{text I} or |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
431 |
bound terms are used, this would almost certainly not be the intended |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
432 |
behaviour. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
433 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
434 |
An alternative implementation would be to specialize the elimination rule to |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
435 |
the bound term and apply it directly. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
436 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
437 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
438 |
method my_allE_almost for y :: 'a = |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
439 |
(match premises in I: "\<forall>x :: 'a. ?Q x" \<Rightarrow> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
440 |
\<open>rule allE [where x = y, OF I]\<close>) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
441 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
442 |
lemma "\<forall>x. P x \<Longrightarrow> P y" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
443 |
by (my_allE_almost y) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
444 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
445 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
446 |
This method will insert a specialized duplicate of a universally quantified |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
447 |
premise. Although this will successfully apply in the presence of such a |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
448 |
premise, it is not likely the intended behaviour. Repeated application of |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
449 |
this method will produce an infinite stream of duplicate specialized |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
450 |
premises, due to the original premise never being removed. To address this, |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
451 |
matched premises may be declared with the @{attribute "thin"} attribute. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
452 |
This will hide the premise from subsequent inner matches, and remove it from |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
453 |
the list of premises when the inner method has finished and the subgoal is |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
454 |
unfocused. It can be considered analogous to the existing @{text thin_tac}. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
455 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
456 |
To complete our example, the correct implementation of the method |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
457 |
will @{attribute "thin"} the premise from the match and then apply it to the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
458 |
specialized elimination rule.\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
459 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
460 |
method my_allE for y :: 'a = |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
461 |
(match premises in I [thin]: "\<forall>x :: 'a. ?Q x" \<Rightarrow> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
462 |
\<open>rule allE [where x = y, OF I]\<close>) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
463 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
464 |
lemma "\<forall>x. P x \<Longrightarrow> \<forall>x. Q x \<Longrightarrow> P y \<and> Q y" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
465 |
by (my_allE y)+ (rule conjI) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
466 |
|
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
467 |
subsubsection \<open>Inner focusing\<close> |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
468 |
|
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
469 |
text \<open> |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
470 |
Premises are \emph{accumulated} for the purposes of subgoal focusing. |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
471 |
In contrast to using standard methods like @{method frule} within |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
472 |
focused match, another @{method match} will have access to all the premises |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
473 |
of the outer focus. |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
474 |
\<close> |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
475 |
|
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
476 |
lemma "A \<Longrightarrow> B \<Longrightarrow> A \<and> B" |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
477 |
by (match premises in H: A \<Rightarrow> \<open>intro conjI, rule H, |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
478 |
match premises in H': B \<Rightarrow> \<open>rule H'\<close>\<close>) |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
479 |
|
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
480 |
text \<open> |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
481 |
In this example, the inner @{method match} can find the focused premise |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
482 |
@{term B}. In contrast, the @{method assumption} method would fail here |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
483 |
due to @{term B} not being logically accessible. |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
484 |
\<close> |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
485 |
|
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
486 |
lemma |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
487 |
"A \<Longrightarrow> A \<and> (B \<longrightarrow> B)" |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
488 |
by (match premises in H: A \<Rightarrow> \<open>intro conjI, rule H, rule impI, |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
489 |
match premises (local) in A \<Rightarrow> \<open>fail\<close> |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
490 |
\<bar> H': B \<Rightarrow> \<open>rule H'\<close>\<close>) |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
491 |
|
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
492 |
text \<open> |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
493 |
In this example, the only premise that exists in the first focus is |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
494 |
@{term "A"}. Prior to the inner match, the rule @{text impI} changes |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
495 |
the goal @{term "B \<longrightarrow> B"} into @{term "B \<Longrightarrow> B"}. A standard premise |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
496 |
match would also include @{term A} as an original premise of the outer |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
497 |
match. The @{text local} argument limits the match to |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
498 |
newly focused premises. |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
499 |
|
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
500 |
\<close> |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
501 |
|
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
502 |
section \<open>Attributes\<close> |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
503 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
504 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
505 |
Attributes may throw errors when applied to a given fact. For example, rule |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
506 |
instantiation will fail of there is a type mismatch or if a given variable |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
507 |
doesn't exist. Within a match or a method definition, it isn't generally |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
508 |
possible to guarantee that applied attributes won't fail. For example, in |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
509 |
the following method there is no guarantee that the two provided facts will |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
510 |
necessarily compose. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
511 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
512 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
513 |
method my_compose uses rule1 rule2 = |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
514 |
(rule rule1 [OF rule2]) |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
515 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
516 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
517 |
Some attributes (like @{attribute OF}) have been made partially |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
518 |
Eisbach-aware. This means that they are able to form a closure despite not |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
519 |
necessarily always being applicable. In the case of @{attribute OF}, it is |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
520 |
up to the proof author to guard attribute application with an appropriate |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
521 |
@{method match}, but there are still no static guarantees. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
522 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
523 |
In contrast to @{attribute OF}, the @{attribute "where"} and @{attribute of} |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
524 |
attributes attempt to provide static guarantees that they will apply |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
525 |
whenever possible. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
526 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
527 |
Within a match pattern for a fact, each outermost quantifier specifies the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
528 |
requirement that a matching fact must have a schematic variable at that |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
529 |
point. This gives a corresponding name to this ``slot'' for the purposes of |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
530 |
forming a static closure, allowing the @{attribute "where"} attribute to |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
531 |
perform an instantiation at run-time. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
532 |
\<close> |
61417 | 533 |
|
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
534 |
lemma |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
535 |
assumes A: "Q \<Longrightarrow> False" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
536 |
shows "\<not> Q" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
537 |
by (match intros in X: "\<And>P. (P \<Longrightarrow> False) \<Longrightarrow> \<not> P" \<Rightarrow> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
538 |
\<open>rule X [where P = Q, OF A]\<close>) |
61417 | 539 |
|
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
540 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
541 |
Subgoal focusing converts the outermost quantifiers of premises into |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
542 |
schematics when lifting them to hypothetical facts. This allows us to |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
543 |
instantiate them with @{attribute "where"} when using an appropriate match |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
544 |
pattern. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
545 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
546 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
547 |
lemma "(\<And>x :: 'a. A x \<Longrightarrow> B x) \<Longrightarrow> A y \<Longrightarrow> B y" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
548 |
by (match premises in I: "\<And>x :: 'a. ?P x \<Longrightarrow> ?Q x" \<Rightarrow> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
549 |
\<open>rule I [where x = y]\<close>) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
550 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
551 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
552 |
The @{attribute of} attribute behaves similarly. It is worth noting, |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
553 |
however, that the positional instantiation of @{attribute of} occurs against |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
554 |
the position of the variables as they are declared \emph{in the match |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
555 |
pattern}. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
556 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
557 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
558 |
lemma |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
559 |
fixes A B and x :: 'a and y :: 'b |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
560 |
assumes asm: "(\<And>x y. A y x \<Longrightarrow> B x y )" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
561 |
shows "A y x \<Longrightarrow> B x y" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
562 |
by (match asm in I: "\<And>(x :: 'a) (y :: 'b). ?P x y \<Longrightarrow> ?Q x y" \<Rightarrow> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
563 |
\<open>rule I [of x y]\<close>) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
564 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
565 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
566 |
In this example, the order of schematics in @{text asm} is actually @{text |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
567 |
"?y ?x"}, but we instantiate our matched rule in the opposite order. This is |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
568 |
because the effective rule @{term I} was bound from the match, which |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
569 |
declared the @{typ 'a} slot first and the @{typ 'b} slot second. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
570 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
571 |
To get the dynamic behaviour of @{attribute of} we can choose to invoke it |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
572 |
\emph{unchecked}. This avoids trying to do any type inference for the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
573 |
provided parameters, instead storing them as their most general type and |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
574 |
doing type matching at run-time. This, like @{attribute OF}, will throw |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
575 |
errors if the expected slots don't exist or there is a type mismatch. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
576 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
577 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
578 |
lemma |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
579 |
fixes A B and x :: 'a and y :: 'b |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
580 |
assumes asm: "\<And>x y. A y x \<Longrightarrow> B x y" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
581 |
shows "A y x \<Longrightarrow> B x y" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
582 |
by (match asm in I: "PROP ?P" \<Rightarrow> \<open>rule I [of (unchecked) y x]\<close>) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
583 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
584 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
585 |
Attributes may be applied to matched facts directly as they are matched. Any |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
586 |
declarations will therefore be applied in the context of the inner method, |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
587 |
as well as any transformations to the rule. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
588 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
589 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
590 |
lemma "(\<And>x :: 'a. A x \<Longrightarrow> B x) \<Longrightarrow> A y \<longrightarrow> B y" |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
591 |
by (match premises in I [of y, intros]: "\<And>x :: 'a. ?P x \<Longrightarrow> ?Q x" \<Rightarrow> |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
592 |
\<open>prop_solver\<close>) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
593 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
594 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
595 |
In this example, the pattern @{text "\<And>x :: 'a. ?P x \<Longrightarrow> ?Q x"} matches against |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
596 |
the only premise, giving an appropriately typed slot for @{term y}. After |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
597 |
the match, the resulting rule is instantiated to @{term y} and then declared |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
598 |
as an @{attribute intros} rule. This is then picked up by @{method |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
599 |
prop_solver} to solve the goal. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
600 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
601 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
602 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
603 |
section \<open>Multi-match \label{sec:multi}\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
604 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
605 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
606 |
In all previous examples, @{method match} was only ever searching for a |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
607 |
single rule or premise. Each local fact would therefore always have a length |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
608 |
of exactly one. We may, however, wish to find \emph{all} matching results. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
609 |
To achieve this, we can simply mark a given pattern with the @{text |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
610 |
"(multi)"} argument. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
611 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
612 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
613 |
lemma |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
614 |
assumes asms: "A \<Longrightarrow> B" "A \<Longrightarrow> D" |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
615 |
shows "(A \<longrightarrow> B) \<and> (A \<longrightarrow> D)" |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
616 |
apply (match asms in I [intros]: "?P \<Longrightarrow> ?Q" \<Rightarrow> \<open>solves \<open>prop_solver\<close>\<close>)? |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
617 |
apply (match asms in I [intros]: "?P \<Longrightarrow> ?Q" (multi) \<Rightarrow> \<open>prop_solver\<close>) |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
618 |
done |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
619 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
620 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
621 |
In the first @{method match}, without the @{text "(multi)"} argument, @{term |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
622 |
I} is only ever be bound to one of the members of @{text asms}. This |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
623 |
backtracks over both possibilities (see next section), however neither |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
624 |
assumption in isolation is sufficient to solve to goal. The use of the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
625 |
@{method solves} combinator ensures that @{method prop_solver} has no effect |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
626 |
on the goal when it doesn't solve it, and so the first match leaves the goal |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
627 |
unchanged. In the second @{method match}, @{text I} is bound to all of |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
628 |
@{text asms}, declaring both results as @{text intros}. With these rules |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
629 |
@{method prop_solver} is capable of solving the goal. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
630 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
631 |
Using for-fixed variables in patterns imposes additional constraints on the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
632 |
results. In all previous examples, the choice of using @{text ?P} or a |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
633 |
for-fixed @{term P} only depended on whether or not @{term P} was mentioned |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
634 |
in another pattern or the inner method. When using a multi-match, however, |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
635 |
all for-fixed terms must agree in the results. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
636 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
637 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
638 |
lemma |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
639 |
assumes asms: "A \<Longrightarrow> B" "A \<Longrightarrow> D" "D \<Longrightarrow> B" |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
640 |
shows "(A \<longrightarrow> B) \<and> (A \<longrightarrow> D)" |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
641 |
apply (match asms in I [intros]: "?P \<Longrightarrow> Q" (multi) for Q \<Rightarrow> |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
642 |
\<open>solves \<open>prop_solver\<close>\<close>)? |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
643 |
apply (match asms in I [intros]: "P \<Longrightarrow> ?Q" (multi) for P \<Rightarrow> |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
644 |
\<open>prop_solver\<close>) |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
645 |
done |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
646 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
647 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
648 |
Here we have two seemingly-equivalent applications of @{method match}, |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
649 |
however only the second one is capable of solving the goal. The first |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
650 |
@{method match} selects the first and third members of @{text asms} (those |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
651 |
that agree on their conclusion), which is not sufficient. The second |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
652 |
@{method match} selects the first and second members of @{text asms} (those |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
653 |
that agree on their assumption), which is enough for @{method prop_solver} |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
654 |
to solve the goal. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
655 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
656 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
657 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
658 |
section \<open>Dummy patterns\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
659 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
660 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
661 |
Dummy patterns may be given as placeholders for unique schematics in |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
662 |
patterns. They implicitly receive all currently bound variables as |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
663 |
arguments, and are coerced into the @{typ prop} type whenever possible. For |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
664 |
example, the trivial dummy pattern @{text "_"} will match any proposition. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
665 |
In contrast, by default the pattern @{text "?P"} is considered to have type |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
666 |
@{typ bool}. It will not bind anything with meta-logical connectives (e.g. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
667 |
@{text "_ \<Longrightarrow> _"} or @{text "_ &&& _"}). |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
668 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
669 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
670 |
lemma |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
671 |
assumes asms: "A &&& B \<Longrightarrow> D" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
672 |
shows "(A \<and> B \<longrightarrow> D)" |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
673 |
by (match asms in I: _ \<Rightarrow> \<open>prop_solver intros: I conjunctionI\<close>) |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
674 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
675 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
676 |
section \<open>Backtracking\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
677 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
678 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
679 |
Patterns are considered top-down, executing the inner method @{text m} of |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
680 |
the first pattern which is satisfied by the current match target. By |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
681 |
default, matching performs extensive backtracking by attempting all valid |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
682 |
variable and fact bindings according to the given pattern. In particular, |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
683 |
all unifiers for a given pattern will be explored, as well as each matching |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
684 |
fact. The inner method @{text m} will be re-executed for each different |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
685 |
variable/fact binding during backtracking. A successful match is considered |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
686 |
a cut-point for backtracking. Specifically, once a match is made no other |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
687 |
pattern-method pairs will be considered. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
688 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
689 |
The method @{text foo} below fails for all goals that are conjunctions. Any |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
690 |
such goal will match the first pattern, causing the second pattern (that |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
691 |
would otherwise match all goals) to never be considered. |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
692 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
693 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
694 |
method foo = |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
695 |
(match conclusion in "?P \<and> ?Q" \<Rightarrow> \<open>fail\<close> \<bar> "?R" \<Rightarrow> \<open>prop_solver\<close>) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
696 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
697 |
text \<open> |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
698 |
The failure of an inner method that is executed after a successful match |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
699 |
will cause the entire match to fail. This distinction is important |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
700 |
due to the pervasive use of backtracking. When a method is used in a |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
701 |
combinator chain, its failure |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
702 |
becomes significant because it signals previously applied methods to move to |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
703 |
the next result. Therefore, it is necessary for @{method match} to not mask |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
704 |
such failure. One can always rewrite a match using the combinators ``@{text |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
705 |
"?"}'' and ``@{text "|"}'' to try subsequent patterns in the case of an |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
706 |
inner-method failure. The following proof method, for example, always |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
707 |
invokes @{method prop_solver} for all goals because its first alternative |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
708 |
either never matches or (if it does match) always fails. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
709 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
710 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
711 |
method foo\<^sub>1 = |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
712 |
(match conclusion in "?P \<and> ?Q" \<Rightarrow> \<open>fail\<close>) | |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
713 |
(match conclusion in "?R" \<Rightarrow> \<open>prop_solver\<close>) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
714 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
715 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
716 |
subsection \<open>Cut\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
717 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
718 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
719 |
Backtracking may be controlled more precisely by marking individual patterns |
61417 | 720 |
as @{text cut}. This causes backtracking to not progress beyond this pattern: |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
721 |
once a match is found no others will be considered. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
722 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
723 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
724 |
method foo\<^sub>2 = |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
725 |
(match premises in I: "P \<and> Q" (cut) and I': "P \<longrightarrow> ?U" for P Q \<Rightarrow> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
726 |
\<open>rule mp [OF I' I [THEN conjunct1]]\<close>) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
727 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
728 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
729 |
In this example, once a conjunction is found (@{term "P \<and> Q"}), all possible |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
730 |
implications of @{term "P"} in the premises are considered, evaluating the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
731 |
inner @{method rule} with each consequent. No other conjunctions will be |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
732 |
considered, with method failure occurring once all implications of the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
733 |
form @{text "P \<longrightarrow> ?U"} have been explored. Here the left-right processing of |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
734 |
individual patterns is important, as all patterns after of the cut will |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
735 |
maintain their usual backtracking behaviour. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
736 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
737 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
738 |
lemma "A \<and> B \<Longrightarrow> A \<longrightarrow> D \<Longrightarrow> A \<longrightarrow> C \<Longrightarrow> C" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
739 |
by foo\<^sub>2 |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
740 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
741 |
lemma "C \<and> D \<Longrightarrow> A \<and> B \<Longrightarrow> A \<longrightarrow> C \<Longrightarrow> C" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
742 |
by (foo\<^sub>2 | prop_solver) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
743 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
744 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
745 |
In this example, the first lemma is solved by @{text foo\<^sub>2}, by first |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
746 |
picking @{term "A \<longrightarrow> D"} for @{text I'}, then backtracking and ultimately |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
747 |
succeeding after picking @{term "A \<longrightarrow> C"}. In the second lemma, however, |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
748 |
@{term "C \<and> D"} is matched first, the second pattern in the match cannot be |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
749 |
found and so the method fails, falling through to @{method prop_solver}. |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
750 |
|
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
751 |
More precise control is also possible by giving a positive |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
752 |
number @{text n} as an argument to @{text cut}. This will limit the number |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
753 |
of backtracking results of that match to be at most @{text n}. |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
754 |
The match argument @{text "(cut 1)"} is the same as simply @{text "(cut)"}. |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
755 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
756 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
757 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
758 |
subsection \<open>Multi-match revisited\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
759 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
760 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
761 |
A multi-match will produce a sequence of potential bindings for for-fixed |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
762 |
variables, where each binding environment is the result of matching against |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
763 |
at least one element from the match target. For each environment, the match |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
764 |
result will be all elements of the match target which agree with the pattern |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
765 |
under that environment. This can result in unexpected behaviour when giving |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
766 |
very general patterns. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
767 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
768 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
769 |
lemma |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
770 |
assumes asms: "\<And>x. A x \<and> B x" "\<And>y. A y \<and> C y" "\<And>z. B z \<and> C z" |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
771 |
shows "A x \<and> C x" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
772 |
by (match asms in I: "\<And>x. P x \<and> ?Q x" (multi) for P \<Rightarrow> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
773 |
\<open>match (P) in "A" \<Rightarrow> \<open>fail\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
774 |
\<bar> _ \<Rightarrow> \<open>match I in "\<And>x. A x \<and> B x" \<Rightarrow> \<open>fail\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
775 |
\<bar> _ \<Rightarrow> \<open>rule I\<close>\<close>\<close>) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
776 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
777 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
778 |
Intuitively it seems like this proof should fail to check. The first match |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
779 |
result, which binds @{term I} to the first two members of @{text asms}, |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
780 |
fails the second inner match due to binding @{term P} to @{term A}. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
781 |
Backtracking then attempts to bind @{term I} to the third member of @{text |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
782 |
asms}. This passes all inner matches, but fails when @{method rule} cannot |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
783 |
successfully apply this to the current goal. After this, a valid match that |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
784 |
is produced by the unifier is one which binds @{term P} to simply @{text |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
785 |
"\<lambda>a. A ?x"}. The first inner match succeeds because @{text "\<lambda>a. A ?x"} does |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
786 |
not match @{term A}. The next inner match succeeds because @{term I} has |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
787 |
only been bound to the first member of @{text asms}. This is due to @{method |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
788 |
match} considering @{text "\<lambda>a. A ?x"} and @{text "\<lambda>a. A ?y"} as distinct |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
789 |
terms. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
790 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
791 |
The simplest way to address this is to explicitly disallow term bindings |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
792 |
which we would consider invalid. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
793 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
794 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
795 |
method abs_used for P = |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
796 |
(match (P) in "\<lambda>a. ?P" \<Rightarrow> \<open>fail\<close> \<bar> _ \<Rightarrow> \<open>-\<close>) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
797 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
798 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
799 |
This method has no effect on the goal state, but instead serves as a filter |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
800 |
on the environment produced from match. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
801 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
802 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
803 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
804 |
section \<open>Uncurrying\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
805 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
806 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
807 |
The @{method match} method is not aware of the logical content of match |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
808 |
targets. Each pattern is simply matched against the shallow structure of a |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
809 |
fact or term. Most facts are in \emph{normal form}, which curries premises |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
810 |
via meta-implication @{text "_ \<Longrightarrow> _"}. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
811 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
812 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
813 |
lemma |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
814 |
assumes asms: "D \<Longrightarrow> B \<Longrightarrow> C" "D \<Longrightarrow> A" |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
815 |
shows "D \<Longrightarrow> B \<Longrightarrow> C \<and> A" |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
816 |
by (match asms in H: "D \<Longrightarrow> _" (multi) \<Rightarrow> \<open>prop_solver elims: H\<close>) |
61417 | 817 |
|
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
818 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
819 |
For the first member of @{text asms} the dummy pattern successfully matches |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
820 |
against @{term "B \<Longrightarrow> C"} and so the proof is successful. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
821 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
822 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
823 |
lemma |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
824 |
assumes asms: "A \<Longrightarrow> B \<Longrightarrow> C" "D \<Longrightarrow> C" |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
825 |
shows "D \<or> (A \<and> B) \<Longrightarrow> C" |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
826 |
apply (match asms in H: "_ \<Longrightarrow> C" (multi) \<Rightarrow> \<open>prop_solver elims: H\<close>)(*<*)? |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
827 |
apply (prop_solver elims: asms) |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
828 |
done(*>*) |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
829 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
830 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
831 |
This proof will fail to solve the goal. Our match pattern will only match |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
832 |
rules which have a single premise, and conclusion @{term C}, so the first |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
833 |
member of @{text asms} is not bound and thus the proof fails. Matching a |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
834 |
pattern of the form @{term "P \<Longrightarrow> Q"} against this fact will bind @{term "P"} |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
835 |
to @{term "A"} and @{term Q} to @{term "B \<Longrightarrow> C"}. Our pattern, with a |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
836 |
concrete @{term "C"} in the conclusion, will fail to match this fact. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
837 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
838 |
To express our desired match, we may \emph{uncurry} our rules before |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
839 |
matching against them. This forms a meta-conjunction of all premises in a |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
840 |
fact, so that only one implication remains. For example the uncurried |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
841 |
version of @{term "A \<Longrightarrow> B \<Longrightarrow> C"} is @{term "A &&& B \<Longrightarrow> C"}. This will now match |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
842 |
our desired pattern @{text "_ \<Longrightarrow> C"}, and can be \emph{curried} after the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
843 |
match to put it back into normal form. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
844 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
845 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
846 |
lemma |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
847 |
assumes asms: "A \<Longrightarrow> B \<Longrightarrow> C" "D \<Longrightarrow> C" |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
848 |
shows "D \<or> (A \<and> B) \<Longrightarrow> C" |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
849 |
by (match asms [uncurry] in H [curry]: "_ \<Longrightarrow> C" (multi) \<Rightarrow> |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
850 |
\<open>prop_solver elims: H\<close>) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
851 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
852 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
853 |
section \<open>Reverse matching\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
854 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
855 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
856 |
The @{method match} method only attempts to perform matching of the pattern |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
857 |
against the match target. Specifically this means that it will not |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
858 |
instantiate schematic terms in the match target. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
859 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
860 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
861 |
lemma |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
862 |
assumes asms: "\<And>x :: 'a. A x" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
863 |
shows "A y" |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
864 |
apply (match asms in H: "A y" \<Rightarrow> \<open>rule H\<close>)? |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
865 |
apply (match asms in H: P for P \<Rightarrow> |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
866 |
\<open>match ("A y") in P \<Rightarrow> \<open>rule H\<close>\<close>) |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
867 |
done |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
868 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
869 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
870 |
In the first @{method match} we attempt to find a member of @{text asms} |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
871 |
which matches our goal precisely. This fails due to no such member existing. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
872 |
The second match reverses the role of the fact in the match, by first giving |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
873 |
a general pattern @{term P}. This bound pattern is then matched against |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
874 |
@{term "A y"}. In this case, @{term P} is bound to @{text "A ?x"} and so it |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
875 |
successfully matches. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
876 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
877 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
878 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
879 |
section \<open>Type matching\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
880 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
881 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
882 |
The rule instantiation attributes @{attribute "where"} and @{attribute "of"} |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
883 |
attempt to guarantee type-correctness wherever possible. This can require |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
884 |
additional invocations of @{method match} in order to statically ensure that |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
885 |
instantiation will succeed. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
886 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
887 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
888 |
lemma |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
889 |
assumes asms: "\<And>x :: 'a. A x" |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
890 |
shows "A y" |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
891 |
by (match asms in H: "\<And>z :: 'b. P z" for P \<Rightarrow> |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
892 |
\<open>match (y) in "y :: 'b" for y \<Rightarrow> \<open>rule H [where z = y]\<close>\<close>) |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
893 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
894 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
895 |
In this example the type @{text 'b} is matched to @{text 'a}, however |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
896 |
statically they are formally distinct types. The first match binds @{text |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
897 |
'b} while the inner match serves to coerce @{term y} into having the type |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
898 |
@{text 'b}. This allows the rule instantiation to successfully apply. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
899 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
900 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
901 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
902 |
chapter \<open>Method development\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
903 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
904 |
section \<open>Tracing methods\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
905 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
906 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
907 |
Method tracing is supported by auxiliary print methods provided by @{theory |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
908 |
Eisbach_Tools}. These include @{method print_fact}, @{method print_term} and |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
909 |
@{method print_type}. Whenever a print method is evaluated it leaves the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
910 |
goal unchanged and writes its argument as tracing output. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
911 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
912 |
Print methods can be combined with the @{method fail} method to investigate |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
913 |
the backtracking behaviour of a method. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
914 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
915 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
916 |
lemma |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
917 |
assumes asms: A B C D |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
918 |
shows D |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
919 |
apply (match asms in H: _ \<Rightarrow> \<open>print_fact H, fail\<close>)(*<*)? |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
920 |
apply (simp add: asms) |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
921 |
done(*>*) |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
922 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
923 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
924 |
This proof will fail, but the tracing output will show the order that the |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
925 |
assumptions are attempted. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
926 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
927 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
928 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
929 |
section \<open>Integrating with Isabelle/ML\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
930 |
|
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
931 |
subsubsection \<open>Attributes\<close> |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
932 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
933 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
934 |
A custom rule attribute is a simple way to extend the functionality of |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
935 |
Eisbach methods. The dummy rule attribute notation (@{text "[[ _ ]]"}) |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
936 |
invokes the given attribute against a dummy fact and evaluates to the result |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
937 |
of that attribute. When used as a match target, this can serve as an |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
938 |
effective auxiliary function. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
939 |
\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
940 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
941 |
attribute_setup get_split_rule = |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
942 |
\<open>Args.term >> (fn t => |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
943 |
Thm.rule_attribute (fn context => fn _ => |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
944 |
(case get_split_rule (Context.proof_of context) t of |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
945 |
SOME thm => thm |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
946 |
| NONE => Drule.dummy_thm)))\<close> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
947 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
948 |
text \<open> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
949 |
In this example, the new attribute @{attribute get_split_rule} lifts the ML |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
950 |
function of the same name into an attribute. When applied to a case |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
951 |
distinction over a datatype, it retrieves its corresponding split rule. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
952 |
|
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
953 |
We can then integrate this intro a method that applies the split rule, first |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
954 |
matching to ensure that fetching the rule was successful. |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
955 |
\<close> |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
956 |
(*<*)declare TrueI [intros](*>*) |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
957 |
method splits = |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
958 |
(match conclusion in "?P f" for f \<Rightarrow> |
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
959 |
\<open>match [[get_split_rule f]] in U: "(_ :: bool) = _" \<Rightarrow> |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
960 |
\<open>rule U [THEN iffD2]\<close>\<close>) |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
961 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
962 |
lemma "L \<noteq> [] \<Longrightarrow> case L of [] \<Rightarrow> False | _ \<Rightarrow> True" |
60298
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
963 |
apply splits |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
964 |
apply (prop_solver intros: allI) |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
965 |
done |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
966 |
|
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
967 |
text \<open> |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
968 |
Here the new @{method splits} method transforms the goal to use only logical |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
969 |
connectives: @{term "L = [] \<longrightarrow> False \<and> (\<forall>x y. L = x # y \<longrightarrow> True)"}. This goal |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
970 |
is then in a form solvable by @{method prop_solver} when given the universal |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
971 |
quantifier introduction rule @{text allI}. |
7c278b692aae
updated Eisbach manual, using version 3149f9146eb5 of its Bitbucket repository;
wenzelm
parents:
60288
diff
changeset
|
972 |
\<close> |
60288
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
973 |
|
d7f636331176
added Eisbach manual, using version 8845c4cb28b6 of its Bitbucket repository;
wenzelm
parents:
diff
changeset
|
974 |
end |