| 
13739
 | 
     1  | 
(*<*)
  | 
| 
 | 
     2  | 
theory Arithmetic = Main:;
  | 
| 
 | 
     3  | 
(*>*)
  | 
| 
 | 
     4  | 
  | 
| 
 | 
     5  | 
subsection  {* Arithmetic *}
 | 
| 
 | 
     6  | 
  | 
| 
 | 
     7  | 
subsubsection {* Power *};
 | 
| 
 | 
     8  | 
  | 
| 
 | 
     9  | 
text {* Define a primitive recursive function $pow~x~n$ that
 | 
| 
 | 
    10  | 
computes $x^n$ on natural numbers.  *};
  | 
| 
 | 
    11  | 
  | 
| 
 | 
    12  | 
consts
  | 
| 
 | 
    13  | 
  pow :: "nat => nat => nat";
  | 
| 
 | 
    14  | 
  | 
| 
 | 
    15  | 
text {*
 | 
| 
 | 
    16  | 
Prove the well known equation $x^{m \cdot n} = (x^m)^n$:
 | 
| 
 | 
    17  | 
*};
  | 
| 
 | 
    18  | 
  | 
| 
 | 
    19  | 
theorem pow_mult: "pow x (m * n) = pow (pow x m) n";
  | 
| 
 | 
    20  | 
(*<*)oops(*>*)
  | 
| 
 | 
    21  | 
  | 
| 
 | 
    22  | 
text {* Hint: prove a suitable lemma first.  If you need to appeal to
 | 
| 
 | 
    23  | 
associativity and commutativity of multiplication: the corresponding
  | 
| 
 | 
    24  | 
simplification rules are named @{text mult_ac}.  *}
 | 
| 
 | 
    25  | 
  | 
| 
 | 
    26  | 
subsubsection {* Summation *}
 | 
| 
 | 
    27  | 
  | 
| 
 | 
    28  | 
text {*
 | 
| 
 | 
    29  | 
Define a (primitive recursive) function $sum~ns$ that sums a list
  | 
| 
 | 
    30  | 
of natural numbers: $sum [n_1, \dots, n_k] = n_1 + \cdots + n_k$.
  | 
| 
 | 
    31  | 
*}
  | 
| 
 | 
    32  | 
  | 
| 
 | 
    33  | 
consts
  | 
| 
 | 
    34  | 
  sum :: "nat list => nat";
  | 
| 
 | 
    35  | 
  | 
| 
 | 
    36  | 
text {*
 | 
| 
 | 
    37  | 
Show that $sum$ is compatible with $rev$. You may need a lemma.
  | 
| 
 | 
    38  | 
*}
  | 
| 
 | 
    39  | 
  | 
| 
 | 
    40  | 
theorem sum_rev: "sum (rev ns) = sum ns"
  | 
| 
 | 
    41  | 
(*<*)oops(*>*)
  | 
| 
 | 
    42  | 
  | 
| 
 | 
    43  | 
text {*
 | 
| 
 | 
    44  | 
Define a function $Sum~f~k$ that sums $f$ from $0$
  | 
| 
 | 
    45  | 
up to $k-1$: $Sum~f~k = f~0 + \cdots + f(k - 1)$.
  | 
| 
 | 
    46  | 
*};
  | 
| 
 | 
    47  | 
  | 
| 
 | 
    48  | 
consts
  | 
| 
 | 
    49  | 
  Sum :: "(nat => nat) => nat => nat";
  | 
| 
 | 
    50  | 
  | 
| 
 | 
    51  | 
text {*
 | 
| 
 | 
    52  | 
Show the following equations for the pointwise summation of functions.
  | 
| 
 | 
    53  | 
Determine first what the expression @{text whatever} should be.
 | 
| 
 | 
    54  | 
*};
  | 
| 
 | 
    55  | 
  | 
| 
 | 
    56  | 
theorem "Sum (%i. f i + g i) k = Sum f k + Sum g k";
  | 
| 
 | 
    57  | 
(*<*)oops(*>*)
  | 
| 
 | 
    58  | 
  | 
| 
 | 
    59  | 
theorem "Sum f (k + l) = Sum f k + Sum whatever l";
  | 
| 
 | 
    60  | 
(*<*)oops(*>*)
  | 
| 
 | 
    61  | 
  | 
| 
 | 
    62  | 
text {*
 | 
| 
 | 
    63  | 
What is the relationship between @{term sum} and @{text Sum}?
 | 
| 
 | 
    64  | 
Prove the following equation, suitably instantiated.
  | 
| 
 | 
    65  | 
*};
  | 
| 
 | 
    66  | 
  | 
| 
 | 
    67  | 
theorem "Sum f k = sum whatever";
  | 
| 
 | 
    68  | 
(*<*)oops(*>*)
  | 
| 
 | 
    69  | 
  | 
| 
 | 
    70  | 
text {*
 | 
| 
 | 
    71  | 
Hint: familiarize yourself with the predefined functions @{term map} and
 | 
| 
 | 
    72  | 
@{term"[i..j(]"} on lists in theory List.
 | 
| 
 | 
    73  | 
*}
  | 
| 
 | 
    74  | 
  | 
| 
 | 
    75  | 
(*<*)
  | 
| 
 | 
    76  | 
end
  | 
| 
 | 
    77  | 
(*>*)  |