Attic/MyFirst.thy
author Chengsong
Wed, 02 Mar 2022 23:13:59 +0000
changeset 438 a73b2e553804
parent 95 a33d3040bf7e
permissions -rw-r--r--
templateforPhd
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
22
fahadausaf <fahad.ausaf@icloud.com>
parents: 21
diff changeset
    51
value "add 2 3"
fahadausaf <fahad.ausaf@icloud.com>
parents: 21
diff changeset
    52
fahadausaf <fahad.ausaf@icloud.com>
parents: 21
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"
21
fahadausaf <fahad.ausaf@icloud.com>
parents: 20
diff changeset
    61
apply(induct n)
fahadausaf <fahad.ausaf@icloud.com>
parents: 20
diff changeset
    62
apply(auto)
fahadausaf <fahad.ausaf@icloud.com>
parents: 20
diff changeset
    63
done
20
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    64
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    65
lemma add_Suc: "add m (Suc n) = Suc (add m n)"
21
fahadausaf <fahad.ausaf@icloud.com>
parents: 20
diff changeset
    66
apply(induct m)
22
fahadausaf <fahad.ausaf@icloud.com>
parents: 21
diff changeset
    67
apply(metis add.simps(1))
21
fahadausaf <fahad.ausaf@icloud.com>
parents: 20
diff changeset
    68
apply(auto)
fahadausaf <fahad.ausaf@icloud.com>
parents: 20
diff changeset
    69
done
20
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    70
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    71
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
    72
apply(induct m)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    73
apply(simp add: add_zero)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    74
apply(simp add: add_Suc)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    75
done
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    76
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    77
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
    78
apply(subst add_04)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    79
apply(subst (2) add_comm)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    80
apply(simp)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    81
done
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    82
14
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    83
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    84
fun dub :: "nat \<Rightarrow> nat" where
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    85
"dub 0 = 0" |
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    86
"dub m = add m m"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    87
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    88
lemma dub_01: "dub 0 = 0"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    89
apply(induct)
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
lemma dub_02: "dub m = add m m"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    94
apply(induction m)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    95
apply(auto)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    96
done
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    97
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    98
value "dub 2"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    99
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   100
fun trip :: "nat \<Rightarrow> nat" where
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   101
"trip 0 = 0" |
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   102
"trip m = add m (add m m)"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   103
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   104
lemma trip_01: "trip 0 = 0"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   105
apply(induct)
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
lemma trip_02: "trip m = add m (add m m)"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   110
apply(induction m)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   111
apply(auto)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   112
done
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   113
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   114
value "trip 1"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   115
value "trip 2"
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   116
20
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   117
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
   118
  "sum 0 = 0"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   119
| "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
   120
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   121
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
   122
  "sum1 0 = 0"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   123
| "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
   124
apply(auto)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   125
done
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   126
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   127
termination sum1
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   128
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
   129
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   130
lemma "sum n = sum1 n"
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(auto)
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
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   135
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
   136
apply(induct n)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   137
apply(simp_all)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   138
done
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   139
14
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   140
fun mull :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   141
"mull 0 0 = 0" |
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   142
"mull m 0 = 0" |
20
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   143
"mull m 1 = m" | 
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   144
(**"mull m (1::nat) = m" | **)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   145
(**"mull m (suc(0)) = m" | **)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   146
"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
   147
apply(pat_completeness)
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   148
apply(auto)
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
done
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   151
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   152
  "mull 0 n = 0"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   153
| "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
   154
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   155
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
   156
sorry
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
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
   159
  "poww 0 n = 1"
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   160
| "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
   161
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   162
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   163
"mull 0 0 = 0" |
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   164
"mull m 0 = 0" |
15
bdabf71fa35b multiply
fahadausaf <fahad.ausaf@icloud.com>
parents: 14
diff changeset
   165
(**"mull m 1 = m" | **)
17
a5427713eef4 multiply 2
fahadausaf <fahad.ausaf@icloud.com>
parents: 16
diff changeset
   166
(**"mull m (1::nat) = m" | **)
a5427713eef4 multiply 2
fahadausaf <fahad.ausaf@icloud.com>
parents: 16
diff changeset
   167
(**"mull m (suc(0)) = m" | **)
a5427713eef4 multiply 2
fahadausaf <fahad.ausaf@icloud.com>
parents: 16
diff changeset
   168
"mull m n = mull m (n-(1::nat))" 
14
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   169
17
a5427713eef4 multiply 2
fahadausaf <fahad.ausaf@icloud.com>
parents: 16
diff changeset
   170
(**Define a function that counts the
a5427713eef4 multiply 2
fahadausaf <fahad.ausaf@icloud.com>
parents: 16
diff changeset
   171
number of occurrences of an element in a list **)
14
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   172
(**
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   173
fun count :: "'a\<Rightarrow>'a list\<Rightarrow>nat" where
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   174
"count  "
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   175
**)
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   176
20
c11651bbebf5 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   177
19
fahadausaf <fahad.ausaf@icloud.com>
parents: 17
diff changeset
   178
(* prove n = n * (n + 1) div 2  *)
14
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
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   184
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   185
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   186
5c6f9325327f calculator
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   187
19
fahadausaf <fahad.ausaf@icloud.com>
parents: 17
diff changeset
   188
fahadausaf <fahad.ausaf@icloud.com>
parents: 17
diff changeset
   189