src/HOL/Sexp.ML
author paulson
Sat Nov 01 12:59:06 1997 +0100 (1997-11-01)
changeset 4059 59c1422c9da5
parent 3029 db0e9b30dc92
child 4089 96fba19bcbe2
permissions -rw-r--r--
New Blast_tac (and minor tidying...)
clasohm@1465
     1
(*  Title:      HOL/Sexp
clasohm@923
     2
    ID:         $Id$
clasohm@1465
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@923
     4
    Copyright   1994  University of Cambridge
clasohm@923
     5
clasohm@923
     6
S-expressions, general binary trees for defining recursive data structures
clasohm@923
     7
*)
clasohm@923
     8
clasohm@923
     9
open Sexp;
clasohm@923
    10
clasohm@923
    11
(** sexp_case **)
clasohm@923
    12
clasohm@923
    13
goalw Sexp.thy [sexp_case_def] "sexp_case c d e (Leaf a) = c(a)";
paulson@3029
    14
by (blast_tac (!claset addSIs [select_equality]) 1);
clasohm@923
    15
qed "sexp_case_Leaf";
clasohm@923
    16
clasohm@923
    17
goalw Sexp.thy [sexp_case_def] "sexp_case c d e (Numb k) = d(k)";
paulson@3029
    18
by (blast_tac (!claset addSIs [select_equality]) 1);
clasohm@923
    19
qed "sexp_case_Numb";
clasohm@923
    20
clasohm@923
    21
goalw Sexp.thy [sexp_case_def] "sexp_case c d e (M$N) = e M N";
paulson@3029
    22
by (blast_tac (!claset addSIs [select_equality]) 1);
clasohm@923
    23
qed "sexp_case_Scons";
clasohm@923
    24
clasohm@923
    25
clasohm@923
    26
(** Introduction rules for sexp constructors **)
clasohm@923
    27
paulson@3029
    28
val [prem] = goalw Sexp.thy [In0_def] "M: sexp ==> In0(M) : sexp";
clasohm@923
    29
by (rtac (prem RS (sexp.NumbI RS sexp.SconsI)) 1);
clasohm@923
    30
qed "sexp_In0I";
clasohm@923
    31
paulson@3029
    32
val [prem] = goalw Sexp.thy [In1_def] "M: sexp ==> In1(M) : sexp";
clasohm@923
    33
by (rtac (prem RS (sexp.NumbI RS sexp.SconsI)) 1);
clasohm@923
    34
qed "sexp_In1I";
clasohm@923
    35
berghofe@1760
    36
AddIs (sexp.intrs@[SigmaI, uprodI]);
berghofe@1760
    37
clasohm@923
    38
goal Sexp.thy "range(Leaf) <= sexp";
paulson@2892
    39
by (Blast_tac 1);
clasohm@923
    40
qed "range_Leaf_subset_sexp";
clasohm@923
    41
clasohm@923
    42
val [major] = goal Sexp.thy "M$N : sexp ==> M: sexp & N: sexp";
clasohm@923
    43
by (rtac (major RS setup_induction) 1);
clasohm@923
    44
by (etac sexp.induct 1);
paulson@2892
    45
by (ALLGOALS Blast_tac);
clasohm@923
    46
qed "Scons_D";
clasohm@923
    47
clasohm@923
    48
(** Introduction rules for 'pred_sexp' **)
clasohm@923
    49
paulson@1642
    50
goalw Sexp.thy [pred_sexp_def] "pred_sexp <= sexp Times sexp";
paulson@2892
    51
by (Blast_tac 1);
clasohm@923
    52
qed "pred_sexp_subset_Sigma";
clasohm@923
    53
clasohm@972
    54
(* (a,b) : pred_sexp^+ ==> a : sexp *)
clasohm@923
    55
val trancl_pred_sexpD1 = 
clasohm@923
    56
    pred_sexp_subset_Sigma RS trancl_subset_Sigma RS subsetD RS SigmaD1
clasohm@923
    57
and trancl_pred_sexpD2 = 
clasohm@923
    58
    pred_sexp_subset_Sigma RS trancl_subset_Sigma RS subsetD RS SigmaD2;
clasohm@923
    59
paulson@2892
    60
goalw Sexp.thy [pred_sexp_def]
paulson@2892
    61
    "!!M. [| M: sexp;  N: sexp |] ==> (M, M$N) : pred_sexp";
paulson@2892
    62
by (Blast_tac 1);
clasohm@923
    63
qed "pred_sexpI1";
clasohm@923
    64
paulson@2892
    65
goalw Sexp.thy [pred_sexp_def]
paulson@2892
    66
    "!!M. [| M: sexp;  N: sexp |] ==> (N, M$N) : pred_sexp";
paulson@2892
    67
by (Blast_tac 1);
clasohm@923
    68
qed "pred_sexpI2";
clasohm@923
    69
clasohm@923
    70
(*Combinations involving transitivity and the rules above*)
clasohm@923
    71
val pred_sexp_t1 = pred_sexpI1 RS r_into_trancl
clasohm@923
    72
and pred_sexp_t2 = pred_sexpI2 RS r_into_trancl;
clasohm@923
    73
clasohm@923
    74
val pred_sexp_trans1 = pred_sexp_t1 RSN (2, trans_trancl RS transD)
clasohm@923
    75
and pred_sexp_trans2 = pred_sexp_t2 RSN (2, trans_trancl RS transD);
clasohm@923
    76
clasohm@972
    77
(*Proves goals of the form (M,N):pred_sexp^+ provided M,N:sexp*)
clasohm@1264
    78
Addsimps (sexp.intrs @ [pred_sexp_t1, pred_sexp_t2,
clasohm@1465
    79
                        pred_sexp_trans1, pred_sexp_trans2, cut_apply]);
clasohm@923
    80
clasohm@923
    81
val major::prems = goalw Sexp.thy [pred_sexp_def]
paulson@3029
    82
    "[| p : pred_sexp;                                       \
clasohm@972
    83
\       !!M N. [| p = (M, M$N);  M: sexp;  N: sexp |] ==> R; \
clasohm@972
    84
\       !!M N. [| p = (N, M$N);  M: sexp;  N: sexp |] ==> R  \
clasohm@923
    85
\    |] ==> R";
clasohm@923
    86
by (cut_facts_tac [major] 1);
clasohm@923
    87
by (REPEAT (eresolve_tac ([asm_rl,emptyE,insertE,UN_E]@prems) 1));
clasohm@923
    88
qed "pred_sexpE";
clasohm@923
    89
clasohm@923
    90
goal Sexp.thy "wf(pred_sexp)";
clasohm@923
    91
by (rtac (pred_sexp_subset_Sigma RS wfI) 1);
clasohm@923
    92
by (etac sexp.induct 1);
paulson@4059
    93
by (ALLGOALS (blast_tac (!claset addSEs [allE, pred_sexpE])));
clasohm@923
    94
qed "wf_pred_sexp";
clasohm@923
    95
paulson@3029
    96
clasohm@923
    97
(*** sexp_rec -- by wf recursion on pred_sexp ***)
clasohm@923
    98
clasohm@1475
    99
goal Sexp.thy
clasohm@1475
   100
   "(%M. sexp_rec M c d e) = wfrec pred_sexp \
clasohm@1475
   101
                       \ (%g. sexp_case c d (%N1 N2. e N1 N2 (g N1) (g N2)))";
clasohm@1475
   102
by (simp_tac (HOL_ss addsimps [sexp_rec_def]) 1);
paulson@3029
   103
bind_thm("sexp_rec_unfold", 
paulson@3029
   104
	 [result() RS eq_reflection, wf_pred_sexp] MRS def_wfrec);
clasohm@923
   105
paulson@3029
   106
(** conversion rules **)
clasohm@923
   107
clasohm@923
   108
goal Sexp.thy "sexp_rec (Leaf a) c d h = c(a)";
clasohm@923
   109
by (stac sexp_rec_unfold 1);
clasohm@923
   110
by (rtac sexp_case_Leaf 1);
clasohm@923
   111
qed "sexp_rec_Leaf";
clasohm@923
   112
clasohm@923
   113
goal Sexp.thy "sexp_rec (Numb k) c d h = d(k)";
clasohm@923
   114
by (stac sexp_rec_unfold 1);
clasohm@923
   115
by (rtac sexp_case_Numb 1);
clasohm@923
   116
qed "sexp_rec_Numb";
clasohm@923
   117
clasohm@923
   118
goal Sexp.thy "!!M. [| M: sexp;  N: sexp |] ==> \
clasohm@923
   119
\    sexp_rec (M$N) c d h = h M N (sexp_rec M c d h) (sexp_rec N c d h)";
clasohm@923
   120
by (rtac (sexp_rec_unfold RS trans) 1);
clasohm@1264
   121
by (asm_simp_tac (!simpset addsimps [sexp_case_Scons,pred_sexpI1,pred_sexpI2])
clasohm@1264
   122
    1);
clasohm@923
   123
qed "sexp_rec_Scons";