src/HOL/Tools/Nitpick/nitpick_hol.ML
changeset 46115 ecab67f5a5c2
parent 46113 dd112cd72c48
child 46217 7b19666f0e3d
equal deleted inserted replaced
46114:e6d33b200f42 46115:ecab67f5a5c2
    85   val const_match : theory -> styp * styp -> bool
    85   val const_match : theory -> styp * styp -> bool
    86   val term_match : theory -> term * term -> bool
    86   val term_match : theory -> term * term -> bool
    87   val frac_from_term_pair : typ -> term -> term -> term
    87   val frac_from_term_pair : typ -> term -> term -> term
    88   val is_TFree : typ -> bool
    88   val is_TFree : typ -> bool
    89   val is_fun_type : typ -> bool
    89   val is_fun_type : typ -> bool
       
    90   val is_set_type : typ -> bool
       
    91   val is_fun_or_set_type : typ -> bool
    90   val is_set_like_type : typ -> bool
    92   val is_set_like_type : typ -> bool
    91   val is_pair_type : typ -> bool
    93   val is_pair_type : typ -> bool
    92   val is_lfp_iterator_type : typ -> bool
    94   val is_lfp_iterator_type : typ -> bool
    93   val is_gfp_iterator_type : typ -> bool
    95   val is_gfp_iterator_type : typ -> bool
    94   val is_fp_iterator_type : typ -> bool
    96   val is_fp_iterator_type : typ -> bool
   480 
   482 
   481 fun is_TFree (TFree _) = true
   483 fun is_TFree (TFree _) = true
   482   | is_TFree _ = false
   484   | is_TFree _ = false
   483 fun is_fun_type (Type (@{type_name fun}, _)) = true
   485 fun is_fun_type (Type (@{type_name fun}, _)) = true
   484   | is_fun_type _ = false
   486   | is_fun_type _ = false
   485 fun is_set_like_type (Type (@{type_name fun}, [_, @{typ bool}])) = true
   487 fun is_set_type (Type (@{type_name set}, _)) = true
       
   488   | is_set_type _ = false
       
   489 val is_fun_or_set_type = is_fun_type orf is_set_type
       
   490 fun is_set_like_type (Type (@{type_name fun}, [_, T'])) =
       
   491     (body_type T' = bool_T)
   486   | is_set_like_type (Type (@{type_name set}, _)) = true
   492   | is_set_like_type (Type (@{type_name set}, _)) = true
   487   | is_set_like_type _ = false
   493   | is_set_like_type _ = false
   488 fun is_pair_type (Type (@{type_name prod}, _)) = true
   494 fun is_pair_type (Type (@{type_name prod}, _)) = true
   489   | is_pair_type _ = false
   495   | is_pair_type _ = false
   490 fun is_lfp_iterator_type (Type (s, _)) = String.isPrefix lfp_iterator_prefix s
   496 fun is_lfp_iterator_type (Type (s, _)) = String.isPrefix lfp_iterator_prefix s
   504 fun is_frac_type ctxt (Type (s, [])) =
   510 fun is_frac_type ctxt (Type (s, [])) =
   505     s |> AList.defined (op =) (#frac_types (Data.get (Context.Proof ctxt)))
   511     s |> AList.defined (op =) (#frac_types (Data.get (Context.Proof ctxt)))
   506   | is_frac_type _ _ = false
   512   | is_frac_type _ _ = false
   507 fun is_number_type ctxt = is_integer_like_type orf is_frac_type ctxt
   513 fun is_number_type ctxt = is_integer_like_type orf is_frac_type ctxt
   508 fun is_higher_order_type (Type (@{type_name fun}, _)) = true
   514 fun is_higher_order_type (Type (@{type_name fun}, _)) = true
       
   515   | is_higher_order_type (Type (@{type_name set}, _)) = true
   509   | is_higher_order_type (Type (_, Ts)) = exists is_higher_order_type Ts
   516   | is_higher_order_type (Type (_, Ts)) = exists is_higher_order_type Ts
   510   | is_higher_order_type _ = false
   517   | is_higher_order_type _ = false
   511 
   518 
   512 fun elem_type (Type (@{type_name set}, [T'])) = T'
   519 fun elem_type (Type (@{type_name set}, [T'])) = T'
   513   | elem_type T = raise TYPE ("Nitpick_HOL.elem_type", [T], [])
   520   | elem_type T = raise TYPE ("Nitpick_HOL.elem_type", [T], [])
  1814   in do_term 0 [] end
  1821   in do_term 0 [] end
  1815 
  1822 
  1816 (** Axiom extraction/generation **)
  1823 (** Axiom extraction/generation **)
  1817 
  1824 
  1818 fun extensional_equal j T t1 t2 =
  1825 fun extensional_equal j T t1 t2 =
  1819   if is_fun_type T orelse is_set_like_type T then
  1826   if is_fun_or_set_type T then
  1820     let
  1827     let
  1821       val dom_T = pseudo_domain_type T
  1828       val dom_T = pseudo_domain_type T
  1822       val ran_T = pseudo_range_type T
  1829       val ran_T = pseudo_range_type T
  1823       val var_t = Var (("x", j), dom_T)
  1830       val var_t = Var (("x", j), dom_T)
  1824       fun apply fun_t arg_t =
  1831       fun apply fun_t arg_t =
  2231     list_abs (outer, image_set |> ap_curry tuple_arg_Ts tuple_T)
  2238     list_abs (outer, image_set |> ap_curry tuple_arg_Ts tuple_T)
  2232     |> unfold_defs_in_term hol_ctxt
  2239     |> unfold_defs_in_term hol_ctxt
  2233   end
  2240   end
  2234 
  2241 
  2235 fun is_good_starred_linear_pred_type (Type (@{type_name fun}, Ts)) =
  2242 fun is_good_starred_linear_pred_type (Type (@{type_name fun}, Ts)) =
  2236     forall (not o (is_fun_type orf is_pair_type)) Ts
  2243     forall (not o (is_fun_or_set_type orf is_pair_type)) Ts
  2237   | is_good_starred_linear_pred_type _ = false
  2244   | is_good_starred_linear_pred_type _ = false
  2238 
  2245 
  2239 fun unrolled_inductive_pred_const (hol_ctxt as {thy, star_linear_preds,
  2246 fun unrolled_inductive_pred_const (hol_ctxt as {thy, star_linear_preds,
  2240                                                 def_tables, simp_table, ...})
  2247                                                 def_tables, simp_table, ...})
  2241                                   gfp (x as (s, T)) =
  2248                                   gfp (x as (s, T)) =