src/HOL/Nominal/nominal_package.ML
changeset 30280 eb98b49ef835
parent 30190 479806475f3c
child 30307 6c74ef5a349f
equal deleted inserted replaced
30279:84097bba7bdc 30280:eb98b49ef835
    47   | dt_recs (DtType (_, dts)) = List.concat (map dt_recs dts)
    47   | dt_recs (DtType (_, dts)) = List.concat (map dt_recs dts)
    48   | dt_recs (DtRec i) = [i];
    48   | dt_recs (DtRec i) = [i];
    49 
    49 
    50 fun dt_cases (descr: descr) (_, args, constrs) =
    50 fun dt_cases (descr: descr) (_, args, constrs) =
    51   let
    51   let
    52     fun the_bname i = Sign.base_name (#1 (valOf (AList.lookup (op =) descr i)));
    52     fun the_bname i = NameSpace.base_name (#1 (valOf (AList.lookup (op =) descr i)));
    53     val bnames = map the_bname (distinct op = (List.concat (map dt_recs args)));
    53     val bnames = map the_bname (distinct op = (List.concat (map dt_recs args)));
    54   in map (fn (c, _) => space_implode "_" (Sign.base_name c :: bnames)) constrs end;
    54   in map (fn (c, _) => space_implode "_" (NameSpace.base_name c :: bnames)) constrs end;
    55 
    55 
    56 
    56 
    57 fun induct_cases descr =
    57 fun induct_cases descr =
    58   DatatypeProp.indexify_names (List.concat (map (dt_cases descr) (map #2 descr)));
    58   DatatypeProp.indexify_names (List.concat (map (dt_cases descr) (map #2 descr)));
    59 
    59 
   362         val permT = mk_permT (Type (a, []));
   362         val permT = mk_permT (Type (a, []));
   363         val pi1 = Free ("pi1", permT);
   363         val pi1 = Free ("pi1", permT);
   364         val pi2 = Free ("pi2", permT);
   364         val pi2 = Free ("pi2", permT);
   365         val pt_inst = pt_inst_of thy2 a;
   365         val pt_inst = pt_inst_of thy2 a;
   366         val pt2' = pt_inst RS pt2;
   366         val pt2' = pt_inst RS pt2;
   367         val pt2_ax = PureThy.get_thm thy2 (NameSpace.map_base (fn s => "pt_" ^ s ^ "2") a);
   367         val pt2_ax = PureThy.get_thm thy2 (NameSpace.map_base_name (fn s => "pt_" ^ s ^ "2") a);
   368       in List.take (map standard (split_conj_thm
   368       in List.take (map standard (split_conj_thm
   369         (Goal.prove_global thy2 [] []
   369         (Goal.prove_global thy2 [] []
   370            (augment_sort thy2 [pt_class_of thy2 a]
   370            (augment_sort thy2 [pt_class_of thy2 a]
   371              (HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj
   371              (HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj
   372                 (map (fn ((s, T), x) =>
   372                 (map (fn ((s, T), x) =>
   397         val pi2 = Free ("pi2", permT);
   397         val pi2 = Free ("pi2", permT);
   398         val at_inst = at_inst_of thy2 a;
   398         val at_inst = at_inst_of thy2 a;
   399         val pt_inst = pt_inst_of thy2 a;
   399         val pt_inst = pt_inst_of thy2 a;
   400         val pt3' = pt_inst RS pt3;
   400         val pt3' = pt_inst RS pt3;
   401         val pt3_rev' = at_inst RS (pt_inst RS pt3_rev);
   401         val pt3_rev' = at_inst RS (pt_inst RS pt3_rev);
   402         val pt3_ax = PureThy.get_thm thy2 (NameSpace.map_base (fn s => "pt_" ^ s ^ "3") a);
   402         val pt3_ax = PureThy.get_thm thy2 (NameSpace.map_base_name (fn s => "pt_" ^ s ^ "3") a);
   403       in List.take (map standard (split_conj_thm
   403       in List.take (map standard (split_conj_thm
   404         (Goal.prove_global thy2 [] []
   404         (Goal.prove_global thy2 [] []
   405           (augment_sort thy2 [pt_class_of thy2 a] (Logic.mk_implies
   405           (augment_sort thy2 [pt_class_of thy2 a] (Logic.mk_implies
   406              (HOLogic.mk_Trueprop (Const ("Nominal.prm_eq",
   406              (HOLogic.mk_Trueprop (Const ("Nominal.prm_eq",
   407                 permT --> permT --> HOLogic.boolT) $ pi1 $ pi2),
   407                 permT --> permT --> HOLogic.boolT) $ pi1 $ pi2),
   662               rewrite_goals_tac [perm_def],
   662               rewrite_goals_tac [perm_def],
   663               asm_full_simp_tac (simpset_of thy addsimps [Rep_inverse]) 1,
   663               asm_full_simp_tac (simpset_of thy addsimps [Rep_inverse]) 1,
   664               asm_full_simp_tac (simpset_of thy addsimps
   664               asm_full_simp_tac (simpset_of thy addsimps
   665                 [Rep RS perm_closed RS Abs_inverse]) 1,
   665                 [Rep RS perm_closed RS Abs_inverse]) 1,
   666               asm_full_simp_tac (HOL_basic_ss addsimps [PureThy.get_thm thy
   666               asm_full_simp_tac (HOL_basic_ss addsimps [PureThy.get_thm thy
   667                 ("pt_" ^ Sign.base_name atom ^ "3")]) 1]) thy
   667                 ("pt_" ^ NameSpace.base_name atom ^ "3")]) 1]) thy
   668           end)
   668           end)
   669         (Abs_inverse_thms ~~ Rep_inverse_thms ~~ Rep_thms ~~ perm_defs ~~
   669         (Abs_inverse_thms ~~ Rep_inverse_thms ~~ Rep_thms ~~ perm_defs ~~
   670            new_type_names ~~ tyvars ~~ perm_closed_thms);
   670            new_type_names ~~ tyvars ~~ perm_closed_thms);
   671 
   671 
   672 
   672 
   796         val lhs = list_comb (Const (cname, constrT), l_args);
   796         val lhs = list_comb (Const (cname, constrT), l_args);
   797         val rhs = list_comb (Const (cname_rep, map fastype_of r_args ---> T'), r_args);
   797         val rhs = list_comb (Const (cname_rep, map fastype_of r_args ---> T'), r_args);
   798         val def = Logic.mk_equals (lhs, Const (abs_name, T' --> T) $ rhs);
   798         val def = Logic.mk_equals (lhs, Const (abs_name, T' --> T) $ rhs);
   799         val eqn = HOLogic.mk_Trueprop (HOLogic.mk_eq
   799         val eqn = HOLogic.mk_Trueprop (HOLogic.mk_eq
   800           (Const (rep_name, T --> T') $ lhs, rhs));
   800           (Const (rep_name, T --> T') $ lhs, rhs));
   801         val def_name = (Sign.base_name cname) ^ "_def";
   801         val def_name = (NameSpace.base_name cname) ^ "_def";
   802         val ([def_thm], thy') = thy |>
   802         val ([def_thm], thy') = thy |>
   803           Sign.add_consts_i [(cname', constrT, mx)] |>
   803           Sign.add_consts_i [(cname', constrT, mx)] |>
   804           (PureThy.add_defs false o map Thm.no_attributes) [(Binding.name def_name, def)]
   804           (PureThy.add_defs false o map Thm.no_attributes) [(Binding.name def_name, def)]
   805       in (thy', defs @ [def_thm], eqns @ [eqn]) end;
   805       in (thy', defs @ [def_thm], eqns @ [eqn]) end;
   806 
   806 
   887       let val T = nth_dtyp' i
   887       let val T = nth_dtyp' i
   888       in List.concat (map (fn (atom, perm_closed_thms) =>
   888       in List.concat (map (fn (atom, perm_closed_thms) =>
   889           map (fn ((cname, dts), constr_rep_thm) =>
   889           map (fn ((cname, dts), constr_rep_thm) =>
   890         let
   890         let
   891           val cname = Sign.intern_const thy8
   891           val cname = Sign.intern_const thy8
   892             (NameSpace.append tname (Sign.base_name cname));
   892             (NameSpace.append tname (NameSpace.base_name cname));
   893           val permT = mk_permT (Type (atom, []));
   893           val permT = mk_permT (Type (atom, []));
   894           val pi = Free ("pi", permT);
   894           val pi = Free ("pi", permT);
   895 
   895 
   896           fun perm t =
   896           fun perm t =
   897             let val T = fastype_of t
   897             let val T = fastype_of t
   943       let val T = nth_dtyp' i
   943       let val T = nth_dtyp' i
   944       in List.mapPartial (fn ((cname, dts), constr_rep_thm) =>
   944       in List.mapPartial (fn ((cname, dts), constr_rep_thm) =>
   945         if null dts then NONE else SOME
   945         if null dts then NONE else SOME
   946         let
   946         let
   947           val cname = Sign.intern_const thy8
   947           val cname = Sign.intern_const thy8
   948             (NameSpace.append tname (Sign.base_name cname));
   948             (NameSpace.append tname (NameSpace.base_name cname));
   949 
   949 
   950           fun make_inj ((dts, dt), (j, args1, args2, eqs)) =
   950           fun make_inj ((dts, dt), (j, args1, args2, eqs)) =
   951             let
   951             let
   952               val Ts_idx = map (typ_of_dtyp descr'' sorts) dts ~~ (j upto j + length dts - 1);
   952               val Ts_idx = map (typ_of_dtyp descr'' sorts) dts ~~ (j upto j + length dts - 1);
   953               val xs = map (fn (T, i) => mk_Free "x" T i) Ts_idx;
   953               val xs = map (fn (T, i) => mk_Free "x" T i) Ts_idx;
   985       (map (fn ((((i, (_, _, constrs)), tname), inject_thms'), perm_thms') =>
   985       (map (fn ((((i, (_, _, constrs)), tname), inject_thms'), perm_thms') =>
   986       let val T = nth_dtyp' i
   986       let val T = nth_dtyp' i
   987       in List.concat (map (fn (cname, dts) => map (fn atom =>
   987       in List.concat (map (fn (cname, dts) => map (fn atom =>
   988         let
   988         let
   989           val cname = Sign.intern_const thy8
   989           val cname = Sign.intern_const thy8
   990             (NameSpace.append tname (Sign.base_name cname));
   990             (NameSpace.append tname (NameSpace.base_name cname));
   991           val atomT = Type (atom, []);
   991           val atomT = Type (atom, []);
   992 
   992 
   993           fun process_constr ((dts, dt), (j, args1, args2)) =
   993           fun process_constr ((dts, dt), (j, args1, args2)) =
   994             let
   994             let
   995               val Ts_idx = map (typ_of_dtyp descr'' sorts) dts ~~ (j upto j + length dts - 1);
   995               val Ts_idx = map (typ_of_dtyp descr'' sorts) dts ~~ (j upto j + length dts - 1);
  1098                    (Const ("Nominal.supp", T --> HOLogic.mk_setT atomT) $ Free (s, T)))
  1098                    (Const ("Nominal.supp", T --> HOLogic.mk_setT atomT) $ Free (s, T)))
  1099                    (indnames ~~ recTs)))))
  1099                    (indnames ~~ recTs)))))
  1100            (fn _ => indtac dt_induct indnames 1 THEN
  1100            (fn _ => indtac dt_induct indnames 1 THEN
  1101             ALLGOALS (asm_full_simp_tac (simpset_of thy8 addsimps
  1101             ALLGOALS (asm_full_simp_tac (simpset_of thy8 addsimps
  1102               (abs_supp @ supp_atm @
  1102               (abs_supp @ supp_atm @
  1103                PureThy.get_thms thy8 ("fs_" ^ Sign.base_name atom ^ "1") @
  1103                PureThy.get_thms thy8 ("fs_" ^ NameSpace.base_name atom ^ "1") @
  1104                List.concat supp_thms))))),
  1104                List.concat supp_thms))))),
  1105          length new_type_names))
  1105          length new_type_names))
  1106       end) atoms;
  1106       end) atoms;
  1107 
  1107 
  1108     val simp_atts = replicate (length new_type_names) [Simplifier.simp_add];
  1108     val simp_atts = replicate (length new_type_names) [Simplifier.simp_add];
  1230     val fin_set_supp = map (fn s =>
  1230     val fin_set_supp = map (fn s =>
  1231       at_inst_of thy9 s RS at_fin_set_supp) dt_atoms;
  1231       at_inst_of thy9 s RS at_fin_set_supp) dt_atoms;
  1232     val fin_set_fresh = map (fn s =>
  1232     val fin_set_fresh = map (fn s =>
  1233       at_inst_of thy9 s RS at_fin_set_fresh) dt_atoms;
  1233       at_inst_of thy9 s RS at_fin_set_fresh) dt_atoms;
  1234     val pt1_atoms = map (fn Type (s, _) =>
  1234     val pt1_atoms = map (fn Type (s, _) =>
  1235       PureThy.get_thm thy9 ("pt_" ^ Sign.base_name s ^ "1")) dt_atomTs;
  1235       PureThy.get_thm thy9 ("pt_" ^ NameSpace.base_name s ^ "1")) dt_atomTs;
  1236     val pt2_atoms = map (fn Type (s, _) =>
  1236     val pt2_atoms = map (fn Type (s, _) =>
  1237       PureThy.get_thm thy9 ("pt_" ^ Sign.base_name s ^ "2") RS sym) dt_atomTs;
  1237       PureThy.get_thm thy9 ("pt_" ^ NameSpace.base_name s ^ "2") RS sym) dt_atomTs;
  1238     val exists_fresh' = PureThy.get_thms thy9 "exists_fresh'";
  1238     val exists_fresh' = PureThy.get_thms thy9 "exists_fresh'";
  1239     val fs_atoms = PureThy.get_thms thy9 "fin_supp";
  1239     val fs_atoms = PureThy.get_thms thy9 "fin_supp";
  1240     val abs_supp = PureThy.get_thms thy9 "abs_supp";
  1240     val abs_supp = PureThy.get_thms thy9 "abs_supp";
  1241     val perm_fresh_fresh = PureThy.get_thms thy9 "perm_fresh_fresh";
  1241     val perm_fresh_fresh = PureThy.get_thms thy9 "perm_fresh_fresh";
  1242     val calc_atm = PureThy.get_thms thy9 "calc_atm";
  1242     val calc_atm = PureThy.get_thms thy9 "calc_atm";
  1557 
  1557 
  1558     (** finite support **)
  1558     (** finite support **)
  1559 
  1559 
  1560     val rec_fin_supp_thms = map (fn aT =>
  1560     val rec_fin_supp_thms = map (fn aT =>
  1561       let
  1561       let
  1562         val name = Sign.base_name (fst (dest_Type aT));
  1562         val name = NameSpace.base_name (fst (dest_Type aT));
  1563         val fs_name = PureThy.get_thm thy11 ("fs_" ^ name ^ "1");
  1563         val fs_name = PureThy.get_thm thy11 ("fs_" ^ name ^ "1");
  1564         val aset = HOLogic.mk_setT aT;
  1564         val aset = HOLogic.mk_setT aT;
  1565         val finite = Const ("Finite_Set.finite", aset --> HOLogic.boolT);
  1565         val finite = Const ("Finite_Set.finite", aset --> HOLogic.boolT);
  1566         val fins = map (fn (f, T) => HOLogic.mk_Trueprop
  1566         val fins = map (fn (f, T) => HOLogic.mk_Trueprop
  1567           (finite $ (Const ("Nominal.supp", T --> aset) $ f)))
  1567           (finite $ (Const ("Nominal.supp", T --> aset) $ f)))
  1596 
  1596 
  1597     val rec_fns' = map (augment_sort thy11 fs_cp_sort) rec_fns;
  1597     val rec_fns' = map (augment_sort thy11 fs_cp_sort) rec_fns;
  1598 
  1598 
  1599     val rec_fresh_thms = map (fn ((aT, eqvt_ths), finite_prems) =>
  1599     val rec_fresh_thms = map (fn ((aT, eqvt_ths), finite_prems) =>
  1600       let
  1600       let
  1601         val name = Sign.base_name (fst (dest_Type aT));
  1601         val name = NameSpace.base_name (fst (dest_Type aT));
  1602         val fs_name = PureThy.get_thm thy11 ("fs_" ^ name ^ "1");
  1602         val fs_name = PureThy.get_thm thy11 ("fs_" ^ name ^ "1");
  1603         val a = Free ("a", aT);
  1603         val a = Free ("a", aT);
  1604         val freshs = map (fn (f, fT) => HOLogic.mk_Trueprop
  1604         val freshs = map (fn (f, fT) => HOLogic.mk_Trueprop
  1605           (fresh_const aT fT $ a $ f)) (rec_fns ~~ rec_fn_Ts)
  1605           (fresh_const aT fT $ a $ f)) (rec_fns ~~ rec_fn_Ts)
  1606       in
  1606       in
  2010         (reccomb_names ~~ recTs ~~ rec_result_Ts);
  2010         (reccomb_names ~~ recTs ~~ rec_result_Ts);
  2011 
  2011 
  2012     val (reccomb_defs, thy12) =
  2012     val (reccomb_defs, thy12) =
  2013       thy11
  2013       thy11
  2014       |> Sign.add_consts_i (map (fn ((name, T), T') =>
  2014       |> Sign.add_consts_i (map (fn ((name, T), T') =>
  2015           (Sign.base_name name, rec_fn_Ts @ [T] ---> T', NoSyn))
  2015           (NameSpace.base_name name, rec_fn_Ts @ [T] ---> T', NoSyn))
  2016           (reccomb_names ~~ recTs ~~ rec_result_Ts))
  2016           (reccomb_names ~~ recTs ~~ rec_result_Ts))
  2017       |> (PureThy.add_defs false o map Thm.no_attributes) (map (fn ((((name, comb), set), T), T') =>
  2017       |> (PureThy.add_defs false o map Thm.no_attributes) (map (fn ((((name, comb), set), T), T') =>
  2018           (Binding.name (Sign.base_name name ^ "_def"), Logic.mk_equals (comb, absfree ("x", T,
  2018           (Binding.name (NameSpace.base_name name ^ "_def"), Logic.mk_equals (comb, absfree ("x", T,
  2019            Const ("The", (T' --> HOLogic.boolT) --> T') $ absfree ("y", T',
  2019            Const ("The", (T' --> HOLogic.boolT) --> T') $ absfree ("y", T',
  2020              set $ Free ("x", T) $ Free ("y", T'))))))
  2020              set $ Free ("x", T) $ Free ("y", T'))))))
  2021                (reccomb_names ~~ reccombs ~~ rec_sets ~~ recTs ~~ rec_result_Ts));
  2021                (reccomb_names ~~ reccombs ~~ rec_sets ~~ recTs ~~ rec_result_Ts));
  2022 
  2022 
  2023     (* prove characteristic equations for primrec combinators *)
  2023     (* prove characteristic equations for primrec combinators *)