author | clasohm |
Mon, 05 Feb 1996 21:27:16 +0100 | |
changeset 1475 | 7f5a4cd08209 |
parent 1465 | 5d7a7e439cec |
child 1642 | 21db0cf9a1a4 |
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 |
val sexp_free_cs = |
|
14 |
set_cs addSDs [Leaf_inject, Numb_inject, Scons_inject] |
|
1465 | 15 |
addSEs [Leaf_neq_Scons, Leaf_neq_Numb, |
16 |
Numb_neq_Scons, Numb_neq_Leaf, |
|
17 |
Scons_neq_Leaf, Scons_neq_Numb]; |
|
923 | 18 |
|
19 |
goalw Sexp.thy [sexp_case_def] "sexp_case c d e (Leaf a) = c(a)"; |
|
1475 | 20 |
by (resolve_tac [select_equality] 1); |
923 | 21 |
by (ALLGOALS (fast_tac sexp_free_cs)); |
22 |
qed "sexp_case_Leaf"; |
|
23 |
||
24 |
goalw Sexp.thy [sexp_case_def] "sexp_case c d e (Numb k) = d(k)"; |
|
1475 | 25 |
by (resolve_tac [select_equality] 1); |
923 | 26 |
by (ALLGOALS (fast_tac sexp_free_cs)); |
27 |
qed "sexp_case_Numb"; |
|
28 |
||
29 |
goalw Sexp.thy [sexp_case_def] "sexp_case c d e (M$N) = e M N"; |
|
1475 | 30 |
by (resolve_tac [select_equality] 1); |
923 | 31 |
by (ALLGOALS (fast_tac sexp_free_cs)); |
32 |
qed "sexp_case_Scons"; |
|
33 |
||
34 |
||
35 |
(** Introduction rules for sexp constructors **) |
|
36 |
||
37 |
val [prem] = goalw Sexp.thy [In0_def] |
|
38 |
"M: sexp ==> In0(M) : sexp"; |
|
39 |
by (rtac (prem RS (sexp.NumbI RS sexp.SconsI)) 1); |
|
40 |
qed "sexp_In0I"; |
|
41 |
||
42 |
val [prem] = goalw Sexp.thy [In1_def] |
|
43 |
"M: sexp ==> In1(M) : sexp"; |
|
44 |
by (rtac (prem RS (sexp.NumbI RS sexp.SconsI)) 1); |
|
45 |
qed "sexp_In1I"; |
|
46 |
||
47 |
val sexp_cs = set_cs addIs sexp.intrs@[SigmaI, uprodI]; |
|
48 |
||
49 |
goal Sexp.thy "range(Leaf) <= sexp"; |
|
50 |
by (fast_tac sexp_cs 1); |
|
51 |
qed "range_Leaf_subset_sexp"; |
|
52 |
||
53 |
val [major] = goal Sexp.thy "M$N : sexp ==> M: sexp & N: sexp"; |
|
54 |
by (rtac (major RS setup_induction) 1); |
|
55 |
by (etac sexp.induct 1); |
|
56 |
by (ALLGOALS |
|
57 |
(fast_tac (set_cs addSEs [Scons_neq_Leaf,Scons_neq_Numb,Scons_inject]))); |
|
58 |
qed "Scons_D"; |
|
59 |
||
60 |
(** Introduction rules for 'pred_sexp' **) |
|
61 |
||
62 |
goalw Sexp.thy [pred_sexp_def] "pred_sexp <= Sigma sexp (%u.sexp)"; |
|
63 |
by (fast_tac sexp_cs 1); |
|
64 |
qed "pred_sexp_subset_Sigma"; |
|
65 |
||
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
66 |
(* (a,b) : pred_sexp^+ ==> a : sexp *) |
923 | 67 |
val trancl_pred_sexpD1 = |
68 |
pred_sexp_subset_Sigma RS trancl_subset_Sigma RS subsetD RS SigmaD1 |
|
69 |
and trancl_pred_sexpD2 = |
|
70 |
pred_sexp_subset_Sigma RS trancl_subset_Sigma RS subsetD RS SigmaD2; |
|
71 |
||
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 |] ==> (M, M$N) : pred_sexp"; |
923 | 74 |
by (fast_tac (set_cs addIs prems) 1); |
75 |
qed "pred_sexpI1"; |
|
76 |
||
77 |
val prems = goalw Sexp.thy [pred_sexp_def] |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
78 |
"[| M: sexp; N: sexp |] ==> (N, M$N) : pred_sexp"; |
923 | 79 |
by (fast_tac (set_cs addIs prems) 1); |
80 |
qed "pred_sexpI2"; |
|
81 |
||
82 |
(*Combinations involving transitivity and the rules above*) |
|
83 |
val pred_sexp_t1 = pred_sexpI1 RS r_into_trancl |
|
84 |
and pred_sexp_t2 = pred_sexpI2 RS r_into_trancl; |
|
85 |
||
86 |
val pred_sexp_trans1 = pred_sexp_t1 RSN (2, trans_trancl RS transD) |
|
87 |
and pred_sexp_trans2 = pred_sexp_t2 RSN (2, trans_trancl RS transD); |
|
88 |
||
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
89 |
(*Proves goals of the form (M,N):pred_sexp^+ provided M,N:sexp*) |
1264 | 90 |
Addsimps (sexp.intrs @ [pred_sexp_t1, pred_sexp_t2, |
1465 | 91 |
pred_sexp_trans1, pred_sexp_trans2, cut_apply]); |
923 | 92 |
|
93 |
val major::prems = goalw Sexp.thy [pred_sexp_def] |
|
94 |
"[| p : pred_sexp; \ |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
95 |
\ !!M N. [| p = (M, M$N); M: sexp; N: sexp |] ==> R; \ |
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
96 |
\ !!M N. [| p = (N, M$N); M: sexp; N: sexp |] ==> R \ |
923 | 97 |
\ |] ==> R"; |
98 |
by (cut_facts_tac [major] 1); |
|
99 |
by (REPEAT (eresolve_tac ([asm_rl,emptyE,insertE,UN_E]@prems) 1)); |
|
100 |
qed "pred_sexpE"; |
|
101 |
||
102 |
goal Sexp.thy "wf(pred_sexp)"; |
|
103 |
by (rtac (pred_sexp_subset_Sigma RS wfI) 1); |
|
104 |
by (etac sexp.induct 1); |
|
105 |
by (fast_tac (HOL_cs addSEs [mp, pred_sexpE, Pair_inject, Scons_inject]) 3); |
|
106 |
by (fast_tac (HOL_cs addSEs [mp, pred_sexpE, Pair_inject, Numb_neq_Scons]) 2); |
|
107 |
by (fast_tac (HOL_cs addSEs [mp, pred_sexpE, Pair_inject, Leaf_neq_Scons]) 1); |
|
108 |
qed "wf_pred_sexp"; |
|
109 |
||
110 |
(*** sexp_rec -- by wf recursion on pred_sexp ***) |
|
111 |
||
1475 | 112 |
goal Sexp.thy |
113 |
"(%M. sexp_rec M c d e) = wfrec pred_sexp \ |
|
114 |
\ (%g. sexp_case c d (%N1 N2. e N1 N2 (g N1) (g N2)))"; |
|
115 |
by (simp_tac (HOL_ss addsimps [sexp_rec_def]) 1); |
|
116 |
bind_thm("sexp_rec_unfold", wf_pred_sexp RS |
|
117 |
((result() RS eq_reflection) RS def_wfrec)); |
|
923 | 118 |
(** conversion rules **) |
119 |
||
1475 | 120 |
(*--------------------------------------------------------------------------- |
121 |
* Old: |
|
122 |
* val sexp_rec_unfold = wf_pred_sexp RS (sexp_rec_def RS def_wfrec); |
|
123 |
*---------------------------------------------------------------------------*) |
|
923 | 124 |
|
125 |
||
126 |
goal Sexp.thy "sexp_rec (Leaf a) c d h = c(a)"; |
|
127 |
by (stac sexp_rec_unfold 1); |
|
128 |
by (rtac sexp_case_Leaf 1); |
|
129 |
qed "sexp_rec_Leaf"; |
|
130 |
||
131 |
goal Sexp.thy "sexp_rec (Numb k) c d h = d(k)"; |
|
132 |
by (stac sexp_rec_unfold 1); |
|
133 |
by (rtac sexp_case_Numb 1); |
|
134 |
qed "sexp_rec_Numb"; |
|
135 |
||
136 |
goal Sexp.thy "!!M. [| M: sexp; N: sexp |] ==> \ |
|
137 |
\ sexp_rec (M$N) c d h = h M N (sexp_rec M c d h) (sexp_rec N c d h)"; |
|
138 |
by (rtac (sexp_rec_unfold RS trans) 1); |
|
1264 | 139 |
by (asm_simp_tac (!simpset addsimps [sexp_case_Scons,pred_sexpI1,pred_sexpI2]) |
140 |
1); |
|
923 | 141 |
qed "sexp_rec_Scons"; |