src/HOL/ex/Sorting.thy
author wenzelm
Thu, 15 Sep 2005 17:17:04 +0200
changeset 17416 5093a587da16
parent 15815 62854cac5410
child 19736 d8d0f8f51d69
permissions -rw-r--r--
fixed type;
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
15815
paulson
parents: 15631
diff changeset
     7
header{*Sorting: Basic Theory*}
paulson
parents: 15631
diff changeset
     8
paulson
parents: 15631
diff changeset
     9
theory Sorting
paulson
parents: 15631
diff changeset
    10
imports Main Multiset
paulson
parents: 15631
diff changeset
    11
begin
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    12
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    13
consts
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    14
  sorted1:: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> bool"
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    15
  sorted :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> bool"
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    16
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 3465
diff changeset
    17
primrec
2517
2af078382853 Modified some defs and shortened proofs.
nipkow
parents: 2511
diff changeset
    18
  "sorted1 le [] = True"
2af078382853 Modified some defs and shortened proofs.
nipkow
parents: 2511
diff changeset
    19
  "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
    20
                        sorted1 le xs)"
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    21
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 3465
diff changeset
    22
primrec
2517
2af078382853 Modified some defs and shortened proofs.
nipkow
parents: 2511
diff changeset
    23
  "sorted le [] = True"
15815
paulson
parents: 15631
diff changeset
    24
  "sorted le (x#xs) = ((\<forall>y \<in> set xs. le x y) & sorted le xs)"
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    25
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    26
8415
paulson
parents: 5184
diff changeset
    27
constdefs
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    28
  total  :: "('a \<Rightarrow> 'a \<Rightarrow> bool) => bool"
15815
paulson
parents: 15631
diff changeset
    29
   "total r == (\<forall>x y. r x y | r y x)"
8415
paulson
parents: 5184
diff changeset
    30
  
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    31
  transf :: "('a \<Rightarrow> 'a \<Rightarrow> bool) => bool"
15815
paulson
parents: 15631
diff changeset
    32
   "transf f == (\<forall>x y z. f x y & f y z --> f x z)"
8415
paulson
parents: 5184
diff changeset
    33
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    34
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    35
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    36
(* Equivalence of two definitions of `sorted' *)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    37
15815
paulson
parents: 15631
diff changeset
    38
lemma sorted1_is_sorted: "transf(le) ==> sorted1 le xs = sorted le xs";
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    39
apply(induct xs)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    40
 apply simp
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    41
apply(simp split: list.split)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    42
apply(unfold transf_def);
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    43
apply(blast)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    44
done
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    45
15815
paulson
parents: 15631
diff changeset
    46
lemma sorted_append [simp]:
paulson
parents: 15631
diff changeset
    47
 "sorted le (xs@ys) = 
paulson
parents: 15631
diff changeset
    48
  (sorted le xs & sorted le ys & (\<forall>x \<in> set xs. \<forall>y \<in> set ys. le x y))"
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    49
by (induct xs, auto)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    50
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    51
end