src/HOL/ex/Sorting.thy
author haftmann
Fri, 11 Jun 2010 17:14:02 +0200
changeset 37407 61dd8c145da7
parent 21404 eb85850d3eb7
child 41413 64cd30d6b0b8
permissions -rw-r--r--
declare lex_prod_def [code del]
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
19736
wenzelm
parents: 15815
diff changeset
    27
definition
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 19736
diff changeset
    28
  total  :: "('a \<Rightarrow> 'a \<Rightarrow> bool) => bool" where
19736
wenzelm
parents: 15815
diff changeset
    29
   "total r = (\<forall>x y. r x y | r y x)"
8415
paulson
parents: 5184
diff changeset
    30
  
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 19736
diff changeset
    31
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 19736
diff changeset
    32
  transf :: "('a \<Rightarrow> 'a \<Rightarrow> bool) => bool" where
19736
wenzelm
parents: 15815
diff changeset
    33
   "transf f = (\<forall>x y z. f x y & f y z --> f x z)"
8415
paulson
parents: 5184
diff changeset
    34
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    35
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    36
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    37
(* Equivalence of two definitions of `sorted' *)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    38
15815
paulson
parents: 15631
diff changeset
    39
lemma sorted1_is_sorted: "transf(le) ==> sorted1 le xs = sorted le xs";
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    40
apply(induct xs)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    41
 apply simp
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    42
apply(simp split: list.split)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    43
apply(unfold transf_def);
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    44
apply(blast)
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    45
done
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    46
15815
paulson
parents: 15631
diff changeset
    47
lemma sorted_append [simp]:
19736
wenzelm
parents: 15815
diff changeset
    48
  "sorted le (xs@ys) = 
wenzelm
parents: 15815
diff changeset
    49
    (sorted le xs & sorted le ys & (\<forall>x \<in> set xs. \<forall>y \<in> set ys. le x y))"
wenzelm
parents: 15815
diff changeset
    50
  by (induct xs) auto
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    51
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    52
end