src/HOL/ex/InSort.ML
author paulson
Thu, 09 Jan 1997 10:22:42 +0100
changeset 2498 7914881f47c0
parent 2031 03a843f0f447
child 2511 282e9a9eae9d
permissions -rw-r--r--
New theorem add_leE
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1266
diff changeset
     1
(*  Title:      HOL/ex/insort.ML
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1266
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
Correctness proof of insertion sort.
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     7
*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     8
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     9
goalw InSort.thy [Sorting.total_def]
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    10
  "!!f. [| total(f); ~f x y |] ==> f y x";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    11
by (Fast_tac 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    12
qed "totalD";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    13
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    14
goalw InSort.thy [Sorting.transf_def]
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    15
  "!!f. [| transf(f); f b a |] ==> !x. f a x --> f b x";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    16
by (Fast_tac 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    17
qed "transfD";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    18
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    19
goal InSort.thy "list_all p (ins f x xs) = (list_all p xs & p(x))";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    20
by (list.induct_tac "xs" 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    21
by (Asm_simp_tac 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    22
by (asm_simp_tac (!simpset setloop (split_tac [expand_if])) 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    23
by (Fast_tac 1);
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    24
Addsimps [result()];
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
goal InSort.thy "(!x. p(x) --> q(x)) --> list_all p xs --> list_all q xs";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    27
by (list.induct_tac "xs" 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    28
by (ALLGOALS(asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    29
qed "list_all_imp";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    30
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    31
val prems = goal InSort.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    32
  "[| total(f); transf(f) |] ==>  sorted f (ins f x xs) = sorted f xs";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    33
by (list.induct_tac "xs" 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    34
by (ALLGOALS(asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    35
by (cut_facts_tac prems 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    36
by (cut_inst_tac [("p","f(a)"),("q","f(x)")] list_all_imp 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    37
by (fast_tac (!claset addDs [totalD,transfD]) 1);
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    38
Addsimps [result()];
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    39
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    40
goal InSort.thy "!!f. [| total(f); transf(f) |] ==>  sorted f (insort f xs)";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    41
by (list.induct_tac "xs" 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    42
by (ALLGOALS Asm_simp_tac);
1750
817a34a54fb0 replaced result() by qed "sorted_insort" in last proof
berghofe
parents: 1465
diff changeset
    43
qed "sorted_insort";
817a34a54fb0 replaced result() by qed "sorted_insort" in last proof
berghofe
parents: 1465
diff changeset
    44