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 % |
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 |