doc-src/TutorialI/IsarOverview/Isar/Logic.thy
changeset 13329 53c4ec15cae0
parent 13326 900f220c800d
child 13330 c9e9b6add754
equal deleted inserted replaced
13328:703de709a64b 13329:53c4ec15cae0
    31 \end{center}
    31 \end{center}
    32 It proves \emph{the-assm}~@{text"\<Longrightarrow>"}~\emph{the-concl}.
    32 It proves \emph{the-assm}~@{text"\<Longrightarrow>"}~\emph{the-concl}.
    33 Text starting with ``--'' is a comment.
    33 Text starting with ``--'' is a comment.
    34 
    34 
    35 Note that propositions in \isakeyword{assume} may but need not be
    35 Note that propositions in \isakeyword{assume} may but need not be
    36 separated by \isakeyword{and} whose purpose is to structure the
    36 separated by \isakeyword{and}, whose purpose is to structure the
    37 assumptions into possibly named blocks, for example
    37 assumptions into possibly named blocks. For example in
    38 \begin{center}
    38 \begin{center}
    39 \isakeyword{assume} @{text"A:"} $A_1$ $A_2$ \isakeyword{and} @{text"B:"} $A_3$
    39 \isakeyword{assume} @{text"A:"} $A_1$ $A_2$ \isakeyword{and} @{text"B:"} $A_3$
    40 \isakeyword{and} $A_4$
    40 \isakeyword{and} $A_4$
    41 \end{center}
    41 \end{center}
    42 Here label @{text A} refers to the list of propositions $A_1$ $A_2$ and
    42 label @{text A} refers to the list of propositions $A_1$ $A_2$ and
    43 label @{text B} to $A_3$.
    43 label @{text B} to $A_3$.
    44 *}
    44 *}
    45 
    45 
    46 section{*Logic*}
    46 section{*Logic*}
    47 
    47 
   244     hence "\<not> A \<or> \<not> B" ..
   244     hence "\<not> A \<or> \<not> B" ..
   245     with nn show False ..
   245     with nn show False ..
   246   qed
   246   qed
   247 qed
   247 qed
   248 text{*\noindent Apart from demonstrating the strangeness of classical
   248 text{*\noindent Apart from demonstrating the strangeness of classical
   249 arguments by contradiction, this example also introduces three new constructs:
   249 arguments by contradiction, this example also introduces two new
   250 \begin{itemize}
   250 abbrebviations:
   251 \item \isakeyword{next} deals with multiple subgoals.  When showing
   251 \begin{center}
   252 @{term"A \<and> B"} we need to show both @{term A} and @{term B}.  Each subgoal
   252 \begin{tabular}{lcl}
   253 is proved separately, in \emph{any} order. The individual proofs are
   253 \isakeyword{hence} &=& \isakeyword{then} \isakeyword{have} \\
   254 separated by \isakeyword{next}.
   254 \isakeyword{with}~\emph{facts} &=&
   255 \end{itemize}
   255 \isakeyword{from}~\emph{facts} \isakeyword{and} @{text this}
       
   256 \end{tabular}
       
   257 \end{center}
   256 *}
   258 *}
   257 
   259 
   258 subsection{*Avoiding duplication*}
   260 subsection{*Avoiding duplication*}
   259 
   261 
   260 text{* So far our examples have been a bit unnatural: normally we want to
   262 text{* So far our examples have been a bit unnatural: normally we want to
   267   assume "A \<and> B" thus "A" ..
   269   assume "A \<and> B" thus "A" ..
   268 qed
   270 qed
   269 text{*\noindent The \isakeyword{proof} always works on the conclusion,
   271 text{*\noindent The \isakeyword{proof} always works on the conclusion,
   270 @{prop"B \<and> A"} in our case, thus selecting $\land$-introduction. Hence
   272 @{prop"B \<and> A"} in our case, thus selecting $\land$-introduction. Hence
   271 we must show @{prop B} and @{prop A}; both are proved by
   273 we must show @{prop B} and @{prop A}; both are proved by
   272 $\land$-elimination.
   274 $\land$-elimination and the proofs are separated by \isakeyword{next}:
       
   275 \begin{description}
       
   276 \item[\isakeyword{next}] deals with multiple subgoals. For example,
       
   277 when showing @{term"A \<and> B"} we need to show both @{term A} and @{term
       
   278 B}.  Each subgoal is proved separately, in \emph{any} order. The
       
   279 individual proofs are separated by \isakeyword{next}.
       
   280 \end{description}
   273 
   281 
   274 This is all very well as long as formulae are small. Let us now look at some
   282 This is all very well as long as formulae are small. Let us now look at some
   275 devices to avoid repeating (possibly large) formulae. A very general method
   283 devices to avoid repeating (possibly large) formulae. A very general method
   276 is pattern matching: *}
   284 is pattern matching: *}
   277 
   285 
   382 of concluding $P(x)$ from $\exists x. P(x)$, while carefully introducing $x$
   390 of concluding $P(x)$ from $\exists x. P(x)$, while carefully introducing $x$
   383 as a new local variable.  Technically, \isakeyword{obtain} is similar to
   391 as a new local variable.  Technically, \isakeyword{obtain} is similar to
   384 \isakeyword{fix} and \isakeyword{assume} together with a soundness proof of
   392 \isakeyword{fix} and \isakeyword{assume} together with a soundness proof of
   385 the elimination involved.
   393 the elimination involved.
   386 
   394 
   387 Here is a proof of a well known tautology which employs another useful
   395 Here is a proof of a well known tautology.
   388 abbreviation: \isakeyword{hence} abbreviates \isakeyword{from}~@{text
   396 Figure out which rule is used where!  *}
   389 this}~\isakeyword{have}.  Figure out which rule is used where!  *}
       
   390 
   397 
   391 lemma assumes ex: "\<exists>x. \<forall>y. P x y" shows "\<forall>y. \<exists>x. P x y"
   398 lemma assumes ex: "\<exists>x. \<forall>y. P x y" shows "\<forall>y. \<exists>x. P x y"
   392 proof
   399 proof
   393   fix y
   400   fix y
   394   from ex obtain x where "\<forall>y. P x y" ..
   401   from ex obtain x where "\<forall>y. P x y" ..
   416       with fy show False by blast
   423       with fy show False by blast
   417     qed
   424     qed
   418   qed
   425   qed
   419 qed
   426 qed
   420 text{*\noindent
   427 text{*\noindent
   421 For a start, the example demonstrates three new language elements:
   428 For a start, the example demonstrates two new constructs:
   422 \begin{itemize}
   429 \begin{itemize}
   423 \item \isakeyword{let} introduces an abbreviation for a term, in our case
   430 \item \isakeyword{let} introduces an abbreviation for a term, in our case
   424 the witness for the claim, because the term occurs multiple times in the proof.
   431 the witness for the claim, because the term occurs multiple times in the proof.
   425 \item Proof by @{text"cases"} starts a proof by cases. Note that it remains
   432 \item Proof by @{text"cases"} starts a proof by cases. Note that it remains
   426 implicit what the two cases are: it is merely expected that the two subproofs
   433 implicit what the two cases are: it is merely expected that the two subproofs
   427 prove @{prop"P \<Longrightarrow> Q"} and @{prop"\<not>P \<Longrightarrow> Q"} for suitable @{term P} and
   434 prove @{prop"P \<Longrightarrow> Q"} and @{prop"\<not>P \<Longrightarrow> Q"} for suitable @{term P} and
   428 @{term Q}.
   435 @{term Q}.
   429 \item \isakeyword{with} is an abbreviation:
       
   430 \begin{center}
       
   431 \isakeyword{with}~\emph{facts} \quad = \quad
       
   432 \isakeyword{from}~\emph{facts} \isakeyword{and} @{text this}
       
   433 \end{center}
       
   434 \end{itemize}
   436 \end{itemize}
   435 If you wonder how to \isakeyword{obtain} @{term y}:
   437 If you wonder how to \isakeyword{obtain} @{term y}:
   436 via the predefined elimination rule @{thm rangeE[no_vars]}.
   438 via the predefined elimination rule @{thm rangeE[no_vars]}.
   437 
   439 
   438 Method @{text blast} is used because the contradiction does not follow easily
   440 Method @{text blast} is used because the contradiction does not follow easily
   697 ?thesis} but @{text"B \<Longrightarrow> ?thesis"}, just as in the previous proof. The
   699 ?thesis} but @{text"B \<Longrightarrow> ?thesis"}, just as in the previous proof. The
   698 base case is trivial. In the assumptions for the induction step we can
   700 base case is trivial. In the assumptions for the induction step we can
   699 see very clearly how things fit together and permit ourselves the
   701 see very clearly how things fit together and permit ourselves the
   700 obvious forward step @{text"IH[OF B]"}. *}
   702 obvious forward step @{text"IH[OF B]"}. *}
   701 
   703 
       
   704 consts rot :: "'a list \<Rightarrow> 'a list"
       
   705 recdef rot "measure length"
       
   706 "rot [] = []"
       
   707 "rot [x] = [x]"
       
   708 "rot (x#y#zs) = y # rot(x#zs)"
       
   709 
       
   710 lemma "length(rot xs) = length xs" (is "?P xs")
       
   711 proof (induct xs rule: rot.induct)
       
   712   show "?P []" by simp
       
   713 next
       
   714   fix x show "?P [x]" by simp
       
   715 next
       
   716   fix x y zs assume "?P (x#zs)"
       
   717   thus "?P (x#y#zs)" by simp
       
   718 qed
       
   719 
   702 (*<*)end(*>*)
   720 (*<*)end(*>*)