doc-src/Exercises/2001/a1/Aufgabe1.thy
author wenzelm
Wed, 09 Jun 2004 18:52:42 +0200
changeset 14898 a25550451b51
parent 13739 f5d0a66c8124
permissions -rw-r--r--
Url.File;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13739
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     1
(*<*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     2
theory Aufgabe1 = Main:
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     3
(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     4
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     5
subsection {* Lists *}
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     6
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     7
text{*
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     8
Define a function @{term replace}, such that @{term"replace x y zs"}
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     9
yields @{term zs} with every occurrence of @{term x} replaced by @{term y}.
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    10
*}
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    11
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    12
consts replace :: "'a \<Rightarrow> 'a \<Rightarrow> 'a list \<Rightarrow> 'a list"
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    13
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    14
text {*
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    15
Prove or disprove (by counter example) the following theorems.
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    16
You may have to prove some lemmas first.
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    17
*};
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    18
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    19
theorem "rev(replace x y zs) = replace x y (rev zs)"
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    20
(*<*)oops(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    21
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    22
theorem "replace x y (replace u v zs) = replace u v (replace x y zs)"
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    23
(*<*)oops(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    24
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    25
theorem "replace y z (replace x y zs) = replace x z zs"
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    26
(*<*)oops(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    27
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    28
text{* Define two functions for removing elements from a list:
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    29
@{term"del1 x xs"} deletes the first occurrence (from the left) of
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    30
@{term x} in @{term xs}, @{term"delall x xs"} all of them.  *}
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    31
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    32
consts del1   :: "'a \<Rightarrow> 'a list \<Rightarrow> 'a list"
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    33
       delall :: "'a \<Rightarrow> 'a list \<Rightarrow> 'a list"
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    34
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    35
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    36
text {*
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    37
Prove or disprove (by counter example) the following theorems.
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    38
*};
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    39
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    40
theorem "del1 x (delall x xs) = delall x xs"
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    41
(*<*)oops(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    42
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    43
theorem "delall x (delall x xs) = delall x xs"
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    44
(*<*)oops(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    45
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    46
theorem "delall x (del1 x xs) = delall x xs"
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    47
(*<*)oops(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    48
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    49
theorem "del1 x (del1 y zs) = del1 y (del1 x zs)"
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    50
(*<*)oops(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    51
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    52
theorem "delall x (del1 y zs) = del1 y (delall x zs)"
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    53
(*<*)oops(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    54
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    55
theorem "delall x (delall y zs) = delall y (delall x zs)"
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    56
(*<*)oops(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    57
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    58
theorem "del1 y (replace x y xs) = del1 x xs"
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    59
(*<*)oops(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    60
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    61
theorem "delall y (replace x y xs) = delall x xs"
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    62
(*<*)oops(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    63
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    64
theorem "replace x y (delall x zs) = delall x zs"
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    65
(*<*)oops(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    66
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    67
theorem "replace x y (delall z zs) = delall z (replace x y zs)"
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    68
(*<*)oops(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    69
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    70
theorem "rev(del1 x xs) = del1 x (rev xs)"
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    71
(*<*)oops(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    72
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    73
theorem "rev(delall x xs) = delall x (rev xs)"
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    74
(*<*)oops(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    75
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    76
(*<*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    77
end
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    78
(*>*)