3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-13 12:28:44 +00:00

ML API savegame

Signed-off-by: Christoph M. Wintersteiger <cwinter@microsoft.com>
This commit is contained in:
Christoph M. Wintersteiger 2013-02-21 14:17:35 +00:00
parent d293b579f3
commit eea13a087f
5 changed files with 107 additions and 114 deletions

View file

@ -162,50 +162,43 @@ let basic_tests ( ctx : context ) =
else else
Printf.printf "Test passed.\n" Printf.printf "Test passed.\n"
) ; ) ;
model_converter_test ctx model_converter_test ctx ;
(* (* Real num/den test. *)
// Real num/den test. let rn = Real.mk_numeral_nd ctx 42 43 in
RatNum rn = ctx.MkReal(42, 43); let inum = (get_numerator rn) in
Expr inum = rn.Numerator; let iden = get_denominator rn in
Expr iden = rn.Denominator; Printf.printf "Numerator: %s Denominator: %s\n" (Real.to_string inum) (Real.to_string iden) ;
Console.WriteLine("Numerator: " + inum + " Denominator: " + iden); if ((Real.to_string inum) <> "42" or (Real.to_string iden) <> "43") then
if (inum.ToString() != "42" || iden.ToString() != "43") raise (TestFailedException "")
throw new TestFailedException(); else
Printf.printf "Test passed.\n"
if (rn.ToDecimalString(3) != "0.976?") ;
throw new TestFailedException(); if ((to_decimal_string rn 3) <> "0.976?") then
raise (TestFailedException "")
BigIntCheck(ctx, ctx.MkReal("-1231231232/234234333")); else
BigIntCheck(ctx, ctx.MkReal("-123123234234234234231232/234234333")); Printf.printf "Test passed.\n"
BigIntCheck(ctx, ctx.MkReal("-234234333")); ;
BigIntCheck(ctx, ctx.MkReal("234234333/2")); if (to_decimal_string (Real.mk_numeral_s ctx "-1231231232/234234333") 5 <> "-5.25640?") then
raise (TestFailedException "")
else if (to_decimal_string (Real.mk_numeral_s ctx "-123123234234234234231232/234234333") 5 <> "-525641278361333.28170?") then
string bn = "1234567890987654321"; raise (TestFailedException "")
else if (to_decimal_string (Real.mk_numeral_s ctx "-234234333") 5 <> "-234234333") then
if (ctx.MkInt(bn).BigInteger.ToString() != bn) raise (TestFailedException "")
throw new TestFailedException(); else if (to_decimal_string (Real.mk_numeral_s ctx "234234333/2") 5 <> "117117166.5") then
raise (TestFailedException "")
if (ctx.MkBV(bn, 128).BigInteger.ToString() != bn) ;
throw new TestFailedException(); (* Error handling test. *)
try (
if (ctx.MkBV(bn, 32).BigInteger.ToString() == bn) let i = Integer.mk_numeral_s ctx "1/2" in
throw new TestFailedException(); raise (TestFailedException "") (* unreachable *)
)
// Error handling test. with Z3native.Exception(_) -> (
try Printf.printf "Exception caught, OK.\n"
{ )
IntExpr i = ctx.MkInt("1/2");
throw new TestFailedException(); // unreachable
}
catch (Z3Exception)
{
}
}
*)
let _ = let _ =
try (
if not (Log.open_ "z3.log") then if not (Log.open_ "z3.log") then
raise (TestFailedException "Log couldn't be opened.") raise (TestFailedException "Log couldn't be opened.")
else else
@ -227,5 +220,10 @@ let _ =
Printf.printf "Disposing...\n"; Printf.printf "Disposing...\n";
Gc.full_major () Gc.full_major ()
); );
Printf.printf "Exiting.\n"; Printf.printf "Exiting.\n" ;
exit 0
) with Z3native.Exception(msg) -> (
Printf.printf "Z3 EXCEPTION: %s\n" msg ;
exit 1
)
;; ;;

View file

@ -11,7 +11,6 @@ open Z3enums
let null = Z3native.mk_null() let null = Z3native.mk_null()
let is_null o = (Z3native.is_null o) let is_null o = (Z3native.is_null o)
(* Internal types *) (* Internal types *)
type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; }
type context = z3_native_context type context = z3_native_context
@ -22,7 +21,6 @@ type z3_native_object = {
inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; inc_ref : Z3native.z3_context -> Z3native.ptr -> unit;
dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } dec_ref : Z3native.z3_context -> Z3native.ptr -> unit }
(** Internal stuff *) (** Internal stuff *)
module Internal = module Internal =
struct struct
@ -1455,11 +1453,11 @@ struct
let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x)
let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = let mk_const ( ctx : context ) ( name : Symbol.symbol ) =
Expr.mk_const ctx name (mk_sort ctx) Expr.mk_const ctx name (mk_sort ctx)
let mk_int_const_s ( ctx : context ) ( name : string ) = let mk_const_s ( ctx : context ) ( name : string ) =
mk_int_const ctx (Symbol.mk_string ctx name) mk_const ctx (Symbol.mk_string ctx name)
let mk_mod ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = let mk_mod ( ctx : context ) ( t1 : expr ) ( t2 : expr ) =
expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (Expr.gno t1) (Expr.gno t2))
@ -1467,10 +1465,10 @@ struct
let mk_rem ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = let mk_rem ( ctx : context ) ( t1 : expr ) ( t2 : expr ) =
expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (Expr.gno t1) (Expr.gno t2))
let mk_int_numeral_s ( ctx : context ) ( v : string ) = let mk_numeral_s ( ctx : context ) ( v : string ) =
expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno (mk_sort ctx))) expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno (mk_sort ctx)))
let mk_int_numeral_i ( ctx : context ) ( v : int ) = let mk_numeral_i ( ctx : context ) ( v : int ) =
expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno (mk_sort ctx))) expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno (mk_sort ctx)))
let mk_int2real ( ctx : context ) ( t : expr ) = let mk_int2real ( ctx : context ) ( t : expr ) =
@ -1496,11 +1494,11 @@ struct
let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x)
let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = let mk_const ( ctx : context ) ( name : Symbol.symbol ) =
Expr.mk_const ctx name (mk_sort ctx) Expr.mk_const ctx name (mk_sort ctx)
let mk_real_const_s ( ctx : context ) ( name : string ) = let mk_const_s ( ctx : context ) ( name : string ) =
mk_real_const ctx (Symbol.mk_string ctx name) mk_const ctx (Symbol.mk_string ctx name)
let mk_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = let mk_numeral_nd ( ctx : context ) ( num : int ) ( den : int) =
if (den == 0) then if (den == 0) then

View file

@ -30,7 +30,6 @@ type context
(** Create a context object *) (** Create a context object *)
val mk_context : (string * string) list -> context val mk_context : (string * string) list -> context
(** Interaction logging for Z3 (** Interaction logging for Z3
Note that this is a global, static log and if multiple Context Note that this is a global, static log and if multiple Context
objects are created, it logs the interaction with all of them. *) objects are created, it logs the interaction with all of them. *)
@ -1117,10 +1116,10 @@ sig
end end
(** Functions to manipulate arithmetic expressions *) (** Functions to manipulate arithmetic expressions *)
module rec Arithmetic : module Arithmetic :
sig sig
(** Integer Arithmetic *) (** Integer Arithmetic *)
module rec Integer : module Integer :
sig sig
(** Create a new integer sort. *) (** Create a new integer sort. *)
val mk_sort : context -> Sort.sort val mk_sort : context -> Sort.sort
@ -1132,10 +1131,10 @@ sig
val to_string : Expr.expr -> string val to_string : Expr.expr -> string
(** Creates an integer constant. *) (** Creates an integer constant. *)
val mk_int_const : context -> Symbol.symbol -> Expr.expr val mk_const : context -> Symbol.symbol -> Expr.expr
(** Creates an integer constant. *) (** Creates an integer constant. *)
val mk_int_const_s : context -> string -> Expr.expr val mk_const_s : context -> string -> Expr.expr
(** Create an expression representing <c>t1 mod t2</c>. (** Create an expression representing <c>t1 mod t2</c>.
The arguments must have int type. *) The arguments must have int type. *)
@ -1146,11 +1145,11 @@ sig
val mk_rem : context -> Expr.expr -> Expr.expr -> Expr.expr val mk_rem : context -> Expr.expr -> Expr.expr -> Expr.expr
(** Create an integer numeral. *) (** Create an integer numeral. *)
val mk_int_numeral_s : context -> string -> Expr.expr val mk_numeral_s : context -> string -> Expr.expr
(** Create an integer numeral. (** Create an integer numeral.
@return A Term with the given value and sort Integer *) @return A Term with the given value and sort Integer *)
val mk_int_numeral_i : context -> int -> Expr.expr val mk_numeral_i : context -> int -> Expr.expr
(** Coerce an integer to a real. (** Coerce an integer to a real.
@ -1174,7 +1173,7 @@ sig
end end
(** Real Arithmetic *) (** Real Arithmetic *)
and Real : module Real :
sig sig
(** Create a real sort. *) (** Create a real sort. *)
val mk_sort : context -> Sort.sort val mk_sort : context -> Sort.sort
@ -1193,10 +1192,10 @@ sig
val to_string : Expr.expr-> string val to_string : Expr.expr-> string
(** Creates a real constant. *) (** Creates a real constant. *)
val mk_real_const : context -> Symbol.symbol -> Expr.expr val mk_const : context -> Symbol.symbol -> Expr.expr
(** Creates a real constant. *) (** Creates a real constant. *)
val mk_real_const_s : context -> string -> Expr.expr val mk_const_s : context -> string -> Expr.expr
(** Create a real numeral from a fraction. (** Create a real numeral from a fraction.
@return A Term with rational value and sort Real @return A Term with rational value and sort Real
@ -1222,7 +1221,7 @@ sig
end end
(** Algebraic Numbers *) (** Algebraic Numbers *)
and AlgebraicNumber : module AlgebraicNumber :
sig sig
(** Return a upper bound for a given real algebraic number. (** Return a upper bound for a given real algebraic number.
The interval isolating the number is smaller than 1/10^precision. The interval isolating the number is smaller than 1/10^precision.
@ -1339,7 +1338,7 @@ sig
end end
(** Functions to manipulate bit-vector expressions *) (** Functions to manipulate bit-vector expressions *)
and BitVector : module BitVector :
sig sig
(** Create a new bit-vector sort. *) (** Create a new bit-vector sort. *)
val mk_sort : context -> int -> Sort.sort val mk_sort : context -> int -> Sort.sort

View file

@ -1,4 +1,4 @@
(** \(**
The Z3 ML/Ocaml Interface. The Z3 ML/Ocaml Interface.
Copyright (C) 2012 Microsoft Corporation Copyright (C) 2012 Microsoft Corporation
@ -11,7 +11,6 @@ open Z3enums
let null = Z3native.mk_null() let null = Z3native.mk_null()
let is_null o = (Z3native.is_null o) let is_null o = (Z3native.is_null o)
(* Internal types *) (* Internal types *)
type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; }
type context = z3_native_context type context = z3_native_context
@ -1679,12 +1678,12 @@ sig
val mk_sort : context -> int_sort val mk_sort : context -> int_sort
val get_int : int_num -> int val get_int : int_num -> int
val to_string : int_num -> string val to_string : int_num -> string
val mk_int_const : context -> Symbol.symbol -> int_expr val mk_const : context -> Symbol.symbol -> int_expr
val mk_int_const_s : context -> string -> int_expr val mk_const_s : context -> string -> int_expr
val mk_mod : context -> int_expr -> int_expr -> int_expr val mk_mod : context -> int_expr -> int_expr -> int_expr
val mk_rem : context -> int_expr -> int_expr -> int_expr val mk_rem : context -> int_expr -> int_expr -> int_expr
val mk_int_numeral_s : context -> string -> int_num val mk_numeral_s : context -> string -> int_num
val mk_int_numeral_i : context -> int -> int_num val mk_numeral_i : context -> int -> int_num
val mk_int2real : context -> int_expr -> Real.real_expr val mk_int2real : context -> int_expr -> Real.real_expr
val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr
end end
@ -1709,8 +1708,8 @@ sig
val get_denominator : rat_num -> Integer.int_num val get_denominator : rat_num -> Integer.int_num
val to_decimal_string : rat_num -> int -> string val to_decimal_string : rat_num -> int -> string
val to_string : rat_num -> string val to_string : rat_num -> string
val mk_real_const : context -> Symbol.symbol -> real_expr val mk_const : context -> Symbol.symbol -> real_expr
val mk_real_const_s : context -> string -> real_expr val mk_const_s : context -> string -> real_expr
val mk_numeral_nd : context -> int -> int -> rat_num val mk_numeral_nd : context -> int -> int -> rat_num
val mk_numeral_s : context -> string -> rat_num val mk_numeral_s : context -> string -> rat_num
val mk_numeral_i : context -> int -> rat_num val mk_numeral_i : context -> int -> rat_num
@ -1816,12 +1815,12 @@ end = struct
val mk_sort : context -> int_sort val mk_sort : context -> int_sort
val get_int : int_num -> int val get_int : int_num -> int
val to_string : int_num -> string val to_string : int_num -> string
val mk_int_const : context -> Symbol.symbol -> int_expr val mk_const : context -> Symbol.symbol -> int_expr
val mk_int_const_s : context -> string -> int_expr val mk_const_s : context -> string -> int_expr
val mk_mod : context -> int_expr -> int_expr -> int_expr val mk_mod : context -> int_expr -> int_expr -> int_expr
val mk_rem : context -> int_expr -> int_expr -> int_expr val mk_rem : context -> int_expr -> int_expr -> int_expr
val mk_int_numeral_s : context -> string -> int_num val mk_numeral_s : context -> string -> int_num
val mk_int_numeral_i : context -> int -> int_num val mk_numeral_i : context -> int -> int_num
val mk_int2real : context -> int_expr -> Real.real_expr val mk_int2real : context -> int_expr -> Real.real_expr
val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr
end = struct end = struct
@ -1884,11 +1883,11 @@ end = struct
let to_string ( x : int_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) let to_string ( x : int_num ) = Z3native.get_numeral_string (ngnc x) (ngno x)
let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = let mk_const ( ctx : context ) ( name : Symbol.symbol ) =
IntExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with IntSort(ArithSort(s)) -> s))) IntExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with IntSort(ArithSort(s)) -> s)))
let mk_int_const_s ( ctx : context ) ( name : string ) = let mk_const_s ( ctx : context ) ( name : string ) =
mk_int_const ctx (Symbol.mk_string ctx name) mk_const ctx (Symbol.mk_string ctx name)
let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) =
int_expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) int_expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2))
@ -1896,10 +1895,10 @@ end = struct
let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) =
int_expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) int_expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2))
let mk_int_numeral_s ( ctx : context ) ( v : string ) = let mk_numeral_s ( ctx : context ) ( v : string ) =
int_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) int_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx)))
let mk_int_numeral_i ( ctx : context ) ( v : int ) = let mk_numeral_i ( ctx : context ) ( v : int ) =
int_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) int_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx)))
let mk_int2real ( ctx : context ) ( t : int_expr ) = let mk_int2real ( ctx : context ) ( t : int_expr ) =
@ -1930,8 +1929,8 @@ end = struct
val get_denominator : rat_num -> Integer.int_num val get_denominator : rat_num -> Integer.int_num
val to_decimal_string : rat_num -> int -> string val to_decimal_string : rat_num -> int -> string
val to_string : rat_num -> string val to_string : rat_num -> string
val mk_real_const : context -> Symbol.symbol -> real_expr val mk_const : context -> Symbol.symbol -> real_expr
val mk_real_const_s : context -> string -> real_expr val mk_const_s : context -> string -> real_expr
val mk_numeral_nd : context -> int -> int -> rat_num val mk_numeral_nd : context -> int -> int -> rat_num
val mk_numeral_s : context -> string -> rat_num val mk_numeral_s : context -> string -> rat_num
val mk_numeral_i : context -> int -> rat_num val mk_numeral_i : context -> int -> rat_num
@ -2002,11 +2001,11 @@ end = struct
let to_string ( x : rat_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) let to_string ( x : rat_num ) = Z3native.get_numeral_string (ngnc x) (ngno x)
let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = let mk_const ( ctx : context ) ( name : Symbol.symbol ) =
RealExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with RealSort(ArithSort(s)) -> s))) RealExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with RealSort(ArithSort(s)) -> s)))
let mk_real_const_s ( ctx : context ) ( name : string ) = let mk_const_s ( ctx : context ) ( name : string ) =
mk_real_const ctx (Symbol.mk_string ctx name) mk_const ctx (Symbol.mk_string ctx name)
let mk_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = let mk_numeral_nd ( ctx : context ) ( num : int ) ( den : int) =
if (den == 0) then if (den == 0) then

View file

@ -34,7 +34,6 @@ type context
(** Create a context object *) (** Create a context object *)
val mk_context : (string * string) list -> context val mk_context : (string * string) list -> context
(** Interaction logging for Z3 (** Interaction logging for Z3
Note that this is a global, static log and if multiple Context Note that this is a global, static log and if multiple Context
objects are created, it logs the interaction with all of them. *) objects are created, it logs the interaction with all of them. *)
@ -1219,10 +1218,10 @@ sig
val to_string : int_num -> string val to_string : int_num -> string
(** Creates an integer constant. *) (** Creates an integer constant. *)
val mk_int_const : context -> Symbol.symbol -> int_expr val mk_const : context -> Symbol.symbol -> int_expr
(** Creates an integer constant. *) (** Creates an integer constant. *)
val mk_int_const_s : context -> string -> int_expr val mk_const_s : context -> string -> int_expr
(** Create an expression representing <c>t1 mod t2</c>. (** Create an expression representing <c>t1 mod t2</c>.
The arguments must have int type. *) The arguments must have int type. *)
@ -1233,11 +1232,11 @@ sig
val mk_rem : context -> int_expr -> int_expr -> int_expr val mk_rem : context -> int_expr -> int_expr -> int_expr
(** Create an integer numeral. *) (** Create an integer numeral. *)
val mk_int_numeral_s : context -> string -> int_num val mk_numeral_s : context -> string -> int_num
(** Create an integer numeral. (** Create an integer numeral.
@return A Term with the given value and sort Integer *) @return A Term with the given value and sort Integer *)
val mk_int_numeral_i : context -> int -> int_num val mk_numeral_i : context -> int -> int_num
(** Coerce an integer to a real. (** Coerce an integer to a real.
@ -1291,10 +1290,10 @@ sig
val to_string : rat_num -> string val to_string : rat_num -> string
(** Creates a real constant. *) (** Creates a real constant. *)
val mk_real_const : context -> Symbol.symbol -> real_expr val mk_const : context -> Symbol.symbol -> real_expr
(** Creates a real constant. *) (** Creates a real constant. *)
val mk_real_const_s : context -> string -> real_expr val mk_const_s : context -> string -> real_expr
(** Create a real numeral from a fraction. (** Create a real numeral from a fraction.
@return A Term with rational value and sort Real @return A Term with rational value and sort Real