3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-05-02 13:27:01 +00:00

Add accessors for RCF numeral internals (#7013)

This commit is contained in:
Christoph M. Wintersteiger 2023-11-23 16:54:23 +00:00 committed by GitHub
parent 9382b96a32
commit 16753e43f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 845 additions and 117 deletions

View file

@ -2080,6 +2080,7 @@ struct
type rcf_num = Z3native.rcf_num
let del (ctx:context) (a:rcf_num) = Z3native.rcf_del ctx a
let del_list (ctx:context) (ns:rcf_num list) = List.iter (fun a -> Z3native.rcf_del ctx a) ns
let mk_rational (ctx:context) (v:string) = Z3native.rcf_mk_rational ctx v
let mk_small_int (ctx:context) (v:int) = Z3native.rcf_mk_small_int ctx v
@ -2087,7 +2088,9 @@ struct
let mk_e (ctx:context) = Z3native.rcf_mk_e ctx
let mk_infinitesimal (ctx:context) = Z3native.rcf_mk_infinitesimal ctx
let mk_roots (ctx:context) (n:int) (a:rcf_num list) = let n, r = Z3native.rcf_mk_roots ctx n a in r
let mk_roots (ctx:context) (a:rcf_num list) =
let n, r = Z3native.rcf_mk_roots ctx (List.length a) a in
List.init n (fun x -> List.nth r x)
let add (ctx:context) (a:rcf_num) (b:rcf_num) = Z3native.rcf_add ctx a b
let sub (ctx:context) (a:rcf_num) (b:rcf_num) = Z3native.rcf_sub ctx a b
@ -2109,6 +2112,83 @@ struct
let num_to_string (ctx:context) (a:rcf_num) (compact:bool) (html:bool) = Z3native.rcf_num_to_string ctx a compact html
let num_to_decimal_string (ctx:context) (a:rcf_num) (prec:int) = Z3native.rcf_num_to_decimal_string ctx a prec
let get_numerator_denominator (ctx:context) (a:rcf_num) = Z3native.rcf_get_numerator_denominator ctx a
let is_rational (ctx:context) (a:rcf_num) = Z3native.rcf_is_rational ctx a
let is_algebraic (ctx:context) (a:rcf_num) = Z3native.rcf_is_algebraic ctx a
let is_infinitesimal (ctx:context) (a:rcf_num) = Z3native.rcf_is_infinitesimal ctx a
let is_transcendental (ctx:context) (a:rcf_num) = Z3native.rcf_is_transcendental ctx a
let extension_index (ctx:context) (a:rcf_num) = Z3native.rcf_extension_index ctx a
let transcendental_name (ctx:context) (a:rcf_num) = Z3native.rcf_transcendental_name ctx a
let infinitesimal_name (ctx:context) (a:rcf_num) = Z3native.rcf_infinitesimal_name ctx a
let num_coefficients (ctx:context) (a:rcf_num) = Z3native.rcf_num_coefficients ctx a
let get_coefficient (ctx:context) (a:rcf_num) (i:int) = Z3native.rcf_coefficient ctx a i
let coefficients (ctx:context) (a:rcf_num) =
List.init (num_coefficients ctx a) (fun i -> Z3native.rcf_coefficient ctx a i)
type interval = {
lower_is_inf : bool;
lower_is_open : bool;
lower : rcf_num;
upper_is_inf : bool;
upper_is_open : bool;
upper : rcf_num;
}
let root_interval (ctx:context) (a:rcf_num) =
let ok, linf, lopen, l, uinf, uopen, u = Z3native.rcf_interval ctx a in
let i:interval = {
lower_is_inf = linf != 0;
lower_is_open = lopen != 0;
lower = l;
upper_is_inf = uinf != 0;
upper_is_open = uopen != 0;
upper = u } in
if ok != 0 then Some i else None
let sign_condition_sign (ctx:context) (a:rcf_num) (i:int) = Z3native.rcf_sign_condition_sign ctx a i
let sign_condition_coefficient (ctx:context) (a:rcf_num) (i:int) (j:int) = Z3native.rcf_sign_condition_coefficient ctx a i j
let num_sign_condition_coefficients (ctx:context) (a:rcf_num) (i:int) = Z3native.rcf_num_sign_condition_coefficients ctx a i
let sign_condition_coefficients (ctx:context) (a:rcf_num) (i:int) =
let n = Z3native.rcf_num_sign_condition_coefficients ctx a i in
List.init n (fun j -> Z3native.rcf_sign_condition_coefficient ctx a i j)
let sign_conditions (ctx:context) (a:rcf_num) =
let n = Z3native.rcf_num_sign_conditions ctx a in
List.init n (fun i ->
(let nc = Z3native.rcf_num_sign_condition_coefficients ctx a i in
List.init nc (fun j -> Z3native.rcf_sign_condition_coefficient ctx a i j)),
Z3native.rcf_sign_condition_sign ctx a i)
type root = {
obj : rcf_num;
polynomial : rcf_num list;
interval : interval option;
sign_conditions : (rcf_num list * int) list;
}
let roots (ctx:context) (a:rcf_num list) =
let rs = mk_roots ctx a in
List.map
(fun r -> {
obj = r;
polynomial = coefficients ctx r;
interval = root_interval ctx r;
sign_conditions = sign_conditions ctx r})
rs
let del_root (ctx:context) (r:root) =
del ctx r.obj;
List.iter (fun n -> del ctx n) r.polynomial;
List.iter (fun (ns, _) -> del_list ctx ns) r.sign_conditions
let del_roots (ctx:context) (rs:root list) =
List.iter (fun r -> del_root ctx r) rs
end

View file

@ -3553,77 +3553,147 @@ end
(** Real closed field *)
module RCF :
sig
type rcf_num
type rcf_num
(** Delete a RCF numeral created using the RCF API. *)
val del : context -> rcf_num -> unit
(** Delete a RCF numeral created using the RCF API. *)
val del : context -> rcf_num -> unit
(** Return a RCF rational using the given string. *)
val mk_rational : context -> string -> rcf_num
(** Delete RCF numerals created using the RCF API. *)
val del_list : context -> rcf_num list -> unit
(** Return a RCF small integer. *)
val mk_small_int : context -> int -> rcf_num
(** Return a RCF rational using the given string. *)
val mk_rational : context -> string -> rcf_num
(** Return Pi *)
val mk_pi : context -> rcf_num
(** Return a RCF small integer. *)
val mk_small_int : context -> int -> rcf_num
(** Return e (Euler's constant) *)
val mk_e : context -> rcf_num
(** Return Pi *)
val mk_pi : context -> rcf_num
(** Return a new infinitesimal that is smaller than all elements in the Z3 field. *)
val mk_infinitesimal : context -> rcf_num
(** Return e (Euler's constant) *)
val mk_e : context -> rcf_num
(** Extract the roots of a polynomial. Precondition: The input polynomial is not the zero polynomial. *)
val mk_roots : context -> int -> rcf_num list -> rcf_num list
(** Return a new infinitesimal that is smaller than all elements in the Z3 field. *)
val mk_infinitesimal : context -> rcf_num
(** Addition *)
val add : context -> rcf_num -> rcf_num -> rcf_num
(** Extract the roots of a polynomial. Precondition: The input polynomial is not the zero polynomial. *)
val mk_roots : context -> rcf_num list -> rcf_num list
(** Subtraction *)
val sub : context -> rcf_num -> rcf_num -> rcf_num
(** Addition *)
val add : context -> rcf_num -> rcf_num -> rcf_num
(** Multiplication *)
val mul : context -> rcf_num -> rcf_num -> rcf_num
(** Subtraction *)
val sub : context -> rcf_num -> rcf_num -> rcf_num
(** Division *)
val div : context -> rcf_num -> rcf_num -> rcf_num
(** Multiplication *)
val mul : context -> rcf_num -> rcf_num -> rcf_num
(** Negation *)
val neg : context -> rcf_num -> rcf_num
(** Division *)
val div : context -> rcf_num -> rcf_num -> rcf_num
(** Multiplicative Inverse *)
val inv : context -> rcf_num -> rcf_num
(** Negation *)
val neg : context -> rcf_num -> rcf_num
(** Power *)
val power : context -> rcf_num -> int -> rcf_num
(** Multiplicative Inverse *)
val inv : context -> rcf_num -> rcf_num
(** less-than *)
val lt : context -> rcf_num -> rcf_num -> bool
(** Power *)
val power : context -> rcf_num -> int -> rcf_num
(** greater-than *)
val gt : context -> rcf_num -> rcf_num -> bool
(** less-than *)
val lt : context -> rcf_num -> rcf_num -> bool
(** less-than or equal *)
val le : context -> rcf_num -> rcf_num -> bool
(** greater-than *)
val gt : context -> rcf_num -> rcf_num -> bool
(** greater-than or equal *)
val ge : context -> rcf_num -> rcf_num -> bool
(** less-than or equal *)
val le : context -> rcf_num -> rcf_num -> bool
(** equality *)
val eq : context -> rcf_num -> rcf_num -> bool
(** greater-than or equal *)
val ge : context -> rcf_num -> rcf_num -> bool
(** not equal *)
val neq : context -> rcf_num -> rcf_num -> bool
(** equality *)
val eq : context -> rcf_num -> rcf_num -> bool
(** Convert the RCF numeral into a string. *)
val num_to_string : context -> rcf_num -> bool -> bool -> string
(** not equal *)
val neq : context -> rcf_num -> rcf_num -> bool
(** Convert the RCF numeral into a string in decimal notation. *)
val num_to_decimal_string : context -> rcf_num -> int -> string
(** Convert the RCF numeral into a string. *)
val num_to_string : context -> rcf_num -> bool -> bool -> string
(** Extract the "numerator" and "denominator" of the given RCF numeral.
We have that \ccode{a = n/d}, moreover \c n and \c d are not represented using rational functions. *)
val get_numerator_denominator : context -> rcf_num -> (rcf_num * rcf_num)
(** Convert the RCF numeral into a string in decimal notation. *)
val num_to_decimal_string : context -> rcf_num -> int -> string
(** Extract the "numerator" and "denominator" of the given RCF numeral.
We have that \ccode{a = n/d}, moreover \c n and \c d are not represented using rational functions. *)
val get_numerator_denominator : context -> rcf_num -> (rcf_num * rcf_num)
(** Return \c true if \c a represents a rational number. *)
val is_rational : context -> rcf_num -> bool
(** Return \c true if \c a represents an algebraic number. *)
val is_algebraic : context -> rcf_num -> bool
(** Return \c true if \c a represents an infinitesimal. *)
val is_infinitesimal : context -> rcf_num -> bool
(** Return \c true if \c a represents a transcendental number. *)
val is_transcendental : context -> rcf_num -> bool
(** Return the index of a field extension. *)
val extension_index : context -> rcf_num -> int
(** Return the name of a transcendental. *)
val transcendental_name : context -> rcf_num -> Symbol.symbol
(** Return the name of an infinitesimal. *)
val infinitesimal_name : context -> rcf_num -> Symbol.symbol
(** Return the number of coefficients in an algebraic number. *)
val num_coefficients : context -> rcf_num -> int
(** Extract a coefficient from an algebraic number. *)
val get_coefficient : context -> rcf_num -> int -> rcf_num
(** Extract the coefficients from an algebraic number. *)
val coefficients : context -> rcf_num -> rcf_num list
(** Extract the sign of a sign condition from an algebraic number. *)
val sign_condition_sign : context -> rcf_num -> int -> int
(** Return the size of a sign condition polynomial. *)
val num_sign_condition_coefficients : context -> rcf_num -> int -> int
(** Extract a sign condition polynomial coefficient from an algebraic number. *)
val sign_condition_coefficient : context -> rcf_num -> int -> int -> rcf_num
(** Extract sign conditions from an algebraic number. *)
val sign_conditions : context -> rcf_num -> (rcf_num list * int) list
(** Extract the interval from an algebraic number. *)
type interval = {
lower_is_inf : bool;
lower_is_open : bool;
lower : rcf_num;
upper_is_inf : bool;
upper_is_open : bool;
upper : rcf_num;
}
val root_interval : context -> rcf_num -> interval option
type root = {
obj : rcf_num;
polynomial : rcf_num list;
interval : interval option;
sign_conditions : (rcf_num list * int) list;
}
val roots : context -> rcf_num list -> root list
val del_root : context -> root -> unit
val del_roots : context -> root list -> unit
end
(** Set a global (or module) parameter, which is shared by all Z3 contexts.