src/HOL/Tools/ATP/atp_problem.ML
changeset 44535 3b0b448b4d69
parent 44283 dcbedaf6f80c
child 44536 2cd0b478d1b6
     1.1 --- a/src/HOL/Tools/ATP/atp_problem.ML	Tue Jul 05 09:54:39 2011 +0200
     1.2 +++ b/src/HOL/Tools/ATP/atp_problem.ML	Tue Jul 05 17:09:59 2011 +0100
     1.3 @@ -7,7 +7,9 @@
     1.4  
     1.5  signature ATP_PROBLEM =
     1.6  sig
     1.7 -  datatype 'a fo_term = ATerm of 'a * 'a fo_term list
     1.8 +  datatype ('a, 'b) ho_term =
     1.9 +    ATerm of 'a * ('a, 'b) ho_term list |
    1.10 +    AAbs of ('a * 'b) * ('a, 'b) ho_term
    1.11    datatype quantifier = AForall | AExists
    1.12    datatype connective = ANot | AAnd | AOr | AImplies | AIff
    1.13    datatype ('a, 'b, 'c) formula =
    1.14 @@ -21,8 +23,8 @@
    1.15    datatype formula_kind = Axiom | Definition | Lemma | Hypothesis | Conjecture
    1.16    datatype 'a problem_line =
    1.17      Decl of string * 'a * 'a ho_type |
    1.18 -    Formula of string * formula_kind * ('a, 'a ho_type, 'a fo_term) formula
    1.19 -               * string fo_term option * string fo_term option
    1.20 +    Formula of string * formula_kind * ('a, 'a ho_type, ('a, 'a ho_type) ho_term) formula
    1.21 +               * (string, string ho_type) ho_term option * (string, string ho_type) ho_term option
    1.22    type 'a problem = (string * 'a problem_line list) list
    1.23  
    1.24    val tptp_cnf : string
    1.25 @@ -91,7 +93,9 @@
    1.26  
    1.27  (** ATP problem **)
    1.28  
    1.29 -datatype 'a fo_term = ATerm of 'a * 'a fo_term list
    1.30 +datatype ('a, 'b) ho_term =
    1.31 +  ATerm of 'a * ('a, 'b) ho_term list |
    1.32 +  AAbs of ('a * 'b) * ('a, 'b) ho_term
    1.33  datatype quantifier = AForall | AExists
    1.34  datatype connective = ANot | AAnd | AOr | AImplies | AIff
    1.35  datatype ('a, 'b, 'c) formula =
    1.36 @@ -105,8 +109,8 @@
    1.37  datatype formula_kind = Axiom | Definition | Lemma | Hypothesis | Conjecture
    1.38  datatype 'a problem_line =
    1.39    Decl of string * 'a * 'a ho_type |
    1.40 -  Formula of string * formula_kind * ('a, 'a ho_type, 'a fo_term) formula
    1.41 -             * string fo_term option * string fo_term option
    1.42 +  Formula of string * formula_kind * ('a, 'a ho_type, ('a, 'a ho_type) ho_term) formula
    1.43 +             * (string, string ho_type) ho_term option * (string, string ho_type) ho_term option
    1.44  type 'a problem = (string * 'a problem_line list) list
    1.45  
    1.46  (* official TPTP syntax *)
    1.47 @@ -225,6 +229,9 @@
    1.48          else
    1.49            s ^ "(" ^ commas ss ^ ")"
    1.50        end
    1.51 +  | string_for_term THF (AAbs ((s, ty), tm)) =
    1.52 +    "^[" ^ s ^ ":" ^ string_for_type THF ty ^ "] : " ^ string_for_term THF tm
    1.53 +  | string_for_term _ _ = raise Fail "unexpected term in first-order format"
    1.54  
    1.55  fun string_for_quantifier AForall = tptp_forall
    1.56    | string_for_quantifier AExists = tptp_exists
    1.57 @@ -303,8 +310,9 @@
    1.58    | is_problem_line_cnf_ueq _ = false
    1.59  
    1.60  fun open_conjecture_term (ATerm ((s, s'), tms)) =
    1.61 -  ATerm (if is_tptp_variable s then (s |> Name.desymbolize false, s')
    1.62 -         else (s, s'), tms |> map open_conjecture_term)
    1.63 +    ATerm (if is_tptp_variable s then (s |> Name.desymbolize false, s')
    1.64 +           else (s, s'), tms |> map open_conjecture_term)
    1.65 +  | open_conjecture_term _ = raise Fail "unexpected higher-order term"
    1.66  fun open_formula conj =
    1.67    let
    1.68      (* We are conveniently assuming that all bound variable names are
    1.69 @@ -403,9 +411,10 @@
    1.70      fun do_type (AFun (ty1, ty2)) = fold do_type [ty1, ty2]
    1.71        | do_type (AType name) = do_sym name (K atype_of_types)
    1.72      fun do_term pred_sym (ATerm (name as (s, _), tms)) =
    1.73 -      is_tptp_user_symbol s
    1.74 -      ? do_sym name (fn _ => default_type pred_sym (length tms))
    1.75 -      #> fold (do_term false) tms
    1.76 +        is_tptp_user_symbol s
    1.77 +        ? do_sym name (fn _ => default_type pred_sym (length tms))
    1.78 +        #> fold (do_term false) tms
    1.79 +      | do_term _ (AAbs ((_, ty), tm)) = do_type ty #> do_term false tm
    1.80      fun do_formula (AQuant (_, xs, phi)) =
    1.81          fold do_type (map_filter snd xs) #> do_formula phi
    1.82        | do_formula (AConn (_, phis)) = fold do_formula phis
    1.83 @@ -496,10 +505,12 @@
    1.84            end
    1.85        in add 0 |> apsnd SOME end
    1.86  
    1.87 -fun nice_term (ATerm (name, ts)) =
    1.88 -  nice_name name ##>> pool_map nice_term ts #>> ATerm
    1.89  fun nice_type (AType name) = nice_name name #>> AType
    1.90    | nice_type (AFun (ty1, ty2)) = nice_type ty1 ##>> nice_type ty2 #>> AFun
    1.91 +fun nice_term (ATerm (name, ts)) =
    1.92 +    nice_name name ##>> pool_map nice_term ts #>> ATerm
    1.93 +  | nice_term (AAbs ((name, ty), tm)) =
    1.94 +    nice_name name ##>> nice_type ty ##>> nice_term tm #>> AAbs
    1.95  fun nice_formula (AQuant (q, xs, phi)) =
    1.96      pool_map nice_name (map fst xs)
    1.97      ##>> pool_map (fn NONE => pair NONE