src/HOL/ex/Qsort.ML
author paulson
Wed, 13 Nov 1996 10:47:08 +0100
changeset 2183 8d42a7bccf0b
parent 2031 03a843f0f447
child 2511 282e9a9eae9d
permissions -rw-r--r--
Updated version and date
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";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    12
by (res_inst_tac[("xs","xs"),("p","le")]Qsort.qsort_ind 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
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))";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    18
by (list.induct_tac "xs" 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    19
by (ALLGOALS(asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
1266
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))";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    24
by (list.induct_tac "xs" 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    25
by (ALLGOALS Asm_simp_tac);
1673
d22110ddd0af repaired critical proofs depending on the order inside non-confluent SimpSets
oheimb
parents: 1465
diff changeset
    26
val alls_lemma=result();
d22110ddd0af repaired critical proofs depending on the order inside non-confluent SimpSets
oheimb
parents: 1465
diff changeset
    27
Addsimps [alls_lemma];
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    28
1673
d22110ddd0af repaired critical proofs depending on the order inside non-confluent SimpSets
oheimb
parents: 1465
diff changeset
    29
goal HOL.thy "((P --> Q) & (~P --> Q)) = Q";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    30
by (Fast_tac 1);
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    31
val lemma = result();
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    32
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    33
goal Qsort.thy "(Alls x:qsort le xs.P(x))  =  (Alls x:xs.P(x))";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    34
by (res_inst_tac[("xs","xs"),("p","le")]Qsort.qsort_ind 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    35
by (Asm_simp_tac 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    36
by (asm_simp_tac (!simpset delsimps [alls_lemma, list_all_Cons])1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    37
by (asm_simp_tac (!simpset addsimps [lemma]) 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 Qsort.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    41
 "sorted le (xs@ys) = (sorted le xs & sorted le ys & \
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    42
\                     (Alls x:xs. Alls y:ys. le x y))";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    43
by (list.induct_tac "xs" 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    44
by (Asm_simp_tac 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    45
by (asm_simp_tac (!simpset delsimps [alls_lemma]) 1);
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    46
Addsimps [result()];
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    47
1673
d22110ddd0af repaired critical proofs depending on the order inside non-confluent SimpSets
oheimb
parents: 1465
diff changeset
    48
d22110ddd0af repaired critical proofs depending on the order inside non-confluent SimpSets
oheimb
parents: 1465
diff changeset
    49
d22110ddd0af repaired critical proofs depending on the order inside non-confluent SimpSets
oheimb
parents: 1465
diff changeset
    50
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    51
goal Qsort.thy 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    52
 "!!le. [| total(le); transf(le) |] ==>  sorted le (qsort le xs)";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    53
by (res_inst_tac[("xs","xs"),("p","le")]Qsort.qsort_ind 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    54
by (Asm_simp_tac 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    55
by (asm_full_simp_tac (!simpset addsimps []) 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    56
by (asm_full_simp_tac (!simpset addsimps [list_all_mem_conv]) 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    57
by (rewrite_goals_tac [Sorting.total_def,Sorting.transf_def]);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    58
by (Fast_tac 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    59
result();
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    60
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    61
(* A verification based on predicate calculus rather than combinators *)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    62
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    63
val sorted_Cons =
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    64
  rewrite_rule [list_all_mem_conv RS eq_reflection] Sorting.sorted_Cons;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    65
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    66
Addsimps [sorted_Cons];
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    67
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 "x mem qsort le xs = x mem xs";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    70
by (res_inst_tac[("xs","xs"),("p","le")]Qsort.qsort_ind 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    71
by (ALLGOALS(asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    72
by (Fast_tac 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
 "sorted le (xs@ys) = (sorted le xs & sorted le ys & \
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    77
\                     (!x. x mem xs --> (!y. y mem ys --> le x y)))";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    78
by (list.induct_tac "xs" 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    79
by (Asm_simp_tac 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    80
by (asm_simp_tac (!simpset setloop (split_tac [expand_if])
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    81
                          delsimps [list_all_conj]
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    82
                          addsimps [list_all_mem_conv]) 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    83
by (Fast_tac 1);
1266
3ae9fe3c0f68 added local simpsets
clasohm
parents: 969
diff changeset
    84
Addsimps [result()];
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    85
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    86
goal Qsort.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    87
  "!!xs. [| total(le); transf(le) |] ==>  sorted le (qsort le xs)";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    88
by (res_inst_tac[("xs","xs"),("p","le")]Qsort.qsort_ind 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    89
by (Simp_tac 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    90
by (asm_simp_tac (!simpset setloop (split_tac [expand_if])
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    91
                          delsimps [list_all_conj]
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    92
                          addsimps [list_all_mem_conv]) 1);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    93
by (rewrite_goals_tac [Sorting.total_def,Sorting.transf_def]);
03a843f0f447 Ran expandshort
paulson
parents: 1820
diff changeset
    94
by (Fast_tac 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    95
result();
1673
d22110ddd0af repaired critical proofs depending on the order inside non-confluent SimpSets
oheimb
parents: 1465
diff changeset
    96
d22110ddd0af repaired critical proofs depending on the order inside non-confluent SimpSets
oheimb
parents: 1465
diff changeset
    97