author | wenzelm |
Thu, 26 Jul 2012 17:16:02 +0200 | |
changeset 48519 | 5deda0549f97 |
parent 46189 | doc-src/TutorialI/Types/document/Pairs.tex@7f6668317e24 |
permissions | -rw-r--r-- |
10560 | 1 |
% |
2 |
\begin{isabellebody}% |
|
3 |
\def\isabellecontext{Pairs}% |
|
17056 | 4 |
% |
5 |
\isadelimtheory |
|
6 |
% |
|
7 |
\endisadelimtheory |
|
8 |
% |
|
9 |
\isatagtheory |
|
10 |
% |
|
11 |
\endisatagtheory |
|
12 |
{\isafoldtheory}% |
|
13 |
% |
|
14 |
\isadelimtheory |
|
15 |
% |
|
16 |
\endisadelimtheory |
|
10560 | 17 |
% |
11428 | 18 |
\isamarkupsection{Pairs and Tuples% |
10560 | 19 |
} |
11866 | 20 |
\isamarkuptrue% |
10560 | 21 |
% |
22 |
\begin{isamarkuptext}% |
|
23 |
\label{sec:products} |
|
11428 | 24 |
Ordered pairs were already introduced in \S\ref{sec:pairs}, but only with a minimal |
10560 | 25 |
repertoire of operations: pairing and the two projections \isa{fst} and |
11149 | 26 |
\isa{snd}. In any non-trivial application of pairs you will find that this |
11494 | 27 |
quickly leads to unreadable nests of projections. This |
28 |
section introduces syntactic sugar to overcome this |
|
10560 | 29 |
problem: pattern matching with tuples.% |
30 |
\end{isamarkuptext}% |
|
11866 | 31 |
\isamarkuptrue% |
10560 | 32 |
% |
10878 | 33 |
\isamarkupsubsection{Pattern Matching with Tuples% |
10560 | 34 |
} |
11866 | 35 |
\isamarkuptrue% |
10560 | 36 |
% |
37 |
\begin{isamarkuptext}% |
|
10878 | 38 |
Tuples may be used as patterns in $\lambda$-abstractions, |
40406 | 39 |
for example \isa{{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}{\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}y{\isaliteral{2C}{\isacharcomma}}z{\isaliteral{29}{\isacharparenright}}{\isaliteral{2E}{\isachardot}}x{\isaliteral{2B}{\isacharplus}}y{\isaliteral{2B}{\isacharplus}}z} and \isa{{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}{\isaliteral{28}{\isacharparenleft}}{\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}y{\isaliteral{29}{\isacharparenright}}{\isaliteral{2C}{\isacharcomma}}z{\isaliteral{29}{\isacharparenright}}{\isaliteral{2E}{\isachardot}}x{\isaliteral{2B}{\isacharplus}}y{\isaliteral{2B}{\isacharplus}}z}. In fact, |
10878 | 40 |
tuple patterns can be used in most variable binding constructs, |
41 |
and they can be nested. Here are |
|
10560 | 42 |
some typical examples: |
43 |
\begin{quote} |
|
40406 | 44 |
\isa{let\ {\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}\ y{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ f\ z\ in\ {\isaliteral{28}{\isacharparenleft}}y{\isaliteral{2C}{\isacharcomma}}\ x{\isaliteral{29}{\isacharparenright}}}\\ |
45 |
\isa{case\ xs\ of\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isadigit{0}}\ {\isaliteral{7C}{\isacharbar}}\ {\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}\ y{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{23}{\isacharhash}}\ zs\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ x\ {\isaliteral{2B}{\isacharplus}}\ y}\\ |
|
46 |
\isa{{\isaliteral{5C3C666F72616C6C3E}{\isasymforall}}{\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}y{\isaliteral{29}{\isacharparenright}}{\isaliteral{5C3C696E3E}{\isasymin}}A{\isaliteral{2E}{\isachardot}}\ x{\isaliteral{3D}{\isacharequal}}y}\\ |
|
47 |
\isa{{\isaliteral{7B}{\isacharbraceleft}}{\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}y{\isaliteral{2C}{\isacharcomma}}z{\isaliteral{29}{\isacharparenright}}{\isaliteral{2E}{\isachardot}}\ x{\isaliteral{3D}{\isacharequal}}z{\isaliteral{7D}{\isacharbraceright}}}\\ |
|
48 |
\isa{{\isaliteral{5C3C556E696F6E3E}{\isasymUnion}}\isaliteral{5C3C5E627375623E}{}\isactrlbsub {\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}\ y{\isaliteral{29}{\isacharparenright}}{\isaliteral{5C3C696E3E}{\isasymin}}A\isaliteral{5C3C5E657375623E}{}\isactrlesub \ {\isaliteral{7B}{\isacharbraceleft}}x\ {\isaliteral{2B}{\isacharplus}}\ y{\isaliteral{7D}{\isacharbraceright}}} |
|
11149 | 49 |
\end{quote} |
10878 | 50 |
The intuitive meanings of these expressions should be obvious. |
10560 | 51 |
Unfortunately, we need to know in more detail what the notation really stands |
10878 | 52 |
for once we have to reason about it. Abstraction |
10560 | 53 |
over pairs and tuples is merely a convenient shorthand for a more complex |
54 |
internal representation. Thus the internal and external form of a term may |
|
55 |
differ, which can affect proofs. If you want to avoid this complication, |
|
40406 | 56 |
stick to \isa{fst} and \isa{snd} and write \isa{{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}p{\isaliteral{2E}{\isachardot}}\ fst\ p\ {\isaliteral{2B}{\isacharplus}}\ snd\ p} |
57 |
instead of \isa{{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}{\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}y{\isaliteral{29}{\isacharparenright}}{\isaliteral{2E}{\isachardot}}\ x{\isaliteral{2B}{\isacharplus}}y}. These terms are distinct even though they |
|
11494 | 58 |
denote the same function. |
10560 | 59 |
|
40406 | 60 |
Internally, \isa{{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}{\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}\ y{\isaliteral{29}{\isacharparenright}}{\isaliteral{2E}{\isachardot}}\ t} becomes \isa{split\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}x\ y{\isaliteral{2E}{\isachardot}}\ t{\isaliteral{29}{\isacharparenright}}}, where |
61 |
\cdx{split} is the uncurrying function of type \isa{{\isaliteral{28}{\isacharparenleft}}{\isaliteral{27}{\isacharprime}}a\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}b\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}c{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{5C3C74696D65733E}{\isasymtimes}}\ {\isaliteral{27}{\isacharprime}}b\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}c} defined as |
|
10560 | 62 |
\begin{center} |
40406 | 63 |
\isa{prod{\isaliteral{5F}{\isacharunderscore}}case\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}c\ p{\isaliteral{2E}{\isachardot}}\ c\ {\isaliteral{28}{\isacharparenleft}}fst\ p{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{28}{\isacharparenleft}}snd\ p{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}} |
64 |
\hfill(\isa{split{\isaliteral{5F}{\isacharunderscore}}def}) |
|
10560 | 65 |
\end{center} |
66 |
Pattern matching in |
|
67 |
other variable binding constructs is translated similarly. Thus we need to |
|
68 |
understand how to reason about such constructs.% |
|
69 |
\end{isamarkuptext}% |
|
11866 | 70 |
\isamarkuptrue% |
10560 | 71 |
% |
10878 | 72 |
\isamarkupsubsection{Theorem Proving% |
10560 | 73 |
} |
11866 | 74 |
\isamarkuptrue% |
10560 | 75 |
% |
76 |
\begin{isamarkuptext}% |
|
40406 | 77 |
The most obvious approach is the brute force expansion of \isa{prod{\isaliteral{5F}{\isacharunderscore}}case}:% |
10560 | 78 |
\end{isamarkuptext}% |
17175 | 79 |
\isamarkuptrue% |
80 |
\isacommand{lemma}\isamarkupfalse% |
|
40406 | 81 |
\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}{\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}y{\isaliteral{29}{\isacharparenright}}{\isaliteral{2E}{\isachardot}}x{\isaliteral{29}{\isacharparenright}}\ p\ {\isaliteral{3D}{\isacharequal}}\ fst\ p{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
17056 | 82 |
% |
83 |
\isadelimproof |
|
84 |
% |
|
85 |
\endisadelimproof |
|
86 |
% |
|
87 |
\isatagproof |
|
17175 | 88 |
\isacommand{by}\isamarkupfalse% |
40406 | 89 |
{\isaliteral{28}{\isacharparenleft}}simp\ add{\isaliteral{3A}{\isacharcolon}}\ split{\isaliteral{5F}{\isacharunderscore}}def{\isaliteral{29}{\isacharparenright}}% |
17056 | 90 |
\endisatagproof |
91 |
{\isafoldproof}% |
|
92 |
% |
|
93 |
\isadelimproof |
|
94 |
% |
|
95 |
\endisadelimproof |
|
11866 | 96 |
% |
10560 | 97 |
\begin{isamarkuptext}% |
27027 | 98 |
\noindent |
40406 | 99 |
This works well if rewriting with \isa{split{\isaliteral{5F}{\isacharunderscore}}def} finishes the |
11149 | 100 |
proof, as it does above. But if it does not, you end up with exactly what |
10560 | 101 |
we are trying to avoid: nests of \isa{fst} and \isa{snd}. Thus this |
102 |
approach is neither elegant nor very practical in large examples, although it |
|
103 |
can be effective in small ones. |
|
104 |
||
11494 | 105 |
If we consider why this lemma presents a problem, |
40406 | 106 |
we realize that we need to replace variable~\isa{p} by some pair \isa{{\isaliteral{28}{\isacharparenleft}}a{\isaliteral{2C}{\isacharcomma}}\ b{\isaliteral{29}{\isacharparenright}}}. Then both sides of the |
11494 | 107 |
equation would simplify to \isa{a} by the simplification rules |
46189
7f6668317e24
updated generated file -- change of printed case syntax probably due to f805747f8571;
wenzelm
parents:
40406
diff
changeset
|
108 |
\isa{{\isaliteral{28}{\isacharparenleft}}case\ {\isaliteral{28}{\isacharparenleft}}a{\isaliteral{2C}{\isacharcomma}}\ b{\isaliteral{29}{\isacharparenright}}\ of\ {\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}\ xa{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ f\ x\ xa{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ f\ a\ b} and \isa{fst\ {\isaliteral{28}{\isacharparenleft}}a{\isaliteral{2C}{\isacharcomma}}\ b{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ a}. |
11494 | 109 |
To reason about tuple patterns requires some way of |
110 |
converting a variable of product type into a pair. |
|
46189
7f6668317e24
updated generated file -- change of printed case syntax probably due to f805747f8571;
wenzelm
parents:
40406
diff
changeset
|
111 |
In case of a subterm of the form \isa{case\ p\ of\ {\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}\ xa{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ f\ x\ xa} this is easy: the split |
40406 | 112 |
rule \isa{split{\isaliteral{5F}{\isacharunderscore}}split} replaces \isa{p} by a pair:% |
11494 | 113 |
\index{*split (method)}% |
10560 | 114 |
\end{isamarkuptext}% |
17175 | 115 |
\isamarkuptrue% |
116 |
\isacommand{lemma}\isamarkupfalse% |
|
40406 | 117 |
\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}{\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}y{\isaliteral{29}{\isacharparenright}}{\isaliteral{2E}{\isachardot}}y{\isaliteral{29}{\isacharparenright}}\ p\ {\isaliteral{3D}{\isacharequal}}\ snd\ p{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
17056 | 118 |
% |
119 |
\isadelimproof |
|
120 |
% |
|
121 |
\endisadelimproof |
|
122 |
% |
|
123 |
\isatagproof |
|
17175 | 124 |
\isacommand{apply}\isamarkupfalse% |
40406 | 125 |
{\isaliteral{28}{\isacharparenleft}}split\ split{\isaliteral{5F}{\isacharunderscore}}split{\isaliteral{29}{\isacharparenright}}% |
16353 | 126 |
\begin{isamarkuptxt}% |
127 |
\begin{isabelle}% |
|
40406 | 128 |
\ {\isadigit{1}}{\isaliteral{2E}{\isachardot}}\ {\isaliteral{5C3C666F72616C6C3E}{\isasymforall}}x\ y{\isaliteral{2E}{\isachardot}}\ p\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}\ y{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C6C6F6E6772696768746172726F773E}{\isasymlongrightarrow}}\ y\ {\isaliteral{3D}{\isacharequal}}\ snd\ p% |
16353 | 129 |
\end{isabelle} |
130 |
This subgoal is easily proved by simplification. Thus we could have combined |
|
131 |
simplification and splitting in one command that proves the goal outright:% |
|
132 |
\end{isamarkuptxt}% |
|
17175 | 133 |
\isamarkuptrue% |
17056 | 134 |
% |
135 |
\endisatagproof |
|
136 |
{\isafoldproof}% |
|
137 |
% |
|
138 |
\isadelimproof |
|
139 |
% |
|
140 |
\endisadelimproof |
|
17175 | 141 |
% |
142 |
\isadelimproof |
|
143 |
% |
|
144 |
\endisadelimproof |
|
145 |
% |
|
146 |
\isatagproof |
|
147 |
\isacommand{by}\isamarkupfalse% |
|
40406 | 148 |
{\isaliteral{28}{\isacharparenleft}}simp\ split{\isaliteral{3A}{\isacharcolon}}\ split{\isaliteral{5F}{\isacharunderscore}}split{\isaliteral{29}{\isacharparenright}}% |
17175 | 149 |
\endisatagproof |
150 |
{\isafoldproof}% |
|
151 |
% |
|
152 |
\isadelimproof |
|
153 |
% |
|
154 |
\endisadelimproof |
|
155 |
% |
|
156 |
\begin{isamarkuptext}% |
|
157 |
Let us look at a second example:% |
|
158 |
\end{isamarkuptext}% |
|
159 |
\isamarkuptrue% |
|
160 |
\isacommand{lemma}\isamarkupfalse% |
|
40406 | 161 |
\ {\isaliteral{22}{\isachardoublequoteopen}}let\ {\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}y{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ p\ in\ fst\ p\ {\isaliteral{3D}{\isacharequal}}\ x{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
17056 | 162 |
% |
163 |
\isadelimproof |
|
164 |
% |
|
165 |
\endisadelimproof |
|
166 |
% |
|
167 |
\isatagproof |
|
17175 | 168 |
\isacommand{apply}\isamarkupfalse% |
40406 | 169 |
{\isaliteral{28}{\isacharparenleft}}simp\ only{\isaliteral{3A}{\isacharcolon}}\ Let{\isaliteral{5F}{\isacharunderscore}}def{\isaliteral{29}{\isacharparenright}}% |
17175 | 170 |
\begin{isamarkuptxt}% |
171 |
\begin{isabelle}% |
|
40406 | 172 |
\ {\isadigit{1}}{\isaliteral{2E}{\isachardot}}\ case\ p\ of\ {\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}\ y{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ fst\ p\ {\isaliteral{3D}{\isacharequal}}\ x% |
17175 | 173 |
\end{isabelle} |
174 |
A paired \isa{let} reduces to a paired $\lambda$-abstraction, which |
|
175 |
can be split as above. The same is true for paired set comprehension:% |
|
176 |
\end{isamarkuptxt}% |
|
177 |
\isamarkuptrue% |
|
178 |
% |
|
179 |
\endisatagproof |
|
180 |
{\isafoldproof}% |
|
181 |
% |
|
182 |
\isadelimproof |
|
16353 | 183 |
% |
17175 | 184 |
\endisadelimproof |
185 |
\isacommand{lemma}\isamarkupfalse% |
|
40406 | 186 |
\ {\isaliteral{22}{\isachardoublequoteopen}}p\ {\isaliteral{5C3C696E3E}{\isasymin}}\ {\isaliteral{7B}{\isacharbraceleft}}{\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}y{\isaliteral{29}{\isacharparenright}}{\isaliteral{2E}{\isachardot}}\ x{\isaliteral{3D}{\isacharequal}}y{\isaliteral{7D}{\isacharbraceright}}\ {\isaliteral{5C3C6C6F6E6772696768746172726F773E}{\isasymlongrightarrow}}\ fst\ p\ {\isaliteral{3D}{\isacharequal}}\ snd\ p{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
17175 | 187 |
% |
188 |
\isadelimproof |
|
189 |
% |
|
190 |
\endisadelimproof |
|
191 |
% |
|
192 |
\isatagproof |
|
193 |
\isacommand{apply}\isamarkupfalse% |
|
194 |
\ simp% |
|
16353 | 195 |
\begin{isamarkuptxt}% |
196 |
\begin{isabelle}% |
|
46189
7f6668317e24
updated generated file -- change of printed case syntax probably due to f805747f8571;
wenzelm
parents:
40406
diff
changeset
|
197 |
\ {\isadigit{1}}{\isaliteral{2E}{\isachardot}}\ {\isaliteral{28}{\isacharparenleft}}case\ p\ of\ {\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}\ xa{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ x\ {\isaliteral{3D}{\isacharequal}}\ xa{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C6C6F6E6772696768746172726F773E}{\isasymlongrightarrow}}\ fst\ p\ {\isaliteral{3D}{\isacharequal}}\ snd\ p% |
16353 | 198 |
\end{isabelle} |
40406 | 199 |
Again, simplification produces a term suitable for \isa{split{\isaliteral{5F}{\isacharunderscore}}split} |
16353 | 200 |
as above. If you are worried about the strange form of the premise: |
40406 | 201 |
\isa{split\ {\isaliteral{28}{\isacharparenleft}}op\ {\isaliteral{3D}{\isacharequal}}{\isaliteral{29}{\isacharparenright}}} is short for \isa{{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}{\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}\ y{\isaliteral{29}{\isacharparenright}}{\isaliteral{2E}{\isachardot}}\ x\ {\isaliteral{3D}{\isacharequal}}\ y}. |
16353 | 202 |
The same proof procedure works for% |
203 |
\end{isamarkuptxt}% |
|
17175 | 204 |
\isamarkuptrue% |
17056 | 205 |
% |
206 |
\endisatagproof |
|
207 |
{\isafoldproof}% |
|
208 |
% |
|
209 |
\isadelimproof |
|
210 |
% |
|
211 |
\endisadelimproof |
|
17175 | 212 |
\isacommand{lemma}\isamarkupfalse% |
40406 | 213 |
\ {\isaliteral{22}{\isachardoublequoteopen}}p\ {\isaliteral{5C3C696E3E}{\isasymin}}\ {\isaliteral{7B}{\isacharbraceleft}}{\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}y{\isaliteral{29}{\isacharparenright}}{\isaliteral{2E}{\isachardot}}\ x{\isaliteral{3D}{\isacharequal}}y{\isaliteral{7D}{\isacharbraceright}}\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ fst\ p\ {\isaliteral{3D}{\isacharequal}}\ snd\ p{\isaliteral{22}{\isachardoublequoteclose}}% |
17056 | 214 |
\isadelimproof |
215 |
% |
|
216 |
\endisadelimproof |
|
217 |
% |
|
218 |
\isatagproof |
|
16353 | 219 |
% |
220 |
\begin{isamarkuptxt}% |
|
221 |
\noindent |
|
40406 | 222 |
except that we now have to use \isa{split{\isaliteral{5F}{\isacharunderscore}}split{\isaliteral{5F}{\isacharunderscore}}asm}, because |
223 |
\isa{prod{\isaliteral{5F}{\isacharunderscore}}case} occurs in the assumptions. |
|
16353 | 224 |
|
40406 | 225 |
However, splitting \isa{prod{\isaliteral{5F}{\isacharunderscore}}case} is not always a solution, as no \isa{prod{\isaliteral{5F}{\isacharunderscore}}case} |
16353 | 226 |
may be present in the goal. Consider the following function:% |
227 |
\end{isamarkuptxt}% |
|
17175 | 228 |
\isamarkuptrue% |
17056 | 229 |
% |
230 |
\endisatagproof |
|
231 |
{\isafoldproof}% |
|
232 |
% |
|
233 |
\isadelimproof |
|
234 |
% |
|
235 |
\endisadelimproof |
|
17175 | 236 |
\isacommand{primrec}\isamarkupfalse% |
40406 | 237 |
\ swap\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{27}{\isacharprime}}a\ {\isaliteral{5C3C74696D65733E}{\isasymtimes}}\ {\isaliteral{27}{\isacharprime}}b\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}b\ {\isaliteral{5C3C74696D65733E}{\isasymtimes}}\ {\isaliteral{27}{\isacharprime}}a{\isaliteral{22}{\isachardoublequoteclose}}\ \isakeyword{where}\ {\isaliteral{22}{\isachardoublequoteopen}}swap\ {\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}y{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}y{\isaliteral{2C}{\isacharcomma}}x{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}% |
10560 | 238 |
\begin{isamarkuptext}% |
239 |
\noindent |
|
240 |
Note that the above \isacommand{primrec} definition is admissible |
|
40406 | 241 |
because \isa{{\isaliteral{5C3C74696D65733E}{\isasymtimes}}} is a datatype. When we now try to prove% |
10560 | 242 |
\end{isamarkuptext}% |
17175 | 243 |
\isamarkuptrue% |
244 |
\isacommand{lemma}\isamarkupfalse% |
|
40406 | 245 |
\ {\isaliteral{22}{\isachardoublequoteopen}}swap{\isaliteral{28}{\isacharparenleft}}swap\ p{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ p{\isaliteral{22}{\isachardoublequoteclose}}% |
17056 | 246 |
\isadelimproof |
247 |
% |
|
248 |
\endisadelimproof |
|
249 |
% |
|
250 |
\isatagproof |
|
16353 | 251 |
% |
252 |
\begin{isamarkuptxt}% |
|
253 |
\noindent |
|
27027 | 254 |
simplification will do nothing, because the defining equation for |
255 |
\isa{swap} expects a pair. Again, we need to turn \isa{p} |
|
40406 | 256 |
into a pair first, but this time there is no \isa{prod{\isaliteral{5F}{\isacharunderscore}}case} in sight. |
27027 | 257 |
The only thing we can do is to split the term by hand:% |
16353 | 258 |
\end{isamarkuptxt}% |
17175 | 259 |
\isamarkuptrue% |
260 |
\isacommand{apply}\isamarkupfalse% |
|
40406 | 261 |
{\isaliteral{28}{\isacharparenleft}}case{\isaliteral{5F}{\isacharunderscore}}tac\ p{\isaliteral{29}{\isacharparenright}}% |
16353 | 262 |
\begin{isamarkuptxt}% |
263 |
\noindent |
|
264 |
\begin{isabelle}% |
|
40406 | 265 |
\ {\isadigit{1}}{\isaliteral{2E}{\isachardot}}\ {\isaliteral{5C3C416E643E}{\isasymAnd}}a\ b{\isaliteral{2E}{\isachardot}}\ p\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}a{\isaliteral{2C}{\isacharcomma}}\ b{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ swap\ {\isaliteral{28}{\isacharparenleft}}swap\ p{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ p% |
16353 | 266 |
\end{isabelle} |
40406 | 267 |
Again, \methdx{case_tac} is applicable because \isa{{\isaliteral{5C3C74696D65733E}{\isasymtimes}}} is a datatype. |
16353 | 268 |
The subgoal is easily proved by \isa{simp}. |
269 |
||
40406 | 270 |
Splitting by \isa{case{\isaliteral{5F}{\isacharunderscore}}tac} also solves the previous examples and may thus |
16353 | 271 |
appear preferable to the more arcane methods introduced first. However, see |
40406 | 272 |
the warning about \isa{case{\isaliteral{5F}{\isacharunderscore}}tac} in \S\ref{sec:struct-ind-case}. |
16353 | 273 |
|
40406 | 274 |
Alternatively, you can split \emph{all} \isa{{\isaliteral{5C3C416E643E}{\isasymAnd}}}-quantified variables |
275 |
in a goal with the rewrite rule \isa{split{\isaliteral{5F}{\isacharunderscore}}paired{\isaliteral{5F}{\isacharunderscore}}all}:% |
|
16353 | 276 |
\end{isamarkuptxt}% |
17175 | 277 |
\isamarkuptrue% |
17056 | 278 |
% |
279 |
\endisatagproof |
|
280 |
{\isafoldproof}% |
|
281 |
% |
|
282 |
\isadelimproof |
|
283 |
% |
|
284 |
\endisadelimproof |
|
17175 | 285 |
\isacommand{lemma}\isamarkupfalse% |
40406 | 286 |
\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{5C3C416E643E}{\isasymAnd}}p\ q{\isaliteral{2E}{\isachardot}}\ swap{\isaliteral{28}{\isacharparenleft}}swap\ p{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ q\ {\isaliteral{5C3C6C6F6E6772696768746172726F773E}{\isasymlongrightarrow}}\ p\ {\isaliteral{3D}{\isacharequal}}\ q{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
17056 | 287 |
% |
288 |
\isadelimproof |
|
289 |
% |
|
290 |
\endisadelimproof |
|
291 |
% |
|
292 |
\isatagproof |
|
17175 | 293 |
\isacommand{apply}\isamarkupfalse% |
40406 | 294 |
{\isaliteral{28}{\isacharparenleft}}simp\ only{\isaliteral{3A}{\isacharcolon}}\ split{\isaliteral{5F}{\isacharunderscore}}paired{\isaliteral{5F}{\isacharunderscore}}all{\isaliteral{29}{\isacharparenright}}% |
16353 | 295 |
\begin{isamarkuptxt}% |
296 |
\noindent |
|
297 |
\begin{isabelle}% |
|
40406 | 298 |
\ {\isadigit{1}}{\isaliteral{2E}{\isachardot}}\ {\isaliteral{5C3C416E643E}{\isasymAnd}}a\ b\ aa\ ba{\isaliteral{2E}{\isachardot}}\ swap\ {\isaliteral{28}{\isacharparenleft}}swap\ {\isaliteral{28}{\isacharparenleft}}a{\isaliteral{2C}{\isacharcomma}}\ b{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}aa{\isaliteral{2C}{\isacharcomma}}\ ba{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C6C6F6E6772696768746172726F773E}{\isasymlongrightarrow}}\ {\isaliteral{28}{\isacharparenleft}}a{\isaliteral{2C}{\isacharcomma}}\ b{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}aa{\isaliteral{2C}{\isacharcomma}}\ ba{\isaliteral{29}{\isacharparenright}}% |
16353 | 299 |
\end{isabelle}% |
300 |
\end{isamarkuptxt}% |
|
17175 | 301 |
\isamarkuptrue% |
302 |
\isacommand{apply}\isamarkupfalse% |
|
303 |
\ simp\isanewline |
|
304 |
\isacommand{done}\isamarkupfalse% |
|
305 |
% |
|
17056 | 306 |
\endisatagproof |
307 |
{\isafoldproof}% |
|
308 |
% |
|
309 |
\isadelimproof |
|
310 |
% |
|
311 |
\endisadelimproof |
|
11866 | 312 |
% |
10560 | 313 |
\begin{isamarkuptext}% |
314 |
\noindent |
|
40406 | 315 |
Note that we have intentionally included only \isa{split{\isaliteral{5F}{\isacharunderscore}}paired{\isaliteral{5F}{\isacharunderscore}}all} |
11494 | 316 |
in the first simplification step, and then we simplify again. |
317 |
This time the reason was not merely |
|
10560 | 318 |
pedagogical: |
40406 | 319 |
\isa{split{\isaliteral{5F}{\isacharunderscore}}paired{\isaliteral{5F}{\isacharunderscore}}all} may interfere with other functions |
11494 | 320 |
of the simplifier. |
321 |
The following command could fail (here it does not) |
|
322 |
where two separate \isa{simp} applications succeed.% |
|
10560 | 323 |
\end{isamarkuptext}% |
17175 | 324 |
\isamarkuptrue% |
17056 | 325 |
% |
326 |
\isadelimproof |
|
327 |
% |
|
328 |
\endisadelimproof |
|
329 |
% |
|
330 |
\isatagproof |
|
17175 | 331 |
\isacommand{apply}\isamarkupfalse% |
40406 | 332 |
{\isaliteral{28}{\isacharparenleft}}simp\ add{\isaliteral{3A}{\isacharcolon}}\ split{\isaliteral{5F}{\isacharunderscore}}paired{\isaliteral{5F}{\isacharunderscore}}all{\isaliteral{29}{\isacharparenright}}% |
17056 | 333 |
\endisatagproof |
334 |
{\isafoldproof}% |
|
335 |
% |
|
336 |
\isadelimproof |
|
337 |
% |
|
338 |
\endisadelimproof |
|
11866 | 339 |
% |
10560 | 340 |
\begin{isamarkuptext}% |
341 |
\noindent |
|
40406 | 342 |
Finally, the simplifier automatically splits all \isa{{\isaliteral{5C3C666F72616C6C3E}{\isasymforall}}} and |
343 |
\isa{{\isaliteral{5C3C6578697374733E}{\isasymexists}}}-quantified variables:% |
|
10560 | 344 |
\end{isamarkuptext}% |
17175 | 345 |
\isamarkuptrue% |
346 |
\isacommand{lemma}\isamarkupfalse% |
|
40406 | 347 |
\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{5C3C666F72616C6C3E}{\isasymforall}}p{\isaliteral{2E}{\isachardot}}\ {\isaliteral{5C3C6578697374733E}{\isasymexists}}q{\isaliteral{2E}{\isachardot}}\ swap\ p\ {\isaliteral{3D}{\isacharequal}}\ swap\ q{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
17056 | 348 |
% |
349 |
\isadelimproof |
|
350 |
% |
|
351 |
\endisadelimproof |
|
352 |
% |
|
353 |
\isatagproof |
|
17175 | 354 |
\isacommand{by}\isamarkupfalse% |
355 |
\ simp% |
|
17056 | 356 |
\endisatagproof |
357 |
{\isafoldproof}% |
|
358 |
% |
|
359 |
\isadelimproof |
|
360 |
% |
|
361 |
\endisadelimproof |
|
11866 | 362 |
% |
10560 | 363 |
\begin{isamarkuptext}% |
364 |
\noindent |
|
27027 | 365 |
To turn off this automatic splitting, disable the |
10560 | 366 |
responsible simplification rules: |
367 |
\begin{center} |
|
40406 | 368 |
\isa{{\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C666F72616C6C3E}{\isasymforall}}x{\isaliteral{2E}{\isachardot}}\ P\ x{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C666F72616C6C3E}{\isasymforall}}a\ b{\isaliteral{2E}{\isachardot}}\ P\ {\isaliteral{28}{\isacharparenleft}}a{\isaliteral{2C}{\isacharcomma}}\ b{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}} |
10560 | 369 |
\hfill |
40406 | 370 |
(\isa{split{\isaliteral{5F}{\isacharunderscore}}paired{\isaliteral{5F}{\isacharunderscore}}All})\\ |
371 |
\isa{{\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C6578697374733E}{\isasymexists}}x{\isaliteral{2E}{\isachardot}}\ P\ x{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C6578697374733E}{\isasymexists}}a\ b{\isaliteral{2E}{\isachardot}}\ P\ {\isaliteral{28}{\isacharparenleft}}a{\isaliteral{2C}{\isacharcomma}}\ b{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}} |
|
10560 | 372 |
\hfill |
40406 | 373 |
(\isa{split{\isaliteral{5F}{\isacharunderscore}}paired{\isaliteral{5F}{\isacharunderscore}}Ex}) |
10560 | 374 |
\end{center}% |
375 |
\end{isamarkuptext}% |
|
17175 | 376 |
\isamarkuptrue% |
17056 | 377 |
% |
378 |
\isadelimtheory |
|
379 |
% |
|
380 |
\endisadelimtheory |
|
381 |
% |
|
382 |
\isatagtheory |
|
383 |
% |
|
384 |
\endisatagtheory |
|
385 |
{\isafoldtheory}% |
|
386 |
% |
|
387 |
\isadelimtheory |
|
388 |
% |
|
389 |
\endisadelimtheory |
|
10560 | 390 |
\end{isabellebody}% |
391 |
%%% Local Variables: |
|
392 |
%%% mode: latex |
|
393 |
%%% TeX-master: "root" |
|
394 |
%%% End: |