src/HOL/BNF/Tools/bnf_def.ML
changeset 49537 fe1deee434b6
parent 49536 898aea2e7a94
child 49538 c90818b63599
     1.1 --- a/src/HOL/BNF/Tools/bnf_def.ML	Sun Sep 23 14:52:53 2012 +0200
     1.2 +++ b/src/HOL/BNF/Tools/bnf_def.ML	Sun Sep 23 14:52:53 2012 +0200
     1.3 @@ -56,7 +56,9 @@
     1.4    val map_id_of_bnf: BNF -> thm
     1.5    val map_wppull_of_bnf: BNF -> thm
     1.6    val map_wpull_of_bnf: BNF -> thm
     1.7 +  val rel_as_srel_of_bnf: BNF -> thm
     1.8    val rel_def_of_bnf: BNF -> thm
     1.9 +  val rel_flip_of_bnf: BNF -> thm
    1.10    val set_bd_of_bnf: BNF -> thm list
    1.11    val set_defs_of_bnf: BNF -> thm list
    1.12    val set_natural'_of_bnf: BNF -> thm list
    1.13 @@ -182,6 +184,8 @@
    1.14    map_comp': thm lazy,
    1.15    map_id': thm lazy,
    1.16    map_wppull: thm lazy,
    1.17 +  rel_as_srel: thm lazy,
    1.18 +  rel_flip: thm lazy,
    1.19    set_natural': thm lazy list,
    1.20    srel_cong: thm lazy,
    1.21    srel_mono: thm lazy,
    1.22 @@ -192,8 +196,8 @@
    1.23  };
    1.24  
    1.25  fun mk_facts bd_Card_order bd_Cinfinite bd_Cnotzero collect_set_natural in_cong in_mono in_srel
    1.26 -    map_comp' map_id' map_wppull set_natural' srel_cong srel_mono srel_Id srel_Gr srel_converse
    1.27 -    srel_O = {
    1.28 +    map_comp' map_id' map_wppull rel_as_srel rel_flip set_natural' srel_cong srel_mono srel_Id
    1.29 +    srel_Gr srel_converse srel_O = {
    1.30    bd_Card_order = bd_Card_order,
    1.31    bd_Cinfinite = bd_Cinfinite,
    1.32    bd_Cnotzero = bd_Cnotzero,
    1.33 @@ -204,6 +208,8 @@
    1.34    map_comp' = map_comp',
    1.35    map_id' = map_id',
    1.36    map_wppull = map_wppull,
    1.37 +  rel_as_srel = rel_as_srel,
    1.38 +  rel_flip = rel_flip,
    1.39    set_natural' = set_natural',
    1.40    srel_cong = srel_cong,
    1.41    srel_mono = srel_mono,
    1.42 @@ -223,6 +229,8 @@
    1.43    map_comp',
    1.44    map_id',
    1.45    map_wppull,
    1.46 +  rel_as_srel,
    1.47 +  rel_flip,
    1.48    set_natural',
    1.49    srel_cong,
    1.50    srel_mono,
    1.51 @@ -240,6 +248,8 @@
    1.52      map_comp' = Lazy.map f map_comp',
    1.53      map_id' = Lazy.map f map_id',
    1.54      map_wppull = Lazy.map f map_wppull,
    1.55 +    rel_as_srel = Lazy.map f rel_as_srel,
    1.56 +    rel_flip = Lazy.map f rel_flip,
    1.57      set_natural' = map (Lazy.map f) set_natural',
    1.58      srel_cong = Lazy.map f srel_cong,
    1.59      srel_mono = Lazy.map f srel_mono,
    1.60 @@ -358,7 +368,9 @@
    1.61  val map_cong_of_bnf = #map_cong o #axioms o rep_bnf;
    1.62  val map_wppull_of_bnf = Lazy.force o #map_wppull o #facts o rep_bnf;
    1.63  val map_wpull_of_bnf = #map_wpull o #axioms o rep_bnf;
    1.64 +val rel_as_srel_of_bnf = Lazy.force o #rel_as_srel o #facts o rep_bnf;
    1.65  val rel_def_of_bnf = #rel_def o #defs o rep_bnf;
    1.66 +val rel_flip_of_bnf = Lazy.force o #rel_flip o #facts o rep_bnf;
    1.67  val set_bd_of_bnf = #set_bd o #axioms o rep_bnf;
    1.68  val set_defs_of_bnf = #set_defs o #defs o rep_bnf;
    1.69  val set_natural_of_bnf = #set_natural o #axioms o rep_bnf;
    1.70 @@ -490,15 +502,17 @@
    1.71  val map_comp'N = "map_comp'";
    1.72  val map_congN = "map_cong";
    1.73  val map_wpullN = "map_wpull";
    1.74 +val rel_as_srelN = "rel_as_srel";
    1.75 +val rel_flipN = "rel_flip";
    1.76 +val set_naturalN = "set_natural";
    1.77 +val set_natural'N = "set_natural'";
    1.78 +val set_bdN = "set_bd";
    1.79  val srel_IdN = "srel_Id";
    1.80  val srel_GrN = "srel_Gr";
    1.81  val srel_converseN = "srel_converse";
    1.82  val srel_monoN = "srel_mono"
    1.83  val srel_ON = "srel_comp";
    1.84  val srel_O_GrN = "srel_comp_Gr";
    1.85 -val set_naturalN = "set_natural";
    1.86 -val set_natural'N = "set_natural'";
    1.87 -val set_bdN = "set_bd";
    1.88  
    1.89  datatype const_policy = Dont_Inline | Hardly_Inline | Smart_Inline | Do_Inline;
    1.90  
    1.91 @@ -695,7 +709,7 @@
    1.92        ||>> mk_Frees' "S" setRTs
    1.93        ||>> mk_Frees "S" setRTs
    1.94        ||>> mk_Frees "T" setRTsBsCs
    1.95 -      ||>> mk_Frees' "Q" QTs;
    1.96 +      ||>> mk_Frees' "R" QTs;
    1.97  
    1.98      (*Gr (in R1 .. Rn) (map fst .. fst)^-1 O Gr (in R1 .. Rn) (map snd .. snd)*)
    1.99      val O_Gr =
   1.100 @@ -714,11 +728,14 @@
   1.101          val y = Free (y_name, U);
   1.102        in fold_rev Term.lambda [x, y] (HOLogic.mk_mem (HOLogic.mk_prod (x, y), t)) end;
   1.103  
   1.104 +    val sQs =
   1.105 +      map3 (fn Q => fn T => fn U =>
   1.106 +          HOLogic.Collect_const (HOLogic.mk_prodT (T, U)) $ HOLogic.mk_split Q) Qs As' Bs';
   1.107 +
   1.108      val rel_rhs = (case raw_rel_opt of
   1.109          NONE =>
   1.110          fold_rev absfree Qs' (mk_predicate_of_set (fst x') (fst y')
   1.111 -          (Term.list_comb (fold_rev Term.absfree Rs' O_Gr, map3 (fn Q => fn T => fn U =>
   1.112 -          HOLogic.Collect_const (HOLogic.mk_prodT (T, U)) $ HOLogic.mk_split Q) Qs As' Bs')))
   1.113 +          (Term.list_comb (fold_rev Term.absfree Rs' O_Gr, sQs)))
   1.114        | SOME raw_rel => prep_term no_defs_lthy raw_rel);
   1.115  
   1.116      val rel_bind_def = (fn () => Binding.suffix_name ("_" ^ relN) b, rel_rhs);
   1.117 @@ -1090,11 +1107,36 @@
   1.118  
   1.119          val in_srel = mk_lazy mk_in_srel;
   1.120  
   1.121 +        val eqset_imp_iff_pair = @{thm eqset_imp_iff_pair};
   1.122 +        val mem_Collect_etc = @{thms mem_Collect_eq fst_conv snd_conv prod.cases};
   1.123 +
   1.124 +        fun mk_rel_as_srel () =
   1.125 +          unfold_thms lthy mem_Collect_etc
   1.126 +            (funpow live (fn thm => thm RS @{thm fun_cong_pair}) (bnf_srel_def RS meta_eq_to_obj_eq)
   1.127 +               RS eqset_imp_iff_pair RS sym)
   1.128 +          |> Drule.zero_var_indexes;
   1.129 +
   1.130 +        val rel_as_srel = mk_lazy mk_rel_as_srel;
   1.131 +
   1.132 +        fun mk_rel_flip () =
   1.133 +          let
   1.134 +            val srel_converse_thm = Lazy.force srel_converse;
   1.135 +            val Rs' = Term.add_vars (prop_of srel_converse_thm) [];
   1.136 +            val cts = map (pairself (certify lthy)) (map Var Rs' ~~ sQs);
   1.137 +            val srel_converse_thm' = Drule.cterm_instantiate cts srel_converse_thm;
   1.138 +          in
   1.139 +            unfold_thms lthy (bnf_srel_def :: @{thm converse_iff} :: mem_Collect_etc)
   1.140 +              (srel_converse_thm' RS eqset_imp_iff_pair)
   1.141 +            |> Drule.zero_var_indexes |> Thm.generalize ([], map fst Qs') 1
   1.142 +          end;
   1.143 +
   1.144 +        val rel_flip = mk_lazy mk_rel_flip;
   1.145 +
   1.146          val defs = mk_defs bnf_map_def bnf_set_defs bnf_rel_def bnf_srel_def;
   1.147  
   1.148          val facts = mk_facts bd_Card_order bd_Cinfinite bd_Cnotzero collect_set_natural in_cong
   1.149 -          in_mono in_srel map_comp' map_id' map_wppull set_natural' srel_cong srel_mono srel_Id
   1.150 -          srel_Gr srel_converse srel_O;
   1.151 +          in_mono in_srel map_comp' map_id' map_wppull rel_as_srel rel_flip set_natural' srel_cong
   1.152 +          srel_mono srel_Id srel_Gr srel_converse srel_O;
   1.153  
   1.154          val wits = map2 mk_witness bnf_wits wit_thms;
   1.155  
   1.156 @@ -1141,6 +1183,8 @@
   1.157                      [(map_comp'N, [Lazy.force (#map_comp' facts)]),
   1.158                      (map_congN, [#map_cong axioms]),
   1.159                      (map_id'N, [Lazy.force (#map_id' facts)]),
   1.160 +                    (rel_as_srelN, [Lazy.force (#rel_as_srel facts)]),
   1.161 +                    (rel_flipN, [Lazy.force (#rel_flip facts)]),
   1.162                      (set_natural'N, map Lazy.force (#set_natural' facts)),
   1.163                      (srel_O_GrN, srel_O_Grs),
   1.164                      (srel_IdN, [Lazy.force (#srel_Id facts)]),