doc-src/IsarAdvanced/Functions/Thy/document/Functions.tex
changeset 21346 c8aa120fa05d
parent 21212 547224bf9348
child 22065 cdd077905eee
equal deleted inserted replaced
21345:a18e60f597b6 21346:c8aa120fa05d
    40 \isacommand{fun}\isamarkupfalse%
    40 \isacommand{fun}\isamarkupfalse%
    41 \ fib\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ nat{\isachardoublequoteclose}\isanewline
    41 \ fib\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ nat{\isachardoublequoteclose}\isanewline
    42 \isakeyword{where}\isanewline
    42 \isakeyword{where}\isanewline
    43 \ \ {\isachardoublequoteopen}fib\ {\isadigit{0}}\ {\isacharequal}\ {\isadigit{1}}{\isachardoublequoteclose}\isanewline
    43 \ \ {\isachardoublequoteopen}fib\ {\isadigit{0}}\ {\isacharequal}\ {\isadigit{1}}{\isachardoublequoteclose}\isanewline
    44 {\isacharbar}\ {\isachardoublequoteopen}fib\ {\isacharparenleft}Suc\ {\isadigit{0}}{\isacharparenright}\ {\isacharequal}\ {\isadigit{1}}{\isachardoublequoteclose}\isanewline
    44 {\isacharbar}\ {\isachardoublequoteopen}fib\ {\isacharparenleft}Suc\ {\isadigit{0}}{\isacharparenright}\ {\isacharequal}\ {\isadigit{1}}{\isachardoublequoteclose}\isanewline
    45 {\isacharbar}\ {\isachardoublequoteopen}fib\ {\isacharparenleft}Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ fib\ n\ {\isacharplus}\ fib\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isachardoublequoteclose}\isanewline
    45 {\isacharbar}\ {\isachardoublequoteopen}fib\ {\isacharparenleft}Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ fib\ n\ {\isacharplus}\ fib\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isachardoublequoteclose}%
    46 %
       
    47 \isadelimproof
       
    48 %
       
    49 \endisadelimproof
       
    50 %
       
    51 \isatagproof
       
    52 %
       
    53 \endisatagproof
       
    54 {\isafoldproof}%
       
    55 %
       
    56 \isadelimproof
       
    57 %
       
    58 \endisadelimproof
       
    59 %
       
    60 \begin{isamarkuptext}%
    46 \begin{isamarkuptext}%
    61 The function always terminates, since the argument of gets smaller in every
    47 The function always terminates, since the argument of gets smaller in every
    62   recursive call. Termination is an
    48   recursive call. Termination is an
    63   important requirement, since it prevents inconsistencies: From
    49   important requirement, since it prevents inconsistencies: From
    64   the "definition" \isa{f{\isacharparenleft}n{\isacharparenright}\ {\isacharequal}\ f{\isacharparenleft}n{\isacharparenright}\ {\isacharplus}\ {\isadigit{1}}} we could prove 
    50   the "definition" \isa{f{\isacharparenleft}n{\isacharparenright}\ {\isacharequal}\ f{\isacharparenleft}n{\isacharparenright}\ {\isacharplus}\ {\isadigit{1}}} we could prove 
    88 \isacommand{fun}\isamarkupfalse%
    74 \isacommand{fun}\isamarkupfalse%
    89 \ sep\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ list{\isachardoublequoteclose}\isanewline
    75 \ sep\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ list{\isachardoublequoteclose}\isanewline
    90 \isakeyword{where}\isanewline
    76 \isakeyword{where}\isanewline
    91 \ \ {\isachardoublequoteopen}sep\ a\ {\isacharparenleft}x{\isacharhash}y{\isacharhash}xs{\isacharparenright}\ {\isacharequal}\ x\ {\isacharhash}\ a\ {\isacharhash}\ sep\ a\ {\isacharparenleft}y\ {\isacharhash}\ xs{\isacharparenright}{\isachardoublequoteclose}\isanewline
    77 \ \ {\isachardoublequoteopen}sep\ a\ {\isacharparenleft}x{\isacharhash}y{\isacharhash}xs{\isacharparenright}\ {\isacharequal}\ x\ {\isacharhash}\ a\ {\isacharhash}\ sep\ a\ {\isacharparenleft}y\ {\isacharhash}\ xs{\isacharparenright}{\isachardoublequoteclose}\isanewline
    92 {\isacharbar}\ {\isachardoublequoteopen}sep\ a\ xs\ \ \ \ \ \ \ {\isacharequal}\ xs{\isachardoublequoteclose}%
    78 {\isacharbar}\ {\isachardoublequoteopen}sep\ a\ xs\ \ \ \ \ \ \ {\isacharequal}\ xs{\isachardoublequoteclose}%
    93 \isadelimproof
       
    94 %
       
    95 \endisadelimproof
       
    96 %
       
    97 \isatagproof
       
    98 %
       
    99 \endisatagproof
       
   100 {\isafoldproof}%
       
   101 %
       
   102 \isadelimproof
       
   103 %
       
   104 \endisadelimproof
       
   105 %
       
   106 \begin{isamarkuptext}%
    79 \begin{isamarkuptext}%
   107 Overlapping patterns are interpreted as "increments" to what is
    80 Overlapping patterns are interpreted as "increments" to what is
   108   already there: The second equation is only meant for the cases where
    81   already there: The second equation is only meant for the cases where
   109   the first one does not match. Consequently, Isabelle replaces it
    82   the first one does not match. Consequently, Isabelle replaces it
   110   internally by the remaining cases, making the patterns disjoint.
    83   internally by the remaining cases, making the patterns disjoint.
   279   smaller in every step, and that the recursion stops when \isa{i}
   252   smaller in every step, and that the recursion stops when \isa{i}
   280   is greater then \isa{n}. Phrased differently, the expression 
   253   is greater then \isa{n}. Phrased differently, the expression 
   281   \isa{N\ {\isacharplus}\ {\isadigit{1}}\ {\isacharminus}\ i} decreases in every recursive call.
   254   \isa{N\ {\isacharplus}\ {\isadigit{1}}\ {\isacharminus}\ i} decreases in every recursive call.
   282 
   255 
   283   We can use this expression as a measure function to construct a
   256   We can use this expression as a measure function to construct a
   284   wellfounded relation, which is a proof of termination:%
   257   wellfounded relation, which can prove termination.%
   285 \end{isamarkuptext}%
   258 \end{isamarkuptext}%
   286 \isamarkuptrue%
   259 \isamarkuptrue%
   287 \isacommand{termination}\isamarkupfalse%
   260 \isacommand{termination}\isamarkupfalse%
   288 \ \isanewline
   261 \ \isanewline
   289 %
   262 %
   291 \ \ %
   264 \ \ %
   292 \endisadelimproof
   265 \endisadelimproof
   293 %
   266 %
   294 \isatagproof
   267 \isatagproof
   295 \isacommand{by}\isamarkupfalse%
   268 \isacommand{by}\isamarkupfalse%
   296 \ {\isacharparenleft}auto{\isacharunderscore}term\ {\isachardoublequoteopen}measure\ {\isacharparenleft}{\isasymlambda}{\isacharparenleft}i{\isacharcomma}N{\isacharparenright}{\isachardot}\ N\ {\isacharplus}\ {\isadigit{1}}\ {\isacharminus}\ i{\isacharparenright}{\isachardoublequoteclose}{\isacharparenright}%
   269 \ {\isacharparenleft}relation\ {\isachardoublequoteopen}measure\ {\isacharparenleft}{\isasymlambda}{\isacharparenleft}i{\isacharcomma}N{\isacharparenright}{\isachardot}\ N\ {\isacharplus}\ {\isadigit{1}}\ {\isacharminus}\ i{\isacharparenright}{\isachardoublequoteclose}{\isacharparenright}\ auto%
   297 \endisatagproof
   270 \endisatagproof
   298 {\isafoldproof}%
   271 {\isafoldproof}%
   299 %
   272 %
   300 \isadelimproof
   273 \isadelimproof
   301 %
   274 %
   349 \ \ %
   322 \ \ %
   350 \endisadelimproof
   323 \endisadelimproof
   351 %
   324 %
   352 \isatagproof
   325 \isatagproof
   353 \isacommand{by}\isamarkupfalse%
   326 \isacommand{by}\isamarkupfalse%
   354 \ {\isacharparenleft}auto{\isacharunderscore}term\ {\isachardoublequoteopen}measures\ {\isacharbrackleft}{\isasymlambda}{\isacharparenleft}i{\isacharcomma}\ N{\isacharparenright}{\isachardot}\ N{\isacharcomma}\ {\isasymlambda}{\isacharparenleft}i{\isacharcomma}N{\isacharparenright}{\isachardot}\ N\ {\isacharplus}\ {\isadigit{1}}\ {\isacharminus}\ i{\isacharbrackright}{\isachardoublequoteclose}{\isacharparenright}%
   327 \ {\isacharparenleft}relation\ {\isachardoublequoteopen}measures\ {\isacharbrackleft}{\isasymlambda}{\isacharparenleft}i{\isacharcomma}\ N{\isacharparenright}{\isachardot}\ N{\isacharcomma}\ {\isasymlambda}{\isacharparenleft}i{\isacharcomma}N{\isacharparenright}{\isachardot}\ N\ {\isacharplus}\ {\isadigit{1}}\ {\isacharminus}\ i{\isacharbrackright}{\isachardoublequoteclose}{\isacharparenright}\ auto%
   355 \endisatagproof
   328 \endisatagproof
   356 {\isafoldproof}%
   329 {\isafoldproof}%
   357 %
   330 %
   358 \isadelimproof
   331 \isadelimproof
   359 %
   332 %
   366 \begin{isamarkuptext}%
   339 \begin{isamarkuptext}%
   367 If two or more functions call one another mutually, they have to be defined
   340 If two or more functions call one another mutually, they have to be defined
   368   in one step. The simplest example are probably \isa{even} and \isa{odd}:%
   341   in one step. The simplest example are probably \isa{even} and \isa{odd}:%
   369 \end{isamarkuptext}%
   342 \end{isamarkuptext}%
   370 \isamarkuptrue%
   343 \isamarkuptrue%
   371 \isanewline
       
   372 \isacommand{function}\isamarkupfalse%
   344 \isacommand{function}\isamarkupfalse%
   373 \ even\ odd\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\isanewline
   345 \ even\ odd\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\isanewline
   374 \isakeyword{where}\isanewline
   346 \isakeyword{where}\isanewline
   375 \ \ {\isachardoublequoteopen}even\ {\isadigit{0}}\ {\isacharequal}\ True{\isachardoublequoteclose}\isanewline
   347 \ \ {\isachardoublequoteopen}even\ {\isadigit{0}}\ {\isacharequal}\ True{\isachardoublequoteclose}\isanewline
   376 {\isacharbar}\ {\isachardoublequoteopen}odd\ {\isadigit{0}}\ {\isacharequal}\ False{\isachardoublequoteclose}\isanewline
   348 {\isacharbar}\ {\isachardoublequoteopen}odd\ {\isadigit{0}}\ {\isacharequal}\ False{\isachardoublequoteclose}\isanewline
   407 \ \ %
   379 \ \ %
   408 \endisadelimproof
   380 \endisadelimproof
   409 %
   381 %
   410 \isatagproof
   382 \isatagproof
   411 \isacommand{by}\isamarkupfalse%
   383 \isacommand{by}\isamarkupfalse%
   412 \ {\isacharparenleft}auto{\isacharunderscore}term\ {\isachardoublequoteopen}measure\ {\isacharparenleft}sum{\isacharunderscore}case\ {\isacharparenleft}{\isacharpercent}n{\isachardot}\ n{\isacharparenright}\ {\isacharparenleft}{\isacharpercent}n{\isachardot}\ n{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}{\isacharparenright}%
   384 \ {\isacharparenleft}relation\ {\isachardoublequoteopen}measure\ {\isacharparenleft}sum{\isacharunderscore}case\ {\isacharparenleft}{\isacharpercent}n{\isachardot}\ n{\isacharparenright}\ {\isacharparenleft}{\isacharpercent}n{\isachardot}\ n{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}{\isacharparenright}\ auto%
   413 \endisatagproof
   385 \endisatagproof
   414 {\isafoldproof}%
   386 {\isafoldproof}%
   415 %
   387 %
   416 \isadelimproof
   388 \isadelimproof
   417 %
   389 %