3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-12 12:08:18 +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 6417f9e648
commit 13416de27e
4 changed files with 96 additions and 102 deletions

View file

@ -162,70 +162,68 @@ 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 _ =
if not (Log.open_ "z3.log") then try (
raise (TestFailedException "Log couldn't be opened.") if not (Log.open_ "z3.log") then
else raise (TestFailedException "Log couldn't be opened.")
( else
Printf.printf "Running Z3 version %s\n" Version.to_string ; (
let cfg = [("model", "true"); ("proof", "false")] in Printf.printf "Running Z3 version %s\n" Version.to_string ;
let ctx = (mk_context cfg) in let cfg = [("model", "true"); ("proof", "false")] in
let is = (Symbol.mk_int ctx 42) in let ctx = (mk_context cfg) in
let ss = (Symbol.mk_string ctx "mySymbol") in let is = (Symbol.mk_int ctx 42) in
let bs = (Boolean.mk_sort ctx) in let ss = (Symbol.mk_string ctx "mySymbol") in
let ints = (Integer.mk_sort ctx) in let bs = (Boolean.mk_sort ctx) in
let rs = (Real.mk_sort ctx) in let ints = (Integer.mk_sort ctx) in
Printf.printf "int symbol: %s\n" (Symbol.to_string is); let rs = (Real.mk_sort ctx) in
Printf.printf "string symbol: %s\n" (Symbol.to_string ss); Printf.printf "int symbol: %s\n" (Symbol.to_string is);
Printf.printf "bool sort: %s\n" (Sort.to_string bs); Printf.printf "string symbol: %s\n" (Symbol.to_string ss);
Printf.printf "int sort: %s\n" (Sort.to_string ints); Printf.printf "bool sort: %s\n" (Sort.to_string bs);
Printf.printf "real sort: %s\n" (Sort.to_string rs); Printf.printf "int sort: %s\n" (Sort.to_string ints);
basic_tests ctx ; Printf.printf "real sort: %s\n" (Sort.to_string rs);
Printf.printf "Disposing...\n"; basic_tests ctx ;
Gc.full_major () Printf.printf "Disposing...\n";
); 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
@ -21,7 +20,6 @@ type z3_native_object = {
mutable m_n_obj : Z3native.ptr ; mutable m_n_obj : Z3native.ptr ;
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 =
@ -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

@ -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