src/HOL/Tools/Sledgehammer/sledgehammer_reconstruct.ML
changeset 39425 5d97fd83ab37
parent 39374 4b35206e6360
child 39452 70a57e40f795
equal deleted inserted replaced
39420:0cf524fad3f5 39425:5d97fd83ab37
    59   | s_iff (t1, t2) = HOLogic.eq_const HOLogic.boolT $ t1 $ t2
    59   | s_iff (t1, t2) = HOLogic.eq_const HOLogic.boolT $ t1 $ t2
    60 
    60 
    61 fun mk_anot (AConn (ANot, [phi])) = phi
    61 fun mk_anot (AConn (ANot, [phi])) = phi
    62   | mk_anot phi = AConn (ANot, [phi])
    62   | mk_anot phi = AConn (ANot, [phi])
    63 fun mk_aconn c (phi1, phi2) = AConn (c, [phi1, phi2])
    63 fun mk_aconn c (phi1, phi2) = AConn (c, [phi1, phi2])
       
    64 
       
    65 fun forall_of v t = HOLogic.all_const (fastype_of v) $ lambda v t
       
    66 fun exists_of v t = HOLogic.exists_const (fastype_of v) $ lambda v t
    64 
    67 
    65 datatype raw_step_name = Str of string * string | Num of string
    68 datatype raw_step_name = Str of string * string | Num of string
    66 
    69 
    67 fun raw_step_num (Str (num, _)) = num
    70 fun raw_step_num (Str (num, _)) = num
    68   | raw_step_num (Num num) = num
    71   | raw_step_num (Num num) = num
   452       | do_term (t as Bound _) = t
   455       | do_term (t as Bound _) = t
   453       | do_term (Abs (a, T, t)) = Abs (a, do_type T, do_term t)
   456       | do_term (Abs (a, T, t)) = Abs (a, do_type T, do_term t)
   454       | do_term (t1 $ t2) = do_term t1 $ do_term t2
   457       | do_term (t1 $ t2) = do_term t1 $ do_term t2
   455   in t |> not (Vartab.is_empty tvar_tab) ? do_term end
   458   in t |> not (Vartab.is_empty tvar_tab) ? do_term end
   456 
   459 
   457 (* ### TODO: looks broken; see forall_of below *)
   460 fun quantify_over_var quant_of var_s t =
   458 fun quantify_over_free quant_s free_s body_t =
   461   let
   459   case Term.add_frees body_t [] |> filter (curry (op =) free_s o fst) of
   462     val vars = [] |> Term.add_vars t |> filter (fn ((s, _), _) => s = var_s)
   460     [] => body_t
   463                   |> map Var
   461   | frees as (_, free_T) :: _ =>
   464   in fold_rev quant_of vars t end
   462     Abs (free_s, free_T, fold (curry abstract_over) (map Free frees) body_t)
       
   463 
   465 
   464 (* Interpret an ATP formula as a HOL term, extracting sort constraints as they
   466 (* Interpret an ATP formula as a HOL term, extracting sort constraints as they
   465    appear in the formula. *)
   467    appear in the formula. *)
   466 fun prop_from_formula thy full_types tfrees phi =
   468 fun prop_from_formula thy full_types tfrees phi =
   467   let
   469   let
   468     fun do_formula pos phi =
   470     fun do_formula pos phi =
   469       case phi of
   471       case phi of
   470         AQuant (_, [], phi) => do_formula pos phi
   472         AQuant (_, [], phi) => do_formula pos phi
   471       | AQuant (q, x :: xs, phi') =>
   473       | AQuant (q, x :: xs, phi') =>
   472         do_formula pos (AQuant (q, xs, phi'))
   474         do_formula pos (AQuant (q, xs, phi'))
   473         #>> quantify_over_free (case q of
   475         #>> quantify_over_var (case q of
   474                                   AForall => @{const_name All}
   476                                  AForall => forall_of
   475                                 | AExists => @{const_name Ex})
   477                                | AExists => exists_of)
   476                                (repair_atp_variable_name Char.toLower x)
   478                               (repair_atp_variable_name Char.toLower x)
   477       | AConn (ANot, [phi']) => do_formula (not pos) phi' #>> s_not
   479       | AConn (ANot, [phi']) => do_formula (not pos) phi' #>> s_not
   478       | AConn (c, [phi1, phi2]) =>
   480       | AConn (c, [phi1, phi2]) =>
   479         do_formula (pos |> c = AImplies ? not) phi1
   481         do_formula (pos |> c = AImplies ? not) phi1
   480         ##>> do_formula pos phi2
   482         ##>> do_formula pos phi2
   481         #>> (case c of
   483         #>> (case c of
   729   if is_axiom axiom_names name then
   731   if is_axiom axiom_names name then
   730     apsnd (union (op =) (map fst (resolve_axiom axiom_names name)))
   732     apsnd (union (op =) (map fst (resolve_axiom axiom_names name)))
   731   else
   733   else
   732     apfst (insert (op =) (raw_label_for_name conjecture_shape name))
   734     apfst (insert (op =) (raw_label_for_name conjecture_shape name))
   733 
   735 
   734 fun forall_of v t = HOLogic.all_const (fastype_of v) $ lambda v t
       
   735 fun forall_vars t = fold_rev forall_of (map Var (Term.add_vars t [])) t
       
   736 
       
   737 fun step_for_line _ _ _ (Definition (_, t1, t2)) = Let (t1, t2)
   736 fun step_for_line _ _ _ (Definition (_, t1, t2)) = Let (t1, t2)
   738   | step_for_line conjecture_shape _ _ (Inference (name, t, [])) =
   737   | step_for_line conjecture_shape _ _ (Inference (name, t, [])) =
   739     Assume (raw_label_for_name conjecture_shape name, t)
   738     Assume (raw_label_for_name conjecture_shape name, t)
   740   | step_for_line conjecture_shape axiom_names j (Inference (name, t, deps)) =
   739   | step_for_line conjecture_shape axiom_names j (Inference (name, t, deps)) =
   741     Have (if j = 1 then [Show] else [],
   740     Have (if j = 1 then [Show] else [],
   742           raw_label_for_name conjecture_shape name, forall_vars t,
   741           raw_label_for_name conjecture_shape name,
       
   742           fold_rev forall_of (map Var (Term.add_vars t [])) t,
   743           ByMetis (fold (add_fact_from_dependency conjecture_shape axiom_names)
   743           ByMetis (fold (add_fact_from_dependency conjecture_shape axiom_names)
   744                         deps ([], [])))
   744                         deps ([], [])))
   745 
   745 
   746 fun raw_step_name (Definition (name, _, _)) = name
   746 fun raw_step_name (Definition (name, _, _)) = name
   747   | raw_step_name (Inference (name, _, _)) = name
   747   | raw_step_name (Inference (name, _, _)) = name