thys/MyFirst.thy
author fahadausaf <fahad.ausaf@icloud.com>
Mon, 06 Oct 2014 16:42:52 +0100
changeset 21 893f0314a88b
parent 20 c11651bbebf5
child 22 fff2b8d356a5
permissions -rw-r--r--
add
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
16
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents: 15
diff changeset
    51
(**commutative-associative**)
20
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    52
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
    53
apply(induct m)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    54
apply(simp_all)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    55
done
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    56
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    57
lemma add_zero: "add n 0 = n"
21
fahadausaf <fahad.ausaf@icloud.com>
parents: 20
diff changeset
    58
apply(induct n)
fahadausaf <fahad.ausaf@icloud.com>
parents: 20
diff changeset
    59
apply(auto)
fahadausaf <fahad.ausaf@icloud.com>
parents: 20
diff changeset
    60
done
20
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    61
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    62
lemma add_Suc: "add m (Suc n) = Suc (add m n)"
21
fahadausaf <fahad.ausaf@icloud.com>
parents: 20
diff changeset
    63
apply(induct m)
fahadausaf <fahad.ausaf@icloud.com>
parents: 20
diff changeset
    64
apply(auto)
fahadausaf <fahad.ausaf@icloud.com>
parents: 20
diff changeset
    65
done
20
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    66
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    67
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
    68
apply(induct m)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    69
apply(simp add: add_zero)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    70
apply(simp add: add_Suc)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    71
done
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    72
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    73
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
    74
apply(subst add_04)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    75
apply(subst (2) add_comm)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    76
apply(simp)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    77
done
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    78
14
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    79
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    80
fun dub :: "nat \<Rightarrow> nat" where
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    81
"dub 0 = 0" |
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    82
"dub m = add m m"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    83
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    84
lemma dub_01: "dub 0 = 0"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    85
apply(induct)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    86
apply(auto)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    87
done
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    88
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    89
lemma dub_02: "dub m = add m m"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    90
apply(induction m)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    91
apply(auto)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    92
done
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    93
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    94
value "dub 2"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    95
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    96
fun trip :: "nat \<Rightarrow> nat" where
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    97
"trip 0 = 0" |
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    98
"trip m = add m (add m m)"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    99
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   100
lemma trip_01: "trip 0 = 0"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   101
apply(induct)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   102
apply(auto)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   103
done
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   104
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   105
lemma trip_02: "trip m = add m (add m m)"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   106
apply(induction m)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   107
apply(auto)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   108
done
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   109
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   110
value "trip 1"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   111
value "trip 2"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   112
20
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   113
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
   114
  "sum 0 = 0"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   115
| "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
   116
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   117
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
   118
  "sum1 0 = 0"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   119
| "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
   120
apply(auto)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   121
done
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   122
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   123
termination sum1
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   124
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
   125
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   126
lemma "sum n = sum1 n"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   127
apply(induct n)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   128
apply(auto)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   129
done
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   130
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   131
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
   132
apply(induct n)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   133
apply(simp_all)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   134
done
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   135
14
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   136
fun mull :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   137
"mull 0 0 = 0" |
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   138
"mull m 0 = 0" |
20
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   139
"mull m 1 = m" | 
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   140
(**"mull m (1::nat) = m" | **)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   141
(**"mull m (suc(0)) = m" | **)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   142
"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
   143
apply(pat_completeness)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   144
apply(auto)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   145
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   146
done
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   147
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   148
  "mull 0 n = 0"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   149
| "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
   150
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   151
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
   152
sorry
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   153
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   154
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
   155
  "poww 0 n = 1"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   156
| "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
   157
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   158
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   159
"mull 0 0 = 0" |
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   160
"mull m 0 = 0" |
15
bdabf71fa35b multiply
fahadausaf <fahad.ausaf@icloud.com>
parents: 14
diff changeset
   161
(**"mull m 1 = m" | **)
17
a5427713eef4 multiply 2
fahadausaf <fahad.ausaf@icloud.com>
parents: 16
diff changeset
   162
(**"mull m (1::nat) = m" | **)
a5427713eef4 multiply 2
fahadausaf <fahad.ausaf@icloud.com>
parents: 16
diff changeset
   163
(**"mull m (suc(0)) = m" | **)
a5427713eef4 multiply 2
fahadausaf <fahad.ausaf@icloud.com>
parents: 16
diff changeset
   164
"mull m n = mull m (n-(1::nat))" 
14
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   165
17
a5427713eef4 multiply 2
fahadausaf <fahad.ausaf@icloud.com>
parents: 16
diff changeset
   166
(**Define a function that counts the
a5427713eef4 multiply 2
fahadausaf <fahad.ausaf@icloud.com>
parents: 16
diff changeset
   167
number of occurrences of an element in a list **)
14
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   168
(**
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   169
fun count :: "'a\<Rightarrow>'a list\<Rightarrow>nat" where
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   170
"count  "
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   171
**)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   172
20
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   173
19
fahadausaf <fahad.ausaf@icloud.com>
parents: 17
diff changeset
   174
(* prove n = n * (n + 1) div 2  *)
14
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
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   183
19
fahadausaf <fahad.ausaf@icloud.com>
parents: 17
diff changeset
   184
fahadausaf <fahad.ausaf@icloud.com>
parents: 17
diff changeset
   185