src/HOL/Sexp.ML
author paulson
Thu, 26 Sep 1996 12:47:47 +0200
changeset 2031 03a843f0f447
parent 1985 84cf16192e03
child 2089 e2ec077ac90d
permissions -rw-r--r--
Ran expandshort
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
goalw Sexp.thy [sexp_case_def] "sexp_case c d e (Leaf a) = c(a)";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1985
diff changeset
    14
by (rtac select_equality 1);
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    15
by (ALLGOALS (Fast_tac));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    16
qed "sexp_case_Leaf";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    17
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    18
goalw Sexp.thy [sexp_case_def] "sexp_case c d e (Numb k) = d(k)";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1985
diff changeset
    19
by (rtac select_equality 1);
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    20
by (ALLGOALS (Fast_tac));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    21
qed "sexp_case_Numb";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    22
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    23
goalw Sexp.thy [sexp_case_def] "sexp_case c d e (M$N) = e M N";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1985
diff changeset
    24
by (rtac select_equality 1);
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    25
by (ALLGOALS (Fast_tac));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    26
qed "sexp_case_Scons";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    27
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
(** Introduction rules for sexp constructors **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    30
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    31
val [prem] = goalw Sexp.thy [In0_def] 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    32
    "M: sexp ==> In0(M) : sexp";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    33
by (rtac (prem RS (sexp.NumbI RS sexp.SconsI)) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    34
qed "sexp_In0I";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    35
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    36
val [prem] = goalw Sexp.thy [In1_def] 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    37
    "M: sexp ==> In1(M) : sexp";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    38
by (rtac (prem RS (sexp.NumbI RS sexp.SconsI)) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    39
qed "sexp_In1I";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    40
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    41
val sexp_cs = set_cs addIs sexp.intrs@[SigmaI, uprodI];
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    42
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    43
AddIs (sexp.intrs@[SigmaI, uprodI]);
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    44
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    45
goal Sexp.thy "range(Leaf) <= sexp";
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    46
by (Fast_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    47
qed "range_Leaf_subset_sexp";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    48
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    49
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
    50
by (rtac (major RS setup_induction) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    51
by (etac sexp.induct 1);
1985
84cf16192e03 Tidied many proofs, using AddIffs to let equivalences take
paulson
parents: 1760
diff changeset
    52
by (ALLGOALS Fast_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    53
qed "Scons_D";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    54
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    55
(** Introduction rules for 'pred_sexp' **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    56
1642
21db0cf9a1a4 Using new "Times" infix
paulson
parents: 1475
diff changeset
    57
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
    58
by (Fast_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    59
qed "pred_sexp_subset_Sigma";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    60
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    61
(* (a,b) : pred_sexp^+ ==> a : sexp *)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    62
val trancl_pred_sexpD1 = 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    63
    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
    64
and trancl_pred_sexpD2 = 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    65
    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
    66
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    67
val prems = goalw Sexp.thy [pred_sexp_def]
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    68
    "[| 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
    69
by (fast_tac (!claset addIs prems) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    70
qed "pred_sexpI1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    71
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    72
val prems = goalw Sexp.thy [pred_sexp_def]
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    73
    "[| 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
    74
by (fast_tac (!claset addIs prems) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    75
qed "pred_sexpI2";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    76
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    77
(*Combinations involving transitivity and the rules above*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    78
val pred_sexp_t1 = pred_sexpI1 RS r_into_trancl
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    79
and pred_sexp_t2 = pred_sexpI2 RS r_into_trancl;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    80
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    81
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
    82
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
    83
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    84
(*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
    85
Addsimps (sexp.intrs @ [pred_sexp_t1, pred_sexp_t2,
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
    86
                        pred_sexp_trans1, pred_sexp_trans2, cut_apply]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    87
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    88
val major::prems = goalw Sexp.thy [pred_sexp_def]
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    89
    "[| p : pred_sexp;  \
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    90
\       !!M N. [| p = (M, M$N);  M: sexp;  N: sexp |] ==> R; \
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    91
\       !!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
    92
\    |] ==> R";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    93
by (cut_facts_tac [major] 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    94
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
    95
qed "pred_sexpE";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    96
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    97
goal Sexp.thy "wf(pred_sexp)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    98
by (rtac (pred_sexp_subset_Sigma RS wfI) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    99
by (etac sexp.induct 1);
1985
84cf16192e03 Tidied many proofs, using AddIffs to let equivalences take
paulson
parents: 1760
diff changeset
   100
by (ALLGOALS (fast_tac (!claset addSEs [mp, pred_sexpE])));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   101
qed "wf_pred_sexp";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   102
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   103
(*** sexp_rec -- by wf recursion on pred_sexp ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   104
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   105
goal Sexp.thy
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   106
   "(%M. sexp_rec M c d e) = wfrec pred_sexp \
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   107
                       \ (%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
   108
by (simp_tac (HOL_ss addsimps [sexp_rec_def]) 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   109
bind_thm("sexp_rec_unfold", wf_pred_sexp RS 
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   110
                            ((result() RS eq_reflection) RS def_wfrec));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   111
(** conversion rules **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   112
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   113
(*---------------------------------------------------------------------------
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   114
 * Old:
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   115
 * 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
   116
 *---------------------------------------------------------------------------*)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   117
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   118
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   119
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
   120
by (stac sexp_rec_unfold 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   121
by (rtac sexp_case_Leaf 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   122
qed "sexp_rec_Leaf";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   123
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   124
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
   125
by (stac sexp_rec_unfold 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   126
by (rtac sexp_case_Numb 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   127
qed "sexp_rec_Numb";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   128
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   129
goal Sexp.thy "!!M. [| M: sexp;  N: sexp |] ==> \
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   130
\    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
   131
by (rtac (sexp_rec_unfold RS trans) 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 972
diff changeset
   132
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
   133
    1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   134
qed "sexp_rec_Scons";