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