src/HOL/ex/Sorting.thy
author wenzelm
Sat, 09 Jul 2011 21:53:27 +0200
changeset 43721 fad8634cee62
parent 41959 b460124855b8
permissions -rw-r--r--
echo prover input via raw_messages, for improved protocol tracing;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41959
b460124855b8 tuned headers;
wenzelm
parents: 41460
diff changeset
     1
(*  Title:      HOL/ex/Sorting.thy
1476
608483c2122a expanded tabs; incorporated Konrad's changes
clasohm
parents: 1376
diff changeset
     2
    Author:     Tobias Nipkow
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     3
    Copyright   1994 TU Muenchen
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     4
*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     5
15815
paulson
parents: 15631
diff changeset
     6
header{*Sorting: Basic Theory*}
paulson
parents: 15631
diff changeset
     7
paulson
parents: 15631
diff changeset
     8
theory Sorting
41413
64cd30d6b0b8 explicit file specifications -- avoid secondary load path;
wenzelm
parents: 21404
diff changeset
     9
imports Main "~~/src/HOL/Library/Multiset"
15815
paulson
parents: 15631
diff changeset
    10
begin
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    11
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    12
consts
13159
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    13
  sorted1:: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> bool"
2af7b94892ce Turned into Isar theories.
nipkow
parents: 8415
diff changeset
    14
  sorted :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> bool"
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"
15815
paulson
parents: 15631
diff changeset
    23
  "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
    24
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    25
19736
wenzelm
parents: 15815
diff changeset
    26
definition
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 19736
diff changeset
    27
  total  :: "('a \<Rightarrow> 'a \<Rightarrow> bool) => bool" where
19736
wenzelm
parents: 15815
diff changeset
    28
   "total r = (\<forall>x y. r x y | r y x)"
8415
paulson
parents: 5184
diff changeset
    29
  
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 19736
diff changeset
    30
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 19736
diff changeset
    31
  transf :: "('a \<Rightarrow> 'a \<Rightarrow> bool) => bool" where
19736
wenzelm
parents: 15815
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]:
19736
wenzelm
parents: 15815
diff changeset
    47
  "sorted le (xs@ys) = 
wenzelm
parents: 15815
diff changeset
    48
    (sorted le xs & sorted le ys & (\<forall>x \<in> set xs. \<forall>y \<in> set ys. le x y))"
wenzelm
parents: 15815
diff changeset
    49
  by (induct xs) auto
13159
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