src/HOL/ex/Qsort.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/qsort.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
Two verifications of Quicksort
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 ss = sorting_ss addsimps ([Qsort.qsort_Nil,Qsort.qsort_Cons]@conj_comms);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    10
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    11
goal Qsort.thy "!x. mset (qsort le xs) x = mset xs x";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    12
by(res_inst_tac[("xs","xs"),("p","le")]Qsort.qsort_ind 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    13
by(ALLGOALS(asm_simp_tac (ss setloop (split_tac [expand_if]))));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    14
result();
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    15
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    16
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    17
goal Qsort.thy "(Alls x:[x:xs.P(x)].Q(x)) = (Alls x:xs. P(x)-->Q(x))";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    18
by(list.induct_tac "xs" 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    19
by(ALLGOALS(asm_simp_tac (ss setloop (split_tac [expand_if]))));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    20
val ss = ss addsimps [result()];
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 Qsort.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    23
 "((Alls x:xs.P(x)) & (Alls x:xs.Q(x))) = (Alls x:xs. P(x)&Q(x))";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    24
by(list.induct_tac "xs" 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    25
by(ALLGOALS(asm_simp_tac ss));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    26
val ss = ss addsimps [result()];
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    27
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    28
goal HOL.thy "((~P --> Q) & (P --> Q)) = Q";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    29
by(fast_tac HOL_cs 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    30
qed "lemma";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    31
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    32
goal Qsort.thy "(Alls x:qsort le xs.P(x))  =  (Alls x:xs.P(x))";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    33
by(res_inst_tac[("xs","xs"),("p","le")]Qsort.qsort_ind 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    34
by(ALLGOALS(asm_simp_tac (ss addsimps [lemma])));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    35
val ss = ss addsimps [result()];
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    36
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    37
goal Qsort.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    38
 "sorted le (xs@ys) = (sorted le xs & sorted le ys & \
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    39
\                     (Alls x:xs. Alls y:ys. le x y))";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    40
by(list.induct_tac "xs" 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    41
by(ALLGOALS(asm_simp_tac ss));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    42
val ss = ss addsimps [result()];
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    43
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    44
goal Qsort.thy 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    45
 "!!le. [| total(le); transf(le) |] ==>  sorted le (qsort le xs)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    46
by(res_inst_tac[("xs","xs"),("p","le")]Qsort.qsort_ind 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    47
by(ALLGOALS(asm_full_simp_tac (ss addsimps [list_all_mem_conv]) ));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    48
by(rewrite_goals_tac [Sorting.total_def,Sorting.transf_def]);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    49
by(fast_tac HOL_cs 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    50
result();
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    51
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    52
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    53
(* A verification based on predicate calculus rather than combinators *)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    54
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    55
val sorted_Cons =
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    56
  rewrite_rule [list_all_mem_conv RS eq_reflection] Sorting.sorted_Cons;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    57
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    58
val ss = list_ss addsimps
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    59
 [Sorting.sorted_Nil,sorted_Cons,
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    60
  Qsort.qsort_Nil,Qsort.qsort_Cons];
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    61
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    62
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    63
goal Qsort.thy "x mem qsort le xs = x mem xs";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    64
by(res_inst_tac[("xs","xs"),("p","le")]Qsort.qsort_ind 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    65
by(ALLGOALS(asm_simp_tac (ss setloop (split_tac [expand_if]))));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    66
by(fast_tac HOL_cs 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    67
val ss = ss addsimps [result()];
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    68
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    69
goal Qsort.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    70
 "sorted le (xs@ys) = (sorted le xs & sorted le ys & \
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    71
\                     (!x. x mem xs --> (!y. y mem ys --> le x y)))";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    72
by(list.induct_tac "xs" 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    73
by(ALLGOALS(asm_simp_tac (ss setloop (split_tac [expand_if]))));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    74
by(fast_tac HOL_cs 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    75
val ss = ss addsimps [result()];
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    76
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    77
goal Qsort.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    78
  "!!xs. [| total(le); transf(le) |] ==>  sorted le (qsort le xs)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    79
by(res_inst_tac[("xs","xs"),("p","le")]Qsort.qsort_ind 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    80
by(simp_tac ss 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    81
by(asm_full_simp_tac (ss setloop (split_tac [expand_if])) 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    82
by(rewrite_goals_tac [Sorting.total_def,Sorting.transf_def]);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    83
by(fast_tac HOL_cs 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    84
result();