src/HOL/Library/Tools/smt_word.ML
author wenzelm
Sun, 04 Aug 2024 17:39:47 +0200
changeset 80636 4041e7c8059d
parent 76183 8089593a364a
permissions -rw-r--r--
tuned: more explicit dest_Const_name and dest_Const_type;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
76183
8089593a364a proper file headers;
wenzelm
parents: 74817
diff changeset
     1
(*  Title:      HOL/Library/Tools/smt_word.ML
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
     2
    Author:     Sascha Boehme, TU Muenchen
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
     3
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
     4
SMT setup for words.
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
     5
*)
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
     6
72508
c89d8e8bd8c7 factored out theory Traditional_Syntax
haftmann
parents: 72489
diff changeset
     7
signature SMT_WORD =
c89d8e8bd8c7 factored out theory Traditional_Syntax
haftmann
parents: 72489
diff changeset
     8
sig
c89d8e8bd8c7 factored out theory Traditional_Syntax
haftmann
parents: 72489
diff changeset
     9
  val add_word_shift': term * string -> Context.generic -> Context.generic
c89d8e8bd8c7 factored out theory Traditional_Syntax
haftmann
parents: 72489
diff changeset
    10
end
c89d8e8bd8c7 factored out theory Traditional_Syntax
haftmann
parents: 72489
diff changeset
    11
c89d8e8bd8c7 factored out theory Traditional_Syntax
haftmann
parents: 72489
diff changeset
    12
structure SMT_Word : SMT_WORD =
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    13
struct
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    14
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    15
open Word_Lib
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    16
57229
blanchet
parents: 56078
diff changeset
    17
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    18
(* SMT-LIB logic *)
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    19
57696
fb71c6f100f8 do not embed 'nat' into 'int's in 'smt2' method -- this is highly inefficient and decreases the Sledgehammer success rate significantly
blanchet
parents: 57553
diff changeset
    20
(* "QF_AUFBV" is too restrictive for Isabelle's problems, which contain aritmetic and quantifiers.
57553
2a6c31ac1c9a don't generate a 'set-logic' command when generating problems in a non-standard (but Z3-supported) union-of-everything logic
blanchet
parents: 57229
diff changeset
    21
   Better set the logic to "" and make at least Z3 happy. *)
74817
1fd8705503b4 generate problems with correct logic for veriT
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 74097
diff changeset
    22
fun smtlib_logic "z3" ts =
1fd8705503b4 generate problems with correct logic for veriT
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 74097
diff changeset
    23
    if exists (Term.exists_type (Term.exists_subtype is_wordT)) ts then SOME "" else NONE
1fd8705503b4 generate problems with correct logic for veriT
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 74097
diff changeset
    24
  | smtlib_logic "verit" _ = NONE
1fd8705503b4 generate problems with correct logic for veriT
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 74097
diff changeset
    25
  | smtlib_logic _ ts =
1fd8705503b4 generate problems with correct logic for veriT
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 74097
diff changeset
    26
    if exists (Term.exists_type (Term.exists_subtype is_wordT)) ts then SOME "AUFBVLIRA" else NONE
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    27
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    28
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    29
(* SMT-LIB builtins *)
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    30
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    31
local
74817
1fd8705503b4 generate problems with correct logic for veriT
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 74097
diff changeset
    32
  val smtlibC = SMTLIB_Interface.smtlibC @ SMTLIB_Interface.bvsmlibC
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    33
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 66551
diff changeset
    34
  val wordT = \<^typ>\<open>'a::len word\<close>
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    35
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    36
  fun index1 s i = "(_ " ^ s ^ " " ^ string_of_int i ^ ")"
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    37
  fun index2 s i j = "(_ " ^ s ^ " " ^ string_of_int i ^ " " ^ string_of_int j ^ ")"
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    38
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 66551
diff changeset
    39
  fun word_typ (Type (\<^type_name>\<open>word\<close>, [T])) =
66551
4df6b0ae900d towards support for HO SMT-LIB
blanchet
parents: 65336
diff changeset
    40
      Option.map (rpair [] o index1 "BitVec") (try dest_binT T)
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    41
    | word_typ _ = NONE
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    42
72909
f9424ceea3c3 don't generate not-fully-defined bit-vector constants in SMT problems
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 72515
diff changeset
    43
  (*CVC4 does not support "_bvk T" when k does not fit in the BV of size T, so remove the bits that
f9424ceea3c3 don't generate not-fully-defined bit-vector constants in SMT problems
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 72515
diff changeset
    44
   will be ignored according to the SMT-LIB*)
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 66551
diff changeset
    45
  fun word_num (Type (\<^type_name>\<open>word\<close>, [T])) k =
72909
f9424ceea3c3 don't generate not-fully-defined bit-vector constants in SMT problems
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 72515
diff changeset
    46
        let
f9424ceea3c3 don't generate not-fully-defined bit-vector constants in SMT problems
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 72515
diff changeset
    47
          val size = try dest_binT T
73021
f602a380e4f2 tuned signature -- prefer Isabelle/ML structure Integer (despite minor confusion due to canonical argument order of "pow");
wenzelm
parents: 72909
diff changeset
    48
          fun max_int size = Integer.pow size 2
72909
f9424ceea3c3 don't generate not-fully-defined bit-vector constants in SMT problems
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 72515
diff changeset
    49
        in
f9424ceea3c3 don't generate not-fully-defined bit-vector constants in SMT problems
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 72515
diff changeset
    50
          (case size of
f9424ceea3c3 don't generate not-fully-defined bit-vector constants in SMT problems
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 72515
diff changeset
    51
            NONE => NONE
f9424ceea3c3 don't generate not-fully-defined bit-vector constants in SMT problems
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 72515
diff changeset
    52
          | SOME size => SOME (index1 ("bv" ^ string_of_int (Int.rem(k, max_int size))) size))
f9424ceea3c3 don't generate not-fully-defined bit-vector constants in SMT problems
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 72515
diff changeset
    53
        end
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    54
    | word_num _ _ = NONE
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    55
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    56
  fun if_fixed pred m n T ts =
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    57
    let val (Us, U) = Term.strip_type T
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    58
    in
57696
fb71c6f100f8 do not embed 'nat' into 'int's in 'smt2' method -- this is highly inefficient and decreases the Sledgehammer success rate significantly
blanchet
parents: 57553
diff changeset
    59
      if pred (U, Us) then SOME (n, length Us, ts, Term.list_comb o pair (Const (m, T))) else NONE
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    60
    end
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    61
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    62
  fun if_fixed_all m = if_fixed (forall (can dest_wordT) o (op ::)) m
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    63
  fun if_fixed_args m = if_fixed (forall (can dest_wordT) o snd) m
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    64
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    65
  fun add_word_fun f (t, n) =
80636
4041e7c8059d tuned: more explicit dest_Const_name and dest_Const_type;
wenzelm
parents: 76183
diff changeset
    66
    let val m = dest_Const_name t
58061
3d060f43accb renamed new SMT module from 'SMT2' to 'SMT'
blanchet
parents: 57696
diff changeset
    67
    in SMT_Builtin.add_builtin_fun smtlibC (Term.dest_Const t, K (f m n)) end
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    68
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 66551
diff changeset
    69
  val mk_nat = HOLogic.mk_number \<^typ>\<open>nat\<close>
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    70
72514
d8661799afb2 removed dependency
haftmann
parents: 72508
diff changeset
    71
  fun mk_shift c [u, t] = Const c $ mk_nat (snd (HOLogic.dest_number u)) $ t
d8661799afb2 removed dependency
haftmann
parents: 72508
diff changeset
    72
    | mk_shift c ts = raise TERM ("bad arguments", Const c :: ts)
d8661799afb2 removed dependency
haftmann
parents: 72508
diff changeset
    73
d8661799afb2 removed dependency
haftmann
parents: 72508
diff changeset
    74
  fun shift m n T ts =
d8661799afb2 removed dependency
haftmann
parents: 72508
diff changeset
    75
    let val U = Term.domain_type (Term.range_type T)
d8661799afb2 removed dependency
haftmann
parents: 72508
diff changeset
    76
    in
d8661799afb2 removed dependency
haftmann
parents: 72508
diff changeset
    77
      (case (can dest_wordT U, try (snd o HOLogic.dest_number o hd) ts) of
d8661799afb2 removed dependency
haftmann
parents: 72508
diff changeset
    78
        (true, SOME i) =>
d8661799afb2 removed dependency
haftmann
parents: 72508
diff changeset
    79
          SOME (n, 2, [hd (tl ts), HOLogic.mk_number U i], mk_shift (m, T))
d8661799afb2 removed dependency
haftmann
parents: 72508
diff changeset
    80
      | _ => NONE)   (* FIXME: also support non-numerical shifts *)
d8661799afb2 removed dependency
haftmann
parents: 72508
diff changeset
    81
    end
d8661799afb2 removed dependency
haftmann
parents: 72508
diff changeset
    82
72489
a1366ce41368 early and more complete setup of tools
haftmann
parents: 71826
diff changeset
    83
  fun mk_shift' c [t, u] = Const c $ t $ mk_nat (snd (HOLogic.dest_number u))
a1366ce41368 early and more complete setup of tools
haftmann
parents: 71826
diff changeset
    84
    | mk_shift' c ts = raise TERM ("bad arguments", Const c :: ts)
a1366ce41368 early and more complete setup of tools
haftmann
parents: 71826
diff changeset
    85
a1366ce41368 early and more complete setup of tools
haftmann
parents: 71826
diff changeset
    86
  fun shift' m n T ts =
a1366ce41368 early and more complete setup of tools
haftmann
parents: 71826
diff changeset
    87
    let val U = Term.domain_type T
a1366ce41368 early and more complete setup of tools
haftmann
parents: 71826
diff changeset
    88
    in
a1366ce41368 early and more complete setup of tools
haftmann
parents: 71826
diff changeset
    89
      (case (can dest_wordT U, try (snd o HOLogic.dest_number o hd o tl) ts) of
a1366ce41368 early and more complete setup of tools
haftmann
parents: 71826
diff changeset
    90
        (true, SOME i) =>
a1366ce41368 early and more complete setup of tools
haftmann
parents: 71826
diff changeset
    91
          SOME (n, 2, [hd ts, HOLogic.mk_number U i], mk_shift' (m, T))
a1366ce41368 early and more complete setup of tools
haftmann
parents: 71826
diff changeset
    92
      | _ => NONE)   (* FIXME: also support non-numerical shifts *)
a1366ce41368 early and more complete setup of tools
haftmann
parents: 71826
diff changeset
    93
    end
a1366ce41368 early and more complete setup of tools
haftmann
parents: 71826
diff changeset
    94
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    95
  fun mk_extract c i ts = Term.list_comb (Const c, mk_nat i :: ts)
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    96
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    97
  fun extract m n T ts =
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    98
    let val U = Term.range_type (Term.range_type T)
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
    99
    in
57696
fb71c6f100f8 do not embed 'nat' into 'int's in 'smt2' method -- this is highly inefficient and decreases the Sledgehammer success rate significantly
blanchet
parents: 57553
diff changeset
   100
      (case (try (snd o HOLogic.dest_number o hd) ts, try dest_wordT U) of
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   101
        (SOME lb, SOME i) =>
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   102
          SOME (index2 n (i + lb - 1) lb, 1, tl ts, mk_extract (m, T) lb)
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   103
      | _ => NONE)
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   104
    end
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   105
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   106
  fun mk_extend c ts = Term.list_comb (Const c, ts)
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   107
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   108
  fun extend m n T ts =
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   109
    let val (U1, U2) = Term.dest_funT T
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   110
    in
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   111
      (case (try dest_wordT U1, try dest_wordT U2) of
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   112
        (SOME i, SOME j) =>
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   113
          if j-i >= 0 then SOME (index1 n (j-i), 1, ts, mk_extend (m, T))
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   114
          else NONE
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   115
      | _ => NONE)
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   116
    end
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   117
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   118
  fun mk_rotate c i ts = Term.list_comb (Const c, mk_nat i :: ts)
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   119
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   120
  fun rotate m n T ts =
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   121
    let val U = Term.domain_type (Term.range_type T)
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   122
    in
57696
fb71c6f100f8 do not embed 'nat' into 'int's in 'smt2' method -- this is highly inefficient and decreases the Sledgehammer success rate significantly
blanchet
parents: 57553
diff changeset
   123
      (case (can dest_wordT U, try (snd o HOLogic.dest_number o hd) ts) of
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   124
        (true, SOME i) => SOME (index1 n i, 1, tl ts, mk_rotate (m, T) i)
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   125
      | _ => NONE)
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   126
    end
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   127
in
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   128
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   129
val setup_builtins =
58061
3d060f43accb renamed new SMT module from 'SMT2' to 'SMT'
blanchet
parents: 57696
diff changeset
   130
  SMT_Builtin.add_builtin_typ smtlibC (wordT, word_typ, word_num) #>
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   131
  fold (add_word_fun if_fixed_all) [
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 66551
diff changeset
   132
    (\<^term>\<open>uminus :: 'a::len word \<Rightarrow> _\<close>, "bvneg"),
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 66551
diff changeset
   133
    (\<^term>\<open>plus :: 'a::len word \<Rightarrow> _\<close>, "bvadd"),
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 66551
diff changeset
   134
    (\<^term>\<open>minus :: 'a::len word \<Rightarrow> _\<close>, "bvsub"),
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 66551
diff changeset
   135
    (\<^term>\<open>times :: 'a::len word \<Rightarrow> _\<close>, "bvmul"),
74097
6d7be1227d02 organize syntax for word operations in bundles
haftmann
parents: 73021
diff changeset
   136
    (\<^term>\<open>not :: 'a::len word \<Rightarrow> _\<close>, "bvnot"),
6d7be1227d02 organize syntax for word operations in bundles
haftmann
parents: 73021
diff changeset
   137
    (\<^term>\<open>and :: 'a::len word \<Rightarrow> _\<close>, "bvand"),
6d7be1227d02 organize syntax for word operations in bundles
haftmann
parents: 73021
diff changeset
   138
    (\<^term>\<open>or :: 'a::len word \<Rightarrow> _\<close>, "bvor"),
6d7be1227d02 organize syntax for word operations in bundles
haftmann
parents: 73021
diff changeset
   139
    (\<^term>\<open>xor :: 'a::len word \<Rightarrow> _\<close>, "bvxor"),
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 66551
diff changeset
   140
    (\<^term>\<open>word_cat :: 'a::len word \<Rightarrow> _\<close>, "concat") ] #>
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   141
  fold (add_word_fun shift) [
72489
a1366ce41368 early and more complete setup of tools
haftmann
parents: 71826
diff changeset
   142
    (\<^term>\<open>push_bit :: nat \<Rightarrow> 'a::len word \<Rightarrow> _ \<close>, "bvshl"),
a1366ce41368 early and more complete setup of tools
haftmann
parents: 71826
diff changeset
   143
    (\<^term>\<open>drop_bit :: nat \<Rightarrow> 'a::len word \<Rightarrow> _\<close>, "bvlshr"),
a1366ce41368 early and more complete setup of tools
haftmann
parents: 71826
diff changeset
   144
    (\<^term>\<open>signed_drop_bit :: nat \<Rightarrow> 'a::len word \<Rightarrow> _\<close>, "bvashr") ] #>
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   145
  add_word_fun extract
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 66551
diff changeset
   146
    (\<^term>\<open>slice :: _ \<Rightarrow> 'a::len word \<Rightarrow> _\<close>, "extract") #>
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   147
  fold (add_word_fun extend) [
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 66551
diff changeset
   148
    (\<^term>\<open>ucast :: 'a::len word \<Rightarrow> _\<close>, "zero_extend"),
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 66551
diff changeset
   149
    (\<^term>\<open>scast :: 'a::len word \<Rightarrow> _\<close>, "sign_extend") ] #>
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   150
  fold (add_word_fun rotate) [
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 66551
diff changeset
   151
    (\<^term>\<open>word_rotl\<close>, "rotate_left"),
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 66551
diff changeset
   152
    (\<^term>\<open>word_rotr\<close>, "rotate_right") ] #>
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   153
  fold (add_word_fun if_fixed_args) [
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 66551
diff changeset
   154
    (\<^term>\<open>less :: 'a::len word \<Rightarrow> _\<close>, "bvult"),
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 66551
diff changeset
   155
    (\<^term>\<open>less_eq :: 'a::len word \<Rightarrow> _\<close>, "bvule"),
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 66551
diff changeset
   156
    (\<^term>\<open>word_sless\<close>, "bvslt"),
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 66551
diff changeset
   157
    (\<^term>\<open>word_sle\<close>, "bvsle") ]
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   158
72508
c89d8e8bd8c7 factored out theory Traditional_Syntax
haftmann
parents: 72489
diff changeset
   159
val add_word_shift' = add_word_fun shift'
c89d8e8bd8c7 factored out theory Traditional_Syntax
haftmann
parents: 72489
diff changeset
   160
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   161
end
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   162
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   163
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   164
(* setup *)
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   165
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   166
val _ = Theory.setup (Context.theory_map (
58061
3d060f43accb renamed new SMT module from 'SMT2' to 'SMT'
blanchet
parents: 57696
diff changeset
   167
  SMTLIB_Interface.add_logic (20, smtlib_logic) #>
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   168
  setup_builtins))
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff changeset
   169
57229
blanchet
parents: 56078
diff changeset
   170
end;