thys/MyFirst.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Mon, 06 Oct 2014 15:24:41 +0100
changeset 20 c11651bbebf5
parent 19 66c9c06c0f0e
child 21 893f0314a88b
permissions -rw-r--r--
some small changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     1
theory MyFirst
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     2
imports Main
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     3
begin
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     4
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     5
datatype 'a list = Nil | Cons 'a "'a list"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     6
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     7
fun app :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" where
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     8
"app Nil ys = ys" |
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     9
"app (Cons x xs) ys = Cons x (app xs ys)"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    10
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    11
fun rev :: "'a list \<Rightarrow> 'a list" where
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    12
"rev Nil = Nil" |
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    13
"rev (Cons x xs) = app (rev xs) (Cons x Nil)"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    14
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    15
value "rev(Cons True (Cons False Nil))"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    16
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    17
value "1 + (2::nat)"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    18
value "1 + (2::int)"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    19
value "1 - (2::nat)"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    20
value "1 - (2::int)"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    21
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    22
lemma app_Nil2 [simp]: "app xs Nil = xs"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    23
apply(induction xs)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    24
apply(auto)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    25
done
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    26
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    27
lemma app_assoc [simp]: "app (app xs ys) zs = app xs (app ys zs)"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    28
apply(induction xs)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    29
apply(auto)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    30
done
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    31
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    32
lemma rev_app [simp]: "rev(app xs ys) = app (rev ys) (rev xs)"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    33
apply (induction xs)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    34
apply (auto)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    35
done
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    36
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    37
theorem rev_rev [simp]: "rev(rev xs) = xs"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    38
apply (induction xs)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    39
apply (auto)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    40
done
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    41
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    42
fun add :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    43
"add 0 n = n" |
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    44
"add (Suc m) n = Suc(add m n)"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    45
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    46
lemma add_02: "add m 0 = m"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    47
apply(induction m)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    48
apply(auto)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    49
done
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    50
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    51
value "add 2 3"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    52
20
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    53
16
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents: 15
diff changeset
    54
(**commutative-associative**)
20
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    55
lemma add_04: "add m (add n k) = add (add m n) k"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    56
apply(induct m)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    57
apply(simp_all)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    58
done
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    59
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    60
lemma add_zero: "add n 0 = n"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    61
sorry
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    62
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    63
lemma add_Suc: "add m (Suc n) = Suc (add m n)"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    64
sorry
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    65
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    66
lemma add_comm: "add m n = add n m"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    67
apply(induct m)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    68
apply(simp add: add_zero)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    69
apply(simp add: add_Suc)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    70
done
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    71
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    72
lemma add_odd: "add m (add n k) = add k (add m n)"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    73
apply(subst add_04)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    74
apply(subst (2) add_comm)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    75
apply(simp)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    76
done
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    77
14
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    78
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    79
fun dub :: "nat \<Rightarrow> nat" where
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    80
"dub 0 = 0" |
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    81
"dub m = add m m"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    82
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    83
lemma dub_01: "dub 0 = 0"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    84
apply(induct)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    85
apply(auto)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    86
done
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    87
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    88
lemma dub_02: "dub m = add m m"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    89
apply(induction m)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    90
apply(auto)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    91
done
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    92
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    93
value "dub 2"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    94
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    95
fun trip :: "nat \<Rightarrow> nat" where
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    96
"trip 0 = 0" |
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    97
"trip m = add m (add m m)"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    98
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    99
lemma trip_01: "trip 0 = 0"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   100
apply(induct)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   101
apply(auto)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   102
done
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   103
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   104
lemma trip_02: "trip m = add m (add m m)"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   105
apply(induction m)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   106
apply(auto)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   107
done
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   108
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   109
value "trip 1"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   110
value "trip 2"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   111
20
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   112
fun sum :: "nat \<Rightarrow> nat" where
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   113
  "sum 0 = 0"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   114
| "sum (Suc n) = (Suc n) + sum n"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   115
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   116
function sum1 :: "nat \<Rightarrow> nat" where
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   117
  "sum1 0 = 0"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   118
| "n \<noteq> 0 \<Longrightarrow> sum1 n = n + sum1 (n - 1)"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   119
apply(auto)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   120
done
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   121
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   122
termination sum1
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   123
by (smt2 "termination" diff_less less_than_iff not_gr0 wf_less_than zero_neq_one)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   124
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   125
lemma "sum n = sum1 n"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   126
apply(induct n)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   127
apply(auto)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   128
done
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   129
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   130
lemma "sum n = (\<Sum>i \<le> n. i)"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   131
apply(induct n)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   132
apply(simp_all)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   133
done
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   134
14
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   135
fun mull :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   136
"mull 0 0 = 0" |
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   137
"mull m 0 = 0" |
20
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   138
"mull m 1 = m" | 
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   139
(**"mull m (1::nat) = m" | **)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   140
(**"mull m (suc(0)) = m" | **)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   141
"mull m n = mull m (n-(1::nat))" 
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   142
apply(pat_completeness)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   143
apply(auto)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   144
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   145
done
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   146
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   147
  "mull 0 n = 0"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   148
| "mull (Suc m) n = add n (mull m n)" 
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   149
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   150
lemma test: "mull m n = m * n"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   151
sorry
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   152
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   153
fun poww :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   154
  "poww 0 n = 1"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   155
| "poww (Suc m) n = mull n (poww m n)" 
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   156
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   157
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   158
"mull 0 0 = 0" |
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   159
"mull m 0 = 0" |
15
bdabf71fa35b multiply
fahadausaf <fahad.ausaf@icloud.com>
parents: 14
diff changeset
   160
(**"mull m 1 = m" | **)
17
a5427713eef4 multiply 2
fahadausaf <fahad.ausaf@icloud.com>
parents: 16
diff changeset
   161
(**"mull m (1::nat) = m" | **)
a5427713eef4 multiply 2
fahadausaf <fahad.ausaf@icloud.com>
parents: 16
diff changeset
   162
(**"mull m (suc(0)) = m" | **)
a5427713eef4 multiply 2
fahadausaf <fahad.ausaf@icloud.com>
parents: 16
diff changeset
   163
"mull m n = mull m (n-(1::nat))" 
14
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   164
17
a5427713eef4 multiply 2
fahadausaf <fahad.ausaf@icloud.com>
parents: 16
diff changeset
   165
(**Define a function that counts the
a5427713eef4 multiply 2
fahadausaf <fahad.ausaf@icloud.com>
parents: 16
diff changeset
   166
number of occurrences of an element in a list **)
14
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   167
(**
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   168
fun count :: "'a\<Rightarrow>'a list\<Rightarrow>nat" where
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   169
"count  "
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   170
**)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   171
20
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   172
19
fahadausaf <fahad.ausaf@icloud.com>
parents: 17
diff changeset
   173
(* prove n = n * (n + 1) div 2  *)
14
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   174
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   175
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   176
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   177
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   178
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   179
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   180
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   181
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   182
19
fahadausaf <fahad.ausaf@icloud.com>
parents: 17
diff changeset
   183
fahadausaf <fahad.ausaf@icloud.com>
parents: 17
diff changeset
   184