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