doc-src/Exercises/2000/a1/Arithmetic.thy
author berghofe
Tue, 01 Jun 2004 15:02:05 +0200
changeset 14861 ca5cae7fb65a
parent 13739 f5d0a66c8124
permissions -rw-r--r--
Removed ~10000 hack in function idx that can lead to inconsistencies when unifying terms with a large number of abstractions.
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 Arithmetic = 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  {* Arithmetic *}
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     6
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     7
subsubsection {* Power *};
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     8
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     9
text {* Define a primitive recursive function $pow~x~n$ that
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    10
computes $x^n$ on natural numbers.  *};
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    11
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    12
consts
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    13
  pow :: "nat => nat => nat";
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    14
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    15
text {*
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    16
Prove the well known equation $x^{m \cdot n} = (x^m)^n$:
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 pow_mult: "pow x (m * n) = pow (pow x m) n";
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
text {* Hint: prove a suitable lemma first.  If you need to appeal to
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    23
associativity and commutativity of multiplication: the corresponding
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    24
simplification rules are named @{text mult_ac}.  *}
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    25
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    26
subsubsection {* Summation *}
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    27
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    28
text {*
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    29
Define a (primitive recursive) function $sum~ns$ that sums a list
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    30
of natural numbers: $sum [n_1, \dots, n_k] = n_1 + \cdots + n_k$.
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    31
*}
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    32
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    33
consts
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    34
  sum :: "nat list => nat";
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
Show that $sum$ is compatible with $rev$. You may need a lemma.
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 sum_rev: "sum (rev ns) = sum ns"
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
text {*
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    44
Define a function $Sum~f~k$ that sums $f$ from $0$
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    45
up to $k-1$: $Sum~f~k = f~0 + \cdots + f(k - 1)$.
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    46
*};
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    47
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    48
consts
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    49
  Sum :: "(nat => nat) => nat => nat";
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    50
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    51
text {*
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    52
Show the following equations for the pointwise summation of functions.
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    53
Determine first what the expression @{text whatever} should be.
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    54
*};
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    55
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    56
theorem "Sum (%i. f i + g i) k = Sum f k + Sum g k";
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    57
(*<*)oops(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    58
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    59
theorem "Sum f (k + l) = Sum f k + Sum whatever l";
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    60
(*<*)oops(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    61
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    62
text {*
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    63
What is the relationship between @{term sum} and @{text Sum}?
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    64
Prove the following equation, suitably instantiated.
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    65
*};
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    66
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    67
theorem "Sum f k = sum whatever";
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
text {*
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    71
Hint: familiarize yourself with the predefined functions @{term map} and
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    72
@{term"[i..j(]"} on lists in theory List.
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    73
*}
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    74
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    75
(*<*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    76
end
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    77
(*>*)