src/HOL/Tools/SMT/smt_builtin.ML
changeset 41354 0abe5db19f3a
parent 41336 0ea5b9c7d233
child 41473 3717fc42ebe9
equal deleted inserted replaced
41345:e284a364f724 41354:0abe5db19f3a
    25   type bfunr = string * int * term list * (term list -> term)
    25   type bfunr = string * int * term list * (term list -> term)
    26   val add_builtin_fun: SMT_Utils.class ->
    26   val add_builtin_fun: SMT_Utils.class ->
    27     (string * typ) * bfunr option bfun -> Context.generic -> Context.generic
    27     (string * typ) * bfunr option bfun -> Context.generic -> Context.generic
    28   val add_builtin_fun': SMT_Utils.class -> term * string -> Context.generic ->
    28   val add_builtin_fun': SMT_Utils.class -> term * string -> Context.generic ->
    29     Context.generic
    29     Context.generic
    30   val add_builtin_fun_ext: (string * typ) * bool bfun -> Context.generic ->
    30   val add_builtin_fun_ext: (string * typ) * term list bfun ->
    31     Context.generic
    31     Context.generic -> Context.generic
    32   val add_builtin_fun_ext': string * typ -> Context.generic -> Context.generic
    32   val add_builtin_fun_ext': string * typ -> Context.generic -> Context.generic
    33   val add_builtin_fun_ext'': string -> Context.generic -> Context.generic
    33   val add_builtin_fun_ext'': string -> Context.generic -> Context.generic
    34   val dest_builtin_fun: Proof.context -> string * typ -> term list ->
    34   val dest_builtin_fun: Proof.context -> string * typ -> term list ->
    35     bfunr option
    35     bfunr option
    36   val dest_builtin_eq: Proof.context -> term -> term -> bfunr option
    36   val dest_builtin_eq: Proof.context -> term -> term -> bfunr option
    37   val dest_builtin_pred: Proof.context -> string * typ -> term list ->
    37   val dest_builtin_pred: Proof.context -> string * typ -> term list ->
    38     bfunr option
    38     bfunr option
    39   val dest_builtin_conn: Proof.context -> string * typ -> term list ->
    39   val dest_builtin_conn: Proof.context -> string * typ -> term list ->
    40     bfunr option
    40     bfunr option
    41   val dest_builtin: Proof.context -> string * typ -> term list -> bfunr option
    41   val dest_builtin: Proof.context -> string * typ -> term list -> bfunr option
       
    42   val dest_builtin_ext: Proof.context -> string * typ -> term list ->
       
    43     term list option
    42   val is_builtin_fun: Proof.context -> string * typ -> term list -> bool
    44   val is_builtin_fun: Proof.context -> string * typ -> term list -> bool
    43   val is_builtin_fun_ext: Proof.context -> string * typ -> term list -> bool
    45   val is_builtin_fun_ext: Proof.context -> string * typ -> term list -> bool
    44 end
    46 end
    45 
    47 
    46 structure SMT_Builtin: SMT_BUILTIN =
    48 structure SMT_Builtin: SMT_BUILTIN =
   146 
   148 
   147 type bfunr = string * int * term list * (term list -> term)
   149 type bfunr = string * int * term list * (term list -> term)
   148 
   150 
   149 structure Builtin_Funcs = Generic_Data
   151 structure Builtin_Funcs = Generic_Data
   150 (
   152 (
   151   type T = (bool bfun, bfunr option bfun) btab
   153   type T = (term list bfun, bfunr option bfun) btab
   152   val empty = Symtab.empty
   154   val empty = Symtab.empty
   153   val extend = I
   155   val extend = I
   154   val merge = merge_btab
   156   val merge = merge_btab
   155 )
   157 )
   156 
   158 
   165   in add_builtin_fun cs (c, bfun) end
   167   in add_builtin_fun cs (c, bfun) end
   166 
   168 
   167 fun add_builtin_fun_ext ((n, T), f) =
   169 fun add_builtin_fun_ext ((n, T), f) =
   168   Builtin_Funcs.map (insert_btab SMT_Utils.basicC n T (Ext f))
   170   Builtin_Funcs.map (insert_btab SMT_Utils.basicC n T (Ext f))
   169 
   171 
   170 fun add_builtin_fun_ext' c =
   172 fun add_builtin_fun_ext' c = add_builtin_fun_ext (c, fn _ => fn _ => I)
   171   add_builtin_fun_ext (c, fn _ => fn _ => fn _ => true)
       
   172 
   173 
   173 fun add_builtin_fun_ext'' n context =
   174 fun add_builtin_fun_ext'' n context =
   174   let val thy = Context.theory_of context
   175   let val thy = Context.theory_of context
   175   in add_builtin_fun_ext' (n, Sign.the_const_type thy n) context end
   176   in add_builtin_fun_ext' (n, Sign.the_const_type thy n) context end
   176 
   177 
   208     (case dest_builtin_num ctxt t of
   209     (case dest_builtin_num ctxt t of
   209       SOME (n, _) => SOME (n, 0, [], K t)
   210       SOME (n, _) => SOME (n, 0, [], K t)
   210     | NONE => dest_builtin_fun ctxt c ts)
   211     | NONE => dest_builtin_fun ctxt c ts)
   211   end
   212   end
   212 
   213 
       
   214 fun dest_builtin_fun_ext ctxt (c as (_, T)) ts =    
       
   215   (case lookup_builtin_fun ctxt c of
       
   216     SOME (_, Int f) => f ctxt T ts |> Option.map (fn (_, _, us, _) => us)
       
   217   | SOME (_, Ext f) => SOME (f ctxt T ts)
       
   218   | NONE => NONE)
       
   219 
       
   220 fun dest_builtin_ext ctxt c ts =
       
   221   if is_builtin_num_ext ctxt (Term.list_comb (Const c, ts)) then SOME []
       
   222   else dest_builtin_fun_ext ctxt c ts
       
   223 
   213 fun is_builtin_fun ctxt c ts = is_some (dest_builtin_fun ctxt c ts)
   224 fun is_builtin_fun ctxt c ts = is_some (dest_builtin_fun ctxt c ts)
   214 
   225 
   215 fun is_builtin_fun_ext ctxt (c as (_, T)) ts =
   226 fun is_builtin_fun_ext ctxt c ts = is_some (dest_builtin_fun_ext ctxt c ts)
   216   (case lookup_builtin_fun ctxt c of
       
   217     SOME (_, Int f) => is_some (f ctxt T ts)
       
   218   | SOME (_, Ext f) => f ctxt T ts
       
   219   | NONE => false)
       
   220 
   227 
   221 end
   228 end