src/HOL/Tools/Sledgehammer/sledgehammer_mash.ML
changeset 53128 ea1b62ed5a54
parent 53127 60801776d8af
child 53129 f92b24047fc7
equal deleted inserted replaced
53127:60801776d8af 53128:ea1b62ed5a54
   589 val crude_str_of_sort =
   589 val crude_str_of_sort =
   590   space_implode ":" o map massage_long_name o subtract (op =) @{sort type}
   590   space_implode ":" o map massage_long_name o subtract (op =) @{sort type}
   591 
   591 
   592 fun crude_str_of_typ (Type (s, [])) = massage_long_name s
   592 fun crude_str_of_typ (Type (s, [])) = massage_long_name s
   593   | crude_str_of_typ (Type (s, Ts)) =
   593   | crude_str_of_typ (Type (s, Ts)) =
   594     massage_long_name s ^
   594     massage_long_name s ^ implode (map crude_str_of_typ Ts)
   595     enclose "(" ")" (space_implode "," (map crude_str_of_typ Ts))
       
   596   | crude_str_of_typ (TFree (_, S)) = crude_str_of_sort S
   595   | crude_str_of_typ (TFree (_, S)) = crude_str_of_sort S
   597   | crude_str_of_typ (TVar (_, S)) = crude_str_of_sort S
   596   | crude_str_of_typ (TVar (_, S)) = crude_str_of_sort S
       
   597 
       
   598 fun maybe_singleton_str _ "" = []
       
   599   | maybe_singleton_str pref s = [pref ^ s]
   598 
   600 
   599 val max_pat_breadth = 10
   601 val max_pat_breadth = 10
   600 
   602 
   601 fun term_features_of ctxt prover thy_name num_facts const_tab term_max_depth
   603 fun term_features_of ctxt prover thy_name num_facts const_tab term_max_depth
   602                      type_max_depth ts =
   604                      type_max_depth ts =
   626         let
   628         let
   627           val T = Type (s, Ts)
   629           val T = Type (s, Ts)
   628           val ps = take max_pat_breadth (pattify_type depth T)
   630           val ps = take max_pat_breadth (pattify_type depth T)
   629           val qs = take max_pat_breadth ("" :: pattify_type (depth - 1) U)
   631           val qs = take max_pat_breadth ("" :: pattify_type (depth - 1) U)
   630         in pass_args ps qs end
   632         in pass_args ps qs end
   631       | pattify_type _ (TFree (_, S)) = [pat_tvar_prefix ^ crude_str_of_sort S]
   633       | pattify_type _ (TFree (_, S)) =
   632       | pattify_type _ (TVar (_, S)) = [pat_tvar_prefix ^ crude_str_of_sort S]
   634         maybe_singleton_str pat_tvar_prefix (crude_str_of_sort S)
       
   635       | pattify_type _ (TVar (_, S)) =
       
   636         maybe_singleton_str pat_tvar_prefix (crude_str_of_sort S)
   633     fun add_type_pat depth T =
   637     fun add_type_pat depth T =
   634       union (op = o pairself fst) (map type_feature_of (pattify_type depth T))
   638       union (op = o pairself fst) (map type_feature_of (pattify_type depth T))
   635     fun add_type_pats 0 _ = I
   639     fun add_type_pats 0 _ = I
   636       | add_type_pats depth t =
   640       | add_type_pats depth t =
   637         add_type_pat depth t #> add_type_pats (depth - 1) t
   641         add_type_pat depth t #> add_type_pats (depth - 1) t
   643 
   647 
   644     fun pattify_term _ _ 0 _ = []
   648     fun pattify_term _ _ 0 _ = []
   645       | pattify_term _ args _ (Const (x as (s, _))) =
   649       | pattify_term _ args _ (Const (x as (s, _))) =
   646         if fst (is_built_in x args) then [] else [massage_long_name s]
   650         if fst (is_built_in x args) then [] else [massage_long_name s]
   647       | pattify_term _ _ _ (Free (s, T)) =
   651       | pattify_term _ _ _ (Free (s, T)) =
   648         [pat_var_prefix ^ crude_str_of_typ T]
   652         maybe_singleton_str pat_var_prefix (crude_str_of_typ T)
   649         |> (if member (op =) fixes s then
   653         |> (if member (op =) fixes s then
   650               cons (massage_long_name (thy_name ^ Long_Name.separator ^ s))
   654               cons (massage_long_name (thy_name ^ Long_Name.separator ^ s))
   651             else
   655             else
   652               I)
   656               I)
   653       | pattify_term _ _ _ (Var (_, T)) = [pat_var_prefix ^ crude_str_of_typ T]
   657       | pattify_term _ _ _ (Var (_, T)) =
       
   658         maybe_singleton_str pat_var_prefix (crude_str_of_typ T)
   654       | pattify_term Ts _ _ (Bound j) =
   659       | pattify_term Ts _ _ (Bound j) =
   655         [pat_var_prefix ^ crude_str_of_typ (nth Ts j)]
   660         maybe_singleton_str pat_var_prefix (crude_str_of_typ (nth Ts j))
   656       | pattify_term Ts args depth (t $ u) =
   661       | pattify_term Ts args depth (t $ u) =
   657         let
   662         let
   658           val ps = take max_pat_breadth (pattify_term Ts (u :: args) depth t)
   663           val ps = take max_pat_breadth (pattify_term Ts (u :: args) depth t)
   659           val qs = take max_pat_breadth ("" :: pattify_term Ts [] (depth - 1) u)
   664           val qs = take max_pat_breadth ("" :: pattify_term Ts [] (depth - 1) u)
   660         in pass_args ps qs end
   665         in pass_args ps qs end