src/HOL/Tools/SMT/smt_real.ML
changeset 41280 a7de9d36f4f2
parent 41072 9f9bc1bdacef
child 41281 679118e35378
equal deleted inserted replaced
41277:1369c27c6966 41280:a7de9d36f4f2
    10 end
    10 end
    11 
    11 
    12 structure SMT_Real: SMT_REAL =
    12 structure SMT_Real: SMT_REAL =
    13 struct
    13 struct
    14 
    14 
       
    15 structure U = SMT_Utils
    15 structure B = SMT_Builtin
    16 structure B = SMT_Builtin
    16 
    17 
    17 
    18 
    18 (* SMT-LIB logic *)
    19 (* SMT-LIB logic *)
    19 
    20 
    27 
    28 
    28 local
    29 local
    29   val smtlibC = SMTLIB_Interface.smtlibC
    30   val smtlibC = SMTLIB_Interface.smtlibC
    30 
    31 
    31   fun real_num _ i = SOME (string_of_int i ^ ".0")
    32   fun real_num _ i = SOME (string_of_int i ^ ".0")
       
    33 
       
    34   fun is_linear [t] = U.is_number t
       
    35     | is_linear [t, u] = U.is_number t orelse U.is_number u
       
    36     | is_linear _ = false
       
    37 
       
    38   fun times _ T ts = if is_linear ts then SOME ((("*", 2), T), ts, T) else NONE
       
    39     | times _ _ _  = NONE
       
    40 
       
    41   fun divide _ T (ts as [_, t]) =
       
    42         if U.is_number t then SOME ((("/", 2), T), ts, T) else NONE
       
    43     | divide _ _ _ = NONE
    32 in
    44 in
    33 
    45 
    34 val setup_builtins =
    46 val setup_builtins =
    35   B.add_builtin_typ smtlibC (@{typ real}, K (SOME "Real"), real_num) #>
    47   B.add_builtin_typ smtlibC (@{typ real}, K (SOME "Real"), real_num) #>
    36   fold (B.add_builtin_fun' smtlibC) [
    48   fold (B.add_builtin_fun' smtlibC) [
       
    49     (@{const less (real)}, "<"),
       
    50     (@{const less_eq (real)}, "<="),
    37     (@{const uminus (real)}, "~"),
    51     (@{const uminus (real)}, "~"),
    38     (@{const plus (real)}, "+"),
    52     (@{const plus (real)}, "+"),
    39     (@{const minus (real)}, "-"),
    53     (@{const minus (real)}, "-") ] #>
    40     (@{const times (real)}, "*"),
    54   B.add_builtin_fun SMTLIB_Interface.smtlibC
    41     (@{const less (real)}, "<"),
    55     (Term.dest_Const @{const times (real)}, times) #>
    42     (@{const less_eq (real)}, "<=") ] #>
    56   B.add_builtin_fun Z3_Interface.smtlib_z3C
    43   B.add_builtin_fun' Z3_Interface.smtlib_z3C (@{const divide (real)}, "/")
    57     (Term.dest_Const @{const divide (real)}, divide)
    44 
    58 
    45 end
    59 end
    46 
    60 
    47 
    61 
    48 (* Z3 constructors *)
    62 (* Z3 constructors *)