src/HOL/Sexp.ML
author paulson
Tue, 16 Jul 1996 15:49:46 +0200
changeset 1868 836950047d85
parent 1760 6f41a494f3b1
child 1985 84cf16192e03
permissions -rw-r--r--
Put in minimal simpset to avoid excessive simplification, just as in revision 1.9 of HOL/indrule.ML
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
     1
(*  Title:      HOL/Sexp
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     4
    Copyright   1994  University of Cambridge
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     5
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     6
S-expressions, general binary trees for defining recursive data structures
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     7
*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     8
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     9
open Sexp;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    10
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    11
(** sexp_case **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    12
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    13
val sexp_free_cs = 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    14
    set_cs addSDs [Leaf_inject, Numb_inject, Scons_inject] 
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
    15
           addSEs [Leaf_neq_Scons, Leaf_neq_Numb,
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
    16
                   Numb_neq_Scons, Numb_neq_Leaf,
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
    17
                   Scons_neq_Leaf, Scons_neq_Numb];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    18
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    19
AddSDs [Leaf_inject, Numb_inject, Scons_inject];
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    20
AddSEs [Leaf_neq_Scons, Leaf_neq_Numb,
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    21
                   Numb_neq_Scons, Numb_neq_Leaf,
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    22
                   Scons_neq_Leaf, Scons_neq_Numb];
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    23
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    24
goalw Sexp.thy [sexp_case_def] "sexp_case c d e (Leaf a) = c(a)";
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
    25
by (resolve_tac [select_equality] 1);
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    26
by (ALLGOALS (Fast_tac));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    27
qed "sexp_case_Leaf";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    28
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    29
goalw Sexp.thy [sexp_case_def] "sexp_case c d e (Numb k) = d(k)";
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
    30
by (resolve_tac [select_equality] 1);
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    31
by (ALLGOALS (Fast_tac));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    32
qed "sexp_case_Numb";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    33
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    34
goalw Sexp.thy [sexp_case_def] "sexp_case c d e (M$N) = e M N";
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
    35
by (resolve_tac [select_equality] 1);
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    36
by (ALLGOALS (Fast_tac));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    37
qed "sexp_case_Scons";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    38
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    39
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    40
(** Introduction rules for sexp constructors **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    41
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    42
val [prem] = goalw Sexp.thy [In0_def] 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    43
    "M: sexp ==> In0(M) : sexp";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    44
by (rtac (prem RS (sexp.NumbI RS sexp.SconsI)) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    45
qed "sexp_In0I";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    46
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    47
val [prem] = goalw Sexp.thy [In1_def] 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    48
    "M: sexp ==> In1(M) : sexp";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    49
by (rtac (prem RS (sexp.NumbI RS sexp.SconsI)) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    50
qed "sexp_In1I";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    51
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    52
val sexp_cs = set_cs addIs sexp.intrs@[SigmaI, uprodI];
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    53
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    54
AddIs (sexp.intrs@[SigmaI, uprodI]);
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    55
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    56
goal Sexp.thy "range(Leaf) <= sexp";
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    57
by (Fast_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    58
qed "range_Leaf_subset_sexp";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    59
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    60
val [major] = goal Sexp.thy "M$N : sexp ==> M: sexp & N: sexp";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    61
by (rtac (major RS setup_induction) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    62
by (etac sexp.induct 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    63
by (ALLGOALS 
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    64
    (fast_tac (!claset addSEs [Scons_neq_Leaf,Scons_neq_Numb,Scons_inject])));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    65
qed "Scons_D";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    66
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    67
(** Introduction rules for 'pred_sexp' **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    68
1642
21db0cf9a1a4 Using new "Times" infix
paulson
parents: 1475
diff changeset
    69
goalw Sexp.thy [pred_sexp_def] "pred_sexp <= sexp Times sexp";
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    70
by (Fast_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    71
qed "pred_sexp_subset_Sigma";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    72
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    73
(* (a,b) : pred_sexp^+ ==> a : sexp *)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    74
val trancl_pred_sexpD1 = 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    75
    pred_sexp_subset_Sigma RS trancl_subset_Sigma RS subsetD RS SigmaD1
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    76
and trancl_pred_sexpD2 = 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    77
    pred_sexp_subset_Sigma RS trancl_subset_Sigma RS subsetD RS SigmaD2;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    78
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    79
val prems = goalw Sexp.thy [pred_sexp_def]
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    80
    "[| M: sexp;  N: sexp |] ==> (M, M$N) : pred_sexp";
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    81
by (fast_tac (!claset addIs prems) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    82
qed "pred_sexpI1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    83
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    84
val prems = goalw Sexp.thy [pred_sexp_def]
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    85
    "[| M: sexp;  N: sexp |] ==> (N, M$N) : pred_sexp";
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    86
by (fast_tac (!claset addIs prems) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    87
qed "pred_sexpI2";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    88
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    89
(*Combinations involving transitivity and the rules above*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    90
val pred_sexp_t1 = pred_sexpI1 RS r_into_trancl
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    91
and pred_sexp_t2 = pred_sexpI2 RS r_into_trancl;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    92
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    93
val pred_sexp_trans1 = pred_sexp_t1 RSN (2, trans_trancl RS transD)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    94
and pred_sexp_trans2 = pred_sexp_t2 RSN (2, trans_trancl RS transD);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    95
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    96
(*Proves goals of the form (M,N):pred_sexp^+ provided M,N:sexp*)
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 972
diff changeset
    97
Addsimps (sexp.intrs @ [pred_sexp_t1, pred_sexp_t2,
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
    98
                        pred_sexp_trans1, pred_sexp_trans2, cut_apply]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    99
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   100
val major::prems = goalw Sexp.thy [pred_sexp_def]
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   101
    "[| p : pred_sexp;  \
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   102
\       !!M N. [| p = (M, M$N);  M: sexp;  N: sexp |] ==> R; \
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   103
\       !!M N. [| p = (N, M$N);  M: sexp;  N: sexp |] ==> R  \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   104
\    |] ==> R";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   105
by (cut_facts_tac [major] 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   106
by (REPEAT (eresolve_tac ([asm_rl,emptyE,insertE,UN_E]@prems) 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   107
qed "pred_sexpE";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   108
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   109
goal Sexp.thy "wf(pred_sexp)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   110
by (rtac (pred_sexp_subset_Sigma RS wfI) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   111
by (etac sexp.induct 1);
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
   112
by (fast_tac (!claset addSEs [mp, pred_sexpE, Pair_inject, Scons_inject]) 3);
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
   113
by (fast_tac (!claset addSEs [mp, pred_sexpE, Pair_inject, Numb_neq_Scons]) 2);
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
   114
by (fast_tac (!claset addSEs [mp, pred_sexpE, Pair_inject, Leaf_neq_Scons]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   115
qed "wf_pred_sexp";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   116
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   117
(*** sexp_rec -- by wf recursion on pred_sexp ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   118
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   119
goal Sexp.thy
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   120
   "(%M. sexp_rec M c d e) = wfrec pred_sexp \
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   121
                       \ (%g. sexp_case c d (%N1 N2. e N1 N2 (g N1) (g N2)))";
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   122
by (simp_tac (HOL_ss addsimps [sexp_rec_def]) 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   123
bind_thm("sexp_rec_unfold", wf_pred_sexp RS 
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   124
                            ((result() RS eq_reflection) RS def_wfrec));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   125
(** conversion rules **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   126
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   127
(*---------------------------------------------------------------------------
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   128
 * Old:
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   129
 * val sexp_rec_unfold = wf_pred_sexp RS (sexp_rec_def RS def_wfrec);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   130
 *---------------------------------------------------------------------------*)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   131
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   132
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   133
goal Sexp.thy "sexp_rec (Leaf a) c d h = c(a)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   134
by (stac sexp_rec_unfold 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   135
by (rtac sexp_case_Leaf 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   136
qed "sexp_rec_Leaf";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   137
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   138
goal Sexp.thy "sexp_rec (Numb k) c d h = d(k)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   139
by (stac sexp_rec_unfold 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   140
by (rtac sexp_case_Numb 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   141
qed "sexp_rec_Numb";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   142
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   143
goal Sexp.thy "!!M. [| M: sexp;  N: sexp |] ==> \
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   144
\    sexp_rec (M$N) c d h = h M N (sexp_rec M c d h) (sexp_rec N c d h)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   145
by (rtac (sexp_rec_unfold RS trans) 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 972
diff changeset
   146
by (asm_simp_tac (!simpset addsimps [sexp_case_Scons,pred_sexpI1,pred_sexpI2])
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 972
diff changeset
   147
    1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   148
qed "sexp_rec_Scons";