src/HOL/Tools/BNF/bnf_def.ML
changeset 57301 7b997028aaac
parent 56954 4ce75d6a8935
child 57303 498a62e65f5f
equal deleted inserted replaced
57300:7e22d7b75e2a 57301:7b997028aaac
    83 
    83 
    84   val mk_map: int -> typ list -> typ list -> term -> term
    84   val mk_map: int -> typ list -> typ list -> term -> term
    85   val mk_rel: int -> typ list -> typ list -> term -> term
    85   val mk_rel: int -> typ list -> typ list -> term -> term
    86   val build_map: Proof.context -> (typ * typ -> term) -> typ * typ -> term
    86   val build_map: Proof.context -> (typ * typ -> term) -> typ * typ -> term
    87   val build_rel: Proof.context -> (typ * typ -> term) -> typ * typ -> term
    87   val build_rel: Proof.context -> (typ * typ -> term) -> typ * typ -> term
       
    88   val build_rel': Proof.context -> typ list -> (typ * typ -> term) -> typ * typ -> term
    88   val flatten_type_args_of_bnf: bnf -> 'a -> 'a list -> 'a list
    89   val flatten_type_args_of_bnf: bnf -> 'a -> 'a list -> 'a list
    89   val map_flattened_map_args: Proof.context -> string -> (term list -> 'a list) -> term list ->
    90   val map_flattened_map_args: Proof.context -> string -> (term list -> 'a list) -> term list ->
    90     'a list
    91     'a list
    91 
    92 
    92   val mk_witness: int list * term -> thm list -> nonemptiness_witness
    93   val mk_witness: int list * term -> thm list -> nonemptiness_witness
   531 fun mk_rel live Ts Us t =
   532 fun mk_rel live Ts Us t =
   532   let val [Type (_, Ts0), Type (_, Us0)] = binder_types (snd (strip_typeN live (fastype_of t))) in
   533   let val [Type (_, Ts0), Type (_, Us0)] = binder_types (snd (strip_typeN live (fastype_of t))) in
   533     Term.subst_atomic_types (Ts0 @ Us0 ~~ Ts @ Us) t
   534     Term.subst_atomic_types (Ts0 @ Us0 ~~ Ts @ Us) t
   534   end;
   535   end;
   535 
   536 
   536 fun build_map_or_rel mk const of_bnf dest ctxt build_simple =
   537 fun build_map_or_rel mk const of_bnf dest blacklist ctxt build_simple =
   537   let
   538   let
   538     fun build (TU as (T, U)) =
   539     fun build (TU as (T, U)) =
   539       if T = U then
   540       if exists (curry (op =) T) blacklist then
       
   541         build_simple TU
       
   542       else if T = U andalso not (exists_subtype_in blacklist T) then
   540         const T
   543         const T
   541       else
   544       else
   542         (case TU of
   545         (case TU of
   543           (Type (s, Ts), Type (s', Us)) =>
   546           (Type (s, Ts), Type (s', Us)) =>
   544           if s = s' then
   547           if s = s' then
   551           else
   554           else
   552             build_simple TU
   555             build_simple TU
   553         | _ => build_simple TU);
   556         | _ => build_simple TU);
   554   in build end;
   557   in build end;
   555 
   558 
   556 val build_map = build_map_or_rel mk_map HOLogic.id_const map_of_bnf dest_funT;
   559 val build_map = build_map_or_rel mk_map HOLogic.id_const map_of_bnf dest_funT [];
   557 val build_rel = build_map_or_rel mk_rel HOLogic.eq_const rel_of_bnf dest_pred2T;
   560 val build_rel = build_map_or_rel mk_rel HOLogic.eq_const rel_of_bnf dest_pred2T [];
       
   561 fun build_rel' ctxt blacklist = build_map_or_rel mk_rel HOLogic.eq_const rel_of_bnf dest_pred2T blacklist ctxt;
   558 
   562 
   559 fun map_flattened_map_args ctxt s map_args fs =
   563 fun map_flattened_map_args ctxt s map_args fs =
   560   let
   564   let
   561     val flat_fs = flatten_type_args_of_bnf (the (bnf_of ctxt s)) Term.dummy fs;
   565     val flat_fs = flatten_type_args_of_bnf (the (bnf_of ctxt s)) Term.dummy fs;
   562     val flat_fs' = map_args flat_fs;
   566     val flat_fs' = map_args flat_fs;
  1282             fun mk_prem setA setB R S a b =
  1286             fun mk_prem setA setB R S a b =
  1283               HOLogic.mk_Trueprop
  1287               HOLogic.mk_Trueprop
  1284                 (mk_Ball (setA $ x) (Term.absfree (dest_Free a)
  1288                 (mk_Ball (setA $ x) (Term.absfree (dest_Free a)
  1285                   (mk_Ball (setB $ y) (Term.absfree (dest_Free b)
  1289                   (mk_Ball (setB $ y) (Term.absfree (dest_Free b)
  1286                     (HOLogic.mk_imp (R $ a $ b, S $ a $ b))))));
  1290                     (HOLogic.mk_imp (R $ a $ b, S $ a $ b))))));
  1287             val prems = HOLogic.mk_Trueprop (Term.list_comb (rel, Rs) $ x $ y) :: 
  1291             val prems = HOLogic.mk_Trueprop (Term.list_comb (rel, Rs) $ x $ y) ::
  1288               map6 mk_prem bnf_sets_As bnf_sets_Bs Rs Rs_copy zs ys;
  1292               map6 mk_prem bnf_sets_As bnf_sets_Bs Rs Rs_copy zs ys;
  1289             val concl = HOLogic.mk_Trueprop (Term.list_comb (rel, Rs_copy) $ x $ y);
  1293             val concl = HOLogic.mk_Trueprop (Term.list_comb (rel, Rs_copy) $ x $ y);
  1290           in
  1294           in
  1291             Goal.prove_sorry lthy [] []
  1295             Goal.prove_sorry lthy [] []
  1292               (fold_rev Logic.all (x :: y :: Rs @ Rs_copy) (Logic.list_implies (prems, concl)))
  1296               (fold_rev Logic.all (x :: y :: Rs @ Rs_copy) (Logic.list_implies (prems, concl)))
  1397       Goal.prove_sorry lthy [] [] (Logic.mk_conjunction_balanced wit_goals)
  1401       Goal.prove_sorry lthy [] [] (Logic.mk_conjunction_balanced wit_goals)
  1398         (fn {context = ctxt, prems = _} => TRYALL Goal.conjunction_tac THEN tac ctxt set_maps)
  1402         (fn {context = ctxt, prems = _} => TRYALL Goal.conjunction_tac THEN tac ctxt set_maps)
  1399         |> Conjunction.elim_balanced (length wit_goals)
  1403         |> Conjunction.elim_balanced (length wit_goals)
  1400         |> map2 (Conjunction.elim_balanced o length) wit_goalss
  1404         |> map2 (Conjunction.elim_balanced o length) wit_goalss
  1401         |> map (map (Thm.close_derivation o Thm.forall_elim_vars 0));
  1405         |> map (map (Thm.close_derivation o Thm.forall_elim_vars 0));
  1402     val (mk_wit_thms, nontriv_wit_goals) = 
  1406     val (mk_wit_thms, nontriv_wit_goals) =
  1403       (case triv_tac_opt of
  1407       (case triv_tac_opt of
  1404         NONE => (fn _ => [], map (map (rpair [])) wit_goalss)
  1408         NONE => (fn _ => [], map (map (rpair [])) wit_goalss)
  1405       | SOME tac => (mk_triv_wit_thms tac, []));
  1409       | SOME tac => (mk_triv_wit_thms tac, []));
  1406   in
  1410   in
  1407     Proof.unfolding ([[(defs, [])]])
  1411     Proof.unfolding ([[(defs, [])]])