src/HOL/ex/Sorting.thy
author kleing
Sat, 26 Mar 2005 00:01:56 +0100
changeset 15631 cbee04ce413b
parent 13159 2af7b94892ce
child 15815 62854cac5410
permissions -rw-r--r--
use Library/Multiset instead of own definition
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
15631
cbee04ce413b use Library/Multiset instead of own definition
kleing
parents: 13159
diff changeset
     9
theory Sorting = Main + Multiset:
13159
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"
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    14
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 3465
diff changeset
    15
primrec
2517
2af078382853 Modified some defs and shortened proofs.
nipkow
parents: 2511
diff changeset
    16
  "sorted1 le [] = True"
2af078382853 Modified some defs and shortened proofs.
nipkow
parents: 2511
diff changeset
    17
  "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
    18
                        sorted1 le xs)"
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    19
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 3465
diff changeset
    20
primrec
2517
2af078382853 Modified some defs and shortened proofs.
nipkow
parents: 2511
diff changeset
    21
  "sorted le [] = True"
3465
e85c24717cad set_of_list -> set
nipkow
parents: 2517
diff changeset
    22
  "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
    23
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    24
8415
paulson
parents: 5184
diff changeset
    25
constdefs
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    26
  total  :: "('a \<Rightarrow> 'a \<Rightarrow> bool) => bool"
8415
paulson
parents: 5184
diff changeset
    27
   "total r == (ALL x y. r x y | r y x)"
paulson
parents: 5184
diff changeset
    28
  
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    29
  transf :: "('a \<Rightarrow> 'a \<Rightarrow> bool) => bool"
8415
paulson
parents: 5184
diff changeset
    30
   "transf f == (ALL x y z. f x y & f y z --> f x z)"
paulson
parents: 5184
diff changeset
    31
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    32
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    33
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    34
(* Equivalence of two definitions of `sorted' *)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    35
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    36
lemma sorted1_is_sorted:
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    37
 "transf(le) ==> sorted1 le xs = sorted le xs";
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    38
apply(induct xs)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    39
 apply simp
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    40
apply(simp split: list.split)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    41
apply(unfold transf_def);
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    42
apply(blast)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    43
done
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    44
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    45
lemma sorted_append[simp]:
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    46
 "sorted le (xs@ys) = (sorted le xs \<and> sorted le ys \<and>
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    47
                       (\<forall>x \<in> set xs. \<forall>y \<in> set ys. le x y))"
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    48
by (induct xs, auto)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    49
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    50
end