thys/CountSnoc.thy.orig
author fahadausaf <fahad.ausaf@icloud.com>
Tue, 07 Oct 2014 18:43:29 +0100
changeset 25 a2a7f65f538a
permissions -rw-r--r--
lemma
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     1
theory CountSnoc
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     2
imports Main
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     3
begin
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     4
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     5
datatype 'a myList = Nil | Cons 'a "'a myList"
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     6
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     7
fun app_list :: "'a myList \<Rightarrow> 'a myList \<Rightarrow> 'a myList" where
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     8
"app_list Nil ys = ys" |
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
     9
"app_list (Cons x xs) ys = Cons x (app_list xs ys)"
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    10
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    11
fun rev_list :: "'a myList \<Rightarrow> 'a myList" where
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    12
"rev_list Nil = Nil" |
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    13
"rev_list (Cons x xs) = app_list (rev_list xs) (Cons x Nil)"
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    14
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    15
(*
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    16
fun count_list :: "'a \<Rightarrow> 'a myList \<Rightarrow> nat" where
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    17
"count_list x [] = 0" |
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    18
"count_list x (y#xs) = (
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    19
  if x = y then Suc(count_list x xs) 
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    20
  else count_list x xs)"
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    21
*)
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    22
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    23
fun count_list :: "'a \<Rightarrow> 'a list \<Rightarrow> nat" where
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    24
"count_list x [] = 0" |
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    25
"count_list x (y#xs) = (
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    26
  if x = y then Suc(count_list x xs) 
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    27
  else count_list x xs)"
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    28
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    29
<<<<<<< local
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    30
value "count_list 1 [1,1,0]"
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    31
value "count_list 1 [2,2,2]"
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    32
value "count_list 2 [2,2,1]"
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    33
=======
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    34
value "count_list (1::nat) [1,1,1]"
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    35
value "count_list (1::nat) [2,2,2]"
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    36
value "count_list (2::nat) [2,2,1]"
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    37
>>>>>>> other
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    38
 
fahadausaf <fahad.ausaf@icloud.com>
parents:
diff changeset
    39