src/HOL/ex/Qsort.ML
author clasohm
Tue, 30 Jan 1996 15:24:36 +0100
changeset 1465 5d7a7e439cec
parent 1266 3ae9fe3c0f68
child 1673 d22110ddd0af
permissions -rw-r--r--
expanded tabs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1266
diff changeset
     1
(*  Title:      HOL/ex/qsort.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
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
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
     9
Addsimps ([Qsort.qsort_Nil,Qsort.qsort_Cons]@conj_comms);
969
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);
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    13
by(ALLGOALS(asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
969
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);
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    19
by(ALLGOALS(asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    20
Addsimps [result()];
969
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);
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    25
by(ALLGOALS Asm_simp_tac);
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    26
Addsimps [result()];
969
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);
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    30
val lemma = result();
969
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);
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    34
by(ALLGOALS(asm_simp_tac (!simpset addsimps [lemma])));
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    35
Addsimps [result()];
969
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);
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    41
by(ALLGOALS Asm_simp_tac);
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    42
Addsimps [result()];
969
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);
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    47
by(ALLGOALS(asm_full_simp_tac (!simpset addsimps [list_all_mem_conv]) ));
969
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
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    58
Addsimps [sorted_Cons];
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    59
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    60
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    61
goal Qsort.thy "x mem qsort le xs = x mem xs";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    62
by(res_inst_tac[("xs","xs"),("p","le")]Qsort.qsort_ind 1);
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    63
by(ALLGOALS(asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    64
by(fast_tac HOL_cs 1);
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    65
Addsimps [result()];
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    66
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    67
goal Qsort.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    68
 "sorted le (xs@ys) = (sorted le xs & sorted le ys & \
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    69
\                     (!x. x mem xs --> (!y. y mem ys --> le x y)))";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    70
by(list.induct_tac "xs" 1);
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    71
by(ALLGOALS(asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    72
by(fast_tac HOL_cs 1);
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    73
Addsimps [result()];
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    74
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    75
goal Qsort.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    76
  "!!xs. [| total(le); transf(le) |] ==>  sorted le (qsort le xs)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    77
by(res_inst_tac[("xs","xs"),("p","le")]Qsort.qsort_ind 1);
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    78
by(Simp_tac 1);
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    79
by(asm_full_simp_tac (!simpset setloop (split_tac [expand_if])) 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    80
by(rewrite_goals_tac [Sorting.total_def,Sorting.transf_def]);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    81
by(fast_tac HOL_cs 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    82
result();