src/HOL/Tools/BNF/bnf_fp_rec_sugar_util.ML
changeset 69593 3dda49e08b9d
parent 67313 a2d7c0987f19
equal deleted inserted replaced
69592:a80d8ec6c998 69593:3dda49e08b9d
   199       error_at ctxt ats ("Duplicable variable " ^ quote (Syntax.string_of_term ctxt (hd dups)) ^
   199       error_at ctxt ats ("Duplicable variable " ^ quote (Syntax.string_of_term ctxt (hd dups)) ^
   200         " in left-hand side"))
   200         " in left-hand side"))
   201   end;
   201   end;
   202 
   202 
   203 fun check_top_sort ctxt b T =
   203 fun check_top_sort ctxt b T =
   204   ignore (Sign.of_sort (Proof_Context.theory_of ctxt) (T, @{sort type}) orelse
   204   ignore (Sign.of_sort (Proof_Context.theory_of ctxt) (T, \<^sort>\<open>type\<close>) orelse
   205     error ("Type of " ^ Binding.print b ^ " contains top sort"));
   205     error ("Type of " ^ Binding.print b ^ " contains top sort"));
   206 
   206 
   207 datatype fp_kind = Least_FP | Greatest_FP;
   207 datatype fp_kind = Least_FP | Greatest_FP;
   208 
   208 
   209 fun case_fp Least_FP l _ = l
   209 fun case_fp Least_FP l _ = l
   262     map (fn x => the (find_first (fn (y :: _) => eq (y, x)) sccs)) ordered_normals
   262     map (fn x => the (find_first (fn (y :: _) => eq (y, x)) sccs)) ordered_normals
   263   end;
   263   end;
   264 
   264 
   265 val mk_common_name = space_implode "_";
   265 val mk_common_name = space_implode "_";
   266 
   266 
   267 fun num_binder_types (Type (@{type_name fun}, [_, T])) = 1 + num_binder_types T
   267 fun num_binder_types (Type (\<^type_name>\<open>fun\<close>, [_, T])) = 1 + num_binder_types T
   268   | num_binder_types _ = 0;
   268   | num_binder_types _ = 0;
   269 
   269 
   270 val exists_subtype_in = Term.exists_subtype o member (op =);
   270 val exists_subtype_in = Term.exists_subtype o member (op =);
   271 fun exists_strict_subtype_in Ts T = exists_subtype_in (remove (op =) T Ts) T;
   271 fun exists_strict_subtype_in Ts T = exists_subtype_in (remove (op =) T Ts) T;
   272 
   272 
   276 fun retype_const_or_free T (Const (s, _)) = Const (s, T)
   276 fun retype_const_or_free T (Const (s, _)) = Const (s, T)
   277   | retype_const_or_free T (Free (s, _)) = Free (s, T)
   277   | retype_const_or_free T (Free (s, _)) = Free (s, T)
   278   | retype_const_or_free _ t = raise TERM ("retype_const_or_free", [t]);
   278   | retype_const_or_free _ t = raise TERM ("retype_const_or_free", [t]);
   279 
   279 
   280 fun drop_all t =
   280 fun drop_all t =
   281   subst_bounds (strip_qnt_vars @{const_name Pure.all} t |> map Free |> rev,
   281   subst_bounds (strip_qnt_vars \<^const_name>\<open>Pure.all\<close> t |> map Free |> rev,
   282     strip_qnt_body @{const_name Pure.all} t);
   282     strip_qnt_body \<^const_name>\<open>Pure.all\<close> t);
   283 
   283 
   284 fun permute_args n t =
   284 fun permute_args n t =
   285   list_comb (t, map Bound (0 :: (n downto 1))) |> fold (K (Term.abs (Name.uu, dummyT))) (0 upto n);
   285   list_comb (t, map Bound (0 :: (n downto 1))) |> fold (K (Term.abs (Name.uu, dummyT))) (0 upto n);
   286 
   286 
   287 fun mk_partial_comp fT g = fst (Term.dest_comb (HOLogic.mk_comp (g, Free (Name.uu, fT))));
   287 fun mk_partial_comp fT g = fst (Term.dest_comb (HOLogic.mk_comp (g, Free (Name.uu, fT))));