11 methods by combining existing ones with their usual syntax. Specifically it |
11 methods by combining existing ones with their usual syntax. Specifically it |
12 allows compound proof methods to be named, and to extend the name space of |
12 allows compound proof methods to be named, and to extend the name space of |
13 basic methods accordingly. Method definitions may abstract over parameters: |
13 basic methods accordingly. Method definitions may abstract over parameters: |
14 terms, facts, or other methods. |
14 terms, facts, or other methods. |
15 |
15 |
16 \medskip The syntax diagram below refers to some syntactic categories that |
16 \<^medskip> |
|
17 The syntax diagram below refers to some syntactic categories that |
17 are further defined in @{cite "isabelle-isar-ref"}. |
18 are further defined in @{cite "isabelle-isar-ref"}. |
18 |
19 |
19 @{rail \<open> |
20 @{rail \<open> |
20 @@{command method} name args @'=' method |
21 @@{command method} name args @'=' method |
21 ; |
22 ; |
175 Eisbach. It is similar to ``@{text "method\<^sub>1, method\<^sub>2"}'', but @{text |
176 Eisbach. It is similar to ``@{text "method\<^sub>1, method\<^sub>2"}'', but @{text |
176 method\<^sub>2} is invoked on on \emph{all} subgoals that have newly emerged from |
177 method\<^sub>2} is invoked on on \emph{all} subgoals that have newly emerged from |
177 @{text method\<^sub>1}. This is useful to handle cases where the number of |
178 @{text method\<^sub>1}. This is useful to handle cases where the number of |
178 subgoals produced by a method is determined dynamically at run-time. |
179 subgoals produced by a method is determined dynamically at run-time. |
179 \<close> |
180 \<close> |
180 text_raw\<open>\vbox{\<close> |
181 |
181 method conj_with uses rule = |
182 method conj_with uses rule = |
182 (intro conjI ; intro rule) |
183 (intro conjI ; intro rule) |
183 |
184 |
184 lemma |
185 lemma |
185 assumes A: "P" |
186 assumes A: "P" |
186 shows "P \<and> P \<and> P" |
187 shows "P \<and> P \<and> P" |
187 by (conj_with rule: A) |
188 by (conj_with rule: A) |
188 text_raw\<open>}\<close> |
189 |
189 text \<open> |
190 text \<open> |
190 Method definitions may take other methods as arguments, and thus implement |
191 Method definitions may take other methods as arguments, and thus implement |
191 method combinators with prefix syntax. For example, to more usefully exploit |
192 method combinators with prefix syntax. For example, to more usefully exploit |
192 Isabelle's backtracking, the explicit requirement that a method solve all |
193 Isabelle's backtracking, the explicit requirement that a method solve all |
193 produced subgoals is frequently useful. This can easily be written as a |
194 produced subgoals is frequently useful. This can easily be written as a |
241 "intros"}, @{text "elims"}, and @{text "subst"}, are managed by declarations |
242 "intros"}, @{text "elims"}, and @{text "subst"}, are managed by declarations |
242 in the current proof context. They will therefore be passed to any recursive |
243 in the current proof context. They will therefore be passed to any recursive |
243 call to @{method prop_solver} and, more generally, any invocation of a |
244 call to @{method prop_solver} and, more generally, any invocation of a |
244 method which declares these named theorems. |
245 method which declares these named theorems. |
245 |
246 |
246 \medskip After declaring some standard rules to the context, the @{method |
247 \<^medskip> |
|
248 After declaring some standard rules to the context, the @{method |
247 prop_solver} becomes capable of solving non-trivial propositional |
249 prop_solver} becomes capable of solving non-trivial propositional |
248 tautologies.\<close> |
250 tautologies.\<close> |
249 |
251 |
250 lemmas [intros] = |
252 lemmas [intros] = |
251 conjI -- \<open>@{thm conjI}\<close> |
253 conjI -- \<open>@{thm conjI}\<close> |
276 provides more direct access to the higher-order matching facility at the |
278 provides more direct access to the higher-order matching facility at the |
277 core of Isabelle. It is implemented as a separate proof method (in |
279 core of Isabelle. It is implemented as a separate proof method (in |
278 Isabelle/ML), and thus can be directly applied to proofs, however it is most |
280 Isabelle/ML), and thus can be directly applied to proofs, however it is most |
279 useful when applied in the context of writing Eisbach method definitions. |
281 useful when applied in the context of writing Eisbach method definitions. |
280 |
282 |
281 \medskip The syntax diagram below refers to some syntactic categories that |
283 \<^medskip> |
|
284 The syntax diagram below refers to some syntactic categories that |
282 are further defined in @{cite "isabelle-isar-ref"}. |
285 are further defined in @{cite "isabelle-isar-ref"}. |
283 |
286 |
284 @{rail \<open> |
287 @{rail \<open> |
285 @@{method match} kind @'in' (pattern '\<Rightarrow>' cartouche + '\<bar>') |
288 @@{method match} kind @'in' (pattern '\<Rightarrow>' cartouche + '\<bar>') |
286 ; |
289 ; |
361 |
364 |
362 Schematic terms like @{text "?P"} may also be used to specify match |
365 Schematic terms like @{text "?P"} may also be used to specify match |
363 variables, but the result of the match is not bound, and thus cannot be used |
366 variables, but the result of the match is not bound, and thus cannot be used |
364 in the inner method body. |
367 in the inner method body. |
365 |
368 |
366 \medskip In the following example we extract the predicate of an |
369 \<^medskip> |
|
370 In the following example we extract the predicate of an |
367 existentially quantified conclusion in the current subgoal and search the |
371 existentially quantified conclusion in the current subgoal and search the |
368 current premises for a matching fact. If both matches are successful, we |
372 current premises for a matching fact. If both matches are successful, we |
369 then instantiate the existential introduction rule with both the witness and |
373 then instantiate the existential introduction rule with both the witness and |
370 predicate, solving with the matched premise. |
374 predicate, solving with the matched premise. |
371 \<close> |
375 \<close> |
524 requirement that a matching fact must have a schematic variable at that |
528 requirement that a matching fact must have a schematic variable at that |
525 point. This gives a corresponding name to this ``slot'' for the purposes of |
529 point. This gives a corresponding name to this ``slot'' for the purposes of |
526 forming a static closure, allowing the @{attribute "where"} attribute to |
530 forming a static closure, allowing the @{attribute "where"} attribute to |
527 perform an instantiation at run-time. |
531 perform an instantiation at run-time. |
528 \<close> |
532 \<close> |
529 text_raw\<open>\vbox{\<close> |
533 |
530 lemma |
534 lemma |
531 assumes A: "Q \<Longrightarrow> False" |
535 assumes A: "Q \<Longrightarrow> False" |
532 shows "\<not> Q" |
536 shows "\<not> Q" |
533 by (match intros in X: "\<And>P. (P \<Longrightarrow> False) \<Longrightarrow> \<not> P" \<Rightarrow> |
537 by (match intros in X: "\<And>P. (P \<Longrightarrow> False) \<Longrightarrow> \<not> P" \<Rightarrow> |
534 \<open>rule X [where P = Q, OF A]\<close>) |
538 \<open>rule X [where P = Q, OF A]\<close>) |
535 text_raw\<open>}\<close> |
539 |
536 text \<open> |
540 text \<open> |
537 Subgoal focusing converts the outermost quantifiers of premises into |
541 Subgoal focusing converts the outermost quantifiers of premises into |
538 schematics when lifting them to hypothetical facts. This allows us to |
542 schematics when lifting them to hypothetical facts. This allows us to |
539 instantiate them with @{attribute "where"} when using an appropriate match |
543 instantiate them with @{attribute "where"} when using an appropriate match |
540 pattern. |
544 pattern. |
711 |
715 |
712 subsection \<open>Cut\<close> |
716 subsection \<open>Cut\<close> |
713 |
717 |
714 text \<open> |
718 text \<open> |
715 Backtracking may be controlled more precisely by marking individual patterns |
719 Backtracking may be controlled more precisely by marking individual patterns |
716 as \emph{cut}. This causes backtracking to not progress beyond this pattern: |
720 as @{text cut}. This causes backtracking to not progress beyond this pattern: |
717 once a match is found no others will be considered. |
721 once a match is found no others will be considered. |
718 \<close> |
722 \<close> |
719 |
723 |
720 method foo\<^sub>2 = |
724 method foo\<^sub>2 = |
721 (match premises in I: "P \<and> Q" (cut) and I': "P \<longrightarrow> ?U" for P Q \<Rightarrow> |
725 (match premises in I: "P \<and> Q" (cut) and I': "P \<longrightarrow> ?U" for P Q \<Rightarrow> |
804 targets. Each pattern is simply matched against the shallow structure of a |
808 targets. Each pattern is simply matched against the shallow structure of a |
805 fact or term. Most facts are in \emph{normal form}, which curries premises |
809 fact or term. Most facts are in \emph{normal form}, which curries premises |
806 via meta-implication @{text "_ \<Longrightarrow> _"}. |
810 via meta-implication @{text "_ \<Longrightarrow> _"}. |
807 \<close> |
811 \<close> |
808 |
812 |
809 text_raw \<open>\vbox{\<close> |
|
810 lemma |
813 lemma |
811 assumes asms: "D \<Longrightarrow> B \<Longrightarrow> C" "D \<Longrightarrow> A" |
814 assumes asms: "D \<Longrightarrow> B \<Longrightarrow> C" "D \<Longrightarrow> A" |
812 shows "D \<Longrightarrow> B \<Longrightarrow> C \<and> A" |
815 shows "D \<Longrightarrow> B \<Longrightarrow> C \<and> A" |
813 by (match asms in H: "D \<Longrightarrow> _" (multi) \<Rightarrow> \<open>prop_solver elims: H\<close>) |
816 by (match asms in H: "D \<Longrightarrow> _" (multi) \<Rightarrow> \<open>prop_solver elims: H\<close>) |
814 text_raw \<open>}\<close> |
817 |
815 text \<open> |
818 text \<open> |
816 For the first member of @{text asms} the dummy pattern successfully matches |
819 For the first member of @{text asms} the dummy pattern successfully matches |
817 against @{term "B \<Longrightarrow> C"} and so the proof is successful. |
820 against @{term "B \<Longrightarrow> C"} and so the proof is successful. |
818 \<close> |
821 \<close> |
819 |
822 |