src/HOL/BNF/Tools/bnf_fp_rec_sugar.ML
changeset 54178 d6dc359426b7
parent 54177 acea8033beaa
child 54180 1753c57eb16c
equal deleted inserted replaced
54177:acea8033beaa 54178:d6dc359426b7
   861     val ((n2m, corec_specs', _, coinduct_thm, strong_coinduct_thm, coinduct_thms,
   861     val ((n2m, corec_specs', _, coinduct_thm, strong_coinduct_thm, coinduct_thms,
   862           strong_coinduct_thms), lthy') =
   862           strong_coinduct_thms), lthy') =
   863       corec_specs_of bs arg_Ts res_Ts (get_indices fixes) callssss lthy;
   863       corec_specs_of bs arg_Ts res_Ts (get_indices fixes) callssss lthy;
   864     val actual_nn = length bs;
   864     val actual_nn = length bs;
   865     val corec_specs = take actual_nn corec_specs'; (*###*)
   865     val corec_specs = take actual_nn corec_specs'; (*###*)
       
   866     val ctr_specss = map #ctr_specs corec_specs;
   866 
   867 
   867     val disc_eqnss' = map_filter (try (fn Disc x => x)) eqns_data
   868     val disc_eqnss' = map_filter (try (fn Disc x => x)) eqns_data
   868       |> partition_eq ((op =) o pairself #fun_name)
   869       |> partition_eq ((op =) o pairself #fun_name)
   869       |> fst o finds (fn (x, ({fun_name, ...} :: _)) => x = fun_name) fun_names
   870       |> fst o finds (fn (x, ({fun_name, ...} :: _)) => x = fun_name) fun_names
   870       |> map (sort ((op <) o pairself #ctr_no |> make_ord) o flat o snd);
   871       |> map (sort ((op <) o pairself #ctr_no |> make_ord) o flat o snd);
   997                 |> Thm.close_derivation
   998                 |> Thm.close_derivation
   998                 |> pair ctr
   999                 |> pair ctr
   999                 |> single
  1000                 |> single
  1000             end;
  1001             end;
  1001 
  1002 
  1002         fun prove_code disc_eqns sel_eqns ctr_alist {ctr_specs, ...} =
  1003         fun prove_code disc_eqns sel_eqns ctr_alist ctr_specs =
  1003           let
  1004           let
  1004             val (fun_name, fun_T, fun_args, maybe_rhs) =
  1005             val (fun_name, fun_T, fun_args, maybe_rhs) =
  1005               (find_first (member (op =) (map #ctr ctr_specs) o #ctr) disc_eqns,
  1006               (find_first (member (op =) (map #ctr ctr_specs) o #ctr) disc_eqns,
  1006                find_first (member (op =) (map #ctr ctr_specs) o #ctr) sel_eqns)
  1007                find_first (member (op =) (map #ctr ctr_specs) o #ctr) sel_eqns)
  1007               |>> Option.map (fn x => (#fun_name x, #fun_T x, #fun_args x, #maybe_code_rhs x))
  1008               |>> Option.map (fn x => (#fun_name x, #fun_T x, #fun_args x, #maybe_code_rhs x))
  1042                     let
  1043                     let
  1043                       val rhs = fold_rev (fn SOME (prems, u) => fn t => mk_If (s_conjs prems) u t)
  1044                       val rhs = fold_rev (fn SOME (prems, u) => fn t => mk_If (s_conjs prems) u t)
  1044                         maybe_ctr_conds_argss
  1045                         maybe_ctr_conds_argss
  1045                         (Const (@{const_name Code.abort}, @{typ String.literal} -->
  1046                         (Const (@{const_name Code.abort}, @{typ String.literal} -->
  1046                             (@{typ unit} --> body_type fun_T) --> body_type fun_T) $
  1047                             (@{typ unit} --> body_type fun_T) --> body_type fun_T) $
  1047                           @{term "STR []"} $ (* FIXME *)
  1048                           HOLogic.mk_literal fun_name $
  1048                           absdummy @{typ unit} (incr_boundvars 1 lhs));
  1049                           absdummy @{typ unit} (incr_boundvars 1 lhs));
  1049                     in SOME (rhs, rhs, map snd ctr_alist) end
  1050                     in SOME (rhs, rhs, map snd ctr_alist) end
  1050                 end);
  1051                 end);
  1051           in
  1052           in
  1052             (case maybe_rhs_info of
  1053             (case maybe_rhs_info of
  1079         val sel_alists = map4 (map ooo prove_sel) corec_specs disc_eqnss exclssss sel_eqnss;
  1080         val sel_alists = map4 (map ooo prove_sel) corec_specs disc_eqnss exclssss sel_eqnss;
  1080         val disc_thmss = map (map snd) disc_alists;
  1081         val disc_thmss = map (map snd) disc_alists;
  1081         val sel_thmss = map (map snd) sel_alists;
  1082         val sel_thmss = map (map snd) sel_alists;
  1082 
  1083 
  1083         val ctr_alists = map5 (maps oooo prove_ctr) disc_alists sel_alists disc_eqnss sel_eqnss
  1084         val ctr_alists = map5 (maps oooo prove_ctr) disc_alists sel_alists disc_eqnss sel_eqnss
  1084           (map #ctr_specs corec_specs);
  1085           ctr_specss;
  1085         val ctr_thmss = map (map snd) ctr_alists;
  1086         val ctr_thmss = map (map snd) ctr_alists;
  1086 
  1087 
  1087         val code_thmss = map4 prove_code disc_eqnss sel_eqnss ctr_alists corec_specs;
  1088         val code_thmss = map4 prove_code disc_eqnss sel_eqnss ctr_alists ctr_specss;
  1088 
  1089 
  1089         val simp_thmss = map2 append disc_thmss sel_thmss
  1090         val simp_thmss = map2 append disc_thmss sel_thmss
  1090 
  1091 
  1091         val common_name = mk_common_name fun_names;
  1092         val common_name = mk_common_name fun_names;
  1092 
  1093