src/HOL/Tools/Sledgehammer/sledgehammer_fol_clause.ML
changeset 36168 0a6ed065683d
parent 36167 c1a35be8e476
child 36169 27b1cc58715e
equal deleted inserted replaced
36167:c1a35be8e476 36168:0a6ed065683d
    31   val make_fixed_type_const : bool -> string -> string
    31   val make_fixed_type_const : bool -> string -> string
    32   val make_type_class : string -> string
    32   val make_type_class : string -> string
    33   datatype kind = Axiom | Conjecture
    33   datatype kind = Axiom | Conjecture
    34   type axiom_name = string
    34   type axiom_name = string
    35   datatype fol_type =
    35   datatype fol_type =
    36       AtomV of string
    36     TyVar of string |
    37     | AtomF of string
    37     TyFree of string |
    38     | Comp of string * fol_type list
    38     TyConstr of string * fol_type list
    39   val string_of_fol_type : fol_type -> string
    39   val string_of_fol_type : fol_type -> string
    40   datatype type_literal = LTVar of string * string | LTFree of string * string
    40   datatype type_literal = LTVar of string * string | LTFree of string * string
    41   exception CLAUSE of string * term
    41   exception CLAUSE of string * term
    42   val add_typs : typ list -> type_literal list
    42   val add_typs : typ list -> type_literal list
    43   val get_tvar_strs: typ list -> string list
    43   val get_tvar_strs: typ list -> string list
   213 
   213 
   214 type axiom_name = string;
   214 type axiom_name = string;
   215 
   215 
   216 (**** Isabelle FOL clauses ****)
   216 (**** Isabelle FOL clauses ****)
   217 
   217 
   218 (*FIXME: give the constructors more sensible names*)
   218 datatype fol_type =
   219 datatype fol_type = AtomV of string
   219   TyVar of string |
   220                   | AtomF of string
   220   TyFree of string |
   221                   | Comp of string * fol_type list;
   221   TyConstr of string * fol_type list
   222 
   222 
   223 fun string_of_fol_type (AtomV x) = x
   223 fun string_of_fol_type (TyVar s) = s
   224   | string_of_fol_type (AtomF x) = x
   224   | string_of_fol_type (TyFree s) = s
   225   | string_of_fol_type (Comp(tcon,tps)) =
   225   | string_of_fol_type (TyConstr (tcon, tps)) =
   226       tcon ^ (paren_pack (map string_of_fol_type tps));
   226       tcon ^ (paren_pack (map string_of_fol_type tps));
   227 
   227 
   228 (*First string is the type class; the second is a TVar or TFfree*)
   228 (*First string is the type class; the second is a TVar or TFfree*)
   229 datatype type_literal = LTVar of string * string | LTFree of string * string;
   229 datatype type_literal = LTVar of string * string | LTFree of string * string;
   230 
   230 
   231 exception CLAUSE of string * term;
   231 exception CLAUSE of string * term;
   232 
   232 
   233 fun atomic_type (TFree (a,_)) = AtomF(make_fixed_type_var a)
   233 fun atomic_type (TFree (a,_)) = TyFree(make_fixed_type_var a)
   234   | atomic_type (TVar (v,_))  = AtomV(make_schematic_type_var v);
   234   | atomic_type (TVar (v,_))  = TyVar(make_schematic_type_var v);
   235 
   235 
   236 (*Flatten a type to a fol_type while accumulating sort constraints on the TFrees and
   236 (*Flatten a type to a fol_type while accumulating sort constraints on the TFrees and
   237   TVars it contains.*)
   237   TVars it contains.*)
   238 fun type_of dfg (Type (a, Ts)) =
   238 fun type_of dfg (Type (a, Ts)) =
   239       let val (folTyps, ts) = types_of dfg Ts
   239       let val (folTyps, ts) = types_of dfg Ts
   240           val t = make_fixed_type_const dfg a
   240           val t = make_fixed_type_const dfg a
   241       in (Comp(t,folTyps), ts) end
   241       in (TyConstr (t, folTyps), ts) end
   242   | type_of dfg T = (atomic_type T, [T])
   242   | type_of dfg T = (atomic_type T, [T])
   243 and types_of dfg Ts =
   243 and types_of dfg Ts =
   244       let val (folTyps,ts) = ListPair.unzip (map (type_of dfg) Ts)
   244       let val (folTyps,ts) = ListPair.unzip (map (type_of dfg) Ts)
   245       in (folTyps, union_all ts) end;
   245       in (folTyps, union_all ts) end;
   246 
   246 
   399       fun upd (class,preds) = Symtab.update (class,1) preds
   399       fun upd (class,preds) = Symtab.update (class,1) preds
   400   in  List.foldl upd preds classes  end;
   400   in  List.foldl upd preds classes  end;
   401 
   401 
   402 (*** Find occurrences of functions in clauses ***)
   402 (*** Find occurrences of functions in clauses ***)
   403 
   403 
   404 fun add_foltype_funcs (AtomV _, funcs) = funcs
   404 fun add_foltype_funcs (TyVar _, funcs) = funcs
   405   | add_foltype_funcs (AtomF a, funcs) = Symtab.update (a,0) funcs
   405   | add_foltype_funcs (TyFree a, funcs) = Symtab.update (a,0) funcs
   406   | add_foltype_funcs (Comp(a,tys), funcs) =
   406   | add_foltype_funcs (TyConstr (a, tys), funcs) =
   407       List.foldl add_foltype_funcs (Symtab.update (a, length tys) funcs) tys;
   407       List.foldl add_foltype_funcs (Symtab.update (a, length tys) funcs) tys;
   408 
   408 
   409 (*TFrees are recorded as constants*)
   409 (*TFrees are recorded as constants*)
   410 fun add_type_sort_funcs (TVar _, funcs) = funcs
   410 fun add_type_sort_funcs (TVar _, funcs) = funcs
   411   | add_type_sort_funcs (TFree (a, _), funcs) =
   411   | add_type_sort_funcs (TFree (a, _), funcs) =