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