author  wenzelm 
Wed, 02 Nov 2005 14:46:51 +0100  
changeset 18057  ad97e231bf8a 
parent 17985  d5d576b72371 
child 18083  cf7669049df5 
permissions  rwrr 
2276  1 
(* Title: HOLCF/domain/theorems.ML 
2445
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
2276
diff
changeset

2 
ID: $Id$ 
12030  3 
Author: David von Oheimb 
15742  4 
New proofs/tactics by Brian Huffman 
2445
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
2276
diff
changeset

5 

12030  6 
Proof generator for domain section. 
1274  7 
*) 
8 

16842  9 
val HOLCF_ss = simpset(); 
2446
c2a9bf6c0948
The previous log message was wrong. The correct one is:
oheimb
parents:
2445
diff
changeset

10 

1274  11 
structure Domain_Theorems = struct 
12 

13 
local 

14 

15 
open Domain_Library; 

16 
infixr 0 ===>;infixr 0 ==>;infix 0 == ; 

17 
infix 1 ===; infix 1 ~= ; infix 1 <<; infix 1 ~<<; 

18 
infix 9 ` ; infix 9 `% ; infix 9 `%%; infixr 9 oo; 

19 

1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

20 
(*  general proof facilities  *) 
1274  21 

14820  22 
fun inferT sg pre_tm = 
15531  23 
#1 (Sign.infer_types (Sign.pp sg) sg (K NONE) (K NONE) [] true ([pre_tm],propT)); 
1274  24 

17985  25 
fun pg'' thy defs t tacs = 
26 
let val t' = inferT thy t in 

27 
standard (Goal.prove thy [] (Logic.strip_imp_prems t') (Logic.strip_imp_concl t') 

28 
(fn prems => rewrite_goals_tac defs THEN EVERY (tacs (map (rewrite_rule defs) prems)))) 

29 
end; 

30 

1274  31 
fun pg' thy defs t tacsf=pg'' thy defs t (fn [] => tacsf 
2033  32 
 prems=> (cut_facts_tac prems 1)::tacsf); 
1274  33 

2033  34 
fun case_UU_tac rews i v = case_tac (v^"=UU") i THEN 
35 
asm_simp_tac (HOLCF_ss addsimps rews) i; 

1274  36 

37 
val chain_tac = REPEAT_DETERM o resolve_tac 

5291  38 
[chain_iterate, ch2ch_Rep_CFunR, ch2ch_Rep_CFunL]; 
1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

39 

b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

40 
(*  general proofs  *) 
1274  41 

1644  42 
val all2E = prove_goal HOL.thy "[ !x y . P x y; P x y ==> R ] ==> R" 
43 
(fn prems =>[ 

2033  44 
resolve_tac prems 1, 
45 
cut_facts_tac prems 1, 

46 
fast_tac HOL_cs 1]); 

1274  47 

18057  48 
val dist_eqI = prove_goal (the_context ()) "!!x::'a::po. ~ x << y ==> x ~= y" 
10230  49 
(fn prems => [ 
50 
(blast_tac (claset() addDs [antisym_less_inverse]) 1)]); 

4755  51 
(* 
52 
infixr 0 y; 

53 
val b = 0; 

54 
fun _ y t = by t; 

55 
fun g defs t = let val sg = sign_of thy; 

56 
val ct = Thm.cterm_of sg (inferT sg t); 

57 
in goalw_cterm defs ct end; 

58 
*) 

1274  59 

60 
in 

61 

4043  62 
fun theorems (((dname,_),cons) : eq, eqs : eq list) thy = 
1274  63 
let 
64 

4030  65 
val dummy = writeln ("Proving isomorphism properties of domain "^dname^" ..."); 
1274  66 
val pg = pg' thy; 
67 

1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

68 
(*  getting the axioms and definitions  *) 
1274  69 

16486  70 
local fun ga s dn = get_thm thy (Name (dn ^ "." ^ s)) in 
4043  71 
val ax_abs_iso = ga "abs_iso" dname; 
72 
val ax_rep_iso = ga "rep_iso" dname; 

73 
val ax_when_def = ga "when_def" dname; 

74 
val axs_con_def = map (fn (con,_) => ga (extern_name con^"_def") dname) cons; 

75 
val axs_dis_def = map (fn (con,_) => ga ( dis_name con^"_def") dname) cons; 

16224
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15742
diff
changeset

76 
val axs_mat_def = map (fn (con,_) => ga ( mat_name con^"_def") dname) cons; 
16394
495dbcd4f4c9
in domain declarations, selector names are now optional
huffman
parents:
16385
diff
changeset

77 
val axs_sel_def = List.concat(map (fn (_,args) => List.mapPartial (fn arg => 
495dbcd4f4c9
in domain declarations, selector names are now optional
huffman
parents:
16385
diff
changeset

78 
Option.map (fn sel => ga (sel^"_def") dname) (sel_of arg)) args) 
4043  79 
cons); 
80 
val ax_copy_def = ga "copy_def" dname; 

1274  81 
end; (* local *) 
82 

1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

83 
(*  theorems concerning the isomorphism  *) 
1274  84 

11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

85 
val dc_abs = %%:(dname^"_abs"); 
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

86 
val dc_rep = %%:(dname^"_rep"); 
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

87 
val dc_copy = %%:(dname^"_copy"); 
1274  88 
val x_name = "x"; 
89 

15742  90 
val iso_locale = iso_intro OF [ax_abs_iso, ax_rep_iso]; 
16224
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15742
diff
changeset

91 
val abs_strict = ax_rep_iso RS (allI RS retraction_strict); 
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15742
diff
changeset

92 
val rep_strict = ax_abs_iso RS (allI RS retraction_strict); 
15742  93 
val abs_defin' = iso_locale RS iso_abs_defin'; 
94 
val rep_defin' = iso_locale RS iso_rep_defin'; 

12037  95 
val iso_rews = map standard [ax_abs_iso,ax_rep_iso,abs_strict,rep_strict]; 
1274  96 

15742  97 
(*  generating beta reduction rules from definitions *) 
98 

99 
local 

100 
fun arglist (Const _ $ Abs (s,_,t)) = let 

101 
val (vars,body) = arglist t 

102 
in (s :: vars, body) end 

103 
 arglist t = ([],t); 

104 
fun bind_fun vars t = Library.foldr mk_All (vars,t); 

105 
fun bound_vars 0 = []  bound_vars i = (Bound (i1) :: bound_vars (i1)); 

106 
in 

107 
fun appl_of_def def = let 

16403  108 
val (_ $ con $ lam) = concl_of def; 
109 
val (vars, rhs) = arglist lam; 

110 
val lhs = mk_cRep_CFun (con, bound_vars (length vars)); 

111 
val appl = bind_fun vars (lhs == rhs); 

112 
val cs = ContProc.cont_thms lam; 

113 
val betas = map (fn c => mk_meta_eq (c RS beta_cfun)) cs; 

15742  114 
in pg (def::betas) appl [rtac reflexive_thm 1] end; 
115 
end; 

116 

117 
val when_appl = appl_of_def ax_when_def; 

118 
val con_appls = map appl_of_def axs_con_def; 

119 

120 
local 

16778  121 
fun arg2typ n arg = let val t = TVar (("'a",n),pcpoS) 
15742  122 
in (n+1, if is_lazy arg then mk_uT t else t) end; 
123 
fun args2typ n [] = (n,oneT) 

124 
 args2typ n [arg] = arg2typ n arg 

125 
 args2typ n (arg::args) = let val (n1,t1) = arg2typ n arg; 

126 
val (n2,t2) = args2typ n1 args 

127 
in (n2, mk_sprodT (t1, t2)) end; 

128 
fun cons2typ n [] = (n,oneT) 

129 
 cons2typ n [con] = args2typ n (snd con) 

130 
 cons2typ n (con::cons) = let val (n1,t1) = args2typ n (snd con); 

131 
val (n2,t2) = cons2typ n1 cons 

132 
in (n2, mk_ssumT (t1, t2)) end; 

133 
in 

134 
fun cons2ctyp cons = ctyp_of (sign_of thy) (snd (cons2typ 1 cons)); 

135 
end; 

136 

1274  137 
local 
15742  138 
val iso_swap = iso_locale RS iso_iso_swap; 
1274  139 
fun one_con (con,args) = let val vns = map vname args in 
17811  140 
Library.foldr mk_ex (vns, foldr1 mk_conj ((%:x_name === con_app2 con %: vns):: 
15742  141 
map (defined o %:) (nonlazy args))) end; 
17811  142 
val exh = foldr1 mk_disj ((%:x_name===UU)::map one_con cons); 
15742  143 
val my_ctyp = cons2ctyp cons; 
144 
val thm1 = instantiate' [SOME my_ctyp] [] exh_start; 

145 
val thm2 = rewrite_rule (map mk_meta_eq ex_defined_iffs) thm1; 

146 
val thm3 = rewrite_rule [mk_meta_eq conj_assoc] thm2; 

1274  147 
in 
15742  148 
val exhaust = pg con_appls (mk_trp exh)[ 
149 
(* first 3 rules replace "x = UU \/ P" with "rep$x = UU \/ P" *) 

150 
rtac disjE 1, 

151 
etac (rep_defin' RS disjI1) 2, 

152 
etac disjI2 2, 

153 
rewrite_goals_tac [mk_meta_eq iso_swap], 

154 
rtac thm3 1]; 

155 
val casedist = standard (rewrite_rule exh_casedists (exhaust RS exh_casedist0)); 

1274  156 
end; 
157 

158 
local 

15570  159 
fun bind_fun t = Library.foldr mk_All (when_funs cons,t); 
1829  160 
fun bound_fun i _ = Bound (length cons  i); 
15570  161 
val when_app = Library.foldl (op `) (%%:(dname^"_when"), mapn bound_fun 1 cons); 
1274  162 
in 
15742  163 
val when_strict = pg [when_appl, mk_meta_eq rep_strict] 
164 
(bind_fun(mk_trp(strict when_app))) 

165 
[resolve_tac [sscase1,ssplit1,strictify1] 1]; 

166 
val when_apps = let fun one_when n (con,args) = pg (when_appl :: con_appls) 

11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

167 
(bind_fun (lift_defined %: (nonlazy args, 
2033  168 
mk_trp(when_app`(con_app con args) === 
5291  169 
mk_cRep_CFun(bound_fun n 0,map %# args)))))[ 
15742  170 
asm_simp_tac (HOLCF_ss addsimps [ax_abs_iso]) 1]; 
2033  171 
in mapn one_when 1 cons end; 
1274  172 
end; 
173 
val when_rews = when_strict::when_apps; 

174 

1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

175 
(*  theorems concerning the constructors, discriminators and selectors  *) 
1274  176 

1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

177 
val dis_rews = let 
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

178 
val dis_stricts = map (fn (con,_) => pg axs_dis_def (mk_trp( 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

179 
strict(%%:(dis_name con)))) [ 
15742  180 
rtac when_strict 1]) cons; 
1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

181 
val dis_apps = let fun one_dis c (con,args)= pg axs_dis_def 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

182 
(lift_defined %: (nonlazy args, 
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

183 
(mk_trp((%%:(dis_name c))`(con_app con args) === 
16778  184 
%%:(if con=c then TT_N else FF_N))))) [ 
2033  185 
asm_simp_tac (HOLCF_ss addsimps when_rews) 1]; 
15570  186 
in List.concat(map (fn (c,_) => map (one_dis c) cons) cons) end; 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

187 
val dis_defins = map (fn (con,args) => pg [] (defined(%:x_name) ==> 
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

188 
defined(%%:(dis_name con)`%x_name)) [ 
4043  189 
rtac casedist 1, 
2033  190 
contr_tac 1, 
8149
941afb897532
added tacticals DETERM_UNTIL and DETERM_UNTIL_SOLVED
oheimb
parents:
7906
diff
changeset

191 
DETERM_UNTIL_SOLVED (CHANGED(asm_simp_tac 
2033  192 
(HOLCF_ss addsimps dis_apps) 1))]) cons; 
1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

193 
in dis_stricts @ dis_defins @ dis_apps end; 
1274  194 

16224
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15742
diff
changeset

195 
val mat_rews = let 
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15742
diff
changeset

196 
val mat_stricts = map (fn (con,_) => pg axs_mat_def (mk_trp( 
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15742
diff
changeset

197 
strict(%%:(mat_name con)))) [ 
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15742
diff
changeset

198 
rtac when_strict 1]) cons; 
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15742
diff
changeset

199 
val mat_apps = let fun one_mat c (con,args)= pg axs_mat_def 
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15742
diff
changeset

200 
(lift_defined %: (nonlazy args, 
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15742
diff
changeset

201 
(mk_trp((%%:(mat_name c))`(con_app con args) === 
16778  202 
(if con=c 
203 
then %%:returnN`(mk_ctuple (map %# args)) 

204 
else %%:failN))))) 

205 
[asm_simp_tac (HOLCF_ss addsimps when_rews) 1]; 

16224
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15742
diff
changeset

206 
in List.concat(map (fn (c,_) => map (one_mat c) cons) cons) end; 
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15742
diff
changeset

207 
in mat_stricts @ mat_apps end; 
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15742
diff
changeset

208 

15570  209 
val con_stricts = List.concat(map (fn (con,args) => map (fn vn => 
15742  210 
pg con_appls 
2033  211 
(mk_trp(con_app2 con (fn arg => if vname arg = vn 
212 
then UU else %# arg) args === UU))[ 

213 
asm_simp_tac (HOLCF_ss addsimps [abs_strict]) 1] 

214 
) (nonlazy args)) cons); 

1274  215 
val con_defins = map (fn (con,args) => pg [] 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

216 
(lift_defined %: (nonlazy args, 
2033  217 
mk_trp(defined(con_app con args)))) ([ 
2445
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
2276
diff
changeset

218 
rtac rev_contrapos 1, 
2033  219 
eres_inst_tac [("f",dis_name con)] cfun_arg_cong 1, 
220 
asm_simp_tac (HOLCF_ss addsimps dis_rews) 1] )) cons; 

1274  221 
val con_rews = con_stricts @ con_defins; 
222 

17840
11bcd77cfa22
domain package generates compactness lemmas for new constructors
huffman
parents:
17811
diff
changeset

223 
val con_compacts = 
11bcd77cfa22
domain package generates compactness lemmas for new constructors
huffman
parents:
17811
diff
changeset

224 
let 
11bcd77cfa22
domain package generates compactness lemmas for new constructors
huffman
parents:
17811
diff
changeset

225 
val rules = [compact_sinl, compact_sinr, compact_spair, compact_up, compact_ONE]; 
11bcd77cfa22
domain package generates compactness lemmas for new constructors
huffman
parents:
17811
diff
changeset

226 
fun one_compact (con,args) = pg con_appls 
11bcd77cfa22
domain package generates compactness lemmas for new constructors
huffman
parents:
17811
diff
changeset

227 
(lift (fn x => %%:compactN $ %:(vname x)) (args, mk_trp(%%:compactN $ (con_app con args)))) 
11bcd77cfa22
domain package generates compactness lemmas for new constructors
huffman
parents:
17811
diff
changeset

228 
[rtac (iso_locale RS iso_compact_abs) 1, REPEAT (resolve_tac rules 1 ORELSE atac 1)]; 
11bcd77cfa22
domain package generates compactness lemmas for new constructors
huffman
parents:
17811
diff
changeset

229 
in map one_compact cons end; 
11bcd77cfa22
domain package generates compactness lemmas for new constructors
huffman
parents:
17811
diff
changeset

230 

11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

231 
val sel_stricts = let fun one_sel sel = pg axs_sel_def (mk_trp(strict(%%:sel))) [ 
2033  232 
simp_tac (HOLCF_ss addsimps when_rews) 1]; 
16394
495dbcd4f4c9
in domain declarations, selector names are now optional
huffman
parents:
16385
diff
changeset

233 
in List.concat(map (fn (_,args) => List.mapPartial (fn arg => Option.map one_sel (sel_of arg)) args) cons) end; 
1274  234 
val sel_apps = let fun one_sel c n sel = map (fn (con,args) => 
2033  235 
let val nlas = nonlazy args; 
236 
val vns = map vname args; 

11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

237 
in pg axs_sel_def (lift_defined %: 
15570  238 
(List.filter (fn v => con=c andalso (v<>List.nth(vns,n))) nlas, 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

239 
mk_trp((%%:sel)`(con_app con args) === 
15570  240 
(if con=c then %:(List.nth(vns,n)) else UU)))) 
2033  241 
( (if con=c then [] 
242 
else map(case_UU_tac(when_rews@con_stricts)1) nlas) 

15570  243 
@(if con=c andalso ((List.nth(vns,n)) mem nlas) 
2033  244 
then[case_UU_tac (when_rews @ con_stricts) 1 
15570  245 
(List.nth(vns,n))] else []) 
2033  246 
@ [asm_simp_tac(HOLCF_ss addsimps when_rews)1])end) cons; 
15570  247 
in List.concat(map (fn (c,args) => 
16842  248 
List.concat(List.mapPartial I (mapn (fn n => fn arg => Option.map (one_sel c n) (sel_of arg)) 0 args))) cons) end; 
16394
495dbcd4f4c9
in domain declarations, selector names are now optional
huffman
parents:
16385
diff
changeset

249 
val sel_defins = if length cons=1 then List.mapPartial (fn arg => Option.map (fn sel => pg [](defined(%:x_name)==> 
495dbcd4f4c9
in domain declarations, selector names are now optional
huffman
parents:
16385
diff
changeset

250 
defined(%%:sel`%x_name)) [ 
4043  251 
rtac casedist 1, 
2033  252 
contr_tac 1, 
8149
941afb897532
added tacticals DETERM_UNTIL and DETERM_UNTIL_SOLVED
oheimb
parents:
7906
diff
changeset

253 
DETERM_UNTIL_SOLVED (CHANGED(asm_simp_tac 
16394
495dbcd4f4c9
in domain declarations, selector names are now optional
huffman
parents:
16385
diff
changeset

254 
(HOLCF_ss addsimps sel_apps) 1))])(sel_of arg)) 
2033  255 
(filter_out is_lazy (snd(hd cons))) else []; 
1274  256 
val sel_rews = sel_stricts @ sel_defins @ sel_apps; 
257 

258 
val distincts_le = let 

259 
fun dist (con1, args1) (con2, args2) = pg [] 

11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

260 
(lift_defined %: ((nonlazy args1), 
2033  261 
(mk_trp (con_app con1 args1 ~<< con_app con2 args2))))([ 
2445
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
2276
diff
changeset

262 
rtac rev_contrapos 1, 
16224
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15742
diff
changeset

263 
eres_inst_tac[("f",dis_name con1)] monofun_cfun_arg 1] 
2033  264 
@map(case_UU_tac (con_stricts @ dis_rews)1)(nonlazy args2) 
265 
@[asm_simp_tac (HOLCF_ss addsimps dis_rews) 1]); 

1274  266 
fun distinct (con1,args1) (con2,args2) = 
2267  267 
let val arg1 = (con1, args1) 
268 
val arg2 = (con2, 

269 
ListPair.map (fn (arg,vn) => upd_vname (K vn) arg) 

270 
(args2, variantlist(map vname args2,map vname args1))) 

2033  271 
in [dist arg1 arg2, dist arg2 arg1] end; 
1274  272 
fun distincts [] = [] 
273 
 distincts (c::cs) = (map (distinct c) cs) :: distincts cs; 

274 
in distincts cons end; 

15570  275 
val dist_les = List.concat (List.concat distincts_le); 
4043  276 
val dist_eqs = let 
1274  277 
fun distinct (_,args1) ((_,args2),leqs) = let 
2033  278 
val (le1,le2) = (hd leqs, hd(tl leqs)); 
279 
val (eq1,eq2) = (le1 RS dist_eqI, le2 RS dist_eqI) in 

280 
if nonlazy args1 = [] then [eq1, eq1 RS not_sym] else 

281 
if nonlazy args2 = [] then [eq2, eq2 RS not_sym] else 

282 
[eq1, eq2] end; 

1274  283 
fun distincts [] = [] 
4062  284 
 distincts ((c,leqs)::cs) = List.concat 
2267  285 
(ListPair.map (distinct c) ((map #1 cs),leqs)) @ 
286 
distincts cs; 

12037  287 
in map standard (distincts (cons~~distincts_le)) end; 
1274  288 

289 
local 

16321
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

290 
fun pgterm rel con args = 
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

291 
let 
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

292 
fun append s = upd_vname(fn v => v^s); 
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

293 
val (largs,rargs) = (args, map (append "'") args); 
17811  294 
val concl = mk_trp (foldr1 mk_conj (ListPair.map rel (map %# largs, map %# rargs))); 
16321
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

295 
val prem = mk_trp (rel(con_app con largs,con_app con rargs)); 
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

296 
val prop = prem ===> lift_defined %: (nonlazy largs, concl); 
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

297 
in pg con_appls prop end; 
15570  298 
val cons' = List.filter (fn (_,args) => args<>[]) cons; 
1274  299 
in 
16321
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

300 
val inverts = 
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

301 
let 
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

302 
val abs_less = ax_abs_iso RS (allI RS injection_less) RS iffD1; 
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

303 
val tacs = [ 
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

304 
dtac abs_less 1, 
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

305 
REPEAT (dresolve_tac [sinl_less RS iffD1, sinr_less RS iffD1] 1), 
16385  306 
asm_full_simp_tac (HOLCF_ss addsimps [spair_less]) 1]; 
16321
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

307 
in map (fn (con,args) => pgterm (op <<) con args tacs) cons' end; 
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

308 
val injects = 
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

309 
let 
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

310 
val abs_eq = ax_abs_iso RS (allI RS injection_eq) RS iffD1; 
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

311 
val tacs = [ 
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

312 
dtac abs_eq 1, 
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

313 
REPEAT (dresolve_tac [sinl_inject, sinr_inject] 1), 
16385  314 
asm_full_simp_tac (HOLCF_ss addsimps [spair_eq]) 1]; 
16321
ef32a42f4079
faster proofs of inverts and injects lemmas, with fewer strictness hypotheses
huffman
parents:
16224
diff
changeset

315 
in map (fn (con,args) => pgterm (op ===) con args tacs) cons' end; 
1274  316 
end; 
317 

1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

318 
(*  theorems concerning one induction step  *) 
1274  319 

1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

320 
val copy_strict = pg[ax_copy_def](mk_trp(strict(dc_copy`%"f"))) [ 
16224
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15742
diff
changeset

321 
asm_simp_tac(HOLCF_ss addsimps [abs_strict, when_strict]) 1]; 
1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

322 
val copy_apps = map (fn (con,args) => pg [ax_copy_def] 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

323 
(lift_defined %: (nonlazy_rec args, 
2033  324 
mk_trp(dc_copy`%"f"`(con_app con args) === 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

325 
(con_app2 con (app_rec_arg (cproj (%:"f") eqs)) args)))) 
2033  326 
(map (case_UU_tac (abs_strict::when_strict::con_stricts) 
327 
1 o vname) 

15570  328 
(List.filter (fn a => not (is_rec a orelse is_lazy a)) args) 
2033  329 
@[asm_simp_tac (HOLCF_ss addsimps when_apps) 1, 
15742  330 
simp_tac (HOLCF_ss addsimps con_appls) 1]))cons; 
1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

331 
val copy_stricts = map (fn (con,args) => pg [] (mk_trp(dc_copy`UU` 
2033  332 
(con_app con args) ===UU)) 
16224
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15742
diff
changeset

333 
(let val rews = copy_strict::copy_apps@con_rews 
2033  334 
in map (case_UU_tac rews 1) (nonlazy args) @ [ 
335 
asm_simp_tac (HOLCF_ss addsimps rews) 1] end)) 

15570  336 
(List.filter (fn (_,args)=>exists is_nonlazy_rec args) cons); 
1274  337 
val copy_rews = copy_strict::copy_apps @ copy_stricts; 
4043  338 
in thy > Theory.add_path (Sign.base_name dname) 
8438  339 
> (#1 o (PureThy.add_thmss (map Thm.no_attributes [ 
4043  340 
("iso_rews" , iso_rews ), 
341 
("exhaust" , [exhaust] ), 

342 
("casedist" , [casedist]), 

343 
("when_rews", when_rews ), 

17840
11bcd77cfa22
domain package generates compactness lemmas for new constructors
huffman
parents:
17811
diff
changeset

344 
("compacts", con_compacts), 
4043  345 
("con_rews", con_rews), 
346 
("sel_rews", sel_rews), 

347 
("dis_rews", dis_rews), 

348 
("dist_les", dist_les), 

349 
("dist_eqs", dist_eqs), 

350 
("inverts" , inverts ), 

351 
("injects" , injects ), 

8438  352 
("copy_rews", copy_rews)]))) 
16462  353 
> (#1 o PureThy.add_thmss [(("match_rews", mat_rews), [Simplifier.simp_add_global])]) 
12037  354 
> Theory.parent_path > rpair (iso_rews @ when_rews @ con_rews @ sel_rews @ dis_rews @ 
355 
dist_les @ dist_eqs @ copy_rews) 

1274  356 
end; (* let *) 
357 

4043  358 
fun comp_theorems (comp_dnam, eqs: eq list) thy = 
1274  359 
let 
4008  360 
val dnames = map (fst o fst) eqs; 
361 
val conss = map snd eqs; 

362 
val comp_dname = Sign.full_name (sign_of thy) comp_dnam; 

363 

12037  364 
val d = writeln("Proving induction properties of domain "^comp_dname^" ..."); 
1274  365 
val pg = pg' thy; 
366 

1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

367 
(*  getting the composite axiom and definitions  *) 
1274  368 

16486  369 
local fun ga s dn = get_thm thy (Name (dn ^ "." ^ s)) in 
4043  370 
val axs_reach = map (ga "reach" ) dnames; 
371 
val axs_take_def = map (ga "take_def" ) dnames; 

372 
val axs_finite_def = map (ga "finite_def") dnames; 

373 
val ax_copy2_def = ga "copy_def" comp_dnam; 

374 
val ax_bisim_def = ga "bisim_def" comp_dnam; 

375 
end; (* local *) 

376 

16486  377 
local fun gt s dn = get_thm thy (Name (dn ^ "." ^ s)); 
378 
fun gts s dn = get_thms thy (Name (dn ^ "." ^ s)) in 

4043  379 
val cases = map (gt "casedist" ) dnames; 
15570  380 
val con_rews = List.concat (map (gts "con_rews" ) dnames); 
381 
val copy_rews = List.concat (map (gts "copy_rews") dnames); 

1274  382 
end; (* local *) 
383 

11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

384 
fun dc_take dn = %%:(dn^"_take"); 
1274  385 
val x_name = idx_name dnames "x"; 
386 
val P_name = idx_name dnames "P"; 

1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

387 
val n_eqs = length eqs; 
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

388 

b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

389 
(*  theorems concerning finite approximation and finite induction  *) 
1274  390 

391 
local 

16224
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15742
diff
changeset

392 
val iterate_Cprod_ss = simpset_of Fix.thy; 
1274  393 
val copy_con_rews = copy_rews @ con_rews; 
1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

394 
val copy_take_defs =(if n_eqs = 1 then [] else [ax_copy2_def]) @ axs_take_def; 
17811  395 
val take_stricts=pg copy_take_defs(mk_trp(foldr1 mk_conj(map(fn((dn,args),_)=> 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

396 
strict(dc_take dn $ %:"n")) eqs))) ([ 
13454  397 
induct_tac "n" 1, 
4030  398 
simp_tac iterate_Cprod_ss 1, 
2033  399 
asm_simp_tac (iterate_Cprod_ss addsimps copy_rews)1]); 
1274  400 
val take_stricts' = rewrite_rule copy_take_defs take_stricts; 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

401 
val take_0s = mapn(fn n=> fn dn => pg axs_take_def(mk_trp((dc_take dn $ %%:"0") 
2033  402 
`%x_name n === UU))[ 
403 
simp_tac iterate_Cprod_ss 1]) 1 dnames; 

1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

404 
val c_UU_tac = case_UU_tac (take_stricts'::copy_con_rews) 1; 
17811  405 
val take_apps = pg copy_take_defs (mk_trp(foldr1 mk_conj 
15570  406 
(List.concat(map (fn ((dn,_),cons) => map (fn (con,args) => Library.foldr mk_all 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

407 
(map vname args,(dc_take dn $ (%%:"Suc" $ %:"n"))`(con_app con args) === 
15570  408 
con_app2 con (app_rec_arg (fn n=>dc_take (List.nth(dnames,n))$ %:"n")) 
2033  409 
args)) cons) eqs)))) ([ 
410 
simp_tac iterate_Cprod_ss 1, 

13454  411 
induct_tac "n" 1, 
2033  412 
simp_tac(iterate_Cprod_ss addsimps copy_con_rews) 1, 
413 
asm_full_simp_tac (HOLCF_ss addsimps 

15570  414 
(List.filter (has_fewer_prems 1) copy_rews)) 1, 
2033  415 
TRY(safe_tac HOL_cs)] @ 
15570  416 
(List.concat(map (fn ((dn,_),cons) => map (fn (con,args) => 
2033  417 
if nonlazy_rec args = [] then all_tac else 
418 
EVERY(map c_UU_tac (nonlazy_rec args)) THEN 

419 
asm_full_simp_tac (HOLCF_ss addsimps copy_rews)1 

420 
) cons) eqs))); 

1274  421 
in 
12037  422 
val take_rews = map standard (atomize take_stricts @ take_0s @ atomize take_apps); 
1274  423 
end; (* local *) 
424 

425 
local 

15570  426 
fun one_con p (con,args) = Library.foldr mk_All (map vname args, 
2033  427 
lift_defined (bound_arg (map vname args)) (nonlazy args, 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

428 
lift (fn arg => %:(P_name (1+rec_of arg)) $ bound_arg args arg) 
15570  429 
(List.filter is_rec args,mk_trp(%:p $ con_app2 con (bound_arg args) args)))); 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

430 
fun one_eq ((p,cons),concl) = (mk_trp(%:p $ UU) ===> 
15570  431 
Library.foldr (op ===>) (map (one_con p) cons,concl)); 
432 
fun ind_term concf = Library.foldr one_eq (mapn (fn n => fn x => (P_name n, x))1conss, 

17811  433 
mk_trp(foldr1 mk_conj (mapn concf 1 dnames))); 
1274  434 
val take_ss = HOL_ss addsimps take_rews; 
1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

435 
fun quant_tac i = EVERY(mapn(fn n=> fn _=> res_inst_tac[("x",x_name n)]spec i) 
2033  436 
1 dnames); 
15570  437 
fun ind_prems_tac prems = EVERY(List.concat (map (fn cons => ( 
2033  438 
resolve_tac prems 1 :: 
15570  439 
List.concat (map (fn (_,args) => 
2033  440 
resolve_tac prems 1 :: 
441 
map (K(atac 1)) (nonlazy args) @ 

15570  442 
map (K(atac 1)) (List.filter is_rec args)) 
2033  443 
cons))) conss)); 
1274  444 
local 
1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

445 
(* check whether every/exists constructor of the nth part of the equation: 
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

446 
it has a possibly indirectly recursive argument that isn't/is possibly 
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

447 
indirectly lazy *) 
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

448 
fun rec_to quant nfn rfn ns lazy_rec (n,cons) = quant (exists (fn arg => 
2033  449 
is_rec arg andalso not(rec_of arg mem ns) andalso 
450 
((rec_of arg = n andalso nfn(lazy_rec orelse is_lazy arg)) orelse 

451 
rec_of arg <> n andalso rec_to quant nfn rfn (rec_of arg::ns) 

15570  452 
(lazy_rec orelse is_lazy arg) (n, (List.nth(conss,rec_of arg)))) 
2033  453 
) o snd) cons; 
1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

454 
fun all_rec_to ns = rec_to forall not all_rec_to ns; 
4030  455 
fun warn (n,cons) = if all_rec_to [] false (n,cons) then (warning 
15570  456 
("domain "^List.nth(dnames,n)^" is empty!"); true) else false; 
16842  457 
fun lazy_rec_to ns = rec_to exists I lazy_rec_to ns; 
1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

458 

b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

459 
in val n__eqs = mapn (fn n => fn (_,cons) => (n,cons)) 0 eqs; 
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

460 
val is_emptys = map warn n__eqs; 
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

461 
val is_finite = forall (not o lazy_rec_to [] false) n__eqs; 
1274  462 
end; 
1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

463 
in (* local *) 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

464 
val finite_ind = pg'' thy [] (ind_term (fn n => fn dn => %:(P_name n)$ 
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

465 
(dc_take dn $ %:"n" `%(x_name n)))) (fn prems => [ 
2033  466 
quant_tac 1, 
2445
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
2276
diff
changeset

467 
simp_tac HOL_ss 1, 
13454  468 
induct_tac "n" 1, 
2033  469 
simp_tac (take_ss addsimps prems) 1, 
470 
TRY(safe_tac HOL_cs)] 

15570  471 
@ List.concat(map (fn (cons,cases) => [ 
2033  472 
res_inst_tac [("x","x")] cases 1, 
473 
asm_simp_tac (take_ss addsimps prems) 1] 

15570  474 
@ List.concat(map (fn (con,args) => 
2033  475 
asm_simp_tac take_ss 1 :: 
476 
map (fn arg => 

477 
case_UU_tac (prems@con_rews) 1 ( 

15570  478 
List.nth(dnames,rec_of arg)^"_take n$"^vname arg)) 
479 
(List.filter is_nonlazy_rec args) @ [ 

2033  480 
resolve_tac prems 1] @ 
481 
map (K (atac 1)) (nonlazy args) @ 

15570  482 
map (K (etac spec 1)) (List.filter is_rec args)) 
2033  483 
cons)) 
4043  484 
(conss~~cases))); 
1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

485 

b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

486 
val take_lemmas =mapn(fn n=> fn(dn,ax_reach)=> pg'' thy axs_take_def(mk_All("n", 
2033  487 
mk_trp(dc_take dn $ Bound 0 `%(x_name n) === 
488 
dc_take dn $ Bound 0 `%(x_name n^"'"))) 

11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

489 
===> mk_trp(%:(x_name n) === %:(x_name n^"'"))) (fn prems => [ 
2033  490 
res_inst_tac[("t",x_name n )](ax_reach RS subst) 1, 
491 
res_inst_tac[("t",x_name n^"'")](ax_reach RS subst) 1, 

492 
stac fix_def2 1, 

493 
REPEAT(CHANGED(rtac(contlub_cfun_arg RS ssubst)1 

494 
THEN chain_tac 1)), 

495 
stac contlub_cfun_fun 1, 

496 
stac contlub_cfun_fun 2, 

497 
rtac lub_equal 3, 

498 
chain_tac 1, 

499 
rtac allI 1, 

500 
resolve_tac prems 1])) 1 (dnames~~axs_reach); 

1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

501 

b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

502 
(*  theorems concerning finiteness and induction  *) 
1274  503 

504 
val (finites,ind) = if is_finite then 

1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

505 
let 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

506 
fun take_enough dn = mk_ex ("n",dc_take dn $ Bound 0 ` %:"x" === %:"x"); 
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

507 
val finite_lemmas1a = map (fn dn => pg [] (mk_trp(defined (%:"x")) ===> 
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

508 
mk_trp(mk_disj(mk_all("n",dc_take dn $ Bound 0 ` %:"x" === UU), 
2033  509 
take_enough dn)) ===> mk_trp(take_enough dn)) [ 
510 
etac disjE 1, 

511 
etac notE 1, 

512 
resolve_tac take_lemmas 1, 

513 
asm_simp_tac take_ss 1, 

514 
atac 1]) dnames; 

17811  515 
val finite_lemma1b = pg [] (mk_trp (mk_all("n",foldr1 mk_conj (mapn 
2033  516 
(fn n => fn ((dn,args),_) => mk_constrainall(x_name n,Type(dn,args), 
517 
mk_disj(dc_take dn $ Bound 1 ` Bound 0 === UU, 

518 
dc_take dn $ Bound 1 ` Bound 0 === Bound 0))) 1 eqs)))) ([ 

519 
rtac allI 1, 

13454  520 
induct_tac "n" 1, 
2033  521 
simp_tac take_ss 1, 
522 
TRY(safe_tac(empty_cs addSEs[conjE] addSIs[conjI]))] @ 

15570  523 
List.concat(mapn (fn n => fn (cons,cases) => [ 
2033  524 
simp_tac take_ss 1, 
525 
rtac allI 1, 

526 
res_inst_tac [("x",x_name n)] cases 1, 

527 
asm_simp_tac take_ss 1] @ 

15570  528 
List.concat(map (fn (con,args) => 
2033  529 
asm_simp_tac take_ss 1 :: 
15570  530 
List.concat(map (fn vn => [ 
2033  531 
eres_inst_tac [("x",vn)] all_dupE 1, 
532 
etac disjE 1, 

533 
asm_simp_tac (HOL_ss addsimps con_rews) 1, 

534 
asm_simp_tac take_ss 1]) 

535 
(nonlazy_rec args))) 

536 
cons)) 

4043  537 
1 (conss~~cases))); 
1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

538 
val finites = map (fn (dn,l1b) => pg axs_finite_def (mk_trp( 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

539 
%%:(dn^"_finite") $ %:"x"))[ 
2033  540 
case_UU_tac take_rews 1 "x", 
541 
eresolve_tac finite_lemmas1a 1, 

542 
step_tac HOL_cs 1, 

543 
step_tac HOL_cs 1, 

544 
cut_facts_tac [l1b] 1, 

545 
fast_tac HOL_cs 1]) (dnames~~atomize finite_lemma1b); 

1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

546 
in 
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

547 
(finites, 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

548 
pg'' thy[](ind_term (fn n => fn dn => %:(P_name n) $ %:(x_name n)))(fn prems => 
2033  549 
TRY(safe_tac HOL_cs) :: 
15570  550 
List.concat (map (fn (finite,fin_ind) => [ 
2033  551 
rtac(rewrite_rule axs_finite_def finite RS exE)1, 
552 
etac subst 1, 

553 
rtac fin_ind 1, 

554 
ind_prems_tac prems]) 

555 
(finites~~(atomize finite_ind)) )) 

1274  556 
) end (* let *) else 
1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

557 
(mapn (fn n => fn dn => read_instantiate_sg (sign_of thy) 
2033  558 
[("P",dn^"_finite "^x_name n)] excluded_middle) 1 dnames, 
16778  559 
pg'' thy [] (Library.foldr (op ===>) (mapn (fn n => K(mk_trp(%%:admN $ %:(P_name n)))) 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

560 
1 dnames, ind_term (fn n => fn dn => %:(P_name n) $ %:(x_name n)))) 
2033  561 
(fn prems => map (fn ax_reach => rtac (ax_reach RS subst) 1) 
562 
axs_reach @ [ 

563 
quant_tac 1, 

564 
rtac (adm_impl_admw RS wfix_ind) 1, 

4030  565 
REPEAT_DETERM(rtac adm_all2 1), 
566 
REPEAT_DETERM(TRY(rtac adm_conj 1) THEN 

567 
rtac adm_subst 1 THEN 

2033  568 
cont_tacR 1 THEN resolve_tac prems 1), 
569 
strip_tac 1, 

570 
rtac (rewrite_rule axs_take_def finite_ind) 1, 

571 
ind_prems_tac prems]) 

4755  572 
handle ERROR => (warning "Cannot prove infinite induction rule"; refl)) 
1274  573 
end; (* local *) 
574 

1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

575 
(*  theorem concerning coinduction  *) 
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

576 

1274  577 
local 
578 
val xs = mapn (fn n => K (x_name n)) 1 dnames; 

1637
b8a8ae2e5de1
Updated: 01Mar96 when functional strictified, copy_def based on when_def
oheimb
parents:
1512
diff
changeset

579 
fun bnd_arg n i = Bound(2*(n_eqs  n)i1); 
1274  580 
val take_ss = HOL_ss addsimps take_rews; 
4755  581 
val sproj = prj (fn s => K("fst("^s^")")) (fn s => K("snd("^s^")")); 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

582 
val coind_lemma=pg[ax_bisim_def](mk_trp(mk_imp(%%:(comp_dname^"_bisim") $ %:"R", 
15570  583 
Library.foldr (fn (x,t)=> mk_all(x,mk_all(x^"'",t))) (xs, 
584 
Library.foldr mk_imp (mapn (fn n => K(proj (%:"R") eqs n $ 

2033  585 
bnd_arg n 0 $ bnd_arg n 1)) 0 dnames, 
17811  586 
foldr1 mk_conj (mapn (fn n => fn dn => 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

587 
(dc_take dn $ %:"n" `bnd_arg n 0 === 
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

588 
(dc_take dn $ %:"n" `bnd_arg n 1)))0 dnames)))))) 
2033  589 
([ rtac impI 1, 
13454  590 
induct_tac "n" 1, 
2033  591 
simp_tac take_ss 1, 
592 
safe_tac HOL_cs] @ 

15570  593 
List.concat(mapn (fn n => fn x => [ 
2033  594 
rotate_tac (n+1) 1, 
595 
etac all2E 1, 

4755  596 
eres_inst_tac [("P1", sproj "R" eqs n^ 
2033  597 
" "^x^" "^x^"'")](mp RS disjE) 1, 
598 
TRY(safe_tac HOL_cs), 

599 
REPEAT(CHANGED(asm_simp_tac take_ss 1))]) 

600 
0 xs)); 

1274  601 
in 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

602 
val coind = pg [] (mk_trp(%%:(comp_dname^"_bisim") $ %:"R") ===> 
15570  603 
Library.foldr (op ===>) (mapn (fn n => fn x => 
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
10835
diff
changeset

604 
mk_trp(proj (%:"R") eqs n $ %:x $ %:(x^"'"))) 0 xs, 
17811  605 
mk_trp(foldr1 mk_conj (map (fn x => %:x === %:(x^"'")) xs)))) ([ 
2033  606 
TRY(safe_tac HOL_cs)] @ 
15570  607 
List.concat(map (fn take_lemma => [ 
2033  608 
rtac take_lemma 1, 
609 
cut_facts_tac [coind_lemma] 1, 

610 
fast_tac HOL_cs 1]) 

611 
take_lemmas)); 

1274  612 
end; (* local *) 
613 

4043  614 
in thy > Theory.add_path comp_dnam 
8438  615 
> (#1 o (PureThy.add_thmss (map Thm.no_attributes [ 
4043  616 
("take_rews" , take_rews ), 
617 
("take_lemmas", take_lemmas), 

618 
("finites" , finites ), 

619 
("finite_ind", [finite_ind]), 

620 
("ind" , [ind ]), 

8438  621 
("coind" , [coind ])]))) 
12037  622 
> Theory.parent_path > rpair take_rews 
1274  623 
end; (* let *) 
624 
end; (* local *) 

625 
end; (* struct *) 