src/HOL/ex/InSort.ML
author lcp
Tue, 25 Apr 1995 11:14:03 +0200
changeset 1072 0140ff702b23
parent 969 b051e2fc2e34
child 1266 3ae9fe3c0f68
permissions -rw-r--r--
updated version
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     1
(*  Title: 	HOL/ex/insort.ML
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     3
    Author: 	Tobias Nipkow
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
val insort_ss = sorting_ss addsimps
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    10
 [InSort.ins_Nil,InSort.ins_Cons,InSort.insort_Nil,InSort.insort_Cons];
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    11
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    12
goalw InSort.thy [Sorting.total_def]
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    13
  "!!f. [| total(f); ~f x y |] ==> f y x";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    14
by(fast_tac HOL_cs 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    15
qed "totalD";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    16
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    17
goalw InSort.thy [Sorting.transf_def]
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    18
  "!!f. [| transf(f); f b a |] ==> !x. f a x --> f b x";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    19
by(fast_tac HOL_cs 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    20
qed "transfD";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    21
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    22
goal InSort.thy "list_all p (ins f x xs) = (list_all p xs & p(x))";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    23
by(list.induct_tac "xs" 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    24
by(asm_simp_tac insort_ss 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    25
by(asm_simp_tac (insort_ss setloop (split_tac [expand_if])) 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    26
by(fast_tac HOL_cs 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    27
val insort_ss = insort_ss addsimps [result()];
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    28
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    29
goal InSort.thy "(!x. p(x) --> q(x)) --> list_all p xs --> list_all q xs";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    30
by(list.induct_tac "xs" 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    31
by(ALLGOALS(asm_simp_tac (insort_ss setloop (split_tac [expand_if]))));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    32
qed "list_all_imp";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    33
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    34
val prems = goal InSort.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    35
  "[| total(f); transf(f) |] ==>  sorted f (ins f x xs) = sorted f xs";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    36
by(list.induct_tac "xs" 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    37
by(ALLGOALS(asm_simp_tac (insort_ss setloop (split_tac [expand_if]))));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    38
by(cut_facts_tac prems 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    39
by(cut_inst_tac [("p","f(a)"),("q","f(x)")] list_all_imp 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    40
by(fast_tac (HOL_cs addDs [totalD,transfD]) 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    41
val insort_ss = insort_ss addsimps [result()];
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    42
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    43
goal InSort.thy "!!f. [| total(f); transf(f) |] ==>  sorted f (insort f xs)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    44
by(list.induct_tac "xs" 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    45
by(ALLGOALS(asm_simp_tac insort_ss));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    46
result();