doc-src/TutorialI/Ifexpr/document/Ifexpr.tex
changeset 11456 7eb63f63e6c6
parent 10978 5eebea8f359f
child 11866 fbd097aec213
equal deleted inserted replaced
11455:e07927b980ec 11456:7eb63f63e6c6
     4 %
     4 %
     5 \isamarkupsubsection{Case Study: Boolean Expressions%
     5 \isamarkupsubsection{Case Study: Boolean Expressions%
     6 }
     6 }
     7 %
     7 %
     8 \begin{isamarkuptext}%
     8 \begin{isamarkuptext}%
     9 \label{sec:boolex}
     9 \label{sec:boolex}\index{boolean expressions example|(}
    10 The aim of this case study is twofold: it shows how to model boolean
    10 The aim of this case study is twofold: it shows how to model boolean
    11 expressions and some algorithms for manipulating them, and it demonstrates
    11 expressions and some algorithms for manipulating them, and it demonstrates
    12 the constructs introduced above.%
    12 the constructs introduced above.%
    13 \end{isamarkuptext}%
    13 \end{isamarkuptext}%
    14 %
    14 %
   112 {\isachardoublequote}norm\ {\isacharparenleft}CIF\ b{\isacharparenright}\ \ \ \ {\isacharequal}\ CIF\ b{\isachardoublequote}\isanewline
   112 {\isachardoublequote}norm\ {\isacharparenleft}CIF\ b{\isacharparenright}\ \ \ \ {\isacharequal}\ CIF\ b{\isachardoublequote}\isanewline
   113 {\isachardoublequote}norm\ {\isacharparenleft}VIF\ x{\isacharparenright}\ \ \ \ {\isacharequal}\ VIF\ x{\isachardoublequote}\isanewline
   113 {\isachardoublequote}norm\ {\isacharparenleft}VIF\ x{\isacharparenright}\ \ \ \ {\isacharequal}\ VIF\ x{\isachardoublequote}\isanewline
   114 {\isachardoublequote}norm\ {\isacharparenleft}IF\ b\ t\ e{\isacharparenright}\ {\isacharequal}\ normif\ b\ {\isacharparenleft}norm\ t{\isacharparenright}\ {\isacharparenleft}norm\ e{\isacharparenright}{\isachardoublequote}%
   114 {\isachardoublequote}norm\ {\isacharparenleft}IF\ b\ t\ e{\isacharparenright}\ {\isacharequal}\ normif\ b\ {\isacharparenleft}norm\ t{\isacharparenright}\ {\isacharparenleft}norm\ e{\isacharparenright}{\isachardoublequote}%
   115 \begin{isamarkuptext}%
   115 \begin{isamarkuptext}%
   116 \noindent
   116 \noindent
   117 Their interplay is a bit tricky, and we leave it to the reader to develop an
   117 Their interplay is tricky; we leave it to you to develop an
   118 intuitive understanding. Fortunately, Isabelle can help us to verify that the
   118 intuitive understanding. Fortunately, Isabelle can help us to verify that the
   119 transformation preserves the value of the expression:%
   119 transformation preserves the value of the expression:%
   120 \end{isamarkuptext}%
   120 \end{isamarkuptext}%
   121 \isacommand{theorem}\ {\isachardoublequote}valif\ {\isacharparenleft}norm\ b{\isacharparenright}\ env\ {\isacharequal}\ valif\ b\ env{\isachardoublequote}%
   121 \isacommand{theorem}\ {\isachardoublequote}valif\ {\isacharparenleft}norm\ b{\isacharparenright}\ env\ {\isacharequal}\ valif\ b\ env{\isachardoublequote}%
   122 \begin{isamarkuptext}%
   122 \begin{isamarkuptext}%
   123 \noindent
   123 \noindent
   124 The proof is canonical, provided we first show the following simplification
   124 The proof is canonical, provided we first show the following simplification
   125 lemma (which also helps to understand what \isa{normif} does):%
   125 lemma, which also helps to understand what \isa{normif} does:%
   126 \end{isamarkuptext}%
   126 \end{isamarkuptext}%
   127 \isacommand{lemma}\ {\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\isanewline
   127 \isacommand{lemma}\ {\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\isanewline
   128 \ \ {\isachardoublequote}{\isasymforall}t\ e{\isachardot}\ valif\ {\isacharparenleft}normif\ b\ t\ e{\isacharparenright}\ env\ {\isacharequal}\ valif\ {\isacharparenleft}IF\ b\ t\ e{\isacharparenright}\ env{\isachardoublequote}%
   128 \ \ {\isachardoublequote}{\isasymforall}t\ e{\isachardot}\ valif\ {\isacharparenleft}normif\ b\ t\ e{\isacharparenright}\ env\ {\isacharequal}\ valif\ {\isacharparenleft}IF\ b\ t\ e{\isacharparenright}\ env{\isachardoublequote}%
   129 \begin{isamarkuptext}%
   129 \begin{isamarkuptext}%
   130 \noindent
   130 \noindent
   131 Note that the lemma does not have a name, but is implicitly used in the proof
   131 Note that the lemma does not have a name, but is implicitly used in the proof
   132 of the theorem shown above because of the \isa{{\isacharbrackleft}simp{\isacharbrackright}} attribute.
   132 of the theorem shown above because of the \isa{{\isacharbrackleft}simp{\isacharbrackright}} attribute.
   133 
   133 
   134 But how can we be sure that \isa{norm} really produces a normal form in
   134 But how can we be sure that \isa{norm} really produces a normal form in
   135 the above sense? We define a function that tests If-expressions for normality%
   135 the above sense? We define a function that tests If-expressions for normality:%
   136 \end{isamarkuptext}%
   136 \end{isamarkuptext}%
   137 \isacommand{consts}\ normal\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}ifex\ {\isasymRightarrow}\ bool{\isachardoublequote}\isanewline
   137 \isacommand{consts}\ normal\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}ifex\ {\isasymRightarrow}\ bool{\isachardoublequote}\isanewline
   138 \isacommand{primrec}\isanewline
   138 \isacommand{primrec}\isanewline
   139 {\isachardoublequote}normal{\isacharparenleft}CIF\ b{\isacharparenright}\ {\isacharequal}\ True{\isachardoublequote}\isanewline
   139 {\isachardoublequote}normal{\isacharparenleft}CIF\ b{\isacharparenright}\ {\isacharequal}\ True{\isachardoublequote}\isanewline
   140 {\isachardoublequote}normal{\isacharparenleft}VIF\ x{\isacharparenright}\ {\isacharequal}\ True{\isachardoublequote}\isanewline
   140 {\isachardoublequote}normal{\isacharparenleft}VIF\ x{\isacharparenright}\ {\isacharequal}\ True{\isachardoublequote}\isanewline
   141 {\isachardoublequote}normal{\isacharparenleft}IF\ b\ t\ e{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}normal\ t\ {\isasymand}\ normal\ e\ {\isasymand}\isanewline
   141 {\isachardoublequote}normal{\isacharparenleft}IF\ b\ t\ e{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}normal\ t\ {\isasymand}\ normal\ e\ {\isasymand}\isanewline
   142 \ \ \ \ \ {\isacharparenleft}case\ b\ of\ CIF\ b\ {\isasymRightarrow}\ True\ {\isacharbar}\ VIF\ x\ {\isasymRightarrow}\ True\ {\isacharbar}\ IF\ x\ y\ z\ {\isasymRightarrow}\ False{\isacharparenright}{\isacharparenright}{\isachardoublequote}%
   142 \ \ \ \ \ {\isacharparenleft}case\ b\ of\ CIF\ b\ {\isasymRightarrow}\ True\ {\isacharbar}\ VIF\ x\ {\isasymRightarrow}\ True\ {\isacharbar}\ IF\ x\ y\ z\ {\isasymRightarrow}\ False{\isacharparenright}{\isacharparenright}{\isachardoublequote}%
   143 \begin{isamarkuptext}%
   143 \begin{isamarkuptext}%
   144 \noindent
   144 \noindent
   145 and prove \isa{normal\ {\isacharparenleft}norm\ b{\isacharparenright}}. Of course, this requires a lemma about
   145 Now we prove \isa{normal\ {\isacharparenleft}norm\ b{\isacharparenright}}. Of course, this requires a lemma about
   146 normality of \isa{normif}:%
   146 normality of \isa{normif}:%
   147 \end{isamarkuptext}%
   147 \end{isamarkuptext}%
   148 \isacommand{lemma}{\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}{\isasymforall}t\ e{\isachardot}\ normal{\isacharparenleft}normif\ b\ t\ e{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}normal\ t\ {\isasymand}\ normal\ e{\isacharparenright}{\isachardoublequote}%
   148 \isacommand{lemma}{\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}{\isasymforall}t\ e{\isachardot}\ normal{\isacharparenleft}normif\ b\ t\ e{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}normal\ t\ {\isasymand}\ normal\ e{\isacharparenright}{\isachardoublequote}%
   149 \begin{isamarkuptext}%
   149 \begin{isamarkuptext}%
   150 \medskip
   150 \medskip
   158   We strengthen the definition of a \isa{normal} If-expression as follows:
   158   We strengthen the definition of a \isa{normal} If-expression as follows:
   159   the first argument of all \isa{IF}s must be a variable. Adapt the above
   159   the first argument of all \isa{IF}s must be a variable. Adapt the above
   160   development to this changed requirement. (Hint: you may need to formulate
   160   development to this changed requirement. (Hint: you may need to formulate
   161   some of the goals as implications (\isa{{\isasymlongrightarrow}}) rather than
   161   some of the goals as implications (\isa{{\isasymlongrightarrow}}) rather than
   162   equalities (\isa{{\isacharequal}}).)
   162   equalities (\isa{{\isacharequal}}).)
   163 \end{exercise}%
   163 \end{exercise}
       
   164 \index{boolean expressions example|)}%
   164 \end{isamarkuptext}%
   165 \end{isamarkuptext}%
   165 \end{isabellebody}%
   166 \end{isabellebody}%
   166 %%% Local Variables:
   167 %%% Local Variables:
   167 %%% mode: latex
   168 %%% mode: latex
   168 %%% TeX-master: "root"
   169 %%% TeX-master: "root"