src/HOL/Sexp.ML
author berghofe
Thu May 23 14:37:06 1996 +0200 (1996-05-23)
changeset 1760 6f41a494f3b1
parent 1642 21db0cf9a1a4
child 1985 84cf16192e03
permissions -rw-r--r--
Replaced fast_tac by Fast_tac (which uses default claset)
New rules are now also added to default claset.
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
val sexp_free_cs = 
clasohm@923
    14
    set_cs addSDs [Leaf_inject, Numb_inject, Scons_inject] 
clasohm@1465
    15
           addSEs [Leaf_neq_Scons, Leaf_neq_Numb,
clasohm@1465
    16
                   Numb_neq_Scons, Numb_neq_Leaf,
clasohm@1465
    17
                   Scons_neq_Leaf, Scons_neq_Numb];
clasohm@923
    18
berghofe@1760
    19
AddSDs [Leaf_inject, Numb_inject, Scons_inject];
berghofe@1760
    20
AddSEs [Leaf_neq_Scons, Leaf_neq_Numb,
berghofe@1760
    21
                   Numb_neq_Scons, Numb_neq_Leaf,
berghofe@1760
    22
                   Scons_neq_Leaf, Scons_neq_Numb];
berghofe@1760
    23
clasohm@923
    24
goalw Sexp.thy [sexp_case_def] "sexp_case c d e (Leaf a) = c(a)";
clasohm@1475
    25
by (resolve_tac [select_equality] 1);
berghofe@1760
    26
by (ALLGOALS (Fast_tac));
clasohm@923
    27
qed "sexp_case_Leaf";
clasohm@923
    28
clasohm@923
    29
goalw Sexp.thy [sexp_case_def] "sexp_case c d e (Numb k) = d(k)";
clasohm@1475
    30
by (resolve_tac [select_equality] 1);
berghofe@1760
    31
by (ALLGOALS (Fast_tac));
clasohm@923
    32
qed "sexp_case_Numb";
clasohm@923
    33
clasohm@923
    34
goalw Sexp.thy [sexp_case_def] "sexp_case c d e (M$N) = e M N";
clasohm@1475
    35
by (resolve_tac [select_equality] 1);
berghofe@1760
    36
by (ALLGOALS (Fast_tac));
clasohm@923
    37
qed "sexp_case_Scons";
clasohm@923
    38
clasohm@923
    39
clasohm@923
    40
(** Introduction rules for sexp constructors **)
clasohm@923
    41
clasohm@923
    42
val [prem] = goalw Sexp.thy [In0_def] 
clasohm@923
    43
    "M: sexp ==> In0(M) : sexp";
clasohm@923
    44
by (rtac (prem RS (sexp.NumbI RS sexp.SconsI)) 1);
clasohm@923
    45
qed "sexp_In0I";
clasohm@923
    46
clasohm@923
    47
val [prem] = goalw Sexp.thy [In1_def] 
clasohm@923
    48
    "M: sexp ==> In1(M) : sexp";
clasohm@923
    49
by (rtac (prem RS (sexp.NumbI RS sexp.SconsI)) 1);
clasohm@923
    50
qed "sexp_In1I";
clasohm@923
    51
clasohm@923
    52
val sexp_cs = set_cs addIs sexp.intrs@[SigmaI, uprodI];
clasohm@923
    53
berghofe@1760
    54
AddIs (sexp.intrs@[SigmaI, uprodI]);
berghofe@1760
    55
clasohm@923
    56
goal Sexp.thy "range(Leaf) <= sexp";
berghofe@1760
    57
by (Fast_tac 1);
clasohm@923
    58
qed "range_Leaf_subset_sexp";
clasohm@923
    59
clasohm@923
    60
val [major] = goal Sexp.thy "M$N : sexp ==> M: sexp & N: sexp";
clasohm@923
    61
by (rtac (major RS setup_induction) 1);
clasohm@923
    62
by (etac sexp.induct 1);
clasohm@923
    63
by (ALLGOALS 
berghofe@1760
    64
    (fast_tac (!claset addSEs [Scons_neq_Leaf,Scons_neq_Numb,Scons_inject])));
clasohm@923
    65
qed "Scons_D";
clasohm@923
    66
clasohm@923
    67
(** Introduction rules for 'pred_sexp' **)
clasohm@923
    68
paulson@1642
    69
goalw Sexp.thy [pred_sexp_def] "pred_sexp <= sexp Times sexp";
berghofe@1760
    70
by (Fast_tac 1);
clasohm@923
    71
qed "pred_sexp_subset_Sigma";
clasohm@923
    72
clasohm@972
    73
(* (a,b) : pred_sexp^+ ==> a : sexp *)
clasohm@923
    74
val trancl_pred_sexpD1 = 
clasohm@923
    75
    pred_sexp_subset_Sigma RS trancl_subset_Sigma RS subsetD RS SigmaD1
clasohm@923
    76
and trancl_pred_sexpD2 = 
clasohm@923
    77
    pred_sexp_subset_Sigma RS trancl_subset_Sigma RS subsetD RS SigmaD2;
clasohm@923
    78
clasohm@923
    79
val prems = goalw Sexp.thy [pred_sexp_def]
clasohm@972
    80
    "[| M: sexp;  N: sexp |] ==> (M, M$N) : pred_sexp";
berghofe@1760
    81
by (fast_tac (!claset addIs prems) 1);
clasohm@923
    82
qed "pred_sexpI1";
clasohm@923
    83
clasohm@923
    84
val prems = goalw Sexp.thy [pred_sexp_def]
clasohm@972
    85
    "[| M: sexp;  N: sexp |] ==> (N, M$N) : pred_sexp";
berghofe@1760
    86
by (fast_tac (!claset addIs prems) 1);
clasohm@923
    87
qed "pred_sexpI2";
clasohm@923
    88
clasohm@923
    89
(*Combinations involving transitivity and the rules above*)
clasohm@923
    90
val pred_sexp_t1 = pred_sexpI1 RS r_into_trancl
clasohm@923
    91
and pred_sexp_t2 = pred_sexpI2 RS r_into_trancl;
clasohm@923
    92
clasohm@923
    93
val pred_sexp_trans1 = pred_sexp_t1 RSN (2, trans_trancl RS transD)
clasohm@923
    94
and pred_sexp_trans2 = pred_sexp_t2 RSN (2, trans_trancl RS transD);
clasohm@923
    95
clasohm@972
    96
(*Proves goals of the form (M,N):pred_sexp^+ provided M,N:sexp*)
clasohm@1264
    97
Addsimps (sexp.intrs @ [pred_sexp_t1, pred_sexp_t2,
clasohm@1465
    98
                        pred_sexp_trans1, pred_sexp_trans2, cut_apply]);
clasohm@923
    99
clasohm@923
   100
val major::prems = goalw Sexp.thy [pred_sexp_def]
clasohm@923
   101
    "[| p : pred_sexp;  \
clasohm@972
   102
\       !!M N. [| p = (M, M$N);  M: sexp;  N: sexp |] ==> R; \
clasohm@972
   103
\       !!M N. [| p = (N, M$N);  M: sexp;  N: sexp |] ==> R  \
clasohm@923
   104
\    |] ==> R";
clasohm@923
   105
by (cut_facts_tac [major] 1);
clasohm@923
   106
by (REPEAT (eresolve_tac ([asm_rl,emptyE,insertE,UN_E]@prems) 1));
clasohm@923
   107
qed "pred_sexpE";
clasohm@923
   108
clasohm@923
   109
goal Sexp.thy "wf(pred_sexp)";
clasohm@923
   110
by (rtac (pred_sexp_subset_Sigma RS wfI) 1);
clasohm@923
   111
by (etac sexp.induct 1);
berghofe@1760
   112
by (fast_tac (!claset addSEs [mp, pred_sexpE, Pair_inject, Scons_inject]) 3);
berghofe@1760
   113
by (fast_tac (!claset addSEs [mp, pred_sexpE, Pair_inject, Numb_neq_Scons]) 2);
berghofe@1760
   114
by (fast_tac (!claset addSEs [mp, pred_sexpE, Pair_inject, Leaf_neq_Scons]) 1);
clasohm@923
   115
qed "wf_pred_sexp";
clasohm@923
   116
clasohm@923
   117
(*** sexp_rec -- by wf recursion on pred_sexp ***)
clasohm@923
   118
clasohm@1475
   119
goal Sexp.thy
clasohm@1475
   120
   "(%M. sexp_rec M c d e) = wfrec pred_sexp \
clasohm@1475
   121
                       \ (%g. sexp_case c d (%N1 N2. e N1 N2 (g N1) (g N2)))";
clasohm@1475
   122
by (simp_tac (HOL_ss addsimps [sexp_rec_def]) 1);
clasohm@1475
   123
bind_thm("sexp_rec_unfold", wf_pred_sexp RS 
clasohm@1475
   124
                            ((result() RS eq_reflection) RS def_wfrec));
clasohm@923
   125
(** conversion rules **)
clasohm@923
   126
clasohm@1475
   127
(*---------------------------------------------------------------------------
clasohm@1475
   128
 * Old:
clasohm@1475
   129
 * val sexp_rec_unfold = wf_pred_sexp RS (sexp_rec_def RS def_wfrec);
clasohm@1475
   130
 *---------------------------------------------------------------------------*)
clasohm@923
   131
clasohm@923
   132
clasohm@923
   133
goal Sexp.thy "sexp_rec (Leaf a) c d h = c(a)";
clasohm@923
   134
by (stac sexp_rec_unfold 1);
clasohm@923
   135
by (rtac sexp_case_Leaf 1);
clasohm@923
   136
qed "sexp_rec_Leaf";
clasohm@923
   137
clasohm@923
   138
goal Sexp.thy "sexp_rec (Numb k) c d h = d(k)";
clasohm@923
   139
by (stac sexp_rec_unfold 1);
clasohm@923
   140
by (rtac sexp_case_Numb 1);
clasohm@923
   141
qed "sexp_rec_Numb";
clasohm@923
   142
clasohm@923
   143
goal Sexp.thy "!!M. [| M: sexp;  N: sexp |] ==> \
clasohm@923
   144
\    sexp_rec (M$N) c d h = h M N (sexp_rec M c d h) (sexp_rec N c d h)";
clasohm@923
   145
by (rtac (sexp_rec_unfold RS trans) 1);
clasohm@1264
   146
by (asm_simp_tac (!simpset addsimps [sexp_case_Scons,pred_sexpI1,pred_sexpI2])
clasohm@1264
   147
    1);
clasohm@923
   148
qed "sexp_rec_Scons";