0
|
1 |
(* Title: HOL/sexp
|
|
2 |
ID: $Id$
|
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory
|
|
4 |
Copyright 1992 University of Cambridge
|
|
5 |
|
|
6 |
For sexp.thy. S-expressions.
|
|
7 |
*)
|
|
8 |
|
|
9 |
open Sexp;
|
|
10 |
|
|
11 |
(** the sexp functional **)
|
|
12 |
|
|
13 |
goal Sexp.thy "mono(%Z. range(Leaf) Un range(Numb) Un Z<*>Z)";
|
|
14 |
by (REPEAT (ares_tac [monoI, subset_refl, Un_mono, uprod_mono] 1));
|
|
15 |
val Sexp_fun_mono = result();
|
|
16 |
|
|
17 |
val Sexp_unfold = Sexp_fun_mono RS (Sexp_def RS def_lfp_Tarski);
|
|
18 |
|
|
19 |
(** Induction **)
|
|
20 |
|
|
21 |
val major::prems = goal Sexp.thy
|
|
22 |
"[| ii: Sexp; !!a. P(Leaf(a)); !!k. P(Numb(k)); \
|
|
23 |
\ !!i j. [| i: Sexp; j: Sexp; P(i); P(j) |] ==> P(i.j) \
|
|
24 |
\ |] ==> P(ii)";
|
|
25 |
by (rtac (major RS (Sexp_def RS def_induct)) 1);
|
|
26 |
by (rtac Sexp_fun_mono 1);
|
|
27 |
by (fast_tac (set_cs addIs prems addSEs [uprodE]) 1);
|
|
28 |
val Sexp_induct = result();
|
|
29 |
|
|
30 |
(** Sexp_case **)
|
|
31 |
|
|
32 |
goalw Sexp.thy [Sexp_case_def] "Sexp_case(Leaf(a),c,d,e) = c(a)";
|
|
33 |
by (fast_tac (HOL_cs addIs [select_equality]
|
|
34 |
addSDs [Leaf_inject]
|
|
35 |
addSEs [Leaf_neq_Scons, Leaf_neq_Numb]) 1);
|
|
36 |
val Sexp_case_Leaf = result();
|
|
37 |
|
|
38 |
goalw Sexp.thy [Sexp_case_def] "Sexp_case(Numb(k),c,d,e) = d(k)";
|
|
39 |
by (fast_tac (HOL_cs addIs [select_equality]
|
|
40 |
addSDs [Numb_inject]
|
|
41 |
addSEs [Numb_neq_Scons, Numb_neq_Leaf]) 1);
|
|
42 |
val Sexp_case_Numb = result();
|
|
43 |
|
|
44 |
goalw Sexp.thy [Sexp_case_def] "Sexp_case(M.N, c, d, e) = e(M,N)";
|
|
45 |
by (fast_tac (HOL_cs addIs [select_equality]
|
|
46 |
addSDs [Scons_inject]
|
|
47 |
addSEs [Scons_neq_Leaf, Scons_neq_Numb]) 1);
|
|
48 |
val Sexp_case_Scons = result();
|
|
49 |
|
|
50 |
|
|
51 |
(** Introduction rules for Sexp constructors **)
|
|
52 |
|
|
53 |
val SexpI = Sexp_unfold RS equalityD2 RS subsetD;
|
|
54 |
|
|
55 |
goal Sexp.thy "Leaf(a): Sexp";
|
|
56 |
by (fast_tac (set_cs addIs [SexpI]) 1);
|
|
57 |
val Sexp_LeafI = result();
|
|
58 |
|
|
59 |
goal Sexp.thy "Numb(a): Sexp";
|
|
60 |
by (fast_tac (set_cs addIs [SexpI]) 1);
|
|
61 |
val Sexp_NumbI = result();
|
|
62 |
|
|
63 |
val prems = goal Sexp.thy
|
|
64 |
"[| M: Sexp; N: Sexp |] ==> M.N : Sexp";
|
|
65 |
by (fast_tac (set_cs addIs ([uprodI,SexpI]@prems)) 1);
|
|
66 |
val Sexp_SconsI = result();
|
|
67 |
|
|
68 |
val [prem] = goalw Sexp.thy [In0_def]
|
|
69 |
"M: Sexp ==> In0(M) : Sexp";
|
|
70 |
by (rtac (prem RS (Sexp_NumbI RS Sexp_SconsI)) 1);
|
|
71 |
val Sexp_In0I = result();
|
|
72 |
|
|
73 |
val [prem] = goalw Sexp.thy [In1_def]
|
|
74 |
"M: Sexp ==> In1(M) : Sexp";
|
|
75 |
by (rtac (prem RS (Sexp_NumbI RS Sexp_SconsI)) 1);
|
|
76 |
val Sexp_In1I = result();
|
|
77 |
|
|
78 |
goal Sexp.thy "range(Leaf) <= Sexp";
|
|
79 |
by (fast_tac (set_cs addIs [SexpI]) 1);
|
|
80 |
val range_Leaf_subset_Sexp = result();
|
|
81 |
|
|
82 |
val [major] = goal Sexp.thy "M.N : Sexp ==> M: Sexp & N: Sexp";
|
|
83 |
by (rtac (major RS setup_induction) 1);
|
|
84 |
by (etac Sexp_induct 1);
|
|
85 |
by (ALLGOALS
|
|
86 |
(fast_tac (set_cs addSEs [Scons_neq_Leaf,Scons_neq_Numb,Scons_inject])));
|
|
87 |
val Scons_D = result();
|
|
88 |
|
|
89 |
(** Introduction rules for 'pred_Sexp' **)
|
|
90 |
|
|
91 |
val sexp_cs = set_cs addIs [SigmaI, uprodI, SexpI];
|
|
92 |
|
|
93 |
goalw Sexp.thy [pred_Sexp_def] "pred_Sexp <= Sigma(Sexp, %u.Sexp)";
|
|
94 |
by (fast_tac sexp_cs 1);
|
|
95 |
val pred_Sexp_subset_Sigma = result();
|
|
96 |
|
|
97 |
(* <a,b> : pred_Sexp^+ ==> a : Sexp *)
|
|
98 |
val trancl_pred_SexpD1 =
|
|
99 |
pred_Sexp_subset_Sigma RS trancl_subset_Sigma RS subsetD RS SigmaD1
|
|
100 |
and trancl_pred_SexpD2 =
|
|
101 |
pred_Sexp_subset_Sigma RS trancl_subset_Sigma RS subsetD RS SigmaD2;
|
|
102 |
|
|
103 |
val prems = goalw Sexp.thy [pred_Sexp_def]
|
|
104 |
"[| M: Sexp; N: Sexp |] ==> <M, M.N> : pred_Sexp";
|
|
105 |
by (fast_tac (set_cs addIs prems) 1);
|
|
106 |
val pred_SexpI1 = result();
|
|
107 |
|
|
108 |
val prems = goalw Sexp.thy [pred_Sexp_def]
|
|
109 |
"[| M: Sexp; N: Sexp |] ==> <N, M.N> : pred_Sexp";
|
|
110 |
by (fast_tac (set_cs addIs prems) 1);
|
|
111 |
val pred_SexpI2 = result();
|
|
112 |
|
|
113 |
(*Combinations involving transitivity and the rules above*)
|
|
114 |
val pred_Sexp_t1 = pred_SexpI1 RS r_into_trancl
|
|
115 |
and pred_Sexp_t2 = pred_SexpI2 RS r_into_trancl;
|
|
116 |
|
|
117 |
val pred_Sexp_trans1 = pred_Sexp_t1 RSN (2, trans_trancl RS transD)
|
|
118 |
and pred_Sexp_trans2 = pred_Sexp_t2 RSN (2, trans_trancl RS transD);
|
|
119 |
|
|
120 |
(*Proves goals of the form <M,N>:pred_Sexp^+ provided M,N:Sexp*)
|
|
121 |
val pred_Sexp_simps =
|
|
122 |
[Sexp_LeafI, Sexp_NumbI, Sexp_SconsI,
|
|
123 |
pred_Sexp_t1, pred_Sexp_t2,
|
|
124 |
pred_Sexp_trans1, pred_Sexp_trans2, cut_apply];
|
|
125 |
val pred_Sexp_ss = HOL_ss addsimps pred_Sexp_simps;
|
|
126 |
|
|
127 |
val major::prems = goalw Sexp.thy [pred_Sexp_def]
|
|
128 |
"[| p : pred_Sexp; \
|
|
129 |
\ !!M N. [| p = <M, M.N>; M: Sexp; N: Sexp |] ==> R; \
|
|
130 |
\ !!M N. [| p = <N, M.N>; M: Sexp; N: Sexp |] ==> R \
|
|
131 |
\ |] ==> R";
|
|
132 |
by (cut_facts_tac [major] 1);
|
|
133 |
by (REPEAT (eresolve_tac ([asm_rl,emptyE,insertE,UN_E]@prems) 1));
|
|
134 |
val pred_SexpE = result();
|
|
135 |
|
|
136 |
goal Sexp.thy "wf(pred_Sexp)";
|
|
137 |
by (rtac (pred_Sexp_subset_Sigma RS wfI) 1);
|
|
138 |
by (etac Sexp_induct 1);
|
|
139 |
by (fast_tac (HOL_cs addSEs [mp, pred_SexpE, Pair_inject, Scons_inject]) 3);
|
|
140 |
by (fast_tac (HOL_cs addSEs [mp, pred_SexpE, Pair_inject, Numb_neq_Scons]) 2);
|
|
141 |
by (fast_tac (HOL_cs addSEs [mp, pred_SexpE, Pair_inject, Leaf_neq_Scons]) 1);
|
|
142 |
val wf_pred_Sexp = result();
|
|
143 |
|
|
144 |
(*** Sexp_rec -- by wf recursion on pred_Sexp ***)
|
|
145 |
|
|
146 |
(** conversion rules **)
|
|
147 |
|
|
148 |
val Sexp_rec_unfold = wf_pred_Sexp RS (Sexp_rec_def RS def_wfrec);
|
|
149 |
|
|
150 |
|
|
151 |
goal Sexp.thy "Sexp_rec(Leaf(a), c, d, h) = c(a)";
|
|
152 |
by (stac Sexp_rec_unfold 1);
|
|
153 |
by (rtac Sexp_case_Leaf 1);
|
|
154 |
val Sexp_rec_Leaf = result();
|
|
155 |
|
|
156 |
goal Sexp.thy "Sexp_rec(Numb(k), c, d, h) = d(k)";
|
|
157 |
by (stac Sexp_rec_unfold 1);
|
|
158 |
by (rtac Sexp_case_Numb 1);
|
|
159 |
val Sexp_rec_Numb = result();
|
|
160 |
|
|
161 |
goal Sexp.thy "!!M. [| M: Sexp; N: Sexp |] ==> \
|
|
162 |
\ Sexp_rec(M.N, c, d, h) = h(M, N, Sexp_rec(M,c,d,h), Sexp_rec(N,c,d,h))";
|
|
163 |
by (rtac (Sexp_rec_unfold RS trans) 1);
|
|
164 |
by (asm_simp_tac(HOL_ss addsimps
|
|
165 |
[Sexp_case_Scons,pred_SexpI1,pred_SexpI2,cut_apply])1);
|
|
166 |
val Sexp_rec_Scons = result();
|