src/HOL/ex/Sorting.thy
author dixon
Wed, 02 Mar 2005 10:33:10 +0100
changeset 15560 c862d556fb18
parent 13159 2af7b94892ce
child 15631 cbee04ce413b
permissions -rw-r--r--
lucas - fixed bug with name capture variables bound outside redex could (previously)conflict with scheme variables that occur in the conditions of an equation, and which were renamed to avoid conflict with another instantiation. This has now been fixed.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1476
608483c2122a expanded tabs; incorporated Konrad's changes
clasohm
parents: 1376
diff changeset
     1
(*  Title:      HOL/ex/sorting.thy
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1476
608483c2122a expanded tabs; incorporated Konrad's changes
clasohm
parents: 1376
diff changeset
     3
    Author:     Tobias Nipkow
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     4
    Copyright   1994 TU Muenchen
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     5
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     6
Specification of sorting
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     7
*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     8
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
     9
theory Sorting = Main:
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    10
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    11
consts
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    12
  sorted1:: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> bool"
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    13
  sorted :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> bool"
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    14
  multiset   :: "'a list => ('a => nat)"
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    15
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 3465
diff changeset
    16
primrec
2517
2af078382853 Modified some defs and shortened proofs.
nipkow
parents: 2511
diff changeset
    17
  "sorted1 le [] = True"
2af078382853 Modified some defs and shortened proofs.
nipkow
parents: 2511
diff changeset
    18
  "sorted1 le (x#xs) = ((case xs of [] => True | y#ys => le x y) &
2af078382853 Modified some defs and shortened proofs.
nipkow
parents: 2511
diff changeset
    19
                        sorted1 le xs)"
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    20
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 3465
diff changeset
    21
primrec
2517
2af078382853 Modified some defs and shortened proofs.
nipkow
parents: 2511
diff changeset
    22
  "sorted le [] = True"
3465
e85c24717cad set_of_list -> set
nipkow
parents: 2517
diff changeset
    23
  "sorted le (x#xs) = ((!y:set xs. le x y) & sorted le xs)"
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    24
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 3465
diff changeset
    25
primrec
8415
paulson
parents: 5184
diff changeset
    26
  "multiset [] y = 0"
paulson
parents: 5184
diff changeset
    27
  "multiset (x#xs) y = (if x=y then Suc(multiset xs y) else multiset xs y)"
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    28
8415
paulson
parents: 5184
diff changeset
    29
constdefs
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    30
  total  :: "('a \<Rightarrow> 'a \<Rightarrow> bool) => bool"
8415
paulson
parents: 5184
diff changeset
    31
   "total r == (ALL x y. r x y | r y x)"
paulson
parents: 5184
diff changeset
    32
  
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    33
  transf :: "('a \<Rightarrow> 'a \<Rightarrow> bool) => bool"
8415
paulson
parents: 5184
diff changeset
    34
   "transf f == (ALL x y z. f x y & f y z --> f x z)"
paulson
parents: 5184
diff changeset
    35
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    36
(* Some general lemmas *)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    37
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    38
lemma multiset_append[simp]:
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    39
 "multiset (xs@ys) x = multiset xs x + multiset ys x"
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    40
by (induct xs, auto)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    41
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    42
lemma multiset_compl_add[simp]:
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    43
 "multiset [x:xs. ~p(x)] z + multiset [x:xs. p(x)] z = multiset xs z";
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    44
by (induct xs, auto)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    45
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    46
lemma set_via_multiset: "set xs = {x. multiset xs x ~= 0}";
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    47
by (induct xs, auto)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    48
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    49
(* Equivalence of two definitions of `sorted' *)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    50
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    51
lemma sorted1_is_sorted:
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    52
 "transf(le) ==> sorted1 le xs = sorted le xs";
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    53
apply(induct xs)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    54
 apply simp
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    55
apply(simp split: list.split)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    56
apply(unfold transf_def);
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    57
apply(blast)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    58
done
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    59
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    60
lemma sorted_append[simp]:
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    61
 "sorted le (xs@ys) = (sorted le xs \<and> sorted le ys \<and>
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    62
                       (\<forall>x \<in> set xs. \<forall>y \<in> set ys. le x y))"
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    63
by (induct xs, auto)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    64
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    65
end