src/CCL/ex/list.ML
author wenzelm
Mon, 09 Nov 1998 15:32:43 +0100
changeset 5824 91113aa09371
parent 290 37d580c16af5
permissions -rw-r--r--
Proof methods.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     1
(*  Title: 	CCL/ex/list
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
    Author: 	Martin Coen, Cambridge University Computer Laboratory
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
    Copyright   1993  University of Cambridge
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     6
For list.thy.
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     9
open List;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    11
val list_defs = [map_def,comp_def,append_def,filter_def,flat_def,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    12
                 insert_def,isort_def,partition_def,qsort_def];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    13
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
(****)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    15
8
c3d2c6dcf3f0 Installation of new simplfier. Previously appeared to set up the old
lcp
parents: 0
diff changeset
    16
val listBs = map (fn s=>prove_goalw List.thy list_defs s (fn _ => [simp_tac term_ss 1]))
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    17
     ["(f o g) = (%a.f(g(a)))",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
      "(f o g)(a) = f(g(a))",
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
      "map(f,[]) = []",
290
37d580c16af5 changed "." to "$" and added parentheses to eliminate ambiguity
clasohm
parents: 8
diff changeset
    20
      "map(f,x$xs) = f(x)$map(f,xs)",
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
      "[] @ m = m",
290
37d580c16af5 changed "." to "$" and added parentheses to eliminate ambiguity
clasohm
parents: 8
diff changeset
    22
      "x$xs @ m = x$(xs @ m)",
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
      "filter(f,[]) = []",
290
37d580c16af5 changed "." to "$" and added parentheses to eliminate ambiguity
clasohm
parents: 8
diff changeset
    24
      "filter(f,x$xs) = if f`x then x$filter(f,xs) else filter(f,xs)",
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    25
      "flat([]) = []",
290
37d580c16af5 changed "." to "$" and added parentheses to eliminate ambiguity
clasohm
parents: 8
diff changeset
    26
      "flat(x$xs) = x @ flat(xs)",
37d580c16af5 changed "." to "$" and added parentheses to eliminate ambiguity
clasohm
parents: 8
diff changeset
    27
      "insert(f,a,[]) = a$[]",
37d580c16af5 changed "." to "$" and added parentheses to eliminate ambiguity
clasohm
parents: 8
diff changeset
    28
      "insert(f,a,x$xs) = if f`a`x then a$x$xs else x$insert(f,a,xs)"];
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    29
8
c3d2c6dcf3f0 Installation of new simplfier. Previously appeared to set up the old
lcp
parents: 0
diff changeset
    30
val list_ss = nat_ss addsimps listBs;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    31
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    32
(****)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    33
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    34
val [prem] = goal List.thy "n:Nat ==> map(f) ^ n ` [] = []";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    35
br (prem RS Nat_ind) 1;
8
c3d2c6dcf3f0 Installation of new simplfier. Previously appeared to set up the old
lcp
parents: 0
diff changeset
    36
by (ALLGOALS (asm_simp_tac list_ss));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    37
val nmapBnil = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    38
290
37d580c16af5 changed "." to "$" and added parentheses to eliminate ambiguity
clasohm
parents: 8
diff changeset
    39
val [prem] = goal List.thy "n:Nat ==> map(f)^n`(x$xs) = (f^n`x)$(map(f)^n`xs)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    40
br (prem RS Nat_ind) 1;
8
c3d2c6dcf3f0 Installation of new simplfier. Previously appeared to set up the old
lcp
parents: 0
diff changeset
    41
by (ALLGOALS (asm_simp_tac list_ss));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    42
val nmapBcons = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    43
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    44
(***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    45
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    46
val prems = goalw List.thy [map_def]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    47
  "[| !!x.x:A==>f(x):B;  l : List(A) |] ==> map(f,l) : List(B)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    48
by (typechk_tac prems 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    49
val mapT = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    50
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    51
val prems = goalw List.thy [append_def]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    52
  "[| l : List(A);  m : List(A) |] ==> l @ m : List(A)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    53
by (typechk_tac prems 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    54
val appendT = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    55
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    56
val prems = goal List.thy
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    57
  "[| l : {l:List(A). m : {m:List(A).P(l @ m)}} |] ==> l @ m : {x:List(A). P(x)}";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    58
by (cut_facts_tac prems 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    59
by (fast_tac (set_cs addSIs [SubtypeI,appendT] addSEs [SubtypeE]) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    60
val appendTS = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    61
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    62
val prems = goalw List.thy [filter_def]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    63
  "[| f:A->Bool;   l : List(A) |] ==> filter(f,l) : List(A)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    64
by (typechk_tac prems 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    65
val filterT = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    66
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    67
val prems = goalw List.thy [flat_def]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    68
  "l : List(List(A)) ==> flat(l) : List(A)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    69
by (typechk_tac (appendT::prems) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    70
val flatT = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    71
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    72
val prems = goalw List.thy [insert_def]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    73
  "[|  f : A->A->Bool; a:A; l : List(A) |] ==> insert(f,a,l) : List(A)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    74
by (typechk_tac prems 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    75
val insertT = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    76
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    77
val prems = goal List.thy
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    78
  "[| f : {f:A->A->Bool. a : {a:A. l : {l:List(A).P(insert(f,a,l))}}} |] ==> \
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    79
\  insert(f,a,l)  : {x:List(A). P(x)}";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    80
by (cut_facts_tac prems 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    81
by (fast_tac (set_cs addSIs [SubtypeI,insertT] addSEs [SubtypeE]) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    82
val insertTS = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    83
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    84
val prems = goalw List.thy [partition_def]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    85
  "[| f:A->Bool;  l : List(A) |] ==> partition(f,l) : List(A)*List(A)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    86
by (typechk_tac prems 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    87
by clean_ccs_tac;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    88
br (ListPRI RS wfstI RS (ListPR_wf RS wmap_wf RS wfI)) 2;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    89
br (ListPRI RS wfstI RS (ListPR_wf RS wmap_wf RS wfI)) 1;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    90
by (REPEAT (atac 1));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    91
val partitionT = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    92
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    93
(*** Correctness Conditions for Insertion Sort ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    94
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    95
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    96
val prems = goalw List.thy [isort_def] 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    97
    "f:A->A->Bool ==> isort(f) : PROD l:List(A).{x: List(A). Ord(f,x) & Perm(x,l)}";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    98
by (gen_ccs_tac  ([insertTS,insertT]@prems) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    99
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   100
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   101
(*** Correctness Conditions for Quick Sort ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   102
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   103
val prems = goalw List.thy [qsort_def] 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   104
    "f:A->A->Bool ==> qsort(f) : PROD l:List(A).{x: List(A). Ord(f,x) & Perm(x,l)}";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   105
by (gen_ccs_tac  ([partitionT,appendTS,appendT]@prems) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   106