src/HOL/Tools/SMT/smt_builtin.ML
author haftmann
Wed, 01 Dec 2010 18:00:40 +0100
changeset 40858 69ab03d29c92
parent 40691 a68f64f99832
child 41059 d2b1fc1b8e19
permissions -rw-r--r--
merged
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40277
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
     1
(*  Title:      HOL/Tools/SMT/smt_builtin.ML
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
     2
    Author:     Sascha Boehme, TU Muenchen
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
     3
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
     4
Crafted collection of SMT built-in symbols.
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
     5
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
     6
FIXME: This list is currently not automatically kept synchronized with the
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
     7
remaining implementation.
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
     8
*)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
     9
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    10
signature SMT_BUILTIN =
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    11
sig
40686
4725ed462387 swap names for built-in tester functions (to better reflect the intuition of what they do);
boehmes
parents: 40681
diff changeset
    12
  val is_builtin: Proof.context -> string * typ -> bool
40277
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    13
  val is_partially_builtin: Proof.context -> string * typ -> bool
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    14
end
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    15
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    16
structure SMT_Builtin: SMT_BUILTIN =
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    17
struct
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    18
40677
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    19
fun is_arithT T =
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    20
  (case T of
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    21
     @{typ int} => true
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    22
   | @{typ nat} => true
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    23
   | Type ("RealDef.real", []) => true
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    24
   | _ => false)
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    25
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    26
fun is_arithT_dom (Type (@{type_name fun}, [T, _])) = is_arithT T
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    27
  | is_arithT_dom _ = false
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    28
fun is_arithT_ran (Type (@{type_name fun}, [_, T])) = is_arithT T
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    29
  | is_arithT_ran _ = false
40277
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    30
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    31
val builtins = Symtab.make [
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    32
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    33
  (* Pure constants *)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    34
  (@{const_name all}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    35
  (@{const_name "=="}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    36
  (@{const_name "==>"}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    37
  (@{const_name Trueprop}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    38
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    39
  (* logical constants *)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    40
  (@{const_name All}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    41
  (@{const_name Ex}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    42
  (@{const_name Ball}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    43
  (@{const_name Bex}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    44
  (@{const_name Ex1}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    45
  (@{const_name True}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    46
  (@{const_name False}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    47
  (@{const_name Not}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    48
  (@{const_name HOL.conj}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    49
  (@{const_name HOL.disj}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    50
  (@{const_name HOL.implies}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    51
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    52
  (* term abbreviations *)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    53
  (@{const_name If}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    54
  (@{const_name bool.bool_case}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    55
  (@{const_name Let}, K true),
40681
872b08416fb4 be more precise: only treat constant 'distinct' applied to an explicit list as built-in
boehmes
parents: 40677
diff changeset
    56
  (* (@{const_name distinct}, K true),  -- not a real builtin, only when
872b08416fb4 be more precise: only treat constant 'distinct' applied to an explicit list as built-in
boehmes
parents: 40677
diff changeset
    57
                                           applied to an explicit list *)
40277
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    58
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    59
  (* technicalities *)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    60
  (@{const_name SMT.pat}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    61
  (@{const_name SMT.nopat}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    62
  (@{const_name SMT.trigger}, K true),
40664
e023788a91a1 added support for quantifier weight annotations
boehmes
parents: 40277
diff changeset
    63
  (@{const_name SMT.weight}, K true),
40277
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    64
  (@{const_name SMT.fun_app}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    65
  (@{const_name SMT.z3div}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    66
  (@{const_name SMT.z3mod}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    67
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    68
  (* equality *)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    69
  (@{const_name HOL.eq}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    70
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    71
  (* numerals *)
40691
a68f64f99832 fix check for builtinness of 0 and 1 -- these aren't functions
blanchet
parents: 40686
diff changeset
    72
  (@{const_name zero_class.zero}, is_arithT),
a68f64f99832 fix check for builtinness of 0 and 1 -- these aren't functions
blanchet
parents: 40686
diff changeset
    73
  (@{const_name one_class.one}, is_arithT),
40277
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    74
  (@{const_name Int.Pls}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    75
  (@{const_name Int.Min}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    76
  (@{const_name Int.Bit0}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    77
  (@{const_name Int.Bit1}, K true),
40677
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    78
  (@{const_name number_of}, is_arithT_ran),
40277
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    79
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    80
  (* arithmetic *)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    81
  (@{const_name nat}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    82
  (@{const_name of_nat}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    83
  (@{const_name Suc}, K true),
40677
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    84
  (@{const_name plus}, is_arithT_dom),
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    85
  (@{const_name uminus}, is_arithT_dom),
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    86
  (@{const_name minus}, is_arithT_dom),
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    87
  (@{const_name abs}, is_arithT_dom),
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    88
  (@{const_name min}, is_arithT_dom),
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    89
  (@{const_name max}, is_arithT_dom),
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    90
  (@{const_name less}, is_arithT_dom),
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
    91
  (@{const_name less_eq}, is_arithT_dom),
40277
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    92
  
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    93
  (* pairs *)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    94
  (@{const_name fst}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    95
  (@{const_name snd}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    96
  (@{const_name Pair}, K true)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    97
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    98
  ]
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    99
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   100
val all_builtins =
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   101
  builtins
40677
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
   102
  |> Symtab.update (@{const_name times}, is_arithT_dom)
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
   103
  |> Symtab.update (@{const_name div_class.div}, is_arithT_dom)
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
   104
  |> Symtab.update (@{const_name div_class.mod}, is_arithT_dom)
f5caf58e9cdb more precise characterization of built-in constants "number_of", "0", and "1"
blanchet
parents: 40664
diff changeset
   105
  |> Symtab.update ("Rings.inverse_class.divide", is_arithT_dom)
40277
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   106
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   107
fun lookup_builtin bs (name, T) =
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   108
  (case Symtab.lookup bs name of
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   109
    SOME proper_type => proper_type T
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   110
  | NONE => false)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   111
40686
4725ed462387 swap names for built-in tester functions (to better reflect the intuition of what they do);
boehmes
parents: 40681
diff changeset
   112
fun is_builtin _ = lookup_builtin builtins
40277
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   113
40686
4725ed462387 swap names for built-in tester functions (to better reflect the intuition of what they do);
boehmes
parents: 40681
diff changeset
   114
fun is_partially_builtin _ = lookup_builtin all_builtins
40277
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   115
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   116
end