src/HOLCF/domain/theorems.ML
author wenzelm
Sat Jan 21 23:02:14 2006 +0100 (2006-01-21)
changeset 18728 6790126ab5f6
parent 18688 abf0f018b5ec
child 18972 2905d1805e1e
permissions -rw-r--r--
simplified type attribute;
oheimb@2276
     1
(*  Title:      HOLCF/domain/theorems.ML
oheimb@2445
     2
    ID:         $Id$
wenzelm@12030
     3
    Author:     David von Oheimb
huffman@15742
     4
                New proofs/tactics by Brian Huffman
oheimb@2445
     5
wenzelm@12030
     6
Proof generator for domain section.
regensbu@1274
     7
*)
regensbu@1274
     8
wenzelm@16842
     9
val HOLCF_ss = simpset();
oheimb@2446
    10
regensbu@1274
    11
structure Domain_Theorems = struct
regensbu@1274
    12
regensbu@1274
    13
local
regensbu@1274
    14
regensbu@1274
    15
open Domain_Library;
regensbu@1274
    16
infixr 0 ===>;infixr 0 ==>;infix 0 == ; 
regensbu@1274
    17
infix 1 ===; infix 1 ~= ; infix 1 <<; infix 1 ~<<;
regensbu@1274
    18
infix 9 `   ; infix 9 `% ; infix 9 `%%; infixr 9 oo;
regensbu@1274
    19
oheimb@1637
    20
(* ----- general proof facilities ------------------------------------------- *)
regensbu@1274
    21
wenzelm@14820
    22
fun inferT sg pre_tm =
skalberg@15531
    23
  #1 (Sign.infer_types (Sign.pp sg) sg (K NONE) (K NONE) [] true ([pre_tm],propT));
regensbu@1274
    24
wenzelm@17985
    25
fun pg'' thy defs t tacs =
wenzelm@17985
    26
  let val t' = inferT thy t in
wenzelm@17985
    27
    standard (Goal.prove thy [] (Logic.strip_imp_prems t') (Logic.strip_imp_concl t')
wenzelm@17985
    28
      (fn prems => rewrite_goals_tac defs THEN EVERY (tacs (map (rewrite_rule defs) prems))))
wenzelm@17985
    29
  end;
wenzelm@17985
    30
regensbu@1274
    31
fun pg'  thy defs t tacsf=pg'' thy defs t (fn []   => tacsf 
paulson@2033
    32
                                | prems=> (cut_facts_tac prems 1)::tacsf);
regensbu@1274
    33
paulson@2033
    34
fun case_UU_tac rews i v =      case_tac (v^"=UU") i THEN
paulson@2033
    35
                                asm_simp_tac (HOLCF_ss addsimps rews) i;
regensbu@1274
    36
regensbu@1274
    37
val chain_tac = REPEAT_DETERM o resolve_tac 
slotosch@5291
    38
                [chain_iterate, ch2ch_Rep_CFunR, ch2ch_Rep_CFunL];
oheimb@1637
    39
oheimb@1637
    40
(* ----- general proofs ----------------------------------------------------- *)
regensbu@1274
    41
oheimb@1644
    42
val all2E = prove_goal HOL.thy "[| !x y . P x y; P x y ==> R |] ==> R"
oheimb@1644
    43
 (fn prems =>[
paulson@2033
    44
                                resolve_tac prems 1,
paulson@2033
    45
                                cut_facts_tac prems 1,
paulson@2033
    46
                                fast_tac HOL_cs 1]);
regensbu@1274
    47
wenzelm@18057
    48
val dist_eqI = prove_goal (the_context ()) "!!x::'a::po. ~ x << y ==> x ~= y" 
paulson@10230
    49
             (fn prems => [
paulson@10230
    50
               (blast_tac (claset() addDs [antisym_less_inverse]) 1)]);
oheimb@4755
    51
(*
oheimb@4755
    52
infixr 0 y;
oheimb@4755
    53
val b = 0;
oheimb@4755
    54
fun _ y t = by t;
oheimb@4755
    55
fun g defs t = let val sg = sign_of thy;
oheimb@4755
    56
                     val ct = Thm.cterm_of sg (inferT sg t);
oheimb@4755
    57
                 in goalw_cterm defs ct end;
oheimb@4755
    58
*)
regensbu@1274
    59
regensbu@1274
    60
in
regensbu@1274
    61
oheimb@4043
    62
fun theorems (((dname,_),cons) : eq, eqs : eq list) thy =
regensbu@1274
    63
let
regensbu@1274
    64
oheimb@4030
    65
val dummy = writeln ("Proving isomorphism properties of domain "^dname^" ...");
regensbu@1274
    66
val pg = pg' thy;
regensbu@1274
    67
oheimb@1637
    68
(* ----- getting the axioms and definitions --------------------------------- *)
regensbu@1274
    69
wenzelm@16486
    70
local fun ga s dn = get_thm thy (Name (dn ^ "." ^ s)) in
oheimb@4043
    71
val ax_abs_iso    = ga "abs_iso"  dname;
oheimb@4043
    72
val ax_rep_iso    = ga "rep_iso"  dname;
oheimb@4043
    73
val ax_when_def   = ga "when_def" dname;
oheimb@4043
    74
val axs_con_def   = map (fn (con,_) => ga (extern_name con^"_def") dname) cons;
oheimb@4043
    75
val axs_dis_def   = map (fn (con,_) => ga (   dis_name con^"_def") dname) cons;
huffman@16224
    76
val axs_mat_def   = map (fn (con,_) => ga (   mat_name con^"_def") dname) cons;
huffman@18113
    77
val axs_pat_def   = map (fn (con,_) => ga (   pat_name con^"_def") dname) cons;
huffman@16394
    78
val axs_sel_def   = List.concat(map (fn (_,args) => List.mapPartial (fn arg =>
huffman@16394
    79
                 Option.map (fn sel => ga (sel^"_def") dname) (sel_of arg)) args)
oheimb@4043
    80
									  cons);
oheimb@4043
    81
val ax_copy_def   = ga "copy_def" dname;
regensbu@1274
    82
end; (* local *)
regensbu@1274
    83
oheimb@1637
    84
(* ----- theorems concerning the isomorphism -------------------------------- *)
regensbu@1274
    85
berghofe@11531
    86
val dc_abs  = %%:(dname^"_abs");
berghofe@11531
    87
val dc_rep  = %%:(dname^"_rep");
berghofe@11531
    88
val dc_copy = %%:(dname^"_copy");
regensbu@1274
    89
val x_name = "x";
regensbu@1274
    90
huffman@15742
    91
val iso_locale = iso_intro OF [ax_abs_iso, ax_rep_iso];
huffman@16224
    92
val abs_strict = ax_rep_iso RS (allI RS retraction_strict);
huffman@16224
    93
val rep_strict = ax_abs_iso RS (allI RS retraction_strict);
huffman@15742
    94
val abs_defin' = iso_locale RS iso_abs_defin';
huffman@15742
    95
val rep_defin' = iso_locale RS iso_rep_defin';
wenzelm@12037
    96
val iso_rews = map standard [ax_abs_iso,ax_rep_iso,abs_strict,rep_strict];
regensbu@1274
    97
huffman@15742
    98
(* ----- generating beta reduction rules from definitions-------------------- *)
huffman@15742
    99
huffman@15742
   100
local
huffman@15742
   101
  fun arglist (Const _ $ Abs (s,_,t)) = let
huffman@15742
   102
        val (vars,body) = arglist t
huffman@15742
   103
        in  (s :: vars, body) end
huffman@15742
   104
  |   arglist t = ([],t);
huffman@15742
   105
  fun bind_fun vars t = Library.foldr mk_All (vars,t);
huffman@15742
   106
  fun bound_vars 0 = [] | bound_vars i = (Bound (i-1) :: bound_vars (i-1));
huffman@15742
   107
in
huffman@15742
   108
  fun appl_of_def def = let
huffman@16403
   109
        val (_ $ con $ lam) = concl_of def;
huffman@16403
   110
        val (vars, rhs) = arglist lam;
huffman@18083
   111
        val lhs = list_ccomb (con, bound_vars (length vars));
huffman@16403
   112
        val appl = bind_fun vars (lhs == rhs);
huffman@16403
   113
        val cs = ContProc.cont_thms lam;
huffman@16403
   114
        val betas = map (fn c => mk_meta_eq (c RS beta_cfun)) cs;
huffman@15742
   115
        in pg (def::betas) appl [rtac reflexive_thm 1] end;
huffman@15742
   116
end;
huffman@15742
   117
huffman@15742
   118
val when_appl = appl_of_def ax_when_def;
huffman@15742
   119
val con_appls = map appl_of_def axs_con_def;
huffman@15742
   120
huffman@15742
   121
local
huffman@16778
   122
  fun arg2typ n arg = let val t = TVar (("'a",n),pcpoS)
huffman@15742
   123
                      in (n+1, if is_lazy arg then mk_uT t else t) end;
huffman@15742
   124
  fun args2typ n [] = (n,oneT)
huffman@15742
   125
  |   args2typ n [arg] = arg2typ n arg
huffman@15742
   126
  |   args2typ n (arg::args) = let val (n1,t1) = arg2typ n arg;
huffman@15742
   127
                                   val (n2,t2) = args2typ n1 args
huffman@15742
   128
			       in  (n2, mk_sprodT (t1, t2)) end;
huffman@15742
   129
  fun cons2typ n [] = (n,oneT)
huffman@15742
   130
  |   cons2typ n [con] = args2typ n (snd con)
huffman@15742
   131
  |   cons2typ n (con::cons) = let val (n1,t1) = args2typ n (snd con);
huffman@15742
   132
                                   val (n2,t2) = cons2typ n1 cons
huffman@15742
   133
			       in  (n2, mk_ssumT (t1, t2)) end;
huffman@15742
   134
in
huffman@15742
   135
  fun cons2ctyp cons = ctyp_of (sign_of thy) (snd (cons2typ 1 cons));
huffman@15742
   136
end;
huffman@15742
   137
regensbu@1274
   138
local 
huffman@15742
   139
  val iso_swap = iso_locale RS iso_iso_swap;
regensbu@1274
   140
  fun one_con (con,args) = let val vns = map vname args in
huffman@17811
   141
    Library.foldr mk_ex (vns, foldr1 mk_conj ((%:x_name === con_app2 con %: vns)::
huffman@15742
   142
                              map (defined o %:) (nonlazy args))) end;
huffman@17811
   143
  val exh = foldr1 mk_disj ((%:x_name===UU)::map one_con cons);
huffman@15742
   144
  val my_ctyp = cons2ctyp cons;
huffman@15742
   145
  val thm1 = instantiate' [SOME my_ctyp] [] exh_start;
huffman@15742
   146
  val thm2 = rewrite_rule (map mk_meta_eq ex_defined_iffs) thm1;
huffman@15742
   147
  val thm3 = rewrite_rule [mk_meta_eq conj_assoc] thm2;
regensbu@1274
   148
in
huffman@15742
   149
val exhaust = pg con_appls (mk_trp exh)[
huffman@15742
   150
(* first 3 rules replace "x = UU \/ P" with "rep$x = UU \/ P" *)
huffman@15742
   151
			rtac disjE 1,
huffman@15742
   152
			etac (rep_defin' RS disjI1) 2,
huffman@15742
   153
			etac disjI2 2,
huffman@15742
   154
			rewrite_goals_tac [mk_meta_eq iso_swap],
huffman@15742
   155
			rtac thm3 1];
huffman@15742
   156
val casedist = standard (rewrite_rule exh_casedists (exhaust RS exh_casedist0));
regensbu@1274
   157
end;
regensbu@1274
   158
regensbu@1274
   159
local 
skalberg@15570
   160
  fun bind_fun t = Library.foldr mk_All (when_funs cons,t);
oheimb@1829
   161
  fun bound_fun i _ = Bound (length cons - i);
huffman@18083
   162
  val when_app  = list_ccomb (%%:(dname^"_when"), mapn bound_fun 1 cons);
regensbu@1274
   163
in
huffman@15742
   164
val when_strict = pg [when_appl, mk_meta_eq rep_strict]
huffman@15742
   165
			(bind_fun(mk_trp(strict when_app)))
huffman@15742
   166
			[resolve_tac [sscase1,ssplit1,strictify1] 1];
huffman@15742
   167
val when_apps = let fun one_when n (con,args) = pg (when_appl :: con_appls)
berghofe@11531
   168
                (bind_fun (lift_defined %: (nonlazy args, 
paulson@2033
   169
                mk_trp(when_app`(con_app con args) ===
huffman@18083
   170
                       list_ccomb(bound_fun n 0,map %# args)))))[
huffman@15742
   171
                asm_simp_tac (HOLCF_ss addsimps [ax_abs_iso]) 1];
paulson@2033
   172
        in mapn one_when 1 cons end;
regensbu@1274
   173
end;
regensbu@1274
   174
val when_rews = when_strict::when_apps;
regensbu@1274
   175
oheimb@1637
   176
(* ----- theorems concerning the constructors, discriminators and selectors - *)
regensbu@1274
   177
oheimb@1637
   178
val dis_rews = let
oheimb@1637
   179
  val dis_stricts = map (fn (con,_) => pg axs_dis_def (mk_trp(
berghofe@11531
   180
                             strict(%%:(dis_name con)))) [
huffman@15742
   181
                                rtac when_strict 1]) cons;
oheimb@1637
   182
  val dis_apps = let fun one_dis c (con,args)= pg axs_dis_def
berghofe@11531
   183
                   (lift_defined %: (nonlazy args,
berghofe@11531
   184
                        (mk_trp((%%:(dis_name c))`(con_app con args) ===
huffman@16778
   185
                              %%:(if con=c then TT_N else FF_N))))) [
paulson@2033
   186
                                asm_simp_tac (HOLCF_ss addsimps when_rews) 1];
skalberg@15570
   187
        in List.concat(map (fn (c,_) => map (one_dis c) cons) cons) end;
berghofe@11531
   188
  val dis_defins = map (fn (con,args) => pg [] (defined(%:x_name) ==> 
berghofe@11531
   189
                      defined(%%:(dis_name con)`%x_name)) [
oheimb@4043
   190
                                rtac casedist 1,
paulson@2033
   191
                                contr_tac 1,
oheimb@8149
   192
                                DETERM_UNTIL_SOLVED (CHANGED(asm_simp_tac 
paulson@2033
   193
                                        (HOLCF_ss addsimps dis_apps) 1))]) cons;
oheimb@1637
   194
in dis_stricts @ dis_defins @ dis_apps end;
regensbu@1274
   195
huffman@16224
   196
val mat_rews = let
huffman@16224
   197
  val mat_stricts = map (fn (con,_) => pg axs_mat_def (mk_trp(
huffman@16224
   198
                             strict(%%:(mat_name con)))) [
huffman@16224
   199
                                rtac when_strict 1]) cons;
huffman@16224
   200
  val mat_apps = let fun one_mat c (con,args)= pg axs_mat_def
huffman@16224
   201
                   (lift_defined %: (nonlazy args,
huffman@16224
   202
                        (mk_trp((%%:(mat_name c))`(con_app con args) ===
huffman@16778
   203
                              (if con=c
huffman@16778
   204
                                  then %%:returnN`(mk_ctuple (map %# args))
huffman@16778
   205
                                  else %%:failN)))))
huffman@16778
   206
                   [asm_simp_tac (HOLCF_ss addsimps when_rews) 1];
huffman@16224
   207
        in List.concat(map (fn (c,_) => map (one_mat c) cons) cons) end;
huffman@16224
   208
in mat_stricts @ mat_apps end;
huffman@16224
   209
huffman@18113
   210
val pat_rews = let
huffman@18113
   211
  fun ps args = mapn (fn n => fn _ => %:("pat" ^ string_of_int n)) 1 args;
huffman@18293
   212
  fun pat_lhs (con,args) = %%:branchN $ list_comb (%%:(pat_name con), ps args);
huffman@18293
   213
  fun pat_rhs (con,[]) = %%:returnN ` ((%:"rhs") ` HOLogic.unit)
huffman@18293
   214
  |   pat_rhs (con,args) =
huffman@18293
   215
        (%%:branchN $ foldr1 cpair_pat (ps args))`(%:"rhs")`(mk_ctuple (map %# args));
huffman@18293
   216
  val pat_stricts = map (fn (con,args) => pg (branch_def::axs_pat_def)
huffman@18293
   217
                      (mk_trp(strict(pat_lhs (con,args)`(%:"rhs"))))
huffman@18293
   218
                      [simp_tac (HOLCF_ss addsimps [when_strict]) 1]) cons;
huffman@18293
   219
  val pat_apps = let fun one_pat c (con,args) = pg (branch_def::axs_pat_def)
huffman@18113
   220
                   (lift_defined %: (nonlazy args,
huffman@18113
   221
                        (mk_trp((pat_lhs c)`(%:"rhs")`(con_app con args) ===
huffman@18113
   222
                              (if con = fst c then pat_rhs c else %%:failN)))))
huffman@18113
   223
                   [asm_simp_tac (HOLCF_ss addsimps when_rews) 1];
huffman@18293
   224
        in List.concat (map (fn c => map (one_pat c) cons) cons) end;
huffman@18113
   225
in pat_stricts @ pat_apps end;
huffman@18113
   226
skalberg@15570
   227
val con_stricts = List.concat(map (fn (con,args) => map (fn vn =>
huffman@15742
   228
                        pg con_appls
paulson@2033
   229
                           (mk_trp(con_app2 con (fn arg => if vname arg = vn 
paulson@2033
   230
                                        then UU else %# arg) args === UU))[
paulson@2033
   231
                                asm_simp_tac (HOLCF_ss addsimps [abs_strict]) 1]
paulson@2033
   232
                        ) (nonlazy args)) cons);
regensbu@1274
   233
val con_defins = map (fn (con,args) => pg []
berghofe@11531
   234
                        (lift_defined %: (nonlazy args,
paulson@2033
   235
                                mk_trp(defined(con_app con args)))) ([
oheimb@2445
   236
                          rtac rev_contrapos 1, 
paulson@2033
   237
                          eres_inst_tac [("f",dis_name con)] cfun_arg_cong 1,
paulson@2033
   238
                          asm_simp_tac (HOLCF_ss addsimps dis_rews) 1] )) cons;
regensbu@1274
   239
val con_rews = con_stricts @ con_defins;
regensbu@1274
   240
huffman@17840
   241
val con_compacts =
huffman@17840
   242
  let
huffman@17840
   243
    val rules = [compact_sinl, compact_sinr, compact_spair, compact_up, compact_ONE];
huffman@17840
   244
    fun one_compact (con,args) = pg con_appls
huffman@18083
   245
      (lift (fn x => %%:compactN $ %#x) (args, mk_trp(%%:compactN $ (con_app con args))))
huffman@17840
   246
      [rtac (iso_locale RS iso_compact_abs) 1, REPEAT (resolve_tac rules 1 ORELSE atac 1)];
huffman@17840
   247
  in map one_compact cons end;
huffman@17840
   248
berghofe@11531
   249
val sel_stricts = let fun one_sel sel = pg axs_sel_def (mk_trp(strict(%%:sel))) [
paulson@2033
   250
                                simp_tac (HOLCF_ss addsimps when_rews) 1];
huffman@16394
   251
in List.concat(map (fn (_,args) => List.mapPartial (fn arg => Option.map one_sel (sel_of arg)) args) cons) end;
regensbu@1274
   252
val sel_apps = let fun one_sel c n sel = map (fn (con,args) => 
paulson@2033
   253
                let val nlas = nonlazy args;
paulson@2033
   254
                    val vns  = map vname args;
berghofe@11531
   255
                in pg axs_sel_def (lift_defined %:
skalberg@15570
   256
                   (List.filter (fn v => con=c andalso (v<>List.nth(vns,n))) nlas,
berghofe@11531
   257
                                mk_trp((%%:sel)`(con_app con args) === 
skalberg@15570
   258
                                (if con=c then %:(List.nth(vns,n)) else UU))))
paulson@2033
   259
                            ( (if con=c then [] 
paulson@2033
   260
                       else map(case_UU_tac(when_rews@con_stricts)1) nlas)
skalberg@15570
   261
                     @(if con=c andalso ((List.nth(vns,n)) mem nlas)
paulson@2033
   262
                                 then[case_UU_tac (when_rews @ con_stricts) 1 
skalberg@15570
   263
                                                  (List.nth(vns,n))] else [])
paulson@2033
   264
                     @ [asm_simp_tac(HOLCF_ss addsimps when_rews)1])end) cons;
skalberg@15570
   265
in List.concat(map  (fn (c,args) => 
wenzelm@16842
   266
     List.concat(List.mapPartial I (mapn (fn n => fn arg => Option.map (one_sel c n) (sel_of arg)) 0 args))) cons) end;
huffman@16394
   267
val sel_defins = if length cons=1 then List.mapPartial (fn arg => Option.map (fn sel => pg [](defined(%:x_name)==> 
huffman@16394
   268
                        defined(%%:sel`%x_name)) [
oheimb@4043
   269
                                rtac casedist 1,
paulson@2033
   270
                                contr_tac 1,
oheimb@8149
   271
                                DETERM_UNTIL_SOLVED (CHANGED(asm_simp_tac 
huffman@16394
   272
                                             (HOLCF_ss addsimps sel_apps) 1))])(sel_of arg)) 
paulson@2033
   273
                 (filter_out is_lazy (snd(hd cons))) else [];
regensbu@1274
   274
val sel_rews = sel_stricts @ sel_defins @ sel_apps;
regensbu@1274
   275
regensbu@1274
   276
val distincts_le = let
regensbu@1274
   277
    fun dist (con1, args1) (con2, args2) = pg []
berghofe@11531
   278
              (lift_defined %: ((nonlazy args1),
paulson@2033
   279
                        (mk_trp (con_app con1 args1 ~<< con_app con2 args2))))([
oheimb@2445
   280
                        rtac rev_contrapos 1,
huffman@16224
   281
                        eres_inst_tac[("f",dis_name con1)] monofun_cfun_arg 1]
paulson@2033
   282
                      @map(case_UU_tac (con_stricts @ dis_rews)1)(nonlazy args2)
paulson@2033
   283
                      @[asm_simp_tac (HOLCF_ss addsimps dis_rews) 1]);
regensbu@1274
   284
    fun distinct (con1,args1) (con2,args2) =
paulson@2267
   285
        let val arg1 = (con1, args1)
paulson@2267
   286
            val arg2 = (con2,
paulson@2267
   287
			ListPair.map (fn (arg,vn) => upd_vname (K vn) arg)
paulson@2267
   288
                        (args2, variantlist(map vname args2,map vname args1)))
paulson@2033
   289
        in [dist arg1 arg2, dist arg2 arg1] end;
regensbu@1274
   290
    fun distincts []      = []
regensbu@1274
   291
    |   distincts (c::cs) = (map (distinct c) cs) :: distincts cs;
regensbu@1274
   292
in distincts cons end;
skalberg@15570
   293
val dist_les = List.concat (List.concat distincts_le);
oheimb@4043
   294
val dist_eqs = let
regensbu@1274
   295
    fun distinct (_,args1) ((_,args2),leqs) = let
paulson@2033
   296
        val (le1,le2) = (hd leqs, hd(tl leqs));
paulson@2033
   297
        val (eq1,eq2) = (le1 RS dist_eqI, le2 RS dist_eqI) in
paulson@2033
   298
        if nonlazy args1 = [] then [eq1, eq1 RS not_sym] else
paulson@2033
   299
        if nonlazy args2 = [] then [eq2, eq2 RS not_sym] else
paulson@2033
   300
                                        [eq1, eq2] end;
regensbu@1274
   301
    fun distincts []      = []
paulson@4062
   302
    |   distincts ((c,leqs)::cs) = List.concat
paulson@2267
   303
	            (ListPair.map (distinct c) ((map #1 cs),leqs)) @
paulson@2267
   304
		    distincts cs;
wenzelm@12037
   305
    in map standard (distincts (cons~~distincts_le)) end;
regensbu@1274
   306
regensbu@1274
   307
local 
huffman@16321
   308
  fun pgterm rel con args =
huffman@16321
   309
    let
huffman@16321
   310
      fun append s = upd_vname(fn v => v^s);
huffman@16321
   311
      val (largs,rargs) = (args, map (append "'") args);
huffman@17811
   312
      val concl = mk_trp (foldr1 mk_conj (ListPair.map rel (map %# largs, map %# rargs)));
huffman@16321
   313
      val prem = mk_trp (rel(con_app con largs,con_app con rargs));
huffman@16321
   314
      val prop = prem ===> lift_defined %: (nonlazy largs, concl);
huffman@16321
   315
    in pg con_appls prop end;
skalberg@15570
   316
  val cons' = List.filter (fn (_,args) => args<>[]) cons;
regensbu@1274
   317
in
huffman@16321
   318
val inverts =
huffman@16321
   319
  let
huffman@16321
   320
    val abs_less = ax_abs_iso RS (allI RS injection_less) RS iffD1;
huffman@16321
   321
    val tacs = [
huffman@16321
   322
      dtac abs_less 1,
huffman@16321
   323
      REPEAT (dresolve_tac [sinl_less RS iffD1, sinr_less RS iffD1] 1),
huffman@16385
   324
      asm_full_simp_tac (HOLCF_ss addsimps [spair_less]) 1];
huffman@16321
   325
  in map (fn (con,args) => pgterm (op <<) con args tacs) cons' end;
huffman@16321
   326
val injects =
huffman@16321
   327
  let
huffman@16321
   328
    val abs_eq = ax_abs_iso RS (allI RS injection_eq) RS iffD1;
huffman@16321
   329
    val tacs = [
huffman@16321
   330
      dtac abs_eq 1,
huffman@16321
   331
      REPEAT (dresolve_tac [sinl_inject, sinr_inject] 1),
huffman@16385
   332
      asm_full_simp_tac (HOLCF_ss addsimps [spair_eq]) 1];
huffman@16321
   333
  in map (fn (con,args) => pgterm (op ===) con args tacs) cons' end;
regensbu@1274
   334
end;
regensbu@1274
   335
oheimb@1637
   336
(* ----- theorems concerning one induction step ----------------------------- *)
regensbu@1274
   337
oheimb@1637
   338
val copy_strict = pg[ax_copy_def](mk_trp(strict(dc_copy`%"f"))) [
huffman@16224
   339
                   asm_simp_tac(HOLCF_ss addsimps [abs_strict, when_strict]) 1];
oheimb@1637
   340
val copy_apps = map (fn (con,args) => pg [ax_copy_def]
berghofe@11531
   341
                    (lift_defined %: (nonlazy_rec args,
paulson@2033
   342
                        mk_trp(dc_copy`%"f"`(con_app con args) ===
berghofe@11531
   343
                (con_app2 con (app_rec_arg (cproj (%:"f") eqs)) args))))
paulson@2033
   344
                        (map (case_UU_tac (abs_strict::when_strict::con_stricts)
paulson@2033
   345
                                 1 o vname)
skalberg@15570
   346
                         (List.filter (fn a => not (is_rec a orelse is_lazy a)) args)
huffman@18084
   347
                        @[asm_simp_tac (HOLCF_ss addsimps when_apps) 1]))cons;
oheimb@1637
   348
val copy_stricts = map (fn (con,args) => pg [] (mk_trp(dc_copy`UU`
paulson@2033
   349
                                        (con_app con args) ===UU))
huffman@16224
   350
     (let val rews = copy_strict::copy_apps@con_rews
paulson@2033
   351
                         in map (case_UU_tac rews 1) (nonlazy args) @ [
paulson@2033
   352
                             asm_simp_tac (HOLCF_ss addsimps rews) 1] end))
skalberg@15570
   353
                        (List.filter (fn (_,args)=>exists is_nonlazy_rec args) cons);
regensbu@1274
   354
val copy_rews = copy_strict::copy_apps @ copy_stricts;
oheimb@4043
   355
in thy |> Theory.add_path (Sign.base_name dname)
haftmann@18377
   356
       |> (snd o (PureThy.add_thmss (map Thm.no_attributes [
oheimb@4043
   357
		("iso_rews" , iso_rews  ),
oheimb@4043
   358
		("exhaust"  , [exhaust] ),
oheimb@4043
   359
		("casedist" , [casedist]),
oheimb@4043
   360
		("when_rews", when_rews ),
huffman@17840
   361
		("compacts", con_compacts),
oheimb@4043
   362
		("con_rews", con_rews),
oheimb@4043
   363
		("sel_rews", sel_rews),
oheimb@4043
   364
		("dis_rews", dis_rews),
huffman@18113
   365
		("pat_rews", pat_rews),
oheimb@4043
   366
		("dist_les", dist_les),
oheimb@4043
   367
		("dist_eqs", dist_eqs),
oheimb@4043
   368
		("inverts" , inverts ),
oheimb@4043
   369
		("injects" , injects ),
wenzelm@8438
   370
		("copy_rews", copy_rews)])))
wenzelm@18728
   371
       |> (snd o PureThy.add_thmss [(("match_rews", mat_rews), [Simplifier.simp_add])])
wenzelm@12037
   372
       |> Theory.parent_path |> rpair (iso_rews @ when_rews @ con_rews @ sel_rews @ dis_rews @
huffman@18293
   373
                 pat_rews @ dist_les @ dist_eqs @ copy_rews)
regensbu@1274
   374
end; (* let *)
regensbu@1274
   375
oheimb@4043
   376
fun comp_theorems (comp_dnam, eqs: eq list) thy =
regensbu@1274
   377
let
oheimb@4008
   378
val dnames = map (fst o fst) eqs;
oheimb@4008
   379
val conss  = map  snd        eqs;
oheimb@4008
   380
val comp_dname = Sign.full_name (sign_of thy) comp_dnam;
oheimb@4008
   381
wenzelm@12037
   382
val d = writeln("Proving induction properties of domain "^comp_dname^" ...");
regensbu@1274
   383
val pg = pg' thy;
regensbu@1274
   384
oheimb@1637
   385
(* ----- getting the composite axiom and definitions ------------------------ *)
regensbu@1274
   386
wenzelm@16486
   387
local fun ga s dn = get_thm thy (Name (dn ^ "." ^ s)) in
oheimb@4043
   388
val axs_reach      = map (ga "reach"     ) dnames;
oheimb@4043
   389
val axs_take_def   = map (ga "take_def"  ) dnames;
oheimb@4043
   390
val axs_finite_def = map (ga "finite_def") dnames;
oheimb@4043
   391
val ax_copy2_def   =      ga "copy_def"  comp_dnam;
oheimb@4043
   392
val ax_bisim_def   =      ga "bisim_def" comp_dnam;
oheimb@4043
   393
end; (* local *)
oheimb@4043
   394
wenzelm@16486
   395
local fun gt  s dn = get_thm  thy (Name (dn ^ "." ^ s));
wenzelm@16486
   396
      fun gts s dn = get_thms thy (Name (dn ^ "." ^ s)) in
oheimb@4043
   397
val cases     =       map (gt  "casedist" ) dnames;
skalberg@15570
   398
val con_rews  = List.concat (map (gts "con_rews" ) dnames);
skalberg@15570
   399
val copy_rews = List.concat (map (gts "copy_rews") dnames);
regensbu@1274
   400
end; (* local *)
regensbu@1274
   401
berghofe@11531
   402
fun dc_take dn = %%:(dn^"_take");
regensbu@1274
   403
val x_name = idx_name dnames "x"; 
regensbu@1274
   404
val P_name = idx_name dnames "P";
oheimb@1637
   405
val n_eqs = length eqs;
oheimb@1637
   406
oheimb@1637
   407
(* ----- theorems concerning finite approximation and finite induction ------ *)
regensbu@1274
   408
regensbu@1274
   409
local
huffman@16224
   410
  val iterate_Cprod_ss = simpset_of Fix.thy;
regensbu@1274
   411
  val copy_con_rews  = copy_rews @ con_rews;
huffman@18083
   412
  val copy_take_defs = (if n_eqs = 1 then [] else [ax_copy2_def]) @ axs_take_def;
huffman@17811
   413
  val take_stricts=pg copy_take_defs(mk_trp(foldr1 mk_conj(map(fn((dn,args),_)=>
berghofe@11531
   414
            strict(dc_take dn $ %:"n")) eqs))) ([
berghofe@13454
   415
                        induct_tac "n" 1,
huffman@18083
   416
                        simp_tac iterate_Cprod_ss 1,
paulson@2033
   417
                        asm_simp_tac (iterate_Cprod_ss addsimps copy_rews)1]);
regensbu@1274
   418
  val take_stricts' = rewrite_rule copy_take_defs take_stricts;
berghofe@11531
   419
  val take_0s = mapn(fn n=> fn dn => pg axs_take_def(mk_trp((dc_take dn $ %%:"0")
paulson@2033
   420
                                                        `%x_name n === UU))[
paulson@2033
   421
                                simp_tac iterate_Cprod_ss 1]) 1 dnames;
oheimb@1637
   422
  val c_UU_tac = case_UU_tac (take_stricts'::copy_con_rews) 1;
huffman@17811
   423
  val take_apps = pg copy_take_defs (mk_trp(foldr1 mk_conj 
skalberg@15570
   424
            (List.concat(map (fn ((dn,_),cons) => map (fn (con,args) => Library.foldr mk_all 
berghofe@11531
   425
        (map vname args,(dc_take dn $ (%%:"Suc" $ %:"n"))`(con_app con args) ===
skalberg@15570
   426
         con_app2 con (app_rec_arg (fn n=>dc_take (List.nth(dnames,n))$ %:"n"))
paulson@2033
   427
                              args)) cons) eqs)))) ([
paulson@2033
   428
                                simp_tac iterate_Cprod_ss 1,
berghofe@13454
   429
                                induct_tac "n" 1,
paulson@2033
   430
                            simp_tac(iterate_Cprod_ss addsimps copy_con_rews) 1,
paulson@2033
   431
                                asm_full_simp_tac (HOLCF_ss addsimps 
skalberg@15570
   432
                                      (List.filter (has_fewer_prems 1) copy_rews)) 1,
paulson@2033
   433
                                TRY(safe_tac HOL_cs)] @
skalberg@15570
   434
                        (List.concat(map (fn ((dn,_),cons) => map (fn (con,args) => 
paulson@2033
   435
                                if nonlazy_rec args = [] then all_tac else
paulson@2033
   436
                                EVERY(map c_UU_tac (nonlazy_rec args)) THEN
paulson@2033
   437
                                asm_full_simp_tac (HOLCF_ss addsimps copy_rews)1
paulson@2033
   438
                                                           ) cons) eqs)));
regensbu@1274
   439
in
wenzelm@12037
   440
val take_rews = map standard (atomize take_stricts @ take_0s @ atomize take_apps);
regensbu@1274
   441
end; (* local *)
regensbu@1274
   442
regensbu@1274
   443
local
skalberg@15570
   444
  fun one_con p (con,args) = Library.foldr mk_All (map vname args,
paulson@2033
   445
        lift_defined (bound_arg (map vname args)) (nonlazy args,
berghofe@11531
   446
        lift (fn arg => %:(P_name (1+rec_of arg)) $ bound_arg args arg)
skalberg@15570
   447
         (List.filter is_rec args,mk_trp(%:p $ con_app2 con (bound_arg args) args))));
berghofe@11531
   448
  fun one_eq ((p,cons),concl) = (mk_trp(%:p $ UU) ===> 
skalberg@15570
   449
                           Library.foldr (op ===>) (map (one_con p) cons,concl));
skalberg@15570
   450
  fun ind_term concf = Library.foldr one_eq (mapn (fn n => fn x => (P_name n, x))1conss,
huffman@17811
   451
                        mk_trp(foldr1 mk_conj (mapn concf 1 dnames)));
regensbu@1274
   452
  val take_ss = HOL_ss addsimps take_rews;
oheimb@1637
   453
  fun quant_tac i = EVERY(mapn(fn n=> fn _=> res_inst_tac[("x",x_name n)]spec i)
paulson@2033
   454
                               1 dnames);
skalberg@15570
   455
  fun ind_prems_tac prems = EVERY(List.concat (map (fn cons => (
paulson@2033
   456
                                     resolve_tac prems 1 ::
skalberg@15570
   457
                                     List.concat (map (fn (_,args) => 
paulson@2033
   458
                                       resolve_tac prems 1 ::
paulson@2033
   459
                                       map (K(atac 1)) (nonlazy args) @
skalberg@15570
   460
                                       map (K(atac 1)) (List.filter is_rec args))
paulson@2033
   461
                                     cons))) conss));
regensbu@1274
   462
  local 
oheimb@1637
   463
    (* check whether every/exists constructor of the n-th part of the equation:
oheimb@1637
   464
       it has a possibly indirectly recursive argument that isn't/is possibly 
oheimb@1637
   465
       indirectly lazy *)
oheimb@1637
   466
    fun rec_to quant nfn rfn ns lazy_rec (n,cons) = quant (exists (fn arg => 
paulson@2033
   467
          is_rec arg andalso not(rec_of arg mem ns) andalso
paulson@2033
   468
          ((rec_of arg =  n andalso nfn(lazy_rec orelse is_lazy arg)) orelse 
paulson@2033
   469
            rec_of arg <> n andalso rec_to quant nfn rfn (rec_of arg::ns) 
skalberg@15570
   470
              (lazy_rec orelse is_lazy arg) (n, (List.nth(conss,rec_of arg))))
paulson@2033
   471
          ) o snd) cons;
oheimb@1637
   472
    fun all_rec_to ns  = rec_to forall not all_rec_to  ns;
oheimb@4030
   473
    fun warn (n,cons)  = if all_rec_to [] false (n,cons) then (warning
skalberg@15570
   474
        ("domain "^List.nth(dnames,n)^" is empty!"); true) else false;
wenzelm@16842
   475
    fun lazy_rec_to ns = rec_to exists I  lazy_rec_to ns;
oheimb@1637
   476
oheimb@1637
   477
  in val n__eqs     = mapn (fn n => fn (_,cons) => (n,cons)) 0 eqs;
oheimb@1637
   478
     val is_emptys = map warn n__eqs;
oheimb@1637
   479
     val is_finite = forall (not o lazy_rec_to [] false) n__eqs;
regensbu@1274
   480
  end;
oheimb@1637
   481
in (* local *)
berghofe@11531
   482
val finite_ind = pg'' thy [] (ind_term (fn n => fn dn => %:(P_name n)$
berghofe@11531
   483
                             (dc_take dn $ %:"n" `%(x_name n)))) (fn prems => [
paulson@2033
   484
                                quant_tac 1,
oheimb@2445
   485
                                simp_tac HOL_ss 1,
berghofe@13454
   486
                                induct_tac "n" 1,
paulson@2033
   487
                                simp_tac (take_ss addsimps prems) 1,
paulson@2033
   488
                                TRY(safe_tac HOL_cs)]
skalberg@15570
   489
                                @ List.concat(map (fn (cons,cases) => [
paulson@2033
   490
                                 res_inst_tac [("x","x")] cases 1,
paulson@2033
   491
                                 asm_simp_tac (take_ss addsimps prems) 1]
skalberg@15570
   492
                                 @ List.concat(map (fn (con,args) => 
paulson@2033
   493
                                  asm_simp_tac take_ss 1 ::
paulson@2033
   494
                                  map (fn arg =>
paulson@2033
   495
                                   case_UU_tac (prems@con_rews) 1 (
skalberg@15570
   496
                           List.nth(dnames,rec_of arg)^"_take n$"^vname arg))
skalberg@15570
   497
                                  (List.filter is_nonlazy_rec args) @ [
paulson@2033
   498
                                  resolve_tac prems 1] @
paulson@2033
   499
                                  map (K (atac 1))      (nonlazy args) @
skalberg@15570
   500
                                  map (K (etac spec 1)) (List.filter is_rec args)) 
paulson@2033
   501
                                 cons))
oheimb@4043
   502
                                (conss~~cases)));
oheimb@1637
   503
oheimb@1637
   504
val take_lemmas =mapn(fn n=> fn(dn,ax_reach)=> pg'' thy axs_take_def(mk_All("n",
paulson@2033
   505
                mk_trp(dc_take dn $ Bound 0 `%(x_name n) === 
paulson@2033
   506
                       dc_take dn $ Bound 0 `%(x_name n^"'")))
berghofe@11531
   507
           ===> mk_trp(%:(x_name n) === %:(x_name n^"'"))) (fn prems => [
paulson@2033
   508
                        res_inst_tac[("t",x_name n    )](ax_reach RS subst) 1,
paulson@2033
   509
                        res_inst_tac[("t",x_name n^"'")](ax_reach RS subst) 1,
paulson@2033
   510
                                stac fix_def2 1,
paulson@2033
   511
                                REPEAT(CHANGED(rtac(contlub_cfun_arg RS ssubst)1
paulson@2033
   512
                                               THEN chain_tac 1)),
paulson@2033
   513
                                stac contlub_cfun_fun 1,
paulson@2033
   514
                                stac contlub_cfun_fun 2,
paulson@2033
   515
                                rtac lub_equal 3,
paulson@2033
   516
                                chain_tac 1,
paulson@2033
   517
                                rtac allI 1,
paulson@2033
   518
                                resolve_tac prems 1])) 1 (dnames~~axs_reach);
oheimb@1637
   519
oheimb@1637
   520
(* ----- theorems concerning finiteness and induction ----------------------- *)
regensbu@1274
   521
regensbu@1274
   522
val (finites,ind) = if is_finite then
oheimb@1637
   523
  let 
berghofe@11531
   524
    fun take_enough dn = mk_ex ("n",dc_take dn $ Bound 0 ` %:"x" === %:"x");
berghofe@11531
   525
    val finite_lemmas1a = map (fn dn => pg [] (mk_trp(defined (%:"x")) ===> 
berghofe@11531
   526
        mk_trp(mk_disj(mk_all("n",dc_take dn $ Bound 0 ` %:"x" === UU),
paulson@2033
   527
        take_enough dn)) ===> mk_trp(take_enough dn)) [
paulson@2033
   528
                                etac disjE 1,
paulson@2033
   529
                                etac notE 1,
paulson@2033
   530
                                resolve_tac take_lemmas 1,
paulson@2033
   531
                                asm_simp_tac take_ss 1,
paulson@2033
   532
                                atac 1]) dnames;
huffman@17811
   533
    val finite_lemma1b = pg [] (mk_trp (mk_all("n",foldr1 mk_conj (mapn 
paulson@2033
   534
        (fn n => fn ((dn,args),_) => mk_constrainall(x_name n,Type(dn,args),
paulson@2033
   535
         mk_disj(dc_take dn $ Bound 1 ` Bound 0 === UU,
paulson@2033
   536
                 dc_take dn $ Bound 1 ` Bound 0 === Bound 0))) 1 eqs)))) ([
paulson@2033
   537
                                rtac allI 1,
berghofe@13454
   538
                                induct_tac "n" 1,
paulson@2033
   539
                                simp_tac take_ss 1,
paulson@2033
   540
                        TRY(safe_tac(empty_cs addSEs[conjE] addSIs[conjI]))] @
skalberg@15570
   541
                                List.concat(mapn (fn n => fn (cons,cases) => [
paulson@2033
   542
                                  simp_tac take_ss 1,
paulson@2033
   543
                                  rtac allI 1,
paulson@2033
   544
                                  res_inst_tac [("x",x_name n)] cases 1,
paulson@2033
   545
                                  asm_simp_tac take_ss 1] @ 
skalberg@15570
   546
                                  List.concat(map (fn (con,args) => 
paulson@2033
   547
                                    asm_simp_tac take_ss 1 ::
skalberg@15570
   548
                                    List.concat(map (fn vn => [
paulson@2033
   549
                                      eres_inst_tac [("x",vn)] all_dupE 1,
paulson@2033
   550
                                      etac disjE 1,
paulson@2033
   551
                                      asm_simp_tac (HOL_ss addsimps con_rews) 1,
paulson@2033
   552
                                      asm_simp_tac take_ss 1])
paulson@2033
   553
                                    (nonlazy_rec args)))
paulson@2033
   554
                                  cons))
oheimb@4043
   555
                                1 (conss~~cases)));
oheimb@1637
   556
    val finites = map (fn (dn,l1b) => pg axs_finite_def (mk_trp(
berghofe@11531
   557
                                                %%:(dn^"_finite") $ %:"x"))[
paulson@2033
   558
                                case_UU_tac take_rews 1 "x",
paulson@2033
   559
                                eresolve_tac finite_lemmas1a 1,
paulson@2033
   560
                                step_tac HOL_cs 1,
paulson@2033
   561
                                step_tac HOL_cs 1,
paulson@2033
   562
                                cut_facts_tac [l1b] 1,
paulson@2033
   563
                        fast_tac HOL_cs 1]) (dnames~~atomize finite_lemma1b);
oheimb@1637
   564
  in
oheimb@1637
   565
  (finites,
berghofe@11531
   566
   pg'' thy[](ind_term (fn n => fn dn => %:(P_name n) $ %:(x_name n)))(fn prems =>
paulson@2033
   567
                                TRY(safe_tac HOL_cs) ::
skalberg@15570
   568
                         List.concat (map (fn (finite,fin_ind) => [
paulson@2033
   569
                               rtac(rewrite_rule axs_finite_def finite RS exE)1,
paulson@2033
   570
                                etac subst 1,
paulson@2033
   571
                                rtac fin_ind 1,
paulson@2033
   572
                                ind_prems_tac prems]) 
paulson@2033
   573
                                   (finites~~(atomize finite_ind)) ))
regensbu@1274
   574
) end (* let *) else
oheimb@1637
   575
  (mapn (fn n => fn dn => read_instantiate_sg (sign_of thy) 
paulson@2033
   576
                    [("P",dn^"_finite "^x_name n)] excluded_middle) 1 dnames,
huffman@16778
   577
   pg'' thy [] (Library.foldr (op ===>) (mapn (fn n => K(mk_trp(%%:admN $ %:(P_name n))))
berghofe@11531
   578
               1 dnames, ind_term (fn n => fn dn => %:(P_name n) $ %:(x_name n))))
paulson@2033
   579
                   (fn prems => map (fn ax_reach => rtac (ax_reach RS subst) 1) 
paulson@2033
   580
                                    axs_reach @ [
paulson@2033
   581
                                quant_tac 1,
paulson@2033
   582
                                rtac (adm_impl_admw RS wfix_ind) 1,
oheimb@4030
   583
                                 REPEAT_DETERM(rtac adm_all2 1),
oheimb@4030
   584
                                 REPEAT_DETERM(TRY(rtac adm_conj 1) THEN 
oheimb@4030
   585
                                                   rtac adm_subst 1 THEN 
paulson@2033
   586
                                        cont_tacR 1 THEN resolve_tac prems 1),
paulson@2033
   587
                                strip_tac 1,
paulson@2033
   588
                                rtac (rewrite_rule axs_take_def finite_ind) 1,
paulson@2033
   589
                                ind_prems_tac prems])
wenzelm@18678
   590
  handle ERROR _ => (warning "Cannot prove infinite induction rule"; refl))
regensbu@1274
   591
end; (* local *)
regensbu@1274
   592
oheimb@1637
   593
(* ----- theorem concerning coinduction ------------------------------------- *)
oheimb@1637
   594
regensbu@1274
   595
local
regensbu@1274
   596
  val xs = mapn (fn n => K (x_name n)) 1 dnames;
oheimb@1637
   597
  fun bnd_arg n i = Bound(2*(n_eqs - n)-i-1);
regensbu@1274
   598
  val take_ss = HOL_ss addsimps take_rews;
oheimb@4755
   599
  val sproj   = prj (fn s => K("fst("^s^")")) (fn s => K("snd("^s^")"));
berghofe@11531
   600
  val coind_lemma=pg[ax_bisim_def](mk_trp(mk_imp(%%:(comp_dname^"_bisim") $ %:"R",
skalberg@15570
   601
                Library.foldr (fn (x,t)=> mk_all(x,mk_all(x^"'",t))) (xs,
skalberg@15570
   602
                  Library.foldr mk_imp (mapn (fn n => K(proj (%:"R") eqs n $ 
paulson@2033
   603
                                      bnd_arg n 0 $ bnd_arg n 1)) 0 dnames,
huffman@17811
   604
                    foldr1 mk_conj (mapn (fn n => fn dn => 
berghofe@11531
   605
                                (dc_take dn $ %:"n" `bnd_arg n 0 === 
berghofe@11531
   606
                                (dc_take dn $ %:"n" `bnd_arg n 1)))0 dnames))))))
paulson@2033
   607
                             ([ rtac impI 1,
berghofe@13454
   608
                                induct_tac "n" 1,
paulson@2033
   609
                                simp_tac take_ss 1,
paulson@2033
   610
                                safe_tac HOL_cs] @
skalberg@15570
   611
                                List.concat(mapn (fn n => fn x => [
paulson@2033
   612
                                  rotate_tac (n+1) 1,
paulson@2033
   613
                                  etac all2E 1,
oheimb@4755
   614
                                  eres_inst_tac [("P1", sproj "R" eqs n^
paulson@2033
   615
                                        " "^x^" "^x^"'")](mp RS disjE) 1,
paulson@2033
   616
                                  TRY(safe_tac HOL_cs),
paulson@2033
   617
                                  REPEAT(CHANGED(asm_simp_tac take_ss 1))]) 
paulson@2033
   618
                                0 xs));
regensbu@1274
   619
in
berghofe@11531
   620
val coind = pg [] (mk_trp(%%:(comp_dname^"_bisim") $ %:"R") ===>
skalberg@15570
   621
                Library.foldr (op ===>) (mapn (fn n => fn x => 
berghofe@11531
   622
                  mk_trp(proj (%:"R") eqs n $ %:x $ %:(x^"'"))) 0 xs,
huffman@17811
   623
                  mk_trp(foldr1 mk_conj (map (fn x => %:x === %:(x^"'")) xs)))) ([
paulson@2033
   624
                                TRY(safe_tac HOL_cs)] @
skalberg@15570
   625
                                List.concat(map (fn take_lemma => [
paulson@2033
   626
                                  rtac take_lemma 1,
paulson@2033
   627
                                  cut_facts_tac [coind_lemma] 1,
paulson@2033
   628
                                  fast_tac HOL_cs 1])
paulson@2033
   629
                                take_lemmas));
regensbu@1274
   630
end; (* local *)
regensbu@1274
   631
oheimb@4043
   632
in thy |> Theory.add_path comp_dnam
haftmann@18377
   633
       |> (snd o (PureThy.add_thmss (map Thm.no_attributes [
oheimb@4043
   634
		("take_rews"  , take_rews  ),
oheimb@4043
   635
		("take_lemmas", take_lemmas),
oheimb@4043
   636
		("finites"    , finites    ),
oheimb@4043
   637
		("finite_ind", [finite_ind]),
oheimb@4043
   638
		("ind"       , [ind       ]),
wenzelm@8438
   639
		("coind"     , [coind     ])])))
wenzelm@12037
   640
       |> Theory.parent_path |> rpair take_rews
regensbu@1274
   641
end; (* let *)
regensbu@1274
   642
end; (* local *)
regensbu@1274
   643
end; (* struct *)