src/HOL/Sexp.ML
author berghofe
Tue, 30 Jun 1998 20:51:15 +0200
changeset 5102 8c782c25a11e
parent 5069 3ea049f7979d
child 5143 b94cd208f073
permissions -rw-r--r--
Adapted to new inductive definition package.
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
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4535
diff changeset
    13
Goalw [sexp_case_def] "sexp_case c d e (Leaf a) = c(a)";
4535
f24cebc299e4 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
    14
by (Blast_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    15
qed "sexp_case_Leaf";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    16
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4535
diff changeset
    17
Goalw [sexp_case_def] "sexp_case c d e (Numb k) = d(k)";
4535
f24cebc299e4 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
    18
by (Blast_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    19
qed "sexp_case_Numb";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    20
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4535
diff changeset
    21
Goalw [sexp_case_def] "sexp_case c d e (M$N) = e M N";
4535
f24cebc299e4 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
    22
by (Blast_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    23
qed "sexp_case_Scons";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    24
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4089
diff changeset
    25
Addsimps [sexp_case_Leaf, sexp_case_Numb, sexp_case_Scons];
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4089
diff changeset
    26
923
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
(** Introduction rules for sexp constructors **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    29
3029
db0e9b30dc92 A bit of tidying
paulson
parents: 2892
diff changeset
    30
val [prem] = goalw Sexp.thy [In0_def] "M: sexp ==> In0(M) : sexp";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    31
by (rtac (prem RS (sexp.NumbI RS sexp.SconsI)) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    32
qed "sexp_In0I";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    33
3029
db0e9b30dc92 A bit of tidying
paulson
parents: 2892
diff changeset
    34
val [prem] = goalw Sexp.thy [In1_def] "M: sexp ==> In1(M) : sexp";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    35
by (rtac (prem RS (sexp.NumbI RS sexp.SconsI)) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    36
qed "sexp_In1I";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    37
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    38
AddIs (sexp.intrs@[SigmaI, uprodI]);
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1642
diff changeset
    39
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4535
diff changeset
    40
Goal "range(Leaf) <= sexp";
2892
67fb21ddfe15 Calls Blast_tac. Tidied some proofs
paulson
parents: 2089
diff changeset
    41
by (Blast_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    42
qed "range_Leaf_subset_sexp";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    43
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    44
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
    45
by (rtac (major RS setup_induction) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    46
by (etac sexp.induct 1);
2892
67fb21ddfe15 Calls Blast_tac. Tidied some proofs
paulson
parents: 2089
diff changeset
    47
by (ALLGOALS Blast_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    48
qed "Scons_D";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    49
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    50
(** Introduction rules for 'pred_sexp' **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    51
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4535
diff changeset
    52
Goalw [pred_sexp_def] "pred_sexp <= sexp Times sexp";
2892
67fb21ddfe15 Calls Blast_tac. Tidied some proofs
paulson
parents: 2089
diff changeset
    53
by (Blast_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    54
qed "pred_sexp_subset_Sigma";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    55
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    56
(* (a,b) : pred_sexp^+ ==> a : sexp *)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    57
val trancl_pred_sexpD1 = 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    58
    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
    59
and trancl_pred_sexpD2 = 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    60
    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
    61
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4535
diff changeset
    62
Goalw [pred_sexp_def]
2892
67fb21ddfe15 Calls Blast_tac. Tidied some proofs
paulson
parents: 2089
diff changeset
    63
    "!!M. [| M: sexp;  N: sexp |] ==> (M, M$N) : pred_sexp";
67fb21ddfe15 Calls Blast_tac. Tidied some proofs
paulson
parents: 2089
diff changeset
    64
by (Blast_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    65
qed "pred_sexpI1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    66
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4535
diff changeset
    67
Goalw [pred_sexp_def]
2892
67fb21ddfe15 Calls Blast_tac. Tidied some proofs
paulson
parents: 2089
diff changeset
    68
    "!!M. [| M: sexp;  N: sexp |] ==> (N, M$N) : pred_sexp";
67fb21ddfe15 Calls Blast_tac. Tidied some proofs
paulson
parents: 2089
diff changeset
    69
by (Blast_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    70
qed "pred_sexpI2";
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
(*Combinations involving transitivity and the rules above*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    73
val pred_sexp_t1 = pred_sexpI1 RS r_into_trancl
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    74
and pred_sexp_t2 = pred_sexpI2 RS r_into_trancl;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    75
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    76
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
    77
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
    78
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    79
(*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
    80
Addsimps (sexp.intrs @ [pred_sexp_t1, pred_sexp_t2,
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
    81
                        pred_sexp_trans1, pred_sexp_trans2, cut_apply]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    82
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    83
val major::prems = goalw Sexp.thy [pred_sexp_def]
3029
db0e9b30dc92 A bit of tidying
paulson
parents: 2892
diff changeset
    84
    "[| p : pred_sexp;                                       \
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    85
\       !!M N. [| p = (M, M$N);  M: sexp;  N: sexp |] ==> R; \
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    86
\       !!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
    87
\    |] ==> R";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    88
by (cut_facts_tac [major] 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    89
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
    90
qed "pred_sexpE";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    91
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4535
diff changeset
    92
Goal "wf(pred_sexp)";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    93
by (rtac (pred_sexp_subset_Sigma RS wfI) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    94
by (etac sexp.induct 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
    95
by (ALLGOALS (blast_tac (claset() addSEs [allE, pred_sexpE])));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    96
qed "wf_pred_sexp";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    97
3029
db0e9b30dc92 A bit of tidying
paulson
parents: 2892
diff changeset
    98
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    99
(*** sexp_rec -- by wf recursion on pred_sexp ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   100
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4535
diff changeset
   101
Goal
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   102
   "(%M. sexp_rec M c d e) = wfrec pred_sexp \
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   103
                       \ (%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
   104
by (simp_tac (HOL_ss addsimps [sexp_rec_def]) 1);
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4089
diff changeset
   105
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4089
diff changeset
   106
(* sexp_rec a c d e =
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4089
diff changeset
   107
   sexp_case c d
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4089
diff changeset
   108
    (%N1 N2.
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4089
diff changeset
   109
        e N1 N2 (cut (%M. sexp_rec M c d e) pred_sexp a N1)
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4089
diff changeset
   110
         (cut (%M. sexp_rec M c d e) pred_sexp a N2)) a
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4089
diff changeset
   111
*)
3029
db0e9b30dc92 A bit of tidying
paulson
parents: 2892
diff changeset
   112
bind_thm("sexp_rec_unfold", 
db0e9b30dc92 A bit of tidying
paulson
parents: 2892
diff changeset
   113
	 [result() RS eq_reflection, wf_pred_sexp] MRS def_wfrec);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   114
3029
db0e9b30dc92 A bit of tidying
paulson
parents: 2892
diff changeset
   115
(** conversion rules **)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   116
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4535
diff changeset
   117
Goal "sexp_rec (Leaf a) c d h = c(a)";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   118
by (stac sexp_rec_unfold 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   119
by (rtac sexp_case_Leaf 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   120
qed "sexp_rec_Leaf";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   121
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4535
diff changeset
   122
Goal "sexp_rec (Numb k) c d h = d(k)";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   123
by (stac sexp_rec_unfold 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   124
by (rtac sexp_case_Numb 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   125
qed "sexp_rec_Numb";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   126
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4535
diff changeset
   127
Goal "!!M. [| M: sexp;  N: sexp |] ==> \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   128
\    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
   129
by (rtac (sexp_rec_unfold RS trans) 1);
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4089
diff changeset
   130
by (asm_simp_tac (simpset() addsimps [pred_sexpI1, pred_sexpI2]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   131
qed "sexp_rec_Scons";