src/Doc/ProgProve/Bool_nat_list.thy
changeset 52842 3682e1b7ce86
parent 52782 b11d73dbfb76
child 53015 a1119cf551e8
equal deleted inserted replaced
52841:87a66bad0796 52842:3682e1b7ce86
   414 but we do now know what the result is. That is, @{term"hd []"} is not undefined
   414 but we do now know what the result is. That is, @{term"hd []"} is not undefined
   415 but underdefined.
   415 but underdefined.
   416 \fi
   416 \fi
   417 %
   417 %
   418 
   418 
       
   419 From now on lists are always the predefined lists.
       
   420 
       
   421 
   419 \subsection{Exercises}
   422 \subsection{Exercises}
   420 
   423 
   421 \begin{exercise}
   424 \begin{exercise}
   422 Define your own addition, multiplication, and exponentiation functions on type
   425 Start from the definition of @{const add} given above.
   423 @{typ nat}. Prove as many of the standard equational laws as possible, e.g.\
   426 Prove it is associative (@{prop"add (add m n) p = add m (add n p)"})
   424 associativity, commutativity and distributivity.
   427 and commutative (@{prop"add m n = add n m"}). Define a recursive function
       
   428 @{text double} @{text"::"} @{typ"nat \<Rightarrow> nat"} and prove that @{prop"double m = add m m"}.
   425 \end{exercise}
   429 \end{exercise}
   426 
   430 
   427 \begin{exercise}
   431 \begin{exercise}
   428 Define your own sorting function on the predefined lists.
   432 Define a function @{text"count ::"} @{typ"'a \<Rightarrow> 'a list \<Rightarrow> nat"}
   429 Prove that the result is sorted and that every element occurs as many times
   433 that counts the number of occurrences of an element in a list. Prove
   430 in the output as in the input.
   434 @{prop"count x xs \<le> length xs"}.
   431 \end{exercise}
   435 \end{exercise}
       
   436 
       
   437 \begin{exercise}
       
   438 Define a recursive function @{text "snoc ::"} @{typ"'a list \<Rightarrow> 'a \<Rightarrow> 'a list"}
       
   439 that appends an element to the end of a list. Do not use the predefined append
       
   440 operator @{text"@"}. With the help of @{text snoc} define a recursive function
       
   441 @{text "reverse ::"} @{typ"'a list \<Rightarrow> 'a list"} that reverses a list. Do not
       
   442 use the predefined function @{const rev}.
       
   443 Prove @{prop"reverse(reverse xs) = xs"}.
       
   444 \end{exercise}
   432 *}
   445 *}
   433 (*<*)
   446 (*<*)
   434 end
   447 end
   435 (*>*)
   448 (*>*)