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