src/HOL/Tools/SMT/smt_builtin.ML
author boehmes
Mon, 22 Nov 2010 23:37:00 +0100
changeset 40664 e023788a91a1
parent 40277 4e3a3461c1a6
child 40677 f5caf58e9cdb
permissions -rw-r--r--
added support for quantifier weight annotations
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
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    12
  val is_partially_builtin: Proof.context -> string * typ -> bool
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    13
  val is_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
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    19
fun is_arithT (Type (@{type_name fun}, [T, _])) =
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    20
      (case T of
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    21
        @{typ int} => true
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    22
      | @{typ nat} => true
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    23
      | Type ("RealDef.real", []) => true
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    24
      | _ => false)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    25
  | is_arithT _ = false
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    26
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    27
val builtins = Symtab.make [
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    28
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    29
  (* Pure constants *)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    30
  (@{const_name all}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    31
  (@{const_name "=="}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    32
  (@{const_name "==>"}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    33
  (@{const_name Trueprop}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    34
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    35
  (* logical constants *)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    36
  (@{const_name All}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    37
  (@{const_name Ex}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    38
  (@{const_name Ball}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    39
  (@{const_name Bex}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    40
  (@{const_name Ex1}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    41
  (@{const_name True}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    42
  (@{const_name False}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    43
  (@{const_name Not}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    44
  (@{const_name HOL.conj}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    45
  (@{const_name HOL.disj}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    46
  (@{const_name HOL.implies}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    47
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    48
  (* term abbreviations *)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    49
  (@{const_name If}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    50
  (@{const_name bool.bool_case}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    51
  (@{const_name Let}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    52
  (@{const_name SMT.distinct}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    53
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    54
  (* technicalities *)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    55
  (@{const_name SMT.pat}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    56
  (@{const_name SMT.nopat}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    57
  (@{const_name SMT.trigger}, K true),
40664
e023788a91a1 added support for quantifier weight annotations
boehmes
parents: 40277
diff changeset
    58
  (@{const_name SMT.weight}, K true),
40277
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    59
  (@{const_name SMT.fun_app}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    60
  (@{const_name SMT.z3div}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    61
  (@{const_name SMT.z3mod}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    62
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    63
  (* equality *)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    64
  (@{const_name HOL.eq}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    65
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    66
  (* numerals *)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    67
  (@{const_name zero_class.zero}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    68
  (@{const_name one_class.one}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    69
  (@{const_name Int.Pls}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    70
  (@{const_name Int.Min}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    71
  (@{const_name Int.Bit0}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    72
  (@{const_name Int.Bit1}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    73
  (@{const_name number_of}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    74
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    75
  (* arithmetic *)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    76
  (@{const_name nat}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    77
  (@{const_name of_nat}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    78
  (@{const_name Suc}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    79
  (@{const_name plus}, is_arithT),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    80
  (@{const_name uminus}, is_arithT),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    81
  (@{const_name minus}, is_arithT),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    82
  (@{const_name abs}, is_arithT),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    83
  (@{const_name min}, is_arithT),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    84
  (@{const_name max}, is_arithT),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    85
  (@{const_name less}, is_arithT),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    86
  (@{const_name less_eq}, is_arithT),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    87
  
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    88
  (* pairs *)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    89
  (@{const_name fst}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    90
  (@{const_name snd}, K true),
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    91
  (@{const_name Pair}, K true)
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
  ]
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    94
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    95
val all_builtins =
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    96
  builtins
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    97
  |> Symtab.update (@{const_name times}, is_arithT)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    98
  |> Symtab.update (@{const_name div_class.div}, is_arithT)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
    99
  |> Symtab.update (@{const_name div_class.mod}, is_arithT)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   100
  |> Symtab.update ("Rings.inverse_class.divide", is_arithT)
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   101
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   102
fun lookup_builtin bs (name, T) =
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   103
  (case Symtab.lookup bs name of
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   104
    SOME proper_type => proper_type T
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   105
  | NONE => false)
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 is_partially_builtin _ = lookup_builtin builtins
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   108
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   109
fun is_builtin _ = lookup_builtin all_builtins
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   110
4e3a3461c1a6 added crafted list of SMT built-in constants
boehmes
parents:
diff changeset
   111
end