src/HOL/Tools/Sledgehammer/sledgehammer_proof_reconstruct.ML
changeset 37643 f576af716aa6
parent 37624 3ee568334813
child 37926 e6ff246c0cdb
equal deleted inserted replaced
37642:06992bc8bdda 37643:f576af716aa6
   212 (* Type variables are given the basic sort "HOL.type". Some will later be
   212 (* Type variables are given the basic sort "HOL.type". Some will later be
   213   constrained by information from type literals, or by type inference. *)
   213   constrained by information from type literals, or by type inference. *)
   214 fun type_from_node _ (u as IntLeaf _) = raise NODE [u]
   214 fun type_from_node _ (u as IntLeaf _) = raise NODE [u]
   215   | type_from_node tfrees (u as StrNode (a, us)) =
   215   | type_from_node tfrees (u as StrNode (a, us)) =
   216     let val Ts = map (type_from_node tfrees) us in
   216     let val Ts = map (type_from_node tfrees) us in
   217       case strip_prefix tconst_prefix a of
   217       case strip_prefix type_const_prefix a of
   218         SOME b => Type (invert_const b, Ts)
   218         SOME b => Type (invert_const b, Ts)
   219       | NONE =>
   219       | NONE =>
   220         if not (null us) then
   220         if not (null us) then
   221           raise NODE [u]  (* only "tconst"s have type arguments *)
   221           raise NODE [u]  (* only "tconst"s have type arguments *)
   222         else case strip_prefix tfree_prefix a of
   222         else case strip_prefix tfree_prefix a of
   251 
   251 
   252 (* First-order translation. No types are known for variables. "HOLogic.typeT"
   252 (* First-order translation. No types are known for variables. "HOLogic.typeT"
   253    should allow them to be inferred.*)
   253    should allow them to be inferred.*)
   254 fun term_from_node thy full_types tfrees =
   254 fun term_from_node thy full_types tfrees =
   255   let
   255   let
   256     fun aux opt_T args u =
   256     fun aux opt_T extra_us u =
   257       case u of
   257       case u of
   258         IntLeaf _ => raise NODE [u]
   258         IntLeaf _ => raise NODE [u]
   259       | StrNode ("hBOOL", [u1]) => aux (SOME @{typ bool}) [] u1
   259       | StrNode ("hBOOL", [u1]) => aux (SOME @{typ bool}) [] u1
   260       | StrNode ("hAPP", [u1, u2]) => aux opt_T (u2 :: args) u1
   260       | StrNode ("hAPP", [u1, u2]) => aux opt_T (u2 :: extra_us) u1
   261       | StrNode ("c_Not", [u1]) => @{const Not} $ aux (SOME @{typ bool}) [] u1
   261       | StrNode ("c_Not", [u1]) => @{const Not} $ aux (SOME @{typ bool}) [] u1
   262       | StrNode (a, us) =>
   262       | StrNode (a, us) =>
   263         if a = type_wrapper_name then
   263         if a = type_wrapper_name then
   264           case us of
   264           case us of
   265             [term_u, typ_u] =>
   265             [typ_u, term_u] =>
   266             aux (SOME (type_from_node tfrees typ_u)) args term_u
   266             aux (SOME (type_from_node tfrees typ_u)) extra_us term_u
   267           | _ => raise NODE us
   267           | _ => raise NODE us
   268         else case strip_prefix const_prefix a of
   268         else case strip_prefix const_prefix a of
   269           SOME "equal" =>
   269           SOME "equal" =>
   270           list_comb (Const (@{const_name "op ="}, HOLogic.typeT),
   270           list_comb (Const (@{const_name "op ="}, HOLogic.typeT),
   271                      map (aux NONE []) us)
   271                      map (aux NONE []) us)
   272         | SOME b =>
   272         | SOME b =>
   273           let
   273           let
   274             val c = invert_const b
   274             val c = invert_const b
   275             val num_type_args = num_type_args thy c
   275             val num_type_args = num_type_args thy c
   276             val actual_num_type_args = if full_types then 0 else num_type_args
   276             val (type_us, term_us) =
   277             val num_term_args = length us - actual_num_type_args
   277               chop (if full_types then 0 else num_type_args) us
   278             val ts = map (aux NONE []) (take num_term_args us @ args)
   278             (* Extra args from "hAPP" come after any arguments given directly to
       
   279                the constant. *)
       
   280             val term_ts = map (aux NONE []) term_us
       
   281             val extra_ts = map (aux NONE []) extra_us
   279             val t =
   282             val t =
   280               Const (c, if full_types then
   283               Const (c, if full_types then
   281                           case opt_T of
   284                           case opt_T of
   282                             SOME T => map fastype_of ts ---> T
   285                             SOME T => map fastype_of term_ts ---> T
   283                           | NONE =>
   286                           | NONE =>
   284                             if num_type_args = 0 then
   287                             if num_type_args = 0 then
   285                               Sign.const_instance thy (c, [])
   288                               Sign.const_instance thy (c, [])
   286                             else
   289                             else
   287                               raise Fail ("no type information for " ^ quote c)
   290                               raise Fail ("no type information for " ^ quote c)
   288                         else
   291                         else
   289                           (* Extra args from "hAPP" come after any arguments
       
   290                              given directly to the constant. *)
       
   291                           if String.isPrefix skolem_theory_name c then
   292                           if String.isPrefix skolem_theory_name c then
   292                             map fastype_of ts ---> HOLogic.typeT
   293                             map fastype_of term_ts ---> HOLogic.typeT
   293                           else
   294                           else
   294                             Sign.const_instance thy (c,
   295                             Sign.const_instance thy (c,
   295                                 map (type_from_node tfrees)
   296                                 map (type_from_node tfrees) type_us))
   296                                     (drop num_term_args us)))
   297           in list_comb (t, term_ts @ extra_ts) end
   297           in list_comb (t, ts) end
       
   298         | NONE => (* a free or schematic variable *)
   298         | NONE => (* a free or schematic variable *)
   299           let
   299           let
   300             val ts = map (aux NONE []) (us @ args)
   300             val ts = map (aux NONE []) (us @ extra_us)
   301             val T = map fastype_of ts ---> HOLogic.typeT
   301             val T = map fastype_of ts ---> HOLogic.typeT
   302             val t =
   302             val t =
   303               case strip_prefix fixed_var_prefix a of
   303               case strip_prefix fixed_var_prefix a of
   304                 SOME b => Free (b, T)
   304                 SOME b => Free (b, T)
   305               | NONE =>
   305               | NONE =>