thys/MyFirst.thy~
author fahadausaf <fahad.ausaf@icloud.com>
Mon, 06 Oct 2014 12:00:46 +0100
changeset 16 a92c10af61bd
child 20 c11651bbebf5
permissions -rw-r--r--
associative-commutative
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     1
theory MyFirst
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     2
imports Main
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     3
begin
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     4
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     5
datatype 'a list = Nil | Cons 'a "'a list"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     6
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     7
fun app :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" where
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     8
"app Nil ys = ys" |
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     9
"app (Cons x xs) ys = Cons x (app xs ys)"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    10
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    11
fun rev :: "'a list \<Rightarrow> 'a list" where
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    12
"rev Nil = Nil" |
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    13
"rev (Cons x xs) = app (rev xs) (Cons x Nil)"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    14
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    15
value "rev(Cons True (Cons False Nil))"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    16
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    17
value "1 + (2::nat)"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    18
value "1 + (2::int)"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    19
value "1 - (2::nat)"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    20
value "1 - (2::int)"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    21
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    22
lemma app_Nil2 [simp]: "app xs Nil = xs"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    23
apply(induction xs)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    24
apply(auto)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    25
done
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    26
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    27
lemma app_assoc [simp]: "app (app xs ys) zs = app xs (app ys zs)"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    28
apply(induction xs)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    29
apply(auto)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    30
done
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    31
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    32
lemma rev_app [simp]: "rev(app xs ys) = app (rev ys) (rev xs)"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    33
apply (induction xs)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    34
apply (auto)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    35
done
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    36
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    37
theorem rev_rev [simp]: "rev(rev xs) = xs"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    38
apply (induction xs)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    39
apply (auto)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    40
done
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    41
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    42
fun add :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    43
"add 0 n = n" |
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    44
"add (Suc m) n = Suc(add m n)"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    45
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    46
lemma add_02: "add m 0 = m"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    47
apply(induction m)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    48
apply(auto)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    49
done
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    50
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    51
value "add 2 3"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    52
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    53
lemma add_04: "add m (add n k) = add k (add m n)"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    54
apply(induct)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    55
apply(auto)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    56
oops
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    57
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    58
fun dub :: "nat \<Rightarrow> nat" where
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    59
"dub 0 = 0" |
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    60
"dub m = add m m"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    61
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    62
lemma dub_01: "dub 0 = 0"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    63
apply(induct)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    64
apply(auto)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    65
done
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    66
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    67
lemma dub_02: "dub m = add m m"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    68
apply(induction m)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    69
apply(auto)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    70
done
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    71
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    72
value "dub 2"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    73
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    74
fun trip :: "nat \<Rightarrow> nat" where
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    75
"trip 0 = 0" |
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    76
"trip m = add m (add m m)"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    77
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    78
lemma trip_01: "trip 0 = 0"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    79
apply(induct)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    80
apply(auto)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    81
done
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    82
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    83
lemma trip_02: "trip m = add m (add m m)"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    84
apply(induction m)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    85
apply(auto)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    86
done
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    87
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    88
value "trip 1"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    89
value "trip 2"
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    90
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    91
fun mull :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    92
"mull 0 0 = 0" |
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    93
"mull m 0 = 0" |
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    94
"mull m 1 = m" |
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    95
"mull m n = 0" 
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    96
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    97
(**
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    98
fun count :: "'a\<Rightarrow>'a list\<Rightarrow>nat" where
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    99
"count  "
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   100
**)
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   101
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   102
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   103
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   104
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   105
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   106
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   107
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   108
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   109
a92c10af61bd associative-commutative
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
   110