apron-dist-0.9.10/0000750014525101416610000000000011252216654013550 5ustar bjeannetpopartapron-dist-0.9.10/README.windows0000640014525101416610000000221411251734233016116 0ustar bjeannetpopart This document tries to explain how to compile Apron under Windows. For the moment, only 32-bit compilation using the Cygwin environment is supported. Note that this is work-in-progress. PREREQUISITES ------------- Get Cygwin at http://www.cygwin.com/ The following Cygwin package are required: - gcc (Devel) - make (Devel) - gmp, mpfr (Math) - doxygen (Devel) - tetex-base (Publishing) Additionally, you'll need to install manually the following - OCaml 3.09 or better, from http://caml.inria.fr/ocaml/release.fr.html (the 3.08 version, in CygWin, at the time of writing is too old) - CamlIDL, from http://caml.inria.fr/pub/old_caml_site/camlidl/ CONFIGURATION ------------- Copy Makefile.config.model into Makefile.config and edit the _PREFIX paths to suit your installation (you might want to set APRON_PREFIX, CAMLIDL_PREFIX and CAML_PREFIX to /usr/local instead of the default /usr). The following options should be disabled: - HAS_CPP (Cygwin's gcc is too old) - HAS_PPL (Apron with PPL compilation untested under Windows) - HAS_LONG_DOUBLE (long double not supported by math library under Windows) Now, (make rebuild), make and make install. apron-dist-0.9.10/mlgmpidl/0000750014525101416610000000000011252216654015355 5ustar bjeannetpopartapron-dist-0.9.10/mlgmpidl/mpfr.ml0000640014525101416610000003274711252216514016664 0ustar bjeannetpopart(* File generated from mpfr.idl *) (* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t and round = | Near | Zero | Up | Down (** MPFR multiprecision floating-point numbers *) (** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x]. These functions are as efficient as their C counterpart: they do not imply additional memory allocation. *) (** {2 Rounding Modes} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Rounding-Related-Functions}C documentation} *) external set_default_rounding_mode : round -> unit = "camlidl_mpfr_mpfr_set_default_rounding_mode" external get_default_rounding_mode : unit -> round = "camlidl_mpfr_mpfr_get_default_rounding_mode" external round_prec : t -> round -> int -> int = "camlidl_mpfr_mpfr_round_prec" (** {2 Exceptions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Exception-Related-Functions}C documentation} *) external get_emin : unit -> int = "camlidl_mpfr_mpfr_get_emin" external get_emax : unit -> int = "camlidl_mpfr_mpfr_get_emax" external set_emin : int -> unit = "camlidl_mpfr_mpfr_set_emin" external set_emax : int -> unit = "camlidl_mpfr_mpfr_set_emax" external check_range : t -> int -> round -> int = "camlidl_mpfr_mpfr_check_range" external clear_underflow : unit -> unit = "camlidl_mpfr_mpfr_clear_underflow" external clear_overflow : unit -> unit = "camlidl_mpfr_mpfr_clear_overflow" external clear_nanflag : unit -> unit = "camlidl_mpfr_mpfr_clear_nanflag" external clear_inexflag : unit -> unit = "camlidl_mpfr_mpfr_clear_inexflag" external clear_flags : unit -> unit = "camlidl_mpfr_mpfr_clear_flags" external underflow_p : unit -> bool = "camlidl_mpfr_mpfr_underflow_p" external overflow_p : unit -> bool = "camlidl_mpfr_mpfr_overflow_p" external nanflag_p : unit -> bool = "camlidl_mpfr_mpfr_nanflag_p" external inexflag_p : unit -> bool = "camlidl_mpfr_mpfr_inexflag_p" (** {2 Initialization Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Initialization-Functions}C documentation} *) external set_default_prec : int -> unit = "camlidl_mpfr_mpfr_set_default_prec" external get_default_prec : unit -> int = "camlidl_mpfr_mpfr_get_default_prec" external init : unit -> t = "camlidl_mpfr_mpfr_init" external init2 : int -> t = "camlidl_mpfr_mpfr_init2" external get_prec : t -> int = "camlidl_mpfr_mpfr_get_prec" external set_prec : t -> int -> unit = "camlidl_mpfr_mpfr_set_prec" external set_prec_raw : t -> int -> unit = "camlidl_mpfr_mpfr_set_prec_raw" (** {2 Assignment Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Assignment-Functions}C documentation} *) external set : t -> t -> round -> int = "camlidl_mpfr_mpfr_set" external set_si : t -> int -> round -> int = "camlidl_mpfr_mpfr_set_si" external set_d : t -> float -> round -> int = "camlidl_mpfr_mpfr_set_d" external set_z : t -> Mpz.t -> round -> int = "camlidl_mpfr_mpfr_set_z" external set_q : t -> Mpq.t -> round -> int = "camlidl_mpfr_mpfr_set_q" external _set_str : t -> string -> int -> round -> unit = "camlidl_mpfr_mpfr__set_str" let set_str a b ~base round = _set_str a b base round external set_f : t -> Mpf.t -> round -> int = "camlidl_mpfr_mpfr_set_f" external set_si_2exp : t -> int -> int -> round -> int = "camlidl_mpfr_mpfr_set_si_2exp" external set_inf : t -> int -> unit = "camlidl_mpfr_mpfr_set_inf" external set_nan : t -> unit = "camlidl_mpfr_mpfr_set_nan" external swap : t -> t -> unit = "camlidl_mpfr_mpfr_swap" (** {2 Combined Initialization and Assignment Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Combined-Initialization-and-Assignment-Functions}C documentation} *) external init_set : t -> round -> int * t = "camlidl_mpfr_mpfr_init_set" external init_set_si : int -> round -> int * t = "camlidl_mpfr_mpfr_init_set_si" external init_set_d : float -> round -> int * t = "camlidl_mpfr_mpfr_init_set_d" external init_set_f : Mpf.t -> round -> int * t = "camlidl_mpfr_mpfr_init_set_f" external init_set_z : Mpz.t -> round -> int * t = "camlidl_mpfr_mpfr_init_set_z" external init_set_q : Mpq.t -> round -> int * t = "camlidl_mpfr_mpfr_init_set_q" external _init_set_str : string -> int -> round -> t = "camlidl_mpfr_mpfr__init_set_str" let init_set_str a ~base round = _init_set_str a base round (** {2 Conversion Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Conversion-Functions}C documentation} *) external get_d : t -> round -> float = "camlidl_mpfr_mpfr_get_d" external get_d1 : t -> float = "camlidl_mpfr_mpfr_get_d1" external get_z_exp : Mpz.t -> t -> int = "camlidl_mpfr_mpfr_get_z_exp" external get_z : Mpz.t -> t -> round -> unit = "camlidl_mpfr_mpfr_get_z" external _get_str : int -> int -> t -> round -> string * int = "camlidl_mpfr_mpfr__get_str" let get_str ~base ~digits a round = _get_str base digits a round (** {2 Basic Arithmetic Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Basic-Arithmetic-Functions}C documentation} *) external add : t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_add" external add_ui : t -> t -> int -> round -> int = "camlidl_mpfr_mpfr_add_ui" external add_z : t -> t -> Mpz.t -> round -> int = "camlidl_mpfr_mpfr_add_z" external add_q : t -> t -> Mpq.t -> round -> int = "camlidl_mpfr_mpfr_add_q" external sub : t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_sub" external ui_sub : t -> int -> t -> round -> int = "camlidl_mpfr_mpfr_ui_sub" external sub_ui : t -> t -> int -> round -> int = "camlidl_mpfr_mpfr_sub_ui" external sub_z : t -> t -> Mpz.t -> round -> int = "camlidl_mpfr_mpfr_sub_z" external sub_q : t -> t -> Mpq.t -> round -> int = "camlidl_mpfr_mpfr_sub_q" external mul : t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_mul" external mul_ui : t -> t -> int -> round -> int = "camlidl_mpfr_mpfr_mul_ui" external mul_z : t -> t -> Mpz.t -> round -> int = "camlidl_mpfr_mpfr_mul_z" external mul_q : t -> t -> Mpq.t -> round -> int = "camlidl_mpfr_mpfr_mul_q" external mul_2ui : t -> t -> int -> round -> int = "camlidl_mpfr_mpfr_mul_2ui" external mul_2si : t -> t -> int -> round -> int = "camlidl_mpfr_mpfr_mul_2si" external mul_2exp : t -> t -> int -> round -> int = "camlidl_mpfr_mpfr_mul_2exp" external div : t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_div" external ui_div : t -> int -> t -> round -> int = "camlidl_mpfr_mpfr_ui_div" external div_ui : t -> t -> int -> round -> int = "camlidl_mpfr_mpfr_div_ui" external div_z : t -> t -> Mpz.t -> round -> int = "camlidl_mpfr_mpfr_div_z" external div_q : t -> t -> Mpq.t -> round -> int = "camlidl_mpfr_mpfr_div_q" external div_2ui : t -> t -> int -> round -> int = "camlidl_mpfr_mpfr_div_2ui" external div_2si : t -> t -> int -> round -> int = "camlidl_mpfr_mpfr_div_2si" let div_2exp = div_2ui external sqrt : t -> t -> round -> bool = "camlidl_mpfr_mpfr_sqrt" external sqrt_ui : t -> int -> round -> bool = "camlidl_mpfr_mpfr_sqrt_ui" external pow_ui : t -> t -> int -> round -> bool = "camlidl_mpfr_mpfr_pow_ui" external pow_si : t -> t -> int -> round -> bool = "camlidl_mpfr_mpfr_pow_si" external ui_pow_ui : t -> int -> int -> round -> bool = "camlidl_mpfr_mpfr_ui_pow_ui" external ui_pow : t -> int -> t -> round -> bool = "camlidl_mpfr_mpfr_ui_pow" external pow : t -> t -> t -> round -> bool = "camlidl_mpfr_mpfr_pow" external neg : t -> t -> round -> int = "camlidl_mpfr_mpfr_neg" external abs : t -> t -> round -> int = "camlidl_mpfr_mpfr_abs" (** {2 Comparison Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Comparison-Functions}C documentation} *) external cmp : t -> t -> int = "camlidl_mpfr_mpfr_cmp" external cmp_si : t -> int -> int = "camlidl_mpfr_mpfr_cmp_si" external cmp_si_2exp : t -> int -> int -> int = "camlidl_mpfr_mpfr_cmp_si_2exp" external sgn : t -> int = "camlidl_mpfr_mpfr_sgn" external _equal : t -> t -> int -> bool = "camlidl_mpfr_mpfr__equal" let equal a b ~bits = _equal a b bits external nan_p : t -> bool = "camlidl_mpfr_mpfr_nan_p" external inf_p : t -> bool = "camlidl_mpfr_mpfr_inf_p" external number_p : t -> bool = "camlidl_mpfr_mpfr_number_p" external reldiff : t -> t -> t -> round -> unit = "camlidl_mpfr_mpfr_reldiff" (** {2 Special Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Special-Functions}C documentation} *) external log : t -> t -> round -> int = "camlidl_mpfr_mpfr_log" external log2 : t -> t -> round -> int = "camlidl_mpfr_mpfr_log2" external log10 : t -> t -> round -> int = "camlidl_mpfr_mpfr_log10" external exp : t -> t -> round -> int = "camlidl_mpfr_mpfr_exp" external exp2 : t -> t -> round -> int = "camlidl_mpfr_mpfr_exp2" external exp10 : t -> t -> round -> int = "camlidl_mpfr_mpfr_exp10" external cos : t -> t -> round -> int = "camlidl_mpfr_mpfr_cos" external sin : t -> t -> round -> int = "camlidl_mpfr_mpfr_sin" external tan : t -> t -> round -> int = "camlidl_mpfr_mpfr_tan" external sec : t -> t -> round -> int = "camlidl_mpfr_mpfr_sec" external csc : t -> t -> round -> int = "camlidl_mpfr_mpfr_csc" external cot : t -> t -> round -> int = "camlidl_mpfr_mpfr_cot" external sin_cos : t -> t -> t -> round -> bool = "camlidl_mpfr_mpfr_sin_cos" external acos : t -> t -> round -> int = "camlidl_mpfr_mpfr_acos" external asin : t -> t -> round -> int = "camlidl_mpfr_mpfr_asin" external atan : t -> t -> round -> int = "camlidl_mpfr_mpfr_atan" external atan2 : t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_atan2" external cosh : t -> t -> round -> int = "camlidl_mpfr_mpfr_cosh" external sinh : t -> t -> round -> int = "camlidl_mpfr_mpfr_sinh" external tanh : t -> t -> round -> int = "camlidl_mpfr_mpfr_tanh" external sech : t -> t -> round -> int = "camlidl_mpfr_mpfr_sech" external csch : t -> t -> round -> int = "camlidl_mpfr_mpfr_csch" external coth : t -> t -> round -> int = "camlidl_mpfr_mpfr_coth" external acosh : t -> t -> round -> int = "camlidl_mpfr_mpfr_acosh" external asinh : t -> t -> round -> int = "camlidl_mpfr_mpfr_asinh" external atanh : t -> t -> round -> int = "camlidl_mpfr_mpfr_atanh" external fac_ui : t -> int -> round -> int = "camlidl_mpfr_mpfr_fac_ui" external log1p : t -> t -> round -> int = "camlidl_mpfr_mpfr_log1p" external expm1 : t -> t -> round -> int = "camlidl_mpfr_mpfr_expm1" external eint : t -> t -> round -> int = "camlidl_mpfr_mpfr_eint" external gamma : t -> t -> round -> int = "camlidl_mpfr_mpfr_gamma" external lngamma : t -> t -> round -> int = "camlidl_mpfr_mpfr_lngamma" external zeta : t -> t -> round -> int = "camlidl_mpfr_mpfr_zeta" external erf : t -> t -> round -> int = "camlidl_mpfr_mpfr_erf" external erfc : t -> t -> round -> int = "camlidl_mpfr_mpfr_erfc" external fma : t -> t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_fma" external agm : t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_agm" external hypot : t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_hypot" external const_log2 : t -> round -> int = "camlidl_mpfr_mpfr_const_log2" external const_pi : t -> round -> int = "camlidl_mpfr_mpfr_const_pi" external const_euler : t -> round -> int = "camlidl_mpfr_mpfr_const_euler" external const_catalan : t -> round -> int = "camlidl_mpfr_mpfr_const_catalan" (** {2 Input and Output Functions: not interfaced} *) (** {2 Miscellaneous Float Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Rounding-Related-Functions}C documentation} *) external rint : t -> t -> round -> int = "camlidl_mpfr_mpfr_rint" external ceil : t -> t -> int = "camlidl_mpfr_mpfr_ceil" external floor : t -> t -> int = "camlidl_mpfr_mpfr_floor" external round : t -> t -> int = "camlidl_mpfr_mpfr_round" external trunc : t -> t -> int = "camlidl_mpfr_mpfr_trunc" external integer_p : t -> bool = "camlidl_mpfr_mpfr_integer_p" external nexttoward : t -> t -> unit = "camlidl_mpfr_mpfr_nexttoward" external nextabove : t -> unit = "camlidl_mpfr_mpfr_nextabove" external nextbelow : t -> unit = "camlidl_mpfr_mpfr_nextbelow" external min : t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_min" external max : t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_max" external get_exp : t -> int = "camlidl_mpfr_mpfr_get_exp" external set_exp : t -> int -> int = "camlidl_mpfr_mpfr_set_exp" (** {2 Additional functions} *) let to_string x = let (s,e) = get_str ~base:10 ~digits:0 x Near in if s="" then "0.0" else Format.sprintf "0.%sE%i" s e (** {2 Pretty printing} *) let print fmt x = let (s,e) = get_str ~base:10 ~digits:0 x Near in if s="" then Format.pp_print_string fmt "0.0" else Format.fprintf fmt "0.%sE%i" s e let string_of_round = function | Near -> "Near" | Zero -> "Zero" | Up -> "Up" | Down -> "Down" let print_round fmt x = Format.pp_print_string fmt (string_of_round x) let to_float ?round x = match round with | None -> get_d1 x | Some r -> get_d x r let to_mpq x = let num,den = Mpz.init(), Mpz.init_set_si 1 in let e = get_z_exp num x in Mpz.mul_2exp den den e; Mpq.of_mpz2 num den let of_int x r = snd (init_set_si x r) let of_float x r = snd (init_set_d x r) let of_mpz x r = snd (init_set_z x r) let of_mpq x r = snd (init_set_q x r) let of_string x r = init_set_str x ~base:10 r let of_frac n d r = let mpq = Mpq.of_frac n d in of_mpq mpq r let of_mpz2 n d r = let mpq = Mpq.of_mpz2 n d in of_mpq mpq r apron-dist-0.9.10/mlgmpidl/gmp_random.ml0000640014525101416610000000371111252216514020030 0ustar bjeannetpopart(* File generated from gmp_random.idl *) (* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution *) type state (** GMP random generation functions *) (** {2 Random State Initialization} *) (** {{:http://gmplib.org/manual/Random-State-Initialization.html#Random-State-Initialization}C documentation} *) external init_default : unit -> state = "camlidl_gmp_random_gmp_randinit_default" external init_lc_2exp : Mpz.t -> int -> int -> state = "camlidl_gmp_random_gmp_randinit_lc_2exp" external init_lc_2exp_size : int -> state = "camlidl_gmp_random_gmp_randinit_lc_2exp_size" (** {2 Random State Seeding} *) (** {{:http://gmplib.org/manual/Random-State-Seeding.html#Random-State-Seeding}C documentation} *) external seed : state -> Mpz.t -> unit = "camlidl_gmp_random_gmp_randseed" external seed_ui : state -> int -> unit = "camlidl_gmp_random_gmp_randseed_ui" (** {2 Random Number Functions} *) (** {3 Integers ({!Mpz})} *) (** {{:http://gmplib.org/manual/Integer-Random-Numbers.html#Integer-Random-Numbers}C documentation} *) module Mpz = struct external urandomb : Mpz.t -> state -> int -> unit = "camlidl_gmp_random_mpz_urandomb" external urandomm : Mpz.t -> state -> Mpz.t -> unit = "camlidl_gmp_random_mpz_urandomm" external rrandomb : Mpz.t -> state -> int -> unit = "camlidl_gmp_random_mpz_rrandomb" end (** {3 Floating-point ({!Mpf})} *) (** {{:http://gmplib.org/manual/Miscellaneous-Float-Functions.html#Miscellaneous-Float-Functions}C documentation} *) module Mpf = struct external urandomb : Mpf.t -> state -> int -> unit = "camlidl_gmp_random_mpf_urandomb" end (** {3 Floating-point ({!Mpfr})} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Miscellaneous-Functions}C documentation} *) module Mpfr = struct external urandomb : Mpfr.t -> state -> unit = "camlidl_gmp_random_mpfr_urandomb" external random : Mpfr.t -> unit = "camlidl_gmp_random_mpfr_random" end apron-dist-0.9.10/mlgmpidl/mpf.ml0000640014525101416610000001427211252216513016472 0ustar bjeannetpopart(* File generated from mpf.idl *) (* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t (** GMP multiprecision floating-point numbers *) (** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x]. These functions are as efficient as their C counterpart: they do not imply additional memory allocation. *) (** {2 Initialization Functions} *) (** {{:http://gmplib.org/manual/Initializing-Floats.html#Initializing-Floats}C documentation} *) external set_default_prec : int -> unit = "camlidl_mpf_mpf_set_default_prec" external get_default_prec : unit -> int = "camlidl_mpf_mpf_get_default_prec" external init : unit -> t = "camlidl_mpf_mpf_init" external init2 : int -> t = "camlidl_mpf_mpf_init2" external get_prec : t -> int = "camlidl_mpf_mpf_get_prec" external set_prec : t -> int -> unit = "camlidl_mpf_mpf_set_prec" external set_prec_raw : t -> int -> unit = "camlidl_mpf_mpf_set_prec_raw" (** {2 Assignement Functions} *) (** {{:http://gmplib.org/manual/Assigning-Floats.html#Assigning-Floats}C documentation} *) external set : t -> t -> unit = "camlidl_mpf_mpf_set" external set_si : t -> int -> unit = "camlidl_mpf_mpf_set_si" external set_d : t -> float -> unit = "camlidl_mpf_mpf_set_d" external set_z : t -> Mpz.t -> unit = "camlidl_mpf_mpf_set_z" external set_q : t -> Mpq.t -> unit = "camlidl_mpf_mpf_set_q" external _set_str : t -> string -> int -> unit = "camlidl_mpf_mpf__set_str" let set_str a b ~base = _set_str a b base external swap : t -> t -> unit = "camlidl_mpf_mpf_swap" (** {2 Combined Initialization and Assignement Functions} *) (** {{:http://gmplib.org/manual/Simultaneous-Float-Init-_0026-Assign.html#Simultaneous-Float-Init-_0026-Assign}C documentation} *) external init_set : t -> t = "camlidl_mpf_mpf_init_set" external init_set_si : int -> t = "camlidl_mpf_mpf_init_set_si" external init_set_d : float -> t = "camlidl_mpf_mpf_init_set_d" external _init_set_str : string -> int -> t = "camlidl_mpf_mpf__init_set_str" let init_set_str a ~base = _init_set_str a base (** {2 Conversion Functions} *) (** {{:http://gmplib.org/manual/Converting-Floats.html#Converting-Floats}C documentation} *) external get_d : t -> float = "camlidl_mpf_mpf_get_d" external get_d_2exp : t -> float * int = "camlidl_mpf_mpf_get_d_2exp" external get_si : t -> nativeint = "camlidl_mpf_mpf_get_si" external get_int : t -> int = "camlidl_mpf_mpf_get_int" external get_z : Mpz.t -> t -> unit = "camlidl_mpf_mpf_get_z" external get_q : Mpq.t -> t -> unit = "camlidl_mpf_mpf_get_q" external _get_str : int -> int -> t -> string * int = "camlidl_mpf_mpf__get_str" let get_str ~base ~digits a = _get_str base digits a (** {2 Arithmetic Functions} *) (** {{:http://gmplib.org/manual/Float-Arithmetic.html#Float-Arithmetic}C documentation} *) external add : t -> t -> t -> unit = "camlidl_mpf_mpf_add" external add_ui : t -> t -> int -> unit = "camlidl_mpf_mpf_add_ui" external sub : t -> t -> t -> unit = "camlidl_mpf_mpf_sub" external ui_sub : t -> int -> t -> unit = "camlidl_mpf_mpf_ui_sub" external sub_ui : t -> t -> int -> unit = "camlidl_mpf_mpf_sub_ui" external mul : t -> t -> t -> unit = "camlidl_mpf_mpf_mul" external mul_ui : t -> t -> int -> unit = "camlidl_mpf_mpf_mul_ui" external mul_2exp : t -> t -> int -> unit = "camlidl_mpf_mpf_mul_2exp" external div : t -> t -> t -> unit = "camlidl_mpf_mpf_div" external ui_div : t -> int -> t -> unit = "camlidl_mpf_mpf_ui_div" external div_ui : t -> t -> int -> unit = "camlidl_mpf_mpf_div_ui" external div_2exp : t -> t -> int -> unit = "camlidl_mpf_mpf_div_2exp" external sqrt : t -> t -> unit = "camlidl_mpf_mpf_sqrt" external pow_ui : t -> t -> int -> unit = "camlidl_mpf_mpf_pow_ui" external neg : t -> t -> unit = "camlidl_mpf_mpf_neg" external abs : t -> t -> unit = "camlidl_mpf_mpf_abs" (** {2 Comparison Functions} *) (** {{:http://gmplib.org/manual/Float-Comparison.html#Float-Comparison}C documentation} *) external cmp : t -> t -> int = "camlidl_mpf_mpf_cmp" external cmp_d : t -> float -> int = "camlidl_mpf_mpf_cmp_d" external cmp_si : t -> int -> int = "camlidl_mpf_mpf_cmp_si" external sgn : t -> int = "camlidl_mpf_mpf_sgn" external _equal : t -> t -> int -> bool = "camlidl_mpf_mpf__equal" let equal a b ~bits = _equal a b bits external reldiff : t -> t -> t -> unit = "camlidl_mpf_mpf_reldiff" (** {2 Input and Output Functions: not interfaced} *) (** {2 Random Number Functions: see {!Gmp_random} module} *) (** {2 Miscellaneous Float Functions} *) (** {{:http://gmplib.org/manual/Miscellaneous-Float-Functions.html#Miscellaneous-Float-Functions}C documentation} *) external ceil : t -> t -> unit = "camlidl_mpf_mpf_ceil" external floor : t -> t -> unit = "camlidl_mpf_mpf_floor" external trunc : t -> t -> unit = "camlidl_mpf_mpf_trunc" external integer_p : t -> bool = "camlidl_mpf_mpf_integer_p" external fits_int_p : t -> bool = "camlidl_mpf_mpf_fits_int_p" external fits_ulong_p : t -> bool = "camlidl_mpf_mpf_fits_ulong_p" external fits_slong_p : t -> bool = "camlidl_mpf_mpf_fits_slong_p" external fits_uint_p : t -> bool = "camlidl_mpf_mpf_fits_uint_p" external fits_sint_p : t -> bool = "camlidl_mpf_mpf_fits_sint_p" external fits_ushort_p : t -> bool = "camlidl_mpf_mpf_fits_ushort_p" external fits_sshort_p : t -> bool = "camlidl_mpf_mpf_fits_sshort_p" (** {2 Additional functions} *) let to_string x = let (s,e) = get_str ~base:10 ~digits:0 x in if s="" then "0.0" else Format.sprintf "0.%se%i" s e let to_float = get_d let of_string str = init_set_str str 10 let of_float = init_set_d let of_int a = init_set_si a let of_mpz x = let res = init() in set_z res x; res let of_mpq x = let res = init() in set_q res x; res let is_integer = integer_p (** {2 Pretty printing} *) let print fmt x = let (s,e) = get_str ~base:10 ~digits:0 x in if s="" then Format.pp_print_string fmt "0.0" else Format.fprintf fmt "0.%se%i" s e apron-dist-0.9.10/mlgmpidl/mpfr_caml.c0000640014525101416610000021242311252216514017461 0ustar bjeannetpopart/* File generated from mpfr.idl */ /* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include "caml/custom.h" #include "gmp_caml.h" extern void camlidl_mpz_ptr_ml2c(value, mpz_ptr *); #define camlidl_ml2c_mpz_mpz_ptr(v,c,ctx) camlidl_mpz_ptr_ml2c(v,c) extern value camlidl_mpz_ptr_c2ml(mpz_ptr *); #define camlidl_c2ml_mpz_mpz_ptr(c,ctx) camlidl_mpz_ptr_c2ml(c) extern void camlidl_mpq_ptr_ml2c(value, mpq_ptr *); #define camlidl_ml2c_mpq_mpq_ptr(v,c,ctx) camlidl_mpq_ptr_ml2c(v,c) extern value camlidl_mpq_ptr_c2ml(mpq_ptr *); #define camlidl_c2ml_mpq_mpq_ptr(c,ctx) camlidl_mpq_ptr_c2ml(c) extern void camlidl_mpf_ptr_ml2c(value, mpf_ptr *); #define camlidl_ml2c_mpf_mpf_ptr(v,c,ctx) camlidl_mpf_ptr_ml2c(v,c) extern value camlidl_mpf_ptr_c2ml(mpf_ptr *); #define camlidl_c2ml_mpf_mpf_ptr(c,ctx) camlidl_mpf_ptr_c2ml(c) #define camlidl_ml2c_mpfr_mpfr_ptr(v,c,ctx) camlidl_mpfr_ptr_ml2c(v,c) #define camlidl_c2ml_mpfr_mpfr_ptr(c,ctx) camlidl_mpfr_ptr_c2ml(c) extern void camlidl_ml2c_mpfr_struct_mpfr_rnd_t(value, mpfr_rnd_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_mpfr_struct_mpfr_rnd_t(mpfr_rnd_t *, camlidl_ctx _ctx); #define camlidl_ml2c_mpfr_mpfr_rnd_t(v,c,ctx) camlidl_mpfr_rnd_t_ml2c(v,c) #define camlidl_c2ml_mpfr_mpfr_rnd_t(c,ctx) camlidl_mpfr_rnd_t_c2ml(c) value camlidl_mpfr_mpfr_set_default_rounding_mode( value _v_RND) { mpfr_rnd_t RND; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); mpfr_set_default_rounding_mode(RND); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_get_default_rounding_mode(value _unit) { mpfr_rnd_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; _res = mpfr_get_default_rounding_mode(); _vres = camlidl_c2ml_mpfr_mpfr_rnd_t(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_round_prec( value _v_X, value _v_RND, value _v_PREC) { mpfr_ptr X; /*in*/ mpfr_rnd_t RND; /*in*/ unsigned long PREC; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); PREC = Long_val(_v_PREC); _res = mpfr_round_prec(X, RND, PREC); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_get_emin(value _unit) { long _res; value _vres; _res = mpfr_get_emin(); _vres = Val_long(_res); return _vres; } value camlidl_mpfr_mpfr_get_emax(value _unit) { long _res; value _vres; _res = mpfr_get_emax(); _vres = Val_long(_res); return _vres; } value camlidl_mpfr_mpfr_set_emin( value _v_EXP) { long EXP; /*in*/ EXP = Long_val(_v_EXP); /* begin user-supplied calling sequence */ { int n = mpfr_set_emin(EXP); if (n){ caml_invalid_argument(""); } } /* end user-supplied calling sequence */ return Val_unit; } value camlidl_mpfr_mpfr_set_emax( value _v_EXP) { long EXP; /*in*/ EXP = Long_val(_v_EXP); /* begin user-supplied calling sequence */ { int n = mpfr_set_emax(EXP); if (n){ caml_invalid_argument(""); } } /* end user-supplied calling sequence */ return Val_unit; } value camlidl_mpfr_mpfr_check_range( value _v_X, value _v_T, value _v_RND) { mpfr_ptr X; /*in*/ int T; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); T = Int_val(_v_T); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_check_range(X, T, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_clear_underflow(value _unit) { mpfr_clear_underflow(); return Val_unit; } value camlidl_mpfr_mpfr_clear_overflow(value _unit) { mpfr_clear_overflow(); return Val_unit; } value camlidl_mpfr_mpfr_clear_nanflag(value _unit) { mpfr_clear_nanflag(); return Val_unit; } value camlidl_mpfr_mpfr_clear_inexflag(value _unit) { mpfr_clear_inexflag(); return Val_unit; } value camlidl_mpfr_mpfr_clear_flags(value _unit) { mpfr_clear_flags(); return Val_unit; } value camlidl_mpfr_mpfr_underflow_p(value _unit) { int _res; value _vres; _res = mpfr_underflow_p(); _vres = Val_int(_res); return _vres; } value camlidl_mpfr_mpfr_overflow_p(value _unit) { int _res; value _vres; _res = mpfr_overflow_p(); _vres = Val_int(_res); return _vres; } value camlidl_mpfr_mpfr_nanflag_p(value _unit) { int _res; value _vres; _res = mpfr_nanflag_p(); _vres = Val_int(_res); return _vres; } value camlidl_mpfr_mpfr_inexflag_p(value _unit) { int _res; value _vres; _res = mpfr_inexflag_p(); _vres = Val_int(_res); return _vres; } value camlidl_mpfr_mpfr_set_default_prec( value _v_PREC) { unsigned long PREC; /*in*/ PREC = Long_val(_v_PREC); mpfr_set_default_prec(PREC); return Val_unit; } value camlidl_mpfr_mpfr_get_default_prec(value _unit) { unsigned long _res; value _vres; _res = mpfr_get_default_prec(); _vres = Val_long(_res); return _vres; } value camlidl_mpfr_mpfr_init(value _unit) { mpfr_t OUTOUTOUT; mpfr_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; mpfr_init(OUTOUTOUT); _vres = camlidl_c2ml_mpfr_mpfr_ptr(&OUTTOUTTOUTT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_init2( value _v_PREC) { mpfr_t OUTOUTOUT; mpfr_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ unsigned long PREC; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; PREC = Long_val(_v_PREC); mpfr_init2(OUTOUTOUT, PREC); _vres = camlidl_c2ml_mpfr_mpfr_ptr(&OUTTOUTTOUTT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_get_prec( value _v_OP) { mpfr_ptr OP; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_get_prec(OP); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_set_prec( value _v_ROP, value _v_PREC) { mpfr_ptr ROP; /*in*/ unsigned long PREC; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); PREC = Long_val(_v_PREC); mpfr_set_prec(ROP, PREC); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_set_prec_raw( value _v_ROP, value _v_PREC) { mpfr_ptr ROP; /*in*/ unsigned long PREC; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); PREC = Long_val(_v_PREC); mpfr_set_prec_raw(ROP, PREC); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_set( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_set(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_set_si( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ long OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); OP = Long_val(_v_OP); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_set_si(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_set_d( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ double OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); OP = Double_val(_v_OP); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_set_d(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_set_z( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_set_z(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_set_q( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpq_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_set_q(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr__set_str( value _v_ROP, value _v_STR, value _v_BASE, value _v_RND) { mpfr_ptr ROP; /*in*/ char *STR; /*in*/ int BASE; /*in*/ mpfr_rnd_t RND; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); STR = String_val(_v_STR); BASE = Int_val(_v_BASE); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); /* begin user-supplied calling sequence */ { int n = mpfr_set_str(ROP,STR,BASE,RND); if (n){ mpfr_clear(ROP); caml_invalid_argument(""); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_set_f( value _v_X, value _v_Y, value _v_RND) { mpfr_ptr X; /*in*/ mpf_ptr Y; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_Y, &Y, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_set_f(X, Y, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_set_si_2exp( value _v_ROP, value _v_OP, value _v_EXPNT, value _v_RND) { mpfr_ptr ROP; /*in*/ long OP; /*in*/ long EXPNT; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); OP = Long_val(_v_OP); EXPNT = Long_val(_v_EXPNT); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_set_si_2exp(ROP, OP, EXPNT, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_set_inf( value _v_X, value _v_SIGN) { mpfr_ptr X; /*in*/ int SIGN; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); SIGN = Int_val(_v_SIGN); mpfr_set_inf(X, SIGN); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_set_nan( value _v_X) { mpfr_ptr X; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); mpfr_set_nan(X); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_swap( value _v_ROP1, value _v_ROP2) { mpfr_ptr ROP1; /*in*/ mpfr_ptr ROP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP1, &ROP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP2, &ROP2, _ctx); mpfr_swap(ROP1, ROP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_init_set( value _v_OP, value _v_RND) { mpfr_t OUTOUTOUT; mpfr_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; value _vresult; value _vres[2] = { 0, 0, }; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_init_set(OUTOUTOUT, OP, RND); Begin_roots_block(_vres, 2) _vres[0] = Val_int(_res); _vres[1] = camlidl_c2ml_mpfr_mpfr_ptr(&OUTTOUTTOUTT, _ctx); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); return _vresult; } value camlidl_mpfr_mpfr_init_set_si( value _v_OP, value _v_RND) { mpfr_t OUTOUTOUT; mpfr_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ long OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; value _vresult; value _vres[2] = { 0, 0, }; OP = Long_val(_v_OP); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_init_set_si(OUTOUTOUT, OP, RND); Begin_roots_block(_vres, 2) _vres[0] = Val_int(_res); _vres[1] = camlidl_c2ml_mpfr_mpfr_ptr(&OUTTOUTTOUTT, _ctx); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); return _vresult; } value camlidl_mpfr_mpfr_init_set_d( value _v_OP, value _v_RND) { mpfr_t OUTOUTOUT; mpfr_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ double OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; value _vresult; value _vres[2] = { 0, 0, }; OP = Double_val(_v_OP); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_init_set_d(OUTOUTOUT, OP, RND); Begin_roots_block(_vres, 2) _vres[0] = Val_int(_res); _vres[1] = camlidl_c2ml_mpfr_mpfr_ptr(&OUTTOUTTOUTT, _ctx); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); return _vresult; } value camlidl_mpfr_mpfr_init_set_f( value _v_OP, value _v_RND) { mpfr_t OUTOUTOUT; mpfr_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ mpf_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; value _vresult; value _vres[2] = { 0, 0, }; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_init_set_f(OUTOUTOUT, OP, RND); Begin_roots_block(_vres, 2) _vres[0] = Val_int(_res); _vres[1] = camlidl_c2ml_mpfr_mpfr_ptr(&OUTTOUTTOUTT, _ctx); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); return _vresult; } value camlidl_mpfr_mpfr_init_set_z( value _v_OP, value _v_RND) { mpfr_t OUTOUTOUT; mpfr_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ mpz_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; value _vresult; value _vres[2] = { 0, 0, }; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_init_set_z(OUTOUTOUT, OP, RND); Begin_roots_block(_vres, 2) _vres[0] = Val_int(_res); _vres[1] = camlidl_c2ml_mpfr_mpfr_ptr(&OUTTOUTTOUTT, _ctx); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); return _vresult; } value camlidl_mpfr_mpfr_init_set_q( value _v_OP, value _v_RND) { mpfr_t OUTOUTOUT; mpfr_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ mpq_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; value _vresult; value _vres[2] = { 0, 0, }; camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_init_set_q(OUTOUTOUT, OP, RND); Begin_roots_block(_vres, 2) _vres[0] = Val_int(_res); _vres[1] = camlidl_c2ml_mpfr_mpfr_ptr(&OUTTOUTTOUTT, _ctx); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); return _vresult; } value camlidl_mpfr_mpfr__init_set_str( value _v_STR, value _v_BASE, value _v_RND) { mpfr_t OUTOUTOUT; mpfr_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ char *STR; /*in*/ int BASE; /*in*/ mpfr_rnd_t RND; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; STR = String_val(_v_STR); BASE = Int_val(_v_BASE); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); /* begin user-supplied calling sequence */ { int n = mpfr_init_set_str(OUTOUTOUT,STR,BASE,RND); if (n){ mpfr_clear(OUTOUTOUT); caml_invalid_argument(""); } } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_mpfr_mpfr_ptr(&OUTTOUTTOUTT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_get_d( value _v_OP, value _v_RND) { mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ double _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_get_d(OP, RND); _vres = copy_double(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_get_d1( value _v_OP) { mpfr_ptr OP; /*in*/ double _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_get_d1(OP); _vres = copy_double(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_get_z_exp( value _v_Z, value _v_OP) { mpz_ptr Z; /*in*/ mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Z, &Z, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_get_z_exp(Z, OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_get_z( value _v_Z, value _v_OP, value _v_RND) { mpz_ptr Z; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Z, &Z, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); mpfr_get_z(Z, OP, RND); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr__get_str( value _v_BASE, value _v_N_DIGITS, value _v_OP, value _v_RND) { long *EXPPTR; /*out*/ int BASE; /*in*/ int N_DIGITS; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ char *_res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; long _c1; value _vresult; value _vres[2] = { 0, 0, }; BASE = Int_val(_v_BASE); N_DIGITS = Int_val(_v_N_DIGITS); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); EXPPTR = &_c1; /* begin user-supplied calling sequence */ _res = mpfr_get_str(NULL,EXPPTR,BASE,N_DIGITS,OP,RND); /* end user-supplied calling sequence */ Begin_roots_block(_vres, 2) _vres[0] = copy_string(_res); _vres[1] = Val_long(*EXPPTR); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ free(_res); /* end user-supplied deallocation sequence */ return _vresult; } value camlidl_mpfr_mpfr_add( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_add(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_add_ui( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ unsigned long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_add_ui(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_add_z( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_add_z(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_add_q( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_add_q(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sub( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sub(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_ui_sub( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ unsigned long OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); OP1 = Long_val(_v_OP1); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_ui_sub(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sub_ui( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ unsigned long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sub_ui(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sub_z( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sub_z(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sub_q( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sub_q(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_mul( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_mul(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_mul_ui( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ unsigned long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_mul_ui(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_mul_z( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_mul_z(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_mul_q( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_mul_q(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_mul_2ui( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ unsigned long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_mul_2ui(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_mul_2si( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_mul_2si(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_mul_2exp( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ unsigned long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_mul_2exp(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_div( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_div(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_ui_div( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ unsigned long OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); OP1 = Long_val(_v_OP1); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_ui_div(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_div_ui( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ unsigned long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_div_ui(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_div_z( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_div_z(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_div_q( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_div_q(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_div_2ui( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ unsigned long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_div_2ui(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_div_2si( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_div_2si(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sqrt( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sqrt(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sqrt_ui( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ unsigned long OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); OP = Long_val(_v_OP); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sqrt_ui(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_pow_ui( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ unsigned long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_pow_ui(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_pow_si( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_pow_si(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_ui_pow_ui( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ unsigned long OP1; /*in*/ unsigned long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); OP1 = Long_val(_v_OP1); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_ui_pow_ui(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_ui_pow( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ unsigned long OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); OP1 = Long_val(_v_OP1); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_ui_pow(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_pow( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_pow(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_neg( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_neg(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_abs( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_abs(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_cmp( value _v_OP1, value _v_OP2) { mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); _res = mpfr_cmp(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_cmp_si( value _v_OP1, value _v_OP2) { mpfr_ptr OP1; /*in*/ long OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); _res = mpfr_cmp_si(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_cmp_si_2exp( value _v_OP1, value _v_OP2, value _v_E) { mpfr_ptr OP1; /*in*/ long OP2; /*in*/ int E; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); E = Int_val(_v_E); _res = mpfr_cmp_si_2exp(OP1, OP2, E); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sgn( value _v_OP) { mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_sgn(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr__equal( value _v_OP1, value _v_OP2, value _v_OP3) { mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ unsigned long OP3; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); OP3 = Long_val(_v_OP3); /* begin user-supplied calling sequence */ _res=mpfr_eq(OP1,OP2,OP3); /* end user-supplied calling sequence */ _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_nan_p( value _v_OP) { mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_nan_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_inf_p( value _v_OP) { mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_inf_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_number_p( value _v_OP) { mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_number_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_reldiff( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); mpfr_reldiff(ROP, OP1, OP2, RND); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_log( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_log(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_log2( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_log2(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_log10( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_log10(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_exp( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_exp(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_exp2( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_exp2(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_exp10( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_exp10(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_cos( value _v_COP, value _v_OP, value _v_RND) { mpfr_ptr COP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_COP, &COP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_cos(COP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sin( value _v_SOP, value _v_OP, value _v_RND) { mpfr_ptr SOP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_SOP, &SOP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sin(SOP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_tan( value _v_TOP, value _v_OP, value _v_RND) { mpfr_ptr TOP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_TOP, &TOP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_tan(TOP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sec( value _v_COP, value _v_OP, value _v_RND) { mpfr_ptr COP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_COP, &COP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sec(COP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_csc( value _v_SOP, value _v_OP, value _v_RND) { mpfr_ptr SOP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_SOP, &SOP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_csc(SOP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_cot( value _v_TOP, value _v_OP, value _v_RND) { mpfr_ptr TOP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_TOP, &TOP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_cot(TOP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sin_cos( value _v_SOP, value _v_COP, value _v_OP, value _v_RND) { mpfr_ptr SOP; /*in*/ mpfr_ptr COP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_SOP, &SOP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_COP, &COP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sin_cos(SOP, COP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_acos( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_acos(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_asin( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_asin(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_atan( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_atan(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_atan2( value _v_ROP, value _v_Y, value _v_X, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr Y; /*in*/ mpfr_ptr X; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_Y, &Y, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_atan2(ROP, Y, X, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_cosh( value _v_COP, value _v_OP, value _v_RND) { mpfr_ptr COP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_COP, &COP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_cosh(COP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sinh( value _v_SOP, value _v_OP, value _v_RND) { mpfr_ptr SOP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_SOP, &SOP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sinh(SOP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_tanh( value _v_TOP, value _v_OP, value _v_RND) { mpfr_ptr TOP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_TOP, &TOP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_tanh(TOP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sech( value _v_COP, value _v_OP, value _v_RND) { mpfr_ptr COP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_COP, &COP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sech(COP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_csch( value _v_SOP, value _v_OP, value _v_RND) { mpfr_ptr SOP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_SOP, &SOP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_csch(SOP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_coth( value _v_TOP, value _v_OP, value _v_RND) { mpfr_ptr TOP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_TOP, &TOP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_coth(TOP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_acosh( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_acosh(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_asinh( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_asinh(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_atanh( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_atanh(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_fac_ui( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ unsigned long OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); OP = Long_val(_v_OP); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_fac_ui(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_log1p( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_log1p(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_expm1( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_expm1(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_eint( value _v_Y, value _v_X, value _v_RND) { mpfr_ptr Y; /*in*/ mpfr_ptr X; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_Y, &Y, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_eint(Y, X, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_gamma( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_gamma(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_lngamma( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_lngamma(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_zeta( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_zeta(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_erf( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_erf(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_erfc( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_erfc(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_fma( value _v_ROP, value _v_OPX, value _v_OPY, value _v_OPZ, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OPX; /*in*/ mpfr_ptr OPY; /*in*/ mpfr_ptr OPZ; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OPX, &OPX, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OPY, &OPY, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OPZ, &OPZ, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_fma(ROP, OPX, OPY, OPZ, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_agm( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_agm(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_hypot( value _v_ROP, value _v_X, value _v_Y, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr X; /*in*/ mpfr_ptr Y; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_Y, &Y, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_hypot(ROP, X, Y, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_const_log2( value _v_ROP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_const_log2(ROP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_const_pi( value _v_ROP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_const_pi(ROP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_const_euler( value _v_ROP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_const_euler(ROP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_const_catalan( value _v_ROP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_const_catalan(ROP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_rint( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_rint(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_ceil( value _v_ROP, value _v_OP) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_ceil(ROP, OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_floor( value _v_ROP, value _v_OP) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_floor(ROP, OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_round( value _v_ROP, value _v_OP) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_round(ROP, OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_trunc( value _v_ROP, value _v_OP) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_trunc(ROP, OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_integer_p( value _v_OP) { mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_integer_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_nexttoward( value _v_X, value _v_Y) { mpfr_ptr X; /*in*/ mpfr_ptr Y; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_Y, &Y, _ctx); mpfr_nexttoward(X, Y); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_nextabove( value _v_X) { mpfr_ptr X; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); mpfr_nextabove(X); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_nextbelow( value _v_X) { mpfr_ptr X; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); mpfr_nextbelow(X); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_min( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_min(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_max( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_max(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_get_exp( value _v_X) { mpfr_ptr X; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); _res = mpfr_get_exp(X); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_set_exp( value _v_X, value _v_E) { mpfr_ptr X; /*in*/ long E; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); E = Long_val(_v_E); _res = mpfr_set_exp(X, E); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } apron-dist-0.9.10/mlgmpidl/mpfrf.ml0000640014525101416610000000533511023223116017013 0ustar bjeannetpopart(** MPFR multi-precision floating-point version, functional version *) (* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution *) open Mpfr type t = Mpfr.t let to_mpfr x = let res = Mpfr.init2 (Mpfr.get_prec x) in let r = Mpfr.set res x Mpfr.Near in assert(r=0); res let of_mpfr = to_mpfr let mpfr x = x let mpfrf x = x (* ====================================================================== *) (** {2 Constructors} *) (* ====================================================================== *) let of_string = Mpfr.of_string let of_float = Mpfr.of_float let of_int = Mpfr.of_int let of_frac = Mpfr.of_frac let of_mpzf (z:Mpzf.t) = Mpfr.of_mpz (Mpzf.mpz z) let of_mpzf2 (num:Mpzf.t) (den:Mpzf.t) = Mpfr.of_mpz2 (Mpzf.mpz num) (Mpzf.mpz den) let of_mpqf (z:Mpqf.t) = Mpfr.of_mpq (Mpqf.mpq z) let of_mpz = Mpfr.of_mpz let of_mpz2 = Mpfr.of_mpz2 let of_mpq = Mpfr.of_mpq (* ====================================================================== *) (** {2 Conversions and Printing} *) (* ====================================================================== *) let to_string = Mpfr.to_string let to_float = Mpfr.to_float let to_mpqf x = Mpqf.mpqf (Mpfr.to_mpq x) let print = Mpfr.print (* ====================================================================== *) (** {2 Arithmetic Functions} *) (* ====================================================================== *) let wrap1 (f: Mpfr.t -> 'a -> 'b -> 'c) = begin fun t r -> let mpfr = Mpfr.init () in ignore (f mpfr t r); mpfr end let wrap2 (f: Mpfr.t -> 'a -> 'b -> 'c -> 'd) = begin fun t1 t2 r -> let mpfr = Mpfr.init () in ignore (f mpfr t1 t2 r); mpfr end let add = wrap2 Mpfr.add let add_int x n r = let mpfr = Mpfr.init () in ignore ( if n>0 then Mpfr.add_ui mpfr x n r else Mpfr.sub_ui mpfr x (-n) r ); mpfr let sub = wrap2 Mpfr.sub let sub_int x n r = let mpfr = Mpfr.init () in ignore ( if n>0 then Mpfr.sub_ui mpfr x n r else Mpfr.add_ui mpfr x (-n) r ); mpfr let mul = wrap2 Mpfr.mul let mul_ui = wrap2 Mpfr.mul_ui let ui_div = wrap2 Mpfr.ui_div let div = wrap2 Mpfr.div let div_ui = wrap2 Mpfr.div_ui let sqrt = wrap1 Mpfr.sqrt let ui_pow = wrap2 Mpfr.ui_pow let pow = wrap2 Mpfr.pow let pow_int = wrap2 Mpfr.pow_si let neg = wrap1 Mpfr.neg let abs = wrap1 Mpfr.abs (* ====================================================================== *) (** {2 Comparison Functions} *) (* ====================================================================== *) let equal = Mpfr.equal let cmp = Mpfr.cmp let cmp_int = Mpfr.cmp_si let nan_p = Mpfr.nan_p let inf_p = Mpfr.inf_p let number_p = Mpfr.number_p let sgn = Mpfr.sgn apron-dist-0.9.10/mlgmpidl/COPYING0000640014525101416610000006403010644465427016424 0ustar bjeannetpopart This license applies to all files distributed in the MLGmpIDL interface, including all source code, libraries, binaries, and documentation. Copyright (C) Bertrand Jeannet 2005-2006 for the MLGmpIDL interface. GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! apron-dist-0.9.10/mlgmpidl/introduction.mli0000640014525101416610000000622211251722332020576 0ustar bjeannetpopart(** *) (** This package is an OCaml interface for the GMP interface, which is decomposed into 7 submodules, corresponding to C modules: {ul {- {module: Mpz}: GMP integers, with side-effect semantics (as in C library)} {- {module: Mpq}: GMP rationals, with side-effect semantics (as in C library)} {- {module: Mpf}: GMP multiprecision floating-point numbers, with side-effect semantics (as in C library)} {- {module: Mpzf}: GMP integers, with functional semantics} {- {module: Mpqf}: GMP integers, with functional semantics} {- {module: Gmp_random}: GMP random number functions} {- {module: Mpfr}: MPFR multiprecision floating-point numbers, with side-effect semantics (as in C library)} {- {module: Mpfrf}: MPFR multiprecision floating-point numbers, with functional semantics} } There already exists such an interface, {{:http://www.di.ens.fr/~monniaux/programmes.html.en}[mlgmp]}, written by D. Monniaux. The motivation for writing a new one in the APRON project were {ol {- The fact that mlgmp provides by default a functional interface to GMP, potentially more costly in term of memory allocation than an imperative interface. mlgmp provides only a relative small numbers of functions in an imperative version.} {- The compatibility with the CamlIDL tool. MLGmpIDL uses CamlIDL, so that other OCaml/C interfaces written with CamlIDL may reuse the MLGmpIDL [.idl] files.} } {2 Requirements} {ul {- GMP library (tested with version 4.0 and up)} {- MPFR library (optional, tested with version 2.2.x)} {- OCaml 3.0 or up (tested with 3.09 and 3.10)} {- Camlidl (tested with 1.05)} } {2 Installation} {ul {- {bf Library} Set the file Makefile.config using the Makefile.config model to your own setting. You might also have to modify the Makefile for executables If you download from the subversion repository, type 'make rebuild', which builds [.ml], [.mli], and [_caml.c] files from [.idl] files. type 'make', possibly 'make debug', and then 'make install' The OCaml part of the library is named [gmp.cma], ([.cmxa], [.a]). The C part of the library is named [libgmp_caml.a], [libgmp_caml.so/dllgmp_caml.so]. 'make install' installs not only [.mli], [.cmi], but also [.idl] files. Be aware however that importing those [.idl] files from other [.idl] files will probably request the application of SED editor with the scripts [sedscript_caml] and [sedscript_c] (look at the Makefile). } {- {b Interpreter and toplevel} With dynamic linking, you can use ordinary runtime ocamlrun and toplevel, otherwise 'make gmprun', 'make gmptop'. You can play with [session.ml], and compile it with 'make session.byte', 'make session.opt'. } {- {b Documentation} The documentation is generated with ocamldoc. 'make mlapronidl.dvi' 'make html' (put the HTML files in the html subdirectoy) } {- {b Miscellaneous} 'make clean' and 'make distclean' have the usual behaviour. 'make mostlyclean', in addition to 'make clean', removes the [.ml], [.mli] and [_caml.c] files generated from .[idl] files. } } *) apron-dist-0.9.10/mlgmpidl/mpf.idl0000640014525101416610000001727111165125334016637 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \"caml/custom.h\"\n\ #include \"gmp_caml.h\"\n\ ") import "mpz.idl"; import "mpq.idl"; typedef [abstract,c2ml(camlidl_mpf_ptr_c2ml),ml2c(camlidl_mpf_ptr_ml2c)] struct __mpf_struct* mpf_ptr; quote(MLMLI,"(** GMP multiprecision floating-point numbers *)\n\n") quote(MLMLI,"(** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x].\n\n These functions are as efficient as their C counterpart: they do not imply additional memory allocation. *)\n\n") /* OUTOUTOUT is a reserved variable name ! (see Makefile and sedscript_c) */ quote(MLI,"\n(** {2 Pretty printing} *)\n") quote(MLI,"val print : Format.formatter -> t -> unit") quote(MLMLI,"\n(** {2 Initialization Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Initializing-Floats.html#Initializing-Floats}C documentation} *)\n") void mpf_set_default_prec (unsigned long int PREC); unsigned long int mpf_get_default_prec (void); void mpf_init ([out] mpf_ptr OUTOUTOUT); void mpf_init2 ([out] mpf_ptr OUTOUTOUT, unsigned long int PREC); unsigned long int mpf_get_prec (mpf_ptr OP); void mpf_set_prec (mpf_ptr ROP, unsigned long int PREC); void mpf_set_prec_raw (mpf_ptr ROP, unsigned long int PREC); quote(MLMLI,"\n(** {2 Assignement Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Assigning-Floats.html#Assigning-Floats}C documentation} *)\n") void mpf_set (mpf_ptr ROP, mpf_ptr OP); void mpf_set_si (mpf_ptr ROP, signed long int OP); void mpf_set_d (mpf_ptr ROP, double OP); void mpf_set_z (mpf_ptr ROP, mpz_ptr OP); void mpf_set_q (mpf_ptr ROP, mpq_ptr OP); void mpf__set_str (mpf_ptr ROP, [string]char *STR, int BASE) quote(call,"{\n\ int n = mpf_set_str(ROP,STR,BASE);\n\ if (n){ mpf_clear(ROP); caml_invalid_argument(\"\"); }\n\ }"); quote(MLI,"val set_str : t -> string -> base:int -> unit") quote(ML,"let set_str a b ~base = _set_str a b base") void mpf_swap (mpf_ptr ROP1, mpf_ptr ROP2); quote(MLMLI,"\n(** {2 Combined Initialization and Assignement Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Simultaneous-Float-Init-_0026-Assign.html#Simultaneous-Float-Init-_0026-Assign}C documentation} *)\n") void mpf_init_set ([out] mpf_ptr OUTOUTOUT, mpf_ptr OP); void mpf_init_set_si ([out] mpf_ptr OUTOUTOUT, signed long int OP); void mpf_init_set_d ([out] mpf_ptr OUTOUTOUT, double OP); void mpf__init_set_str ([out] mpf_ptr OUTOUTOUT, [string]char *STR, int BASE) quote(call,"\ {\n\ int n = mpf_init_set_str(OUTOUTOUT,STR,BASE);\n\ if (n){ mpf_clear(OUTOUTOUT); caml_invalid_argument(\"\"); }\n\ }"); quote(MLI,"val init_set_str : string -> base:int -> t") quote(ML,"let init_set_str a ~base = _init_set_str a base") quote(MLMLI,"\n(** {2 Conversion Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Converting-Floats.html#Converting-Floats}C documentation} *)\n") double mpf_get_d (mpf_ptr OP); double mpf_get_d_2exp ([out]signed long int *EXP, mpf_ptr OP); [nativeint]long mpf_get_si (mpf_ptr OP); long mpf_get_int (mpf_ptr OP) quote(call,"_res = mpf_get_si(OP);"); quote(MLI,"\n (* Replace Mpz.set_f: t -> Mpz.t -> unit *)") void mpf_get_z (mpz_ptr ROP, mpf_ptr OP) quote(call,"mpz_set_f(ROP,OP);"); quote(MLI,"\n (* Replace Mpq.set_f: t -> Mpq.t -> unit *)") void mpf_get_q (mpq_ptr ROP, mpf_ptr OP) quote(call,"mpq_set_f(ROP,OP);"); [string]char* mpf__get_str ([out]long int *EXPPTR, int BASE, int N_DIGITS, mpf_ptr OP) quote(call,"_res = mpf_get_str(NULL,EXPPTR,BASE,N_DIGITS,OP);") quote(dealloc,"free(_res);"); quote(MLI,"val get_str : base:int -> digits:int -> t -> string * int") quote(ML,"let get_str ~base ~digits a = _get_str base digits a") quote(MLI,"\n(** {2 User Conversions} *)\n") quote(MLI,"(** These functionss are additions to or renaming of functions offered by the C library. *)\n") quote(MLI,"val to_string : t -> string") quote(MLI,"val to_float : t -> float") quote(MLI,"val of_string : string -> t") quote(MLI,"val of_float : float -> t") quote(MLI,"val of_int : int -> t") quote(MLI,"val of_mpz : Mpz.t -> t") quote(MLI,"val of_mpq : Mpq.t -> t") quote(MLI,"val is_integer : t -> bool") quote(MLMLI,"\n(** {2 Arithmetic Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Float-Arithmetic.html#Float-Arithmetic}C documentation} *)\n") void mpf_add (mpf_ptr ROP, mpf_ptr OP1, mpf_ptr OP2); void mpf_add_ui (mpf_ptr ROP, mpf_ptr OP1, unsigned long int OP2); void mpf_sub (mpf_ptr ROP, mpf_ptr OP1, mpf_ptr OP2); void mpf_ui_sub (mpf_ptr ROP, unsigned long int OP1, mpf_ptr OP2); void mpf_sub_ui (mpf_ptr ROP, mpf_ptr OP1, unsigned long int OP2); void mpf_mul (mpf_ptr ROP, mpf_ptr OP1, mpf_ptr OP2); void mpf_mul_ui (mpf_ptr ROP, mpf_ptr OP1, unsigned long int OP2); void mpf_mul_2exp (mpf_ptr ROP, mpf_ptr OP1, unsigned long int OP2); void mpf_div (mpf_ptr ROP, mpf_ptr OP1, mpf_ptr OP2); void mpf_ui_div (mpf_ptr ROP, unsigned long int OP1, mpf_ptr OP2); void mpf_div_ui (mpf_ptr ROP, mpf_ptr OP1, unsigned long int OP2); void mpf_div_2exp (mpf_ptr ROP, mpf_ptr OP1, unsigned long int OP2); void mpf_sqrt (mpf_ptr ROP, mpf_ptr OP); void mpf_pow_ui (mpf_ptr ROP, mpf_ptr OP1, unsigned long int OP2); void mpf_neg (mpf_ptr ROP, mpf_ptr OP); void mpf_abs (mpf_ptr ROP, mpf_ptr OP); quote(MLMLI,"\n(** {2 Comparison Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Float-Comparison.html#Float-Comparison}C documentation} *)\n") int mpf_cmp (mpf_ptr OP1, mpf_ptr OP2); int mpf_cmp_d (mpf_ptr OP1, double OP2); int mpf_cmp_si (mpf_ptr OP1, signed long int OP2); int mpf_sgn (mpf_ptr OP); boolean mpf__equal (mpf_ptr OP1, mpf_ptr OP2, unsigned long int OP3) quote(call,"_res=mpf_eq(OP1,OP2,OP3);"); quote(MLI,"val equal : t -> t -> bits:int -> bool") quote(ML,"let equal a b ~bits = _equal a b bits") void mpf_reldiff (mpf_ptr ROP, mpf_ptr OP1, mpf_ptr OP2); quote(MLMLI,"\n(** {2 Input and Output Functions: not interfaced} *)\n") quote(MLMLI,"\n(** {2 Random Number Functions: see {!Gmp_random} module} *)\n") quote(MLMLI,"\n(** {2 Miscellaneous Float Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Miscellaneous-Float-Functions.html#Miscellaneous-Float-Functions}C documentation} *)\n") void mpf_ceil (mpf_ptr ROP, mpf_ptr OP); void mpf_floor (mpf_ptr ROP, mpf_ptr OP); void mpf_trunc (mpf_ptr ROP, mpf_ptr OP); boolean mpf_integer_p (mpf_ptr OP); quote(MLI,"\n(* Does it fit in an OCaml integer *)") boolean mpf_fits_int_p (mpf_ptr OP); quote(MLI,"\n(* Limited relevance here *)") boolean mpf_fits_ulong_p (mpf_ptr OP); boolean mpf_fits_slong_p (mpf_ptr OP); boolean mpf_fits_uint_p (mpf_ptr OP); boolean mpf_fits_sint_p (mpf_ptr OP); boolean mpf_fits_ushort_p (mpf_ptr OP); boolean mpf_fits_sshort_p (mpf_ptr OP); quote(ML,"\n(** {2 Additional functions} *)\n") quote(ML,"let to_string x = \n\ let (s,e) = get_str ~base:10 ~digits:0 x in \n\ if s=\"\" \n\ then \"0.0\" \n\ else Format.sprintf \"0.%se%i\" s e \n\ ") quote(ML,"let to_float = get_d") quote(ML,"let of_string str = init_set_str str 10") quote(ML,"let of_float = init_set_d") quote(ML,"let of_int a = init_set_si a") quote(ML,"let of_mpz x = let res = init() in set_z res x; res") quote(ML,"let of_mpq x = let res = init() in set_q res x; res") quote(ML,"let is_integer = integer_p") quote(ML,"\n(** {2 Pretty printing} *)\n") quote(ML,"let print fmt x = \n\ let (s,e) = get_str ~base:10 ~digits:0 x in \n\ if s=\"\" \n\ then Format.pp_print_string fmt \"0.0\" \n\ else Format.fprintf fmt \"0.%se%i\" s e \n\ ") apron-dist-0.9.10/mlgmpidl/mpzf.mli0000640014525101416610000000475211165125334017042 0ustar bjeannetpopart(** GMP multi-precision integers, functional version *) (* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution *) (** Functions in this module has a functional semantics, unlike the corresponding functions in {!Mpz}. These functions are less efficients, due to the additional memory allocation neded for the result. This module could be extended to offer more functions with a functional semantics. *) type t (** multi-precision integer *) val to_mpz : t -> Mpz.t val of_mpz : Mpz.t -> t (** Safe conversion from and to Mpz.t. There is no sharing between the argument and the result. *) val mpz : t -> Mpz.t val mpzf : Mpz.t -> t (** Unsafe conversion from and to Mpz.t. The argument and the result actually share the same number: be cautious ! *) (* ====================================================================== *) (** {2 Pretty-printing} *) (* ====================================================================== *) val print : Format.formatter -> t -> unit (* ====================================================================== *) (** {2 Constructors} *) (* ====================================================================== *) val of_string : string -> t val of_float : float -> t val of_int : int -> t (* ====================================================================== *) (** {2 Conversions} *) (* ====================================================================== *) val to_string : t -> string val to_float : t -> float (* ====================================================================== *) (** {2 Arithmetic Functions} *) (* ====================================================================== *) val add : t -> t -> t val add_int : t -> int -> t val sub : t -> t -> t val sub_int : t -> int -> t val mul : t -> t -> t val mul_int : t -> int -> t val cdiv_q : t -> t -> t val cdiv_r : t -> t -> t val cdiv_qr : t -> t -> t * t val fdiv_q : t -> t -> t val fdiv_r : t -> t -> t val fdiv_qr : t -> t -> t * t val tdiv_q : t -> t -> t val tdiv_r : t -> t -> t val tdiv_qr : t -> t -> t * t val divexact : t -> t -> t val gmod : t -> t -> t val gcd : t -> t -> t val lcm : t -> t -> t val neg : t -> t val abs : t -> t (* ====================================================================== *) (** {2 Comparison Functions} *) (* ====================================================================== *) val cmp : t -> t -> int val cmp_int : t -> int -> int val sgn : t -> int apron-dist-0.9.10/mlgmpidl/session.ml0000640014525101416610000000040111251722332017360 0ustar bjeannetpopart(* ocaml -I $MLGMPDIL_PREFIX #load "bigarray.cma";; #load "gmp.cma";; #install_printer Mpq.print;; *) open Mpq;; let a = init();; let b = init();; set_si a 2 3;; set_si b 1 5;; get_str ~base:10 a;; get_str ~base:10 b;; add a a b;; let c = init();; apron-dist-0.9.10/mlgmpidl/mpq_caml.c0000640014525101416610000003043711252216513017314 0ustar bjeannetpopart/* File generated from mpq.idl */ /* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include "caml/custom.h" #include "gmp_caml.h" extern void camlidl_mpz_ptr_ml2c(value, mpz_ptr *); #define camlidl_ml2c_mpz_mpz_ptr(v,c,ctx) camlidl_mpz_ptr_ml2c(v,c) extern value camlidl_mpz_ptr_c2ml(mpz_ptr *); #define camlidl_c2ml_mpz_mpz_ptr(c,ctx) camlidl_mpz_ptr_c2ml(c) #define camlidl_ml2c_mpq_mpq_ptr(v,c,ctx) camlidl_mpq_ptr_ml2c(v,c) #define camlidl_c2ml_mpq_mpq_ptr(c,ctx) camlidl_mpq_ptr_c2ml(c) value camlidl_mpq_mpq_canonicalize( value _v_OP) { mpq_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); mpq_canonicalize(OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_init(value _unit) { mpq_t OUTOUTOUT; mpq_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; mpq_init(OUTOUTOUT); _vres = camlidl_c2ml_mpq_mpq_ptr(&OUTTOUTTOUTT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpq_mpq_set( value _v_ROP, value _v_OP) { mpq_ptr ROP; /*in*/ mpq_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); mpq_set(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_set_z( value _v_ROP, value _v_OP) { mpq_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); mpq_set_z(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_set_si( value _v_ROP, value _v_OP1, value _v_OP2) { mpq_ptr ROP; /*in*/ long OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); OP1 = Long_val(_v_OP1); OP2 = Long_val(_v_OP2); mpq_set_si(ROP, OP1, OP2); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ mpq_canonicalize(ROP); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_mpq_mpq__set_str( value _v_ROP, value _v_STR, value _v_BASE) { mpq_ptr ROP; /*in*/ char *STR; /*in*/ int BASE; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); STR = String_val(_v_STR); BASE = Int_val(_v_BASE); /* begin user-supplied calling sequence */ { int n = mpq_set_str(ROP,STR,BASE); if (n){ mpq_clear(ROP); caml_invalid_argument(""); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ mpq_canonicalize(ROP); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_mpq_mpq_swap( value _v_ROP1, value _v_ROP2) { mpq_ptr ROP1; /*in*/ mpq_ptr ROP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP1, &ROP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_ROP2, &ROP2, _ctx); mpq_swap(ROP1, ROP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_get_d( value _v_OP) { mpq_ptr OP; /*in*/ double _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); _res = mpq_get_d(OP); _vres = copy_double(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpq_mpq_set_d( value _v_ROP, value _v_OP) { mpq_ptr ROP; /*in*/ double OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); OP = Double_val(_v_OP); mpq_set_d(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_get_z( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ mpq_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); /* begin user-supplied calling sequence */ mpz_set_q(ROP,OP); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq__get_str( value _v_BASE, value _v_OP) { int BASE; /*in*/ mpq_ptr OP; /*in*/ char *_res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; BASE = Int_val(_v_BASE); camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); /* begin user-supplied calling sequence */ _res = mpq_get_str(NULL,BASE,OP); /* end user-supplied calling sequence */ _vres = copy_string(_res); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ free(_res); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_mpq_mpq_add( value _v_ROP, value _v_OP1, value _v_OP2) { mpq_ptr ROP; /*in*/ mpq_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); mpq_add(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_sub( value _v_ROP, value _v_OP1, value _v_OP2) { mpq_ptr ROP; /*in*/ mpq_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); mpq_sub(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_mul( value _v_ROP, value _v_OP1, value _v_OP2) { mpq_ptr ROP; /*in*/ mpq_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); mpq_mul(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_mul_2exp( value _v_ROP, value _v_OP1, value _v_OP2) { mpq_ptr ROP; /*in*/ mpq_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpq_mul_2exp(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_div( value _v_ROP, value _v_OP1, value _v_OP2) { mpq_ptr ROP; /*in*/ mpq_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); mpq_div(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_div_2exp( value _v_ROP, value _v_OP1, value _v_OP2) { mpq_ptr ROP; /*in*/ mpq_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpq_div_2exp(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_neg( value _v_ROP, value _v_OP) { mpq_ptr ROP; /*in*/ mpq_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); mpq_neg(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_abs( value _v_ROP, value _v_OP) { mpq_ptr ROP; /*in*/ mpq_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); mpq_abs(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_inv( value _v_ROP, value _v_OP) { mpq_ptr ROP; /*in*/ mpq_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); mpq_inv(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_cmp( value _v_OP1, value _v_OP2) { mpq_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); _res = mpq_cmp(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpq_mpq_cmp_si( value _v_OP1, value _v_NUM2, value _v_DEN2) { mpq_ptr OP1; /*in*/ long NUM2; /*in*/ unsigned long DEN2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_OP1, &OP1, _ctx); NUM2 = Long_val(_v_NUM2); DEN2 = Long_val(_v_DEN2); _res = mpq_cmp_si(OP1, NUM2, DEN2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpq_mpq_sgn( value _v_OP) { mpq_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); _res = mpq_sgn(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpq_mpq_equal( value _v_OP1, value _v_OP2) { mpq_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); _res = mpq_equal(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpq_mpq_get_num( value _v_NUMERATOR, value _v_RATIONAL) { mpz_ptr NUMERATOR; /*in*/ mpq_ptr RATIONAL; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_NUMERATOR, &NUMERATOR, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_RATIONAL, &RATIONAL, _ctx); mpq_get_num(NUMERATOR, RATIONAL); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_get_den( value _v_DENOMINATOR, value _v_RATIONAL) { mpz_ptr DENOMINATOR; /*in*/ mpq_ptr RATIONAL; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_DENOMINATOR, &DENOMINATOR, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_RATIONAL, &RATIONAL, _ctx); mpq_get_den(DENOMINATOR, RATIONAL); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_set_num( value _v_RATIONAL, value _v_NUMERATOR) { mpq_ptr RATIONAL; /*in*/ mpz_ptr NUMERATOR; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_RATIONAL, &RATIONAL, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_NUMERATOR, &NUMERATOR, _ctx); mpq_set_num(RATIONAL, NUMERATOR); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_set_den( value _v_RATIONAL, value _v_DENOMINATOR) { mpq_ptr RATIONAL; /*in*/ mpz_ptr DENOMINATOR; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_RATIONAL, &RATIONAL, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_DENOMINATOR, &DENOMINATOR, _ctx); mpq_set_den(RATIONAL, DENOMINATOR); camlidl_free(_ctx); return Val_unit; } apron-dist-0.9.10/mlgmpidl/gmp_random_caml.c0000640014525101416610000001602411252216514020637 0ustar bjeannetpopart/* File generated from gmp_random.idl */ /* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include "caml/custom.h" #include "gmp_caml.h" extern void camlidl_mpz_ptr_ml2c(value, mpz_ptr *); #define camlidl_ml2c_mpz_mpz_ptr(v,c,ctx) camlidl_mpz_ptr_ml2c(v,c) extern value camlidl_mpz_ptr_c2ml(mpz_ptr *); #define camlidl_c2ml_mpz_mpz_ptr(c,ctx) camlidl_mpz_ptr_c2ml(c) extern void camlidl_mpq_ptr_ml2c(value, mpq_ptr *); #define camlidl_ml2c_mpq_mpq_ptr(v,c,ctx) camlidl_mpq_ptr_ml2c(v,c) extern value camlidl_mpq_ptr_c2ml(mpq_ptr *); #define camlidl_c2ml_mpq_mpq_ptr(c,ctx) camlidl_mpq_ptr_c2ml(c) extern void camlidl_mpf_ptr_ml2c(value, mpf_ptr *); #define camlidl_ml2c_mpf_mpf_ptr(v,c,ctx) camlidl_mpf_ptr_ml2c(v,c) extern value camlidl_mpf_ptr_c2ml(mpf_ptr *); #define camlidl_c2ml_mpf_mpf_ptr(c,ctx) camlidl_mpf_ptr_c2ml(c) extern void camlidl_mpfr_ptr_ml2c(value, mpfr_ptr *); #define camlidl_ml2c_mpfr_mpfr_ptr(v,c,ctx) camlidl_mpfr_ptr_ml2c(v,c) extern value camlidl_mpfr_ptr_c2ml(mpfr_ptr *); #define camlidl_c2ml_mpfr_mpfr_ptr(c,ctx) camlidl_mpfr_ptr_c2ml(c) extern void camlidl_ml2c_mpfr_struct_mpfr_rnd_t(value, mpfr_rnd_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_mpfr_struct_mpfr_rnd_t(mpfr_rnd_t *, camlidl_ctx _ctx); extern void camlidl_mpfr_rnd_t_ml2c(value, mpfr_rnd_t *); #define camlidl_ml2c_mpfr_mpfr_rnd_t(v,c,ctx) camlidl_mpfr_rnd_t_ml2c(v,c) extern value camlidl_mpfr_rnd_t_c2ml(mpfr_rnd_t *); #define camlidl_c2ml_mpfr_mpfr_rnd_t(c,ctx) camlidl_mpfr_rnd_t_c2ml(c) #define camlidl_ml2c_gmp_random_gmp_randstate_ptr(v,c,ctx) camlidl_gmp_randstate_ptr_ml2c(v,c) #define camlidl_c2ml_gmp_random_gmp_randstate_ptr(c,ctx) camlidl_gmp_randstate_ptr_c2ml(c) value camlidl_gmp_random_gmp_randinit_default(value _unit) { gmp_randstate_t OUTOUTOUT; gmp_randstate_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; gmp_randinit_default(OUTOUTOUT); _vres = camlidl_c2ml_gmp_random_gmp_randstate_ptr(&OUTTOUTTOUTT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_gmp_random_gmp_randinit_lc_2exp( value _v_A, value _v_C, value _v_M2EXP) { gmp_randstate_t OUTOUTOUT; gmp_randstate_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ mpz_ptr A; /*in*/ unsigned long C; /*in*/ unsigned long M2EXP; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_A, &A, _ctx); C = Long_val(_v_C); M2EXP = Long_val(_v_M2EXP); gmp_randinit_lc_2exp(OUTOUTOUT, A, C, M2EXP); _vres = camlidl_c2ml_gmp_random_gmp_randstate_ptr(&OUTTOUTTOUTT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_gmp_random_gmp_randinit_lc_2exp_size( value _v_SIZE) { gmp_randstate_t OUTOUTOUT; gmp_randstate_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ unsigned long SIZE; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; SIZE = Long_val(_v_SIZE); /* begin user-supplied calling sequence */ { int n = gmp_randinit_lc_2exp_size(OUTOUTOUT,SIZE); if (n==0) caml_invalid_argument("Argument not supported"); } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_gmp_random_gmp_randstate_ptr(&OUTTOUTTOUTT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_gmp_random_gmp_randseed( value _v_STATE, value _v_SEED) { gmp_randstate_ptr STATE; /*in*/ mpz_ptr SEED; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_gmp_random_gmp_randstate_ptr(_v_STATE, &STATE, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_SEED, &SEED, _ctx); gmp_randseed(STATE, SEED); camlidl_free(_ctx); return Val_unit; } value camlidl_gmp_random_gmp_randseed_ui( value _v_STATE, value _v_SEED) { gmp_randstate_ptr STATE; /*in*/ unsigned long SEED; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_gmp_random_gmp_randstate_ptr(_v_STATE, &STATE, _ctx); SEED = Long_val(_v_SEED); gmp_randseed_ui(STATE, SEED); camlidl_free(_ctx); return Val_unit; } value camlidl_gmp_random_mpz_urandomb( value _v_ROP, value _v_STATE, value _v_N) { mpz_ptr ROP; /*in*/ gmp_randstate_ptr STATE; /*in*/ unsigned long N; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_gmp_random_gmp_randstate_ptr(_v_STATE, &STATE, _ctx); N = Long_val(_v_N); mpz_urandomb(ROP, STATE, N); camlidl_free(_ctx); return Val_unit; } value camlidl_gmp_random_mpz_urandomm( value _v_ROP, value _v_STATE, value _v_N) { mpz_ptr ROP; /*in*/ gmp_randstate_ptr STATE; /*in*/ mpz_ptr N; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_gmp_random_gmp_randstate_ptr(_v_STATE, &STATE, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); mpz_urandomm(ROP, STATE, N); camlidl_free(_ctx); return Val_unit; } value camlidl_gmp_random_mpz_rrandomb( value _v_ROP, value _v_STATE, value _v_N) { mpz_ptr ROP; /*in*/ gmp_randstate_ptr STATE; /*in*/ unsigned long N; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_gmp_random_gmp_randstate_ptr(_v_STATE, &STATE, _ctx); N = Long_val(_v_N); mpz_rrandomb(ROP, STATE, N); camlidl_free(_ctx); return Val_unit; } value camlidl_gmp_random_mpf_urandomb( value _v_ROP, value _v_STATE, value _v_N) { mpf_ptr ROP; /*in*/ gmp_randstate_ptr STATE; /*in*/ unsigned long N; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_gmp_random_gmp_randstate_ptr(_v_STATE, &STATE, _ctx); N = Long_val(_v_N); mpf_urandomb(ROP, STATE, N); camlidl_free(_ctx); return Val_unit; } value camlidl_gmp_random_mpfr_urandomb( value _v_ROP, value _v_STATE) { mpfr_ptr ROP; /*in*/ gmp_randstate_ptr STATE; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_gmp_random_gmp_randstate_ptr(_v_STATE, &STATE, _ctx); mpfr_urandomb(ROP, STATE); camlidl_free(_ctx); return Val_unit; } value camlidl_gmp_random_mpfr_random( value _v_ROP) { mpfr_ptr ROP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); mpfr_random(ROP); camlidl_free(_ctx); return Val_unit; } apron-dist-0.9.10/mlgmpidl/mpq.ml0000640014525101416610000000765011252216513016507 0ustar bjeannetpopart(* File generated from mpq.idl *) (* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t (** GMP multiprecision rationals *) (** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x]. These functions are as efficient as their C counterpart: they do not imply additional memory allocation, unlike the corresponding functions in the module {!Mpqf}. *) external canonicalize : t -> unit = "camlidl_mpq_mpq_canonicalize" (** {2 Initialization and Assignment Functions} *) (** {{:http://gmplib.org/manual/Initializing-Rationals.html#Initializing-Rationals}C documentation} *) external init : unit -> t = "camlidl_mpq_mpq_init" external set : t -> t -> unit = "camlidl_mpq_mpq_set" external set_z : t -> Mpz.t -> unit = "camlidl_mpq_mpq_set_z" external set_si : t -> int -> int -> unit = "camlidl_mpq_mpq_set_si" external _set_str : t -> string -> int -> unit = "camlidl_mpq_mpq__set_str" let set_str a b ~base = _set_str a b base external swap : t -> t -> unit = "camlidl_mpq_mpq_swap" (** {2 Conversion Functions} *) (** {{:http://gmplib.org/manual/Rational-Conversions.html#Rational-Conversions}C documentation} *) external get_d : t -> float = "camlidl_mpq_mpq_get_d" external set_d : t -> float -> unit = "camlidl_mpq_mpq_set_d" external get_z : Mpz.t -> t -> unit = "camlidl_mpq_mpq_get_z" external _get_str : int -> t -> string = "camlidl_mpq_mpq__get_str" let get_str ~base a = _get_str base a (** {2 Arithmetic Functions} *) (** {{:http://gmplib.org/manual/Rational-Arithmetic.html#Rational-Arithmetic}C documentation} *) external add : t -> t -> t -> unit = "camlidl_mpq_mpq_add" external sub : t -> t -> t -> unit = "camlidl_mpq_mpq_sub" external mul : t -> t -> t -> unit = "camlidl_mpq_mpq_mul" external mul_2exp : t -> t -> int -> unit = "camlidl_mpq_mpq_mul_2exp" external div : t -> t -> t -> unit = "camlidl_mpq_mpq_div" external div_2exp : t -> t -> int -> unit = "camlidl_mpq_mpq_div_2exp" external neg : t -> t -> unit = "camlidl_mpq_mpq_neg" external abs : t -> t -> unit = "camlidl_mpq_mpq_abs" external inv : t -> t -> unit = "camlidl_mpq_mpq_inv" (** {2 Comparison Functions} *) (** {{:http://gmplib.org/manual/Comparing-Rationals.html#Comparing-Rationals}C documentation} *) external cmp : t -> t -> int = "camlidl_mpq_mpq_cmp" external cmp_si : t -> int -> int -> int = "camlidl_mpq_mpq_cmp_si" external sgn : t -> int = "camlidl_mpq_mpq_sgn" external equal : t -> t -> bool = "camlidl_mpq_mpq_equal" (** {2 Applying Integer Functions to Rationals} *) (** {{:http://gmplib.org/manual/Applying-Integer-Functions.html#Applying-Integer-Functions}C documentation} *) external get_num : Mpz.t -> t -> unit = "camlidl_mpq_mpq_get_num" external get_den : Mpz.t -> t -> unit = "camlidl_mpq_mpq_get_den" external set_num : t -> Mpz.t -> unit = "camlidl_mpq_mpq_set_num" external set_den : t -> Mpz.t -> unit = "camlidl_mpq_mpq_set_den" (** {2 Input and Output Functions: not interfaced} *) (** {2 Pretty printing} *) let print fmt x = Format.pp_print_string fmt (get_str 10 x) let init_set x = let y = init() in set y x; y let init_set_z z = let x = init() in set_z x z; x let init_set_si n d = let x = init() in set_si x n d; x let init_set_str str ~base = let x = init() in ignore (set_str x str ~base); x let init_set_d d = let x = init() in set_d x d; x let to_string x = get_str 10 x let to_float = get_d let of_string str = init_set_str str 10 let of_float = init_set_d let of_int a = init_set_si a 1 let of_frac = init_set_si let of_mpz = init_set_z let of_mpz2 num den = let res = init() in set_num res num; set_den res den; canonicalize res; res apron-dist-0.9.10/mlgmpidl/mpf.mli0000640014525101416610000001425011252216513016637 0ustar bjeannetpopart(* File generated from mpf.idl *) (* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t (** GMP multiprecision floating-point numbers *) (** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x]. These functions are as efficient as their C counterpart: they do not imply additional memory allocation. *) (** {2 Pretty printing} *) val print : Format.formatter -> t -> unit (** {2 Initialization Functions} *) (** {{:http://gmplib.org/manual/Initializing-Floats.html#Initializing-Floats}C documentation} *) external set_default_prec : int -> unit = "camlidl_mpf_mpf_set_default_prec" external get_default_prec : unit -> int = "camlidl_mpf_mpf_get_default_prec" external init : unit -> t = "camlidl_mpf_mpf_init" external init2 : int -> t = "camlidl_mpf_mpf_init2" external get_prec : t -> int = "camlidl_mpf_mpf_get_prec" external set_prec : t -> int -> unit = "camlidl_mpf_mpf_set_prec" external set_prec_raw : t -> int -> unit = "camlidl_mpf_mpf_set_prec_raw" (** {2 Assignement Functions} *) (** {{:http://gmplib.org/manual/Assigning-Floats.html#Assigning-Floats}C documentation} *) external set : t -> t -> unit = "camlidl_mpf_mpf_set" external set_si : t -> int -> unit = "camlidl_mpf_mpf_set_si" external set_d : t -> float -> unit = "camlidl_mpf_mpf_set_d" external set_z : t -> Mpz.t -> unit = "camlidl_mpf_mpf_set_z" external set_q : t -> Mpq.t -> unit = "camlidl_mpf_mpf_set_q" external _set_str : t -> string -> int -> unit = "camlidl_mpf_mpf__set_str" val set_str : t -> string -> base:int -> unit external swap : t -> t -> unit = "camlidl_mpf_mpf_swap" (** {2 Combined Initialization and Assignement Functions} *) (** {{:http://gmplib.org/manual/Simultaneous-Float-Init-_0026-Assign.html#Simultaneous-Float-Init-_0026-Assign}C documentation} *) external init_set : t -> t = "camlidl_mpf_mpf_init_set" external init_set_si : int -> t = "camlidl_mpf_mpf_init_set_si" external init_set_d : float -> t = "camlidl_mpf_mpf_init_set_d" external _init_set_str : string -> int -> t = "camlidl_mpf_mpf__init_set_str" val init_set_str : string -> base:int -> t (** {2 Conversion Functions} *) (** {{:http://gmplib.org/manual/Converting-Floats.html#Converting-Floats}C documentation} *) external get_d : t -> float = "camlidl_mpf_mpf_get_d" external get_d_2exp : t -> float * int = "camlidl_mpf_mpf_get_d_2exp" external get_si : t -> nativeint = "camlidl_mpf_mpf_get_si" external get_int : t -> int = "camlidl_mpf_mpf_get_int" (* Replace Mpz.set_f: t -> Mpz.t -> unit *) external get_z : Mpz.t -> t -> unit = "camlidl_mpf_mpf_get_z" (* Replace Mpq.set_f: t -> Mpq.t -> unit *) external get_q : Mpq.t -> t -> unit = "camlidl_mpf_mpf_get_q" external _get_str : int -> int -> t -> string * int = "camlidl_mpf_mpf__get_str" val get_str : base:int -> digits:int -> t -> string * int (** {2 User Conversions} *) (** These functionss are additions to or renaming of functions offered by the C library. *) val to_string : t -> string val to_float : t -> float val of_string : string -> t val of_float : float -> t val of_int : int -> t val of_mpz : Mpz.t -> t val of_mpq : Mpq.t -> t val is_integer : t -> bool (** {2 Arithmetic Functions} *) (** {{:http://gmplib.org/manual/Float-Arithmetic.html#Float-Arithmetic}C documentation} *) external add : t -> t -> t -> unit = "camlidl_mpf_mpf_add" external add_ui : t -> t -> int -> unit = "camlidl_mpf_mpf_add_ui" external sub : t -> t -> t -> unit = "camlidl_mpf_mpf_sub" external ui_sub : t -> int -> t -> unit = "camlidl_mpf_mpf_ui_sub" external sub_ui : t -> t -> int -> unit = "camlidl_mpf_mpf_sub_ui" external mul : t -> t -> t -> unit = "camlidl_mpf_mpf_mul" external mul_ui : t -> t -> int -> unit = "camlidl_mpf_mpf_mul_ui" external mul_2exp : t -> t -> int -> unit = "camlidl_mpf_mpf_mul_2exp" external div : t -> t -> t -> unit = "camlidl_mpf_mpf_div" external ui_div : t -> int -> t -> unit = "camlidl_mpf_mpf_ui_div" external div_ui : t -> t -> int -> unit = "camlidl_mpf_mpf_div_ui" external div_2exp : t -> t -> int -> unit = "camlidl_mpf_mpf_div_2exp" external sqrt : t -> t -> unit = "camlidl_mpf_mpf_sqrt" external pow_ui : t -> t -> int -> unit = "camlidl_mpf_mpf_pow_ui" external neg : t -> t -> unit = "camlidl_mpf_mpf_neg" external abs : t -> t -> unit = "camlidl_mpf_mpf_abs" (** {2 Comparison Functions} *) (** {{:http://gmplib.org/manual/Float-Comparison.html#Float-Comparison}C documentation} *) external cmp : t -> t -> int = "camlidl_mpf_mpf_cmp" external cmp_d : t -> float -> int = "camlidl_mpf_mpf_cmp_d" external cmp_si : t -> int -> int = "camlidl_mpf_mpf_cmp_si" external sgn : t -> int = "camlidl_mpf_mpf_sgn" external _equal : t -> t -> int -> bool = "camlidl_mpf_mpf__equal" val equal : t -> t -> bits:int -> bool external reldiff : t -> t -> t -> unit = "camlidl_mpf_mpf_reldiff" (** {2 Input and Output Functions: not interfaced} *) (** {2 Random Number Functions: see {!Gmp_random} module} *) (** {2 Miscellaneous Float Functions} *) (** {{:http://gmplib.org/manual/Miscellaneous-Float-Functions.html#Miscellaneous-Float-Functions}C documentation} *) external ceil : t -> t -> unit = "camlidl_mpf_mpf_ceil" external floor : t -> t -> unit = "camlidl_mpf_mpf_floor" external trunc : t -> t -> unit = "camlidl_mpf_mpf_trunc" external integer_p : t -> bool = "camlidl_mpf_mpf_integer_p" (* Does it fit in an OCaml integer *) external fits_int_p : t -> bool = "camlidl_mpf_mpf_fits_int_p" (* Limited relevance here *) external fits_ulong_p : t -> bool = "camlidl_mpf_mpf_fits_ulong_p" external fits_slong_p : t -> bool = "camlidl_mpf_mpf_fits_slong_p" external fits_uint_p : t -> bool = "camlidl_mpf_mpf_fits_uint_p" external fits_sint_p : t -> bool = "camlidl_mpf_mpf_fits_sint_p" external fits_ushort_p : t -> bool = "camlidl_mpf_mpf_fits_ushort_p" external fits_sshort_p : t -> bool = "camlidl_mpf_mpf_fits_sshort_p" apron-dist-0.9.10/mlgmpidl/gmp_random.mli0000640014525101416610000000370011252216514020177 0ustar bjeannetpopart(* File generated from gmp_random.idl *) (* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution *) type state (** GMP random generation functions *) (** {2 Random State Initialization} *) (** {{:http://gmplib.org/manual/Random-State-Initialization.html#Random-State-Initialization}C documentation} *) external init_default : unit -> state = "camlidl_gmp_random_gmp_randinit_default" external init_lc_2exp : Mpz.t -> int -> int -> state = "camlidl_gmp_random_gmp_randinit_lc_2exp" external init_lc_2exp_size : int -> state = "camlidl_gmp_random_gmp_randinit_lc_2exp_size" (** {2 Random State Seeding} *) (** {{:http://gmplib.org/manual/Random-State-Seeding.html#Random-State-Seeding}C documentation} *) external seed : state -> Mpz.t -> unit = "camlidl_gmp_random_gmp_randseed" external seed_ui : state -> int -> unit = "camlidl_gmp_random_gmp_randseed_ui" (** {2 Random Number Functions} *) (** {3 Integers ({!Mpz})} *) (** {{:http://gmplib.org/manual/Integer-Random-Numbers.html#Integer-Random-Numbers}C documentation} *) module Mpz : sig external urandomb : Mpz.t -> state -> int -> unit = "camlidl_gmp_random_mpz_urandomb" external urandomm : Mpz.t -> state -> Mpz.t -> unit = "camlidl_gmp_random_mpz_urandomm" external rrandomb : Mpz.t -> state -> int -> unit = "camlidl_gmp_random_mpz_rrandomb" end (** {3 Floating-point ({!Mpf})} *) (** {{:http://gmplib.org/manual/Miscellaneous-Float-Functions.html#Miscellaneous-Float-Functions}C documentation} *) module Mpf : sig external urandomb : Mpf.t -> state -> int -> unit = "camlidl_gmp_random_mpf_urandomb" end (** {3 Floating-point ({!Mpfr})} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Miscellaneous-Functions}C documentation} *) module Mpfr : sig external urandomb : Mpfr.t -> state -> unit = "camlidl_gmp_random_mpfr_urandomb" external random : Mpfr.t -> unit = "camlidl_gmp_random_mpfr_random" end apron-dist-0.9.10/mlgmpidl/mpz.mli0000640014525101416610000003216311252216513016666 0ustar bjeannetpopart(* File generated from mpz.idl *) (* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t (** GMP multi-precision integers *) (** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x]. These functions are as efficient as their C counterpart: they do not imply additional memory allocation, unlike the corresponding functions in the module {!Mpzf}. *) (** {2 Pretty printing} *) val print : Format.formatter -> t -> unit (** {2 Initialization Functions} *) (** {{:http://gmplib.org/manual/Initializing-Integers.html#Initializing-Integers}C documentation} *) external init : unit -> t = "camlidl_mpz_mpz_init" external init2 : int -> t = "camlidl_mpz_mpz_init2" external realloc2 : t -> int -> unit = "camlidl_mpz_mpz_realloc2" (** {2 Assignement Functions} *) (** {{:http://gmplib.org/manual/Assigning-Integers.html#Assigning-Integers}C documentation} *) (** The first parameter holds the result. *) external set : t -> t -> unit = "camlidl_mpz_mpz_set" external set_si : t -> int -> unit = "camlidl_mpz_mpz_set_si" external set_d : t -> float -> unit = "camlidl_mpz_mpz_set_d" (** For [set_q: t -> Mpq.t -> unit], see {!Mpq.get_z} *) external _set_str : t -> string -> int -> unit = "camlidl_mpz_mpz__set_str" val set_str : t -> string -> base:int -> unit external swap : t -> t -> unit = "camlidl_mpz_mpz_swap" (** {2 Combined Initialization and Assignment Functions} *) (** {{:http://gmplib.org/manual/Simultaneous-Integer-Init-_0026-Assign.html#Simultaneous-Integer-Init-_0026-Assign}C documentation} *) external init_set : t -> t = "camlidl_mpz_mpz_init_set" external init_set_si : int -> t = "camlidl_mpz_mpz_init_set_si" external init_set_d : float -> t = "camlidl_mpz_mpz_init_set_d" external _init_set_str : string -> int -> t = "camlidl_mpz_mpz__init_set_str" val init_set_str : string -> base:int -> t (** {2 Conversion Functions} *) (** {{:http://gmplib.org/manual/Converting-Integers.html#Converting-Integers}C documentation} *) external get_si : t -> nativeint = "camlidl_mpz_mpz_get_si" external get_int : t -> int = "camlidl_mpz_mpz_get_int" external get_d : t -> float = "camlidl_mpz_mpz_get_d" external get_d_2exp : t -> float * int = "camlidl_mpz_mpz_get_d_2exp" external _get_str : int -> t -> string = "camlidl_mpz_mpz__get_str" val get_str : base:int -> t -> string (** {2 User Conversions} *) (** These functions are additions to or renaming of functions offered by the C library. *) val to_string : t -> string val to_float : t -> float val of_string : string -> t val of_float : float -> t val of_int : int -> t (** {2 Arithmetic Functions} *) (** {{:http://gmplib.org/manual/Integer-Arithmetic.html#Integer-Arithmetic}C documentation} *) (** The first parameter holds the result. *) external add : t -> t -> t -> unit = "camlidl_mpz_mpz_add" external add_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_add_ui" external sub : t -> t -> t -> unit = "camlidl_mpz_mpz_sub" external sub_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_sub_ui" external ui_sub : t -> int -> t -> unit = "camlidl_mpz_mpz_ui_sub" external mul : t -> t -> t -> unit = "camlidl_mpz_mpz_mul" external mul_si : t -> t -> int -> unit = "camlidl_mpz_mpz_mul_si" external addmul : t -> t -> t -> unit = "camlidl_mpz_mpz_addmul" external addmul_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_addmul_ui" external submul : t -> t -> t -> unit = "camlidl_mpz_mpz_submul" external submul_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_submul_ui" external mul_2exp : t -> t -> int -> unit = "camlidl_mpz_mpz_mul_2exp" external neg : t -> t -> unit = "camlidl_mpz_mpz_neg" external abs : t -> t -> unit = "camlidl_mpz_mpz_abs" (** {2 Division Functions} *) (** {{:http://gmplib.org/manual/Integer-Division.html#Integer-Division}C documentation} *) (** [c] stands for ceiling, [f] for floor, and [t] for truncate (rounds toward 0).*) (** {3 Ceiling division} *) (** The first parameter holds the quotient. *) external cdiv_q : t -> t -> t -> unit = "camlidl_mpz_mpz_cdiv_q" (** The first parameter holds the remainder. *) external cdiv_r : t -> t -> t -> unit = "camlidl_mpz_mpz_cdiv_r" (** The two first parameters hold resp. the quotient and the remainder). *) external cdiv_qr : t -> t -> t -> t -> unit = "camlidl_mpz_mpz_cdiv_qr" (** The first parameter holds the quotient. *) external cdiv_q_ui : t -> t -> int -> int = "camlidl_mpz_mpz_cdiv_q_ui" (** The first parameter holds the remainder. *) external cdiv_r_ui : t -> t -> int -> int = "camlidl_mpz_mpz_cdiv_r_ui" (** The two first parameters hold resp. the quotient and the remainder). *) external cdiv_qr_ui : t -> t -> t -> int -> int = "camlidl_mpz_mpz_cdiv_qr_ui" external cdiv_ui : t -> int -> int = "camlidl_mpz_mpz_cdiv_ui" (** The first parameter holds the quotient. *) external cdiv_q_2exp : t -> t -> int -> unit = "camlidl_mpz_mpz_cdiv_q_2exp" (** The first parameter holds the remainder. *) external cdiv_r_2exp : t -> t -> int -> unit = "camlidl_mpz_mpz_cdiv_r_2exp" (** {3 Floor division} *) external fdiv_q : t -> t -> t -> unit = "camlidl_mpz_mpz_fdiv_q" external fdiv_r : t -> t -> t -> unit = "camlidl_mpz_mpz_fdiv_r" external fdiv_qr : t -> t -> t -> t -> unit = "camlidl_mpz_mpz_fdiv_qr" external fdiv_q_ui : t -> t -> int -> int = "camlidl_mpz_mpz_fdiv_q_ui" external fdiv_r_ui : t -> t -> int -> int = "camlidl_mpz_mpz_fdiv_r_ui" external fdiv_qr_ui : t -> t -> t -> int -> int = "camlidl_mpz_mpz_fdiv_qr_ui" external fdiv_ui : t -> int -> int = "camlidl_mpz_mpz_fdiv_ui" external fdiv_q_2exp : t -> t -> int -> unit = "camlidl_mpz_mpz_fdiv_q_2exp" external fdiv_r_2exp : t -> t -> int -> unit = "camlidl_mpz_mpz_fdiv_r_2exp" (** {3 Truncate division} *) external tdiv_q : t -> t -> t -> unit = "camlidl_mpz_mpz_tdiv_q" external tdiv_r : t -> t -> t -> unit = "camlidl_mpz_mpz_tdiv_r" external tdiv_qr : t -> t -> t -> t -> unit = "camlidl_mpz_mpz_tdiv_qr" external tdiv_q_ui : t -> t -> int -> int = "camlidl_mpz_mpz_tdiv_q_ui" external tdiv_r_ui : t -> t -> int -> int = "camlidl_mpz_mpz_tdiv_r_ui" external tdiv_qr_ui : t -> t -> t -> int -> int = "camlidl_mpz_mpz_tdiv_qr_ui" external tdiv_ui : t -> int -> int = "camlidl_mpz_mpz_tdiv_ui" external tdiv_q_2exp : t -> t -> int -> unit = "camlidl_mpz_mpz_tdiv_q_2exp" external tdiv_r_2exp : t -> t -> int -> unit = "camlidl_mpz_mpz_tdiv_r_2exp" (** {3 Other division-related functions} *) external gmod : t -> t -> t -> unit = "camlidl_mpz_mpz_gmod" external gmod_ui : t -> t -> int -> int = "camlidl_mpz_mpz_gmod_ui" external divexact : t -> t -> t -> unit = "camlidl_mpz_mpz_divexact" external divexact_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_divexact_ui" external divisible_p : t -> t -> bool = "camlidl_mpz_mpz_divisible_p" external divisible_ui_p : t -> int -> bool = "camlidl_mpz_mpz_divisible_ui_p" external divisible_2exp_p : t -> int -> bool = "camlidl_mpz_mpz_divisible_2exp_p" external congruent_p : t -> t -> t -> bool = "camlidl_mpz_mpz_congruent_p" external congruent_ui_p : t -> int -> int -> bool = "camlidl_mpz_mpz_congruent_ui_p" external congruent_2exp_p : t -> t -> int -> bool = "camlidl_mpz_mpz_congruent_2exp_p" (** {2 Exponentiation Functions} *) (** {{:http://gmplib.org/manual/Integer-Exponentiation.html#Integer-Exponentiation}C documentation} *) external _powm : t -> t -> t -> t -> unit = "camlidl_mpz_mpz__powm" external _powm_ui : t -> t -> int -> t -> unit = "camlidl_mpz_mpz__powm_ui" val powm : t -> t -> t -> modulo:t -> unit val powm_ui : t -> t -> int -> modulo:t -> unit external pow_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_pow_ui" external ui_pow_ui : t -> int -> int -> unit = "camlidl_mpz_mpz_ui_pow_ui" (** {2 Root Extraction Functions} *) (** {{:http://gmplib.org/manual/Integer-Roots.html#Integer-Roots}C documentation} *) external root : t -> t -> int -> bool = "camlidl_mpz_mpz_root" external sqrt : t -> t -> unit = "camlidl_mpz_mpz_sqrt" external _sqrtrem : t -> t -> t -> unit = "camlidl_mpz_mpz__sqrtrem" val sqrtrem : t -> remainder:t -> t -> unit external perfect_power_p : t -> bool = "camlidl_mpz_mpz_perfect_power_p" external perfect_square_p : t -> bool = "camlidl_mpz_mpz_perfect_square_p" (** {2 Number Theoretic Functions} *) (** {{:http://gmplib.org/manual/Number-Theoretic-Functions.html#Number-Theoretic-Functions}C documentation} *) external probab_prime_p : t -> int -> int = "camlidl_mpz_mpz_probab_prime_p" external nextprime : t -> t -> unit = "camlidl_mpz_mpz_nextprime" external gcd : t -> t -> t -> unit = "camlidl_mpz_mpz_gcd" external gcd_ui : t option -> t -> int -> int = "camlidl_mpz_mpz_gcd_ui" external _gcdext : t -> t -> t -> t -> t -> unit = "camlidl_mpz_mpz__gcdext" val gcdext : gcd:t -> alpha:t -> beta:t -> t -> t -> unit external lcm : t -> t -> t -> unit = "camlidl_mpz_mpz_lcm" external lcm_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_lcm_ui" external invert : t -> t -> t -> bool = "camlidl_mpz_mpz_invert" external jacobi : t -> t -> int = "camlidl_mpz_mpz_jacobi" external legendre : t -> t -> int = "camlidl_mpz_mpz_legendre" external kronecker : t -> t -> int = "camlidl_mpz_mpz_kronecker" external kronecker_si : t -> int -> int = "camlidl_mpz_mpz_kronecker_si" external si_kronecker : int -> t -> int = "camlidl_mpz_mpz_si_kronecker" external remove : t -> t -> t -> int = "camlidl_mpz_mpz_remove" external fac_ui : t -> int -> unit = "camlidl_mpz_mpz_fac_ui" external bin_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_bin_ui" external bin_uiui : t -> int -> int -> unit = "camlidl_mpz_mpz_bin_uiui" external fib_ui : t -> int -> unit = "camlidl_mpz_mpz_fib_ui" external fib2_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_fib2_ui" external lucnum_ui : t -> int -> unit = "camlidl_mpz_mpz_lucnum_ui" external lucnum2_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_lucnum2_ui" (** {2 Comparison Functions} *) (** {{:http://gmplib.org/manual/Integer-Comparisons.html#Integer-Comparisons}C documentation} *) external cmp : t -> t -> int = "camlidl_mpz_mpz_cmp" external cmp_d : t -> float -> int = "camlidl_mpz_mpz_cmp_d" external cmp_si : t -> int -> int = "camlidl_mpz_mpz_cmp_si" external cmpabs : t -> t -> int = "camlidl_mpz_mpz_cmpabs" external cmpabs_d : t -> float -> int = "camlidl_mpz_mpz_cmpabs_d" external cmpabs_ui : t -> int -> int = "camlidl_mpz_mpz_cmpabs_ui" external sgn : t -> int = "camlidl_mpz_mpz_sgn" (** {2 Logical and Bit Manipulation Functions} *) (** {{:http://gmplib.org/manual/Integer-Logic-and-Bit-Fiddling.html#Integer-Logic-and-Bit-Fiddling}C documentation} *) external gand : t -> t -> t -> unit = "camlidl_mpz_mpz_gand" external ior : t -> t -> t -> unit = "camlidl_mpz_mpz_ior" external xor : t -> t -> t -> unit = "camlidl_mpz_mpz_xor" external com : t -> t -> unit = "camlidl_mpz_mpz_com" external popcount : t -> int = "camlidl_mpz_mpz_popcount" external hamdist : t -> t -> int = "camlidl_mpz_mpz_hamdist" external scan0 : t -> int -> int = "camlidl_mpz_mpz_scan0" external scan1 : t -> int -> int = "camlidl_mpz_mpz_scan1" external setbit : t -> int -> unit = "camlidl_mpz_mpz_setbit" external clrbit : t -> int -> unit = "camlidl_mpz_mpz_clrbit" external tstbit : t -> int -> bool = "camlidl_mpz_mpz_tstbit" (** {2 Input and Output Functions: not interfaced} *) (** {2 Random Number Functions: see {!Gmp_random} module} *) (** {2 Integer Import and Export Functions} *) (** {{:ttp://gmplib.org/manual/Integer-Import-and-Export.html#Integer-Import-and-Export}C documentation} *) external _import : t -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t -> int -> int -> unit = "camlidl_mpz_mpz__import" external _export : t -> int -> int -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t = "camlidl_mpz_mpz__export" val import : dest:t -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t -> order:int -> endian:int -> unit val export : t -> order:int -> endian:int -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t (** {2 Miscellaneous Functions} *) (** {{:http://gmplib.org/manual/Miscellaneous-Integer-Functions.html#Miscellaneous-Integer-Functions}C documentation} *) (* Does it fit in an OCaml integer *) external fits_int_p : t -> bool = "camlidl_mpz_mpz_fits_int_p" external odd_p : t -> bool = "camlidl_mpz_mpz_odd_p" external even_p : t -> bool = "camlidl_mpz_mpz_even_p" external size : t -> int = "camlidl_mpz_mpz_size" external sizeinbase : t -> int -> int = "camlidl_mpz_mpz_sizeinbase" (* Limited relevance here *) external fits_ulong_p : t -> bool = "camlidl_mpz_mpz_fits_ulong_p" external fits_slong_p : t -> bool = "camlidl_mpz_mpz_fits_slong_p" external fits_uint_p : t -> bool = "camlidl_mpz_mpz_fits_uint_p" external fits_sint_p : t -> bool = "camlidl_mpz_mpz_fits_sint_p" external fits_ushort_p : t -> bool = "camlidl_mpz_mpz_fits_ushort_p" external fits_sshort_p : t -> bool = "camlidl_mpz_mpz_fits_sshort_p" apron-dist-0.9.10/mlgmpidl/Makefile.config.model0000640014525101416610000000453211251722332021357 0ustar bjeannetpopart# -*- mode: makefile -*- ###################################################################### # HAS Flags ###################################################################### # If defined to non-empty value, compiles also the MPFR interface HAS_MPFR=1 # If defined to non-empty value, generates dynamic libraries. # Do not forget to add -fPIC to CFLAGS and CFLAGS_DEBUG HAS_SHARED=1 ###################################################################### # Directories ###################################################################### # Where to *INSTALL* the package ($MLGMPIDL_PREFIX)/lib) MLGMPIDL_PREFIX = # Where to find GMP ($(GMP_PREFIX)/include, ($GMP_PREFIX)/lib) # GMP_PREFIX = /usr # Where to find MPFR ($(MPFR_PREFIX)/include, ($MPFR_PREFIX)/lib # (needed if HAS_MPFR=1) MPFR_PREFIX = /usr # Where to find OCAML ($(CAML_PREFIX)/bin, $(CAML_PREFIX)/lib/ocaml, ...) # CAML_PREFIX = /usr # Where to find CAMLIDL ($(CAMLIDL_PREFIX)/bin, $(CAMLIDL_PREFIX)/lib/ocaml, ...) # CAMLIDL_PREFIX = /usr ###################################################################### # Tools and Flags ###################################################################### # if defined to 1, the C stub lib referenced by the OCaml library is dynamic. MLGMPIDL_SHARED=1 # C compiler CC = gcc # C compilation flags CFLAGS = \ -Wcast-qual -Wswitch -Werror-implicit-function-declaration \ -Wall -Wextra -Wundef -Wbad-function-cast -Wcast-align -Wstrict-prototypes \ -Wno-unused \ -fPIC \ -std=c99 \ -O3 -UNDEBUG # C compilation flags in debug (or profile) mode CFLAGS_DEBUG = \ -Wcast-qual -Wswitch -Werror-implicit-function-declaration \ -Wall -Wextra -Wundef -Wbad-function-cast -Wcast-align -Wstrict-prototypes \ -Wno-unused \ -fPIC \ -std=c99 \ -g -O0 -DNDEBUG AR = ar RANLIB = ranlib SED = sed M4 = m4 INSTALL = install INSTALLd = install -d OCAMLC = $(CAML_PREFIX)/bin/ocamlc.opt OCAMLOPT = $(CAML_PREFIX)/bin/ocamlopt.opt # ocamlc compilation flags OCAMLFLAGS = -annot -g # ocamlopt compilation flags OCAMLOPTFLAGS = -annot -inline 20 OCAMLDEP = $(CAML_PREFIX)/bin/ocamldep OCAMLLEX = $(CAML_PREFIX)/bin/ocamllex.opt OCAMLYACC = $(CAML_PREFIX)/bin/ocamlyacc OCAMLDOC = $(CAML_PREFIX)/bin/ocamldoc.opt OCAMLMKTOP = $(CAML_PREFIX)/bin/ocamlmktop CAMLIDL = $(CAMLIDL_PREFIX)/bin/camlidl LATEX=latex DVIPDF=dvipdf MAKEINDEX=makeindex TEXI2DVI=texi2dvi TEXI2HTML=texi2html apron-dist-0.9.10/mlgmpidl/mpzf.ml0000640014525101416610000000336610555430260016670 0ustar bjeannetpopart(** GMP multi-precision integers, functional version *) (* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution *) open Mpz type t = Mpz.t let to_mpz : t -> Mpz.t = Mpz.init_set let of_mpz : Mpz.t -> t = Mpz.init_set let mpz (x:t) : Mpz.t = x let mpzf (x:Mpz.t) : t = x let of_string = Mpz.of_string let of_float = Mpz.of_float let of_int = Mpz.of_int let to_string = Mpz.to_string let to_float = Mpz.to_float let print = Mpz.print let wrap1 (f: Mpz.t -> 'a -> unit) = begin fun t -> let mpz = Mpz.init () in f mpz t; mpz end let wrap2 (f: Mpz.t -> 'a -> 'b -> unit) = begin fun t1 t2 -> let mpz = Mpz.init () in f mpz t1 t2; mpz end let wrap22 (f: Mpz.t -> Mpz.t -> 'a -> 'b -> unit) = begin fun t1 t2 -> let mpz1 = Mpz.init () in let mpz2 = Mpz.init () in f mpz1 mpz2 t1 t2; (mpz1,mpz2) end let add = wrap2 Mpz.add let add_int z n = let mpz = Mpz.init() in if n>0 then Mpz.add_ui mpz z n else Mpz.sub_ui mpz z (-n) ; mpz let sub = wrap2 Mpz.sub let sub_int z n = let mpz = Mpz.init() in if n>0 then Mpz.sub_ui mpz z n else Mpz.add_ui mpz z (-n) ; mpz let mul = wrap2 Mpz.mul let mul_int = wrap2 Mpz.mul_si let cdiv_q = wrap2 Mpz.cdiv_q let cdiv_r = wrap2 Mpz.cdiv_r let cdiv_qr = wrap22 Mpz.cdiv_qr let fdiv_q = wrap2 Mpz.fdiv_q let fdiv_r = wrap2 Mpz.fdiv_r let fdiv_qr = wrap22 Mpz.fdiv_qr let tdiv_q = wrap2 Mpz.tdiv_q let tdiv_r = wrap2 Mpz.tdiv_r let tdiv_qr = wrap22 Mpz.tdiv_qr let divexact = wrap2 Mpz.divexact let gmod = wrap2 Mpz.gmod let gcd = wrap2 Mpz.gcd let lcm = wrap2 Mpz.lcm let neg = wrap1 Mpz.neg let abs = wrap1 Mpz.abs let cmp = Mpz.cmp let cmp_int = Mpz.cmp_si let sgn = Mpz.sgn apron-dist-0.9.10/mlgmpidl/Makefile0000640014525101416610000002021211251742322017006 0ustar bjeannetpopartinclude Makefile.config #--------------------------------------- # Directories #--------------------------------------- SRCDIR = $(shell pwd) # # Installation directory prefix # MLGMPIDL_PREFIX = # PREFIX = $(MLGMPIDL_PREFIX) #--------------------------------------- # CAML part #--------------------------------------- OCAMLINC = ifeq ($(HAS_MPFR),) LDFLAGS = \ -L$(GMP_PREFIX)/lib -lgmp \ -L$(CAMLIDL_PREFIX)/lib/ocaml -lcamlidl RPATH=$(GMP_PREFIX)/lib:$(CAMLIDL_PREFIX)/lib/ocaml else LDFLAGS = \ -L$(MPFR_PREFIX)/lib -lmpfr \ -L$(GMP_PREFIX)/lib -lgmp \ -L$(CAMLIDL_PREFIX)/lib/ocaml -lcamlidl RPATH=$(MPFR_PREFIX)/lib:$(GMP_PREFIX)/lib:$(CAMLIDL_PREFIX)/lib/ocaml endif ifeq ($(HAS_SHARED),) OCAMLLDFLAGS = $(OCAMLOPTLDFLAGS) else OCAMLLDFLAGS = $(OCAMLOPTLDFLAGS) -dllib -lgmp_caml endif #--------------------------------------- # C part #--------------------------------------- ifeq ($(HAS_MPFR),) ICFLAGS = \ -DHAS_MPFR=$(HAS_MPFR) \ -I$(GMP_PREFIX)/include \ -I$(CAML_PREFIX)/lib/ocaml -I$(CAMLIDL_PREFIX)/lib/ocaml else ICFLAGS = \ -DHAS_MPFR=$(HAS_MPFR) \ -I$(GMP_PREFIX)/include \ -I$(MPFR_PREFIX)/include \ -I$(CAML_PREFIX)/lib/ocaml -I$(CAMLIDL_PREFIX)/lib/ocaml endif #--------------------------------------- # Files #--------------------------------------- ifeq ($(HAS_MPFR),) IDLMODULES = mpz mpq mpf gmp_random MLMODULES = mpz mpqf mpq mpqf mpf gmp_random else IDLMODULES = mpz mpq mpf mpfr gmp_random MLMODULES = mpz mpzf mpq mpqf mpf mpfr mpfrf gmp_random endif MLSRC = $(MLMODULES:%=%.mli) $(MLMODULES:%=%.ml) MLINT = $(MLMODULES:%=%.cmi) MLOBJ = $(MLMODULES:%=%.cmo) MLOBJx = $(MLMODULES:%=%.cmx) MLLIB_TOINSTALL = $(IDLMODULES:%=%.idl) $(MLMODULES:%=%.mli) $(MLMODULES:%=%.cmi) gmp.cma MLLIB_TOINSTALLx = $(MLMODULES:%=%.cmx) gmp.cmxa gmp.a CCMODULES = gmp_caml $(IDLMODULES:%=%_caml) CCSRC = gmp_caml.h $(CCMODULES:%=%.c) CCBIN_TOINSTALL = gmptop CCLIB_TOINSTALL = libgmp_caml.a libgmp_caml.so CCINC_TOINSTALL = gmp_caml.h #--------------------------------------- # Rules #--------------------------------------- all: $(MLSRC) $(MLINT) $(MLOBJ) $(MLOBJx) gmp.cma gmp.cmxa libgmp_caml.a ifneq ($(HAS_SHARED),) all: libgmp_caml.so endif mldep: $(MLSRC) ocamldep $(OCAMLINC) $(MLSRC) install: $(INSTALLd) $(PREFIX)/include $(PREFIX)/lib $(PREFIX)/bin $(INSTALL) gmp_caml.h $(PREFIX)/include for i in $(MLLIB_TOINSTALL) $(MLLIB_TOINSTALLx) $(CCLIB_TOINSTALL); do \ if test -f $$i; then $(INSTALL) $$i $(PREFIX)/lib; fi; \ done (cd $(PREFIX)/lib; if test -f libgmp_caml.so; then ln -s -f libgmp_caml.so dllgmp_caml.so; fi) #--------------------------------------- # Misc rules #--------------------------------------- uninstall: (cd $(PREFIX)/include; /bin/rm -f gmp_caml.h) (cd $(PREFIX)/lib; /bin/rm -f $(MLLIB_TOINSTALL) $(MLLIB_TOINSTALLx) $(CCLIB_TOINSTALL) *gmp_caml*.a *gmp_caml*.so) (cd $(PREFIX)/bin; /bin/rm -f $(CCBIN_TOINSTALL)) distclean: uninstall clean: /bin/rm -fr tmp html /bin/rm -f gmprun gmptop /bin/rm -f *.aux *.bbl *.ilg *.idx *.ind *.out *.blg *.dvi *.log *.toc *.ps *.html *.pdf /bin/rm -f *.o *.a *.cmi *.cmo *.cmx *.cmxa *.cma *.annot *.so session.byte session.opt session.opt2 tmp/* html/* /bin/rm -f ocamldoc.[cefkimoptv]* ocamldoc.sty mostlyclean: clean /bin/rm -f $(IDLMODULES:%=%.ml) $(IDLMODULES:%=%.mli) $(IDLMODULES:%=%_caml.c) tar: $(IDLMODULES:%=%.idl) $(MLSRC) $(CCSRC) Makefile Makefile.config.model README COPYING Changes session.ml mlgmpidl.tex sedscript_c sedscript_caml (cd ..; tar zcvf $(HOME)/mlgmpidl.tgz $(^:%=mlgmpidl/%)) dist: $(IDLMODULES:%=%.idl) $(MLSRC) $(CCSRC) Makefile Makefile.config.model README COPYING Changes session.ml mlgmpidl.tex mlgmpidl.pdf html sedscript_c sedscript_caml (cd ..; tar zcvf $(HOME)/mlgmpidl.tgz $(^:%=mlgmpidl/%)) #--------------------------------------- # Compilation Example #--------------------------------------- # bytecode session.byte: session.ml gmp.cma $(OCAMLC) -I $(PREFIX)/lib -o $@ bigarray.cma gmp.cma $< # native code session.opt: session.ml gmp.cmxa $(OCAMLOPT) -I $(PREFIX)/lib -cclib -L. -o $@ bigarray.cmxa gmp.cmxa $< # native code with noautolink session2.opt: session.ml $(OCAMLOPT) -noautolink -I $(PREFIX)/lib -o $@ bigarray.cmxa gmp.cmxa $< -ccopt "-L$(MLGMPIDL_PREFIX)/lib" -cclib "-lgmp_caml" \ -ccopt "-L$(MPFR_PREFIX)/lib" -cclib "-lmpfr" \ -ccopt "-L$(GMP_PREFIX)/lib" -cclib "-lgmp" \ -ccopt "-L$(CAML_PREFIX)/lib/ocaml" -cclib "-lbigarray" \ -ccopt "-L$(CAMLIDL_PREFIX)/lib/ocaml" -cclib "-lcamlidl" #--------------------------------------- # CAML rules #--------------------------------------- gmp.cma: $(MLOBJ) libgmp_caml.a $(OCAMLMKLIB) -ocamlc "$(OCAMLC)" -verbose -o gmp -oc gmp_caml $(MLOBJ) $(LDFLAGS) gmp.cmxa: $(MLOBJx) libgmp_caml.a $(OCAMLMKLIB) -ocamlopt "$(OCAMLOPT)" -verbose -o gmp -oc gmp_caml $(MLOBJx) $(LDFLAGS) $(RANLIB) gmp.a libgmp_caml.a: $(CCMODULES:%=%.o) $(AR) rc $@ $^ $(RANLIB) $@ libgmp_caml_debug.a: $(CCMODULES:%=%_debug.o) $(AR) rc $@ $^ $(RANLIB) $@ libgmp_caml.so: $(CCMODULES:%=%.o) $(CC) $(CFLAGS) -shared -o $@ $^ $(LDFLAGS) -Wl,-rpath,$(RPATH) libgmp_caml_debug.so: $(CCMODULES:%=%.o) $(CC) $(CFLAGS_DEBUG) -shared -o $@ $^ $(LDFLAGS) -Wl,-rpath,$(RPATH) dllgmp_caml.so: libgmp_caml.so ln -s $^ $@ dllgmp_caml_debug.so: libgmp_caml_debug.so ln -s $^ $@ #--------------------------------------- # TEX and HTML rules #--------------------------------------- .PHONY: html mlgmpidl.dvi mlgmpidl.pdf: mlgmpidl.dvi $(DVIPDF) mlgmpidl.dvi mlgmpidl.dvi: introduction.mli $(MLMODULES:%=%.mli) $(OCAMLDOC) $(OCAMLINC) \ -latextitle 1,chapter -latextitle 2,section -latextitle 3,subsection -latextitle 4,subsubsection -latextitle 5,paragraph -latextitle 6,subparagraph -noheader -notrailer -latex -o ocamldoc.tex $^ $(LATEX) mlgmpidl $(MAKEINDEX) mlgmpidl $(LATEX) mlgmpidl $(LATEX) mlgmpidl html: introduction.mli $(MLMODULES:%=%.mli) mkdir -p html $(OCAMLDOC) $(OCAMLINC) -html -d html -colorize-code $^ #-------------------------------------------------------------- # IMPLICIT RULES AND DEPENDENCIES #-------------------------------------------------------------- .SUFFIXES: .tex .fig .c .h .o .ml .mli .cmi .cmo .cmx .idl _debug.o _prof.o _caml.c #----------------------------------- # IDL #----------------------------------- # sed -f sedscript_caml allows to remove prefixes generated by camlidl # and to modify type name # sed -f sedscript_c allows to deal with GMP peculiarity for types # grep --extended-regexp '^(.)+$$' removes blanks lines rebuild: mkdir -p tmp for i in $(IDLMODULES); do \ echo "module $$i"; \ cp $${i}.idl tmp/$${i}.idl; \ $(CAMLIDL) -prepro cpp -D HAS_MPFR=$(HAS_MPFR) -no-include -I $(SRCDIR) tmp/$${i}.idl; \ $(SED) -f sedscript_c tmp/$${i}_stubs.c >$${i}_caml.c; \ $(SED) -f sedscript_caml tmp/$${i}.ml >$${i}.ml; \ $(SED) -f sedscript_caml tmp/$${i}.mli >$${i}.mli; \ done #----------------------------------- # C #----------------------------------- %.o: %.c gmp_caml.h $(CC) $(CFLAGS) $(ICFLAGS) -c -o $@ $< %_debug.o: %.c gmp_caml.h $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -c -o $@ $< #----------------------------------- # CAML #----------------------------------- %.cmi: %.mli $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -c $< %.cmo: %.ml %.cmi $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -c $< %.cmx: %.ml %.cmi $(OCAMLOPT) $(OCAMLOPTFLAGS) $(OCAMLINC) -c $< #----------------------------------- # Dependencies #----------------------------------- gmp_random.cmo: mpz.cmi mpf.cmi gmp_random.cmi gmp_random.cmx: mpz.cmx mpf.cmx gmp_random.cmi mpf.cmo: mpz.cmi mpq.cmi mpf.cmi mpf.cmx: mpz.cmx mpq.cmx mpf.cmi ifneq ($(HAS_MPFR),) mpfr.cmo: mpz.cmi mpq.cmi mpqf.cmi mpf.cmi mpfr.cmi mpfr.cmx: mpz.cmx mpq.cmx mpqf.cmx mpf.cmx mpfr.cmi mpfr.cmi: mpz.cmi mpq.cmi mpqf.cmi mpf.cmi mpfrf.cmo: mpzf.cmi mpqf.cmi mpfr.cmi mpfrf.cmi mpfrf.cmx: mpzf.cmx mpqf.cmx mpfr.cmx mpfrf.cmi mpfrf.cmi: mpzf.cmi mpz.cmi mpqf.cmi mpq.cmi mpfr.cmi endif mpqf.cmo: mpzf.cmi mpz.cmi mpq.cmi mpqf.cmi mpqf.cmx: mpzf.cmx mpz.cmx mpq.cmx mpqf.cmi mpq.cmo: mpz.cmi mpq.cmi mpq.cmx: mpz.cmx mpq.cmi mpzf.cmo: mpz.cmi mpzf.cmi mpzf.cmx: mpz.cmx mpzf.cmi mpz.cmo: mpz.cmi mpz.cmx: mpz.cmi session.cmo: mpq.cmi session.cmx: mpq.cmx gmp_random.cmi: mpz.cmi mpf.cmi mpf.cmi: mpz.cmi mpq.cmi mpqf.cmi: mpzf.cmi mpz.cmi mpq.cmi mpq.cmi: mpz.cmi mpzf.cmi: mpz.cmi apron-dist-0.9.10/mlgmpidl/mpfr.mli0000640014525101416610000003207311252216514017025 0ustar bjeannetpopart(* File generated from mpfr.idl *) (* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t and round = | Near | Zero | Up | Down (** MPFR multiprecision floating-point numbers *) (** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x]. These functions are as efficient as their C counterpart: they do not imply additional memory allocation. *) (** {2 Pretty printing} *) val print : Format.formatter -> t -> unit val print_round : Format.formatter -> round -> unit val string_of_round : round -> string (** {2 Rounding Modes} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Rounding-Related-Functions}C documentation} *) external set_default_rounding_mode : round -> unit = "camlidl_mpfr_mpfr_set_default_rounding_mode" external get_default_rounding_mode : unit -> round = "camlidl_mpfr_mpfr_get_default_rounding_mode" external round_prec : t -> round -> int -> int = "camlidl_mpfr_mpfr_round_prec" (** {2 Exceptions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Exception-Related-Functions}C documentation} *) external get_emin : unit -> int = "camlidl_mpfr_mpfr_get_emin" external get_emax : unit -> int = "camlidl_mpfr_mpfr_get_emax" external set_emin : int -> unit = "camlidl_mpfr_mpfr_set_emin" external set_emax : int -> unit = "camlidl_mpfr_mpfr_set_emax" external check_range : t -> int -> round -> int = "camlidl_mpfr_mpfr_check_range" external clear_underflow : unit -> unit = "camlidl_mpfr_mpfr_clear_underflow" external clear_overflow : unit -> unit = "camlidl_mpfr_mpfr_clear_overflow" external clear_nanflag : unit -> unit = "camlidl_mpfr_mpfr_clear_nanflag" external clear_inexflag : unit -> unit = "camlidl_mpfr_mpfr_clear_inexflag" external clear_flags : unit -> unit = "camlidl_mpfr_mpfr_clear_flags" external underflow_p : unit -> bool = "camlidl_mpfr_mpfr_underflow_p" external overflow_p : unit -> bool = "camlidl_mpfr_mpfr_overflow_p" external nanflag_p : unit -> bool = "camlidl_mpfr_mpfr_nanflag_p" external inexflag_p : unit -> bool = "camlidl_mpfr_mpfr_inexflag_p" (** {2 Initialization Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Initialization-Functions}C documentation} *) external set_default_prec : int -> unit = "camlidl_mpfr_mpfr_set_default_prec" external get_default_prec : unit -> int = "camlidl_mpfr_mpfr_get_default_prec" external init : unit -> t = "camlidl_mpfr_mpfr_init" external init2 : int -> t = "camlidl_mpfr_mpfr_init2" external get_prec : t -> int = "camlidl_mpfr_mpfr_get_prec" external set_prec : t -> int -> unit = "camlidl_mpfr_mpfr_set_prec" external set_prec_raw : t -> int -> unit = "camlidl_mpfr_mpfr_set_prec_raw" (** {2 Assignment Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Assignment-Functions}C documentation} *) external set : t -> t -> round -> int = "camlidl_mpfr_mpfr_set" external set_si : t -> int -> round -> int = "camlidl_mpfr_mpfr_set_si" external set_d : t -> float -> round -> int = "camlidl_mpfr_mpfr_set_d" external set_z : t -> Mpz.t -> round -> int = "camlidl_mpfr_mpfr_set_z" external set_q : t -> Mpq.t -> round -> int = "camlidl_mpfr_mpfr_set_q" external _set_str : t -> string -> int -> round -> unit = "camlidl_mpfr_mpfr__set_str" val set_str : t -> string -> base:int -> round -> unit external set_f : t -> Mpf.t -> round -> int = "camlidl_mpfr_mpfr_set_f" external set_si_2exp : t -> int -> int -> round -> int = "camlidl_mpfr_mpfr_set_si_2exp" external set_inf : t -> int -> unit = "camlidl_mpfr_mpfr_set_inf" external set_nan : t -> unit = "camlidl_mpfr_mpfr_set_nan" external swap : t -> t -> unit = "camlidl_mpfr_mpfr_swap" (** {2 Combined Initialization and Assignment Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Combined-Initialization-and-Assignment-Functions}C documentation} *) external init_set : t -> round -> int * t = "camlidl_mpfr_mpfr_init_set" external init_set_si : int -> round -> int * t = "camlidl_mpfr_mpfr_init_set_si" external init_set_d : float -> round -> int * t = "camlidl_mpfr_mpfr_init_set_d" external init_set_f : Mpf.t -> round -> int * t = "camlidl_mpfr_mpfr_init_set_f" external init_set_z : Mpz.t -> round -> int * t = "camlidl_mpfr_mpfr_init_set_z" external init_set_q : Mpq.t -> round -> int * t = "camlidl_mpfr_mpfr_init_set_q" external _init_set_str : string -> int -> round -> t = "camlidl_mpfr_mpfr__init_set_str" val init_set_str : string -> base:int -> round -> t (** {2 Conversion Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Conversion-Functions}C documentation} *) external get_d : t -> round -> float = "camlidl_mpfr_mpfr_get_d" external get_d1 : t -> float = "camlidl_mpfr_mpfr_get_d1" external get_z_exp : Mpz.t -> t -> int = "camlidl_mpfr_mpfr_get_z_exp" external get_z : Mpz.t -> t -> round -> unit = "camlidl_mpfr_mpfr_get_z" external _get_str : int -> int -> t -> round -> string * int = "camlidl_mpfr_mpfr__get_str" val get_str : base:int -> digits:int -> t -> round -> string * int (** {2 User Conversions} *) (** These functionss are additions to or renaming of functions offered by the C library. *) val to_string : t -> string val to_float : ?round:round -> t -> float val to_mpq : t -> Mpq.t val of_string : string -> round -> t val of_float : float -> round -> t val of_int : int -> round -> t val of_frac : int -> int -> round -> t val of_mpz : Mpz.t -> round -> t val of_mpz2 : Mpz.t -> Mpz.t -> round -> t val of_mpq : Mpq.t -> round -> t (** {2 Basic Arithmetic Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Basic-Arithmetic-Functions}C documentation} *) external add : t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_add" external add_ui : t -> t -> int -> round -> int = "camlidl_mpfr_mpfr_add_ui" external add_z : t -> t -> Mpz.t -> round -> int = "camlidl_mpfr_mpfr_add_z" external add_q : t -> t -> Mpq.t -> round -> int = "camlidl_mpfr_mpfr_add_q" external sub : t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_sub" external ui_sub : t -> int -> t -> round -> int = "camlidl_mpfr_mpfr_ui_sub" external sub_ui : t -> t -> int -> round -> int = "camlidl_mpfr_mpfr_sub_ui" external sub_z : t -> t -> Mpz.t -> round -> int = "camlidl_mpfr_mpfr_sub_z" external sub_q : t -> t -> Mpq.t -> round -> int = "camlidl_mpfr_mpfr_sub_q" external mul : t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_mul" external mul_ui : t -> t -> int -> round -> int = "camlidl_mpfr_mpfr_mul_ui" external mul_z : t -> t -> Mpz.t -> round -> int = "camlidl_mpfr_mpfr_mul_z" external mul_q : t -> t -> Mpq.t -> round -> int = "camlidl_mpfr_mpfr_mul_q" external mul_2ui : t -> t -> int -> round -> int = "camlidl_mpfr_mpfr_mul_2ui" external mul_2si : t -> t -> int -> round -> int = "camlidl_mpfr_mpfr_mul_2si" external mul_2exp : t -> t -> int -> round -> int = "camlidl_mpfr_mpfr_mul_2exp" external div : t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_div" external ui_div : t -> int -> t -> round -> int = "camlidl_mpfr_mpfr_ui_div" external div_ui : t -> t -> int -> round -> int = "camlidl_mpfr_mpfr_div_ui" external div_z : t -> t -> Mpz.t -> round -> int = "camlidl_mpfr_mpfr_div_z" external div_q : t -> t -> Mpq.t -> round -> int = "camlidl_mpfr_mpfr_div_q" external div_2ui : t -> t -> int -> round -> int = "camlidl_mpfr_mpfr_div_2ui" external div_2si : t -> t -> int -> round -> int = "camlidl_mpfr_mpfr_div_2si" val div_2exp : t -> t -> int -> round -> int external sqrt : t -> t -> round -> bool = "camlidl_mpfr_mpfr_sqrt" external sqrt_ui : t -> int -> round -> bool = "camlidl_mpfr_mpfr_sqrt_ui" external pow_ui : t -> t -> int -> round -> bool = "camlidl_mpfr_mpfr_pow_ui" external pow_si : t -> t -> int -> round -> bool = "camlidl_mpfr_mpfr_pow_si" external ui_pow_ui : t -> int -> int -> round -> bool = "camlidl_mpfr_mpfr_ui_pow_ui" external ui_pow : t -> int -> t -> round -> bool = "camlidl_mpfr_mpfr_ui_pow" external pow : t -> t -> t -> round -> bool = "camlidl_mpfr_mpfr_pow" external neg : t -> t -> round -> int = "camlidl_mpfr_mpfr_neg" external abs : t -> t -> round -> int = "camlidl_mpfr_mpfr_abs" (** {2 Comparison Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Comparison-Functions}C documentation} *) external cmp : t -> t -> int = "camlidl_mpfr_mpfr_cmp" external cmp_si : t -> int -> int = "camlidl_mpfr_mpfr_cmp_si" external cmp_si_2exp : t -> int -> int -> int = "camlidl_mpfr_mpfr_cmp_si_2exp" external sgn : t -> int = "camlidl_mpfr_mpfr_sgn" external _equal : t -> t -> int -> bool = "camlidl_mpfr_mpfr__equal" val equal : t -> t -> bits:int -> bool external nan_p : t -> bool = "camlidl_mpfr_mpfr_nan_p" external inf_p : t -> bool = "camlidl_mpfr_mpfr_inf_p" external number_p : t -> bool = "camlidl_mpfr_mpfr_number_p" external reldiff : t -> t -> t -> round -> unit = "camlidl_mpfr_mpfr_reldiff" (** {2 Special Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Special-Functions}C documentation} *) external log : t -> t -> round -> int = "camlidl_mpfr_mpfr_log" external log2 : t -> t -> round -> int = "camlidl_mpfr_mpfr_log2" external log10 : t -> t -> round -> int = "camlidl_mpfr_mpfr_log10" external exp : t -> t -> round -> int = "camlidl_mpfr_mpfr_exp" external exp2 : t -> t -> round -> int = "camlidl_mpfr_mpfr_exp2" external exp10 : t -> t -> round -> int = "camlidl_mpfr_mpfr_exp10" external cos : t -> t -> round -> int = "camlidl_mpfr_mpfr_cos" external sin : t -> t -> round -> int = "camlidl_mpfr_mpfr_sin" external tan : t -> t -> round -> int = "camlidl_mpfr_mpfr_tan" external sec : t -> t -> round -> int = "camlidl_mpfr_mpfr_sec" external csc : t -> t -> round -> int = "camlidl_mpfr_mpfr_csc" external cot : t -> t -> round -> int = "camlidl_mpfr_mpfr_cot" external sin_cos : t -> t -> t -> round -> bool = "camlidl_mpfr_mpfr_sin_cos" external acos : t -> t -> round -> int = "camlidl_mpfr_mpfr_acos" external asin : t -> t -> round -> int = "camlidl_mpfr_mpfr_asin" external atan : t -> t -> round -> int = "camlidl_mpfr_mpfr_atan" external atan2 : t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_atan2" external cosh : t -> t -> round -> int = "camlidl_mpfr_mpfr_cosh" external sinh : t -> t -> round -> int = "camlidl_mpfr_mpfr_sinh" external tanh : t -> t -> round -> int = "camlidl_mpfr_mpfr_tanh" external sech : t -> t -> round -> int = "camlidl_mpfr_mpfr_sech" external csch : t -> t -> round -> int = "camlidl_mpfr_mpfr_csch" external coth : t -> t -> round -> int = "camlidl_mpfr_mpfr_coth" external acosh : t -> t -> round -> int = "camlidl_mpfr_mpfr_acosh" external asinh : t -> t -> round -> int = "camlidl_mpfr_mpfr_asinh" external atanh : t -> t -> round -> int = "camlidl_mpfr_mpfr_atanh" external fac_ui : t -> int -> round -> int = "camlidl_mpfr_mpfr_fac_ui" external log1p : t -> t -> round -> int = "camlidl_mpfr_mpfr_log1p" external expm1 : t -> t -> round -> int = "camlidl_mpfr_mpfr_expm1" external eint : t -> t -> round -> int = "camlidl_mpfr_mpfr_eint" external gamma : t -> t -> round -> int = "camlidl_mpfr_mpfr_gamma" external lngamma : t -> t -> round -> int = "camlidl_mpfr_mpfr_lngamma" external zeta : t -> t -> round -> int = "camlidl_mpfr_mpfr_zeta" external erf : t -> t -> round -> int = "camlidl_mpfr_mpfr_erf" external erfc : t -> t -> round -> int = "camlidl_mpfr_mpfr_erfc" external fma : t -> t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_fma" external agm : t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_agm" external hypot : t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_hypot" external const_log2 : t -> round -> int = "camlidl_mpfr_mpfr_const_log2" external const_pi : t -> round -> int = "camlidl_mpfr_mpfr_const_pi" external const_euler : t -> round -> int = "camlidl_mpfr_mpfr_const_euler" external const_catalan : t -> round -> int = "camlidl_mpfr_mpfr_const_catalan" (** {2 Input and Output Functions: not interfaced} *) (** {2 Miscellaneous Float Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Rounding-Related-Functions}C documentation} *) external rint : t -> t -> round -> int = "camlidl_mpfr_mpfr_rint" external ceil : t -> t -> int = "camlidl_mpfr_mpfr_ceil" external floor : t -> t -> int = "camlidl_mpfr_mpfr_floor" external round : t -> t -> int = "camlidl_mpfr_mpfr_round" external trunc : t -> t -> int = "camlidl_mpfr_mpfr_trunc" external integer_p : t -> bool = "camlidl_mpfr_mpfr_integer_p" external nexttoward : t -> t -> unit = "camlidl_mpfr_mpfr_nexttoward" external nextabove : t -> unit = "camlidl_mpfr_mpfr_nextabove" external nextbelow : t -> unit = "camlidl_mpfr_mpfr_nextbelow" external min : t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_min" external max : t -> t -> t -> round -> int = "camlidl_mpfr_mpfr_max" external get_exp : t -> int = "camlidl_mpfr_mpfr_get_exp" external set_exp : t -> int -> int = "camlidl_mpfr_mpfr_set_exp" apron-dist-0.9.10/mlgmpidl/mpqf.mli0000640014525101416610000000501311165125334017020 0ustar bjeannetpopart(** GMP multi-precision rationals, functional version *) (* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution *) (** Functions in this module has a functional semantics, unlike the corresponding functions in {!Mpq}. These functions are less efficients, due to the additional memory allocation neded for the result. *) type t (** multi-precision rationals *) val to_mpq : t -> Mpq.t val of_mpq : Mpq.t -> t (** Safe conversion from and to Mpq.t. There is no sharing between the argument and the result. *) val mpq : t -> Mpq.t val mpqf : Mpq.t -> t (** Unsafe conversion from and to Mpq.t. The argument and the result actually share the same number: be cautious ! *) (* ====================================================================== *) (** {2 Pretty-printing} *) (* ====================================================================== *) val print : Format.formatter -> t -> unit (* ====================================================================== *) (** {2 Constructors} *) (* ====================================================================== *) val of_string : string -> t val of_float : float -> t val of_int : int -> t val of_frac : int -> int -> t val of_mpz : Mpz.t -> t val of_mpz2 : Mpz.t -> Mpz.t -> t val of_mpzf : Mpzf.t -> t val of_mpzf2 : Mpzf.t -> Mpzf.t -> t (* ====================================================================== *) (** {2 Conversions} *) (* ====================================================================== *) val to_string : t -> string val to_float : t -> float val to_mpzf2 : t -> Mpzf.t * Mpzf.t (* ====================================================================== *) (** {2 Arithmetic Functions} *) (* ====================================================================== *) val add : t -> t -> t val sub : t -> t -> t val mul : t -> t -> t val div : t -> t -> t val neg : t -> t val abs : t -> t val inv : t -> t val equal : t -> t -> bool (* ====================================================================== *) (** {2 Comparison Functions} *) (* ====================================================================== *) val cmp : t -> t -> int val cmp_int : t -> int -> int val cmp_frac : t -> int -> int -> int val sgn : t -> int (* ====================================================================== *) (** {2 Extraction Functions} *) (* ====================================================================== *) val get_num : t -> Mpzf.t val get_den : t -> Mpzf.t apron-dist-0.9.10/mlgmpidl/mpqf.ml0000640014525101416610000000264111023223116016641 0ustar bjeannetpopart(** GMP multi-precision rationals, functional version *) (* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution *) open Mpq type t = Mpq.t let to_mpq = Mpq.init_set let of_mpq = Mpq.init_set let mpq (x:t) : Mpq.t = x let mpqf (x:Mpq.t) : t = x let of_mpz = Mpq.init_set_z let of_mpz2 = Mpq.of_mpz2 let of_string = Mpq.of_string let of_float = Mpq.of_float let of_int = Mpq.of_int let of_frac = Mpq.of_frac let of_mpzf (z:Mpzf.t) = Mpq.of_mpz (Mpzf.mpz z) let of_mpzf2 (num:Mpzf.t) (den:Mpzf.t) = Mpq.of_mpz2 (Mpzf.mpz num) (Mpzf.mpz den) let to_string = Mpq.to_string let to_float = Mpq.to_float let print = Mpq.print let wrap1 (f: Mpq.t -> 'a -> unit) = begin fun t -> let mpq = Mpq.init () in f mpq t; mpq end let wrap2 (f: Mpq.t -> 'a -> 'b -> unit) = begin fun t1 t2 -> let mpq = Mpq.init () in f mpq t1 t2; mpq end let add = wrap2 Mpq.add let sub = wrap2 Mpq.sub let mul = wrap2 Mpq.mul let div = wrap2 Mpq.div let neg = wrap1 Mpq.neg let abs = wrap1 Mpq.abs let inv = wrap1 Mpq.inv let equal = Mpq.equal let cmp = Mpq.cmp let cmp_int q n = Mpq.cmp_si q n 1 let cmp_frac = Mpq.cmp_si let sgn = Mpq.sgn let get_num q = let num = Mpz.init() in Mpq.get_num num q; Mpzf.mpzf num let get_den q = let den = Mpz.init() in Mpq.get_den den q; Mpzf.mpzf den let to_mpzf2 q = (get_num q, get_den q) apron-dist-0.9.10/mlgmpidl/gmp_caml.c0000640014525101416610000003027510645155440017310 0ustar bjeannetpopart/* ********************************************************************** */ /* gmp_caml.c */ /* ********************************************************************** */ /* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include "caml/fail.h" #include "caml/alloc.h" #include "caml/custom.h" #include "caml/memory.h" #include "caml/callback.h" #include "caml/camlidlruntime.h" #include "gmp_caml.h" /* ********************************************************************** */ /* I. Custom datatypes: fastest coding */ /* ********************************************************************** */ /* ====================================================================== */ /* I.1 mpz_t */ /* ====================================================================== */ void camlidl_custom_mpz_finalize(value val) { __mpz_struct* mpz = (__mpz_struct*)(Data_custom_val(val)); mpz_clear(mpz); } int camlidl_custom_mpz_compare(value val1, value val2) { int res; __mpz_struct* mpz1; __mpz_struct* mpz2; mpz1 = (__mpz_struct*)(Data_custom_val(val1)); mpz2 = (__mpz_struct*)(Data_custom_val(val2)); res = mpz_cmp(mpz1,mpz2); res = res > 0 ? 1 : res==0 ? 0 : -1; return res; } long camlidl_custom_mpz_hash(value val) { __mpz_struct* mpz = (__mpz_struct*)(Data_custom_val(val)); long hash = mpz_get_si(mpz); return hash; } struct custom_operations camlidl_custom_mpz = { "camlidl_gmp_custom_mpz", &camlidl_custom_mpz_finalize, &camlidl_custom_mpz_compare, &camlidl_custom_mpz_hash, custom_serialize_default, custom_deserialize_default }; value camlidl_mpz_ptr_c2ml(mpz_ptr* mpz) { value val; val = alloc_custom(&camlidl_custom_mpz, sizeof(__mpz_struct), 0, 1); *(((__mpz_struct*)(Data_custom_val(val)))) = *(*mpz); return val; } void camlidl_mpz_ptr_ml2c(value val, mpz_ptr* mpz) { *mpz = (mpz_ptr)(Data_custom_val(val)); } void camlidl_mpz_ml2c(value val, __mpz_struct* mpz) { *mpz = *((mpz_ptr)(Data_custom_val(val))); } /* ====================================================================== */ /* I.2 mpq_t */ /* ====================================================================== */ void camlidl_custom_mpq_finalize(value val) { __mpq_struct* mpq = (__mpq_struct*)(Data_custom_val(val)); mpq_clear(mpq); } int camlidl_custom_mpq_compare(value val1, value val2) { int res; __mpq_struct* mpq1; __mpq_struct* mpq2; mpq1 = (__mpq_struct*)(Data_custom_val(val1)); mpq2 = (__mpq_struct*)(Data_custom_val(val2)); res = mpq_cmp(mpq1,mpq2); res = res > 0 ? 1 : res==0 ? 0 : -1; return res; } long camlidl_custom_mpq_hash(value val) { __mpq_struct* mpq = (__mpq_struct*)(Data_custom_val(val)); unsigned long num = mpz_get_ui(mpq_numref(mpq)); unsigned long den = mpz_get_ui(mpq_denref(mpq)); long hash; if (num==0) hash = 0; else if (den==0) hash = num>0 ? LONG_MAX : LONG_MIN; else hash = (labs(num) 0 ? 1 : res==0 ? 0 : -1; return res; } long camlidl_custom_mpf_hash(value val) { __mpf_struct* mpf = (__mpf_struct*)(Data_custom_val(val)); long hash; double d; signed long int exp; d = mpf_get_d_2exp (&exp, mpf); hash = (long)d; return hash; } struct custom_operations camlidl_custom_mpf = { "camlidl_gmp_custom_mpf", &camlidl_custom_mpf_finalize, &camlidl_custom_mpf_compare, &camlidl_custom_mpf_hash, custom_serialize_default, custom_deserialize_default }; value camlidl_mpf_ptr_c2ml(mpf_ptr* mpf) { value val; val = alloc_custom(&camlidl_custom_mpf, sizeof(__mpf_struct), 0, 1); *(((__mpf_struct*)(Data_custom_val(val)))) = *(*mpf); return val; } void camlidl_mpf_ptr_ml2c(value val, mpf_ptr* mpf) { *mpf = (mpf_ptr)(Data_custom_val(val)); } void camlidl_mpf_ml2c(value val, __mpf_struct* mpf) { *mpf = *((mpf_ptr)(Data_custom_val(val))); } int mpf_fits_int_p (mpf_t OP) { if (mpf_fits_slong_p(OP)){ long v = mpf_get_si(OP); return (Min_long <= v && v <= Max_long); } else { return 0; } } /* ====================================================================== */ /* I.4 mpfr_t */ /* ====================================================================== */ #if defined(HAS_MPFR) #if HAS_MPFR!=0 void camlidl_custom_mpfr_finalize(value val) { __mpfr_struct* mpfr = (__mpfr_struct*)(Data_custom_val(val)); mpfr_clear(mpfr); } int camlidl_custom_mpfr_compare(value val1, value val2) { int res; __mpfr_struct* mpfr1; __mpfr_struct* mpfr2; mpfr1 = (__mpfr_struct*)(Data_custom_val(val1)); mpfr2 = (__mpfr_struct*)(Data_custom_val(val2)); res = mpfr_cmp(mpfr1,mpfr2); res = res > 0 ? 1 : res==0 ? 0 : -1; return res; } long camlidl_custom_mpfr_hash(value val) { __mpfr_struct* mpfr = (__mpfr_struct*)(Data_custom_val(val)); long hash; double d; int exp; d = mpfr_get_d(mpfr, GMP_RNDN); d = frexp(d,&exp); hash = (long)d; return hash; } struct custom_operations camlidl_custom_mpfr = { "camlidl_gmp_custom_mpfr", &camlidl_custom_mpfr_finalize, &camlidl_custom_mpfr_compare, &camlidl_custom_mpfr_hash, custom_serialize_default, custom_deserialize_default }; value camlidl_mpfr_ptr_c2ml(mpfr_ptr* mpfr) { value val; val = alloc_custom(&camlidl_custom_mpfr, sizeof(__mpfr_struct), 0, 1); *(((__mpfr_struct*)(Data_custom_val(val)))) = *(*mpfr); return val; } void camlidl_mpfr_ptr_ml2c(value val, mpfr_ptr* mpfr) { *mpfr = (mpfr_ptr)(Data_custom_val(val)); } void camlidl_mpfr_ml2c(value val, __mpfr_struct* mpfr) { *mpfr = *((mpfr_ptr)(Data_custom_val(val))); } #endif #endif /* ====================================================================== */ /* I.5 gmp_randstate_t */ /* ====================================================================== */ void camlidl_custom_gmp_randstate_finalize(value val) { __gmp_randstate_struct* gmp_randstate = (__gmp_randstate_struct*)(Data_custom_val(val)); gmp_randclear(gmp_randstate); } struct custom_operations camlidl_custom_gmp_randstate = { "camlidl_gmp_custom_randstate", &camlidl_custom_gmp_randstate_finalize, custom_compare_default, custom_hash_default, custom_serialize_default, custom_deserialize_default }; value camlidl_gmp_randstate_ptr_c2ml(gmp_randstate_ptr* gmp_randstate) { value val; val = alloc_custom(&camlidl_custom_gmp_randstate, sizeof(__gmp_randstate_struct), 0, 1); *((__gmp_randstate_struct*)(Data_custom_val(val))) = *(*gmp_randstate); return val; } void camlidl_gmp_randstate_ptr_ml2c(value val, gmp_randstate_ptr* gmp_randstate) { *gmp_randstate = (gmp_randstate_ptr)(Data_custom_val(val)); } /* ********************************************************************** */ /* II. Custom datatypes: more standard coding */ /* ********************************************************************** */ /* ====================================================================== */ /* II.1 mpz2_t */ /* ====================================================================== */ /* void camlidl_custom_mpz2_finalize(value val) { CAMLparam1(val); __mpz_struct** mpz = (__mpz_struct**)(Data_custom_val(val)); mpz_clear(*mpz); free(*mpz); } int camlidl_custom_mpz2_compare(value val1, value val2) { CAMLparam2(val1,val2); int res; __mpz_struct** mpz1; __mpz_struct** mpz2; mpz1 = (__mpz_struct**)(Data_custom_val(val1)); mpz2 = (__mpz_struct**)(Data_custom_val(val2)); res = mpz_cmp(*mpz1,*mpz2); res = res > 0 ? 1 : res==0 ? 0 : -1; CAMLreturn(res); } long camlidl_custom_mpz2_hash(value val) { CAMLparam1(val); __mpz_struct** mpz = (__mpz_struct**)(Data_custom_val(val)); long hash = mpz_get_si(*mpz); CAMLreturn(hash); } struct custom_operations camlidl_custom_mpz2 = { "camlidl_gmp_custom_mpz2", &camlidl_custom_mpz2_finalize, &camlidl_custom_mpz2_compare, &camlidl_custom_mpz2_hash, custom_serialize_default, custom_deserialize_default }; value camlidl_mpz2_ptr_c2ml(mpz_ptr* mpz) { value val; __mpz_struct* p; p = malloc(sizeof(__mpz_struct)); *p = *(*mpz); val = alloc_custom(&camlidl_custom_mpz2, sizeof(__mpz_struct*), 0, 1); *(((__mpz_struct**)(Data_custom_val(val)))) = p; return val; } void camlidl_mpz2_ptr_ml2c(value val, mpz_ptr* mpz) { *mpz = *(__mpz_struct**)(Data_custom_val(val)); } */ /* ====================================================================== */ /* II.2 mpq2_t */ /* ====================================================================== */ /* void camlidl_custom_mpq2_finalize(value val) { CAMLparam1(val); __mpq_struct** mpq = (__mpq_struct**)(Data_custom_val(val)); mpq_clear(*mpq); } int camlidl_custom_mpq2_compare(value val1, value val2) { CAMLparam2(val1,val2); int res; __mpq_struct** mpq1; __mpq_struct** mpq2; mpq1 = (__mpq_struct**)(Data_custom_val(val1)); mpq2 = (__mpq_struct**)(Data_custom_val(val2)); res = mpq_cmp(*mpq1,*mpq2); res = res > 0 ? 1 : res==0 ? 0 : -1; CAMLreturn(res); } long camlidl_custom_mpq2_hash(value val) { CAMLparam1(val); __mpq_struct** mpq = (__mpq_struct**)(Data_custom_val(val)); unsigned long num = mpz_get_ui(mpq_numref(*mpq)); unsigned long den = mpz_get_ui(mpq_denref(*mpq)); long hash = num unit = "camlidl_mpq_mpq_canonicalize" (** {2 Pretty printing} *) val print : Format.formatter -> t -> unit (** {2 Initialization and Assignment Functions} *) (** {{:http://gmplib.org/manual/Initializing-Rationals.html#Initializing-Rationals}C documentation} *) external init : unit -> t = "camlidl_mpq_mpq_init" external set : t -> t -> unit = "camlidl_mpq_mpq_set" external set_z : t -> Mpz.t -> unit = "camlidl_mpq_mpq_set_z" external set_si : t -> int -> int -> unit = "camlidl_mpq_mpq_set_si" external _set_str : t -> string -> int -> unit = "camlidl_mpq_mpq__set_str" val set_str : t -> string -> base:int -> unit external swap : t -> t -> unit = "camlidl_mpq_mpq_swap" (** {2 Additional Initialization and Assignements functions} *) (** These functions are additions to or renaming of functions offered by the C library. *) val init_set : t -> t val init_set_z : Mpz.t -> t val init_set_si : int -> int -> t val init_set_str : string -> base:int -> t val init_set_d : float -> t (** {2 Conversion Functions} *) (** {{:http://gmplib.org/manual/Rational-Conversions.html#Rational-Conversions}C documentation} *) external get_d : t -> float = "camlidl_mpq_mpq_get_d" external set_d : t -> float -> unit = "camlidl_mpq_mpq_set_d" (* Replace Mpz.set_q: Mpz.t -> Mpq.t -> unit *) external get_z : Mpz.t -> t -> unit = "camlidl_mpq_mpq_get_z" (* For set_f: t -> Mpf.t -> unit, see Mpf.get_q *) external _get_str : int -> t -> string = "camlidl_mpq_mpq__get_str" val get_str : base:int -> t -> string (** {2 User Conversions} *) (** These functionss are additions to or renaming of functions offeered by the C library. *) val to_string : t -> string val to_float : t -> float val of_string : string -> t val of_float : float -> t val of_int : int -> t val of_frac : int -> int -> t val of_mpz : Mpz.t -> t val of_mpz2 : Mpz.t -> Mpz.t -> t (** {2 Arithmetic Functions} *) (** {{:http://gmplib.org/manual/Rational-Arithmetic.html#Rational-Arithmetic}C documentation} *) external add : t -> t -> t -> unit = "camlidl_mpq_mpq_add" external sub : t -> t -> t -> unit = "camlidl_mpq_mpq_sub" external mul : t -> t -> t -> unit = "camlidl_mpq_mpq_mul" external mul_2exp : t -> t -> int -> unit = "camlidl_mpq_mpq_mul_2exp" external div : t -> t -> t -> unit = "camlidl_mpq_mpq_div" external div_2exp : t -> t -> int -> unit = "camlidl_mpq_mpq_div_2exp" external neg : t -> t -> unit = "camlidl_mpq_mpq_neg" external abs : t -> t -> unit = "camlidl_mpq_mpq_abs" external inv : t -> t -> unit = "camlidl_mpq_mpq_inv" (** {2 Comparison Functions} *) (** {{:http://gmplib.org/manual/Comparing-Rationals.html#Comparing-Rationals}C documentation} *) external cmp : t -> t -> int = "camlidl_mpq_mpq_cmp" external cmp_si : t -> int -> int -> int = "camlidl_mpq_mpq_cmp_si" external sgn : t -> int = "camlidl_mpq_mpq_sgn" external equal : t -> t -> bool = "camlidl_mpq_mpq_equal" (** {2 Applying Integer Functions to Rationals} *) (** {{:http://gmplib.org/manual/Applying-Integer-Functions.html#Applying-Integer-Functions}C documentation} *) external get_num : Mpz.t -> t -> unit = "camlidl_mpq_mpq_get_num" external get_den : Mpz.t -> t -> unit = "camlidl_mpq_mpq_get_den" external set_num : t -> Mpz.t -> unit = "camlidl_mpq_mpq_set_num" external set_den : t -> Mpz.t -> unit = "camlidl_mpq_mpq_set_den" (** {2 Input and Output Functions: not interfaced} *) apron-dist-0.9.10/mlgmpidl/gmp_random.idl0000640014525101416610000000524111165125334020172 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \"caml/custom.h\"\n\ #include \"gmp_caml.h\"\n\ ") import "mpz.idl"; import "mpf.idl"; #if HAS_MPFR!=0 import "mpfr.idl"; #endif /* OUTOUTOUT is a reserved variable name ! (see Makefile) */ typedef [abstract,c2ml(camlidl_gmp_randstate_ptr_c2ml),ml2c(camlidl_gmp_randstate_ptr_ml2c)] struct __gmp_randstate_struct* gmp_randstate_ptr; quote(MLMLI,"(** GMP random generation functions *)\n\n") quote(MLMLI,"(** {2 Random State Initialization} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Random-State-Initialization.html#Random-State-Initialization}C documentation} *)\n") void gmp_randinit_default([out]gmp_randstate_ptr OUTOUTOUT); void gmp_randinit_lc_2exp ([out]gmp_randstate_ptr OUTOUTOUT, mpz_ptr A, unsigned long C, unsigned long M2EXP); void gmp_randinit_lc_2exp_size ([out]gmp_randstate_ptr OUTOUTOUT, unsigned long SIZE) quote(call,"\ {\n\ int n = gmp_randinit_lc_2exp_size(OUTOUTOUT,SIZE);\n\ if (n==0) caml_invalid_argument(\"Argument not supported\");\n\ }"); quote(MLMLI,"(** {2 Random State Seeding} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Random-State-Seeding.html#Random-State-Seeding}C documentation} *)\n") void gmp_randseed (gmp_randstate_ptr STATE, mpz_ptr SEED); void gmp_randseed_ui (gmp_randstate_ptr STATE, unsigned long int SEED); quote(MLMLI,"(** {2 Random Number Functions} *)\n") quote(MLMLI,"(** {3 Integers ({!Mpz})} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Random-Numbers.html#Integer-Random-Numbers}C documentation} *)\n") quote(MLI,"module Mpz : sig") quote(ML,"module Mpz = struct") void mpz_urandomb (mpz_ptr ROP, gmp_randstate_ptr STATE, unsigned long int N); void mpz_urandomm (mpz_ptr ROP, gmp_randstate_ptr STATE, mpz_ptr N); void mpz_rrandomb (mpz_ptr ROP, gmp_randstate_ptr STATE, unsigned long int N); quote(MLMLI,"end\n") quote(MLMLI,"(** {3 Floating-point ({!Mpf})} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Miscellaneous-Float-Functions.html#Miscellaneous-Float-Functions}C documentation} *)\n") quote(MLI,"module Mpf : sig") quote(ML,"module Mpf = struct") void mpf_urandomb (mpf_ptr ROP, gmp_randstate_ptr STATE, unsigned long int N); quote(MLMLI,"end\n") #if HAS_MPFR!=0 quote(MLMLI,"(** {3 Floating-point ({!Mpfr})} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Miscellaneous-Functions}C documentation} *)\n") quote(MLI,"module Mpfr : sig") quote(ML,"module Mpfr = struct") void mpfr_urandomb (mpfr_ptr ROP, gmp_randstate_ptr STATE); void mpfr_random (mpfr_ptr ROP); quote(MLMLI,"end\n") #endif apron-dist-0.9.10/mlgmpidl/mlgmpidl.tex0000640014525101416610000000215211251722332017677 0ustar bjeannetpopart\documentclass[[twoside,10pt,a4paper]{report} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} \usepackage{ae} \usepackage{fullpage} \usepackage{url} \usepackage{ocamldoc} \usepackage{makeidx} \usepackage{fancyhdr} \pagestyle{fancy} \renewcommand{\headrulewidth}{0.9pt} \renewcommand{\footrulewidth}{0pt} \setlength{\headheight}{2.8ex} \setlength{\footskip}{5ex} \renewcommand{\chaptermark}[1]{ % \markboth{\MakeUppercase{\chaptername}\ \thechapter.\ #1}{}} \renewcommand{\sectionmark}[1]{} \setcounter{tocdepth}{0} \setcounter{secnumdepth}{4} \usepackage{color} \definecolor{mygreen}{rgb}{0,0.6,0} \usepackage[ps2pdf]{hyperref} \setlength{\parindent}{0em} \setlength{\parskip}{0.5ex} %\usepackage{listings} %\lstloadlanguages{Caml} \makeindex \title{MLGMPIDL: OCaml interface for GMP and MPFR libraries (version 1.1)} \begin{document} \maketitle \vspace*{0.9\textheight} All files distributed in the MLGMPIDL interface are distributed under LGPL license. Copyright (C) Bertrand Jeannet 2005-2009 for the MLGMPIDL interface. \newpage \tableofcontents \input{ocamldoc.tex} \appendix \printindex \end{document} apron-dist-0.9.10/mlgmpidl/mpf_caml.c0000640014525101416610000005761311252216513017306 0ustar bjeannetpopart/* File generated from mpf.idl */ /* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include "caml/custom.h" #include "gmp_caml.h" extern void camlidl_mpz_ptr_ml2c(value, mpz_ptr *); #define camlidl_ml2c_mpz_mpz_ptr(v,c,ctx) camlidl_mpz_ptr_ml2c(v,c) extern value camlidl_mpz_ptr_c2ml(mpz_ptr *); #define camlidl_c2ml_mpz_mpz_ptr(c,ctx) camlidl_mpz_ptr_c2ml(c) extern void camlidl_mpq_ptr_ml2c(value, mpq_ptr *); #define camlidl_ml2c_mpq_mpq_ptr(v,c,ctx) camlidl_mpq_ptr_ml2c(v,c) extern value camlidl_mpq_ptr_c2ml(mpq_ptr *); #define camlidl_c2ml_mpq_mpq_ptr(c,ctx) camlidl_mpq_ptr_c2ml(c) #define camlidl_ml2c_mpf_mpf_ptr(v,c,ctx) camlidl_mpf_ptr_ml2c(v,c) #define camlidl_c2ml_mpf_mpf_ptr(c,ctx) camlidl_mpf_ptr_c2ml(c) value camlidl_mpf_mpf_set_default_prec( value _v_PREC) { unsigned long PREC; /*in*/ PREC = Long_val(_v_PREC); mpf_set_default_prec(PREC); return Val_unit; } value camlidl_mpf_mpf_get_default_prec(value _unit) { unsigned long _res; value _vres; _res = mpf_get_default_prec(); _vres = Val_long(_res); return _vres; } value camlidl_mpf_mpf_init(value _unit) { mpf_t OUTOUTOUT; mpf_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; mpf_init(OUTOUTOUT); _vres = camlidl_c2ml_mpf_mpf_ptr(&OUTTOUTTOUTT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_init2( value _v_PREC) { mpf_t OUTOUTOUT; mpf_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ unsigned long PREC; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; PREC = Long_val(_v_PREC); mpf_init2(OUTOUTOUT, PREC); _vres = camlidl_c2ml_mpf_mpf_ptr(&OUTTOUTTOUTT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_get_prec( value _v_OP) { mpf_ptr OP; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_get_prec(OP); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_set_prec( value _v_ROP, value _v_PREC) { mpf_ptr ROP; /*in*/ unsigned long PREC; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); PREC = Long_val(_v_PREC); mpf_set_prec(ROP, PREC); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_set_prec_raw( value _v_ROP, value _v_PREC) { mpf_ptr ROP; /*in*/ unsigned long PREC; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); PREC = Long_val(_v_PREC); mpf_set_prec_raw(ROP, PREC); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_set( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ mpf_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); mpf_set(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_set_si( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ long OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); OP = Long_val(_v_OP); mpf_set_si(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_set_d( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ double OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); OP = Double_val(_v_OP); mpf_set_d(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_set_z( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); mpf_set_z(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_set_q( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ mpq_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); mpf_set_q(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf__set_str( value _v_ROP, value _v_STR, value _v_BASE) { mpf_ptr ROP; /*in*/ char *STR; /*in*/ int BASE; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); STR = String_val(_v_STR); BASE = Int_val(_v_BASE); /* begin user-supplied calling sequence */ { int n = mpf_set_str(ROP,STR,BASE); if (n){ mpf_clear(ROP); caml_invalid_argument(""); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_swap( value _v_ROP1, value _v_ROP2) { mpf_ptr ROP1; /*in*/ mpf_ptr ROP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP1, &ROP1, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_ROP2, &ROP2, _ctx); mpf_swap(ROP1, ROP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_init_set( value _v_OP) { mpf_t OUTOUTOUT; mpf_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ mpf_ptr OP; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); mpf_init_set(OUTOUTOUT, OP); _vres = camlidl_c2ml_mpf_mpf_ptr(&OUTTOUTTOUTT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_init_set_si( value _v_OP) { mpf_t OUTOUTOUT; mpf_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ long OP; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; OP = Long_val(_v_OP); mpf_init_set_si(OUTOUTOUT, OP); _vres = camlidl_c2ml_mpf_mpf_ptr(&OUTTOUTTOUTT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_init_set_d( value _v_OP) { mpf_t OUTOUTOUT; mpf_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ double OP; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; OP = Double_val(_v_OP); mpf_init_set_d(OUTOUTOUT, OP); _vres = camlidl_c2ml_mpf_mpf_ptr(&OUTTOUTTOUTT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf__init_set_str( value _v_STR, value _v_BASE) { mpf_t OUTOUTOUT; mpf_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ char *STR; /*in*/ int BASE; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; STR = String_val(_v_STR); BASE = Int_val(_v_BASE); /* begin user-supplied calling sequence */ { int n = mpf_init_set_str(OUTOUTOUT,STR,BASE); if (n){ mpf_clear(OUTOUTOUT); caml_invalid_argument(""); } } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_mpf_mpf_ptr(&OUTTOUTTOUTT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_get_d( value _v_OP) { mpf_ptr OP; /*in*/ double _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_get_d(OP); _vres = copy_double(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_get_d_2exp( value _v_OP) { long *EXP; /*out*/ mpf_ptr OP; /*in*/ double _res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; long _c1; value _vresult; value _vres[2] = { 0, 0, }; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); EXP = &_c1; _res = mpf_get_d_2exp(EXP, OP); Begin_roots_block(_vres, 2) _vres[0] = copy_double(_res); _vres[1] = Val_long(*EXP); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); return _vresult; } value camlidl_mpf_mpf_get_si( value _v_OP) { mpf_ptr OP; /*in*/ long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_get_si(OP); _vres = copy_nativeint(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_get_int( value _v_OP) { mpf_ptr OP; /*in*/ long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); /* begin user-supplied calling sequence */ _res = mpf_get_si(OP); /* end user-supplied calling sequence */ _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_get_z( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ mpf_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); /* begin user-supplied calling sequence */ mpz_set_f(ROP,OP); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_get_q( value _v_ROP, value _v_OP) { mpq_ptr ROP; /*in*/ mpf_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); /* begin user-supplied calling sequence */ mpq_set_f(ROP,OP); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf__get_str( value _v_BASE, value _v_N_DIGITS, value _v_OP) { long *EXPPTR; /*out*/ int BASE; /*in*/ int N_DIGITS; /*in*/ mpf_ptr OP; /*in*/ char *_res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; long _c1; value _vresult; value _vres[2] = { 0, 0, }; BASE = Int_val(_v_BASE); N_DIGITS = Int_val(_v_N_DIGITS); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); EXPPTR = &_c1; /* begin user-supplied calling sequence */ _res = mpf_get_str(NULL,EXPPTR,BASE,N_DIGITS,OP); /* end user-supplied calling sequence */ Begin_roots_block(_vres, 2) _vres[0] = copy_string(_res); _vres[1] = Val_long(*EXPPTR); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ free(_res); /* end user-supplied deallocation sequence */ return _vresult; } value camlidl_mpf_mpf_add( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ mpf_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP2, &OP2, _ctx); mpf_add(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_add_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpf_add_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_sub( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ mpf_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP2, &OP2, _ctx); mpf_sub(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_ui_sub( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ unsigned long OP1; /*in*/ mpf_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); OP1 = Long_val(_v_OP1); camlidl_ml2c_mpf_mpf_ptr(_v_OP2, &OP2, _ctx); mpf_ui_sub(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_sub_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpf_sub_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_mul( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ mpf_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP2, &OP2, _ctx); mpf_mul(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_mul_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpf_mul_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_mul_2exp( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpf_mul_2exp(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_div( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ mpf_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP2, &OP2, _ctx); mpf_div(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_ui_div( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ unsigned long OP1; /*in*/ mpf_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); OP1 = Long_val(_v_OP1); camlidl_ml2c_mpf_mpf_ptr(_v_OP2, &OP2, _ctx); mpf_ui_div(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_div_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpf_div_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_div_2exp( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpf_div_2exp(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_sqrt( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ mpf_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); mpf_sqrt(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_pow_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpf_pow_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_neg( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ mpf_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); mpf_neg(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_abs( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ mpf_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); mpf_abs(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_cmp( value _v_OP1, value _v_OP2) { mpf_ptr OP1; /*in*/ mpf_ptr OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP2, &OP2, _ctx); _res = mpf_cmp(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_cmp_d( value _v_OP1, value _v_OP2) { mpf_ptr OP1; /*in*/ double OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); OP2 = Double_val(_v_OP2); _res = mpf_cmp_d(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_cmp_si( value _v_OP1, value _v_OP2) { mpf_ptr OP1; /*in*/ long OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); _res = mpf_cmp_si(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_sgn( value _v_OP) { mpf_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_sgn(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf__equal( value _v_OP1, value _v_OP2, value _v_OP3) { mpf_ptr OP1; /*in*/ mpf_ptr OP2; /*in*/ unsigned long OP3; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP2, &OP2, _ctx); OP3 = Long_val(_v_OP3); /* begin user-supplied calling sequence */ _res=mpf_eq(OP1,OP2,OP3); /* end user-supplied calling sequence */ _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_reldiff( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ mpf_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP2, &OP2, _ctx); mpf_reldiff(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_ceil( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ mpf_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); mpf_ceil(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_floor( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ mpf_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); mpf_floor(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_trunc( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ mpf_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); mpf_trunc(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_integer_p( value _v_OP) { mpf_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_integer_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_fits_int_p( value _v_OP) { mpf_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_fits_int_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_fits_ulong_p( value _v_OP) { mpf_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_fits_ulong_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_fits_slong_p( value _v_OP) { mpf_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_fits_slong_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_fits_uint_p( value _v_OP) { mpf_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_fits_uint_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_fits_sint_p( value _v_OP) { mpf_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_fits_sint_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_fits_ushort_p( value _v_OP) { mpf_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_fits_ushort_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_fits_sshort_p( value _v_OP) { mpf_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_fits_sshort_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } apron-dist-0.9.10/mlgmpidl/mpfrf.mli0000640014525101416610000000620711165125334017175 0ustar bjeannetpopart(** MPFR multi-precision floating-point version, functional version *) (* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution *) (** Functions in this module has a functional semantics, unlike the corresponding functions in {!Mpfr}. These functions do not return the rounding information and are less efficients, due to the additional memory allocation neded for the result. *) type t = Mpfr.t (** multi-precision floating-point numbers *) val to_mpfr : t -> Mpfr.t val of_mpfr : Mpfr.t -> t (** Safe conversion from and to Mpfr.t. There is no sharing between the argument and the result. *) val mpfr : t -> Mpfr.t val mpfrf : Mpfr.t -> t (** Unsafe conversion from and to Mpfr.t. The argument and the result actually share the same number: be cautious ! *) (** Conversion from and to Mpz.t, Mpq.t and Mpfr.t There is no sharing between the argument and the result. *) (* ====================================================================== *) (** {2 Pretty-printing} *) (* ====================================================================== *) val print : Format.formatter -> t -> unit (* ====================================================================== *) (** {2 Constructors} *) (* ====================================================================== *) val of_string : string -> Mpfr.round -> t val of_float : float -> Mpfr.round -> t val of_int : int -> Mpfr.round -> t val of_frac : int -> int -> Mpfr.round -> t val of_mpz : Mpz.t -> Mpfr.round -> t val of_mpz2 : Mpz.t -> Mpz.t -> Mpfr.round -> t val of_mpzf : Mpzf.t -> Mpfr.round -> t val of_mpzf2 : Mpzf.t -> Mpzf.t -> Mpfr.round -> t val of_mpq : Mpq.t -> Mpfr.round -> t val of_mpqf : Mpqf.t -> Mpfr.round -> t (* ====================================================================== *) (** {2 Conversions} *) (* ====================================================================== *) val to_string : t -> string val to_float : ?round:Mpfr.round -> t -> float val to_mpqf : t -> Mpqf.t (* ====================================================================== *) (** {2 Arithmetic Functions} *) (* ====================================================================== *) val add : t -> t -> Mpfr.round -> t val add_int : t -> int -> Mpfr.round -> t val sub : t -> t -> Mpfr.round -> t val sub_int : t -> int -> Mpfr.round -> t val mul : t -> t -> Mpfr.round -> t val mul_ui : t -> int -> Mpfr.round -> t val ui_div : int -> t -> Mpfr.round -> t val div : t -> t -> Mpfr.round -> t val div_ui : t -> int -> Mpfr.round -> t val sqrt : t -> Mpfr.round -> t val ui_pow : int -> t -> Mpfr.round -> t val pow : t -> t -> Mpfr.round -> t val pow_int : t -> int -> Mpfr.round -> t val neg : t -> Mpfr.round -> t val abs : t -> Mpfr.round -> t (* ====================================================================== *) (** {2 Comparison Functions} *) (* ====================================================================== *) val equal : t -> t -> bits:int -> bool val cmp : t -> t -> int val cmp_int : t -> int -> int val sgn : t -> int val nan_p : t -> bool val inf_p : t -> bool val number_p : t -> bool apron-dist-0.9.10/mlgmpidl/mpfr.idl0000640014525101416610000003527111165125334017021 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \"caml/custom.h\"\n\ #include \"gmp_caml.h\"\n\ ") import "mpz.idl"; import "mpq.idl"; import "mpf.idl"; typedef [abstract,c2ml(camlidl_mpfr_ptr_c2ml),ml2c(camlidl_mpfr_ptr_ml2c)] struct __mpfr_struct* mpfr_ptr; quote(MLMLI,"(** MPFR multiprecision floating-point numbers *)\n\n") typedef [mltype("\n | Near\n | Zero\n | Up\n | Down"), c2ml(camlidl_mpfr_rnd_t_c2ml),ml2c(camlidl_mpfr_rnd_t_ml2c)] struct mpfr_rnd_t mpfr_rnd_t; quote(MLMLI,"(** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x].\n\n These functions are as efficient as their C counterpart: they do not imply additional memory allocation. *)\n\n") /* OUTOUTOUT is a reserved variable name ! (see Makefile and sedscript_c) */ quote(MLI,"\n(** {2 Pretty printing} *)\n") quote(MLI,"val print : Format.formatter -> t -> unit") quote(MLI,"val print_round : Format.formatter -> round -> unit") quote(MLI,"val string_of_round : round -> string") quote(MLMLI,"\n(** {2 Rounding Modes} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Rounding-Related-Functions}C documentation} *)\n") void mpfr_set_default_rounding_mode (mpfr_rnd_t RND); mpfr_rnd_t mpfr_get_default_rounding_mode (void); int mpfr_round_prec (mpfr_ptr X, mpfr_rnd_t RND, unsigned long int PREC); quote(MLMLI,"\n(** {2 Exceptions} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Exception-Related-Functions}C documentation} *)\n") long int mpfr_get_emin (void); long int mpfr_get_emax (void); void mpfr_set_emin (long int EXP) quote(call,"{\n\ int n = mpfr_set_emin(EXP);\n\ if (n){ caml_invalid_argument(\"\"); }\n\ }"); void mpfr_set_emax (long int EXP) quote(call,"{\n\ int n = mpfr_set_emax(EXP);\n\ if (n){ caml_invalid_argument(\"\"); }\n\ }"); int mpfr_check_range (mpfr_ptr X, int T, mpfr_rnd_t RND); void mpfr_clear_underflow (void); void mpfr_clear_overflow (void); void mpfr_clear_nanflag (void); void mpfr_clear_inexflag (void); void mpfr_clear_flags (void); boolean mpfr_underflow_p (void); boolean mpfr_overflow_p (void); boolean mpfr_nanflag_p (void); boolean mpfr_inexflag_p (void); quote(MLMLI,"\n(** {2 Initialization Functions} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Initialization-Functions}C documentation} *)\n") void mpfr_set_default_prec (unsigned long int PREC); unsigned long int mpfr_get_default_prec (void); void mpfr_init ([out] mpfr_ptr OUTOUTOUT); void mpfr_init2 ([out] mpfr_ptr OUTOUTOUT, unsigned long int PREC); unsigned long int mpfr_get_prec (mpfr_ptr OP); void mpfr_set_prec (mpfr_ptr ROP, unsigned long int PREC); void mpfr_set_prec_raw (mpfr_ptr ROP, unsigned long int PREC); quote(MLMLI,"\n(** {2 Assignment Functions} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Assignment-Functions}C documentation} *)\n") int mpfr_set (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_set_si (mpfr_ptr ROP, signed long int OP, mpfr_rnd_t RND); int mpfr_set_d (mpfr_ptr ROP, double OP, mpfr_rnd_t RND); int mpfr_set_z (mpfr_ptr ROP, mpz_ptr OP, mpfr_rnd_t RND); int mpfr_set_q (mpfr_ptr ROP, mpq_ptr OP, mpfr_rnd_t RND); void mpfr__set_str (mpfr_ptr ROP, [string]char *STR, int BASE, mpfr_rnd_t RND) quote(call,"{\n\ int n = mpfr_set_str(ROP,STR,BASE,RND);\n\ if (n){ mpfr_clear(ROP); caml_invalid_argument(\"\"); }\n\ }"); quote(MLI,"val set_str : t -> string -> base:int -> mpfr_rnd_t -> unit") quote(ML,"let set_str a b ~base round = _set_str a b base round") int mpfr_set_f (mpfr_ptr X, mpf_ptr Y, mpfr_rnd_t RND); int mpfr_set_si_2exp (mpfr_ptr ROP, signed long int OP, signed long int EXPNT, mpfr_rnd_t RND); void mpfr_set_inf (mpfr_ptr X, int SIGN); void mpfr_set_nan (mpfr_ptr X); void mpfr_swap (mpfr_ptr ROP1, mpfr_ptr ROP2); quote(MLMLI,"\n(** {2 Combined Initialization and Assignment Functions} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Combined-Initialization-and-Assignment-Functions}C documentation} *)\n") int mpfr_init_set ([out] mpfr_ptr OUTOUTOUT, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_init_set_si ([out] mpfr_ptr OUTOUTOUT, signed long int OP, mpfr_rnd_t RND); int mpfr_init_set_d ([out] mpfr_ptr OUTOUTOUT, double OP, mpfr_rnd_t RND); int mpfr_init_set_f ([out] mpfr_ptr OUTOUTOUT, mpf_ptr OP, mpfr_rnd_t RND); int mpfr_init_set_z ([out] mpfr_ptr OUTOUTOUT, mpz_ptr OP, mpfr_rnd_t RND); int mpfr_init_set_q ([out] mpfr_ptr OUTOUTOUT, mpq_ptr OP, mpfr_rnd_t RND); void mpfr__init_set_str ([out] mpfr_ptr OUTOUTOUT, [string]char *STR, int BASE, mpfr_rnd_t RND) quote(call,"\ {\n\ int n = mpfr_init_set_str(OUTOUTOUT,STR,BASE,RND);\n\ if (n){ mpfr_clear(OUTOUTOUT); caml_invalid_argument(\"\"); }\n\ }"); quote(MLI,"val init_set_str : string -> base:int -> mpfr_rnd_t -> t") quote(ML,"let init_set_str a ~base round = _init_set_str a base round") quote(MLMLI,"\n(** {2 Conversion Functions} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Conversion-Functions}C documentation} *)\n") double mpfr_get_d (mpfr_ptr OP, mpfr_rnd_t RND); double mpfr_get_d1 (mpfr_ptr OP); int mpfr_get_z_exp (mpz_ptr Z, mpfr_ptr OP); void mpfr_get_z (mpz_ptr Z, mpfr_ptr OP, mpfr_rnd_t RND); [string]char* mpfr__get_str ([out]long int *EXPPTR, int BASE, int N_DIGITS, mpfr_ptr OP, mpfr_rnd_t RND) quote(call,"_res = mpfr_get_str(NULL,EXPPTR,BASE,N_DIGITS,OP,RND);") quote(dealloc,"free(_res);"); quote(MLI,"val get_str : base:int -> digits:int -> t -> mpfr_rnd_t -> string * int") quote(ML,"let get_str ~base ~digits a round = _get_str base digits a round") quote(MLI,"\n(** {2 User Conversions} *)\n") quote(MLI,"(** These functionss are additions to or renaming of functions offered by the C library. *)\n") quote(MLI,"val to_string : t -> string") quote(MLI,"val to_float : ?round:round -> t -> float") quote(MLI,"val to_mpq : t -> Mpq.t") quote(MLI,"val of_string : string -> round -> t") quote(MLI,"val of_float : float -> round -> t") quote(MLI,"val of_int : int -> round -> t") quote(MLI,"val of_frac : int -> int -> round -> t") quote(MLI,"val of_mpz : Mpz.t -> round -> t") quote(MLI,"val of_mpz2 : Mpz.t -> Mpz.t -> round -> t") quote(MLI,"val of_mpq : Mpq.t -> round -> t") quote(MLMLI,"\n(** {2 Basic Arithmetic Functions} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Basic-Arithmetic-Functions}C documentation} *)\n") int mpfr_add (mpfr_ptr ROP, mpfr_ptr OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_add_ui (mpfr_ptr ROP, mpfr_ptr OP1, unsigned long int OP2, mpfr_rnd_t RND); int mpfr_add_z (mpfr_ptr ROP, mpfr_ptr OP1, mpz_ptr OP2, mpfr_rnd_t RND); int mpfr_add_q (mpfr_ptr ROP, mpfr_ptr OP1, mpq_ptr OP2, mpfr_rnd_t RND); int mpfr_sub (mpfr_ptr ROP, mpfr_ptr OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_ui_sub (mpfr_ptr ROP, unsigned long int OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_sub_ui (mpfr_ptr ROP, mpfr_ptr OP1, unsigned long int OP2, mpfr_rnd_t RND); int mpfr_sub_z (mpfr_ptr ROP, mpfr_ptr OP1, mpz_ptr OP2, mpfr_rnd_t RND); int mpfr_sub_q (mpfr_ptr ROP, mpfr_ptr OP1, mpq_ptr OP2, mpfr_rnd_t RND); int mpfr_mul (mpfr_ptr ROP, mpfr_ptr OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_mul_ui (mpfr_ptr ROP, mpfr_ptr OP1, unsigned long int OP2, mpfr_rnd_t RND); int mpfr_mul_z (mpfr_ptr ROP, mpfr_ptr OP1, mpz_ptr OP2, mpfr_rnd_t RND); int mpfr_mul_q (mpfr_ptr ROP, mpfr_ptr OP1, mpq_ptr OP2, mpfr_rnd_t RND); int mpfr_mul_2ui (mpfr_ptr ROP, mpfr_ptr OP1, unsigned long int OP2, mpfr_rnd_t RND); int mpfr_mul_2si (mpfr_ptr ROP, mpfr_ptr OP1, long int OP2, mpfr_rnd_t RND); int mpfr_mul_2exp (mpfr_ptr ROP, mpfr_ptr OP1, unsigned long int OP2, mpfr_rnd_t RND); int mpfr_div (mpfr_ptr ROP, mpfr_ptr OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_ui_div (mpfr_ptr ROP, unsigned long int OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_div_ui (mpfr_ptr ROP, mpfr_ptr OP1, unsigned long int OP2, mpfr_rnd_t RND); int mpfr_div_z (mpfr_ptr ROP, mpfr_ptr OP1, mpz_ptr OP2, mpfr_rnd_t RND); int mpfr_div_q (mpfr_ptr ROP, mpfr_ptr OP1, mpq_ptr OP2, mpfr_rnd_t RND); int mpfr_div_2ui (mpfr_ptr ROP, mpfr_ptr OP1, unsigned long int OP2, mpfr_rnd_t RND); int mpfr_div_2si (mpfr_ptr ROP, mpfr_ptr OP1, long int OP2, mpfr_rnd_t RND); quote(MLI,"val div_2exp : t -> t -> int -> mpfr_rnd_t -> int") quote(ML,"let div_2exp = div_2ui") boolean mpfr_sqrt (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); boolean mpfr_sqrt_ui (mpfr_ptr ROP, unsigned long int OP, mpfr_rnd_t RND); boolean mpfr_pow_ui (mpfr_ptr ROP, mpfr_ptr OP1, unsigned long int OP2, mpfr_rnd_t RND); boolean mpfr_pow_si (mpfr_ptr ROP, mpfr_ptr OP1, signed long int OP2, mpfr_rnd_t RND); boolean mpfr_ui_pow_ui (mpfr_ptr ROP, unsigned long int OP1, unsigned long int OP2, mpfr_rnd_t RND); boolean mpfr_ui_pow (mpfr_ptr ROP, unsigned long int OP1, mpfr_ptr OP2, mpfr_rnd_t RND); boolean mpfr_pow (mpfr_ptr ROP, mpfr_ptr OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_neg (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_abs (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); quote(MLMLI,"\n(** {2 Comparison Functions} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Comparison-Functions}C documentation} *)\n") int mpfr_cmp (mpfr_ptr OP1, mpfr_ptr OP2); int mpfr_cmp_si (mpfr_ptr OP1, signed long int OP2); int mpfr_cmp_si_2exp (mpfr_ptr OP1, long int OP2, int E); int mpfr_sgn (mpfr_ptr OP); boolean mpfr__equal (mpfr_ptr OP1, mpfr_ptr OP2, unsigned long int OP3) quote(call,"_res=mpfr_eq(OP1,OP2,OP3);"); quote(MLI,"val equal : t -> t -> bits:int -> bool") quote(ML,"let equal a b ~bits = _equal a b bits") boolean mpfr_nan_p (mpfr_ptr OP); boolean mpfr_inf_p (mpfr_ptr OP); boolean mpfr_number_p (mpfr_ptr OP); void mpfr_reldiff (mpfr_ptr ROP, mpfr_ptr OP1, mpfr_ptr OP2, mpfr_rnd_t RND); quote(MLMLI,"\n(** {2 Special Functions} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Special-Functions}C documentation} *)\n") int mpfr_log (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_log2 (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_log10 (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_exp (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_exp2 (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_exp10 (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_cos (mpfr_ptr COP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_sin (mpfr_ptr SOP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_tan (mpfr_ptr TOP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_sec (mpfr_ptr COP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_csc (mpfr_ptr SOP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_cot (mpfr_ptr TOP, mpfr_ptr OP, mpfr_rnd_t RND); boolean mpfr_sin_cos (mpfr_ptr SOP, mpfr_ptr COP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_acos (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_asin (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_atan (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_atan2 (mpfr_ptr ROP, mpfr_ptr Y, mpfr_ptr X, mpfr_rnd_t RND); int mpfr_cosh (mpfr_ptr COP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_sinh (mpfr_ptr SOP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_tanh (mpfr_ptr TOP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_sech (mpfr_ptr COP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_csch (mpfr_ptr SOP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_coth (mpfr_ptr TOP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_acosh (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_asinh (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_atanh (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_fac_ui (mpfr_ptr ROP, unsigned long int OP, mpfr_rnd_t RND); int mpfr_log1p (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_expm1 (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_eint (mpfr_ptr Y, mpfr_ptr X, mpfr_rnd_t RND); int mpfr_gamma (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_lngamma (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_zeta (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_erf (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_erfc (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_fma (mpfr_ptr ROP, mpfr_ptr OPX,mpfr_ptr OPY, mpfr_ptr OPZ, mpfr_rnd_t RND); int mpfr_agm (mpfr_ptr ROP, mpfr_ptr OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_hypot (mpfr_ptr ROP, mpfr_ptr X, mpfr_ptr Y, mpfr_rnd_t RND); int mpfr_const_log2 (mpfr_ptr ROP, mpfr_rnd_t RND); int mpfr_const_pi (mpfr_ptr ROP, mpfr_rnd_t RND); int mpfr_const_euler (mpfr_ptr ROP, mpfr_rnd_t RND); int mpfr_const_catalan (mpfr_ptr ROP, mpfr_rnd_t RND); quote(MLMLI,"\n(** {2 Input and Output Functions: not interfaced} *)\n") quote(MLMLI,"\n(** {2 Miscellaneous Float Functions} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Rounding-Related-Functions}C documentation} *)\n") int mpfr_rint (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_ceil (mpfr_ptr ROP, mpfr_ptr OP); int mpfr_floor (mpfr_ptr ROP, mpfr_ptr OP); int mpfr_round (mpfr_ptr ROP, mpfr_ptr OP); int mpfr_trunc (mpfr_ptr ROP, mpfr_ptr OP); boolean mpfr_integer_p (mpfr_ptr OP); void mpfr_nexttoward (mpfr_ptr X, mpfr_ptr Y); void mpfr_nextabove (mpfr_ptr X); void mpfr_nextbelow (mpfr_ptr X); int mpfr_min (mpfr_ptr ROP, mpfr_ptr OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_max (mpfr_ptr ROP, mpfr_ptr OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_get_exp (mpfr_ptr X); int mpfr_set_exp (mpfr_ptr X, signed long int E); quote(ML,"\n(** {2 Additional functions} *)\n") quote(ML,"let to_string x = \n\ let (s,e) = get_str ~base:10 ~digits:0 x Near in \n\ if s=\"\" \n\ then \"0.0\" \n\ else Format.sprintf \"0.%sE%i\" s e \n\ ") quote(ML,"\n(** {2 Pretty printing} *)\n") quote(ML,"let print fmt x = \n\ let (s,e) = get_str ~base:10 ~digits:0 x Near in \n\ if s=\"\" \n\ then Format.pp_print_string fmt \"0.0\" \n\ else Format.fprintf fmt \"0.%sE%i\" s e \n\ \n\ let string_of_round = function\n\ | Near -> \"Near\"\n\ | Zero -> \"Zero\"\n\ | Up -> \"Up\"\n\ | Down -> \"Down\"\n\ let print_round fmt x = Format.pp_print_string fmt (string_of_round x)\n\ ") quote(ML,"let to_float ?round x = \n\ match round with\n\ | None -> get_d1 x\n\ | Some r -> get_d x r\n\ ") quote(ML,"let to_mpq x = \n\ let num,den = Mpz.init(), Mpz.init_set_si 1 in\n\ let e = get_z_exp num x in\n\ Mpz.mul_2exp den den e;\n\ Mpq.of_mpz2 num den\n\ ") quote(ML,"let of_int x r = snd (init_set_si x r)") quote(ML,"let of_float x r = snd (init_set_d x r)") quote(ML,"let of_mpz x r = snd (init_set_z x r)") quote(ML,"let of_mpq x r = snd (init_set_q x r)") quote(ML,"let of_string x r = init_set_str x ~base:10 r") quote(ML,"let of_frac n d r = let mpq = Mpq.of_frac n d in of_mpq mpq r") quote(ML,"let of_mpz2 n d r = let mpq = Mpq.of_mpz2 n d in of_mpq mpq r") apron-dist-0.9.10/mlgmpidl/mpz.ml0000640014525101416610000003167111252216513016520 0ustar bjeannetpopart(* File generated from mpz.idl *) (* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t (** GMP multi-precision integers *) (** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x]. These functions are as efficient as their C counterpart: they do not imply additional memory allocation, unlike the corresponding functions in the module {!Mpzf}. *) (** {2 Initialization Functions} *) (** {{:http://gmplib.org/manual/Initializing-Integers.html#Initializing-Integers}C documentation} *) external init : unit -> t = "camlidl_mpz_mpz_init" external init2 : int -> t = "camlidl_mpz_mpz_init2" external realloc2 : t -> int -> unit = "camlidl_mpz_mpz_realloc2" (** {2 Assignement Functions} *) (** {{:http://gmplib.org/manual/Assigning-Integers.html#Assigning-Integers}C documentation} *) (** The first parameter holds the result. *) external set : t -> t -> unit = "camlidl_mpz_mpz_set" external set_si : t -> int -> unit = "camlidl_mpz_mpz_set_si" external set_d : t -> float -> unit = "camlidl_mpz_mpz_set_d" external _set_str : t -> string -> int -> unit = "camlidl_mpz_mpz__set_str" let set_str a b ~base = _set_str a b base external swap : t -> t -> unit = "camlidl_mpz_mpz_swap" (** {2 Combined Initialization and Assignment Functions} *) (** {{:http://gmplib.org/manual/Simultaneous-Integer-Init-_0026-Assign.html#Simultaneous-Integer-Init-_0026-Assign}C documentation} *) external init_set : t -> t = "camlidl_mpz_mpz_init_set" external init_set_si : int -> t = "camlidl_mpz_mpz_init_set_si" external init_set_d : float -> t = "camlidl_mpz_mpz_init_set_d" external _init_set_str : string -> int -> t = "camlidl_mpz_mpz__init_set_str" let init_set_str a ~base = _init_set_str a base (** {2 Conversion Functions} *) (** {{:http://gmplib.org/manual/Converting-Integers.html#Converting-Integers}C documentation} *) external get_si : t -> nativeint = "camlidl_mpz_mpz_get_si" external get_int : t -> int = "camlidl_mpz_mpz_get_int" external get_d : t -> float = "camlidl_mpz_mpz_get_d" external get_d_2exp : t -> float * int = "camlidl_mpz_mpz_get_d_2exp" external _get_str : int -> t -> string = "camlidl_mpz_mpz__get_str" let get_str ~base a = _get_str base a (** {2 User Conversions} *) (** These functions are additions to or renaming of functions offered by the C library. *) let to_string x = get_str 10 x let to_float = get_d let of_string str = init_set_str str 10 let of_float = init_set_d let of_int = init_set_si (** {2 Pretty printing} *) let print fmt x = Format.pp_print_string fmt (get_str 10 x) (** {2 Arithmetic Functions} *) (** {{:http://gmplib.org/manual/Integer-Arithmetic.html#Integer-Arithmetic}C documentation} *) (** The first parameter holds the result. *) external add : t -> t -> t -> unit = "camlidl_mpz_mpz_add" external add_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_add_ui" external sub : t -> t -> t -> unit = "camlidl_mpz_mpz_sub" external sub_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_sub_ui" external ui_sub : t -> int -> t -> unit = "camlidl_mpz_mpz_ui_sub" external mul : t -> t -> t -> unit = "camlidl_mpz_mpz_mul" external mul_si : t -> t -> int -> unit = "camlidl_mpz_mpz_mul_si" external addmul : t -> t -> t -> unit = "camlidl_mpz_mpz_addmul" external addmul_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_addmul_ui" external submul : t -> t -> t -> unit = "camlidl_mpz_mpz_submul" external submul_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_submul_ui" external mul_2exp : t -> t -> int -> unit = "camlidl_mpz_mpz_mul_2exp" external neg : t -> t -> unit = "camlidl_mpz_mpz_neg" external abs : t -> t -> unit = "camlidl_mpz_mpz_abs" (** {2 Division Functions} *) (** {{:http://gmplib.org/manual/Integer-Division.html#Integer-Division}C documentation} *) (** [c] stands for ceiling, [f] for floor, and [t] for truncate (rounds toward 0).*) (** {3 Ceiling division} *) (** The first parameter holds the quotient. *) external cdiv_q : t -> t -> t -> unit = "camlidl_mpz_mpz_cdiv_q" (** The first parameter holds the remainder. *) external cdiv_r : t -> t -> t -> unit = "camlidl_mpz_mpz_cdiv_r" (** The two first parameters hold resp. the quotient and the remainder). *) external cdiv_qr : t -> t -> t -> t -> unit = "camlidl_mpz_mpz_cdiv_qr" (** The first parameter holds the quotient. *) external cdiv_q_ui : t -> t -> int -> int = "camlidl_mpz_mpz_cdiv_q_ui" (** The first parameter holds the remainder. *) external cdiv_r_ui : t -> t -> int -> int = "camlidl_mpz_mpz_cdiv_r_ui" (** The two first parameters hold resp. the quotient and the remainder). *) external cdiv_qr_ui : t -> t -> t -> int -> int = "camlidl_mpz_mpz_cdiv_qr_ui" external cdiv_ui : t -> int -> int = "camlidl_mpz_mpz_cdiv_ui" (** The first parameter holds the quotient. *) external cdiv_q_2exp : t -> t -> int -> unit = "camlidl_mpz_mpz_cdiv_q_2exp" (** The first parameter holds the remainder. *) external cdiv_r_2exp : t -> t -> int -> unit = "camlidl_mpz_mpz_cdiv_r_2exp" (** {3 Floor division} *) external fdiv_q : t -> t -> t -> unit = "camlidl_mpz_mpz_fdiv_q" external fdiv_r : t -> t -> t -> unit = "camlidl_mpz_mpz_fdiv_r" external fdiv_qr : t -> t -> t -> t -> unit = "camlidl_mpz_mpz_fdiv_qr" external fdiv_q_ui : t -> t -> int -> int = "camlidl_mpz_mpz_fdiv_q_ui" external fdiv_r_ui : t -> t -> int -> int = "camlidl_mpz_mpz_fdiv_r_ui" external fdiv_qr_ui : t -> t -> t -> int -> int = "camlidl_mpz_mpz_fdiv_qr_ui" external fdiv_ui : t -> int -> int = "camlidl_mpz_mpz_fdiv_ui" external fdiv_q_2exp : t -> t -> int -> unit = "camlidl_mpz_mpz_fdiv_q_2exp" external fdiv_r_2exp : t -> t -> int -> unit = "camlidl_mpz_mpz_fdiv_r_2exp" (** {3 Truncate division} *) external tdiv_q : t -> t -> t -> unit = "camlidl_mpz_mpz_tdiv_q" external tdiv_r : t -> t -> t -> unit = "camlidl_mpz_mpz_tdiv_r" external tdiv_qr : t -> t -> t -> t -> unit = "camlidl_mpz_mpz_tdiv_qr" external tdiv_q_ui : t -> t -> int -> int = "camlidl_mpz_mpz_tdiv_q_ui" external tdiv_r_ui : t -> t -> int -> int = "camlidl_mpz_mpz_tdiv_r_ui" external tdiv_qr_ui : t -> t -> t -> int -> int = "camlidl_mpz_mpz_tdiv_qr_ui" external tdiv_ui : t -> int -> int = "camlidl_mpz_mpz_tdiv_ui" external tdiv_q_2exp : t -> t -> int -> unit = "camlidl_mpz_mpz_tdiv_q_2exp" external tdiv_r_2exp : t -> t -> int -> unit = "camlidl_mpz_mpz_tdiv_r_2exp" (** {3 Other division-related functions} *) external gmod : t -> t -> t -> unit = "camlidl_mpz_mpz_gmod" external gmod_ui : t -> t -> int -> int = "camlidl_mpz_mpz_gmod_ui" external divexact : t -> t -> t -> unit = "camlidl_mpz_mpz_divexact" external divexact_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_divexact_ui" external divisible_p : t -> t -> bool = "camlidl_mpz_mpz_divisible_p" external divisible_ui_p : t -> int -> bool = "camlidl_mpz_mpz_divisible_ui_p" external divisible_2exp_p : t -> int -> bool = "camlidl_mpz_mpz_divisible_2exp_p" external congruent_p : t -> t -> t -> bool = "camlidl_mpz_mpz_congruent_p" external congruent_ui_p : t -> int -> int -> bool = "camlidl_mpz_mpz_congruent_ui_p" external congruent_2exp_p : t -> t -> int -> bool = "camlidl_mpz_mpz_congruent_2exp_p" (** {2 Exponentiation Functions} *) (** {{:http://gmplib.org/manual/Integer-Exponentiation.html#Integer-Exponentiation}C documentation} *) external _powm : t -> t -> t -> t -> unit = "camlidl_mpz_mpz__powm" external _powm_ui : t -> t -> int -> t -> unit = "camlidl_mpz_mpz__powm_ui" let powm a b c ~modulo = _powm a b c modulo let powm_ui a b c ~modulo = _powm_ui a b c modulo external pow_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_pow_ui" external ui_pow_ui : t -> int -> int -> unit = "camlidl_mpz_mpz_ui_pow_ui" (** {2 Root Extraction Functions} *) (** {{:http://gmplib.org/manual/Integer-Roots.html#Integer-Roots}C documentation} *) external root : t -> t -> int -> bool = "camlidl_mpz_mpz_root" external sqrt : t -> t -> unit = "camlidl_mpz_mpz_sqrt" external _sqrtrem : t -> t -> t -> unit = "camlidl_mpz_mpz__sqrtrem" let sqrtrem a ~remainder b = _sqrtrem a remainder b external perfect_power_p : t -> bool = "camlidl_mpz_mpz_perfect_power_p" external perfect_square_p : t -> bool = "camlidl_mpz_mpz_perfect_square_p" (** {2 Number Theoretic Functions} *) (** {{:http://gmplib.org/manual/Number-Theoretic-Functions.html#Number-Theoretic-Functions}C documentation} *) external probab_prime_p : t -> int -> int = "camlidl_mpz_mpz_probab_prime_p" external nextprime : t -> t -> unit = "camlidl_mpz_mpz_nextprime" external gcd : t -> t -> t -> unit = "camlidl_mpz_mpz_gcd" external gcd_ui : t option -> t -> int -> int = "camlidl_mpz_mpz_gcd_ui" external _gcdext : t -> t -> t -> t -> t -> unit = "camlidl_mpz_mpz__gcdext" let gcdext ~gcd ~alpha ~beta a b = _gcdext gcd alpha beta a b external lcm : t -> t -> t -> unit = "camlidl_mpz_mpz_lcm" external lcm_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_lcm_ui" external invert : t -> t -> t -> bool = "camlidl_mpz_mpz_invert" external jacobi : t -> t -> int = "camlidl_mpz_mpz_jacobi" external legendre : t -> t -> int = "camlidl_mpz_mpz_legendre" external kronecker : t -> t -> int = "camlidl_mpz_mpz_kronecker" external kronecker_si : t -> int -> int = "camlidl_mpz_mpz_kronecker_si" external si_kronecker : int -> t -> int = "camlidl_mpz_mpz_si_kronecker" external remove : t -> t -> t -> int = "camlidl_mpz_mpz_remove" external fac_ui : t -> int -> unit = "camlidl_mpz_mpz_fac_ui" external bin_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_bin_ui" external bin_uiui : t -> int -> int -> unit = "camlidl_mpz_mpz_bin_uiui" external fib_ui : t -> int -> unit = "camlidl_mpz_mpz_fib_ui" external fib2_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_fib2_ui" external lucnum_ui : t -> int -> unit = "camlidl_mpz_mpz_lucnum_ui" external lucnum2_ui : t -> t -> int -> unit = "camlidl_mpz_mpz_lucnum2_ui" (** {2 Comparison Functions} *) (** {{:http://gmplib.org/manual/Integer-Comparisons.html#Integer-Comparisons}C documentation} *) external cmp : t -> t -> int = "camlidl_mpz_mpz_cmp" external cmp_d : t -> float -> int = "camlidl_mpz_mpz_cmp_d" external cmp_si : t -> int -> int = "camlidl_mpz_mpz_cmp_si" external cmpabs : t -> t -> int = "camlidl_mpz_mpz_cmpabs" external cmpabs_d : t -> float -> int = "camlidl_mpz_mpz_cmpabs_d" external cmpabs_ui : t -> int -> int = "camlidl_mpz_mpz_cmpabs_ui" external sgn : t -> int = "camlidl_mpz_mpz_sgn" (** {2 Logical and Bit Manipulation Functions} *) (** {{:http://gmplib.org/manual/Integer-Logic-and-Bit-Fiddling.html#Integer-Logic-and-Bit-Fiddling}C documentation} *) external gand : t -> t -> t -> unit = "camlidl_mpz_mpz_gand" external ior : t -> t -> t -> unit = "camlidl_mpz_mpz_ior" external xor : t -> t -> t -> unit = "camlidl_mpz_mpz_xor" external com : t -> t -> unit = "camlidl_mpz_mpz_com" external popcount : t -> int = "camlidl_mpz_mpz_popcount" external hamdist : t -> t -> int = "camlidl_mpz_mpz_hamdist" external scan0 : t -> int -> int = "camlidl_mpz_mpz_scan0" external scan1 : t -> int -> int = "camlidl_mpz_mpz_scan1" external setbit : t -> int -> unit = "camlidl_mpz_mpz_setbit" external clrbit : t -> int -> unit = "camlidl_mpz_mpz_clrbit" external tstbit : t -> int -> bool = "camlidl_mpz_mpz_tstbit" (** {2 Input and Output Functions: not interfaced} *) (** {2 Random Number Functions: see {!Gmp_random} module} *) (** {2 Integer Import and Export Functions} *) (** {{:ttp://gmplib.org/manual/Integer-Import-and-Export.html#Integer-Import-and-Export}C documentation} *) external _import : t -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t -> int -> int -> unit = "camlidl_mpz_mpz__import" external _export : t -> int -> int -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t = "camlidl_mpz_mpz__export" let import ~dest array ~order ~endian = _import dest array order endian let export x ~order ~endian = _export x order endian (** {2 Miscellaneous Functions} *) (** {{:http://gmplib.org/manual/Miscellaneous-Integer-Functions.html#Miscellaneous-Integer-Functions}C documentation} *) external fits_int_p : t -> bool = "camlidl_mpz_mpz_fits_int_p" external odd_p : t -> bool = "camlidl_mpz_mpz_odd_p" external even_p : t -> bool = "camlidl_mpz_mpz_even_p" external size : t -> int = "camlidl_mpz_mpz_size" external sizeinbase : t -> int -> int = "camlidl_mpz_mpz_sizeinbase" external fits_ulong_p : t -> bool = "camlidl_mpz_mpz_fits_ulong_p" external fits_slong_p : t -> bool = "camlidl_mpz_mpz_fits_slong_p" external fits_uint_p : t -> bool = "camlidl_mpz_mpz_fits_uint_p" external fits_sint_p : t -> bool = "camlidl_mpz_mpz_fits_sint_p" external fits_ushort_p : t -> bool = "camlidl_mpz_mpz_fits_ushort_p" external fits_sshort_p : t -> bool = "camlidl_mpz_mpz_fits_sshort_p" apron-dist-0.9.10/mlgmpidl/Changes0000640014525101416610000000036211165146660016654 0ustar bjeannetpopart Version 1.1: - API * Mpfrf added (functional interface to Mprf). * Random functions for Mpfr numbers in Gmp_random module. - Distribution/Packaging * HTML Links to GMP/MPFR online documentation added in .mli files. Version 1.0: apron-dist-0.9.10/mlgmpidl/mpz_caml.c0000640014525101416610000016016011252216513017322 0ustar bjeannetpopart/* File generated from mpz.idl */ /* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include "limits.h" #include "caml/custom.h" #include "gmp_caml.h" #define camlidl_ml2c_mpz_mpz_ptr(v,c,ctx) camlidl_mpz_ptr_ml2c(v,c) #define camlidl_c2ml_mpz_mpz_ptr(c,ctx) camlidl_mpz_ptr_c2ml(c) value camlidl_mpz_mpz_init(value _unit) { mpz_t OUTOUTOUT; mpz_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; mpz_init(OUTOUTOUT); _vres = camlidl_c2ml_mpz_mpz_ptr(&OUTTOUTTOUTT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_init2( value _v_N) { mpz_t OUTOUTOUT; mpz_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ unsigned long N; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; N = Long_val(_v_N); mpz_init2(OUTOUTOUT, N); _vres = camlidl_c2ml_mpz_mpz_ptr(&OUTTOUTTOUTT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_realloc2( value _v_ROP, value _v_N) { mpz_ptr ROP; /*in*/ unsigned long N; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); N = Long_val(_v_N); mpz_realloc2(ROP, N); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_set( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); mpz_set(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_set_si( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ long OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); OP = Long_val(_v_OP); mpz_set_si(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_set_d( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ double OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); OP = Double_val(_v_OP); mpz_set_d(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz__set_str( value _v_ROP, value _v_STR, value _v_BASE) { mpz_ptr ROP; /*in*/ char *STR; /*in*/ int BASE; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); STR = String_val(_v_STR); BASE = Int_val(_v_BASE); /* begin user-supplied calling sequence */ { int n = mpz_set_str(ROP,STR,BASE); if (n){ mpz_clear(ROP); caml_invalid_argument(""); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_swap( value _v_ROP1, value _v_ROP2) { mpz_ptr ROP1; /*in*/ mpz_ptr ROP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP1, &ROP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_ROP2, &ROP2, _ctx); mpz_swap(ROP1, ROP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_init_set( value _v_OP) { mpz_t OUTOUTOUT; mpz_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ mpz_ptr OP; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); mpz_init_set(OUTOUTOUT, OP); _vres = camlidl_c2ml_mpz_mpz_ptr(&OUTTOUTTOUTT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_init_set_si( value _v_OP) { mpz_t OUTOUTOUT; mpz_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ long OP; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; OP = Long_val(_v_OP); mpz_init_set_si(OUTOUTOUT, OP); _vres = camlidl_c2ml_mpz_mpz_ptr(&OUTTOUTTOUTT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_init_set_d( value _v_OP) { mpz_t OUTOUTOUT; mpz_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ double OP; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; OP = Double_val(_v_OP); mpz_init_set_d(OUTOUTOUT, OP); _vres = camlidl_c2ml_mpz_mpz_ptr(&OUTTOUTTOUTT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz__init_set_str( value _v_STR, value _v_BASE) { mpz_t OUTOUTOUT; mpz_ptr OUTTOUTTOUTT = OUTOUTOUT;; /*out*/ char *STR; /*in*/ int BASE; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; STR = String_val(_v_STR); BASE = Int_val(_v_BASE); /* begin user-supplied calling sequence */ { int n = mpz_init_set_str(OUTOUTOUT,STR,BASE); if (n){ mpz_clear(OUTOUTOUT); caml_invalid_argument(""); } } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_mpz_mpz_ptr(&OUTTOUTTOUTT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_get_si( value _v_OP) { mpz_ptr OP; /*in*/ long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_get_si(OP); _vres = copy_nativeint(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_get_int( value _v_OP) { mpz_ptr OP; /*in*/ long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); /* begin user-supplied calling sequence */ _res = mpz_get_si(OP); /* end user-supplied calling sequence */ _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_get_d( value _v_OP) { mpz_ptr OP; /*in*/ double _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_get_d(OP); _vres = copy_double(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_get_d_2exp( value _v_OP) { long *EXP; /*out*/ mpz_ptr OP; /*in*/ double _res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; long _c1; value _vresult; value _vres[2] = { 0, 0, }; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); EXP = &_c1; _res = mpz_get_d_2exp(EXP, OP); Begin_roots_block(_vres, 2) _vres[0] = copy_double(_res); _vres[1] = Val_long(*EXP); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); return _vresult; } value camlidl_mpz_mpz__get_str( value _v_BASE, value _v_OP) { int BASE; /*in*/ mpz_ptr OP; /*in*/ char *_res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; BASE = Int_val(_v_BASE); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); /* begin user-supplied calling sequence */ _res = mpz_get_str(NULL,BASE,OP); /* end user-supplied calling sequence */ _vres = copy_string(_res); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ free(_res); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_mpz_mpz_add( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_add(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_add_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpz_add_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_sub( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_sub(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_sub_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpz_sub_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_ui_sub( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ unsigned long OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); OP1 = Long_val(_v_OP1); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_ui_sub(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_mul( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_mul(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_mul_si( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpz_mul_si(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_addmul( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_addmul(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_addmul_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpz_addmul_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_submul( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_submul(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_submul_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpz_submul_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_mul_2exp( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpz_mul_2exp(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_neg( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); mpz_neg(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_abs( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); mpz_abs(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_cdiv_q( value _v_Q, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_cdiv_q(Q, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_cdiv_r( value _v_R, value _v_N, value _v_D) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_cdiv_r(R, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_cdiv_qr( value _v_Q, value _v_R, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_cdiv_qr(Q, R, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_cdiv_q_ui( value _v_Q, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_cdiv_q_ui(Q, N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_cdiv_r_ui( value _v_R, value _v_N, value _v_D) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_cdiv_r_ui(R, N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_cdiv_qr_ui( value _v_Q, value _v_R, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_cdiv_qr_ui(Q, R, N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_cdiv_ui( value _v_N, value _v_D) { mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_cdiv_ui(N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_cdiv_q_2exp( value _v_Q, value _v_N, value _v_B) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ unsigned long B; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); B = Long_val(_v_B); mpz_cdiv_q_2exp(Q, N, B); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_cdiv_r_2exp( value _v_R, value _v_N, value _v_B) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long B; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); B = Long_val(_v_B); mpz_cdiv_r_2exp(R, N, B); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_fdiv_q( value _v_Q, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_fdiv_q(Q, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_fdiv_r( value _v_R, value _v_N, value _v_D) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_fdiv_r(R, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_fdiv_qr( value _v_Q, value _v_R, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_fdiv_qr(Q, R, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_fdiv_q_ui( value _v_Q, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_fdiv_q_ui(Q, N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fdiv_r_ui( value _v_R, value _v_N, value _v_D) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_fdiv_r_ui(R, N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fdiv_qr_ui( value _v_Q, value _v_R, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_fdiv_qr_ui(Q, R, N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fdiv_ui( value _v_N, value _v_D) { mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_fdiv_ui(N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fdiv_q_2exp( value _v_Q, value _v_N, value _v_B) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ unsigned long B; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); B = Long_val(_v_B); mpz_fdiv_q_2exp(Q, N, B); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_fdiv_r_2exp( value _v_R, value _v_N, value _v_B) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long B; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); B = Long_val(_v_B); mpz_fdiv_r_2exp(R, N, B); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_tdiv_q( value _v_Q, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_tdiv_q(Q, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_tdiv_r( value _v_R, value _v_N, value _v_D) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_tdiv_r(R, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_tdiv_qr( value _v_Q, value _v_R, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_tdiv_qr(Q, R, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_tdiv_q_ui( value _v_Q, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_tdiv_q_ui(Q, N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_tdiv_r_ui( value _v_R, value _v_N, value _v_D) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_tdiv_r_ui(R, N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_tdiv_qr_ui( value _v_Q, value _v_R, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_tdiv_qr_ui(Q, R, N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_tdiv_ui( value _v_N, value _v_D) { mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_tdiv_ui(N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_tdiv_q_2exp( value _v_Q, value _v_N, value _v_B) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ unsigned long B; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); B = Long_val(_v_B); mpz_tdiv_q_2exp(Q, N, B); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_tdiv_r_2exp( value _v_R, value _v_N, value _v_B) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long B; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); B = Long_val(_v_B); mpz_tdiv_r_2exp(R, N, B); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_gmod( value _v_R, value _v_N, value _v_D) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); /* begin user-supplied calling sequence */ mpz_mod(R,N,D); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_gmod_ui( value _v_R, value _v_N, value _v_D) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); /* begin user-supplied calling sequence */ _res = mpz_mod_ui(R,N,D); /* end user-supplied calling sequence */ _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_divexact( value _v_Q, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_divexact(Q, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_divexact_ui( value _v_Q, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); mpz_divexact_ui(Q, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_divisible_p( value _v_N, value _v_D) { mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); _res = mpz_divisible_p(N, D); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_divisible_ui_p( value _v_N, value _v_D) { mpz_ptr N; /*in*/ unsigned long D; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_divisible_ui_p(N, D); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_divisible_2exp_p( value _v_N, value _v_B) { mpz_ptr N; /*in*/ unsigned long B; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); B = Long_val(_v_B); _res = mpz_divisible_2exp_p(N, B); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_congruent_p( value _v_N, value _v_C, value _v_D) { mpz_ptr N; /*in*/ mpz_ptr C; /*in*/ mpz_ptr D; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_C, &C, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); _res = mpz_congruent_p(N, C, D); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_congruent_ui_p( value _v_N, value _v_C, value _v_D) { mpz_ptr N; /*in*/ unsigned long C; /*in*/ unsigned long D; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); C = Long_val(_v_C); D = Long_val(_v_D); _res = mpz_congruent_ui_p(N, C, D); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_congruent_2exp_p( value _v_N, value _v_C, value _v_B) { mpz_ptr N; /*in*/ mpz_ptr C; /*in*/ unsigned long B; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_C, &C, _ctx); B = Long_val(_v_B); _res = mpz_congruent_2exp_p(N, C, B); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz__powm( value _v_ROP, value _v_BASE, value _v_EXP, value _v_MOD) { mpz_ptr ROP; /*in*/ mpz_ptr BASE; /*in*/ mpz_ptr EXP; /*in*/ mpz_ptr MOD; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_BASE, &BASE, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_EXP, &EXP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_MOD, &MOD, _ctx); /* begin user-supplied calling sequence */ mpz_powm(ROP,BASE,EXP,MOD); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz__powm_ui( value _v_ROP, value _v_BASE, value _v_EXP, value _v_MOD) { mpz_ptr ROP; /*in*/ mpz_ptr BASE; /*in*/ unsigned long EXP; /*in*/ mpz_ptr MOD; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_BASE, &BASE, _ctx); EXP = Long_val(_v_EXP); camlidl_ml2c_mpz_mpz_ptr(_v_MOD, &MOD, _ctx); /* begin user-supplied calling sequence */ mpz_powm_ui(ROP,BASE,EXP,MOD); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_pow_ui( value _v_ROP, value _v_BASE, value _v_EXP) { mpz_ptr ROP; /*in*/ mpz_ptr BASE; /*in*/ unsigned long EXP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_BASE, &BASE, _ctx); EXP = Long_val(_v_EXP); mpz_pow_ui(ROP, BASE, EXP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_ui_pow_ui( value _v_ROP, value _v_BASE, value _v_EXP) { mpz_ptr ROP; /*in*/ unsigned long BASE; /*in*/ unsigned long EXP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); BASE = Long_val(_v_BASE); EXP = Long_val(_v_EXP); mpz_ui_pow_ui(ROP, BASE, EXP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_root( value _v_ROP, value _v_OP, value _v_N) { mpz_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ unsigned long N; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); N = Long_val(_v_N); _res = mpz_root(ROP, OP, N); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_sqrt( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); mpz_sqrt(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz__sqrtrem( value _v_ROP1, value _v_ROP2, value _v_OP) { mpz_ptr ROP1; /*in*/ mpz_ptr ROP2; /*in*/ mpz_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP1, &ROP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_ROP2, &ROP2, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); /* begin user-supplied calling sequence */ mpz_sqrtrem(ROP1,ROP2,OP); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_perfect_power_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_perfect_power_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_perfect_square_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_perfect_square_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_probab_prime_p( value _v_N, value _v_REPS) { mpz_ptr N; /*in*/ int REPS; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); REPS = Int_val(_v_REPS); _res = mpz_probab_prime_p(N, REPS); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_nextprime( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); mpz_nextprime(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_gcd( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_gcd(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_gcd_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr *ROP; /*in*/ mpz_ptr OP1; /*in*/ unsigned long OP2; /*in*/ unsigned long _res; value _v1; mpz_ptr _c2; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; if (_v_ROP == Val_int(0)) { ROP = NULL; } else { _v1 = Field(_v_ROP, 0); ROP = &_c2; camlidl_ml2c_mpz_mpz_ptr(_v1, &_c2, _ctx); } camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); /* begin user-supplied calling sequence */ _res = mpz_gcd_ui(ROP ? *ROP : NULL,OP1,OP2); /* end user-supplied calling sequence */ _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz__gcdext( value _v_G, value _v_S, value _v_T, value _v_A, value _v_B) { mpz_ptr G; /*in*/ mpz_ptr S; /*in*/ mpz_ptr T; /*in*/ mpz_ptr A; /*in*/ mpz_ptr B; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_G, &G, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_S, &S, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_T, &T, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_A, &A, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_B, &B, _ctx); /* begin user-supplied calling sequence */ mpz_gcdext(G,S,T,A,B); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_lcm( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_lcm(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_lcm_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpz_lcm_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_invert( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); _res = mpz_invert(ROP, OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_jacobi( value _v_A, value _v_B) { mpz_ptr A; /*in*/ mpz_ptr B; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_A, &A, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_B, &B, _ctx); _res = mpz_jacobi(A, B); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_legendre( value _v_A, value _v_P) { mpz_ptr A; /*in*/ mpz_ptr P; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_A, &A, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_P, &P, _ctx); _res = mpz_legendre(A, P); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_kronecker( value _v_A, value _v_B) { mpz_ptr A; /*in*/ mpz_ptr B; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_A, &A, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_B, &B, _ctx); _res = mpz_kronecker(A, B); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_kronecker_si( value _v_A, value _v_B) { mpz_ptr A; /*in*/ long B; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_A, &A, _ctx); B = Long_val(_v_B); _res = mpz_kronecker_si(A, B); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_si_kronecker( value _v_A, value _v_B) { long A; /*in*/ mpz_ptr B; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; A = Long_val(_v_A); camlidl_ml2c_mpz_mpz_ptr(_v_B, &B, _ctx); _res = mpz_si_kronecker(A, B); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_remove( value _v_ROP, value _v_OP, value _v_F) { mpz_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ mpz_ptr F; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_F, &F, _ctx); _res = mpz_remove(ROP, OP, F); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fac_ui( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ unsigned long OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); OP = Long_val(_v_OP); mpz_fac_ui(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_bin_ui( value _v_ROP, value _v_N, value _v_K) { mpz_ptr ROP; /*in*/ mpz_ptr N; /*in*/ unsigned long K; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); K = Long_val(_v_K); mpz_bin_ui(ROP, N, K); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_bin_uiui( value _v_ROP, value _v_N, value _v_K) { mpz_ptr ROP; /*in*/ unsigned long N; /*in*/ unsigned long K; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); N = Long_val(_v_N); K = Long_val(_v_K); mpz_bin_uiui(ROP, N, K); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_fib_ui( value _v_FN, value _v_N) { mpz_ptr FN; /*in*/ unsigned long N; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_FN, &FN, _ctx); N = Long_val(_v_N); mpz_fib_ui(FN, N); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_fib2_ui( value _v_FN, value _v_FNSUB1, value _v_N) { mpz_ptr FN; /*in*/ mpz_ptr FNSUB1; /*in*/ unsigned long N; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_FN, &FN, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_FNSUB1, &FNSUB1, _ctx); N = Long_val(_v_N); mpz_fib2_ui(FN, FNSUB1, N); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_lucnum_ui( value _v_LN, value _v_N) { mpz_ptr LN; /*in*/ unsigned long N; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_LN, &LN, _ctx); N = Long_val(_v_N); mpz_lucnum_ui(LN, N); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_lucnum2_ui( value _v_LN, value _v_LNSUB1, value _v_N) { mpz_ptr LN; /*in*/ mpz_ptr LNSUB1; /*in*/ unsigned long N; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_LN, &LN, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_LNSUB1, &LNSUB1, _ctx); N = Long_val(_v_N); mpz_lucnum2_ui(LN, LNSUB1, N); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_cmp( value _v_OP1, value _v_OP2) { mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); _res = mpz_cmp(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_cmp_d( value _v_OP1, value _v_OP2) { mpz_ptr OP1; /*in*/ double OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Double_val(_v_OP2); _res = mpz_cmp_d(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_cmp_si( value _v_OP1, value _v_OP2) { mpz_ptr OP1; /*in*/ long OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); _res = mpz_cmp_si(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_cmpabs( value _v_OP1, value _v_OP2) { mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); _res = mpz_cmpabs(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_cmpabs_d( value _v_OP1, value _v_OP2) { mpz_ptr OP1; /*in*/ double OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Double_val(_v_OP2); _res = mpz_cmpabs_d(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_cmpabs_ui( value _v_OP1, value _v_OP2) { mpz_ptr OP1; /*in*/ unsigned long OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); _res = mpz_cmpabs_ui(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_sgn( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_sgn(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_gand( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); /* begin user-supplied calling sequence */ mpz_and(ROP,OP1,OP2); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_ior( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_ior(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_xor( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_xor(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_com( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); mpz_com(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_popcount( value _v_OP) { mpz_ptr OP; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); /* begin user-supplied calling sequence */ _res = mpz_popcount(OP); if (_res==ULONG_MAX) _res = Max_long; /* end user-supplied calling sequence */ _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_hamdist( value _v_OP1, value _v_OP2) { mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); /* begin user-supplied calling sequence */ _res = mpz_hamdist(OP1,OP2); if (_res==ULONG_MAX) _res = Max_long; /* end user-supplied calling sequence */ _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_scan0( value _v_OP, value _v_STARTING_BIT) { mpz_ptr OP; /*in*/ unsigned long STARTING_BIT; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); STARTING_BIT = Long_val(_v_STARTING_BIT); /* begin user-supplied calling sequence */ _res = mpz_scan0(OP,STARTING_BIT); if (_res==ULONG_MAX) _res = Max_long; /* end user-supplied calling sequence */ _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_scan1( value _v_OP, value _v_STARTING_BIT) { mpz_ptr OP; /*in*/ unsigned long STARTING_BIT; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); STARTING_BIT = Long_val(_v_STARTING_BIT); /* begin user-supplied calling sequence */ _res = mpz_scan1(OP,STARTING_BIT); if (_res==ULONG_MAX) _res = Max_long; /* end user-supplied calling sequence */ _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_setbit( value _v_ROP, value _v_BIT_INDEX) { mpz_ptr ROP; /*in*/ unsigned long BIT_INDEX; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); BIT_INDEX = Long_val(_v_BIT_INDEX); mpz_setbit(ROP, BIT_INDEX); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_clrbit( value _v_ROP, value _v_BIT_INDEX) { mpz_ptr ROP; /*in*/ unsigned long BIT_INDEX; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); BIT_INDEX = Long_val(_v_BIT_INDEX); mpz_clrbit(ROP, BIT_INDEX); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_tstbit( value _v_OP, value _v_BIT_INDEX) { mpz_ptr OP; /*in*/ unsigned long BIT_INDEX; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); BIT_INDEX = Long_val(_v_BIT_INDEX); _res = mpz_tstbit(OP, BIT_INDEX); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz__import( value _v_ROP, value _v_OP, value _v_ORDER, value _v_ENDIAN) { mpz_ptr ROP; /*in*/ int COUNT; /*in*/ int *OP; /*in*/ int ORDER; /*in*/ int ENDIAN; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); OP = Bigarray_val(_v_OP)->data; COUNT = Bigarray_val(_v_OP)->dim[0]; ORDER = Int_val(_v_ORDER); ENDIAN = Int_val(_v_ENDIAN); /* begin user-supplied calling sequence */ mpz_import (ROP, COUNT, ORDER, sizeof(intnat), ENDIAN, 0, OP); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz__export( value _v_OP, value _v_ORDER, value _v_ENDIAN) { mpz_ptr OP; /*in*/ int ORDER; /*in*/ int ENDIAN; /*in*/ unsigned int *COUNT; /*out*/ int *_res; unsigned int _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); ORDER = Int_val(_v_ORDER); ENDIAN = Int_val(_v_ENDIAN); COUNT = &_c1; /* begin user-supplied calling sequence */ _res = mpz_export (NULL, COUNT, ORDER, sizeof(intnat), ENDIAN, 0, OP); /* end user-supplied calling sequence */ _vres = alloc_bigarray_dims( BIGARRAY_INT32 | BIGARRAY_C_LAYOUT | BIGARRAY_MANAGED, 1, _res, COUNT); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fits_int_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_fits_int_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_odd_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_odd_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_even_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_even_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_size( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_size(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_sizeinbase( value _v_OP, value _v_BASE) { mpz_ptr OP; /*in*/ int BASE; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); BASE = Int_val(_v_BASE); /* begin user-supplied calling sequence */ if (BASE<2 || BASE>36) caml_invalid_argument("Argument not supported"); _res = mpz_sizeinbase (OP,BASE); /* end user-supplied calling sequence */ _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fits_ulong_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_fits_ulong_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fits_slong_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_fits_slong_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fits_uint_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_fits_uint_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fits_sint_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_fits_sint_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fits_ushort_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_fits_ushort_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fits_sshort_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_fits_sshort_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } apron-dist-0.9.10/mlgmpidl/mpz.idl0000640014525101416610000003631211165125334016660 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \"limits.h\"\n\ #include \"caml/custom.h\"\n\ #include \"gmp_caml.h\"\n\ ") typedef [abstract,c2ml(camlidl_mpz_ptr_c2ml),ml2c(camlidl_mpz_ptr_ml2c)] struct __mpz_struct* mpz_ptr; quote(MLMLI,"(** GMP multi-precision integers *)\n\n") quote(MLMLI,"(** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x].\n\n These functions are as efficient as their C counterpart: they do not imply additional memory allocation, unlike the corresponding functions in the module {!Mpzf}. *)\n\n") /* OUTOUTOUT is a reserved variable name ! (see Makefile and sedscript_c) */ quote(MLI,"\n(** {2 Pretty printing} *)\n") quote(MLI,"val print : Format.formatter -> t -> unit") quote(MLMLI,"\n(** {2 Initialization Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Initializing-Integers.html#Initializing-Integers}C documentation} *)\n") void mpz_init([out] mpz_ptr OUTOUTOUT); void mpz_init2([out] mpz_ptr OUTOUTOUT, unsigned long N); void mpz_realloc2 (mpz_ptr ROP, unsigned long N); quote(MLMLI,"\n(** {2 Assignement Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Assigning-Integers.html#Assigning-Integers}C documentation} *)\n") quote(MLMLI,"\n(** The first parameter holds the result. *)\n") void mpz_set(mpz_ptr ROP, mpz_ptr OP); void mpz_set_si(mpz_ptr ROP, long int OP); void mpz_set_d (mpz_ptr ROP, double OP); quote(MLI,"\n(** For [set_q: t -> Mpq.t -> unit], see {!Mpq.get_z} *)\n\n") /* void mpz_set_q (mpz_ptr ROP, mpq_t OP); */ void mpz__set_str (mpz_ptr ROP, [string]char* STR, int BASE) quote(call,"{\n\ int n = mpz_set_str(ROP,STR,BASE);\n\ if (n){ mpz_clear(ROP); caml_invalid_argument(\"\"); }\n\ }"); quote(MLI,"val set_str : t -> string -> base:int -> unit") quote(ML,"let set_str a b ~base = _set_str a b base") void mpz_swap (mpz_ptr ROP1, mpz_ptr ROP2); quote(MLMLI,"\n(** {2 Combined Initialization and Assignment Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Simultaneous-Integer-Init-_0026-Assign.html#Simultaneous-Integer-Init-_0026-Assign}C documentation} *)\n") void mpz_init_set ([out]mpz_ptr OUTOUTOUT, mpz_ptr OP); void mpz_init_set_si ([out]mpz_ptr OUTOUTOUT, signed long int OP); void mpz_init_set_d ([out]mpz_ptr OUTOUTOUT, double OP); void mpz__init_set_str([out]mpz_ptr OUTOUTOUT, [string]char *STR, int BASE) quote(call,"\ {\n\ int n = mpz_init_set_str(OUTOUTOUT,STR,BASE);\n\ if (n){ mpz_clear(OUTOUTOUT); caml_invalid_argument(\"\"); }\n\ }"); quote(MLI,"val init_set_str : string -> base:int -> t") quote(ML,"let init_set_str a ~base = _init_set_str a base") quote(MLMLI,"\n(** {2 Conversion Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Converting-Integers.html#Converting-Integers}C documentation} *)\n") [nativeint]signed long int mpz_get_si (mpz_ptr OP); signed long int mpz_get_int (mpz_ptr OP) quote(call,"_res = mpz_get_si(OP);"); double mpz_get_d (mpz_ptr OP); double mpz_get_d_2exp ([out]signed long int *EXP, mpz_ptr OP); [string]char* mpz__get_str (int BASE, mpz_ptr OP) quote(call,"_res = mpz_get_str(NULL,BASE,OP);") quote(dealloc,"free(_res);"); quote(MLI,"val get_str : base:int -> t -> string") quote(ML,"let get_str ~base a = _get_str base a") quote(MLMLI,"\n\n(** {2 User Conversions} *)\n") quote(MLMLI,"(** These functions are additions to or renaming of functions offered by the C library. *)\n") quote(MLI,"val to_string : t -> string") quote(MLI,"val to_float : t -> float") quote(ML,"let to_string x = get_str 10 x") quote(ML,"let to_float = get_d") quote(MLI,"val of_string : string -> t") quote(MLI,"val of_float : float -> t") quote(MLI,"val of_int : int -> t") quote(ML,"let of_string str = init_set_str str 10") quote(ML,"let of_float = init_set_d") quote(ML,"let of_int = init_set_si") quote(ML,"\n(** {2 Pretty printing} *)\n") quote(ML,"let print fmt x = Format.pp_print_string fmt (get_str 10 x)") quote(MLMLI,"\n(** {2 Arithmetic Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Arithmetic.html#Integer-Arithmetic}C documentation} *)\n") quote(MLMLI,"(** The first parameter holds the result. *)\n") void mpz_add (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_add_ui (mpz_ptr ROP, mpz_ptr OP1, unsigned long int OP2); void mpz_sub (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_sub_ui (mpz_ptr ROP, mpz_ptr OP1, unsigned long int OP2); void mpz_ui_sub (mpz_ptr ROP, unsigned long int OP1, mpz_ptr OP2); void mpz_mul (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_mul_si (mpz_ptr ROP, mpz_ptr OP1, long int OP2); void mpz_addmul (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_addmul_ui (mpz_ptr ROP, mpz_ptr OP1, unsigned long int OP2); void mpz_submul (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_submul_ui (mpz_ptr ROP, mpz_ptr OP1, unsigned long int OP2); void mpz_mul_2exp (mpz_ptr ROP, mpz_ptr OP1, unsigned long int OP2); void mpz_neg (mpz_ptr ROP, mpz_ptr OP); void mpz_abs (mpz_ptr ROP, mpz_ptr OP); quote(MLMLI,"\n(** {2 Division Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Division.html#Integer-Division}C documentation} *)\n") quote(MLMLI,"(** [c] stands for ceiling, [f] for floor, and [t] for truncate (rounds toward 0).*)") quote(MLMLI,"(** {3 Ceiling division} *)\n") quote(MLMLI,"(** The first parameter holds the quotient. *)") void mpz_cdiv_q (mpz_ptr Q, mpz_ptr N, mpz_ptr D); quote(MLMLI,"(** The first parameter holds the remainder. *)") void mpz_cdiv_r (mpz_ptr R, mpz_ptr N, mpz_ptr D); quote(MLMLI,"(** The two first parameters hold resp. the quotient and the remainder). *)") void mpz_cdiv_qr (mpz_ptr Q, mpz_ptr R, mpz_ptr N, mpz_ptr D); quote(MLMLI,"(** The first parameter holds the quotient. *)") unsigned long int mpz_cdiv_q_ui (mpz_ptr Q, mpz_ptr N, unsigned long int D); quote(MLMLI,"(** The first parameter holds the remainder. *)") unsigned long int mpz_cdiv_r_ui (mpz_ptr R, mpz_ptr N, unsigned long int D); quote(MLMLI,"(** The two first parameters hold resp. the quotient and the remainder). *)") unsigned long int mpz_cdiv_qr_ui (mpz_ptr Q, mpz_ptr R, mpz_ptr N, unsigned long int D); unsigned long int mpz_cdiv_ui (mpz_ptr N, unsigned long int D); quote(MLMLI,"(** The first parameter holds the quotient. *)") void mpz_cdiv_q_2exp (mpz_ptr Q, mpz_ptr N, unsigned long int B); quote(MLMLI,"(** The first parameter holds the remainder. *)") void mpz_cdiv_r_2exp (mpz_ptr R, mpz_ptr N, unsigned long int B); quote(MLMLI,"(** {3 Floor division} *)\n") void mpz_fdiv_q (mpz_ptr Q, mpz_ptr N, mpz_ptr D); void mpz_fdiv_r (mpz_ptr R, mpz_ptr N, mpz_ptr D); void mpz_fdiv_qr (mpz_ptr Q, mpz_ptr R, mpz_ptr N, mpz_ptr D); unsigned long int mpz_fdiv_q_ui (mpz_ptr Q, mpz_ptr N, unsigned long int D); unsigned long int mpz_fdiv_r_ui (mpz_ptr R, mpz_ptr N, unsigned long int D); unsigned long int mpz_fdiv_qr_ui (mpz_ptr Q, mpz_ptr R, mpz_ptr N, unsigned long int D); unsigned long int mpz_fdiv_ui (mpz_ptr N, unsigned long int D); void mpz_fdiv_q_2exp (mpz_ptr Q, mpz_ptr N, unsigned long int B); void mpz_fdiv_r_2exp (mpz_ptr R, mpz_ptr N, unsigned long int B); quote(MLMLI,"(** {3 Truncate division} *)\n") void mpz_tdiv_q (mpz_ptr Q, mpz_ptr N, mpz_ptr D); void mpz_tdiv_r (mpz_ptr R, mpz_ptr N, mpz_ptr D); void mpz_tdiv_qr (mpz_ptr Q, mpz_ptr R, mpz_ptr N, mpz_ptr D); unsigned long int mpz_tdiv_q_ui (mpz_ptr Q, mpz_ptr N, unsigned long int D); unsigned long int mpz_tdiv_r_ui (mpz_ptr R, mpz_ptr N, unsigned long int D); unsigned long int mpz_tdiv_qr_ui (mpz_ptr Q, mpz_ptr R, mpz_ptr N, unsigned long int D); unsigned long int mpz_tdiv_ui (mpz_ptr N, unsigned long int D); void mpz_tdiv_q_2exp (mpz_ptr Q, mpz_ptr N, unsigned long int B); void mpz_tdiv_r_2exp (mpz_ptr R, mpz_ptr N, unsigned long int B); quote(MLMLI,"(** {3 Other division-related functions} *)\n") void mpz_gmod (mpz_ptr R, mpz_ptr N, mpz_ptr D) quote(call,"mpz_mod(R,N,D);"); unsigned long int mpz_gmod_ui (mpz_ptr R, mpz_ptr N, unsigned long int D) quote(call,"_res = mpz_mod_ui(R,N,D);"); void mpz_divexact (mpz_ptr Q, mpz_ptr N, mpz_ptr D); void mpz_divexact_ui (mpz_ptr Q, mpz_ptr N, unsigned long D); boolean mpz_divisible_p (mpz_ptr N, mpz_ptr D); boolean mpz_divisible_ui_p (mpz_ptr N, unsigned long int D); boolean mpz_divisible_2exp_p (mpz_ptr N, unsigned long int B); boolean mpz_congruent_p (mpz_ptr N, mpz_ptr C, mpz_ptr D); boolean mpz_congruent_ui_p (mpz_ptr N, unsigned long int C, unsigned long int D); boolean mpz_congruent_2exp_p (mpz_ptr N, mpz_ptr C, unsigned long int B); quote(MLMLI,"\n(** {2 Exponentiation Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Exponentiation.html#Integer-Exponentiation}C documentation} *)\n") void mpz__powm (mpz_ptr ROP, mpz_ptr BASE, mpz_ptr EXP, mpz_ptr MOD) quote(call,"mpz_powm(ROP,BASE,EXP,MOD);"); void mpz__powm_ui (mpz_ptr ROP, mpz_ptr BASE, unsigned long int EXP, mpz_ptr MOD) quote(call,"mpz_powm_ui(ROP,BASE,EXP,MOD);"); quote(MLI,"\ val powm : t -> t -> t -> modulo:t -> unit\n\ val powm_ui : t -> t -> int -> modulo:t -> unit\n\ ") quote(ML,"\ let powm a b c ~modulo = _powm a b c modulo\n\ let powm_ui a b c ~modulo = _powm_ui a b c modulo\n\ ") void mpz_pow_ui (mpz_ptr ROP, mpz_ptr BASE, unsigned long int EXP); void mpz_ui_pow_ui (mpz_ptr ROP, unsigned long int BASE,unsigned long int EXP); quote(MLMLI,"\n(** {2 Root Extraction Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Roots.html#Integer-Roots}C documentation} *)\n") boolean mpz_root (mpz_ptr ROP, mpz_ptr OP, unsigned long int N); void mpz_sqrt (mpz_ptr ROP, mpz_ptr OP); void mpz__sqrtrem (mpz_ptr ROP1, mpz_ptr ROP2, mpz_ptr OP) quote(call,"mpz_sqrtrem(ROP1,ROP2,OP);"); quote(MLI,"val sqrtrem : t -> remainder:t -> t -> unit") quote(ML,"let sqrtrem a ~remainder b = _sqrtrem a remainder b") boolean mpz_perfect_power_p (mpz_ptr OP); boolean mpz_perfect_square_p (mpz_ptr OP); quote(MLMLI,"\n(** {2 Number Theoretic Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Number-Theoretic-Functions.html#Number-Theoretic-Functions}C documentation} *)\n") int mpz_probab_prime_p (mpz_ptr N, int REPS); void mpz_nextprime (mpz_ptr ROP, mpz_ptr OP); void mpz_gcd (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); unsigned long int mpz_gcd_ui ([unique]mpz_ptr* ROP, mpz_ptr OP1, unsigned long int OP2) quote(call,"_res = mpz_gcd_ui(ROP ? *ROP : NULL,OP1,OP2);"); void mpz__gcdext (mpz_ptr G, mpz_ptr S, mpz_ptr T, mpz_ptr A, mpz_ptr B) quote(call,"mpz_gcdext(G,S,T,A,B);"); quote(MLI,"val gcdext : gcd:t -> alpha:t -> beta:t -> t -> t -> unit") quote(ML,"let gcdext ~gcd ~alpha ~beta a b = _gcdext gcd alpha beta a b") void mpz_lcm (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_lcm_ui (mpz_ptr ROP, mpz_ptr OP1, unsigned long OP2); boolean mpz_invert (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); int mpz_jacobi (mpz_ptr A, mpz_ptr B); int mpz_legendre (mpz_ptr A, mpz_ptr P); int mpz_kronecker (mpz_ptr A, mpz_ptr B); int mpz_kronecker_si (mpz_ptr A, long B); int mpz_si_kronecker (long A, mpz_ptr B); unsigned long int mpz_remove (mpz_ptr ROP, mpz_ptr OP, mpz_ptr F); void mpz_fac_ui (mpz_ptr ROP, unsigned long int OP); void mpz_bin_ui (mpz_ptr ROP, mpz_ptr N, unsigned long int K); void mpz_bin_uiui (mpz_ptr ROP, unsigned long int N, unsigned long int K); void mpz_fib_ui (mpz_ptr FN, unsigned long int N); void mpz_fib2_ui (mpz_ptr FN, mpz_ptr FNSUB1, unsigned long N); void mpz_lucnum_ui (mpz_ptr LN, unsigned long int N); void mpz_lucnum2_ui (mpz_ptr LN, mpz_ptr LNSUB1, unsigned long int N); quote(MLMLI,"\n(** {2 Comparison Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Comparisons.html#Integer-Comparisons}C documentation} *)\n") int mpz_cmp (mpz_ptr OP1, mpz_ptr OP2); int mpz_cmp_d (mpz_ptr OP1, double OP2); int mpz_cmp_si (mpz_ptr OP1, signed long int OP2); int mpz_cmpabs (mpz_ptr OP1, mpz_ptr OP2); int mpz_cmpabs_d (mpz_ptr OP1, double OP2); int mpz_cmpabs_ui (mpz_ptr OP1, unsigned long int OP2); int mpz_sgn (mpz_ptr OP); quote(MLMLI,"\n(** {2 Logical and Bit Manipulation Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Logic-and-Bit-Fiddling.html#Integer-Logic-and-Bit-Fiddling}C documentation} *)\n") void mpz_gand (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2) quote(call,"mpz_and(ROP,OP1,OP2);"); void mpz_ior (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_xor (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_com (mpz_ptr ROP, mpz_ptr OP); unsigned long int mpz_popcount (mpz_ptr OP) quote(call,"_res = mpz_popcount(OP); if (_res==ULONG_MAX) _res = Max_long;"); unsigned long int mpz_hamdist (mpz_ptr OP1, mpz_ptr OP2) quote(call,"_res = mpz_hamdist(OP1,OP2); if (_res==ULONG_MAX) _res = Max_long;"); unsigned long int mpz_scan0 (mpz_ptr OP, unsigned long int STARTING_BIT) quote(call,"_res = mpz_scan0(OP,STARTING_BIT); if (_res==ULONG_MAX) _res = Max_long;"); unsigned long int mpz_scan1 (mpz_ptr OP, unsigned long int STARTING_BIT) quote(call,"_res = mpz_scan1(OP,STARTING_BIT); if (_res==ULONG_MAX) _res = Max_long;"); void mpz_setbit (mpz_ptr ROP, unsigned long int BIT_INDEX); void mpz_clrbit (mpz_ptr ROP, unsigned long int BIT_INDEX); boolean mpz_tstbit (mpz_ptr OP, unsigned long int BIT_INDEX); quote(MLMLI,"\n(** {2 Input and Output Functions: not interfaced} *)\n") quote(MLMLI,"\n(** {2 Random Number Functions: see {!Gmp_random} module} *)\n") quote(MLMLI,"\n(** {2 Integer Import and Export Functions} *)") quote(MLMLI,"(** {{:ttp://gmplib.org/manual/Integer-Import-and-Export.html#Integer-Import-and-Export}C documentation} *)\n") void mpz__import (mpz_ptr ROP, int COUNT, [size_is(COUNT),bigarray] int OP[], int ORDER, int ENDIAN) quote(call,"mpz_import (ROP, COUNT, ORDER, sizeof(intnat), ENDIAN, 0, OP);"); [size_is(COUNT),bigarray,managed] int* mpz__export (mpz_ptr OP, int ORDER, int ENDIAN, [out,ignore]unsigned int *COUNT) quote(call,"_res = mpz_export (NULL, COUNT, ORDER, sizeof(intnat), ENDIAN, 0, OP);"); quote(MLI,"\ val import : dest:t -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t -> order:int -> endian:int -> unit\n\ val export : t -> order:int -> endian:int -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t\n\ ") quote(ML,"\ let import ~dest array ~order ~endian = _import dest array order endian\n\ let export x ~order ~endian = _export x order endian\n\ ") quote(MLMLI,"\n(** {2 Miscellaneous Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Miscellaneous-Integer-Functions.html#Miscellaneous-Integer-Functions}C documentation} *)\n") quote(MLI,"\n(* Does it fit in an OCaml integer *)") boolean mpz_fits_int_p (mpz_ptr OP); boolean mpz_odd_p (mpz_ptr OP); boolean mpz_even_p (mpz_ptr OP); int mpz_size(mpz_ptr OP); int mpz_sizeinbase (mpz_ptr OP, int BASE) quote(call,"\ if (BASE<2 || BASE>36) caml_invalid_argument(\"Argument not supported\");\n\ _res = mpz_sizeinbase (OP,BASE);"); quote(MLI,"\n(* Limited relevance here *)") boolean mpz_fits_ulong_p (mpz_ptr OP); boolean mpz_fits_slong_p (mpz_ptr OP); boolean mpz_fits_uint_p (mpz_ptr OP); boolean mpz_fits_sint_p (mpz_ptr OP); boolean mpz_fits_ushort_p (mpz_ptr OP); boolean mpz_fits_sshort_p (mpz_ptr OP); apron-dist-0.9.10/mlgmpidl/sedscript_c0000640014525101416610000000141610644461001017575 0ustar bjeannetpopart# SED script applied to C files generated by CAMLIDL # # 1. Insert a comment after first line # 1 a\\n/* This file is part of the MLGmpIDL interface, released under LGPL license.\n Please read the COPYING file packaged in the distribution */ # # 2. Subtle trick: when encountering a variable named OUTOUTOUTT, # (which represent an out paramater) # substitute to the declaration: mpz_ptr OUTOUTOUT; # the declarations: mpz_t OUTOUTOUT; mpz_ptr OUTTOUTTOUTT=OUTOUTOUT # s/\([^ ]*\)_ptr OUTOUTOUT/\1_t OUTOUTOUT\; \1_ptr OUTTOUTTOUTT = OUTOUTOUT;/g; # # this is because mpz_ptr does not allocate the stack space # needed for the mpz_t to be returned. # # 3.Substitution when calling camlidl_c2ml_mpz_mpz_ptr # s/(&OUTOUTOUT/(\&OUTTOUTTOUTT/g; s/struct mpfr_rnd_t/mpfr_rnd_t/g; apron-dist-0.9.10/mlgmpidl/README0000640014525101416610000000602511251722332016233 0ustar bjeannetpopart# $Id$ # This file is part of the MLGmpIDL OCaml interface for GMP (and MPFR), # released under LGPL license. # Please read the COPYING file packaged in the distribution This package is an OCAML interface for GMP and MPFR libraries. The interface is decomposed into 5 modules: Mpz : GMP multiprecision integers Mpzf : GMP multiprecision integers, functional version (no side-effect on numbers) Mpq : GMP multiprecision rationals Mpqf : GMP multiprecision rationals, functional version (no side-effect on numbers) Mpf : GMP multiprecision floating-point numbers Gmp_random: GMP random numbers generation Mpfr : MPFR multiprecision floating-point numbers Mpfrf : MPFR multiprecision floating-point numbers, functional version (no side-effect on numbers) Compared to the well-known MLGMP interface developped by D. Monniaux (http://www.di.ens.fr/~monniaux/programmes.html.en), MLGMPIDL favours an imperative interface to a functional interface (all functions are offered in an imperative version, more efficient in term of memory allocation). Moreover, it uses CamlIDL, which allows to design easily further OCaml/C interface that needs GMP types, using "import mpz.idl" clauses. The APRON project exploits this. REQUIREMENTS ============ GMP library (tested with version 4.0 and up) MPFR library (optional, tested with version 2.2.x) OCaml 3.0 or up (tested with 3.09) Camlidl (tested with 1.05) GNU sed, version 4.1 or up INSTALLATION ============ 1. Library ---------- Set the file Makefile.config using the Makefile.config model to your own setting. You might also have to modify the Makefile for executables type 'make rebuild', which builds .ml, .mli, and _caml.c files from .idl files. type 'make', and then 'make install' The OCaml part of the library is named gmp.cma (.cmxa, .a). The C part of the library is named libgmp_caml.a (libgmp_caml_debug.a), or, with dynamic linking, dllgmp_caml.so. 'make install' installs not only .mli, .cmi, but also .idl files. Be aware however that importing those .idl files from other .idl files will probably request the application of SED editor with the scripts sedscript_caml and sedscript_c (look at the Makefile). 2. Linking ------------ gmp.cma requires bigarray.cma. Look at the rule for session.byte and session.opt executable in the Makefile to see how to link against gmp.cma/gmp.cmxa. 3. Interpreter and toplevel --------------------------- With dynamic linking, you can use ordinary runtime ocamlrun and toplevel, otherwise 'make gmprun', 'make gmptop' You can play with [session.ml], and compile it with 'make session.byte', 'make session.opt'. 4. Documentation ---------------- The documentation (currently, just refers to GMP and MPFR doc) is generated with ocamldoc. 'make mlgmpidl.pdf' 'make html' (put the HTML files in the html subdirectoy) 5. Miscellaneous ---------------- 'make clean' and 'make distclean' have the usual behaviour. 'make mostlyclean', in addition to 'make clean', removes the .ml, .mli and _caml.c files generated from .idl files. apron-dist-0.9.10/mlgmpidl/mpq.idl0000640014525101416610000001344611165146562016660 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \"caml/custom.h\"\n\ #include \"gmp_caml.h\"\n\ ") import "mpz.idl"; typedef [abstract,c2ml(camlidl_mpq_ptr_c2ml),ml2c(camlidl_mpq_ptr_ml2c)] struct __mpq_struct* mpq_ptr; quote(MLMLI,"(** GMP multiprecision rationals *)\n\n") quote(MLMLI,"(** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x].\n\n These functions are as efficient as their C counterpart: they do not imply additional memory allocation, unlike the corresponding functions in the module {!Mpqf}. *)\n\n") /* OUTOUTOUT is a reserved variable name ! (see Makefile and sedscript_c) */ void mpq_canonicalize (mpq_ptr OP); quote(MLI,"\n(** {2 Pretty printing} *)\n") quote(MLI,"val print : Format.formatter -> t -> unit") quote(MLMLI,"\n(** {2 Initialization and Assignment Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Initializing-Rationals.html#Initializing-Rationals}C documentation} *)\n") void mpq_init([out] mpq_ptr OUTOUTOUT); void mpq_set(mpq_ptr ROP, mpq_ptr OP); void mpq_set_z (mpq_ptr ROP, mpz_ptr OP); void mpq_set_si (mpq_ptr ROP, signed long int OP1, unsigned long int OP2) quote(dealloc, "mpq_canonicalize(ROP);"); void mpq__set_str(mpq_ptr ROP, [string]char* STR, int BASE) quote(call,"{\n\ int n = mpq_set_str(ROP,STR,BASE);\n\ if (n){ mpq_clear(ROP); caml_invalid_argument(\"\"); }\n\ }") quote(dealloc, "mpq_canonicalize(ROP);"); quote(MLI,"val set_str : t -> string -> base:int -> unit") quote(ML,"let set_str a b ~base = _set_str a b base") void mpq_swap (mpq_ptr ROP1, mpq_ptr ROP2); quote(MLI,"(** {2 Additional Initialization and Assignements functions} *)\n") quote(MLI,"(** These functions are additions to or renaming of functions offered by the C library. *)\n") quote(MLI,"val init_set : t -> t") quote(MLI,"val init_set_z : Mpz.t -> t") quote(MLI,"val init_set_si : int -> int -> t") quote(MLI,"val init_set_str : string -> base:int -> t") quote(MLI,"val init_set_d : float -> t") quote(MLMLI,"\n(** {2 Conversion Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Rational-Conversions.html#Rational-Conversions}C documentation} *)\n") double mpq_get_d (mpq_ptr OP); void mpq_set_d (mpq_ptr ROP, double OP); quote(MLI,"\n(* Replace Mpz.set_q: Mpz.t -> Mpq.t -> unit *)") void mpq_get_z(mpz_ptr ROP, mpq_ptr OP) quote(call,"mpz_set_q(ROP,OP);"); quote(MLI,"\n(* For set_f: t -> Mpf.t -> unit, see Mpf.get_q *)\n\n") /* void mpq_set_f (mpq_ptr ROP, mpf_ptr OP); */ [string]char* mpq__get_str (int BASE, mpq_ptr OP) quote(call,"_res = mpq_get_str(NULL,BASE,OP);") quote(dealloc,"free(_res);"); quote(MLI,"val get_str : base:int -> t -> string") quote(ML,"let get_str ~base a = _get_str base a") quote(MLI,"\n(** {2 User Conversions} *)\n") quote(MLI,"(** These functionss are additions to or renaming of functions offeered by the C library. *)\n") quote(MLI,"val to_string : t -> string") quote(MLI,"val to_float : t -> float") quote(MLI,"val of_string : string -> t") quote(MLI,"val of_float : float -> t") quote(MLI,"val of_int : int -> t") quote(MLI,"val of_frac : int -> int -> t") quote(MLI,"val of_mpz : Mpz.t -> t") quote(MLI,"val of_mpz2 : Mpz.t -> Mpz.t -> t") quote(MLMLI,"\n(** {2 Arithmetic Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Rational-Arithmetic.html#Rational-Arithmetic}C documentation} *)\n") void mpq_add (mpq_ptr ROP, mpq_ptr OP1, mpq_ptr OP2); void mpq_sub (mpq_ptr ROP, mpq_ptr OP1, mpq_ptr OP2); void mpq_mul (mpq_ptr ROP, mpq_ptr OP1, mpq_ptr OP2); void mpq_mul_2exp (mpq_ptr ROP, mpq_ptr OP1, unsigned long int OP2); void mpq_div (mpq_ptr ROP, mpq_ptr OP1, mpq_ptr OP2); void mpq_div_2exp (mpq_ptr ROP, mpq_ptr OP1, unsigned long int OP2); void mpq_neg (mpq_ptr ROP, mpq_ptr OP); void mpq_abs (mpq_ptr ROP, mpq_ptr OP); void mpq_inv (mpq_ptr ROP, mpq_ptr OP); quote(MLMLI,"\n(** {2 Comparison Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Comparing-Rationals.html#Comparing-Rationals}C documentation} *)\n") int mpq_cmp (mpq_ptr OP1, mpq_ptr OP2); int mpq_cmp_si (mpq_ptr OP1, long int NUM2, unsigned long int DEN2); int mpq_sgn (mpq_ptr OP); boolean mpq_equal (mpq_ptr OP1, mpq_ptr OP2); quote(MLMLI,"\n(** {2 Applying Integer Functions to Rationals} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Applying-Integer-Functions.html#Applying-Integer-Functions}C documentation} *)\n") void mpq_get_num (mpz_ptr NUMERATOR, mpq_ptr RATIONAL); void mpq_get_den (mpz_ptr DENOMINATOR, mpq_ptr RATIONAL); void mpq_set_num (mpq_ptr RATIONAL, mpz_ptr NUMERATOR); void mpq_set_den (mpq_ptr RATIONAL, mpz_ptr DENOMINATOR); quote(MLMLI,"\n(** {2 Input and Output Functions: not interfaced} *)\n") quote(ML,"\n(** {2 Pretty printing} *)\n") quote(ML,"let print fmt x = Format.pp_print_string fmt (get_str 10 x)") quote(ML,"let init_set x = let y = init() in set y x; y") quote(ML,"let init_set_z z = let x = init() in set_z x z; x") quote(ML,"let init_set_si n d = let x = init() in set_si x n d; x") quote(ML,"let init_set_str str ~base = let x = init() in ignore (set_str x str ~base); x") quote(ML,"let init_set_d d = let x = init() in set_d x d; x") quote(ML,"let to_string x = get_str 10 x") quote(ML,"let to_float = get_d") quote(ML,"let of_string str = init_set_str str 10") quote(ML,"let of_float = init_set_d") quote(ML,"let of_int a = init_set_si a 1") quote(ML,"let of_frac = init_set_si") quote(ML,"let of_mpz = init_set_z") quote(ML,"let of_mpz2 num den = let res = init() in set_num res num; set_den res den; canonicalize res; res") apron-dist-0.9.10/mlgmpidl/tmp/0000750014525101416610000000000011252216514016150 5ustar bjeannetpopartapron-dist-0.9.10/mlgmpidl/tmp/mpfr.ml0000640014525101416610000004021611252216513017451 0ustar bjeannetpopart(* File generated from mpfr.idl *) type mpfr_ptr and mpfr_rnd_t = | Near | Zero | Up | Down (** MPFR multiprecision floating-point numbers *) (** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x]. These functions are as efficient as their C counterpart: they do not imply additional memory allocation. *) (** {2 Rounding Modes} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Rounding-Related-Functions}C documentation} *) external mpfr_set_default_rounding_mode : mpfr_rnd_t -> unit = "camlidl_mpfr_mpfr_set_default_rounding_mode" external mpfr_get_default_rounding_mode : unit -> mpfr_rnd_t = "camlidl_mpfr_mpfr_get_default_rounding_mode" external mpfr_round_prec : mpfr_ptr -> mpfr_rnd_t -> int -> int = "camlidl_mpfr_mpfr_round_prec" (** {2 Exceptions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Exception-Related-Functions}C documentation} *) external mpfr_get_emin : unit -> int = "camlidl_mpfr_mpfr_get_emin" external mpfr_get_emax : unit -> int = "camlidl_mpfr_mpfr_get_emax" external mpfr_set_emin : int -> unit = "camlidl_mpfr_mpfr_set_emin" external mpfr_set_emax : int -> unit = "camlidl_mpfr_mpfr_set_emax" external mpfr_check_range : mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_check_range" external mpfr_clear_underflow : unit -> unit = "camlidl_mpfr_mpfr_clear_underflow" external mpfr_clear_overflow : unit -> unit = "camlidl_mpfr_mpfr_clear_overflow" external mpfr_clear_nanflag : unit -> unit = "camlidl_mpfr_mpfr_clear_nanflag" external mpfr_clear_inexflag : unit -> unit = "camlidl_mpfr_mpfr_clear_inexflag" external mpfr_clear_flags : unit -> unit = "camlidl_mpfr_mpfr_clear_flags" external mpfr_underflow_p : unit -> bool = "camlidl_mpfr_mpfr_underflow_p" external mpfr_overflow_p : unit -> bool = "camlidl_mpfr_mpfr_overflow_p" external mpfr_nanflag_p : unit -> bool = "camlidl_mpfr_mpfr_nanflag_p" external mpfr_inexflag_p : unit -> bool = "camlidl_mpfr_mpfr_inexflag_p" (** {2 Initialization Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Initialization-Functions}C documentation} *) external mpfr_set_default_prec : int -> unit = "camlidl_mpfr_mpfr_set_default_prec" external mpfr_get_default_prec : unit -> int = "camlidl_mpfr_mpfr_get_default_prec" external mpfr_init : unit -> mpfr_ptr = "camlidl_mpfr_mpfr_init" external mpfr_init2 : int -> mpfr_ptr = "camlidl_mpfr_mpfr_init2" external mpfr_get_prec : mpfr_ptr -> int = "camlidl_mpfr_mpfr_get_prec" external mpfr_set_prec : mpfr_ptr -> int -> unit = "camlidl_mpfr_mpfr_set_prec" external mpfr_set_prec_raw : mpfr_ptr -> int -> unit = "camlidl_mpfr_mpfr_set_prec_raw" (** {2 Assignment Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Assignment-Functions}C documentation} *) external mpfr_set : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_set" external mpfr_set_si : mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_set_si" external mpfr_set_d : mpfr_ptr -> float -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_set_d" external mpfr_set_z : mpfr_ptr -> Mpz.mpz_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_set_z" external mpfr_set_q : mpfr_ptr -> Mpq.mpq_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_set_q" external mpfr__set_str : mpfr_ptr -> string -> int -> mpfr_rnd_t -> unit = "camlidl_mpfr_mpfr__set_str" let set_str a b ~base round = _set_str a b base round external mpfr_set_f : mpfr_ptr -> Mpf.mpf_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_set_f" external mpfr_set_si_2exp : mpfr_ptr -> int -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_set_si_2exp" external mpfr_set_inf : mpfr_ptr -> int -> unit = "camlidl_mpfr_mpfr_set_inf" external mpfr_set_nan : mpfr_ptr -> unit = "camlidl_mpfr_mpfr_set_nan" external mpfr_swap : mpfr_ptr -> mpfr_ptr -> unit = "camlidl_mpfr_mpfr_swap" (** {2 Combined Initialization and Assignment Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Combined-Initialization-and-Assignment-Functions}C documentation} *) external mpfr_init_set : mpfr_ptr -> mpfr_rnd_t -> int * mpfr_ptr = "camlidl_mpfr_mpfr_init_set" external mpfr_init_set_si : int -> mpfr_rnd_t -> int * mpfr_ptr = "camlidl_mpfr_mpfr_init_set_si" external mpfr_init_set_d : float -> mpfr_rnd_t -> int * mpfr_ptr = "camlidl_mpfr_mpfr_init_set_d" external mpfr_init_set_f : Mpf.mpf_ptr -> mpfr_rnd_t -> int * mpfr_ptr = "camlidl_mpfr_mpfr_init_set_f" external mpfr_init_set_z : Mpz.mpz_ptr -> mpfr_rnd_t -> int * mpfr_ptr = "camlidl_mpfr_mpfr_init_set_z" external mpfr_init_set_q : Mpq.mpq_ptr -> mpfr_rnd_t -> int * mpfr_ptr = "camlidl_mpfr_mpfr_init_set_q" external mpfr__init_set_str : string -> int -> mpfr_rnd_t -> mpfr_ptr = "camlidl_mpfr_mpfr__init_set_str" let init_set_str a ~base round = _init_set_str a base round (** {2 Conversion Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Conversion-Functions}C documentation} *) external mpfr_get_d : mpfr_ptr -> mpfr_rnd_t -> float = "camlidl_mpfr_mpfr_get_d" external mpfr_get_d1 : mpfr_ptr -> float = "camlidl_mpfr_mpfr_get_d1" external mpfr_get_z_exp : Mpz.mpz_ptr -> mpfr_ptr -> int = "camlidl_mpfr_mpfr_get_z_exp" external mpfr_get_z : Mpz.mpz_ptr -> mpfr_ptr -> mpfr_rnd_t -> unit = "camlidl_mpfr_mpfr_get_z" external mpfr__get_str : int -> int -> mpfr_ptr -> mpfr_rnd_t -> string * int = "camlidl_mpfr_mpfr__get_str" let get_str ~base ~digits a round = _get_str base digits a round (** {2 Basic Arithmetic Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Basic-Arithmetic-Functions}C documentation} *) external mpfr_add : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_add" external mpfr_add_ui : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_add_ui" external mpfr_add_z : mpfr_ptr -> mpfr_ptr -> Mpz.mpz_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_add_z" external mpfr_add_q : mpfr_ptr -> mpfr_ptr -> Mpq.mpq_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_add_q" external mpfr_sub : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_sub" external mpfr_ui_sub : mpfr_ptr -> int -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_ui_sub" external mpfr_sub_ui : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_sub_ui" external mpfr_sub_z : mpfr_ptr -> mpfr_ptr -> Mpz.mpz_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_sub_z" external mpfr_sub_q : mpfr_ptr -> mpfr_ptr -> Mpq.mpq_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_sub_q" external mpfr_mul : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_mul" external mpfr_mul_ui : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_mul_ui" external mpfr_mul_z : mpfr_ptr -> mpfr_ptr -> Mpz.mpz_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_mul_z" external mpfr_mul_q : mpfr_ptr -> mpfr_ptr -> Mpq.mpq_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_mul_q" external mpfr_mul_2ui : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_mul_2ui" external mpfr_mul_2si : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_mul_2si" external mpfr_mul_2exp : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_mul_2exp" external mpfr_div : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_div" external mpfr_ui_div : mpfr_ptr -> int -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_ui_div" external mpfr_div_ui : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_div_ui" external mpfr_div_z : mpfr_ptr -> mpfr_ptr -> Mpz.mpz_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_div_z" external mpfr_div_q : mpfr_ptr -> mpfr_ptr -> Mpq.mpq_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_div_q" external mpfr_div_2ui : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_div_2ui" external mpfr_div_2si : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_div_2si" let div_2exp = div_2ui external mpfr_sqrt : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> bool = "camlidl_mpfr_mpfr_sqrt" external mpfr_sqrt_ui : mpfr_ptr -> int -> mpfr_rnd_t -> bool = "camlidl_mpfr_mpfr_sqrt_ui" external mpfr_pow_ui : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> bool = "camlidl_mpfr_mpfr_pow_ui" external mpfr_pow_si : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> bool = "camlidl_mpfr_mpfr_pow_si" external mpfr_ui_pow_ui : mpfr_ptr -> int -> int -> mpfr_rnd_t -> bool = "camlidl_mpfr_mpfr_ui_pow_ui" external mpfr_ui_pow : mpfr_ptr -> int -> mpfr_ptr -> mpfr_rnd_t -> bool = "camlidl_mpfr_mpfr_ui_pow" external mpfr_pow : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> bool = "camlidl_mpfr_mpfr_pow" external mpfr_neg : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_neg" external mpfr_abs : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_abs" (** {2 Comparison Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Comparison-Functions}C documentation} *) external mpfr_cmp : mpfr_ptr -> mpfr_ptr -> int = "camlidl_mpfr_mpfr_cmp" external mpfr_cmp_si : mpfr_ptr -> int -> int = "camlidl_mpfr_mpfr_cmp_si" external mpfr_cmp_si_2exp : mpfr_ptr -> int -> int -> int = "camlidl_mpfr_mpfr_cmp_si_2exp" external mpfr_sgn : mpfr_ptr -> int = "camlidl_mpfr_mpfr_sgn" external mpfr__equal : mpfr_ptr -> mpfr_ptr -> int -> bool = "camlidl_mpfr_mpfr__equal" let equal a b ~bits = _equal a b bits external mpfr_nan_p : mpfr_ptr -> bool = "camlidl_mpfr_mpfr_nan_p" external mpfr_inf_p : mpfr_ptr -> bool = "camlidl_mpfr_mpfr_inf_p" external mpfr_number_p : mpfr_ptr -> bool = "camlidl_mpfr_mpfr_number_p" external mpfr_reldiff : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> unit = "camlidl_mpfr_mpfr_reldiff" (** {2 Special Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Special-Functions}C documentation} *) external mpfr_log : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_log" external mpfr_log2 : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_log2" external mpfr_log10 : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_log10" external mpfr_exp : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_exp" external mpfr_exp2 : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_exp2" external mpfr_exp10 : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_exp10" external mpfr_cos : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_cos" external mpfr_sin : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_sin" external mpfr_tan : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_tan" external mpfr_sec : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_sec" external mpfr_csc : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_csc" external mpfr_cot : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_cot" external mpfr_sin_cos : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> bool = "camlidl_mpfr_mpfr_sin_cos" external mpfr_acos : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_acos" external mpfr_asin : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_asin" external mpfr_atan : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_atan" external mpfr_atan2 : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_atan2" external mpfr_cosh : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_cosh" external mpfr_sinh : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_sinh" external mpfr_tanh : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_tanh" external mpfr_sech : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_sech" external mpfr_csch : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_csch" external mpfr_coth : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_coth" external mpfr_acosh : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_acosh" external mpfr_asinh : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_asinh" external mpfr_atanh : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_atanh" external mpfr_fac_ui : mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_fac_ui" external mpfr_log1p : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_log1p" external mpfr_expm1 : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_expm1" external mpfr_eint : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_eint" external mpfr_gamma : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_gamma" external mpfr_lngamma : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_lngamma" external mpfr_zeta : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_zeta" external mpfr_erf : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_erf" external mpfr_erfc : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_erfc" external mpfr_fma : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_fma" external mpfr_agm : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_agm" external mpfr_hypot : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_hypot" external mpfr_const_log2 : mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_const_log2" external mpfr_const_pi : mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_const_pi" external mpfr_const_euler : mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_const_euler" external mpfr_const_catalan : mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_const_catalan" (** {2 Input and Output Functions: not interfaced} *) (** {2 Miscellaneous Float Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Rounding-Related-Functions}C documentation} *) external mpfr_rint : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_rint" external mpfr_ceil : mpfr_ptr -> mpfr_ptr -> int = "camlidl_mpfr_mpfr_ceil" external mpfr_floor : mpfr_ptr -> mpfr_ptr -> int = "camlidl_mpfr_mpfr_floor" external mpfr_round : mpfr_ptr -> mpfr_ptr -> int = "camlidl_mpfr_mpfr_round" external mpfr_trunc : mpfr_ptr -> mpfr_ptr -> int = "camlidl_mpfr_mpfr_trunc" external mpfr_integer_p : mpfr_ptr -> bool = "camlidl_mpfr_mpfr_integer_p" external mpfr_nexttoward : mpfr_ptr -> mpfr_ptr -> unit = "camlidl_mpfr_mpfr_nexttoward" external mpfr_nextabove : mpfr_ptr -> unit = "camlidl_mpfr_mpfr_nextabove" external mpfr_nextbelow : mpfr_ptr -> unit = "camlidl_mpfr_mpfr_nextbelow" external mpfr_min : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_min" external mpfr_max : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_max" external mpfr_get_exp : mpfr_ptr -> int = "camlidl_mpfr_mpfr_get_exp" external mpfr_set_exp : mpfr_ptr -> int -> int = "camlidl_mpfr_mpfr_set_exp" (** {2 Additional functions} *) let to_string x = let (s,e) = get_str ~base:10 ~digits:0 x Near in if s="" then "0.0" else Format.sprintf "0.%sE%i" s e (** {2 Pretty printing} *) let print fmt x = let (s,e) = get_str ~base:10 ~digits:0 x Near in if s="" then Format.pp_print_string fmt "0.0" else Format.fprintf fmt "0.%sE%i" s e let string_of_round = function | Near -> "Near" | Zero -> "Zero" | Up -> "Up" | Down -> "Down" let print_round fmt x = Format.pp_print_string fmt (string_of_round x) let to_float ?round x = match round with | None -> get_d1 x | Some r -> get_d x r let to_mpq x = let num,den = Mpz.init(), Mpz.init_set_si 1 in let e = get_z_exp num x in Mpz.mul_2exp den den e; Mpq.of_mpz2 num den let of_int x r = snd (init_set_si x r) let of_float x r = snd (init_set_d x r) let of_mpz x r = snd (init_set_z x r) let of_mpq x r = snd (init_set_q x r) let of_string x r = init_set_str x ~base:10 r let of_frac n d r = let mpq = Mpq.of_frac n d in of_mpq mpq r let of_mpz2 n d r = let mpq = Mpq.of_mpz2 n d in of_mpq mpq r apron-dist-0.9.10/mlgmpidl/tmp/gmp_random.ml0000640014525101416610000000407011252216514020627 0ustar bjeannetpopart(* File generated from gmp_random.idl *) type gmp_randstate_ptr (** GMP random generation functions *) (** {2 Random State Initialization} *) (** {{:http://gmplib.org/manual/Random-State-Initialization.html#Random-State-Initialization}C documentation} *) external gmp_randinit_default : unit -> gmp_randstate_ptr = "camlidl_gmp_random_gmp_randinit_default" external gmp_randinit_lc_2exp : Mpz.mpz_ptr -> int -> int -> gmp_randstate_ptr = "camlidl_gmp_random_gmp_randinit_lc_2exp" external gmp_randinit_lc_2exp_size : int -> gmp_randstate_ptr = "camlidl_gmp_random_gmp_randinit_lc_2exp_size" (** {2 Random State Seeding} *) (** {{:http://gmplib.org/manual/Random-State-Seeding.html#Random-State-Seeding}C documentation} *) external gmp_randseed : gmp_randstate_ptr -> Mpz.mpz_ptr -> unit = "camlidl_gmp_random_gmp_randseed" external gmp_randseed_ui : gmp_randstate_ptr -> int -> unit = "camlidl_gmp_random_gmp_randseed_ui" (** {2 Random Number Functions} *) (** {3 Integers ({!Mpz})} *) (** {{:http://gmplib.org/manual/Integer-Random-Numbers.html#Integer-Random-Numbers}C documentation} *) module Mpz = struct external mpz_urandomb : Mpz.mpz_ptr -> gmp_randstate_ptr -> int -> unit = "camlidl_gmp_random_mpz_urandomb" external mpz_urandomm : Mpz.mpz_ptr -> gmp_randstate_ptr -> Mpz.mpz_ptr -> unit = "camlidl_gmp_random_mpz_urandomm" external mpz_rrandomb : Mpz.mpz_ptr -> gmp_randstate_ptr -> int -> unit = "camlidl_gmp_random_mpz_rrandomb" end (** {3 Floating-point ({!Mpf})} *) (** {{:http://gmplib.org/manual/Miscellaneous-Float-Functions.html#Miscellaneous-Float-Functions}C documentation} *) module Mpf = struct external mpf_urandomb : Mpf.mpf_ptr -> gmp_randstate_ptr -> int -> unit = "camlidl_gmp_random_mpf_urandomb" end (** {3 Floating-point ({!Mpfr})} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Miscellaneous-Functions}C documentation} *) module Mpfr = struct external mpfr_urandomb : Mpfr.mpfr_ptr -> gmp_randstate_ptr -> unit = "camlidl_gmp_random_mpfr_urandomb" external mpfr_random : Mpfr.mpfr_ptr -> unit = "camlidl_gmp_random_mpfr_random" end apron-dist-0.9.10/mlgmpidl/tmp/mpf.ml0000640014525101416610000001546511252216513017277 0ustar bjeannetpopart(* File generated from mpf.idl *) type mpf_ptr (** GMP multiprecision floating-point numbers *) (** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x]. These functions are as efficient as their C counterpart: they do not imply additional memory allocation. *) (** {2 Initialization Functions} *) (** {{:http://gmplib.org/manual/Initializing-Floats.html#Initializing-Floats}C documentation} *) external mpf_set_default_prec : int -> unit = "camlidl_mpf_mpf_set_default_prec" external mpf_get_default_prec : unit -> int = "camlidl_mpf_mpf_get_default_prec" external mpf_init : unit -> mpf_ptr = "camlidl_mpf_mpf_init" external mpf_init2 : int -> mpf_ptr = "camlidl_mpf_mpf_init2" external mpf_get_prec : mpf_ptr -> int = "camlidl_mpf_mpf_get_prec" external mpf_set_prec : mpf_ptr -> int -> unit = "camlidl_mpf_mpf_set_prec" external mpf_set_prec_raw : mpf_ptr -> int -> unit = "camlidl_mpf_mpf_set_prec_raw" (** {2 Assignement Functions} *) (** {{:http://gmplib.org/manual/Assigning-Floats.html#Assigning-Floats}C documentation} *) external mpf_set : mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_set" external mpf_set_si : mpf_ptr -> int -> unit = "camlidl_mpf_mpf_set_si" external mpf_set_d : mpf_ptr -> float -> unit = "camlidl_mpf_mpf_set_d" external mpf_set_z : mpf_ptr -> Mpz.mpz_ptr -> unit = "camlidl_mpf_mpf_set_z" external mpf_set_q : mpf_ptr -> Mpq.mpq_ptr -> unit = "camlidl_mpf_mpf_set_q" external mpf__set_str : mpf_ptr -> string -> int -> unit = "camlidl_mpf_mpf__set_str" let set_str a b ~base = _set_str a b base external mpf_swap : mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_swap" (** {2 Combined Initialization and Assignement Functions} *) (** {{:http://gmplib.org/manual/Simultaneous-Float-Init-_0026-Assign.html#Simultaneous-Float-Init-_0026-Assign}C documentation} *) external mpf_init_set : mpf_ptr -> mpf_ptr = "camlidl_mpf_mpf_init_set" external mpf_init_set_si : int -> mpf_ptr = "camlidl_mpf_mpf_init_set_si" external mpf_init_set_d : float -> mpf_ptr = "camlidl_mpf_mpf_init_set_d" external mpf__init_set_str : string -> int -> mpf_ptr = "camlidl_mpf_mpf__init_set_str" let init_set_str a ~base = _init_set_str a base (** {2 Conversion Functions} *) (** {{:http://gmplib.org/manual/Converting-Floats.html#Converting-Floats}C documentation} *) external mpf_get_d : mpf_ptr -> float = "camlidl_mpf_mpf_get_d" external mpf_get_d_2exp : mpf_ptr -> float * int = "camlidl_mpf_mpf_get_d_2exp" external mpf_get_si : mpf_ptr -> nativeint = "camlidl_mpf_mpf_get_si" external mpf_get_int : mpf_ptr -> int = "camlidl_mpf_mpf_get_int" external mpf_get_z : Mpz.mpz_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_get_z" external mpf_get_q : Mpq.mpq_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_get_q" external mpf__get_str : int -> int -> mpf_ptr -> string * int = "camlidl_mpf_mpf__get_str" let get_str ~base ~digits a = _get_str base digits a (** {2 Arithmetic Functions} *) (** {{:http://gmplib.org/manual/Float-Arithmetic.html#Float-Arithmetic}C documentation} *) external mpf_add : mpf_ptr -> mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_add" external mpf_add_ui : mpf_ptr -> mpf_ptr -> int -> unit = "camlidl_mpf_mpf_add_ui" external mpf_sub : mpf_ptr -> mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_sub" external mpf_ui_sub : mpf_ptr -> int -> mpf_ptr -> unit = "camlidl_mpf_mpf_ui_sub" external mpf_sub_ui : mpf_ptr -> mpf_ptr -> int -> unit = "camlidl_mpf_mpf_sub_ui" external mpf_mul : mpf_ptr -> mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_mul" external mpf_mul_ui : mpf_ptr -> mpf_ptr -> int -> unit = "camlidl_mpf_mpf_mul_ui" external mpf_mul_2exp : mpf_ptr -> mpf_ptr -> int -> unit = "camlidl_mpf_mpf_mul_2exp" external mpf_div : mpf_ptr -> mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_div" external mpf_ui_div : mpf_ptr -> int -> mpf_ptr -> unit = "camlidl_mpf_mpf_ui_div" external mpf_div_ui : mpf_ptr -> mpf_ptr -> int -> unit = "camlidl_mpf_mpf_div_ui" external mpf_div_2exp : mpf_ptr -> mpf_ptr -> int -> unit = "camlidl_mpf_mpf_div_2exp" external mpf_sqrt : mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_sqrt" external mpf_pow_ui : mpf_ptr -> mpf_ptr -> int -> unit = "camlidl_mpf_mpf_pow_ui" external mpf_neg : mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_neg" external mpf_abs : mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_abs" (** {2 Comparison Functions} *) (** {{:http://gmplib.org/manual/Float-Comparison.html#Float-Comparison}C documentation} *) external mpf_cmp : mpf_ptr -> mpf_ptr -> int = "camlidl_mpf_mpf_cmp" external mpf_cmp_d : mpf_ptr -> float -> int = "camlidl_mpf_mpf_cmp_d" external mpf_cmp_si : mpf_ptr -> int -> int = "camlidl_mpf_mpf_cmp_si" external mpf_sgn : mpf_ptr -> int = "camlidl_mpf_mpf_sgn" external mpf__equal : mpf_ptr -> mpf_ptr -> int -> bool = "camlidl_mpf_mpf__equal" let equal a b ~bits = _equal a b bits external mpf_reldiff : mpf_ptr -> mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_reldiff" (** {2 Input and Output Functions: not interfaced} *) (** {2 Random Number Functions: see {!Gmp_random} module} *) (** {2 Miscellaneous Float Functions} *) (** {{:http://gmplib.org/manual/Miscellaneous-Float-Functions.html#Miscellaneous-Float-Functions}C documentation} *) external mpf_ceil : mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_ceil" external mpf_floor : mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_floor" external mpf_trunc : mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_trunc" external mpf_integer_p : mpf_ptr -> bool = "camlidl_mpf_mpf_integer_p" external mpf_fits_int_p : mpf_ptr -> bool = "camlidl_mpf_mpf_fits_int_p" external mpf_fits_ulong_p : mpf_ptr -> bool = "camlidl_mpf_mpf_fits_ulong_p" external mpf_fits_slong_p : mpf_ptr -> bool = "camlidl_mpf_mpf_fits_slong_p" external mpf_fits_uint_p : mpf_ptr -> bool = "camlidl_mpf_mpf_fits_uint_p" external mpf_fits_sint_p : mpf_ptr -> bool = "camlidl_mpf_mpf_fits_sint_p" external mpf_fits_ushort_p : mpf_ptr -> bool = "camlidl_mpf_mpf_fits_ushort_p" external mpf_fits_sshort_p : mpf_ptr -> bool = "camlidl_mpf_mpf_fits_sshort_p" (** {2 Additional functions} *) let to_string x = let (s,e) = get_str ~base:10 ~digits:0 x in if s="" then "0.0" else Format.sprintf "0.%se%i" s e let to_float = get_d let of_string str = init_set_str str 10 let of_float = init_set_d let of_int a = init_set_si a let of_mpz x = let res = init() in set_z res x; res let of_mpq x = let res = init() in set_q res x; res let is_integer = integer_p (** {2 Pretty printing} *) let print fmt x = let (s,e) = get_str ~base:10 ~digits:0 x in if s="" then Format.pp_print_string fmt "0.0" else Format.fprintf fmt "0.%se%i" s e apron-dist-0.9.10/mlgmpidl/tmp/gmp_random_stubs.c0000640014525101416610000001541111252216514021662 0ustar bjeannetpopart/* File generated from gmp_random.idl */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include "caml/custom.h" #include "gmp_caml.h" extern void camlidl_mpz_ptr_ml2c(value, mpz_ptr *); #define camlidl_ml2c_mpz_mpz_ptr(v,c,ctx) camlidl_mpz_ptr_ml2c(v,c) extern value camlidl_mpz_ptr_c2ml(mpz_ptr *); #define camlidl_c2ml_mpz_mpz_ptr(c,ctx) camlidl_mpz_ptr_c2ml(c) extern void camlidl_mpq_ptr_ml2c(value, mpq_ptr *); #define camlidl_ml2c_mpq_mpq_ptr(v,c,ctx) camlidl_mpq_ptr_ml2c(v,c) extern value camlidl_mpq_ptr_c2ml(mpq_ptr *); #define camlidl_c2ml_mpq_mpq_ptr(c,ctx) camlidl_mpq_ptr_c2ml(c) extern void camlidl_mpf_ptr_ml2c(value, mpf_ptr *); #define camlidl_ml2c_mpf_mpf_ptr(v,c,ctx) camlidl_mpf_ptr_ml2c(v,c) extern value camlidl_mpf_ptr_c2ml(mpf_ptr *); #define camlidl_c2ml_mpf_mpf_ptr(c,ctx) camlidl_mpf_ptr_c2ml(c) extern void camlidl_mpfr_ptr_ml2c(value, mpfr_ptr *); #define camlidl_ml2c_mpfr_mpfr_ptr(v,c,ctx) camlidl_mpfr_ptr_ml2c(v,c) extern value camlidl_mpfr_ptr_c2ml(mpfr_ptr *); #define camlidl_c2ml_mpfr_mpfr_ptr(c,ctx) camlidl_mpfr_ptr_c2ml(c) extern void camlidl_ml2c_mpfr_struct_mpfr_rnd_t(value, struct mpfr_rnd_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_mpfr_struct_mpfr_rnd_t(struct mpfr_rnd_t *, camlidl_ctx _ctx); extern void camlidl_mpfr_rnd_t_ml2c(value, mpfr_rnd_t *); #define camlidl_ml2c_mpfr_mpfr_rnd_t(v,c,ctx) camlidl_mpfr_rnd_t_ml2c(v,c) extern value camlidl_mpfr_rnd_t_c2ml(mpfr_rnd_t *); #define camlidl_c2ml_mpfr_mpfr_rnd_t(c,ctx) camlidl_mpfr_rnd_t_c2ml(c) #define camlidl_ml2c_gmp_random_gmp_randstate_ptr(v,c,ctx) camlidl_gmp_randstate_ptr_ml2c(v,c) #define camlidl_c2ml_gmp_random_gmp_randstate_ptr(c,ctx) camlidl_gmp_randstate_ptr_c2ml(c) value camlidl_gmp_random_gmp_randinit_default(value _unit) { gmp_randstate_ptr OUTOUTOUT; /*out*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; gmp_randinit_default(OUTOUTOUT); _vres = camlidl_c2ml_gmp_random_gmp_randstate_ptr(&OUTOUTOUT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_gmp_random_gmp_randinit_lc_2exp( value _v_A, value _v_C, value _v_M2EXP) { gmp_randstate_ptr OUTOUTOUT; /*out*/ mpz_ptr A; /*in*/ unsigned long C; /*in*/ unsigned long M2EXP; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_A, &A, _ctx); C = Long_val(_v_C); M2EXP = Long_val(_v_M2EXP); gmp_randinit_lc_2exp(OUTOUTOUT, A, C, M2EXP); _vres = camlidl_c2ml_gmp_random_gmp_randstate_ptr(&OUTOUTOUT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_gmp_random_gmp_randinit_lc_2exp_size( value _v_SIZE) { gmp_randstate_ptr OUTOUTOUT; /*out*/ unsigned long SIZE; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; SIZE = Long_val(_v_SIZE); /* begin user-supplied calling sequence */ { int n = gmp_randinit_lc_2exp_size(OUTOUTOUT,SIZE); if (n==0) caml_invalid_argument("Argument not supported"); } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_gmp_random_gmp_randstate_ptr(&OUTOUTOUT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_gmp_random_gmp_randseed( value _v_STATE, value _v_SEED) { gmp_randstate_ptr STATE; /*in*/ mpz_ptr SEED; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_gmp_random_gmp_randstate_ptr(_v_STATE, &STATE, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_SEED, &SEED, _ctx); gmp_randseed(STATE, SEED); camlidl_free(_ctx); return Val_unit; } value camlidl_gmp_random_gmp_randseed_ui( value _v_STATE, value _v_SEED) { gmp_randstate_ptr STATE; /*in*/ unsigned long SEED; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_gmp_random_gmp_randstate_ptr(_v_STATE, &STATE, _ctx); SEED = Long_val(_v_SEED); gmp_randseed_ui(STATE, SEED); camlidl_free(_ctx); return Val_unit; } value camlidl_gmp_random_mpz_urandomb( value _v_ROP, value _v_STATE, value _v_N) { mpz_ptr ROP; /*in*/ gmp_randstate_ptr STATE; /*in*/ unsigned long N; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_gmp_random_gmp_randstate_ptr(_v_STATE, &STATE, _ctx); N = Long_val(_v_N); mpz_urandomb(ROP, STATE, N); camlidl_free(_ctx); return Val_unit; } value camlidl_gmp_random_mpz_urandomm( value _v_ROP, value _v_STATE, value _v_N) { mpz_ptr ROP; /*in*/ gmp_randstate_ptr STATE; /*in*/ mpz_ptr N; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_gmp_random_gmp_randstate_ptr(_v_STATE, &STATE, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); mpz_urandomm(ROP, STATE, N); camlidl_free(_ctx); return Val_unit; } value camlidl_gmp_random_mpz_rrandomb( value _v_ROP, value _v_STATE, value _v_N) { mpz_ptr ROP; /*in*/ gmp_randstate_ptr STATE; /*in*/ unsigned long N; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_gmp_random_gmp_randstate_ptr(_v_STATE, &STATE, _ctx); N = Long_val(_v_N); mpz_rrandomb(ROP, STATE, N); camlidl_free(_ctx); return Val_unit; } value camlidl_gmp_random_mpf_urandomb( value _v_ROP, value _v_STATE, value _v_N) { mpf_ptr ROP; /*in*/ gmp_randstate_ptr STATE; /*in*/ unsigned long N; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_gmp_random_gmp_randstate_ptr(_v_STATE, &STATE, _ctx); N = Long_val(_v_N); mpf_urandomb(ROP, STATE, N); camlidl_free(_ctx); return Val_unit; } value camlidl_gmp_random_mpfr_urandomb( value _v_ROP, value _v_STATE) { mpfr_ptr ROP; /*in*/ gmp_randstate_ptr STATE; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_gmp_random_gmp_randstate_ptr(_v_STATE, &STATE, _ctx); mpfr_urandomb(ROP, STATE); camlidl_free(_ctx); return Val_unit; } value camlidl_gmp_random_mpfr_random( value _v_ROP) { mpfr_ptr ROP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); mpfr_random(ROP); camlidl_free(_ctx); return Val_unit; } apron-dist-0.9.10/mlgmpidl/tmp/mpf.idl0000640014525101416610000001727111252216513017434 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \"caml/custom.h\"\n\ #include \"gmp_caml.h\"\n\ ") import "mpz.idl"; import "mpq.idl"; typedef [abstract,c2ml(camlidl_mpf_ptr_c2ml),ml2c(camlidl_mpf_ptr_ml2c)] struct __mpf_struct* mpf_ptr; quote(MLMLI,"(** GMP multiprecision floating-point numbers *)\n\n") quote(MLMLI,"(** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x].\n\n These functions are as efficient as their C counterpart: they do not imply additional memory allocation. *)\n\n") /* OUTOUTOUT is a reserved variable name ! (see Makefile and sedscript_c) */ quote(MLI,"\n(** {2 Pretty printing} *)\n") quote(MLI,"val print : Format.formatter -> t -> unit") quote(MLMLI,"\n(** {2 Initialization Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Initializing-Floats.html#Initializing-Floats}C documentation} *)\n") void mpf_set_default_prec (unsigned long int PREC); unsigned long int mpf_get_default_prec (void); void mpf_init ([out] mpf_ptr OUTOUTOUT); void mpf_init2 ([out] mpf_ptr OUTOUTOUT, unsigned long int PREC); unsigned long int mpf_get_prec (mpf_ptr OP); void mpf_set_prec (mpf_ptr ROP, unsigned long int PREC); void mpf_set_prec_raw (mpf_ptr ROP, unsigned long int PREC); quote(MLMLI,"\n(** {2 Assignement Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Assigning-Floats.html#Assigning-Floats}C documentation} *)\n") void mpf_set (mpf_ptr ROP, mpf_ptr OP); void mpf_set_si (mpf_ptr ROP, signed long int OP); void mpf_set_d (mpf_ptr ROP, double OP); void mpf_set_z (mpf_ptr ROP, mpz_ptr OP); void mpf_set_q (mpf_ptr ROP, mpq_ptr OP); void mpf__set_str (mpf_ptr ROP, [string]char *STR, int BASE) quote(call,"{\n\ int n = mpf_set_str(ROP,STR,BASE);\n\ if (n){ mpf_clear(ROP); caml_invalid_argument(\"\"); }\n\ }"); quote(MLI,"val set_str : t -> string -> base:int -> unit") quote(ML,"let set_str a b ~base = _set_str a b base") void mpf_swap (mpf_ptr ROP1, mpf_ptr ROP2); quote(MLMLI,"\n(** {2 Combined Initialization and Assignement Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Simultaneous-Float-Init-_0026-Assign.html#Simultaneous-Float-Init-_0026-Assign}C documentation} *)\n") void mpf_init_set ([out] mpf_ptr OUTOUTOUT, mpf_ptr OP); void mpf_init_set_si ([out] mpf_ptr OUTOUTOUT, signed long int OP); void mpf_init_set_d ([out] mpf_ptr OUTOUTOUT, double OP); void mpf__init_set_str ([out] mpf_ptr OUTOUTOUT, [string]char *STR, int BASE) quote(call,"\ {\n\ int n = mpf_init_set_str(OUTOUTOUT,STR,BASE);\n\ if (n){ mpf_clear(OUTOUTOUT); caml_invalid_argument(\"\"); }\n\ }"); quote(MLI,"val init_set_str : string -> base:int -> t") quote(ML,"let init_set_str a ~base = _init_set_str a base") quote(MLMLI,"\n(** {2 Conversion Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Converting-Floats.html#Converting-Floats}C documentation} *)\n") double mpf_get_d (mpf_ptr OP); double mpf_get_d_2exp ([out]signed long int *EXP, mpf_ptr OP); [nativeint]long mpf_get_si (mpf_ptr OP); long mpf_get_int (mpf_ptr OP) quote(call,"_res = mpf_get_si(OP);"); quote(MLI,"\n (* Replace Mpz.set_f: t -> Mpz.t -> unit *)") void mpf_get_z (mpz_ptr ROP, mpf_ptr OP) quote(call,"mpz_set_f(ROP,OP);"); quote(MLI,"\n (* Replace Mpq.set_f: t -> Mpq.t -> unit *)") void mpf_get_q (mpq_ptr ROP, mpf_ptr OP) quote(call,"mpq_set_f(ROP,OP);"); [string]char* mpf__get_str ([out]long int *EXPPTR, int BASE, int N_DIGITS, mpf_ptr OP) quote(call,"_res = mpf_get_str(NULL,EXPPTR,BASE,N_DIGITS,OP);") quote(dealloc,"free(_res);"); quote(MLI,"val get_str : base:int -> digits:int -> t -> string * int") quote(ML,"let get_str ~base ~digits a = _get_str base digits a") quote(MLI,"\n(** {2 User Conversions} *)\n") quote(MLI,"(** These functionss are additions to or renaming of functions offered by the C library. *)\n") quote(MLI,"val to_string : t -> string") quote(MLI,"val to_float : t -> float") quote(MLI,"val of_string : string -> t") quote(MLI,"val of_float : float -> t") quote(MLI,"val of_int : int -> t") quote(MLI,"val of_mpz : Mpz.t -> t") quote(MLI,"val of_mpq : Mpq.t -> t") quote(MLI,"val is_integer : t -> bool") quote(MLMLI,"\n(** {2 Arithmetic Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Float-Arithmetic.html#Float-Arithmetic}C documentation} *)\n") void mpf_add (mpf_ptr ROP, mpf_ptr OP1, mpf_ptr OP2); void mpf_add_ui (mpf_ptr ROP, mpf_ptr OP1, unsigned long int OP2); void mpf_sub (mpf_ptr ROP, mpf_ptr OP1, mpf_ptr OP2); void mpf_ui_sub (mpf_ptr ROP, unsigned long int OP1, mpf_ptr OP2); void mpf_sub_ui (mpf_ptr ROP, mpf_ptr OP1, unsigned long int OP2); void mpf_mul (mpf_ptr ROP, mpf_ptr OP1, mpf_ptr OP2); void mpf_mul_ui (mpf_ptr ROP, mpf_ptr OP1, unsigned long int OP2); void mpf_mul_2exp (mpf_ptr ROP, mpf_ptr OP1, unsigned long int OP2); void mpf_div (mpf_ptr ROP, mpf_ptr OP1, mpf_ptr OP2); void mpf_ui_div (mpf_ptr ROP, unsigned long int OP1, mpf_ptr OP2); void mpf_div_ui (mpf_ptr ROP, mpf_ptr OP1, unsigned long int OP2); void mpf_div_2exp (mpf_ptr ROP, mpf_ptr OP1, unsigned long int OP2); void mpf_sqrt (mpf_ptr ROP, mpf_ptr OP); void mpf_pow_ui (mpf_ptr ROP, mpf_ptr OP1, unsigned long int OP2); void mpf_neg (mpf_ptr ROP, mpf_ptr OP); void mpf_abs (mpf_ptr ROP, mpf_ptr OP); quote(MLMLI,"\n(** {2 Comparison Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Float-Comparison.html#Float-Comparison}C documentation} *)\n") int mpf_cmp (mpf_ptr OP1, mpf_ptr OP2); int mpf_cmp_d (mpf_ptr OP1, double OP2); int mpf_cmp_si (mpf_ptr OP1, signed long int OP2); int mpf_sgn (mpf_ptr OP); boolean mpf__equal (mpf_ptr OP1, mpf_ptr OP2, unsigned long int OP3) quote(call,"_res=mpf_eq(OP1,OP2,OP3);"); quote(MLI,"val equal : t -> t -> bits:int -> bool") quote(ML,"let equal a b ~bits = _equal a b bits") void mpf_reldiff (mpf_ptr ROP, mpf_ptr OP1, mpf_ptr OP2); quote(MLMLI,"\n(** {2 Input and Output Functions: not interfaced} *)\n") quote(MLMLI,"\n(** {2 Random Number Functions: see {!Gmp_random} module} *)\n") quote(MLMLI,"\n(** {2 Miscellaneous Float Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Miscellaneous-Float-Functions.html#Miscellaneous-Float-Functions}C documentation} *)\n") void mpf_ceil (mpf_ptr ROP, mpf_ptr OP); void mpf_floor (mpf_ptr ROP, mpf_ptr OP); void mpf_trunc (mpf_ptr ROP, mpf_ptr OP); boolean mpf_integer_p (mpf_ptr OP); quote(MLI,"\n(* Does it fit in an OCaml integer *)") boolean mpf_fits_int_p (mpf_ptr OP); quote(MLI,"\n(* Limited relevance here *)") boolean mpf_fits_ulong_p (mpf_ptr OP); boolean mpf_fits_slong_p (mpf_ptr OP); boolean mpf_fits_uint_p (mpf_ptr OP); boolean mpf_fits_sint_p (mpf_ptr OP); boolean mpf_fits_ushort_p (mpf_ptr OP); boolean mpf_fits_sshort_p (mpf_ptr OP); quote(ML,"\n(** {2 Additional functions} *)\n") quote(ML,"let to_string x = \n\ let (s,e) = get_str ~base:10 ~digits:0 x in \n\ if s=\"\" \n\ then \"0.0\" \n\ else Format.sprintf \"0.%se%i\" s e \n\ ") quote(ML,"let to_float = get_d") quote(ML,"let of_string str = init_set_str str 10") quote(ML,"let of_float = init_set_d") quote(ML,"let of_int a = init_set_si a") quote(ML,"let of_mpz x = let res = init() in set_z res x; res") quote(ML,"let of_mpq x = let res = init() in set_q res x; res") quote(ML,"let is_integer = integer_p") quote(ML,"\n(** {2 Pretty printing} *)\n") quote(ML,"let print fmt x = \n\ let (s,e) = get_str ~base:10 ~digits:0 x in \n\ if s=\"\" \n\ then Format.pp_print_string fmt \"0.0\" \n\ else Format.fprintf fmt \"0.%se%i\" s e \n\ ") apron-dist-0.9.10/mlgmpidl/tmp/mpfr_stubs.c0000640014525101416610000021150511252216514020505 0ustar bjeannetpopart/* File generated from mpfr.idl */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include "caml/custom.h" #include "gmp_caml.h" extern void camlidl_mpz_ptr_ml2c(value, mpz_ptr *); #define camlidl_ml2c_mpz_mpz_ptr(v,c,ctx) camlidl_mpz_ptr_ml2c(v,c) extern value camlidl_mpz_ptr_c2ml(mpz_ptr *); #define camlidl_c2ml_mpz_mpz_ptr(c,ctx) camlidl_mpz_ptr_c2ml(c) extern void camlidl_mpq_ptr_ml2c(value, mpq_ptr *); #define camlidl_ml2c_mpq_mpq_ptr(v,c,ctx) camlidl_mpq_ptr_ml2c(v,c) extern value camlidl_mpq_ptr_c2ml(mpq_ptr *); #define camlidl_c2ml_mpq_mpq_ptr(c,ctx) camlidl_mpq_ptr_c2ml(c) extern void camlidl_mpf_ptr_ml2c(value, mpf_ptr *); #define camlidl_ml2c_mpf_mpf_ptr(v,c,ctx) camlidl_mpf_ptr_ml2c(v,c) extern value camlidl_mpf_ptr_c2ml(mpf_ptr *); #define camlidl_c2ml_mpf_mpf_ptr(c,ctx) camlidl_mpf_ptr_c2ml(c) #define camlidl_ml2c_mpfr_mpfr_ptr(v,c,ctx) camlidl_mpfr_ptr_ml2c(v,c) #define camlidl_c2ml_mpfr_mpfr_ptr(c,ctx) camlidl_mpfr_ptr_c2ml(c) extern void camlidl_ml2c_mpfr_struct_mpfr_rnd_t(value, struct mpfr_rnd_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_mpfr_struct_mpfr_rnd_t(struct mpfr_rnd_t *, camlidl_ctx _ctx); #define camlidl_ml2c_mpfr_mpfr_rnd_t(v,c,ctx) camlidl_mpfr_rnd_t_ml2c(v,c) #define camlidl_c2ml_mpfr_mpfr_rnd_t(c,ctx) camlidl_mpfr_rnd_t_c2ml(c) value camlidl_mpfr_mpfr_set_default_rounding_mode( value _v_RND) { mpfr_rnd_t RND; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); mpfr_set_default_rounding_mode(RND); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_get_default_rounding_mode(value _unit) { mpfr_rnd_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; _res = mpfr_get_default_rounding_mode(); _vres = camlidl_c2ml_mpfr_mpfr_rnd_t(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_round_prec( value _v_X, value _v_RND, value _v_PREC) { mpfr_ptr X; /*in*/ mpfr_rnd_t RND; /*in*/ unsigned long PREC; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); PREC = Long_val(_v_PREC); _res = mpfr_round_prec(X, RND, PREC); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_get_emin(value _unit) { long _res; value _vres; _res = mpfr_get_emin(); _vres = Val_long(_res); return _vres; } value camlidl_mpfr_mpfr_get_emax(value _unit) { long _res; value _vres; _res = mpfr_get_emax(); _vres = Val_long(_res); return _vres; } value camlidl_mpfr_mpfr_set_emin( value _v_EXP) { long EXP; /*in*/ EXP = Long_val(_v_EXP); /* begin user-supplied calling sequence */ { int n = mpfr_set_emin(EXP); if (n){ caml_invalid_argument(""); } } /* end user-supplied calling sequence */ return Val_unit; } value camlidl_mpfr_mpfr_set_emax( value _v_EXP) { long EXP; /*in*/ EXP = Long_val(_v_EXP); /* begin user-supplied calling sequence */ { int n = mpfr_set_emax(EXP); if (n){ caml_invalid_argument(""); } } /* end user-supplied calling sequence */ return Val_unit; } value camlidl_mpfr_mpfr_check_range( value _v_X, value _v_T, value _v_RND) { mpfr_ptr X; /*in*/ int T; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); T = Int_val(_v_T); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_check_range(X, T, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_clear_underflow(value _unit) { mpfr_clear_underflow(); return Val_unit; } value camlidl_mpfr_mpfr_clear_overflow(value _unit) { mpfr_clear_overflow(); return Val_unit; } value camlidl_mpfr_mpfr_clear_nanflag(value _unit) { mpfr_clear_nanflag(); return Val_unit; } value camlidl_mpfr_mpfr_clear_inexflag(value _unit) { mpfr_clear_inexflag(); return Val_unit; } value camlidl_mpfr_mpfr_clear_flags(value _unit) { mpfr_clear_flags(); return Val_unit; } value camlidl_mpfr_mpfr_underflow_p(value _unit) { int _res; value _vres; _res = mpfr_underflow_p(); _vres = Val_int(_res); return _vres; } value camlidl_mpfr_mpfr_overflow_p(value _unit) { int _res; value _vres; _res = mpfr_overflow_p(); _vres = Val_int(_res); return _vres; } value camlidl_mpfr_mpfr_nanflag_p(value _unit) { int _res; value _vres; _res = mpfr_nanflag_p(); _vres = Val_int(_res); return _vres; } value camlidl_mpfr_mpfr_inexflag_p(value _unit) { int _res; value _vres; _res = mpfr_inexflag_p(); _vres = Val_int(_res); return _vres; } value camlidl_mpfr_mpfr_set_default_prec( value _v_PREC) { unsigned long PREC; /*in*/ PREC = Long_val(_v_PREC); mpfr_set_default_prec(PREC); return Val_unit; } value camlidl_mpfr_mpfr_get_default_prec(value _unit) { unsigned long _res; value _vres; _res = mpfr_get_default_prec(); _vres = Val_long(_res); return _vres; } value camlidl_mpfr_mpfr_init(value _unit) { mpfr_ptr OUTOUTOUT; /*out*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; mpfr_init(OUTOUTOUT); _vres = camlidl_c2ml_mpfr_mpfr_ptr(&OUTOUTOUT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_init2( value _v_PREC) { mpfr_ptr OUTOUTOUT; /*out*/ unsigned long PREC; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; PREC = Long_val(_v_PREC); mpfr_init2(OUTOUTOUT, PREC); _vres = camlidl_c2ml_mpfr_mpfr_ptr(&OUTOUTOUT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_get_prec( value _v_OP) { mpfr_ptr OP; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_get_prec(OP); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_set_prec( value _v_ROP, value _v_PREC) { mpfr_ptr ROP; /*in*/ unsigned long PREC; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); PREC = Long_val(_v_PREC); mpfr_set_prec(ROP, PREC); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_set_prec_raw( value _v_ROP, value _v_PREC) { mpfr_ptr ROP; /*in*/ unsigned long PREC; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); PREC = Long_val(_v_PREC); mpfr_set_prec_raw(ROP, PREC); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_set( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_set(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_set_si( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ long OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); OP = Long_val(_v_OP); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_set_si(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_set_d( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ double OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); OP = Double_val(_v_OP); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_set_d(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_set_z( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_set_z(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_set_q( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpq_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_set_q(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr__set_str( value _v_ROP, value _v_STR, value _v_BASE, value _v_RND) { mpfr_ptr ROP; /*in*/ char *STR; /*in*/ int BASE; /*in*/ mpfr_rnd_t RND; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); STR = String_val(_v_STR); BASE = Int_val(_v_BASE); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); /* begin user-supplied calling sequence */ { int n = mpfr_set_str(ROP,STR,BASE,RND); if (n){ mpfr_clear(ROP); caml_invalid_argument(""); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_set_f( value _v_X, value _v_Y, value _v_RND) { mpfr_ptr X; /*in*/ mpf_ptr Y; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_Y, &Y, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_set_f(X, Y, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_set_si_2exp( value _v_ROP, value _v_OP, value _v_EXPNT, value _v_RND) { mpfr_ptr ROP; /*in*/ long OP; /*in*/ long EXPNT; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); OP = Long_val(_v_OP); EXPNT = Long_val(_v_EXPNT); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_set_si_2exp(ROP, OP, EXPNT, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_set_inf( value _v_X, value _v_SIGN) { mpfr_ptr X; /*in*/ int SIGN; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); SIGN = Int_val(_v_SIGN); mpfr_set_inf(X, SIGN); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_set_nan( value _v_X) { mpfr_ptr X; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); mpfr_set_nan(X); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_swap( value _v_ROP1, value _v_ROP2) { mpfr_ptr ROP1; /*in*/ mpfr_ptr ROP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP1, &ROP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP2, &ROP2, _ctx); mpfr_swap(ROP1, ROP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_init_set( value _v_OP, value _v_RND) { mpfr_ptr OUTOUTOUT; /*out*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; value _vresult; value _vres[2] = { 0, 0, }; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_init_set(OUTOUTOUT, OP, RND); Begin_roots_block(_vres, 2) _vres[0] = Val_int(_res); _vres[1] = camlidl_c2ml_mpfr_mpfr_ptr(&OUTOUTOUT, _ctx); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); return _vresult; } value camlidl_mpfr_mpfr_init_set_si( value _v_OP, value _v_RND) { mpfr_ptr OUTOUTOUT; /*out*/ long OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; value _vresult; value _vres[2] = { 0, 0, }; OP = Long_val(_v_OP); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_init_set_si(OUTOUTOUT, OP, RND); Begin_roots_block(_vres, 2) _vres[0] = Val_int(_res); _vres[1] = camlidl_c2ml_mpfr_mpfr_ptr(&OUTOUTOUT, _ctx); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); return _vresult; } value camlidl_mpfr_mpfr_init_set_d( value _v_OP, value _v_RND) { mpfr_ptr OUTOUTOUT; /*out*/ double OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; value _vresult; value _vres[2] = { 0, 0, }; OP = Double_val(_v_OP); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_init_set_d(OUTOUTOUT, OP, RND); Begin_roots_block(_vres, 2) _vres[0] = Val_int(_res); _vres[1] = camlidl_c2ml_mpfr_mpfr_ptr(&OUTOUTOUT, _ctx); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); return _vresult; } value camlidl_mpfr_mpfr_init_set_f( value _v_OP, value _v_RND) { mpfr_ptr OUTOUTOUT; /*out*/ mpf_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; value _vresult; value _vres[2] = { 0, 0, }; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_init_set_f(OUTOUTOUT, OP, RND); Begin_roots_block(_vres, 2) _vres[0] = Val_int(_res); _vres[1] = camlidl_c2ml_mpfr_mpfr_ptr(&OUTOUTOUT, _ctx); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); return _vresult; } value camlidl_mpfr_mpfr_init_set_z( value _v_OP, value _v_RND) { mpfr_ptr OUTOUTOUT; /*out*/ mpz_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; value _vresult; value _vres[2] = { 0, 0, }; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_init_set_z(OUTOUTOUT, OP, RND); Begin_roots_block(_vres, 2) _vres[0] = Val_int(_res); _vres[1] = camlidl_c2ml_mpfr_mpfr_ptr(&OUTOUTOUT, _ctx); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); return _vresult; } value camlidl_mpfr_mpfr_init_set_q( value _v_OP, value _v_RND) { mpfr_ptr OUTOUTOUT; /*out*/ mpq_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; value _vresult; value _vres[2] = { 0, 0, }; camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_init_set_q(OUTOUTOUT, OP, RND); Begin_roots_block(_vres, 2) _vres[0] = Val_int(_res); _vres[1] = camlidl_c2ml_mpfr_mpfr_ptr(&OUTOUTOUT, _ctx); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); return _vresult; } value camlidl_mpfr_mpfr__init_set_str( value _v_STR, value _v_BASE, value _v_RND) { mpfr_ptr OUTOUTOUT; /*out*/ char *STR; /*in*/ int BASE; /*in*/ mpfr_rnd_t RND; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; STR = String_val(_v_STR); BASE = Int_val(_v_BASE); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); /* begin user-supplied calling sequence */ { int n = mpfr_init_set_str(OUTOUTOUT,STR,BASE,RND); if (n){ mpfr_clear(OUTOUTOUT); caml_invalid_argument(""); } } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_mpfr_mpfr_ptr(&OUTOUTOUT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_get_d( value _v_OP, value _v_RND) { mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ double _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_get_d(OP, RND); _vres = copy_double(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_get_d1( value _v_OP) { mpfr_ptr OP; /*in*/ double _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_get_d1(OP); _vres = copy_double(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_get_z_exp( value _v_Z, value _v_OP) { mpz_ptr Z; /*in*/ mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Z, &Z, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_get_z_exp(Z, OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_get_z( value _v_Z, value _v_OP, value _v_RND) { mpz_ptr Z; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Z, &Z, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); mpfr_get_z(Z, OP, RND); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr__get_str( value _v_BASE, value _v_N_DIGITS, value _v_OP, value _v_RND) { long *EXPPTR; /*out*/ int BASE; /*in*/ int N_DIGITS; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ char *_res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; long _c1; value _vresult; value _vres[2] = { 0, 0, }; BASE = Int_val(_v_BASE); N_DIGITS = Int_val(_v_N_DIGITS); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); EXPPTR = &_c1; /* begin user-supplied calling sequence */ _res = mpfr_get_str(NULL,EXPPTR,BASE,N_DIGITS,OP,RND); /* end user-supplied calling sequence */ Begin_roots_block(_vres, 2) _vres[0] = copy_string(_res); _vres[1] = Val_long(*EXPPTR); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ free(_res); /* end user-supplied deallocation sequence */ return _vresult; } value camlidl_mpfr_mpfr_add( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_add(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_add_ui( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ unsigned long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_add_ui(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_add_z( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_add_z(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_add_q( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_add_q(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sub( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sub(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_ui_sub( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ unsigned long OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); OP1 = Long_val(_v_OP1); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_ui_sub(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sub_ui( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ unsigned long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sub_ui(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sub_z( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sub_z(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sub_q( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sub_q(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_mul( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_mul(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_mul_ui( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ unsigned long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_mul_ui(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_mul_z( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_mul_z(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_mul_q( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_mul_q(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_mul_2ui( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ unsigned long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_mul_2ui(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_mul_2si( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_mul_2si(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_mul_2exp( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ unsigned long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_mul_2exp(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_div( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_div(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_ui_div( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ unsigned long OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); OP1 = Long_val(_v_OP1); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_ui_div(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_div_ui( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ unsigned long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_div_ui(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_div_z( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_div_z(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_div_q( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_div_q(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_div_2ui( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ unsigned long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_div_2ui(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_div_2si( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_div_2si(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sqrt( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sqrt(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sqrt_ui( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ unsigned long OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); OP = Long_val(_v_OP); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sqrt_ui(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_pow_ui( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ unsigned long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_pow_ui(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_pow_si( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_pow_si(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_ui_pow_ui( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ unsigned long OP1; /*in*/ unsigned long OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); OP1 = Long_val(_v_OP1); OP2 = Long_val(_v_OP2); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_ui_pow_ui(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_ui_pow( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ unsigned long OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); OP1 = Long_val(_v_OP1); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_ui_pow(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_pow( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_pow(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_neg( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_neg(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_abs( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_abs(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_cmp( value _v_OP1, value _v_OP2) { mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); _res = mpfr_cmp(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_cmp_si( value _v_OP1, value _v_OP2) { mpfr_ptr OP1; /*in*/ long OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); _res = mpfr_cmp_si(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_cmp_si_2exp( value _v_OP1, value _v_OP2, value _v_E) { mpfr_ptr OP1; /*in*/ long OP2; /*in*/ int E; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); E = Int_val(_v_E); _res = mpfr_cmp_si_2exp(OP1, OP2, E); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sgn( value _v_OP) { mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_sgn(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr__equal( value _v_OP1, value _v_OP2, value _v_OP3) { mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ unsigned long OP3; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); OP3 = Long_val(_v_OP3); /* begin user-supplied calling sequence */ _res=mpfr_eq(OP1,OP2,OP3); /* end user-supplied calling sequence */ _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_nan_p( value _v_OP) { mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_nan_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_inf_p( value _v_OP) { mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_inf_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_number_p( value _v_OP) { mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_number_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_reldiff( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); mpfr_reldiff(ROP, OP1, OP2, RND); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_log( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_log(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_log2( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_log2(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_log10( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_log10(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_exp( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_exp(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_exp2( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_exp2(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_exp10( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_exp10(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_cos( value _v_COP, value _v_OP, value _v_RND) { mpfr_ptr COP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_COP, &COP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_cos(COP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sin( value _v_SOP, value _v_OP, value _v_RND) { mpfr_ptr SOP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_SOP, &SOP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sin(SOP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_tan( value _v_TOP, value _v_OP, value _v_RND) { mpfr_ptr TOP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_TOP, &TOP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_tan(TOP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sec( value _v_COP, value _v_OP, value _v_RND) { mpfr_ptr COP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_COP, &COP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sec(COP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_csc( value _v_SOP, value _v_OP, value _v_RND) { mpfr_ptr SOP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_SOP, &SOP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_csc(SOP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_cot( value _v_TOP, value _v_OP, value _v_RND) { mpfr_ptr TOP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_TOP, &TOP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_cot(TOP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sin_cos( value _v_SOP, value _v_COP, value _v_OP, value _v_RND) { mpfr_ptr SOP; /*in*/ mpfr_ptr COP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_SOP, &SOP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_COP, &COP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sin_cos(SOP, COP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_acos( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_acos(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_asin( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_asin(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_atan( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_atan(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_atan2( value _v_ROP, value _v_Y, value _v_X, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr Y; /*in*/ mpfr_ptr X; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_Y, &Y, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_atan2(ROP, Y, X, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_cosh( value _v_COP, value _v_OP, value _v_RND) { mpfr_ptr COP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_COP, &COP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_cosh(COP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sinh( value _v_SOP, value _v_OP, value _v_RND) { mpfr_ptr SOP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_SOP, &SOP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sinh(SOP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_tanh( value _v_TOP, value _v_OP, value _v_RND) { mpfr_ptr TOP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_TOP, &TOP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_tanh(TOP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_sech( value _v_COP, value _v_OP, value _v_RND) { mpfr_ptr COP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_COP, &COP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_sech(COP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_csch( value _v_SOP, value _v_OP, value _v_RND) { mpfr_ptr SOP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_SOP, &SOP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_csch(SOP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_coth( value _v_TOP, value _v_OP, value _v_RND) { mpfr_ptr TOP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_TOP, &TOP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_coth(TOP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_acosh( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_acosh(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_asinh( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_asinh(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_atanh( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_atanh(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_fac_ui( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ unsigned long OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); OP = Long_val(_v_OP); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_fac_ui(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_log1p( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_log1p(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_expm1( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_expm1(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_eint( value _v_Y, value _v_X, value _v_RND) { mpfr_ptr Y; /*in*/ mpfr_ptr X; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_Y, &Y, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_eint(Y, X, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_gamma( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_gamma(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_lngamma( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_lngamma(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_zeta( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_zeta(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_erf( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_erf(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_erfc( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_erfc(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_fma( value _v_ROP, value _v_OPX, value _v_OPY, value _v_OPZ, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OPX; /*in*/ mpfr_ptr OPY; /*in*/ mpfr_ptr OPZ; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OPX, &OPX, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OPY, &OPY, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OPZ, &OPZ, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_fma(ROP, OPX, OPY, OPZ, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_agm( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_agm(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_hypot( value _v_ROP, value _v_X, value _v_Y, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr X; /*in*/ mpfr_ptr Y; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_Y, &Y, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_hypot(ROP, X, Y, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_const_log2( value _v_ROP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_const_log2(ROP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_const_pi( value _v_ROP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_const_pi(ROP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_const_euler( value _v_ROP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_const_euler(ROP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_const_catalan( value _v_ROP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_const_catalan(ROP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_rint( value _v_ROP, value _v_OP, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_rint(ROP, OP, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_ceil( value _v_ROP, value _v_OP) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_ceil(ROP, OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_floor( value _v_ROP, value _v_OP) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_floor(ROP, OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_round( value _v_ROP, value _v_OP) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_round(ROP, OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_trunc( value _v_ROP, value _v_OP) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_trunc(ROP, OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_integer_p( value _v_OP) { mpfr_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_OP, &OP, _ctx); _res = mpfr_integer_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_nexttoward( value _v_X, value _v_Y) { mpfr_ptr X; /*in*/ mpfr_ptr Y; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_Y, &Y, _ctx); mpfr_nexttoward(X, Y); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_nextabove( value _v_X) { mpfr_ptr X; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); mpfr_nextabove(X); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_nextbelow( value _v_X) { mpfr_ptr X; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); mpfr_nextbelow(X); camlidl_free(_ctx); return Val_unit; } value camlidl_mpfr_mpfr_min( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_min(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_max( value _v_ROP, value _v_OP1, value _v_OP2, value _v_RND) { mpfr_ptr ROP; /*in*/ mpfr_ptr OP1; /*in*/ mpfr_ptr OP2; /*in*/ mpfr_rnd_t RND; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpfr_mpfr_ptr(_v_OP2, &OP2, _ctx); camlidl_ml2c_mpfr_mpfr_rnd_t(_v_RND, &RND, _ctx); _res = mpfr_max(ROP, OP1, OP2, RND); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_get_exp( value _v_X) { mpfr_ptr X; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); _res = mpfr_get_exp(X); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpfr_mpfr_set_exp( value _v_X, value _v_E) { mpfr_ptr X; /*in*/ long E; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpfr_mpfr_ptr(_v_X, &X, _ctx); E = Long_val(_v_E); _res = mpfr_set_exp(X, E); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } apron-dist-0.9.10/mlgmpidl/tmp/mpq.ml0000640014525101416610000001030111252216513017272 0ustar bjeannetpopart(* File generated from mpq.idl *) type mpq_ptr (** GMP multiprecision rationals *) (** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x]. These functions are as efficient as their C counterpart: they do not imply additional memory allocation, unlike the corresponding functions in the module {!Mpqf}. *) external mpq_canonicalize : mpq_ptr -> unit = "camlidl_mpq_mpq_canonicalize" (** {2 Initialization and Assignment Functions} *) (** {{:http://gmplib.org/manual/Initializing-Rationals.html#Initializing-Rationals}C documentation} *) external mpq_init : unit -> mpq_ptr = "camlidl_mpq_mpq_init" external mpq_set : mpq_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_set" external mpq_set_z : mpq_ptr -> Mpz.mpz_ptr -> unit = "camlidl_mpq_mpq_set_z" external mpq_set_si : mpq_ptr -> int -> int -> unit = "camlidl_mpq_mpq_set_si" external mpq__set_str : mpq_ptr -> string -> int -> unit = "camlidl_mpq_mpq__set_str" let set_str a b ~base = _set_str a b base external mpq_swap : mpq_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_swap" (** {2 Conversion Functions} *) (** {{:http://gmplib.org/manual/Rational-Conversions.html#Rational-Conversions}C documentation} *) external mpq_get_d : mpq_ptr -> float = "camlidl_mpq_mpq_get_d" external mpq_set_d : mpq_ptr -> float -> unit = "camlidl_mpq_mpq_set_d" external mpq_get_z : Mpz.mpz_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_get_z" external mpq__get_str : int -> mpq_ptr -> string = "camlidl_mpq_mpq__get_str" let get_str ~base a = _get_str base a (** {2 Arithmetic Functions} *) (** {{:http://gmplib.org/manual/Rational-Arithmetic.html#Rational-Arithmetic}C documentation} *) external mpq_add : mpq_ptr -> mpq_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_add" external mpq_sub : mpq_ptr -> mpq_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_sub" external mpq_mul : mpq_ptr -> mpq_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_mul" external mpq_mul_2exp : mpq_ptr -> mpq_ptr -> int -> unit = "camlidl_mpq_mpq_mul_2exp" external mpq_div : mpq_ptr -> mpq_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_div" external mpq_div_2exp : mpq_ptr -> mpq_ptr -> int -> unit = "camlidl_mpq_mpq_div_2exp" external mpq_neg : mpq_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_neg" external mpq_abs : mpq_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_abs" external mpq_inv : mpq_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_inv" (** {2 Comparison Functions} *) (** {{:http://gmplib.org/manual/Comparing-Rationals.html#Comparing-Rationals}C documentation} *) external mpq_cmp : mpq_ptr -> mpq_ptr -> int = "camlidl_mpq_mpq_cmp" external mpq_cmp_si : mpq_ptr -> int -> int -> int = "camlidl_mpq_mpq_cmp_si" external mpq_sgn : mpq_ptr -> int = "camlidl_mpq_mpq_sgn" external mpq_equal : mpq_ptr -> mpq_ptr -> bool = "camlidl_mpq_mpq_equal" (** {2 Applying Integer Functions to Rationals} *) (** {{:http://gmplib.org/manual/Applying-Integer-Functions.html#Applying-Integer-Functions}C documentation} *) external mpq_get_num : Mpz.mpz_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_get_num" external mpq_get_den : Mpz.mpz_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_get_den" external mpq_set_num : mpq_ptr -> Mpz.mpz_ptr -> unit = "camlidl_mpq_mpq_set_num" external mpq_set_den : mpq_ptr -> Mpz.mpz_ptr -> unit = "camlidl_mpq_mpq_set_den" (** {2 Input and Output Functions: not interfaced} *) (** {2 Pretty printing} *) let print fmt x = Format.pp_print_string fmt (get_str 10 x) let init_set x = let y = init() in set y x; y let init_set_z z = let x = init() in set_z x z; x let init_set_si n d = let x = init() in set_si x n d; x let init_set_str str ~base = let x = init() in ignore (set_str x str ~base); x let init_set_d d = let x = init() in set_d x d; x let to_string x = get_str 10 x let to_float = get_d let of_string str = init_set_str str 10 let of_float = init_set_d let of_int a = init_set_si a 1 let of_frac = init_set_si let of_mpz = init_set_z let of_mpz2 num den = let res = init() in set_num res num; set_den res den; canonicalize res; res apron-dist-0.9.10/mlgmpidl/tmp/mpf.mli0000640014525101416610000001544311252216513017444 0ustar bjeannetpopart(* File generated from mpf.idl *) type mpf_ptr (** GMP multiprecision floating-point numbers *) (** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x]. These functions are as efficient as their C counterpart: they do not imply additional memory allocation. *) (** {2 Pretty printing} *) val print : Format.formatter -> t -> unit (** {2 Initialization Functions} *) (** {{:http://gmplib.org/manual/Initializing-Floats.html#Initializing-Floats}C documentation} *) external mpf_set_default_prec : int -> unit = "camlidl_mpf_mpf_set_default_prec" external mpf_get_default_prec : unit -> int = "camlidl_mpf_mpf_get_default_prec" external mpf_init : unit -> mpf_ptr = "camlidl_mpf_mpf_init" external mpf_init2 : int -> mpf_ptr = "camlidl_mpf_mpf_init2" external mpf_get_prec : mpf_ptr -> int = "camlidl_mpf_mpf_get_prec" external mpf_set_prec : mpf_ptr -> int -> unit = "camlidl_mpf_mpf_set_prec" external mpf_set_prec_raw : mpf_ptr -> int -> unit = "camlidl_mpf_mpf_set_prec_raw" (** {2 Assignement Functions} *) (** {{:http://gmplib.org/manual/Assigning-Floats.html#Assigning-Floats}C documentation} *) external mpf_set : mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_set" external mpf_set_si : mpf_ptr -> int -> unit = "camlidl_mpf_mpf_set_si" external mpf_set_d : mpf_ptr -> float -> unit = "camlidl_mpf_mpf_set_d" external mpf_set_z : mpf_ptr -> Mpz.mpz_ptr -> unit = "camlidl_mpf_mpf_set_z" external mpf_set_q : mpf_ptr -> Mpq.mpq_ptr -> unit = "camlidl_mpf_mpf_set_q" external mpf__set_str : mpf_ptr -> string -> int -> unit = "camlidl_mpf_mpf__set_str" val set_str : t -> string -> base:int -> unit external mpf_swap : mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_swap" (** {2 Combined Initialization and Assignement Functions} *) (** {{:http://gmplib.org/manual/Simultaneous-Float-Init-_0026-Assign.html#Simultaneous-Float-Init-_0026-Assign}C documentation} *) external mpf_init_set : mpf_ptr -> mpf_ptr = "camlidl_mpf_mpf_init_set" external mpf_init_set_si : int -> mpf_ptr = "camlidl_mpf_mpf_init_set_si" external mpf_init_set_d : float -> mpf_ptr = "camlidl_mpf_mpf_init_set_d" external mpf__init_set_str : string -> int -> mpf_ptr = "camlidl_mpf_mpf__init_set_str" val init_set_str : string -> base:int -> t (** {2 Conversion Functions} *) (** {{:http://gmplib.org/manual/Converting-Floats.html#Converting-Floats}C documentation} *) external mpf_get_d : mpf_ptr -> float = "camlidl_mpf_mpf_get_d" external mpf_get_d_2exp : mpf_ptr -> float * int = "camlidl_mpf_mpf_get_d_2exp" external mpf_get_si : mpf_ptr -> nativeint = "camlidl_mpf_mpf_get_si" external mpf_get_int : mpf_ptr -> int = "camlidl_mpf_mpf_get_int" (* Replace Mpz.set_f: t -> Mpz.t -> unit *) external mpf_get_z : Mpz.mpz_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_get_z" (* Replace Mpq.set_f: t -> Mpq.t -> unit *) external mpf_get_q : Mpq.mpq_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_get_q" external mpf__get_str : int -> int -> mpf_ptr -> string * int = "camlidl_mpf_mpf__get_str" val get_str : base:int -> digits:int -> t -> string * int (** {2 User Conversions} *) (** These functionss are additions to or renaming of functions offered by the C library. *) val to_string : t -> string val to_float : t -> float val of_string : string -> t val of_float : float -> t val of_int : int -> t val of_mpz : Mpz.t -> t val of_mpq : Mpq.t -> t val is_integer : t -> bool (** {2 Arithmetic Functions} *) (** {{:http://gmplib.org/manual/Float-Arithmetic.html#Float-Arithmetic}C documentation} *) external mpf_add : mpf_ptr -> mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_add" external mpf_add_ui : mpf_ptr -> mpf_ptr -> int -> unit = "camlidl_mpf_mpf_add_ui" external mpf_sub : mpf_ptr -> mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_sub" external mpf_ui_sub : mpf_ptr -> int -> mpf_ptr -> unit = "camlidl_mpf_mpf_ui_sub" external mpf_sub_ui : mpf_ptr -> mpf_ptr -> int -> unit = "camlidl_mpf_mpf_sub_ui" external mpf_mul : mpf_ptr -> mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_mul" external mpf_mul_ui : mpf_ptr -> mpf_ptr -> int -> unit = "camlidl_mpf_mpf_mul_ui" external mpf_mul_2exp : mpf_ptr -> mpf_ptr -> int -> unit = "camlidl_mpf_mpf_mul_2exp" external mpf_div : mpf_ptr -> mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_div" external mpf_ui_div : mpf_ptr -> int -> mpf_ptr -> unit = "camlidl_mpf_mpf_ui_div" external mpf_div_ui : mpf_ptr -> mpf_ptr -> int -> unit = "camlidl_mpf_mpf_div_ui" external mpf_div_2exp : mpf_ptr -> mpf_ptr -> int -> unit = "camlidl_mpf_mpf_div_2exp" external mpf_sqrt : mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_sqrt" external mpf_pow_ui : mpf_ptr -> mpf_ptr -> int -> unit = "camlidl_mpf_mpf_pow_ui" external mpf_neg : mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_neg" external mpf_abs : mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_abs" (** {2 Comparison Functions} *) (** {{:http://gmplib.org/manual/Float-Comparison.html#Float-Comparison}C documentation} *) external mpf_cmp : mpf_ptr -> mpf_ptr -> int = "camlidl_mpf_mpf_cmp" external mpf_cmp_d : mpf_ptr -> float -> int = "camlidl_mpf_mpf_cmp_d" external mpf_cmp_si : mpf_ptr -> int -> int = "camlidl_mpf_mpf_cmp_si" external mpf_sgn : mpf_ptr -> int = "camlidl_mpf_mpf_sgn" external mpf__equal : mpf_ptr -> mpf_ptr -> int -> bool = "camlidl_mpf_mpf__equal" val equal : t -> t -> bits:int -> bool external mpf_reldiff : mpf_ptr -> mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_reldiff" (** {2 Input and Output Functions: not interfaced} *) (** {2 Random Number Functions: see {!Gmp_random} module} *) (** {2 Miscellaneous Float Functions} *) (** {{:http://gmplib.org/manual/Miscellaneous-Float-Functions.html#Miscellaneous-Float-Functions}C documentation} *) external mpf_ceil : mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_ceil" external mpf_floor : mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_floor" external mpf_trunc : mpf_ptr -> mpf_ptr -> unit = "camlidl_mpf_mpf_trunc" external mpf_integer_p : mpf_ptr -> bool = "camlidl_mpf_mpf_integer_p" (* Does it fit in an OCaml integer *) external mpf_fits_int_p : mpf_ptr -> bool = "camlidl_mpf_mpf_fits_int_p" (* Limited relevance here *) external mpf_fits_ulong_p : mpf_ptr -> bool = "camlidl_mpf_mpf_fits_ulong_p" external mpf_fits_slong_p : mpf_ptr -> bool = "camlidl_mpf_mpf_fits_slong_p" external mpf_fits_uint_p : mpf_ptr -> bool = "camlidl_mpf_mpf_fits_uint_p" external mpf_fits_sint_p : mpf_ptr -> bool = "camlidl_mpf_mpf_fits_sint_p" external mpf_fits_ushort_p : mpf_ptr -> bool = "camlidl_mpf_mpf_fits_ushort_p" external mpf_fits_sshort_p : mpf_ptr -> bool = "camlidl_mpf_mpf_fits_sshort_p" apron-dist-0.9.10/mlgmpidl/tmp/gmp_random.mli0000640014525101416610000000405711252216514021005 0ustar bjeannetpopart(* File generated from gmp_random.idl *) type gmp_randstate_ptr (** GMP random generation functions *) (** {2 Random State Initialization} *) (** {{:http://gmplib.org/manual/Random-State-Initialization.html#Random-State-Initialization}C documentation} *) external gmp_randinit_default : unit -> gmp_randstate_ptr = "camlidl_gmp_random_gmp_randinit_default" external gmp_randinit_lc_2exp : Mpz.mpz_ptr -> int -> int -> gmp_randstate_ptr = "camlidl_gmp_random_gmp_randinit_lc_2exp" external gmp_randinit_lc_2exp_size : int -> gmp_randstate_ptr = "camlidl_gmp_random_gmp_randinit_lc_2exp_size" (** {2 Random State Seeding} *) (** {{:http://gmplib.org/manual/Random-State-Seeding.html#Random-State-Seeding}C documentation} *) external gmp_randseed : gmp_randstate_ptr -> Mpz.mpz_ptr -> unit = "camlidl_gmp_random_gmp_randseed" external gmp_randseed_ui : gmp_randstate_ptr -> int -> unit = "camlidl_gmp_random_gmp_randseed_ui" (** {2 Random Number Functions} *) (** {3 Integers ({!Mpz})} *) (** {{:http://gmplib.org/manual/Integer-Random-Numbers.html#Integer-Random-Numbers}C documentation} *) module Mpz : sig external mpz_urandomb : Mpz.mpz_ptr -> gmp_randstate_ptr -> int -> unit = "camlidl_gmp_random_mpz_urandomb" external mpz_urandomm : Mpz.mpz_ptr -> gmp_randstate_ptr -> Mpz.mpz_ptr -> unit = "camlidl_gmp_random_mpz_urandomm" external mpz_rrandomb : Mpz.mpz_ptr -> gmp_randstate_ptr -> int -> unit = "camlidl_gmp_random_mpz_rrandomb" end (** {3 Floating-point ({!Mpf})} *) (** {{:http://gmplib.org/manual/Miscellaneous-Float-Functions.html#Miscellaneous-Float-Functions}C documentation} *) module Mpf : sig external mpf_urandomb : Mpf.mpf_ptr -> gmp_randstate_ptr -> int -> unit = "camlidl_gmp_random_mpf_urandomb" end (** {3 Floating-point ({!Mpfr})} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Miscellaneous-Functions}C documentation} *) module Mpfr : sig external mpfr_urandomb : Mpfr.mpfr_ptr -> gmp_randstate_ptr -> unit = "camlidl_gmp_random_mpfr_urandomb" external mpfr_random : Mpfr.mpfr_ptr -> unit = "camlidl_gmp_random_mpfr_random" end apron-dist-0.9.10/mlgmpidl/tmp/mpz.mli0000640014525101416610000003562411252216512017472 0ustar bjeannetpopart(* File generated from mpz.idl *) type mpz_ptr (** GMP multi-precision integers *) (** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x]. These functions are as efficient as their C counterpart: they do not imply additional memory allocation, unlike the corresponding functions in the module {!Mpzf}. *) (** {2 Pretty printing} *) val print : Format.formatter -> t -> unit (** {2 Initialization Functions} *) (** {{:http://gmplib.org/manual/Initializing-Integers.html#Initializing-Integers}C documentation} *) external mpz_init : unit -> mpz_ptr = "camlidl_mpz_mpz_init" external mpz_init2 : int -> mpz_ptr = "camlidl_mpz_mpz_init2" external mpz_realloc2 : mpz_ptr -> int -> unit = "camlidl_mpz_mpz_realloc2" (** {2 Assignement Functions} *) (** {{:http://gmplib.org/manual/Assigning-Integers.html#Assigning-Integers}C documentation} *) (** The first parameter holds the result. *) external mpz_set : mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_set" external mpz_set_si : mpz_ptr -> int -> unit = "camlidl_mpz_mpz_set_si" external mpz_set_d : mpz_ptr -> float -> unit = "camlidl_mpz_mpz_set_d" (** For [set_q: t -> Mpq.t -> unit], see {!Mpq.get_z} *) external mpz__set_str : mpz_ptr -> string -> int -> unit = "camlidl_mpz_mpz__set_str" val set_str : t -> string -> base:int -> unit external mpz_swap : mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_swap" (** {2 Combined Initialization and Assignment Functions} *) (** {{:http://gmplib.org/manual/Simultaneous-Integer-Init-_0026-Assign.html#Simultaneous-Integer-Init-_0026-Assign}C documentation} *) external mpz_init_set : mpz_ptr -> mpz_ptr = "camlidl_mpz_mpz_init_set" external mpz_init_set_si : int -> mpz_ptr = "camlidl_mpz_mpz_init_set_si" external mpz_init_set_d : float -> mpz_ptr = "camlidl_mpz_mpz_init_set_d" external mpz__init_set_str : string -> int -> mpz_ptr = "camlidl_mpz_mpz__init_set_str" val init_set_str : string -> base:int -> t (** {2 Conversion Functions} *) (** {{:http://gmplib.org/manual/Converting-Integers.html#Converting-Integers}C documentation} *) external mpz_get_si : mpz_ptr -> nativeint = "camlidl_mpz_mpz_get_si" external mpz_get_int : mpz_ptr -> int = "camlidl_mpz_mpz_get_int" external mpz_get_d : mpz_ptr -> float = "camlidl_mpz_mpz_get_d" external mpz_get_d_2exp : mpz_ptr -> float * int = "camlidl_mpz_mpz_get_d_2exp" external mpz__get_str : int -> mpz_ptr -> string = "camlidl_mpz_mpz__get_str" val get_str : base:int -> t -> string (** {2 User Conversions} *) (** These functions are additions to or renaming of functions offered by the C library. *) val to_string : t -> string val to_float : t -> float val of_string : string -> t val of_float : float -> t val of_int : int -> t (** {2 Arithmetic Functions} *) (** {{:http://gmplib.org/manual/Integer-Arithmetic.html#Integer-Arithmetic}C documentation} *) (** The first parameter holds the result. *) external mpz_add : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_add" external mpz_add_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_add_ui" external mpz_sub : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_sub" external mpz_sub_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_sub_ui" external mpz_ui_sub : mpz_ptr -> int -> mpz_ptr -> unit = "camlidl_mpz_mpz_ui_sub" external mpz_mul : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_mul" external mpz_mul_si : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_mul_si" external mpz_addmul : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_addmul" external mpz_addmul_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_addmul_ui" external mpz_submul : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_submul" external mpz_submul_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_submul_ui" external mpz_mul_2exp : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_mul_2exp" external mpz_neg : mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_neg" external mpz_abs : mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_abs" (** {2 Division Functions} *) (** {{:http://gmplib.org/manual/Integer-Division.html#Integer-Division}C documentation} *) (** [c] stands for ceiling, [f] for floor, and [t] for truncate (rounds toward 0).*) (** {3 Ceiling division} *) (** The first parameter holds the quotient. *) external mpz_cdiv_q : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_cdiv_q" (** The first parameter holds the remainder. *) external mpz_cdiv_r : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_cdiv_r" (** The two first parameters hold resp. the quotient and the remainder). *) external mpz_cdiv_qr : mpz_ptr -> mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_cdiv_qr" (** The first parameter holds the quotient. *) external mpz_cdiv_q_ui : mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_cdiv_q_ui" (** The first parameter holds the remainder. *) external mpz_cdiv_r_ui : mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_cdiv_r_ui" (** The two first parameters hold resp. the quotient and the remainder). *) external mpz_cdiv_qr_ui : mpz_ptr -> mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_cdiv_qr_ui" external mpz_cdiv_ui : mpz_ptr -> int -> int = "camlidl_mpz_mpz_cdiv_ui" (** The first parameter holds the quotient. *) external mpz_cdiv_q_2exp : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_cdiv_q_2exp" (** The first parameter holds the remainder. *) external mpz_cdiv_r_2exp : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_cdiv_r_2exp" (** {3 Floor division} *) external mpz_fdiv_q : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_fdiv_q" external mpz_fdiv_r : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_fdiv_r" external mpz_fdiv_qr : mpz_ptr -> mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_fdiv_qr" external mpz_fdiv_q_ui : mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_fdiv_q_ui" external mpz_fdiv_r_ui : mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_fdiv_r_ui" external mpz_fdiv_qr_ui : mpz_ptr -> mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_fdiv_qr_ui" external mpz_fdiv_ui : mpz_ptr -> int -> int = "camlidl_mpz_mpz_fdiv_ui" external mpz_fdiv_q_2exp : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_fdiv_q_2exp" external mpz_fdiv_r_2exp : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_fdiv_r_2exp" (** {3 Truncate division} *) external mpz_tdiv_q : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_tdiv_q" external mpz_tdiv_r : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_tdiv_r" external mpz_tdiv_qr : mpz_ptr -> mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_tdiv_qr" external mpz_tdiv_q_ui : mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_tdiv_q_ui" external mpz_tdiv_r_ui : mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_tdiv_r_ui" external mpz_tdiv_qr_ui : mpz_ptr -> mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_tdiv_qr_ui" external mpz_tdiv_ui : mpz_ptr -> int -> int = "camlidl_mpz_mpz_tdiv_ui" external mpz_tdiv_q_2exp : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_tdiv_q_2exp" external mpz_tdiv_r_2exp : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_tdiv_r_2exp" (** {3 Other division-related functions} *) external mpz_gmod : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_gmod" external mpz_gmod_ui : mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_gmod_ui" external mpz_divexact : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_divexact" external mpz_divexact_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_divexact_ui" external mpz_divisible_p : mpz_ptr -> mpz_ptr -> bool = "camlidl_mpz_mpz_divisible_p" external mpz_divisible_ui_p : mpz_ptr -> int -> bool = "camlidl_mpz_mpz_divisible_ui_p" external mpz_divisible_2exp_p : mpz_ptr -> int -> bool = "camlidl_mpz_mpz_divisible_2exp_p" external mpz_congruent_p : mpz_ptr -> mpz_ptr -> mpz_ptr -> bool = "camlidl_mpz_mpz_congruent_p" external mpz_congruent_ui_p : mpz_ptr -> int -> int -> bool = "camlidl_mpz_mpz_congruent_ui_p" external mpz_congruent_2exp_p : mpz_ptr -> mpz_ptr -> int -> bool = "camlidl_mpz_mpz_congruent_2exp_p" (** {2 Exponentiation Functions} *) (** {{:http://gmplib.org/manual/Integer-Exponentiation.html#Integer-Exponentiation}C documentation} *) external mpz__powm : mpz_ptr -> mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz__powm" external mpz__powm_ui : mpz_ptr -> mpz_ptr -> int -> mpz_ptr -> unit = "camlidl_mpz_mpz__powm_ui" val powm : t -> t -> t -> modulo:t -> unit val powm_ui : t -> t -> int -> modulo:t -> unit external mpz_pow_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_pow_ui" external mpz_ui_pow_ui : mpz_ptr -> int -> int -> unit = "camlidl_mpz_mpz_ui_pow_ui" (** {2 Root Extraction Functions} *) (** {{:http://gmplib.org/manual/Integer-Roots.html#Integer-Roots}C documentation} *) external mpz_root : mpz_ptr -> mpz_ptr -> int -> bool = "camlidl_mpz_mpz_root" external mpz_sqrt : mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_sqrt" external mpz__sqrtrem : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz__sqrtrem" val sqrtrem : t -> remainder:t -> t -> unit external mpz_perfect_power_p : mpz_ptr -> bool = "camlidl_mpz_mpz_perfect_power_p" external mpz_perfect_square_p : mpz_ptr -> bool = "camlidl_mpz_mpz_perfect_square_p" (** {2 Number Theoretic Functions} *) (** {{:http://gmplib.org/manual/Number-Theoretic-Functions.html#Number-Theoretic-Functions}C documentation} *) external mpz_probab_prime_p : mpz_ptr -> int -> int = "camlidl_mpz_mpz_probab_prime_p" external mpz_nextprime : mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_nextprime" external mpz_gcd : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_gcd" external mpz_gcd_ui : mpz_ptr option -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_gcd_ui" external mpz__gcdext : mpz_ptr -> mpz_ptr -> mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz__gcdext" val gcdext : gcd:t -> alpha:t -> beta:t -> t -> t -> unit external mpz_lcm : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_lcm" external mpz_lcm_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_lcm_ui" external mpz_invert : mpz_ptr -> mpz_ptr -> mpz_ptr -> bool = "camlidl_mpz_mpz_invert" external mpz_jacobi : mpz_ptr -> mpz_ptr -> int = "camlidl_mpz_mpz_jacobi" external mpz_legendre : mpz_ptr -> mpz_ptr -> int = "camlidl_mpz_mpz_legendre" external mpz_kronecker : mpz_ptr -> mpz_ptr -> int = "camlidl_mpz_mpz_kronecker" external mpz_kronecker_si : mpz_ptr -> int -> int = "camlidl_mpz_mpz_kronecker_si" external mpz_si_kronecker : int -> mpz_ptr -> int = "camlidl_mpz_mpz_si_kronecker" external mpz_remove : mpz_ptr -> mpz_ptr -> mpz_ptr -> int = "camlidl_mpz_mpz_remove" external mpz_fac_ui : mpz_ptr -> int -> unit = "camlidl_mpz_mpz_fac_ui" external mpz_bin_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_bin_ui" external mpz_bin_uiui : mpz_ptr -> int -> int -> unit = "camlidl_mpz_mpz_bin_uiui" external mpz_fib_ui : mpz_ptr -> int -> unit = "camlidl_mpz_mpz_fib_ui" external mpz_fib2_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_fib2_ui" external mpz_lucnum_ui : mpz_ptr -> int -> unit = "camlidl_mpz_mpz_lucnum_ui" external mpz_lucnum2_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_lucnum2_ui" (** {2 Comparison Functions} *) (** {{:http://gmplib.org/manual/Integer-Comparisons.html#Integer-Comparisons}C documentation} *) external mpz_cmp : mpz_ptr -> mpz_ptr -> int = "camlidl_mpz_mpz_cmp" external mpz_cmp_d : mpz_ptr -> float -> int = "camlidl_mpz_mpz_cmp_d" external mpz_cmp_si : mpz_ptr -> int -> int = "camlidl_mpz_mpz_cmp_si" external mpz_cmpabs : mpz_ptr -> mpz_ptr -> int = "camlidl_mpz_mpz_cmpabs" external mpz_cmpabs_d : mpz_ptr -> float -> int = "camlidl_mpz_mpz_cmpabs_d" external mpz_cmpabs_ui : mpz_ptr -> int -> int = "camlidl_mpz_mpz_cmpabs_ui" external mpz_sgn : mpz_ptr -> int = "camlidl_mpz_mpz_sgn" (** {2 Logical and Bit Manipulation Functions} *) (** {{:http://gmplib.org/manual/Integer-Logic-and-Bit-Fiddling.html#Integer-Logic-and-Bit-Fiddling}C documentation} *) external mpz_gand : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_gand" external mpz_ior : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_ior" external mpz_xor : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_xor" external mpz_com : mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_com" external mpz_popcount : mpz_ptr -> int = "camlidl_mpz_mpz_popcount" external mpz_hamdist : mpz_ptr -> mpz_ptr -> int = "camlidl_mpz_mpz_hamdist" external mpz_scan0 : mpz_ptr -> int -> int = "camlidl_mpz_mpz_scan0" external mpz_scan1 : mpz_ptr -> int -> int = "camlidl_mpz_mpz_scan1" external mpz_setbit : mpz_ptr -> int -> unit = "camlidl_mpz_mpz_setbit" external mpz_clrbit : mpz_ptr -> int -> unit = "camlidl_mpz_mpz_clrbit" external mpz_tstbit : mpz_ptr -> int -> bool = "camlidl_mpz_mpz_tstbit" (** {2 Input and Output Functions: not interfaced} *) (** {2 Random Number Functions: see {!Gmp_random} module} *) (** {2 Integer Import and Export Functions} *) (** {{:ttp://gmplib.org/manual/Integer-Import-and-Export.html#Integer-Import-and-Export}C documentation} *) external mpz__import : mpz_ptr -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t -> int -> int -> unit = "camlidl_mpz_mpz__import" external mpz__export : mpz_ptr -> int -> int -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t = "camlidl_mpz_mpz__export" val import : dest:t -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t -> order:int -> endian:int -> unit val export : t -> order:int -> endian:int -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t (** {2 Miscellaneous Functions} *) (** {{:http://gmplib.org/manual/Miscellaneous-Integer-Functions.html#Miscellaneous-Integer-Functions}C documentation} *) (* Does it fit in an OCaml integer *) external mpz_fits_int_p : mpz_ptr -> bool = "camlidl_mpz_mpz_fits_int_p" external mpz_odd_p : mpz_ptr -> bool = "camlidl_mpz_mpz_odd_p" external mpz_even_p : mpz_ptr -> bool = "camlidl_mpz_mpz_even_p" external mpz_size : mpz_ptr -> int = "camlidl_mpz_mpz_size" external mpz_sizeinbase : mpz_ptr -> int -> int = "camlidl_mpz_mpz_sizeinbase" (* Limited relevance here *) external mpz_fits_ulong_p : mpz_ptr -> bool = "camlidl_mpz_mpz_fits_ulong_p" external mpz_fits_slong_p : mpz_ptr -> bool = "camlidl_mpz_mpz_fits_slong_p" external mpz_fits_uint_p : mpz_ptr -> bool = "camlidl_mpz_mpz_fits_uint_p" external mpz_fits_sint_p : mpz_ptr -> bool = "camlidl_mpz_mpz_fits_sint_p" external mpz_fits_ushort_p : mpz_ptr -> bool = "camlidl_mpz_mpz_fits_ushort_p" external mpz_fits_sshort_p : mpz_ptr -> bool = "camlidl_mpz_mpz_fits_sshort_p" apron-dist-0.9.10/mlgmpidl/tmp/mpf_stubs.c0000640014525101416610000005704411252216513020330 0ustar bjeannetpopart/* File generated from mpf.idl */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include "caml/custom.h" #include "gmp_caml.h" extern void camlidl_mpz_ptr_ml2c(value, mpz_ptr *); #define camlidl_ml2c_mpz_mpz_ptr(v,c,ctx) camlidl_mpz_ptr_ml2c(v,c) extern value camlidl_mpz_ptr_c2ml(mpz_ptr *); #define camlidl_c2ml_mpz_mpz_ptr(c,ctx) camlidl_mpz_ptr_c2ml(c) extern void camlidl_mpq_ptr_ml2c(value, mpq_ptr *); #define camlidl_ml2c_mpq_mpq_ptr(v,c,ctx) camlidl_mpq_ptr_ml2c(v,c) extern value camlidl_mpq_ptr_c2ml(mpq_ptr *); #define camlidl_c2ml_mpq_mpq_ptr(c,ctx) camlidl_mpq_ptr_c2ml(c) #define camlidl_ml2c_mpf_mpf_ptr(v,c,ctx) camlidl_mpf_ptr_ml2c(v,c) #define camlidl_c2ml_mpf_mpf_ptr(c,ctx) camlidl_mpf_ptr_c2ml(c) value camlidl_mpf_mpf_set_default_prec( value _v_PREC) { unsigned long PREC; /*in*/ PREC = Long_val(_v_PREC); mpf_set_default_prec(PREC); return Val_unit; } value camlidl_mpf_mpf_get_default_prec(value _unit) { unsigned long _res; value _vres; _res = mpf_get_default_prec(); _vres = Val_long(_res); return _vres; } value camlidl_mpf_mpf_init(value _unit) { mpf_ptr OUTOUTOUT; /*out*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; mpf_init(OUTOUTOUT); _vres = camlidl_c2ml_mpf_mpf_ptr(&OUTOUTOUT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_init2( value _v_PREC) { mpf_ptr OUTOUTOUT; /*out*/ unsigned long PREC; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; PREC = Long_val(_v_PREC); mpf_init2(OUTOUTOUT, PREC); _vres = camlidl_c2ml_mpf_mpf_ptr(&OUTOUTOUT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_get_prec( value _v_OP) { mpf_ptr OP; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_get_prec(OP); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_set_prec( value _v_ROP, value _v_PREC) { mpf_ptr ROP; /*in*/ unsigned long PREC; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); PREC = Long_val(_v_PREC); mpf_set_prec(ROP, PREC); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_set_prec_raw( value _v_ROP, value _v_PREC) { mpf_ptr ROP; /*in*/ unsigned long PREC; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); PREC = Long_val(_v_PREC); mpf_set_prec_raw(ROP, PREC); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_set( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ mpf_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); mpf_set(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_set_si( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ long OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); OP = Long_val(_v_OP); mpf_set_si(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_set_d( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ double OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); OP = Double_val(_v_OP); mpf_set_d(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_set_z( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); mpf_set_z(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_set_q( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ mpq_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); mpf_set_q(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf__set_str( value _v_ROP, value _v_STR, value _v_BASE) { mpf_ptr ROP; /*in*/ char *STR; /*in*/ int BASE; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); STR = String_val(_v_STR); BASE = Int_val(_v_BASE); /* begin user-supplied calling sequence */ { int n = mpf_set_str(ROP,STR,BASE); if (n){ mpf_clear(ROP); caml_invalid_argument(""); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_swap( value _v_ROP1, value _v_ROP2) { mpf_ptr ROP1; /*in*/ mpf_ptr ROP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP1, &ROP1, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_ROP2, &ROP2, _ctx); mpf_swap(ROP1, ROP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_init_set( value _v_OP) { mpf_ptr OUTOUTOUT; /*out*/ mpf_ptr OP; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); mpf_init_set(OUTOUTOUT, OP); _vres = camlidl_c2ml_mpf_mpf_ptr(&OUTOUTOUT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_init_set_si( value _v_OP) { mpf_ptr OUTOUTOUT; /*out*/ long OP; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; OP = Long_val(_v_OP); mpf_init_set_si(OUTOUTOUT, OP); _vres = camlidl_c2ml_mpf_mpf_ptr(&OUTOUTOUT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_init_set_d( value _v_OP) { mpf_ptr OUTOUTOUT; /*out*/ double OP; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; OP = Double_val(_v_OP); mpf_init_set_d(OUTOUTOUT, OP); _vres = camlidl_c2ml_mpf_mpf_ptr(&OUTOUTOUT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf__init_set_str( value _v_STR, value _v_BASE) { mpf_ptr OUTOUTOUT; /*out*/ char *STR; /*in*/ int BASE; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; STR = String_val(_v_STR); BASE = Int_val(_v_BASE); /* begin user-supplied calling sequence */ { int n = mpf_init_set_str(OUTOUTOUT,STR,BASE); if (n){ mpf_clear(OUTOUTOUT); caml_invalid_argument(""); } } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_mpf_mpf_ptr(&OUTOUTOUT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_get_d( value _v_OP) { mpf_ptr OP; /*in*/ double _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_get_d(OP); _vres = copy_double(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_get_d_2exp( value _v_OP) { long *EXP; /*out*/ mpf_ptr OP; /*in*/ double _res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; long _c1; value _vresult; value _vres[2] = { 0, 0, }; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); EXP = &_c1; _res = mpf_get_d_2exp(EXP, OP); Begin_roots_block(_vres, 2) _vres[0] = copy_double(_res); _vres[1] = Val_long(*EXP); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); return _vresult; } value camlidl_mpf_mpf_get_si( value _v_OP) { mpf_ptr OP; /*in*/ long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_get_si(OP); _vres = copy_nativeint(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_get_int( value _v_OP) { mpf_ptr OP; /*in*/ long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); /* begin user-supplied calling sequence */ _res = mpf_get_si(OP); /* end user-supplied calling sequence */ _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_get_z( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ mpf_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); /* begin user-supplied calling sequence */ mpz_set_f(ROP,OP); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_get_q( value _v_ROP, value _v_OP) { mpq_ptr ROP; /*in*/ mpf_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); /* begin user-supplied calling sequence */ mpq_set_f(ROP,OP); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf__get_str( value _v_BASE, value _v_N_DIGITS, value _v_OP) { long *EXPPTR; /*out*/ int BASE; /*in*/ int N_DIGITS; /*in*/ mpf_ptr OP; /*in*/ char *_res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; long _c1; value _vresult; value _vres[2] = { 0, 0, }; BASE = Int_val(_v_BASE); N_DIGITS = Int_val(_v_N_DIGITS); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); EXPPTR = &_c1; /* begin user-supplied calling sequence */ _res = mpf_get_str(NULL,EXPPTR,BASE,N_DIGITS,OP); /* end user-supplied calling sequence */ Begin_roots_block(_vres, 2) _vres[0] = copy_string(_res); _vres[1] = Val_long(*EXPPTR); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ free(_res); /* end user-supplied deallocation sequence */ return _vresult; } value camlidl_mpf_mpf_add( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ mpf_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP2, &OP2, _ctx); mpf_add(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_add_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpf_add_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_sub( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ mpf_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP2, &OP2, _ctx); mpf_sub(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_ui_sub( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ unsigned long OP1; /*in*/ mpf_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); OP1 = Long_val(_v_OP1); camlidl_ml2c_mpf_mpf_ptr(_v_OP2, &OP2, _ctx); mpf_ui_sub(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_sub_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpf_sub_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_mul( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ mpf_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP2, &OP2, _ctx); mpf_mul(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_mul_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpf_mul_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_mul_2exp( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpf_mul_2exp(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_div( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ mpf_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP2, &OP2, _ctx); mpf_div(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_ui_div( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ unsigned long OP1; /*in*/ mpf_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); OP1 = Long_val(_v_OP1); camlidl_ml2c_mpf_mpf_ptr(_v_OP2, &OP2, _ctx); mpf_ui_div(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_div_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpf_div_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_div_2exp( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpf_div_2exp(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_sqrt( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ mpf_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); mpf_sqrt(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_pow_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpf_pow_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_neg( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ mpf_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); mpf_neg(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_abs( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ mpf_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); mpf_abs(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_cmp( value _v_OP1, value _v_OP2) { mpf_ptr OP1; /*in*/ mpf_ptr OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP2, &OP2, _ctx); _res = mpf_cmp(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_cmp_d( value _v_OP1, value _v_OP2) { mpf_ptr OP1; /*in*/ double OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); OP2 = Double_val(_v_OP2); _res = mpf_cmp_d(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_cmp_si( value _v_OP1, value _v_OP2) { mpf_ptr OP1; /*in*/ long OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); _res = mpf_cmp_si(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_sgn( value _v_OP) { mpf_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_sgn(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf__equal( value _v_OP1, value _v_OP2, value _v_OP3) { mpf_ptr OP1; /*in*/ mpf_ptr OP2; /*in*/ unsigned long OP3; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP2, &OP2, _ctx); OP3 = Long_val(_v_OP3); /* begin user-supplied calling sequence */ _res=mpf_eq(OP1,OP2,OP3); /* end user-supplied calling sequence */ _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_reldiff( value _v_ROP, value _v_OP1, value _v_OP2) { mpf_ptr ROP; /*in*/ mpf_ptr OP1; /*in*/ mpf_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP2, &OP2, _ctx); mpf_reldiff(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_ceil( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ mpf_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); mpf_ceil(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_floor( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ mpf_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); mpf_floor(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_trunc( value _v_ROP, value _v_OP) { mpf_ptr ROP; /*in*/ mpf_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); mpf_trunc(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpf_mpf_integer_p( value _v_OP) { mpf_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_integer_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_fits_int_p( value _v_OP) { mpf_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_fits_int_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_fits_ulong_p( value _v_OP) { mpf_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_fits_ulong_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_fits_slong_p( value _v_OP) { mpf_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_fits_slong_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_fits_uint_p( value _v_OP) { mpf_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_fits_uint_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_fits_sint_p( value _v_OP) { mpf_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_fits_sint_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_fits_ushort_p( value _v_OP) { mpf_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_fits_ushort_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpf_mpf_fits_sshort_p( value _v_OP) { mpf_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpf_mpf_ptr(_v_OP, &OP, _ctx); _res = mpf_fits_sshort_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } apron-dist-0.9.10/mlgmpidl/tmp/mpfr.mli0000640014525101416610000003736611252216513017636 0ustar bjeannetpopart(* File generated from mpfr.idl *) type mpfr_ptr and mpfr_rnd_t = | Near | Zero | Up | Down (** MPFR multiprecision floating-point numbers *) (** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x]. These functions are as efficient as their C counterpart: they do not imply additional memory allocation. *) (** {2 Pretty printing} *) val print : Format.formatter -> t -> unit val print_round : Format.formatter -> round -> unit val string_of_round : round -> string (** {2 Rounding Modes} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Rounding-Related-Functions}C documentation} *) external mpfr_set_default_rounding_mode : mpfr_rnd_t -> unit = "camlidl_mpfr_mpfr_set_default_rounding_mode" external mpfr_get_default_rounding_mode : unit -> mpfr_rnd_t = "camlidl_mpfr_mpfr_get_default_rounding_mode" external mpfr_round_prec : mpfr_ptr -> mpfr_rnd_t -> int -> int = "camlidl_mpfr_mpfr_round_prec" (** {2 Exceptions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Exception-Related-Functions}C documentation} *) external mpfr_get_emin : unit -> int = "camlidl_mpfr_mpfr_get_emin" external mpfr_get_emax : unit -> int = "camlidl_mpfr_mpfr_get_emax" external mpfr_set_emin : int -> unit = "camlidl_mpfr_mpfr_set_emin" external mpfr_set_emax : int -> unit = "camlidl_mpfr_mpfr_set_emax" external mpfr_check_range : mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_check_range" external mpfr_clear_underflow : unit -> unit = "camlidl_mpfr_mpfr_clear_underflow" external mpfr_clear_overflow : unit -> unit = "camlidl_mpfr_mpfr_clear_overflow" external mpfr_clear_nanflag : unit -> unit = "camlidl_mpfr_mpfr_clear_nanflag" external mpfr_clear_inexflag : unit -> unit = "camlidl_mpfr_mpfr_clear_inexflag" external mpfr_clear_flags : unit -> unit = "camlidl_mpfr_mpfr_clear_flags" external mpfr_underflow_p : unit -> bool = "camlidl_mpfr_mpfr_underflow_p" external mpfr_overflow_p : unit -> bool = "camlidl_mpfr_mpfr_overflow_p" external mpfr_nanflag_p : unit -> bool = "camlidl_mpfr_mpfr_nanflag_p" external mpfr_inexflag_p : unit -> bool = "camlidl_mpfr_mpfr_inexflag_p" (** {2 Initialization Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Initialization-Functions}C documentation} *) external mpfr_set_default_prec : int -> unit = "camlidl_mpfr_mpfr_set_default_prec" external mpfr_get_default_prec : unit -> int = "camlidl_mpfr_mpfr_get_default_prec" external mpfr_init : unit -> mpfr_ptr = "camlidl_mpfr_mpfr_init" external mpfr_init2 : int -> mpfr_ptr = "camlidl_mpfr_mpfr_init2" external mpfr_get_prec : mpfr_ptr -> int = "camlidl_mpfr_mpfr_get_prec" external mpfr_set_prec : mpfr_ptr -> int -> unit = "camlidl_mpfr_mpfr_set_prec" external mpfr_set_prec_raw : mpfr_ptr -> int -> unit = "camlidl_mpfr_mpfr_set_prec_raw" (** {2 Assignment Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Assignment-Functions}C documentation} *) external mpfr_set : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_set" external mpfr_set_si : mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_set_si" external mpfr_set_d : mpfr_ptr -> float -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_set_d" external mpfr_set_z : mpfr_ptr -> Mpz.mpz_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_set_z" external mpfr_set_q : mpfr_ptr -> Mpq.mpq_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_set_q" external mpfr__set_str : mpfr_ptr -> string -> int -> mpfr_rnd_t -> unit = "camlidl_mpfr_mpfr__set_str" val set_str : t -> string -> base:int -> mpfr_rnd_t -> unit external mpfr_set_f : mpfr_ptr -> Mpf.mpf_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_set_f" external mpfr_set_si_2exp : mpfr_ptr -> int -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_set_si_2exp" external mpfr_set_inf : mpfr_ptr -> int -> unit = "camlidl_mpfr_mpfr_set_inf" external mpfr_set_nan : mpfr_ptr -> unit = "camlidl_mpfr_mpfr_set_nan" external mpfr_swap : mpfr_ptr -> mpfr_ptr -> unit = "camlidl_mpfr_mpfr_swap" (** {2 Combined Initialization and Assignment Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Combined-Initialization-and-Assignment-Functions}C documentation} *) external mpfr_init_set : mpfr_ptr -> mpfr_rnd_t -> int * mpfr_ptr = "camlidl_mpfr_mpfr_init_set" external mpfr_init_set_si : int -> mpfr_rnd_t -> int * mpfr_ptr = "camlidl_mpfr_mpfr_init_set_si" external mpfr_init_set_d : float -> mpfr_rnd_t -> int * mpfr_ptr = "camlidl_mpfr_mpfr_init_set_d" external mpfr_init_set_f : Mpf.mpf_ptr -> mpfr_rnd_t -> int * mpfr_ptr = "camlidl_mpfr_mpfr_init_set_f" external mpfr_init_set_z : Mpz.mpz_ptr -> mpfr_rnd_t -> int * mpfr_ptr = "camlidl_mpfr_mpfr_init_set_z" external mpfr_init_set_q : Mpq.mpq_ptr -> mpfr_rnd_t -> int * mpfr_ptr = "camlidl_mpfr_mpfr_init_set_q" external mpfr__init_set_str : string -> int -> mpfr_rnd_t -> mpfr_ptr = "camlidl_mpfr_mpfr__init_set_str" val init_set_str : string -> base:int -> mpfr_rnd_t -> t (** {2 Conversion Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Conversion-Functions}C documentation} *) external mpfr_get_d : mpfr_ptr -> mpfr_rnd_t -> float = "camlidl_mpfr_mpfr_get_d" external mpfr_get_d1 : mpfr_ptr -> float = "camlidl_mpfr_mpfr_get_d1" external mpfr_get_z_exp : Mpz.mpz_ptr -> mpfr_ptr -> int = "camlidl_mpfr_mpfr_get_z_exp" external mpfr_get_z : Mpz.mpz_ptr -> mpfr_ptr -> mpfr_rnd_t -> unit = "camlidl_mpfr_mpfr_get_z" external mpfr__get_str : int -> int -> mpfr_ptr -> mpfr_rnd_t -> string * int = "camlidl_mpfr_mpfr__get_str" val get_str : base:int -> digits:int -> t -> mpfr_rnd_t -> string * int (** {2 User Conversions} *) (** These functionss are additions to or renaming of functions offered by the C library. *) val to_string : t -> string val to_float : ?round:round -> t -> float val to_mpq : t -> Mpq.t val of_string : string -> round -> t val of_float : float -> round -> t val of_int : int -> round -> t val of_frac : int -> int -> round -> t val of_mpz : Mpz.t -> round -> t val of_mpz2 : Mpz.t -> Mpz.t -> round -> t val of_mpq : Mpq.t -> round -> t (** {2 Basic Arithmetic Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Basic-Arithmetic-Functions}C documentation} *) external mpfr_add : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_add" external mpfr_add_ui : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_add_ui" external mpfr_add_z : mpfr_ptr -> mpfr_ptr -> Mpz.mpz_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_add_z" external mpfr_add_q : mpfr_ptr -> mpfr_ptr -> Mpq.mpq_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_add_q" external mpfr_sub : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_sub" external mpfr_ui_sub : mpfr_ptr -> int -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_ui_sub" external mpfr_sub_ui : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_sub_ui" external mpfr_sub_z : mpfr_ptr -> mpfr_ptr -> Mpz.mpz_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_sub_z" external mpfr_sub_q : mpfr_ptr -> mpfr_ptr -> Mpq.mpq_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_sub_q" external mpfr_mul : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_mul" external mpfr_mul_ui : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_mul_ui" external mpfr_mul_z : mpfr_ptr -> mpfr_ptr -> Mpz.mpz_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_mul_z" external mpfr_mul_q : mpfr_ptr -> mpfr_ptr -> Mpq.mpq_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_mul_q" external mpfr_mul_2ui : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_mul_2ui" external mpfr_mul_2si : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_mul_2si" external mpfr_mul_2exp : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_mul_2exp" external mpfr_div : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_div" external mpfr_ui_div : mpfr_ptr -> int -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_ui_div" external mpfr_div_ui : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_div_ui" external mpfr_div_z : mpfr_ptr -> mpfr_ptr -> Mpz.mpz_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_div_z" external mpfr_div_q : mpfr_ptr -> mpfr_ptr -> Mpq.mpq_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_div_q" external mpfr_div_2ui : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_div_2ui" external mpfr_div_2si : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_div_2si" val div_2exp : t -> t -> int -> mpfr_rnd_t -> int external mpfr_sqrt : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> bool = "camlidl_mpfr_mpfr_sqrt" external mpfr_sqrt_ui : mpfr_ptr -> int -> mpfr_rnd_t -> bool = "camlidl_mpfr_mpfr_sqrt_ui" external mpfr_pow_ui : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> bool = "camlidl_mpfr_mpfr_pow_ui" external mpfr_pow_si : mpfr_ptr -> mpfr_ptr -> int -> mpfr_rnd_t -> bool = "camlidl_mpfr_mpfr_pow_si" external mpfr_ui_pow_ui : mpfr_ptr -> int -> int -> mpfr_rnd_t -> bool = "camlidl_mpfr_mpfr_ui_pow_ui" external mpfr_ui_pow : mpfr_ptr -> int -> mpfr_ptr -> mpfr_rnd_t -> bool = "camlidl_mpfr_mpfr_ui_pow" external mpfr_pow : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> bool = "camlidl_mpfr_mpfr_pow" external mpfr_neg : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_neg" external mpfr_abs : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_abs" (** {2 Comparison Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Comparison-Functions}C documentation} *) external mpfr_cmp : mpfr_ptr -> mpfr_ptr -> int = "camlidl_mpfr_mpfr_cmp" external mpfr_cmp_si : mpfr_ptr -> int -> int = "camlidl_mpfr_mpfr_cmp_si" external mpfr_cmp_si_2exp : mpfr_ptr -> int -> int -> int = "camlidl_mpfr_mpfr_cmp_si_2exp" external mpfr_sgn : mpfr_ptr -> int = "camlidl_mpfr_mpfr_sgn" external mpfr__equal : mpfr_ptr -> mpfr_ptr -> int -> bool = "camlidl_mpfr_mpfr__equal" val equal : t -> t -> bits:int -> bool external mpfr_nan_p : mpfr_ptr -> bool = "camlidl_mpfr_mpfr_nan_p" external mpfr_inf_p : mpfr_ptr -> bool = "camlidl_mpfr_mpfr_inf_p" external mpfr_number_p : mpfr_ptr -> bool = "camlidl_mpfr_mpfr_number_p" external mpfr_reldiff : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> unit = "camlidl_mpfr_mpfr_reldiff" (** {2 Special Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Special-Functions}C documentation} *) external mpfr_log : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_log" external mpfr_log2 : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_log2" external mpfr_log10 : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_log10" external mpfr_exp : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_exp" external mpfr_exp2 : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_exp2" external mpfr_exp10 : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_exp10" external mpfr_cos : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_cos" external mpfr_sin : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_sin" external mpfr_tan : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_tan" external mpfr_sec : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_sec" external mpfr_csc : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_csc" external mpfr_cot : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_cot" external mpfr_sin_cos : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> bool = "camlidl_mpfr_mpfr_sin_cos" external mpfr_acos : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_acos" external mpfr_asin : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_asin" external mpfr_atan : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_atan" external mpfr_atan2 : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_atan2" external mpfr_cosh : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_cosh" external mpfr_sinh : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_sinh" external mpfr_tanh : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_tanh" external mpfr_sech : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_sech" external mpfr_csch : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_csch" external mpfr_coth : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_coth" external mpfr_acosh : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_acosh" external mpfr_asinh : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_asinh" external mpfr_atanh : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_atanh" external mpfr_fac_ui : mpfr_ptr -> int -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_fac_ui" external mpfr_log1p : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_log1p" external mpfr_expm1 : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_expm1" external mpfr_eint : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_eint" external mpfr_gamma : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_gamma" external mpfr_lngamma : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_lngamma" external mpfr_zeta : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_zeta" external mpfr_erf : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_erf" external mpfr_erfc : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_erfc" external mpfr_fma : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_fma" external mpfr_agm : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_agm" external mpfr_hypot : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_hypot" external mpfr_const_log2 : mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_const_log2" external mpfr_const_pi : mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_const_pi" external mpfr_const_euler : mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_const_euler" external mpfr_const_catalan : mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_const_catalan" (** {2 Input and Output Functions: not interfaced} *) (** {2 Miscellaneous Float Functions} *) (** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Rounding-Related-Functions}C documentation} *) external mpfr_rint : mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_rint" external mpfr_ceil : mpfr_ptr -> mpfr_ptr -> int = "camlidl_mpfr_mpfr_ceil" external mpfr_floor : mpfr_ptr -> mpfr_ptr -> int = "camlidl_mpfr_mpfr_floor" external mpfr_round : mpfr_ptr -> mpfr_ptr -> int = "camlidl_mpfr_mpfr_round" external mpfr_trunc : mpfr_ptr -> mpfr_ptr -> int = "camlidl_mpfr_mpfr_trunc" external mpfr_integer_p : mpfr_ptr -> bool = "camlidl_mpfr_mpfr_integer_p" external mpfr_nexttoward : mpfr_ptr -> mpfr_ptr -> unit = "camlidl_mpfr_mpfr_nexttoward" external mpfr_nextabove : mpfr_ptr -> unit = "camlidl_mpfr_mpfr_nextabove" external mpfr_nextbelow : mpfr_ptr -> unit = "camlidl_mpfr_mpfr_nextbelow" external mpfr_min : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_min" external mpfr_max : mpfr_ptr -> mpfr_ptr -> mpfr_ptr -> mpfr_rnd_t -> int = "camlidl_mpfr_mpfr_max" external mpfr_get_exp : mpfr_ptr -> int = "camlidl_mpfr_mpfr_get_exp" external mpfr_set_exp : mpfr_ptr -> int -> int = "camlidl_mpfr_mpfr_set_exp" apron-dist-0.9.10/mlgmpidl/tmp/mpz_stubs.c0000640014525101416610000015741111252216512020352 0ustar bjeannetpopart/* File generated from mpz.idl */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include "limits.h" #include "caml/custom.h" #include "gmp_caml.h" #define camlidl_ml2c_mpz_mpz_ptr(v,c,ctx) camlidl_mpz_ptr_ml2c(v,c) #define camlidl_c2ml_mpz_mpz_ptr(c,ctx) camlidl_mpz_ptr_c2ml(c) value camlidl_mpz_mpz_init(value _unit) { mpz_ptr OUTOUTOUT; /*out*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; mpz_init(OUTOUTOUT); _vres = camlidl_c2ml_mpz_mpz_ptr(&OUTOUTOUT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_init2( value _v_N) { mpz_ptr OUTOUTOUT; /*out*/ unsigned long N; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; N = Long_val(_v_N); mpz_init2(OUTOUTOUT, N); _vres = camlidl_c2ml_mpz_mpz_ptr(&OUTOUTOUT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_realloc2( value _v_ROP, value _v_N) { mpz_ptr ROP; /*in*/ unsigned long N; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); N = Long_val(_v_N); mpz_realloc2(ROP, N); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_set( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); mpz_set(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_set_si( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ long OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); OP = Long_val(_v_OP); mpz_set_si(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_set_d( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ double OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); OP = Double_val(_v_OP); mpz_set_d(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz__set_str( value _v_ROP, value _v_STR, value _v_BASE) { mpz_ptr ROP; /*in*/ char *STR; /*in*/ int BASE; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); STR = String_val(_v_STR); BASE = Int_val(_v_BASE); /* begin user-supplied calling sequence */ { int n = mpz_set_str(ROP,STR,BASE); if (n){ mpz_clear(ROP); caml_invalid_argument(""); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_swap( value _v_ROP1, value _v_ROP2) { mpz_ptr ROP1; /*in*/ mpz_ptr ROP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP1, &ROP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_ROP2, &ROP2, _ctx); mpz_swap(ROP1, ROP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_init_set( value _v_OP) { mpz_ptr OUTOUTOUT; /*out*/ mpz_ptr OP; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); mpz_init_set(OUTOUTOUT, OP); _vres = camlidl_c2ml_mpz_mpz_ptr(&OUTOUTOUT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_init_set_si( value _v_OP) { mpz_ptr OUTOUTOUT; /*out*/ long OP; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; OP = Long_val(_v_OP); mpz_init_set_si(OUTOUTOUT, OP); _vres = camlidl_c2ml_mpz_mpz_ptr(&OUTOUTOUT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_init_set_d( value _v_OP) { mpz_ptr OUTOUTOUT; /*out*/ double OP; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; OP = Double_val(_v_OP); mpz_init_set_d(OUTOUTOUT, OP); _vres = camlidl_c2ml_mpz_mpz_ptr(&OUTOUTOUT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz__init_set_str( value _v_STR, value _v_BASE) { mpz_ptr OUTOUTOUT; /*out*/ char *STR; /*in*/ int BASE; /*in*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; STR = String_val(_v_STR); BASE = Int_val(_v_BASE); /* begin user-supplied calling sequence */ { int n = mpz_init_set_str(OUTOUTOUT,STR,BASE); if (n){ mpz_clear(OUTOUTOUT); caml_invalid_argument(""); } } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_mpz_mpz_ptr(&OUTOUTOUT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_get_si( value _v_OP) { mpz_ptr OP; /*in*/ long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_get_si(OP); _vres = copy_nativeint(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_get_int( value _v_OP) { mpz_ptr OP; /*in*/ long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); /* begin user-supplied calling sequence */ _res = mpz_get_si(OP); /* end user-supplied calling sequence */ _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_get_d( value _v_OP) { mpz_ptr OP; /*in*/ double _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_get_d(OP); _vres = copy_double(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_get_d_2exp( value _v_OP) { long *EXP; /*out*/ mpz_ptr OP; /*in*/ double _res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; long _c1; value _vresult; value _vres[2] = { 0, 0, }; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); EXP = &_c1; _res = mpz_get_d_2exp(EXP, OP); Begin_roots_block(_vres, 2) _vres[0] = copy_double(_res); _vres[1] = Val_long(*EXP); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); return _vresult; } value camlidl_mpz_mpz__get_str( value _v_BASE, value _v_OP) { int BASE; /*in*/ mpz_ptr OP; /*in*/ char *_res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; BASE = Int_val(_v_BASE); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); /* begin user-supplied calling sequence */ _res = mpz_get_str(NULL,BASE,OP); /* end user-supplied calling sequence */ _vres = copy_string(_res); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ free(_res); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_mpz_mpz_add( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_add(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_add_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpz_add_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_sub( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_sub(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_sub_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpz_sub_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_ui_sub( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ unsigned long OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); OP1 = Long_val(_v_OP1); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_ui_sub(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_mul( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_mul(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_mul_si( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpz_mul_si(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_addmul( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_addmul(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_addmul_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpz_addmul_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_submul( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_submul(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_submul_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpz_submul_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_mul_2exp( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpz_mul_2exp(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_neg( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); mpz_neg(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_abs( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); mpz_abs(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_cdiv_q( value _v_Q, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_cdiv_q(Q, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_cdiv_r( value _v_R, value _v_N, value _v_D) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_cdiv_r(R, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_cdiv_qr( value _v_Q, value _v_R, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_cdiv_qr(Q, R, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_cdiv_q_ui( value _v_Q, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_cdiv_q_ui(Q, N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_cdiv_r_ui( value _v_R, value _v_N, value _v_D) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_cdiv_r_ui(R, N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_cdiv_qr_ui( value _v_Q, value _v_R, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_cdiv_qr_ui(Q, R, N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_cdiv_ui( value _v_N, value _v_D) { mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_cdiv_ui(N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_cdiv_q_2exp( value _v_Q, value _v_N, value _v_B) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ unsigned long B; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); B = Long_val(_v_B); mpz_cdiv_q_2exp(Q, N, B); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_cdiv_r_2exp( value _v_R, value _v_N, value _v_B) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long B; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); B = Long_val(_v_B); mpz_cdiv_r_2exp(R, N, B); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_fdiv_q( value _v_Q, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_fdiv_q(Q, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_fdiv_r( value _v_R, value _v_N, value _v_D) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_fdiv_r(R, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_fdiv_qr( value _v_Q, value _v_R, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_fdiv_qr(Q, R, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_fdiv_q_ui( value _v_Q, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_fdiv_q_ui(Q, N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fdiv_r_ui( value _v_R, value _v_N, value _v_D) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_fdiv_r_ui(R, N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fdiv_qr_ui( value _v_Q, value _v_R, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_fdiv_qr_ui(Q, R, N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fdiv_ui( value _v_N, value _v_D) { mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_fdiv_ui(N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fdiv_q_2exp( value _v_Q, value _v_N, value _v_B) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ unsigned long B; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); B = Long_val(_v_B); mpz_fdiv_q_2exp(Q, N, B); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_fdiv_r_2exp( value _v_R, value _v_N, value _v_B) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long B; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); B = Long_val(_v_B); mpz_fdiv_r_2exp(R, N, B); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_tdiv_q( value _v_Q, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_tdiv_q(Q, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_tdiv_r( value _v_R, value _v_N, value _v_D) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_tdiv_r(R, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_tdiv_qr( value _v_Q, value _v_R, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_tdiv_qr(Q, R, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_tdiv_q_ui( value _v_Q, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_tdiv_q_ui(Q, N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_tdiv_r_ui( value _v_R, value _v_N, value _v_D) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_tdiv_r_ui(R, N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_tdiv_qr_ui( value _v_Q, value _v_R, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_tdiv_qr_ui(Q, R, N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_tdiv_ui( value _v_N, value _v_D) { mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_tdiv_ui(N, D); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_tdiv_q_2exp( value _v_Q, value _v_N, value _v_B) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ unsigned long B; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); B = Long_val(_v_B); mpz_tdiv_q_2exp(Q, N, B); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_tdiv_r_2exp( value _v_R, value _v_N, value _v_B) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long B; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); B = Long_val(_v_B); mpz_tdiv_r_2exp(R, N, B); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_gmod( value _v_R, value _v_N, value _v_D) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); /* begin user-supplied calling sequence */ mpz_mod(R,N,D); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_gmod_ui( value _v_R, value _v_N, value _v_D) { mpz_ptr R; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_R, &R, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); /* begin user-supplied calling sequence */ _res = mpz_mod_ui(R,N,D); /* end user-supplied calling sequence */ _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_divexact( value _v_Q, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); mpz_divexact(Q, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_divexact_ui( value _v_Q, value _v_N, value _v_D) { mpz_ptr Q; /*in*/ mpz_ptr N; /*in*/ unsigned long D; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_Q, &Q, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); mpz_divexact_ui(Q, N, D); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_divisible_p( value _v_N, value _v_D) { mpz_ptr N; /*in*/ mpz_ptr D; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); _res = mpz_divisible_p(N, D); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_divisible_ui_p( value _v_N, value _v_D) { mpz_ptr N; /*in*/ unsigned long D; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); D = Long_val(_v_D); _res = mpz_divisible_ui_p(N, D); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_divisible_2exp_p( value _v_N, value _v_B) { mpz_ptr N; /*in*/ unsigned long B; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); B = Long_val(_v_B); _res = mpz_divisible_2exp_p(N, B); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_congruent_p( value _v_N, value _v_C, value _v_D) { mpz_ptr N; /*in*/ mpz_ptr C; /*in*/ mpz_ptr D; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_C, &C, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_D, &D, _ctx); _res = mpz_congruent_p(N, C, D); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_congruent_ui_p( value _v_N, value _v_C, value _v_D) { mpz_ptr N; /*in*/ unsigned long C; /*in*/ unsigned long D; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); C = Long_val(_v_C); D = Long_val(_v_D); _res = mpz_congruent_ui_p(N, C, D); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_congruent_2exp_p( value _v_N, value _v_C, value _v_B) { mpz_ptr N; /*in*/ mpz_ptr C; /*in*/ unsigned long B; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_C, &C, _ctx); B = Long_val(_v_B); _res = mpz_congruent_2exp_p(N, C, B); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz__powm( value _v_ROP, value _v_BASE, value _v_EXP, value _v_MOD) { mpz_ptr ROP; /*in*/ mpz_ptr BASE; /*in*/ mpz_ptr EXP; /*in*/ mpz_ptr MOD; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_BASE, &BASE, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_EXP, &EXP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_MOD, &MOD, _ctx); /* begin user-supplied calling sequence */ mpz_powm(ROP,BASE,EXP,MOD); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz__powm_ui( value _v_ROP, value _v_BASE, value _v_EXP, value _v_MOD) { mpz_ptr ROP; /*in*/ mpz_ptr BASE; /*in*/ unsigned long EXP; /*in*/ mpz_ptr MOD; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_BASE, &BASE, _ctx); EXP = Long_val(_v_EXP); camlidl_ml2c_mpz_mpz_ptr(_v_MOD, &MOD, _ctx); /* begin user-supplied calling sequence */ mpz_powm_ui(ROP,BASE,EXP,MOD); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_pow_ui( value _v_ROP, value _v_BASE, value _v_EXP) { mpz_ptr ROP; /*in*/ mpz_ptr BASE; /*in*/ unsigned long EXP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_BASE, &BASE, _ctx); EXP = Long_val(_v_EXP); mpz_pow_ui(ROP, BASE, EXP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_ui_pow_ui( value _v_ROP, value _v_BASE, value _v_EXP) { mpz_ptr ROP; /*in*/ unsigned long BASE; /*in*/ unsigned long EXP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); BASE = Long_val(_v_BASE); EXP = Long_val(_v_EXP); mpz_ui_pow_ui(ROP, BASE, EXP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_root( value _v_ROP, value _v_OP, value _v_N) { mpz_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ unsigned long N; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); N = Long_val(_v_N); _res = mpz_root(ROP, OP, N); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_sqrt( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); mpz_sqrt(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz__sqrtrem( value _v_ROP1, value _v_ROP2, value _v_OP) { mpz_ptr ROP1; /*in*/ mpz_ptr ROP2; /*in*/ mpz_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP1, &ROP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_ROP2, &ROP2, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); /* begin user-supplied calling sequence */ mpz_sqrtrem(ROP1,ROP2,OP); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_perfect_power_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_perfect_power_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_perfect_square_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_perfect_square_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_probab_prime_p( value _v_N, value _v_REPS) { mpz_ptr N; /*in*/ int REPS; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); REPS = Int_val(_v_REPS); _res = mpz_probab_prime_p(N, REPS); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_nextprime( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); mpz_nextprime(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_gcd( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_gcd(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_gcd_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr *ROP; /*in*/ mpz_ptr OP1; /*in*/ unsigned long OP2; /*in*/ unsigned long _res; value _v1; mpz_ptr _c2; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; if (_v_ROP == Val_int(0)) { ROP = NULL; } else { _v1 = Field(_v_ROP, 0); ROP = &_c2; camlidl_ml2c_mpz_mpz_ptr(_v1, &_c2, _ctx); } camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); /* begin user-supplied calling sequence */ _res = mpz_gcd_ui(ROP ? *ROP : NULL,OP1,OP2); /* end user-supplied calling sequence */ _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz__gcdext( value _v_G, value _v_S, value _v_T, value _v_A, value _v_B) { mpz_ptr G; /*in*/ mpz_ptr S; /*in*/ mpz_ptr T; /*in*/ mpz_ptr A; /*in*/ mpz_ptr B; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_G, &G, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_S, &S, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_T, &T, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_A, &A, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_B, &B, _ctx); /* begin user-supplied calling sequence */ mpz_gcdext(G,S,T,A,B); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_lcm( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_lcm(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_lcm_ui( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpz_lcm_ui(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_invert( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); _res = mpz_invert(ROP, OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_jacobi( value _v_A, value _v_B) { mpz_ptr A; /*in*/ mpz_ptr B; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_A, &A, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_B, &B, _ctx); _res = mpz_jacobi(A, B); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_legendre( value _v_A, value _v_P) { mpz_ptr A; /*in*/ mpz_ptr P; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_A, &A, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_P, &P, _ctx); _res = mpz_legendre(A, P); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_kronecker( value _v_A, value _v_B) { mpz_ptr A; /*in*/ mpz_ptr B; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_A, &A, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_B, &B, _ctx); _res = mpz_kronecker(A, B); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_kronecker_si( value _v_A, value _v_B) { mpz_ptr A; /*in*/ long B; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_A, &A, _ctx); B = Long_val(_v_B); _res = mpz_kronecker_si(A, B); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_si_kronecker( value _v_A, value _v_B) { long A; /*in*/ mpz_ptr B; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; A = Long_val(_v_A); camlidl_ml2c_mpz_mpz_ptr(_v_B, &B, _ctx); _res = mpz_si_kronecker(A, B); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_remove( value _v_ROP, value _v_OP, value _v_F) { mpz_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ mpz_ptr F; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_F, &F, _ctx); _res = mpz_remove(ROP, OP, F); _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fac_ui( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ unsigned long OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); OP = Long_val(_v_OP); mpz_fac_ui(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_bin_ui( value _v_ROP, value _v_N, value _v_K) { mpz_ptr ROP; /*in*/ mpz_ptr N; /*in*/ unsigned long K; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_N, &N, _ctx); K = Long_val(_v_K); mpz_bin_ui(ROP, N, K); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_bin_uiui( value _v_ROP, value _v_N, value _v_K) { mpz_ptr ROP; /*in*/ unsigned long N; /*in*/ unsigned long K; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); N = Long_val(_v_N); K = Long_val(_v_K); mpz_bin_uiui(ROP, N, K); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_fib_ui( value _v_FN, value _v_N) { mpz_ptr FN; /*in*/ unsigned long N; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_FN, &FN, _ctx); N = Long_val(_v_N); mpz_fib_ui(FN, N); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_fib2_ui( value _v_FN, value _v_FNSUB1, value _v_N) { mpz_ptr FN; /*in*/ mpz_ptr FNSUB1; /*in*/ unsigned long N; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_FN, &FN, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_FNSUB1, &FNSUB1, _ctx); N = Long_val(_v_N); mpz_fib2_ui(FN, FNSUB1, N); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_lucnum_ui( value _v_LN, value _v_N) { mpz_ptr LN; /*in*/ unsigned long N; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_LN, &LN, _ctx); N = Long_val(_v_N); mpz_lucnum_ui(LN, N); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_lucnum2_ui( value _v_LN, value _v_LNSUB1, value _v_N) { mpz_ptr LN; /*in*/ mpz_ptr LNSUB1; /*in*/ unsigned long N; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_LN, &LN, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_LNSUB1, &LNSUB1, _ctx); N = Long_val(_v_N); mpz_lucnum2_ui(LN, LNSUB1, N); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_cmp( value _v_OP1, value _v_OP2) { mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); _res = mpz_cmp(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_cmp_d( value _v_OP1, value _v_OP2) { mpz_ptr OP1; /*in*/ double OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Double_val(_v_OP2); _res = mpz_cmp_d(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_cmp_si( value _v_OP1, value _v_OP2) { mpz_ptr OP1; /*in*/ long OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); _res = mpz_cmp_si(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_cmpabs( value _v_OP1, value _v_OP2) { mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); _res = mpz_cmpabs(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_cmpabs_d( value _v_OP1, value _v_OP2) { mpz_ptr OP1; /*in*/ double OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Double_val(_v_OP2); _res = mpz_cmpabs_d(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_cmpabs_ui( value _v_OP1, value _v_OP2) { mpz_ptr OP1; /*in*/ unsigned long OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); _res = mpz_cmpabs_ui(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_sgn( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_sgn(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_gand( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); /* begin user-supplied calling sequence */ mpz_and(ROP,OP1,OP2); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_ior( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_ior(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_xor( value _v_ROP, value _v_OP1, value _v_OP2) { mpz_ptr ROP; /*in*/ mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); mpz_xor(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_com( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); mpz_com(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_popcount( value _v_OP) { mpz_ptr OP; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); /* begin user-supplied calling sequence */ _res = mpz_popcount(OP); if (_res==ULONG_MAX) _res = Max_long; /* end user-supplied calling sequence */ _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_hamdist( value _v_OP1, value _v_OP2) { mpz_ptr OP1; /*in*/ mpz_ptr OP2; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP2, &OP2, _ctx); /* begin user-supplied calling sequence */ _res = mpz_hamdist(OP1,OP2); if (_res==ULONG_MAX) _res = Max_long; /* end user-supplied calling sequence */ _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_scan0( value _v_OP, value _v_STARTING_BIT) { mpz_ptr OP; /*in*/ unsigned long STARTING_BIT; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); STARTING_BIT = Long_val(_v_STARTING_BIT); /* begin user-supplied calling sequence */ _res = mpz_scan0(OP,STARTING_BIT); if (_res==ULONG_MAX) _res = Max_long; /* end user-supplied calling sequence */ _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_scan1( value _v_OP, value _v_STARTING_BIT) { mpz_ptr OP; /*in*/ unsigned long STARTING_BIT; /*in*/ unsigned long _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); STARTING_BIT = Long_val(_v_STARTING_BIT); /* begin user-supplied calling sequence */ _res = mpz_scan1(OP,STARTING_BIT); if (_res==ULONG_MAX) _res = Max_long; /* end user-supplied calling sequence */ _vres = Val_long(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_setbit( value _v_ROP, value _v_BIT_INDEX) { mpz_ptr ROP; /*in*/ unsigned long BIT_INDEX; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); BIT_INDEX = Long_val(_v_BIT_INDEX); mpz_setbit(ROP, BIT_INDEX); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_clrbit( value _v_ROP, value _v_BIT_INDEX) { mpz_ptr ROP; /*in*/ unsigned long BIT_INDEX; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); BIT_INDEX = Long_val(_v_BIT_INDEX); mpz_clrbit(ROP, BIT_INDEX); camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz_tstbit( value _v_OP, value _v_BIT_INDEX) { mpz_ptr OP; /*in*/ unsigned long BIT_INDEX; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); BIT_INDEX = Long_val(_v_BIT_INDEX); _res = mpz_tstbit(OP, BIT_INDEX); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz__import( value _v_ROP, value _v_OP, value _v_ORDER, value _v_ENDIAN) { mpz_ptr ROP; /*in*/ int COUNT; /*in*/ int *OP; /*in*/ int ORDER; /*in*/ int ENDIAN; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); OP = Bigarray_val(_v_OP)->data; COUNT = Bigarray_val(_v_OP)->dim[0]; ORDER = Int_val(_v_ORDER); ENDIAN = Int_val(_v_ENDIAN); /* begin user-supplied calling sequence */ mpz_import (ROP, COUNT, ORDER, sizeof(intnat), ENDIAN, 0, OP); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpz_mpz__export( value _v_OP, value _v_ORDER, value _v_ENDIAN) { mpz_ptr OP; /*in*/ int ORDER; /*in*/ int ENDIAN; /*in*/ unsigned int *COUNT; /*out*/ int *_res; unsigned int _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); ORDER = Int_val(_v_ORDER); ENDIAN = Int_val(_v_ENDIAN); COUNT = &_c1; /* begin user-supplied calling sequence */ _res = mpz_export (NULL, COUNT, ORDER, sizeof(intnat), ENDIAN, 0, OP); /* end user-supplied calling sequence */ _vres = alloc_bigarray_dims( BIGARRAY_INT32 | BIGARRAY_C_LAYOUT | BIGARRAY_MANAGED, 1, _res, COUNT); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fits_int_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_fits_int_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_odd_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_odd_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_even_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_even_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_size( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_size(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_sizeinbase( value _v_OP, value _v_BASE) { mpz_ptr OP; /*in*/ int BASE; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); BASE = Int_val(_v_BASE); /* begin user-supplied calling sequence */ if (BASE<2 || BASE>36) caml_invalid_argument("Argument not supported"); _res = mpz_sizeinbase (OP,BASE); /* end user-supplied calling sequence */ _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fits_ulong_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_fits_ulong_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fits_slong_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_fits_slong_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fits_uint_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_fits_uint_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fits_sint_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_fits_sint_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fits_ushort_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_fits_ushort_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpz_mpz_fits_sshort_p( value _v_OP) { mpz_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); _res = mpz_fits_sshort_p(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } apron-dist-0.9.10/mlgmpidl/tmp/mpq.mli0000640014525101416610000001054611252216513017456 0ustar bjeannetpopart(* File generated from mpq.idl *) type mpq_ptr (** GMP multiprecision rationals *) (** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x]. These functions are as efficient as their C counterpart: they do not imply additional memory allocation, unlike the corresponding functions in the module {!Mpqf}. *) external mpq_canonicalize : mpq_ptr -> unit = "camlidl_mpq_mpq_canonicalize" (** {2 Pretty printing} *) val print : Format.formatter -> t -> unit (** {2 Initialization and Assignment Functions} *) (** {{:http://gmplib.org/manual/Initializing-Rationals.html#Initializing-Rationals}C documentation} *) external mpq_init : unit -> mpq_ptr = "camlidl_mpq_mpq_init" external mpq_set : mpq_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_set" external mpq_set_z : mpq_ptr -> Mpz.mpz_ptr -> unit = "camlidl_mpq_mpq_set_z" external mpq_set_si : mpq_ptr -> int -> int -> unit = "camlidl_mpq_mpq_set_si" external mpq__set_str : mpq_ptr -> string -> int -> unit = "camlidl_mpq_mpq__set_str" val set_str : t -> string -> base:int -> unit external mpq_swap : mpq_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_swap" (** {2 Additional Initialization and Assignements functions} *) (** These functions are additions to or renaming of functions offered by the C library. *) val init_set : t -> t val init_set_z : Mpz.t -> t val init_set_si : int -> int -> t val init_set_str : string -> base:int -> t val init_set_d : float -> t (** {2 Conversion Functions} *) (** {{:http://gmplib.org/manual/Rational-Conversions.html#Rational-Conversions}C documentation} *) external mpq_get_d : mpq_ptr -> float = "camlidl_mpq_mpq_get_d" external mpq_set_d : mpq_ptr -> float -> unit = "camlidl_mpq_mpq_set_d" (* Replace Mpz.set_q: Mpz.t -> Mpq.t -> unit *) external mpq_get_z : Mpz.mpz_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_get_z" (* For set_f: t -> Mpf.t -> unit, see Mpf.get_q *) external mpq__get_str : int -> mpq_ptr -> string = "camlidl_mpq_mpq__get_str" val get_str : base:int -> t -> string (** {2 User Conversions} *) (** These functionss are additions to or renaming of functions offeered by the C library. *) val to_string : t -> string val to_float : t -> float val of_string : string -> t val of_float : float -> t val of_int : int -> t val of_frac : int -> int -> t val of_mpz : Mpz.t -> t val of_mpz2 : Mpz.t -> Mpz.t -> t (** {2 Arithmetic Functions} *) (** {{:http://gmplib.org/manual/Rational-Arithmetic.html#Rational-Arithmetic}C documentation} *) external mpq_add : mpq_ptr -> mpq_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_add" external mpq_sub : mpq_ptr -> mpq_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_sub" external mpq_mul : mpq_ptr -> mpq_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_mul" external mpq_mul_2exp : mpq_ptr -> mpq_ptr -> int -> unit = "camlidl_mpq_mpq_mul_2exp" external mpq_div : mpq_ptr -> mpq_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_div" external mpq_div_2exp : mpq_ptr -> mpq_ptr -> int -> unit = "camlidl_mpq_mpq_div_2exp" external mpq_neg : mpq_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_neg" external mpq_abs : mpq_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_abs" external mpq_inv : mpq_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_inv" (** {2 Comparison Functions} *) (** {{:http://gmplib.org/manual/Comparing-Rationals.html#Comparing-Rationals}C documentation} *) external mpq_cmp : mpq_ptr -> mpq_ptr -> int = "camlidl_mpq_mpq_cmp" external mpq_cmp_si : mpq_ptr -> int -> int -> int = "camlidl_mpq_mpq_cmp_si" external mpq_sgn : mpq_ptr -> int = "camlidl_mpq_mpq_sgn" external mpq_equal : mpq_ptr -> mpq_ptr -> bool = "camlidl_mpq_mpq_equal" (** {2 Applying Integer Functions to Rationals} *) (** {{:http://gmplib.org/manual/Applying-Integer-Functions.html#Applying-Integer-Functions}C documentation} *) external mpq_get_num : Mpz.mpz_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_get_num" external mpq_get_den : Mpz.mpz_ptr -> mpq_ptr -> unit = "camlidl_mpq_mpq_get_den" external mpq_set_num : mpq_ptr -> Mpz.mpz_ptr -> unit = "camlidl_mpq_mpq_set_num" external mpq_set_den : mpq_ptr -> Mpz.mpz_ptr -> unit = "camlidl_mpq_mpq_set_den" (** {2 Input and Output Functions: not interfaced} *) apron-dist-0.9.10/mlgmpidl/tmp/gmp_random.idl0000640014525101416610000000524111252216514020770 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \"caml/custom.h\"\n\ #include \"gmp_caml.h\"\n\ ") import "mpz.idl"; import "mpf.idl"; #if HAS_MPFR!=0 import "mpfr.idl"; #endif /* OUTOUTOUT is a reserved variable name ! (see Makefile) */ typedef [abstract,c2ml(camlidl_gmp_randstate_ptr_c2ml),ml2c(camlidl_gmp_randstate_ptr_ml2c)] struct __gmp_randstate_struct* gmp_randstate_ptr; quote(MLMLI,"(** GMP random generation functions *)\n\n") quote(MLMLI,"(** {2 Random State Initialization} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Random-State-Initialization.html#Random-State-Initialization}C documentation} *)\n") void gmp_randinit_default([out]gmp_randstate_ptr OUTOUTOUT); void gmp_randinit_lc_2exp ([out]gmp_randstate_ptr OUTOUTOUT, mpz_ptr A, unsigned long C, unsigned long M2EXP); void gmp_randinit_lc_2exp_size ([out]gmp_randstate_ptr OUTOUTOUT, unsigned long SIZE) quote(call,"\ {\n\ int n = gmp_randinit_lc_2exp_size(OUTOUTOUT,SIZE);\n\ if (n==0) caml_invalid_argument(\"Argument not supported\");\n\ }"); quote(MLMLI,"(** {2 Random State Seeding} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Random-State-Seeding.html#Random-State-Seeding}C documentation} *)\n") void gmp_randseed (gmp_randstate_ptr STATE, mpz_ptr SEED); void gmp_randseed_ui (gmp_randstate_ptr STATE, unsigned long int SEED); quote(MLMLI,"(** {2 Random Number Functions} *)\n") quote(MLMLI,"(** {3 Integers ({!Mpz})} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Random-Numbers.html#Integer-Random-Numbers}C documentation} *)\n") quote(MLI,"module Mpz : sig") quote(ML,"module Mpz = struct") void mpz_urandomb (mpz_ptr ROP, gmp_randstate_ptr STATE, unsigned long int N); void mpz_urandomm (mpz_ptr ROP, gmp_randstate_ptr STATE, mpz_ptr N); void mpz_rrandomb (mpz_ptr ROP, gmp_randstate_ptr STATE, unsigned long int N); quote(MLMLI,"end\n") quote(MLMLI,"(** {3 Floating-point ({!Mpf})} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Miscellaneous-Float-Functions.html#Miscellaneous-Float-Functions}C documentation} *)\n") quote(MLI,"module Mpf : sig") quote(ML,"module Mpf = struct") void mpf_urandomb (mpf_ptr ROP, gmp_randstate_ptr STATE, unsigned long int N); quote(MLMLI,"end\n") #if HAS_MPFR!=0 quote(MLMLI,"(** {3 Floating-point ({!Mpfr})} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Miscellaneous-Functions}C documentation} *)\n") quote(MLI,"module Mpfr : sig") quote(ML,"module Mpfr = struct") void mpfr_urandomb (mpfr_ptr ROP, gmp_randstate_ptr STATE); void mpfr_random (mpfr_ptr ROP); quote(MLMLI,"end\n") #endif apron-dist-0.9.10/mlgmpidl/tmp/mpfr.idl0000640014525101416610000003527111252216513017616 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \"caml/custom.h\"\n\ #include \"gmp_caml.h\"\n\ ") import "mpz.idl"; import "mpq.idl"; import "mpf.idl"; typedef [abstract,c2ml(camlidl_mpfr_ptr_c2ml),ml2c(camlidl_mpfr_ptr_ml2c)] struct __mpfr_struct* mpfr_ptr; quote(MLMLI,"(** MPFR multiprecision floating-point numbers *)\n\n") typedef [mltype("\n | Near\n | Zero\n | Up\n | Down"), c2ml(camlidl_mpfr_rnd_t_c2ml),ml2c(camlidl_mpfr_rnd_t_ml2c)] struct mpfr_rnd_t mpfr_rnd_t; quote(MLMLI,"(** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x].\n\n These functions are as efficient as their C counterpart: they do not imply additional memory allocation. *)\n\n") /* OUTOUTOUT is a reserved variable name ! (see Makefile and sedscript_c) */ quote(MLI,"\n(** {2 Pretty printing} *)\n") quote(MLI,"val print : Format.formatter -> t -> unit") quote(MLI,"val print_round : Format.formatter -> round -> unit") quote(MLI,"val string_of_round : round -> string") quote(MLMLI,"\n(** {2 Rounding Modes} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Rounding-Related-Functions}C documentation} *)\n") void mpfr_set_default_rounding_mode (mpfr_rnd_t RND); mpfr_rnd_t mpfr_get_default_rounding_mode (void); int mpfr_round_prec (mpfr_ptr X, mpfr_rnd_t RND, unsigned long int PREC); quote(MLMLI,"\n(** {2 Exceptions} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Exception-Related-Functions}C documentation} *)\n") long int mpfr_get_emin (void); long int mpfr_get_emax (void); void mpfr_set_emin (long int EXP) quote(call,"{\n\ int n = mpfr_set_emin(EXP);\n\ if (n){ caml_invalid_argument(\"\"); }\n\ }"); void mpfr_set_emax (long int EXP) quote(call,"{\n\ int n = mpfr_set_emax(EXP);\n\ if (n){ caml_invalid_argument(\"\"); }\n\ }"); int mpfr_check_range (mpfr_ptr X, int T, mpfr_rnd_t RND); void mpfr_clear_underflow (void); void mpfr_clear_overflow (void); void mpfr_clear_nanflag (void); void mpfr_clear_inexflag (void); void mpfr_clear_flags (void); boolean mpfr_underflow_p (void); boolean mpfr_overflow_p (void); boolean mpfr_nanflag_p (void); boolean mpfr_inexflag_p (void); quote(MLMLI,"\n(** {2 Initialization Functions} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Initialization-Functions}C documentation} *)\n") void mpfr_set_default_prec (unsigned long int PREC); unsigned long int mpfr_get_default_prec (void); void mpfr_init ([out] mpfr_ptr OUTOUTOUT); void mpfr_init2 ([out] mpfr_ptr OUTOUTOUT, unsigned long int PREC); unsigned long int mpfr_get_prec (mpfr_ptr OP); void mpfr_set_prec (mpfr_ptr ROP, unsigned long int PREC); void mpfr_set_prec_raw (mpfr_ptr ROP, unsigned long int PREC); quote(MLMLI,"\n(** {2 Assignment Functions} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Assignment-Functions}C documentation} *)\n") int mpfr_set (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_set_si (mpfr_ptr ROP, signed long int OP, mpfr_rnd_t RND); int mpfr_set_d (mpfr_ptr ROP, double OP, mpfr_rnd_t RND); int mpfr_set_z (mpfr_ptr ROP, mpz_ptr OP, mpfr_rnd_t RND); int mpfr_set_q (mpfr_ptr ROP, mpq_ptr OP, mpfr_rnd_t RND); void mpfr__set_str (mpfr_ptr ROP, [string]char *STR, int BASE, mpfr_rnd_t RND) quote(call,"{\n\ int n = mpfr_set_str(ROP,STR,BASE,RND);\n\ if (n){ mpfr_clear(ROP); caml_invalid_argument(\"\"); }\n\ }"); quote(MLI,"val set_str : t -> string -> base:int -> mpfr_rnd_t -> unit") quote(ML,"let set_str a b ~base round = _set_str a b base round") int mpfr_set_f (mpfr_ptr X, mpf_ptr Y, mpfr_rnd_t RND); int mpfr_set_si_2exp (mpfr_ptr ROP, signed long int OP, signed long int EXPNT, mpfr_rnd_t RND); void mpfr_set_inf (mpfr_ptr X, int SIGN); void mpfr_set_nan (mpfr_ptr X); void mpfr_swap (mpfr_ptr ROP1, mpfr_ptr ROP2); quote(MLMLI,"\n(** {2 Combined Initialization and Assignment Functions} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Combined-Initialization-and-Assignment-Functions}C documentation} *)\n") int mpfr_init_set ([out] mpfr_ptr OUTOUTOUT, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_init_set_si ([out] mpfr_ptr OUTOUTOUT, signed long int OP, mpfr_rnd_t RND); int mpfr_init_set_d ([out] mpfr_ptr OUTOUTOUT, double OP, mpfr_rnd_t RND); int mpfr_init_set_f ([out] mpfr_ptr OUTOUTOUT, mpf_ptr OP, mpfr_rnd_t RND); int mpfr_init_set_z ([out] mpfr_ptr OUTOUTOUT, mpz_ptr OP, mpfr_rnd_t RND); int mpfr_init_set_q ([out] mpfr_ptr OUTOUTOUT, mpq_ptr OP, mpfr_rnd_t RND); void mpfr__init_set_str ([out] mpfr_ptr OUTOUTOUT, [string]char *STR, int BASE, mpfr_rnd_t RND) quote(call,"\ {\n\ int n = mpfr_init_set_str(OUTOUTOUT,STR,BASE,RND);\n\ if (n){ mpfr_clear(OUTOUTOUT); caml_invalid_argument(\"\"); }\n\ }"); quote(MLI,"val init_set_str : string -> base:int -> mpfr_rnd_t -> t") quote(ML,"let init_set_str a ~base round = _init_set_str a base round") quote(MLMLI,"\n(** {2 Conversion Functions} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Conversion-Functions}C documentation} *)\n") double mpfr_get_d (mpfr_ptr OP, mpfr_rnd_t RND); double mpfr_get_d1 (mpfr_ptr OP); int mpfr_get_z_exp (mpz_ptr Z, mpfr_ptr OP); void mpfr_get_z (mpz_ptr Z, mpfr_ptr OP, mpfr_rnd_t RND); [string]char* mpfr__get_str ([out]long int *EXPPTR, int BASE, int N_DIGITS, mpfr_ptr OP, mpfr_rnd_t RND) quote(call,"_res = mpfr_get_str(NULL,EXPPTR,BASE,N_DIGITS,OP,RND);") quote(dealloc,"free(_res);"); quote(MLI,"val get_str : base:int -> digits:int -> t -> mpfr_rnd_t -> string * int") quote(ML,"let get_str ~base ~digits a round = _get_str base digits a round") quote(MLI,"\n(** {2 User Conversions} *)\n") quote(MLI,"(** These functionss are additions to or renaming of functions offered by the C library. *)\n") quote(MLI,"val to_string : t -> string") quote(MLI,"val to_float : ?round:round -> t -> float") quote(MLI,"val to_mpq : t -> Mpq.t") quote(MLI,"val of_string : string -> round -> t") quote(MLI,"val of_float : float -> round -> t") quote(MLI,"val of_int : int -> round -> t") quote(MLI,"val of_frac : int -> int -> round -> t") quote(MLI,"val of_mpz : Mpz.t -> round -> t") quote(MLI,"val of_mpz2 : Mpz.t -> Mpz.t -> round -> t") quote(MLI,"val of_mpq : Mpq.t -> round -> t") quote(MLMLI,"\n(** {2 Basic Arithmetic Functions} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Basic-Arithmetic-Functions}C documentation} *)\n") int mpfr_add (mpfr_ptr ROP, mpfr_ptr OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_add_ui (mpfr_ptr ROP, mpfr_ptr OP1, unsigned long int OP2, mpfr_rnd_t RND); int mpfr_add_z (mpfr_ptr ROP, mpfr_ptr OP1, mpz_ptr OP2, mpfr_rnd_t RND); int mpfr_add_q (mpfr_ptr ROP, mpfr_ptr OP1, mpq_ptr OP2, mpfr_rnd_t RND); int mpfr_sub (mpfr_ptr ROP, mpfr_ptr OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_ui_sub (mpfr_ptr ROP, unsigned long int OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_sub_ui (mpfr_ptr ROP, mpfr_ptr OP1, unsigned long int OP2, mpfr_rnd_t RND); int mpfr_sub_z (mpfr_ptr ROP, mpfr_ptr OP1, mpz_ptr OP2, mpfr_rnd_t RND); int mpfr_sub_q (mpfr_ptr ROP, mpfr_ptr OP1, mpq_ptr OP2, mpfr_rnd_t RND); int mpfr_mul (mpfr_ptr ROP, mpfr_ptr OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_mul_ui (mpfr_ptr ROP, mpfr_ptr OP1, unsigned long int OP2, mpfr_rnd_t RND); int mpfr_mul_z (mpfr_ptr ROP, mpfr_ptr OP1, mpz_ptr OP2, mpfr_rnd_t RND); int mpfr_mul_q (mpfr_ptr ROP, mpfr_ptr OP1, mpq_ptr OP2, mpfr_rnd_t RND); int mpfr_mul_2ui (mpfr_ptr ROP, mpfr_ptr OP1, unsigned long int OP2, mpfr_rnd_t RND); int mpfr_mul_2si (mpfr_ptr ROP, mpfr_ptr OP1, long int OP2, mpfr_rnd_t RND); int mpfr_mul_2exp (mpfr_ptr ROP, mpfr_ptr OP1, unsigned long int OP2, mpfr_rnd_t RND); int mpfr_div (mpfr_ptr ROP, mpfr_ptr OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_ui_div (mpfr_ptr ROP, unsigned long int OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_div_ui (mpfr_ptr ROP, mpfr_ptr OP1, unsigned long int OP2, mpfr_rnd_t RND); int mpfr_div_z (mpfr_ptr ROP, mpfr_ptr OP1, mpz_ptr OP2, mpfr_rnd_t RND); int mpfr_div_q (mpfr_ptr ROP, mpfr_ptr OP1, mpq_ptr OP2, mpfr_rnd_t RND); int mpfr_div_2ui (mpfr_ptr ROP, mpfr_ptr OP1, unsigned long int OP2, mpfr_rnd_t RND); int mpfr_div_2si (mpfr_ptr ROP, mpfr_ptr OP1, long int OP2, mpfr_rnd_t RND); quote(MLI,"val div_2exp : t -> t -> int -> mpfr_rnd_t -> int") quote(ML,"let div_2exp = div_2ui") boolean mpfr_sqrt (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); boolean mpfr_sqrt_ui (mpfr_ptr ROP, unsigned long int OP, mpfr_rnd_t RND); boolean mpfr_pow_ui (mpfr_ptr ROP, mpfr_ptr OP1, unsigned long int OP2, mpfr_rnd_t RND); boolean mpfr_pow_si (mpfr_ptr ROP, mpfr_ptr OP1, signed long int OP2, mpfr_rnd_t RND); boolean mpfr_ui_pow_ui (mpfr_ptr ROP, unsigned long int OP1, unsigned long int OP2, mpfr_rnd_t RND); boolean mpfr_ui_pow (mpfr_ptr ROP, unsigned long int OP1, mpfr_ptr OP2, mpfr_rnd_t RND); boolean mpfr_pow (mpfr_ptr ROP, mpfr_ptr OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_neg (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_abs (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); quote(MLMLI,"\n(** {2 Comparison Functions} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Comparison-Functions}C documentation} *)\n") int mpfr_cmp (mpfr_ptr OP1, mpfr_ptr OP2); int mpfr_cmp_si (mpfr_ptr OP1, signed long int OP2); int mpfr_cmp_si_2exp (mpfr_ptr OP1, long int OP2, int E); int mpfr_sgn (mpfr_ptr OP); boolean mpfr__equal (mpfr_ptr OP1, mpfr_ptr OP2, unsigned long int OP3) quote(call,"_res=mpfr_eq(OP1,OP2,OP3);"); quote(MLI,"val equal : t -> t -> bits:int -> bool") quote(ML,"let equal a b ~bits = _equal a b bits") boolean mpfr_nan_p (mpfr_ptr OP); boolean mpfr_inf_p (mpfr_ptr OP); boolean mpfr_number_p (mpfr_ptr OP); void mpfr_reldiff (mpfr_ptr ROP, mpfr_ptr OP1, mpfr_ptr OP2, mpfr_rnd_t RND); quote(MLMLI,"\n(** {2 Special Functions} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Special-Functions}C documentation} *)\n") int mpfr_log (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_log2 (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_log10 (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_exp (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_exp2 (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_exp10 (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_cos (mpfr_ptr COP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_sin (mpfr_ptr SOP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_tan (mpfr_ptr TOP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_sec (mpfr_ptr COP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_csc (mpfr_ptr SOP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_cot (mpfr_ptr TOP, mpfr_ptr OP, mpfr_rnd_t RND); boolean mpfr_sin_cos (mpfr_ptr SOP, mpfr_ptr COP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_acos (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_asin (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_atan (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_atan2 (mpfr_ptr ROP, mpfr_ptr Y, mpfr_ptr X, mpfr_rnd_t RND); int mpfr_cosh (mpfr_ptr COP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_sinh (mpfr_ptr SOP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_tanh (mpfr_ptr TOP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_sech (mpfr_ptr COP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_csch (mpfr_ptr SOP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_coth (mpfr_ptr TOP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_acosh (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_asinh (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_atanh (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_fac_ui (mpfr_ptr ROP, unsigned long int OP, mpfr_rnd_t RND); int mpfr_log1p (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_expm1 (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_eint (mpfr_ptr Y, mpfr_ptr X, mpfr_rnd_t RND); int mpfr_gamma (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_lngamma (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_zeta (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_erf (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_erfc (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_fma (mpfr_ptr ROP, mpfr_ptr OPX,mpfr_ptr OPY, mpfr_ptr OPZ, mpfr_rnd_t RND); int mpfr_agm (mpfr_ptr ROP, mpfr_ptr OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_hypot (mpfr_ptr ROP, mpfr_ptr X, mpfr_ptr Y, mpfr_rnd_t RND); int mpfr_const_log2 (mpfr_ptr ROP, mpfr_rnd_t RND); int mpfr_const_pi (mpfr_ptr ROP, mpfr_rnd_t RND); int mpfr_const_euler (mpfr_ptr ROP, mpfr_rnd_t RND); int mpfr_const_catalan (mpfr_ptr ROP, mpfr_rnd_t RND); quote(MLMLI,"\n(** {2 Input and Output Functions: not interfaced} *)\n") quote(MLMLI,"\n(** {2 Miscellaneous Float Functions} *)") quote(MLMLI,"(** {{:http://www.mpfr.org/mpfr-current/mpfr.html#Rounding-Related-Functions}C documentation} *)\n") int mpfr_rint (mpfr_ptr ROP, mpfr_ptr OP, mpfr_rnd_t RND); int mpfr_ceil (mpfr_ptr ROP, mpfr_ptr OP); int mpfr_floor (mpfr_ptr ROP, mpfr_ptr OP); int mpfr_round (mpfr_ptr ROP, mpfr_ptr OP); int mpfr_trunc (mpfr_ptr ROP, mpfr_ptr OP); boolean mpfr_integer_p (mpfr_ptr OP); void mpfr_nexttoward (mpfr_ptr X, mpfr_ptr Y); void mpfr_nextabove (mpfr_ptr X); void mpfr_nextbelow (mpfr_ptr X); int mpfr_min (mpfr_ptr ROP, mpfr_ptr OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_max (mpfr_ptr ROP, mpfr_ptr OP1, mpfr_ptr OP2, mpfr_rnd_t RND); int mpfr_get_exp (mpfr_ptr X); int mpfr_set_exp (mpfr_ptr X, signed long int E); quote(ML,"\n(** {2 Additional functions} *)\n") quote(ML,"let to_string x = \n\ let (s,e) = get_str ~base:10 ~digits:0 x Near in \n\ if s=\"\" \n\ then \"0.0\" \n\ else Format.sprintf \"0.%sE%i\" s e \n\ ") quote(ML,"\n(** {2 Pretty printing} *)\n") quote(ML,"let print fmt x = \n\ let (s,e) = get_str ~base:10 ~digits:0 x Near in \n\ if s=\"\" \n\ then Format.pp_print_string fmt \"0.0\" \n\ else Format.fprintf fmt \"0.%sE%i\" s e \n\ \n\ let string_of_round = function\n\ | Near -> \"Near\"\n\ | Zero -> \"Zero\"\n\ | Up -> \"Up\"\n\ | Down -> \"Down\"\n\ let print_round fmt x = Format.pp_print_string fmt (string_of_round x)\n\ ") quote(ML,"let to_float ?round x = \n\ match round with\n\ | None -> get_d1 x\n\ | Some r -> get_d x r\n\ ") quote(ML,"let to_mpq x = \n\ let num,den = Mpz.init(), Mpz.init_set_si 1 in\n\ let e = get_z_exp num x in\n\ Mpz.mul_2exp den den e;\n\ Mpq.of_mpz2 num den\n\ ") quote(ML,"let of_int x r = snd (init_set_si x r)") quote(ML,"let of_float x r = snd (init_set_d x r)") quote(ML,"let of_mpz x r = snd (init_set_z x r)") quote(ML,"let of_mpq x r = snd (init_set_q x r)") quote(ML,"let of_string x r = init_set_str x ~base:10 r") quote(ML,"let of_frac n d r = let mpq = Mpq.of_frac n d in of_mpq mpq r") quote(ML,"let of_mpz2 n d r = let mpq = Mpq.of_mpz2 n d in of_mpq mpq r") apron-dist-0.9.10/mlgmpidl/tmp/mpz.ml0000640014525101416610000003533211252216512017315 0ustar bjeannetpopart(* File generated from mpz.idl *) type mpz_ptr (** GMP multi-precision integers *) (** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x]. These functions are as efficient as their C counterpart: they do not imply additional memory allocation, unlike the corresponding functions in the module {!Mpzf}. *) (** {2 Initialization Functions} *) (** {{:http://gmplib.org/manual/Initializing-Integers.html#Initializing-Integers}C documentation} *) external mpz_init : unit -> mpz_ptr = "camlidl_mpz_mpz_init" external mpz_init2 : int -> mpz_ptr = "camlidl_mpz_mpz_init2" external mpz_realloc2 : mpz_ptr -> int -> unit = "camlidl_mpz_mpz_realloc2" (** {2 Assignement Functions} *) (** {{:http://gmplib.org/manual/Assigning-Integers.html#Assigning-Integers}C documentation} *) (** The first parameter holds the result. *) external mpz_set : mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_set" external mpz_set_si : mpz_ptr -> int -> unit = "camlidl_mpz_mpz_set_si" external mpz_set_d : mpz_ptr -> float -> unit = "camlidl_mpz_mpz_set_d" external mpz__set_str : mpz_ptr -> string -> int -> unit = "camlidl_mpz_mpz__set_str" let set_str a b ~base = _set_str a b base external mpz_swap : mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_swap" (** {2 Combined Initialization and Assignment Functions} *) (** {{:http://gmplib.org/manual/Simultaneous-Integer-Init-_0026-Assign.html#Simultaneous-Integer-Init-_0026-Assign}C documentation} *) external mpz_init_set : mpz_ptr -> mpz_ptr = "camlidl_mpz_mpz_init_set" external mpz_init_set_si : int -> mpz_ptr = "camlidl_mpz_mpz_init_set_si" external mpz_init_set_d : float -> mpz_ptr = "camlidl_mpz_mpz_init_set_d" external mpz__init_set_str : string -> int -> mpz_ptr = "camlidl_mpz_mpz__init_set_str" let init_set_str a ~base = _init_set_str a base (** {2 Conversion Functions} *) (** {{:http://gmplib.org/manual/Converting-Integers.html#Converting-Integers}C documentation} *) external mpz_get_si : mpz_ptr -> nativeint = "camlidl_mpz_mpz_get_si" external mpz_get_int : mpz_ptr -> int = "camlidl_mpz_mpz_get_int" external mpz_get_d : mpz_ptr -> float = "camlidl_mpz_mpz_get_d" external mpz_get_d_2exp : mpz_ptr -> float * int = "camlidl_mpz_mpz_get_d_2exp" external mpz__get_str : int -> mpz_ptr -> string = "camlidl_mpz_mpz__get_str" let get_str ~base a = _get_str base a (** {2 User Conversions} *) (** These functions are additions to or renaming of functions offered by the C library. *) let to_string x = get_str 10 x let to_float = get_d let of_string str = init_set_str str 10 let of_float = init_set_d let of_int = init_set_si (** {2 Pretty printing} *) let print fmt x = Format.pp_print_string fmt (get_str 10 x) (** {2 Arithmetic Functions} *) (** {{:http://gmplib.org/manual/Integer-Arithmetic.html#Integer-Arithmetic}C documentation} *) (** The first parameter holds the result. *) external mpz_add : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_add" external mpz_add_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_add_ui" external mpz_sub : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_sub" external mpz_sub_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_sub_ui" external mpz_ui_sub : mpz_ptr -> int -> mpz_ptr -> unit = "camlidl_mpz_mpz_ui_sub" external mpz_mul : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_mul" external mpz_mul_si : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_mul_si" external mpz_addmul : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_addmul" external mpz_addmul_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_addmul_ui" external mpz_submul : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_submul" external mpz_submul_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_submul_ui" external mpz_mul_2exp : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_mul_2exp" external mpz_neg : mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_neg" external mpz_abs : mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_abs" (** {2 Division Functions} *) (** {{:http://gmplib.org/manual/Integer-Division.html#Integer-Division}C documentation} *) (** [c] stands for ceiling, [f] for floor, and [t] for truncate (rounds toward 0).*) (** {3 Ceiling division} *) (** The first parameter holds the quotient. *) external mpz_cdiv_q : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_cdiv_q" (** The first parameter holds the remainder. *) external mpz_cdiv_r : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_cdiv_r" (** The two first parameters hold resp. the quotient and the remainder). *) external mpz_cdiv_qr : mpz_ptr -> mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_cdiv_qr" (** The first parameter holds the quotient. *) external mpz_cdiv_q_ui : mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_cdiv_q_ui" (** The first parameter holds the remainder. *) external mpz_cdiv_r_ui : mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_cdiv_r_ui" (** The two first parameters hold resp. the quotient and the remainder). *) external mpz_cdiv_qr_ui : mpz_ptr -> mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_cdiv_qr_ui" external mpz_cdiv_ui : mpz_ptr -> int -> int = "camlidl_mpz_mpz_cdiv_ui" (** The first parameter holds the quotient. *) external mpz_cdiv_q_2exp : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_cdiv_q_2exp" (** The first parameter holds the remainder. *) external mpz_cdiv_r_2exp : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_cdiv_r_2exp" (** {3 Floor division} *) external mpz_fdiv_q : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_fdiv_q" external mpz_fdiv_r : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_fdiv_r" external mpz_fdiv_qr : mpz_ptr -> mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_fdiv_qr" external mpz_fdiv_q_ui : mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_fdiv_q_ui" external mpz_fdiv_r_ui : mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_fdiv_r_ui" external mpz_fdiv_qr_ui : mpz_ptr -> mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_fdiv_qr_ui" external mpz_fdiv_ui : mpz_ptr -> int -> int = "camlidl_mpz_mpz_fdiv_ui" external mpz_fdiv_q_2exp : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_fdiv_q_2exp" external mpz_fdiv_r_2exp : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_fdiv_r_2exp" (** {3 Truncate division} *) external mpz_tdiv_q : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_tdiv_q" external mpz_tdiv_r : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_tdiv_r" external mpz_tdiv_qr : mpz_ptr -> mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_tdiv_qr" external mpz_tdiv_q_ui : mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_tdiv_q_ui" external mpz_tdiv_r_ui : mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_tdiv_r_ui" external mpz_tdiv_qr_ui : mpz_ptr -> mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_tdiv_qr_ui" external mpz_tdiv_ui : mpz_ptr -> int -> int = "camlidl_mpz_mpz_tdiv_ui" external mpz_tdiv_q_2exp : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_tdiv_q_2exp" external mpz_tdiv_r_2exp : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_tdiv_r_2exp" (** {3 Other division-related functions} *) external mpz_gmod : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_gmod" external mpz_gmod_ui : mpz_ptr -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_gmod_ui" external mpz_divexact : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_divexact" external mpz_divexact_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_divexact_ui" external mpz_divisible_p : mpz_ptr -> mpz_ptr -> bool = "camlidl_mpz_mpz_divisible_p" external mpz_divisible_ui_p : mpz_ptr -> int -> bool = "camlidl_mpz_mpz_divisible_ui_p" external mpz_divisible_2exp_p : mpz_ptr -> int -> bool = "camlidl_mpz_mpz_divisible_2exp_p" external mpz_congruent_p : mpz_ptr -> mpz_ptr -> mpz_ptr -> bool = "camlidl_mpz_mpz_congruent_p" external mpz_congruent_ui_p : mpz_ptr -> int -> int -> bool = "camlidl_mpz_mpz_congruent_ui_p" external mpz_congruent_2exp_p : mpz_ptr -> mpz_ptr -> int -> bool = "camlidl_mpz_mpz_congruent_2exp_p" (** {2 Exponentiation Functions} *) (** {{:http://gmplib.org/manual/Integer-Exponentiation.html#Integer-Exponentiation}C documentation} *) external mpz__powm : mpz_ptr -> mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz__powm" external mpz__powm_ui : mpz_ptr -> mpz_ptr -> int -> mpz_ptr -> unit = "camlidl_mpz_mpz__powm_ui" let powm a b c ~modulo = _powm a b c modulo let powm_ui a b c ~modulo = _powm_ui a b c modulo external mpz_pow_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_pow_ui" external mpz_ui_pow_ui : mpz_ptr -> int -> int -> unit = "camlidl_mpz_mpz_ui_pow_ui" (** {2 Root Extraction Functions} *) (** {{:http://gmplib.org/manual/Integer-Roots.html#Integer-Roots}C documentation} *) external mpz_root : mpz_ptr -> mpz_ptr -> int -> bool = "camlidl_mpz_mpz_root" external mpz_sqrt : mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_sqrt" external mpz__sqrtrem : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz__sqrtrem" let sqrtrem a ~remainder b = _sqrtrem a remainder b external mpz_perfect_power_p : mpz_ptr -> bool = "camlidl_mpz_mpz_perfect_power_p" external mpz_perfect_square_p : mpz_ptr -> bool = "camlidl_mpz_mpz_perfect_square_p" (** {2 Number Theoretic Functions} *) (** {{:http://gmplib.org/manual/Number-Theoretic-Functions.html#Number-Theoretic-Functions}C documentation} *) external mpz_probab_prime_p : mpz_ptr -> int -> int = "camlidl_mpz_mpz_probab_prime_p" external mpz_nextprime : mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_nextprime" external mpz_gcd : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_gcd" external mpz_gcd_ui : mpz_ptr option -> mpz_ptr -> int -> int = "camlidl_mpz_mpz_gcd_ui" external mpz__gcdext : mpz_ptr -> mpz_ptr -> mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz__gcdext" let gcdext ~gcd ~alpha ~beta a b = _gcdext gcd alpha beta a b external mpz_lcm : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_lcm" external mpz_lcm_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_lcm_ui" external mpz_invert : mpz_ptr -> mpz_ptr -> mpz_ptr -> bool = "camlidl_mpz_mpz_invert" external mpz_jacobi : mpz_ptr -> mpz_ptr -> int = "camlidl_mpz_mpz_jacobi" external mpz_legendre : mpz_ptr -> mpz_ptr -> int = "camlidl_mpz_mpz_legendre" external mpz_kronecker : mpz_ptr -> mpz_ptr -> int = "camlidl_mpz_mpz_kronecker" external mpz_kronecker_si : mpz_ptr -> int -> int = "camlidl_mpz_mpz_kronecker_si" external mpz_si_kronecker : int -> mpz_ptr -> int = "camlidl_mpz_mpz_si_kronecker" external mpz_remove : mpz_ptr -> mpz_ptr -> mpz_ptr -> int = "camlidl_mpz_mpz_remove" external mpz_fac_ui : mpz_ptr -> int -> unit = "camlidl_mpz_mpz_fac_ui" external mpz_bin_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_bin_ui" external mpz_bin_uiui : mpz_ptr -> int -> int -> unit = "camlidl_mpz_mpz_bin_uiui" external mpz_fib_ui : mpz_ptr -> int -> unit = "camlidl_mpz_mpz_fib_ui" external mpz_fib2_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_fib2_ui" external mpz_lucnum_ui : mpz_ptr -> int -> unit = "camlidl_mpz_mpz_lucnum_ui" external mpz_lucnum2_ui : mpz_ptr -> mpz_ptr -> int -> unit = "camlidl_mpz_mpz_lucnum2_ui" (** {2 Comparison Functions} *) (** {{:http://gmplib.org/manual/Integer-Comparisons.html#Integer-Comparisons}C documentation} *) external mpz_cmp : mpz_ptr -> mpz_ptr -> int = "camlidl_mpz_mpz_cmp" external mpz_cmp_d : mpz_ptr -> float -> int = "camlidl_mpz_mpz_cmp_d" external mpz_cmp_si : mpz_ptr -> int -> int = "camlidl_mpz_mpz_cmp_si" external mpz_cmpabs : mpz_ptr -> mpz_ptr -> int = "camlidl_mpz_mpz_cmpabs" external mpz_cmpabs_d : mpz_ptr -> float -> int = "camlidl_mpz_mpz_cmpabs_d" external mpz_cmpabs_ui : mpz_ptr -> int -> int = "camlidl_mpz_mpz_cmpabs_ui" external mpz_sgn : mpz_ptr -> int = "camlidl_mpz_mpz_sgn" (** {2 Logical and Bit Manipulation Functions} *) (** {{:http://gmplib.org/manual/Integer-Logic-and-Bit-Fiddling.html#Integer-Logic-and-Bit-Fiddling}C documentation} *) external mpz_gand : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_gand" external mpz_ior : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_ior" external mpz_xor : mpz_ptr -> mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_xor" external mpz_com : mpz_ptr -> mpz_ptr -> unit = "camlidl_mpz_mpz_com" external mpz_popcount : mpz_ptr -> int = "camlidl_mpz_mpz_popcount" external mpz_hamdist : mpz_ptr -> mpz_ptr -> int = "camlidl_mpz_mpz_hamdist" external mpz_scan0 : mpz_ptr -> int -> int = "camlidl_mpz_mpz_scan0" external mpz_scan1 : mpz_ptr -> int -> int = "camlidl_mpz_mpz_scan1" external mpz_setbit : mpz_ptr -> int -> unit = "camlidl_mpz_mpz_setbit" external mpz_clrbit : mpz_ptr -> int -> unit = "camlidl_mpz_mpz_clrbit" external mpz_tstbit : mpz_ptr -> int -> bool = "camlidl_mpz_mpz_tstbit" (** {2 Input and Output Functions: not interfaced} *) (** {2 Random Number Functions: see {!Gmp_random} module} *) (** {2 Integer Import and Export Functions} *) (** {{:ttp://gmplib.org/manual/Integer-Import-and-Export.html#Integer-Import-and-Export}C documentation} *) external mpz__import : mpz_ptr -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t -> int -> int -> unit = "camlidl_mpz_mpz__import" external mpz__export : mpz_ptr -> int -> int -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t = "camlidl_mpz_mpz__export" let import ~dest array ~order ~endian = _import dest array order endian let export x ~order ~endian = _export x order endian (** {2 Miscellaneous Functions} *) (** {{:http://gmplib.org/manual/Miscellaneous-Integer-Functions.html#Miscellaneous-Integer-Functions}C documentation} *) external mpz_fits_int_p : mpz_ptr -> bool = "camlidl_mpz_mpz_fits_int_p" external mpz_odd_p : mpz_ptr -> bool = "camlidl_mpz_mpz_odd_p" external mpz_even_p : mpz_ptr -> bool = "camlidl_mpz_mpz_even_p" external mpz_size : mpz_ptr -> int = "camlidl_mpz_mpz_size" external mpz_sizeinbase : mpz_ptr -> int -> int = "camlidl_mpz_mpz_sizeinbase" external mpz_fits_ulong_p : mpz_ptr -> bool = "camlidl_mpz_mpz_fits_ulong_p" external mpz_fits_slong_p : mpz_ptr -> bool = "camlidl_mpz_mpz_fits_slong_p" external mpz_fits_uint_p : mpz_ptr -> bool = "camlidl_mpz_mpz_fits_uint_p" external mpz_fits_sint_p : mpz_ptr -> bool = "camlidl_mpz_mpz_fits_sint_p" external mpz_fits_ushort_p : mpz_ptr -> bool = "camlidl_mpz_mpz_fits_ushort_p" external mpz_fits_sshort_p : mpz_ptr -> bool = "camlidl_mpz_mpz_fits_sshort_p" apron-dist-0.9.10/mlgmpidl/tmp/mpz.idl0000640014525101416610000003631211252216512017454 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \"limits.h\"\n\ #include \"caml/custom.h\"\n\ #include \"gmp_caml.h\"\n\ ") typedef [abstract,c2ml(camlidl_mpz_ptr_c2ml),ml2c(camlidl_mpz_ptr_ml2c)] struct __mpz_struct* mpz_ptr; quote(MLMLI,"(** GMP multi-precision integers *)\n\n") quote(MLMLI,"(** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x].\n\n These functions are as efficient as their C counterpart: they do not imply additional memory allocation, unlike the corresponding functions in the module {!Mpzf}. *)\n\n") /* OUTOUTOUT is a reserved variable name ! (see Makefile and sedscript_c) */ quote(MLI,"\n(** {2 Pretty printing} *)\n") quote(MLI,"val print : Format.formatter -> t -> unit") quote(MLMLI,"\n(** {2 Initialization Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Initializing-Integers.html#Initializing-Integers}C documentation} *)\n") void mpz_init([out] mpz_ptr OUTOUTOUT); void mpz_init2([out] mpz_ptr OUTOUTOUT, unsigned long N); void mpz_realloc2 (mpz_ptr ROP, unsigned long N); quote(MLMLI,"\n(** {2 Assignement Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Assigning-Integers.html#Assigning-Integers}C documentation} *)\n") quote(MLMLI,"\n(** The first parameter holds the result. *)\n") void mpz_set(mpz_ptr ROP, mpz_ptr OP); void mpz_set_si(mpz_ptr ROP, long int OP); void mpz_set_d (mpz_ptr ROP, double OP); quote(MLI,"\n(** For [set_q: t -> Mpq.t -> unit], see {!Mpq.get_z} *)\n\n") /* void mpz_set_q (mpz_ptr ROP, mpq_t OP); */ void mpz__set_str (mpz_ptr ROP, [string]char* STR, int BASE) quote(call,"{\n\ int n = mpz_set_str(ROP,STR,BASE);\n\ if (n){ mpz_clear(ROP); caml_invalid_argument(\"\"); }\n\ }"); quote(MLI,"val set_str : t -> string -> base:int -> unit") quote(ML,"let set_str a b ~base = _set_str a b base") void mpz_swap (mpz_ptr ROP1, mpz_ptr ROP2); quote(MLMLI,"\n(** {2 Combined Initialization and Assignment Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Simultaneous-Integer-Init-_0026-Assign.html#Simultaneous-Integer-Init-_0026-Assign}C documentation} *)\n") void mpz_init_set ([out]mpz_ptr OUTOUTOUT, mpz_ptr OP); void mpz_init_set_si ([out]mpz_ptr OUTOUTOUT, signed long int OP); void mpz_init_set_d ([out]mpz_ptr OUTOUTOUT, double OP); void mpz__init_set_str([out]mpz_ptr OUTOUTOUT, [string]char *STR, int BASE) quote(call,"\ {\n\ int n = mpz_init_set_str(OUTOUTOUT,STR,BASE);\n\ if (n){ mpz_clear(OUTOUTOUT); caml_invalid_argument(\"\"); }\n\ }"); quote(MLI,"val init_set_str : string -> base:int -> t") quote(ML,"let init_set_str a ~base = _init_set_str a base") quote(MLMLI,"\n(** {2 Conversion Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Converting-Integers.html#Converting-Integers}C documentation} *)\n") [nativeint]signed long int mpz_get_si (mpz_ptr OP); signed long int mpz_get_int (mpz_ptr OP) quote(call,"_res = mpz_get_si(OP);"); double mpz_get_d (mpz_ptr OP); double mpz_get_d_2exp ([out]signed long int *EXP, mpz_ptr OP); [string]char* mpz__get_str (int BASE, mpz_ptr OP) quote(call,"_res = mpz_get_str(NULL,BASE,OP);") quote(dealloc,"free(_res);"); quote(MLI,"val get_str : base:int -> t -> string") quote(ML,"let get_str ~base a = _get_str base a") quote(MLMLI,"\n\n(** {2 User Conversions} *)\n") quote(MLMLI,"(** These functions are additions to or renaming of functions offered by the C library. *)\n") quote(MLI,"val to_string : t -> string") quote(MLI,"val to_float : t -> float") quote(ML,"let to_string x = get_str 10 x") quote(ML,"let to_float = get_d") quote(MLI,"val of_string : string -> t") quote(MLI,"val of_float : float -> t") quote(MLI,"val of_int : int -> t") quote(ML,"let of_string str = init_set_str str 10") quote(ML,"let of_float = init_set_d") quote(ML,"let of_int = init_set_si") quote(ML,"\n(** {2 Pretty printing} *)\n") quote(ML,"let print fmt x = Format.pp_print_string fmt (get_str 10 x)") quote(MLMLI,"\n(** {2 Arithmetic Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Arithmetic.html#Integer-Arithmetic}C documentation} *)\n") quote(MLMLI,"(** The first parameter holds the result. *)\n") void mpz_add (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_add_ui (mpz_ptr ROP, mpz_ptr OP1, unsigned long int OP2); void mpz_sub (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_sub_ui (mpz_ptr ROP, mpz_ptr OP1, unsigned long int OP2); void mpz_ui_sub (mpz_ptr ROP, unsigned long int OP1, mpz_ptr OP2); void mpz_mul (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_mul_si (mpz_ptr ROP, mpz_ptr OP1, long int OP2); void mpz_addmul (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_addmul_ui (mpz_ptr ROP, mpz_ptr OP1, unsigned long int OP2); void mpz_submul (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_submul_ui (mpz_ptr ROP, mpz_ptr OP1, unsigned long int OP2); void mpz_mul_2exp (mpz_ptr ROP, mpz_ptr OP1, unsigned long int OP2); void mpz_neg (mpz_ptr ROP, mpz_ptr OP); void mpz_abs (mpz_ptr ROP, mpz_ptr OP); quote(MLMLI,"\n(** {2 Division Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Division.html#Integer-Division}C documentation} *)\n") quote(MLMLI,"(** [c] stands for ceiling, [f] for floor, and [t] for truncate (rounds toward 0).*)") quote(MLMLI,"(** {3 Ceiling division} *)\n") quote(MLMLI,"(** The first parameter holds the quotient. *)") void mpz_cdiv_q (mpz_ptr Q, mpz_ptr N, mpz_ptr D); quote(MLMLI,"(** The first parameter holds the remainder. *)") void mpz_cdiv_r (mpz_ptr R, mpz_ptr N, mpz_ptr D); quote(MLMLI,"(** The two first parameters hold resp. the quotient and the remainder). *)") void mpz_cdiv_qr (mpz_ptr Q, mpz_ptr R, mpz_ptr N, mpz_ptr D); quote(MLMLI,"(** The first parameter holds the quotient. *)") unsigned long int mpz_cdiv_q_ui (mpz_ptr Q, mpz_ptr N, unsigned long int D); quote(MLMLI,"(** The first parameter holds the remainder. *)") unsigned long int mpz_cdiv_r_ui (mpz_ptr R, mpz_ptr N, unsigned long int D); quote(MLMLI,"(** The two first parameters hold resp. the quotient and the remainder). *)") unsigned long int mpz_cdiv_qr_ui (mpz_ptr Q, mpz_ptr R, mpz_ptr N, unsigned long int D); unsigned long int mpz_cdiv_ui (mpz_ptr N, unsigned long int D); quote(MLMLI,"(** The first parameter holds the quotient. *)") void mpz_cdiv_q_2exp (mpz_ptr Q, mpz_ptr N, unsigned long int B); quote(MLMLI,"(** The first parameter holds the remainder. *)") void mpz_cdiv_r_2exp (mpz_ptr R, mpz_ptr N, unsigned long int B); quote(MLMLI,"(** {3 Floor division} *)\n") void mpz_fdiv_q (mpz_ptr Q, mpz_ptr N, mpz_ptr D); void mpz_fdiv_r (mpz_ptr R, mpz_ptr N, mpz_ptr D); void mpz_fdiv_qr (mpz_ptr Q, mpz_ptr R, mpz_ptr N, mpz_ptr D); unsigned long int mpz_fdiv_q_ui (mpz_ptr Q, mpz_ptr N, unsigned long int D); unsigned long int mpz_fdiv_r_ui (mpz_ptr R, mpz_ptr N, unsigned long int D); unsigned long int mpz_fdiv_qr_ui (mpz_ptr Q, mpz_ptr R, mpz_ptr N, unsigned long int D); unsigned long int mpz_fdiv_ui (mpz_ptr N, unsigned long int D); void mpz_fdiv_q_2exp (mpz_ptr Q, mpz_ptr N, unsigned long int B); void mpz_fdiv_r_2exp (mpz_ptr R, mpz_ptr N, unsigned long int B); quote(MLMLI,"(** {3 Truncate division} *)\n") void mpz_tdiv_q (mpz_ptr Q, mpz_ptr N, mpz_ptr D); void mpz_tdiv_r (mpz_ptr R, mpz_ptr N, mpz_ptr D); void mpz_tdiv_qr (mpz_ptr Q, mpz_ptr R, mpz_ptr N, mpz_ptr D); unsigned long int mpz_tdiv_q_ui (mpz_ptr Q, mpz_ptr N, unsigned long int D); unsigned long int mpz_tdiv_r_ui (mpz_ptr R, mpz_ptr N, unsigned long int D); unsigned long int mpz_tdiv_qr_ui (mpz_ptr Q, mpz_ptr R, mpz_ptr N, unsigned long int D); unsigned long int mpz_tdiv_ui (mpz_ptr N, unsigned long int D); void mpz_tdiv_q_2exp (mpz_ptr Q, mpz_ptr N, unsigned long int B); void mpz_tdiv_r_2exp (mpz_ptr R, mpz_ptr N, unsigned long int B); quote(MLMLI,"(** {3 Other division-related functions} *)\n") void mpz_gmod (mpz_ptr R, mpz_ptr N, mpz_ptr D) quote(call,"mpz_mod(R,N,D);"); unsigned long int mpz_gmod_ui (mpz_ptr R, mpz_ptr N, unsigned long int D) quote(call,"_res = mpz_mod_ui(R,N,D);"); void mpz_divexact (mpz_ptr Q, mpz_ptr N, mpz_ptr D); void mpz_divexact_ui (mpz_ptr Q, mpz_ptr N, unsigned long D); boolean mpz_divisible_p (mpz_ptr N, mpz_ptr D); boolean mpz_divisible_ui_p (mpz_ptr N, unsigned long int D); boolean mpz_divisible_2exp_p (mpz_ptr N, unsigned long int B); boolean mpz_congruent_p (mpz_ptr N, mpz_ptr C, mpz_ptr D); boolean mpz_congruent_ui_p (mpz_ptr N, unsigned long int C, unsigned long int D); boolean mpz_congruent_2exp_p (mpz_ptr N, mpz_ptr C, unsigned long int B); quote(MLMLI,"\n(** {2 Exponentiation Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Exponentiation.html#Integer-Exponentiation}C documentation} *)\n") void mpz__powm (mpz_ptr ROP, mpz_ptr BASE, mpz_ptr EXP, mpz_ptr MOD) quote(call,"mpz_powm(ROP,BASE,EXP,MOD);"); void mpz__powm_ui (mpz_ptr ROP, mpz_ptr BASE, unsigned long int EXP, mpz_ptr MOD) quote(call,"mpz_powm_ui(ROP,BASE,EXP,MOD);"); quote(MLI,"\ val powm : t -> t -> t -> modulo:t -> unit\n\ val powm_ui : t -> t -> int -> modulo:t -> unit\n\ ") quote(ML,"\ let powm a b c ~modulo = _powm a b c modulo\n\ let powm_ui a b c ~modulo = _powm_ui a b c modulo\n\ ") void mpz_pow_ui (mpz_ptr ROP, mpz_ptr BASE, unsigned long int EXP); void mpz_ui_pow_ui (mpz_ptr ROP, unsigned long int BASE,unsigned long int EXP); quote(MLMLI,"\n(** {2 Root Extraction Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Roots.html#Integer-Roots}C documentation} *)\n") boolean mpz_root (mpz_ptr ROP, mpz_ptr OP, unsigned long int N); void mpz_sqrt (mpz_ptr ROP, mpz_ptr OP); void mpz__sqrtrem (mpz_ptr ROP1, mpz_ptr ROP2, mpz_ptr OP) quote(call,"mpz_sqrtrem(ROP1,ROP2,OP);"); quote(MLI,"val sqrtrem : t -> remainder:t -> t -> unit") quote(ML,"let sqrtrem a ~remainder b = _sqrtrem a remainder b") boolean mpz_perfect_power_p (mpz_ptr OP); boolean mpz_perfect_square_p (mpz_ptr OP); quote(MLMLI,"\n(** {2 Number Theoretic Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Number-Theoretic-Functions.html#Number-Theoretic-Functions}C documentation} *)\n") int mpz_probab_prime_p (mpz_ptr N, int REPS); void mpz_nextprime (mpz_ptr ROP, mpz_ptr OP); void mpz_gcd (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); unsigned long int mpz_gcd_ui ([unique]mpz_ptr* ROP, mpz_ptr OP1, unsigned long int OP2) quote(call,"_res = mpz_gcd_ui(ROP ? *ROP : NULL,OP1,OP2);"); void mpz__gcdext (mpz_ptr G, mpz_ptr S, mpz_ptr T, mpz_ptr A, mpz_ptr B) quote(call,"mpz_gcdext(G,S,T,A,B);"); quote(MLI,"val gcdext : gcd:t -> alpha:t -> beta:t -> t -> t -> unit") quote(ML,"let gcdext ~gcd ~alpha ~beta a b = _gcdext gcd alpha beta a b") void mpz_lcm (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_lcm_ui (mpz_ptr ROP, mpz_ptr OP1, unsigned long OP2); boolean mpz_invert (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); int mpz_jacobi (mpz_ptr A, mpz_ptr B); int mpz_legendre (mpz_ptr A, mpz_ptr P); int mpz_kronecker (mpz_ptr A, mpz_ptr B); int mpz_kronecker_si (mpz_ptr A, long B); int mpz_si_kronecker (long A, mpz_ptr B); unsigned long int mpz_remove (mpz_ptr ROP, mpz_ptr OP, mpz_ptr F); void mpz_fac_ui (mpz_ptr ROP, unsigned long int OP); void mpz_bin_ui (mpz_ptr ROP, mpz_ptr N, unsigned long int K); void mpz_bin_uiui (mpz_ptr ROP, unsigned long int N, unsigned long int K); void mpz_fib_ui (mpz_ptr FN, unsigned long int N); void mpz_fib2_ui (mpz_ptr FN, mpz_ptr FNSUB1, unsigned long N); void mpz_lucnum_ui (mpz_ptr LN, unsigned long int N); void mpz_lucnum2_ui (mpz_ptr LN, mpz_ptr LNSUB1, unsigned long int N); quote(MLMLI,"\n(** {2 Comparison Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Comparisons.html#Integer-Comparisons}C documentation} *)\n") int mpz_cmp (mpz_ptr OP1, mpz_ptr OP2); int mpz_cmp_d (mpz_ptr OP1, double OP2); int mpz_cmp_si (mpz_ptr OP1, signed long int OP2); int mpz_cmpabs (mpz_ptr OP1, mpz_ptr OP2); int mpz_cmpabs_d (mpz_ptr OP1, double OP2); int mpz_cmpabs_ui (mpz_ptr OP1, unsigned long int OP2); int mpz_sgn (mpz_ptr OP); quote(MLMLI,"\n(** {2 Logical and Bit Manipulation Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Logic-and-Bit-Fiddling.html#Integer-Logic-and-Bit-Fiddling}C documentation} *)\n") void mpz_gand (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2) quote(call,"mpz_and(ROP,OP1,OP2);"); void mpz_ior (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_xor (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_com (mpz_ptr ROP, mpz_ptr OP); unsigned long int mpz_popcount (mpz_ptr OP) quote(call,"_res = mpz_popcount(OP); if (_res==ULONG_MAX) _res = Max_long;"); unsigned long int mpz_hamdist (mpz_ptr OP1, mpz_ptr OP2) quote(call,"_res = mpz_hamdist(OP1,OP2); if (_res==ULONG_MAX) _res = Max_long;"); unsigned long int mpz_scan0 (mpz_ptr OP, unsigned long int STARTING_BIT) quote(call,"_res = mpz_scan0(OP,STARTING_BIT); if (_res==ULONG_MAX) _res = Max_long;"); unsigned long int mpz_scan1 (mpz_ptr OP, unsigned long int STARTING_BIT) quote(call,"_res = mpz_scan1(OP,STARTING_BIT); if (_res==ULONG_MAX) _res = Max_long;"); void mpz_setbit (mpz_ptr ROP, unsigned long int BIT_INDEX); void mpz_clrbit (mpz_ptr ROP, unsigned long int BIT_INDEX); boolean mpz_tstbit (mpz_ptr OP, unsigned long int BIT_INDEX); quote(MLMLI,"\n(** {2 Input and Output Functions: not interfaced} *)\n") quote(MLMLI,"\n(** {2 Random Number Functions: see {!Gmp_random} module} *)\n") quote(MLMLI,"\n(** {2 Integer Import and Export Functions} *)") quote(MLMLI,"(** {{:ttp://gmplib.org/manual/Integer-Import-and-Export.html#Integer-Import-and-Export}C documentation} *)\n") void mpz__import (mpz_ptr ROP, int COUNT, [size_is(COUNT),bigarray] int OP[], int ORDER, int ENDIAN) quote(call,"mpz_import (ROP, COUNT, ORDER, sizeof(intnat), ENDIAN, 0, OP);"); [size_is(COUNT),bigarray,managed] int* mpz__export (mpz_ptr OP, int ORDER, int ENDIAN, [out,ignore]unsigned int *COUNT) quote(call,"_res = mpz_export (NULL, COUNT, ORDER, sizeof(intnat), ENDIAN, 0, OP);"); quote(MLI,"\ val import : dest:t -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t -> order:int -> endian:int -> unit\n\ val export : t -> order:int -> endian:int -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t\n\ ") quote(ML,"\ let import ~dest array ~order ~endian = _import dest array order endian\n\ let export x ~order ~endian = _export x order endian\n\ ") quote(MLMLI,"\n(** {2 Miscellaneous Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Miscellaneous-Integer-Functions.html#Miscellaneous-Integer-Functions}C documentation} *)\n") quote(MLI,"\n(* Does it fit in an OCaml integer *)") boolean mpz_fits_int_p (mpz_ptr OP); boolean mpz_odd_p (mpz_ptr OP); boolean mpz_even_p (mpz_ptr OP); int mpz_size(mpz_ptr OP); int mpz_sizeinbase (mpz_ptr OP, int BASE) quote(call,"\ if (BASE<2 || BASE>36) caml_invalid_argument(\"Argument not supported\");\n\ _res = mpz_sizeinbase (OP,BASE);"); quote(MLI,"\n(* Limited relevance here *)") boolean mpz_fits_ulong_p (mpz_ptr OP); boolean mpz_fits_slong_p (mpz_ptr OP); boolean mpz_fits_uint_p (mpz_ptr OP); boolean mpz_fits_sint_p (mpz_ptr OP); boolean mpz_fits_ushort_p (mpz_ptr OP); boolean mpz_fits_sshort_p (mpz_ptr OP); apron-dist-0.9.10/mlgmpidl/tmp/mpq.idl0000640014525101416610000001344611252216513017447 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \"caml/custom.h\"\n\ #include \"gmp_caml.h\"\n\ ") import "mpz.idl"; typedef [abstract,c2ml(camlidl_mpq_ptr_c2ml),ml2c(camlidl_mpq_ptr_ml2c)] struct __mpq_struct* mpq_ptr; quote(MLMLI,"(** GMP multiprecision rationals *)\n\n") quote(MLMLI,"(** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x].\n\n These functions are as efficient as their C counterpart: they do not imply additional memory allocation, unlike the corresponding functions in the module {!Mpqf}. *)\n\n") /* OUTOUTOUT is a reserved variable name ! (see Makefile and sedscript_c) */ void mpq_canonicalize (mpq_ptr OP); quote(MLI,"\n(** {2 Pretty printing} *)\n") quote(MLI,"val print : Format.formatter -> t -> unit") quote(MLMLI,"\n(** {2 Initialization and Assignment Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Initializing-Rationals.html#Initializing-Rationals}C documentation} *)\n") void mpq_init([out] mpq_ptr OUTOUTOUT); void mpq_set(mpq_ptr ROP, mpq_ptr OP); void mpq_set_z (mpq_ptr ROP, mpz_ptr OP); void mpq_set_si (mpq_ptr ROP, signed long int OP1, unsigned long int OP2) quote(dealloc, "mpq_canonicalize(ROP);"); void mpq__set_str(mpq_ptr ROP, [string]char* STR, int BASE) quote(call,"{\n\ int n = mpq_set_str(ROP,STR,BASE);\n\ if (n){ mpq_clear(ROP); caml_invalid_argument(\"\"); }\n\ }") quote(dealloc, "mpq_canonicalize(ROP);"); quote(MLI,"val set_str : t -> string -> base:int -> unit") quote(ML,"let set_str a b ~base = _set_str a b base") void mpq_swap (mpq_ptr ROP1, mpq_ptr ROP2); quote(MLI,"(** {2 Additional Initialization and Assignements functions} *)\n") quote(MLI,"(** These functions are additions to or renaming of functions offered by the C library. *)\n") quote(MLI,"val init_set : t -> t") quote(MLI,"val init_set_z : Mpz.t -> t") quote(MLI,"val init_set_si : int -> int -> t") quote(MLI,"val init_set_str : string -> base:int -> t") quote(MLI,"val init_set_d : float -> t") quote(MLMLI,"\n(** {2 Conversion Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Rational-Conversions.html#Rational-Conversions}C documentation} *)\n") double mpq_get_d (mpq_ptr OP); void mpq_set_d (mpq_ptr ROP, double OP); quote(MLI,"\n(* Replace Mpz.set_q: Mpz.t -> Mpq.t -> unit *)") void mpq_get_z(mpz_ptr ROP, mpq_ptr OP) quote(call,"mpz_set_q(ROP,OP);"); quote(MLI,"\n(* For set_f: t -> Mpf.t -> unit, see Mpf.get_q *)\n\n") /* void mpq_set_f (mpq_ptr ROP, mpf_ptr OP); */ [string]char* mpq__get_str (int BASE, mpq_ptr OP) quote(call,"_res = mpq_get_str(NULL,BASE,OP);") quote(dealloc,"free(_res);"); quote(MLI,"val get_str : base:int -> t -> string") quote(ML,"let get_str ~base a = _get_str base a") quote(MLI,"\n(** {2 User Conversions} *)\n") quote(MLI,"(** These functionss are additions to or renaming of functions offeered by the C library. *)\n") quote(MLI,"val to_string : t -> string") quote(MLI,"val to_float : t -> float") quote(MLI,"val of_string : string -> t") quote(MLI,"val of_float : float -> t") quote(MLI,"val of_int : int -> t") quote(MLI,"val of_frac : int -> int -> t") quote(MLI,"val of_mpz : Mpz.t -> t") quote(MLI,"val of_mpz2 : Mpz.t -> Mpz.t -> t") quote(MLMLI,"\n(** {2 Arithmetic Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Rational-Arithmetic.html#Rational-Arithmetic}C documentation} *)\n") void mpq_add (mpq_ptr ROP, mpq_ptr OP1, mpq_ptr OP2); void mpq_sub (mpq_ptr ROP, mpq_ptr OP1, mpq_ptr OP2); void mpq_mul (mpq_ptr ROP, mpq_ptr OP1, mpq_ptr OP2); void mpq_mul_2exp (mpq_ptr ROP, mpq_ptr OP1, unsigned long int OP2); void mpq_div (mpq_ptr ROP, mpq_ptr OP1, mpq_ptr OP2); void mpq_div_2exp (mpq_ptr ROP, mpq_ptr OP1, unsigned long int OP2); void mpq_neg (mpq_ptr ROP, mpq_ptr OP); void mpq_abs (mpq_ptr ROP, mpq_ptr OP); void mpq_inv (mpq_ptr ROP, mpq_ptr OP); quote(MLMLI,"\n(** {2 Comparison Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Comparing-Rationals.html#Comparing-Rationals}C documentation} *)\n") int mpq_cmp (mpq_ptr OP1, mpq_ptr OP2); int mpq_cmp_si (mpq_ptr OP1, long int NUM2, unsigned long int DEN2); int mpq_sgn (mpq_ptr OP); boolean mpq_equal (mpq_ptr OP1, mpq_ptr OP2); quote(MLMLI,"\n(** {2 Applying Integer Functions to Rationals} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Applying-Integer-Functions.html#Applying-Integer-Functions}C documentation} *)\n") void mpq_get_num (mpz_ptr NUMERATOR, mpq_ptr RATIONAL); void mpq_get_den (mpz_ptr DENOMINATOR, mpq_ptr RATIONAL); void mpq_set_num (mpq_ptr RATIONAL, mpz_ptr NUMERATOR); void mpq_set_den (mpq_ptr RATIONAL, mpz_ptr DENOMINATOR); quote(MLMLI,"\n(** {2 Input and Output Functions: not interfaced} *)\n") quote(ML,"\n(** {2 Pretty printing} *)\n") quote(ML,"let print fmt x = Format.pp_print_string fmt (get_str 10 x)") quote(ML,"let init_set x = let y = init() in set y x; y") quote(ML,"let init_set_z z = let x = init() in set_z x z; x") quote(ML,"let init_set_si n d = let x = init() in set_si x n d; x") quote(ML,"let init_set_str str ~base = let x = init() in ignore (set_str x str ~base); x") quote(ML,"let init_set_d d = let x = init() in set_d x d; x") quote(ML,"let to_string x = get_str 10 x") quote(ML,"let to_float = get_d") quote(ML,"let of_string str = init_set_str str 10") quote(ML,"let of_float = init_set_d") quote(ML,"let of_int a = init_set_si a 1") quote(ML,"let of_frac = init_set_si") quote(ML,"let of_mpz = init_set_z") quote(ML,"let of_mpz2 num den = let res = init() in set_num res num; set_den res den; canonicalize res; res") apron-dist-0.9.10/mlgmpidl/tmp/mpq_stubs.c0000640014525101416610000003015411252216513020334 0ustar bjeannetpopart/* File generated from mpq.idl */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include "caml/custom.h" #include "gmp_caml.h" extern void camlidl_mpz_ptr_ml2c(value, mpz_ptr *); #define camlidl_ml2c_mpz_mpz_ptr(v,c,ctx) camlidl_mpz_ptr_ml2c(v,c) extern value camlidl_mpz_ptr_c2ml(mpz_ptr *); #define camlidl_c2ml_mpz_mpz_ptr(c,ctx) camlidl_mpz_ptr_c2ml(c) #define camlidl_ml2c_mpq_mpq_ptr(v,c,ctx) camlidl_mpq_ptr_ml2c(v,c) #define camlidl_c2ml_mpq_mpq_ptr(c,ctx) camlidl_mpq_ptr_c2ml(c) value camlidl_mpq_mpq_canonicalize( value _v_OP) { mpq_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); mpq_canonicalize(OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_init(value _unit) { mpq_ptr OUTOUTOUT; /*out*/ value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; mpq_init(OUTOUTOUT); _vres = camlidl_c2ml_mpq_mpq_ptr(&OUTOUTOUT, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_mpq_mpq_set( value _v_ROP, value _v_OP) { mpq_ptr ROP; /*in*/ mpq_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); mpq_set(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_set_z( value _v_ROP, value _v_OP) { mpq_ptr ROP; /*in*/ mpz_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_OP, &OP, _ctx); mpq_set_z(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_set_si( value _v_ROP, value _v_OP1, value _v_OP2) { mpq_ptr ROP; /*in*/ long OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); OP1 = Long_val(_v_OP1); OP2 = Long_val(_v_OP2); mpq_set_si(ROP, OP1, OP2); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ mpq_canonicalize(ROP); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_mpq_mpq__set_str( value _v_ROP, value _v_STR, value _v_BASE) { mpq_ptr ROP; /*in*/ char *STR; /*in*/ int BASE; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); STR = String_val(_v_STR); BASE = Int_val(_v_BASE); /* begin user-supplied calling sequence */ { int n = mpq_set_str(ROP,STR,BASE); if (n){ mpq_clear(ROP); caml_invalid_argument(""); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ mpq_canonicalize(ROP); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_mpq_mpq_swap( value _v_ROP1, value _v_ROP2) { mpq_ptr ROP1; /*in*/ mpq_ptr ROP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP1, &ROP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_ROP2, &ROP2, _ctx); mpq_swap(ROP1, ROP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_get_d( value _v_OP) { mpq_ptr OP; /*in*/ double _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); _res = mpq_get_d(OP); _vres = copy_double(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpq_mpq_set_d( value _v_ROP, value _v_OP) { mpq_ptr ROP; /*in*/ double OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); OP = Double_val(_v_OP); mpq_set_d(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_get_z( value _v_ROP, value _v_OP) { mpz_ptr ROP; /*in*/ mpq_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); /* begin user-supplied calling sequence */ mpz_set_q(ROP,OP); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq__get_str( value _v_BASE, value _v_OP) { int BASE; /*in*/ mpq_ptr OP; /*in*/ char *_res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; BASE = Int_val(_v_BASE); camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); /* begin user-supplied calling sequence */ _res = mpq_get_str(NULL,BASE,OP); /* end user-supplied calling sequence */ _vres = copy_string(_res); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ free(_res); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_mpq_mpq_add( value _v_ROP, value _v_OP1, value _v_OP2) { mpq_ptr ROP; /*in*/ mpq_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); mpq_add(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_sub( value _v_ROP, value _v_OP1, value _v_OP2) { mpq_ptr ROP; /*in*/ mpq_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); mpq_sub(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_mul( value _v_ROP, value _v_OP1, value _v_OP2) { mpq_ptr ROP; /*in*/ mpq_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); mpq_mul(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_mul_2exp( value _v_ROP, value _v_OP1, value _v_OP2) { mpq_ptr ROP; /*in*/ mpq_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpq_mul_2exp(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_div( value _v_ROP, value _v_OP1, value _v_OP2) { mpq_ptr ROP; /*in*/ mpq_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); mpq_div(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_div_2exp( value _v_ROP, value _v_OP1, value _v_OP2) { mpq_ptr ROP; /*in*/ mpq_ptr OP1; /*in*/ unsigned long OP2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP1, &OP1, _ctx); OP2 = Long_val(_v_OP2); mpq_div_2exp(ROP, OP1, OP2); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_neg( value _v_ROP, value _v_OP) { mpq_ptr ROP; /*in*/ mpq_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); mpq_neg(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_abs( value _v_ROP, value _v_OP) { mpq_ptr ROP; /*in*/ mpq_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); mpq_abs(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_inv( value _v_ROP, value _v_OP) { mpq_ptr ROP; /*in*/ mpq_ptr OP; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_ROP, &ROP, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); mpq_inv(ROP, OP); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_cmp( value _v_OP1, value _v_OP2) { mpq_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); _res = mpq_cmp(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpq_mpq_cmp_si( value _v_OP1, value _v_NUM2, value _v_DEN2) { mpq_ptr OP1; /*in*/ long NUM2; /*in*/ unsigned long DEN2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_OP1, &OP1, _ctx); NUM2 = Long_val(_v_NUM2); DEN2 = Long_val(_v_DEN2); _res = mpq_cmp_si(OP1, NUM2, DEN2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpq_mpq_sgn( value _v_OP) { mpq_ptr OP; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_OP, &OP, _ctx); _res = mpq_sgn(OP); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpq_mpq_equal( value _v_OP1, value _v_OP2) { mpq_ptr OP1; /*in*/ mpq_ptr OP2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_OP1, &OP1, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_OP2, &OP2, _ctx); _res = mpq_equal(OP1, OP2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_mpq_mpq_get_num( value _v_NUMERATOR, value _v_RATIONAL) { mpz_ptr NUMERATOR; /*in*/ mpq_ptr RATIONAL; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_NUMERATOR, &NUMERATOR, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_RATIONAL, &RATIONAL, _ctx); mpq_get_num(NUMERATOR, RATIONAL); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_get_den( value _v_DENOMINATOR, value _v_RATIONAL) { mpz_ptr DENOMINATOR; /*in*/ mpq_ptr RATIONAL; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpz_mpz_ptr(_v_DENOMINATOR, &DENOMINATOR, _ctx); camlidl_ml2c_mpq_mpq_ptr(_v_RATIONAL, &RATIONAL, _ctx); mpq_get_den(DENOMINATOR, RATIONAL); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_set_num( value _v_RATIONAL, value _v_NUMERATOR) { mpq_ptr RATIONAL; /*in*/ mpz_ptr NUMERATOR; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_RATIONAL, &RATIONAL, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_NUMERATOR, &NUMERATOR, _ctx); mpq_set_num(RATIONAL, NUMERATOR); camlidl_free(_ctx); return Val_unit; } value camlidl_mpq_mpq_set_den( value _v_RATIONAL, value _v_DENOMINATOR) { mpq_ptr RATIONAL; /*in*/ mpz_ptr DENOMINATOR; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_mpq_mpq_ptr(_v_RATIONAL, &RATIONAL, _ctx); camlidl_ml2c_mpz_mpz_ptr(_v_DENOMINATOR, &DENOMINATOR, _ctx); mpq_set_den(RATIONAL, DENOMINATOR); camlidl_free(_ctx); return Val_unit; } apron-dist-0.9.10/mlgmpidl/gmp_caml.h0000640014525101416610000000343510645155755017324 0ustar bjeannetpopart/* ********************************************************************** */ /* gmp_caml.h */ /* ********************************************************************** */ /* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef __GMP_CAML_H__ #define __GMP_CAML_H__ #include #include #include "gmp.h" #if defined(HAS_MPFR) #if HAS_MPFR!=0 #include "mpfr.h" #endif #endif #include "caml/mlvalues.h" #ifdef __cplusplus extern "C" { #endif struct gmp_randstate__t { gmp_randstate_t mp; }; typedef __gmp_randstate_struct* gmp_randstate_ptr; value camlidl_mpz_ptr_c2ml(mpz_ptr* mpz); void camlidl_mpz_ptr_ml2c(value val, mpz_ptr* mpz); void camlidl_mpz_ml2c(value val, __mpz_struct* mpz); value camlidl_mpq_ptr_c2ml(mpq_ptr* mpq); void camlidl_mpq_ptr_ml2c(value val, mpq_ptr* mpq); void camlidl_mpq_ml2c(value val, __mpq_struct* mpq); value camlidl_mpf_ptr_c2ml(mpf_ptr* mpf); void camlidl_mpf_ptr_ml2c(value val, mpf_ptr* mpf); void camlidl_mpf_ml2c(value val, __mpf_struct* mpf); #if defined(HAS_MPFR) #if HAS_MPFR!=0 value camlidl_mpfr_ptr_c2ml(mpfr_ptr* mpf); void camlidl_mpfr_ptr_ml2c(value val, mpfr_ptr* mpf); void camlidl_mpfr_ml2c(value val, __mpfr_struct* mpf); static inline value camlidl_mpfr_rnd_t_c2ml(mpfr_rnd_t* rnd) { assert(*rnd>=0 && *rnd=0 && *rnd=4.1.x required M4 = m4 INSTALL = install INSTALLd = install -d OCAMLC = $(CAML_PREFIX)/bin/ocamlc.opt OCAMLOPT = $(CAML_PREFIX)/bin/ocamlopt.opt # ocamlc compilation flags OCAMLFLAGS = -g # ocamlopt compilation flags OCAMLOPTFLAGS = -inline 20 OCAMLDEP = $(CAML_PREFIX)/bin/ocamldep OCAMLLEX = $(CAML_PREFIX)/bin/ocamllex.opt OCAMLYACC = $(CAML_PREFIX)/bin/ocamlyacc OCAMLDOC = $(CAML_PREFIX)/bin/ocamldoc.opt OCAMLMKTOP = $(CAML_PREFIX)/bin/ocamlmktop OCAMLMKLIB = $(CAML_PREFIX)/bin/ocamlmklib CAMLIDL = $(CAMLIDL_PREFIX)/bin/camlidl LATEX=latex DVIPDF=dvipdf MAKEINDEX=makeindex TEXI2DVI=texi2dvi TEXI2HTML=texi2html apron-dist-0.9.10/Makefile0000640014525101416610000000157011251742505015212 0ustar bjeannetpopartinclude Makefile.config REQUESTED = \ mlgmpidl/Makefile.config \ apron/Makefile.config all: $(REQUESTED) ifneq ($(HAS_OCAML),) (cd mlgmpidl; make all install) endif (cd apron; make all) install: (cd apron; make all) rebuild: $(REQUESTED) ifneq ($(HAS_OCAML),) (cd mlgmpidl; make rebuild install) endif (cd apron; make rebuild) clean: $(REQUESTED) (cd mlgmpidl; make clean) (cd apron; make clean) mostlyclean: $(REQUESTED) (cd mlgmpidl; make mostlyclean) (cd apron; make mostlyclean) /bin/rm -f $(REQUESTED) uninstall: $(REQUESTED) (cd mlgmpidl; make uninstall) (cd apron; make uninstall) distclean: uninstall doc: ifneq ($(HAS_OCAML),) (cd mlgmpidl; make mlgmpidl.pdf html) endif (cd apron; make doc) mlgmpidl/Makefile.config: Makefile.config Makefile $(SED) -e '1 aHAS_MPFR=1\n' Makefile.config >$@ apron/Makefile.config: Makefile.config Makefile cp -f $< $@ apron-dist-0.9.10/README.mac0000640014525101416610000000250211251734233015164 0ustar bjeannetpopart This document tries to explain some specific points in compiling Apron under Macintosh. It brings additional information compared to the README. Note that this is work-in-progress. PREREQUISITES ------------- - GNU sed is required, instead of standard sed. - gcc 4.0.1 is reported to cause this problem at the end of the compilation process: ld: duplicate symbol ___gmpz_abs in ... more recent versions should work properly. The following Cygwin package are required: - gcc (Devel) - make (Devel) - gmp, mpfr (Math) - doxygen (Devel) - tetex-base (Publishing) Additionally, you'll need to install manually the following - OCaml 3.09 or better, from http://caml.inria.fr/ocaml/release.fr.html (the 3.08 version, in CygWin, at the time of writing is too old) - CamlIDL, from http://caml.inria.fr/pub/old_caml_site/camlidl/ CONFIGURATION ------------- Copy Makefile.config.model into Makefile.config and edit the _PREFIX paths to suit your installation (you might want to set APRON_PREFIX, CAMLIDL_PREFIX and CAML_PREFIX to /usr/local instead of the default /usr). The following options should be disabled: - HAS_CPP (Cygwin's gcc is too old) - HAS_PPL (Apron with PPL compilation untested under Windows) - HAS_LONG_DOUBLE (long double not supported by math library under Windows) Now, (make rebuild), make and make install. apron-dist-0.9.10/apron/0000750014525101416610000000000011252216654014667 5ustar bjeannetpopartapron-dist-0.9.10/apron/README.windows0000640014525101416610000000235211023224037017231 0ustar bjeannetpopart This document tries to explain how to compile Apron under Windows. For the moment, only 32-bit compilation using the Cygwin environment is supported. Note that this is work-in-progress. PREREQUISITES ------------- Get Cygwin at http://www.cygwin.com/ The following Cygwin package are required: - gcc (Devel) - make (Devel) - gmp, mpfr (Math) - doxygen (Devel) - tetex-base (Publishing) Additionally, you'll need to install manually the following - OCaml 3.09 or better, from http://caml.inria.fr/ocaml/release.fr.html (the 3.08 version, in CygWin, at the time of writing is too old) - CamlIDL, from http://caml.inria.fr/pub/old_caml_site/camlidl/ CONFIGURATION ------------- Copy Makefile.config.model into Makefile.config and edit the _PREFIX paths to suit your installation (you might want to set APRON_PREFIX, CAMLIDL_PREFIX and CAML_PREFIX to /usr/local instead of the default /usr). The following options should be disabled: - HAS_CPP (Cygwin's gcc is too old) - HAS_PPL (Apron with PPL compilation untested under Windows) - HAS_LONG_DOUBLE (long double not supported by math library under Windows) Do the same with mlgmpidl/Makefile.config.model Now, (make rebuild), make and make install in the apron top-level directory should work. apron-dist-0.9.10/apron/octagons/0000750014525101416610000000000011252216517016502 5ustar bjeannetpopartapron-dist-0.9.10/apron/octagons/oct_internal.h0000640014525101416610000004117011006063143021330 0ustar bjeannetpopart/* * oct_internal.h * * Private definitions, access to internal structures and algorithms. * Use with care. * * APRON Library / Octagonal Domain * * Copyright (C) Antoine Mine' 2006 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __OCT_INTERNAL_H #define __OCT_INTERNAL_H #include "oct_fun.h" #ifdef __cplusplus extern "C" { #endif /* ********************************************************************** */ /* I. Manager */ /* ********************************************************************** */ /* manager-local data specific to octagons */ struct _oct_internal_t { /* current function */ ap_funid_t funid; /* local parameters for current function */ ap_funopt_t* funopt; /* growing temporary buffer */ bound_t* tmp; void* tmp2; size_t tmp_size; /* raised when a conversion from/to a user type resulted in an overapproximation */ bool conv; /* back-pointer */ ap_manager_t* man; }; /* called by each function to setup and get manager-local data */ static inline oct_internal_t* oct_init_from_manager(ap_manager_t* man, ap_funid_t id, size_t size) { oct_internal_t* pr = (oct_internal_t*) man->internal; pr->funid = id; pr->funopt = man->option.funopt+id; man->result.flag_exact = man->result.flag_best = true; pr->conv = false; if (pr->tmp_sizetmp,pr->tmp_size); pr->tmp = (bound_t*)realloc(pr->tmp,sizeof(bound_t)*size); assert(pr->tmp); pr->tmp_size = size; bound_init_array(pr->tmp,pr->tmp_size); pr->tmp2 = realloc(pr->tmp2,sizeof(long)*size); assert(pr->tmp2); } return pr; } /* loss of precision can be due to one of the following 1) the algorithm is incomplete or the algorithm is incomplete on Z and we have intdim > 0 or the numerical type induces overapproximation (NUMINT or NUMFLOAT) => no solution at run-time, you need to recompile the library with another NUM base type 2) the user disabled closure (algorithm<0) => solution: raise algorithm 3) approximation in the conversion from / to user type => use another user type */ #define flag_incomplete \ man->result.flag_exact = man->result.flag_best = false #define flag_algo flag_incomplete #define flag_conv flag_incomplete /* invalid argument exception */ #define arg_assert(cond,action) \ do { if (!(cond)) { \ char buf_[1024]; \ snprintf(buf_,sizeof(buf_), \ "assertion (%s) failed in %s at %s:%i", \ #cond, __func__, __FILE__, __LINE__); \ ap_manager_raise_exception(pr->man,AP_EXC_INVALID_ARGUMENT, \ pr->funid,buf_); \ action } \ } while(0) /* malloc with safe-guard */ #define checked_malloc(ptr,t,nb,action) \ do { \ (ptr) = (t*)malloc(sizeof(t)*(nb)); \ if (!(ptr)) { \ char buf_[1024]; \ snprintf(buf_,sizeof(buf_), \ "cannot allocate %s[%lu] for %s in %s at %s:%i", \ #t, (long unsigned)(nb), #ptr, \ __func__, __FILE__, __LINE__); \ ap_manager_raise_exception(pr->man,AP_EXC_OUT_OF_SPACE, \ pr->funid,buf_); \ action } \ } while(0) /* ********************************************************************** */ /* II. Half-matrices */ /* ********************************************************************** */ /* ============================================================ */ /* II.1 Basic Management */ /* ============================================================ */ /* see oct_hmat.c */ bound_t* hmat_alloc (oct_internal_t* pr, size_t dim); void hmat_free (oct_internal_t* pr, bound_t* m, size_t dim); bound_t* hmat_alloc_zero (oct_internal_t* pr, size_t dim); bound_t* hmat_alloc_top (oct_internal_t* pr, size_t dim); bound_t* hmat_copy (oct_internal_t* pr, bound_t* m, size_t dim); void hmat_fdump (FILE* stream, oct_internal_t* pr, bound_t* m, size_t dim); //* ============================================================ */ /* II.2 Access */ /* ============================================================ */ static inline size_t matsize(size_t dim) { return 2 * dim * (dim+1); } /* position of (i,j) element, assuming j/2 <= i/2 */ static inline size_t matpos(size_t i, size_t j) { return j + ((i+1)*(i+1))/2; } /* position of (i,j) element, no assumption */ static inline size_t matpos2(size_t i, size_t j) { if (j>i) return matpos(j^1,i^1); else return matpos(i,j); } /* ============================================================ */ /* II.3 Closure Algorithms */ /* ============================================================ */ /* see oct_closure.c */ bool hmat_s_step(bound_t* m, size_t dim); bool hmat_close(bound_t* m, size_t dim); bool hmat_close_incremental(bound_t* m, size_t dim, size_t v); bool hmat_check_closed(bound_t* m, size_t dim); /* ============================================================ */ /* II.4 Constraints and generators */ /* ============================================================ */ /* see oct_transfer.c */ bool hmat_add_lincons(oct_internal_t* pr, bound_t* b, size_t dim, ap_lincons0_array_t* ar, bool* exact, bool* respect_closure); void hmat_add_generators(oct_internal_t* pr, bound_t* b, size_t dim, ap_generator0_array_t* ar); /* ============================================================ */ /* II.5 Resze */ /* ============================================================ */ /* see oct_reize.c */ void hmat_addrem_dimensions(bound_t* dst, bound_t* src, ap_dim_t* pos, size_t nb_pos, size_t mult, size_t dim, bool add); void hmat_permute(bound_t* dst, bound_t* src, size_t dst_dim, size_t src_dim, ap_dim_t* permutation); /* ********************************************************************** */ /* III. Numbers */ /* ********************************************************************** */ /* To perform soundly, we suppose that all conversions beteween num and base types (double, int, mpz, mpq, etc.) always over-approximate the result (as long as the fits function returns true). */ static inline void bound_bmin(bound_t dst, bound_t arg) { bound_min(dst,dst,arg); } static inline void bound_badd(bound_t dst, bound_t arg) { bound_add(dst,dst,arg); } /* ============================================================ */ /* III.1 Properties on num_t */ /* ============================================================ */ /* num_incomplete does the type make algorithms incomplete num_safe is the type safe in case of overflow */ #if defined(NUM_LONGINT) || defined(NUM_LONGLONGINT) /* overflows produce unsound results, type not closed by / 2 */ #define num_incomplete 1 #define num_safe 0 #elif defined ( NUM_MPZ ) /* no overflow, type not closed by / 2 */ #define num_incomplete 1 #define num_safe 1 #elif defined(NUM_LONGRAT) || defined(NUM_LONGLONGRAT) /* complete algorithms, but overflows produce unsound results */ #define num_incomplete 0 #define num_safe 0 #elif defined(NUM_MPQ) /* the "perfect" type */ #define num_incomplete 0 #define num_safe 1 #elif defined(NUM_DOUBLE) || defined(NUM_LONGDOUBLE) || defined(NUM_MPFR) /* overflow are ok (stick to +oo), type not closed by + and / 2 */ #define num_incomplete 1 #define num_safe 1 /* duh */ #else #error "No numerical type defined" #endif /* ============================================================ */ /* III.2 Conversions from user types */ /* ============================================================ */ /* sound conversion from a scalar to a bound_t optional negation and multiplication by 2 if negation, lower approximation, otherwise, upper approximation pr->conv is set if the conversion is not exact */ static inline void bound_of_scalar(oct_internal_t* pr, bound_t r, ap_scalar_t* t, bool neg, bool mul2) { if (neg) ap_scalar_neg(t,t); if (!bound_set_ap_scalar(r,t)) pr->conv = true; if (mul2) { bound_mul_2(r,r); pr->conv = true; } if (neg) ap_scalar_neg(t,t); } /* both bounds of an interval, the lower bound is negated pr->conv is set if the conversion is not exact returns true if the interval is empty */ static inline bool bounds_of_interval(oct_internal_t* pr, bound_t minf, bound_t sup, ap_interval_t* i, bool mul2) { bound_of_scalar(pr,minf,i->inf,true,mul2); bound_of_scalar(pr,sup,i->sup,false,mul2); return ap_scalar_cmp(i->inf,i->sup)>0; } /* as above, for a coeff_t */ static inline bool bounds_of_coeff(oct_internal_t* pr, bound_t minf, bound_t sup, ap_coeff_t c, bool mul2) { switch (c.discr) { case AP_COEFF_SCALAR: bound_of_scalar(pr,minf,c.val.scalar,true,mul2); bound_of_scalar(pr,sup,c.val.scalar,false,mul2); return false; case AP_COEFF_INTERVAL: bound_of_scalar(pr,minf,c.val.interval->inf,true,mul2); bound_of_scalar(pr,sup,c.val.interval->sup,false,mul2); return ap_scalar_cmp(c.val.interval->inf,c.val.interval->sup)>0; default: arg_assert(0,return false;); } } static void bounds_of_generator(oct_internal_t* pr, bound_t* dst, ap_linexpr0_t* e, size_t dim) { size_t i; switch (e->discr) { case AP_LINEXPR_DENSE: arg_assert(e->size<=dim,return;); for (i=0;isize;i++) { bounds_of_coeff(pr,dst[2*i],dst[2*i+1],e->p.coeff[i],false); } for (;isize;i++) { size_t d = e->p.linterm[i].dim; arg_assert(dp.linterm[i].coeff,false); } break; default: arg_assert(0,return;); } } /* ============================================================ */ /* III.3 Conversions to user types */ /* ============================================================ */ /* upper bound => scalar, with optional division by 2 pr->conv is set if the conversion is not exact */ static inline void scalar_of_upper_bound(oct_internal_t* pr, ap_scalar_t* r, bound_t b, bool div2) { ap_scalar_reinit(r,NUM_AP_SCALAR); if (bound_infty(b)) ap_scalar_set_infty(r,1); else { switch (NUM_AP_SCALAR) { case AP_SCALAR_DOUBLE: if (!double_set_num(&r->val.dbl,bound_numref(b)) || div2) pr->conv = 1; if (div2) r->val.dbl /= 2; break; case AP_SCALAR_MPQ: if (!mpq_set_num(r->val.mpq,bound_numref(b)) || div2) pr->conv = 1; if (div2) mpq_div_2exp(r->val.mpq,r->val.mpq,1); break; case AP_SCALAR_MPFR: if (!mpfr_set_num(r->val.mpfr,bound_numref(b)) || div2) pr->conv = 1; if (div2) mpfr_div_2ui(r->val.mpfr,r->val.mpfr,1,GMP_RNDU); break; default: abort(); } } } /* opposite of lower bound => scalar, with optional division by 2 pr->conv is set if the conversion is not exact */ static inline void scalar_of_lower_bound(oct_internal_t* pr, ap_scalar_t* r, bound_t b, bool div2) { ap_scalar_reinit(r,NUM_AP_SCALAR); if (bound_infty(b)) ap_scalar_set_infty(r,-1); else { switch (NUM_AP_SCALAR) { case AP_SCALAR_DOUBLE: if (!double_set_num(&r->val.dbl,bound_numref(b)) || div2) pr->conv = 1; if (div2) r->val.dbl /= 2; r->val.dbl = -r->val.dbl; break; case AP_SCALAR_MPQ: if (!mpq_set_num(r->val.mpq,bound_numref(b)) || div2) pr->conv = 1; if (div2) mpq_div_2exp(r->val.mpq,r->val.mpq,1); mpq_neg(r->val.mpq,r->val.mpq); break; case AP_SCALAR_MPFR: if (!mpfr_set_num(r->val.mpfr,bound_numref(b)) || div2) pr->conv = 1; if (div2) mpfr_div_2ui(r->val.mpfr,r->val.mpfr,1,GMP_RNDU); mpfr_neg(r->val.mpfr,r->val.mpfr,GMP_RNDD); break; default: abort(); } } } /* makes an interval from [-minf,sup], with sound approximations pr->conv is set if the conversion is not exact note: may output an empty interval */ static inline void interval_of_bounds(oct_internal_t* pr, ap_interval_t* i, bound_t minf, bound_t sup, bool div2) { scalar_of_upper_bound(pr,i->sup, sup,div2); scalar_of_lower_bound(pr,i->inf,minf,div2); } /* ============================================================ */ /* III.4 Bound manipulations */ /* ============================================================ */ /* [-r_inf,r_sup] = [-a_inf,a_sup] * [-b_inf,b_sup] where 0 * oo = oo * 0 = 0 */ static inline void bounds_mul(bound_t r_inf, bound_t r_sup, bound_t a_inf, bound_t a_sup, bound_t b_inf, bound_t b_sup, bound_t tmp[8]) { bound_mul(tmp[0],a_sup,b_sup); bound_neg(tmp[4],a_sup); bound_mul(tmp[4],tmp[4],b_sup); bound_mul(tmp[1],a_inf,b_inf); bound_neg(tmp[5],a_inf); bound_mul(tmp[5],tmp[5],b_inf); bound_mul(tmp[6],a_sup,b_inf); bound_neg(tmp[2],a_sup); bound_mul(tmp[2],tmp[2],b_inf); bound_mul(tmp[7],a_inf,b_sup); bound_neg(tmp[3],a_inf); bound_mul(tmp[3],tmp[3],b_sup); bound_max(r_sup,tmp[0],tmp[1]); bound_max(r_sup,r_sup,tmp[2]); bound_max(r_sup,r_sup,tmp[3]); bound_max(r_inf,tmp[4],tmp[5]); bound_max(r_inf,r_inf,tmp[6]); bound_max(r_inf,r_inf,tmp[7]); } /* ============================================================ */ /* III.5 Conversion to constraints */ /* ============================================================ */ /* constraint at line i, column j, with upper bound m */ static inline ap_lincons0_t lincons_of_bound(oct_internal_t* pr, size_t i, size_t j, bound_t m) { ap_linexpr0_t* e; if (i==j) { /* zeroary constraint */ e = ap_linexpr0_alloc(AP_LINEXPR_SPARSE, 0); scalar_of_upper_bound(pr,e->cst.val.scalar,m,true); } else if (i==(j^1)) { /* unary constraint */ e = ap_linexpr0_alloc(AP_LINEXPR_SPARSE, 1); e->p.linterm[0].dim = i/2; ap_scalar_set_int(e->p.linterm[0].coeff.val.scalar,(i&1) ? -1 : 1); scalar_of_upper_bound(pr,e->cst.val.scalar,m,true); } else { /* binary constraint */ e = ap_linexpr0_alloc(AP_LINEXPR_SPARSE, 2); e->p.linterm[0].dim = j/2; e->p.linterm[1].dim = i/2; ap_scalar_set_int(e->p.linterm[0].coeff.val.scalar,(j&1) ? 1 : -1); ap_scalar_set_int(e->p.linterm[1].coeff.val.scalar,(i&1) ? -1 : 1); scalar_of_upper_bound(pr,e->cst.val.scalar,m,false); } return ap_lincons0_make(AP_CONS_SUPEQ,e,NULL); } /* ============================================================ */ /* III.5 Expression classification */ /* ============================================================ */ /* see oct_transfer.c */ typedef struct { enum { EMPTY, /* empty domain */ ZERO, /* 0 */ UNARY, /* unary unit expression */ BINARY, /* binary unit expression */ OTHER, } type; /* index and coefficient for unary / binary unit expressions */ size_t i,j; int coef_i,coef_j; /* -1 or 1 */ } uexpr; /* convert expression to bounds, look for unit unary or binary form */ uexpr oct_uexpr_of_linexpr(oct_internal_t* pr, bound_t* dst, ap_linexpr0_t* e, size_t dim); /* ********************************************************************** */ /* IV. Octagons */ /* ********************************************************************** */ /* ============================================================ */ /* IV.1 Internal Representation */ /* ============================================================ */ struct _oct_t { bound_t* m; /* contraint half-matrix (or NULL) */ bound_t* closed; /* closed version of m (or NULL for not available) */ size_t dim; /* total number of variables */ size_t intdim; /* the first intdim variables are integer ones */ }; /* several cases are possible m==NULL closed==NULL -- definitively empty octagon m!=NULL closed==NULL -- empty or non-empty octagon, closure not available m==NULL closed!=NULL \_ definitively non-empty octagon, closure available m!=NULL closed!=NULL / */ /* ============================================================ */ /* IV.2 Management */ /* ============================================================ */ oct_t* oct_alloc_internal (oct_internal_t* pr, size_t dim, size_t intdim); void oct_free_internal (oct_internal_t* pr, oct_t* o); oct_t* oct_copy_internal (oct_internal_t* pr, oct_t* o); void oct_cache_closure (oct_internal_t* pr, oct_t* a); void oct_close (oct_internal_t* pr, oct_t* a); oct_t* oct_set_mat (oct_internal_t* pr, oct_t* a, bound_t* m, bound_t* closed, bool destructive); oct_t* oct_alloc_top (oct_internal_t* pr, size_t dim, size_t intdim); #ifdef __cplusplus } #endif #endif /* __OCT_INTERNAL_H */ apron-dist-0.9.10/apron/octagons/testall.sh0000750014525101416610000000042511005654323020507 0ustar bjeannetpopart#!/bin/bash make all || exit mv log log.old echo "Test started `date`"| tee log for i in Il Ill MPZ Ri Rll MPQ D Dl MPFR do echo "Test for $i `date`" | tee -a log ./octtest$i +120 2>&1 | tee -a log done echo "Test finished at `date`"| tee -a log grep error log apron-dist-0.9.10/apron/octagons/oct_caml.c0000640014525101416610000003457511252216517020446 0ustar bjeannetpopart/* File generated from oct.idl */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #include "oct.h" #include "apron_caml.h" #define I0_CHECK_EXC(man) if (man->result.exn!=AP_EXC_NONE){ value v = camlidl_c2ml_manager_struct_ap_exclog_t(man->result.exclog,_ctx); caml_raise_with_arg(*caml_named_value("apron exception"),v); } typedef struct oct_internal_t* internal_ptr; extern void camlidl_apron_scalar_ml2c(value, ap_scalar_t *); #define camlidl_ml2c_scalar_ap_scalar_t(v,c,ctx) camlidl_apron_scalar_ml2c(v,c) extern value camlidl_apron_scalar_c2ml(ap_scalar_t *); #define camlidl_c2ml_scalar_ap_scalar_t(c,ctx) camlidl_apron_scalar_c2ml(c) extern void camlidl_ml2c_scalar_ap_scalar_ptr(value, ap_scalar_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_ap_scalar_ptr(ap_scalar_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_scalar_struct_ap_scalar_array_t(value, struct ap_scalar_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_struct_ap_scalar_array_t(struct ap_scalar_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_t(value, struct ap_interval_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_t(struct ap_interval_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_ap_interval_ptr(value, ap_interval_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_ap_interval_ptr(ap_interval_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_array_t(value, struct ap_interval_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_array_t(struct ap_interval_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_coeff_struct_ap_coeff_t(value, struct ap_coeff_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_coeff_struct_ap_coeff_t(struct ap_coeff_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_ap_dim_t(value, ap_dim_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_ap_dim_t(ap_dim_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimchange_t(value, struct ap_dimchange_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange_t(struct ap_dimchange_t *, camlidl_ctx _ctx); extern void camlidl_apron_dimchange_ml2c(value, ap_dimchange_t *); #define camlidl_ml2c_dim_ap_dimchange_t(v,c,ctx) camlidl_apron_dimchange_ml2c(v,c) extern value camlidl_apron_dimchange_c2ml(ap_dimchange_t *); #define camlidl_c2ml_dim_ap_dimchange_t(c,ctx) camlidl_apron_dimchange_c2ml(c) extern void camlidl_ml2c_dim_struct_ap_dimchange2_t(value, struct ap_dimchange2_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange2_t(struct ap_dimchange2_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimperm_t(value, struct ap_dimperm_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimperm_t(struct ap_dimperm_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimension_t(value, struct ap_dimension_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimension_t(struct ap_dimension_t *, camlidl_ctx _ctx); extern void camlidl_apron_linexpr0_ptr_ml2c(value, ap_linexpr0_ptr *); #define camlidl_ml2c_linexpr0_ap_linexpr0_ptr(v,c,ctx) camlidl_apron_linexpr0_ptr_ml2c(v,c) extern value camlidl_apron_linexpr0_ptr_c2ml(ap_linexpr0_ptr *); #define camlidl_c2ml_linexpr0_ap_linexpr0_ptr(c,ctx) camlidl_apron_linexpr0_ptr_c2ml(c) extern int camlidl_ml2c_generator0_enum_gentyp(value); extern value camlidl_c2ml_generator0_enum_gentyp(int); extern int camlidl_transl_table_generator0_enum_gentyp[]; extern void camlidl_ml2c_generator0_struct_ap_generator0_t(value, struct ap_generator0_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_generator0_struct_ap_generator0_t(struct ap_generator0_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_generator0_struct_ap_generator0_array_t(value, struct ap_generator0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_generator0_struct_ap_generator0_array_t(struct ap_generator0_array_t *, camlidl_ctx _ctx); extern void camlidl_apron_lincons0_ml2c(value, ap_lincons0_t *); #define camlidl_ml2c_lincons0_ap_lincons0_t(v,c,ctx) camlidl_apron_lincons0_ml2c(v,c) extern value camlidl_apron_lincons0_c2ml(ap_lincons0_t *); #define camlidl_c2ml_lincons0_ap_lincons0_t(c,ctx) camlidl_apron_lincons0_c2ml(c) extern void camlidl_ml2c_lincons0_struct_ap_lincons0_array_t(value, struct ap_lincons0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_lincons0_struct_ap_lincons0_array_t(struct ap_lincons0_array_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr0_ptr_ml2c(value, ap_texpr0_ptr *); #define camlidl_ml2c_texpr0_ap_texpr0_ptr(v,c,ctx) camlidl_apron_texpr0_ptr_ml2c(v,c) extern value camlidl_apron_texpr0_ptr_c2ml(ap_texpr0_ptr *); #define camlidl_c2ml_texpr0_ap_texpr0_ptr(c,ctx) camlidl_apron_texpr0_ptr_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_op_t(value, ap_texpr_op_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_op_t(ap_texpr_op_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_unop_t_ml2c(value, ap_texpr_unop_t *); #define camlidl_ml2c_texpr0_ap_texpr_unop_t(v,c,ctx) camlidl_apron_texpr_unop_t_ml2c(v,c) extern value camlidl_apron_texpr_unop_t_c2ml(ap_texpr_unop_t *); #define camlidl_c2ml_texpr0_ap_texpr_unop_t(c,ctx) camlidl_apron_texpr_unop_t_c2ml(c) extern void camlidl_apron_texpr_binop_t_ml2c(value, ap_texpr_binop_t *); #define camlidl_ml2c_texpr0_ap_texpr_binop_t(v,c,ctx) camlidl_apron_texpr_binop_t_ml2c(v,c) extern value camlidl_apron_texpr_binop_t_c2ml(ap_texpr_binop_t *); #define camlidl_c2ml_texpr0_ap_texpr_binop_t(c,ctx) camlidl_apron_texpr_binop_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rtype_t(value, ap_texpr_rtype_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rtype_t(ap_texpr_rtype_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_rtype_t_ml2c(value, ap_texpr_rtype_t *); #define camlidl_ml2c_texpr0_ap_texpr_rtype_t(v,c,ctx) camlidl_apron_texpr_rtype_t_ml2c(v,c) extern value camlidl_apron_texpr_rtype_t_c2ml(ap_texpr_rtype_t *); #define camlidl_c2ml_texpr0_ap_texpr_rtype_t(c,ctx) camlidl_apron_texpr_rtype_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rdir_t(value, ap_texpr_rdir_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rdir_t(ap_texpr_rdir_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_rdir_t_ml2c(value, ap_texpr_rdir_t *); #define camlidl_ml2c_texpr0_ap_texpr_rdir_t(v,c,ctx) camlidl_apron_texpr_rdir_t_ml2c(v,c) extern value camlidl_apron_texpr_rdir_t_c2ml(ap_texpr_rdir_t *); #define camlidl_c2ml_texpr0_ap_texpr_rdir_t(c,ctx) camlidl_apron_texpr_rdir_t_c2ml(c) extern void camlidl_apron_tcons0_ml2c(value, ap_tcons0_t *); #define camlidl_ml2c_tcons0_ap_tcons0_t(v,c,ctx) camlidl_apron_tcons0_ml2c(v,c) extern value camlidl_apron_tcons0_c2ml(ap_tcons0_t *); #define camlidl_c2ml_tcons0_ap_tcons0_t(c,ctx) camlidl_apron_tcons0_c2ml(c) extern void camlidl_ml2c_tcons0_struct_ap_tcons0_array_t(value, struct ap_tcons0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_tcons0_struct_ap_tcons0_array_t(struct ap_tcons0_array_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_funid_ml2c(value, ap_funid_t *); #define camlidl_ml2c_manager_ap_funid_t(v,c,ctx) camlidl_apron_manager_funid_ml2c(v,c) extern value camlidl_apron_manager_funid_c2ml(ap_funid_t *); #define camlidl_c2ml_manager_ap_funid_t(c,ctx) camlidl_apron_manager_funid_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_funopt_t(value, struct ap_funopt_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_funopt_t(struct ap_funopt_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_exc_ml2c(value, ap_exc_t *); #define camlidl_ml2c_manager_ap_exc_t(v,c,ctx) camlidl_apron_manager_exc_ml2c(v,c) extern value camlidl_apron_manager_exc_c2ml(ap_exc_t *); #define camlidl_c2ml_manager_ap_exc_t(c,ctx) camlidl_apron_manager_exc_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_exclog_t(value, struct ap_exclog_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_exclog_t(struct ap_exclog_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_ptr_ml2c(value, ap_manager_ptr *); #define camlidl_ml2c_manager_ap_manager_ptr(v,c,ctx) camlidl_apron_manager_ptr_ml2c(v,c) extern value camlidl_apron_manager_ptr_c2ml(ap_manager_ptr *); #define camlidl_c2ml_manager_ap_manager_ptr(c,ctx) camlidl_apron_manager_ptr_c2ml(c) extern void camlidl_apron_abstract0_ptr_ml2c(value, ap_abstract0_ptr *); #define camlidl_ml2c_abstract0_ap_abstract0_ptr(v,c,ctx) camlidl_apron_abstract0_ptr_ml2c(v,c) extern value camlidl_apron_abstract0_ptr_c2ml(ap_abstract0_ptr *); #define camlidl_c2ml_abstract0_ap_abstract0_ptr(c,ctx) camlidl_apron_abstract0_ptr_c2ml(c) void camlidl_ml2c_oct_internal_ptr(value _v1, internal_ptr * _c2, camlidl_ctx _ctx) { *_c2 = *((internal_ptr *) Bp_val(_v1)); } value camlidl_c2ml_oct_internal_ptr(internal_ptr * _c2, camlidl_ctx _ctx) { value _v1; _v1 = camlidl_alloc((sizeof(internal_ptr) + sizeof(value) - 1) / sizeof(value), Abstract_tag); *((internal_ptr *) Bp_val(_v1)) = *_c2; return _v1; } value camlidl_oct_oct_manager_alloc(value _unit) { ap_manager_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; _res = oct_manager_alloc(); _vres = camlidl_c2ml_manager_ap_manager_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_oct_manager_get_internal( value _v_man) { ap_manager_ptr man; /*in*/ internal_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); /* begin user-supplied calling sequence */ _res = (internal_ptr)man->internal; /* end user-supplied calling sequence */ _vres = camlidl_c2ml_oct_internal_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_oct_ap_abstract0_oct_of_generator_array( value _v_man, value _v_v1, value _v_v2, value _v_v3) { ap_manager_ptr man; /*in*/ int v1; /*in*/ int v2; /*in*/ struct ap_generator0_array_t *v3; /*in*/ ap_abstract0_ptr _res; struct ap_generator0_array_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); v1 = Int_val(_v_v1); v2 = Int_val(_v_v2); v3 = &_c1; camlidl_ml2c_generator0_struct_ap_generator0_array_t(_v_v3, &_c1, _ctx); _res = ap_abstract0_oct_of_generator_array(man, v1, v2, v3); _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ I0_CHECK_EXC(man) /* end user-supplied deallocation sequence */ return _vres; } value camlidl_oct_ap_abstract0_oct_widening_thresholds( value _v_man, value _v_a1, value _v_a2, value _v_array) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a1; /*in*/ ap_abstract0_ptr a2; /*in*/ struct ap_scalar_array_t array; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a1, &a1, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a2, &a2, _ctx); camlidl_ml2c_scalar_struct_ap_scalar_array_t(_v_array, &array, _ctx); /* begin user-supplied calling sequence */ _res = ap_abstract0_oct_widening_thresholds(man,a1,a2,(const ap_scalar_t**)array.p,array.size); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ I0_CHECK_EXC(man) /* end user-supplied deallocation sequence */ return _vres; } value camlidl_oct_ap_abstract0_oct_narrowing( value _v_man, value _v_a1, value _v_a2) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a1; /*in*/ ap_abstract0_ptr a2; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a1, &a1, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a2, &a2, _ctx); _res = ap_abstract0_oct_narrowing(man, a1, a2); _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ I0_CHECK_EXC(man) /* end user-supplied deallocation sequence */ return _vres; } value camlidl_oct_ap_abstract0_oct_add_epsilon( value _v_man, value _v_a, value _v_epsilon) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_scalar_ptr epsilon; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); camlidl_ml2c_scalar_ap_scalar_ptr(_v_epsilon, &epsilon, _ctx); _res = ap_abstract0_oct_add_epsilon(man, a, epsilon); _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ I0_CHECK_EXC(man) /* end user-supplied deallocation sequence */ return _vres; } value camlidl_oct_ap_abstract0_oct_add_epsilon_bin( value _v_man, value _v_a1, value _v_a2, value _v_epsilon) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a1; /*in*/ ap_abstract0_ptr a2; /*in*/ ap_scalar_ptr epsilon; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a1, &a1, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a2, &a2, _ctx); camlidl_ml2c_scalar_ap_scalar_ptr(_v_epsilon, &epsilon, _ctx); _res = ap_abstract0_oct_add_epsilon_bin(man, a1, a2, epsilon); _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ I0_CHECK_EXC(man) /* end user-supplied deallocation sequence */ return _vres; } apron-dist-0.9.10/apron/octagons/oct_nary.c0000640014525101416610000003040411232032174020457 0ustar bjeannetpopart/* * oct_nary.c * * N-ary octagon functions: meet, join, widening, narrowing & related. * * APRON Library / Octagonal Domain * * Copyright (C) Antoine Mine' 2006 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #include "oct.h" #include "oct_internal.h" /* ============================================================ */ /* Meet and Join */ /* ============================================================ */ oct_t* oct_meet(ap_manager_t* man, bool destructive, oct_t* a1, oct_t* a2) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_MEET,0); bound_t* m; arg_assert(a1->dim==a2->dim && a1->intdim==a2->intdim,return NULL;); if ((!a1->closed && !a1->m) || (!a2->closed && !a2->m)) /* one argument is empty */ return oct_set_mat(pr,a1,NULL,NULL,destructive); else { bound_t* m1 = a1->closed ? a1->closed : a1->m; bound_t* m2 = a2->closed ? a2->closed : a2->m; size_t i; m = destructive ? m1 : hmat_alloc(pr,a1->dim); for (i=0;idim);i++) bound_min(m[i],m1[i],m2[i]); /* optimal, but not closed */ return oct_set_mat(pr,a1,m,NULL,destructive); } } oct_t* oct_join(ap_manager_t* man, bool destructive, oct_t* a1, oct_t* a2) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_JOIN,0); arg_assert(a1->dim==a2->dim && a1->intdim==a2->intdim,return NULL;); if (pr->funopt->algorithm>=0) { oct_cache_closure(pr,a1); oct_cache_closure(pr,a2); } if (!a1->closed && !a1->m) { if (!a2->closed && !a2->m) /* both empty */ return oct_set_mat(pr,a1,NULL,NULL,destructive); else /* a1 empty, a2 not empty */ return oct_set_mat(pr,a1,hmat_copy(pr,a2->m,a2->dim), hmat_copy(pr,a2->closed,a2->dim),destructive); } else if (!a2->closed && !a2->m) /* a1 not empty, a2 empty */ return oct_set_mat(pr,a1,a1->m,a1->closed,destructive); else { /* not empty */ bound_t* m1 = a1->closed ? a1->closed : a1->m; bound_t* m2 = a2->closed ? a2->closed : a2->m; bound_t* m = destructive ? m1 : hmat_alloc(pr,a1->dim); size_t i; man->result.flag_exact = false; for (i=0;idim);i++) bound_max(m[i],m1[i],m2[i]); if (a1->closed && a2->closed) { /* result is closed and optimal on Q */ if (num_incomplete || a1->intdim) flag_incomplete; return oct_set_mat(pr,a1,NULL,m,destructive); } else { /* not optimal, not closed */ flag_algo; return oct_set_mat(pr,a1,m,NULL,destructive); } } } oct_t* oct_meet_array(ap_manager_t* man, oct_t** tab, size_t size) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_MEET_ARRAY,0); oct_t* r; size_t i,k; arg_assert(size>0,return NULL;); r = oct_alloc_internal(pr,tab[0]->dim,tab[0]->intdim); /* check whether there is an empty element */ for (k=0;km && !tab[k]->closed) return r; /* all elements are non-empty */ r->m = hmat_copy(pr,tab[0]->closed ? tab[0]->closed : tab[0]->m,r->dim); for (k=1;kclosed ? tab[k]->closed : tab[k]->m; arg_assert(tab[k]->dim==r->dim && tab[k]->intdim==r->intdim, oct_free_internal(pr,r);return NULL;); for (i=0;idim);i++) bound_bmin(r->m[i],x[i]); } return r; } oct_t* oct_join_array(ap_manager_t* man, oct_t** tab, size_t size) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_JOIN_ARRAY,0); int algo = pr->funopt->algorithm; bool closed = true; oct_t* r; bound_t* m = NULL; size_t i,k; arg_assert(size>0,return NULL;); r = oct_alloc_internal(pr,tab[0]->dim,tab[0]->intdim); for (k=0;kdim==r->dim && tab[k]->intdim==r->intdim, oct_free_internal(pr,r);return NULL;); if (algo>=0) oct_cache_closure(pr,tab[k]); /* skip definitely empty */ if (!tab[k]->m && !tab[k]->closed) continue; if (!m) /* first non-empty */ m = hmat_copy(pr,tab[k]->closed ? tab[k]->closed : tab[k]->m,r->dim); else { /* not first non-empty */ bound_t* x = tab[k]->closed ? tab[k]->closed : tab[k]->m; for (i=0;idim);i++) bound_max(m[i],m[i],x[i]); } if (!tab[k]->closed) closed = false; } if (!m) { /* empty result */ } else if (closed) { /* closed, optimal result, in Q */ man->result.flag_exact = false; r->closed = m; if (num_incomplete || r->intdim) flag_incomplete; } else { /* non closed, non optimal result */ r->m = m; flag_algo; } return r; } /* ============================================================ */ /* Widening, Narrowing */ /* ============================================================ */ oct_t* oct_widening(ap_manager_t* man, oct_t* a1, oct_t* a2) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_WIDENING,0); int algo = pr->funopt->algorithm; oct_t* r; arg_assert(a1->dim==a2->dim && a1->intdim==a2->intdim,return NULL;); if (algo>=0) oct_cache_closure(pr,a2); if (!a1->closed && !a1->m) /* a1 definitively closed */ r = oct_copy_internal(pr,a2); else if (!a2->closed && !a2->m) /* a2 definitively closed */ r = oct_copy_internal(pr,a1); else { /* work on the origial left matrix, not the closed cache! */ bound_t* m1 = a1->m ? a1->m : a1->closed; bound_t* m2 = a2->closed ? a2->closed : a2->m; size_t i; r = oct_alloc_internal(pr,a1->dim,a1->intdim); r->m = hmat_alloc(pr,r->dim); if (algo==oct_pre_widening || algo==-oct_pre_widening) { /* degenerate hull: NOT A PROPER WIDENING, use with care */ for (i=0;idim);i++) bound_max(r->m[i],m1[i],m2[i]); } else { /* standard widening */ for (i=0;idim);i++) if (bound_cmp(m1[i],m2[i])>=0) bound_set(r->m[i],m1[i]); else bound_set_infty(r->m[i],1); } } return r; } oct_t* oct_widening_thresholds(ap_manager_t* man, oct_t* a1, oct_t* a2, ap_scalar_t** array, size_t nb) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_WIDENING,nb+1); int algo = pr->funopt->algorithm; oct_t* r; arg_assert(a1->dim==a2->dim && a1->intdim==a2->intdim,return NULL;); if (algo>=0) oct_cache_closure(pr,a2); if (!a1->closed && !a1->m) /* a1 definitively closed */ r = oct_copy_internal(pr,a2); else if (!a2->closed && !a2->m) /* a2 definitively closed */ r = oct_copy_internal(pr,a1); else { /* work on the origial left matrix, not the closed cache! */ bound_t* m1 = a1->m ? a1->m : a1->closed; bound_t* m2 = a2->closed ? a2->closed : a2->m; size_t i; r = oct_alloc_internal(pr,a1->dim,a1->intdim); r->m = hmat_alloc(pr,r->dim); /* convert array to bounds */ for (i=0;itmp[i],array[i],false,false); bound_set_infty(pr->tmp[nb],1); /* point-wise loop */ for (i=0;idim);i++) if (bound_cmp(m1[i],m2[i])>=0) bound_set(r->m[i],m1[i]); else { #if 0 /* dichotomy on array */ size_t low=0, hi=nb; while (lowtmp[med],m2[i])<0) low=med+1; else hi=med; } bound_set(r->m[i],pr->tmp[low]); #else size_t j; for (j=0;jtmp[j])<=0) break; bound_set(r->m[i],pr->tmp[j]); #endif } /* warn user for conv errors in thresolds */ if (pr->conv) flag_conv; } return r; } oct_t* oct_narrowing(ap_manager_t* man, oct_t* a1, oct_t* a2) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_WIDENING,0); oct_t* r; arg_assert(a1->dim==a2->dim && a1->intdim==a2->intdim,return NULL;); if (pr->funopt->algorithm>=0) { oct_cache_closure(pr,a1); oct_cache_closure(pr,a2); } r = oct_alloc_internal(pr,a1->dim,a1->intdim); if ((!a1->closed && !a1->m) || (!a2->closed && !a2->m)) { /* a1 or a2 definitively closed */ } else { bound_t* m1 = a1->closed ? a1->closed : a1->m; bound_t* m2 = a2->closed ? a2->closed : a2->m; size_t i; r->m = hmat_alloc(pr,r->dim); for (i=0;idim);i++) bound_set(r->m[i], bound_infty(m1[i]) ? m2[i] : m1[i]); } return r; } ap_abstract0_t* ap_abstract0_oct_narrowing( ap_manager_t* man, ap_abstract0_t* a1, ap_abstract0_t* a2 ) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_WIDENING,0); oct_t* a = (oct_t*) (a1->value); arg_assert(man->library==a1->man->library && man->library==a2->man->library, return abstract0_of_oct(man,oct_alloc_top(pr,a->dim,a->intdim));); return abstract0_of_oct(man,oct_narrowing (man,a1->value,a2->value)); } ap_abstract0_t* ap_abstract0_oct_widening_thresholds(ap_manager_t* man, ap_abstract0_t* a1, ap_abstract0_t* a2, ap_scalar_t** array, size_t nb) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_WIDENING,0); oct_t* a = (oct_t*) (a1->value); arg_assert(man->library==a1->man->library && man->library==a2->man->library, return abstract0_of_oct(man,oct_alloc_top(pr,a->dim,a->intdim));); return abstract0_of_oct(man,oct_widening_thresholds (man,a1->value,a2->value,array,nb)); } /* ============================================================ */ /* Perturbation */ /* ============================================================ */ oct_t* oct_add_epsilon(ap_manager_t* man, oct_t* a, ap_scalar_t* epsilon) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_WIDENING,2); oct_t* r = oct_alloc_internal(pr,a->dim,a->intdim); bound_t* m; m = a->m ? a->m : a->closed; if (m) { size_t i; /* compute max of finite bounds */ bound_set_int(pr->tmp[0],0); for (i=0;idim);i++) { if (bound_infty(m[i])) continue; if (bound_sgn(m[i])>=0) bound_max(pr->tmp[0],pr->tmp[0],m[i]); else { bound_neg(pr->tmp[1],m[i]); bound_max(pr->tmp[0],pr->tmp[0],pr->tmp[1]); } } /* multiply by epsilon */ bound_of_scalar(pr,pr->tmp[1],epsilon,false,false); bound_mul(pr->tmp[0],pr->tmp[0],pr->tmp[1]); /* enlarge bounds */ r->m = hmat_alloc(pr,r->dim); for (i=0;idim);i++) bound_add(r->m[i],m[i],pr->tmp[0]); } return r; } ap_abstract0_t* ap_abstract0_oct_add_epsilon(ap_manager_t* man, ap_abstract0_t* a1, ap_scalar_t* epsilon) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_WIDENING,0); oct_t* a = (oct_t*) (a1->value); arg_assert(man->library==a1->man->library, return abstract0_of_oct(man,oct_alloc_top(pr,a->dim,a->intdim));); return abstract0_of_oct(man,oct_add_epsilon(man,a,epsilon)); } oct_t* oct_add_epsilon_bin(ap_manager_t* man, oct_t* a1, oct_t* a2, ap_scalar_t* epsilon) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_WIDENING,2); oct_t* r; arg_assert(a1->dim==a2->dim && a1->intdim==a2->intdim,return NULL;); if (!a1->closed && !a1->m) /* a1 definitely empty */ r = oct_copy_internal(pr,a2); else if (!a2->closed && !a2->m) /* a2 definitely empty */ r = oct_copy_internal(pr,a1); else { bound_t* m1 = a1->m ? a1->m : a1->closed; bound_t* m2 = a2->m ? a2->m : a2->closed; size_t i; r = oct_alloc_internal(pr,a1->dim,a1->intdim); r->m = hmat_alloc(pr,r->dim); /* get max abs of non +oo coefs in m2, times epsilon */ bound_set_int(pr->tmp[0],0); for (i=0;idim);i++) { if (bound_infty(m2[i])) continue; if (bound_sgn(m2[i])>=0) bound_max(pr->tmp[0],pr->tmp[0],m2[i]); else { bound_neg(pr->tmp[1],m2[i]); bound_max(pr->tmp[0],pr->tmp[0],pr->tmp[1]); } } /* multiply by epsilon */ bound_of_scalar(pr,pr->tmp[1],epsilon,false,false); bound_mul(pr->tmp[0],pr->tmp[0],pr->tmp[1]); /* enlarge unstable coefficients in a1 */ for (i=0;idim);i++) if (bound_cmp(m1[i],m2[i])<0) bound_add(r->m[i],m2[i],pr->tmp[0]); else bound_set(r->m[i],m1[i]); } return r; } ap_abstract0_t* ap_abstract0_oct_add_epsilon_bin(ap_manager_t* man, ap_abstract0_t* a1, ap_abstract0_t* a2, ap_scalar_t* epsilon) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_WIDENING,0); oct_t* a = (oct_t*) (a1->value); arg_assert(man->library==a1->man->library && man->library==a2->man->library, return abstract0_of_oct(man,oct_alloc_top(pr,a->dim,a->intdim));); return abstract0_of_oct(man,oct_add_epsilon_bin(man,a1->value,a2->value,epsilon)); } apron-dist-0.9.10/apron/octagons/mltest.ml0000640014525101416610000000113310573346463020354 0ustar bjeannetpopart(* mltest.ml * * A very simple example * * APRON Library / Octagonal Domain * * Copyright (C) Antoine Mine' 2007 *) (* compile with: ocamlc -I ${INSTALL_DIR}/lib \ gmp.cma apron.cma oct.cma mltest.ml \ -cclib -loctQg -cclib -lapron you can change: - INSTALL_DIR to where APRON is installed, - -loctQg to the desired underlying numeric type, - ocamlc to ocamlopt, and replace each .cma to the corresponding .cmxa *) open Apron let m = Oct.manager_alloc () let _ = Printf.printf "name: %s\nversion: %s\n" (Manager.get_library m) (Manager.get_version m) (* TO BE CONTINUED *) apron-dist-0.9.10/apron/octagons/oct.mli0000640014525101416610000001031211252216517017770 0ustar bjeannetpopart(* File generated from oct.idl *) type internal (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. *) (** Octagon abstract domain. *) type t (** Type of octagons. Octagons are defined by conjunctions of inequalities of the form [+/-x_i +/- x_j >= 0]. Abstract values which are octagons have the type [t Apron.AbstractX.t]. Managers allocated for octagons have the type [t Apron.manager.t]. *) (** Allocate a new manager to manipulate octagons. *) external manager_alloc : unit -> t Apron.Manager.t = "camlidl_oct_oct_manager_alloc" (** No internal parameters for now... *) external manager_get_internal : t Apron.Manager.t -> internal = "camlidl_oct_manager_get_internal" (** Approximate a set of generators to an abstract value, with best precision. *) external of_generator_array : t Apron.Manager.t -> int -> int -> Apron.Generator0.t array -> t Apron.Abstract0.t = "camlidl_oct_ap_abstract0_oct_of_generator_array" (** Widening with scalar thresholds. *) external widening_thresholds : t Apron.Manager.t -> t Apron.Abstract0.t -> t Apron.Abstract0.t -> Apron.Scalar.t array -> t Apron.Abstract0.t = "camlidl_oct_ap_abstract0_oct_widening_thresholds" (** Standard narrowing. *) external narrowing : t Apron.Manager.t -> t Apron.Abstract0.t -> t Apron.Abstract0.t -> t Apron.Abstract0.t = "camlidl_oct_ap_abstract0_oct_narrowing" (** Perturbation. *) external add_epsilon : t Apron.Manager.t -> t Apron.Abstract0.t -> Apron.Scalar.t -> t Apron.Abstract0.t = "camlidl_oct_ap_abstract0_oct_add_epsilon" (** Perturbation. *) external add_epsilon_bin : t Apron.Manager.t -> t Apron.Abstract0.t -> t Apron.Abstract0.t -> Apron.Scalar.t -> t Apron.Abstract0.t = "camlidl_oct_ap_abstract0_oct_add_epsilon_bin" (** Algorithms. *) val pre_widening : int (** {2 Type conversions} *) val manager_is_oct : 'a Apron.Manager.t -> bool (** Return [true] iff the argument manager is an octagon manager *) val manager_of_oct : t Apron.Manager.t -> 'a Apron.Manager.t (** Make an octagon manager generic *) val manager_to_oct : 'a Apron.Manager.t -> t Apron.Manager.t (** Instanciate the type of an octagon manager. Raises [Failure] if the argument manager is not an octagon manager *) module Abstract0 : sig val is_oct : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument value is an oct value *) val of_oct : t Apron.Abstract0.t -> 'a Apron.Abstract0.t (** Make an oct value generic *) val to_oct : 'a Apron.Abstract0.t -> t Apron.Abstract0.t (** Instanciate the type of an oct value. Raises [Failure] if the argument value is not an oct value *) end module Abstract1 : sig val is_oct : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument value is an oct value *) val of_oct : t Apron.Abstract1.t -> 'a Apron.Abstract1.t (** Make an oct value generic *) val to_oct : 'a Apron.Abstract1.t -> t Apron.Abstract1.t (** Instanciate the type of an oct value. Raises [Failure] if the argument value is not an oct value *) end (** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. {3 Bytecode compilation} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \ bigarray.cma gmp.cma apron.cma octD.cma mlexample.ml]} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \ bigarray.cma gmp.cma apron.cma octD.cma ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \ bigarray.cma gmp.cma apron.cma octD.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa octD.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa octD.cmxa mlexample.ml \ -cclib "-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib \ -loctD_caml_debug -loctD_debug \ -lapron_caml_debug -lapron_debug \ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP_PREFIX/lib -lgmp \ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \ -lbigarray" ]} *) apron-dist-0.9.10/apron/octagons/COPYING0000640014525101416610000006371710452747432017562 0ustar bjeannetpopart This license applies to all files distributed in the original package, including all source code, libraries, binaries, and documentation GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! apron-dist-0.9.10/apron/octagons/oct.h0000640014525101416610000000524710573346463017462 0ustar bjeannetpopart/* * oct.h * * Public definitions. * The only file you need to include to use octagons. * * APRON Library / Octagonal Domain * * Copyright (C) Antoine Mine' 2006 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __OCT_H #define __OCT_H /* dependencies */ #include #include #include #include "ap_coeff.h" #include "ap_dimension.h" #include "ap_expr0.h" #include "ap_manager.h" #include "ap_abstract0.h" #ifdef __cplusplus extern "C" { #endif ap_manager_t* oct_manager_alloc(void); /* Creates a new manager for the octagon library. */ /* ============================================================ */ /* Supplementary functions & options */ /* ============================================================ */ ap_abstract0_t* ap_abstract0_oct_of_generator_array(ap_manager_t* man, size_t intdim, size_t realdim, ap_generator0_array_t* array); ap_abstract0_t* ap_abstract0_oct_widening_thresholds(ap_manager_t* man, ap_abstract0_t* a1, ap_abstract0_t* a2, ap_scalar_t** arr, size_t nb ); /* Widening with threshold. array is assumed to contain nb thresholds, sorted in increasing order. */ ap_abstract0_t* ap_abstract0_oct_narrowing( ap_manager_t* man, ap_abstract0_t* a1, ap_abstract0_t* a2 ); /* Standard narrowing: refine only +oo constraint */ static const int oct_pre_widening = 99; /* Not a widening, but a degenerate hull (precisely, a hull without closure of the left argument). It is tantalizing to interleave widenings and hulls to improve the precision of fix-point computations but, unfortunately, this destroys the converge property and makes analyses loop forever. This PRE-WIDENING is a middle-ground. It does not ensure convergence by itself, but can be safely interleaved with widenings. As long as proper widenings occur infinitely often, the interleaved sequence will converge. Also, it converges more slowly, and so, gives a better precision. */ ap_abstract0_t* ap_abstract0_oct_add_epsilon(ap_manager_t* man, ap_abstract0_t* a, ap_scalar_t* epsilon); /* Enlarge each bound by epsilon times the maximum finite bound in the octagon */ ap_abstract0_t* ap_abstract0_oct_add_epsilon_bin(ap_manager_t* man, ap_abstract0_t* a1, ap_abstract0_t* a2, ap_scalar_t* epsilon); /* Enlarge each bound from a1 by epsilon times the maximum finite bound in a2. Only those bounds in a1 that are not stable in a2 are enlared. */ #ifdef __cplusplus } #endif #endif /* __OCT_H */ apron-dist-0.9.10/apron/octagons/oct.idl0000640014525101416610000001476211251674650020001 0ustar bjeannetpopart/* -*- mode: c -*- */ /* * oct.idl * * OCaml interface specification for camlidl * * APRON Library / Octagonal Domain * * Copyright (C) Antoine Mine' 2006 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ quote(C,"/*\n This file is part of the APRON Library, released under LGPL license.\n Please read the COPYING file packaged in the distribution.\n*/") quote(MLMLI,"(*\n This file is part of the APRON Library, released under LGPL license.\n Please read the COPYING file packaged in the distribution.\n*)") quote(MLI,"\n \n(** Octagon abstract domain. *)\n \n") quote(C,"#include \"oct.h\"") quote(C,"#include \"apron_caml.h\"") quote(C,"#define I0_CHECK_EXC(man) if (man->result.exn!=AP_EXC_NONE){ value v = camlidl_c2ml_manager_struct_ap_exclog_t(man->result.exclog,_ctx); caml_raise_with_arg(*caml_named_value(\"apron exception\"),v); } ") quote(C,"typedef struct oct_internal_t* internal_ptr;") import "generator0.idl"; import "abstract0.idl"; import "scalar.idl"; import "manager.idl"; typedef [abstract] struct oct_internal_t* internal_ptr; quote(MLMLI,"\n \n\ type t\n\ (** Type of octagons.\n\n\ Octagons are defined by conjunctions of inequalities of the form\n\ [+/-x_i +/- x_j >= 0].\n\n\ Abstract values which are octagons have the type [t Apron.AbstractX.t].\n\n\ Managers allocated for octagons have the type [t Apron.manager.t].\n\ *)\n\n \ ") quote(MLI,"(** Allocate a new manager to manipulate octagons. *)") ap_manager_ptr oct_manager_alloc(void); quote(MLI,"(** No internal parameters for now... *)") internal_ptr manager_get_internal(ap_manager_ptr man) quote(call,"_res = (internal_ptr)man->internal;"); quote(MLI,"(** Approximate a set of generators to an abstract value, with best precision. *)") ap_abstract0_ptr ap_abstract0_oct_of_generator_array(ap_manager_ptr man, int v1, int v2, [ref]struct ap_generator0_array_t* v3) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Widening with scalar thresholds. *)") ap_abstract0_ptr ap_abstract0_oct_widening_thresholds(ap_manager_ptr man,ap_abstract0_ptr a1,ap_abstract0_ptr a2,struct ap_scalar_array_t array) quote(call,"_res = ap_abstract0_oct_widening_thresholds(man,a1,a2,(const ap_scalar_t**)array.p,array.size);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Standard narrowing. *)") ap_abstract0_ptr ap_abstract0_oct_narrowing(ap_manager_ptr man, ap_abstract0_ptr a1,ap_abstract0_ptr a2) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Perturbation. *)") ap_abstract0_ptr ap_abstract0_oct_add_epsilon(ap_manager_ptr man,ap_abstract0_ptr a,ap_scalar_ptr epsilon) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Perturbation. *)") ap_abstract0_ptr ap_abstract0_oct_add_epsilon_bin(ap_manager_ptr man,ap_abstract0_ptr a1,ap_abstract0_ptr a2,ap_scalar_ptr epsilon) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Algorithms. *)") const int pre_widening = 99; quote(MLI,"\n(** {2 Type conversions} *) val manager_is_oct : 'a Apron.Manager.t -> bool (** Return [true] iff the argument manager is an octagon manager *) val manager_of_oct : t Apron.Manager.t -> 'a Apron.Manager.t (** Make an octagon manager generic *) val manager_to_oct : 'a Apron.Manager.t -> t Apron.Manager.t (** Instanciate the type of an octagon manager. Raises [Failure] if the argument manager is not an octagon manager *) module Abstract0 : sig val is_oct : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument value is an oct value *) val of_oct : t Apron.Abstract0.t -> 'a Apron.Abstract0.t (** Make an oct value generic *) val to_oct : 'a Apron.Abstract0.t -> t Apron.Abstract0.t (** Instanciate the type of an oct value. Raises [Failure] if the argument value is not an oct value *) end module Abstract1 : sig val is_oct : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument value is an oct value *) val of_oct : t Apron.Abstract1.t -> 'a Apron.Abstract1.t (** Make an oct value generic *) val to_oct : 'a Apron.Abstract1.t -> t Apron.Abstract1.t (** Instanciate the type of an oct value. Raises [Failure] if the argument value is not an oct value *) end ") quote(ML," let manager_is_oct man = let str = Apron.Manager.get_library man in (String.compare str \"oct\")==0 let manager_of_oct (man:t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_oct (man:'a Apron.Manager.t) : t Apron.Manager.t = if manager_is_oct man then Obj.magic man else failwith \"Oct.manager_to_oct: the argument manager is not an Oct manager\" module Abstract0 = struct let is_oct abs = manager_is_oct (Apron.Abstract0.manager abs) let of_oct (abs: t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let to_oct (abs:'a Apron.Abstract0.t) : t Apron.Abstract0.t = if is_oct abs then Obj.magic abs else failwith \"Oct.Abstract0.to_oct: the argument value is not an oct value\" end module Abstract1 = struct let is_oct abs = manager_is_oct (Apron.Abstract1.manager abs) let of_oct (abs: t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let to_oct (abs:'a Apron.Abstract1.t) : t Apron.Abstract1.t = if is_oct abs then Obj.magic abs else failwith \"Oct.Abstract1.to_oct: the argument value is not an oct value\" end ") quote(MLI,"\n(** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. {3 Bytecode compilation} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma octD.cma mlexample.ml]} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \\ bigarray.cma gmp.cma apron.cma octD.cma ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma octD.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa octD.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa octD.cmxa mlexample.ml \\ -cclib \"-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib \\ -loctD_caml_debug -loctD_debug \\ -lapron_caml_debug -lapron_debug \\ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP_PREFIX/lib -lgmp \\ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \\ -lbigarray\" ]} *)") apron-dist-0.9.10/apron/octagons/oct_transfer.c0000640014525101416610000010573411005654323021347 0ustar bjeannetpopart/* * oct_transfer.c * * Assignment, substitution, guard transfer functions. * * APRON Library / Octagonal Domain * * Copyright (C) Antoine Mine' 2006 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #include "oct.h" #include "oct_internal.h" #include "ap_generic.h" /* ============================================================ */ /* Expression classification */ /* ============================================================ */ uexpr oct_uexpr_of_linexpr(oct_internal_t* pr, bound_t* dst, ap_linexpr0_t* e, size_t dim) { #define CLASS_COEFF(idx,coef) \ if (!bound_cmp_int(dst[2*idx+2],-coef) && \ !bound_cmp_int(dst[2*idx+3],coef)) { \ if (u.type==ZERO) { u.type = UNARY; u.i = idx; u.coef_i = coef; } \ else { u.type = BINARY; u.j = idx; u.coef_j = coef; } \ continue; \ } #define CLASS_VAR(idx) \ if (u.type==EMPTY) continue; \ if (!bound_sgn(dst[2*idx+2]) && !bound_sgn(dst[2*idx+3])) continue; \ if (u.type>=BINARY) { u.type = OTHER; continue; } \ CLASS_COEFF(idx,1); \ CLASS_COEFF(idx,-1); \ u.type = OTHER; uexpr u = { ZERO, 0, 0, 0, 0 }; size_t i; if (bounds_of_coeff(pr,dst[0],dst[1],e->cst,false)) u.type = EMPTY; switch (e->discr) { case AP_LINEXPR_DENSE: arg_assert(e->size<=dim,return u;); for (i=0;isize;i++) { if (bounds_of_coeff(pr,dst[2*i+2],dst[2*i+3],e->p.coeff[i],false)) u.type = EMPTY; CLASS_VAR(i); } for (;isize;i++) { size_t d = e->p.linterm[i].dim; arg_assert(dp.linterm[i].coeff,false)) u.type = EMPTY; CLASS_VAR(d); } break; default: arg_assert(0,return u;); } return u; } /* for debugging */ static void print_uexpr(uexpr u, bound_t* dst, size_t dim) { size_t i; printf("[-"); bound_print(dst[0]); printf(","); bound_print(dst[1]); printf("]"); for (i=0;i= 0 "); switch (u.type) { case ZERO: printf(" zeroary\n"); break; case UNARY: printf(" unary v%i=%i\n",(int)u.i,u.coef_i); break; case BINARY: printf(" binary v%i=%i v%i=%i\n",(int)u.i,u.coef_i,(int)u.j,u.coef_j); break; default: printf("\n"); } fflush(stdout); } /* ============================================================ */ /* Adding constraints / generators */ /* ============================================================ */ /* set *exact to 1 if all all constraints are octagonal ones return true if empty */ bool hmat_add_lincons(oct_internal_t* pr, bound_t* b, size_t dim, ap_lincons0_array_t* ar, bool* exact, bool* respect_closure) { size_t i, j, k, ui, uj; size_t var_pending = 0; /* delay incremental closure as long as possible */ int closure_pending = 0; *exact = 1; for (i=0;isize;i++) { ap_constyp_t c = ar->p[i].constyp; uexpr u; switch (c) { /* skipped */ case AP_CONS_EQMOD: case AP_CONS_DISEQ: *exact = 0; continue; /* handled */ case AP_CONS_EQ: case AP_CONS_SUPEQ: case AP_CONS_SUP: break; /* error */ default: assert(0); } /* now handle ==, >=, > */ u = oct_uexpr_of_linexpr(pr,pr->tmp,ar->p[i].linexpr0,dim); switch (u.type) { case EMPTY: /* empty constraint: no added information */ break; case ZERO: if ((c==AP_CONS_SUPEQ && bound_sgn(pr->tmp[1])>=0) || /* [-a,b] >= 0 <=> b >= 0 */ (c==AP_CONS_SUP && bound_sgn(pr->tmp[1])>0) || /* [-a,b] > 0 <=> b > 0 */ (c==AP_CONS_EQ && bound_sgn(pr->tmp[0])>=0 && bound_sgn(pr->tmp[1])>=0) /* [-a,b] = 0 <=> a >= 0 && b >= 0 */ ) ; /* trivial */ else return true; /* unsatisfiable */ break; case UNARY: /* can we delay incremental closure further? */ if (*respect_closure && closure_pending && var_pending!=u.i) { if (hmat_close_incremental(b,dim,var_pending)) return true; } closure_pending = 1; var_pending = u.i; if (u.coef_i==1) ui = 2*u.i; else ui = 2*u.i+1; bound_mul_2(pr->tmp[0],pr->tmp[0]); bound_mul_2(pr->tmp[1],pr->tmp[1]); bound_bmin(b[matpos(ui,ui^1)],pr->tmp[1]); /* c_i X_i + [-a,b] >= 0 <=> -c_i X_i <= b */ if (c==AP_CONS_EQ) bound_bmin(b[matpos(ui^1,ui)],pr->tmp[0]); /* c_i X_i + [-a,b] <= 0 <=> c_i X_i <= a */ if (c==AP_CONS_SUP) *exact = 0; /* not exact for strict constraints */ break; case BINARY: /* can we delay incremental closure further? */ if (*respect_closure && closure_pending && var_pending!=u.i && var_pending!=u.j) { if (hmat_close_incremental(b,dim,var_pending)) return true; } closure_pending = 1; var_pending = (var_pending==u.j) ? u.j : u.i; if ( u.coef_i==1) ui = 2*u.i; else ui = 2*u.i+1; if ( u.coef_j==1) uj = 2*u.j; else uj = 2*u.j+1; bound_bmin(b[matpos2(uj,ui^1)],pr->tmp[1]); /* c_i X_i + c_j X_j + [-a,b] >= 0 <=> -c_i X_i - c_j X_j <= b */ if (c==AP_CONS_EQ) bound_bmin(b[matpos2(uj^1,ui)],pr->tmp[0]); /* c_i X_i + c_j X_j + [-a,b] <= 0 <=> c_i X_i + c_j X_j <= a */ if (c==AP_CONS_SUP) *exact = 0; /* not exact for strict constraints */ break; case OTHER: { /* general, approximated case */ bound_t tmpa, tmpb, Cb, cb; int Cinf = 0; /* number of infinite upper bounds */ size_t Cj1 = 0, Cj2 = 0; /* variable index with infinite bound */ int cinf = 0; /* number of infinite lower bounds */ size_t cj1 = 0, cj2 = 0; /* variable index with infinite bound */ *respect_closure = false; /* do not respect closure */ bound_init(tmpa); bound_init(tmpb); bound_init(Cb); bound_init(cb); /* compute 2 * upper bound, ignoring components leading to +oo */ bound_mul_2(cb,pr->tmp[0]); bound_mul_2(Cb,pr->tmp[1]); for (j=0;jtmp[2*j+2],pr->tmp[2*j+3], pr->tmp+2*(dim+1)); if (bound_infty(tmpa)) { cinf++; cj2 = cj1; cj1 = j; } else bound_badd(cb,tmpa); if (bound_infty(tmpb)) { Cinf++; Cj2 = Cj1; Cj1 = j; } else bound_badd(Cb,tmpb); } /* upper bound */ if (bound_infty(Cb)) ; else if (!Cinf) { /* no infinite bound: derive quadratic number of bounds */ for (j=0;jtmp[2*j+2],-1)<=0 && !bound_infty(b[matpos(2*j+1,2*j)])) { /* -x <= expr-x <= max(expr) - max x */ bound_sub(tmpa,Cb,b[matpos(2*j+1,2*j)]); uj = 2*j+1; } else if (bound_cmp_int(pr->tmp[2*j+3],-1)<=0 && !bound_infty(b[matpos(2*j,2*j+1)])) { /* x <= expr+x <= max(expr) - max(-x) */ bound_sub(tmpa,Cb,b[matpos(2*j,2*j+1)]); uj = 2*j; } else continue; for (k=j+1;ktmp[2*k+2],-1)<=0 && !bound_infty(b[matpos(2*k+1,2*k)])) { /* (+/-)x -y <= max(expr) - max((+/-)x) - max y */ bound_sub(tmpb,tmpa,b[matpos(2*k+1,2*k)]); bound_div_2(tmpb,tmpb); bound_bmin(b[matpos(2*k,uj)],tmpb); } else if (bound_cmp_int(pr->tmp[2*k+3],-1)<=0 && !bound_infty(b[matpos(2*k,2*k+1)])) { /* (+/-)x +y <= max(expr) - max((+/-)x) - max (-y) */ bound_sub(tmpb,tmpa,b[matpos(2*k,2*k+1)]); bound_div_2(tmpb,tmpb); bound_bmin(b[matpos(2*k+1,uj)],tmpb); } } } } else if (Cinf==1) { /* one infinite bound: derive linear number of bounds */ if (!bound_cmp_int(pr->tmp[2*Cj1+3],-1) && !bound_cmp_int(pr->tmp[2*Cj1+2], 1)) uj = 2*Cj1; else if (!bound_cmp_int(pr->tmp[2*Cj1+3], 1) && !bound_cmp_int(pr->tmp[2*Cj1+2],-1)) uj = 2*Cj1+1; else goto Cbrk; for (k=0;ktmp[2*k+2],-1)<=0 && !bound_infty(b[matpos(2*k+1,2*k)])) { /* (+/-)x -y <= max(expr) - max((+/-)x) - max y */ bound_sub(tmpb,Cb,b[matpos(2*k+1,2*k)]); bound_div_2(tmpb,tmpb); bound_bmin(b[matpos2(2*k,uj)],tmpb); } else if (bound_cmp_int(pr->tmp[2*k+3],-1)<=0 && !bound_infty(b[matpos(2*k,2*k+1)])) { /* (+/-)x +y <= max(expr) - max((+/-)x) - max (-y) */ bound_sub(tmpb,Cb,b[matpos(2*k,2*k+1)]); bound_div_2(tmpb,tmpb); bound_bmin(b[matpos2(2*k+1,uj)],tmpb); } } } else if (Cinf==2) { /* two infinite bounds: derive just one bound */ if (!bound_cmp_int(pr->tmp[2*Cj1+3],-1) && !bound_cmp_int(pr->tmp[2*Cj1+2], 1)) ui = 2*Cj1; else if (!bound_cmp_int(pr->tmp[2*Cj1+3], 1) && !bound_cmp_int(pr->tmp[2*Cj1+2],-1)) ui = 2*Cj1+1; else goto Cbrk; if (!bound_cmp_int(pr->tmp[2*Cj2+3],-1) && !bound_cmp_int(pr->tmp[2*Cj2+2], 1)) uj = 2*Cj2; else if (!bound_cmp_int(pr->tmp[2*Cj2+3], 1) && !bound_cmp_int(pr->tmp[2*Cj2+2],-1)) uj = 2*Cj2+1; else goto Cbrk; bound_div_2(tmpa,Cb); bound_bmin(b[matpos2(uj^1,ui)],tmpa); } /* if more than two infinite bounds: do nothing */ Cbrk: /* lower bound */ if (c==AP_CONS_EQ) { if (bound_infty(cb)) ; else if (!cinf) { for (j=0;jtmp[2*j+3],-1)<=0 && !bound_infty(b[matpos(2*j+1,2*j)])) { bound_sub(tmpa,cb,b[matpos(2*j+1,2*j)]); uj = 2*j+1; } else if (bound_cmp_int(pr->tmp[2*j+2],-1)<=0 && !bound_infty(b[matpos(2*j,2*j+1)])) { bound_sub(tmpa,cb,b[matpos(2*j,2*j+1)]); uj = 2*j; } else continue; for (k=j+1;ktmp[2*k+3],-1)<=0 && !bound_infty(b[matpos(2*k+1,2*k)])) { bound_sub(tmpb,tmpa,b[matpos(2*k+1,2*k)]); bound_div_2(tmpb,tmpb); bound_bmin(b[matpos(2*k,uj)],tmpb); } else if (bound_cmp_int(pr->tmp[2*k+2],-1)<=0 && !bound_infty(b[matpos(2*k,2*k+1)])) { bound_sub(tmpb,tmpa,b[matpos(2*k,2*k+1)]); bound_div_2(tmpb,tmpb); bound_bmin(b[matpos(2*k+1,uj)],tmpb); } } } } else if (cinf==1) { if (!bound_cmp_int(pr->tmp[2*cj1+2],-1) && !bound_cmp_int(pr->tmp[2*cj1+3], 1)) uj = 2*cj1; else if (!bound_cmp_int(pr->tmp[2*cj1+2], 1) && !bound_cmp_int(pr->tmp[2*cj1+3],-1)) uj = 2*cj1+1; else goto cbrk; for (k=0;ktmp[2*k+3],-1)<=0 && !bound_infty(b[matpos(2*k+1,2*k)])) { bound_sub(tmpb,cb,b[matpos(2*k+1,2*k)]); bound_div_2(tmpb,tmpb); bound_bmin(b[matpos2(2*k,uj)],tmpb); } else if (bound_cmp_int(pr->tmp[2*k+2],-1)<=0 && !bound_infty(b[matpos(2*k,2*k+1)])) { bound_sub(tmpb,cb,b[matpos(2*k,2*k+1)]); bound_div_2(tmpb,tmpb); bound_bmin(b[matpos2(2*k+1,uj)],tmpb); } } } else if (cinf==2) { if (!bound_cmp_int(pr->tmp[2*cj1+2],-1) && !bound_cmp_int(pr->tmp[2*cj1+3], 1)) ui = 2*cj1; else if (!bound_cmp_int(pr->tmp[2*cj1+2], 1) && !bound_cmp_int(pr->tmp[2*cj1+3],-1)) ui = 2*cj1+1; else goto cbrk; if (!bound_cmp_int(pr->tmp[2*cj2+2],-1) && !bound_cmp_int(pr->tmp[2*cj2+3], 1)) uj = 2*cj2; else if (!bound_cmp_int(pr->tmp[2*cj2+2], 1) && !bound_cmp_int(pr->tmp[2*cj2+3],-1)) uj = 2*cj2+1; else goto cbrk; bound_div_2(tmpa,cb); bound_bmin(b[matpos2(uj^1,ui)],tmpa); } } cbrk: bound_clear(tmpa); bound_clear(tmpb); bound_clear(Cb); bound_clear(cb); *exact = 0; } break; default: assert(0); } } /* apply pending incremental closure now */ if (*respect_closure && closure_pending) if (hmat_close_incremental(b,dim,var_pending)) return true; return false; } void hmat_add_generators(oct_internal_t* pr, bound_t* b, size_t dim, ap_generator0_array_t* ar) { uexpr u; size_t i,j,k; bound_t* bb; /* add vertices */ for (i=0;isize;i++) { if (ar->p[i].gentyp!=AP_GEN_VERTEX) continue; bounds_of_generator(pr,pr->tmp,ar->p[i].linexpr0,dim); for (bb=b,j=0;j<2*dim;j++) for (k=0;k<=(j|1);k++,bb++) { bound_add(pr->tmp[2*dim],pr->tmp[j],pr->tmp[k^1]); bound_max(*bb,*bb,pr->tmp[2*dim]); } } /* add others */ for (i=0;isize;i++) { switch (ar->p[i].gentyp) { /* rays */ case AP_GEN_RAY: case AP_GEN_RAYMOD: bounds_of_generator(pr,pr->tmp+2,ar->p[i].linexpr0,dim); for (bb=b,j=0;j<2*dim;j++) for (k=0;k<=(j|1);k++,bb++) { bound_add(pr->tmp[0],pr->tmp[2+(k^1)],pr->tmp[2+j]); if (bound_sgn(pr->tmp[0])>0) bound_set_infty(*bb,1); } break; /* lines */ case AP_GEN_LINE: case AP_GEN_LINEMOD: bounds_of_generator(pr,pr->tmp+2,ar->p[i].linexpr0,dim); for (bb=b,j=0;j<2*dim;j++) for (k=0;k<=(j|1);k++,bb++) { bound_add(pr->tmp[0],pr->tmp[2+(k^1)],pr->tmp[2+j]); bound_add(pr->tmp[1],pr->tmp[2+(j^1)],pr->tmp[2+k]); if (bound_sgn(pr->tmp[0])>0 || bound_sgn(pr->tmp[1])>0) bound_set_infty(*bb,1); } break; case AP_GEN_VERTEX: continue; /* already done */ default: assert(0); } } } /* ============================================================ */ /* Meet constraints and Join generators */ /* ============================================================ */ oct_t* oct_meet_lincons_array(ap_manager_t* man, bool destructive, oct_t* a, ap_lincons0_array_t* array) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_MEET_LINCONS_ARRAY,2*(a->dim+8)); if (!a->closed && !a->m) /* definitively empty */ return oct_set_mat(pr,a,NULL,NULL,destructive); else { bool exact, respect_closure; size_t i; bound_t* m = a->closed ? a->closed : a->m; /* can / should we try to respect closure */ respect_closure = (m==a->closed) && (pr->funopt->algorithm>=0); if (!destructive) m = hmat_copy(pr,m,a->dim); /* go */ if (hmat_add_lincons(pr,m,a->dim,array,&exact,&respect_closure)) { /* empty */ if (!destructive) hmat_free(pr,m,a->dim); return oct_set_mat(pr,a,NULL,NULL,destructive); } else { /* exact if octagonal constraints & no conversion error */ if (num_incomplete || !exact) flag_incomplete; else if (pr->conv) flag_conv; if (respect_closure) return oct_set_mat(pr,a,NULL,m,destructive); else return oct_set_mat(pr,a,m,NULL,destructive); } } } oct_t* oct_meet_tcons_array(ap_manager_t* man, bool destructive, oct_t* a, ap_tcons0_array_t* array) { return ap_generic_meet_intlinearize_tcons_array(man,destructive,a,array, NUM_AP_SCALAR, AP_LINEXPR_INTLINEAR, &oct_meet_lincons_array); } oct_t* oct_add_ray_array(ap_manager_t* man, bool destructive, oct_t* a, ap_generator0_array_t* array) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_ADD_RAY_ARRAY,2*(a->dim+2)); bound_t *m; if (pr->funopt->algorithm>=0) oct_cache_closure(pr,a); m = a->closed ? a->closed : a->m; if (!m) /* definitively empty */ return oct_set_mat(pr,a,NULL,NULL,destructive); else { size_t i; if (!destructive) m = hmat_copy(pr,m,a->dim); hmat_add_generators(pr,m,a->dim,array); /* result is best on Q if closed and no conversion errors */ man->result.flag_exact = false; if (num_incomplete || a->intdim) flag_incomplete; else if (!a->closed) flag_algo; else if (pr->conv) flag_conv; return oct_set_mat(pr,a,m,NULL,destructive); } } /* ============================================================ */ /* Assignement and Substitutions */ /* ============================================================ */ /* internal helper function: forget all about dimension d */ static inline void hmat_forget_var(bound_t* m, size_t dim, size_t d) { size_t k; for (k=0;k<2*d;k++) { bound_set_infty(m[matpos(2*d,k)],1); bound_set_infty(m[matpos(2*d+1,k)],1); } for (k=2*d+2;k<2*dim;k++) { bound_set_infty(m[matpos(k,2*d)],1); bound_set_infty(m[matpos(k,2*d+1)],1); } bound_set_infty(m[matpos(2*d,2*d+1)],1); bound_set_infty(m[matpos(2*d+1,2*d)],1); } /* internal helper function: apply assignment */ /* if *respect_closure=true, try to respect closure, when returning, *respect_closure=true only if this was possible */ static void hmat_assign(oct_internal_t* pr, uexpr u, bound_t* m, size_t dim, size_t d, bool* respect_closure) { size_t i,k; if (u.type==ZERO ) { /* X <- [-a,b], non-invertible */ if (*respect_closure) { /* 'respect closure' version */ for (k=0;k<2*d;k++) { bound_div_2(pr->tmp[2],m[matpos(k^1,k)]); bound_add(m[matpos(2*d,k)],pr->tmp[2],pr->tmp[0]); bound_add(m[matpos(2*d+1,k)],pr->tmp[2],pr->tmp[1]); } for (k=2*d+2;k<2*dim;k++) { bound_div_2(pr->tmp[2],m[matpos(k,k^1)]); bound_add(m[matpos(k,2*d)],pr->tmp[2],pr->tmp[1]); bound_add(m[matpos(k,2*d+1)],pr->tmp[2],pr->tmp[0]); } } else { /* plain version */ hmat_forget_var(m,dim,d); } bound_mul_2(m[matpos(2*d,2*d+1)],pr->tmp[0]); bound_mul_2(m[matpos(2*d+1,2*d)],pr->tmp[1]); } else if (u.type==UNARY && u.i!=d) { /* X <- c_i X_i + [-a,b], X_i!=X, non-invertible */ hmat_forget_var(m,dim,d); i = 2*u.i + (u.coef_i==1 ? 0 : 1); bound_set(m[matpos2(2*d,i)],pr->tmp[0]); bound_set(m[matpos2(i,2*d)],pr->tmp[1]); if (*respect_closure) hmat_close_incremental(m,dim,d); } else if (u.type==UNARY && u.coef_i==-1) { /* X <- - X + [-a,b], invertible */ /* always respect closure */ for (k=0;k<2*d;k++) { bound_set(pr->tmp[2],m[matpos(2*d,k)]); bound_add(m[matpos(2*d,k)],m[matpos(2*d+1,k)],pr->tmp[0]); bound_add(m[matpos(2*d+1,k)],pr->tmp[2],pr->tmp[1]); } for (k=2*d+2;k<2*dim;k++) { bound_set(pr->tmp[2],m[matpos(k,2*d)]); bound_add(m[matpos(k,2*d)],m[matpos(k,2*d+1)],pr->tmp[1]); bound_add(m[matpos(k,2*d+1)],pr->tmp[2],pr->tmp[0]); } bound_mul_2(pr->tmp[0],pr->tmp[0]); bound_mul_2(pr->tmp[1],pr->tmp[1]); bound_set(pr->tmp[2],m[matpos(2*d+1,2*d)]); bound_add(m[matpos(2*d+1,2*d)],m[matpos(2*d,2*d+1)],pr->tmp[1]); bound_add(m[matpos(2*d,2*d+1)],pr->tmp[2],pr->tmp[0]); } else if (u.type==UNARY && u.coef_i==1) { /* X <- X + [-a,b], invertible */ /* always respect closure */ for (k=0;k<2*d;k++) { bound_badd(m[matpos(2*d,k)],pr->tmp[0]); bound_badd(m[matpos(2*d+1,k)],pr->tmp[1]); } for (k=2*d+2;k<2*dim;k++) { bound_badd(m[matpos(k,2*d)],pr->tmp[1]); bound_badd(m[matpos(k,2*d+1)],pr->tmp[0]); } bound_mul_2(pr->tmp[0],pr->tmp[0]); bound_mul_2(pr->tmp[1],pr->tmp[1]); bound_badd(m[matpos(2*d+1,2*d)],pr->tmp[1]); bound_badd(m[matpos(2*d,2*d+1)],pr->tmp[0]); } else { /* general, approximated case */ bound_t tmpa, tmpb, Cb, cb; int Cinf = 0; /* number of infinite upper bounds */ int cinf = 0; /* number of infinite lower bounds */ size_t Ci = 0, ci = 0; /* variable index with infinite bound */ *respect_closure = false; /* does not respect closure */ bound_init(tmpa); bound_init(tmpb); bound_init(Cb); bound_init(cb); /* compute 2 * expression bounds, ignoring components leading to +oo */ bound_mul_2(cb,pr->tmp[0]); bound_mul_2(Cb,pr->tmp[1]); for (i=0;itmp[2*i+2],pr->tmp[2*i+3], pr->tmp+2*(dim+1)); if (bound_infty(tmpa)) { cinf++; ci = i; } else bound_badd(cb,tmpa); if (bound_infty(tmpb)) { Cinf++; Ci = i; } else bound_badd(Cb,tmpb); } hmat_forget_var(m,dim,d); /* upper bounds */ if (!Cinf) { /* no bound is infinite */ bound_set(m[matpos(2*d+1,2*d)],Cb); /* bound for x */ for (i=0;itmp[2*i+2],-1)<=0 && !bound_infty(m[matpos(2*i+1,2*i)])) { /* bound for x-y */ bound_sub(tmpa,Cb,m[matpos(2*i+1,2*i)]); bound_div_2(m[matpos2(2*i,2*d)],tmpa); } else if (bound_cmp_int(pr->tmp[2*i+3],-1)<=0 && !bound_infty(m[matpos(2*i,2*i+1)])) { /* bound for x+y */ bound_sub(tmpa,Cb,m[matpos(2*i,2*i+1)]); bound_div_2(m[matpos2(2*i+1,2*d)],tmpa); } } } else if (Cinf==1) { /* exactly one bound is infinite, X_d+/-X_Cinf may still be finite */ if (Ci!=d) { if (!bound_cmp_int(pr->tmp[2*i+3],1) && !bound_cmp_int(pr->tmp[2*i+2],-1)) bound_div_2(m[matpos2(2*Ci,2*d)],Cb); else if (!bound_cmp_int(pr->tmp[2*i+3],-1) && !bound_cmp_int(pr->tmp[2*i+2],1)) bound_div_2(m[matpos2(2*Ci+1,2*d)],Cb); } } /* lower bounds */ if (!cinf) { /* no bound is infinite */ bound_set(m[matpos(2*d,2*d+1)],cb); /* bound for -x */ for (i=0;itmp[2*i+2],-1)<=0 && !bound_infty(m[matpos(2*i,2*i+1)])) { /* bound for -x+y */ bound_sub(tmpa,cb,m[matpos(2*i,2*i+1)]); bound_div_2(m[matpos2(2*i+1,2*d+1)],tmpa); } else if (bound_cmp_int(pr->tmp[2*i+3],-1)<=0 && !bound_infty(m[matpos(2*i+1,2*i)])) { /* bound for -x-y */ bound_sub(tmpa,cb,m[matpos(2*i+1,2*i)]); bound_div_2(m[matpos2(2*i,2*d+1)],tmpa); } } } else if (cinf==1) { /* exactly one bound is infinite, -X_d+/-X_Cinf may still be finite */ if (ci!=d) { if (!bound_cmp_int(pr->tmp[2*i+3],1) && !bound_cmp_int(pr->tmp[2*i+2],-1)) bound_div_2(m[matpos2(2*d,2*ci)],cb); else if (!bound_cmp_int(pr->tmp[2*i+3],-1) && !bound_cmp_int(pr->tmp[2*i+2],1)) bound_div_2(m[matpos2(2*d,2*ci+1)],cb); } } bound_clear(tmpa); bound_clear(tmpb); bound_clear(Cb); bound_clear(cb); } } /* internal helper function: apply substitution, retrun true if empty */ static bool hmat_subst(oct_internal_t* pr, uexpr u, bound_t* m, size_t dim, size_t d, bound_t* dst, bool* respect_closure) { size_t i,k; if (u.type==ZERO ) { /* X -> [-a,b], non-invertible */ *respect_closure = false; /* TODO: does it respect closure? */ /* test satisfiability */ bound_mul_2(pr->tmp[2],pr->tmp[0]); bound_mul_2(pr->tmp[3],pr->tmp[1]); bound_add(pr->tmp[2],pr->tmp[2],m[matpos(2*d+1,2*d)]); bound_add(pr->tmp[3],pr->tmp[3],m[matpos(2*d,2*d+1)]); if (bound_sgn(pr->tmp[2])<0 || bound_sgn(pr->tmp[3])<0) return true; /* infer unary contraints cX from binary constraints on cX + c'Xd */ for (i=0;i<2*d;i++) { bound_add(pr->tmp[2],pr->tmp[0],m[matpos(2*d+1,i^1)]); bound_add(pr->tmp[3],pr->tmp[1],m[matpos(2*d,i^1)]); bound_mul_2(pr->tmp[2],pr->tmp[2]); bound_mul_2(pr->tmp[3],pr->tmp[3]); bound_bmin(m[matpos(i,i^1)],pr->tmp[2]); bound_bmin(m[matpos(i,i^1)],pr->tmp[3]); } for (i=2*d+2;i<2*dim;i++) { bound_add(pr->tmp[2],pr->tmp[0],m[matpos(i,2*d)]); bound_add(pr->tmp[3],pr->tmp[1],m[matpos(i,2*d+1)]); bound_mul_2(pr->tmp[2],pr->tmp[2]); bound_mul_2(pr->tmp[3],pr->tmp[3]); bound_bmin(m[matpos(i,i^1)],pr->tmp[2]); bound_bmin(m[matpos(i,i^1)],pr->tmp[3]); } hmat_forget_var(m,dim,d); return false; } else if (u.type==UNARY && u.i!=d) { k = u.i*2 + (u.coef_i==1 ? 0 : 1 ); /* X -> cX_i + [-a,b], X_i!=X, non-invertible */ *respect_closure = false; /* TODO: does it respect closure? */ /* test satisfiability */ bound_add(pr->tmp[2],pr->tmp[0],m[matpos2(k,2*d)]); bound_add(pr->tmp[3],pr->tmp[1],m[matpos2(2*d,k)]); if (bound_sgn(pr->tmp[2])<0 || bound_sgn(pr->tmp[3])<0) return true; /* infer binary constraints by substitution */ for (i=0;i<2*d;i++) { bound_add(pr->tmp[2],pr->tmp[0],m[matpos(2*d+1,i)]); bound_add(pr->tmp[3],pr->tmp[1],m[matpos(2*d,i)]); bound_bmin(m[matpos2(k^1,i)],pr->tmp[2]); bound_bmin(m[matpos2(k,i)],pr->tmp[3]); } for (i=2*d+2;i<2*dim;i++) { bound_add(pr->tmp[2],pr->tmp[0],m[matpos(i^1,2*d)]); bound_add(pr->tmp[3],pr->tmp[1],m[matpos(i^1,2*d+1)]); bound_bmin(m[matpos2(k^1,i)],pr->tmp[2]); bound_bmin(m[matpos2(k,i)],pr->tmp[3]); } /* infer unary constraints by substitution */ bound_mul_2(pr->tmp[2],pr->tmp[0]); bound_mul_2(pr->tmp[3],pr->tmp[1]); bound_badd(pr->tmp[2],m[matpos(2*d+1,d*2)]); bound_badd(pr->tmp[3],m[matpos(2*d,d*2+1)]); bound_bmin(m[matpos(k^1,k)],pr->tmp[2]); bound_bmin(m[matpos(k,k^1)],pr->tmp[3]); hmat_forget_var(m,dim,d); return false; } else if (u.type==UNARY && u.coef_i==-1) { /* X -> - X + [-a,b], invertible */ /* equivalent to X <- -X + [-a,b] */ hmat_assign(pr,u,m,dim,d,respect_closure); return false; } else if (u.type==UNARY && u.coef_i==1) { /* X -> X + [-a,b], invertible */ /* equivalent to X <- X + [-b,a] */ bound_set(pr->tmp[dim*2+3],pr->tmp[0]); bound_set(pr->tmp[0],pr->tmp[1]); bound_set(pr->tmp[1],pr->tmp[dim*2+3]); hmat_assign(pr,u,m,dim,d,respect_closure); return false; } else { /* general, approximated case */ /* TODO */ /* for now, respects closure... */ hmat_forget_var(m,dim,d); return false; } } /* common simple case: X_d -> X_k */ static void hmat_subst_var(bound_t* m, size_t dim, size_t d, size_t k) { size_t i; /* infer binary constraints by substitution */ for (i=0;i<2*d;i++) { bound_bmin(m[matpos2(2*k+1,i)],m[matpos(2*d+1,i)]); bound_bmin(m[matpos2(2*k,i)],m[matpos(2*d,i)]); } for (i=2*d+2;i<2*dim;i++) { bound_bmin(m[matpos2(2*k+1,i)],m[matpos(i^1,2*d)]); bound_bmin(m[matpos2(2*k,i)],m[matpos(i^1,2*d+1)]); } /* infer unary constraints by substitution */ bound_bmin(m[matpos(2*k+1,2*k)],m[matpos(2*d+1,d*2)]); bound_bmin(m[matpos(2*k,2*k+1)],m[matpos(2*d,d*2+1)]); hmat_forget_var(m,dim,d); } oct_t* oct_assign_linexpr(ap_manager_t* man, bool destructive, oct_t* a, ap_dim_t d, ap_linexpr0_t* expr, oct_t* dest) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_ASSIGN_LINEXPR_ARRAY,2*(a->dim+1+5)); uexpr u = oct_uexpr_of_linexpr(pr,pr->tmp,expr,a->dim); bound_t* m; bool respect_closure; arg_assert(ddim,return NULL;); if (dest && !dest->closed && !dest->m) /* definitively empty due to dest*/ return oct_set_mat(pr,a,NULL,NULL,destructive); if (u.type==EMPTY) /* definitively empty due to empty expression */ return oct_set_mat(pr,a,NULL,NULL,destructive); /* useful to close only for non-invertible assignments */ if ((u.type!=UNARY || u.i!=d) && pr->funopt->algorithm>=0) oct_cache_closure(pr,a); m = a->closed ? a->closed : a->m; if (!m) return oct_set_mat(pr,a,NULL,NULL,destructive); /* empty */ /* can / should we try to respect the closure */ respect_closure = (m==a->closed) && (pr->funopt->algorithm>=0) && (!dest); if (!destructive) m = hmat_copy(pr,m,a->dim); /* go */ hmat_assign(pr,u,m,a->dim,d,&respect_closure); /* exact on Q if zeroary or unary, closed arg and no conv error */ if (u.type==BINARY || u.type==OTHER) flag_incomplete; else if (num_incomplete || a->intdim) flag_incomplete; else if (!a->closed) flag_algo; else if (pr->conv) flag_conv; /* intersect with dest */ if (dest) { bound_t* m2 = dest->closed ? dest->closed : dest->m; size_t i; for (i=0;idim);i++) bound_min(m[i],m[i],m2[i]); } if (respect_closure) return oct_set_mat(pr,a,NULL,m,destructive); else return oct_set_mat(pr,a,m,NULL,destructive); } oct_t* oct_substitute_linexpr(ap_manager_t* man, bool destructive, oct_t* a, ap_dim_t d, ap_linexpr0_t* expr, oct_t* dest) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY,2*(a->dim+1+5)); uexpr u = oct_uexpr_of_linexpr(pr,pr->tmp,expr,a->dim); bound_t * m, *m2; bool respect_closure; arg_assert(ddim,return NULL;); m2 = dest ? (dest->closed ? dest->closed : dest->m) : NULL; if (dest && !m2) /* definitively empty due to dest*/ return oct_set_mat(pr,a,NULL,NULL,destructive); if (u.type==EMPTY) /* definitively empty due to empty expression */ return oct_set_mat(pr,a,NULL,NULL,destructive); /* useful to close only for non-invertible substitution */ if ((u.type!=UNARY || u.i!=d) && pr->funopt->algorithm>=0) oct_cache_closure(pr,a); m = a->closed ? a->closed : a->m; if (!m) return oct_set_mat(pr,a,NULL,NULL,destructive); /* empty */ /* can / should we try to respect the closure */ respect_closure = (m==a->closed) && (pr->funopt->algorithm>=0) && (!dest); if (!destructive) m = hmat_copy(pr,m,a->dim); /* go */ if (hmat_subst(pr,u,m,a->dim,d,(bound_t*)m2,&respect_closure)) { /* empty */ if (!destructive) hmat_free(pr,m,a->dim); return oct_set_mat(pr,a,NULL,NULL,destructive); } if (u.type==BINARY || u.type==OTHER) flag_incomplete; else if (num_incomplete || a->intdim) flag_incomplete; else if (!a->closed) flag_algo; else if (pr->conv) flag_conv; /* intersect with dest */ if (m2) { size_t i; for (i=0;idim);i++) bound_min(m[i],m[i],m2[i]); } if (respect_closure) return oct_set_mat(pr,a,NULL,m,destructive); else return oct_set_mat(pr,a,m,NULL,destructive); } oct_t* oct_assign_linexpr_array(ap_manager_t* man, bool destructive, oct_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, oct_t* dest) { if (size==1) return oct_assign_linexpr(man,destructive,a,tdim[0],texpr[0],dest); oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_ASSIGN_LINEXPR_ARRAY,2*(a->dim+size+5)); ap_dim_t* d = (ap_dim_t*) pr->tmp2; bound_t *m, *mm; size_t i; ap_dim_t p = a->dim; int inexact = 0; bool respect_closure = false; /* TODO */ /* checks */ arg_assert(size>0,return NULL;); for (i=0;idim;i++) d[i] = 0; for (i=0;idim,return NULL;); arg_assert(!d[tdim[i]],return NULL;); /* tdim has duplicate */ d[tdim[i]] = 1; } if (dest && !dest->closed && !dest->m) /* definitively empty due to dest*/ return oct_set_mat(pr,a,NULL,NULL,destructive); if (pr->funopt->algorithm>=0) oct_cache_closure(pr,a); m = a->closed ? a->closed : a->m; if (!m) return oct_set_mat(pr,a,NULL,NULL,destructive); /* empty */ /* add temporary dimensions to hold destination variables */ mm = hmat_alloc_top(pr,a->dim+size); bound_set_array(mm,m,matsize(a->dim)); /* coefs in expr for temporary dimensions are set to 0 */ for (i=0;i<2*size;i++) bound_set_int(pr->tmp[2*a->dim+i+2],0); /* perform assignments */ for (i=0;itmp,texpr[i],a->dim); if (u.type==EMPTY) { hmat_free(pr,mm,a->dim+size); return oct_set_mat(pr,a,NULL,NULL,destructive); } if (u.type==BINARY || u.type==OTHER) inexact = 1; hmat_assign(pr,u,mm,a->dim+size,a->dim+i,&respect_closure); } /* now close & remove temporary variables */ if (pr->funopt->algorithm>=0) { if (hmat_close(mm,a->dim+size)) { /* empty */ hmat_free(pr,mm,a->dim+size); return oct_set_mat(pr,a,NULL,NULL,destructive); } } else flag_algo; if (!destructive) m = hmat_alloc(pr,a->dim); for (i=0;idim;i++) d[i] = i; for (i=0;idim+i] = tdim[i]; d[tdim[i]] = a->dim; } hmat_permute(m,mm,a->dim,a->dim+size,d); hmat_free(pr,mm,a->dim+size); /* intersect with dest */ if (dest) { bound_t* m2 = dest->closed ? dest->closed : dest->m; size_t i; for (i=0;idim);i++) bound_min(m[i],m[i],m2[i]); } if (inexact || a->intdim) flag_incomplete; else if (!a->closed) flag_algo; else if (pr->conv) flag_conv; return oct_set_mat(pr,a,m,NULL,destructive); } oct_t* oct_substitute_linexpr_array(ap_manager_t* man, bool destructive, oct_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, oct_t* dest) { if (size==1) return oct_substitute_linexpr(man,destructive,a,tdim[0],texpr[0],dest); oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY, 2*(a->dim+size+5)); ap_dim_t* d = (ap_dim_t*) pr->tmp2; bound_t *m, *mm, *m2; size_t i,j; ap_dim_t p = a->dim; int inexact = 0; bool respect_closure = false; /* TODO */ /* checks */ arg_assert(size>0,return NULL;); for (i=0;idim;i++) d[i] = 0; for (i=0;idim,return NULL;); arg_assert(!d[tdim[i]],return NULL;); /* tdim has duplicate */ d[tdim[i]] = 1; } m2 = dest ? (dest->closed ? dest->closed : dest->m) : NULL; if (dest && !m2) /* definitively empty due to dest*/ return oct_set_mat(pr,a,NULL,NULL,destructive); if (pr->funopt->algorithm>=0) oct_cache_closure(pr,a); m = a->closed ? a->closed : a->m; if (!m) return oct_set_mat(pr,a,NULL,NULL,destructive); /* empty */ /* add temporary dimensions to hold destination variables */ mm = hmat_alloc_top(pr,a->dim+size); bound_set_array(mm,m,matsize(a->dim)); /* susbstitute org with temp variables */ for (i=0;idim+i), src = 2*tdim[i]; for (j=0;jdim+2*size;j++) { bound_bmin(mm[matpos2(dst+1,j)],mm[matpos(j^1,src)]); bound_bmin(mm[matpos2(dst,j)],mm[matpos(j^1,src+1)]); } bound_bmin(mm[matpos(dst+1,dst)],mm[matpos(src+1,src)]); bound_bmin(mm[matpos(dst,dst+1)],mm[matpos(src,src+1)]); hmat_forget_var(mm,a->dim+size,tdim[i]); } /* coefs in expr for temporary dimensions are set to 0 */ for (i=0;i<2*size;i++) bound_set_int(pr->tmp[2*a->dim+i+2],0); /* perform substitutions */ for (i=0;itmp,texpr[i],a->dim); if (u.type==EMPTY) { hmat_free(pr,mm,a->dim+size); return oct_set_mat(pr,a,NULL,NULL,destructive); } if (u.type==BINARY || u.type==OTHER) inexact = 1; if (hmat_subst(pr,u,mm,a->dim+size,a->dim+i,m2, &respect_closure)) { /* empty */ hmat_free(pr,mm,a->dim+size); return oct_set_mat(pr,a,NULL,NULL,destructive); } } /* now close */ if (pr->funopt->algorithm>=0) { if (hmat_close(mm,a->dim+size)) { /* empty */ hmat_free(pr,mm,a->dim+size); return oct_set_mat(pr,a,NULL,NULL,destructive); } } else flag_algo; /* remove temp */ if (!destructive) m = hmat_copy(pr,mm,a->dim); else bound_set_array(m,mm,matsize(a->dim)); hmat_free(pr,mm,a->dim+size); /* intersect with dest */ if (m2) { size_t i; for (i=0;idim);i++) bound_min(m[i],m[i],m2[i]); } if (inexact || a->intdim) flag_incomplete; else if (!a->closed) flag_algo; else if (pr->conv) flag_conv; return oct_set_mat(pr,a,m,NULL,destructive); } oct_t* oct_assign_texpr_array(ap_manager_t* man, bool destructive, oct_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, oct_t* dest) { return ap_generic_assign_texpr_array(man,destructive,a,tdim,texpr,size,dest); } oct_t* oct_substitute_texpr_array(ap_manager_t* man, bool destructive, oct_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, oct_t* dest) { return ap_generic_substitute_texpr_array(man,destructive,a,tdim,texpr,size,dest); } apron-dist-0.9.10/apron/octagons/oct_predicate.c0000640014525101416610000003566411005654323021467 0ustar bjeannetpopart/* * oct_predicate.c * * Predicates on octagons, extraction functions * * APRON Library / Octagonal Domain * * Copyright (C) Antoine Mine' 2006 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #include "oct.h" #include "oct_internal.h" #include "ap_generic.h" /* ============================================================ */ /* Tests */ /* ============================================================ */ bool oct_is_bottom(ap_manager_t* man, oct_t* a) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_IS_BOTTOM,0); if (pr->funopt->algorithm>=0) oct_cache_closure(pr,a); if (a->closed) { /* definitively non empty on Q */ if (num_incomplete || a->intdim) { flag_incomplete; } return false; } else if (!a->m) /* definitively empty */ return true; else { /* no closure => we don't know */ flag_algo; return false; } } bool oct_is_top(ap_manager_t* man, oct_t* a) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_IS_TOP,0); size_t i,j; bound_t* m = a->m ? a->m : a->closed; if (!m) return false; for (i=0;i<2*a->dim;i++) for (j=0;j<=(i|1);j++,m++) if (!bound_infty(*m) && i!=j) return false; return true; } bool oct_is_leq(ap_manager_t* man, oct_t* a1, oct_t* a2) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_IS_LEQ,0); arg_assert(a1->dim==a2->dim && a1->intdim==a2->intdim,return false;); if (pr->funopt->algorithm>=0) oct_cache_closure(pr,a1); if (!a1->closed && !a1->m) { /* a1 definitively empty */ return true; } else if (!a2->closed && !a2->m) { /* a2 definitively empty */ if (a1->closed) { /* a1 not empty on Q */ if (num_incomplete || a1->intdim) { flag_incomplete; } return false; } else { flag_algo; return false; } } else { size_t i,j; bound_t *x = a1->closed ? a1->closed : a1->m; bound_t *y = a2->closed ? a2->closed : a2->m; for (i=0;i<2*a1->dim;i++) for (j=0;j<=(i|1);j++,x++,y++) if (bound_cmp(*x,*y)>0) { if (a1->closed) { /* not included on Q */ if (num_incomplete || a1->intdim) { flag_incomplete; } return false; } else { flag_algo; return false; } } /* definitively included */ return true; } } bool oct_is_eq(ap_manager_t* man, oct_t* a1, oct_t* a2) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_IS_EQ,0); arg_assert(a1->dim==a2->dim && a1->intdim==a2->intdim,return false;); if (pr->funopt->algorithm>=0) { oct_cache_closure(pr,a1); oct_cache_closure(pr,a2); } if (!a1->closed && !a1->m) { if (!a2->closed && !a2->m) { /* both are empty */ return true; } else if (a2->closed) { /* a1 empty, e2 not empty on Q */ if (num_incomplete || a1->intdim) { flag_incomplete; } return false; } else { flag_algo; return false; } } else if (!a2->closed && !a2->m) { if (a1->closed) { /* a2 empty, e1 not empty on Q */ if (num_incomplete || a1->intdim) { flag_incomplete; } return false; } else { flag_algo; return false; } } else { size_t i,j; bound_t *x = a1->closed ? a1->closed : a1->m; bound_t *y = a2->closed ? a2->closed : a2->m; for (i=0;i<2*a1->dim;i++) for (j=0;j<=(i|1);j++,x++,y++) if (bound_cmp(*x,*y)) { if (a1->closed) { /* not equal on Q */ if (num_incomplete || a1->intdim) { flag_incomplete; } return false; } else { flag_algo; return false; } } /* definitively equal */ return true; } } bool oct_sat_interval(ap_manager_t* man, oct_t* a, ap_dim_t dim, ap_interval_t* i) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_SAT_INTERVAL,0); arg_assert(dimdim,return false;); if (pr->funopt->algorithm>=0) oct_cache_closure(pr,a); if (!a->closed && !a->m) { /* really empty */ return true; } else { bound_t* m = a->closed ? a->closed : a->m; ap_interval_t* b = ap_interval_alloc(); bool r; /* get (possibly approximated) bounds */ interval_of_bounds(pr,b, m[matpos(2*dim,2*dim+1)],m[matpos(2*dim+1,2*dim)],true); /* compare with i */ r = (ap_scalar_cmp(b->inf,i->inf)>=0) && (ap_scalar_cmp(b->sup,i->sup)<=0); ap_interval_free(b); if (r) return true; /* definitively saturates */ else /* definitely does not saturate on Q if closed & no conv error */ if (num_incomplete || a->intdim) { flag_incomplete; return false; } else if (!a->closed) { flag_algo; return false; } else if (pr->conv) { flag_conv; return false; } else return false; } } bool oct_is_dimension_unconstrained(ap_manager_t* man, oct_t* a, ap_dim_t dim) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_IS_DIMENSION_UNCONSTRAINED,0); arg_assert(dimdim,return false;); if (!a->closed && !a->m) /* definitively empty */ return false; else { bound_t* b = a->closed ? a->closed : a->m; size_t i, d2=2*dim; for (i=0;i<2*a->dim;i++) { if (!bound_infty(b[matpos2(i,d2)]) && i!=d2) return false; if (!bound_infty(b[matpos2(i,d2+1)]) && i!=d2+1) return false; } return true; } } /* not very precise for non unit constraints (always top) */ /* the semantics of non-deterministic expressions (i.e., intervals) is true saturates all expressions false may saturate some, may not saturate some */ bool oct_sat_lincons(ap_manager_t* man, oct_t* a, ap_lincons0_t* lincons) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_SAT_LINCONS, 2*(a->dim+1)); if (pr->funopt->algorithm>=0) oct_cache_closure(pr,a); if (!a->closed && !a->m) { /* really empty */ return true; } else { bound_t* b = a->closed ? a->closed : a->m; size_t i, ui, uj; ap_constyp_t c = lincons->constyp; uexpr u; bool r; switch (c) { /* skipped */ case AP_CONS_EQMOD: case AP_CONS_DISEQ: return false; /* handled */ case AP_CONS_EQ: case AP_CONS_SUPEQ: case AP_CONS_SUP: break; /* error */ default: assert(0); } u = oct_uexpr_of_linexpr(pr,pr->tmp,lincons->linexpr0,a->dim); switch (u.type) { case EMPTY: /* the empty set has all properties */ return true; case ZERO: if ((c==AP_CONS_SUPEQ && bound_sgn(pr->tmp[0])<=0) || /* [-a,b] >= 0 <=> a <= 0 */ (c==AP_CONS_SUP && bound_sgn(pr->tmp[0])<0) || /* [-a,b] > 0 <=> a < 0 */ (c==AP_CONS_EQ && !bound_sgn(pr->tmp[0]) && !bound_sgn(pr->tmp[1])) /* [-a,b] = 0 <=> a=b=0 */ ) return true; /* always saturates */ else { /* does not always saturate on Q, if closed and no conv error */ if (num_incomplete || a->intdim) { flag_incomplete; return false; } else if (!a->closed) { flag_algo; return false; } else if (pr->conv) { flag_conv; return false; } return false; } case UNARY: if (u.coef_i==1) ui = 2*u.i; else ui = 2*u.i+1; bound_mul_2(pr->tmp[0],pr->tmp[0]); bound_mul_2(pr->tmp[1],pr->tmp[1]); bound_badd(pr->tmp[0],b[matpos(ui,ui^1)]); bound_badd(pr->tmp[1],b[matpos(ui^1,ui)]); if (bound_sgn(pr->tmp[0])<=0 && /* c_i X_i + [-a,b] >= 0 <=> -c_i X_i + a <= 0 */ (c!=AP_CONS_SUP || bound_sgn(pr->tmp[0])<0) && /* c_i X_i + [-a,b] > 0 <=> -c_i X_i + a < 0 */ (c!=AP_CONS_EQ || bound_sgn(pr->tmp[1])<=0) /* c_i X_i + [-a,b] <= 0 <=> c_i X_i + b <= 0 */ ) return true; /* always saturates */ else { /* does not always saturate on Q, if closed and no conv error */ if (num_incomplete || a->intdim) { flag_incomplete; return false; } else if (!a->closed) { flag_algo; return false; } else if (pr->conv) { flag_conv; return false; } return false; } case BINARY: if ( u.coef_i==1) ui = 2*u.i; else ui = 2*u.i+1; if ( u.coef_j==1) uj = 2*u.j; else uj = 2*u.j+1; bound_badd(pr->tmp[0],b[matpos(uj,ui^1)]); bound_badd(pr->tmp[1],b[matpos(uj^1,ui)]); if (bound_sgn(pr->tmp[0])<=0 && /* c_i X_i + c_j X_j + [-a,b] >= 0 <=> -c_i X_i - c_j X_j + a <= 0 */ (c!=AP_CONS_SUP || bound_sgn(pr->tmp[0])<0) && /* c_i X_i + c_j X_j + [-a,b] > 0 <=> -c_i X_i - c_j X_j + a < 0 */ (c!=AP_CONS_EQ || bound_sgn(pr->tmp[1])<=0) /* c_i X_i + c_j X_j + [-a,b] <= 0 <=> c_i X_i + c_j X_j + b <= 0 */ ) return true; else { /* does not saturate on Q, when closed and no conv error */ if (num_incomplete || a->intdim) { flag_incomplete; return false; } else if (!a->closed) { flag_algo; return false; } else if (pr->conv) { flag_conv; return false; } return false; } case OTHER: /* no clue */ flag_incomplete; return false; default: assert(0); return false; /* unreachable */ } } } bool oct_sat_tcons(ap_manager_t* man, oct_t* a, ap_tcons0_t* cons) { return ap_generic_sat_tcons(man,a,cons,NUM_AP_SCALAR,false); } /* ============================================================ */ /* Extraction of properties */ /* ============================================================ */ /* not very precise for non unit constraints (interval arithmetics) */ ap_interval_t* oct_bound_linexpr(ap_manager_t* man, oct_t* a, ap_linexpr0_t* expr) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_BOUND_LINEXPR, 2*(a->dim+5)); ap_interval_t* r = ap_interval_alloc(); if (pr->funopt->algorithm>=0) oct_cache_closure(pr,a); if (!a->closed && !a->m) { /* really empty */ ap_interval_set_bottom(r); } else { bound_t* b = a->closed ? a->closed : a->m; size_t i, ui, uj; uexpr u = oct_uexpr_of_linexpr(pr,pr->tmp,expr,a->dim); switch (u.type) { case EMPTY: ap_interval_set_bottom(r); break; case ZERO: interval_of_bounds(pr,r,pr->tmp[0],pr->tmp[1],false); /* exact on Q if closed and no conversion error */ if (num_incomplete || a->intdim) flag_incomplete; else if (!a->closed) flag_algo; else if (pr->conv) flag_conv; break; case UNARY: if (u.coef_i==1) ui = 2*u.i; else ui = 2*u.i+1; bounds_of_coeff(pr,pr->tmp[0],pr->tmp[1],expr->cst,true); bound_badd(pr->tmp[0],b[matpos(ui,ui^1)]); bound_badd(pr->tmp[1],b[matpos(ui^1,ui)]); interval_of_bounds(pr,r,pr->tmp[0],pr->tmp[1],true); /* exact on Q if closed and no conversion error */ if (num_incomplete || a->intdim) flag_incomplete; else if (!a->closed) flag_algo; else if (pr->conv) flag_conv; break; case BINARY: if (u.coef_i==1) ui = 2*u.i; else ui = 2*u.i+1; if (u.coef_j==1) uj = 2*u.j; else uj = 2*u.j+1; bound_badd(pr->tmp[0],b[matpos2(uj,ui^1)]); bound_badd(pr->tmp[1],b[matpos2(uj^1,ui)]); interval_of_bounds(pr,r,pr->tmp[0],pr->tmp[1],false); /* exact on Q if closed and no conversion error */ if (num_incomplete || a->intdim) flag_incomplete; else if (!a->closed) flag_algo; else if (pr->conv) flag_conv; break; case OTHER: /* interval approximation */ for (i=0;idim;i++) { bound_div_2(pr->tmp[2*i+2],pr->tmp[2*i+2]); bound_div_2(pr->tmp[2*i+3],pr->tmp[2*i+3]); bounds_mul(pr->tmp[2*i+2],pr->tmp[2*i+3], b[matpos(2*i,2*i+1)],b[matpos(2*i+1,2*i)], pr->tmp[2*i+2],pr->tmp[2*i+3],pr->tmp+2*(a->dim+1)); bound_badd(pr->tmp[0],pr->tmp[2*i+2]); bound_badd(pr->tmp[1],pr->tmp[2*i+3]); } interval_of_bounds(pr,r,pr->tmp[0],pr->tmp[1],false); /* not optimal, even when closing a */ flag_incomplete; break; default: assert(0); } } return r; } ap_interval_t* oct_bound_texpr(ap_manager_t* man, oct_t* a, ap_texpr0_t* expr) { return ap_generic_bound_texpr(man,a,expr,NUM_AP_SCALAR,false); } ap_interval_t* oct_bound_dimension(ap_manager_t* man, oct_t* a, ap_dim_t dim) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_BOUND_DIMENSION,0); ap_interval_t* r = ap_interval_alloc(); arg_assert(dimdim,ap_interval_free(r);return NULL;); if (pr->funopt->algorithm>=0) oct_cache_closure(pr,a); if (!a->closed && !a->m) { /* really empty */ ap_interval_set_bottom(r); } else if (a->closed) { /* optimal in Q */ interval_of_bounds(pr,r, a->closed[matpos(2*dim,2*dim+1)], a->closed[matpos(2*dim+1,2*dim)],true); if (num_incomplete || a->intdim) flag_incomplete; else if (pr->conv) flag_conv; } else { /* not optimal */ interval_of_bounds(pr,r, a->m[matpos(2*dim,2*dim+1)],a->m[matpos(2*dim+1,2*dim)], true); flag_algo; } return r; } ap_lincons0_array_t oct_to_lincons_array(ap_manager_t* man, oct_t* a) { ap_lincons0_array_t ar; oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_TO_LINCONS_ARRAY,0); if (!a->closed && !a->m) { /* definitively empty */ ar = ap_lincons0_array_make(1); ar.p[0] = ap_lincons0_make_unsat(); } else { /* put non-oo constraint bounds only */ bound_t* m = a->closed ? a->closed : a->m; size_t i,j,n=0; ar = ap_lincons0_array_make(matsize(a->dim)); for (i=0;i<2*a->dim;i++) for (j=0;j<=(i|1);j++,m++) { if (i==j || bound_infty(*m)) continue; ar.p[n] = lincons_of_bound(pr,i,j,*m); n++; } ar.size = n; if (pr->conv) flag_conv; } return ar; } ap_tcons0_array_t oct_to_tcons_array(ap_manager_t* man, oct_t* a) { return ap_generic_to_tcons_array(man,a); } ap_interval_t** oct_to_box(ap_manager_t* man, oct_t* a) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_TO_BOX,0); ap_interval_t** in = ap_interval_array_alloc(a->dim); size_t i; if (pr->funopt->algorithm>=0) oct_cache_closure(pr,a); if (!a->closed && !a->m) { /* definitively empty */ for (i=0;idim;i++) ap_interval_set_bottom(in[i]); } else { /* put variable bounds */ bound_t* m = a->closed ? a->closed : a->m; for (i=0;idim;i++) interval_of_bounds(pr,in[i], m[matpos(2*i,2*i+1)],m[matpos(2*i+1,2*i)],true); man->result.flag_exact = false; if (!a->closed) flag_algo; else if (num_incomplete || a->intdim) flag_incomplete; else if (pr->conv) flag_conv; } return in; } /* not really implemented (returns either top or bottom) */ ap_generator0_array_t oct_to_generator_array(ap_manager_t* man, oct_t* a) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_TO_GENERATOR_ARRAY,0); if (pr->funopt->algorithm>=0) oct_cache_closure(pr,a); if (!a->closed && !a->m) { /* definitively empty */ return ap_generator0_array_make(0); } else { /* not empty => full universe */ ap_generator0_array_t ar = ap_generator0_array_make(a->dim+1); size_t i; /* origin vertex */ ar.p[0] = ap_generator0_make(AP_GEN_VERTEX, ap_linexpr0_alloc(AP_LINEXPR_SPARSE,0)); /* one line for each dimension */ for (i=0;idim;i++) { ap_linexpr0_t* e = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,1); e->p.linterm[0].dim = i; ap_coeff_set_scalar_int(&e->p.linterm[0].coeff,1); ar.p[i+1] = ap_generator0_make(AP_GEN_LINE,e); } flag_incomplete; return ar; } } apron-dist-0.9.10/apron/octagons/oct_doc.html0000640014525101416610000004255610645406626021026 0ustar bjeannetpopart APRON Library - Octagon Domain Implementation

APRON Library - Octagon Domain Implementation

Table of Contents

  1. Introduction
  2. Installation
  3. Access to the Library from C and C++
  4. Underlying Numeric Set
  5. Precision of the Transfer Functions
  6. Precision of the Predicates
  7. The algorithm parameter
  8. Widenings and Narrowing
  9. Additional Transfer Functions
  10. Unimplemented Features
  11. Conversion with Polyhedra
  12. Tools
  13. Low-level Access
  14. Access to the Library from OCaml
  15. Links
  16. Contact

Introduction

The APRON project provides a common interface for various numerical abstract domains with various expressiveness and cost versus precision trade-offs. This document describes the octagon domain implementation available within APRON. The octagon domain allows manipulating and representing conjunctions of invariants of the form ±x ±yc, where x and y range among a finite set of numerical program variables. In two dimensions, such invariants have an octagonal shape, hence the name.

Familiarity is assumed with the generic APRON framework as well as the octagon abstract domain (see external links).

Installation

Please see the README file included in the distribution for installation instructions.

Access to the Library from C and C++

Your C or C++ program must be linked with the following libraries:

  • the octagon library -loctX (where X denotes the chosen numeric set; MPQ for instance);
  • the APRON library -lapron;
  • the GMP library -lgmp;
  • the MPFR library -lmpfr;
  • the standard mathematical library -lm.
It is possible to use additional libraries, such as the POLKA module -lpolkaMPQ.

The standard way to access to the octagon library is through an APRON manager. The manager is created as follows:

  • include the oct.h file,
  • create an octagon manager ap_manager_t* man = oct_manager_alloc();
All standard APRON functions from ap_abstract0.h are available on octagons through man.

Note that, when using a floating-point implementation of the octagon library, creating a manager will automatically put the floating-point unit into rounding towards +oo mode (using ap_fpu_init provided by APRON), as it is required to ensure the soundness of the transfer functions. Beware that this setting is global: it affects all the computations of the process, not only those occurring in the octagon library.

Underlying Numeric Set

The octagon library is compiled with a variety of underlying numeric set, distinguished using a suffix:

  • I: integers with a plain "long int" representation;
  • Ill: integers with a "long long int" representation;
  • MPZ: arbitrary precision integers using GMP;
  • Rl: rationals with a "long int" representation;
  • Rll: rationals with a "long long int" representation;
  • MPQ: arbitrary precision rationals using GMP;
  • D: reals with a "double" representation;
  • Dl: reals with a "long double" representation.

The choice of this numeric set affects the soundness, precision, and efficiency of the analysis:

  • int and long types are subject to overflows, which may result in unsound results (no overflow checking is performed for efficiency reasons),
  • double and long double types are subject to rounding, which may result in some loss of precision; rounding is always performed towards +oo, which ensures soundness;
  • abstract transfer functions are inherently incomplete in Z, which results in some loss of precision;
  • constraints on reals are soundly approximated when using numbers in Z,
  • GMP types are much slower than native types.
For best precision, MPQ is recommended. For a fast and versatile yet sound analysis, D is recommended.

Note that the underlying numeric set chosen for octagons is not related to the choice of double or GMP for ap_scalar_t types used as arguments in transfer functions. Type mismatches may result in extra over-approximation (but always in a sound way).

Precision of the Transfer Functions

Exact transfer functions are provided for the class of operations that are closed under octagons. These include:

  • conjunctions with or conversions from constraints of the form ±x ±yc or ±xc,
  • (possibly parallel) assignments and substitutions of expressions of the form ±x + [a,b] or [a,b],
  • meets (i.e., intersections) of octagons,
  • getting the bound of a dimension or an expression of the form ±x ±y + [a,b], ±x + [a,b], or [a,b],
  • conversions to constraint sets,
  • conversions from boxes,
  • variable additions, deletions, projections, permutations, and expansions,
  • topological closures (always identity),
  • serializations and de-serializations.

Best transfer functions are provided in the following cases:

  • join (i.e., union) of octagons,
  • addition of rays,
  • conversions from generator sets,
  • conversions to boxes,
  • variable folding.

The following transfer functions use some approximate polynomial algorithms and have no precision guarantees:

  • conversions from or conjunctions with arbitrary constraints (a weakly relational approximation is used),
  • (possibly parallel) assignments and substitutions of arbitrary expressions (a weakly relational approximation is used),
  • conversions to generator sets (the whole universe is always returned),
  • getting the bound of arbitrary expressions (interval arithmetics is used).

Additionally, the exactness or best-precision feature of an abstract transfer function is often lost when the MPQ underlying numeric set is not used, or the arguments have integer dimensions, or the user sets the algorithm parameter to a strictly negative value. Finally, the exactness or best-precision feature can be lost due to conversion between the underlying numeric type and user-provided ap_scalar_t types. The octagon library will set the flag_exact and flag_best manager flags accordingly in all cases.

Note that, due to interval coefficients, expressions may be non-deterministic, that is, correspond to a bunch of expressions. In case of assignments, substitutions, or bound determinations of non-deterministic expressions, or conjunctions with non-deterministic constraints, we considers the join of all results, when ranging over the non-deterministic set.

Precision of the Predicates

The following predicates are exact, i.e., they always return either tbool_true or tbool_false (provided that algorithm is greater than or equal to 0, that the octagon has no integer dimension, and that the MPQ underlying domain is selected):

  • testing for inclusion, equality, emptiness, or universality,
  • testing whether a dimension is unbounded or saturated by a given interval,
  • testing for saturation by an expression of the form ±x ±y + [a,b], ±x + [a,b], or [a,b].

Note that, for non-deterministic expressions, tbool_false is returned as long as the saturation is not satisfied for at least one expression.

Testing for the saturation by an arbitrary expression is very imprecise. It always return tbool_top.

When algorithm is set to a strictly negative value, the octagon has an integer dimension, the MPQ underlying domain is selected, or the conversion from user-specified ap_scalar_t types to internal types resulted in an over-approximation, the predicate is sound but not exact: it is a semi-test. That is, it mainly returns either tbool_true or tbool_top. It can conclude that the predicate is definitively tbool_false only in very rare cases. The octagon library will set the flag_exact and flag_best manager flags accordingly in all cases.

The algorithm parameter

The algorithm field in the manager provides an implementation-specific parameter to set the required level of precision for transfer functions.

In the octagon domain, only two precision levels are recognised. They correspond to (with the exception of the widening):

  • algorithm ≥ 0 is the normal precision: a transitive closure algorithm is used pervasively to achieve best precision transfer functions and results in transfer functions that have a cubic worst-case cost (in the number of variables),
  • algorithm < 0 is the low precision: the transitive closure algorithm is not used, the best precision feature is not guaranteed, and transfer functions have a quadratic worst-case cost (many actually have a linear cost).

Widenings and Narrowing

Depending on the algorithm flag, one of the following widening algorithm is used:

  • algorithm = 0: the right argument is closed, the standard widening is used: unstable constraints are forgotten. Thus, it converges in a quadratic number of steps, at worse.
  • algorithm < 0: the standard widening algorithm is used but the right argument is not closed.
  • algorithm = oct_pre_widening: this special value corresponds to a pre-widening. It does not enforce the convergence by itself but can be safely intermixed with a regular widening to improve the precision of the sequence, without jeopardizing the overall convergence. As long as a regular widening is applied infinitely often, the sequence will converge in finite time. (Note that intermixing a regular widening with a join operator will result in a diverging sequence. Thus, the join is not a pre-widening. Our pre-widening is actually a join without the closure application.) Use with care!

The ap_abstract0_oct_widening_thresholds provides a widening with scalar thresholds. For each constraint of the form ±x ±yc or ±xc where the bound c is not stable, the widening replaces c with the scalar immediately greater in the user-supplied list, or +oo if it is greater than the greatest supplied scalar. The list must be sorted in strictly increasing order. (Note that this operator is not exactly the same as the generic ap_abstract0_widening_threshold function which is synthesized from ap_abstract0_sat_lincons and ap_abstract0_meet_lincons_array.)

The ap_abstract0_oct_narrowing function implements the standard narrowing: it refines only those constraints that have no finite bound. Thus, it converges in a quadratic number of steps, at worse.

Additional Transfer Functions

The octagon library provides a few functions not generic enough to be included in the APRON library. They share the ap_abstract0_oct_ prefix.

Additionally to the widening with thresholds and narrowing functions described in the preceding section, the octagon domain provides the following extra function:

  • ap_abstract0_oct_of_generator_array converts a generator set to an octagon, with best-precision.
  • ap_abstract0_oct_add_epsilon enlarges each constraint bound by a user-specified factor of the maximum finite bound present in the octagon.

Unimplemented Features

The following are not implemented and will raise an exception:

  • all the functions related to minimal and canonical forms,
  • ap_abstract0_approximate.

Conversion with Polyhedra

In order to ensure the best precision, the following conversion procedures are recommended:

  • To convert a polyhedron to an octagon, call ap_abstract0_to_generator_array on the polyhedra and then ap_abstract0_oct_of_generator_array on the result.
  • To convert an octagon to a polyhedron, call ap_abstract0_to_lincons_array on the octagon and then ap_abstract0_of_lincons_array on the result.

Do not extract the generators of an octagon or build an octagon from arbitrary linear constraints as these are not best-precision operators.

Tools

The distribution provides a fully automatic test suite with octtest. It compares the result of all transfer functions in the octagon and polyhedron domains, checking for soundness, best-precision and exactness properties.

Low-level Access

The file oct/oct_fun.h provides a direct access to all the octagon functions, without the abstraction provided by the manager. Note that these functions perform less sanity checks, and so, may not be as safe. Wrapping and unwrapping a oct_t* pointer within a generic ap_abstract0_t* is done using the abstract0_of_oct and oct_of_abstract0 functions.

The file oct/oct_internal.h must be included to access to the low-level representation of octagons struct oct_t and manager-specific data struct _oct_internal_t. Direct access to private fields is not recommended.

Access to the Library from OCaml

Your OCaml program must be linked with the following modules, in order:

  • the GMP OCaml wrapper: gmp.cmxa (or gmp.cma for byte-code);
  • the APRON OCaml wrapper: apron.cmxa (or apron.cma for byte-code);
  • the octagon OCaml wrapper: oct.cmxa (or oct.cma for byte-code);
  • the C octagon library for the chosen numerical type, e.g., -cclib -loctMPQ;
  • the C apron library: -cclib -lapron.
You may need the specify the include path with -I, depending on your installation.

Examples:

  • ocamlc -I $HOME/lib gmp.cma apron.cma oct.cma mltest.ml -cclib -loctMPQ -cclib -lapron
  • ocamlopt -I $HOME/lib gmp.cmxa apron.cmxa oct.cmxa mltest.ml -cclib -loctMPQ -cclib -lapron

The octagon library provides an Oct OCaml module There is no numeric suffix here: the OCaml wrapper is independent from the chosen numerical type. The Oct.manager_alloc function returns a new manager that can then be used with the standard Apron.Abstract0 module provided by APRON.

The Oct module also provides some implementation-specific functions:

  • of_generator_array to convert from a set of generators to an octagon, with best abstraction,
  • the widening_thresholds widening,
  • the narrowing standard narrowing,
  • the add_epsilon perturbation function.

Links

APRON

The octagon abstract domain:

  • Main journal article describing the octagon domain: The Octagon Abstract Domain in Higher-Order and Symbolic Computation, 2006.
  • The Ph.D. Thesis that gave rise to the octagon domain.
  • Former implementation the APRON implementation is based on.

Contact

Main developer: Antoine Miné mine@di.ens.fr. apron-dist-0.9.10/apron/octagons/Makefile0000640014525101416610000002667411252236542020162 0ustar bjeannetpopart# Makefile # # APRON Library / Octagonal Domain # # Copyright (C) Antoine Mine' 2006 # This file is part of the APRON Library, released under LGPL license. # Please read the COPYING file packaged in the distribution. include ../Makefile.config PREFIX = $(APRON_PREFIX) # C include and lib directories INCDIR = $(PREFIX)/include LIBDIR = $(PREFIX)/lib BINDIR = $(PREFIX)/bin SRCDIR = $(shell pwd) #--------------------------------------- # Programs #--------------------------------------- # Library creation SHARED = gcc -shared #--------------------------------------- # Flags #--------------------------------------- # Use ICFLAGS to specify machine-independent compilation flags. ICFLAGS = \ -I$(MLGMPIDL_PREFIX)/include \ -I../newpolka \ -I../apron \ -I../mlapronidl \ -I../num \ -I../itv \ -I$(MPFR_PREFIX)/include -I$(GMP_PREFIX)/include \ -I$(CAML_PREFIX)/lib/ocaml -I$(CAMLIDL_PREFIX)/lib/ocaml # Caml OCAMLINC = -I $(MLGMPIDL_PREFIX)/lib -I ../mlapronidl #--------------------------------------- # Files #--------------------------------------- CCSOURCES = oct_hmat.c oct_print.c oct_transfer.c oct_closure.c oct_nary.c \ oct_representation.c oct_predicate.c oct_resize.c CCINC = oct_internal.h oct_fun.h # trigers a whole recompilation #DEPS = $(APRON_PREFIX)/include/ap_abstract0.h #--------------------------------------- # Rules #--------------------------------------- root: @echo @echo "Please choose a target from:" @echo @echo " Il Ill MPZ Rl Rll MPQ D Dl MPFR: single C library" @echo " all : all C libraries" @echo " ml : OCaml library" @echo " mlIl mlIll ... : OCaml toplevel & byte-code" @echo " allml : everything" @echo " install : to install what has been compiled" @echo " clean : remove objects" @echo " distclean : clean & uninstall" @echo " mostyleclean : remove objects & autogenerated" @echo " rebuild : rebuild autogenerated " @echo all: Il Ill MPZ Ri Rll MPQ D Dl MPFR allml: allIl allIll allMPZ allRi allRll allMPQ allD allDl allMPFR allIl: Il mlIl allIll: Ill mlIll allMPZ: MPZ mlMPZ allRi: Ri mlRi allRll: Rll mlRll allMPQ: MPQ mlMPQ allD: D mlD allDl: Dl mlDl allMPFR: MPFR mlMPFR Il: liboctIl.a liboctIl_debug.a octtestIl Ill: liboctIll.a liboctIll_debug.a octtestIll MPZ: liboctMPZ.a liboctMPZ_debug.a octtestMPZ Ri: liboctRi.a liboctRi_debug.a octtestRi Rll: liboctRll.a liboctRll_debug.a octtestRll MPQ: liboctMPQ.a liboctMPQ_debug.a octtestMPQ D: liboctD.a liboctD_debug.a octtestD Dl: liboctDl.a liboctDl_debug.a octtestDl MPFR: liboctMPFR.a liboctMPFR_debug.a octtestMPFR ifneq ($(HAS_SHARED),) Il: liboctIl.so liboctIl_debug.so Ill: liboctIll.so liboctIll_debug.so MPZ: liboctMPZ.so liboctMPZ_debug.so Ri: liboctRi.so liboctRi_debug.so Rll: liboctRll.so liboctRll_debug.so MPQ: liboctMPQ.so liboctMPQ_debug.so D: liboctD.so liboctD_debug.so Dl: liboctDl.so liboctDl_debug.so MPFR: liboctMPFR.so liboctMPFR_debug.so endif mlexample%.byte: mlexample.ml oct%.cma $(OCAMLC) $(OCAMLFLAGS) -I $(MLGMPIDL_INSTALL)/lib -I $(APRON_PREFIX)/lib -o $@ bigarray.cma gmp.cma apron.cma oct$*.cma $< mlexample%.opt: mlexample.ml oct%.cmxa $(OCAMLOPT) $(OCAMLOPTFLAGS) -I $(MLGMPIDL_INSTALL)/lib -I $(APRON_PREFIX)/lib -o $@ bigarray.cmxa gmp.cmxa apron.cmxa oct$*.cmxa $< clean: /bin/rm -f *.[ao] *.so octtest* /bin/rm -f *.?.tex *.log *.aux *.bbl *.blg *.toc *.dvi *.ps *.pstex* /bin/rm -fr *.cm[ioax] *.cmxa /bin/rm -fr octtop* octrun* tmp /bin/rm -fr *~ \#*\# mostlyclean: clean /bin/rm -fr oct_caml.c oct.ml oct.mli install: $(INSTALLd) $(INCDIR) $(INCDIR)/oct $(LIBDIR) $(BINDIR) $(INSTALL) oct.h $(INCDIR) $(INSTALL) $(CCINC) $(INCDIR)/oct for i in liboct*.* liboct*_debug.* liboct*_caml.* oct.idl; do \ if test -f $$i; then $(INSTALL) $$i $(LIBDIR); fi; \ done for i in dlloct*_caml.so; do \ cp -f -d $$i $(LIBDIR); \ done for i in octtest?? octtop?? octrun??; do \ if test -f $$i; then $(INSTALL) $$i $(BINDIR); fi; \ done for i in oct.mli oct.cmi oct.cmx oct*.cma oct*.cmxa oct.a; do \ if test -f $$i; then $(INSTALL) $$i $(LIBDIR); fi; \ done uninstall: /bin/rm -fr $(INCDIR)/oct.h /bin/rm -f $(BINDIR)/octtest?? $(BINDIR)/octtop?? $(BINDIR)/octrun?? /bin/rm -f $(LIBDIR)/liboct*.* $(LIBDIR)/liboct*_debug.* /bin/rm -f $(LIBDIR)/dlloct*.so $(LIBDIR)/dlloct*_debug.so /bin/rm -f $(LIBDIR)/oct.mli $(LIBDIR)/oct.cm[ix] $(LIBDIR)/oct.idl $(LIBDIR)/oct*.cma $(LIBDIR)/oct*.cmxa $(LIBDIR)/oct*.a distclean: uninstall /bin/rm -f Makefile.depend dist: Makefile COPYING README oct_doc.html sedscript_caml sedscript_c $(CCSOURCES) $(CCINC) oct.h oct_test.c oct.idl oct.mli oct.ml oct_caml.c (cd ..; tar zcvf octagons.tgz $(^:%=octagons/%)) #--------------------------------------- # IMPLICIT RULES AND DEPENDENCIES #--------------------------------------- .SUFFIXES: .tex .c .h .a .o .so #----------------------------------- # C part #----------------------------------- liboct%.a: $(subst .c,%.o,$(CCSOURCES)) $(AR) rcs $@ $^ $(RANLIB) $@ liboct%_debug.a: $(subst .c,%_debug.o,$(CCSOURCES)) $(AR) rcs $@ $^ $(RANLIB) $@ liboct%.so: $(subst .c,%.o,$(CCSOURCES)) $(SHARED) -o $@ $^ octtest%: liboct%_debug.a oct_test%.o $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -o $@ oct_test$*.o \ -L. -loct$*_debug \ -L../newpolka -lpolkaMPQ_debug \ -L../apron -lapron_debug \ -L$(MPFR_PREFIX)/lib -lmpfr \ -L$(GMP_PREFIX)/lib -lgmp \ -lm %_caml.o: %_caml.c $(CCINC) $(DEPS) $(CC) $(CFLAGS) $(ICFLAGS) -c -o $@ $< %_caml_debug.o: %_caml.c $(CCINC) $(DEPS) $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -c -o $@ $< %Il.o: %.c $(CCINC) $(DEPS) $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_LONGINT -c -o $@ $< %Il_debug.o: %.c $(CCINC) $(DEPS) $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_LONGINT -c -o $@ $< %Ill.o: %.c $(CCINC) $(DEPS) $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_LONGLONGINT -c -o $@ $< %Ill_debug.o: %.c $(CCINC) $(DEPS) $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_LONGLONGINT -c -o $@ $< %MPZ.o: %.c $(CCINC) $(DEPS) $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_MPZ -I$(GMP_PREFIX)/include -c -o $@ $< %MPZ_debug.o: %.c $(CCINC) $(DEPS) $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_MPZ -I$(GMP_PREFIX)/include -c -o $@ $< %Ri.o: %.c $(CCINC) $(DEPS) $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_LONGRAT -c -o $@ $< %Ri_debug.o: %.c $(CCINC) $(DEPS) $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_LONGRAT -c -o $@ $< %Rll.o: %.c $(CCINC) $(DEPS) $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_LONGLONGRAT -c -o $@ $< %Rll_debug.o: %.c $(CCINC) $(DEPS) $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_LONGLONGRAT -c -o $@ $< %MPQ.o: %.c $(CCINC) $(DEPS) $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_MPQ -I$(GMP_PREFIX)/include -c -o $@ $< %MPQ_debug.o: %.c $(CCINC) $(DEPS) $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_MPQ -I$(GMP_PREFIX)/include -c -o $@ $< %D.o: %.c $(CCINC) $(DEPS) $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_DOUBLE -c -o $@ $< %D_debug.o: %.c $(CCINC) $(DEPS) $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_DOUBLE -c -o $@ $< %Dl.o: %.c $(CCINC) $(DEPS) $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_LONGDOUBLE -c -o $@ $< %Dl_debug.o: %.c $(CCINC) $(DEPS) $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_LONGDOUBLE -c -o $@ $< %MPFR.o: %.c $(CCINC) $(DEPS) $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_MPFR -c -o $@ $< %MPFR_debug.o: %.c $(CCINC) $(DEPS) $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_MPFR -c -o $@ $< # TODO: mpfr ? .PRECIOUS: liboct%.a liboct%_debug.a liboct%.so liboct%_debug.so .PRECIOUS: liboct%_caml.a liboct%_caml_debug.a liboct%_caml.so liboct%_caml_debug.so .PRECIOUS: %Il.o %Ill.o %MPZ.o %Ri.o %Rll.o %MPQ.o %D.o %Dl.o %MPFR.o .PRECIOUS: %Il_debug.o %Ill_debug.o %MPZ_debug.o %Ri_debug.o %Rll_debug.o %MPQ_debug.o %D_debug.o %Dl_debug.o %MPFR_debug.o #----------------------------------- # Caml part #----------------------------------- .INTERMEDIATE: mlIl ml: oct.mli oct.cmi oct.cmx oct.cma oct.cmxa oct.a mlIl: ml octIl.cma octIl.cmxa liboctIl_caml.a liboctIl_caml_debug.a mlIll: ml octIll.cma octIll.cmxa liboctIll_caml.a liboctIll_caml_debug.a mlMPZ: ml octMPZ.cma octMPZ.cmxa liboctMPZ_caml.a liboctMPZ_caml_debug.a mlRll: ml octRll.cma octRll.cmxa liboctRll_caml.a liboctRll_caml_debug.a mlMPQ: ml octMPQ.cma octMPQ.cmxa liboctMPQ_caml.a liboctMPQ_caml_debug.a mlD: ml octD.cma octD.cmxa liboctD_caml.a liboctD_caml_debug.a mlDl: ml octDl.cma octDl.cmxa liboctDl_caml.a liboctDl_caml_debug.a mlMPFR: ml octMPFR.cma octMPFR.cmxa liboctMPFR_caml.a liboctMPFR_caml_debug.a ifneq ($(HAS_SHARED),) mlIl: liboctIl_caml.so liboctIl_caml_debug.so dlloctIl_caml.so dlloctIl_caml_debug.so mlIll:liboctIll_caml.so liboctIll_caml_debug.so dlloctIll_caml.so dlloctIll_caml_debug.so mlMPZ:liboctMPZ_caml.so liboctMPZ_caml_debug.so dlloctMPZ_caml.so dlloctMPZ_caml_debug.so mlRll:liboctRll_caml.so liboctRll_caml_debug.so dlloctRll_caml.so dlloctRll_caml_debug.so mlMPQ:liboctMPQ_caml.so liboctMPQ_caml_debug.so dlloctMPQ_caml.so dlloctMPQ_caml_debug.so mlD:liboctD_caml.so liboctD_caml_debug.so dlloctD_caml.so dlloctD_caml_debug.so mlDl:liboctDl_caml.so liboctDl_caml_debug.so dlloctDl_caml.so dlloctDl_caml_debug.so mlMPFR:liboctMPFR_caml.so liboctMPFR_caml_debug.so dlloctMPFR_caml.so dlloctMPFR_caml_debug.so endif #octtop%: oct.cma liboct_caml.a liboct%.a # $(OCAMLMKTOP) -noautolink $(OCAMLFLAGS) $(OCAMLINC) -o $@ -custom bigarray.cma gmp.cma apron.cma oct.cma -ccopt "-L. -L$(MLGMPIDL_PREFIX)/lib -L../mlapronidl -L../apron -L../itv -L$(MPFR_PREFIX)/lib -L$(GMP_PREFIX)/lib -L$(CAMLIDL_PREFIX)/lib/ocaml" -cclib "-loct_caml -loct$* -lapron_caml -lapron -lgmp_caml -lmpfr -lgmp -lbigarray -lcamlidl" #octrun%: oct.cma liboct_caml.a # $(OCAMLC) -noautolink $(OCAMLFLAGS) $(OCAMLINC) -o $@ -make-runtime bigarray.cma gmp.cma apron.cma oct.cma -ccopt "-L. -L$(MLGMPIDL_PREFIX)/lib -L../mlapronidl -L../apron -L../itv -L$(MPFR_PREFIX)/lib -L$(GMP_PREFIX)/lib -L$(CAMLIDL_PREFIX)/lib/ocaml" -cclib "-loct_caml -loct$* -lapron_caml -lapron -lgmp_caml -lmpfr -lgmp -lbigarray -lcamlidl" oct.cma: octMPQ.cma ln -s -f $^ $@ oct.cmxa: octMPQ.cmxa ln -s -f $^ $@ oct.a: octMPQ.a ln -s -f $^ $@ oct%.cma: oct.cmi oct.cmo liboct%_caml.a liboct%.a $(OCAMLMKLIB) -ocamlc "$(OCAMLC)" -verbose -o oct$* -oc oct$*_caml oct.cmo -loct$* -L$(APRON_PREFIX)/lib -Wl,-rpath,$(APRON_PREFIX)/lib oct%.cmxa oct%.a: oct.cmi oct.cmx liboct%_caml.a liboct%.a $(OCAMLMKLIB) -ocamlopt "$(OCAMLOPT)" -verbose -o oct$* -oc oct$*_caml oct.cmx -loct$* -L$(APRON_PREFIX)/lib -Wl,-rpath,$(APRON_PREFIX)/lib liboct%_caml.a: oct_caml.o liboct%.a $(AR) rcs $@ $< $(RANLIB) $@ liboct%_caml_debug.a: oct_caml_debug.o liboct%_debug.a $(AR) rcs $@ $< $(RANLIB) $@ liboct%_caml.so: oct_caml.o liboct%.so $(SHARED) -o $@ oct_caml.o -L. -loct$* -Wl,-rpath,$(APRON_PREFIX)/lib liboct%_caml_debug.so: oct_caml_debug.o liboct%_debug.so $(SHARED) -o $@ oct_caml_debug.o -L. -loct$*_debug -Wl,-rpath,$(APRON_PREFIX)/lib dlloct%_caml.so: liboct%_caml.so ln -s -f $^ $@ dlloct%_caml_debug.so: liboct%_caml_debug.so ln -s -f $^ $@ rebuild: oct.idl mkdir -p tmp cp ../mlapronidl/*.idl tmp cp oct.idl tmp/ cd tmp && $(CAMLIDL) -no-include -nocpp -I . oct.idl $(SED) -f sedscript_c tmp/oct_stubs.c >oct_caml.c $(SED) -f sedscript_caml tmp/oct.ml >oct.ml $(SED) -f sedscript_caml tmp/oct.mli >oct.mli .PRECIOUS: %_caml.c %.ml %.mli %.cmi liboct%_caml.a liboct%_caml.so oct.cmx oct.cmo #--------------------------------------- # ML generic rules #--------------------------------------- %.cmi: %.mli $(DEPS) $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -c $< %.cmo: %.ml %.cmi $(DEPS) $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -c $< %.cmx: %.ml %.cmi $(DEPS) $(OCAMLOPT) $(OCAMLOPTFLAGS) $(OCAMLINC) -c $< #----------------------------------- # DEPENDENCIES #----------------------------------- apron-dist-0.9.10/apron/octagons/oct_print.c0000640014525101416610000001332110703142335020644 0ustar bjeannetpopart/* * oct_print.c * * Printing and serialization * * APRON Library / Octagonal Domain * * Copyright (C) Antoine Mine' 2006 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #include "oct.h" #include "oct_internal.h" /* ============================================================ */ /* Printing */ /* ============================================================ */ /* internal printing... */ static inline void oct_print_bounds(FILE*stream, oct_internal_t* pr, bound_t* m, size_t dim, char** name_of_dim) { size_t i,j; for (i=0;i<2*dim;i++) for (j=0;j<=(i|1);j++,m++) { ap_lincons0_t l; if (i==j || bound_infty(*m)) continue; l = lincons_of_bound(pr,i,j,*m); ap_lincons0_fprint(stream,&l,name_of_dim); ap_lincons0_clear(&l); fprintf(stream,"\n"); } } void oct_fprint(FILE* stream, ap_manager_t* man, oct_t* a, char** name_of_dim) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_FPRINT,0); if (pr->funopt->algorithm>=0) oct_cache_closure(pr,a); if (!a->closed && !a->m) { fprintf(stream,"empty octagon of dim (%lu,%lu)\n", (unsigned long)a->intdim,(unsigned long)(a->dim-a->intdim)); } else { bound_t* m = a->closed ? a->closed : a->m; fprintf(stream,"octagon of dim (%lu,%lu)\n", (unsigned long)a->intdim,(unsigned long)(a->dim-a->intdim)); /* if not closed, print the original matrix, not the closed cache */ oct_print_bounds(stream,pr,m,a->dim,name_of_dim); if (pr->conv) flag_conv; } } void oct_fprintdiff(FILE* stream, ap_manager_t* man, oct_t* a1, oct_t* a2, char** name_of_dim) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_FPRINTDIFF,0); arg_assert(a1->dim==a2->dim && a1->intdim==a2->intdim,); if (pr->funopt->algorithm>=0) oct_cache_closure(pr,a1); if (pr->funopt->algorithm>=0) oct_cache_closure(pr,a2); if (!a1->closed && !a1->m) { if (a2->closed || a2->m) { fprintf(stream,"octagon1 = empty\noctagon2 =\n"); oct_print_bounds(stream,pr,a2->m?a2->m:a2->closed,a2->dim,name_of_dim); if (pr->conv) flag_conv; } else fprintf(stream,"octagon1 = octagon2 = empty\n"); } else if (!a2->closed && !a2->m) { fprintf(stream,"octagon1 =\n"); oct_print_bounds(stream,pr,a1->m?a1->m:a1->closed,a1->dim,name_of_dim); fprintf(stream,"octagon2 = empty\n"); if (pr->conv) flag_conv; } else { bound_t* m1 = a1->closed ? a1->closed : a1->m; bound_t* m2 = a2->closed ? a2->closed : a2->m; size_t i,j,n=0; for (i=0;i<2*a1->dim;i++) for (j=0;j<=(i|1);j++,m1++,m2++) { ap_lincons0_t l; if (i==j || !bound_cmp(*m1,*m2)) continue; l = lincons_of_bound(pr,i,j,*m1); ap_lincons0_fprint(stream,&l,name_of_dim); ap_lincons0_clear(&l); fprintf(stream," / "); l = lincons_of_bound(pr,i,j,*m2); ap_lincons0_fprint(stream,&l,name_of_dim); ap_lincons0_clear(&l); fprintf(stream, "\n"); n++; } if (!n) fprintf(stream,"octagon1 = octagon2\n"); if (pr->conv) flag_conv; } } void oct_fdump(FILE* stream, ap_manager_t* man, oct_t* a) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_FDUMP,0); fprintf(stream,"octagon of dim (%lu,%lu)\n", (unsigned long)a->intdim,(unsigned long)(a->dim-a->intdim)); if (a->m) { fprintf(stream,"matrix:\n"); hmat_fdump(stream,pr,a->m,a->dim); } else fprintf(stream,"matrix: NULL\n"); if (a->closed) { fprintf(stream,"closed matrix:\n"); hmat_fdump(stream,pr,a->closed,a->dim); } else fprintf(stream,"closed matrix: NULL\n"); } /* ============================================================ */ /* Serialization */ /* ============================================================ */ /* raw format: 0: uchar: num_serialize_id 1: uchar: state (0=empty, 1=not closed, 2=closed) 2: uint32: intdim 6: uint32: realdim 10: - : half matrix, as flat array of bound_t */ ap_membuf_t oct_serialize_raw(ap_manager_t* man, oct_t* a) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_SERIALIZE_RAW,0); ap_membuf_t buf; size_t n = 10; if (a->m) n += bound_serialized_size_array(a->m,matsize(a->dim)); else if (a->closed) n += bound_serialized_size_array(a->closed,matsize(a->dim)); checked_malloc(buf.ptr,char,n,buf.size=0;return buf;); ((unsigned char*)buf.ptr)[0] = num_serialize_id(); num_dump_word32((char*)buf.ptr+2,a->dim); num_dump_word32((char*)buf.ptr+6,a->intdim); n = 10; if (a->m) { ((char*)buf.ptr)[1] = 1; buf.size = 10 + bound_serialize_array ((char*)buf.ptr+10,a->m,matsize(a->dim)); } else if (a->closed) { ((char*)buf.ptr)[1] = 2; buf.size = 10 + bound_serialize_array ((char*)buf.ptr+10,a->closed,matsize(a->dim)); } else { ((char*)buf.ptr)[1] = 0; buf.size = 10; } return buf; } oct_t* oct_deserialize_raw(ap_manager_t* man, void* ptr, size_t* size) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_DESERIALIZE_RAW,0); unsigned char id = ((unsigned char*)ptr)[0]; char state = ((char*)ptr)[1]; size_t dim = num_undump_word32((char*)ptr+2); size_t intdim = num_undump_word32((char*)ptr+6); size_t dummy; oct_t* r = oct_alloc_internal(pr,dim,intdim); arg_assert(id==num_serialize_id(),oct_free_internal(pr,r);return NULL;); arg_assert(state<3,oct_free_internal(pr,r);return NULL;); if (!size) size = &dummy; switch (state) { case 0: *size = 10; break; case 1: r->m = hmat_alloc(pr,dim); *size = 10 + bound_deserialize_array(r->m,(char*)ptr+10,matsize(dim)); break; case 2: r->closed = hmat_alloc(pr,dim); *size = 10 + bound_deserialize_array(r->closed,(char*)ptr+10,matsize(dim)); break; default: assert(0); } return r; } apron-dist-0.9.10/apron/octagons/oct_hmat.c0000640014525101416610000000501610607213001020433 0ustar bjeannetpopart/* * oct_hmat.c * * Half-matrices - Basic management. * * APRON Library / Octagonal Domain * * Copyright (C) Antoine Mine' 2006 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #include "oct.h" #include "oct_internal.h" /* We consider matrices of 2n*2n upper bounds. Let us denote by (i,j) the matrix element at line i, column j; the matrix induces the following constraints: Vj-Vi <= (2i,2j) Vj+Vi <= (2i+1,2j) -Vj-Vi <= (2i,2j+1) -Vj+Vi <= (2i+1,2j+1) Actually, this representation is redudant, and so, we manipulate 2x2 block lower-triangular matrices. Only elements (i,j) such that j/2 <= i/2 are represented: j -> 0 1 2 3 4 5 ___ 0 |_|_| 1 |_|_|___ i -> 2 |_|_|_|_| 3 |_|_|_|_|___ 4 |_|_|_|_|_|_| 5 |_|_|_|_|_|_| j 0 -2x0 2x0 0 i x0-x1 -x0-x1 0 -2x1 x0+x1 -x0+x1 2x1 0 Elements such that j/2 > i/2 are retreived by coherence: (i,j) = (j^1,i^1) */ /* alloced but not initialized */ inline bound_t* hmat_alloc(oct_internal_t* pr, size_t dim) { bound_t* r; size_t sz = matsize(dim); if (!sz) sz = 1; /* make sure we never malloc a O-sized block */ checked_malloc(r,bound_t,sz,return NULL;); bound_init_array(r,matsize(dim)); return r; } inline void hmat_free(oct_internal_t* pr, bound_t* m, size_t dim) { bound_clear_array(m,matsize(dim)); free(m); } /* all variables are initialized to 0 */ inline bound_t* hmat_alloc_zero(oct_internal_t* pr, size_t dim) { size_t i; bound_t* r = hmat_alloc(pr,dim); for (i=0;i= 0]. Abstract values which are octagons have the type [t Apron.AbstractX.t]. Managers allocated for octagons have the type [t Apron.manager.t]. *) external manager_alloc : unit -> t Apron.Manager.t = "camlidl_oct_oct_manager_alloc" external manager_get_internal : t Apron.Manager.t -> internal = "camlidl_oct_manager_get_internal" external of_generator_array : t Apron.Manager.t -> int -> int -> Apron.Generator0.t array -> t Apron.Abstract0.t = "camlidl_oct_ap_abstract0_oct_of_generator_array" external widening_thresholds : t Apron.Manager.t -> t Apron.Abstract0.t -> t Apron.Abstract0.t -> Apron.Scalar.t array -> t Apron.Abstract0.t = "camlidl_oct_ap_abstract0_oct_widening_thresholds" external narrowing : t Apron.Manager.t -> t Apron.Abstract0.t -> t Apron.Abstract0.t -> t Apron.Abstract0.t = "camlidl_oct_ap_abstract0_oct_narrowing" external add_epsilon : t Apron.Manager.t -> t Apron.Abstract0.t -> Apron.Scalar.t -> t Apron.Abstract0.t = "camlidl_oct_ap_abstract0_oct_add_epsilon" external add_epsilon_bin : t Apron.Manager.t -> t Apron.Abstract0.t -> t Apron.Abstract0.t -> Apron.Scalar.t -> t Apron.Abstract0.t = "camlidl_oct_ap_abstract0_oct_add_epsilon_bin" let pre_widening = 99 let manager_is_oct man = let str = Apron.Manager.get_library man in (String.compare str "oct")==0 let manager_of_oct (man:t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_oct (man:'a Apron.Manager.t) : t Apron.Manager.t = if manager_is_oct man then Obj.magic man else failwith "Oct.manager_to_oct: the argument manager is not an Oct manager" module Abstract0 = struct let is_oct abs = manager_is_oct (Apron.Abstract0.manager abs) let of_oct (abs: t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let to_oct (abs:'a Apron.Abstract0.t) : t Apron.Abstract0.t = if is_oct abs then Obj.magic abs else failwith "Oct.Abstract0.to_oct: the argument value is not an oct value" end module Abstract1 = struct let is_oct abs = manager_is_oct (Apron.Abstract1.manager abs) let of_oct (abs: t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let to_oct (abs:'a Apron.Abstract1.t) : t Apron.Abstract1.t = if is_oct abs then Obj.magic abs else failwith "Oct.Abstract1.to_oct: the argument value is not an oct value" end apron-dist-0.9.10/apron/octagons/oct_closure.c0000640014525101416610000001246310452747432021204 0ustar bjeannetpopart/* * oct_closure.c * * Half-matrices - Closure algorithms * * APRON Library / Octagonal Domain * * Copyright (C) Antoine Mine' 2006 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #include "oct.h" #include "oct_internal.h" /* All closures are in-place. */ /* ============================================================ */ /* Full Closure */ /* ============================================================ */ /* unary constraint propagation */ bool hmat_s_step(bound_t* m, size_t dim) { size_t i,j,k; bound_t *c,ik,ij; bound_init(ik); bound_init(ij); /* lone S step */ c = m; for (i=0;i<2*dim;i++) { bound_div_2(ij,m[matpos(i,i^1)]); for (j=0;j<=(i|1);j++,c++) { bound_div_2(ik,m[matpos(j^1,j)]); bound_badd(ik,ij); bound_bmin(*c,ik); } } bound_clear(ik); bound_clear(ij); /* emptyness checking */ for (i=0;i<2*dim;i++) { c = m+matpos(i,i); if (bound_sgn(*c)<0) return true; bound_set_int(*c,0); } return false; } /* We use a variant of Floyd-Warshall shortest-path closure algorithm, with some extra constraint propagation step. Returns true if the resulting matrix is empty, false otherwise (does not free the matrix) Cubic time. Constant space. */ bool hmat_close(bound_t* m, size_t dim) { size_t i,j,k; bound_t *c,ik,ik2,ij; bound_init(ik); bound_init(ik2); bound_init(ij); /* Floyd-Warshall */ for (k=0;k<2*dim;k++) { size_t k2 = k^1; c = m; for (i=0;i<2*dim;i++) { size_t i2 = i|1; size_t br = k0) closed = false; } for (i=0;i<2*dim;i++) for (j=0;j<2*dim;j++) if (bound_cmp(m[matpos2(i,j)],m[matpos2(j^1,i^1)])>0) closed = false; for (i=0;i<2*dim;i++) for (j=0;j<2*dim;j++) { bound_add(w,m[matpos2(i,i^1)],m[matpos2(j^1,j)]); bound_div_2(w,w); if (bound_cmp(m[matpos2(i,j)],w)>0) closed = false; } bound_clear(w); return closed; } apron-dist-0.9.10/apron/octagons/mlexample.ml0000640014525101416610000001330711251675321021026 0ustar bjeannetpopart(* This file is part of the APRON Library, released under LGPL license. (use of PPL) Please read the COPYING file packaged in the distribution. *) (* with default setting (if dynamic libraries): ocaml -I $MLGMPIDL_INSTALL/lib -I $APRON_INSTALL/lib #load "bigarray.cma";; #load "gmp.cma";; #load "apron.cma";; #load "octD.cma";; #install_printer Apron.Linexpr1.print;; #install_printer Apron.Texpr1.print;; #install_printer Apron.Lincons1.print;; #install_printer Apron.Generator1.print;; #install_printer Apron.Abstract1.print;; let environment_print fmt x = Apron.Environment.print fmt x;; let lincons1_array_print fmt x = Apron.Lincons1.array_print fmt x;; let generator1_array_print fmt x = Apron.Generator1.array_print fmt x;; #install_printer Apron.Var.print;; #install_printer environment_print;; #install_printer lincons1_array_print;; #install_printer generator1_array_print;; *) open Apron;; open Mpqf;; open Format;; let print_array = Abstract0.print_array;; let lincons1_array_print fmt x = Lincons1.array_print fmt x ;; let generator1_array_print fmt x = Generator1.array_print fmt x ;; let man = Oct.manager_alloc ();; let var_x = Var.of_string "x";; let var_y = Var.of_string "y";; let var_z = Var.of_string "z";; let var_w = Var.of_string "w";; let var_u = Var.of_string "u";; let var_v = Var.of_string "v";; let var_a = Var.of_string "a";; let var_b = Var.of_string "b";; let ex1 (man:'a Manager.t) : 'a Abstract1.t = printf "Using Library: %s, version %s@." (Manager.get_library man) (Manager.get_version man); let env = Environment.make [|var_x; var_y; var_z; var_w|] [|var_u; var_v; var_a; var_b|] in let env2 = Environment.make [|var_x; var_y; var_z; var_w|] [||] in printf "env=%a@.env2=%a@." (fun x -> Environment.print x) env (fun x -> Environment.print x) env2 ; (* Creation of abstract value 1/2x+2/3y=1, [1,2]<=z+2w<=4, 0<=u<=5 *) let tab = Parser.lincons1_of_lstring env ["1/2x+2/3y=1"; "[1;2]<=z+2w";"z+2w<=4"; "0<=u";"u<=5"] in printf "tab = %a@." lincons1_array_print tab; let abs = Abstract1.of_lincons_array man env tab in printf "abs=%a@." Abstract1.print abs; (* Extraction (we first extract values for existing constraints, then for dimensions) *) let box = Abstract1.to_box man abs in printf "box=%a@." (print_array Interval.print) box.Abstract1.interval_array; for i=0 to 4 do let expr = Lincons1.get_linexpr1 (Lincons1.array_get tab i) in let box = Abstract1.bound_linexpr man abs expr in printf "Bound of %a = %a@." Linexpr1.print expr Interval.print box; done; (* 2. dimensions *) (* 3. of box *) let abs2 = Abstract1.of_box man env [|var_x; var_y; var_z; var_w; var_u; var_v; var_a; var_b|] box.Abstract1.interval_array in printf "abs2=%a@." Abstract1.print abs2; (* 4. Tests top and bottom *) let abs3 = Abstract1.bottom man env in printf "abs3=%a@.is_bottom(abs3)=%b@." Abstract1.print abs3 (Abstract1.is_bottom man abs3); printf "abs=%a@." Abstract1.print abs; let p2 = Abstract1.expand man abs var_y [|Var.of_string "y1"; Var.of_string "y2"|] in printf "p2=expand(abs,y,[y1,y2]))=%a@." Abstract1.print p2; let p2 = Abstract1.expand man abs var_u [|Var.of_string "u1"; Var.of_string "u2"|] in printf "p2=expand(abs,u,[u1,u2]))=%a@." Abstract1.print p2; (* Tree expressions *) let texpr = Parser.texpr1_of_string env "a + (x*y*y/sqrt(b))" in let abs2 = Abstract1.assign_texpr man abs var_u texpr None in printf "abs2=%a@." Abstract1.print abs2; abs ;; let ex2 (man:'a Manager.t) = let env = Environment.make [||] [|var_x; var_y; var_z|] in (* Creation of abstract value 5<=x<=14, 4<=y<=12, z=0 *) let abs1 = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int 5 14; Interval.of_int 4 12; Interval.of_int 0 0; |] in let abs2 = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int 3 12; Interval.of_int 5 13; Interval.of_int 1 1; |] in let abs3 = Abstract1.join man abs1 abs2 in abs3 ;; (* Comparing join of two different assignements and assignement by the "join" of expressions *) let ex3 (man:'a Manager.t) = let env = Environment.make [||] [|var_x; var_y; var_z|] in (* Creation of abstract value -3<=x<=-2, 10<=y<=12, -1<=z<=1 *) let abs = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int (-3) (-2); Interval.of_int 10 12; Interval.of_int (-1) (1) |] in (* Creation of linear expressions *) let linexpr1 = Parser.linexpr1_of_string env "z+x+2y" in let linexpr2 = Parser.linexpr1_of_string env "z+2x+y" in let abs1 = Abstract1.assign_linexpr man abs var_z linexpr1 None in let abs2 = Abstract1.assign_linexpr man abs var_z linexpr2 None in let res1 = Abstract1.join man abs1 abs2 in printf "abs=%a@.abs1=%a@.abs2=%a@.res1=%a@." Abstract1.print abs Abstract1.print abs1 Abstract1.print abs2 Abstract1.print res1; (* Creation of linear expression [1,2]y and [1,2]z *) let linexpr = Parser.linexpr1_of_string env "z + [1;2]x + [1;2]y" in let res2 = Abstract1.assign_linexpr man abs var_z linexpr None in printf "res2=%a@." Abstract1.print res2 ; let abs1 = Abstract1.substitute_linexpr man res1 var_z linexpr1 None in let abs2 = Abstract1.substitute_linexpr man res1 var_z linexpr2 None in let res1 = Abstract1.join man abs1 abs2 in printf "abs1=%a@.abs2=%a@.res1=%a@." Abstract1.print abs1 Abstract1.print abs2 Abstract1.print res1 ; let res2 = Abstract1.substitute_linexpr man res2 var_z linexpr None in printf "res2=%a@." Abstract1.print res2 ; res1 ;; let abs1 = ex1 man;; let abs2 = ex2 man;; let abs3 = ex3 man;; apron-dist-0.9.10/apron/octagons/oct_fun.h0000640014525101416610000003334011232032174020305 0ustar bjeannetpopart/* * oct_fun.h * * Direct access to hi-level octagonal functions bypassing the manager. * The only file you need to include to use octagons. * * APRON Library / Octagonal Domain * * Copyright (C) Antoine Mine' 2006 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __OCT_FUN_H #define __OCT_FUN_H /* dependencies */ #include #include #include #define NUMFLT_PRINT_PREC ap_scalar_print_prec #include "num.h" #include "bound.h" #include "ap_coeff.h" #include "ap_dimension.h" #include "ap_expr0.h" #include "ap_manager.h" #include "oct.h" #ifdef __cplusplus extern "C" { #endif /* ============================================================ */ /* I.1 Memory */ /* ============================================================ */ struct _oct_t; typedef struct _oct_t oct_t; /* Abstract data type of octagons (defined in oct_private.h). */ oct_t* oct_copy(ap_manager_t* man, oct_t* a); /* Return a copy of an abstract value, on which destructive update does not affect the initial value. */ void oct_free(ap_manager_t* man, oct_t* a); /* Free all the memory used by the abstract value */ size_t oct_size(ap_manager_t* man, oct_t* a); /* Return the abstract size of an abstract value (see ap_manager_t) */ struct _oct_internal_t; typedef struct _oct_internal_t oct_internal_t; /* Abstract data type of library-specific manager options. */ oct_t* oct_of_abstract0(ap_abstract0_t* a); ap_abstract0_t* abstract0_of_oct(ap_manager_t* man, oct_t* oct); /* Wrapping / unwrapping of oct_t in ap_abstract0_t (no copy) */ /* ============================================================ */ /* I.2 Control of internal representation */ /* ============================================================ */ /* NOT IMPLEMENTED */ void oct_minimize(ap_manager_t* man, oct_t* a); void oct_canonicalize(ap_manager_t* man, oct_t* a); int oct_hash(ap_manager_t* man, oct_t* a); void oct_approximate(ap_manager_t* man, oct_t* a, int algorithm); bool oct_is_minimal(ap_manager_t* man, oct_t* a); bool oct_is_canonical(ap_manager_t* man, oct_t* a); /* ============================================================ */ /* I.3 Printing */ /* ============================================================ */ void oct_fprint(FILE* stream, ap_manager_t* man, oct_t* a, char** name_of_dim); /* Print the abstract value in a pretty way, using function name_of_dim to name dimensions */ void oct_fprintdiff(FILE* stream, ap_manager_t* man, oct_t* a1, oct_t* a2, char** name_of_dim); /* Print the difference between a1 (old value) and a2 (new value), using function name_of_dim to name dimensions. The meaning of difference is library dependent. */ void oct_fdump(FILE* stream, ap_manager_t* man, oct_t* a); /* Dump the internal representation of an abstract value, for debugging purposes */ /* ============================================================ */ /* I.4 Serialization */ /* ============================================================ */ ap_membuf_t oct_serialize_raw(ap_manager_t* man, oct_t* a); /* Allocate a memory buffer (with malloc), output the abstract value in raw binary format to it and return a pointer on the memory buffer and the size of bytes written. It is the user responsability to free the memory afterwards (with free). */ oct_t* oct_deserialize_raw(ap_manager_t* man, void* ptr, size_t* size); /* Return the abstract value read in raw binary format from the input stream and store in size the number of bytes read */ /* ********************************************************************** */ /* II. Constructor, accessors, tests and property extraction */ /* ********************************************************************** */ /* ============================================================ */ /* II.1 Basic constructors */ /* ============================================================ */ /* We assume that dimensions [0..intdim-1] correspond to integer variables, and dimensions [intdim..intdim+realdim-1] to real variables */ oct_t* oct_bottom(ap_manager_t* man, size_t intdim, size_t realdim); /* Create a bottom (empty) value */ oct_t* oct_top(ap_manager_t* man, size_t intdim, size_t realdim); /* Create a top (universe) value */ oct_t* oct_of_box(ap_manager_t* man, size_t intdim, size_t realdim, ap_interval_t** tinterval); /* Abstract an hypercube defined by the array of intervals of size intdim+realdim */ oct_t* oct_of_lincons_array(ap_manager_t* man, size_t intdim, size_t realdim, ap_lincons0_array_t* array); /* Abstract a convex polyhedra defined by an array of linear constraints */ oct_t* oct_of_tcons_array(ap_manager_t* man, size_t intdim, size_t realdim, ap_tcons0_array_t* array); /* Abstract a conjunction of tree expressions constraints */ oct_t* oct_of_generator_array(ap_manager_t* man, size_t intdim, size_t realdim, ap_generator0_array_t* array); /* Abstract a convex polyhedra defined an array of generators */ /* ============================================================ */ /* II.2 Accessors */ /* ============================================================ */ ap_dimension_t oct_dimension(ap_manager_t* man, oct_t* a); /* Return the total number of dimensions of the abstract values */ /* ============================================================ */ /* II.3 Tests */ /* ============================================================ */ bool oct_is_bottom(ap_manager_t* man, oct_t* a); bool oct_is_top(ap_manager_t* man, oct_t* a); bool oct_is_leq(ap_manager_t* man, oct_t* a1, oct_t* a2); /* inclusion check */ bool oct_is_eq(ap_manager_t* man, oct_t* a1, oct_t* a2); /* equality check */ /* NOT IMPLEMENTED */ bool oct_sat_lincons(ap_manager_t* man, oct_t* a, ap_lincons0_t* cons); /* does the abstract value satisfy the linear constraint ? */ bool oct_sat_tcons(ap_manager_t* man, oct_t* a, ap_tcons0_t* cons); /* does the abstract value satisfy the tree expression constraint ? */ bool oct_sat_interval(ap_manager_t* man, oct_t* a, ap_dim_t dim, ap_interval_t* interval); /* is the dimension included in the interval in the abstract value ? */ bool oct_is_dimension_unconstrained(ap_manager_t* man, oct_t* a, ap_dim_t dim); /* is the dimension unconstrained ? */ /* ============================================================ */ /* II.4 Extraction of properties */ /* ============================================================ */ ap_interval_t* oct_bound_linexpr(ap_manager_t* man, oct_t* a, ap_linexpr0_t* expr); /* Returns the interval taken by a linear expression over the abstract value */ ap_interval_t* oct_bound_texpr(ap_manager_t* man, oct_t* a, ap_texpr0_t* expr); /* Returns the interval taken by a tree expression over the abstract value */ ap_interval_t* oct_bound_dimension(ap_manager_t* man, oct_t* a, ap_dim_t dim); /* Returns the interval taken by the dimension over the abstract value */ ap_lincons0_array_t oct_to_lincons_array(ap_manager_t* man, oct_t* a); /* Converts an abstract value to a polyhedra (conjunction of linear constraints). */ ap_tcons0_array_t oct_to_tcons_array(ap_manager_t* man, oct_t* a); /* Converts an abstract value to a conjunction of tree expressions constraints */ ap_interval_t** oct_to_box(ap_manager_t* man, oct_t* a); /* Converts an abstract value to an interval/hypercube. The size of the resulting array is oct_dimension(man,a). This function can be reimplemented by using oct_bound_linexpr */ ap_generator0_array_t oct_to_generator_array(ap_manager_t* man, oct_t* a); /* Converts an abstract value to a system of generators. */ /* ********************************************************************** */ /* III. Operations */ /* ********************************************************************** */ /* ============================================================ */ /* III.1 Meet and Join */ /* ============================================================ */ oct_t* oct_meet(ap_manager_t* man, bool destructive, oct_t* a1, oct_t* a2); oct_t* oct_join(ap_manager_t* man, bool destructive, oct_t* a1, oct_t* a2); /* Meet and Join of 2 abstract values */ oct_t* oct_meet_array(ap_manager_t* man, oct_t** tab, size_t size); oct_t* oct_join_array(ap_manager_t* man, oct_t** tab, size_t size); /* Meet and Join of an array of abstract values. Raises an [[exc_invalid_argument]] exception if [[size==0]] (no way to define the dimensionality of the result in such a case */ oct_t* oct_meet_lincons_array(ap_manager_t* man, bool destructive, oct_t* a, ap_lincons0_array_t* array); /* Meet of an abstract value with a set of constraints (generalize oct_of_lincons_array) */ oct_t* oct_meet_tcons_array(ap_manager_t* man, bool destructive, oct_t* a, ap_tcons0_array_t* array); /* Meet of an abstract value with a set of tree expressions constraints. (generalize oct_of_tcons_array) */ oct_t* oct_add_ray_array(ap_manager_t* man, bool destructive, oct_t* a, ap_generator0_array_t* array); /* Generalized time elapse operator. Note: this is not like adding arbitrary generators because: - oct_add_ray_array is strict - array can only contain rays and lines, not vertices */ /* ============================================================ */ /* III.2 Assignement and Substitutions */ /* ============================================================ */ oct_t* oct_assign_linexpr_array(ap_manager_t* man, bool destructive, oct_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, oct_t* dest); oct_t* oct_substitute_linexpr_array(ap_manager_t* man, bool destructive, oct_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, oct_t* dest); oct_t* oct_assign_texpr_array(ap_manager_t* man, bool destructive, oct_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, oct_t* dest); oct_t* oct_substitute_texpr_array(ap_manager_t* man, bool destructive, oct_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, oct_t* dest); /* Parallel Assignement and Substitution of several dimensions by expressions in abstract value org. dest is an optional argument. If not NULL, semantically speaking, the result of the transformation is intersected with dest. This is useful for precise backward transformations in lattices like intervals or octagons. */ /* ============================================================ */ /* III.3 Projections */ /* ============================================================ */ oct_t* oct_forget_array(ap_manager_t* man, bool destructive, oct_t* a, ap_dim_t* tdim, size_t size, bool project); /* ============================================================ */ /* III.4 Change and permutation of dimensions */ /* ============================================================ */ oct_t* oct_add_dimensions(ap_manager_t* man, bool destructive, oct_t* a, ap_dimchange_t* dimchange, bool project); oct_t* oct_remove_dimensions(ap_manager_t* man, bool destructive, oct_t* a, ap_dimchange_t* dimchange); oct_t* oct_permute_dimensions(ap_manager_t* man, bool destructive, oct_t* a, ap_dimperm_t* permutation); /* ============================================================ */ /* III.5 Expansion and folding of dimensions */ /* ============================================================ */ oct_t* oct_expand(ap_manager_t* man, bool destructive, oct_t* a, ap_dim_t dim, size_t n); /* Expand the dimension dim into itself + n additional dimensions. It results in (n+1) unrelated dimensions having same relations with other dimensions. The (n+1) dimensions are put as follows: - original dimension dim - if the dimension is integer, the n additional dimensions are put at the end of integer dimensions; if it is real, at the end of the real dimensions. */ oct_t* oct_fold(ap_manager_t* man, bool destructive, oct_t* a, ap_dim_t* tdim, size_t size); /* Fold the dimensions in the array tdim of size n>=1 and put the result in the first dimension in the array. The other dimensions of the array are then removed. */ /* ============================================================ */ /* III.6 Widening, Narrowing */ /* ============================================================ */ oct_t* oct_widening(ap_manager_t* man, oct_t* a1, oct_t* a2); /* Standard widening: set unstable constraints to +oo */ oct_t* oct_widening_thresholds(ap_manager_t* man, oct_t* a1, oct_t* a2, ap_scalar_t** array, size_t nb); /* Widening with threshold. array is assumed to contain nb thresholds, sorted in increasing order. */ oct_t* oct_narrowing(ap_manager_t* man, oct_t* a1, oct_t* a2); /* Standard narrowing: refine only +oo constraint */ oct_t* oct_add_epsilon(ap_manager_t* man, oct_t* a, ap_scalar_t* epsilon); /* Enlarge each bound by epsilon times the maximum finite bound in the octagon */ oct_t* oct_add_epsilon_bin(ap_manager_t* man, oct_t* a1, oct_t* a2, ap_scalar_t* epsilon); /* Enlarge each bound from a1 by epsilon times the maximum finite bound in a2. Only bounds in a1 that are not stable in a2 are enlarged. */ /* ============================================================ */ /* III.7 Topological closure operation */ /* ============================================================ */ oct_t* oct_closure(ap_manager_t* man, bool destructive, oct_t* a); /* Returns the topological closure of a possibly opened abstract value */ #ifdef __cplusplus } #endif #endif /* __OCT_FUN_H */ apron-dist-0.9.10/apron/octagons/oct_resize.c0000640014525101416610000002523010723557216021025 0ustar bjeannetpopart/* * oct_resize.c * * Projection, changes of dimension, variable permutation. * * APRON Library / Octagonal Domain * * Copyright (C) Antoine Mine' 2006 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #include "oct.h" #include "oct_internal.h" /* ============================================================ */ /* Projections */ /* ============================================================ */ oct_t* oct_forget_array(ap_manager_t* man, bool destructive, oct_t* a, ap_dim_t* tdim, size_t size, bool project) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_FORGET_ARRAY,0); if (pr->funopt->algorithm>=0) oct_cache_closure(pr,a); if (!a->closed && !a->m) /* definitively empty */ return oct_set_mat(pr,a,NULL,NULL,destructive); else { bound_t* m = a->closed ? a->closed : a->m; size_t i,k; if (!destructive) m = hmat_copy(pr,m,a->dim); for (i=0;idim,return NULL;); /* binary constraints on tdim[i] */ for (k=0;kdim;k++) { bound_set_infty(m[matpos(k,d2)],1); bound_set_infty(m[matpos(k,d2+1)],1); } /* unary constraints on tdim[i] */ if (project) { bound_set_int(m[matpos(d2,d2+1)],0); bound_set_int(m[matpos(d2+1,d2)],0); } else { bound_set_infty(m[matpos(d2,d2+1)],1); bound_set_infty(m[matpos(d2+1,d2)],1); } } if (a->closed) { /* result is exact on Q, and closed if forget, not project */ if (num_incomplete || a->intdim) flag_incomplete; if (project) return oct_set_mat(pr,a,m,NULL,destructive); else return oct_set_mat(pr,a,NULL,m,destructive); } else { /* not exact, not closed */ flag_algo; return oct_set_mat(pr,a,m,NULL,destructive); } } } /* ============================================================ */ /* Change and permutation of dimensions */ /* ============================================================ */ /* internal helper function */ void hmat_addrem_dimensions(bound_t* dst, bound_t* src, ap_dim_t* pos, size_t nb_pos, size_t mult, size_t dim, bool add) { size_t i,j,new_j,org_j; new_j = org_j = pos[0]*2; bound_set_array(dst,src,matsize(pos[0])); for (j=0;j=size_org_line) break; /* partial block */ bound_set_array(new_c+new_i,org_c+org_i,last_org_i-org_i); new_i += last_org_i-org_i; org_i = last_org_i; /* skip elems */ if (add) new_i += 2*mult; else org_i += 2*mult; } /* copy remaining elems */ bound_set_array(new_c+new_i,org_c+org_i,size_org_line-org_i); /* next line */ org_c += size_org_line; new_c += size_new_line; } } } } oct_t* oct_add_dimensions(ap_manager_t* man, bool destructive, oct_t* a, ap_dimchange_t* dimchange, bool project) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_ADD_DIMENSIONS,0); bound_t* m = a->closed ? a->closed : a->m; bound_t* mm; size_t i, nb = dimchange->intdim+dimchange->realdim; oct_t* r; if (!m) mm = NULL; else { /* check */ for (i=0;idim[i]<=a->dim,return NULL;); arg_assert(!i || dimchange->dim[i-1]<=dimchange->dim[i],return NULL;); } /* insert variables */ mm = hmat_alloc_top(pr,a->dim+nb); hmat_addrem_dimensions(mm,m,dimchange->dim, nb,1,a->dim,true); /* set new variables to 0, if necessary */ if (project) { for (i=0;idim[i]); bound_set_int(mm[matpos(v+1,v)],0); bound_set_int(mm[matpos(v,v+1)],0); } } } /* always exact, respect closure if embedding, not projecting */ if (a->closed && !project) r = oct_set_mat(pr,a,NULL,mm,destructive); else r = oct_set_mat(pr,a,mm,NULL,destructive); r->dim += nb; r->intdim += dimchange->intdim; return r; } oct_t* oct_remove_dimensions(ap_manager_t* man, bool destructive, oct_t* a, ap_dimchange_t* dimchange) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_REMOVE_DIMENSIONS,0); bound_t *m, *mm; size_t i, nb = dimchange->intdim+dimchange->realdim; oct_t* r; if (pr->funopt->algorithm>=0) oct_cache_closure(pr,a); m = a->closed ? a->closed : a->m; if (!m) mm = NULL; else { /* check */ for (i=0;idim[i]dim,return NULL;); arg_assert(!i || dimchange->dim[i-1]dim[i],return NULL;); } /* remove variables */ mm = hmat_alloc(pr,a->dim-nb); hmat_addrem_dimensions(mm,m,dimchange->dim, nb,1,a->dim,false); } if (a->closed) { /* result is exact on Q, and closed */ if (num_incomplete || a->intdim) flag_incomplete; r = oct_set_mat(pr,a,NULL,mm,destructive); } else { /* not exact, not closed */ flag_algo; r = oct_set_mat(pr,a,mm,NULL,destructive); } r->dim -= nb; r->intdim -= dimchange->intdim; return r; } /* internal helper function: permute & change dimension */ void hmat_permute(bound_t* dst, bound_t* src, size_t dst_dim, size_t src_dim, ap_dim_t* permutation) { size_t i,j; for (i=0;i= 2*dst_dim) { src+=4*(i+1); continue; } for (j=0;j<=i;j++,src+=2) { size_t new_jj = 2*permutation[j]; if (new_jj >= 2*dst_dim) continue; bound_set(dst[matpos2(new_ii ,new_jj )],src[0]); bound_set(dst[matpos2(new_ii ,new_jj+1)],src[1]); bound_set(dst[matpos2(new_ii+1,new_jj )],src[2*(i+1)]); bound_set(dst[matpos2(new_ii+1,new_jj+1)],src[2*(i+1)+1]); } src+=2*(i+1); } } oct_t* oct_permute_dimensions(ap_manager_t* man, bool destructive, oct_t* a, ap_dimperm_t* permutation) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_ADD_DIMENSIONS,0); bound_t* m = a->closed ? a->closed : a->m; bound_t* mm; arg_assert(permutation->size==a->dim,return NULL;); if (!m) mm = NULL; else { /* check (only bounds, not injectivity) */ size_t i,j; for (i=0;idim;i++) arg_assert(permutation->dim[i]dim,return NULL;); /* permuted copy */ mm = hmat_alloc(pr,a->dim); hmat_permute(mm,m,a->dim,a->dim,permutation->dim); } /* always exact, respects closure */ if (a->closed) return oct_set_mat(pr,a,NULL,mm,destructive); else return oct_set_mat(pr,a,mm,NULL,destructive); } /* ============================================================ */ /* Expansion and folding of dimensions */ /* ============================================================ */ oct_t* oct_expand(ap_manager_t* man, bool destructive, oct_t* a, ap_dim_t dim, size_t n) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_EXPAND,0); bound_t* m = a->closed ? a->closed : a->m; size_t i, j; ap_dim_t pos = (dim < a->intdim) ? a->intdim : a->dim; bound_t* mm; oct_t* r; arg_assert(dimdim,return NULL;); if (!m) mm = NULL; else { /* insert n variables at pos */ mm = hmat_alloc_top(pr,a->dim+n); hmat_addrem_dimensions(mm,m,&pos,1,n,a->dim,true); for (i=0;idim+n);j++) { bound_set(mm[matpos2(2*(pos+i) ,j)],mm[matpos(j^1,2*dim+1)]); bound_set(mm[matpos2(2*(pos+i)+1,j)],mm[matpos(j^1,2*dim)]); } /* copy unary constraints */ bound_set(mm[matpos2(2*(pos+i),2*(pos+i)+1)],mm[matpos2(2*dim,2*dim+1)]); bound_set(mm[matpos2(2*(pos+i)+1,2*(pos+i))],mm[matpos2(2*dim+1,2*dim)]); } } /* exact, generally not closed */ r = oct_set_mat(pr,a,mm,NULL,destructive); r->dim += n; if (dimintdim) r->intdim += n; return r; } oct_t* oct_fold(ap_manager_t* man, bool destructive, oct_t* a, ap_dim_t* tdim, size_t size) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_FOLD,matsize(a->dim)); bound_t* m; bound_t* mm; oct_t* r; if (pr->funopt->algorithm>=0) oct_cache_closure(pr,a); m = a->closed ? a->closed : a->m; if (!m) mm = NULL; else { /* check, assuming tdim[0..(size-1)] is strictly increasing */ size_t i,j; arg_assert(size>0,return NULL;); for (i=1;idim,return NULL;); bound_set_array(pr->tmp,m,matsize(a->dim)); /* merge binary constraints */ for (j=0;j<2*tdim[0];j++) { bound_t* mm1 = pr->tmp+matpos2(tdim[0]*2 ,j); bound_t* mm2 = pr->tmp+matpos2(tdim[0]*2+1,j); for (i=1;idim;j++) { bound_t* mm1 = pr->tmp+matpos2(tdim[0]*2 ,j); bound_t* mm2 = pr->tmp+matpos2(tdim[0]*2+1,j); for (i=1;itmp+matpos2(tdim[0]*2 ,tdim[0]*2+1); bound_t* mm2 = pr->tmp+matpos2(tdim[0]*2+1,tdim[0]*2 ); for (i=1;idim-size+1); hmat_addrem_dimensions(mm,pr->tmp,tdim+1,size-1,1,a->dim,false); /* reset diagonal elements */ bound_set_int(mm[matpos(tdim[0]*2 ,tdim[0]*2 )],0); bound_set_int(mm[matpos(tdim[0]*2+1,tdim[0]*2+1)],0); man->result.flag_exact = false; } if (a->closed) { /* result is optimal on Q, not closed */ if (num_incomplete || a->intdim) flag_incomplete; r = oct_set_mat(pr,a,mm,NULL,destructive); } else { /* not exact, not closed */ flag_algo; r = oct_set_mat(pr,a,mm,NULL,destructive); } r->dim -= size-1; if (tdim[0]intdim) r->intdim -= size-1; return r; } apron-dist-0.9.10/apron/octagons/sedscript_c0000640014525101416610000000017710644461001020727 0ustar bjeannetpoparts/struct ap_texpr_op_t/ap_texpr_op_t/g s/struct ap_texpr_rtype_t/ap_texpr_rtype_t/g s/struct ap_texpr_rdir_t/ap_texpr_rdir_t/g apron-dist-0.9.10/apron/octagons/README0000640014525101416610000001301410644461001017354 0ustar bjeannetpopart# README # # Installation documentation # # APRON Library / Octagonal Domain # # Copyright (C) Antoine Mine' 2006 # This file is part of the APRON Library, released under LGPL license. # Please read the COPYING file packaged in the distribution This package is a implementation of the octagon abstract domain that conforms to the APRON interface. It includes both a C and a OCaml interface. DOCUMENTATION ============= This file presents installation instructions only. Please see the oct_doc.html file for how to use the octagon library. Actually, the oct_doc.html only documents only those features that are specific to the octagon implementation. For other features, you should read the generic APRON documentation. EASY START ========== The main APRON makefile (likely ../Makefile) should automatically build and install the octagon library. Actually, it only builds the most useful parts: the C libraries using GMP integers (liboctZg.a) and using doubles (liboctFd.a) as well as the OCaml wrapper (oct.cm(x)a) (provided HAS_OCAML has been defined in Makefile.config). The rest documents some extra things you can do by calling directly the Makefile in the octagon directory. C LIBRARY ========= Requirements: * the APRON library * the ITV and NUM libraries * the MPFR and GMP libraries Provided libraries. Several versions of the octagon domain are provided, based on different internal representation for numbers. They are distinguished by a two-letter "numeric suffix": * Il : integers with a plain "long int" representation * Ill : integers with a "long long int" representation * MPZ : arbitrary precision integers using GMP * Rl : rationals with a "long int" representation * Rll : rationals with a "long long int" representation * MPQ : arbitrary precision rationals using GMP * D : reals with a "double" representation * Dl reals with a "long double" representation Given the numeric suffix Xx, the library is named liboctXx.a. How to compile (given a numeric suffix Xx): 1) the parent directory must contain a Makefile.config file 2) make sure the Makefile.config has the following variables defined: OCT_PREFIX where to install the octagon library APRON_PREFIX where the apron module from APRON is installed NUM_PREFIX where the num module from APRON is installed GMP_PREFIX where the GMP library is installed 3) if you just check-out the SVN distribution, you need to "make rebuild" if you use a stable tarball distribution, this is not necessary 4) "make Xx" 5) "make install" will install the compiled C library(ies) in OCT_PREFIX/lib, and the headers in OCT_PREFIX/include/oct Note that "make all" is a shortcut for "make Il Ill ... Dl", that is, it builds all C libraries. SELF-TEST ========= The distribution contains a self-testing utility. Given the numeric suffix Xx, the utility is names octtestXx Requirements: * All of the above * the newpolka module for APRON How to use (given a numeric suffix Xx): 1) make sure the Makefile.config file has the POLKA_PREFIX variable defined 2) type "make octtestXx" 3) run with "./octtestXx" The self-test compares the result on the octagon domain and the polyhedron domain to check for soundness. It generates random constraints, and so, its result vary from run to run. For each test, a character is displayed. Generally, '*' means a result as good as in polyhedra, 'x' means an optimal octagonal result, 'o' means an empty result, '=', '<' and '>' compare the precision of two octagon transfer functions and '.' just means a correct result. The test should not produce any error. Please report any error encountered! OCAML LIBRARY ============= Requirements: * OCaml 3.09 * the GMP and MPFR libraries * the APRON library (including the apron, num, itv, mlgmpidl, and mlapronidl modules) How to compile the library: 1) make sure the Makefile.config has the following variables defined: CAML_PREFIX where the standard OCaml distribution is installed (without the /bin/ocaml suffix) MLAPRONIDL_PREFIX where the OCaml binding for APRON is installed MLGMPIDL_PREFIX where the OCaml binding for GMP from APRON is installed 2) "make ml" 3) "make install" will install the OCaml module(s) in OCT_PREFIX/lib "make rebuild" will generate some .ml, .mli, .c source files from the .idl files (and some sed scripts). This is only needed if you check-out from SVN as the generated files are provided in tarballs (to ease installation). The library to link with is called oct.cma, for byte-code, and oct.cmxa for native code. The corresponding module is called Oct. There is no numeric suffix here: the OCaml wrapper is independent from the number representation chosen. When building OCaml programs, you must link with both: - the generic OCaml library oct.cma or oct.cmxa - the C octagon library with the desired suffix. and all the apron & gmp libraries. See mltest.ml for an example. Top-level & byte-code runtime can be compiling using "make mlXx". Here, you must tell with numeric suffix "Xx" you wish to use. "make install" will install them in OCT_PREFIX/bin. CLEANING ======== "make clean" will delete all object files, but not auto-generated sources. "make mostlyclean" will also delete sources generated from idl files (only relevant for the OCaml library). After mostlyclean-ing, you will need to rebuild them manually with "make rebuild". This requires CAMLIDL_PREFIX to be setup properly in ../Makefile.config. "make distclean" will clean all objects (not auto-generated sources) and uninstall them. apron-dist-0.9.10/apron/octagons/tmp/0000750014525101416610000000000011252216517017302 5ustar bjeannetpopartapron-dist-0.9.10/apron/octagons/tmp/interval.idl0000640014525101416610000001133511252216517021624 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \n\ #include \"ap_coeff.h\"\n\ #include \"apron_caml.h\"\n\ ") import "scalar.idl"; /* For ap_interval_t, - the conversion from ML to C may use allocation, but it is automatically freed by Camlidl mechanisms - the conversion from C to ML duplicate the C allocated memory. Hence, the C type should be explicitly deallocated (if allocated from the underlying C function) */ struct ap_interval_t { [ref,mlname(mutable_inf)] ap_scalar_t* inf; [ref,mlname(mutable_sup)] ap_scalar_t* sup; }; typedef [ref]struct ap_interval_t* ap_interval_ptr; struct ap_interval_array_t { [size_is(size)]ap_interval_ptr* p; int size; }; quote(MLMLI,"(** APRON Intervals on scalars *)\n\n") quote(MLI,"\n\ val of_scalar : Scalar.t -> Scalar.t -> t\n\ (** Build an interval from a lower and an upper bound *)\n\ val of_infsup : Scalar.t -> Scalar.t -> t\n\ (** depreciated *)\n\ \n\ val of_mpq : Mpq.t -> Mpq.t -> t\n\ val of_mpqf : Mpqf.t -> Mpqf.t -> t\n\ val of_int : int -> int -> t\n\ val of_frac : int -> int -> int -> int -> t\n\ val of_float : float -> float -> t\n\ val of_mpfr : Mpfr.t -> Mpfr.t -> t\n\ (** Create an interval from resp. two\n\ - multi-precision rationals [Mpq.t] \n\ - multi-precision rationals [Mpqf.t] \n\ - integers \n\ - fractions [x/y] and [z/w]\n\ - machine floats\n\ - Mpfr floats\n\ *)\n\ \n\ val is_top : t -> bool\n\ (** Does the interval represent the universe ([[-oo,+oo]]) ? *)\n\ \n\ val is_bottom : t -> bool\n\ (** Does the interval contain no value ([[a,b]] with a>b) ? *)\n\ \n\ val is_leq : t -> t -> bool\n\ (** Inclusion test. [is_leq x y] returns [true] if [x] is included in [y] *)\n\ \n\ val cmp : t -> t -> int\n\ (** Non Total Comparison:\n\ 0: equality\n\ -1: i1 included in i2\n\ +1: i2 included in i1\n\ -2: i1.inf less than or equal to i2.inf\n\ +2: i1.inf greater than i2.inf\n\ *)\n\ val equal : t -> t -> bool\n\ (** Equality test *)\n\ val is_zero : t -> bool\n\ (** Is the interval equal to [0,0] ? *)\n\ val equal_int : t -> int -> bool\n\ (** Is the interval equal to [i,i] ? *)\n\ val neg : t -> t\n\ (** Negation *)\n\ val top : t\n\ val bottom : t\n\ (** Top and bottom intervals (using [DOUBLE] coefficients) *)\n\ \n\ val set_infsup : t -> Scalar.t -> Scalar.t -> unit\n\ (** Fill the interval with the given lower and upper bouunds *)\n\ \n\ val set_top : t -> unit\n\ val set_bottom : t -> unit\n\ (** Fill the interval with top (resp. bottom) value *)\n\ \n\ val print : Format.formatter -> t -> unit\n\ (** Print an interval, under the format [[inf,sup]] *)\n\ ") quote(ML,"\n\ let of_scalar inf sup = { inf = inf; sup = sup }\n\ let of_infsup = of_scalar\n\ let of_mpq x y = { \n\ inf = Scalar.of_mpq x;\n\ sup = Scalar.of_mpq y\n\ }\n\ let of_mpqf x y = {\n\ inf = Scalar.of_mpqf x;\n\ sup = Scalar.of_mpqf y\n\ }\n\ let of_int x y = {\n\ inf = Scalar.of_int x;\n\ sup = Scalar.of_int y\n\ }\n\ let of_frac x y z w = {\n\ inf = Scalar.of_frac x y;\n\ sup = Scalar.of_frac z w\n\ }\n\ let of_float x y = {\n\ inf = Scalar.of_float x;\n\ sup = Scalar.of_float y\n\ }\n\ let of_mpfr x y = {\n\ inf = Scalar.of_mpfr x;\n\ sup = Scalar.of_mpfr y\n\ }\n\ let is_top itv =\n\ Scalar.is_infty itv.inf < 0 && Scalar.is_infty itv.sup > 0\n\ let is_bottom itv =\n\ Scalar.cmp itv.inf itv.sup > 0\n\ let is_leq itv1 itv2 =\n\ Scalar.cmp itv1.inf itv2.inf >= 0 &&\n\ Scalar.cmp itv1.sup itv2.sup <= 0\n\ let cmp itv1 itv2 =\n\ let s1 = Scalar.cmp itv1.inf itv2.inf in\n\ let s2 = Scalar.cmp itv1.sup itv2.sup in\n\ if s1=0 && s2=0 then 0\n\ else if s1>=0 && s2<=0 then -1\n\ else if s1<=0 && s2>=0 then 1\n\ else if s1<=0 then -2\n\ else 2\n\ let equal itv1 itv2 =\n\ Scalar.equal itv1.inf itv2.inf &&\n\ Scalar.equal itv1.sup itv2.sup \n\ let is_zero itv =\n\ Scalar.sgn itv.inf=0 && Scalar.sgn itv.sup = 0\n\ let equal_int itv b = \n\ Scalar.equal_int itv.inf b && Scalar.equal_int itv.sup b\n\ let neg itv = \n\ { inf = Scalar.neg itv.sup; sup = Scalar.neg itv.inf }\n\ let top = { inf = Scalar.Float neg_infinity; sup = Scalar.Float infinity }\n\ let bottom = { inf = Scalar.Float infinity; sup = Scalar.Float neg_infinity }\n\ let set_infsup itv inf sup =\n\ itv.inf <- inf;\n\ itv.sup <- sup\n\ let set_top itv =\n\ itv.inf <- Scalar.Float neg_infinity;\n\ itv.sup <- Scalar.Float infinity\n\ let set_bottom itv =\n\ itv.inf <- Scalar.Float infinity;\n\ itv.sup <- Scalar.Float neg_infinity\n\ let print fmt itv =\n\ Format.fprintf fmt \"[@[%a;@ %a@]]\"\n\ Scalar.print itv.inf Scalar.print itv.sup\n\ ") apron-dist-0.9.10/apron/octagons/tmp/generator1.idl0000640014525101416610000002235511252216517022053 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \n\ #include \"ap_generator1.h\"\n\ #include \"apron_caml.h\"\n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; import "linexpr0.idl"; import "generator0.idl"; import "environment.idl"; import "linexpr1.idl"; struct ap_generator1_t { [mlname(mutable_generator0)] struct ap_generator0_t generator0; [mlname(mutable_env)]ap_environment_ptr env; }; struct ap_generator1_array_t { [mlname(mutable_generator0_array)] struct ap_generator0_array_t generator0_array; [mlname(mutable_array_env)] ap_environment_ptr env; }; quote(MLMLI,"(** APRON Generators and array of generators of level 1 *)") quote(MLMLI,"\n\ type typ = Generator0.typ = \n\ | LINE\n\ | RAY\n\ | VERTEX\n\ | LINEMOD\n\ | RAYMOD\n\ ") quote(MLI,"\n\ (** Make a generator. Modifying later the linear expression ({e not\n\ advisable}) modifies correspondingly the generator and conversely,\n\ except for changes of environements *)\n\ val make: Linexpr1.t -> Generator0.typ -> t\n\ \n\ (** Copy (deep copy) *)\n\ val copy: t -> t\n\ \n\ (** Print the generator *)\n\ val print : Format.formatter -> t -> unit\n\ \n\ (** Get the generator type *)\n\ val get_typ: t -> Generator0.typ\n\ \n\ (** Iter the function on the pair coefficient/variable of the underlying linear\n\ expression *)\n\ val iter: (Coeff.t -> Var.t -> unit) -> t -> unit\n\ \n\ (** Set the generator type *)\n\ val set_typ: t -> Generator0.typ -> unit\n\ \n\ (** Set simultaneously a number of coefficients.\n\ \n\ [set_list expr [(c1,\"x\"); (c2,\"y\")]] assigns coefficients [c1] \n\ to variable [\"x\"] and coefficient [c2] to variable [\"y\"]. *)\n\ val set_list : t -> (Coeff.t * Var.t) list -> unit\n\ \n\ (** Set simultaneously a number of coefficients, as [set_list]. *)\n\ val set_array : t -> (Coeff.t * Var.t) array -> unit\n\ \n\ ") quote(MLI,"(** Get the coefficient of the variable in the underlying linear expression *)") struct ap_coeff_t ap_generator1_get_coeff([ref]struct ap_generator1_t* a, ap_var_t var) quote(call, "\n\ {\n\ bool b;\n\ ap_coeff_init(&_res,AP_COEFF_SCALAR);\n\ b = ap_generator1_get_coeff(&_res,a,var);\n\ if (b){\n\ char str[160];\n\ char* name;\n\ ap_coeff_clear(&_res);\n\ name = ap_var_operations->to_string(var);\n\ snprintf(str,159,\"Generator1.get_coeff: unknown variable %s in the environment\",name);\n\ free(name);\n\ caml_failwith(str);\n\ }\n\ }\n\ ") quote(dealloc,"ap_coeff_clear(&_res);"); quote(MLI,"(** Set the coefficient of the variable in the underlying linear expression *)") void ap_generator1_set_coeff([ref]struct ap_generator1_t* a, ap_var_t var, [ref]struct ap_coeff_t* coeff) quote(call, "\n\ {\n\ bool b;\n\ b = ap_generator1_set_coeff(a,var,coeff);\n\ if (b){\n\ char str[160];\n\ char* name;\n\ name = ap_var_operations->to_string(var);\n\ snprintf(str,159,\"Generator1.set_coeff: unknown variable %s in the environment\",name);\n\ free(name);\n\ caml_failwith(str);\n\ }\n\ }"); quote(MLI,"(** Change the environement of the generator for a super-environement. Raise [Failure] if it is not the case *)") struct ap_generator1_t ap_generator1_extend_environment(const struct ap_generator1_t generator, ap_environment_ptr env) quote(call,"\n\ {\n\ bool b;\n\ b = ap_generator1_extend_environment(&_res,&generator,env);\n\ if (b) caml_failwith(\"Generator1.extend_environment: new environment is not a superenvironment\");\n\ }") ; quote(MLI,"(** Side-effect version of the previous function *)") void ap_generator1_extend_environment_with(struct ap_generator1_t generator, ap_environment_ptr env) quote(call,"\n\ {\n\ if (generator.env!=env){ \n\ bool b;\n\ ap_environment_copy(generator.env); /* to protect it */ \n\ b = ap_generator1_extend_environment_with(&generator,env);\n\ if (b){ \n\ ap_environment_free(generator.env); \n\ caml_failwith(\"Generator1.extend_environment_with: new environment is not a superenvironment\");\n\ }\n\ Store_field(_v_generator,1,_v_env);\n\ ap_environment_free(env);\n\ }\n\ }") ; quote(ML,"\n\ let make linexpr1 gentyp = {\n\ generator0 = {\n\ Generator0.linexpr0 = linexpr1.Linexpr1.linexpr0;\n\ Generator0.typ = gentyp;\n\ };\n\ env = linexpr1.Linexpr1.env;\n\ }\n\ let copy gen = {\n\ generator0 = Generator0.copy gen.generator0;\n\ env = gen.env;\n\ }\n\ let print fmt gen = \n\ Generator0.print\n\ (fun dim -> Var.to_string (Environment.var_of_dim gen.env dim)) fmt gen.generator0;\n \ ()\n\ let get_typ gen = gen.generator0.Generator0.typ\n\ let set_typ gen typ = gen.generator0.Generator0.typ <- typ\n\ let get_generator0 gen = gen.generator0\n\ let get_env gen = gen.env\n\ let set_list expr list = \n\ List.iter\n\ (fun (coeff,var) -> set_coeff expr var coeff )\n\ list;\n\ ()\n\ let set_array expr tab = \n\ Array.iter\n\ (fun (coeff,var) -> set_coeff expr var coeff )\n\ tab;\n\ ()\n\ \n\ let iter f gen =\n\ Linexpr0.iter\n\ (begin fun coeff dim ->\n\ f coeff (Environment.var_of_dim gen.env dim)\n\ end)\n\ gen.generator0.Generator0.linexpr0\n\ let get_linexpr1 gen = {\n\ Linexpr1.linexpr0 = gen.generator0.Generator0.linexpr0;\n\ Linexpr1.env = gen.env;\n\ }") quote(MLMLI,"(* ====================================================================== *)") quote(MLMLI,"(** {2 Type earray} *)") quote(MLMLI,"(* ====================================================================== *)") quote(MLI,"\n\ (** Make an array of generators with the given size and defined on the\n\ given environement. The elements are initialized with the line 0. *)\n\ val array_make : Environment.t -> int -> earray\n\ \n\ (** Print an array of generators *)\n\ val array_print :\n\ ?first:(unit, Format.formatter, unit) format ->\n\ ?sep:(unit, Format.formatter, unit) format ->\n\ ?last:(unit, Format.formatter, unit) format ->\n\ Format.formatter -> earray -> unit\n\ \n\ (** Get the size of the array *)\n\ val array_length : earray -> int\n\ \n\ (** Get the element of the given index (which is not a copy) *)\n\ val array_get : earray -> int -> t\n\ \n\ (** Set the element of the given index (without any copy). The array and the\n\ generator should be defined on the same environement; otherwise a [Failure]\n\ exception is raised.*)\n\ val array_set : earray -> int -> t -> unit\n\ ") quote(MLI,"(** Change the environement of the array of generators for a super-environement. Raise [Failure] if it is not the case*)") struct ap_generator1_array_t ap_generator1_array_extend_environment(const struct ap_generator1_array_t array, ap_environment_ptr env) quote(call,"\n\ {\n\ bool b;\n\ b = ap_generator1_array_extend_environment(&_res,&array,env);\n\ if (b) caml_failwith(\"Generator1.array_extend_environment: new environment is not a superenvironment\");\n\ }") ; quote(MLI,"(** Side-effect version of the previous function *)") void ap_generator1_array_extend_environment_with(struct ap_generator1_array_t array, ap_environment_ptr env) quote(call,"\n\ {\n\ if (array.env!=env){ \n\ bool b;\n\ ap_environment_copy(array.env); /* to protect it */ \n\ b = ap_generator1_array_extend_environment_with(&array,env);\n\ if (b){ \n\ ap_environment_free(array.env); \n\ caml_failwith(\"Generator1.array_extend_environment_with: new environment is not a superenvironment\");\n\ }\n\ Store_field(_v_array,1,_v_env);\n\ ap_environment_free(env);\n\ }\n\ }") ; quote(MLI,"\n\ (** Get the environement of the generator *)\n\ val get_env: t -> Environment.t\n\ \n\ (** Get the underlying linear expression. Modifying the linear expression ({e\n\ not advisable}) modifies correspondingly the generator and\n\ conversely, except for changes of environements *)\n\ val get_linexpr1: t -> Linexpr1.t\n\ \n\ (** Get the underlying generator of level 0. Modifying the generator\n\ of level 0 ({e not advisable}) modifies correspondingly the generator\n\ and conversely, except for changes of environements*)\n\ val get_generator0: t -> Generator0.t\n\ ") quote(ML,"\n\ let array_make env size =\n\ let gen = Generator0.make (Linexpr0.make None) Generator0.LINE in\n\ {\n\ generator0_array = Array.make size gen;\n\ array_env = env\n\ }\n\ let array_print\n\ ?(first=(\"[|@[\":(unit,Format.formatter,unit) format))\n\ ?(sep = (\";@ \":(unit,Format.formatter,unit) format))\n\ ?(last = (\"@]|]\":(unit,Format.formatter,unit) format))\n\ fmt array \n\ = \n\ Abstract0.print_array ~first ~sep ~last\n\ (Generator0.print\n\ (fun dim -> Var.to_string (Environment.var_of_dim array.array_env dim)))\n \ fmt array.generator0_array;\n\ ()\n\ let array_length array = Array.length (array.generator0_array)\n\ let array_get array index =\n\ let gen0 = array.generator0_array.(index) in\n\ { generator0 = gen0; env = array.array_env; }\n\ let array_set array index gen1 =\n\ if not (Environment.equal array.array_env gen1.env) then\n\ failwith \"Expr1.array_set: environments are not the same\"\n\ else\n\ array.generator0_array.(index) <- gen1.generator0;\n\ ") apron-dist-0.9.10/apron/octagons/tmp/lincons0.idl0000640014525101416610000000755711252216517021540 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(MLI,"(** APRON Linear constraints of level 0 *)") quote(C, "\n\ #include \n\ #include \"ap_lincons0.h\"\n\ #include \"apron_caml.h\"\n\ \n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; import "linexpr0.idl"; /* For ap_lincons0_t, - the conversion from ML to C may use allocation, but it is automatically freed by Camlidl mechanisms - the conversion from C to ML free after conversion the scalar field in the C structure. the C type should NOT be deallocated */ quote(C,"\n\ void camlidl_apron_lincons0_ml2c(value v,ap_lincons0_t* cons, camlidl_ctx _ctx)\n\ {\n\ value _v_linexpr0;\n\ value _v_constyp;\n\ value _v_scalar;\n\ \n\ _v_linexpr0 = Field(v,0);\n\ camlidl_apron_linexpr0_ptr_ml2c(_v_linexpr0,&cons->linexpr0);\n\ _v_constyp = Field(v,1);\n\ if (Is_long(_v_constyp)){\n\ switch (Int_val(_v_constyp)){ case 0:\n\ case 1:\n\ case 2:\n\ cons->constyp = Int_val(_v_constyp);\n\ break;\n\ case 3:\n\ cons->constyp = 4;\n\ break;\n\ default:\n\ abort();\n\ }\n\ cons->scalar = NULL;\n\ }\n\ else {\n\ switch (Tag_val(_v_constyp)){\n\ case 0:\n\ cons->constyp = AP_CONS_EQMOD;\n\ _v_scalar = Field(_v_constyp,0);\n\ cons->scalar = (ap_scalar_t *)camlidl_malloc(sizeof(ap_scalar_t),_ctx);\n\ camlidl_apron_scalar_ml2c(_v_scalar,cons->scalar);\n\ break;\n\ default:\n\ abort();\n\ }\n\ }\n\ }\n\ value camlidl_apron_lincons0_c2ml(ap_lincons0_t* cons)\n\ {\n\ value vres;\n\ value _v[3];\n\ _v[0] = _v[1] = _v[2] = 0;\n\ \n\ Begin_roots_block(_v, 3)\n\ _v[0] = camlidl_apron_linexpr0_ptr_c2ml(&cons->linexpr0);\n\ switch(cons->constyp){\n\ case AP_CONS_EQ:\n\ case AP_CONS_SUPEQ:\n\ case AP_CONS_SUP:\n\ _v[1] = Val_int(cons->constyp);\n\ break;\n\ case AP_CONS_DISEQ:\n\ _v[1] = Val_int(3);\n\ break;\n\ case AP_CONS_EQMOD:\n\ assert(cons->scalar!=NULL);\n\ _v[2] = camlidl_apron_scalar_c2ml(cons->scalar);\n\ _v[1] = camlidl_alloc_small(1, 0);\n\ Field(_v[1],0) = _v[2];\n\ ap_scalar_free(cons->scalar); cons->scalar = NULL;\n\ break;\n\ }\n\ vres = camlidl_alloc_small(2, 0);\n\ Field(vres, 0) = _v[0];\n\ Field(vres, 1) = _v[1];\n\ End_roots()\n\ return vres;\n\ }\n\ ") typedef [mltype("{\n mutable linexpr0 : Linexpr0.t;\n mutable typ : typ;\n}"), abstract, ml2c(camlidl_apron_lincons0_ml2c), c2ml(camlidl_apron_lincons0_c2ml)] struct ap_lincons0_t ap_lincons0_t; quote(MLMLI,"and typ =\n | EQ\n | SUPEQ\n | SUP\n | DISEQ\n | EQMOD of Scalar.t\n") struct ap_lincons0_array_t { [size_is(size)] ap_lincons0_t* p; int size; }; quote(MLI,"\n\ (** Make a linear constraint. Modifying later the linear expression\n\ modifies correspondingly the linear constraint and conversely *)\n\ val make : Linexpr0.t -> typ -> t\n\ \n\ (** Copy a linear constraint (deep copy) *)\n\ val copy : t -> t\n\ \n\ (** Convert a constraint type to a string ([=],[>=], or [>]) *)\n\ val string_of_typ : typ -> string\n\ \n\ (** Print a constraint *)\n\ val print : (Dim.t -> string) -> Format.formatter -> t -> unit\n\ ") quote(ML,"\n\ let string_of_typ = function\n\ | EQ | EQMOD _ -> \"=\"\n\ | SUPEQ -> \">=\"\n\ | SUP -> \">\"\n\ | DISEQ -> \"<>\"\n\ \n\ let print assoc fmt cons = \n\ Linexpr0.print assoc fmt cons.linexpr0;\n\ Format.fprintf fmt \"%s0\" (string_of_typ cons.typ);\n\ begin match cons.typ with\n\ | EQMOD x -> Format.fprintf fmt \" mod %a\" Scalar.print x;\n\ | _ -> ()\n\ end;\n\ ()\n\ let make expr typ = {\n\ linexpr0 = expr; typ = typ \n\ }\n\ let copy cons = {\n\ linexpr0 = Linexpr0.copy cons.linexpr0; typ = cons.typ\n\ }\n\ ") apron-dist-0.9.10/apron/octagons/tmp/scalar.idl0000640014525101416610000001625311252216517021251 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #define HAS_MPFR 1\n\ #include \n\ #include \"ap_coeff.h\"\n\ #include \"gmp_caml.h\"\n\ #include \"apron_caml.h\"\n\ ") /* For ap_scalar_t, - the conversion from ML to C reuse the ML allocated memory - the conversion from C to ML duplicate the C allocated memory. Hence, the C type should be explicitly deallocated (if allocated from the underlying C function) */ quote(C,"\n\ void camlidl_apron_scalar_ml2c(value v, struct ap_scalar_t* scalar)\n\ {\n\ value v2 = Field(v,0);\n\ scalar->discr = Tag_val(v);\n\ switch (scalar->discr) {\n\ case 0: /* DOUBLE */\n\ scalar->val.dbl = Double_val(v2);\n\ break;\n\ case 1: /* MPQ */\n\ scalar->val.mpq = (mpq_ptr)(Data_custom_val(v2));\n\ break;\n\ case 2: /* MPFR */\n\ scalar->val.mpfr = (mpfr_ptr)(Data_custom_val(v2));\n\ break;\n\ default:\n\ caml_failwith(\"unknown scalar discriminant in camlidl_apron_scalar_ml2c\");\n\ }\n\ return;\n\ }\n\ value camlidl_apron_scalar_c2ml(struct ap_scalar_t* scalar)\n\ {\n\ value v,v2;\n\ v2 = Val_unit;\n\ Begin_root(v2);\n\ switch(scalar->discr){\n\ case AP_SCALAR_DOUBLE:\n\ v2 = caml_copy_double(scalar->val.dbl);\n\ break;\n\ case AP_SCALAR_MPQ:\n\ {\n\ mpq_t mpq;\n\ mpq_ptr mpq_ptr = mpq;\n\ mpq_init(mpq);\n\ mpq_set(mpq,scalar->val.mpq);\n\ v2 = camlidl_mpq_ptr_c2ml(&mpq_ptr);\n\ }\n\ break;\n\ case AP_SCALAR_MPFR:\n\ {\n\ mpfr_t mpfr;\n\ mpfr_ptr mpfr_ptr = mpfr;\n\ mpfr_init2(mpfr,mpfr_get_prec(scalar->val.mpfr));\n\ mpfr_set(mpfr,scalar->val.mpfr,GMP_RNDU /* exact */);\n\ v2 = camlidl_mpfr_ptr_c2ml(&mpfr_ptr);\n\ }\n\ break;\n\ default:\n\ caml_failwith(\"unknown scalar discriminant in camlidl_apron_scalar_c2ml\");\n\ }\n\ v = alloc_small(1,scalar->discr);\n\ Field(v,0) = v2;\n\ End_roots();\n\ return v;\n\ }\n\ ") typedef [mltype("Float of float | Mpqf of Mpqf.t | Mpfrf of Mpfrf.t"), abstract, ml2c(camlidl_apron_scalar_ml2c), c2ml(camlidl_apron_scalar_c2ml)] struct ap_scalar_t ap_scalar_t; typedef [ref]ap_scalar_t* ap_scalar_ptr; struct ap_scalar_array_t { [size_is(size)]ap_scalar_ptr* p; int size; }; quote(MLMLI,"(** APRON Scalar numbers. See {!Mpqf} for operations on GMP multiprecision rational numbers and {!Mpfr} for operations on MPFR multi-precision floating-point numbers. *)\n\n") quote(MLI,"\n\ val of_mpq : Mpq.t -> t\n\ val of_mpqf : Mpqf.t -> t\n\ val of_int : int -> t\n\ val of_frac : int -> int -> t\n\ (** Create a scalar of type [Mpqf] from resp.\n\ - A multi-precision rational [Mpq.t] \n\ - A multi-precision rational [Mpqf.t] \n\ - an integer \n\ - a fraction [x/y]\n\ *)\n\ \n\ val of_mpfr : Mpfr.t -> t\n\ val of_mpfrf : Mpfrf.t -> t\n\ (** Create a scalar of type [Mpfrf] with the given value *)\n\ val of_float : float -> t\n\ (** Create a scalar of type [Float] with the given value *)\n\ val of_infty : int -> t \n\ (** Create a scalar of type [Float] with the value multiplied by\n\ infinity (resulting in minus infinity, zero, or infinity \n\ *)\n\ val is_infty : t -> int\n\ (** Infinity test.\n\ [is_infty x] returns [-1] if x is [-oo], [1] if x is [+oo], and [0] if [x] is\n\ finite. *)\n\ \n\ val sgn : t -> int\n\ (** Return the sign of the coefficient, which may be a negative value, zero\n\ or a positive value. *)\n\ \n\ val cmp : t -> t -> int\n\ (** Compare two coefficients, possibly converting to [Mpqf.t].\n\ [compare x y] returns a negative number if [x] is less than [y], \n\ [0] if they ar equal, and a positive number if [x] is greater than [y].\n\ *)\n\ \n\ val cmp_int : t -> int -> int\n\ (** Compare a coefficient with an integer *)\n\ \n\ val equal : t -> t -> bool\n\ (** Equality test, possibly using a conversion to [Mpqf.t].\n\ Return [true] if the 2 values are equal. Two infinite values of the same\n\ signs are considered as equal. *)\n\ \n\ val equal_int : t -> int -> bool\n\ (** Equality test with an integer *)\n\ \n\ val neg : t -> t\n\ (** Negation *)\n\ val to_string : t -> string\n\ (** Conversion to string, using [string_of_double], [Mpqf.to_string] or [Mpfr.to_string]\n\ *)\n\ \n\ val print : Format.formatter -> t -> unit\n\ (** Print a coefficient *)\n\ ") quote(ML,"\ let of_mpq x = Mpqf (Mpqf.of_mpq x)\n\ let of_mpqf x = Mpqf x\n\ let of_mpfr x = Mpfrf (Mpfrf.of_mpfr x)\n\ let of_mpfrf x = Mpfrf x\n\ let of_int x = Mpqf(Mpqf.of_int x)\n\ let of_frac x y = Mpqf(Mpqf.of_frac x y)\n\ let of_float x = Float(x)\n\ let of_infty s = \n\ if s>0 then Float(Pervasives.infinity)\n\ else if s<0 then Float(Pervasives.neg_infinity)\n\ else Float(0.0)\n\ let is_infty scalar =\n\ match scalar with\n\ | Mpqf x ->\n\ let z = Mpqf.get_den x in\n\ if Mpzf.sgn z <> 0 then 0\n\ else begin\n\ let z = Mpqf.get_num x in\n\ let sgn = Mpzf.sgn z in\n\ if sgn > 0 then 1 else if sgn < 0 then -1 else 0\n\ end\n\ | Mpfrf x ->\n\ if Mpfrf.inf_p x then\n\ if Mpfrf.sgn x > 0 then 1 else -1\n\ else 0\n\ | Float x ->\n\ if x = Pervasives.infinity then 1\n\ else if x = Pervasives.neg_infinity then -1\n\ else 0\n\ let sgn scalar =\n\ match scalar with\n\ | Mpqf x -> Mpqf.sgn x\n\ | Mpfrf x -> Mpfrf.sgn x\n\ | Float x -> if x > 0.0+.0.0 then 1 else if x < -.0.0 then -1 else 0\n\ let to_mpqf = function\n\ | Mpqf x -> x\n\ | Mpfrf x -> Mpfrf.to_mpqf x\n\ | Float x -> Mpqf.of_float x\n\ let cmp c1 c2 =\n\ let s1 = is_infty c1 in\n\ let s2 = is_infty c2 in\n\ if s1>s2 then 1\n\ else if s1 Mpqf.cmp x1 x2\n\ | (Mpfrf x1, Mpfrf x2) -> Mpfrf.cmp x1 x2\n\ | (Float x1, Float x2) -> if x1>x2 then 1 else if x1 Mpqf.cmp (to_mpqf x1) (to_mpqf x2)\n\ end\n\ let equal c1 c2 =\n\ let s1 = is_infty c1 in\n\ let s2 = is_infty c2 in\n\ if s1!=s2 then false\n\ else if s1!=0 then true\n\ else begin\n\ match (c1,c2) with\n\ | (Mpqf x1, Mpqf x2) -> Mpqf.equal x1 x2\n\ | (Mpfrf x1, Mpfrf x2) -> Mpfrf.cmp x1 x2 = 0\n\ | (Float x1, Float x2) -> x1 = x2\n\ | x1, x2 -> Mpqf.equal (to_mpqf x1) (to_mpqf x2)\n\ end\n\ let cmp_int scalar n =\n\ match scalar with\n\ | Mpqf x -> Mpqf.cmp_int x n\n\ | Mpfrf x -> Mpfrf.cmp_int x n\n\ | Float x -> Pervasives.compare x (float_of_int n)\n\ let equal_int scalar n =\n\ match scalar with\n\ | Mpqf x -> (Mpqf.cmp_int x n)=0\n\ | Mpfrf x -> (Mpfrf.cmp_int x n)=0\n\ | Float x -> x=(float_of_int n)\n\ let neg scalar =\n\ match scalar with\n\ | Mpqf x -> Mpqf(Mpqf.neg x)\n\ | Mpfrf x ->\n\ let y = Mpfr.init2 (Mpfr.get_prec x) in\n\ ignore (Mpfr.neg y x Mpfr.Up);\n\ Mpfrf(Mpfrf.mpfrf y)\n \ | Float x -> Float(-. x)\n\ let to_string scalar =\n\ match scalar with\n\ | Mpqf x -> Mpqf.to_string x\n\ | Mpfrf x -> Mpfrf.to_string x\n\ | Float x -> string_of_float x\n\ let print fmt scalar =\n\ Format.pp_print_string fmt (to_string scalar)\n\ ") apron-dist-0.9.10/apron/octagons/tmp/abstract0.idl0000640014525101416610000007362611252216517021676 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \n\ #include \"ap_expr0.h\"\n\ #include \"ap_abstract0.h\"\n\ #include \"caml/callback.h\"\n\ #include \"apron_caml.h\"\n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; import "linexpr0.idl"; import "lincons0.idl"; import "generator0.idl"; import "texpr0.idl"; import "tcons0.idl"; import "manager.idl"; typedef [abstract, c2ml(camlidl_apron_abstract0_ptr_c2ml), ml2c(camlidl_apron_abstract0_ptr_ml2c)] struct ap_abstract0_ptr ap_abstract0_ptr; quote(MLMLI,"(** APRON Abstract value of level 0 *)") quote(MLMLI,"(** The type parameter ['a] allows to distinguish abstract values with different underlying abstract domains. *)\n") quote(MLI,"\n(** TO BE DOCUMENTED *)") void ap_abstract0_set_gc(int size) quote(call,"camlidl_apron_heap = size;"); quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(** {2 General management} *)") quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Memory} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n(** Copy a value *)") ap_abstract0_ptr ap_abstract0_copy(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Return the abstract size of a value *)") int ap_abstract0_size(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Control of internal representation} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n(** Minimize the size of the representation of the value. This may result in a later recomputation of internal information.*)") void ap_abstract0_minimize(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Put the abstract value in canonical form. (not yet clear definition) *)") void ap_abstract0_canonicalize(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"I0_CHECK_EXC(man)"); int ap_abstract0_hash(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** [approximate man abs alg] perform some transformation on the abstract value, guided by the argument [alg]. The transformation may lose information. The argument [alg] overrides the field algorithm of the structure of type [Manager.funopt] associated to ap_abstract0_approximate (commodity feature).*)") void ap_abstract0_approximate(ap_manager_ptr man, ap_abstract0_ptr a, int v) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Printing} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n(** Dump on the [stdout] C stream the internal representation of an abstract value, for debugging purposes *)") void ap_abstract0_fdump(ap_manager_ptr man, ap_abstract0_ptr a) quote(call,"ap_abstract0_fdump(stdout,man, a); fflush(stdout);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Print as a set of constraints *)") quote(MLI,"val print: (int -> string) -> Format.formatter -> 'a t -> unit") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Serialization} *)") quote(MLMLI,"(* ============================================================ *)") /* membuf_t ap_abstract0_serialize_raw(ap_manager_ptr man, ap_abstract0_ptr a); ap_abstract0_ptr ap_abstract0_deserialize_raw(ap_manager_ptr man, void* ptr); */ quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(** {2 Constructor, accessors, tests and property extraction} *)") quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Basic constructors} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n(** Create a bottom (empty) value with the given number of integer and real variables *)") ap_abstract0_ptr ap_abstract0_bottom(ap_manager_ptr man, int v1, int v2) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Create a top (universe) value with the given number of integer and real variables *)") ap_abstract0_ptr ap_abstract0_top(ap_manager_ptr man, int v1, int v2) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Abstract an hypercube.\n\n[of_box man intdim realdim array] abstracts an hypercube defined by the array of intervals of size [intdim+realdim] *)") ap_abstract0_ptr ap_abstract0_of_box(ap_manager_ptr man, int intdim, int realdim, struct ap_interval_array_t array) quote(call,"_res = ap_abstract0_of_box(man,intdim,realdim,(ap_interval_t**)array.p);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Accessors} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n") struct ap_dimension_t ap_abstract0_dimension(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"I0_CHECK_EXC(man)"); ap_manager_ptr ap_abstract0_manager(ap_abstract0_ptr a) quote(call,"_res = ap_manager_copy(a->man);"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Tests} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n(** Emptiness test *)") boolean ap_abstract0_is_bottom(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Universality test *)") boolean ap_abstract0_is_top(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Inclusion test. The 2 abstract values should be compatible. *)") boolean ap_abstract0_is_leq(ap_manager_ptr man, ap_abstract0_ptr a1, ap_abstract0_ptr a2) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Equality test. The 2 abstract values should be compatible. *)") boolean ap_abstract0_is_eq(ap_manager_ptr man, ap_abstract0_ptr a1, ap_abstract0_ptr a2) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Does the abstract value satisfy the linear constraint ? *)") boolean ap_abstract0_sat_lincons(ap_manager_ptr man, ap_abstract0_ptr a, [ref]ap_lincons0_t* v) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Does the abstract value satisfy the tree expression constraint ? *)") boolean ap_abstract0_sat_tcons(ap_manager_ptr man, ap_abstract0_ptr a, [ref]ap_tcons0_t* v) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Does the abstract value satisfy the constraint [dim in interval] ? *)") boolean ap_abstract0_sat_interval(ap_manager_ptr man, ap_abstract0_ptr a, ap_dim_t v1, [ref]struct ap_interval_t* v2) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Is the dimension unconstrained in the abstract value ? If yes, this means that the existential quantification of the dimension does not change the value. *)") boolean ap_abstract0_is_dimension_unconstrained(ap_manager_ptr man, ap_abstract0_ptr a, ap_dim_t v); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Extraction of properties} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n(** Return the interval of variation of the dimension in the abstract value. *)") [ref]struct ap_interval_t* ap_abstract0_bound_dimension(ap_manager_ptr man, ap_abstract0_ptr a, ap_dim_t v) quote(dealloc,"ap_interval_free(_res); I0_CHECK_EXC(man)"); quote(MLI,"\n(** Return the interval of variation of the linear expression in the abstract value.\n\nImplement a form of linear programming, where the argument linear expression is the one to optimize under the constraints induced by the abstract value. *)") [ref]struct ap_interval_t* ap_abstract0_bound_linexpr(ap_manager_ptr man, ap_abstract0_ptr a, ap_linexpr0_ptr v) quote(dealloc,"ap_interval_free(_res); I0_CHECK_EXC(man)"); quote(MLI,"\n(** Return the interval of variation of the tree expression in the abstract value. *)") [ref]struct ap_interval_t* ap_abstract0_bound_texpr(ap_manager_ptr man, ap_abstract0_ptr a, ap_texpr0_ptr v) quote(dealloc,"ap_interval_free(_res); I0_CHECK_EXC(man)"); quote(MLI,"\n(** Convert the abstract value to an hypercube *)") struct ap_interval_array_t ap_abstract0_to_box(ap_manager_ptr man, ap_abstract0_ptr a) quote(call,"{\n\ ap_dimension_t dim; _res.p = ap_abstract0_to_box(man,a);\n\ dim = ap_abstract0_dimension(man,a);\n\ _res.size = dim.intdim + dim.realdim;\n\ }") quote(dealloc,"ap_interval_array_free(_res.p, _res.size); I0_CHECK_EXC(man)"); quote(MLI,"\n(** Convert the abstract value to a conjunction of linear constraints. *)") struct ap_lincons0_array_t ap_abstract0_to_lincons_array(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"free(_res.p); I0_CHECK_EXC(man)"); quote(MLI,"\n(** Convert the abstract value to a conjunction of tree expression constraints. *)") struct ap_tcons0_array_t ap_abstract0_to_tcons_array(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"free(_res.p); I0_CHECK_EXC(man)"); quote(MLI,"\n(** Convert the abstract value to a set of generators that defines it. *)") struct ap_generator0_array_t ap_abstract0_to_generator_array(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"free(_res.p); I0_CHECK_EXC(man)"); quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(** {2 Operations} *)") quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Meet and Join} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n") quote(MLI,"(** Meet of 2 abstract values. *)") ap_abstract0_ptr ap_abstract0_meet(ap_manager_ptr man, ap_abstract0_ptr a1, ap_abstract0_ptr a2) quote(call,"_res = ap_abstract0_meet(man,false,a1,a2);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Meet of a non empty array of abstract values. *)") ap_abstract0_ptr ap_abstract0_meet_array(ap_manager_ptr man, [size_is(size)] ap_abstract0_ptr* array, unsigned int size) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Meet of an abstract value with an array of linear constraints. *)") ap_abstract0_ptr ap_abstract0_meet_lincons_array(ap_manager_ptr man, ap_abstract0_ptr a, [ref]struct ap_lincons0_array_t* v) quote(call,"_res = ap_abstract0_meet_lincons_array(man,false,a,v);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Meet of an abstract value with an array of tree expression constraints. *)") ap_abstract0_ptr ap_abstract0_meet_tcons_array(ap_manager_ptr man, ap_abstract0_ptr a, [ref]struct ap_tcons0_array_t* v) quote(call,"_res = ap_abstract0_meet_tcons_array(man,false,a,v);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Join of 2 abstract values. *)") ap_abstract0_ptr ap_abstract0_join(ap_manager_ptr man, ap_abstract0_ptr a1, ap_abstract0_ptr a2) quote(call,"_res = ap_abstract0_join(man,false,a1,a2);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Join of a non empty array of abstract values. *)") ap_abstract0_ptr ap_abstract0_join_array(ap_manager_ptr man, [size_is(size)]ap_abstract0_ptr array[], unsigned int size) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Add the array of generators to the abstract value (time elapse operator).\n\n The generators should either lines or rays, not vertices. *)") ap_abstract0_ptr ap_abstract0_add_ray_array(ap_manager_ptr man, ap_abstract0_ptr a, [ref]struct ap_generator0_array_t* v) quote(call,"_res = ap_abstract0_add_ray_array(man,false,a,v);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** {5 Side-effect versions of the previous functions} *)\n") void ap_abstract0_meet_with(ap_manager_ptr man, ap_abstract0_ptr a1, ap_abstract0_ptr a2) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_meet(man,true,a1,a2);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a1)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_meet_lincons_array_with(ap_manager_ptr man, ap_abstract0_ptr a, [ref]struct ap_lincons0_array_t* v) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_meet_lincons_array(man,true,a,v);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_meet_tcons_array_with(ap_manager_ptr man, ap_abstract0_ptr a, [ref]struct ap_tcons0_array_t* v) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_meet_tcons_array(man,true,a,v);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_join_with(ap_manager_ptr man, ap_abstract0_ptr a1, ap_abstract0_ptr a2) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_join(man,true,a1,a2);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a1)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_add_ray_array_with(ap_manager_ptr man, ap_abstract0_ptr a, [ref]struct ap_generator0_array_t* v) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_add_ray_array(man,true,a,v);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Assignements and Substitutions} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** Parallel assignement of an array of dimensions by an array of same size of linear expressions *)") ap_abstract0_ptr ap_abstract0_assign_linexpr_array(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v3)]ap_dim_t* v1, [size_is(v4)]ap_linexpr0_ptr* v2, int v3, int v4, ap_abstract0_ptr* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract0.assign_linexpr_array: arrays of different size\");\n\ _res = ap_abstract0_assign_linexpr_array(man,false,a,v1,v2,v3,dest==NULL ? NULL : *dest);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Parallel substitution of an array of dimensions by an array of same size of linear expressions *)") ap_abstract0_ptr ap_abstract0_substitute_linexpr_array(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v3)]ap_dim_t* v1, [size_is(v4)]ap_linexpr0_ptr* v2, int v3, int v4, ap_abstract0_ptr* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract0.substitute_linexpr_array: arrays of different size\");\n\ _res = ap_abstract0_substitute_linexpr_array(man,false,a,v1,v2,v3,dest==NULL ? NULL : *dest);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Parallel assignement of an array of dimensions by an array of same size of tree expressions *)") ap_abstract0_ptr ap_abstract0_assign_texpr_array(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v3)]ap_dim_t* v1, [size_is(v4)]ap_texpr0_ptr* v2, int v3, int v4, ap_abstract0_ptr* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract0.assign_texpr_array: arrays of different size\");\n\ _res = ap_abstract0_assign_texpr_array(man,false,a,v1,v2,v3,dest==NULL ? NULL : *dest);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Parallel substitution of an array of dimensions by an array of same size of tree expressions *)") ap_abstract0_ptr ap_abstract0_substitute_texpr_array(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v3)]ap_dim_t* v1, [size_is(v4)]ap_texpr0_ptr* v2, int v3, int v4, ap_abstract0_ptr* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract0.substitute_texpr_array: arrays of different size\");\n\ _res = ap_abstract0_substitute_texpr_array(man,false,a,v1,v2,v3,dest==NULL ? NULL : *dest);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** {5 Side-effect versions of the previous functions} *)\n\n") void ap_abstract0_assign_linexpr_array_with(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v3)]ap_dim_t* v1, [size_is(v4)]ap_linexpr0_ptr* v2, int v3, int v4, ap_abstract0_ptr* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract0.assign_linexpr_array_with: arrays of different size\");\n\ {\n\ ap_abstract0_t* res = ap_abstract0_assign_linexpr_array(man,true,a,v1,v2,v3,dest==NULL ? NULL : *dest);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_substitute_linexpr_array_with(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v3)]ap_dim_t* v1, [size_is(v4)]ap_linexpr0_ptr* v2, int v3, int v4, ap_abstract0_ptr* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract0.substitute_linexpr_array_with: arrays of different size\");\n\ {\n\ ap_abstract0_t* res = ap_abstract0_substitute_linexpr_array(man,true,a,v1,v2,v3,dest==NULL ? NULL : *dest);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_assign_texpr_array_with(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v3)]ap_dim_t* v1, [size_is(v4)]ap_texpr0_ptr* v2, int v3, int v4, ap_abstract0_ptr* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract0.assign_texpr_array_with: arrays of different size\");\n\ {\n\ ap_abstract0_t* res = ap_abstract0_assign_texpr_array(man,true,a,v1,v2,v3,dest==NULL ? NULL : *dest);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_substitute_texpr_array_with(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v3)]ap_dim_t* v1, [size_is(v4)]ap_texpr0_ptr* v2, int v3, int v4, ap_abstract0_ptr* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract0.substitute_texpr_array_with: arrays of different size\");\n\ {\n\ ap_abstract0_t* res = ap_abstract0_substitute_texpr_array(man,true,a,v1,v2,v3,dest==NULL ? NULL : *dest);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n\n") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Projections} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** These functions implements forgeting (existential quantification) of (array of) dimensions. Both functional and side-effect versions are provided. The Boolean, if true, adds a projection onto 0-plane. *)\n\n") ap_abstract0_ptr ap_abstract0_forget_array(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v2)]ap_dim_t* v1, int v2, boolean v3) quote(call,"_res = ap_abstract0_forget_array(man,false,a,v1,v2,v3);") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_forget_array_with(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v2)]ap_dim_t* v1, int v2, boolean v3) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_forget_array(man,true,a,v1,v2,v3);\n \ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Change and permutation of dimensions} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"\n") ap_abstract0_ptr ap_abstract0_add_dimensions(ap_manager_ptr man, ap_abstract0_ptr a, ap_dimchange_t dimchange, boolean project) quote(call,"_res = ap_abstract0_add_dimensions(man,false,a,&dimchange, project);ap_dimchange_clear(&dimchange);") quote(dealloc,"I0_CHECK_EXC(man)"); ap_abstract0_ptr ap_abstract0_remove_dimensions(ap_manager_ptr man, ap_abstract0_ptr a, ap_dimchange_t dimchange) quote(call,"_res = ap_abstract0_remove_dimensions(man,false,a,&dimchange);ap_dimchange_clear(&dimchange);") quote(dealloc,"I0_CHECK_EXC(man)"); ap_abstract0_ptr ap_abstract0_apply_dimchange2(ap_manager_ptr man, ap_abstract0_ptr a, struct ap_dimchange2_t dimchange2, boolean project) quote(call," _res = ap_abstract0_apply_dimchange2(man,false,a,&dimchange2,project); if (dimchange2.add) ap_dimchange_clear(dimchange2.add); if (dimchange2.remove) ap_dimchange_clear(dimchange2.remove); ") quote(dealloc,"I0_CHECK_EXC(man)"); ap_abstract0_ptr ap_abstract0_permute_dimensions(ap_manager_ptr man, ap_abstract0_ptr a, [ref]struct ap_dimperm_t* perm) quote(call,"_res = ap_abstract0_permute_dimensions(man,false,a,perm);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** {5 Side-effect versions of the previous functions} *)\n\n") void ap_abstract0_add_dimensions_with(ap_manager_ptr man, ap_abstract0_ptr a, ap_dimchange_t dimchange, boolean v1) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_add_dimensions(man,true,a,&dimchange,v1);\n \ ap_dimchange_clear(&dimchange);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_remove_dimensions_with(ap_manager_ptr man, ap_abstract0_ptr a, ap_dimchange_t dimchange) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_remove_dimensions(man,true,a,&dimchange);\n\ ap_dimchange_clear(&dimchange);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_apply_dimchange2_with(ap_manager_ptr man, ap_abstract0_ptr a, struct ap_dimchange2_t dimchange2, boolean project) quote(call," ap_abstract0_t* res = ap_abstract0_apply_dimchange2(man,true,a,&dimchange2,project); ap_dimchange2_clear(&dimchange2); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res; ") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_permute_dimensions_with(ap_manager_ptr man, ap_abstract0_ptr a, struct ap_dimperm_t* perm) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_permute_dimensions(man,true,a,perm);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n\n") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Expansion and folding of dimensions} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n\ (**\n\ These functions allows to expand one dimension into several ones having the\n\ same properties with respect to the other dimensions, and to fold several\n\ dimensions into one. Formally,\n\ \n\ - expand P(x,y,z) z w = P(x,y,z) inter P(x,y,w) if z is expanded in z and w\n\ - fold Q(x,y,z,w) z w = exists w:Q(x,y,z,w) union (exist z:Q(x,y,z,w))(z<-w)\n\ if z and w are folded onto z\n\ *)\n\n\ ") quote(MLI,"(** \ Expansion: [expand a dim n] expands the dimension [dim] into itself + [n]\n\ additional dimensions. It results in (n+1) unrelated dimensions having\n\ same relations with other dimensions. The (n+1) dimensions are put as\n\ follows: \n\ \n\ - original dimension [dim]\n\ - if the dimension is integer, the n additional dimensions are put at the\n\ end of integer dimensions; if it is real, at the end of the real\n\ dimensions.\n\ *)") ap_abstract0_ptr ap_abstract0_expand(ap_manager_ptr man, ap_abstract0_ptr a, ap_dim_t v1, int v2) quote(call,"_res = ap_abstract0_expand(man,false,a,v1,v2);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI," \ (** Folding: [fold a tdim] fold the dimensions in the array [tdim] of size n>=1\n\ and put the result in the first dimension of the array. The other\n\ dimensions of the array are then removed (using\n\ ap_abstract0_permute_remove_dimensions).\n\ *)") ap_abstract0_ptr ap_abstract0_fold(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v2)]ap_dim_t* v1, int v2) quote(call,"_res = ap_abstract0_fold(man,false,a,v1,v2);") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_expand_with(ap_manager_ptr man, ap_abstract0_ptr a, ap_dim_t v1, int v2) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_expand(man,true,a,v1,v2); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_fold_with(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v2)]ap_dim_t* v1, int v2) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_fold(man,true,a,v1,v2); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Widening} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** Widening *)") ap_abstract0_ptr ap_abstract0_widening(ap_manager_ptr man, ap_abstract0_ptr a1, ap_abstract0_ptr a2) quote(dealloc,"I0_CHECK_EXC(man)"); ap_abstract0_ptr ap_abstract0_widening_threshold(ap_manager_ptr man, ap_abstract0_ptr a1, ap_abstract0_ptr a2, [ref]struct ap_lincons0_array_t* v) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Closure operation} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** Closure: transform strict constraints into non-strict ones.*)") ap_abstract0_ptr ap_abstract0_closure(ap_manager_ptr man, ap_abstract0_ptr a) quote(call,"_res = ap_abstract0_closure(man,false,a);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Side-effect version *)") void ap_abstract0_closure_with(ap_manager_ptr man, ap_abstract0_ptr a) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_closure(man,true,a); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(** {2 Additional operations} *)") quote(MLMLI,"(* ********************************************************************** *)") quote(MLI,"\n\ val of_lincons_array : 'a Manager.t -> int -> int -> Lincons0.t array -> 'a t\n\ val of_tcons_array : 'a Manager.t -> int -> int -> Tcons0.t array -> 'a t\n\ (** Abstract a conjunction of constraints *)\n\ \n\ val assign_linexpr : 'a Manager.t -> 'a t -> Dim.t -> Linexpr0.t -> 'a t option -> 'a t\n\ val substitute_linexpr : 'a Manager.t -> 'a t -> Dim.t -> Linexpr0.t -> 'a t option -> 'a t\n\ val assign_texpr : 'a Manager.t -> 'a t -> Dim.t -> Texpr0.t -> 'a t option -> 'a t\n\ val substitute_texpr : 'a Manager.t -> 'a t -> Dim.t -> Texpr0.t -> 'a t option -> 'a t\n\ (** Assignement/Substitution of a single dimension by a single expression *)\n\ \n\ val assign_linexpr_with : 'a Manager.t -> 'a t -> Dim.t -> Linexpr0.t -> 'a t option -> unit\n\ val substitute_linexpr_with : 'a Manager.t -> 'a t -> Dim.t -> Linexpr0.t -> 'a t option -> unit\n\ val assign_texpr_with : 'a Manager.t -> 'a t -> Dim.t -> Texpr0.t -> 'a t option -> unit\n\ val substitute_texpr_with : 'a Manager.t -> 'a t -> Dim.t -> Texpr0.t -> 'a t option -> unit\n\ (** Side-effect version of the previous functions *)\n\ \n\ ") quote(ML,"\n\ let of_lincons_array man intdim realdim array =\n\ let res = top man intdim realdim in\n\ meet_lincons_array_with man res array;\n\ res\n\ let of_tcons_array man intdim realdim array =\n\ let res = top man intdim realdim in\n\ meet_tcons_array_with man res array;\n\ res\n\ let assign_linexpr man abs dim expr odest =\n\ assign_linexpr_array man abs [|dim|] [|expr|] odest\n\ let assign_texpr man abs dim expr odest =\n\ assign_texpr_array man abs [|dim|] [|expr|] odest\n\ let substitute_linexpr man abs dim expr odest =\n\ substitute_linexpr_array man abs [|dim|] [|expr|] odest\n\ let substitute_texpr man abs dim expr odest =\n\ substitute_texpr_array man abs [|dim|] [|expr|] odest\n\ let assign_linexpr_with man abs dim expr odest =\n\ assign_linexpr_array_with man abs [|dim|] [|expr|] odest\n\ let assign_texpr_with man abs dim expr odest =\n\ assign_texpr_array_with man abs [|dim|] [|expr|] odest\n\ let substitute_linexpr_with man abs dim expr odest =\n\ substitute_linexpr_array_with man abs [|dim|] [|expr|] odest\n\ let substitute_texpr_with man abs dim expr odest =\n\ substitute_texpr_array_with man abs [|dim|] [|expr|] odest\n\ ") quote(ML,"\n\ let print_array\n\ ?(first=(\"[|@[\":(unit,Format.formatter,unit) format))\n\ ?(sep = (\";@ \":(unit,Format.formatter,unit) format))\n\ ?(last = (\"@]|]\":(unit,Format.formatter,unit) format))\n\ (print_elt: Format.formatter -> 'a -> unit)\n\ (fmt:Format.formatter)\n\ (array: 'a array)\n\ : unit\n\ =\n\ if array=[||] then begin\n\ Format.fprintf fmt first;\n\ Format.fprintf fmt last;\n\ end\n\ else begin\n\ Format.fprintf fmt first;\n\ let first = ref true in\n\ Array.iter\n\ (begin fun e ->\n\ if !first then first := false else Format.fprintf fmt sep;\n\ print_elt fmt e\n\ end)\n\ array\n\ ;\n\ Format.fprintf fmt last;\n\ end\n\ \n\ let print assoc fmt a =\n\ let man = manager a in\n\ if is_bottom man a then\n \ Format.pp_print_string fmt \"bottom\"\n\ else if is_top man a then\n\ Format.pp_print_string fmt \"top\"\n\ else begin\n\ let tab = to_lincons_array man a in\n\ print_array (Lincons0.print assoc) fmt tab;\n\ end\n\ ") quote(MLI,"\n(** General use *)\n\ val print_array :\n\ ?first:(unit, Format.formatter, unit) format ->\n\ ?sep:(unit, Format.formatter, unit) format ->\n\ ?last:(unit, Format.formatter, unit) format ->\n\ (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a array -> unit\n\ ") apron-dist-0.9.10/apron/octagons/tmp/texpr0.idl0000640014525101416610000003074211252216517021225 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(MLI,"(** APRON tree expressions of level 0 *)\n") quote(C, "\n\ #include \n\ #include \"ap_texpr0.h\"\n\ #include \"apron_caml.h\"\n\ \n\ value camlidl_texpr0_ap_texpr0_to_expr_c2ml(ap_texpr0_t* expr, camlidl_ctx _ctx)\n\ {\n\ value _v_res;\n\ \n\ switch(expr->discr){\n\ case AP_TEXPR_CST:\n\ {\n\ value v0 = Val_unit;\n\ Begin_root(v0);\n\ v0 = camlidl_c2ml_coeff_struct_ap_coeff_t(&expr->val.cst, _ctx);\n\ _v_res = caml_alloc_small(1,0);\n\ Field(_v_res,0) = v0;\n\ End_roots();\n\ }\n\ break;\n\ case AP_TEXPR_DIM:\n\ _v_res = caml_alloc_small(1,1);\n\ Field(_v_res,0) = Val_int(expr->val.dim);\n\ break;\n\ case AP_TEXPR_NODE:\n\ {\n\ value v0,v1,v2,v3,v4;\n\ v0 = v1 = v2 = v3 = v4 = Val_unit;\n\ Begin_roots5(v0,v1,v2,v3,v4);\n\ ap_texpr0_node_t* node = expr->val.node;\n\ v1 = camlidl_texpr0_ap_texpr0_to_expr_c2ml(node->exprA,_ctx);\n\ v3 = camlidl_apron_texpr_rtype_t_c2ml(&node->type);\n\ v4 = camlidl_apron_texpr_rdir_t_c2ml(&node->dir);\n\ if (ap_texpr_is_unop(node->op)){\n\ v0 = camlidl_apron_texpr_unop_t_c2ml(&node->op);\n\ _v_res = caml_alloc_small(4,2);\n\ Field(_v_res,0) = v0;\n\ Field(_v_res,1) = v1;\n\ Field(_v_res,2) = v3;\n\ Field(_v_res,3) = v4;\n\ }\n\ else {\n\ v0 = camlidl_apron_texpr_binop_t_c2ml(&node->op);\n\ v2 = camlidl_texpr0_ap_texpr0_to_expr_c2ml(node->exprB,_ctx);\n\ _v_res = caml_alloc_small(5,3);\n\ Field(_v_res,0) = v0;\n\ Field(_v_res,1) = v1;\n\ Field(_v_res,2) = v2;\n\ Field(_v_res,3) = v3;\n\ Field(_v_res,4) = v4;\n\ }\n\ End_roots();\n\ }\n\ break;\n\ default:\n\ abort();\n\ }\n\ return _v_res;\n\ }\n\ value camlidl_texpr0_ap_texpr0_to_expr(value _v_texpr)\n\ {\n\ CAMLparam1(_v_texpr);\n\ CAMLlocal1(_v_res);\n\ ap_texpr0_t* expr;\n\ \n\ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL };\n\ camlidl_ctx _ctx = &_ctxs;\n\ \n\ camlidl_apron_texpr0_ptr_ml2c(_v_texpr,&expr);\n\ _v_res = camlidl_texpr0_ap_texpr0_to_expr_c2ml(expr,_ctx);\n\ camlidl_free(_ctx);\n\ \n\ CAMLreturn(_v_res);\n\ }\n\ \n\ void camlidl_texpr0_ap_texpr0_of_expr_ml2c(value v, ap_texpr0_t** res, camlidl_ctx _ctx)\n\ {\n\ ap_texpr0_t* texpr;\n\ ap_texpr0_node_t* node;\n\ ap_coeff_t coeff;\n\ value v0,v1,v2,v3,v4;\n\ \n\ texpr = malloc(sizeof(ap_texpr0_t));\n \ \n\ assert (Is_block(v));\n\ switch (Tag_val(v)){\n\ case 0: /* Constant */\n\ assert(Wosize_val(v)==1);\n\ v0 = Field(v,0);\n\ texpr->discr = AP_TEXPR_CST;\n\ camlidl_ml2c_coeff_struct_ap_coeff_t(v0,&coeff,_ctx);\n\ ap_coeff_init_set(&texpr->val.cst,&coeff);\n\ break;\n\ case 1: /* Dimension */\n\ assert(Wosize_val(v)==1);\n\ v0 = Field(v,0);\n\ texpr->discr = AP_TEXPR_DIM;\n\ texpr->val.dim = Int_val(v0);\n\ break;\n\ case 2: /* Unary node */\n\ v0 = Field(v,0);\n\ v1 = Field(v,1);\n\ v2 = Field(v,2);\n\ v3 = Field(v,3);\n\ \n\ node = malloc(sizeof(ap_texpr0_node_t));\n \ camlidl_apron_texpr_unop_t_ml2c (v0,&node->op);\n\ camlidl_texpr0_ap_texpr0_of_expr_ml2c(v1,&node->exprA,_ctx);\n \ camlidl_apron_texpr_rtype_t_ml2c (v2,&node->type);\n\ camlidl_apron_texpr_rdir_t_ml2c (v3,&node->dir);\n\ node->exprB = NULL;\n\ texpr->discr = AP_TEXPR_NODE;\n\ texpr->val.node = node;\n\ break;\n\ case 3: /* Binary node */\n\ v0 = Field(v,0);\n\ v1 = Field(v,1);\n\ v2 = Field(v,2);\n\ v3 = Field(v,3);\n\ v4 = Field(v,4);\n\ node = malloc(sizeof(ap_texpr0_node_t));\n\ camlidl_apron_texpr_binop_t_ml2c (v0,&node->op);\n\ camlidl_texpr0_ap_texpr0_of_expr_ml2c(v1,&node->exprA,_ctx);\n \ camlidl_texpr0_ap_texpr0_of_expr_ml2c(v2,&node->exprB,_ctx);\n \ camlidl_apron_texpr_rtype_t_ml2c (v3,&node->type);\n\ camlidl_apron_texpr_rdir_t_ml2c (v4,&node->dir);\n\ texpr->discr = AP_TEXPR_NODE;\n\ texpr->val.node = node;\n\ break;\n\ default:\n\ assert(false);\n\ }\n\ *res = texpr;\n\ }\n\ value camlidl_texpr0_ap_texpr0_of_expr(value _v_expr)\n\ {\n\ CAMLparam1(_v_expr);\n\ CAMLlocal1(_v_res);\n\ ap_texpr0_t* res;\n\ \n\ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL };\n\ camlidl_ctx _ctx = &_ctxs;\n\ \n\ camlidl_texpr0_ap_texpr0_of_expr_ml2c(_v_expr,&res,_ctx);\n\ _v_res = camlidl_apron_texpr0_ptr_c2ml(&res);\n\ \n\ camlidl_free(_ctx);\n\ CAMLreturn(_v_res);\n\ }\n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; import "linexpr0.idl"; typedef [abstract, ml2c(camlidl_apron_texpr0_ptr_ml2c), c2ml(camlidl_apron_texpr0_ptr_c2ml)] struct ap_texpr0_ptr* ap_texpr0_ptr; typedef [mltype("\n | Neg\n | Cast\n | Sqrt (** *)\n (** Unary operators *)"), ml2c(camlidl_apron_texpr_unop_t_ml2c), c2ml(camlidl_apron_texpr_unop_t_c2ml)] struct ap_texpr_op_t ap_texpr_unop_t; typedef [mltype("\n | Add\n | Sub\n | Mul\n | Div\n | Mod (** *)\n (** Binary operators *)"), ml2c(camlidl_apron_texpr_binop_t_ml2c), c2ml(camlidl_apron_texpr_binop_t_c2ml)] struct ap_texpr_op_t ap_texpr_binop_t; typedef [mltype("\n | Real\n | Int\n | Single\n | Double\n | Extended\n | Quad (** *)\n (** Destination type for rounding *)"), ml2c(camlidl_apron_texpr_rtype_t_ml2c), c2ml(camlidl_apron_texpr_rtype_t_c2ml)] struct ap_texpr_rtype_t ap_texpr_rtype_t; typedef [mltype("\n | Near\n | Zero\n | Up\n | Down\n | Rnd (** *)\n (** Rounding direction *)"), ml2c(camlidl_apron_texpr_rdir_t_ml2c), c2ml(camlidl_apron_texpr_rdir_t_c2ml)] struct ap_texpr_rdir_t ap_texpr_rdir_t; quote(MLMLI,"\n\ (** User type for tree expressions *) \n\ type expr = \n\ | Cst of Coeff.t \n\ | Dim of Dim.t \n\ | Unop of unop * expr * typ * round \n\ | Binop of binop * expr * expr * typ * round \n\ ") quote(MLMLI,"(** {2 Constructors and Destructor} *)") quote(MLI,"(** General constructor (actually the most efficient *)") quote(MLMLI,"external of_expr : expr -> t = \"camlidl_texpr0_ap_texpr0_of_expr\"\n") quote(MLI,"(** Copy *)") ap_texpr0_ptr ap_texpr0_copy(const ap_texpr0_ptr a); quote(MLI,"(** Conversion *)") ap_texpr0_ptr ap_texpr0_of_linexpr(ap_linexpr0_ptr e) quote(call,"_res = ap_texpr0_from_linexpr0(e);"); quote(MLI,"(** General destructor *)") quote(MLMLI,"external to_expr : t -> expr = \"camlidl_texpr0_ap_texpr0_to_expr\"\n") quote(MLI,"\n(** {3 Incremental constructors} *)\n") ap_texpr0_ptr ap_texpr0_cst([ref]struct ap_coeff_t* coeff); ap_texpr0_ptr ap_texpr0_dim(ap_dim_t dim); ap_texpr0_ptr ap_texpr0_unop(ap_texpr_unop_t op, ap_texpr0_ptr expr, ap_texpr_rtype_t type, ap_texpr_rdir_t dir) quote(call,"_res = ap_texpr0_unop(op,ap_texpr0_copy(expr),type,dir);"); ap_texpr0_ptr ap_texpr0_binop(ap_texpr_binop_t op, ap_texpr_rtype_t type, ap_texpr_rdir_t dir, ap_texpr0_ptr exprA, ap_texpr0_ptr exprB) quote(call,"_res = ap_texpr0_binop(op,ap_texpr0_copy(exprA),ap_texpr0_copy(exprB),type,dir);"); /* quote(MLMLI,"external dims : t -> Dim.t array = \"camlidl_texpr0_ap_texpr0_dims\"") quote(C,"\n\ value camlidl_texpr0_ap_texpr0_dims(value _v_texpr)\n\ {\n\ CAMLparam1(_v_texpr);\n\ CAMLlocal1(_v_res);\n\ ap_texpr0_t* expr;\n\ ap_dim_t* dims;\n\ size_t size,i;\n\ \n\ camlidl_apron_texpr0_ptr_ml2c(_v_texpr,&expr);\n\ dims = ap_texpr0_dimlist(expr);\n\ size=0;\n\ while (dims[size] != AP_DIM_MAX) size++;\n\ _v_res = camlidl_alloc(size,0);\n\ for (i=0; i string\n\ val string_of_binop : binop -> string\n\ val string_of_typ : typ -> string\n\ val string_of_round : round -> string\n\ val print_unop : Format.formatter -> unop -> unit\n\ val print_binop : Format.formatter -> binop -> unit\n\ val print_typ : Format.formatter -> typ -> unit\n\ val print_round : Format.formatter -> round -> unit\n\ val print_expr : (Dim.t -> string) -> Format.formatter -> expr -> unit\n\ (** Print a tree expression, using a function converting from dimensions to names *)\n\ val print : (Dim.t -> string) -> Format.formatter -> t -> unit\n\ (** Print an abstract tree expression, using a function converting from dimensions to names *)\n\ ") quote(ML,"\n\ let string_of_unop = function\n\ | Neg -> \"Neg\"\n\ | Cast -> \"Cast\"\n\ | Sqrt -> \"Sqrt\"\n\ let string_of_binop = function\n\ | Add -> \"Add\"\n\ | Sub -> \"Sub\"\n\ | Mul -> \"Mul\"\n\ | Div -> \"Div\"\n\ | Mod -> \"Mod\"\n\ let string_of_typ = function\n\ | Real -> \"Real\"\n\ | Int -> \"Int\"\n\ | Single -> \"Single\"\n\ | Double -> \"Double\"\n\ | Extended -> \"Extended\"\n\ | Quad-> \"Quad\"\n\ let string_of_round = function\n\ | Near -> \"Near\"\n\ | Zero -> \"Zero\"\n\ | Up -> \"Up\"\n\ | Down -> \"Down\"\n\ | Rnd -> \"Rnd\"\n\ let print_typ fmt x = Format.pp_print_string fmt (string_of_typ x)\n\ let print_round fmt x = Format.pp_print_string fmt (string_of_round x)\n\ let print_unop fmt x = Format.pp_print_string fmt (string_of_unop x)\n\ let print_binop fmt x = Format.pp_print_string fmt (string_of_binop x)\n\ \n\ \n\ let print_string_of_unop = function\n\ | Neg -> \"-\"\n\ | Cast -> \"cast\"\n\ | Sqrt -> \"sqrt\"\n\ let print_string_of_binop = function\n\ | Add -> \"+\"\n\ | Sub -> \"-\"\n\ | Mul -> \"*\"\n\ | Div -> \"/\"\n\ | Mod -> \"%\"\n\ let print_string_of_typ = function\n\ | Real -> \"\"\n\ | Int -> \"i\"\n\ | Single -> \"f\"\n\ | Double -> \"d\"\n\ | Extended -> \"l\"\n\ | Quad-> \"q\"\n\ let print_string_of_round = function\n\ | Near -> \"n\"\n\ | Zero -> \"0\"\n\ | Up -> \"+oo\"\n\ | Down -> \"-oo\"\n\ | Rnd -> \"?\"\n\ let print_sprint_unop op typ round =\n\ if op=Neg then\n\ Format.sprintf \"%s\" (print_string_of_unop op)\n\ else begin\n\ if typ=Real then\n\ Format.sprintf \"%s \" (print_string_of_unop op)\n\ else\n\ Format.sprintf \"%s_%s,%s \" (print_string_of_unop op)\n\ (print_string_of_typ typ) (print_string_of_round round)\n\ end\n\ let print_sprint_binop op typ round =\n\ if typ=Real then\n\ Format.sprintf \"%s\" (print_string_of_binop op)\n\ else\n\ Format.sprintf \"%s_%s,%s\" (print_string_of_binop op)\n\ (print_string_of_typ typ) (print_string_of_round round)\n\ let print_precedence_of_unop = function\n\ | Neg -> 3\n\ | Cast | Sqrt -> 4\n\ let print_precedence_of_binop = function\n\ | Add | Sub -> 1\n\ | Mul | Div | Mod -> 2\n\ \n\ \n\ let rec print_expr (string_of_dim:Dim.t -> string) fmt expr =\n\ let precedence_of_expr = function\n\ | Cst _\n\ | Dim _ -> 5\n\ | Unop(op,_,_,_) -> print_precedence_of_unop op\n\ | Binop(op,_,_,_,_) -> print_precedence_of_binop op\n\ in\n\ match expr with\n\ | Cst x -> Coeff.print fmt x\n\ | Dim x -> Format.pp_print_string fmt (string_of_dim x)\n\ | Unop(op,e,typ,round) ->\n\ let prec = print_precedence_of_unop op in\n\ let prec1 = precedence_of_expr e in\n\ let par = prec1<=prec in\n\ Format.fprintf fmt \"%s%s%a%s\"\n\ (print_sprint_unop op typ round)\n\ (if par then \"(\" else \"\")\n\ (print_expr string_of_dim) e\n\ (if par then \")\" else \"\")\n\ | Binop(op,e1,e2,typ,round) ->\n\ let prec = print_precedence_of_binop op in\n\ let prec1 = precedence_of_expr e1 in\n\ let prec2 = precedence_of_expr e2 in\n\ let par1 = prec1 typ -> round -> string\n\ val print_sprint_binop : binop -> typ -> round -> string\n\ val print_precedence_of_unop : unop -> int\n\ val print_precedence_of_binop : binop -> int\n\ ") apron-dist-0.9.10/apron/octagons/tmp/oct.mli0000640014525101416610000001067211252216517020601 0ustar bjeannetpopart(* File generated from oct.idl *) type internal_ptr (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. *) (** Octagon abstract domain. *) type t (** Type of octagons. Octagons are defined by conjunctions of inequalities of the form [+/-x_i +/- x_j >= 0]. Abstract values which are octagons have the type [t Apron.AbstractX.t]. Managers allocated for octagons have the type [t Apron.manager.t]. *) (** Allocate a new manager to manipulate octagons. *) external oct_manager_alloc : unit -> Manager.ap_manager_ptr = "camlidl_oct_oct_manager_alloc" (** No internal parameters for now... *) external manager_get_internal : Manager.ap_manager_ptr -> internal_ptr = "camlidl_oct_manager_get_internal" (** Approximate a set of generators to an abstract value, with best precision. *) external ap_abstract0_oct_of_generator_array : Manager.ap_manager_ptr -> int -> int -> Generator0.ap_generator0_array_t -> Abstract0.ap_abstract0_ptr = "camlidl_oct_ap_abstract0_oct_of_generator_array" (** Widening with scalar thresholds. *) external ap_abstract0_oct_widening_thresholds : Manager.ap_manager_ptr -> Abstract0.ap_abstract0_ptr -> Abstract0.ap_abstract0_ptr -> Scalar.ap_scalar_array_t -> Abstract0.ap_abstract0_ptr = "camlidl_oct_ap_abstract0_oct_widening_thresholds" (** Standard narrowing. *) external ap_abstract0_oct_narrowing : Manager.ap_manager_ptr -> Abstract0.ap_abstract0_ptr -> Abstract0.ap_abstract0_ptr -> Abstract0.ap_abstract0_ptr = "camlidl_oct_ap_abstract0_oct_narrowing" (** Perturbation. *) external ap_abstract0_oct_add_epsilon : Manager.ap_manager_ptr -> Abstract0.ap_abstract0_ptr -> Scalar.ap_scalar_ptr -> Abstract0.ap_abstract0_ptr = "camlidl_oct_ap_abstract0_oct_add_epsilon" (** Perturbation. *) external ap_abstract0_oct_add_epsilon_bin : Manager.ap_manager_ptr -> Abstract0.ap_abstract0_ptr -> Abstract0.ap_abstract0_ptr -> Scalar.ap_scalar_ptr -> Abstract0.ap_abstract0_ptr = "camlidl_oct_ap_abstract0_oct_add_epsilon_bin" (** Algorithms. *) val pre_widening : int (** {2 Type conversions} *) val manager_is_oct : 'a Apron.Manager.t -> bool (** Return [true] iff the argument manager is an octagon manager *) val manager_of_oct : t Apron.Manager.t -> 'a Apron.Manager.t (** Make an octagon manager generic *) val manager_to_oct : 'a Apron.Manager.t -> t Apron.Manager.t (** Instanciate the type of an octagon manager. Raises [Failure] if the argument manager is not an octagon manager *) module Abstract0 : sig val is_oct : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument value is an oct value *) val of_oct : t Apron.Abstract0.t -> 'a Apron.Abstract0.t (** Make an oct value generic *) val to_oct : 'a Apron.Abstract0.t -> t Apron.Abstract0.t (** Instanciate the type of an oct value. Raises [Failure] if the argument value is not an oct value *) end module Abstract1 : sig val is_oct : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument value is an oct value *) val of_oct : t Apron.Abstract1.t -> 'a Apron.Abstract1.t (** Make an oct value generic *) val to_oct : 'a Apron.Abstract1.t -> t Apron.Abstract1.t (** Instanciate the type of an oct value. Raises [Failure] if the argument value is not an oct value *) end (** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. {3 Bytecode compilation} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \ bigarray.cma gmp.cma apron.cma octD.cma mlexample.ml]} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \ bigarray.cma gmp.cma apron.cma octD.cma ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \ bigarray.cma gmp.cma apron.cma octD.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa octD.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa octD.cmxa mlexample.ml \ -cclib "-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib \ -loctD_caml_debug -loctD_debug \ -lapron_caml_debug -lapron_debug \ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP_PREFIX/lib -lgmp \ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \ -lbigarray" ]} *) apron-dist-0.9.10/apron/octagons/tmp/oct_stubs.c0000640014525101416610000003464711252216517021472 0ustar bjeannetpopart/* File generated from oct.idl */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #include "oct.h" #include "apron_caml.h" #define I0_CHECK_EXC(man) if (man->result.exn!=AP_EXC_NONE){ value v = camlidl_c2ml_manager_struct_ap_exclog_t(man->result.exclog,_ctx); caml_raise_with_arg(*caml_named_value("apron exception"),v); } typedef struct oct_internal_t* internal_ptr; extern void camlidl_apron_scalar_ml2c(value, ap_scalar_t *); #define camlidl_ml2c_scalar_ap_scalar_t(v,c,ctx) camlidl_apron_scalar_ml2c(v,c) extern value camlidl_apron_scalar_c2ml(ap_scalar_t *); #define camlidl_c2ml_scalar_ap_scalar_t(c,ctx) camlidl_apron_scalar_c2ml(c) extern void camlidl_ml2c_scalar_ap_scalar_ptr(value, ap_scalar_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_ap_scalar_ptr(ap_scalar_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_scalar_struct_ap_scalar_array_t(value, struct ap_scalar_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_struct_ap_scalar_array_t(struct ap_scalar_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_t(value, struct ap_interval_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_t(struct ap_interval_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_ap_interval_ptr(value, ap_interval_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_ap_interval_ptr(ap_interval_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_array_t(value, struct ap_interval_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_array_t(struct ap_interval_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_coeff_struct_ap_coeff_t(value, struct ap_coeff_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_coeff_struct_ap_coeff_t(struct ap_coeff_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_ap_dim_t(value, ap_dim_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_ap_dim_t(ap_dim_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimchange_t(value, struct ap_dimchange_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange_t(struct ap_dimchange_t *, camlidl_ctx _ctx); extern void camlidl_apron_dimchange_ml2c(value, ap_dimchange_t *); #define camlidl_ml2c_dim_ap_dimchange_t(v,c,ctx) camlidl_apron_dimchange_ml2c(v,c) extern value camlidl_apron_dimchange_c2ml(ap_dimchange_t *); #define camlidl_c2ml_dim_ap_dimchange_t(c,ctx) camlidl_apron_dimchange_c2ml(c) extern void camlidl_ml2c_dim_struct_ap_dimchange2_t(value, struct ap_dimchange2_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange2_t(struct ap_dimchange2_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimperm_t(value, struct ap_dimperm_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimperm_t(struct ap_dimperm_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimension_t(value, struct ap_dimension_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimension_t(struct ap_dimension_t *, camlidl_ctx _ctx); extern void camlidl_apron_linexpr0_ptr_ml2c(value, ap_linexpr0_ptr *); #define camlidl_ml2c_linexpr0_ap_linexpr0_ptr(v,c,ctx) camlidl_apron_linexpr0_ptr_ml2c(v,c) extern value camlidl_apron_linexpr0_ptr_c2ml(ap_linexpr0_ptr *); #define camlidl_c2ml_linexpr0_ap_linexpr0_ptr(c,ctx) camlidl_apron_linexpr0_ptr_c2ml(c) extern int camlidl_ml2c_generator0_enum_gentyp(value); extern value camlidl_c2ml_generator0_enum_gentyp(int); extern int camlidl_transl_table_generator0_enum_gentyp[]; extern void camlidl_ml2c_generator0_struct_ap_generator0_t(value, struct ap_generator0_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_generator0_struct_ap_generator0_t(struct ap_generator0_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_generator0_struct_ap_generator0_array_t(value, struct ap_generator0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_generator0_struct_ap_generator0_array_t(struct ap_generator0_array_t *, camlidl_ctx _ctx); extern void camlidl_apron_lincons0_ml2c(value, ap_lincons0_t *); #define camlidl_ml2c_lincons0_ap_lincons0_t(v,c,ctx) camlidl_apron_lincons0_ml2c(v,c) extern value camlidl_apron_lincons0_c2ml(ap_lincons0_t *); #define camlidl_c2ml_lincons0_ap_lincons0_t(c,ctx) camlidl_apron_lincons0_c2ml(c) extern void camlidl_ml2c_lincons0_struct_ap_lincons0_array_t(value, struct ap_lincons0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_lincons0_struct_ap_lincons0_array_t(struct ap_lincons0_array_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr0_ptr_ml2c(value, ap_texpr0_ptr *); #define camlidl_ml2c_texpr0_ap_texpr0_ptr(v,c,ctx) camlidl_apron_texpr0_ptr_ml2c(v,c) extern value camlidl_apron_texpr0_ptr_c2ml(ap_texpr0_ptr *); #define camlidl_c2ml_texpr0_ap_texpr0_ptr(c,ctx) camlidl_apron_texpr0_ptr_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_op_t(value, struct ap_texpr_op_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_op_t(struct ap_texpr_op_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_unop_t_ml2c(value, ap_texpr_unop_t *); #define camlidl_ml2c_texpr0_ap_texpr_unop_t(v,c,ctx) camlidl_apron_texpr_unop_t_ml2c(v,c) extern value camlidl_apron_texpr_unop_t_c2ml(ap_texpr_unop_t *); #define camlidl_c2ml_texpr0_ap_texpr_unop_t(c,ctx) camlidl_apron_texpr_unop_t_c2ml(c) extern void camlidl_apron_texpr_binop_t_ml2c(value, ap_texpr_binop_t *); #define camlidl_ml2c_texpr0_ap_texpr_binop_t(v,c,ctx) camlidl_apron_texpr_binop_t_ml2c(v,c) extern value camlidl_apron_texpr_binop_t_c2ml(ap_texpr_binop_t *); #define camlidl_c2ml_texpr0_ap_texpr_binop_t(c,ctx) camlidl_apron_texpr_binop_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rtype_t(value, struct ap_texpr_rtype_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rtype_t(struct ap_texpr_rtype_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_rtype_t_ml2c(value, ap_texpr_rtype_t *); #define camlidl_ml2c_texpr0_ap_texpr_rtype_t(v,c,ctx) camlidl_apron_texpr_rtype_t_ml2c(v,c) extern value camlidl_apron_texpr_rtype_t_c2ml(ap_texpr_rtype_t *); #define camlidl_c2ml_texpr0_ap_texpr_rtype_t(c,ctx) camlidl_apron_texpr_rtype_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rdir_t(value, struct ap_texpr_rdir_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rdir_t(struct ap_texpr_rdir_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_rdir_t_ml2c(value, ap_texpr_rdir_t *); #define camlidl_ml2c_texpr0_ap_texpr_rdir_t(v,c,ctx) camlidl_apron_texpr_rdir_t_ml2c(v,c) extern value camlidl_apron_texpr_rdir_t_c2ml(ap_texpr_rdir_t *); #define camlidl_c2ml_texpr0_ap_texpr_rdir_t(c,ctx) camlidl_apron_texpr_rdir_t_c2ml(c) extern void camlidl_apron_tcons0_ml2c(value, ap_tcons0_t *); #define camlidl_ml2c_tcons0_ap_tcons0_t(v,c,ctx) camlidl_apron_tcons0_ml2c(v,c) extern value camlidl_apron_tcons0_c2ml(ap_tcons0_t *); #define camlidl_c2ml_tcons0_ap_tcons0_t(c,ctx) camlidl_apron_tcons0_c2ml(c) extern void camlidl_ml2c_tcons0_struct_ap_tcons0_array_t(value, struct ap_tcons0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_tcons0_struct_ap_tcons0_array_t(struct ap_tcons0_array_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_funid_ml2c(value, ap_funid_t *); #define camlidl_ml2c_manager_ap_funid_t(v,c,ctx) camlidl_apron_manager_funid_ml2c(v,c) extern value camlidl_apron_manager_funid_c2ml(ap_funid_t *); #define camlidl_c2ml_manager_ap_funid_t(c,ctx) camlidl_apron_manager_funid_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_funopt_t(value, struct ap_funopt_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_funopt_t(struct ap_funopt_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_exc_ml2c(value, ap_exc_t *); #define camlidl_ml2c_manager_ap_exc_t(v,c,ctx) camlidl_apron_manager_exc_ml2c(v,c) extern value camlidl_apron_manager_exc_c2ml(ap_exc_t *); #define camlidl_c2ml_manager_ap_exc_t(c,ctx) camlidl_apron_manager_exc_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_exclog_t(value, struct ap_exclog_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_exclog_t(struct ap_exclog_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_ptr_ml2c(value, ap_manager_ptr *); #define camlidl_ml2c_manager_ap_manager_ptr(v,c,ctx) camlidl_apron_manager_ptr_ml2c(v,c) extern value camlidl_apron_manager_ptr_c2ml(ap_manager_ptr *); #define camlidl_c2ml_manager_ap_manager_ptr(c,ctx) camlidl_apron_manager_ptr_c2ml(c) extern void camlidl_apron_abstract0_ptr_ml2c(value, ap_abstract0_ptr *); #define camlidl_ml2c_abstract0_ap_abstract0_ptr(v,c,ctx) camlidl_apron_abstract0_ptr_ml2c(v,c) extern value camlidl_apron_abstract0_ptr_c2ml(ap_abstract0_ptr *); #define camlidl_c2ml_abstract0_ap_abstract0_ptr(c,ctx) camlidl_apron_abstract0_ptr_c2ml(c) void camlidl_ml2c_oct_internal_ptr(value _v1, internal_ptr * _c2, camlidl_ctx _ctx) { *_c2 = *((internal_ptr *) Bp_val(_v1)); } value camlidl_c2ml_oct_internal_ptr(internal_ptr * _c2, camlidl_ctx _ctx) { value _v1; _v1 = camlidl_alloc((sizeof(internal_ptr) + sizeof(value) - 1) / sizeof(value), Abstract_tag); *((internal_ptr *) Bp_val(_v1)) = *_c2; return _v1; } value camlidl_oct_oct_manager_alloc(value _unit) { ap_manager_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; _res = oct_manager_alloc(); _vres = camlidl_c2ml_manager_ap_manager_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_oct_manager_get_internal( value _v_man) { ap_manager_ptr man; /*in*/ internal_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); /* begin user-supplied calling sequence */ _res = (internal_ptr)man->internal; /* end user-supplied calling sequence */ _vres = camlidl_c2ml_oct_internal_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_oct_ap_abstract0_oct_of_generator_array( value _v_man, value _v_v1, value _v_v2, value _v_v3) { ap_manager_ptr man; /*in*/ int v1; /*in*/ int v2; /*in*/ struct ap_generator0_array_t *v3; /*in*/ ap_abstract0_ptr _res; struct ap_generator0_array_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); v1 = Int_val(_v_v1); v2 = Int_val(_v_v2); v3 = &_c1; camlidl_ml2c_generator0_struct_ap_generator0_array_t(_v_v3, &_c1, _ctx); _res = ap_abstract0_oct_of_generator_array(man, v1, v2, v3); _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ I0_CHECK_EXC(man) /* end user-supplied deallocation sequence */ return _vres; } value camlidl_oct_ap_abstract0_oct_widening_thresholds( value _v_man, value _v_a1, value _v_a2, value _v_array) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a1; /*in*/ ap_abstract0_ptr a2; /*in*/ struct ap_scalar_array_t array; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a1, &a1, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a2, &a2, _ctx); camlidl_ml2c_scalar_struct_ap_scalar_array_t(_v_array, &array, _ctx); /* begin user-supplied calling sequence */ _res = ap_abstract0_oct_widening_thresholds(man,a1,a2,(const ap_scalar_t**)array.p,array.size); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ I0_CHECK_EXC(man) /* end user-supplied deallocation sequence */ return _vres; } value camlidl_oct_ap_abstract0_oct_narrowing( value _v_man, value _v_a1, value _v_a2) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a1; /*in*/ ap_abstract0_ptr a2; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a1, &a1, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a2, &a2, _ctx); _res = ap_abstract0_oct_narrowing(man, a1, a2); _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ I0_CHECK_EXC(man) /* end user-supplied deallocation sequence */ return _vres; } value camlidl_oct_ap_abstract0_oct_add_epsilon( value _v_man, value _v_a, value _v_epsilon) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_scalar_ptr epsilon; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); camlidl_ml2c_scalar_ap_scalar_ptr(_v_epsilon, &epsilon, _ctx); _res = ap_abstract0_oct_add_epsilon(man, a, epsilon); _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ I0_CHECK_EXC(man) /* end user-supplied deallocation sequence */ return _vres; } value camlidl_oct_ap_abstract0_oct_add_epsilon_bin( value _v_man, value _v_a1, value _v_a2, value _v_epsilon) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a1; /*in*/ ap_abstract0_ptr a2; /*in*/ ap_scalar_ptr epsilon; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a1, &a1, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a2, &a2, _ctx); camlidl_ml2c_scalar_ap_scalar_ptr(_v_epsilon, &epsilon, _ctx); _res = ap_abstract0_oct_add_epsilon_bin(man, a1, a2, epsilon); _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ I0_CHECK_EXC(man) /* end user-supplied deallocation sequence */ return _vres; } apron-dist-0.9.10/apron/octagons/tmp/oct.idl0000640014525101416610000001476211252216517020574 0ustar bjeannetpopart/* -*- mode: c -*- */ /* * oct.idl * * OCaml interface specification for camlidl * * APRON Library / Octagonal Domain * * Copyright (C) Antoine Mine' 2006 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ quote(C,"/*\n This file is part of the APRON Library, released under LGPL license.\n Please read the COPYING file packaged in the distribution.\n*/") quote(MLMLI,"(*\n This file is part of the APRON Library, released under LGPL license.\n Please read the COPYING file packaged in the distribution.\n*)") quote(MLI,"\n \n(** Octagon abstract domain. *)\n \n") quote(C,"#include \"oct.h\"") quote(C,"#include \"apron_caml.h\"") quote(C,"#define I0_CHECK_EXC(man) if (man->result.exn!=AP_EXC_NONE){ value v = camlidl_c2ml_manager_struct_ap_exclog_t(man->result.exclog,_ctx); caml_raise_with_arg(*caml_named_value(\"apron exception\"),v); } ") quote(C,"typedef struct oct_internal_t* internal_ptr;") import "generator0.idl"; import "abstract0.idl"; import "scalar.idl"; import "manager.idl"; typedef [abstract] struct oct_internal_t* internal_ptr; quote(MLMLI,"\n \n\ type t\n\ (** Type of octagons.\n\n\ Octagons are defined by conjunctions of inequalities of the form\n\ [+/-x_i +/- x_j >= 0].\n\n\ Abstract values which are octagons have the type [t Apron.AbstractX.t].\n\n\ Managers allocated for octagons have the type [t Apron.manager.t].\n\ *)\n\n \ ") quote(MLI,"(** Allocate a new manager to manipulate octagons. *)") ap_manager_ptr oct_manager_alloc(void); quote(MLI,"(** No internal parameters for now... *)") internal_ptr manager_get_internal(ap_manager_ptr man) quote(call,"_res = (internal_ptr)man->internal;"); quote(MLI,"(** Approximate a set of generators to an abstract value, with best precision. *)") ap_abstract0_ptr ap_abstract0_oct_of_generator_array(ap_manager_ptr man, int v1, int v2, [ref]struct ap_generator0_array_t* v3) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Widening with scalar thresholds. *)") ap_abstract0_ptr ap_abstract0_oct_widening_thresholds(ap_manager_ptr man,ap_abstract0_ptr a1,ap_abstract0_ptr a2,struct ap_scalar_array_t array) quote(call,"_res = ap_abstract0_oct_widening_thresholds(man,a1,a2,(const ap_scalar_t**)array.p,array.size);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Standard narrowing. *)") ap_abstract0_ptr ap_abstract0_oct_narrowing(ap_manager_ptr man, ap_abstract0_ptr a1,ap_abstract0_ptr a2) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Perturbation. *)") ap_abstract0_ptr ap_abstract0_oct_add_epsilon(ap_manager_ptr man,ap_abstract0_ptr a,ap_scalar_ptr epsilon) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Perturbation. *)") ap_abstract0_ptr ap_abstract0_oct_add_epsilon_bin(ap_manager_ptr man,ap_abstract0_ptr a1,ap_abstract0_ptr a2,ap_scalar_ptr epsilon) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Algorithms. *)") const int pre_widening = 99; quote(MLI,"\n(** {2 Type conversions} *) val manager_is_oct : 'a Apron.Manager.t -> bool (** Return [true] iff the argument manager is an octagon manager *) val manager_of_oct : t Apron.Manager.t -> 'a Apron.Manager.t (** Make an octagon manager generic *) val manager_to_oct : 'a Apron.Manager.t -> t Apron.Manager.t (** Instanciate the type of an octagon manager. Raises [Failure] if the argument manager is not an octagon manager *) module Abstract0 : sig val is_oct : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument value is an oct value *) val of_oct : t Apron.Abstract0.t -> 'a Apron.Abstract0.t (** Make an oct value generic *) val to_oct : 'a Apron.Abstract0.t -> t Apron.Abstract0.t (** Instanciate the type of an oct value. Raises [Failure] if the argument value is not an oct value *) end module Abstract1 : sig val is_oct : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument value is an oct value *) val of_oct : t Apron.Abstract1.t -> 'a Apron.Abstract1.t (** Make an oct value generic *) val to_oct : 'a Apron.Abstract1.t -> t Apron.Abstract1.t (** Instanciate the type of an oct value. Raises [Failure] if the argument value is not an oct value *) end ") quote(ML," let manager_is_oct man = let str = Apron.Manager.get_library man in (String.compare str \"oct\")==0 let manager_of_oct (man:t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_oct (man:'a Apron.Manager.t) : t Apron.Manager.t = if manager_is_oct man then Obj.magic man else failwith \"Oct.manager_to_oct: the argument manager is not an Oct manager\" module Abstract0 = struct let is_oct abs = manager_is_oct (Apron.Abstract0.manager abs) let of_oct (abs: t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let to_oct (abs:'a Apron.Abstract0.t) : t Apron.Abstract0.t = if is_oct abs then Obj.magic abs else failwith \"Oct.Abstract0.to_oct: the argument value is not an oct value\" end module Abstract1 = struct let is_oct abs = manager_is_oct (Apron.Abstract1.manager abs) let of_oct (abs: t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let to_oct (abs:'a Apron.Abstract1.t) : t Apron.Abstract1.t = if is_oct abs then Obj.magic abs else failwith \"Oct.Abstract1.to_oct: the argument value is not an oct value\" end ") quote(MLI,"\n(** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. {3 Bytecode compilation} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma octD.cma mlexample.ml]} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \\ bigarray.cma gmp.cma apron.cma octD.cma ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma octD.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa octD.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa octD.cmxa mlexample.ml \\ -cclib \"-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib \\ -loctD_caml_debug -loctD_debug \\ -lapron_caml_debug -lapron_debug \\ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP_PREFIX/lib -lgmp \\ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \\ -lbigarray\" ]} *)") apron-dist-0.9.10/apron/octagons/tmp/dim.idl0000640014525101416610000000653611252216517020560 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \n\ #include \"ap_dimension.h\"\n\ #include \"caml/mlvalues.h\"\n\ #include \"apron_caml.h\"\n\ ") typedef unsigned int ap_dim_t; typedef [mltype("{\n dim : int array;\n intdim : int;\n realdim : int;\n}"), c2ml(camlidl_apron_dimchange_c2ml), ml2c(camlidl_apron_dimchange_ml2c)] struct ap_dimchange_t ap_dimchange_t; struct ap_dimchange2_t { ap_dimchange_t* add; ap_dimchange_t* remove; }; struct ap_dimperm_t { [size_is(size)]unsigned int* dim; unsigned int size; }; struct ap_dimension_t { [mlname(intd)]unsigned int intdim; [mlname(reald)]unsigned int realdim; }; quote(MLMLI,"(** APRON Dimensions and related types *)") quote(MLI,"\n(** {ul {- [t=int] is the type of dimensions.} {- The semantics of an object [(change:change)] is the following one: {ul {- [change.intdim] and [change.realdim] indicate the number of integer and real dimensions to add or to remove} {- In case of the addition of dimensions, [change.dim[i]=k] means: add one dimension at dimension k and shift the already existing dimensions greater than or equal to k one step on the right (or increment them). if k is equal to the size of the vector, then it means: add a dimension at the end. Repetition are allowed, and means that one inserts more than one dimensions. Example: [add_dimensions [i0 i1 r0 r1] { dim=[0 1 2 2 4]; intdim=3; realdim=1 }] returns [0 i0 0 i1 0 0 r0 r1 0], considered as a vector with 6 integer dimensions and 3 real dimensions.} {- In case of the removal of dimensions, dimchange.dim[i]=k means: remove the dimension k and shift the dimensions greater than k one step on the left (or decrement them). Repetitions are meaningless (and are not correct specification) Example: [remove_dimensions [i0 i1 i2 r0 r1 r2] { dim=[0 2 4]; intdim=2; realdim=1 }] returns [i1 r0 r2], considered as a vector with 1 integer dimensions and 2 real dimensions. }}} {- The semantics of an object [(change2:change2)] is the combination of the two following transformations: {ul {- [change2.add] indicates an optional addition of dimensions.} {- [change2.remove] indicates an optional removal of dimensions.} }} {- [perm] defines a permutation.} {- [dimension] defines the dimensionality of an abstract value (number of integer and real dimensions). }} *) ") quote(MLI," (** Assuming a transformation for add_dimensions, invert it in-place to obtain the inverse transformation using remove_dimensions *) val change_add_invert : change -> unit (** [perm_compose perm1 perm2] composes the 2 permutations perm1 and perm2 (in this order). The sizes of permutations are supposed to be equal. *) val perm_compose : perm -> perm -> perm (** Invert a permutation *) val perm_invert : perm -> perm ") quote(ML," let change_add_invert change = let dim = change.dim in for i=0 to (Array.length dim)-1 do dim.(i) <- dim.(i) + i; done let perm_compose perm1 perm2 = let length = Array.length perm1 in assert(length==(Array.length perm2)); Array.init length (fun i -> perm2.(perm1.(i))) let perm_invert perm = let length = Array.length perm in let res = Array.make length 0 in for i=0 to length-1 do res.(perm.(i)) <- i; done; res ") apron-dist-0.9.10/apron/octagons/tmp/manager.idl0000640014525101416610000002455111252216517021416 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \n\ #include \"ap_manager.h\"\n\ #include \"apron_caml.h\"\n\ \n\ void camlidl_apron_manager_funid_ml2c(value _v, enum ap_funid_t* res)\n\ {\n\ int v = Int_val(_v);\n\ if (v+1>=AP_FUNID_CHANGE_ENVIRONMENT)\n\ *res = v+1;\n\ else\n\ *res = v;\n\ }\n\ value camlidl_apron_manager_funid_c2ml(enum ap_funid_t* arg)\n\ {\n\ int n = *arg;\n\ if (n>=0 && nAP_FUNID_SIZE) n--;\n\ }\n\ else {\n\ invalid_argument(\"enum ap_funid_t: bad enum value\");\n\ }\n\ return Val_int(n);\n\ }\n\ void camlidl_apron_manager_exc_ml2c(value _v, enum ap_exc_t* res)\n\ {\n\ *res = Int_val(_v);\n\ }\n\ value camlidl_apron_manager_exc_c2ml(enum ap_exc_t* arg)\n\ {\n\ int n = *arg;\n\ if (! (n>=AP_EXC_NONE && n= AP_FUNID_SIZE) invalid_argument(\"Manager.get.funopt : should be different from Funid_change_environment and Funid_rename_array (no option for remaining identifiers)\");\n\ _res = ap_manager_get_funopt(man,funid);\n\ "); quote(MLI,"(** Set the options for the function. [funid] should be different from [Funid_change_environment] and [Funid_rename_array] (no option associated to them). *)") void ap_manager_set_funopt(ap_manager_ptr man, ap_funid_t funid, [ref]struct ap_funopt_t* funopt) quote(call,"\ if (funid >= AP_FUNID_SIZE) invalid_argument(\"Manager.set.funopt ...: should be different from Funid_change_environment and Funid_rename_array (no option for remaining identifiers)\");\n\ ap_manager_set_funopt(man,funid,funopt);\n\ "); quote(MLI,"(** Get the corresponding result flag *)") boolean ap_manager_get_flag_exact(ap_manager_ptr man); quote(MLI,"(** Get the corresponding result flag *)") boolean ap_manager_get_flag_best(ap_manager_ptr man); quote(MLI,"(** Exception raised by functions of the interface *)") quote(MLMLI,"exception Error of ap_exclog_t"); quote(ML,"\ let _ = Callback.register_exception \"apron exception\" \ (Error { exn=Exc_none; funid = Funid_bottom; msg = \"dummy\"; })") quote(MLI,"val string_of_funid: ap_funid_t -> string") quote(MLI,"val string_of_exc: ap_exc_t -> string") quote(MLI,"val print_funid: Format.formatter -> ap_funid_t -> unit") quote(MLI,"val print_funopt: Format.formatter -> ap_funopt_t -> unit") quote(MLI,"val print_exc: Format.formatter -> ap_exc_t -> unit") quote(MLI,"val print_exclog: Format.formatter -> ap_exclog_t -> unit") quote(MLI," (** Printing functions *)") quote(ML,"\n\ let string_of_funid = function\n\ | Funid_unknown -> \"Funid_unknown\"\n\ | Funid_copy -> \"Funid_copy\"\n\ | Funid_free -> \"Funid_free\"\n\ | Funid_asize -> \"Funid_asize\"\n\ | Funid_minimize -> \"Funid_minimize\"\n\ | Funid_canonicalize -> \"Funid_canonicalize\"\n\ | Funid_hash -> \"Funid_hash\"\n\ | Funid_approximate -> \"Funid_approximate\"\n\ | Funid_fprint -> \"Funid_fprint\"\n\ | Funid_fprintdiff -> \"Funid_fprintdiff\"\n\ | Funid_fdump -> \"Funid_fdump\"\n\ | Funid_serialize_raw -> \"Funid_serialize_raw\"\n\ | Funid_deserialize_raw -> \"Funid_deserialize_raw\"\n\ | Funid_bottom -> \"Funid_bottom\"\n\ | Funid_top -> \"Funid_top\"\n\ | Funid_of_box -> \"Funid_of_box\"\n\ | Funid_dimension -> \"Funid_dimension\"\n\ | Funid_is_bottom -> \"Funid_is_bottom\"\n\ | Funid_is_top -> \"Funid_is_top\"\n\ | Funid_is_leq -> \"Funid_is_leq\"\n\ | Funid_is_eq -> \"Funid_is_eq\"\n\ | Funid_is_dimension_unconstrained -> \"Funid_is_dimension_unconstrained\"\n\ | Funid_sat_interval -> \"Funid_sat_interval\"\n\ | Funid_sat_lincons -> \"Funid_sat_lincons\"\n\ | Funid_sat_tcons -> \"Funid_sat_tcons\"\n\ | Funid_bound_dimension -> \"Funid_bound_dimension\"\n\ | Funid_bound_linexpr -> \"Funid_bound_linexpr\"\n\ | Funid_bound_texpr -> \"Funid_bound_texpr\"\n\ | Funid_to_box -> \"Funid_to_box\"\n\ | Funid_to_lincons_array -> \"Funid_to_lincons_array\"\n\ | Funid_to_tcons_array -> \"Funid_to_tcons_array\"\n\ | Funid_to_generator_array -> \"Funid_to_generator_array\"\n\ | Funid_meet -> \"Funid_meet\"\n\ | Funid_meet_array -> \"Funid_meet_array\"\n\ | Funid_meet_lincons_array -> \"Funid_meet_lincons_array\"\n\ | Funid_meet_tcons_array -> \"Funid_meet_tcons_array\"\n\ | Funid_join -> \"Funid_join\"\n\ | Funid_join_array -> \"Funid_join_array\"\n\ | Funid_add_ray_array -> \"Funid_add_ray_array\"\n\ | Funid_assign_linexpr_array -> \"Funid_assign_linexpr_array\"\n\ | Funid_substitute_linexpr_array -> \"Funid_substitute_linexpr_array\"\n\ | Funid_assign_texpr_array -> \"Funid_assign_texpr_array\"\n\ | Funid_substitute_texpr_array -> \"Funid_substitute_texpr_array\"\n\ | Funid_add_dimensions -> \"Funid_add_dimensions\"\n\ | Funid_remove_dimensions -> \"Funid_remove_dimensions\"\n\ | Funid_permute_dimensions -> \"Funid_permute_dimensions\"\n\ | Funid_forget_array -> \"Funid_forget_array\"\n\ | Funid_expand -> \"Funid_expand\"\n\ | Funid_fold -> \"Funid_fold\"\n\ | Funid_widening -> \"Funid_widening\"\n\ | Funid_closure -> \"Funid_closure\"\n\ | Funid_change_environment -> \"Funid_change_environment\"\n\ | Funid_rename_array -> \"Funid_rename_array\"\n\ \n\ let string_of_exc = function\n\ | Exc_none -> \"Exc_none\"\n\ | Exc_timeout -> \"Exc_timeout\"\n\ | Exc_out_of_space -> \"Exc_out_of_space\"\n\ | Exc_overflow -> \"Exc_overflow\"\n\ | Exc_invalid_argument -> \"Exc_invalid_argument\"\n\ | Exc_not_implemented -> \"Exc_not_implemented\"\n\ \n\ let print_funid fmt x = Format.pp_print_string fmt (string_of_funid x)\n\ let print_exc fmt x = Format.pp_print_string fmt (string_of_exc x)\n\ let print_exclog fmt x =\n\ Format.fprintf fmt \"{ @[ exn = %a;@ funid = %a;@ msg = %s;@] }\" print_exc x.exn print_funid x.funid x.msg\n\ let print_funopt fmt x =\n\ Format.fprintf fmt \"{ @[ algorithm = %i;@ timeout = %i;@ max_object_size = %i;@ flag_exact_wanted = %b;@ flag_best_wanted = %b;@] }\" x.algorithm x.timeout x.max_object_size x.flag_exact_wanted x.flag_best_wanted\n\ ") quote(MLI,"(** Set / get the global manager used for deserialization *)") void ap_manager_set_deserialize(ap_manager_ptr man); ap_manager_ptr ap_manager_get_deserialize(); /* Init */ quote(ML,"external init: unit -> unit = \"camlidl_apron_init\"\n") quote(ML,"let _ = init()") apron-dist-0.9.10/apron/octagons/tmp/generator0.idl0000640014525101416610000000352211252216517022045 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(MLI,"(** APRON Generators of level 0 *)") quote(C, "\n\ #include \n\ #include \"ap_generator0.h\"\n\ #include \"apron_caml.h\"\n\ \n\ #define LINE AP_GEN_LINE \n\ #define RAY AP_GEN_RAY \n\ #define VERTEX AP_GEN_VERTEX \n\ #define LINEMOD AP_GEN_LINEMOD \n\ #define RAYMOD AP_GEN_RAYMOD \n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; import "linexpr0.idl"; enum gentyp { LINE, RAY, VERTEX, LINEMOD, RAYMOD }; struct ap_generator0_t { [mlname(mutable_linexpr0)] ap_linexpr0_ptr linexpr0; /* constant coefficient ignored */ [mlname(mutable_typ)] enum gentyp gentyp; }; struct ap_generator0_array_t { [size_is(size)] struct ap_generator0_t* p; int size; }; quote(MLI,"\n\ (** Making a generator. The constant coefficient of the linear expression is\n\ ignored. Modifying later the linear expression modifies correspondingly the\n\ generator and conversely. *)\n\ val make : Linexpr0.t -> typ -> t\n\ \n\ (** Copy a generator (deep copy) *)\n\ val copy : t -> t\n\ \n\ (** Convert a generator type to a string ([LIN],[RAY], or [VTX]) *)\n\ val string_of_typ : typ -> string\n\ \n\ (** Print a generator *)\n\ val print : (Dim.t -> string) -> Format.formatter -> t -> unit\n\ ") quote(ML,"\n\ let string_of_typ = function\n\ | LINE -> \"LIN\"\n\ | RAY -> \"RAY\"\n\ | VERTEX -> \"VTX\"\n\ | LINEMOD -> \"LINMOD\"\n\ | RAYMOD -> \"RAYMOD\"\n\ \n\ let print assoc fmt gen = \n\ Format.fprintf fmt \"%s:\" (string_of_typ gen.gentyp);\n\ Linexpr0.print assoc fmt gen.linexpr0;\n\ ()\n\ let make expr typ = {\n\ linexpr0 = expr; typ = typ;\n\ }\n\ let copy gen = {\n\ linexpr0 = Linexpr0.copy gen.linexpr0; typ = gen.typ;\n\ }\n\ ") apron-dist-0.9.10/apron/octagons/tmp/texpr1.idl0000640014525101416610000003260311252216517021224 0ustar bjeannetpopart/* -*- mode: c -*- */ quote(MLI,"(** APRON Expressions of level 1 *)") quote(C, "\n\ #include \n\ #include \"ap_texpr1.h\"\n\ #include \"apron_caml.h\"\n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "texpr0.idl"; import "environment.idl"; struct ap_texpr1_t { [mlname(mutable_texpr0)] ap_texpr0_ptr texpr0; [mlname(mutable_env)] ap_environment_ptr env; }; quote(MLMLI,"\n\ (** Unary operators *) \n\ type unop = Texpr0.unop = \n\ | Neg\n\ | Cast\n\ | Sqrt\n\ \n\ (** Binary operators *) \n\ type binop = Texpr0.binop = \n\ | Add\n\ | Sub\n\ | Mul\n\ | Div\n\ | Mod\n\ \n\ (** Destination type for rounding *) \n\ type typ = Texpr0.typ = \n\ | Real\n\ | Int\n\ | Single\n\ | Double\n\ | Extended\n\ | Quad\n\ \n\ (** Rounding direction *) \n\ type round = Texpr0.round = \n\ | Near\n\ | Zero\n\ | Up\n\ | Down\n\ | Rnd\n\ \n\ (** User type for tree expressions *) \n\ type expr = \n\ | Cst of Coeff.t \n\ | Var of Var.t \n\ | Unop of unop * expr * typ * round \n\ | Binop of binop * expr * expr * typ * round \n\ ") quote(C, "\n\ value camlidl_texpr1_ap_texpr1_to_expr_c2ml(ap_environment_t* env, ap_texpr0_t* expr, camlidl_ctx _ctx)\n\ {\n\ value _v_res ;\n\ \n\ switch(expr->discr){\n\ case AP_TEXPR_CST:\n\ {\n\ value v0 = Val_unit;\n\ Begin_root(v0);\n\ v0 = camlidl_c2ml_coeff_struct_ap_coeff_t(&expr->val.cst, _ctx);\n\ _v_res = caml_alloc_small(1,0);\n\ Field(_v_res,0) = v0;\n\ End_roots();\n\ }\n\ break;\n\ case AP_TEXPR_DIM:\n\ {\n\ ap_var_t var;\n\ value v0 = Val_unit;\n\ var = ap_environment_var_of_dim(env,expr->val.dim);\n\ assert(var!=NULL);\n\ var = ap_var_copy(var);\n\ Begin_root(v0);\n\ v0 = camlidl_apron_var_ptr_c2ml(&var);\n\ _v_res = caml_alloc_small(1,1);\n\ Field(_v_res,0) = v0;\n\ End_roots();\n\ }\n\ break;\n\ case AP_TEXPR_NODE:\n\ {\n\ value v0,v1,v2,v3,v4;\n\ v0 = v1 = v2 = v3 = v4 = Val_unit;\n\ Begin_roots5(v0,v1,v2,v3,v4);\n\ ap_texpr0_node_t* node = expr->val.node;\n\ v1 = camlidl_texpr1_ap_texpr1_to_expr_c2ml(env,node->exprA,_ctx);\n\ v3 = camlidl_apron_texpr_rtype_t_c2ml(&node->type);\n\ v4 = camlidl_apron_texpr_rdir_t_c2ml(&node->dir);\n\ if (ap_texpr_is_unop(node->op)){\n\ v0 = camlidl_apron_texpr_unop_t_c2ml(&node->op);\n\ _v_res = caml_alloc_small(4,2);\n\ Field(_v_res,0) = v0;\n\ Field(_v_res,1) = v1;\n\ Field(_v_res,2) = v3;\n\ Field(_v_res,3) = v4;\n\ }\n\ else {\n\ v0 = camlidl_apron_texpr_binop_t_c2ml(&node->op);\n\ v2 = camlidl_texpr1_ap_texpr1_to_expr_c2ml(env,node->exprB,_ctx);\n\ _v_res = caml_alloc_small(5,3);\n\ Field(_v_res,0) = v0;\n\ Field(_v_res,1) = v1;\n\ Field(_v_res,2) = v2;\n\ Field(_v_res,3) = v3;\n\ Field(_v_res,4) = v4;\n\ }\n\ End_roots();\n\ }\n\ break;\n\ default:\n\ abort();\n\ }\n\ return _v_res;\n\ }\n\ value camlidl_texpr1_ap_texpr1_to_expr(value _v_texpr)\n\ {\n\ CAMLparam1(_v_texpr);\n\ CAMLlocal1(_v_res);\n\ ap_environment_t* env;\n\ ap_texpr1_t texpr1;\n\ \n\ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL };\n\ camlidl_ctx _ctx = &_ctxs;\n\ \n\ camlidl_ml2c_texpr1_struct_ap_texpr1_t(_v_texpr,&texpr1,_ctx);\n\ _v_res = camlidl_texpr1_ap_texpr1_to_expr_c2ml(texpr1.env,texpr1.texpr0,_ctx);\n\ camlidl_free(_ctx);\n\ \n\ CAMLreturn(_v_res);\n\ }\n\ \n\ void camlidl_texpr1_ap_texpr0_of_expr_ml2c(value v, ap_environment_t* env, ap_texpr0_t** res, camlidl_ctx _ctx)\n\ {\n\ ap_texpr0_t* texpr;\n\ ap_texpr0_node_t* node;\n\ ap_coeff_t coeff;\n\ ap_var_t var;\n\ ap_dim_t dim;\n\ ap_texpr0_t* exprA;\n\ ap_texpr0_t* exprB;\n\ value v0,v1,v2,v3,v4;\n\ \n\ texpr = malloc(sizeof(ap_texpr0_t));\n \ \n\ assert (Is_block(v));\n\ switch (Tag_val(v)){\n\ case 0: /* Constant */\n\ assert(Wosize_val(v)==1);\n\ v0 = Field(v,0);\n\ texpr->discr = AP_TEXPR_CST;\n\ camlidl_ml2c_coeff_struct_ap_coeff_t(v0,&coeff,_ctx);\n\ ap_coeff_init_set(&texpr->val.cst,&coeff);\n\ break;\n\ case 1: /* Variable */\n\ assert(Wosize_val(v)==1);\n\ v0 = Field(v,0);\n\ camlidl_apron_var_ptr_ml2c(v0,&var);\n\ texpr->discr = AP_TEXPR_DIM;\n\ texpr->val.dim = ap_environment_dim_of_var(env,var);\n\ if (texpr->val.dim == AP_DIM_MAX){\n\ free(texpr);\n\ texpr = NULL;\n\ }\n\ break;\n\ case 2: /* Unary node */\n\ v0 = Field(v,0);\n\ v1 = Field(v,1);\n\ v2 = Field(v,2);\n\ v3 = Field(v,3);\n\ \n\ camlidl_texpr1_ap_texpr0_of_expr_ml2c(v1,env,&exprA,_ctx);\n\ if (exprA==NULL){\n\ free(texpr);\n\ texpr = NULL;\n\ }\n\ else {\n\ node = malloc(sizeof(ap_texpr0_node_t));\n\ camlidl_apron_texpr_unop_t_ml2c (v0,&node->op);\n\ camlidl_apron_texpr_rtype_t_ml2c (v2,&node->type);\n\ camlidl_apron_texpr_rdir_t_ml2c (v3,&node->dir);\n\ node->exprA = exprA; \n\ node->exprB = NULL;\n\ texpr->discr = AP_TEXPR_NODE;\n\ texpr->val.node = node;\n\ }\n\ break;\n\ case 3: /* Binary node */\n\ v0 = Field(v,0);\n\ v1 = Field(v,1);\n\ v2 = Field(v,2);\n\ v3 = Field(v,3);\n\ v4 = Field(v,4);\n\ camlidl_texpr1_ap_texpr0_of_expr_ml2c(v1,env,&exprA,_ctx);\n\ if (exprA==NULL){\n\ free(texpr);\n\ texpr = NULL;\n\ }\n\ else {\n\ camlidl_texpr1_ap_texpr0_of_expr_ml2c(v2,env,&exprB,_ctx);\n\ if (exprB==NULL){\n\ ap_texpr0_free(exprA);\n\ free(texpr);\n\ texpr = NULL;\n\ }\n\ else {\n\ node = malloc(sizeof(ap_texpr0_node_t));\n\ camlidl_apron_texpr_binop_t_ml2c (v0,&node->op);\n\ camlidl_apron_texpr_rtype_t_ml2c (v3,&node->type);\n\ camlidl_apron_texpr_rdir_t_ml2c (v4,&node->dir);\n\ node->exprA = exprA; \n\ node->exprB = exprB; \n\ texpr->discr = AP_TEXPR_NODE;\n\ texpr->val.node = node;\n\ }\n\ }\n\ break;\n\ default:\n\ assert(false);\n\ }\n\ *res = texpr;\n\ }\n\ value camlidl_texpr1_ap_texpr0_of_expr(value _v_env, value _v_expr)\n\ {\n\ CAMLparam2(_v_env,_v_expr);\n\ CAMLlocal1(_v_res);\n\ ap_texpr0_t* texpr0;\n\ ap_environment_t* env;\n\ \n\ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL };\n\ camlidl_ctx _ctx = &_ctxs;\n\ \n\ camlidl_apron_environment_ptr_ml2c(_v_env,&env);\n\ camlidl_texpr1_ap_texpr0_of_expr_ml2c(_v_expr,env,&texpr0,_ctx);\n\ camlidl_free(_ctx);\n\ if (texpr0==NULL){\n\ caml_failwith(\"Texpr1.texpr0_of_expr: unknown variable in the environment\");\n\ }\n\ _v_res = camlidl_apron_texpr0_ptr_c2ml(&texpr0);\n\ CAMLreturn(_v_res);\n\ }\n\ ") quote(MLMLI,"(** {2 Constructors and Destructor} *)") quote(MLI,"(** General constructor (actually the most efficient) *)") quote(MLI,"val of_expr : Environment.t -> expr -> t\n") /* quote(ML,"external texpr0_of_expr : Environment.t -> expr -> Texpr0.t = \"camlidl_texpr1_ap_texpr0_of_expr\") */ quote(ML,"\ let rec expr0_of_expr1 env expr =\n\ match expr with\n\ | Cst x -> Texpr0.Cst x\n\ | Var var -> Texpr0.Dim (Environment.dim_of_var env var)\n\ | Unop(op,e,t,r) -> \n\ Texpr0.Unop(\n\ op,\n\ (expr0_of_expr1 env e),\n\ t,r\n\ )\n\ | Binop(op,e1,e2,t,r) -> \n\ Texpr0.Binop(\n\ op,\n\ (expr0_of_expr1 env e1),\n\ (expr0_of_expr1 env e2),\n\ t,r\n\ )\n\ let texpr0_of_expr env expr =\n\ Texpr0.of_expr (expr0_of_expr1 env expr)\n\ let of_expr env expr = {\n\ texpr0 = texpr0_of_expr env expr;\n\ env = env;\n\ }\n\ ") quote(MLI,"\ (** Copy *)\n\ val copy : t -> t\n\ \n\ (** Conversion *)\n\ val of_linexpr : Linexpr1.t -> t\n\ ") quote(ML,"\n\ let copy e = { texpr0 = Texpr0.copy e.texpr0; env = e.env }\n\ let of_linexpr e = { texpr0 = Texpr0.of_linexpr e.Linexpr1.linexpr0; env = e.Linexpr1.env }\n\ ") quote(MLI,"(** General destructor *)") /* quote(MLMLI,"external to_expr : t -> expr = \"camlidl_texpr1_ap_texpr1_to_expr\"\n") */ quote(MLI,"val to_expr : t -> expr\n") quote(ML,"\ let rec expr1_of_expr0 env expr =\n\ match expr with\n\ | Texpr0.Cst x -> Cst x\n\ | Texpr0.Dim dim -> Var (Environment.var_of_dim env dim)\n\ | Texpr0.Unop(op,e,t,r) -> \n\ Unop(\n\ op,\n\ (expr1_of_expr0 env e),\n\ t,r\n\ )\n\ | Texpr0.Binop(op,e1,e2,t,r) -> \n\ Binop(\n\ op,\n\ (expr1_of_expr0 env e1),\n\ (expr1_of_expr0 env e2),\n\ t,r\n\ )\n\ let to_expr texpr1 =\n\ let expr0 = Texpr0.to_expr texpr1.texpr0 in\n\ expr1_of_expr0 texpr1.env expr0\n\ ") quote(MLI,"\n(** {3 Incremental constructors} *)\n") [ref]struct ap_texpr1_t* ap_texpr1_cst(ap_environment_ptr env, [ref]struct ap_coeff_t* coeff); [ref]struct ap_texpr1_t* ap_texpr1_var(ap_environment_ptr env, ap_var_t var); [ref]struct ap_texpr1_t* ap_texpr1_unop(ap_texpr_unop_t op, [ref]struct ap_texpr1_t* expr, ap_texpr_rtype_t type, ap_texpr_rdir_t dir) quote(call,"_res = ap_texpr1_unop(op,ap_texpr1_copy(expr),type,dir);"); [ref]struct ap_texpr1_t* ap_texpr1_binop(ap_texpr_binop_t op, [ref]struct ap_texpr1_t* exprA, [ref]struct ap_texpr1_t* exprB, ap_texpr_rtype_t type, ap_texpr_rdir_t dir) quote(call,"_res = ap_texpr1_binop(op,ap_texpr1_copy(exprA),ap_texpr1_copy(exprB),type,dir);"); quote(MLMLI,"\n(** {2 Tests} *)\n") quote(MLI,"\ val is_interval_cst : t -> bool \n\ val is_interval_linear : t -> bool \n\ val is_interval_polynomial : t -> bool \n\ val is_interval_polyfrac : t -> bool \n\ val is_scalar : t -> bool \n\ ") quote(ML,"\ let is_interval_cst x = Texpr0.is_interval_cst x.texpr0 \n\ let is_interval_linear x = Texpr0.is_interval_linear x.texpr0 \n\ let is_interval_polynomial x = Texpr0.is_interval_polynomial x.texpr0 \n\ let is_interval_polyfrac x = Texpr0.is_interval_polyfrac x.texpr0 \n\ let is_scalar x = Texpr0.is_scalar x.texpr0 \n\ ") quote(MLMLI,"\n(** {2 Operations} *)\n") quote(MLI,"(** Change the environment of the expression for a super-environement. Raise [Failure] if it is not the case *)") [ref]struct ap_texpr1_t* ap_texpr1_extend_environment([ref]struct ap_texpr1_t* texpr, ap_environment_ptr env) quote(call,"\n\ {\n\ bool b;\n\ _res = ap_texpr1_extend_environment(texpr,env);\n\ if (!_res) caml_failwith(\"Texpr1.extend_environment: new environment is not a superenvironment\");\n\ }\n\ ") ; quote(MLI,"(** Side-effet version of the previous function *)") void ap_texpr1_extend_environment_with([ref]struct ap_texpr1_t* texpr, ap_environment_ptr env) quote(call,"\n\ {\n\ if (texpr->env!=env){ \n\ bool b;\n\ ap_environment_copy(texpr->env); /* to protect it */ \n\ b = ap_texpr1_extend_environment_with(texpr,env);\n\ if (b){ \n\ ap_environment_free(texpr->env); \n\ caml_failwith(\"Texpr1.extend_environment_with: new environment is not a superenvironment\");\n\ }\n\ Store_field(_v_texpr,1,_v_env);\n\ ap_environment_free(env);\n\ }\n\ }\n\ ") ; quote(MLI,"\n\ (** Get the underlying expression of level 0 (which is not a copy). *)\n\ val get_texpr0: t -> Texpr0.t\n\ \n\ (** Get the environement of the expression *)\n\ val get_env: t -> Environment.t\n\ \n\ ") quote(ML,"\n\ let get_texpr0 expr = expr.texpr0\n\ let get_env expr = expr.env\n\ ") quote(MLMLI,"\n(** {2 Printing} *)\n") quote(MLI,"\n\ val string_of_unop : unop -> string\n\ val string_of_binop : binop -> string\n\ val string_of_typ : typ -> string\n\ val string_of_round : round -> string\n\ val print_unop : Format.formatter -> unop -> unit\n\ val print_binop : Format.formatter -> binop -> unit\n\ val print_typ : Format.formatter -> typ -> unit\n\ val print_round : Format.formatter -> round -> unit\n\ val print_expr : Format.formatter -> expr -> unit\n\ (** Print a tree expression *)\n\ val print : Format.formatter -> t -> unit\n\ (** Print an abstract tree expression *)\n\ ") quote(ML,"\n\ let string_of_unop = Texpr0.string_of_unop\n\ let string_of_binop = Texpr0.string_of_binop\n\ let string_of_typ = Texpr0.string_of_typ\n\ let string_of_round = Texpr0.string_of_round\n\ let print_unop = Texpr0.print_unop\n\ let print_binop = Texpr0.print_binop\n\ let print_typ = Texpr0.print_typ\n\ let print_round = Texpr0.print_round\n\ let rec print_expr fmt expr =\n\ let precedence_of_expr = function\n\ | Cst _\n\ | Var _ -> 5\n\ | Unop(op,_,_,_) -> Texpr0.print_precedence_of_unop op\n\ | Binop(op,_,_,_,_) -> Texpr0.print_precedence_of_binop op\n\ in\n\ match expr with\n\ | Cst x -> Coeff.print fmt x\n\ | Var x -> Format.pp_print_string fmt (Var.to_string x)\n\ | Unop(op,e,typ,round) ->\n\ let prec = Texpr0.print_precedence_of_unop op in\n\ let prec1 = precedence_of_expr e in\n\ let par = prec1<=prec in\n\ Format.fprintf fmt \"%s%s%a%s\"\n\ (Texpr0.print_sprint_unop op typ round)\n\ (if par then \"(\" else \"\")\n\ print_expr e\n\ (if par then \")\" else \"\")\n\ | Binop(op,e1,e2,typ,round) ->\n\ let prec = Texpr0.print_precedence_of_binop op in\n\ let prec1 = precedence_of_expr e1 in\n\ let prec2 = precedence_of_expr e2 in\n\ let par1 = prec1 Var.to_string (Environment.var_of_dim expr.env dim))\n\ fmt expr.texpr0\n\ ") apron-dist-0.9.10/apron/octagons/tmp/coeff.idl0000640014525101416610000001130111252216517021053 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \n\ #include \"ap_coeff.h\"\n\ #include \"apron_caml.h\"\n\ \n\ #define Scalar AP_COEFF_SCALAR\n\ #define Interval AP_COEFF_INTERVAL\n\ ") import "scalar.idl"; import "interval.idl"; /* For ap_coeff_t, - the conversion from ML to C may use allocation, but it is automatically freed by Camlidl mechanisms - the conversion from C to ML duplicate the C allocated memory. Hence, the C type should be explicitly deallocated (if allocated from the underlying C function) */ struct ap_coeff_t { int discr; /* discriminant for coefficient */ [switch_is(discr)] union { case Scalar: [ref]ap_scalar_t* scalar; /* cst (normal linear expression) */ case Interval: [ref]struct ap_interval_t* interval; /* interval (quasi-linear expression) */ } val; }; quote(MLMLI,"(** APRON Coefficients (either scalars or intervals) *)") quote(MLI,"\n\ val s_of_mpq : Mpq.t -> t\n\ val s_of_mpqf : Mpqf.t -> t\n\ val s_of_int : int -> t\n\ val s_of_frac : int -> int -> t\n\ (** Create a scalar coefficient of type [Mpqf.t] from resp.\n\ - A multi-precision rational [Mpq.t] \n\ - A multi-precision rational [Mpqf.t] \n\ - an integer \n\ - a fraction [x/y]\n\ *)\n\ \n\ val s_of_float : float -> t\n\ (** Create an interval coefficient of type [Float] with the given value *)\n\ val s_of_mpfr : Mpfr.t -> t\n\ (** Create an interval coefficient of type [Mpfr] with the given value *)\n\ val i_of_scalar : Scalar.t -> Scalar.t -> t\n\ (** Build an interval from a lower and an upper bound *)\n\ val i_of_mpq : Mpq.t -> Mpq.t -> t\n\ val i_of_mpqf : Mpqf.t -> Mpqf.t -> t\n\ val i_of_int : int -> int -> t\n\ val i_of_frac : int -> int -> int -> int -> t\n\ val i_of_float : float -> float -> t\n\ val i_of_mpfr : Mpfr.t -> Mpfr.t -> t\n\ (** Create an interval coefficient from resp. two\n\ - multi-precision rationals [Mpq.t] \n\ - multi-precision rationals [Mpqf.t] \n\ - integers \n\ - fractions [x/y] and [z/w]\n\ - machine floats\n\ - Mpfr floats\n\ *)\n\ \n\ val is_scalar : t -> bool\n\ val is_interval : t -> bool\n\ val cmp : t -> t -> int\n\ (** Non Total Comparison:\n\ - If the 2 coefficients are both scalars, corresp. to Scalar.cmp\n\ - If the 2 coefficients are both intervals, corresp. to Interval.cmp\n\ - otherwise, -3 if the first is a scalar, 3 otherwise\n\ *)\n\ val equal : t -> t -> bool\n\ (** Equality test *)\n\ val is_zero : t -> bool\n\ (** Is the coefficient equal to scalar 0 or interval [0,0] ? *)\n\ val equal_int : t -> int -> bool\n\ (** Is the coefficient equal to scalar b or interval [b,b] ? *)\n\ val neg : t -> t\n\ (** Negation *)\n\ val reduce : t -> t\n\ (** Convert interval to scalar if possible *)\n\ val print : Format.formatter -> t -> unit\n\ (** Printing *)\n\ ") quote(ML,"\n\ let s_of_mpq x = Scalar (Scalar.of_mpq x)\n\ let s_of_mpqf x = Scalar (Scalar.of_mpqf x)\n\ let s_of_int x = Scalar (Scalar.of_int x)\n\ let s_of_frac x y = Scalar (Scalar.of_frac x y)\n\ let s_of_float x = Scalar (Scalar.of_float x)\n\ let s_of_mpfr x = Scalar (Scalar.of_mpfr x)\n\ \n\ let i_of_scalar inf sup = Interval (Interval.of_scalar inf sup)\n\ let i_of_mpq x y = Interval (Interval.of_mpq x y)\n\ let i_of_mpqf x y = Interval (Interval.of_mpqf x y)\n\ let i_of_int x y = Interval (Interval.of_int x y)\n\ let i_of_frac x y z w = Interval (Interval.of_frac x y z w)\n\ let i_of_float x y = Interval (Interval.of_float x y)\n\ let i_of_mpfr x y = Interval (Interval.of_mpfr x y)\n\ \n\ let is_scalar c = match c with Scalar _ -> true | _ -> false\n\ let is_interval c = match c with Interval _ -> true | _ -> false\n\ let cmp c1 c2 = match (c1,c2) with\n\ | (Scalar s1, Scalar s2) -> Scalar.cmp s1 s2\n\ | (Interval i1, Interval i2) -> Interval.cmp i1 i2\n\ | (Scalar _, _) -> (-3)\n\ | _ -> 3\n\ let equal c1 c2 = match (c1,c2) with\n\ | (Scalar s1, Scalar s2) -> Scalar.equal s1 s2\n\ | (Interval i1, Interval i2) -> Interval.equal i1 i2\n\ | _ -> false\n\ let is_zero c = match c with\n\ | Scalar s -> (Scalar.sgn s)=0\n\ | Interval i -> Interval.is_zero i\n\ let equal_int c b = match c with\n\ | Scalar s -> Scalar.equal_int s b\n\ | Interval i -> Interval.equal_int i b\n\ let neg c = match c with\n\ | Scalar s -> Scalar (Scalar.neg s)\n\ | Interval i -> Interval (Interval.neg i)\n\ let reduce c = match c with\n\ | Scalar _ -> c\n\ | Interval i ->\n\ if Scalar.equal i.Interval.inf i.Interval.sup\n\ then Scalar i.Interval.inf\n\ else c\n\ let print fmt c = match c with\n\ | Scalar s -> Scalar.print fmt s\n\ | Interval i -> Interval.print fmt i\n\ ") apron-dist-0.9.10/apron/octagons/tmp/environment.idl0000640014525101416610000002565011252216517022351 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \n\ #include \"ap_environment.h\"\n\ #include \"caml/mlvalues.h\"\n\ #include \"apron_caml.h\"\n\ ") import "dim.idl"; import "var.idl"; quote(C,"enum typvar {\n\ AP_INT,AP_REAL\n\ };\n\ ") enum typvar { AP_INT,AP_REAL }; typedef [abstract, c2ml(camlidl_apron_environment_ptr_c2ml), ml2c(camlidl_apron_environment_ptr_ml2c)] struct ap_environment_ptr ap_environment_ptr; quote(MLMLI,"(** APRON Environments binding dimensions to names *)") quote(MLI,"\n(** Making an environment from a set of integer and real variables. Raise [Failure] in case of name conflict. *)") ap_environment_ptr ap_environment_make([size_is(intdim)]ap_var_t* name_of_intdim, int intdim, [size_is(realdim)]ap_var_t* name_of_realdim, int realdim) quote(call,"\n\ _res = ap_environment_alloc(name_of_intdim,intdim,name_of_realdim,realdim);\n\ if (_res==NULL){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.make: duplicated variable names\");\n\ }\n\ assert(_res->count >= 1);\n\ ") ; quote(MLI,"\n(** Adding to an environment a set of integer and real variables. Raise [Failure] in case of name conflict. *)") ap_environment_ptr ap_environment_add(ap_environment_ptr e, [size_is(intdim)]ap_var_t* name_of_intdim, int intdim, [size_is(realdim)]ap_var_t* name_of_realdim, int realdim) quote(call,"\n\ _res = ap_environment_add(e,name_of_intdim,intdim,name_of_realdim,realdim);\n\ if (_res==NULL){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.add: duplicated variable names\");\n\ }\n\ assert(_res->count >= 1);") ; quote(MLI,"\n(** Remove from an environment a set of variables. Raise [Failure] in case of non-existing variables. *)") ap_environment_ptr ap_environment_remove(ap_environment_ptr e, [size_is(size)]ap_var_t* tvar, int size) quote(call,"\n\ _res = ap_environment_remove(e,tvar,size);\n\ if (_res==NULL){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.remove: unknown variable names\");\n\ }\n\ assert(_res->count >= 1);") ; quote(MLI,"\n(** Renaming in an environment a set of variables. Raise [Failure] in case of interferences with the variables that are not renamed. *)") ap_environment_ptr ap_environment_rename(ap_environment_ptr e, [size_is(size1)]ap_var_t* tvar1, [size_is(size2)]ap_var_t* tvar2, int size1,int size2) quote(call,"\n\ if (size1!=size2){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.rename: arrays of different sizes\");\n\ }\n\ else {\n\ struct ap_dimperm_t perm;\n\ _res = ap_environment_rename(e,tvar1,tvar2,size1,&perm);\n\ ap_dimperm_clear(&perm);\n\ if (_res==NULL){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.rename: unknown variables or interference of new variables with unrenamed variables\");\n\ }\n\ }\n\ assert(_res->count >= 1);") ; quote(MLI,"\n(** Similar to previous function, but returns also \n\ the permutation on dimensions induced by the renaming. *)") ap_environment_ptr ap_environment_rename_perm(ap_environment_ptr e, [size_is(size1)]ap_var_t* tvar1, [size_is(size2)]ap_var_t* tvar2, int size1,int size2, [out] struct ap_dimperm_t perm) quote(call,"\n\ if (size1!=size2){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.rename: arrays of different sizes\");\n\ }\n\ else {\n\ _res = ap_environment_rename(e,tvar1,tvar2,size1,&perm);\n\ if (_res==NULL){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.rename_dimperm: unknown variables or interference of new variables with unrenamed variables\");\n\ }\n\ }\n\ assert(_res->count >= 1);") quote(dealloc,"ap_dimperm_clear(&perm);") ; quote(MLI,"\n (** Compute the least common environment of 2 environment, \n\ that is, the environment composed of all the variables \n\ of the 2 environments.\n\ Raise [Failure] if the same variable has different types \n\ in the 2 environment.\ *)") ap_environment_ptr ap_environment_lce(ap_environment_ptr e1, ap_environment_ptr e2) quote(call,"\n\ {\n\ ap_dimchange_t *c1;\n\ ap_dimchange_t *c2;\n\ _res = ap_environment_lce(e1,e2,&c1,&c2);\n\ if (c1) ap_dimchange_free(c1);\n\ if (c2) ap_dimchange_free(c2);\n\ }\n\ if (_res==NULL){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.lce: variable with two different types\");\n\ }\n\ assert(_res->count >= 1);") ; quote(MLI,"\n (** Similar to the previous function, but returns also the transformations \n\ required to convert from [e1] (resp. [e2]) \n\ to the lce. If [None] is returned, this means \n\ that [e1] (resp. [e2]) is identic to the lce.*)") ap_environment_ptr ap_environment_lce_change([in] ap_environment_ptr e1, [in] ap_environment_ptr e2, [out,unique] ap_dimchange_t *c1, [out,unique] ap_dimchange_t *c2) quote(call,"\n\ {\n\ _res = ap_environment_lce(e1,e2,&c1,&c2);\n\ }\n\ if (_res==NULL){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.lce: variable with two different types\");\n\ }\n\ assert(_res->count >= 1);") quote(dealloc," if (c1) ap_dimchange_free(c1); if (c2) ap_dimchange_free(c2); ") ; quote(MLI,"\n (** [dimchange e1 e2] computes the transformation for \n\ converting from an environment [e1] to a superenvironment \n\ [e2]. Raises [Failure] if [e2] is not a superenvironment.\ *)") [ref]ap_dimchange_t *ap_environment_dimchange(ap_environment_ptr e1, ap_environment_ptr e2) quote(call,"\n\ _res = ap_environment_dimchange(e1,e2);\n\ if (_res==NULL){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.dimchange: the second environment is not a superenvironment of the first one\");\n\ }\n\ ") quote(dealloc,"ap_dimchange_free(_res);") ; quote(MLI,"\n (** [dimchange2 e1 e2] computes the transformation for converting from an environment [e1] to a (compatible) environment [e2], by first adding (some) variables of [e2] and then removing (some) variables of [e1]. Raises [Failure] if the two environments are incompatible. *)") [ref]struct ap_dimchange2_t *ap_environment_dimchange2(ap_environment_ptr e1, ap_environment_ptr e2) quote(call,"\n\ _res = ap_environment_dimchange2(e1,e2);\n\ if (_res==NULL){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.dimchange2: the two environments are not compatible\");\n\ }\n\ ") quote(dealloc,"ap_dimchange2_free(_res);") ; quote(MLI,"\n(** Test equality if two environments *)") boolean ap_environment_equal(ap_environment_ptr env1, ap_environment_ptr env2) quote(call,"\n\ _res = ap_environment_is_eq(env1,env2);\n\ "); quote(MLI,"\n(** Compare two environment. [compare env1 env2] return [-2] if the environements are not compatible (a variable has different types in the 2 environements), [-1] if [env1] is a subset of env2, [0] if equality, [+1] if env1 is a superset of env2, and [+2] otherwise (the lce exists and is a strict superset of both) *)") int ap_environment_compare(ap_environment_ptr env1, ap_environment_ptr env2); quote(MLI,"\n(** Hashing function for environments *)") int ap_environment_hash(ap_environment_ptr env); quote(MLI,"\n(** Return the dimension of the environment *)") struct ap_dimension_t ap_environment_dimension(ap_environment_ptr e) quote(call,"_res.intdim = e->intdim; _res.realdim = e->realdim;"); quote(MLI,"\n(** Return the size of the environment *)") unsigned int ap_environment_size(ap_environment_ptr e) quote(call,"_res = e->intdim + e->realdim;"); quote(MLI,"\n(** Return true if the variable is present in the environment. *)") boolean ap_environment_mem_var(ap_environment_ptr e, ap_var_t var) quote(call,"\n\ {\n\ ap_dim_t dim;\n\ dim = ap_environment_dim_of_var(e,var);\n\ _res = (dim != AP_DIM_MAX);\n\ }"); quote(MLI,"\n(** Return the type of variables in the environment. If the variable does not belong to the environment, raise a [Failure] exception. *)") enum typvar ap_environment_typ_of_var(ap_environment_ptr e, ap_var_t var) quote(call,"\n\ {\n\ ap_dim_t dim;\n\ dim = ap_environment_dim_of_var(e,var);\n\ if (dim==AP_DIM_MAX)\n\ caml_failwith(\"Environment.dim_of_var: unknown variable in the environment\");\n\ _res =\n\ dim=( dimintdim ? AP_INT : AP_REAL);\n\ }"); quote(MLI,"\n(** Return the (lexicographically ordered) sets of integer and real variables in the environment *)") void ap_environment_vars(ap_environment_ptr e, [out,size_is((*e).intdim)]ap_var_t* name_of_intdim, [out,size_is((*e).realdim)]ap_var_t* name_of_realdim) quote(call,"\n\ {\n\ size_t i;\n\ for(i=0;iintdim;i++) name_of_intdim[i] = ap_var_operations->copy(e->var_of_dim[i]);\n \ for(i=0;irealdim;i++) name_of_realdim[i] = ap_var_operations->copy(e->var_of_dim[e->intdim+i]);\n \ }"); quote(MLI,"\n(** Return the variable corresponding to the given dimension in the environment. Raise [Failure] is the dimension is out of the range of the environment (greater than or equal to [dim env]) *)") ap_var_t ap_environment_var_of_dim(ap_environment_ptr e, ap_dim_t dim) quote(call,"\n\ if (dim>=e->intdim+e->realdim){\n\ caml_failwith(\"Environment.var_of_dim: dim out of range w.r.t. the environment\");\n\ }\n\ _res = ap_var_operations->copy(e->var_of_dim[dim]);"); quote(MLI,"\n(** Return the dimension associated to the given variable in the environment. Raise [Failure] if the variable does not belong to the environment. *)") ap_dim_t ap_environment_dim_of_var(ap_environment_ptr e, ap_var_t var) quote(call,"\n\ _res = ap_environment_dim_of_var(e,var);\n\ if (_res==AP_DIM_MAX){\n\ caml_failwith(\"Environment.dim_of_var: unknown variable in the environment\");\n\ }"); quote(MLMLI,"\n(** Printing *)") quote(MLI,"val print :\n\ ?first:(unit, Format.formatter, unit) format ->\n\ ?sep:(unit, Format.formatter, unit) format ->\n\ ?last:(unit, Format.formatter, unit) format ->\n\ Format.formatter -> t -> unit\n\ ") quote(ML,"\n\ let print\n\ ?(first=(\"[|@[\":(unit,Format.formatter,unit) format))\n\ ?(sep = (\";@ \":(unit,Format.formatter,unit) format))\n\ ?(last = (\"@]|]\":(unit,Format.formatter,unit) format))\n\ (fmt:Format.formatter)\n\ (env: t)\n\ : unit\n\ =\n\ let dim = dimension env in\n\ if dim.Dim.intd+dim.Dim.reald=0 then begin\n\ Format.fprintf fmt first;\n\ Format.fprintf fmt last;\n\ end\n\ else begin\n\ Format.fprintf fmt first;\n\ let first = ref true in\n\ for i=0 to pred dim.Dim.intd do\n\ let var = var_of_dim env i in\n\ if !first then first := false else Format.fprintf fmt sep;\n\ Format.fprintf fmt \"%i> %s:int\"\n\ i (Var.to_string var)\n\ done;\n\ for i=dim.Dim.intd to dim.Dim.intd + (pred dim.Dim.reald) do\n\ let var = var_of_dim env i in\n\ if !first then first := false else Format.fprintf fmt sep;\n\ Format.fprintf fmt \"%i> %s:real\"\n\ i (Var.to_string var)\n\ done;\n\ Format.fprintf fmt last;\n\ end\n\ ") apron-dist-0.9.10/apron/octagons/tmp/linexpr1.idl0000640014525101416610000001271411252216517021544 0ustar bjeannetpopart/* -*- mode: c -*- */ quote(MLI,"(** APRON Expressions of level 1 *)") quote(C, "\n\ #include \n\ #include \"ap_linexpr1.h\"\n\ #include \"apron_caml.h\"\n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "linexpr0.idl"; import "environment.idl"; struct ap_linexpr1_t { [mlname(mutable_linexpr0)] ap_linexpr0_ptr linexpr0; [mlname(mutable_env)] ap_environment_ptr env; }; quote(MLI,"\n\n\ (** Build a linear expression defined on the given argument, which is sparse by\n\ default. *)\n\ val make: ?sparse:bool -> Environment.ap_environment_ptr -> t\n\ \n\ (** In case of sparse representation, remove zero coefficients *)\n\ val minimize: t -> unit\n\ \n\ (** Copy *)\n\ val copy: t -> t\n\ \n\ (** Print the linear expression *)\n\ val print: Format.formatter -> t -> unit\n\ \n\ val set_list : t -> (Coeff.t * Var.t) list -> Coeff.t option -> unit\n\ (** Set simultaneously a number of coefficients.\n\ \n\ [set_list expr [(c1,\"x\"); (c2,\"y\")] (Some cst)] assigns coefficients [c1] \n\ to variable [\"x\"], coefficient [c2] to variable [\"y\"], and coefficient [cst]\n\ to the constant. If [(Some cst)] is replaced by [None],\n\ the constant coefficient is not assigned. *)\n\ val set_array : t -> (Coeff.t * Var.t) array -> Coeff.t option -> unit\n\ (** Set simultaneously a number of coefficients, as [set_list]. *)\n\ \n\ (** Iter the function on the pair coefficient/variable of the linear expression *)\n\ val iter: (Coeff.t -> Var.t -> unit) -> t -> unit\n\ \n\ (** Get the constant *)\n\ val get_cst: t -> Coeff.t\n\ \n\ (** Set the constant *)\n\ val set_cst: t -> Coeff.t -> unit\n\ ") quote(MLI,"(** Get the coefficient of the variable *)") struct ap_coeff_t ap_linexpr1_get_coeff([ref]struct ap_linexpr1_t* a, ap_var_t var) quote(call, "\n\ {\n\ bool b;\n\ ap_coeff_init(&_res,AP_COEFF_SCALAR);\n\ b = ap_linexpr1_get_coeff(&_res,a,var);\n\ if (b){\n\ char str[160];\n\ char* name;\n\ ap_coeff_clear(&_res);\n\ name = ap_var_operations->to_string(var);\n\ snprintf(str,159,\"Linexpr1.get_coeff: unknown variable %s in the environment\",name);\n\ free(name);\n\ caml_failwith(str);\n\ }\n\ }\n\ "); quote(MLI,"(** Set the coefficient of the variable *)") void ap_linexpr1_set_coeff([ref]struct ap_linexpr1_t* a, ap_var_t var, [ref]struct ap_coeff_t* coeff) quote(call, "\n\ {\n\ bool b;\n\ b = ap_linexpr1_set_coeff(a,var,coeff);\n\ if (b){\n\ char str[160];\n\ char* name;\n\ name = ap_var_operations->to_string(var);\n\ snprintf(str,159,\"Linexpr1.set_coeff: unknown variable %s in the environment\",name);\n\ free(name);\n\ caml_failwith(str);\n\ }\n\ }\n\ "); quote(MLI,"(** Change the environment of the expression for a super-environement. Raise [Failure] if it is not the case *)") struct ap_linexpr1_t ap_linexpr1_extend_environment(const struct ap_linexpr1_t linexpr, ap_environment_ptr env) quote(call,"\n\ {\n\ bool b;\n\ b = ap_linexpr1_extend_environment(&_res,&linexpr,env);\n\ if (b) caml_failwith(\"Linexpr1.extend_environment: new environment is not a superenvironment\");\n\ }\n\ ") ; quote(MLI,"(** Side-effet version of the previous function *)") void ap_linexpr1_extend_environment_with(struct ap_linexpr1_t linexpr, ap_environment_ptr env) quote(call,"\n\ {\n\ if (linexpr.env!=env){ \n\ bool b;\n\ ap_environment_copy(linexpr.env); /* to protect it */ \n\ b = ap_linexpr1_extend_environment_with(&linexpr,env);\n\ if (b){ \n\ ap_environment_free(linexpr.env); \n\ caml_failwith(\"Linexpr1.extend_environment_with: new environment is not a superenvironment\");\n\ }\n\ Store_field(_v_linexpr,1,_v_env);\n\ ap_environment_free(env);\n\ }\n\ }\n\ ") ; quote(MLI,"(** Does the linear expression depend only on integer variables ? *)") boolean ap_linexpr1_is_integer([ref]struct ap_linexpr1_t* e); quote(MLI,"(** Does the linear expression depend only on real variables ? *)") boolean ap_linexpr1_is_real([ref]struct ap_linexpr1_t* e); quote(MLI,"\n\ (** Get the underlying expression of level 0 (which is not a copy). *)\n\ val get_linexpr0: t -> Linexpr0.t\n\ \n\ (** Get the environement of the expression *)\n\ val get_env: t -> Environment.t\n\ \n\ ") quote(ML,"\n\ let make ?(sparse=true) env = {\n\ linexpr0 = Linexpr0.make\n\ (if sparse\n\ then None\n\ else Some (Environment.size env));\n\ env = env;\n\ }\n\ let minimize e = Linexpr0.minimize e.linexpr0\n\ let copy e = {\n\ linexpr0 = Linexpr0.copy e.linexpr0;\n\ env = e.env;\n\ }\n\ let get_cst expr =\n\ Linexpr0.get_cst expr.linexpr0\n\ let get_linexpr0 expr = expr.linexpr0\n\ let get_env expr = expr.env\n\ let set_cst expr cst =\n\ Linexpr0.set_cst expr.linexpr0 cst\n\ let set_list expr list ocst = \n\ List.iter\n\ (fun (coeff,var) -> set_coeff expr var coeff )\n\ list;\n\ begin match ocst with\n\ | Some cst -> set_cst expr cst\n\ | None -> ()\n\ end;\n\ ()\n\ let set_array expr tab ocst = \n\ Array.iter\n\ (fun (coeff,var) -> set_coeff expr var coeff )\n\ tab;\n\ begin match ocst with\n\ | Some cst -> set_cst expr cst\n\ | None -> ()\n\ end;\n\ ()\n\ \n\ let iter f expr =\n\ Linexpr0.iter\n\ (begin fun coeff dim ->\n\ f coeff (Environment.var_of_dim expr.env dim)\n\ end)\n\ expr.linexpr0\n\ let print fmt expr =\n\ Linexpr0.print\n\ (fun dim -> Var.to_string (Environment.var_of_dim expr.env dim))\n\ fmt expr.linexpr0\n \ ") apron-dist-0.9.10/apron/octagons/tmp/abstract1.idl0000640014525101416610000010067611252216517021673 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \n\ #include \"ap_expr0.h\"\n\ #include \"ap_abstract0.h\"\n\ #include \"ap_environment.h\"\n\ #include \"ap_expr1.h\"\n\ #include \"ap_abstract1.h\"\n\ #include \"caml/callback.h\"\n\ #include \"apron_caml.h\"\n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; import "linexpr0.idl"; import "lincons0.idl"; import "generator0.idl"; import "manager.idl"; import "abstract0.idl"; import "environment.idl"; import "linexpr1.idl"; import "lincons1.idl"; import "generator1.idl"; import "texpr1.idl"; import "tcons1.idl"; struct ap_abstract1_t { [mlname(mutable_abstract0)] ap_abstract0_ptr abstract0; [mlname(mutable_env)] ap_environment_ptr env; }; quote(MLMLI,"(** APRON Abstract values of level 1 *)") quote(MLMLI,"(** The type parameter ['a] allows to distinguish abstract values with different underlying abstract domains. *)\n") quote(MLMLI,"type box1 = { mutable interval_array : Interval.t array; mutable box1_env : Environment.t }") quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(** {2 General management} *)") quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Memory} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n\ (** Copy a value *) val copy : 'a Manager.t -> 'a t -> 'a t\n\ \n\ (** Return the abstract size of a value *) val size : 'a Manager.t -> 'a t -> int\n\ ") quote(ML,"\n\ let copy man x = { abstract0 = Abstract0.copy man x.abstract0; env = x.env }\n\ let size man x = Abstract0.size man x.abstract0\n\ ") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Control of internal representation} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n\ (** Minimize the size of the representation of the value. This may result in a later recomputation of internal information.*) val minimize : 'a Manager.t -> 'a t -> unit\n\ \n\ (** Put the abstract value in canonical form. (not yet clear definition) *) val canonicalize : 'a Manager.t -> 'a t -> unit\n\ \n\ val hash : 'a Manager.t -> 'a t -> int\n\ \n\ (** [approximate man abs alg] perform some transformation on the abstract value, guided by the argument [alg]. The transformation may lose information. The argument [alg] overrides the field algorithm of the structure of type [Manager.funopt] associated to ap_abstract0_approximate (commodity feature).*) val approximate : 'a Manager.t -> 'a t -> int -> unit\n\ \n\ ") quote(ML,"\n\ let minimize man x = Abstract0.minimize man x.abstract0\n\ let canonicalize man x = Abstract0.canonicalize man x.abstract0\n\ let hash man x = 5*(Environment.hash x.env) + Abstract0.hash man x.abstract0\n\ let approximate man x n = Abstract0.approximate man x.abstract0 n\n\ ") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Printing} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n(** Dump on the [stdout] C stream the internal representation of an abstract value, for debugging purposes *)") void ap_abstract1_fdump(ap_manager_ptr man, [ref]struct ap_abstract1_t* a) quote(call,"ap_abstract1_fdump(stdout,man, a); fflush(stdout);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Print as a set of constraints *)") quote(MLI,"val print: Format.formatter -> 'a t -> unit") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Serialization} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(** {2 Constructor, accessors, tests and property extraction} *)") quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Basic constructors} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** All these functions request explicitly an environment in their arguments. *)\n") quote(MLI,"\n(** Create a bottom (empty) value defined on the given environment *)") struct ap_abstract1_t ap_abstract1_bottom(ap_manager_ptr man, ap_environment_ptr env) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Create a top (universe) value defined on the given environment *)") struct ap_abstract1_t ap_abstract1_top(ap_manager_ptr man, ap_environment_ptr env) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Abstract an hypercube.\n\n[of_box man env tvar tinterval] abstracts an hypercube defined by the arrays [tvar] and [tinterval]. The result is defined on the environment [env], which should contain all the variables in [tvar] (and defines their type) *)") struct ap_abstract1_t ap_abstract1_of_box(ap_manager_ptr man, ap_environment_ptr env, [size_is(size)]ap_var_t* tvar, [size_is(size2)]ap_interval_ptr* tinterval, unsigned int size, unsigned int size2) quote(call,"\n\ if (size!=size2)\n\ caml_failwith(\"Abstract1.of_box: the two arrays are of different sizes\");\n\ _res = ap_abstract1_of_box(man,env,tvar,tinterval,size);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Accessors} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n\ val manager : 'a t -> 'a Manager.t\n\ val env : 'a t -> Environment.t\n\ val abstract0 : 'a t -> 'a Abstract0.t\n\ (** Return resp. the underlying manager, environment and abstract value of level 0 *)\n\ ") quote(ML,"\n\ let manager x = Abstract0.manager x.abstract0\n\ let env x = x.env\n\ let abstract0 x = x.abstract0\n\ ") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Tests} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n\ (** Emptiness test *) val is_bottom : 'a Manager.t -> 'a t -> bool\n\ \n\ (** Universality test *) val is_top : 'a Manager.t -> 'a t -> bool\n\ ") quote(ML,"\n\ let is_bottom man x = Abstract0.is_bottom man x.abstract0\n\ let is_top man x = Abstract0.is_top man x.abstract0\n\ ") quote(MLI,"\n(** Inclusion test. The 2 abstract values should be compatible. *)") boolean ap_abstract1_is_leq(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Equality test. The 2 abstract values should be compatible. *)") boolean ap_abstract1_is_eq(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Does the abstract value satisfy the linear constraint ? *)") boolean ap_abstract1_sat_lincons(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_lincons1_t* v) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Does the abstract value satisfy the tree expression constraint ? *)") boolean ap_abstract1_sat_tcons(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_tcons1_t* v) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Does the abstract value satisfy the constraint [dim in interval] ? *)") boolean ap_abstract1_sat_interval(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, ap_var_t v1, [ref]struct ap_interval_t* v2) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Is the variable unconstrained in the abstract value ? If yes, this means that the existential quantification of the dimension does not change the value. *)") boolean ap_abstract1_is_variable_unconstrained(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, ap_var_t v) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Extraction of properties} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n(** Return the interval of variation of the variable in the abstract value. *)") [ref]struct ap_interval_t* ap_abstract1_bound_variable(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, ap_var_t v) quote(dealloc,"ap_interval_free(_res); I0_CHECK_EXC(man)"); quote(MLI,"\n(** Return the interval of variation of the linear expression in the abstract value. \n\nImplement a form of linear programming, where the argument linear expression is the one to optimize under the constraints induced by the abstract value. *)") [ref]struct ap_interval_t* ap_abstract1_bound_linexpr(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_linexpr1_t* v) quote(dealloc,"ap_interval_free(_res); I0_CHECK_EXC(man)"); quote(MLI,"\n(** Return the interval of variation of the tree expression in the abstract value. *)") [ref]struct ap_interval_t* ap_abstract1_bound_texpr(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_texpr1_t* v) quote(dealloc,"ap_interval_free(_res); I0_CHECK_EXC(man)"); quote(MLI,"\n\ (** Convert the abstract value to an hypercube *) val to_box : 'a Manager.t -> 'a t -> box1\n\ \n\ (** Convert the abstract value to a conjunction of linear constraints. *) val to_lincons_array : 'a Manager.t -> 'a t -> Lincons1.earray\n\ (** Convert the abstract value to a conjunction of tree expressions constraints. *) val to_tcons_array : 'a Manager.t -> 'a t -> Tcons1.earray\n\ \n\ (** Convert the abstract value to a set of generators that defines it. *) val to_generator_array : 'a Manager.t -> 'a t -> Generator1.earray\n\ \n\ ") quote(ML,"\n\ let to_lincons_array man x = {\n\ Lincons1.lincons0_array = Abstract0.to_lincons_array man x.abstract0;\n\ Lincons1.array_env = x.env\n\ }\n\ let to_tcons_array man x = {\n\ Tcons1.tcons0_array = Abstract0.to_tcons_array man x.abstract0;\n\ Tcons1.array_env = x.env\n\ }\n\ let to_generator_array man x = {\n\ Generator1.generator0_array = Abstract0.to_generator_array man x.abstract0;\n\ Generator1.array_env = x.env\n\ }\n\ let to_box man x = {\n\ interval_array = Abstract0.to_box man x.abstract0;\n\ box1_env = x.env\n\ }\n\ ") quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(** {2 Operations} *)") quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Meet and Join} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** Meet of 2 abstract values. *)") struct ap_abstract1_t ap_abstract1_meet(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2) quote(call,"_res = ap_abstract1_meet(man,false,a1,a2);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Meet of a non empty array of abstract values. *)") struct ap_abstract1_t ap_abstract1_meet_array(ap_manager_ptr man, [size_is(size)]struct ap_abstract1_t* array, unsigned int size) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Meet of an abstract value with an array of linear constraints. *)") struct ap_abstract1_t ap_abstract1_meet_lincons_array(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_lincons1_array_t* v) quote(call,"_res = ap_abstract1_meet_lincons_array(man,false,a,v);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Meet of an abstract value with an array of tree expressions constraints. *)") struct ap_abstract1_t ap_abstract1_meet_tcons_array(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_tcons1_array_t* v) quote(call,"_res = ap_abstract1_meet_tcons_array(man,false,a,v);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Join of 2 abstract values. *)") struct ap_abstract1_t ap_abstract1_join(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2) quote(call,"_res = ap_abstract1_join(man,false,a1,a2);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Join of a non empty array of abstract values. *)") struct ap_abstract1_t ap_abstract1_join_array(ap_manager_ptr man, [size_is(size)]struct ap_abstract1_t* array, unsigned int size) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Add the array of generators to the abstract value (time elapse operator).\n\n The generators should either lines or rays, not vertices. *)") struct ap_abstract1_t ap_abstract1_add_ray_array(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_generator1_array_t* v) quote(call,"_res = ap_abstract1_add_ray_array(man,false,a,v);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** {5 Side-effect versions of the previous functions} *)\n") void ap_abstract1_meet_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2) quote(call,"{\n\ ap_abstract1_t res = ap_abstract1_meet(man,true,a1,a2);\n\ value v = Field(_v_a1,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_meet_lincons_array_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_lincons1_array_t* v) quote(call,"{\n\ ap_abstract1_t res = ap_abstract1_meet_lincons_array(man,true,a,v);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_meet_tcons_array_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_tcons1_array_t* v) quote(call,"{\n\ ap_abstract1_t res = ap_abstract1_meet_tcons_array(man,true,a,v);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_join_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2) quote(call,"{\n\ ap_abstract1_t res = ap_abstract1_join(man,true,a1,a2);\n\ value v = Field(_v_a1,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_add_ray_array_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_generator1_array_t* v) quote(call,"{\n\ ap_abstract1_t res = ap_abstract1_add_ray_array(man,true,a,v);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Assignement and Substitutions} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** Parallel assignement of an array of dimensions by an array of same size of linear expressions *)") struct ap_abstract1_t ap_abstract1_assign_linexpr_array(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]struct ap_linexpr1_t* v2, int v3,int v4, struct ap_abstract1_t* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.assign_linexpr_array: arrays of different size\");\n\ _res = ap_abstract1_assign_linexpr_array(man,false,a,v1,v2,v3,dest);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Parallel substitution of an array of dimensions by an array of same size of linear expressions *)") struct ap_abstract1_t ap_abstract1_substitute_linexpr_array(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]struct ap_linexpr1_t* v2, int v3, int v4, struct ap_abstract1_t* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.substitute_linexpr_array: arrays of different size\");\n\ _res = ap_abstract1_substitute_linexpr_array(man,false,a,v1,v2,v3,dest);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Parallel assignement of an array of dimensions by an array of same size of tree expressions *)") struct ap_abstract1_t ap_abstract1_assign_texpr_array(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]struct ap_texpr1_t* v2, int v3,int v4, struct ap_abstract1_t* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.assign_texpr_array: arrays of different size\");\n\ _res = ap_abstract1_assign_texpr_array(man,false,a,v1,v2,v3,dest);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Parallel substitution of an array of dimensions by an array of same size of tree expressions *)") struct ap_abstract1_t ap_abstract1_substitute_texpr_array(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]struct ap_texpr1_t* v2, int v3, int v4, struct ap_abstract1_t* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.substitute_texpr_array: arrays of different size\");\n\ _res = ap_abstract1_substitute_texpr_array(man,false,a,v1,v2,v3,dest);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** {5 Side-effect versions of the previous functions} *)\n") void ap_abstract1_assign_linexpr_array_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]struct ap_linexpr1_t* v2, int v3,int v4, struct ap_abstract1_t* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.assign_linexpr_array_with: arrays of different size\");\n\ {\n\ ap_abstract1_t res = ap_abstract1_assign_linexpr_array(man,true,a,v1,v2,v3,dest);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_substitute_linexpr_array_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]struct ap_linexpr1_t* v2, int v3, int v4, struct ap_abstract1_t* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.substitute_linexpr_array_with: arrays of different size\");\n\ {\n\ ap_abstract1_t res = ap_abstract1_substitute_linexpr_array(man,true,a,v1,v2,v3,dest);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_assign_texpr_array_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]struct ap_texpr1_t* v2, int v3, int v4, struct ap_abstract1_t* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.assign_texpr_array_with: arrays of different size\");\n\ {\n\ ap_abstract1_t res = ap_abstract1_assign_texpr_array(man,true,a,v1,v2,v3,dest);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_substitute_texpr_array_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]struct ap_texpr1_t* v2, int v3, int v4, struct ap_abstract1_t* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.substitute_texpr_array_with: arrays of different size\");\n\ {\n\ ap_abstract1_t res = ap_abstract1_substitute_texpr_array(man,true,a,v1,v2,v3,dest);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Projections} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** These functions implements forgeting (existential quantification) of (array of) variables. Both functional and side-effect versions are provided. The Boolean, if true, adds a projection onto 0-plane. *)\n\n") struct ap_abstract1_t ap_abstract1_forget_array(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v2)]ap_var_t* v1, unsigned int v2, boolean v3) quote(call,"_res = ap_abstract1_forget_array(man,false,a,v1,v2,v3);") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_forget_array_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v2)]ap_var_t* v1, int v2, boolean v3) quote(call,"{\n\ ap_abstract1_t res = ap_abstract1_forget_array(man,true,a,v1,v2,v3); value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Change and permutation of dimensions} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** Change the environement of the abstract values.\n\nVariables that are removed are first existentially quantified, and variables that are introduced are unconstrained. The Boolean, if true, adds a projection onto 0-plane for these ones. *)") struct ap_abstract1_t ap_abstract1_change_environment(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, ap_environment_ptr v1, boolean v2) quote(call,"_res = ap_abstract1_change_environment(man,false,a,v1,v2);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Remove from the environment of the abstract value and from the abstract value itself variables that are unconstrained in it. *)") struct ap_abstract1_t ap_abstract1_minimize_environment(ap_manager_ptr man, [ref]struct ap_abstract1_t* a) quote(call,"_res = ap_abstract1_minimize_environment(man,false,a);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Parallel renaming of the environment of the abstract value.\n\nThe new variables should not interfere with the variables that are not renamed. *)") struct ap_abstract1_t ap_abstract1_rename_array(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]ap_var_t* v2, unsigned int v3, unsigned int v4) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.rename_array: arrays of different size\");\n\ _res = ap_abstract1_rename_array(man,false,a,v1,v2,v3);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_change_environment_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, ap_environment_ptr v1, boolean v2) quote(call,"\ {\n\ ap_environment_t* oldenv = ap_environment_copy(a->env);\n \ ap_abstract1_t res = ap_abstract1_change_environment(man,true,a,v1,v2);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ if (res.env==oldenv){\n\ ap_environment_free(oldenv);\n\ }\n\ else {\n\ assert(res.env==v1);\n\ Store_field(_v_a,1,_v_v1);\n\ }\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_minimize_environment_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a) quote(call,"{\n\ ap_environment_t* oldenv = ap_environment_copy(a->env);\n \ ap_abstract1_t res = ap_abstract1_minimize_environment(man,true,a);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ if (res.env==oldenv){\n\ ap_environment_free(oldenv);\n\ }\n\ else {\n\ v = camlidl_apron_environment_ptr_c2ml(&res.env); \n\ Store_field(_v_a,1,v); \n\ }\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_rename_array_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]ap_var_t* v2, unsigned int v3, unsigned int v4) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.rename_array_with: arrays of different size\");\n\ {\n\ ap_environment_t* oldenv = ap_environment_copy(a->env);\n \ ap_abstract1_t res = ap_abstract1_rename_array(man,true,a,v1,v2,v3);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ if (res.env==oldenv){\n\ ap_environment_free(oldenv);\n\ }\n\ else {\n\ v = camlidl_apron_environment_ptr_c2ml(&res.env); \n\ Store_field(_v_a,1,v); \n\ }\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Expansion and folding of dimensions} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n\ (**\n\ These functions allows to expand one dimension into several ones having the\n\ same properties with respect to the other dimensions, and to fold several\n\ dimensions into one. Formally,\n\ \n\ - expand P(x,y,z) z w = P(x,y,z) inter P(x,y,w) if z is expanded in z and w\n\ - fold Q(x,y,z,w) z w = exists w:Q(x,y,z,w) union (exist z:Q(x,y,z,w))(z<-w)\n\ if z and w are folded onto z\n\ *)\n\n\ ") quote(MLI,"(** \ Expansion: [expand a var tvar] expands the variable [var] into itself and\n \ the additional variables in [tvar], which are given the same type as [var].\n\n\ It results in (n+1) unrelated variables having\n \ same relations with other variables. The additional variables are added to the environment of \n\ the argument for making the environment of the result, so they should\n\ not belong to the initial environement.\n\ *)") struct ap_abstract1_t ap_abstract1_expand(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, ap_var_t v1, [size_is(v3)]ap_var_t* v2, int v3) quote(call,"_res = ap_abstract1_expand(man,false,a,v1,v2,v3);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI," \ (** Folding: [fold a tvar] fold the variables in the array [tvar] of size n>=1\n\ and put the result in the first variable of the array. The other\n\ variables of the array are then removed, both from the environment and the abstract value.\n\ *)") struct ap_abstract1_t ap_abstract1_fold(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v2)]ap_var_t* v1, int v2) quote(call,"_res = ap_abstract1_fold(man,false,a,v1,v2);") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_expand_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, ap_var_t v1, [size_is(v3)]ap_var_t* v2, int v3) quote(call,"{\n\ ap_environment_t* oldenv = ap_environment_copy(a->env);\n \ ap_abstract1_t res = ap_abstract1_expand(man,true,a,v1,v2,v3); value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ if (res.env==oldenv){\n\ ap_environment_free(oldenv);\n\ }\n\ else {\n\ v = camlidl_apron_environment_ptr_c2ml(&res.env); \n\ Store_field(_v_a,1,v); \n\ }\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_fold_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v2)]ap_var_t* v1, int v2) quote(call,"{\n\ ap_environment_t* oldenv = ap_environment_copy(a->env);\n \ ap_abstract1_t res = ap_abstract1_fold(man,true,a,v1,v2); value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ if (res.env==oldenv){\n\ ap_environment_free(oldenv);\n\ }\n\ else {\n\ v = camlidl_apron_environment_ptr_c2ml(&res.env); \n\ Store_field(_v_a,1,v); \n\ }\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Widening} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** Widening *)") struct ap_abstract1_t ap_abstract1_widening(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2) quote(dealloc,"I0_CHECK_EXC(man)"); struct ap_abstract1_t ap_abstract1_widening_threshold(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2, [ref]struct ap_lincons1_array_t* v) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Closure operation} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** Closure: transform strict constraints into non-strict ones.*)") struct ap_abstract1_t ap_abstract1_closure(ap_manager_ptr man,[ref]struct ap_abstract1_t* a) quote(call,"_res = ap_abstract1_closure(man,false,a);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Side-effect version *)") void ap_abstract1_closure_with(ap_manager_ptr man,[ref]struct ap_abstract1_t* a) quote(call,"{\n\ ap_abstract1_t res = ap_abstract1_closure(man,true,a); value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(** {2 Additional operations} *)") quote(MLMLI,"(* ********************************************************************** *)") quote(MLI,"\n\ val of_lincons_array : 'a Manager.t -> Environment.t -> Lincons1.earray -> 'a t\n\ val of_tcons_array : 'a Manager.t -> Environment.t -> Tcons1.earray -> 'a t\n\ (** Abstract a conjunction of constraints *)\n\ \n\ val assign_linexpr : 'a Manager.t -> 'a t -> Var.t -> Linexpr1.t -> 'a t option -> 'a t\n\ val substitute_linexpr : 'a Manager.t -> 'a t -> Var.t -> Linexpr1.t -> 'a t option -> 'a t\n\ val assign_texpr : 'a Manager.t -> 'a t -> Var.t -> Texpr1.t -> 'a t option -> 'a t\n\ val substitute_texpr : 'a Manager.t -> 'a t -> Var.t -> Texpr1.t -> 'a t option -> 'a t\n\ (** Assignement/Substitution of a single dimension by a single expression *)\n\ \n\ val assign_linexpr_with : 'a Manager.t -> 'a t -> Var.t -> Linexpr1.t -> 'a t option -> unit\n\ val substitute_linexpr_with : 'a Manager.t -> 'a t -> Var.t -> Linexpr1.t -> 'a t option -> unit\n\ val assign_texpr_with : 'a Manager.t -> 'a t -> Var.t -> Texpr1.t -> 'a t option -> unit\n\ val substitute_texpr_with : 'a Manager.t -> 'a t -> Var.t -> Texpr1.t -> 'a t option -> unit\n\ (** Side-effect version of the previous functions *)\n\ \n\ ") quote(ML,"\n\ let of_lincons_array man env array =\n\ let res = top man env in\n\ meet_lincons_array_with man res array;\n\ res\n\ let of_tcons_array man env array =\n\ let res = top man env in\n\ meet_tcons_array_with man res array;\n\ res\n\ let assign_linexpr man abs dim expr odest =\n\ assign_linexpr_array man abs [|dim|] [|expr|] odest\n\ let assign_texpr man abs dim expr odest =\n\ assign_texpr_array man abs [|dim|] [|expr|] odest\n\ let substitute_linexpr man abs dim expr odest =\n\ substitute_linexpr_array man abs [|dim|] [|expr|] odest\n\ let substitute_texpr man abs dim expr odest =\n\ substitute_texpr_array man abs [|dim|] [|expr|] odest\n\ let assign_linexpr_with man abs dim expr odest =\n\ assign_linexpr_array_with man abs [|dim|] [|expr|] odest\n\ let assign_texpr_with man abs dim expr odest =\n\ assign_texpr_array_with man abs [|dim|] [|expr|] odest\n\ let substitute_linexpr_with man abs dim expr odest =\n\ substitute_linexpr_array_with man abs [|dim|] [|expr|] odest\n\ let substitute_texpr_with man abs dim expr odest =\n\ substitute_texpr_array_with man abs [|dim|] [|expr|] odest\n\ ") quote(MLI,"(** Unification of 2 abstract values on their least common environment *)") struct ap_abstract1_t ap_abstract1_unify(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2) quote(call,"_res = ap_abstract1_unify(man,false,a1,a2);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Side-effect version *)") void ap_abstract1_unify_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2) quote(call,"\ {\n\ ap_abstract1_t res = ap_abstract1_unify(man,true,a1,a2);\n\ value v = Field(_v_a1,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ v = Field(_v_a1,1);\n\ *((ap_environment_ptr *) Data_custom_val(v)) = res.env;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(ML,"\n\ let print fmt a =\n\ let man = manager a in\n\ if is_bottom man a then\n\ Format.pp_print_string fmt \"bottom\"\n\ else if is_top man a then\n\ Format.pp_print_string fmt \"top\"\n\ else begin\n\ let tab = to_lincons_array man a in\n\ Lincons1.array_print fmt tab;\n\ end\n\ ") apron-dist-0.9.10/apron/octagons/tmp/lincons1.idl0000640014525101416610000002460511252216517021532 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \n\ #include \"ap_lincons1.h\"\n\ #include \"apron_caml.h\"\n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; import "linexpr0.idl"; import "lincons0.idl"; import "environment.idl"; import "linexpr1.idl"; struct ap_lincons1_t { [mlname(mutable_lincons0)] ap_lincons0_t lincons0; [mlname(mutable_env)] ap_environment_ptr env; }; struct ap_lincons1_array_t { [mlname(mutable_lincons0_array)] struct ap_lincons0_array_t lincons0_array; [mlname(mutable_array_env)] ap_environment_ptr env; }; quote(MLMLI,"(** APRON Constraints and array of constraints of level 1 *)") quote(MLMLI,"\n\ type typ = Lincons0.typ =\n\ | EQ\n\ | SUPEQ\n\ | SUP\n\ | DISEQ\n\ | EQMOD of Scalar.t\n\ ") quote(MLI,"\n\ (** Make a linear constraint. Modifying later the linear expression ({e not\n\ advisable}) modifies correspondingly the linear constraint and conversely,\n\ except for changes of environements *)\n\ val make: Linexpr1.t -> typ -> t\n\ \n\ (** Copy (deep copy) *)\n\ val copy: t -> t\n\ \n\ (** Convert a constraint type to a string ([=],[>=], or [>]) *)\n\ val string_of_typ : typ -> string\n\ \n\ (** Print the linear constraint *)\n\ val print : Format.formatter -> t -> unit\n\ \n\ (** Get the constraint type *)\n\ val get_typ: t -> typ\n\ \n\ (** Iter the function on the pair coefficient/variable of the underlying linear\n\ expression *)\n\ val iter: (Coeff.t -> Var.t -> unit) -> t -> unit\n\ \n\ (** Get the constant of the underlying linear expression *)\n\ val get_cst: t -> Coeff.t\n\ \n\ (** Set the constraint type *)\n\ val set_typ: t -> typ -> unit\n\ \n\ (** Set simultaneously a number of coefficients.\n\ \n\ [set_list expr [(c1,\"x\"); (c2,\"y\")] (Some cst)] assigns coefficients [c1] \n\ to variable [\"x\"], coefficient [c2] to variable [\"y\"], and coefficient [cst]\n\ to the constant. If [(Some cst)] is replaced by [None],\n\ the constant coefficient is not assigned. *)\n\ val set_list : t -> (Coeff.t * Var.t) list -> Coeff.t option -> unit\n\ \n\ (** Set simultaneously a number of coefficients, as [set_list]. *)\n\ val set_array : t -> (Coeff.t * Var.t) array -> Coeff.t option -> unit\n\ \n\ (** Set the constant of the underlying linear expression *)\n\ val set_cst: t -> Coeff.t -> unit\n\ ") quote(MLI,"(** Get the coefficient of the variable in the underlying linear expression *)") struct ap_coeff_t ap_lincons1_get_coeff([ref]struct ap_lincons1_t* a, ap_var_t var) quote(call, "\n\ {\n\ bool b;\n\ ap_coeff_init(&_res,AP_COEFF_SCALAR);\n\ b = ap_lincons1_get_coeff(&_res,a,var);\n\ if (b){\n\ char str[160];\n\ char* name;\n\ ap_coeff_clear(&_res);\n\ name = ap_var_operations->to_string(var);\n\ snprintf(str,159,\"Lincons1.get_coeff: unknown variable %s in the environment\",name);\n\ free(name);\n\ caml_failwith(str);\n\ }\n\ }\n\ ") quote(dealloc,"ap_coeff_clear(&_res);"); quote(MLI,"(** Set the coefficient of the variable in the underlying linear expression *)") void ap_lincons1_set_coeff([ref]struct ap_lincons1_t* a, ap_var_t var, [ref]struct ap_coeff_t* coeff) quote(call, "\n\ {\n\ bool b;\n\ b = ap_lincons1_set_coeff(a,var,coeff);\n\ if (b){\n\ char str[160];\n\ char* name;\n\ name = ap_var_operations->to_string(var);\n\ snprintf(str,159,\"Lincons1.set_coeff: unknown variable %s in the environment\",name);\n\ free(name);\n\ caml_failwith(str);\n\ }\n\ }\n\ "); quote(MLI,"(** Build the unsatisfiable constraint -1>=0 *)") struct ap_lincons1_t ap_lincons1_make_unsat(ap_environment_ptr env); quote(MLI,"(** Is the constraint not satisfiable ? *)") boolean ap_lincons1_is_unsat([ref]struct ap_lincons1_t* cons); quote(MLI,"(** Change the environement of the constraint for a super-environement. Raise [Failure] if it is not the case *)") struct ap_lincons1_t ap_lincons1_extend_environment(const struct ap_lincons1_t lincons, ap_environment_ptr env) quote(call,"\n\ {\n\ bool b;\n\ b = ap_lincons1_extend_environment(&_res,&lincons,env);\n\ if (b) caml_failwith(\"Lincons1.extend_environment: new environment is not a superenvironment\");\n\ }") ; quote(MLI,"(** Side-effect version of the previous function *)") void ap_lincons1_extend_environment_with(struct ap_lincons1_t lincons, ap_environment_ptr env) quote(call,"\n\ {\n\ if (lincons.env!=env){ \n\ bool b;\n\ ap_environment_copy(lincons.env); /* to protect it */ \n\ b = ap_lincons1_extend_environment_with(&lincons,env);\n\ if (b){ \n\ ap_environment_free(lincons.env); \n\ caml_failwith(\"Lincons1.extend_environment_with: new environment is not a superenvironment\");\n\ }\n\ Store_field(_v_lincons,1,_v_env);\n\ ap_environment_free(env);\n\ }\n\ }") ; quote(MLI,"\n\ (** Get the environement of the linear constraint *)\n\ val get_env: t -> Environment.t\n\ \n\ (** Get the underlying linear expression. Modifying the linear expression ({e\n\ not advisable}) modifies correspondingly the linear constraint and\n\ conversely, except for changes of environements *)\n\ val get_linexpr1: t -> Linexpr1.t\n\ \n\ (** Get the underlying linear constraint of level 0. Modifying the constraint\n\ of level 0 ({e not advisable}) modifies correspondingly the linear constraint\n\ and conversely, except for changes of environements*)\n\ val get_lincons0: t -> Lincons0.t\n\ \n\ ") quote(ML,"\n\ let make linexpr1 typ = {\n\ lincons0 = {\n\ Lincons0.linexpr0 = linexpr1.Linexpr1.linexpr0;\n\ Lincons0.typ = typ;\n\ };\n\ env = linexpr1.Linexpr1.env;\n\ }\n\ let copy cons = {\n\ lincons0 = Lincons0.copy cons.lincons0;\n\ env = cons.env;\n\ }\n\ let string_of_typ = Lincons0.string_of_typ\n\ \n\ let print fmt cons = \n\ Lincons0.print\n\ (fun dim -> Var.to_string (Environment.var_of_dim cons.env dim)) fmt cons.lincons0;\n \ ()\n\ let get_typ cons = cons.lincons0.Lincons0.typ\n\ let set_typ cons typ = cons.lincons0.Lincons0.typ <- typ\n\ let get_cst cons = Linexpr0.get_cst cons.lincons0.Lincons0.linexpr0\n\ let set_cst cons cst = Linexpr0.set_cst cons.lincons0.Lincons0.linexpr0 cst\n\ let get_lincons0 cons = cons.lincons0\n\ let get_env cons = cons.env\n\ let set_list expr list ocst = \n\ List.iter\n\ (fun (coeff,var) -> set_coeff expr var coeff )\n\ list;\n\ begin match ocst with\n\ | Some cst -> set_cst expr cst\n\ | None -> ()\n\ end;\n\ ()\n\ let set_array expr tab ocst = \n\ Array.iter\n\ (fun (coeff,var) -> set_coeff expr var coeff )\n\ tab;\n\ begin match ocst with\n\ | Some cst -> set_cst expr cst\n\ | None -> ()\n\ end;\n\ ()\n\ \n\ let iter f cons =\n\ Linexpr0.iter\n\ (begin fun coeff dim ->\n\ f coeff (Environment.var_of_dim cons.env dim)\n\ end)\n\ cons.lincons0.Lincons0.linexpr0\n\ let get_linexpr1 cons = {\n\ Linexpr1.linexpr0 = cons.lincons0.Lincons0.linexpr0;\n\ Linexpr1.env = cons.env;\n\ }") quote(MLMLI,"(* ====================================================================== *)") quote(MLMLI,"(** {2 Type array} *)") quote(MLMLI,"(* ====================================================================== *)") quote(MLI,"\n\ (** Make an array of linear constraints with the given size and defined on the\n\ given environement. The elements are initialized with the constraint 0=0. *)\n\ val array_make : Environment.t -> int -> earray\n\ \n\ (** Print an array of constraints *)\n\ val array_print :\n\ ?first:(unit, Format.formatter, unit) format ->\n\ ?sep:(unit, Format.formatter, unit) format ->\n\ ?last:(unit, Format.formatter, unit) format ->\n\ Format.formatter -> earray -> unit\n\ \n\ (** Get the size of the array *)\n\ val array_length : earray -> int\n\ \n\ (** Get the environment of the array *)\n\ val array_get_env : earray -> Environment.t\n\ \n\ (** Get the element of the given index (which is not a copy) *)\n\ val array_get : earray -> int -> t\n\ \n\ (** Set the element of the given index (without any copy). The array and the\n\ constraint should be defined on the same environement; otherwise a [Failure]\n\ exception is raised.*)\n\ val array_set : earray -> int -> t -> unit\n\ ") quote(MLI,"(** Change the environement of the array of constraints for a super-environement. Raise [Failure] if it is not the case*)") struct ap_lincons1_array_t ap_lincons1_array_extend_environment(const struct ap_lincons1_array_t array, ap_environment_ptr env) quote(call,"\n\ {\n\ bool b;\n\ b = ap_lincons1_array_extend_environment(&_res,&array,env);\n\ if (b) caml_failwith(\"Lincons1.array_extend_environment: new environment is not a superenvironment\");\n\ }") ; quote(MLI,"(** Side-effect version of the previous function *)") void ap_lincons1_array_extend_environment_with(struct ap_lincons1_array_t array, ap_environment_ptr env) quote(call,"\n\ {\n\ if (array.env!=env){ \n\ bool b;\n\ ap_environment_copy(array.env); /* to protect it */ \n\ b = ap_lincons1_array_extend_environment_with(&array,env);\n\ if (b){ \n\ ap_environment_free(array.env); \n\ caml_failwith(\"Lincons1.array_extend_environment_with: new environment is not a superenvironment\");\n\ }\n\ Store_field(_v_array,1,_v_env);\n\ ap_environment_free(env);\n\ }\n\ }") ; quote(ML,"\n\ let array_make env size =\n\ let cons = Lincons0.make (Linexpr0.make None) Lincons0.EQ in\n\ {\n\ lincons0_array = Array.make size cons;\n\ array_env = env\n\ }\n\ let array_print\n\ ?(first=(\"[|@[\":(unit,Format.formatter,unit) format))\n\ ?(sep = (\";@ \":(unit,Format.formatter,unit) format))\n\ ?(last = (\"@]|]\":(unit,Format.formatter,unit) format))\n\ fmt array \n\ = \n\ Abstract0.print_array ~first ~sep ~last\n\ (Lincons0.print\n\ (fun dim -> Var.to_string (Environment.var_of_dim array.array_env dim)))\n \ fmt array.lincons0_array;\n\ ()\n\ let array_length array = Array.length (array.lincons0_array)\n\ let array_get_env array = array.array_env\n\ let array_get array index =\n\ let cons0 = array.lincons0_array.(index) in\n\ { lincons0 = cons0; env = array.array_env; }\n\ let array_set array index cons1 =\n\ if not (Environment.equal array.array_env cons1.env) then\n\ failwith \"Lincons1.array_set: environments are not the same\"\n\ else\n\ array.lincons0_array.(index) <- cons1.lincons0;\n\ ") apron-dist-0.9.10/apron/octagons/tmp/oct.ml0000640014525101416610000000546611252216517020435 0ustar bjeannetpopart(* File generated from oct.idl *) type internal_ptr (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. *) type t (** Type of octagons. Octagons are defined by conjunctions of inequalities of the form [+/-x_i +/- x_j >= 0]. Abstract values which are octagons have the type [t Apron.AbstractX.t]. Managers allocated for octagons have the type [t Apron.manager.t]. *) external oct_manager_alloc : unit -> Manager.ap_manager_ptr = "camlidl_oct_oct_manager_alloc" external manager_get_internal : Manager.ap_manager_ptr -> internal_ptr = "camlidl_oct_manager_get_internal" external ap_abstract0_oct_of_generator_array : Manager.ap_manager_ptr -> int -> int -> Generator0.ap_generator0_array_t -> Abstract0.ap_abstract0_ptr = "camlidl_oct_ap_abstract0_oct_of_generator_array" external ap_abstract0_oct_widening_thresholds : Manager.ap_manager_ptr -> Abstract0.ap_abstract0_ptr -> Abstract0.ap_abstract0_ptr -> Scalar.ap_scalar_array_t -> Abstract0.ap_abstract0_ptr = "camlidl_oct_ap_abstract0_oct_widening_thresholds" external ap_abstract0_oct_narrowing : Manager.ap_manager_ptr -> Abstract0.ap_abstract0_ptr -> Abstract0.ap_abstract0_ptr -> Abstract0.ap_abstract0_ptr = "camlidl_oct_ap_abstract0_oct_narrowing" external ap_abstract0_oct_add_epsilon : Manager.ap_manager_ptr -> Abstract0.ap_abstract0_ptr -> Scalar.ap_scalar_ptr -> Abstract0.ap_abstract0_ptr = "camlidl_oct_ap_abstract0_oct_add_epsilon" external ap_abstract0_oct_add_epsilon_bin : Manager.ap_manager_ptr -> Abstract0.ap_abstract0_ptr -> Abstract0.ap_abstract0_ptr -> Scalar.ap_scalar_ptr -> Abstract0.ap_abstract0_ptr = "camlidl_oct_ap_abstract0_oct_add_epsilon_bin" let pre_widening = 99 let manager_is_oct man = let str = Apron.Manager.get_library man in (String.compare str "oct")==0 let manager_of_oct (man:t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_oct (man:'a Apron.Manager.t) : t Apron.Manager.t = if manager_is_oct man then Obj.magic man else failwith "Oct.manager_to_oct: the argument manager is not an Oct manager" module Abstract0 = struct let is_oct abs = manager_is_oct (Apron.Abstract0.manager abs) let of_oct (abs: t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let to_oct (abs:'a Apron.Abstract0.t) : t Apron.Abstract0.t = if is_oct abs then Obj.magic abs else failwith "Oct.Abstract0.to_oct: the argument value is not an oct value" end module Abstract1 = struct let is_oct abs = manager_is_oct (Apron.Abstract1.manager abs) let of_oct (abs: t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let to_oct (abs:'a Apron.Abstract1.t) : t Apron.Abstract1.t = if is_oct abs then Obj.magic abs else failwith "Oct.Abstract1.to_oct: the argument value is not an oct value" end apron-dist-0.9.10/apron/octagons/tmp/linexpr0.idl0000640014525101416610000001547611252216517021553 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(MLI,"(** APRON Linear expressions of level 0 *)\n") quote(C, "\n\ #include \n\ #include \"ap_linexpr0.h\"\n\ #include \"apron_caml.h\"\n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; typedef [abstract, ml2c(camlidl_apron_linexpr0_ptr_ml2c), c2ml(camlidl_apron_linexpr0_ptr_c2ml)] struct ap_linexpr0_ptr* ap_linexpr0_ptr; quote(MLI,"(** Create a linear expression. Its representation is sparse if [None] is provided, dense of size [size] if [Some size] is provided. *)") ap_linexpr0_ptr ap_linexpr0_make([unique]int* size) quote(call,"\n\ if (size && *size<0) caml_failwith(\"Linexpr0.make: negative optional size\");\n\ if (size){\n\ _res = ap_linexpr0_alloc(AP_LINEXPR_DENSE, *size);\n\ } else {\n\ _res = ap_linexpr0_alloc(AP_LINEXPR_SPARSE, 0);\n\ }\n\ "); quote(MLI,"\n\ val of_list : int option -> (Coeff.t * Dim.t) list -> Coeff.t option -> t\n\ (** Combines {!make} and {!set_list} (see below) *)\n\ val of_array : int option -> (Coeff.t * Dim.t) array -> Coeff.t option -> t\n\ (** Combines {!make} and {!set_array} (see below) *)\n\ ") quote(MLI,"(** In case of sparse representation, remove zero coefficients *)") void ap_linexpr0_minimize(ap_linexpr0_ptr a); quote(MLI,"(** Copy *)") ap_linexpr0_ptr ap_linexpr0_copy(const ap_linexpr0_ptr a); quote(MLI,"(** Comparison with lexicographic ordering using Coeff.cmp, terminating by constant *)") int ap_linexpr0_compare(const ap_linexpr0_ptr a, const ap_linexpr0_ptr b); quote(MLI,"(** Hashing function *)") int ap_linexpr0_hash(const ap_linexpr0_ptr a); quote(MLI,"(** Get the size of the linear expression (which may be sparse or dense) *)") int ap_linexpr0_get_size(ap_linexpr0_ptr a) quote(call,"_res = a->size;"); quote(MLI,"(** Get the constant *)") [ref]struct ap_coeff_t* ap_linexpr0_get_cst(ap_linexpr0_ptr a) quote(call,"_res = &a->cst;"); quote(MLI,"(** Get the coefficient corresponding to the dimension *)") struct ap_coeff_t ap_linexpr0_get_coeff(ap_linexpr0_ptr a, int dim) quote(call, "\n\ {\n\ bool b;\n\ ap_coeff_init(&_res,AP_COEFF_SCALAR);\n\ if (dim<0) goto ap_linexpr0_get_coeff_exit;\n\ b = ap_linexpr0_get_coeff(&_res,a,(ap_dim_t)dim);\n \ if (b){\n\ ap_linexpr0_get_coeff_exit:\n\ ap_coeff_clear(&_res);\n\ caml_failwith(\"Linexpr0.get_coeff: out of bound dimension\");\n\ }\n\ }") quote(dealloc,"ap_coeff_clear(&_res);"); quote(MLI,"\n\ val set_list : t -> (Coeff.t * Dim.t) list -> Coeff.t option -> unit\n\ (** Set simultaneously a number of coefficients.\n\ \n\ [set_list expr [(c1,1); (c2,2)] (Some cst)] assigns coefficients [c1] \n\ to dimension 1, coefficient [c2] to dimension 2, and coefficient [cst]\n\ to the constant. If [(Some cst)] is replaced by [None],\n\ the constant coefficient is not assigned. *)\n\ val set_array : t -> (Coeff.t * Dim.t) array -> Coeff.t option -> unit\n\ (** Set simultaneously a number of coefficients, as [set_list]. *)\n") quote(MLI,"(** Set the constant *)") void ap_linexpr0_set_cst(ap_linexpr0_ptr a, [ref]struct ap_coeff_t* coeff) quote(call,"ap_linexpr0_set_cst(a,coeff);"); quote(MLI,"(** Set the coefficient corresponding to the dimension *)") void ap_linexpr0_set_coeff(ap_linexpr0_ptr a, int dim, [ref]struct ap_coeff_t* coeff) quote(call, "\n\ {\n\ bool b;\n\ if (dim<0) goto ap_linexpr0_set_coeff_exit;\n\ b = ap_linexpr0_set_coeff(a,(ap_dim_t)dim,coeff);\n \ if (b){\n\ ap_linexpr0_set_coeff_exit:\n\ caml_failwith(\"Linexpr0.set_coeff: out of bound dimension\");\n\ }\n\ }\n\ "); quote(MLI,"(** Iter the function on the pairs coefficient/dimension of the linear expression *)") quote(MLMLI,"\n\ external ap_linexpr0_iter: (Coeff.t -> Dim.t -> unit) -> ap_linexpr0_ptr -> unit = \"camlidl_expr0_linexpr0_iter\"\n \ ") quote(C,"\n\ value camlidl_expr0_linexpr0_iter(value _v_closure, value _v_linexpr0)\n\ {\n\ CAMLparam2(_v_closure,_v_linexpr0);\n\ CAMLlocal2(_v_dim,_v_coeff);\n\ size_t i;\n\ ap_dim_t dim;\n\ ap_coeff_t* pcoeff;\n\ ap_linexpr0_t* linexpr0;\n\ \n\ camlidl_apron_linexpr0_ptr_ml2c(_v_linexpr0,&linexpr0);\n\ ap_linexpr0_ForeachLinterm(linexpr0,i,dim,pcoeff){\n\ _v_dim = Val_int(dim);\n\ _v_coeff = camlidl_c2ml_coeff_struct_ap_coeff_t(pcoeff,NULL);\n \ callback2(_v_closure,_v_coeff,_v_dim);\n\ }\n\ CAMLreturn(Val_unit);\n\ }\n\ ") quote(MLI,"\n\ (** Print a linear expression, using a function converting from dimensions to names *)\n\ val print : (Dim.t -> string) -> Format.formatter -> ap_linexpr0_ptr -> unit\n\ ") quote(ML,"\n\ let set_list expr list ocst = \n\ List.iter\n\ (fun (coeff,dim) -> set_coeff expr dim coeff )\n\ list;\n\ begin match ocst with\n\ | Some cst -> set_cst expr cst\n\ | None -> ()\n\ end;\n\ ()\n\ let set_array expr tab ocst = \n\ Array.iter\n\ (fun (coeff,dim) -> set_coeff expr dim coeff )\n\ tab;\n\ begin match ocst with\n\ | Some cst -> set_cst expr cst\n\ | None -> ()\n\ end;\n\ ()\n\ \n\ let of_list osize list ocst =\n\ let expr = make osize in\n\ set_list expr list ocst;\n\ expr\n\ let of_array osize tab ocst =\n\ let expr = make osize in\n\ set_array expr tab ocst;\n\ expr\n\ \n\ let print assoc fmt expr = \n\ Format.fprintf fmt \"@[\";\n\ let first = ref true in\n\ iter\n\ (begin fun coeff dim ->\n\ let coeff = Coeff.reduce coeff in\n\ let sgn = match coeff with\n\ | Coeff.Scalar x -> Scalar.sgn x\n\ | Coeff.Interval i ->\n\ if Interval.is_zero i then 0 else 1\n\ in\n\ if sgn <> 0 then begin\n\ if not !first then Format.fprintf fmt \"@,\";\n\ if sgn>0 then begin\n\ if not !first then Format.pp_print_string fmt \"+\";\n\ end;\n\ begin match coeff with\n\ | Coeff.Scalar scalar ->\n\ if Scalar.equal_int scalar (-1) then\n\ Format.pp_print_string fmt \"-\"\n\ else if not (Scalar.equal_int scalar 1) then\n\ Scalar.print fmt scalar;\n\ | Coeff.Interval i ->\n\ Interval.print fmt i\n\ end;\n\ Format.pp_print_string fmt (assoc dim);\n\ first := false;\n\ end;\n\ end)\n\ expr;\n\ begin match get_cst expr with\n\ | Coeff.Scalar scalar ->\n\ let sgn = Scalar.sgn scalar in\n\ if sgn <> 0 then begin\n\ if not !first then Format.fprintf fmt \"@,\";\n\ if sgn>0 && not !first then Format.pp_print_char fmt '+';\n\ Scalar.print fmt scalar;\n\ end\n\ else if !first then\n\ Format.pp_print_char fmt '0';\n\ | Coeff.Interval i ->\n\ if not (Interval.is_zero i) then begin\n\ if not !first then Format.pp_print_char fmt '+';\n\ Interval.print fmt i\n\ end\n\ else if !first then\n\ Format.pp_print_char fmt '0';\n\ end;\n\ Format.fprintf fmt \"@]\";\n\ ()\n\ ") apron-dist-0.9.10/apron/octagons/tmp/var.idl0000640014525101416610000000212011252216517020560 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, " #include \"apron_caml.h\" ") typedef [abstract, ml2c(camlidl_apron_var_ptr_ml2c), c2ml(camlidl_apron_var_ptr_c2ml)] struct apron_var_ptr ap_var_t; quote(MLMLI,"(** APRON Variables *)\n") quote(MLI,"(** Constructor *)") ap_var_t ap_var_of_string([string]char* name); quote(MLI,"(** Comparison function *)") int ap_var_compare(ap_var_t var1, ap_var_t var2); quote(MLI,"(** Conversion to string *)") [string]char* ap_var_to_string(ap_var_t var) quote(call,"_res = ((apron_var_ptr)var)->name;"); quote(MLI,"(** Hash function *)") int ap_var_hash(ap_var_t var); quote(MLI," (** Printing function *) val print : Format.formatter -> t -> unit ") quote(ML," let print fmt v = Format.pp_print_string fmt (to_string v) ") quote(MLMLI," (** Initialisation of abstract type operations in C library *) external set_var_operations : unit -> unit = \"camlidl_apron_set_var_operations\""); quote(ML," let _ = set_var_operations () ") apron-dist-0.9.10/apron/octagons/tmp/tcons1.idl0000640014525101416610000001643511252216517021215 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \n\ #include \"ap_tcons1.h\"\n\ #include \"apron_caml.h\"\n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; import "texpr0.idl"; import "tcons0.idl"; import "environment.idl"; import "texpr1.idl"; struct ap_tcons1_t { [mlname(mutable_tcons0)] ap_tcons0_t tcons0; [mlname(mutable_env)] ap_environment_ptr env; }; struct ap_tcons1_array_t { [mlname(mutable_tcons0_array)] struct ap_tcons0_array_t tcons0_array; [mlname(mutable_array_env)] ap_environment_ptr env; }; quote(MLMLI,"(** APRON tree constraints and array of tree constraints of level 1 *)") quote(MLMLI,"\n\ type typ = Lincons0.typ =\n\ | EQ\n\ | SUPEQ\n\ | SUP\n\ | DISEQ\n\ | EQMOD of Scalar.t\n\ ") quote(MLI,"\n\ (** Make a tree expression constraint. Modifying later the linear expression ({e not\n\ advisable}) modifies correspondingly the tree expression constraint and conversely,\n\ except for changes of environements *)\n\ val make: Texpr1.t -> typ -> t\n\ \n\ (** Copy (deep copy) *)\n\ val copy: t -> t\n\ \n\ (** Convert a constraint type to a string ([=],[>=], or [>]) *)\n\ val string_of_typ : typ -> string\n\ \n\ (** Print the tree expression constraint *)\n\ val print : Format.formatter -> t -> unit\n\ \n\ (** Get the constraint type *)\n\ val get_typ: t -> typ\n\ \n\ (** Set the constraint type *)\n\ val set_typ: t -> typ -> unit\n\ \n\ ") quote(MLI,"(** Change the environement of the constraint for a super-environement. Raise [Failure] if it is not the case *)") struct ap_tcons1_t ap_tcons1_extend_environment(const struct ap_tcons1_t tcons, ap_environment_ptr env) quote(call,"\n\ {\n\ bool b;\n\ b = ap_tcons1_extend_environment(&_res,&tcons,env);\n\ if (b) caml_failwith(\"Tcons1.extend_environment: new environment is not a superenvironment\");\n\ }") ; quote(MLI,"(** Side-effect version of the previous function *)") void ap_tcons1_extend_environment_with(struct ap_tcons1_t tcons, ap_environment_ptr env) quote(call,"\n\ {\n\ if (tcons.env!=env){ \n\ bool b;\n\ ap_environment_copy(tcons.env); /* to protect it */ \n\ b = ap_tcons1_extend_environment_with(&tcons,env);\n\ if (b){ \n\ ap_environment_free(tcons.env); \n\ caml_failwith(\"Tcons1.extend_environment_with: new environment is not a superenvironment\");\n\ }\n\ Store_field(_v_tcons,1,_v_env);\n\ ap_environment_free(env);\n\ }\n\ }") ; quote(MLI,"\n\ (** Get the environement of the tree expression constraint *)\n\ val get_env: t -> Environment.t\n\ \n\ (** Get the underlying linear expression. Modifying the linear expression ({e\n\ not advisable}) modifies correspondingly the tree expression constraint and\n\ conversely, except for changes of environements *)\n\ val get_texpr1: t -> Texpr1.t\n\ \n\ (** Get the underlying tree expression constraint of level 0. Modifying the constraint\n\ of level 0 ({e not advisable}) modifies correspondingly the tree expression constraint\n\ and conversely, except for changes of environements*)\n\ val get_tcons0: t -> Tcons0.t\n\ \n\ ") quote(ML,"\n\ let make texpr1 typ = {\n\ tcons0 = {\n\ Tcons0.texpr0 = texpr1.Texpr1.texpr0;\n\ Tcons0.typ = typ;\n\ };\n\ env = texpr1.Texpr1.env;\n\ }\n\ let copy cons = {\n\ tcons0 = Tcons0.copy cons.tcons0;\n\ env = cons.env;\n\ }\n\ let string_of_typ = Tcons0.string_of_typ\n\ \n\ let print fmt cons = \n\ Tcons0.print\n\ (fun dim -> Var.to_string (Environment.var_of_dim cons.env dim)) fmt cons.tcons0;\n \ ()\n\ let get_typ cons = cons.tcons0.Tcons0.typ\n\ let set_typ cons typ = cons.tcons0.Tcons0.typ <- typ\n\ let get_tcons0 cons = cons.tcons0\n\ let get_env cons = cons.env\n\ let get_texpr1 cons = {\n\ Texpr1.texpr0 = cons.tcons0.Tcons0.texpr0;\n\ Texpr1.env = cons.env;\n\ }") quote(MLMLI,"(* ====================================================================== *)") quote(MLMLI,"(** {2 Type array} *)") quote(MLMLI,"(* ====================================================================== *)") quote(MLI,"\n\ (** Make an array of tree expression constraints with the given size and defined on the\n\ given environement. The elements are initialized with the constraint 0=0. *)\n\ val array_make : Environment.t -> int -> earray\n\ \n\ (** Print an array of constraints *)\n\ val array_print :\n\ ?first:(unit, Format.formatter, unit) format ->\n\ ?sep:(unit, Format.formatter, unit) format ->\n\ ?last:(unit, Format.formatter, unit) format ->\n\ Format.formatter -> earray -> unit\n\ \n\ (** Get the size of the array *)\n\ val array_length : earray -> int\n\ \n\ (** Get the environment of the array *)\n\ val array_get_env : earray -> Environment.t\n\ \n\ (** Get the element of the given index (which is not a copy) *)\n\ val array_get : earray -> int -> t\n\ \n\ (** Set the element of the given index (without any copy). The array and the\n\ constraint should be defined on the same environement; otherwise a [Failure]\n\ exception is raised.*)\n\ val array_set : earray -> int -> t -> unit\n\ ") quote(MLI,"(** Change the environement of the array of constraints for a super-environement. Raise [Failure] if it is not the case*)") struct ap_tcons1_array_t ap_tcons1_array_extend_environment(const struct ap_tcons1_array_t array, ap_environment_ptr env) quote(call,"\n\ {\n\ bool b;\n\ b = ap_tcons1_array_extend_environment(&_res,&array,env);\n\ if (b) caml_failwith(\"Tcons1.array_extend_environment: new environment is not a superenvironment\");\n\ }") ; quote(MLI,"(** Side-effect version of the previous function *)") void ap_tcons1_array_extend_environment_with(struct ap_tcons1_array_t array, ap_environment_ptr env) quote(call,"\n\ {\n\ if (array.env!=env){ \n\ bool b;\n\ ap_environment_copy(array.env); /* to protect it */ \n\ b = ap_tcons1_array_extend_environment_with(&array,env);\n\ if (b){ \n\ ap_environment_free(array.env); \n\ caml_failwith(\"Tcons1.array_extend_environment_with: new environment is not a superenvironment\");\n\ }\n\ Store_field(_v_array,1,_v_env);\n\ ap_environment_free(env);\n\ }\n\ }") ; quote(ML,"\n\ let array_make env size =\n\ let cons = Tcons0.make (Texpr0.cst (Coeff.s_of_int 0)) Tcons0.EQ in\n \ {\n\ tcons0_array = Array.make size cons;\n\ array_env = env\n\ }\n\ let array_print\n\ ?(first=(\"[|@[\":(unit,Format.formatter,unit) format))\n\ ?(sep = (\";@ \":(unit,Format.formatter,unit) format))\n\ ?(last = (\"@]|]\":(unit,Format.formatter,unit) format))\n\ fmt array \n\ = \n\ Abstract0.print_array ~first ~sep ~last\n\ (Tcons0.print\n\ (fun dim -> Var.to_string (Environment.var_of_dim array.array_env dim)))\n \ fmt array.tcons0_array;\n\ ()\n\ let array_length array = Array.length (array.tcons0_array)\n\ let array_get_env array = array.array_env\n\ let array_get array index =\n\ let cons0 = array.tcons0_array.(index) in\n\ { tcons0 = cons0; env = array.array_env; }\n\ let array_set array index cons1 =\n\ if not (Environment.equal array.array_env cons1.env) then\n\ failwith \"Tcons1.array_set: environments are not the same\"\n\ else\n\ array.tcons0_array.(index) <- cons1.tcons0;\n\ ") apron-dist-0.9.10/apron/octagons/tmp/tcons0.idl0000640014525101416610000000757211252216517021216 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(MLI,"(** APRON tree expressions constraints of level 0 *)") quote(C, "\n\ #include \n\ #include \"ap_lincons0.h\"\n\ #include \"ap_texpr0.h\"\n\ #include \"apron_caml.h\"\n\ \n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; import "lincons0.idl"; import "texpr0.idl"; /* For ap_tcons0_t, - the conversion from ML to C may use allocation, but it is automatically freed by Camlidl mechanisms - the conversion from C to ML free after conversion the scalar field in the C structure. the C type should NOT be deallocated */ quote(C,"\n\ void camlidl_apron_tcons0_ml2c(value v,ap_tcons0_t* cons, camlidl_ctx _ctx)\n\ {\n\ value _v_texpr0;\n\ value _v_constyp;\n\ value _v_scalar;\n\ \n\ _v_texpr0 = Field(v,0);\n\ camlidl_apron_texpr0_ptr_ml2c(_v_texpr0,&cons->texpr0);\n\ _v_constyp = Field(v,1);\n\ if (Is_long(_v_constyp)){\n\ switch (Int_val(_v_constyp)){ case 0:\n\ case 1:\n\ case 2:\n\ cons->constyp = Int_val(_v_constyp);\n\ break;\n\ case 3:\n\ cons->constyp = 4;\n\ break;\n\ default:\n\ abort();\n\ }\n\ cons->scalar = NULL;\n\ }\n\ else {\n\ switch (Tag_val(_v_constyp)){\n\ case 0:\n\ cons->constyp = AP_CONS_EQMOD;\n\ _v_scalar = Field(_v_constyp,0);\n\ cons->scalar = (ap_scalar_t *)camlidl_malloc(sizeof(ap_scalar_t),_ctx);\n\ camlidl_apron_scalar_ml2c(_v_scalar,cons->scalar);\n\ break;\n\ default:\n\ abort();\n\ }\n\ }\n\ }\n\ value camlidl_apron_tcons0_c2ml(ap_tcons0_t* cons)\n\ {\n\ value vres;\n\ value _v[3];\n\ _v[0] = _v[1] = _v[2] = 0;\n\ \n\ Begin_roots_block(_v, 3)\n\ _v[0] = camlidl_apron_texpr0_ptr_c2ml(&cons->texpr0);\n\ switch(cons->constyp){\n\ case AP_CONS_EQ:\n\ case AP_CONS_SUPEQ:\n\ case AP_CONS_SUP:\n\ _v[1] = Val_int(cons->constyp);\n\ break;\n\ case AP_CONS_DISEQ:\n\ _v[1] = Val_int(3);\n\ break;\n\ case AP_CONS_EQMOD:\n\ assert(cons->scalar!=NULL);\n\ _v[2] = camlidl_apron_scalar_c2ml(cons->scalar);\n\ _v[1] = camlidl_alloc_small(1, 0);\n\ Field(_v[1],0) = _v[2];\n\ ap_scalar_free(cons->scalar); cons->scalar = NULL;\n\ break;\n\ }\n\ vres = camlidl_alloc_small(2, 0);\n\ Field(vres, 0) = _v[0];\n\ Field(vres, 1) = _v[1];\n\ End_roots()\n\ return vres;\n\ }\n\ ") typedef [mltype("{\n mutable texpr0 : Texpr0.t;\n mutable typ : Lincons0.typ;\n}"), abstract, ml2c(camlidl_apron_tcons0_ml2c), c2ml(camlidl_apron_tcons0_c2ml)] struct ap_tcons0_t ap_tcons0_t; quote(MLMLI,"\n\ type typ = Lincons0.typ =\n\ | EQ\n\ | SUPEQ\n\ | SUP\n\ | DISEQ\n\ | EQMOD of Scalar.t\n\ ") struct ap_tcons0_array_t { [size_is(size)] ap_tcons0_t* p; int size; }; quote(MLI,"\n\ (** Make a tree expression constraint. Modifying later the tree expression expression\n\ modifies correspondingly the tree expression constraint and conversely *)\n\ val make : Texpr0.t -> typ -> t\n\ \n\ (** Copy a tree expression constraint (deep copy) *)\n\ val copy : t -> t\n\ \n\ (** Convert a constraint type to a string ([=],[>=], or [>]) *)\n\ val string_of_typ : typ -> string\n\ \n\ (** Print a constraint *)\n\ val print : (Dim.t -> string) -> Format.formatter -> t -> unit\n\ ") quote(ML,"\n\ let string_of_typ = Lincons0.string_of_typ\n\ \n\ let print assoc fmt cons = \n\ Texpr0.print assoc fmt cons.texpr0;\n\ Format.fprintf fmt \" %s 0\" (string_of_typ cons.typ);\n\ begin match cons.typ with\n\ | EQMOD x -> Format.fprintf fmt \" mod %a\" Scalar.print x;\n\ | _ -> ()\n\ end;\n\ ()\n\ let make expr typ = {\n\ texpr0 = expr; typ = typ \n\ }\n\ let copy cons = {\n\ texpr0 = Texpr0.copy cons.texpr0; typ = cons.typ\n\ }\n\ ") apron-dist-0.9.10/apron/octagons/tmp/mpz.idl0000750014525101416610000003631211252216517020612 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \"limits.h\"\n\ #include \"caml/custom.h\"\n\ #include \"gmp_caml.h\"\n\ ") typedef [abstract,c2ml(camlidl_mpz_ptr_c2ml),ml2c(camlidl_mpz_ptr_ml2c)] struct __mpz_struct* mpz_ptr; quote(MLMLI,"(** GMP multi-precision integers *)\n\n") quote(MLMLI,"(** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x].\n\n These functions are as efficient as their C counterpart: they do not imply additional memory allocation, unlike the corresponding functions in the module {!Mpzf}. *)\n\n") /* OUTOUTOUT is a reserved variable name ! (see Makefile and sedscript_c) */ quote(MLI,"\n(** {2 Pretty printing} *)\n") quote(MLI,"val print : Format.formatter -> t -> unit") quote(MLMLI,"\n(** {2 Initialization Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Initializing-Integers.html#Initializing-Integers}C documentation} *)\n") void mpz_init([out] mpz_ptr OUTOUTOUT); void mpz_init2([out] mpz_ptr OUTOUTOUT, unsigned long N); void mpz_realloc2 (mpz_ptr ROP, unsigned long N); quote(MLMLI,"\n(** {2 Assignement Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Assigning-Integers.html#Assigning-Integers}C documentation} *)\n") quote(MLMLI,"\n(** The first parameter holds the result. *)\n") void mpz_set(mpz_ptr ROP, mpz_ptr OP); void mpz_set_si(mpz_ptr ROP, long int OP); void mpz_set_d (mpz_ptr ROP, double OP); quote(MLI,"\n(** For [set_q: t -> Mpq.t -> unit], see {!Mpq.get_z} *)\n\n") /* void mpz_set_q (mpz_ptr ROP, mpq_t OP); */ void mpz__set_str (mpz_ptr ROP, [string]char* STR, int BASE) quote(call,"{\n\ int n = mpz_set_str(ROP,STR,BASE);\n\ if (n){ mpz_clear(ROP); caml_invalid_argument(\"\"); }\n\ }"); quote(MLI,"val set_str : t -> string -> base:int -> unit") quote(ML,"let set_str a b ~base = _set_str a b base") void mpz_swap (mpz_ptr ROP1, mpz_ptr ROP2); quote(MLMLI,"\n(** {2 Combined Initialization and Assignment Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Simultaneous-Integer-Init-_0026-Assign.html#Simultaneous-Integer-Init-_0026-Assign}C documentation} *)\n") void mpz_init_set ([out]mpz_ptr OUTOUTOUT, mpz_ptr OP); void mpz_init_set_si ([out]mpz_ptr OUTOUTOUT, signed long int OP); void mpz_init_set_d ([out]mpz_ptr OUTOUTOUT, double OP); void mpz__init_set_str([out]mpz_ptr OUTOUTOUT, [string]char *STR, int BASE) quote(call,"\ {\n\ int n = mpz_init_set_str(OUTOUTOUT,STR,BASE);\n\ if (n){ mpz_clear(OUTOUTOUT); caml_invalid_argument(\"\"); }\n\ }"); quote(MLI,"val init_set_str : string -> base:int -> t") quote(ML,"let init_set_str a ~base = _init_set_str a base") quote(MLMLI,"\n(** {2 Conversion Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Converting-Integers.html#Converting-Integers}C documentation} *)\n") [nativeint]signed long int mpz_get_si (mpz_ptr OP); signed long int mpz_get_int (mpz_ptr OP) quote(call,"_res = mpz_get_si(OP);"); double mpz_get_d (mpz_ptr OP); double mpz_get_d_2exp ([out]signed long int *EXP, mpz_ptr OP); [string]char* mpz__get_str (int BASE, mpz_ptr OP) quote(call,"_res = mpz_get_str(NULL,BASE,OP);") quote(dealloc,"free(_res);"); quote(MLI,"val get_str : base:int -> t -> string") quote(ML,"let get_str ~base a = _get_str base a") quote(MLMLI,"\n\n(** {2 User Conversions} *)\n") quote(MLMLI,"(** These functions are additions to or renaming of functions offered by the C library. *)\n") quote(MLI,"val to_string : t -> string") quote(MLI,"val to_float : t -> float") quote(ML,"let to_string x = get_str 10 x") quote(ML,"let to_float = get_d") quote(MLI,"val of_string : string -> t") quote(MLI,"val of_float : float -> t") quote(MLI,"val of_int : int -> t") quote(ML,"let of_string str = init_set_str str 10") quote(ML,"let of_float = init_set_d") quote(ML,"let of_int = init_set_si") quote(ML,"\n(** {2 Pretty printing} *)\n") quote(ML,"let print fmt x = Format.pp_print_string fmt (get_str 10 x)") quote(MLMLI,"\n(** {2 Arithmetic Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Arithmetic.html#Integer-Arithmetic}C documentation} *)\n") quote(MLMLI,"(** The first parameter holds the result. *)\n") void mpz_add (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_add_ui (mpz_ptr ROP, mpz_ptr OP1, unsigned long int OP2); void mpz_sub (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_sub_ui (mpz_ptr ROP, mpz_ptr OP1, unsigned long int OP2); void mpz_ui_sub (mpz_ptr ROP, unsigned long int OP1, mpz_ptr OP2); void mpz_mul (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_mul_si (mpz_ptr ROP, mpz_ptr OP1, long int OP2); void mpz_addmul (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_addmul_ui (mpz_ptr ROP, mpz_ptr OP1, unsigned long int OP2); void mpz_submul (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_submul_ui (mpz_ptr ROP, mpz_ptr OP1, unsigned long int OP2); void mpz_mul_2exp (mpz_ptr ROP, mpz_ptr OP1, unsigned long int OP2); void mpz_neg (mpz_ptr ROP, mpz_ptr OP); void mpz_abs (mpz_ptr ROP, mpz_ptr OP); quote(MLMLI,"\n(** {2 Division Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Division.html#Integer-Division}C documentation} *)\n") quote(MLMLI,"(** [c] stands for ceiling, [f] for floor, and [t] for truncate (rounds toward 0).*)") quote(MLMLI,"(** {3 Ceiling division} *)\n") quote(MLMLI,"(** The first parameter holds the quotient. *)") void mpz_cdiv_q (mpz_ptr Q, mpz_ptr N, mpz_ptr D); quote(MLMLI,"(** The first parameter holds the remainder. *)") void mpz_cdiv_r (mpz_ptr R, mpz_ptr N, mpz_ptr D); quote(MLMLI,"(** The two first parameters hold resp. the quotient and the remainder). *)") void mpz_cdiv_qr (mpz_ptr Q, mpz_ptr R, mpz_ptr N, mpz_ptr D); quote(MLMLI,"(** The first parameter holds the quotient. *)") unsigned long int mpz_cdiv_q_ui (mpz_ptr Q, mpz_ptr N, unsigned long int D); quote(MLMLI,"(** The first parameter holds the remainder. *)") unsigned long int mpz_cdiv_r_ui (mpz_ptr R, mpz_ptr N, unsigned long int D); quote(MLMLI,"(** The two first parameters hold resp. the quotient and the remainder). *)") unsigned long int mpz_cdiv_qr_ui (mpz_ptr Q, mpz_ptr R, mpz_ptr N, unsigned long int D); unsigned long int mpz_cdiv_ui (mpz_ptr N, unsigned long int D); quote(MLMLI,"(** The first parameter holds the quotient. *)") void mpz_cdiv_q_2exp (mpz_ptr Q, mpz_ptr N, unsigned long int B); quote(MLMLI,"(** The first parameter holds the remainder. *)") void mpz_cdiv_r_2exp (mpz_ptr R, mpz_ptr N, unsigned long int B); quote(MLMLI,"(** {3 Floor division} *)\n") void mpz_fdiv_q (mpz_ptr Q, mpz_ptr N, mpz_ptr D); void mpz_fdiv_r (mpz_ptr R, mpz_ptr N, mpz_ptr D); void mpz_fdiv_qr (mpz_ptr Q, mpz_ptr R, mpz_ptr N, mpz_ptr D); unsigned long int mpz_fdiv_q_ui (mpz_ptr Q, mpz_ptr N, unsigned long int D); unsigned long int mpz_fdiv_r_ui (mpz_ptr R, mpz_ptr N, unsigned long int D); unsigned long int mpz_fdiv_qr_ui (mpz_ptr Q, mpz_ptr R, mpz_ptr N, unsigned long int D); unsigned long int mpz_fdiv_ui (mpz_ptr N, unsigned long int D); void mpz_fdiv_q_2exp (mpz_ptr Q, mpz_ptr N, unsigned long int B); void mpz_fdiv_r_2exp (mpz_ptr R, mpz_ptr N, unsigned long int B); quote(MLMLI,"(** {3 Truncate division} *)\n") void mpz_tdiv_q (mpz_ptr Q, mpz_ptr N, mpz_ptr D); void mpz_tdiv_r (mpz_ptr R, mpz_ptr N, mpz_ptr D); void mpz_tdiv_qr (mpz_ptr Q, mpz_ptr R, mpz_ptr N, mpz_ptr D); unsigned long int mpz_tdiv_q_ui (mpz_ptr Q, mpz_ptr N, unsigned long int D); unsigned long int mpz_tdiv_r_ui (mpz_ptr R, mpz_ptr N, unsigned long int D); unsigned long int mpz_tdiv_qr_ui (mpz_ptr Q, mpz_ptr R, mpz_ptr N, unsigned long int D); unsigned long int mpz_tdiv_ui (mpz_ptr N, unsigned long int D); void mpz_tdiv_q_2exp (mpz_ptr Q, mpz_ptr N, unsigned long int B); void mpz_tdiv_r_2exp (mpz_ptr R, mpz_ptr N, unsigned long int B); quote(MLMLI,"(** {3 Other division-related functions} *)\n") void mpz_gmod (mpz_ptr R, mpz_ptr N, mpz_ptr D) quote(call,"mpz_mod(R,N,D);"); unsigned long int mpz_gmod_ui (mpz_ptr R, mpz_ptr N, unsigned long int D) quote(call,"_res = mpz_mod_ui(R,N,D);"); void mpz_divexact (mpz_ptr Q, mpz_ptr N, mpz_ptr D); void mpz_divexact_ui (mpz_ptr Q, mpz_ptr N, unsigned long D); boolean mpz_divisible_p (mpz_ptr N, mpz_ptr D); boolean mpz_divisible_ui_p (mpz_ptr N, unsigned long int D); boolean mpz_divisible_2exp_p (mpz_ptr N, unsigned long int B); boolean mpz_congruent_p (mpz_ptr N, mpz_ptr C, mpz_ptr D); boolean mpz_congruent_ui_p (mpz_ptr N, unsigned long int C, unsigned long int D); boolean mpz_congruent_2exp_p (mpz_ptr N, mpz_ptr C, unsigned long int B); quote(MLMLI,"\n(** {2 Exponentiation Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Exponentiation.html#Integer-Exponentiation}C documentation} *)\n") void mpz__powm (mpz_ptr ROP, mpz_ptr BASE, mpz_ptr EXP, mpz_ptr MOD) quote(call,"mpz_powm(ROP,BASE,EXP,MOD);"); void mpz__powm_ui (mpz_ptr ROP, mpz_ptr BASE, unsigned long int EXP, mpz_ptr MOD) quote(call,"mpz_powm_ui(ROP,BASE,EXP,MOD);"); quote(MLI,"\ val powm : t -> t -> t -> modulo:t -> unit\n\ val powm_ui : t -> t -> int -> modulo:t -> unit\n\ ") quote(ML,"\ let powm a b c ~modulo = _powm a b c modulo\n\ let powm_ui a b c ~modulo = _powm_ui a b c modulo\n\ ") void mpz_pow_ui (mpz_ptr ROP, mpz_ptr BASE, unsigned long int EXP); void mpz_ui_pow_ui (mpz_ptr ROP, unsigned long int BASE,unsigned long int EXP); quote(MLMLI,"\n(** {2 Root Extraction Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Roots.html#Integer-Roots}C documentation} *)\n") boolean mpz_root (mpz_ptr ROP, mpz_ptr OP, unsigned long int N); void mpz_sqrt (mpz_ptr ROP, mpz_ptr OP); void mpz__sqrtrem (mpz_ptr ROP1, mpz_ptr ROP2, mpz_ptr OP) quote(call,"mpz_sqrtrem(ROP1,ROP2,OP);"); quote(MLI,"val sqrtrem : t -> remainder:t -> t -> unit") quote(ML,"let sqrtrem a ~remainder b = _sqrtrem a remainder b") boolean mpz_perfect_power_p (mpz_ptr OP); boolean mpz_perfect_square_p (mpz_ptr OP); quote(MLMLI,"\n(** {2 Number Theoretic Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Number-Theoretic-Functions.html#Number-Theoretic-Functions}C documentation} *)\n") int mpz_probab_prime_p (mpz_ptr N, int REPS); void mpz_nextprime (mpz_ptr ROP, mpz_ptr OP); void mpz_gcd (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); unsigned long int mpz_gcd_ui ([unique]mpz_ptr* ROP, mpz_ptr OP1, unsigned long int OP2) quote(call,"_res = mpz_gcd_ui(ROP ? *ROP : NULL,OP1,OP2);"); void mpz__gcdext (mpz_ptr G, mpz_ptr S, mpz_ptr T, mpz_ptr A, mpz_ptr B) quote(call,"mpz_gcdext(G,S,T,A,B);"); quote(MLI,"val gcdext : gcd:t -> alpha:t -> beta:t -> t -> t -> unit") quote(ML,"let gcdext ~gcd ~alpha ~beta a b = _gcdext gcd alpha beta a b") void mpz_lcm (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_lcm_ui (mpz_ptr ROP, mpz_ptr OP1, unsigned long OP2); boolean mpz_invert (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); int mpz_jacobi (mpz_ptr A, mpz_ptr B); int mpz_legendre (mpz_ptr A, mpz_ptr P); int mpz_kronecker (mpz_ptr A, mpz_ptr B); int mpz_kronecker_si (mpz_ptr A, long B); int mpz_si_kronecker (long A, mpz_ptr B); unsigned long int mpz_remove (mpz_ptr ROP, mpz_ptr OP, mpz_ptr F); void mpz_fac_ui (mpz_ptr ROP, unsigned long int OP); void mpz_bin_ui (mpz_ptr ROP, mpz_ptr N, unsigned long int K); void mpz_bin_uiui (mpz_ptr ROP, unsigned long int N, unsigned long int K); void mpz_fib_ui (mpz_ptr FN, unsigned long int N); void mpz_fib2_ui (mpz_ptr FN, mpz_ptr FNSUB1, unsigned long N); void mpz_lucnum_ui (mpz_ptr LN, unsigned long int N); void mpz_lucnum2_ui (mpz_ptr LN, mpz_ptr LNSUB1, unsigned long int N); quote(MLMLI,"\n(** {2 Comparison Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Comparisons.html#Integer-Comparisons}C documentation} *)\n") int mpz_cmp (mpz_ptr OP1, mpz_ptr OP2); int mpz_cmp_d (mpz_ptr OP1, double OP2); int mpz_cmp_si (mpz_ptr OP1, signed long int OP2); int mpz_cmpabs (mpz_ptr OP1, mpz_ptr OP2); int mpz_cmpabs_d (mpz_ptr OP1, double OP2); int mpz_cmpabs_ui (mpz_ptr OP1, unsigned long int OP2); int mpz_sgn (mpz_ptr OP); quote(MLMLI,"\n(** {2 Logical and Bit Manipulation Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Integer-Logic-and-Bit-Fiddling.html#Integer-Logic-and-Bit-Fiddling}C documentation} *)\n") void mpz_gand (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2) quote(call,"mpz_and(ROP,OP1,OP2);"); void mpz_ior (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_xor (mpz_ptr ROP, mpz_ptr OP1, mpz_ptr OP2); void mpz_com (mpz_ptr ROP, mpz_ptr OP); unsigned long int mpz_popcount (mpz_ptr OP) quote(call,"_res = mpz_popcount(OP); if (_res==ULONG_MAX) _res = Max_long;"); unsigned long int mpz_hamdist (mpz_ptr OP1, mpz_ptr OP2) quote(call,"_res = mpz_hamdist(OP1,OP2); if (_res==ULONG_MAX) _res = Max_long;"); unsigned long int mpz_scan0 (mpz_ptr OP, unsigned long int STARTING_BIT) quote(call,"_res = mpz_scan0(OP,STARTING_BIT); if (_res==ULONG_MAX) _res = Max_long;"); unsigned long int mpz_scan1 (mpz_ptr OP, unsigned long int STARTING_BIT) quote(call,"_res = mpz_scan1(OP,STARTING_BIT); if (_res==ULONG_MAX) _res = Max_long;"); void mpz_setbit (mpz_ptr ROP, unsigned long int BIT_INDEX); void mpz_clrbit (mpz_ptr ROP, unsigned long int BIT_INDEX); boolean mpz_tstbit (mpz_ptr OP, unsigned long int BIT_INDEX); quote(MLMLI,"\n(** {2 Input and Output Functions: not interfaced} *)\n") quote(MLMLI,"\n(** {2 Random Number Functions: see {!Gmp_random} module} *)\n") quote(MLMLI,"\n(** {2 Integer Import and Export Functions} *)") quote(MLMLI,"(** {{:ttp://gmplib.org/manual/Integer-Import-and-Export.html#Integer-Import-and-Export}C documentation} *)\n") void mpz__import (mpz_ptr ROP, int COUNT, [size_is(COUNT),bigarray] int OP[], int ORDER, int ENDIAN) quote(call,"mpz_import (ROP, COUNT, ORDER, sizeof(intnat), ENDIAN, 0, OP);"); [size_is(COUNT),bigarray,managed] int* mpz__export (mpz_ptr OP, int ORDER, int ENDIAN, [out,ignore]unsigned int *COUNT) quote(call,"_res = mpz_export (NULL, COUNT, ORDER, sizeof(intnat), ENDIAN, 0, OP);"); quote(MLI,"\ val import : dest:t -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t -> order:int -> endian:int -> unit\n\ val export : t -> order:int -> endian:int -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t\n\ ") quote(ML,"\ let import ~dest array ~order ~endian = _import dest array order endian\n\ let export x ~order ~endian = _export x order endian\n\ ") quote(MLMLI,"\n(** {2 Miscellaneous Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Miscellaneous-Integer-Functions.html#Miscellaneous-Integer-Functions}C documentation} *)\n") quote(MLI,"\n(* Does it fit in an OCaml integer *)") boolean mpz_fits_int_p (mpz_ptr OP); boolean mpz_odd_p (mpz_ptr OP); boolean mpz_even_p (mpz_ptr OP); int mpz_size(mpz_ptr OP); int mpz_sizeinbase (mpz_ptr OP, int BASE) quote(call,"\ if (BASE<2 || BASE>36) caml_invalid_argument(\"Argument not supported\");\n\ _res = mpz_sizeinbase (OP,BASE);"); quote(MLI,"\n(* Limited relevance here *)") boolean mpz_fits_ulong_p (mpz_ptr OP); boolean mpz_fits_slong_p (mpz_ptr OP); boolean mpz_fits_uint_p (mpz_ptr OP); boolean mpz_fits_sint_p (mpz_ptr OP); boolean mpz_fits_ushort_p (mpz_ptr OP); boolean mpz_fits_sshort_p (mpz_ptr OP); apron-dist-0.9.10/apron/octagons/tmp/mpq.idl0000750014525101416610000001344611252216517020604 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the MLGmpIDL interface, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \"caml/custom.h\"\n\ #include \"gmp_caml.h\"\n\ ") import "mpz.idl"; typedef [abstract,c2ml(camlidl_mpq_ptr_c2ml),ml2c(camlidl_mpq_ptr_ml2c)] struct __mpq_struct* mpq_ptr; quote(MLMLI,"(** GMP multiprecision rationals *)\n\n") quote(MLMLI,"(** The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like [set], [add], ...) the first parameter of type [t] is an out-parameter and holds the result when the function returns. For instance, [add x y z] adds the values of [y] and [z] and stores the result in [x].\n\n These functions are as efficient as their C counterpart: they do not imply additional memory allocation, unlike the corresponding functions in the module {!Mpqf}. *)\n\n") /* OUTOUTOUT is a reserved variable name ! (see Makefile and sedscript_c) */ void mpq_canonicalize (mpq_ptr OP); quote(MLI,"\n(** {2 Pretty printing} *)\n") quote(MLI,"val print : Format.formatter -> t -> unit") quote(MLMLI,"\n(** {2 Initialization and Assignment Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Initializing-Rationals.html#Initializing-Rationals}C documentation} *)\n") void mpq_init([out] mpq_ptr OUTOUTOUT); void mpq_set(mpq_ptr ROP, mpq_ptr OP); void mpq_set_z (mpq_ptr ROP, mpz_ptr OP); void mpq_set_si (mpq_ptr ROP, signed long int OP1, unsigned long int OP2) quote(dealloc, "mpq_canonicalize(ROP);"); void mpq__set_str(mpq_ptr ROP, [string]char* STR, int BASE) quote(call,"{\n\ int n = mpq_set_str(ROP,STR,BASE);\n\ if (n){ mpq_clear(ROP); caml_invalid_argument(\"\"); }\n\ }") quote(dealloc, "mpq_canonicalize(ROP);"); quote(MLI,"val set_str : t -> string -> base:int -> unit") quote(ML,"let set_str a b ~base = _set_str a b base") void mpq_swap (mpq_ptr ROP1, mpq_ptr ROP2); quote(MLI,"(** {2 Additional Initialization and Assignements functions} *)\n") quote(MLI,"(** These functions are additions to or renaming of functions offered by the C library. *)\n") quote(MLI,"val init_set : t -> t") quote(MLI,"val init_set_z : Mpz.t -> t") quote(MLI,"val init_set_si : int -> int -> t") quote(MLI,"val init_set_str : string -> base:int -> t") quote(MLI,"val init_set_d : float -> t") quote(MLMLI,"\n(** {2 Conversion Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Rational-Conversions.html#Rational-Conversions}C documentation} *)\n") double mpq_get_d (mpq_ptr OP); void mpq_set_d (mpq_ptr ROP, double OP); quote(MLI,"\n(* Replace Mpz.set_q: Mpz.t -> Mpq.t -> unit *)") void mpq_get_z(mpz_ptr ROP, mpq_ptr OP) quote(call,"mpz_set_q(ROP,OP);"); quote(MLI,"\n(* For set_f: t -> Mpf.t -> unit, see Mpf.get_q *)\n\n") /* void mpq_set_f (mpq_ptr ROP, mpf_ptr OP); */ [string]char* mpq__get_str (int BASE, mpq_ptr OP) quote(call,"_res = mpq_get_str(NULL,BASE,OP);") quote(dealloc,"free(_res);"); quote(MLI,"val get_str : base:int -> t -> string") quote(ML,"let get_str ~base a = _get_str base a") quote(MLI,"\n(** {2 User Conversions} *)\n") quote(MLI,"(** These functionss are additions to or renaming of functions offeered by the C library. *)\n") quote(MLI,"val to_string : t -> string") quote(MLI,"val to_float : t -> float") quote(MLI,"val of_string : string -> t") quote(MLI,"val of_float : float -> t") quote(MLI,"val of_int : int -> t") quote(MLI,"val of_frac : int -> int -> t") quote(MLI,"val of_mpz : Mpz.t -> t") quote(MLI,"val of_mpz2 : Mpz.t -> Mpz.t -> t") quote(MLMLI,"\n(** {2 Arithmetic Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Rational-Arithmetic.html#Rational-Arithmetic}C documentation} *)\n") void mpq_add (mpq_ptr ROP, mpq_ptr OP1, mpq_ptr OP2); void mpq_sub (mpq_ptr ROP, mpq_ptr OP1, mpq_ptr OP2); void mpq_mul (mpq_ptr ROP, mpq_ptr OP1, mpq_ptr OP2); void mpq_mul_2exp (mpq_ptr ROP, mpq_ptr OP1, unsigned long int OP2); void mpq_div (mpq_ptr ROP, mpq_ptr OP1, mpq_ptr OP2); void mpq_div_2exp (mpq_ptr ROP, mpq_ptr OP1, unsigned long int OP2); void mpq_neg (mpq_ptr ROP, mpq_ptr OP); void mpq_abs (mpq_ptr ROP, mpq_ptr OP); void mpq_inv (mpq_ptr ROP, mpq_ptr OP); quote(MLMLI,"\n(** {2 Comparison Functions} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Comparing-Rationals.html#Comparing-Rationals}C documentation} *)\n") int mpq_cmp (mpq_ptr OP1, mpq_ptr OP2); int mpq_cmp_si (mpq_ptr OP1, long int NUM2, unsigned long int DEN2); int mpq_sgn (mpq_ptr OP); boolean mpq_equal (mpq_ptr OP1, mpq_ptr OP2); quote(MLMLI,"\n(** {2 Applying Integer Functions to Rationals} *)") quote(MLMLI,"(** {{:http://gmplib.org/manual/Applying-Integer-Functions.html#Applying-Integer-Functions}C documentation} *)\n") void mpq_get_num (mpz_ptr NUMERATOR, mpq_ptr RATIONAL); void mpq_get_den (mpz_ptr DENOMINATOR, mpq_ptr RATIONAL); void mpq_set_num (mpq_ptr RATIONAL, mpz_ptr NUMERATOR); void mpq_set_den (mpq_ptr RATIONAL, mpz_ptr DENOMINATOR); quote(MLMLI,"\n(** {2 Input and Output Functions: not interfaced} *)\n") quote(ML,"\n(** {2 Pretty printing} *)\n") quote(ML,"let print fmt x = Format.pp_print_string fmt (get_str 10 x)") quote(ML,"let init_set x = let y = init() in set y x; y") quote(ML,"let init_set_z z = let x = init() in set_z x z; x") quote(ML,"let init_set_si n d = let x = init() in set_si x n d; x") quote(ML,"let init_set_str str ~base = let x = init() in ignore (set_str x str ~base); x") quote(ML,"let init_set_d d = let x = init() in set_d x d; x") quote(ML,"let to_string x = get_str 10 x") quote(ML,"let to_float = get_d") quote(ML,"let of_string str = init_set_str str 10") quote(ML,"let of_float = init_set_d") quote(ML,"let of_int a = init_set_si a 1") quote(ML,"let of_frac = init_set_si") quote(ML,"let of_mpz = init_set_z") quote(ML,"let of_mpz2 num den = let res = init() in set_num res num; set_den res den; canonicalize res; res") apron-dist-0.9.10/apron/octagons/oct_representation.c0000640014525101416610000003123011164746234022563 0ustar bjeannetpopart/* * oct_representation.c * * Simple functions related to the representation of octagons * * APRON Library / Octagonal Domain * * Copyright (C) Antoine Mine' 2006 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #include "oct.h" #include "oct_internal.h" #include "ap_generic.h" /* ============================================================ */ /* Memory Related */ /* ============================================================ */ /* generic allocation routine, returns a bottom octagon */ inline oct_t* oct_alloc_internal(oct_internal_t* pr, size_t dim, size_t intdim) { oct_t* r; checked_malloc(r,oct_t,1,return NULL;); r->intdim = intdim; r->dim = dim; r->closed = r->m = NULL; return r; } inline oct_t* oct_alloc_top(oct_internal_t* pr, size_t dim, size_t intdim) { oct_t* r = oct_alloc_internal(pr,dim,intdim); r->closed = hmat_alloc_top(pr,dim); return r; } inline void oct_free_internal(oct_internal_t* pr, oct_t* a) { if (a->m) hmat_free(pr,a->m,a->dim); if (a->closed) hmat_free(pr,a->closed,a->dim); a->closed = a->m = NULL; free(a); } inline oct_t* oct_copy_internal(oct_internal_t* pr, oct_t* a) { oct_t* r = oct_alloc_internal(pr,a->dim,a->intdim); r->m = hmat_copy(pr,a->m,a->dim); r->closed = hmat_copy(pr,a->closed,a->dim); return r; } oct_t* oct_copy(ap_manager_t* man, oct_t* a) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_COPY,0); return oct_copy_internal(pr,a); } void oct_free(ap_manager_t* man, oct_t* a) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_FREE,0); oct_free_internal(pr,a); } size_t oct_size(ap_manager_t* man, oct_t* a) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_ASIZE,0); if (!a->m) return 1; return matsize(a->dim); } /* If destructive, returns a with fields m and closed updated (former fields of a, if not reused in m or closed, are destroyed). If not destructive, returns a new octagon with same dimensions as a and m and closed as half-matrices. m and closed can safely alias fields in a */ oct_t* oct_set_mat(oct_internal_t* pr, oct_t* a, bound_t* m, bound_t* closed, bool destructive) { oct_t* r; if (destructive) { /* free non-aliased matrices */ if (a->m && a->m!=m && a->m!=closed) hmat_free(pr,a->m,a->dim); if (a->closed && a->closed!=m && a->closed!=closed) hmat_free(pr,a->closed,a->dim); r = a; } else { /* copy aliased matrices */ r = oct_alloc_internal(pr,a->dim,a->intdim); if (m && (a->m==m || a->closed==m)) m = hmat_copy(pr,m,a->dim); if (closed && (a->m==closed || a->closed==closed)) closed = hmat_copy(pr,closed,a->dim); } r->m = m; r->closed = closed; return r; } /* ============================================================ */ /* Basic Constructors */ /* ============================================================ */ oct_t* oct_bottom(ap_manager_t* man, size_t intdim, size_t realdim) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_BOTTOM,0); oct_t* r = oct_alloc_internal(pr,intdim+realdim,intdim); return r; } oct_t* oct_top(ap_manager_t* man, size_t intdim, size_t realdim) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_TOP,0); oct_t* r = oct_alloc_internal(pr,intdim+realdim,intdim); r->closed = hmat_alloc_top(pr,r->dim); return r; } oct_t* oct_of_box(ap_manager_t* man, size_t intdim, size_t realdim, ap_interval_t ** t) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_OF_BOX,0); oct_t* r = oct_alloc_internal(pr,intdim+realdim,intdim); size_t i,j,n2; if (!t) return r; /* empty */ for (i=0;idim;i++) if (ap_scalar_cmp(t[i]->inf,t[i]->sup)>0) return r; /* empty */ r->closed = hmat_alloc_top(pr,r->dim); for (i=0;idim;i++) if (bounds_of_interval(pr, r->closed[matpos(2*i,2*i+1)], r->closed[matpos(2*i+1,2*i)], t[i],true)) { /* one interval is empty -> the result is empty */ hmat_free(pr,r->closed,r->dim); r->closed = NULL; return r; } /* a S step is sufficient to ensure clsoure */ if (hmat_s_step(r->closed,r->dim)){ /* definitively empty */ hmat_free(pr,r->closed,r->dim); r->closed = NULL; } /* exact, except for conversion errors */ if (pr->conv) flag_conv; return r; } oct_t* oct_of_generator_array(ap_manager_t* man, size_t intdim, size_t realdim, ap_generator0_array_t* ar) { size_t dim = intdim+realdim; oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_ADD_RAY_ARRAY, 2*(dim+1)); oct_t* r = oct_alloc_internal(pr,intdim+realdim,intdim); size_t i,j,k; /* find one vertex */ for (i=0;isize;i++) { bound_t* b; if (ar->p[i].gentyp!=AP_GEN_VERTEX) continue; bounds_of_generator(pr,pr->tmp,ar->p[i].linexpr0,dim); r->m = hmat_alloc_top(pr,dim); for (b=r->m,j=0;j<2*dim;j++) for (k=0;k<=(j|1);k++,b++) bound_sub(*b,pr->tmp[j],pr->tmp[k]); break; } if (r->m) { /* not empty */ hmat_add_generators(pr,r->m,dim,ar); /* best in Q and Z, except for conversion errors */ man->result.flag_exact = false; if (pr->conv) flag_conv; } return r; } ap_abstract0_t* ap_abstract0_oct_of_generator_array(ap_manager_t* man, size_t intdim, size_t realdim, ap_generator0_array_t* array) { return abstract0_of_oct(man,oct_of_generator_array(man,intdim,realdim,array)); } /* ============================================================ */ /* Accessors */ /* ============================================================ */ ap_dimension_t oct_dimension(ap_manager_t* man, oct_t* a) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_DIMENSION,0); ap_dimension_t r; r.intdim = a->intdim; r.realdim = a->dim-a->intdim; return r; } /* ============================================================ */ /* Closure */ /* ============================================================ */ /* Make sure the closed version of the matrix a->closed is available. If a->closed when it returns, this means the octagon is empty. If the octagon is not empty, a->m is not modified. => this DOES NOT affect the semantics of functions that rely on a->m (e.g., widening) */ void oct_cache_closure(oct_internal_t* pr, oct_t* a) { if (a->closed || !a->m) return; a->closed = hmat_copy(pr,a->m,a->dim); if (hmat_close(a->closed,a->dim)) { /* empty! */ hmat_free(pr,a->m,a->dim); hmat_free(pr,a->closed,a->dim); a->m = a->closed = NULL; } } /* Unlike oct_cache_closure, this frees the a->m representation, forcing all further transfer functions to work on the closed version... => this changes the semantics of functions such as widening */ void oct_close(oct_internal_t* pr, oct_t* a) { if (!a->m) return; if (a->closed) { hmat_free(pr,a->m,a->dim); a->m = NULL; return; } a->closed = a->m; a->m = NULL; if (hmat_close(a->closed,a->dim)) { hmat_free(pr,a->closed,a->dim); a->closed = NULL; } } /* ============================================================ */ /* Control of internal representation: NOT IMPLEMENTED */ /* ============================================================ */ /* NOT IMPLEMENTED: do nothing */ void oct_minimize(ap_manager_t* man, oct_t* a) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_MINIMIZE,0); ap_manager_raise_exception(man,AP_EXC_NOT_IMPLEMENTED,pr->funid, "not implemented"); } /* NOT IMPLEMENTED: do nothing */ void oct_canonicalize(ap_manager_t* man, oct_t* a) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_CANONICALIZE,0); ap_manager_raise_exception(man,AP_EXC_NOT_IMPLEMENTED,pr->funid, "not implemented"); } /* NOT IMPLEMENTED: do nothing */ int oct_hash(ap_manager_t* man, oct_t* a) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_HASH,0); if (pr->funopt->algorithm>=0) oct_cache_closure(pr,a); if (a->closed || a->m) { int r = 0; bound_t *m = a->closed ? a->closed : a->m; size_t i,j; for (i=0;i<2*a->dim;i++) for (j=0;j<=(i|1);j++,m) r = r*37 + bound_hash(*m); return r; } return 0; } /* NOT IMPLEMENTED: do nothing */ void oct_approximate(ap_manager_t* man, oct_t* a, int algorithm) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_APPROXIMATE,0); ap_manager_raise_exception(man,AP_EXC_NOT_IMPLEMENTED,pr->funid, "not implemented"); } /* ============================================================ */ /* Topological losure operation */ /* ============================================================ */ /* actually identity */ oct_t* oct_closure(ap_manager_t* man, bool destructive, oct_t* a) { oct_internal_t* pr = oct_init_from_manager(man,AP_FUNID_CLOSURE,0); if (destructive) return a; else return oct_copy_internal(pr,a); } /* ============================================================ */ /* Managers */ /* ============================================================ */ void oct_internal_free(oct_internal_t* pr) { bound_clear_array(pr->tmp,pr->tmp_size); free(pr->tmp); free(pr->tmp2); free(pr); } ap_manager_t* oct_manager_alloc(void) { size_t i; ap_manager_t* man; oct_internal_t* pr; if (!ap_fpu_init()) { fprintf(stderr,"oct_manager_alloc cannot change the FPU rounding mode\n"); } pr = (oct_internal_t*)malloc(sizeof(oct_internal_t)); assert(pr); pr->tmp_size = 10; pr->tmp = malloc(sizeof(bound_t)*pr->tmp_size); assert(pr->tmp); bound_init_array(pr->tmp,pr->tmp_size); pr->tmp2 = malloc(sizeof(long)*pr->tmp_size); assert(pr->tmp2); man = ap_manager_alloc("oct","1.0 with " NUM_NAME, pr, (void (*)(void*))oct_internal_free); pr->man = man; man->funptr[AP_FUNID_COPY] = &oct_copy; man->funptr[AP_FUNID_FREE] = &oct_free; man->funptr[AP_FUNID_ASIZE] = &oct_size; man->funptr[AP_FUNID_MINIMIZE] = &oct_minimize; man->funptr[AP_FUNID_CANONICALIZE] = &oct_canonicalize; man->funptr[AP_FUNID_HASH] = &oct_hash; man->funptr[AP_FUNID_APPROXIMATE] = &oct_approximate; man->funptr[AP_FUNID_FPRINT] = &oct_fprint; man->funptr[AP_FUNID_FPRINTDIFF] = &oct_fprintdiff; man->funptr[AP_FUNID_FDUMP] = &oct_fdump; man->funptr[AP_FUNID_SERIALIZE_RAW] = &oct_serialize_raw; man->funptr[AP_FUNID_DESERIALIZE_RAW] = &oct_deserialize_raw; man->funptr[AP_FUNID_BOTTOM] = &oct_bottom; man->funptr[AP_FUNID_TOP] = &oct_top; man->funptr[AP_FUNID_OF_BOX] = &oct_of_box; man->funptr[AP_FUNID_DIMENSION] = &oct_dimension; man->funptr[AP_FUNID_IS_BOTTOM] = &oct_is_bottom; man->funptr[AP_FUNID_IS_TOP] = &oct_is_top; man->funptr[AP_FUNID_IS_LEQ] = &oct_is_leq; man->funptr[AP_FUNID_IS_EQ] = &oct_is_eq; man->funptr[AP_FUNID_IS_DIMENSION_UNCONSTRAINED] = &oct_is_dimension_unconstrained; man->funptr[AP_FUNID_SAT_INTERVAL] = &oct_sat_interval; man->funptr[AP_FUNID_SAT_LINCONS] = &oct_sat_lincons; man->funptr[AP_FUNID_SAT_TCONS] = &oct_sat_tcons; man->funptr[AP_FUNID_BOUND_DIMENSION] = &oct_bound_dimension; man->funptr[AP_FUNID_BOUND_LINEXPR] = &oct_bound_linexpr; man->funptr[AP_FUNID_BOUND_TEXPR] = &oct_bound_texpr; man->funptr[AP_FUNID_TO_BOX] = &oct_to_box; man->funptr[AP_FUNID_TO_LINCONS_ARRAY] = &oct_to_lincons_array; man->funptr[AP_FUNID_TO_TCONS_ARRAY] = &oct_to_tcons_array; man->funptr[AP_FUNID_TO_GENERATOR_ARRAY] = &oct_to_generator_array; man->funptr[AP_FUNID_MEET] = &oct_meet; man->funptr[AP_FUNID_MEET_ARRAY] = &oct_meet_array; man->funptr[AP_FUNID_MEET_LINCONS_ARRAY] = &oct_meet_lincons_array; man->funptr[AP_FUNID_MEET_TCONS_ARRAY] = &oct_meet_tcons_array; man->funptr[AP_FUNID_JOIN] = &oct_join; man->funptr[AP_FUNID_JOIN_ARRAY] = &oct_join_array; man->funptr[AP_FUNID_ADD_RAY_ARRAY] = &oct_add_ray_array; man->funptr[AP_FUNID_ASSIGN_LINEXPR_ARRAY] = &oct_assign_linexpr_array; man->funptr[AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY] = &oct_substitute_linexpr_array; man->funptr[AP_FUNID_ASSIGN_TEXPR_ARRAY] = &oct_assign_texpr_array; man->funptr[AP_FUNID_SUBSTITUTE_TEXPR_ARRAY] = &oct_substitute_texpr_array; man->funptr[AP_FUNID_ADD_DIMENSIONS] = &oct_add_dimensions; man->funptr[AP_FUNID_REMOVE_DIMENSIONS] = &oct_remove_dimensions; man->funptr[AP_FUNID_PERMUTE_DIMENSIONS] = &oct_permute_dimensions; man->funptr[AP_FUNID_FORGET_ARRAY] = &oct_forget_array; man->funptr[AP_FUNID_EXPAND] = &oct_expand; man->funptr[AP_FUNID_FOLD] = &oct_fold; man->funptr[AP_FUNID_WIDENING] = &oct_widening; man->funptr[AP_FUNID_CLOSURE] = &oct_closure; for (i=0;ivalue; } ap_abstract0_t* abstract0_of_oct(ap_manager_t* man, oct_t* oct) { ap_abstract0_t* r = malloc(sizeof(ap_abstract0_t)); assert(r); r->value = oct; r->man = ap_manager_copy(man); return r; } apron-dist-0.9.10/apron/octagons/sedscript_caml0000640014525101416610000000054410573327713021433 0ustar bjeannetpoparts/Manager.ap_manager_ptr/t Apron.Manager.t/g; s/internal_ptr/internal/g; s/external oct_/external /g; s/Generator0.ap_generator0_array_t/Apron.Generator0.t array/g; s/Scalar.ap_scalar_ptr/Apron.Scalar.t/g; s/Scalar.ap_scalar_array_t/Apron.Scalar.t array/g; s/Abstract0.ap_abstract0_ptr/t Apron.Abstract0.t/g; s/external ap_abstract0_oct_/external /g; apron-dist-0.9.10/apron/octagons/oct_test.c0000640014525101416610000014645311164746234020516 0ustar bjeannetpopart/* * oct_test.c * * Unit testing. * * APRON Library / Octagonal Domain * * Copyright (C) Antoine Mine' 2006 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #include #include #include #include long int lrand48(void); void srand48(long int seedval); #include "oct.h" #include "oct_fun.h" #include "oct_internal.h" #include "pk.h" ap_manager_t* mo; /* octagon */ ap_manager_t* mp; /* polyhedron */ oct_internal_t* pr; pk_internal_t* pk; #define MAXN 50000 int N = 70; char b1_[MAXN+4]= " ["; char b2_[MAXN+4]; int i_; int error_ = 0; typedef enum { none = 0, best = 1, exact = 2 } exactness; exactness flag; #define LOOP \ { \ memset(b1_+2,' ',N); b1_[N+2]=']'; b1_[N+3]=0; \ memset(b2_,8,N+3); b2_[N+3]=0; \ for (i_=0;i_result.flag_exact) ; \ else if (m->result.flag_best && flag==exact) flag = best; \ else flag = none; #define RESULT(c) b1_[i_+2]=c #define ERROR(msg) \ do { \ fprintf(stderr,"\n%s\n",msg); \ RESULT('!'); \ error_++; \ } while (0) #define ENDLOOP \ } } \ if (N<80) printf("%s%s\n",b1_,b2_); \ else printf("%c",b1_[i_+2]) char check(oct_t* o) { if (!o->closed && !o->m) return 'o'; /* really empty */ if (o->closed) { bound_t* cl; size_t i; if (num_incomplete || o->intdim) return '.'; /* incomplete */ /* check that o->closed is really closed */ if (!hmat_check_closed(o->closed,o->dim)) { ERROR("invalid closure"); return '!'; } if (!o->m) return 'c'; /* ok */ /* now check that closure(o->m) = o->closed */ cl = hmat_copy(pr,o->m,o->dim); hmat_close(cl,o->dim); for (i=0;idim);i++) if (bound_cmp(cl[i],o->closed[i])) { hmat_free(pr,cl,o->dim); return '#'; } hmat_free(pr,cl,o->dim); return 'C'; } return '.'; /* regular matrix */ } void random_bound(bound_t b) { num_t n; num_init(n); num_set_int2(n,lrand48()%20-2,lrand48()%4+1); bound_set_num(b,n); num_clear(n); } oct_t* random_oct(int dim,float frac) { oct_t* o = oct_alloc_internal(pr,dim,0); bound_t* b; int i,j,x,y; num_t n; o->m = hmat_alloc_top(pr,dim); b = o->m; num_init(n); for (i=0;i<2*dim;i++) for (j=0;j<=(i|1);j++,b++) { if (i==j) continue; if (lrand48()%100>frac*100) continue; y = lrand48()%4+1; x = lrand48()%20-2; num_set_int2(n,x,y); bound_set_num(*b,n); } num_clear(n); return o; } /* build polyhedron & octagon at the same time, from same constraints */ void random_poly_oct(int dim,float frac, oct_t**o, ap_abstract0_t** p) { bound_t* b; int i,j,x,y; num_t n; *o = oct_alloc_internal(pr,dim,0); (*o)->m = hmat_alloc_top(pr,dim); *p = ap_abstract0_top(mp,0,dim); b = (*o)->m; num_init(n); for (i=0;i<2*dim;i++) for (j=0;j<=(i|1);j++,b++) { if (i==j) continue; if (lrand48()%100>frac*100) continue; { ap_linexpr0_t* l; ap_lincons0_array_t c = ap_lincons0_array_make(1); y = lrand48()%4+1; x = lrand48()%20-2; if (!num_set_int2(n,x,y)) flag = none; bound_set_num(*b,n); l = ap_linexpr0_alloc(AP_LINEXPR_SPARSE, 2); if (i/2!=j/2) ap_linexpr0_set_list(l, AP_CST_S_FRAC, x, y, AP_COEFF_S_INT, (j%2) ? 1 : -1, j/2, AP_COEFF_S_INT, (i%2) ? -1 : 1, i/2, AP_END); else ap_linexpr0_set_list(l, AP_CST_S_FRAC, x, y, AP_COEFF_S_INT, (j%2) ? 2 : -2, j/2, AP_END); c.p[0] = ap_lincons0_make(AP_CONS_SUPEQ, l, NULL); *p = ap_abstract0_meet_lincons_array(mp,true,*p,&c); ap_lincons0_array_clear(&c); } } num_clear(n); } typedef enum { expr_unary, expr_oct, expr_lin, expr_qlin, expr_interv, } exprmode; const char* exprname[] = { "unary ", "octagonal ", "", "quasi", "interval " }; ap_linexpr0_t* random_linexpr(exprmode mode, int dim) { ap_linexpr0_t* l = ap_linexpr0_alloc(AP_LINEXPR_DENSE,dim); int i,n1,n2,d; if (mode<=expr_oct) { if (lrand48()%10>2) ap_coeff_set_scalar_int(l->p.coeff+(lrand48()%dim),lrand48()%3-1); if (mode==expr_oct) if (lrand48()%10>2) ap_coeff_set_scalar_int(l->p.coeff+(lrand48()%dim),lrand48()%3-1); } else if (mode<=expr_qlin) { for (i=0;ip.coeff+i,lrand48()%20-10,lrand48()%4+1); } else { for (i=0;ip.coeff+i,n1,d,n2,d); } } if (mode<=expr_lin) { ap_coeff_set_scalar_frac(&l->cst,lrand48()%20-10,lrand48()%4+1); } else { int n1 = lrand48()%20-10; int n2 = n1 + lrand48()%20; int d = lrand48()%4+1; ap_coeff_set_interval_frac(&l->cst,n1,d,n2,d); } return l; } /* chose one linexpr within an interval linexpr */ ap_linexpr0_t* random_from_linexpr(ap_linexpr0_t* a) { size_t i; ap_linexpr0_t* l = ap_linexpr0_alloc(AP_LINEXPR_DENSE,a->size); assert(a->discr==AP_LINEXPR_DENSE); for (i=0;isize;i++) { switch (a->p.coeff[i].discr) { case AP_COEFF_SCALAR: ap_coeff_set_scalar(l->p.coeff+i,a->p.coeff[i].val.scalar); break; case AP_COEFF_INTERVAL: if (lrand48()%2) ap_coeff_set_scalar(l->p.coeff+i,a->p.coeff[i].val.interval->inf); else ap_coeff_set_scalar(l->p.coeff+i,a->p.coeff[i].val.interval->sup); break; } } switch (a->cst.discr) { case AP_COEFF_SCALAR: ap_coeff_set_scalar(&l->cst,a->cst.val.scalar); break; case AP_COEFF_INTERVAL: if (lrand48()%2) ap_coeff_set_scalar(&l->cst,a->cst.val.interval->inf); else ap_coeff_set_scalar(&l->cst,a->cst.val.interval->sup); break; } return l; } ap_lincons0_t random_from_lincons(ap_lincons0_t a) { return ap_lincons0_make(a.constyp,random_from_linexpr(a.linexpr0),NULL); } ap_generator0_t random_generator(int dim, ap_gentyp_t g) { ap_linexpr0_t* l = ap_linexpr0_alloc(AP_LINEXPR_DENSE,dim); int i; for (i=0;ip.coeff+i,lrand48()%20-2,lrand48()%4+1); ap_coeff_set_scalar_int(&l->cst,0); return ap_generator0_make(g,l); } ap_texpr0_t* random_texpr(int dim, int depth) { if (!depth) { switch (lrand48()%3) { case 0: return ap_texpr0_dim(lrand48()%dim); case 1: return ap_texpr0_cst_scalar_frac(lrand48()%20-2,lrand48()%4+1); default: { int n1 = lrand48()%20-2, d = lrand48()%4+1; int n2 = n1 + lrand48()%10; return ap_texpr0_cst_interval_frac(n1,d,n2,d); } } } else if (lrand48()%2) return ap_texpr0_unop(AP_TEXPR_NEG+lrand48()%(AP_TEXPR_SQRT-AP_TEXPR_NEG+1), random_texpr(dim,lrand48()%depth), lrand48()%AP_RTYPE_SIZE, lrand48()%AP_RDIR_SIZE); else return ap_texpr0_binop(lrand48()%AP_TEXPR_NEG, random_texpr(dim,lrand48()%depth), random_texpr(dim,lrand48()%depth), lrand48()%AP_RTYPE_SIZE, lrand48()%AP_RDIR_SIZE); } ap_abstract0_t* random_poly(int dim) { ap_abstract0_t* p; int i; ap_interval_t** t = ap_interval_array_alloc(dim); ap_generator0_array_t ar = ap_generator0_array_make(dim); for (i=0;iresult.flag_exact; } bool oct_is_neq(ap_manager_t* man, oct_t* a1, oct_t* a2) { return !oct_is_eq(man,a1,a2) && man->result.flag_exact; } /* ********************************* */ /* infos */ /* ********************************* */ void info(void) { printf("octagons: %s (%s)\n",mo->library,mo->version); printf("polyhedra: %s (%s)\n",mp->library,mp->version); printf("nums: %s (%s wto overflow,%s)\n",NUM_NAME, num_safe ? "sound" : "unsound", num_incomplete ? "incomplete" : "complete"); } /* ********************************* */ /* various tests */ /* ********************************* */ void test_misc(void) { size_t D = 5; int i; oct_t* bot = oct_bottom(mo,0,D); oct_t* top = oct_top(mo,0,D); ap_abstract0_t* bot2 = poly_of_oct(bot); ap_abstract0_t* top2 = poly_of_oct(top); ap_dimension_t d1 = oct_dimension(mo,bot); ap_dimension_t d2 = oct_dimension(mo,top); printf("\nperforming various tests\n"); check(bot); check(top); if (d1.intdim || d1.realdim!=D) printf("oct_dimension failed #1\n"); if (d2.intdim || d2.realdim!=D) printf("oct_dimension failed #2\n"); if (!oct_is_bottom(mo,bot)) printf("oct_is_bottom failed #3\n"); if (oct_is_bottom(mo,top)) printf("oct_is_bottom failed #4\n"); if (oct_is_top(mo,bot)) printf("oct_is_top failed #5\n"); if (!oct_is_top(mo,top)) printf("oct_is_top failed #6\n"); if (!oct_is_leq(mo,bot,top)) printf("oct_is_leq failed #7\n"); if (oct_is_leq(mo,top,bot)) printf("oct_is_leq failed #8\n"); if (!oct_is_eq(mo,bot,bot)) printf("oct_is_eq failed #9\n"); if (!oct_is_eq(mo,top,top)) printf("oct_is_eq failed #10\n"); if (oct_is_eq(mo,bot,top)) printf("oct_is_eq failed #11\n"); if (oct_is_dimension_unconstrained(mo,bot,0)) printf("oct_is_dimension_unconstrained #12\n"); if (!oct_is_dimension_unconstrained(mo,top,0)) printf("oct_is_dimension_unconstrained #13\n"); if (!ap_abstract0_is_bottom(mp,bot2) && mp->result.flag_exact) printf("poly_is_bottom failed\n"); if (!ap_abstract0_is_top(mp,top2) && mp->result.flag_exact) printf("poly_is_top failed\n"); for (i=0;iclosed) { for (i=0;2*i8) random_bound(o->closed[matpos2(i,2*v)]); if (lrand48()%10>8) random_bound(o->closed[matpos2(i,2*v+1)]); } o->m = hmat_copy(pr,o->closed,dim); if (hmat_close_incremental(o->closed,dim,v)) RESULT('o'); else RESULT(check(o)); } else RESULT('o'); oct_free(mo,o); } ENDLOOP; } /* ********************************* */ /* conversions */ /* ********************************* */ void test_polyhedra_conversion(void) { printf("\nconversion to polyhedra %s\n",num_incomplete ? "" : "(* expected)"); LOOP { oct_t *o, *o2; ap_abstract0_t *p, *p2; o = random_oct(2,.1); p = poly_of_oct(o); o2 = oct_of_poly(p); p2 = poly_of_oct(o2); RESULT(check(o)); check(o2); if (oct_is_nleq(mo,o,o2)) { ERROR("oct not included in"); print_oct("o",o); print_poly("p",p); print_oct("o2",o2); } if (!ap_abstract0_is_leq(mp,p,p2)) { ERROR("poly not included in"); print_oct("o",o); print_poly("p",p); print_oct("o2",o2); print_poly("p2",p2); } if (oct_is_eq(mo,o,o2) && ap_abstract0_is_eq(mp,p,p2)) RESULT('*'); if (flag>=best && (oct_is_neq(mo,o,o2) || !ap_abstract0_is_eq(mp,p,p2))) ERROR("best flag"); oct_free(mo,o); oct_free(mo,o2); ap_abstract0_free(mp,p); ap_abstract0_free(mp,p2); } ENDLOOP; { oct_t *o; ap_abstract0_t *p; bool r; flag = exact; o = oct_bottom(mo,0,7); p = poly_of_oct(o); r = ap_abstract0_is_bottom(mp,p); FLAG(mp); if (flag>=best && !r) printf("poly_is_bottom failed\n"); oct_free(mo,o); ap_abstract0_free(mp,p); } { oct_t *o; ap_abstract0_t *p; o = oct_top(mo,0,7); p = poly_of_oct(o); if (!ap_abstract0_is_top(mp,p) && mp->result.flag_exact) printf("poly_is_top failed\n"); oct_free(mo,o); ap_abstract0_free(mp,p); } } void test_polyhedra_conversion2(void) { printf("\nconversion from polyhedra (=from generator) %s\n",num_incomplete?"":"(* expected)"); LOOP { ap_abstract0_t *p, *p2; oct_t *o, *o2; p = random_poly(5); o = oct_of_poly(p); p2 = poly_of_oct(o); o2 = oct_of_poly(p2); RESULT(check(o)); check(o2); if (oct_is_nleq(mo,o,o2) || !ap_abstract0_is_leq(mp,p,p2)) { ERROR("not included in"); print_poly("p",p); print_oct("o",o); print_poly("p2",p2); print_oct("o2",o2); } if (oct_is_eq(mo,o,o2)) RESULT('*'); if (flag>=best && oct_is_neq(mo,o,o2)) ERROR("best flag"); oct_free(mo,o); oct_free(mo,o2); ap_abstract0_free(mp,p); ap_abstract0_free(mp,p2); } ENDLOOP; { ap_abstract0_t *p; oct_t *o; flag = exact; p = ap_abstract0_bottom(mp,0,7); o = oct_of_poly(p); if (flag>=best && !oct_is_bottom(mo,o)) printf("oct_is_bottom failed\n"); oct_free(mo,o); ap_abstract0_free(mp,p); } { ap_abstract0_t *p; oct_t *o; flag = exact; p = ap_abstract0_top(mp,0,7); o = oct_of_poly(p); if (flag>=best && !oct_is_top(mo,o)) printf("oct_is_top failed\n"); oct_free(mo,o); ap_abstract0_free(mp,p); } } void test_lincons_conversion(exprmode mode) { printf("\nconversion from %slincons %s\n",exprname[mode], num_incomplete?"":(mode<=expr_oct)?"(* expected)":"(*,x,. expected)"); LOOP { int dim = 6, nb = 10, i; ap_abstract0_t *p, *p2; oct_t *o, *oo; ap_lincons0_array_t t = ap_lincons0_array_make(nb); ap_lincons0_array_t tt = ap_lincons0_array_make(nb); for (i=0;i=90)?AP_CONS_EQ: (lrand48()%100>=90)?AP_CONS_SUP: AP_CONS_SUPEQ, random_linexpr(mode,dim), NULL); tt.p[i] = random_from_lincons(t.p[i]); } p = ap_abstract0_of_lincons_array(mp,0,dim,&tt); o = oct_top(mo,0,dim); o = oct_meet_lincons_array(mo,true,o,&t); FLAG(mo); p2 = poly_of_oct(o); oo = oct_of_poly(p); RESULT(check(o)); if (!ap_abstract0_is_leq(mp,p,p2)) { ERROR("not included in"); print_poly("p",p); fprintf(stderr,"t = "); ap_lincons0_array_fprint(stderr,&t,NULL); print_oct("o",o); print_poly("p2",p2); } if (ap_abstract0_is_eq(mp,p,p2)) RESULT('*'); else if (oct_is_eq(mo,o,oo)) RESULT('x'); if (flag>=best && oct_is_neq(mo,o,oo)) ERROR("best flag"); if (flag==exact && !ap_abstract0_is_eq(mp,p,p2)) ERROR("exact flag"); oct_free(mo,o); oct_free(mo,oo); ap_abstract0_free(mp,p); ap_abstract0_free(mp,p2); ap_lincons0_array_clear(&t); ap_lincons0_array_clear(&tt); } ENDLOOP; } void test_generator_conversion(void) { printf("\nconversion to generators %s\n",num_incomplete?"":"(.,* expected)"); LOOP { size_t dim = 6; oct_t *o, *o2; ap_generator0_array_t t; o = random_oct(dim,.1); t = oct_to_generator_array(mo,o); FLAG(mo); o2 = oct_of_generator_array(mo,0,dim,&t); FLAG(mo); RESULT(check(o2)); if (oct_is_nleq(mo,o,o2)) { ERROR("not included in"); print_oct("o",o); fprintf(stderr,"t = "); ap_generator0_array_fprint(stderr,&t,NULL); print_oct("o2",o2); } if (oct_is_eq(mo,o,o2)) RESULT('*'); if (flag==exact && oct_is_neq(mo,o,o2)) ERROR("exact flag"); oct_free(mo,o); oct_free(mo,o2); ap_generator0_array_clear(&t); } ENDLOOP; } void test_box_conversion(void) { printf("\nconversion to box %s\n",num_incomplete?"":"(* expected)"); LOOP { size_t dim = 6; int i; oct_t *o,*o2,*o3; ap_interval_t **b,**b2; o = random_oct(dim,.1); b = oct_to_box(mo,o); FLAG(mo); o2 = oct_of_box(mo,0,dim,b); FLAG(mo); b2 = oct_to_box(mo,o2); FLAG(mo); o3 = oct_of_box(mo,0,dim,b2); FLAG(mo); RESULT(check(o)); check(o2); if (oct_is_nleq(mo,o,o2) || oct_is_nleq(mo,o2,o3)) { ERROR("not included in"); print_oct("o",o); print_oct("o2",o2); print_oct("o3",o3); } if (oct_is_eq(mo,o2,o3)) RESULT('*'); if (flag==exact && oct_is_neq(mo,o2,o3)) ERROR("exact flag"); ap_interval_array_free(b,dim); ap_interval_array_free(b2,dim); oct_free(mo,o); oct_free(mo,o2); oct_free(mo,o3); } ENDLOOP; } /* ********************************* */ /* serialization */ /* ********************************* */ void test_serialize(void) { printf("\nserialization %s\n","(* expected)"); LOOP { size_t sz; oct_t *o, *o2; ap_membuf_t b; o = random_oct(10,.1); b = oct_serialize_raw(mo,o); FLAG(mo); o2 = oct_deserialize_raw(mo,b.ptr,&sz); FLAG(mo); RESULT(check(o)); check(o2); if (oct_is_nleq(mo,o,o2)) { ERROR("not included in"); print_oct("o",o); print_oct("o2",o2); } if (oct_is_eq(mo,o,o2)) RESULT('*'); if (flag==exact && oct_is_neq(mo,o,o2)) ERROR("exact flag"); if (b.size!=sz) ERROR("different size"); oct_free(mo,o); oct_free(mo,o2); free(b.ptr); } ENDLOOP; } /* ********************************* */ /* bound */ /* ********************************* */ void test_bound_dim(void) { printf("\nbound dimension %s\n",num_incomplete?"":"(* expected)"); LOOP { int dim = 6; int v = lrand48() % dim; oct_t *o; ap_abstract0_t *p; ap_interval_t *io, *ip; random_poly_oct(dim, .2, &o, &p); io = oct_bound_dimension(mo,o,v); FLAG(mo); ip = ap_abstract0_bound_dimension(mp,p,v); FLAG(mp); RESULT(check(o)); if (!oct_sat_interval(mo,o,v,io)) ERROR("not sat oct"); FLAG(mo); if (!ap_abstract0_sat_interval(mp,p,v,io)) { ERROR("not sat poly"); print_oct("o",o); print_poly("p",p); fprintf(stderr,"dim=%i\n",v); print_interval("io",io); print_interval("ip",ip); } FLAG(mp); if (!ap_interval_cmp(ip,io) && oct_sat_interval(mo,o,v,ip)) RESULT('*'); else if (ap_interval_cmp(ip,io)==-1) RESULT('.'); else ERROR("not included in"); if (flag==exact && ap_interval_cmp(ip,io)) ERROR("exact flag"); if (!oct_is_dimension_unconstrained(mo,o,v) && ap_abstract0_is_dimension_unconstrained(mp,p,v)) ERROR("not unconstrained"); oct_free(mo,o); ap_abstract0_free(mp,p); ap_interval_free(io); ap_interval_free(ip); } ENDLOOP; } void test_bound_linexpr(exprmode mode) { printf("\nbound %slinexpr %s\n",exprname[mode], num_incomplete?"":(mode<=expr_oct)?"(* expected)":"(*,. expected)"); LOOP { int dim = 6; oct_t *o; ap_abstract0_t *p; ap_linexpr0_t *e, *ee; ap_interval_t *io, *ip; random_poly_oct(dim, .2, &o, &p); e = random_linexpr(mode,dim); ee = random_from_linexpr(e); io = oct_bound_linexpr(mo,o,e); FLAG(mo); ip = ap_abstract0_bound_linexpr(mp,p,ee); FLAG(mp); if (!ap_interval_cmp(ip,io)) RESULT('*'); else if (ap_interval_cmp(ip,io)==-1) RESULT('.'); else ERROR("not included in"); if (flag==exact && ap_interval_cmp(ip,io)) ERROR("exact flag"); oct_free(mo,o); ap_abstract0_free(mp,p); ap_linexpr0_free(e); ap_linexpr0_free(ee); ap_interval_free(io); ap_interval_free(ip); } ENDLOOP; } void test_bound_texpr(void) { printf("\nbound texpr\n"); LOOP { int dim = 6; oct_t *o; ap_abstract0_t *p; ap_texpr0_t *e; ap_interval_t *io, *ip; random_poly_oct(dim, .2, &o, &p); e = random_texpr(dim,3); io = oct_bound_texpr(mo,o,e); FLAG(mo); ip = ap_abstract0_bound_texpr(mp,p,e); FLAG(mp); if (!ap_interval_cmp(ip,io)) RESULT('*'); else RESULT('.'); if (flag==exact && ap_interval_cmp(ip,io)) ERROR("exact flag"); oct_free(mo,o); ap_abstract0_free(mp,p); ap_texpr0_free(e); ap_interval_free(io); ap_interval_free(ip); } ENDLOOP; } /* ********************************* */ /* meet */ /* ********************************* */ void test_meet(void) { printf("\nmeet %s\n",num_incomplete ? "" : "(* expected)"); LOOP { int dim = 6; oct_t *o1, *o2, *o; ap_abstract0_t *p1, *p2, *p, *pp; random_poly_oct(dim, .2, &o1, &p1); random_poly_oct(dim, .2, &o2, &p2); o = oct_meet(mo,false,o1,o2); FLAG(mo); p = ap_abstract0_meet(mp,false,p1,p2); FLAG(mp); pp = poly_of_oct(o); RESULT(check(o)); check(o1); check(o2); if (oct_is_nleq(mo,o,o1) || oct_is_nleq(mo,o,o2)) { ERROR("not lower bound"); print_oct("o1",o1); print_oct("o2",o2); print_oct("o",o); print_poly("p",p); } if (!ap_abstract0_is_leq(mp,p,pp)) { ERROR("not poly approx"); print_oct("o1",o1); print_oct("o2",o2); print_oct("o",o); print_poly("p",p); } if (ap_abstract0_is_eq(mp,p,pp)) RESULT('*'); if (flag==exact && !ap_abstract0_is_eq(mp,p,pp)) ERROR("exact flag"); oct_free(mo,o); oct_free(mo,o1); oct_free(mo,o2); ap_abstract0_free(mp,p); ap_abstract0_free(mp,pp); ap_abstract0_free(mp,p1); ap_abstract0_free(mp,p2); } ENDLOOP; printf("\nmeet top %s\n","(* expected)"); LOOP { int dim = 8; oct_t *o1, *o2, *o, *oo; o1 = random_oct(dim,.2); o2 = oct_top(mo,0,dim); o = oct_meet(mo,false,o1,o2); oo = oct_meet(mo,false,o,o1); check(o1); check(o2); check(o); if (oct_is_neq(mo,o,o1)) { ERROR("not eq #1"); print_oct("o1",o1); print_oct("o",o); } else if (oct_is_neq(mo,o,oo)) { ERROR("not eq #2"); print_oct("o1",o1); print_oct("o",o); print_oct("oo",oo); } else RESULT('*'); oct_free(mo,o); oct_free(mo,o1); oct_free(mo,o2); oct_free(mo,oo); } ENDLOOP; printf("\nmeet bot %s\n","(* expected)"); LOOP { int dim = 8; oct_t *o1, *o2, *o; o1 = random_oct(dim,.2); o2 = oct_bottom(mo,0,dim); o = oct_meet(mo,false,o1,o2); check(o1); check(o2); check(o); if (!oct_is_bottom(mo,o)) { ERROR("not bottom"); print_oct("o1",o1); print_oct("o",o); } else RESULT('*'); oct_free(mo,o); oct_free(mo,o1); oct_free(mo,o2); } ENDLOOP; } #define NB_MEET 5 void test_meet_array(void) { printf("\nmeet array %s\n",num_incomplete ? "" : "(* expected)"); LOOP { int i, dim = 6; oct_t* o[NB_MEET], *oo; ap_abstract0_t* p[NB_MEET], *pp, *ppp; for (i=0;i=8) oct_close(pr,o); for (i=0;i=80)?AP_CONS_EQ: (lrand48()%100>=80)?AP_CONS_SUP: AP_CONS_SUPEQ, random_linexpr(mode,dim), NULL); arr.p[i] = random_from_lincons(ar.p[i]); } o1 = oct_meet_lincons_array(mo,false,o,&ar); FLAG(mo); p1 = ap_abstract0_meet_lincons_array(mp,false,p,&arr); FLAG(mp); p2 = poly_of_oct(o1); o2 = oct_of_poly(p1); check(o); RESULT(check(o1)); if (!ap_abstract0_is_leq(mp,p1,p2)) { ERROR("not included in"); ap_lincons0_array_fprint(stderr,&ar,NULL); print_poly("p",p); print_poly("p1",p1); print_poly("p2",p2); print_oct("o",o); print_oct("o1",o1); print_oct("o2",o2); } if (ap_abstract0_is_eq(mp,p1,p2)) RESULT('*'); else if (oct_is_eq(mo,o1,o2)) RESULT('x'); if (flag>=best && !ap_abstract0_is_eq(mp,p1,p2)) ERROR("best flag"); if (flag==exact && oct_is_neq(mo,o1,o2)) ERROR("exact flag"); oct_free(mo,o); oct_free(mo,o1); oct_free(mo,o2); ap_abstract0_free(mp,p); ap_abstract0_free(mp,p1); ap_abstract0_free(mp,p2); ap_lincons0_array_clear(&ar); ap_lincons0_array_clear(&arr); } ENDLOOP; } /* ********************************* */ /* saturation */ /* ********************************* */ void test_sat_lincons(exprmode mode) { printf("\nsaturate %slincons %s\n",exprname[mode], num_incomplete?"":(mode<=expr_oct)?"(* expected)":"(*,. expected)"); LOOP { size_t dim = 6; oct_t *o, *o1; ap_abstract0_t* p; ap_lincons0_t l, ll; ap_lincons0_array_t ar = ap_lincons0_array_make(1); bool ro,ro1,rp; random_poly_oct(dim, .1, &o, &p); l = ap_lincons0_make((lrand48()%100>=90)?AP_CONS_EQ: AP_CONS_SUPEQ, random_linexpr(mode,dim), NULL); ll = random_from_lincons(l); ar.p[0] = l; o1 = oct_meet_lincons_array(mo,false,o,&ar); FLAG(mo); RESULT(check(o1)); ro = oct_sat_lincons(mo,o,&l); FLAG(mo); ro1 = oct_sat_lincons(mo,o1,&l); FLAG(mo); rp = ap_abstract0_sat_lincons(mp,p,&ll); FLAG(mp); if (!ro1 && flag==exact) { ERROR("not sat #1"); ap_lincons0_fprint(stderr,&l,NULL); fprintf(stderr,"\n"); print_oct("o1",o1); } else if (ro && !ro1) { ERROR("not sat #2"); ap_lincons0_fprint(stderr,&l,NULL); fprintf(stderr,"\n"); print_oct("o",o); print_oct("o1",o1); } else if (ro && !rp) { ERROR("sat oct =/=> sat poly"); ap_lincons0_fprint(stderr,&l,NULL); fprintf(stderr,"\nsat oct = %s\nsat poly = %s\n", ro ? "T" : "F", rp ? "T" : "F" ); print_oct("o",o); } else if (ro==rp) RESULT('*'); else RESULT('.'); if (flag==exact && ro!=rp) ERROR("exact flag"); oct_free(mo,o); oct_free(mo,o1); ap_abstract0_free(mp,p); ap_lincons0_array_clear(&ar); ap_lincons0_clear(&ll); } ENDLOOP; } /* ********************************* */ /* join */ /* ********************************* */ void test_join(void) { printf("\njoin %s\n",num_incomplete?"":"(*,x expected)"); LOOP { int dim = 6; oct_t *o1, *o2, *o3, *o; ap_abstract0_t *p1, *p2, *p, *pp; random_poly_oct(dim, .1, &o1, &p1); random_poly_oct(dim, .1, &o2, &p2); o = oct_join(mo,false,o1,o2); FLAG(mo); p = ap_abstract0_join(mp,false,p1,p2); FLAG(mp); pp = poly_of_oct(o); o3 = oct_of_poly(p); RESULT(check(o)); check(o1); check(o2); if (oct_is_nleq(mo,o1,o) || oct_is_nleq(mo,o2,o)) { ERROR("not upper bound"); print_oct("o1",o1); print_oct("o2",o2); print_oct("o",o); print_poly("p",p); } if (!ap_abstract0_is_leq(mp,p,pp)) { ERROR("not poly approx"); print_oct("o1",o1); print_oct("o2",o2); print_oct("o",o); print_poly("p1",p1); print_poly("p2",p2); print_poly("p",p); } if (ap_abstract0_is_eq(mp,p,pp)) RESULT('*'); else if (oct_is_eq(mo,o,o3)) RESULT('x'); if (flag==exact && !ap_abstract0_is_eq(mp,p,pp)) ERROR("exact flag"); if (flag>=best && oct_is_neq(mo,o,o3)) ERROR("best flag"); oct_free(mo,o); oct_free(mo,o1); oct_free(mo,o2); oct_free(mo,o3); ap_abstract0_free(mp,p); ap_abstract0_free(mp,pp); ap_abstract0_free(mp,p1); ap_abstract0_free(mp,p2); } ENDLOOP; printf("\njoin bot %s\n",num_incomplete?"":"(* expected)"); LOOP { int dim = 8; oct_t *o1, *o2, *o, *oo; o1 = random_oct(dim,.2); o2 = oct_bottom(mo,0,dim); o = oct_join(mo,false,o1,o2); oo = oct_join(mo,false,o,o1); RESULT(check(o1)); check(o2); check(o); if (oct_is_neq(mo,o,o1)) { ERROR("not eq #1"); print_oct("o1",o1); print_oct("o",o); } else if (oct_is_neq(mo,o,oo)) { ERROR("not eq #2"); print_oct("o1",o1); print_oct("o",o); print_oct("oo",oo); } else RESULT('*'); oct_free(mo,o); oct_free(mo,o1); oct_free(mo,o2); oct_free(mo,oo); } ENDLOOP; printf("\njoin top %s\n",num_incomplete?"":"(* expected)"); LOOP { int dim = 8; oct_t *o1, *o2, *o; o1 = random_oct(dim,.2); o2 = oct_top(mo,0,dim); o = oct_join(mo,false,o1,o2); RESULT(check(o1)); check(o2); check(o); if (!oct_is_top(mo,o)) { ERROR("not top"); print_oct("o1",o1); print_oct("o",o); } else RESULT('*'); oct_free(mo,o); oct_free(mo,o1); oct_free(mo,o2); } ENDLOOP; } #define NB_JOIN 7 void test_join_array(void) { printf("\njoin array %s\n",num_incomplete?"":"(x,* expected)"); LOOP { int i, dim = 6; oct_t* o[NB_JOIN], *oo, *ooo; ap_abstract0_t* p[NB_JOIN], *pp, *ppp, *ps; for (i=0;i=best && oct_is_neq(mo,oo,ooo)) ERROR("best flag"); if (!ap_abstract0_is_eq(mp,ppp,ps)) { ERROR("poly_join_array not equivalent to poly_join"); for (i=0;i=8) oct_close(pr,o); for (i=0;i=80)?AP_GEN_LINE:AP_GEN_RAY); o1 = oct_add_ray_array(mo,false,o,&ar); FLAG(mo); p1 = ap_abstract0_add_ray_array(mp,false,p,&ar); FLAG(mp); p2 = poly_of_oct(o1); o2 = oct_of_poly(p1); check(o); RESULT(check(o1)); if (!ap_abstract0_is_leq(mp,p1,p2)) { ERROR("not included in"); ap_generator0_array_fprint(stderr,&ar,NULL); print_poly("p",p); print_poly("p1",p1); print_poly("p2",p2); } if (ap_abstract0_is_eq(mp,p1,p2)) RESULT('*'); else if (oct_is_eq(mo,o1,o2)) RESULT('x'); if (flag==exact && !ap_abstract0_is_eq(mp,p1,p2)) ERROR("exact flag"); if (flag>=best && oct_is_neq(mo,o1,o2)) ERROR("best flag"); oct_free(mo,o); oct_free(mo,o1); oct_free(mo,o2); ap_abstract0_free(mp,p); ap_abstract0_free(mp,p1); ap_abstract0_free(mp,p2); ap_generator0_array_clear(&ar); } ENDLOOP; } /* ********************************* */ /* dimension manipulation */ /* ********************************* */ void test_dimadd(void) { printf("\nadd dimensions\n"); LOOP { size_t i, dim = 15; oct_t *o1, *o2, *o3; ap_dimchange_t* a = ap_dimchange_alloc(0,3); ap_dimchange_t* r = ap_dimchange_alloc(0,a->realdim); o1 = random_oct(dim,.1); if (lrand48()%10>=8) oct_close(pr,o1); for (i=0;irealdim;i++) { a->dim[i] = lrand48()%3; if (i) a->dim[i] += a->dim[i-1]; r->dim[i] = a->dim[i]+i; } o2 = oct_add_dimensions(mo,false,o1,a,true); o3 = oct_remove_dimensions(mo,false,o2,r); RESULT(check(o1)); check(o2); check(o3); if (oct_is_neq(mo,o1,o3)) { ERROR("not eq"); ap_dimchange_fprint(stderr,a); ap_dimchange_fprint(stderr,r); print_oct("o1",o1); print_oct("o2",o2);print_oct("o3",o3); } oct_free(mo,o1); oct_free(mo,o2); oct_free(mo,o3); ap_dimchange_free(a); ap_dimchange_free(r); } ENDLOOP; } void test_dimrem(void) { printf("\nremove dimensions, forget\n"); LOOP { size_t i, dim = 15; oct_t *o1, *o2, *o3 ,*o4; ap_dimchange_t* a = ap_dimchange_alloc(0,3); ap_dimchange_t* r = ap_dimchange_alloc(0,a->realdim); o1 = random_oct(dim,.01); if (lrand48()%10>=8) oct_close(pr,o1); for (i=0;irealdim;i++) { r->dim[i] = lrand48()%3 + 1; if (i) r->dim[i] += r->dim[i-1]; a->dim[i] = r->dim[i]-i; } o2 = oct_remove_dimensions(mo,false,o1,r); o3 = oct_add_dimensions(mo,false,o2,a,false); o4 = oct_forget_array(mo,false,o1,r->dim,r->realdim,false); RESULT(check(o1)); check(o2); check(o3); check(o4); if (oct_is_neq(mo,o3,o4)) { ERROR("not eq"); ap_dimchange_fprint(stderr,r); ap_dimchange_fprint(stderr,a); print_oct("o1",o1); print_oct("o2",o2); print_oct("o3",o3); print_oct("o4",o4); } oct_free(mo,o1); oct_free(mo,o2); oct_free(mo,o3); oct_free(mo,o4); ap_dimchange_free(a); ap_dimchange_free(r); } ENDLOOP; } void test_permute(void) { printf("\npermute dimensions\n"); LOOP { size_t i, dim = 14; oct_t *o1, *o2, *o3; ap_dimperm_t* p = ap_dimperm_alloc(dim); ap_dimperm_t* q = ap_dimperm_alloc(dim); o1 = random_oct(dim,.1); if (lrand48()%10>=8) oct_close(pr,o1); /* random permutation */ ap_dimperm_set_id(p); for (i=0;isize-1;i++) { int j = i + (lrand48() % (p->size-i)); int a = p->dim[j]; p->dim[j] = p->dim[i]; p->dim[i] = a; } /* inverse permutation */ for (i=0;isize;i++) q->dim[p->dim[i]] = i; o2 = oct_permute_dimensions(mo,false,o1,p); o3 = oct_permute_dimensions(mo,false,o2,q); RESULT(check(o1)); check(o2); check(o3); if (oct_is_neq(mo,o1,o3)) { ERROR("not eq"); ap_dimperm_fprint(stderr,p); ap_dimperm_fprint(stderr,q); print_oct("o1",o1); print_oct("o2",o2); print_oct("o3",o3); } oct_free(mo,o1); oct_free(mo,o2); oct_free(mo,o3); ap_dimperm_free(p); ap_dimperm_free(q); } ENDLOOP; } void test_expand(void) { printf("\nexpand dimensions\n"); LOOP { size_t dim = 5; ap_dim_t d = lrand48() % dim; ap_dim_t dd[] = { d, dim, dim+1 }; size_t n = (lrand48() % 2) + 1; oct_t *o1, *o2, *o3; ap_abstract0_t *p1, *p2, *p3; random_poly_oct(dim, .1, &o1, &p1); o2 = oct_expand(mo,false,o1,d,n); FLAG(mo); o3 = oct_fold(mo,false,o2,dd,n+1); FLAG(mo); p2 = ap_abstract0_expand(mp,false,p1,d,n); FLAG(mp); p3 = poly_of_oct(o2); RESULT(check(o1)); check(o2); check(o3); check(o3); if (flag>=best && oct_is_neq(mo,o1,o3)) { ERROR("not eq"); fprintf(stderr,"dim %i expanded %i times\n",(int)d,(int)n); print_oct("o1",o1); print_oct("o2",o2); print_oct("o3",o3); } if (!ap_abstract0_is_leq(mp,p2,p3)) { ERROR("not leq"); fprintf(stderr,"dim %i expanded %i times\n",(int)d,(int)n); print_oct("o1",o1); print_oct("o2",o2); print_poly("p1",p1); print_poly("p2",p2); print_poly("p3",p3); } if (ap_abstract0_is_eq(mp,p2,p3)) RESULT('*'); if (flag==exact && !ap_abstract0_is_eq(mp,p2,p3)) ERROR("exact flag"); oct_free(mo,o1); oct_free(mo,o2); oct_free(mo,o3); ap_abstract0_free(mp,p1); ap_abstract0_free(mp,p2); ap_abstract0_free(mp,p3); } ENDLOOP; } void test_fold(void) { printf("\nfold dimensions\n"); LOOP { size_t dim = 6, i; ap_dim_t dd[3]; oct_t *o1, *o2; ap_abstract0_t *p1, *p2, *p3; random_poly_oct(dim, .1, &o1, &p1); dd[0] = lrand48() % (dim-3); dd[1] = dd[0] + 1 + (lrand48() % (dim-2-dd[0])); dd[2] = dd[1] + 1 + (lrand48() % (dim-1-dd[1])); o2 = oct_fold(mo,false,o1,dd,3); FLAG(mo); p2 = ap_abstract0_fold(mp,false,p1,dd,3); FLAG(mp); p3 = poly_of_oct(o2); RESULT(check(o1)); check(o2); if (!ap_abstract0_is_leq(mp,p2,p3)) { ERROR("not leq"); fprintf(stderr,"fold %i,%i,%i\n",(int)dd[0],(int)dd[1],(int)dd[2]); print_oct("o1",o1); print_oct("o2",o2); print_poly("p1",p1); print_poly("p2",p2); print_poly("p3",p3); } if (ap_abstract0_is_eq(mp,p2,p3)) RESULT('*'); if (flag==exact && !ap_abstract0_is_eq(mp,p2,p3)) ERROR("exact flag"); oct_free(mo,o1); oct_free(mo,o2); ap_abstract0_free(mp,p1); ap_abstract0_free(mp,p2); ap_abstract0_free(mp,p3); } ENDLOOP; } /* ********************************* */ /* widening */ /* ********************************* */ void test_widening(void) { printf("\nwidening\n"); LOOP { int dim = 8; oct_t *o1, *o2, *o; o1 = random_oct(dim,.1); o2 = random_oct(dim,.1); o = oct_widening(mo,o1,o2); RESULT(check(o)); if (oct_is_nleq(mo,o1,o) || oct_is_nleq(mo,o2,o)) { ERROR("not upper bound"); print_oct("o1",o1); print_oct("o2",o2); print_oct("o",o); } oct_free(mo,o1); oct_free(mo,o2); oct_free(mo,o); } ENDLOOP; printf("\nwidening convergence\n"); LOOP { int dim = 5, nb = 4*dim*dim; oct_t *o1 = random_oct(dim,.1); for (;nb>0;nb--) { oct_t* o2 = random_oct(dim,.1); oct_t* o = oct_widening(mo,o1,o2); oct_free(mo,o2); if (oct_is_leq(mo,o,o1)) { oct_free(mo,o); break; } oct_free(mo,o1); o1 = o; } RESULT(check(o1)); oct_free(mo,o1); if (!nb) ERROR("not converging in reasonable time"); } ENDLOOP; } void test_widening_thrs(void) { printf("\nwidening with thresholds\n"); LOOP { int dim = 8, n; oct_t *o1, *o2, *o; o1 = random_oct(dim,.1); o2 = random_oct(dim,.1); ap_scalar_t* t[10]; for (n=0;n<10;n++) t[n]=ap_scalar_alloc_set_double((lrand48()%30-15)*0.25); o = oct_widening_thresholds(mo,o1,o2,t,10); RESULT(check(o)); if (oct_is_nleq(mo,o1,o) || oct_is_nleq(mo,o2,o)) { ERROR("not upper bound"); print_oct("o1",o1); print_oct("o2",o2); print_oct("o",o); } oct_free(mo,o1); oct_free(mo,o2); oct_free(mo,o); for (n=0;n<10;n++) ap_scalar_free(t[n]); } ENDLOOP; printf("\nwidening with thresholds convergence\n"); LOOP { int dim = 5, nb = 4*dim*dim*10, n; oct_t *o1 = random_oct(dim,.1); ap_scalar_t* t[10]; for (n=0;n<10;n++) t[n]=ap_scalar_alloc_set_double((lrand48()%30-15)*0.25); for (;nb>0;nb--) { oct_t* o2 = random_oct(dim,.1); oct_t* o = oct_widening_thresholds(mo,o1,o2,t,10); oct_free(mo,o2); if (oct_is_leq(mo,o,o1)) { oct_free(mo,o); break; } oct_free(mo,o1); o1 = o; } RESULT(check(o1)); oct_free(mo,o1); for (n=0;n<10;n++) ap_scalar_free(t[n]); if (!nb) ERROR("not converging in reasonable time"); } ENDLOOP; } /* ********************************* */ /* narrowing */ /* ********************************* */ void test_narrowing(void) { printf("\nnarrowing\n"); LOOP { int dim = 8; oct_t *o1, *o2, *o, *oo; o1 = random_oct(dim,.01); o2 = random_oct(dim,.01); o = oct_narrowing(mo,o1,o2); oo = oct_meet(mo,false,o1,o2); RESULT(check(o)); if (oct_is_nleq(mo,o,o1) || oct_is_nleq(mo,oo,o)) { ERROR("not decreasing"); print_oct("o1",o1); print_oct("o2",o2); print_oct("o",o); print_oct("oo",oo); } oct_free(mo,o1); oct_free(mo,o2); oct_free(mo,o); oct_free(mo,oo); } ENDLOOP; printf("\nwidening narrowing\n"); LOOP { int dim = 5, nb = 4*dim*dim; oct_t *o1 = random_oct(dim,.03); for (;nb>0;nb--) { oct_t* o2 = random_oct(dim,.03); oct_t* o = oct_narrowing(mo,o1,o2); oct_free(mo,o2); if (oct_is_leq(mo,o,o1)) { oct_free(mo,o); break; } oct_free(mo,o1); o1 = o; } RESULT(check(o1)); oct_free(mo,o1); if (!nb) ERROR("not converging in reasonable time"); } ENDLOOP; } /* ********************************* */ /* assignments / substitutions */ /* ********************************* */ void test_assign(int subst, exprmode mode) { printf("\n%s %slinexpr %s\n", subst ? "subst" : "assign", exprname[mode], num_incomplete?"":mode==expr_unary ? "(* expected)" : ""); LOOP { size_t dim = 6; ap_dim_t d = lrand48()%dim; oct_t *o, *o1, *o2; ap_abstract0_t *p, *p1, *p2; ap_linexpr0_t* l = random_linexpr(mode,dim); ap_linexpr0_t* ll = random_from_linexpr(l); random_poly_oct(dim, .1, &o, &p); if (lrand48()%10>=5) oct_close(pr,o); o1 = subst ? oct_substitute_linexpr_array(mo,false,o,&d,&l,1,NULL) : oct_assign_linexpr_array(mo,false,o,&d,&l,1,NULL); FLAG(mo); p1 = subst ? ap_abstract0_substitute_linexpr(mp,false,p,d,ll,NULL) : ap_abstract0_assign_linexpr(mp,false,p,d,ll,NULL);; FLAG(mp); p2 = poly_of_oct(o1); o2 = oct_of_poly(p1); RESULT(check(o1)); if (!ap_abstract0_is_leq(mp,p1,p2)) { ERROR("not included in"); fprintf(stderr,"x%i %s ",(int)d,subst?"->":"<-"); ap_linexpr0_fprint(stderr,l,NULL); fprintf(stderr," / "); ap_linexpr0_fprint(stderr,ll,NULL); fprintf(stderr,"\n"); print_poly("p",p); print_poly("p1",p1); print_poly("p2",p2); } if (ap_abstract0_is_eq(mp,p1,p2)) RESULT('*'); else if (oct_is_eq(mo,o1,o2)) RESULT('x'); if (flag==exact && !ap_abstract0_is_eq(mp,p1,p2)) ERROR("exact flag"); if (flag>=best && oct_is_neq(mo,o1,o2)) ERROR("best flag"); oct_free(mo,o); oct_free(mo,o1); oct_free(mo,o2); ap_abstract0_free(mp,p); ap_abstract0_free(mp,p1); ap_abstract0_free(mp,p2); ap_linexpr0_free(l); ap_linexpr0_free(ll); } ENDLOOP; } #define NB_ASSIGN 3 void test_par_assign(int subst, exprmode mode) { printf("\nparallel %s %slinexpr %s\n",subst ? "subst" : "assign", num_incomplete?"":exprname[mode],mode==expr_unary ? "(* expected)" : ""); LOOP { size_t dim = 6, i, j, k; ap_dim_t d[NB_ASSIGN]; oct_t *o, *o1, *o2; ap_abstract0_t *p, *p1, *p2; ap_linexpr0_t *l[NB_ASSIGN], *ll[NB_ASSIGN]; random_poly_oct(dim, .1, &o, &p); for (i=0;i=8) oct_close(pr,o); o1 = subst ? oct_substitute_linexpr_array(mo,false,o,d,l,NB_ASSIGN,NULL) : oct_assign_linexpr_array(mo,false,o,d,l,NB_ASSIGN,NULL); FLAG(mo); p1 = subst ? ap_abstract0_substitute_linexpr_array(mp,false,p,d,ll,NB_ASSIGN,NULL) : ap_abstract0_assign_linexpr_array(mp,false,p,d,ll,NB_ASSIGN,NULL); FLAG(mp); p2 = poly_of_oct(o1); o2 = oct_of_poly(p1); RESULT(check(o1)); if (!ap_abstract0_is_leq(mp,p1,p2)) { ERROR("not included in"); for (i=0;i":"<-"); ap_linexpr0_fprint(stderr,l[i],NULL); fprintf(stderr," / "); ap_linexpr0_fprint(stderr,ll[i],NULL); fprintf(stderr,"\n"); } print_poly("p",p); print_poly("p1",p1); print_poly("p2",p2); } else if (ap_abstract0_is_eq(mp,p1,p2)) RESULT('*'); else if (oct_is_eq(mo,o1,o2)) RESULT('x'); if (flag==exact && !ap_abstract0_is_eq(mp,p1,p2)) ERROR("exact flag"); if (flag>=best && oct_is_neq(mo,o1,o2)) ERROR("best flag"); oct_free(mo,o); oct_free(mo,o1); oct_free(mo,o2); ap_abstract0_free(mp,p); ap_abstract0_free(mp,p1); ap_abstract0_free(mp,p2); for (i=0;i=8) oct_close(pr,o); o1 = subst ? oct_substitute_linexpr_array(mo,false,o,&d,&l,1,NULL) : oct_assign_linexpr_array(mo,false,o,&d,&l,1,NULL); FLAG(mo); o2 = subst ? oct_substitute_linexpr_array(mo,false,o,&d,&l,1,NULL) : oct_assign_linexpr_array(mo,false,o,&d,&l,1,NULL); FLAG(mo); check(o1); check(o2); if (oct_is_eq(mo,o1,o2)) RESULT('='); else if (oct_is_leq(mo,o1,o2)) RESULT('<'); else if (oct_is_leq(mo,o2,o1)) RESULT('>'); else RESULT('.'); if (flag==exact && oct_is_neq(mo,o1,o2)) ERROR("exact flag"); oct_free(mo,o); oct_free(mo,o1); oct_free(mo,o2); ap_linexpr0_free(l); } ENDLOOP; } void test_assign_texpr(int subst) { printf("\n%s texpr\n", subst ? "subst" : "assign"); LOOP { size_t dim = 5; ap_dim_t d = lrand48()%dim; oct_t *o, *o1, *o2; ap_abstract0_t *p, *p1, *p2; ap_texpr0_t* e = random_texpr(dim,3); random_poly_oct(dim, .1, &o, &p); if (lrand48()%10>=5) oct_close(pr,o); o1 = subst ? oct_substitute_texpr_array(mo,false,o,&d,&e,1,NULL) : oct_assign_texpr_array(mo,false,o,&d,&e,1,NULL); FLAG(mo); p1 = subst ? ap_abstract0_substitute_texpr_array(mp,false,p,&d,&e,1,NULL) : ap_abstract0_assign_texpr_array(mp,false,p,&d,&e,1,NULL);; FLAG(mp); p2 = poly_of_oct(o1); o2 = oct_of_poly(p1); RESULT(check(o1)); if (ap_abstract0_is_eq(mp,p1,p2)) RESULT('*'); else if (oct_is_eq(mo,o1,o2)) RESULT('x'); else RESULT('.'); if (flag==exact && !ap_abstract0_is_eq(mp,p1,p2)) ERROR("exact flag"); if (flag>=best && oct_is_neq(mo,o1,o2)) ERROR("best flag"); oct_free(mo,o); oct_free(mo,o1); oct_free(mo,o2); ap_abstract0_free(mp,p); ap_abstract0_free(mp,p1); ap_abstract0_free(mp,p2); ap_texpr0_free(e); } ENDLOOP; } /* ********************************* */ /* hash */ /* ********************************* */ void test_hash(void) { printf("\nhash\n"); LOOP { size_t dim = 5; oct_t *oa,*ob; int ra,rb; oa = random_oct(dim,.1); ra = oct_hash(mo,oa); ob = oct_copy(mo,oa); rb = oct_hash(mo,ob); RESULT('.'); if (ra!=rb) ERROR("different hash"); oct_free(mo,oa); oct_free(mo,ob); } ENDLOOP; } /* ********************************* */ /* main */ /* ********************************* */ void tests(int algo) { int i; for (i=0;ioption.funopt[i].algorithm = algo; mp->option.funopt[i].algorithm = algo; } printf("\nstarting tests with algo=%i\n",algo); /* tests */ test_misc(); test_serialize(); test_closure(); test_incremental_closure(); test_polyhedra_conversion(); test_polyhedra_conversion2(); /* poly_check: F not normalized */ test_lincons_conversion(expr_oct); test_lincons_conversion(expr_lin); test_lincons_conversion(expr_interv); test_generator_conversion(); test_box_conversion(); test_bound_dim(); test_bound_linexpr(expr_oct); test_bound_linexpr(expr_lin); test_bound_linexpr(expr_interv); test_bound_texpr(); test_meet(); test_meet_array(); test_join(); test_join_array(); test_add_ray(); test_add_lincons(expr_oct); test_add_lincons(expr_lin); test_add_lincons(expr_interv); test_sat_lincons(expr_oct); test_sat_lincons(expr_lin); test_sat_lincons(expr_interv); test_dimadd(); test_dimrem(); test_permute(); test_expand(); test_fold(); test_widening(); test_widening_thrs(); test_narrowing(); test_assign(0,expr_unary); test_assign(0,expr_lin); test_assign(0,expr_interv); test_par_assign(0,expr_unary); test_par_assign(0,expr_lin); test_par_assign(0,expr_interv); test_par_assign2(0,expr_unary); test_par_assign2(0,expr_lin); test_par_assign2(0,expr_interv); test_assign(1,expr_unary); test_assign(1,expr_lin); test_assign(1,expr_interv); test_par_assign(1,expr_unary); test_par_assign(1,expr_lin); test_par_assign(1,expr_interv); test_par_assign2(1,expr_unary); test_par_assign2(1,expr_lin); test_par_assign2(1,expr_interv); test_assign_texpr(0); test_assign_texpr(1); test_hash(); } int main(int argc, const char** argv) { long int seed; int i; seed = time(NULL); for (i=1;ioption.funopt[i].flag_exact_wanted = true; mo->option.funopt[i].flag_best_wanted = true; mp->option.funopt[i].flag_exact_wanted = true; mp->option.funopt[i].flag_best_wanted = true; } for (i=0;ioption.abort_if_exception[i] = true; mp->option.abort_if_exception[i] = true; } pr = oct_init_from_manager(mo,0,0); pk = pk_manager_get_internal(mp); pk_set_max_coeff_size(pk,0); pk_set_approximate_max_coeff_size(pk,0); info(); tests(0); tests(-1); /* quit */ ap_manager_free(mo); ap_manager_free(mp); if (error_) printf("\n%i error(s)!\n",error_); else printf("\nall tests passed\n"); return 0; } apron-dist-0.9.10/apron/box/0000750014525101416610000000000011252216517015455 5ustar bjeannetpopartapron-dist-0.9.10/apron/box/box_representation.c0000640014525101416610000001767010760562320021546 0ustar bjeannetpopart/* ********************************************************************** */ /* box_representation.c: general management */ /* ********************************************************************** */ #include #include #include "box_internal.h" #include "box_representation.h" /* ********************************************************************** */ /* Internal functions */ /* ********************************************************************** */ box_t* box_alloc(size_t intdim, size_t realdim) { box_t* itv = malloc(sizeof(box_t)); itv->p = NULL; itv->intdim = intdim; itv->realdim = realdim; return itv; } void box_init(box_t* a) { size_t i; size_t nbdims = a->intdim + a->realdim; assert(a->p==NULL); a->p = itv_array_alloc(nbdims+1); /* Add an unused dimension to differentiate empty and top values in dimension 0+0 */ } void box_set_bottom(box_t* a) { if (a->p){ itv_array_free(a->p,a->intdim+a->realdim+1); a->p = NULL; } } void box_set_top(box_t* a) { size_t i; size_t nbdims; nbdims = a->intdim + a->realdim; if (a->p==NULL){ box_init(a); }; for (i=0; ip[i]); } } void box_set(box_t* a, box_t* b) { size_t i; size_t nbdims; if (b->p==NULL) return; nbdims = b->intdim + b->realdim; if (a->p==NULL){ box_init(a); }; for (i=0; ip[i],b->p[i]); } } /* ********************************************************************** */ /* 1. Memory */ /* ********************************************************************** */ /* Return a copy of an abstract value, on which destructive update does not affect the initial value. */ box_t* box_copy(ap_manager_t* man, box_t* a) { size_t i; size_t nbdims = a->intdim+a->realdim; box_t* b = box_alloc(a->intdim,a->realdim); if (a->p){ b->p = malloc((nbdims+1)*sizeof(itv_t)); for (i=0; ip[i],a->p[i]); } itv_init(b->p[nbdims]); /* Add an unused dimension to differentiate empty and top values in dimension 0+0 */ } man->result.flag_best = true; man->result.flag_exact = true; return b; } /* Free all the memory used by the abstract value */ void box_free(ap_manager_t* man, box_t* a) { if (a->p){ itv_array_free(a->p,a->intdim+a->realdim+1); a->p = NULL; } free(a); } /* Return the abstract size of an abstract value (see ap_manager_t) */ size_t box_size(ap_manager_t* man, box_t* a) { return 2*(a->intdim+a->realdim); } /* ********************************************************************** */ /* 2. Control of internal representation */ /* ********************************************************************** */ /* Minimize the size of the representation of a. This may result in a later recomputation of internal information. */ void box_minimize(ap_manager_t* man, box_t* a) { man->result.flag_best = true; man->result.flag_exact = true; return; } /* Put the abstract value in canonical form. (not yet clear definition) */ void box_canonicalize(ap_manager_t* man, box_t* a) { man->result.flag_best = true; man->result.flag_exact = true; return; } /* Return an hash code */ int box_hash(ap_manager_t* man, box_t* a) { int i,dec,size,res; size = a->intdim +a->realdim; res = size * 2999; if (a->p!=NULL){ for (i=0; ip[i]); } } man->result.flag_best = true; man->result.flag_exact = true; return res; } /* Perform some transformation on the abstract value, guided by the field algorithm. The transformation may lose information. The argument "algorithm" overrides the field algorithm of the structure of type foption_t associated to box_approximate (commodity feature). */ void box_approximate(ap_manager_t* man, box_t* a, int algorithm) { man->result.flag_best = true; man->result.flag_exact = true; return; } /* ********************************************************************** */ /* 3. Printing */ /* ********************************************************************** */ /* Print the abstract value in a pretty way, using function name_of_dim to name dimensions */ void box_fprint(FILE* stream, ap_manager_t* man, box_t* a, char** name_of_dim) { size_t i; size_t nbdims = a->intdim + a->realdim; fprintf(stream,"interval of dim (%ld,%ld):", (long)a->intdim,(long)a->realdim); if (a->p){ fprintf(stream,"\n"); for(i=0; ip[i]); fprintf(stream,"\n"); } } else { fprintf(stream,nbdims>0 ? " bottom\n" : "top\n"); } } /* Dump the internal representation of an abstract value, for debugging purposes */ void box_fdump(FILE* stream, ap_manager_t* man, box_t* a) { size_t i; size_t nbdims = a->intdim + a->realdim; fprintf(stream,"interval of dim (%ld,%ld):", (long)a->intdim,(long)a->realdim); if (a->p){ fprintf(stream,"\n"); for(i=0; ip[i]); fprintf(stream,"\n"); } } else { fprintf(stream, nbdims>0 ? " bottom\n" : "top\n"); } } /* Print the difference between a1 (old value) and a2 (new value), using function name_of_dim to name dimensions. The meaning of difference is library dependent. */ void box_fprintdiff(FILE* stream, ap_manager_t* man, box_t* a, box_t* b, char** name_of_dim) { size_t i; size_t nbdims; char* str; nbdims = a->intdim + a->realdim; fprintf(stream,"diff of 2 intervals of dim (%ld,%ld)", (long)a->intdim,(long)b->intdim); if (box_is_eq(man,a,b)){ fprintf(stream," : none\n"); } else { /* we are sure that nbdims>0 */ if (a->p==0){ fprintf(stream,"\nbottom =>\n"); box_fprint(stream,man,b,name_of_dim); } else if (b->p==0){ fprintf(stream,"\n"); box_fprint(stream,man,a,name_of_dim); fprintf(stream,"=> bottom\n"); } else { bound_t bound; bound_init(bound); for(i=0; ip[i]->inf, b->p[i]->inf); int sgn2 = bound_cmp(a->p[i]->sup, b->p[i]->sup); if (sgn1!=0 || sgn2!=0){ if (name_of_dim) fprintf(stream,"%8s in ",name_of_dim[i]); else fprintf(stream,"x%ld in ", (long)i); itv_fprint(stream,a->p[i]); fprintf(stream," => "); str = sgn1>0 ? "-[" : ( sgn1<0 ? "+[" : "[=, " ); fprintf(stream,str); if (sgn1!=0){ bound_neg(bound,b->p[i]->inf); bound_fprint(stream,bound); fprintf(stream,", "); } if (sgn2!=0){ bound_fprint(stream,b->p[i]->sup); } str = sgn2>0 ? "]+" : ( sgn2<0 ? "]-" : "=]" ); fprintf(stream,"%s\n",str); } else { if (name_of_dim) fprintf(stream,"%8s in [=,=]\n",name_of_dim[i]); else fprintf(stream,"x%ld in [=,=]\n",(long)i); } } bound_clear(bound); } } } /* ********************************************************************** */ /* 4. Serialization */ /* ********************************************************************** */ /* Allocate a memory buffer (with malloc), output the abstract value in raw binary format to it and return a pointer on the memory buffer and the size of bytes written. It is the user responsability to free the memory afterwards (with free). */ ap_membuf_t box_serialize_raw(ap_manager_t* man, box_t* a) { ap_membuf_t buf; ap_manager_raise_exception(man,AP_EXC_NOT_IMPLEMENTED,AP_FUNID_SERIALIZE_RAW,""); buf.ptr = NULL; buf.size = 0; return buf; } /* Return the abstract value read in raw binary format from the input stream and store in size the number of bytes read */ box_t* box_deserialize_raw(ap_manager_t* man, void* ptr) { ap_manager_raise_exception(man,AP_EXC_NOT_IMPLEMENTED,AP_FUNID_DESERIALIZE_RAW,""); return NULL; } apron-dist-0.9.10/apron/box/box_internal.h0000640014525101416610000000246610564602263020325 0ustar bjeannetpopart/* ********************************************************************** */ /* box_internal.h: abstract lattice of intervals */ /* ********************************************************************** */ #ifndef _BOX_INTERNAL_H_ #define _BOX_INTERNAL_H_ #include #include #include "box_config.h" #include "itv.h" #ifdef __cplusplus extern "C" { #endif struct box_t { itv_t* p; size_t intdim; size_t realdim; }; ap_manager_t* box_manager_alloc(void); typedef struct box_internal_t { itv_internal_t* itv; itv_t bound_linexpr_internal_itv; itv_t bound_linexpr_internal_itv2; ap_interval_t* sat_interval_interval; itv_t sat_lincons_itv; num_t sat_lincons_num; itv_t bound_linexpr_itv; itv_t meet_lincons_internal_itv; itv_t meet_lincons_internal_itv2; itv_t meet_lincons_internal_itv3; bound_t meet_lincons_internal_bound; } box_internal_t; void box_internal_init(box_internal_t* intern); void box_internal_clear(box_internal_t* intern); box_internal_t* box_internal_alloc(void); void box_internal_free(box_internal_t* intern); /* Initializes some fields of pk from manager */ static inline box_internal_t* box_init_from_manager(ap_manager_t* man, ap_funid_t funid) { box_internal_t* itv = (box_internal_t*)man->internal; return itv; } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/box/box_meetjoin.c0000640014525101416610000003306711217702126020312 0ustar bjeannetpopart/* ********************************************************************** */ /* box_meetjoin.c */ /* ********************************************************************** */ #include #include #include "box_internal.h" #include "box_representation.h" #include "box_constructor.h" #include "box_meetjoin.h" #include "itv_linexpr.h" #include "itv_linearize.h" /* ============================================================ */ /* Meet and Join */ /* ============================================================ */ box_t* box_meet(ap_manager_t* man, bool destructive, box_t* a1, box_t* a2) { size_t i; bool exc; size_t nbdims; box_t* res; box_internal_t* intern = (box_internal_t*)man->internal; man->result.flag_best = true; man->result.flag_exact = true; res = destructive ? a1 : box_alloc(a1->intdim,a1->realdim); if (a1->p==NULL || a2->p==NULL){ box_set_bottom(res); return res; } if (!destructive){ box_init(res); } nbdims = a1->intdim + a1->realdim; for (i=0; iitv,res->p[i],a1->p[i],a2->p[i]); if (exc){ box_set_bottom(res); break; } } return res; } box_t* box_join(ap_manager_t* man, bool destructive, box_t* a1, box_t* a2) { size_t i; size_t nbdims; box_t* res; man->result.flag_best = true; man->result.flag_exact = false; res = destructive ? a1 : box_alloc(a1->intdim,a1->realdim); if (a1->p==NULL){ if (a2->p!=NULL){ man->result.flag_exact = true; box_set(res,a2); } return res; } else if (a2->p==NULL){ man->result.flag_exact = true; if (!destructive) box_set(res,a1); return res; } man->result.flag_exact = false; if (!destructive){ box_init(res); } nbdims = a1->intdim + a2->realdim; for (i=0; ip[i],a1->p[i],a2->p[i]); } return res; } box_t* box_meet_array(ap_manager_t* man, box_t** tab, size_t size) { size_t i; box_t* res; res = box_copy(man,tab[0]); for (i=1;ip==NULL) break; } man->result.flag_best = true; man->result.flag_exact = true; return res; } box_t* box_join_array(ap_manager_t* man, box_t** tab, size_t size) { size_t i; box_t* res; res = box_copy(man,tab[0]); for (i=1;iresult.flag_best = true; man->result.flag_exact = false; return res; } /* ============================================================ */ /* Add_ray_array */ /* ============================================================ */ /* Generalized time elapse operator */ void box_add_ray(box_internal_t* intern, box_t* a, ap_generator0_t* gen) { size_t i; int sgn; ap_coeff_t* coeff; ap_dim_t dim; ap_linexpr0_t* expr; assert(gen->gentyp != AP_GEN_VERTEX); if (a->p==NULL){ box_set_bottom(a); return; } expr = gen->linexpr0; ap_linexpr0_ForeachLinterm(expr,i,dim,coeff){ assert(coeff->discr==AP_COEFF_SCALAR); ap_scalar_t* scalar = coeff->val.scalar; sgn = ap_scalar_sgn(scalar); if (sgn!=0){ if (sgn>0 || gen->gentyp==AP_GEN_LINE){ bound_set_infty(a->p[dim]->sup,1); } if (sgn<0 || gen->gentyp==AP_GEN_LINE){ bound_set_infty(a->p[dim]->inf,1); } } } } box_t* box_add_ray_array(ap_manager_t* man, bool destructive, box_t* a, ap_generator0_array_t* array) { size_t i; box_t* res; box_internal_t* intern = (box_internal_t*)man->internal; man->result.flag_best = true; man->result.flag_exact = false; res = destructive ? a : box_copy(man,a); if (a->p==NULL){ man->result.flag_exact = true; return res; } for (i=0;isize; i++){ box_add_ray(intern,res,&array->p[i]); } return res; } /* ============================================================ */ /* Meet_lincons */ /* ============================================================ */ /* Meet of an abstract value with a constraint */ bool box_meet_lincons_internal(box_internal_t* intern, box_t* a, itv_lincons_t* cons) { size_t nbcoeffs,nbdims; ap_dim_t dim; size_t i; itv_ptr pitv; itv_linexpr_t* expr; bool *peq; bool equality,change,globalchange; bool exc; assert(cons->constyp == AP_CONS_EQ || cons->constyp == AP_CONS_SUPEQ || cons->constyp == AP_CONS_SUP); if (a->p==NULL){ box_set_bottom(a); return false; } nbdims = a->intdim + a->realdim; expr = &cons->linexpr; globalchange = false; /* Iterates on coefficients */ nbcoeffs = 0; itv_set_int(intern->meet_lincons_internal_itv2,0); itv_linexpr_ForeachLinterm(expr,i,dim,pitv,peq){ nbcoeffs++; /* 1. We decompose the expression e = ax+e' */ /* We save the linterm */ itv_swap(intern->meet_lincons_internal_itv2,pitv); equality = *peq; *peq = true; /* 2. evaluate e' */ itv_eval_linexpr(intern->itv, intern->meet_lincons_internal_itv3,expr,a->p); change = false; if (!itv_is_top(intern->meet_lincons_internal_itv3)){ if (equality){ int sgn = bound_sgn(intern->meet_lincons_internal_itv2->sup); if (sgn!=0){ /* If we have ax+e' >= 0 with a>0 we can deduce that x>=-e'/a, or x>= inf(-e'/a) If we have ax+e' >= 0 with a<0 we can deduce that -ax<=e', or x<= sup(e'/-a) If we have ax+e'=0 we can deduce x=-e'/a, or inf(-e'/a)<= x <= sup(-e'/a) */ if (sgn>0 || cons->constyp == AP_CONS_EQ){ /* If we have a>0, we compute sup(e')/a=sup(e'/a)=-inf(-e'/a) If we have a<0, we compute -inf(e')/(-a)=-inf(-e'/a) */ if (sgn>0){ bound_div(intern->meet_lincons_internal_bound, intern->meet_lincons_internal_itv3->sup, intern->meet_lincons_internal_itv2->sup); } else { bound_div(intern->meet_lincons_internal_bound, intern->meet_lincons_internal_itv3->inf, intern->meet_lincons_internal_itv2->inf); } /* We update the interval */ if (bound_cmp(intern->meet_lincons_internal_bound, a->p[dim]->inf)<0){ change = true; bound_set(a->p[dim]->inf, intern->meet_lincons_internal_bound); } } if (sgn<0 || cons->constyp == AP_CONS_EQ){ /* If we have a<0, we compute sup(e')/(-a)=sup(e'/-a) If we have a>0, we compute -inf(e')/a=-inf(e'/a)=sup(e'/-a) */ if (sgn<0){ bound_div(intern->meet_lincons_internal_bound, intern->meet_lincons_internal_itv3->sup, intern->meet_lincons_internal_itv2->inf); } else { bound_div(intern->meet_lincons_internal_bound, intern->meet_lincons_internal_itv3->inf, intern->meet_lincons_internal_itv2->sup); } /* We update the interval */ if (bound_cmp(intern->meet_lincons_internal_bound, a->p[dim]->sup)<0){ change = true; bound_set(a->p[dim]->sup, intern->meet_lincons_internal_bound); } } } } else { /* We have an interval */ /* - If we have [m;M]x+e' >= 0 with m>0, then [m,M]x>=inf(-e'), or [m,M]x>=-sup(e') so we need at least * if -sup(e')>=0: x>=-sup(e')/M * if -sup(e')<=0: x>=-sup(e')/m - If we have [m,M]x+e'<=0 with M<0, then [-M,-m]x>=inf(e') * inf(e')>=0: x>=inf(e')/-m * inf(e')<=0: x>=inf(e')/-M - If we have [m;M]x+e' >= 0 with M<0, then [-M,-m]x<=sup(e'), so we need at least * if sup(e')>=0: x<=sup(e')/-M * if sup(e')<=0: x<=sup(e')/-m - If we have [m,M]x+e'<=0 with m>0, then [m,M]x<=sup(-e') or [m,M]x<=-inf(e') * -inf(e')>=0: x<=inf(e')/-M * -inf(e')<=0: x<=inf(e')/-m */ int sgncoeff = bound_sgn(intern->meet_lincons_internal_itv2->inf)<0 ? 1 : ( bound_sgn(intern->meet_lincons_internal_itv2->sup)<0 ? -1 : 0 ); if (sgncoeff != 0){ int sgninf = bound_sgn(intern->meet_lincons_internal_itv3->inf); int sgnsup = bound_sgn(intern->meet_lincons_internal_itv3->sup); if (sgncoeff>0 || (cons->constyp==AP_CONS_EQ && sgncoeff<0)){ if (sgncoeff>0){ if (sgnsup<=0){ /* We compute sup(e')/M */ bound_div(intern->meet_lincons_internal_bound, intern->meet_lincons_internal_itv3->sup, intern->meet_lincons_internal_itv2->sup); } else { /* We compute sup(e')/m = (-sup(e'))/(-m) */ bound_neg(intern->meet_lincons_internal_bound, intern->meet_lincons_internal_itv3->sup); bound_div(intern->meet_lincons_internal_bound, intern->meet_lincons_internal_bound, intern->meet_lincons_internal_itv2->inf); } } else { bound_neg(intern->meet_lincons_internal_bound, intern->meet_lincons_internal_itv3->inf); if (sgninf<=0){ /* We compute inf(e')/m = (-inf(e'))/(-m) */ bound_div(intern->meet_lincons_internal_bound, intern->meet_lincons_internal_bound, intern->meet_lincons_internal_itv2->inf); } else { /* We compute inf(e')/M) = - (-inf(e'))/M */ bound_div(intern->meet_lincons_internal_bound, intern->meet_lincons_internal_bound, intern->meet_lincons_internal_itv2->sup); bound_neg(intern->meet_lincons_internal_bound, intern->meet_lincons_internal_bound); } } /* We update the interval */ if (bound_cmp(intern->meet_lincons_internal_bound, a->p[dim]->inf)<0){ change = true; bound_set(a->p[dim]->inf, intern->meet_lincons_internal_bound); } } if (sgncoeff<0 || (cons->constyp==AP_CONS_EQ && sgncoeff>0)){ if (sgncoeff<0){ if (sgnsup>=0){ /* We compute sup(e')/-M */ bound_neg(intern->meet_lincons_internal_bound, intern->meet_lincons_internal_itv2->sup); bound_div(intern->meet_lincons_internal_bound, intern->meet_lincons_internal_itv3->sup, intern->meet_lincons_internal_bound); } else { /* We compute sup(e')/-m */ bound_div(intern->meet_lincons_internal_bound, intern->meet_lincons_internal_itv3->sup, intern->meet_lincons_internal_itv2->inf); } } else { if (sgninf>=0){ /* We compute -inf(e')/M */ bound_div(intern->meet_lincons_internal_bound, intern->meet_lincons_internal_itv3->inf, intern->meet_lincons_internal_itv2->sup); } else { /* We compute -inf(e')/m = inf(e')/(-m) */ bound_neg(intern->meet_lincons_internal_bound, intern->meet_lincons_internal_itv3->inf); bound_div(intern->meet_lincons_internal_bound, intern->meet_lincons_internal_bound, intern->meet_lincons_internal_itv2->inf); } } /* We update the interval */ if (bound_cmp(intern->meet_lincons_internal_bound, a->p[dim]->sup)<0){ change = true; bound_set(a->p[dim]->sup, intern->meet_lincons_internal_bound); } } } } } itv_swap(intern->meet_lincons_internal_itv2,pitv); *peq = equality; if (change){ globalchange = true; exc = itv_canonicalize(intern->itv,a->p[dim],dimintdim); if (exc){ box_set_bottom(a); goto _box_meet_box_lincons_exit; } } } if (nbcoeffs==0){ /* Maybe an unsatisfiable constraint */ bool unsat; int sgnsup = bound_sgn(expr->cst->sup); int sgninf = expr->equality ? sgnsup : -bound_sgn(expr->cst->inf); switch(cons->constyp){ case AP_CONS_EQ: unsat = sgnsup < 0 || sgninf > 0; break; case AP_CONS_SUPEQ: unsat = sgnsup<0; break; case AP_CONS_SUP: unsat = (sgnsup<=0); break; default: abort(); } if (unsat){ box_set_bottom(a); globalchange = true; } else globalchange = false; } _box_meet_box_lincons_exit: return globalchange; } box_t* box_meet_lincons_array(ap_manager_t* man, bool destructive, box_t* a, ap_lincons0_array_t* array) { box_t* res; size_t kmax; itv_lincons_array_t tlincons; box_internal_t* intern = (box_internal_t*)man->internal; res = destructive ? a : box_copy(man,a); if (a->p==NULL){ man->result.flag_best = true; man->result.flag_exact = true; } else { man->result.flag_best = array->size==1; man->result.flag_exact = false; kmax = man->option.funopt[AP_FUNID_MEET_LINCONS_ARRAY].algorithm; if (kmax<1) kmax=2; itv_lincons_array_init(&tlincons,array->size); itv_lincons_array_set_ap_lincons0_array(intern->itv,&tlincons,array); tbool_t tb = itv_lincons_array_reduce_integer(intern->itv,&tlincons,a->intdim); if (tb==tbool_false){ goto _box_meet_lincons_array_bottom; } itv_boxize_lincons_array(intern->itv, res->p,NULL, &tlincons,res->p,a->intdim,kmax,false); if (itv_is_bottom(intern->itv,res->p[0])){ _box_meet_lincons_array_bottom: box_set_bottom(res); } itv_lincons_array_clear(&tlincons); } return res; } box_t* box_meet_tcons_array(ap_manager_t* man, bool destructive, box_t* a, ap_tcons0_array_t* array) { box_t* res; size_t kmax; box_internal_t* intern = (box_internal_t*)man->internal; itv_lincons_array_t tlincons; res = destructive ? a : box_copy(man,a); if (a->p==NULL){ man->result.flag_best = true; man->result.flag_exact = true; } else { man->result.flag_best = array->size==1; man->result.flag_exact = false; kmax = man->option.funopt[AP_FUNID_MEET_TCONS_ARRAY].algorithm; if (kmax<1) kmax=2; itv_lincons_array_init(&tlincons,array->size); itv_intlinearize_ap_tcons0_array(intern->itv,&tlincons, array,res->p,res->intdim); tbool_t tb = itv_lincons_array_reduce_integer(intern->itv,&tlincons,a->intdim); if (tb==tbool_false){ goto _box_meet_tcons_array_bottom; } itv_boxize_lincons_array(intern->itv, res->p,NULL, &tlincons,res->p,a->intdim,kmax,false); if (itv_is_bottom(intern->itv,res->p[0])){ _box_meet_tcons_array_bottom: box_set_bottom(res); } itv_lincons_array_clear(&tlincons); } return res; } apron-dist-0.9.10/apron/box/box_resize.c0000640014525101416610000000514310723557216020004 0ustar bjeannetpopart/* ********************************************************************** */ /* box_resize.c */ /* ********************************************************************** */ #include "box_internal.h" #include "box_resize.h" box_t* box_add_dimensions(ap_manager_t* man, bool destructive, box_t* a, ap_dimchange_t* dimchange, bool project) { box_t* res; size_t size; size_t dimsup; int i,k; man->result.flag_best = true; man->result.flag_exact = true; res = destructive ? a : box_copy(man,a); if (a->p==NULL){ goto box_add_dimensions_exit; } size = res->intdim+res->realdim; dimsup = dimchange->intdim+dimchange->realdim; res->p = realloc(res->p,(size+dimsup+1)*sizeof(itv_t)); for (i=(int)size+1;i<(int)(size+dimsup+1);i++){ itv_init(res->p[i]); } k = dimsup; for (i=(int)size; i>=0; i--){ if (i<(int)size){ itv_set(res->p[i+k],a->p[i]); } while (k>=1 && dimchange->dim[k-1]==(ap_dim_t)i){ k--; if (project){ bound_set_int(res->p[i+k]->inf,0); bound_set_int(res->p[i+k]->sup,0); } else { itv_set_top(res->p[i+k]); } } } box_add_dimensions_exit: res->intdim = a->intdim+dimchange->intdim; res->realdim = a->realdim+dimchange->realdim; return res; } box_t* box_remove_dimensions(ap_manager_t* man, bool destructive, box_t* a, ap_dimchange_t* dimchange) { box_t* res; size_t size; size_t dimsup; size_t i,k; man->result.flag_best = true; man->result.flag_exact = true; res = destructive ? a : box_copy(man,a); if (a->p==NULL){ goto box_remove_dimensions_exit; } size = res->intdim+res->realdim; dimsup = dimchange->intdim+dimchange->realdim; k=0; for (i=0; idim[k]==i+k){ k++; } itv_set(res->p[i],a->p[i+k]); } itv_set_int(res->p[size-dimsup],0); for (i=size-dimsup+1;ip[i]); } res->p = realloc(res->p,(size-dimsup+1)*sizeof(itv_t)); box_remove_dimensions_exit: res->intdim = a->intdim-dimchange->intdim; res->realdim = a->realdim-dimchange->realdim; return res; } box_t* box_permute_dimensions(ap_manager_t* man, bool destructive, box_t* a, ap_dimperm_t* perm) { box_t* res; size_t size; size_t i; man->result.flag_best = true; man->result.flag_exact = true; if (a->p==NULL){ return destructive ? a : box_copy(man,a); } res = box_copy(man,a); size = res->intdim+res->realdim; for (i=0;ip[perm->dim[i]],a->p[i]); } if (destructive) box_free(man,a); return res; } apron-dist-0.9.10/apron/box/box_otherops.c0000640014525101416610000000632010723557216020344 0ustar bjeannetpopart/* ********************************************************************** */ /* box_otherops.c */ /* ********************************************************************** */ #include "box_internal.h" #include "box_otherops.h" box_t* box_forget_array(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t* tdim, size_t size, bool project) { box_t* res; size_t i; man->result.flag_best = true; man->result.flag_exact = true; res = destructive ? a : box_copy(man,a); if (a->p==NULL){ return res; } if (project){ for (i=0;ip[tdim[i]]; bound_set_int(itv->inf,0); bound_set_int(itv->sup,0); } } else { for (i=0;ip[tdim[i]]; itv_set_top(itv); } } return res; } box_t* box_expand(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t dim, size_t dimsup) { size_t intdimsup,realdimsup,offset; ap_dimchange_t dimchange; size_t i; box_t* res; man->result.flag_best = true; man->result.flag_exact = true; if (dimintdim){ intdimsup = dimsup; realdimsup = 0; offset = a->intdim; } else { intdimsup = 0; realdimsup = dimsup; offset = a->intdim+a->realdim; } if (a->p==NULL || dimsup==0){ res = destructive ? a : box_copy(man,a); res->intdim = a->intdim+intdimsup; res->realdim = a->realdim+realdimsup; return res; } ap_dimchange_init(&dimchange,intdimsup,realdimsup); for (i=0;ip[i],res->p[dim]); } ap_dimchange_clear(&dimchange); return res; } box_t* box_fold(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t* tdim, size_t size) { ap_dim_t dim; size_t dimsup,intdimsup,realdimsup; ap_dimchange_t dimchange; size_t i; box_t* res; man->result.flag_best = true; man->result.flag_exact = true; dim = tdim[0]; dimsup = size-1; res = destructive ? a : box_copy(man,a); if (dimintdim){ intdimsup = dimsup; realdimsup = 0; } else { intdimsup = 0; realdimsup = dimsup; } if (a->p==NULL || dimsup==0){ res->intdim = a->intdim-intdimsup; res->realdim = a->realdim-realdimsup; return res; } for (i=1; ip[dim],res->p[dim],res->p[tdim[i]]); } ap_dimchange_init(&dimchange,intdimsup,realdimsup); for (i=0;iresult.flag_best = true; man->result.flag_exact = true; nbdims = a1->intdim+a1->realdim; if (a1->p==NULL){ return box_copy(man,a2); } assert(a2->p!=NULL); res = box_copy(man,a1); for (i=0; ip[i],a1->p[i],a2->p[i]); } return res; } box_t* box_closure(ap_manager_t* man, bool destructive, box_t* a) { man->result.flag_best = true; man->result.flag_exact = true; return destructive ? a : box_copy(man,a); } apron-dist-0.9.10/apron/box/box.texi0000640014525101416610000000431110634023044017132 0ustar bjeannetpopart@c This file is part of the APRON Library, released under LGPL @c license. Please read the COPYING file packaged in the distribution @c to be included from apron.texi The @sc{Box} interval library is aimed to be used through the APRON interface. @menu * Use of Box:: * Allocating Box managers:: @end menu @c =================================================================== @node Use of Box, Allocating Box managers,, Box @subsection Use of Box @c =================================================================== To use @sc{Box} in C, add @example #include "box.h" @end example in your source file(s) and add @samp{-I$(BOX_PREFIX)/include} in the command line in your Makefile. You should also link your object files with the @sc{Box} library to produce an executable, by adding something like @samp{-L$(APRON_PREFIX)/lib -lboxmpq -litvmpq} in the command line in your Makefile (followed by the standard @samp{-lapron -litvmpq -litvdbl -L$(MPFR_PREFIX)/lib -lmpfr -L$(GMP_PREFIX)/lib -lgmp}). There are actually several variants of the library: @table @file @item libboxllr.a The underlying representation for numbers is rationals based on @code{long long int} integers. This may cause overflows. These are currently not detected. It requires also the @file{libitvllr.a} library. @item libboxdbl.a The underlying representations for numbers is @code{double}. Overflows are not possible (we use infinite floating numbers), but currently the soundness is not ensured for all operations. It requires also the @file{libitvdbl.a} library. @item libboxmpq.a The underlying representations for rationams is @code{mpq_t}, the multi-precision rationals from the GNU GMP library. Overflows are not possible any more, but huge numbers may appear. It requires also the @file{libitvmpq.a} library. @end table Also, all library are available in debug mode (@samp{libboxmpq_debug.a}, ...). @c =================================================================== @node Allocating Box managers , , Use of Box, Box @subsection Allocating Box managers @c =================================================================== @deftypefun ap_manager_t* box_manager_alloc () Allocate a APRON manager linked to the Box library. @end deftypefun apron-dist-0.9.10/apron/box/COPYING0000640014525101416610000006401210555674006016522 0ustar bjeannetpopart This license applies to all files distributed in the APRON library, including all source code, libraries, binaries, and documentation. Copyright (C) Bertrand Jeannet 2006 for the box subpackage. GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! apron-dist-0.9.10/apron/box/box.ml0000640014525101416610000000276311252216517016610 0ustar bjeannetpopart(* File generated from box.idl *) (** Intervals abstract domain *) (** Type of boxes. Boxes constrains each dimension/variable [x_i] to belong to an interval [I_i]. Abstract values which are boxes have the type [t Apron.AbstractX.t]. Managers allocated for boxes have the type [t Apron.manager.t]. *) type t external manager_alloc : unit -> t Apron.Manager.t = "camlidl_box_box_manager_alloc" let manager_is_box man = let str = Apron.Manager.get_library man in (String.compare str "box")==0 let manager_of_box (man:t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_box (man:'a Apron.Manager.t) : t Apron.Manager.t = if manager_is_box man then Obj.magic man else failwith "Box.manager_to_box: the argument manager is not a Box manager" module Abstract0 = struct let is_box abs = manager_is_box (Apron.Abstract0.manager abs) let of_box (abs: t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let to_box (abs:'a Apron.Abstract0.t) : t Apron.Abstract0.t = if is_box abs then Obj.magic abs else failwith "Box.Abstract0.to_box: the argument value is not a Box value" end module Abstract1 = struct let is_box abs = manager_is_box (Apron.Abstract1.manager abs) let of_box (abs: t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let to_box (abs:'a Apron.Abstract1.t) : t Apron.Abstract1.t = if is_box abs then Obj.magic abs else failwith "Box.Abstract1.to_box: the argument value is not a Box value" end apron-dist-0.9.10/apron/box/box_meetjoin.h0000640014525101416610000000203710644461001020305 0ustar bjeannetpopart/* ********************************************************************** */ /* box_meetjoin.h */ /* ********************************************************************** */ #ifndef _BOX_MEETJOIN_H_ #define _BOX_MEETJOIN_H_ #include "box.h" #ifdef __cplusplus extern "C" { #endif void box_add_ray(box_internal_t* intern, box_t* a, ap_generator0_t* gen); box_t* box_meet(ap_manager_t* man, bool destructive, box_t* a1, box_t* a2); box_t* box_join(ap_manager_t* man, bool destructive, box_t* a1, box_t* a2); box_t* box_meet_array(ap_manager_t* man, box_t** tab, size_t size); box_t* box_join_array(ap_manager_t* man, box_t** tab, size_t size); box_t* box_meet_lincons_array(ap_manager_t* man, bool destructive, box_t* a, ap_lincons0_array_t* array); box_t* box_meet_tcons_array(ap_manager_t* man, bool destructive, box_t* a, ap_tcons0_array_t* array); box_t* box_add_ray_array(ap_manager_t* man, bool destructive, box_t* a, ap_generator0_array_t* array); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/box/box_constructor.h0000640014525101416610000000403010723557216021067 0ustar bjeannetpopart/* ********************************************************************** */ /* box_constructor.h: constructors */ /* ********************************************************************** */ #ifndef _BOX_CONSTRUCTOR_H_ #define _BOX_CONSTRUCTOR_H_ #include "box.h" #ifdef __cplusplus extern "C" { #endif void box_bound_linexpr_internal(box_internal_t* intern, itv_t itv, box_t* a, ap_linexpr0_t* expr); box_t* box_bottom(ap_manager_t* man, size_t intdim, size_t realdim); box_t* box_top(ap_manager_t* man, size_t intdim, size_t realdim); box_t* box_of_box(ap_manager_t* man, size_t intdim, size_t realdim, ap_interval_t** tinterval); box_t* box_of_lincons_array(ap_manager_t* man, size_t intdim, size_t realdim, ap_lincons0_array_t* array); box_t* box_of_tcons_array(ap_manager_t* man, size_t intdim, size_t realdim, ap_tcons0_array_t* array); ap_dimension_t box_dimension(ap_manager_t* man, box_t* a); bool box_is_bottom(ap_manager_t* man, box_t* a); bool box_is_top(ap_manager_t* man, box_t* a); bool box_is_leq(ap_manager_t* man, box_t* a, box_t* b); bool box_is_eq(ap_manager_t* man, box_t* a, box_t* b); bool box_is_dimension_unconstrained(ap_manager_t* man, box_t* a, ap_dim_t dim); bool box_sat_interval(ap_manager_t* man, box_t* a, ap_dim_t dim, ap_interval_t* interval); bool box_sat_lincons(ap_manager_t* man, box_t* a, ap_lincons0_t* cons); bool box_sat_tcons(ap_manager_t* man, box_t* a, ap_tcons0_t* cons); ap_interval_t* box_bound_dimension(ap_manager_t* man, box_t* a, ap_dim_t dim); ap_interval_t* box_bound_linexpr(ap_manager_t* man, box_t* a, ap_linexpr0_t* expr); ap_interval_t* box_bound_texpr(ap_manager_t* man, box_t* a, ap_texpr0_t* expr); ap_lincons0_array_t box_to_lincons_array(ap_manager_t* man, box_t* a); ap_tcons0_array_t box_to_tcons_array(ap_manager_t* man, box_t* a); ap_generator0_array_t box_to_generator_array(ap_manager_t* man, box_t* a); ap_interval_t** box_to_box(ap_manager_t* man, box_t* a); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/box/manager.idl0000777014525101416610000000000011252510553024240 2../mlapronidl/manager.idlustar bjeannetpopartapron-dist-0.9.10/apron/box/box.h0000640014525101416610000003011210760562320016413 0ustar bjeannetpopart/* ********************************************************************** */ /* box.h: abstract lattice of intervals */ /* ********************************************************************** */ #ifndef _BOX_H_ #define _BOX_H_ #include #include "ap_global0.h" #ifdef __cplusplus extern "C" { #endif /* OCaml interface */ ap_manager_t* box_manager_alloc(void); typedef struct box_t box_t; /* ********************************************************************** */ /* I. General management */ /* ********************************************************************** */ /* ============================================================ */ /* I.1 Memory */ /* ============================================================ */ box_t* box_copy(ap_manager_t* man, box_t* a); /* Return a copy of a box value, on which destructive update does not affect the initial value. */ void box_free(ap_manager_t* man, box_t* a); /* Free all the memory used by the box value */ size_t box_size(ap_manager_t* man, box_t* a); /* Return the itv size of a box value (see ap_manager_t) */ /* ============================================================ */ /* I.2 Control of internal representation */ /* ============================================================ */ void box_minimize(ap_manager_t* man, box_t* a); /* Minimize the size of the representation of a. This may result in a later recomputation of internal information. */ void box_canonicalize(ap_manager_t* man, box_t* a); /* Put the box value in canonical form. (not yet clear definition) */ int box_hash(ap_manager_t* man, box_t* a); /* Return an hash code */ void box_approximate(ap_manager_t* man, box_t* a, int algorithm); /* Perform some transformation on the box value, guided by the field algorithm. The transformation may lose information. */ bool box_is_minimal(ap_manager_t* man, box_t* a); bool box_is_canonical(ap_manager_t* man, box_t* a); /* ============================================================ */ /* I.3 Printing */ /* ============================================================ */ void box_fprint(FILE* stream, ap_manager_t* man, box_t* a, char** name_of_dim); /* Print the box value in a pretty way, using function name_of_dim to name dimensions */ void box_fprintdiff(FILE* stream, ap_manager_t* man, box_t* a1, box_t* a2, char** name_of_dim); /* Print the difference between a1 (old value) and a2 (new value), using function name_of_dim to name dimensions. The meaning of difference is library dependent. */ void box_fdump(FILE* stream, ap_manager_t* man, box_t* a); /* Dump the internal representation of a box value, for debugging purposes */ /* ============================================================ */ /* I.4 Serialization */ /* ============================================================ */ ap_membuf_t box_serialize_raw(ap_manager_t* man, box_t* a); /* Allocate a memory bfer (with malloc), output the box value in raw binary format to it and return a pointer on the memory buffer and the size of bytes written. It is the user responsability to free the memory afterwards (with free). */ box_t* box_deserialize_raw(ap_manager_t* man, void* ptr); /* Return the box value read in raw binary format from the input stream and store in size the number of bytes read */ /* ********************************************************************** */ /* II. Constructor, accessors, tests and property extraction */ /* ********************************************************************** */ /* ============================================================ */ /* II.1 Basic constructors */ /* ============================================================ */ /* We assume that dimensions [0..intdim-1] correspond to integer variables, and dimensions [intdim..intdim+realdim-1] to real variables */ box_t* box_bottom(ap_manager_t* man, size_t intdim, size_t realdim); /* Create a bottom (empty) value */ box_t* box_top(ap_manager_t* man, size_t intdim, size_t realdim); /* Create a top (universe) value */ box_t* box_of_box(ap_manager_t* man, size_t intdim, size_t realdim, ap_interval_t** tinterval); /* Abstract an hypercube defined by the array of intervals of size intdim+realdim */ /* ============================================================ */ /* II.2 Accessors */ /* ============================================================ */ ap_dimension_t box_dimension(ap_manager_t* man, box_t* a); /* Return the dimensionality of the box values */ /* ============================================================ */ /* II.3 Tests */ /* ============================================================ */ bool box_is_bottom(ap_manager_t* man, box_t* a); bool box_is_top(ap_manager_t* man, box_t* a); bool box_is_leq(ap_manager_t* man, box_t* a1, box_t* a2); /* inclusion check */ bool box_is_eq(ap_manager_t* man, box_t* a1, box_t* a2); /* equality check */ bool box_sat_lincons(ap_manager_t* man, box_t* a, ap_lincons0_t* cons); /* does the box value satisfy the linear constraint ? */ bool box_sat_tcons(ap_manager_t* man, box_t* a, ap_tcons0_t* tcons); /* does the box value satisfy the tree expression constraint ? */ bool box_sat_interval(ap_manager_t* man, box_t* a, ap_dim_t dim, ap_interval_t* interval); /* is the dimension included in the interval in the box value ? */ bool box_is_dimension_unconstrained(ap_manager_t* man, box_t* a, ap_dim_t dim); /* is the dimension unconstrained in the box value ? If it is the case, we have forget(man,a,dim) == a */ /* ============================================================ */ /* II.4 Extraction of properties */ /* ============================================================ */ ap_interval_t* box_bound_dimension(ap_manager_t* man, box_t* a, ap_dim_t dim); /* Returns the interval taken by a linear expression over the box value */ ap_interval_t* box_bound_linexpr(ap_manager_t* man, box_t* a, ap_linexpr0_t* expr); /* Returns the interval taken by a linear expression over the box value */ ap_interval_t* box_bound_texpr(ap_manager_t* man, box_t* a, ap_texpr0_t* expr); /* Returns the interval taken by a tree expression over the box value */ ap_interval_t** box_to_box(ap_manager_t* man, box_t* a); /* Converts a box value to an interval/hypercube. The size of the resulting array is box_dimension(man,a). This function can be reimplemented by using box_bound_linexpr */ ap_lincons0_array_t box_to_lincons_array(ap_manager_t* man, box_t* a); /* Converts a box value to a polyhedra (conjunction of linear constraints). The size of the returned array is stored in size. */ ap_tcons0_array_t box_to_tcons_array(ap_manager_t* man, box_t* a); /* Converts an box value to conjunction of tree expressions constraints. The constraints are normally guaranteed to be scalar (without intervals) */ ap_generator0_array_t box_to_generator_array(ap_manager_t* man, box_t* a); /* Converts an box value to a system of generators. */ /* ********************************************************************** */ /* III. Operations: functional version */ /* ********************************************************************** */ /* ============================================================ */ /* III.1 Meet and Join */ /* ============================================================ */ box_t* box_meet(ap_manager_t* man, bool destructive, box_t* a1, box_t* a2); box_t* box_join(ap_manager_t* man, bool destructive, box_t* a1, box_t* a2); /* Meet and Join of 2 box values */ box_t* box_meet_array(ap_manager_t* man, box_t** tab, size_t size); box_t* box_join_array(ap_manager_t* man, box_t** tab, size_t size); /* Meet and Join of an array of box values. Raises an [[exc_invalid_argument]] exception if [[size==0]] (no way to define the dimensionality of the result in such a case */ box_t* box_meet_lincons_array(ap_manager_t* man, bool destructive, box_t* a, ap_lincons0_array_t* array); /* Meet of an box value with a set of constraints */ box_t* box_meet_tcons_array(ap_manager_t* man, bool destructive, box_t* a, ap_tcons0_array_t* array); /* Meet of an box value with a set of tree expressions constraints */ box_t* box_add_ray_array(ap_manager_t* man, bool destructive, box_t* a, ap_generator0_array_t* array); /* Generalized time elapse operator */ /* ============================================================ */ /* III.2 Assignement and Substitutions */ /* ============================================================ */ box_t* box_assign_linexpr_array(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, box_t* dest); box_t* box_substitute_linexpr_array(ap_manager_t* man, bool destructive, box_t* org, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, box_t* dest); box_t* box_assign_texpr_array(ap_manager_t* man, bool destructive, box_t* org, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, box_t* dest); box_t* box_substitute_texpr_array(ap_manager_t* man, bool destructive, box_t* org, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, box_t* dest); /* Parallel Assignement and Substitution of several dimensions by expressions in box value org. dest is an optional argument. If not NULL, semantically speaking, the result of the transformation is intersected with dest. This is useful for precise backward transformations in lattices like intervals or octagons. */ /* ============================================================ */ /* III.3 Projections */ /* ============================================================ */ box_t* box_forget_array(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t* tdim, size_t size, bool project); /* ============================================================ */ /* III.4 Change and permutation of dimensions */ /* ============================================================ */ box_t* box_add_dimensions(ap_manager_t* man, bool destructive, box_t* a, ap_dimchange_t* dimchange, bool project); box_t* box_remove_dimensions(ap_manager_t* man, bool destructive, box_t* a, ap_dimchange_t* dimchange); /* Size of the permutation is supposed to be equal to the dimension of the box value */ box_t* box_permute_dimensions(ap_manager_t* man, bool destructive, box_t* a, ap_dimperm_t* perm); /* ============================================================ */ /* III.5 Expansion and folding of dimensions */ /* ============================================================ */ box_t* box_expand(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t dim, size_t n); /* Expand the dimension dim into itself + n additional dimensions. It results in (n+1) unrelated dimensions having same relations with other dimensions. The (n+1) dimensions are put as follows: - original dimension dim - if the dimension is integer, the n additional dimensions are put at the end of integer dimensions; if it is real, at the end of the real dimensions. */ box_t* box_fold(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t* tdim, size_t size); /* Fold the dimensions in the array tdim of size n>=1 and put the result in the first dimension in the array. The other dimensions of the array are then removed (using box_permute_remove_dimensions). */ /* ============================================================ */ /* III.6 Widening */ /* ============================================================ */ box_t* box_widening(ap_manager_t* man, box_t* a1, box_t* a2); /* ============================================================ */ /* III.7 Closure operation */ /* ============================================================ */ /* Returns the topological closure of a possibly opened box value */ box_t* box_closure(ap_manager_t* man, bool destructive, box_t* a); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/box/box_constructor.c0000640014525101416610000003335311164714356021074 0ustar bjeannetpopart/* ********************************************************************** */ /* box_constructor.c: constructors */ /* ********************************************************************** */ #include #include #include "box_internal.h" #include "box_representation.h" #include "ap_generic.h" #include "itv_linexpr.h" #include "itv_linearize.h" /* ********************************************************************** */ /* 1. Basic constructors */ /* ********************************************************************** */ /* We assume that dimensions [0..intdim-1] correspond to integer variables, and dimensions [intdim..intdim+realdim-1] to real variables */ /* Create a bottom (empty) value */ box_t* box_bottom(ap_manager_t* man, size_t intdim, size_t realdim) { man->result.flag_best = true; man->result.flag_exact = true; return box_alloc(intdim,realdim); } /* Create a top (universe) value */ box_t* box_top(ap_manager_t* man, size_t intdim, size_t realdim) { size_t i; box_t* a = box_alloc(intdim,realdim); box_init(a); for(i=0;iintdim+a->realdim; i++){ itv_set_top(a->p[i]); } man->result.flag_best = true; man->result.flag_exact = true; return a; } /* Abstract an hypercube defined by the array of intervals of size intdim+realdim */ box_t* box_of_box(ap_manager_t* man, size_t intdim, size_t realdim, ap_interval_t** tinterval) { size_t i; bool exc; box_internal_t* intern = box_init_from_manager(man,AP_FUNID_OF_BOX); box_t* a = box_alloc(intdim,realdim); if (intdim+realdim!=0){ box_init(a); for(i=0;iitv,a->p[i],tinterval[i]); exc = itv_canonicalize(intern->itv,a->p[i],iresult.flag_best = true; man->result.flag_exact = true; return a; } /* ********************************************************************** */ /* 2. Accessors */ /* ********************************************************************** */ ap_dimension_t box_dimension(ap_manager_t* man, box_t* a) { ap_dimension_t res; res.intdim = a->intdim; res.realdim = a->realdim; return res; } /* ********************************************************************** */ /* 3. Tests */ /* ********************************************************************** */ bool box_is_bottom(ap_manager_t* man, box_t* a) { man->result.flag_best = true; man->result.flag_exact = true; return a->p==NULL; } bool box_is_top(ap_manager_t* man, box_t* a) { size_t i; bool res; size_t nbdims = a->intdim + a->realdim; man->result.flag_best = true; man->result.flag_exact = true; if (a->p==NULL) return false; res = true; for (i=0;ip[i])){ res = false; break; } } return res; } /* inclusion check */ bool box_is_leq(ap_manager_t* man, box_t* a, box_t* b) { size_t i; bool res; size_t nbdims; man->result.flag_best = true; man->result.flag_exact = true; nbdims = a->intdim + a->realdim; if (a->p==NULL) return true; else if (b->p==NULL) return false; res = true; for (i=0;ip[i],b->p[i])){ res = false; break; } } return res; } /* equality check */ bool box_is_eq(ap_manager_t* man, box_t* a, box_t* b) { size_t i; bool res; size_t nbdims; man->result.flag_best = true; man->result.flag_exact = true; nbdims = a->intdim + a->realdim; if (a->p==NULL) return b->p==NULL; else if (b->p==NULL) return false; res = true; for (i=0;ip[i],b->p[i])){ res = false; break; } } return res; } bool box_is_dimension_unconstrained(ap_manager_t* man, box_t* a, ap_dim_t dim) { return a->p && itv_is_top(a->p[dim]); } /* is the dimension included in the interval in the abstract value ? */ bool box_sat_interval(ap_manager_t* man, box_t* a, ap_dim_t dim, ap_interval_t* interval) { box_internal_t* intern = box_init_from_manager(man,AP_FUNID_SAT_INTERVAL); man->result.flag_best = true; man->result.flag_exact = true; if (a->p==NULL) return true; ap_interval_set_itv(intern->itv, intern->sat_interval_interval, a->p[dim]); return ap_interval_is_leq(intern->sat_interval_interval,interval); } /* does the abstract value satisfy the linear constraint ? */ bool box_sat_lincons(ap_manager_t* man, box_t* a, ap_lincons0_t* cons) { itv_lincons_t lincons; bool exact; tbool_t res; box_internal_t* intern = box_init_from_manager(man,AP_FUNID_SAT_LINCONS); man->result.flag_best = man->result.flag_exact = true; if (a->p==NULL) return true; itv_lincons_init(&lincons); itv_lincons_set_ap_lincons0(intern->itv,&lincons,cons); exact = itv_eval_ap_linexpr0(intern->itv, lincons.linexpr.cst, cons->linexpr0, a->p); lincons.linexpr.equality = itv_is_point(intern->itv,lincons.linexpr.cst); itv_linexpr_reinit(&lincons.linexpr,0); res = itv_eval_cstlincons(intern->itv,&lincons); itv_lincons_clear(&lincons); man->result.flag_exact = exact; return res==tbool_true; } /* does the abstract value satisfy the tree constraint ? */ bool box_sat_tcons(ap_manager_t* man, box_t* a, ap_tcons0_t* cons) { itv_lincons_t lincons; bool exact; tbool_t res; box_internal_t* intern = box_init_from_manager(man,AP_FUNID_SAT_TCONS); man->result.flag_best = man->result.flag_exact = true; if (a->p==NULL) return true; man->result.flag_best = man->result.flag_exact = false; itv_lincons_init(&lincons); itv_eval_ap_texpr0(intern->itv, lincons.linexpr.cst, cons->texpr0, a->p); lincons.linexpr.equality = itv_is_point(intern->itv,lincons.linexpr.cst); lincons.constyp = cons->constyp; if (cons->scalar) num_set_ap_scalar(lincons.num,cons->scalar); else num_set_int(lincons.num,0); res = itv_eval_cstlincons(intern->itv,&lincons); if (res==tbool_top) res = tbool_false; itv_lincons_clear(&lincons); return res==tbool_true; } /* ********************************************************************** */ /* II.4 Extraction of properties */ /* ********************************************************************** */ ap_interval_t* box_bound_dimension(ap_manager_t* man, box_t* a, ap_dim_t dim) { bool exact; box_internal_t* intern = box_init_from_manager(man,AP_FUNID_BOUND_DIMENSION); ap_interval_t* interval = ap_interval_alloc(); if (a->p==NULL){ ap_interval_set_bottom(interval); exact = true; } else { exact = ap_interval_set_itv(intern->itv,interval,a->p[dim]); } man->result.flag_best = true; man->result.flag_exact = exact; return interval; } /* Returns the interval taken by a linear expression over the abstract value */ ap_interval_t* box_bound_linexpr(ap_manager_t* man, box_t* a, ap_linexpr0_t* expr) { bool exact; ap_interval_t* interval = ap_interval_alloc(); box_internal_t* intern = box_init_from_manager(man,AP_FUNID_BOUND_LINEXPR); if (a->p==NULL){ ap_interval_set_bottom(interval); exact = true; } else { exact = itv_eval_ap_linexpr0(intern->itv, intern->bound_linexpr_itv,expr,a->p); ap_interval_set_itv(intern->itv, interval,intern->bound_linexpr_itv); } man->result.flag_best = true; man->result.flag_exact = exact; return interval; } /* Returns the interval taken by a tree expression over the abstract value */ ap_interval_t* box_bound_texpr(ap_manager_t* man, box_t* a, ap_texpr0_t* expr) { bool exact; ap_interval_t* interval; box_internal_t* intern = box_init_from_manager(man,AP_FUNID_BOUND_TEXPR); interval = ap_interval_alloc(); if (a->p==NULL){ ap_interval_set_bottom(interval); exact = true; } else { itv_eval_ap_texpr0(intern->itv, intern->bound_linexpr_itv,expr,a->p); ap_interval_set_itv(intern->itv, interval, intern->bound_linexpr_itv); } man->result.flag_best = true; man->result.flag_exact = false; return interval; } /* Converts an abstract value to a polyhedra (conjunction of linear constraints). The size of the returned array is stored in size. */ ap_lincons0_array_t box_to_lincons_array(ap_manager_t* man, box_t* a) { size_t i; ap_lincons0_array_t array; box_internal_t* intern = (box_internal_t*)man->internal; size_t nbdims = a->intdim + a->realdim; man->result.flag_best = true; man->result.flag_exact = true; if (a->p==NULL){ array = ap_lincons0_array_make(1); array.p[0] = ap_lincons0_make_unsat(); } else if (nbdims==0){ array = ap_lincons0_array_make(0); } else { size_t size; ap_linexpr0_t* expr; ap_scalar_t* scalar; size = 0; for (i=0;ip[i]->inf)) size++; bool point = itv_is_point(intern->itv,a->p[i]); if (!point && !bound_infty(a->p[i]->sup)) size++; } array = ap_lincons0_array_make(size); size = 0; for (i=0;ip[i]->inf)){ expr = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,1); ap_coeff_set_scalar_int(&expr->p.linterm[0].coeff, 1); expr->p.linterm[0].dim = i; ap_coeff_reinit(&expr->cst,AP_COEFF_SCALAR,AP_SCALAR_DOUBLE); scalar = expr->cst.val.scalar; ap_scalar_set_bound(scalar,a->p[i]->inf); point = itv_is_point(intern->itv,a->p[i]); array.p[size].constyp = point ? AP_CONS_EQ : AP_CONS_SUPEQ; array.p[size].linexpr0 = expr; size++; } if (!point && !bound_infty(a->p[i]->sup)){ expr = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,1); ap_coeff_set_scalar_int(&expr->p.linterm[0].coeff, -1); expr->p.linterm[0].dim = i; ap_coeff_reinit(&expr->cst,AP_COEFF_SCALAR,AP_SCALAR_DOUBLE); ap_scalar_set_bound(expr->cst.val.scalar,a->p[i]->sup); array.p[size].constyp = AP_CONS_SUPEQ; array.p[size].linexpr0 = expr; size++; } } } return array; } ap_tcons0_array_t box_to_tcons_array(ap_manager_t* man, box_t* a) { return ap_generic_to_tcons_array(man,a); } ap_generator0_array_t box_to_generator_array(ap_manager_t* man, box_t* a) { size_t i,j,size; size_t nbcoeffs,nblines,nbrays,nbvertices,l,r,v; ap_generator0_array_t array; ap_linexpr0_t* vertex; ap_scalar_t scalar; man->result.flag_best = true; man->result.flag_exact = true; size = a->intdim+a->realdim; if (a->p==NULL){ array = ap_generator0_array_make(0); return array; } /* Count the number of generators */ nbvertices = 1; /* we take into account the vertex */ nbrays = 0; nblines = 0; nbcoeffs = 0; for (i=0;ip[i]; bool iinf = bound_infty(itv->inf); bool isup = bound_infty(itv->sup); if (iinf && isup){ nblines++; } else { nbcoeffs++; if (iinf || isup){ nbrays++; } else { nbvertices *= 2; } } } /* Preparation */ array = ap_generator0_array_make(nblines+nbrays+nbvertices); ap_scalar_init(&scalar,AP_SCALAR_DOUBLE); ap_scalar_set_double(&scalar,0.0); /* Let's go now ! */ v = r = l = 0; /* Creates the vertices */ vertex = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,nbcoeffs); for (i=0;ip[i]; bool iinf = bound_infty(itv->inf); bool isup = bound_infty(itv->sup); if (!iinf || !isup){ ap_linexpr0_set_coeff_scalar(vertex,i,&scalar); } } array.p[nblines+nbrays + v] = ap_generator0_make(AP_GEN_VERTEX,vertex); v=1; for (i=0; ip[i]; bool iinf = bound_infty(itv->inf); bool isup = bound_infty(itv->sup); if (!iinf && !isup){ /* Duplication, and in same time set inf and sup */ for (j=0; jinf); ap_scalar_neg(&scalar,&scalar); ap_linexpr0_set_coeff_scalar(array.p[nblines+nbrays + j].linexpr0, i,&scalar); ap_scalar_set_bound(&scalar,itv->sup); ap_linexpr0_set_coeff_scalar(array.p[nblines+nbrays + v + j].linexpr0, i,&scalar); } v *= 2; } } /* Create lines and rays */ for (i=0; ip[i]; bool iinf = bound_infty(itv->inf); bool isup = bound_infty(itv->sup); if (iinf || isup){ expr = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,1); if (iinf && isup){ ap_linexpr0_set_coeff_scalar_double(expr,i,1.0); array.p[l] = ap_generator0_make(AP_GEN_LINE,expr); l++; } else if (isup){ ap_linexpr0_set_coeff_scalar_double(expr,i,1.0); array.p[nblines+r] = ap_generator0_make(AP_GEN_RAY,expr); r++; for (j=nblines+nbrays; jinf); ap_scalar_neg(&scalar,&scalar); ap_linexpr0_set_coeff_scalar(expr,i,&scalar); } } else if (iinf){ ap_linexpr0_set_coeff_scalar_double(expr,i,-1.0); array.p[nblines+r] = ap_generator0_make(AP_GEN_RAY,expr); r++; for (j=nblines+nbrays; jsup); ap_linexpr0_set_coeff_scalar(expr,i,&scalar); } } } } /* Clear things */ ap_scalar_clear(&scalar); return array; } /* Converts an abstract value to an interval/hypercube. The size of the resulting array is box_dimension(man,a). This function can be reimplemented by using box_bound_linexpr */ ap_interval_t** box_to_box(ap_manager_t* man, box_t* a) { size_t i; ap_interval_t** interval; size_t nbdims; box_internal_t* intern = (box_internal_t*)man->internal; man->result.flag_best = true; man->result.flag_exact = true; nbdims = a->intdim+a->realdim; if (nbdims==0){ interval = NULL; } else { interval = ap_interval_array_alloc(nbdims); for (i=0; ip==NULL){ ap_interval_set_bottom(interval[i]); } else { ap_interval_set_itv(intern->itv,interval[i],a->p[i]); } } } return interval; } apron-dist-0.9.10/apron/box/box_assign.h0000640014525101416610000000204710644461001017760 0ustar bjeannetpopart/* ********************************************************************** */ /* box_assign.h */ /* ********************************************************************** */ #ifndef _BOX_ASSIGN_H_ #define _BOX_ASSIGN_H_ #include "box.h" #ifdef __cplusplus extern "C" { #endif box_t* box_assign_linexpr_array(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, box_t* dest); box_t* box_substitute_linexpr_array(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, box_t* dest); box_t* box_assign_texpr_array(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, box_t* dest); box_t* box_substitute_texpr_array(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, box_t* dest); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/box/box_assign.c0000640014525101416610000000711010723557216017763 0ustar bjeannetpopart/* ********************************************************************** */ /* box_assign.c */ /* ********************************************************************** */ #include #include #include "box_internal.h" #include "box_constructor.h" #include "box_assign.h" #include "ap_generic.h" #include "itv_linexpr.h" #include "itv_linearize.h" box_t* box_assign_linexpr_array(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, box_t* dest) { bool exact; size_t i; box_t* res; box_internal_t* intern = man->internal; exact = true; if (a->p==NULL || (dest && dest->p==NULL)){ man->result.flag_best = true; man->result.flag_exact = true; return destructive ? a : box_copy(man,a); } if (size==1){ res = destructive ? a : box_copy(man,a); exact = itv_eval_ap_linexpr0(intern->itv, res->p[tdim[0]],texpr[0],a->p); } else { res = box_copy(man,a); for (i=0;iitv, res->p[tdim[i]],texpr[i],a->p) && exact; } if (destructive) box_free(man,a); } if (dest) res = box_meet(man,true,res,dest); man->result.flag_best = size==1 && exact; man->result.flag_exact = false; return res; } box_t* box_substitute_linexpr_array(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, box_t* dest) { return (box_t*)ap_generic_substitute_linexpr_array(man,destructive,a, tdim,texpr,size, dest); } box_t* box_assign_texpr(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t dim, ap_texpr0_t* texpr, box_t* dest) { bool exact; box_t* res; box_internal_t* intern = man->internal; res = destructive ? a : box_copy(man,a); if (a->p==NULL || (dest!=NULL && dest->p==NULL)){ man->result.flag_best = true; man->result.flag_exact = true; return res; } itv_eval_ap_texpr0(intern->itv,res->p[dim],texpr,a->p); if (dest) res = box_meet(man,true,res,dest); man->result.flag_best = false; man->result.flag_exact = false; return res; } box_t* box_assign_texpr_array(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, box_t* dest) { size_t i; box_t* res; box_internal_t* intern = man->internal; if (a->p==NULL || (dest && dest->p==NULL)){ man->result.flag_best = true; man->result.flag_exact = true; return destructive ? a : box_copy(man,a); } if (size==1){ res = destructive ? a : box_copy(man,a); itv_eval_ap_texpr0(intern->itv,res->p[tdim[0]],texpr[0],a->p); } else { res = box_copy(man,a); for (i=0;iitv,res->p[tdim[i]],texpr[i],a->p); } if (destructive) box_free(man,a); } if (dest) res = box_meet(man,true,res,dest); man->result.flag_best = false; man->result.flag_exact = false; return res; } box_t* box_substitute_texpr_array(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, box_t* dest) { return (box_t*)ap_generic_substitute_texpr_array(man,destructive,a, tdim,texpr,size, dest); } box_t* box_substitute_texpr(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t dim, ap_texpr0_t* texpr, box_t* dest) { return (box_t*)ap_generic_substitute_texpr_array(man,destructive,a, &dim,&texpr,1, dest); } apron-dist-0.9.10/apron/box/box_resize.h0000640014525101416610000000127410606726476020020 0ustar bjeannetpopart/* ********************************************************************** */ /* box_resize.h */ /* ********************************************************************** */ #ifndef _BOX_RESIZE_H_ #define _BOX_RESIZE_H_ #include "box.h" #ifdef __cplusplus extern "C" { #endif box_t* box_add_dimensions(ap_manager_t* man, bool destructive, box_t* a, ap_dimchange_t* dimchange, bool project); box_t* box_remove_dimensions(ap_manager_t* man, bool destructive, box_t* a, ap_dimchange_t* dimchange); box_t* box_permute_dimensions(ap_manager_t* man, bool destructive, box_t* a, ap_dimperm_t* permutation); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/box/box_representation.h0000640014525101416610000000245310571032754021547 0ustar bjeannetpopart/* ********************************************************************** */ /* box_representation.c: general management */ /* ********************************************************************** */ #ifndef _BOX_REPRESENTATION_H_ #define _BOX_REPRESENTATION_H_ #include "box.h" #ifdef __cplusplus extern "C" { #endif /* Internal functions */ box_t* box_alloc(size_t intdim, size_t realdim); void box_init(box_t* a); void box_set_bottom(box_t* a); void box_set_top(box_t* a); void box_set(box_t* a, box_t* b); /* 1. Memory */ box_t* box_copy(ap_manager_t* man, box_t* a); void box_free(ap_manager_t* man, box_t* a); size_t box_size(ap_manager_t* man, box_t* a); /* 2. Control of internal representation */ void box_minimize(ap_manager_t* man, box_t* a); void box_canonicalize(ap_manager_t* man, box_t* a); void box_approximate(ap_manager_t* man, box_t* a, int algorithm); /* 3. Printing */ void box_print(FILE* stream, ap_manager_t* man,box_t* a,char** name_of_dim); void box_dump(FILE* stream, ap_manager_t* man, box_t* a); void box_printdiff(FILE* stream, ap_manager_t* man, box_t* a, box_t* b, char** name_of_dim); /* 4. Serialization */ ap_membuf_t box_serialize_raw(ap_manager_t* man, box_t* a); box_t* box_deserialize_raw(ap_manager_t* man, void* ptr); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/box/Makefile0000640014525101416610000001741611251737120017124 0ustar bjeannetpopartinclude ../Makefile.config PREFIX = $(APRON_PREFIX) SRCDIR = $(shell pwd) #--------------------------------------- # Programs #--------------------------------------- #--------------------------------------- # Flags #--------------------------------------- # Use ICFLAGS to specify machine-independent compilation flags. ICFLAGS = \ -I$(MLGMPIDL_PREFIX)/include \ -I../num \ -I../itv \ -I../apron \ -I../mlapronidl \ -I$(GMP_PREFIX)/include -I$(MPFR_PREFIX)/include \ -I$(CAMLIDL_PREFIX)/lib/ocaml -I$(CAML_PREFIX)/lib/ocaml # Caml OCAMLINC = -I $(MLGMPIDL_PREFIX)/lib -I ../mlapronidl #--------------------------------------- # Files #--------------------------------------- CCMODULES = box_internal box_representation box_constructor box_meetjoin box_assign box_resize box_otherops CCSRC = box_config.h box.h $(CCMODULES:%=%.h) $(CCMODULES:%=%.c) CCINC_TO_INSTALL = box.h CCBIN_TO_INSTALL = CCLIB_TO_INSTALL = \ libboxMPQ.a libboxD.a libboxMPFR.a \ libboxMPQ_debug.a libboxD_debug.a libboxMPFR_debug.a \ libboxMPQ.so libboxD.so libboxMPFR.so \ libboxMPQ_debug.so libboxD_debug.so libboxMPFR_debug.so CAML_TO_INSTALL = \ box.idl box.ml box.mli box.cmi box.cmx \ box.cma box.cmxa box.a \ boxMPQ.cma boxMPQ.cmxa boxMPQ.a \ boxD.cma boxD.cmxa boxD.a \ boxMPFR.cma boxMPFR.cmxa boxMPFR.a \ libboxMPQ_caml.a libboxD_caml.a libboxMPFR_caml.a \ libboxMPQ_caml_debug.a libboxD_caml_debug.a libboxMPFR_caml_debug.a \ libboxMPQ_caml.so libboxD_caml.so libboxMPFR_caml.so \ libboxMPQ_caml_debug.so libboxD_caml_debug.so libboxMPFR_caml_debug.so \ dllboxMPQ_caml.so dllboxD_caml.so dllboxMPFR_caml.so \ dllboxMPQ_caml_debug.so dllboxD_caml_debug.so dllboxMPFR_caml_debug.so #--------------------------------------- # Rules #--------------------------------------- # Possible goals: # depend doc install # and the following one all: allMPQ allD allMPFR allMPQ: libboxMPQ.a libboxMPQ_debug.a allD: libboxD.a libboxD_debug.a allMPFR: libboxMPFR.a libboxMPFR_debug.a ifneq ($(HAS_SHARED),) allMPQ: libboxMPQ.so libboxMPQ_debug.so allD: libboxD.so libboxD_debug.so allMPFR: libboxMPFR.so libboxMPFR_debug.so endif ml: box.mli box.ml box.cmi box.cmx box.a mlMPQ mlD mlMPFR box.cma box.cmxa mlMPQ: boxMPQ.cma boxMPQ.cmxa libboxMPQ_caml.a libboxMPQ_caml_debug.a mlD: boxD.cma boxD.cmxa libboxD_caml.a libboxD_caml_debug.a mlMPFR: boxMPFR.cma boxMPFR.cmxa libboxMPFR_caml.a libboxMPFR_caml_debug.a ifneq ($(HAS_SHARED),) mlMPQ: libboxMPQ_caml.so libboxMPQ_caml_debug.so dllboxMPQ_caml.so dllboxMPQ_caml_debug.so mlD: libboxD_caml.so libboxD_caml_debug.so dllboxD_caml.so dllboxD_caml_debug.so mlMPFR: libboxMPFR_caml.so libboxMPFR_caml_debug.so dllboxMPFR_caml.so dllboxMPFR_caml_debug.so endif mlexample%.byte: mlexample.ml box%.cma $(OCAMLC) $(OCAMLFLAGS) -I $(MLGMPIDL_INSTALL)/lib -I $(APRON_PREFIX)/lib -o $@ bigarray.cma gmp.cma apron.cma box$*.cma $< mlexample%.opt: mlexample.ml box%.cmxa $(OCAMLOPT) $(OCAMLOPTFLAGS) -I $(MLGMPIDL_INSTALL)/lib -I $(APRON_PREFIX)/lib -o $@ bigarray.cmxa gmp.cmxa apron.cmxa box$*.cmxa $< clean: /bin/rm -f *.[ao] *.so *.cm[ioax] *.cmxa *.byte *.opt code2latex /bin/rm -f *.?.tex *.log *.aux *.bbl *.blg *.toc *.dvi *.ps *.pstex* /bin/rm -fr boxpolkarung boxpolkatopg tmp mostlyclean: clean /bin/rm -fr manager.idl /bin/rm -f box.ml box.mli box_caml.c install: $(CCINC_TO_INSTALL) $(CCLIB_TO_INSTALL) $(INSTALLd) $(PREFIX)/include $(PREFIX)/lib $(INSTALL) $(CCINC_TO_INSTALL) $(PREFIX)/include for i in $(CCLIB_TO_INSTALL); do \ if test -f $$i; then $(INSTALL) $$i $(PREFIX)/lib; fi; \ done # for i in $(CCBIN_TO_INSTALL); do \ # if test -f $$i; then $(INSTALL) $$i $(PREFIX)/bin; fi; \ # done for i in $(CAML_TO_INSTALL); do \ if test -f $$i; then cp -f -d $$i $(PREFIX)/lib; fi; \ done uninstall: for i in $(CCINC_TO_INSTALL); do /bin/rm -f $(PREFIX)/include/$$i; done /bin/rm -f $(PREFIX)/lib/libbox*.* $(PREFIX)/lib/liboct*_debug.* /bin/rm -f $(PREFIX)/lib/dllbox*.so $(PREFIX)/lib/dlloct*_debug.so /bin/rm -f $(PREFIX)/lib/box.mli $(PREFIX)/lib/box.ml $(PREFIX)/lib/box.cm[ix] $(PREFIX)/lib/box.idl $(PREFIX)/lib/box*.cma $(PREFIX)/lib/box*.cmxa $(PREFIX)/lib/box*.a distclean: uninstall /bin/rm -f Makefile.depend dist: $(CCSRC) Makefile sedscript_caml box.texi box.idl box.ml box.mli box_caml.c COPYING README (cd ..; tar zcvf box.tgz $(^:%=box/%)) #--------------------------------------- # IMPLICIT RULES AND DEPENDENCIES #--------------------------------------- .SUFFIXES: .tex .c .h .a .o .PRECIOUS: libbox%.a libbox%_debug.a libbox%.so libbox%_debug.so .PRECIOUS: libbox%_caml.a libbox%_caml_debug.a libbox%_caml.so libbox%_caml_debug.so .PRECIOUS: %MPQ.o %D.o %MPFR.o .PRECIOUS: %MPQ_debug.o %D_debug.o %MPFR_debug.o .PRECIOUS: %.cmo %.cmx #----------------------------------- # C part #----------------------------------- libbox%.a: $(subst .c,%.o,$(CCMODULES:%=%.c)) $(AR) rcs $@ $^ $(RANLIB) $@ libbox%_debug.a: $(subst .c,%_debug.o,$(CCMODULES:%=%.c)) $(AR) rcs $@ $^ $(RANLIB) $@ libbox%.so: $(subst .c,%.o,$(CCMODULES:%=%.c)) $(CC) $(CFLAGS) -shared -o $@ $^ libbox%_debug.so: $(subst .c,%_debug.o,$(CCMODULES:%=%.c)) $(CC) $(CFLAGS_DEBUG) -shared -o $@ $^ %MPQ.o: %.c $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_MPQ -c -o $@ $< %MPQ_debug.o: %.c $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_MPQ -c -o $@ $< %Rll.o: %.c $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_LONGLONGRAT -c -o $@ $< %Rll_debug.o: %.c $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_LONGLONGRAT -c -o $@ $< %D.o: %.c $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_DOUBLE -c -o $@ $< %D_debug.o: %.c $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_DOUBLE -c -o $@ $< %MPFR.o: %.c $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_MPFR -c -o $@ $< %MPFR_debug.o: %.c $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_MPFR -c -o $@ $< #--------------------------------------- # OCaml binding #--------------------------------------- libbox%_caml.a: box_caml.o libbox%.a $(AR) rcs $@ $< $(RANLIB) $@ libbox%_caml_debug.a: box_caml_debug.o libbox%_debug.a $(AR) rcs $@ $< $(RANLIB) $@ libbox%_caml.so: box_caml.o libbox%.so $(CC) $(CFLAGS) -shared -o $@ box_caml.o -L. -lbox$* -Wl,-rpath,$(APRON_PREFIX)/lib libbox%_caml_debug.so: box_caml_debug.o libbox%_debug.so $(CC) $(CFLAGS8DEBUG) -shared -o $@ box_caml_debug.o -L. -lbox$*_debug -Wl,-rpath,$(APRON_PREFIX)/lib dllbox%_caml.so: libbox%_caml.so ln -s -f $^ $@ dllbox%_caml_debug.so: libbox%_caml_debug.so ln -s -f $^ $@ box_caml.o: box_caml.c $(CC) $(CFLAGS) $(ICFLAGS) -I../apron -DNUM_MPQ -c -o $@ $< box_caml_debug.o: box_caml.c $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -I../apron -DNUM_MPQ -c -o $@ $< #--------------------------------------- # OCaml rules #--------------------------------------- box.cma: boxMPQ.cma ln -s -f $^ $@ box.cmxa: boxMPQ.cmxa ln -s -f $^ $@ box.a: boxMPQ.a ln -s -f $^ $@ box%.cma: box.cmo libbox%_caml.a libbox%.a $(OCAMLMKLIB) -ocamlc "$(OCAMLC)" -verbose -o box$* -oc box$*_caml box.cmo -lbox$* -L$(APRON_PREFIX)/lib -Wl,-rpath,$(APRON_PREFIX)/lib box%.cmxa box%.a: box.cmx libbox%_caml.a libbox%.a $(OCAMLMKLIB) -ocamlopt "$(OCAMLOPT)" -verbose -o box$* -oc box$*_caml box.cmx -lbox$* -L$(APRON_PREFIX)/lib -Wl,-rpath,$(APRON_PREFIX)/lib #--------------------------------------- # IDL rules #--------------------------------------- manager.idl: ../mlapronidl/manager.idl ln -s -f $< $@ # generates box.ml, box.mli, box_caml.c from box.idl rebuild: manager.idl box.idl mkdir -p tmp cp box.idl tmp/box.idl $(CAMLIDL) -no-include -nocpp tmp/box.idl cp tmp/box_stubs.c box_caml.c $(SED) -f sedscript_caml tmp/box.ml >box.ml $(SED) -f sedscript_caml tmp/box.mli >box.mli #--------------------------------------- # ML generic rules #--------------------------------------- %.cmi: %.mli $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -c $< %.cmo: %.ml %.cmi $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -c $< %.cmx: %.ml %.cmi $(OCAMLOPT) $(OCAMLOPTFLAGS) $(OCAMLINC) -c $< #----------------------------------- # DEPENDENCIES #----------------------------------- apron-dist-0.9.10/apron/box/box.mli0000640014525101416610000000545411252216517016761 0ustar bjeannetpopart(* File generated from box.idl *) (** Intervals abstract domain *) (** Type of boxes. Boxes constrains each dimension/variable [x_i] to belong to an interval [I_i]. Abstract values which are boxes have the type [t Apron.AbstractX.t]. Managers allocated for boxes have the type [t Apron.manager.t]. *) type t (** Create a Box manager. *) external manager_alloc : unit -> t Apron.Manager.t = "camlidl_box_box_manager_alloc" (** {2 Type conversions} *) val manager_is_box : 'a Apron.Manager.t -> bool (** Return [true] iff the argument manager is a box manager *) val manager_of_box : t Apron.Manager.t -> 'a Apron.Manager.t (** Make a box manager generic *) val manager_to_box : 'a Apron.Manager.t -> t Apron.Manager.t (** Instanciate the type of a box manager. Raises [Failure] if the argument manager is not a box manager *) module Abstract0 : sig val is_box : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument value is a box value *) val of_box : t Apron.Abstract0.t -> 'a Apron.Abstract0.t (** Make a box value generic *) val to_box : 'a Apron.Abstract0.t -> t Apron.Abstract0.t (** Instanciate the type of a box value. Raises [Failure] if the argument value is not a box value *) end module Abstract1 : sig val is_box : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument value is a box value *) val of_box : t Apron.Abstract1.t -> 'a Apron.Abstract1.t (** Make a box value generic *) val to_box : 'a Apron.Abstract1.t -> t Apron.Abstract1.t (** Instanciate the type of a box value. Raises [Failure] if the argument value is not a box value *) end (** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. {3 Bytecode compilation} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \ bigarray.cma gmp.cma apron.cma boxMPQ.cma mlexample.ml]} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \ bigarray.cma gmp.cma apron.cma boxMPQ.cma ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \ bigarray.cma gmp.cma apron.cma boxMPQ.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa boxMPQ.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa boxMPQ.cmxa mlexample.ml \ -cclib "-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib \ -lboxMPQ_caml_debug -lboxMPQ_debug \ -lapron_caml_debug -lapron_debug \ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP/lib_PREFIX/lib -lgmp \ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \ -lbigarray" ]} *) apron-dist-0.9.10/apron/box/box_internal.c0000640014525101416610000001114211164714204020303 0ustar bjeannetpopart/* ********************************************************************** */ /* box_internal.c */ /* ********************************************************************** */ #include #include #include "box_internal.h" #include "box.h" #include "itv.h" void box_internal_init(box_internal_t* intern) { intern->itv = itv_internal_alloc(); itv_init(intern->bound_linexpr_internal_itv); itv_init(intern->bound_linexpr_internal_itv2); intern->sat_interval_interval = ap_interval_alloc(); itv_init(intern->sat_lincons_itv); num_init(intern->sat_lincons_num); itv_init(intern->bound_linexpr_itv); itv_init(intern->meet_lincons_internal_itv); itv_init(intern->meet_lincons_internal_itv2); itv_init(intern->meet_lincons_internal_itv3); bound_init(intern->meet_lincons_internal_bound); } void box_internal_clear(box_internal_t* intern) { itv_internal_free(intern->itv); intern->itv=NULL; itv_clear(intern->bound_linexpr_internal_itv); itv_clear(intern->bound_linexpr_internal_itv2); ap_interval_free(intern->sat_interval_interval); intern->sat_interval_interval = NULL; itv_clear(intern->sat_lincons_itv); num_clear(intern->sat_lincons_num); itv_clear(intern->bound_linexpr_itv); itv_clear(intern->meet_lincons_internal_itv); itv_clear(intern->meet_lincons_internal_itv2); itv_clear(intern->meet_lincons_internal_itv3); bound_clear(intern->meet_lincons_internal_bound); } box_internal_t* box_internal_alloc(void) { box_internal_t* intern = malloc(sizeof(box_internal_t)); box_internal_init(intern); return intern; } void box_internal_free(box_internal_t* intern) { box_internal_clear(intern); free(intern); } ap_manager_t* box_manager_alloc(void) { size_t i; box_internal_t* itv; ap_manager_t* man; void** funptr; if (!ap_fpu_init()) { fprintf(stderr,"box_manager_alloc cannot change the FPU rounding mode\n"); } itv = box_internal_alloc(); man = ap_manager_alloc("box", "1.0 with " NUM_NAME, itv, (void (*)(void*))box_internal_free); funptr = man->funptr; funptr[AP_FUNID_COPY] = &box_copy; funptr[AP_FUNID_FREE] = &box_free; funptr[AP_FUNID_ASIZE] = &box_size; funptr[AP_FUNID_MINIMIZE] = &box_minimize; funptr[AP_FUNID_CANONICALIZE] = &box_canonicalize; funptr[AP_FUNID_HASH] = &box_hash; funptr[AP_FUNID_APPROXIMATE] = &box_approximate; funptr[AP_FUNID_FPRINT] = &box_fprint; funptr[AP_FUNID_FPRINTDIFF] = &box_fprintdiff; funptr[AP_FUNID_FDUMP] = &box_fdump; funptr[AP_FUNID_SERIALIZE_RAW] = &box_serialize_raw; funptr[AP_FUNID_DESERIALIZE_RAW] = &box_deserialize_raw; funptr[AP_FUNID_BOTTOM] = &box_bottom; funptr[AP_FUNID_TOP] = &box_top; funptr[AP_FUNID_OF_BOX] = &box_of_box; funptr[AP_FUNID_DIMENSION] = &box_dimension; funptr[AP_FUNID_IS_BOTTOM] = &box_is_bottom; funptr[AP_FUNID_IS_TOP] = &box_is_top; funptr[AP_FUNID_IS_LEQ] = &box_is_leq; funptr[AP_FUNID_IS_EQ] = &box_is_eq; funptr[AP_FUNID_IS_DIMENSION_UNCONSTRAINED] = &box_is_dimension_unconstrained; funptr[AP_FUNID_SAT_INTERVAL] = &box_sat_interval; funptr[AP_FUNID_SAT_LINCONS] = &box_sat_lincons; funptr[AP_FUNID_SAT_TCONS] = &box_sat_tcons; funptr[AP_FUNID_BOUND_DIMENSION] = &box_bound_dimension; funptr[AP_FUNID_BOUND_LINEXPR] = &box_bound_linexpr; funptr[AP_FUNID_BOUND_TEXPR] = &box_bound_texpr; funptr[AP_FUNID_TO_BOX] = &box_to_box; funptr[AP_FUNID_TO_LINCONS_ARRAY] = &box_to_lincons_array; funptr[AP_FUNID_TO_TCONS_ARRAY] = &box_to_tcons_array; funptr[AP_FUNID_TO_GENERATOR_ARRAY] = &box_to_generator_array; funptr[AP_FUNID_MEET] = &box_meet; funptr[AP_FUNID_MEET_ARRAY] = &box_meet_array; funptr[AP_FUNID_MEET_LINCONS_ARRAY] = &box_meet_lincons_array; funptr[AP_FUNID_MEET_TCONS_ARRAY] = &box_meet_tcons_array; funptr[AP_FUNID_JOIN] = &box_join; funptr[AP_FUNID_JOIN_ARRAY] = &box_join_array; funptr[AP_FUNID_ADD_RAY_ARRAY] = &box_add_ray_array; funptr[AP_FUNID_ASSIGN_LINEXPR_ARRAY] = &box_assign_linexpr_array; funptr[AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY] = &box_substitute_linexpr_array; funptr[AP_FUNID_ASSIGN_TEXPR_ARRAY] = &box_assign_texpr_array; funptr[AP_FUNID_SUBSTITUTE_TEXPR_ARRAY] = &box_substitute_texpr_array; funptr[AP_FUNID_ADD_DIMENSIONS] = &box_add_dimensions; funptr[AP_FUNID_REMOVE_DIMENSIONS] = &box_remove_dimensions; funptr[AP_FUNID_PERMUTE_DIMENSIONS] = &box_permute_dimensions; funptr[AP_FUNID_FORGET_ARRAY] = &box_forget_array; funptr[AP_FUNID_EXPAND] = &box_expand; funptr[AP_FUNID_FOLD] = &box_fold; funptr[AP_FUNID_WIDENING] = &box_widening; funptr[AP_FUNID_CLOSURE] = &box_closure; for (i=0; i Environment.print x) env (fun x -> Environment.print x) env2 ; (* Creation of abstract value 1/2x+2/3y=1, [1,2]<=z+2w<=4, 0<=u<=5 *) let tab = Parser.lincons1_of_lstring env ["1/2x+2/3y=1"; "[1;2]<=z+2w";"z+2w<=4"; "0<=u";"u<=5"] in printf "tab = %a@." lincons1_array_print tab; let abs = Abstract1.of_lincons_array man env tab in printf "abs=%a@." Abstract1.print abs; (* Extraction (we first extract values for existing constraints, then for dimensions) *) let box = Abstract1.to_box man abs in printf "box=%a@." (print_array Interval.print) box.Abstract1.interval_array; for i=0 to 4 do let expr = Lincons1.get_linexpr1 (Lincons1.array_get tab i) in let box = Abstract1.bound_linexpr man abs expr in printf "Bound of %a = %a@." Linexpr1.print expr Interval.print box; done; (* 2. dimensions *) (* 3. of box *) let abs2 = Abstract1.of_box man env [|var_x; var_y; var_z; var_w; var_u; var_v; var_a; var_b|] box.Abstract1.interval_array in printf "abs2=%a@." Abstract1.print abs2; (* 4. Tests top and bottom *) let abs3 = Abstract1.bottom man env in printf "abs3=%a@.is_bottom(abs3)=%b@." Abstract1.print abs3 (Abstract1.is_bottom man abs3); printf "abs=%a@." Abstract1.print abs; let p2 = Abstract1.expand man abs var_y [|Var.of_string "y1"; Var.of_string "y2"|] in printf "p2=expand(abs,y,[y1,y2]))=%a@." Abstract1.print p2; let p2 = Abstract1.expand man abs var_u [|Var.of_string "u1"; Var.of_string "u2"|] in printf "p2=expand(abs,u,[u1,u2]))=%a@." Abstract1.print p2; (* Tree expressions *) let texpr = Parser.texpr1_of_string env "a + (x*y*y/sqrt(b))" in let abs2 = Abstract1.assign_texpr man abs var_u texpr None in printf "abs2=%a@." Abstract1.print abs2; abs ;; let ex2 (man:'a Manager.t) = let env = Environment.make [||] [|var_x; var_y; var_z|] in (* Creation of abstract value 5<=x<=14, 4<=y<=12, z=0 *) let abs1 = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int 5 14; Interval.of_int 4 12; Interval.of_int 0 0; |] in let abs2 = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int 3 12; Interval.of_int 5 13; Interval.of_int 1 1; |] in let abs3 = Abstract1.join man abs1 abs2 in abs3 ;; (* Comparing join of two different assignements and assignement by the "join" of expressions *) let ex3 (man:'a Manager.t) = let env = Environment.make [||] [|var_x; var_y; var_z|] in (* Creation of abstract value -3<=x<=-2, 10<=y<=12, -1<=z<=1 *) let abs = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int (-3) (-2); Interval.of_int 10 12; Interval.of_int (-1) (1) |] in (* Creation of linear expressions *) let linexpr1 = Parser.linexpr1_of_string env "z+x+2y" in let linexpr2 = Parser.linexpr1_of_string env "z+2x+y" in let abs1 = Abstract1.assign_linexpr man abs var_z linexpr1 None in let abs2 = Abstract1.assign_linexpr man abs var_z linexpr2 None in let res1 = Abstract1.join man abs1 abs2 in printf "abs=%a@.abs1=%a@.abs2=%a@.res1=%a@." Abstract1.print abs Abstract1.print abs1 Abstract1.print abs2 Abstract1.print res1; (* Creation of linear expression [1,2]y and [1,2]z *) let linexpr = Parser.linexpr1_of_string env "z + [1;2]x + [1;2]y" in let res2 = Abstract1.assign_linexpr man abs var_z linexpr None in printf "res2=%a@." Abstract1.print res2 ; let abs1 = Abstract1.substitute_linexpr man res1 var_z linexpr1 None in let abs2 = Abstract1.substitute_linexpr man res1 var_z linexpr2 None in let res1 = Abstract1.join man abs1 abs2 in printf "abs1=%a@.abs2=%a@.res1=%a@." Abstract1.print abs1 Abstract1.print abs2 Abstract1.print res1 ; let res2 = Abstract1.substitute_linexpr man res2 var_z linexpr None in printf "res2=%a@." Abstract1.print res2 ; res1 ;; let abs1 = ex1 man;; let abs2 = ex2 man;; let abs3 = ex3 man;; apron-dist-0.9.10/apron/box/box_otherops.h0000640014525101416610000000143410571032754020346 0ustar bjeannetpopart/* ********************************************************************** */ /* box_otherops.h */ /* ********************************************************************** */ #ifndef _BOX_OTHEROPS_H_ #define _BOX_OTHEROPS_H_ #include "box.h" #ifdef __cplusplus extern "C" { #endif box_t* box_forget_array(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t* tdim, size_t size, bool project); box_t* box_expand(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t dim, size_t n); box_t* box_fold(ap_manager_t* man, bool destructive, box_t* a, ap_dim_t* tdim, size_t size); box_t* box_widening(ap_manager_t* man, box_t* a1, box_t* a2); box_t* box_closure(ap_manager_t* man, bool destructive, box_t* a); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/box/box.idl0000640014525101416610000001026711251674650016753 0ustar bjeannetpopart/* -*- mode: c -*- */ quote(C,"#include \"box.h\"") quote(C,"#include \"ap_manager.h\"") quote(C,"#include \"apron_caml.h\"") import "manager.idl"; quote(MLMLI,"(** Intervals abstract domain *)") quote(MLMLI," (** Type of boxes. Boxes constrains each dimension/variable [x_i] to belong to an interval [I_i]. Abstract values which are boxes have the type [t Apron.AbstractX.t]. Managers allocated for boxes have the type [t Apron.manager.t]. *) type t ") quote(MLI,"\n(** Create a Box manager. *)") ap_manager_ptr box_manager_alloc() quote(call,"_res = box_manager_alloc(); { ap_exc_t i; for (i=1; i bool (** Return [true] iff the argument manager is a box manager *) val manager_of_box : t Apron.Manager.t -> 'a Apron.Manager.t (** Make a box manager generic *) val manager_to_box : 'a Apron.Manager.t -> t Apron.Manager.t (** Instanciate the type of a box manager. Raises [Failure] if the argument manager is not a box manager *) module Abstract0 : sig val is_box : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument value is a box value *) val of_box : t Apron.Abstract0.t -> 'a Apron.Abstract0.t (** Make a box value generic *) val to_box : 'a Apron.Abstract0.t -> t Apron.Abstract0.t (** Instanciate the type of a box value. Raises [Failure] if the argument value is not a box value *) end module Abstract1 : sig val is_box : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument value is a box value *) val of_box : t Apron.Abstract1.t -> 'a Apron.Abstract1.t (** Make a box value generic *) val to_box : 'a Apron.Abstract1.t -> t Apron.Abstract1.t (** Instanciate the type of a box value. Raises [Failure] if the argument value is not a box value *) end ") quote(ML," let manager_is_box man = let str = Apron.Manager.get_library man in (String.compare str \"box\")==0 let manager_of_box (man:t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_box (man:'a Apron.Manager.t) : t Apron.Manager.t = if manager_is_box man then Obj.magic man else failwith \"Box.manager_to_box: the argument manager is not a Box manager\" module Abstract0 = struct let is_box abs = manager_is_box (Apron.Abstract0.manager abs) let of_box (abs: t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let to_box (abs:'a Apron.Abstract0.t) : t Apron.Abstract0.t = if is_box abs then Obj.magic abs else failwith \"Box.Abstract0.to_box: the argument value is not a Box value\" end module Abstract1 = struct let is_box abs = manager_is_box (Apron.Abstract1.manager abs) let of_box (abs: t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let to_box (abs:'a Apron.Abstract1.t) : t Apron.Abstract1.t = if is_box abs then Obj.magic abs else failwith \"Box.Abstract1.to_box: the argument value is not a Box value\" end ") quote(MLI,"\n(** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. {3 Bytecode compilation} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma boxMPQ.cma mlexample.ml]} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \\ bigarray.cma gmp.cma apron.cma boxMPQ.cma ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma boxMPQ.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa boxMPQ.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa boxMPQ.cmxa mlexample.ml \\ -cclib \"-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib \\ -lboxMPQ_caml_debug -lboxMPQ_debug \\ -lapron_caml_debug -lapron_debug \\ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP/lib_PREFIX/lib -lgmp \\ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \\ -lbigarray\" ]} *)") apron-dist-0.9.10/apron/box/box_caml.c0000640014525101416610000000416111252216517017410 0ustar bjeannetpopart/* File generated from box.idl */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include "box.h" #include "ap_manager.h" #include "apron_caml.h" extern void camlidl_apron_manager_funid_ml2c(value, ap_funid_t *); #define camlidl_ml2c_manager_ap_funid_t(v,c,ctx) camlidl_apron_manager_funid_ml2c(v,c) extern value camlidl_apron_manager_funid_c2ml(ap_funid_t *); #define camlidl_c2ml_manager_ap_funid_t(c,ctx) camlidl_apron_manager_funid_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_funopt_t(value, struct ap_funopt_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_funopt_t(struct ap_funopt_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_exc_ml2c(value, ap_exc_t *); #define camlidl_ml2c_manager_ap_exc_t(v,c,ctx) camlidl_apron_manager_exc_ml2c(v,c) extern value camlidl_apron_manager_exc_c2ml(ap_exc_t *); #define camlidl_c2ml_manager_ap_exc_t(c,ctx) camlidl_apron_manager_exc_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_exclog_t(value, struct ap_exclog_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_exclog_t(struct ap_exclog_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_ptr_ml2c(value, ap_manager_ptr *); #define camlidl_ml2c_manager_ap_manager_ptr(v,c,ctx) camlidl_apron_manager_ptr_ml2c(v,c) extern value camlidl_apron_manager_ptr_c2ml(ap_manager_ptr *); #define camlidl_c2ml_manager_ap_manager_ptr(c,ctx) camlidl_apron_manager_ptr_c2ml(c) value camlidl_box_box_manager_alloc(value _unit) { ap_manager_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; /* begin user-supplied calling sequence */ _res = box_manager_alloc(); { ap_exc_t i; for (i=1; i Manager.ap_manager_ptr = "camlidl_box_box_manager_alloc" let manager_is_box man = let str = Apron.Manager.get_library man in (String.compare str "box")==0 let manager_of_box (man:t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_box (man:'a Apron.Manager.t) : t Apron.Manager.t = if manager_is_box man then Obj.magic man else failwith "Box.manager_to_box: the argument manager is not a Box manager" module Abstract0 = struct let is_box abs = manager_is_box (Apron.Abstract0.manager abs) let of_box (abs: t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let to_box (abs:'a Apron.Abstract0.t) : t Apron.Abstract0.t = if is_box abs then Obj.magic abs else failwith "Box.Abstract0.to_box: the argument value is not a Box value" end module Abstract1 = struct let is_box abs = manager_is_box (Apron.Abstract1.manager abs) let of_box (abs: t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let to_box (abs:'a Apron.Abstract1.t) : t Apron.Abstract1.t = if is_box abs then Obj.magic abs else failwith "Box.Abstract1.to_box: the argument value is not a Box value" end apron-dist-0.9.10/apron/box/tmp/box.mli0000640014525101416610000000546511252216517017563 0ustar bjeannetpopart(* File generated from box.idl *) (** Intervals abstract domain *) (** Type of boxes. Boxes constrains each dimension/variable [x_i] to belong to an interval [I_i]. Abstract values which are boxes have the type [t Apron.AbstractX.t]. Managers allocated for boxes have the type [t Apron.manager.t]. *) type t (** Create a Box manager. *) external box_manager_alloc : unit -> Manager.ap_manager_ptr = "camlidl_box_box_manager_alloc" (** {2 Type conversions} *) val manager_is_box : 'a Apron.Manager.t -> bool (** Return [true] iff the argument manager is a box manager *) val manager_of_box : t Apron.Manager.t -> 'a Apron.Manager.t (** Make a box manager generic *) val manager_to_box : 'a Apron.Manager.t -> t Apron.Manager.t (** Instanciate the type of a box manager. Raises [Failure] if the argument manager is not a box manager *) module Abstract0 : sig val is_box : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument value is a box value *) val of_box : t Apron.Abstract0.t -> 'a Apron.Abstract0.t (** Make a box value generic *) val to_box : 'a Apron.Abstract0.t -> t Apron.Abstract0.t (** Instanciate the type of a box value. Raises [Failure] if the argument value is not a box value *) end module Abstract1 : sig val is_box : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument value is a box value *) val of_box : t Apron.Abstract1.t -> 'a Apron.Abstract1.t (** Make a box value generic *) val to_box : 'a Apron.Abstract1.t -> t Apron.Abstract1.t (** Instanciate the type of a box value. Raises [Failure] if the argument value is not a box value *) end (** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. {3 Bytecode compilation} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \ bigarray.cma gmp.cma apron.cma boxMPQ.cma mlexample.ml]} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \ bigarray.cma gmp.cma apron.cma boxMPQ.cma ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \ bigarray.cma gmp.cma apron.cma boxMPQ.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa boxMPQ.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa boxMPQ.cmxa mlexample.ml \ -cclib "-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib \ -lboxMPQ_caml_debug -lboxMPQ_debug \ -lapron_caml_debug -lapron_debug \ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP/lib_PREFIX/lib -lgmp \ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \ -lbigarray" ]} *) apron-dist-0.9.10/apron/box/tmp/box.idl0000640014525101416610000001026711252216517017546 0ustar bjeannetpopart/* -*- mode: c -*- */ quote(C,"#include \"box.h\"") quote(C,"#include \"ap_manager.h\"") quote(C,"#include \"apron_caml.h\"") import "manager.idl"; quote(MLMLI,"(** Intervals abstract domain *)") quote(MLMLI," (** Type of boxes. Boxes constrains each dimension/variable [x_i] to belong to an interval [I_i]. Abstract values which are boxes have the type [t Apron.AbstractX.t]. Managers allocated for boxes have the type [t Apron.manager.t]. *) type t ") quote(MLI,"\n(** Create a Box manager. *)") ap_manager_ptr box_manager_alloc() quote(call,"_res = box_manager_alloc(); { ap_exc_t i; for (i=1; i bool (** Return [true] iff the argument manager is a box manager *) val manager_of_box : t Apron.Manager.t -> 'a Apron.Manager.t (** Make a box manager generic *) val manager_to_box : 'a Apron.Manager.t -> t Apron.Manager.t (** Instanciate the type of a box manager. Raises [Failure] if the argument manager is not a box manager *) module Abstract0 : sig val is_box : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument value is a box value *) val of_box : t Apron.Abstract0.t -> 'a Apron.Abstract0.t (** Make a box value generic *) val to_box : 'a Apron.Abstract0.t -> t Apron.Abstract0.t (** Instanciate the type of a box value. Raises [Failure] if the argument value is not a box value *) end module Abstract1 : sig val is_box : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument value is a box value *) val of_box : t Apron.Abstract1.t -> 'a Apron.Abstract1.t (** Make a box value generic *) val to_box : 'a Apron.Abstract1.t -> t Apron.Abstract1.t (** Instanciate the type of a box value. Raises [Failure] if the argument value is not a box value *) end ") quote(ML," let manager_is_box man = let str = Apron.Manager.get_library man in (String.compare str \"box\")==0 let manager_of_box (man:t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_box (man:'a Apron.Manager.t) : t Apron.Manager.t = if manager_is_box man then Obj.magic man else failwith \"Box.manager_to_box: the argument manager is not a Box manager\" module Abstract0 = struct let is_box abs = manager_is_box (Apron.Abstract0.manager abs) let of_box (abs: t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let to_box (abs:'a Apron.Abstract0.t) : t Apron.Abstract0.t = if is_box abs then Obj.magic abs else failwith \"Box.Abstract0.to_box: the argument value is not a Box value\" end module Abstract1 = struct let is_box abs = manager_is_box (Apron.Abstract1.manager abs) let of_box (abs: t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let to_box (abs:'a Apron.Abstract1.t) : t Apron.Abstract1.t = if is_box abs then Obj.magic abs else failwith \"Box.Abstract1.to_box: the argument value is not a Box value\" end ") quote(MLI,"\n(** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. {3 Bytecode compilation} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma boxMPQ.cma mlexample.ml]} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \\ bigarray.cma gmp.cma apron.cma boxMPQ.cma ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma boxMPQ.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa boxMPQ.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa boxMPQ.cmxa mlexample.ml \\ -cclib \"-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib \\ -lboxMPQ_caml_debug -lboxMPQ_debug \\ -lapron_caml_debug -lapron_debug \\ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP/lib_PREFIX/lib -lgmp \\ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \\ -lbigarray\" ]} *)") apron-dist-0.9.10/apron/box/tmp/box_stubs.c0000640014525101416610000000416111252216517020434 0ustar bjeannetpopart/* File generated from box.idl */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include "box.h" #include "ap_manager.h" #include "apron_caml.h" extern void camlidl_apron_manager_funid_ml2c(value, ap_funid_t *); #define camlidl_ml2c_manager_ap_funid_t(v,c,ctx) camlidl_apron_manager_funid_ml2c(v,c) extern value camlidl_apron_manager_funid_c2ml(ap_funid_t *); #define camlidl_c2ml_manager_ap_funid_t(c,ctx) camlidl_apron_manager_funid_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_funopt_t(value, struct ap_funopt_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_funopt_t(struct ap_funopt_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_exc_ml2c(value, ap_exc_t *); #define camlidl_ml2c_manager_ap_exc_t(v,c,ctx) camlidl_apron_manager_exc_ml2c(v,c) extern value camlidl_apron_manager_exc_c2ml(ap_exc_t *); #define camlidl_c2ml_manager_ap_exc_t(c,ctx) camlidl_apron_manager_exc_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_exclog_t(value, struct ap_exclog_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_exclog_t(struct ap_exclog_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_ptr_ml2c(value, ap_manager_ptr *); #define camlidl_ml2c_manager_ap_manager_ptr(v,c,ctx) camlidl_apron_manager_ptr_ml2c(v,c) extern value camlidl_apron_manager_ptr_c2ml(ap_manager_ptr *); #define camlidl_c2ml_manager_ap_manager_ptr(c,ctx) camlidl_apron_manager_ptr_c2ml(c) value camlidl_box_box_manager_alloc(value _unit) { ap_manager_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; /* begin user-supplied calling sequence */ _res = box_manager_alloc(); { ap_exc_t i; for (i=1; i #include #include #include #include "ap_global0.h" #include "box.h" #include "oct.h" #include "pk.h" #include "pkeq.h" #include "ap_ppl.h" #include "ap_pkgrid.h" ap_linexpr0_t* random_linexpr_linear(int); ap_abstract0_t* random_abstract_std(ap_manager_t* man, int dim); void random_abstract2_std(ap_manager_t*, ap_manager_t*, int, ap_abstract0_t**, ap_abstract0_t**); ap_texpr0_t* random_texpr_std(int, int); ap_texpr0_t* random_texpr_real(int, int); /* ********************************************************************** */ /* Global paramaters */ /* ********************************************************************** */ FILE* stream=NULL; ap_manager_t* manprec; ap_manager_t* manrough; int intdim; ap_linexpr0_t* (*random_linexpr)(int) = &random_linexpr_linear; ap_texpr0_t* (*random_texpr)(int,int) = &random_texpr_real; ap_abstract0_t* (*random_abstract)(ap_manager_t*, int) = &random_abstract_std; void (*random_abstract2)(ap_manager_t*, ap_manager_t*, int, ap_abstract0_t**, ap_abstract0_t**) = &random_abstract2_std; bool random_abstract2_equal = 1; /* Indicates whether the last call to random_abstract2 guarantees that the two abstract values are semantically equal */ size_t nb_meetjoin_array = 4; size_t nb_asssub_array = 4; #define N 10 char b1_[N+4]= " ["; char b2_[N+4]; int i_; int error_ = 0; #define LOOP \ { \ memset(b1_+2,' ',N); b1_[N+2]=']'; b1_[N+3]=0; \ memset(b2_,8,N+3); b2_[N+3]=0; \ for (i_=0;i_p.coeff+i,rand()%20-10,rand()%4+1); ap_coeff_set_scalar_frac(&l->cst,rand()%20-10,rand()%4+1); return l; } /* random affine expression, quasilinear */ ap_linexpr0_t* random_linexpr_quasilinear(int dim) { ap_linexpr0_t* l = random_linexpr_linear(dim); int n1 = rand()%20-10; int n2 = n1 + rand()%10; int d1 = rand()%4+1; int d2 = rand()%d1+1; ap_linexpr0_set_cst_interval_frac(l,n1,d1,n2,d2); return l; } /* random affine expression, intlinear */ ap_linexpr0_t* random_linexpr_intlinear(int dim) { ap_linexpr0_t* l = ap_linexpr0_alloc(AP_LINEXPR_DENSE,dim); int i,n1,n2,d1,d2; for (i=0;ip.coeff+i,n1,d1,n2,d2); } n1 = rand()%20-10; n2 = n1 + rand()%10; d1 = rand()%4+1; d2 = rand()%d1+1; ap_coeff_set_interval_frac(&l->cst,n1,d1,n2,d2); return l; } /* random affine expression, linear, chosen from an interval linear one */ ap_linexpr0_t* random_linexpr_linear_from_intlinear(ap_linexpr0_t* a) { size_t i; ap_linexpr0_t* l = ap_linexpr0_alloc(AP_LINEXPR_DENSE,a->size); for (i=0;isize;i++) { switch (a->p.coeff[i].discr) { case AP_COEFF_SCALAR: ap_coeff_set_scalar(&l->p.coeff[i],a->p.coeff[i].val.scalar); break; case AP_COEFF_INTERVAL: if (rand()%2) ap_coeff_set_scalar(&l->p.coeff[i],a->p.coeff[i].val.interval->inf); else ap_coeff_set_scalar(&l->p.coeff[i],a->p.coeff[i].val.interval->sup); break; } } switch (a->cst.discr) { case AP_COEFF_SCALAR: ap_coeff_set_scalar(&l->cst,a->cst.val.scalar); break; case AP_COEFF_INTERVAL: if (rand()%2) ap_coeff_set_scalar(&l->cst,a->cst.val.interval->inf); else ap_coeff_set_scalar(&l->cst,a->cst.val.interval->sup); break; } return l; } ap_lincons0_t random_lincons_linear_from_intlinear(ap_lincons0_t a) { return ap_lincons0_make(a.constyp, random_linexpr_linear_from_intlinear(a.linexpr0), NULL); } /* random tree expression */ ap_texpr0_t* random_texpr_std(int dim, int depth) { if (depth==0) { switch (rand()%3) { case 0: return ap_texpr0_dim(rand()%dim); case 1: return ap_texpr0_cst_scalar_frac(rand()%20-2,rand()%4+1); default: { int n1 = rand()%20-10; int n2 = n1 + rand()%10; int d1 = rand()%4+1; int d2 = n2>=0 ? rand()%d1+1 : d1+1+rand()%4; return ap_texpr0_cst_interval_frac(n1,d1,n2,d2); } } } else { if (rand()%2) return ap_texpr0_unop(AP_TEXPR_NEG+rand()%(AP_TEXPR_SQRT-AP_TEXPR_NEG+1), random_texpr(dim,rand()%depth), rand()%AP_RTYPE_SIZE, rand()%AP_RDIR_SIZE); else return ap_texpr0_binop(rand()%AP_TEXPR_NEG, random_texpr(dim,rand()%depth), random_texpr(dim,rand()%depth), rand()%AP_RTYPE_SIZE, rand()%AP_RDIR_SIZE); } } ap_texpr0_t* random_texpr_real(int dim, int depth) { if (depth==0) { switch (rand()%3) { case 0: return ap_texpr0_dim(rand()%dim); case 1: return ap_texpr0_cst_scalar_frac(rand()%20-2,rand()%4+1); default: { int n1 = rand()%20-10; int n2 = n1 + rand()%10; int d1 = rand()%4+1; int d2 = n2>=0 ? rand()%d1+1 : d1+1+rand()%4; return ap_texpr0_cst_interval_frac(n1,d1,n2,d2); } } } else { if (rand()%2) return ap_texpr0_unop(AP_TEXPR_NEG+rand()%(AP_TEXPR_SQRT-AP_TEXPR_NEG+1), random_texpr(dim,rand()%depth), AP_RTYPE_REAL, rand()%AP_RDIR_SIZE); else return ap_texpr0_binop(rand()%AP_TEXPR_NEG, random_texpr(dim,rand()%depth), random_texpr(dim,rand()%depth), AP_RTYPE_REAL, rand()%AP_RDIR_SIZE); } } /* random generator of specified type */ ap_generator0_t random_generator(int dim, ap_gentyp_t g) { ap_linexpr0_t* l = random_linexpr_linear(dim); ap_coeff_set_scalar_int(&l->cst,0); return ap_generator0_make(g,l); } /* random constraint of specified type */ ap_lincons0_t random_constraint(int dim, ap_constyp_t c) { ap_linexpr0_t* l = random_linexpr(dim); switch (c) { case AP_CONS_EQ: case AP_CONS_SUPEQ: case AP_CONS_SUP: return ap_lincons0_make(c,l,NULL); break; case AP_CONS_EQMOD: { ap_scalar_t* scalar = ap_scalar_alloc(); ap_scalar_set_frac(scalar,rand()%20-10,rand()%4+1); return ap_lincons0_make(c,l,scalar); } break; default: abort(); } } /* ********************************************************************** */ /* Random generation of abstract values */ /* ********************************************************************** */ /* random abstract value, created with the vdim vertices, and rdim rays. */ ap_abstract0_t* random_abstract_std(ap_manager_t* man, int dim) { int i; ap_abstract0_t* p; ap_interval_t** t; ap_generator0_array_t ar; int vdim,rdim; vdim = (dim * 90) / 100; rdim = dim-vdim; t = ap_interval_array_alloc(dim); if (vdim==0){ /* creating an abstract value with the origin */ for (i=0;iman,tmp); } } /* adding rays */ ar = ap_generator0_array_make(rdim); for (i=0;iman,a); if (a->man==man) return a; l = ap_abstract0_to_lincons_array(a->man,a); res = ap_abstract0_of_lincons_array(man,d.intdim,d.realdim,&l); ap_lincons0_array_clear(&l); return res; } /* generate a pair of related abstract values */ void random_abstract2_std(ap_manager_t* man1,/* assumed to be the most precise */ ap_manager_t* man2,/* assumed to be the less precise */ int dim, ap_abstract0_t** abs1, ap_abstract0_t** abs2) { *abs2 = random_abstract(man2,dim); *abs1 = convert(man1,*abs2); random_abstract2_equal = true; } void random_abstract2_inv(ap_manager_t* man1,/* assumed to be the most precise */ ap_manager_t* man2,/* assumed to be the less precise */ int dim, ap_abstract0_t** abs1, ap_abstract0_t** abs2) { *abs1 = random_abstract(man1,dim); *abs2 = convert(man2,*abs1); random_abstract2_equal = false; } /* print */ void print_abstract(const char* msg, ap_abstract0_t* p) { fprintf(stream,"%s (%s) = ",msg,p->man->library); ap_abstract0_fprint(stream,p->man,p,NULL); ap_abstract0_fdump(stream,p->man,p); fprintf(stream,"\n"); } /* ********************************************************************** */ /* Comparison of abstract values */ /* ********************************************************************** */ /* The first abstract value is supposed to be defined on a more precise abstract domain than the second one. Hence we convert a2 to the first abstract domain and then performs the comparison. */ bool is_eq(ap_abstract0_t* a1, ap_abstract0_t* a2) { ap_abstract0_t* aa2 = convert(a1->man,a2); bool r = ap_abstract0_is_eq(a1->man,a1,aa2); if (a2!=aa2) ap_abstract0_free(aa2->man,aa2); return r; } bool is_leq(ap_abstract0_t* a1, ap_abstract0_t* a2) { ap_abstract0_t* aa2 = convert(a1->man,a2); bool r = ap_abstract0_is_leq(a1->man,a1,aa2); if (a2!=aa2) ap_abstract0_free(aa2->man,aa2); return r; } /* ********************************************************************** */ /* Tests */ /* ********************************************************************** */ /* ====================================================================== */ /* Various tests on special cases */ /* ====================================================================== */ /* test on prec domain */ void test_misc(void) { size_t D = 5; int i; ap_abstract0_t *bot,*top; bot = ap_abstract0_bottom(manprec,0,D); top = ap_abstract0_top(manprec,0,D); ap_dimension_t d1 = ap_abstract0_dimension(manprec,bot); ap_dimension_t d2 = ap_abstract0_dimension(manprec,top); printf("\nperforming various tests\n"); if (d1.intdim || d1.realdim!=D) printf("ap_abstract0_dimension failed #1\n"); if (d2.intdim || d2.realdim!=D) printf("ap_abstract0_dimension failed #2\n"); if (ap_abstract0_is_bottom(manprec,bot)==false) printf("ap_abstract0_is_bottom failed #3\n"); if (ap_abstract0_is_bottom(manprec,top)) printf("ap_abstract0_is_bottom failed #4\n"); if (ap_abstract0_is_top(manprec,bot)) printf("ap_abstract0_is_top failed #5\n"); if (ap_abstract0_is_top(manprec,top)==false) printf("ap_abstract0_is_top failed #6\n"); if (ap_abstract0_is_leq(manprec,bot,top)==false) printf("ap_abstract0_is_leq failed #7\n"); if (ap_abstract0_is_leq(manprec,top,bot)) printf("ap_abstract0_is_leq failed #8\n"); if (ap_abstract0_is_eq(manprec,bot,bot)==false) printf("ap_abstract0_is_eq failed #9\n"); if (ap_abstract0_is_eq(manprec,top,top)==false) printf("ap_abstract0_is_eq failed #10\n"); if (ap_abstract0_is_eq(manprec,bot,top)) printf("ap_abstract0_is_eq failed #11\n"); if (ap_abstract0_is_dimension_unconstrained(manprec,bot,0)) printf("ap_abstract0_is_dimension_unconstrained #12\n"); if (ap_abstract0_is_dimension_unconstrained(manprec,top,0)==false) printf("ap_abstract0_is_dimension_unconstrained #13\n"); for (i=0;i=90)?AP_CONS_EQ: (rand()%100>=90)?AP_CONS_SUP:AP_CONS_SUPEQ, random_linexpr(dim),NULL); bool roughs,precs; random_abstract2(manprec,manrough,dim,&preca,&rougha); roughs = ap_abstract0_sat_lincons(manrough,rougha,&l); precs = ap_abstract0_sat_lincons(manprec,preca,&l); RESULT('*'); if (random_abstract2_equal && ((roughs && roughs!=precs) || (precs && roughs!=precs)) || roughs && !precs){ ERROR("different results"); print_abstract("rougha",rougha);print_abstract("preca",preca); ap_lincons0_fprint(stream,&l,NULL); fprintf(stream,"\nroughs=%i precs=%i\n",roughs,precs); } ap_abstract0_free(manrough,rougha); ap_abstract0_free(manprec,preca); ap_lincons0_clear(&l); } ENDLOOP; } void test_sat_tcons(void) { printf("\nsat_tcons\n"); LOOP { size_t dim = 6, depth=3; ap_abstract0_t* rougha,*preca; ap_tcons0_t l = ap_tcons0_make((rand()%100>=90)?AP_CONS_EQ: (rand()%100>=90)?AP_CONS_SUP:AP_CONS_SUPEQ, random_texpr(dim,depth),NULL); bool roughs,precs; random_abstract2(manprec,manrough,dim,&preca,&rougha); roughs = ap_abstract0_sat_tcons(manrough,rougha,&l); precs = ap_abstract0_sat_tcons(manprec,preca,&l); RESULT('*'); if (random_abstract2_equal && ((roughs && roughs!=precs) || (precs && roughs!=precs)) || roughs && !precs){ ERROR("different results"); print_abstract("rougha",rougha);print_abstract("preca",preca); ap_tcons0_fprint(stream,&l,NULL); fprintf(stream,"\nroughs=%i precs=%i\n",roughs,precs); } ap_abstract0_free(manrough,rougha); ap_abstract0_free(manprec,preca); ap_tcons0_clear(&l); } ENDLOOP; } void test_to_box(void) { printf("\nbox conversion\n"); LOOP { size_t i, dim = 6; ap_abstract0_t* rougha,*roughr, *preca,*precr; ap_interval_t** roughi,**preci; random_abstract2(manprec,manrough,dim,&preca,&rougha); roughi = ap_abstract0_to_box(manrough,rougha); preci = ap_abstract0_to_box(manprec,preca); roughr = ap_abstract0_of_box(manrough,0,dim,(ap_interval_t**)roughi); precr = ap_abstract0_of_box(manprec,0,dim,(ap_interval_t**)preci); RESULT('*'); if (!is_leq(precr,roughr)) { ERROR("different results"); for (i=0;i=90)?AP_CONS_EQ: (rand()%100>=90)?AP_CONS_SUP:AP_CONS_SUPEQ, random_linexpr(dim),NULL); } roughr = ap_abstract0_meet_lincons_array(manrough,false,rougha,&ar); precr = ap_abstract0_meet_lincons_array(manprec,false,preca,&ar); RESULT('*'); if (!is_leq(precr,roughr)) { ERROR("different results"); ap_lincons0_array_fprint(stream,&ar,NULL); print_abstract("rougha",rougha); print_abstract("preca",preca); print_abstract("roughr",roughr); print_abstract("precr",precr); } ap_abstract0_free(manrough,rougha); ap_abstract0_free(manprec,preca); ap_abstract0_free(manrough,roughr); ap_abstract0_free(manprec,precr); ap_lincons0_array_clear(&ar); } ENDLOOP; } void test_meet_tcons_array(void) { printf("\nmeet_tcons_array\n"); LOOP { size_t i, dim = 6, depth = 4, nb = 3; ap_abstract0_t* rougha,*roughr, *preca,*precr; ap_tcons0_array_t ar = ap_tcons0_array_make(nb); random_abstract2(manprec,manrough,dim,&preca,&rougha); for (i=0;i=90)?AP_CONS_EQ: (rand()%100>=90)?AP_CONS_SUP:AP_CONS_SUPEQ, random_texpr(dim,depth),NULL); } roughr = ap_abstract0_meet_tcons_array(manrough,false,rougha,&ar); precr = ap_abstract0_meet_tcons_array(manprec,false,preca,&ar); RESULT('*'); if (!is_leq(precr,roughr)) { ERROR("different results"); ap_tcons0_array_fprint(stream,&ar,NULL); print_abstract("rougha",rougha); print_abstract("preca",preca); print_abstract("roughr",roughr); print_abstract("precr",precr); } ap_abstract0_free(manrough,rougha); ap_abstract0_free(manprec,preca); ap_abstract0_free(manrough,roughr); ap_abstract0_free(manprec,precr); ap_tcons0_array_clear(&ar); } ENDLOOP; } void test_join(void) { int dim = 4; printf("\njoin\n"); LOOP { ap_abstract0_t *prec0,*prec1,*precr,*rough0,*rough1,*roughr; random_abstract2(manprec,manrough,dim,&prec0,&rough0); random_abstract2(manprec,manrough,dim,&prec1,&rough1); roughr = ap_abstract0_join(manrough,false,rough0,rough1); precr = ap_abstract0_join(manprec,false,prec0,prec1); RESULT('*'); if (!is_leq(precr,roughr)) { ERROR("different results"); print_abstract("rough0",rough0); print_abstract("rough1",rough1); print_abstract("roughr",roughr); print_abstract("precr",precr); } ap_abstract0_free(manrough,rough0); ap_abstract0_free(manrough,rough1); ap_abstract0_free(manrough,roughr); ap_abstract0_free(manprec,prec0); ap_abstract0_free(manprec,prec1); ap_abstract0_free(manprec,precr); } ENDLOOP; } void test_join_array(void) { int i,dim = 3; printf("\njoin_array\n"); LOOP { ap_abstract0_t* rougha[nb_meetjoin_array], *roughr; ap_abstract0_t* preca[nb_meetjoin_array], *precr; for (i=0;i=80)?AP_GEN_LINE:AP_GEN_RAY); roughr = ap_abstract0_add_ray_array(manrough,false,rougha,&ar); precr = ap_abstract0_add_ray_array(manprec,false,preca,&ar); RESULT('*'); if (!is_leq(precr,roughr)) { ERROR("different results"); ap_generator0_array_fprint(stream,&ar,NULL); print_abstract("rougha",rougha); print_abstract("roughr",roughr); print_abstract("precr",precr); } ap_abstract0_free(manrough,rougha); ap_abstract0_free(manprec,preca); ap_abstract0_free(manrough,roughr); ap_abstract0_free(manprec,precr); ap_generator0_array_clear(&ar); } ENDLOOP; } void test_assign_linexpr(void) { printf("\nassign_linexpr\n"); LOOP { size_t dim = 7; size_t p = rand() % dim; ap_abstract0_t* rougha,*roughr, *preca,*precr; ap_linexpr0_t* l = random_linexpr(dim); random_abstract2(manprec,manrough,dim,&preca,&rougha); roughr = ap_abstract0_assign_linexpr(manrough,false,rougha,p,l,NULL); precr = ap_abstract0_assign_linexpr(manprec,false,preca,p,l,NULL); RESULT('*'); if (!is_leq(precr,roughr)) { ERROR("different results"); fprintf(stream,"x%i <- ",(int)p); ap_linexpr0_fprint(stream,l,NULL); fprintf(stream,"\n"); print_abstract("rougha",rougha); print_abstract("roughr",roughr); print_abstract("precr",precr); } ap_abstract0_free(manrough,rougha); ap_abstract0_free(manprec,preca); ap_abstract0_free(manrough,roughr); ap_abstract0_free(manprec,precr); ap_linexpr0_free(l); } ENDLOOP; } void test_assign_linexpr_array(void) { printf("\nassign_linexpr_array\n"); LOOP { size_t i, dim = 5; ap_abstract0_t* rougha,*roughr, *preca,*precr; ap_dim_t d[nb_asssub_array]; ap_linexpr0_t *l[nb_asssub_array]; random_abstract2(manprec,manrough,dim,&preca,&rougha); for (i=0;i ",(int)p); ap_linexpr0_fprint(stream,l,NULL); fprintf(stream,"\n"); print_abstract("rougha",rougha); print_abstract("roughr",roughr); print_abstract("precr",precr); } ap_abstract0_free(manrough,rougha); ap_abstract0_free(manprec,preca); ap_abstract0_free(manrough,roughr); ap_abstract0_free(manprec,precr); ap_linexpr0_free(l); } ENDLOOP; } void test_substitute_linexpr_array(void) { printf("\nsubstitute_linexpr_array\n"); LOOP { size_t i, dim = 7; size_t p = rand() % dim; ap_abstract0_t* rougha,*roughr, *preca,*precr; ap_dim_t d[nb_asssub_array]; ap_linexpr0_t *l[nb_asssub_array]; random_abstract2(manprec,manrough,dim,&preca,&rougha); for (i=0;i ",d[i]); ap_linexpr0_fprint(stream,l[i],NULL); fprintf(stream,"\n"); } print_abstract("rougha",rougha); print_abstract("roughr",roughr); print_abstract("precr",precr); } ap_abstract0_free(manrough,rougha); ap_abstract0_free(manprec,preca); ap_abstract0_free(manrough,roughr); ap_abstract0_free(manprec,precr); for (i=0;i ",(int)p); ap_texpr0_fprint(stream,l,NULL); fprintf(stream,"\n"); print_abstract("rougha",rougha); print_abstract("roughr",roughr); print_abstract("precr",precr); } ap_abstract0_free(manrough,rougha); ap_abstract0_free(manprec,preca); ap_abstract0_free(manrough,roughr); ap_abstract0_free(manprec,precr); ap_texpr0_free(l); } ENDLOOP; } void test_substitute_texpr_array(void) { printf("\nsubstitute_texpr_array\n"); LOOP { size_t i, dim = 7, depth=3; size_t p = rand() % dim; ap_abstract0_t* rougha,*roughr, *preca,*precr; ap_dim_t d[nb_asssub_array]; ap_texpr0_t *l[nb_asssub_array]; random_abstract2(manprec,manrough,dim,&preca,&rougha); for (i=0;i ",d[i]); ap_texpr0_fprint(stream,l[i],NULL); fprintf(stream,"\n"); } print_abstract("rougha",rougha); print_abstract("roughr",roughr); print_abstract("precr",precr); } ap_abstract0_free(manrough,rougha); ap_abstract0_free(manprec,preca); ap_abstract0_free(manrough,roughr); ap_abstract0_free(manprec,precr); for (i=0;iintdim+a->realdim;i++) { a->dim[i] = rand()%3 + 1; if (i) a->dim[i] += a->dim[i-1]; if (a->dim[i]intdim++; a->realdim--; } assert(a->dim[i]dim,a->realdim,proj); precr = ap_abstract0_forget_array(manprec,false,preca,a->dim,a->realdim,proj); RESULT('*'); if (!is_leq(precr,roughr)) { ERROR("different results"); ap_dimchange_fprint(stream,a); print_abstract("rougha",rougha); print_abstract("roughr",roughr); print_abstract("precr",precr); } ap_abstract0_free(manrough,rougha); ap_abstract0_free(manprec,preca); ap_abstract0_free(manrough,roughr); ap_abstract0_free(manprec,precr); ap_dimchange_free(a); } ENDLOOP; } void test_add_dimensions(void) { printf("\nadd dimensions\n"); LOOP { size_t i, dim = 8; ap_dimchange_t* a = ap_dimchange_alloc(0,3); ap_abstract0_t* rougha,*roughr, *preca,*precr; int proj = rand()%2; ap_dimension_t d; random_abstract2(manprec,manrough,dim,&preca,&rougha); d = ap_abstract0_dimension(manrough,rougha); for (i=0;iintdim+a->realdim;i++) { a->dim[i] = rand()%3; if (i) a->dim[i] += a->dim[i-1]; if (a->dim[i]intdim++; a->realdim--; } assert(a->dim[i]intdim+a->realdim;i++) { a->dim[i] = rand()%3 + 1; if (i) a->dim[i] += a->dim[i-1]; if (a->dim[i]intdim++; a->realdim--; } assert(a->dim[i]size-1;i++) { int a, j; if (idim[j]; p->dim[j] = p->dim[i]; p->dim[i] = a; } roughr = ap_abstract0_permute_dimensions(manrough,false,rougha,p); precr = ap_abstract0_permute_dimensions(manprec,false,preca,p); RESULT('*'); if (!is_eq(precr,roughr)) { ERROR("different results"); ap_dimperm_fprint(stream,p); print_abstract("rougha",rougha); print_abstract("roughr",roughr); print_abstract("precr",precr); } ap_abstract0_free(manrough,rougha); ap_abstract0_free(manprec,preca); ap_abstract0_free(manrough,roughr); ap_abstract0_free(manprec,precr); ap_dimperm_free(p); } ENDLOOP; } void test_expand(void) { printf("\nexpand dimensions\n"); LOOP { size_t dim = 6; ap_dim_t dd = rand() % dim; size_t n = (rand() % 2) + 1; ap_abstract0_t* rougha,*roughr, *preca,*precr; ap_dimension_t d; random_abstract2(manprec,manrough,dim,&preca,&rougha); d = ap_abstract0_dimension(manrough,rougha); roughr = ap_abstract0_expand(manrough,false,rougha,dd,n); precr = ap_abstract0_expand(manprec,false,preca,dd,n); RESULT('*'); if (!is_eq(precr,roughr)) { ERROR("different results"); fprintf(stream,"dim %i expanded %i times\n",(int)dd,(int)n); print_abstract("rougha",rougha); print_abstract("roughr",roughr); print_abstract("precr",precr); } ap_abstract0_free(manrough,rougha); ap_abstract0_free(manprec,preca); ap_abstract0_free(manrough,roughr); ap_abstract0_free(manprec,precr); } ENDLOOP; } void test_fold(void) { printf("\nfold dimensions\n"); LOOP { size_t dim = 6; ap_dim_t dd[3]; ap_abstract0_t* rougha,*roughr, *preca,*precr; ap_dimension_t d; random_abstract2(manprec,manrough,dim,&preca,&rougha); d = ap_abstract0_dimension(manrough,rougha); do { dd[0] = rand() % dim; if (dd[0]=dd[1]); roughr = ap_abstract0_fold(manrough,false,rougha,dd,2); precr = ap_abstract0_fold(manprec,false,preca,dd,2); RESULT('*'); if (!is_leq(precr,roughr)) { ERROR("different results"); fprintf(stream,"fold %i,%i,%i\n",(int)dd[0],(int)dd[1],(int)dd[2]); print_abstract("rougha",rougha); print_abstract("roughr",roughr); print_abstract("precr",precr); } ap_abstract0_free(manrough,rougha); ap_abstract0_free(manprec,preca); ap_abstract0_free(manrough,roughr); ap_abstract0_free(manprec,precr); } ENDLOOP; } void test_widen(void) { int dim = 5; printf("\nwidening\n"); LOOP { ap_abstract0_t* rough0, *rough1, *roughr; ap_abstract0_t* prec0, *prec1, *precr; rough0 = random_abstract(manrough,dim); rough1 = random_abstract(manrough,dim); rough1 = ap_abstract0_join(manrough,true,rough1,rough0); roughr = ap_abstract0_widening(manrough,rough0,rough1); prec0 = convert(manprec,rough0); prec1 = convert(manprec,rough1); precr = ap_abstract0_widening(manprec,prec0,prec1); RESULT('*'); if (!is_leq(precr,roughr)) { ERROR("different results"); print_abstract("rough0",rough0); print_abstract("rough1",rough1); print_abstract("roughr",roughr); print_abstract("precr",precr); } ap_abstract0_free(manrough,rough0); ap_abstract0_free(manrough,rough1); ap_abstract0_free(manrough,roughr); ap_abstract0_free(manprec,prec0); ap_abstract0_free(manprec,prec1); ap_abstract0_free(manprec,precr); } ENDLOOP; } /* Main test function */ /* Depends on global variables manprec,manrough,intdim */ void test(ap_manager_t* man1, /* the most precise */ ap_manager_t* man2 /* the less precise */ ) { int i; manprec = man1; manrough = man2; for (i=0;ioption.abort_if_exception[i] = true; manrough->option.abort_if_exception[i] = true; } for (intdim=0;intdim<1;intdim++) { printf("\n\ncomparing libraries:\n- %s (%s)\n- %s (%s)\nwith int=%i\n\n", manprec->library,manprec->version,manrough->library,manrough->version,intdim); /* run tests */ /* test_conv(); test_bound_dimension(); test_bound_linexpr(); test_bound_texpr(); test_sat_interval(); test_sat_lincons(); test_sat_tcons(); test_to_box(); test_meet(); test_meet_array(); test_meet_lincons_array(); test_meet_tcons_array(); test_join(); test_join_array(); test_add_ray(); test_assign_linexpr(); test_assign_linexpr_array(); test_substitute_linexpr(); test_substitute_linexpr_array(); */ test_assign_texpr(); test_assign_texpr_array(); /* test_substitute_texpr(); test_substitute_texpr_array(); test_forget_array(); test_add_dimensions(); test_remove_dimensions(); test_permute_dimensions(); test_expand(); test_fold(); */ } if (error_) printf("\n%i error(s)!\n",error_); else printf("\nall tests passed\n"); } /* main */ /* **** */ int main(int argc, char** argv) { int i; stream = stdout; if (argc==1){ srand(time(NULL)); } else if (argc==2){ unsigned int seed = atoi(argv[1]); srand(seed); } else { fprintf(stream,"usage: %s []\n",argv[0]); exit(1); } /* allocating all managers */ ap_manager_t* manbox = box_manager_alloc(); ap_manager_t* manoct = oct_manager_alloc(); ap_manager_t* manpkl = pk_manager_alloc(false); ap_manager_t* manpks = pk_manager_alloc(true); ap_manager_t* manpkeq = pkeq_manager_alloc(); ap_funopt_t funopt = ap_manager_get_funopt(manpkl,AP_FUNID_REMOVE_DIMENSIONS); funopt.algorithm = -1; ap_manager_set_funopt(manpkl,AP_FUNID_REMOVE_DIMENSIONS,&funopt); ap_manager_t* manppll = ap_ppl_poly_manager_alloc(false); ap_manager_t* manppls = ap_ppl_poly_manager_alloc(true); ap_manager_t* manpplgrid = ap_ppl_grid_manager_alloc(); ap_manager_t* manpkgrid = ap_pkgrid_manager_alloc(false); /* First serie */ intdim = 0; random_linexpr = &random_linexpr_linear; random_abstract = &random_abstract_std; for (i=0; i<1; i++){ random_abstract2 = i==0 ? &random_abstract2_std : &random_abstract2_inv; /* // box/polyhedra test(manpkl,manbox); test(manpks,manbox); test(manppll,manbox); test(manppls,manbox); // polyhedra/polyhedra (same library) test(manpks,manpkl); test(manpkl,manpks); test(manppls,manppll); test(manppll,manppls); // Polka polyhedra/PPL polyhedra test(manppll,manpkl); test(manpkl,manppll); test(manppls,manpks); test(manpks,manppls); */ // Grid/Equalities test(manpplgrid,manpkeq); random_abstract = &random_abstract_eq; /* test(manpplgrid,manpkeq); random_abstract = &random_abstract_eqmod; test(manpplgrid,manpkeq); */ // manpkgrid /* random_abstract = &random_abstract_eqmod; test(manpkgrid,manpplgrid); test(manpkgrid,manpkl); */ // Oct/Box and Oct/Poly /* random_abstract = &random_abstract_std; test(manoct,manbox); test(manpkl,manoct); test(manpks,manoct); // test(manppll,manoct); //test(manppls,manoct); */ } /* clean-up */ ap_manager_free(manbox); ap_manager_free(manoct); ap_manager_free(manpkl); ap_manager_free(manpks); ap_manager_free(manpkeq); ap_manager_free(manppll); ap_manager_free(manppls); ap_manager_free(manpplgrid); ap_manager_free(manpkgrid); return 0; } apron-dist-0.9.10/apron/test/COPYING0000640014525101416610000004340010702675515016707 0ustar bjeannetpopart This license (GPL) applies to all files distributed in this test subdirectory (source code, binaries). Copyright (C) Antoine Miné and Bertrand Jeannet 2005-2007 for the test subpackage. GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. apron-dist-0.9.10/apron/test/mlexample0.ml0000640014525101416610000001223111251677053020247 0ustar bjeannetpopart(** Test the special case of abstract values with dimensionality 0,0 *) open Format;; open Apron;; let print_array print_elt fmt array = if array=[||] then begin fprintf fmt "[||]" end else begin fprintf fmt "[|@["; let first = ref true in Array.iter (begin fun e -> if !first then first := false else fprintf fmt ";@ "; print_elt fmt e end) array ; fprintf fmt "@]|]"; end ;; let string_of_dim dim = "x"^(string_of_int dim);; let man1 = Box.manager_alloc ();; let man2 = Oct.manager_alloc ();; let man3 = Polka.manager_alloc_loose ();; let man4 = Ppl.manager_alloc_loose ();; let man5 = Ppl.manager_alloc_grid ();; let man6 = PolkaGrid.manager_alloc man3 man5;; let f man name = printf "man=%s, %s@. @[" (Manager.get_library man) name; let a = match name with | "bottom" -> Abstract0.bottom man 0 0 | "top" -> Abstract0.top man 0 0 | _ -> failwith "" in let a2 = match name with | "bottom" -> Abstract0.bottom man 0 2 | "top" -> let tcons = [| Lincons0.make (Linexpr0.of_list (Some 2) [((Coeff.s_of_int 1),0)] None) Lincons0.EQ; Lincons0.make (Linexpr0.of_list (Some 2) [((Coeff.s_of_int 1),1)] None) Lincons0.EQ |] in let a0 = Abstract0.of_lincons_array man 0 2 tcons in let tcons = [| Lincons0.make (Linexpr0.of_list (Some 2) [((Coeff.s_of_int 1),0)] (Some(Coeff.s_of_int 2))) Lincons0.EQ; Lincons0.make (Linexpr0.of_list (Some 2) [((Coeff.s_of_int 1),1)] (Some(Coeff.s_of_int 2))) Lincons0.EQ |] in let a1 = Abstract0.of_lincons_array man 0 2 tcons in Abstract0.join_with man a0 a1; a0 | _ -> failwith "" in let linexpr = Linexpr0.make None in Linexpr0.set_cst linexpr (Coeff.s_of_int (-2)); let lincons = Lincons0.make linexpr Lincons0.SUPEQ in let texpr = Texpr0.cst (Coeff.s_of_int (-2)) in let tcons = Tcons0.make texpr Lincons0.SUPEQ in printf "a = %a@ " (Abstract0.print string_of_dim) a; printf "is_bottom = %b@ " (Abstract0.is_bottom man a); printf "is_top = %b@ " (Abstract0.is_top man a); printf "to_box = %a@ " (print_array Interval.print) (Abstract0.to_box man a); printf "to_lincons_array = %a@ " (print_array (Lincons0.print string_of_dim)) (Abstract0.to_lincons_array man a); printf "to_tcons_array = %a@ " (print_array (Tcons0.print string_of_dim)) (Abstract0.to_tcons_array man a); if man!=(Obj.magic man6) then printf "to_generator_array = %a@ " (print_array (Generator0.print string_of_dim)) (Abstract0.to_generator_array man a); printf "bound_linexpr = %a@ " Interval.print (Abstract0.bound_linexpr man a linexpr); printf "bound_texpr = %a@ " Interval.print (Abstract0.bound_texpr man a texpr); printf "sat_lincons = %b@ " (Abstract0.sat_lincons man a lincons); printf "sat_tcons = %b@ " (Abstract0.sat_tcons man a tcons); let x = Abstract0.add_dimensions man a ({Dim.dim=[|0;0|];Dim.intdim=0;Dim.realdim=2}) false in printf "add_dimensions = %a (x)@ " (Abstract0.print string_of_dim) x ; printf "sat_lincons(x) = %b@ " (Abstract0.sat_lincons man x lincons); printf "sat_tcons(x) = %b@ " (Abstract0.sat_tcons man x tcons); printf "a2 = %a@ " (Abstract0.print string_of_dim) a2; printf "remove_dimensions(a2) = %a@ " (Abstract0.print string_of_dim) (Abstract0.remove_dimensions man a2 ({Dim.dim=[|0;1|];Dim.intdim=0;Dim.realdim=2})) ; printf "@]@."; () ;; let test_widening_strict man = let var_x = Var.of_string "x" in let var_y = Var.of_string "y" in let var_z = Var.of_string "z" in let env = Environment.make [|var_x|] [|var_y; var_z|] in let tab1 = Parser.lincons1_of_lstring env ["-x+8>=0";"-y>=0";"-5*z+4>0"; "z>=0";"x>=0"] in let tab2 = Parser.lincons1_of_lstring env ["-x+8>=0";"-y>=0";"-5*z+4>=0"; "z>=0";"x>=0"] in let abs1 = Abstract1.of_lincons_array man env tab1 in let abs2 = Abstract1.of_lincons_array man env tab2 in let abs3 = Abstract1.widening man abs1 abs2 in printf "widening @[%a@ %a@ = %a@]@." Abstract1.print abs1 Abstract1.print abs2 Abstract1.print abs3 ; () ;; test_widening_strict man1;; let _ = f man1 "bottom"; f man2 "bottom"; f man3 "bottom"; f man4 "bottom"; f man5 "bottom"; f man6 "bottom"; f man1 "top"; f man2 "top"; f man3 "top"; f man4 "top"; f man5 "top"; f man6 "top"; () ;; let f man = let abs1 = Abstract0.bottom man 1 1 in let abs2 = Abstract0.top man 0 0 in begin try printf "hash bottom = %i@." (Hashtbl.hash abs1) with _ as exn -> printf "hash bottom = exception %s@." (Printexc.to_string exn) end; begin try printf "hash top = %i@." (Hashtbl.hash abs2) with _ as exn -> printf "hash top = exception %s@." (Printexc.to_string exn) end; begin try printf "compare bottom top = %i@." (Pervasives.compare abs1 abs2) with _ as exn -> printf "compare bottom top = exception %s@." (Printexc.to_string exn) end; () ;; f man1;; f man2;; f man3;; f man4;; f man5;; f man6;; f man1;; f man2;; f man3;; f man4;; f man5;; f man6;; apron-dist-0.9.10/apron/test/Makefile0000640014525101416610000000267511251703423017313 0ustar bjeannetpopartinclude ../Makefile.config ICFLAGS = \ -I$(GMP_PREFIX)/include \ -I$(MPFR_PREFIX)/include \ -I$(APRON_PREFIX)/include \ -I$(PPL_PREFIX)/include LCFLAGS = \ -L$(GMP_PREFIX)/lib \ -L$(MPFR_PREFIX)/lib \ -L$(APRON_PREFIX)/lib \ -L$(PPL_PREFIX)/lib \ -L$(CAMLIDL_PREFIX)/lib/ocaml OCAMLINC = \ -I $(MLGMPIDL_PREFIX)/lib \ -I $(APRON_PREFIX)/lib OCAMLLDFLAGS = \ -verbose -cc "g++" \ bigarray.cma gmp.cma apron.cma boxMPQ.cma polkaMPQ.cma octD.cma ppl.cma polkaGrid.cma OCAMLOPTLDFLAGS = \ -noautolink -verbose -ccopt "$(LCFLAGS)" \ bigarray.cmxa gmp.cmxa apron.cmxa boxMPQ.cmxa polkaMPQ.cmxa octD.cmxa ppl.cmxa polkaGrid.cmxa all: C # C examples C: ctest1 %: %.o $(CXX) $(ICFLAGS) $(LCFLAGS) -o $@ $< \ -lap_pkgrid -lap_ppl -lppl -lgmpxx -lpolkaMPQ -loctMPQ -lboxMPQ -lapron -lmpfr -lgmp %_debug: %_debug.o $(CXX) -g $(ICFLAGS) $(LCFLAGS) -o $@ $< \ -lap_pkgrid_debug -lap_ppl_debug -lppl -lgmpxx -lpolkaMPQ_debug -loctMPQ_debug -lboxMPQ_debug -lapron_debug -lmpfr -lgmp %.o : %.c $(CC) $(CFLAGS) $(ICFLAGS) $(LCFLAGS) -c -o $@ $< %_debug.o: %.c $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) $(LCFLAGS) -c -o $@ $< # OCaml examples %.opt: %.ml $(OCAMLOPT) $(OCAMLOPTFLAGS) $(OCAMLINC) $(OCAMLOPTLDFLAGS) -o $@ $< %.byte: %.ml $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) $(OCAMLLDFLAGS) -o $@ $< clean: rm -f ctest1 ctest1_debug *.o *.cm[xoia] *.opt *.byte distclean: clean mostlyclean: clean dist: ctest1.c Makefile README (cd ..; tar zcvf test.tgz $(^:%=test/%)) apron-dist-0.9.10/apron/test/README0000640014525101416610000000020110672507041016516 0ustar bjeannetpopart# This file is part of the APRON Library, released under GPL # license. Various testing of APRON libraries Require PPL library. apron-dist-0.9.10/apron/itv/0000750014525101416610000000000011252216464015470 5ustar bjeannetpopartapron-dist-0.9.10/apron/itv/test2.c0000640014525101416610000001050211006063143016663 0ustar bjeannetpopart /* Some more itv testing. Compile with gcc test2.c itv.c itv_linexpr.c -std=c99 -I../num -I../apron -L../apron -lapron_debug -lmpfr -lgmp -lm -DNUM_MPQ (replacing NUM_MPQ with your choice of NUM_) */ #include #include #include #include "ap_manager.h" #include "num.h" #include "bound.h" #include "itv.h" itv_internal_t* intern; void testun(itv_t a) { itv_t b; bool exact; itv_init(b); printf("x = "); itv_print(a); printf("\n"); itv_neg(b,a); printf("-x = "); itv_print(b); printf("\n"); itv_abs(b,a); printf("abs(x) = "); itv_print(b); printf("\n"); exact = itv_sqrt(intern,b,a); printf("sqrt(x) = "); itv_print(b); printf(" (%i)\n",exact); itv_ceil(b,a); printf("ceil(x) = "); itv_print(b); printf("\n"); itv_floor(b,a); printf("floor(x) = "); itv_print(b); printf("\n"); itv_trunc(b,a); printf("trunc(x) = "); itv_print(b); printf("\n"); itv_to_int(b,a); printf("int(x) = "); itv_print(b); printf("\n"); itv_to_float(b,a); printf("float(x) = "); itv_print(b); printf("\n"); itv_to_double(b,a); printf("double(x) = "); itv_print(b); printf("\n"); itv_mul_2exp(b,a,2); printf("x << 2 = "); itv_print(b); printf("\n"); itv_mul_2exp(b,a,-2); printf("x >> 2 = "); itv_print(b); printf("\n"); printf("\n"); itv_clear(b); } void testbin(itv_t a, itv_t b) { itv_t c; itv_init(c); printf("x = "); itv_print(a); printf("\n"); printf("y = "); itv_print(b); printf("\n"); itv_add(c,a,b); printf("x + y = "); itv_print(c); printf("\n"); itv_sub(c,a,b); printf("x - y = "); itv_print(c); printf("\n"); itv_mul(intern,c,a,b); printf("x * y = "); itv_print(c); printf("\n"); itv_div(intern,c,a,b); printf("x / y = "); itv_print(c); printf("\n"); itv_clear(c); printf("\n"); } void testmod(itv_t a, itv_t b) { itv_t c; itv_init(c); printf("x = "); itv_print(a); printf("\n"); printf("y = "); itv_print(b); printf("\n"); itv_mod(intern,c,a,b,1); printf("x mod_i y = "); itv_print(c); printf("\n"); itv_mod(intern,c,a,b,0); printf("x mod_f y = "); itv_print(c); printf("\n"); printf("\n"); itv_clear(c); } void set_double(itv_t a, double inf, double sup) { num_t n; num_init(n); printf("[%f,%f]\n",inf,sup); if (sup==1./0.) bound_set_infty(a->sup,1); else { num_set_double(n,sup); bound_set_num(a->sup,n); } if (inf==-1./0.) bound_set_infty(a->inf,1); else { num_set_double(n,-inf); bound_set_num(a->inf,n); } num_clear(n); } void set_frac(itv_t a, int ninf, int dinf, int nsup, int dsup) { num_t n; num_init(n); printf("[%i/%i,%i/%i]\n",ninf,dinf,nsup,dsup); num_set_int2(n,nsup,dsup); bound_set_num(a->sup,n); num_set_int2(n,-ninf,dinf); bound_set_num(a->inf,n); num_clear(n); } int main() { itv_t a,b; ap_fpu_init(); mpfr_set_default_prec(4046); intern = itv_internal_alloc(); itv_init(a); itv_init(b); set_double(a,2,9); testun(a); set_double(a,2.25,9.5); testun(a); set_double(a,-9.5,-2.25); testun(a); set_double(a,-5.5,7.25); testun(a); set_double(a,15,1./0.); testun(a); set_double(a,-1./0.,6); testun(a); set_double(a,-1./0.,1./0.); testun(a); set_frac(a,-1,10,1,100); testun(a); set_double(a,1,-2); testun(a); set_double(a,1,5); set_double(b,10,10); testmod(a,b); set_double(a,15,18); set_double(b,10,10); testmod(a,b); set_double(a,2,28); set_double(b,10,10); testmod(a,b); set_double(a,-15,28); set_double(b,10,10); testmod(a,b); set_double(a,-15,-2); set_double(b,10,10); testmod(a,b); set_double(a,-15,-10); set_double(b,10,10); testmod(a,b); set_double(a,1,5); set_double(b,12,24); testmod(a,b); set_double(a,-4,6); set_double(b,12,24); testmod(a,b); set_double(a,0,10); set_double(b,6,8); testmod(a,b); set_double(a,0,7); set_double(b,6,8); testmod(a,b); set_double(a,2,10); set_double(b,6,8); testmod(a,b); set_double(a,1.5,10.5); set_double(b,12.3,14.5); testmod(a,b); set_double(a,1,2); set_double(b,3,4); testbin(a,b); set_double(a,2,6); set_double(b,-2,-1); testbin(a,b); set_double(a,-2,-1); set_double(b,2,6); testbin(a,b); set_double(a,-4,-1); set_double(b,-2,-1); testbin(a,b); set_double(a,-2,3); set_double(b,0,2); testbin(a,b); set_double(a,-2,-1); set_double(b,-2,-1); testbin(a,b); set_double(a,-2,-1); set_double(b,-2,0); testbin(a,b); set_double(a,-2,3); set_double(b,-1,1); testbin(a,b); itv_clear(a); itv_clear(b); itv_internal_free(intern); return 0; } apron-dist-0.9.10/apron/itv/test.c0000640014525101416610000000526211006063143016610 0ustar bjeannetpopart#include #include #include #include "ap_manager.h" #include "num.h" #include "bound.h" #include "itv.h" void arith(itv_internal_t* intern, itv_t a, itv_t b, itv_t c, bound_t bound) { itv_t bb,cc; itv_init_set(bb,b); itv_init_set(cc,c); printf("********************\n"); printf("b="); itv_print(b); printf(" c="); itv_print(c); printf(" bound="); bound_print(bound); printf("\n"); itv_set(b,bb); itv_set(c,cc); itv_swap(b,c); printf("itv_swap(b,c): "); printf("b="); itv_print(b); printf(" c="); itv_print(c); printf("\n"); itv_set(b,bb); itv_set(c,cc); itv_neg(a,b); printf("itv_neg(b)="); itv_print(a); printf("\n"); itv_set(b,bb); itv_set(c,cc); itv_add(a,b,c); printf("itv_add(b,c)="); itv_print(a); printf("\n"); itv_set(b,bb); itv_set(c,cc); itv_sub(a,b,c); printf("itv_sub(b,c)="); itv_print(a); printf("\n"); itv_set(b,bb); itv_set(c,cc); itv_mul(intern,a,b,c); printf("itv_mul(b,c)="); itv_print(a); printf("\n"); itv_set(b,bb); itv_set(c,cc); itv_add_bound(a,b,bound); printf("itv_add_bound(b,bound)="); itv_print(a); printf("\n"); itv_set(b,bb); itv_set(c,cc); itv_sub_bound(a,b,bound); printf("itv_sub_bound(b,bound)="); itv_print(a); printf("\n"); itv_set(b,bb); itv_set(c,cc); itv_mul_bound(a,b,bound); printf("itv_mul_bound(b,bound)="); itv_print(a); printf("\n"); itv_set(b,bb); itv_set(c,cc); itv_div_bound(a,b,bound); printf("itv_div_bound(b,bound)="); itv_print(a); printf("\n"); itv_set(b,bb); itv_set(c,cc); itv_clear(bb); itv_clear(cc); } int main(int argc, char**argv) { itv_t a,b,c; bound_t bound; itv_internal_t* intern; ap_fpu_init(); mpfr_set_default_prec(4046); intern = itv_internal_alloc(); itv_init(a); itv_init(b); itv_init(c); bound_init(bound); /* Positive or negative intervals */ bound_set_int(b->inf,-3); bound_set_int(b->sup,5); bound_set_int(c->inf,-1); bound_set_int(c->sup,5); bound_set_int(bound,4); arith(intern,a,b,c,bound); itv_neg(c,c); arith(intern,a,b,c,bound); itv_neg(b,b); arith(intern,a,b,c,bound); itv_neg(c,c); arith(intern,a,b,c,bound); /* general intervals */ bound_set_int(b->inf,3); bound_set_int(b->sup,5); bound_set_int(c->inf,7); bound_set_int(c->sup,11); bound_set_int(bound,3); arith(intern,a,b,c,bound); bound_set_int(bound,-3); arith(intern,a,b,c,bound); /* aliases */ bound_set_int(b->inf,3); bound_set_int(b->sup,5); bound_set_int(c->inf,7); bound_set_int(c->sup,11); bound_set_int(bound,3); arith(intern,b,b,b,bound); bound_set_int(bound,-3); arith(intern,b,b,b,bound); itv_clear(a); itv_clear(b); itv_clear(c); bound_clear(bound); itv_internal_free(intern); } apron-dist-0.9.10/apron/itv/itv_fun.h0000640014525101416610000000035611005654323017314 0ustar bjeannetpopart/* ********************************************************************** */ /* itv_fun.h: defines ITV_FUN */ /* ********************************************************************** */ #include "num_name.h" #define ITVFUN(x) NUMFUN(x) apron-dist-0.9.10/apron/itv/itv_linexpr.h0000640014525101416610000004502411022224673020206 0ustar bjeannetpopart/* ********************************************************************** */ /* itv_linexpr.c: */ /* ********************************************************************** */ #ifndef _ITV_LINEXPR_H_ #define _ITV_LINEXPR_H_ #include "itv.h" #include "ap_expr0.h" #ifdef __cplusplus extern "C" { #endif /* ********************************************************************** */ /* Dataypes */ /* ********************************************************************** */ /* Interval linear term */ typedef struct itv_linterm_t { itv_t itv; bool equality; /* indicate that the interval is reduced to a single value */ ap_dim_t dim; } itv_linterm_t; /* Interval linear expression */ typedef struct itv_linexpr_t { itv_linterm_t* linterm; size_t size; itv_t cst; bool equality; /* indicate that the interval cst is reduced to a single value */ } itv_linexpr_t; /* Interval linear constraint */ typedef struct itv_lincons_t { itv_linexpr_t linexpr; ap_constyp_t constyp; num_t num; } itv_lincons_t; /* Array of interval linear constraint */ typedef struct itv_lincons_array_t { itv_lincons_t* p; size_t size; } itv_lincons_array_t; /* Iterator (Macro): use: itv_linexpr_ForeachLinterm(itv_linexpr_t* e, size_t i, ap_dim_t d, itv_ptr pitv, bool* pequality){ .. } where - e is the inspected expression, - i is the internal iterator (of type size_t or int) - dim is the dimension of one linear term - pitv is a pointer to the corresponding coefficient - pequality indicates if the interval is actually a point */ #define itv_linexpr_ForeachLinterm(_p_e, _p_i, _p_d, _p_itv, _p_equality) \ for ((_p_i)=0; \ (_p_i)<(_p_e)->size ? \ (((_p_d) = (_p_e)->linterm[i].dim), \ ((_p_itv) = (_p_e)->linterm[i].itv), \ ((_p_equality) = &((_p_e)->linterm[i].equality)), \ ((_p_d)!=AP_DIM_MAX)) : \ false; \ (_p_i)++) /* ********************************************************************** */ /* I. Constructor and Destructor */ /* ********************************************************************** */ static inline void itv_linterm_init(itv_linterm_t* term); static inline void itv_linterm_init_set(itv_linterm_t* res, itv_linterm_t* term); static inline void itv_linterm_set(itv_linterm_t* res, itv_linterm_t* term); static inline void itv_linterm_clear(itv_linterm_t* term); static inline void itv_linterm_swap(itv_linterm_t* a, itv_linterm_t* b); static inline void itv_linexpr_init(itv_linexpr_t* expr, size_t size); static inline void itv_linexpr_init_set(itv_linexpr_t* res, itv_linexpr_t* expr); static inline void itv_linexpr_set(itv_linexpr_t* res, itv_linexpr_t* expr); static inline void itv_linexpr_reinit(itv_linexpr_t* expr, size_t size); static inline void itv_linexpr_clear(itv_linexpr_t* expr); static inline void itv_linexpr_fprint(FILE* stream, itv_linexpr_t* expr, char** name); static inline void itv_linexpr_print(itv_linexpr_t* expr, char** name); static inline void itv_lincons_init(itv_lincons_t* cons); static inline void itv_lincons_set(itv_lincons_t* res, itv_lincons_t* expr); static inline void itv_lincons_set_bool(itv_lincons_t* res, bool value); static inline void itv_lincons_clear(itv_lincons_t* cons); static inline void itv_lincons_fprint(FILE* stream, itv_lincons_t* cons, char** name); static inline void itv_lincons_print(itv_lincons_t* cons, char** name); static inline void itv_lincons_swap(itv_lincons_t* a, itv_lincons_t* b); static inline void itv_lincons_array_init(itv_lincons_array_t* array, size_t size); static inline void itv_lincons_array_reinit(itv_lincons_array_t* array, size_t size); static inline void itv_lincons_array_clear(itv_lincons_array_t* array); static inline void itv_lincons_array_fprint(FILE* stream, itv_lincons_array_t* array, char** name); static inline void itv_lincons_array_print(itv_lincons_array_t* array, char** name); /* ********************************************************************** */ /* II. Conversions from and to APRON datatypes */ /* ********************************************************************** */ static inline bool itv_linexpr_set_ap_linexpr0(itv_internal_t* intern, itv_linexpr_t* expr, ap_linexpr0_t* linexpr0); /* Convert an ap_linexpr0_t into an itv_linexpr_t. expr points to an initialized object. Return true if the conversion is exact */ static inline bool itv_lincons_set_ap_lincons0(itv_internal_t* intern, itv_lincons_t* cons, ap_lincons0_t* lincons0); /* Convert an ap_lincons0_t into an itv_lincons_t cons points to an initialized object. Return true if the conversion is exact */ static inline bool itv_lincons_array_set_ap_lincons0_array(itv_internal_t* intern, itv_lincons_array_t* tcons, ap_lincons0_array_t* tlincons0); /* Convert an ap_lincons0_array_t into an itv_lincons_array_t tcons points to an initialized object. Return true if the conversion is exact */ static inline void ap_linexpr0_set_itv_linexpr(itv_internal_t* intern, ap_linexpr0_t** plinexpr0, itv_linexpr_t* linexpr); /* Convert an itv_linexpr_t into an ap_linexpr0_t. If the result *plinexpr0 is not NULL, possibly reinitialize *plinexpr0, otherwise allocate it. */ static inline void ap_lincons0_set_itv_lincons(itv_internal_t* intern, ap_lincons0_t* plincons0, itv_lincons_t* lincons); /* Convert an itv_linexpr_t into an ap_linexpr0_t. The result plincons0 is supposed initialized. */ /* ********************************************************************** */ /* III. Arithmetic */ /* ********************************************************************** */ static inline void itv_linexpr_neg(itv_linexpr_t* expr); /* Negate in-place an expression */ static inline void itv_linexpr_scale(itv_internal_t* intern, itv_linexpr_t* expr, itv_t coeff); /* Scale in-place an expression by an interval */ static inline void itv_linexpr_add(itv_internal_t* intern, itv_linexpr_t* expr, itv_linexpr_t* exprA, itv_linexpr_t* exprB); static inline void itv_linexpr_sub(itv_internal_t* intern, itv_linexpr_t* expr, itv_linexpr_t* exprA, itv_linexpr_t* exprB); /* Resp. add and substract two linear epxression. (Substraction temporarily negates exprB, and then restores it */ /* ********************************************************************** */ /* IV. Tests and Simplifications */ /* ********************************************************************** */ static inline bool itv_linexpr_is_integer(itv_linexpr_t* expr, size_t intdim); static inline bool itv_lincons_is_integer(itv_lincons_t* cons, size_t intdim); static inline bool itv_linexpr_is_scalar(itv_linexpr_t* expr); static inline bool itv_linexpr_is_quasilinear(itv_linexpr_t* expr); static inline bool itv_linexpr_is_integer(itv_linexpr_t* expr, size_t intdim); static inline bool itv_lincons_is_scalar(itv_lincons_t* expr); static inline bool itv_lincons_is_quasilinear(itv_lincons_t* expr); static inline bool itv_lincons_array_is_scalar(itv_lincons_array_t* array); static inline bool itv_lincons_array_is_quasilinear(itv_lincons_array_t* array); static inline bool itv_linexpr_is_integer(itv_linexpr_t* expr, size_t intdim); static inline bool itv_lincons_is_integer(itv_lincons_t* cons, size_t intdim); static inline tbool_t itv_eval_cstlincons(itv_internal_t* intern, itv_lincons_t* lincons); /* Is the assumed constant constraint satisfied ? */ static inline bool itv_sat_lincons_is_false(itv_internal_t* intern, itv_lincons_t* lincons); /* Return true if the constraint is not satisfiable *for all* deterministic expressions contained in it Cases taken into account: - expr + [a,A] = 0 (mod k) with a!=A - expr + [-oo,+oo] != 0 - expr + (-oo,x] >|>= 0 - the cases where itv_eval_cstlincons returns tbool_false */ static inline void itv_lincons_reduce_integer(itv_internal_t* intern, itv_lincons_t* cons, size_t intdim); /* Transform a constraint involving only integer variables and only scalar coefficients (with the exception of the constant) as follows: - divide expr by the pgcd of non-constant coefficients details differ according to type of num (integer, rational, floating-point) - expr + [min,sup] >= 0 ==> expr + floor(sup) >= 0 - expr + [min,sup] > 0 ==> expr + sup - 1 >= if sup is integer expr + floor(sup) >= 0 otherwise - expr + [min,sup] = 0 ==> expr + [ceil(min),floor(sup)] = 0 */ static inline tbool_t itv_lincons_array_reduce(itv_internal_t* intern, itv_lincons_array_t* array, bool meet); /* Simplify the array as follows: - remove trivially true constraints (like 1>=0) - if a constraint is trivially false, reduce the array to the constraint 1=0 Return - tbool_true if rmpty array - tbool_false if trivially false - tbool_top otherwise */ static inline tbool_t itv_lincons_array_reduce_integer(itv_internal_t* intern, itv_lincons_array_t* array, size_t intdim); /* Apply first itv_lincons_reduce_integer, and then itv_lincons_array_reduce(.,.,true) */ /* ********************************************************************** */ /* Definition of inline functions */ /* ********************************************************************** */ void ITVFUN(itv_linexpr_init)(itv_linexpr_t* expr, size_t size); void ITVFUN(itv_linexpr_init_set)(itv_linexpr_t* res, itv_linexpr_t* expr); void ITVFUN(itv_linexpr_set)(itv_linexpr_t* res, itv_linexpr_t* expr); void ITVFUN(itv_linexpr_reinit)(itv_linexpr_t* expr, size_t size); void ITVFUN(itv_linexpr_clear)(itv_linexpr_t* expr); void ITVFUN(itv_linexpr_fprint)(FILE* stream, itv_linexpr_t* expr, char** name); void ITVFUN(itv_lincons_set_bool)(itv_lincons_t* cons, bool value); void ITVFUN(itv_lincons_fprint)(FILE* stream, itv_lincons_t* cons, char** name); void ITVFUN(itv_lincons_array_init)(itv_lincons_array_t* array, size_t size); void ITVFUN(itv_lincons_array_reinit)(itv_lincons_array_t* array, size_t size); void ITVFUN(itv_lincons_array_clear)(itv_lincons_array_t* array); void ITVFUN(itv_lincons_array_fprint)(FILE* stream, itv_lincons_array_t* array, char** name); bool ITVFUN(itv_linexpr_set_ap_linexpr0)(itv_internal_t* intern, itv_linexpr_t* expr, ap_linexpr0_t* linexpr0); bool ITVFUN(itv_lincons_set_ap_lincons0)(itv_internal_t* intern, itv_lincons_t* cons, ap_lincons0_t* lincons0); bool ITVFUN(itv_lincons_array_set_ap_lincons0_array)(itv_internal_t* intern, itv_lincons_array_t* tcons, ap_lincons0_array_t* tlincons0); void ITVFUN(ap_linexpr0_set_itv_linexpr)(itv_internal_t* intern, ap_linexpr0_t** linexpr0, itv_linexpr_t* linexpr); void ITVFUN(ap_lincons0_set_itv_lincons)(itv_internal_t* intern, ap_lincons0_t* lincons0, itv_lincons_t* lincons); void ITVFUN(itv_linexpr_neg)(itv_linexpr_t* expr); void ITVFUN(itv_linexpr_scale)(itv_internal_t* intern, itv_linexpr_t* expr, itv_t coeff); void ITVFUN(itv_linexpr_div)(itv_internal_t* intern, itv_linexpr_t* expr, itv_t coeff); void ITVFUN(itv_linexpr_add)(itv_internal_t* intern, itv_linexpr_t* expr, itv_linexpr_t* exprA, itv_linexpr_t* exprB); void ITVFUN(itv_linexpr_sub)(itv_internal_t* intern, itv_linexpr_t* expr, itv_linexpr_t* exprA, itv_linexpr_t* exprB); bool ITVFUN(itv_linexpr_is_scalar)(itv_linexpr_t* expr); bool ITVFUN(itv_linexpr_is_quasilinear)(itv_linexpr_t* expr); bool ITVFUN(itv_lincons_array_is_scalar)(itv_lincons_array_t* array); bool ITVFUN(itv_lincons_array_is_quasilinear)(itv_lincons_array_t* array); bool ITVFUN(itv_linexpr_is_integer)(itv_linexpr_t* expr, size_t intdim); bool ITVFUN(itv_lincons_is_integer)(itv_lincons_t* cons, size_t intdim); tbool_t ITVFUN(itv_eval_cstlincons)(itv_internal_t* intern, itv_lincons_t* lincons); bool ITVFUN(itv_sat_lincons_is_false)(itv_internal_t* intern, itv_lincons_t* lincons); void ITVFUN(itv_lincons_reduce_integer)(itv_internal_t* intern, itv_lincons_t* cons, size_t intdim); tbool_t ITVFUN(itv_lincons_array_reduce)(itv_internal_t* intern, itv_lincons_array_t* array, bool meet); tbool_t ITVFUN(itv_lincons_array_reduce_integer)(itv_internal_t* intern, itv_lincons_array_t* array, size_t intdim); static inline void itv_linterm_init(itv_linterm_t* term) { itv_init(term->itv); term->equality = true; term->dim = AP_DIM_MAX; } static inline void itv_linterm_init_set(itv_linterm_t* res, itv_linterm_t* term) { itv_init_set(res->itv,term->itv); res->equality = term->equality; res->dim = term->dim; } static inline void itv_linterm_set(itv_linterm_t* res, itv_linterm_t* term) { itv_set(res->itv,term->itv); res->equality = term->equality; res->dim = term->dim; } static inline void itv_linterm_clear(itv_linterm_t* term) { itv_clear(term->itv); } static inline void itv_linterm_swap(itv_linterm_t* a, itv_linterm_t* b) { if (a!=b){ itv_linterm_t t=*a; *a=*b; *b=t; } } static inline void itv_linexpr_init(itv_linexpr_t* expr, size_t size) { ITVFUN(itv_linexpr_init)(expr,size); } static inline void itv_linexpr_init_set(itv_linexpr_t* res, itv_linexpr_t* expr) { ITVFUN(itv_linexpr_init_set)(res,expr); } static inline void itv_linexpr_set(itv_linexpr_t* res, itv_linexpr_t* expr) { ITVFUN(itv_linexpr_set)(res,expr); } static inline void itv_linexpr_reinit(itv_linexpr_t* expr, size_t size) { ITVFUN(itv_linexpr_reinit)(expr,size); } static inline void itv_linexpr_clear(itv_linexpr_t* expr) { ITVFUN(itv_linexpr_clear)(expr); } static inline void itv_linexpr_fprint(FILE* stream, itv_linexpr_t* expr, char** name) { ITVFUN(itv_linexpr_fprint)(stream,expr,name); } static inline void itv_linexpr_print(itv_linexpr_t* expr, char** name) { itv_linexpr_fprint(stdout,expr,name); } static inline void itv_lincons_init(itv_lincons_t* cons) { itv_linexpr_init(&cons->linexpr,0); num_init(cons->num); } static inline void itv_lincons_set(itv_lincons_t* a, itv_lincons_t* b) { if (a!=b){ itv_linexpr_set(&a->linexpr,&b->linexpr); num_set(a->num,b->num); a->constyp = b->constyp; } } static inline void itv_lincons_set_bool(itv_lincons_t* a, bool value) { ITVFUN(itv_lincons_set_bool)(a,value); } static inline void itv_lincons_clear(itv_lincons_t* cons) { itv_linexpr_clear(&cons->linexpr); num_clear(cons->num); } static inline void itv_lincons_fprint(FILE* stream, itv_lincons_t* cons, char** name) { ITVFUN(itv_lincons_fprint)(stream,cons,name); } static inline void itv_lincons_print(itv_lincons_t* cons, char** name) { itv_lincons_fprint(stdout,cons,name); } static inline void itv_lincons_swap(itv_lincons_t* a, itv_lincons_t* b) { if (a!=b){ itv_lincons_t t=*a; *a=*b; *b=t; } } static inline void itv_lincons_array_init(itv_lincons_array_t* array, size_t size) { ITVFUN(itv_lincons_array_init)(array,size); } static inline void itv_lincons_array_reinit(itv_lincons_array_t* array, size_t size) { ITVFUN(itv_lincons_array_reinit)(array,size); } static inline void itv_lincons_array_clear(itv_lincons_array_t* array) { ITVFUN(itv_lincons_array_clear)(array); } static inline void itv_lincons_array_fprint(FILE* stream, itv_lincons_array_t* array, char** name) { ITVFUN(itv_lincons_array_fprint)(stream,array,name); } static inline void itv_lincons_array_print(itv_lincons_array_t* array, char** name) { itv_lincons_array_fprint(stdout,array,name); } static inline bool itv_linexpr_set_ap_linexpr0(itv_internal_t* intern, itv_linexpr_t* expr, ap_linexpr0_t* linexpr0) { return ITVFUN(itv_linexpr_set_ap_linexpr0)(intern,expr,linexpr0); } static inline bool itv_lincons_set_ap_lincons0(itv_internal_t* intern, itv_lincons_t* cons, ap_lincons0_t* lincons0) { return ITVFUN(itv_lincons_set_ap_lincons0)(intern,cons,lincons0); } static inline bool itv_lincons_array_set_ap_lincons0_array(itv_internal_t* intern, itv_lincons_array_t* tcons, ap_lincons0_array_t* tlincons0) { return ITVFUN(itv_lincons_array_set_ap_lincons0_array)(intern,tcons,tlincons0); } static inline void ap_linexpr0_set_itv_linexpr(itv_internal_t* intern, ap_linexpr0_t** expr, itv_linexpr_t* linexpr0) { ITVFUN(ap_linexpr0_set_itv_linexpr)(intern,expr,linexpr0); } static inline void ap_lincons0_set_itv_lincons(itv_internal_t* intern, ap_lincons0_t* cons, itv_lincons_t* lincons0) { ITVFUN(ap_lincons0_set_itv_lincons)(intern,cons,lincons0); } static inline void itv_linexpr_neg(itv_linexpr_t* expr) { ITVFUN(itv_linexpr_neg)(expr); } static inline void itv_linexpr_scale(itv_internal_t* intern, itv_linexpr_t* expr, itv_t coeff) { ITVFUN(itv_linexpr_scale)(intern,expr,coeff); } static inline void itv_linexpr_div(itv_internal_t* intern, itv_linexpr_t* expr, itv_t coeff) { ITVFUN(itv_linexpr_div)(intern,expr,coeff); } static inline void itv_linexpr_add(itv_internal_t* intern, itv_linexpr_t* expr, itv_linexpr_t* exprA, itv_linexpr_t* exprB) { ITVFUN(itv_linexpr_add)(intern,expr,exprA,exprB); } static inline void itv_linexpr_sub(itv_internal_t* intern, itv_linexpr_t* expr, itv_linexpr_t* exprA, itv_linexpr_t* exprB) { ITVFUN(itv_linexpr_sub)(intern,expr,exprA,exprB); } static inline bool itv_linexpr_is_scalar(itv_linexpr_t* expr) { return ITVFUN(itv_linexpr_is_scalar)(expr); } static inline bool itv_linexpr_is_quasilinear(itv_linexpr_t* expr) { return ITVFUN(itv_linexpr_is_quasilinear)(expr); } static inline bool itv_lincons_is_scalar(itv_lincons_t* cons) { return ITVFUN(itv_linexpr_is_scalar)(&cons->linexpr); } static inline bool itv_lincons_is_quasilinear(itv_lincons_t* cons) { return ITVFUN(itv_linexpr_is_quasilinear)(&cons->linexpr); } static inline bool itv_lincons_array_is_scalar(itv_lincons_array_t* array) { return ITVFUN(itv_lincons_array_is_scalar)(array); } static inline bool itv_lincons_array_is_quasilinear(itv_lincons_array_t* array) { return ITVFUN(itv_lincons_array_is_quasilinear)(array); } static inline bool itv_linexpr_is_integer(itv_linexpr_t* expr, size_t intdim) { return ITVFUN(itv_linexpr_is_integer)(expr,intdim); } static inline bool itv_lincons_is_integer(itv_lincons_t* cons, size_t intdim) { return ITVFUN(itv_linexpr_is_integer)(&cons->linexpr,intdim); } static inline tbool_t itv_eval_cstlincons(itv_internal_t* intern, itv_lincons_t* lincons) { return ITVFUN(itv_eval_cstlincons)(intern,lincons); } static inline bool itv_sat_lincons_is_false(itv_internal_t* intern, itv_lincons_t* lincons) { return ITVFUN(itv_sat_lincons_is_false)(intern,lincons); } static inline void itv_lincons_reduce_integer(itv_internal_t* intern, itv_lincons_t* cons, size_t intdim) { ITVFUN(itv_lincons_reduce_integer)(intern,cons,intdim); } static inline tbool_t itv_lincons_array_reduce(itv_internal_t* intern, itv_lincons_array_t* array, bool meet) { return ITVFUN(itv_lincons_array_reduce)(intern,array,meet); } static inline tbool_t itv_lincons_array_reduce_integer(itv_internal_t* intern, itv_lincons_array_t* array, size_t intdim) { return ITVFUN(itv_lincons_array_reduce_integer)(intern,array,intdim); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/itv/COPYING0000640014525101416610000006403310555673727016550 0ustar bjeannetpopart This license applies to all files distributed in the APRON library, including all source code, libraries, binaries, and documentation. Copyright (C) Bertrand Jeannet and Antoine Miné 2006 for the itv subpackage. GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! apron-dist-0.9.10/apron/itv/itv_linearize.h0000640014525101416610000002566011122221351020502 0ustar bjeannetpopart/* ********************************************************************** */ /* itv_linearize.c: */ /* ********************************************************************** */ #ifndef _ITV_LINEARIZE_H_ #define _ITV_LINEARIZE_H_ #include "itv.h" #include "itv_linexpr.h" #include "ap_expr0.h" #ifdef __cplusplus extern "C" { #endif /* ********************************************************************** */ /* I. Evaluation of expressions */ /* ********************************************************************** */ static inline void itv_eval_linexpr(itv_internal_t* intern, itv_t itv, itv_linexpr_t* expr, itv_t* env); /* Evaluate the interval linear expression, using the array p[] associating intervals to dimensions */ static inline bool itv_eval_ap_linexpr0(itv_internal_t* intern, itv_t itv, ap_linexpr0_t* expr, itv_t* env); /* Evaluate the interval linear expression, using the array p[] associating intervals to dimensions. Return true if all conversions were exact */ /* ********************************************************************** */ /* II. Boxization of interval linear expressions */ /* ********************************************************************** */ static inline bool itv_boxize_lincons_array(itv_internal_t* intern, itv_t* res, bool* tchange, itv_lincons_array_t* array, itv_t* env,size_t intdim, size_t kmax, bool intervalonly); /* Deduce interval constraints from a set of interval linear constraints. Return true if some bounds have been inferred. - The inferred bounds are stored in res (which may be equal to env) - If tchange!=NULL, tchange[2dim] (resp. 2dim+1) set to true indicates that the inf (resp. sup) bound of dimension dim has been improved. - env is the current bounds for variables - kmax specifies the maximum number of iterations - if intervalonly is true, deduces bounds from a constraint only when the coefficient associated to the current dimension is an interval. */ /* ********************************************************************** */ /* III. (Quasi)linearisation of interval linear expressions and constraints */ /* ********************************************************************** */ /* These functions return true if there were no rounding in computations. They may perform simplifications, which are valid - for intersecting constraints, when parameter meet is true - for testing satisfaction, when parameter meet is false */ static inline bool itv_quasilinearize_linexpr(itv_internal_t* intern, itv_linexpr_t* linexpr, itv_t* env, bool for_meet_inequality); /* Quasilinearize in-place linexpr using the bounding box itv */ static inline bool itv_quasilinearize_lincons(itv_internal_t* intern, itv_lincons_t* lincons, itv_t* env, bool meet); /* Quasilinearize in-place lincons using the bounding box itv */ static inline bool itv_quasilinearize_lincons_array(itv_internal_t* intern, itv_lincons_array_t* tlincons, itv_t* env, bool meet); /* (Quasi)linearize in-place tlincons using the bounding box itv */ static inline void itv_linearize_lincons_array(itv_internal_t* intern, itv_lincons_array_t* tlincons, bool meet); /* Linearize in-place quasilinear tlincons using the bounding box itv */ /* ********************************************************************** */ /* IV. Evaluation of tree expressions */ /* ********************************************************************** */ static inline void itv_eval_ap_texpr0(itv_internal_t* intern, itv_t res, ap_texpr0_t* expr, itv_t* env); /* ********************************************************************** */ /* V. Linearisation of linear tree expressions. */ /* ********************************************************************** */ /* Linearize a tree expression that is (syntaxically) linear with exact arithmetic. Compared to itv_intlinearize_ap_XX() functions below, these functions does not require a bounding box for dimensions. If the precondition is violated, the result may be unsound. Return true in case of problem (non linear tree expression). */ static inline bool itv_intlinearize_ap_texpr0_intlinear(itv_internal_t* intern, itv_linexpr_t* res, ap_texpr0_t* expr); static inline bool itv_intlinearize_ap_tcons0_intlinear(itv_internal_t* intern, itv_lincons_t* res, ap_tcons0_t* cons); static inline bool itv_intlinearize_ap_tcons0_array_intlinear(itv_internal_t* intern, itv_lincons_array_t* res, ap_tcons0_array_t* cons); /* ********************************************************************** */ /* VI. Linearisation of tree expressions. */ /* ********************************************************************** */ /* These functions returns true if the linearization return in an empty expression (of type [1;-1]). This may happen when linearizing sqrt(-1), for instance. They may perform simplifications, which are valid - for intersecting constraints, when parameter meet is true - for testing satisfaction, when parameter meet is false */ static inline bool itv_intlinearize_ap_texpr0(itv_internal_t* intern, itv_linexpr_t* res, ap_texpr0_t* expr, itv_t* env, size_t intdim); static inline bool itv_intlinearize_ap_tcons0(itv_internal_t* intern, itv_lincons_t* res, ap_tcons0_t* cons, itv_t* env, size_t intdim); static inline bool itv_intlinearize_ap_tcons0_array(itv_internal_t* intern, itv_lincons_array_t* res, ap_tcons0_array_t* cons, itv_t* env, size_t intdim); /* ********************************************************************** */ /* Prototypes of functions */ /* ********************************************************************** */ /* I. Evaluation of expressions */ void ITVFUN(itv_eval_linexpr)(itv_internal_t* intern, itv_t itv, itv_linexpr_t* expr, itv_t* env); bool ITVFUN(itv_eval_ap_linexpr0)(itv_internal_t* intern, itv_t itv, ap_linexpr0_t* expr, itv_t* env); /* II. Boxization of interval linear expressions */ bool ITVFUN(itv_boxize_lincons_array)(itv_internal_t* intern, itv_t* res, bool* change, itv_lincons_array_t* array, itv_t* env, size_t intdim, size_t kmax, bool intervalonly); /* III. (Quasi)linearisation of interval linear expressions and constraints */ bool ITVFUN(itv_quasilinearize_linexpr)(itv_internal_t* intern, itv_linexpr_t* linexpr, itv_t* env, bool for_meet_inequality); bool ITVFUN(itv_quasilinearize_lincons)(itv_internal_t* intern, itv_lincons_t* lincons, itv_t* env, bool meet); bool ITVFUN(itv_quasilinearize_lincons_array)(itv_internal_t* intern, itv_lincons_array_t* tlincons, itv_t* env, bool meet); void ITVFUN(itv_linearize_lincons_array)(itv_internal_t* intern, itv_lincons_array_t* array, bool meet); /* IV. Evaluation of tree expressions */ void ITVFUN(itv_eval_ap_texpr0)(itv_internal_t* intern, itv_t itv, ap_texpr0_t* expr, itv_t* env); /* V. Linearisation of linear tree expressions. */ bool ITVFUN(itv_intlinearize_ap_texpr0_intlinear)(itv_internal_t* intern, itv_linexpr_t* res, ap_texpr0_t* expr); bool ITVFUN(itv_intlinearize_ap_tcons0_intlinear)(itv_internal_t* intern,itv_lincons_t* res, ap_tcons0_t* cons); bool ITVFUN(itv_intlinearize_ap_tcons0_array_intlinear)(itv_internal_t* intern,itv_lincons_array_t* res, ap_tcons0_array_t* cons); /* VI. Linearisation of tree expressions. */ bool ITVFUN(itv_intlinearize_ap_texpr0)(itv_internal_t* intern,itv_linexpr_t* res,ap_texpr0_t* expr,itv_t* env, size_t intdim); bool ITVFUN(itv_intlinearize_ap_tcons0)(itv_internal_t* intern,itv_lincons_t* res, ap_tcons0_t* cons, itv_t* env, size_t intdim); bool ITVFUN(itv_intlinearize_ap_tcons0_array)(itv_internal_t* intern,itv_lincons_array_t* res, ap_tcons0_array_t* cons, itv_t* env, size_t intdim); /* ********************************************************************** */ /* Definition of inline functions */ /* ********************************************************************** */ /* I. Evaluation of expressions */ static inline void itv_eval_linexpr(itv_internal_t* intern, itv_t itv, itv_linexpr_t* expr, itv_t* env) { ITVFUN(itv_eval_linexpr)(intern,itv,expr,env); } static inline bool itv_eval_ap_linexpr0(itv_internal_t* intern, itv_t itv, ap_linexpr0_t* expr, itv_t* env) { return ITVFUN(itv_eval_ap_linexpr0)(intern,itv,expr,env); } /* II. Boxization of interval linear expressions */ static inline bool itv_boxize_lincons_array(itv_internal_t* intern, itv_t* res, bool* tchange, itv_lincons_array_t* array, itv_t* env, size_t intdim, size_t kmax, bool intervalonly) { return ITVFUN(itv_boxize_lincons_array)(intern,res,tchange,array,env,intdim,kmax,intervalonly); } /* III. (Quasi)linearisation of interval linear expressions and constraints */ static inline bool itv_quasilinearize_linexpr(itv_internal_t* intern, itv_linexpr_t* linexpr, itv_t* env, bool for_ineq) { return ITVFUN(itv_quasilinearize_linexpr)(intern,linexpr,env, for_ineq); } static inline bool itv_quasilinearize_lincons(itv_internal_t* intern, itv_lincons_t* lincons, itv_t* env, bool meet) { return ITVFUN(itv_quasilinearize_lincons)(intern,lincons,env,meet); } static inline bool itv_quasilinearize_lincons_array(itv_internal_t* intern, itv_lincons_array_t* tlincons, itv_t* env, bool meet) { return ITVFUN(itv_quasilinearize_lincons_array)(intern,tlincons,env,meet); } static inline void itv_linearize_lincons_array(itv_internal_t* intern, itv_lincons_array_t* array, bool meet) { ITVFUN(itv_linearize_lincons_array)(intern,array,meet); } /* IV. Evaluation of tree expressions */ static inline void itv_eval_ap_texpr0(itv_internal_t* intern, itv_t itv, ap_texpr0_t* expr, itv_t* env) { ITVFUN(itv_eval_ap_texpr0)(intern,itv,expr,env); } /* V. Linearisation of linear tree expressions. */ static inline bool itv_intlinearize_ap_texpr0_intlinear(itv_internal_t* intern, itv_linexpr_t* linexpr, ap_texpr0_t* expr) { return ITVFUN(itv_intlinearize_ap_texpr0_intlinear)(intern,linexpr,expr); } static inline bool itv_intlinearize_ap_tcons0_intlinear(itv_internal_t* intern, itv_lincons_t* lincons, ap_tcons0_t* cons) { return ITVFUN(itv_intlinearize_ap_tcons0_intlinear)(intern,lincons,cons); } static inline bool itv_intlinearize_ap_tcons0_array_intlinear(itv_internal_t* intern, itv_lincons_array_t* tlincons, ap_tcons0_array_t* tcons) { return ITVFUN(itv_intlinearize_ap_tcons0_array_intlinear)(intern,tlincons,tcons); } /* VI. Linearisation of tree expressions. */ static inline bool itv_intlinearize_ap_texpr0(itv_internal_t* intern, itv_linexpr_t* linexpr, ap_texpr0_t* expr, itv_t* env, size_t intdim) { return ITVFUN(itv_intlinearize_ap_texpr0)(intern,linexpr,expr,env,intdim); } static inline bool itv_intlinearize_ap_tcons0(itv_internal_t* intern, itv_lincons_t* lincons, ap_tcons0_t* cons, itv_t* env, size_t intdim) { return ITVFUN(itv_intlinearize_ap_tcons0)(intern,lincons,cons,env,intdim); } static inline bool itv_intlinearize_ap_tcons0_array(itv_internal_t* intern, itv_lincons_array_t* tlincons, ap_tcons0_array_t* tcons, itv_t* env, size_t intdim) { return ITVFUN(itv_intlinearize_ap_tcons0_array)(intern,tlincons,tcons,env,intdim); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/itv/Makefile0000640014525101416610000001360311251675166017143 0ustar bjeannetpopart include ../Makefile.config PREFIX = $(APRON_PREFIX) SRCDIR = $(shell pwd) #--------------------------------------- # Flags #--------------------------------------- # Use ICFLAGS to specify machine-independent compilation flags. ICFLAGS = \ -I../num \ -I../apron \ -I$(GMP_PREFIX)/include \ -I$(MPFR_PREFIX)/include #--------------------------------------- # Files #--------------------------------------- CCMODULES = itv itv_linexpr itv_linearize CCSRC = itv_config.h itv_fun.h $(CCMODULES:%=%.h) $(CCMODULES:%=%.c) CCINC_TO_INSTALL = itv.h itv_fun.h itv_config.h itv_linexpr.h itv_linearize.h CCBIN_TO_INSTALL = CCLIB_TO_INSTALL = \ libitvIl.a libitvIl_debug.a \ libitvIll.a libitvIll_debug.a \ libitvRl.a libitvRl_debug.a \ libitvRll.a libitvRll_debug.a \ libitvMPZ.a libitvMPZ_debug.a \ libitvMPQ.a libitvMPQ_debug.a \ libitvD.a libitvD_debug.a \ libitvMPFR.a libitvMPFR_debug.a \ libitv.a libitv_debug.a ifneq ($(HAS_LONG_DOUBLE),) CCLIB_TO_INSTALL := $(CCLIB_TO_INSTALL) libitvDl.a libitvDl_debug.a endif OFILES = $(CCMODULES:%=%Il.o) $(CCMODULES:%=%Ill.o) $(CCMODULES:%=%Rl.o) $(CCMODULES:%=%Rll.o) $(CCMODULES:%=%MPZ.o) $(CCMODULES:%=%MPQ.o) $(CCMODULES:%=%D.o) $(CCMODULES:%=%MPFR.o) ifneq ($(HAS_LONG_DOUBLE),) OFILES := $(OFILES) $(CCMODULES:%=%Dl.o) endif #--------------------------------------- # Rules #--------------------------------------- # Possible goals: # depend doc install # and the following one all: allMPQ allRll allD allMPFR libitv.a libitv_debug.a allMPQ: libitvMPQ.a libitvMPQ_debug.a allRll: libitvRll.a libitvRll_debug.a allD: libitvD.a libitvD_debug.a allMPFR: libitvMPFR.a libitvMPFR_debug.a tests: testMPQ testRll testD testMPFR test2MPQ test2Rll test2D test2MPFR clean: /bin/rm -f *.[ao] testMPQ testRll testD testMPFR test2MPQ test2Rll test2D test2MPFR /bin/rm -f *.?.tex *.log *.aux *.bbl *.blg *.toc *.dvi *.ps *.pstex* mostlyclean: clean install: $(CCINC_TO_INSTALL) $(CCLIB_TO_INSTALL) $(INSTALLd) $(PREFIX)/include $(PREFIX)/lib $(INSTALL) $(CCINC_TO_INSTALL) $(PREFIX)/include for i in $(CCLIB_TO_INSTALL); do \ if test -f $$i; then $(INSTALL) $$i $(PREFIX)/lib; fi; \ done # for i in $(CCBIN_TO_INSTALL); do \ # if test -f $$i; then $(INSTALL) $$i $(PREFIX)/bin; fi; \ # done distclean: for i in $(CCINC_TO_INSTALL); do /bin/rm -f $(PREFIX)/include/$$i; done for i in $(CCLIB_TO_INSTALL); do /bin/rm -f $(PREFIX)/lib/$$i; done for i in $(CCBIN_TO_INSTALL); do /bin/rm -f $(PREFIX)/bin/$$i; done /bin/rm -f Makefile.depend dist: $(CCSRC) Makefile COPYING README (cd ..; tar zcvf itv.tgz $(^:%=itv/%)) #--------------------------------------- # IMPLICIT RULES AND DEPENDENCIES #--------------------------------------- .SUFFIXES: .tex .c .h .a .o #----------------------------------- # C part #----------------------------------- libitv.a: $(OFILES) $(AR) rcs $@ $^ $(RANLIB) $@ libitv_debug.a: $(OFILES:%.o=%_debug.o) $(AR) rcs $@ $^ $(RANLIB) $@ libitv%.a: $(subst .c,%.o,$(CCMODULES:%=%.c)) $(AR) rcs $@ $^ $(RANLIB) $@ libitv%_debug.a: $(subst .c,%_debug.o,$(CCMODULES:%=%.c)) $(AR) rcs $@ $^ $(RANLIB) $@ %Il.o: %.c $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_LONGINT -c -o $@ $< %Il_debug.o: %.c $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_LONGINT -c -o $@ $< %Ill.o: %.c $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_LONGLONGINT -c -o $@ $< %Ill_debug.o: %.c $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_LONGLONGINT -c -o $@ $< %Rl.o: %.c $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_LONGRAT -c -o $@ $< %Rl_debug.o: %.c $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_LONGRAT -c -o $@ $< %Rll.o: %.c $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_LONGLONGRAT -c -o $@ $< %Rll_debug.o: %.c $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_LONGLONGRAT -c -o $@ $< %MPZ.o: %.c $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_MPZ -c -o $@ $< %MPZ_debug.o: %.c $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_MPZ -c -o $@ $< %MPQ.o: %.c $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_MPQ -c -o $@ $< %MPQ_debug.o: %.c $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_MPQ -c -o $@ $< %D.o: %.c $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_DOUBLE -c -o $@ $< %D_debug.o: %.c $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_DOUBLE -c -o $@ $< %Dl.o: %.c $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_LONGDOUBLE -c -o $@ $< %Dl_debug.o: %.c $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_LONGDOUBLE -c -o $@ $< %MPFR.o: %.c $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_MPFR -c -o $@ $< %MPFR_debug.o: %.c $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_MPFR -c -o $@ $< testMPQ: testMPQ_debug.o libitvMPQ_debug.a $(CC) $(CFLAGS_DEBUG) -L. -L$(GMP_PREFIX)/lib -L../apron -o $@ $< -litvMPQ_debug -lapron_debug -lgmp -lmpfr -lm testRll: testRll_debug.o libitvRll_debug.a $(CC) $(CFLAGS_DEBUG) -L. -L$(GMP_PREFIX)/lib -L../apron -o $@ $< -litvRll_debug -lapron_debug -lgmp -lmpfr -lm testD: testD_debug.o libitvD_debug.a $(CC) $(CFLAGS_DEBUG) -L. -L$(GMP_PREFIX)/lib -L../apron -o $@ $< -litvD_debug -lapron_debug -lgmp -lmpfr -lm testMPFR: testMPFR_debug.o libitvMPFR_debug.a $(CC) $(CFLAGS_DEBUG) -L. -L$(GMP_PREFIX)/lib -L../apron -o $@ $< -litvMPFR_debug -lapron_debug -lgmp -lmpfr -lm test2MPQ: testMPQ_debug.o libitvMPQ_debug.a $(CC) $(CFLAGS_DEBUG) -L. -L$(GMP_PREFIX)/lib -L../apron -o $@ $< -litvMPQ_debug -lapron_debug -lgmp -lmpfr -lm test2Rll: testRll_debug.o libitvRll_debug.a $(CC) $(CFLAGS_DEBUG) -L. -L$(GMP_PREFIX)/lib -L../apron -o $@ $< -litvRll_debug -lapron_debug -lgmp -lmpfr -lm test2D: testD_debug.o libitvD_debug.a $(CC) $(CFLAGS_DEBUG) -L. -L$(GMP_PREFIX)/lib -L../apron -o $@ $< -litvD_debug -lapron_debug -lgmp -lmpfr -lm test2MPFR: testMPFR_debug.o libitvMPFR_debug.a $(CC) $(CFLAGS_DEBUG) -L. -L$(GMP_PREFIX)/lib -L../apron -o $@ $< -litvMPFR_debug -lapron_debug -lgmp -lmpfr -lm out: tests ./testMPQ > out.MPQ ./test2MPQ > out2.MPQ ./testMPFR > out.MPFR ./test2MPFR > out2.MPFR ./testRll > out.Rll ./test2Rll > out2.Rll ./testD > out.D ./test2D > out2.D #----------------------------------- # DEPENDENCIES #----------------------------------- itv%.o: itv.c itv.h itv_fun.h itv_linexpr%.o: itv_linexpr.c itv_linexpr.h itv.h itv_fun.h apron-dist-0.9.10/apron/itv/itv_linexpr.c0000640014525101416610000005242311164715535020213 0ustar bjeannetpopart/* ********************************************************************** */ /* itv_linexpr.c: */ /* ********************************************************************** */ #include "itv_linexpr.h" /* ********************************************************************** */ /* I. Constructor and Destructor */ /* ********************************************************************** */ void ITVFUN(itv_linexpr_init)(itv_linexpr_t* expr, size_t size) { expr->linterm = NULL; expr->size = 0; itv_init(expr->cst); expr->equality = true; itv_linexpr_reinit(expr,size); } void ITVFUN(itv_linexpr_init_set)(itv_linexpr_t* res, itv_linexpr_t* expr) { size_t i; itv_init_set(res->cst,expr->cst); res->equality = expr->equality; res->linterm = expr->size ? malloc(expr->size*sizeof(itv_linterm_t)) : NULL; for (i=0;isize;i++){ itv_linterm_init_set(&res->linterm[i],&expr->linterm[i]); } res->size = expr->size; } void ITVFUN(itv_linexpr_set)(itv_linexpr_t* res, itv_linexpr_t* expr) { size_t i,size; if (res==expr) return; itv_set(res->cst,expr->cst); res->equality = expr->equality; for (i=expr->size; isize; i++){ itv_linterm_clear(&res->linterm[i]); } res->linterm = realloc(res->linterm,expr->size*sizeof(itv_linterm_t)); size = res->size < expr->size ? res->size : expr->size; for (i=0;ilinterm[i],&expr->linterm[i]); } for (i=size; isize;i++){ itv_linterm_init_set(&res->linterm[i],&expr->linterm[i]); } res->size = expr->size; } void ITVFUN(itv_linexpr_reinit)(itv_linexpr_t* expr, size_t size) { size_t i; for (i=size; isize; i++){ itv_linterm_clear(&expr->linterm[i]); } expr->linterm = realloc(expr->linterm,size*sizeof(itv_linterm_t)); for (i=expr->size;ilinterm[i]); } expr->size = size; return; } void ITVFUN(itv_linexpr_clear)(itv_linexpr_t* expr) { size_t i; if (expr->linterm){ for (i=0;isize;i++){ itv_linterm_clear(&expr->linterm[i]); } free(expr->linterm); expr->linterm = NULL; expr->size = 0; } itv_clear(expr->cst); } void ITVFUN(itv_linexpr_fprint)(FILE* stream, itv_linexpr_t* expr, char** name) { itv_linexpr_t* e; size_t i; ap_dim_t dim; itv_ptr pitv; bool* peq; itv_fprint(stream,expr->cst); itv_linexpr_ForeachLinterm(expr,i,dim,pitv,peq) { fprintf(stream, " + "); itv_fprint(stream,pitv); if (name) fprintf(stream,"%s",name[dim]); else fprintf(stream,"x%lu",(unsigned long)dim); } } void ITVFUN(itv_lincons_set_bool)(itv_lincons_t* lincons, bool value) { /* constraint 0=0 if value, 1=0 otherwise */ itv_linexpr_reinit(&lincons->linexpr,0); itv_set_int(lincons->linexpr.cst,value ? 0 : 1); lincons->linexpr.equality = true; lincons->constyp = AP_CONS_EQ; } void ITVFUN(itv_lincons_fprint)(FILE* stream, itv_lincons_t* cons, char** name) { ITVFUN(itv_linexpr_fprint)(stream,&cons->linexpr,name); fprintf(stream, cons->constyp == AP_CONS_EQ || cons->constyp == AP_CONS_EQMOD ? " = 0" : ( cons->constyp == AP_CONS_SUPEQ ? " >= 0" : (cons->constyp == AP_CONS_SUP ? " > 0" : "\"ERROR in itv_lincons_fprint\""))); if (cons->constyp == AP_CONS_EQMOD){ fprintf(stream," mod "); num_fprint(stream,cons->num); } } void ITVFUN(itv_lincons_array_init)(itv_lincons_array_t* array, size_t size) { size_t i; array->size = size; array->p = malloc(size*sizeof(itv_lincons_t)); for (i=0; ip[i]); } void ITVFUN(itv_lincons_array_reinit)(itv_lincons_array_t* array, size_t size) { size_t i; if (size == array->size) return; if (size < array->size){ for (i=size; isize; i++){ itv_lincons_clear(&array->p[i]); } array->p = realloc(array->p,size*sizeof(itv_lincons_t)); } else { /* size > array->size */ array->p = realloc(array->p,size*sizeof(itv_lincons_t)); for (i=array->size; ip[i]); } } array->size = size; return; } void ITVFUN(itv_lincons_array_clear)(itv_lincons_array_t* array) { size_t i; for (i=0; isize; i++) itv_lincons_clear(&array->p[i]); free(array->p); array->size = 0; array->p = NULL; } void ITVFUN(itv_lincons_array_fprint)(FILE* stream, itv_lincons_array_t* array, char** name) { size_t i; fprintf(stream,"array of size %d\n",(int)array->size); for (i=0; isize; i++){ itv_lincons_fprint(stream,&array->p[i],name); fprintf(stream,"\n"); } } /* ********************************************************************** */ /* II. Conversions from and to APRON datatypes */ /* ********************************************************************** */ bool ITVFUN(itv_linexpr_set_ap_linexpr0)(itv_internal_t* intern, itv_linexpr_t* expr, ap_linexpr0_t* linexpr0) { size_t i,k,size; ap_dim_t dim; ap_coeff_t* coeff; bool res,exact, eq; size=0; ap_linexpr0_ForeachLinterm(linexpr0,i,dim,coeff){ size++; } itv_linexpr_reinit(expr,size); exact = itv_set_ap_coeff(intern, expr->cst, &linexpr0->cst); expr->equality = exact && linexpr0->cst.discr==AP_COEFF_SCALAR; res = exact; k = 0; ap_linexpr0_ForeachLinterm(linexpr0,i,dim,coeff){ exact = itv_set_ap_coeff(intern, expr->linterm[k].itv, coeff); if (!itv_is_zero(expr->linterm[k].itv)){ eq = exact && coeff->discr==AP_COEFF_SCALAR; res = res && exact; expr->linterm[k].equality = eq; expr->linterm[k].dim = dim; k++; } } itv_linexpr_reinit(expr,k); return res; } bool ITVFUN(itv_lincons_set_ap_lincons0)(itv_internal_t* intern, itv_lincons_t* cons, ap_lincons0_t* lincons0) { bool exact1 = itv_linexpr_set_ap_linexpr0(intern, &cons->linexpr, lincons0->linexpr0); cons->constyp = lincons0->constyp; if (lincons0->scalar){ bool exact2 = num_set_ap_scalar(cons->num,lincons0->scalar); return exact1 && exact2; } else { num_set_int(cons->num,0); return exact1; } } bool ITVFUN(itv_lincons_array_set_ap_lincons0_array)(itv_internal_t* intern, itv_lincons_array_t* tcons, ap_lincons0_array_t* tlincons0) { size_t i; bool exact = true; itv_lincons_array_reinit(tcons,tlincons0->size); for (i=0; isize; i++){ exact = itv_lincons_set_ap_lincons0(intern,&tcons->p[i],&tlincons0->p[i]) && exact; } return exact; } void ITVFUN(ap_linexpr0_set_itv_linexpr)(itv_internal_t* intern, ap_linexpr0_t** plinexpr0, itv_linexpr_t* linexpr) { ap_linexpr0_t* linexpr0; size_t i,k; ap_dim_t dim; bool* peq; itv_ptr pitv; linexpr0 = *plinexpr0; if (linexpr0==NULL){ linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,linexpr->size); } else { ap_linexpr0_realloc(linexpr0,linexpr->size); } ap_coeff_set_itv(intern,&linexpr0->cst,linexpr->cst); k = 0; itv_linexpr_ForeachLinterm(linexpr,i,dim,pitv,peq){ linexpr0->p.linterm[k].dim = dim; ap_coeff_set_itv(intern,&linexpr0->p.linterm[k].coeff,pitv); k++; } *plinexpr0 = linexpr0; return; } void ITVFUN(ap_lincons0_set_itv_lincons)(itv_internal_t* intern, ap_lincons0_t* plincons0, itv_lincons_t* lincons) { ap_linexpr0_set_itv_linexpr(intern,&plincons0->linexpr0,&lincons->linexpr); plincons0->constyp = lincons->constyp; if (num_sgn(lincons->num)){ if (plincons0->scalar==NULL){ plincons0->scalar = ap_scalar_alloc(); } ap_scalar_set_num(plincons0->scalar,lincons->num); } else { if (plincons0->scalar!=NULL){ ap_scalar_free(plincons0->scalar); plincons0->scalar = NULL; } } } /* ********************************************************************** */ /* III. Arithmetic */ /* ********************************************************************** */ void ITVFUN(itv_linexpr_neg)(itv_linexpr_t* expr) { size_t i; ap_dim_t dim; bool* peq; itv_ptr pitv; itv_neg(expr->cst,expr->cst); itv_linexpr_ForeachLinterm(expr,i,dim,pitv,peq){ itv_neg(pitv,pitv); } return; } void ITVFUN(itv_linexpr_scale)(itv_internal_t* intern, itv_linexpr_t* expr, itv_t coeff) { size_t i; ap_dim_t dim; bool* peq; itv_ptr pitv; if (itv_is_zero(coeff)){ itv_set(expr->cst,coeff); itv_linexpr_reinit(expr,0); return; } itv_mul(intern,expr->cst,expr->cst,coeff); if (itv_is_top(expr->cst)){ itv_linexpr_reinit(expr,0); return; } else { itv_linexpr_ForeachLinterm(expr,i,dim,pitv,peq){ itv_mul(intern,pitv,pitv,coeff); *peq = *peq /* speed-up */ && itv_is_point(intern,pitv); } } return; } void ITVFUN(itv_linexpr_div)(itv_internal_t* intern, itv_linexpr_t* expr, itv_t coeff) { size_t i; ap_dim_t dim; bool* peq; itv_ptr pitv; itv_div(intern,expr->cst,expr->cst,coeff); itv_linexpr_ForeachLinterm(expr,i,dim,pitv,peq){ itv_div(intern,pitv,pitv,coeff); *peq = *peq /* speed-up */ && itv_is_point(intern,pitv); } return; } void ITVFUN(itv_linexpr_add)(itv_internal_t* intern, itv_linexpr_t* res, itv_linexpr_t* exprA, itv_linexpr_t* exprB) { size_t i,j,k; itv_linexpr_t expr; bool endA,endB; if (res==exprA || res==exprB){ itv_linexpr_init(&expr,exprA->size+exprB->size); } else { expr = *res; itv_linexpr_reinit(&expr,exprA->size+exprB->size); } i = j = k = 0; endA = endB = false; itv_add(expr.cst,exprA->cst,exprB->cst); expr.equality = exprA->equality && exprB->equality && itv_is_point(intern,expr.cst); if (itv_is_top(expr.cst)) goto _itv_linexpr_add_return; while (true){ endA = endA || (i==exprA->size) || exprA->linterm[i].dim == AP_DIM_MAX; endB = endB || (j==exprB->size) || exprB->linterm[j].dim == AP_DIM_MAX; if (endA && endB) break; if (endA || (!endB && exprB->linterm[j].dim < exprA->linterm[i].dim)){ itv_set(expr.linterm[k].itv, exprB->linterm[j].itv); expr.linterm[k].equality = exprB->linterm[j].equality; expr.linterm[k].dim = exprB->linterm[j].dim; k++; j++; } else if (endB || (!endA && exprA->linterm[i].dim < exprB->linterm[j].dim)){ itv_set(expr.linterm[k].itv, exprA->linterm[i].itv); expr.linterm[k].equality = exprA->linterm[i].equality; expr.linterm[k].dim = exprA->linterm[i].dim; k++; i++; } else { itv_add(expr.linterm[k].itv, exprA->linterm[i].itv,exprB->linterm[j].itv); expr.linterm[k].equality = exprA->linterm[i].equality && exprB->linterm[j].equality && /* speed-up */ itv_is_point(intern,expr.linterm[k].itv); expr.linterm[k].dim = exprA->linterm[i].dim; if (!itv_is_zero(expr.linterm[k].itv)){ k++; } i++; j++; } } _itv_linexpr_add_return: itv_linexpr_reinit(&expr,k); if (res==exprA || res==exprB){ itv_linexpr_clear(res); } *res = expr; return; } void ITVFUN(itv_linexpr_sub)(itv_internal_t* intern, itv_linexpr_t* res, itv_linexpr_t* exprA, itv_linexpr_t* exprB) { if (exprA==exprB){ itv_linexpr_t expr; itv_linexpr_init_set(&expr,exprB); itv_linexpr_neg(&expr); itv_linexpr_add(intern,res,exprA,&expr); itv_linexpr_clear(&expr); } else { itv_linexpr_neg(exprB); itv_linexpr_add(intern,res,exprA,exprB); if (exprB!=res){ itv_linexpr_neg(exprB); } } } /* ********************************************************************** */ /* IV. Tests */ /* ********************************************************************** */ bool ITVFUN(itv_linexpr_is_scalar)(itv_linexpr_t* expr) { bool res = expr->equality; if (res){ size_t i; for (i=0; isize; i++){ res = expr->linterm[i].equality; if (!res) break; } } return res; } bool ITVFUN(itv_linexpr_is_quasilinear)(itv_linexpr_t* expr) { bool res; if (expr->size==0) res = true; else { size_t i; for (i=0; isize; i++){ res = expr->linterm[i].equality; if (!res) break; } } return res; } bool ITVFUN(itv_lincons_array_is_scalar)(itv_lincons_array_t* array) { size_t i; bool res = true; for (i=0; isize; i++){ res = itv_lincons_is_scalar(&array->p[i]); if (!res) break; } return res; } bool ITVFUN(itv_lincons_array_is_quasilinear)(itv_lincons_array_t* array) { size_t i; bool res = true; for (i=0; isize; i++){ res = itv_lincons_is_quasilinear(&array->p[i]); if (!res) break; } return res; } bool ITVFUN(itv_linexpr_is_integer)(itv_linexpr_t* expr, size_t intdim) { size_t i; bool res; res = true; for (i=0; isize; i++){ if (expr->linterm[i].dim>=intdim){ res = false; break; } } return res; } bool ITVFUN(itv_lincons_is_integer)(itv_lincons_t* cons, size_t intdim) { return ITVFUN(itv_linexpr_is_integer)(&cons->linexpr,intdim); } /* Evaluate a constraint, composed of a constant (interval) expression */ tbool_t ITVFUN(itv_eval_cstlincons)(itv_internal_t* intern, itv_lincons_t* lincons) { tbool_t res; itv_ptr cst = lincons->linexpr.cst; bool equality = lincons->linexpr.equality; assert (lincons->linexpr.size==0); if (itv_is_bottom(intern,cst)){ return tbool_false; } switch (lincons->constyp){ case AP_CONS_EQ: if (equality){ int sgn = bound_sgn(cst->sup); res = (sgn==0 ? tbool_true : tbool_false); } else { if (bound_sgn(cst->sup)<0 || bound_sgn(cst->inf)<0) res = tbool_false; else res = tbool_top; } break; case AP_CONS_DISEQ: res = (bound_sgn(cst->inf)<0 || bound_sgn(cst->sup)<0) ? tbool_true : tbool_top; break; case AP_CONS_SUPEQ: if (bound_sgn(cst->inf)<=0) res = tbool_true; else if (bound_sgn(cst->sup)<0) res = tbool_false; else res = tbool_top; break; case AP_CONS_SUP: if (bound_sgn(cst->inf)<0) res = tbool_true; else if (bound_sgn(cst->sup)<=0) res = tbool_false; else res = tbool_top; break; case AP_CONS_EQMOD: if (equality){ if (bound_sgn(cst->sup)==0){ res = tbool_true; } else if (num_cmp_int(lincons->num,0)){ res = (bound_sgn(cst->sup)==0) ? tbool_true : tbool_top; } else { #if defined(NUM_NUMRAT) numrat_t numrat; numrat_init(numrat); numrat_div(numrat,bound_numref(cst->sup),lincons->num); if (numint_cmp_int(numrat_denref(numrat),1)==0){ res = tbool_true; } else { res = tbool_top; } numrat_clear(numrat); #elif defined(NUM_NUMINT) numint_t numint; numint_init(numint); numint_mod(numint,bound_numref(cst->sup),lincons->num); if (numint_sgn(numint)==0){ res = tbool_true; } else { res = tbool_top; } numint_clear(numint); #else res = tbool_top; #endif } } else { res = tbool_top; } break; default: abort(); } return res; } bool ITVFUN(itv_sat_lincons_is_false)(itv_internal_t* intern, itv_lincons_t* lincons) { bool res = false; bool equality = lincons->linexpr.equality; itv_ptr cst = lincons->linexpr.cst; bool inf = bound_infty(cst->inf); switch (lincons->constyp){ case AP_CONS_EQ: case AP_CONS_EQMOD: res = !equality; break; case AP_CONS_DISEQ: res = inf && bound_infty(cst->sup); break; case AP_CONS_SUPEQ: case AP_CONS_SUP: res = inf; break; default: break; } if (!res && lincons->linexpr.size==0 && itv_eval_cstlincons(intern,lincons)==tbool_false){ res = true; } return res; } static bool itv_lincons_is_useless_for_meet(itv_internal_t* intern, itv_lincons_t* lincons) { bool res = false; itv_ptr cst = lincons->linexpr.cst; if (lincons->linexpr.size==0){ if (itv_eval_cstlincons(intern,lincons)!=tbool_false) res = true; } else { if (!lincons->linexpr.equality){ bool sup = bound_infty(cst->sup); switch (lincons->constyp){ case AP_CONS_EQ: case AP_CONS_DISEQ: case AP_CONS_EQMOD: { bool inf = bound_infty(cst->inf); res = inf && sup; } break; case AP_CONS_SUPEQ: case AP_CONS_SUP: res = sup; break; default: break; } } } return res; } void ITVFUN(itv_lincons_reduce_integer)(itv_internal_t* intern, itv_lincons_t* cons, size_t intdim) { itv_linexpr_t* expr; size_t i; itv_ptr pitv; ap_dim_t dim; bool* peq; bool integer; switch (cons->constyp){ case AP_CONS_EQ: case AP_CONS_SUPEQ: case AP_CONS_SUP: break; default: return; } expr = &cons->linexpr; /* Tests if only integer variables are involved */ if (!itv_linexpr_is_integer(expr,intdim)) return; /* Check that there are only scalar coefficients for dimensions */ itv_linexpr_ForeachLinterm(expr,i,dim,pitv,peq) { if (!(*peq)) return; } #if defined(NUM_NUMRAT) { /* compute lcm of denominators and gcd of numerators */ numint_set_int(numrat_denref(intern->quasi_num),1); numint_set_int(numrat_numref(intern->quasi_num),0); itv_linexpr_ForeachLinterm(expr,i,dim,pitv,peq) { numint_lcm(numrat_denref(intern->quasi_num), numrat_denref(intern->quasi_num), numrat_denref(bound_numref(pitv->sup))); numint_gcd(numrat_numref(intern->quasi_num), numrat_numref(intern->quasi_num), numrat_numref(bound_numref(pitv->sup))); } if (numint_sgn(numrat_numref(intern->quasi_num))==0) return; itv_linexpr_ForeachLinterm(expr,i,dim,pitv,peq) { numint_divexact(numrat_numref(bound_numref(pitv->sup)), numrat_numref(bound_numref(pitv->sup)), numrat_numref(intern->quasi_num)); numint_mul(numrat_numref(bound_numref(pitv->sup)), numrat_numref(bound_numref(pitv->sup)), numrat_denref(intern->quasi_num)); numint_divexact(numrat_numref(bound_numref(pitv->sup)), numrat_numref(bound_numref(pitv->sup)), numrat_denref(bound_numref(pitv->sup))); numint_set_int(numrat_denref(bound_numref(pitv->sup)), 1); bound_neg(pitv->inf,pitv->sup); } numrat_inv(intern->quasi_num,intern->quasi_num); itv_mul_num(expr->cst,expr->cst,intern->quasi_num); } #else #if defined(NUM_NUMFLT) { /* Assuming that all coefficients are either integer, compute the pgcd */ mpz_set_si(intern->reduce_lincons_gcd,0); itv_linexpr_ForeachLinterm(expr,i,dim,pitv,peq) { if (!numflt_integer(pitv->sup)) return; mpz_set_numflt(intern->reduce_lincons_mpz,pitv->sup); mpz_gcd(intern->reduce_lincons_gcd, intern->reduce_lincons_gcd, intern->reduce_lincons_mpz); } if (mpz_sgn(intern->reduce_lincons_gcd)==0 || mpz_cmp_si(intern->reduce_lincons_gcd,1)==0) return; bool exact = numflt_set_mpz(intern->quasi_num,intern->reduce_lincons_gcd); if (!exact) return; } #elif defined(NUM_NUMINT) { num_set_int(intern->quasi_num,0); itv_linexpr_ForeachLinterm(expr,i,dim,pitv,peq) { numint_gcd(intern->quasi_num, intern->quasi_num, bound_numref(pitv->sup)); } if (numint_sgn(intern->quasi_num)==0 || numint_cmp_int(intern->quasi_num,1)==0) return; } #else #error "HERE" #endif /* divide by gcd put in intern->quasi_num */ itv_linexpr_ForeachLinterm(expr,i,dim,pitv,peq) { itv_div_num(pitv,pitv,intern->quasi_num); } itv_div_num(expr->cst,expr->cst,intern->quasi_num); #endif /* Constrain bounds */ if (!bound_infty(expr->cst->sup)){ if (cons->constyp==AP_CONS_SUP){ if (num_integer(bound_numref(expr->cst->sup))){ bound_sub_uint(expr->cst->sup,expr->cst->sup,1); } else { num_floor(bound_numref(expr->cst->sup), bound_numref(expr->cst->sup)); } cons->constyp = AP_CONS_SUPEQ; } else { num_floor(bound_numref(expr->cst->sup), bound_numref(expr->cst->sup)); } } if (cons->constyp == AP_CONS_EQ){ if (!bound_infty(expr->cst->inf)){ if (expr->equality){ bound_neg(expr->cst->inf, expr->cst->sup); } else { num_floor(bound_numref(expr->cst->inf), bound_numref(expr->cst->inf)); } } if (itv_is_bottom(intern,expr->cst)){ itv_lincons_set_bool(cons,false); } } else { if (!bound_infty(expr->cst->sup)){ bound_neg(expr->cst->inf,expr->cst->sup); expr->equality = true; } } } tbool_t ITVFUN(itv_lincons_array_reduce)(itv_internal_t* intern, itv_lincons_array_t* array, bool meet) { tbool_t res; size_t i,size; res = tbool_top; i = 0; size = array->size; while (ip[i].linexpr.size==0){ tbool_t sat = itv_eval_cstlincons(intern,&array->p[i]); if (sat==tbool_true){ itv_lincons_array_reduce_remove: size --; itv_lincons_swap(&array->p[i],&array->p[size]); continue; } else if (sat==tbool_false){ itv_lincons_array_reduce_false: itv_lincons_array_reinit(array,1); itv_lincons_set_bool(&array->p[0],false); return tbool_false; } } if (meet && itv_lincons_is_useless_for_meet(intern,&array->p[i])) goto itv_lincons_array_reduce_remove; else if (!meet && itv_sat_lincons_is_false(intern,&array->p[i])) goto itv_lincons_array_reduce_false; else { i++; } } itv_lincons_array_reinit(array,size); if (size==0) res = tbool_true; else if (size==1 && array->p[0].linexpr.size==0) res = itv_eval_cstlincons(intern,&array->p[0]); return res; } tbool_t ITVFUN(itv_lincons_array_reduce_integer)(itv_internal_t* intern, itv_lincons_array_t* array, size_t intdim) { size_t i; for (i=0; isize; i++){ itv_lincons_reduce_integer(intern,&array->p[i],intdim); } return itv_lincons_array_reduce(intern,array,true); } apron-dist-0.9.10/apron/itv/itv_config.h0000640014525101416610000000040410564602263017770 0ustar bjeannetpopart #ifndef _ITV_CONFIG_H_ #define _ITV_CONFIG_H_ #ifdef __cplusplus #define HAS_BOOL extern "C" { #endif #ifndef HAS_BOOL #define HAS_BOOL typedef char bool; static const bool false = 0; static const bool true = 1; #endif #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/itv/itv_linearize.c0000640014525101416610000012631311122221351020472 0ustar bjeannetpopart/* ********************************************************************** */ /* itv_linearize.c: */ /* ********************************************************************** */ #include "itv_linearize.h" #define LOGDEBUG 0 /* ********************************************************************** */ /* I. Evaluation of interval linear expressions */ /* ********************************************************************** */ /* Evaluate an ITV interval linear expression */ void ITVFUN(itv_eval_linexpr)(itv_internal_t* intern, itv_t itv, itv_linexpr_t* expr, itv_t* env) { size_t i; ap_dim_t dim; itv_ptr pitv; bool* peq; assert(env); itv_set(intern->eval_itv2, expr->cst); itv_linexpr_ForeachLinterm(expr,i,dim,pitv,peq){ if (*peq){ if (bound_sgn(pitv->sup)!=0){ itv_mul_bound(intern->eval_itv, env[dim], pitv->sup); itv_add(intern->eval_itv2, intern->eval_itv2, intern->eval_itv); } } else { itv_mul(intern, intern->eval_itv, env[dim], pitv); itv_add(intern->eval_itv2, intern->eval_itv2, intern->eval_itv); } if (itv_is_top(intern->eval_itv2)) break; } itv_set(itv,intern->eval_itv2); } /* Evaluate an APRON interval linear expression */ bool ITVFUN(itv_eval_ap_linexpr0)(itv_internal_t* intern, itv_t itv, ap_linexpr0_t* expr, itv_t* env) { size_t i; ap_dim_t dim; ap_coeff_t* pcoeff; bool exact,res; assert(env); exact = itv_set_ap_coeff(intern, intern->eval_itv3, &expr->cst); res = exact; ap_linexpr0_ForeachLinterm(expr,i,dim,pcoeff){ exact = itv_set_ap_coeff(intern,intern->eval_itv2,pcoeff); res = res && exact; bool eq = exact && pcoeff->discr==AP_COEFF_SCALAR; if (eq){ if (bound_sgn(intern->eval_itv2->sup)!=0){ itv_mul_bound(intern->eval_itv, env[dim], intern->eval_itv2->sup); itv_add(intern->eval_itv3, intern->eval_itv3, intern->eval_itv); } } else { itv_mul(intern, intern->eval_itv, env[dim], intern->eval_itv2); itv_add(intern->eval_itv3, intern->eval_itv3, intern->eval_itv); } if (itv_is_top(intern->eval_itv3)) break; } itv_set(itv,intern->eval_itv3); return res; } /* ********************************************************************** */ /* II. Boxization of interval linear expressions */ /* ********************************************************************** */ static bool itv_boxize_lincons(itv_internal_t* intern, itv_t* res, bool* tchange, itv_lincons_t* cons, itv_t* env, size_t intdim, bool intervalonly) { size_t i; itv_linexpr_t* expr; bool change,globalchange; bool exc; assert(cons->constyp == AP_CONS_EQ || cons->constyp == AP_CONS_SUPEQ || cons->constyp == AP_CONS_SUP); expr = &cons->linexpr; globalchange = false; /* Iterates on coefficients */ itv_set_int(intern->boxize_lincons_itv,0); for (i=0; isize; i++){ ap_dim_t dim = expr->linterm[i].dim; bool equality = expr->linterm[i].equality; /* 1. We decompose the expression e = ax+e' */ itv_swap(intern->boxize_lincons_itv,expr->linterm[i].itv); expr->linterm[i].equality = true; /* 2. evaluate e' */ itv_eval_linexpr(intern, intern->boxize_lincons_eval,expr,env); /* 3. Perform deductions */ change = false; if (!itv_is_top(intern->boxize_lincons_eval)){ if (equality && !intervalonly){ int sgn = bound_sgn(intern->boxize_lincons_itv->sup); if (sgn!=0){ /* If we have ax+e' >= 0 with a>0 we can deduce that x>=-e'/a, or x>= inf(-e'/a) If we have ax+e' >= 0 with a<0 we can deduce that -ax<=e', or x<= sup(e'/-a) If we have ax+e'=0 we can deduce x=-e'/a, or inf(-e'/a)<= x <= sup(-e'/a) */ if (sgn>0 || cons->constyp == AP_CONS_EQ){ /* If we have a>0, we compute sup(e')/a=sup(e'/a)=-inf(-e'/a) If we have a<0, we compute -inf(e')/(-a)=-inf(-e'/a) */ if (sgn>0){ bound_div(intern->boxize_lincons_bound, intern->boxize_lincons_eval->sup, intern->boxize_lincons_itv->sup); } else { bound_div(intern->boxize_lincons_bound, intern->boxize_lincons_eval->inf, intern->boxize_lincons_itv->inf); } if (dimboxize_lincons_bound)){ if (cons->constyp==AP_CONS_SUP && num_integer(bound_numref(intern->boxize_lincons_bound))){ num_sub_uint(bound_numref(intern->boxize_lincons_bound), bound_numref(intern->boxize_lincons_bound), 1); } else { bound_floor(intern->boxize_lincons_bound, intern->boxize_lincons_bound); } } /* We update the interval */ if (bound_cmp(intern->boxize_lincons_bound, res[dim]->inf)<0){ change = true; if (tchange) tchange[2*dim] = true; bound_set(res[dim]->inf, intern->boxize_lincons_bound); } } if (sgn<0 || cons->constyp == AP_CONS_EQ){ /* If we have a<0, we compute sup(e')/(-a)=sup(e'/-a) If we have a>0, we compute -inf(e')/a=-inf(e'/a)=sup(e'/-a) */ if (sgn<0){ bound_div(intern->boxize_lincons_bound, intern->boxize_lincons_eval->sup, intern->boxize_lincons_itv->inf); } else { bound_div(intern->boxize_lincons_bound, intern->boxize_lincons_eval->inf, intern->boxize_lincons_itv->sup); } if (dimboxize_lincons_bound)){ if (cons->constyp==AP_CONS_SUP && num_integer(bound_numref(intern->boxize_lincons_bound))){ num_sub_uint(bound_numref(intern->boxize_lincons_bound), bound_numref(intern->boxize_lincons_bound), 1); } else { bound_floor(intern->boxize_lincons_bound, intern->boxize_lincons_bound); } } /* We update the interval */ if (bound_cmp(intern->boxize_lincons_bound, res[dim]->sup)<0){ change = true; if (tchange) tchange[2*dim+1] = true; bound_set(res[dim]->sup, intern->boxize_lincons_bound); } } } } else if (!equality){ /* We have an interval */ /* - If we have [m;M]x+e' >= 0 with m>0, then [m,M]x>=inf(-e'), or [m,M]x>=-sup(e') so we need at least * if -sup(e')>=0: x>=-sup(e')/M * if -sup(e')<=0: x>=-sup(e')/m - If we have [m,M]x+e'<=0 with M<0, then [-M,-m]x>=inf(e') * inf(e')>=0: x>=inf(e')/-m * inf(e')<=0: x>=inf(e')/-M - If we have [m;M]x+e' >= 0 with M<0, then [-M,-m]x<=sup(e'), so we need at least * if sup(e')>=0: x<=sup(e')/-M * if sup(e')<=0: x<=sup(e')/-m - If we have [m,M]x+e'<=0 with m>0, then [m,M]x<=sup(-e') or [m,M]x<=-inf(e') * -inf(e')>=0: x<=inf(e')/-M * -inf(e')<=0: x<=inf(e')/-m */ int sgnitv = bound_sgn(intern->boxize_lincons_itv->inf)<0 ? 1 : ( bound_sgn(intern->boxize_lincons_itv->sup)<0 ? -1 : 0 ); if (sgnitv != 0){ int sgnevalinf = bound_sgn(intern->boxize_lincons_eval->inf); int sgnevalsup = bound_sgn(intern->boxize_lincons_eval->sup); if (sgnitv>0 || (cons->constyp==AP_CONS_EQ && sgnitv<0)){ if (sgnitv>0){ if (sgnevalsup<=0){ /* We compute sup(e')/M */ bound_div(intern->boxize_lincons_bound, intern->boxize_lincons_eval->sup, intern->boxize_lincons_itv->sup); } else { /* We compute sup(e')/m = (-sup(e'))/(-m) */ bound_neg(intern->boxize_lincons_bound, intern->boxize_lincons_eval->sup); bound_div(intern->boxize_lincons_bound, intern->boxize_lincons_bound, intern->boxize_lincons_itv->inf); } } else { if (sgnevalinf<=0){ /* We compute inf(e')/m = (-inf(e'))/(-m) */ bound_div(intern->boxize_lincons_bound, intern->boxize_lincons_eval->inf, intern->boxize_lincons_itv->inf); } else { /* We compute inf(e')/M) = (-inf(e'))/(-M) */ bound_neg(intern->boxize_lincons_bound, intern->boxize_lincons_itv->sup); bound_div(intern->boxize_lincons_bound, intern->boxize_lincons_eval->inf, intern->boxize_lincons_bound); } } if (dimboxize_lincons_bound)){ if (cons->constyp==AP_CONS_SUP && num_integer(bound_numref(intern->boxize_lincons_bound))){ num_sub_uint(bound_numref(intern->boxize_lincons_bound), bound_numref(intern->boxize_lincons_bound), 1); } else { bound_floor(intern->boxize_lincons_bound, intern->boxize_lincons_bound); } } /* We update the interval */ if (bound_cmp(intern->boxize_lincons_bound, res[dim]->inf)<0){ change = true; if (tchange) tchange[2*dim] = true; bound_set(res[dim]->inf, intern->boxize_lincons_bound); } } if (sgnitv<0 || (cons->constyp==AP_CONS_EQ && sgnitv>0)){ if (sgnitv<0){ if (sgnevalsup>=0){ /* We compute sup(e')/-M */ bound_neg(intern->boxize_lincons_bound, intern->boxize_lincons_itv->sup); bound_div(intern->boxize_lincons_bound, intern->boxize_lincons_eval->sup, intern->boxize_lincons_bound); } else { /* We compute sup(e')/-m */ bound_div(intern->boxize_lincons_bound, intern->boxize_lincons_eval->sup, intern->boxize_lincons_itv->inf); } } else { if (sgnevalinf>=0){ /* We compute -inf(e')/M */ bound_div(intern->boxize_lincons_bound, intern->boxize_lincons_eval->inf, intern->boxize_lincons_itv->sup); } else { /* We compute -inf(e')/m = inf(e')/(-m) */ bound_neg(intern->boxize_lincons_bound, intern->boxize_lincons_eval->inf); bound_div(intern->boxize_lincons_bound, intern->boxize_lincons_bound, intern->boxize_lincons_itv->inf); } } if (dimboxize_lincons_bound)){ if (cons->constyp==AP_CONS_SUP && num_integer(bound_numref(intern->boxize_lincons_bound))){ num_sub_uint(bound_numref(intern->boxize_lincons_bound), bound_numref(intern->boxize_lincons_bound), 1); } else { bound_floor(intern->boxize_lincons_bound, intern->boxize_lincons_bound); } } /* We update the interval */ if (bound_cmp(intern->boxize_lincons_bound, res[dim]->sup)<0){ change = true; if (tchange) tchange[2*dim+1] = true; bound_set(res[dim]->sup, intern->boxize_lincons_bound); } } } } } itv_swap(intern->boxize_lincons_itv,expr->linterm[i].itv); expr->linterm[i].equality = equality; if (change){ globalchange = true; exc = itv_canonicalize(intern,res[dim],dimsize==0 && itv_eval_cstlincons(intern,cons)==tbool_false){ itv_set_bottom(res[0]); globalchange = true; } return globalchange; } /* This function deduces interval constraints from a set of interval linear constraints. Return true if some (better if res==env) bounds have been inferred. - The inferred bounds are stored in res (which may be equal to env) - If tchange!=NULL *and initialized to false*, tchange[2dim] (resp. 2dim+1) set to true indicates that the inf (resp. sup) bound of dimension dim has been improved. - env is the current bounds for variables - kmax specifies the maximum number of iterations, when res==env - if intervalonly is true, deduces bounds from a constraint only when the coefficient associated to the current dimension is an interval. */ bool ITVFUN(itv_boxize_lincons_array)(itv_internal_t* intern, itv_t* res, bool* tchange, itv_lincons_array_t* array, itv_t* env,size_t intdim, size_t kmax, bool intervalonly) { size_t i,k; bool change,globalchange; if (kmax<1) kmax=1; if (res!=env) kmax=1; globalchange = false; /* we possibly perform kmax passes */ for (k=0;k<(size_t)kmax;k++){ change = false; for (i=0; isize; i++){ if (array->p[i].constyp==AP_CONS_EQ || array->p[i].constyp==AP_CONS_SUPEQ || array->p[i].constyp==AP_CONS_SUP){ change = itv_boxize_lincons(intern,res,tchange,&array->p[i],env,intdim,intervalonly) || change ; globalchange = globalchange || change; if (itv_is_bottom(intern,res[0])){ return true; } } } if (!change) break; } return globalchange; } /* ********************************************************************** */ /* III. (Quasi)linearisation of interval linear expressions */ /* ********************************************************************** */ /* These functions quasilinearize in-place expressions and constraints. They optimize (sets of) constraints when the parameter meet is true, by deducing things. If constraints are quasilinearized for testing satisfaction, meet should be set to false. */ /* Choose the middle of interval coefficient coeff for quasilinearisation */ /* Applies the following choice: if coeff=[-oo,+oo], choose 0 if coeff=[-oo,x], choose x if coeff=[x,+oo], choose x if coeff = [inf,sup] if for_meet_inequality, (* always choose in favour of a finite sup bound in the constant of the quasilinear expression *) if var=[-oo,a] choose inf, because it gives inf.var + [0,sup-inf].[-oo,a] = inf.var + [-oo,b] if var=[a,+oo] choose sup, because it gives sup.var + [inf-sup,0].[a,+oo] = sup.var + [-oo,b] if var=[a,b], choose middle else (* always choose in favour of at least a finite bound in the evaluation of the quasilinear expression *) if var=[-oo,a] if inf >= 0, choose inf, because inf.var + [0,sup-inf][-oo,a] evaluates to a finite sup bound if sup<=0, choose sup because sup.var + [inf-sup,0][-oo,a] evaluates to a finite inf bound otherwise arbitrary choice (middle) if var=[a,+oo] if inf >= 0, choose inf, because inf.var + [0,sup-inf][a,+oo] evaluates to a finite inf bound if sup <= 0, choose sup, because sup.var + [inf-sup,0][a,+oo] evaluates to a finite sup bound otherwise arbitrary choice (middle) if var=[a,b], choose middle */ static void itv_quasilinearize_choose_middle(num_t middle, /* the result */ itv_t coeff, /* the coefficient in which middle is to be picked */ itv_t var, /* the variable interval */ bool for_meet_inequality /* is it for the linearisation of an inequality ? */ ) { if (bound_infty(coeff->inf)){ if (bound_infty(coeff->sup)) num_set_int(middle,0); else num_set(middle, bound_numref(coeff->sup)); } else if (bound_infty(coeff->sup)) num_neg(middle, bound_numref(coeff->inf)); else { /* if coeff = [inf,sup] */ if (for_meet_inequality){ if (bound_infty(var->inf)) num_neg(middle, bound_numref(coeff->inf)); else if (bound_infty(var->sup)) num_set(middle, bound_numref(coeff->sup)); else /* Arbitrary choice: we take the middle */ goto itv_quasilinearize_choose_middle_default; } else { if (bound_infty(var->inf) ? !bound_infty(var->sup) : bound_infty(var->sup)){ if (bound_sgn(coeff->inf)<=0) num_neg(middle, bound_numref(coeff->inf)); else if (bound_sgn(coeff->sup)<=0) num_set(middle, bound_numref(coeff->sup)); else /* Arbitrary choice: we take the middle */ goto itv_quasilinearize_choose_middle_default; } else { itv_quasilinearize_choose_middle_default: num_sub(middle, bound_numref(coeff->sup), bound_numref(coeff->inf)); num_div_2(middle, middle); } } } } bool ITVFUN(itv_quasilinearize_linexpr)(itv_internal_t* intern, itv_linexpr_t* linexpr, itv_t* env, bool for_meet_inequality) { size_t i,k,size; ap_dim_t dim; itv_ptr itv; bool* peq; #if LOGDEBUG printf("itv_quasilinearize_linexpr:\n"); itv_linexpr_print(linexpr,0); printf("\n"); #endif k = 0; i = 0; size = linexpr->size; while (ilinterm[i].dim; itv = linexpr->linterm[i].itv; peq = &(linexpr->linterm[i].equality); if (itv_is_point(intern,env[dim])){ /* If a variable has a constant value, simplification */ itv_mul_num(itv,itv,bound_numref(env[dim]->sup)); itv_add(linexpr->cst,linexpr->cst,itv); size--; itv_linterm_t tmp = linexpr->linterm[i]; linexpr->linterm[i] = linexpr->linterm[size]; linexpr->linterm[size] = tmp; } else { if (*peq == false){ /* Compute the middle of the interval */ itv_quasilinearize_choose_middle(intern->quasi_num, itv,env[dim],for_meet_inequality); /* Residue (interval-middle) */ itv_sub_num(intern->eval_itv2,itv,intern->quasi_num); /* Multiplication of residue by variable range */ itv_mul(intern, intern->eval_itv, intern->eval_itv2, env[dim]); /* Addition to the constant coefficient */ itv_add(linexpr->cst,linexpr->cst,intern->eval_itv); if (itv_is_top(linexpr->cst)){ k = 0; break; } /* Addition of the linear term */ if (num_sgn(intern->quasi_num)!=0){ linexpr->linterm[k].equality = true; linexpr->linterm[k].dim = dim; itv_set_num(linexpr->linterm[k].itv,intern->quasi_num); k++; } } else { if (k!=i){ linexpr->linterm[k].equality = *peq; linexpr->linterm[k].dim = dim; itv_set(linexpr->linterm[k].itv,itv); } k++; } i++; } } itv_linexpr_reinit(linexpr,k); #if LOGDEBUG itv_linexpr_print(linexpr,0); printf("\n"); #endif #if defined(NUM_FLOAT) || defined(NUM_DOUBLE) || defined(NUM_LONGDOUBLE) || defined(NUM_MPFR) || defined (NUM_NUMINT) return false; #else return true; #endif } bool ITVFUN(itv_quasilinearize_lincons)(itv_internal_t* intern, itv_lincons_t* lincons, itv_t* env, bool meet) { if (lincons->linexpr.size==0){ /* constant expression */ tbool_t sat = itv_eval_cstlincons(intern,lincons); if (sat==tbool_true || sat==tbool_false){ itv_lincons_set_bool(lincons,sat==tbool_true); } return true; } else { itv_quasilinearize_lincons_std: return itv_quasilinearize_linexpr(intern,&lincons->linexpr,env, meet && (lincons->constyp==AP_CONS_SUP || lincons->constyp==AP_CONS_SUPEQ)); } } bool ITVFUN(itv_quasilinearize_lincons_array)(itv_internal_t* intern, itv_lincons_array_t* array, itv_t* env, bool meet) { size_t i,j,size; bool exact = true; itv_lincons_array_reduce(intern,array,meet); size = array->size; for (i=0; ip[i].constyp == AP_CONS_EQ && !itv_linexpr_is_quasilinear(&array->p[i].linexpr)){ /* Split an equality constraint into two inequalities if it is really interval linear ==> better precision because quasilinearisation choices differ between expr>=0 and expr<=0 */ if (size>=array->size){ itv_lincons_array_reinit(array,1+(5*array->size)/4); } array->p[i].constyp = AP_CONS_SUPEQ; itv_lincons_set(&array->p[size],&array->p[i]); itv_linexpr_neg(&array->p[size].linexpr); size++; } exact = itv_quasilinearize_lincons(intern,&array->p[i],env,meet) && exact; if (array->p[i].linexpr.size==0 && itv_eval_cstlincons(intern,&array->p[i]) == tbool_false){ itv_lincons_array_reinit(array,1); itv_lincons_set_bool(&array->p[0],false); return true; } } itv_lincons_array_reinit(array,size); return exact; } /* Transform sets of quasilinear constraint as follows: e.x + [a,b] >= 0 ==> e.x + b >= 0 e.x + [a,b] > 0 ==> e.x + b > 0 e.x + [a,b] = 0 ==> e.x + b >= 0 and e.x + a <= 0 added at the end e.x + [a,b] = 0 mod k ==> unchanged Also remove (some) trivially true constraints e.x + oo >= 0 */ static void itv_lincons_select_sup(itv_lincons_t* cons) { bound_neg(cons->linexpr.cst->inf,cons->linexpr.cst->sup); cons->linexpr.equality = true; } static void itv_lincons_select_inf(itv_lincons_t* cons) { size_t i; bound_neg(cons->linexpr.cst->inf,cons->linexpr.cst->inf); bound_neg(cons->linexpr.cst->sup,cons->linexpr.cst->inf); cons->linexpr.equality = true; for (i=0;ilinexpr.size;i++){ itv_neg(cons->linexpr.linterm[i].itv,cons->linexpr.linterm[i].itv); } } void ITVFUN(itv_linearize_lincons_array)(itv_internal_t* intern, itv_lincons_array_t* array, bool meet) { size_t index,size,sizeorg; tbool_t res = itv_lincons_array_reduce(intern,array,meet); if (res!=tbool_top) return; /* One now remove intervals when we can */ sizeorg = array->size; size = sizeorg; for (index=0; indexp[index]; if (!cons->linexpr.equality){ itv_ptr cst = cons->linexpr.cst; bool sup = !bound_infty(cst->sup); switch (cons->constyp){ case AP_CONS_EQ: assert (meet); /* otherwise, already removed */ { bool inf = !bound_infty(cst->inf); assert (inf || sup); /* otherwise, already removed */ if (inf && sup){ if (size>=array->size){ itv_lincons_array_reinit(array,1+5*array->size/4); } /* Be cautious: cons and cst may be invalid now */ itv_lincons_set(&array->p[size],&array->p[index]); array->p[index].constyp = AP_CONS_SUPEQ; array->p[size].constyp = AP_CONS_SUPEQ; itv_lincons_select_sup(&array->p[index]); itv_lincons_select_inf(&array->p[size]); size++; } else if (inf){ array->p[index].constyp = AP_CONS_SUPEQ; itv_lincons_select_inf(&array->p[index]); } else if (sup){ array->p[index].constyp = AP_CONS_SUPEQ; itv_lincons_select_sup(&array->p[index]); } else assert(false); } break; case AP_CONS_SUPEQ: case AP_CONS_SUP: if (meet){ assert(sup); itv_lincons_select_sup(&array->p[index]); } else { assert(!bound_infty(cst->inf)); bound_neg(cons->linexpr.cst->sup,cons->linexpr.cst->inf); cons->linexpr.equality = true; } break; default: break; } } } itv_lincons_array_reinit(array,size); } /* ********************************************************************** */ /* IV. Evaluation of tree expressions */ /* ********************************************************************** */ /* General rounding */ static void itv_round(itv_t res, itv_t arg, ap_texpr_rtype_t t, ap_texpr_rdir_t d) { switch (t) { case AP_RTYPE_REAL: if (&res!=&arg) itv_set(res,arg); break; case AP_RTYPE_INT: switch (d) { case AP_RDIR_ZERO: itv_trunc(res,arg); break; case AP_RDIR_UP: itv_ceil(res,arg); break; case AP_RDIR_DOWN: itv_floor(res,arg); break; case AP_RDIR_RND: case AP_RDIR_NEAREST: /* 'to nearest' case could be improved */ itv_to_int(res,arg); break; default: assert(0); } break; case AP_RTYPE_SINGLE: /* directed rounding cases (+oo, -oo, 0) could be improved */ itv_to_float(res,arg); break; case AP_RTYPE_QUAD: /* 'round to quad' could be improved */ case AP_RTYPE_EXTENDED: /* 'round to extended' could be improved */ case AP_RTYPE_DOUBLE: /* directed rounding cases (+oo, -oo, 0) could be improved */ itv_to_double(res,arg); break; default: assert(0); } } /* Evaluates node into interval res, assuming operator arguments are arg1 and (for binary operator) arg2 */ static void itv_eval_ap_texpr0_node(itv_internal_t* intern, ap_texpr0_node_t* n, itv_t res, itv_t arg1, itv_t arg2) { switch (n->op) { case AP_TEXPR_NEG: itv_neg(res, arg1); return; /* no rounding */ case AP_TEXPR_CAST: itv_set(res, arg1); break; case AP_TEXPR_SQRT: itv_sqrt(intern, res, arg1); break; case AP_TEXPR_ADD: itv_add(res, arg1, arg2); break; case AP_TEXPR_SUB: itv_sub(res, arg1, arg2); break; case AP_TEXPR_MUL: itv_mul(intern, res, arg1, arg2); break; case AP_TEXPR_DIV: itv_div(intern, res, arg1, arg2); break; case AP_TEXPR_MOD: itv_mod(intern, res, arg1, arg2, n->type==AP_RTYPE_INT); return; /* no rounding */ default: assert(0); } itv_round(res,res,n->type,n->dir); } /* evaluates expr into intervalres, assuming env maps dimensions to interval values */ void ITVFUN(itv_eval_ap_texpr0)(itv_internal_t* intern, itv_t res, ap_texpr0_t* expr, itv_t* env) { if (!expr) { itv_set_bottom(res); return; } switch(expr->discr){ case AP_TEXPR_CST: itv_set_ap_coeff(intern,res,&expr->val.cst); break; case AP_TEXPR_DIM: itv_set(res,env[expr->val.dim]); break; case AP_TEXPR_NODE: if (expr->val.node->exprB) { /* binary */ itv_t x; itv_init(x); itv_eval_ap_texpr0(intern,x,expr->val.node->exprA,env); itv_eval_ap_texpr0(intern,res,expr->val.node->exprB,env); if (itv_is_bottom(intern,x) || itv_is_bottom(intern,res)){ itv_set_bottom(res); } else { itv_eval_ap_texpr0_node(intern,expr->val.node,res,x,res); } itv_clear(x); } else { /* unary */ itv_eval_ap_texpr0(intern,res,expr->val.node->exprA,env); if (!itv_is_bottom(intern,res)){ itv_eval_ap_texpr0_node(intern,expr->val.node,res,res,res); } } break; default: assert(false); } } /* ====================================================================== */ /* V. Interval linearization of interval linear tree expressions */ /* ====================================================================== */ /* preconditions: - lres is initialised postconditions: - stores an interval linear form in lres - returns true if input expression is not interval linear */ static bool ap_texpr0_node_intlinearize_linear(itv_internal_t* intern, ap_texpr0_node_t* n, itv_linexpr_t* lres /* out */) { itv_t i1; itv_linexpr_t l1; bool exc = n->type!=AP_RTYPE_REAL; if (exc) return exc; switch (n->op) { case AP_TEXPR_NEG: exc = itv_intlinearize_ap_texpr0_intlinear(intern,lres,n->exprA); itv_linexpr_neg(lres); break; case AP_TEXPR_CAST: break; case AP_TEXPR_MOD: case AP_TEXPR_SQRT: exc = true; break; case AP_TEXPR_ADD: case AP_TEXPR_SUB: itv_linexpr_init(&l1,0); /* intlinearize arguments */ exc = itv_intlinearize_ap_texpr0_intlinear(intern,&l1,n->exprA); exc = itv_intlinearize_ap_texpr0_intlinear(intern,lres,n->exprB) || exc; /* add/sub linear form & interval */ if (n->op==AP_TEXPR_ADD) itv_linexpr_add(intern,lres,&l1,lres); else itv_linexpr_sub(intern,lres,&l1,lres); itv_linexpr_clear(&l1); break; case AP_TEXPR_MUL: case AP_TEXPR_DIV: itv_init(i1); if (ap_texpr0_is_interval_cst(n->exprB)){ exc = itv_intlinearize_ap_texpr0_intlinear(intern,lres,n->exprA); itv_eval_ap_texpr0(intern,i1,n->exprB,NULL); } else if (n->op == AP_TEXPR_MUL && ap_texpr0_is_interval_cst(n->exprA)){ exc = itv_intlinearize_ap_texpr0_intlinear(intern,lres,n->exprB); itv_eval_ap_texpr0(intern,i1,n->exprA,NULL); } else { exc = true; break; } if (n->op==AP_TEXPR_DIV){ itv_t i2; itv_init(i2); itv_set_int(i2,1); itv_div(intern,i1,i2,i1); itv_clear(i2); } itv_linexpr_scale(intern,lres,i1); itv_clear(i1); break; default: assert(0); } return exc; } bool ITVFUN(itv_intlinearize_ap_texpr0_intlinear)(itv_internal_t* intern, itv_linexpr_t* lres, ap_texpr0_t* expr) { itv_linexpr_t r; bool exc = false; assert(expr); switch(expr->discr){ case AP_TEXPR_CST: itv_linexpr_reinit(lres,0); itv_set_ap_coeff(intern,lres->cst,&expr->val.cst); lres->equality = itv_is_point(intern,lres->cst); break; case AP_TEXPR_DIM: itv_linexpr_reinit(lres,1); itv_set_int(lres->cst,0); lres->linterm[0].dim = expr->val.dim; lres->linterm[0].equality = true; itv_set_int(lres->linterm[0].itv,1); break; case AP_TEXPR_NODE: if (ap_texpr0_is_interval_cst(expr)){ itv_linexpr_reinit(lres,0); itv_eval_ap_texpr0(intern,lres->cst,expr,NULL); lres->equality = itv_is_point(intern,lres->cst); } else { exc = ap_texpr0_node_intlinearize_linear(intern,expr->val.node,lres); } break; default: exc = true; assert(false); } return exc; } bool ITVFUN(itv_intlinearize_ap_tcons0_intlinear)(itv_internal_t* intern, itv_lincons_t* res, ap_tcons0_t* cons) { bool exc = itv_intlinearize_ap_texpr0_intlinear(intern,&res->linexpr,cons->texpr0); if (exc){ itv_lincons_set_bool(res,false); } else { res->constyp = cons->constyp; if (cons->scalar){ num_set_ap_scalar(res->num,cons->scalar); } else { num_set_int(res->num,0); } } return exc; } bool ITVFUN(itv_intlinearize_ap_tcons0_array_intlinear)(itv_internal_t* intern, itv_lincons_array_t* res, ap_tcons0_array_t* array) { bool exc; size_t i,index; itv_lincons_array_reinit(res,array->size); exc = false; for (i=0; isize;i++){ bool exc = itv_intlinearize_ap_texpr0_intlinear(intern,&res->p[i].linexpr,array->p[i].texpr0); res->p[i].constyp = array->p[i].constyp; if (array->p[i].scalar){ num_set_ap_scalar(res->p[i].num,array->p[i].scalar); } else { num_set_int(res->p[i].num,0); } if (exc){ itv_lincons_array_reinit(res,1); itv_lincons_set_bool(&res->p[0],false); break; } } return exc; } /* ====================================================================== */ /* VI. Linearization of tree expressions */ /* ====================================================================== */ /* transform in-place [A0,B0] + sum Xi [Ai,Bi] into ([A0,B0] + [A0,B0][-ulp,ulp]) + [-mf,mf] + sum Xi ([Ai,Bi] + [Ai,Bi][-ulp,ulp]) i.e., add a relative error of magnitude ulp as an interval linear form */ static void itv_linexpr_round_float_lin(itv_internal_t* intern, itv_linexpr_t* l /* in/out */, float_const* f) { size_t i; ap_dim_t dim; bool* peq; itv_ptr pitv; itv_magnitude(intern->linear_bound,l->cst); bound_mul(intern->linear_bound,intern->linear_bound,f->ulp->sup); bound_add(intern->linear_bound,intern->linear_bound,f->min->sup); itv_enlarge_bound(l->cst,l->cst,intern->linear_bound); l->equality = false; itv_linexpr_ForeachLinterm(l,i,dim,pitv,peq) { *peq = false; itv_magnitude(intern->linear_bound,pitv); bound_mul(intern->linear_bound,intern->linear_bound,f->ulp->sup); itv_enlarge_bound(pitv,pitv,intern->linear_bound); } } /* transform in-place [A0,B0] + sum Xi [Ai,Bi] into [A0,B0] + ([A0,B0] + sum [min Xi,max Xi][Ai,Bi]) [-ulp,ulp] + [-mf,mf] sum Xi [Ai,Bi] i.e., adds a relative error of magnitude ulp flattened into an interval */ static void itv_linexpr_round_float(itv_internal_t* intern, itv_linexpr_t* l /* in/out */, float_const* f, itv_t* env) { size_t i; ap_dim_t dim; bool* peq; itv_ptr pitv; itv_magnitude(intern->linear_bound,l->cst); l->equality = false; itv_linexpr_ForeachLinterm(l,i,dim,pitv,peq) { *peq = false; itv_magnitude(intern->linear_bound2,pitv); itv_magnitude(intern->linear_bound3,env[dim]); bound_mul(intern->linear_bound2,intern->linear_bound2,intern->linear_bound3); bound_add(intern->linear_bound,intern->linear_bound,intern->linear_bound2); } bound_mul(intern->linear_bound,intern->linear_bound,f->ulp->sup); bound_add(intern->linear_bound,intern->linear_bound,f->min->sup); itv_enlarge_bound(l->cst,l->cst,intern->linear_bound); } /* adds an absolute error to l corresponding to a conversion to int assumes that i overapproximates the values of l before conversion */ static void ap_texpr0_to_int(itv_internal_t* intern, itv_linexpr_t* l /* in/out */, itv_t i /* in */, ap_texpr_rdir_t d) { switch (d) { case AP_RDIR_UP: /* add [0,1] */ bound_add_uint(l->cst->sup,l->cst->sup,1); break; case AP_RDIR_DOWN: /* add [-1,0] */ bound_add_uint(l->cst->inf,l->cst->inf,1); break; case AP_RDIR_RND: /* add [-1,1] */ bound_add_uint(l->cst->sup,l->cst->sup,1); bound_add_uint(l->cst->inf,l->cst->inf,1); break; case AP_RDIR_ZERO: /* UP or DOWN or RND, depending on sign of i */ if (bound_sgn(i->inf)>0) bound_add_uint(l->cst->sup,l->cst->sup,1); if (bound_sgn(i->sup)>0) bound_add_uint(l->cst->inf,l->cst->inf,1); break; case AP_RDIR_NEAREST: /* [-0.5,0.5] */ itv_add(l->cst,l->cst,intern->itv_half); break; default: assert(0); } l->equality = false; } /* adds rounding error to both l and i to go from type org to type dst */ static ap_texpr_rtype_t ap_texpr0_round(itv_internal_t* intern, itv_linexpr_t* l /* in/out */, itv_t i /* in/out */, ap_texpr_rtype_t org, ap_texpr_rtype_t dst, ap_texpr_rdir_t d) { if (dst==AP_RTYPE_REAL) return org; switch (dst) { case AP_RTYPE_INT: if (org==AP_RTYPE_INT) return org; ap_texpr0_to_int(intern,l,i,d); break; case AP_RTYPE_SINGLE: if (org==AP_RTYPE_SINGLE) return org; itv_linexpr_round_float_lin(intern,l,&intern->cst_single); break; case AP_RTYPE_DOUBLE: if (org==AP_RTYPE_SINGLE || org==AP_RTYPE_DOUBLE) return org; itv_linexpr_round_float_lin(intern,l,&intern->cst_double); break; case AP_RTYPE_EXTENDED: if (org==AP_RTYPE_SINGLE && org==AP_RTYPE_DOUBLE && org==AP_RTYPE_EXTENDED) return org; itv_linexpr_round_float_lin(intern,l,&intern->cst_extended); break; case AP_RTYPE_QUAD: if (org==AP_RTYPE_SINGLE || org==AP_RTYPE_DOUBLE || org==AP_RTYPE_EXTENDED || org==AP_RTYPE_QUAD) return org; itv_linexpr_round_float_lin(intern,l,&intern->cst_quad); break; default: assert(0); } itv_round(i,i,dst,d); return dst; } /* reduce l and i: - intersect i with the interval evaluation of l - if l is constant, replace it with i - check for emptiness */ static void ap_texpr0_reduce(itv_internal_t* intern, itv_t* env, itv_linexpr_t* l /* in/out */, itv_t i /* in/out */) { itv_t tmp; itv_init(tmp); itv_eval_linexpr(intern,tmp,l,env); itv_meet(intern,i,i,tmp); if (itv_is_bottom(intern,i) || itv_is_bottom(intern,l->cst)) { itv_set_bottom(i); itv_set_bottom(l->cst); if (l->size>0) itv_linexpr_reinit(l,0); } else if (l->size==0){ itv_set(l->cst,i); l->equality = itv_is_point(intern,l->cst); } itv_clear(tmp); } /* multiplication heuristic: choose which interval to keep (0=a, 1=b) */ static int ap_texpr0_cmp_range(itv_internal_t* intern, itv_linexpr_t* la, itv_t ia, itv_linexpr_t* lb, itv_t ib) { int sgn_a,sgn_b; /* if one linear form is an interval keep it */ if (la->size==0) return 0; if (lb->size==0) return 1; /* if only one interval has constant sign, keep it */ sgn_a = itv_is_pos(ia) || itv_is_neg(ia); sgn_b = itv_is_pos(ib) || itv_is_neg(ib); if (sgn_a!=sgn_b) return sgn_a ? 0 : 1; /* otherwise, keep the interval with the smallest relative range */ itv_range_rel(intern,intern->linear_bound,ia); itv_range_rel(intern,intern->linear_bound2,ib); if (bound_cmp(intern->linear_bound,intern->linear_bound2)<0) return 0; else return 1; } /* preconditions: - env assigns an interval to each dimension - dimensions strictly smaller that intdim are integer - lres is not initialised - ires is initialised postconditions: - stores an interval linear form in lres - stores an interval in ires both encompase the exact expression values (ires may be smaller than the interval evaluation of lres) - returns the expression type */ static ap_texpr_rtype_t itv_intlinearize_texpr0_rec(itv_internal_t* intern, ap_texpr0_t* expr, itv_t* env, size_t intdim, itv_linexpr_t* lres /* out */, itv_t ires /* out */); static int debug_indent = 0; static ap_texpr_rtype_t ap_texpr0_node_intlinearize(itv_internal_t* intern, ap_texpr0_node_t* n, itv_t* env, size_t intdim, itv_linexpr_t* lres /* out */, itv_t ires /* out */) { itv_t i1,i2; itv_linexpr_t l1; ap_texpr_rtype_t t1,t2; switch (n->op) { case AP_TEXPR_NEG: /* negate linear form & interval, no rounding */ t1 = itv_intlinearize_texpr0_rec(intern,n->exprA,env,intdim,lres,ires); itv_linexpr_neg(lres); itv_neg(ires,ires); return t1; case AP_TEXPR_CAST: /* round linear form & interval */ t1 = itv_intlinearize_texpr0_rec(intern,n->exprA,env,intdim,lres,ires); ap_texpr0_round(intern,lres,ires,t1,n->type,n->dir); ap_texpr0_reduce(intern,env,lres,ires); break; case AP_TEXPR_SQRT: /* intlinearize argument, lres is not used */ itv_intlinearize_texpr0_rec(intern,n->exprA,env,intdim,lres,ires); /* interval square root */ itv_sqrt(intern,ires,ires); itv_round(ires,ires,n->type,n->dir); itv_linexpr_reinit(lres,0); itv_set(lres->cst,ires); lres->equality = itv_is_point(intern,lres->cst); break; case AP_TEXPR_ADD: case AP_TEXPR_SUB: itv_init(i1); itv_linexpr_init(&l1,0); /* intlinearize arguments */ t1 = itv_intlinearize_texpr0_rec(intern,n->exprA,env,intdim,&l1,i1); t2 = itv_intlinearize_texpr0_rec(intern,n->exprB,env,intdim,lres,ires); if (itv_is_bottom(intern,i1) || itv_is_bottom(intern,ires)){ itv_set_bottom(ires); itv_linexpr_reinit(lres,0); itv_set(lres->cst,ires); } else { /* add/sub linear form & interval */ if (n->op==AP_TEXPR_ADD) { itv_linexpr_add(intern,lres,&l1,lres); itv_add(ires,i1,ires); } else { itv_linexpr_sub(intern,lres,&l1,lres); itv_sub(ires,i1,ires); } /* round */ ap_texpr0_round(intern,lres,ires, (t1==AP_RTYPE_INT && t2==AP_RTYPE_INT) ? AP_RTYPE_INT : AP_RTYPE_REAL, n->type,n->dir); /* reduce */ ap_texpr0_reduce(intern,env,lres,ires); } itv_clear(i1); itv_linexpr_clear(&l1); break; case AP_TEXPR_DIV: itv_init(i1); itv_linexpr_init(&l1,0); /* intlinearize arguments, l1 is not used */ itv_intlinearize_texpr0_rec(intern,n->exprA,env,intdim,lres,ires); itv_intlinearize_texpr0_rec(intern,n->exprB,env,intdim,&l1,i1); if (itv_is_bottom(intern,i1) || itv_is_bottom(intern,ires)){ itv_set_bottom(ires); itv_linexpr_reinit(lres,0); itv_set(lres->cst,ires); } else { /* divide linear form & interval */ itv_linexpr_div(intern,lres,i1); itv_div(intern,ires,ires,i1); /* round */ ap_texpr0_round(intern,lres,ires,AP_RTYPE_REAL,n->type,n->dir); /* reduce */ ap_texpr0_reduce(intern,env,lres,ires); } itv_clear(i1); itv_linexpr_clear(&l1); break; case AP_TEXPR_MUL: itv_init(i1); itv_linexpr_init(&l1,0); /* intlinearize arguments */ t1 = itv_intlinearize_texpr0_rec(intern,n->exprA,env,intdim,&l1,i1); t2 = itv_intlinearize_texpr0_rec(intern,n->exprB,env,intdim,lres,ires); if (itv_is_bottom(intern,i1) || itv_is_bottom(intern,ires)){ itv_set_bottom(ires); itv_linexpr_reinit(lres,0); itv_set(lres->cst,ires); itv_linexpr_clear(&l1); } else { /* multiply one linear form with the other interval */ if (ap_texpr0_cmp_range(intern,&l1,i1,lres,ires)) { /* res = ires * l1 */ #if LOGDEBUG printf("%*s lin * inter\n",2*debug_indent,""); #endif itv_linexpr_clear(lres); *lres = l1; itv_linexpr_scale(intern,lres,ires); } else { /* res = i1 * lres */ #if LOGDEBUG printf("%*s inter * lin\n",2*debug_indent,""); #endif itv_linexpr_clear(&l1); itv_linexpr_scale(intern,lres,i1); } itv_mul(intern,ires,i1,ires); /* round */ ap_texpr0_round(intern,lres,ires, (t1==AP_RTYPE_INT && t2==AP_RTYPE_INT) ? AP_RTYPE_INT : AP_RTYPE_REAL, n->type,n->dir); /* reduce */ ap_texpr0_reduce(intern,env,lres,ires); } itv_clear(i1); break; case AP_TEXPR_MOD: itv_init(i1); itv_linexpr_init(&l1,0); /* intlinearize arguments, lres & l1 are not used */ itv_intlinearize_texpr0_rec(intern,n->exprA,env,intdim,lres,ires); itv_intlinearize_texpr0_rec(intern,n->exprB,env,intdim,&l1,i1); if (itv_is_bottom(intern,i1) || itv_is_bottom(intern,ires)){ itv_set_bottom(ires); itv_linexpr_reinit(lres,0); itv_set(lres->cst,ires); } else { /* interval modulo, no rounding */ itv_mod(intern,ires,ires,i1,n->type==AP_RTYPE_INT); itv_linexpr_reinit(lres,0); itv_set(lres->cst,ires); lres->equality = itv_is_point(intern,lres->cst); } itv_clear(i1); itv_linexpr_clear(&l1); break; default: assert(0); } return n->type; } static ap_texpr_rtype_t itv_intlinearize_texpr0_rec(itv_internal_t* intern, ap_texpr0_t* expr, itv_t* env, size_t intdim, itv_linexpr_t* lres /* out */, itv_t ires /* out */) { itv_linexpr_t r; ap_texpr_rtype_t t; assert(expr); #if LOGDEBUG printf("%*s @ ",2*debug_indent,""); ap_texpr0_print(expr,NULL); printf("\n"); debug_indent++; #endif switch(expr->discr){ case AP_TEXPR_CST: itv_set_ap_coeff(intern,ires,&expr->val.cst); itv_linexpr_reinit(lres,0); itv_set(lres->cst,ires); lres->equality = itv_is_point(intern,lres->cst); t = itv_is_int(intern,lres->cst) ? AP_RTYPE_INT : AP_RTYPE_REAL; break; case AP_TEXPR_DIM: itv_set(ires,env[expr->val.dim]); itv_linexpr_reinit(lres,1); itv_set_int(lres->cst,0); lres->linterm[0].dim = expr->val.dim; lres->linterm[0].equality = true; itv_set_int(lres->linterm[0].itv,1); t = (expr->val.dimval.node,env,intdim,lres,ires); break; default: t = 0; assert(false); } #if LOGDEBUG debug_indent--; printf("%*s = ",2*debug_indent,""); itv_linexpr_print(lres,NULL); printf(" /\\ "); itv_print(ires); printf(" t=%i\n",t); #endif return t; } bool ITVFUN(itv_intlinearize_ap_texpr0)(itv_internal_t* intern, itv_linexpr_t* res, ap_texpr0_t* expr, itv_t* env, size_t intdim) { bool exc; itv_t i; itv_init(i); itv_intlinearize_texpr0_rec(intern,expr,env,intdim,res,i); if (!itv_is_bottom(intern,i) && !itv_is_bottom(intern,res->cst)) { if (res->size==0){ itv_meet(intern,res->cst,res->cst,i); res->equality = itv_is_point(intern,res->cst); } exc = false; } else { exc = true; } itv_clear(i); return exc; } bool ITVFUN(itv_intlinearize_ap_tcons0)(itv_internal_t* intern, itv_lincons_t* res, ap_tcons0_t* cons, itv_t* env, size_t intdim) { bool exc = itv_intlinearize_ap_texpr0(intern,&res->linexpr,cons->texpr0,env,intdim); if (exc){ itv_lincons_set_bool(res,false); } else { res->constyp = cons->constyp; if (cons->scalar){ num_set_ap_scalar(res->num,cons->scalar); } else { num_set_int(res->num,0); } } return exc; } bool ITVFUN(itv_intlinearize_ap_tcons0_array)(itv_internal_t* intern, itv_lincons_array_t* res, ap_tcons0_array_t* array, itv_t* env, size_t intdim) { bool exc; itv_t itv; size_t i,index; itv_init(itv); itv_lincons_array_reinit(res,array->size); exc = false; for (i=0; isize;i++){ itv_intlinearize_texpr0_rec(intern,array->p[i].texpr0, env,intdim,&res->p[i].linexpr,itv); res->p[i].constyp = array->p[i].constyp; if (array->p[i].scalar){ num_set_ap_scalar(res->p[i].num,array->p[i].scalar); } else { num_set_int(res->p[i].num,0); } if (itv_is_bottom(intern,itv) || itv_is_bottom(intern,res->p[i].linexpr.cst) || (res->p[i].linexpr.size==0 ? itv_eval_cstlincons(intern,&res->p[i])==tbool_false : false)){ exc = true; itv_lincons_array_reinit(res,1); itv_lincons_set_bool(&res->p[0],false); break; } } itv_clear(itv); return exc; } apron-dist-0.9.10/apron/itv/itv.h0000640014525101416610000004440511005654323016447 0ustar bjeannetpopart/* ********************************************************************** */ /* itv.h: (unidimensional) intervals */ /* ********************************************************************** */ #ifndef _ITV_H_ #define _ITV_H_ #include #include "num.h" #include "bound.h" #include "itv_config.h" #include "ap_coeff.h" #include "itv_fun.h" #ifdef __cplusplus extern "C" { #endif /* Be cautious: interval [a,b] is represented by [-a,b]. This is because bound quantities are always rounded toward +infty */ typedef struct __itv_struct { bound_t inf; /* negation of the inf bound */ bound_t sup; /* sup bound */ } __itv_struct; typedef __itv_struct itv_t[1]; typedef __itv_struct* itv_ptr; /* Workspace to avoid temporary allocation and deallocation when num_t and bound_t are multiprecision numbers */ /* some useful local constant for linearization */ typedef struct { itv_t ulp; /* [-1;1] * unit in the least place */ itv_t min; /* [-1;1] * minimum positive denormal */ itv_t min_normal; /* [-1;1] * minimum positive normal */ itv_t max; /* [-1;1] * maximum non +oo */ itv_t max_exact; /* [-1;1] * maximum exactly representable integer */ } float_const; typedef struct itv_internal_t { num_t canonicalize_num; bound_t muldiv_bound; bound_t mul_bound; bound_t sqrt_bound; bound_t linear_bound; bound_t linear_bound2; bound_t linear_bound3; itv_t mul_itv; itv_t mul_itv2; ap_scalar_t* ap_conversion_scalar; bound_t ap_conversion_bound; itv_t eval_itv; itv_t eval_itv2; itv_t eval_itv3; num_t quasi_num; itv_t boxize_lincons_itv; itv_t boxize_lincons_eval; bound_t boxize_lincons_bound; float_const cst_half, cst_single, cst_double, cst_extended, cst_quad; itv_t itv_half; /* [-0.5,0.5] */ mpz_t reduce_lincons_gcd; mpz_t reduce_lincons_mpz; } itv_internal_t; static inline itv_internal_t* itv_internal_alloc(void); /* Allocate and initialize internal workspace */ static inline void itv_internal_free(itv_internal_t* intern); /* Clear and free internal workspace */ static inline void itv_internal_init(itv_internal_t* intern); static inline void itv_internal_clear(itv_internal_t* intern); /* GMP Semantics */ /* ********************************************************************** */ /* itv */ /* ********************************************************************** */ /* Initialization and clearing */ static inline void itv_init(itv_t a); static inline void itv_init_array(itv_t* a, size_t size); static inline void itv_init_set(itv_t a, itv_t b); static inline void itv_clear(itv_t a); static inline void itv_clear_array(itv_t* a, size_t size); static inline itv_t* itv_array_alloc(size_t size); static inline void itv_array_free(itv_t* a, size_t size); /* Assignement */ static inline void itv_set(itv_t a, itv_t b); static inline void itv_set_num(itv_t a, num_t b); static inline void itv_set_num2(itv_t a, num_t b, num_t c); static inline void itv_set_int(itv_t a, long int b); static inline void itv_set_int2(itv_t a, long int b, long int c); static inline void itv_set_bottom(itv_t a); static inline void itv_set_top(itv_t a); static inline void itv_swap(itv_t a, itv_t b); /* a = [-b,b] */ static inline void itv_set_unit_num(itv_t a, num_t b); static inline void itv_set_unit_bound(itv_t a, bound_t b); /* a = b + [-c,c] */ static inline void itv_enlarge_bound(itv_t a, itv_t b, bound_t c); /* Normalization and tests */ static inline bool itv_canonicalize(itv_internal_t* intern, itv_t a, bool integer); /* Canonicalize an interval: - if integer is true, narrows bound to integers - return true if the interval is bottom - return false otherwise */ static inline bool itv_is_top(itv_t a); static inline bool itv_is_bottom(itv_internal_t* intern, itv_t a); /* Return true iff the interval is resp. [-oo,+oo] or empty */ static inline bool itv_is_point(itv_internal_t* intern, itv_t a); /* Return true iff the interval is a single point */ static inline bool itv_is_zero(itv_t a); /* Return true iff the interval is a single zero point */ static inline bool itv_is_leq(itv_t a, itv_t b); /* Inclusion test */ static inline bool itv_is_eq(itv_t a, itv_t b); /* Equality test */ static inline int itv_hash(itv_t a); /* Hash code */ static inline bool itv_is_pos(itv_t a); static inline bool itv_is_neg(itv_t a); /* Included in [0;+oo], [-oo;0], or any of those */ static inline bool itv_is_int(itv_internal_t* intern, itv_t a); /* has integer bounds */ static inline void itv_range_abs(bound_t a, itv_t b); /* a=(max b - min b) */ static inline void itv_range_rel(itv_internal_t* intern, bound_t a, itv_t b); /* a=(max b - min b) / (|a+b|/2) */ /* Lattice operations */ static inline bool itv_meet(itv_internal_t* intern, itv_t a, itv_t b, itv_t c); /* Assign a with the intersection of b and c */ static inline void itv_join(itv_t a, itv_t b, itv_t c); /* Assign a with the union of b and c */ static inline void itv_widening(itv_t a, itv_t b, itv_t c); /* Assign a with the standard interval widening of b by c */ /* Arithmetic operations */ static inline void itv_add(itv_t a, itv_t b, itv_t c); static inline void itv_sub(itv_t a, itv_t b, itv_t c); static inline void itv_neg(itv_t a, itv_t b); static inline void itv_mul(itv_internal_t* intern, itv_t a, itv_t b, itv_t c); static inline void itv_div(itv_internal_t* intern, itv_t a, itv_t b, itv_t c); static inline void itv_add_num(itv_t a, itv_t b, num_t c); static inline void itv_sub_num(itv_t a, itv_t b, num_t c); static inline void itv_mul_num(itv_t a, itv_t b, num_t c); static inline void itv_div_num(itv_t a, itv_t b, num_t c); static inline void itv_add_bound(itv_t a, itv_t b, bound_t c); static inline void itv_sub_bound(itv_t a, itv_t b, bound_t c); static inline void itv_mul_bound(itv_t a, itv_t b, bound_t c); static inline void itv_div_bound(itv_t a, itv_t b, bound_t c); static inline bool itv_sqrt(itv_internal_t* intern, itv_t a, itv_t b); static inline void itv_abs(itv_t a, itv_t b); static inline void itv_mul_2exp(itv_t a, itv_t b, int c); static inline void itv_magnitude(bound_t a, itv_t b); /* get the absolute value of maximal bound */ static inline void itv_mod(itv_internal_t* intern, itv_t a, itv_t b, itv_t c, bool is_int); /* x mod y = x - y*trunc(x/y) */ /* Integer casts (rounding towards +oo, -oo, 0, or worst-case) */ static inline void itv_ceil(itv_t a, itv_t b); static inline void itv_floor(itv_t a, itv_t b); static inline void itv_trunc(itv_t a, itv_t b); static inline void itv_to_int(itv_t a, itv_t b); /* Floating-point casts (worst cases) */ static inline void itv_to_float(itv_t a, itv_t b); static inline void itv_to_double(itv_t a, itv_t b); /* Printing */ static inline int itv_snprint(char* s, size_t size, itv_t a); static inline void itv_fprint(FILE* stream, itv_t a); static inline void itv_print(itv_t a); /* All these functions return true if the conversion is exact */ static inline bool itv_set_ap_scalar(itv_internal_t* intern, itv_t a, ap_scalar_t* b); /* Convert a ap_scalar_t into a itv_t. Assumes the scalar is finite. If it returns true, the interval is a single point */ static inline bool itv_set_ap_interval(itv_internal_t* intern, itv_t a, ap_interval_t* b); /* Convert a ap_interval_t into a itv_t */ static inline bool itv_set_ap_coeff(itv_internal_t* intern, itv_t a, ap_coeff_t* b); /* Convert a ap_coeff_t into a itv_t. */ static inline bool ap_interval_set_itv(itv_internal_t* intern, ap_interval_t* a, itv_t b); /* Convert a itv_t into a ap_interval_t */ static inline bool ap_coeff_set_itv(itv_internal_t* intern, ap_coeff_t* a, itv_t b); /* Convert a itv_t into a ap_coeff_t */ static inline bool itv_array_set_ap_interval_array(itv_internal_t* intern, itv_t** ptitv, ap_interval_t** array, size_t size); /* Convert an array of ap_interval_t into an array of itv_t. The paramater ptitv is a result parameter. The result is to be found in *ptitv */ /* ********************************************************************** */ /* Definition of inline functions */ /* ********************************************************************** */ void ITVFUN(itv_internal_init)(itv_internal_t* intern); void ITVFUN(itv_internal_clear)(itv_internal_t* intern); itv_internal_t* ITVFUN(itv_internal_alloc)(void); void ITVFUN(itv_internal_free)(itv_internal_t* intern); bool ITVFUN(itv_canonicalize)(itv_internal_t* intern, itv_t a, bool integer); void ITVFUN(itv_mul_num)(itv_t a, itv_t b, num_t c); void ITVFUN(itv_div_num)(itv_t a, itv_t b, num_t c); void ITVFUN(itv_div_num)(itv_t a, itv_t b, num_t c); void ITVFUN(itv_mul_bound)(itv_t a, itv_t b, bound_t c); void ITVFUN(itv_div_bound)(itv_t a, itv_t b, bound_t c); void ITVFUN(itv_sub)(itv_t a, itv_t b, itv_t c); void ITVFUN(itv_neg)(itv_t a, itv_t b); void ITVFUN(itv_mul)(itv_internal_t* intern, itv_t a, itv_t b, itv_t c); void ITVFUN(itv_div)(itv_internal_t* intern, itv_t a, itv_t b, itv_t c); bool ITVFUN(itv_sqrt)(itv_internal_t* intern, itv_t a, itv_t b); void ITVFUN(itv_abs)(itv_t a, itv_t b); void ITVFUN(itv_mod)(itv_internal_t* intern, itv_t a, itv_t b, itv_t c, bool is_int); void ITVFUN(itv_fprint)(FILE* stream, itv_t a); int ITVFUN(itv_snprint)(char* s, size_t size, itv_t a); bool ITVFUN(itv_set_ap_scalar)(itv_internal_t* intern, itv_t a, ap_scalar_t* b); bool ITVFUN(itv_set_ap_interval)(itv_internal_t* intern, itv_t a, ap_interval_t* b); bool ITVFUN(itv_set_ap_coeff)(itv_internal_t* intern, itv_t itv, ap_coeff_t* coeff); bool ITVFUN(ap_interval_set_itv)(itv_internal_t* intern, ap_interval_t* a, itv_t b); bool ITVFUN(ap_coeff_set_itv)(itv_internal_t* intern, ap_coeff_t* a, itv_t b); bool ITVFUN(itv_array_set_ap_interval_array)(itv_internal_t* intern, itv_t** ptitv, ap_interval_t** array, size_t size); static inline void itv_internal_init(itv_internal_t* intern) { ITVFUN(itv_internal_init)(intern); } static inline void itv_internal_clear(itv_internal_t* intern) { ITVFUN(itv_internal_clear)(intern); } static inline itv_internal_t* itv_internal_alloc(void) { return ITVFUN(itv_internal_alloc)(); } static inline void itv_internal_free(itv_internal_t* intern) { ITVFUN(itv_internal_free)(intern); } static inline bool itv_canonicalize(itv_internal_t* intern, itv_t a, bool integer) { return ITVFUN(itv_canonicalize)(intern,a,integer); } static inline void itv_mul_num(itv_t a, itv_t b, num_t c) { ITVFUN(itv_mul_num)(a,b,c); } static inline void itv_div_num(itv_t a, itv_t b, num_t c) { ITVFUN(itv_div_num)(a,b,c); } static inline void itv_mul_bound(itv_t a, itv_t b, bound_t c) { ITVFUN(itv_mul_bound)(a,b,c); } static inline void itv_div_bound(itv_t a, itv_t b, bound_t c) { ITVFUN(itv_div_bound)(a,b,c); } static inline void itv_sub(itv_t a, itv_t b, itv_t c) { ITVFUN(itv_sub)(a,b,c); } static inline void itv_neg(itv_t a, itv_t b) { ITVFUN(itv_neg)(a,b); } static inline void itv_mul(itv_internal_t* intern, itv_t a, itv_t b, itv_t c) { ITVFUN(itv_mul)(intern,a,b,c); } static inline void itv_div(itv_internal_t* intern, itv_t a, itv_t b, itv_t c) { ITVFUN(itv_div)(intern,a,b,c); } static inline void itv_fprint(FILE* stream, itv_t a) { ITVFUN(itv_fprint)(stream,a); } static inline int itv_snprint(char* s, size_t size, itv_t a) { return ITVFUN(itv_snprint)(s,size,a); } static inline bool itv_set_ap_scalar(itv_internal_t* intern, itv_t a, ap_scalar_t* b) { return ITVFUN(itv_set_ap_scalar)(intern,a,b); } static inline bool itv_set_ap_interval(itv_internal_t* intern, itv_t a, ap_interval_t* b) { return ITVFUN(itv_set_ap_interval)(intern,a,b); } static inline bool itv_set_ap_coeff(itv_internal_t* intern, itv_t itv, ap_coeff_t* coeff) { return ITVFUN(itv_set_ap_coeff)(intern,itv,coeff); } static inline bool ap_interval_set_itv(itv_internal_t* intern, ap_interval_t* a, itv_t b) { return ITVFUN(ap_interval_set_itv)(intern,a,b); } static inline bool ap_coeff_set_itv(itv_internal_t* intern, ap_coeff_t* a, itv_t b) { return ITVFUN(ap_coeff_set_itv)(intern,a,b); } static inline bool itv_array_set_ap_interval_array(itv_internal_t* intern, itv_t** ptitv, ap_interval_t** array, size_t size) { return ITVFUN(itv_array_set_ap_interval_array)(intern,ptitv,array,size); } static inline void itv_init(itv_t a) { bound_init(a->inf); bound_init(a->sup); } static inline void itv_init_array(itv_t* a, size_t size) { size_t i; for (i=0; iinf,b->inf); bound_init_set(a->sup,b->sup); } static inline void itv_clear(itv_t a) { bound_clear(a->inf); bound_clear(a->sup); } static inline void itv_clear_array(itv_t* a, size_t size) { #if !defined(NUM_NATIVE) size_t i; for (i=0; iinf,b->inf); bound_set(a->sup,b->sup); } static inline void itv_set_num(itv_t a, num_t b) { bound_set_num(a->sup,b); bound_neg(a->inf,a->sup); } static inline void itv_set_num2(itv_t a, num_t b, num_t c) { bound_set_num(a->sup,b); num_neg(c,c); bound_set_num(a->inf,c); num_neg(c,c); } static inline void itv_set_unit_num(itv_t a, num_t b) { bound_set_num(a->inf,b); bound_set_num(a->sup,b); } static inline void itv_set_unit_bound(itv_t a, bound_t b) { bound_set(a->inf,b); bound_set(a->sup,b); } static inline void itv_enlarge_bound(itv_t a, itv_t b, bound_t c) { bound_add(a->inf,b->inf,c); bound_add(a->sup,b->sup,c); } static inline void itv_set_int(itv_t a, long int b) { bound_set_int(a->inf,-b); bound_set_int(a->sup,b); } static inline void itv_set_int2(itv_t a, long int b, long int c) { bound_set_int(a->inf,-b); bound_set_int(a->sup,c); } static inline void itv_set_bottom(itv_t a) { bound_set_int(a->inf,-1); bound_set_int(a->sup,-1); } static inline void itv_set_top(itv_t a) { bound_set_infty(a->inf,1); bound_set_infty(a->sup,1); } static inline void itv_swap(itv_t a, itv_t b) { itv_t t; *t=*a;*a=*b;*b=*t; } static inline bool itv_is_top(itv_t a) { return bound_infty(a->inf) && bound_infty(a->sup); } static inline bool itv_is_bottom(itv_internal_t* intern, itv_t a) { return itv_canonicalize(intern, a, false); } static inline bool itv_is_point(itv_internal_t* intern, itv_t a) { if (!bound_infty(a->inf) && !bound_infty(a->sup)){ num_neg(intern->canonicalize_num,bound_numref(a->inf)); return num_equal(intern->canonicalize_num,bound_numref(a->sup)); } else return false; } static inline bool itv_is_zero(itv_t a) { return bound_sgn(a->inf)==0 && bound_sgn(a->sup)==0; } static inline bool itv_is_leq(itv_t a, itv_t b) { return bound_cmp(a->sup,b->sup)<=0 && bound_cmp(a->inf,b->inf)<=0; } static inline bool itv_is_eq(itv_t a, itv_t b) { return bound_equal(a->sup,b->sup) && bound_equal(a->inf,b->inf); } static inline int itv_hash(itv_t a) { return (5*bound_hash(a->inf) + 7*bound_hash(a->sup)); } static inline bool itv_meet(itv_internal_t* intern, itv_t a, itv_t b, itv_t c) { bound_min(a->sup,b->sup,c->sup); bound_min(a->inf,b->inf,c->inf); return itv_canonicalize(intern,a,false); } static inline void itv_join(itv_t a, itv_t b, itv_t c) { bound_max(a->sup,b->sup,c->sup); bound_max(a->inf,b->inf,c->inf); } static inline void bound_widening(bound_t a, bound_t b, bound_t c) { if (bound_infty(c) || bound_cmp(b,c)<0){ bound_set_infty(a,+1); } else { bound_set(a,b); } } static inline void itv_widening(itv_t a, itv_t b, itv_t c) { bound_widening(a->sup,b->sup,c->sup); bound_widening(a->inf,b->inf,c->inf); } static inline void itv_add(itv_t a, itv_t b, itv_t c) { bound_add(a->sup,b->sup,c->sup); bound_add(a->inf,b->inf,c->inf); } static inline void itv_add_num(itv_t a, itv_t b, num_t c) { bound_add_num(a->sup,b->sup,c); bound_sub_num(a->inf,b->inf,c); } static inline void itv_sub_num(itv_t a, itv_t b, num_t c) { bound_sub_num(a->sup,b->sup,c); bound_add_num(a->inf,b->inf,c); } static inline void itv_add_bound(itv_t a, itv_t b, bound_t c) { bound_add(a->sup,b->sup,c); bound_sub(a->inf,b->inf,c); } static inline void itv_sub_bound(itv_t a, itv_t b, bound_t c) { bound_sub(a->sup,b->sup,c); bound_add(a->inf,b->inf,c); } static inline bool itv_sqrt(itv_internal_t* intern, itv_t a, itv_t b) { return ITVFUN(itv_sqrt)(intern,a,b); } static inline void itv_abs(itv_t a, itv_t b) { ITVFUN(itv_abs)(a,b); } static inline void itv_mod(itv_internal_t* intern, itv_t a, itv_t b, itv_t c, bool is_int) { ITVFUN(itv_mod)(intern,a,b,c,is_int); } static inline void itv_print(itv_t itv) { itv_fprint(stdout,itv); } static inline void itv_ceil(itv_t a, itv_t b) { bound_ceil(a->sup,b->sup); bound_floor(a->inf,b->inf); } static inline void itv_floor(itv_t a, itv_t b) { bound_floor(a->sup,b->sup); bound_ceil(a->inf,b->inf); } static inline void itv_trunc(itv_t a, itv_t b) { bound_trunc(a->sup,b->sup); bound_trunc(a->inf,b->inf); } static inline void itv_to_int(itv_t a, itv_t b) { bound_ceil(a->sup,b->sup); bound_ceil(a->inf,b->inf); } static inline void itv_to_float(itv_t a, itv_t b) { bound_to_float(a->sup,b->sup); bound_to_float(a->inf,b->inf); } static inline void itv_to_double(itv_t a, itv_t b) { bound_to_double(a->sup,b->sup); bound_to_double(a->inf,b->inf); } static inline void itv_mul_2exp(itv_t a, itv_t b, int c) { bound_mul_2exp(a->sup,b->sup,c); bound_mul_2exp(a->inf,b->inf,c); } static inline bool itv_is_pos(itv_t a) { return (bound_sgn(a->inf)<=0); } static inline bool itv_is_neg(itv_t a) { return (bound_sgn(a->sup)<=0); } static inline void itv_magnitude(bound_t a, itv_t b) { if (bound_sgn(b->inf)<=0) bound_set(a,b->sup); else if (bound_sgn(b->sup)<=0) bound_set(a,b->inf); else bound_max(a,b->inf,b->sup); } static inline void itv_range_abs(bound_t a, itv_t b) { bound_add(a,b->sup,b->inf); } static inline void itv_range_rel(itv_internal_t* intern, bound_t a, itv_t b) { bound_add(a,b->sup,b->inf); if (!bound_infty(a)) { itv_magnitude(intern->muldiv_bound,b); bound_div_2(intern->muldiv_bound,intern->muldiv_bound); bound_div(a,a,intern->muldiv_bound); } } static inline bool itv_is_int(itv_internal_t* intern, itv_t a) { bound_trunc(intern->muldiv_bound,a->sup); if (bound_cmp(intern->muldiv_bound,a->sup)) return false; bound_trunc(intern->muldiv_bound,a->inf); return !bound_cmp(intern->muldiv_bound,a->inf); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/itv/itv.c0000640014525101416610000004355411005654323016446 0ustar bjeannetpopart/* ********************************************************************** */ /* itv.c: (unidimensional) intervals */ /* ********************************************************************** */ #include "itv.h" #include "math.h" /* The macro ITVFUN(itv_name) (defined in itv.h) expands name with itvNUM_SUFFIX_ */ static void make_float_const(int frac_bits, int exp_bits, int exp_bias, float_const* cst) { bound_t b,c; bound_init(b); bound_init(c); itv_init(cst->ulp); itv_init(cst->min); itv_init(cst->min_normal); itv_init(cst->max); itv_init(cst->max_exact); bound_set_int(b,1); bound_mul_2exp(b,b,-frac_bits); itv_set_unit_bound(cst->ulp,b); bound_set_int(b,1); bound_mul_2exp(b,b,1-exp_bias-frac_bits); itv_set_unit_bound(cst->min,b); bound_set_int(b,1); bound_mul_2exp(b,b,1-exp_bias); itv_set_unit_bound(cst->min_normal,b); bound_set_int(b,2); bound_set_int(c,1); bound_mul_2exp(c,c,-frac_bits); bound_sub(b,b,c); bound_mul_2exp(b,b,(1<max,b); bound_set_int(b,1); bound_mul_2exp(b,b,frac_bits); itv_set_unit_bound(cst->max_exact,b); bound_clear(b); bound_clear(c); } static void float_const_clear(float_const* cst) { itv_clear(cst->ulp); itv_clear(cst->min); itv_clear(cst->min_normal); itv_clear(cst->max); itv_clear(cst->max_exact); } void ITVFUN(itv_internal_init)(itv_internal_t* intern) { num_init(intern->canonicalize_num); bound_init(intern->muldiv_bound); bound_init(intern->mul_bound); bound_init(intern->sqrt_bound); bound_init(intern->linear_bound); bound_init(intern->linear_bound2); bound_init(intern->linear_bound3); itv_init(intern->mul_itv); itv_init(intern->mul_itv2); intern->ap_conversion_scalar = ap_scalar_alloc(); bound_init(intern->ap_conversion_bound); itv_init(intern->eval_itv); itv_init(intern->eval_itv2); itv_init(intern->eval_itv3); num_init(intern->quasi_num); itv_init(intern->boxize_lincons_itv); itv_init(intern->boxize_lincons_eval); bound_init(intern->boxize_lincons_bound); mpz_init(intern->reduce_lincons_gcd); mpz_init(intern->reduce_lincons_mpz); make_float_const(10,5,15,&intern->cst_half); /* 16-bit */ make_float_const(23,8,127,&intern->cst_single); /* 32-bit */ make_float_const(52,11,1023,&intern->cst_double); /* 64-bit */ make_float_const(63,15,16383,&intern->cst_extended); /* 80-bit, no hidden bit */ make_float_const(112,15,16383,&intern->cst_quad); /* 128-bit */ itv_init(intern->itv_half); itv_set_int2(intern->itv_half,-1,1); itv_mul_2exp(intern->itv_half,intern->itv_half,-1); } void ITVFUN(itv_internal_clear)(itv_internal_t* intern) { num_clear(intern->canonicalize_num); bound_clear(intern->muldiv_bound); bound_clear(intern->mul_bound); bound_clear(intern->sqrt_bound); bound_clear(intern->linear_bound); bound_clear(intern->linear_bound2); bound_clear(intern->linear_bound3); itv_clear(intern->mul_itv); itv_clear(intern->mul_itv2); ap_scalar_free(intern->ap_conversion_scalar); intern->ap_conversion_scalar = NULL; bound_clear(intern->ap_conversion_bound); itv_clear(intern->eval_itv); itv_clear(intern->eval_itv2); itv_clear(intern->eval_itv3); num_clear(intern->quasi_num); itv_clear(intern->boxize_lincons_itv); itv_clear(intern->boxize_lincons_eval); bound_clear(intern->boxize_lincons_bound); mpz_clear(intern->reduce_lincons_gcd); mpz_clear(intern->reduce_lincons_mpz); float_const_clear(&intern->cst_half); float_const_clear(&intern->cst_single); float_const_clear(&intern->cst_double); float_const_clear(&intern->cst_extended); float_const_clear(&intern->cst_quad); itv_clear(intern->itv_half); } itv_internal_t* ITVFUN(itv_internal_alloc)(void) { itv_internal_t* intern = malloc(sizeof(itv_internal_t)); itv_internal_init(intern); return intern; } void ITVFUN(itv_internal_free)(itv_internal_t* intern) { itv_internal_clear(intern); free(intern); } /* ********************************************************************** */ /* Normalization and tests */ /* ********************************************************************** */ /* If integer is true, narrow the interval to integer bounds. In any case, return true if the interval is bottom */ bool ITVFUN(itv_canonicalize)(itv_internal_t* intern, itv_t a, bool integer) { bool exc; if (integer){ bound_floor(a->inf,a->inf); bound_floor(a->sup,a->sup); } if (bound_infty(a->inf) || bound_infty(a->sup)) return false; /* Check that it is not bottom */ exc = false; num_neg(intern->canonicalize_num,bound_numref(a->inf)); if (bound_cmp_num(a->sup,intern->canonicalize_num) < 0) exc = true; return exc; } /* ********************************************************************** */ /* Arithmetic operations */ /* ********************************************************************** */ /* We assume no aliasing between - an itv and a num or a bound, */ void ITVFUN(itv_mul_num)(itv_t a, itv_t b, num_t c) { bound_mul_num(a->sup,b->sup,c); bound_mul_num(a->inf,b->inf,c); if (num_sgn(c)<0){ bound_swap(a->inf,a->sup); bound_neg(a->sup,a->sup); bound_neg(a->inf,a->inf); } } void ITVFUN(itv_mul_bound)(itv_t a, itv_t b, bound_t c) { assert (c!=a->inf && c!=a->sup && c!=b->inf && c!=b->sup); bound_mul(a->sup,b->sup,c); bound_mul(a->inf,b->inf,c); if (bound_sgn(c)<0){ bound_swap(a->inf,a->sup); bound_neg(a->sup,a->sup); bound_neg(a->inf,a->inf); } } void ITVFUN(itv_div_num)(itv_t a, itv_t b, num_t c) { bound_div_num(a->sup,b->sup,c); bound_div_num(a->inf,b->inf,c); if (num_sgn(c)<0){ bound_swap(a->inf,a->sup); bound_neg(a->sup,a->sup); bound_neg(a->inf,a->inf); } } void ITVFUN(itv_div_bound)(itv_t a, itv_t b, bound_t c) { assert (c!=a->inf && c!=a->sup && c!=b->inf && c!=b->sup); bound_div(a->sup,b->sup,c); bound_div(a->inf,b->inf,c); if (bound_sgn(c)<0){ bound_swap(a->inf,a->sup); bound_neg(a->sup,a->sup); bound_neg(a->inf,a->inf); } } void ITVFUN(itv_sub)(itv_t a, itv_t b, itv_t c) { if (a!=c){ bound_add(a->inf,b->inf,c->sup); bound_add(a->sup,b->sup,c->inf); } else { bound_swap(a->inf,a->sup); itv_add(a,b,c); } } void ITVFUN(itv_neg)(itv_t a, itv_t b) { if (a!=b){ bound_set(a->inf,b->sup); bound_set(a->sup,b->inf); } else { bound_swap(a->inf,a->sup); } } bool ITVFUN(itv_sqrt)(itv_internal_t* intern, itv_t a, itv_t b) { bool exact = true; if (itv_is_bottom(intern,b) || bound_sgn(b->sup)<0) { /* empty result */ itv_set_bottom(a); return true; } /* lower bound */ if (bound_sgn(b->inf)>=0) { bound_set_int(a->inf,0); } else { bound_neg(b->inf,b->inf); bound_sqrt(intern->sqrt_bound,a->inf,b->inf); exact = exact && bound_equal(intern->sqrt_bound,a->inf); bound_neg(b->inf,b->inf); if (a!=b) bound_neg(a->inf,a->inf); } /* upper bound */ bound_sqrt(a->sup,intern->sqrt_bound,b->sup); exact = exact && bound_equal(intern->sqrt_bound,a->sup); return exact; } void ITVFUN(itv_abs)(itv_t a, itv_t b) { if (bound_sgn(b->inf)<=0) /* positive interval */ itv_set(a,b); else if (bound_sgn(b->sup)<=0) /* negative interval */ itv_neg(a,b); else { bound_max(a->sup,b->inf,b->sup); bound_set_int(a->inf,0); } } void ITVFUN(itv_mod)(itv_internal_t* intern, itv_t a, itv_t b, itv_t c, bool is_int) { /* b-|c|*trunc(b/|c|) */ itv_abs(intern->eval_itv, c); if (!bound_sgn(intern->eval_itv->inf)) itv_set_top(a); else { itv_div(intern, intern->eval_itv2, b, intern->eval_itv); itv_trunc(intern->eval_itv2, intern->eval_itv2); itv_mul(intern, intern->eval_itv2, intern->eval_itv2, intern->eval_itv); if (is_int) bound_sub_uint(intern->eval_itv->sup,intern->eval_itv->sup,1); if (bound_sgn(b->sup)<0) { /* [-max|c|,0] */ bound_set(intern->eval_itv->inf, intern->eval_itv->sup); bound_set_int(intern->eval_itv->sup, 0); } else if (bound_sgn(b->inf)>0) /* [-max|c|,max|c|] */ bound_set(intern->eval_itv->inf, intern->eval_itv->sup); else /* [0,max|c|] */ bound_set_int(intern->eval_itv->inf, 0); itv_sub(a, b, intern->eval_itv2); itv_meet(intern, a, a, intern->eval_itv); } } /* ====================================================================== */ /* Multiplication */ /* ====================================================================== */ /* Assume that both intervals are positive */ static void itv_mulpp(itv_internal_t* intern, itv_t a, itv_t b, itv_t c) { assert(bound_sgn(b->inf)<=0 && bound_sgn(c->inf)<=0); bound_mul(a->inf,b->inf,c->inf); bound_neg(a->inf,a->inf); bound_mul(a->sup,b->sup,c->sup); } /* Assume that both intervals are negative */ static void itv_mulnn(itv_internal_t* intern, itv_t a, itv_t b, itv_t c) { assert(bound_sgn(b->sup)<=0 && bound_sgn(c->sup)<=0); bound_mul(a->inf,b->inf,c->inf); bound_mul(a->sup,b->sup,c->sup); bound_neg(a->sup,a->sup); bound_swap(a->inf,a->sup); } /* Assume that b is positive and c negative */ static void itv_mulpn(itv_internal_t* intern, itv_t a, itv_t b, itv_t c) { assert(bound_sgn(b->inf)<=0 && bound_sgn(c->sup)<=0); bound_mul(intern->mul_bound,b->inf,c->sup); bound_mul(a->inf,b->sup,c->inf); bound_neg(a->sup,intern->mul_bound); } /* Assume that interval c is positive */ static void itv_mulp(itv_internal_t* intern, itv_t a, itv_t b, itv_t c) { assert(bound_sgn(c->inf)<=0); if (bound_sgn(b->inf)<=0){ /* b is positive */ itv_mulpp(intern,a,b,c); } else if (bound_sgn(b->sup)<=0){ /* b is negative */ itv_mulpn(intern,a,c,b); } else { /* 0 is in the middle of b: one multiplies b by c->sup */ bound_mul(a->inf,b->inf,c->sup); bound_mul(a->sup,b->sup,c->sup); } } /* Assume that interval c is negative */ static void itv_muln(itv_internal_t* intern, itv_t a, itv_t b, itv_t c) { assert(bound_sgn(c->sup)<=0); if (bound_sgn(b->inf)<=0){ /* b is positive */ itv_mulpn(intern,a,b,c); } else if (bound_sgn(b->sup)<=0){ /* b is negative */ itv_mulnn(intern,a,b,c); } else { /* 0 is in the middle of b: one multiplies b by c->inf */ bound_mul(a->sup,b->sup,c->inf); bound_mul(a->inf,b->inf,c->inf); bound_swap(a->inf,a->sup); } } void ITVFUN(itv_mul)(itv_internal_t* intern, itv_t a, itv_t b, itv_t c) { if (bound_sgn(c->inf)<=0){ /* c is positive, */ itv_mulp(intern,a,b,c); } else if (bound_sgn(c->sup)<=0){ /* c is negative */ itv_muln(intern,a,b,c); } else if (bound_sgn(b->inf)<=0){ /* b is positive, */ itv_mulp(intern,a,c,b); } else if (bound_sgn(c->sup)<=0){ /* b is negative */ itv_muln(intern,a,c,b); } else { /* divide c */ bound_set(intern->mul_itv->inf,c->inf); bound_set_int(intern->mul_itv->sup,0); itv_muln(intern,intern->mul_itv2,b,intern->mul_itv); bound_set_int(intern->mul_itv->inf,0); bound_set(intern->mul_itv->sup,c->sup); itv_mulp(intern,a,b,intern->mul_itv); itv_join(a,a,intern->mul_itv2); } } /* ====================================================================== */ /* Division */ /* ====================================================================== */ /* Assume that both intervals are positive */ static void itv_divpp(itv_internal_t* intern, itv_t a, itv_t b, itv_t c) { assert(bound_sgn(b->inf)<=0 && bound_sgn(c->inf)<0); bound_div(intern->mul_bound,b->sup,c->inf); bound_div(a->inf,b->inf,c->sup); bound_neg(a->sup,intern->mul_bound); } /* Assume that both intervals are negative */ static void itv_divnn(itv_internal_t* intern, itv_t a, itv_t b, itv_t c) { assert(bound_sgn(b->sup)<=0 && bound_sgn(c->sup)<0); if (a!=b){ bound_div(a->inf,b->sup,c->inf); bound_div(a->sup,b->inf,c->sup); bound_neg(a->sup,a->sup); } else { bound_div(intern->mul_bound,b->sup,c->inf); bound_div(a->sup,b->inf,c->sup); bound_neg(a->sup,a->sup); bound_set(a->inf,intern->mul_bound); } } /* Assume that b is positive and c negative */ static void itv_divpn(itv_internal_t* intern, itv_t a, itv_t b, itv_t c) { assert(bound_sgn(b->inf)<=0 && bound_sgn(c->sup)<0); /* bound_div(a->inf,b->sup,c->sup); bound_neg(a->inf,a->inf) bound_div(a->sup,b->inf,c->inf); */ bound_div(a->sup,b->sup,c->sup); bound_div(a->inf,b->inf,c->inf); bound_neg(a->sup,a->sup); bound_swap(a->inf,a->sup); } /* Assume that b is negative and c positive */ static void itv_divnp(itv_internal_t* intern, itv_t a, itv_t b, itv_t c) { assert(bound_sgn(b->sup)<=0 && bound_sgn(c->inf)<0); bound_neg(b->inf, b->inf); bound_div(a->inf,b->inf,c->inf); bound_div(a->sup,b->sup,c->sup); if (a!=b) bound_neg(b->inf, b->inf); } /* Assume that interval c is positive */ static void itv_divp(itv_internal_t* intern, itv_t a, itv_t b, itv_t c) { assert(bound_sgn(c->inf)<0); if (bound_sgn(b->inf)<=0){ /* b is positive */ itv_divpp(intern,a,b,c); } else if (bound_sgn(b->sup)<=0){ /* b is negative */ itv_divnp(intern,a,b,c); } else { /* 0 is in the middle of b: one divides b by c->inf */ bound_div(a->sup,b->sup,c->inf); bound_neg(a->sup,a->sup); bound_div(a->inf,b->inf,c->inf); bound_neg(a->inf,a->inf); } } /* Assume that interval c is negative */ static void itv_divn(itv_internal_t* intern, itv_t a, itv_t b, itv_t c) { assert(bound_sgn(c->sup)<0); if (bound_sgn(b->inf)<=0){ /* b is positive */ itv_divpn(intern,a,b,c); } else if (bound_sgn(b->sup)<=0){ /* b is negative */ itv_divnn(intern,a,b,c); } else { /* 0 is in the middle of b: one cross-divide b by c->sup */ /* bound_div(a->inf,b->sup,c->sup); bound_div(a->sup,b->inf,c->sup); */ bound_div(a->inf,b->inf,c->sup); bound_div(a->sup,b->sup,c->sup); bound_swap(a->inf,a->sup); bound_neg(a->inf,a->inf); bound_neg(a->sup,a->sup); } } void ITVFUN(itv_div)(itv_internal_t* intern, itv_t a, itv_t b, itv_t c) { if (bound_sgn(c->inf)<0){ /* c is positive */ itv_divp(intern,a,b,c); } else if (bound_sgn(c->sup)<0){ /* c is negative */ itv_divn(intern,a,b,c); } else if (bound_sgn(b->inf)==0 && bound_sgn(b->sup)==0){ /* b is [0,0] */ itv_set(a,b); } else { itv_set_top(a); } } /* ********************************************************************** */ /* Printing */ /* ********************************************************************** */ void ITVFUN(itv_fprint)(FILE* stream, itv_t a) { num_t num; fprintf(stream,"["); if (bound_infty(a->inf)) fprintf(stream,"-oo"); else { num_init(num); num_neg(num,bound_numref(a->inf)); num_fprint(stream,num); num_clear(num); } fprintf(stream,","); bound_fprint(stream,a->sup); fprintf(stream,"]"); } int ITVFUN(itv_snprint)(char* s, size_t size, itv_t a) { num_t num; int count = 0; count += snprintf(s+count,size-count,"["); if (bound_infty(a->inf)) count += snprintf(s+count,size-count,"-oo"); else { num_init(num); num_neg(num,bound_numref(a->inf)); count += num_snprint(s+count,size-count,num); num_clear(num); } count += snprintf(s+count,size-count,","); bound_snprint(s+count,size-count,a->sup); count += snprintf(s+count,size-count,"]"); return count; } /* ********************************************************************** */ /* Conversions */ /* ********************************************************************** */ bool ITVFUN(itv_set_ap_scalar)(itv_internal_t* intern, itv_t a, ap_scalar_t* b) { assert (ap_scalar_infty(b)==0); bool exact = bound_set_ap_scalar(a->sup,b); if (exact){ bound_neg(a->inf,a->sup); return true; } else { ap_scalar_neg(intern->ap_conversion_scalar, b); bound_set_ap_scalar(a->inf,intern->ap_conversion_scalar); return false; } } bool ITVFUN(itv_set_ap_interval)(itv_internal_t* intern, itv_t a, ap_interval_t* b) { ap_scalar_neg(intern->ap_conversion_scalar, b->inf); bool b1 = bound_set_ap_scalar(a->inf,intern->ap_conversion_scalar); bool b2 = bound_set_ap_scalar(a->sup,b->sup); return b1 && b2; } bool ITVFUN(itv_set_ap_coeff)(itv_internal_t* intern, itv_t itv, ap_coeff_t* coeff) { switch(coeff->discr){ case AP_COEFF_SCALAR: return itv_set_ap_scalar(intern,itv,coeff->val.scalar); break; case AP_COEFF_INTERVAL: return itv_set_ap_interval(intern, itv, coeff->val.interval); break; default: abort(); } } bool ITVFUN(ap_interval_set_itv)(itv_internal_t* intern, ap_interval_t* a, itv_t b) { bool b1 = ap_scalar_set_bound(a->inf,b->inf); ap_scalar_neg(a->inf,a->inf); bool b2 = ap_scalar_set_bound(a->sup,b->sup); return b1 && b2; } bool ITVFUN(ap_coeff_set_itv)(itv_internal_t* intern, ap_coeff_t* a, itv_t b) { bool exact; if (itv_is_point(intern,b)){ exact = ap_scalar_set_bound(intern->ap_conversion_scalar, b->sup); if (exact){ ap_coeff_set_scalar(a, intern->ap_conversion_scalar); return true; } else { ap_coeff_reinit(a,AP_COEFF_INTERVAL, intern->ap_conversion_scalar->discr); ap_scalar_set(a->val.interval->sup, intern->ap_conversion_scalar); bound_neg(intern->ap_conversion_bound, b->inf); /* we now it is finite */ ap_scalar_set_bound(a->val.interval->inf, intern->ap_conversion_bound); return false; } } else { ap_coeff_reinit(a,AP_COEFF_INTERVAL,NUM_AP_SCALAR); return ap_interval_set_itv(intern,a->val.interval,b); } } bool ITVFUN(itv_array_set_ap_interval_array)(itv_internal_t* intern, itv_t** ptitv, ap_interval_t** array, size_t size) { bool exact, res; itv_t* titv; size_t i; titv = itv_array_alloc(size); res = true; for (i=0; i\n\ #include \"ap_coeff.h\"\n\ #include \"apron_caml.h\"\n\ ") import "scalar.idl"; /* For ap_interval_t, - the conversion from ML to C may use allocation, but it is automatically freed by Camlidl mechanisms - the conversion from C to ML duplicate the C allocated memory. Hence, the C type should be explicitly deallocated (if allocated from the underlying C function) */ struct ap_interval_t { [ref,mlname(mutable_inf)] ap_scalar_t* inf; [ref,mlname(mutable_sup)] ap_scalar_t* sup; }; typedef [ref]struct ap_interval_t* ap_interval_ptr; struct ap_interval_array_t { [size_is(size)]ap_interval_ptr* p; int size; }; quote(MLMLI,"(** APRON Intervals on scalars *)\n\n") quote(MLI,"\n\ val of_scalar : Scalar.t -> Scalar.t -> t\n\ (** Build an interval from a lower and an upper bound *)\n\ val of_infsup : Scalar.t -> Scalar.t -> t\n\ (** depreciated *)\n\ \n\ val of_mpq : Mpq.t -> Mpq.t -> t\n\ val of_mpqf : Mpqf.t -> Mpqf.t -> t\n\ val of_int : int -> int -> t\n\ val of_frac : int -> int -> int -> int -> t\n\ val of_float : float -> float -> t\n\ val of_mpfr : Mpfr.t -> Mpfr.t -> t\n\ (** Create an interval from resp. two\n\ - multi-precision rationals [Mpq.t] \n\ - multi-precision rationals [Mpqf.t] \n\ - integers \n\ - fractions [x/y] and [z/w]\n\ - machine floats\n\ - Mpfr floats\n\ *)\n\ \n\ val is_top : t -> bool\n\ (** Does the interval represent the universe ([[-oo,+oo]]) ? *)\n\ \n\ val is_bottom : t -> bool\n\ (** Does the interval contain no value ([[a,b]] with a>b) ? *)\n\ \n\ val is_leq : t -> t -> bool\n\ (** Inclusion test. [is_leq x y] returns [true] if [x] is included in [y] *)\n\ \n\ val cmp : t -> t -> int\n\ (** Non Total Comparison:\n\ 0: equality\n\ -1: i1 included in i2\n\ +1: i2 included in i1\n\ -2: i1.inf less than or equal to i2.inf\n\ +2: i1.inf greater than i2.inf\n\ *)\n\ val equal : t -> t -> bool\n\ (** Equality test *)\n\ val is_zero : t -> bool\n\ (** Is the interval equal to [0,0] ? *)\n\ val equal_int : t -> int -> bool\n\ (** Is the interval equal to [i,i] ? *)\n\ val neg : t -> t\n\ (** Negation *)\n\ val top : t\n\ val bottom : t\n\ (** Top and bottom intervals (using [DOUBLE] coefficients) *)\n\ \n\ val set_infsup : t -> Scalar.t -> Scalar.t -> unit\n\ (** Fill the interval with the given lower and upper bouunds *)\n\ \n\ val set_top : t -> unit\n\ val set_bottom : t -> unit\n\ (** Fill the interval with top (resp. bottom) value *)\n\ \n\ val print : Format.formatter -> t -> unit\n\ (** Print an interval, under the format [[inf,sup]] *)\n\ ") quote(ML,"\n\ let of_scalar inf sup = { inf = inf; sup = sup }\n\ let of_infsup = of_scalar\n\ let of_mpq x y = { \n\ inf = Scalar.of_mpq x;\n\ sup = Scalar.of_mpq y\n\ }\n\ let of_mpqf x y = {\n\ inf = Scalar.of_mpqf x;\n\ sup = Scalar.of_mpqf y\n\ }\n\ let of_int x y = {\n\ inf = Scalar.of_int x;\n\ sup = Scalar.of_int y\n\ }\n\ let of_frac x y z w = {\n\ inf = Scalar.of_frac x y;\n\ sup = Scalar.of_frac z w\n\ }\n\ let of_float x y = {\n\ inf = Scalar.of_float x;\n\ sup = Scalar.of_float y\n\ }\n\ let of_mpfr x y = {\n\ inf = Scalar.of_mpfr x;\n\ sup = Scalar.of_mpfr y\n\ }\n\ let is_top itv =\n\ Scalar.is_infty itv.inf < 0 && Scalar.is_infty itv.sup > 0\n\ let is_bottom itv =\n\ Scalar.cmp itv.inf itv.sup > 0\n\ let is_leq itv1 itv2 =\n\ Scalar.cmp itv1.inf itv2.inf >= 0 &&\n\ Scalar.cmp itv1.sup itv2.sup <= 0\n\ let cmp itv1 itv2 =\n\ let s1 = Scalar.cmp itv1.inf itv2.inf in\n\ let s2 = Scalar.cmp itv1.sup itv2.sup in\n\ if s1=0 && s2=0 then 0\n\ else if s1>=0 && s2<=0 then -1\n\ else if s1<=0 && s2>=0 then 1\n\ else if s1<=0 then -2\n\ else 2\n\ let equal itv1 itv2 =\n\ Scalar.equal itv1.inf itv2.inf &&\n\ Scalar.equal itv1.sup itv2.sup \n\ let is_zero itv =\n\ Scalar.sgn itv.inf=0 && Scalar.sgn itv.sup = 0\n\ let equal_int itv b = \n\ Scalar.equal_int itv.inf b && Scalar.equal_int itv.sup b\n\ let neg itv = \n\ { inf = Scalar.neg itv.sup; sup = Scalar.neg itv.inf }\n\ let top = { inf = Scalar.Float neg_infinity; sup = Scalar.Float infinity }\n\ let bottom = { inf = Scalar.Float infinity; sup = Scalar.Float neg_infinity }\n\ let set_infsup itv inf sup =\n\ itv.inf <- inf;\n\ itv.sup <- sup\n\ let set_top itv =\n\ itv.inf <- Scalar.Float neg_infinity;\n\ itv.sup <- Scalar.Float infinity\n\ let set_bottom itv =\n\ itv.inf <- Scalar.Float infinity;\n\ itv.sup <- Scalar.Float neg_infinity\n\ let print fmt itv =\n\ Format.fprintf fmt \"[@[%a;@ %a@]]\"\n\ Scalar.print itv.inf Scalar.print itv.sup\n\ ") apron-dist-0.9.10/apron/mlapronidl/parser.mli0000640014525101416610000001104111023235130021007 0ustar bjeannetpopart(* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) (** APRON Parsing of expressions *) (** {2 Introduction} This small module implements the parsing of expressions, constraints and generators. The allowed syntax is simple for linear expressions (no parenthesis) but supports interval expressions. The syntax is more flexible for tree expressions. {3 Syntax} [lincons ::= linexpr ('>' | '>=' | '=' | '!=' | '=' | '<=' | '<') linexpr | linexpr = linexpr 'mod' scalar] [gen ::= ('V:' | 'R:' | 'L:' | 'RM:' | 'LM:') linexpr] [linexpr ::= linexpr '+' linterm | linexpr '-' linterm | linterm] [linterm ::= coeff ['*'] identifier | coeff | ['-'] identifier] [tcons ::= texpr ('>' | '>=' | '=' | '!=' | '=' | '<=' | '<') texpr | texpr = texpr 'mod' scalar] [texpr ::= coeff | identifier | unop texpr | texpr binop texpr | '(' texpr ')'] [binop ::= ('+'|'-'|'*'|'/'|'%')['_'('i'|'f'|'d'|'l'|'q')][','('n'|'0'|'+oo'|'-oo')]] [unop ::= ('cast' | 'sqrt')['_'('i'|'f'|'d'|'l'|'q')][','('n'|'0'|'+oo'|'-oo')]] [coeff ::= scalar | ['-'] '['scalar ';' scalar ']'] [scalar ::= ['-'] (integer | rational | floating_point_number)] For tree expressions [texpr], by default the operations have an exact arithmetic semantics in the real numbers (even if involved variables are of integer). The type qualifiers modify this default semantics. Their meaning is as follows: - [i] integer semantics - [f] IEEE754 32 bits floating-point semantics - [d] IEEE754 64 bits floating-point semantics - [l] IEEE754 80 bits floating-point semantics - [q] IEEE754 129 bits floating-point semantics By default, the rounding mode is "any" (this applies only in non-real semantics), which allows to emulate all the following rounding modes: - [n] nearest - [0] towards zero - [+oo] towards infinity - [-oo] towards minus infinity - [?] any {3 Examples} [let (linexpr:Linexpr1.t) = Parser.linexpr1_of_string env "z+0.4x+2y"] [let (tab:Lincons1.earray) = Parser.lincons1_of_lstring env ["1/2x+2/3y=1";"[1;2]<=z+2w";"z+2w<=4";"0<=u";"u<=5"]] [let (generator:Generator1.t) = Parser.generator1_of_string env "R:x+2y"] [let (texpr:Texpr1.t) = Parser.texpr1_of_string env "a %_i,? b +_f,0 c"] {3 Remarks} There is the possibility to parse directly from a lexing buffer, or from a string (from which one can generate a buffer with the function [Lexing.from_string]. This module uses the underlying modules [Apron_lexer] and [Apron_parser]. *) (** {2 Interface} *) exception Error of string (** Raised by conversion functions *) val linexpr1_of_lexbuf : Environment.t -> Lexing.lexbuf -> Linexpr1.t val lincons1_of_lexbuf : Environment.t -> Lexing.lexbuf -> Lincons1.t val generator1_of_lexbuf : Environment.t -> Lexing.lexbuf -> Generator1.t (** Conversion from lexing buffers to resp. linear expressions, linear constraints and generators, defined on the given environment. *) val texpr1expr_of_lexbuf : Lexing.lexbuf -> Texpr1.expr val texpr1_of_lexbuf : Environment.t -> Lexing.lexbuf -> Texpr1.t val tcons1_of_lexbuf : Environment.t -> Lexing.lexbuf -> Tcons1.t (** Conversion from lexing buffers to resp. tree expressions and constraints, defined on the given environment. *) val linexpr1_of_string : Environment.t -> string -> Linexpr1.t val lincons1_of_string : Environment.t -> string -> Lincons1.t val generator1_of_string : Environment.t -> string -> Generator1.t (** Conversion from strings to resp. linear expressions, linear constraints and generators, defined on the given environment. *) val texpr1expr_of_string : string -> Texpr1.expr val texpr1_of_string : Environment.t -> string -> Texpr1.t val tcons1_of_string : Environment.t -> string -> Tcons1.t (** Conversion from lexing buffers to resp. tree expressions and constraints, defined on the given environment. *) val lincons1_of_lstring : Environment.t -> string list -> Lincons1.earray val generator1_of_lstring : Environment.t -> string list -> Generator1.earray (** Conversion from lists of strings to array of resp. linear constraints and generators, defined on the given environment. *) val tcons1_of_lstring : Environment.t -> string list -> Tcons1.earray (** Conversion from lists of strings to array of tree constraints. *) val of_lstring : 'a Manager.t -> Environment.t -> string list -> 'a Abstract1.t (** Abstraction of lists of strings representing constraints to abstract values, on the abstract domain defined by the given manager. *) apron-dist-0.9.10/apron/mlapronidl/lincons1_caml.c0000640014525101416610000003122511252216516021717 0ustar bjeannetpopart/* File generated from lincons1.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include #include "ap_lincons1.h" #include "apron_caml.h" extern void camlidl_apron_scalar_ml2c(value, ap_scalar_t *); #define camlidl_ml2c_scalar_ap_scalar_t(v,c,ctx) camlidl_apron_scalar_ml2c(v,c) extern value camlidl_apron_scalar_c2ml(ap_scalar_t *); #define camlidl_c2ml_scalar_ap_scalar_t(c,ctx) camlidl_apron_scalar_c2ml(c) extern void camlidl_ml2c_scalar_ap_scalar_ptr(value, ap_scalar_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_ap_scalar_ptr(ap_scalar_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_scalar_struct_ap_scalar_array_t(value, struct ap_scalar_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_struct_ap_scalar_array_t(struct ap_scalar_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_t(value, struct ap_interval_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_t(struct ap_interval_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_ap_interval_ptr(value, ap_interval_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_ap_interval_ptr(ap_interval_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_array_t(value, struct ap_interval_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_array_t(struct ap_interval_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_coeff_struct_ap_coeff_t(value, struct ap_coeff_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_coeff_struct_ap_coeff_t(struct ap_coeff_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_ap_dim_t(value, ap_dim_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_ap_dim_t(ap_dim_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimchange_t(value, struct ap_dimchange_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange_t(struct ap_dimchange_t *, camlidl_ctx _ctx); extern void camlidl_apron_dimchange_ml2c(value, ap_dimchange_t *); #define camlidl_ml2c_dim_ap_dimchange_t(v,c,ctx) camlidl_apron_dimchange_ml2c(v,c) extern value camlidl_apron_dimchange_c2ml(ap_dimchange_t *); #define camlidl_c2ml_dim_ap_dimchange_t(c,ctx) camlidl_apron_dimchange_c2ml(c) extern void camlidl_ml2c_dim_struct_ap_dimchange2_t(value, struct ap_dimchange2_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange2_t(struct ap_dimchange2_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimperm_t(value, struct ap_dimperm_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimperm_t(struct ap_dimperm_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimension_t(value, struct ap_dimension_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimension_t(struct ap_dimension_t *, camlidl_ctx _ctx); extern void camlidl_apron_linexpr0_ptr_ml2c(value, ap_linexpr0_ptr *); #define camlidl_ml2c_linexpr0_ap_linexpr0_ptr(v,c,ctx) camlidl_apron_linexpr0_ptr_ml2c(v,c) extern value camlidl_apron_linexpr0_ptr_c2ml(ap_linexpr0_ptr *); #define camlidl_c2ml_linexpr0_ap_linexpr0_ptr(c,ctx) camlidl_apron_linexpr0_ptr_c2ml(c) extern void camlidl_apron_lincons0_ml2c(value, ap_lincons0_t *, camlidl_ctx); #define camlidl_ml2c_lincons0_ap_lincons0_t(v,c,ctx) camlidl_apron_lincons0_ml2c(v,c,ctx) extern value camlidl_apron_lincons0_c2ml(ap_lincons0_t *); #define camlidl_c2ml_lincons0_ap_lincons0_t(c,ctx) camlidl_apron_lincons0_c2ml(c) extern void camlidl_ml2c_lincons0_struct_ap_lincons0_array_t(value, struct ap_lincons0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_lincons0_struct_ap_lincons0_array_t(struct ap_lincons0_array_t *, camlidl_ctx _ctx); extern void camlidl_apron_var_ptr_ml2c(value, ap_var_t *); #define camlidl_ml2c_var_ap_var_t(v,c,ctx) camlidl_apron_var_ptr_ml2c(v,c) extern value camlidl_apron_var_ptr_c2ml(ap_var_t *); #define camlidl_c2ml_var_ap_var_t(c,ctx) camlidl_apron_var_ptr_c2ml(c) extern int camlidl_ml2c_environment_enum_typvar(value); extern value camlidl_c2ml_environment_enum_typvar(int); extern int camlidl_transl_table_environment_enum_typvar[]; extern void camlidl_apron_environment_ptr_ml2c(value, ap_environment_ptr *); #define camlidl_ml2c_environment_ap_environment_ptr(v,c,ctx) camlidl_apron_environment_ptr_ml2c(v,c) extern value camlidl_apron_environment_ptr_c2ml(ap_environment_ptr *); #define camlidl_c2ml_environment_ap_environment_ptr(c,ctx) camlidl_apron_environment_ptr_c2ml(c) extern void camlidl_ml2c_linexpr1_struct_ap_linexpr1_t(value, struct ap_linexpr1_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_linexpr1_struct_ap_linexpr1_t(struct ap_linexpr1_t *, camlidl_ctx _ctx); void camlidl_ml2c_lincons1_struct_ap_lincons1_t(value _v1, struct ap_lincons1_t * _c2, camlidl_ctx _ctx) { value _v3; value _v4; _v3 = Field(_v1, 0); camlidl_ml2c_lincons0_ap_lincons0_t(_v3, &(*_c2).lincons0, _ctx); _v4 = Field(_v1, 1); camlidl_ml2c_environment_ap_environment_ptr(_v4, &(*_c2).env, _ctx); } value camlidl_c2ml_lincons1_struct_ap_lincons1_t(struct ap_lincons1_t * _c1, camlidl_ctx _ctx) { value _v2; value _v3[2]; _v3[0] = _v3[1] = 0; Begin_roots_block(_v3, 2) _v3[0] = camlidl_c2ml_lincons0_ap_lincons0_t(&(*_c1).lincons0, _ctx); _v3[1] = camlidl_c2ml_environment_ap_environment_ptr(&(*_c1).env, _ctx); _v2 = camlidl_alloc_small(2, 0); Field(_v2, 0) = _v3[0]; Field(_v2, 1) = _v3[1]; End_roots() return _v2; } void camlidl_ml2c_lincons1_struct_ap_lincons1_array_t(value _v1, struct ap_lincons1_array_t * _c2, camlidl_ctx _ctx) { value _v3; value _v4; _v3 = Field(_v1, 0); camlidl_ml2c_lincons0_struct_ap_lincons0_array_t(_v3, &(*_c2).lincons0_array, _ctx); _v4 = Field(_v1, 1); camlidl_ml2c_environment_ap_environment_ptr(_v4, &(*_c2).env, _ctx); } value camlidl_c2ml_lincons1_struct_ap_lincons1_array_t(struct ap_lincons1_array_t * _c1, camlidl_ctx _ctx) { value _v2; value _v3[2]; _v3[0] = _v3[1] = 0; Begin_roots_block(_v3, 2) _v3[0] = camlidl_c2ml_lincons0_struct_ap_lincons0_array_t(&(*_c1).lincons0_array, _ctx); _v3[1] = camlidl_c2ml_environment_ap_environment_ptr(&(*_c1).env, _ctx); _v2 = camlidl_alloc_small(2, 0); Field(_v2, 0) = _v3[0]; Field(_v2, 1) = _v3[1]; End_roots() return _v2; } value camlidl_lincons1_ap_lincons1_get_coeff( value _v_a, value _v_var) { struct ap_lincons1_t *a; /*in*/ ap_var_t var; /*in*/ struct ap_coeff_t _res; struct ap_lincons1_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; a = &_c1; camlidl_ml2c_lincons1_struct_ap_lincons1_t(_v_a, &_c1, _ctx); camlidl_ml2c_var_ap_var_t(_v_var, &var, _ctx); /* begin user-supplied calling sequence */ { bool b; ap_coeff_init(&_res,AP_COEFF_SCALAR); b = ap_lincons1_get_coeff(&_res,a,var); if (b){ char str[160]; char* name; ap_coeff_clear(&_res); name = ap_var_operations->to_string(var); snprintf(str,159,"Lincons1.get_coeff: unknown variable %s in the environment",name); free(name); caml_failwith(str); } } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_coeff_struct_ap_coeff_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ ap_coeff_clear(&_res); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_lincons1_ap_lincons1_set_coeff( value _v_a, value _v_var, value _v_coeff) { struct ap_lincons1_t *a; /*in*/ ap_var_t var; /*in*/ struct ap_coeff_t *coeff; /*in*/ struct ap_lincons1_t _c1; struct ap_coeff_t _c2; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; a = &_c1; camlidl_ml2c_lincons1_struct_ap_lincons1_t(_v_a, &_c1, _ctx); camlidl_ml2c_var_ap_var_t(_v_var, &var, _ctx); coeff = &_c2; camlidl_ml2c_coeff_struct_ap_coeff_t(_v_coeff, &_c2, _ctx); /* begin user-supplied calling sequence */ { bool b; b = ap_lincons1_set_coeff(a,var,coeff); if (b){ char str[160]; char* name; name = ap_var_operations->to_string(var); snprintf(str,159,"Lincons1.set_coeff: unknown variable %s in the environment",name); free(name); caml_failwith(str); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_lincons1_ap_lincons1_make_unsat( value _v_env) { ap_environment_ptr env; /*in*/ struct ap_lincons1_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); _res = ap_lincons1_make_unsat(env); _vres = camlidl_c2ml_lincons1_struct_ap_lincons1_t(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_lincons1_ap_lincons1_is_unsat( value _v_cons) { struct ap_lincons1_t *cons; /*in*/ int _res; struct ap_lincons1_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; cons = &_c1; camlidl_ml2c_lincons1_struct_ap_lincons1_t(_v_cons, &_c1, _ctx); _res = ap_lincons1_is_unsat(cons); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_lincons1_ap_lincons1_extend_environment( value _v_lincons, value _v_env) { struct ap_lincons1_t lincons; /*in*/ ap_environment_ptr env; /*in*/ struct ap_lincons1_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_lincons1_struct_ap_lincons1_t(_v_lincons, &lincons, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); /* begin user-supplied calling sequence */ { bool b; b = ap_lincons1_extend_environment(&_res,&lincons,env); if (b) caml_failwith("Lincons1.extend_environment: new environment is not a superenvironment"); } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_lincons1_struct_ap_lincons1_t(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_lincons1_ap_lincons1_extend_environment_with( value _v_lincons, value _v_env) { struct ap_lincons1_t lincons; /*in*/ ap_environment_ptr env; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_lincons1_struct_ap_lincons1_t(_v_lincons, &lincons, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); /* begin user-supplied calling sequence */ { if (lincons.env!=env){ bool b; ap_environment_copy(lincons.env); /* to protect it */ b = ap_lincons1_extend_environment_with(&lincons,env); if (b){ ap_environment_free(lincons.env); caml_failwith("Lincons1.extend_environment_with: new environment is not a superenvironment"); } Store_field(_v_lincons,1,_v_env); ap_environment_free(env); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_lincons1_ap_lincons1_array_extend_environment( value _v_array, value _v_env) { struct ap_lincons1_array_t array; /*in*/ ap_environment_ptr env; /*in*/ struct ap_lincons1_array_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_lincons1_struct_ap_lincons1_array_t(_v_array, &array, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); /* begin user-supplied calling sequence */ { bool b; b = ap_lincons1_array_extend_environment(&_res,&array,env); if (b) caml_failwith("Lincons1.array_extend_environment: new environment is not a superenvironment"); } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_lincons1_struct_ap_lincons1_array_t(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_lincons1_ap_lincons1_array_extend_environment_with( value _v_array, value _v_env) { struct ap_lincons1_array_t array; /*in*/ ap_environment_ptr env; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_lincons1_struct_ap_lincons1_array_t(_v_array, &array, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); /* begin user-supplied calling sequence */ { if (array.env!=env){ bool b; ap_environment_copy(array.env); /* to protect it */ b = ap_lincons1_array_extend_environment_with(&array,env); if (b){ ap_environment_free(array.env); caml_failwith("Lincons1.array_extend_environment_with: new environment is not a superenvironment"); } Store_field(_v_array,1,_v_env); ap_environment_free(env); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } apron-dist-0.9.10/apron/mlapronidl/generator1.idl0000640014525101416610000002235510654126013021573 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \n\ #include \"ap_generator1.h\"\n\ #include \"apron_caml.h\"\n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; import "linexpr0.idl"; import "generator0.idl"; import "environment.idl"; import "linexpr1.idl"; struct ap_generator1_t { [mlname(mutable_generator0)] struct ap_generator0_t generator0; [mlname(mutable_env)]ap_environment_ptr env; }; struct ap_generator1_array_t { [mlname(mutable_generator0_array)] struct ap_generator0_array_t generator0_array; [mlname(mutable_array_env)] ap_environment_ptr env; }; quote(MLMLI,"(** APRON Generators and array of generators of level 1 *)") quote(MLMLI,"\n\ type typ = Generator0.typ = \n\ | LINE\n\ | RAY\n\ | VERTEX\n\ | LINEMOD\n\ | RAYMOD\n\ ") quote(MLI,"\n\ (** Make a generator. Modifying later the linear expression ({e not\n\ advisable}) modifies correspondingly the generator and conversely,\n\ except for changes of environements *)\n\ val make: Linexpr1.t -> Generator0.typ -> t\n\ \n\ (** Copy (deep copy) *)\n\ val copy: t -> t\n\ \n\ (** Print the generator *)\n\ val print : Format.formatter -> t -> unit\n\ \n\ (** Get the generator type *)\n\ val get_typ: t -> Generator0.typ\n\ \n\ (** Iter the function on the pair coefficient/variable of the underlying linear\n\ expression *)\n\ val iter: (Coeff.t -> Var.t -> unit) -> t -> unit\n\ \n\ (** Set the generator type *)\n\ val set_typ: t -> Generator0.typ -> unit\n\ \n\ (** Set simultaneously a number of coefficients.\n\ \n\ [set_list expr [(c1,\"x\"); (c2,\"y\")]] assigns coefficients [c1] \n\ to variable [\"x\"] and coefficient [c2] to variable [\"y\"]. *)\n\ val set_list : t -> (Coeff.t * Var.t) list -> unit\n\ \n\ (** Set simultaneously a number of coefficients, as [set_list]. *)\n\ val set_array : t -> (Coeff.t * Var.t) array -> unit\n\ \n\ ") quote(MLI,"(** Get the coefficient of the variable in the underlying linear expression *)") struct ap_coeff_t ap_generator1_get_coeff([ref]struct ap_generator1_t* a, ap_var_t var) quote(call, "\n\ {\n\ bool b;\n\ ap_coeff_init(&_res,AP_COEFF_SCALAR);\n\ b = ap_generator1_get_coeff(&_res,a,var);\n\ if (b){\n\ char str[160];\n\ char* name;\n\ ap_coeff_clear(&_res);\n\ name = ap_var_operations->to_string(var);\n\ snprintf(str,159,\"Generator1.get_coeff: unknown variable %s in the environment\",name);\n\ free(name);\n\ caml_failwith(str);\n\ }\n\ }\n\ ") quote(dealloc,"ap_coeff_clear(&_res);"); quote(MLI,"(** Set the coefficient of the variable in the underlying linear expression *)") void ap_generator1_set_coeff([ref]struct ap_generator1_t* a, ap_var_t var, [ref]struct ap_coeff_t* coeff) quote(call, "\n\ {\n\ bool b;\n\ b = ap_generator1_set_coeff(a,var,coeff);\n\ if (b){\n\ char str[160];\n\ char* name;\n\ name = ap_var_operations->to_string(var);\n\ snprintf(str,159,\"Generator1.set_coeff: unknown variable %s in the environment\",name);\n\ free(name);\n\ caml_failwith(str);\n\ }\n\ }"); quote(MLI,"(** Change the environement of the generator for a super-environement. Raise [Failure] if it is not the case *)") struct ap_generator1_t ap_generator1_extend_environment(const struct ap_generator1_t generator, ap_environment_ptr env) quote(call,"\n\ {\n\ bool b;\n\ b = ap_generator1_extend_environment(&_res,&generator,env);\n\ if (b) caml_failwith(\"Generator1.extend_environment: new environment is not a superenvironment\");\n\ }") ; quote(MLI,"(** Side-effect version of the previous function *)") void ap_generator1_extend_environment_with(struct ap_generator1_t generator, ap_environment_ptr env) quote(call,"\n\ {\n\ if (generator.env!=env){ \n\ bool b;\n\ ap_environment_copy(generator.env); /* to protect it */ \n\ b = ap_generator1_extend_environment_with(&generator,env);\n\ if (b){ \n\ ap_environment_free(generator.env); \n\ caml_failwith(\"Generator1.extend_environment_with: new environment is not a superenvironment\");\n\ }\n\ Store_field(_v_generator,1,_v_env);\n\ ap_environment_free(env);\n\ }\n\ }") ; quote(ML,"\n\ let make linexpr1 gentyp = {\n\ generator0 = {\n\ Generator0.linexpr0 = linexpr1.Linexpr1.linexpr0;\n\ Generator0.typ = gentyp;\n\ };\n\ env = linexpr1.Linexpr1.env;\n\ }\n\ let copy gen = {\n\ generator0 = Generator0.copy gen.generator0;\n\ env = gen.env;\n\ }\n\ let print fmt gen = \n\ Generator0.print\n\ (fun dim -> Var.to_string (Environment.var_of_dim gen.env dim)) fmt gen.generator0;\n \ ()\n\ let get_typ gen = gen.generator0.Generator0.typ\n\ let set_typ gen typ = gen.generator0.Generator0.typ <- typ\n\ let get_generator0 gen = gen.generator0\n\ let get_env gen = gen.env\n\ let set_list expr list = \n\ List.iter\n\ (fun (coeff,var) -> set_coeff expr var coeff )\n\ list;\n\ ()\n\ let set_array expr tab = \n\ Array.iter\n\ (fun (coeff,var) -> set_coeff expr var coeff )\n\ tab;\n\ ()\n\ \n\ let iter f gen =\n\ Linexpr0.iter\n\ (begin fun coeff dim ->\n\ f coeff (Environment.var_of_dim gen.env dim)\n\ end)\n\ gen.generator0.Generator0.linexpr0\n\ let get_linexpr1 gen = {\n\ Linexpr1.linexpr0 = gen.generator0.Generator0.linexpr0;\n\ Linexpr1.env = gen.env;\n\ }") quote(MLMLI,"(* ====================================================================== *)") quote(MLMLI,"(** {2 Type earray} *)") quote(MLMLI,"(* ====================================================================== *)") quote(MLI,"\n\ (** Make an array of generators with the given size and defined on the\n\ given environement. The elements are initialized with the line 0. *)\n\ val array_make : Environment.t -> int -> earray\n\ \n\ (** Print an array of generators *)\n\ val array_print :\n\ ?first:(unit, Format.formatter, unit) format ->\n\ ?sep:(unit, Format.formatter, unit) format ->\n\ ?last:(unit, Format.formatter, unit) format ->\n\ Format.formatter -> earray -> unit\n\ \n\ (** Get the size of the array *)\n\ val array_length : earray -> int\n\ \n\ (** Get the element of the given index (which is not a copy) *)\n\ val array_get : earray -> int -> t\n\ \n\ (** Set the element of the given index (without any copy). The array and the\n\ generator should be defined on the same environement; otherwise a [Failure]\n\ exception is raised.*)\n\ val array_set : earray -> int -> t -> unit\n\ ") quote(MLI,"(** Change the environement of the array of generators for a super-environement. Raise [Failure] if it is not the case*)") struct ap_generator1_array_t ap_generator1_array_extend_environment(const struct ap_generator1_array_t array, ap_environment_ptr env) quote(call,"\n\ {\n\ bool b;\n\ b = ap_generator1_array_extend_environment(&_res,&array,env);\n\ if (b) caml_failwith(\"Generator1.array_extend_environment: new environment is not a superenvironment\");\n\ }") ; quote(MLI,"(** Side-effect version of the previous function *)") void ap_generator1_array_extend_environment_with(struct ap_generator1_array_t array, ap_environment_ptr env) quote(call,"\n\ {\n\ if (array.env!=env){ \n\ bool b;\n\ ap_environment_copy(array.env); /* to protect it */ \n\ b = ap_generator1_array_extend_environment_with(&array,env);\n\ if (b){ \n\ ap_environment_free(array.env); \n\ caml_failwith(\"Generator1.array_extend_environment_with: new environment is not a superenvironment\");\n\ }\n\ Store_field(_v_array,1,_v_env);\n\ ap_environment_free(env);\n\ }\n\ }") ; quote(MLI,"\n\ (** Get the environement of the generator *)\n\ val get_env: t -> Environment.t\n\ \n\ (** Get the underlying linear expression. Modifying the linear expression ({e\n\ not advisable}) modifies correspondingly the generator and\n\ conversely, except for changes of environements *)\n\ val get_linexpr1: t -> Linexpr1.t\n\ \n\ (** Get the underlying generator of level 0. Modifying the generator\n\ of level 0 ({e not advisable}) modifies correspondingly the generator\n\ and conversely, except for changes of environements*)\n\ val get_generator0: t -> Generator0.t\n\ ") quote(ML,"\n\ let array_make env size =\n\ let gen = Generator0.make (Linexpr0.make None) Generator0.LINE in\n\ {\n\ generator0_array = Array.make size gen;\n\ array_env = env\n\ }\n\ let array_print\n\ ?(first=(\"[|@[\":(unit,Format.formatter,unit) format))\n\ ?(sep = (\";@ \":(unit,Format.formatter,unit) format))\n\ ?(last = (\"@]|]\":(unit,Format.formatter,unit) format))\n\ fmt array \n\ = \n\ Abstract0.print_array ~first ~sep ~last\n\ (Generator0.print\n\ (fun dim -> Var.to_string (Environment.var_of_dim array.array_env dim)))\n \ fmt array.generator0_array;\n\ ()\n\ let array_length array = Array.length (array.generator0_array)\n\ let array_get array index =\n\ let gen0 = array.generator0_array.(index) in\n\ { generator0 = gen0; env = array.array_env; }\n\ let array_set array index gen1 =\n\ if not (Environment.equal array.array_env gen1.env) then\n\ failwith \"Expr1.array_set: environments are not the same\"\n\ else\n\ array.generator0_array.(index) <- gen1.generator0;\n\ ") apron-dist-0.9.10/apron/mlapronidl/dim.ml0000640014525101416610000000155711252216515020140 0ustar bjeannetpopart(* File generated from dim.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = int and change = { dim : int array; intdim : int; realdim : int; } and change2 = { add: change option; remove: change option; } and perm = int array and dimension = { intd: int; reald: int; } (** APRON Dimensions and related types *) let change_add_invert change = let dim = change.dim in for i=0 to (Array.length dim)-1 do dim.(i) <- dim.(i) + i; done let perm_compose perm1 perm2 = let length = Array.length perm1 in assert(length==(Array.length perm2)); Array.init length (fun i -> perm2.(perm1.(i))) let perm_invert perm = let length = Array.length perm in let res = Array.make length 0 in for i=0 to length-1 do res.(perm.(i)) <- i; done; res apron-dist-0.9.10/apron/mlapronidl/environment.mli0000640014525101416610000001136011252216516022076 0ustar bjeannetpopart(* File generated from environment.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type typvar = | INT | REAL and t (** APRON Environments binding dimensions to names *) (** Making an environment from a set of integer and real variables. Raise [Failure] in case of name conflict. *) external make : Var.t array -> Var.t array -> t = "camlidl_environment_ap_environment_make" (** Adding to an environment a set of integer and real variables. Raise [Failure] in case of name conflict. *) external add : t -> Var.t array -> Var.t array -> t = "camlidl_environment_ap_environment_add" (** Remove from an environment a set of variables. Raise [Failure] in case of non-existing variables. *) external remove : t -> Var.t array -> t = "camlidl_environment_ap_environment_remove" (** Renaming in an environment a set of variables. Raise [Failure] in case of interferences with the variables that are not renamed. *) external rename : t -> Var.t array -> Var.t array -> t = "camlidl_environment_ap_environment_rename" (** Similar to previous function, but returns also the permutation on dimensions induced by the renaming. *) external rename_perm : t -> Var.t array -> Var.t array -> t * Dim.perm = "camlidl_environment_ap_environment_rename_perm" (** Compute the least common environment of 2 environment, that is, the environment composed of all the variables of the 2 environments. Raise [Failure] if the same variable has different types in the 2 environment.*) external lce : t -> t -> t = "camlidl_environment_ap_environment_lce" (** Similar to the previous function, but returns also the transformations required to convert from [e1] (resp. [e2]) to the lce. If [None] is returned, this means that [e1] (resp. [e2]) is identic to the lce.*) external lce_change : t -> t -> t * Dim.change option * Dim.change option = "camlidl_environment_ap_environment_lce_change" (** [dimchange e1 e2] computes the transformation for converting from an environment [e1] to a superenvironment [e2]. Raises [Failure] if [e2] is not a superenvironment.*) external dimchange : t -> t -> Dim.change = "camlidl_environment_ap_environment_dimchange" (** [dimchange2 e1 e2] computes the transformation for converting from an environment [e1] to a (compatible) environment [e2], by first adding (some) variables of [e2] and then removing (some) variables of [e1]. Raises [Failure] if the two environments are incompatible. *) external dimchange2 : t -> t -> Dim.change2 = "camlidl_environment_ap_environment_dimchange2" (** Test equality if two environments *) external equal : t -> t -> bool = "camlidl_environment_ap_environment_equal" (** Compare two environment. [compare env1 env2] return [-2] if the environements are not compatible (a variable has different types in the 2 environements), [-1] if [env1] is a subset of env2, [0] if equality, [+1] if env1 is a superset of env2, and [+2] otherwise (the lce exists and is a strict superset of both) *) external compare : t -> t -> int = "camlidl_environment_ap_environment_compare" (** Hashing function for environments *) external hash : t -> int = "camlidl_environment_ap_environment_hash" (** Return the dimension of the environment *) external dimension : t -> Dim.dimension = "camlidl_environment_ap_environment_dimension" (** Return the size of the environment *) external size : t -> int = "camlidl_environment_ap_environment_size" (** Return true if the variable is present in the environment. *) external mem_var : t -> Var.t -> bool = "camlidl_environment_ap_environment_mem_var" (** Return the type of variables in the environment. If the variable does not belong to the environment, raise a [Failure] exception. *) external typ_of_var : t -> Var.t -> typvar = "camlidl_environment_ap_environment_typ_of_var" (** Return the (lexicographically ordered) sets of integer and real variables in the environment *) external vars : t -> Var.t array * Var.t array = "camlidl_environment_ap_environment_vars" (** Return the variable corresponding to the given dimension in the environment. Raise [Failure] is the dimension is out of the range of the environment (greater than or equal to [dim env]) *) external var_of_dim : t -> Dim.t -> Var.t = "camlidl_environment_ap_environment_var_of_dim" (** Return the dimension associated to the given variable in the environment. Raise [Failure] if the variable does not belong to the environment. *) external dim_of_var : t -> Var.t -> Dim.t = "camlidl_environment_ap_environment_dim_of_var" (** Printing *) val print : ?first:(unit, Format.formatter, unit) format -> ?sep:(unit, Format.formatter, unit) format -> ?last:(unit, Format.formatter, unit) format -> Format.formatter -> t -> unit apron-dist-0.9.10/apron/mlapronidl/generator1.ml0000640014525101416610000000624011252216516021431 0ustar bjeannetpopart(* File generated from generator1.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = { mutable generator0: Generator0.t; mutable env: Environment.t; } and earray = { mutable generator0_array: Generator0.t array; mutable array_env: Environment.t; } (** APRON Generators and array of generators of level 1 *) type typ = Generator0.typ = | LINE | RAY | VERTEX | LINEMOD | RAYMOD external get_coeff : t -> Var.t -> Coeff.t = "camlidl_generator1_ap_generator1_get_coeff" external set_coeff : t -> Var.t -> Coeff.t -> unit = "camlidl_generator1_ap_generator1_set_coeff" external extend_environment : t -> Environment.t -> t = "camlidl_generator1_ap_generator1_extend_environment" external extend_environment_with : t -> Environment.t -> unit = "camlidl_generator1_ap_generator1_extend_environment_with" let make linexpr1 typ = { generator0 = { Generator0.linexpr0 = linexpr1.Linexpr1.linexpr0; Generator0.typ = typ; }; env = linexpr1.Linexpr1.env; } let copy gen = { generator0 = Generator0.copy gen.generator0; env = gen.env; } let print fmt gen = Generator0.print (fun dim -> Var.to_string (Environment.var_of_dim gen.env dim)) fmt gen.generator0; () let get_typ gen = gen.generator0.Generator0.typ let set_typ gen typ = gen.generator0.Generator0.typ <- typ let get_generator0 gen = gen.generator0 let get_env gen = gen.env let set_list expr list = List.iter (fun (coeff,var) -> set_coeff expr var coeff ) list; () let set_array expr tab = Array.iter (fun (coeff,var) -> set_coeff expr var coeff ) tab; () let iter f gen = Linexpr0.iter (begin fun coeff dim -> f coeff (Environment.var_of_dim gen.env dim) end) gen.generator0.Generator0.linexpr0 let get_linexpr1 gen = { Linexpr1.linexpr0 = gen.generator0.Generator0.linexpr0; Linexpr1.env = gen.env; } (* ====================================================================== *) (** {2 Type earray} *) (* ====================================================================== *) external array_extend_environment : earray -> Environment.t -> earray = "camlidl_generator1_ap_generator1_array_extend_environment" external array_extend_environment_with : earray -> Environment.t -> unit = "camlidl_generator1_ap_generator1_array_extend_environment_with" let array_make env size = let gen = Generator0.make (Linexpr0.make None) Generator0.LINE in { generator0_array = Array.make size gen; array_env = env } let array_print ?(first=("[|@[":(unit,Format.formatter,unit) format)) ?(sep = (";@ ":(unit,Format.formatter,unit) format)) ?(last = ("@]|]":(unit,Format.formatter,unit) format)) fmt array = Abstract0.print_array ~first ~sep ~last (Generator0.print (fun dim -> Var.to_string (Environment.var_of_dim array.array_env dim))) fmt array.generator0_array; () let array_length array = Array.length (array.generator0_array) let array_get array index = let gen0 = array.generator0_array.(index) in { generator0 = gen0; env = array.array_env; } let array_set array index gen1 = if not (Environment.equal array.array_env gen1.env) then failwith "Expr1.array_set: environments are not the same" else array.generator0_array.(index) <- gen1.generator0; apron-dist-0.9.10/apron/mlapronidl/linexpr0_caml.c0000640014525101416610000002224011252216515021726 0ustar bjeannetpopart/* File generated from linexpr0.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include #include "ap_linexpr0.h" #include "apron_caml.h" extern void camlidl_apron_scalar_ml2c(value, ap_scalar_t *); #define camlidl_ml2c_scalar_ap_scalar_t(v,c,ctx) camlidl_apron_scalar_ml2c(v,c) extern value camlidl_apron_scalar_c2ml(ap_scalar_t *); #define camlidl_c2ml_scalar_ap_scalar_t(c,ctx) camlidl_apron_scalar_c2ml(c) extern void camlidl_ml2c_scalar_ap_scalar_ptr(value, ap_scalar_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_ap_scalar_ptr(ap_scalar_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_scalar_struct_ap_scalar_array_t(value, struct ap_scalar_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_struct_ap_scalar_array_t(struct ap_scalar_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_t(value, struct ap_interval_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_t(struct ap_interval_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_ap_interval_ptr(value, ap_interval_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_ap_interval_ptr(ap_interval_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_array_t(value, struct ap_interval_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_array_t(struct ap_interval_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_coeff_struct_ap_coeff_t(value, struct ap_coeff_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_coeff_struct_ap_coeff_t(struct ap_coeff_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_ap_dim_t(value, ap_dim_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_ap_dim_t(ap_dim_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimchange_t(value, struct ap_dimchange_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange_t(struct ap_dimchange_t *, camlidl_ctx _ctx); extern void camlidl_apron_dimchange_ml2c(value, ap_dimchange_t *); #define camlidl_ml2c_dim_ap_dimchange_t(v,c,ctx) camlidl_apron_dimchange_ml2c(v,c) extern value camlidl_apron_dimchange_c2ml(ap_dimchange_t *); #define camlidl_c2ml_dim_ap_dimchange_t(c,ctx) camlidl_apron_dimchange_c2ml(c) extern void camlidl_ml2c_dim_struct_ap_dimchange2_t(value, struct ap_dimchange2_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange2_t(struct ap_dimchange2_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimperm_t(value, struct ap_dimperm_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimperm_t(struct ap_dimperm_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimension_t(value, struct ap_dimension_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimension_t(struct ap_dimension_t *, camlidl_ctx _ctx); #define camlidl_ml2c_linexpr0_ap_linexpr0_ptr(v,c,ctx) camlidl_apron_linexpr0_ptr_ml2c(v,c) #define camlidl_c2ml_linexpr0_ap_linexpr0_ptr(c,ctx) camlidl_apron_linexpr0_ptr_c2ml(c) value camlidl_linexpr0_ap_linexpr0_make( value _v_size) { int *size; /*in*/ ap_linexpr0_ptr _res; value _v1; int _c2; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; if (_v_size == Val_int(0)) { size = NULL; } else { _v1 = Field(_v_size, 0); size = &_c2; _c2 = Int_val(_v1); } /* begin user-supplied calling sequence */ if (size && *size<0) caml_failwith("Linexpr0.make: negative optional size"); if (size){ _res = ap_linexpr0_alloc(AP_LINEXPR_DENSE, *size); } else { _res = ap_linexpr0_alloc(AP_LINEXPR_SPARSE, 0); } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_linexpr0_ap_linexpr0_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_linexpr0_ap_linexpr0_minimize( value _v_a) { ap_linexpr0_ptr a; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_linexpr0_ap_linexpr0_ptr(_v_a, &a, _ctx); ap_linexpr0_minimize(a); camlidl_free(_ctx); return Val_unit; } value camlidl_linexpr0_ap_linexpr0_copy( value _v_a) { ap_linexpr0_ptr a; /*in*/ ap_linexpr0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_linexpr0_ap_linexpr0_ptr(_v_a, &a, _ctx); _res = ap_linexpr0_copy(a); _vres = camlidl_c2ml_linexpr0_ap_linexpr0_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_linexpr0_ap_linexpr0_compare( value _v_a, value _v_b) { ap_linexpr0_ptr a; /*in*/ ap_linexpr0_ptr b; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_linexpr0_ap_linexpr0_ptr(_v_a, &a, _ctx); camlidl_ml2c_linexpr0_ap_linexpr0_ptr(_v_b, &b, _ctx); _res = ap_linexpr0_compare(a, b); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_linexpr0_ap_linexpr0_hash( value _v_a) { ap_linexpr0_ptr a; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_linexpr0_ap_linexpr0_ptr(_v_a, &a, _ctx); _res = ap_linexpr0_hash(a); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_linexpr0_ap_linexpr0_get_size( value _v_a) { ap_linexpr0_ptr a; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_linexpr0_ap_linexpr0_ptr(_v_a, &a, _ctx); /* begin user-supplied calling sequence */ _res = a->size; /* end user-supplied calling sequence */ _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_linexpr0_ap_linexpr0_get_cst( value _v_a) { ap_linexpr0_ptr a; /*in*/ struct ap_coeff_t *_res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_linexpr0_ap_linexpr0_ptr(_v_a, &a, _ctx); /* begin user-supplied calling sequence */ _res = &a->cst; /* end user-supplied calling sequence */ _vres = camlidl_c2ml_coeff_struct_ap_coeff_t(&*_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_linexpr0_ap_linexpr0_get_coeff( value _v_a, value _v_dim) { ap_linexpr0_ptr a; /*in*/ int dim; /*in*/ struct ap_coeff_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_linexpr0_ap_linexpr0_ptr(_v_a, &a, _ctx); dim = Int_val(_v_dim); /* begin user-supplied calling sequence */ { bool b; ap_coeff_init(&_res,AP_COEFF_SCALAR); if (dim<0) goto ap_linexpr0_get_coeff_exit; b = ap_linexpr0_get_coeff(&_res,a,(ap_dim_t)dim); if (b){ ap_linexpr0_get_coeff_exit: ap_coeff_clear(&_res); caml_failwith("Linexpr0.get_coeff: out of bound dimension"); } } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_coeff_struct_ap_coeff_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ ap_coeff_clear(&_res); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_linexpr0_ap_linexpr0_set_cst( value _v_a, value _v_coeff) { ap_linexpr0_ptr a; /*in*/ struct ap_coeff_t *coeff; /*in*/ struct ap_coeff_t _c1; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_linexpr0_ap_linexpr0_ptr(_v_a, &a, _ctx); coeff = &_c1; camlidl_ml2c_coeff_struct_ap_coeff_t(_v_coeff, &_c1, _ctx); /* begin user-supplied calling sequence */ ap_linexpr0_set_cst(a,coeff); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_linexpr0_ap_linexpr0_set_coeff( value _v_a, value _v_dim, value _v_coeff) { ap_linexpr0_ptr a; /*in*/ int dim; /*in*/ struct ap_coeff_t *coeff; /*in*/ struct ap_coeff_t _c1; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_linexpr0_ap_linexpr0_ptr(_v_a, &a, _ctx); dim = Int_val(_v_dim); coeff = &_c1; camlidl_ml2c_coeff_struct_ap_coeff_t(_v_coeff, &_c1, _ctx); /* begin user-supplied calling sequence */ { bool b; if (dim<0) goto ap_linexpr0_set_coeff_exit; b = ap_linexpr0_set_coeff(a,(ap_dim_t)dim,coeff); if (b){ ap_linexpr0_set_coeff_exit: caml_failwith("Linexpr0.set_coeff: out of bound dimension"); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_expr0_linexpr0_iter(value _v_closure, value _v_linexpr0) { CAMLparam2(_v_closure,_v_linexpr0); CAMLlocal2(_v_dim,_v_coeff); size_t i; ap_dim_t dim; ap_coeff_t* pcoeff; ap_linexpr0_t* linexpr0; camlidl_apron_linexpr0_ptr_ml2c(_v_linexpr0,&linexpr0); ap_linexpr0_ForeachLinterm(linexpr0,i,dim,pcoeff){ _v_dim = Val_int(dim); _v_coeff = camlidl_c2ml_coeff_struct_ap_coeff_t(pcoeff,NULL); callback2(_v_closure,_v_coeff,_v_dim); } CAMLreturn(Val_unit); } apron-dist-0.9.10/apron/mlapronidl/lincons0_caml.c0000640014525101416610000001346011252216515021716 0ustar bjeannetpopart/* File generated from lincons0.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include #include "ap_lincons0.h" #include "apron_caml.h" extern void camlidl_apron_scalar_ml2c(value, ap_scalar_t *); #define camlidl_ml2c_scalar_ap_scalar_t(v,c,ctx) camlidl_apron_scalar_ml2c(v,c) extern value camlidl_apron_scalar_c2ml(ap_scalar_t *); #define camlidl_c2ml_scalar_ap_scalar_t(c,ctx) camlidl_apron_scalar_c2ml(c) extern void camlidl_ml2c_scalar_ap_scalar_ptr(value, ap_scalar_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_ap_scalar_ptr(ap_scalar_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_scalar_struct_ap_scalar_array_t(value, struct ap_scalar_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_struct_ap_scalar_array_t(struct ap_scalar_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_t(value, struct ap_interval_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_t(struct ap_interval_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_ap_interval_ptr(value, ap_interval_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_ap_interval_ptr(ap_interval_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_array_t(value, struct ap_interval_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_array_t(struct ap_interval_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_coeff_struct_ap_coeff_t(value, struct ap_coeff_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_coeff_struct_ap_coeff_t(struct ap_coeff_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_ap_dim_t(value, ap_dim_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_ap_dim_t(ap_dim_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimchange_t(value, struct ap_dimchange_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange_t(struct ap_dimchange_t *, camlidl_ctx _ctx); extern void camlidl_apron_dimchange_ml2c(value, ap_dimchange_t *); #define camlidl_ml2c_dim_ap_dimchange_t(v,c,ctx) camlidl_apron_dimchange_ml2c(v,c) extern value camlidl_apron_dimchange_c2ml(ap_dimchange_t *); #define camlidl_c2ml_dim_ap_dimchange_t(c,ctx) camlidl_apron_dimchange_c2ml(c) extern void camlidl_ml2c_dim_struct_ap_dimchange2_t(value, struct ap_dimchange2_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange2_t(struct ap_dimchange2_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimperm_t(value, struct ap_dimperm_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimperm_t(struct ap_dimperm_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimension_t(value, struct ap_dimension_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimension_t(struct ap_dimension_t *, camlidl_ctx _ctx); extern void camlidl_apron_linexpr0_ptr_ml2c(value, ap_linexpr0_ptr *); #define camlidl_ml2c_linexpr0_ap_linexpr0_ptr(v,c,ctx) camlidl_apron_linexpr0_ptr_ml2c(v,c) extern value camlidl_apron_linexpr0_ptr_c2ml(ap_linexpr0_ptr *); #define camlidl_c2ml_linexpr0_ap_linexpr0_ptr(c,ctx) camlidl_apron_linexpr0_ptr_c2ml(c) void camlidl_apron_lincons0_ml2c(value v,ap_lincons0_t* cons, camlidl_ctx _ctx) { value _v_linexpr0; value _v_constyp; value _v_scalar; _v_linexpr0 = Field(v,0); camlidl_apron_linexpr0_ptr_ml2c(_v_linexpr0,&cons->linexpr0); _v_constyp = Field(v,1); if (Is_long(_v_constyp)){ switch (Int_val(_v_constyp)){ case 0: case 1: case 2: cons->constyp = Int_val(_v_constyp); break; case 3: cons->constyp = 4; break; default: abort(); } cons->scalar = NULL; } else { switch (Tag_val(_v_constyp)){ case 0: cons->constyp = AP_CONS_EQMOD; _v_scalar = Field(_v_constyp,0); cons->scalar = (ap_scalar_t *)camlidl_malloc(sizeof(ap_scalar_t),_ctx); camlidl_apron_scalar_ml2c(_v_scalar,cons->scalar); break; default: abort(); } } } value camlidl_apron_lincons0_c2ml(ap_lincons0_t* cons) { value vres; value _v[3]; _v[0] = _v[1] = _v[2] = 0; Begin_roots_block(_v, 3) _v[0] = camlidl_apron_linexpr0_ptr_c2ml(&cons->linexpr0); switch(cons->constyp){ case AP_CONS_EQ: case AP_CONS_SUPEQ: case AP_CONS_SUP: _v[1] = Val_int(cons->constyp); break; case AP_CONS_DISEQ: _v[1] = Val_int(3); break; case AP_CONS_EQMOD: assert(cons->scalar!=NULL); _v[2] = camlidl_apron_scalar_c2ml(cons->scalar); _v[1] = camlidl_alloc_small(1, 0); Field(_v[1],0) = _v[2]; ap_scalar_free(cons->scalar); cons->scalar = NULL; break; } vres = camlidl_alloc_small(2, 0); Field(vres, 0) = _v[0]; Field(vres, 1) = _v[1]; End_roots() return vres; } #define camlidl_ml2c_lincons0_ap_lincons0_t(v,c,ctx) camlidl_apron_lincons0_ml2c(v,c,ctx) #define camlidl_c2ml_lincons0_ap_lincons0_t(c,ctx) camlidl_apron_lincons0_c2ml(c) void camlidl_ml2c_lincons0_struct_ap_lincons0_array_t(value _v1, struct ap_lincons0_array_t * _c2, camlidl_ctx _ctx) { mlsize_t _c3; mlsize_t _c4; value _v5; _c3 = Wosize_val(_v1); (*_c2).p = camlidl_malloc(_c3 * sizeof(ap_lincons0_t ), _ctx); for (_c4 = 0; _c4 < _c3; _c4++) { _v5 = Field(_v1, _c4); camlidl_ml2c_lincons0_ap_lincons0_t(_v5, &(*_c2).p[_c4], _ctx); } (*_c2).size = _c3; } value camlidl_c2ml_lincons0_struct_ap_lincons0_array_t(struct ap_lincons0_array_t * _c1, camlidl_ctx _ctx) { value _v2; mlsize_t _c3; value _v4; _v2 = camlidl_alloc((*_c1).size, 0); Begin_root(_v2) for (_c3 = 0; _c3 < (*_c1).size; _c3++) { _v4 = camlidl_c2ml_lincons0_ap_lincons0_t(&(*_c1).p[_c3], _ctx); modify(&Field(_v2, _c3), _v4); } End_roots() return _v2; } apron-dist-0.9.10/apron/mlapronidl/manager_caml.c0000640014525101416610000001747111252216515021611 0ustar bjeannetpopart/* File generated from manager.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include #include "ap_manager.h" #include "apron_caml.h" void camlidl_apron_manager_funid_ml2c(value _v, enum ap_funid_t* res) { int v = Int_val(_v); if (v+1>=AP_FUNID_CHANGE_ENVIRONMENT) *res = v+1; else *res = v; } value camlidl_apron_manager_funid_c2ml(enum ap_funid_t* arg) { int n = *arg; if (n>=0 && nAP_FUNID_SIZE) n--; } else { invalid_argument("enum ap_funid_t: bad enum value"); } return Val_int(n); } void camlidl_apron_manager_exc_ml2c(value _v, enum ap_exc_t* res) { *res = Int_val(_v); } value camlidl_apron_manager_exc_c2ml(enum ap_exc_t* arg) { int n = *arg; if (! (n>=AP_EXC_NONE && n= AP_FUNID_SIZE) invalid_argument("Manager.get.funopt : should be different from Funid_change_environment and Funid_rename_array (no option for remaining identifiers)"); _res = ap_manager_get_funopt(man,funid); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_manager_struct_ap_funopt_t(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_manager_ap_manager_set_funopt( value _v_man, value _v_funid, value _v_funopt) { ap_manager_ptr man; /*in*/ ap_funid_t funid; /*in*/ struct ap_funopt_t *funopt; /*in*/ struct ap_funopt_t _c1; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_manager_ap_funid_t(_v_funid, &funid, _ctx); funopt = &_c1; camlidl_ml2c_manager_struct_ap_funopt_t(_v_funopt, &_c1, _ctx); /* begin user-supplied calling sequence */ if (funid >= AP_FUNID_SIZE) invalid_argument("Manager.set.funopt ...: should be different from Funid_change_environment and Funid_rename_array (no option for remaining identifiers)"); ap_manager_set_funopt(man,funid,funopt); /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_manager_ap_manager_get_flag_exact( value _v_man) { ap_manager_ptr man; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); _res = ap_manager_get_flag_exact(man); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_manager_ap_manager_get_flag_best( value _v_man) { ap_manager_ptr man; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); _res = ap_manager_get_flag_best(man); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_manager_ap_manager_set_deserialize( value _v_man) { ap_manager_ptr man; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); ap_manager_set_deserialize(man); camlidl_free(_ctx); return Val_unit; } value camlidl_manager_ap_manager_get_deserialize(value _unit) { ap_manager_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; _res = ap_manager_get_deserialize(); _vres = camlidl_c2ml_manager_ap_manager_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } apron-dist-0.9.10/apron/mlapronidl/lincons0.idl0000640014525101416610000000755710644461001021256 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(MLI,"(** APRON Linear constraints of level 0 *)") quote(C, "\n\ #include \n\ #include \"ap_lincons0.h\"\n\ #include \"apron_caml.h\"\n\ \n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; import "linexpr0.idl"; /* For ap_lincons0_t, - the conversion from ML to C may use allocation, but it is automatically freed by Camlidl mechanisms - the conversion from C to ML free after conversion the scalar field in the C structure. the C type should NOT be deallocated */ quote(C,"\n\ void camlidl_apron_lincons0_ml2c(value v,ap_lincons0_t* cons, camlidl_ctx _ctx)\n\ {\n\ value _v_linexpr0;\n\ value _v_constyp;\n\ value _v_scalar;\n\ \n\ _v_linexpr0 = Field(v,0);\n\ camlidl_apron_linexpr0_ptr_ml2c(_v_linexpr0,&cons->linexpr0);\n\ _v_constyp = Field(v,1);\n\ if (Is_long(_v_constyp)){\n\ switch (Int_val(_v_constyp)){ case 0:\n\ case 1:\n\ case 2:\n\ cons->constyp = Int_val(_v_constyp);\n\ break;\n\ case 3:\n\ cons->constyp = 4;\n\ break;\n\ default:\n\ abort();\n\ }\n\ cons->scalar = NULL;\n\ }\n\ else {\n\ switch (Tag_val(_v_constyp)){\n\ case 0:\n\ cons->constyp = AP_CONS_EQMOD;\n\ _v_scalar = Field(_v_constyp,0);\n\ cons->scalar = (ap_scalar_t *)camlidl_malloc(sizeof(ap_scalar_t),_ctx);\n\ camlidl_apron_scalar_ml2c(_v_scalar,cons->scalar);\n\ break;\n\ default:\n\ abort();\n\ }\n\ }\n\ }\n\ value camlidl_apron_lincons0_c2ml(ap_lincons0_t* cons)\n\ {\n\ value vres;\n\ value _v[3];\n\ _v[0] = _v[1] = _v[2] = 0;\n\ \n\ Begin_roots_block(_v, 3)\n\ _v[0] = camlidl_apron_linexpr0_ptr_c2ml(&cons->linexpr0);\n\ switch(cons->constyp){\n\ case AP_CONS_EQ:\n\ case AP_CONS_SUPEQ:\n\ case AP_CONS_SUP:\n\ _v[1] = Val_int(cons->constyp);\n\ break;\n\ case AP_CONS_DISEQ:\n\ _v[1] = Val_int(3);\n\ break;\n\ case AP_CONS_EQMOD:\n\ assert(cons->scalar!=NULL);\n\ _v[2] = camlidl_apron_scalar_c2ml(cons->scalar);\n\ _v[1] = camlidl_alloc_small(1, 0);\n\ Field(_v[1],0) = _v[2];\n\ ap_scalar_free(cons->scalar); cons->scalar = NULL;\n\ break;\n\ }\n\ vres = camlidl_alloc_small(2, 0);\n\ Field(vres, 0) = _v[0];\n\ Field(vres, 1) = _v[1];\n\ End_roots()\n\ return vres;\n\ }\n\ ") typedef [mltype("{\n mutable linexpr0 : Linexpr0.t;\n mutable typ : typ;\n}"), abstract, ml2c(camlidl_apron_lincons0_ml2c), c2ml(camlidl_apron_lincons0_c2ml)] struct ap_lincons0_t ap_lincons0_t; quote(MLMLI,"and typ =\n | EQ\n | SUPEQ\n | SUP\n | DISEQ\n | EQMOD of Scalar.t\n") struct ap_lincons0_array_t { [size_is(size)] ap_lincons0_t* p; int size; }; quote(MLI,"\n\ (** Make a linear constraint. Modifying later the linear expression\n\ modifies correspondingly the linear constraint and conversely *)\n\ val make : Linexpr0.t -> typ -> t\n\ \n\ (** Copy a linear constraint (deep copy) *)\n\ val copy : t -> t\n\ \n\ (** Convert a constraint type to a string ([=],[>=], or [>]) *)\n\ val string_of_typ : typ -> string\n\ \n\ (** Print a constraint *)\n\ val print : (Dim.t -> string) -> Format.formatter -> t -> unit\n\ ") quote(ML,"\n\ let string_of_typ = function\n\ | EQ | EQMOD _ -> \"=\"\n\ | SUPEQ -> \">=\"\n\ | SUP -> \">\"\n\ | DISEQ -> \"<>\"\n\ \n\ let print assoc fmt cons = \n\ Linexpr0.print assoc fmt cons.linexpr0;\n\ Format.fprintf fmt \"%s0\" (string_of_typ cons.typ);\n\ begin match cons.typ with\n\ | EQMOD x -> Format.fprintf fmt \" mod %a\" Scalar.print x;\n\ | _ -> ()\n\ end;\n\ ()\n\ let make expr typ = {\n\ linexpr0 = expr; typ = typ \n\ }\n\ let copy cons = {\n\ linexpr0 = Linexpr0.copy cons.linexpr0; typ = cons.typ\n\ }\n\ ") apron-dist-0.9.10/apron/mlapronidl/linexpr0.mli0000640014525101416610000000512211252216515021271 0ustar bjeannetpopart(* File generated from linexpr0.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t (** APRON Linear expressions of level 0 *) (** Create a linear expression. Its representation is sparse if [None] is provided, dense of size [size] if [Some size] is provided. *) external make : int option -> t = "camlidl_linexpr0_ap_linexpr0_make" val of_list : int option -> (Coeff.t * Dim.t) list -> Coeff.t option -> t (** Combines {!make} and {!set_list} (see below) *) val of_array : int option -> (Coeff.t * Dim.t) array -> Coeff.t option -> t (** Combines {!make} and {!set_array} (see below) *) (** In case of sparse representation, remove zero coefficients *) external minimize : t -> unit = "camlidl_linexpr0_ap_linexpr0_minimize" (** Copy *) external copy : t -> t = "camlidl_linexpr0_ap_linexpr0_copy" (** Comparison with lexicographic ordering using Coeff.cmp, terminating by constant *) external compare : t -> t -> int = "camlidl_linexpr0_ap_linexpr0_compare" (** Hashing function *) external hash : t -> int = "camlidl_linexpr0_ap_linexpr0_hash" (** Get the size of the linear expression (which may be sparse or dense) *) external get_size : t -> int = "camlidl_linexpr0_ap_linexpr0_get_size" (** Get the constant *) external get_cst : t -> Coeff.t = "camlidl_linexpr0_ap_linexpr0_get_cst" (** Get the coefficient corresponding to the dimension *) external get_coeff : t -> int -> Coeff.t = "camlidl_linexpr0_ap_linexpr0_get_coeff" val set_list : t -> (Coeff.t * Dim.t) list -> Coeff.t option -> unit (** Set simultaneously a number of coefficients. [set_list expr [(c1,1); (c2,2)] (Some cst)] assigns coefficients [c1] to dimension 1, coefficient [c2] to dimension 2, and coefficient [cst] to the constant. If [(Some cst)] is replaced by [None], the constant coefficient is not assigned. *) val set_array : t -> (Coeff.t * Dim.t) array -> Coeff.t option -> unit (** Set simultaneously a number of coefficients, as [set_list]. *) (** Set the constant *) external set_cst : t -> Coeff.t -> unit = "camlidl_linexpr0_ap_linexpr0_set_cst" (** Set the coefficient corresponding to the dimension *) external set_coeff : t -> int -> Coeff.t -> unit = "camlidl_linexpr0_ap_linexpr0_set_coeff" (** Iter the function on the pairs coefficient/dimension of the linear expression *) external iter: (Coeff.t -> Dim.t -> unit) -> t -> unit = "camlidl_expr0_linexpr0_iter" (** Print a linear expression, using a function converting from dimensions to names *) val print : (Dim.t -> string) -> Format.formatter -> t -> unit apron-dist-0.9.10/apron/mlapronidl/scalar.idl0000640014525101416610000001625311023232505020764 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #define HAS_MPFR 1\n\ #include \n\ #include \"ap_coeff.h\"\n\ #include \"gmp_caml.h\"\n\ #include \"apron_caml.h\"\n\ ") /* For ap_scalar_t, - the conversion from ML to C reuse the ML allocated memory - the conversion from C to ML duplicate the C allocated memory. Hence, the C type should be explicitly deallocated (if allocated from the underlying C function) */ quote(C,"\n\ void camlidl_apron_scalar_ml2c(value v, struct ap_scalar_t* scalar)\n\ {\n\ value v2 = Field(v,0);\n\ scalar->discr = Tag_val(v);\n\ switch (scalar->discr) {\n\ case 0: /* DOUBLE */\n\ scalar->val.dbl = Double_val(v2);\n\ break;\n\ case 1: /* MPQ */\n\ scalar->val.mpq = (mpq_ptr)(Data_custom_val(v2));\n\ break;\n\ case 2: /* MPFR */\n\ scalar->val.mpfr = (mpfr_ptr)(Data_custom_val(v2));\n\ break;\n\ default:\n\ caml_failwith(\"unknown scalar discriminant in camlidl_apron_scalar_ml2c\");\n\ }\n\ return;\n\ }\n\ value camlidl_apron_scalar_c2ml(struct ap_scalar_t* scalar)\n\ {\n\ value v,v2;\n\ v2 = Val_unit;\n\ Begin_root(v2);\n\ switch(scalar->discr){\n\ case AP_SCALAR_DOUBLE:\n\ v2 = caml_copy_double(scalar->val.dbl);\n\ break;\n\ case AP_SCALAR_MPQ:\n\ {\n\ mpq_t mpq;\n\ mpq_ptr mpq_ptr = mpq;\n\ mpq_init(mpq);\n\ mpq_set(mpq,scalar->val.mpq);\n\ v2 = camlidl_mpq_ptr_c2ml(&mpq_ptr);\n\ }\n\ break;\n\ case AP_SCALAR_MPFR:\n\ {\n\ mpfr_t mpfr;\n\ mpfr_ptr mpfr_ptr = mpfr;\n\ mpfr_init2(mpfr,mpfr_get_prec(scalar->val.mpfr));\n\ mpfr_set(mpfr,scalar->val.mpfr,GMP_RNDU /* exact */);\n\ v2 = camlidl_mpfr_ptr_c2ml(&mpfr_ptr);\n\ }\n\ break;\n\ default:\n\ caml_failwith(\"unknown scalar discriminant in camlidl_apron_scalar_c2ml\");\n\ }\n\ v = alloc_small(1,scalar->discr);\n\ Field(v,0) = v2;\n\ End_roots();\n\ return v;\n\ }\n\ ") typedef [mltype("Float of float | Mpqf of Mpqf.t | Mpfrf of Mpfrf.t"), abstract, ml2c(camlidl_apron_scalar_ml2c), c2ml(camlidl_apron_scalar_c2ml)] struct ap_scalar_t ap_scalar_t; typedef [ref]ap_scalar_t* ap_scalar_ptr; struct ap_scalar_array_t { [size_is(size)]ap_scalar_ptr* p; int size; }; quote(MLMLI,"(** APRON Scalar numbers. See {!Mpqf} for operations on GMP multiprecision rational numbers and {!Mpfr} for operations on MPFR multi-precision floating-point numbers. *)\n\n") quote(MLI,"\n\ val of_mpq : Mpq.t -> t\n\ val of_mpqf : Mpqf.t -> t\n\ val of_int : int -> t\n\ val of_frac : int -> int -> t\n\ (** Create a scalar of type [Mpqf] from resp.\n\ - A multi-precision rational [Mpq.t] \n\ - A multi-precision rational [Mpqf.t] \n\ - an integer \n\ - a fraction [x/y]\n\ *)\n\ \n\ val of_mpfr : Mpfr.t -> t\n\ val of_mpfrf : Mpfrf.t -> t\n\ (** Create a scalar of type [Mpfrf] with the given value *)\n\ val of_float : float -> t\n\ (** Create a scalar of type [Float] with the given value *)\n\ val of_infty : int -> t \n\ (** Create a scalar of type [Float] with the value multiplied by\n\ infinity (resulting in minus infinity, zero, or infinity \n\ *)\n\ val is_infty : t -> int\n\ (** Infinity test.\n\ [is_infty x] returns [-1] if x is [-oo], [1] if x is [+oo], and [0] if [x] is\n\ finite. *)\n\ \n\ val sgn : t -> int\n\ (** Return the sign of the coefficient, which may be a negative value, zero\n\ or a positive value. *)\n\ \n\ val cmp : t -> t -> int\n\ (** Compare two coefficients, possibly converting to [Mpqf.t].\n\ [compare x y] returns a negative number if [x] is less than [y], \n\ [0] if they ar equal, and a positive number if [x] is greater than [y].\n\ *)\n\ \n\ val cmp_int : t -> int -> int\n\ (** Compare a coefficient with an integer *)\n\ \n\ val equal : t -> t -> bool\n\ (** Equality test, possibly using a conversion to [Mpqf.t].\n\ Return [true] if the 2 values are equal. Two infinite values of the same\n\ signs are considered as equal. *)\n\ \n\ val equal_int : t -> int -> bool\n\ (** Equality test with an integer *)\n\ \n\ val neg : t -> t\n\ (** Negation *)\n\ val to_string : t -> string\n\ (** Conversion to string, using [string_of_double], [Mpqf.to_string] or [Mpfr.to_string]\n\ *)\n\ \n\ val print : Format.formatter -> t -> unit\n\ (** Print a coefficient *)\n\ ") quote(ML,"\ let of_mpq x = Mpqf (Mpqf.of_mpq x)\n\ let of_mpqf x = Mpqf x\n\ let of_mpfr x = Mpfrf (Mpfrf.of_mpfr x)\n\ let of_mpfrf x = Mpfrf x\n\ let of_int x = Mpqf(Mpqf.of_int x)\n\ let of_frac x y = Mpqf(Mpqf.of_frac x y)\n\ let of_float x = Float(x)\n\ let of_infty s = \n\ if s>0 then Float(Pervasives.infinity)\n\ else if s<0 then Float(Pervasives.neg_infinity)\n\ else Float(0.0)\n\ let is_infty scalar =\n\ match scalar with\n\ | Mpqf x ->\n\ let z = Mpqf.get_den x in\n\ if Mpzf.sgn z <> 0 then 0\n\ else begin\n\ let z = Mpqf.get_num x in\n\ let sgn = Mpzf.sgn z in\n\ if sgn > 0 then 1 else if sgn < 0 then -1 else 0\n\ end\n\ | Mpfrf x ->\n\ if Mpfrf.inf_p x then\n\ if Mpfrf.sgn x > 0 then 1 else -1\n\ else 0\n\ | Float x ->\n\ if x = Pervasives.infinity then 1\n\ else if x = Pervasives.neg_infinity then -1\n\ else 0\n\ let sgn scalar =\n\ match scalar with\n\ | Mpqf x -> Mpqf.sgn x\n\ | Mpfrf x -> Mpfrf.sgn x\n\ | Float x -> if x > 0.0+.0.0 then 1 else if x < -.0.0 then -1 else 0\n\ let to_mpqf = function\n\ | Mpqf x -> x\n\ | Mpfrf x -> Mpfrf.to_mpqf x\n\ | Float x -> Mpqf.of_float x\n\ let cmp c1 c2 =\n\ let s1 = is_infty c1 in\n\ let s2 = is_infty c2 in\n\ if s1>s2 then 1\n\ else if s1 Mpqf.cmp x1 x2\n\ | (Mpfrf x1, Mpfrf x2) -> Mpfrf.cmp x1 x2\n\ | (Float x1, Float x2) -> if x1>x2 then 1 else if x1 Mpqf.cmp (to_mpqf x1) (to_mpqf x2)\n\ end\n\ let equal c1 c2 =\n\ let s1 = is_infty c1 in\n\ let s2 = is_infty c2 in\n\ if s1!=s2 then false\n\ else if s1!=0 then true\n\ else begin\n\ match (c1,c2) with\n\ | (Mpqf x1, Mpqf x2) -> Mpqf.equal x1 x2\n\ | (Mpfrf x1, Mpfrf x2) -> Mpfrf.cmp x1 x2 = 0\n\ | (Float x1, Float x2) -> x1 = x2\n\ | x1, x2 -> Mpqf.equal (to_mpqf x1) (to_mpqf x2)\n\ end\n\ let cmp_int scalar n =\n\ match scalar with\n\ | Mpqf x -> Mpqf.cmp_int x n\n\ | Mpfrf x -> Mpfrf.cmp_int x n\n\ | Float x -> Pervasives.compare x (float_of_int n)\n\ let equal_int scalar n =\n\ match scalar with\n\ | Mpqf x -> (Mpqf.cmp_int x n)=0\n\ | Mpfrf x -> (Mpfrf.cmp_int x n)=0\n\ | Float x -> x=(float_of_int n)\n\ let neg scalar =\n\ match scalar with\n\ | Mpqf x -> Mpqf(Mpqf.neg x)\n\ | Mpfrf x ->\n\ let y = Mpfr.init2 (Mpfr.get_prec x) in\n\ ignore (Mpfr.neg y x Mpfr.Up);\n\ Mpfrf(Mpfrf.mpfrf y)\n \ | Float x -> Float(-. x)\n\ let to_string scalar =\n\ match scalar with\n\ | Mpqf x -> Mpqf.to_string x\n\ | Mpfrf x -> Mpfrf.to_string x\n\ | Float x -> string_of_float x\n\ let print fmt scalar =\n\ Format.pp_print_string fmt (to_string scalar)\n\ ") apron-dist-0.9.10/apron/mlapronidl/abstract0.idl0000640014525101416610000007362611247457151021427 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \n\ #include \"ap_expr0.h\"\n\ #include \"ap_abstract0.h\"\n\ #include \"caml/callback.h\"\n\ #include \"apron_caml.h\"\n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; import "linexpr0.idl"; import "lincons0.idl"; import "generator0.idl"; import "texpr0.idl"; import "tcons0.idl"; import "manager.idl"; typedef [abstract, c2ml(camlidl_apron_abstract0_ptr_c2ml), ml2c(camlidl_apron_abstract0_ptr_ml2c)] struct ap_abstract0_ptr ap_abstract0_ptr; quote(MLMLI,"(** APRON Abstract value of level 0 *)") quote(MLMLI,"(** The type parameter ['a] allows to distinguish abstract values with different underlying abstract domains. *)\n") quote(MLI,"\n(** TO BE DOCUMENTED *)") void ap_abstract0_set_gc(int size) quote(call,"camlidl_apron_heap = size;"); quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(** {2 General management} *)") quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Memory} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n(** Copy a value *)") ap_abstract0_ptr ap_abstract0_copy(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Return the abstract size of a value *)") int ap_abstract0_size(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Control of internal representation} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n(** Minimize the size of the representation of the value. This may result in a later recomputation of internal information.*)") void ap_abstract0_minimize(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Put the abstract value in canonical form. (not yet clear definition) *)") void ap_abstract0_canonicalize(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"I0_CHECK_EXC(man)"); int ap_abstract0_hash(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** [approximate man abs alg] perform some transformation on the abstract value, guided by the argument [alg]. The transformation may lose information. The argument [alg] overrides the field algorithm of the structure of type [Manager.funopt] associated to ap_abstract0_approximate (commodity feature).*)") void ap_abstract0_approximate(ap_manager_ptr man, ap_abstract0_ptr a, int v) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Printing} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n(** Dump on the [stdout] C stream the internal representation of an abstract value, for debugging purposes *)") void ap_abstract0_fdump(ap_manager_ptr man, ap_abstract0_ptr a) quote(call,"ap_abstract0_fdump(stdout,man, a); fflush(stdout);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Print as a set of constraints *)") quote(MLI,"val print: (int -> string) -> Format.formatter -> 'a t -> unit") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Serialization} *)") quote(MLMLI,"(* ============================================================ *)") /* membuf_t ap_abstract0_serialize_raw(ap_manager_ptr man, ap_abstract0_ptr a); ap_abstract0_ptr ap_abstract0_deserialize_raw(ap_manager_ptr man, void* ptr); */ quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(** {2 Constructor, accessors, tests and property extraction} *)") quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Basic constructors} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n(** Create a bottom (empty) value with the given number of integer and real variables *)") ap_abstract0_ptr ap_abstract0_bottom(ap_manager_ptr man, int v1, int v2) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Create a top (universe) value with the given number of integer and real variables *)") ap_abstract0_ptr ap_abstract0_top(ap_manager_ptr man, int v1, int v2) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Abstract an hypercube.\n\n[of_box man intdim realdim array] abstracts an hypercube defined by the array of intervals of size [intdim+realdim] *)") ap_abstract0_ptr ap_abstract0_of_box(ap_manager_ptr man, int intdim, int realdim, struct ap_interval_array_t array) quote(call,"_res = ap_abstract0_of_box(man,intdim,realdim,(ap_interval_t**)array.p);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Accessors} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n") struct ap_dimension_t ap_abstract0_dimension(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"I0_CHECK_EXC(man)"); ap_manager_ptr ap_abstract0_manager(ap_abstract0_ptr a) quote(call,"_res = ap_manager_copy(a->man);"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Tests} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n(** Emptiness test *)") boolean ap_abstract0_is_bottom(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Universality test *)") boolean ap_abstract0_is_top(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Inclusion test. The 2 abstract values should be compatible. *)") boolean ap_abstract0_is_leq(ap_manager_ptr man, ap_abstract0_ptr a1, ap_abstract0_ptr a2) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Equality test. The 2 abstract values should be compatible. *)") boolean ap_abstract0_is_eq(ap_manager_ptr man, ap_abstract0_ptr a1, ap_abstract0_ptr a2) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Does the abstract value satisfy the linear constraint ? *)") boolean ap_abstract0_sat_lincons(ap_manager_ptr man, ap_abstract0_ptr a, [ref]ap_lincons0_t* v) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Does the abstract value satisfy the tree expression constraint ? *)") boolean ap_abstract0_sat_tcons(ap_manager_ptr man, ap_abstract0_ptr a, [ref]ap_tcons0_t* v) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Does the abstract value satisfy the constraint [dim in interval] ? *)") boolean ap_abstract0_sat_interval(ap_manager_ptr man, ap_abstract0_ptr a, ap_dim_t v1, [ref]struct ap_interval_t* v2) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Is the dimension unconstrained in the abstract value ? If yes, this means that the existential quantification of the dimension does not change the value. *)") boolean ap_abstract0_is_dimension_unconstrained(ap_manager_ptr man, ap_abstract0_ptr a, ap_dim_t v); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Extraction of properties} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n(** Return the interval of variation of the dimension in the abstract value. *)") [ref]struct ap_interval_t* ap_abstract0_bound_dimension(ap_manager_ptr man, ap_abstract0_ptr a, ap_dim_t v) quote(dealloc,"ap_interval_free(_res); I0_CHECK_EXC(man)"); quote(MLI,"\n(** Return the interval of variation of the linear expression in the abstract value.\n\nImplement a form of linear programming, where the argument linear expression is the one to optimize under the constraints induced by the abstract value. *)") [ref]struct ap_interval_t* ap_abstract0_bound_linexpr(ap_manager_ptr man, ap_abstract0_ptr a, ap_linexpr0_ptr v) quote(dealloc,"ap_interval_free(_res); I0_CHECK_EXC(man)"); quote(MLI,"\n(** Return the interval of variation of the tree expression in the abstract value. *)") [ref]struct ap_interval_t* ap_abstract0_bound_texpr(ap_manager_ptr man, ap_abstract0_ptr a, ap_texpr0_ptr v) quote(dealloc,"ap_interval_free(_res); I0_CHECK_EXC(man)"); quote(MLI,"\n(** Convert the abstract value to an hypercube *)") struct ap_interval_array_t ap_abstract0_to_box(ap_manager_ptr man, ap_abstract0_ptr a) quote(call,"{\n\ ap_dimension_t dim; _res.p = ap_abstract0_to_box(man,a);\n\ dim = ap_abstract0_dimension(man,a);\n\ _res.size = dim.intdim + dim.realdim;\n\ }") quote(dealloc,"ap_interval_array_free(_res.p, _res.size); I0_CHECK_EXC(man)"); quote(MLI,"\n(** Convert the abstract value to a conjunction of linear constraints. *)") struct ap_lincons0_array_t ap_abstract0_to_lincons_array(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"free(_res.p); I0_CHECK_EXC(man)"); quote(MLI,"\n(** Convert the abstract value to a conjunction of tree expression constraints. *)") struct ap_tcons0_array_t ap_abstract0_to_tcons_array(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"free(_res.p); I0_CHECK_EXC(man)"); quote(MLI,"\n(** Convert the abstract value to a set of generators that defines it. *)") struct ap_generator0_array_t ap_abstract0_to_generator_array(ap_manager_ptr man, ap_abstract0_ptr a) quote(dealloc,"free(_res.p); I0_CHECK_EXC(man)"); quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(** {2 Operations} *)") quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Meet and Join} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n") quote(MLI,"(** Meet of 2 abstract values. *)") ap_abstract0_ptr ap_abstract0_meet(ap_manager_ptr man, ap_abstract0_ptr a1, ap_abstract0_ptr a2) quote(call,"_res = ap_abstract0_meet(man,false,a1,a2);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Meet of a non empty array of abstract values. *)") ap_abstract0_ptr ap_abstract0_meet_array(ap_manager_ptr man, [size_is(size)] ap_abstract0_ptr* array, unsigned int size) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Meet of an abstract value with an array of linear constraints. *)") ap_abstract0_ptr ap_abstract0_meet_lincons_array(ap_manager_ptr man, ap_abstract0_ptr a, [ref]struct ap_lincons0_array_t* v) quote(call,"_res = ap_abstract0_meet_lincons_array(man,false,a,v);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Meet of an abstract value with an array of tree expression constraints. *)") ap_abstract0_ptr ap_abstract0_meet_tcons_array(ap_manager_ptr man, ap_abstract0_ptr a, [ref]struct ap_tcons0_array_t* v) quote(call,"_res = ap_abstract0_meet_tcons_array(man,false,a,v);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Join of 2 abstract values. *)") ap_abstract0_ptr ap_abstract0_join(ap_manager_ptr man, ap_abstract0_ptr a1, ap_abstract0_ptr a2) quote(call,"_res = ap_abstract0_join(man,false,a1,a2);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Join of a non empty array of abstract values. *)") ap_abstract0_ptr ap_abstract0_join_array(ap_manager_ptr man, [size_is(size)]ap_abstract0_ptr array[], unsigned int size) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Add the array of generators to the abstract value (time elapse operator).\n\n The generators should either lines or rays, not vertices. *)") ap_abstract0_ptr ap_abstract0_add_ray_array(ap_manager_ptr man, ap_abstract0_ptr a, [ref]struct ap_generator0_array_t* v) quote(call,"_res = ap_abstract0_add_ray_array(man,false,a,v);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** {5 Side-effect versions of the previous functions} *)\n") void ap_abstract0_meet_with(ap_manager_ptr man, ap_abstract0_ptr a1, ap_abstract0_ptr a2) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_meet(man,true,a1,a2);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a1)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_meet_lincons_array_with(ap_manager_ptr man, ap_abstract0_ptr a, [ref]struct ap_lincons0_array_t* v) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_meet_lincons_array(man,true,a,v);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_meet_tcons_array_with(ap_manager_ptr man, ap_abstract0_ptr a, [ref]struct ap_tcons0_array_t* v) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_meet_tcons_array(man,true,a,v);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_join_with(ap_manager_ptr man, ap_abstract0_ptr a1, ap_abstract0_ptr a2) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_join(man,true,a1,a2);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a1)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_add_ray_array_with(ap_manager_ptr man, ap_abstract0_ptr a, [ref]struct ap_generator0_array_t* v) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_add_ray_array(man,true,a,v);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Assignements and Substitutions} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** Parallel assignement of an array of dimensions by an array of same size of linear expressions *)") ap_abstract0_ptr ap_abstract0_assign_linexpr_array(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v3)]ap_dim_t* v1, [size_is(v4)]ap_linexpr0_ptr* v2, int v3, int v4, ap_abstract0_ptr* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract0.assign_linexpr_array: arrays of different size\");\n\ _res = ap_abstract0_assign_linexpr_array(man,false,a,v1,v2,v3,dest==NULL ? NULL : *dest);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Parallel substitution of an array of dimensions by an array of same size of linear expressions *)") ap_abstract0_ptr ap_abstract0_substitute_linexpr_array(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v3)]ap_dim_t* v1, [size_is(v4)]ap_linexpr0_ptr* v2, int v3, int v4, ap_abstract0_ptr* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract0.substitute_linexpr_array: arrays of different size\");\n\ _res = ap_abstract0_substitute_linexpr_array(man,false,a,v1,v2,v3,dest==NULL ? NULL : *dest);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Parallel assignement of an array of dimensions by an array of same size of tree expressions *)") ap_abstract0_ptr ap_abstract0_assign_texpr_array(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v3)]ap_dim_t* v1, [size_is(v4)]ap_texpr0_ptr* v2, int v3, int v4, ap_abstract0_ptr* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract0.assign_texpr_array: arrays of different size\");\n\ _res = ap_abstract0_assign_texpr_array(man,false,a,v1,v2,v3,dest==NULL ? NULL : *dest);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Parallel substitution of an array of dimensions by an array of same size of tree expressions *)") ap_abstract0_ptr ap_abstract0_substitute_texpr_array(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v3)]ap_dim_t* v1, [size_is(v4)]ap_texpr0_ptr* v2, int v3, int v4, ap_abstract0_ptr* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract0.substitute_texpr_array: arrays of different size\");\n\ _res = ap_abstract0_substitute_texpr_array(man,false,a,v1,v2,v3,dest==NULL ? NULL : *dest);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** {5 Side-effect versions of the previous functions} *)\n\n") void ap_abstract0_assign_linexpr_array_with(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v3)]ap_dim_t* v1, [size_is(v4)]ap_linexpr0_ptr* v2, int v3, int v4, ap_abstract0_ptr* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract0.assign_linexpr_array_with: arrays of different size\");\n\ {\n\ ap_abstract0_t* res = ap_abstract0_assign_linexpr_array(man,true,a,v1,v2,v3,dest==NULL ? NULL : *dest);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_substitute_linexpr_array_with(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v3)]ap_dim_t* v1, [size_is(v4)]ap_linexpr0_ptr* v2, int v3, int v4, ap_abstract0_ptr* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract0.substitute_linexpr_array_with: arrays of different size\");\n\ {\n\ ap_abstract0_t* res = ap_abstract0_substitute_linexpr_array(man,true,a,v1,v2,v3,dest==NULL ? NULL : *dest);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_assign_texpr_array_with(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v3)]ap_dim_t* v1, [size_is(v4)]ap_texpr0_ptr* v2, int v3, int v4, ap_abstract0_ptr* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract0.assign_texpr_array_with: arrays of different size\");\n\ {\n\ ap_abstract0_t* res = ap_abstract0_assign_texpr_array(man,true,a,v1,v2,v3,dest==NULL ? NULL : *dest);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_substitute_texpr_array_with(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v3)]ap_dim_t* v1, [size_is(v4)]ap_texpr0_ptr* v2, int v3, int v4, ap_abstract0_ptr* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract0.substitute_texpr_array_with: arrays of different size\");\n\ {\n\ ap_abstract0_t* res = ap_abstract0_substitute_texpr_array(man,true,a,v1,v2,v3,dest==NULL ? NULL : *dest);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n\n") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Projections} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** These functions implements forgeting (existential quantification) of (array of) dimensions. Both functional and side-effect versions are provided. The Boolean, if true, adds a projection onto 0-plane. *)\n\n") ap_abstract0_ptr ap_abstract0_forget_array(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v2)]ap_dim_t* v1, int v2, boolean v3) quote(call,"_res = ap_abstract0_forget_array(man,false,a,v1,v2,v3);") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_forget_array_with(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v2)]ap_dim_t* v1, int v2, boolean v3) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_forget_array(man,true,a,v1,v2,v3);\n \ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Change and permutation of dimensions} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"\n") ap_abstract0_ptr ap_abstract0_add_dimensions(ap_manager_ptr man, ap_abstract0_ptr a, ap_dimchange_t dimchange, boolean project) quote(call,"_res = ap_abstract0_add_dimensions(man,false,a,&dimchange, project);ap_dimchange_clear(&dimchange);") quote(dealloc,"I0_CHECK_EXC(man)"); ap_abstract0_ptr ap_abstract0_remove_dimensions(ap_manager_ptr man, ap_abstract0_ptr a, ap_dimchange_t dimchange) quote(call,"_res = ap_abstract0_remove_dimensions(man,false,a,&dimchange);ap_dimchange_clear(&dimchange);") quote(dealloc,"I0_CHECK_EXC(man)"); ap_abstract0_ptr ap_abstract0_apply_dimchange2(ap_manager_ptr man, ap_abstract0_ptr a, struct ap_dimchange2_t dimchange2, boolean project) quote(call," _res = ap_abstract0_apply_dimchange2(man,false,a,&dimchange2,project); if (dimchange2.add) ap_dimchange_clear(dimchange2.add); if (dimchange2.remove) ap_dimchange_clear(dimchange2.remove); ") quote(dealloc,"I0_CHECK_EXC(man)"); ap_abstract0_ptr ap_abstract0_permute_dimensions(ap_manager_ptr man, ap_abstract0_ptr a, [ref]struct ap_dimperm_t* perm) quote(call,"_res = ap_abstract0_permute_dimensions(man,false,a,perm);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** {5 Side-effect versions of the previous functions} *)\n\n") void ap_abstract0_add_dimensions_with(ap_manager_ptr man, ap_abstract0_ptr a, ap_dimchange_t dimchange, boolean v1) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_add_dimensions(man,true,a,&dimchange,v1);\n \ ap_dimchange_clear(&dimchange);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_remove_dimensions_with(ap_manager_ptr man, ap_abstract0_ptr a, ap_dimchange_t dimchange) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_remove_dimensions(man,true,a,&dimchange);\n\ ap_dimchange_clear(&dimchange);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_apply_dimchange2_with(ap_manager_ptr man, ap_abstract0_ptr a, struct ap_dimchange2_t dimchange2, boolean project) quote(call," ap_abstract0_t* res = ap_abstract0_apply_dimchange2(man,true,a,&dimchange2,project); ap_dimchange2_clear(&dimchange2); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res; ") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_permute_dimensions_with(ap_manager_ptr man, ap_abstract0_ptr a, struct ap_dimperm_t* perm) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_permute_dimensions(man,true,a,perm);\n\ *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n\n") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Expansion and folding of dimensions} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n\ (**\n\ These functions allows to expand one dimension into several ones having the\n\ same properties with respect to the other dimensions, and to fold several\n\ dimensions into one. Formally,\n\ \n\ - expand P(x,y,z) z w = P(x,y,z) inter P(x,y,w) if z is expanded in z and w\n\ - fold Q(x,y,z,w) z w = exists w:Q(x,y,z,w) union (exist z:Q(x,y,z,w))(z<-w)\n\ if z and w are folded onto z\n\ *)\n\n\ ") quote(MLI,"(** \ Expansion: [expand a dim n] expands the dimension [dim] into itself + [n]\n\ additional dimensions. It results in (n+1) unrelated dimensions having\n\ same relations with other dimensions. The (n+1) dimensions are put as\n\ follows: \n\ \n\ - original dimension [dim]\n\ - if the dimension is integer, the n additional dimensions are put at the\n\ end of integer dimensions; if it is real, at the end of the real\n\ dimensions.\n\ *)") ap_abstract0_ptr ap_abstract0_expand(ap_manager_ptr man, ap_abstract0_ptr a, ap_dim_t v1, int v2) quote(call,"_res = ap_abstract0_expand(man,false,a,v1,v2);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI," \ (** Folding: [fold a tdim] fold the dimensions in the array [tdim] of size n>=1\n\ and put the result in the first dimension of the array. The other\n\ dimensions of the array are then removed (using\n\ ap_abstract0_permute_remove_dimensions).\n\ *)") ap_abstract0_ptr ap_abstract0_fold(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v2)]ap_dim_t* v1, int v2) quote(call,"_res = ap_abstract0_fold(man,false,a,v1,v2);") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_expand_with(ap_manager_ptr man, ap_abstract0_ptr a, ap_dim_t v1, int v2) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_expand(man,true,a,v1,v2); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract0_fold_with(ap_manager_ptr man, ap_abstract0_ptr a, [size_is(v2)]ap_dim_t* v1, int v2) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_fold(man,true,a,v1,v2); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Widening} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** Widening *)") ap_abstract0_ptr ap_abstract0_widening(ap_manager_ptr man, ap_abstract0_ptr a1, ap_abstract0_ptr a2) quote(dealloc,"I0_CHECK_EXC(man)"); ap_abstract0_ptr ap_abstract0_widening_threshold(ap_manager_ptr man, ap_abstract0_ptr a1, ap_abstract0_ptr a2, [ref]struct ap_lincons0_array_t* v) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Closure operation} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** Closure: transform strict constraints into non-strict ones.*)") ap_abstract0_ptr ap_abstract0_closure(ap_manager_ptr man, ap_abstract0_ptr a) quote(call,"_res = ap_abstract0_closure(man,false,a);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Side-effect version *)") void ap_abstract0_closure_with(ap_manager_ptr man, ap_abstract0_ptr a) quote(call,"{\n\ ap_abstract0_t* res = ap_abstract0_closure(man,true,a); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(** {2 Additional operations} *)") quote(MLMLI,"(* ********************************************************************** *)") quote(MLI,"\n\ val of_lincons_array : 'a Manager.t -> int -> int -> Lincons0.t array -> 'a t\n\ val of_tcons_array : 'a Manager.t -> int -> int -> Tcons0.t array -> 'a t\n\ (** Abstract a conjunction of constraints *)\n\ \n\ val assign_linexpr : 'a Manager.t -> 'a t -> Dim.t -> Linexpr0.t -> 'a t option -> 'a t\n\ val substitute_linexpr : 'a Manager.t -> 'a t -> Dim.t -> Linexpr0.t -> 'a t option -> 'a t\n\ val assign_texpr : 'a Manager.t -> 'a t -> Dim.t -> Texpr0.t -> 'a t option -> 'a t\n\ val substitute_texpr : 'a Manager.t -> 'a t -> Dim.t -> Texpr0.t -> 'a t option -> 'a t\n\ (** Assignement/Substitution of a single dimension by a single expression *)\n\ \n\ val assign_linexpr_with : 'a Manager.t -> 'a t -> Dim.t -> Linexpr0.t -> 'a t option -> unit\n\ val substitute_linexpr_with : 'a Manager.t -> 'a t -> Dim.t -> Linexpr0.t -> 'a t option -> unit\n\ val assign_texpr_with : 'a Manager.t -> 'a t -> Dim.t -> Texpr0.t -> 'a t option -> unit\n\ val substitute_texpr_with : 'a Manager.t -> 'a t -> Dim.t -> Texpr0.t -> 'a t option -> unit\n\ (** Side-effect version of the previous functions *)\n\ \n\ ") quote(ML,"\n\ let of_lincons_array man intdim realdim array =\n\ let res = top man intdim realdim in\n\ meet_lincons_array_with man res array;\n\ res\n\ let of_tcons_array man intdim realdim array =\n\ let res = top man intdim realdim in\n\ meet_tcons_array_with man res array;\n\ res\n\ let assign_linexpr man abs dim expr odest =\n\ assign_linexpr_array man abs [|dim|] [|expr|] odest\n\ let assign_texpr man abs dim expr odest =\n\ assign_texpr_array man abs [|dim|] [|expr|] odest\n\ let substitute_linexpr man abs dim expr odest =\n\ substitute_linexpr_array man abs [|dim|] [|expr|] odest\n\ let substitute_texpr man abs dim expr odest =\n\ substitute_texpr_array man abs [|dim|] [|expr|] odest\n\ let assign_linexpr_with man abs dim expr odest =\n\ assign_linexpr_array_with man abs [|dim|] [|expr|] odest\n\ let assign_texpr_with man abs dim expr odest =\n\ assign_texpr_array_with man abs [|dim|] [|expr|] odest\n\ let substitute_linexpr_with man abs dim expr odest =\n\ substitute_linexpr_array_with man abs [|dim|] [|expr|] odest\n\ let substitute_texpr_with man abs dim expr odest =\n\ substitute_texpr_array_with man abs [|dim|] [|expr|] odest\n\ ") quote(ML,"\n\ let print_array\n\ ?(first=(\"[|@[\":(unit,Format.formatter,unit) format))\n\ ?(sep = (\";@ \":(unit,Format.formatter,unit) format))\n\ ?(last = (\"@]|]\":(unit,Format.formatter,unit) format))\n\ (print_elt: Format.formatter -> 'a -> unit)\n\ (fmt:Format.formatter)\n\ (array: 'a array)\n\ : unit\n\ =\n\ if array=[||] then begin\n\ Format.fprintf fmt first;\n\ Format.fprintf fmt last;\n\ end\n\ else begin\n\ Format.fprintf fmt first;\n\ let first = ref true in\n\ Array.iter\n\ (begin fun e ->\n\ if !first then first := false else Format.fprintf fmt sep;\n\ print_elt fmt e\n\ end)\n\ array\n\ ;\n\ Format.fprintf fmt last;\n\ end\n\ \n\ let print assoc fmt a =\n\ let man = manager a in\n\ if is_bottom man a then\n \ Format.pp_print_string fmt \"bottom\"\n\ else if is_top man a then\n\ Format.pp_print_string fmt \"top\"\n\ else begin\n\ let tab = to_lincons_array man a in\n\ print_array (Lincons0.print assoc) fmt tab;\n\ end\n\ ") quote(MLI,"\n(** General use *)\n\ val print_array :\n\ ?first:(unit, Format.formatter, unit) format ->\n\ ?sep:(unit, Format.formatter, unit) format ->\n\ ?last:(unit, Format.formatter, unit) format ->\n\ (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a array -> unit\n\ ") apron-dist-0.9.10/apron/mlapronidl/texpr0.idl0000640014525101416610000003074211247456650020761 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(MLI,"(** APRON tree expressions of level 0 *)\n") quote(C, "\n\ #include \n\ #include \"ap_texpr0.h\"\n\ #include \"apron_caml.h\"\n\ \n\ value camlidl_texpr0_ap_texpr0_to_expr_c2ml(ap_texpr0_t* expr, camlidl_ctx _ctx)\n\ {\n\ value _v_res;\n\ \n\ switch(expr->discr){\n\ case AP_TEXPR_CST:\n\ {\n\ value v0 = Val_unit;\n\ Begin_root(v0);\n\ v0 = camlidl_c2ml_coeff_struct_ap_coeff_t(&expr->val.cst, _ctx);\n\ _v_res = caml_alloc_small(1,0);\n\ Field(_v_res,0) = v0;\n\ End_roots();\n\ }\n\ break;\n\ case AP_TEXPR_DIM:\n\ _v_res = caml_alloc_small(1,1);\n\ Field(_v_res,0) = Val_int(expr->val.dim);\n\ break;\n\ case AP_TEXPR_NODE:\n\ {\n\ value v0,v1,v2,v3,v4;\n\ v0 = v1 = v2 = v3 = v4 = Val_unit;\n\ Begin_roots5(v0,v1,v2,v3,v4);\n\ ap_texpr0_node_t* node = expr->val.node;\n\ v1 = camlidl_texpr0_ap_texpr0_to_expr_c2ml(node->exprA,_ctx);\n\ v3 = camlidl_apron_texpr_rtype_t_c2ml(&node->type);\n\ v4 = camlidl_apron_texpr_rdir_t_c2ml(&node->dir);\n\ if (ap_texpr_is_unop(node->op)){\n\ v0 = camlidl_apron_texpr_unop_t_c2ml(&node->op);\n\ _v_res = caml_alloc_small(4,2);\n\ Field(_v_res,0) = v0;\n\ Field(_v_res,1) = v1;\n\ Field(_v_res,2) = v3;\n\ Field(_v_res,3) = v4;\n\ }\n\ else {\n\ v0 = camlidl_apron_texpr_binop_t_c2ml(&node->op);\n\ v2 = camlidl_texpr0_ap_texpr0_to_expr_c2ml(node->exprB,_ctx);\n\ _v_res = caml_alloc_small(5,3);\n\ Field(_v_res,0) = v0;\n\ Field(_v_res,1) = v1;\n\ Field(_v_res,2) = v2;\n\ Field(_v_res,3) = v3;\n\ Field(_v_res,4) = v4;\n\ }\n\ End_roots();\n\ }\n\ break;\n\ default:\n\ abort();\n\ }\n\ return _v_res;\n\ }\n\ value camlidl_texpr0_ap_texpr0_to_expr(value _v_texpr)\n\ {\n\ CAMLparam1(_v_texpr);\n\ CAMLlocal1(_v_res);\n\ ap_texpr0_t* expr;\n\ \n\ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL };\n\ camlidl_ctx _ctx = &_ctxs;\n\ \n\ camlidl_apron_texpr0_ptr_ml2c(_v_texpr,&expr);\n\ _v_res = camlidl_texpr0_ap_texpr0_to_expr_c2ml(expr,_ctx);\n\ camlidl_free(_ctx);\n\ \n\ CAMLreturn(_v_res);\n\ }\n\ \n\ void camlidl_texpr0_ap_texpr0_of_expr_ml2c(value v, ap_texpr0_t** res, camlidl_ctx _ctx)\n\ {\n\ ap_texpr0_t* texpr;\n\ ap_texpr0_node_t* node;\n\ ap_coeff_t coeff;\n\ value v0,v1,v2,v3,v4;\n\ \n\ texpr = malloc(sizeof(ap_texpr0_t));\n \ \n\ assert (Is_block(v));\n\ switch (Tag_val(v)){\n\ case 0: /* Constant */\n\ assert(Wosize_val(v)==1);\n\ v0 = Field(v,0);\n\ texpr->discr = AP_TEXPR_CST;\n\ camlidl_ml2c_coeff_struct_ap_coeff_t(v0,&coeff,_ctx);\n\ ap_coeff_init_set(&texpr->val.cst,&coeff);\n\ break;\n\ case 1: /* Dimension */\n\ assert(Wosize_val(v)==1);\n\ v0 = Field(v,0);\n\ texpr->discr = AP_TEXPR_DIM;\n\ texpr->val.dim = Int_val(v0);\n\ break;\n\ case 2: /* Unary node */\n\ v0 = Field(v,0);\n\ v1 = Field(v,1);\n\ v2 = Field(v,2);\n\ v3 = Field(v,3);\n\ \n\ node = malloc(sizeof(ap_texpr0_node_t));\n \ camlidl_apron_texpr_unop_t_ml2c (v0,&node->op);\n\ camlidl_texpr0_ap_texpr0_of_expr_ml2c(v1,&node->exprA,_ctx);\n \ camlidl_apron_texpr_rtype_t_ml2c (v2,&node->type);\n\ camlidl_apron_texpr_rdir_t_ml2c (v3,&node->dir);\n\ node->exprB = NULL;\n\ texpr->discr = AP_TEXPR_NODE;\n\ texpr->val.node = node;\n\ break;\n\ case 3: /* Binary node */\n\ v0 = Field(v,0);\n\ v1 = Field(v,1);\n\ v2 = Field(v,2);\n\ v3 = Field(v,3);\n\ v4 = Field(v,4);\n\ node = malloc(sizeof(ap_texpr0_node_t));\n\ camlidl_apron_texpr_binop_t_ml2c (v0,&node->op);\n\ camlidl_texpr0_ap_texpr0_of_expr_ml2c(v1,&node->exprA,_ctx);\n \ camlidl_texpr0_ap_texpr0_of_expr_ml2c(v2,&node->exprB,_ctx);\n \ camlidl_apron_texpr_rtype_t_ml2c (v3,&node->type);\n\ camlidl_apron_texpr_rdir_t_ml2c (v4,&node->dir);\n\ texpr->discr = AP_TEXPR_NODE;\n\ texpr->val.node = node;\n\ break;\n\ default:\n\ assert(false);\n\ }\n\ *res = texpr;\n\ }\n\ value camlidl_texpr0_ap_texpr0_of_expr(value _v_expr)\n\ {\n\ CAMLparam1(_v_expr);\n\ CAMLlocal1(_v_res);\n\ ap_texpr0_t* res;\n\ \n\ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL };\n\ camlidl_ctx _ctx = &_ctxs;\n\ \n\ camlidl_texpr0_ap_texpr0_of_expr_ml2c(_v_expr,&res,_ctx);\n\ _v_res = camlidl_apron_texpr0_ptr_c2ml(&res);\n\ \n\ camlidl_free(_ctx);\n\ CAMLreturn(_v_res);\n\ }\n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; import "linexpr0.idl"; typedef [abstract, ml2c(camlidl_apron_texpr0_ptr_ml2c), c2ml(camlidl_apron_texpr0_ptr_c2ml)] struct ap_texpr0_ptr* ap_texpr0_ptr; typedef [mltype("\n | Neg\n | Cast\n | Sqrt (** *)\n (** Unary operators *)"), ml2c(camlidl_apron_texpr_unop_t_ml2c), c2ml(camlidl_apron_texpr_unop_t_c2ml)] struct ap_texpr_op_t ap_texpr_unop_t; typedef [mltype("\n | Add\n | Sub\n | Mul\n | Div\n | Mod (** *)\n (** Binary operators *)"), ml2c(camlidl_apron_texpr_binop_t_ml2c), c2ml(camlidl_apron_texpr_binop_t_c2ml)] struct ap_texpr_op_t ap_texpr_binop_t; typedef [mltype("\n | Real\n | Int\n | Single\n | Double\n | Extended\n | Quad (** *)\n (** Destination type for rounding *)"), ml2c(camlidl_apron_texpr_rtype_t_ml2c), c2ml(camlidl_apron_texpr_rtype_t_c2ml)] struct ap_texpr_rtype_t ap_texpr_rtype_t; typedef [mltype("\n | Near\n | Zero\n | Up\n | Down\n | Rnd (** *)\n (** Rounding direction *)"), ml2c(camlidl_apron_texpr_rdir_t_ml2c), c2ml(camlidl_apron_texpr_rdir_t_c2ml)] struct ap_texpr_rdir_t ap_texpr_rdir_t; quote(MLMLI,"\n\ (** User type for tree expressions *) \n\ type expr = \n\ | Cst of Coeff.t \n\ | Dim of Dim.t \n\ | Unop of unop * expr * typ * round \n\ | Binop of binop * expr * expr * typ * round \n\ ") quote(MLMLI,"(** {2 Constructors and Destructor} *)") quote(MLI,"(** General constructor (actually the most efficient *)") quote(MLMLI,"external of_expr : expr -> t = \"camlidl_texpr0_ap_texpr0_of_expr\"\n") quote(MLI,"(** Copy *)") ap_texpr0_ptr ap_texpr0_copy(const ap_texpr0_ptr a); quote(MLI,"(** Conversion *)") ap_texpr0_ptr ap_texpr0_of_linexpr(ap_linexpr0_ptr e) quote(call,"_res = ap_texpr0_from_linexpr0(e);"); quote(MLI,"(** General destructor *)") quote(MLMLI,"external to_expr : t -> expr = \"camlidl_texpr0_ap_texpr0_to_expr\"\n") quote(MLI,"\n(** {3 Incremental constructors} *)\n") ap_texpr0_ptr ap_texpr0_cst([ref]struct ap_coeff_t* coeff); ap_texpr0_ptr ap_texpr0_dim(ap_dim_t dim); ap_texpr0_ptr ap_texpr0_unop(ap_texpr_unop_t op, ap_texpr0_ptr expr, ap_texpr_rtype_t type, ap_texpr_rdir_t dir) quote(call,"_res = ap_texpr0_unop(op,ap_texpr0_copy(expr),type,dir);"); ap_texpr0_ptr ap_texpr0_binop(ap_texpr_binop_t op, ap_texpr_rtype_t type, ap_texpr_rdir_t dir, ap_texpr0_ptr exprA, ap_texpr0_ptr exprB) quote(call,"_res = ap_texpr0_binop(op,ap_texpr0_copy(exprA),ap_texpr0_copy(exprB),type,dir);"); /* quote(MLMLI,"external dims : t -> Dim.t array = \"camlidl_texpr0_ap_texpr0_dims\"") quote(C,"\n\ value camlidl_texpr0_ap_texpr0_dims(value _v_texpr)\n\ {\n\ CAMLparam1(_v_texpr);\n\ CAMLlocal1(_v_res);\n\ ap_texpr0_t* expr;\n\ ap_dim_t* dims;\n\ size_t size,i;\n\ \n\ camlidl_apron_texpr0_ptr_ml2c(_v_texpr,&expr);\n\ dims = ap_texpr0_dimlist(expr);\n\ size=0;\n\ while (dims[size] != AP_DIM_MAX) size++;\n\ _v_res = camlidl_alloc(size,0);\n\ for (i=0; i string\n\ val string_of_binop : binop -> string\n\ val string_of_typ : typ -> string\n\ val string_of_round : round -> string\n\ val print_unop : Format.formatter -> unop -> unit\n\ val print_binop : Format.formatter -> binop -> unit\n\ val print_typ : Format.formatter -> typ -> unit\n\ val print_round : Format.formatter -> round -> unit\n\ val print_expr : (Dim.t -> string) -> Format.formatter -> expr -> unit\n\ (** Print a tree expression, using a function converting from dimensions to names *)\n\ val print : (Dim.t -> string) -> Format.formatter -> t -> unit\n\ (** Print an abstract tree expression, using a function converting from dimensions to names *)\n\ ") quote(ML,"\n\ let string_of_unop = function\n\ | Neg -> \"Neg\"\n\ | Cast -> \"Cast\"\n\ | Sqrt -> \"Sqrt\"\n\ let string_of_binop = function\n\ | Add -> \"Add\"\n\ | Sub -> \"Sub\"\n\ | Mul -> \"Mul\"\n\ | Div -> \"Div\"\n\ | Mod -> \"Mod\"\n\ let string_of_typ = function\n\ | Real -> \"Real\"\n\ | Int -> \"Int\"\n\ | Single -> \"Single\"\n\ | Double -> \"Double\"\n\ | Extended -> \"Extended\"\n\ | Quad-> \"Quad\"\n\ let string_of_round = function\n\ | Near -> \"Near\"\n\ | Zero -> \"Zero\"\n\ | Up -> \"Up\"\n\ | Down -> \"Down\"\n\ | Rnd -> \"Rnd\"\n\ let print_typ fmt x = Format.pp_print_string fmt (string_of_typ x)\n\ let print_round fmt x = Format.pp_print_string fmt (string_of_round x)\n\ let print_unop fmt x = Format.pp_print_string fmt (string_of_unop x)\n\ let print_binop fmt x = Format.pp_print_string fmt (string_of_binop x)\n\ \n\ \n\ let print_string_of_unop = function\n\ | Neg -> \"-\"\n\ | Cast -> \"cast\"\n\ | Sqrt -> \"sqrt\"\n\ let print_string_of_binop = function\n\ | Add -> \"+\"\n\ | Sub -> \"-\"\n\ | Mul -> \"*\"\n\ | Div -> \"/\"\n\ | Mod -> \"%\"\n\ let print_string_of_typ = function\n\ | Real -> \"\"\n\ | Int -> \"i\"\n\ | Single -> \"f\"\n\ | Double -> \"d\"\n\ | Extended -> \"l\"\n\ | Quad-> \"q\"\n\ let print_string_of_round = function\n\ | Near -> \"n\"\n\ | Zero -> \"0\"\n\ | Up -> \"+oo\"\n\ | Down -> \"-oo\"\n\ | Rnd -> \"?\"\n\ let print_sprint_unop op typ round =\n\ if op=Neg then\n\ Format.sprintf \"%s\" (print_string_of_unop op)\n\ else begin\n\ if typ=Real then\n\ Format.sprintf \"%s \" (print_string_of_unop op)\n\ else\n\ Format.sprintf \"%s_%s,%s \" (print_string_of_unop op)\n\ (print_string_of_typ typ) (print_string_of_round round)\n\ end\n\ let print_sprint_binop op typ round =\n\ if typ=Real then\n\ Format.sprintf \"%s\" (print_string_of_binop op)\n\ else\n\ Format.sprintf \"%s_%s,%s\" (print_string_of_binop op)\n\ (print_string_of_typ typ) (print_string_of_round round)\n\ let print_precedence_of_unop = function\n\ | Neg -> 3\n\ | Cast | Sqrt -> 4\n\ let print_precedence_of_binop = function\n\ | Add | Sub -> 1\n\ | Mul | Div | Mod -> 2\n\ \n\ \n\ let rec print_expr (string_of_dim:Dim.t -> string) fmt expr =\n\ let precedence_of_expr = function\n\ | Cst _\n\ | Dim _ -> 5\n\ | Unop(op,_,_,_) -> print_precedence_of_unop op\n\ | Binop(op,_,_,_,_) -> print_precedence_of_binop op\n\ in\n\ match expr with\n\ | Cst x -> Coeff.print fmt x\n\ | Dim x -> Format.pp_print_string fmt (string_of_dim x)\n\ | Unop(op,e,typ,round) ->\n\ let prec = print_precedence_of_unop op in\n\ let prec1 = precedence_of_expr e in\n\ let par = prec1<=prec in\n\ Format.fprintf fmt \"%s%s%a%s\"\n\ (print_sprint_unop op typ round)\n\ (if par then \"(\" else \"\")\n\ (print_expr string_of_dim) e\n\ (if par then \")\" else \"\")\n\ | Binop(op,e1,e2,typ,round) ->\n\ let prec = print_precedence_of_binop op in\n\ let prec1 = precedence_of_expr e1 in\n\ let prec2 = precedence_of_expr e2 in\n\ let par1 = prec1 typ -> round -> string\n\ val print_sprint_binop : binop -> typ -> round -> string\n\ val print_precedence_of_unop : unop -> int\n\ val print_precedence_of_binop : binop -> int\n\ ") apron-dist-0.9.10/apron/mlapronidl/texpr1.mli0000640014525101416610000000542311252216516020760 0ustar bjeannetpopart(* File generated from texpr1.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = { mutable texpr0: Texpr0.t; mutable env: Environment.t; } (** APRON Expressions of level 1 *) (** Unary operators *) type unop = Texpr0.unop = | Neg | Cast | Sqrt (** Binary operators *) type binop = Texpr0.binop = | Add | Sub | Mul | Div | Mod (** Destination type for rounding *) type typ = Texpr0.typ = | Real | Int | Single | Double | Extended | Quad (** Rounding direction *) type round = Texpr0.round = | Near | Zero | Up | Down | Rnd (** User type for tree expressions *) type expr = | Cst of Coeff.t | Var of Var.t | Unop of unop * expr * typ * round | Binop of binop * expr * expr * typ * round (** {2 Constructors and Destructor} *) (** General constructor (actually the most efficient) *) val of_expr : Environment.t -> expr -> t (** Copy *) val copy : t -> t (** Conversion *) val of_linexpr : Linexpr1.t -> t (** General destructor *) val to_expr : t -> expr (** {3 Incremental constructors} *) external cst : Environment.t -> Coeff.t -> t = "camlidl_texpr1_ap_texpr1_cst" external var : Environment.t -> Var.t -> t = "camlidl_texpr1_ap_texpr1_var" external unop : Texpr0.unop -> t -> Texpr0.typ -> Texpr0.round -> t = "camlidl_texpr1_ap_texpr1_unop" external binop : Texpr0.binop -> t -> t -> Texpr0.typ -> Texpr0.round -> t = "camlidl_texpr1_ap_texpr1_binop" (** {2 Tests} *) val is_interval_cst : t -> bool val is_interval_linear : t -> bool val is_interval_polynomial : t -> bool val is_interval_polyfrac : t -> bool val is_scalar : t -> bool (** {2 Operations} *) (** Change the environment of the expression for a super-environement. Raise [Failure] if it is not the case *) external extend_environment : t -> Environment.t -> t = "camlidl_texpr1_ap_texpr1_extend_environment" (** Side-effet version of the previous function *) external extend_environment_with : t -> Environment.t -> unit = "camlidl_texpr1_ap_texpr1_extend_environment_with" (** Get the underlying expression of level 0 (which is not a copy). *) val get_texpr0: t -> Texpr0.t (** Get the environement of the expression *) val get_env: t -> Environment.t (** {2 Printing} *) val string_of_unop : unop -> string val string_of_binop : binop -> string val string_of_typ : typ -> string val string_of_round : round -> string val print_unop : Format.formatter -> unop -> unit val print_binop : Format.formatter -> binop -> unit val print_typ : Format.formatter -> typ -> unit val print_round : Format.formatter -> round -> unit val print_expr : Format.formatter -> expr -> unit (** Print a tree expression *) val print : Format.formatter -> t -> unit (** Print an abstract tree expression *) apron-dist-0.9.10/apron/mlapronidl/dim.mli0000640014525101416610000000472711252216515020313 0ustar bjeannetpopart(* File generated from dim.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = int and change = { dim : int array; intdim : int; realdim : int; } and change2 = { add: change option; remove: change option; } and perm = int array and dimension = { intd: int; reald: int; } (** APRON Dimensions and related types *) (** {ul {- [t=int] is the type of dimensions.} {- The semantics of an object [(change:change)] is the following one: {ul {- [change.intdim] and [change.realdim] indicate the number of integer and real dimensions to add or to remove} {- In case of the addition of dimensions, [change.dim[i]=k] means: add one dimension at dimension k and shift the already existing dimensions greater than or equal to k one step on the right (or increment them). if k is equal to the size of the vector, then it means: add a dimension at the end. Repetition are allowed, and means that one inserts more than one dimensions. Example: [add_dimensions [i0 i1 r0 r1] { dim=[0 1 2 2 4]; intdim=3; realdim=1 }] returns [0 i0 0 i1 0 0 r0 r1 0], considered as a vector with 6 integer dimensions and 3 real dimensions.} {- In case of the removal of dimensions, dimchange.dim[i]=k means: remove the dimension k and shift the dimensions greater than k one step on the left (or decrement them). Repetitions are meaningless (and are not correct specification) Example: [remove_dimensions [i0 i1 i2 r0 r1 r2] { dim=[0 2 4]; intdim=2; realdim=1 }] returns [i1 r0 r2], considered as a vector with 1 integer dimensions and 2 real dimensions. }}} {- The semantics of an object [(change2:change2)] is the combination of the two following transformations: {ul {- [change2.add] indicates an optional addition of dimensions.} {- [change2.remove] indicates an optional removal of dimensions.} }} {- [perm] defines a permutation.} {- [dimension] defines the dimensionality of an abstract value (number of integer and real dimensions). }} *) (** Assuming a transformation for add_dimensions, invert it in-place to obtain the inverse transformation using remove_dimensions *) val change_add_invert : change -> unit (** [perm_compose perm1 perm2] composes the 2 permutations perm1 and perm2 (in this order). The sizes of permutations are supposed to be equal. *) val perm_compose : perm -> perm -> perm (** Invert a permutation *) val perm_invert : perm -> perm apron-dist-0.9.10/apron/mlapronidl/manager.mli0000640014525101416610000000753311252216515021152 0ustar bjeannetpopart(* File generated from manager.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type funid = | Funid_unknown | Funid_copy | Funid_free | Funid_asize | Funid_minimize | Funid_canonicalize | Funid_hash | Funid_approximate | Funid_fprint | Funid_fprintdiff | Funid_fdump | Funid_serialize_raw | Funid_deserialize_raw | Funid_bottom | Funid_top | Funid_of_box | Funid_dimension | Funid_is_bottom | Funid_is_top | Funid_is_leq | Funid_is_eq | Funid_is_dimension_unconstrained | Funid_sat_interval | Funid_sat_lincons | Funid_sat_tcons | Funid_bound_dimension | Funid_bound_linexpr | Funid_bound_texpr | Funid_to_box | Funid_to_lincons_array | Funid_to_tcons_array | Funid_to_generator_array | Funid_meet | Funid_meet_array | Funid_meet_lincons_array | Funid_meet_tcons_array | Funid_join | Funid_join_array | Funid_add_ray_array | Funid_assign_linexpr_array | Funid_substitute_linexpr_array | Funid_assign_texpr_array | Funid_substitute_texpr_array | Funid_add_dimensions | Funid_remove_dimensions | Funid_permute_dimensions | Funid_forget_array | Funid_expand | Funid_fold | Funid_widening | Funid_closure | Funid_change_environment | Funid_rename_array and funopt = { algorithm: int; timeout: int; max_object_size: int; flag_exact_wanted: bool; flag_best_wanted: bool; } and exc = | Exc_none | Exc_timeout | Exc_out_of_space | Exc_overflow | Exc_invalid_argument | Exc_not_implemented and exclog = { exn: exc; funid: funid; msg: string; } and 'a t (** APRON Managers *) (** The type parameter ['a] allows to distinguish managers allocated by different underlying abstract domains. *) (** Concerning the other types, - [funid] defines identifiers for the generic function working on abstrat values; - [funopt] defines the options associated to generic functions; - [exc] defines the different kind of exceptions; - [exclog] defines the exceptions raised by APRON functions. *) (** Get the name of the effective library which allocated the manager *) external get_library : 'a t -> string = "camlidl_manager_ap_manager_get_library" (** Get the version of the effective library which allocated the manager *) external get_version : 'a t -> string = "camlidl_manager_ap_manager_get_version" (** Return the default options for any function ([0] or [false] for al fields) *) external funopt_make : unit -> funopt = "camlidl_manager_ap_funopt_make" (** Get the options sets for the function. The result is a copy of the internal structure and may be freely modified. [funid] should be different from [Funid_change_environment] and [Funid_rename_array] (no option associated to them). *) external get_funopt : 'a t -> funid -> funopt = "camlidl_manager_ap_manager_get_funopt" (** Set the options for the function. [funid] should be different from [Funid_change_environment] and [Funid_rename_array] (no option associated to them). *) external set_funopt : 'a t -> funid -> funopt -> unit = "camlidl_manager_ap_manager_set_funopt" (** Get the corresponding result flag *) external get_flag_exact : 'a t -> bool = "camlidl_manager_ap_manager_get_flag_exact" (** Get the corresponding result flag *) external get_flag_best : 'a t -> bool = "camlidl_manager_ap_manager_get_flag_best" (** Exception raised by functions of the interface *) exception Error of exclog val string_of_funid: funid -> string val string_of_exc: exc -> string val print_funid: Format.formatter -> funid -> unit val print_funopt: Format.formatter -> funopt -> unit val print_exc: Format.formatter -> exc -> unit val print_exclog: Format.formatter -> exclog -> unit (** Printing functions *) (** Set / get the global manager used for deserialization *) external set_deserialize : 'a t -> unit = "camlidl_manager_ap_manager_set_deserialize" external get_deserialize : unit -> 'a t = "camlidl_manager_ap_manager_get_deserialize" apron-dist-0.9.10/apron/mlapronidl/scalar_caml.c0000640014525101416610000000601311252216514021431 0ustar bjeannetpopart/* File generated from scalar.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #define HAS_MPFR 1 #include #include "ap_coeff.h" #include "gmp_caml.h" #include "apron_caml.h" void camlidl_apron_scalar_ml2c(value v, struct ap_scalar_t* scalar) { value v2 = Field(v,0); scalar->discr = Tag_val(v); switch (scalar->discr) { case 0: /* DOUBLE */ scalar->val.dbl = Double_val(v2); break; case 1: /* MPQ */ scalar->val.mpq = (mpq_ptr)(Data_custom_val(v2)); break; case 2: /* MPFR */ scalar->val.mpfr = (mpfr_ptr)(Data_custom_val(v2)); break; default: caml_failwith("unknown scalar discriminant in camlidl_apron_scalar_ml2c"); } return; } value camlidl_apron_scalar_c2ml(struct ap_scalar_t* scalar) { value v,v2; v2 = Val_unit; Begin_root(v2); switch(scalar->discr){ case AP_SCALAR_DOUBLE: v2 = caml_copy_double(scalar->val.dbl); break; case AP_SCALAR_MPQ: { mpq_t mpq; mpq_ptr mpq_ptr = mpq; mpq_init(mpq); mpq_set(mpq,scalar->val.mpq); v2 = camlidl_mpq_ptr_c2ml(&mpq_ptr); } break; case AP_SCALAR_MPFR: { mpfr_t mpfr; mpfr_ptr mpfr_ptr = mpfr; mpfr_init2(mpfr,mpfr_get_prec(scalar->val.mpfr)); mpfr_set(mpfr,scalar->val.mpfr,GMP_RNDU /* exact */); v2 = camlidl_mpfr_ptr_c2ml(&mpfr_ptr); } break; default: caml_failwith("unknown scalar discriminant in camlidl_apron_scalar_c2ml"); } v = alloc_small(1,scalar->discr); Field(v,0) = v2; End_roots(); return v; } #define camlidl_ml2c_scalar_ap_scalar_t(v,c,ctx) camlidl_apron_scalar_ml2c(v,c) #define camlidl_c2ml_scalar_ap_scalar_t(c,ctx) camlidl_apron_scalar_c2ml(c) void camlidl_ml2c_scalar_ap_scalar_ptr(value _v1, ap_scalar_ptr * _c2, camlidl_ctx _ctx) { (*_c2) = (ap_scalar_t *) camlidl_malloc(sizeof(ap_scalar_t ), _ctx); camlidl_ml2c_scalar_ap_scalar_t(_v1, &*(*_c2), _ctx); } value camlidl_c2ml_scalar_ap_scalar_ptr(ap_scalar_ptr * _c2, camlidl_ctx _ctx) { value _v1; _v1 = camlidl_c2ml_scalar_ap_scalar_t(&*(*_c2), _ctx); return _v1; } void camlidl_ml2c_scalar_struct_ap_scalar_array_t(value _v1, struct ap_scalar_array_t * _c2, camlidl_ctx _ctx) { mlsize_t _c3; mlsize_t _c4; value _v5; _c3 = Wosize_val(_v1); (*_c2).p = camlidl_malloc(_c3 * sizeof(ap_scalar_ptr ), _ctx); for (_c4 = 0; _c4 < _c3; _c4++) { _v5 = Field(_v1, _c4); camlidl_ml2c_scalar_ap_scalar_ptr(_v5, &(*_c2).p[_c4], _ctx); } (*_c2).size = _c3; } value camlidl_c2ml_scalar_struct_ap_scalar_array_t(struct ap_scalar_array_t * _c1, camlidl_ctx _ctx) { value _v2; mlsize_t _c3; value _v4; _v2 = camlidl_alloc((*_c1).size, 0); Begin_root(_v2) for (_c3 = 0; _c3 < (*_c1).size; _c3++) { _v4 = camlidl_c2ml_scalar_ap_scalar_ptr(&(*_c1).p[_c3], _ctx); modify(&Field(_v2, _c3), _v4); } End_roots() return _v2; } apron-dist-0.9.10/apron/mlapronidl/texpr0.ml0000640014525101416610000001121711252216515020603 0ustar bjeannetpopart(* File generated from texpr0.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t and unop = | Neg | Cast | Sqrt (** *) (** Unary operators *) and binop = | Add | Sub | Mul | Div | Mod (** *) (** Binary operators *) and typ = | Real | Int | Single | Double | Extended | Quad (** *) (** Destination type for rounding *) and round = | Near | Zero | Up | Down | Rnd (** *) (** Rounding direction *) (** User type for tree expressions *) type expr = | Cst of Coeff.t | Dim of Dim.t | Unop of unop * expr * typ * round | Binop of binop * expr * expr * typ * round (** {2 Constructors and Destructor} *) external of_expr : expr -> t = "camlidl_texpr0_ap_texpr0_of_expr" external copy : t -> t = "camlidl_texpr0_ap_texpr0_copy" external of_linexpr : Linexpr0.t -> t = "camlidl_texpr0_ap_texpr0_of_linexpr" external to_expr : t -> expr = "camlidl_texpr0_ap_texpr0_to_expr" external cst : Coeff.t -> t = "camlidl_texpr0_ap_texpr0_cst" external dim : Dim.t -> t = "camlidl_texpr0_ap_texpr0_dim" external unop : unop -> t -> typ -> round -> t = "camlidl_texpr0_ap_texpr0_unop" external binop : binop -> typ -> round -> t -> t -> t = "camlidl_texpr0_ap_texpr0_binop" (** {2 Tests} *) external is_interval_cst : t -> bool = "camlidl_texpr0_ap_texpr0_is_interval_cst" external is_interval_linear : t -> bool = "camlidl_texpr0_ap_texpr0_is_interval_linear" external is_interval_polynomial : t -> bool = "camlidl_texpr0_ap_texpr0_is_interval_polynomial" external is_interval_polyfrac : t -> bool = "camlidl_texpr0_ap_texpr0_is_interval_polyfrac" external is_scalar : t -> bool = "camlidl_texpr0_ap_texpr0_is_scalar" (** {2 Printing} *) let string_of_unop = function | Neg -> "Neg" | Cast -> "Cast" | Sqrt -> "Sqrt" let string_of_binop = function | Add -> "Add" | Sub -> "Sub" | Mul -> "Mul" | Div -> "Div" | Mod -> "Mod" let string_of_typ = function | Real -> "Real" | Int -> "Int" | Single -> "Single" | Double -> "Double" | Extended -> "Extended" | Quad-> "Quad" let string_of_round = function | Near -> "Near" | Zero -> "Zero" | Up -> "Up" | Down -> "Down" | Rnd -> "Rnd" let print_typ fmt x = Format.pp_print_string fmt (string_of_typ x) let print_round fmt x = Format.pp_print_string fmt (string_of_round x) let print_unop fmt x = Format.pp_print_string fmt (string_of_unop x) let print_binop fmt x = Format.pp_print_string fmt (string_of_binop x) let print_string_of_unop = function | Neg -> "-" | Cast -> "cast" | Sqrt -> "sqrt" let print_string_of_binop = function | Add -> "+" | Sub -> "-" | Mul -> "*" | Div -> "/" | Mod -> "%" let print_string_of_typ = function | Real -> "" | Int -> "i" | Single -> "f" | Double -> "d" | Extended -> "l" | Quad-> "q" let print_string_of_round = function | Near -> "n" | Zero -> "0" | Up -> "+oo" | Down -> "-oo" | Rnd -> "?" let print_sprint_unop op typ round = if op=Neg then Format.sprintf "%s" (print_string_of_unop op) else begin if typ=Real then Format.sprintf "%s " (print_string_of_unop op) else Format.sprintf "%s_%s,%s " (print_string_of_unop op) (print_string_of_typ typ) (print_string_of_round round) end let print_sprint_binop op typ round = if typ=Real then Format.sprintf "%s" (print_string_of_binop op) else Format.sprintf "%s_%s,%s" (print_string_of_binop op) (print_string_of_typ typ) (print_string_of_round round) let print_precedence_of_unop = function | Neg -> 3 | Cast | Sqrt -> 4 let print_precedence_of_binop = function | Add | Sub -> 1 | Mul | Div | Mod -> 2 let rec print_expr (string_of_dim:Dim.t -> string) fmt expr = let precedence_of_expr = function | Cst _ | Dim _ -> 5 | Unop(op,_,_,_) -> print_precedence_of_unop op | Binop(op,_,_,_,_) -> print_precedence_of_binop op in match expr with | Cst x -> Coeff.print fmt x | Dim x -> Format.pp_print_string fmt (string_of_dim x) | Unop(op,e,typ,round) -> let prec = print_precedence_of_unop op in let prec1 = precedence_of_expr e in let par = prec1<=prec in Format.fprintf fmt "%s%s%a%s" (print_sprint_unop op typ round) (if par then "(" else "") (print_expr string_of_dim) e (if par then ")" else "") | Binop(op,e1,e2,typ,round) -> let prec = print_precedence_of_binop op in let prec1 = precedence_of_expr e1 in let prec2 = precedence_of_expr e2 in let par1 = prec1 acc | (var,coeff)::l -> let nacc = if Coeff.is_zero coeff then acc else (var,(Coeff.neg coeff))::acc in neg nacc l %} /* \section{Lexems} %======================================================== */ %token TK_EOF %token TK_VERTEX TK_RAY TK_LINE TK_RAYMOD TK_LINEMOD %token TK_SUPEG TK_INFEG TK_SUP TK_INF TK_EG TK_DISEG TK_MOD %token TK_LBRACKET TK_RBRACKET TK_SEMICOLON TK_LPAR TK_RPAR %token <(Texpr1.typ * Texpr1.round)> TK_MUL %token <(Texpr1.typ * Texpr1.round)> TK_ADD %token <(Texpr1.typ * Texpr1.round)> TK_SUB %token <(Texpr1.typ * Texpr1.round)> TK_DIV %token <(Texpr1.typ * Texpr1.round)> TK_MODULO %token <(Texpr1.typ * Texpr1.round)> TK_CAST %token <(Texpr1.typ * Texpr1.round)> TK_SQRT %token TK_MPQF %token TK_FLOAT %token TK_VAR %start lincons generator linexpr tcons texpr %type lincons %type generator %type <(string*Coeff.t) list> linexpr %type tcons %type texpr %% /* \section{Rules} %========================================================= */ lincons: linexpr0 TK_EG linexpr0 TK_EOF { (Lincons0.EQ, neg $1 $3) } | linexpr0 TK_EG linexpr0 TK_MOD scalar0 TK_EOF { (Lincons0.EQMOD($5), neg $1 $3) } | linexpr0 TK_DISEG linexpr0 TK_EOF { failwith "!= not yet supported" } | linexpr0 TK_SUP linexpr0 TK_EOF { (Lincons0.SUP, neg $1 $3) } | linexpr0 TK_SUPEG linexpr0 TK_EOF { (Lincons0.SUPEQ, neg $1 $3) } | linexpr0 TK_INFEG linexpr0 TK_EOF { (Lincons0.SUPEQ, neg $3 $1) } | linexpr0 TK_INF linexpr0 TK_EOF { (Lincons0.SUP, neg $3 $1) } generator: TK_VERTEX linexpr0 TK_EOF { (Generator0.VERTEX,$2) } | TK_RAY linexpr0 TK_EOF { (Generator0.RAY,$2) } | TK_LINE linexpr0 TK_EOF { (Generator0.LINE,$2) } | TK_RAYMOD linexpr0 TK_EOF { (Generator0.RAYMOD,$2) } | TK_LINEMOD linexpr0 TK_EOF { (Generator0.LINEMOD,$2) } linexpr: linexpr0 TK_EOF { $1 } linexpr0: linexpr0 TK_ADD term { $3::$1 } | linexpr0 TK_SUB term { let (var,coeff) = $3 in (var,Coeff.neg coeff)::$1 } | term { [$1] } term: coeff id { ($2,$1) } | coeff TK_MUL id { ($3,$1) } | coeff { ("",$1) } | id { ($1, Coeff.s_of_int 1) } | TK_SUB id { ($2, Coeff.s_of_int (-1)) } tcons: tcons0 TK_EOF { $1 } tcons0: texpr0 TK_EG texpr0 { (Tcons0.EQ, (Texpr1.Binop (Texpr1.Sub,$1,$3,Texpr1.Real,Texpr1.Rnd))) } | texpr0 TK_EG texpr0 TK_MOD scalar0 { (Tcons0.EQMOD($5), (Texpr1.Binop (Texpr1.Sub,$1,$3,Texpr1.Real,Texpr1.Rnd))) } | texpr0 TK_DISEG texpr0 { failwith "!= not yet supported" } | texpr0 TK_SUP texpr0 { (Tcons0.SUP, (Texpr1.Binop (Texpr1.Sub,$1,$3,Texpr1.Real,Texpr1.Rnd))) } | texpr0 TK_SUPEG texpr0 { (Tcons0.SUPEQ, (Texpr1.Binop (Texpr1.Sub,$1,$3,Texpr1.Real,Texpr1.Rnd))) } | texpr0 TK_INFEG texpr0 { (Tcons0.SUPEQ, (Texpr1.Binop (Texpr1.Sub,$3,$1,Texpr1.Real,Texpr1.Rnd))) } | texpr0 TK_INF texpr0 { (Tcons0.SUP, (Texpr1.Binop (Texpr1.Sub,$3,$1,Texpr1.Real,Texpr1.Rnd))) } texpr: texpr0 TK_EOF { $1 } texpr0: texpr0 TK_ADD texpr0_1 { let (t,r) = $2 in Texpr1.Binop(Texpr1.Add,$1,$3,t,r) } | texpr0 TK_SUB texpr0_1 { let (t,r) = $2 in Texpr1.Binop(Texpr1.Sub,$1,$3,t,r) } | texpr0_1 { $1 } texpr0_1: texpr0_1 TK_MUL texpr0_2 { let (t,r) = $2 in Texpr1.Binop(Texpr1.Mul,$1,$3,t,r) } | texpr0_1 TK_DIV texpr0_2 { let (t,r) = $2 in Texpr1.Binop(Texpr1.Div,$1,$3,t,r) } | texpr0_1 TK_MODULO texpr0_2 { let (t,r) = $2 in Texpr1.Binop(Texpr1.Div,$1,$3,t,r) } | texpr0_2 { $1 } texpr0_2: TK_SUB texpr0_2 { let (t,r) = $1 in Texpr1.Unop(Texpr1.Neg,$2,t,r) } | texpr0_3 { $1 } texpr0_3: TK_CAST texpr0_3 { let (t,r) = $1 in Texpr1.Unop(Texpr1.Cast,$2,t,r) } | TK_SQRT texpr0_3 { let (t,r) = $1 in Texpr1.Unop(Texpr1.Sqrt,$2,t,r) } | TK_LPAR texpr0 TK_RPAR { $2 } | coeff0 { Texpr1.Cst($1) } | id { Texpr1.Var(Var.of_string $1) } id: TK_VAR { $1 } scalar0: TK_MPQF { Scalar.Mpqf($1) } | TK_FLOAT { Scalar.Float($1) } scalar: scalar0 { $1 } | TK_SUB scalar0 { Scalar.neg $2 } coeff0: scalar0 { Coeff.Scalar $1 } | TK_LBRACKET scalar TK_SEMICOLON scalar TK_RBRACKET { Coeff.Interval(Interval.of_infsup $2 $4) } coeff: coeff0 { $1 } | TK_SUB coeff0 { Coeff.neg $2 } apron-dist-0.9.10/apron/mlapronidl/apron_caml.c0000640014525101416610000002440611122224705021306 0ustar bjeannetpopart/* ********************************************************************** */ /* apron_caml.c */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "apron_caml.h" /* ********************************************************************** */ /* dimchange */ /* ********************************************************************** */ void camlidl_apron_dimchange_ml2c(const value v, ap_dimchange_t* dimchange) { value vintdim,vrealdim,vdim,v2; size_t i,size; vintdim = Field(v,1); vrealdim = Field(v,2); ap_dimchange_init(dimchange,Int_val(vintdim),Int_val(vrealdim)); vdim = Field(v,0); size = Wosize_val(vdim); if (dimchange->intdim+dimchange->realdim>size) caml_failwith("Invalid object of type Linexpr0.dimchange: size of the array smaller than intdim+realdim"); for (i=0;idim[i] = Int_val(v2); } return; } value camlidl_apron_dimchange_c2ml(ap_dimchange_t* dimchange) { value vintdim,vrealdim,vdim,v; size_t i,size; size = dimchange->intdim+dimchange->realdim; vintdim = Val_int(dimchange->intdim); vrealdim = Val_int(dimchange->realdim); vdim = caml_alloc(size,0); Begin_root(vdim) for (i=0;idim[i]); Store_field(vdim,i,v); } End_roots() v = caml_alloc_small(3,0); Field(v,1) = vintdim; Field(v,2) = vrealdim; Field(v,0) = vdim; return v; } /* ********************************************************************** */ /* linexpr0 */ /* ********************************************************************** */ static void camlidl_apron_linexpr0_ptr_finalize(value v) { ap_linexpr0_t* p = *(ap_linexpr0_ptr *) Data_custom_val(v); ap_linexpr0_free(p); } static long camlidl_apron_linexpr0_ptr_hash(value v) { ap_linexpr0_t* p = *(ap_linexpr0_ptr *) Data_custom_val(v); return ap_linexpr0_hash(p); } static int camlidl_apron_linexpr0_ptr_compare(value v1, value v2) { ap_linexpr0_t* p1 = *(ap_linexpr0_ptr *) Data_custom_val(v1); ap_linexpr0_t* p2 = *(ap_linexpr0_ptr *) Data_custom_val(v2); return ap_linexpr0_compare(p1,p2); } struct custom_operations camlidl_apron_custom_linexpr0_ptr = { "apl0", camlidl_apron_linexpr0_ptr_finalize, camlidl_apron_linexpr0_ptr_compare, camlidl_apron_linexpr0_ptr_hash, custom_serialize_default, custom_deserialize_default }; /* ********************************************************************** */ /* texpr0 */ /* ********************************************************************** */ static void camlidl_apron_texpr0_ptr_finalize(value v) { ap_texpr0_t* p = *(ap_texpr0_ptr *) Data_custom_val(v); ap_texpr0_free(p); } static long camlidl_apron_texpr0_ptr_hash(value v) { ap_texpr0_t* p = *(ap_texpr0_ptr *) Data_custom_val(v); return ap_texpr0_hash(p); } static int camlidl_apron_texpr0_ptr_compare(value v1, value v2) { ap_texpr0_t* p1 = *(ap_texpr0_ptr *) Data_custom_val(v1); ap_texpr0_t* p2 = *(ap_texpr0_ptr *) Data_custom_val(v2); return ap_texpr0_equal(p1,p2) ? 0 : (p1library==p2->library) ? 0 : ((p1 of manager.ml has not been executed: this is not normal\n"); abort(); } value v = camlidl_c2ml_manager_struct_ap_exclog_t(man->result.exclog,NULL); caml_raise_with_arg(*p,v); } /* ********************************************************************** */ /* abstract0 */ /* ********************************************************************** */ mlsize_t camlidl_apron_heap = 1 << 20; static void camlidl_apron_abstract0_ptr_finalize(value v) { ap_abstract0_ptr* p = (ap_abstract0_ptr *) Data_custom_val(v); ap_abstract0_t* a = *p; ap_abstract0_free(a->man,a); } static long camlidl_apron_abstract0_ptr_hash(value v) { ap_abstract0_ptr* p = (ap_abstract0_ptr *) Data_custom_val(v); ap_abstract0_t* a = *p; long res = ap_abstract0_hash(a->man,a); if (a->man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(a->man,NULL); return res; } static int camlidl_apron_abstract0_ptr_compare(value v1, value v2) { ap_abstract0_ptr* p1 = (ap_abstract0_ptr *) Data_custom_val(v1); ap_abstract0_ptr* p2 = (ap_abstract0_ptr *) Data_custom_val(v2); ap_abstract0_t* a1 = *p1; ap_abstract0_t* a2 = *p2; ap_dimension_t dim1,dim2; int res; if (v1==v2 || p1==p2 || a1==a2) res=0; else { dim1 = ap_abstract0_dimension(a1->man,a1); dim2 = ap_abstract0_dimension(a2->man,a2); res = dim1.intdim-dim2.intdim; if (!res){ res = dim1.realdim-dim2.realdim; if (!res){ if (ap_abstract0_is_eq(a1->man,a1,a2)) res=0; else res = a1 > a2 ? 1 : (-1); if (a1->man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(a1->man,NULL); } } } return res; } /* global manager used for deserialization */ static ap_manager_ptr deserialize_man = NULL; void ap_manager_set_deserialize(ap_manager_ptr man) { deserialize_man = man; } ap_manager_ptr ap_manager_get_deserialize(void) { return deserialize_man; } static void camlidl_apron_abstract0_serialize(value v, unsigned long * w32, unsigned long * w64) { ap_abstract0_ptr* p = (ap_abstract0_ptr *) Data_custom_val(v); ap_abstract0_t* a = *p; ap_membuf_t buf = ap_abstract0_serialize_raw(a->man,a); serialize_int_8(buf.size); serialize_block_1(buf.ptr,buf.size); *w32 = 4; *w64 = 8; } static unsigned long camlidl_apron_abstract0_deserialize(void * dst) { if (deserialize_man) { size_t size = deserialize_uint_8(), realsize; void* data; data = malloc(size); assert(data); deserialize_block_1(data,size); *((ap_abstract0_ptr*)dst) = ap_abstract0_deserialize_raw(deserialize_man,data,&realsize); free(data); } else caml_failwith("you must call Apron.Manager.set_deserialize before deserializing abstract elements."); return sizeof(ap_abstract0_ptr); } struct custom_operations camlidl_apron_custom_abstract0_ptr = { "apa0", camlidl_apron_abstract0_ptr_finalize, camlidl_apron_abstract0_ptr_compare, camlidl_apron_abstract0_ptr_hash, camlidl_apron_abstract0_serialize, camlidl_apron_abstract0_deserialize }; /* ********************************************************************** */ /* variable */ /* ********************************************************************** */ static struct ap_var_operations_t camlidl_apron_var_ptr_operations = { ap_var_compare, ap_var_hash, ap_var_copy, ap_var_free, ap_var_to_string }; value camlidl_apron_set_var_operations(value v) { CAMLparam1(v); ap_var_operations = &camlidl_apron_var_ptr_operations; CAMLreturn(Val_unit); } static void camlidl_apron_var_ptr_finalize(value v) { apron_var_ptr e = *(apron_var_ptr *) Data_custom_val(v); ap_var_free(e); return; } static long camlidl_apron_var_ptr_hash(value v) { CAMLparam1(v); apron_var_ptr e = *(apron_var_ptr *) Data_custom_val(v); int res = ap_var_hash(e); CAMLreturn(res); } static int camlidl_apron_var_ptr_compare(value v1, value v2) { CAMLparam2(v1,v2); int res; apron_var_ptr e1 = *(apron_var_ptr *) Data_custom_val(v1); apron_var_ptr e2 = *(apron_var_ptr *) Data_custom_val(v2); res = ap_var_compare(e1,e2); CAMLreturn(res); } struct custom_operations camlidl_apron_custom_var_ptr = { "ape", camlidl_apron_var_ptr_finalize, camlidl_apron_var_ptr_compare, camlidl_apron_var_ptr_hash, custom_serialize_default, custom_deserialize_default }; /* ********************************************************************** */ /* environment */ /* ********************************************************************** */ static void camlidl_apron_environment_ptr_finalize(value v) { ap_environment_t* e = *(ap_environment_ptr *) Data_custom_val(v); ap_environment_free(e); return; } static long camlidl_apron_environment_ptr_hash(value v) { CAMLparam1(v); ap_environment_t* e = *(ap_environment_ptr *) Data_custom_val(v); int res = ap_environment_hash(e); CAMLreturn(res); } static int camlidl_apron_environment_ptr_compare(value v1, value v2) { CAMLparam2(v1,v2); int res; ap_environment_t* env1 = *(ap_environment_ptr *) Data_custom_val(v1); ap_environment_t* env2 = *(ap_environment_ptr *) Data_custom_val(v2); res = ap_environment_compare(env1,env2); CAMLreturn(res); } struct custom_operations camlidl_apron_custom_environment_ptr = { "ape", camlidl_apron_environment_ptr_finalize, camlidl_apron_environment_ptr_compare, camlidl_apron_environment_ptr_hash, custom_serialize_default, custom_deserialize_default }; value camlidl_apron_environment_ptr_c2ml(ap_environment_ptr* p) { value v; v = alloc_custom(&camlidl_apron_custom_environment_ptr, sizeof(ap_environment_ptr), 0,1); *((ap_environment_ptr *) Data_custom_val(v)) = *p; return v; } /* ********************************************************************** */ /* init */ /* ********************************************************************** */ value camlidl_apron_init(value dummy) { register_custom_operations(&camlidl_apron_custom_abstract0_ptr); return Val_unit; } apron-dist-0.9.10/apron/mlapronidl/linexpr1.ml0000640014525101416610000000342211252216516021123 0ustar bjeannetpopart(* File generated from linexpr1.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = { mutable linexpr0: Linexpr0.t; mutable env: Environment.t; } external get_coeff : t -> Var.t -> Coeff.t = "camlidl_linexpr1_ap_linexpr1_get_coeff" external set_coeff : t -> Var.t -> Coeff.t -> unit = "camlidl_linexpr1_ap_linexpr1_set_coeff" external extend_environment : t -> Environment.t -> t = "camlidl_linexpr1_ap_linexpr1_extend_environment" external extend_environment_with : t -> Environment.t -> unit = "camlidl_linexpr1_ap_linexpr1_extend_environment_with" external is_integer : t -> bool = "camlidl_linexpr1_ap_linexpr1_is_integer" external is_real : t -> bool = "camlidl_linexpr1_ap_linexpr1_is_real" let make ?(sparse=true) env = { linexpr0 = Linexpr0.make (if sparse then None else Some (Environment.size env)); env = env; } let minimize e = Linexpr0.minimize e.linexpr0 let copy e = { linexpr0 = Linexpr0.copy e.linexpr0; env = e.env; } let get_cst expr = Linexpr0.get_cst expr.linexpr0 let get_linexpr0 expr = expr.linexpr0 let get_env expr = expr.env let set_cst expr cst = Linexpr0.set_cst expr.linexpr0 cst let set_list expr list ocst = List.iter (fun (coeff,var) -> set_coeff expr var coeff ) list; begin match ocst with | Some cst -> set_cst expr cst | None -> () end; () let set_array expr tab ocst = Array.iter (fun (coeff,var) -> set_coeff expr var coeff ) tab; begin match ocst with | Some cst -> set_cst expr cst | None -> () end; () let iter f expr = Linexpr0.iter (begin fun coeff dim -> f coeff (Environment.var_of_dim expr.env dim) end) expr.linexpr0 let print fmt expr = Linexpr0.print (fun dim -> Var.to_string (Environment.var_of_dim expr.env dim)) fmt expr.linexpr0 apron-dist-0.9.10/apron/mlapronidl/macros.m40000640014525101416610000000020211122224705020541 0ustar bjeannetpopartm4_dnl m4_define(`I0_CHECK_EXC', `if ($1->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception($1,_ctx);')m4_dnl m4_dnl apron-dist-0.9.10/apron/mlapronidl/scalar.ml0000640014525101416610000000531711252216514020631 0ustar bjeannetpopart(* File generated from scalar.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = Float of float | Mpqf of Mpqf.t | Mpfrf of Mpfrf.t (** APRON Scalar numbers. See {!Mpqf} for operations on GMP multiprecision rational numbers and {!Mpfr} for operations on MPFR multi-precision floating-point numbers. *) let of_mpq x = Mpqf (Mpqf.of_mpq x) let of_mpqf x = Mpqf x let of_mpfr x = Mpfrf (Mpfrf.of_mpfr x) let of_mpfrf x = Mpfrf x let of_int x = Mpqf(Mpqf.of_int x) let of_frac x y = Mpqf(Mpqf.of_frac x y) let of_float x = Float(x) let of_infty s = if s>0 then Float(Pervasives.infinity) else if s<0 then Float(Pervasives.neg_infinity) else Float(0.0) let is_infty scalar = match scalar with | Mpqf x -> let z = Mpqf.get_den x in if Mpzf.sgn z <> 0 then 0 else begin let z = Mpqf.get_num x in let sgn = Mpzf.sgn z in if sgn > 0 then 1 else if sgn < 0 then -1 else 0 end | Mpfrf x -> if Mpfrf.inf_p x then if Mpfrf.sgn x > 0 then 1 else -1 else 0 | Float x -> if x = Pervasives.infinity then 1 else if x = Pervasives.neg_infinity then -1 else 0 let sgn scalar = match scalar with | Mpqf x -> Mpqf.sgn x | Mpfrf x -> Mpfrf.sgn x | Float x -> if x > 0.0+.0.0 then 1 else if x < -.0.0 then -1 else 0 let to_mpqf = function | Mpqf x -> x | Mpfrf x -> Mpfrf.to_mpqf x | Float x -> Mpqf.of_float x let cmp c1 c2 = let s1 = is_infty c1 in let s2 = is_infty c2 in if s1>s2 then 1 else if s1 Mpqf.cmp x1 x2 | (Mpfrf x1, Mpfrf x2) -> Mpfrf.cmp x1 x2 | (Float x1, Float x2) -> if x1>x2 then 1 else if x1 Mpqf.cmp (to_mpqf x1) (to_mpqf x2) end let equal c1 c2 = let s1 = is_infty c1 in let s2 = is_infty c2 in if s1!=s2 then false else if s1!=0 then true else begin match (c1,c2) with | (Mpqf x1, Mpqf x2) -> Mpqf.equal x1 x2 | (Mpfrf x1, Mpfrf x2) -> Mpfrf.cmp x1 x2 = 0 | (Float x1, Float x2) -> x1 = x2 | x1, x2 -> Mpqf.equal (to_mpqf x1) (to_mpqf x2) end let cmp_int scalar n = match scalar with | Mpqf x -> Mpqf.cmp_int x n | Mpfrf x -> Mpfrf.cmp_int x n | Float x -> Pervasives.compare x (float_of_int n) let equal_int scalar n = match scalar with | Mpqf x -> (Mpqf.cmp_int x n)=0 | Mpfrf x -> (Mpfrf.cmp_int x n)=0 | Float x -> x=(float_of_int n) let neg scalar = match scalar with | Mpqf x -> Mpqf(Mpqf.neg x) | Mpfrf x -> let y = Mpfr.init2 (Mpfr.get_prec x) in ignore (Mpfr.neg y x Mpfr.Up); Mpfrf(Mpfrf.mpfrf y) | Float x -> Float(-. x) let to_string scalar = match scalar with | Mpqf x -> Mpqf.to_string x | Mpfrf x -> Mpfrf.to_string x | Float x -> string_of_float x let print fmt scalar = Format.pp_print_string fmt (to_string scalar) apron-dist-0.9.10/apron/mlapronidl/abstract1.ml0000640014525101416610000003041711252216517021252 0ustar bjeannetpopart(* File generated from abstract1.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type 'a t = { mutable abstract0: 'a Abstract0.t; mutable env: Environment.t; } (** APRON Abstract values of level 1 *) (** The type parameter ['a] allows to distinguish abstract values with different underlying abstract domains. *) type box1 = { mutable interval_array : Interval.t array; mutable box1_env : Environment.t } (* ********************************************************************** *) (** {2 General management} *) (* ********************************************************************** *) (* ============================================================ *) (** {3 Memory} *) (* ============================================================ *) let copy man x = { abstract0 = Abstract0.copy man x.abstract0; env = x.env } let size man x = Abstract0.size man x.abstract0 (* ============================================================ *) (** {3 Control of internal representation} *) (* ============================================================ *) let minimize man x = Abstract0.minimize man x.abstract0 let canonicalize man x = Abstract0.canonicalize man x.abstract0 let hash man x = 5*(Environment.hash x.env) + Abstract0.hash man x.abstract0 let approximate man x n = Abstract0.approximate man x.abstract0 n (* ============================================================ *) (** {3 Printing} *) (* ============================================================ *) external fdump : 'a Manager.t -> 'a t -> unit = "camlidl_abstract1_ap_abstract1_fdump" (* ============================================================ *) (** {3 Serialization} *) (* ============================================================ *) (* ********************************************************************** *) (** {2 Constructor, accessors, tests and property extraction} *) (* ********************************************************************** *) (* ============================================================ *) (** {3 Basic constructors} *) (* ============================================================ *) external bottom : 'a Manager.t -> Environment.t -> 'a t = "camlidl_abstract1_ap_abstract1_bottom" external top : 'a Manager.t -> Environment.t -> 'a t = "camlidl_abstract1_ap_abstract1_top" external of_box : 'a Manager.t -> Environment.t -> Var.t array -> Interval.t array -> 'a t = "camlidl_abstract1_ap_abstract1_of_box" (* ============================================================ *) (** {3 Accessors} *) (* ============================================================ *) let manager x = Abstract0.manager x.abstract0 let env x = x.env let abstract0 x = x.abstract0 (* ============================================================ *) (** {3 Tests} *) (* ============================================================ *) let is_bottom man x = Abstract0.is_bottom man x.abstract0 let is_top man x = Abstract0.is_top man x.abstract0 external is_leq : 'a Manager.t -> 'a t -> 'a t -> bool = "camlidl_abstract1_ap_abstract1_is_leq" external is_eq : 'a Manager.t -> 'a t -> 'a t -> bool = "camlidl_abstract1_ap_abstract1_is_eq" external sat_lincons : 'a Manager.t -> 'a t -> Lincons1.t -> bool = "camlidl_abstract1_ap_abstract1_sat_lincons" external sat_tcons : 'a Manager.t -> 'a t -> Tcons1.t -> bool = "camlidl_abstract1_ap_abstract1_sat_tcons" external sat_interval : 'a Manager.t -> 'a t -> Var.t -> Interval.t -> bool = "camlidl_abstract1_ap_abstract1_sat_interval" external is_variable_unconstrained : 'a Manager.t -> 'a t -> Var.t -> bool = "camlidl_abstract1_ap_abstract1_is_variable_unconstrained" (* ============================================================ *) (** {3 Extraction of properties} *) (* ============================================================ *) external bound_variable : 'a Manager.t -> 'a t -> Var.t -> Interval.t = "camlidl_abstract1_ap_abstract1_bound_variable" external bound_linexpr : 'a Manager.t -> 'a t -> Linexpr1.t -> Interval.t = "camlidl_abstract1_ap_abstract1_bound_linexpr" external bound_texpr : 'a Manager.t -> 'a t -> Texpr1.t -> Interval.t = "camlidl_abstract1_ap_abstract1_bound_texpr" let to_lincons_array man x = { Lincons1.lincons0_array = Abstract0.to_lincons_array man x.abstract0; Lincons1.array_env = x.env } let to_tcons_array man x = { Tcons1.tcons0_array = Abstract0.to_tcons_array man x.abstract0; Tcons1.array_env = x.env } let to_generator_array man x = { Generator1.generator0_array = Abstract0.to_generator_array man x.abstract0; Generator1.array_env = x.env } let to_box man x = { interval_array = Abstract0.to_box man x.abstract0; box1_env = x.env } (* ********************************************************************** *) (** {2 Operations} *) (* ********************************************************************** *) (* ============================================================ *) (** {3 Meet and Join} *) (* ============================================================ *) external meet : 'a Manager.t -> 'a t -> 'a t -> 'a t = "camlidl_abstract1_ap_abstract1_meet" external meet_array : 'a Manager.t -> 'a t array -> 'a t = "camlidl_abstract1_ap_abstract1_meet_array" external meet_lincons_array : 'a Manager.t -> 'a t -> Lincons1.earray -> 'a t = "camlidl_abstract1_ap_abstract1_meet_lincons_array" external meet_tcons_array : 'a Manager.t -> 'a t -> Tcons1.earray -> 'a t = "camlidl_abstract1_ap_abstract1_meet_tcons_array" external join : 'a Manager.t -> 'a t -> 'a t -> 'a t = "camlidl_abstract1_ap_abstract1_join" external join_array : 'a Manager.t -> 'a t array -> 'a t = "camlidl_abstract1_ap_abstract1_join_array" external add_ray_array : 'a Manager.t -> 'a t -> Generator1.earray -> 'a t = "camlidl_abstract1_ap_abstract1_add_ray_array" external meet_with : 'a Manager.t -> 'a t -> 'a t -> unit = "camlidl_abstract1_ap_abstract1_meet_with" external meet_lincons_array_with : 'a Manager.t -> 'a t -> Lincons1.earray -> unit = "camlidl_abstract1_ap_abstract1_meet_lincons_array_with" external meet_tcons_array_with : 'a Manager.t -> 'a t -> Tcons1.earray -> unit = "camlidl_abstract1_ap_abstract1_meet_tcons_array_with" external join_with : 'a Manager.t -> 'a t -> 'a t -> unit = "camlidl_abstract1_ap_abstract1_join_with" external add_ray_array_with : 'a Manager.t -> 'a t -> Generator1.earray -> unit = "camlidl_abstract1_ap_abstract1_add_ray_array_with" (* ============================================================ *) (** {3 Assignement and Substitutions} *) (* ============================================================ *) external assign_linexpr_array : 'a Manager.t -> 'a t -> Var.t array -> Linexpr1.t array -> 'a t option -> 'a t = "camlidl_abstract1_ap_abstract1_assign_linexpr_array" external substitute_linexpr_array : 'a Manager.t -> 'a t -> Var.t array -> Linexpr1.t array -> 'a t option -> 'a t = "camlidl_abstract1_ap_abstract1_substitute_linexpr_array" external assign_texpr_array : 'a Manager.t -> 'a t -> Var.t array -> Texpr1.t array -> 'a t option -> 'a t = "camlidl_abstract1_ap_abstract1_assign_texpr_array" external substitute_texpr_array : 'a Manager.t -> 'a t -> Var.t array -> Texpr1.t array -> 'a t option -> 'a t = "camlidl_abstract1_ap_abstract1_substitute_texpr_array" external assign_linexpr_array_with : 'a Manager.t -> 'a t -> Var.t array -> Linexpr1.t array -> 'a t option -> unit = "camlidl_abstract1_ap_abstract1_assign_linexpr_array_with" external substitute_linexpr_array_with : 'a Manager.t -> 'a t -> Var.t array -> Linexpr1.t array -> 'a t option -> unit = "camlidl_abstract1_ap_abstract1_substitute_linexpr_array_with" external assign_texpr_array_with : 'a Manager.t -> 'a t -> Var.t array -> Texpr1.t array -> 'a t option -> unit = "camlidl_abstract1_ap_abstract1_assign_texpr_array_with" external substitute_texpr_array_with : 'a Manager.t -> 'a t -> Var.t array -> Texpr1.t array -> 'a t option -> unit = "camlidl_abstract1_ap_abstract1_substitute_texpr_array_with" (* ============================================================ *) (** {3 Projections} *) (* ============================================================ *) external forget_array : 'a Manager.t -> 'a t -> Var.t array -> bool -> 'a t = "camlidl_abstract1_ap_abstract1_forget_array" external forget_array_with : 'a Manager.t -> 'a t -> Var.t array -> bool -> unit = "camlidl_abstract1_ap_abstract1_forget_array_with" (* ============================================================ *) (** {3 Change and permutation of dimensions} *) (* ============================================================ *) external change_environment : 'a Manager.t -> 'a t -> Environment.t -> bool -> 'a t = "camlidl_abstract1_ap_abstract1_change_environment" external minimize_environment : 'a Manager.t -> 'a t -> 'a t = "camlidl_abstract1_ap_abstract1_minimize_environment" external rename_array : 'a Manager.t -> 'a t -> Var.t array -> Var.t array -> 'a t = "camlidl_abstract1_ap_abstract1_rename_array" external change_environment_with : 'a Manager.t -> 'a t -> Environment.t -> bool -> unit = "camlidl_abstract1_ap_abstract1_change_environment_with" external minimize_environment_with : 'a Manager.t -> 'a t -> unit = "camlidl_abstract1_ap_abstract1_minimize_environment_with" external rename_array_with : 'a Manager.t -> 'a t -> Var.t array -> Var.t array -> unit = "camlidl_abstract1_ap_abstract1_rename_array_with" (* ============================================================ *) (** {3 Expansion and folding of dimensions} *) (* ============================================================ *) external expand : 'a Manager.t -> 'a t -> Var.t -> Var.t array -> 'a t = "camlidl_abstract1_ap_abstract1_expand" external fold : 'a Manager.t -> 'a t -> Var.t array -> 'a t = "camlidl_abstract1_ap_abstract1_fold" external expand_with : 'a Manager.t -> 'a t -> Var.t -> Var.t array -> unit = "camlidl_abstract1_ap_abstract1_expand_with" external fold_with : 'a Manager.t -> 'a t -> Var.t array -> unit = "camlidl_abstract1_ap_abstract1_fold_with" (* ============================================================ *) (** {3 Widening} *) (* ============================================================ *) external widening : 'a Manager.t -> 'a t -> 'a t -> 'a t = "camlidl_abstract1_ap_abstract1_widening" external widening_threshold : 'a Manager.t -> 'a t -> 'a t -> Lincons1.earray -> 'a t = "camlidl_abstract1_ap_abstract1_widening_threshold" (* ============================================================ *) (** {3 Closure operation} *) (* ============================================================ *) external closure : 'a Manager.t -> 'a t -> 'a t = "camlidl_abstract1_ap_abstract1_closure" external closure_with : 'a Manager.t -> 'a t -> unit = "camlidl_abstract1_ap_abstract1_closure_with" (* ********************************************************************** *) (** {2 Additional operations} *) (* ********************************************************************** *) let of_lincons_array man env array = let res = top man env in meet_lincons_array_with man res array; res let of_tcons_array man env array = let res = top man env in meet_tcons_array_with man res array; res let assign_linexpr man abs dim expr odest = assign_linexpr_array man abs [|dim|] [|expr|] odest let assign_texpr man abs dim expr odest = assign_texpr_array man abs [|dim|] [|expr|] odest let substitute_linexpr man abs dim expr odest = substitute_linexpr_array man abs [|dim|] [|expr|] odest let substitute_texpr man abs dim expr odest = substitute_texpr_array man abs [|dim|] [|expr|] odest let assign_linexpr_with man abs dim expr odest = assign_linexpr_array_with man abs [|dim|] [|expr|] odest let assign_texpr_with man abs dim expr odest = assign_texpr_array_with man abs [|dim|] [|expr|] odest let substitute_linexpr_with man abs dim expr odest = substitute_linexpr_array_with man abs [|dim|] [|expr|] odest let substitute_texpr_with man abs dim expr odest = substitute_texpr_array_with man abs [|dim|] [|expr|] odest external unify : 'a Manager.t -> 'a t -> 'a t -> 'a t = "camlidl_abstract1_ap_abstract1_unify" external unify_with : 'a Manager.t -> 'a t -> 'a t -> unit = "camlidl_abstract1_ap_abstract1_unify_with" let print fmt a = let man = manager a in if is_bottom man a then Format.pp_print_string fmt "bottom" else if is_top man a then Format.pp_print_string fmt "top" else begin let tab = to_lincons_array man a in Lincons1.array_print fmt tab; end apron-dist-0.9.10/apron/mlapronidl/apron_lexer.mll0000640014525101416610000000615410645462257022072 0ustar bjeannetpopart(* $Id$ *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) (** Lexical analysis of expressions, constraints, generators *) { open Apron_parser open Lexing exception Error of int * int let attributes_of_string (pos:int) lexbuf = let str = lexeme lexbuf in let length = (String.length str) - pos in let suffix = String.sub str pos length in let index = ref 0 in if length=0 then (Texpr1.Real, Texpr1.Rnd) else begin if String.get suffix !index <> '_' || length = 1 then raise (Error(lexeme_start lexbuf, lexeme_end lexbuf)) ; incr index; let round_typ = match String.get suffix !index with | 'i' -> Texpr1.Int | 'f' -> Texpr1.Single | 'd' -> Texpr1.Double | 'l' -> Texpr1.Extended | 'q' -> Texpr1.Quad | _ -> raise (Error(lexeme_start lexbuf, lexeme_end lexbuf)) in if length = 2 then (round_typ, Texpr1.Rnd) else begin incr index; if (String.get suffix !index) <> ',' || length = 3 then raise (Error(lexeme_start lexbuf, lexeme_end lexbuf)) ; incr index; let round_dir = match String.sub suffix !index (length - !index) with | "n" -> Texpr1.Near | "0" -> Texpr1.Zero | "+oo" -> Texpr1.Up | "-oo" -> Texpr1.Down | "?" -> Texpr1.Rnd | _ -> raise (Error(lexeme_start lexbuf, lexeme_end lexbuf)) in (round_typ, round_dir) end end } rule lex = parse eof { TK_EOF } | [' ' '\t' '\n'] + { lex lexbuf } | "[" { TK_LBRACKET } | "]" { TK_RBRACKET } | "(" { TK_LPAR } | ")" { TK_RPAR } | ";" { TK_SEMICOLON } | "mod" { TK_MOD } | "V:" { TK_VERTEX } | "R:" { TK_RAY } | "L:" { TK_LINE } | "RM:" { TK_RAYMOD } | "LM:" { TK_LINEMOD } (* Arithmetic operations *) | "+"(('_'['i''f''d''l''q'])(','("n"|"0"|"+oo"|"-oo"|"?"))?)? { TK_ADD(attributes_of_string 1 lexbuf) } | "-"(('_'['i''f''d''l''q'])(','("n"|"0"|"+oo"|"-oo"|"?"))?)? { TK_SUB(attributes_of_string 1 lexbuf) } | "*"(('_'['i''f''d''l''q'])(','("n"|"0"|"+oo"|"-oo"|"?"))?)? { TK_MUL(attributes_of_string 1 lexbuf) } | "/"(('_'['i''f''d''l''q'])(','("n"|"0"|"+oo"|"-oo"|"?"))?)? { TK_DIV(attributes_of_string 1 lexbuf) } | "%"(('_'['i''f''d''l''q'])(','("n"|"0"|"+oo"|"-oo"|"?"))?)? { TK_MODULO(attributes_of_string 1 lexbuf) } | "cast"(('_'['i''f''d''l''q'])(','("n"|"0"|"+oo"|"-oo"|"?"))?)? { TK_CAST(attributes_of_string 4 lexbuf) } | "sqrt"(('_'['i''f''d''l''q'])(','("n"|"0"|"+oo"|"-oo"|"?"))?)? { TK_SQRT(attributes_of_string 4 lexbuf) } (* Boolean operations *) | ">" { TK_SUP } | "<" { TK_INF } | ">=" { TK_SUPEG } | "<=" { TK_INFEG } | "=" { TK_EG } | "!=" { TK_DISEG } | (['0'-'9'])+ ('/'['0'-'9']+)? { let str = lexeme lexbuf in TK_MPQF(Mpqf.of_string str) } | ['0'-'9']* ('.' ['0'-'9']+) (['e' 'E'] ['+' '-']? ['0'-'9']+)? { let str = lexeme lexbuf in TK_FLOAT(float_of_string str) } (* Identifiers *) | ['A'-'Z' 'a'-'z' '_'] ( ['_' 'A'-'Z' 'a'-'z' '0'-'9' '.'] ) * ( ['\''] ) * { TK_VAR (lexeme lexbuf) } | _ { raise (Error(lexeme_start lexbuf, lexeme_end lexbuf)) } apron-dist-0.9.10/apron/mlapronidl/COPYING0000640014525101416610000006402610437621734020077 0ustar bjeannetpopart This license applies to all files distributed in the APRON library, including all source code, libraries, binaries, and documentation. Copyright (C) Bertrand Jeannet 2005-2006 for the mlapronidl subpackage. GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! apron-dist-0.9.10/apron/mlapronidl/abstract1_caml.c0000640014525101416610000022004211252216517022053 0ustar bjeannetpopart/* File generated from abstract1.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include #include "ap_expr0.h" #include "ap_abstract0.h" #include "ap_environment.h" #include "ap_expr1.h" #include "ap_abstract1.h" #include "caml/callback.h" #include "apron_caml.h" extern void camlidl_apron_scalar_ml2c(value, ap_scalar_t *); #define camlidl_ml2c_scalar_ap_scalar_t(v,c,ctx) camlidl_apron_scalar_ml2c(v,c) extern value camlidl_apron_scalar_c2ml(ap_scalar_t *); #define camlidl_c2ml_scalar_ap_scalar_t(c,ctx) camlidl_apron_scalar_c2ml(c) extern void camlidl_ml2c_scalar_ap_scalar_ptr(value, ap_scalar_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_ap_scalar_ptr(ap_scalar_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_scalar_struct_ap_scalar_array_t(value, struct ap_scalar_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_struct_ap_scalar_array_t(struct ap_scalar_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_t(value, struct ap_interval_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_t(struct ap_interval_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_ap_interval_ptr(value, ap_interval_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_ap_interval_ptr(ap_interval_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_array_t(value, struct ap_interval_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_array_t(struct ap_interval_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_coeff_struct_ap_coeff_t(value, struct ap_coeff_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_coeff_struct_ap_coeff_t(struct ap_coeff_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_ap_dim_t(value, ap_dim_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_ap_dim_t(ap_dim_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimchange_t(value, struct ap_dimchange_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange_t(struct ap_dimchange_t *, camlidl_ctx _ctx); extern void camlidl_apron_dimchange_ml2c(value, ap_dimchange_t *); #define camlidl_ml2c_dim_ap_dimchange_t(v,c,ctx) camlidl_apron_dimchange_ml2c(v,c) extern value camlidl_apron_dimchange_c2ml(ap_dimchange_t *); #define camlidl_c2ml_dim_ap_dimchange_t(c,ctx) camlidl_apron_dimchange_c2ml(c) extern void camlidl_ml2c_dim_struct_ap_dimchange2_t(value, struct ap_dimchange2_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange2_t(struct ap_dimchange2_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimperm_t(value, struct ap_dimperm_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimperm_t(struct ap_dimperm_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimension_t(value, struct ap_dimension_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimension_t(struct ap_dimension_t *, camlidl_ctx _ctx); extern void camlidl_apron_linexpr0_ptr_ml2c(value, ap_linexpr0_ptr *); #define camlidl_ml2c_linexpr0_ap_linexpr0_ptr(v,c,ctx) camlidl_apron_linexpr0_ptr_ml2c(v,c) extern value camlidl_apron_linexpr0_ptr_c2ml(ap_linexpr0_ptr *); #define camlidl_c2ml_linexpr0_ap_linexpr0_ptr(c,ctx) camlidl_apron_linexpr0_ptr_c2ml(c) extern void camlidl_apron_lincons0_ml2c(value, ap_lincons0_t *, camlidl_ctx); #define camlidl_ml2c_lincons0_ap_lincons0_t(v,c,ctx) camlidl_apron_lincons0_ml2c(v,c,ctx) extern value camlidl_apron_lincons0_c2ml(ap_lincons0_t *); #define camlidl_c2ml_lincons0_ap_lincons0_t(c,ctx) camlidl_apron_lincons0_c2ml(c) extern void camlidl_ml2c_lincons0_struct_ap_lincons0_array_t(value, struct ap_lincons0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_lincons0_struct_ap_lincons0_array_t(struct ap_lincons0_array_t *, camlidl_ctx _ctx); extern int camlidl_ml2c_generator0_enum_gentyp(value); extern value camlidl_c2ml_generator0_enum_gentyp(int); extern int camlidl_transl_table_generator0_enum_gentyp[]; extern void camlidl_ml2c_generator0_struct_ap_generator0_t(value, struct ap_generator0_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_generator0_struct_ap_generator0_t(struct ap_generator0_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_generator0_struct_ap_generator0_array_t(value, struct ap_generator0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_generator0_struct_ap_generator0_array_t(struct ap_generator0_array_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_funid_ml2c(value, ap_funid_t *); #define camlidl_ml2c_manager_ap_funid_t(v,c,ctx) camlidl_apron_manager_funid_ml2c(v,c) extern value camlidl_apron_manager_funid_c2ml(ap_funid_t *); #define camlidl_c2ml_manager_ap_funid_t(c,ctx) camlidl_apron_manager_funid_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_funopt_t(value, struct ap_funopt_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_funopt_t(struct ap_funopt_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_exc_ml2c(value, ap_exc_t *); #define camlidl_ml2c_manager_ap_exc_t(v,c,ctx) camlidl_apron_manager_exc_ml2c(v,c) extern value camlidl_apron_manager_exc_c2ml(ap_exc_t *); #define camlidl_c2ml_manager_ap_exc_t(c,ctx) camlidl_apron_manager_exc_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_exclog_t(value, struct ap_exclog_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_exclog_t(struct ap_exclog_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_ptr_ml2c(value, ap_manager_ptr *); #define camlidl_ml2c_manager_ap_manager_ptr(v,c,ctx) camlidl_apron_manager_ptr_ml2c(v,c) extern value camlidl_apron_manager_ptr_c2ml(ap_manager_ptr *); #define camlidl_c2ml_manager_ap_manager_ptr(c,ctx) camlidl_apron_manager_ptr_c2ml(c) extern void camlidl_apron_texpr0_ptr_ml2c(value, ap_texpr0_ptr *); #define camlidl_ml2c_texpr0_ap_texpr0_ptr(v,c,ctx) camlidl_apron_texpr0_ptr_ml2c(v,c) extern value camlidl_apron_texpr0_ptr_c2ml(ap_texpr0_ptr *); #define camlidl_c2ml_texpr0_ap_texpr0_ptr(c,ctx) camlidl_apron_texpr0_ptr_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_op_t(value, ap_texpr_op_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_op_t(ap_texpr_op_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_unop_t_ml2c(value, ap_texpr_unop_t *); #define camlidl_ml2c_texpr0_ap_texpr_unop_t(v,c,ctx) camlidl_apron_texpr_unop_t_ml2c(v,c) extern value camlidl_apron_texpr_unop_t_c2ml(ap_texpr_unop_t *); #define camlidl_c2ml_texpr0_ap_texpr_unop_t(c,ctx) camlidl_apron_texpr_unop_t_c2ml(c) extern void camlidl_apron_texpr_binop_t_ml2c(value, ap_texpr_binop_t *); #define camlidl_ml2c_texpr0_ap_texpr_binop_t(v,c,ctx) camlidl_apron_texpr_binop_t_ml2c(v,c) extern value camlidl_apron_texpr_binop_t_c2ml(ap_texpr_binop_t *); #define camlidl_c2ml_texpr0_ap_texpr_binop_t(c,ctx) camlidl_apron_texpr_binop_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rtype_t(value, ap_texpr_rtype_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rtype_t(ap_texpr_rtype_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_rtype_t_ml2c(value, ap_texpr_rtype_t *); #define camlidl_ml2c_texpr0_ap_texpr_rtype_t(v,c,ctx) camlidl_apron_texpr_rtype_t_ml2c(v,c) extern value camlidl_apron_texpr_rtype_t_c2ml(ap_texpr_rtype_t *); #define camlidl_c2ml_texpr0_ap_texpr_rtype_t(c,ctx) camlidl_apron_texpr_rtype_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rdir_t(value, ap_texpr_rdir_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rdir_t(ap_texpr_rdir_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_rdir_t_ml2c(value, ap_texpr_rdir_t *); #define camlidl_ml2c_texpr0_ap_texpr_rdir_t(v,c,ctx) camlidl_apron_texpr_rdir_t_ml2c(v,c) extern value camlidl_apron_texpr_rdir_t_c2ml(ap_texpr_rdir_t *); #define camlidl_c2ml_texpr0_ap_texpr_rdir_t(c,ctx) camlidl_apron_texpr_rdir_t_c2ml(c) extern void camlidl_apron_tcons0_ml2c(value, ap_tcons0_t *, camlidl_ctx); #define camlidl_ml2c_tcons0_ap_tcons0_t(v,c,ctx) camlidl_apron_tcons0_ml2c(v,c,ctx) extern value camlidl_apron_tcons0_c2ml(ap_tcons0_t *); #define camlidl_c2ml_tcons0_ap_tcons0_t(c,ctx) camlidl_apron_tcons0_c2ml(c) extern void camlidl_ml2c_tcons0_struct_ap_tcons0_array_t(value, struct ap_tcons0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_tcons0_struct_ap_tcons0_array_t(struct ap_tcons0_array_t *, camlidl_ctx _ctx); extern void camlidl_apron_abstract0_ptr_ml2c(value, ap_abstract0_ptr *); #define camlidl_ml2c_abstract0_ap_abstract0_ptr(v,c,ctx) camlidl_apron_abstract0_ptr_ml2c(v,c) extern value camlidl_apron_abstract0_ptr_c2ml(ap_abstract0_ptr *); #define camlidl_c2ml_abstract0_ap_abstract0_ptr(c,ctx) camlidl_apron_abstract0_ptr_c2ml(c) extern void camlidl_apron_var_ptr_ml2c(value, ap_var_t *); #define camlidl_ml2c_var_ap_var_t(v,c,ctx) camlidl_apron_var_ptr_ml2c(v,c) extern value camlidl_apron_var_ptr_c2ml(ap_var_t *); #define camlidl_c2ml_var_ap_var_t(c,ctx) camlidl_apron_var_ptr_c2ml(c) extern int camlidl_ml2c_environment_enum_typvar(value); extern value camlidl_c2ml_environment_enum_typvar(int); extern int camlidl_transl_table_environment_enum_typvar[]; extern void camlidl_apron_environment_ptr_ml2c(value, ap_environment_ptr *); #define camlidl_ml2c_environment_ap_environment_ptr(v,c,ctx) camlidl_apron_environment_ptr_ml2c(v,c) extern value camlidl_apron_environment_ptr_c2ml(ap_environment_ptr *); #define camlidl_c2ml_environment_ap_environment_ptr(c,ctx) camlidl_apron_environment_ptr_c2ml(c) extern void camlidl_ml2c_linexpr1_struct_ap_linexpr1_t(value, struct ap_linexpr1_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_linexpr1_struct_ap_linexpr1_t(struct ap_linexpr1_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_lincons1_struct_ap_lincons1_t(value, struct ap_lincons1_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_lincons1_struct_ap_lincons1_t(struct ap_lincons1_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_lincons1_struct_ap_lincons1_array_t(value, struct ap_lincons1_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_lincons1_struct_ap_lincons1_array_t(struct ap_lincons1_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_generator1_struct_ap_generator1_t(value, struct ap_generator1_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_generator1_struct_ap_generator1_t(struct ap_generator1_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_generator1_struct_ap_generator1_array_t(value, struct ap_generator1_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_generator1_struct_ap_generator1_array_t(struct ap_generator1_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_texpr1_struct_ap_texpr1_t(value, struct ap_texpr1_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr1_struct_ap_texpr1_t(struct ap_texpr1_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_tcons1_struct_ap_tcons1_t(value, struct ap_tcons1_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_tcons1_struct_ap_tcons1_t(struct ap_tcons1_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_tcons1_struct_ap_tcons1_array_t(value, struct ap_tcons1_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_tcons1_struct_ap_tcons1_array_t(struct ap_tcons1_array_t *, camlidl_ctx _ctx); void camlidl_ml2c_abstract1_struct_ap_abstract1_t(value _v1, struct ap_abstract1_t * _c2, camlidl_ctx _ctx) { value _v3; value _v4; _v3 = Field(_v1, 0); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v3, &(*_c2).abstract0, _ctx); _v4 = Field(_v1, 1); camlidl_ml2c_environment_ap_environment_ptr(_v4, &(*_c2).env, _ctx); } value camlidl_c2ml_abstract1_struct_ap_abstract1_t(struct ap_abstract1_t * _c1, camlidl_ctx _ctx) { value _v2; value _v3[2]; _v3[0] = _v3[1] = 0; Begin_roots_block(_v3, 2) _v3[0] = camlidl_c2ml_abstract0_ap_abstract0_ptr(&(*_c1).abstract0, _ctx); _v3[1] = camlidl_c2ml_environment_ap_environment_ptr(&(*_c1).env, _ctx); _v2 = camlidl_alloc_small(2, 0); Field(_v2, 0) = _v3[0]; Field(_v2, 1) = _v3[1]; End_roots() return _v2; } value camlidl_abstract1_ap_abstract1_fdump( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ struct ap_abstract1_t _c1; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); /* begin user-supplied calling sequence */ ap_abstract1_fdump(stdout,man, a); fflush(stdout); /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract1_ap_abstract1_bottom( value _v_man, value _v_env) { ap_manager_ptr man; /*in*/ ap_environment_ptr env; /*in*/ struct ap_abstract1_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); _res = ap_abstract1_bottom(man, env); _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_top( value _v_man, value _v_env) { ap_manager_ptr man; /*in*/ ap_environment_ptr env; /*in*/ struct ap_abstract1_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); _res = ap_abstract1_top(man, env); _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_of_box( value _v_man, value _v_env, value _v_tvar, value _v_tinterval) { ap_manager_ptr man; /*in*/ ap_environment_ptr env; /*in*/ ap_var_t *tvar; /*in*/ ap_interval_ptr *tinterval; /*in*/ unsigned int size; /*in*/ unsigned int size2; /*in*/ struct ap_abstract1_t _res; mlsize_t _c1; mlsize_t _c2; value _v3; mlsize_t _c4; mlsize_t _c5; value _v6; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); _c1 = Wosize_val(_v_tvar); tvar = camlidl_malloc(_c1 * sizeof(ap_var_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_tvar, _c2); camlidl_ml2c_var_ap_var_t(_v3, &tvar[_c2], _ctx); } size = _c1; _c4 = Wosize_val(_v_tinterval); tinterval = camlidl_malloc(_c4 * sizeof(ap_interval_ptr ), _ctx); for (_c5 = 0; _c5 < _c4; _c5++) { _v6 = Field(_v_tinterval, _c5); camlidl_ml2c_interval_ap_interval_ptr(_v6, &tinterval[_c5], _ctx); } size2 = _c4; /* begin user-supplied calling sequence */ if (size!=size2) caml_failwith("Abstract1.of_box: the two arrays are of different sizes"); _res = ap_abstract1_of_box(man,env,tvar,tinterval,size); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_is_leq( value _v_man, value _v_a1, value _v_a2) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a1; /*in*/ struct ap_abstract1_t *a2; /*in*/ int _res; struct ap_abstract1_t _c1; struct ap_abstract1_t _c2; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a1 = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a1, &_c1, _ctx); a2 = &_c2; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a2, &_c2, _ctx); _res = ap_abstract1_is_leq(man, a1, a2); _vres = Val_int(_res); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_is_eq( value _v_man, value _v_a1, value _v_a2) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a1; /*in*/ struct ap_abstract1_t *a2; /*in*/ int _res; struct ap_abstract1_t _c1; struct ap_abstract1_t _c2; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a1 = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a1, &_c1, _ctx); a2 = &_c2; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a2, &_c2, _ctx); _res = ap_abstract1_is_eq(man, a1, a2); _vres = Val_int(_res); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_sat_lincons( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ struct ap_lincons1_t *v; /*in*/ int _res; struct ap_abstract1_t _c1; struct ap_lincons1_t _c2; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); v = &_c2; camlidl_ml2c_lincons1_struct_ap_lincons1_t(_v_v, &_c2, _ctx); _res = ap_abstract1_sat_lincons(man, a, v); _vres = Val_int(_res); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_sat_tcons( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ struct ap_tcons1_t *v; /*in*/ int _res; struct ap_abstract1_t _c1; struct ap_tcons1_t _c2; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); v = &_c2; camlidl_ml2c_tcons1_struct_ap_tcons1_t(_v_v, &_c2, _ctx); _res = ap_abstract1_sat_tcons(man, a, v); _vres = Val_int(_res); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_sat_interval( value _v_man, value _v_a, value _v_v1, value _v_v2) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_var_t v1; /*in*/ struct ap_interval_t *v2; /*in*/ int _res; struct ap_abstract1_t _c1; struct ap_interval_t _c2; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); camlidl_ml2c_var_ap_var_t(_v_v1, &v1, _ctx); v2 = &_c2; camlidl_ml2c_interval_struct_ap_interval_t(_v_v2, &_c2, _ctx); _res = ap_abstract1_sat_interval(man, a, v1, v2); _vres = Val_int(_res); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_is_variable_unconstrained( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_var_t v; /*in*/ int _res; struct ap_abstract1_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); camlidl_ml2c_var_ap_var_t(_v_v, &v, _ctx); _res = ap_abstract1_is_variable_unconstrained(man, a, v); _vres = Val_int(_res); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_bound_variable( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_var_t v; /*in*/ struct ap_interval_t *_res; struct ap_abstract1_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); camlidl_ml2c_var_ap_var_t(_v_v, &v, _ctx); _res = ap_abstract1_bound_variable(man, a, v); _vres = camlidl_c2ml_interval_struct_ap_interval_t(&*_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ ap_interval_free(_res); if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_bound_linexpr( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ struct ap_linexpr1_t *v; /*in*/ struct ap_interval_t *_res; struct ap_abstract1_t _c1; struct ap_linexpr1_t _c2; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); v = &_c2; camlidl_ml2c_linexpr1_struct_ap_linexpr1_t(_v_v, &_c2, _ctx); _res = ap_abstract1_bound_linexpr(man, a, v); _vres = camlidl_c2ml_interval_struct_ap_interval_t(&*_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ ap_interval_free(_res); if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_bound_texpr( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ struct ap_texpr1_t *v; /*in*/ struct ap_interval_t *_res; struct ap_abstract1_t _c1; struct ap_texpr1_t _c2; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); v = &_c2; camlidl_ml2c_texpr1_struct_ap_texpr1_t(_v_v, &_c2, _ctx); _res = ap_abstract1_bound_texpr(man, a, v); _vres = camlidl_c2ml_interval_struct_ap_interval_t(&*_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ ap_interval_free(_res); if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_meet( value _v_man, value _v_a1, value _v_a2) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a1; /*in*/ struct ap_abstract1_t *a2; /*in*/ struct ap_abstract1_t _res; struct ap_abstract1_t _c1; struct ap_abstract1_t _c2; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a1 = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a1, &_c1, _ctx); a2 = &_c2; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a2, &_c2, _ctx); /* begin user-supplied calling sequence */ _res = ap_abstract1_meet(man,false,a1,a2); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_meet_array( value _v_man, value _v_array) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *array; /*in*/ unsigned int size; /*in*/ struct ap_abstract1_t _res; mlsize_t _c1; mlsize_t _c2; value _v3; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); _c1 = Wosize_val(_v_array); array = camlidl_malloc(_c1 * sizeof(struct ap_abstract1_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_array, _c2); camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v3, &array[_c2], _ctx); } size = _c1; _res = ap_abstract1_meet_array(man, array, size); _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_meet_lincons_array( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ struct ap_lincons1_array_t *v; /*in*/ struct ap_abstract1_t _res; struct ap_abstract1_t _c1; struct ap_lincons1_array_t _c2; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); v = &_c2; camlidl_ml2c_lincons1_struct_ap_lincons1_array_t(_v_v, &_c2, _ctx); /* begin user-supplied calling sequence */ _res = ap_abstract1_meet_lincons_array(man,false,a,v); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_meet_tcons_array( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ struct ap_tcons1_array_t *v; /*in*/ struct ap_abstract1_t _res; struct ap_abstract1_t _c1; struct ap_tcons1_array_t _c2; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); v = &_c2; camlidl_ml2c_tcons1_struct_ap_tcons1_array_t(_v_v, &_c2, _ctx); /* begin user-supplied calling sequence */ _res = ap_abstract1_meet_tcons_array(man,false,a,v); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_join( value _v_man, value _v_a1, value _v_a2) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a1; /*in*/ struct ap_abstract1_t *a2; /*in*/ struct ap_abstract1_t _res; struct ap_abstract1_t _c1; struct ap_abstract1_t _c2; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a1 = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a1, &_c1, _ctx); a2 = &_c2; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a2, &_c2, _ctx); /* begin user-supplied calling sequence */ _res = ap_abstract1_join(man,false,a1,a2); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_join_array( value _v_man, value _v_array) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *array; /*in*/ unsigned int size; /*in*/ struct ap_abstract1_t _res; mlsize_t _c1; mlsize_t _c2; value _v3; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); _c1 = Wosize_val(_v_array); array = camlidl_malloc(_c1 * sizeof(struct ap_abstract1_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_array, _c2); camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v3, &array[_c2], _ctx); } size = _c1; _res = ap_abstract1_join_array(man, array, size); _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_add_ray_array( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ struct ap_generator1_array_t *v; /*in*/ struct ap_abstract1_t _res; struct ap_abstract1_t _c1; struct ap_generator1_array_t _c2; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); v = &_c2; camlidl_ml2c_generator1_struct_ap_generator1_array_t(_v_v, &_c2, _ctx); /* begin user-supplied calling sequence */ _res = ap_abstract1_add_ray_array(man,false,a,v); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_meet_with( value _v_man, value _v_a1, value _v_a2) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a1; /*in*/ struct ap_abstract1_t *a2; /*in*/ struct ap_abstract1_t _c1; struct ap_abstract1_t _c2; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a1 = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a1, &_c1, _ctx); a2 = &_c2; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a2, &_c2, _ctx); /* begin user-supplied calling sequence */ { ap_abstract1_t res = ap_abstract1_meet(man,true,a1,a2); value v = Field(_v_a1,0); *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract1_ap_abstract1_meet_lincons_array_with( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ struct ap_lincons1_array_t *v; /*in*/ struct ap_abstract1_t _c1; struct ap_lincons1_array_t _c2; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); v = &_c2; camlidl_ml2c_lincons1_struct_ap_lincons1_array_t(_v_v, &_c2, _ctx); /* begin user-supplied calling sequence */ { ap_abstract1_t res = ap_abstract1_meet_lincons_array(man,true,a,v); value v = Field(_v_a,0); *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract1_ap_abstract1_meet_tcons_array_with( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ struct ap_tcons1_array_t *v; /*in*/ struct ap_abstract1_t _c1; struct ap_tcons1_array_t _c2; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); v = &_c2; camlidl_ml2c_tcons1_struct_ap_tcons1_array_t(_v_v, &_c2, _ctx); /* begin user-supplied calling sequence */ { ap_abstract1_t res = ap_abstract1_meet_tcons_array(man,true,a,v); value v = Field(_v_a,0); *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract1_ap_abstract1_join_with( value _v_man, value _v_a1, value _v_a2) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a1; /*in*/ struct ap_abstract1_t *a2; /*in*/ struct ap_abstract1_t _c1; struct ap_abstract1_t _c2; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a1 = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a1, &_c1, _ctx); a2 = &_c2; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a2, &_c2, _ctx); /* begin user-supplied calling sequence */ { ap_abstract1_t res = ap_abstract1_join(man,true,a1,a2); value v = Field(_v_a1,0); *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract1_ap_abstract1_add_ray_array_with( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ struct ap_generator1_array_t *v; /*in*/ struct ap_abstract1_t _c1; struct ap_generator1_array_t _c2; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); v = &_c2; camlidl_ml2c_generator1_struct_ap_generator1_array_t(_v_v, &_c2, _ctx); /* begin user-supplied calling sequence */ { ap_abstract1_t res = ap_abstract1_add_ray_array(man,true,a,v); value v = Field(_v_a,0); *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract1_ap_abstract1_assign_linexpr_array( value _v_man, value _v_a, value _v_v1, value _v_v2, value _v_dest) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_var_t *v1; /*in*/ struct ap_linexpr1_t *v2; /*in*/ int v3; /*in*/ int v4; /*in*/ struct ap_abstract1_t *dest; /*in*/ struct ap_abstract1_t _res; struct ap_abstract1_t _c1; mlsize_t _c2; mlsize_t _c3; value _v4; mlsize_t _c5; mlsize_t _c6; value _v7; value _v8; struct ap_abstract1_t _c9; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); _c2 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c2 * sizeof(ap_var_t ), _ctx); for (_c3 = 0; _c3 < _c2; _c3++) { _v4 = Field(_v_v1, _c3); camlidl_ml2c_var_ap_var_t(_v4, &v1[_c3], _ctx); } v3 = _c2; _c5 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c5 * sizeof(struct ap_linexpr1_t ), _ctx); for (_c6 = 0; _c6 < _c5; _c6++) { _v7 = Field(_v_v2, _c6); camlidl_ml2c_linexpr1_struct_ap_linexpr1_t(_v7, &v2[_c6], _ctx); } v4 = _c5; if (_v_dest == Val_int(0)) { dest = NULL; } else { _v8 = Field(_v_dest, 0); dest = &_c9; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v8, &_c9, _ctx); } /* begin user-supplied calling sequence */ if (v3!=v4) caml_failwith("Abstract1.assign_linexpr_array: arrays of different size"); _res = ap_abstract1_assign_linexpr_array(man,false,a,v1,v2,v3,dest); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_substitute_linexpr_array( value _v_man, value _v_a, value _v_v1, value _v_v2, value _v_dest) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_var_t *v1; /*in*/ struct ap_linexpr1_t *v2; /*in*/ int v3; /*in*/ int v4; /*in*/ struct ap_abstract1_t *dest; /*in*/ struct ap_abstract1_t _res; struct ap_abstract1_t _c1; mlsize_t _c2; mlsize_t _c3; value _v4; mlsize_t _c5; mlsize_t _c6; value _v7; value _v8; struct ap_abstract1_t _c9; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); _c2 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c2 * sizeof(ap_var_t ), _ctx); for (_c3 = 0; _c3 < _c2; _c3++) { _v4 = Field(_v_v1, _c3); camlidl_ml2c_var_ap_var_t(_v4, &v1[_c3], _ctx); } v3 = _c2; _c5 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c5 * sizeof(struct ap_linexpr1_t ), _ctx); for (_c6 = 0; _c6 < _c5; _c6++) { _v7 = Field(_v_v2, _c6); camlidl_ml2c_linexpr1_struct_ap_linexpr1_t(_v7, &v2[_c6], _ctx); } v4 = _c5; if (_v_dest == Val_int(0)) { dest = NULL; } else { _v8 = Field(_v_dest, 0); dest = &_c9; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v8, &_c9, _ctx); } /* begin user-supplied calling sequence */ if (v3!=v4) caml_failwith("Abstract1.substitute_linexpr_array: arrays of different size"); _res = ap_abstract1_substitute_linexpr_array(man,false,a,v1,v2,v3,dest); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_assign_texpr_array( value _v_man, value _v_a, value _v_v1, value _v_v2, value _v_dest) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_var_t *v1; /*in*/ struct ap_texpr1_t *v2; /*in*/ int v3; /*in*/ int v4; /*in*/ struct ap_abstract1_t *dest; /*in*/ struct ap_abstract1_t _res; struct ap_abstract1_t _c1; mlsize_t _c2; mlsize_t _c3; value _v4; mlsize_t _c5; mlsize_t _c6; value _v7; value _v8; struct ap_abstract1_t _c9; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); _c2 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c2 * sizeof(ap_var_t ), _ctx); for (_c3 = 0; _c3 < _c2; _c3++) { _v4 = Field(_v_v1, _c3); camlidl_ml2c_var_ap_var_t(_v4, &v1[_c3], _ctx); } v3 = _c2; _c5 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c5 * sizeof(struct ap_texpr1_t ), _ctx); for (_c6 = 0; _c6 < _c5; _c6++) { _v7 = Field(_v_v2, _c6); camlidl_ml2c_texpr1_struct_ap_texpr1_t(_v7, &v2[_c6], _ctx); } v4 = _c5; if (_v_dest == Val_int(0)) { dest = NULL; } else { _v8 = Field(_v_dest, 0); dest = &_c9; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v8, &_c9, _ctx); } /* begin user-supplied calling sequence */ if (v3!=v4) caml_failwith("Abstract1.assign_texpr_array: arrays of different size"); _res = ap_abstract1_assign_texpr_array(man,false,a,v1,v2,v3,dest); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_substitute_texpr_array( value _v_man, value _v_a, value _v_v1, value _v_v2, value _v_dest) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_var_t *v1; /*in*/ struct ap_texpr1_t *v2; /*in*/ int v3; /*in*/ int v4; /*in*/ struct ap_abstract1_t *dest; /*in*/ struct ap_abstract1_t _res; struct ap_abstract1_t _c1; mlsize_t _c2; mlsize_t _c3; value _v4; mlsize_t _c5; mlsize_t _c6; value _v7; value _v8; struct ap_abstract1_t _c9; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); _c2 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c2 * sizeof(ap_var_t ), _ctx); for (_c3 = 0; _c3 < _c2; _c3++) { _v4 = Field(_v_v1, _c3); camlidl_ml2c_var_ap_var_t(_v4, &v1[_c3], _ctx); } v3 = _c2; _c5 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c5 * sizeof(struct ap_texpr1_t ), _ctx); for (_c6 = 0; _c6 < _c5; _c6++) { _v7 = Field(_v_v2, _c6); camlidl_ml2c_texpr1_struct_ap_texpr1_t(_v7, &v2[_c6], _ctx); } v4 = _c5; if (_v_dest == Val_int(0)) { dest = NULL; } else { _v8 = Field(_v_dest, 0); dest = &_c9; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v8, &_c9, _ctx); } /* begin user-supplied calling sequence */ if (v3!=v4) caml_failwith("Abstract1.substitute_texpr_array: arrays of different size"); _res = ap_abstract1_substitute_texpr_array(man,false,a,v1,v2,v3,dest); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_assign_linexpr_array_with( value _v_man, value _v_a, value _v_v1, value _v_v2, value _v_dest) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_var_t *v1; /*in*/ struct ap_linexpr1_t *v2; /*in*/ int v3; /*in*/ int v4; /*in*/ struct ap_abstract1_t *dest; /*in*/ struct ap_abstract1_t _c1; mlsize_t _c2; mlsize_t _c3; value _v4; mlsize_t _c5; mlsize_t _c6; value _v7; value _v8; struct ap_abstract1_t _c9; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); _c2 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c2 * sizeof(ap_var_t ), _ctx); for (_c3 = 0; _c3 < _c2; _c3++) { _v4 = Field(_v_v1, _c3); camlidl_ml2c_var_ap_var_t(_v4, &v1[_c3], _ctx); } v3 = _c2; _c5 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c5 * sizeof(struct ap_linexpr1_t ), _ctx); for (_c6 = 0; _c6 < _c5; _c6++) { _v7 = Field(_v_v2, _c6); camlidl_ml2c_linexpr1_struct_ap_linexpr1_t(_v7, &v2[_c6], _ctx); } v4 = _c5; if (_v_dest == Val_int(0)) { dest = NULL; } else { _v8 = Field(_v_dest, 0); dest = &_c9; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v8, &_c9, _ctx); } /* begin user-supplied calling sequence */ if (v3!=v4) caml_failwith("Abstract1.assign_linexpr_array_with: arrays of different size"); { ap_abstract1_t res = ap_abstract1_assign_linexpr_array(man,true,a,v1,v2,v3,dest); value v = Field(_v_a,0); *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract1_ap_abstract1_substitute_linexpr_array_with( value _v_man, value _v_a, value _v_v1, value _v_v2, value _v_dest) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_var_t *v1; /*in*/ struct ap_linexpr1_t *v2; /*in*/ int v3; /*in*/ int v4; /*in*/ struct ap_abstract1_t *dest; /*in*/ struct ap_abstract1_t _c1; mlsize_t _c2; mlsize_t _c3; value _v4; mlsize_t _c5; mlsize_t _c6; value _v7; value _v8; struct ap_abstract1_t _c9; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); _c2 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c2 * sizeof(ap_var_t ), _ctx); for (_c3 = 0; _c3 < _c2; _c3++) { _v4 = Field(_v_v1, _c3); camlidl_ml2c_var_ap_var_t(_v4, &v1[_c3], _ctx); } v3 = _c2; _c5 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c5 * sizeof(struct ap_linexpr1_t ), _ctx); for (_c6 = 0; _c6 < _c5; _c6++) { _v7 = Field(_v_v2, _c6); camlidl_ml2c_linexpr1_struct_ap_linexpr1_t(_v7, &v2[_c6], _ctx); } v4 = _c5; if (_v_dest == Val_int(0)) { dest = NULL; } else { _v8 = Field(_v_dest, 0); dest = &_c9; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v8, &_c9, _ctx); } /* begin user-supplied calling sequence */ if (v3!=v4) caml_failwith("Abstract1.substitute_linexpr_array_with: arrays of different size"); { ap_abstract1_t res = ap_abstract1_substitute_linexpr_array(man,true,a,v1,v2,v3,dest); value v = Field(_v_a,0); *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract1_ap_abstract1_assign_texpr_array_with( value _v_man, value _v_a, value _v_v1, value _v_v2, value _v_dest) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_var_t *v1; /*in*/ struct ap_texpr1_t *v2; /*in*/ int v3; /*in*/ int v4; /*in*/ struct ap_abstract1_t *dest; /*in*/ struct ap_abstract1_t _c1; mlsize_t _c2; mlsize_t _c3; value _v4; mlsize_t _c5; mlsize_t _c6; value _v7; value _v8; struct ap_abstract1_t _c9; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); _c2 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c2 * sizeof(ap_var_t ), _ctx); for (_c3 = 0; _c3 < _c2; _c3++) { _v4 = Field(_v_v1, _c3); camlidl_ml2c_var_ap_var_t(_v4, &v1[_c3], _ctx); } v3 = _c2; _c5 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c5 * sizeof(struct ap_texpr1_t ), _ctx); for (_c6 = 0; _c6 < _c5; _c6++) { _v7 = Field(_v_v2, _c6); camlidl_ml2c_texpr1_struct_ap_texpr1_t(_v7, &v2[_c6], _ctx); } v4 = _c5; if (_v_dest == Val_int(0)) { dest = NULL; } else { _v8 = Field(_v_dest, 0); dest = &_c9; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v8, &_c9, _ctx); } /* begin user-supplied calling sequence */ if (v3!=v4) caml_failwith("Abstract1.assign_texpr_array_with: arrays of different size"); { ap_abstract1_t res = ap_abstract1_assign_texpr_array(man,true,a,v1,v2,v3,dest); value v = Field(_v_a,0); *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract1_ap_abstract1_substitute_texpr_array_with( value _v_man, value _v_a, value _v_v1, value _v_v2, value _v_dest) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_var_t *v1; /*in*/ struct ap_texpr1_t *v2; /*in*/ int v3; /*in*/ int v4; /*in*/ struct ap_abstract1_t *dest; /*in*/ struct ap_abstract1_t _c1; mlsize_t _c2; mlsize_t _c3; value _v4; mlsize_t _c5; mlsize_t _c6; value _v7; value _v8; struct ap_abstract1_t _c9; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); _c2 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c2 * sizeof(ap_var_t ), _ctx); for (_c3 = 0; _c3 < _c2; _c3++) { _v4 = Field(_v_v1, _c3); camlidl_ml2c_var_ap_var_t(_v4, &v1[_c3], _ctx); } v3 = _c2; _c5 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c5 * sizeof(struct ap_texpr1_t ), _ctx); for (_c6 = 0; _c6 < _c5; _c6++) { _v7 = Field(_v_v2, _c6); camlidl_ml2c_texpr1_struct_ap_texpr1_t(_v7, &v2[_c6], _ctx); } v4 = _c5; if (_v_dest == Val_int(0)) { dest = NULL; } else { _v8 = Field(_v_dest, 0); dest = &_c9; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v8, &_c9, _ctx); } /* begin user-supplied calling sequence */ if (v3!=v4) caml_failwith("Abstract1.substitute_texpr_array_with: arrays of different size"); { ap_abstract1_t res = ap_abstract1_substitute_texpr_array(man,true,a,v1,v2,v3,dest); value v = Field(_v_a,0); *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract1_ap_abstract1_forget_array( value _v_man, value _v_a, value _v_v1, value _v_v3) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_var_t *v1; /*in*/ unsigned int v2; /*in*/ int v3; /*in*/ struct ap_abstract1_t _res; struct ap_abstract1_t _c1; mlsize_t _c2; mlsize_t _c3; value _v4; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); _c2 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c2 * sizeof(ap_var_t ), _ctx); for (_c3 = 0; _c3 < _c2; _c3++) { _v4 = Field(_v_v1, _c3); camlidl_ml2c_var_ap_var_t(_v4, &v1[_c3], _ctx); } v2 = _c2; v3 = Int_val(_v_v3); /* begin user-supplied calling sequence */ _res = ap_abstract1_forget_array(man,false,a,v1,v2,v3); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_forget_array_with( value _v_man, value _v_a, value _v_v1, value _v_v3) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_var_t *v1; /*in*/ int v2; /*in*/ int v3; /*in*/ struct ap_abstract1_t _c1; mlsize_t _c2; mlsize_t _c3; value _v4; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); _c2 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c2 * sizeof(ap_var_t ), _ctx); for (_c3 = 0; _c3 < _c2; _c3++) { _v4 = Field(_v_v1, _c3); camlidl_ml2c_var_ap_var_t(_v4, &v1[_c3], _ctx); } v2 = _c2; v3 = Int_val(_v_v3); /* begin user-supplied calling sequence */ { ap_abstract1_t res = ap_abstract1_forget_array(man,true,a,v1,v2,v3); value v = Field(_v_a,0); *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract1_ap_abstract1_change_environment( value _v_man, value _v_a, value _v_v1, value _v_v2) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_environment_ptr v1; /*in*/ int v2; /*in*/ struct ap_abstract1_t _res; struct ap_abstract1_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_v1, &v1, _ctx); v2 = Int_val(_v_v2); /* begin user-supplied calling sequence */ _res = ap_abstract1_change_environment(man,false,a,v1,v2); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_minimize_environment( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ struct ap_abstract1_t _res; struct ap_abstract1_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); /* begin user-supplied calling sequence */ _res = ap_abstract1_minimize_environment(man,false,a); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_rename_array( value _v_man, value _v_a, value _v_v1, value _v_v2) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_var_t *v1; /*in*/ ap_var_t *v2; /*in*/ unsigned int v3; /*in*/ unsigned int v4; /*in*/ struct ap_abstract1_t _res; struct ap_abstract1_t _c1; mlsize_t _c2; mlsize_t _c3; value _v4; mlsize_t _c5; mlsize_t _c6; value _v7; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); _c2 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c2 * sizeof(ap_var_t ), _ctx); for (_c3 = 0; _c3 < _c2; _c3++) { _v4 = Field(_v_v1, _c3); camlidl_ml2c_var_ap_var_t(_v4, &v1[_c3], _ctx); } v3 = _c2; _c5 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c5 * sizeof(ap_var_t ), _ctx); for (_c6 = 0; _c6 < _c5; _c6++) { _v7 = Field(_v_v2, _c6); camlidl_ml2c_var_ap_var_t(_v7, &v2[_c6], _ctx); } v4 = _c5; /* begin user-supplied calling sequence */ if (v3!=v4) caml_failwith("Abstract1.rename_array: arrays of different size"); _res = ap_abstract1_rename_array(man,false,a,v1,v2,v3); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_change_environment_with( value _v_man, value _v_a, value _v_v1, value _v_v2) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_environment_ptr v1; /*in*/ int v2; /*in*/ struct ap_abstract1_t _c1; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_v1, &v1, _ctx); v2 = Int_val(_v_v2); /* begin user-supplied calling sequence */ { ap_environment_t* oldenv = ap_environment_copy(a->env); ap_abstract1_t res = ap_abstract1_change_environment(man,true,a,v1,v2); value v = Field(_v_a,0); *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0; if (res.env==oldenv){ ap_environment_free(oldenv); } else { assert(res.env==v1); Store_field(_v_a,1,_v_v1); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract1_ap_abstract1_minimize_environment_with( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ struct ap_abstract1_t _c1; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); /* begin user-supplied calling sequence */ { ap_environment_t* oldenv = ap_environment_copy(a->env); ap_abstract1_t res = ap_abstract1_minimize_environment(man,true,a); value v = Field(_v_a,0); *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0; if (res.env==oldenv){ ap_environment_free(oldenv); } else { v = camlidl_apron_environment_ptr_c2ml(&res.env); Store_field(_v_a,1,v); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract1_ap_abstract1_rename_array_with( value _v_man, value _v_a, value _v_v1, value _v_v2) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_var_t *v1; /*in*/ ap_var_t *v2; /*in*/ unsigned int v3; /*in*/ unsigned int v4; /*in*/ struct ap_abstract1_t _c1; mlsize_t _c2; mlsize_t _c3; value _v4; mlsize_t _c5; mlsize_t _c6; value _v7; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); _c2 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c2 * sizeof(ap_var_t ), _ctx); for (_c3 = 0; _c3 < _c2; _c3++) { _v4 = Field(_v_v1, _c3); camlidl_ml2c_var_ap_var_t(_v4, &v1[_c3], _ctx); } v3 = _c2; _c5 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c5 * sizeof(ap_var_t ), _ctx); for (_c6 = 0; _c6 < _c5; _c6++) { _v7 = Field(_v_v2, _c6); camlidl_ml2c_var_ap_var_t(_v7, &v2[_c6], _ctx); } v4 = _c5; /* begin user-supplied calling sequence */ if (v3!=v4) caml_failwith("Abstract1.rename_array_with: arrays of different size"); { ap_environment_t* oldenv = ap_environment_copy(a->env); ap_abstract1_t res = ap_abstract1_rename_array(man,true,a,v1,v2,v3); value v = Field(_v_a,0); *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0; if (res.env==oldenv){ ap_environment_free(oldenv); } else { v = camlidl_apron_environment_ptr_c2ml(&res.env); Store_field(_v_a,1,v); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract1_ap_abstract1_expand( value _v_man, value _v_a, value _v_v1, value _v_v2) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_var_t v1; /*in*/ ap_var_t *v2; /*in*/ int v3; /*in*/ struct ap_abstract1_t _res; struct ap_abstract1_t _c1; mlsize_t _c2; mlsize_t _c3; value _v4; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); camlidl_ml2c_var_ap_var_t(_v_v1, &v1, _ctx); _c2 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c2 * sizeof(ap_var_t ), _ctx); for (_c3 = 0; _c3 < _c2; _c3++) { _v4 = Field(_v_v2, _c3); camlidl_ml2c_var_ap_var_t(_v4, &v2[_c3], _ctx); } v3 = _c2; /* begin user-supplied calling sequence */ _res = ap_abstract1_expand(man,false,a,v1,v2,v3); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_fold( value _v_man, value _v_a, value _v_v1) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_var_t *v1; /*in*/ int v2; /*in*/ struct ap_abstract1_t _res; struct ap_abstract1_t _c1; mlsize_t _c2; mlsize_t _c3; value _v4; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); _c2 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c2 * sizeof(ap_var_t ), _ctx); for (_c3 = 0; _c3 < _c2; _c3++) { _v4 = Field(_v_v1, _c3); camlidl_ml2c_var_ap_var_t(_v4, &v1[_c3], _ctx); } v2 = _c2; /* begin user-supplied calling sequence */ _res = ap_abstract1_fold(man,false,a,v1,v2); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_expand_with( value _v_man, value _v_a, value _v_v1, value _v_v2) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_var_t v1; /*in*/ ap_var_t *v2; /*in*/ int v3; /*in*/ struct ap_abstract1_t _c1; mlsize_t _c2; mlsize_t _c3; value _v4; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); camlidl_ml2c_var_ap_var_t(_v_v1, &v1, _ctx); _c2 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c2 * sizeof(ap_var_t ), _ctx); for (_c3 = 0; _c3 < _c2; _c3++) { _v4 = Field(_v_v2, _c3); camlidl_ml2c_var_ap_var_t(_v4, &v2[_c3], _ctx); } v3 = _c2; /* begin user-supplied calling sequence */ { ap_environment_t* oldenv = ap_environment_copy(a->env); ap_abstract1_t res = ap_abstract1_expand(man,true,a,v1,v2,v3); value v = Field(_v_a,0); *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0; if (res.env==oldenv){ ap_environment_free(oldenv); } else { v = camlidl_apron_environment_ptr_c2ml(&res.env); Store_field(_v_a,1,v); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract1_ap_abstract1_fold_with( value _v_man, value _v_a, value _v_v1) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ ap_var_t *v1; /*in*/ int v2; /*in*/ struct ap_abstract1_t _c1; mlsize_t _c2; mlsize_t _c3; value _v4; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); _c2 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c2 * sizeof(ap_var_t ), _ctx); for (_c3 = 0; _c3 < _c2; _c3++) { _v4 = Field(_v_v1, _c3); camlidl_ml2c_var_ap_var_t(_v4, &v1[_c3], _ctx); } v2 = _c2; /* begin user-supplied calling sequence */ { ap_environment_t* oldenv = ap_environment_copy(a->env); ap_abstract1_t res = ap_abstract1_fold(man,true,a,v1,v2); value v = Field(_v_a,0); *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0; if (res.env==oldenv){ ap_environment_free(oldenv); } else { v = camlidl_apron_environment_ptr_c2ml(&res.env); Store_field(_v_a,1,v); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract1_ap_abstract1_widening( value _v_man, value _v_a1, value _v_a2) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a1; /*in*/ struct ap_abstract1_t *a2; /*in*/ struct ap_abstract1_t _res; struct ap_abstract1_t _c1; struct ap_abstract1_t _c2; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a1 = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a1, &_c1, _ctx); a2 = &_c2; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a2, &_c2, _ctx); _res = ap_abstract1_widening(man, a1, a2); _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_widening_threshold( value _v_man, value _v_a1, value _v_a2, value _v_v) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a1; /*in*/ struct ap_abstract1_t *a2; /*in*/ struct ap_lincons1_array_t *v; /*in*/ struct ap_abstract1_t _res; struct ap_abstract1_t _c1; struct ap_abstract1_t _c2; struct ap_lincons1_array_t _c3; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a1 = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a1, &_c1, _ctx); a2 = &_c2; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a2, &_c2, _ctx); v = &_c3; camlidl_ml2c_lincons1_struct_ap_lincons1_array_t(_v_v, &_c3, _ctx); _res = ap_abstract1_widening_threshold(man, a1, a2, v); _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_closure( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ struct ap_abstract1_t _res; struct ap_abstract1_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); /* begin user-supplied calling sequence */ _res = ap_abstract1_closure(man,false,a); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_closure_with( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a; /*in*/ struct ap_abstract1_t _c1; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a, &_c1, _ctx); /* begin user-supplied calling sequence */ { ap_abstract1_t res = ap_abstract1_closure(man,true,a); value v = Field(_v_a,0); *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract1_ap_abstract1_unify( value _v_man, value _v_a1, value _v_a2) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a1; /*in*/ struct ap_abstract1_t *a2; /*in*/ struct ap_abstract1_t _res; struct ap_abstract1_t _c1; struct ap_abstract1_t _c2; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a1 = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a1, &_c1, _ctx); a2 = &_c2; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a2, &_c2, _ctx); /* begin user-supplied calling sequence */ _res = ap_abstract1_unify(man,false,a1,a2); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract1_struct_ap_abstract1_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract1_ap_abstract1_unify_with( value _v_man, value _v_a1, value _v_a2) { ap_manager_ptr man; /*in*/ struct ap_abstract1_t *a1; /*in*/ struct ap_abstract1_t *a2; /*in*/ struct ap_abstract1_t _c1; struct ap_abstract1_t _c2; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); a1 = &_c1; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a1, &_c1, _ctx); a2 = &_c2; camlidl_ml2c_abstract1_struct_ap_abstract1_t(_v_a2, &_c2, _ctx); /* begin user-supplied calling sequence */ { ap_abstract1_t res = ap_abstract1_unify(man,true,a1,a2); value v = Field(_v_a1,0); *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0; v = Field(_v_a1,1); *((ap_environment_ptr *) Data_custom_val(v)) = res.env; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } apron-dist-0.9.10/apron/mlapronidl/apron_lexer.mli0000640014525101416610000000042610644465427022064 0ustar bjeannetpopart(* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) (** Lexical analysis of expressions, constraints, generators *) exception Error of int * int val lex: Lexing.lexbuf -> Apron_parser.token apron-dist-0.9.10/apron/mlapronidl/coeff_caml.c0000640014525101416610000000621411252216515021252 0ustar bjeannetpopart/* File generated from coeff.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include #include "ap_coeff.h" #include "apron_caml.h" #define Scalar AP_COEFF_SCALAR #define Interval AP_COEFF_INTERVAL extern void camlidl_apron_scalar_ml2c(value, ap_scalar_t *); #define camlidl_ml2c_scalar_ap_scalar_t(v,c,ctx) camlidl_apron_scalar_ml2c(v,c) extern value camlidl_apron_scalar_c2ml(ap_scalar_t *); #define camlidl_c2ml_scalar_ap_scalar_t(c,ctx) camlidl_apron_scalar_c2ml(c) extern void camlidl_ml2c_scalar_ap_scalar_ptr(value, ap_scalar_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_ap_scalar_ptr(ap_scalar_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_scalar_struct_ap_scalar_array_t(value, struct ap_scalar_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_struct_ap_scalar_array_t(struct ap_scalar_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_t(value, struct ap_interval_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_t(struct ap_interval_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_ap_interval_ptr(value, ap_interval_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_ap_interval_ptr(ap_interval_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_array_t(value, struct ap_interval_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_array_t(struct ap_interval_array_t *, camlidl_ctx _ctx); void camlidl_ml2c_coeff_struct_ap_coeff_t(value _v1, struct ap_coeff_t * _c2, camlidl_ctx _ctx) { value _v3; value _v4; switch (Tag_val(_v1)) { case 0: /* Scalar */ (*_c2).discr = Scalar; _v3 = Field(_v1, 0); (*_c2).val.scalar = (ap_scalar_t *) camlidl_malloc(sizeof(ap_scalar_t ), _ctx); camlidl_ml2c_scalar_ap_scalar_t(_v3, &*(*_c2).val.scalar, _ctx); break; case 1: /* Interval */ (*_c2).discr = Interval; _v4 = Field(_v1, 0); (*_c2).val.interval = (struct ap_interval_t *) camlidl_malloc(sizeof(struct ap_interval_t ), _ctx); camlidl_ml2c_interval_struct_ap_interval_t(_v4, &*(*_c2).val.interval, _ctx); break; } } value camlidl_c2ml_coeff_struct_ap_coeff_t(struct ap_coeff_t * _c1, camlidl_ctx _ctx) { value _v2; value _v3; value _v4; switch ((*_c1).discr) { case Scalar: _v3 = camlidl_c2ml_scalar_ap_scalar_t(&*(*_c1).val.scalar, _ctx); Begin_root(_v3) _v2 = camlidl_alloc_small(1, 0); Field(_v2, 0) = _v3; End_roots() break; case Interval: _v4 = camlidl_c2ml_interval_struct_ap_interval_t(&*(*_c1).val.interval, _ctx); Begin_root(_v4) _v2 = camlidl_alloc_small(1, 1); Field(_v2, 0) = _v4; End_roots() break; default: invalid_argument("struct ap_coeff_t: bad discriminant for union "); } return _v2; } apron-dist-0.9.10/apron/mlapronidl/texpr0_caml.c0000640014525101416610000003320311252216515021410 0ustar bjeannetpopart/* File generated from texpr0.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include #include "ap_texpr0.h" #include "apron_caml.h" value camlidl_texpr0_ap_texpr0_to_expr_c2ml(ap_texpr0_t* expr, camlidl_ctx _ctx) { value _v_res; switch(expr->discr){ case AP_TEXPR_CST: { value v0 = Val_unit; Begin_root(v0); v0 = camlidl_c2ml_coeff_struct_ap_coeff_t(&expr->val.cst, _ctx); _v_res = caml_alloc_small(1,0); Field(_v_res,0) = v0; End_roots(); } break; case AP_TEXPR_DIM: _v_res = caml_alloc_small(1,1); Field(_v_res,0) = Val_int(expr->val.dim); break; case AP_TEXPR_NODE: { value v0,v1,v2,v3,v4; v0 = v1 = v2 = v3 = v4 = Val_unit; Begin_roots5(v0,v1,v2,v3,v4); ap_texpr0_node_t* node = expr->val.node; v1 = camlidl_texpr0_ap_texpr0_to_expr_c2ml(node->exprA,_ctx); v3 = camlidl_apron_texpr_rtype_t_c2ml(&node->type); v4 = camlidl_apron_texpr_rdir_t_c2ml(&node->dir); if (ap_texpr_is_unop(node->op)){ v0 = camlidl_apron_texpr_unop_t_c2ml(&node->op); _v_res = caml_alloc_small(4,2); Field(_v_res,0) = v0; Field(_v_res,1) = v1; Field(_v_res,2) = v3; Field(_v_res,3) = v4; } else { v0 = camlidl_apron_texpr_binop_t_c2ml(&node->op); v2 = camlidl_texpr0_ap_texpr0_to_expr_c2ml(node->exprB,_ctx); _v_res = caml_alloc_small(5,3); Field(_v_res,0) = v0; Field(_v_res,1) = v1; Field(_v_res,2) = v2; Field(_v_res,3) = v3; Field(_v_res,4) = v4; } End_roots(); } break; default: abort(); } return _v_res; } value camlidl_texpr0_ap_texpr0_to_expr(value _v_texpr) { CAMLparam1(_v_texpr); CAMLlocal1(_v_res); ap_texpr0_t* expr; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_apron_texpr0_ptr_ml2c(_v_texpr,&expr); _v_res = camlidl_texpr0_ap_texpr0_to_expr_c2ml(expr,_ctx); camlidl_free(_ctx); CAMLreturn(_v_res); } void camlidl_texpr0_ap_texpr0_of_expr_ml2c(value v, ap_texpr0_t** res, camlidl_ctx _ctx) { ap_texpr0_t* texpr; ap_texpr0_node_t* node; ap_coeff_t coeff; value v0,v1,v2,v3,v4; texpr = malloc(sizeof(ap_texpr0_t)); assert (Is_block(v)); switch (Tag_val(v)){ case 0: /* Constant */ assert(Wosize_val(v)==1); v0 = Field(v,0); texpr->discr = AP_TEXPR_CST; camlidl_ml2c_coeff_struct_ap_coeff_t(v0,&coeff,_ctx); ap_coeff_init_set(&texpr->val.cst,&coeff); break; case 1: /* Dimension */ assert(Wosize_val(v)==1); v0 = Field(v,0); texpr->discr = AP_TEXPR_DIM; texpr->val.dim = Int_val(v0); break; case 2: /* Unary node */ v0 = Field(v,0); v1 = Field(v,1); v2 = Field(v,2); v3 = Field(v,3); node = malloc(sizeof(ap_texpr0_node_t)); camlidl_apron_texpr_unop_t_ml2c (v0,&node->op); camlidl_texpr0_ap_texpr0_of_expr_ml2c(v1,&node->exprA,_ctx); camlidl_apron_texpr_rtype_t_ml2c (v2,&node->type); camlidl_apron_texpr_rdir_t_ml2c (v3,&node->dir); node->exprB = NULL; texpr->discr = AP_TEXPR_NODE; texpr->val.node = node; break; case 3: /* Binary node */ v0 = Field(v,0); v1 = Field(v,1); v2 = Field(v,2); v3 = Field(v,3); v4 = Field(v,4); node = malloc(sizeof(ap_texpr0_node_t)); camlidl_apron_texpr_binop_t_ml2c (v0,&node->op); camlidl_texpr0_ap_texpr0_of_expr_ml2c(v1,&node->exprA,_ctx); camlidl_texpr0_ap_texpr0_of_expr_ml2c(v2,&node->exprB,_ctx); camlidl_apron_texpr_rtype_t_ml2c (v3,&node->type); camlidl_apron_texpr_rdir_t_ml2c (v4,&node->dir); texpr->discr = AP_TEXPR_NODE; texpr->val.node = node; break; default: assert(false); } *res = texpr; } value camlidl_texpr0_ap_texpr0_of_expr(value _v_expr) { CAMLparam1(_v_expr); CAMLlocal1(_v_res); ap_texpr0_t* res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_texpr0_ap_texpr0_of_expr_ml2c(_v_expr,&res,_ctx); _v_res = camlidl_apron_texpr0_ptr_c2ml(&res); camlidl_free(_ctx); CAMLreturn(_v_res); } extern void camlidl_apron_scalar_ml2c(value, ap_scalar_t *); #define camlidl_ml2c_scalar_ap_scalar_t(v,c,ctx) camlidl_apron_scalar_ml2c(v,c) extern value camlidl_apron_scalar_c2ml(ap_scalar_t *); #define camlidl_c2ml_scalar_ap_scalar_t(c,ctx) camlidl_apron_scalar_c2ml(c) extern void camlidl_ml2c_scalar_ap_scalar_ptr(value, ap_scalar_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_ap_scalar_ptr(ap_scalar_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_scalar_struct_ap_scalar_array_t(value, struct ap_scalar_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_struct_ap_scalar_array_t(struct ap_scalar_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_t(value, struct ap_interval_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_t(struct ap_interval_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_ap_interval_ptr(value, ap_interval_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_ap_interval_ptr(ap_interval_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_array_t(value, struct ap_interval_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_array_t(struct ap_interval_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_coeff_struct_ap_coeff_t(value, struct ap_coeff_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_coeff_struct_ap_coeff_t(struct ap_coeff_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_ap_dim_t(value, ap_dim_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_ap_dim_t(ap_dim_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimchange_t(value, struct ap_dimchange_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange_t(struct ap_dimchange_t *, camlidl_ctx _ctx); extern void camlidl_apron_dimchange_ml2c(value, ap_dimchange_t *); #define camlidl_ml2c_dim_ap_dimchange_t(v,c,ctx) camlidl_apron_dimchange_ml2c(v,c) extern value camlidl_apron_dimchange_c2ml(ap_dimchange_t *); #define camlidl_c2ml_dim_ap_dimchange_t(c,ctx) camlidl_apron_dimchange_c2ml(c) extern void camlidl_ml2c_dim_struct_ap_dimchange2_t(value, struct ap_dimchange2_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange2_t(struct ap_dimchange2_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimperm_t(value, struct ap_dimperm_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimperm_t(struct ap_dimperm_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimension_t(value, struct ap_dimension_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimension_t(struct ap_dimension_t *, camlidl_ctx _ctx); extern void camlidl_apron_linexpr0_ptr_ml2c(value, ap_linexpr0_ptr *); #define camlidl_ml2c_linexpr0_ap_linexpr0_ptr(v,c,ctx) camlidl_apron_linexpr0_ptr_ml2c(v,c) extern value camlidl_apron_linexpr0_ptr_c2ml(ap_linexpr0_ptr *); #define camlidl_c2ml_linexpr0_ap_linexpr0_ptr(c,ctx) camlidl_apron_linexpr0_ptr_c2ml(c) #define camlidl_ml2c_texpr0_ap_texpr0_ptr(v,c,ctx) camlidl_apron_texpr0_ptr_ml2c(v,c) #define camlidl_c2ml_texpr0_ap_texpr0_ptr(c,ctx) camlidl_apron_texpr0_ptr_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_op_t(value, ap_texpr_op_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_op_t(ap_texpr_op_t *, camlidl_ctx _ctx); #define camlidl_ml2c_texpr0_ap_texpr_unop_t(v,c,ctx) camlidl_apron_texpr_unop_t_ml2c(v,c) #define camlidl_c2ml_texpr0_ap_texpr_unop_t(c,ctx) camlidl_apron_texpr_unop_t_c2ml(c) #define camlidl_ml2c_texpr0_ap_texpr_binop_t(v,c,ctx) camlidl_apron_texpr_binop_t_ml2c(v,c) #define camlidl_c2ml_texpr0_ap_texpr_binop_t(c,ctx) camlidl_apron_texpr_binop_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rtype_t(value, ap_texpr_rtype_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rtype_t(ap_texpr_rtype_t *, camlidl_ctx _ctx); #define camlidl_ml2c_texpr0_ap_texpr_rtype_t(v,c,ctx) camlidl_apron_texpr_rtype_t_ml2c(v,c) #define camlidl_c2ml_texpr0_ap_texpr_rtype_t(c,ctx) camlidl_apron_texpr_rtype_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rdir_t(value, ap_texpr_rdir_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rdir_t(ap_texpr_rdir_t *, camlidl_ctx _ctx); #define camlidl_ml2c_texpr0_ap_texpr_rdir_t(v,c,ctx) camlidl_apron_texpr_rdir_t_ml2c(v,c) #define camlidl_c2ml_texpr0_ap_texpr_rdir_t(c,ctx) camlidl_apron_texpr_rdir_t_c2ml(c) value camlidl_texpr0_ap_texpr0_copy( value _v_a) { ap_texpr0_ptr a; /*in*/ ap_texpr0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_texpr0_ap_texpr0_ptr(_v_a, &a, _ctx); _res = ap_texpr0_copy(a); _vres = camlidl_c2ml_texpr0_ap_texpr0_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_texpr0_ap_texpr0_of_linexpr( value _v_e) { ap_linexpr0_ptr e; /*in*/ ap_texpr0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_linexpr0_ap_linexpr0_ptr(_v_e, &e, _ctx); /* begin user-supplied calling sequence */ _res = ap_texpr0_from_linexpr0(e); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_texpr0_ap_texpr0_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_texpr0_ap_texpr0_cst( value _v_coeff) { struct ap_coeff_t *coeff; /*in*/ ap_texpr0_ptr _res; struct ap_coeff_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; coeff = &_c1; camlidl_ml2c_coeff_struct_ap_coeff_t(_v_coeff, &_c1, _ctx); _res = ap_texpr0_cst(coeff); _vres = camlidl_c2ml_texpr0_ap_texpr0_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_texpr0_ap_texpr0_dim( value _v_dim) { ap_dim_t dim; /*in*/ ap_texpr0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_dim_ap_dim_t(_v_dim, &dim, _ctx); _res = ap_texpr0_dim(dim); _vres = camlidl_c2ml_texpr0_ap_texpr0_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_texpr0_ap_texpr0_unop( value _v_op, value _v_expr, value _v_type, value _v_dir) { ap_texpr_unop_t op; /*in*/ ap_texpr0_ptr expr; /*in*/ ap_texpr_rtype_t type; /*in*/ ap_texpr_rdir_t dir; /*in*/ ap_texpr0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_texpr0_ap_texpr_unop_t(_v_op, &op, _ctx); camlidl_ml2c_texpr0_ap_texpr0_ptr(_v_expr, &expr, _ctx); camlidl_ml2c_texpr0_ap_texpr_rtype_t(_v_type, &type, _ctx); camlidl_ml2c_texpr0_ap_texpr_rdir_t(_v_dir, &dir, _ctx); /* begin user-supplied calling sequence */ _res = ap_texpr0_unop(op,ap_texpr0_copy(expr),type,dir); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_texpr0_ap_texpr0_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_texpr0_ap_texpr0_binop( value _v_op, value _v_type, value _v_dir, value _v_exprA, value _v_exprB) { ap_texpr_binop_t op; /*in*/ ap_texpr_rtype_t type; /*in*/ ap_texpr_rdir_t dir; /*in*/ ap_texpr0_ptr exprA; /*in*/ ap_texpr0_ptr exprB; /*in*/ ap_texpr0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_texpr0_ap_texpr_binop_t(_v_op, &op, _ctx); camlidl_ml2c_texpr0_ap_texpr_rtype_t(_v_type, &type, _ctx); camlidl_ml2c_texpr0_ap_texpr_rdir_t(_v_dir, &dir, _ctx); camlidl_ml2c_texpr0_ap_texpr0_ptr(_v_exprA, &exprA, _ctx); camlidl_ml2c_texpr0_ap_texpr0_ptr(_v_exprB, &exprB, _ctx); /* begin user-supplied calling sequence */ _res = ap_texpr0_binop(op,ap_texpr0_copy(exprA),ap_texpr0_copy(exprB),type,dir); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_texpr0_ap_texpr0_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_texpr0_ap_texpr0_is_interval_cst( value _v_a) { ap_texpr0_ptr a; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_texpr0_ap_texpr0_ptr(_v_a, &a, _ctx); _res = ap_texpr0_is_interval_cst(a); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_texpr0_ap_texpr0_is_interval_linear( value _v_a) { ap_texpr0_ptr a; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_texpr0_ap_texpr0_ptr(_v_a, &a, _ctx); _res = ap_texpr0_is_interval_linear(a); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_texpr0_ap_texpr0_is_interval_polynomial( value _v_a) { ap_texpr0_ptr a; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_texpr0_ap_texpr0_ptr(_v_a, &a, _ctx); _res = ap_texpr0_is_interval_polynomial(a); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_texpr0_ap_texpr0_is_interval_polyfrac( value _v_a) { ap_texpr0_ptr a; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_texpr0_ap_texpr0_ptr(_v_a, &a, _ctx); _res = ap_texpr0_is_interval_polyfrac(a); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_texpr0_ap_texpr0_is_scalar( value _v_a) { ap_texpr0_ptr a; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_texpr0_ap_texpr0_ptr(_v_a, &a, _ctx); _res = ap_texpr0_is_scalar(a); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } apron-dist-0.9.10/apron/mlapronidl/introduction.mli0000640014525101416610000003425111252510634022255 0ustar bjeannetpopart(** *) (** This package is an OCaml interface for the APRON library/interface. The interface is accessed via the module Apron, which is decomposed into 15 submodules, corresponding to C modules, and which can be organized in 4 groups {ol {- {b Coefficients}: scalar numbers, intervals, ... } {- {b Managers and Abstract Domains} {ul {- {!module: Manager}: managers} {- {!module: Box}: interval domain} {- {!module: Oct}: octagon domain} {- {!module: Polka}: convex polyhedra and linear equalities domains} {- {!module: Ppl}: PPL convex polyhedra and linear congruences domains} {- {!module: PolkaGrid}: reduced product of convex polyhedra and PPL linear congruences} } } {- {b Level 1 of the interface (user-level)}: manipulation of generic datatypes (expressions, constraints, ..., and generic abstract domain interface)} {- {b Level 0 of the interface (lower-level)}: manipulation of generic datatypes (expressions, constraints, ..., and generic abstract domain interface)} } *) (* ********************************************************************** *) (** {2 Requirements and installation} *) (* ********************************************************************** *) (** (See README of general APRON distribution for more details) {ul {- APRON library} {- GMP library version 4.2 or up (tested with version 4.2.1 and 4.3.1)} {- MPFR library version 2.2 or up (tested with version 2.2.1 and 2.3.1)} {- MLGMPIDL to GMP and MPFR libraries} {- OCaml 3.09 or up} {- Camlidl (tested with 1.05)} } For compiling from repository (strongly recommended): {ul {- GNU M4 preprocessor} {- GNU sed} } It is important to have the GNU versions ! *) (* ====================================================================== *) (** {3 Installation} *) (* ====================================================================== *) (** {ul {- {b Library}: Set the file [../Makefile.config] to your own setting. type 'make', and then 'make install' The OCaml part of the library is named [apron.cma] ([.cmxa], [.a]). The C part of the library, which is automatically referenced by [apron.cma/apron.cmxa], is named [libapron_caml.a], [libapron_caml.so], [dllapron_caml.so] (which is a soft link to the previous library) (debug versions: [libapron_caml_debug.a], [libapron_caml_debug.so], [dllapron_caml_debug.so]) 'make install' installs not only [.mli], [.cmi], but also [.idl] files. } {- {b Documentation}: The documentation is generated with ocamldoc. 'make mlapronidl.pdf' 'make html' (put the HTML files in the html subdirectoy) } {- {b Miscellaneous}: 'make clean' and 'make distclean' have the usual behaviour. } } *) (* ********************************************************************** *) (** {2:hints Hints on programming idioms} *) (* ********************************************************************** *) (* ====================================================================== *) (** {3 Allocating managers} *) (* ====================================================================== *) (** The user might have some difficulties to exploit the genericity of the interface at first glance (it was actually my case). Assume your main analysis function looks like: {[let analyze_and_display equations (man : 'a Apron.Manager.t) : unit = ... ]} where [equations] is the equation system, [man] the APRON manager, and ['a] the effective abstract domain/implementation to be used in the analysis. {ol {- You might want to write code like {[let manager_alloc option = match option with | `Box -> Box.manager_alloc () | `Oct -> Oct.manager_alloc () ;; let main option equations = let man = manager_alloc opt in analyze_and_display man equations ;;]} but this does not work because [manager_alloc] cannot be typed (the types of [(Box.manager_alloc ()) : Box.t Apron.Manager.t] and [(Oct.manager_alloc ()) : Oct.t Apron.Manager.t] cannot be unified). } {- Using continuations does not work either: {[let manager_alloc_and_continue option (continuation:'a Apron.Manager.t -> 'b) = match option with | `Box -> continuation (Box.manager_alloc ()) | `Oct -> continuation (Oct.manager_alloc ()) ;; let main option equations = manager_alloc_and_continue option (fun apron -> analyze_and_display equations equations apron) ;;]} but this does not work because the argument [continuation] is monomorphic inside the body of [manager_alloc_and_continue] (i.e, it is not generalized): {[let manager_alloc_and_continue option (continuation:'a Apron.Manager.t -> 'b) = match option with | `Box -> continuation (Box.manager_alloc ()) | `Oct -> continuation (Oct.manager_alloc ()) ;; ^^^^^^^^^^^^^^^^^^^^ Error: This expression has type Oct.t Apron.Manager.t but an expression was expected of type Box.t Apron.Manager.t]} You can read detailed explanations about this issue on {{:http://caml.inria.fr/pub/old_caml_site/FAQ/FAQ_EXPERT-eng.html#arguments_polymorphes}OCaml FAQ}. } } I can suggest 3 solutions: {ol {- Following {{:http://caml.inria.fr/pub/old_caml_site/FAQ/FAQ_EXPERT-eng.html#arguments_polymorphes}OCaml FAQ}, you can modify attempt 2 above as follows: {[let manager_alloc_and_continue option equations = match option with | `Box -> analyze_and_display equations (Box.manager_alloc ()) | `Oct -> analyze_and_display equations (Oct.manager_alloc ()) ;; let main option equations = manager_alloc_and_continue option equations ;;]} Now this can be type-checked: {[val manager_alloc_and_continue : [< `Box | `Oct ] -> 'a -> unit = ]} This is not very elegant: the call to [analyze_and_display] is hard-coded in [manager_alloc_and_continue], and one has to pass all its arguments (like [equations]) to [manager_alloc_and_continue]. } {- It is possible to not give up with continuations by encapsulating them into a record (resp. an immediate object), because record fields (resp. methods) may be polymorphic. {ul {- Using records: {[type continuation = { f : 'a. 'a Apron.Manager.t -> unit; };; let manager_alloc_and_continue option (continuation:continuation) = match option with | `Box -> continuation.f (Box.manager_alloc ()) | `Oct -> continuation.f (Oct.manager_alloc ()) ;; let main option equations = manager_alloc_and_continue option {f = fun apron -> analyze_and_display equations apron} ;;]} } {- Using immediate objects: {[type continuation = < f : 'a. 'a Apron.Manager.t -> unit >;; let manager_alloc_and_continue option (continuation:continuation) = match option with | `Box -> continuation#f (Box.manager_alloc ()) | `Oct -> continuation#f (Oct.manager_alloc ()) ;; let main option equations = manager_alloc_and_continue option (object method f: 'a .'a Apron.Manager.t -> unit = fun apron -> analyze_and_display equations apron end) ;;]} Compared to records, using immediate objects requires to repeat polymorphic type annotations. On the other hand, one does not need to define a new type [continuation]: {[let manager_alloc_and_continue option (continuation:< f : 'a. 'a Apron.Manager.t -> unit >) match option with | `Box -> continuation#f (Box.manager_alloc ()) | `Oct -> continuation#f (Oct.manager_alloc ()) ;; let main option equations = manager_alloc_and_continue option (object method f: 'a .'a Apron.Manager.t -> unit = fun apron -> analyze_and_display equations apron end) ;;]} }}} {- A last possibility is to use the type conversion functions provided in {!module: Box} and {!module: Oct} (as well as in the other domain modules). One can modify attempt 1 as follows: {[let manager_alloc option = match option with | `Box -> Box.manager_of_box (Box.manager_alloc ()) | `Oct -> Oct.manager_of_oct (Oct.manager_alloc ()) ;; let main option equations = let man = manager_alloc opt in analyze_and_display man equations ;;]} {[val manager_alloc : [< `Box | `Oct ] -> 'a Apron.Manager.t = ]} The purpose of functions {!Box.manager_of_box} and {!Oct.manager_of_oct} is to generalize the type of their arguments (this is implemented with the [Obj.magic] function... but this is safe). This is the most simple and flexible way. } } *) (* ====================================================================== *) (** {3 Breaking (locally) genericity} *) (* ====================================================================== *) (** Assume that you are inside the body of the same {[analyze_and_display: equations -> 'a Apron.Manager.t -> unit]} function and that you want at some point - either to modify an option of the manager [man], depending on the effective underlying domain (like {!Polka.set_max_coeff_size}); - or similarly to perform a specific operation on an abstract value. You can modify the solution 1 above so as to pass a [modify: 'a Apron.Manager.t -> unit] function to [analyze_and_display]: {[let analyze_and_display equations (man : 'a Apron.Manager.t) (modify : 'a Apron.Manager.t -> unit) = ... ;; let manager_alloc_and_continue option equations = match option with | `Box -> analyze_and_display equations (Box.manager_alloc ()) box_modify | `Oct -> analyze_and_display equations (Oct.manager_alloc ()) oct_modify ;; let main option equations = manager_alloc_and_continue option equations ;;]} The most flexible way however is to use the ``dynamic cast'' functions {!Box.manager_to_box}, {!Box.Abstract0.to_box}, {!Oct.manager_to_oct}, {!Oct.Abstract0.to_oct}. These functions raise a [Failure] exception in case of (dynamic) typing error, but this can be avoided by the test functions {!Box.manager_is_box} and {!Oct.manager_is_oct} *) (* ********************************************************************** *) (** {2:compilation Compiling and linking client programs against APRON} *) (* ********************************************************************** *) (** To make things clearer, we assume an example file [mlexample.ml] which uses both NewPolka (convex polyhedra) and Box (intervals) libraries, in their versions where rationals are GMP rationals (which is the default). We assume that C and OCaml interface and library files are located in directory $APRON/lib. The native-code compilation command looks like {[ ocamlopt -I $APRON/lib -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa boxMPFR.cmxa polkaMPQ.cmxa mlexample.ml]} Comments: {ol {- You need at least the libraries [bigarray] (standard OCaml distribution), [gmp], and [apron] (standard APRON distribution), plus the one implementing an effective abstract domains: here, [boxMPFR], and [polkaMPQ].} {- The C libraries associated to those OCaml libraries (e.g., [gmp_caml], [boxMPFR_caml], \ldots) are automatically looked for, as well as the the libraries implementing abstract domains (e.g., [polkaMPQ], [boxMPFR]). If other versions of abstract domains library are wanted, you should use the [-noautolink] option as explained below.} {- If in [Makefile.config], the [HAS_SHARED] variable is set to a non-empty value, dynamic versions of those libraires are also available, but makes sure that all the needed libraries are in the dynamic search path indicated by [$LD_LIBRARY_PATH].} } If dynamic libraries are available, the byte-code compilation process looks like {[ ocamlc -I $MLGMPIDL/lib -I $APRON/lib -o mlexample.byte \ bigarray.cma gmp.cma apron.cma boxMPFR.cma polkaMPQ.cma mlexample.ml ]} Comments: {ol {- The ocamlrun bytecode interpreter will automatically load the dynamic libraries, using environment variables [$LD_LIBRARY_PATH] (and possibly [$CAML_LD_LIBRARY_PATH], see OCaml documentation, section on OCaml/C interface).} {- You can very easily use the interactive toplevel interpreter: type ['ocaml -I $MLGMPIDL/lib -I $APRON/lib'] and then enter: {[ #load "bigarray.cma";; #load "gmp.cma";; #load "apron.cma";; #load "polkaMPQ.cma";; ... ]} } {- This is also the only way to load and use in the OCaml debugger pretty-printers depending on C code, like {[ #load "bigarray.cma";; #load "gmp.cma";; #load "apron.cma";; #installl_printer Apron.Abstract1.print;; ]} } } If only static libraries are available, you can: {ol {- Create a custom runtime and use it as follows: {[ ocamlc -I $MLGMPIDL/lib -I $APRON/lib -make-runtime -o myrun \ bigarray.cma gmp.cma apron.cma boxMPFR.cma polkaMPQ.cma ocamlc -I $MLGMPIDL/lib -I $APRON/lib -use-runtime myrun -o \mlexample.byte \ bigarray.cma gmp.cma apron.cma box.cma polka.cma mlexample.ml ]} Comments: {ol {- One first build a custom bytecode interpreter that includes the new native-code needed; } {- One then compile the [mlexample.ml] file, using the generated bytecode interpreter. } } } {- If you want to use the interactive toplevel interpreter, you have to generate a custom toplevel interpreter using the [ocamlmktop] command (see OCaml documentation, section on OCaml/C interface): {[ ocamlmktop -I $MLGMPIDL/lib -I $APRON/lib -o mytop \ bigarray.cma gmp.cma apron.cma boxMPFR.cma polkaMPQ.cma ]} } } The automatic search for C libraries associated to these OCaml libraries can be disabled by the option [-noautolink] supported by both [ocamlc] and [ocamlopt] commands. For instance, the command for native-code compilation can alternatively looks like: {[ ocamlopt -I $MLGMPIDL/lib -I $APRON/lib -noautolink -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa boxMPFR.cmxa polkaMPQ.cmxa mlexample.ml \ -cclib "-L$MLGMPIDL/lib -L$APRON/lib \ -lpolkaMPQ_caml_debug -lpolkaMPQ_debug \ -lboxMPFR_caml_debug -lboxMPFR_debug \ -lapron_caml_debug -lapron_debug \ -lgmp_caml -L$MPFR -lmpfr -L$GMP/lib -lgmp \ -L$CAMLIDL/lib/ocaml -lcamlidl \ -lbigarray" ]} or more simply, if dynamic libraries are available (because some dynamic libraries are automatically referenced by others): {[ ocamlopt -I $MLGMPIDL/lib -I $APRON/lib -noautolink -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa boxMPFR.cmxa polkaMPQ.cmxa mlexample.ml \ -cclib "-L$MLGMPIDL/lib -L$APRON/lib \ -lpolkaMPQ_caml_debug \ -lboxMPFR_caml_debug \ -lapron_caml_debug \ -lgmp_caml \ -lbigarray" ]} This is mandatory if you want to use non-default versions of libraries (here, debug versions). The option [-verbose] helps to understand what is happening in case of problem. More details are given in the modules implementing a specific abstract domain. *) apron-dist-0.9.10/apron/mlapronidl/coeff.mli0000640014525101416610000000373711252216515020624 0ustar bjeannetpopart(* File generated from coeff.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type union_5 = | Scalar of Scalar.t | Interval of Interval.t and t = union_5 (** APRON Coefficients (either scalars or intervals) *) val s_of_mpq : Mpq.t -> t val s_of_mpqf : Mpqf.t -> t val s_of_int : int -> t val s_of_frac : int -> int -> t (** Create a scalar coefficient of type [Mpqf.t] from resp. - A multi-precision rational [Mpq.t] - A multi-precision rational [Mpqf.t] - an integer - a fraction [x/y] *) val s_of_float : float -> t (** Create an interval coefficient of type [Float] with the given value *) val s_of_mpfr : Mpfr.t -> t (** Create an interval coefficient of type [Mpfr] with the given value *) val i_of_scalar : Scalar.t -> Scalar.t -> t (** Build an interval from a lower and an upper bound *) val i_of_mpq : Mpq.t -> Mpq.t -> t val i_of_mpqf : Mpqf.t -> Mpqf.t -> t val i_of_int : int -> int -> t val i_of_frac : int -> int -> int -> int -> t val i_of_float : float -> float -> t val i_of_mpfr : Mpfr.t -> Mpfr.t -> t (** Create an interval coefficient from resp. two - multi-precision rationals [Mpq.t] - multi-precision rationals [Mpqf.t] - integers - fractions [x/y] and [z/w] - machine floats - Mpfr floats *) val is_scalar : t -> bool val is_interval : t -> bool val cmp : t -> t -> int (** Non Total Comparison: - If the 2 coefficients are both scalars, corresp. to Scalar.cmp - If the 2 coefficients are both intervals, corresp. to Interval.cmp - otherwise, -3 if the first is a scalar, 3 otherwise *) val equal : t -> t -> bool (** Equality test *) val is_zero : t -> bool (** Is the coefficient equal to scalar 0 or interval [0,0] ? *) val equal_int : t -> int -> bool (** Is the coefficient equal to scalar b or interval [b,b] ? *) val neg : t -> t (** Negation *) val reduce : t -> t (** Convert interval to scalar if possible *) val print : Format.formatter -> t -> unit (** Printing *) apron-dist-0.9.10/apron/mlapronidl/linexpr0.ml0000640014525101416610000000532211252216515021122 0ustar bjeannetpopart(* File generated from linexpr0.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t external make : int option -> t = "camlidl_linexpr0_ap_linexpr0_make" external minimize : t -> unit = "camlidl_linexpr0_ap_linexpr0_minimize" external copy : t -> t = "camlidl_linexpr0_ap_linexpr0_copy" external compare : t -> t -> int = "camlidl_linexpr0_ap_linexpr0_compare" external hash : t -> int = "camlidl_linexpr0_ap_linexpr0_hash" external get_size : t -> int = "camlidl_linexpr0_ap_linexpr0_get_size" external get_cst : t -> Coeff.t = "camlidl_linexpr0_ap_linexpr0_get_cst" external get_coeff : t -> int -> Coeff.t = "camlidl_linexpr0_ap_linexpr0_get_coeff" external set_cst : t -> Coeff.t -> unit = "camlidl_linexpr0_ap_linexpr0_set_cst" external set_coeff : t -> int -> Coeff.t -> unit = "camlidl_linexpr0_ap_linexpr0_set_coeff" external iter: (Coeff.t -> Dim.t -> unit) -> t -> unit = "camlidl_expr0_linexpr0_iter" let set_list expr list ocst = List.iter (fun (coeff,dim) -> set_coeff expr dim coeff ) list; begin match ocst with | Some cst -> set_cst expr cst | None -> () end; () let set_array expr tab ocst = Array.iter (fun (coeff,dim) -> set_coeff expr dim coeff ) tab; begin match ocst with | Some cst -> set_cst expr cst | None -> () end; () let of_list osize list ocst = let expr = make osize in set_list expr list ocst; expr let of_array osize tab ocst = let expr = make osize in set_array expr tab ocst; expr let print assoc fmt expr = Format.fprintf fmt "@["; let first = ref true in iter (begin fun coeff dim -> let coeff = Coeff.reduce coeff in let sgn = match coeff with | Coeff.Scalar x -> Scalar.sgn x | Coeff.Interval i -> if Interval.is_zero i then 0 else 1 in if sgn <> 0 then begin if not !first then Format.fprintf fmt "@,"; if sgn>0 then begin if not !first then Format.pp_print_string fmt "+"; end; begin match coeff with | Coeff.Scalar scalar -> if Scalar.equal_int scalar (-1) then Format.pp_print_string fmt "-" else if not (Scalar.equal_int scalar 1) then Scalar.print fmt scalar; | Coeff.Interval i -> Interval.print fmt i end; Format.pp_print_string fmt (assoc dim); first := false; end; end) expr; begin match get_cst expr with | Coeff.Scalar scalar -> let sgn = Scalar.sgn scalar in if sgn <> 0 then begin if not !first then Format.fprintf fmt "@,"; if sgn>0 && not !first then Format.pp_print_char fmt '+'; Scalar.print fmt scalar; end else if !first then Format.pp_print_char fmt '0'; | Coeff.Interval i -> if not (Interval.is_zero i) then begin if not !first then Format.pp_print_char fmt '+'; Interval.print fmt i end else if !first then Format.pp_print_char fmt '0'; end; Format.fprintf fmt "@]"; () apron-dist-0.9.10/apron/mlapronidl/dim_caml.c0000640014525101416610000000757111252216515020750 0ustar bjeannetpopart/* File generated from dim.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include #include "ap_dimension.h" #include "caml/mlvalues.h" #include "apron_caml.h" void camlidl_ml2c_dim_ap_dim_t(value _v1, ap_dim_t * _c2, camlidl_ctx _ctx) { (*_c2) = Int_val(_v1); } value camlidl_c2ml_dim_ap_dim_t(ap_dim_t * _c2, camlidl_ctx _ctx) { value _v1; _v1 = Val_int((*_c2)); return _v1; } extern void camlidl_ml2c_dim_struct_ap_dimchange_t(value, struct ap_dimchange_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange_t(struct ap_dimchange_t *, camlidl_ctx _ctx); #define camlidl_ml2c_dim_ap_dimchange_t(v,c,ctx) camlidl_apron_dimchange_ml2c(v,c) #define camlidl_c2ml_dim_ap_dimchange_t(c,ctx) camlidl_apron_dimchange_c2ml(c) void camlidl_ml2c_dim_struct_ap_dimchange2_t(value _v1, struct ap_dimchange2_t * _c2, camlidl_ctx _ctx) { value _v3; value _v4; value _v5; value _v6; _v3 = Field(_v1, 0); if (_v3 == Val_int(0)) { (*_c2).add = NULL; } else { _v4 = Field(_v3, 0); (*_c2).add = (ap_dimchange_t *) camlidl_malloc(sizeof(ap_dimchange_t ), _ctx); camlidl_ml2c_dim_ap_dimchange_t(_v4, &*(*_c2).add, _ctx); } _v5 = Field(_v1, 1); if (_v5 == Val_int(0)) { (*_c2).remove = NULL; } else { _v6 = Field(_v5, 0); (*_c2).remove = (ap_dimchange_t *) camlidl_malloc(sizeof(ap_dimchange_t ), _ctx); camlidl_ml2c_dim_ap_dimchange_t(_v6, &*(*_c2).remove, _ctx); } } value camlidl_c2ml_dim_struct_ap_dimchange2_t(struct ap_dimchange2_t * _c1, camlidl_ctx _ctx) { value _v2; value _v3[2]; value _v4; value _v5; _v3[0] = _v3[1] = 0; Begin_roots_block(_v3, 2) if ((*_c1).add == NULL) { _v3[0] = Val_int(0); } else { _v4 = camlidl_c2ml_dim_ap_dimchange_t(&*(*_c1).add, _ctx); Begin_root(_v4) _v3[0] = camlidl_alloc_small(1, 0); Field(_v3[0], 0) = _v4; End_roots(); } if ((*_c1).remove == NULL) { _v3[1] = Val_int(0); } else { _v5 = camlidl_c2ml_dim_ap_dimchange_t(&*(*_c1).remove, _ctx); Begin_root(_v5) _v3[1] = camlidl_alloc_small(1, 0); Field(_v3[1], 0) = _v5; End_roots(); } _v2 = camlidl_alloc_small(2, 0); Field(_v2, 0) = _v3[0]; Field(_v2, 1) = _v3[1]; End_roots() return _v2; } void camlidl_ml2c_dim_struct_ap_dimperm_t(value _v1, struct ap_dimperm_t * _c2, camlidl_ctx _ctx) { mlsize_t _c3; mlsize_t _c4; value _v5; _c3 = Wosize_val(_v1); (*_c2).dim = camlidl_malloc(_c3 * sizeof(unsigned int ), _ctx); for (_c4 = 0; _c4 < _c3; _c4++) { _v5 = Field(_v1, _c4); (*_c2).dim[_c4] = Int_val(_v5); } (*_c2).size = _c3; } value camlidl_c2ml_dim_struct_ap_dimperm_t(struct ap_dimperm_t * _c1, camlidl_ctx _ctx) { value _v2; mlsize_t _c3; value _v4; _v2 = camlidl_alloc((*_c1).size, 0); for (_c3 = 0; _c3 < (*_c1).size; _c3++) { _v4 = Val_int((*_c1).dim[_c3]); modify(&Field(_v2, _c3), _v4); } return _v2; } void camlidl_ml2c_dim_struct_ap_dimension_t(value _v1, struct ap_dimension_t * _c2, camlidl_ctx _ctx) { value _v3; value _v4; _v3 = Field(_v1, 0); (*_c2).intdim = Int_val(_v3); _v4 = Field(_v1, 1); (*_c2).realdim = Int_val(_v4); } value camlidl_c2ml_dim_struct_ap_dimension_t(struct ap_dimension_t * _c1, camlidl_ctx _ctx) { value _v2; value _v3[2]; _v3[0] = _v3[1] = 0; Begin_roots_block(_v3, 2) _v3[0] = Val_int((*_c1).intdim); _v3[1] = Val_int((*_c1).realdim); _v2 = camlidl_alloc_small(2, 0); Field(_v2, 0) = _v3[0]; Field(_v2, 1) = _v3[1]; End_roots() return _v2; } apron-dist-0.9.10/apron/mlapronidl/dim.idl0000640014525101416610000000653611224617002020275 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \n\ #include \"ap_dimension.h\"\n\ #include \"caml/mlvalues.h\"\n\ #include \"apron_caml.h\"\n\ ") typedef unsigned int ap_dim_t; typedef [mltype("{\n dim : int array;\n intdim : int;\n realdim : int;\n}"), c2ml(camlidl_apron_dimchange_c2ml), ml2c(camlidl_apron_dimchange_ml2c)] struct ap_dimchange_t ap_dimchange_t; struct ap_dimchange2_t { ap_dimchange_t* add; ap_dimchange_t* remove; }; struct ap_dimperm_t { [size_is(size)]unsigned int* dim; unsigned int size; }; struct ap_dimension_t { [mlname(intd)]unsigned int intdim; [mlname(reald)]unsigned int realdim; }; quote(MLMLI,"(** APRON Dimensions and related types *)") quote(MLI,"\n(** {ul {- [t=int] is the type of dimensions.} {- The semantics of an object [(change:change)] is the following one: {ul {- [change.intdim] and [change.realdim] indicate the number of integer and real dimensions to add or to remove} {- In case of the addition of dimensions, [change.dim[i]=k] means: add one dimension at dimension k and shift the already existing dimensions greater than or equal to k one step on the right (or increment them). if k is equal to the size of the vector, then it means: add a dimension at the end. Repetition are allowed, and means that one inserts more than one dimensions. Example: [add_dimensions [i0 i1 r0 r1] { dim=[0 1 2 2 4]; intdim=3; realdim=1 }] returns [0 i0 0 i1 0 0 r0 r1 0], considered as a vector with 6 integer dimensions and 3 real dimensions.} {- In case of the removal of dimensions, dimchange.dim[i]=k means: remove the dimension k and shift the dimensions greater than k one step on the left (or decrement them). Repetitions are meaningless (and are not correct specification) Example: [remove_dimensions [i0 i1 i2 r0 r1 r2] { dim=[0 2 4]; intdim=2; realdim=1 }] returns [i1 r0 r2], considered as a vector with 1 integer dimensions and 2 real dimensions. }}} {- The semantics of an object [(change2:change2)] is the combination of the two following transformations: {ul {- [change2.add] indicates an optional addition of dimensions.} {- [change2.remove] indicates an optional removal of dimensions.} }} {- [perm] defines a permutation.} {- [dimension] defines the dimensionality of an abstract value (number of integer and real dimensions). }} *) ") quote(MLI," (** Assuming a transformation for add_dimensions, invert it in-place to obtain the inverse transformation using remove_dimensions *) val change_add_invert : change -> unit (** [perm_compose perm1 perm2] composes the 2 permutations perm1 and perm2 (in this order). The sizes of permutations are supposed to be equal. *) val perm_compose : perm -> perm -> perm (** Invert a permutation *) val perm_invert : perm -> perm ") quote(ML," let change_add_invert change = let dim = change.dim in for i=0 to (Array.length dim)-1 do dim.(i) <- dim.(i) + i; done let perm_compose perm1 perm2 = let length = Array.length perm1 in assert(length==(Array.length perm2)); Array.init length (fun i -> perm2.(perm1.(i))) let perm_invert perm = let length = Array.length perm in let res = Array.make length 0 in for i=0 to length-1 do res.(perm.(i)) <- i; done; res ") apron-dist-0.9.10/apron/mlapronidl/var.mli0000640014525101416610000000140211252216516020316 0ustar bjeannetpopart(* File generated from var.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t (** APRON Variables *) (** Constructor *) external of_string : string -> t = "camlidl_var_ap_var_of_string" (** Comparison function *) external compare : t -> t -> int = "camlidl_var_ap_var_compare" (** Conversion to string *) external to_string : t -> string = "camlidl_var_ap_var_to_string" (** Hash function *) external hash : t -> int = "camlidl_var_ap_var_hash" (** Printing function *) val print : Format.formatter -> t -> unit (** Initialisation of abstract type operations in C library *) external set_var_operations : unit -> unit = "camlidl_apron_set_var_operations" apron-dist-0.9.10/apron/mlapronidl/lincons1.mli0000640014525101416610000001154711252216516021267 0ustar bjeannetpopart(* File generated from lincons1.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = { mutable lincons0: Lincons0.t; mutable env: Environment.t; } and earray = { mutable lincons0_array: Lincons0.t array; mutable array_env: Environment.t; } (** APRON Constraints and array of constraints of level 1 *) type typ = Lincons0.typ = | EQ | SUPEQ | SUP | DISEQ | EQMOD of Scalar.t (** Make a linear constraint. Modifying later the linear expression ({e not advisable}) modifies correspondingly the linear constraint and conversely, except for changes of environements *) val make: Linexpr1.t -> typ -> t (** Copy (deep copy) *) val copy: t -> t (** Convert a constraint type to a string ([=],[>=], or [>]) *) val string_of_typ : typ -> string (** Print the linear constraint *) val print : Format.formatter -> t -> unit (** Get the constraint type *) val get_typ: t -> typ (** Iter the function on the pair coefficient/variable of the underlying linear expression *) val iter: (Coeff.t -> Var.t -> unit) -> t -> unit (** Get the constant of the underlying linear expression *) val get_cst: t -> Coeff.t (** Set the constraint type *) val set_typ: t -> typ -> unit (** Set simultaneously a number of coefficients. [set_list expr [(c1,"x"); (c2,"y")] (Some cst)] assigns coefficients [c1] to variable ["x"], coefficient [c2] to variable ["y"], and coefficient [cst] to the constant. If [(Some cst)] is replaced by [None], the constant coefficient is not assigned. *) val set_list : t -> (Coeff.t * Var.t) list -> Coeff.t option -> unit (** Set simultaneously a number of coefficients, as [set_list]. *) val set_array : t -> (Coeff.t * Var.t) array -> Coeff.t option -> unit (** Set the constant of the underlying linear expression *) val set_cst: t -> Coeff.t -> unit (** Get the coefficient of the variable in the underlying linear expression *) external get_coeff : t -> Var.t -> Coeff.t = "camlidl_lincons1_ap_lincons1_get_coeff" (** Set the coefficient of the variable in the underlying linear expression *) external set_coeff : t -> Var.t -> Coeff.t -> unit = "camlidl_lincons1_ap_lincons1_set_coeff" (** Build the unsatisfiable constraint -1>=0 *) external make_unsat : Environment.t -> t = "camlidl_lincons1_ap_lincons1_make_unsat" (** Is the constraint not satisfiable ? *) external is_unsat : t -> bool = "camlidl_lincons1_ap_lincons1_is_unsat" (** Change the environement of the constraint for a super-environement. Raise [Failure] if it is not the case *) external extend_environment : t -> Environment.t -> t = "camlidl_lincons1_ap_lincons1_extend_environment" (** Side-effect version of the previous function *) external extend_environment_with : t -> Environment.t -> unit = "camlidl_lincons1_ap_lincons1_extend_environment_with" (** Get the environement of the linear constraint *) val get_env: t -> Environment.t (** Get the underlying linear expression. Modifying the linear expression ({e not advisable}) modifies correspondingly the linear constraint and conversely, except for changes of environements *) val get_linexpr1: t -> Linexpr1.t (** Get the underlying linear constraint of level 0. Modifying the constraint of level 0 ({e not advisable}) modifies correspondingly the linear constraint and conversely, except for changes of environements*) val get_lincons0: t -> Lincons0.t (* ====================================================================== *) (** {2 Type array} *) (* ====================================================================== *) (** Make an array of linear constraints with the given size and defined on the given environement. The elements are initialized with the constraint 0=0. *) val array_make : Environment.t -> int -> earray (** Print an array of constraints *) val array_print : ?first:(unit, Format.formatter, unit) format -> ?sep:(unit, Format.formatter, unit) format -> ?last:(unit, Format.formatter, unit) format -> Format.formatter -> earray -> unit (** Get the size of the array *) val array_length : earray -> int (** Get the environment of the array *) val array_get_env : earray -> Environment.t (** Get the element of the given index (which is not a copy) *) val array_get : earray -> int -> t (** Set the element of the given index (without any copy). The array and the constraint should be defined on the same environement; otherwise a [Failure] exception is raised.*) val array_set : earray -> int -> t -> unit (** Change the environement of the array of constraints for a super-environement. Raise [Failure] if it is not the case*) external array_extend_environment : earray -> Environment.t -> earray = "camlidl_lincons1_ap_lincons1_array_extend_environment" (** Side-effect version of the previous function *) external array_extend_environment_with : earray -> Environment.t -> unit = "camlidl_lincons1_ap_lincons1_array_extend_environment_with" apron-dist-0.9.10/apron/mlapronidl/parser.ml0000640014525101416610000002163011023235130020643 0ustar bjeannetpopart(* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) (** APRON Parsing of expressions *) (** {2 Introduction} This small module implements the parsing of expressions, constraints and generators. The allowed syntax is simple for linear expressions (no parenthesis) but supports interval expressions. The syntax is more flexible for tree expressions. {3 Syntax} [lincons ::= linexpr ('>' | '>=' | '=' | '!=' | '=' | '<=' | '<') linexpr | linexpr = linexpr 'mod' scalar] [gen ::= ('V:' | 'R:' | 'L:' | 'RM:' | 'LM:') linexpr] [linexpr ::= linexpr '+' linterm | linexpr '-' linterm | linterm] [linterm ::= coeff ['*'] identifier | coeff | ['-'] identifier] [tcons ::= texpr ('>' | '>=' | '=' | '!=' | '=' | '<=' | '<') texpr | texpr = texpr 'mod' scalar] [texpr ::= coeff | identifier | unop texpr | texpr binop texpr | '(' texpr ')'] [binop ::= ('+'|'-'|'*'|'/'|'%')['_'('i'|'f'|'d'|'l'|'q')][','('n'|'0'|'+oo'|'-oo')]] [unop ::= ('cast' | 'sqrt')['_'('i'|'f'|'d'|'l'|'q')][','('n'|'0'|'+oo'|'-oo')]] [coeff ::= scalar | ['-'] '['scalar ';' scalar ']'] [scalar ::= ['-'] (integer | rational | floating_point_number)] For tree expressions [texpr], by default the operations have an exact arithmetic semantics in the real numbers (even if involved variables are of integer). The type qualifiers modify this default semantics. Their meaning is as follows: - [i] integer semantics - [f] IEEE754 32 bits floating-point semantics - [d] IEEE754 64 bits floating-point semantics - [l] IEEE754 80 bits floating-point semantics - [q] IEEE754 129 bits floating-point semantics By default, the rounding mode is "any" (this applies only in non-real semantics), which allows to emulate all the following rounding modes: - [n] nearest - [0] towards zero - [+oo] towards infinity - [-oo] towards minus infinity - [?] any {3 Examples} [let (linexpr:Linexpr1.t) = Parser.linexpr1_of_string env "z+0.4x+2y"] [let (tab:Lincons1.earray) = Parser.lincons1_of_lstring env ["1/2x+2/3y=1";"[1;2]<=z+2w";"z+2w<=4";"0<=u";"u<=5"]] [let (generator:Generator1.t) = Parser.generator1_of_string env "R:x+2y"] [let (texpr:Texpr1.t) = Parser.texpr1_of_string env "a %_i,? b +_f,0 c"] {3 Remarks} There is the possibility to parse directly from a lexing buffer, or from a string (from which one can generate a buffer with the function [Lexing.from_string]. This module uses the underlying modules [Apron_lexer] and [Apron_parser]. *) exception Error of string let raise_error str = raise (Error str) (* **********************************************************************) (** {2 Internal functions} *) (* **********************************************************************) let rec check_list = function | (var1,_)::(((var2,_)::_) as l)-> if (String.compare var1 var2)=0 then raise (Error (Format.sprintf "%s appears twice in an expression" (if var1="" then "Constant coefficient" else ("Variable "^var1)))) else check_list l | _ -> () let linexpr1_of_linexpr (env:Environment.t) (list:(string*Coeff.t) list) : Linexpr1.t = let list = List.sort (fun (var1,_) (var2,_) -> String.compare var1 var2) list in check_list list; let res = Linexpr1.make env in List.iter (begin fun (var,coeff) -> if var="" then Linexpr1.set_cst res coeff else Linexpr1.set_coeff res (Var.of_string var) coeff end) list ; res let lincons1_of_lincons (env:Environment.t) (lincons:Lincons0.typ * (string*Coeff.t) list) : Lincons1.t = let (typ,list) = lincons in Lincons1.make (linexpr1_of_linexpr env list) typ let generator1_of_generator (env:Environment.t) (generator:Generator0.typ * (string*Coeff.t) list) : Generator1.t = let (typ,list) = generator in Generator1.make (linexpr1_of_linexpr env list) typ (* **********************************************************************) (** {2 Exported functions: using lexbuf} *) (* **********************************************************************) let linexpr1_of_lexbuf (env:Environment.t) (lexbuf:Lexing.lexbuf) : Linexpr1.t = let x = Apron_parser.linexpr Apron_lexer.lex lexbuf in linexpr1_of_linexpr env x let lincons1_of_lexbuf (env:Environment.t) (lexbuf:Lexing.lexbuf) : Lincons1.t = let x = Apron_parser.lincons Apron_lexer.lex lexbuf in lincons1_of_lincons env x let generator1_of_lexbuf (env:Environment.t) (lexbuf:Lexing.lexbuf) : Generator1.t = let x = Apron_parser.generator Apron_lexer.lex lexbuf in generator1_of_generator env x let texpr1expr_of_lexbuf (lexbuf:Lexing.lexbuf) : Texpr1.expr = Apron_parser.texpr Apron_lexer.lex lexbuf let texpr1_of_lexbuf (env:Environment.t) (lexbuf:Lexing.lexbuf) : Texpr1.t = let x = texpr1expr_of_lexbuf lexbuf in Texpr1.of_expr env x let tcons1_of_lexbuf (env:Environment.t) (lexbuf:Lexing.lexbuf) : Tcons1.t = let (t,x) = Apron_parser.tcons Apron_lexer.lex lexbuf in Tcons1.make (Texpr1.of_expr env x) t (* **********************************************************************) (** {2 Exported functions: using strings} *) (* **********************************************************************) let linexpr1_of_string (env:Environment.t) (str:string) : Linexpr1.t = try let lexbuf = Lexing.from_string str in try linexpr1_of_lexbuf env lexbuf with Parsing.Parse_error -> raise_error (Format.sprintf "Syntaxical error, characters %d-%d in expression %s" (Lexing.lexeme_start lexbuf) (Lexing.lexeme_end lexbuf) str) with Apron_lexer.Error (s,e) -> raise_error (Format.sprintf "Lexical error, characters %d-%d in expression %s" s e str) let lincons1_of_string (env:Environment.t) (str:string) : Lincons1.t = try let lexbuf = Lexing.from_string str in try lincons1_of_lexbuf env lexbuf with Parsing.Parse_error -> raise_error (Format.sprintf "Syntaxical error, characters %d-%d in constraint %s" (Lexing.lexeme_start lexbuf) (Lexing.lexeme_end lexbuf) str) with Apron_lexer.Error (s,e) -> raise_error (Format.sprintf "Lexical error, characters %d-%d in constraint %s" s e str) let generator1_of_string (env:Environment.t) (str:string) : Generator1.t = try let lexbuf = Lexing.from_string str in try generator1_of_lexbuf env lexbuf with Parsing.Parse_error -> raise_error (Format.sprintf "Syntaxical error, characters %d-%d in generator %s" (Lexing.lexeme_start lexbuf) (Lexing.lexeme_end lexbuf) str) with Apron_lexer.Error (s,e) -> raise_error (Format.sprintf "Lexical error, characters %d-%d in generator %s" s e str) let texpr1expr_of_string (str:string) : Texpr1.expr = try let lexbuf = Lexing.from_string str in try texpr1expr_of_lexbuf lexbuf with Parsing.Parse_error -> raise_error (Format.sprintf "Syntaxical error, characters %d-%d in expression %s" (Lexing.lexeme_start lexbuf) (Lexing.lexeme_end lexbuf) str) with Apron_lexer.Error (s,e) -> raise_error (Format.sprintf "Lexical error, characters %d-%d in expression %s" s e str) let texpr1_of_string (env:Environment.t) (str:string) : Texpr1.t = let expr = texpr1expr_of_string str in Texpr1.of_expr env expr let tcons1_of_string (env:Environment.t) (str:string) : Tcons1.t = try let lexbuf = Lexing.from_string str in try tcons1_of_lexbuf env lexbuf with Parsing.Parse_error -> raise_error (Format.sprintf "Syntaxical error, characters %d-%d in constraint %s" (Lexing.lexeme_start lexbuf) (Lexing.lexeme_end lexbuf) str) with Apron_lexer.Error (s,e) -> raise_error (Format.sprintf "Lexical error, characters %d-%d in constraint %s" s e str) let lincons1_of_lstring (env:Environment.t) (lstr:string list) : Lincons1.earray = let length = List.length lstr in let res = Lincons1.array_make env length in let i = ref (-1) in List.iter (fun str -> incr i; let x = lincons1_of_string env str in Lincons1.array_set res !i x ) lstr ; res let generator1_of_lstring (env:Environment.t) (lstr:string list) : Generator1.earray = let length = List.length lstr in let res = Generator1.array_make env length in let i = ref (-1) in List.iter (fun str -> incr i; let x = generator1_of_string env str in Generator1.array_set res !i x ) lstr ; res let tcons1_of_lstring (env:Environment.t) (lstr:string list) : Tcons1.earray = let length = List.length lstr in let res = Tcons1.array_make env length in let i = ref (-1) in List.iter (fun str -> incr i; let x = tcons1_of_string env str in Tcons1.array_set res !i x ) lstr ; res let of_lstring (man:'a Manager.t) (env:Environment.t) (lstr:string list) : 'a Abstract1.t = let array = lincons1_of_lstring env lstr in Abstract1.of_lincons_array man env array apron-dist-0.9.10/apron/mlapronidl/manager.idl0000640014525101416610000002455111224617156021145 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \n\ #include \"ap_manager.h\"\n\ #include \"apron_caml.h\"\n\ \n\ void camlidl_apron_manager_funid_ml2c(value _v, enum ap_funid_t* res)\n\ {\n\ int v = Int_val(_v);\n\ if (v+1>=AP_FUNID_CHANGE_ENVIRONMENT)\n\ *res = v+1;\n\ else\n\ *res = v;\n\ }\n\ value camlidl_apron_manager_funid_c2ml(enum ap_funid_t* arg)\n\ {\n\ int n = *arg;\n\ if (n>=0 && nAP_FUNID_SIZE) n--;\n\ }\n\ else {\n\ invalid_argument(\"enum ap_funid_t: bad enum value\");\n\ }\n\ return Val_int(n);\n\ }\n\ void camlidl_apron_manager_exc_ml2c(value _v, enum ap_exc_t* res)\n\ {\n\ *res = Int_val(_v);\n\ }\n\ value camlidl_apron_manager_exc_c2ml(enum ap_exc_t* arg)\n\ {\n\ int n = *arg;\n\ if (! (n>=AP_EXC_NONE && n= AP_FUNID_SIZE) invalid_argument(\"Manager.get.funopt : should be different from Funid_change_environment and Funid_rename_array (no option for remaining identifiers)\");\n\ _res = ap_manager_get_funopt(man,funid);\n\ "); quote(MLI,"(** Set the options for the function. [funid] should be different from [Funid_change_environment] and [Funid_rename_array] (no option associated to them). *)") void ap_manager_set_funopt(ap_manager_ptr man, ap_funid_t funid, [ref]struct ap_funopt_t* funopt) quote(call,"\ if (funid >= AP_FUNID_SIZE) invalid_argument(\"Manager.set.funopt ...: should be different from Funid_change_environment and Funid_rename_array (no option for remaining identifiers)\");\n\ ap_manager_set_funopt(man,funid,funopt);\n\ "); quote(MLI,"(** Get the corresponding result flag *)") boolean ap_manager_get_flag_exact(ap_manager_ptr man); quote(MLI,"(** Get the corresponding result flag *)") boolean ap_manager_get_flag_best(ap_manager_ptr man); quote(MLI,"(** Exception raised by functions of the interface *)") quote(MLMLI,"exception Error of ap_exclog_t"); quote(ML,"\ let _ = Callback.register_exception \"apron exception\" \ (Error { exn=Exc_none; funid = Funid_bottom; msg = \"dummy\"; })") quote(MLI,"val string_of_funid: ap_funid_t -> string") quote(MLI,"val string_of_exc: ap_exc_t -> string") quote(MLI,"val print_funid: Format.formatter -> ap_funid_t -> unit") quote(MLI,"val print_funopt: Format.formatter -> ap_funopt_t -> unit") quote(MLI,"val print_exc: Format.formatter -> ap_exc_t -> unit") quote(MLI,"val print_exclog: Format.formatter -> ap_exclog_t -> unit") quote(MLI," (** Printing functions *)") quote(ML,"\n\ let string_of_funid = function\n\ | Funid_unknown -> \"Funid_unknown\"\n\ | Funid_copy -> \"Funid_copy\"\n\ | Funid_free -> \"Funid_free\"\n\ | Funid_asize -> \"Funid_asize\"\n\ | Funid_minimize -> \"Funid_minimize\"\n\ | Funid_canonicalize -> \"Funid_canonicalize\"\n\ | Funid_hash -> \"Funid_hash\"\n\ | Funid_approximate -> \"Funid_approximate\"\n\ | Funid_fprint -> \"Funid_fprint\"\n\ | Funid_fprintdiff -> \"Funid_fprintdiff\"\n\ | Funid_fdump -> \"Funid_fdump\"\n\ | Funid_serialize_raw -> \"Funid_serialize_raw\"\n\ | Funid_deserialize_raw -> \"Funid_deserialize_raw\"\n\ | Funid_bottom -> \"Funid_bottom\"\n\ | Funid_top -> \"Funid_top\"\n\ | Funid_of_box -> \"Funid_of_box\"\n\ | Funid_dimension -> \"Funid_dimension\"\n\ | Funid_is_bottom -> \"Funid_is_bottom\"\n\ | Funid_is_top -> \"Funid_is_top\"\n\ | Funid_is_leq -> \"Funid_is_leq\"\n\ | Funid_is_eq -> \"Funid_is_eq\"\n\ | Funid_is_dimension_unconstrained -> \"Funid_is_dimension_unconstrained\"\n\ | Funid_sat_interval -> \"Funid_sat_interval\"\n\ | Funid_sat_lincons -> \"Funid_sat_lincons\"\n\ | Funid_sat_tcons -> \"Funid_sat_tcons\"\n\ | Funid_bound_dimension -> \"Funid_bound_dimension\"\n\ | Funid_bound_linexpr -> \"Funid_bound_linexpr\"\n\ | Funid_bound_texpr -> \"Funid_bound_texpr\"\n\ | Funid_to_box -> \"Funid_to_box\"\n\ | Funid_to_lincons_array -> \"Funid_to_lincons_array\"\n\ | Funid_to_tcons_array -> \"Funid_to_tcons_array\"\n\ | Funid_to_generator_array -> \"Funid_to_generator_array\"\n\ | Funid_meet -> \"Funid_meet\"\n\ | Funid_meet_array -> \"Funid_meet_array\"\n\ | Funid_meet_lincons_array -> \"Funid_meet_lincons_array\"\n\ | Funid_meet_tcons_array -> \"Funid_meet_tcons_array\"\n\ | Funid_join -> \"Funid_join\"\n\ | Funid_join_array -> \"Funid_join_array\"\n\ | Funid_add_ray_array -> \"Funid_add_ray_array\"\n\ | Funid_assign_linexpr_array -> \"Funid_assign_linexpr_array\"\n\ | Funid_substitute_linexpr_array -> \"Funid_substitute_linexpr_array\"\n\ | Funid_assign_texpr_array -> \"Funid_assign_texpr_array\"\n\ | Funid_substitute_texpr_array -> \"Funid_substitute_texpr_array\"\n\ | Funid_add_dimensions -> \"Funid_add_dimensions\"\n\ | Funid_remove_dimensions -> \"Funid_remove_dimensions\"\n\ | Funid_permute_dimensions -> \"Funid_permute_dimensions\"\n\ | Funid_forget_array -> \"Funid_forget_array\"\n\ | Funid_expand -> \"Funid_expand\"\n\ | Funid_fold -> \"Funid_fold\"\n\ | Funid_widening -> \"Funid_widening\"\n\ | Funid_closure -> \"Funid_closure\"\n\ | Funid_change_environment -> \"Funid_change_environment\"\n\ | Funid_rename_array -> \"Funid_rename_array\"\n\ \n\ let string_of_exc = function\n\ | Exc_none -> \"Exc_none\"\n\ | Exc_timeout -> \"Exc_timeout\"\n\ | Exc_out_of_space -> \"Exc_out_of_space\"\n\ | Exc_overflow -> \"Exc_overflow\"\n\ | Exc_invalid_argument -> \"Exc_invalid_argument\"\n\ | Exc_not_implemented -> \"Exc_not_implemented\"\n\ \n\ let print_funid fmt x = Format.pp_print_string fmt (string_of_funid x)\n\ let print_exc fmt x = Format.pp_print_string fmt (string_of_exc x)\n\ let print_exclog fmt x =\n\ Format.fprintf fmt \"{ @[ exn = %a;@ funid = %a;@ msg = %s;@] }\" print_exc x.exn print_funid x.funid x.msg\n\ let print_funopt fmt x =\n\ Format.fprintf fmt \"{ @[ algorithm = %i;@ timeout = %i;@ max_object_size = %i;@ flag_exact_wanted = %b;@ flag_best_wanted = %b;@] }\" x.algorithm x.timeout x.max_object_size x.flag_exact_wanted x.flag_best_wanted\n\ ") quote(MLI,"(** Set / get the global manager used for deserialization *)") void ap_manager_set_deserialize(ap_manager_ptr man); ap_manager_ptr ap_manager_get_deserialize(); /* Init */ quote(ML,"external init: unit -> unit = \"camlidl_apron_init\"\n") quote(ML,"let _ = init()") apron-dist-0.9.10/apron/mlapronidl/interval.ml0000640014525101416610000000373311252216515021211 0ustar bjeannetpopart(* File generated from interval.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = { mutable inf: Scalar.t; mutable sup: Scalar.t; } (** APRON Intervals on scalars *) let of_scalar inf sup = { inf = inf; sup = sup } let of_infsup = of_scalar let of_mpq x y = { inf = Scalar.of_mpq x; sup = Scalar.of_mpq y } let of_mpqf x y = { inf = Scalar.of_mpqf x; sup = Scalar.of_mpqf y } let of_int x y = { inf = Scalar.of_int x; sup = Scalar.of_int y } let of_frac x y z w = { inf = Scalar.of_frac x y; sup = Scalar.of_frac z w } let of_float x y = { inf = Scalar.of_float x; sup = Scalar.of_float y } let of_mpfr x y = { inf = Scalar.of_mpfr x; sup = Scalar.of_mpfr y } let is_top itv = Scalar.is_infty itv.inf < 0 && Scalar.is_infty itv.sup > 0 let is_bottom itv = Scalar.cmp itv.inf itv.sup > 0 let is_leq itv1 itv2 = Scalar.cmp itv1.inf itv2.inf >= 0 && Scalar.cmp itv1.sup itv2.sup <= 0 let cmp itv1 itv2 = let s1 = Scalar.cmp itv1.inf itv2.inf in let s2 = Scalar.cmp itv1.sup itv2.sup in if s1=0 && s2=0 then 0 else if s1>=0 && s2<=0 then -1 else if s1<=0 && s2>=0 then 1 else if s1<=0 then -2 else 2 let equal itv1 itv2 = Scalar.equal itv1.inf itv2.inf && Scalar.equal itv1.sup itv2.sup let is_zero itv = Scalar.sgn itv.inf=0 && Scalar.sgn itv.sup = 0 let equal_int itv b = Scalar.equal_int itv.inf b && Scalar.equal_int itv.sup b let neg itv = { inf = Scalar.neg itv.sup; sup = Scalar.neg itv.inf } let top = { inf = Scalar.Float neg_infinity; sup = Scalar.Float infinity } let bottom = { inf = Scalar.Float infinity; sup = Scalar.Float neg_infinity } let set_infsup itv inf sup = itv.inf <- inf; itv.sup <- sup let set_top itv = itv.inf <- Scalar.Float neg_infinity; itv.sup <- Scalar.Float infinity let set_bottom itv = itv.inf <- Scalar.Float infinity; itv.sup <- Scalar.Float neg_infinity let print fmt itv = Format.fprintf fmt "[@[%a;@ %a@]]" Scalar.print itv.inf Scalar.print itv.sup apron-dist-0.9.10/apron/mlapronidl/generator0.idl0000640014525101416610000000352210620623402021562 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(MLI,"(** APRON Generators of level 0 *)") quote(C, "\n\ #include \n\ #include \"ap_generator0.h\"\n\ #include \"apron_caml.h\"\n\ \n\ #define LINE AP_GEN_LINE \n\ #define RAY AP_GEN_RAY \n\ #define VERTEX AP_GEN_VERTEX \n\ #define LINEMOD AP_GEN_LINEMOD \n\ #define RAYMOD AP_GEN_RAYMOD \n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; import "linexpr0.idl"; enum gentyp { LINE, RAY, VERTEX, LINEMOD, RAYMOD }; struct ap_generator0_t { [mlname(mutable_linexpr0)] ap_linexpr0_ptr linexpr0; /* constant coefficient ignored */ [mlname(mutable_typ)] enum gentyp gentyp; }; struct ap_generator0_array_t { [size_is(size)] struct ap_generator0_t* p; int size; }; quote(MLI,"\n\ (** Making a generator. The constant coefficient of the linear expression is\n\ ignored. Modifying later the linear expression modifies correspondingly the\n\ generator and conversely. *)\n\ val make : Linexpr0.t -> typ -> t\n\ \n\ (** Copy a generator (deep copy) *)\n\ val copy : t -> t\n\ \n\ (** Convert a generator type to a string ([LIN],[RAY], or [VTX]) *)\n\ val string_of_typ : typ -> string\n\ \n\ (** Print a generator *)\n\ val print : (Dim.t -> string) -> Format.formatter -> t -> unit\n\ ") quote(ML,"\n\ let string_of_typ = function\n\ | LINE -> \"LIN\"\n\ | RAY -> \"RAY\"\n\ | VERTEX -> \"VTX\"\n\ | LINEMOD -> \"LINMOD\"\n\ | RAYMOD -> \"RAYMOD\"\n\ \n\ let print assoc fmt gen = \n\ Format.fprintf fmt \"%s:\" (string_of_typ gen.gentyp);\n\ Linexpr0.print assoc fmt gen.linexpr0;\n\ ()\n\ let make expr typ = {\n\ linexpr0 = expr; typ = typ;\n\ }\n\ let copy gen = {\n\ linexpr0 = Linexpr0.copy gen.linexpr0; typ = gen.typ;\n\ }\n\ ") apron-dist-0.9.10/apron/mlapronidl/texpr1.idl0000640014525101416610000003260310654126013020744 0ustar bjeannetpopart/* -*- mode: c -*- */ quote(MLI,"(** APRON Expressions of level 1 *)") quote(C, "\n\ #include \n\ #include \"ap_texpr1.h\"\n\ #include \"apron_caml.h\"\n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "texpr0.idl"; import "environment.idl"; struct ap_texpr1_t { [mlname(mutable_texpr0)] ap_texpr0_ptr texpr0; [mlname(mutable_env)] ap_environment_ptr env; }; quote(MLMLI,"\n\ (** Unary operators *) \n\ type unop = Texpr0.unop = \n\ | Neg\n\ | Cast\n\ | Sqrt\n\ \n\ (** Binary operators *) \n\ type binop = Texpr0.binop = \n\ | Add\n\ | Sub\n\ | Mul\n\ | Div\n\ | Mod\n\ \n\ (** Destination type for rounding *) \n\ type typ = Texpr0.typ = \n\ | Real\n\ | Int\n\ | Single\n\ | Double\n\ | Extended\n\ | Quad\n\ \n\ (** Rounding direction *) \n\ type round = Texpr0.round = \n\ | Near\n\ | Zero\n\ | Up\n\ | Down\n\ | Rnd\n\ \n\ (** User type for tree expressions *) \n\ type expr = \n\ | Cst of Coeff.t \n\ | Var of Var.t \n\ | Unop of unop * expr * typ * round \n\ | Binop of binop * expr * expr * typ * round \n\ ") quote(C, "\n\ value camlidl_texpr1_ap_texpr1_to_expr_c2ml(ap_environment_t* env, ap_texpr0_t* expr, camlidl_ctx _ctx)\n\ {\n\ value _v_res ;\n\ \n\ switch(expr->discr){\n\ case AP_TEXPR_CST:\n\ {\n\ value v0 = Val_unit;\n\ Begin_root(v0);\n\ v0 = camlidl_c2ml_coeff_struct_ap_coeff_t(&expr->val.cst, _ctx);\n\ _v_res = caml_alloc_small(1,0);\n\ Field(_v_res,0) = v0;\n\ End_roots();\n\ }\n\ break;\n\ case AP_TEXPR_DIM:\n\ {\n\ ap_var_t var;\n\ value v0 = Val_unit;\n\ var = ap_environment_var_of_dim(env,expr->val.dim);\n\ assert(var!=NULL);\n\ var = ap_var_copy(var);\n\ Begin_root(v0);\n\ v0 = camlidl_apron_var_ptr_c2ml(&var);\n\ _v_res = caml_alloc_small(1,1);\n\ Field(_v_res,0) = v0;\n\ End_roots();\n\ }\n\ break;\n\ case AP_TEXPR_NODE:\n\ {\n\ value v0,v1,v2,v3,v4;\n\ v0 = v1 = v2 = v3 = v4 = Val_unit;\n\ Begin_roots5(v0,v1,v2,v3,v4);\n\ ap_texpr0_node_t* node = expr->val.node;\n\ v1 = camlidl_texpr1_ap_texpr1_to_expr_c2ml(env,node->exprA,_ctx);\n\ v3 = camlidl_apron_texpr_rtype_t_c2ml(&node->type);\n\ v4 = camlidl_apron_texpr_rdir_t_c2ml(&node->dir);\n\ if (ap_texpr_is_unop(node->op)){\n\ v0 = camlidl_apron_texpr_unop_t_c2ml(&node->op);\n\ _v_res = caml_alloc_small(4,2);\n\ Field(_v_res,0) = v0;\n\ Field(_v_res,1) = v1;\n\ Field(_v_res,2) = v3;\n\ Field(_v_res,3) = v4;\n\ }\n\ else {\n\ v0 = camlidl_apron_texpr_binop_t_c2ml(&node->op);\n\ v2 = camlidl_texpr1_ap_texpr1_to_expr_c2ml(env,node->exprB,_ctx);\n\ _v_res = caml_alloc_small(5,3);\n\ Field(_v_res,0) = v0;\n\ Field(_v_res,1) = v1;\n\ Field(_v_res,2) = v2;\n\ Field(_v_res,3) = v3;\n\ Field(_v_res,4) = v4;\n\ }\n\ End_roots();\n\ }\n\ break;\n\ default:\n\ abort();\n\ }\n\ return _v_res;\n\ }\n\ value camlidl_texpr1_ap_texpr1_to_expr(value _v_texpr)\n\ {\n\ CAMLparam1(_v_texpr);\n\ CAMLlocal1(_v_res);\n\ ap_environment_t* env;\n\ ap_texpr1_t texpr1;\n\ \n\ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL };\n\ camlidl_ctx _ctx = &_ctxs;\n\ \n\ camlidl_ml2c_texpr1_struct_ap_texpr1_t(_v_texpr,&texpr1,_ctx);\n\ _v_res = camlidl_texpr1_ap_texpr1_to_expr_c2ml(texpr1.env,texpr1.texpr0,_ctx);\n\ camlidl_free(_ctx);\n\ \n\ CAMLreturn(_v_res);\n\ }\n\ \n\ void camlidl_texpr1_ap_texpr0_of_expr_ml2c(value v, ap_environment_t* env, ap_texpr0_t** res, camlidl_ctx _ctx)\n\ {\n\ ap_texpr0_t* texpr;\n\ ap_texpr0_node_t* node;\n\ ap_coeff_t coeff;\n\ ap_var_t var;\n\ ap_dim_t dim;\n\ ap_texpr0_t* exprA;\n\ ap_texpr0_t* exprB;\n\ value v0,v1,v2,v3,v4;\n\ \n\ texpr = malloc(sizeof(ap_texpr0_t));\n \ \n\ assert (Is_block(v));\n\ switch (Tag_val(v)){\n\ case 0: /* Constant */\n\ assert(Wosize_val(v)==1);\n\ v0 = Field(v,0);\n\ texpr->discr = AP_TEXPR_CST;\n\ camlidl_ml2c_coeff_struct_ap_coeff_t(v0,&coeff,_ctx);\n\ ap_coeff_init_set(&texpr->val.cst,&coeff);\n\ break;\n\ case 1: /* Variable */\n\ assert(Wosize_val(v)==1);\n\ v0 = Field(v,0);\n\ camlidl_apron_var_ptr_ml2c(v0,&var);\n\ texpr->discr = AP_TEXPR_DIM;\n\ texpr->val.dim = ap_environment_dim_of_var(env,var);\n\ if (texpr->val.dim == AP_DIM_MAX){\n\ free(texpr);\n\ texpr = NULL;\n\ }\n\ break;\n\ case 2: /* Unary node */\n\ v0 = Field(v,0);\n\ v1 = Field(v,1);\n\ v2 = Field(v,2);\n\ v3 = Field(v,3);\n\ \n\ camlidl_texpr1_ap_texpr0_of_expr_ml2c(v1,env,&exprA,_ctx);\n\ if (exprA==NULL){\n\ free(texpr);\n\ texpr = NULL;\n\ }\n\ else {\n\ node = malloc(sizeof(ap_texpr0_node_t));\n\ camlidl_apron_texpr_unop_t_ml2c (v0,&node->op);\n\ camlidl_apron_texpr_rtype_t_ml2c (v2,&node->type);\n\ camlidl_apron_texpr_rdir_t_ml2c (v3,&node->dir);\n\ node->exprA = exprA; \n\ node->exprB = NULL;\n\ texpr->discr = AP_TEXPR_NODE;\n\ texpr->val.node = node;\n\ }\n\ break;\n\ case 3: /* Binary node */\n\ v0 = Field(v,0);\n\ v1 = Field(v,1);\n\ v2 = Field(v,2);\n\ v3 = Field(v,3);\n\ v4 = Field(v,4);\n\ camlidl_texpr1_ap_texpr0_of_expr_ml2c(v1,env,&exprA,_ctx);\n\ if (exprA==NULL){\n\ free(texpr);\n\ texpr = NULL;\n\ }\n\ else {\n\ camlidl_texpr1_ap_texpr0_of_expr_ml2c(v2,env,&exprB,_ctx);\n\ if (exprB==NULL){\n\ ap_texpr0_free(exprA);\n\ free(texpr);\n\ texpr = NULL;\n\ }\n\ else {\n\ node = malloc(sizeof(ap_texpr0_node_t));\n\ camlidl_apron_texpr_binop_t_ml2c (v0,&node->op);\n\ camlidl_apron_texpr_rtype_t_ml2c (v3,&node->type);\n\ camlidl_apron_texpr_rdir_t_ml2c (v4,&node->dir);\n\ node->exprA = exprA; \n\ node->exprB = exprB; \n\ texpr->discr = AP_TEXPR_NODE;\n\ texpr->val.node = node;\n\ }\n\ }\n\ break;\n\ default:\n\ assert(false);\n\ }\n\ *res = texpr;\n\ }\n\ value camlidl_texpr1_ap_texpr0_of_expr(value _v_env, value _v_expr)\n\ {\n\ CAMLparam2(_v_env,_v_expr);\n\ CAMLlocal1(_v_res);\n\ ap_texpr0_t* texpr0;\n\ ap_environment_t* env;\n\ \n\ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL };\n\ camlidl_ctx _ctx = &_ctxs;\n\ \n\ camlidl_apron_environment_ptr_ml2c(_v_env,&env);\n\ camlidl_texpr1_ap_texpr0_of_expr_ml2c(_v_expr,env,&texpr0,_ctx);\n\ camlidl_free(_ctx);\n\ if (texpr0==NULL){\n\ caml_failwith(\"Texpr1.texpr0_of_expr: unknown variable in the environment\");\n\ }\n\ _v_res = camlidl_apron_texpr0_ptr_c2ml(&texpr0);\n\ CAMLreturn(_v_res);\n\ }\n\ ") quote(MLMLI,"(** {2 Constructors and Destructor} *)") quote(MLI,"(** General constructor (actually the most efficient) *)") quote(MLI,"val of_expr : Environment.t -> expr -> t\n") /* quote(ML,"external texpr0_of_expr : Environment.t -> expr -> Texpr0.t = \"camlidl_texpr1_ap_texpr0_of_expr\") */ quote(ML,"\ let rec expr0_of_expr1 env expr =\n\ match expr with\n\ | Cst x -> Texpr0.Cst x\n\ | Var var -> Texpr0.Dim (Environment.dim_of_var env var)\n\ | Unop(op,e,t,r) -> \n\ Texpr0.Unop(\n\ op,\n\ (expr0_of_expr1 env e),\n\ t,r\n\ )\n\ | Binop(op,e1,e2,t,r) -> \n\ Texpr0.Binop(\n\ op,\n\ (expr0_of_expr1 env e1),\n\ (expr0_of_expr1 env e2),\n\ t,r\n\ )\n\ let texpr0_of_expr env expr =\n\ Texpr0.of_expr (expr0_of_expr1 env expr)\n\ let of_expr env expr = {\n\ texpr0 = texpr0_of_expr env expr;\n\ env = env;\n\ }\n\ ") quote(MLI,"\ (** Copy *)\n\ val copy : t -> t\n\ \n\ (** Conversion *)\n\ val of_linexpr : Linexpr1.t -> t\n\ ") quote(ML,"\n\ let copy e = { texpr0 = Texpr0.copy e.texpr0; env = e.env }\n\ let of_linexpr e = { texpr0 = Texpr0.of_linexpr e.Linexpr1.linexpr0; env = e.Linexpr1.env }\n\ ") quote(MLI,"(** General destructor *)") /* quote(MLMLI,"external to_expr : t -> expr = \"camlidl_texpr1_ap_texpr1_to_expr\"\n") */ quote(MLI,"val to_expr : t -> expr\n") quote(ML,"\ let rec expr1_of_expr0 env expr =\n\ match expr with\n\ | Texpr0.Cst x -> Cst x\n\ | Texpr0.Dim dim -> Var (Environment.var_of_dim env dim)\n\ | Texpr0.Unop(op,e,t,r) -> \n\ Unop(\n\ op,\n\ (expr1_of_expr0 env e),\n\ t,r\n\ )\n\ | Texpr0.Binop(op,e1,e2,t,r) -> \n\ Binop(\n\ op,\n\ (expr1_of_expr0 env e1),\n\ (expr1_of_expr0 env e2),\n\ t,r\n\ )\n\ let to_expr texpr1 =\n\ let expr0 = Texpr0.to_expr texpr1.texpr0 in\n\ expr1_of_expr0 texpr1.env expr0\n\ ") quote(MLI,"\n(** {3 Incremental constructors} *)\n") [ref]struct ap_texpr1_t* ap_texpr1_cst(ap_environment_ptr env, [ref]struct ap_coeff_t* coeff); [ref]struct ap_texpr1_t* ap_texpr1_var(ap_environment_ptr env, ap_var_t var); [ref]struct ap_texpr1_t* ap_texpr1_unop(ap_texpr_unop_t op, [ref]struct ap_texpr1_t* expr, ap_texpr_rtype_t type, ap_texpr_rdir_t dir) quote(call,"_res = ap_texpr1_unop(op,ap_texpr1_copy(expr),type,dir);"); [ref]struct ap_texpr1_t* ap_texpr1_binop(ap_texpr_binop_t op, [ref]struct ap_texpr1_t* exprA, [ref]struct ap_texpr1_t* exprB, ap_texpr_rtype_t type, ap_texpr_rdir_t dir) quote(call,"_res = ap_texpr1_binop(op,ap_texpr1_copy(exprA),ap_texpr1_copy(exprB),type,dir);"); quote(MLMLI,"\n(** {2 Tests} *)\n") quote(MLI,"\ val is_interval_cst : t -> bool \n\ val is_interval_linear : t -> bool \n\ val is_interval_polynomial : t -> bool \n\ val is_interval_polyfrac : t -> bool \n\ val is_scalar : t -> bool \n\ ") quote(ML,"\ let is_interval_cst x = Texpr0.is_interval_cst x.texpr0 \n\ let is_interval_linear x = Texpr0.is_interval_linear x.texpr0 \n\ let is_interval_polynomial x = Texpr0.is_interval_polynomial x.texpr0 \n\ let is_interval_polyfrac x = Texpr0.is_interval_polyfrac x.texpr0 \n\ let is_scalar x = Texpr0.is_scalar x.texpr0 \n\ ") quote(MLMLI,"\n(** {2 Operations} *)\n") quote(MLI,"(** Change the environment of the expression for a super-environement. Raise [Failure] if it is not the case *)") [ref]struct ap_texpr1_t* ap_texpr1_extend_environment([ref]struct ap_texpr1_t* texpr, ap_environment_ptr env) quote(call,"\n\ {\n\ bool b;\n\ _res = ap_texpr1_extend_environment(texpr,env);\n\ if (!_res) caml_failwith(\"Texpr1.extend_environment: new environment is not a superenvironment\");\n\ }\n\ ") ; quote(MLI,"(** Side-effet version of the previous function *)") void ap_texpr1_extend_environment_with([ref]struct ap_texpr1_t* texpr, ap_environment_ptr env) quote(call,"\n\ {\n\ if (texpr->env!=env){ \n\ bool b;\n\ ap_environment_copy(texpr->env); /* to protect it */ \n\ b = ap_texpr1_extend_environment_with(texpr,env);\n\ if (b){ \n\ ap_environment_free(texpr->env); \n\ caml_failwith(\"Texpr1.extend_environment_with: new environment is not a superenvironment\");\n\ }\n\ Store_field(_v_texpr,1,_v_env);\n\ ap_environment_free(env);\n\ }\n\ }\n\ ") ; quote(MLI,"\n\ (** Get the underlying expression of level 0 (which is not a copy). *)\n\ val get_texpr0: t -> Texpr0.t\n\ \n\ (** Get the environement of the expression *)\n\ val get_env: t -> Environment.t\n\ \n\ ") quote(ML,"\n\ let get_texpr0 expr = expr.texpr0\n\ let get_env expr = expr.env\n\ ") quote(MLMLI,"\n(** {2 Printing} *)\n") quote(MLI,"\n\ val string_of_unop : unop -> string\n\ val string_of_binop : binop -> string\n\ val string_of_typ : typ -> string\n\ val string_of_round : round -> string\n\ val print_unop : Format.formatter -> unop -> unit\n\ val print_binop : Format.formatter -> binop -> unit\n\ val print_typ : Format.formatter -> typ -> unit\n\ val print_round : Format.formatter -> round -> unit\n\ val print_expr : Format.formatter -> expr -> unit\n\ (** Print a tree expression *)\n\ val print : Format.formatter -> t -> unit\n\ (** Print an abstract tree expression *)\n\ ") quote(ML,"\n\ let string_of_unop = Texpr0.string_of_unop\n\ let string_of_binop = Texpr0.string_of_binop\n\ let string_of_typ = Texpr0.string_of_typ\n\ let string_of_round = Texpr0.string_of_round\n\ let print_unop = Texpr0.print_unop\n\ let print_binop = Texpr0.print_binop\n\ let print_typ = Texpr0.print_typ\n\ let print_round = Texpr0.print_round\n\ let rec print_expr fmt expr =\n\ let precedence_of_expr = function\n\ | Cst _\n\ | Var _ -> 5\n\ | Unop(op,_,_,_) -> Texpr0.print_precedence_of_unop op\n\ | Binop(op,_,_,_,_) -> Texpr0.print_precedence_of_binop op\n\ in\n\ match expr with\n\ | Cst x -> Coeff.print fmt x\n\ | Var x -> Format.pp_print_string fmt (Var.to_string x)\n\ | Unop(op,e,typ,round) ->\n\ let prec = Texpr0.print_precedence_of_unop op in\n\ let prec1 = precedence_of_expr e in\n\ let par = prec1<=prec in\n\ Format.fprintf fmt \"%s%s%a%s\"\n\ (Texpr0.print_sprint_unop op typ round)\n\ (if par then \"(\" else \"\")\n\ print_expr e\n\ (if par then \")\" else \"\")\n\ | Binop(op,e1,e2,typ,round) ->\n\ let prec = Texpr0.print_precedence_of_binop op in\n\ let prec1 = precedence_of_expr e1 in\n\ let prec2 = precedence_of_expr e2 in\n\ let par1 = prec1 Var.to_string (Environment.var_of_dim expr.env dim))\n\ fmt expr.texpr0\n\ ") apron-dist-0.9.10/apron/mlapronidl/coeff.idl0000640014525101416610000001130111247456444020610 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \n\ #include \"ap_coeff.h\"\n\ #include \"apron_caml.h\"\n\ \n\ #define Scalar AP_COEFF_SCALAR\n\ #define Interval AP_COEFF_INTERVAL\n\ ") import "scalar.idl"; import "interval.idl"; /* For ap_coeff_t, - the conversion from ML to C may use allocation, but it is automatically freed by Camlidl mechanisms - the conversion from C to ML duplicate the C allocated memory. Hence, the C type should be explicitly deallocated (if allocated from the underlying C function) */ struct ap_coeff_t { int discr; /* discriminant for coefficient */ [switch_is(discr)] union { case Scalar: [ref]ap_scalar_t* scalar; /* cst (normal linear expression) */ case Interval: [ref]struct ap_interval_t* interval; /* interval (quasi-linear expression) */ } val; }; quote(MLMLI,"(** APRON Coefficients (either scalars or intervals) *)") quote(MLI,"\n\ val s_of_mpq : Mpq.t -> t\n\ val s_of_mpqf : Mpqf.t -> t\n\ val s_of_int : int -> t\n\ val s_of_frac : int -> int -> t\n\ (** Create a scalar coefficient of type [Mpqf.t] from resp.\n\ - A multi-precision rational [Mpq.t] \n\ - A multi-precision rational [Mpqf.t] \n\ - an integer \n\ - a fraction [x/y]\n\ *)\n\ \n\ val s_of_float : float -> t\n\ (** Create an interval coefficient of type [Float] with the given value *)\n\ val s_of_mpfr : Mpfr.t -> t\n\ (** Create an interval coefficient of type [Mpfr] with the given value *)\n\ val i_of_scalar : Scalar.t -> Scalar.t -> t\n\ (** Build an interval from a lower and an upper bound *)\n\ val i_of_mpq : Mpq.t -> Mpq.t -> t\n\ val i_of_mpqf : Mpqf.t -> Mpqf.t -> t\n\ val i_of_int : int -> int -> t\n\ val i_of_frac : int -> int -> int -> int -> t\n\ val i_of_float : float -> float -> t\n\ val i_of_mpfr : Mpfr.t -> Mpfr.t -> t\n\ (** Create an interval coefficient from resp. two\n\ - multi-precision rationals [Mpq.t] \n\ - multi-precision rationals [Mpqf.t] \n\ - integers \n\ - fractions [x/y] and [z/w]\n\ - machine floats\n\ - Mpfr floats\n\ *)\n\ \n\ val is_scalar : t -> bool\n\ val is_interval : t -> bool\n\ val cmp : t -> t -> int\n\ (** Non Total Comparison:\n\ - If the 2 coefficients are both scalars, corresp. to Scalar.cmp\n\ - If the 2 coefficients are both intervals, corresp. to Interval.cmp\n\ - otherwise, -3 if the first is a scalar, 3 otherwise\n\ *)\n\ val equal : t -> t -> bool\n\ (** Equality test *)\n\ val is_zero : t -> bool\n\ (** Is the coefficient equal to scalar 0 or interval [0,0] ? *)\n\ val equal_int : t -> int -> bool\n\ (** Is the coefficient equal to scalar b or interval [b,b] ? *)\n\ val neg : t -> t\n\ (** Negation *)\n\ val reduce : t -> t\n\ (** Convert interval to scalar if possible *)\n\ val print : Format.formatter -> t -> unit\n\ (** Printing *)\n\ ") quote(ML,"\n\ let s_of_mpq x = Scalar (Scalar.of_mpq x)\n\ let s_of_mpqf x = Scalar (Scalar.of_mpqf x)\n\ let s_of_int x = Scalar (Scalar.of_int x)\n\ let s_of_frac x y = Scalar (Scalar.of_frac x y)\n\ let s_of_float x = Scalar (Scalar.of_float x)\n\ let s_of_mpfr x = Scalar (Scalar.of_mpfr x)\n\ \n\ let i_of_scalar inf sup = Interval (Interval.of_scalar inf sup)\n\ let i_of_mpq x y = Interval (Interval.of_mpq x y)\n\ let i_of_mpqf x y = Interval (Interval.of_mpqf x y)\n\ let i_of_int x y = Interval (Interval.of_int x y)\n\ let i_of_frac x y z w = Interval (Interval.of_frac x y z w)\n\ let i_of_float x y = Interval (Interval.of_float x y)\n\ let i_of_mpfr x y = Interval (Interval.of_mpfr x y)\n\ \n\ let is_scalar c = match c with Scalar _ -> true | _ -> false\n\ let is_interval c = match c with Interval _ -> true | _ -> false\n\ let cmp c1 c2 = match (c1,c2) with\n\ | (Scalar s1, Scalar s2) -> Scalar.cmp s1 s2\n\ | (Interval i1, Interval i2) -> Interval.cmp i1 i2\n\ | (Scalar _, _) -> (-3)\n\ | _ -> 3\n\ let equal c1 c2 = match (c1,c2) with\n\ | (Scalar s1, Scalar s2) -> Scalar.equal s1 s2\n\ | (Interval i1, Interval i2) -> Interval.equal i1 i2\n\ | _ -> false\n\ let is_zero c = match c with\n\ | Scalar s -> (Scalar.sgn s)=0\n\ | Interval i -> Interval.is_zero i\n\ let equal_int c b = match c with\n\ | Scalar s -> Scalar.equal_int s b\n\ | Interval i -> Interval.equal_int i b\n\ let neg c = match c with\n\ | Scalar s -> Scalar (Scalar.neg s)\n\ | Interval i -> Interval (Interval.neg i)\n\ let reduce c = match c with\n\ | Scalar _ -> c\n\ | Interval i ->\n\ if Scalar.equal i.Interval.inf i.Interval.sup\n\ then Scalar i.Interval.inf\n\ else c\n\ let print fmt c = match c with\n\ | Scalar s -> Scalar.print fmt s\n\ | Interval i -> Interval.print fmt i\n\ ") apron-dist-0.9.10/apron/mlapronidl/environment.idl0000640014525101416610000002565011224617210022067 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \n\ #include \"ap_environment.h\"\n\ #include \"caml/mlvalues.h\"\n\ #include \"apron_caml.h\"\n\ ") import "dim.idl"; import "var.idl"; quote(C,"enum typvar {\n\ AP_INT,AP_REAL\n\ };\n\ ") enum typvar { AP_INT,AP_REAL }; typedef [abstract, c2ml(camlidl_apron_environment_ptr_c2ml), ml2c(camlidl_apron_environment_ptr_ml2c)] struct ap_environment_ptr ap_environment_ptr; quote(MLMLI,"(** APRON Environments binding dimensions to names *)") quote(MLI,"\n(** Making an environment from a set of integer and real variables. Raise [Failure] in case of name conflict. *)") ap_environment_ptr ap_environment_make([size_is(intdim)]ap_var_t* name_of_intdim, int intdim, [size_is(realdim)]ap_var_t* name_of_realdim, int realdim) quote(call,"\n\ _res = ap_environment_alloc(name_of_intdim,intdim,name_of_realdim,realdim);\n\ if (_res==NULL){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.make: duplicated variable names\");\n\ }\n\ assert(_res->count >= 1);\n\ ") ; quote(MLI,"\n(** Adding to an environment a set of integer and real variables. Raise [Failure] in case of name conflict. *)") ap_environment_ptr ap_environment_add(ap_environment_ptr e, [size_is(intdim)]ap_var_t* name_of_intdim, int intdim, [size_is(realdim)]ap_var_t* name_of_realdim, int realdim) quote(call,"\n\ _res = ap_environment_add(e,name_of_intdim,intdim,name_of_realdim,realdim);\n\ if (_res==NULL){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.add: duplicated variable names\");\n\ }\n\ assert(_res->count >= 1);") ; quote(MLI,"\n(** Remove from an environment a set of variables. Raise [Failure] in case of non-existing variables. *)") ap_environment_ptr ap_environment_remove(ap_environment_ptr e, [size_is(size)]ap_var_t* tvar, int size) quote(call,"\n\ _res = ap_environment_remove(e,tvar,size);\n\ if (_res==NULL){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.remove: unknown variable names\");\n\ }\n\ assert(_res->count >= 1);") ; quote(MLI,"\n(** Renaming in an environment a set of variables. Raise [Failure] in case of interferences with the variables that are not renamed. *)") ap_environment_ptr ap_environment_rename(ap_environment_ptr e, [size_is(size1)]ap_var_t* tvar1, [size_is(size2)]ap_var_t* tvar2, int size1,int size2) quote(call,"\n\ if (size1!=size2){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.rename: arrays of different sizes\");\n\ }\n\ else {\n\ struct ap_dimperm_t perm;\n\ _res = ap_environment_rename(e,tvar1,tvar2,size1,&perm);\n\ ap_dimperm_clear(&perm);\n\ if (_res==NULL){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.rename: unknown variables or interference of new variables with unrenamed variables\");\n\ }\n\ }\n\ assert(_res->count >= 1);") ; quote(MLI,"\n(** Similar to previous function, but returns also \n\ the permutation on dimensions induced by the renaming. *)") ap_environment_ptr ap_environment_rename_perm(ap_environment_ptr e, [size_is(size1)]ap_var_t* tvar1, [size_is(size2)]ap_var_t* tvar2, int size1,int size2, [out] struct ap_dimperm_t perm) quote(call,"\n\ if (size1!=size2){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.rename: arrays of different sizes\");\n\ }\n\ else {\n\ _res = ap_environment_rename(e,tvar1,tvar2,size1,&perm);\n\ if (_res==NULL){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.rename_dimperm: unknown variables or interference of new variables with unrenamed variables\");\n\ }\n\ }\n\ assert(_res->count >= 1);") quote(dealloc,"ap_dimperm_clear(&perm);") ; quote(MLI,"\n (** Compute the least common environment of 2 environment, \n\ that is, the environment composed of all the variables \n\ of the 2 environments.\n\ Raise [Failure] if the same variable has different types \n\ in the 2 environment.\ *)") ap_environment_ptr ap_environment_lce(ap_environment_ptr e1, ap_environment_ptr e2) quote(call,"\n\ {\n\ ap_dimchange_t *c1;\n\ ap_dimchange_t *c2;\n\ _res = ap_environment_lce(e1,e2,&c1,&c2);\n\ if (c1) ap_dimchange_free(c1);\n\ if (c2) ap_dimchange_free(c2);\n\ }\n\ if (_res==NULL){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.lce: variable with two different types\");\n\ }\n\ assert(_res->count >= 1);") ; quote(MLI,"\n (** Similar to the previous function, but returns also the transformations \n\ required to convert from [e1] (resp. [e2]) \n\ to the lce. If [None] is returned, this means \n\ that [e1] (resp. [e2]) is identic to the lce.*)") ap_environment_ptr ap_environment_lce_change([in] ap_environment_ptr e1, [in] ap_environment_ptr e2, [out,unique] ap_dimchange_t *c1, [out,unique] ap_dimchange_t *c2) quote(call,"\n\ {\n\ _res = ap_environment_lce(e1,e2,&c1,&c2);\n\ }\n\ if (_res==NULL){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.lce: variable with two different types\");\n\ }\n\ assert(_res->count >= 1);") quote(dealloc," if (c1) ap_dimchange_free(c1); if (c2) ap_dimchange_free(c2); ") ; quote(MLI,"\n (** [dimchange e1 e2] computes the transformation for \n\ converting from an environment [e1] to a superenvironment \n\ [e2]. Raises [Failure] if [e2] is not a superenvironment.\ *)") [ref]ap_dimchange_t *ap_environment_dimchange(ap_environment_ptr e1, ap_environment_ptr e2) quote(call,"\n\ _res = ap_environment_dimchange(e1,e2);\n\ if (_res==NULL){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.dimchange: the second environment is not a superenvironment of the first one\");\n\ }\n\ ") quote(dealloc,"ap_dimchange_free(_res);") ; quote(MLI,"\n (** [dimchange2 e1 e2] computes the transformation for converting from an environment [e1] to a (compatible) environment [e2], by first adding (some) variables of [e2] and then removing (some) variables of [e1]. Raises [Failure] if the two environments are incompatible. *)") [ref]struct ap_dimchange2_t *ap_environment_dimchange2(ap_environment_ptr e1, ap_environment_ptr e2) quote(call,"\n\ _res = ap_environment_dimchange2(e1,e2);\n\ if (_res==NULL){\n\ camlidl_free(_ctx);\n\ caml_failwith(\"Environment.dimchange2: the two environments are not compatible\");\n\ }\n\ ") quote(dealloc,"ap_dimchange2_free(_res);") ; quote(MLI,"\n(** Test equality if two environments *)") boolean ap_environment_equal(ap_environment_ptr env1, ap_environment_ptr env2) quote(call,"\n\ _res = ap_environment_is_eq(env1,env2);\n\ "); quote(MLI,"\n(** Compare two environment. [compare env1 env2] return [-2] if the environements are not compatible (a variable has different types in the 2 environements), [-1] if [env1] is a subset of env2, [0] if equality, [+1] if env1 is a superset of env2, and [+2] otherwise (the lce exists and is a strict superset of both) *)") int ap_environment_compare(ap_environment_ptr env1, ap_environment_ptr env2); quote(MLI,"\n(** Hashing function for environments *)") int ap_environment_hash(ap_environment_ptr env); quote(MLI,"\n(** Return the dimension of the environment *)") struct ap_dimension_t ap_environment_dimension(ap_environment_ptr e) quote(call,"_res.intdim = e->intdim; _res.realdim = e->realdim;"); quote(MLI,"\n(** Return the size of the environment *)") unsigned int ap_environment_size(ap_environment_ptr e) quote(call,"_res = e->intdim + e->realdim;"); quote(MLI,"\n(** Return true if the variable is present in the environment. *)") boolean ap_environment_mem_var(ap_environment_ptr e, ap_var_t var) quote(call,"\n\ {\n\ ap_dim_t dim;\n\ dim = ap_environment_dim_of_var(e,var);\n\ _res = (dim != AP_DIM_MAX);\n\ }"); quote(MLI,"\n(** Return the type of variables in the environment. If the variable does not belong to the environment, raise a [Failure] exception. *)") enum typvar ap_environment_typ_of_var(ap_environment_ptr e, ap_var_t var) quote(call,"\n\ {\n\ ap_dim_t dim;\n\ dim = ap_environment_dim_of_var(e,var);\n\ if (dim==AP_DIM_MAX)\n\ caml_failwith(\"Environment.dim_of_var: unknown variable in the environment\");\n\ _res =\n\ dim=( dimintdim ? AP_INT : AP_REAL);\n\ }"); quote(MLI,"\n(** Return the (lexicographically ordered) sets of integer and real variables in the environment *)") void ap_environment_vars(ap_environment_ptr e, [out,size_is((*e).intdim)]ap_var_t* name_of_intdim, [out,size_is((*e).realdim)]ap_var_t* name_of_realdim) quote(call,"\n\ {\n\ size_t i;\n\ for(i=0;iintdim;i++) name_of_intdim[i] = ap_var_operations->copy(e->var_of_dim[i]);\n \ for(i=0;irealdim;i++) name_of_realdim[i] = ap_var_operations->copy(e->var_of_dim[e->intdim+i]);\n \ }"); quote(MLI,"\n(** Return the variable corresponding to the given dimension in the environment. Raise [Failure] is the dimension is out of the range of the environment (greater than or equal to [dim env]) *)") ap_var_t ap_environment_var_of_dim(ap_environment_ptr e, ap_dim_t dim) quote(call,"\n\ if (dim>=e->intdim+e->realdim){\n\ caml_failwith(\"Environment.var_of_dim: dim out of range w.r.t. the environment\");\n\ }\n\ _res = ap_var_operations->copy(e->var_of_dim[dim]);"); quote(MLI,"\n(** Return the dimension associated to the given variable in the environment. Raise [Failure] if the variable does not belong to the environment. *)") ap_dim_t ap_environment_dim_of_var(ap_environment_ptr e, ap_var_t var) quote(call,"\n\ _res = ap_environment_dim_of_var(e,var);\n\ if (_res==AP_DIM_MAX){\n\ caml_failwith(\"Environment.dim_of_var: unknown variable in the environment\");\n\ }"); quote(MLMLI,"\n(** Printing *)") quote(MLI,"val print :\n\ ?first:(unit, Format.formatter, unit) format ->\n\ ?sep:(unit, Format.formatter, unit) format ->\n\ ?last:(unit, Format.formatter, unit) format ->\n\ Format.formatter -> t -> unit\n\ ") quote(ML,"\n\ let print\n\ ?(first=(\"[|@[\":(unit,Format.formatter,unit) format))\n\ ?(sep = (\";@ \":(unit,Format.formatter,unit) format))\n\ ?(last = (\"@]|]\":(unit,Format.formatter,unit) format))\n\ (fmt:Format.formatter)\n\ (env: t)\n\ : unit\n\ =\n\ let dim = dimension env in\n\ if dim.Dim.intd+dim.Dim.reald=0 then begin\n\ Format.fprintf fmt first;\n\ Format.fprintf fmt last;\n\ end\n\ else begin\n\ Format.fprintf fmt first;\n\ let first = ref true in\n\ for i=0 to pred dim.Dim.intd do\n\ let var = var_of_dim env i in\n\ if !first then first := false else Format.fprintf fmt sep;\n\ Format.fprintf fmt \"%i> %s:int\"\n\ i (Var.to_string var)\n\ done;\n\ for i=dim.Dim.intd to dim.Dim.intd + (pred dim.Dim.reald) do\n\ let var = var_of_dim env i in\n\ if !first then first := false else Format.fprintf fmt sep;\n\ Format.fprintf fmt \"%i> %s:real\"\n\ i (Var.to_string var)\n\ done;\n\ Format.fprintf fmt last;\n\ end\n\ ") apron-dist-0.9.10/apron/mlapronidl/tcons1.mli0000640014525101416610000000677511252216516020757 0ustar bjeannetpopart(* File generated from tcons1.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = { mutable tcons0: Tcons0.t; mutable env: Environment.t; } and earray = { mutable tcons0_array: Tcons0.t array; mutable array_env: Environment.t; } (** APRON tree constraints and array of tree constraints of level 1 *) type typ = Lincons0.typ = | EQ | SUPEQ | SUP | DISEQ | EQMOD of Scalar.t (** Make a tree expression constraint. Modifying later the linear expression ({e not advisable}) modifies correspondingly the tree expression constraint and conversely, except for changes of environements *) val make: Texpr1.t -> typ -> t (** Copy (deep copy) *) val copy: t -> t (** Convert a constraint type to a string ([=],[>=], or [>]) *) val string_of_typ : typ -> string (** Print the tree expression constraint *) val print : Format.formatter -> t -> unit (** Get the constraint type *) val get_typ: t -> typ (** Set the constraint type *) val set_typ: t -> typ -> unit (** Change the environement of the constraint for a super-environement. Raise [Failure] if it is not the case *) external extend_environment : t -> Environment.t -> t = "camlidl_tcons1_ap_tcons1_extend_environment" (** Side-effect version of the previous function *) external extend_environment_with : t -> Environment.t -> unit = "camlidl_tcons1_ap_tcons1_extend_environment_with" (** Get the environement of the tree expression constraint *) val get_env: t -> Environment.t (** Get the underlying linear expression. Modifying the linear expression ({e not advisable}) modifies correspondingly the tree expression constraint and conversely, except for changes of environements *) val get_texpr1: t -> Texpr1.t (** Get the underlying tree expression constraint of level 0. Modifying the constraint of level 0 ({e not advisable}) modifies correspondingly the tree expression constraint and conversely, except for changes of environements*) val get_tcons0: t -> Tcons0.t (* ====================================================================== *) (** {2 Type array} *) (* ====================================================================== *) (** Make an array of tree expression constraints with the given size and defined on the given environement. The elements are initialized with the constraint 0=0. *) val array_make : Environment.t -> int -> earray (** Print an array of constraints *) val array_print : ?first:(unit, Format.formatter, unit) format -> ?sep:(unit, Format.formatter, unit) format -> ?last:(unit, Format.formatter, unit) format -> Format.formatter -> earray -> unit (** Get the size of the array *) val array_length : earray -> int (** Get the environment of the array *) val array_get_env : earray -> Environment.t (** Get the element of the given index (which is not a copy) *) val array_get : earray -> int -> t (** Set the element of the given index (without any copy). The array and the constraint should be defined on the same environement; otherwise a [Failure] exception is raised.*) val array_set : earray -> int -> t -> unit (** Change the environement of the array of constraints for a super-environement. Raise [Failure] if it is not the case*) external array_extend_environment : earray -> Environment.t -> earray = "camlidl_tcons1_ap_tcons1_array_extend_environment" (** Side-effect version of the previous function *) external array_extend_environment_with : earray -> Environment.t -> unit = "camlidl_tcons1_ap_tcons1_array_extend_environment_with" apron-dist-0.9.10/apron/mlapronidl/tcons0_caml.c0000640014525101416610000002062611252216515021401 0ustar bjeannetpopart/* File generated from tcons0.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include #include "ap_lincons0.h" #include "ap_texpr0.h" #include "apron_caml.h" extern void camlidl_apron_scalar_ml2c(value, ap_scalar_t *); #define camlidl_ml2c_scalar_ap_scalar_t(v,c,ctx) camlidl_apron_scalar_ml2c(v,c) extern value camlidl_apron_scalar_c2ml(ap_scalar_t *); #define camlidl_c2ml_scalar_ap_scalar_t(c,ctx) camlidl_apron_scalar_c2ml(c) extern void camlidl_ml2c_scalar_ap_scalar_ptr(value, ap_scalar_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_ap_scalar_ptr(ap_scalar_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_scalar_struct_ap_scalar_array_t(value, struct ap_scalar_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_struct_ap_scalar_array_t(struct ap_scalar_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_t(value, struct ap_interval_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_t(struct ap_interval_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_ap_interval_ptr(value, ap_interval_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_ap_interval_ptr(ap_interval_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_array_t(value, struct ap_interval_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_array_t(struct ap_interval_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_coeff_struct_ap_coeff_t(value, struct ap_coeff_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_coeff_struct_ap_coeff_t(struct ap_coeff_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_ap_dim_t(value, ap_dim_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_ap_dim_t(ap_dim_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimchange_t(value, struct ap_dimchange_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange_t(struct ap_dimchange_t *, camlidl_ctx _ctx); extern void camlidl_apron_dimchange_ml2c(value, ap_dimchange_t *); #define camlidl_ml2c_dim_ap_dimchange_t(v,c,ctx) camlidl_apron_dimchange_ml2c(v,c) extern value camlidl_apron_dimchange_c2ml(ap_dimchange_t *); #define camlidl_c2ml_dim_ap_dimchange_t(c,ctx) camlidl_apron_dimchange_c2ml(c) extern void camlidl_ml2c_dim_struct_ap_dimchange2_t(value, struct ap_dimchange2_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange2_t(struct ap_dimchange2_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimperm_t(value, struct ap_dimperm_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimperm_t(struct ap_dimperm_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimension_t(value, struct ap_dimension_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimension_t(struct ap_dimension_t *, camlidl_ctx _ctx); extern void camlidl_apron_linexpr0_ptr_ml2c(value, ap_linexpr0_ptr *); #define camlidl_ml2c_linexpr0_ap_linexpr0_ptr(v,c,ctx) camlidl_apron_linexpr0_ptr_ml2c(v,c) extern value camlidl_apron_linexpr0_ptr_c2ml(ap_linexpr0_ptr *); #define camlidl_c2ml_linexpr0_ap_linexpr0_ptr(c,ctx) camlidl_apron_linexpr0_ptr_c2ml(c) extern void camlidl_apron_lincons0_ml2c(value, ap_lincons0_t *, camlidl_ctx); #define camlidl_ml2c_lincons0_ap_lincons0_t(v,c,ctx) camlidl_apron_lincons0_ml2c(v,c,ctx) extern value camlidl_apron_lincons0_c2ml(ap_lincons0_t *); #define camlidl_c2ml_lincons0_ap_lincons0_t(c,ctx) camlidl_apron_lincons0_c2ml(c) extern void camlidl_ml2c_lincons0_struct_ap_lincons0_array_t(value, struct ap_lincons0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_lincons0_struct_ap_lincons0_array_t(struct ap_lincons0_array_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr0_ptr_ml2c(value, ap_texpr0_ptr *); #define camlidl_ml2c_texpr0_ap_texpr0_ptr(v,c,ctx) camlidl_apron_texpr0_ptr_ml2c(v,c) extern value camlidl_apron_texpr0_ptr_c2ml(ap_texpr0_ptr *); #define camlidl_c2ml_texpr0_ap_texpr0_ptr(c,ctx) camlidl_apron_texpr0_ptr_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_op_t(value, ap_texpr_op_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_op_t(ap_texpr_op_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_unop_t_ml2c(value, ap_texpr_unop_t *); #define camlidl_ml2c_texpr0_ap_texpr_unop_t(v,c,ctx) camlidl_apron_texpr_unop_t_ml2c(v,c) extern value camlidl_apron_texpr_unop_t_c2ml(ap_texpr_unop_t *); #define camlidl_c2ml_texpr0_ap_texpr_unop_t(c,ctx) camlidl_apron_texpr_unop_t_c2ml(c) extern void camlidl_apron_texpr_binop_t_ml2c(value, ap_texpr_binop_t *); #define camlidl_ml2c_texpr0_ap_texpr_binop_t(v,c,ctx) camlidl_apron_texpr_binop_t_ml2c(v,c) extern value camlidl_apron_texpr_binop_t_c2ml(ap_texpr_binop_t *); #define camlidl_c2ml_texpr0_ap_texpr_binop_t(c,ctx) camlidl_apron_texpr_binop_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rtype_t(value, ap_texpr_rtype_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rtype_t(ap_texpr_rtype_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_rtype_t_ml2c(value, ap_texpr_rtype_t *); #define camlidl_ml2c_texpr0_ap_texpr_rtype_t(v,c,ctx) camlidl_apron_texpr_rtype_t_ml2c(v,c) extern value camlidl_apron_texpr_rtype_t_c2ml(ap_texpr_rtype_t *); #define camlidl_c2ml_texpr0_ap_texpr_rtype_t(c,ctx) camlidl_apron_texpr_rtype_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rdir_t(value, ap_texpr_rdir_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rdir_t(ap_texpr_rdir_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_rdir_t_ml2c(value, ap_texpr_rdir_t *); #define camlidl_ml2c_texpr0_ap_texpr_rdir_t(v,c,ctx) camlidl_apron_texpr_rdir_t_ml2c(v,c) extern value camlidl_apron_texpr_rdir_t_c2ml(ap_texpr_rdir_t *); #define camlidl_c2ml_texpr0_ap_texpr_rdir_t(c,ctx) camlidl_apron_texpr_rdir_t_c2ml(c) void camlidl_apron_tcons0_ml2c(value v,ap_tcons0_t* cons, camlidl_ctx _ctx) { value _v_texpr0; value _v_constyp; value _v_scalar; _v_texpr0 = Field(v,0); camlidl_apron_texpr0_ptr_ml2c(_v_texpr0,&cons->texpr0); _v_constyp = Field(v,1); if (Is_long(_v_constyp)){ switch (Int_val(_v_constyp)){ case 0: case 1: case 2: cons->constyp = Int_val(_v_constyp); break; case 3: cons->constyp = 4; break; default: abort(); } cons->scalar = NULL; } else { switch (Tag_val(_v_constyp)){ case 0: cons->constyp = AP_CONS_EQMOD; _v_scalar = Field(_v_constyp,0); cons->scalar = (ap_scalar_t *)camlidl_malloc(sizeof(ap_scalar_t),_ctx); camlidl_apron_scalar_ml2c(_v_scalar,cons->scalar); break; default: abort(); } } } value camlidl_apron_tcons0_c2ml(ap_tcons0_t* cons) { value vres; value _v[3]; _v[0] = _v[1] = _v[2] = 0; Begin_roots_block(_v, 3) _v[0] = camlidl_apron_texpr0_ptr_c2ml(&cons->texpr0); switch(cons->constyp){ case AP_CONS_EQ: case AP_CONS_SUPEQ: case AP_CONS_SUP: _v[1] = Val_int(cons->constyp); break; case AP_CONS_DISEQ: _v[1] = Val_int(3); break; case AP_CONS_EQMOD: assert(cons->scalar!=NULL); _v[2] = camlidl_apron_scalar_c2ml(cons->scalar); _v[1] = camlidl_alloc_small(1, 0); Field(_v[1],0) = _v[2]; ap_scalar_free(cons->scalar); cons->scalar = NULL; break; } vres = camlidl_alloc_small(2, 0); Field(vres, 0) = _v[0]; Field(vres, 1) = _v[1]; End_roots() return vres; } #define camlidl_ml2c_tcons0_ap_tcons0_t(v,c,ctx) camlidl_apron_tcons0_ml2c(v,c,ctx) #define camlidl_c2ml_tcons0_ap_tcons0_t(c,ctx) camlidl_apron_tcons0_c2ml(c) void camlidl_ml2c_tcons0_struct_ap_tcons0_array_t(value _v1, struct ap_tcons0_array_t * _c2, camlidl_ctx _ctx) { mlsize_t _c3; mlsize_t _c4; value _v5; _c3 = Wosize_val(_v1); (*_c2).p = camlidl_malloc(_c3 * sizeof(ap_tcons0_t ), _ctx); for (_c4 = 0; _c4 < _c3; _c4++) { _v5 = Field(_v1, _c4); camlidl_ml2c_tcons0_ap_tcons0_t(_v5, &(*_c2).p[_c4], _ctx); } (*_c2).size = _c3; } value camlidl_c2ml_tcons0_struct_ap_tcons0_array_t(struct ap_tcons0_array_t * _c1, camlidl_ctx _ctx) { value _v2; mlsize_t _c3; value _v4; _v2 = camlidl_alloc((*_c1).size, 0); Begin_root(_v2) for (_c3 = 0; _c3 < (*_c1).size; _c3++) { _v4 = camlidl_c2ml_tcons0_ap_tcons0_t(&(*_c1).p[_c3], _ctx); modify(&Field(_v2, _c3), _v4); } End_roots() return _v2; } apron-dist-0.9.10/apron/mlapronidl/environment_caml.c0000640014525101416610000005212611252216516022540 0ustar bjeannetpopart/* File generated from environment.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include #include "ap_environment.h" #include "caml/mlvalues.h" #include "apron_caml.h" extern void camlidl_ml2c_dim_ap_dim_t(value, ap_dim_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_ap_dim_t(ap_dim_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimchange_t(value, struct ap_dimchange_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange_t(struct ap_dimchange_t *, camlidl_ctx _ctx); extern void camlidl_apron_dimchange_ml2c(value, ap_dimchange_t *); #define camlidl_ml2c_dim_ap_dimchange_t(v,c,ctx) camlidl_apron_dimchange_ml2c(v,c) extern value camlidl_apron_dimchange_c2ml(ap_dimchange_t *); #define camlidl_c2ml_dim_ap_dimchange_t(c,ctx) camlidl_apron_dimchange_c2ml(c) extern void camlidl_ml2c_dim_struct_ap_dimchange2_t(value, struct ap_dimchange2_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange2_t(struct ap_dimchange2_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimperm_t(value, struct ap_dimperm_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimperm_t(struct ap_dimperm_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimension_t(value, struct ap_dimension_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimension_t(struct ap_dimension_t *, camlidl_ctx _ctx); extern void camlidl_apron_var_ptr_ml2c(value, ap_var_t *); #define camlidl_ml2c_var_ap_var_t(v,c,ctx) camlidl_apron_var_ptr_ml2c(v,c) extern value camlidl_apron_var_ptr_c2ml(ap_var_t *); #define camlidl_c2ml_var_ap_var_t(c,ctx) camlidl_apron_var_ptr_c2ml(c) enum typvar { AP_INT,AP_REAL }; int camlidl_transl_table_environment_enum_4[2] = { AP_INT, AP_REAL, }; int camlidl_ml2c_environment_enum_typvar(value _v1) { int _c2; _c2 = camlidl_transl_table_environment_enum_4[Int_val(_v1)]; return _c2; } value camlidl_c2ml_environment_enum_typvar(int _c1) { value _v2; switch(_c1) { case AP_INT: _v2 = Val_int(0); break; case AP_REAL: _v2 = Val_int(1); break; default: invalid_argument("enum typvar: bad enum typvar value"); } return _v2; } #define camlidl_ml2c_environment_ap_environment_ptr(v,c,ctx) camlidl_apron_environment_ptr_ml2c(v,c) #define camlidl_c2ml_environment_ap_environment_ptr(c,ctx) camlidl_apron_environment_ptr_c2ml(c) value camlidl_environment_ap_environment_make( value _v_name_of_intdim, value _v_name_of_realdim) { ap_var_t *name_of_intdim; /*in*/ int intdim; /*in*/ ap_var_t *name_of_realdim; /*in*/ int realdim; /*in*/ ap_environment_ptr _res; mlsize_t _c1; mlsize_t _c2; value _v3; mlsize_t _c4; mlsize_t _c5; value _v6; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; _c1 = Wosize_val(_v_name_of_intdim); name_of_intdim = camlidl_malloc(_c1 * sizeof(ap_var_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_name_of_intdim, _c2); camlidl_ml2c_var_ap_var_t(_v3, &name_of_intdim[_c2], _ctx); } intdim = _c1; _c4 = Wosize_val(_v_name_of_realdim); name_of_realdim = camlidl_malloc(_c4 * sizeof(ap_var_t ), _ctx); for (_c5 = 0; _c5 < _c4; _c5++) { _v6 = Field(_v_name_of_realdim, _c5); camlidl_ml2c_var_ap_var_t(_v6, &name_of_realdim[_c5], _ctx); } realdim = _c4; /* begin user-supplied calling sequence */ _res = ap_environment_alloc(name_of_intdim,intdim,name_of_realdim,realdim); if (_res==NULL){ camlidl_free(_ctx); caml_failwith("Environment.make: duplicated variable names"); } assert(_res->count >= 1); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_environment_ap_environment_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_environment_ap_environment_add( value _v_e, value _v_name_of_intdim, value _v_name_of_realdim) { ap_environment_ptr e; /*in*/ ap_var_t *name_of_intdim; /*in*/ int intdim; /*in*/ ap_var_t *name_of_realdim; /*in*/ int realdim; /*in*/ ap_environment_ptr _res; mlsize_t _c1; mlsize_t _c2; value _v3; mlsize_t _c4; mlsize_t _c5; value _v6; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_environment_ap_environment_ptr(_v_e, &e, _ctx); _c1 = Wosize_val(_v_name_of_intdim); name_of_intdim = camlidl_malloc(_c1 * sizeof(ap_var_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_name_of_intdim, _c2); camlidl_ml2c_var_ap_var_t(_v3, &name_of_intdim[_c2], _ctx); } intdim = _c1; _c4 = Wosize_val(_v_name_of_realdim); name_of_realdim = camlidl_malloc(_c4 * sizeof(ap_var_t ), _ctx); for (_c5 = 0; _c5 < _c4; _c5++) { _v6 = Field(_v_name_of_realdim, _c5); camlidl_ml2c_var_ap_var_t(_v6, &name_of_realdim[_c5], _ctx); } realdim = _c4; /* begin user-supplied calling sequence */ _res = ap_environment_add(e,name_of_intdim,intdim,name_of_realdim,realdim); if (_res==NULL){ camlidl_free(_ctx); caml_failwith("Environment.add: duplicated variable names"); } assert(_res->count >= 1); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_environment_ap_environment_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_environment_ap_environment_remove( value _v_e, value _v_tvar) { ap_environment_ptr e; /*in*/ ap_var_t *tvar; /*in*/ int size; /*in*/ ap_environment_ptr _res; mlsize_t _c1; mlsize_t _c2; value _v3; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_environment_ap_environment_ptr(_v_e, &e, _ctx); _c1 = Wosize_val(_v_tvar); tvar = camlidl_malloc(_c1 * sizeof(ap_var_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_tvar, _c2); camlidl_ml2c_var_ap_var_t(_v3, &tvar[_c2], _ctx); } size = _c1; /* begin user-supplied calling sequence */ _res = ap_environment_remove(e,tvar,size); if (_res==NULL){ camlidl_free(_ctx); caml_failwith("Environment.remove: unknown variable names"); } assert(_res->count >= 1); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_environment_ap_environment_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_environment_ap_environment_rename( value _v_e, value _v_tvar1, value _v_tvar2) { ap_environment_ptr e; /*in*/ ap_var_t *tvar1; /*in*/ ap_var_t *tvar2; /*in*/ int size1; /*in*/ int size2; /*in*/ ap_environment_ptr _res; mlsize_t _c1; mlsize_t _c2; value _v3; mlsize_t _c4; mlsize_t _c5; value _v6; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_environment_ap_environment_ptr(_v_e, &e, _ctx); _c1 = Wosize_val(_v_tvar1); tvar1 = camlidl_malloc(_c1 * sizeof(ap_var_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_tvar1, _c2); camlidl_ml2c_var_ap_var_t(_v3, &tvar1[_c2], _ctx); } size1 = _c1; _c4 = Wosize_val(_v_tvar2); tvar2 = camlidl_malloc(_c4 * sizeof(ap_var_t ), _ctx); for (_c5 = 0; _c5 < _c4; _c5++) { _v6 = Field(_v_tvar2, _c5); camlidl_ml2c_var_ap_var_t(_v6, &tvar2[_c5], _ctx); } size2 = _c4; /* begin user-supplied calling sequence */ if (size1!=size2){ camlidl_free(_ctx); caml_failwith("Environment.rename: arrays of different sizes"); } else { struct ap_dimperm_t perm; _res = ap_environment_rename(e,tvar1,tvar2,size1,&perm); ap_dimperm_clear(&perm); if (_res==NULL){ camlidl_free(_ctx); caml_failwith("Environment.rename: unknown variables or interference of new variables with unrenamed variables"); } } assert(_res->count >= 1); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_environment_ap_environment_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_environment_ap_environment_rename_perm( value _v_e, value _v_tvar1, value _v_tvar2) { ap_environment_ptr e; /*in*/ ap_var_t *tvar1; /*in*/ ap_var_t *tvar2; /*in*/ int size1; /*in*/ int size2; /*in*/ struct ap_dimperm_t perm; /*out*/ ap_environment_ptr _res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; mlsize_t _c1; mlsize_t _c2; value _v3; mlsize_t _c4; mlsize_t _c5; value _v6; value _vresult; value _vres[2] = { 0, 0, }; camlidl_ml2c_environment_ap_environment_ptr(_v_e, &e, _ctx); _c1 = Wosize_val(_v_tvar1); tvar1 = camlidl_malloc(_c1 * sizeof(ap_var_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_tvar1, _c2); camlidl_ml2c_var_ap_var_t(_v3, &tvar1[_c2], _ctx); } size1 = _c1; _c4 = Wosize_val(_v_tvar2); tvar2 = camlidl_malloc(_c4 * sizeof(ap_var_t ), _ctx); for (_c5 = 0; _c5 < _c4; _c5++) { _v6 = Field(_v_tvar2, _c5); camlidl_ml2c_var_ap_var_t(_v6, &tvar2[_c5], _ctx); } size2 = _c4; /* begin user-supplied calling sequence */ if (size1!=size2){ camlidl_free(_ctx); caml_failwith("Environment.rename: arrays of different sizes"); } else { _res = ap_environment_rename(e,tvar1,tvar2,size1,&perm); if (_res==NULL){ camlidl_free(_ctx); caml_failwith("Environment.rename_dimperm: unknown variables or interference of new variables with unrenamed variables"); } } assert(_res->count >= 1); /* end user-supplied calling sequence */ Begin_roots_block(_vres, 2) _vres[0] = camlidl_c2ml_environment_ap_environment_ptr(&_res, _ctx); _vres[1] = camlidl_c2ml_dim_struct_ap_dimperm_t(&perm, _ctx); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ ap_dimperm_clear(&perm); /* end user-supplied deallocation sequence */ return _vresult; } value camlidl_environment_ap_environment_lce( value _v_e1, value _v_e2) { ap_environment_ptr e1; /*in*/ ap_environment_ptr e2; /*in*/ ap_environment_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_environment_ap_environment_ptr(_v_e1, &e1, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_e2, &e2, _ctx); /* begin user-supplied calling sequence */ { ap_dimchange_t *c1; ap_dimchange_t *c2; _res = ap_environment_lce(e1,e2,&c1,&c2); if (c1) ap_dimchange_free(c1); if (c2) ap_dimchange_free(c2); } if (_res==NULL){ camlidl_free(_ctx); caml_failwith("Environment.lce: variable with two different types"); } assert(_res->count >= 1); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_environment_ap_environment_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_environment_ap_environment_lce_change( value _v_e1, value _v_e2) { ap_environment_ptr e1; /*in*/ ap_environment_ptr e2; /*in*/ ap_dimchange_t *c1; /*out*/ ap_dimchange_t *c2; /*out*/ ap_environment_ptr _res; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; ap_dimchange_t _c1; ap_dimchange_t _c2; value _v3; value _v4; value _vresult; value _vres[3] = { 0, 0, 0, }; camlidl_ml2c_environment_ap_environment_ptr(_v_e1, &e1, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_e2, &e2, _ctx); c1 = &_c1; c2 = &_c2; /* begin user-supplied calling sequence */ { _res = ap_environment_lce(e1,e2,&c1,&c2); } if (_res==NULL){ camlidl_free(_ctx); caml_failwith("Environment.lce: variable with two different types"); } assert(_res->count >= 1); /* end user-supplied calling sequence */ Begin_roots_block(_vres, 3) _vres[0] = camlidl_c2ml_environment_ap_environment_ptr(&_res, _ctx); if (c1 == NULL) { _vres[1] = Val_int(0); } else { _v3 = camlidl_c2ml_dim_ap_dimchange_t(&*c1, _ctx); Begin_root(_v3) _vres[1] = camlidl_alloc_small(1, 0); Field(_vres[1], 0) = _v3; End_roots(); } if (c2 == NULL) { _vres[2] = Val_int(0); } else { _v4 = camlidl_c2ml_dim_ap_dimchange_t(&*c2, _ctx); Begin_root(_v4) _vres[2] = camlidl_alloc_small(1, 0); Field(_vres[2], 0) = _v4; End_roots(); } _vresult = camlidl_alloc_small(3, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; Field(_vresult, 2) = _vres[2]; End_roots() camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (c1) ap_dimchange_free(c1); if (c2) ap_dimchange_free(c2); /* end user-supplied deallocation sequence */ return _vresult; } value camlidl_environment_ap_environment_dimchange( value _v_e1, value _v_e2) { ap_environment_ptr e1; /*in*/ ap_environment_ptr e2; /*in*/ ap_dimchange_t *_res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_environment_ap_environment_ptr(_v_e1, &e1, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_e2, &e2, _ctx); /* begin user-supplied calling sequence */ _res = ap_environment_dimchange(e1,e2); if (_res==NULL){ camlidl_free(_ctx); caml_failwith("Environment.dimchange: the second environment is not a superenvironment of the first one"); } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_dim_ap_dimchange_t(&*_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ ap_dimchange_free(_res); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_environment_ap_environment_dimchange2( value _v_e1, value _v_e2) { ap_environment_ptr e1; /*in*/ ap_environment_ptr e2; /*in*/ struct ap_dimchange2_t *_res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_environment_ap_environment_ptr(_v_e1, &e1, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_e2, &e2, _ctx); /* begin user-supplied calling sequence */ _res = ap_environment_dimchange2(e1,e2); if (_res==NULL){ camlidl_free(_ctx); caml_failwith("Environment.dimchange2: the two environments are not compatible"); } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_dim_struct_ap_dimchange2_t(&*_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ ap_dimchange2_free(_res); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_environment_ap_environment_equal( value _v_env1, value _v_env2) { ap_environment_ptr env1; /*in*/ ap_environment_ptr env2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_environment_ap_environment_ptr(_v_env1, &env1, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env2, &env2, _ctx); /* begin user-supplied calling sequence */ _res = ap_environment_is_eq(env1,env2); /* end user-supplied calling sequence */ _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_environment_ap_environment_compare( value _v_env1, value _v_env2) { ap_environment_ptr env1; /*in*/ ap_environment_ptr env2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_environment_ap_environment_ptr(_v_env1, &env1, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env2, &env2, _ctx); _res = ap_environment_compare(env1, env2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_environment_ap_environment_hash( value _v_env) { ap_environment_ptr env; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); _res = ap_environment_hash(env); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_environment_ap_environment_dimension( value _v_e) { ap_environment_ptr e; /*in*/ struct ap_dimension_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_environment_ap_environment_ptr(_v_e, &e, _ctx); /* begin user-supplied calling sequence */ _res.intdim = e->intdim; _res.realdim = e->realdim; /* end user-supplied calling sequence */ _vres = camlidl_c2ml_dim_struct_ap_dimension_t(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_environment_ap_environment_size( value _v_e) { ap_environment_ptr e; /*in*/ unsigned int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_environment_ap_environment_ptr(_v_e, &e, _ctx); /* begin user-supplied calling sequence */ _res = e->intdim + e->realdim; /* end user-supplied calling sequence */ _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_environment_ap_environment_mem_var( value _v_e, value _v_var) { ap_environment_ptr e; /*in*/ ap_var_t var; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_environment_ap_environment_ptr(_v_e, &e, _ctx); camlidl_ml2c_var_ap_var_t(_v_var, &var, _ctx); /* begin user-supplied calling sequence */ { ap_dim_t dim; dim = ap_environment_dim_of_var(e,var); _res = (dim != AP_DIM_MAX); } /* end user-supplied calling sequence */ _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_environment_ap_environment_typ_of_var( value _v_e, value _v_var) { ap_environment_ptr e; /*in*/ ap_var_t var; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_environment_ap_environment_ptr(_v_e, &e, _ctx); camlidl_ml2c_var_ap_var_t(_v_var, &var, _ctx); /* begin user-supplied calling sequence */ { ap_dim_t dim; dim = ap_environment_dim_of_var(e,var); if (dim==AP_DIM_MAX) caml_failwith("Environment.dim_of_var: unknown variable in the environment"); _res = dim=( dimintdim ? AP_INT : AP_REAL); } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_environment_enum_typvar(_res); camlidl_free(_ctx); return _vres; } value camlidl_environment_ap_environment_vars( value _v_e) { ap_environment_ptr e; /*in*/ ap_var_t *name_of_intdim; /*out*/ ap_var_t *name_of_realdim; /*out*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; mlsize_t _c1; value _v2; mlsize_t _c3; value _v4; value _vresult; value _vres[2] = { 0, 0, }; camlidl_ml2c_environment_ap_environment_ptr(_v_e, &e, _ctx); name_of_intdim = camlidl_malloc((*e).intdim * sizeof(ap_var_t ), _ctx); name_of_realdim = camlidl_malloc((*e).realdim * sizeof(ap_var_t ), _ctx); /* begin user-supplied calling sequence */ { size_t i; for(i=0;iintdim;i++) name_of_intdim[i] = ap_var_operations->copy(e->var_of_dim[i]); for(i=0;irealdim;i++) name_of_realdim[i] = ap_var_operations->copy(e->var_of_dim[e->intdim+i]); } /* end user-supplied calling sequence */ Begin_roots_block(_vres, 2) _vres[0] = camlidl_alloc((*e).intdim, 0); Begin_root(_vres[0]) for (_c1 = 0; _c1 < (*e).intdim; _c1++) { _v2 = camlidl_c2ml_var_ap_var_t(&name_of_intdim[_c1], _ctx); modify(&Field(_vres[0], _c1), _v2); } End_roots() _vres[1] = camlidl_alloc((*e).realdim, 0); Begin_root(_vres[1]) for (_c3 = 0; _c3 < (*e).realdim; _c3++) { _v4 = camlidl_c2ml_var_ap_var_t(&name_of_realdim[_c3], _ctx); modify(&Field(_vres[1], _c3), _v4); } End_roots() _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); return _vresult; } value camlidl_environment_ap_environment_var_of_dim( value _v_e, value _v_dim) { ap_environment_ptr e; /*in*/ ap_dim_t dim; /*in*/ ap_var_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_environment_ap_environment_ptr(_v_e, &e, _ctx); camlidl_ml2c_dim_ap_dim_t(_v_dim, &dim, _ctx); /* begin user-supplied calling sequence */ if (dim>=e->intdim+e->realdim){ caml_failwith("Environment.var_of_dim: dim out of range w.r.t. the environment"); } _res = ap_var_operations->copy(e->var_of_dim[dim]); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_var_ap_var_t(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_environment_ap_environment_dim_of_var( value _v_e, value _v_var) { ap_environment_ptr e; /*in*/ ap_var_t var; /*in*/ ap_dim_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_environment_ap_environment_ptr(_v_e, &e, _ctx); camlidl_ml2c_var_ap_var_t(_v_var, &var, _ctx); /* begin user-supplied calling sequence */ _res = ap_environment_dim_of_var(e,var); if (_res==AP_DIM_MAX){ caml_failwith("Environment.dim_of_var: unknown variable in the environment"); } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_dim_ap_dim_t(&_res, _ctx); camlidl_free(_ctx); return _vres; } apron-dist-0.9.10/apron/mlapronidl/scalar.mli0000640014525101416610000000403111252216514020772 0ustar bjeannetpopart(* File generated from scalar.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = Float of float | Mpqf of Mpqf.t | Mpfrf of Mpfrf.t (** APRON Scalar numbers. See {!Mpqf} for operations on GMP multiprecision rational numbers and {!Mpfr} for operations on MPFR multi-precision floating-point numbers. *) val of_mpq : Mpq.t -> t val of_mpqf : Mpqf.t -> t val of_int : int -> t val of_frac : int -> int -> t (** Create a scalar of type [Mpqf] from resp. - A multi-precision rational [Mpq.t] - A multi-precision rational [Mpqf.t] - an integer - a fraction [x/y] *) val of_mpfr : Mpfr.t -> t val of_mpfrf : Mpfrf.t -> t (** Create a scalar of type [Mpfrf] with the given value *) val of_float : float -> t (** Create a scalar of type [Float] with the given value *) val of_infty : int -> t (** Create a scalar of type [Float] with the value multiplied by infinity (resulting in minus infinity, zero, or infinity *) val is_infty : t -> int (** Infinity test. [is_infty x] returns [-1] if x is [-oo], [1] if x is [+oo], and [0] if [x] is finite. *) val sgn : t -> int (** Return the sign of the coefficient, which may be a negative value, zero or a positive value. *) val cmp : t -> t -> int (** Compare two coefficients, possibly converting to [Mpqf.t]. [compare x y] returns a negative number if [x] is less than [y], [0] if they ar equal, and a positive number if [x] is greater than [y]. *) val cmp_int : t -> int -> int (** Compare a coefficient with an integer *) val equal : t -> t -> bool (** Equality test, possibly using a conversion to [Mpqf.t]. Return [true] if the 2 values are equal. Two infinite values of the same signs are considered as equal. *) val equal_int : t -> int -> bool (** Equality test with an integer *) val neg : t -> t (** Negation *) val to_string : t -> string (** Conversion to string, using [string_of_double], [Mpqf.to_string] or [Mpfr.to_string] *) val print : Format.formatter -> t -> unit (** Print a coefficient *) apron-dist-0.9.10/apron/mlapronidl/generator1_caml.c0000640014525101416610000003007111252216516022236 0ustar bjeannetpopart/* File generated from generator1.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include #include "ap_generator1.h" #include "apron_caml.h" extern void camlidl_apron_scalar_ml2c(value, ap_scalar_t *); #define camlidl_ml2c_scalar_ap_scalar_t(v,c,ctx) camlidl_apron_scalar_ml2c(v,c) extern value camlidl_apron_scalar_c2ml(ap_scalar_t *); #define camlidl_c2ml_scalar_ap_scalar_t(c,ctx) camlidl_apron_scalar_c2ml(c) extern void camlidl_ml2c_scalar_ap_scalar_ptr(value, ap_scalar_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_ap_scalar_ptr(ap_scalar_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_scalar_struct_ap_scalar_array_t(value, struct ap_scalar_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_struct_ap_scalar_array_t(struct ap_scalar_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_t(value, struct ap_interval_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_t(struct ap_interval_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_ap_interval_ptr(value, ap_interval_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_ap_interval_ptr(ap_interval_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_array_t(value, struct ap_interval_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_array_t(struct ap_interval_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_coeff_struct_ap_coeff_t(value, struct ap_coeff_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_coeff_struct_ap_coeff_t(struct ap_coeff_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_ap_dim_t(value, ap_dim_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_ap_dim_t(ap_dim_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimchange_t(value, struct ap_dimchange_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange_t(struct ap_dimchange_t *, camlidl_ctx _ctx); extern void camlidl_apron_dimchange_ml2c(value, ap_dimchange_t *); #define camlidl_ml2c_dim_ap_dimchange_t(v,c,ctx) camlidl_apron_dimchange_ml2c(v,c) extern value camlidl_apron_dimchange_c2ml(ap_dimchange_t *); #define camlidl_c2ml_dim_ap_dimchange_t(c,ctx) camlidl_apron_dimchange_c2ml(c) extern void camlidl_ml2c_dim_struct_ap_dimchange2_t(value, struct ap_dimchange2_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange2_t(struct ap_dimchange2_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimperm_t(value, struct ap_dimperm_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimperm_t(struct ap_dimperm_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimension_t(value, struct ap_dimension_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimension_t(struct ap_dimension_t *, camlidl_ctx _ctx); extern void camlidl_apron_linexpr0_ptr_ml2c(value, ap_linexpr0_ptr *); #define camlidl_ml2c_linexpr0_ap_linexpr0_ptr(v,c,ctx) camlidl_apron_linexpr0_ptr_ml2c(v,c) extern value camlidl_apron_linexpr0_ptr_c2ml(ap_linexpr0_ptr *); #define camlidl_c2ml_linexpr0_ap_linexpr0_ptr(c,ctx) camlidl_apron_linexpr0_ptr_c2ml(c) extern int camlidl_ml2c_generator0_enum_gentyp(value); extern value camlidl_c2ml_generator0_enum_gentyp(int); extern int camlidl_transl_table_generator0_enum_gentyp[]; extern void camlidl_ml2c_generator0_struct_ap_generator0_t(value, struct ap_generator0_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_generator0_struct_ap_generator0_t(struct ap_generator0_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_generator0_struct_ap_generator0_array_t(value, struct ap_generator0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_generator0_struct_ap_generator0_array_t(struct ap_generator0_array_t *, camlidl_ctx _ctx); extern void camlidl_apron_var_ptr_ml2c(value, ap_var_t *); #define camlidl_ml2c_var_ap_var_t(v,c,ctx) camlidl_apron_var_ptr_ml2c(v,c) extern value camlidl_apron_var_ptr_c2ml(ap_var_t *); #define camlidl_c2ml_var_ap_var_t(c,ctx) camlidl_apron_var_ptr_c2ml(c) extern int camlidl_ml2c_environment_enum_typvar(value); extern value camlidl_c2ml_environment_enum_typvar(int); extern int camlidl_transl_table_environment_enum_typvar[]; extern void camlidl_apron_environment_ptr_ml2c(value, ap_environment_ptr *); #define camlidl_ml2c_environment_ap_environment_ptr(v,c,ctx) camlidl_apron_environment_ptr_ml2c(v,c) extern value camlidl_apron_environment_ptr_c2ml(ap_environment_ptr *); #define camlidl_c2ml_environment_ap_environment_ptr(c,ctx) camlidl_apron_environment_ptr_c2ml(c) extern void camlidl_ml2c_linexpr1_struct_ap_linexpr1_t(value, struct ap_linexpr1_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_linexpr1_struct_ap_linexpr1_t(struct ap_linexpr1_t *, camlidl_ctx _ctx); void camlidl_ml2c_generator1_struct_ap_generator1_t(value _v1, struct ap_generator1_t * _c2, camlidl_ctx _ctx) { value _v3; value _v4; _v3 = Field(_v1, 0); camlidl_ml2c_generator0_struct_ap_generator0_t(_v3, &(*_c2).generator0, _ctx); _v4 = Field(_v1, 1); camlidl_ml2c_environment_ap_environment_ptr(_v4, &(*_c2).env, _ctx); } value camlidl_c2ml_generator1_struct_ap_generator1_t(struct ap_generator1_t * _c1, camlidl_ctx _ctx) { value _v2; value _v3[2]; _v3[0] = _v3[1] = 0; Begin_roots_block(_v3, 2) _v3[0] = camlidl_c2ml_generator0_struct_ap_generator0_t(&(*_c1).generator0, _ctx); _v3[1] = camlidl_c2ml_environment_ap_environment_ptr(&(*_c1).env, _ctx); _v2 = camlidl_alloc_small(2, 0); Field(_v2, 0) = _v3[0]; Field(_v2, 1) = _v3[1]; End_roots() return _v2; } void camlidl_ml2c_generator1_struct_ap_generator1_array_t(value _v1, struct ap_generator1_array_t * _c2, camlidl_ctx _ctx) { value _v3; value _v4; _v3 = Field(_v1, 0); camlidl_ml2c_generator0_struct_ap_generator0_array_t(_v3, &(*_c2).generator0_array, _ctx); _v4 = Field(_v1, 1); camlidl_ml2c_environment_ap_environment_ptr(_v4, &(*_c2).env, _ctx); } value camlidl_c2ml_generator1_struct_ap_generator1_array_t(struct ap_generator1_array_t * _c1, camlidl_ctx _ctx) { value _v2; value _v3[2]; _v3[0] = _v3[1] = 0; Begin_roots_block(_v3, 2) _v3[0] = camlidl_c2ml_generator0_struct_ap_generator0_array_t(&(*_c1).generator0_array, _ctx); _v3[1] = camlidl_c2ml_environment_ap_environment_ptr(&(*_c1).env, _ctx); _v2 = camlidl_alloc_small(2, 0); Field(_v2, 0) = _v3[0]; Field(_v2, 1) = _v3[1]; End_roots() return _v2; } value camlidl_generator1_ap_generator1_get_coeff( value _v_a, value _v_var) { struct ap_generator1_t *a; /*in*/ ap_var_t var; /*in*/ struct ap_coeff_t _res; struct ap_generator1_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; a = &_c1; camlidl_ml2c_generator1_struct_ap_generator1_t(_v_a, &_c1, _ctx); camlidl_ml2c_var_ap_var_t(_v_var, &var, _ctx); /* begin user-supplied calling sequence */ { bool b; ap_coeff_init(&_res,AP_COEFF_SCALAR); b = ap_generator1_get_coeff(&_res,a,var); if (b){ char str[160]; char* name; ap_coeff_clear(&_res); name = ap_var_operations->to_string(var); snprintf(str,159,"Generator1.get_coeff: unknown variable %s in the environment",name); free(name); caml_failwith(str); } } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_coeff_struct_ap_coeff_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ ap_coeff_clear(&_res); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_generator1_ap_generator1_set_coeff( value _v_a, value _v_var, value _v_coeff) { struct ap_generator1_t *a; /*in*/ ap_var_t var; /*in*/ struct ap_coeff_t *coeff; /*in*/ struct ap_generator1_t _c1; struct ap_coeff_t _c2; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; a = &_c1; camlidl_ml2c_generator1_struct_ap_generator1_t(_v_a, &_c1, _ctx); camlidl_ml2c_var_ap_var_t(_v_var, &var, _ctx); coeff = &_c2; camlidl_ml2c_coeff_struct_ap_coeff_t(_v_coeff, &_c2, _ctx); /* begin user-supplied calling sequence */ { bool b; b = ap_generator1_set_coeff(a,var,coeff); if (b){ char str[160]; char* name; name = ap_var_operations->to_string(var); snprintf(str,159,"Generator1.set_coeff: unknown variable %s in the environment",name); free(name); caml_failwith(str); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_generator1_ap_generator1_extend_environment( value _v_generator, value _v_env) { struct ap_generator1_t generator; /*in*/ ap_environment_ptr env; /*in*/ struct ap_generator1_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_generator1_struct_ap_generator1_t(_v_generator, &generator, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); /* begin user-supplied calling sequence */ { bool b; b = ap_generator1_extend_environment(&_res,&generator,env); if (b) caml_failwith("Generator1.extend_environment: new environment is not a superenvironment"); } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_generator1_struct_ap_generator1_t(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_generator1_ap_generator1_extend_environment_with( value _v_generator, value _v_env) { struct ap_generator1_t generator; /*in*/ ap_environment_ptr env; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_generator1_struct_ap_generator1_t(_v_generator, &generator, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); /* begin user-supplied calling sequence */ { if (generator.env!=env){ bool b; ap_environment_copy(generator.env); /* to protect it */ b = ap_generator1_extend_environment_with(&generator,env); if (b){ ap_environment_free(generator.env); caml_failwith("Generator1.extend_environment_with: new environment is not a superenvironment"); } Store_field(_v_generator,1,_v_env); ap_environment_free(env); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_generator1_ap_generator1_array_extend_environment( value _v_array, value _v_env) { struct ap_generator1_array_t array; /*in*/ ap_environment_ptr env; /*in*/ struct ap_generator1_array_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_generator1_struct_ap_generator1_array_t(_v_array, &array, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); /* begin user-supplied calling sequence */ { bool b; b = ap_generator1_array_extend_environment(&_res,&array,env); if (b) caml_failwith("Generator1.array_extend_environment: new environment is not a superenvironment"); } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_generator1_struct_ap_generator1_array_t(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_generator1_ap_generator1_array_extend_environment_with( value _v_array, value _v_env) { struct ap_generator1_array_t array; /*in*/ ap_environment_ptr env; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_generator1_struct_ap_generator1_array_t(_v_array, &array, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); /* begin user-supplied calling sequence */ { if (array.env!=env){ bool b; ap_environment_copy(array.env); /* to protect it */ b = ap_generator1_array_extend_environment_with(&array,env); if (b){ ap_environment_free(array.env); caml_failwith("Generator1.array_extend_environment_with: new environment is not a superenvironment"); } Store_field(_v_array,1,_v_env); ap_environment_free(env); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } apron-dist-0.9.10/apron/mlapronidl/tcons0.ml0000640014525101416610000000130511252216515020564 0ustar bjeannetpopart(* File generated from tcons0.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = { mutable texpr0 : Texpr0.t; mutable typ : Lincons0.typ; } type typ = Lincons0.typ = | EQ | SUPEQ | SUP | DISEQ | EQMOD of Scalar.t let string_of_typ = Lincons0.string_of_typ let print assoc fmt cons = Texpr0.print assoc fmt cons.texpr0; Format.fprintf fmt " %s 0" (string_of_typ cons.typ); begin match cons.typ with | EQMOD x -> Format.fprintf fmt " mod %a" Scalar.print x; | _ -> () end; () let make expr typ = { texpr0 = expr; typ = typ } let copy cons = { texpr0 = Texpr0.copy cons.texpr0; typ = cons.typ } apron-dist-0.9.10/apron/mlapronidl/interval.mli0000640014525101416610000000362011252216515021355 0ustar bjeannetpopart(* File generated from interval.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = { mutable inf: Scalar.t; mutable sup: Scalar.t; } (** APRON Intervals on scalars *) val of_scalar : Scalar.t -> Scalar.t -> t (** Build an interval from a lower and an upper bound *) val of_infsup : Scalar.t -> Scalar.t -> t (** depreciated *) val of_mpq : Mpq.t -> Mpq.t -> t val of_mpqf : Mpqf.t -> Mpqf.t -> t val of_int : int -> int -> t val of_frac : int -> int -> int -> int -> t val of_float : float -> float -> t val of_mpfr : Mpfr.t -> Mpfr.t -> t (** Create an interval from resp. two - multi-precision rationals [Mpq.t] - multi-precision rationals [Mpqf.t] - integers - fractions [x/y] and [z/w] - machine floats - Mpfr floats *) val is_top : t -> bool (** Does the interval represent the universe ([[-oo,+oo]]) ? *) val is_bottom : t -> bool (** Does the interval contain no value ([[a,b]] with a>b) ? *) val is_leq : t -> t -> bool (** Inclusion test. [is_leq x y] returns [true] if [x] is included in [y] *) val cmp : t -> t -> int (** Non Total Comparison: 0: equality -1: i1 included in i2 +1: i2 included in i1 -2: i1.inf less than or equal to i2.inf +2: i1.inf greater than i2.inf *) val equal : t -> t -> bool (** Equality test *) val is_zero : t -> bool (** Is the interval equal to [0,0] ? *) val equal_int : t -> int -> bool (** Is the interval equal to [i,i] ? *) val neg : t -> t (** Negation *) val top : t val bottom : t (** Top and bottom intervals (using [DOUBLE] coefficients) *) val set_infsup : t -> Scalar.t -> Scalar.t -> unit (** Fill the interval with the given lower and upper bouunds *) val set_top : t -> unit val set_bottom : t -> unit (** Fill the interval with top (resp. bottom) value *) val print : Format.formatter -> t -> unit (** Print an interval, under the format [[inf,sup]] *) apron-dist-0.9.10/apron/mlapronidl/Makefile0000640014525101416610000003302311251737120020465 0ustar bjeannetpopartinclude ../Makefile.config #--------------------------------------- # Directories #--------------------------------------- SRCDIR = $(shell pwd) # # PREFIX = $(APRON_PREFIX) # #--------------------------------------- # CAML part #--------------------------------------- OCAMLINC = -I $(MLGMPIDL_PREFIX)/lib #--------------------------------------- # C part #--------------------------------------- ICFLAGS = \ -I$(MLGMPIDL_PREFIX)/include -I../apron \ -I$(GMP_PREFIX)/include \ -I$(MPFR_PREFIX)/include \ -I$(CAML_PREFIX)/lib/ocaml -I$(CAMLIDL_PREFIX)/lib/ocaml #--------------------------------------- # Files #--------------------------------------- IDLMODULES = \ scalar interval coeff \ dim linexpr0 lincons0 generator0 texpr0 tcons0 manager abstract0 \ var environment linexpr1 lincons1 generator1 texpr1 tcons1 abstract1 IDLMODULEStex = Introduction.tex \ Scalar.tex Interval.tex Coeff.tex \ Dim.tex Linexpr0.tex Lincons0.tex Generator0.tex Texpr0.tex Tcons0.tex Texpr1.tex Tcons1.tex Manager.tex Abstract0.tex \ Var.tex Environment.tex Linexpr1.tex Lincons1.tex Generator1.tex Texpr1.tex Tcons1.tex Abstract1.tex \ Mpz.tex Mpq.tex Mpzf.tex Mpqf.tex Mpf.tex Gmp_random.tex Mpfr.tex Mpfrf.tex Box.tex Oct.tex Polka.tex Ppl.tex PolkaGrid.tex MLMODULES = $(IDLMODULES) apron_parser apron_lexer parser MLSRC = $(MLMODULES:%=%.mli) $(MLMODULES:%=%.ml) apron_lexer.mll apron_parser.mly MLINT = $(MLMODULES:%=%.cmi) MLOBJ = $(MLMODULES:%=%.cmo) MLOBJx = $(MLMODULES:%=%.cmx) MLLIB_TOINSTALL = $(IDLMODULES:%=%.idl) apron.cmi apron.cma MLLIB_TOINSTALLx = apron.cmx apron.cmxa apron.a CCMODULES = apron_caml $(IDLMODULES:%=%_caml) CCSRC = apron_caml.h $(CCMODULES:%=%.c) CCLIB_TOINSTALL = libapron_caml.a libapron_caml_debug.a libapron_caml.so libapron_caml_debug.so dllapron_caml.so dllapron_caml_debug.so CCINC_TOINSTALL = apron_caml.h #--------------------------------------- # Rules #--------------------------------------- all: apron.cmi apron.cmx apron.cma apron.cmxa apron.a libapron_caml.a libapron_caml_debug.a ifneq ($(HAS_SHARED),) all: libapron_caml.so libapron_caml_debug.so dllapron_caml.so dllapron_caml_debug.so endif mldep: $(MLSRC) ocamldep $(MLSRC) #--------------------------------------- # Misc rules #--------------------------------------- tar: $(IDLMODULES:%=%.idl) apron_lexer.mll apron_lexer.mli apron_parser.mly parser.ml parser.mli apron_caml.c apron_caml.h macros.m4 Makefile COPYING README mlapronidl.tex sedscript_caml sedscript_c (cd ..; tar zcvf mlapronidl.tgz $(^:%=mlapronidl/%)) dist: $(IDLMODULES:%=%.idl) $(MLSRC) $(CCSRC) macros.m4 apron_caml.c apron_caml.h Makefile COPYING README mlapronidl.tex sedscript_caml sedscript_c mlapronidl.pdf html (cd ..; tar zcvf mlapronidl.tgz $(^:%=mlapronidl/%)) clean: /bin/rm -f $(IDLMODULEStex) Apron_lexer.tex Apron_parser.tex Parser.tex /bin/rm -f mpz.idl mpq.idl /bin/rm -f mlapronidl.out mlapronidl.aux mlapronidl.idx mlapronidl.ilg mlapronidl.ind mlapronidl.bbl mlapronidl.blg mlapronidl.dvi mlapronidl.log mlapronidl.toc mlapronidl.ps mlapronidl.pdf /bin/rm -f *.o *.a *.so *.cmi *.cmo *.cmx *.cmxa *.cma apron_parser.ml apron_parser.mli apron_lexer.ml /bin/rm -fr tmp html /bin/rm -f ocamldoc.[cefkimoptv]* ocamldoc.sty mostlyclean: clean /bin/rm -f $(IDLMODULES:%=%.ml) $(IDLMODULES:%=%.mli) $(IDLMODULES:%=%_caml.c) distclean: /bin/rm -f $(MLLIB_TOINSTALL:%=$(APRON_PREFIX)/lib/%) /bin/rm -f $(MLLIB_TOINSTALLx:%=$(APRON_PREFIX)/lib/%) /bin/rm -f $(CCLIB_TOINSTALL:%=$(APRON_PREFIX)/lib/%) /bin/rm -f $(CCINC_TOINSTALL:%=$(APRON_PREFIX)/include/%) install: $(MLLIB_TOINSTALL) $(MLLIB_TOINSTALLx) $(CCLIB_TOINSTALL) $(CCINC_TOINSTALL) mkdir -p $(APRON_PREFIX)/lib mkdir -p $(APRON_PREFIX)/include for i in $(MLLIB_TOINSTALL) $(MLLIB_TOINSTALLx) $(CCLIB_TOINSTALL); do if test -f $$i; then cp -f -d $$i $(APRON_PREFIX)/lib; fi; done $(INSTALL) $(CCINC_TOINSTALL) $(APRON_PREFIX)/include #--------------------------------------- # Library rules #--------------------------------------- apron.cma: apron.cmo libapron_caml.a $(OCAMLMKLIB) -ocamlc "$(OCAMLC)" -verbose -o apron -oc apron_caml apron.cmo -lapron -L$(APRON_PREFIX)/lib -Wl,-rpath,$(APRON_PREFIX)/lib apron.cmxa: apron.cmx libapron_caml.a $(OCAMLMKLIB) -ocamlopt "$(OCAMLOPT)" -verbose -o apron -oc apron_caml apron.cmx -lapron -L$(APRON_PREFIX)/lib -Wl,-rpath,$(APRON_PREFIX)/lib libapron_caml.a: $(CCMODULES:%=%.o) $(AR) rc $@ $^ $(RANLIB) $@ libapron_caml_debug.a: $(CCMODULES:%=%_debug.o) $(AR) rc $@ $^ $(RANLIB) $@ libapron_caml.so: $(CCMODULES:%=%.o) ../apron/libapron.so $(CC) $(CFLAGS) -shared -o $@ $(CCMODULES:%=%.o) -L../apron -lapron -Wl,-rpath,$(APRON_PREFIX)/lib libapron_caml_debug.so: $(CCMODULES:%=%_debug.o) ../apron/libapron_debug.so $(CC) $(CFLAGS_DEBUG) -shared -o $@ $(CCMODULES:%=%_debug.o) -L../apron -lapron -Wl,-rpath,$(APRON_PREFIX)/lib dllapron_caml.so: libapron_caml.so ln -s $^ $@ dllapron_caml_debug.so: libapron_caml_debug.so ln -s $^ $@ #--------------------------------------- # CAML rules #--------------------------------------- apron.cmo apron.cmi: $(MLOBJ) $(MLINT) $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -pack -o $@ $(MLOBJ) apron.cmx apron.o: $(MLOBJx) $(OCAMLOPT) $(OCAMLOPTFLAGS) -pack -o $@ $(MLOBJx) apron_lexer.ml: apron_lexer.mll $(OCAMLLEX) $^ apron_parser.ml apron_parser.mli: apron_parser.mly $(OCAMLYACC) $^ #--------------------------------------- # TEX and HTML rules #--------------------------------------- .PHONY: html mlapronidl.pdf: mlapronidl.dvi $(DVIPDF) mlapronidl.dvi mlapronidl.dvi: mlapronidl.tex introduction.mli $(MLMODULES:%=%.mli) ../box/box.mli ../octagons/oct.mli ../newpolka/polka.mli ../ppl/ppl.mli ../products/polkaGrid.mli $(MLGMPIDL_PREFIX)/lib/mpz.mli $(MLGMPIDL_PREFIX)/lib/mpq.mli $(MLGMPIDL_PREFIX)/lib/gmp_random.mli $(MLGMPIDL_PREFIX)/lib/mpf.mli $(MLGMPIDL_PREFIX)/lib/mpfr.mli $(MLGMPIDL_PREFIX)/lib/mpzf.mli $(MLGMPIDL_PREFIX)/lib/mpqf.mli $(MLGMPIDL_PREFIX)/lib/mpfrf.mli $(OCAMLDOC) $(OCAMLINC) -I ../newpolka -I ../ppl \ -latextitle 1,chapter -latextitle 2,section -latextitle 3,subsection -latextitle 4,subsubsection -latextitle 5,paragraph -latextitle 6,subparagraph -noheader -notrailer -latex -sepfiles introduction.mli $(MLMODULES:%=%.mli) ../box/box.mli ../octagons/oct.mli ../newpolka/polka.mli ../ppl/ppl.mli ../products/polkaGrid.mli $(MLGMPIDL_PREFIX)/lib/mpz.mli $(MLGMPIDL_PREFIX)/lib/mpq.mli $(MLGMPIDL_PREFIX)/lib/gmp_random.mli $(MLGMPIDL_PREFIX)/lib/mpf.mli $(MLGMPIDL_PREFIX)/lib/mpfr.mli $(MLGMPIDL_PREFIX)/lib/mpzf.mli $(MLGMPIDL_PREFIX)/lib/mpqf.mli $(MLGMPIDL_PREFIX)/lib/mpfrf.mli $(LATEX) mlapronidl $(MAKEINDEX) mlapronidl $(LATEX) mlapronidl $(LATEX) mlapronidl html: mlapronidl.odoc introduction.mli $(IDLMODULES:%=%.mli) parser.mli $(MLMODULES:%=%.mli) ../box/box.mli ../octagons/oct.mli ../newpolka/polka.mli ../ppl/ppl.mli ../products/polkaGrid.mli $(MLGMPIDL_PREFIX)/lib/mpz.mli $(MLGMPIDL_PREFIX)/lib/mpq.mli $(MLGMPIDL_PREFIX)/lib/gmp_random.mli $(MLGMPIDL_PREFIX)/lib/mpf.mli $(MLGMPIDL_PREFIX)/lib/mpfr.mli $(MLGMPIDL_PREFIX)/lib/mpzf.mli $(MLGMPIDL_PREFIX)/lib/mpqf.mli $(MLGMPIDL_PREFIX)/lib/mpfrf.mli mkdir -p html $(OCAMLDOC) $(OCAMLINC) -I ../newpolka -I ../ppl \ -html -d html -colorize-code -intro mlapronidl.odoc introduction.mli $(IDLMODULES:%=%.mli) parser.mli ../box/box.mli ../octagons/oct.mli ../newpolka/polka.mli ../ppl/ppl.mli ../products/polkaGrid.mli $(MLGMPIDL_PREFIX)/lib/mpz.mli $(MLGMPIDL_PREFIX)/lib/mpq.mli $(MLGMPIDL_PREFIX)/lib/gmp_random.mli $(MLGMPIDL_PREFIX)/lib/mpf.mli $(MLGMPIDL_PREFIX)/lib/mpfr.mli $(MLGMPIDL_PREFIX)/lib/mpzf.mli $(MLGMPIDL_PREFIX)/lib/mpqf.mli $(MLGMPIDL_PREFIX)/lib/mpfrf.mli #-------------------------------------------------------------- # IMPLICIT RULES AND DEPENDENCIES #-------------------------------------------------------------- .SUFFIXES: .tex .fig .c .h .o .ml .mli .cmi .cmo .cmx .idl _debug.o _prof.o _caml.c .nw #--------------------------------------- # C generic rules #--------------------------------------- %.o: %.c apron_caml.h $(CC) $(CFLAGS) $(ICFLAGS) -fPIC -c $< %_debug.o: %.c apron_caml.h $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -fPIC -c -o $@ $< #--------------------------------------- # IDL generic rules #--------------------------------------- mpz.idl: $(MLGMPIDL_PREFIX)/lib/mpz.idl ln -s $^ $@ mpq.idl: $(MLGMPIDL_PREFIX)/lib/mpq.idl ln -s $^ $@ # Generate for each %.idl: %i.ml, %i.mli, %_caml.c rebuild: mpz.idl mpq.idl mkdir -p tmp for i in $(IDLMODULES); do \ echo "module $$i"; \ cp $${i}.idl tmp/$${i}.idl; \ $(CAMLIDL) -no-include -prepro "$(M4) --prefix-builtins macros.m4" -I $(SRCDIR) tmp/$${i}.idl; \ $(SED) -f sedscript_c tmp/$${i}_stubs.c >$${i}_caml.c; \ $(SED) -f sedscript_caml tmp/$${i}.ml >$${i}.ml; \ $(SED) -f sedscript_caml tmp/$${i}.mli >$${i}.mli; \ done rm -fr tmp #--------------------------------------- # ML generic rules #--------------------------------------- %.cmi: %.mli $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -c $< %.cmo: %.ml %.cmi $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -c $< %.cmx: %.ml %.cmi $(OCAMLOPT) $(OCAMLOPTFLAGS) $(OCAMLINC) -for-pack Apron -c $< #--------------------------------------- # Dependencies #--------------------------------------- depend: $(MLMODULES:%=%.ml) $(MLMODULES:%=%.mli) $(OCAMLDEP) $^ scalar.cmo: scalar.cmi scalar.cmx: scalar.cmi interval.cmo: scalar.cmi interval.cmi interval.cmx: scalar.cmx interval.cmi coeff.cmo: scalar.cmi interval.cmi coeff.cmi coeff.cmx: scalar.cmx interval.cmx coeff.cmi dim.cmo: dim.cmi dim.cmx: dim.cmi linexpr0.cmo: scalar.cmi interval.cmi dim.cmi coeff.cmi linexpr0.cmi linexpr0.cmx: scalar.cmx interval.cmx dim.cmx coeff.cmx linexpr0.cmi lincons0.cmo: scalar.cmi linexpr0.cmi lincons0.cmi lincons0.cmx: scalar.cmx linexpr0.cmx lincons0.cmi generator0.cmo: linexpr0.cmi generator0.cmi generator0.cmx: linexpr0.cmx generator0.cmi texpr0.cmo: linexpr0.cmi dim.cmi coeff.cmi texpr0.cmi texpr0.cmx: linexpr0.cmx dim.cmx coeff.cmx texpr0.cmi tcons0.cmo: texpr0.cmi scalar.cmi lincons0.cmi tcons0.cmi tcons0.cmx: texpr0.cmx scalar.cmx lincons0.cmx tcons0.cmi manager.cmo: manager.cmi manager.cmx: manager.cmi abstract0.cmo: texpr0.cmi tcons0.cmi manager.cmi linexpr0.cmi lincons0.cmi \ interval.cmi generator0.cmi dim.cmi abstract0.cmi abstract0.cmx: texpr0.cmx tcons0.cmx manager.cmx linexpr0.cmx lincons0.cmx \ interval.cmx generator0.cmx dim.cmx abstract0.cmi var.cmo: var.cmi var.cmx: var.cmi environment.cmo: var.cmi dim.cmi environment.cmi environment.cmx: var.cmx dim.cmx environment.cmi linexpr1.cmo: var.cmi linexpr0.cmi environment.cmi coeff.cmi linexpr1.cmi linexpr1.cmx: var.cmx linexpr0.cmx environment.cmx coeff.cmx linexpr1.cmi lincons1.cmo: var.cmi scalar.cmi linexpr1.cmi linexpr0.cmi lincons0.cmi \ environment.cmi coeff.cmi abstract0.cmi lincons1.cmi lincons1.cmx: var.cmx scalar.cmx linexpr1.cmx linexpr0.cmx lincons0.cmx \ environment.cmx coeff.cmx abstract0.cmx lincons1.cmi generator1.cmo: var.cmi linexpr1.cmi linexpr0.cmi generator0.cmi \ environment.cmi coeff.cmi abstract0.cmi generator1.cmi generator1.cmx: var.cmx linexpr1.cmx linexpr0.cmx generator0.cmx \ environment.cmx coeff.cmx abstract0.cmx generator1.cmi texpr1.cmo: var.cmi texpr0.cmi linexpr1.cmi environment.cmi dim.cmi coeff.cmi \ texpr1.cmi texpr1.cmx: var.cmx texpr0.cmx linexpr1.cmx environment.cmx dim.cmx coeff.cmx \ texpr1.cmi tcons1.cmo: var.cmi texpr1.cmi texpr0.cmi tcons0.cmi scalar.cmi lincons0.cmi \ environment.cmi coeff.cmi abstract0.cmi tcons1.cmi tcons1.cmx: var.cmx texpr1.cmx texpr0.cmx tcons0.cmx scalar.cmx lincons0.cmx \ environment.cmx coeff.cmx abstract0.cmx tcons1.cmi abstract1.cmo: var.cmi texpr1.cmi tcons1.cmi manager.cmi linexpr1.cmi \ lincons1.cmi interval.cmi generator1.cmi environment.cmi abstract0.cmi \ abstract1.cmi abstract1.cmx: var.cmx texpr1.cmx tcons1.cmx manager.cmx linexpr1.cmx \ lincons1.cmx interval.cmx generator1.cmx environment.cmx abstract0.cmx \ abstract1.cmi apron_parser.cmo: scalar.cmi lincons0.cmi interval.cmi generator0.cmi \ coeff.cmi apron_parser.cmi apron_parser.cmx: scalar.cmx lincons0.cmx interval.cmx generator0.cmx \ coeff.cmx apron_parser.cmi apron_lexer.cmo: apron_parser.cmi apron_lexer.cmi apron_lexer.cmx: apron_parser.cmx apron_lexer.cmi parser.cmo: var.cmi manager.cmi linexpr1.cmi lincons1.cmi lincons0.cmi \ generator1.cmi generator0.cmi environment.cmi coeff.cmi apron_parser.cmi \ apron_lexer.cmi abstract1.cmi parser.cmi parser.cmx: var.cmx manager.cmx linexpr1.cmx lincons1.cmx lincons0.cmx \ generator1.cmx generator0.cmx environment.cmx coeff.cmx apron_parser.cmx \ apron_lexer.cmx abstract1.cmx parser.cmi interval.cmi: scalar.cmi coeff.cmi: scalar.cmi interval.cmi linexpr0.cmi: dim.cmi coeff.cmi lincons0.cmi: scalar.cmi linexpr0.cmi dim.cmi generator0.cmi: linexpr0.cmi dim.cmi texpr0.cmi: linexpr0.cmi dim.cmi coeff.cmi tcons0.cmi: texpr0.cmi scalar.cmi lincons0.cmi dim.cmi abstract0.cmi: texpr0.cmi tcons0.cmi manager.cmi linexpr0.cmi lincons0.cmi \ interval.cmi generator0.cmi dim.cmi environment.cmi: var.cmi dim.cmi linexpr1.cmi: var.cmi linexpr0.cmi environment.cmi coeff.cmi lincons1.cmi: var.cmi scalar.cmi linexpr1.cmi lincons0.cmi environment.cmi \ coeff.cmi generator1.cmi: var.cmi linexpr1.cmi generator0.cmi environment.cmi coeff.cmi texpr1.cmi: var.cmi texpr0.cmi linexpr1.cmi environment.cmi dim.cmi coeff.cmi tcons1.cmi: texpr1.cmi tcons0.cmi scalar.cmi lincons0.cmi environment.cmi abstract1.cmi: var.cmi texpr1.cmi tcons1.cmi manager.cmi linexpr1.cmi \ lincons1.cmi interval.cmi generator1.cmi environment.cmi abstract0.cmi apron_parser.cmi: lincons0.cmi generator0.cmi coeff.cmi apron_lexer.cmi: apron_parser.cmi parser.cmi: manager.cmi linexpr1.cmi lincons1.cmi generator1.cmi \ environment.cmi abstract1.cmi apron-dist-0.9.10/apron/mlapronidl/lincons1.ml0000640014525101416610000000720511252216516021112 0ustar bjeannetpopart(* File generated from lincons1.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = { mutable lincons0: Lincons0.t; mutable env: Environment.t; } and earray = { mutable lincons0_array: Lincons0.t array; mutable array_env: Environment.t; } (** APRON Constraints and array of constraints of level 1 *) type typ = Lincons0.typ = | EQ | SUPEQ | SUP | DISEQ | EQMOD of Scalar.t external get_coeff : t -> Var.t -> Coeff.t = "camlidl_lincons1_ap_lincons1_get_coeff" external set_coeff : t -> Var.t -> Coeff.t -> unit = "camlidl_lincons1_ap_lincons1_set_coeff" external make_unsat : Environment.t -> t = "camlidl_lincons1_ap_lincons1_make_unsat" external is_unsat : t -> bool = "camlidl_lincons1_ap_lincons1_is_unsat" external extend_environment : t -> Environment.t -> t = "camlidl_lincons1_ap_lincons1_extend_environment" external extend_environment_with : t -> Environment.t -> unit = "camlidl_lincons1_ap_lincons1_extend_environment_with" let make linexpr1 typ = { lincons0 = { Lincons0.linexpr0 = linexpr1.Linexpr1.linexpr0; Lincons0.typ = typ; }; env = linexpr1.Linexpr1.env; } let copy cons = { lincons0 = Lincons0.copy cons.lincons0; env = cons.env; } let string_of_typ = Lincons0.string_of_typ let print fmt cons = Lincons0.print (fun dim -> Var.to_string (Environment.var_of_dim cons.env dim)) fmt cons.lincons0; () let get_typ cons = cons.lincons0.Lincons0.typ let set_typ cons typ = cons.lincons0.Lincons0.typ <- typ let get_cst cons = Linexpr0.get_cst cons.lincons0.Lincons0.linexpr0 let set_cst cons cst = Linexpr0.set_cst cons.lincons0.Lincons0.linexpr0 cst let get_lincons0 cons = cons.lincons0 let get_env cons = cons.env let set_list expr list ocst = List.iter (fun (coeff,var) -> set_coeff expr var coeff ) list; begin match ocst with | Some cst -> set_cst expr cst | None -> () end; () let set_array expr tab ocst = Array.iter (fun (coeff,var) -> set_coeff expr var coeff ) tab; begin match ocst with | Some cst -> set_cst expr cst | None -> () end; () let iter f cons = Linexpr0.iter (begin fun coeff dim -> f coeff (Environment.var_of_dim cons.env dim) end) cons.lincons0.Lincons0.linexpr0 let get_linexpr1 cons = { Linexpr1.linexpr0 = cons.lincons0.Lincons0.linexpr0; Linexpr1.env = cons.env; } (* ====================================================================== *) (** {2 Type array} *) (* ====================================================================== *) external array_extend_environment : earray -> Environment.t -> earray = "camlidl_lincons1_ap_lincons1_array_extend_environment" external array_extend_environment_with : earray -> Environment.t -> unit = "camlidl_lincons1_ap_lincons1_array_extend_environment_with" let array_make env size = let cons = Lincons0.make (Linexpr0.make None) Lincons0.EQ in { lincons0_array = Array.make size cons; array_env = env } let array_print ?(first=("[|@[":(unit,Format.formatter,unit) format)) ?(sep = (";@ ":(unit,Format.formatter,unit) format)) ?(last = ("@]|]":(unit,Format.formatter,unit) format)) fmt array = Abstract0.print_array ~first ~sep ~last (Lincons0.print (fun dim -> Var.to_string (Environment.var_of_dim array.array_env dim))) fmt array.lincons0_array; () let array_length array = Array.length (array.lincons0_array) let array_get_env array = array.array_env let array_get array index = let cons0 = array.lincons0_array.(index) in { lincons0 = cons0; env = array.array_env; } let array_set array index cons1 = if not (Environment.equal array.array_env cons1.env) then failwith "Lincons1.array_set: environments are not the same" else array.lincons0_array.(index) <- cons1.lincons0; apron-dist-0.9.10/apron/mlapronidl/linexpr1.idl0000640014525101416610000001271410525143261021265 0ustar bjeannetpopart/* -*- mode: c -*- */ quote(MLI,"(** APRON Expressions of level 1 *)") quote(C, "\n\ #include \n\ #include \"ap_linexpr1.h\"\n\ #include \"apron_caml.h\"\n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "linexpr0.idl"; import "environment.idl"; struct ap_linexpr1_t { [mlname(mutable_linexpr0)] ap_linexpr0_ptr linexpr0; [mlname(mutable_env)] ap_environment_ptr env; }; quote(MLI,"\n\n\ (** Build a linear expression defined on the given argument, which is sparse by\n\ default. *)\n\ val make: ?sparse:bool -> Environment.ap_environment_ptr -> t\n\ \n\ (** In case of sparse representation, remove zero coefficients *)\n\ val minimize: t -> unit\n\ \n\ (** Copy *)\n\ val copy: t -> t\n\ \n\ (** Print the linear expression *)\n\ val print: Format.formatter -> t -> unit\n\ \n\ val set_list : t -> (Coeff.t * Var.t) list -> Coeff.t option -> unit\n\ (** Set simultaneously a number of coefficients.\n\ \n\ [set_list expr [(c1,\"x\"); (c2,\"y\")] (Some cst)] assigns coefficients [c1] \n\ to variable [\"x\"], coefficient [c2] to variable [\"y\"], and coefficient [cst]\n\ to the constant. If [(Some cst)] is replaced by [None],\n\ the constant coefficient is not assigned. *)\n\ val set_array : t -> (Coeff.t * Var.t) array -> Coeff.t option -> unit\n\ (** Set simultaneously a number of coefficients, as [set_list]. *)\n\ \n\ (** Iter the function on the pair coefficient/variable of the linear expression *)\n\ val iter: (Coeff.t -> Var.t -> unit) -> t -> unit\n\ \n\ (** Get the constant *)\n\ val get_cst: t -> Coeff.t\n\ \n\ (** Set the constant *)\n\ val set_cst: t -> Coeff.t -> unit\n\ ") quote(MLI,"(** Get the coefficient of the variable *)") struct ap_coeff_t ap_linexpr1_get_coeff([ref]struct ap_linexpr1_t* a, ap_var_t var) quote(call, "\n\ {\n\ bool b;\n\ ap_coeff_init(&_res,AP_COEFF_SCALAR);\n\ b = ap_linexpr1_get_coeff(&_res,a,var);\n\ if (b){\n\ char str[160];\n\ char* name;\n\ ap_coeff_clear(&_res);\n\ name = ap_var_operations->to_string(var);\n\ snprintf(str,159,\"Linexpr1.get_coeff: unknown variable %s in the environment\",name);\n\ free(name);\n\ caml_failwith(str);\n\ }\n\ }\n\ "); quote(MLI,"(** Set the coefficient of the variable *)") void ap_linexpr1_set_coeff([ref]struct ap_linexpr1_t* a, ap_var_t var, [ref]struct ap_coeff_t* coeff) quote(call, "\n\ {\n\ bool b;\n\ b = ap_linexpr1_set_coeff(a,var,coeff);\n\ if (b){\n\ char str[160];\n\ char* name;\n\ name = ap_var_operations->to_string(var);\n\ snprintf(str,159,\"Linexpr1.set_coeff: unknown variable %s in the environment\",name);\n\ free(name);\n\ caml_failwith(str);\n\ }\n\ }\n\ "); quote(MLI,"(** Change the environment of the expression for a super-environement. Raise [Failure] if it is not the case *)") struct ap_linexpr1_t ap_linexpr1_extend_environment(const struct ap_linexpr1_t linexpr, ap_environment_ptr env) quote(call,"\n\ {\n\ bool b;\n\ b = ap_linexpr1_extend_environment(&_res,&linexpr,env);\n\ if (b) caml_failwith(\"Linexpr1.extend_environment: new environment is not a superenvironment\");\n\ }\n\ ") ; quote(MLI,"(** Side-effet version of the previous function *)") void ap_linexpr1_extend_environment_with(struct ap_linexpr1_t linexpr, ap_environment_ptr env) quote(call,"\n\ {\n\ if (linexpr.env!=env){ \n\ bool b;\n\ ap_environment_copy(linexpr.env); /* to protect it */ \n\ b = ap_linexpr1_extend_environment_with(&linexpr,env);\n\ if (b){ \n\ ap_environment_free(linexpr.env); \n\ caml_failwith(\"Linexpr1.extend_environment_with: new environment is not a superenvironment\");\n\ }\n\ Store_field(_v_linexpr,1,_v_env);\n\ ap_environment_free(env);\n\ }\n\ }\n\ ") ; quote(MLI,"(** Does the linear expression depend only on integer variables ? *)") boolean ap_linexpr1_is_integer([ref]struct ap_linexpr1_t* e); quote(MLI,"(** Does the linear expression depend only on real variables ? *)") boolean ap_linexpr1_is_real([ref]struct ap_linexpr1_t* e); quote(MLI,"\n\ (** Get the underlying expression of level 0 (which is not a copy). *)\n\ val get_linexpr0: t -> Linexpr0.t\n\ \n\ (** Get the environement of the expression *)\n\ val get_env: t -> Environment.t\n\ \n\ ") quote(ML,"\n\ let make ?(sparse=true) env = {\n\ linexpr0 = Linexpr0.make\n\ (if sparse\n\ then None\n\ else Some (Environment.size env));\n\ env = env;\n\ }\n\ let minimize e = Linexpr0.minimize e.linexpr0\n\ let copy e = {\n\ linexpr0 = Linexpr0.copy e.linexpr0;\n\ env = e.env;\n\ }\n\ let get_cst expr =\n\ Linexpr0.get_cst expr.linexpr0\n\ let get_linexpr0 expr = expr.linexpr0\n\ let get_env expr = expr.env\n\ let set_cst expr cst =\n\ Linexpr0.set_cst expr.linexpr0 cst\n\ let set_list expr list ocst = \n\ List.iter\n\ (fun (coeff,var) -> set_coeff expr var coeff )\n\ list;\n\ begin match ocst with\n\ | Some cst -> set_cst expr cst\n\ | None -> ()\n\ end;\n\ ()\n\ let set_array expr tab ocst = \n\ Array.iter\n\ (fun (coeff,var) -> set_coeff expr var coeff )\n\ tab;\n\ begin match ocst with\n\ | Some cst -> set_cst expr cst\n\ | None -> ()\n\ end;\n\ ()\n\ \n\ let iter f expr =\n\ Linexpr0.iter\n\ (begin fun coeff dim ->\n\ f coeff (Environment.var_of_dim expr.env dim)\n\ end)\n\ expr.linexpr0\n\ let print fmt expr =\n\ Linexpr0.print\n\ (fun dim -> Var.to_string (Environment.var_of_dim expr.env dim))\n\ fmt expr.linexpr0\n \ ") apron-dist-0.9.10/apron/mlapronidl/linexpr1_caml.c0000640014525101416610000002240711252216516021735 0ustar bjeannetpopart/* File generated from linexpr1.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include #include "ap_linexpr1.h" #include "apron_caml.h" extern void camlidl_apron_scalar_ml2c(value, ap_scalar_t *); #define camlidl_ml2c_scalar_ap_scalar_t(v,c,ctx) camlidl_apron_scalar_ml2c(v,c) extern value camlidl_apron_scalar_c2ml(ap_scalar_t *); #define camlidl_c2ml_scalar_ap_scalar_t(c,ctx) camlidl_apron_scalar_c2ml(c) extern void camlidl_ml2c_scalar_ap_scalar_ptr(value, ap_scalar_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_ap_scalar_ptr(ap_scalar_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_scalar_struct_ap_scalar_array_t(value, struct ap_scalar_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_struct_ap_scalar_array_t(struct ap_scalar_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_t(value, struct ap_interval_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_t(struct ap_interval_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_ap_interval_ptr(value, ap_interval_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_ap_interval_ptr(ap_interval_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_array_t(value, struct ap_interval_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_array_t(struct ap_interval_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_coeff_struct_ap_coeff_t(value, struct ap_coeff_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_coeff_struct_ap_coeff_t(struct ap_coeff_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_ap_dim_t(value, ap_dim_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_ap_dim_t(ap_dim_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimchange_t(value, struct ap_dimchange_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange_t(struct ap_dimchange_t *, camlidl_ctx _ctx); extern void camlidl_apron_dimchange_ml2c(value, ap_dimchange_t *); #define camlidl_ml2c_dim_ap_dimchange_t(v,c,ctx) camlidl_apron_dimchange_ml2c(v,c) extern value camlidl_apron_dimchange_c2ml(ap_dimchange_t *); #define camlidl_c2ml_dim_ap_dimchange_t(c,ctx) camlidl_apron_dimchange_c2ml(c) extern void camlidl_ml2c_dim_struct_ap_dimchange2_t(value, struct ap_dimchange2_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange2_t(struct ap_dimchange2_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimperm_t(value, struct ap_dimperm_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimperm_t(struct ap_dimperm_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimension_t(value, struct ap_dimension_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimension_t(struct ap_dimension_t *, camlidl_ctx _ctx); extern void camlidl_apron_linexpr0_ptr_ml2c(value, ap_linexpr0_ptr *); #define camlidl_ml2c_linexpr0_ap_linexpr0_ptr(v,c,ctx) camlidl_apron_linexpr0_ptr_ml2c(v,c) extern value camlidl_apron_linexpr0_ptr_c2ml(ap_linexpr0_ptr *); #define camlidl_c2ml_linexpr0_ap_linexpr0_ptr(c,ctx) camlidl_apron_linexpr0_ptr_c2ml(c) extern void camlidl_apron_var_ptr_ml2c(value, ap_var_t *); #define camlidl_ml2c_var_ap_var_t(v,c,ctx) camlidl_apron_var_ptr_ml2c(v,c) extern value camlidl_apron_var_ptr_c2ml(ap_var_t *); #define camlidl_c2ml_var_ap_var_t(c,ctx) camlidl_apron_var_ptr_c2ml(c) extern int camlidl_ml2c_environment_enum_typvar(value); extern value camlidl_c2ml_environment_enum_typvar(int); extern int camlidl_transl_table_environment_enum_typvar[]; extern void camlidl_apron_environment_ptr_ml2c(value, ap_environment_ptr *); #define camlidl_ml2c_environment_ap_environment_ptr(v,c,ctx) camlidl_apron_environment_ptr_ml2c(v,c) extern value camlidl_apron_environment_ptr_c2ml(ap_environment_ptr *); #define camlidl_c2ml_environment_ap_environment_ptr(c,ctx) camlidl_apron_environment_ptr_c2ml(c) void camlidl_ml2c_linexpr1_struct_ap_linexpr1_t(value _v1, struct ap_linexpr1_t * _c2, camlidl_ctx _ctx) { value _v3; value _v4; _v3 = Field(_v1, 0); camlidl_ml2c_linexpr0_ap_linexpr0_ptr(_v3, &(*_c2).linexpr0, _ctx); _v4 = Field(_v1, 1); camlidl_ml2c_environment_ap_environment_ptr(_v4, &(*_c2).env, _ctx); } value camlidl_c2ml_linexpr1_struct_ap_linexpr1_t(struct ap_linexpr1_t * _c1, camlidl_ctx _ctx) { value _v2; value _v3[2]; _v3[0] = _v3[1] = 0; Begin_roots_block(_v3, 2) _v3[0] = camlidl_c2ml_linexpr0_ap_linexpr0_ptr(&(*_c1).linexpr0, _ctx); _v3[1] = camlidl_c2ml_environment_ap_environment_ptr(&(*_c1).env, _ctx); _v2 = camlidl_alloc_small(2, 0); Field(_v2, 0) = _v3[0]; Field(_v2, 1) = _v3[1]; End_roots() return _v2; } value camlidl_linexpr1_ap_linexpr1_get_coeff( value _v_a, value _v_var) { struct ap_linexpr1_t *a; /*in*/ ap_var_t var; /*in*/ struct ap_coeff_t _res; struct ap_linexpr1_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; a = &_c1; camlidl_ml2c_linexpr1_struct_ap_linexpr1_t(_v_a, &_c1, _ctx); camlidl_ml2c_var_ap_var_t(_v_var, &var, _ctx); /* begin user-supplied calling sequence */ { bool b; ap_coeff_init(&_res,AP_COEFF_SCALAR); b = ap_linexpr1_get_coeff(&_res,a,var); if (b){ char str[160]; char* name; ap_coeff_clear(&_res); name = ap_var_operations->to_string(var); snprintf(str,159,"Linexpr1.get_coeff: unknown variable %s in the environment",name); free(name); caml_failwith(str); } } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_coeff_struct_ap_coeff_t(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_linexpr1_ap_linexpr1_set_coeff( value _v_a, value _v_var, value _v_coeff) { struct ap_linexpr1_t *a; /*in*/ ap_var_t var; /*in*/ struct ap_coeff_t *coeff; /*in*/ struct ap_linexpr1_t _c1; struct ap_coeff_t _c2; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; a = &_c1; camlidl_ml2c_linexpr1_struct_ap_linexpr1_t(_v_a, &_c1, _ctx); camlidl_ml2c_var_ap_var_t(_v_var, &var, _ctx); coeff = &_c2; camlidl_ml2c_coeff_struct_ap_coeff_t(_v_coeff, &_c2, _ctx); /* begin user-supplied calling sequence */ { bool b; b = ap_linexpr1_set_coeff(a,var,coeff); if (b){ char str[160]; char* name; name = ap_var_operations->to_string(var); snprintf(str,159,"Linexpr1.set_coeff: unknown variable %s in the environment",name); free(name); caml_failwith(str); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_linexpr1_ap_linexpr1_extend_environment( value _v_linexpr, value _v_env) { struct ap_linexpr1_t linexpr; /*in*/ ap_environment_ptr env; /*in*/ struct ap_linexpr1_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_linexpr1_struct_ap_linexpr1_t(_v_linexpr, &linexpr, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); /* begin user-supplied calling sequence */ { bool b; b = ap_linexpr1_extend_environment(&_res,&linexpr,env); if (b) caml_failwith("Linexpr1.extend_environment: new environment is not a superenvironment"); } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_linexpr1_struct_ap_linexpr1_t(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_linexpr1_ap_linexpr1_extend_environment_with( value _v_linexpr, value _v_env) { struct ap_linexpr1_t linexpr; /*in*/ ap_environment_ptr env; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_linexpr1_struct_ap_linexpr1_t(_v_linexpr, &linexpr, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); /* begin user-supplied calling sequence */ { if (linexpr.env!=env){ bool b; ap_environment_copy(linexpr.env); /* to protect it */ b = ap_linexpr1_extend_environment_with(&linexpr,env); if (b){ ap_environment_free(linexpr.env); caml_failwith("Linexpr1.extend_environment_with: new environment is not a superenvironment"); } Store_field(_v_linexpr,1,_v_env); ap_environment_free(env); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_linexpr1_ap_linexpr1_is_integer( value _v_e) { struct ap_linexpr1_t *e; /*in*/ int _res; struct ap_linexpr1_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; e = &_c1; camlidl_ml2c_linexpr1_struct_ap_linexpr1_t(_v_e, &_c1, _ctx); _res = ap_linexpr1_is_integer(e); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_linexpr1_ap_linexpr1_is_real( value _v_e) { struct ap_linexpr1_t *e; /*in*/ int _res; struct ap_linexpr1_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; e = &_c1; camlidl_ml2c_linexpr1_struct_ap_linexpr1_t(_v_e, &_c1, _ctx); _res = ap_linexpr1_is_real(e); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } apron-dist-0.9.10/apron/mlapronidl/abstract1.idl0000640014525101416610000010067611247457151021424 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \n\ #include \"ap_expr0.h\"\n\ #include \"ap_abstract0.h\"\n\ #include \"ap_environment.h\"\n\ #include \"ap_expr1.h\"\n\ #include \"ap_abstract1.h\"\n\ #include \"caml/callback.h\"\n\ #include \"apron_caml.h\"\n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; import "linexpr0.idl"; import "lincons0.idl"; import "generator0.idl"; import "manager.idl"; import "abstract0.idl"; import "environment.idl"; import "linexpr1.idl"; import "lincons1.idl"; import "generator1.idl"; import "texpr1.idl"; import "tcons1.idl"; struct ap_abstract1_t { [mlname(mutable_abstract0)] ap_abstract0_ptr abstract0; [mlname(mutable_env)] ap_environment_ptr env; }; quote(MLMLI,"(** APRON Abstract values of level 1 *)") quote(MLMLI,"(** The type parameter ['a] allows to distinguish abstract values with different underlying abstract domains. *)\n") quote(MLMLI,"type box1 = { mutable interval_array : Interval.t array; mutable box1_env : Environment.t }") quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(** {2 General management} *)") quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Memory} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n\ (** Copy a value *) val copy : 'a Manager.t -> 'a t -> 'a t\n\ \n\ (** Return the abstract size of a value *) val size : 'a Manager.t -> 'a t -> int\n\ ") quote(ML,"\n\ let copy man x = { abstract0 = Abstract0.copy man x.abstract0; env = x.env }\n\ let size man x = Abstract0.size man x.abstract0\n\ ") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Control of internal representation} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n\ (** Minimize the size of the representation of the value. This may result in a later recomputation of internal information.*) val minimize : 'a Manager.t -> 'a t -> unit\n\ \n\ (** Put the abstract value in canonical form. (not yet clear definition) *) val canonicalize : 'a Manager.t -> 'a t -> unit\n\ \n\ val hash : 'a Manager.t -> 'a t -> int\n\ \n\ (** [approximate man abs alg] perform some transformation on the abstract value, guided by the argument [alg]. The transformation may lose information. The argument [alg] overrides the field algorithm of the structure of type [Manager.funopt] associated to ap_abstract0_approximate (commodity feature).*) val approximate : 'a Manager.t -> 'a t -> int -> unit\n\ \n\ ") quote(ML,"\n\ let minimize man x = Abstract0.minimize man x.abstract0\n\ let canonicalize man x = Abstract0.canonicalize man x.abstract0\n\ let hash man x = 5*(Environment.hash x.env) + Abstract0.hash man x.abstract0\n\ let approximate man x n = Abstract0.approximate man x.abstract0 n\n\ ") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Printing} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n(** Dump on the [stdout] C stream the internal representation of an abstract value, for debugging purposes *)") void ap_abstract1_fdump(ap_manager_ptr man, [ref]struct ap_abstract1_t* a) quote(call,"ap_abstract1_fdump(stdout,man, a); fflush(stdout);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Print as a set of constraints *)") quote(MLI,"val print: Format.formatter -> 'a t -> unit") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Serialization} *)") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(** {2 Constructor, accessors, tests and property extraction} *)") quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Basic constructors} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** All these functions request explicitly an environment in their arguments. *)\n") quote(MLI,"\n(** Create a bottom (empty) value defined on the given environment *)") struct ap_abstract1_t ap_abstract1_bottom(ap_manager_ptr man, ap_environment_ptr env) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Create a top (universe) value defined on the given environment *)") struct ap_abstract1_t ap_abstract1_top(ap_manager_ptr man, ap_environment_ptr env) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Abstract an hypercube.\n\n[of_box man env tvar tinterval] abstracts an hypercube defined by the arrays [tvar] and [tinterval]. The result is defined on the environment [env], which should contain all the variables in [tvar] (and defines their type) *)") struct ap_abstract1_t ap_abstract1_of_box(ap_manager_ptr man, ap_environment_ptr env, [size_is(size)]ap_var_t* tvar, [size_is(size2)]ap_interval_ptr* tinterval, unsigned int size, unsigned int size2) quote(call,"\n\ if (size!=size2)\n\ caml_failwith(\"Abstract1.of_box: the two arrays are of different sizes\");\n\ _res = ap_abstract1_of_box(man,env,tvar,tinterval,size);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Accessors} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n\ val manager : 'a t -> 'a Manager.t\n\ val env : 'a t -> Environment.t\n\ val abstract0 : 'a t -> 'a Abstract0.t\n\ (** Return resp. the underlying manager, environment and abstract value of level 0 *)\n\ ") quote(ML,"\n\ let manager x = Abstract0.manager x.abstract0\n\ let env x = x.env\n\ let abstract0 x = x.abstract0\n\ ") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Tests} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n\ (** Emptiness test *) val is_bottom : 'a Manager.t -> 'a t -> bool\n\ \n\ (** Universality test *) val is_top : 'a Manager.t -> 'a t -> bool\n\ ") quote(ML,"\n\ let is_bottom man x = Abstract0.is_bottom man x.abstract0\n\ let is_top man x = Abstract0.is_top man x.abstract0\n\ ") quote(MLI,"\n(** Inclusion test. The 2 abstract values should be compatible. *)") boolean ap_abstract1_is_leq(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Equality test. The 2 abstract values should be compatible. *)") boolean ap_abstract1_is_eq(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Does the abstract value satisfy the linear constraint ? *)") boolean ap_abstract1_sat_lincons(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_lincons1_t* v) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Does the abstract value satisfy the tree expression constraint ? *)") boolean ap_abstract1_sat_tcons(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_tcons1_t* v) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Does the abstract value satisfy the constraint [dim in interval] ? *)") boolean ap_abstract1_sat_interval(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, ap_var_t v1, [ref]struct ap_interval_t* v2) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** Is the variable unconstrained in the abstract value ? If yes, this means that the existential quantification of the dimension does not change the value. *)") boolean ap_abstract1_is_variable_unconstrained(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, ap_var_t v) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Extraction of properties} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n(** Return the interval of variation of the variable in the abstract value. *)") [ref]struct ap_interval_t* ap_abstract1_bound_variable(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, ap_var_t v) quote(dealloc,"ap_interval_free(_res); I0_CHECK_EXC(man)"); quote(MLI,"\n(** Return the interval of variation of the linear expression in the abstract value. \n\nImplement a form of linear programming, where the argument linear expression is the one to optimize under the constraints induced by the abstract value. *)") [ref]struct ap_interval_t* ap_abstract1_bound_linexpr(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_linexpr1_t* v) quote(dealloc,"ap_interval_free(_res); I0_CHECK_EXC(man)"); quote(MLI,"\n(** Return the interval of variation of the tree expression in the abstract value. *)") [ref]struct ap_interval_t* ap_abstract1_bound_texpr(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_texpr1_t* v) quote(dealloc,"ap_interval_free(_res); I0_CHECK_EXC(man)"); quote(MLI,"\n\ (** Convert the abstract value to an hypercube *) val to_box : 'a Manager.t -> 'a t -> box1\n\ \n\ (** Convert the abstract value to a conjunction of linear constraints. *) val to_lincons_array : 'a Manager.t -> 'a t -> Lincons1.earray\n\ (** Convert the abstract value to a conjunction of tree expressions constraints. *) val to_tcons_array : 'a Manager.t -> 'a t -> Tcons1.earray\n\ \n\ (** Convert the abstract value to a set of generators that defines it. *) val to_generator_array : 'a Manager.t -> 'a t -> Generator1.earray\n\ \n\ ") quote(ML,"\n\ let to_lincons_array man x = {\n\ Lincons1.lincons0_array = Abstract0.to_lincons_array man x.abstract0;\n\ Lincons1.array_env = x.env\n\ }\n\ let to_tcons_array man x = {\n\ Tcons1.tcons0_array = Abstract0.to_tcons_array man x.abstract0;\n\ Tcons1.array_env = x.env\n\ }\n\ let to_generator_array man x = {\n\ Generator1.generator0_array = Abstract0.to_generator_array man x.abstract0;\n\ Generator1.array_env = x.env\n\ }\n\ let to_box man x = {\n\ interval_array = Abstract0.to_box man x.abstract0;\n\ box1_env = x.env\n\ }\n\ ") quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(** {2 Operations} *)") quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Meet and Join} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** Meet of 2 abstract values. *)") struct ap_abstract1_t ap_abstract1_meet(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2) quote(call,"_res = ap_abstract1_meet(man,false,a1,a2);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Meet of a non empty array of abstract values. *)") struct ap_abstract1_t ap_abstract1_meet_array(ap_manager_ptr man, [size_is(size)]struct ap_abstract1_t* array, unsigned int size) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Meet of an abstract value with an array of linear constraints. *)") struct ap_abstract1_t ap_abstract1_meet_lincons_array(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_lincons1_array_t* v) quote(call,"_res = ap_abstract1_meet_lincons_array(man,false,a,v);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Meet of an abstract value with an array of tree expressions constraints. *)") struct ap_abstract1_t ap_abstract1_meet_tcons_array(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_tcons1_array_t* v) quote(call,"_res = ap_abstract1_meet_tcons_array(man,false,a,v);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Join of 2 abstract values. *)") struct ap_abstract1_t ap_abstract1_join(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2) quote(call,"_res = ap_abstract1_join(man,false,a1,a2);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Join of a non empty array of abstract values. *)") struct ap_abstract1_t ap_abstract1_join_array(ap_manager_ptr man, [size_is(size)]struct ap_abstract1_t* array, unsigned int size) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Add the array of generators to the abstract value (time elapse operator).\n\n The generators should either lines or rays, not vertices. *)") struct ap_abstract1_t ap_abstract1_add_ray_array(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_generator1_array_t* v) quote(call,"_res = ap_abstract1_add_ray_array(man,false,a,v);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** {5 Side-effect versions of the previous functions} *)\n") void ap_abstract1_meet_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2) quote(call,"{\n\ ap_abstract1_t res = ap_abstract1_meet(man,true,a1,a2);\n\ value v = Field(_v_a1,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_meet_lincons_array_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_lincons1_array_t* v) quote(call,"{\n\ ap_abstract1_t res = ap_abstract1_meet_lincons_array(man,true,a,v);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_meet_tcons_array_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_tcons1_array_t* v) quote(call,"{\n\ ap_abstract1_t res = ap_abstract1_meet_tcons_array(man,true,a,v);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_join_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2) quote(call,"{\n\ ap_abstract1_t res = ap_abstract1_join(man,true,a1,a2);\n\ value v = Field(_v_a1,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_add_ray_array_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [ref]struct ap_generator1_array_t* v) quote(call,"{\n\ ap_abstract1_t res = ap_abstract1_add_ray_array(man,true,a,v);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Assignement and Substitutions} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** Parallel assignement of an array of dimensions by an array of same size of linear expressions *)") struct ap_abstract1_t ap_abstract1_assign_linexpr_array(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]struct ap_linexpr1_t* v2, int v3,int v4, struct ap_abstract1_t* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.assign_linexpr_array: arrays of different size\");\n\ _res = ap_abstract1_assign_linexpr_array(man,false,a,v1,v2,v3,dest);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Parallel substitution of an array of dimensions by an array of same size of linear expressions *)") struct ap_abstract1_t ap_abstract1_substitute_linexpr_array(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]struct ap_linexpr1_t* v2, int v3, int v4, struct ap_abstract1_t* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.substitute_linexpr_array: arrays of different size\");\n\ _res = ap_abstract1_substitute_linexpr_array(man,false,a,v1,v2,v3,dest);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Parallel assignement of an array of dimensions by an array of same size of tree expressions *)") struct ap_abstract1_t ap_abstract1_assign_texpr_array(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]struct ap_texpr1_t* v2, int v3,int v4, struct ap_abstract1_t* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.assign_texpr_array: arrays of different size\");\n\ _res = ap_abstract1_assign_texpr_array(man,false,a,v1,v2,v3,dest);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Parallel substitution of an array of dimensions by an array of same size of tree expressions *)") struct ap_abstract1_t ap_abstract1_substitute_texpr_array(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]struct ap_texpr1_t* v2, int v3, int v4, struct ap_abstract1_t* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.substitute_texpr_array: arrays of different size\");\n\ _res = ap_abstract1_substitute_texpr_array(man,false,a,v1,v2,v3,dest);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"\n(** {5 Side-effect versions of the previous functions} *)\n") void ap_abstract1_assign_linexpr_array_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]struct ap_linexpr1_t* v2, int v3,int v4, struct ap_abstract1_t* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.assign_linexpr_array_with: arrays of different size\");\n\ {\n\ ap_abstract1_t res = ap_abstract1_assign_linexpr_array(man,true,a,v1,v2,v3,dest);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_substitute_linexpr_array_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]struct ap_linexpr1_t* v2, int v3, int v4, struct ap_abstract1_t* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.substitute_linexpr_array_with: arrays of different size\");\n\ {\n\ ap_abstract1_t res = ap_abstract1_substitute_linexpr_array(man,true,a,v1,v2,v3,dest);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_assign_texpr_array_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]struct ap_texpr1_t* v2, int v3, int v4, struct ap_abstract1_t* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.assign_texpr_array_with: arrays of different size\");\n\ {\n\ ap_abstract1_t res = ap_abstract1_assign_texpr_array(man,true,a,v1,v2,v3,dest);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_substitute_texpr_array_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]struct ap_texpr1_t* v2, int v3, int v4, struct ap_abstract1_t* dest) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.substitute_texpr_array_with: arrays of different size\");\n\ {\n\ ap_abstract1_t res = ap_abstract1_substitute_texpr_array(man,true,a,v1,v2,v3,dest);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Projections} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** These functions implements forgeting (existential quantification) of (array of) variables. Both functional and side-effect versions are provided. The Boolean, if true, adds a projection onto 0-plane. *)\n\n") struct ap_abstract1_t ap_abstract1_forget_array(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v2)]ap_var_t* v1, unsigned int v2, boolean v3) quote(call,"_res = ap_abstract1_forget_array(man,false,a,v1,v2,v3);") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_forget_array_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v2)]ap_var_t* v1, int v2, boolean v3) quote(call,"{\n\ ap_abstract1_t res = ap_abstract1_forget_array(man,true,a,v1,v2,v3); value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Change and permutation of dimensions} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** Change the environement of the abstract values.\n\nVariables that are removed are first existentially quantified, and variables that are introduced are unconstrained. The Boolean, if true, adds a projection onto 0-plane for these ones. *)") struct ap_abstract1_t ap_abstract1_change_environment(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, ap_environment_ptr v1, boolean v2) quote(call,"_res = ap_abstract1_change_environment(man,false,a,v1,v2);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Remove from the environment of the abstract value and from the abstract value itself variables that are unconstrained in it. *)") struct ap_abstract1_t ap_abstract1_minimize_environment(ap_manager_ptr man, [ref]struct ap_abstract1_t* a) quote(call,"_res = ap_abstract1_minimize_environment(man,false,a);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Parallel renaming of the environment of the abstract value.\n\nThe new variables should not interfere with the variables that are not renamed. *)") struct ap_abstract1_t ap_abstract1_rename_array(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]ap_var_t* v2, unsigned int v3, unsigned int v4) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.rename_array: arrays of different size\");\n\ _res = ap_abstract1_rename_array(man,false,a,v1,v2,v3);\n\ ") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_change_environment_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, ap_environment_ptr v1, boolean v2) quote(call,"\ {\n\ ap_environment_t* oldenv = ap_environment_copy(a->env);\n \ ap_abstract1_t res = ap_abstract1_change_environment(man,true,a,v1,v2);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ if (res.env==oldenv){\n\ ap_environment_free(oldenv);\n\ }\n\ else {\n\ assert(res.env==v1);\n\ Store_field(_v_a,1,_v_v1);\n\ }\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_minimize_environment_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a) quote(call,"{\n\ ap_environment_t* oldenv = ap_environment_copy(a->env);\n \ ap_abstract1_t res = ap_abstract1_minimize_environment(man,true,a);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ if (res.env==oldenv){\n\ ap_environment_free(oldenv);\n\ }\n\ else {\n\ v = camlidl_apron_environment_ptr_c2ml(&res.env); \n\ Store_field(_v_a,1,v); \n\ }\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_rename_array_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v3)]ap_var_t* v1, [size_is(v4)]ap_var_t* v2, unsigned int v3, unsigned int v4) quote(call,"\n\ if (v3!=v4) caml_failwith(\"Abstract1.rename_array_with: arrays of different size\");\n\ {\n\ ap_environment_t* oldenv = ap_environment_copy(a->env);\n \ ap_abstract1_t res = ap_abstract1_rename_array(man,true,a,v1,v2,v3);\n\ value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ if (res.env==oldenv){\n\ ap_environment_free(oldenv);\n\ }\n\ else {\n\ v = camlidl_apron_environment_ptr_c2ml(&res.env); \n\ Store_field(_v_a,1,v); \n\ }\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Expansion and folding of dimensions} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"\n\ (**\n\ These functions allows to expand one dimension into several ones having the\n\ same properties with respect to the other dimensions, and to fold several\n\ dimensions into one. Formally,\n\ \n\ - expand P(x,y,z) z w = P(x,y,z) inter P(x,y,w) if z is expanded in z and w\n\ - fold Q(x,y,z,w) z w = exists w:Q(x,y,z,w) union (exist z:Q(x,y,z,w))(z<-w)\n\ if z and w are folded onto z\n\ *)\n\n\ ") quote(MLI,"(** \ Expansion: [expand a var tvar] expands the variable [var] into itself and\n \ the additional variables in [tvar], which are given the same type as [var].\n\n\ It results in (n+1) unrelated variables having\n \ same relations with other variables. The additional variables are added to the environment of \n\ the argument for making the environment of the result, so they should\n\ not belong to the initial environement.\n\ *)") struct ap_abstract1_t ap_abstract1_expand(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, ap_var_t v1, [size_is(v3)]ap_var_t* v2, int v3) quote(call,"_res = ap_abstract1_expand(man,false,a,v1,v2,v3);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI," \ (** Folding: [fold a tvar] fold the variables in the array [tvar] of size n>=1\n\ and put the result in the first variable of the array. The other\n\ variables of the array are then removed, both from the environment and the abstract value.\n\ *)") struct ap_abstract1_t ap_abstract1_fold(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v2)]ap_var_t* v1, int v2) quote(call,"_res = ap_abstract1_fold(man,false,a,v1,v2);") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_expand_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, ap_var_t v1, [size_is(v3)]ap_var_t* v2, int v3) quote(call,"{\n\ ap_environment_t* oldenv = ap_environment_copy(a->env);\n \ ap_abstract1_t res = ap_abstract1_expand(man,true,a,v1,v2,v3); value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ if (res.env==oldenv){\n\ ap_environment_free(oldenv);\n\ }\n\ else {\n\ v = camlidl_apron_environment_ptr_c2ml(&res.env); \n\ Store_field(_v_a,1,v); \n\ }\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); void ap_abstract1_fold_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a, [size_is(v2)]ap_var_t* v1, int v2) quote(call,"{\n\ ap_environment_t* oldenv = ap_environment_copy(a->env);\n \ ap_abstract1_t res = ap_abstract1_fold(man,true,a,v1,v2); value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ if (res.env==oldenv){\n\ ap_environment_free(oldenv);\n\ }\n\ else {\n\ v = camlidl_apron_environment_ptr_c2ml(&res.env); \n\ Store_field(_v_a,1,v); \n\ }\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Widening} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** Widening *)") struct ap_abstract1_t ap_abstract1_widening(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2) quote(dealloc,"I0_CHECK_EXC(man)"); struct ap_abstract1_t ap_abstract1_widening_threshold(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2, [ref]struct ap_lincons1_array_t* v) quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ============================================================ *)") quote(MLMLI,"(** {3 Closure operation} *)\n") quote(MLMLI,"(* ============================================================ *)") quote(MLI,"(** Closure: transform strict constraints into non-strict ones.*)") struct ap_abstract1_t ap_abstract1_closure(ap_manager_ptr man,[ref]struct ap_abstract1_t* a) quote(call,"_res = ap_abstract1_closure(man,false,a);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Side-effect version *)") void ap_abstract1_closure_with(ap_manager_ptr man,[ref]struct ap_abstract1_t* a) quote(call,"{\n\ ap_abstract1_t res = ap_abstract1_closure(man,true,a); value v = Field(_v_a,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLMLI,"(* ********************************************************************** *)") quote(MLMLI,"(** {2 Additional operations} *)") quote(MLMLI,"(* ********************************************************************** *)") quote(MLI,"\n\ val of_lincons_array : 'a Manager.t -> Environment.t -> Lincons1.earray -> 'a t\n\ val of_tcons_array : 'a Manager.t -> Environment.t -> Tcons1.earray -> 'a t\n\ (** Abstract a conjunction of constraints *)\n\ \n\ val assign_linexpr : 'a Manager.t -> 'a t -> Var.t -> Linexpr1.t -> 'a t option -> 'a t\n\ val substitute_linexpr : 'a Manager.t -> 'a t -> Var.t -> Linexpr1.t -> 'a t option -> 'a t\n\ val assign_texpr : 'a Manager.t -> 'a t -> Var.t -> Texpr1.t -> 'a t option -> 'a t\n\ val substitute_texpr : 'a Manager.t -> 'a t -> Var.t -> Texpr1.t -> 'a t option -> 'a t\n\ (** Assignement/Substitution of a single dimension by a single expression *)\n\ \n\ val assign_linexpr_with : 'a Manager.t -> 'a t -> Var.t -> Linexpr1.t -> 'a t option -> unit\n\ val substitute_linexpr_with : 'a Manager.t -> 'a t -> Var.t -> Linexpr1.t -> 'a t option -> unit\n\ val assign_texpr_with : 'a Manager.t -> 'a t -> Var.t -> Texpr1.t -> 'a t option -> unit\n\ val substitute_texpr_with : 'a Manager.t -> 'a t -> Var.t -> Texpr1.t -> 'a t option -> unit\n\ (** Side-effect version of the previous functions *)\n\ \n\ ") quote(ML,"\n\ let of_lincons_array man env array =\n\ let res = top man env in\n\ meet_lincons_array_with man res array;\n\ res\n\ let of_tcons_array man env array =\n\ let res = top man env in\n\ meet_tcons_array_with man res array;\n\ res\n\ let assign_linexpr man abs dim expr odest =\n\ assign_linexpr_array man abs [|dim|] [|expr|] odest\n\ let assign_texpr man abs dim expr odest =\n\ assign_texpr_array man abs [|dim|] [|expr|] odest\n\ let substitute_linexpr man abs dim expr odest =\n\ substitute_linexpr_array man abs [|dim|] [|expr|] odest\n\ let substitute_texpr man abs dim expr odest =\n\ substitute_texpr_array man abs [|dim|] [|expr|] odest\n\ let assign_linexpr_with man abs dim expr odest =\n\ assign_linexpr_array_with man abs [|dim|] [|expr|] odest\n\ let assign_texpr_with man abs dim expr odest =\n\ assign_texpr_array_with man abs [|dim|] [|expr|] odest\n\ let substitute_linexpr_with man abs dim expr odest =\n\ substitute_linexpr_array_with man abs [|dim|] [|expr|] odest\n\ let substitute_texpr_with man abs dim expr odest =\n\ substitute_texpr_array_with man abs [|dim|] [|expr|] odest\n\ ") quote(MLI,"(** Unification of 2 abstract values on their least common environment *)") struct ap_abstract1_t ap_abstract1_unify(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2) quote(call,"_res = ap_abstract1_unify(man,false,a1,a2);") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** Side-effect version *)") void ap_abstract1_unify_with(ap_manager_ptr man, [ref]struct ap_abstract1_t* a1, [ref]struct ap_abstract1_t* a2) quote(call,"\ {\n\ ap_abstract1_t res = ap_abstract1_unify(man,true,a1,a2);\n\ value v = Field(_v_a1,0);\n\ *((ap_abstract0_ptr *) Data_custom_val(v)) = res.abstract0;\n\ v = Field(_v_a1,1);\n\ *((ap_environment_ptr *) Data_custom_val(v)) = res.env;\n\ }") quote(dealloc,"I0_CHECK_EXC(man)"); quote(ML,"\n\ let print fmt a =\n\ let man = manager a in\n\ if is_bottom man a then\n\ Format.pp_print_string fmt \"bottom\"\n\ else if is_top man a then\n\ Format.pp_print_string fmt \"top\"\n\ else begin\n\ let tab = to_lincons_array man a in\n\ Lincons1.array_print fmt tab;\n\ end\n\ ") apron-dist-0.9.10/apron/mlapronidl/lincons1.idl0000640014525101416610000002460510654126013021252 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \n\ #include \"ap_lincons1.h\"\n\ #include \"apron_caml.h\"\n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; import "linexpr0.idl"; import "lincons0.idl"; import "environment.idl"; import "linexpr1.idl"; struct ap_lincons1_t { [mlname(mutable_lincons0)] ap_lincons0_t lincons0; [mlname(mutable_env)] ap_environment_ptr env; }; struct ap_lincons1_array_t { [mlname(mutable_lincons0_array)] struct ap_lincons0_array_t lincons0_array; [mlname(mutable_array_env)] ap_environment_ptr env; }; quote(MLMLI,"(** APRON Constraints and array of constraints of level 1 *)") quote(MLMLI,"\n\ type typ = Lincons0.typ =\n\ | EQ\n\ | SUPEQ\n\ | SUP\n\ | DISEQ\n\ | EQMOD of Scalar.t\n\ ") quote(MLI,"\n\ (** Make a linear constraint. Modifying later the linear expression ({e not\n\ advisable}) modifies correspondingly the linear constraint and conversely,\n\ except for changes of environements *)\n\ val make: Linexpr1.t -> typ -> t\n\ \n\ (** Copy (deep copy) *)\n\ val copy: t -> t\n\ \n\ (** Convert a constraint type to a string ([=],[>=], or [>]) *)\n\ val string_of_typ : typ -> string\n\ \n\ (** Print the linear constraint *)\n\ val print : Format.formatter -> t -> unit\n\ \n\ (** Get the constraint type *)\n\ val get_typ: t -> typ\n\ \n\ (** Iter the function on the pair coefficient/variable of the underlying linear\n\ expression *)\n\ val iter: (Coeff.t -> Var.t -> unit) -> t -> unit\n\ \n\ (** Get the constant of the underlying linear expression *)\n\ val get_cst: t -> Coeff.t\n\ \n\ (** Set the constraint type *)\n\ val set_typ: t -> typ -> unit\n\ \n\ (** Set simultaneously a number of coefficients.\n\ \n\ [set_list expr [(c1,\"x\"); (c2,\"y\")] (Some cst)] assigns coefficients [c1] \n\ to variable [\"x\"], coefficient [c2] to variable [\"y\"], and coefficient [cst]\n\ to the constant. If [(Some cst)] is replaced by [None],\n\ the constant coefficient is not assigned. *)\n\ val set_list : t -> (Coeff.t * Var.t) list -> Coeff.t option -> unit\n\ \n\ (** Set simultaneously a number of coefficients, as [set_list]. *)\n\ val set_array : t -> (Coeff.t * Var.t) array -> Coeff.t option -> unit\n\ \n\ (** Set the constant of the underlying linear expression *)\n\ val set_cst: t -> Coeff.t -> unit\n\ ") quote(MLI,"(** Get the coefficient of the variable in the underlying linear expression *)") struct ap_coeff_t ap_lincons1_get_coeff([ref]struct ap_lincons1_t* a, ap_var_t var) quote(call, "\n\ {\n\ bool b;\n\ ap_coeff_init(&_res,AP_COEFF_SCALAR);\n\ b = ap_lincons1_get_coeff(&_res,a,var);\n\ if (b){\n\ char str[160];\n\ char* name;\n\ ap_coeff_clear(&_res);\n\ name = ap_var_operations->to_string(var);\n\ snprintf(str,159,\"Lincons1.get_coeff: unknown variable %s in the environment\",name);\n\ free(name);\n\ caml_failwith(str);\n\ }\n\ }\n\ ") quote(dealloc,"ap_coeff_clear(&_res);"); quote(MLI,"(** Set the coefficient of the variable in the underlying linear expression *)") void ap_lincons1_set_coeff([ref]struct ap_lincons1_t* a, ap_var_t var, [ref]struct ap_coeff_t* coeff) quote(call, "\n\ {\n\ bool b;\n\ b = ap_lincons1_set_coeff(a,var,coeff);\n\ if (b){\n\ char str[160];\n\ char* name;\n\ name = ap_var_operations->to_string(var);\n\ snprintf(str,159,\"Lincons1.set_coeff: unknown variable %s in the environment\",name);\n\ free(name);\n\ caml_failwith(str);\n\ }\n\ }\n\ "); quote(MLI,"(** Build the unsatisfiable constraint -1>=0 *)") struct ap_lincons1_t ap_lincons1_make_unsat(ap_environment_ptr env); quote(MLI,"(** Is the constraint not satisfiable ? *)") boolean ap_lincons1_is_unsat([ref]struct ap_lincons1_t* cons); quote(MLI,"(** Change the environement of the constraint for a super-environement. Raise [Failure] if it is not the case *)") struct ap_lincons1_t ap_lincons1_extend_environment(const struct ap_lincons1_t lincons, ap_environment_ptr env) quote(call,"\n\ {\n\ bool b;\n\ b = ap_lincons1_extend_environment(&_res,&lincons,env);\n\ if (b) caml_failwith(\"Lincons1.extend_environment: new environment is not a superenvironment\");\n\ }") ; quote(MLI,"(** Side-effect version of the previous function *)") void ap_lincons1_extend_environment_with(struct ap_lincons1_t lincons, ap_environment_ptr env) quote(call,"\n\ {\n\ if (lincons.env!=env){ \n\ bool b;\n\ ap_environment_copy(lincons.env); /* to protect it */ \n\ b = ap_lincons1_extend_environment_with(&lincons,env);\n\ if (b){ \n\ ap_environment_free(lincons.env); \n\ caml_failwith(\"Lincons1.extend_environment_with: new environment is not a superenvironment\");\n\ }\n\ Store_field(_v_lincons,1,_v_env);\n\ ap_environment_free(env);\n\ }\n\ }") ; quote(MLI,"\n\ (** Get the environement of the linear constraint *)\n\ val get_env: t -> Environment.t\n\ \n\ (** Get the underlying linear expression. Modifying the linear expression ({e\n\ not advisable}) modifies correspondingly the linear constraint and\n\ conversely, except for changes of environements *)\n\ val get_linexpr1: t -> Linexpr1.t\n\ \n\ (** Get the underlying linear constraint of level 0. Modifying the constraint\n\ of level 0 ({e not advisable}) modifies correspondingly the linear constraint\n\ and conversely, except for changes of environements*)\n\ val get_lincons0: t -> Lincons0.t\n\ \n\ ") quote(ML,"\n\ let make linexpr1 typ = {\n\ lincons0 = {\n\ Lincons0.linexpr0 = linexpr1.Linexpr1.linexpr0;\n\ Lincons0.typ = typ;\n\ };\n\ env = linexpr1.Linexpr1.env;\n\ }\n\ let copy cons = {\n\ lincons0 = Lincons0.copy cons.lincons0;\n\ env = cons.env;\n\ }\n\ let string_of_typ = Lincons0.string_of_typ\n\ \n\ let print fmt cons = \n\ Lincons0.print\n\ (fun dim -> Var.to_string (Environment.var_of_dim cons.env dim)) fmt cons.lincons0;\n \ ()\n\ let get_typ cons = cons.lincons0.Lincons0.typ\n\ let set_typ cons typ = cons.lincons0.Lincons0.typ <- typ\n\ let get_cst cons = Linexpr0.get_cst cons.lincons0.Lincons0.linexpr0\n\ let set_cst cons cst = Linexpr0.set_cst cons.lincons0.Lincons0.linexpr0 cst\n\ let get_lincons0 cons = cons.lincons0\n\ let get_env cons = cons.env\n\ let set_list expr list ocst = \n\ List.iter\n\ (fun (coeff,var) -> set_coeff expr var coeff )\n\ list;\n\ begin match ocst with\n\ | Some cst -> set_cst expr cst\n\ | None -> ()\n\ end;\n\ ()\n\ let set_array expr tab ocst = \n\ Array.iter\n\ (fun (coeff,var) -> set_coeff expr var coeff )\n\ tab;\n\ begin match ocst with\n\ | Some cst -> set_cst expr cst\n\ | None -> ()\n\ end;\n\ ()\n\ \n\ let iter f cons =\n\ Linexpr0.iter\n\ (begin fun coeff dim ->\n\ f coeff (Environment.var_of_dim cons.env dim)\n\ end)\n\ cons.lincons0.Lincons0.linexpr0\n\ let get_linexpr1 cons = {\n\ Linexpr1.linexpr0 = cons.lincons0.Lincons0.linexpr0;\n\ Linexpr1.env = cons.env;\n\ }") quote(MLMLI,"(* ====================================================================== *)") quote(MLMLI,"(** {2 Type array} *)") quote(MLMLI,"(* ====================================================================== *)") quote(MLI,"\n\ (** Make an array of linear constraints with the given size and defined on the\n\ given environement. The elements are initialized with the constraint 0=0. *)\n\ val array_make : Environment.t -> int -> earray\n\ \n\ (** Print an array of constraints *)\n\ val array_print :\n\ ?first:(unit, Format.formatter, unit) format ->\n\ ?sep:(unit, Format.formatter, unit) format ->\n\ ?last:(unit, Format.formatter, unit) format ->\n\ Format.formatter -> earray -> unit\n\ \n\ (** Get the size of the array *)\n\ val array_length : earray -> int\n\ \n\ (** Get the environment of the array *)\n\ val array_get_env : earray -> Environment.t\n\ \n\ (** Get the element of the given index (which is not a copy) *)\n\ val array_get : earray -> int -> t\n\ \n\ (** Set the element of the given index (without any copy). The array and the\n\ constraint should be defined on the same environement; otherwise a [Failure]\n\ exception is raised.*)\n\ val array_set : earray -> int -> t -> unit\n\ ") quote(MLI,"(** Change the environement of the array of constraints for a super-environement. Raise [Failure] if it is not the case*)") struct ap_lincons1_array_t ap_lincons1_array_extend_environment(const struct ap_lincons1_array_t array, ap_environment_ptr env) quote(call,"\n\ {\n\ bool b;\n\ b = ap_lincons1_array_extend_environment(&_res,&array,env);\n\ if (b) caml_failwith(\"Lincons1.array_extend_environment: new environment is not a superenvironment\");\n\ }") ; quote(MLI,"(** Side-effect version of the previous function *)") void ap_lincons1_array_extend_environment_with(struct ap_lincons1_array_t array, ap_environment_ptr env) quote(call,"\n\ {\n\ if (array.env!=env){ \n\ bool b;\n\ ap_environment_copy(array.env); /* to protect it */ \n\ b = ap_lincons1_array_extend_environment_with(&array,env);\n\ if (b){ \n\ ap_environment_free(array.env); \n\ caml_failwith(\"Lincons1.array_extend_environment_with: new environment is not a superenvironment\");\n\ }\n\ Store_field(_v_array,1,_v_env);\n\ ap_environment_free(env);\n\ }\n\ }") ; quote(ML,"\n\ let array_make env size =\n\ let cons = Lincons0.make (Linexpr0.make None) Lincons0.EQ in\n\ {\n\ lincons0_array = Array.make size cons;\n\ array_env = env\n\ }\n\ let array_print\n\ ?(first=(\"[|@[\":(unit,Format.formatter,unit) format))\n\ ?(sep = (\";@ \":(unit,Format.formatter,unit) format))\n\ ?(last = (\"@]|]\":(unit,Format.formatter,unit) format))\n\ fmt array \n\ = \n\ Abstract0.print_array ~first ~sep ~last\n\ (Lincons0.print\n\ (fun dim -> Var.to_string (Environment.var_of_dim array.array_env dim)))\n \ fmt array.lincons0_array;\n\ ()\n\ let array_length array = Array.length (array.lincons0_array)\n\ let array_get_env array = array.array_env\n\ let array_get array index =\n\ let cons0 = array.lincons0_array.(index) in\n\ { lincons0 = cons0; env = array.array_env; }\n\ let array_set array index cons1 =\n\ if not (Environment.equal array.array_env cons1.env) then\n\ failwith \"Lincons1.array_set: environments are not the same\"\n\ else\n\ array.lincons0_array.(index) <- cons1.lincons0;\n\ ") apron-dist-0.9.10/apron/mlapronidl/abstract1.mli0000640014525101416610000004217711252216517021431 0ustar bjeannetpopart(* File generated from abstract1.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type 'a t = { mutable abstract0: 'a Abstract0.t; mutable env: Environment.t; } (** APRON Abstract values of level 1 *) (** The type parameter ['a] allows to distinguish abstract values with different underlying abstract domains. *) type box1 = { mutable interval_array : Interval.t array; mutable box1_env : Environment.t } (* ********************************************************************** *) (** {2 General management} *) (* ********************************************************************** *) (* ============================================================ *) (** {3 Memory} *) (* ============================================================ *) (** Copy a value *) val copy : 'a Manager.t -> 'a t -> 'a t (** Return the abstract size of a value *) val size : 'a Manager.t -> 'a t -> int (* ============================================================ *) (** {3 Control of internal representation} *) (* ============================================================ *) (** Minimize the size of the representation of the value. This may result in a later recomputation of internal information.*) val minimize : 'a Manager.t -> 'a t -> unit (** Put the abstract value in canonical form. (not yet clear definition) *) val canonicalize : 'a Manager.t -> 'a t -> unit val hash : 'a Manager.t -> 'a t -> int (** [approximate man abs alg] perform some transformation on the abstract value, guided by the argument [alg]. The transformation may lose information. The argument [alg] overrides the field algorithm of the structure of type [Manager.funopt] associated to ap_abstract0_approximate (commodity feature).*) val approximate : 'a Manager.t -> 'a t -> int -> unit (* ============================================================ *) (** {3 Printing} *) (* ============================================================ *) (** Dump on the [stdout] C stream the internal representation of an abstract value, for debugging purposes *) external fdump : 'a Manager.t -> 'a t -> unit = "camlidl_abstract1_ap_abstract1_fdump" (** Print as a set of constraints *) val print: Format.formatter -> 'a t -> unit (* ============================================================ *) (** {3 Serialization} *) (* ============================================================ *) (* ********************************************************************** *) (** {2 Constructor, accessors, tests and property extraction} *) (* ********************************************************************** *) (* ============================================================ *) (** {3 Basic constructors} *) (* ============================================================ *) (** All these functions request explicitly an environment in their arguments. *) (** Create a bottom (empty) value defined on the given environment *) external bottom : 'a Manager.t -> Environment.t -> 'a t = "camlidl_abstract1_ap_abstract1_bottom" (** Create a top (universe) value defined on the given environment *) external top : 'a Manager.t -> Environment.t -> 'a t = "camlidl_abstract1_ap_abstract1_top" (** Abstract an hypercube. [of_box man env tvar tinterval] abstracts an hypercube defined by the arrays [tvar] and [tinterval]. The result is defined on the environment [env], which should contain all the variables in [tvar] (and defines their type) *) external of_box : 'a Manager.t -> Environment.t -> Var.t array -> Interval.t array -> 'a t = "camlidl_abstract1_ap_abstract1_of_box" (* ============================================================ *) (** {3 Accessors} *) (* ============================================================ *) val manager : 'a t -> 'a Manager.t val env : 'a t -> Environment.t val abstract0 : 'a t -> 'a Abstract0.t (** Return resp. the underlying manager, environment and abstract value of level 0 *) (* ============================================================ *) (** {3 Tests} *) (* ============================================================ *) (** Emptiness test *) val is_bottom : 'a Manager.t -> 'a t -> bool (** Universality test *) val is_top : 'a Manager.t -> 'a t -> bool (** Inclusion test. The 2 abstract values should be compatible. *) external is_leq : 'a Manager.t -> 'a t -> 'a t -> bool = "camlidl_abstract1_ap_abstract1_is_leq" (** Equality test. The 2 abstract values should be compatible. *) external is_eq : 'a Manager.t -> 'a t -> 'a t -> bool = "camlidl_abstract1_ap_abstract1_is_eq" (** Does the abstract value satisfy the linear constraint ? *) external sat_lincons : 'a Manager.t -> 'a t -> Lincons1.t -> bool = "camlidl_abstract1_ap_abstract1_sat_lincons" (** Does the abstract value satisfy the tree expression constraint ? *) external sat_tcons : 'a Manager.t -> 'a t -> Tcons1.t -> bool = "camlidl_abstract1_ap_abstract1_sat_tcons" (** Does the abstract value satisfy the constraint [dim in interval] ? *) external sat_interval : 'a Manager.t -> 'a t -> Var.t -> Interval.t -> bool = "camlidl_abstract1_ap_abstract1_sat_interval" (** Is the variable unconstrained in the abstract value ? If yes, this means that the existential quantification of the dimension does not change the value. *) external is_variable_unconstrained : 'a Manager.t -> 'a t -> Var.t -> bool = "camlidl_abstract1_ap_abstract1_is_variable_unconstrained" (* ============================================================ *) (** {3 Extraction of properties} *) (* ============================================================ *) (** Return the interval of variation of the variable in the abstract value. *) external bound_variable : 'a Manager.t -> 'a t -> Var.t -> Interval.t = "camlidl_abstract1_ap_abstract1_bound_variable" (** Return the interval of variation of the linear expression in the abstract value. Implement a form of linear programming, where the argument linear expression is the one to optimize under the constraints induced by the abstract value. *) external bound_linexpr : 'a Manager.t -> 'a t -> Linexpr1.t -> Interval.t = "camlidl_abstract1_ap_abstract1_bound_linexpr" (** Return the interval of variation of the tree expression in the abstract value. *) external bound_texpr : 'a Manager.t -> 'a t -> Texpr1.t -> Interval.t = "camlidl_abstract1_ap_abstract1_bound_texpr" (** Convert the abstract value to an hypercube *) val to_box : 'a Manager.t -> 'a t -> box1 (** Convert the abstract value to a conjunction of linear constraints. *) val to_lincons_array : 'a Manager.t -> 'a t -> Lincons1.earray (** Convert the abstract value to a conjunction of tree expressions constraints. *) val to_tcons_array : 'a Manager.t -> 'a t -> Tcons1.earray (** Convert the abstract value to a set of generators that defines it. *) val to_generator_array : 'a Manager.t -> 'a t -> Generator1.earray (* ********************************************************************** *) (** {2 Operations} *) (* ********************************************************************** *) (* ============================================================ *) (** {3 Meet and Join} *) (* ============================================================ *) (** Meet of 2 abstract values. *) external meet : 'a Manager.t -> 'a t -> 'a t -> 'a t = "camlidl_abstract1_ap_abstract1_meet" (** Meet of a non empty array of abstract values. *) external meet_array : 'a Manager.t -> 'a t array -> 'a t = "camlidl_abstract1_ap_abstract1_meet_array" (** Meet of an abstract value with an array of linear constraints. *) external meet_lincons_array : 'a Manager.t -> 'a t -> Lincons1.earray -> 'a t = "camlidl_abstract1_ap_abstract1_meet_lincons_array" (** Meet of an abstract value with an array of tree expressions constraints. *) external meet_tcons_array : 'a Manager.t -> 'a t -> Tcons1.earray -> 'a t = "camlidl_abstract1_ap_abstract1_meet_tcons_array" (** Join of 2 abstract values. *) external join : 'a Manager.t -> 'a t -> 'a t -> 'a t = "camlidl_abstract1_ap_abstract1_join" (** Join of a non empty array of abstract values. *) external join_array : 'a Manager.t -> 'a t array -> 'a t = "camlidl_abstract1_ap_abstract1_join_array" (** Add the array of generators to the abstract value (time elapse operator). The generators should either lines or rays, not vertices. *) external add_ray_array : 'a Manager.t -> 'a t -> Generator1.earray -> 'a t = "camlidl_abstract1_ap_abstract1_add_ray_array" (** {5 Side-effect versions of the previous functions} *) external meet_with : 'a Manager.t -> 'a t -> 'a t -> unit = "camlidl_abstract1_ap_abstract1_meet_with" external meet_lincons_array_with : 'a Manager.t -> 'a t -> Lincons1.earray -> unit = "camlidl_abstract1_ap_abstract1_meet_lincons_array_with" external meet_tcons_array_with : 'a Manager.t -> 'a t -> Tcons1.earray -> unit = "camlidl_abstract1_ap_abstract1_meet_tcons_array_with" external join_with : 'a Manager.t -> 'a t -> 'a t -> unit = "camlidl_abstract1_ap_abstract1_join_with" external add_ray_array_with : 'a Manager.t -> 'a t -> Generator1.earray -> unit = "camlidl_abstract1_ap_abstract1_add_ray_array_with" (* ============================================================ *) (** {3 Assignement and Substitutions} *) (* ============================================================ *) (** Parallel assignement of an array of dimensions by an array of same size of linear expressions *) external assign_linexpr_array : 'a Manager.t -> 'a t -> Var.t array -> Linexpr1.t array -> 'a t option -> 'a t = "camlidl_abstract1_ap_abstract1_assign_linexpr_array" (** Parallel substitution of an array of dimensions by an array of same size of linear expressions *) external substitute_linexpr_array : 'a Manager.t -> 'a t -> Var.t array -> Linexpr1.t array -> 'a t option -> 'a t = "camlidl_abstract1_ap_abstract1_substitute_linexpr_array" (** Parallel assignement of an array of dimensions by an array of same size of tree expressions *) external assign_texpr_array : 'a Manager.t -> 'a t -> Var.t array -> Texpr1.t array -> 'a t option -> 'a t = "camlidl_abstract1_ap_abstract1_assign_texpr_array" (** Parallel substitution of an array of dimensions by an array of same size of tree expressions *) external substitute_texpr_array : 'a Manager.t -> 'a t -> Var.t array -> Texpr1.t array -> 'a t option -> 'a t = "camlidl_abstract1_ap_abstract1_substitute_texpr_array" (** {5 Side-effect versions of the previous functions} *) external assign_linexpr_array_with : 'a Manager.t -> 'a t -> Var.t array -> Linexpr1.t array -> 'a t option -> unit = "camlidl_abstract1_ap_abstract1_assign_linexpr_array_with" external substitute_linexpr_array_with : 'a Manager.t -> 'a t -> Var.t array -> Linexpr1.t array -> 'a t option -> unit = "camlidl_abstract1_ap_abstract1_substitute_linexpr_array_with" external assign_texpr_array_with : 'a Manager.t -> 'a t -> Var.t array -> Texpr1.t array -> 'a t option -> unit = "camlidl_abstract1_ap_abstract1_assign_texpr_array_with" external substitute_texpr_array_with : 'a Manager.t -> 'a t -> Var.t array -> Texpr1.t array -> 'a t option -> unit = "camlidl_abstract1_ap_abstract1_substitute_texpr_array_with" (* ============================================================ *) (** {3 Projections} *) (* ============================================================ *) (** These functions implements forgeting (existential quantification) of (array of) variables. Both functional and side-effect versions are provided. The Boolean, if true, adds a projection onto 0-plane. *) external forget_array : 'a Manager.t -> 'a t -> Var.t array -> bool -> 'a t = "camlidl_abstract1_ap_abstract1_forget_array" external forget_array_with : 'a Manager.t -> 'a t -> Var.t array -> bool -> unit = "camlidl_abstract1_ap_abstract1_forget_array_with" (* ============================================================ *) (** {3 Change and permutation of dimensions} *) (* ============================================================ *) (** Change the environement of the abstract values. Variables that are removed are first existentially quantified, and variables that are introduced are unconstrained. The Boolean, if true, adds a projection onto 0-plane for these ones. *) external change_environment : 'a Manager.t -> 'a t -> Environment.t -> bool -> 'a t = "camlidl_abstract1_ap_abstract1_change_environment" (** Remove from the environment of the abstract value and from the abstract value itself variables that are unconstrained in it. *) external minimize_environment : 'a Manager.t -> 'a t -> 'a t = "camlidl_abstract1_ap_abstract1_minimize_environment" (** Parallel renaming of the environment of the abstract value. The new variables should not interfere with the variables that are not renamed. *) external rename_array : 'a Manager.t -> 'a t -> Var.t array -> Var.t array -> 'a t = "camlidl_abstract1_ap_abstract1_rename_array" external change_environment_with : 'a Manager.t -> 'a t -> Environment.t -> bool -> unit = "camlidl_abstract1_ap_abstract1_change_environment_with" external minimize_environment_with : 'a Manager.t -> 'a t -> unit = "camlidl_abstract1_ap_abstract1_minimize_environment_with" external rename_array_with : 'a Manager.t -> 'a t -> Var.t array -> Var.t array -> unit = "camlidl_abstract1_ap_abstract1_rename_array_with" (* ============================================================ *) (** {3 Expansion and folding of dimensions} *) (* ============================================================ *) (** These functions allows to expand one dimension into several ones having the same properties with respect to the other dimensions, and to fold several dimensions into one. Formally, - expand P(x,y,z) z w = P(x,y,z) inter P(x,y,w) if z is expanded in z and w - fold Q(x,y,z,w) z w = exists w:Q(x,y,z,w) union (exist z:Q(x,y,z,w))(z<-w) if z and w are folded onto z *) (** Expansion: [expand a var tvar] expands the variable [var] into itself and the additional variables in [tvar], which are given the same type as [var]. It results in (n+1) unrelated variables having same relations with other variables. The additional variables are added to the environment of the argument for making the environment of the result, so they should not belong to the initial environement. *) external expand : 'a Manager.t -> 'a t -> Var.t -> Var.t array -> 'a t = "camlidl_abstract1_ap_abstract1_expand" (** Folding: [fold a tvar] fold the variables in the array [tvar] of size n>=1 and put the result in the first variable of the array. The other variables of the array are then removed, both from the environment and the abstract value. *) external fold : 'a Manager.t -> 'a t -> Var.t array -> 'a t = "camlidl_abstract1_ap_abstract1_fold" external expand_with : 'a Manager.t -> 'a t -> Var.t -> Var.t array -> unit = "camlidl_abstract1_ap_abstract1_expand_with" external fold_with : 'a Manager.t -> 'a t -> Var.t array -> unit = "camlidl_abstract1_ap_abstract1_fold_with" (* ============================================================ *) (** {3 Widening} *) (* ============================================================ *) (** Widening *) external widening : 'a Manager.t -> 'a t -> 'a t -> 'a t = "camlidl_abstract1_ap_abstract1_widening" external widening_threshold : 'a Manager.t -> 'a t -> 'a t -> Lincons1.earray -> 'a t = "camlidl_abstract1_ap_abstract1_widening_threshold" (* ============================================================ *) (** {3 Closure operation} *) (* ============================================================ *) (** Closure: transform strict constraints into non-strict ones.*) external closure : 'a Manager.t -> 'a t -> 'a t = "camlidl_abstract1_ap_abstract1_closure" (** Side-effect version *) external closure_with : 'a Manager.t -> 'a t -> unit = "camlidl_abstract1_ap_abstract1_closure_with" (* ********************************************************************** *) (** {2 Additional operations} *) (* ********************************************************************** *) val of_lincons_array : 'a Manager.t -> Environment.t -> Lincons1.earray -> 'a t val of_tcons_array : 'a Manager.t -> Environment.t -> Tcons1.earray -> 'a t (** Abstract a conjunction of constraints *) val assign_linexpr : 'a Manager.t -> 'a t -> Var.t -> Linexpr1.t -> 'a t option -> 'a t val substitute_linexpr : 'a Manager.t -> 'a t -> Var.t -> Linexpr1.t -> 'a t option -> 'a t val assign_texpr : 'a Manager.t -> 'a t -> Var.t -> Texpr1.t -> 'a t option -> 'a t val substitute_texpr : 'a Manager.t -> 'a t -> Var.t -> Texpr1.t -> 'a t option -> 'a t (** Assignement/Substitution of a single dimension by a single expression *) val assign_linexpr_with : 'a Manager.t -> 'a t -> Var.t -> Linexpr1.t -> 'a t option -> unit val substitute_linexpr_with : 'a Manager.t -> 'a t -> Var.t -> Linexpr1.t -> 'a t option -> unit val assign_texpr_with : 'a Manager.t -> 'a t -> Var.t -> Texpr1.t -> 'a t option -> unit val substitute_texpr_with : 'a Manager.t -> 'a t -> Var.t -> Texpr1.t -> 'a t option -> unit (** Side-effect version of the previous functions *) (** Unification of 2 abstract values on their least common environment *) external unify : 'a Manager.t -> 'a t -> 'a t -> 'a t = "camlidl_abstract1_ap_abstract1_unify" (** Side-effect version *) external unify_with : 'a Manager.t -> 'a t -> 'a t -> unit = "camlidl_abstract1_ap_abstract1_unify_with" apron-dist-0.9.10/apron/mlapronidl/generator0_caml.c0000640014525101416610000001317211252216515022237 0ustar bjeannetpopart/* File generated from generator0.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include #include "ap_generator0.h" #include "apron_caml.h" #define LINE AP_GEN_LINE #define RAY AP_GEN_RAY #define VERTEX AP_GEN_VERTEX #define LINEMOD AP_GEN_LINEMOD #define RAYMOD AP_GEN_RAYMOD extern void camlidl_apron_scalar_ml2c(value, ap_scalar_t *); #define camlidl_ml2c_scalar_ap_scalar_t(v,c,ctx) camlidl_apron_scalar_ml2c(v,c) extern value camlidl_apron_scalar_c2ml(ap_scalar_t *); #define camlidl_c2ml_scalar_ap_scalar_t(c,ctx) camlidl_apron_scalar_c2ml(c) extern void camlidl_ml2c_scalar_ap_scalar_ptr(value, ap_scalar_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_ap_scalar_ptr(ap_scalar_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_scalar_struct_ap_scalar_array_t(value, struct ap_scalar_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_struct_ap_scalar_array_t(struct ap_scalar_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_t(value, struct ap_interval_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_t(struct ap_interval_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_ap_interval_ptr(value, ap_interval_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_ap_interval_ptr(ap_interval_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_array_t(value, struct ap_interval_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_array_t(struct ap_interval_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_coeff_struct_ap_coeff_t(value, struct ap_coeff_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_coeff_struct_ap_coeff_t(struct ap_coeff_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_ap_dim_t(value, ap_dim_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_ap_dim_t(ap_dim_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimchange_t(value, struct ap_dimchange_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange_t(struct ap_dimchange_t *, camlidl_ctx _ctx); extern void camlidl_apron_dimchange_ml2c(value, ap_dimchange_t *); #define camlidl_ml2c_dim_ap_dimchange_t(v,c,ctx) camlidl_apron_dimchange_ml2c(v,c) extern value camlidl_apron_dimchange_c2ml(ap_dimchange_t *); #define camlidl_c2ml_dim_ap_dimchange_t(c,ctx) camlidl_apron_dimchange_c2ml(c) extern void camlidl_ml2c_dim_struct_ap_dimchange2_t(value, struct ap_dimchange2_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange2_t(struct ap_dimchange2_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimperm_t(value, struct ap_dimperm_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimperm_t(struct ap_dimperm_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimension_t(value, struct ap_dimension_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimension_t(struct ap_dimension_t *, camlidl_ctx _ctx); extern void camlidl_apron_linexpr0_ptr_ml2c(value, ap_linexpr0_ptr *); #define camlidl_ml2c_linexpr0_ap_linexpr0_ptr(v,c,ctx) camlidl_apron_linexpr0_ptr_ml2c(v,c) extern value camlidl_apron_linexpr0_ptr_c2ml(ap_linexpr0_ptr *); #define camlidl_c2ml_linexpr0_ap_linexpr0_ptr(c,ctx) camlidl_apron_linexpr0_ptr_c2ml(c) int camlidl_transl_table_generator0_enum_9[5] = { LINE, RAY, VERTEX, LINEMOD, RAYMOD, }; int camlidl_ml2c_generator0_enum_gentyp(value _v1) { int _c2; _c2 = camlidl_transl_table_generator0_enum_9[Int_val(_v1)]; return _c2; } value camlidl_c2ml_generator0_enum_gentyp(int _c1) { value _v2; _v2 = camlidl_find_enum(_c1, camlidl_transl_table_generator0_enum_9, 5, "enum gentyp: bad enum gentyp value"); return _v2; } void camlidl_ml2c_generator0_struct_ap_generator0_t(value _v1, struct ap_generator0_t * _c2, camlidl_ctx _ctx) { value _v3; value _v4; _v3 = Field(_v1, 0); camlidl_ml2c_linexpr0_ap_linexpr0_ptr(_v3, &(*_c2).linexpr0, _ctx); _v4 = Field(_v1, 1); (*_c2).gentyp = camlidl_ml2c_generator0_enum_gentyp(_v4); } value camlidl_c2ml_generator0_struct_ap_generator0_t(struct ap_generator0_t * _c1, camlidl_ctx _ctx) { value _v2; value _v3[2]; _v3[0] = _v3[1] = 0; Begin_roots_block(_v3, 2) _v3[0] = camlidl_c2ml_linexpr0_ap_linexpr0_ptr(&(*_c1).linexpr0, _ctx); _v3[1] = camlidl_c2ml_generator0_enum_gentyp((*_c1).gentyp); _v2 = camlidl_alloc_small(2, 0); Field(_v2, 0) = _v3[0]; Field(_v2, 1) = _v3[1]; End_roots() return _v2; } void camlidl_ml2c_generator0_struct_ap_generator0_array_t(value _v1, struct ap_generator0_array_t * _c2, camlidl_ctx _ctx) { mlsize_t _c3; mlsize_t _c4; value _v5; _c3 = Wosize_val(_v1); (*_c2).p = camlidl_malloc(_c3 * sizeof(struct ap_generator0_t ), _ctx); for (_c4 = 0; _c4 < _c3; _c4++) { _v5 = Field(_v1, _c4); camlidl_ml2c_generator0_struct_ap_generator0_t(_v5, &(*_c2).p[_c4], _ctx); } (*_c2).size = _c3; } value camlidl_c2ml_generator0_struct_ap_generator0_array_t(struct ap_generator0_array_t * _c1, camlidl_ctx _ctx) { value _v2; mlsize_t _c3; value _v4; _v2 = camlidl_alloc((*_c1).size, 0); Begin_root(_v2) for (_c3 = 0; _c3 < (*_c1).size; _c3++) { _v4 = camlidl_c2ml_generator0_struct_ap_generator0_t(&(*_c1).p[_c3], _ctx); modify(&Field(_v2, _c3), _v4); } End_roots() return _v2; } apron-dist-0.9.10/apron/mlapronidl/linexpr0.idl0000640014525101416610000001547611023232505021266 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(MLI,"(** APRON Linear expressions of level 0 *)\n") quote(C, "\n\ #include \n\ #include \"ap_linexpr0.h\"\n\ #include \"apron_caml.h\"\n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; typedef [abstract, ml2c(camlidl_apron_linexpr0_ptr_ml2c), c2ml(camlidl_apron_linexpr0_ptr_c2ml)] struct ap_linexpr0_ptr* ap_linexpr0_ptr; quote(MLI,"(** Create a linear expression. Its representation is sparse if [None] is provided, dense of size [size] if [Some size] is provided. *)") ap_linexpr0_ptr ap_linexpr0_make([unique]int* size) quote(call,"\n\ if (size && *size<0) caml_failwith(\"Linexpr0.make: negative optional size\");\n\ if (size){\n\ _res = ap_linexpr0_alloc(AP_LINEXPR_DENSE, *size);\n\ } else {\n\ _res = ap_linexpr0_alloc(AP_LINEXPR_SPARSE, 0);\n\ }\n\ "); quote(MLI,"\n\ val of_list : int option -> (Coeff.t * Dim.t) list -> Coeff.t option -> t\n\ (** Combines {!make} and {!set_list} (see below) *)\n\ val of_array : int option -> (Coeff.t * Dim.t) array -> Coeff.t option -> t\n\ (** Combines {!make} and {!set_array} (see below) *)\n\ ") quote(MLI,"(** In case of sparse representation, remove zero coefficients *)") void ap_linexpr0_minimize(ap_linexpr0_ptr a); quote(MLI,"(** Copy *)") ap_linexpr0_ptr ap_linexpr0_copy(const ap_linexpr0_ptr a); quote(MLI,"(** Comparison with lexicographic ordering using Coeff.cmp, terminating by constant *)") int ap_linexpr0_compare(const ap_linexpr0_ptr a, const ap_linexpr0_ptr b); quote(MLI,"(** Hashing function *)") int ap_linexpr0_hash(const ap_linexpr0_ptr a); quote(MLI,"(** Get the size of the linear expression (which may be sparse or dense) *)") int ap_linexpr0_get_size(ap_linexpr0_ptr a) quote(call,"_res = a->size;"); quote(MLI,"(** Get the constant *)") [ref]struct ap_coeff_t* ap_linexpr0_get_cst(ap_linexpr0_ptr a) quote(call,"_res = &a->cst;"); quote(MLI,"(** Get the coefficient corresponding to the dimension *)") struct ap_coeff_t ap_linexpr0_get_coeff(ap_linexpr0_ptr a, int dim) quote(call, "\n\ {\n\ bool b;\n\ ap_coeff_init(&_res,AP_COEFF_SCALAR);\n\ if (dim<0) goto ap_linexpr0_get_coeff_exit;\n\ b = ap_linexpr0_get_coeff(&_res,a,(ap_dim_t)dim);\n \ if (b){\n\ ap_linexpr0_get_coeff_exit:\n\ ap_coeff_clear(&_res);\n\ caml_failwith(\"Linexpr0.get_coeff: out of bound dimension\");\n\ }\n\ }") quote(dealloc,"ap_coeff_clear(&_res);"); quote(MLI,"\n\ val set_list : t -> (Coeff.t * Dim.t) list -> Coeff.t option -> unit\n\ (** Set simultaneously a number of coefficients.\n\ \n\ [set_list expr [(c1,1); (c2,2)] (Some cst)] assigns coefficients [c1] \n\ to dimension 1, coefficient [c2] to dimension 2, and coefficient [cst]\n\ to the constant. If [(Some cst)] is replaced by [None],\n\ the constant coefficient is not assigned. *)\n\ val set_array : t -> (Coeff.t * Dim.t) array -> Coeff.t option -> unit\n\ (** Set simultaneously a number of coefficients, as [set_list]. *)\n") quote(MLI,"(** Set the constant *)") void ap_linexpr0_set_cst(ap_linexpr0_ptr a, [ref]struct ap_coeff_t* coeff) quote(call,"ap_linexpr0_set_cst(a,coeff);"); quote(MLI,"(** Set the coefficient corresponding to the dimension *)") void ap_linexpr0_set_coeff(ap_linexpr0_ptr a, int dim, [ref]struct ap_coeff_t* coeff) quote(call, "\n\ {\n\ bool b;\n\ if (dim<0) goto ap_linexpr0_set_coeff_exit;\n\ b = ap_linexpr0_set_coeff(a,(ap_dim_t)dim,coeff);\n \ if (b){\n\ ap_linexpr0_set_coeff_exit:\n\ caml_failwith(\"Linexpr0.set_coeff: out of bound dimension\");\n\ }\n\ }\n\ "); quote(MLI,"(** Iter the function on the pairs coefficient/dimension of the linear expression *)") quote(MLMLI,"\n\ external ap_linexpr0_iter: (Coeff.t -> Dim.t -> unit) -> ap_linexpr0_ptr -> unit = \"camlidl_expr0_linexpr0_iter\"\n \ ") quote(C,"\n\ value camlidl_expr0_linexpr0_iter(value _v_closure, value _v_linexpr0)\n\ {\n\ CAMLparam2(_v_closure,_v_linexpr0);\n\ CAMLlocal2(_v_dim,_v_coeff);\n\ size_t i;\n\ ap_dim_t dim;\n\ ap_coeff_t* pcoeff;\n\ ap_linexpr0_t* linexpr0;\n\ \n\ camlidl_apron_linexpr0_ptr_ml2c(_v_linexpr0,&linexpr0);\n\ ap_linexpr0_ForeachLinterm(linexpr0,i,dim,pcoeff){\n\ _v_dim = Val_int(dim);\n\ _v_coeff = camlidl_c2ml_coeff_struct_ap_coeff_t(pcoeff,NULL);\n \ callback2(_v_closure,_v_coeff,_v_dim);\n\ }\n\ CAMLreturn(Val_unit);\n\ }\n\ ") quote(MLI,"\n\ (** Print a linear expression, using a function converting from dimensions to names *)\n\ val print : (Dim.t -> string) -> Format.formatter -> ap_linexpr0_ptr -> unit\n\ ") quote(ML,"\n\ let set_list expr list ocst = \n\ List.iter\n\ (fun (coeff,dim) -> set_coeff expr dim coeff )\n\ list;\n\ begin match ocst with\n\ | Some cst -> set_cst expr cst\n\ | None -> ()\n\ end;\n\ ()\n\ let set_array expr tab ocst = \n\ Array.iter\n\ (fun (coeff,dim) -> set_coeff expr dim coeff )\n\ tab;\n\ begin match ocst with\n\ | Some cst -> set_cst expr cst\n\ | None -> ()\n\ end;\n\ ()\n\ \n\ let of_list osize list ocst =\n\ let expr = make osize in\n\ set_list expr list ocst;\n\ expr\n\ let of_array osize tab ocst =\n\ let expr = make osize in\n\ set_array expr tab ocst;\n\ expr\n\ \n\ let print assoc fmt expr = \n\ Format.fprintf fmt \"@[\";\n\ let first = ref true in\n\ iter\n\ (begin fun coeff dim ->\n\ let coeff = Coeff.reduce coeff in\n\ let sgn = match coeff with\n\ | Coeff.Scalar x -> Scalar.sgn x\n\ | Coeff.Interval i ->\n\ if Interval.is_zero i then 0 else 1\n\ in\n\ if sgn <> 0 then begin\n\ if not !first then Format.fprintf fmt \"@,\";\n\ if sgn>0 then begin\n\ if not !first then Format.pp_print_string fmt \"+\";\n\ end;\n\ begin match coeff with\n\ | Coeff.Scalar scalar ->\n\ if Scalar.equal_int scalar (-1) then\n\ Format.pp_print_string fmt \"-\"\n\ else if not (Scalar.equal_int scalar 1) then\n\ Scalar.print fmt scalar;\n\ | Coeff.Interval i ->\n\ Interval.print fmt i\n\ end;\n\ Format.pp_print_string fmt (assoc dim);\n\ first := false;\n\ end;\n\ end)\n\ expr;\n\ begin match get_cst expr with\n\ | Coeff.Scalar scalar ->\n\ let sgn = Scalar.sgn scalar in\n\ if sgn <> 0 then begin\n\ if not !first then Format.fprintf fmt \"@,\";\n\ if sgn>0 && not !first then Format.pp_print_char fmt '+';\n\ Scalar.print fmt scalar;\n\ end\n\ else if !first then\n\ Format.pp_print_char fmt '0';\n\ | Coeff.Interval i ->\n\ if not (Interval.is_zero i) then begin\n\ if not !first then Format.pp_print_char fmt '+';\n\ Interval.print fmt i\n\ end\n\ else if !first then\n\ Format.pp_print_char fmt '0';\n\ end;\n\ Format.fprintf fmt \"@]\";\n\ ()\n\ ") apron-dist-0.9.10/apron/mlapronidl/texpr1_caml.c0000640014525101416610000004020711252216516021414 0ustar bjeannetpopart/* File generated from texpr1.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include #include "ap_texpr1.h" #include "apron_caml.h" extern void camlidl_apron_scalar_ml2c(value, ap_scalar_t *); #define camlidl_ml2c_scalar_ap_scalar_t(v,c,ctx) camlidl_apron_scalar_ml2c(v,c) extern value camlidl_apron_scalar_c2ml(ap_scalar_t *); #define camlidl_c2ml_scalar_ap_scalar_t(c,ctx) camlidl_apron_scalar_c2ml(c) extern void camlidl_ml2c_scalar_ap_scalar_ptr(value, ap_scalar_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_ap_scalar_ptr(ap_scalar_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_scalar_struct_ap_scalar_array_t(value, struct ap_scalar_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_struct_ap_scalar_array_t(struct ap_scalar_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_t(value, struct ap_interval_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_t(struct ap_interval_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_ap_interval_ptr(value, ap_interval_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_ap_interval_ptr(ap_interval_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_array_t(value, struct ap_interval_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_array_t(struct ap_interval_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_coeff_struct_ap_coeff_t(value, struct ap_coeff_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_coeff_struct_ap_coeff_t(struct ap_coeff_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_ap_dim_t(value, ap_dim_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_ap_dim_t(ap_dim_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimchange_t(value, struct ap_dimchange_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange_t(struct ap_dimchange_t *, camlidl_ctx _ctx); extern void camlidl_apron_dimchange_ml2c(value, ap_dimchange_t *); #define camlidl_ml2c_dim_ap_dimchange_t(v,c,ctx) camlidl_apron_dimchange_ml2c(v,c) extern value camlidl_apron_dimchange_c2ml(ap_dimchange_t *); #define camlidl_c2ml_dim_ap_dimchange_t(c,ctx) camlidl_apron_dimchange_c2ml(c) extern void camlidl_ml2c_dim_struct_ap_dimchange2_t(value, struct ap_dimchange2_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange2_t(struct ap_dimchange2_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimperm_t(value, struct ap_dimperm_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimperm_t(struct ap_dimperm_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimension_t(value, struct ap_dimension_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimension_t(struct ap_dimension_t *, camlidl_ctx _ctx); extern void camlidl_apron_linexpr0_ptr_ml2c(value, ap_linexpr0_ptr *); #define camlidl_ml2c_linexpr0_ap_linexpr0_ptr(v,c,ctx) camlidl_apron_linexpr0_ptr_ml2c(v,c) extern value camlidl_apron_linexpr0_ptr_c2ml(ap_linexpr0_ptr *); #define camlidl_c2ml_linexpr0_ap_linexpr0_ptr(c,ctx) camlidl_apron_linexpr0_ptr_c2ml(c) extern void camlidl_apron_texpr0_ptr_ml2c(value, ap_texpr0_ptr *); #define camlidl_ml2c_texpr0_ap_texpr0_ptr(v,c,ctx) camlidl_apron_texpr0_ptr_ml2c(v,c) extern value camlidl_apron_texpr0_ptr_c2ml(ap_texpr0_ptr *); #define camlidl_c2ml_texpr0_ap_texpr0_ptr(c,ctx) camlidl_apron_texpr0_ptr_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_op_t(value, ap_texpr_op_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_op_t(ap_texpr_op_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_unop_t_ml2c(value, ap_texpr_unop_t *); #define camlidl_ml2c_texpr0_ap_texpr_unop_t(v,c,ctx) camlidl_apron_texpr_unop_t_ml2c(v,c) extern value camlidl_apron_texpr_unop_t_c2ml(ap_texpr_unop_t *); #define camlidl_c2ml_texpr0_ap_texpr_unop_t(c,ctx) camlidl_apron_texpr_unop_t_c2ml(c) extern void camlidl_apron_texpr_binop_t_ml2c(value, ap_texpr_binop_t *); #define camlidl_ml2c_texpr0_ap_texpr_binop_t(v,c,ctx) camlidl_apron_texpr_binop_t_ml2c(v,c) extern value camlidl_apron_texpr_binop_t_c2ml(ap_texpr_binop_t *); #define camlidl_c2ml_texpr0_ap_texpr_binop_t(c,ctx) camlidl_apron_texpr_binop_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rtype_t(value, ap_texpr_rtype_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rtype_t(ap_texpr_rtype_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_rtype_t_ml2c(value, ap_texpr_rtype_t *); #define camlidl_ml2c_texpr0_ap_texpr_rtype_t(v,c,ctx) camlidl_apron_texpr_rtype_t_ml2c(v,c) extern value camlidl_apron_texpr_rtype_t_c2ml(ap_texpr_rtype_t *); #define camlidl_c2ml_texpr0_ap_texpr_rtype_t(c,ctx) camlidl_apron_texpr_rtype_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rdir_t(value, ap_texpr_rdir_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rdir_t(ap_texpr_rdir_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_rdir_t_ml2c(value, ap_texpr_rdir_t *); #define camlidl_ml2c_texpr0_ap_texpr_rdir_t(v,c,ctx) camlidl_apron_texpr_rdir_t_ml2c(v,c) extern value camlidl_apron_texpr_rdir_t_c2ml(ap_texpr_rdir_t *); #define camlidl_c2ml_texpr0_ap_texpr_rdir_t(c,ctx) camlidl_apron_texpr_rdir_t_c2ml(c) extern void camlidl_apron_var_ptr_ml2c(value, ap_var_t *); #define camlidl_ml2c_var_ap_var_t(v,c,ctx) camlidl_apron_var_ptr_ml2c(v,c) extern value camlidl_apron_var_ptr_c2ml(ap_var_t *); #define camlidl_c2ml_var_ap_var_t(c,ctx) camlidl_apron_var_ptr_c2ml(c) extern int camlidl_ml2c_environment_enum_typvar(value); extern value camlidl_c2ml_environment_enum_typvar(int); extern int camlidl_transl_table_environment_enum_typvar[]; extern void camlidl_apron_environment_ptr_ml2c(value, ap_environment_ptr *); #define camlidl_ml2c_environment_ap_environment_ptr(v,c,ctx) camlidl_apron_environment_ptr_ml2c(v,c) extern value camlidl_apron_environment_ptr_c2ml(ap_environment_ptr *); #define camlidl_c2ml_environment_ap_environment_ptr(c,ctx) camlidl_apron_environment_ptr_c2ml(c) void camlidl_ml2c_texpr1_struct_ap_texpr1_t(value _v1, struct ap_texpr1_t * _c2, camlidl_ctx _ctx) { value _v3; value _v4; _v3 = Field(_v1, 0); camlidl_ml2c_texpr0_ap_texpr0_ptr(_v3, &(*_c2).texpr0, _ctx); _v4 = Field(_v1, 1); camlidl_ml2c_environment_ap_environment_ptr(_v4, &(*_c2).env, _ctx); } value camlidl_c2ml_texpr1_struct_ap_texpr1_t(struct ap_texpr1_t * _c1, camlidl_ctx _ctx) { value _v2; value _v3[2]; _v3[0] = _v3[1] = 0; Begin_roots_block(_v3, 2) _v3[0] = camlidl_c2ml_texpr0_ap_texpr0_ptr(&(*_c1).texpr0, _ctx); _v3[1] = camlidl_c2ml_environment_ap_environment_ptr(&(*_c1).env, _ctx); _v2 = camlidl_alloc_small(2, 0); Field(_v2, 0) = _v3[0]; Field(_v2, 1) = _v3[1]; End_roots() return _v2; } value camlidl_texpr1_ap_texpr1_to_expr_c2ml(ap_environment_t* env, ap_texpr0_t* expr, camlidl_ctx _ctx) { value _v_res ; switch(expr->discr){ case AP_TEXPR_CST: { value v0 = Val_unit; Begin_root(v0); v0 = camlidl_c2ml_coeff_struct_ap_coeff_t(&expr->val.cst, _ctx); _v_res = caml_alloc_small(1,0); Field(_v_res,0) = v0; End_roots(); } break; case AP_TEXPR_DIM: { ap_var_t var; value v0 = Val_unit; var = ap_environment_var_of_dim(env,expr->val.dim); assert(var!=NULL); var = ap_var_copy(var); Begin_root(v0); v0 = camlidl_apron_var_ptr_c2ml(&var); _v_res = caml_alloc_small(1,1); Field(_v_res,0) = v0; End_roots(); } break; case AP_TEXPR_NODE: { value v0,v1,v2,v3,v4; v0 = v1 = v2 = v3 = v4 = Val_unit; Begin_roots5(v0,v1,v2,v3,v4); ap_texpr0_node_t* node = expr->val.node; v1 = camlidl_texpr1_ap_texpr1_to_expr_c2ml(env,node->exprA,_ctx); v3 = camlidl_apron_texpr_rtype_t_c2ml(&node->type); v4 = camlidl_apron_texpr_rdir_t_c2ml(&node->dir); if (ap_texpr_is_unop(node->op)){ v0 = camlidl_apron_texpr_unop_t_c2ml(&node->op); _v_res = caml_alloc_small(4,2); Field(_v_res,0) = v0; Field(_v_res,1) = v1; Field(_v_res,2) = v3; Field(_v_res,3) = v4; } else { v0 = camlidl_apron_texpr_binop_t_c2ml(&node->op); v2 = camlidl_texpr1_ap_texpr1_to_expr_c2ml(env,node->exprB,_ctx); _v_res = caml_alloc_small(5,3); Field(_v_res,0) = v0; Field(_v_res,1) = v1; Field(_v_res,2) = v2; Field(_v_res,3) = v3; Field(_v_res,4) = v4; } End_roots(); } break; default: abort(); } return _v_res; } value camlidl_texpr1_ap_texpr1_to_expr(value _v_texpr) { CAMLparam1(_v_texpr); CAMLlocal1(_v_res); ap_environment_t* env; ap_texpr1_t texpr1; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_texpr1_struct_ap_texpr1_t(_v_texpr,&texpr1,_ctx); _v_res = camlidl_texpr1_ap_texpr1_to_expr_c2ml(texpr1.env,texpr1.texpr0,_ctx); camlidl_free(_ctx); CAMLreturn(_v_res); } void camlidl_texpr1_ap_texpr0_of_expr_ml2c(value v, ap_environment_t* env, ap_texpr0_t** res, camlidl_ctx _ctx) { ap_texpr0_t* texpr; ap_texpr0_node_t* node; ap_coeff_t coeff; ap_var_t var; ap_dim_t dim; ap_texpr0_t* exprA; ap_texpr0_t* exprB; value v0,v1,v2,v3,v4; texpr = malloc(sizeof(ap_texpr0_t)); assert (Is_block(v)); switch (Tag_val(v)){ case 0: /* Constant */ assert(Wosize_val(v)==1); v0 = Field(v,0); texpr->discr = AP_TEXPR_CST; camlidl_ml2c_coeff_struct_ap_coeff_t(v0,&coeff,_ctx); ap_coeff_init_set(&texpr->val.cst,&coeff); break; case 1: /* Variable */ assert(Wosize_val(v)==1); v0 = Field(v,0); camlidl_apron_var_ptr_ml2c(v0,&var); texpr->discr = AP_TEXPR_DIM; texpr->val.dim = ap_environment_dim_of_var(env,var); if (texpr->val.dim == AP_DIM_MAX){ free(texpr); texpr = NULL; } break; case 2: /* Unary node */ v0 = Field(v,0); v1 = Field(v,1); v2 = Field(v,2); v3 = Field(v,3); camlidl_texpr1_ap_texpr0_of_expr_ml2c(v1,env,&exprA,_ctx); if (exprA==NULL){ free(texpr); texpr = NULL; } else { node = malloc(sizeof(ap_texpr0_node_t)); camlidl_apron_texpr_unop_t_ml2c (v0,&node->op); camlidl_apron_texpr_rtype_t_ml2c (v2,&node->type); camlidl_apron_texpr_rdir_t_ml2c (v3,&node->dir); node->exprA = exprA; node->exprB = NULL; texpr->discr = AP_TEXPR_NODE; texpr->val.node = node; } break; case 3: /* Binary node */ v0 = Field(v,0); v1 = Field(v,1); v2 = Field(v,2); v3 = Field(v,3); v4 = Field(v,4); camlidl_texpr1_ap_texpr0_of_expr_ml2c(v1,env,&exprA,_ctx); if (exprA==NULL){ free(texpr); texpr = NULL; } else { camlidl_texpr1_ap_texpr0_of_expr_ml2c(v2,env,&exprB,_ctx); if (exprB==NULL){ ap_texpr0_free(exprA); free(texpr); texpr = NULL; } else { node = malloc(sizeof(ap_texpr0_node_t)); camlidl_apron_texpr_binop_t_ml2c (v0,&node->op); camlidl_apron_texpr_rtype_t_ml2c (v3,&node->type); camlidl_apron_texpr_rdir_t_ml2c (v4,&node->dir); node->exprA = exprA; node->exprB = exprB; texpr->discr = AP_TEXPR_NODE; texpr->val.node = node; } } break; default: assert(false); } *res = texpr; } value camlidl_texpr1_ap_texpr0_of_expr(value _v_env, value _v_expr) { CAMLparam2(_v_env,_v_expr); CAMLlocal1(_v_res); ap_texpr0_t* texpr0; ap_environment_t* env; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_apron_environment_ptr_ml2c(_v_env,&env); camlidl_texpr1_ap_texpr0_of_expr_ml2c(_v_expr,env,&texpr0,_ctx); camlidl_free(_ctx); if (texpr0==NULL){ caml_failwith("Texpr1.texpr0_of_expr: unknown variable in the environment"); } _v_res = camlidl_apron_texpr0_ptr_c2ml(&texpr0); CAMLreturn(_v_res); } value camlidl_texpr1_ap_texpr1_cst( value _v_env, value _v_coeff) { ap_environment_ptr env; /*in*/ struct ap_coeff_t *coeff; /*in*/ struct ap_texpr1_t *_res; struct ap_coeff_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); coeff = &_c1; camlidl_ml2c_coeff_struct_ap_coeff_t(_v_coeff, &_c1, _ctx); _res = ap_texpr1_cst(env, coeff); _vres = camlidl_c2ml_texpr1_struct_ap_texpr1_t(&*_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_texpr1_ap_texpr1_var( value _v_env, value _v_var) { ap_environment_ptr env; /*in*/ ap_var_t var; /*in*/ struct ap_texpr1_t *_res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); camlidl_ml2c_var_ap_var_t(_v_var, &var, _ctx); _res = ap_texpr1_var(env, var); _vres = camlidl_c2ml_texpr1_struct_ap_texpr1_t(&*_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_texpr1_ap_texpr1_unop( value _v_op, value _v_expr, value _v_type, value _v_dir) { ap_texpr_unop_t op; /*in*/ struct ap_texpr1_t *expr; /*in*/ ap_texpr_rtype_t type; /*in*/ ap_texpr_rdir_t dir; /*in*/ struct ap_texpr1_t *_res; struct ap_texpr1_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_texpr0_ap_texpr_unop_t(_v_op, &op, _ctx); expr = &_c1; camlidl_ml2c_texpr1_struct_ap_texpr1_t(_v_expr, &_c1, _ctx); camlidl_ml2c_texpr0_ap_texpr_rtype_t(_v_type, &type, _ctx); camlidl_ml2c_texpr0_ap_texpr_rdir_t(_v_dir, &dir, _ctx); /* begin user-supplied calling sequence */ _res = ap_texpr1_unop(op,ap_texpr1_copy(expr),type,dir); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_texpr1_struct_ap_texpr1_t(&*_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_texpr1_ap_texpr1_binop( value _v_op, value _v_exprA, value _v_exprB, value _v_type, value _v_dir) { ap_texpr_binop_t op; /*in*/ struct ap_texpr1_t *exprA; /*in*/ struct ap_texpr1_t *exprB; /*in*/ ap_texpr_rtype_t type; /*in*/ ap_texpr_rdir_t dir; /*in*/ struct ap_texpr1_t *_res; struct ap_texpr1_t _c1; struct ap_texpr1_t _c2; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_texpr0_ap_texpr_binop_t(_v_op, &op, _ctx); exprA = &_c1; camlidl_ml2c_texpr1_struct_ap_texpr1_t(_v_exprA, &_c1, _ctx); exprB = &_c2; camlidl_ml2c_texpr1_struct_ap_texpr1_t(_v_exprB, &_c2, _ctx); camlidl_ml2c_texpr0_ap_texpr_rtype_t(_v_type, &type, _ctx); camlidl_ml2c_texpr0_ap_texpr_rdir_t(_v_dir, &dir, _ctx); /* begin user-supplied calling sequence */ _res = ap_texpr1_binop(op,ap_texpr1_copy(exprA),ap_texpr1_copy(exprB),type,dir); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_texpr1_struct_ap_texpr1_t(&*_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_texpr1_ap_texpr1_extend_environment( value _v_texpr, value _v_env) { struct ap_texpr1_t *texpr; /*in*/ ap_environment_ptr env; /*in*/ struct ap_texpr1_t *_res; struct ap_texpr1_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; texpr = &_c1; camlidl_ml2c_texpr1_struct_ap_texpr1_t(_v_texpr, &_c1, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); /* begin user-supplied calling sequence */ { bool b; _res = ap_texpr1_extend_environment(texpr,env); if (!_res) caml_failwith("Texpr1.extend_environment: new environment is not a superenvironment"); } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_texpr1_struct_ap_texpr1_t(&*_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_texpr1_ap_texpr1_extend_environment_with( value _v_texpr, value _v_env) { struct ap_texpr1_t *texpr; /*in*/ ap_environment_ptr env; /*in*/ struct ap_texpr1_t _c1; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; texpr = &_c1; camlidl_ml2c_texpr1_struct_ap_texpr1_t(_v_texpr, &_c1, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); /* begin user-supplied calling sequence */ { if (texpr->env!=env){ bool b; ap_environment_copy(texpr->env); /* to protect it */ b = ap_texpr1_extend_environment_with(texpr,env); if (b){ ap_environment_free(texpr->env); caml_failwith("Texpr1.extend_environment_with: new environment is not a superenvironment"); } Store_field(_v_texpr,1,_v_env); ap_environment_free(env); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } apron-dist-0.9.10/apron/mlapronidl/generator0.ml0000640014525101416610000000124411252216515021426 0ustar bjeannetpopart(* File generated from generator0.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type typ = | LINE | RAY | VERTEX | LINEMOD | RAYMOD and t = { mutable linexpr0: Linexpr0.t; mutable typ: typ; } let string_of_typ = function | LINE -> "LIN" | RAY -> "RAY" | VERTEX -> "VTX" | LINEMOD -> "LINMOD" | RAYMOD -> "RAYMOD" let print assoc fmt gen = Format.fprintf fmt "%s:" (string_of_typ gen.typ); Linexpr0.print assoc fmt gen.linexpr0; () let make expr typ = { linexpr0 = expr; typ = typ; } let copy gen = { linexpr0 = Linexpr0.copy gen.linexpr0; typ = gen.typ; } apron-dist-0.9.10/apron/mlapronidl/coeff.ml0000640014525101416610000000363711252216515020452 0ustar bjeannetpopart(* File generated from coeff.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type union_5 = | Scalar of Scalar.t | Interval of Interval.t and t = union_5 (** APRON Coefficients (either scalars or intervals) *) let s_of_mpq x = Scalar (Scalar.of_mpq x) let s_of_mpqf x = Scalar (Scalar.of_mpqf x) let s_of_int x = Scalar (Scalar.of_int x) let s_of_frac x y = Scalar (Scalar.of_frac x y) let s_of_float x = Scalar (Scalar.of_float x) let s_of_mpfr x = Scalar (Scalar.of_mpfr x) let i_of_scalar inf sup = Interval (Interval.of_scalar inf sup) let i_of_mpq x y = Interval (Interval.of_mpq x y) let i_of_mpqf x y = Interval (Interval.of_mpqf x y) let i_of_int x y = Interval (Interval.of_int x y) let i_of_frac x y z w = Interval (Interval.of_frac x y z w) let i_of_float x y = Interval (Interval.of_float x y) let i_of_mpfr x y = Interval (Interval.of_mpfr x y) let is_scalar c = match c with Scalar _ -> true | _ -> false let is_interval c = match c with Interval _ -> true | _ -> false let cmp c1 c2 = match (c1,c2) with | (Scalar s1, Scalar s2) -> Scalar.cmp s1 s2 | (Interval i1, Interval i2) -> Interval.cmp i1 i2 | (Scalar _, _) -> (-3) | _ -> 3 let equal c1 c2 = match (c1,c2) with | (Scalar s1, Scalar s2) -> Scalar.equal s1 s2 | (Interval i1, Interval i2) -> Interval.equal i1 i2 | _ -> false let is_zero c = match c with | Scalar s -> (Scalar.sgn s)=0 | Interval i -> Interval.is_zero i let equal_int c b = match c with | Scalar s -> Scalar.equal_int s b | Interval i -> Interval.equal_int i b let neg c = match c with | Scalar s -> Scalar (Scalar.neg s) | Interval i -> Interval (Interval.neg i) let reduce c = match c with | Scalar _ -> c | Interval i -> if Scalar.equal i.Interval.inf i.Interval.sup then Scalar i.Interval.inf else c let print fmt c = match c with | Scalar s -> Scalar.print fmt s | Interval i -> Interval.print fmt i apron-dist-0.9.10/apron/mlapronidl/var.idl0000640014525101416610000000212011224617210020276 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, " #include \"apron_caml.h\" ") typedef [abstract, ml2c(camlidl_apron_var_ptr_ml2c), c2ml(camlidl_apron_var_ptr_c2ml)] struct apron_var_ptr ap_var_t; quote(MLMLI,"(** APRON Variables *)\n") quote(MLI,"(** Constructor *)") ap_var_t ap_var_of_string([string]char* name); quote(MLI,"(** Comparison function *)") int ap_var_compare(ap_var_t var1, ap_var_t var2); quote(MLI,"(** Conversion to string *)") [string]char* ap_var_to_string(ap_var_t var) quote(call,"_res = ((apron_var_ptr)var)->name;"); quote(MLI,"(** Hash function *)") int ap_var_hash(ap_var_t var); quote(MLI," (** Printing function *) val print : Format.formatter -> t -> unit ") quote(ML," let print fmt v = Format.pp_print_string fmt (to_string v) ") quote(MLMLI," (** Initialisation of abstract type operations in C library *) external set_var_operations : unit -> unit = \"camlidl_apron_set_var_operations\""); quote(ML," let _ = set_var_operations () ") apron-dist-0.9.10/apron/mlapronidl/apron_caml.h0000640014525101416610000002172311224617210021312 0ustar bjeannetpopart/* ********************************************************************** */ /* apron_caml.h */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _APRON_CAML_H_ #define _APRON_CAML_H_ #include #include "gmp_caml.h" #include "ap_manager.h" #include "ap_coeff.h" #include "ap_expr0.h" #include "ap_environment.h" #include "ap_abstract0.h" #include "ap_expr1.h" #include "ap_abstract1.h" #include #include #include #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif struct ap_interval_array_t { struct ap_interval_t** p; size_t size; }; struct ap_scalar_array_t { struct ap_scalar_t** p; size_t size; }; typedef struct ap_interval_t* ap_interval_ptr; typedef struct ap_scalar_t* ap_scalar_ptr; typedef struct ap_linexpr0_t* ap_linexpr0_ptr; typedef struct ap_texpr0_t* ap_texpr0_ptr; typedef struct ap_manager_t* ap_manager_ptr; typedef struct ap_manager_t* ap_manager_opt_ptr; typedef union ap_lincons0_typ { ap_scalar_t* scalar; } ap_lincons0_typ; struct ap_lincons0_ptr { ap_linexpr0_t* linexpr0; ap_constyp_t constyp; union ap_lincons0_typ typ; }; typedef struct apron_var_t { char* name; size_t count; } apron_var_t; typedef struct apron_var_t* apron_var_ptr; typedef struct ap_environment_t* ap_environment_ptr; typedef ap_abstract0_t* ap_abstract0_ptr; typedef struct ap_abstract1_ptr { ap_abstract0_ptr ap_abstract0_ptr; ap_environment_t* env; } ap_abstract1_ptr; /* ********************************************************************** */ /* dimchange */ /* ********************************************************************** */ void camlidl_apron_dimchange_ml2c(value v, ap_dimchange_t* dimchange); value camlidl_apron_dimchange_c2ml(ap_dimchange_t* dimchange); /* ********************************************************************** */ /* scalar */ /* ********************************************************************** */ void camlidl_apron_scalar_ml2c(value v, struct ap_scalar_t* scalar); value camlidl_apron_scalar_c2ml(struct ap_scalar_t* scalar); /* ********************************************************************** */ /* coefficients */ /* ********************************************************************** */ void camlidl_ml2c_coeff_struct_ap_coeff_t(value _v1, struct ap_coeff_t * _c2, struct camlidl_ctx_struct* _ctx); value camlidl_c2ml_coeff_struct_ap_coeff_t(struct ap_coeff_t * _c1, struct camlidl_ctx_struct* _ctx); /* ********************************************************************** */ /* linexpr0 */ /* ********************************************************************** */ extern struct custom_operations camlidl_apron_custom_linexpr0_ptr; static inline void camlidl_apron_linexpr0_ptr_ml2c(value v, ap_linexpr0_ptr* p) { *p = *((ap_linexpr0_ptr *) Data_custom_val(v)); } static inline value camlidl_apron_linexpr0_ptr_c2ml(ap_linexpr0_ptr* p) { value v; v = alloc_custom(&camlidl_apron_custom_linexpr0_ptr, sizeof(ap_linexpr0_ptr), 0,1); *((ap_linexpr0_ptr *) Data_custom_val(v)) = *p; return v; } /* ********************************************************************** */ /* texpr0 */ /* ********************************************************************** */ typedef ap_texpr_op_t ap_texpr_unop_t; typedef ap_texpr_op_t ap_texpr_binop_t; extern struct custom_operations camlidl_apron_custom_texpr0_ptr; static inline void camlidl_apron_texpr0_ptr_ml2c(value v, ap_texpr0_ptr* p) { *p = *((ap_texpr0_ptr *) Data_custom_val(v)); } static inline value camlidl_apron_texpr0_ptr_c2ml(ap_texpr0_ptr* p) { value v; v = alloc_custom(&camlidl_apron_custom_texpr0_ptr, sizeof(ap_texpr0_ptr), 0,1); *((ap_texpr0_ptr *) Data_custom_val(v)) = *p; return v; } static inline void camlidl_apron_texpr_unop_t_ml2c(value v, ap_texpr_op_t* op) { *op = AP_TEXPR_NEG + Int_val(v); assert(*op>=AP_TEXPR_NEG && *op<=AP_TEXPR_SQRT); } static inline value camlidl_apron_texpr_unop_t_c2ml(ap_texpr_op_t* op) { assert(*op>=AP_TEXPR_NEG && *op<=AP_TEXPR_SQRT); return Val_int((*op)-AP_TEXPR_NEG); } static inline void camlidl_apron_texpr_binop_t_ml2c(value v, ap_texpr_op_t* op) { *op = Int_val(v); assert(*op<=AP_TEXPR_MOD); } static inline value camlidl_apron_texpr_binop_t_c2ml(ap_texpr_op_t* op) { assert(*op<=AP_TEXPR_MOD); return Val_int((*op)); } static inline void camlidl_apron_texpr_rtype_t_ml2c(value v, ap_texpr_rtype_t* op) { *op = Int_val(v); assert(*op<=AP_RTYPE_QUAD); } static inline value camlidl_apron_texpr_rtype_t_c2ml(ap_texpr_rtype_t* op) { assert(*op<=AP_RTYPE_QUAD); return Val_int(*op); } static inline void camlidl_apron_texpr_rdir_t_ml2c(value v, ap_texpr_rdir_t* op) { *op = Int_val(v); assert(*op<=AP_RDIR_RND); } static inline value camlidl_apron_texpr_rdir_t_c2ml(ap_texpr_rdir_t* op) { assert(*op<=AP_RDIR_RND); return Val_int(*op); } /* ********************************************************************** */ /* manager */ /* ********************************************************************** */ extern struct custom_operations camlidl_apron_custom_manager_ptr; static inline void camlidl_apron_manager_ptr_ml2c(value v, ap_manager_ptr* p) { *p = *((ap_manager_ptr *) Data_custom_val(v)); } static inline value camlidl_apron_manager_ptr_c2ml(ap_manager_ptr* p) { value v; v = alloc_custom(&camlidl_apron_custom_manager_ptr, sizeof(ap_manager_ptr), 0,1); *((ap_manager_ptr *) Data_custom_val(v)) = *p; return v; } void ap_manager_set_deserialize(ap_manager_ptr man); ap_manager_ptr ap_manager_get_deserialize(void); extern value camlidl_c2ml_manager_struct_ap_exclog_t(struct ap_exclog_t*, struct camlidl_ctx_struct*); extern void camlidl_apron_manager_check_exception(struct ap_manager_t* man, void* _ctx); /* ********************************************************************** */ /* abstract0 */ /* ********************************************************************** */ extern struct custom_operations camlidl_apron_custom_abstract0_ptr; extern mlsize_t camlidl_apron_heap; static inline void camlidl_apron_abstract0_ptr_ml2c(value v, ap_abstract0_ptr* p) { *p = *((ap_abstract0_ptr *) Data_custom_val(v)); } static inline value camlidl_apron_abstract0_ptr_c2ml(ap_abstract0_ptr* p) { value v; assert((*p)->man!=NULL); v = alloc_custom(&camlidl_apron_custom_abstract0_ptr, sizeof(ap_abstract0_ptr), ap_abstract0_size((*p)->man,(*p)), camlidl_apron_heap); *((ap_abstract0_ptr *) Data_custom_val(v)) = *p; return v; } /* ********************************************************************** */ /* Variable */ /* ********************************************************************** */ static inline apron_var_ptr ap_var_of_string(char* name) { apron_var_ptr p = malloc(sizeof(apron_var_t)); p->name = malloc((1+strlen(name))*sizeof(char)); strcpy(p->name,name); p->count=1; return p; } static inline int ap_var_compare(ap_var_t pp1, ap_var_t pp2) { apron_var_ptr p1 = (apron_var_ptr)pp1; apron_var_ptr p2 = (apron_var_ptr)pp2; return (p1==p2) ? 0 : strcmp(p1->name,p2->name); } static inline int ap_var_hash(ap_var_t pp) { apron_var_ptr p = (apron_var_ptr)pp; unsigned char* c; int res = 0; for (c=(unsigned char*)p->name; (*c)!=0; c++){ res = res * 11 + (*c); } return res; } static inline ap_var_t ap_var_copy(ap_var_t pp){ apron_var_ptr p = (apron_var_ptr)pp; p->count++; return (ap_var_t)p; } static inline void ap_var_free(ap_var_t pp){ apron_var_ptr p = (apron_var_ptr)pp; if (p->count<=1){ free(p->name); free(p); } else p->count--; } static inline char* ap_var_to_string(ap_var_t pp) { apron_var_ptr p = (apron_var_ptr)pp; size_t l; char* res; l = strlen(p->name)+1; res = malloc(l*sizeof(char)); strcpy(res,p->name); return res; } static inline void camlidl_apron_var_ptr_ml2c(value v, ap_var_t* p){ *p = *((ap_var_t *) Data_custom_val(v)); } extern struct custom_operations camlidl_apron_custom_var_ptr; static inline value camlidl_apron_var_ptr_c2ml(ap_var_t* p) { value v; v = alloc_custom(&camlidl_apron_custom_var_ptr, sizeof(apron_var_ptr), 0,1); *((apron_var_ptr *) Data_custom_val(v)) = *p; return v; } /* ********************************************************************** */ /* environment */ /* ********************************************************************** */ extern struct custom_operations camlidl_apron_custom_environment_ptr; static inline void camlidl_apron_environment_ptr_ml2c(value v, ap_environment_ptr* p) { *p = *((ap_environment_ptr *) Data_custom_val(v)); } value camlidl_apron_environment_ptr_c2ml(ap_environment_ptr* p); /* ********************************************************************** */ /* init */ /* ********************************************************************** */ value camlidl_apron_init(value dummy); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/mlapronidl/tcons0.mli0000640014525101416610000000150111252216515020733 0ustar bjeannetpopart(* File generated from tcons0.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = { mutable texpr0 : Texpr0.t; mutable typ : Lincons0.typ; } (** APRON tree expressions constraints of level 0 *) type typ = Lincons0.typ = | EQ | SUPEQ | SUP | DISEQ | EQMOD of Scalar.t (** Make a tree expression constraint. Modifying later the tree expression expression modifies correspondingly the tree expression constraint and conversely *) val make : Texpr0.t -> typ -> t (** Copy a tree expression constraint (deep copy) *) val copy : t -> t (** Convert a constraint type to a string ([=],[>=], or [>]) *) val string_of_typ : typ -> string (** Print a constraint *) val print : (Dim.t -> string) -> Format.formatter -> t -> unit apron-dist-0.9.10/apron/mlapronidl/generator0.mli0000640014525101416610000000145011252216515021576 0ustar bjeannetpopart(* File generated from generator0.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type typ = | LINE | RAY | VERTEX | LINEMOD | RAYMOD and t = { mutable linexpr0: Linexpr0.t; mutable typ: typ; } (** APRON Generators of level 0 *) (** Making a generator. The constant coefficient of the linear expression is ignored. Modifying later the linear expression modifies correspondingly the generator and conversely. *) val make : Linexpr0.t -> typ -> t (** Copy a generator (deep copy) *) val copy : t -> t (** Convert a generator type to a string ([LIN],[RAY], or [VTX]) *) val string_of_typ : typ -> string (** Print a generator *) val print : (Dim.t -> string) -> Format.formatter -> t -> unit apron-dist-0.9.10/apron/mlapronidl/mlapronidl.tex0000640014525101416610000000362211251703423021711 0ustar bjeannetpopart\documentclass[twoside,10pt,a4paper]{report} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} \usepackage{ae} \usepackage{fullpage} \usepackage{url} \usepackage{ocamldoc} \usepackage{makeidx} \usepackage{fancyhdr} \pagestyle{fancy} \renewcommand{\headrulewidth}{0.9pt} \renewcommand{\footrulewidth}{0pt} \setlength{\headheight}{2.8ex} \setlength{\footskip}{5ex} \renewcommand{\chaptermark}[1]{ % \markboth{\MakeUppercase{\chaptername}\ \thechapter.\ #1}{}} \renewcommand{\sectionmark}[1]{} \setcounter{tocdepth}{1} \setcounter{secnumdepth}{4} \usepackage{color} \definecolor{mygreen}{rgb}{0,0.6,0} \usepackage[ps2pdf]{hyperref} \setlength{\parindent}{0em} \setlength{\parskip}{0.5ex} \makeindex \title{MLAPRONIDL: OCaml interface for APRON library} \author{Bertrand Jeannet} \begin{document} \maketitle \vspace*{0.9\textheight} All files distributed in the APRON library, including \textsc{MLApronIDL} subpackage, are distributed under LGPL license. Copyright (C) Bertrand Jeannet and Antoine Mine 2005-2009 for the \textsc{MLAPRONIDL} subpackage. \newpage \tableofcontents \input{Introduction.tex} \part{Coefficients} \input{Scalar.tex} \input{Interval.tex} \input{Coeff.tex} \part{Managers and Abstract Domains} \input{Manager.tex} \input{Box.tex} \input{Oct.tex} \input{Polka.tex} \input{Ppl.tex} \input{PolkaGrid.tex} \part{Level 1 of the interface} \input{Var.tex} \input{Environment.tex} \input{Linexpr1.tex} \input{Lincons1.tex} \input{Generator1.tex} \input{Texpr1.tex} \input{Tcons1.tex} \input{Abstract1.tex} \input{Parser.tex} \part{Level 0 of the interface} \input{Dim.tex} \input{Linexpr0.tex} \input{Lincons0.tex} \input{Generator0.tex} \input{Texpr0.tex} \input{Tcons0.tex} \input{Abstract0.tex} \part{MLGmpIDL modules} \input{Mpz.tex} \input{Mpq.tex} \input{Mpf.tex} \input{Mpfr.tex} \input{Gmp_random.tex} \input{Mpzf.tex} \input{Mpqf.tex} \input{Mpfrf.tex} \appendix \printindex \end{document} apron-dist-0.9.10/apron/mlapronidl/texpr1.ml0000640014525101416610000001025411252216516020605 0ustar bjeannetpopart(* File generated from texpr1.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = { mutable texpr0: Texpr0.t; mutable env: Environment.t; } (** Unary operators *) type unop = Texpr0.unop = | Neg | Cast | Sqrt (** Binary operators *) type binop = Texpr0.binop = | Add | Sub | Mul | Div | Mod (** Destination type for rounding *) type typ = Texpr0.typ = | Real | Int | Single | Double | Extended | Quad (** Rounding direction *) type round = Texpr0.round = | Near | Zero | Up | Down | Rnd (** User type for tree expressions *) type expr = | Cst of Coeff.t | Var of Var.t | Unop of unop * expr * typ * round | Binop of binop * expr * expr * typ * round (** {2 Constructors and Destructor} *) let rec expr0_of_expr1 env expr = match expr with | Cst x -> Texpr0.Cst x | Var var -> Texpr0.Dim (Environment.dim_of_var env var) | Unop(op,e,t,r) -> Texpr0.Unop( op, (expr0_of_expr1 env e), t,r ) | Binop(op,e1,e2,t,r) -> Texpr0.Binop( op, (expr0_of_expr1 env e1), (expr0_of_expr1 env e2), t,r ) let texpr0_of_expr env expr = Texpr0.of_expr (expr0_of_expr1 env expr) let of_expr env expr = { texpr0 = texpr0_of_expr env expr; env = env; } let copy e = { texpr0 = Texpr0.copy e.texpr0; env = e.env } let of_linexpr e = { texpr0 = Texpr0.of_linexpr e.Linexpr1.linexpr0; env = e.Linexpr1.env } let rec expr1_of_expr0 env expr = match expr with | Texpr0.Cst x -> Cst x | Texpr0.Dim dim -> Var (Environment.var_of_dim env dim) | Texpr0.Unop(op,e,t,r) -> Unop( op, (expr1_of_expr0 env e), t,r ) | Texpr0.Binop(op,e1,e2,t,r) -> Binop( op, (expr1_of_expr0 env e1), (expr1_of_expr0 env e2), t,r ) let to_expr texpr1 = let expr0 = Texpr0.to_expr texpr1.texpr0 in expr1_of_expr0 texpr1.env expr0 external cst : Environment.t -> Coeff.t -> t = "camlidl_texpr1_ap_texpr1_cst" external var : Environment.t -> Var.t -> t = "camlidl_texpr1_ap_texpr1_var" external unop : Texpr0.unop -> t -> Texpr0.typ -> Texpr0.round -> t = "camlidl_texpr1_ap_texpr1_unop" external binop : Texpr0.binop -> t -> t -> Texpr0.typ -> Texpr0.round -> t = "camlidl_texpr1_ap_texpr1_binop" (** {2 Tests} *) let is_interval_cst x = Texpr0.is_interval_cst x.texpr0 let is_interval_linear x = Texpr0.is_interval_linear x.texpr0 let is_interval_polynomial x = Texpr0.is_interval_polynomial x.texpr0 let is_interval_polyfrac x = Texpr0.is_interval_polyfrac x.texpr0 let is_scalar x = Texpr0.is_scalar x.texpr0 (** {2 Operations} *) external extend_environment : t -> Environment.t -> t = "camlidl_texpr1_ap_texpr1_extend_environment" external extend_environment_with : t -> Environment.t -> unit = "camlidl_texpr1_ap_texpr1_extend_environment_with" let get_texpr0 expr = expr.texpr0 let get_env expr = expr.env (** {2 Printing} *) let string_of_unop = Texpr0.string_of_unop let string_of_binop = Texpr0.string_of_binop let string_of_typ = Texpr0.string_of_typ let string_of_round = Texpr0.string_of_round let print_unop = Texpr0.print_unop let print_binop = Texpr0.print_binop let print_typ = Texpr0.print_typ let print_round = Texpr0.print_round let rec print_expr fmt expr = let precedence_of_expr = function | Cst _ | Var _ -> 5 | Unop(op,_,_,_) -> Texpr0.print_precedence_of_unop op | Binop(op,_,_,_,_) -> Texpr0.print_precedence_of_binop op in match expr with | Cst x -> Coeff.print fmt x | Var x -> Format.pp_print_string fmt (Var.to_string x) | Unop(op,e,typ,round) -> let prec = Texpr0.print_precedence_of_unop op in let prec1 = precedence_of_expr e in let par = prec1<=prec in Format.fprintf fmt "%s%s%a%s" (Texpr0.print_sprint_unop op typ round) (if par then "(" else "") print_expr e (if par then ")" else "") | Binop(op,e1,e2,typ,round) -> let prec = Texpr0.print_precedence_of_binop op in let prec1 = precedence_of_expr e1 in let prec2 = precedence_of_expr e2 in let par1 = prec1 Var.to_string (Environment.var_of_dim expr.env dim)) fmt expr.texpr0 apron-dist-0.9.10/apron/mlapronidl/tcons1.ml0000640014525101416610000000515411252216516020574 0ustar bjeannetpopart(* File generated from tcons1.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = { mutable tcons0: Tcons0.t; mutable env: Environment.t; } and earray = { mutable tcons0_array: Tcons0.t array; mutable array_env: Environment.t; } (** APRON tree constraints and array of tree constraints of level 1 *) type typ = Lincons0.typ = | EQ | SUPEQ | SUP | DISEQ | EQMOD of Scalar.t external extend_environment : t -> Environment.t -> t = "camlidl_tcons1_ap_tcons1_extend_environment" external extend_environment_with : t -> Environment.t -> unit = "camlidl_tcons1_ap_tcons1_extend_environment_with" let make texpr1 typ = { tcons0 = { Tcons0.texpr0 = texpr1.Texpr1.texpr0; Tcons0.typ = typ; }; env = texpr1.Texpr1.env; } let copy cons = { tcons0 = Tcons0.copy cons.tcons0; env = cons.env; } let string_of_typ = Tcons0.string_of_typ let print fmt cons = Tcons0.print (fun dim -> Var.to_string (Environment.var_of_dim cons.env dim)) fmt cons.tcons0; () let get_typ cons = cons.tcons0.Tcons0.typ let set_typ cons typ = cons.tcons0.Tcons0.typ <- typ let get_tcons0 cons = cons.tcons0 let get_env cons = cons.env let get_texpr1 cons = { Texpr1.texpr0 = cons.tcons0.Tcons0.texpr0; Texpr1.env = cons.env; } (* ====================================================================== *) (** {2 Type array} *) (* ====================================================================== *) external array_extend_environment : earray -> Environment.t -> earray = "camlidl_tcons1_ap_tcons1_array_extend_environment" external array_extend_environment_with : earray -> Environment.t -> unit = "camlidl_tcons1_ap_tcons1_array_extend_environment_with" let array_make env size = let cons = Tcons0.make (Texpr0.cst (Coeff.s_of_int 0)) Tcons0.EQ in { tcons0_array = Array.make size cons; array_env = env } let array_print ?(first=("[|@[":(unit,Format.formatter,unit) format)) ?(sep = (";@ ":(unit,Format.formatter,unit) format)) ?(last = ("@]|]":(unit,Format.formatter,unit) format)) fmt array = Abstract0.print_array ~first ~sep ~last (Tcons0.print (fun dim -> Var.to_string (Environment.var_of_dim array.array_env dim))) fmt array.tcons0_array; () let array_length array = Array.length (array.tcons0_array) let array_get_env array = array.array_env let array_get array index = let cons0 = array.tcons0_array.(index) in { tcons0 = cons0; env = array.array_env; } let array_set array index cons1 = if not (Environment.equal array.array_env cons1.env) then failwith "Tcons1.array_set: environments are not the same" else array.tcons0_array.(index) <- cons1.tcons0; apron-dist-0.9.10/apron/mlapronidl/tcons1.idl0000640014525101416610000001643510654126013020735 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C, "\n\ #include \n\ #include \"ap_tcons1.h\"\n\ #include \"apron_caml.h\"\n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; import "texpr0.idl"; import "tcons0.idl"; import "environment.idl"; import "texpr1.idl"; struct ap_tcons1_t { [mlname(mutable_tcons0)] ap_tcons0_t tcons0; [mlname(mutable_env)] ap_environment_ptr env; }; struct ap_tcons1_array_t { [mlname(mutable_tcons0_array)] struct ap_tcons0_array_t tcons0_array; [mlname(mutable_array_env)] ap_environment_ptr env; }; quote(MLMLI,"(** APRON tree constraints and array of tree constraints of level 1 *)") quote(MLMLI,"\n\ type typ = Lincons0.typ =\n\ | EQ\n\ | SUPEQ\n\ | SUP\n\ | DISEQ\n\ | EQMOD of Scalar.t\n\ ") quote(MLI,"\n\ (** Make a tree expression constraint. Modifying later the linear expression ({e not\n\ advisable}) modifies correspondingly the tree expression constraint and conversely,\n\ except for changes of environements *)\n\ val make: Texpr1.t -> typ -> t\n\ \n\ (** Copy (deep copy) *)\n\ val copy: t -> t\n\ \n\ (** Convert a constraint type to a string ([=],[>=], or [>]) *)\n\ val string_of_typ : typ -> string\n\ \n\ (** Print the tree expression constraint *)\n\ val print : Format.formatter -> t -> unit\n\ \n\ (** Get the constraint type *)\n\ val get_typ: t -> typ\n\ \n\ (** Set the constraint type *)\n\ val set_typ: t -> typ -> unit\n\ \n\ ") quote(MLI,"(** Change the environement of the constraint for a super-environement. Raise [Failure] if it is not the case *)") struct ap_tcons1_t ap_tcons1_extend_environment(const struct ap_tcons1_t tcons, ap_environment_ptr env) quote(call,"\n\ {\n\ bool b;\n\ b = ap_tcons1_extend_environment(&_res,&tcons,env);\n\ if (b) caml_failwith(\"Tcons1.extend_environment: new environment is not a superenvironment\");\n\ }") ; quote(MLI,"(** Side-effect version of the previous function *)") void ap_tcons1_extend_environment_with(struct ap_tcons1_t tcons, ap_environment_ptr env) quote(call,"\n\ {\n\ if (tcons.env!=env){ \n\ bool b;\n\ ap_environment_copy(tcons.env); /* to protect it */ \n\ b = ap_tcons1_extend_environment_with(&tcons,env);\n\ if (b){ \n\ ap_environment_free(tcons.env); \n\ caml_failwith(\"Tcons1.extend_environment_with: new environment is not a superenvironment\");\n\ }\n\ Store_field(_v_tcons,1,_v_env);\n\ ap_environment_free(env);\n\ }\n\ }") ; quote(MLI,"\n\ (** Get the environement of the tree expression constraint *)\n\ val get_env: t -> Environment.t\n\ \n\ (** Get the underlying linear expression. Modifying the linear expression ({e\n\ not advisable}) modifies correspondingly the tree expression constraint and\n\ conversely, except for changes of environements *)\n\ val get_texpr1: t -> Texpr1.t\n\ \n\ (** Get the underlying tree expression constraint of level 0. Modifying the constraint\n\ of level 0 ({e not advisable}) modifies correspondingly the tree expression constraint\n\ and conversely, except for changes of environements*)\n\ val get_tcons0: t -> Tcons0.t\n\ \n\ ") quote(ML,"\n\ let make texpr1 typ = {\n\ tcons0 = {\n\ Tcons0.texpr0 = texpr1.Texpr1.texpr0;\n\ Tcons0.typ = typ;\n\ };\n\ env = texpr1.Texpr1.env;\n\ }\n\ let copy cons = {\n\ tcons0 = Tcons0.copy cons.tcons0;\n\ env = cons.env;\n\ }\n\ let string_of_typ = Tcons0.string_of_typ\n\ \n\ let print fmt cons = \n\ Tcons0.print\n\ (fun dim -> Var.to_string (Environment.var_of_dim cons.env dim)) fmt cons.tcons0;\n \ ()\n\ let get_typ cons = cons.tcons0.Tcons0.typ\n\ let set_typ cons typ = cons.tcons0.Tcons0.typ <- typ\n\ let get_tcons0 cons = cons.tcons0\n\ let get_env cons = cons.env\n\ let get_texpr1 cons = {\n\ Texpr1.texpr0 = cons.tcons0.Tcons0.texpr0;\n\ Texpr1.env = cons.env;\n\ }") quote(MLMLI,"(* ====================================================================== *)") quote(MLMLI,"(** {2 Type array} *)") quote(MLMLI,"(* ====================================================================== *)") quote(MLI,"\n\ (** Make an array of tree expression constraints with the given size and defined on the\n\ given environement. The elements are initialized with the constraint 0=0. *)\n\ val array_make : Environment.t -> int -> earray\n\ \n\ (** Print an array of constraints *)\n\ val array_print :\n\ ?first:(unit, Format.formatter, unit) format ->\n\ ?sep:(unit, Format.formatter, unit) format ->\n\ ?last:(unit, Format.formatter, unit) format ->\n\ Format.formatter -> earray -> unit\n\ \n\ (** Get the size of the array *)\n\ val array_length : earray -> int\n\ \n\ (** Get the environment of the array *)\n\ val array_get_env : earray -> Environment.t\n\ \n\ (** Get the element of the given index (which is not a copy) *)\n\ val array_get : earray -> int -> t\n\ \n\ (** Set the element of the given index (without any copy). The array and the\n\ constraint should be defined on the same environement; otherwise a [Failure]\n\ exception is raised.*)\n\ val array_set : earray -> int -> t -> unit\n\ ") quote(MLI,"(** Change the environement of the array of constraints for a super-environement. Raise [Failure] if it is not the case*)") struct ap_tcons1_array_t ap_tcons1_array_extend_environment(const struct ap_tcons1_array_t array, ap_environment_ptr env) quote(call,"\n\ {\n\ bool b;\n\ b = ap_tcons1_array_extend_environment(&_res,&array,env);\n\ if (b) caml_failwith(\"Tcons1.array_extend_environment: new environment is not a superenvironment\");\n\ }") ; quote(MLI,"(** Side-effect version of the previous function *)") void ap_tcons1_array_extend_environment_with(struct ap_tcons1_array_t array, ap_environment_ptr env) quote(call,"\n\ {\n\ if (array.env!=env){ \n\ bool b;\n\ ap_environment_copy(array.env); /* to protect it */ \n\ b = ap_tcons1_array_extend_environment_with(&array,env);\n\ if (b){ \n\ ap_environment_free(array.env); \n\ caml_failwith(\"Tcons1.array_extend_environment_with: new environment is not a superenvironment\");\n\ }\n\ Store_field(_v_array,1,_v_env);\n\ ap_environment_free(env);\n\ }\n\ }") ; quote(ML,"\n\ let array_make env size =\n\ let cons = Tcons0.make (Texpr0.cst (Coeff.s_of_int 0)) Tcons0.EQ in\n \ {\n\ tcons0_array = Array.make size cons;\n\ array_env = env\n\ }\n\ let array_print\n\ ?(first=(\"[|@[\":(unit,Format.formatter,unit) format))\n\ ?(sep = (\";@ \":(unit,Format.formatter,unit) format))\n\ ?(last = (\"@]|]\":(unit,Format.formatter,unit) format))\n\ fmt array \n\ = \n\ Abstract0.print_array ~first ~sep ~last\n\ (Tcons0.print\n\ (fun dim -> Var.to_string (Environment.var_of_dim array.array_env dim)))\n \ fmt array.tcons0_array;\n\ ()\n\ let array_length array = Array.length (array.tcons0_array)\n\ let array_get_env array = array.array_env\n\ let array_get array index =\n\ let cons0 = array.tcons0_array.(index) in\n\ { tcons0 = cons0; env = array.array_env; }\n\ let array_set array index cons1 =\n\ if not (Environment.equal array.array_env cons1.env) then\n\ failwith \"Tcons1.array_set: environments are not the same\"\n\ else\n\ array.tcons0_array.(index) <- cons1.tcons0;\n\ ") apron-dist-0.9.10/apron/mlapronidl/abstract0_caml.c0000640014525101416610000021764311252216516022066 0ustar bjeannetpopart/* File generated from abstract0.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include #include "ap_expr0.h" #include "ap_abstract0.h" #include "caml/callback.h" #include "apron_caml.h" extern void camlidl_apron_scalar_ml2c(value, ap_scalar_t *); #define camlidl_ml2c_scalar_ap_scalar_t(v,c,ctx) camlidl_apron_scalar_ml2c(v,c) extern value camlidl_apron_scalar_c2ml(ap_scalar_t *); #define camlidl_c2ml_scalar_ap_scalar_t(c,ctx) camlidl_apron_scalar_c2ml(c) extern void camlidl_ml2c_scalar_ap_scalar_ptr(value, ap_scalar_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_ap_scalar_ptr(ap_scalar_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_scalar_struct_ap_scalar_array_t(value, struct ap_scalar_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_struct_ap_scalar_array_t(struct ap_scalar_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_t(value, struct ap_interval_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_t(struct ap_interval_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_ap_interval_ptr(value, ap_interval_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_ap_interval_ptr(ap_interval_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_array_t(value, struct ap_interval_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_array_t(struct ap_interval_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_coeff_struct_ap_coeff_t(value, struct ap_coeff_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_coeff_struct_ap_coeff_t(struct ap_coeff_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_ap_dim_t(value, ap_dim_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_ap_dim_t(ap_dim_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimchange_t(value, struct ap_dimchange_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange_t(struct ap_dimchange_t *, camlidl_ctx _ctx); extern void camlidl_apron_dimchange_ml2c(value, ap_dimchange_t *); #define camlidl_ml2c_dim_ap_dimchange_t(v,c,ctx) camlidl_apron_dimchange_ml2c(v,c) extern value camlidl_apron_dimchange_c2ml(ap_dimchange_t *); #define camlidl_c2ml_dim_ap_dimchange_t(c,ctx) camlidl_apron_dimchange_c2ml(c) extern void camlidl_ml2c_dim_struct_ap_dimchange2_t(value, struct ap_dimchange2_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange2_t(struct ap_dimchange2_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimperm_t(value, struct ap_dimperm_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimperm_t(struct ap_dimperm_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimension_t(value, struct ap_dimension_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimension_t(struct ap_dimension_t *, camlidl_ctx _ctx); extern void camlidl_apron_linexpr0_ptr_ml2c(value, ap_linexpr0_ptr *); #define camlidl_ml2c_linexpr0_ap_linexpr0_ptr(v,c,ctx) camlidl_apron_linexpr0_ptr_ml2c(v,c) extern value camlidl_apron_linexpr0_ptr_c2ml(ap_linexpr0_ptr *); #define camlidl_c2ml_linexpr0_ap_linexpr0_ptr(c,ctx) camlidl_apron_linexpr0_ptr_c2ml(c) extern void camlidl_apron_lincons0_ml2c(value, ap_lincons0_t *, camlidl_ctx); #define camlidl_ml2c_lincons0_ap_lincons0_t(v,c,ctx) camlidl_apron_lincons0_ml2c(v,c,ctx) extern value camlidl_apron_lincons0_c2ml(ap_lincons0_t *); #define camlidl_c2ml_lincons0_ap_lincons0_t(c,ctx) camlidl_apron_lincons0_c2ml(c) extern void camlidl_ml2c_lincons0_struct_ap_lincons0_array_t(value, struct ap_lincons0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_lincons0_struct_ap_lincons0_array_t(struct ap_lincons0_array_t *, camlidl_ctx _ctx); extern int camlidl_ml2c_generator0_enum_gentyp(value); extern value camlidl_c2ml_generator0_enum_gentyp(int); extern int camlidl_transl_table_generator0_enum_gentyp[]; extern void camlidl_ml2c_generator0_struct_ap_generator0_t(value, struct ap_generator0_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_generator0_struct_ap_generator0_t(struct ap_generator0_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_generator0_struct_ap_generator0_array_t(value, struct ap_generator0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_generator0_struct_ap_generator0_array_t(struct ap_generator0_array_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr0_ptr_ml2c(value, ap_texpr0_ptr *); #define camlidl_ml2c_texpr0_ap_texpr0_ptr(v,c,ctx) camlidl_apron_texpr0_ptr_ml2c(v,c) extern value camlidl_apron_texpr0_ptr_c2ml(ap_texpr0_ptr *); #define camlidl_c2ml_texpr0_ap_texpr0_ptr(c,ctx) camlidl_apron_texpr0_ptr_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_op_t(value, ap_texpr_op_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_op_t(ap_texpr_op_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_unop_t_ml2c(value, ap_texpr_unop_t *); #define camlidl_ml2c_texpr0_ap_texpr_unop_t(v,c,ctx) camlidl_apron_texpr_unop_t_ml2c(v,c) extern value camlidl_apron_texpr_unop_t_c2ml(ap_texpr_unop_t *); #define camlidl_c2ml_texpr0_ap_texpr_unop_t(c,ctx) camlidl_apron_texpr_unop_t_c2ml(c) extern void camlidl_apron_texpr_binop_t_ml2c(value, ap_texpr_binop_t *); #define camlidl_ml2c_texpr0_ap_texpr_binop_t(v,c,ctx) camlidl_apron_texpr_binop_t_ml2c(v,c) extern value camlidl_apron_texpr_binop_t_c2ml(ap_texpr_binop_t *); #define camlidl_c2ml_texpr0_ap_texpr_binop_t(c,ctx) camlidl_apron_texpr_binop_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rtype_t(value, ap_texpr_rtype_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rtype_t(ap_texpr_rtype_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_rtype_t_ml2c(value, ap_texpr_rtype_t *); #define camlidl_ml2c_texpr0_ap_texpr_rtype_t(v,c,ctx) camlidl_apron_texpr_rtype_t_ml2c(v,c) extern value camlidl_apron_texpr_rtype_t_c2ml(ap_texpr_rtype_t *); #define camlidl_c2ml_texpr0_ap_texpr_rtype_t(c,ctx) camlidl_apron_texpr_rtype_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rdir_t(value, ap_texpr_rdir_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rdir_t(ap_texpr_rdir_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_rdir_t_ml2c(value, ap_texpr_rdir_t *); #define camlidl_ml2c_texpr0_ap_texpr_rdir_t(v,c,ctx) camlidl_apron_texpr_rdir_t_ml2c(v,c) extern value camlidl_apron_texpr_rdir_t_c2ml(ap_texpr_rdir_t *); #define camlidl_c2ml_texpr0_ap_texpr_rdir_t(c,ctx) camlidl_apron_texpr_rdir_t_c2ml(c) extern void camlidl_apron_tcons0_ml2c(value, ap_tcons0_t *, camlidl_ctx); #define camlidl_ml2c_tcons0_ap_tcons0_t(v,c,ctx) camlidl_apron_tcons0_ml2c(v,c,ctx) extern value camlidl_apron_tcons0_c2ml(ap_tcons0_t *); #define camlidl_c2ml_tcons0_ap_tcons0_t(c,ctx) camlidl_apron_tcons0_c2ml(c) extern void camlidl_ml2c_tcons0_struct_ap_tcons0_array_t(value, struct ap_tcons0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_tcons0_struct_ap_tcons0_array_t(struct ap_tcons0_array_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_funid_ml2c(value, ap_funid_t *); #define camlidl_ml2c_manager_ap_funid_t(v,c,ctx) camlidl_apron_manager_funid_ml2c(v,c) extern value camlidl_apron_manager_funid_c2ml(ap_funid_t *); #define camlidl_c2ml_manager_ap_funid_t(c,ctx) camlidl_apron_manager_funid_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_funopt_t(value, struct ap_funopt_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_funopt_t(struct ap_funopt_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_exc_ml2c(value, ap_exc_t *); #define camlidl_ml2c_manager_ap_exc_t(v,c,ctx) camlidl_apron_manager_exc_ml2c(v,c) extern value camlidl_apron_manager_exc_c2ml(ap_exc_t *); #define camlidl_c2ml_manager_ap_exc_t(c,ctx) camlidl_apron_manager_exc_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_exclog_t(value, struct ap_exclog_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_exclog_t(struct ap_exclog_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_ptr_ml2c(value, ap_manager_ptr *); #define camlidl_ml2c_manager_ap_manager_ptr(v,c,ctx) camlidl_apron_manager_ptr_ml2c(v,c) extern value camlidl_apron_manager_ptr_c2ml(ap_manager_ptr *); #define camlidl_c2ml_manager_ap_manager_ptr(c,ctx) camlidl_apron_manager_ptr_c2ml(c) #define camlidl_ml2c_abstract0_ap_abstract0_ptr(v,c,ctx) camlidl_apron_abstract0_ptr_ml2c(v,c) #define camlidl_c2ml_abstract0_ap_abstract0_ptr(c,ctx) camlidl_apron_abstract0_ptr_c2ml(c) value camlidl_abstract0_ap_abstract0_set_gc( value _v_size) { int size; /*in*/ size = Int_val(_v_size); /* begin user-supplied calling sequence */ camlidl_apron_heap = size; /* end user-supplied calling sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_copy( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _res = ap_abstract0_copy(man, a); _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_size( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _res = ap_abstract0_size(man, a); _vres = Val_int(_res); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_minimize( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); ap_abstract0_minimize(man, a); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_canonicalize( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); ap_abstract0_canonicalize(man, a); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_hash( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _res = ap_abstract0_hash(man, a); _vres = Val_int(_res); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_approximate( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ int v; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); v = Int_val(_v_v); ap_abstract0_approximate(man, a, v); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_fdump( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); /* begin user-supplied calling sequence */ ap_abstract0_fdump(stdout,man, a); fflush(stdout); /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_bottom( value _v_man, value _v_v1, value _v_v2) { ap_manager_ptr man; /*in*/ int v1; /*in*/ int v2; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); v1 = Int_val(_v_v1); v2 = Int_val(_v_v2); _res = ap_abstract0_bottom(man, v1, v2); _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_top( value _v_man, value _v_v1, value _v_v2) { ap_manager_ptr man; /*in*/ int v1; /*in*/ int v2; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); v1 = Int_val(_v_v1); v2 = Int_val(_v_v2); _res = ap_abstract0_top(man, v1, v2); _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_of_box( value _v_man, value _v_intdim, value _v_realdim, value _v_array) { ap_manager_ptr man; /*in*/ int intdim; /*in*/ int realdim; /*in*/ struct ap_interval_array_t array; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); intdim = Int_val(_v_intdim); realdim = Int_val(_v_realdim); camlidl_ml2c_interval_struct_ap_interval_array_t(_v_array, &array, _ctx); /* begin user-supplied calling sequence */ _res = ap_abstract0_of_box(man,intdim,realdim,(ap_interval_t**)array.p); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_dimension( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ struct ap_dimension_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _res = ap_abstract0_dimension(man, a); _vres = camlidl_c2ml_dim_struct_ap_dimension_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_manager( value _v_a) { ap_abstract0_ptr a; /*in*/ ap_manager_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); /* begin user-supplied calling sequence */ _res = ap_manager_copy(a->man); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_manager_ap_manager_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_abstract0_ap_abstract0_is_bottom( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _res = ap_abstract0_is_bottom(man, a); _vres = Val_int(_res); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_is_top( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _res = ap_abstract0_is_top(man, a); _vres = Val_int(_res); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_is_leq( value _v_man, value _v_a1, value _v_a2) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a1; /*in*/ ap_abstract0_ptr a2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a1, &a1, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a2, &a2, _ctx); _res = ap_abstract0_is_leq(man, a1, a2); _vres = Val_int(_res); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_is_eq( value _v_man, value _v_a1, value _v_a2) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a1; /*in*/ ap_abstract0_ptr a2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a1, &a1, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a2, &a2, _ctx); _res = ap_abstract0_is_eq(man, a1, a2); _vres = Val_int(_res); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_sat_lincons( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_lincons0_t *v; /*in*/ int _res; ap_lincons0_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); v = &_c1; camlidl_ml2c_lincons0_ap_lincons0_t(_v_v, &_c1, _ctx); _res = ap_abstract0_sat_lincons(man, a, v); _vres = Val_int(_res); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_sat_tcons( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_tcons0_t *v; /*in*/ int _res; ap_tcons0_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); v = &_c1; camlidl_ml2c_tcons0_ap_tcons0_t(_v_v, &_c1, _ctx); _res = ap_abstract0_sat_tcons(man, a, v); _vres = Val_int(_res); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_sat_interval( value _v_man, value _v_a, value _v_v1, value _v_v2) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dim_t v1; /*in*/ struct ap_interval_t *v2; /*in*/ int _res; struct ap_interval_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); camlidl_ml2c_dim_ap_dim_t(_v_v1, &v1, _ctx); v2 = &_c1; camlidl_ml2c_interval_struct_ap_interval_t(_v_v2, &_c1, _ctx); _res = ap_abstract0_sat_interval(man, a, v1, v2); _vres = Val_int(_res); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_is_dimension_unconstrained( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dim_t v; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); camlidl_ml2c_dim_ap_dim_t(_v_v, &v, _ctx); _res = ap_abstract0_is_dimension_unconstrained(man, a, v); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_abstract0_ap_abstract0_bound_dimension( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dim_t v; /*in*/ struct ap_interval_t *_res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); camlidl_ml2c_dim_ap_dim_t(_v_v, &v, _ctx); _res = ap_abstract0_bound_dimension(man, a, v); _vres = camlidl_c2ml_interval_struct_ap_interval_t(&*_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ ap_interval_free(_res); if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_bound_linexpr( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_linexpr0_ptr v; /*in*/ struct ap_interval_t *_res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); camlidl_ml2c_linexpr0_ap_linexpr0_ptr(_v_v, &v, _ctx); _res = ap_abstract0_bound_linexpr(man, a, v); _vres = camlidl_c2ml_interval_struct_ap_interval_t(&*_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ ap_interval_free(_res); if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_bound_texpr( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_texpr0_ptr v; /*in*/ struct ap_interval_t *_res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); camlidl_ml2c_texpr0_ap_texpr0_ptr(_v_v, &v, _ctx); _res = ap_abstract0_bound_texpr(man, a, v); _vres = camlidl_c2ml_interval_struct_ap_interval_t(&*_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ ap_interval_free(_res); if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_to_box( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ struct ap_interval_array_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); /* begin user-supplied calling sequence */ { ap_dimension_t dim; _res.p = ap_abstract0_to_box(man,a); dim = ap_abstract0_dimension(man,a); _res.size = dim.intdim + dim.realdim; } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_interval_struct_ap_interval_array_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ ap_interval_array_free(_res.p, _res.size); if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_to_lincons_array( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ struct ap_lincons0_array_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _res = ap_abstract0_to_lincons_array(man, a); _vres = camlidl_c2ml_lincons0_struct_ap_lincons0_array_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ free(_res.p); if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_to_tcons_array( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ struct ap_tcons0_array_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _res = ap_abstract0_to_tcons_array(man, a); _vres = camlidl_c2ml_tcons0_struct_ap_tcons0_array_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ free(_res.p); if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_to_generator_array( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ struct ap_generator0_array_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _res = ap_abstract0_to_generator_array(man, a); _vres = camlidl_c2ml_generator0_struct_ap_generator0_array_t(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ free(_res.p); if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_meet( value _v_man, value _v_a1, value _v_a2) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a1; /*in*/ ap_abstract0_ptr a2; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a1, &a1, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a2, &a2, _ctx); /* begin user-supplied calling sequence */ _res = ap_abstract0_meet(man,false,a1,a2); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_meet_array( value _v_man, value _v_array) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr *array; /*in*/ unsigned int size; /*in*/ ap_abstract0_ptr _res; mlsize_t _c1; mlsize_t _c2; value _v3; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); _c1 = Wosize_val(_v_array); array = camlidl_malloc(_c1 * sizeof(ap_abstract0_ptr ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_array, _c2); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v3, &array[_c2], _ctx); } size = _c1; _res = ap_abstract0_meet_array(man, array, size); _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_meet_lincons_array( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ struct ap_lincons0_array_t *v; /*in*/ ap_abstract0_ptr _res; struct ap_lincons0_array_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); v = &_c1; camlidl_ml2c_lincons0_struct_ap_lincons0_array_t(_v_v, &_c1, _ctx); /* begin user-supplied calling sequence */ _res = ap_abstract0_meet_lincons_array(man,false,a,v); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_meet_tcons_array( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ struct ap_tcons0_array_t *v; /*in*/ ap_abstract0_ptr _res; struct ap_tcons0_array_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); v = &_c1; camlidl_ml2c_tcons0_struct_ap_tcons0_array_t(_v_v, &_c1, _ctx); /* begin user-supplied calling sequence */ _res = ap_abstract0_meet_tcons_array(man,false,a,v); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_join( value _v_man, value _v_a1, value _v_a2) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a1; /*in*/ ap_abstract0_ptr a2; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a1, &a1, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a2, &a2, _ctx); /* begin user-supplied calling sequence */ _res = ap_abstract0_join(man,false,a1,a2); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_join_array( value _v_man, value _v_array) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr *array; /*in*/ unsigned int size; /*in*/ ap_abstract0_ptr _res; mlsize_t _c1; mlsize_t _c2; value _v3; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); _c1 = Wosize_val(_v_array); array = camlidl_malloc(_c1 * sizeof(ap_abstract0_ptr ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_array, _c2); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v3, &array[_c2], _ctx); } size = _c1; _res = ap_abstract0_join_array(man, array, size); _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_add_ray_array( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ struct ap_generator0_array_t *v; /*in*/ ap_abstract0_ptr _res; struct ap_generator0_array_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); v = &_c1; camlidl_ml2c_generator0_struct_ap_generator0_array_t(_v_v, &_c1, _ctx); /* begin user-supplied calling sequence */ _res = ap_abstract0_add_ray_array(man,false,a,v); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_meet_with( value _v_man, value _v_a1, value _v_a2) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a1; /*in*/ ap_abstract0_ptr a2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a1, &a1, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a2, &a2, _ctx); /* begin user-supplied calling sequence */ { ap_abstract0_t* res = ap_abstract0_meet(man,true,a1,a2); *((ap_abstract0_ptr *) Data_custom_val(_v_a1)) = res; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_meet_lincons_array_with( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ struct ap_lincons0_array_t *v; /*in*/ struct ap_lincons0_array_t _c1; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); v = &_c1; camlidl_ml2c_lincons0_struct_ap_lincons0_array_t(_v_v, &_c1, _ctx); /* begin user-supplied calling sequence */ { ap_abstract0_t* res = ap_abstract0_meet_lincons_array(man,true,a,v); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_meet_tcons_array_with( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ struct ap_tcons0_array_t *v; /*in*/ struct ap_tcons0_array_t _c1; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); v = &_c1; camlidl_ml2c_tcons0_struct_ap_tcons0_array_t(_v_v, &_c1, _ctx); /* begin user-supplied calling sequence */ { ap_abstract0_t* res = ap_abstract0_meet_tcons_array(man,true,a,v); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_join_with( value _v_man, value _v_a1, value _v_a2) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a1; /*in*/ ap_abstract0_ptr a2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a1, &a1, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a2, &a2, _ctx); /* begin user-supplied calling sequence */ { ap_abstract0_t* res = ap_abstract0_join(man,true,a1,a2); *((ap_abstract0_ptr *) Data_custom_val(_v_a1)) = res; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_add_ray_array_with( value _v_man, value _v_a, value _v_v) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ struct ap_generator0_array_t *v; /*in*/ struct ap_generator0_array_t _c1; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); v = &_c1; camlidl_ml2c_generator0_struct_ap_generator0_array_t(_v_v, &_c1, _ctx); /* begin user-supplied calling sequence */ { ap_abstract0_t* res = ap_abstract0_add_ray_array(man,true,a,v); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_assign_linexpr_array( value _v_man, value _v_a, value _v_v1, value _v_v2, value _v_dest) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dim_t *v1; /*in*/ ap_linexpr0_ptr *v2; /*in*/ int v3; /*in*/ int v4; /*in*/ ap_abstract0_ptr *dest; /*in*/ ap_abstract0_ptr _res; mlsize_t _c1; mlsize_t _c2; value _v3; mlsize_t _c4; mlsize_t _c5; value _v6; value _v7; ap_abstract0_ptr _c8; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _c1 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c1 * sizeof(ap_dim_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_v1, _c2); camlidl_ml2c_dim_ap_dim_t(_v3, &v1[_c2], _ctx); } v3 = _c1; _c4 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c4 * sizeof(ap_linexpr0_ptr ), _ctx); for (_c5 = 0; _c5 < _c4; _c5++) { _v6 = Field(_v_v2, _c5); camlidl_ml2c_linexpr0_ap_linexpr0_ptr(_v6, &v2[_c5], _ctx); } v4 = _c4; if (_v_dest == Val_int(0)) { dest = NULL; } else { _v7 = Field(_v_dest, 0); dest = &_c8; camlidl_ml2c_abstract0_ap_abstract0_ptr(_v7, &_c8, _ctx); } /* begin user-supplied calling sequence */ if (v3!=v4) caml_failwith("Abstract0.assign_linexpr_array: arrays of different size"); _res = ap_abstract0_assign_linexpr_array(man,false,a,v1,v2,v3,dest==NULL ? NULL : *dest); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_substitute_linexpr_array( value _v_man, value _v_a, value _v_v1, value _v_v2, value _v_dest) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dim_t *v1; /*in*/ ap_linexpr0_ptr *v2; /*in*/ int v3; /*in*/ int v4; /*in*/ ap_abstract0_ptr *dest; /*in*/ ap_abstract0_ptr _res; mlsize_t _c1; mlsize_t _c2; value _v3; mlsize_t _c4; mlsize_t _c5; value _v6; value _v7; ap_abstract0_ptr _c8; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _c1 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c1 * sizeof(ap_dim_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_v1, _c2); camlidl_ml2c_dim_ap_dim_t(_v3, &v1[_c2], _ctx); } v3 = _c1; _c4 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c4 * sizeof(ap_linexpr0_ptr ), _ctx); for (_c5 = 0; _c5 < _c4; _c5++) { _v6 = Field(_v_v2, _c5); camlidl_ml2c_linexpr0_ap_linexpr0_ptr(_v6, &v2[_c5], _ctx); } v4 = _c4; if (_v_dest == Val_int(0)) { dest = NULL; } else { _v7 = Field(_v_dest, 0); dest = &_c8; camlidl_ml2c_abstract0_ap_abstract0_ptr(_v7, &_c8, _ctx); } /* begin user-supplied calling sequence */ if (v3!=v4) caml_failwith("Abstract0.substitute_linexpr_array: arrays of different size"); _res = ap_abstract0_substitute_linexpr_array(man,false,a,v1,v2,v3,dest==NULL ? NULL : *dest); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_assign_texpr_array( value _v_man, value _v_a, value _v_v1, value _v_v2, value _v_dest) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dim_t *v1; /*in*/ ap_texpr0_ptr *v2; /*in*/ int v3; /*in*/ int v4; /*in*/ ap_abstract0_ptr *dest; /*in*/ ap_abstract0_ptr _res; mlsize_t _c1; mlsize_t _c2; value _v3; mlsize_t _c4; mlsize_t _c5; value _v6; value _v7; ap_abstract0_ptr _c8; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _c1 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c1 * sizeof(ap_dim_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_v1, _c2); camlidl_ml2c_dim_ap_dim_t(_v3, &v1[_c2], _ctx); } v3 = _c1; _c4 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c4 * sizeof(ap_texpr0_ptr ), _ctx); for (_c5 = 0; _c5 < _c4; _c5++) { _v6 = Field(_v_v2, _c5); camlidl_ml2c_texpr0_ap_texpr0_ptr(_v6, &v2[_c5], _ctx); } v4 = _c4; if (_v_dest == Val_int(0)) { dest = NULL; } else { _v7 = Field(_v_dest, 0); dest = &_c8; camlidl_ml2c_abstract0_ap_abstract0_ptr(_v7, &_c8, _ctx); } /* begin user-supplied calling sequence */ if (v3!=v4) caml_failwith("Abstract0.assign_texpr_array: arrays of different size"); _res = ap_abstract0_assign_texpr_array(man,false,a,v1,v2,v3,dest==NULL ? NULL : *dest); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_substitute_texpr_array( value _v_man, value _v_a, value _v_v1, value _v_v2, value _v_dest) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dim_t *v1; /*in*/ ap_texpr0_ptr *v2; /*in*/ int v3; /*in*/ int v4; /*in*/ ap_abstract0_ptr *dest; /*in*/ ap_abstract0_ptr _res; mlsize_t _c1; mlsize_t _c2; value _v3; mlsize_t _c4; mlsize_t _c5; value _v6; value _v7; ap_abstract0_ptr _c8; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _c1 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c1 * sizeof(ap_dim_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_v1, _c2); camlidl_ml2c_dim_ap_dim_t(_v3, &v1[_c2], _ctx); } v3 = _c1; _c4 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c4 * sizeof(ap_texpr0_ptr ), _ctx); for (_c5 = 0; _c5 < _c4; _c5++) { _v6 = Field(_v_v2, _c5); camlidl_ml2c_texpr0_ap_texpr0_ptr(_v6, &v2[_c5], _ctx); } v4 = _c4; if (_v_dest == Val_int(0)) { dest = NULL; } else { _v7 = Field(_v_dest, 0); dest = &_c8; camlidl_ml2c_abstract0_ap_abstract0_ptr(_v7, &_c8, _ctx); } /* begin user-supplied calling sequence */ if (v3!=v4) caml_failwith("Abstract0.substitute_texpr_array: arrays of different size"); _res = ap_abstract0_substitute_texpr_array(man,false,a,v1,v2,v3,dest==NULL ? NULL : *dest); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_assign_linexpr_array_with( value _v_man, value _v_a, value _v_v1, value _v_v2, value _v_dest) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dim_t *v1; /*in*/ ap_linexpr0_ptr *v2; /*in*/ int v3; /*in*/ int v4; /*in*/ ap_abstract0_ptr *dest; /*in*/ mlsize_t _c1; mlsize_t _c2; value _v3; mlsize_t _c4; mlsize_t _c5; value _v6; value _v7; ap_abstract0_ptr _c8; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _c1 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c1 * sizeof(ap_dim_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_v1, _c2); camlidl_ml2c_dim_ap_dim_t(_v3, &v1[_c2], _ctx); } v3 = _c1; _c4 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c4 * sizeof(ap_linexpr0_ptr ), _ctx); for (_c5 = 0; _c5 < _c4; _c5++) { _v6 = Field(_v_v2, _c5); camlidl_ml2c_linexpr0_ap_linexpr0_ptr(_v6, &v2[_c5], _ctx); } v4 = _c4; if (_v_dest == Val_int(0)) { dest = NULL; } else { _v7 = Field(_v_dest, 0); dest = &_c8; camlidl_ml2c_abstract0_ap_abstract0_ptr(_v7, &_c8, _ctx); } /* begin user-supplied calling sequence */ if (v3!=v4) caml_failwith("Abstract0.assign_linexpr_array_with: arrays of different size"); { ap_abstract0_t* res = ap_abstract0_assign_linexpr_array(man,true,a,v1,v2,v3,dest==NULL ? NULL : *dest); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_substitute_linexpr_array_with( value _v_man, value _v_a, value _v_v1, value _v_v2, value _v_dest) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dim_t *v1; /*in*/ ap_linexpr0_ptr *v2; /*in*/ int v3; /*in*/ int v4; /*in*/ ap_abstract0_ptr *dest; /*in*/ mlsize_t _c1; mlsize_t _c2; value _v3; mlsize_t _c4; mlsize_t _c5; value _v6; value _v7; ap_abstract0_ptr _c8; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _c1 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c1 * sizeof(ap_dim_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_v1, _c2); camlidl_ml2c_dim_ap_dim_t(_v3, &v1[_c2], _ctx); } v3 = _c1; _c4 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c4 * sizeof(ap_linexpr0_ptr ), _ctx); for (_c5 = 0; _c5 < _c4; _c5++) { _v6 = Field(_v_v2, _c5); camlidl_ml2c_linexpr0_ap_linexpr0_ptr(_v6, &v2[_c5], _ctx); } v4 = _c4; if (_v_dest == Val_int(0)) { dest = NULL; } else { _v7 = Field(_v_dest, 0); dest = &_c8; camlidl_ml2c_abstract0_ap_abstract0_ptr(_v7, &_c8, _ctx); } /* begin user-supplied calling sequence */ if (v3!=v4) caml_failwith("Abstract0.substitute_linexpr_array_with: arrays of different size"); { ap_abstract0_t* res = ap_abstract0_substitute_linexpr_array(man,true,a,v1,v2,v3,dest==NULL ? NULL : *dest); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_assign_texpr_array_with( value _v_man, value _v_a, value _v_v1, value _v_v2, value _v_dest) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dim_t *v1; /*in*/ ap_texpr0_ptr *v2; /*in*/ int v3; /*in*/ int v4; /*in*/ ap_abstract0_ptr *dest; /*in*/ mlsize_t _c1; mlsize_t _c2; value _v3; mlsize_t _c4; mlsize_t _c5; value _v6; value _v7; ap_abstract0_ptr _c8; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _c1 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c1 * sizeof(ap_dim_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_v1, _c2); camlidl_ml2c_dim_ap_dim_t(_v3, &v1[_c2], _ctx); } v3 = _c1; _c4 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c4 * sizeof(ap_texpr0_ptr ), _ctx); for (_c5 = 0; _c5 < _c4; _c5++) { _v6 = Field(_v_v2, _c5); camlidl_ml2c_texpr0_ap_texpr0_ptr(_v6, &v2[_c5], _ctx); } v4 = _c4; if (_v_dest == Val_int(0)) { dest = NULL; } else { _v7 = Field(_v_dest, 0); dest = &_c8; camlidl_ml2c_abstract0_ap_abstract0_ptr(_v7, &_c8, _ctx); } /* begin user-supplied calling sequence */ if (v3!=v4) caml_failwith("Abstract0.assign_texpr_array_with: arrays of different size"); { ap_abstract0_t* res = ap_abstract0_assign_texpr_array(man,true,a,v1,v2,v3,dest==NULL ? NULL : *dest); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_substitute_texpr_array_with( value _v_man, value _v_a, value _v_v1, value _v_v2, value _v_dest) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dim_t *v1; /*in*/ ap_texpr0_ptr *v2; /*in*/ int v3; /*in*/ int v4; /*in*/ ap_abstract0_ptr *dest; /*in*/ mlsize_t _c1; mlsize_t _c2; value _v3; mlsize_t _c4; mlsize_t _c5; value _v6; value _v7; ap_abstract0_ptr _c8; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _c1 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c1 * sizeof(ap_dim_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_v1, _c2); camlidl_ml2c_dim_ap_dim_t(_v3, &v1[_c2], _ctx); } v3 = _c1; _c4 = Wosize_val(_v_v2); v2 = camlidl_malloc(_c4 * sizeof(ap_texpr0_ptr ), _ctx); for (_c5 = 0; _c5 < _c4; _c5++) { _v6 = Field(_v_v2, _c5); camlidl_ml2c_texpr0_ap_texpr0_ptr(_v6, &v2[_c5], _ctx); } v4 = _c4; if (_v_dest == Val_int(0)) { dest = NULL; } else { _v7 = Field(_v_dest, 0); dest = &_c8; camlidl_ml2c_abstract0_ap_abstract0_ptr(_v7, &_c8, _ctx); } /* begin user-supplied calling sequence */ if (v3!=v4) caml_failwith("Abstract0.substitute_texpr_array_with: arrays of different size"); { ap_abstract0_t* res = ap_abstract0_substitute_texpr_array(man,true,a,v1,v2,v3,dest==NULL ? NULL : *dest); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_forget_array( value _v_man, value _v_a, value _v_v1, value _v_v3) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dim_t *v1; /*in*/ int v2; /*in*/ int v3; /*in*/ ap_abstract0_ptr _res; mlsize_t _c1; mlsize_t _c2; value _v3; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _c1 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c1 * sizeof(ap_dim_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_v1, _c2); camlidl_ml2c_dim_ap_dim_t(_v3, &v1[_c2], _ctx); } v2 = _c1; v3 = Int_val(_v_v3); /* begin user-supplied calling sequence */ _res = ap_abstract0_forget_array(man,false,a,v1,v2,v3); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_forget_array_with( value _v_man, value _v_a, value _v_v1, value _v_v3) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dim_t *v1; /*in*/ int v2; /*in*/ int v3; /*in*/ mlsize_t _c1; mlsize_t _c2; value _v3; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _c1 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c1 * sizeof(ap_dim_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_v1, _c2); camlidl_ml2c_dim_ap_dim_t(_v3, &v1[_c2], _ctx); } v2 = _c1; v3 = Int_val(_v_v3); /* begin user-supplied calling sequence */ { ap_abstract0_t* res = ap_abstract0_forget_array(man,true,a,v1,v2,v3); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_add_dimensions( value _v_man, value _v_a, value _v_dimchange, value _v_project) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dimchange_t dimchange; /*in*/ int project; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); camlidl_ml2c_dim_ap_dimchange_t(_v_dimchange, &dimchange, _ctx); project = Int_val(_v_project); /* begin user-supplied calling sequence */ _res = ap_abstract0_add_dimensions(man,false,a,&dimchange, project);ap_dimchange_clear(&dimchange); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_remove_dimensions( value _v_man, value _v_a, value _v_dimchange) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dimchange_t dimchange; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); camlidl_ml2c_dim_ap_dimchange_t(_v_dimchange, &dimchange, _ctx); /* begin user-supplied calling sequence */ _res = ap_abstract0_remove_dimensions(man,false,a,&dimchange);ap_dimchange_clear(&dimchange); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_apply_dimchange2( value _v_man, value _v_a, value _v_dimchange2, value _v_project) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ struct ap_dimchange2_t dimchange2; /*in*/ int project; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); camlidl_ml2c_dim_struct_ap_dimchange2_t(_v_dimchange2, &dimchange2, _ctx); project = Int_val(_v_project); /* begin user-supplied calling sequence */ _res = ap_abstract0_apply_dimchange2(man,false,a,&dimchange2,project); if (dimchange2.add) ap_dimchange_clear(dimchange2.add); if (dimchange2.remove) ap_dimchange_clear(dimchange2.remove); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_permute_dimensions( value _v_man, value _v_a, value _v_perm) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ struct ap_dimperm_t *perm; /*in*/ ap_abstract0_ptr _res; struct ap_dimperm_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); perm = &_c1; camlidl_ml2c_dim_struct_ap_dimperm_t(_v_perm, &_c1, _ctx); /* begin user-supplied calling sequence */ _res = ap_abstract0_permute_dimensions(man,false,a,perm); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_add_dimensions_with( value _v_man, value _v_a, value _v_dimchange, value _v_v1) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dimchange_t dimchange; /*in*/ int v1; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); camlidl_ml2c_dim_ap_dimchange_t(_v_dimchange, &dimchange, _ctx); v1 = Int_val(_v_v1); /* begin user-supplied calling sequence */ { ap_abstract0_t* res = ap_abstract0_add_dimensions(man,true,a,&dimchange,v1); ap_dimchange_clear(&dimchange); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_remove_dimensions_with( value _v_man, value _v_a, value _v_dimchange) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dimchange_t dimchange; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); camlidl_ml2c_dim_ap_dimchange_t(_v_dimchange, &dimchange, _ctx); /* begin user-supplied calling sequence */ { ap_abstract0_t* res = ap_abstract0_remove_dimensions(man,true,a,&dimchange); ap_dimchange_clear(&dimchange); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_apply_dimchange2_with( value _v_man, value _v_a, value _v_dimchange2, value _v_project) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ struct ap_dimchange2_t dimchange2; /*in*/ int project; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); camlidl_ml2c_dim_struct_ap_dimchange2_t(_v_dimchange2, &dimchange2, _ctx); project = Int_val(_v_project); /* begin user-supplied calling sequence */ ap_abstract0_t* res = ap_abstract0_apply_dimchange2(man,true,a,&dimchange2,project); ap_dimchange2_clear(&dimchange2); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res; /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_permute_dimensions_with( value _v_man, value _v_a, value _v_perm) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ struct ap_dimperm_t *perm; /*in*/ value _v1; struct ap_dimperm_t _c2; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); if (_v_perm == Val_int(0)) { perm = NULL; } else { _v1 = Field(_v_perm, 0); perm = &_c2; camlidl_ml2c_dim_struct_ap_dimperm_t(_v1, &_c2, _ctx); } /* begin user-supplied calling sequence */ { ap_abstract0_t* res = ap_abstract0_permute_dimensions(man,true,a,perm); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_expand( value _v_man, value _v_a, value _v_v1, value _v_v2) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dim_t v1; /*in*/ int v2; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); camlidl_ml2c_dim_ap_dim_t(_v_v1, &v1, _ctx); v2 = Int_val(_v_v2); /* begin user-supplied calling sequence */ _res = ap_abstract0_expand(man,false,a,v1,v2); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_fold( value _v_man, value _v_a, value _v_v1) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dim_t *v1; /*in*/ int v2; /*in*/ ap_abstract0_ptr _res; mlsize_t _c1; mlsize_t _c2; value _v3; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _c1 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c1 * sizeof(ap_dim_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_v1, _c2); camlidl_ml2c_dim_ap_dim_t(_v3, &v1[_c2], _ctx); } v2 = _c1; /* begin user-supplied calling sequence */ _res = ap_abstract0_fold(man,false,a,v1,v2); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_expand_with( value _v_man, value _v_a, value _v_v1, value _v_v2) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dim_t v1; /*in*/ int v2; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); camlidl_ml2c_dim_ap_dim_t(_v_v1, &v1, _ctx); v2 = Int_val(_v_v2); /* begin user-supplied calling sequence */ { ap_abstract0_t* res = ap_abstract0_expand(man,true,a,v1,v2); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_fold_with( value _v_man, value _v_a, value _v_v1) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_dim_t *v1; /*in*/ int v2; /*in*/ mlsize_t _c1; mlsize_t _c2; value _v3; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); _c1 = Wosize_val(_v_v1); v1 = camlidl_malloc(_c1 * sizeof(ap_dim_t ), _ctx); for (_c2 = 0; _c2 < _c1; _c2++) { _v3 = Field(_v_v1, _c2); camlidl_ml2c_dim_ap_dim_t(_v3, &v1[_c2], _ctx); } v2 = _c1; /* begin user-supplied calling sequence */ { ap_abstract0_t* res = ap_abstract0_fold(man,true,a,v1,v2); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } value camlidl_abstract0_ap_abstract0_widening( value _v_man, value _v_a1, value _v_a2) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a1; /*in*/ ap_abstract0_ptr a2; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a1, &a1, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a2, &a2, _ctx); _res = ap_abstract0_widening(man, a1, a2); _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_widening_threshold( value _v_man, value _v_a1, value _v_a2, value _v_v) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a1; /*in*/ ap_abstract0_ptr a2; /*in*/ struct ap_lincons0_array_t *v; /*in*/ ap_abstract0_ptr _res; struct ap_lincons0_array_t _c1; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a1, &a1, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a2, &a2, _ctx); v = &_c1; camlidl_ml2c_lincons0_struct_ap_lincons0_array_t(_v_v, &_c1, _ctx); _res = ap_abstract0_widening_threshold(man, a1, a2, v); _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_closure( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); /* begin user-supplied calling sequence */ _res = ap_abstract0_closure(man,false,a); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } value camlidl_abstract0_ap_abstract0_closure_with( value _v_man, value _v_a) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr a; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_a, &a, _ctx); /* begin user-supplied calling sequence */ { ap_abstract0_t* res = ap_abstract0_closure(man,true,a); *((ap_abstract0_ptr *) Data_custom_val(_v_a)) = res; } /* end user-supplied calling sequence */ camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return Val_unit; } apron-dist-0.9.10/apron/mlapronidl/tcons0.idl0000640014525101416610000000757210644461001020734 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(MLI,"(** APRON tree expressions constraints of level 0 *)") quote(C, "\n\ #include \n\ #include \"ap_lincons0.h\"\n\ #include \"ap_texpr0.h\"\n\ #include \"apron_caml.h\"\n\ \n\ ") import "scalar.idl"; import "interval.idl"; import "coeff.idl"; import "dim.idl"; import "lincons0.idl"; import "texpr0.idl"; /* For ap_tcons0_t, - the conversion from ML to C may use allocation, but it is automatically freed by Camlidl mechanisms - the conversion from C to ML free after conversion the scalar field in the C structure. the C type should NOT be deallocated */ quote(C,"\n\ void camlidl_apron_tcons0_ml2c(value v,ap_tcons0_t* cons, camlidl_ctx _ctx)\n\ {\n\ value _v_texpr0;\n\ value _v_constyp;\n\ value _v_scalar;\n\ \n\ _v_texpr0 = Field(v,0);\n\ camlidl_apron_texpr0_ptr_ml2c(_v_texpr0,&cons->texpr0);\n\ _v_constyp = Field(v,1);\n\ if (Is_long(_v_constyp)){\n\ switch (Int_val(_v_constyp)){ case 0:\n\ case 1:\n\ case 2:\n\ cons->constyp = Int_val(_v_constyp);\n\ break;\n\ case 3:\n\ cons->constyp = 4;\n\ break;\n\ default:\n\ abort();\n\ }\n\ cons->scalar = NULL;\n\ }\n\ else {\n\ switch (Tag_val(_v_constyp)){\n\ case 0:\n\ cons->constyp = AP_CONS_EQMOD;\n\ _v_scalar = Field(_v_constyp,0);\n\ cons->scalar = (ap_scalar_t *)camlidl_malloc(sizeof(ap_scalar_t),_ctx);\n\ camlidl_apron_scalar_ml2c(_v_scalar,cons->scalar);\n\ break;\n\ default:\n\ abort();\n\ }\n\ }\n\ }\n\ value camlidl_apron_tcons0_c2ml(ap_tcons0_t* cons)\n\ {\n\ value vres;\n\ value _v[3];\n\ _v[0] = _v[1] = _v[2] = 0;\n\ \n\ Begin_roots_block(_v, 3)\n\ _v[0] = camlidl_apron_texpr0_ptr_c2ml(&cons->texpr0);\n\ switch(cons->constyp){\n\ case AP_CONS_EQ:\n\ case AP_CONS_SUPEQ:\n\ case AP_CONS_SUP:\n\ _v[1] = Val_int(cons->constyp);\n\ break;\n\ case AP_CONS_DISEQ:\n\ _v[1] = Val_int(3);\n\ break;\n\ case AP_CONS_EQMOD:\n\ assert(cons->scalar!=NULL);\n\ _v[2] = camlidl_apron_scalar_c2ml(cons->scalar);\n\ _v[1] = camlidl_alloc_small(1, 0);\n\ Field(_v[1],0) = _v[2];\n\ ap_scalar_free(cons->scalar); cons->scalar = NULL;\n\ break;\n\ }\n\ vres = camlidl_alloc_small(2, 0);\n\ Field(vres, 0) = _v[0];\n\ Field(vres, 1) = _v[1];\n\ End_roots()\n\ return vres;\n\ }\n\ ") typedef [mltype("{\n mutable texpr0 : Texpr0.t;\n mutable typ : Lincons0.typ;\n}"), abstract, ml2c(camlidl_apron_tcons0_ml2c), c2ml(camlidl_apron_tcons0_c2ml)] struct ap_tcons0_t ap_tcons0_t; quote(MLMLI,"\n\ type typ = Lincons0.typ =\n\ | EQ\n\ | SUPEQ\n\ | SUP\n\ | DISEQ\n\ | EQMOD of Scalar.t\n\ ") struct ap_tcons0_array_t { [size_is(size)] ap_tcons0_t* p; int size; }; quote(MLI,"\n\ (** Make a tree expression constraint. Modifying later the tree expression expression\n\ modifies correspondingly the tree expression constraint and conversely *)\n\ val make : Texpr0.t -> typ -> t\n\ \n\ (** Copy a tree expression constraint (deep copy) *)\n\ val copy : t -> t\n\ \n\ (** Convert a constraint type to a string ([=],[>=], or [>]) *)\n\ val string_of_typ : typ -> string\n\ \n\ (** Print a constraint *)\n\ val print : (Dim.t -> string) -> Format.formatter -> t -> unit\n\ ") quote(ML,"\n\ let string_of_typ = Lincons0.string_of_typ\n\ \n\ let print assoc fmt cons = \n\ Texpr0.print assoc fmt cons.texpr0;\n\ Format.fprintf fmt \" %s 0\" (string_of_typ cons.typ);\n\ begin match cons.typ with\n\ | EQMOD x -> Format.fprintf fmt \" mod %a\" Scalar.print x;\n\ | _ -> ()\n\ end;\n\ ()\n\ let make expr typ = {\n\ texpr0 = expr; typ = typ \n\ }\n\ let copy cons = {\n\ texpr0 = Texpr0.copy cons.texpr0; typ = cons.typ\n\ }\n\ ") apron-dist-0.9.10/apron/mlapronidl/var_caml.c0000640014525101416610000000422711252216516020763 0ustar bjeannetpopart/* File generated from var.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include "apron_caml.h" #define camlidl_ml2c_var_ap_var_t(v,c,ctx) camlidl_apron_var_ptr_ml2c(v,c) #define camlidl_c2ml_var_ap_var_t(c,ctx) camlidl_apron_var_ptr_c2ml(c) value camlidl_var_ap_var_of_string( value _v_name) { char *name; /*in*/ ap_var_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; name = String_val(_v_name); _res = ap_var_of_string(name); _vres = camlidl_c2ml_var_ap_var_t(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_var_ap_var_compare( value _v_var1, value _v_var2) { ap_var_t var1; /*in*/ ap_var_t var2; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_var_ap_var_t(_v_var1, &var1, _ctx); camlidl_ml2c_var_ap_var_t(_v_var2, &var2, _ctx); _res = ap_var_compare(var1, var2); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_var_ap_var_to_string( value _v_var) { ap_var_t var; /*in*/ char *_res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_var_ap_var_t(_v_var, &var, _ctx); /* begin user-supplied calling sequence */ _res = ((apron_var_ptr)var)->name; /* end user-supplied calling sequence */ _vres = copy_string(_res); camlidl_free(_ctx); return _vres; } value camlidl_var_ap_var_hash( value _v_var) { ap_var_t var; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_var_ap_var_t(_v_var, &var, _ctx); _res = ap_var_hash(var); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } apron-dist-0.9.10/apron/mlapronidl/var.ml0000640014525101416610000000127311252216516020153 0ustar bjeannetpopart(* File generated from var.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t (** APRON Variables *) external of_string : string -> t = "camlidl_var_ap_var_of_string" external compare : t -> t -> int = "camlidl_var_ap_var_compare" external to_string : t -> string = "camlidl_var_ap_var_to_string" external hash : t -> int = "camlidl_var_ap_var_hash" let print fmt v = Format.pp_print_string fmt (to_string v) (** Initialisation of abstract type operations in C library *) external set_var_operations : unit -> unit = "camlidl_apron_set_var_operations" let _ = set_var_operations () apron-dist-0.9.10/apron/mlapronidl/interval_caml.c0000640014525101416610000000640411252216515022015 0ustar bjeannetpopart/* File generated from interval.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include #include "ap_coeff.h" #include "apron_caml.h" extern void camlidl_apron_scalar_ml2c(value, ap_scalar_t *); #define camlidl_ml2c_scalar_ap_scalar_t(v,c,ctx) camlidl_apron_scalar_ml2c(v,c) extern value camlidl_apron_scalar_c2ml(ap_scalar_t *); #define camlidl_c2ml_scalar_ap_scalar_t(c,ctx) camlidl_apron_scalar_c2ml(c) extern void camlidl_ml2c_scalar_ap_scalar_ptr(value, ap_scalar_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_ap_scalar_ptr(ap_scalar_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_scalar_struct_ap_scalar_array_t(value, struct ap_scalar_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_struct_ap_scalar_array_t(struct ap_scalar_array_t *, camlidl_ctx _ctx); void camlidl_ml2c_interval_struct_ap_interval_t(value _v1, struct ap_interval_t * _c2, camlidl_ctx _ctx) { value _v3; value _v4; _v3 = Field(_v1, 0); (*_c2).inf = (ap_scalar_t *) camlidl_malloc(sizeof(ap_scalar_t ), _ctx); camlidl_ml2c_scalar_ap_scalar_t(_v3, &*(*_c2).inf, _ctx); _v4 = Field(_v1, 1); (*_c2).sup = (ap_scalar_t *) camlidl_malloc(sizeof(ap_scalar_t ), _ctx); camlidl_ml2c_scalar_ap_scalar_t(_v4, &*(*_c2).sup, _ctx); } value camlidl_c2ml_interval_struct_ap_interval_t(struct ap_interval_t * _c1, camlidl_ctx _ctx) { value _v2; value _v3[2]; _v3[0] = _v3[1] = 0; Begin_roots_block(_v3, 2) _v3[0] = camlidl_c2ml_scalar_ap_scalar_t(&*(*_c1).inf, _ctx); _v3[1] = camlidl_c2ml_scalar_ap_scalar_t(&*(*_c1).sup, _ctx); _v2 = camlidl_alloc_small(2, 0); Field(_v2, 0) = _v3[0]; Field(_v2, 1) = _v3[1]; End_roots() return _v2; } void camlidl_ml2c_interval_ap_interval_ptr(value _v1, ap_interval_ptr * _c2, camlidl_ctx _ctx) { (*_c2) = (struct ap_interval_t *) camlidl_malloc(sizeof(struct ap_interval_t ), _ctx); camlidl_ml2c_interval_struct_ap_interval_t(_v1, &*(*_c2), _ctx); } value camlidl_c2ml_interval_ap_interval_ptr(ap_interval_ptr * _c2, camlidl_ctx _ctx) { value _v1; _v1 = camlidl_c2ml_interval_struct_ap_interval_t(&*(*_c2), _ctx); return _v1; } void camlidl_ml2c_interval_struct_ap_interval_array_t(value _v1, struct ap_interval_array_t * _c2, camlidl_ctx _ctx) { mlsize_t _c3; mlsize_t _c4; value _v5; _c3 = Wosize_val(_v1); (*_c2).p = camlidl_malloc(_c3 * sizeof(ap_interval_ptr ), _ctx); for (_c4 = 0; _c4 < _c3; _c4++) { _v5 = Field(_v1, _c4); camlidl_ml2c_interval_ap_interval_ptr(_v5, &(*_c2).p[_c4], _ctx); } (*_c2).size = _c3; } value camlidl_c2ml_interval_struct_ap_interval_array_t(struct ap_interval_array_t * _c1, camlidl_ctx _ctx) { value _v2; mlsize_t _c3; value _v4; _v2 = camlidl_alloc((*_c1).size, 0); Begin_root(_v2) for (_c3 = 0; _c3 < (*_c1).size; _c3++) { _v4 = camlidl_c2ml_interval_ap_interval_ptr(&(*_c1).p[_c3], _ctx); modify(&Field(_v2, _c3), _v4); } End_roots() return _v2; } apron-dist-0.9.10/apron/mlapronidl/lincons0.mli0000640014525101416610000000141311252216515021254 0ustar bjeannetpopart(* File generated from lincons0.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = { mutable linexpr0 : Linexpr0.t; mutable typ : typ; } (** APRON Linear constraints of level 0 *) and typ = | EQ | SUPEQ | SUP | DISEQ | EQMOD of Scalar.t (** Make a linear constraint. Modifying later the linear expression modifies correspondingly the linear constraint and conversely *) val make : Linexpr0.t -> typ -> t (** Copy a linear constraint (deep copy) *) val copy : t -> t (** Convert a constraint type to a string ([=],[>=], or [>]) *) val string_of_typ : typ -> string (** Print a constraint *) val print : (Dim.t -> string) -> Format.formatter -> t -> unit apron-dist-0.9.10/apron/mlapronidl/mpz.idl0000777014525101416610000000000011252510553032605 2/scratch/home/bjeannet/pkg/mlgmpidl/linux386/lib/mpz.idlustar bjeannetpopartapron-dist-0.9.10/apron/mlapronidl/texpr0.mli0000640014525101416610000000555011252216515020757 0ustar bjeannetpopart(* File generated from texpr0.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t and unop = | Neg | Cast | Sqrt (** *) (** Unary operators *) and binop = | Add | Sub | Mul | Div | Mod (** *) (** Binary operators *) and typ = | Real | Int | Single | Double | Extended | Quad (** *) (** Destination type for rounding *) and round = | Near | Zero | Up | Down | Rnd (** *) (** Rounding direction *) (** APRON tree expressions of level 0 *) (** User type for tree expressions *) type expr = | Cst of Coeff.t | Dim of Dim.t | Unop of unop * expr * typ * round | Binop of binop * expr * expr * typ * round (** {2 Constructors and Destructor} *) (** General constructor (actually the most efficient *) external of_expr : expr -> t = "camlidl_texpr0_ap_texpr0_of_expr" (** Copy *) external copy : t -> t = "camlidl_texpr0_ap_texpr0_copy" (** Conversion *) external of_linexpr : Linexpr0.t -> t = "camlidl_texpr0_ap_texpr0_of_linexpr" (** General destructor *) external to_expr : t -> expr = "camlidl_texpr0_ap_texpr0_to_expr" (** {3 Incremental constructors} *) external cst : Coeff.t -> t = "camlidl_texpr0_ap_texpr0_cst" external dim : Dim.t -> t = "camlidl_texpr0_ap_texpr0_dim" external unop : unop -> t -> typ -> round -> t = "camlidl_texpr0_ap_texpr0_unop" external binop : binop -> typ -> round -> t -> t -> t = "camlidl_texpr0_ap_texpr0_binop" (** {2 Tests} *) external is_interval_cst : t -> bool = "camlidl_texpr0_ap_texpr0_is_interval_cst" external is_interval_linear : t -> bool = "camlidl_texpr0_ap_texpr0_is_interval_linear" external is_interval_polynomial : t -> bool = "camlidl_texpr0_ap_texpr0_is_interval_polynomial" external is_interval_polyfrac : t -> bool = "camlidl_texpr0_ap_texpr0_is_interval_polyfrac" external is_scalar : t -> bool = "camlidl_texpr0_ap_texpr0_is_scalar" (** {2 Printing} *) val string_of_unop : unop -> string val string_of_binop : binop -> string val string_of_typ : typ -> string val string_of_round : round -> string val print_unop : Format.formatter -> unop -> unit val print_binop : Format.formatter -> binop -> unit val print_typ : Format.formatter -> typ -> unit val print_round : Format.formatter -> round -> unit val print_expr : (Dim.t -> string) -> Format.formatter -> expr -> unit (** Print a tree expression, using a function converting from dimensions to names *) val print : (Dim.t -> string) -> Format.formatter -> t -> unit (** Print an abstract tree expression, using a function converting from dimensions to names *) (** {2 Internal usage for level 1} *) val print_sprint_unop : unop -> typ -> round -> string val print_sprint_binop : binop -> typ -> round -> string val print_precedence_of_unop : unop -> int val print_precedence_of_binop : binop -> int apron-dist-0.9.10/apron/mlapronidl/abstract0.mli0000640014525101416610000004243511252216516021424 0ustar bjeannetpopart(* File generated from abstract0.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type 'a t (** APRON Abstract value of level 0 *) (** The type parameter ['a] allows to distinguish abstract values with different underlying abstract domains. *) (** TO BE DOCUMENTED *) external set_gc : int -> unit = "camlidl_abstract0_ap_abstract0_set_gc" (* ********************************************************************** *) (** {2 General management} *) (* ********************************************************************** *) (* ============================================================ *) (** {3 Memory} *) (* ============================================================ *) (** Copy a value *) external copy : 'a Manager.t -> 'a t -> 'a t = "camlidl_abstract0_ap_abstract0_copy" (** Return the abstract size of a value *) external size : 'a Manager.t -> 'a t -> int = "camlidl_abstract0_ap_abstract0_size" (* ============================================================ *) (** {3 Control of internal representation} *) (* ============================================================ *) (** Minimize the size of the representation of the value. This may result in a later recomputation of internal information.*) external minimize : 'a Manager.t -> 'a t -> unit = "camlidl_abstract0_ap_abstract0_minimize" (** Put the abstract value in canonical form. (not yet clear definition) *) external canonicalize : 'a Manager.t -> 'a t -> unit = "camlidl_abstract0_ap_abstract0_canonicalize" external hash : 'a Manager.t -> 'a t -> int = "camlidl_abstract0_ap_abstract0_hash" (** [approximate man abs alg] perform some transformation on the abstract value, guided by the argument [alg]. The transformation may lose information. The argument [alg] overrides the field algorithm of the structure of type [Manager.funopt] associated to ap_abstract0_approximate (commodity feature).*) external approximate : 'a Manager.t -> 'a t -> int -> unit = "camlidl_abstract0_ap_abstract0_approximate" (* ============================================================ *) (** {3 Printing} *) (* ============================================================ *) (** Dump on the [stdout] C stream the internal representation of an abstract value, for debugging purposes *) external fdump : 'a Manager.t -> 'a t -> unit = "camlidl_abstract0_ap_abstract0_fdump" (** Print as a set of constraints *) val print: (int -> string) -> Format.formatter -> 'a t -> unit (* ============================================================ *) (** {3 Serialization} *) (* ============================================================ *) (* ********************************************************************** *) (** {2 Constructor, accessors, tests and property extraction} *) (* ********************************************************************** *) (* ============================================================ *) (** {3 Basic constructors} *) (* ============================================================ *) (** Create a bottom (empty) value with the given number of integer and real variables *) external bottom : 'a Manager.t -> int -> int -> 'a t = "camlidl_abstract0_ap_abstract0_bottom" (** Create a top (universe) value with the given number of integer and real variables *) external top : 'a Manager.t -> int -> int -> 'a t = "camlidl_abstract0_ap_abstract0_top" (** Abstract an hypercube. [of_box man intdim realdim array] abstracts an hypercube defined by the array of intervals of size [intdim+realdim] *) external of_box : 'a Manager.t -> int -> int -> Interval.t array -> 'a t = "camlidl_abstract0_ap_abstract0_of_box" (* ============================================================ *) (** {3 Accessors} *) (* ============================================================ *) external dimension : 'a Manager.t -> 'a t -> Dim.dimension = "camlidl_abstract0_ap_abstract0_dimension" external manager : 'a t -> 'a Manager.t = "camlidl_abstract0_ap_abstract0_manager" (* ============================================================ *) (** {3 Tests} *) (* ============================================================ *) (** Emptiness test *) external is_bottom : 'a Manager.t -> 'a t -> bool = "camlidl_abstract0_ap_abstract0_is_bottom" (** Universality test *) external is_top : 'a Manager.t -> 'a t -> bool = "camlidl_abstract0_ap_abstract0_is_top" (** Inclusion test. The 2 abstract values should be compatible. *) external is_leq : 'a Manager.t -> 'a t -> 'a t -> bool = "camlidl_abstract0_ap_abstract0_is_leq" (** Equality test. The 2 abstract values should be compatible. *) external is_eq : 'a Manager.t -> 'a t -> 'a t -> bool = "camlidl_abstract0_ap_abstract0_is_eq" (** Does the abstract value satisfy the linear constraint ? *) external sat_lincons : 'a Manager.t -> 'a t -> Lincons0.t -> bool = "camlidl_abstract0_ap_abstract0_sat_lincons" (** Does the abstract value satisfy the tree expression constraint ? *) external sat_tcons : 'a Manager.t -> 'a t -> Tcons0.t -> bool = "camlidl_abstract0_ap_abstract0_sat_tcons" (** Does the abstract value satisfy the constraint [dim in interval] ? *) external sat_interval : 'a Manager.t -> 'a t -> Dim.t -> Interval.t -> bool = "camlidl_abstract0_ap_abstract0_sat_interval" (** Is the dimension unconstrained in the abstract value ? If yes, this means that the existential quantification of the dimension does not change the value. *) external is_dimension_unconstrained : 'a Manager.t -> 'a t -> Dim.t -> bool = "camlidl_abstract0_ap_abstract0_is_dimension_unconstrained" (* ============================================================ *) (** {3 Extraction of properties} *) (* ============================================================ *) (** Return the interval of variation of the dimension in the abstract value. *) external bound_dimension : 'a Manager.t -> 'a t -> Dim.t -> Interval.t = "camlidl_abstract0_ap_abstract0_bound_dimension" (** Return the interval of variation of the linear expression in the abstract value. Implement a form of linear programming, where the argument linear expression is the one to optimize under the constraints induced by the abstract value. *) external bound_linexpr : 'a Manager.t -> 'a t -> Linexpr0.t -> Interval.t = "camlidl_abstract0_ap_abstract0_bound_linexpr" (** Return the interval of variation of the tree expression in the abstract value. *) external bound_texpr : 'a Manager.t -> 'a t -> Texpr0.t -> Interval.t = "camlidl_abstract0_ap_abstract0_bound_texpr" (** Convert the abstract value to an hypercube *) external to_box : 'a Manager.t -> 'a t -> Interval.t array = "camlidl_abstract0_ap_abstract0_to_box" (** Convert the abstract value to a conjunction of linear constraints. *) external to_lincons_array : 'a Manager.t -> 'a t -> Lincons0.t array = "camlidl_abstract0_ap_abstract0_to_lincons_array" (** Convert the abstract value to a conjunction of tree expression constraints. *) external to_tcons_array : 'a Manager.t -> 'a t -> Tcons0.t array = "camlidl_abstract0_ap_abstract0_to_tcons_array" (** Convert the abstract value to a set of generators that defines it. *) external to_generator_array : 'a Manager.t -> 'a t -> Generator0.t array = "camlidl_abstract0_ap_abstract0_to_generator_array" (* ********************************************************************** *) (** {2 Operations} *) (* ********************************************************************** *) (* ============================================================ *) (** {3 Meet and Join} *) (* ============================================================ *) (** Meet of 2 abstract values. *) external meet : 'a Manager.t -> 'a t -> 'a t -> 'a t = "camlidl_abstract0_ap_abstract0_meet" (** Meet of a non empty array of abstract values. *) external meet_array : 'a Manager.t -> 'a t array -> 'a t = "camlidl_abstract0_ap_abstract0_meet_array" (** Meet of an abstract value with an array of linear constraints. *) external meet_lincons_array : 'a Manager.t -> 'a t -> Lincons0.t array -> 'a t = "camlidl_abstract0_ap_abstract0_meet_lincons_array" (** Meet of an abstract value with an array of tree expression constraints. *) external meet_tcons_array : 'a Manager.t -> 'a t -> Tcons0.t array -> 'a t = "camlidl_abstract0_ap_abstract0_meet_tcons_array" (** Join of 2 abstract values. *) external join : 'a Manager.t -> 'a t -> 'a t -> 'a t = "camlidl_abstract0_ap_abstract0_join" (** Join of a non empty array of abstract values. *) external join_array : 'a Manager.t -> 'a t array -> 'a t = "camlidl_abstract0_ap_abstract0_join_array" (** Add the array of generators to the abstract value (time elapse operator). The generators should either lines or rays, not vertices. *) external add_ray_array : 'a Manager.t -> 'a t -> Generator0.t array -> 'a t = "camlidl_abstract0_ap_abstract0_add_ray_array" (** {5 Side-effect versions of the previous functions} *) external meet_with : 'a Manager.t -> 'a t -> 'a t -> unit = "camlidl_abstract0_ap_abstract0_meet_with" external meet_lincons_array_with : 'a Manager.t -> 'a t -> Lincons0.t array -> unit = "camlidl_abstract0_ap_abstract0_meet_lincons_array_with" external meet_tcons_array_with : 'a Manager.t -> 'a t -> Tcons0.t array -> unit = "camlidl_abstract0_ap_abstract0_meet_tcons_array_with" external join_with : 'a Manager.t -> 'a t -> 'a t -> unit = "camlidl_abstract0_ap_abstract0_join_with" external add_ray_array_with : 'a Manager.t -> 'a t -> Generator0.t array -> unit = "camlidl_abstract0_ap_abstract0_add_ray_array_with" (* ============================================================ *) (** {3 Assignements and Substitutions} *) (* ============================================================ *) (** Parallel assignement of an array of dimensions by an array of same size of linear expressions *) external assign_linexpr_array : 'a Manager.t -> 'a t -> Dim.t array -> Linexpr0.t array -> 'a t option -> 'a t = "camlidl_abstract0_ap_abstract0_assign_linexpr_array" (** Parallel substitution of an array of dimensions by an array of same size of linear expressions *) external substitute_linexpr_array : 'a Manager.t -> 'a t -> Dim.t array -> Linexpr0.t array -> 'a t option -> 'a t = "camlidl_abstract0_ap_abstract0_substitute_linexpr_array" (** Parallel assignement of an array of dimensions by an array of same size of tree expressions *) external assign_texpr_array : 'a Manager.t -> 'a t -> Dim.t array -> Texpr0.t array -> 'a t option -> 'a t = "camlidl_abstract0_ap_abstract0_assign_texpr_array" (** Parallel substitution of an array of dimensions by an array of same size of tree expressions *) external substitute_texpr_array : 'a Manager.t -> 'a t -> Dim.t array -> Texpr0.t array -> 'a t option -> 'a t = "camlidl_abstract0_ap_abstract0_substitute_texpr_array" (** {5 Side-effect versions of the previous functions} *) external assign_linexpr_array_with : 'a Manager.t -> 'a t -> Dim.t array -> Linexpr0.t array -> 'a t option -> unit = "camlidl_abstract0_ap_abstract0_assign_linexpr_array_with" external substitute_linexpr_array_with : 'a Manager.t -> 'a t -> Dim.t array -> Linexpr0.t array -> 'a t option -> unit = "camlidl_abstract0_ap_abstract0_substitute_linexpr_array_with" external assign_texpr_array_with : 'a Manager.t -> 'a t -> Dim.t array -> Texpr0.t array -> 'a t option -> unit = "camlidl_abstract0_ap_abstract0_assign_texpr_array_with" external substitute_texpr_array_with : 'a Manager.t -> 'a t -> Dim.t array -> Texpr0.t array -> 'a t option -> unit = "camlidl_abstract0_ap_abstract0_substitute_texpr_array_with" (* ============================================================ *) (** {3 Projections} *) (* ============================================================ *) (** These functions implements forgeting (existential quantification) of (array of) dimensions. Both functional and side-effect versions are provided. The Boolean, if true, adds a projection onto 0-plane. *) external forget_array : 'a Manager.t -> 'a t -> Dim.t array -> bool -> 'a t = "camlidl_abstract0_ap_abstract0_forget_array" external forget_array_with : 'a Manager.t -> 'a t -> Dim.t array -> bool -> unit = "camlidl_abstract0_ap_abstract0_forget_array_with" (* ============================================================ *) (** {3 Change and permutation of dimensions} *) (* ============================================================ *) external add_dimensions : 'a Manager.t -> 'a t -> Dim.change -> bool -> 'a t = "camlidl_abstract0_ap_abstract0_add_dimensions" external remove_dimensions : 'a Manager.t -> 'a t -> Dim.change -> 'a t = "camlidl_abstract0_ap_abstract0_remove_dimensions" external apply_dimchange2 : 'a Manager.t -> 'a t -> Dim.change2 -> bool -> 'a t = "camlidl_abstract0_ap_abstract0_apply_dimchange2" external permute_dimensions : 'a Manager.t -> 'a t -> Dim.perm -> 'a t = "camlidl_abstract0_ap_abstract0_permute_dimensions" (** {5 Side-effect versions of the previous functions} *) external add_dimensions_with : 'a Manager.t -> 'a t -> Dim.change -> bool -> unit = "camlidl_abstract0_ap_abstract0_add_dimensions_with" external remove_dimensions_with : 'a Manager.t -> 'a t -> Dim.change -> unit = "camlidl_abstract0_ap_abstract0_remove_dimensions_with" external apply_dimchange2_with : 'a Manager.t -> 'a t -> Dim.change2 -> bool -> unit = "camlidl_abstract0_ap_abstract0_apply_dimchange2_with" external permute_dimensions_with : 'a Manager.t -> 'a t -> Dim.perm option -> unit = "camlidl_abstract0_ap_abstract0_permute_dimensions_with" (* ============================================================ *) (** {3 Expansion and folding of dimensions} *) (* ============================================================ *) (** These functions allows to expand one dimension into several ones having the same properties with respect to the other dimensions, and to fold several dimensions into one. Formally, - expand P(x,y,z) z w = P(x,y,z) inter P(x,y,w) if z is expanded in z and w - fold Q(x,y,z,w) z w = exists w:Q(x,y,z,w) union (exist z:Q(x,y,z,w))(z<-w) if z and w are folded onto z *) (** Expansion: [expand a dim n] expands the dimension [dim] into itself + [n] additional dimensions. It results in (n+1) unrelated dimensions having same relations with other dimensions. The (n+1) dimensions are put as follows: - original dimension [dim] - if the dimension is integer, the n additional dimensions are put at the end of integer dimensions; if it is real, at the end of the real dimensions. *) external expand : 'a Manager.t -> 'a t -> Dim.t -> int -> 'a t = "camlidl_abstract0_ap_abstract0_expand" (** Folding: [fold a tdim] fold the dimensions in the array [tdim] of size n>=1 and put the result in the first dimension of the array. The other dimensions of the array are then removed (using ap_abstract0_permute_remove_dimensions). *) external fold : 'a Manager.t -> 'a t -> Dim.t array -> 'a t = "camlidl_abstract0_ap_abstract0_fold" external expand_with : 'a Manager.t -> 'a t -> Dim.t -> int -> unit = "camlidl_abstract0_ap_abstract0_expand_with" external fold_with : 'a Manager.t -> 'a t -> Dim.t array -> unit = "camlidl_abstract0_ap_abstract0_fold_with" (* ============================================================ *) (** {3 Widening} *) (* ============================================================ *) (** Widening *) external widening : 'a Manager.t -> 'a t -> 'a t -> 'a t = "camlidl_abstract0_ap_abstract0_widening" external widening_threshold : 'a Manager.t -> 'a t -> 'a t -> Lincons0.t array -> 'a t = "camlidl_abstract0_ap_abstract0_widening_threshold" (* ============================================================ *) (** {3 Closure operation} *) (* ============================================================ *) (** Closure: transform strict constraints into non-strict ones.*) external closure : 'a Manager.t -> 'a t -> 'a t = "camlidl_abstract0_ap_abstract0_closure" (** Side-effect version *) external closure_with : 'a Manager.t -> 'a t -> unit = "camlidl_abstract0_ap_abstract0_closure_with" (* ********************************************************************** *) (** {2 Additional operations} *) (* ********************************************************************** *) val of_lincons_array : 'a Manager.t -> int -> int -> Lincons0.t array -> 'a t val of_tcons_array : 'a Manager.t -> int -> int -> Tcons0.t array -> 'a t (** Abstract a conjunction of constraints *) val assign_linexpr : 'a Manager.t -> 'a t -> Dim.t -> Linexpr0.t -> 'a t option -> 'a t val substitute_linexpr : 'a Manager.t -> 'a t -> Dim.t -> Linexpr0.t -> 'a t option -> 'a t val assign_texpr : 'a Manager.t -> 'a t -> Dim.t -> Texpr0.t -> 'a t option -> 'a t val substitute_texpr : 'a Manager.t -> 'a t -> Dim.t -> Texpr0.t -> 'a t option -> 'a t (** Assignement/Substitution of a single dimension by a single expression *) val assign_linexpr_with : 'a Manager.t -> 'a t -> Dim.t -> Linexpr0.t -> 'a t option -> unit val substitute_linexpr_with : 'a Manager.t -> 'a t -> Dim.t -> Linexpr0.t -> 'a t option -> unit val assign_texpr_with : 'a Manager.t -> 'a t -> Dim.t -> Texpr0.t -> 'a t option -> unit val substitute_texpr_with : 'a Manager.t -> 'a t -> Dim.t -> Texpr0.t -> 'a t option -> unit (** Side-effect version of the previous functions *) (** General use *) val print_array : ?first:(unit, Format.formatter, unit) format -> ?sep:(unit, Format.formatter, unit) format -> ?last:(unit, Format.formatter, unit) format -> (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a array -> unit apron-dist-0.9.10/apron/mlapronidl/abstract0.ml0000640014525101416610000003221611252216516021247 0ustar bjeannetpopart(* File generated from abstract0.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type 'a t (** APRON Abstract value of level 0 *) (** The type parameter ['a] allows to distinguish abstract values with different underlying abstract domains. *) external set_gc : int -> unit = "camlidl_abstract0_ap_abstract0_set_gc" (* ********************************************************************** *) (** {2 General management} *) (* ********************************************************************** *) (* ============================================================ *) (** {3 Memory} *) (* ============================================================ *) external copy : 'a Manager.t -> 'a t -> 'a t = "camlidl_abstract0_ap_abstract0_copy" external size : 'a Manager.t -> 'a t -> int = "camlidl_abstract0_ap_abstract0_size" (* ============================================================ *) (** {3 Control of internal representation} *) (* ============================================================ *) external minimize : 'a Manager.t -> 'a t -> unit = "camlidl_abstract0_ap_abstract0_minimize" external canonicalize : 'a Manager.t -> 'a t -> unit = "camlidl_abstract0_ap_abstract0_canonicalize" external hash : 'a Manager.t -> 'a t -> int = "camlidl_abstract0_ap_abstract0_hash" external approximate : 'a Manager.t -> 'a t -> int -> unit = "camlidl_abstract0_ap_abstract0_approximate" (* ============================================================ *) (** {3 Printing} *) (* ============================================================ *) external fdump : 'a Manager.t -> 'a t -> unit = "camlidl_abstract0_ap_abstract0_fdump" (* ============================================================ *) (** {3 Serialization} *) (* ============================================================ *) (* ********************************************************************** *) (** {2 Constructor, accessors, tests and property extraction} *) (* ********************************************************************** *) (* ============================================================ *) (** {3 Basic constructors} *) (* ============================================================ *) external bottom : 'a Manager.t -> int -> int -> 'a t = "camlidl_abstract0_ap_abstract0_bottom" external top : 'a Manager.t -> int -> int -> 'a t = "camlidl_abstract0_ap_abstract0_top" external of_box : 'a Manager.t -> int -> int -> Interval.t array -> 'a t = "camlidl_abstract0_ap_abstract0_of_box" (* ============================================================ *) (** {3 Accessors} *) (* ============================================================ *) external dimension : 'a Manager.t -> 'a t -> Dim.dimension = "camlidl_abstract0_ap_abstract0_dimension" external manager : 'a t -> 'a Manager.t = "camlidl_abstract0_ap_abstract0_manager" (* ============================================================ *) (** {3 Tests} *) (* ============================================================ *) external is_bottom : 'a Manager.t -> 'a t -> bool = "camlidl_abstract0_ap_abstract0_is_bottom" external is_top : 'a Manager.t -> 'a t -> bool = "camlidl_abstract0_ap_abstract0_is_top" external is_leq : 'a Manager.t -> 'a t -> 'a t -> bool = "camlidl_abstract0_ap_abstract0_is_leq" external is_eq : 'a Manager.t -> 'a t -> 'a t -> bool = "camlidl_abstract0_ap_abstract0_is_eq" external sat_lincons : 'a Manager.t -> 'a t -> Lincons0.t -> bool = "camlidl_abstract0_ap_abstract0_sat_lincons" external sat_tcons : 'a Manager.t -> 'a t -> Tcons0.t -> bool = "camlidl_abstract0_ap_abstract0_sat_tcons" external sat_interval : 'a Manager.t -> 'a t -> Dim.t -> Interval.t -> bool = "camlidl_abstract0_ap_abstract0_sat_interval" external is_dimension_unconstrained : 'a Manager.t -> 'a t -> Dim.t -> bool = "camlidl_abstract0_ap_abstract0_is_dimension_unconstrained" (* ============================================================ *) (** {3 Extraction of properties} *) (* ============================================================ *) external bound_dimension : 'a Manager.t -> 'a t -> Dim.t -> Interval.t = "camlidl_abstract0_ap_abstract0_bound_dimension" external bound_linexpr : 'a Manager.t -> 'a t -> Linexpr0.t -> Interval.t = "camlidl_abstract0_ap_abstract0_bound_linexpr" external bound_texpr : 'a Manager.t -> 'a t -> Texpr0.t -> Interval.t = "camlidl_abstract0_ap_abstract0_bound_texpr" external to_box : 'a Manager.t -> 'a t -> Interval.t array = "camlidl_abstract0_ap_abstract0_to_box" external to_lincons_array : 'a Manager.t -> 'a t -> Lincons0.t array = "camlidl_abstract0_ap_abstract0_to_lincons_array" external to_tcons_array : 'a Manager.t -> 'a t -> Tcons0.t array = "camlidl_abstract0_ap_abstract0_to_tcons_array" external to_generator_array : 'a Manager.t -> 'a t -> Generator0.t array = "camlidl_abstract0_ap_abstract0_to_generator_array" (* ********************************************************************** *) (** {2 Operations} *) (* ********************************************************************** *) (* ============================================================ *) (** {3 Meet and Join} *) (* ============================================================ *) external meet : 'a Manager.t -> 'a t -> 'a t -> 'a t = "camlidl_abstract0_ap_abstract0_meet" external meet_array : 'a Manager.t -> 'a t array -> 'a t = "camlidl_abstract0_ap_abstract0_meet_array" external meet_lincons_array : 'a Manager.t -> 'a t -> Lincons0.t array -> 'a t = "camlidl_abstract0_ap_abstract0_meet_lincons_array" external meet_tcons_array : 'a Manager.t -> 'a t -> Tcons0.t array -> 'a t = "camlidl_abstract0_ap_abstract0_meet_tcons_array" external join : 'a Manager.t -> 'a t -> 'a t -> 'a t = "camlidl_abstract0_ap_abstract0_join" external join_array : 'a Manager.t -> 'a t array -> 'a t = "camlidl_abstract0_ap_abstract0_join_array" external add_ray_array : 'a Manager.t -> 'a t -> Generator0.t array -> 'a t = "camlidl_abstract0_ap_abstract0_add_ray_array" external meet_with : 'a Manager.t -> 'a t -> 'a t -> unit = "camlidl_abstract0_ap_abstract0_meet_with" external meet_lincons_array_with : 'a Manager.t -> 'a t -> Lincons0.t array -> unit = "camlidl_abstract0_ap_abstract0_meet_lincons_array_with" external meet_tcons_array_with : 'a Manager.t -> 'a t -> Tcons0.t array -> unit = "camlidl_abstract0_ap_abstract0_meet_tcons_array_with" external join_with : 'a Manager.t -> 'a t -> 'a t -> unit = "camlidl_abstract0_ap_abstract0_join_with" external add_ray_array_with : 'a Manager.t -> 'a t -> Generator0.t array -> unit = "camlidl_abstract0_ap_abstract0_add_ray_array_with" (* ============================================================ *) (** {3 Assignements and Substitutions} *) (* ============================================================ *) external assign_linexpr_array : 'a Manager.t -> 'a t -> Dim.t array -> Linexpr0.t array -> 'a t option -> 'a t = "camlidl_abstract0_ap_abstract0_assign_linexpr_array" external substitute_linexpr_array : 'a Manager.t -> 'a t -> Dim.t array -> Linexpr0.t array -> 'a t option -> 'a t = "camlidl_abstract0_ap_abstract0_substitute_linexpr_array" external assign_texpr_array : 'a Manager.t -> 'a t -> Dim.t array -> Texpr0.t array -> 'a t option -> 'a t = "camlidl_abstract0_ap_abstract0_assign_texpr_array" external substitute_texpr_array : 'a Manager.t -> 'a t -> Dim.t array -> Texpr0.t array -> 'a t option -> 'a t = "camlidl_abstract0_ap_abstract0_substitute_texpr_array" external assign_linexpr_array_with : 'a Manager.t -> 'a t -> Dim.t array -> Linexpr0.t array -> 'a t option -> unit = "camlidl_abstract0_ap_abstract0_assign_linexpr_array_with" external substitute_linexpr_array_with : 'a Manager.t -> 'a t -> Dim.t array -> Linexpr0.t array -> 'a t option -> unit = "camlidl_abstract0_ap_abstract0_substitute_linexpr_array_with" external assign_texpr_array_with : 'a Manager.t -> 'a t -> Dim.t array -> Texpr0.t array -> 'a t option -> unit = "camlidl_abstract0_ap_abstract0_assign_texpr_array_with" external substitute_texpr_array_with : 'a Manager.t -> 'a t -> Dim.t array -> Texpr0.t array -> 'a t option -> unit = "camlidl_abstract0_ap_abstract0_substitute_texpr_array_with" (* ============================================================ *) (** {3 Projections} *) (* ============================================================ *) external forget_array : 'a Manager.t -> 'a t -> Dim.t array -> bool -> 'a t = "camlidl_abstract0_ap_abstract0_forget_array" external forget_array_with : 'a Manager.t -> 'a t -> Dim.t array -> bool -> unit = "camlidl_abstract0_ap_abstract0_forget_array_with" (* ============================================================ *) (** {3 Change and permutation of dimensions} *) (* ============================================================ *) external add_dimensions : 'a Manager.t -> 'a t -> Dim.change -> bool -> 'a t = "camlidl_abstract0_ap_abstract0_add_dimensions" external remove_dimensions : 'a Manager.t -> 'a t -> Dim.change -> 'a t = "camlidl_abstract0_ap_abstract0_remove_dimensions" external apply_dimchange2 : 'a Manager.t -> 'a t -> Dim.change2 -> bool -> 'a t = "camlidl_abstract0_ap_abstract0_apply_dimchange2" external permute_dimensions : 'a Manager.t -> 'a t -> Dim.perm -> 'a t = "camlidl_abstract0_ap_abstract0_permute_dimensions" external add_dimensions_with : 'a Manager.t -> 'a t -> Dim.change -> bool -> unit = "camlidl_abstract0_ap_abstract0_add_dimensions_with" external remove_dimensions_with : 'a Manager.t -> 'a t -> Dim.change -> unit = "camlidl_abstract0_ap_abstract0_remove_dimensions_with" external apply_dimchange2_with : 'a Manager.t -> 'a t -> Dim.change2 -> bool -> unit = "camlidl_abstract0_ap_abstract0_apply_dimchange2_with" external permute_dimensions_with : 'a Manager.t -> 'a t -> Dim.perm option -> unit = "camlidl_abstract0_ap_abstract0_permute_dimensions_with" (* ============================================================ *) (** {3 Expansion and folding of dimensions} *) (* ============================================================ *) external expand : 'a Manager.t -> 'a t -> Dim.t -> int -> 'a t = "camlidl_abstract0_ap_abstract0_expand" external fold : 'a Manager.t -> 'a t -> Dim.t array -> 'a t = "camlidl_abstract0_ap_abstract0_fold" external expand_with : 'a Manager.t -> 'a t -> Dim.t -> int -> unit = "camlidl_abstract0_ap_abstract0_expand_with" external fold_with : 'a Manager.t -> 'a t -> Dim.t array -> unit = "camlidl_abstract0_ap_abstract0_fold_with" (* ============================================================ *) (** {3 Widening} *) (* ============================================================ *) external widening : 'a Manager.t -> 'a t -> 'a t -> 'a t = "camlidl_abstract0_ap_abstract0_widening" external widening_threshold : 'a Manager.t -> 'a t -> 'a t -> Lincons0.t array -> 'a t = "camlidl_abstract0_ap_abstract0_widening_threshold" (* ============================================================ *) (** {3 Closure operation} *) (* ============================================================ *) external closure : 'a Manager.t -> 'a t -> 'a t = "camlidl_abstract0_ap_abstract0_closure" external closure_with : 'a Manager.t -> 'a t -> unit = "camlidl_abstract0_ap_abstract0_closure_with" (* ********************************************************************** *) (** {2 Additional operations} *) (* ********************************************************************** *) let of_lincons_array man intdim realdim array = let res = top man intdim realdim in meet_lincons_array_with man res array; res let of_tcons_array man intdim realdim array = let res = top man intdim realdim in meet_tcons_array_with man res array; res let assign_linexpr man abs dim expr odest = assign_linexpr_array man abs [|dim|] [|expr|] odest let assign_texpr man abs dim expr odest = assign_texpr_array man abs [|dim|] [|expr|] odest let substitute_linexpr man abs dim expr odest = substitute_linexpr_array man abs [|dim|] [|expr|] odest let substitute_texpr man abs dim expr odest = substitute_texpr_array man abs [|dim|] [|expr|] odest let assign_linexpr_with man abs dim expr odest = assign_linexpr_array_with man abs [|dim|] [|expr|] odest let assign_texpr_with man abs dim expr odest = assign_texpr_array_with man abs [|dim|] [|expr|] odest let substitute_linexpr_with man abs dim expr odest = substitute_linexpr_array_with man abs [|dim|] [|expr|] odest let substitute_texpr_with man abs dim expr odest = substitute_texpr_array_with man abs [|dim|] [|expr|] odest let print_array ?(first=("[|@[":(unit,Format.formatter,unit) format)) ?(sep = (";@ ":(unit,Format.formatter,unit) format)) ?(last = ("@]|]":(unit,Format.formatter,unit) format)) (print_elt: Format.formatter -> 'a -> unit) (fmt:Format.formatter) (array: 'a array) : unit = if array=[||] then begin Format.fprintf fmt first; Format.fprintf fmt last; end else begin Format.fprintf fmt first; let first = ref true in Array.iter (begin fun e -> if !first then first := false else Format.fprintf fmt sep; print_elt fmt e end) array ; Format.fprintf fmt last; end let print assoc fmt a = let man = manager a in if is_bottom man a then Format.pp_print_string fmt "bottom" else if is_top man a then Format.pp_print_string fmt "top" else begin let tab = to_lincons_array man a in print_array (Lincons0.print assoc) fmt tab; end apron-dist-0.9.10/apron/mlapronidl/sedscript_c0000640014525101416610000000160610644461001021251 0ustar bjeannetpopart1 a\\n/* This file is part of the APRON Library, released under LGPL license.\n Please read the COPYING file packaged in the distribution */ s/extern void camlidl_apron_lincons0_ml2c(value, ap_lincons0_t \*)/extern void camlidl_apron_lincons0_ml2c(value, ap_lincons0_t *, camlidl_ctx)/g s/#define camlidl_ml2c_lincons0_ap_lincons0_t(v,c,ctx) camlidl_apron_lincons0_ml2c(v,c)/#define camlidl_ml2c_lincons0_ap_lincons0_t(v,c,ctx) camlidl_apron_lincons0_ml2c(v,c,ctx)/g s/extern void camlidl_apron_tcons0_ml2c(value, ap_tcons0_t \*)/extern void camlidl_apron_tcons0_ml2c(value, ap_tcons0_t *, camlidl_ctx)/g s/#define camlidl_ml2c_tcons0_ap_tcons0_t(v,c,ctx) camlidl_apron_tcons0_ml2c(v,c)/#define camlidl_ml2c_tcons0_ap_tcons0_t(v,c,ctx) camlidl_apron_tcons0_ml2c(v,c,ctx)/g s/struct ap_texpr_op_t/ap_texpr_op_t/g s/struct ap_texpr_rtype_t/ap_texpr_rtype_t/g s/struct ap_texpr_rdir_t/ap_texpr_rdir_t/g apron-dist-0.9.10/apron/mlapronidl/README0000640014525101416610000000747211251670336017723 0ustar bjeannetpopart# $Id$ # This file is part of the APRON Library, released under LGPL # license. # Please read the COPYING file packaged in the distribution This package is an OCAML interface for the APRON library/interface. The interface is accessed via the Apron module, which is decomposed into 15 submodules, corresponding to C modules: Scalar : scalars (numbers) Interval : intervals on scalars Coeff : coefficients (either scalars or intervals) Dimension : dimensions and related operations Linexpr0 : (interval) linear expressions, level 0 Lincons0 : (interval) linear constraints, level 0 Generator0 : generators, level 0 Texpr0 : tree expressions, level 0 Tcons0 : tree constraints, level 0 Manager : managers Abstract0: : abstract values, level 0 Var : variables Environment: environment binding variables to dimensions Linexpr1 : (interval) linear expressions, level 1 Lincons1 : interval) linear constraints, level 1 Generator1 : generators, level 1 Texpr0 : tree expressions, level 1 Tcons0 : tree constraints, level 1 Abstract1 : abstract values, level 1 Parser : parsing of expressions, constraints and generators REQUIREMENTS ============ M4 preprocessor (standard on any UNIX system) APRON library GMP library (tested with version 4.0 and up) MPFR library (tested with version 2.2 and up) mlgmpidl package (included) OCaml 3.0 or up (tested with 3.09) Camlidl (tested with 1.05) INSTALLATION ============ 1. Library ---------- Set the file Makefile.config to your own setting. You might also have to modify the Makefile for executables type 'make', and then 'make install' The OCaml part of the library is named apron.cma (.cmxa, .a) The C part of the library is named libapron_caml.a or dllapron_caml.so (libapron_caml_debug.a or ...) 'make install' installs not only .mli, .cmi, but also .idl files. 2. Documentation ---------------- The documentation is generated with ocamldoc. 'make mlapronidl.pdf' 'make html' (put the HTML files in the html subdirectoy) 3. Miscellaneous ---------------- 'make clean' and 'make distclean' have the usual behaviour. COMPILATION AND LINKING ======================= To make things clearer, we assume an example file 'mlexample.ml' which uses both NewPolka (convex polyhedra) and Box (intervals) libraries, in their versions where numbers are GMP rationals (the default). We assume that C and OCaml interface and library files are located in directory $APRON/lib. The native-code compilation command looks like ocamlopt -I $MLGMPIDL/lib -I $APRON/lib -o mlexample.opt bigarray.cmxa gmp.cmxa apron.cmxa boxMPFR.cmxa polkaMPQ.cmxa mlexample.ml Comments: 1. You need at least the libraries 'bigarray' (standard OCaml distribution), 'gmp', and 'apron' (standard APRON distribution), plus the one implementing an effective abstract domains: here, 'boxMPFR', and 'polkaMPQ'. 2. The C libraries associated to those OCaml libraries ('gmp_caml', 'box_caml', ...) are automatically looked for. If dynamic libraries are available (HAS_SHARED variable in Makefile.config), the byte-code compilation process looks the same: ocamlc -I $MLGMPIDL/lib -I $APRON/lib -o mlexample.byte bigarray.cma gmp.cma apron.cma boxMPFR.cma polkaMPQ.cma mlexample.ml Otherwise, either 1. add the '-custom' option on the command-line above 2. or use a cusrtom runtime interprer: ocamlc -I $APRON/lib -make-runtime -o myrun bigarray.cma gmp.cma apron.cma boxMPFR.cma polkaMPQ.cma ocamlc -I $APRON/lib -use-runtime myrun -o mlexample.byte bigarray.cma gmp.cma apron.cma box.cma polka.cma mlexample.ml Comments: a. One first build a custom bytecode interpreter that includes the new native-code needed; b. One then compile the 'mlexample.ml' file. The option '-verbose' helps to understand what is happening in case of problem. See the pdf or html documentations for more details. apron-dist-0.9.10/apron/mlapronidl/lincons0.ml0000640014525101416610000000137211252216515021107 0ustar bjeannetpopart(* File generated from lincons0.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = { mutable linexpr0 : Linexpr0.t; mutable typ : typ; } and typ = | EQ | SUPEQ | SUP | DISEQ | EQMOD of Scalar.t let string_of_typ = function | EQ | EQMOD _ -> "=" | SUPEQ -> ">=" | SUP -> ">" | DISEQ -> "<>" let print assoc fmt cons = Linexpr0.print assoc fmt cons.linexpr0; Format.fprintf fmt "%s0" (string_of_typ cons.typ); begin match cons.typ with | EQMOD x -> Format.fprintf fmt " mod %a" Scalar.print x; | _ -> () end; () let make expr typ = { linexpr0 = expr; typ = typ } let copy cons = { linexpr0 = Linexpr0.copy cons.linexpr0; typ = cons.typ } apron-dist-0.9.10/apron/mlapronidl/mpq.idl0000777014525101416610000000000011252510553032563 2/scratch/home/bjeannet/pkg/mlgmpidl/linux386/lib/mpq.idlustar bjeannetpopartapron-dist-0.9.10/apron/mlapronidl/environment.ml0000640014525101416610000000545611252216516021736 0ustar bjeannetpopart(* File generated from environment.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type typvar = | INT | REAL and t (** APRON Environments binding dimensions to names *) external make : Var.t array -> Var.t array -> t = "camlidl_environment_ap_environment_make" external add : t -> Var.t array -> Var.t array -> t = "camlidl_environment_ap_environment_add" external remove : t -> Var.t array -> t = "camlidl_environment_ap_environment_remove" external rename : t -> Var.t array -> Var.t array -> t = "camlidl_environment_ap_environment_rename" external rename_perm : t -> Var.t array -> Var.t array -> t * Dim.perm = "camlidl_environment_ap_environment_rename_perm" external lce : t -> t -> t = "camlidl_environment_ap_environment_lce" external lce_change : t -> t -> t * Dim.change option * Dim.change option = "camlidl_environment_ap_environment_lce_change" external dimchange : t -> t -> Dim.change = "camlidl_environment_ap_environment_dimchange" external dimchange2 : t -> t -> Dim.change2 = "camlidl_environment_ap_environment_dimchange2" external equal : t -> t -> bool = "camlidl_environment_ap_environment_equal" external compare : t -> t -> int = "camlidl_environment_ap_environment_compare" external hash : t -> int = "camlidl_environment_ap_environment_hash" external dimension : t -> Dim.dimension = "camlidl_environment_ap_environment_dimension" external size : t -> int = "camlidl_environment_ap_environment_size" external mem_var : t -> Var.t -> bool = "camlidl_environment_ap_environment_mem_var" external typ_of_var : t -> Var.t -> typvar = "camlidl_environment_ap_environment_typ_of_var" external vars : t -> Var.t array * Var.t array = "camlidl_environment_ap_environment_vars" external var_of_dim : t -> Dim.t -> Var.t = "camlidl_environment_ap_environment_var_of_dim" external dim_of_var : t -> Var.t -> Dim.t = "camlidl_environment_ap_environment_dim_of_var" (** Printing *) let print ?(first=("[|@[":(unit,Format.formatter,unit) format)) ?(sep = (";@ ":(unit,Format.formatter,unit) format)) ?(last = ("@]|]":(unit,Format.formatter,unit) format)) (fmt:Format.formatter) (env: t) : unit = let dim = dimension env in if dim.Dim.intd+dim.Dim.reald=0 then begin Format.fprintf fmt first; Format.fprintf fmt last; end else begin Format.fprintf fmt first; let first = ref true in for i=0 to pred dim.Dim.intd do let var = var_of_dim env i in if !first then first := false else Format.fprintf fmt sep; Format.fprintf fmt "%i> %s:int" i (Var.to_string var) done; for i=dim.Dim.intd to dim.Dim.intd + (pred dim.Dim.reald) do let var = var_of_dim env i in if !first then first := false else Format.fprintf fmt sep; Format.fprintf fmt "%i> %s:real" i (Var.to_string var) done; Format.fprintf fmt last; end apron-dist-0.9.10/apron/mlapronidl/linexpr1.mli0000640014525101416610000000472611252216516021304 0ustar bjeannetpopart(* File generated from linexpr1.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = { mutable linexpr0: Linexpr0.t; mutable env: Environment.t; } (** APRON Expressions of level 1 *) (** Build a linear expression defined on the given argument, which is sparse by default. *) val make: ?sparse:bool -> Environment.t -> t (** In case of sparse representation, remove zero coefficients *) val minimize: t -> unit (** Copy *) val copy: t -> t (** Print the linear expression *) val print: Format.formatter -> t -> unit val set_list : t -> (Coeff.t * Var.t) list -> Coeff.t option -> unit (** Set simultaneously a number of coefficients. [set_list expr [(c1,"x"); (c2,"y")] (Some cst)] assigns coefficients [c1] to variable ["x"], coefficient [c2] to variable ["y"], and coefficient [cst] to the constant. If [(Some cst)] is replaced by [None], the constant coefficient is not assigned. *) val set_array : t -> (Coeff.t * Var.t) array -> Coeff.t option -> unit (** Set simultaneously a number of coefficients, as [set_list]. *) (** Iter the function on the pair coefficient/variable of the linear expression *) val iter: (Coeff.t -> Var.t -> unit) -> t -> unit (** Get the constant *) val get_cst: t -> Coeff.t (** Set the constant *) val set_cst: t -> Coeff.t -> unit (** Get the coefficient of the variable *) external get_coeff : t -> Var.t -> Coeff.t = "camlidl_linexpr1_ap_linexpr1_get_coeff" (** Set the coefficient of the variable *) external set_coeff : t -> Var.t -> Coeff.t -> unit = "camlidl_linexpr1_ap_linexpr1_set_coeff" (** Change the environment of the expression for a super-environement. Raise [Failure] if it is not the case *) external extend_environment : t -> Environment.t -> t = "camlidl_linexpr1_ap_linexpr1_extend_environment" (** Side-effet version of the previous function *) external extend_environment_with : t -> Environment.t -> unit = "camlidl_linexpr1_ap_linexpr1_extend_environment_with" (** Does the linear expression depend only on integer variables ? *) external is_integer : t -> bool = "camlidl_linexpr1_ap_linexpr1_is_integer" (** Does the linear expression depend only on real variables ? *) external is_real : t -> bool = "camlidl_linexpr1_ap_linexpr1_is_real" (** Get the underlying expression of level 0 (which is not a copy). *) val get_linexpr0: t -> Linexpr0.t (** Get the environement of the expression *) val get_env: t -> Environment.t apron-dist-0.9.10/apron/mlapronidl/sedscript_caml0000640014525101416610000000432011224617210021737 0ustar bjeannetpopart1 a\\n(* This file is part of the APRON Library, released under LGPL license.\n Please read the COPYING file packaged in the distribution *) s/mutable_/mutable /g; s/mpq_ptr/t/g; s/^and ap_scalar_ptr = ap_scalar_t//g; s/^and ap_scalar_array_t = ap_scalar_ptr array//g; s/ap_scalar_t/t/g; s/ap_scalar_ptr/t/g; s/Scalar.ap_scalar_array_t/Scalar.t array/g; s/^and ap_interval_ptr = ap_interval_t//g; s/^and ap_interval_array_t = ap_interval_ptr array//g; s/ap_interval_t/t/g; s/ap_interval_ptr/t/g; s/Interval.ap_interval_array_t/Interval.t array/g; s/ap_coeff_t/t/g; s/ap_dim_t/t/g; s/ap_dimchange_t/change/g; s/ap_dimchange2_t/change2/g; s/ap_dimperm_t/perm/g; s/ap_dimension_t/dimension/g; s/ap_linexpr0_ptr/t/g; s/external ap_linexpr0_/external /g; s/^and ap_lincons0_array_t = ap_lincons0_t array//g; s/ap_lincons0_t/t/g; s/ap_lincons0_array_t/t array/g; s/gentyp/typ/g; s/^and ap_generator0_array_t = ap_generator0_t array//g; s/ap_generator0_t/t/g; s/ap_generator0_array_t/t array/g; s/ap_texpr0_ptr/t/g; s/ap_texpr_unop_t/unop/g; s/ap_texpr_binop_t/binop/g; s/ap_texpr_rtype_t/typ/g; s/ap_texpr_rdir_t/round/g; s/external ap_texpr0_/external /g; s/^and ap_tcons0_array_t = ap_tcons0_t array//g; s/ap_tcons0_t/t/g; s/ap_tcons0_array_t/t array/g; s/tbool_t/tbool/g; s/ap_exc_t/exc/g; s/ap_funid_t/funid/g; s/ap_funopt_t/funopt/g; s/ ap_funopt_/ funopt_/g; s/ap_exclog_t/exclog/g; s/\(\([A-Z][a-z0-9]*[.]\)\?\)ap_manager_ptr/'a \1t/g; s/\(\([A-Z][a-z0-9]*[.]\)\?\)ap_manager_t/'a \1t/g; s/external ap_manager_/external /g; s/\(\([A-Z][a-z0-9]*[.]\)\?\)ap_abstract0_ptr/'a \1t/g; s/external ap_abstract0_/external /g; s/\([^_]\)ap_var_/\1/g; s/ap_environment_ptr/t/g; s/external ap_environment_/external /g; s/AP_INT/INT/g; s/AP_REAL/REAL/g; s/ap_linexpr1_t/t/g; s/external ap_linexpr1_/external /g; s/ap_lincons1_t/t/g; s/ap_lincons1_array_t/earray/g; s/external ap_lincons1_/external /g; s/ap_generator1_t/t/g; s/ap_generator1_array_t/earray/g; s/external ap_generator1_/external /g; s/ap_texpr1_t\([^a-zA-Z]\|$\)/t\1/g; s/external ap_texpr1_/external /g; s/ap_tcons1_t/t/g; s/ap_tcons1_array_t/earray/g; s/external ap_tcons1_/external /g; s/\(\([A-Z][a-z0-9]*[.]\)\?\)ap_abstract1_t\([^a-zA-Z]\|$\)/'a \1t\3/g; s/external ap_abstract1_/external /g; apron-dist-0.9.10/apron/mlapronidl/tcons1_caml.c0000640014525101416610000003050111252216516021374 0ustar bjeannetpopart/* File generated from tcons1.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include #include "ap_tcons1.h" #include "apron_caml.h" extern void camlidl_apron_scalar_ml2c(value, ap_scalar_t *); #define camlidl_ml2c_scalar_ap_scalar_t(v,c,ctx) camlidl_apron_scalar_ml2c(v,c) extern value camlidl_apron_scalar_c2ml(ap_scalar_t *); #define camlidl_c2ml_scalar_ap_scalar_t(c,ctx) camlidl_apron_scalar_c2ml(c) extern void camlidl_ml2c_scalar_ap_scalar_ptr(value, ap_scalar_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_ap_scalar_ptr(ap_scalar_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_scalar_struct_ap_scalar_array_t(value, struct ap_scalar_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_struct_ap_scalar_array_t(struct ap_scalar_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_t(value, struct ap_interval_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_t(struct ap_interval_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_ap_interval_ptr(value, ap_interval_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_ap_interval_ptr(ap_interval_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_array_t(value, struct ap_interval_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_array_t(struct ap_interval_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_coeff_struct_ap_coeff_t(value, struct ap_coeff_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_coeff_struct_ap_coeff_t(struct ap_coeff_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_ap_dim_t(value, ap_dim_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_ap_dim_t(ap_dim_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimchange_t(value, struct ap_dimchange_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange_t(struct ap_dimchange_t *, camlidl_ctx _ctx); extern void camlidl_apron_dimchange_ml2c(value, ap_dimchange_t *); #define camlidl_ml2c_dim_ap_dimchange_t(v,c,ctx) camlidl_apron_dimchange_ml2c(v,c) extern value camlidl_apron_dimchange_c2ml(ap_dimchange_t *); #define camlidl_c2ml_dim_ap_dimchange_t(c,ctx) camlidl_apron_dimchange_c2ml(c) extern void camlidl_ml2c_dim_struct_ap_dimchange2_t(value, struct ap_dimchange2_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange2_t(struct ap_dimchange2_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimperm_t(value, struct ap_dimperm_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimperm_t(struct ap_dimperm_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimension_t(value, struct ap_dimension_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimension_t(struct ap_dimension_t *, camlidl_ctx _ctx); extern void camlidl_apron_linexpr0_ptr_ml2c(value, ap_linexpr0_ptr *); #define camlidl_ml2c_linexpr0_ap_linexpr0_ptr(v,c,ctx) camlidl_apron_linexpr0_ptr_ml2c(v,c) extern value camlidl_apron_linexpr0_ptr_c2ml(ap_linexpr0_ptr *); #define camlidl_c2ml_linexpr0_ap_linexpr0_ptr(c,ctx) camlidl_apron_linexpr0_ptr_c2ml(c) extern void camlidl_apron_texpr0_ptr_ml2c(value, ap_texpr0_ptr *); #define camlidl_ml2c_texpr0_ap_texpr0_ptr(v,c,ctx) camlidl_apron_texpr0_ptr_ml2c(v,c) extern value camlidl_apron_texpr0_ptr_c2ml(ap_texpr0_ptr *); #define camlidl_c2ml_texpr0_ap_texpr0_ptr(c,ctx) camlidl_apron_texpr0_ptr_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_op_t(value, ap_texpr_op_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_op_t(ap_texpr_op_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_unop_t_ml2c(value, ap_texpr_unop_t *); #define camlidl_ml2c_texpr0_ap_texpr_unop_t(v,c,ctx) camlidl_apron_texpr_unop_t_ml2c(v,c) extern value camlidl_apron_texpr_unop_t_c2ml(ap_texpr_unop_t *); #define camlidl_c2ml_texpr0_ap_texpr_unop_t(c,ctx) camlidl_apron_texpr_unop_t_c2ml(c) extern void camlidl_apron_texpr_binop_t_ml2c(value, ap_texpr_binop_t *); #define camlidl_ml2c_texpr0_ap_texpr_binop_t(v,c,ctx) camlidl_apron_texpr_binop_t_ml2c(v,c) extern value camlidl_apron_texpr_binop_t_c2ml(ap_texpr_binop_t *); #define camlidl_c2ml_texpr0_ap_texpr_binop_t(c,ctx) camlidl_apron_texpr_binop_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rtype_t(value, ap_texpr_rtype_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rtype_t(ap_texpr_rtype_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_rtype_t_ml2c(value, ap_texpr_rtype_t *); #define camlidl_ml2c_texpr0_ap_texpr_rtype_t(v,c,ctx) camlidl_apron_texpr_rtype_t_ml2c(v,c) extern value camlidl_apron_texpr_rtype_t_c2ml(ap_texpr_rtype_t *); #define camlidl_c2ml_texpr0_ap_texpr_rtype_t(c,ctx) camlidl_apron_texpr_rtype_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rdir_t(value, ap_texpr_rdir_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rdir_t(ap_texpr_rdir_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_rdir_t_ml2c(value, ap_texpr_rdir_t *); #define camlidl_ml2c_texpr0_ap_texpr_rdir_t(v,c,ctx) camlidl_apron_texpr_rdir_t_ml2c(v,c) extern value camlidl_apron_texpr_rdir_t_c2ml(ap_texpr_rdir_t *); #define camlidl_c2ml_texpr0_ap_texpr_rdir_t(c,ctx) camlidl_apron_texpr_rdir_t_c2ml(c) extern void camlidl_apron_lincons0_ml2c(value, ap_lincons0_t *, camlidl_ctx); #define camlidl_ml2c_lincons0_ap_lincons0_t(v,c,ctx) camlidl_apron_lincons0_ml2c(v,c,ctx) extern value camlidl_apron_lincons0_c2ml(ap_lincons0_t *); #define camlidl_c2ml_lincons0_ap_lincons0_t(c,ctx) camlidl_apron_lincons0_c2ml(c) extern void camlidl_ml2c_lincons0_struct_ap_lincons0_array_t(value, struct ap_lincons0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_lincons0_struct_ap_lincons0_array_t(struct ap_lincons0_array_t *, camlidl_ctx _ctx); extern void camlidl_apron_tcons0_ml2c(value, ap_tcons0_t *, camlidl_ctx); #define camlidl_ml2c_tcons0_ap_tcons0_t(v,c,ctx) camlidl_apron_tcons0_ml2c(v,c,ctx) extern value camlidl_apron_tcons0_c2ml(ap_tcons0_t *); #define camlidl_c2ml_tcons0_ap_tcons0_t(c,ctx) camlidl_apron_tcons0_c2ml(c) extern void camlidl_ml2c_tcons0_struct_ap_tcons0_array_t(value, struct ap_tcons0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_tcons0_struct_ap_tcons0_array_t(struct ap_tcons0_array_t *, camlidl_ctx _ctx); extern void camlidl_apron_var_ptr_ml2c(value, ap_var_t *); #define camlidl_ml2c_var_ap_var_t(v,c,ctx) camlidl_apron_var_ptr_ml2c(v,c) extern value camlidl_apron_var_ptr_c2ml(ap_var_t *); #define camlidl_c2ml_var_ap_var_t(c,ctx) camlidl_apron_var_ptr_c2ml(c) extern int camlidl_ml2c_environment_enum_typvar(value); extern value camlidl_c2ml_environment_enum_typvar(int); extern int camlidl_transl_table_environment_enum_typvar[]; extern void camlidl_apron_environment_ptr_ml2c(value, ap_environment_ptr *); #define camlidl_ml2c_environment_ap_environment_ptr(v,c,ctx) camlidl_apron_environment_ptr_ml2c(v,c) extern value camlidl_apron_environment_ptr_c2ml(ap_environment_ptr *); #define camlidl_c2ml_environment_ap_environment_ptr(c,ctx) camlidl_apron_environment_ptr_c2ml(c) extern void camlidl_ml2c_texpr1_struct_ap_texpr1_t(value, struct ap_texpr1_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr1_struct_ap_texpr1_t(struct ap_texpr1_t *, camlidl_ctx _ctx); void camlidl_ml2c_tcons1_struct_ap_tcons1_t(value _v1, struct ap_tcons1_t * _c2, camlidl_ctx _ctx) { value _v3; value _v4; _v3 = Field(_v1, 0); camlidl_ml2c_tcons0_ap_tcons0_t(_v3, &(*_c2).tcons0, _ctx); _v4 = Field(_v1, 1); camlidl_ml2c_environment_ap_environment_ptr(_v4, &(*_c2).env, _ctx); } value camlidl_c2ml_tcons1_struct_ap_tcons1_t(struct ap_tcons1_t * _c1, camlidl_ctx _ctx) { value _v2; value _v3[2]; _v3[0] = _v3[1] = 0; Begin_roots_block(_v3, 2) _v3[0] = camlidl_c2ml_tcons0_ap_tcons0_t(&(*_c1).tcons0, _ctx); _v3[1] = camlidl_c2ml_environment_ap_environment_ptr(&(*_c1).env, _ctx); _v2 = camlidl_alloc_small(2, 0); Field(_v2, 0) = _v3[0]; Field(_v2, 1) = _v3[1]; End_roots() return _v2; } void camlidl_ml2c_tcons1_struct_ap_tcons1_array_t(value _v1, struct ap_tcons1_array_t * _c2, camlidl_ctx _ctx) { value _v3; value _v4; _v3 = Field(_v1, 0); camlidl_ml2c_tcons0_struct_ap_tcons0_array_t(_v3, &(*_c2).tcons0_array, _ctx); _v4 = Field(_v1, 1); camlidl_ml2c_environment_ap_environment_ptr(_v4, &(*_c2).env, _ctx); } value camlidl_c2ml_tcons1_struct_ap_tcons1_array_t(struct ap_tcons1_array_t * _c1, camlidl_ctx _ctx) { value _v2; value _v3[2]; _v3[0] = _v3[1] = 0; Begin_roots_block(_v3, 2) _v3[0] = camlidl_c2ml_tcons0_struct_ap_tcons0_array_t(&(*_c1).tcons0_array, _ctx); _v3[1] = camlidl_c2ml_environment_ap_environment_ptr(&(*_c1).env, _ctx); _v2 = camlidl_alloc_small(2, 0); Field(_v2, 0) = _v3[0]; Field(_v2, 1) = _v3[1]; End_roots() return _v2; } value camlidl_tcons1_ap_tcons1_extend_environment( value _v_tcons, value _v_env) { struct ap_tcons1_t tcons; /*in*/ ap_environment_ptr env; /*in*/ struct ap_tcons1_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_tcons1_struct_ap_tcons1_t(_v_tcons, &tcons, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); /* begin user-supplied calling sequence */ { bool b; b = ap_tcons1_extend_environment(&_res,&tcons,env); if (b) caml_failwith("Tcons1.extend_environment: new environment is not a superenvironment"); } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_tcons1_struct_ap_tcons1_t(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_tcons1_ap_tcons1_extend_environment_with( value _v_tcons, value _v_env) { struct ap_tcons1_t tcons; /*in*/ ap_environment_ptr env; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_tcons1_struct_ap_tcons1_t(_v_tcons, &tcons, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); /* begin user-supplied calling sequence */ { if (tcons.env!=env){ bool b; ap_environment_copy(tcons.env); /* to protect it */ b = ap_tcons1_extend_environment_with(&tcons,env); if (b){ ap_environment_free(tcons.env); caml_failwith("Tcons1.extend_environment_with: new environment is not a superenvironment"); } Store_field(_v_tcons,1,_v_env); ap_environment_free(env); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } value camlidl_tcons1_ap_tcons1_array_extend_environment( value _v_array, value _v_env) { struct ap_tcons1_array_t array; /*in*/ ap_environment_ptr env; /*in*/ struct ap_tcons1_array_t _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_tcons1_struct_ap_tcons1_array_t(_v_array, &array, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); /* begin user-supplied calling sequence */ { bool b; b = ap_tcons1_array_extend_environment(&_res,&array,env); if (b) caml_failwith("Tcons1.array_extend_environment: new environment is not a superenvironment"); } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_tcons1_struct_ap_tcons1_array_t(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_tcons1_ap_tcons1_array_extend_environment_with( value _v_array, value _v_env) { struct ap_tcons1_array_t array; /*in*/ ap_environment_ptr env; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_tcons1_struct_ap_tcons1_array_t(_v_array, &array, _ctx); camlidl_ml2c_environment_ap_environment_ptr(_v_env, &env, _ctx); /* begin user-supplied calling sequence */ { if (array.env!=env){ bool b; ap_environment_copy(array.env); /* to protect it */ b = ap_tcons1_array_extend_environment_with(&array,env); if (b){ ap_environment_free(array.env); caml_failwith("Tcons1.array_extend_environment_with: new environment is not a superenvironment"); } Store_field(_v_array,1,_v_env); ap_environment_free(env); } } /* end user-supplied calling sequence */ camlidl_free(_ctx); return Val_unit; } apron-dist-0.9.10/apron/mlapronidl/generator1.mli0000640014525101416610000001011511252216516021576 0ustar bjeannetpopart(* File generated from generator1.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type t = { mutable generator0: Generator0.t; mutable env: Environment.t; } and earray = { mutable generator0_array: Generator0.t array; mutable array_env: Environment.t; } (** APRON Generators and array of generators of level 1 *) type typ = Generator0.typ = | LINE | RAY | VERTEX | LINEMOD | RAYMOD (** Make a generator. Modifying later the linear expression ({e not advisable}) modifies correspondingly the generator and conversely, except for changes of environements *) val make: Linexpr1.t -> Generator0.typ -> t (** Copy (deep copy) *) val copy: t -> t (** Print the generator *) val print : Format.formatter -> t -> unit (** Get the generator type *) val get_typ: t -> Generator0.typ (** Iter the function on the pair coefficient/variable of the underlying linear expression *) val iter: (Coeff.t -> Var.t -> unit) -> t -> unit (** Set the generator type *) val set_typ: t -> Generator0.typ -> unit (** Set simultaneously a number of coefficients. [set_list expr [(c1,"x"); (c2,"y")]] assigns coefficients [c1] to variable ["x"] and coefficient [c2] to variable ["y"]. *) val set_list : t -> (Coeff.t * Var.t) list -> unit (** Set simultaneously a number of coefficients, as [set_list]. *) val set_array : t -> (Coeff.t * Var.t) array -> unit (** Get the coefficient of the variable in the underlying linear expression *) external get_coeff : t -> Var.t -> Coeff.t = "camlidl_generator1_ap_generator1_get_coeff" (** Set the coefficient of the variable in the underlying linear expression *) external set_coeff : t -> Var.t -> Coeff.t -> unit = "camlidl_generator1_ap_generator1_set_coeff" (** Change the environement of the generator for a super-environement. Raise [Failure] if it is not the case *) external extend_environment : t -> Environment.t -> t = "camlidl_generator1_ap_generator1_extend_environment" (** Side-effect version of the previous function *) external extend_environment_with : t -> Environment.t -> unit = "camlidl_generator1_ap_generator1_extend_environment_with" (* ====================================================================== *) (** {2 Type earray} *) (* ====================================================================== *) (** Make an array of generators with the given size and defined on the given environement. The elements are initialized with the line 0. *) val array_make : Environment.t -> int -> earray (** Print an array of generators *) val array_print : ?first:(unit, Format.formatter, unit) format -> ?sep:(unit, Format.formatter, unit) format -> ?last:(unit, Format.formatter, unit) format -> Format.formatter -> earray -> unit (** Get the size of the array *) val array_length : earray -> int (** Get the element of the given index (which is not a copy) *) val array_get : earray -> int -> t (** Set the element of the given index (without any copy). The array and the generator should be defined on the same environement; otherwise a [Failure] exception is raised.*) val array_set : earray -> int -> t -> unit (** Change the environement of the array of generators for a super-environement. Raise [Failure] if it is not the case*) external array_extend_environment : earray -> Environment.t -> earray = "camlidl_generator1_ap_generator1_array_extend_environment" (** Side-effect version of the previous function *) external array_extend_environment_with : earray -> Environment.t -> unit = "camlidl_generator1_ap_generator1_array_extend_environment_with" (** Get the environement of the generator *) val get_env: t -> Environment.t (** Get the underlying linear expression. Modifying the linear expression ({e not advisable}) modifies correspondingly the generator and conversely, except for changes of environements *) val get_linexpr1: t -> Linexpr1.t (** Get the underlying generator of level 0. Modifying the generator of level 0 ({e not advisable}) modifies correspondingly the generator and conversely, except for changes of environements*) val get_generator0: t -> Generator0.t apron-dist-0.9.10/apron/mlapronidl/manager.ml0000640014525101416610000001366211252216515021001 0ustar bjeannetpopart(* File generated from manager.idl *) (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution *) type funid = | Funid_unknown | Funid_copy | Funid_free | Funid_asize | Funid_minimize | Funid_canonicalize | Funid_hash | Funid_approximate | Funid_fprint | Funid_fprintdiff | Funid_fdump | Funid_serialize_raw | Funid_deserialize_raw | Funid_bottom | Funid_top | Funid_of_box | Funid_dimension | Funid_is_bottom | Funid_is_top | Funid_is_leq | Funid_is_eq | Funid_is_dimension_unconstrained | Funid_sat_interval | Funid_sat_lincons | Funid_sat_tcons | Funid_bound_dimension | Funid_bound_linexpr | Funid_bound_texpr | Funid_to_box | Funid_to_lincons_array | Funid_to_tcons_array | Funid_to_generator_array | Funid_meet | Funid_meet_array | Funid_meet_lincons_array | Funid_meet_tcons_array | Funid_join | Funid_join_array | Funid_add_ray_array | Funid_assign_linexpr_array | Funid_substitute_linexpr_array | Funid_assign_texpr_array | Funid_substitute_texpr_array | Funid_add_dimensions | Funid_remove_dimensions | Funid_permute_dimensions | Funid_forget_array | Funid_expand | Funid_fold | Funid_widening | Funid_closure | Funid_change_environment | Funid_rename_array and funopt = { algorithm: int; timeout: int; max_object_size: int; flag_exact_wanted: bool; flag_best_wanted: bool; } and exc = | Exc_none | Exc_timeout | Exc_out_of_space | Exc_overflow | Exc_invalid_argument | Exc_not_implemented and exclog = { exn: exc; funid: funid; msg: string; } and 'a t (** APRON Managers *) (** The type parameter ['a] allows to distinguish managers allocated by different underlying abstract domains. *) (** Concerning the other types, - [funid] defines identifiers for the generic function working on abstrat values; - [funopt] defines the options associated to generic functions; - [exc] defines the different kind of exceptions; - [exclog] defines the exceptions raised by APRON functions. *) external get_library : 'a t -> string = "camlidl_manager_ap_manager_get_library" external get_version : 'a t -> string = "camlidl_manager_ap_manager_get_version" external funopt_make : unit -> funopt = "camlidl_manager_ap_funopt_make" external get_funopt : 'a t -> funid -> funopt = "camlidl_manager_ap_manager_get_funopt" external set_funopt : 'a t -> funid -> funopt -> unit = "camlidl_manager_ap_manager_set_funopt" external get_flag_exact : 'a t -> bool = "camlidl_manager_ap_manager_get_flag_exact" external get_flag_best : 'a t -> bool = "camlidl_manager_ap_manager_get_flag_best" exception Error of exclog let _ = Callback.register_exception "apron exception" (Error { exn=Exc_none; funid = Funid_bottom; msg = "dummy"; }) let string_of_funid = function | Funid_unknown -> "Funid_unknown" | Funid_copy -> "Funid_copy" | Funid_free -> "Funid_free" | Funid_asize -> "Funid_asize" | Funid_minimize -> "Funid_minimize" | Funid_canonicalize -> "Funid_canonicalize" | Funid_hash -> "Funid_hash" | Funid_approximate -> "Funid_approximate" | Funid_fprint -> "Funid_fprint" | Funid_fprintdiff -> "Funid_fprintdiff" | Funid_fdump -> "Funid_fdump" | Funid_serialize_raw -> "Funid_serialize_raw" | Funid_deserialize_raw -> "Funid_deserialize_raw" | Funid_bottom -> "Funid_bottom" | Funid_top -> "Funid_top" | Funid_of_box -> "Funid_of_box" | Funid_dimension -> "Funid_dimension" | Funid_is_bottom -> "Funid_is_bottom" | Funid_is_top -> "Funid_is_top" | Funid_is_leq -> "Funid_is_leq" | Funid_is_eq -> "Funid_is_eq" | Funid_is_dimension_unconstrained -> "Funid_is_dimension_unconstrained" | Funid_sat_interval -> "Funid_sat_interval" | Funid_sat_lincons -> "Funid_sat_lincons" | Funid_sat_tcons -> "Funid_sat_tcons" | Funid_bound_dimension -> "Funid_bound_dimension" | Funid_bound_linexpr -> "Funid_bound_linexpr" | Funid_bound_texpr -> "Funid_bound_texpr" | Funid_to_box -> "Funid_to_box" | Funid_to_lincons_array -> "Funid_to_lincons_array" | Funid_to_tcons_array -> "Funid_to_tcons_array" | Funid_to_generator_array -> "Funid_to_generator_array" | Funid_meet -> "Funid_meet" | Funid_meet_array -> "Funid_meet_array" | Funid_meet_lincons_array -> "Funid_meet_lincons_array" | Funid_meet_tcons_array -> "Funid_meet_tcons_array" | Funid_join -> "Funid_join" | Funid_join_array -> "Funid_join_array" | Funid_add_ray_array -> "Funid_add_ray_array" | Funid_assign_linexpr_array -> "Funid_assign_linexpr_array" | Funid_substitute_linexpr_array -> "Funid_substitute_linexpr_array" | Funid_assign_texpr_array -> "Funid_assign_texpr_array" | Funid_substitute_texpr_array -> "Funid_substitute_texpr_array" | Funid_add_dimensions -> "Funid_add_dimensions" | Funid_remove_dimensions -> "Funid_remove_dimensions" | Funid_permute_dimensions -> "Funid_permute_dimensions" | Funid_forget_array -> "Funid_forget_array" | Funid_expand -> "Funid_expand" | Funid_fold -> "Funid_fold" | Funid_widening -> "Funid_widening" | Funid_closure -> "Funid_closure" | Funid_change_environment -> "Funid_change_environment" | Funid_rename_array -> "Funid_rename_array" let string_of_exc = function | Exc_none -> "Exc_none" | Exc_timeout -> "Exc_timeout" | Exc_out_of_space -> "Exc_out_of_space" | Exc_overflow -> "Exc_overflow" | Exc_invalid_argument -> "Exc_invalid_argument" | Exc_not_implemented -> "Exc_not_implemented" let print_funid fmt x = Format.pp_print_string fmt (string_of_funid x) let print_exc fmt x = Format.pp_print_string fmt (string_of_exc x) let print_exclog fmt x = Format.fprintf fmt "{ @[ exn = %a;@ funid = %a;@ msg = %s;@] }" print_exc x.exn print_funid x.funid x.msg let print_funopt fmt x = Format.fprintf fmt "{ @[ algorithm = %i;@ timeout = %i;@ max_object_size = %i;@ flag_exact_wanted = %b;@ flag_best_wanted = %b;@] }" x.algorithm x.timeout x.max_object_size x.flag_exact_wanted x.flag_best_wanted external set_deserialize : 'a t -> unit = "camlidl_manager_ap_manager_set_deserialize" external get_deserialize : unit -> 'a t = "camlidl_manager_ap_manager_get_deserialize" external init: unit -> unit = "camlidl_apron_init" let _ = init() apron-dist-0.9.10/apron/COPYING0000640014525101416610000006405010672507041015726 0ustar bjeannetpopart This license applies to all files distributed in the original package, *except* files contained in ppl, products, examples, and tests subdirectories, which contain specific COPYING files (GPL license instead of LGPL license). GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! apron-dist-0.9.10/apron/AUTHORS0000640014525101416610000000102310564630522015733 0ustar bjeannetpopart The APRON interface has been designed by the research teams involved in the APRON project (http://www.cri.ensmp.fr/apron/). The related software developpements have been conducted by the following people: Bertrand Jeannet Main author of num, mlgmpidl, apron, mlapronidl, and newpolka packages. Sebastian Pop Adaptation of the Omega library (to come). Antoine Mine Author of the Octagon Abstract Domain Library and its adaptation to APRON interface. Binding to the Parma Polyhedra Library. Author of num package. apron-dist-0.9.10/apron/ppl/0000750014525101416610000000000011252216517015460 5ustar bjeannetpopartapron-dist-0.9.10/apron/ppl/ppl.ml0000640014525101416610000001513111252216517016607 0ustar bjeannetpopart(* File generated from ppl.idl *) (* This file is part of the APRON Library, released under GPL license. Please read the COPYING file packaged in the distribution. *) (** Convex Polyhedra and Linear Congruences abstract domains (PPL wrapper) *) (** This module is a wrapper around the Parma Polyhedra Library. *) type loose type strict (** Two flavors for convex polyhedra: loose or strict. Loose polyhedra cannot have strict inequality constraints like [x>0]. They are algorithmically more efficient (less generators, simpler normalization). Convex polyhedra are defined by the conjunction of a set of linear constraints of the form [a_0*x_0 + ... + a_n*x_n + b >= 0] or [a_0*x_0 + ... + a_n*x_n + b > 0] where [a_0, ..., a_n, b, c] are constants and [x_0, ..., x_n] variables. *) type grid (** Linear congruences. Linear congruences are defined by the conjunction of equality constraints modulo a rational number, of the form [a_0*x_0 + ... + a_n*x_n = b mod c], where [a_0, ..., a_n, b, c] are constants and [x_0, ..., x_n] variables. *) type 'a t (** Type of convex polyhedra/linear congruences, where ['a] is [loose], [strict] or [grid]. Abstract values which are convex polyhedra have the type [loose t Apron.AbstractX.t] or [strict t Apron.AbstractX.t]. Abstract values which are conjunction of linear congruences equalities have the type [grid t Apron.AbstractX.t]. Managers allocated by PPL have the type ['a t Apron.Manager.t]. *) external manager_alloc_loose : unit -> loose t Apron.Manager.t = "camlidl_ppl_ap_ppl_manager_alloc_loose" external manager_alloc_strict : unit -> strict t Apron.Manager.t = "camlidl_ppl_ap_ppl_manager_alloc_strict" external manager_alloc_grid : unit -> grid t Apron.Manager.t = "camlidl_ppl_ap_ppl_manager_alloc_grid" let manager_is_ppl man = let str = Apron.Manager.get_library man in let str = try String.sub str 0 3 with Invalid_argument _ -> "" in (String.compare str "PPL")==0 let manager_of_ppl (man:'a t Apron.Manager.t) : 'b Apron.Manager.t = Obj.magic man let manager_to_ppl (man:'a Apron.Manager.t) : 'b t Apron.Manager.t = if manager_is_ppl man then Obj.magic man else failwith "Ppl.to_ppl: the argument manager is not a Ppl manager" let manager_is_ppl_loose man = let str = Apron.Manager.get_library man in (String.compare str "PPL::Polyhedron, loose mode")==0 let manager_of_ppl_loose (man:loose t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_ppl_loose (man:'a Apron.Manager.t) : loose t Apron.Manager.t = if manager_is_ppl_loose man then Obj.magic man else failwith "Ppl.to_ppl_loose: the argument manager is not a loose Ppl manager" let manager_is_ppl_strict man = let str = Apron.Manager.get_library man in (String.compare str "PPL::Polyhedron, strict mode")==0 let manager_of_ppl_strict (man:strict t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_ppl_strict (man:'a Apron.Manager.t) : strict t Apron.Manager.t = if manager_is_ppl_strict man then Obj.magic man else failwith "Ppl.to_ppl_strict: the argument manager is not a strict Ppl manager" let manager_is_ppl_grid man = let str = Apron.Manager.get_library man in (String.compare str "PPL::Grid")==0 let manager_of_ppl_grid (man:grid t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_ppl_grid (man:'a Apron.Manager.t) : grid t Apron.Manager.t = if manager_is_ppl_grid man then Obj.magic man else failwith "Ppl.to_ppl_grid: the argument manager is not a grid Ppl manager" module Abstract0 = struct let is_ppl abs = manager_is_ppl (Apron.Abstract0.manager abs) let is_ppl_loose abs = manager_is_ppl_loose (Apron.Abstract0.manager abs) let is_ppl_strict abs = manager_is_ppl (Apron.Abstract0.manager abs) let is_ppl_grid abs = manager_is_ppl_grid (Apron.Abstract0.manager abs) let of_ppl (abs: 'a t Apron.Abstract0.t) : 'b Apron.Abstract0.t = Obj.magic abs let of_ppl_loose (abs: loose t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let of_ppl_strict (abs: strict t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let of_ppl_grid (abs: grid t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let to_ppl (abs:'a Apron.Abstract0.t) : 'b t Apron.Abstract0.t = if is_ppl abs then Obj.magic abs else failwith "Ppl.Abstract0.to_ppl: the argument value is not a ppl value" let to_ppl_loose (abs:'a Apron.Abstract0.t) : loose t Apron.Abstract0.t = if is_ppl_loose abs then Obj.magic abs else failwith "Ppl.Abstract0.to_ppl_loose: the argument value is not a loose ppl value" let to_ppl_strict (abs:'a Apron.Abstract0.t) : strict t Apron.Abstract0.t = if is_ppl_strict abs then Obj.magic abs else failwith "Ppl.Abstract0.to_ppl_strict: the argument value is not a strict ppl value" let to_ppl_grid (abs:'a Apron.Abstract0.t) : grid t Apron.Abstract0.t = if is_ppl_grid abs then Obj.magic abs else failwith "Ppl.Abstract0.to_ppl_grid: the argument value is not a grid ppl value" end module Abstract1 = struct let is_ppl abs = manager_is_ppl (Apron.Abstract1.manager abs) let is_ppl_loose abs = manager_is_ppl_loose (Apron.Abstract1.manager abs) let is_ppl_strict abs = manager_is_ppl (Apron.Abstract1.manager abs) let is_ppl_grid abs = manager_is_ppl_grid (Apron.Abstract1.manager abs) let of_ppl (abs: 'a t Apron.Abstract1.t) : 'b Apron.Abstract1.t = Obj.magic abs let of_ppl_loose (abs: loose t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let of_ppl_strict (abs: strict t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let of_ppl_grid (abs: grid t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let to_ppl (abs:'a Apron.Abstract1.t) : 'b t Apron.Abstract1.t = if is_ppl abs then Obj.magic abs else failwith "Ppl.Abstract1.to_ppl: the argument value is not a ppl value" let to_ppl_loose (abs:'a Apron.Abstract1.t) : loose t Apron.Abstract1.t = if is_ppl_loose abs then Obj.magic abs else failwith "Ppl.Abstract1.to_ppl_loose: the argument value is not a loose ppl value" let to_ppl_strict (abs:'a Apron.Abstract1.t) : strict t Apron.Abstract1.t = if is_ppl_strict abs then Obj.magic abs else failwith "Ppl.Abstract1.to_ppl_strict: the argument value is not a strict ppl value" let to_ppl_grid (abs:'a Apron.Abstract1.t) : grid t Apron.Abstract1.t = if is_ppl_grid abs then Obj.magic abs else failwith "Ppl.Abstract1.to_ppl_grid: the argument value is not a grid ppl value" end apron-dist-0.9.10/apron/ppl/ppl.mli0000640014525101416610000001436611252216517016771 0ustar bjeannetpopart(* File generated from ppl.idl *) (* This file is part of the APRON Library, released under GPL license. Please read the COPYING file packaged in the distribution. *) (** Convex Polyhedra and Linear Congruences abstract domains (PPL wrapper) *) (** This module is a wrapper around the Parma Polyhedra Library. *) type loose type strict (** Two flavors for convex polyhedra: loose or strict. Loose polyhedra cannot have strict inequality constraints like [x>0]. They are algorithmically more efficient (less generators, simpler normalization). Convex polyhedra are defined by the conjunction of a set of linear constraints of the form [a_0*x_0 + ... + a_n*x_n + b >= 0] or [a_0*x_0 + ... + a_n*x_n + b > 0] where [a_0, ..., a_n, b, c] are constants and [x_0, ..., x_n] variables. *) type grid (** Linear congruences. Linear congruences are defined by the conjunction of equality constraints modulo a rational number, of the form [a_0*x_0 + ... + a_n*x_n = b mod c], where [a_0, ..., a_n, b, c] are constants and [x_0, ..., x_n] variables. *) type 'a t (** Type of convex polyhedra/linear congruences, where ['a] is [loose], [strict] or [grid]. Abstract values which are convex polyhedra have the type [loose t Apron.AbstractX.t] or [strict t Apron.AbstractX.t]. Abstract values which are conjunction of linear congruences equalities have the type [grid t Apron.AbstractX.t]. Managers allocated by PPL have the type ['a t Apron.Manager.t]. *) (** Allocate a PPL manager for loose convex polyhedra. *) external manager_alloc_loose : unit -> loose t Apron.Manager.t = "camlidl_ppl_ap_ppl_manager_alloc_loose" (** Allocate a PPL manager for strict convex polyhedra. *) external manager_alloc_strict : unit -> strict t Apron.Manager.t = "camlidl_ppl_ap_ppl_manager_alloc_strict" (** Allocate a new manager for linear congruences (grids) *) external manager_alloc_grid : unit -> grid t Apron.Manager.t = "camlidl_ppl_ap_ppl_manager_alloc_grid" (** {2 Type conversions} *) val manager_is_ppl : 'a Apron.Manager.t -> bool val manager_is_ppl_loose : 'a Apron.Manager.t -> bool val manager_is_ppl_strict : 'a Apron.Manager.t -> bool val manager_is_ppl_grid : 'a Apron.Manager.t -> bool (** Return [true] iff the argument manager is a ppl manager *) val manager_of_ppl : 'a t Apron.Manager.t -> 'b Apron.Manager.t val manager_of_ppl_loose : loose t Apron.Manager.t -> 'a Apron.Manager.t val manager_of_ppl_strict : strict t Apron.Manager.t -> 'a Apron.Manager.t val manager_of_ppl_grid : grid t Apron.Manager.t -> 'a Apron.Manager.t (** Make a ppl manager generic *) val manager_to_ppl : 'a Apron.Manager.t -> 'b t Apron.Manager.t val manager_to_ppl_loose : 'a Apron.Manager.t -> loose t Apron.Manager.t val manager_to_ppl_strict : 'a Apron.Manager.t -> strict t Apron.Manager.t val manager_to_ppl_grid : 'a Apron.Manager.t -> grid t Apron.Manager.t (** Instanciate the type of a ppl manager. Raises [Failure] if the argument manager is not a ppl manager *) module Abstract0 : sig val is_ppl : 'a Apron.Abstract0.t -> bool val is_ppl_loose : 'a Apron.Abstract0.t -> bool val is_ppl_strict : 'a Apron.Abstract0.t -> bool val is_ppl_grid : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument manager is a ppl value *) val of_ppl : 'a t Apron.Abstract0.t -> 'b Apron.Abstract0.t val of_ppl_loose : loose t Apron.Abstract0.t -> 'a Apron.Abstract0.t val of_ppl_strict : strict t Apron.Abstract0.t -> 'a Apron.Abstract0.t val of_ppl_grid : grid t Apron.Abstract0.t -> 'a Apron.Abstract0.t (** Make a ppl value generic *) val to_ppl : 'a Apron.Abstract0.t -> 'b t Apron.Abstract0.t val to_ppl_loose : 'a Apron.Abstract0.t -> loose t Apron.Abstract0.t val to_ppl_strict : 'a Apron.Abstract0.t -> strict t Apron.Abstract0.t val to_ppl_grid : 'a Apron.Abstract0.t -> grid t Apron.Abstract0.t (** Instanciate the type of a ppl value. Raises [Failure] if the argument manager is not a ppl manager *) end module Abstract1 : sig val is_ppl : 'a Apron.Abstract1.t -> bool val is_ppl_loose : 'a Apron.Abstract1.t -> bool val is_ppl_strict : 'a Apron.Abstract1.t -> bool val is_ppl_grid : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument manager is a ppl value *) val of_ppl : 'a t Apron.Abstract1.t -> 'b Apron.Abstract1.t val of_ppl_loose : loose t Apron.Abstract1.t -> 'a Apron.Abstract1.t val of_ppl_strict : strict t Apron.Abstract1.t -> 'a Apron.Abstract1.t val of_ppl_grid : grid t Apron.Abstract1.t -> 'a Apron.Abstract1.t (** Make a ppl value generic *) val to_ppl : 'a Apron.Abstract1.t -> 'b t Apron.Abstract1.t val to_ppl_loose : 'a Apron.Abstract1.t -> loose t Apron.Abstract1.t val to_ppl_strict : 'a Apron.Abstract1.t -> strict t Apron.Abstract1.t val to_ppl_grid : 'a Apron.Abstract1.t -> grid t Apron.Abstract1.t (** Instanciate the type of a ppl value. Raises [Failure] if the argument manager is not a ppl manager *) end (** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. Do not forget the [-cc "g++"] option: PPL is a C++ library which requires a C++ linker. {3 Bytecode compilation} {[ocamlc -cc "g++"-I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \ bigarray.cma gmp.cma apron.cma ppl.cma mlexample.ml]} {[ocamlc -cc "g++" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \ bigarray.cma gmp.cma apron.cma ppl.cma ocamlc -cc "g++" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \ bigarray.cma gmp.cma apron.cma ppl.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -cc "g++" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa ppl.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -cc "g++" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa ppl.cmxa mlexample.ml \ -cclib "-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib -L$PPL_PREFIX/lib\ -lap_ppl_caml_debug -lap_ppl_debug -lppl -lgmpxx \ -lapron_caml_debug -lapron_debug \ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP_PREFIX/lib -lgmp \ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \ -lbigarray" ]} *) apron-dist-0.9.10/apron/ppl/ppl_poly.hh0000640014525101416610000003203710760562320017644 0ustar bjeannetpopart/* * ppl_poly.hh * * APRON Library / PPL library wrapper * * Wrappers specific to the Polyhedron PPL classes. * * Copyright (C) Antoine Mine' 2006 * */ /* * This file is part of the APRON Library, released under GPL license. * Please read the COPYING file packaged in the distribution. */ #ifndef __PPL_POLY_H #define __PPL_POLY_H #include "ppl.hh" using namespace std; using namespace Parma_Polyhedra_Library; class PPL_Poly { public: Polyhedron* p; size_t intdim; PPL_Poly(ap_manager_t* man, const PPL_Poly& x); PPL_Poly(ap_manager_t* man, size_t intdim, size_t realdim, Degenerate_Element kind); ~PPL_Poly(); }; #ifdef __cplusplus extern "C" { #endif /* ============================================================ */ /* A. Constructor for APRON manager (to be freed with ap_manager_free). */ /* ============================================================ */ ap_manager_t* ap_ppl_poly_manager_alloc(bool strict); /* Allocate a PPL manager for convex polyhedra. If the Boolean parameter is true, abstract values generated with the manager can have strict constraints (like x>0). Otherwise they are defined using only loose constraints. Managers and abstract values in strict or loose mode are incompatible. */ /* ********************************************************************** */ /* I. General management */ /* ********************************************************************** */ /* ============================================================ */ /* I.1 Memory */ /* ============================================================ */ PPL_Poly* ap_ppl_poly_copy(ap_manager_t* man, PPL_Poly* a); /* Return a copy of an abstract value, on which destructive update does not affect the initial value. */ void ap_ppl_poly_free(ap_manager_t* man, PPL_Poly* a); /* Free all the memory used by the abstract value */ size_t ap_ppl_poly_size(ap_manager_t* man, PPL_Poly* a); /* Return the abstract size of a polyhedron, which is the number of coefficients of its current representation, possibly redundant. */ /* ============================================================ */ /* I.2 Control of internal representation */ /* ============================================================ */ void ap_ppl_poly_minimize(ap_manager_t* man, PPL_Poly* a); /* Same as ap_ppl_poly_canonicalize */ void ap_ppl_poly_canonicalize(ap_manager_t* man, PPL_Poly* a); /* Put the polyhedron with minimized constraints and frames. If in addition the integer man->option->canonicalize.algorithm is strictly positive, normalize equalities and lines, and also strict constraints */ int ap_ppl_poly_hash(ap_manager_t* man, PPL_Poly* a); void ap_ppl_poly_approximate(ap_manager_t* man, PPL_Poly* a, int algorithm); /* Do nothing */ /* ============================================================ */ /* I.3 Printing */ /* ============================================================ */ void ap_ppl_poly_fprint(FILE* stream, ap_manager_t* man, PPL_Poly* a, char** name_of_dim); /* Print the abstract value in a pretty way, using function name_of_dim to name dimensions */ void ap_ppl_poly_fprintdiff(FILE* stream, ap_manager_t* man, PPL_Poly* a1, PPL_Poly* a2, char** name_of_dim); /* Print the difference between a1 (old value) and a2 (new value), using function name_of_dim to name dimensions. The meaning of difference is library dependent. Not implemented */ void ap_ppl_poly_fdump(FILE* stream, ap_manager_t* man, PPL_Poly* a); /* Dump the internal representation of an abstract value, for debugging purposes */ /* ============================================================ */ /* I.4 Serialization */ /* ============================================================ */ ap_membuf_t ap_ppl_poly_serialize_raw(ap_manager_t* man, PPL_Poly* a); /* Allocate a memory buffer (with malloc), output the abstract value in raw binary format to it and return a pointer on the memory buffer and the size of bytes written. It is the user responsability to free the memory afterwards (with free). Not implemented */ PPL_Poly* ap_ppl_poly_deserialize_raw(ap_manager_t* man, void* ptr, size_t* size); /* Return the abstract value read in raw binary format from the input stream and store in size the number of bytes read. Not implemented */ /* ********************************************************************** */ /* II. Constructor, accessors, tests and property extraction */ /* ********************************************************************** */ /* ============================================================ */ /* II.1 Basic constructors */ /* ============================================================ */ /* We assume that dimensions [0..intdim-1] correspond to integer variables, and dimensions [intdim..intdim+realdim-1] to real variables */ PPL_Poly* ap_ppl_poly_bottom(ap_manager_t* man, size_t intdim, size_t realdim); /* Create a bottom (empty) value */ PPL_Poly* ap_ppl_poly_top(ap_manager_t* man, size_t intdim, size_t realdim); /* Create a top (universe) value */ PPL_Poly* ap_ppl_poly_of_box(ap_manager_t* man, size_t intdim, size_t realdim, ap_interval_t** tinterval); /* Abstract an hypercube defined by the array of intervals of size intdim+realdim */ /* ============================================================ */ /* II.2 Accessors */ /* ============================================================ */ ap_dimension_t ap_ppl_poly_dimension(ap_manager_t* man, PPL_Poly* a); /* Return the total number of dimensions of the abstract values */ /* ============================================================ */ /* II.3 Tests */ /* ============================================================ */ bool ap_ppl_poly_is_bottom(ap_manager_t* man, PPL_Poly* a); /* Emptiness test */ bool ap_ppl_poly_is_top(ap_manager_t* man, PPL_Poly* a); /* Universe test */ bool ap_ppl_poly_is_leq(ap_manager_t* man, PPL_Poly* a1, PPL_Poly* a2); /* Inclusion test */ bool ap_ppl_poly_is_eq(ap_manager_t* man, PPL_Poly* a1, PPL_Poly* a2); /* Equality test */ bool ap_ppl_poly_sat_lincons(ap_manager_t* man, PPL_Poly* a, ap_lincons0_t* lincons); /* Satisfiability of a linear constraint */ bool ap_ppl_poly_sat_tcons(ap_manager_t* man, PPL_Poly* a, ap_tcons0_t* cons); /* Satisfiability of a tree expression constraint. */ bool ap_ppl_poly_sat_interval(ap_manager_t* man, PPL_Poly* a, ap_dim_t dim, ap_interval_t* interval); /* Inclusion of a dimension in an interval */ bool ap_ppl_poly_is_dimension_unconstrained(ap_manager_t* man, PPL_Poly* po, ap_dim_t dim); /* Is a dimension unconstrained ? */ /* ============================================================ */ /* II.4 Extraction of properties */ /* ============================================================ */ ap_interval_t* ap_ppl_poly_bound_linexpr(ap_manager_t* man, PPL_Poly* a, ap_linexpr0_t* expr); /* Returns the interval taken by a linear expression over the abstract value. */ ap_interval_t* ap_ppl_poly_bound_texpr(ap_manager_t* man, PPL_Poly* a, ap_texpr0_t* expr); /* Returns the interval taken by a tree expression over the abstract value. */ ap_interval_t* ap_ppl_poly_bound_dimension(ap_manager_t* man, PPL_Poly* a, ap_dim_t dim); /* Returns the interval taken by the dimension over the abstract value. */ ap_lincons0_array_t ap_ppl_poly_to_lincons_array(ap_manager_t* man, PPL_Poly* a); /* Converts an abstract value to a polyhedra (conjunction of linear constraints). */ ap_tcons0_array_t ap_ppl_poly_to_tcons_array(ap_manager_t* man, PPL_Poly* a); /* Converts an abstract value to a conjunction of tree expressions constraints. */ ap_interval_t** ap_ppl_poly_to_box(ap_manager_t* man, PPL_Poly* a); /* Converts an abstract value to an interval/hypercube. The size of the resulting array is ap_ppl_poly_dimension(man,a). */ ap_generator0_array_t ap_ppl_poly_to_generator_array(ap_manager_t* man, PPL_Poly* a); /* Converts an abstract value to a system of generators. */ /* ********************************************************************** */ /* III. Operations */ /* ********************************************************************** */ /* ============================================================ */ /* III.1 Meet and Join */ /* ============================================================ */ PPL_Poly* ap_ppl_poly_meet(ap_manager_t* man, bool destructive, PPL_Poly* a1, PPL_Poly* a2); PPL_Poly* ap_ppl_poly_join(ap_manager_t* man, bool destructive, PPL_Poly* a1, PPL_Poly* a2); /* Meet and Join of 2 abstract values */ PPL_Poly* ap_ppl_poly_meet_array(ap_manager_t* man, PPL_Poly** tab, size_t size); PPL_Poly* ap_ppl_poly_join_array(ap_manager_t* man, PPL_Poly** tab, size_t size); /* Meet and Join of a non-empty array of abstract values. (no way to define the dimensionality of the result in such a case */ PPL_Poly* ap_ppl_poly_meet_lincons_array(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_lincons0_array_t* array); /* Meet of an abstract value with a set of constraints (generalize ap_ppl_poly_of_lincons_array) */ PPL_Poly* ap_ppl_poly_meet_tcons_array(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_tcons0_array_t* array); /* Meet of an abstract value with a set of tree expressionsconstraints. */ PPL_Poly* ap_ppl_poly_add_ray_array(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_generator0_array_t* array); /* Generalized time elapse operator */ /* ============================================================ */ /* III.2 Assignement and Substitutions */ /* ============================================================ */ PPL_Poly* ap_ppl_poly_assign_linexpr_array(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, PPL_Poly* dest); PPL_Poly* ap_ppl_poly_substitute_linexpr_array(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, PPL_Poly* dest); PPL_Poly* ap_ppl_poly_assign_texpr_array(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, PPL_Poly* dest); PPL_Poly* ap_ppl_poly_substitute_texpr_array(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, PPL_Poly* dest); /* Parallel Assignement and Substitution of several dimensions by expressons. */ /* ============================================================ */ /* III.3 Projections */ /* ============================================================ */ PPL_Poly* ap_ppl_poly_forget_array(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_dim_t* tdim, size_t size, bool project); /* ============================================================ */ /* III.4 Change and permutation of dimensions */ /* ============================================================ */ PPL_Poly* ap_ppl_poly_add_dimensions(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_dimchange_t* dimchange, bool project); PPL_Poly* ap_ppl_poly_remove_dimensions(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_dimchange_t* dimchange); PPL_Poly* ap_ppl_poly_permute_dimensions(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_dimperm_t* permutation); /* ============================================================ */ /* III.5 Expansion and folding of dimensions */ /* ============================================================ */ PPL_Poly* ap_ppl_poly_expand(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_dim_t dim, size_t n); /* Expand the dimension dim into itself + n additional dimensions. It results in (n+1) unrelated dimensions having same relations with other dimensions. The (n+1) dimensions are put as follows: - original dimension dim - if the dimension is integer, the n additional dimensions are put at the end of integer dimensions; if it is real, at the end of the real dimensions. */ PPL_Poly* ap_ppl_poly_fold(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_dim_t* tdim, size_t size); /* Fold the dimensions in the array tdim of size n>=1 and put the result in the first dimension in the array. The other dimensions of the array are then removed (using ap_ppl_poly_permute_remove_dimensions). */ /* ============================================================ */ /* III.6 Widening */ /* ============================================================ */ /* Widening */ PPL_Poly* ap_ppl_poly_widening(ap_manager_t* man, PPL_Poly* a1, PPL_Poly* a2); /* ============================================================ */ /* III.7 Closure operation */ /* ============================================================ */ /* Returns the topological closure of a possibly opened abstract value */ PPL_Poly* ap_ppl_poly_closure(ap_manager_t* man, bool destructive, PPL_Poly* a); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/ppl/ppl_user.cc0000640014525101416610000004634111144120547017626 0ustar bjeannetpopart/* * ppl_user.cc * * APRON Library / PPL library wrapper * * Conversion between APRON user types and PPL classes. * These are shared by all PPL wrappers. * * Copyright (C) Antoine Mine' 2006 * */ /* * This file is part of the APRON Library, released under GPL license. * Please read the COPYING file packaged in the distribution. */ #include #include #include "ppl_user.hh" extern "C" ppl_internal_t* ap_ppl_internal_alloc(bool strict) { ppl_internal_t* intern = (ppl_internal_t*)malloc(sizeof(ppl_internal_t)); intern->strict = strict; intern->itv = itv_internal_alloc(); return intern; } extern "C" void ap_ppl_internal_free(void* internal) { ppl_internal_t* intern = (ppl_internal_t*)internal; itv_internal_free(intern->itv); free(intern); } /* ********************************************************************** */ /* Conversions from PPL to APRON */ /* ********************************************************************** */ /* Constraint => ap_lincons0_t (exact) */ ap_lincons0_t ap_ppl_to_lincons(const Constraint& c) { ap_constyp_t t; ap_linexpr0_t* e; int i, n = c.space_dimension(); /* special, inconsistent case */ if (c.is_inconsistent()) return ap_lincons0_make_unsat(); /* other cases */ e = ap_linexpr0_alloc(AP_LINEXPR_DENSE,n); assert(e); /* variable coefficients */ for (i=0;ip.coeff[i].val.scalar,c.coefficient(Variable(i))); /* constant coefficient */ ap_ppl_mpz_to_scalar(e->cst.val.scalar,c.inhomogeneous_term()); /* constraint type */ if (c.is_nonstrict_inequality()) t = AP_CONS_SUPEQ; else if (c.is_equality()) t = AP_CONS_EQ; else if (c.is_strict_inequality()) t = AP_CONS_SUP; else throw invalid_argument("Constraint type in ap_ppl_to_lincons"); return ap_lincons0_make(t,e,NULL); } /* Constraint_System => ap_lincons0_array_t (exact) */ ap_lincons0_array_t ap_ppl_to_lincons_array(const Constraint_System& c) { ap_lincons0_array_t a; Constraint_System::const_iterator i, end = c.end(); int k; /* first, compute system size */ for (i=c.begin(),k=0;i!=end;i++,k++); a = ap_lincons0_array_make(k); /* then, convert constraints */ for (i=c.begin(),k=0;i!=end;i++,k++) a.p[k] = ap_ppl_to_lincons(*i); return a; } /* Congruence => ap_lincons0_t (exact) */ ap_lincons0_t ap_ppl_to_lincons(const Congruence& c) { ap_constyp_t t; ap_linexpr0_t* e; int i, n = c.space_dimension(); /* special, inconsistent case */ #ifndef PPL_0_9 if (c.is_inconsistent()) #else if (c.is_trivial_false()) #endif return ap_lincons0_make_unsat(); /* other cases */ e = ap_linexpr0_alloc(AP_LINEXPR_DENSE,n); assert(e); /* variable coefficients */ for (i=0;ip.coeff[i].val.scalar,c.coefficient(Variable(i))); /* constant coefficient */ ap_ppl_mpz_to_scalar(e->cst.val.scalar,c.inhomogeneous_term()); /* constraint type */ if (c.is_equality()) return ap_lincons0_make(AP_CONS_EQ,e,NULL); else { ap_scalar_t* mod = ap_scalar_alloc(); ap_ppl_mpz_to_scalar(mod,c.modulus()); return ap_lincons0_make(AP_CONS_EQMOD,e,mod); } } /* Congruence_System => ap_lincons0_array_t (exact) */ ap_lincons0_array_t ap_ppl_to_lincons_array(const Congruence_System& c) { ap_lincons0_array_t a; Congruence_System::const_iterator i, end = c.end(); int k; /* first, compute system size */ for (i=c.begin(),k=0;i!=end;i++,k++); a = ap_lincons0_array_make(k); /* then, convert constraints */ for (i=c.begin(),k=0;i!=end;i++,k++) a.p[k] = ap_ppl_to_lincons(*i); return a; } /* ====================================================================== */ /* Generators */ /* ====================================================================== */ /* Generator => ap_generator0_t */ ap_generator0_t ap_ppl_to_generator(const Generator& c, bool& exact) { ap_gentyp_t t; ap_linexpr0_t* e; int i, n = c.space_dimension(); e = ap_linexpr0_alloc(AP_LINEXPR_DENSE,n); assert(e); exact = true; ap_linexpr0_set_cst_scalar_int(e,0); if (c.is_ray() || c.is_line()) { /* ray or line: no divisor */ for (i=0;ip.coeff[i].val.scalar,c.coefficient(Variable(i))); return ap_generator0_make(c.is_ray() ? AP_GEN_RAY : AP_GEN_LINE,e); } else { /* point or closure point: has divisor */ const mpz_class& div = c.divisor(); if (c.is_closure_point()) exact = false; for (i=0;ip.coeff[i].val.scalar,c.coefficient(Variable(i)),div); return ap_generator0_make(AP_GEN_VERTEX,e); } } /* Generator_System => ap_generator0_array_t */ ap_generator0_array_t ap_ppl_to_generator_array(const Generator_System& c, bool& exact) { ap_generator0_array_t a; Generator_System::const_iterator i, end = c.end(); int k; bool exact2; exact = true; /* first, compute system size */ for (i=c.begin(),k=0;i!=end;i++,k++); a = ap_generator0_array_make(k); /* then, convert generators */ for (i=c.begin(),k=0;i!=end;i++,k++){ a.p[k] = ap_ppl_to_generator(*i,exact2); exact = exact && exact2; } return a; } /* Grid_Generator => ap_generator0_t (exact) */ ap_generator0_t ap_ppl_to_generator(const Grid_Generator& c) { ap_gentyp_t t; ap_linexpr0_t* e; int i, n = c.space_dimension(); e = ap_linexpr0_alloc(AP_LINEXPR_DENSE,n); assert(e); ap_linexpr0_set_cst_scalar_int(e,0); if (c.is_line()) { /* line: no divisor */ for (i=0;ip.coeff[i].val.scalar,c.coefficient(Variable(i))); return ap_generator0_make(AP_GEN_LINE,e); } else { /* point or parameter: has divisor */ const mpz_class& div = c.divisor(); for (i=0;ip.coeff[i].val.scalar,c.coefficient(Variable(i)),div); return ap_generator0_make(c.is_point() ? AP_GEN_VERTEX : AP_GEN_LINEMOD,e); } } /* Grid_Generator_System => ap_generator0_array_t (exact) */ ap_generator0_array_t ap_ppl_to_generator_array(const Grid_Generator_System& c) { ap_generator0_array_t a; Grid_Generator_System::const_iterator i, end = c.end(); int k; /* first, compute system size */ for (i=c.begin(),k=0;i!=end;i++,k++); a = ap_generator0_array_make(k); /* then, convert generators */ for (i=c.begin(),k=0;i!=end;i++,k++){ a.p[k] = ap_ppl_to_generator(*i); } return a; } /* whole universe as a generator system */ ap_generator0_array_t ap_ppl_generator_universe(size_t dim) { ap_generator0_array_t ar = ap_generator0_array_make(dim+1); /* origin vertex */ ar.p[0] = ap_generator0_make(AP_GEN_VERTEX,ap_linexpr0_alloc(AP_LINEXPR_SPARSE,0)); /* one line for each dimension */ for (size_t i=0;ip.linterm[0].dim = i; ap_coeff_set_scalar_int(&e->p.linterm[0].coeff,1); ar.p[i+1] = ap_generator0_make(AP_GEN_LINE,e); } return ar; } /* ********************************************************************** */ /* Conversions from APRON to PPL */ /* ********************************************************************** */ /* ====================================================================== */ /* Boxes */ /* ====================================================================== */ /* whole universe as a box */ void ap_ppl_box_universe(ap_interval_t** i,size_t nb) { for (size_t j=0;j Constraint_System (return exactness) */ bool ap_ppl_of_box(Constraint_System& r, ap_interval_t** a, size_t intdim, size_t realdim) { bool exact = true; size_t i; mpq_class temp; size_t nb = intdim+realdim; mpq_ptr mpq = temp.get_mpq_t(); r.clear(); for (i=0;iinf)) { case 0: exact = !ap_mpq_set_scalar(mpq,a[i]->inf,GMP_RNDD) && exact; if (i= temp.get_num() )); break; case -1: break; case 1: r = Constraint_System::zero_dim_empty(); return true; default: assert(0); } /* sup */ switch (ap_scalar_infty(a[i]->sup)) { case 0: exact = !ap_mpq_set_scalar(mpq,a[i]->sup,GMP_RNDU) && exact; if (i Congruence_System (return exactness) */ bool ap_ppl_of_box(Congruence_System& r, ap_interval_t** a, size_t intdim, size_t realdim) { bool exact = true; size_t i; mpq_class temp; size_t nb = intdim+realdim; r.clear(); for (i=0;iinf); int sup = ap_scalar_infty(a[i]->sup); /* unsatisfiable */ if (inf==1 || sup==-1) { r = Congruence_System::zero_dim_empty(); return true; } /* no-singleton */ if (inf || sup || !ap_scalar_equal(a[i]->inf,a[i]->sup) || ap_mpq_set_scalar(temp.get_mpq_t(),a[i]->inf,GMP_RNDD)) { exact = false; } /* singleton */ else r.insert(Constraint(Variable(i)==temp)); } return exact; } /* ====================================================================== */ /* Linear expressions */ /* ====================================================================== */ /* Assume a quasilinear expressions, with the selected bound of constant coefficient different from +oo */ bool ap_ppl_of_itv_linexpr(Linear_Expression& r, mpz_class& den, itv_linexpr_t* linexpr, int mode) { mpq_class temp; size_t i; ap_dim_t dim; itv_ptr pitv; bool* peq; mpz_set_ui(den.get_mpz_t(),1); if (mode>0){ if (bound_infty(linexpr->cst->sup)){ throw cannot_convert(); abort(); } if (bound_sgn(linexpr->cst->sup)) mpz_set(den.get_mpz_t(),numrat_denref(bound_numref(linexpr->cst->sup))); } else if (mode < 0){ if (bound_infty(linexpr->cst->inf)){ throw cannot_convert(); abort(); } if (bound_sgn(linexpr->cst->inf)) mpz_set(den.get_mpz_t(),numrat_denref(bound_numref(linexpr->cst->inf))); } else { assert(0); } r = Linear_Expression::zero(); /* compute lcm of denominators in den */ itv_linexpr_ForeachLinterm(linexpr,i,dim,pitv,peq){ assert(*peq); mpz_lcm(den.get_mpz_t(),den.get_mpz_t(),numrat_denref(bound_numref(pitv->sup))); } /* add variable coefficients * den */ itv_linexpr_ForeachLinterm(linexpr,i,dim,pitv,peq){ mpq_set(temp.get_mpq_t(),bound_numref(pitv->sup)); temp *= den; r += Variable(dim) * temp.get_num(); } /* add constant coefficient * den */ if (mode>0){ mpq_set(temp.get_mpq_t(),bound_numref(linexpr->cst->sup)); } else { mpq_neg(temp.get_mpq_t(),bound_numref(linexpr->cst->inf)); } temp *= den; r += temp.get_num(); return true; } /* ap_linexpr0_t => ppl */ /* linearize if titv!=NULL */ void ap_ppl_of_linexpr(itv_internal_t* intern, Linear_Expression& r, mpz_class& den, ap_linexpr0_t* c, int mode) { itv_linexpr_t linexpr; itv_linexpr_init(&linexpr,0); itv_linexpr_set_ap_linexpr0(intern,&linexpr,c); ap_ppl_of_itv_linexpr(r,den,&linexpr,mode); itv_linexpr_clear(&linexpr); } /* ====================================================================== */ /* Constraints */ /* ====================================================================== */ bool ap_ppl_of_itv_lincons(Constraint& r, mpz_class& den, itv_lincons_t* lincons, bool allow_strict) { Linear_Expression l; ap_ppl_of_itv_linexpr(l,den,&lincons->linexpr,1); switch (lincons->constyp) { case AP_CONS_SUPEQ: r = ( l >= 0 ); return true; case AP_CONS_EQ: r = ( l == 0 ); return true; case AP_CONS_SUP: if (allow_strict) { r = ( l > 0 ); return true; } else { r = (l >= 0); return false; } case AP_CONS_EQMOD: if (numrat_sgn(lincons->num)==0){ r = ( l == 0 ); return true; } else { throw cannot_convert(); } case AP_CONS_DISEQ: throw cannot_convert(); default: throw invalid_argument("Constraint type in ap_ppl_of_lincons"); } } /* ap_lincons0_t => Constraint (may raise cannot_convert, return exact) */ /* congruences are overapproximated as linear equalities */ bool ap_ppl_of_lincons(itv_internal_t* intern, Constraint& r,ap_lincons0_t* c,bool allow_strict) { itv_lincons_t lincons; mpz_class den; itv_lincons_init(&lincons); bool exact = itv_lincons_set_ap_lincons0(intern,&lincons,c); exact = ap_ppl_of_itv_lincons(r,den,&lincons,allow_strict) && exact; itv_lincons_clear(&lincons); return exact; } bool ap_ppl_of_itv_lincons(Congruence& r, mpz_class& den, itv_lincons_t* c) { Linear_Expression l; if (!itv_linexpr_is_scalar(&c->linexpr)){ throw cannot_convert(); } ap_ppl_of_itv_linexpr(l,den,&c->linexpr,1); switch (c->constyp) { case AP_CONS_SUPEQ: case AP_CONS_SUP: case AP_CONS_DISEQ: throw cannot_convert(); case AP_CONS_EQ: r = ( l %= 0 ) / 0; break; case AP_CONS_EQMOD: if (num_sgn(c->num)==0){ r = ( l %= 0 ) / 0; } else { mpq_class mod; num_set(mod.get_mpq_t(),c->num); r = ( l * mod.get_den() %= 0) / mod.get_num(); } break; default: throw invalid_argument("Constraint type in ap_ppl_of_lincons"); } return true; } /* ap_lincons0_t => Congruence (may raise cannot_convert, return exact) */ bool ap_ppl_of_lincons(itv_internal_t* intern, Congruence& r,ap_lincons0_t* c) { itv_lincons_t lincons; mpz_class den; itv_lincons_init(&lincons); bool exact = itv_lincons_set_ap_lincons0(intern,&lincons,c); exact = ap_ppl_of_itv_lincons(r,den,&lincons) && exact; itv_lincons_clear(&lincons); return exact; } /* ap_lincons0_array_t => Constraint_System returns true if exact (some constraint was dropped or approximated) */ bool ap_ppl_of_itv_lincons_array(Constraint_System& r, mpz_class& den, itv_lincons_array_t* a, bool allow_strict) { bool exact = true; size_t i; Constraint c = Constraint::zero_dim_positivity(); r.clear(); for (i=0;isize;i++) { try { exact = ap_ppl_of_itv_lincons(c,den,&a->p[i],allow_strict) && exact; r.insert(c); } catch (cannot_convert w) { exact = false; } } return exact; } /* ap_lincons0_array_t => Constraint_System returns true if exact (some constraint was dropped or approximated) */ bool ap_ppl_of_lincons_array(itv_internal_t* intern, Constraint_System& r, ap_lincons0_array_t* a,bool allow_strict) { itv_lincons_array_t array; mpz_class den; itv_lincons_array_init(&array,a->size); bool exact = itv_lincons_array_set_ap_lincons0_array(intern,&array,a); exact = ap_ppl_of_itv_lincons_array(r,den,&array,allow_strict) && exact; itv_lincons_array_clear(&array); return exact; } /* ap_lincons0_array_t => Constraint_System returns true if exact (some constraint was dropped or approximated) */ bool ap_ppl_of_itv_lincons_array(Congruence_System& r, mpz_class& den, itv_lincons_array_t* a) { bool exact = true; size_t i; Congruence c = Congruence::zero_dim_false(); r.clear(); for (i=0;isize;i++) { try { exact = ap_ppl_of_itv_lincons(c,den,&a->p[i]) && exact; r.insert(c); } catch (cannot_convert w) { exact = false; } } return exact; } /* ap_lincons0_array_t => Congruence_System returns true if exact (some constraint was dropped or approximated) */ bool ap_ppl_of_lincons_array(itv_internal_t* intern, Congruence_System& r,ap_lincons0_array_t* a) { itv_lincons_array_t array; mpz_class den; itv_lincons_array_init(&array,a->size); bool exact = itv_lincons_array_set_ap_lincons0_array(intern,&array,a); exact = ap_ppl_of_itv_lincons_array(r,den,&array) && exact; itv_lincons_array_clear(&array); return exact; } /* ap_generator0_t => Generator (may raise cannot_convert, or return true) */ bool ap_ppl_of_generator(itv_internal_t* intern, Generator& r, ap_generator0_t* c) { Linear_Expression l; mpz_class den; if (!ap_linexpr0_is_linear(c->linexpr0)){ throw cannot_convert(); } ap_ppl_of_linexpr(intern,l,den,c->linexpr0,1); switch (c->gentyp) { case AP_GEN_VERTEX: r = Generator::point(l,den); return true; case AP_GEN_RAY: r = Generator::ray(l); return true; case AP_GEN_LINE: r = Generator::line(l); return true; case AP_GEN_RAYMOD: r = Generator::ray(l); return false; case AP_GEN_LINEMOD: r = Generator::line(l); return false; default: throw invalid_argument("Generator type in ap_ppl_of_generator"); } } /* Test if the linear part of the generator is 0 Needed because PPL refuses non-vertex generators with such expressions */ bool ap_ppl_ap_generator0_select(ap_generator0_t* g) { if (g->gentyp==AP_GEN_VERTEX) { return true; } else { size_t i; ap_dim_t dim; ap_coeff_t* coeff; ap_linexpr0_t* e = g->linexpr0; bool res = false; ap_linexpr0_ForeachLinterm(e,i,dim,coeff){ if (ap_coeff_zero(coeff)==false){ res = true; break; } } return res; } } /* ap_generator0_array_t => Generator_System (may raise cannot_convert, or return false) */ bool ap_ppl_of_generator_array(itv_internal_t* intern, Generator_System& r, ap_generator0_array_t* a) { bool exact = true; size_t i; Generator c = Generator::zero_dim_point(); r.clear(); for (i=0;isize;i++) { if (ap_ppl_ap_generator0_select(&a->p[i])){ exact = ap_ppl_of_generator(intern,c,&a->p[i]) && exact; r.insert(c); } } return exact; } /* ap_generator0_t => Grid_Generator (may raise cannot_convert, or return true) */ bool ap_ppl_of_generator(itv_internal_t* intern, Grid_Generator& r, ap_generator0_t* c) { Linear_Expression l; mpz_class den; if (!ap_linexpr0_is_linear(c->linexpr0)){ throw cannot_convert(); } ap_ppl_of_linexpr(intern,l,den,c->linexpr0,1); switch (c->gentyp) { #ifndef PPL_0_9 case AP_GEN_VERTEX: r = Grid_Generator::grid_point(l,den); return true; case AP_GEN_RAY: r = Grid_Generator::grid_line(l); return false; case AP_GEN_LINE: r = Grid_Generator::grid_line(l); return true; #else case AP_GEN_VERTEX: r = Grid_Generator::point(l,den); return true; case AP_GEN_RAY: r = Grid_Generator::line(l); return false; case AP_GEN_LINE: r = Grid_Generator::line(l); return true; #endif case AP_GEN_RAYMOD: r = Grid_Generator::parameter(l,den); return false; case AP_GEN_LINEMOD: r = Grid_Generator::parameter(l,den); return true; default: throw invalid_argument("Generator type in ap_ppl_of_generator"); } } /* ap_generator0_array_t => Grid_Generator_System (may raise cannot_convert, or return true) */ bool ap_ppl_of_generator_array(itv_internal_t* intern, Grid_Generator_System& r,ap_generator0_array_t* a) { bool exact = true; size_t i; #ifndef PPL_0_9 Grid_Generator c = Grid_Generator::grid_point(); #else Grid_Generator c = Grid_Generator::point(); #endif r.clear(); for (i=0;isize;i++) { if (ap_ppl_ap_generator0_select(&a->p[i])){ exact = ap_ppl_of_generator(intern,c,&a->p[i]) && exact; r.insert(c); } } return exact; } apron-dist-0.9.10/apron/ppl/ppl_test.c0000640014525101416610000006073510723557216017500 0ustar bjeannetpopart/* * ppl_test.c * * Unit testing. Compares NewPolka & PPL implementations. * * APRON Library / PPL library wrapper * * Copyright (C) Antoine Mine' 2006 * */ /* This file is part of the APRON Library, released under GPL license. Please read the COPYING file packaged in the distribution. */ #include #include #include #include #include "ap_global0.h" #include "pk.h" #include "ap_ppl.h" ap_manager_t* ppl; ap_manager_t* pk; int intdim; /* utilities */ /* ********* */ void random_interval(ap_interval_t* i) { int n1 = rand()%20-10; int n2 = n1 + rand()%20; int d = rand()%3+1; ap_interval_set_frac(i,n1,d,n2,d); } /* random affine expression */ ap_linexpr0_t* random_linexpr(int dim) { ap_linexpr0_t* l = ap_linexpr0_alloc(AP_LINEXPR_DENSE,dim); int i; for (i=0;ip.coeff+i,rand()%20-10,rand()%4+1); ap_coeff_set_scalar_frac(&l->cst,rand()%20-10,rand()%4+1); return l; } /* random affine expression with scalar constant coefficient */ ap_linexpr0_t* random_linexpr_inter(int dim) { ap_linexpr0_t* l = random_linexpr(dim); int n1 = rand()%20-10; int n2 = n1 + rand()%20; int d = rand()%4+1; ap_linexpr0_set_cst_interval_frac(l,n1,d,n2,d); return l; } /* random generator of specified type */ ap_generator0_t random_generator(int dim, ap_gentyp_t g) { ap_linexpr0_t* l = ap_linexpr0_alloc(AP_LINEXPR_DENSE,dim); int i; for (i=0;ip.coeff+i,rand()%20-2,rand()%4+1); ap_coeff_set_scalar_int(&l->cst,1); return ap_generator0_make(g,l); } /* random polyhedron */ ap_abstract0_t* random_poly(ap_manager_t* man,int dim) { int i; ap_abstract0_t* p; ap_interval_t** t = ap_interval_array_alloc(dim); ap_generator0_array_t ar = ap_generator0_array_make(dim); for (i=0;i=90)?AP_GEN_RAY:AP_GEN_VERTEX); //ap_generator0_array_fprint(stderr,&ar,NULL); if (intdim) p = ap_abstract0_of_box(man,dim/2,dim-dim/2,(ap_interval_t**)t); else p = ap_abstract0_of_box(man,0,dim,(ap_interval_t**)t); ap_abstract0_add_ray_array(man,true,p,&ar); ap_generator0_array_clear(&ar); ap_interval_array_free(t,dim); return p; } /* convert to specified manager */ ap_abstract0_t* convert(ap_manager_t* man, ap_abstract0_t* a) { ap_lincons0_array_t l; ap_dimension_t d = ap_abstract0_dimension(a->man,a); if (a->man==man) return a; l = ap_abstract0_to_lincons_array(a->man,a); a = ap_abstract0_of_lincons_array(man,d.intdim,d.realdim,&l); ap_lincons0_array_clear(&l); return a; } /* compare */ bool is_eq(ap_abstract0_t* a1,ap_abstract0_t* a2) { ap_abstract0_t* aa2 = convert(a1->man,a2); bool r = ap_abstract0_is_eq(a1->man,a1,aa2); if (a2!=aa2) ap_abstract0_free(aa2->man,aa2); return r; } /* print */ void print_poly(const char* msg, ap_abstract0_t* p) { fprintf(stderr,"%s (%s) = ",msg,p->man->library); ap_abstract0_fprint(stderr,p->man,p,NULL); ap_abstract0_fdump(stderr,p->man,p); fprintf(stderr,"\n"); } /* loop */ /* **** */ #define N 70 char b1_[N+4]= " ["; char b2_[N+4]; int i_; int error_ = 0; #define LOOP \ { \ memset(b1_+2,' ',N); b1_[N+2]=']'; b1_[N+3]=0; \ memset(b2_,8,N+3); b2_[N+3]=0; \ for (i_=0;i_intdim+a->realdim;i++) { a->dim[i] = rand()%3; if (i) a->dim[i] += a->dim[i-1]; if (a->dim[i]intdim++; a->realdim--; } assert(a->dim[i]intdim+a->realdim;i++) { a->dim[i] = rand()%3 + 1; if (i) a->dim[i] += a->dim[i-1]; if (a->dim[i]intdim++; a->realdim--; } assert(a->dim[i]intdim+a->realdim;i++) { a->dim[i] = rand()%3 + 1; if (i) a->dim[i] += a->dim[i-1]; if (a->dim[i]intdim++; a->realdim--; } assert(a->dim[i]dim,a->realdim,proj); pplr = ap_abstract0_forget_array(ppl,false,ppla,a->dim,a->realdim,proj); RESULT('*'); if (!is_eq(pkr,pplr)) { ERROR("different results"); ap_dimchange_fprint(stderr,a); print_poly("pka",pka); print_poly("pkr",pkr); print_poly("pplr",pplr); } ap_abstract0_free(pk,pka); ap_abstract0_free(ppl,ppla); ap_abstract0_free(pk,pkr); ap_abstract0_free(ppl,pplr); ap_dimchange_free(a); } ENDLOOP; } void test_permute(void) { printf("\npermute dimensions\n"); LOOP { size_t i, dim = 6; ap_dimperm_t* p = ap_dimperm_alloc(dim); ap_abstract0_t* pka,*pkr, *ppla,*pplr; ap_dimension_t d; pka = random_poly(pk,dim); ppla = convert(ppl,pka); d = ap_abstract0_dimension(pk,pka); /* random permutation */ ap_dimperm_set_id(p); for (i=0;isize-1;i++) { int a, j; if (idim[j]; p->dim[j] = p->dim[i]; p->dim[i] = a; } pkr = ap_abstract0_permute_dimensions(pk,false,pka,p); pplr = ap_abstract0_permute_dimensions(ppl,false,ppla,p); RESULT('*'); if (!is_eq(pkr,pplr)) { ERROR("different results"); ap_dimperm_fprint(stderr,p); print_poly("pka",pka); print_poly("pkr",pkr); print_poly("pplr",pplr); } ap_abstract0_free(pk,pka); ap_abstract0_free(ppl,ppla); ap_abstract0_free(pk,pkr); ap_abstract0_free(ppl,pplr); ap_dimperm_free(p); } ENDLOOP; } void test_expand(void) { printf("\nexpand dimensions\n"); LOOP { size_t i, dim = 6; ap_dim_t dd = rand() % dim; size_t n = (rand() % 2) + 1; ap_abstract0_t* pka,*pkr, *ppla,*pplr; ap_dimension_t d; pka = random_poly(pk,dim); ppla = convert(ppl,pka); d = ap_abstract0_dimension(pk,pka); pkr = ap_abstract0_expand(pk,false,pka,dd,n); pplr = ap_abstract0_expand(ppl,false,ppla,dd,n); RESULT('*'); if (!is_eq(pkr,pplr)) { ERROR("different results"); fprintf(stderr,"dim %i expanded %i times\n",(int)dd,(int)n); print_poly("pka",pka); print_poly("pkr",pkr); print_poly("pplr",pplr); } ap_abstract0_free(pk,pka); ap_abstract0_free(ppl,ppla); ap_abstract0_free(pk,pkr); ap_abstract0_free(ppl,pplr); } ENDLOOP; } void test_fold(void) { printf("\nfold dimensions\n"); LOOP { size_t i, dim = 6; ap_dim_t dd[3]; ap_abstract0_t* pka,*pkr, *ppla,*pplr; ap_dimension_t d; pka = random_poly(pk,dim); ppla = convert(ppl,pka); d = ap_abstract0_dimension(pk,pka); do { dd[0] = rand() % dim; if (dd[0]=dd[1]); pkr = ap_abstract0_fold(pk,false,pka,dd,2); pplr = ap_abstract0_fold(ppl,false,ppla,dd,2); RESULT('*'); if (!is_eq(pkr,pplr)) { ERROR("different results"); fprintf(stderr,"fold %i,%i,%i\n",(int)dd[0],(int)dd[1],(int)dd[2]); print_poly("pka",pka); print_poly("pkr",pkr); print_poly("pplr",pplr); } ap_abstract0_free(pk,pka); ap_abstract0_free(ppl,ppla); ap_abstract0_free(pk,pkr); ap_abstract0_free(ppl,pplr); } ENDLOOP; } void test_add_lincons(void) { printf("\nadd lincons\n"); LOOP { size_t i, dim = 6, nb = 4; ap_abstract0_t* pka,*pkr, *ppla,*pplr; ap_lincons0_array_t ar = ap_lincons0_array_make(nb); pka = random_poly(pk,dim); ppla = convert(ppl,pka); for (i=0;i=90)?AP_CONS_EQ: (rand()%100>=90)?AP_CONS_SUP:AP_CONS_SUPEQ, random_linexpr(dim),NULL); } pkr = ap_abstract0_meet_lincons_array(pk,false,pka,&ar); pplr = ap_abstract0_meet_lincons_array(ppl,false,ppla,&ar); RESULT('*'); if (!is_eq(pkr,pplr)) { ERROR("different results"); ap_lincons0_array_fprint(stderr,&ar,NULL); print_poly("pka",pka); print_poly("pkr",pkr); print_poly("pplr",pplr); } ap_abstract0_free(pk,pka); ap_abstract0_free(ppl,ppla); ap_abstract0_free(pk,pkr); ap_abstract0_free(ppl,pplr); ap_lincons0_array_clear(&ar); } ENDLOOP; } void test_add_ray(void) { printf("\nadd rays\n"); LOOP { size_t i, dim = 4, nb = 4; ap_abstract0_t* pka,*pkr, *ppla,*pplr; ap_generator0_array_t ar = ap_generator0_array_make(nb); pka = random_poly(pk,dim); ppla = convert(ppl,pka); for (i=0;i=80)?AP_GEN_LINE:AP_GEN_RAY); pkr = ap_abstract0_add_ray_array(pk,false,pka,&ar); pplr = ap_abstract0_add_ray_array(ppl,false,ppla,&ar); RESULT('*'); if (!is_eq(pkr,pplr)) { ERROR("different results"); ap_generator0_array_fprint(stderr,&ar,NULL); print_poly("pka",pka); print_poly("pkr",pkr); print_poly("pplr",pplr); } ap_abstract0_free(pk,pka); ap_abstract0_free(ppl,ppla); ap_abstract0_free(pk,pkr); ap_abstract0_free(ppl,pplr); ap_generator0_array_clear(&ar); } ENDLOOP; } void test_box(void) { printf("\nbox conversion\n"); LOOP { size_t i, dim = 6; ap_abstract0_t* pka,*pkr, *ppla,*pplr; ap_interval_t** pki,**ppli; pka = random_poly(pk,dim); ppla = convert(ppl,pka); pki = ap_abstract0_to_box(pk,pka); ppli = ap_abstract0_to_box(ppl,ppla); pkr = ap_abstract0_of_box(pk,0,dim,(ap_interval_t**)pki); pplr = ap_abstract0_of_box(ppl,0,dim,(ap_interval_t**)ppli); RESULT('*'); if (!is_eq(pkr,pplr)) { ERROR("different results"); for (i=0;i=90)?AP_CONS_EQ: (rand()%100>=90)?AP_CONS_SUP:AP_CONS_SUPEQ, random_linexpr(dim),NULL); bool pks,ppls; pka = random_poly(pk,dim); ppla = convert(ppl,pka); pks = ap_abstract0_sat_lincons(pk,pka,&l); ppls = ap_abstract0_sat_lincons(ppl,ppla,&l); RESULT('*'); if (pks!=ppls) { ERROR("different results"); print_poly("pka",pka); ap_lincons0_fprint(stderr,&l,NULL); fprintf(stderr,"\npks=%i ppls=%i\n",pks,ppls); } ap_abstract0_free(pk,pka); ap_abstract0_free(ppl,ppla); ap_lincons0_clear(&l); } ENDLOOP; } void test_isat(void) { printf("\ninterval saturation\n"); LOOP { size_t dim = 6; size_t p = rand() % dim; ap_abstract0_t* pka,*ppla; ap_interval_t* i = ap_interval_alloc(); bool pks,ppls; random_interval(i); pka = random_poly(pk,dim); ppla = convert(ppl,pka); pks = ap_abstract0_sat_interval(pk,pka,p,i); ppls = ap_abstract0_sat_interval(ppl,ppla,p,i); RESULT('*'); if (pks!=ppls) { ERROR("different results"); print_poly("pka",pka); ap_interval_fprint(stderr,i); fprintf(stderr,"\nvar=%i\npks=%i ppls=%i\n",(int)p,pks,ppls); } ap_abstract0_free(pk,pka); ap_abstract0_free(ppl,ppla); ap_interval_free(i); } ENDLOOP; } void test_assign(void) { printf("\nassign\n"); LOOP { size_t i, dim = 7; size_t p = rand() % dim; ap_abstract0_t* pka,*pkr, *ppla,*pplr; ap_linexpr0_t* l = random_linexpr(dim); pka = random_poly(pk,dim); ppla = convert(ppl,pka); pkr = ap_abstract0_assign_linexpr(pk,false,pka,p,l,NULL); pplr = ap_abstract0_assign_linexpr(ppl,false,ppla,p,l,NULL); RESULT('*'); if (!is_eq(pkr,pplr)) { ERROR("different results"); fprintf(stderr,"x%i <- ",(int)p); ap_linexpr0_fprint(stderr,l,NULL); fprintf(stderr,"\n"); print_poly("pka",pka); print_poly("pkr",pkr); print_poly("pplr",pplr); } ap_abstract0_free(pk,pka); ap_abstract0_free(ppl,ppla); ap_abstract0_free(pk,pkr); ap_abstract0_free(ppl,pplr); ap_linexpr0_free(l); } ENDLOOP; } void test_par_assign(void) { printf("\nparallel assign\n"); LOOP { size_t i, dim = 7; size_t p = rand() % dim; ap_abstract0_t* pka,*pkr, *ppla,*pplr; ap_dim_t d[NB]; ap_linexpr0_t *l[NB]; pka = random_poly(pk,dim); ppla = convert(ppl,pka); for (i=0;i ",(int)p); ap_linexpr0_fprint(stderr,l,NULL); fprintf(stderr,"\n"); print_poly("pka",pka); print_poly("pkr",pkr); print_poly("pplr",pplr); } ap_abstract0_free(pk,pka); ap_abstract0_free(ppl,ppla); ap_abstract0_free(pk,pkr); ap_abstract0_free(ppl,pplr); ap_linexpr0_free(l); } ENDLOOP; } void test_par_subst(void) { printf("\nparallel subst\n"); LOOP { size_t i, dim = 7; size_t p = rand() % dim; ap_abstract0_t* pka,*pkr, *ppla,*pplr; ap_dim_t d[NB]; ap_linexpr0_t *l[NB]; pka = random_poly(pk,dim); ppla = convert(ppl,pka); for (i=0;i ",d[i]); ap_linexpr0_fprint(stderr,l[i],NULL); fprintf(stderr,"\n"); } print_poly("pka",pka); print_poly("pkr",pkr); print_poly("pplr",pplr); } ap_abstract0_free(pk,pka); ap_abstract0_free(ppl,ppla); ap_abstract0_free(pk,pkr); ap_abstract0_free(ppl,pplr); for (i=0;ioption.abort_if_exception[i] = true; ppl->option.abort_if_exception[i] = true; } printf("\n\ncomparing libraries:\n- %s (%s)\n- %s (%s)\nwith strict=%i int=%i\n\n", pk->library,pk->version,ppl->library,ppl->version,strict,intdim); /* run tests */ test_conv(); test_join(); test_meet(); test_join_array(); test_meet_array(); test_dimadd(); test_dimrem(); test_forget(); test_permute(); test_expand(); test_fold(); test_add_lincons(); test_add_ray(); test_box(); test_vbound(); test_lbound(); test_csat(); test_isat(); test_assign(); test_par_assign(); test_subst(); test_par_subst(); if (!strict) test_widen(); // behave differently in strict mode /* clean-up */ ap_manager_free(pk); ap_manager_free(ppl); } /*}*/ if (error_) printf("\n%i error(s)!\n",error_); else printf("\nall tests passed\n"); return 0; } apron-dist-0.9.10/apron/ppl/ap_ppl.h0000640014525101416610000000261010672507041017104 0ustar bjeannetpopart/* * apron_ppl.h * * APRON Library / PPL library wrapper * * This is the (only) one .h to include to access all PPL domains. * * Copyright (C) Antoine Mine' 2006 * */ /* * This file is part of the APRON Library, released under GPL license. * Please read the COPYING file packaged in the distribution. */ #ifndef __APRON_PPL_H #define __APRON_PPL_H #include "ap_global0.h" #ifdef __cplusplus extern "C" { #endif ap_manager_t* ap_ppl_poly_manager_alloc(bool strict); /* (PPL::Polyhedron ) Allocate an APRON manager for convex polyhedra, linked to PPL. If the Boolean parameter is true, abstract values generated with the manager can have strict constraints (like x>0). Otherwise they are defined using only loose constraints. Managers and abstract values in strict and loose mode are incompatible. */ ap_manager_t* ap_ppl_grid_manager_alloc(void); /* (PPL::Grid) Allocate a APRON manager for grids, linked to PPL. */ /* extra functions not in APRON managers */ ap_abstract0_t* ap_abstract0_ppl_poly_widening_thresholds(ap_manager_t* man, ap_abstract0_t* a1, ap_abstract0_t* a2, ap_lincons0_array_t* array); ap_abstract0_t* ap_abstract0_ppl_grid_widening_thresholds(ap_manager_t* man, ap_abstract0_t* a1, ap_abstract0_t* a2, ap_lincons0_array_t* array); #ifdef __cplusplus } #endif #endif /* __APRON_PPL_H */ apron-dist-0.9.10/apron/ppl/COPYING0000640014525101416610000004334610664570161016532 0ustar bjeannetpopart This license applies to all files distributed in the original package, including all source code, libraries, binaries, and documentation GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. apron-dist-0.9.10/apron/ppl/manager.idl0000777014525101416610000000000011252510553024243 2../mlapronidl/manager.idlustar bjeannetpopartapron-dist-0.9.10/apron/ppl/ppl_user.hh0000640014525101416610000001726311144120547017641 0ustar bjeannetpopart/* * ppl_user.cc * * APRON Library / PPL library wrapper * * Conversion between APRON user types and PPL classes. * These are used internally by all PPL wrappers, but not exported to the user. * * Copyright (C) Antoine Mine' 2006 * */ /* * This file is part of the APRON Library, released under GPL license. * Please read the COPYING file packaged in the distribution. */ /* APRON includes */ #include "ap_ppl.h" #include "ppl_poly.hh" #define NUM_MPQ #include "num.h" #include "numint.h" #include "numrat.h" #include "bound.h" #include "itv.h" #include "itv_linexpr.h" #include "itv_linearize.h" /* PPL includes */ #include "ppl.hh" /* using namespace std; using namespace Parma_Polyhedra_Library; */ #ifndef PPL_VERSION_MAJOR #error "no version information" #endif #if (PPL_VERSION_MAJOR==0) && (PPL_VERSION_MINOR <= 9) #define PPL_0_9 #endif /* ********************************************************************** */ /* Types and exceptions */ /* ********************************************************************** */ /* Internal structure in managers */ typedef struct ppl_internal_t { bool strict; /* strict or loose mode for polyhedra */ struct itv_internal_t* itv; /* Used for linearisation */ } ppl_internal_t; extern "C" ppl_internal_t* ap_ppl_internal_alloc(bool strict); extern "C" void ap_ppl_internal_free(void*); /* Indicates that a an object cannot be exactly converted into another one should be caught in transfer functions */ class cannot_convert: public exception { public: cannot_convert() {}; }; /* ********************************************************************** */ /* Number conversions */ /* ********************************************************************** */ /* GMP => scalar (exact) */ static inline void ap_ppl_mpz_to_scalar(ap_scalar_t* s, const mpz_class& i) { ap_scalar_reinit(s,AP_SCALAR_MPQ); mpz_set(mpq_numref(s->val.mpq), i.get_mpz_t()); mpz_set_ui(mpq_denref(s->val.mpq), 1); } /* GMP / GMP => scalar (exact) */ static inline void ap_ppl_mpz2_to_scalar(ap_scalar_t* s, const mpz_class& n, const mpz_class& d) { ap_scalar_reinit(s,AP_SCALAR_MPQ); mpz_set(mpq_numref(s->val.mpq), n.get_mpz_t()); mpz_set(mpq_denref(s->val.mpq), d.get_mpz_t()); mpq_canonicalize(s->val.mpq); } /* coeff => GMP */ /* fail if the coeff cannot be exactely represented as a finite mpq */ static inline void ap_ppl_mpq_of_coef(mpq_class& res, const ap_coeff_t coef) { switch (coef.discr) { case AP_COEFF_SCALAR: if (ap_scalar_infty(coef.val.scalar) || ap_mpq_set_scalar(res.get_mpq_t(),coef.val.scalar,GMP_RNDU)) throw cannot_convert(); break; case AP_COEFF_INTERVAL: { mpq_class tmp; if (ap_scalar_infty(coef.val.interval->sup) || ap_scalar_infty(coef.val.interval->inf) || ap_mpq_set_scalar(res.get_mpq_t(),coef.val.interval->sup,GMP_RNDU) || ap_mpq_set_scalar(tmp.get_mpq_t(),coef.val.interval->inf,GMP_RNDD) || tmp!=res) throw cannot_convert(); } break; default: throw invalid_argument("Coefficient type ap_ppl_mpq_of_coef"); } } /* ********************************************************************** */ /* Conversions from PPL to APRON */ /* ********************************************************************** */ /* some of these may raise cannot_convert */ /* returned booleans are true when inexact */ /* reference booleans are set to true when inexact, left unchanged otherwise */ extern ap_lincons0_t ap_ppl_to_lincons(const Constraint& c); extern ap_lincons0_t ap_ppl_to_lincons(const Congruence& c); extern ap_lincons0_array_t ap_ppl_to_lincons_array(const Constraint_System& c); extern ap_lincons0_array_t ap_ppl_to_lincons_array(const Congruence_System& c); extern ap_generator0_t ap_ppl_to_generator(const Generator& c, bool& exact); extern ap_generator0_t ap_ppl_to_generator(const Grid_Generator& c); extern ap_generator0_array_t ap_ppl_to_generator_array(const Generator_System& c, bool& exact); extern ap_generator0_array_t ap_ppl_to_generator_array(const Grid_Generator_System& c); extern ap_generator0_array_t ap_ppl_generator_universe(size_t dim); extern void ap_ppl_box_universe(ap_interval_t** i,size_t nb); /* ********************************************************************** */ /* Conversions from ITV to PPL */ /* ********************************************************************** */ /* some of these may raise cannot_convert */ /* returned booleans are true when exact */ /* reference booleans are set to true when exact, false otherwise */ /* Linear expressions */ extern bool ap_ppl_of_itv_linexpr(Linear_Expression& r, mpz_class& den, itv_linexpr_t* c, int mode); /* Linear constraints */ extern bool ap_ppl_of_itv_lincons(Constraint& r, mpz_class& den, itv_lincons_t* c, bool allow_strict); extern bool ap_ppl_of_itv_lincons(Congruence& r, mpz_class& den, itv_lincons_t* c); extern bool ap_ppl_of_itv_lincons_array(Constraint_System& r, mpz_class& den,itv_lincons_array_t* a,bool allow_strict); extern bool ap_ppl_of_itv_lincons_array(Congruence_System& r, mpz_class& den,itv_lincons_array_t* a); /* ********************************************************************** */ /* Conversions from APRON to PPL */ /* ********************************************************************** */ /* some of these may raise cannot_convert */ /* returned booleans are true when exact */ /* reference booleans are set to true when exact, false otherwise */ /* Generators */ extern bool ap_ppl_of_generator(itv_internal_t* intern, Generator& r,ap_generator0_t* c); extern bool ap_ppl_of_generator(itv_internal_t* intern, Grid_Generator& r,ap_generator0_t* c); extern bool ap_ppl_of_generator_array(itv_internal_t* intern, Generator_System& r,ap_generator0_array_t* a); extern bool ap_ppl_of_generator_array(itv_internal_t* intern, Grid_Generator_System& r,ap_generator0_array_t* a); /* Boxes */ extern bool ap_ppl_of_box(Constraint_System& r, ap_interval_t** a, size_t intdim, size_t realdim); extern bool ap_ppl_of_box(Congruence_System& r, ap_interval_t** a, size_t intdim, size_t realdim); /* Linear expressions */ extern void ap_ppl_of_linexpr(itv_internal_t* intern, Linear_Expression& r, mpz_class& den, ap_linexpr0_t* c, int mode); /* Linear constraints */ extern bool ap_ppl_of_lincons(itv_internal_t* intern, Constraint& r, PPL_Poly& abs, ap_lincons0_t* c,bool allow_strict); extern bool ap_ppl_of_lincons(itv_internal_t* intern, Congruence& r,ap_lincons0_t* c); extern bool ap_ppl_of_lincons_array(itv_internal_t* intern, Constraint_System& r,ap_lincons0_array_t* a,bool allow_strict); extern bool ap_ppl_of_lincons_array(itv_internal_t* intern, Congruence_System& r,ap_lincons0_array_t* a); /* ********************************************************************** */ /* Others */ /* ********************************************************************** */ static ap_abstract0_t* ap_ppl_make_abstract0(ap_manager_t* man, void* v) { ap_abstract0_t* r = (ap_abstract0_t*)malloc(sizeof(ap_abstract0_t)); assert(r); r->value = v; r->man = ap_manager_copy(man); return r; } /* returns an element with the correct manager and, if possible, size */ static ap_abstract0_t* ap_ppl_invalid_abstract0(ap_manager_t* man, ap_abstract0_t* org = NULL) { if (org) { ap_dimension_t d = ap_abstract0_dimension(org->man,org); return ap_abstract0_top(man,d.intdim,d.realdim); } else return ap_abstract0_top(man,0,1); } #define arg_assert(cond,action,funid) \ do { if (!(cond)) { \ char buf_[1024]; \ snprintf(buf_,sizeof(buf_), \ "assertion (%s) failed in %s at %s:%i", \ #cond, __func__, __FILE__, __LINE__); \ ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT, funid,buf_); \ action } \ } while(0) apron-dist-0.9.10/apron/ppl/ppl.patch0000640014525101416610000000255310564706001017277 0ustar bjeannetpopartdiff -ru ppl-0.9-org/src/Grid_Generator.defs.hh ppl-0.9/src/Grid_Generator.defs.hh --- ppl-0.9-org/src/Grid_Generator.defs.hh 2006-02-26 21:24:05.000000000 +0100 +++ ppl-0.9/src/Grid_Generator.defs.hh 2007-02-14 18:31:16.000000000 +0100 @@ -223,10 +223,12 @@ the notion of coefficient with the notion of coordinate: these are equivalent only when the divisor is 1. */ -class Parma_Polyhedra_Library::Grid_Generator : private Generator { +class Parma_Polyhedra_Library::Grid_Generator : protected Generator { public: // FIXME: Add wrappers of any other public Generator methods. + Coefficient_traits::const_reference coefficient(Variable v) const; + //! Returns the dimension of the vector space enclosing \p *this. dimension_type space_dimension() const; Seulement dans ppl-0.9/src: Grid_Generator.defs.hh~ diff -ru ppl-0.9-org/src/Grid_Generator.inlines.hh ppl-0.9/src/Grid_Generator.inlines.hh --- ppl-0.9-org/src/Grid_Generator.inlines.hh 2006-01-27 14:50:36.000000000 +0100 +++ ppl-0.9/src/Grid_Generator.inlines.hh 2007-02-14 18:25:56.000000000 +0100 @@ -27,6 +27,11 @@ namespace Parma_Polyhedra_Library { +inline Coefficient_traits::const_reference +Grid_Generator::coefficient(const Variable v) const { + return Generator::coefficient(v); +} + inline Grid_Generator::Grid_Generator(Generator g) : Generator(Generator::point()) { apron-dist-0.9.10/apron/ppl/ppl_poly.cc0000640014525101416610000011505311144120547017630 0ustar bjeannetpopart/* * ppl_poly.cc * * APRON Library / PPL library wrapper * * Wrappers specific to the Polyhedron PPL classes. * * Copyright (C) Antoine Mine' 2006 * */ /* * This file is part of the APRON Library, released under GPL license. * Please read the COPYING file packaged in the distribution. */ #include #include "ap_generic.h" #include "ap_linearize.h" #include "ap_ppl.h" #include "ppl_user.hh" #include "ppl_poly.hh" #include using namespace std; using namespace Parma_Polyhedra_Library; /* ********************************************************************** */ /* General stuff */ /* ********************************************************************** */ /* ====================================================================== */ /* Manager */ /* ====================================================================== */ static inline ppl_internal_t* get_internal(ap_manager_t* man) { return (ppl_internal_t*)man->internal; } /* ====================================================================== */ /* PPL_Poly */ /* ====================================================================== */ PPL_Poly::PPL_Poly(ap_manager_t* man, const PPL_Poly& x) : intdim(x.intdim) { ppl_internal_t* ppl = get_internal(man); p = ppl->strict ? (Polyhedron*)new NNC_Polyhedron(*(NNC_Polyhedron*)x.p) : (Polyhedron*)new C_Polyhedron(*(C_Polyhedron*)x.p); } PPL_Poly::PPL_Poly(ap_manager_t* man, size_t intdim, size_t realdim, Degenerate_Element kind) : intdim(intdim) { ppl_internal_t* ppl = get_internal(man); try { p = ppl->strict ? (Polyhedron*)new NNC_Polyhedron(intdim+realdim,kind) : (Polyhedron*)new C_Polyhedron(intdim+realdim,kind); } catch (std::logic_error e) { intdim = 0; if (ppl->strict) p = new NNC_Polyhedron(1,kind); else p = new C_Polyhedron(1,kind); } } PPL_Poly::~PPL_Poly() { delete p; } /* ====================================================================== */ /* Error Handlers */ /* ====================================================================== */ /* returns a polyhedron, of specified size if possible */ #define CATCH_WITH_DIM(funid,intdim,realdim) \ catch (cannot_convert w) { \ /* bailing out, not an error */ \ man->result.flag_exact = man->result.flag_best = false; \ return new PPL_Poly(man,intdim,realdim,UNIVERSE); \ } \ catch (std::logic_error e) { \ /* actual error */ \ ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT,funid,e.what()); \ return new PPL_Poly(man,intdim,realdim,UNIVERSE); \ } /* returns a polyhedron, with size compatible with poly if possible */ #define CATCH_WITH_POLY(funid,poly) \ CATCH_WITH_DIM(funid,poly->intdim,poly->p->space_dimension()-poly->intdim) /* returns v */ #define CATCH_WITH_VAL(funid,v) \ catch (cannot_convert w) { \ /* bailing out, not an error */ \ man->result.flag_exact = man->result.flag_best = false; \ return v; \ } \ catch (std::logic_error e) { \ /* actual error */ \ ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT,funid,e.what()); \ return v; \ } /* returns nothing */ #define CATCH_WITH_VOID(funid) CATCH_WITH_VAL(funid,) /* prints message */ #define CATCH_WITH_MSG(funid) \ catch (cannot_convert w) { \ /* bailing out, not an error */ \ fprintf(stream,"!exception!"); \ } \ catch (std::logic_error e) { \ /* actual error */ \ ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT,funid,e.what()); \ fprintf(stream,"!exception!"); \ } /* ====================================================================== */ /* utility shared by _bound_dimension & _to_box, _sat_interval (exact) */ /* ====================================================================== */ static void ap_ppl_poly_bound_dim(ap_interval_t* r,PPL_Poly* a,int dim) { Coefficient sup_n,sup_d; Linear_Expression l = Variable(dim); bool ok; /* sup bound */ if (a->p->maximize(l,sup_n,sup_d,ok)) ap_ppl_mpz2_to_scalar(r->sup,sup_n,sup_d); else ap_scalar_set_infty(r->sup,1); /* inf bound */ if (a->p->minimize(l,sup_n,sup_d,ok)) ap_ppl_mpz2_to_scalar(r->inf,sup_n,sup_d); else ap_scalar_set_infty(r->inf,-1); } static itv_t* ap_ppl_poly_to_itv_array(PPL_Poly* a) { Coefficient sup_n,sup_d; Linear_Expression l; bool ok; size_t i,nb; nb = a->p->space_dimension(); itv_t* env = itv_array_alloc(nb); for (i=0; ip->maximize(l,sup_n,sup_d,ok)){ bound_set_int(env[i]->sup,0); numrat_set_numint2(env[i]->sup,sup_n.get_mpz_t(),sup_d.get_mpz_t()); } else bound_set_infty(env[i]->sup,1); /* inf bound */ if (a->p->minimize(l,sup_n,sup_d,ok)){ bound_set_int(env[i]->inf,0); numrat_set_numint2(env[i]->inf,sup_n.get_mpz_t(),sup_d.get_mpz_t()); numrat_neg(env[i]->inf,env[i]->inf); } else bound_set_infty(env[i]->inf,1); } return env; } /* ********************************************************************** */ /* I. General management */ /* ********************************************************************** */ /* ============================================================ */ /* I.1 Memory */ /* ============================================================ */ extern "C" PPL_Poly* ap_ppl_poly_copy(ap_manager_t* man, PPL_Poly* a) { man->result.flag_exact = man->result.flag_best = true; try { return new PPL_Poly(man,*a); } CATCH_WITH_POLY(AP_FUNID_COPY,a); } extern "C" void ap_ppl_poly_free(ap_manager_t* man, PPL_Poly* a) { man->result.flag_exact = man->result.flag_best = true; try { delete a; } CATCH_WITH_VOID(AP_FUNID_FREE); } extern "C" size_t ap_ppl_poly_size(ap_manager_t* man, PPL_Poly* a) { man->result.flag_exact = man->result.flag_best = true; try { return a->p->total_memory_in_bytes(); } CATCH_WITH_VAL(AP_FUNID_ASIZE,0); } /* ============================================================ */ /* I.2 Control of internal representation */ /* ============================================================ */ extern "C" void ap_ppl_poly_minimize(ap_manager_t* man, PPL_Poly* a) { man->result.flag_exact = man->result.flag_best = true; try { /* the calls force in-place minimisation */ (void)a->p->minimized_constraints(); (void)a->p->minimized_generators(); } CATCH_WITH_VOID(AP_FUNID_MINIMIZE); } extern "C" void ap_ppl_poly_canonicalize(ap_manager_t* man, PPL_Poly* a) { man->result.flag_exact = man->result.flag_best = true; try { /* the calls force in-place minimisation */ (void)a->p->minimized_constraints(); (void)a->p->minimized_generators(); } CATCH_WITH_VOID(AP_FUNID_CANONICALIZE); } extern "C" int ap_ppl_poly_hash(ap_manager_t* man, PPL_Poly* a) { man->result.flag_exact = man->result.flag_best = true; try { (void)a->p->minimized_constraints(); (void)a->p->minimized_generators(); return a->p->total_memory_in_bytes(); } CATCH_WITH_VAL(AP_FUNID_HASH,0); } extern "C" void ap_ppl_poly_approximate(ap_manager_t* man, PPL_Poly* a, int algorithm) { man->result.flag_exact = man->result.flag_best = true; return; } /* ============================================================ */ /* I.3 Printing */ /* ============================================================ */ extern "C" void ap_ppl_poly_fprint(FILE* stream, ap_manager_t* man, PPL_Poly* a, char** name_of_dim) { man->result.flag_exact = man->result.flag_best = true; try { if (a->p->is_empty()){ ap_dimension_t dim = ap_ppl_poly_dimension(man,a); fprintf(stream,"empty polyhedron of dim (%lu,%lu)\n", (unsigned long)dim.intdim,(unsigned long)dim.realdim); } else { ap_lincons0_array_t ar = ap_ppl_to_lincons_array(a->p->minimized_constraints()); ap_lincons0_array_fprint(stream,&ar,name_of_dim); ap_lincons0_array_clear(&ar); } } CATCH_WITH_MSG(AP_FUNID_FPRINT); } /* NOT IMPLEMENTED! */ extern "C" void ap_ppl_poly_fprintdiff(FILE* stream, ap_manager_t* man, PPL_Poly* a1, PPL_Poly* a2, char** name_of_dim) { ap_manager_raise_exception(man,AP_EXC_NOT_IMPLEMENTED,AP_FUNID_FPRINTDIFF,"not implemented"); } /* fdump will print the unminimized contraint & generator systems */ extern "C" void ap_ppl_poly_fdump(FILE* stream, ap_manager_t* man, PPL_Poly* a) { man->result.flag_exact = man->result.flag_best = true; try { /* dump constraints */ fprintf(stream,"constraints: "); ap_lincons0_array_t ar = ap_ppl_to_lincons_array(a->p->constraints()); ap_lincons0_array_fprint(stream,&ar,NULL); ap_lincons0_array_clear(&ar); /* dump generators */ fprintf(stream,"generators: "); bool exact = true; ap_generator0_array_t ar2 = ap_ppl_to_generator_array(a->p->generators(),exact); if (!exact) fprintf(stream,"(inexact) "); ap_generator0_array_fprint(stream,&ar2,NULL); ap_generator0_array_clear(&ar2); } CATCH_WITH_MSG(AP_FUNID_FPRINTDIFF); } /* ============================================================ */ /* I.4 Serialization */ /* ============================================================ */ /* NOT IMPLEMENTED! */ extern "C" ap_membuf_t ap_ppl_poly_serialize_raw(ap_manager_t* man, PPL_Poly* a) { ap_membuf_t membuf; membuf.ptr = NULL; membuf.size = 0; ap_manager_raise_exception(man,AP_EXC_NOT_IMPLEMENTED,AP_FUNID_SERIALIZE_RAW,"not implemented"); return membuf; } /* NOT IMPLEMENTED! */ extern "C" PPL_Poly* ap_ppl_poly_deserialize_raw(ap_manager_t* man, void* ptr, size_t* size) { ap_manager_raise_exception(man,AP_EXC_NOT_IMPLEMENTED,AP_FUNID_DESERIALIZE_RAW,"not implemented"); return NULL; } /* ********************************************************************** */ /* II. Constructor, accessors, tests and property extraction */ /* ********************************************************************** */ extern "C" PPL_Poly* ap_ppl_poly_bottom(ap_manager_t* man, size_t intdim, size_t realdim) { man->result.flag_exact = man->result.flag_best = true; try { return new PPL_Poly(man,intdim,realdim,EMPTY); } CATCH_WITH_DIM(AP_FUNID_BOTTOM,intdim,realdim); } extern "C" PPL_Poly* ap_ppl_poly_top(ap_manager_t* man, size_t intdim, size_t realdim) { man->result.flag_exact = man->result.flag_best = true; try { return new PPL_Poly(man,intdim,realdim,UNIVERSE); } CATCH_WITH_DIM(AP_FUNID_TOP,intdim,realdim); } extern "C" PPL_Poly* ap_ppl_poly_of_box(ap_manager_t* man, size_t intdim, size_t realdim, ap_interval_t** tinterval) { man->result.flag_exact = man->result.flag_best = (intdim==0); try { PPL_Poly* r = new PPL_Poly(man,intdim,realdim,UNIVERSE); Constraint_System c; if (!ap_ppl_of_box(c,tinterval,intdim,realdim)) man->result.flag_exact = man->result.flag_best = false; r->p->add_constraints(c); return r; } CATCH_WITH_DIM(AP_FUNID_OF_BOX,intdim,realdim); } /* ============================================================ */ /* II.2 Accessors */ /* ============================================================ */ extern "C" ap_dimension_t ap_ppl_poly_dimension(ap_manager_t* man, PPL_Poly* a) { man->result.flag_exact = man->result.flag_best = true; ap_dimension_t d = { 0, 0 }; try { d.intdim = a->intdim; d.realdim = a->p->space_dimension()-a->intdim; return d; } CATCH_WITH_VAL(AP_FUNID_DIMENSION,d); } /* ============================================================ */ /* II.3 Tests */ /* ============================================================ */ extern "C" bool ap_ppl_poly_is_bottom(ap_manager_t* man, PPL_Poly* a) { man->result.flag_exact = man->result.flag_best = (a->intdim==0); try { return a->p->is_empty(); } CATCH_WITH_VAL(AP_FUNID_IS_BOTTOM,false); } extern "C" bool ap_ppl_poly_is_top(ap_manager_t* man, PPL_Poly* a) { man->result.flag_exact = man->result.flag_best = true; try { return a->p->is_universe(); } CATCH_WITH_VAL(AP_FUNID_IS_TOP,false); } extern "C" bool ap_ppl_poly_is_leq(ap_manager_t* man, PPL_Poly* a1, PPL_Poly* a2) { man->result.flag_exact = man->result.flag_best = (a1->intdim==0); try { return a2->p->contains(*a1->p); } CATCH_WITH_VAL(AP_FUNID_IS_LEQ,false); } extern "C" bool ap_ppl_poly_is_eq(ap_manager_t* man, PPL_Poly* a1, PPL_Poly* a2) { man->result.flag_exact = man->result.flag_best = (a1->intdim==0); try { return *a1->p == *a2->p; } CATCH_WITH_VAL(AP_FUNID_IS_EQ,false); } extern "C" bool ap_ppl_poly_sat_lincons(ap_manager_t* man, PPL_Poly* a, ap_lincons0_t* lincons0) { ppl_internal_t* intern = get_internal(man); man->result.flag_exact = man->result.flag_best = true; try { if (a->p->is_empty()) return true; else { itv_lincons_t lincons; Linear_Expression l; mpz_class den; Constraint r = Constraint::zero_dim_positivity(); bool exact = true; switch (lincons0->constyp) { case AP_CONS_EQ: case AP_CONS_EQMOD: if (!ap_linexpr0_is_linear(lincons0->linexpr0)){ man->result.flag_exact = man->result.flag_best = false; return false; } case AP_CONS_SUPEQ: case AP_CONS_SUP: itv_lincons_init(&lincons); exact = itv_lincons_set_ap_lincons0(intern->itv,&lincons,lincons0) && exact; if (itv_sat_lincons_is_false(intern->itv,&lincons)){ itv_lincons_clear(&lincons); if (!exact) man->result.flag_exact = man->result.flag_best = false; return false; } if (!itv_lincons_is_quasilinear(&lincons)){ itv_t* env = ap_ppl_poly_to_itv_array(a); exact = itv_quasilinearize_lincons(intern->itv,&lincons,env,false) && exact; itv_array_free(env,a->p->space_dimension()); } if (itv_sat_lincons_is_false(intern->itv,&lincons)){ itv_lincons_clear(&lincons); man->result.flag_exact = man->result.flag_best = true; return false; } assert (!bound_infty(lincons.linexpr.cst->inf)); exact = ap_ppl_of_itv_linexpr(l,den,&lincons.linexpr,-1) && exact; itv_lincons_clear(&lincons); switch (lincons.constyp){ case AP_CONS_SUPEQ: r = (l>=0); break; case AP_CONS_SUP: r = intern->strict ? (l>0) : (l>=0); break; case AP_CONS_EQMOD: exact = exact && (num_sgn(lincons.num)==0); case AP_CONS_EQ: r = (l == 0); break; default: assert(0); } break; default: man->result.flag_exact = man->result.flag_best = false; return false; } if (!exact) man->result.flag_exact = man->result.flag_best = false; Poly_Con_Relation relation = a->p->relation_with(r); return relation.implies(Poly_Con_Relation::is_included()); } } CATCH_WITH_VAL(AP_FUNID_SAT_LINCONS,false); } extern "C" bool ap_ppl_poly_sat_tcons(ap_manager_t* man, PPL_Poly* a, ap_tcons0_t* cons) { return ap_generic_sat_tcons(man,a,cons,AP_SCALAR_MPQ,true); } extern "C" bool ap_ppl_poly_sat_interval(ap_manager_t* man, PPL_Poly* a, ap_dim_t dim, ap_interval_t* i) { ap_interval_t* ig = ap_interval_alloc(); man->result.flag_exact = man->result.flag_best = false; try { ap_ppl_poly_bound_dim(ig,a,dim); bool r = ap_interval_is_leq(ig,i); ap_interval_free(ig); return r || a->p->is_empty(); } CATCH_WITH_VAL(AP_FUNID_SAT_INTERVAL,(ap_interval_free(ig),false)); } extern "C" bool ap_ppl_poly_is_dimension_unconstrained(ap_manager_t* man, PPL_Poly* a, ap_dim_t dim) { man->result.flag_exact = man->result.flag_best = true; try { if (a->p->is_empty()){ return false; } else { Generator g = Generator::line(Variable(dim)); return a->p->relation_with(g) == Poly_Gen_Relation::subsumes(); } } CATCH_WITH_VAL(AP_FUNID_IS_DIMENSION_UNCONSTRAINED,false); } /* ============================================================ */ /* II.4 Extraction of properties */ /* ============================================================ */ extern "C" ap_interval_t* ap_ppl_poly_bound_linexpr(ap_manager_t* man, PPL_Poly* a, ap_linexpr0_t* expr) { ppl_internal_t* intern = get_internal(man); man->result.flag_exact = man->result.flag_best = (a->intdim==0); ap_interval_t* r = ap_interval_alloc(); try { if (a->p->is_empty()) { /* empty */ ap_interval_set_bottom(r); } else { /* not empty */ itv_linexpr_t linexpr; Coefficient sup_n,sup_d; Linear_Expression l; mpz_class den; bool ok; bool exact = true; itv_linexpr_init(&linexpr,0); exact = itv_linexpr_set_ap_linexpr0(intern->itv,&linexpr,expr) && exact; if (!itv_linexpr_is_quasilinear(&linexpr)){ itv_t* env = ap_ppl_poly_to_itv_array(a); exact = itv_quasilinearize_linexpr(intern->itv,&linexpr,env,false) && exact; itv_array_free(env,a->p->space_dimension()); } if (linexpr.size==0){ ap_interval_set_itv(intern->itv,r,linexpr.cst); } else { /* sup bound */ if (bound_infty(linexpr.cst->sup)){ ap_scalar_set_infty(r->sup,1); } else { exact = ap_ppl_of_itv_linexpr(l,den,&linexpr,+1) && exact; if (a->p->maximize(l,sup_n,sup_d,ok)) { sup_d *= den; ap_ppl_mpz2_to_scalar(r->sup,sup_n,sup_d); } else { ap_scalar_set_infty(r->sup,1); } } /* inf bound */ if (bound_infty(linexpr.cst->inf)){ ap_scalar_set_infty(r->inf,-1); } else { if (!itv_linexpr_is_scalar(&linexpr)){ ap_ppl_of_itv_linexpr(l,den,&linexpr,-1); } if (a->p->minimize(l,sup_n,sup_d,ok)) { sup_d *= den; ap_ppl_mpz2_to_scalar(r->inf,sup_n,sup_d); } else { ap_scalar_set_infty(r->inf,-1); } } } itv_linexpr_clear(&linexpr); if (!exact) man->result.flag_exact = man->result.flag_best = false; } } CATCH_WITH_VAL(AP_FUNID_BOUND_LINEXPR,(ap_interval_set_top(r),r)); return r; } extern "C" ap_interval_t* ap_ppl_poly_bound_texpr(ap_manager_t* man, PPL_Poly* a, ap_texpr0_t* expr) { return ap_generic_bound_texpr(man,a,expr,AP_SCALAR_MPQ,true); } extern "C" ap_interval_t* ap_ppl_poly_bound_dimension(ap_manager_t* man, PPL_Poly* a, ap_dim_t dim) { man->result.flag_exact = man->result.flag_best = (a->intdim==0); ap_interval_t* r = ap_interval_alloc(); try { if (a->p->is_empty()) ap_interval_set_bottom(r); /* empty */ else ap_ppl_poly_bound_dim(r,a,dim); /* not empty */ return r; } CATCH_WITH_VAL(AP_FUNID_BOUND_DIMENSION,(ap_interval_set_top(r),r)); } extern "C" ap_lincons0_array_t ap_ppl_poly_to_lincons_array(ap_manager_t* man, PPL_Poly* a) { man->result.flag_exact = man->result.flag_best = a->intdim==0; try { return ap_ppl_to_lincons_array(a->p->constraints()); } CATCH_WITH_VAL(AP_FUNID_TO_LINCONS_ARRAY,ap_lincons0_array_make(0)); } extern "C" ap_tcons0_array_t ap_ppl_poly_to_tcons_array(ap_manager_t* man, PPL_Poly* a) { return ap_generic_to_tcons_array(man,a); } extern "C" ap_interval_t** ap_ppl_poly_to_box(ap_manager_t* man, PPL_Poly* a) { man->result.flag_exact = man->result.flag_best = (a->intdim==0); size_t dim = a->p->space_dimension(); ap_interval_t** in = ap_interval_array_alloc(dim); try { if (a->p->is_empty()) /* empty */ for (size_t i=0;iresult.flag_exact = man->result.flag_best = (a->intdim==0); try { bool exact = true; ap_generator0_array_t r = ap_ppl_to_generator_array(a->p->generators(),exact); if (!exact) man->result.flag_exact = man->result.flag_best = false; return r; } CATCH_WITH_VAL(AP_FUNID_TO_GENERATOR_ARRAY,ap_ppl_generator_universe(a->p->space_dimension())); } /* ********************************************************************** */ /* III. Operations */ /* ********************************************************************** */ /* ============================================================ */ /* III.1 Meet and Join */ /* ============================================================ */ extern "C" PPL_Poly* ap_ppl_poly_meet(ap_manager_t* man, bool destructive, PPL_Poly* a1, PPL_Poly* a2) { man->result.flag_exact = man->result.flag_best = (a1->intdim==0); try { PPL_Poly* r = destructive ? a1 : new PPL_Poly(man,*a1); r->p->intersection_assign(*a2->p); return r; } CATCH_WITH_POLY(AP_FUNID_MEET,a1); } extern "C" PPL_Poly* ap_ppl_poly_join(ap_manager_t* man, bool destructive, PPL_Poly* a1, PPL_Poly* a2) { man->result.flag_exact = false; man->result.flag_best = (a1->intdim==0); try { PPL_Poly* r = destructive ? a1 : new PPL_Poly(man,*a1); r->p->poly_hull_assign(*a2->p); return r; } CATCH_WITH_POLY(AP_FUNID_JOIN,a1); } extern "C" PPL_Poly* ap_ppl_poly_meet_array(ap_manager_t* man, PPL_Poly** tab, size_t size) { assert(size>=1); man->result.flag_exact = man->result.flag_best = (tab[0]->intdim==0); try { PPL_Poly* r = new PPL_Poly(man,*tab[0]); for (size_t i=1;ip->intersection_assign(*tab[i]->p); return r; } CATCH_WITH_POLY(AP_FUNID_MEET_ARRAY,tab[0]); } extern "C" PPL_Poly* ap_ppl_poly_join_array(ap_manager_t* man, PPL_Poly** tab, size_t size) { assert(size>=1); man->result.flag_exact = false; man->result.flag_best = (tab[0]->intdim==0); try { PPL_Poly* r = new PPL_Poly(man,*tab[0]); for (size_t i=1;ip->poly_hull_assign(*tab[i]->p); return r; } CATCH_WITH_POLY(AP_FUNID_JOIN_ARRAY,tab[0]); } extern "C" PPL_Poly* ap_ppl_poly_meet_lincons_array(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_lincons0_array_t* array) { bool exact = true; itv_lincons_array_t array2; bool lin; mpz_class den; ppl_internal_t* intern = get_internal(man); man->result.flag_exact = man->result.flag_best = (a->intdim==0); try { PPL_Poly* r = destructive ? a : new PPL_Poly(man,*a); if (a->p->is_empty()){ return r; } itv_lincons_array_init(&array2,array->size); exact = itv_lincons_array_set_ap_lincons0_array(intern->itv, &array2, array) && exact; if (!itv_lincons_array_is_quasilinear(&array2)){ itv_t* env = ap_ppl_poly_to_itv_array(a); exact = itv_quasilinearize_lincons_array(intern->itv,&array2,env,true) && exact; itv_array_free(env,a->p->space_dimension()); } itv_linearize_lincons_array(intern->itv,&array2,true); Constraint_System c; exact = ap_ppl_of_itv_lincons_array(c,den,&array2,intern->strict) && exact; if (!exact) man->result.flag_exact = man->result.flag_best = false; itv_lincons_array_clear(&array2); r->p->add_recycled_constraints(c); return r; } CATCH_WITH_POLY(AP_FUNID_MEET_LINCONS_ARRAY,a); } extern "C" PPL_Poly* ap_ppl_poly_meet_tcons_array(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_tcons0_array_t* array) { return (PPL_Poly*)ap_generic_meet_intlinearize_tcons_array(man,destructive, a, array, AP_SCALAR_MPQ, AP_LINEXPR_LINEAR, (void* (*)(ap_manager_t*, bool, void*, ap_lincons0_array_t*)) (&ap_ppl_poly_meet_lincons_array)); } extern "C" PPL_Poly* ap_ppl_poly_add_ray_array(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_generator0_array_t* array) { ppl_internal_t* intern = get_internal(man); man->result.flag_exact = man->result.flag_best = (a->intdim==0); try { PPL_Poly* r = destructive ? a : new PPL_Poly(man,*a); if (!r->p->is_empty()){ Generator_System c; if (!ap_ppl_of_generator_array(intern->itv,c,array)) man->result.flag_exact = man->result.flag_best = false; r->p->add_recycled_generators(c); } return r; } CATCH_WITH_POLY(AP_FUNID_ADD_RAY_ARRAY,a); } /* ============================================================ */ /* III.2 Assignement and Substitutions */ /* ============================================================ */ extern "C" PPL_Poly* ap_ppl_poly_assign_linexpr_array(ap_manager_t* man, bool destructive, PPL_Poly* org, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, PPL_Poly* dest) { size_t i; ppl_internal_t* intern = get_internal(man); bool exact = true; for (i=0;iresult.flag_exact = man->result.flag_best = (org->intdim==0); try { PPL_Poly* r = destructive ? org : new PPL_Poly(man,*org); itv_linexpr_t linexpr; Linear_Expression e; mpz_class den; itv_linexpr_init(&linexpr,0); itv_linexpr_set_ap_linexpr0(intern->itv,&linexpr,texpr[0]); if (!ap_ppl_of_itv_linexpr(e,den,&linexpr,1)) man->result.flag_exact = man->result.flag_best = false; itv_linexpr_clear(&linexpr); r->p->affine_image(Variable(tdim[0]),e,den); if (dest) r->p->intersection_assign(*dest->p); return r; } CATCH_WITH_POLY(AP_FUNID_ASSIGN_LINEXPR_ARRAY,org); } else { return (PPL_Poly*)ap_generic_assign_linexpr_array(man,destructive,org,tdim,texpr,size,dest); } } extern "C" PPL_Poly* ap_ppl_poly_substitute_linexpr_array(ap_manager_t* man, bool destructive, PPL_Poly* org, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, PPL_Poly* dest) { size_t i; ppl_internal_t* intern = get_internal(man); bool exact = true; for (i=0;iresult.flag_exact = man->result.flag_best = (org->intdim==0); try { PPL_Poly* r = destructive ? org : new PPL_Poly(man,*org); itv_linexpr_t linexpr; Linear_Expression e; mpz_class den; itv_linexpr_init(&linexpr,0); itv_linexpr_set_ap_linexpr0(intern->itv,&linexpr,texpr[0]); if (!ap_ppl_of_itv_linexpr(e,den,&linexpr,1)) man->result.flag_exact = man->result.flag_best = false; itv_linexpr_clear(&linexpr); r->p->affine_preimage(Variable(tdim[0]),e,den); if (dest) r->p->intersection_assign(*dest->p); return r; } CATCH_WITH_POLY(AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY,org); } else { return (PPL_Poly*)ap_generic_substitute_linexpr_array(man,destructive,org,tdim,texpr,size,dest); } } extern "C" PPL_Poly* ap_ppl_poly_assign_texpr_array(ap_manager_t* man, bool destructive, PPL_Poly* org, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, PPL_Poly* dest) { return (PPL_Poly*)ap_generic_assign_texpr_array(man,destructive,org,tdim,texpr,size,dest); } extern "C" PPL_Poly* ap_ppl_poly_substitute_texpr_array(ap_manager_t* man, bool destructive, PPL_Poly* org, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, PPL_Poly* dest) { return (PPL_Poly*)ap_generic_substitute_texpr_array(man,destructive,org,tdim,texpr,size,dest); } /* ============================================================ */ /* III.3 Projections */ /* ============================================================ */ extern "C" PPL_Poly* ap_ppl_poly_forget_array(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_dim_t* tdim, size_t size, bool project) { man->result.flag_exact = man->result.flag_best = (a->intdim==0); try { PPL_Poly* r = destructive ? a : new PPL_Poly(man,*a); if (!r->p->is_empty()){ for (size_t i=0;ip->add_generator(Generator::line(Variable(tdim[i]))); if (project) { for (size_t i=0;ip->add_constraint(Variable(tdim[i])==0); } } return r; } CATCH_WITH_POLY(AP_FUNID_FORGET_ARRAY,a); } /* partial functions used in map_space_dimensions */ class ap_ppl_map { protected: size_t dom,codom,*tab; char* def; public: ap_ppl_map(size_t dom,size_t codom) : dom(dom), codom(codom) { tab = new size_t [dom]; def = new char [dom]; memset(def,0,dom); } ~ap_ppl_map() { delete[] tab; delete[] def; } void set(dimension_type i,dimension_type j) { tab[i] = j; def[i] = 1; } bool has_empty_codomain() const { return codom==0; } dimension_type max_in_codomain() const { return codom-1; } bool maps(dimension_type i,dimension_type& j) const { j = tab[i]; return def[i]; } void do_map(PPL_Poly* r) const { r->p->map_space_dimensions(*this); } }; /* ============================================================ */ /* III.4 Change and permutation of dimensions */ /* ============================================================ */ extern "C" PPL_Poly* ap_ppl_poly_add_dimensions(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_dimchange_t* dimchange, bool project) { man->result.flag_exact = man->result.flag_best = true; size_t adddim = dimchange->intdim+dimchange->realdim; size_t olddim = a->p->space_dimension(); try { PPL_Poly* r = destructive ? a : new PPL_Poly(man,*a); /* add dimensions */ if (project) r->p->add_space_dimensions_and_project(adddim); else r->p->add_space_dimensions_and_embed(adddim); /* reorder dimensions */ ap_ppl_map map = ap_ppl_map(olddim+adddim,olddim+adddim); size_t i,j=0; for (i=0;idim[i];j++) map.set(j,i+j); map.set(olddim+i,i+j); } for (;jintdim += dimchange->intdim; return r; } CATCH_WITH_DIM(AP_FUNID_ADD_DIMENSIONS,a->intdim+dimchange->intdim,olddim+dimchange->realdim-a->intdim); } extern "C" PPL_Poly* ap_ppl_poly_remove_dimensions(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_dimchange_t* dimchange) { man->result.flag_exact = man->result.flag_best = (a->intdim==0); size_t deldim = dimchange->intdim+dimchange->realdim; size_t olddim = a->p->space_dimension(); try { PPL_Poly* r = destructive ? a : new PPL_Poly(man,*a); /* reorder & drop dimensions */ ap_ppl_map map = ap_ppl_map(olddim,olddim-deldim); for (size_t j=0,i=0;jdim[i]) i++; else map.set(j,j-i); map.do_map(r); r->intdim -= dimchange->intdim; return r; } CATCH_WITH_DIM(AP_FUNID_REMOVE_DIMENSIONS,a->intdim-dimchange->intdim,olddim-dimchange->realdim-a->intdim); } extern "C" PPL_Poly* ap_ppl_poly_permute_dimensions(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_dimperm_t* perm) { man->result.flag_exact = man->result.flag_best = true; try { PPL_Poly* r = destructive ? a : new PPL_Poly(man,*a); ap_ppl_map map = ap_ppl_map(perm->size,perm->size); for (size_t i=0;isize;i++) map.set(i,perm->dim[i]); map.do_map(r); return r; } CATCH_WITH_POLY(AP_FUNID_PERMUTE_DIMENSIONS,a); } /* ============================================================ */ /* III.5 Expansion and folding of dimensions */ /* ============================================================ */ extern "C" PPL_Poly* ap_ppl_poly_expand(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_dim_t dim, size_t n) { man->result.flag_exact = man->result.flag_best = true; try { size_t olddim = a->p->space_dimension(); PPL_Poly* r = destructive ? a : new PPL_Poly(man,*a); r->p->expand_space_dimension(Variable(dim),n); if (dimintdim) { /* expanded an integer dimension => needs some reordering */ ap_ppl_map map = ap_ppl_map(olddim+n,olddim+n); size_t i; for (i=0;iintdim;i++) map.set(i,i); for (i=0;iintdim+i); for (i=r->intdim;iintdim += n; } return r; } CATCH_WITH_DIM(AP_FUNID_EXPAND,a->intdim,a->p->space_dimension()-a->intdim+n); } extern "C" PPL_Poly* ap_ppl_poly_fold(ap_manager_t* man, bool destructive, PPL_Poly* a, ap_dim_t* tdim, size_t size) { man->result.flag_exact = false; man->result.flag_best = (a->intdim==0); try { PPL_Poly* r = destructive ? a : new PPL_Poly(man,*a); Variables_Set s; assert(size>0); for (size_t i=1;ip->fold_space_dimensions(s,Variable(tdim[0])); if (tdim[0]intdim) r->intdim -= size-1; return r; } CATCH_WITH_DIM(AP_FUNID_FOLD,a->intdim,a->p->space_dimension()-a->intdim-size); } /* ============================================================ */ /* III.6 Widening */ /* ============================================================ */ extern "C" PPL_Poly* ap_ppl_poly_widening(ap_manager_t* man, PPL_Poly* a1, PPL_Poly* a2) { man->result.flag_exact = man->result.flag_best = false; int algo = man->option.funopt[AP_FUNID_WIDENING].algorithm; try { PPL_Poly* r = new PPL_Poly(man,*a2); if (algo>0) r->p->BHRZ03_widening_assign(*a1->p); else r->p->H79_widening_assign(*a1->p); return r; } CATCH_WITH_POLY(AP_FUNID_WIDENING,a1); } extern "C" PPL_Poly* ap_ppl_poly_widening_threshold(ap_manager_t* man, PPL_Poly* a1, PPL_Poly* a2, ap_lincons0_array_t* array) { ppl_internal_t* intern = get_internal(man); man->result.flag_exact = man->result.flag_best = false; int algo = man->option.funopt[AP_FUNID_WIDENING].algorithm; try { Constraint_System c; /* when a1->strict=false, c will not contain any strict constraint */ ap_ppl_of_lincons_array(intern->itv,c,array,intern->strict); PPL_Poly* r = new PPL_Poly(man,*a2); if (algo>2) r->p->bounded_BHRZ03_extrapolation_assign(*a1->p,c); else if (algo>1) r->p->limited_BHRZ03_extrapolation_assign(*a1->p,c); else if (algo>0) r->p->bounded_H79_extrapolation_assign(*a1->p,c); else r->p->limited_H79_extrapolation_assign(*a1->p,c); return r; } CATCH_WITH_POLY(AP_FUNID_WIDENING,a1); } ap_abstract0_t* ap_abstract0_ppl_poly_widening_thresholds(ap_manager_t* man, ap_abstract0_t* a1, ap_abstract0_t* a2, ap_lincons0_array_t* array) { arg_assert(man->library==a1->man->library && man->library==a2->man->library, return ap_ppl_invalid_abstract0(man,a1);, AP_FUNID_WIDENING); man->result.flag_exact = man->result.flag_best = false; return ap_ppl_make_abstract0(man,ap_ppl_poly_widening_threshold(man,(PPL_Poly*)a1->value,(PPL_Poly*)a2->value,array)); } /* ============================================================ */ /* III.7 Closure operation */ /* ============================================================ */ extern "C" PPL_Poly* ap_ppl_poly_closure(ap_manager_t* man, bool destructive, PPL_Poly* a) { man->result.flag_exact = man->result.flag_best = true; try { PPL_Poly* r = destructive ? a : new PPL_Poly(man,*a); r->p->topological_closure_assign(); return r; } CATCH_WITH_POLY(AP_FUNID_CLOSURE,a); } /* ********************************************************************** */ /* Managers */ /* ********************************************************************** */ extern "C" ap_manager_t* ap_ppl_poly_manager_alloc(bool strict) { int i; ppl_internal_t* ppl; ap_manager_t* man; ppl = ap_ppl_internal_alloc(strict); char* name = const_cast(strict ? "PPL::Polyhedron, strict mode" : "PPL::Polyhedron, loose mode"); man = ap_manager_alloc(name,PPL_VERSION,ppl,&ap_ppl_internal_free); assert(man); man->funptr[AP_FUNID_COPY] = (void*)ap_ppl_poly_copy; man->funptr[AP_FUNID_FREE] = (void*)ap_ppl_poly_free; man->funptr[AP_FUNID_ASIZE] = (void*)ap_ppl_poly_size; man->funptr[AP_FUNID_MINIMIZE] = (void*)ap_ppl_poly_minimize; man->funptr[AP_FUNID_CANONICALIZE] = (void*)ap_ppl_poly_canonicalize; man->funptr[AP_FUNID_HASH] = (void*)ap_ppl_poly_hash; man->funptr[AP_FUNID_APPROXIMATE] = (void*)ap_ppl_poly_approximate; man->funptr[AP_FUNID_FPRINT] = (void*)ap_ppl_poly_fprint; man->funptr[AP_FUNID_FPRINTDIFF] = (void*)ap_ppl_poly_fprintdiff; man->funptr[AP_FUNID_FDUMP] = (void*)ap_ppl_poly_fdump; man->funptr[AP_FUNID_SERIALIZE_RAW] = (void*)ap_ppl_poly_serialize_raw; man->funptr[AP_FUNID_DESERIALIZE_RAW] = (void*)ap_ppl_poly_deserialize_raw; man->funptr[AP_FUNID_BOTTOM] = (void*)ap_ppl_poly_bottom; man->funptr[AP_FUNID_TOP] = (void*)ap_ppl_poly_top; man->funptr[AP_FUNID_OF_BOX] = (void*)ap_ppl_poly_of_box; man->funptr[AP_FUNID_DIMENSION] = (void*)ap_ppl_poly_dimension; man->funptr[AP_FUNID_IS_BOTTOM] = (void*)ap_ppl_poly_is_bottom; man->funptr[AP_FUNID_IS_TOP] = (void*)ap_ppl_poly_is_top; man->funptr[AP_FUNID_IS_LEQ] = (void*)ap_ppl_poly_is_leq; man->funptr[AP_FUNID_IS_EQ] = (void*)ap_ppl_poly_is_eq; man->funptr[AP_FUNID_IS_DIMENSION_UNCONSTRAINED] = (void*)ap_ppl_poly_is_dimension_unconstrained; man->funptr[AP_FUNID_SAT_INTERVAL] = (void*)ap_ppl_poly_sat_interval; man->funptr[AP_FUNID_SAT_LINCONS] = (void*)ap_ppl_poly_sat_lincons; man->funptr[AP_FUNID_SAT_TCONS] = (void*)ap_ppl_poly_sat_tcons; man->funptr[AP_FUNID_BOUND_DIMENSION] = (void*)ap_ppl_poly_bound_dimension; man->funptr[AP_FUNID_BOUND_LINEXPR] = (void*)ap_ppl_poly_bound_linexpr; man->funptr[AP_FUNID_BOUND_TEXPR] = (void*)ap_ppl_poly_bound_texpr; man->funptr[AP_FUNID_TO_BOX] = (void*)ap_ppl_poly_to_box; man->funptr[AP_FUNID_TO_LINCONS_ARRAY] = (void*)ap_ppl_poly_to_lincons_array; man->funptr[AP_FUNID_TO_TCONS_ARRAY] = (void*)ap_ppl_poly_to_tcons_array; man->funptr[AP_FUNID_TO_GENERATOR_ARRAY] = (void*)ap_ppl_poly_to_generator_array; man->funptr[AP_FUNID_MEET] = (void*)ap_ppl_poly_meet; man->funptr[AP_FUNID_MEET_ARRAY] = (void*)ap_ppl_poly_meet_array; man->funptr[AP_FUNID_MEET_LINCONS_ARRAY] = (void*)ap_ppl_poly_meet_lincons_array; man->funptr[AP_FUNID_MEET_TCONS_ARRAY] = (void*)ap_ppl_poly_meet_tcons_array; man->funptr[AP_FUNID_JOIN] = (void*)ap_ppl_poly_join; man->funptr[AP_FUNID_JOIN_ARRAY] = (void*)ap_ppl_poly_join_array; man->funptr[AP_FUNID_ADD_RAY_ARRAY] = (void*)ap_ppl_poly_add_ray_array; man->funptr[AP_FUNID_ASSIGN_LINEXPR_ARRAY] = (void*)ap_ppl_poly_assign_linexpr_array; man->funptr[AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY] = (void*)ap_ppl_poly_substitute_linexpr_array; man->funptr[AP_FUNID_ASSIGN_TEXPR_ARRAY] = (void*)ap_ppl_poly_assign_texpr_array; man->funptr[AP_FUNID_SUBSTITUTE_TEXPR_ARRAY] = (void*)ap_ppl_poly_substitute_texpr_array; man->funptr[AP_FUNID_ADD_DIMENSIONS] = (void*)ap_ppl_poly_add_dimensions; man->funptr[AP_FUNID_REMOVE_DIMENSIONS] = (void*)ap_ppl_poly_remove_dimensions; man->funptr[AP_FUNID_PERMUTE_DIMENSIONS] = (void*)ap_ppl_poly_permute_dimensions; man->funptr[AP_FUNID_FORGET_ARRAY] = (void*)ap_ppl_poly_forget_array; man->funptr[AP_FUNID_EXPAND] = (void*)ap_ppl_poly_expand; man->funptr[AP_FUNID_FOLD] = (void*)ap_ppl_poly_fold; man->funptr[AP_FUNID_WIDENING] = (void*)ap_ppl_poly_widening; man->funptr[AP_FUNID_CLOSURE] = (void*)ap_ppl_poly_closure; for (i=0;ippl.ml sed -f sedscript_caml tmp/ppl.mli >ppl.mli .PRECIOUS: %_caml.c %.ml %.mli %.cmi libap_ppl_caml.a libap_ppl_caml.so ppl.cmx ppl.cmo #--------------------------------------- # ML generic rules #--------------------------------------- %.cmi: %.mli $(DEPS) $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -c $< %.cmo: %.ml %.cmi $(DEPS) $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -c $< %.cmx: %.ml %.cmi $(DEPS) $(OCAMLOPT) $(OCAMLOPTFLAGS) $(OCAMLINC) -c $< apron-dist-0.9.10/apron/ppl/ppl_grid.h0000640014525101416610000003076310723557216017451 0ustar bjeannetpopart/* * ppl_grid.h * * APRON Library / PPL library wrapper * * Wrappers specific to the Grid PPL classes. * * Copyright (C) Antoine Mine' 2006 * */ /* * This file is part of the APRON Library, released under GPL license. * Please read the COPYING file packaged in the distribution. */ #ifndef _PPL_GRID_H_ #define _PPL_GRID_H_ #include "ap_manager.h" #include "ap_global0.h" /* ============================================================ */ /* A. Constructor for APRON manager (to be freed with ap_manager_free). */ /* ============================================================ */ ap_manager_t* ap_ppl_grid_manager_alloc(void); /* Allocate a PPL manager for grids. */ /* ********************************************************************** */ /* I. General management */ /* ********************************************************************** */ /* ============================================================ */ /* I.1 Memory */ /* ============================================================ */ struct ppl_grid* ap_ppl_grid_copy(ap_manager_t* man, struct ppl_grid* a); /* Return a copy of an abstract value, on which destructive update does not affect the initial value. */ void ap_ppl_grid_free(ap_manager_t* man, struct ppl_grid* a); /* Free all the memory used by the abstract value */ size_t ap_ppl_grid_size(ap_manager_t* man, struct ppl_grid* a); /* Return the abstract size of a polyhedron, which is the number of coefficients of its current representation, possibly redundant. */ /* ============================================================ */ /* I.2 Control of internal representation */ /* ============================================================ */ void ap_ppl_grid_minimize(ap_manager_t* man, struct ppl_grid* a); /* Same as ap_ppl_grid_canonicalize */ void ap_ppl_grid_canonicalize(ap_manager_t* man, struct ppl_grid* a); /* Put the polyhedron with minimized constraints and frames. If in addition the integer man->option->canonicalize.algorithm is strictly positive, normalize equalities and lines, and also strict constraints */ void ap_ppl_grid_approximate(ap_manager_t* man, struct ppl_grid* a, int algorithm); /* Do nothing */ /* ============================================================ */ /* I.3 Printing */ /* ============================================================ */ void ap_ppl_grid_fprint(FILE* stream, ap_manager_t* man, struct ppl_grid* a, char** name_of_dim); /* Print the abstract value in a pretty way, using function name_of_dim to name dimensions */ void ap_ppl_grid_fprintdiff(FILE* stream, ap_manager_t* man, struct ppl_grid* a1, struct ppl_grid* a2, char** name_of_dim); /* Print the difference between a1 (old value) and a2 (new value), using function name_of_dim to name dimensions. The meaning of difference is library dependent. Not implemented */ void ap_ppl_grid_fdump(FILE* stream, ap_manager_t* man, struct ppl_grid* a); /* Dump the internal representation of an abstract value, for debugging purposes */ /* ============================================================ */ /* I.4 Serialization */ /* ============================================================ */ ap_membuf_t ap_ppl_grid_serialize_raw(ap_manager_t* man, struct ppl_grid* a); /* Allocate a memory buffer (with malloc), output the abstract value in raw binary format to it and return a pointer on the memory buffer and the size of bytes written. It is the user responsability to free the memory afterwards (with free). Not implemented */ struct ppl_grid* ap_ppl_grid_deserialize_raw(ap_manager_t* man, void* ptr, size_t* size); /* Return the abstract value read in raw binary format from the input stream and store in size the number of bytes read. Not implemented */ /* ********************************************************************** */ /* II. Constructor, accessors, tests and property extraction */ /* ********************************************************************** */ /* ============================================================ */ /* II.1 Basic constructors */ /* ============================================================ */ /* We assume that dimensions [0..intdim-1] correspond to integer variables, and dimensions [intdim..intdim+realdim-1] to real variables */ struct ppl_grid* ap_ppl_grid_bottom(ap_manager_t* man, size_t intdim, size_t realdim); /* Create a bottom (empty) value */ struct ppl_grid* ap_ppl_grid_top(ap_manager_t* man, size_t intdim, size_t realdim); /* Create a top (universe) value */ struct ppl_grid* ap_ppl_grid_of_box(ap_manager_t* man, size_t intdim, size_t realdim, ap_interval_t** tinterval); /* Abstract an hypercube defined by the array of intervals of size intdim+realdim */ struct ppl_grid* ap_ppl_grid_of_lincons_array(ap_manager_t* man, size_t intdim, size_t realdim, ap_lincons0_array_t* array); /* Abstract a convex polyhedra defined by the array of linear constraints of size size */ /* ============================================================ */ /* II.2 Accessors */ /* ============================================================ */ ap_dimension_t ap_ppl_grid_dimension(ap_manager_t* man, struct ppl_grid* a); /* Return the total number of dimensions of the abstract values */ /* ============================================================ */ /* II.3 Tests */ /* ============================================================ */ bool ap_ppl_grid_is_bottom(ap_manager_t* man, struct ppl_grid* a); /* Emptiness test */ bool ap_ppl_grid_is_top(ap_manager_t* man, struct ppl_grid* a); /* Universe test */ bool ap_ppl_grid_is_leq(ap_manager_t* man, struct ppl_grid* a1, struct ppl_grid* a2); /* Inclusion test */ bool ap_ppl_grid_is_eq(ap_manager_t* man, struct ppl_grid* a1, struct ppl_grid* a2); /* Equality test */ bool ap_ppl_grid_sat_lincons(ap_manager_t* man, struct ppl_grid* a, ap_lincons0_t* lincons); /* Satisfiability of a linear constraint */ bool ap_ppl_grid_sat_interval(ap_manager_t* man, struct ppl_grid* a, ap_dim_t dim, ap_interval_t* interval); /* Inclusion of a dimension in an interval */ bool ap_ppl_grid_is_dimension_unconstrained(ap_manager_t* man, struct ppl_grid* po, ap_dim_t dim); /* Is a dimension unconstrained ? */ /* ============================================================ */ /* II.4 Extraction of properties */ /* ============================================================ */ ap_interval_t* ap_ppl_grid_bound_linexpr(ap_manager_t* man, struct ppl_grid* a, ap_linexpr0_t* expr); /* Returns the interval taken by a linear expression over the abstract value. */ ap_interval_t* ap_ppl_grid_bound_dimension(ap_manager_t* man, struct ppl_grid* a, ap_dim_t dim); /* Returns the interval taken by the dimension over the abstract value. */ ap_lincons0_array_t ap_ppl_grid_to_lincons_array(ap_manager_t* man, struct ppl_grid* a); /* Converts an abstract value to a polyhedra (conjunction of linear constraints). */ ap_interval_t** ap_ppl_grid_to_box(ap_manager_t* man, struct ppl_grid* a); /* Converts an abstract value to an interval/hypercube. The size of the resulting array is ap_ppl_grid_dimension(man,a). */ ap_generator0_array_t ap_ppl_grid_to_generator_array(ap_manager_t* man, struct ppl_grid* a); /* Converts an abstract value to a system of generators. */ /* ********************************************************************** */ /* III. Operations */ /* ********************************************************************** */ /* ============================================================ */ /* III.1 Meet and Join */ /* ============================================================ */ struct ppl_grid* ap_ppl_grid_meet(ap_manager_t* man, bool destructive, struct ppl_grid* a1, struct ppl_grid* a2); struct ppl_grid* ap_ppl_grid_join(ap_manager_t* man, bool destructive, struct ppl_grid* a1, struct ppl_grid* a2); /* Meet and Join of 2 abstract values */ struct ppl_grid* ap_ppl_grid_meet_array(ap_manager_t* man, struct ppl_grid** tab, size_t size); struct ppl_grid* ap_ppl_grid_join_array(ap_manager_t* man, struct ppl_grid** tab, size_t size); /* Meet and Join of a non-empty array of abstract values. (no way to define the dimensionality of the result in such a case */ struct ppl_grid* ap_ppl_grid_meet_lincons_array(ap_manager_t* man, bool destructive, struct ppl_grid* a, ap_lincons0_array_t* array); /* Meet of an abstract value with a set of constraints (generalize ap_ppl_grid_of_lincons_array) */ struct ppl_grid* ap_ppl_grid_add_ray_array(ap_manager_t* man, bool destructive, struct ppl_grid* a, ap_generator0_array_t* array); /* Generalized time elapse operator */ /* ============================================================ */ /* III.2 Assignement and Substitutions */ /* ============================================================ */ struct ppl_grid* ap_ppl_grid_assign_linexpr(ap_manager_t* man, bool destructive, struct ppl_grid* a, ap_dim_t dim, ap_linexpr0_t* expr, struct ppl_grid* dest); struct ppl_grid* ap_ppl_grid_substitute_linexpr(ap_manager_t* man, bool destructive, struct ppl_grid* a, ap_dim_t dim, ap_linexpr0_t* expr, struct ppl_grid* dest); /* Assignement and Substitution of a single dimension by resp. a linear expression and a interval linear expression */ struct ppl_grid* ap_ppl_grid_assign_linexpr_array(ap_manager_t* man, bool destructive, struct ppl_grid* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, struct ppl_grid* dest); struct ppl_grid* ap_ppl_grid_substitute_linexpr_array(ap_manager_t* man, bool destructive, struct ppl_grid* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, struct ppl_grid* dest); /* Parallel Assignement and Substitution of several dimensions by linear expressons. */ /* ============================================================ */ /* III.3 Projections */ /* ============================================================ */ struct ppl_grid* ap_ppl_grid_forget_array(ap_manager_t* man, bool destructive, struct ppl_grid* a, ap_dim_t* tdim, size_t size, bool project); /* ============================================================ */ /* III.4 Change and permutation of dimensions */ /* ============================================================ */ struct ppl_grid* ap_ppl_grid_add_dimensions(ap_manager_t* man, bool destructive, struct ppl_grid* a, ap_dimchange_t* dimchange, bool project); struct ppl_grid* ap_ppl_grid_remove_dimensions(ap_manager_t* man, bool destructive, struct ppl_grid* a, ap_dimchange_t* dimchange); struct ppl_grid* ap_ppl_grid_permute_dimensions(ap_manager_t* man, bool destructive, struct ppl_grid* a, ap_dimperm_t* permutation); /* ============================================================ */ /* III.5 Expansion and folding of dimensions */ /* ============================================================ */ struct ppl_grid* ap_ppl_grid_expand(ap_manager_t* man, bool destructive, struct ppl_grid* a, ap_dim_t dim, size_t n); /* Expand the dimension dim into itself + n additional dimensions. It results in (n+1) unrelated dimensions having same relations with other dimensions. The (n+1) dimensions are put as follows: - original dimension dim - if the dimension is integer, the n additional dimensions are put at the end of integer dimensions; if it is real, at the end of the real dimensions. */ struct ppl_grid* ap_ppl_grid_fold(ap_manager_t* man, bool destructive, struct ppl_grid* a, ap_dim_t* tdim, size_t size); /* Fold the dimensions in the array tdim of size n>=1 and put the result in the first dimension in the array. The other dimensions of the array are then removed (using ap_ppl_grid_permute_remove_dimensions). */ /* ============================================================ */ /* III.6 Widening */ /* ============================================================ */ /* Widening */ struct ppl_grid* ap_ppl_grid_widening(ap_manager_t* man, struct ppl_grid* a1, struct ppl_grid* a2); /* ============================================================ */ /* III.7 Closure operation */ /* ============================================================ */ /* Returns the topological closure of a possibly opened abstract value */ struct ppl_grid* ap_ppl_grid_closure(ap_manager_t* man, bool destructive, struct ppl_grid* a); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/ppl/ppl_grid.cc0000640014525101416610000011243711144120547017575 0ustar bjeannetpopart/* * ppl_grid.cc * * APRON Library / PPL library wrapper * * Wrappers specific to the Grid class. * * Copyright (C) Antoine Mine' 2006 * */ /* * This file is part of the APRON Library, released under GPL license. * Please read the COPYING file packaged in the distribution. */ #include #include "ap_generic.h" #include "ap_ppl.h" #include "ppl_user.hh" #include "ppl_grid.hh" #include using namespace std; using namespace Parma_Polyhedra_Library; /* ********************************************************************** */ /* General stuff */ /* ********************************************************************** */ /* ====================================================================== */ /* Manager */ /* ====================================================================== */ static inline ppl_internal_t* get_internal(ap_manager_t* man) { return (ppl_internal_t*)man->internal; } /* ====================================================================== */ /* PPL_Grid */ /* ====================================================================== */ /* wrapper: adds initdim info */ /* grids are always "reduced" wrt intdim: we keep mod 1 constraints for integer variables */ PPL_Grid::PPL_Grid(const PPL_Grid& x) : p(new Grid(*x.p)), intdim(x.intdim) {} PPL_Grid::PPL_Grid(size_t intdim,size_t realdim,Degenerate_Element kind) : intdim(intdim) { try { p = new Grid(intdim+realdim,kind); if (kind!=EMPTY) reduce(); } catch (std::logic_error e) { intdim = 0; p = new Grid(1,kind); } } /* enforce integer constraints */ void PPL_Grid::reduce() { for (size_t i=0;iadd_congruence((Variable(i) %=0) / 1); } void PPL_Grid::forget_dim(size_t dim) { #ifndef PPL_0_9 if (intdim>dim) p->add_grid_generator(Grid_Generator::parameter(Variable(dim))); else p->add_grid_generator(Grid_Generator::grid_line(Variable(dim))); #else if (intdim>dim) p->add_generator(Grid_Generator::parameter(Variable(dim))); else p->add_generator(Grid_Generator::line(Variable(dim))); #endif } PPL_Grid::~PPL_Grid() { delete p; } /* ====================================================================== */ /* Error Handlers */ /* ====================================================================== */ /* returns a grid, of specified size if possible */ #define CATCH_WITH_DIM(funid,intdim,realdim) \ catch (cannot_convert w) { \ /* bailing out, not an error */ \ man->result.flag_exact = man->result.flag_best = false; \ return new PPL_Grid(intdim,realdim,UNIVERSE); \ } \ catch (std::logic_error e) { \ /* actual error */ \ ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT,funid,e.what()); \ return new PPL_Grid(intdim,realdim,UNIVERSE); \ } /* returns a grid, with size compatible with grid if possible */ #define CATCH_WITH_GRID(funid,grid) \ CATCH_WITH_DIM(funid,grid->intdim,grid->p->space_dimension()-grid->intdim) /* returns v */ #define CATCH_WITH_VAL(funid,v) \ catch (cannot_convert w) { \ /* bailing out, not an error */ \ man->result.flag_exact = man->result.flag_best = false; \ return v; \ } \ catch (std::logic_error e) { \ /* actual error */ \ ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT,funid,e.what()); \ return v; \ } /* returns nothing */ #define CATCH_WITH_VOID(funid) CATCH_WITH_VAL(funid,) /* prints message */ #define CATCH_WITH_MSG(funid) \ catch (cannot_convert w) { \ /* bailing out, not an error */ \ fprintf(stream,"!exception!"); \ } \ catch (std::logic_error e) { \ /* actual error */ \ ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT,funid,e.what()); \ fprintf(stream,"!exception!"); \ } /* ====================================================================== */ /* utility shared by _bound_dimension, _to_box, & _sat_interval (exact) */ /* ====================================================================== */ static void ap_ppl_grid_bound_dim(ap_interval_t* r,PPL_Grid* a,int dim) { Coefficient sup_n,sup_d,inf_n,inf_d; Linear_Expression l = Variable(dim); bool ok; /* sup bound */ if (a->p->maximize(l,sup_n,sup_d,ok)) ap_ppl_mpz2_to_scalar(r->sup,sup_n,sup_d); else ap_scalar_set_infty(r->sup,1); /* inf bound */ if (a->p->minimize(l,inf_n,inf_d,ok)) ap_ppl_mpz2_to_scalar(r->inf,inf_n,inf_d); else ap_scalar_set_infty(r->inf,-1); } static itv_t* ap_ppl_grid_to_itv_array(PPL_Grid* a) { Coefficient sup_n,sup_d; Linear_Expression l; bool ok; size_t i,nb; nb = a->p->space_dimension(); itv_t* env = itv_array_alloc(nb); for (i=0; ip->maximize(l,sup_n,sup_d,ok)){ bound_set_int(env[i]->sup,0); numrat_set_numint2(env[i]->sup,sup_n.get_mpz_t(),sup_d.get_mpz_t()); } else bound_set_infty(env[i]->sup,1); /* inf bound */ if (a->p->minimize(l,sup_n,sup_d,ok)){ bound_set_int(env[i]->inf,0); numrat_set_numint2(env[i]->inf,sup_n.get_mpz_t(),sup_d.get_mpz_t()); numrat_neg(env[i]->inf,env[i]->inf); } else bound_set_infty(env[i]->inf,1); } return env; } /* ********************************************************************** */ /* I. General management */ /* ********************************************************************** */ /* ============================================================ */ /* I.1 Memory */ /* ============================================================ */ extern "C" PPL_Grid* ap_ppl_grid_copy(ap_manager_t* man, PPL_Grid* a) { man->result.flag_exact = man->result.flag_best = true; try { return new PPL_Grid(*a); } CATCH_WITH_GRID(AP_FUNID_COPY,a); } extern "C" void ap_ppl_grid_free(ap_manager_t* man, PPL_Grid* a) { man->result.flag_exact = man->result.flag_best = true; try { delete a; } CATCH_WITH_VOID(AP_FUNID_FREE); } extern "C" size_t ap_ppl_grid_size(ap_manager_t* man, PPL_Grid* a) { man->result.flag_exact = man->result.flag_best = true; try { return a->p->total_memory_in_bytes(); } CATCH_WITH_VAL(AP_FUNID_ASIZE,0); } /* ============================================================ */ /* I.2 Control of internal representation */ /* ============================================================ */ extern "C" void ap_ppl_grid_minimize(ap_manager_t* man, PPL_Grid* a) { man->result.flag_exact = man->result.flag_best = true; try { /* re-add integer constraints (should not be needed except after a widening) */ ((PPL_Grid*)a)->reduce(); /* the calls force in-place minimisation */ (void)a->p->minimized_congruences(); #ifndef PPL_0_9 (void)a->p->minimized_grid_generators(); #else (void)a->p->minimized_generators(); #endif } CATCH_WITH_VOID(AP_FUNID_MINIMIZE); } extern "C" void ap_ppl_grid_canonicalize(ap_manager_t* man, PPL_Grid* a) { man->result.flag_exact = man->result.flag_best = true; try { /* re-add integer constraints (should not be needed except after a widening) */ ((PPL_Grid*)a)->reduce(); /* the calls force in-place minimisation */ (void)a->p->minimized_congruences(); #ifndef PPL_0_9 (void)a->p->minimized_grid_generators(); #else (void)a->p->minimized_generators(); #endif } CATCH_WITH_VOID(AP_FUNID_CANONICALIZE); } extern "C" int ap_ppl_grid_hash(ap_manager_t* man, PPL_Grid* a) { man->result.flag_exact = man->result.flag_best = true; try { ((PPL_Grid*)a)->reduce(); /* the calls force in-place minimisation */ (void)a->p->minimized_congruences(); #ifndef PPL_0_9 (void)a->p->minimized_grid_generators(); #else (void)a->p->minimized_generators(); #endif return a->p->total_memory_in_bytes(); } CATCH_WITH_VAL(AP_FUNID_HASH,0); } extern "C" void ap_ppl_grid_approximate(ap_manager_t* man, PPL_Grid* a, int algorithm) { man->result.flag_exact = man->result.flag_best = true; return; } /* ============================================================ */ /* I.3 Printing */ /* ============================================================ */ extern "C" void ap_ppl_grid_fprint(FILE* stream, ap_manager_t* man, PPL_Grid* a, char** name_of_dim) { man->result.flag_exact = man->result.flag_best = true; try { if (a->p->is_empty()){ ap_dimension_t dim = ap_ppl_grid_dimension(man,a); fprintf(stream,"empty grid of dim (%lu,%lu)\n", (unsigned long)dim.intdim,(unsigned long)dim.realdim); } else { ap_lincons0_array_t ar = ap_ppl_to_lincons_array(a->p->minimized_congruences()); ap_lincons0_array_fprint(stream,&ar,name_of_dim); ap_lincons0_array_clear(&ar); } } CATCH_WITH_MSG(AP_FUNID_FPRINT); } /* NOT IMPLEMENTED! */ extern "C" void ap_ppl_grid_fprintdiff(FILE* stream, ap_manager_t* man, PPL_Grid* a1, PPL_Grid* a2, char** name_of_dim) { ap_manager_raise_exception(man,AP_EXC_NOT_IMPLEMENTED,AP_FUNID_FPRINTDIFF,"not implemented"); } /* fdump will print the unminimized contraint & generator systems */ extern "C" void ap_ppl_grid_fdump(FILE* stream, ap_manager_t* man, PPL_Grid* a) { man->result.flag_exact = man->result.flag_best = true; try { /* dump constraints */ fprintf(stream,"constraints: "); ap_lincons0_array_t ar = ap_ppl_to_lincons_array(a->p->congruences()); ap_lincons0_array_fprint(stream,&ar,NULL); ap_lincons0_array_clear(&ar); /* dump generators */ fprintf(stream,"generators: "); #ifndef PPL_0_9 ap_generator0_array_t ar2 = ap_ppl_to_generator_array(a->p->grid_generators()); #else ap_generator0_array_t ar2 = ap_ppl_to_generator_array(a->p->generators()); #endif ap_generator0_array_fprint(stream,&ar2,NULL); ap_generator0_array_clear(&ar2); } CATCH_WITH_MSG(AP_FUNID_FPRINTDIFF); } /* ============================================================ */ /* I.4 Serialization */ /* ============================================================ */ /* NOT IMPLEMENTED! */ extern "C" ap_membuf_t ap_ppl_grid_serialize_raw(ap_manager_t* man, PPL_Grid* a) { ap_membuf_t membuf; membuf.ptr = NULL; membuf.size = 0; ap_manager_raise_exception(man,AP_EXC_NOT_IMPLEMENTED,AP_FUNID_SERIALIZE_RAW,"not implemented"); return membuf; } /* NOT IMPLEMENTED! */ extern "C" PPL_Grid* ap_ppl_grid_deserialize_raw(ap_manager_t* man, void* ptr, size_t* size) { ap_manager_raise_exception(man,AP_EXC_NOT_IMPLEMENTED,AP_FUNID_DESERIALIZE_RAW,"not implemented"); return NULL; } /* ********************************************************************** */ /* II. Constructor, accessors, tests and property extraction */ /* ********************************************************************** */ extern "C" PPL_Grid* ap_ppl_grid_bottom(ap_manager_t* man, size_t intdim, size_t realdim) { man->result.flag_exact = man->result.flag_best = true; try { return new PPL_Grid(intdim,realdim,EMPTY); } CATCH_WITH_DIM(AP_FUNID_BOTTOM,intdim,realdim); } extern "C" PPL_Grid* ap_ppl_grid_top(ap_manager_t* man, size_t intdim, size_t realdim) { man->result.flag_exact = man->result.flag_best = true; try { return new PPL_Grid(intdim,realdim,UNIVERSE); } CATCH_WITH_DIM(AP_FUNID_TOP,intdim,realdim); } extern "C" PPL_Grid* ap_ppl_grid_of_box(ap_manager_t* man, size_t intdim, size_t realdim, ap_interval_t** tinterval) { man->result.flag_exact = false; man->result.flag_best = true; try { PPL_Grid* r = new PPL_Grid(intdim,realdim,UNIVERSE); Congruence_System c; if (!ap_ppl_of_box(c,tinterval,intdim,realdim)) man->result.flag_exact = man->result.flag_best = false; r->p->add_recycled_congruences(c); return r; } CATCH_WITH_DIM(AP_FUNID_OF_BOX,intdim,realdim); } /* ============================================================ */ /* II.2 Accessors */ /* ============================================================ */ extern "C" ap_dimension_t ap_ppl_grid_dimension(ap_manager_t* man, PPL_Grid* a) { man->result.flag_exact = man->result.flag_best = true; ap_dimension_t d = { 0, 0 }; try { d.intdim = a->intdim; d.realdim = a->p->space_dimension()-a->intdim; return d; } CATCH_WITH_VAL(AP_FUNID_DIMENSION,d); } /* ============================================================ */ /* II.3 Tests */ /* ============================================================ */ extern "C" bool ap_ppl_grid_is_bottom(ap_manager_t* man, PPL_Grid* a) { man->result.flag_exact = man->result.flag_best = true; try { return a->p->is_empty(); } CATCH_WITH_VAL(AP_FUNID_IS_BOTTOM,false); } extern "C" bool ap_ppl_grid_is_top(ap_manager_t* man, PPL_Grid* a) { man->result.flag_exact = man->result.flag_best = true; try { return a->p->is_universe(); } CATCH_WITH_VAL(AP_FUNID_IS_TOP,false); } extern "C" bool ap_ppl_grid_is_leq(ap_manager_t* man, PPL_Grid* a1, PPL_Grid* a2) { man->result.flag_exact = man->result.flag_best = true; try { return a2->p->contains(*a1->p); } CATCH_WITH_VAL(AP_FUNID_IS_LEQ,false); } extern "C" bool ap_ppl_grid_is_eq(ap_manager_t* man, PPL_Grid* a1, PPL_Grid* a2) { man->result.flag_exact = man->result.flag_best = true; try { return *a1->p == *a2->p; } CATCH_WITH_VAL(AP_FUNID_IS_EQ,false); } extern "C" bool ap_ppl_grid_sat_lincons(ap_manager_t* man, PPL_Grid* a, ap_lincons0_t* lincons0) { ppl_internal_t* intern = get_internal(man); man->result.flag_exact = man->result.flag_best = true; try { if (a->p->is_empty()){ return true; } else { itv_lincons_t lincons; mpz_class den; Congruence c = Congruence::zero_dim_false(); bool res; if (!ap_linexpr0_is_linear(lincons0->linexpr0)){ man->result.flag_exact = man->result.flag_best = false; return false; } itv_lincons_init(&lincons); if (!itv_lincons_set_ap_lincons0(intern->itv,&lincons,lincons0)) man->result.flag_exact = man->result.flag_best = false; if (itv_sat_lincons_is_false(intern->itv,&lincons)){ itv_lincons_clear(&lincons); return false; } assert(itv_lincons_is_scalar(&lincons)); try { if (!ap_ppl_of_itv_lincons(c,den,&lincons)) man->result.flag_exact = man->result.flag_best = false; Poly_Con_Relation relation = a->p->relation_with(c); if (relation.implies(Poly_Con_Relation::is_included())){ res = true; } else { res = false; } man->result.flag_exact = man->result.flag_best = true; } catch (cannot_convert w) { man->result.flag_exact = man->result.flag_best = false; res = false; } itv_lincons_clear(&lincons); return res; } } CATCH_WITH_VAL(AP_FUNID_SAT_LINCONS,false); } extern "C" bool ap_ppl_grid_sat_tcons(ap_manager_t* man, PPL_Grid* a, ap_tcons0_t* cons) { return ap_generic_sat_tcons(man,a,cons,AP_SCALAR_MPQ,true); } extern "C" bool ap_ppl_grid_sat_interval(ap_manager_t* man, PPL_Grid* a, ap_dim_t dim, ap_interval_t* i) { ap_interval_t* ig = ap_interval_alloc(); man->result.flag_exact = man->result.flag_best = false; try { ap_ppl_grid_bound_dim(ig,a,dim); bool r = ap_interval_is_leq(ig,i); ap_interval_free(ig); return r || a->p->is_empty(); } CATCH_WITH_VAL(AP_FUNID_SAT_INTERVAL,(ap_interval_free(ig),false)); } extern "C" bool ap_ppl_grid_is_dimension_unconstrained(ap_manager_t* man, PPL_Grid* a, ap_dim_t dim) { man->result.flag_exact = man->result.flag_best = true; try { #ifndef PPL_0_9 Grid_Generator g = Grid_Generator::grid_line(Variable(dim)); #else Grid_Generator g = Grid_Generator::line(Variable(dim)); #endif return a->p->relation_with(g) == Poly_Gen_Relation::subsumes(); } CATCH_WITH_VAL(AP_FUNID_IS_DIMENSION_UNCONSTRAINED,false); } /* ============================================================ */ /* II.4 Extraction of properties */ /* ============================================================ */ extern "C" ap_interval_t* ap_ppl_grid_bound_linexpr(ap_manager_t* man, PPL_Grid* a, ap_linexpr0_t* expr) { ppl_internal_t* intern = get_internal(man); man->result.flag_exact = man->result.flag_best = true; ap_interval_t* r = ap_interval_alloc(); try { if (a->p->is_empty()) { /* empty */ ap_interval_set_bottom(r); } else { /* not empty */ itv_linexpr_t linexpr; Coefficient sup_n,sup_d; Linear_Expression l; mpz_class den; bool ok; bool exact = true; itv_linexpr_init(&linexpr,0); exact = itv_linexpr_set_ap_linexpr0(intern->itv,&linexpr,expr) && exact; if (!itv_linexpr_is_quasilinear(&linexpr)){ itv_t* env = ap_ppl_grid_to_itv_array(a); exact = itv_quasilinearize_linexpr(intern->itv,&linexpr,env,false); itv_array_free(env,a->p->space_dimension()); } if (linexpr.size==0){ ap_interval_set_itv(intern->itv,r,linexpr.cst); } else { /* sup bound */ if (bound_infty(linexpr.cst->sup)){ ap_scalar_set_infty(r->sup,1); } else { ap_ppl_of_linexpr(intern->itv,l,den,expr,1); if (a->p->maximize(l,sup_n,sup_d,ok)) { sup_d *= den; ap_ppl_mpz2_to_scalar(r->sup,sup_n,sup_d); } else ap_scalar_set_infty(r->sup,1); } /* inf bound */ if (bound_infty(linexpr.cst->inf)){ ap_scalar_set_infty(r->inf,-1); } else { if (!itv_linexpr_is_scalar(&linexpr)){ ap_ppl_of_itv_linexpr(l,den,&linexpr,-1); } if (a->p->minimize(l,sup_n,sup_d,ok)) { sup_d *= den; ap_ppl_mpz2_to_scalar(r->inf,sup_n,sup_d); } else { ap_scalar_set_infty(r->inf,-1); } } } if (!exact) man->result.flag_exact = man->result.flag_best = false; itv_linexpr_clear(&linexpr); } } CATCH_WITH_VAL(AP_FUNID_BOUND_LINEXPR,(ap_interval_set_top(r),r)); return r; } extern "C" ap_interval_t* ap_ppl_grid_bound_texpr(ap_manager_t* man, PPL_Grid* a, ap_texpr0_t* expr) { return ap_generic_bound_texpr(man,a,expr,AP_SCALAR_MPQ,true); } extern "C" ap_interval_t* ap_ppl_grid_bound_dimension(ap_manager_t* man, PPL_Grid* a, ap_dim_t dim) { man->result.flag_exact = man->result.flag_best = true; ap_interval_t* r = ap_interval_alloc(); try { if (a->p->is_empty()) ap_interval_set_bottom(r); /* empty */ else ap_ppl_grid_bound_dim(r,a,dim); /* not empty */ return r; } CATCH_WITH_VAL(AP_FUNID_BOUND_DIMENSION,(ap_interval_set_top(r),r)); } extern "C" ap_lincons0_array_t ap_ppl_grid_to_lincons_array(ap_manager_t* man, PPL_Grid* a) { man->result.flag_exact = man->result.flag_best = true; try { return ap_ppl_to_lincons_array(a->p->congruences()); } CATCH_WITH_VAL(AP_FUNID_TO_LINCONS_ARRAY,ap_lincons0_array_make(0)); } extern "C" ap_tcons0_array_t ap_ppl_grid_to_tcons_array(ap_manager_t* man, PPL_Grid* a) { return ap_generic_to_tcons_array(man,a); } extern "C" ap_interval_t** ap_ppl_grid_to_box(ap_manager_t* man, PPL_Grid* a) { man->result.flag_exact = man->result.flag_best = true; size_t dim = a->p->space_dimension(); ap_interval_t** in = ap_interval_array_alloc(dim); try { if (a->p->is_empty()){ /* empty */ for (size_t i=0;iresult.flag_exact = man->result.flag_best = true; try { #ifndef PPL_0_9 return ap_ppl_to_generator_array(a->p->grid_generators()); #else return ap_ppl_to_generator_array(a->p->generators()); #endif } CATCH_WITH_VAL(AP_FUNID_TO_GENERATOR_ARRAY,ap_ppl_generator_universe(a->p->space_dimension())); } /* ********************************************************************** */ /* III. Operations */ /* ********************************************************************** */ /* ============================================================ */ /* III.1 Meet and Join */ /* ============================================================ */ extern "C" PPL_Grid* ap_ppl_grid_meet(ap_manager_t* man, bool destructive, PPL_Grid* a1, PPL_Grid* a2) { man->result.flag_exact = man->result.flag_best = true; try { PPL_Grid* r = destructive ? a1 : new PPL_Grid(*a1); r->p->intersection_assign(*a2->p); return r; } CATCH_WITH_GRID(AP_FUNID_MEET,a1); } extern "C" PPL_Grid* ap_ppl_grid_join(ap_manager_t* man, bool destructive, PPL_Grid* a1, PPL_Grid* a2) { man->result.flag_exact = false; man->result.flag_best = true; try { PPL_Grid* r = destructive ? a1 : new PPL_Grid(*a1); /* TODO: should we use join_assign_if_exact? */ #ifndef PPL_0_9 r->p->upper_bound_assign(*a2->p); #else r->p->join_assign(*a2->p); #endif return r; } CATCH_WITH_GRID(AP_FUNID_JOIN,a1); } extern "C" PPL_Grid* ap_ppl_grid_meet_array(ap_manager_t* man, PPL_Grid** tab, size_t size) { assert(size>=1); man->result.flag_exact = man->result.flag_best = true; try { PPL_Grid* r = new PPL_Grid(*tab[0]); for (size_t i=1;ip->intersection_assign(*tab[i]->p); return r; } CATCH_WITH_GRID(AP_FUNID_MEET_ARRAY,tab[0]); } extern "C" PPL_Grid* ap_ppl_grid_join_array(ap_manager_t* man, PPL_Grid** tab, size_t size) { assert(size>=1); man->result.flag_exact = false; man->result.flag_best = true; try { PPL_Grid* r = new PPL_Grid(*tab[0]); for (size_t i=1;ip->upper_bound_assign(*tab[i]->p); #else r->p->join_assign(*tab[i]->p); #endif return r; } CATCH_WITH_GRID(AP_FUNID_JOIN_ARRAY,tab[0]); } extern "C" PPL_Grid* ap_ppl_grid_meet_lincons_array(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_lincons0_array_t* array) { ppl_internal_t* intern = get_internal(man); man->result.flag_exact = man->result.flag_best = true; try { PPL_Grid* r = destructive ? a : new PPL_Grid(*a); Congruence_System c; if (!ap_ppl_of_lincons_array(intern->itv,c,array)) man->result.flag_exact = man->result.flag_best = false; r->p->add_recycled_congruences(c); return r; } CATCH_WITH_GRID(AP_FUNID_MEET_LINCONS_ARRAY,a); } extern "C" PPL_Grid* ap_ppl_grid_meet_tcons_array(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_tcons0_array_t* array) { return (PPL_Grid*)ap_generic_meet_intlinearize_tcons_array(man,destructive, a, array, AP_SCALAR_MPQ, AP_LINEXPR_LINEAR, (void* (*)(ap_manager_t*, bool, void*, ap_lincons0_array_t*)) (&ap_ppl_grid_meet_lincons_array)); } extern "C" PPL_Grid* ap_ppl_grid_add_ray_array(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_generator0_array_t* array) { ppl_internal_t* intern = get_internal(man); man->result.flag_exact = man->result.flag_best = true; try { PPL_Grid* r = destructive ? a : new PPL_Grid(*a); if (!a->p->is_empty()){ Grid_Generator_System c; if (!ap_ppl_of_generator_array(intern->itv,c,array)) man->result.flag_exact = man->result.flag_best = false; #ifndef PPL_0_9 r->p->add_recycled_grid_generators(c); #else r->p->add_recycled_generators(c); #endif r->reduce(); } return r; } CATCH_WITH_GRID(AP_FUNID_ADD_RAY_ARRAY,a); } /* ============================================================ */ /* III.2 Assignement and Substitutions */ /* ============================================================ */ extern "C" PPL_Grid* ap_ppl_grid_assign_linexpr(ap_manager_t* man, bool destructive, PPL_Grid* org, ap_dim_t dim, ap_linexpr0_t* expr, PPL_Grid* dest) { bool exact; ppl_internal_t* intern = get_internal(man); man->result.flag_exact = man->result.flag_best = true; try { PPL_Grid* r = destructive ? org : new PPL_Grid(*org); try { Linear_Expression e; mpz_class den; if (!ap_linexpr0_is_linear(expr)){ throw cannot_convert(); } ap_ppl_of_linexpr(intern->itv,e,den,expr,1); r->p->affine_image(Variable(dim),e,den); r->reduce(); } catch (cannot_convert x) { /* defaults to forget */ r->forget_dim(dim); if (dimintdim) r->reduce(); man->result.flag_exact = man->result.flag_best = false; } if (dest) r->p->intersection_assign(*dest->p); return r; } CATCH_WITH_GRID(AP_FUNID_ASSIGN_LINEXPR_ARRAY,org); } extern "C" PPL_Grid* ap_ppl_grid_substitute_linexpr(ap_manager_t* man, bool destructive, PPL_Grid* org, ap_dim_t dim, ap_linexpr0_t* expr, PPL_Grid* dest) { bool exact; ppl_internal_t* intern = get_internal(man); man->result.flag_exact = man->result.flag_best = true; try { PPL_Grid* r = destructive ? org : new PPL_Grid(*org); try { Linear_Expression e; mpz_class den; if (!ap_linexpr0_is_linear(expr)){ throw cannot_convert(); } ap_ppl_of_linexpr(intern->itv,e,den,expr,1); r->p->affine_preimage(Variable(dim),e,den); r->reduce(); } catch (cannot_convert x) { /* defaults to forget */ r->forget_dim(dim); if (dimintdim) r->reduce(); man->result.flag_exact = man->result.flag_best = false; } if (dest) r->p->intersection_assign(*dest->p); return r; } CATCH_WITH_GRID(AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY,org); } extern "C" PPL_Grid* ap_ppl_grid_assign_linexpr_array(ap_manager_t* man, bool destructive, PPL_Grid* org, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, PPL_Grid* dest) { PPL_Grid* r; size_t i; bool exact = true; for (i=0;iintdim) man->result.flag_exact = man->result.flag_best = false; return r; } extern "C" PPL_Grid* ap_ppl_grid_substitute_linexpr_array(ap_manager_t* man, bool destructive, PPL_Grid* org, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, PPL_Grid* dest) { PPL_Grid* r; size_t i; bool exact = true; for (i=0;iintdim) man->result.flag_exact = man->result.flag_best = false; return r; } extern "C" PPL_Grid* ap_ppl_grid_forget_array(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dim_t* tdim, size_t size, bool project) { man->result.flag_exact = man->result.flag_best = true; try { PPL_Grid* r = destructive ? a : new PPL_Grid(*a); if (!a->p->is_empty()){ for (size_t i=0;iforget_dim(tdim[i]); if (project) { for (size_t i=0;ip->add_constraint(Variable(tdim[i])==0); } else { r->reduce(); } } return r; } CATCH_WITH_GRID(AP_FUNID_FORGET_ARRAY,a); } extern "C" PPL_Grid* ap_ppl_grid_assign_texpr_array(ap_manager_t* man, bool destructive, PPL_Grid* org, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, PPL_Grid* dest) { return (PPL_Grid*)ap_generic_assign_texpr_array(man, destructive, org, tdim,texpr,size, dest); } extern "C" PPL_Grid* ap_ppl_grid_substitute_texpr_array(ap_manager_t* man, bool destructive, PPL_Grid* org, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, PPL_Grid* dest) { return (PPL_Grid*)ap_generic_substitute_texpr_array(man, destructive, org, tdim,texpr,size, dest); } /* partial functions used in map_space_dimensions */ class ap_ppl_map { protected: size_t dom,codom,*tab; char* def; public: ap_ppl_map(size_t dom,size_t codom) : dom(dom), codom(codom) { tab = new size_t [dom]; def = new char [dom]; memset(def,0,dom); } ~ap_ppl_map() { delete[] tab; delete[] def; } void set(dimension_type i,dimension_type j) { tab[i] = j; def[i] = 1; } bool has_empty_codomain() const { return codom==0; } dimension_type max_in_codomain() const { return codom-1; } bool maps(dimension_type i,dimension_type& j) const { j = tab[i]; return def[i]; } void do_map(PPL_Grid* r) const { r->p->map_space_dimensions(*this); } }; extern "C" PPL_Grid* ap_ppl_grid_add_dimensions(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dimchange_t* dimchange, bool project) { man->result.flag_exact = man->result.flag_best = true; size_t adddim = dimchange->intdim+dimchange->realdim; size_t olddim = a->p->space_dimension(); try { PPL_Grid* r = destructive ? a : new PPL_Grid(*a); /* add dimensions */ if (project) r->p->add_space_dimensions_and_project(adddim); else r->p->add_space_dimensions_and_embed(adddim); /* reorder dimensions */ ap_ppl_map map = ap_ppl_map(olddim+adddim,olddim+adddim); size_t i,j=0; for (i=0;idim[i];j++) map.set(j,i+j); map.set(olddim+i,i+j); } for (;jintdim += dimchange->intdim; r->reduce(); return r; } CATCH_WITH_DIM(AP_FUNID_ADD_DIMENSIONS,a->intdim+dimchange->intdim,olddim+dimchange->realdim-a->intdim); } extern "C" PPL_Grid* ap_ppl_grid_remove_dimensions(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dimchange_t* dimchange) { man->result.flag_exact = man->result.flag_best = true; size_t deldim = dimchange->intdim+dimchange->realdim; size_t olddim = a->p->space_dimension(); try { PPL_Grid* r = destructive ? a : new PPL_Grid(*a); /* reorder & drop dimensions */ ap_ppl_map map = ap_ppl_map(olddim,olddim-deldim); for (size_t j=0,i=0;jdim[i]) i++; else map.set(j,j-i); map.do_map(r); r->intdim -= dimchange->intdim; return r; } CATCH_WITH_DIM(AP_FUNID_REMOVE_DIMENSIONS,a->intdim-dimchange->intdim,olddim-dimchange->realdim-a->intdim); } extern "C" PPL_Grid* ap_ppl_grid_permute_dimensions(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dimperm_t* perm) { man->result.flag_exact = false; man->result.flag_best = true; try { PPL_Grid* r = destructive ? a : new PPL_Grid(*a); ap_ppl_map map = ap_ppl_map(perm->size,perm->size); for (size_t i=0;isize;i++) map.set(i,perm->dim[i]); map.do_map(r); return r; } CATCH_WITH_GRID(AP_FUNID_PERMUTE_DIMENSIONS,a); } extern "C" PPL_Grid* ap_ppl_grid_expand(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dim_t dim, size_t n) { man->result.flag_exact = man->result.flag_best = true; try { size_t olddim = a->p->space_dimension(); PPL_Grid* r = destructive ? a : new PPL_Grid(*a); r->p->expand_space_dimension(Variable(dim),n); if (dimintdim) { /* expanded an integer dimension => needs some reordering */ ap_ppl_map map = ap_ppl_map(olddim+n,olddim+n); size_t i; for (i=0;iintdim;i++) map.set(i,i); for (i=0;iintdim+i); for (i=r->intdim;iintdim += n; } return r; } CATCH_WITH_DIM(AP_FUNID_EXPAND,a->intdim,a->p->space_dimension()-a->intdim+n); } extern "C" PPL_Grid* ap_ppl_grid_fold(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dim_t* tdim, size_t size) { man->result.flag_exact = false; man->result.flag_best = true; try { PPL_Grid* r = destructive ? a : new PPL_Grid(*a); Variables_Set s; assert(size>0); for (size_t i=1;ip->fold_space_dimensions(s,Variable(tdim[0])); if (tdim[0]intdim) r->intdim -= size-1; r->reduce(); return r; } CATCH_WITH_DIM(AP_FUNID_FOLD,a->intdim,a->p->space_dimension()-a->intdim-size); } extern "C" PPL_Grid* ap_ppl_grid_widening(ap_manager_t* man, PPL_Grid* a1, PPL_Grid* a2) { man->result.flag_exact = man->result.flag_best = false; try { PPL_Grid* r = new PPL_Grid(*a2); r->p->widening_assign(*a1->p); r->reduce(); return r; } CATCH_WITH_GRID(AP_FUNID_WIDENING,a1); } extern "C" PPL_Grid* ap_ppl_grid_widening_threshold(ap_manager_t* man, PPL_Grid* a1, PPL_Grid* a2, ap_lincons0_array_t* array) { ppl_internal_t* intern = get_internal(man); man->result.flag_exact = man->result.flag_best = false; try { Congruence_System c; /* when a1->strict=false, c will not contain any strict constraint */ ap_ppl_of_lincons_array(intern->itv,c,array); PPL_Grid* r = new PPL_Grid(*a2); r->p->limited_extrapolation_assign(*a1->p,c); r->reduce(); return r; } CATCH_WITH_GRID(AP_FUNID_WIDENING,a1); } extern "C" PPL_Grid* ap_ppl_grid_closure(ap_manager_t* man, bool destructive, PPL_Grid* a) { man->result.flag_exact = man->result.flag_best = true; try { PPL_Grid* r = destructive ? a : new PPL_Grid(*a); r->p->topological_closure_assign(); return r; } CATCH_WITH_GRID(AP_FUNID_CLOSURE,a); } /* ********************************************************************** */ /* Managers */ /* ********************************************************************** */ extern "C" ap_manager_t* ap_ppl_grid_manager_alloc(void) { int i; ppl_internal_t* ppl; ap_manager_t* man; ppl = ap_ppl_internal_alloc(false); man = ap_manager_alloc("PPL::Grid", PPL_VERSION, ppl, &ap_ppl_internal_free); assert(man); man->funptr[AP_FUNID_COPY] = (void*)ap_ppl_grid_copy; man->funptr[AP_FUNID_FREE] = (void*)ap_ppl_grid_free; man->funptr[AP_FUNID_ASIZE] = (void*)ap_ppl_grid_size; man->funptr[AP_FUNID_MINIMIZE] = (void*)ap_ppl_grid_minimize; man->funptr[AP_FUNID_CANONICALIZE] = (void*)ap_ppl_grid_canonicalize; man->funptr[AP_FUNID_HASH] = (void*)ap_ppl_grid_hash; man->funptr[AP_FUNID_APPROXIMATE] = (void*)ap_ppl_grid_approximate; man->funptr[AP_FUNID_FPRINT] = (void*)ap_ppl_grid_fprint; man->funptr[AP_FUNID_FPRINTDIFF] = (void*)ap_ppl_grid_fprintdiff; man->funptr[AP_FUNID_FDUMP] = (void*)ap_ppl_grid_fdump; man->funptr[AP_FUNID_SERIALIZE_RAW] = (void*)ap_ppl_grid_serialize_raw; man->funptr[AP_FUNID_DESERIALIZE_RAW] = (void*)ap_ppl_grid_deserialize_raw; man->funptr[AP_FUNID_BOTTOM] = (void*)ap_ppl_grid_bottom; man->funptr[AP_FUNID_TOP] = (void*)ap_ppl_grid_top; man->funptr[AP_FUNID_OF_BOX] = (void*)ap_ppl_grid_of_box; man->funptr[AP_FUNID_DIMENSION] = (void*)ap_ppl_grid_dimension; man->funptr[AP_FUNID_IS_BOTTOM] = (void*)ap_ppl_grid_is_bottom; man->funptr[AP_FUNID_IS_TOP] = (void*)ap_ppl_grid_is_top; man->funptr[AP_FUNID_IS_LEQ] = (void*)ap_ppl_grid_is_leq; man->funptr[AP_FUNID_IS_EQ] = (void*)ap_ppl_grid_is_eq; man->funptr[AP_FUNID_IS_DIMENSION_UNCONSTRAINED] = (void*)ap_ppl_grid_is_dimension_unconstrained; man->funptr[AP_FUNID_SAT_INTERVAL] = (void*)ap_ppl_grid_sat_interval; man->funptr[AP_FUNID_SAT_LINCONS] = (void*)ap_ppl_grid_sat_lincons; man->funptr[AP_FUNID_SAT_TCONS] = (void*)ap_ppl_grid_sat_tcons; man->funptr[AP_FUNID_BOUND_DIMENSION] = (void*)ap_ppl_grid_bound_dimension; man->funptr[AP_FUNID_BOUND_LINEXPR] = (void*)ap_ppl_grid_bound_linexpr; man->funptr[AP_FUNID_BOUND_TEXPR] = (void*)ap_ppl_grid_bound_texpr; man->funptr[AP_FUNID_TO_BOX] = (void*)ap_ppl_grid_to_box; man->funptr[AP_FUNID_TO_LINCONS_ARRAY] = (void*)ap_ppl_grid_to_lincons_array; man->funptr[AP_FUNID_TO_TCONS_ARRAY] = (void*)ap_ppl_grid_to_tcons_array; man->funptr[AP_FUNID_TO_GENERATOR_ARRAY] = (void*)ap_ppl_grid_to_generator_array; man->funptr[AP_FUNID_MEET] = (void*)ap_ppl_grid_meet; man->funptr[AP_FUNID_MEET_ARRAY] = (void*)ap_ppl_grid_meet_array; man->funptr[AP_FUNID_MEET_LINCONS_ARRAY] = (void*)ap_ppl_grid_meet_lincons_array; man->funptr[AP_FUNID_MEET_TCONS_ARRAY] = (void*)ap_ppl_grid_meet_tcons_array; man->funptr[AP_FUNID_JOIN] = (void*)ap_ppl_grid_join; man->funptr[AP_FUNID_JOIN_ARRAY] = (void*)ap_ppl_grid_join_array; man->funptr[AP_FUNID_ADD_RAY_ARRAY] = (void*)ap_ppl_grid_add_ray_array; man->funptr[AP_FUNID_ASSIGN_LINEXPR_ARRAY] = (void*)ap_ppl_grid_assign_linexpr_array; man->funptr[AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY] = (void*)ap_ppl_grid_substitute_linexpr_array; man->funptr[AP_FUNID_ASSIGN_TEXPR_ARRAY] = (void*)ap_ppl_grid_assign_texpr_array; man->funptr[AP_FUNID_SUBSTITUTE_TEXPR_ARRAY] = (void*)ap_ppl_grid_substitute_texpr_array; man->funptr[AP_FUNID_ADD_DIMENSIONS] = (void*)ap_ppl_grid_add_dimensions; man->funptr[AP_FUNID_REMOVE_DIMENSIONS] = (void*)ap_ppl_grid_remove_dimensions; man->funptr[AP_FUNID_PERMUTE_DIMENSIONS] = (void*)ap_ppl_grid_permute_dimensions; man->funptr[AP_FUNID_FORGET_ARRAY] = (void*)ap_ppl_grid_forget_array; man->funptr[AP_FUNID_EXPAND] = (void*)ap_ppl_grid_expand; man->funptr[AP_FUNID_FOLD] = (void*)ap_ppl_grid_fold; man->funptr[AP_FUNID_WIDENING] = (void*)ap_ppl_grid_widening; man->funptr[AP_FUNID_CLOSURE] = (void*)ap_ppl_grid_closure; for (i=0;i0}). Managers in strict mode or in loose mode (strict constraints disabled) are not compatible, and so are corresponding abstract values. @end deftypefun @deftypefun ap_manager_t* ap_ppl_grid_manager_alloc () Allocate an APRON manager for linear equalities, linked to the PPL library. @end deftypefun @c =================================================================== @node APRON PPL standard options, , Allocating APRON PPL managers, PPL @subsection APRON PPL standard options @c =================================================================== Currently, the only options available are related to the widening operators. @multitable @columnfractions .2 .06 .74 @item Function @tab algo @tab Comments @item @item widening @tab <=0 @tab CH78 standard widening (Cousot & Halbwachs, POPL'1978). @item @tab >0 @tab BHRZ03 widening (Bagnara, Hill, Ricci & Zafanella, SAS'2003) @item @item widening_threshold @tab <=0 @tab standard widening with threshold @item @tab =1 @tab standard widening with threshold, intersected by the bounding box of the convex hull pof the two arguments @item @tab <=0 @tab standard widening with threshold @item @tab =1 @tab standard widening with threshold, intersected by the bounding box of the convex hull of the second argument. This is actually an extrapolation rather than a widening (termination is not guaranteed) @item @tab =2 @tab BHRZ03 widening with threshold @item @tab =3 @tab BHRZ03 widening with threshold, intersected by the bounding box of the convex hull of the second argument. This is actually an extrapolation rather than a widening (termination is not guaranteed) @end multitable apron-dist-0.9.10/apron/ppl/mlexample.ml0000640014525101416610000001331411251675321020002 0ustar bjeannetpopart(* This file is part of the APRON Library, released under LGPL license. (use of PPL) Please read the COPYING file packaged in the distribution. *) (* with default setting (if dynamic libraries): ocaml -I $MLGMPIDL_INSTALL/lib -I $APRON_INSTALL/lib #load "bigarray.cma";; #load "gmp.cma";; #load "apron.cma";; #load "ppl.cma";; #install_printer Apron.Linexpr1.print;; #install_printer Apron.Texpr1.print;; #install_printer Apron.Lincons1.print;; #install_printer Apron.Generator1.print;; #install_printer Apron.Abstract1.print;; let environment_print fmt x = Apron.Environment.print fmt x;; let lincons1_array_print fmt x = Apron.Lincons1.array_print fmt x;; let generator1_array_print fmt x = Apron.Generator1.array_print fmt x;; #install_printer Apron.Var.print;; #install_printer environment_print;; #install_printer lincons1_array_print;; #install_printer generator1_array_print;; *) open Apron;; open Mpqf;; open Format;; let print_array = Abstract0.print_array;; let lincons1_array_print fmt x = Lincons1.array_print fmt x ;; let generator1_array_print fmt x = Generator1.array_print fmt x ;; let man = Ppl.manager_alloc_loose ();; let var_x = Var.of_string "x";; let var_y = Var.of_string "y";; let var_z = Var.of_string "z";; let var_w = Var.of_string "w";; let var_u = Var.of_string "u";; let var_v = Var.of_string "v";; let var_a = Var.of_string "a";; let var_b = Var.of_string "b";; let ex1 (man:'a Manager.t) : 'a Abstract1.t = printf "Using Library: %s, version %s@." (Manager.get_library man) (Manager.get_version man); let env = Environment.make [|var_x; var_y; var_z; var_w|] [|var_u; var_v; var_a; var_b|] in let env2 = Environment.make [|var_x; var_y; var_z; var_w|] [||] in printf "env=%a@.env2=%a@." (fun x -> Environment.print x) env (fun x -> Environment.print x) env2 ; (* Creation of abstract value 1/2x+2/3y=1, [1,2]<=z+2w<=4, 0<=u<=5 *) let tab = Parser.lincons1_of_lstring env ["1/2x+2/3y=1"; "[1;2]<=z+2w";"z+2w<=4"; "0<=u";"u<=5"] in printf "tab = %a@." lincons1_array_print tab; let abs = Abstract1.of_lincons_array man env tab in printf "abs=%a@." Abstract1.print abs; (* Extraction (we first extract values for existing constraints, then for dimensions) *) let box = Abstract1.to_box man abs in printf "box=%a@." (print_array Interval.print) box.Abstract1.interval_array; for i=0 to 4 do let expr = Lincons1.get_linexpr1 (Lincons1.array_get tab i) in let box = Abstract1.bound_linexpr man abs expr in printf "Bound of %a = %a@." Linexpr1.print expr Interval.print box; done; (* 2. dimensions *) (* 3. of box *) let abs2 = Abstract1.of_box man env [|var_x; var_y; var_z; var_w; var_u; var_v; var_a; var_b|] box.Abstract1.interval_array in printf "abs2=%a@." Abstract1.print abs2; (* 4. Tests top and bottom *) let abs3 = Abstract1.bottom man env in printf "abs3=%a@.is_bottom(abs3)=%b@." Abstract1.print abs3 (Abstract1.is_bottom man abs3); printf "abs=%a@." Abstract1.print abs; let p2 = Abstract1.expand man abs var_y [|Var.of_string "y1"; Var.of_string "y2"|] in printf "p2=expand(abs,y,[y1,y2]))=%a@." Abstract1.print p2; let p2 = Abstract1.expand man abs var_u [|Var.of_string "u1"; Var.of_string "u2"|] in printf "p2=expand(abs,u,[u1,u2]))=%a@." Abstract1.print p2; (* Tree expressions *) let texpr = Parser.texpr1_of_string env "a + (x*y*y/sqrt(b))" in let abs2 = Abstract1.assign_texpr man abs var_u texpr None in printf "abs2=%a@." Abstract1.print abs2; abs ;; let ex2 (man:'a Manager.t) = let env = Environment.make [||] [|var_x; var_y; var_z|] in (* Creation of abstract value 5<=x<=14, 4<=y<=12, z=0 *) let abs1 = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int 5 14; Interval.of_int 4 12; Interval.of_int 0 0; |] in let abs2 = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int 3 12; Interval.of_int 5 13; Interval.of_int 1 1; |] in let abs3 = Abstract1.join man abs1 abs2 in abs3 ;; (* Comparing join of two different assignements and assignement by the "join" of expressions *) let ex3 (man:'a Manager.t) = let env = Environment.make [||] [|var_x; var_y; var_z|] in (* Creation of abstract value -3<=x<=-2, 10<=y<=12, -1<=z<=1 *) let abs = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int (-3) (-2); Interval.of_int 10 12; Interval.of_int (-1) (1) |] in (* Creation of linear expressions *) let linexpr1 = Parser.linexpr1_of_string env "z+x+2y" in let linexpr2 = Parser.linexpr1_of_string env "z+2x+y" in let abs1 = Abstract1.assign_linexpr man abs var_z linexpr1 None in let abs2 = Abstract1.assign_linexpr man abs var_z linexpr2 None in let res1 = Abstract1.join man abs1 abs2 in printf "abs=%a@.abs1=%a@.abs2=%a@.res1=%a@." Abstract1.print abs Abstract1.print abs1 Abstract1.print abs2 Abstract1.print res1; (* Creation of linear expression [1,2]y and [1,2]z *) let linexpr = Parser.linexpr1_of_string env "z + [1;2]x + [1;2]y" in let res2 = Abstract1.assign_linexpr man abs var_z linexpr None in printf "res2=%a@." Abstract1.print res2 ; let abs1 = Abstract1.substitute_linexpr man res1 var_z linexpr1 None in let abs2 = Abstract1.substitute_linexpr man res1 var_z linexpr2 None in let res1 = Abstract1.join man abs1 abs2 in printf "abs1=%a@.abs2=%a@.res1=%a@." Abstract1.print abs1 Abstract1.print abs2 Abstract1.print res1 ; let res2 = Abstract1.substitute_linexpr man res2 var_z linexpr None in printf "res2=%a@." Abstract1.print res2 ; res1 ;; let abs1 = ex1 man;; let abs2 = ex2 man;; let abs3 = ex3 man;; apron-dist-0.9.10/apron/ppl/ap_ppl_caml.c0000640014525101416610000000625011252216517020077 0ustar bjeannetpopart/* File generated from ppl.idl */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include /* This file is part of the APRON Library, released under GPL license. Please read the COPYING file packaged in the distribution. */ #include "ap_ppl.h" #include "apron_caml.h" #define I0_CHECK_EXC(man) if (man->result.exn!=AP_EXC_NONE){ value v = camlidl_c2ml_manager_struct_ap_exclog_t(man->result.exclog,_ctx); caml_raise_with_arg(*caml_named_value("apron exception"),v); } extern void camlidl_apron_manager_funid_ml2c(value, ap_funid_t *); #define camlidl_ml2c_manager_ap_funid_t(v,c,ctx) camlidl_apron_manager_funid_ml2c(v,c) extern value camlidl_apron_manager_funid_c2ml(ap_funid_t *); #define camlidl_c2ml_manager_ap_funid_t(c,ctx) camlidl_apron_manager_funid_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_funopt_t(value, struct ap_funopt_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_funopt_t(struct ap_funopt_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_exc_ml2c(value, ap_exc_t *); #define camlidl_ml2c_manager_ap_exc_t(v,c,ctx) camlidl_apron_manager_exc_ml2c(v,c) extern value camlidl_apron_manager_exc_c2ml(ap_exc_t *); #define camlidl_c2ml_manager_ap_exc_t(c,ctx) camlidl_apron_manager_exc_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_exclog_t(value, struct ap_exclog_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_exclog_t(struct ap_exclog_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_ptr_ml2c(value, ap_manager_ptr *); #define camlidl_ml2c_manager_ap_manager_ptr(v,c,ctx) camlidl_apron_manager_ptr_ml2c(v,c) extern value camlidl_apron_manager_ptr_c2ml(ap_manager_ptr *); #define camlidl_c2ml_manager_ap_manager_ptr(c,ctx) camlidl_apron_manager_ptr_c2ml(c) value camlidl_ppl_ap_ppl_manager_alloc_loose(value _unit) { ap_manager_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; /* begin user-supplied calling sequence */ _res = ap_ppl_poly_manager_alloc(false); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_manager_ap_manager_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_ppl_ap_ppl_manager_alloc_strict(value _unit) { ap_manager_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; /* begin user-supplied calling sequence */ _res = ap_ppl_poly_manager_alloc(true); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_manager_ap_manager_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_ppl_ap_ppl_manager_alloc_grid(value _unit) { ap_manager_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; /* begin user-supplied calling sequence */ _res = ap_ppl_grid_manager_alloc(); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_manager_ap_manager_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } apron-dist-0.9.10/apron/ppl/README0000640014525101416610000000416711144120547016346 0ustar bjeannetpopart# README # # APRON Library / Parma Polyhedra Library # # Copyright (C) Antoine Mine' 2006-2009 # This file is part of the APRON Library, released under GPL license. # Please read the COPYING file packaged in the distribution This package is a wrapper for the the Parma Polyhedra Library. (http://www.cs.unipr.it/ppl/) Requirements: - APRON - ITV - PPL library version 0.9 or 0.10, with GMP support - GMPXX (normally installed with GMP) - for apron_ppl_test: NewPolka APRON module If HAS_PPL is defined in ../Makefile.config, then the main APRON Makefile will automatically build and install this module. 9/2/2009 changes - the wrapper has been updated to compile PPL version 0.10 - it should still compile with version 0.9 of PPL provided that you apply the provided patch 1. go to the directoy containing the ppl-0.9 directory 2. type 'patch -p0 C libary - make ml => OCaml library - make install => install C and (if compiled) OCaml libraries apron-dist-0.9.10/apron/ppl/ppl_grid.hh0000640014525101416610000003412310760562320017604 0ustar bjeannetpopart/* * ppl_grid.hh * * APRON Library / PPL library wrapper * * Wrappers specific to the Grid PPL classes. * * Copyright (C) Antoine Mine' 2006 * */ /* * This file is part of the APRON Library, released under GPL license. * Please read the COPYING file packaged in the distribution. */ #ifndef __PPL_GRID_HH #define __PPL_GRID_HH #include "ppl.hh" using namespace std; using namespace Parma_Polyhedra_Library; class PPL_Grid { public: Grid* p; size_t intdim; PPL_Grid(const PPL_Grid& x); PPL_Grid(size_t intdim, size_t realdim, Degenerate_Element kind); ~PPL_Grid(); /* enforce integer constraints */ void reduce(); void forget_dim(size_t dim); }; #ifdef __cplusplus extern "C" { #endif /* ============================================================ */ /* A. Constructor for APRON manager (to be freed with ap_manager_free). */ /* ============================================================ */ ap_manager_t* ap_ppl_grid_manager_alloc(); /* Allocate a PPL manager for grids. */ /* ********************************************************************** */ /* I. General management */ /* ********************************************************************** */ /* ============================================================ */ /* I.1 Memory */ /* ============================================================ */ PPL_Grid* ap_ppl_grid_copy(ap_manager_t* man, PPL_Grid* a); /* Return a copy of an abstract value, on which destructive update does not affect the initial value. */ void ap_ppl_grid_free(ap_manager_t* man, PPL_Grid* a); /* Free all the memory used by the abstract value */ size_t ap_ppl_grid_size(ap_manager_t* man, PPL_Grid* a); /* Return the abstract size of an abstract value, which is the number of coefficients of its current representation, possibly redundant. */ /* ============================================================ */ /* I.2 Control of internal representation */ /* ============================================================ */ void ap_ppl_grid_minimize(ap_manager_t* man, PPL_Grid* a); /* Same as ap_ppl_grid_canonicalize */ void ap_ppl_grid_canonicalize(ap_manager_t* man, PPL_Grid* a); /* Put the polyhedron with minimized constraints and frames. If in addition the integer man->option->canonicalize.algorithm is strictly positive, normalize equalities and lines, and also strict constraints */ int ap_ppl_grid_hash(ap_manager_t* man, PPL_Grid* a); void ap_ppl_grid_approximate(ap_manager_t* man, PPL_Grid* a, int algorithm); /* Do nothing */ /* ============================================================ */ /* I.3 Printing */ /* ============================================================ */ void ap_ppl_grid_fprint(FILE* stream, ap_manager_t* man, PPL_Grid* a, char** name_of_dim); /* Print the abstract value in a pretty way, using function name_of_dim to name dimensions */ void ap_ppl_grid_fprintdiff(FILE* stream, ap_manager_t* man, PPL_Grid* a1, PPL_Grid* a2, char** name_of_dim); /* Print the difference between a1 (old value) and a2 (new value), using function name_of_dim to name dimensions. The meaning of difference is library dependent. Not implemented */ void ap_ppl_grid_fdump(FILE* stream, ap_manager_t* man, PPL_Grid* a); /* Dump the internal representation of an abstract value, for debugging purposes */ /* ============================================================ */ /* I.4 Serialization */ /* ============================================================ */ ap_membuf_t ap_ppl_grid_serialize_raw(ap_manager_t* man, PPL_Grid* a); /* Allocate a memory buffer (with malloc), output the abstract value in raw binary format to it and return a pointer on the memory buffer and the size of bytes written. It is the user responsability to free the memory afterwards (with free). Not implemented */ PPL_Grid* ap_ppl_grid_deserialize_raw(ap_manager_t* man, void* ptr, size_t* size); /* Return the abstract value read in raw binary format from the input stream and store in size the number of bytes read. Not implemented */ /* ********************************************************************** */ /* II. Constructor, accessors, tests and property extraction */ /* ********************************************************************** */ /* ============================================================ */ /* II.1 Basic constructors */ /* ============================================================ */ /* We assume that dimensions [0..intdim-1] correspond to integer variables, and dimensions [intdim..intdim+realdim-1] to real variables */ PPL_Grid* ap_ppl_grid_bottom(ap_manager_t* man, size_t intdim, size_t realdim); /* Create a bottom (empty) value */ PPL_Grid* ap_ppl_grid_top(ap_manager_t* man, size_t intdim, size_t realdim); /* Create a top (universe) value */ PPL_Grid* ap_ppl_grid_of_box(ap_manager_t* man, size_t intdim, size_t realdim, ap_interval_t** tinterval); /* Abstract an hypercube defined by the array of intervals of size intdim+realdim */ PPL_Grid* ap_ppl_grid_of_lincons_array(ap_manager_t* man, size_t intdim, size_t realdim, ap_lincons0_array_t* array); /* Abstract a convex polyhedra defined by the array of linear constraints of size size */ PPL_Grid* ap_ppl_grid_of_tcons_array(ap_manager_t* man, size_t intdim, size_t realdim, ap_tcons0_array_t* array); /* Abstract a conjunction of tree expressions constraints of size size */ /* ============================================================ */ /* II.2 Accessors */ /* ============================================================ */ ap_dimension_t ap_ppl_grid_dimension(ap_manager_t* man, PPL_Grid* a); /* Return the total number of dimensions of the abstract values */ /* ============================================================ */ /* II.3 Tests */ /* ============================================================ */ bool ap_ppl_grid_is_bottom(ap_manager_t* man, PPL_Grid* a); /* Emptiness test */ bool ap_ppl_grid_is_top(ap_manager_t* man, PPL_Grid* a); /* Universe test */ bool ap_ppl_grid_is_leq(ap_manager_t* man, PPL_Grid* a1, PPL_Grid* a2); /* Inclusion test */ bool ap_ppl_grid_is_eq(ap_manager_t* man, PPL_Grid* a1, PPL_Grid* a2); /* Equality test */ bool ap_ppl_grid_sat_lincons(ap_manager_t* man, PPL_Grid* a, ap_lincons0_t* lincons); /* Satisfiability of a linear constraint */ bool ap_ppl_grid_sat_tcons(ap_manager_t* man, PPL_Grid* a, ap_tcons0_t* cons); /* Satisfiability of a tree expression constraint. */ bool ap_ppl_grid_sat_interval(ap_manager_t* man, PPL_Grid* a, ap_dim_t dim, ap_interval_t* interval); /* Inclusion of a dimension in an interval */ bool ap_ppl_grid_is_dimension_unconstrained(ap_manager_t* man, PPL_Grid* po, ap_dim_t dim); /* Is a dimension unconstrained ? */ /* ============================================================ */ /* II.4 Extraction of properties */ /* ============================================================ */ ap_interval_t* ap_ppl_grid_bound_linexpr(ap_manager_t* man, PPL_Grid* a, ap_linexpr0_t* expr); /* Returns the interval taken by a linear expression over the abstract value. */ ap_interval_t* ap_ppl_grid_bound_texpr(ap_manager_t* man, PPL_Grid* a, ap_texpr0_t* expr); /* Returns the interval taken by a tree expression over the abstract value. */ ap_interval_t* ap_ppl_grid_bound_dimension(ap_manager_t* man, PPL_Grid* a, ap_dim_t dim); /* Returns the interval taken by the dimension over the abstract value. */ ap_lincons0_array_t ap_ppl_grid_to_lincons_array(ap_manager_t* man, PPL_Grid* a); /* Converts an abstract value to a gridhedra (conjunction of linear constraints). */ ap_tcons0_array_t ap_ppl_grid_to_tcons_array(ap_manager_t* man, PPL_Grid* a); /* Converts an abstract value to a conjunction of tree expressions constraints. */ ap_interval_t** ap_ppl_grid_to_box(ap_manager_t* man, PPL_Grid* a); /* Converts an abstract value to an interval/hypercube. The size of the resulting array is ap_ppl_grid_dimension(man,a). */ ap_generator0_array_t ap_ppl_grid_to_generator_array(ap_manager_t* man, PPL_Grid* a); /* Converts an abstract value to a system of generators. */ /* ********************************************************************** */ /* III. Operations */ /* ********************************************************************** */ /* ============================================================ */ /* III.1 Meet and Join */ /* ============================================================ */ PPL_Grid* ap_ppl_grid_meet(ap_manager_t* man, bool destructive, PPL_Grid* a1, PPL_Grid* a2); PPL_Grid* ap_ppl_grid_join(ap_manager_t* man, bool destructive, PPL_Grid* a1, PPL_Grid* a2); /* Meet and Join of 2 abstract values */ PPL_Grid* ap_ppl_grid_meet_array(ap_manager_t* man, PPL_Grid** tab, size_t size); PPL_Grid* ap_ppl_grid_join_array(ap_manager_t* man, PPL_Grid** tab, size_t size); /* Meet and Join of a non-empty array of abstract values. (no way to define the dimensionality of the result in such a case */ PPL_Grid* ap_ppl_grid_meet_lincons_array(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_lincons0_array_t* array); /* Meet of an abstract value with a set of constraints (generalize ap_ppl_grid_of_lincons_array) */ PPL_Grid* ap_ppl_grid_meet_tcons_array(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_tcons0_array_t* array); /* Meet of an abstract value with a set of tree expressionsconstraints. */ PPL_Grid* ap_ppl_grid_add_ray_array(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_generator0_array_t* array); /* Generalized time elapse operator */ /* ============================================================ */ /* III.2 Assignement and Substitutions */ /* ============================================================ */ PPL_Grid* ap_ppl_grid_assign_linexpr(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dim_t dim, ap_linexpr0_t* expr, PPL_Grid* dest); PPL_Grid* ap_ppl_grid_substitute_linexpr(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dim_t dim, ap_linexpr0_t* expr, PPL_Grid* dest); /* Assignement and Substitution of a single dimension by resp. a linear expression and a interval linear expression */ PPL_Grid* ap_ppl_grid_assign_linexpr_array(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, PPL_Grid* dest); PPL_Grid* ap_ppl_grid_substitute_linexpr_array(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, PPL_Grid* dest); /* Parallel Assignement and Substitution of several dimensions by linear expressons. */ PPL_Grid* ap_ppl_grid_assign_texpr(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dim_t dim, ap_texpr0_t* expr, PPL_Grid* dest); PPL_Grid* ap_ppl_grid_substitute_texpr(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dim_t dim, ap_texpr0_t* expr, PPL_Grid* dest); /* Assignement and Substitution of a single dimension by a tree expression */ PPL_Grid* ap_ppl_grid_assign_texpr_array(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, PPL_Grid* dest); PPL_Grid* ap_ppl_grid_substitute_texpr_array(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, PPL_Grid* dest); /* Parallel Assignement and Substitution of several dimensions by tree expressions. */ /* ============================================================ */ /* III.3 Projections */ /* ============================================================ */ PPL_Grid* ap_ppl_grid_forget_array(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dim_t* tdim, size_t size, bool project); /* ============================================================ */ /* III.4 Change and permutation of dimensions */ /* ============================================================ */ PPL_Grid* ap_ppl_grid_add_dimensions(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dimchange_t* dimchange, bool project); PPL_Grid* ap_ppl_grid_remove_dimensions(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dimchange_t* dimchange); PPL_Grid* ap_ppl_grid_permute_dimensions(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dimperm_t* permutation); /* ============================================================ */ /* III.5 Expansion and folding of dimensions */ /* ============================================================ */ PPL_Grid* ap_ppl_grid_expand(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dim_t dim, size_t n); /* Expand the dimension dim into itself + n additional dimensions. It results in (n+1) unrelated dimensions having same relations with other dimensions. The (n+1) dimensions are put as follows: - original dimension dim - if the dimension is integer, the n additional dimensions are put at the end of integer dimensions; if it is real, at the end of the real dimensions. */ PPL_Grid* ap_ppl_grid_fold(ap_manager_t* man, bool destructive, PPL_Grid* a, ap_dim_t* tdim, size_t size); /* Fold the dimensions in the array tdim of size n>=1 and put the result in the first dimension in the array. The other dimensions of the array are then removed (using ap_ppl_grid_permute_remove_dimensions). */ /* ============================================================ */ /* III.6 Widening */ /* ============================================================ */ /* Widening */ PPL_Grid* ap_ppl_grid_widening(ap_manager_t* man, PPL_Grid* a1, PPL_Grid* a2); /* ============================================================ */ /* III.7 Closure operation */ /* ============================================================ */ /* Returns the topological closure of a possibly opened abstract value */ PPL_Grid* ap_ppl_grid_closure(ap_manager_t* man, bool destructive, PPL_Grid* a); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/ppl/tmp/0000750014525101416610000000000011252216517016260 5ustar bjeannetpopartapron-dist-0.9.10/apron/ppl/tmp/ppl.ml0000640014525101416610000001515311252216517017413 0ustar bjeannetpopart(* File generated from ppl.idl *) (* This file is part of the APRON Library, released under GPL license. Please read the COPYING file packaged in the distribution. *) (** Convex Polyhedra and Linear Congruences abstract domains (PPL wrapper) *) (** This module is a wrapper around the Parma Polyhedra Library. *) type loose type strict (** Two flavors for convex polyhedra: loose or strict. Loose polyhedra cannot have strict inequality constraints like [x>0]. They are algorithmically more efficient (less generators, simpler normalization). Convex polyhedra are defined by the conjunction of a set of linear constraints of the form [a_0*x_0 + ... + a_n*x_n + b >= 0] or [a_0*x_0 + ... + a_n*x_n + b > 0] where [a_0, ..., a_n, b, c] are constants and [x_0, ..., x_n] variables. *) type grid (** Linear congruences. Linear congruences are defined by the conjunction of equality constraints modulo a rational number, of the form [a_0*x_0 + ... + a_n*x_n = b mod c], where [a_0, ..., a_n, b, c] are constants and [x_0, ..., x_n] variables. *) type 'a t (** Type of convex polyhedra/linear congruences, where ['a] is [loose], [strict] or [grid]. Abstract values which are convex polyhedra have the type [loose t Apron.AbstractX.t] or [strict t Apron.AbstractX.t]. Abstract values which are conjunction of linear congruences equalities have the type [grid t Apron.AbstractX.t]. Managers allocated by PPL have the type ['a t Apron.Manager.t]. *) external ap_ppl_manager_alloc_loose : unit -> Manager.ap_manager_ptr = "camlidl_ppl_ap_ppl_manager_alloc_loose" external ap_ppl_manager_alloc_strict : unit -> Manager.ap_manager_ptr = "camlidl_ppl_ap_ppl_manager_alloc_strict" external ap_ppl_manager_alloc_grid : unit -> Manager.ap_manager_ptr = "camlidl_ppl_ap_ppl_manager_alloc_grid" let manager_is_ppl man = let str = Apron.Manager.get_library man in let str = try String.sub str 0 3 with Invalid_argument _ -> "" in (String.compare str "PPL")==0 let manager_of_ppl (man:'a t Apron.Manager.t) : 'b Apron.Manager.t = Obj.magic man let manager_to_ppl (man:'a Apron.Manager.t) : 'b t Apron.Manager.t = if manager_is_ppl man then Obj.magic man else failwith "Ppl.to_ppl: the argument manager is not a Ppl manager" let manager_is_ppl_loose man = let str = Apron.Manager.get_library man in (String.compare str "PPL::Polyhedron, loose mode")==0 let manager_of_ppl_loose (man:loose t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_ppl_loose (man:'a Apron.Manager.t) : loose t Apron.Manager.t = if manager_is_ppl_loose man then Obj.magic man else failwith "Ppl.to_ppl_loose: the argument manager is not a loose Ppl manager" let manager_is_ppl_strict man = let str = Apron.Manager.get_library man in (String.compare str "PPL::Polyhedron, strict mode")==0 let manager_of_ppl_strict (man:strict t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_ppl_strict (man:'a Apron.Manager.t) : strict t Apron.Manager.t = if manager_is_ppl_strict man then Obj.magic man else failwith "Ppl.to_ppl_strict: the argument manager is not a strict Ppl manager" let manager_is_ppl_grid man = let str = Apron.Manager.get_library man in (String.compare str "PPL::Grid")==0 let manager_of_ppl_grid (man:grid t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_ppl_grid (man:'a Apron.Manager.t) : grid t Apron.Manager.t = if manager_is_ppl_grid man then Obj.magic man else failwith "Ppl.to_ppl_grid: the argument manager is not a grid Ppl manager" module Abstract0 = struct let is_ppl abs = manager_is_ppl (Apron.Abstract0.manager abs) let is_ppl_loose abs = manager_is_ppl_loose (Apron.Abstract0.manager abs) let is_ppl_strict abs = manager_is_ppl (Apron.Abstract0.manager abs) let is_ppl_grid abs = manager_is_ppl_grid (Apron.Abstract0.manager abs) let of_ppl (abs: 'a t Apron.Abstract0.t) : 'b Apron.Abstract0.t = Obj.magic abs let of_ppl_loose (abs: loose t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let of_ppl_strict (abs: strict t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let of_ppl_grid (abs: grid t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let to_ppl (abs:'a Apron.Abstract0.t) : 'b t Apron.Abstract0.t = if is_ppl abs then Obj.magic abs else failwith "Ppl.Abstract0.to_ppl: the argument value is not a ppl value" let to_ppl_loose (abs:'a Apron.Abstract0.t) : loose t Apron.Abstract0.t = if is_ppl_loose abs then Obj.magic abs else failwith "Ppl.Abstract0.to_ppl_loose: the argument value is not a loose ppl value" let to_ppl_strict (abs:'a Apron.Abstract0.t) : strict t Apron.Abstract0.t = if is_ppl_strict abs then Obj.magic abs else failwith "Ppl.Abstract0.to_ppl_strict: the argument value is not a strict ppl value" let to_ppl_grid (abs:'a Apron.Abstract0.t) : grid t Apron.Abstract0.t = if is_ppl_grid abs then Obj.magic abs else failwith "Ppl.Abstract0.to_ppl_grid: the argument value is not a grid ppl value" end module Abstract1 = struct let is_ppl abs = manager_is_ppl (Apron.Abstract1.manager abs) let is_ppl_loose abs = manager_is_ppl_loose (Apron.Abstract1.manager abs) let is_ppl_strict abs = manager_is_ppl (Apron.Abstract1.manager abs) let is_ppl_grid abs = manager_is_ppl_grid (Apron.Abstract1.manager abs) let of_ppl (abs: 'a t Apron.Abstract1.t) : 'b Apron.Abstract1.t = Obj.magic abs let of_ppl_loose (abs: loose t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let of_ppl_strict (abs: strict t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let of_ppl_grid (abs: grid t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let to_ppl (abs:'a Apron.Abstract1.t) : 'b t Apron.Abstract1.t = if is_ppl abs then Obj.magic abs else failwith "Ppl.Abstract1.to_ppl: the argument value is not a ppl value" let to_ppl_loose (abs:'a Apron.Abstract1.t) : loose t Apron.Abstract1.t = if is_ppl_loose abs then Obj.magic abs else failwith "Ppl.Abstract1.to_ppl_loose: the argument value is not a loose ppl value" let to_ppl_strict (abs:'a Apron.Abstract1.t) : strict t Apron.Abstract1.t = if is_ppl_strict abs then Obj.magic abs else failwith "Ppl.Abstract1.to_ppl_strict: the argument value is not a strict ppl value" let to_ppl_grid (abs:'a Apron.Abstract1.t) : grid t Apron.Abstract1.t = if is_ppl_grid abs then Obj.magic abs else failwith "Ppl.Abstract1.to_ppl_grid: the argument value is not a grid ppl value" end apron-dist-0.9.10/apron/ppl/tmp/ppl.mli0000640014525101416610000001441011252216517017557 0ustar bjeannetpopart(* File generated from ppl.idl *) (* This file is part of the APRON Library, released under GPL license. Please read the COPYING file packaged in the distribution. *) (** Convex Polyhedra and Linear Congruences abstract domains (PPL wrapper) *) (** This module is a wrapper around the Parma Polyhedra Library. *) type loose type strict (** Two flavors for convex polyhedra: loose or strict. Loose polyhedra cannot have strict inequality constraints like [x>0]. They are algorithmically more efficient (less generators, simpler normalization). Convex polyhedra are defined by the conjunction of a set of linear constraints of the form [a_0*x_0 + ... + a_n*x_n + b >= 0] or [a_0*x_0 + ... + a_n*x_n + b > 0] where [a_0, ..., a_n, b, c] are constants and [x_0, ..., x_n] variables. *) type grid (** Linear congruences. Linear congruences are defined by the conjunction of equality constraints modulo a rational number, of the form [a_0*x_0 + ... + a_n*x_n = b mod c], where [a_0, ..., a_n, b, c] are constants and [x_0, ..., x_n] variables. *) type 'a t (** Type of convex polyhedra/linear congruences, where ['a] is [loose], [strict] or [grid]. Abstract values which are convex polyhedra have the type [loose t Apron.AbstractX.t] or [strict t Apron.AbstractX.t]. Abstract values which are conjunction of linear congruences equalities have the type [grid t Apron.AbstractX.t]. Managers allocated by PPL have the type ['a t Apron.Manager.t]. *) (** Allocate a PPL manager for loose convex polyhedra. *) external ap_ppl_manager_alloc_loose : unit -> Manager.ap_manager_ptr = "camlidl_ppl_ap_ppl_manager_alloc_loose" (** Allocate a PPL manager for strict convex polyhedra. *) external ap_ppl_manager_alloc_strict : unit -> Manager.ap_manager_ptr = "camlidl_ppl_ap_ppl_manager_alloc_strict" (** Allocate a new manager for linear congruences (grids) *) external ap_ppl_manager_alloc_grid : unit -> Manager.ap_manager_ptr = "camlidl_ppl_ap_ppl_manager_alloc_grid" (** {2 Type conversions} *) val manager_is_ppl : 'a Apron.Manager.t -> bool val manager_is_ppl_loose : 'a Apron.Manager.t -> bool val manager_is_ppl_strict : 'a Apron.Manager.t -> bool val manager_is_ppl_grid : 'a Apron.Manager.t -> bool (** Return [true] iff the argument manager is a ppl manager *) val manager_of_ppl : 'a t Apron.Manager.t -> 'b Apron.Manager.t val manager_of_ppl_loose : loose t Apron.Manager.t -> 'a Apron.Manager.t val manager_of_ppl_strict : strict t Apron.Manager.t -> 'a Apron.Manager.t val manager_of_ppl_grid : grid t Apron.Manager.t -> 'a Apron.Manager.t (** Make a ppl manager generic *) val manager_to_ppl : 'a Apron.Manager.t -> 'b t Apron.Manager.t val manager_to_ppl_loose : 'a Apron.Manager.t -> loose t Apron.Manager.t val manager_to_ppl_strict : 'a Apron.Manager.t -> strict t Apron.Manager.t val manager_to_ppl_grid : 'a Apron.Manager.t -> grid t Apron.Manager.t (** Instanciate the type of a ppl manager. Raises [Failure] if the argument manager is not a ppl manager *) module Abstract0 : sig val is_ppl : 'a Apron.Abstract0.t -> bool val is_ppl_loose : 'a Apron.Abstract0.t -> bool val is_ppl_strict : 'a Apron.Abstract0.t -> bool val is_ppl_grid : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument manager is a ppl value *) val of_ppl : 'a t Apron.Abstract0.t -> 'b Apron.Abstract0.t val of_ppl_loose : loose t Apron.Abstract0.t -> 'a Apron.Abstract0.t val of_ppl_strict : strict t Apron.Abstract0.t -> 'a Apron.Abstract0.t val of_ppl_grid : grid t Apron.Abstract0.t -> 'a Apron.Abstract0.t (** Make a ppl value generic *) val to_ppl : 'a Apron.Abstract0.t -> 'b t Apron.Abstract0.t val to_ppl_loose : 'a Apron.Abstract0.t -> loose t Apron.Abstract0.t val to_ppl_strict : 'a Apron.Abstract0.t -> strict t Apron.Abstract0.t val to_ppl_grid : 'a Apron.Abstract0.t -> grid t Apron.Abstract0.t (** Instanciate the type of a ppl value. Raises [Failure] if the argument manager is not a ppl manager *) end module Abstract1 : sig val is_ppl : 'a Apron.Abstract1.t -> bool val is_ppl_loose : 'a Apron.Abstract1.t -> bool val is_ppl_strict : 'a Apron.Abstract1.t -> bool val is_ppl_grid : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument manager is a ppl value *) val of_ppl : 'a t Apron.Abstract1.t -> 'b Apron.Abstract1.t val of_ppl_loose : loose t Apron.Abstract1.t -> 'a Apron.Abstract1.t val of_ppl_strict : strict t Apron.Abstract1.t -> 'a Apron.Abstract1.t val of_ppl_grid : grid t Apron.Abstract1.t -> 'a Apron.Abstract1.t (** Make a ppl value generic *) val to_ppl : 'a Apron.Abstract1.t -> 'b t Apron.Abstract1.t val to_ppl_loose : 'a Apron.Abstract1.t -> loose t Apron.Abstract1.t val to_ppl_strict : 'a Apron.Abstract1.t -> strict t Apron.Abstract1.t val to_ppl_grid : 'a Apron.Abstract1.t -> grid t Apron.Abstract1.t (** Instanciate the type of a ppl value. Raises [Failure] if the argument manager is not a ppl manager *) end (** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. Do not forget the [-cc "g++"] option: PPL is a C++ library which requires a C++ linker. {3 Bytecode compilation} {[ocamlc -cc "g++"-I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \ bigarray.cma gmp.cma apron.cma ppl.cma mlexample.ml]} {[ocamlc -cc "g++" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \ bigarray.cma gmp.cma apron.cma ppl.cma ocamlc -cc "g++" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \ bigarray.cma gmp.cma apron.cma ppl.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -cc "g++" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa ppl.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -cc "g++" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa ppl.cmxa mlexample.ml \ -cclib "-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib -L$PPL_PREFIX/lib\ -lap_ppl_caml_debug -lap_ppl_debug -lppl -lgmpxx \ -lapron_caml_debug -lapron_debug \ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP_PREFIX/lib -lgmp \ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \ -lbigarray" ]} *) apron-dist-0.9.10/apron/ppl/tmp/ppl_stubs.c0000640014525101416610000000625011252216517020443 0ustar bjeannetpopart/* File generated from ppl.idl */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include /* This file is part of the APRON Library, released under GPL license. Please read the COPYING file packaged in the distribution. */ #include "ap_ppl.h" #include "apron_caml.h" #define I0_CHECK_EXC(man) if (man->result.exn!=AP_EXC_NONE){ value v = camlidl_c2ml_manager_struct_ap_exclog_t(man->result.exclog,_ctx); caml_raise_with_arg(*caml_named_value("apron exception"),v); } extern void camlidl_apron_manager_funid_ml2c(value, ap_funid_t *); #define camlidl_ml2c_manager_ap_funid_t(v,c,ctx) camlidl_apron_manager_funid_ml2c(v,c) extern value camlidl_apron_manager_funid_c2ml(ap_funid_t *); #define camlidl_c2ml_manager_ap_funid_t(c,ctx) camlidl_apron_manager_funid_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_funopt_t(value, struct ap_funopt_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_funopt_t(struct ap_funopt_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_exc_ml2c(value, ap_exc_t *); #define camlidl_ml2c_manager_ap_exc_t(v,c,ctx) camlidl_apron_manager_exc_ml2c(v,c) extern value camlidl_apron_manager_exc_c2ml(ap_exc_t *); #define camlidl_c2ml_manager_ap_exc_t(c,ctx) camlidl_apron_manager_exc_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_exclog_t(value, struct ap_exclog_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_exclog_t(struct ap_exclog_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_ptr_ml2c(value, ap_manager_ptr *); #define camlidl_ml2c_manager_ap_manager_ptr(v,c,ctx) camlidl_apron_manager_ptr_ml2c(v,c) extern value camlidl_apron_manager_ptr_c2ml(ap_manager_ptr *); #define camlidl_c2ml_manager_ap_manager_ptr(c,ctx) camlidl_apron_manager_ptr_c2ml(c) value camlidl_ppl_ap_ppl_manager_alloc_loose(value _unit) { ap_manager_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; /* begin user-supplied calling sequence */ _res = ap_ppl_poly_manager_alloc(false); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_manager_ap_manager_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_ppl_ap_ppl_manager_alloc_strict(value _unit) { ap_manager_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; /* begin user-supplied calling sequence */ _res = ap_ppl_poly_manager_alloc(true); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_manager_ap_manager_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_ppl_ap_ppl_manager_alloc_grid(value _unit) { ap_manager_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; /* begin user-supplied calling sequence */ _res = ap_ppl_grid_manager_alloc(); /* end user-supplied calling sequence */ _vres = camlidl_c2ml_manager_ap_manager_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } apron-dist-0.9.10/apron/ppl/tmp/ppl.idl0000640014525101416610000002763011252216517017556 0ustar bjeannetpopart/* -*- mode: c -*- */ /* * ppl.idl * * OCaml interface specification for camlidl * * APRON Library / PPL library wrapper * * Copyright (C) Antoine Mine' 2006 * */ /* This file is part of the APRON Library, released under GPL license. Please read the COPYING file packaged in the distribution. */ quote(C,"/*\n This file is part of the APRON Library, released under GPL license.\n Please read the COPYING file packaged in the distribution.\n*/") quote(MLMLI,"(*\n This file is part of the APRON Library, released under GPL license.\n Please read the COPYING file packaged in the distribution.\n*)\n") quote(C,"#include \"ap_ppl.h\"") quote(C,"#include \"apron_caml.h\"") quote(C,"#define I0_CHECK_EXC(man) if (man->result.exn!=AP_EXC_NONE){ value v = camlidl_c2ml_manager_struct_ap_exclog_t(man->result.exclog,_ctx); caml_raise_with_arg(*caml_named_value(\"apron exception\"),v); } ") import "manager.idl"; quote(MLMLI,"(** Convex Polyhedra and Linear Congruences abstract domains (PPL wrapper) *)\n") quote(MLMLI,"(** This module is a wrapper around the Parma Polyhedra Library. *)\n\n") quote(MLMLI," type loose type strict (** Two flavors for convex polyhedra: loose or strict. Loose polyhedra cannot have strict inequality constraints like [x>0]. They are algorithmically more efficient (less generators, simpler normalization). Convex polyhedra are defined by the conjunction of a set of linear constraints of the form [a_0*x_0 + ... + a_n*x_n + b >= 0] or [a_0*x_0 + ... + a_n*x_n + b > 0] where [a_0, ..., a_n, b, c] are constants and [x_0, ..., x_n] variables. *) type grid (** Linear congruences. Linear congruences are defined by the conjunction of equality constraints modulo a rational number, of the form [a_0*x_0 + ... + a_n*x_n = b mod c], where [a_0, ..., a_n, b, c] are constants and [x_0, ..., x_n] variables. *) type 'a t (** Type of convex polyhedra/linear congruences, where ['a] is [loose], [strict] or [grid]. Abstract values which are convex polyhedra have the type [loose t Apron.AbstractX.t] or [strict t Apron.AbstractX.t]. Abstract values which are conjunction of linear congruences equalities have the type [grid t Apron.AbstractX.t]. Managers allocated by PPL have the type ['a t Apron.Manager.t]. *) ") quote(MLI,"(** Allocate a PPL manager for loose convex polyhedra. *)") ap_manager_ptr ap_ppl_manager_alloc_loose() quote(call,"_res = ap_ppl_poly_manager_alloc(false);"); quote(MLI,"(** Allocate a PPL manager for strict convex polyhedra. *)") ap_manager_ptr ap_ppl_manager_alloc_strict() quote(call,"_res = ap_ppl_poly_manager_alloc(true);"); quote(MLI,"(** Allocate a new manager for linear congruences (grids) *)") ap_manager_ptr ap_ppl_manager_alloc_grid() quote(call,"_res = ap_ppl_grid_manager_alloc();"); quote(MLI,"(** {2 Type conversions} *) val manager_is_ppl : 'a Apron.Manager.t -> bool val manager_is_ppl_loose : 'a Apron.Manager.t -> bool val manager_is_ppl_strict : 'a Apron.Manager.t -> bool val manager_is_ppl_grid : 'a Apron.Manager.t -> bool (** Return [true] iff the argument manager is a ppl manager *) val manager_of_ppl : 'a t Apron.Manager.t -> 'b Apron.Manager.t val manager_of_ppl_loose : loose t Apron.Manager.t -> 'a Apron.Manager.t val manager_of_ppl_strict : strict t Apron.Manager.t -> 'a Apron.Manager.t val manager_of_ppl_grid : grid t Apron.Manager.t -> 'a Apron.Manager.t (** Make a ppl manager generic *) val manager_to_ppl : 'a Apron.Manager.t -> 'b t Apron.Manager.t val manager_to_ppl_loose : 'a Apron.Manager.t -> loose t Apron.Manager.t val manager_to_ppl_strict : 'a Apron.Manager.t -> strict t Apron.Manager.t val manager_to_ppl_grid : 'a Apron.Manager.t -> grid t Apron.Manager.t (** Instanciate the type of a ppl manager. Raises [Failure] if the argument manager is not a ppl manager *) module Abstract0 : sig val is_ppl : 'a Apron.Abstract0.t -> bool val is_ppl_loose : 'a Apron.Abstract0.t -> bool val is_ppl_strict : 'a Apron.Abstract0.t -> bool val is_ppl_grid : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument manager is a ppl value *) val of_ppl : 'a t Apron.Abstract0.t -> 'b Apron.Abstract0.t val of_ppl_loose : loose t Apron.Abstract0.t -> 'a Apron.Abstract0.t val of_ppl_strict : strict t Apron.Abstract0.t -> 'a Apron.Abstract0.t val of_ppl_grid : grid t Apron.Abstract0.t -> 'a Apron.Abstract0.t (** Make a ppl value generic *) val to_ppl : 'a Apron.Abstract0.t -> 'b t Apron.Abstract0.t val to_ppl_loose : 'a Apron.Abstract0.t -> loose t Apron.Abstract0.t val to_ppl_strict : 'a Apron.Abstract0.t -> strict t Apron.Abstract0.t val to_ppl_grid : 'a Apron.Abstract0.t -> grid t Apron.Abstract0.t (** Instanciate the type of a ppl value. Raises [Failure] if the argument manager is not a ppl manager *) end module Abstract1 : sig val is_ppl : 'a Apron.Abstract1.t -> bool val is_ppl_loose : 'a Apron.Abstract1.t -> bool val is_ppl_strict : 'a Apron.Abstract1.t -> bool val is_ppl_grid : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument manager is a ppl value *) val of_ppl : 'a t Apron.Abstract1.t -> 'b Apron.Abstract1.t val of_ppl_loose : loose t Apron.Abstract1.t -> 'a Apron.Abstract1.t val of_ppl_strict : strict t Apron.Abstract1.t -> 'a Apron.Abstract1.t val of_ppl_grid : grid t Apron.Abstract1.t -> 'a Apron.Abstract1.t (** Make a ppl value generic *) val to_ppl : 'a Apron.Abstract1.t -> 'b t Apron.Abstract1.t val to_ppl_loose : 'a Apron.Abstract1.t -> loose t Apron.Abstract1.t val to_ppl_strict : 'a Apron.Abstract1.t -> strict t Apron.Abstract1.t val to_ppl_grid : 'a Apron.Abstract1.t -> grid t Apron.Abstract1.t (** Instanciate the type of a ppl value. Raises [Failure] if the argument manager is not a ppl manager *) end ") quote(ML," let manager_is_ppl man = let str = Apron.Manager.get_library man in let str = try String.sub str 0 3 with Invalid_argument _ -> \"\" in (String.compare str \"PPL\")==0 let manager_of_ppl (man:'a t Apron.Manager.t) : 'b Apron.Manager.t = Obj.magic man let manager_to_ppl (man:'a Apron.Manager.t) : 'b t Apron.Manager.t = if manager_is_ppl man then Obj.magic man else failwith \"Ppl.to_ppl: the argument manager is not a Ppl manager\" let manager_is_ppl_loose man = let str = Apron.Manager.get_library man in (String.compare str \"PPL::Polyhedron, loose mode\")==0 let manager_of_ppl_loose (man:loose t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_ppl_loose (man:'a Apron.Manager.t) : loose t Apron.Manager.t = if manager_is_ppl_loose man then Obj.magic man else failwith \"Ppl.to_ppl_loose: the argument manager is not a loose Ppl manager\" let manager_is_ppl_strict man = let str = Apron.Manager.get_library man in (String.compare str \"PPL::Polyhedron, strict mode\")==0 let manager_of_ppl_strict (man:strict t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_ppl_strict (man:'a Apron.Manager.t) : strict t Apron.Manager.t = if manager_is_ppl_strict man then Obj.magic man else failwith \"Ppl.to_ppl_strict: the argument manager is not a strict Ppl manager\" let manager_is_ppl_grid man = let str = Apron.Manager.get_library man in (String.compare str \"PPL::Grid\")==0 let manager_of_ppl_grid (man:grid t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_ppl_grid (man:'a Apron.Manager.t) : grid t Apron.Manager.t = if manager_is_ppl_grid man then Obj.magic man else failwith \"Ppl.to_ppl_grid: the argument manager is not a grid Ppl manager\" module Abstract0 = struct let is_ppl abs = manager_is_ppl (Apron.Abstract0.manager abs) let is_ppl_loose abs = manager_is_ppl_loose (Apron.Abstract0.manager abs) let is_ppl_strict abs = manager_is_ppl (Apron.Abstract0.manager abs) let is_ppl_grid abs = manager_is_ppl_grid (Apron.Abstract0.manager abs) let of_ppl (abs: 'a t Apron.Abstract0.t) : 'b Apron.Abstract0.t = Obj.magic abs let of_ppl_loose (abs: loose t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let of_ppl_strict (abs: strict t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let of_ppl_grid (abs: grid t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let to_ppl (abs:'a Apron.Abstract0.t) : 'b t Apron.Abstract0.t = if is_ppl abs then Obj.magic abs else failwith \"Ppl.Abstract0.to_ppl: the argument value is not a ppl value\" let to_ppl_loose (abs:'a Apron.Abstract0.t) : loose t Apron.Abstract0.t = if is_ppl_loose abs then Obj.magic abs else failwith \"Ppl.Abstract0.to_ppl_loose: the argument value is not a loose ppl value\" let to_ppl_strict (abs:'a Apron.Abstract0.t) : strict t Apron.Abstract0.t = if is_ppl_strict abs then Obj.magic abs else failwith \"Ppl.Abstract0.to_ppl_strict: the argument value is not a strict ppl value\" let to_ppl_grid (abs:'a Apron.Abstract0.t) : grid t Apron.Abstract0.t = if is_ppl_grid abs then Obj.magic abs else failwith \"Ppl.Abstract0.to_ppl_grid: the argument value is not a grid ppl value\" end module Abstract1 = struct let is_ppl abs = manager_is_ppl (Apron.Abstract1.manager abs) let is_ppl_loose abs = manager_is_ppl_loose (Apron.Abstract1.manager abs) let is_ppl_strict abs = manager_is_ppl (Apron.Abstract1.manager abs) let is_ppl_grid abs = manager_is_ppl_grid (Apron.Abstract1.manager abs) let of_ppl (abs: 'a t Apron.Abstract1.t) : 'b Apron.Abstract1.t = Obj.magic abs let of_ppl_loose (abs: loose t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let of_ppl_strict (abs: strict t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let of_ppl_grid (abs: grid t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let to_ppl (abs:'a Apron.Abstract1.t) : 'b t Apron.Abstract1.t = if is_ppl abs then Obj.magic abs else failwith \"Ppl.Abstract1.to_ppl: the argument value is not a ppl value\" let to_ppl_loose (abs:'a Apron.Abstract1.t) : loose t Apron.Abstract1.t = if is_ppl_loose abs then Obj.magic abs else failwith \"Ppl.Abstract1.to_ppl_loose: the argument value is not a loose ppl value\" let to_ppl_strict (abs:'a Apron.Abstract1.t) : strict t Apron.Abstract1.t = if is_ppl_strict abs then Obj.magic abs else failwith \"Ppl.Abstract1.to_ppl_strict: the argument value is not a strict ppl value\" let to_ppl_grid (abs:'a Apron.Abstract1.t) : grid t Apron.Abstract1.t = if is_ppl_grid abs then Obj.magic abs else failwith \"Ppl.Abstract1.to_ppl_grid: the argument value is not a grid ppl value\" end ") quote(MLI,"\n(** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. Do not forget the [-cc \"g++\"] option: PPL is a C++ library which requires a C++ linker. {3 Bytecode compilation} {[ocamlc -cc \"g++\"-I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma ppl.cma mlexample.ml]} {[ocamlc -cc \"g++\" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \\ bigarray.cma gmp.cma apron.cma ppl.cma ocamlc -cc \"g++\" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma ppl.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -cc \"g++\" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa ppl.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -cc \"g++\" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa ppl.cmxa mlexample.ml \\ -cclib \"-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib -L$PPL_PREFIX/lib\\ -lap_ppl_caml_debug -lap_ppl_debug -lppl -lgmpxx \\ -lapron_caml_debug -lapron_debug \\ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP_PREFIX/lib -lgmp \\ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \\ -lbigarray\" ]} *)") apron-dist-0.9.10/apron/ppl/sedscript_caml0000640014525101416610000000072410620623461020401 0ustar bjeannetpoparts/Manager.ap_manager_ptr/'a t Apron.Manager.t/g; s/external ap_ppl_/external /g; s/external manager_alloc_loose : unit -> 'a t Apron.Manager.t/external manager_alloc_loose : unit -> loose t Apron.Manager.t/g; s/external manager_alloc_strict : unit -> 'a t Apron.Manager.t/external manager_alloc_strict : unit -> strict t Apron.Manager.t/g; s/external manager_alloc_grid : unit -> 'a t Apron.Manager.t/external manager_alloc_grid : unit -> grid t Apron.Manager.t/g; apron-dist-0.9.10/apron/ppl/ppl.idl0000640014525101416610000002763011251674650016763 0ustar bjeannetpopart/* -*- mode: c -*- */ /* * ppl.idl * * OCaml interface specification for camlidl * * APRON Library / PPL library wrapper * * Copyright (C) Antoine Mine' 2006 * */ /* This file is part of the APRON Library, released under GPL license. Please read the COPYING file packaged in the distribution. */ quote(C,"/*\n This file is part of the APRON Library, released under GPL license.\n Please read the COPYING file packaged in the distribution.\n*/") quote(MLMLI,"(*\n This file is part of the APRON Library, released under GPL license.\n Please read the COPYING file packaged in the distribution.\n*)\n") quote(C,"#include \"ap_ppl.h\"") quote(C,"#include \"apron_caml.h\"") quote(C,"#define I0_CHECK_EXC(man) if (man->result.exn!=AP_EXC_NONE){ value v = camlidl_c2ml_manager_struct_ap_exclog_t(man->result.exclog,_ctx); caml_raise_with_arg(*caml_named_value(\"apron exception\"),v); } ") import "manager.idl"; quote(MLMLI,"(** Convex Polyhedra and Linear Congruences abstract domains (PPL wrapper) *)\n") quote(MLMLI,"(** This module is a wrapper around the Parma Polyhedra Library. *)\n\n") quote(MLMLI," type loose type strict (** Two flavors for convex polyhedra: loose or strict. Loose polyhedra cannot have strict inequality constraints like [x>0]. They are algorithmically more efficient (less generators, simpler normalization). Convex polyhedra are defined by the conjunction of a set of linear constraints of the form [a_0*x_0 + ... + a_n*x_n + b >= 0] or [a_0*x_0 + ... + a_n*x_n + b > 0] where [a_0, ..., a_n, b, c] are constants and [x_0, ..., x_n] variables. *) type grid (** Linear congruences. Linear congruences are defined by the conjunction of equality constraints modulo a rational number, of the form [a_0*x_0 + ... + a_n*x_n = b mod c], where [a_0, ..., a_n, b, c] are constants and [x_0, ..., x_n] variables. *) type 'a t (** Type of convex polyhedra/linear congruences, where ['a] is [loose], [strict] or [grid]. Abstract values which are convex polyhedra have the type [loose t Apron.AbstractX.t] or [strict t Apron.AbstractX.t]. Abstract values which are conjunction of linear congruences equalities have the type [grid t Apron.AbstractX.t]. Managers allocated by PPL have the type ['a t Apron.Manager.t]. *) ") quote(MLI,"(** Allocate a PPL manager for loose convex polyhedra. *)") ap_manager_ptr ap_ppl_manager_alloc_loose() quote(call,"_res = ap_ppl_poly_manager_alloc(false);"); quote(MLI,"(** Allocate a PPL manager for strict convex polyhedra. *)") ap_manager_ptr ap_ppl_manager_alloc_strict() quote(call,"_res = ap_ppl_poly_manager_alloc(true);"); quote(MLI,"(** Allocate a new manager for linear congruences (grids) *)") ap_manager_ptr ap_ppl_manager_alloc_grid() quote(call,"_res = ap_ppl_grid_manager_alloc();"); quote(MLI,"(** {2 Type conversions} *) val manager_is_ppl : 'a Apron.Manager.t -> bool val manager_is_ppl_loose : 'a Apron.Manager.t -> bool val manager_is_ppl_strict : 'a Apron.Manager.t -> bool val manager_is_ppl_grid : 'a Apron.Manager.t -> bool (** Return [true] iff the argument manager is a ppl manager *) val manager_of_ppl : 'a t Apron.Manager.t -> 'b Apron.Manager.t val manager_of_ppl_loose : loose t Apron.Manager.t -> 'a Apron.Manager.t val manager_of_ppl_strict : strict t Apron.Manager.t -> 'a Apron.Manager.t val manager_of_ppl_grid : grid t Apron.Manager.t -> 'a Apron.Manager.t (** Make a ppl manager generic *) val manager_to_ppl : 'a Apron.Manager.t -> 'b t Apron.Manager.t val manager_to_ppl_loose : 'a Apron.Manager.t -> loose t Apron.Manager.t val manager_to_ppl_strict : 'a Apron.Manager.t -> strict t Apron.Manager.t val manager_to_ppl_grid : 'a Apron.Manager.t -> grid t Apron.Manager.t (** Instanciate the type of a ppl manager. Raises [Failure] if the argument manager is not a ppl manager *) module Abstract0 : sig val is_ppl : 'a Apron.Abstract0.t -> bool val is_ppl_loose : 'a Apron.Abstract0.t -> bool val is_ppl_strict : 'a Apron.Abstract0.t -> bool val is_ppl_grid : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument manager is a ppl value *) val of_ppl : 'a t Apron.Abstract0.t -> 'b Apron.Abstract0.t val of_ppl_loose : loose t Apron.Abstract0.t -> 'a Apron.Abstract0.t val of_ppl_strict : strict t Apron.Abstract0.t -> 'a Apron.Abstract0.t val of_ppl_grid : grid t Apron.Abstract0.t -> 'a Apron.Abstract0.t (** Make a ppl value generic *) val to_ppl : 'a Apron.Abstract0.t -> 'b t Apron.Abstract0.t val to_ppl_loose : 'a Apron.Abstract0.t -> loose t Apron.Abstract0.t val to_ppl_strict : 'a Apron.Abstract0.t -> strict t Apron.Abstract0.t val to_ppl_grid : 'a Apron.Abstract0.t -> grid t Apron.Abstract0.t (** Instanciate the type of a ppl value. Raises [Failure] if the argument manager is not a ppl manager *) end module Abstract1 : sig val is_ppl : 'a Apron.Abstract1.t -> bool val is_ppl_loose : 'a Apron.Abstract1.t -> bool val is_ppl_strict : 'a Apron.Abstract1.t -> bool val is_ppl_grid : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument manager is a ppl value *) val of_ppl : 'a t Apron.Abstract1.t -> 'b Apron.Abstract1.t val of_ppl_loose : loose t Apron.Abstract1.t -> 'a Apron.Abstract1.t val of_ppl_strict : strict t Apron.Abstract1.t -> 'a Apron.Abstract1.t val of_ppl_grid : grid t Apron.Abstract1.t -> 'a Apron.Abstract1.t (** Make a ppl value generic *) val to_ppl : 'a Apron.Abstract1.t -> 'b t Apron.Abstract1.t val to_ppl_loose : 'a Apron.Abstract1.t -> loose t Apron.Abstract1.t val to_ppl_strict : 'a Apron.Abstract1.t -> strict t Apron.Abstract1.t val to_ppl_grid : 'a Apron.Abstract1.t -> grid t Apron.Abstract1.t (** Instanciate the type of a ppl value. Raises [Failure] if the argument manager is not a ppl manager *) end ") quote(ML," let manager_is_ppl man = let str = Apron.Manager.get_library man in let str = try String.sub str 0 3 with Invalid_argument _ -> \"\" in (String.compare str \"PPL\")==0 let manager_of_ppl (man:'a t Apron.Manager.t) : 'b Apron.Manager.t = Obj.magic man let manager_to_ppl (man:'a Apron.Manager.t) : 'b t Apron.Manager.t = if manager_is_ppl man then Obj.magic man else failwith \"Ppl.to_ppl: the argument manager is not a Ppl manager\" let manager_is_ppl_loose man = let str = Apron.Manager.get_library man in (String.compare str \"PPL::Polyhedron, loose mode\")==0 let manager_of_ppl_loose (man:loose t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_ppl_loose (man:'a Apron.Manager.t) : loose t Apron.Manager.t = if manager_is_ppl_loose man then Obj.magic man else failwith \"Ppl.to_ppl_loose: the argument manager is not a loose Ppl manager\" let manager_is_ppl_strict man = let str = Apron.Manager.get_library man in (String.compare str \"PPL::Polyhedron, strict mode\")==0 let manager_of_ppl_strict (man:strict t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_ppl_strict (man:'a Apron.Manager.t) : strict t Apron.Manager.t = if manager_is_ppl_strict man then Obj.magic man else failwith \"Ppl.to_ppl_strict: the argument manager is not a strict Ppl manager\" let manager_is_ppl_grid man = let str = Apron.Manager.get_library man in (String.compare str \"PPL::Grid\")==0 let manager_of_ppl_grid (man:grid t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_ppl_grid (man:'a Apron.Manager.t) : grid t Apron.Manager.t = if manager_is_ppl_grid man then Obj.magic man else failwith \"Ppl.to_ppl_grid: the argument manager is not a grid Ppl manager\" module Abstract0 = struct let is_ppl abs = manager_is_ppl (Apron.Abstract0.manager abs) let is_ppl_loose abs = manager_is_ppl_loose (Apron.Abstract0.manager abs) let is_ppl_strict abs = manager_is_ppl (Apron.Abstract0.manager abs) let is_ppl_grid abs = manager_is_ppl_grid (Apron.Abstract0.manager abs) let of_ppl (abs: 'a t Apron.Abstract0.t) : 'b Apron.Abstract0.t = Obj.magic abs let of_ppl_loose (abs: loose t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let of_ppl_strict (abs: strict t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let of_ppl_grid (abs: grid t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let to_ppl (abs:'a Apron.Abstract0.t) : 'b t Apron.Abstract0.t = if is_ppl abs then Obj.magic abs else failwith \"Ppl.Abstract0.to_ppl: the argument value is not a ppl value\" let to_ppl_loose (abs:'a Apron.Abstract0.t) : loose t Apron.Abstract0.t = if is_ppl_loose abs then Obj.magic abs else failwith \"Ppl.Abstract0.to_ppl_loose: the argument value is not a loose ppl value\" let to_ppl_strict (abs:'a Apron.Abstract0.t) : strict t Apron.Abstract0.t = if is_ppl_strict abs then Obj.magic abs else failwith \"Ppl.Abstract0.to_ppl_strict: the argument value is not a strict ppl value\" let to_ppl_grid (abs:'a Apron.Abstract0.t) : grid t Apron.Abstract0.t = if is_ppl_grid abs then Obj.magic abs else failwith \"Ppl.Abstract0.to_ppl_grid: the argument value is not a grid ppl value\" end module Abstract1 = struct let is_ppl abs = manager_is_ppl (Apron.Abstract1.manager abs) let is_ppl_loose abs = manager_is_ppl_loose (Apron.Abstract1.manager abs) let is_ppl_strict abs = manager_is_ppl (Apron.Abstract1.manager abs) let is_ppl_grid abs = manager_is_ppl_grid (Apron.Abstract1.manager abs) let of_ppl (abs: 'a t Apron.Abstract1.t) : 'b Apron.Abstract1.t = Obj.magic abs let of_ppl_loose (abs: loose t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let of_ppl_strict (abs: strict t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let of_ppl_grid (abs: grid t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let to_ppl (abs:'a Apron.Abstract1.t) : 'b t Apron.Abstract1.t = if is_ppl abs then Obj.magic abs else failwith \"Ppl.Abstract1.to_ppl: the argument value is not a ppl value\" let to_ppl_loose (abs:'a Apron.Abstract1.t) : loose t Apron.Abstract1.t = if is_ppl_loose abs then Obj.magic abs else failwith \"Ppl.Abstract1.to_ppl_loose: the argument value is not a loose ppl value\" let to_ppl_strict (abs:'a Apron.Abstract1.t) : strict t Apron.Abstract1.t = if is_ppl_strict abs then Obj.magic abs else failwith \"Ppl.Abstract1.to_ppl_strict: the argument value is not a strict ppl value\" let to_ppl_grid (abs:'a Apron.Abstract1.t) : grid t Apron.Abstract1.t = if is_ppl_grid abs then Obj.magic abs else failwith \"Ppl.Abstract1.to_ppl_grid: the argument value is not a grid ppl value\" end ") quote(MLI,"\n(** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. Do not forget the [-cc \"g++\"] option: PPL is a C++ library which requires a C++ linker. {3 Bytecode compilation} {[ocamlc -cc \"g++\"-I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma ppl.cma mlexample.ml]} {[ocamlc -cc \"g++\" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \\ bigarray.cma gmp.cma apron.cma ppl.cma ocamlc -cc \"g++\" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma ppl.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -cc \"g++\" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa ppl.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -cc \"g++\" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa ppl.cmxa mlexample.ml \\ -cclib \"-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib -L$PPL_PREFIX/lib\\ -lap_ppl_caml_debug -lap_ppl_debug -lppl -lgmpxx \\ -lapron_caml_debug -lapron_debug \\ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP_PREFIX/lib -lgmp \\ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \\ -lbigarray\" ]} *)") apron-dist-0.9.10/apron/index.tex0000640014525101416610000001463711252236653016535 0ustar bjeannetpopart\documentclass[a4paper,11pt]{article} \usepackage{hyperlatex} \htmlcss{style.css} \htmltitle{APRON numerical abstract domain library} \htmlpanel{0} \setcounter{htmlautomenu}{1} \setcounter{htmldepth}{1} \usepackage{xspace} \T\usepackage{color} \T\usepackage{pstricks,pst-node,pstcol} \T\usepackage{graphicx} \T\usepackage{mycolor} \T\usepackage{amsmath} \T\usepackage{amssymb} %\usepackage{frames} \newcommand{\ocaml}{\xlink{OCaml}{http://www.caml.org}\xspace} \newcommand{\mlgmpidl}{\xlink{MLGMPIDL}{http://www.inrialpes.fr/pop-art/people/bjeannet/mlxxxidl-forge/mlgmpidl/}\xspace} \newcommand{\camlidl}{\xlink{CamlIDL}{http://caml.inria.fr/camlidl/}\xspace} \newcommand{\interproc}{\xlink{Interproc}{http://pop-art.inrialpes.fr/interproc/interprocweb.cgi}\xspace} \title{APRON numerical abstract domain library} \date{} \author{} \begin{document} %\xmlattributes*{img}{align="left"} %\xlink{\htmlimg{http://devel.inria.fr/logo_inria.png}{INRIA}}{http://www.inria.fr} \xmlattributes*{img}{align="RIGHT"} \htmlimg{poster.gif}{poster} \xlink{Home page}{http://apron.cri.ensmp.fr/} \maketitle \section{About} The APRON library is dedicated to the static analysis of the numerical variables of a program by Abstract Interpretation. The aim of such an analysis is to infer invariants about these variables. like $1<=x+y<=z$, which holds during any execution of the program. You may look at to the \interproc analyzer for an online demonstration of static analysis. The APRON library is intended to be a common interface to various underlying libraries/abstract domains and to provide additional services that can be implemented independently from the underlying library/abstract domain, as shown by the poster on the right (presented at the \xlink{SAS 2007}{http://www2.imm.dtu.dk/sas2007/}). You may also read the associated \xlink{flyer}{flyer.pdf}. Currently, APRON provides a C interface and an \ocaml interface. There also exists a C++ interface, which is more experimental. The version 0.9.10 (10th septembre 2009) contains 3 libraries and 4 abstract domains: \begin{itemize} \item The BOX intervals library \item The OCT octagon library \item The NEWPOLKA Convex Polyhedra and Linear Equalities library \end{itemize} It also provides an optional interface to the \xlink{Parma Polyhedra Library}{http://www.cs.unipr.it/ppl/}, which adds \begin{itemize} \item the Convex Polyhedra and Linear Congruences (grid) domains \item the reduced product of NewPolka convex polyhedra and PPL linear congruences \end{itemize} \section{Demonstration} The online \interproc static analyzer illustrates the use of the APRON library in static analysis. \section{License} APRON is a free software under LGPL license, except the wrappers related to the PPL library, which follows the GPL license of the PPL library. \section{Documentation} \begin{itemize} \item On-line \xlink{C interface}{http://apron.cri.ensmp.fr/library/0.9.10/apron/apron.html} and \xlink{OCaml interface}{http://apron.cri.ensmp.fr/library/0.9.10/mlapronidl/index.html}; \item \xlink{C pdf}{http://apron.cri.ensmp.fr/library/0.9.10/apron.pdf} or \xlink{OCaml pdf}{http://apron.cri.ensmp.fr/library/0.9.10/mlapronidl.pdf}; \item \xlink{C example}{http://apron.cri.ensmp.fr/library/0.9.10/example1.c} or \xlink{OCaml example 1}{http://apron.cri.ensmp.fr/library/0.9.10/mlexample1.ml}/\xlink{OCaml example 2}{http://apron.cri.ensmp.fr/library/0.9.10/mlexample2.ml}/\xlink{OCaml example 3}{http://apron.cri.ensmp.fr/library/0.9.10/mlexample3.ml}. For the ML examples, they are almost identical, but the ones with the higher numbers use higher-level functions to define affine expressions and constraints. \end{itemize} \section{Download} \subsection{Requirements} \begin{itemize} \item An ANSI C compiler (only gcc with ansi option has been tested) \item The \xlink{GMP}{http://www.swox.com/gmp/} library, version 4.2 or up, and the \xlink{MPFR}{http://www.mpfr.org/} library, version 2.2 or up; \item Optionally, \xlink{Parma Polyhedra Library}{http://www.cs.unipr.it/ppl/}, and \xlink{GMP}{http://www.swox.com/gmp/} compiled with \kbd{-enable-cxx} configuration option) \item If you want the C++ interface (still experimental), GCC 4.1.2 or up \item If you want to use the \ocaml interface, you need the \ocaml system, version 3.09 or up, the \camlidl 1.05 stub code generator for the OCaml interface, as well as GNU SED 4.1 or up, and GNU m4 (if you download from subversion repository). You also need \mlgmpidl, but it can be included if you opt for the ``distribution'' version of APRON (see below). \end{itemize} \subsection{Current version: 0.9.10} \begin{itemize} \item \xlink{Tar-gzipped sources}{http://apron.cri.ensmp.fr/library/apron-0.9.10.tgz} \item \xlink{Tar-gzipped sources of both APRON and MLGMPIDL}{http://apron.cri.ensmp.fr/library/apron-dist-0.9.10.tgz} \item \xlink{Changes}{http://apron.cri.ensmp.fr/library/Changes} \item You can also access to the \xlink{SUBVERSION REPOSITORY}{http://svn.cri.ensmp.fr/svn/apron/}, by typing something like \begin{quote} \kbd{svn list http://svn.cri.ensmp.fr/svn/apron/apron/trunk}. \end{quote} If you want to access the distribution which references both APRON and MLGMPIDL (using subversion external links): \begin{quote} \kbd{svn list http://svn.cri.ensmp.fr/svn/apron/apron-dist/trunk}. \end{quote} \end{itemize} As the library may still contain subtle bugs, we strongly suggest to be up-to-date with the most recent version. \subsection{Older versions} \begin{itemize} \item 0.9.9 \xlink{Tar-gzipped sources}{http://apron.cri.ensmp.fr/library/apron-0.9.9.tgz} \item 0.9.8 \xlink{Tar-gzipped sources}{http://apron.cri.ensmp.fr/library/apron-0.9.8.tgz} \item 0.9.7 \xlink{Tar-gzipped sources}{http://apron.cri.ensmp.fr/library/apron-0.9.7.tgz} \item 0.9.6 \xlink{Tar-gzipped sources}{http://apron.cri.ensmp.fr/library/apron-0.9.6.tgz} \item 0.9.5 \xlink{Tar-gzipped sources}{http://apron.cri.ensmp.fr/library/apron-0.9.5.tgz} \item 0.9.4 \xlink{Tar-gzipped sources}{http://apron.cri.ensmp.fr/library/apron-0.9.4.tgz} \item 0.9.3 \xlink{Tar-gzipped sources}{http://apron.cri.ensmp.fr/library/apron-0.9.3.tgz} \item 0.9.2 \xlink{Tar-gzipped sources}{http://apron.cri.ensmp.fr/library/apron-0.9.2.tgz} \item 0.9.1 \xlink{Tar-gzipped sources}{http://apron.cri.ensmp.fr/library/apron-0.9.1.tgz} \item 0.9.0 \xlink{Tar-gzipped sources}{http://apron.cri.ensmp.fr/library/apron-0.9.0.tgz} \end{itemize} \end{document} apron-dist-0.9.10/apron/Makefile.config.model0000640014525101416610000000664111251675421020702 0ustar bjeannetpopart# -*- mode: makefile -*- ###################################################################### # HAS Flags ###################################################################### # If defined to non-empty value, generates dynamic libraries. # Do not forget to add -fPIC to CFLAGS and CFLAGS_DEBUG HAS_SHARED=1 # If defined to non-empty value, compiles the OCaml interface HAS_OCAML = 1 # If defined to non-empty value, compiles the C++ interface (beta version) # HAS_CPP = 1 # If defined to non-empty value, compiles the PPL domain # (require included patch to PPL, see ppl/README and ppl/ppl.patch) # HAS_PPL = 1 # If defined to non-empty value, support for "long double" is enabled # HAS_LONG_DOUBLE = 1 ###################################################################### # Directories ###################################################################### # Where to install and to find APRON # ($(APRON_PREFIX)/include, $(APRON_PREFIX)/lib) # APRON_PREFIX = /usr # Where to install and to find MLGMPIDL # ($(MLGMPIDL_PREFIX)/lib) # MLGMPIDL_PREFIX = /usr/local # Where to find GMP ($(GMP_PREFIX)/include, ($GMP_PREFIX)/lib # GMP_PREFIX = /usr # Where to find MPFR ($(MPFR_PREFIX)/include, ($MPFR_PREFIX)/lib # MPFR_PREFIX = /usr # Where to find PPL ($(PPL_PREFIX)/include, $(PPL_PREFIX)/lib # PPL_PREFIX = /usr # Where to find OCAML ($(CAML_PREFIX)/bin, $(CAML_PREFIX)/lib/ocaml, ...) # CAML_PREFIX = /usr # Where to find CAMLIDL ($(CAMLIDL_PREFIX)/bin, $(CAMLIDL_PREFIX)/lib/ocaml, ...) # CAMLIDL_PREFIX = /usr ###################################################################### # Tools and Flags ###################################################################### # C compiler CC = gcc # C compilation flags CFLAGS = \ -Wcast-qual -Wswitch -Werror-implicit-function-declaration \ -Wall -Wextra -Wundef -Wbad-function-cast -Wcast-align -Wstrict-prototypes \ -Wno-unused \ -std=c99 -U__STRICT_ANSI__ \ -fPIC -O3 -DNDEBUG # C compilation flags in debug (or profile) mode CFLAGS_DEBUG = \ -Wcast-qual -Wswitch -Werror-implicit-function-declaration \ -Wall -Wextra -Wundef -Wbad-function-cast -Wcast-align -Wstrict-prototypes \ -Wno-unused \ -std=c99 -U__STRICT_ANSI__ \ -fPIC -g -O0 -UNDEBUG # Examples of CFLAGS # CFLAGS = -Wswitch -Werror-implicit-function-declaration -Wall -std=c99 \ # -O3 -DNDEBUG \ # -march=pentium-m -mtune=pentium-m -pipe -mmmx -msse -msse2 \ # -mfpmath=sse -ftracer -funit-at-a-time -funroll-loops -fmove-all-movables # C++ compiler CXX = g++ # C++ compilation flags CXXFLAGS = \ -Wcast-qual -Wswitch \ -Wall -Wextra -Wundef -Wcast-align \ -Wno-unused \ -fPIC -O3 -DNDEBUG # C++ compilation flags in debug (or profile) mode CXXFLAGS_DEBUG = \ -Wcast-qual -Wswitch \ -Wall -Wextra -Wundef -Wcast-align \ -Wno-unused \ -fPIC -g -O0 -UNDEBUG AR = ar RANLIB = ranlib SED = sed # version >=4.1.x required M4 = m4 INSTALL = install INSTALLd = install -d OCAMLC = $(CAML_PREFIX)/bin/ocamlc.opt OCAMLOPT = $(CAML_PREFIX)/bin/ocamlopt.opt # ocamlc compilation flags OCAMLFLAGS = -g # ocamlopt compilation flags OCAMLOPTFLAGS = -inline 20 OCAMLDEP = $(CAML_PREFIX)/bin/ocamldep OCAMLLEX = $(CAML_PREFIX)/bin/ocamllex.opt OCAMLYACC = $(CAML_PREFIX)/bin/ocamlyacc OCAMLDOC = $(CAML_PREFIX)/bin/ocamldoc.opt OCAMLMKTOP = $(CAML_PREFIX)/bin/ocamlmktop OCAMLMKLIB = $(CAML_PREFIX)/bin/ocamlmklib CAMLIDL = $(CAMLIDL_PREFIX)/bin/camlidl LATEX=latex DVIPDF=dvipdf MAKEINDEX=makeindex TEXI2DVI=texi2dvi TEXI2HTML=texi2html apron-dist-0.9.10/apron/Makefile0000640014525101416610000000746411252213304016330 0ustar bjeannetpopartinclude Makefile.config LCFLAGS = \ -Lapron -Litv -Lbox -Loctagons -Lnewpolka \ -L$(PPL_PREFIX)/lib -Lppl \ -Lproducts \ -L$(GMP_PREFIX)/lib -L$(MPFR_PREFIX)/lib \ -L$(CAMLIDL_PREFIX)/lib/ocaml all: c ifneq ($(HAS_OCAML),) all: ml endif ifneq ($(HAS_CPP),) all: cxx endif c: (cd num; make all) (cd itv; make all) (cd apron; make all) (cd newpolka; make all) (cd box; make all) (cd octagons; make MPQ D) ifneq ($(HAS_PPL),) (cd ppl; make) (cd products; make) endif cxx: (cd apronxx; make) ml: (cd mlapronidl; make all) (cd newpolka; make ml) (cd box; make ml) (cd octagons; make mlMPQ mlD) ifneq ($(HAS_PPL),) (cd ppl; make ml) (cd products; make ml) endif .PHONY: aprontop apronppltop aprontop: $(OCAMLMKTOP) -I $(MLGMPIDL_PREFIX) -I $(APRON_PREFIX) -verbose -o $@ \ bigarray.cma gmp.cma apron.cma boxMPQ.cma octMPQ.cma polkaMPQ.cma apronppltop: $(OCAMLMKTOP) -I $(MLGMPIDL_PREFIX) -I $(APRON_PREFIX) -verbose -o $@ \ bigarray.cma gmp.cma apron.cma boxMPQ.cma octMPQ.cma polkaMPQ.cma ppl.cma polkaGrid.cma rebuild: ifneq ($(HAS_OCAML),) (cd mlapronidl; make rebuild) (cd newpolka; make rebuild) (cd box; make rebuild) (cd octagons; make rebuild) (cd ppl; make rebuild) (cd products; make rebuild) endif install: (cd num; make install) (cd itv; make install) (cd apron; make install) (cd newpolka; make install) (cd box; make install) (cd octagons; make install) ifneq ($(HAS_PPL),) (cd ppl; make install) (cd products; make install) endif ifneq ($(HAS_OCAML),) (cd mlapronidl; make install) $(INSTALLd) $(APRON_PREFIX)/bin if test -f aprontop; then $(INSTALL) aprontop $(APRON_PREFIX)/bin; fi ifneq ($(HAS_PPL),) if test -f aprontop; then $(INSTALL) apronppltop $(APRON_PREFIX)/bin; fi endif endif ifneq ($(HAS_CPP),) (cd apronxx; make install) endif clean: (cd num; make clean) (cd itv; make clean) (cd apron; make clean) (cd mlapronidl; make clean) (cd box; make clean) (cd newpolka; make clean) (cd octagons; make clean) (cd ppl; make clean) (cd products; make clean) (cd apronxx; make clean) (cd examples; make clean) (cd test; make clean) rm -fr online tmp apron*run aprontop apronppltop mostlyclean: clean (cd mlapronidl; make mostlyclean) (cd box; make mostlyclean) (cd octagons; make mostlyclean) (cd newpolka; make mostlyclean) (cd ppl; make mostlyclean) (cd products; make mostlyclean) (cd apronxx; make mostlyclean) uninstall :distclean distclean: (cd num; make distclean) (cd itv; make distclean) (cd apron; make distclean) (cd mlapronidl; make distclean) (cd box; make distclean) (cd newpolka; make distclean) (cd octagons; make distclean) (cd examples; make distclean) (cd ppl; make distclean) (cd products; make distclean) (cd apronxx; make distclean) (cd $(APRON_PREFIX)/bin; rm -f apron*) doc: (cd apron; make html apron.pdf) ifneq ($(HAS_OCAML),) (cd mlapronidl; make html mlapronidl.pdf) endif ifneq ($(HAS_CPP),) (cd apronxx; make doc) endif # make distribution, update to reflect current version PKGNAME = apron-0.9.10 PKGFILES = Makefile README README.windows README.mac AUTHORS COPYING Makefile.config.model Changes PKGDIRS = apron num itv octagons box newpolka ppl products mlapronidl examples test apronxx dist: $(MAKE) all $(MAKE) doc mkdir -p $(PKGNAME) $(MAKE) $(foreach pkg,$(PKGDIRS),pkg_$(pkg)) cp $(PKGFILES) $(PKGNAME) tar vczf $(PKGNAME).tgz $(PKGNAME) rm -rf $(PKGNAME) # these 2 targets are for main developpers only index.html: index.tex hyperlatex index.tex online: doc index.html rm -fr online mkdir -p online mv index.html poster.gif flyer.pdf online mv apron/html online/apron mv mlapronidl/html online/mlapronidl cp apron/apron.pdf online cp mlapronidl/mlapronidl.pdf online cp examples/example1.c online cp examples/mlexample?.ml online cp Changes online pkg_%: (cd $*; $(MAKE) dist) (cd $(PKGNAME); tar xzf ../$*.tgz) rm -rf $*.tgz apron-dist-0.9.10/apron/products/0000750014525101416610000000000011252216517016530 5ustar bjeannetpopartapron-dist-0.9.10/apron/products/interval.idl0000777014525101416610000000000011252510553025737 2../mlapronidl/interval.idlustar bjeannetpopartapron-dist-0.9.10/apron/products/lincons0.idl0000777014525101416610000000000011252510553025541 2../mlapronidl/lincons0.idlustar bjeannetpopartapron-dist-0.9.10/apron/products/scalar.idl0000777014525101416610000000000011252510553025001 2../mlapronidl/scalar.idlustar bjeannetpopartapron-dist-0.9.10/apron/products/abstract0.idl0000777014525101416610000000000011252510553026035 2../mlapronidl/abstract0.idlustar bjeannetpopartapron-dist-0.9.10/apron/products/texpr0.idl0000777014525101416610000000000011252510553024733 2../mlapronidl/texpr0.idlustar bjeannetpopartapron-dist-0.9.10/apron/products/polkaGrid_caml.c0000640014525101416610000003267511252216517021622 0ustar bjeannetpopart/* File generated from polkaGrid.idl */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include "ap_global0.h" #include "apron_caml.h" #include "ap_pkgrid.h" extern void camlidl_apron_manager_funid_ml2c(value, ap_funid_t *); #define camlidl_ml2c_manager_ap_funid_t(v,c,ctx) camlidl_apron_manager_funid_ml2c(v,c) extern value camlidl_apron_manager_funid_c2ml(ap_funid_t *); #define camlidl_c2ml_manager_ap_funid_t(c,ctx) camlidl_apron_manager_funid_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_funopt_t(value, struct ap_funopt_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_funopt_t(struct ap_funopt_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_exc_ml2c(value, ap_exc_t *); #define camlidl_ml2c_manager_ap_exc_t(v,c,ctx) camlidl_apron_manager_exc_ml2c(v,c) extern value camlidl_apron_manager_exc_c2ml(ap_exc_t *); #define camlidl_c2ml_manager_ap_exc_t(c,ctx) camlidl_apron_manager_exc_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_exclog_t(value, struct ap_exclog_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_exclog_t(struct ap_exclog_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_ptr_ml2c(value, ap_manager_ptr *); #define camlidl_ml2c_manager_ap_manager_ptr(v,c,ctx) camlidl_apron_manager_ptr_ml2c(v,c) extern value camlidl_apron_manager_ptr_c2ml(ap_manager_ptr *); #define camlidl_c2ml_manager_ap_manager_ptr(c,ctx) camlidl_apron_manager_ptr_c2ml(c) extern void camlidl_apron_scalar_ml2c(value, ap_scalar_t *); #define camlidl_ml2c_scalar_ap_scalar_t(v,c,ctx) camlidl_apron_scalar_ml2c(v,c) extern value camlidl_apron_scalar_c2ml(ap_scalar_t *); #define camlidl_c2ml_scalar_ap_scalar_t(c,ctx) camlidl_apron_scalar_c2ml(c) extern void camlidl_ml2c_scalar_ap_scalar_ptr(value, ap_scalar_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_ap_scalar_ptr(ap_scalar_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_scalar_struct_ap_scalar_array_t(value, struct ap_scalar_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_struct_ap_scalar_array_t(struct ap_scalar_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_t(value, struct ap_interval_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_t(struct ap_interval_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_ap_interval_ptr(value, ap_interval_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_ap_interval_ptr(ap_interval_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_array_t(value, struct ap_interval_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_array_t(struct ap_interval_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_coeff_struct_ap_coeff_t(value, struct ap_coeff_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_coeff_struct_ap_coeff_t(struct ap_coeff_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_ap_dim_t(value, ap_dim_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_ap_dim_t(ap_dim_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimchange_t(value, struct ap_dimchange_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange_t(struct ap_dimchange_t *, camlidl_ctx _ctx); extern void camlidl_apron_dimchange_ml2c(value, ap_dimchange_t *); #define camlidl_ml2c_dim_ap_dimchange_t(v,c,ctx) camlidl_apron_dimchange_ml2c(v,c) extern value camlidl_apron_dimchange_c2ml(ap_dimchange_t *); #define camlidl_c2ml_dim_ap_dimchange_t(c,ctx) camlidl_apron_dimchange_c2ml(c) extern void camlidl_ml2c_dim_struct_ap_dimchange2_t(value, struct ap_dimchange2_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange2_t(struct ap_dimchange2_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimperm_t(value, struct ap_dimperm_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimperm_t(struct ap_dimperm_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimension_t(value, struct ap_dimension_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimension_t(struct ap_dimension_t *, camlidl_ctx _ctx); extern void camlidl_apron_linexpr0_ptr_ml2c(value, ap_linexpr0_ptr *); #define camlidl_ml2c_linexpr0_ap_linexpr0_ptr(v,c,ctx) camlidl_apron_linexpr0_ptr_ml2c(v,c) extern value camlidl_apron_linexpr0_ptr_c2ml(ap_linexpr0_ptr *); #define camlidl_c2ml_linexpr0_ap_linexpr0_ptr(c,ctx) camlidl_apron_linexpr0_ptr_c2ml(c) extern void camlidl_apron_lincons0_ml2c(value, ap_lincons0_t *, camlidl_ctx); #define camlidl_ml2c_lincons0_ap_lincons0_t(v,c,ctx) camlidl_apron_lincons0_ml2c(v,c,ctx) extern value camlidl_apron_lincons0_c2ml(ap_lincons0_t *); #define camlidl_c2ml_lincons0_ap_lincons0_t(c,ctx) camlidl_apron_lincons0_c2ml(c) extern void camlidl_ml2c_lincons0_struct_ap_lincons0_array_t(value, struct ap_lincons0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_lincons0_struct_ap_lincons0_array_t(struct ap_lincons0_array_t *, camlidl_ctx _ctx); extern int camlidl_ml2c_generator0_enum_gentyp(value); extern value camlidl_c2ml_generator0_enum_gentyp(int); extern int camlidl_transl_table_generator0_enum_gentyp[]; extern void camlidl_ml2c_generator0_struct_ap_generator0_t(value, struct ap_generator0_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_generator0_struct_ap_generator0_t(struct ap_generator0_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_generator0_struct_ap_generator0_array_t(value, struct ap_generator0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_generator0_struct_ap_generator0_array_t(struct ap_generator0_array_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr0_ptr_ml2c(value, ap_texpr0_ptr *); #define camlidl_ml2c_texpr0_ap_texpr0_ptr(v,c,ctx) camlidl_apron_texpr0_ptr_ml2c(v,c) extern value camlidl_apron_texpr0_ptr_c2ml(ap_texpr0_ptr *); #define camlidl_c2ml_texpr0_ap_texpr0_ptr(c,ctx) camlidl_apron_texpr0_ptr_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_op_t(value, ap_texpr_op_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_op_t(ap_texpr_op_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_unop_t_ml2c(value, ap_texpr_unop_t *); #define camlidl_ml2c_texpr0_ap_texpr_unop_t(v,c,ctx) camlidl_apron_texpr_unop_t_ml2c(v,c) extern value camlidl_apron_texpr_unop_t_c2ml(ap_texpr_unop_t *); #define camlidl_c2ml_texpr0_ap_texpr_unop_t(c,ctx) camlidl_apron_texpr_unop_t_c2ml(c) extern void camlidl_apron_texpr_binop_t_ml2c(value, ap_texpr_binop_t *); #define camlidl_ml2c_texpr0_ap_texpr_binop_t(v,c,ctx) camlidl_apron_texpr_binop_t_ml2c(v,c) extern value camlidl_apron_texpr_binop_t_c2ml(ap_texpr_binop_t *); #define camlidl_c2ml_texpr0_ap_texpr_binop_t(c,ctx) camlidl_apron_texpr_binop_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rtype_t(value, ap_texpr_rtype_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rtype_t(ap_texpr_rtype_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_rtype_t_ml2c(value, ap_texpr_rtype_t *); #define camlidl_ml2c_texpr0_ap_texpr_rtype_t(v,c,ctx) camlidl_apron_texpr_rtype_t_ml2c(v,c) extern value camlidl_apron_texpr_rtype_t_c2ml(ap_texpr_rtype_t *); #define camlidl_c2ml_texpr0_ap_texpr_rtype_t(c,ctx) camlidl_apron_texpr_rtype_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rdir_t(value, ap_texpr_rdir_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rdir_t(ap_texpr_rdir_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_rdir_t_ml2c(value, ap_texpr_rdir_t *); #define camlidl_ml2c_texpr0_ap_texpr_rdir_t(v,c,ctx) camlidl_apron_texpr_rdir_t_ml2c(v,c) extern value camlidl_apron_texpr_rdir_t_c2ml(ap_texpr_rdir_t *); #define camlidl_c2ml_texpr0_ap_texpr_rdir_t(c,ctx) camlidl_apron_texpr_rdir_t_c2ml(c) extern void camlidl_apron_tcons0_ml2c(value, ap_tcons0_t *, camlidl_ctx); #define camlidl_ml2c_tcons0_ap_tcons0_t(v,c,ctx) camlidl_apron_tcons0_ml2c(v,c,ctx) extern value camlidl_apron_tcons0_c2ml(ap_tcons0_t *); #define camlidl_c2ml_tcons0_ap_tcons0_t(c,ctx) camlidl_apron_tcons0_c2ml(c) extern void camlidl_ml2c_tcons0_struct_ap_tcons0_array_t(value, struct ap_tcons0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_tcons0_struct_ap_tcons0_array_t(struct ap_tcons0_array_t *, camlidl_ctx _ctx); extern void camlidl_apron_abstract0_ptr_ml2c(value, ap_abstract0_ptr *); #define camlidl_ml2c_abstract0_ap_abstract0_ptr(v,c,ctx) camlidl_apron_abstract0_ptr_ml2c(v,c) extern value camlidl_apron_abstract0_ptr_c2ml(ap_abstract0_ptr *); #define camlidl_c2ml_abstract0_ap_abstract0_ptr(c,ctx) camlidl_apron_abstract0_ptr_c2ml(c) value camlidl_polkaGrid_ap_pkgrid_manager_alloc( value _v_manpk, value _v_manpplgrid) { ap_manager_ptr manpk; /*in*/ ap_manager_ptr manpplgrid; /*in*/ ap_manager_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_manpk, &manpk, _ctx); camlidl_ml2c_manager_ap_manager_ptr(_v_manpplgrid, &manpplgrid, _ctx); /* begin user-supplied calling sequence */ _res = ap_pkgrid_manager_alloc(manpk,manpplgrid); if (_res==NULL) caml_failwith("PolkaGrid.manager_alloc: the provided polka manager is most probably an equalities polka manager"); { ap_exc_t i; for (i=1; iinternal; manpk = ap_manager_copy(intern->tmanagers[0]); manpplgrid = ap_manager_copy(intern->tmanagers[1]); /* end user-supplied calling sequence */ Begin_roots_block(_vres, 2) _vres[0] = camlidl_c2ml_manager_ap_manager_ptr(&manpk, _ctx); _vres[1] = camlidl_c2ml_manager_ap_manager_ptr(&manpplgrid, _ctx); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); return _vresult; } value camlidl_polkaGrid_ap_pkgrid_decompose( value _v_abs) { ap_abstract0_ptr abs; /*in*/ ap_abstract0_ptr abspk; /*out*/ ap_abstract0_ptr abspplgrid; /*out*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; value _vresult; value _vres[2] = { 0, 0, }; camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_abs, &abs, _ctx); /* begin user-supplied calling sequence */ { ap_reducedproduct_internal_t* intern = (ap_reducedproduct_internal_t*)abs->man->internal; ap_manager_t* manpk = intern->tmanagers[0]; ap_manager_t* manpplgrid = intern->tmanagers[1]; void** res = ap_reducedproduct_decompose(abs->man,false,(ap_reducedproduct_t*)abs->value); abspk = (ap_abstract0_t*)malloc(sizeof(ap_abstract0_t)); abspk->man = ap_manager_copy(manpk); abspk->value = res[0]; abspplgrid = (ap_abstract0_t*)malloc(sizeof(ap_abstract0_t)); abspplgrid->man = ap_manager_copy(manpplgrid); abspplgrid->value = res[1]; free(res); } /* end user-supplied calling sequence */ Begin_roots_block(_vres, 2) _vres[0] = camlidl_c2ml_abstract0_ap_abstract0_ptr(&abspk, _ctx); _vres[1] = camlidl_c2ml_abstract0_ap_abstract0_ptr(&abspplgrid, _ctx); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (abs->man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(abs->man,_ctx); /* end user-supplied deallocation sequence */ return _vresult; } value camlidl_polkaGrid_ap_pkgrid_compose( value _v_man, value _v_abspk, value _v_abspplgrid) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr abspk; /*in*/ ap_abstract0_ptr abspplgrid; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_abspk, &abspk, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_abspplgrid, &abspplgrid, _ctx); /* begin user-supplied calling sequence */ { ap_reducedproduct_internal_t* intern = (ap_reducedproduct_internal_t*)man->internal; ap_manager_t* manpk = intern->tmanagers[0]; ap_manager_t* manpplgrid = intern->tmanagers[1]; void* tabs[2]; tabs[0] = abspk->value; tabs[1] = abspplgrid->value; ap_reducedproduct_t* prod = ap_reducedproduct_compose(man,false,tabs); _res = (ap_abstract0_t*)malloc(sizeof(ap_abstract0_t)); _res->man = ap_manager_copy(man); _res->value = prod; } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } apron-dist-0.9.10/apron/products/polkaGrid.ml0000640014525101416610000000423111252216517020777 0ustar bjeannetpopart(* File generated from polkaGrid.idl *) (** Reduced product of NewPolka polyhedra and PPL grids *) (** Type of abstract values, where ['a] is [Polka.loose] or [Polka.strict]. *) type 'a t external manager_alloc : 'a Polka.t Apron.Manager.t -> Ppl.grid Ppl.t Apron.Manager.t -> 'a t Apron.Manager.t = "camlidl_polkaGrid_ap_pkgrid_manager_alloc" external manager_decompose : 'a t Apron.Manager.t -> 'a Polka.t Apron.Manager.t * Ppl.grid Ppl.t Apron.Manager.t = "camlidl_polkaGrid_ap_pkgrid_manager_decompose" external decompose : 'a t Apron.Abstract0.t -> 'a Polka.t Apron.Abstract0.t * Ppl.grid Ppl.t Apron.Abstract0.t = "camlidl_polkaGrid_ap_pkgrid_decompose" external compose : 'a t Apron.Manager.t -> 'a Polka.t Apron.Abstract0.t -> Ppl.grid Ppl.t Apron.Abstract0.t -> 'a t Apron.Abstract0.t = "camlidl_polkaGrid_ap_pkgrid_compose" let manager_is_polkagrid man = let str = Apron.Manager.get_library man in let str = try String.sub str 0 9 with Invalid_argument _ -> "" in (String.compare str "polkagrid")==0 let manager_of_polkagrid (man:'a t Apron.Manager.t) : 'b Apron.Manager.t = Obj.magic man let manager_to_polkagrid (man:'a Apron.Manager.t) : 'b t Apron.Manager.t = if manager_is_polkagrid man then Obj.magic man else failwith "PolkaGrid.to_polkagrid: the argument manager is not a polkagrid manager" module Abstract0 = struct let is_polkagrid abs = manager_is_polkagrid (Apron.Abstract0.manager abs) let of_polkagrid (abs: 'a t Apron.Abstract0.t) : 'b Apron.Abstract0.t = Obj.magic abs let to_polkagrid (abs:'a Apron.Abstract0.t) : 'b t Apron.Abstract0.t = if is_polkagrid abs then Obj.magic abs else failwith "PolkaGrid.Abstract0.to_polkagrid: the argument value is not a polkagrid value" end module Abstract1 = struct let is_polkagrid abs = manager_is_polkagrid (Apron.Abstract1.manager abs) let of_polkagrid (abs: 'a t Apron.Abstract1.t) : 'b Apron.Abstract1.t = Obj.magic abs let to_polkagrid (abs:'a Apron.Abstract1.t) : 'b t Apron.Abstract1.t = if is_polkagrid abs then Obj.magic abs else failwith "PolkaGrid.Abstract1.to_polkagrid: the argument value is not a polkagrid value" end apron-dist-0.9.10/apron/products/macros.m40000777014525101416610000000000011252510553024357 2../mlapronidl/macros.m4ustar bjeannetpopartapron-dist-0.9.10/apron/products/COPYING0000640014525101416610000000021610664570161017567 0ustar bjeannetpopart - The files ap_pkgrid.c, ap_pkgrid.h, ap_pkgrid.texi, polkaGrid.idl are released under the GPL license, as they relies on the PPL library. apron-dist-0.9.10/apron/products/dim.idl0000777014525101416610000000000011252510553023611 2../mlapronidl/dim.idlustar bjeannetpopartapron-dist-0.9.10/apron/products/polkaGrid.idl0000640014525101416610000001555011251675047021153 0ustar bjeannetpopart/* -*- mode: c -*- */ quote(C,"#include \"ap_global0.h\"") quote(C,"#include \"apron_caml.h\"") quote(C,"#include \"ap_pkgrid.h\"") import "manager.idl"; import "abstract0.idl"; quote(MLMLI,"(** Reduced product of NewPolka polyhedra and PPL grids *)") quote(MLMLI," (** Type of abstract values, where ['a] is [Polka.loose] or [Polka.strict]. *)\n\ type 'a t ") quote(MLI,"(** Create a PolkaGrid manager from a (loose or strict) polka manager, and a PPL grid manager *)") ap_manager_ptr ap_pkgrid_manager_alloc(ap_manager_ptr manpk, ap_manager_ptr manpplgrid) quote(call," _res = ap_pkgrid_manager_alloc(manpk,manpplgrid); if (_res==NULL) caml_failwith(\"PolkaGrid.manager_alloc: the provided polka manager is most probably an equalities polka manager\"); { ap_exc_t i; for (i=1; iinternal; manpk = ap_manager_copy(intern->tmanagers[0]); manpplgrid = ap_manager_copy(intern->tmanagers[1]); "); quote(MLI,"(** Decompose an abstract value *)") void ap_pkgrid_decompose(ap_abstract0_ptr abs, [out]ap_abstract0_ptr abspk, [out]ap_abstract0_ptr abspplgrid) quote(call," { ap_reducedproduct_internal_t* intern = (ap_reducedproduct_internal_t*)abs->man->internal; ap_manager_t* manpk = intern->tmanagers[0]; ap_manager_t* manpplgrid = intern->tmanagers[1]; void** res = ap_reducedproduct_decompose(abs->man,false,(ap_reducedproduct_t*)abs->value); abspk = (ap_abstract0_t*)malloc(sizeof(ap_abstract0_t)); abspk->man = ap_manager_copy(manpk); abspk->value = res[0]; abspplgrid = (ap_abstract0_t*)malloc(sizeof(ap_abstract0_t)); abspplgrid->man = ap_manager_copy(manpplgrid); abspplgrid->value = res[1]; free(res); } ") quote(dealloc,"I0_CHECK_EXC(abs->man)"); quote(MLI,"(** Compose an abstract value *)") ap_abstract0_ptr ap_pkgrid_compose(ap_manager_ptr man, ap_abstract0_ptr abspk, ap_abstract0_ptr abspplgrid) quote(call," { ap_reducedproduct_internal_t* intern = (ap_reducedproduct_internal_t*)man->internal; ap_manager_t* manpk = intern->tmanagers[0]; ap_manager_t* manpplgrid = intern->tmanagers[1]; void* tabs[2]; tabs[0] = abspk->value; tabs[1] = abspplgrid->value; ap_reducedproduct_t* prod = ap_reducedproduct_compose(man,false,tabs); _res = (ap_abstract0_t*)malloc(sizeof(ap_abstract0_t)); _res->man = ap_manager_copy(man); _res->value = prod; } ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** {2 Type conversions} *) val manager_is_polkagrid : 'a Apron.Manager.t -> bool (** Return [true] iff the argument manager is a polkagrid manager *) val manager_of_polkagrid : 'a t Apron.Manager.t -> 'b Apron.Manager.t (** Makes a polkagrid manager generic *) val manager_to_polkagrid : 'a Apron.Manager.t -> 'b t Apron.Manager.t (** Instanciate the type of a polkagrid manager. Raises [Failure] if the argument manager is not a polkagrid manager *) module Abstract0 : sig val is_polkagrid : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument manager is a polkagrid value *) val of_polkagrid : 'a t Apron.Abstract0.t -> 'b Apron.Abstract0.t (** Makes a polkagrid value generic *) val to_polkagrid : 'a Apron.Abstract0.t -> 'b t Apron.Abstract0.t (** Instanciate the type of a polkagrid value. Raises [Failure] if the argument manager is not a polkagrid manager *) end module Abstract1 : sig val is_polkagrid : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument manager is a polkagrid value *) val of_polkagrid : 'a t Apron.Abstract1.t -> 'b Apron.Abstract1.t (** Makes a polkagrid value generic *) val to_polkagrid : 'a Apron.Abstract1.t -> 'b t Apron.Abstract1.t (** Instanciate the type of a polkagrid value. Raises [Failure] if the argument manager is not a polkagrid manager *) end ") quote(ML," let manager_is_polkagrid man = let str = Apron.Manager.get_library man in let str = try String.sub str 0 9 with Invalid_argument _ -> \"\" in (String.compare str \"polkagrid\")==0 let manager_of_polkagrid (man:'a t Apron.Manager.t) : 'b Apron.Manager.t = Obj.magic man let manager_to_polkagrid (man:'a Apron.Manager.t) : 'b t Apron.Manager.t = if manager_is_polkagrid man then Obj.magic man else failwith \"PolkaGrid.to_polkagrid: the argument manager is not a polkagrid manager\" module Abstract0 = struct let is_polkagrid abs = manager_is_polkagrid (Apron.Abstract0.manager abs) let of_polkagrid (abs: 'a t Apron.Abstract0.t) : 'b Apron.Abstract0.t = Obj.magic abs let to_polkagrid (abs:'a Apron.Abstract0.t) : 'b t Apron.Abstract0.t = if is_polkagrid abs then Obj.magic abs else failwith \"PolkaGrid.Abstract0.to_polkagrid: the argument value is not a polkagrid value\" end module Abstract1 = struct let is_polkagrid abs = manager_is_polkagrid (Apron.Abstract1.manager abs) let of_polkagrid (abs: 'a t Apron.Abstract1.t) : 'b Apron.Abstract1.t = Obj.magic abs let to_polkagrid (abs:'a Apron.Abstract1.t) : 'b t Apron.Abstract1.t = if is_polkagrid abs then Obj.magic abs else failwith \"PolkaGrid.Abstract1.to_polkagrid: the argument value is not a polkagrid value\" end ") quote(MLI,"\n(** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. Do not forget the [-cc \"g++\"] option: PPL is a C++ library which requires a C++ linker. {3 Bytecode compilation} {[ocamlc -cc \"g++\"-I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma polkaMPQ.cma ppl.cma polkaGrid.cma mlexample.ml]} {[ocamlc -cc \"g++\" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \\ bigarray.cma gmp.cma apron.cma polkaMPQ.cma ppl.cma polkaGrid.cma ocamlc -cc \"g++\" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma polkaMPQ.cma ppl.cma polkaGrid.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -cc \"g++\" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa polkaMPQ.cmxa ppl.cmxa polkaGrid.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -cc \"g++\" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa polkaMPQ.cmxa ppl.cmxa polkaGrid.cmxa mlexample.ml \\ -cclib \"-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib -L$PPL_PREFIX/lib \\ -lpolkaGrid_caml_debug -lap_pkgrid_debug \\ -lpolkaMPQ_caml_debug -lpolkaMPQ_debug \\ -lap_ppl_caml_debug -lap_ppl_debug -lppl -lgmpxx \\ -lapron_caml_debug -lapron_debug \\ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP_PREFIX/lib -lgmp \\ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \\ -lbigarray\" ]} *)") apron-dist-0.9.10/apron/products/manager.idl0000777014525101416610000000000011252510553025313 2../mlapronidl/manager.idlustar bjeannetpopartapron-dist-0.9.10/apron/products/generator0.idl0000777014525101416610000000000011252510553026403 2../mlapronidl/generator0.idlustar bjeannetpopartapron-dist-0.9.10/apron/products/coeff.idl0000777014525101416610000000000011252510553024433 2../mlapronidl/coeff.idlustar bjeannetpopartapron-dist-0.9.10/apron/products/Makefile0000640014525101416610000001527411252236624020203 0ustar bjeannetpopartinclude ../Makefile.config PREFIX = $(APRON_PREFIX) SRCDIR = $(shell pwd) #--------------------------------------- # Flags #--------------------------------------- # Use ICFLAGS to specify machine-independent compilation flags. ICFLAGS = \ -I$(MLGMPIDL_PREFIX)/include \ -I../apron \ -I../num -I../itv \ -I../newpolka \ -I../ppl \ -I../mlapronidl \ -I$(GMP_PREFIX)/include -I$(MPFR_PREFIX)/include \ -I$(CAMLIDL_PREFIX)/lib/ocaml -I$(CAML_PREFIX)/lib/ocaml # Caml OCAMLINC = -I $(MLGMPIDL_PREFIX)/lib -I ../mlapronidl -I ../newpolka -I ../ppl #--------------------------------------- # Files #--------------------------------------- CCMODULES = ap_pkgrid CCSRC = $(CCMODULES:%=%.h) $(CCMODULES:%=%.c) CCINC_TO_INSTALL = ap_pkgrid.h CCBIN_TO_INSTALL = CCLIB_TO_INSTALL = \ libap_pkgrid.a libap_pkgrid_debug.a \ libap_pkgrid.so libap_pkgrid_debug.so \ polkaGrid.mli polkaGrid.ml \ polkaGrid.cmi polkaGrid.cmx polkaGrid.cma polkaGrid.cmxa polkaGrid.a \ libpolkaGrid_caml.a libpolkaGrid_caml_debug.a \ libpolkaGrid_caml.so libpolkaGrid_caml_debug.so #--------------------------------------- # Rules #--------------------------------------- all: libap_pkgrid.a libap_pkgrid_debug.a ifneq ($(HAS_SHARED),) all: libap_pkgrid.so libap_pkgrid_debug.so endif ml: polkaGrid.mli polkaGrid.ml polkaGrid.cmi polkaGrid.cmx polkaGrid.cma polkaGrid.cmxa libpolkaGrid_caml.a libpolkaGrid_caml_debug.a ifneq ($(HAS_SHARED),) ml: libpolkaGrid_caml.so libpolkaGrid_caml_debug.so dllpolkaGrid_caml.so dllpolkaGrid_caml_debug.so endif mlexample%.byte: mlexample.ml $(APRON_PREFIX)/lib/polka%.cma $(APRON_PREFIX)/lib/ppl.cma polkaGrid.cma $(OCAMLC) $(OCAMLFLAGS) -I $(MLGMPIDL_INSTALL)/lib -I $(APRON_PREFIX)/lib -o $@ bigarray.cma gmp.cma apron.cma polka%.cma ppl.cma polkaGrid.cma $< mlexample%.opt: mlexample.ml $(APRON_PREFIX)/lib/polka%.cmxa $(APRON_PREFIX)/lib/ppl.cmxa polkaGrid.cmxa $(OCAMLOPT) $(OCAMLOPTFLAGS) -I $(MLGMPIDL_INSTALL)/lib -I $(APRON_PREFIX)/lib -o $@ bigarray.cmxa gmp.cmxa apron.cmxa polka%.cmxa ppl.cmxa polkaGrid.cmxa $< clean: /bin/rm -f *.[ao] *.so *.cm[xiao] *.cmxa /bin/rm -f *.?.tex *.log *.aux *.bbl *.blg *.toc *.dvi *.ps *.pstex* mostlyclean: clean /bin/rm -fr scalar.idl interval.idl coeff.idl dim.idl linexpr0.idl lincons0.idl generator0.idl texpr0.idl tcons0.idl manager.idl abstract0.idl macros.m4 sedscript_c /bin/rm -f polkaGrid.ml polkaGrid.mli polkaGrid_caml.c install: $(INSTALLd) $(PREFIX)/include $(PREFIX)/lib $(INSTALL) $(CCINC_TO_INSTALL) $(PREFIX)/include for i in $(CCLIB_TO_INSTALL); do \ if test -f $$i; then $(INSTALL) $$i $(PREFIX)/lib; fi; \ done for i in dllpolkaGrid_caml*.so; do \ if test -f $$i; then cp -f -d $$i $(PREFIX)/lib; fi; \ done uninstall: for i in $(CCINC_TO_INSTALL); do /bin/rm -f $(PREFIX)/include/$$i; done for i in $(CCLIB_TO_INSTALL); do /bin/rm -f $(PREFIX)/lib/$$i; done for i in dllpolkaGrid_caml*.so; do /bin/rm -f $(PREFIX)/lib/$$i; done for i in $(CCBIN_TO_INSTALL); do /bin/rm -f $(PREFIX)/bin/$$i; done distclean: uninstall /bin/rm -f Makefile.depend dist: $(CCSRC) ap_pkgrid.texi sedscript_caml polkaGrid.idl polkaGrid.ml polkaGrid.mli polkaGrid_caml.c Makefile COPYING README (cd ..; tar zcvf products.tgz $(^:%=products/%)) #--------------------------------------- # IMPLICIT RULES AND DEPENDENCIES #--------------------------------------- .SUFFIXES: .tex .c .h .a .o #----------------------------------- # C part #----------------------------------- libap_pkgrid.a: ap_pkgrid.o $(AR) rcs $@ $^ $(RANLIB) $@ libap_pkgrid_debug.a: ap_pkgrid_debug.o $(AR) rcs $@ $^ $(RANLIB) $@ libap_pkgrid.so: ap_pkgrid.o $(CXX) $(CXXFLAGS) -shared -o $@ $^ libap_pkgrid_debug.so: ap_pkgrid_debug.o $(CXX) $(CXXFLAGS_DEBUG) -shared -o $@ $^ #--------------------------------------- # C rules #--------------------------------------- libpolkaGrid_caml.a: polkaGrid_caml.o $(AR) rcs $@ $^ $(RANLIB) $@ libpolkaGrid_caml_debug.a: polkaGrid_caml_debug.o $(AR) rcs $@ $^ $(RANLIB) $@ libpolkaGrid_caml.so: polkaGrid_caml.o libap_pkgrid.so $(CXX) $(CXXFLAGS) -shared -o $@ $< -lap_pkgrid -L. -Wl-rpath,$(APRON_PREFIX)/lib libpolkaGrid_caml_debug.so: polkaGrid_caml_debug.o libap_pkgrid_debug.so $(CXX) $(CXXFLAGS) -shared -o $@ $< -lap_pkgrid_debug -L. -Wl-rpath,$(APRON_PREFIX)/lib dllpolkaGrid_caml.so: libpolkaGrid_caml.so ln -s -f $^ $@ dllpolkaGrid_caml_debug.so: libpolkaGrid_caml_debug.so ln -s -f $^ $@ #--------------------------------------- # ML rules #--------------------------------------- polkaGrid.cma: polkaGrid.cmo libpolkaGrid_caml.a libap_pkgrid.a $(OCAMLMKLIB) -ocamlc "$(OCAMLC) -cc $(CXX)" -verbose -o polkaGrid -oc ap_polkaGrid_caml polkaGrid.cmo -lap_polkaGrid -L$(APRON_PREFIX)/lib -Wl,-rpath,$(APRON_PREFIX)/lib polkaGrid.cmxa: polkaGrid.cmx libpolkaGrid_caml.a libap_pkgrid.a $(OCAMLMKLIB) -ocamlopt "$(OCAMLOPT) -cc $(CXX)" -verbose -o polkaGrid -oc ap_polkaGrid_caml polkaGrid.cmx -lap_polkaGrid -L$(APRON_PREFIX)/lib -Wl,-rpath,$(APRON_PREFIX)/lib #--------------------------------------- # IDL rules #--------------------------------------- scalar.idl: ../mlapronidl/scalar.idl ln -s $< $@ interval.idl: ../mlapronidl/interval.idl ln -s $< $@ coeff.idl: ../mlapronidl/coeff.idl ln -s $< $@ dim.idl: ../mlapronidl/dim.idl ln -s $< $@ linexpr0.idl: ../mlapronidl/linexpr0.idl ln -s $< $@ lincons0.idl: ../mlapronidl/lincons0.idl ln -s $< $@ generator0.idl: ../mlapronidl/generator0.idl ln -s $< $@ texpr0.idl: ../mlapronidl/texpr0.idl ln -s $< $@ tcons0.idl: ../mlapronidl/tcons0.idl ln -s $< $@ manager.idl: ../mlapronidl/manager.idl ln -s $< $@ abstract0.idl: ../mlapronidl/abstract0.idl ln -s $< $@ macros.m4: ../mlapronidl/macros.m4 ln -s $< $@ sedscript_c: ../mlapronidl/sedscript_c ln -s $< $@ # generates polkaGrid.ml, polkaGrid.mli, polkaGrid_caml.c from polkaGrid.idl rebuild: polkaGrid.idl macros.m4 sedscript_c scalar.idl interval.idl coeff.idl dim.idl linexpr0.idl lincons0.idl generator0.idl texpr0.idl tcons0.idl manager.idl abstract0.idl mkdir -p tmp cp polkaGrid.idl tmp/polkaGrid.idl $(CAMLIDL) -no-include -prepro "$(M4) --prefix-builtins macros.m4" tmp/polkaGrid.idl $(SED) -f sedscript_c tmp/polkaGrid_stubs.c >polkaGrid_caml.c $(SED) -f sedscript_caml tmp/polkaGrid.ml >polkaGrid.ml $(SED) -f sedscript_caml tmp/polkaGrid.mli >polkaGrid.mli #--------------------------------------- # ML generic rules #--------------------------------------- %.cmi: %.mli $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -c $< %.cmo: %.ml %.cmi $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -c $< %.cmx: %.ml %.cmi $(OCAMLOPT) $(OCAMLOPTFLAGS) $(OCAMLINC) -c $< #--------------------------------------- # C generic rules #--------------------------------------- %.o: %.c $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_MPQ -c -o $@ $< %_debug.o: %.c $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_MPQ -c -o $@ $< apron-dist-0.9.10/apron/products/ap_pkgrid.c0000640014525101416610000001430511251675047020646 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_pkgrid.c: reduced product of NewPolka polyhedra and PPL grids */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include "ap_global0.h" #include "ap_reducedproduct.h" #include "ap_reducedproduct.h" #include "pk.h" #include "pk_internal.h" #include "pk_matrix.h" #include "pk_satmat.h" #include "pk_representation.h" #include "pk_user.h" #include "ppl_grid.h" void ap_pkgrid_reduce(ap_manager_t* manager, ap_reducedproduct_t* a) { size_t i,index; ap_reducedproduct_internal_t* intern = (ap_reducedproduct_internal_t*)manager->internal; ap_manager_t* manpoly = intern->tmanagers[0]; ap_manager_t* mangrid = intern->tmanagers[1]; pk_t* poly = (pk_t*)a->p[0]; struct ppl_grid* grid = a->p[1]; ap_lincons0_array_t array,array2; ap_interval_t* interval; mpq_t quotient,aprime,diff,prod; int cmp; ap_dimension_t dimension; mpq_init(diff); mpq_init(prod); mpq_init(quotient); mpq_init(aprime); dimension = pk_dimension(manpoly,poly); /* 1. Reduction from poly to grid: one add equalities of poly to grid */ pk_canonicalize(manpoly,poly); if (pk_is_bottom(manpoly,poly)){ ap_pkgrid_reduce_exit1: ap_ppl_grid_free(mangrid,grid); grid = ap_ppl_grid_bottom(mangrid, dimension.intdim,dimension.realdim); goto ap_pkgrid_reduce_exit; } assert(poly->C->_sorted); if (poly->nbeq>0){ array = ap_lincons0_array_make(poly->nbeq); for (i=0; inbeq; i++){ array.p[i] = lincons0_of_vector((pk_internal_t*)(manpoly->internal), poly->C->p[i],poly->C->nbcolumns); } grid = ap_ppl_grid_meet_lincons_array(mangrid,true,grid,&array); ap_lincons0_array_clear(&array); if (ap_ppl_grid_is_bottom(mangrid,grid)){ ap_pkgrid_reduce_exit2: pk_free(manpoly,poly); poly = pk_bottom(manpoly, dimension.intdim,dimension.realdim); goto ap_pkgrid_reduce_exit; } } /* 2. Reduction from grid to poly: for each equality e=0 mod m, m>0, compute [a,b] = range(e) in poly if b-a > m, nothing to do; otherwise, compute [a',b'] where a' = a - sup(a/m) m, b' = b - sup(a/m) m (we have -minf) || ap_scalar_infty(interval->sup)){ ap_interval_free(interval); continue; } assert(interval->inf->discr==AP_SCALAR_MPQ && interval->sup->discr==AP_SCALAR_MPQ); assert(cons.scalar->discr==AP_SCALAR_MPQ); mpq_sub(diff, interval->sup->val.mpq, interval->inf->val.mpq); cmp = mpq_cmp(diff,cons.scalar->val.mpq); if (cmp<=0){ /* b-a<=m */ mpq_div(quotient,interval->inf->val.mpq,cons.scalar->val.mpq); mpz_cdiv_q(mpq_numref(quotient), mpq_numref(quotient), mpq_denref(quotient)); mpz_set_si(mpq_denref(quotient),1); mpq_mul(prod,quotient,cons.scalar->val.mpq); mpq_sub(aprime,interval->inf->val.mpq,prod); if (cmp==0 && mpq_sgn(aprime)!=0){ goto ap_pkgrid_reduce_red; } else if (cmp<0){ mpq_add(diff,diff,aprime); if (mpq_sgn(diff)>=0){ ap_pkgrid_reduce_red: assert(cons.linexpr0->cst.discr==AP_COEFF_SCALAR && cons.linexpr0->cst.val.scalar->discr==AP_SCALAR_MPQ); array2.p[index] = ap_lincons0_copy(&cons); cons = array2.p[index]; index++; mpq_add(cons.linexpr0->cst.val.scalar->val.mpq, cons.linexpr0->cst.val.scalar->val.mpq, prod); cons.constyp = AP_CONS_EQ; } else { ap_lincons0_array_clear(&array); ap_lincons0_array_clear(&array2); ap_ppl_grid_free(mangrid,grid); pk_free(manpoly,poly); grid = ap_ppl_grid_bottom(mangrid, dimension.intdim,dimension.realdim); poly = pk_bottom(manpoly, dimension.intdim,dimension.realdim); ap_interval_free(interval); goto ap_pkgrid_reduce_exit; } } } ap_interval_free(interval); break; default: break; } } array2.size = index; poly = pk_meet_lincons_array(manpoly,true,poly,&array2); ap_lincons0_array_clear(&array); ap_lincons0_array_clear(&array2); ap_pkgrid_reduce_exit: mpq_clear(diff); mpq_clear(prod); mpq_clear(quotient); mpq_clear(aprime); a->p[0] = poly; a->p[1] = grid; } void ap_pkgrid_approximate(ap_manager_t* manager, ap_reducedproduct_t* a, int n) { ap_reducedproduct_internal_t* intern = (ap_reducedproduct_internal_t*)manager->internal; ap_manager_t* manpoly = intern->tmanagers[0]; ap_manager_t* mangrid = intern->tmanagers[1]; pk_t* poly = (pk_t*)a->p[0]; struct ppl_grid* grid = a->p[1]; pk_approximate(manpoly,poly,n); ap_pkgrid_reduce(manager,a); } ap_manager_t* ap_pkgrid_manager_alloc(ap_manager_t* manpk, ap_manager_t* manpplgrid) { ap_manager_t* tmanagers[2]; bool strict; strict = (strcmp(manpk->library,"polka, strict mode")==0); if ( !(strcmp(manpk->library,"polka, loose mode")==0 || strict) || !strcmp(manpplgrid->library,"PPL::Grid") ) return NULL; tmanagers[0] = manpk; tmanagers[1] = manpplgrid; char* library = strict ? "pkgrid: polka, strict mode and PPL::Grid" : "pkgrid: polka, loose mode and PPL::Grid"; ap_manager_t* man = ap_reducedproduct_manager_alloc(library, tmanagers,2, &ap_pkgrid_reduce, ap_pkgrid_approximate); return man; } apron-dist-0.9.10/apron/products/ap_pkgrid.h0000640014525101416610000000251011251675047020646 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_poly_grid.h: reduced product of NewPolka polyhedra and PPL grids */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _AP_PKGRID_H_ #define _AP_PKGRID_H_ #include "ap_reducedproduct.h" #ifdef __cplusplus extern "C" { #endif ap_manager_t* ap_pkgrid_manager_alloc(ap_manager_t* manpk, ap_manager_t* manpplgrid); /* Allocates a product managaer (see ap_reducedproduct.h header file Returns NULL if manpk is not a polka manager for loose or strict polyhedra, or if manpplgrid is not a PPL manager for grids. The given managers are copied (reference count incremented) in the result. So, if the argument managers are not needed any more, they should be freed with ap_manager_free. */ void ap_pkgrid_reduce(ap_manager_t* manager, ap_reducedproduct_t* a); /* Reduction function between the two domains */ void ap_pkgrid_approximate(ap_manager_t* manager, ap_reducedproduct_t* a, int n); /* Approximation function. It consists in apply approximate to the Polka polyhedron, with the argument n. */ #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/products/linexpr0.idl0000777014525101416610000000000011252510553025571 2../mlapronidl/linexpr0.idlustar bjeannetpopartapron-dist-0.9.10/apron/products/polkaGrid.mli0000640014525101416610000000764711252216517021166 0ustar bjeannetpopart(* File generated from polkaGrid.idl *) (** Reduced product of NewPolka polyhedra and PPL grids *) (** Type of abstract values, where ['a] is [Polka.loose] or [Polka.strict]. *) type 'a t (** Create a PolkaGrid manager from a (loose or strict) polka manager, and a PPL grid manager *) external manager_alloc : 'a Polka.t Apron.Manager.t -> Ppl.grid Ppl.t Apron.Manager.t -> 'a t Apron.Manager.t = "camlidl_polkaGrid_ap_pkgrid_manager_alloc" (** Decompose the manager *) external manager_decompose : 'a t Apron.Manager.t -> 'a Polka.t Apron.Manager.t * Ppl.grid Ppl.t Apron.Manager.t = "camlidl_polkaGrid_ap_pkgrid_manager_decompose" (** Decompose an abstract value *) external decompose : 'a t Apron.Abstract0.t -> 'a Polka.t Apron.Abstract0.t * Ppl.grid Ppl.t Apron.Abstract0.t = "camlidl_polkaGrid_ap_pkgrid_decompose" (** Compose an abstract value *) external compose : 'a t Apron.Manager.t -> 'a Polka.t Apron.Abstract0.t -> Ppl.grid Ppl.t Apron.Abstract0.t -> 'a t Apron.Abstract0.t = "camlidl_polkaGrid_ap_pkgrid_compose" (** {2 Type conversions} *) val manager_is_polkagrid : 'a Apron.Manager.t -> bool (** Return [true] iff the argument manager is a polkagrid manager *) val manager_of_polkagrid : 'a t Apron.Manager.t -> 'b Apron.Manager.t (** Makes a polkagrid manager generic *) val manager_to_polkagrid : 'a Apron.Manager.t -> 'b t Apron.Manager.t (** Instanciate the type of a polkagrid manager. Raises [Failure] if the argument manager is not a polkagrid manager *) module Abstract0 : sig val is_polkagrid : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument manager is a polkagrid value *) val of_polkagrid : 'a t Apron.Abstract0.t -> 'b Apron.Abstract0.t (** Makes a polkagrid value generic *) val to_polkagrid : 'a Apron.Abstract0.t -> 'b t Apron.Abstract0.t (** Instanciate the type of a polkagrid value. Raises [Failure] if the argument manager is not a polkagrid manager *) end module Abstract1 : sig val is_polkagrid : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument manager is a polkagrid value *) val of_polkagrid : 'a t Apron.Abstract1.t -> 'b Apron.Abstract1.t (** Makes a polkagrid value generic *) val to_polkagrid : 'a Apron.Abstract1.t -> 'b t Apron.Abstract1.t (** Instanciate the type of a polkagrid value. Raises [Failure] if the argument manager is not a polkagrid manager *) end (** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. Do not forget the [-cc "g++"] option: PPL is a C++ library which requires a C++ linker. {3 Bytecode compilation} {[ocamlc -cc "g++"-I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \ bigarray.cma gmp.cma apron.cma polkaMPQ.cma ppl.cma polkaGrid.cma mlexample.ml]} {[ocamlc -cc "g++" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \ bigarray.cma gmp.cma apron.cma polkaMPQ.cma ppl.cma polkaGrid.cma ocamlc -cc "g++" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \ bigarray.cma gmp.cma apron.cma polkaMPQ.cma ppl.cma polkaGrid.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -cc "g++" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa polkaMPQ.cmxa ppl.cmxa polkaGrid.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -cc "g++" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa polkaMPQ.cmxa ppl.cmxa polkaGrid.cmxa mlexample.ml \ -cclib "-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib -L$PPL_PREFIX/lib \ -lpolkaGrid_caml_debug -lap_pkgrid_debug \ -lpolkaMPQ_caml_debug -lpolkaMPQ_debug \ -lap_ppl_caml_debug -lap_ppl_debug -lppl -lgmpxx \ -lapron_caml_debug -lapron_debug \ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP_PREFIX/lib -lgmp \ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \ -lbigarray" ]} *) apron-dist-0.9.10/apron/products/mlexample.ml0000640014525101416610000001354711251675321021062 0ustar bjeannetpopart(* This file is part of the APRON Library, released under LGPL license. (use of PPL) Please read the COPYING file packaged in the distribution. *) (* with default setting (if dynamic libraries): ocaml -I $MLGMPIDL_INSTALL/lib -I $APRON_INSTALL/lib #load "bigarray.cma";; #load "gmp.cma";; #load "apron.cma";; #load "polkaMPQ.cma";; #load "ppl.cma";; #load "polkaGrid.cma";; #install_printer Apron.Linexpr1.print;; #install_printer Apron.Texpr1.print;; #install_printer Apron.Lincons1.print;; #install_printer Apron.Generator1.print;; #install_printer Apron.Abstract1.print;; let environment_print fmt x = Apron.Environment.print fmt x;; let lincons1_array_print fmt x = Apron.Lincons1.array_print fmt x;; let generator1_array_print fmt x = Apron.Generator1.array_print fmt x;; #install_printer Apron.Var.print;; #install_printer environment_print;; #install_printer lincons1_array_print;; #install_printer generator1_array_print;; *) open Apron;; open Mpqf;; open Format;; let print_array = Abstract0.print_array;; let lincons1_array_print fmt x = Lincons1.array_print fmt x ;; let generator1_array_print fmt x = Generator1.array_print fmt x ;; let manpolka = Polka.manager_alloc_loose ();; let manpplgrid = Ppl.manager_alloc_grid ();; let man = PolkaGrid.manager_alloc manpolka manpplgrid;; let var_x = Var.of_string "x";; let var_y = Var.of_string "y";; let var_z = Var.of_string "z";; let var_w = Var.of_string "w";; let var_u = Var.of_string "u";; let var_v = Var.of_string "v";; let var_a = Var.of_string "a";; let var_b = Var.of_string "b";; let ex1 (man:'a Manager.t) : 'a Abstract1.t = printf "Using Library: %s, version %s@." (Manager.get_library man) (Manager.get_version man); let env = Environment.make [|var_x; var_y; var_z; var_w|] [|var_u; var_v; var_a; var_b|] in let env2 = Environment.make [|var_x; var_y; var_z; var_w|] [||] in printf "env=%a@.env2=%a@." (fun x -> Environment.print x) env (fun x -> Environment.print x) env2 ; (* Creation of abstract value 1/2x+2/3y=1, [1,2]<=z+2w<=4, 0<=u<=5 *) let tab = Parser.lincons1_of_lstring env ["1/2x+2/3y=1"; "[1;2]<=z+2w";"z+2w<=4"; "0<=u";"u<=5"] in printf "tab = %a@." lincons1_array_print tab; let abs = Abstract1.of_lincons_array man env tab in printf "abs=%a@." Abstract1.print abs; (* Extraction (we first extract values for existing constraints, then for dimensions) *) let box = Abstract1.to_box man abs in printf "box=%a@." (print_array Interval.print) box.Abstract1.interval_array; for i=0 to 4 do let expr = Lincons1.get_linexpr1 (Lincons1.array_get tab i) in let box = Abstract1.bound_linexpr man abs expr in printf "Bound of %a = %a@." Linexpr1.print expr Interval.print box; done; (* 2. dimensions *) (* 3. of box *) let abs2 = Abstract1.of_box man env [|var_x; var_y; var_z; var_w; var_u; var_v; var_a; var_b|] box.Abstract1.interval_array in printf "abs2=%a@." Abstract1.print abs2; (* 4. Tests top and bottom *) let abs3 = Abstract1.bottom man env in printf "abs3=%a@.is_bottom(abs3)=%b@." Abstract1.print abs3 (Abstract1.is_bottom man abs3); printf "abs=%a@." Abstract1.print abs; let p2 = Abstract1.expand man abs var_y [|Var.of_string "y1"; Var.of_string "y2"|] in printf "p2=expand(abs,y,[y1,y2]))=%a@." Abstract1.print p2; let p2 = Abstract1.expand man abs var_u [|Var.of_string "u1"; Var.of_string "u2"|] in printf "p2=expand(abs,u,[u1,u2]))=%a@." Abstract1.print p2; (* Tree expressions *) let texpr = Parser.texpr1_of_string env "a + (x*y*y/sqrt(b))" in let abs2 = Abstract1.assign_texpr man abs var_u texpr None in printf "abs2=%a@." Abstract1.print abs2; abs ;; let ex2 (man:'a Manager.t) = let env = Environment.make [||] [|var_x; var_y; var_z|] in (* Creation of abstract value 5<=x<=14, 4<=y<=12, z=0 *) let abs1 = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int 5 14; Interval.of_int 4 12; Interval.of_int 0 0; |] in let abs2 = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int 3 12; Interval.of_int 5 13; Interval.of_int 1 1; |] in let abs3 = Abstract1.join man abs1 abs2 in abs3 ;; (* Comparing join of two different assignements and assignement by the "join" of expressions *) let ex3 (man:'a Manager.t) = let env = Environment.make [||] [|var_x; var_y; var_z|] in (* Creation of abstract value -3<=x<=-2, 10<=y<=12, -1<=z<=1 *) let abs = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int (-3) (-2); Interval.of_int 10 12; Interval.of_int (-1) (1) |] in (* Creation of linear expressions *) let linexpr1 = Parser.linexpr1_of_string env "z+x+2y" in let linexpr2 = Parser.linexpr1_of_string env "z+2x+y" in let abs1 = Abstract1.assign_linexpr man abs var_z linexpr1 None in let abs2 = Abstract1.assign_linexpr man abs var_z linexpr2 None in let res1 = Abstract1.join man abs1 abs2 in printf "abs=%a@.abs1=%a@.abs2=%a@.res1=%a@." Abstract1.print abs Abstract1.print abs1 Abstract1.print abs2 Abstract1.print res1; (* Creation of linear expression [1,2]y and [1,2]z *) let linexpr = Parser.linexpr1_of_string env "z + [1;2]x + [1;2]y" in let res2 = Abstract1.assign_linexpr man abs var_z linexpr None in printf "res2=%a@." Abstract1.print res2 ; let abs1 = Abstract1.substitute_linexpr man res1 var_z linexpr1 None in let abs2 = Abstract1.substitute_linexpr man res1 var_z linexpr2 None in let res1 = Abstract1.join man abs1 abs2 in printf "abs1=%a@.abs2=%a@.res1=%a@." Abstract1.print abs1 Abstract1.print abs2 Abstract1.print res1 ; let res2 = Abstract1.substitute_linexpr man res2 var_z linexpr None in printf "res2=%a@." Abstract1.print res2 ; res1 ;; let abs1 = ex1 man;; let abs2 = ex2 man;; let abs3 = ex3 man;; apron-dist-0.9.10/apron/products/tcons0.idl0000777014525101416610000000000011252510553024703 2../mlapronidl/tcons0.idlustar bjeannetpopartapron-dist-0.9.10/apron/products/sedscript_c0000777014525101416610000000000011252510553025555 2../mlapronidl/sedscript_custar bjeannetpopartapron-dist-0.9.10/apron/products/README0000640014525101416610000000245611251675321017421 0ustar bjeannetpopart # This file is part of the APRON Library, released under LGPL # license. # Please read the COPYING file packaged in the distribution This package contains various products built upon APRON base abstract domains. It contais currently: - the reduced product of NewPolka convex polyhedra and PPL linear congruences It includes both the C interface and the OCaml interface to APRON. REQUIREMENTS ============ For the C interface: GMP library (tested with version 4.0 and up) MPFR library (tested with version 2.2.0 and up) NUM "library" (a set of header files) ITV library APRON library For the OCaml interface, in addition: OCaml 3.0 or up (tested with 3.09) Camlidl (tested with 1.05) MLGMPIDL package MLAPRONIDL package INSTALLATION ============ 1. C Library ---------- type 'make', and then 'make install' The library is named libap_pkgrid.a (and libap_pkgrid_debug.a). For use via APRON, the include files to consider is ap_pkgrid.h. 2. OCaml Library ---------------- type 'make ml', and then 'make install' The C part of the library is named libpolkaGrid_caml.a or libpolkaGrid_caml.so/dllpolkaGrid_caml.so (and libpolkaGrid_caml_debug.a or ...). The OCaml part is named polkaGrid.cma (polkaGrid.cmxa) 3. Miscellaneous ---------------- 'make clean' and 'make distclean' have the usual behaviour. apron-dist-0.9.10/apron/products/tmp/0000750014525101416610000000000011252216517017330 5ustar bjeannetpopartapron-dist-0.9.10/apron/products/tmp/polkaGrid.ml0000640014525101416610000000424711252216517021606 0ustar bjeannetpopart(* File generated from polkaGrid.idl *) (** Reduced product of NewPolka polyhedra and PPL grids *) (** Type of abstract values, where ['a] is [Polka.loose] or [Polka.strict]. *) type 'a t external ap_pkgrid_manager_alloc : Manager.ap_manager_ptr -> Manager.ap_manager_ptr -> Manager.ap_manager_ptr = "camlidl_polkaGrid_ap_pkgrid_manager_alloc" external ap_pkgrid_manager_decompose : Manager.ap_manager_ptr -> Manager.ap_manager_ptr * Manager.ap_manager_ptr = "camlidl_polkaGrid_ap_pkgrid_manager_decompose" external ap_pkgrid_decompose : Abstract0.ap_abstract0_ptr -> Abstract0.ap_abstract0_ptr * Abstract0.ap_abstract0_ptr = "camlidl_polkaGrid_ap_pkgrid_decompose" external ap_pkgrid_compose : Manager.ap_manager_ptr -> Abstract0.ap_abstract0_ptr -> Abstract0.ap_abstract0_ptr -> Abstract0.ap_abstract0_ptr = "camlidl_polkaGrid_ap_pkgrid_compose" let manager_is_polkagrid man = let str = Apron.Manager.get_library man in let str = try String.sub str 0 9 with Invalid_argument _ -> "" in (String.compare str "polkagrid")==0 let manager_of_polkagrid (man:'a t Apron.Manager.t) : 'b Apron.Manager.t = Obj.magic man let manager_to_polkagrid (man:'a Apron.Manager.t) : 'b t Apron.Manager.t = if manager_is_polkagrid man then Obj.magic man else failwith "PolkaGrid.to_polkagrid: the argument manager is not a polkagrid manager" module Abstract0 = struct let is_polkagrid abs = manager_is_polkagrid (Apron.Abstract0.manager abs) let of_polkagrid (abs: 'a t Apron.Abstract0.t) : 'b Apron.Abstract0.t = Obj.magic abs let to_polkagrid (abs:'a Apron.Abstract0.t) : 'b t Apron.Abstract0.t = if is_polkagrid abs then Obj.magic abs else failwith "PolkaGrid.Abstract0.to_polkagrid: the argument value is not a polkagrid value" end module Abstract1 = struct let is_polkagrid abs = manager_is_polkagrid (Apron.Abstract1.manager abs) let of_polkagrid (abs: 'a t Apron.Abstract1.t) : 'b Apron.Abstract1.t = Obj.magic abs let to_polkagrid (abs:'a Apron.Abstract1.t) : 'b t Apron.Abstract1.t = if is_polkagrid abs then Obj.magic abs else failwith "PolkaGrid.Abstract1.to_polkagrid: the argument value is not a polkagrid value" end apron-dist-0.9.10/apron/products/tmp/polkaGrid.idl0000640014525101416610000001555011252216517021745 0ustar bjeannetpopart/* -*- mode: c -*- */ quote(C,"#include \"ap_global0.h\"") quote(C,"#include \"apron_caml.h\"") quote(C,"#include \"ap_pkgrid.h\"") import "manager.idl"; import "abstract0.idl"; quote(MLMLI,"(** Reduced product of NewPolka polyhedra and PPL grids *)") quote(MLMLI," (** Type of abstract values, where ['a] is [Polka.loose] or [Polka.strict]. *)\n\ type 'a t ") quote(MLI,"(** Create a PolkaGrid manager from a (loose or strict) polka manager, and a PPL grid manager *)") ap_manager_ptr ap_pkgrid_manager_alloc(ap_manager_ptr manpk, ap_manager_ptr manpplgrid) quote(call," _res = ap_pkgrid_manager_alloc(manpk,manpplgrid); if (_res==NULL) caml_failwith(\"PolkaGrid.manager_alloc: the provided polka manager is most probably an equalities polka manager\"); { ap_exc_t i; for (i=1; iinternal; manpk = ap_manager_copy(intern->tmanagers[0]); manpplgrid = ap_manager_copy(intern->tmanagers[1]); "); quote(MLI,"(** Decompose an abstract value *)") void ap_pkgrid_decompose(ap_abstract0_ptr abs, [out]ap_abstract0_ptr abspk, [out]ap_abstract0_ptr abspplgrid) quote(call," { ap_reducedproduct_internal_t* intern = (ap_reducedproduct_internal_t*)abs->man->internal; ap_manager_t* manpk = intern->tmanagers[0]; ap_manager_t* manpplgrid = intern->tmanagers[1]; void** res = ap_reducedproduct_decompose(abs->man,false,(ap_reducedproduct_t*)abs->value); abspk = (ap_abstract0_t*)malloc(sizeof(ap_abstract0_t)); abspk->man = ap_manager_copy(manpk); abspk->value = res[0]; abspplgrid = (ap_abstract0_t*)malloc(sizeof(ap_abstract0_t)); abspplgrid->man = ap_manager_copy(manpplgrid); abspplgrid->value = res[1]; free(res); } ") quote(dealloc,"I0_CHECK_EXC(abs->man)"); quote(MLI,"(** Compose an abstract value *)") ap_abstract0_ptr ap_pkgrid_compose(ap_manager_ptr man, ap_abstract0_ptr abspk, ap_abstract0_ptr abspplgrid) quote(call," { ap_reducedproduct_internal_t* intern = (ap_reducedproduct_internal_t*)man->internal; ap_manager_t* manpk = intern->tmanagers[0]; ap_manager_t* manpplgrid = intern->tmanagers[1]; void* tabs[2]; tabs[0] = abspk->value; tabs[1] = abspplgrid->value; ap_reducedproduct_t* prod = ap_reducedproduct_compose(man,false,tabs); _res = (ap_abstract0_t*)malloc(sizeof(ap_abstract0_t)); _res->man = ap_manager_copy(man); _res->value = prod; } ") quote(dealloc,"I0_CHECK_EXC(man)"); quote(MLI,"(** {2 Type conversions} *) val manager_is_polkagrid : 'a Apron.Manager.t -> bool (** Return [true] iff the argument manager is a polkagrid manager *) val manager_of_polkagrid : 'a t Apron.Manager.t -> 'b Apron.Manager.t (** Makes a polkagrid manager generic *) val manager_to_polkagrid : 'a Apron.Manager.t -> 'b t Apron.Manager.t (** Instanciate the type of a polkagrid manager. Raises [Failure] if the argument manager is not a polkagrid manager *) module Abstract0 : sig val is_polkagrid : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument manager is a polkagrid value *) val of_polkagrid : 'a t Apron.Abstract0.t -> 'b Apron.Abstract0.t (** Makes a polkagrid value generic *) val to_polkagrid : 'a Apron.Abstract0.t -> 'b t Apron.Abstract0.t (** Instanciate the type of a polkagrid value. Raises [Failure] if the argument manager is not a polkagrid manager *) end module Abstract1 : sig val is_polkagrid : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument manager is a polkagrid value *) val of_polkagrid : 'a t Apron.Abstract1.t -> 'b Apron.Abstract1.t (** Makes a polkagrid value generic *) val to_polkagrid : 'a Apron.Abstract1.t -> 'b t Apron.Abstract1.t (** Instanciate the type of a polkagrid value. Raises [Failure] if the argument manager is not a polkagrid manager *) end ") quote(ML," let manager_is_polkagrid man = let str = Apron.Manager.get_library man in let str = try String.sub str 0 9 with Invalid_argument _ -> \"\" in (String.compare str \"polkagrid\")==0 let manager_of_polkagrid (man:'a t Apron.Manager.t) : 'b Apron.Manager.t = Obj.magic man let manager_to_polkagrid (man:'a Apron.Manager.t) : 'b t Apron.Manager.t = if manager_is_polkagrid man then Obj.magic man else failwith \"PolkaGrid.to_polkagrid: the argument manager is not a polkagrid manager\" module Abstract0 = struct let is_polkagrid abs = manager_is_polkagrid (Apron.Abstract0.manager abs) let of_polkagrid (abs: 'a t Apron.Abstract0.t) : 'b Apron.Abstract0.t = Obj.magic abs let to_polkagrid (abs:'a Apron.Abstract0.t) : 'b t Apron.Abstract0.t = if is_polkagrid abs then Obj.magic abs else failwith \"PolkaGrid.Abstract0.to_polkagrid: the argument value is not a polkagrid value\" end module Abstract1 = struct let is_polkagrid abs = manager_is_polkagrid (Apron.Abstract1.manager abs) let of_polkagrid (abs: 'a t Apron.Abstract1.t) : 'b Apron.Abstract1.t = Obj.magic abs let to_polkagrid (abs:'a Apron.Abstract1.t) : 'b t Apron.Abstract1.t = if is_polkagrid abs then Obj.magic abs else failwith \"PolkaGrid.Abstract1.to_polkagrid: the argument value is not a polkagrid value\" end ") quote(MLI,"\n(** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. Do not forget the [-cc \"g++\"] option: PPL is a C++ library which requires a C++ linker. {3 Bytecode compilation} {[ocamlc -cc \"g++\"-I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma polkaMPQ.cma ppl.cma polkaGrid.cma mlexample.ml]} {[ocamlc -cc \"g++\" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \\ bigarray.cma gmp.cma apron.cma polkaMPQ.cma ppl.cma polkaGrid.cma ocamlc -cc \"g++\" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma polkaMPQ.cma ppl.cma polkaGrid.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -cc \"g++\" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa polkaMPQ.cmxa ppl.cmxa polkaGrid.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -cc \"g++\" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa polkaMPQ.cmxa ppl.cmxa polkaGrid.cmxa mlexample.ml \\ -cclib \"-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib -L$PPL_PREFIX/lib \\ -lpolkaGrid_caml_debug -lap_pkgrid_debug \\ -lpolkaMPQ_caml_debug -lpolkaMPQ_debug \\ -lap_ppl_caml_debug -lap_ppl_debug -lppl -lgmpxx \\ -lapron_caml_debug -lapron_debug \\ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP_PREFIX/lib -lgmp \\ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \\ -lbigarray\" ]} *)") apron-dist-0.9.10/apron/products/tmp/polkaGrid.mli0000640014525101416610000000766511252216517021766 0ustar bjeannetpopart(* File generated from polkaGrid.idl *) (** Reduced product of NewPolka polyhedra and PPL grids *) (** Type of abstract values, where ['a] is [Polka.loose] or [Polka.strict]. *) type 'a t (** Create a PolkaGrid manager from a (loose or strict) polka manager, and a PPL grid manager *) external ap_pkgrid_manager_alloc : Manager.ap_manager_ptr -> Manager.ap_manager_ptr -> Manager.ap_manager_ptr = "camlidl_polkaGrid_ap_pkgrid_manager_alloc" (** Decompose the manager *) external ap_pkgrid_manager_decompose : Manager.ap_manager_ptr -> Manager.ap_manager_ptr * Manager.ap_manager_ptr = "camlidl_polkaGrid_ap_pkgrid_manager_decompose" (** Decompose an abstract value *) external ap_pkgrid_decompose : Abstract0.ap_abstract0_ptr -> Abstract0.ap_abstract0_ptr * Abstract0.ap_abstract0_ptr = "camlidl_polkaGrid_ap_pkgrid_decompose" (** Compose an abstract value *) external ap_pkgrid_compose : Manager.ap_manager_ptr -> Abstract0.ap_abstract0_ptr -> Abstract0.ap_abstract0_ptr -> Abstract0.ap_abstract0_ptr = "camlidl_polkaGrid_ap_pkgrid_compose" (** {2 Type conversions} *) val manager_is_polkagrid : 'a Apron.Manager.t -> bool (** Return [true] iff the argument manager is a polkagrid manager *) val manager_of_polkagrid : 'a t Apron.Manager.t -> 'b Apron.Manager.t (** Makes a polkagrid manager generic *) val manager_to_polkagrid : 'a Apron.Manager.t -> 'b t Apron.Manager.t (** Instanciate the type of a polkagrid manager. Raises [Failure] if the argument manager is not a polkagrid manager *) module Abstract0 : sig val is_polkagrid : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument manager is a polkagrid value *) val of_polkagrid : 'a t Apron.Abstract0.t -> 'b Apron.Abstract0.t (** Makes a polkagrid value generic *) val to_polkagrid : 'a Apron.Abstract0.t -> 'b t Apron.Abstract0.t (** Instanciate the type of a polkagrid value. Raises [Failure] if the argument manager is not a polkagrid manager *) end module Abstract1 : sig val is_polkagrid : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument manager is a polkagrid value *) val of_polkagrid : 'a t Apron.Abstract1.t -> 'b Apron.Abstract1.t (** Makes a polkagrid value generic *) val to_polkagrid : 'a Apron.Abstract1.t -> 'b t Apron.Abstract1.t (** Instanciate the type of a polkagrid value. Raises [Failure] if the argument manager is not a polkagrid manager *) end (** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. Do not forget the [-cc "g++"] option: PPL is a C++ library which requires a C++ linker. {3 Bytecode compilation} {[ocamlc -cc "g++"-I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \ bigarray.cma gmp.cma apron.cma polkaMPQ.cma ppl.cma polkaGrid.cma mlexample.ml]} {[ocamlc -cc "g++" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \ bigarray.cma gmp.cma apron.cma polkaMPQ.cma ppl.cma polkaGrid.cma ocamlc -cc "g++" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \ bigarray.cma gmp.cma apron.cma polkaMPQ.cma ppl.cma polkaGrid.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -cc "g++" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa polkaMPQ.cmxa ppl.cmxa polkaGrid.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -cc "g++" -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa polkaMPQ.cmxa ppl.cmxa polkaGrid.cmxa mlexample.ml \ -cclib "-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib -L$PPL_PREFIX/lib \ -lpolkaGrid_caml_debug -lap_pkgrid_debug \ -lpolkaMPQ_caml_debug -lpolkaMPQ_debug \ -lap_ppl_caml_debug -lap_ppl_debug -lppl -lgmpxx \ -lapron_caml_debug -lapron_debug \ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP_PREFIX/lib -lgmp \ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \ -lbigarray" ]} *) apron-dist-0.9.10/apron/products/tmp/polkaGrid_stubs.c0000640014525101416610000003247411252216517022643 0ustar bjeannetpopart/* File generated from polkaGrid.idl */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include "ap_global0.h" #include "apron_caml.h" #include "ap_pkgrid.h" extern void camlidl_apron_manager_funid_ml2c(value, ap_funid_t *); #define camlidl_ml2c_manager_ap_funid_t(v,c,ctx) camlidl_apron_manager_funid_ml2c(v,c) extern value camlidl_apron_manager_funid_c2ml(ap_funid_t *); #define camlidl_c2ml_manager_ap_funid_t(c,ctx) camlidl_apron_manager_funid_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_funopt_t(value, struct ap_funopt_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_funopt_t(struct ap_funopt_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_exc_ml2c(value, ap_exc_t *); #define camlidl_ml2c_manager_ap_exc_t(v,c,ctx) camlidl_apron_manager_exc_ml2c(v,c) extern value camlidl_apron_manager_exc_c2ml(ap_exc_t *); #define camlidl_c2ml_manager_ap_exc_t(c,ctx) camlidl_apron_manager_exc_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_exclog_t(value, struct ap_exclog_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_exclog_t(struct ap_exclog_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_ptr_ml2c(value, ap_manager_ptr *); #define camlidl_ml2c_manager_ap_manager_ptr(v,c,ctx) camlidl_apron_manager_ptr_ml2c(v,c) extern value camlidl_apron_manager_ptr_c2ml(ap_manager_ptr *); #define camlidl_c2ml_manager_ap_manager_ptr(c,ctx) camlidl_apron_manager_ptr_c2ml(c) extern void camlidl_apron_scalar_ml2c(value, ap_scalar_t *); #define camlidl_ml2c_scalar_ap_scalar_t(v,c,ctx) camlidl_apron_scalar_ml2c(v,c) extern value camlidl_apron_scalar_c2ml(ap_scalar_t *); #define camlidl_c2ml_scalar_ap_scalar_t(c,ctx) camlidl_apron_scalar_c2ml(c) extern void camlidl_ml2c_scalar_ap_scalar_ptr(value, ap_scalar_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_ap_scalar_ptr(ap_scalar_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_scalar_struct_ap_scalar_array_t(value, struct ap_scalar_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_scalar_struct_ap_scalar_array_t(struct ap_scalar_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_t(value, struct ap_interval_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_t(struct ap_interval_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_ap_interval_ptr(value, ap_interval_ptr *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_ap_interval_ptr(ap_interval_ptr *, camlidl_ctx _ctx); extern void camlidl_ml2c_interval_struct_ap_interval_array_t(value, struct ap_interval_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_interval_struct_ap_interval_array_t(struct ap_interval_array_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_coeff_struct_ap_coeff_t(value, struct ap_coeff_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_coeff_struct_ap_coeff_t(struct ap_coeff_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_ap_dim_t(value, ap_dim_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_ap_dim_t(ap_dim_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimchange_t(value, struct ap_dimchange_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange_t(struct ap_dimchange_t *, camlidl_ctx _ctx); extern void camlidl_apron_dimchange_ml2c(value, ap_dimchange_t *); #define camlidl_ml2c_dim_ap_dimchange_t(v,c,ctx) camlidl_apron_dimchange_ml2c(v,c) extern value camlidl_apron_dimchange_c2ml(ap_dimchange_t *); #define camlidl_c2ml_dim_ap_dimchange_t(c,ctx) camlidl_apron_dimchange_c2ml(c) extern void camlidl_ml2c_dim_struct_ap_dimchange2_t(value, struct ap_dimchange2_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimchange2_t(struct ap_dimchange2_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimperm_t(value, struct ap_dimperm_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimperm_t(struct ap_dimperm_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_dim_struct_ap_dimension_t(value, struct ap_dimension_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_dim_struct_ap_dimension_t(struct ap_dimension_t *, camlidl_ctx _ctx); extern void camlidl_apron_linexpr0_ptr_ml2c(value, ap_linexpr0_ptr *); #define camlidl_ml2c_linexpr0_ap_linexpr0_ptr(v,c,ctx) camlidl_apron_linexpr0_ptr_ml2c(v,c) extern value camlidl_apron_linexpr0_ptr_c2ml(ap_linexpr0_ptr *); #define camlidl_c2ml_linexpr0_ap_linexpr0_ptr(c,ctx) camlidl_apron_linexpr0_ptr_c2ml(c) extern void camlidl_apron_lincons0_ml2c(value, ap_lincons0_t *); #define camlidl_ml2c_lincons0_ap_lincons0_t(v,c,ctx) camlidl_apron_lincons0_ml2c(v,c) extern value camlidl_apron_lincons0_c2ml(ap_lincons0_t *); #define camlidl_c2ml_lincons0_ap_lincons0_t(c,ctx) camlidl_apron_lincons0_c2ml(c) extern void camlidl_ml2c_lincons0_struct_ap_lincons0_array_t(value, struct ap_lincons0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_lincons0_struct_ap_lincons0_array_t(struct ap_lincons0_array_t *, camlidl_ctx _ctx); extern int camlidl_ml2c_generator0_enum_gentyp(value); extern value camlidl_c2ml_generator0_enum_gentyp(int); extern int camlidl_transl_table_generator0_enum_gentyp[]; extern void camlidl_ml2c_generator0_struct_ap_generator0_t(value, struct ap_generator0_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_generator0_struct_ap_generator0_t(struct ap_generator0_t *, camlidl_ctx _ctx); extern void camlidl_ml2c_generator0_struct_ap_generator0_array_t(value, struct ap_generator0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_generator0_struct_ap_generator0_array_t(struct ap_generator0_array_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr0_ptr_ml2c(value, ap_texpr0_ptr *); #define camlidl_ml2c_texpr0_ap_texpr0_ptr(v,c,ctx) camlidl_apron_texpr0_ptr_ml2c(v,c) extern value camlidl_apron_texpr0_ptr_c2ml(ap_texpr0_ptr *); #define camlidl_c2ml_texpr0_ap_texpr0_ptr(c,ctx) camlidl_apron_texpr0_ptr_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_op_t(value, struct ap_texpr_op_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_op_t(struct ap_texpr_op_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_unop_t_ml2c(value, ap_texpr_unop_t *); #define camlidl_ml2c_texpr0_ap_texpr_unop_t(v,c,ctx) camlidl_apron_texpr_unop_t_ml2c(v,c) extern value camlidl_apron_texpr_unop_t_c2ml(ap_texpr_unop_t *); #define camlidl_c2ml_texpr0_ap_texpr_unop_t(c,ctx) camlidl_apron_texpr_unop_t_c2ml(c) extern void camlidl_apron_texpr_binop_t_ml2c(value, ap_texpr_binop_t *); #define camlidl_ml2c_texpr0_ap_texpr_binop_t(v,c,ctx) camlidl_apron_texpr_binop_t_ml2c(v,c) extern value camlidl_apron_texpr_binop_t_c2ml(ap_texpr_binop_t *); #define camlidl_c2ml_texpr0_ap_texpr_binop_t(c,ctx) camlidl_apron_texpr_binop_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rtype_t(value, struct ap_texpr_rtype_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rtype_t(struct ap_texpr_rtype_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_rtype_t_ml2c(value, ap_texpr_rtype_t *); #define camlidl_ml2c_texpr0_ap_texpr_rtype_t(v,c,ctx) camlidl_apron_texpr_rtype_t_ml2c(v,c) extern value camlidl_apron_texpr_rtype_t_c2ml(ap_texpr_rtype_t *); #define camlidl_c2ml_texpr0_ap_texpr_rtype_t(c,ctx) camlidl_apron_texpr_rtype_t_c2ml(c) extern void camlidl_ml2c_texpr0_struct_ap_texpr_rdir_t(value, struct ap_texpr_rdir_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_texpr0_struct_ap_texpr_rdir_t(struct ap_texpr_rdir_t *, camlidl_ctx _ctx); extern void camlidl_apron_texpr_rdir_t_ml2c(value, ap_texpr_rdir_t *); #define camlidl_ml2c_texpr0_ap_texpr_rdir_t(v,c,ctx) camlidl_apron_texpr_rdir_t_ml2c(v,c) extern value camlidl_apron_texpr_rdir_t_c2ml(ap_texpr_rdir_t *); #define camlidl_c2ml_texpr0_ap_texpr_rdir_t(c,ctx) camlidl_apron_texpr_rdir_t_c2ml(c) extern void camlidl_apron_tcons0_ml2c(value, ap_tcons0_t *); #define camlidl_ml2c_tcons0_ap_tcons0_t(v,c,ctx) camlidl_apron_tcons0_ml2c(v,c) extern value camlidl_apron_tcons0_c2ml(ap_tcons0_t *); #define camlidl_c2ml_tcons0_ap_tcons0_t(c,ctx) camlidl_apron_tcons0_c2ml(c) extern void camlidl_ml2c_tcons0_struct_ap_tcons0_array_t(value, struct ap_tcons0_array_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_tcons0_struct_ap_tcons0_array_t(struct ap_tcons0_array_t *, camlidl_ctx _ctx); extern void camlidl_apron_abstract0_ptr_ml2c(value, ap_abstract0_ptr *); #define camlidl_ml2c_abstract0_ap_abstract0_ptr(v,c,ctx) camlidl_apron_abstract0_ptr_ml2c(v,c) extern value camlidl_apron_abstract0_ptr_c2ml(ap_abstract0_ptr *); #define camlidl_c2ml_abstract0_ap_abstract0_ptr(c,ctx) camlidl_apron_abstract0_ptr_c2ml(c) value camlidl_polkaGrid_ap_pkgrid_manager_alloc( value _v_manpk, value _v_manpplgrid) { ap_manager_ptr manpk; /*in*/ ap_manager_ptr manpplgrid; /*in*/ ap_manager_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_manpk, &manpk, _ctx); camlidl_ml2c_manager_ap_manager_ptr(_v_manpplgrid, &manpplgrid, _ctx); /* begin user-supplied calling sequence */ _res = ap_pkgrid_manager_alloc(manpk,manpplgrid); if (_res==NULL) caml_failwith("PolkaGrid.manager_alloc: the provided polka manager is most probably an equalities polka manager"); { ap_exc_t i; for (i=1; iinternal; manpk = ap_manager_copy(intern->tmanagers[0]); manpplgrid = ap_manager_copy(intern->tmanagers[1]); /* end user-supplied calling sequence */ Begin_roots_block(_vres, 2) _vres[0] = camlidl_c2ml_manager_ap_manager_ptr(&manpk, _ctx); _vres[1] = camlidl_c2ml_manager_ap_manager_ptr(&manpplgrid, _ctx); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); return _vresult; } value camlidl_polkaGrid_ap_pkgrid_decompose( value _v_abs) { ap_abstract0_ptr abs; /*in*/ ap_abstract0_ptr abspk; /*out*/ ap_abstract0_ptr abspplgrid; /*out*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; value _vresult; value _vres[2] = { 0, 0, }; camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_abs, &abs, _ctx); /* begin user-supplied calling sequence */ { ap_reducedproduct_internal_t* intern = (ap_reducedproduct_internal_t*)abs->man->internal; ap_manager_t* manpk = intern->tmanagers[0]; ap_manager_t* manpplgrid = intern->tmanagers[1]; void** res = ap_reducedproduct_decompose(abs->man,false,(ap_reducedproduct_t*)abs->value); abspk = (ap_abstract0_t*)malloc(sizeof(ap_abstract0_t)); abspk->man = ap_manager_copy(manpk); abspk->value = res[0]; abspplgrid = (ap_abstract0_t*)malloc(sizeof(ap_abstract0_t)); abspplgrid->man = ap_manager_copy(manpplgrid); abspplgrid->value = res[1]; free(res); } /* end user-supplied calling sequence */ Begin_roots_block(_vres, 2) _vres[0] = camlidl_c2ml_abstract0_ap_abstract0_ptr(&abspk, _ctx); _vres[1] = camlidl_c2ml_abstract0_ap_abstract0_ptr(&abspplgrid, _ctx); _vresult = camlidl_alloc_small(2, 0); Field(_vresult, 0) = _vres[0]; Field(_vresult, 1) = _vres[1]; End_roots() camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (abs->man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(abs->man,_ctx); /* end user-supplied deallocation sequence */ return _vresult; } value camlidl_polkaGrid_ap_pkgrid_compose( value _v_man, value _v_abspk, value _v_abspplgrid) { ap_manager_ptr man; /*in*/ ap_abstract0_ptr abspk; /*in*/ ap_abstract0_ptr abspplgrid; /*in*/ ap_abstract0_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_manager_ap_manager_ptr(_v_man, &man, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_abspk, &abspk, _ctx); camlidl_ml2c_abstract0_ap_abstract0_ptr(_v_abspplgrid, &abspplgrid, _ctx); /* begin user-supplied calling sequence */ { ap_reducedproduct_internal_t* intern = (ap_reducedproduct_internal_t*)man->internal; ap_manager_t* manpk = intern->tmanagers[0]; ap_manager_t* manpplgrid = intern->tmanagers[1]; void* tabs[2]; tabs[0] = abspk->value; tabs[1] = abspplgrid->value; ap_reducedproduct_t* prod = ap_reducedproduct_compose(man,false,tabs); _res = (ap_abstract0_t*)malloc(sizeof(ap_abstract0_t)); _res->man = ap_manager_copy(man); _res->value = prod; } /* end user-supplied calling sequence */ _vres = camlidl_c2ml_abstract0_ap_abstract0_ptr(&_res, _ctx); camlidl_free(_ctx); /* begin user-supplied deallocation sequence */ if (man->result.exn!=AP_EXC_NONE) camlidl_apron_manager_check_exception(man,_ctx); /* end user-supplied deallocation sequence */ return _vres; } apron-dist-0.9.10/apron/products/ap_pkgrid.texi0000640014525101416610000000446511251675047021403 0ustar bjeannetpopart@c This file is part of the APRON Library, released under LGPL @c license. Please read the COPYING file packaged in the distribution @c to be included from apron.texi The @sc{pkgrid} library is aimed to be used through the APRON interface. It implements the reduced product of NewPolka convex polyhedra and the PPL linear congruences abstract domains and implementations. It exploits for this the features offered by the module @file{ap_reducedproduct} contained in the @file{apron} core library. @menu * Use of pkgrid:: * Allocating pkgrid managers:: @end menu @c =================================================================== @node Use of pkgrid, Allocating pkgrid managers,, pkgrid @subsection Use of pkgrid @c =================================================================== To use @sc{pkgrid} in C, add @example #include "ap_pkgrid.h" @end example in your source file(s) and add @samp{-I$(APRON_PREFIX)/include} in the command line in your Makefile. You should also link your object files with the @sc{pkgrid} library to produce an executable, by adding something like @samp{-L$(APRON_PREFIX)/lib -lap_pkgrid} in the command line in your Makefile, followed by the flags and libraries needed for the NewPolka library (@pxref{Use of NewPolka}) and the PPL library (@pxref{Use of APRON PPL}). Be cautious: because of the use of the PPL library, you @samp{g++} (C++ compiler) instead of @samp{gcc} (C compiler) for the linking. Also, the library is available in debug mode (@samp{libap_pkgrid_debug.a}, @samp{libap_pkgrid_debug.so}). @c =================================================================== @node Allocating pkgrid managers , , Use of pkgrid, pkgrid @subsection Allocating pkgrid managers @c =================================================================== @deftypefun ap_manager_t* ap_pkgrid_manager_alloc (ap_manager_t* @var{manpk}, ap_manager_t* @var{manpplgrid}) Allocate a APRON manager linked to the pkgrid library, using the (loose or strict) polka manager @var{manpk} and the PPL grid manager @var{manpplgrid}. If one of the argulment manager is not of the right type, returns @code{NULL}. @end deftypefun Available standard options are the one offered by the generic reduced product module @file{ap_reducedproduct} contained in the @file{apron} core library (@pxref{Functions for implementors}). apron-dist-0.9.10/apron/products/sedscript_caml0000640014525101416610000000201711251675047021456 0ustar bjeannetpoparts/Manager.ap_manager_ptr/'a t Apron.Manager.t/g; s/Abstract0.ap_abstract0_ptr/'a t Apron.Abstract0.t/g; s/external ap_pkgrid_/external /g; s/external manager_alloc : 'a t Apron.Manager.t -> 'a t Apron.Manager.t -> 'a t Apron.Manager.t/external manager_alloc : 'a Polka.t Apron.Manager.t -> Ppl.grid Ppl.t Apron.Manager.t -> 'a t Apron.Manager.t/g; s/external manager_decompose : 'a t Apron.Manager.t -> 'a t Apron.Manager.t \* 'a t Apron.Manager.t/external manager_decompose : 'a t Apron.Manager.t -> 'a Polka.t Apron.Manager.t \* Ppl.grid Ppl.t Apron.Manager.t/g; s/external decompose : 'a t Apron.Abstract0.t -> 'a t Apron.Abstract0.t \* 'a t Apron.Abstract0.t/external decompose : 'a t Apron.Abstract0.t -> 'a Polka.t Apron.Abstract0.t \* Ppl.grid Ppl.t Apron.Abstract0.t/g; s/external compose : 'a t Apron.Manager.t -> 'a t Apron.Abstract0.t -> 'a t Apron.Abstract0.t -> 'a t Apron.Abstract0.t/external compose : 'a t Apron.Manager.t -> 'a Polka.t Apron.Abstract0.t -> Ppl.grid Ppl.t Apron.Abstract0.t -> 'a t Apron.Abstract0.t/g; apron-dist-0.9.10/apron/apronxx/0000750014525101416610000000000011252216462016363 5ustar bjeannetpopartapron-dist-0.9.10/apron/apronxx/apxx_generator1_inline.hh0000640014525101416610000003106710703144237023361 0ustar bjeannetpopart/* -*- C++ -*- * apxx_generator1_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ /* ================================= */ /* generator1 */ /* ================================= */ /* constructors */ /* ============ */ inline generator1::generator1(ap_generator1_t p) : l(p) {} inline generator1::generator1(const environment& e, const generator0& x) { l.env = ap_environment_copy(const_cast(e.get_ap_environment_t())); l.generator0 = ap_generator0_copy(const_cast(x.get_ap_generator0_t())); } inline generator1::generator1(const environment& e, ap_gentyp_t gentyp) { ap_linexpr1_t llin = ap_linexpr1_make(const_cast(e.get_ap_environment_t()), AP_LINEXPR_SPARSE, 0); l = ap_generator1_make(gentyp, &llin); } inline generator1::generator1(ap_gentyp_t gentyp, const linexpr1& lin) { ap_linexpr1_t llin = ap_linexpr1_copy(const_cast(lin.get_ap_linexpr1_t())); l = ap_generator1_make(gentyp, &llin); } inline generator1::generator1(const generator1& x) { l = ap_generator1_copy(const_cast(&x.l)); } inline generator1::generator1(const generator1& x, const environment& e) { if (!x.has_linexpr()) throw std::invalid_argument("apron::generator1::generator1(const generator&, const environment&) empty expression"); bool r = ap_generator1_extend_environment(&l, const_cast(&x.l), const_cast(e.get_ap_environment_t())); if (r) throw std::invalid_argument("apron::generator1::generator1(const generator&, const environment&) not a super-environment"); } /* destructor */ /* ========== */ inline generator1::~generator1() { ap_generator1_clear(&l); } /* assignment */ /* ========== */ inline generator1& generator1::operator= (const generator1& x) { ap_generator1_t ll = ap_generator1_copy(const_cast(&x.l)); ap_generator1_clear(&l); l = ll; return *this; } inline void generator1::set_linexpr(const linexpr1& c) { get_generator0().set_linexpr(c.get_linexpr0()); } /* dimension operations */ /* ==================== */ inline void generator1::extend_environment(const environment& e) { if (!has_linexpr()) throw std::invalid_argument("apron::generator1::extend_environment(cconst environment&) empty expression"); bool r = ap_generator1_extend_environment_with(&l, const_cast(e.get_ap_environment_t())); if (r) throw std::invalid_argument("apron::generator1::extend_environment(const environment&) not a super-environment"); } /* access */ /* ====== */ inline environment generator1::get_environment() const { return (ap_environment_copy(ap_generator1_envref(const_cast(&l)))); } inline const generator0& generator1::get_generator0() const { return reinterpret_cast(*ap_generator1_generator0ref(const_cast(&l))); } inline generator0& generator1::get_generator0() { return reinterpret_cast(*ap_generator1_generator0ref(&l)); } inline size_t generator1::size() const { return get_generator0().size(); } inline ap_gentyp_t& generator1::get_gentyp() { return get_generator0().get_gentyp(); } inline const ap_gentyp_t& generator1::get_gentyp() const { return get_generator0().get_gentyp(); } inline bool generator1::has_linexpr() const { return get_generator0().has_linexpr(); } inline linexpr1 generator1::get_linexpr() const { if (!has_linexpr()) throw std::invalid_argument("apron::generator1::get_linexpr() empty expression"); linexpr0 ll = get_generator0().get_linexpr(); return linexpr1(get_environment(),ll); } inline coeff& generator1::get_cst() { if (!has_linexpr()) throw std::invalid_argument("apron::generator1::get_cst() empty expression"); return reinterpret_cast(*ap_generator1_cstref(&l)); } inline const coeff& generator1::get_cst() const { if (!has_linexpr()) throw std::invalid_argument("apron::generator1::get_cst() empty expression"); return reinterpret_cast(*ap_generator1_cstref(const_cast(&l))); } inline coeff& generator1::operator[](const var& var) { if (!has_linexpr()) throw std::invalid_argument("apron::generator1::operator[](const var&) empty expression"); ap_coeff_t* x = ap_generator1_coeffref(&l, const_cast(var.get_ap_var_t())); if (!x) throw std::invalid_argument("apron::generator1::operator[](const var&) variable not in environment"); return reinterpret_cast(*x); } inline const coeff& generator1::operator[](const var& var) const { if (!has_linexpr()) throw std::invalid_argument("apron::generator1::operator[](const var&) empty expression"); ap_coeff_t* x = ap_generator1_coeffref(const_cast(&l), const_cast(var.get_ap_var_t())); if (!x) throw std::invalid_argument("apron::generator1::operator[](const var&) variable not in environment"); return reinterpret_cast(*x); } /* print */ /* ===== */ inline std::ostream& operator<< (std::ostream& os, const generator1& s) { if (!s.has_linexpr()) throw std::invalid_argument("apron::operator<<(ostream&, const generator1&) empty expression"); switch (s.get_gentyp()) { case AP_GEN_LINE: os << "LINE: "; break; case AP_GEN_RAY: os << "RAY: "; break; case AP_GEN_VERTEX: os << "VERTEX: "; break; case AP_GEN_LINEMOD: os << "LINEMOD: "; break; case AP_GEN_RAYMOD: os << "RAYMOD: "; break; default: throw std::invalid_argument("apron::operator<<(ostream&, const generator1&) invalid generator type"); } return os << s.get_linexpr(); } inline void generator1::print(FILE* stream) const { ap_generator1_fprint(stream, const_cast(&l)); } /* C-level compatibility */ /* ===================== */ inline const ap_generator1_t* generator1::get_ap_generator1_t() const { return &l; } inline ap_generator1_t* generator1::get_ap_generator1_t() { return &l; } /* ================================= */ /* generator1_array */ /* ================================= */ /* constructors */ /* ============ */ inline generator1_array::generator1_array(ap_generator1_array_t& a) : a(a) {} inline generator1_array::generator1_array(const environment& e, const generator0_array& x) { size_t sz = x.size(); a = ap_generator1_array_make(const_cast(e.get_ap_environment_t()), sz); for (size_t i=0; i(e.get_ap_environment_t()), size); } inline generator1_array::generator1_array(const generator1_array& x) { size_t sz = x.size(); a = ap_generator1_array_make(x.get_environment().get_ap_environment_t(), sz); for (size_t i=0; i(&x.a), const_cast(e.get_ap_environment_t())); if (r) throw std::invalid_argument("apron::generator1_array::generator1_array(const generator1_array&, const environment&) not a super-environment"); } inline generator1_array::generator1_array(size_t sz, const generator1 x[]) { if (sz<1) throw std::invalid_argument("apron::generator1_array::generator1_array(size_t sz, const generator1[]) null size"); a = ap_generator1_array_make(x[0].get_environment().get_ap_environment_t(), sz); for (size_t i=0; i (x[i].get_generator0().get_ap_generator0_t())); } inline generator1_array::generator1_array(const std::vector& x) { size_t sz = x.size(); if (sz<1) throw std::invalid_argument("apron::generator1_array::generator1_array(const vector&) null size"); a = ap_generator1_array_make(x[0].get_environment().get_ap_environment_t(), sz); for (size_t i=0; i (x[i].get_generator0().get_ap_generator0_t())); } /* destructor */ /* ========== */ inline generator1_array::~generator1_array() { ap_generator1_array_clear(&a); } /* assignment */ /* ========== */ inline generator1_array& generator1_array::operator= (const generator1_array& x) { if (this!=&x) { size_t sz = x.size(); ap_generator1_array_clear(&a); a = ap_generator1_array_make(x.get_environment().get_ap_environment_t(), sz); for (size_t i=0; i (x[i].get_generator0().get_ap_generator0_t())); } return *this; } inline generator1_array& generator1_array::operator= (const std::vector& x) { size_t size = x.size(); if (size<1) { ap_generator1_array_t aa = ap_generator1_array_make(a.env,0); ap_generator1_array_clear(&a); a = aa; return *this; } ap_generator1_array_clear(&a); a = ap_generator1_array_make(x[0].get_environment().get_ap_environment_t(), size); for (size_t i=0; i (x[i].get_generator0().get_ap_generator0_t())); return *this; } /* dimension operations */ /* ==================== */ inline void generator1_array::resize(size_t size) { ap_generator0_array_resize(&a.generator0_array, size); } inline void generator1_array::extend_environment(const environment& e) { bool r = ap_generator1_array_extend_environment_with(&a, const_cast(e.get_ap_environment_t())); if (r) throw std::invalid_argument("apron::generator1_array::extend_environment(const environment&) not a super-environment"); } /* access */ /* ====== */ inline size_t generator1_array::size() const { return ap_generator1_array_size(const_cast(&a)); } inline environment generator1_array::get_environment() const { return (ap_environment_copy(ap_generator1_array_envref(const_cast(&a)))); } inline const generator0_array& generator1_array::get_generator0_array() const { return reinterpret_cast(const_cast(a.generator0_array)); } inline generator0_array& generator1_array::get_generator0_array() { return reinterpret_cast(a.generator0_array); } inline generator1 generator1_array::get(size_t i) const { if (i>=size()) throw std::out_of_range("apron::generator1_array::get(size_t)"); ap_generator1_t c = ap_generator1_array_get(const_cast(&a),i); return generator1(ap_generator1_copy(&c)); } inline void generator1_array::set(size_t i, const generator1& x) { if (i>=size()) throw std::out_of_range("apron::generator1_array::get(size_t)"); ap_generator0_clear(&a.generator0_array.p[i]); a.generator0_array.p[i] = ap_generator0_copy(const_cast (x.get_generator0().get_ap_generator0_t())); } /* conversion */ /* ========== */ inline generator1_array::operator std::vector() const { size_t sz = size(); generator1 dummy(get_environment(),generator0()); std::vector v(sz,dummy); for (size_t i=0;i(&a),i); v[i] = ap_generator1_copy(&c); } return v; } /* print */ /* ===== */ inline std::ostream& operator<< (std::ostream& os, const generator1_array& s) { size_t sz = s.size(); os << "{ "; for (size_t i=0;i(&a)); } /* C-level compatibility */ /* ===================== */ inline const ap_generator1_array_t* generator1_array::get_ap_generator1_array_t() const { return &a; } inline ap_generator1_array_t* generator1_array::get_ap_generator1_array_t() { return &a; } apron-dist-0.9.10/apron/apronxx/apxx_interval_inline.hh0000640014525101416610000002406611006063143023130 0ustar bjeannetpopart/* -*- C++ -*- * apxx_interval_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ /* ================================= */ /* interval */ /* ================================= */ /* constructors */ /* ============ */ inline void interval::init() { c.inf = ap_scalar_alloc(); c.sup = ap_scalar_alloc(); } inline interval::interval(ap_interval_t* i) : c(*i) { free(i); } inline interval::interval() { init(); } inline interval::interval(const interval& x) { init(); ap_interval_set(&c, const_cast(&x.c)); } inline interval::interval(const scalar& inf, const scalar& sup) { init(); ap_interval_set_scalar(&c, const_cast(inf.get_ap_scalar_t()), const_cast(sup.get_ap_scalar_t())); } inline interval::interval(int inf, int sup) { init(); ap_interval_set_int(&c, inf, sup); } inline interval::interval(long inf, long sup) { init(); ap_interval_set_int(&c, inf, sup); } inline interval::interval(double inf, double sup) { init(); ap_interval_set_double(&c, inf, sup); } inline interval::interval(const frac& inf, const frac& sup) { init(); ap_interval_set_frac(&c, inf.num, inf.den, sup.num, sup.den); } inline interval::interval(const mpq_class& inf, const mpq_class& sup) { init(); ap_interval_set_mpq(&c, const_cast(inf).get_mpq_t(), const_cast(sup).get_mpq_t()); } inline interval::interval(mpfr_t inf, mpfr_t sup) { init(); ap_interval_set_mpfr(&c,inf,sup); } inline interval::interval(top t) { init(); ap_interval_set_top(&c); } inline interval::interval(bottom t) { init(); ap_interval_set_bottom(&c); } /* destructor */ /* ========== */ inline interval::~interval() { ap_scalar_free(c.inf); ap_scalar_free(c.sup); } /* assignments */ /* =========== */ /* = */ inline interval& interval::operator= (const interval& x) { ap_interval_set(&c, const_cast(&x.c)); return *this; } inline interval& interval::operator= (top t) { ap_interval_set_top(&c); return *this; } inline interval& interval::operator= (bottom t) { ap_interval_set_bottom(&c); return *this; } /* set */ inline interval& interval::set(const interval& x) { ap_interval_set(&c, const_cast(&x.c)); return *this; } inline interval& interval::set(const scalar& inf, const scalar& sup) { ap_interval_set_scalar(&c, const_cast(inf.get_ap_scalar_t()), const_cast(sup.get_ap_scalar_t())); return *this; } inline interval& interval::set(int inf, int sup) { ap_interval_set_int(&c, inf, sup); return *this; } inline interval& interval::set(long inf, long sup) { ap_interval_set_int(&c, inf, sup); return *this; } inline interval& interval::set(double inf, double sup) { ap_interval_set_double(&c, inf, sup); return *this; } inline interval& interval::set(const frac& inf, const frac& sup) { ap_interval_set_frac(&c, inf.num, inf.den, sup.num, sup.den); return *this; } inline interval& interval::set(const mpq_class& inf, const mpq_class& sup) { ap_interval_set_mpq(&c, const_cast(inf).get_mpq_t(), const_cast(sup).get_mpq_t()); return *this; } inline interval& interval::set(mpfr_t inf, mpfr_t sup) { ap_interval_set_mpfr(&c,inf,sup); return *this; } inline interval& interval::set(top t) { ap_interval_set_top(&c); return *this; } inline interval& interval::set(bottom t) { ap_interval_set_bottom(&c); return *this; } /* swap */ inline void swap(interval& a, interval &b) { ap_interval_swap(&a.c, &b.c); } /* access */ /* ====== */ inline scalar& interval::get_inf() { return reinterpret_cast(*c.inf); } inline scalar& interval::get_sup() { return reinterpret_cast(*c.sup); } inline const scalar& interval::get_inf() const { return reinterpret_cast(*c.inf); } inline const scalar& interval::get_sup() const { return reinterpret_cast(*c.sup); } /* print */ /* ===== */ inline std::ostream& operator<< (std::ostream& os, const interval& s) { return os << '[' << s.get_inf() << ',' << s.get_sup() << ']'; } inline void interval::print(FILE* stream) const { ap_interval_fprint(stream, const_cast(&c)); } /* tests */ /* ===== */ inline bool interval::is_top() const { return ap_interval_is_top(const_cast(&c)); } inline bool interval::is_bottom() const { return ap_interval_is_bottom(const_cast(&c)); } inline bool operator<= (const interval&a, const interval &b) { return ap_interval_is_leq(const_cast(&a.c), const_cast(&b.c)); } inline bool operator>= (const interval&a, const interval &b) { return ap_interval_is_leq(const_cast(&b.c), const_cast(&a.c)); } inline bool operator< (const interval&a, const interval &b) { return ap_interval_cmp(const_cast(&a.c), const_cast(&b.c)) == -1; } inline bool operator> (const interval&a, const interval &b) { return ap_interval_cmp(const_cast(&a.c), const_cast(&b.c)) == 1; } inline bool operator== (const interval&a, const interval &b) { return ap_interval_equal(const_cast(&a.c), const_cast(&b.c)); } inline bool operator!= (const interval&a, const interval &b) { return !ap_interval_equal(const_cast(&a.c), const_cast(&b.c)); } inline interval::order cmp (const interval&a, const interval &b) { return (interval::order)ap_interval_cmp(const_cast(&a.c), const_cast(&b.c)); } /* other operators */ /* =============== */ inline void interval::neg() { ap_interval_neg(&c, &c); } inline interval interval::operator- () const { interval r = *this; r.neg(); return r; } inline long interval::hash() const { return ap_interval_hash(const_cast(&c)); } /* C-level compatibility */ inline const ap_interval_t* interval::get_ap_interval_t() const { return &c; } inline ap_interval_t* interval::get_ap_interval_t() { return &c; } /* ================================= */ /* interval_array */ /* ================================= */ inline interval_array::interval_array(size_t size, ap_interval_t** c) : sz(size), c(c) {} /* constructors */ /* ============ */ inline interval_array::interval_array(size_t size) : sz(size), c(ap_interval_array_alloc(size)) {} inline interval_array::interval_array(const interval_array &x) : sz(x.sz), c(ap_interval_array_alloc(x.sz)) { for (size_t i=0;i& x) : sz(x.size()), c(ap_interval_array_alloc(x.size())) { for (size_t i=0;i(x[i].get_ap_interval_t())); } inline interval_array::interval_array(size_t size, const interval x[]) : sz(size), c(ap_interval_array_alloc(size)) { for (size_t i=0;i(x[i].get_ap_interval_t())); } /* destructor */ /* ========== */ inline interval_array::~interval_array() { ap_interval_array_free(c, sz); } /* assignment */ /* ========== */ inline interval_array& interval_array::operator= (const interval_array &x) { if (&x!=this) { if (sz != x.sz) { ap_interval_array_free(c, sz); sz = x.sz; c = ap_interval_array_alloc(sz); } for (size_t i=0;i& x) { if (sz != x.size()) { ap_interval_array_free(c, sz); sz = x.size(); c = ap_interval_array_alloc(sz); } for (size_t i=0;i(x[i].get_ap_interval_t())); return *this; } inline interval_array& interval_array::operator= (const interval x[]) { for (size_t i=0;i(x[i].get_ap_interval_t())); return *this; } /* conversion */ /* ========== */ inline interval_array::operator std::vector() const { std::vector v = std::vector(sz); for (size_t i=0;i(c[i])); fprintf(stream, " "); } fprintf(stream,"}"); } /* access */ /* ====== */ inline size_t interval_array::size() const { return sz; } inline interval** interval_array::contents() { return reinterpret_cast(c); } inline interval& interval_array::get(size_t i) { if (i >= sz) throw std::out_of_range("apron::interval_array::get(size_t)"); return reinterpret_cast(*c[i]); } inline const interval& interval_array::get(size_t i) const { if (i >= sz) throw std::out_of_range("apron::interval_array::get(size_t)"); return reinterpret_cast(*c[i]); } inline interval& interval_array::operator[](size_t i) { return reinterpret_cast(*c[i]); } inline const interval& interval_array::operator[](size_t i) const { return reinterpret_cast(*c[i]); } /* C API compatibility */ /* =================== */ inline const ap_interval_t * const * interval_array::get_ap_interval_t_array() const { return c; } inline ap_interval_t** interval_array::get_ap_interval_t_array() { return c; } apron-dist-0.9.10/apron/apronxx/apxx_abstract1_inline.hh0000640014525101416610000015643710723557216023216 0ustar bjeannetpopart/* -*- C++ -*- * apxx_abstract1_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ /* ================================= */ /* abstract1 */ /* ================================= */ /* constructors */ /* ============ */ inline abstract1::abstract1(ap_abstract1_t x) : a(x) {} inline abstract1::abstract1(manager &m, const environment& e, top x) { a = ap_abstract1_top(m.get_ap_manager_t(), const_cast(e.get_ap_environment_t())); m.raise("apron::abstract1::abstract1(manager &, const environment&, top)",a); } inline abstract1::abstract1(manager &m, const environment& e, bottom x) { a = ap_abstract1_bottom(m.get_ap_manager_t(), const_cast(e.get_ap_environment_t())); m.raise("apron::abstract1::abstract1(manager &, const environment&, bottom)",a); } inline abstract1::abstract1(manager &m, const abstract1& t) { a = ap_abstract1_copy(m.get_ap_manager_t(), const_cast(&t.a)); m.raise("apron::abstract1::abstract1(manager &, const abstract1&)",a); } inline abstract1::abstract1(manager &m, const environment& e, const abstract0& t) { a.env = ap_environment_copy(const_cast(e.get_ap_environment_t())); a.abstract0 = ap_abstract0_copy(m.get_ap_manager_t(), const_cast(t.get_ap_abstract0_t())); m.raise("apron::abstract1::abstract1(manager &, const abstract1&)",a); } inline abstract1::abstract1(manager &m, const environment& e, const var v[], const interval_array& x) { a = ap_abstract1_of_box(m.get_ap_manager_t(), const_cast(e.get_ap_environment_t()), reinterpret_cast(const_cast(v)), const_cast(x.get_ap_interval_t_array()), x.size()); m.raise("apron::abstract1::abstract1(manager &, const environment&, const var[], const interval_array&)",a); } inline abstract1::abstract1(manager &m, const environment& e, const std::vector& v, const interval_array& x) { if (v.size()!=x.size()) throw std::invalid_argument("apron::abstract1::abstract1(manager &, const environment&, const std::vector&, const interval_array&): different array sizes"); ap_var_t vv[v.size()]; for (size_t i=0;i(e.get_ap_environment_t()), vv, const_cast(x.get_ap_interval_t_array()), v.size()); m.raise("apron::abstract1::abstract1(manager &, const environment&, const std::vector&, const interval_array&)",a); } inline abstract1::abstract1(manager &m, const lincons1_array& x) { a = ap_abstract1_of_lincons_array(m.get_ap_manager_t(), const_cast(x.get_environment().get_ap_environment_t()), const_cast(x.get_ap_lincons1_array_t())); m.raise("apron::abstract1::abstract1(manager &, const lincons1_array&)",a); } inline abstract1::abstract1(manager &m, const tcons1_array& x) { a = ap_abstract1_of_tcons_array(m.get_ap_manager_t(), const_cast(x.get_environment().get_ap_environment_t()), const_cast(x.get_ap_tcons1_array_t())); m.raise("apron::abstract1::abstract1(manager &, const tcons1_array&)",a); } inline abstract1::abstract1(const abstract1& t) { a = ap_abstract1_copy(t.a.abstract0->man, const_cast(&t.a)); manager::raise(a.abstract0->man, "apron::abstract1::abstract1(abstract1&)",a); } /* destructor */ /* ========== */ inline abstract1::~abstract1() { if (a.abstract0) ap_abstract1_clear(a.abstract0->man, &a); } inline void abstract1::free(manager& m) { if (a.abstract0) ap_abstract1_clear(m.get_ap_manager_t(), &a); } /* assignments */ /* =========== */ inline abstract1& abstract1::operator=(const abstract1& t) { if (&t!=this) { ap_abstract1_t r = ap_abstract1_copy(a.abstract0->man, const_cast(&t.a)); manager::raise(a.abstract0->man, "apron::abstract1::operator=(const abstract1&)",r); ap_abstract1_clear(a.abstract0->man, &a); a = r; } return *this; } inline abstract1& abstract1::operator=(top t) { ap_abstract1_t r = ap_abstract1_top(a.abstract0->man, a.env); manager::raise(a.abstract0->man, "apron::abstract1::operator=(top)",r); ap_abstract1_clear(a.abstract0->man, &a); a = r; return *this; } inline abstract1& abstract1::operator=(bottom t) { ap_abstract1_t r = ap_abstract1_bottom(a.abstract0->man, a.env); manager::raise(a.abstract0->man, "apron::abstract1::operator=(bottom)",r); ap_abstract1_clear(a.abstract0->man, &a); a = r; return *this; } inline abstract1& abstract1::operator=(const interval_array& x) { ap_dimension_t d = ap_abstract0_dimension(a.abstract0->man, a.abstract0); if (x.size()man, d.intdim, d.realdim, const_cast(x.get_ap_interval_t_array())); manager::raise(a.abstract0->man, "apron::abstract1::operator=(const interval_array&)",r); ap_abstract0_free(a.abstract0->man, a.abstract0); a.abstract0 = r; return *this; } inline abstract1& abstract1::operator=(const lincons1_array& x) { ap_abstract1_t r = ap_abstract1_of_lincons_array(a.abstract0->man, const_cast(x.get_environment().get_ap_environment_t()), const_cast(x.get_ap_lincons1_array_t())); manager::raise(a.abstract0->man, "apron::abstract1::operator=(const lincons1_array&)",r); ap_abstract1_clear(a.abstract0->man, &a); a = r; return *this; } inline abstract1& abstract1::operator=(const tcons1_array& x) { ap_abstract1_t r = ap_abstract1_of_tcons_array(a.abstract0->man, const_cast(x.get_environment().get_ap_environment_t()), const_cast(x.get_ap_tcons1_array_t())); manager::raise(a.abstract0->man, "apron::abstract1::operator=(const tcons1_array&)",r); ap_abstract1_clear(a.abstract0->man, &a); a = r; return *this; } inline abstract1& abstract1::set(manager& m, const abstract1& x) { if (&x!=this) { ap_abstract1_t r = ap_abstract1_copy(m.get_ap_manager_t(), const_cast(&x.a)); m.raise("apron::abstract1::set(manager&, abstract1&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &a); a = r; } return *this; } inline abstract1& abstract1::set(manager& m, top t) { ap_abstract1_t r = ap_abstract1_top(m.get_ap_manager_t(), a.env); m.raise("apron::abstract1::set(manager&, top)",r); ap_abstract1_clear(m.get_ap_manager_t(), &a); a = r; return *this; } inline abstract1& abstract1::set(manager& m, const environment& e, top t) { ap_abstract1_t r = ap_abstract1_top(m.get_ap_manager_t(), const_cast(e.get_ap_environment_t())); m.raise("apron::abstract1::set(manager&, const environment&, top)",r); ap_abstract1_clear(m.get_ap_manager_t(), &a); a = r; return *this; } inline abstract1& abstract1::set(manager& m, bottom t) { ap_abstract1_t r = ap_abstract1_bottom(m.get_ap_manager_t(), a.env); m.raise("apron::abstract1::set(manager&, bottom)",r); ap_abstract1_clear(m.get_ap_manager_t(), &a); a = r; return *this; } inline abstract1& abstract1::set(manager& m, const environment& e, bottom t) { ap_abstract1_t r = ap_abstract1_bottom(m.get_ap_manager_t(), const_cast(e.get_ap_environment_t())); m.raise("apron::abstract1::set(manager&, const environment&, bottom)",r); ap_abstract1_clear(m.get_ap_manager_t(), &a); a = r; return *this; } inline abstract1& abstract1::set(manager& m, const interval_array& x) { ap_dimension_t d = ap_abstract0_dimension(m.get_ap_manager_t(), a.abstract0); if (x.size()(x.get_ap_interval_t_array())); m.raise("apron::abstract1::operator=(const interval_array&)",r); ap_abstract0_free(m.get_ap_manager_t(), a.abstract0); a.abstract0 = r; return *this; } inline abstract1& abstract1::set(manager &m, const environment& e, const var v[], const interval_array& x) { ap_abstract1_t r = ap_abstract1_of_box(m.get_ap_manager_t(), const_cast(e.get_ap_environment_t()), reinterpret_cast(const_cast(v)), const_cast(x.get_ap_interval_t_array()), x.size()); m.raise("apron::abstract1::set(manager &, const environment&, const var[], const interval_array&)",r); ap_abstract1_clear(m.get_ap_manager_t(),&a); a = r; return *this; } inline abstract1& abstract1::set(manager &m, const environment& e, const std::vector& v, const interval_array& x) { if (v.size()!=x.size()) throw std::invalid_argument("apron::abstract1::abstract1(manager &, const environment&, const std::vector&, const interval_array&): different array sizes"); ap_var_t vv[v.size()]; for (size_t i=0;i(e.get_ap_environment_t()), vv, const_cast(x.get_ap_interval_t_array()), v.size()); m.raise("apron::abstract1::set(manager &, const environment&, const std::vector&, const interval_array&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &a); a = r; return *this; } inline abstract1& abstract1::set(manager& m, const lincons1_array& x) { ap_abstract1_t r = ap_abstract1_of_lincons_array(m.get_ap_manager_t(), const_cast(x.get_environment().get_ap_environment_t()), const_cast(x.get_ap_lincons1_array_t())); m.raise("apron::abstract1::set(manager &, const lincons1_array&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &a); a = r; return *this; } inline abstract1& abstract1::set(manager& m, const tcons1_array& x) { ap_abstract1_t r = ap_abstract1_of_tcons_array(m.get_ap_manager_t(), const_cast(x.get_environment().get_ap_environment_t()), const_cast(x.get_ap_tcons1_array_t())); m.raise("apron::abstract1::set(manager &, const tcons1_array&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &a); a = r; return *this; } /* representation */ /* ============== */ inline abstract1& abstract1::minimize(manager& m) { ap_abstract1_minimize(m.get_ap_manager_t(), &a); m.raise("apron::abstract1::minimize(manager &)"); return *this; } inline abstract1& abstract1::canonicalize(manager& m) { ap_abstract1_canonicalize(m.get_ap_manager_t(), &a); m.raise("apron::abstract1::canonicalize(manager &)"); return *this; } inline abstract1& abstract1::approximate(manager& m, int algorithm) { ap_abstract1_approximate(m.get_ap_manager_t(), &a, algorithm); m.raise("apron::abstract1::approximate(manager &, int)"); return *this; } /* printing */ /* ======== */ inline void abstract1::print(manager& m, FILE* stream) const { ap_abstract1_fprint(stream, m.get_ap_manager_t(), const_cast(&a)); m.raise("apron::abstract1::print(manager&, FILE*)"); } inline void printdiff(manager& m, const abstract1& x, const abstract1& y, FILE* stream) { ap_abstract1_fprintdiff(stream, m.get_ap_manager_t(), const_cast(&x.a), const_cast(&y.a)); m.raise("apron::printdiff(manager&, const abstract1&, const abstract1&, FILE*)"); } inline void abstract1::dump(manager& m, FILE* stream) const { ap_abstract1_fdump(stream, m.get_ap_manager_t(), const_cast(&a)); m.raise("apron::abstract1::dump(manager&, FILE*)"); } inline std::ostream& operator<< (std::ostream& os, const abstract1& s) { manager m = s.get_manager(); if (s.is_bottom(m)) return os << "bottom"; if (s.is_top(m)) return os << "top"; return os << s.to_lincons_array(m); } /* serialisation */ /* ============= */ inline std::string* abstract1::serialize(manager& m) const { ap_membuf_t x = ap_abstract1_serialize_raw(m.get_ap_manager_t(), const_cast(&a)); m.raise("apron::abstract1::serialize_raw(manager&)"); std::string* s = new std::string((char*)x.ptr, x.size); ::free(x.ptr); return s; } inline abstract1& deserialize(manager& m, abstract1& dst, const std::string& s, size_t* eaten) { size_t x = s.size(); ap_abstract1_t r = ap_abstract1_deserialize_raw(m.get_ap_manager_t(), const_cast(s.data()), &x); m.raise("apron::deserialize_raw(manager&, abstract1&, const std::string&, size_t*)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; if (eaten) *eaten = x; return dst; } /* access */ /* ====== */ inline manager abstract1::get_manager() const { return ap_manager_copy(ap_abstract0_manager(const_cast(a.abstract0))); } inline environment abstract1::get_environment() const { return ap_environment_copy(const_cast(a.env)); } inline abstract0& abstract1::get_abstract0() { return reinterpret_cast(a.abstract0); } inline const abstract0& abstract1::get_abstract0() const { return reinterpret_cast(a.abstract0); } inline size_t abstract1::size(manager& m) const { size_t sz = ap_abstract1_size(m.get_ap_manager_t(), const_cast(&a)); m.raise("apron::abstract1::get_size(manager&)"); return sz; } /* predicates */ /* ========== */ inline bool abstract1::is_bottom(manager& m) const { bool r = ap_abstract1_is_bottom(m.get_ap_manager_t(), const_cast(&a)); m.raise("apron::abstract1::is_bottom(manager&)"); return r; } inline bool abstract1::is_top(manager& m) const { bool r = ap_abstract1_is_top(m.get_ap_manager_t(), const_cast(&a)); m.raise("apron::abstract1::is_top(manager&)"); return r; } inline bool abstract1::is_eq(manager& m, const abstract1& x) const { bool r = ap_abstract1_is_eq(m.get_ap_manager_t(), const_cast(&a), const_cast(&x.a)); m.raise("apron::abstract1::is_eq(manager&, const abstract&)"); return r; } inline bool abstract1::is_leq(manager& m, const abstract1& x) const { bool r = ap_abstract1_is_leq(m.get_ap_manager_t(), const_cast(&a), const_cast(&x.a)); m.raise("apron::abstract1::is_leq(manager&, const abstract&)"); return r; } inline bool abstract1::sat(manager& m, const lincons1& l) const { bool r = ap_abstract1_sat_lincons(m.get_ap_manager_t(), const_cast(&a), const_cast(l.get_ap_lincons1_t())); m.raise("apron::abstract1::sat(manager&, const lincons1&)"); return r; } inline bool abstract1::sat(manager& m, const tcons1& l) const { bool r = ap_abstract1_sat_tcons(m.get_ap_manager_t(), const_cast(&a), const_cast(l.get_ap_tcons1_t())); m.raise("apron::abstract1::sat(manager&, const tcons1&)"); return r; } inline bool abstract1::sat(manager& m, const var& v, const interval& i) const { bool r = ap_abstract1_sat_interval(m.get_ap_manager_t(), const_cast(&a), v.get_ap_var_t(), const_cast(i.get_ap_interval_t())); m.raise("apron::abstract1::sat(manager&, const var&, const interval&)"); return r; } inline bool abstract1::is_variable_unconstrained(manager& m, const var& v) const { bool r = ap_abstract1_is_variable_unconstrained(m.get_ap_manager_t(), const_cast(&a), v.get_ap_var_t()); m.raise("apron::abstract1::is_variable_unconstrained(manager&, const var&)"); return r; } inline bool operator== (const abstract1& x, const abstract1& y) { bool r = ap_abstract1_is_eq(x.a.abstract0->man, const_cast(&x.a), const_cast(&y.a)); manager::raise(x.a.abstract0->man, "apron::operator==(const abstract1&, const abstract1&)"); return r; } inline bool operator!= (const abstract1& x, const abstract1& y) { return !(x==y); } inline bool operator<= (const abstract1& x, const abstract1& y) { bool r = ap_abstract1_is_leq(x.a.abstract0->man, const_cast(&x.a), const_cast(&y.a)); manager::raise(x.a.abstract0->man, "apron::operator<=(const abstract1&, const abstract1&)"); return r; } inline bool operator>= (const abstract1& x, const abstract1& y) { return y<=x; } inline bool operator> (const abstract1& x, const abstract1& y) { return !(x<=y); } inline bool operator< (const abstract1& x, const abstract1& y) { return !(y<=x); } /* Properties */ /* ========== */ inline interval abstract1::bound(manager& m, const linexpr1& l) const { ap_interval_t* r = ap_abstract1_bound_linexpr(m.get_ap_manager_t(), const_cast(&a), const_cast(l.get_ap_linexpr1_t())); m.raise("apron::abstract1::bound(manager&, const linexpr1&)"); return r; } inline interval abstract1::bound(manager& m, const texpr1& l) const { ap_interval_t* r = ap_abstract1_bound_texpr(m.get_ap_manager_t(), const_cast(&a), const_cast(l.get_ap_texpr1_t())); if (m.exception_raised()) ap_interval_free(r); m.raise("apron::abstract1::bound(manager&, const texpr1&)"); return r; } inline interval abstract1::bound(manager& m, const var& d) const { ap_interval_t* r = ap_abstract1_bound_variable(m.get_ap_manager_t(), const_cast(&a), d.get_ap_var_t()); if (m.exception_raised()) ap_interval_free(r); m.raise("apron::abstract1::bound(manager&, ap_dim_t)"); return r; } inline interval_array abstract1::to_box(manager& m) const { ap_box1_t r = ap_abstract1_to_box(m.get_ap_manager_t(), const_cast(&a)); if (m.exception_raised()) ap_box1_clear(&r); m.raise("apron::abstract1::to_box(manager&)"); size_t sz = r.env->intdim + r.env->realdim; ap_environment_free(r.env); return interval_array(sz, r.p); } inline lincons1_array abstract1::to_lincons_array(manager& m) const { ap_lincons1_array_t r = ap_abstract1_to_lincons_array(m.get_ap_manager_t(), const_cast(&a)); if (m.exception_raised()) ap_lincons1_array_clear(&r); m.raise("apron::abstract1::to_lincons_array(manager&)"); return r; } inline tcons1_array abstract1::to_tcons_array(manager& m) const { ap_tcons1_array_t r = ap_abstract1_to_tcons_array(m.get_ap_manager_t(), const_cast(&a)); if (m.exception_raised()) ap_tcons1_array_clear(&r); m.raise("apron::abstract1::to_tcons_array(manager&)"); return r; } inline generator1_array abstract1::to_generator_array(manager& m) const { ap_generator1_array_t r = ap_abstract1_to_generator_array(m.get_ap_manager_t(), const_cast(&a)); if (m.exception_raised()) ap_generator1_array_clear(&r); m.raise("apron::abstract1::to_generator_array(manager&)"); return r; } /* Meet, join, unification */ /* ======================= */ inline abstract1& abstract1::unify(manager& m, const abstract1& y) { a = ap_abstract1_unify(m.get_ap_manager_t(), true, const_cast(&a), const_cast(&y.a)); m.raise("apron::abstract1::unify(manager&, const abstract1&)"); return *this; } inline abstract1& unify(manager& m, abstract1& dst, const abstract1& x, const abstract1& y) { ap_abstract1_t r = ap_abstract1_unify(m.get_ap_manager_t(), false, const_cast(&x.a), const_cast(&y.a)); m.raise("apron::unify(manager&, abstract1&, const abstract1&, const abstract1&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& abstract1::meet(manager& m, const abstract1& y) { a = ap_abstract1_meet(m.get_ap_manager_t(), true, const_cast(&a), const_cast(&y.a)); m.raise("apron::abstract1::meet(manager&, const abstract1&)"); return *this; } inline abstract1& meet(manager& m, abstract1& dst, const abstract1& x, const abstract1& y) { ap_abstract1_t r = ap_abstract1_meet(m.get_ap_manager_t(), false, const_cast(&x.a), const_cast(&y.a)); m.raise("apron::meet(manager&, abstract1&, const abstract1&, const abstract1&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& meet(manager& m, abstract1& dst, const std::vector& x) { ap_abstract1_t xx[x.size()]; for (size_t i=0;iget_ap_abstract1_t()); ap_abstract1_t r = ap_abstract1_meet_array(m.get_ap_manager_t(), xx, x.size()); m.raise("apron::meet(manager&, abstract1&, const std::vector&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& meet(manager& m, abstract1& dst, size_t sz, const abstract1 * const x[]) { ap_abstract1_t xx[sz]; for (size_t i=0;iget_ap_abstract1_t()); ap_abstract1_t r = ap_abstract1_meet_array(m.get_ap_manager_t(), xx, sz); m.raise("apron::meet(manager&, abstract1&, size_t, const abstract1 * const [])",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& abstract1::join(manager& m, const abstract1& y) { a = ap_abstract1_join(m.get_ap_manager_t(), true, const_cast(&a), const_cast(&y.a)); m.raise("apron::abstract1::join(manager&, const abstract1&)"); return *this; } inline abstract1& join(manager& m, abstract1& dst, const abstract1& x, const abstract1& y) { ap_abstract1_t r = ap_abstract1_join(m.get_ap_manager_t(), false, const_cast(&x.a), const_cast(&y.a)); m.raise("apron::join(manager&, abstract1&, const abstract1&, const abstract1&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& join(manager& m, abstract1& dst, size_t sz, const abstract1 * const x[]) { ap_abstract1_t xx[sz]; for (size_t i=0;iget_ap_abstract1_t()); ap_abstract1_t r = ap_abstract1_join_array(m.get_ap_manager_t(), xx, sz); m.raise("apron::join(manager&, abstract1&, size_t, const abstract1 * const [])",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& join(manager& m, abstract1& dst, const std::vector& x) { ap_abstract1_t xx[x.size()]; for (size_t i=0;iget_ap_abstract1_t()); ap_abstract1_t r = ap_abstract1_join_array(m.get_ap_manager_t(), xx, x.size()); m.raise("apron::join(manager&, abstract1&, const std::vector&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& abstract1::meet(manager& m, const lincons1_array& y) { a = ap_abstract1_meet_lincons_array(m.get_ap_manager_t(), true, const_cast(&a), const_cast(y.get_ap_lincons1_array_t())); m.raise("apron::abstract1::meet(manager&, const lincons1_array&)"); return *this; } inline abstract1& meet(manager& m, abstract1& dst, const abstract1& x, const lincons1_array& y) { ap_abstract1_t r = ap_abstract1_meet_lincons_array(m.get_ap_manager_t(), false, const_cast(&x.a), const_cast(y.get_ap_lincons1_array_t())); m.raise("apron::meet(manager&, abstract1&, const abstract1&, const lincons1_array&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& abstract1::meet(manager& m, const tcons1_array& y) { a = ap_abstract1_meet_tcons_array(m.get_ap_manager_t(), true, const_cast(&a), const_cast(y.get_ap_tcons1_array_t())); m.raise("apron::abstract1::meet(manager&, const tcons1_array&)"); return *this; } inline abstract1& meet(manager& m, abstract1& dst, const abstract1& x, const tcons1_array& y) { ap_abstract1_t r = ap_abstract1_meet_tcons_array(m.get_ap_manager_t(), false, const_cast(&x.a), const_cast(y.get_ap_tcons1_array_t())); m.raise("apron::meet(manager&, abstract1&, const abstract1&, const tcons1_array&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& abstract1::add_rays(manager& m, const generator1_array& y) { a = ap_abstract1_add_ray_array(m.get_ap_manager_t(), true, const_cast(&a), const_cast(y.get_ap_generator1_array_t())); m.raise("apron::abstract1::add_rays(manager&, const generator1_array&)"); return *this; } inline abstract1& add_rays(manager& m, abstract1& dst, const abstract1& x, const generator1_array& y) { ap_abstract1_t r = ap_abstract1_add_ray_array(m.get_ap_manager_t(), false, const_cast(&x.a), const_cast(y.get_ap_generator1_array_t())); m.raise("apron::add_rays(manager&, abstract1&, const abstract1&, const generator1_array&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& abstract1::operator*=(const abstract1& y) { a = ap_abstract1_meet(a.abstract0->man, true, const_cast(&a), const_cast(&y.a)); manager::raise(a.abstract0->man, "apron::abstract1::operator*=(const abstract1&)"); return *this; } inline abstract1& abstract1::operator+=(const abstract1& y) { a = ap_abstract1_join(a.abstract0->man, true, const_cast(&a), const_cast(&y.a)); manager::raise(a.abstract0->man, "apron::abstract1::operator+=(const abstract1&)"); return *this; } inline abstract1& abstract1::operator*=(const lincons1_array& y) { a = ap_abstract1_meet_lincons_array(a.abstract0->man, true, const_cast(&a), const_cast(y.get_ap_lincons1_array_t())); manager::raise(a.abstract0->man, "apron::abstract1::operator*=(const lincons1_array&)"); return *this; } inline abstract1& abstract1::operator*=(const tcons1_array& y) { a = ap_abstract1_meet_tcons_array(a.abstract0->man, true, const_cast(&a), const_cast(y.get_ap_tcons1_array_t())); manager::raise(a.abstract0->man, "apron::abstract1::operator*=(const tcons1_array&)"); return *this; } inline abstract1& abstract1::operator+=(const generator1_array& y) { a = ap_abstract1_add_ray_array(a.abstract0->man, true, const_cast(&a), const_cast(y.get_ap_generator1_array_t())); manager::raise(a.abstract0->man, "apron::abstract1::operator+=(const generator1_array&)"); return *this; } /* Assignments */ /* =========== */ static inline ap_abstract1_t* ap_abstract1_t_or_null(const abstract1& i) { ap_abstract1_t* r = const_cast(i.get_ap_abstract1_t()); if (r->abstract0) return r; return NULL; } inline abstract1& abstract1::assign(manager& m, const var& v, const linexpr1& l, const abstract1& inter) { a = ap_abstract1_assign_linexpr_array(m.get_ap_manager_t(), true, &a, reinterpret_cast(const_cast(&v)), const_cast(l.get_ap_linexpr1_t()), 1, ap_abstract1_t_or_null(inter)); m.raise("apron::abstract1::assign(manager&, size_t size, const var&, const linexpr1&, const abstract1&)"); return *this; } inline abstract1& abstract1::assign(manager& m, size_t size, const var v[], const linexpr1 * const l[], const abstract1& inter) { ap_linexpr1_t ll[size]; for (size_t i=0;iget_ap_linexpr1_t()); a = ap_abstract1_assign_linexpr_array(m.get_ap_manager_t(), true, &a, reinterpret_cast(const_cast(v)), ll, size, ap_abstract1_t_or_null(inter)); m.raise("apron::abstract1::assign(manager&, size_t size, const var[], const linexpr1 * const [], const abstract1&)"); return *this; } inline abstract1& abstract1::assign(manager& m, const std::vector& v, const std::vector& l, const abstract1& inter) { if (l.size()!=v.size()) throw std::invalid_argument("apron::abstract1::assign(manager&, const std::vector&, const std::vector&, const abstract1&) vectors have different size"); ap_linexpr1_t ll[l.size()]; ap_var_t vv[v.size()]; for (size_t i=0;iget_ap_linexpr1_t()); vv[i] = v[i].get_ap_var_t(); } a = ap_abstract1_assign_linexpr_array(m.get_ap_manager_t(), true, &a, vv, ll, l.size(), ap_abstract1_t_or_null(inter)); m.raise("apron::abstract1::assign(manager&, const std::vector&, const std::vector&, const abstract1&)"); return *this; } inline abstract1& assign(manager& m, abstract1& dst, const abstract1& src, const var& v, const linexpr1& l, const abstract1& inter) { ap_abstract1_t r = ap_abstract1_assign_linexpr_array(m.get_ap_manager_t(), false, const_cast(&src.a), reinterpret_cast(const_cast(&v)), const_cast(l.get_ap_linexpr1_t()), 1, ap_abstract1_t_or_null(inter)); m.raise("apron::assign(manager&, abstract1&, const abstract1&, const var&, const linexpr1&, const abstract1&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& assign(manager& m, abstract1& dst, const abstract1& src, size_t size, const var v[], const linexpr1 * const l[], const abstract1& inter) { ap_linexpr1_t ll[size]; for (size_t i=0;iget_ap_linexpr1_t()); ap_abstract1_t r = ap_abstract1_assign_linexpr_array(m.get_ap_manager_t(), false, const_cast(&src.a), reinterpret_cast(const_cast(v)), ll, size, ap_abstract1_t_or_null(inter)); m.raise("apron::assign((manager&, abstract1&, const abstract1&, size_t size, const var[], const linexpr1 * const [], const abstract1&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& assign(manager& m, abstract1& dst, const abstract1& src, const std::vector& v, const std::vector& l, const abstract1& inter) { if (l.size()!=v.size()) throw std::invalid_argument("apron::assign(manager&, abstract1, const abstract1&, const std::vector&, const std::vector&, const abstract1&) vectors have different size"); ap_linexpr1_t ll[l.size()]; ap_var_t vv[v.size()]; for (size_t i=0;iget_ap_linexpr1_t()); vv[i] = v[i].get_ap_var_t(); } ap_abstract1_t r = ap_abstract1_assign_linexpr_array(m.get_ap_manager_t(), false, const_cast(&src.a), vv, ll, l.size(), ap_abstract1_t_or_null(inter)); m.raise("apron::assign(manager&, abstract1, const abstract1&, const std::vector&, const std::vector&, const abstract1&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& abstract1::assign(manager& m, const var& v, const texpr1& l, const abstract1& inter) { a = ap_abstract1_assign_texpr_array(m.get_ap_manager_t(), true, &a, reinterpret_cast(const_cast(&v)), const_cast(l.get_ap_texpr1_t()), 1, ap_abstract1_t_or_null(inter)); m.raise("apron::abstract1::assign(manager&, size_t size, const var&, const texpr1&, const abstract1&)"); return *this; } inline abstract1& abstract1::assign(manager& m, size_t size, const var v[], const texpr1 * const l[], const abstract1& inter) { ap_texpr1_t ll[size]; for (size_t i=0;iget_ap_texpr1_t()); a = ap_abstract1_assign_texpr_array(m.get_ap_manager_t(), true, &a, reinterpret_cast(const_cast(v)), ll, size, ap_abstract1_t_or_null(inter)); m.raise("apron::abstract1::assign(manager&, size_t size, const var[], const texpr1 * const [], const abstract1&)"); return *this; } inline abstract1& abstract1::assign(manager& m, const std::vector& v, const std::vector& l, const abstract1& inter) { if (l.size()!=v.size()) throw std::invalid_argument("apron::abstract1::assign(manager&, const std::vector&, const std::vector&, const abstract1&) vectors have different size"); ap_texpr1_t ll[l.size()]; ap_var_t vv[v.size()]; for (size_t i=0;iget_ap_texpr1_t()); vv[i] = v[i].get_ap_var_t(); } a = ap_abstract1_assign_texpr_array(m.get_ap_manager_t(), true, &a, vv, ll, l.size(), ap_abstract1_t_or_null(inter)); m.raise("apron::abstract1::assign(manager&, const std::vector&, const std::vector&, const abstract1&) vectors have different size"); return *this; } inline abstract1& assign(manager& m, abstract1& dst, const abstract1& src, const var& v, const texpr1& l, const abstract1& inter) { ap_abstract1_t r = ap_abstract1_assign_texpr_array(m.get_ap_manager_t(), false, const_cast(&src.a), reinterpret_cast(const_cast(&v)), const_cast(l.get_ap_texpr1_t()), 1, ap_abstract1_t_or_null(inter)); m.raise("apron::assign(manager&, abstract1&, const abstract1&, const var&, const texpr1&, const abstract1&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& assign(manager& m, abstract1& dst, const abstract1& src, size_t size, const var v[], const texpr1 * const l[], const abstract1& inter) { ap_texpr1_t ll[size]; for (size_t i=0;iget_ap_texpr1_t()); ap_abstract1_t r = ap_abstract1_assign_texpr_array(m.get_ap_manager_t(), false, const_cast(&src.a), reinterpret_cast(const_cast(v)), ll, size, ap_abstract1_t_or_null(inter)); m.raise("apron::assign((manager&, abstract1&, const abstract1&, size_t size, const var[], const texpr1 * const [], const abstract1&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& assign(manager& m, abstract1& dst, const abstract1& src, const std::vector& v, const std::vector& l, const abstract1& inter) { if (l.size()!=v.size()) throw std::invalid_argument("apron::assign(manager&, abstract1, const abstract1&, const std::vector&, const std::vector&, const abstract1&) vectors have different size"); ap_texpr1_t ll[l.size()]; ap_var_t vv[v.size()]; for (size_t i=0;iget_ap_texpr1_t()); vv[i] = v[i].get_ap_var_t(); } ap_abstract1_t r = ap_abstract1_assign_texpr_array(m.get_ap_manager_t(), false, const_cast(&src.a), vv, ll, l.size(), ap_abstract1_t_or_null(inter)); m.raise("apron::assign(manager&, abstract1, const abstract1&, const std::vector&, const std::vector&, const abstract1&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } /* Substitutions */ /* =========== = */ inline abstract1& abstract1::substitute(manager& m, const var& v, const linexpr1& l, const abstract1& inter) { a = ap_abstract1_substitute_linexpr_array(m.get_ap_manager_t(), true, &a, reinterpret_cast(const_cast(&v)), const_cast(l.get_ap_linexpr1_t()), 1, ap_abstract1_t_or_null(inter)); m.raise("apron::abstract1::substitute(manager&, size_t size, const var&, const linexpr1&, const abstract1&)"); return *this; } inline abstract1& abstract1::substitute(manager& m, size_t size, const var v[], const linexpr1 * const l[], const abstract1& inter) { ap_linexpr1_t ll[size]; for (size_t i=0;iget_ap_linexpr1_t()); a = ap_abstract1_substitute_linexpr_array(m.get_ap_manager_t(), true, &a, reinterpret_cast(const_cast(v)), ll, size, ap_abstract1_t_or_null(inter)); m.raise("apron::abstract1::substitute(manager&, size_t size, const var[], const linexpr1 * const [], const abstract1&)"); return *this; } inline abstract1& abstract1::substitute(manager& m, const std::vector& v, const std::vector& l, const abstract1& inter) { if (l.size()!=v.size()) throw std::invalid_argument("apron::abstract1::substitute(manager&, const std::vector&, const std::vector&, const abstract1&) vectors have different size"); ap_linexpr1_t ll[l.size()]; ap_var_t vv[v.size()]; for (size_t i=0;iget_ap_linexpr1_t()); vv[i] = v[i].get_ap_var_t(); } a = ap_abstract1_substitute_linexpr_array(m.get_ap_manager_t(), true, &a, vv, ll, l.size(), ap_abstract1_t_or_null(inter)); m.raise("apron::abstract1::substitute(manager&, const std::vector&, const std::vector&, const abstract1&)"); return *this; } inline abstract1& substitute(manager& m, abstract1& dst, const abstract1& src, const var& v, const linexpr1& l, const abstract1& inter) { ap_abstract1_t r = ap_abstract1_substitute_linexpr_array(m.get_ap_manager_t(), false, const_cast(&src.a), reinterpret_cast(const_cast(&v)), const_cast(l.get_ap_linexpr1_t()), 1, ap_abstract1_t_or_null(inter)); m.raise("apron::substitute(manager&, abstract1&, const abstract1&, const var&, const linexpr1&, const abstract1&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& substitute(manager& m, abstract1& dst, const abstract1& src, size_t size, const var v[], const linexpr1 * const l[], const abstract1& inter) { ap_linexpr1_t ll[size]; for (size_t i=0;iget_ap_linexpr1_t()); ap_abstract1_t r = ap_abstract1_substitute_linexpr_array(m.get_ap_manager_t(), false, const_cast(&src.a), reinterpret_cast(const_cast(v)), ll, size, ap_abstract1_t_or_null(inter)); m.raise("apron::substitute((manager&, abstract1&, const abstract1&, size_t size, const var[], const linexpr1 * const [], const abstract1&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& substitute(manager& m, abstract1& dst, const abstract1& src, const std::vector& v, const std::vector& l, const abstract1& inter) { if (l.size()!=v.size()) throw std::invalid_argument("apron::substitute(manager&, abstract1, const abstract1&, const std::vector&, const std::vector&, const abstract1&) vectors have different size"); ap_linexpr1_t ll[l.size()]; ap_var_t vv[v.size()]; for (size_t i=0;iget_ap_linexpr1_t()); vv[i] = v[i].get_ap_var_t(); } ap_abstract1_t r = ap_abstract1_substitute_linexpr_array(m.get_ap_manager_t(), false, const_cast(&src.a), vv, ll, l.size(), ap_abstract1_t_or_null(inter)); m.raise("apron::substitute(manager&, abstract1, const abstract1&, const std::vector&, const std::vector&, const abstract1&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& abstract1::substitute(manager& m, const var& v, const texpr1& l, const abstract1& inter) { a = ap_abstract1_substitute_texpr_array(m.get_ap_manager_t(), true, &a, reinterpret_cast(const_cast(&v)), const_cast(l.get_ap_texpr1_t()), 1, ap_abstract1_t_or_null(inter)); m.raise("apron::abstract1::substitute(manager&, size_t size, const var&, const texpr1&, const abstract1&)"); return *this; } inline abstract1& abstract1::substitute(manager& m, size_t size, const var v[], const texpr1 * const l[], const abstract1& inter) { ap_texpr1_t ll[size]; for (size_t i=0;iget_ap_texpr1_t()); a = ap_abstract1_substitute_texpr_array(m.get_ap_manager_t(), true, &a, reinterpret_cast(const_cast(v)), ll, size, ap_abstract1_t_or_null(inter)); m.raise("apron::abstract1::substitute(manager&, size_t size, const var[], const texpr1 * const [], const abstract1&)"); return *this; } inline abstract1& abstract1::substitute(manager& m, const std::vector& v, const std::vector& l, const abstract1& inter) { if (l.size()!=v.size()) throw std::invalid_argument("apron::abstract1::substitute(manager&, const std::vector&, const std::vector&, const abstract1&) vectors have different size"); ap_texpr1_t ll[l.size()]; ap_var_t vv[v.size()]; for (size_t i=0;iget_ap_texpr1_t()); vv[i] = v[i].get_ap_var_t(); } a = ap_abstract1_substitute_texpr_array(m.get_ap_manager_t(), true, &a, vv, ll, l.size(), ap_abstract1_t_or_null(inter)); m.raise("apron::abstract1::substitute(manager&, const std::vector&, const std::vector&, const abstract1&) vectors have different size"); return *this; } inline abstract1& substitute(manager& m, abstract1& dst, const abstract1& src, const var& v, const texpr1& l, const abstract1& inter) { ap_abstract1_t r = ap_abstract1_substitute_texpr_array(m.get_ap_manager_t(), false, const_cast(&src.a), reinterpret_cast(const_cast(&v)), const_cast(l.get_ap_texpr1_t()), 1, ap_abstract1_t_or_null(inter)); m.raise("apron::substitute(manager&, abstract1&, const abstract1&, const var&, const texpr1&, const abstract1&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& substitute(manager& m, abstract1& dst, const abstract1& src, size_t size, const var v[], const texpr1 * const l[], const abstract1& inter) { ap_texpr1_t ll[size]; for (size_t i=0;iget_ap_texpr1_t()); ap_abstract1_t r = ap_abstract1_substitute_texpr_array(m.get_ap_manager_t(), false, const_cast(&src.a), reinterpret_cast(const_cast(v)), ll, size, ap_abstract1_t_or_null(inter)); m.raise("apron::substitute((manager&, abstract1&, const abstract1&, size_t size, const var[], const texpr1 * const [], const abstract1&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& substitute(manager& m, abstract1& dst, const abstract1& src, const std::vector& v, const std::vector& l, const abstract1& inter) { if (l.size()!=v.size()) throw std::invalid_argument("apron::substitute(manager&, abstract1, const abstract1&, const std::vector&, const std::vector&, const abstract1&) vectors have different size"); ap_texpr1_t ll[l.size()]; ap_var_t vv[v.size()]; for (size_t i=0;iget_ap_texpr1_t()); vv[i] = v[i].get_ap_var_t(); } ap_abstract1_t r = ap_abstract1_substitute_texpr_array(m.get_ap_manager_t(), false, const_cast(&src.a), vv, ll, l.size(), ap_abstract1_t_or_null(inter)); m.raise("apron::substitute(manager&, abstract1, const abstract1&, const std::vector&, const std::vector&, const abstract1&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } /* Projection */ /* ========== */ inline abstract1& abstract1::forget(manager& m, const var& v, bool project) { return forget(m,1,&v,project); } inline abstract1& abstract1::forget(manager& m, size_t size, const var v[], bool project) { a = ap_abstract1_forget_array(m.get_ap_manager_t(), true, &a, reinterpret_cast(const_cast(v)), size, project); m.raise("apron::abstract1::forget(manager&, size_t, const var[], bool)"); return *this; } inline abstract1& abstract1::forget(manager& m, const std::vector& v, bool project) { ap_var_t vv[v.size()]; for (size_t i=0;i&, bool)"); return *this; } inline abstract1& forget(manager& m, abstract1& dst, const abstract1& src, const var& v, bool project) { return forget(m,dst,src,1,&v,project); } inline abstract1& forget(manager& m, abstract1& dst, const abstract1& src, size_t size, const var v[], bool project) { ap_abstract1_t r = ap_abstract1_forget_array(m.get_ap_manager_t(), false, const_cast(&src.a), reinterpret_cast(const_cast(v)), size, project); m.raise("apron::forget(manager&, abstract1&, const abstract1&, size_t, const var[], bool)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& forget(manager& m, abstract1& dst, const abstract1& src, const std::vector& v, bool project) { ap_var_t vv[v.size()]; for (size_t i=0;i(&src.a), vv, v.size(), project); m.raise("apron::forget(manager&, abstract1&, const abstract1&, const std::vector&, bool)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } /* Change of environment */ /* ====================== */ inline abstract1& abstract1::change_environment(manager& m, const environment& e, bool project) { a = ap_abstract1_change_environment(m.get_ap_manager_t(), true, &a, const_cast(e.get_ap_environment_t()), project); m.raise("apron::abstract1::change_environment(manager&, const environment&, bool)"); return *this; } inline abstract1& change_environment(manager& m, abstract1& dst, const abstract1& src, const environment& e, bool project) { ap_abstract1_t r = ap_abstract1_change_environment(m.get_ap_manager_t(), false, const_cast(&src.a), const_cast(e.get_ap_environment_t()), project); m.raise("apron::change_environment(manager&, abstrct1&, const abstract1&, const environment&, bool)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& abstract1::minimize_environment(manager& m) { a = ap_abstract1_minimize_environment(m.get_ap_manager_t(), true, &a); m.raise("apron::abstract1::minimize_environment(manager&)"); return *this; } inline abstract1& minimize_environment(manager& m, abstract1& dst, const abstract1& src) { ap_abstract1_t r = ap_abstract1_minimize_environment(m.get_ap_manager_t(), false, const_cast(&src.a)); m.raise("apron::minimize_environment(manager&, abstract1&, const abstract1&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& abstract1::rename(manager& m, size_t size, const var oldv[], const var newv[]) { a = ap_abstract1_rename_array(m.get_ap_manager_t(), true, &a, reinterpret_cast(const_cast(oldv)), reinterpret_cast(const_cast(newv)), size); m.raise("apron::abstract1::rename(manager&, size_t, const var[], const var[])"); return *this; } inline abstract1& abstract1::rename(manager& m, const std::vector& oldv, const std::vector& newv) { if (oldv.size()!=newv.size()) throw std::invalid_argument("apron::abstract1::rename(manager&, const std::vector&, const std::vector&) vector have different size"); ap_var_t oldvv[oldv.size()]; ap_var_t newvv[newv.size()]; for (size_t i=0;i&, const std::vector&)"); return *this; } inline abstract1& rename(manager& m, abstract1& dst, const abstract1& src, size_t size, const var oldv[], const var newv[]) { ap_abstract1_t r = ap_abstract1_rename_array(m.get_ap_manager_t(), false, const_cast(&src.a), reinterpret_cast(const_cast(oldv)), reinterpret_cast(const_cast(newv)), size); m.raise("apron::rename(manager&, abstract1&, const abstract1&, size_t, const var[], const var[])",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& rename(manager& m, abstract1& dst, const abstract1& src, const std::vector& oldv, const std::vector& newv) { if (oldv.size()!=newv.size()) throw std::invalid_argument("apron::abstract1::rename(manager&, abstract1&, const abstract1&, const std::vector&, const std::vector&) vector have different size"); ap_var_t oldvv[oldv.size()]; ap_var_t newvv[newv.size()]; for (size_t i=0;i(&src.a), oldvv, newvv, oldv.size()); m.raise("apron::rename(manager&, abstract1&, const abstract1&, const std::vector&, const std::vector&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } /* Expansion and folding */ /* ===================== */ inline abstract1& abstract1::expand(manager& m, const var& v, size_t size, const var vv[]) { a = ap_abstract1_expand(m.get_ap_manager_t(), true, &a, const_cast(v.get_ap_var_t()), reinterpret_cast(const_cast(vv)), size); m.raise("apron::abstract1::expand(manager&, const var&, size_t, const var[])"); return *this; } inline abstract1& abstract1::expand(manager& m, const var& v, const std::vector& vv) { ap_var_t ww[vv.size()]; for (size_t i=0;i(v.get_ap_var_t()), ww, vv.size()); m.raise("apron::abstract1::expand(manager&, const var&, const std::vector&)"); return *this; } inline abstract1& expand(manager& m, abstract1& dst, const abstract1& src, const var& v, size_t size, const var vv[]) { ap_abstract1_t r = ap_abstract1_expand(m.get_ap_manager_t(), false, const_cast(&src.a), const_cast(v.get_ap_var_t()), reinterpret_cast(const_cast(vv)), size); m.raise("apron::expand(manager&, abstract1&, const abstract1&, const var&, size_t, const var[])",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& expand(manager& m, abstract1& dst, const abstract1& src, const var& v, const std::vector& vv) { ap_var_t ww[vv.size()]; for (size_t i=0;i(&src.a), const_cast(v.get_ap_var_t()), ww, vv.size()); m.raise("apron::expand(manager&, abstract1&, const abstract1&, const var&, const std::vector&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& abstract1::fold(manager& m, size_t size, const var vv[]) { a = ap_abstract1_fold(m.get_ap_manager_t(), true, &a, reinterpret_cast(const_cast(vv)), size); m.raise("apron::abstract1::fold(manager&, const var&, size_t, const var[])"); return *this; } inline abstract1& abstract1::fold(manager& m, const std::vector& vv) { ap_var_t ww[vv.size()]; for (size_t i=0;i&)"); return *this; } inline abstract1& fold(manager& m, abstract1& dst, const abstract1& src, size_t size, const var vv[]) { ap_abstract1_t r = ap_abstract1_fold(m.get_ap_manager_t(), false, const_cast(&src.a), reinterpret_cast(const_cast(vv)), size); m.raise("apron::fold(manager&, abstract1&, const abstract1&, size_t, const var[])",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& fold(manager& m, abstract1& dst, const abstract1& src, const std::vector& vv) { ap_var_t ww[vv.size()]; for (size_t i=0;i(&src.a), ww, vv.size()); m.raise("apron::fold(manager&, abstract1&, const abstract1&, const std::vector&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } /* Widenings */ /* ========= */ inline abstract1& widening(manager& m, abstract1& dst, const abstract1& x, const abstract1& y) { ap_abstract1_t r = ap_abstract1_widening(m.get_ap_manager_t(), const_cast(&x.a), const_cast(&y.a)); m.raise("apron::widening(manager&, abstract1&, const abstract1&, const abstract1&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } inline abstract1& widening(manager& m, abstract1& dst, const abstract1& x, const abstract1& y, const lincons1_array& l) { ap_abstract1_t r = ap_abstract1_widening_threshold(m.get_ap_manager_t(), const_cast(&x.a), const_cast(&y.a), const_cast(l.get_ap_lincons1_array_t())); m.raise("apron::widening(manager&, abstract1&, const abstract1&, const abstract1&, const lincons1_array&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } /* Closure */ /* ======= */ inline abstract1& abstract1::closure(manager& m) { a = ap_abstract1_closure(m.get_ap_manager_t(), true, &a); m.raise("apron::abstract1::closured(manager&)"); return *this; } inline abstract1& closure(manager& m, abstract1& dst, const abstract1& src) { ap_abstract1_t r = ap_abstract1_closure(m.get_ap_manager_t(), false, const_cast(&src.a)); m.raise("apron::closure(manager&, abstract1&, const abstract1&)",r); ap_abstract1_clear(m.get_ap_manager_t(), &dst.a); dst.a = r; return dst; } /* C-level compatibility */ /* ===================== */ inline ap_abstract1_t* abstract1::get_ap_abstract1_t() { return &a; } inline const ap_abstract1_t* abstract1::get_ap_abstract1_t() const { return &a; } apron-dist-0.9.10/apron/apronxx/apxx_lincons1.hh0000640014525101416610000003366410703144237021507 0ustar bjeannetpopart/* -*- C++ -*- * apxx_lincons1.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_LINCONS1_HH #define __APXX_LINCONS1_HH #include "ap_lincons1.h" #include "apxx_environment.hh" #include "apxx_lincons0.hh" #include "apxx_linexpr1.hh" namespace apron { /* ================================= */ /* lincons1 */ /* ================================= */ /*! \brief Level 1 linear constraint (ap_lincons1_t wrapper). * * Level 1 version of linear constraints with scalar or interval coefficients (coeff). * Terms are indexed using variable names (var) instead of dimensions (ap_dim_t). * Internally, a lincons1 wraps together a lincons0 (memory managed) and an environment (holding a * reference count). */ class lincons1 : public use_malloc { protected: ap_lincons1_t l; //!< Structure managed by APRON. //! Internal use only. Shallow copy (no copy of lincons0 or environment). lincons1(ap_lincons1_t p); friend class lincons1_array; public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ /*! \brief Creates a new constraint from a lincons0 (copied) and an environment (reference count * incremented) associating names to dimensions in lincons0. */ lincons1(const environment& e, const lincons0& x); /*! \brief Creates a new (non-modulo) constraint from an empty linear expression. * * The auxiliary scalar is not created (has_modulo returns false). * The linear expression is created sparse and empty (has_linexpr returns true). * \arg \c e associates a variable name to each dimension (reference counter incremented). * \arg \c constyp can be \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, or \c AP_CONS_DISEQ (but not \c AP_CONS_EQMOD). */ lincons1(const environment& e, ap_constyp_t constyp=AP_CONS_SUPEQ); /*! \brief Creates a new (non-modulo) constraint from a linear expression (copied). * * The auxiliary scalar is not created (has_modulo returns false). * \arg \c constyp can be \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, or \c AP_CONS_DISEQ (but not \c AP_CONS_EQMOD). */ lincons1(ap_constyp_t constyp, const linexpr1& lin); /*! \brief Creates a new constraint from a linear expression and a modulo scalar (both copied). * * \arg \c constyp can be \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, \c AP_CONS_EQMOD, or \c AP_CONS_DISEQ. */ lincons1(ap_constyp_t constyp, const linexpr1& lin, const scalar& modulo); //! Makes an unsatisfiable constraint (-1>=0). lincons1(const environment& e, unsat x); //! (Deep) copy of a constraint. lincons1(const lincons1& x); /*! \brief Makes a (deep) copy of x and extends its environment. * * \throw std::invalid_argument if e is not a super-environment of that of x. */ lincons1(const lincons1& x, const environment& e); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ /*! \brief Frees all space for the expression and coefficients, and decrements the reference count * of the environment. */ ~lincons1(); //@} /* assignment */ /* ========== */ /** @name Assignment */ //@{ //! Makes a (deep) copy. lincons1& operator= (const lincons1& x); //! Assigns an unsatisfiable constraint to *this (-1>=0). lincons1& operator= (unsat x); /*! \brief Sets the auxiliary scalar modulo to c (copied). * * Does not fail as get_modulo can: if the constraint was created without an auxiliary scalar, * it is created. */ void set_modulo(const scalar& c); /*! \brief Sets the underlying linear expression to c (copied). * * Does not fail as get_linexpr can: if the constraint was created without an underlying expression, * it is created. * * \warning assumes that c and *this have equal environments (unchecked). */ void set_linexpr(const linexpr1& c); //@} /* dimension operations */ /* ==================== */ /** @name Dimension operations */ //@{ /*! \brief Extends the environment of the expression. * * \throw std::invalid_argument if e is not a super-environment of that of *this. */ void extend_environment(const environment& e); //@} /* access */ /* ====== */ /** @name Accesses, size */ //@{ //! Returns the environment of the constraint (with incremented reference count). environment get_environment() const; //! Returns a reference to the underlying lincons0. const lincons0& get_lincons0() const; //! Returns a (modifiable) reference to the underlying lincons0. lincons0& get_lincons0(); /*! \brief Returns the size of the underlying linear expression. * * \throw std::invalid_argument if no valid linear expression has been defined. */ size_t size() const; /*! \brief Returns a (modifiable) reference to the constraint type. * * \return either \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, \c AP_CONS_EQMOD, or \c AP_CONS_DISEQ. */ ap_constyp_t& get_constyp(); /*! \brief Returns a reference to the constraint type. * * \return either \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, \c AP_CONS_EQMOD, or \c AP_CONS_DISEQ. */ const ap_constyp_t& get_constyp() const; //! Whether the constraint has a valid auxiliary scalar (used in modulo constraints). bool has_modulo() const; /*! \brief Whether the constraint has a valid linear expression. * * \note The only way the linear expression may be invalid is when accessing fields of uninitialised * (or enlarged) lincons1_array. */ bool has_linexpr() const; /*! \brief Returns a (modifiable) reference to the auxiliary scalar. * * \throw std::invalid_argument if no valid auxiliary scalar has been defined. */ scalar& get_modulo(); /*! \brief Returns a reference to the auxiliary scalar. * * \throw std::invalid_argument if no valid auxiliary scalar has been defined. */ const scalar& get_modulo() const; /*! \brief Returns a copy of the underlying linear expression. * * \throw std::invalid_argument if no valid linear expression has been defined. */ linexpr1 get_linexpr() const; /*! \brief Returns a (modifiable) reference to the constant coefficient. * * \throw std::invalid_argument if no valid linear expression has been defined. */ coeff& get_cst(); /*! \brief Returns a reference to the constant coefficient. * * \throw std::invalid_argument if no valid linear expression has been defined. */ const coeff& get_cst() const; /*! \brief Returns a (modifiable) reference to the coefficient corresponding to the given variable name. * * \throw std::invalid_argument if the variable name is not present in the environment. * \throw std::invalid_argument if no valid linear expression has been defined. */ coeff& operator[](const var& v); /*! \brief Returns a reference to the coefficient corresponding to the given variable name. * * \throw std::invalid_argument if the variable name is not present in the environment. * \throw std::invalid_argument if no valid linear expression has been defined. */ const coeff& operator[](const var& v) const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ //! Printing. friend std::ostream& operator<< (std::ostream& os, const lincons1& s); //! Prints to a C stream. void print(FILE* stream=stdout) const; //@} /* tests */ /* ===== */ /** @name Tests */ //@{ /*! \brief Whether the constraint is unsatisfiable. * * \throw std::invalid_argument if no valid linear expression has been defined. */ bool is_unsat() const; /*! \brief Whether the underlying linear expression has only scalar coefficients. * * \throw std::invalid_argument if no valid linear expression has been defined. */ bool is_linear() const; /*! \brief Whether the underlying linear expression has only scalar coefficients, * except maybe for the constant one. * * \throw std::invalid_argument if no valid linear expression has been defined. */ bool is_quasilinear() const; // TODO: equal, compare (currently not in ap_lincons1.h) ??? //@} /* TODO: evaluation, linearization, intelligent constructors */ /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. const ap_lincons1_t* get_ap_lincons1_t() const; //! Returns a pointer to the internal APRON object stored in *this. ap_lincons1_t* get_ap_lincons1_t(); //@} }; /* ================================= */ /* lincons1_array */ /* ================================= */ /*! \brief Array of linear constraints (ap_lincons1_array_t wrapper). * * Level 1 version of linear constraint arrays. * Internally, a lincons1_array wraps together a lincons0_array (memory managed) and an environment * (holding a reference count). * Please note that all constraints share the same environment! */ class lincons1_array : public use_malloc { protected: ap_lincons1_array_t a; //!< Structure managed by APRON. //! Internal use only. Shallow copy (no copy of lincons0_array or environment). lincons1_array(ap_lincons1_array_t& a); friend class abstract1; public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ /*! \brief Creates a new constraint array from a lincons0_array (copied) and an environment (reference count * incremented) associating names to dimensions. */ lincons1_array(const environment& e, const lincons0_array& x); /*! \brief Creates a new array of the given size containing uninitialized constraints. * * has_modulo and has_linexpr will return false on all elements of the array. * \arg \c e associates a variable name to each dimension (reference count incremented). */ lincons1_array(const environment& e, size_t size); //! (Deep) copy. lincons1_array(const lincons1_array& x); /*! \brief Makes a (deep) copy of x and extends its environment. * * \throw std::invalid_argument if e is not a super-environment of that of x. */ lincons1_array(const lincons1_array& x, const environment& e); /*! \brief Creates a lincons1_array from an array (of size >0) of constraints of the given size (copied). * * \warning assumes that all constraints have the same environment (unchecked). * \throw std::invalid_argument if size<1. */ lincons1_array(size_t size, const lincons1 x[]); /*! \brief Creates a lincons1_array from an vector (of size >0) of constraints of the given size (copied). * * \warning assumes that all constraints have the same environment (unchecked). * \throw std::invalid_argument if vector size<1. */ lincons1_array(const std::vector& x); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ /*! \brief Frees the space used by the array and all its constraints, and decrements the * reference count of the environment. */ ~lincons1_array(); //@} /* assignment */ /* ========== */ /** @name Assignments */ //@{ //! (Deep) copy. lincons1_array& operator= (const lincons1_array& x); /*! \brief Copies the constraints from the array into *this. * * \warning assumes that all constraints have the same environment (unchecked). * \arg x should contain (at least) size elements. */ lincons1_array& operator= (const lincons1 x[]); /*! Copies the constraints from the vector into the array, changing its size if needed. * * \warning assumes that all constraints have the same environment (unchecked). */ lincons1_array& operator= (const std::vector& x); //@} /* dimension operations */ /* ==================== */ /** @name Dimension operations */ //@{ //! Resizes the array. void resize(size_t size); /*! \brief Extends the environment of all expressions in array. * * \throw std::invalid_argument if e is not a super-environment of that of *this. */ void extend_environment(const environment& e); //@} /* access */ /* ====== */ /** @name Accesses */ //@{ //! Returns the size of the array. size_t size() const; //! Returns the environment shared by all constraints (with incremented reference count). environment get_environment() const; //! Returns a reference to the underlying lincons0_array. const lincons0_array& get_lincons0_array() const; //! Returns a (modifiable) reference to the underlying lincons0_array. lincons0_array& get_lincons0_array(); /*! \brief Returns a copy of the constraint at index i. * * \throw std::out_of_range if i exceeds the dimension of the array. */ lincons1 get(size_t i) const; /*! \brief Changes the constraint at index i. * * \warning assumes that x and *this have equal environments. * \throw std::out_of_range if i exceeds the dimension of the array. */ void set(size_t i, const lincons1& x); //@} /* conversion */ /* ========== */ /** @name Conversion */ //@{ //! Returns a copy of the linear constraints in the form of a vector. operator std::vector() const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ /*! \brief Printing. * * \throw std::invalid_argument an underlying expression is missing, or an * auxiliary scalar is missing (for modulo constraint). */ friend std::ostream& operator<< (std::ostream& os, const lincons1_array& s); //! Prints to a C stream. void print(FILE* stream=stdout) const; //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. const ap_lincons1_array_t* get_ap_lincons1_array_t() const; //! Returns a pointer to the internal APRON object stored in *this. ap_lincons1_array_t* get_ap_lincons1_array_t(); //@} }; #include "apxx_lincons1_inline.hh" } #endif /* __APXX_LINCONS1_HH */ apron-dist-0.9.10/apron/apronxx/apxx_var_inline.hh0000640014525101416610000000541210703144237022075 0ustar bjeannetpopart/* -*- C++ -*- * apxx_var_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ /* ================================= */ /* var */ /* ================================= */ /* constructors */ /* ============ */ inline var::var(const void* x) { v = ap_var_operations->copy(const_cast(x)); } inline var::var(const std::string& x) { v = ap_var_operations->copy(const_cast(x.c_str())); } inline var::var(const var& x) { v = ap_var_operations->copy(x.v); } /* destructor */ /* ========== */ inline var::~var() { ap_var_operations->free(v); } /* assignments */ /* =========== */ inline var& var::operator=(const var& x) { if (x.v!=v) { ap_var_t vv = ap_var_operations->copy(x.v); ap_var_operations->free(v); v = vv; } return *this; } inline var& var::operator=(const void* x) { ap_var_operations->free(v); v = ap_var_operations->copy(const_cast(x)); return *this; } inline var& var::operator=(const std::string& x) { ap_var_operations->free(v); v = ap_var_operations->copy(const_cast(x.c_str())); return *this; } /* conversions */ /* =========== */ inline var::operator char*() const { return ap_var_operations->to_string(v); } inline var::operator std::string() const { char* c = ap_var_operations->to_string(v); std::string s = c; free(c); return s; } /* comparisons */ /* =========== */ inline int compare(const var& x, const var& y) { return ap_var_operations->compare(x.v,y.v); } inline bool operator==(const var& x, const var& y) { return ap_var_operations->compare(x.v,y.v)==0; } inline bool operator!=(const var& x, const var& y) { return ap_var_operations->compare(x.v,y.v)!=0; } inline bool operator>=(const var& x, const var& y) { return ap_var_operations->compare(x.v,y.v)>=0; } inline bool operator<=(const var& x, const var& y) { return ap_var_operations->compare(x.v,y.v)<=0; } inline bool operator>(const var& x, const var& y) { return ap_var_operations->compare(x.v,y.v)>0; } inline bool operator<(const var& x, const var& y) { return ap_var_operations->compare(x.v,y.v)<0; } /* print */ /* ===== */ inline std::ostream& operator<< (std::ostream& os, const var& s) { std::string ss = s; return os << ss; } inline void var::print(FILE* stream) const { char* x = ap_var_operations->to_string(const_cast(v)); fprintf(stream,"%s",x); free(x); } /* C-level compatibility */ /* ===================== */ inline const ap_var_t& var::get_ap_var_t() const { return v; } inline ap_var_t& var::get_ap_var_t() { return v; } apron-dist-0.9.10/apron/apronxx/apxx_abstract0.hh0000640014525101416610000011165210723557216021645 0ustar bjeannetpopart/* -*- C++ -*- * apxx_abstract0.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_ABSTRACT0_HH #define __APXX_ABSTRACT0_HH #include #include "ap_abstract0.h" #include "apxx_linexpr0.hh" #include "apxx_lincons0.hh" #include "apxx_generator0.hh" #include "apxx_manager.hh" namespace apron { /* ================================= */ /* abstract0 */ /* ================================= */ /*! \brief Level 0 abstract value (ap_abstract0_t* wrapper). * * An abstract0 object stores an abstract value. * It represents a set of points in a numerical space with some integer-valued dimensions and some * real-valued dimensions. * * \warning all the abstract operators are guaranteed to be sound, but not complete, that is: * - returned abstract elements and intervals are over-approximations of the actual result on sets, * - returned constraint conjunction may satisfy more points than the original abstract element, * - returned generators may span more points than the original abstract element, * - predicates return \c true if the predicate is definitively true, * and \c false if either the predicate is false (flag_exact is then true), or * due to abstraction, the domain cannot conclude (flag_exact is then false). * * An abstract0 is always created with a manager that indicates the underlying library. This * defines its internal representation and algorithms, which in turns defines the expressiveness and * cost vs. precision trade-off. * Most operations to manipulate an abstract0 also take a manager as first argument. * This must be a manager compatible with the one of all abstract0 arguments (including this), * that is, a manger created by the same library (e.g., NewPolka polyhedra) and using the same * parameter values, if any (e.g., strictness). * It need not be the very same manager the abstract0 was created with. * * Overloaded arithmetic, assignment and copy operators that cannot take an extra manager * argument will implicitly use the manager used to create the first argument. * * Additionally, for binary or n-aray operators, all abstract0 must have the same number of * integer and real dimensions. * * Many operations exist in two kinds: * - an imperative class function that modifies the this abstract0, * - a more "functional" global function that takes as argument both one or several constant * source abstract0 and one destination abstract0 that will be overridden with the result. * * Both kinds will return a reference to the abstract0 that holds the result. * * Most functions can throw a variety of exceptions: * - std::invalid_argument, when arguments have incompatible managers, types, or dimensions, * - std::length_error, when running out of memory or exceeding the \c max_object_size * value set by the user in the manager, * - std::overflow_error, when a numerical overflow occurs, * - not_implemented, when some function is not available, * - timeout, when exceeding the \c timout value set by the user in the manager. */ class abstract0 : public use_malloc { protected: ap_abstract0_t* a; //!< Pointer managed by APRON. //! Internal use only. Wraps an abstract0 around the pointer x, taking ownership of the object. abstract0(ap_abstract0_t* x); //! NULL abstract element, to be used only as default argument in assign and substitute. static const abstract0 null; friend class manager; public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ //! Creates an abstract element representing the whole space. abstract0(manager &m, size_t intdim, size_t realdim, top x); //! Creates an abstract element representing the empty set. abstract0(manager &m, size_t intdim, size_t realdim, bottom x); //! Creates a (deep) copy of the abstract element. abstract0(manager &m, const abstract0& t); /*! \brief Creates an abstract element from a box. * * \throw std::invalid_argument if x has less than intdim+realdim dimensions. */ abstract0(manager &m, size_t intdim, size_t realdim, const interval_array& x); //! Creates an abstract element from a conjunction of linear constraints. abstract0(manager &m, size_t intdim, size_t realdim, const lincons0_array& x); //! Creates an abstract element from a conjunction of arbitrary constraints. abstract0(manager &m, size_t intdim, size_t realdim, const tcons0_array& x); /*! \brief Creates a (deep) copy of the abstract element. * * Implicitly uses the manager used to create *this. */ abstract0(const abstract0& t); //@} /* destructor */ /* ========== */ /** @name Destructors */ //@{ /*! \brief Destroys the abstract element. * * Implicitly uses the manager used to create *this. */ ~abstract0(); /*! \brief Destroys the abstract element using the given manager. * * The abstract element cannot be used after being freed. * However, the standard destructor can be safely be called (resulting in a no-op). */ void free(manager& m); //@} /* assignments */ /* =========== */ /** @name Copies and conversions to abstract elements */ //@{ /*! \brief Assigns a copy of t to *this. * * Implicitly uses the manager used to create *this. */ abstract0& operator=(const abstract0& t); /*! \brief Assigns the full space to *this. * * Implicitly uses the manager used to create *this. */ abstract0& operator=(top t); /*! \brief Assigns the empty set to *this. * * Implicitly uses the manager used to create *this. */ abstract0& operator=(bottom t); /*! \brief Assigns a box to *this. * * Implicitly uses the manager used to create *this. * * \throw std::invalid_argument if the array has insufficient size. */ abstract0& operator=(const interval_array& x); /*! \brief Assigns a conjunction of linear constraints to *this. * * Implicitly uses the manager used to create *this. */ abstract0& operator=(const lincons0_array& x); /*! \brief Assigns a conjunction of arbitrary constraints to *this. * * Implicitly uses the manager used to create *this. */ abstract0& operator=(const tcons0_array& x); /*! \brief Replaces *this with a copy of x. * * \return a reference to *this. */ abstract0& set(manager& m, const abstract0& x); /*! \brief Replaces *this with the full space. * * You can either specify new intdim and realdim values or keep those of *this * (if unspecified, i.e., left to \c AP_DIM_MAX). * * \return a reference to *this. */ abstract0& set(manager& m, top t, size_t intdim = AP_DIM_MAX, size_t realdim = AP_DIM_MAX); /*! \brief Replaces *this with the empty set. * * You can either specify new intdim and realdim values or keep those of *this * (if unspecified, i.e., left to \c AP_DIM_MAX). * * \return a reference to *this. */ abstract0& set(manager& m, bottom t, size_t intdim = AP_DIM_MAX, size_t realdim = AP_DIM_MAX); /*! \brief Replaces *this with a box. * * You can either specify new intdim and realdim values or keep those of *this * (if unspecified, i.e., left to \c AP_DIM_MAX). * * \return a reference to *this. */ abstract0& set(manager& m, const interval_array& x, size_t intdim = AP_DIM_MAX, size_t realdim = AP_DIM_MAX); /*! \brief Replaces *this with a conjunction of linear constraints. * * You can either specify new intdim and realdim values or keep those of *this * (if unspecified, i.e., left to \c AP_DIM_MAX). * * \return a reference to *this. */ abstract0& set(manager& m, const lincons0_array& x, size_t intdim = AP_DIM_MAX, size_t realdim = AP_DIM_MAX); /*! \brief Replaces *this with a conjunction of arbitrary constraints. * * You can either specify new intdim and realdim values or keep those of *this * (if unspecified, i.e., left to \c AP_DIM_MAX). * * \return a reference to *this. */ abstract0& set(manager& m, const tcons0_array& x, size_t intdim = AP_DIM_MAX, size_t realdim = AP_DIM_MAX); //@} /* representation */ /* ============== */ /** @name Control of internal representation */ //@{ /*! \brief Minimizes the size of the representation, to save memory. * * \return a reference to *this. */ abstract0& minimize(manager& m); /*! \brief Puts the abstract element in canonical form (if such a notion exists). * * \return a reference to *this. */ abstract0& canonicalize(manager& m); /*! \brief Simplifies the abstract element, potentially loosing precision. * * \return a reference to *this. */ abstract0& approximate(manager& m, int algorithm); //@} /* printing */ /* ======== */ /** @name Printing */ //@{ //! Pretty-printing to a C stream. void print(manager& m, char** name_of_dim=NULL, FILE* stream=stdout) const; //! Pretty-printing the difference between x and y to a C stream. friend void printdiff(manager& m, const abstract0& x, const abstract0& y, char** name_of_dim=NULL, FILE* stream=stdout); //! Raw printing to a C stream (mainly for debug purposes). void dump(manager& m, FILE* stream=stdout) const; //! Prints in constraint form. friend std::ostream& operator<< (std::ostream& os, const abstract0& s); //@} /* serialisation */ /* ============= */ /** @name Serialisation */ //@{ /*! \brief Serializes an abstract element. * * The string can be safely stored to disk and reloaded later or transmitted across a network. * The format is library-specific but is generally a machine-readable byte-stream. * * \return a newly allocated string that the caller should delete it after use. */ std::string* serialize(manager& m) const; /*! \brief Reconstruct an abstract element form a serialized byte-stream and put it into dst. * * The managers used to serialized and deserialize need not be the same, but they must * have been created using the same library and with the same arguments. * * \arg \c eaten, if not NULL, will be set to the actual number of bytes consumed from the * string. * \return a reference to dst. */ friend abstract0& deserialize(manager& m, abstract0& dst, const std::string& s, size_t* eaten = NULL); //@} /* access */ /* ====== */ /** @name Access */ //@{ //! Returns the manager the abstract element was created with (with reference count incremented). manager get_manager() const; //! \brief Returns the number of integer and real dimensions in the abstract element. ap_dimension_t get_dimension(manager& m) const; /*! \brief Returns the (abstract) size of the abstract element. * * The unit in which size is computed is library-specific. * It is guaranteed to be the same as the unit for the \c max_object_size field of * the ap_funopt_t structure. */ size_t size(manager& m) const; //@} /* predicates */ /* ========== */ /** @name Predicates */ //@{ //! \brief Whether *this represents the empty set. bool is_bottom(manager& m) const; //! Whether *this represents the full space. bool is_top(manager& m) const; //! Whether *this and x represent the same set. bool is_eq(manager& m, const abstract0& x) const; //! Whether *this is included in x (set-wise). bool is_leq(manager& m, const abstract0& x) const; //! Whether all points in *this satisfy a linear constraint. bool sat(manager& m, const lincons0& l) const; //! Whether all points in *this satisfy an arbitrary constraint. bool sat(manager& m, const tcons0& l) const; /*! \brief Whether the dimension dim of all points in *this is included * in the given interval. */ bool sat(manager& m, ap_dim_t dim, const interval& i) const; //! \brief Whether the points in *this are unbounded in the given dimension. bool is_dimension_unconstrained(manager& m, ap_dim_t dim) const; /*! \brief Whether x and y represent the same set. * * The manager for the left argument is used implicitly. */ friend bool operator== (const abstract0& x, const abstract0& y); /*! \brief Whether x and y represent different sets. * * The manager for the left argument is used implicitly. */ friend bool operator!= (const abstract0& x, const abstract0& y); /*! \brief Whether x is included within y (set-wise). * * The manager for the left argument is used implicitly. */ friend bool operator<= (const abstract0& x, const abstract0& y); /*! \brief Whether x contains y (set-wise). * * The manager for the left argument is used implicitly. */ friend bool operator>= (const abstract0& x, const abstract0& y); /*! \brief Whether x strictly contains y (set-wise). * * The manager for the left argument is used implicitly. */ friend bool operator> (const abstract0& x, const abstract0& y); /*! \brief Whether x is strictly included within y (set-wise). * * The manager for the left argument is used implicitly. */ friend bool operator< (const abstract0& x, const abstract0& y); /* Properties */ /* ========== */ /** @name Property extraction */ //@{ //! Returns some bounds for a linear expression evaluated in all points in the abstract element. interval bound(manager& m, const linexpr0& l) const; //! Returns some bounds for an arbitrary expression evaluated in all points in the abstract element. interval bound(manager& m, const texpr0& l) const; //! Returns some bounds for the given coordinate on all points in the abstract element. interval bound(manager& m, ap_dim_t d) const; //! Returns a bounding box for the set represented by the abstract element. interval_array to_box(manager& m) const; /*! \brief Returns a generator representation of (an over-approximation of) the * set represented by the abstract element. */ generator0_array to_generator_array(manager& m) const; /*! \brief Returns a linear constraint representation of (an over-approximation of) the * set represented by the abstract element. */ lincons0_array to_lincons_array(manager& m) const; /*! \brief Returns a constraint representation of (an over-approximation of) the * set represented by the abstract element. */ tcons0_array to_tcons_array(manager& m) const; //@} /* Meet */ /* ==== */ /** @name Meet */ //@{ /*! \brief Replaces *this with the meet of *this and the abstract element y. * * \return a reference to *this. */ abstract0& meet(manager& m, const abstract0& y); /*! \brief Replaces dst with the meet of x and y. * * \return a reference to dst. */ friend abstract0& meet(manager& m, abstract0& dst, const abstract0& x, const abstract0& y); /*! \brief Replaces dst with the meet of all abstract elements in x. * * \return a reference to dst. */ friend abstract0& meet(manager& m, abstract0& dst, const std::vector& x); /*! \brief Replaces dst with the meet of all size abstract elements in x. * * \return a reference to dst. */ friend abstract0& meet(manager& m, abstract0& dst, size_t size, const abstract0 * const x[]); /*! \brief Adds some linear constraints to *this (modified in-place). * * \return a reference to *this. */ abstract0& meet(manager& m, const lincons0_array& y); /*! \brief Replaces dst with the meet of x and some linear constraints. * * \return a reference to dst. */ friend abstract0& meet(manager& m, abstract0& dst, const abstract0& x, const lincons0_array& y); /*! \brief Adds some arbitrary constraints to *this (modified in-place). * * \return a reference to *this. */ abstract0& meet(manager& m, const tcons0_array& y); /*! \brief Replaces dst with the meet of x and some arbitrary constraints. * * \return a reference to dst. */ friend abstract0& meet(manager& m, abstract0& dst, const abstract0& x, const tcons0_array& y); /*! \brief Replaces *this with the meet of *this and the abstract element y. * * Implicitly uses the manager used to create *this. * * \return a reference to *this. */ abstract0& operator*=(const abstract0& y); /*! \brief Adds some linear constraints to *this (modified in-place). * * Implicitly uses the manager used to create *this. * * \return a reference to *this. */ abstract0& operator*=(const lincons0_array& y); /*! \brief Adds some arbitrary constraints to *this (modified in-place). * * Implicitly uses the manager used to create *this. * * \return a reference to *this. */ abstract0& operator*=(const tcons0_array& y); //@} /* Join */ /* ==== */ /** @name Join */ //@{ /*! \brief Replaces *this with the join of *this and the abstract element y. * * \return a reference to *this. */ abstract0& join(manager& m, const abstract0& y); /*! \brief Replaces dst with the join of x and y. * * \return a reference to dst. */ friend abstract0& join(manager& m, abstract0& dst, const abstract0& x, const abstract0& y); /*! \brief Replaces dst with the join of all abstract elements in x. * * \return a reference to dst. */ friend abstract0& join(manager& m, abstract0& dst, const std::vector& x); /*! \brief Replaces dst with the join of all size abstract elements in x. * * \return a reference to dst. */ friend abstract0& join(manager& m, abstract0& dst, size_t size, const abstract0 * const x[]); /*! \brief Adds some rays to *this (modified in-place). * * \arg \c y can only contain rays and lines, not vertexes. * * \return a reference to *this. */ abstract0& add_rays(manager& m, const generator0_array& y); /*! \brief Replaces dst with x with some rays added. * * \arg \c y can only contain rays and lines, not vertexes. * * \return a reference to *this. */ friend abstract0& add_rays(manager& m, abstract0& dst, const abstract0& x, const generator0_array& y); /*! \brief Replaces *this with the join of *this and the abstract element y. * * Implicitly uses the manager used to create *this. * * \return a reference to *this. */ abstract0& operator+=(const abstract0& y); /*! \brief Adds some rays to *this (modified in-place). * * Implicitly uses the manager used to create *this. * * \arg \c y can only contain rays and lines, not vertexes. * * \return a reference to *this. */ abstract0& operator+=(const generator0_array& y); //@} /* Assignments */ /* =========== */ /** @name Assignment */ //@{ /*! \brief In-place assignment of linear expression. * * *this is modified in-place to reflect the effect of assigning l to dimension dim. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. */ abstract0& assign(manager& m, ap_dim_t dim, const linexpr0& l, const abstract0& inter = null); /*! \brief In-place parallel assignment of linear expressions. * * *this is modified in-place to reflect the effect of assigning l[i] to dimension dim[i], for * i from 0 to size-1. * Assignments are performed in parallel. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. */ abstract0& assign(manager& m, size_t size, const ap_dim_t dim[], const linexpr0 * const l[], const abstract0& inter = null); /*! \brief In-place parallel assignment of linear expressions. * * *this is modified in-place to reflect the effect of assigning l[i] to dimension dim[i]. * Assignments are performed in parallel. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. * * \throw std::invalid_argument if the vectors have different size. */ abstract0& assign(manager& m, const std::vector& dim, const std::vector& l, const abstract0& inter = null); /*! \brief Assignment of linear expression. * * dst is replaced with the effect of assigning l to dimension dim in src. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. */ friend abstract0& assign(manager& m, abstract0& dst, const abstract0& src, ap_dim_t dim, const linexpr0& l, const abstract0& inter = null); /*! \brief Parallel assignment of linear expressions. * * dst is replaced with the effect of assigning l[i] to dimension dim[i] in src, * for i from 0 to size-1. * Assignments are performed in parallel. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. */ friend abstract0& assign(manager& m, abstract0& dst, const abstract0& src, size_t size, const ap_dim_t dim[], const linexpr0 * const l[], const abstract0& inter = null); /*! \brief Parallel assignment of linear expressions. * * dst is replaced with the effect of assigning l[i] to dimension dim[i] in src. * Assignments are performed in parallel. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. * * \throw std::invalid_argument if the vectors have different size. */ friend abstract0& assign(manager& m, abstract0& dst, const abstract0& src, const std::vector& dim, const std::vector& l, const abstract0& inter = null); /*! \brief In-place assignment of arbitrary expression. * * *this is modified in-place to reflect the effect of assigning l to dimension dim. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. */ abstract0& assign(manager& m, ap_dim_t dim, const texpr0& l, const abstract0& inter = null); /*! \brief In-place parallel assignment of arbitrary expressions. * * *this is modified in-place to reflect the effect of assigning l[i] to dimension dim[i], for * i from 0 to size-1. * Assignments are performed in parallel. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. */ abstract0& assign(manager& m, size_t size, const ap_dim_t dim[], const texpr0 * const l[], const abstract0& inter = null); /*! \brief In-place parallel assignment of arbitrary expressions. * * *this is modified in-place to reflect the effect of assigning l[i] to dimension dim[i]. * Assignments are performed in parallel. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. * * \throw std::invalid_argument if the vectors have different size. */ abstract0& assign(manager& m, const std::vector& dim, const std::vector& l, const abstract0& inter = null); /*! \brief Assignment of arbitrary expression. * * dst is replaced with the effect of assigning l to dimension dim in src. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. */ friend abstract0& assign(manager& m, abstract0& dst, const abstract0& src, ap_dim_t dim, const texpr0& l, const abstract0& inter = null); /*! \brief Parallel assignment of arbitrary expressions. * * dst is replaced with the effect of assigning l[i] to dimension dim[i] in src, * for i from 0 to size-1. * Assignments are performed in parallel. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. */ friend abstract0& assign(manager& m, abstract0& dst, const abstract0& src, size_t size, const ap_dim_t dim[], const texpr0 * const l[], const abstract0& inter = null); /*! \brief Parallel assignment of arbitrary expressions. * * dst is replaced with the effect of assigning l[i] to dimension dim[i] in src. * Assignments are performed in parallel. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. * * \throw std::invalid_argument if the vectors have different size. */ friend abstract0& assign(manager& m, abstract0& dst, const abstract0& src, const std::vector& dim, const std::vector& l, const abstract0& inter = null); //@} /* Substitutions */ /* ============== */ /** @name Substitution */ //@{ /*! \brief In-place substitution (backward assignment) of linear expression. * * *this is modified in-place to reflect the effect of substituting l to dimension dim. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. */ abstract0& substitute(manager& m, ap_dim_t dim, const linexpr0& l, const abstract0& inter = null); /*! \brief In-place parallel substitution (backward assignment) of linear expressions. * * *this is modified in-place to reflect the effect of substituting l[i] to dimension dim[i], for * i from 0 to size-1. * Substitutions are performed in parallel. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. */ abstract0& substitute(manager& m, size_t size, const ap_dim_t dim[], const linexpr0 * const l[], const abstract0& inter = null); /*! \brief In-place parallel substitution (backward assignment) of linear expressions. * * *this is modified in-place to reflect the effect of substituting l[i] to dimension dim[i]. * Substitutions are performed in parallel. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. * * \throw std::invalid_argument if the vectors have different size. */ abstract0& substitute(manager& m, const std::vector& dim, const std::vector& l, const abstract0& inter = null); /*! \brief Substitution (backward assignment) of linear expression. * * dst is replaced with the effect of substituting l to dimension dim in src. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. */ friend abstract0& substitute(manager& m, abstract0& dst, const abstract0& src, ap_dim_t dim, const linexpr0& l, const abstract0& inter = null); /*! \brief Parallel substitution (backward assignment) of linear expressions. * * dst is replaced with the effect of substituting l[i] to dimension dim[i] in src, * for i from 0 to size-1. * Substitutions are performed in parallel. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. */ friend abstract0& substitute(manager& m, abstract0& dst, const abstract0& src, size_t size, const ap_dim_t dim[], const linexpr0 * const l[], const abstract0& inter = null); /*! \brief Parallel substitution (backward assignment) of linear expressions. * * dst is replaced with the effect of substituting l[i] to dimension dim[i] in src. * Substitutions are performed in parallel. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. * * \throw std::invalid_argument if the vectors have different size. */ friend abstract0& substitute(manager& m, abstract0& dst, const abstract0& src, const std::vector& dim, const std::vector& l, const abstract0& inter = null); /*! \brief In-place substitution (backward assignment) of arbitrary expression. * * *this is modified in-place to reflect the effect of substituting l to dimension dim. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. */ abstract0& substitute(manager& m, ap_dim_t dim, const texpr0& l, const abstract0& inter = null); /*! \brief In-place parallel substitution (backward assignment) of arbitrary expressions. * * *this is modified in-place to reflect the effect of substituting l[i] to dimension dim[i], for * i from 0 to size-1. * Substitutions are performed in parallel. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. */ abstract0& substitute(manager& m, size_t size, const ap_dim_t dim[], const texpr0 * const l[], const abstract0& inter = null); /*! \brief In-place parallel substitution (backward assignment) of arbitrary expressions. * * *this is modified in-place to reflect the effect of substituting l[i] to dimension dim[i]. * Substitutions are performed in parallel. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. * * \throw std::invalid_argument if the vectors have different size. */ abstract0& substitute(manager& m, const std::vector& dim, const std::vector& l, const abstract0& inter = null); /*! \brief Substitution (backward assignment) of arbitrary expression. * * dst is replaced with the effect of substituting l to dimension dim in src. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. */ friend abstract0& substitute(manager& m, abstract0& dst, const abstract0& src, ap_dim_t dim, const texpr0& l, const abstract0& inter = null); /*! \brief Parallel substitution (backward assignment) of arbitrary expressions. * * dst is replaced with the effect of substituting l[i] to dimension dim[i] in src, * for i from 0 to size-1. * Substitutions are performed in parallel. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. */ friend abstract0& substitute(manager& m, abstract0& dst, const abstract0& src, size_t size, const ap_dim_t dim[], const texpr0 * const l[], const abstract0& inter = null); /*! \brief Parallel substitution (backward assignment) of arbitrary expressions. * * dst is replaced with the effect of substituting l[i] to dimension dim[i] in src. * Substitutions are performed in parallel. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. * * \throw std::invalid_argument if the vectors have different size. */ friend abstract0& substitute(manager& m, abstract0& dst, const abstract0& src, const std::vector& dim, const std::vector& l, const abstract0& inter = null); //@} /* Projection */ /* ========== */ /** @name Projection, forget */ //@{ /*! \brief Forgets about the value of dimension dim in *this. * * \arg \c project whether to reset the dimension to 0 (if true), or leave it undefined (if false). * * \return a reference to *this. */ abstract0& forget(manager& m, ap_dim_t dim, bool project = false); /*! \brief Forgets about the value of dimensions dims[0] to dims[size-1] in *this. * * \arg \c project whether to reset the dimensions to 0 (if true), or leave them undefined (if false). * * \return a reference to *this. */ abstract0& forget(manager& m, size_t size, const ap_dim_t dim[], bool project = false); /*! \brief Forgets about the value of all the dimensions in dim in *this. * * \arg \c project whether to reset the dimensions to 0 (if true), or leave them undefined (if false). * * \return a reference to *this. */ abstract0& forget(manager& m, const std::vector dim, bool project = false); /*! \brief Stores in dst the result of forgetting the value of dimension dim in src. * * \arg \c project if true, resets the dimension to 0 (if true). * * \return a reference to dst. */ friend abstract0& forget(manager& m, abstract0& dst, const abstract0& src, ap_dim_t dim, bool project = false); /*! \brief Stores in dst the result of forgetting the value of dimensions dim[0] to * dim[size-1] in src. * * \arg \c project whether to reset the dimensions to 0 (if true), or leave them undefined (if false). * * \return a reference to dst. */ friend abstract0& forget(manager& m, abstract0& dst, const abstract0& src, size_t size, const ap_dim_t dim[], bool project = false); /*! \brief Stores in dst the result of forgetting the value of all the dimensions in dim in src. * * \arg \c project whether to reset the dimensions to 0 (if true), or leave them undefined (if false). * * \return a reference to dst. */ friend abstract0& forget(manager& m, abstract0& dst, const abstract0& src, const std::vector dim, bool project = false); //@} /* Change of dimension */ /* =================== */ /** @name Change of dimension */ //@{ /*! \brief Adds some dimensions to *this. * * \arg \c project whether to set the new dimensions to 0 (if true), or leave them undefined (if false). * * \return a reference to *this. */ abstract0& add_dimensions(manager& m, const dimchange& d, bool project = false); /*! \brief Removes some dimensions from *this. * * \return a reference to *this. */ abstract0& remove_dimensions(manager& m, const dimchange& d); /*! \brief Permutes some dimensions in *this. * * \return a reference to *this. */ abstract0& permute_dimensions(manager& m, const dimperm& d); /*! \brief Copies src into dst and adds some dimensions. * * \arg \c project whether to set the new dimensions to 0 (if true), or leave them undefined (if false). * * \return a reference to dst. */ friend abstract0& add_dimensions(manager& m, abstract0& dst, const abstract0& src, const dimchange& d, bool project = false); /*! \brief Copies src into dst and removes some dimensions. * * \return a reference to dst. */ friend abstract0& remove_dimensions(manager& m, abstract0& dst, const abstract0& src, const dimchange& d); /*! \brief Copies src into dst and permute some dimensions. * * \return a reference to dst. */ friend abstract0& permute_dimensions(manager& m, abstract0& dst, const abstract0& src, const dimperm& d); //@} /* Expansion and folding */ /* ===================== */ /** @name Expansion and folding */ //@{ /*! \brief Duplicates dimension dim into n copies in *this (modified in-place). * * New dimensions are appended after the last integer or real dimension of *this. * * \return a reference to *this. */ abstract0& expand(manager& m, ap_dim_t dim, size_t n = 1); /*! \brief Replaces dst with a copy of src and duplicates dimension dim into n copies. * * New dimensions are appended after the last integer or real dimension of dst. * * \return a reference to dst. */ friend abstract0& expand(manager& m, abstract0& dst, const abstract0& src, ap_dim_t dim, size_t n = 1); /*! \brief Folds dimensions dim[0] to dim[size-1] in *this (modified in-place). * * dim must be sorted and contain variables of the same type (integer or real). * After folding, only dim[0] is kept and other dimensions are removed. * * \return a reference to *this. */ abstract0& fold(manager& m, size_t size, const ap_dim_t dim[]); /*! \brief Folds all dimensions dims in *this (modified in-place). * * dim must be sorted and contain variables of the same type (integer or real). * After folding, only dim[0] is kept and other dimensions are removed. * * \return a reference to *this. */ abstract0& fold(manager& m, const std::vector& dim); /*! \brief Replaces dst with a copy of src and folds dimensions dims[0] to dim[size-1]. * * dim must be sorted and contain variables of the same type (integer or real). * After folding, only dim[0] is kept and other dimensions are removed. * * \return a reference to dst. */ friend abstract0& fold(manager& m, abstract0& dst, const abstract0& src, size_t size, const ap_dim_t dim[]); /*! \brief Replaces dst with a copy of src and folds all dimensions in dims. * * dim must be sorted and contain variables of the same type (integer or real). * After folding, only dim[0] is kept and other dimensions are removed. * * \return a reference to dst. */ friend abstract0& fold(manager& m, abstract0& dst, const abstract0& src, const std::vector& dim); //@} /* Widenings */ /* ========= */ /** @name Widening */ //@{ /*! \brief Stores in dst the result of x widened with y. * * \warning y must be a superset of x. * * \return a reference to dst. */ friend abstract0& widening(manager& m, abstract0& dst, const abstract0& x, const abstract0& y); /*! \brief Stores in dst the result of x widened with y, using some widening thresholds. * * \warning y must be a superset of x. * * \return a reference to dst. */ friend abstract0& widening(manager& m, abstract0& dst, const abstract0& x, const abstract0& y, const lincons0_array& l); //@} /* Closure */ /* ======= */ /** @name Closure */ //@{ /*! \brief Replaces *this with its topological closure. * * \return a reference to *this. */ abstract0& closure(manager& m); /*! \brief Stores in dst the topological closure of src. * * \return a reference to dst. */ friend abstract0& closure(manager& m, abstract0& dst, const abstract0& src); //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. ap_abstract0_t* get_ap_abstract0_t(); //! Returns a pointer to the internal APRON object stored in *this. const ap_abstract0_t* get_ap_abstract0_t() const; //@} }; #include "apxx_abstract0_inline.hh" } #endif /* __APXX_ABSTRACT0_HH */ apron-dist-0.9.10/apron/apronxx/doc/0000750014525101416610000000000011252216461017127 5ustar bjeannetpopartapron-dist-0.9.10/apron/apronxx/doc/Doxyfile0000640014525101416610000002137010703144237020642 0ustar bjeannetpopart# Doxyfile 1.5.2 #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- DOXYFILE_ENCODING = UTF-8 PROJECT_NAME = APRONXX PROJECT_NUMBER = 0.9.7 OUTPUT_DIRECTORY = /home/mine/apron/trunk/apronxx/doc CREATE_SUBDIRS = NO OUTPUT_LANGUAGE = English BRIEF_MEMBER_DESC = YES REPEAT_BRIEF = YES ABBREVIATE_BRIEF = "The $name class" \ "The $name widget" \ "The $name file" \ is \ provides \ specifies \ contains \ represents \ a \ an \ the ALWAYS_DETAILED_SEC = NO INLINE_INHERITED_MEMB = NO FULL_PATH_NAMES = YES STRIP_FROM_PATH = /home/mine/apron/trunk/apronxx/ STRIP_FROM_INC_PATH = SHORT_NAMES = NO JAVADOC_AUTOBRIEF = NO MULTILINE_CPP_IS_BRIEF = NO DETAILS_AT_TOP = NO INHERIT_DOCS = YES SEPARATE_MEMBER_PAGES = NO TAB_SIZE = 8 ALIASES = OPTIMIZE_OUTPUT_FOR_C = NO OPTIMIZE_OUTPUT_JAVA = NO BUILTIN_STL_SUPPORT = YES CPP_CLI_SUPPORT = NO DISTRIBUTE_GROUP_DOC = NO SUBGROUPING = YES #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- EXTRACT_ALL = YES EXTRACT_PRIVATE = YES EXTRACT_STATIC = YES EXTRACT_LOCAL_CLASSES = YES EXTRACT_LOCAL_METHODS = NO HIDE_UNDOC_MEMBERS = NO HIDE_UNDOC_CLASSES = NO HIDE_FRIEND_COMPOUNDS = YES HIDE_IN_BODY_DOCS = NO INTERNAL_DOCS = NO CASE_SENSE_NAMES = YES HIDE_SCOPE_NAMES = NO SHOW_INCLUDE_FILES = YES INLINE_INFO = YES SORT_MEMBER_DOCS = YES SORT_BRIEF_DOCS = NO SORT_BY_SCOPE_NAME = NO GENERATE_TODOLIST = YES GENERATE_TESTLIST = YES GENERATE_BUGLIST = YES GENERATE_DEPRECATEDLIST= YES ENABLED_SECTIONS = MAX_INITIALIZER_LINES = 30 SHOW_USED_FILES = YES SHOW_DIRECTORIES = YES FILE_VERSION_FILTER = #--------------------------------------------------------------------------- # configuration options related to warning and progress messages #--------------------------------------------------------------------------- QUIET = YES WARNINGS = NO WARN_IF_UNDOCUMENTED = YES WARN_IF_DOC_ERROR = YES WARN_NO_PARAMDOC = YES WARN_FORMAT = "$file:$line: $text" WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- INPUT = ../ INPUT_ENCODING = UTF-8 FILE_PATTERNS = *.h \ *.hh RECURSIVE = NO EXCLUDE = EXCLUDE_SYMLINKS = NO EXCLUDE_PATTERNS = EXCLUDE_SYMBOLS = EXAMPLE_PATH = EXAMPLE_PATTERNS = * EXAMPLE_RECURSIVE = NO IMAGE_PATH = INPUT_FILTER = FILTER_PATTERNS = FILTER_SOURCE_FILES = NO #--------------------------------------------------------------------------- # configuration options related to source browsing #--------------------------------------------------------------------------- SOURCE_BROWSER = NO INLINE_SOURCES = NO STRIP_CODE_COMMENTS = YES REFERENCED_BY_RELATION = NO REFERENCES_RELATION = NO REFERENCES_LINK_SOURCE = YES USE_HTAGS = NO VERBATIM_HEADERS = YES #--------------------------------------------------------------------------- # configuration options related to the alphabetical class index #--------------------------------------------------------------------------- ALPHABETICAL_INDEX = YES COLS_IN_ALPHA_INDEX = 5 IGNORE_PREFIX = #--------------------------------------------------------------------------- # configuration options related to the HTML output #--------------------------------------------------------------------------- GENERATE_HTML = YES HTML_OUTPUT = html HTML_FILE_EXTENSION = .html HTML_HEADER = HTML_FOOTER = HTML_STYLESHEET = HTML_ALIGN_MEMBERS = YES GENERATE_HTMLHELP = NO CHM_FILE = HHC_LOCATION = GENERATE_CHI = NO BINARY_TOC = NO TOC_EXPAND = NO DISABLE_INDEX = NO ENUM_VALUES_PER_LINE = 4 GENERATE_TREEVIEW = NO TREEVIEW_WIDTH = 250 #--------------------------------------------------------------------------- # configuration options related to the LaTeX output #--------------------------------------------------------------------------- GENERATE_LATEX = YES LATEX_OUTPUT = latex LATEX_CMD_NAME = latex MAKEINDEX_CMD_NAME = makeindex COMPACT_LATEX = YES PAPER_TYPE = a4wide EXTRA_PACKAGES = LATEX_HEADER = PDF_HYPERLINKS = YES USE_PDFLATEX = YES LATEX_BATCHMODE = NO LATEX_HIDE_INDICES = NO #--------------------------------------------------------------------------- # configuration options related to the RTF output #--------------------------------------------------------------------------- GENERATE_RTF = NO RTF_OUTPUT = rtf COMPACT_RTF = NO RTF_HYPERLINKS = NO RTF_STYLESHEET_FILE = RTF_EXTENSIONS_FILE = #--------------------------------------------------------------------------- # configuration options related to the man page output #--------------------------------------------------------------------------- GENERATE_MAN = NO MAN_OUTPUT = man MAN_EXTENSION = .3 MAN_LINKS = NO #--------------------------------------------------------------------------- # configuration options related to the XML output #--------------------------------------------------------------------------- GENERATE_XML = NO XML_OUTPUT = xml XML_SCHEMA = XML_DTD = XML_PROGRAMLISTING = YES #--------------------------------------------------------------------------- # configuration options for the AutoGen Definitions output #--------------------------------------------------------------------------- GENERATE_AUTOGEN_DEF = NO #--------------------------------------------------------------------------- # configuration options related to the Perl module output #--------------------------------------------------------------------------- GENERATE_PERLMOD = NO PERLMOD_LATEX = NO PERLMOD_PRETTY = YES PERLMOD_MAKEVAR_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the preprocessor #--------------------------------------------------------------------------- ENABLE_PREPROCESSING = YES MACRO_EXPANSION = NO EXPAND_ONLY_PREDEF = NO SEARCH_INCLUDES = YES INCLUDE_PATH = ../../apron INCLUDE_FILE_PATTERNS = .h PREDEFINED = EXPAND_AS_DEFINED = SKIP_FUNCTION_MACROS = YES #--------------------------------------------------------------------------- # Configuration::additions related to external references #--------------------------------------------------------------------------- TAGFILES = GENERATE_TAGFILE = ALLEXTERNALS = NO EXTERNAL_GROUPS = YES PERL_PATH = /usr/bin/perl #--------------------------------------------------------------------------- # Configuration options related to the dot tool #--------------------------------------------------------------------------- CLASS_DIAGRAMS = NO MSCGEN_PATH = HIDE_UNDOC_RELATIONS = YES HAVE_DOT = NO CLASS_GRAPH = YES COLLABORATION_GRAPH = YES GROUP_GRAPHS = YES UML_LOOK = NO TEMPLATE_RELATIONS = NO INCLUDE_GRAPH = YES INCLUDED_BY_GRAPH = YES CALL_GRAPH = NO CALLER_GRAPH = NO GRAPHICAL_HIERARCHY = YES DIRECTORY_GRAPH = YES DOT_IMAGE_FORMAT = png DOT_PATH = DOTFILE_DIRS = DOT_GRAPH_MAX_NODES = 50 DOT_TRANSPARENT = NO DOT_MULTI_TARGETS = NO GENERATE_LEGEND = YES DOT_CLEANUP = YES #--------------------------------------------------------------------------- # Configuration::additions related to the search engine #--------------------------------------------------------------------------- SEARCHENGINE = NO apron-dist-0.9.10/apron/apronxx/apxx_expr1.hh0000640014525101416610000000073410656607364021024 0ustar bjeannetpopart/* -*- C++ -*- * apxx_expr1.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_EXPR1_HH #define __APXX_EXPR1_HH #include "apxx_linexpr1.hh" #include "apxx_lincons1.hh" #include "apxx_generator1.hh" #include "apxx_texpr1.hh" #include "apxx_tcons1.hh" #endif /* __APXX_EXPR1_HH */ apron-dist-0.9.10/apron/apronxx/apxx_dimension_inline.hh0000640014525101416610000002205710703144237023276 0ustar bjeannetpopart/* -*- C++ -*- * apxx_dimension_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ /* ================================= */ /* varname */ /* ================================= */ inline varname::varname(const std::vector& names) : names(names) {} template inline std::basic_ostream& operator<<(std::basic_ostream& os, const varname& v) { std::vector*& vv = (std::vector*&)os.pword(varname::xindex); if (vv) delete vv; if (v.names.size()) vv = new std::vector(v.names); else vv = NULL; return os; } template inline std::vector* get_varname(std::basic_ostream& os) { return (std::vector*)os.pword(varname::xindex); } /* ================================= */ /* dimchange */ /* ================================= */ /* constructor */ /* =========== */ inline dimchange::dimchange(size_t intdim, size_t realdim) { ap_dimchange_init(&c, intdim, realdim); } inline dimchange::dimchange(size_t intdim, size_t realdim, const ap_dim_t d[]) { ap_dimchange_init(&c, intdim, realdim); memcpy(c.dim, d, sizeof(ap_dim_t) * (intdim + realdim)); } inline dimchange::dimchange(const dimchange& x, bool inv) { ap_dimchange_init(&c, x.c.intdim, x.c.realdim); memcpy(c.dim, x.c.dim, sizeof(ap_dim_t) * (x.c.intdim + x.c.realdim)); if (inv) ap_dimchange_add_invert(&c); } inline dimchange::dimchange(size_t intdim, size_t realdim, const std::vector& d) { if (d.size()&) vector too short"); ap_dimchange_init(&c, intdim, realdim); for (size_t i=0; i& d) { if (d.size()&) vector too short"); for (size_t i=0; i= c.intdim + c.realdim) throw std::out_of_range("apron::dimchange::get(size_t)"); return c.dim[dim]; } inline const ap_dim_t& dimchange::get(size_t dim) const { if (dim >= c.intdim + c.realdim) throw std::out_of_range("apron::dimchange::get(size_t)"); return c.dim[dim]; } inline ap_dim_t& dimchange::operator[](size_t dim) { return c.dim[dim]; } inline const ap_dim_t& dimchange::operator[](size_t dim) const { return c.dim[dim]; } /* print */ /* ===== */ inline std::ostream& operator<< (std::ostream& os, const dimchange& s) { std::vector* names = get_varname(os); os << "dimchange: intdim=" << s.c.intdim << ", realdim=" << s.c.realdim << std::endl; if (names) { size_t sz = (*names).size(); for (size_t i=0;i(&c)); } /* other operators */ /* =============== */ inline void dimchange::add_invert() { ap_dimchange_add_invert(&c); } inline dimchange dimchange::operator- () const { dimchange r = *this; ap_dimchange_add_invert(&r.c); return r; } /* C-level compatibility */ /* ===================== */ inline const ap_dimchange_t* dimchange::get_ap_dimchange_t() const { return &c; } inline ap_dimchange_t* dimchange::get_ap_dimchange_t() { return &c; } /* ================================= */ /* dimperm */ /* ================================= */ /* constructor */ /* =========== */ inline dimperm::dimperm(size_t size) { ap_dimperm_init(&c, size); } inline dimperm::dimperm(size_t size, const ap_dim_t d[]) { ap_dimperm_init(&c, size); memcpy(c.dim, d, sizeof(ap_dim_t) * (size)); } inline dimperm::dimperm(id t) { ap_dimperm_init(&c, t.size); ap_dimperm_set_id(&c); } inline dimperm::dimperm(const dimperm& x, bool inv) { ap_dimperm_init(&c, x.c.size); if (inv) ap_dimperm_invert(&c, const_cast(&x.c)); else memcpy(c.dim, x.c.dim, sizeof(ap_dim_t) * (x.c.size)); } inline dimperm::dimperm(const dimperm& x, const dimperm& y) { ap_dimperm_init(&c, x.c.size); ap_dimperm_compose( &c, const_cast(&x.c), const_cast(&y.c) ); } inline dimperm::dimperm(const std::vector& d) { ap_dimperm_init(&c, d.size()); for (size_t i=0; i& d) { if (c.size!=d.size()) { ap_dimperm_clear(&c); ap_dimperm_init(&c, d.size()); } for (size_t i=0; i= c.size) throw std::out_of_range("apron::dimperm::get(size_t)"); return c.dim[dim]; } inline const ap_dim_t& dimperm::get(size_t dim) const { if (dim >= c.size) throw std::out_of_range("apron::dimperm::get(size_t)"); return c.dim[dim]; } /* print */ /* ===== */ inline std::ostream& operator<< (std::ostream& os, const dimperm& s) { std::vector* names = get_varname(os); os << "dimperm: size=" << s.c.size << std::endl; if (names) { size_t sz = (*names).size(); for (size_t i=0;i "; if (s.c.dim[i] " << "x" << s.c.dim[i] << std::endl; } return os; } inline void dimperm::print(FILE* stream) const { ap_dimperm_fprint(stream, const_cast(&c)); } /* other operators */ /* =============== */ /* composition */ inline dimperm& dimperm::operator*= (const dimperm& y) { if (c.size!=y.c.size) throw std::invalid_argument("apron::dimperm::operator*= (const dimperm&) size mismatch"); if (&y==this) { dimperm tmp = y; ap_dimperm_compose(&c, &c, const_cast(&tmp.c)); } else ap_dimperm_compose(&c, &c, const_cast(&y.c)); return *this; } inline dimperm operator* (const dimperm& x, const dimperm& y) { if (x.c.size!=y.c.size) throw std::invalid_argument("apron::dimperm::operator* (const dimperm&, const dimperm&) size mismatch"); dimperm r = x.c.size; ap_dimperm_compose(&r.c, const_cast(&x.c), const_cast(&y.c)); return r; } /* inversion */ inline void dimperm::invert() { dimperm tmp = *this; ap_dimperm_invert(&c, &tmp.c); } inline dimperm dimperm::operator- () const { dimperm r = c.size; ap_dimperm_invert(&r.c, const_cast(&c)); return r; } /* C-level compatibility */ /* ===================== */ inline const ap_dimperm_t* dimperm::get_ap_dimperm_t() const { return &c; } inline ap_dimperm_t* dimperm::get_ap_dimperm_t() { return &c; } apron-dist-0.9.10/apron/apronxx/apxx_lincons0_inline.hh0000640014525101416610000002705010703144237023034 0ustar bjeannetpopart/* -*- C++ -*- * apxx_lincons0_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ /* ================================= */ /* lincons0 */ /* ================================= */ inline lincons0::lincons0(ap_lincons0_t l) : l(l) {} inline lincons0::lincons0(ap_constyp_t constyp) { ap_linexpr0_t* llin = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,0); l = ap_lincons0_make(constyp, llin, NULL); } inline lincons0::lincons0(ap_constyp_t constyp, const linexpr0& lin, const scalar& modulo) { ap_linexpr0_t* llin = ap_linexpr0_copy(const_cast(lin.get_ap_linexpr0_t())); ap_scalar_t* mmodulo = ap_scalar_alloc_set(const_cast(modulo.get_ap_scalar_t())); l = ap_lincons0_make(constyp, llin, mmodulo); } inline lincons0::lincons0(ap_constyp_t constyp, const linexpr0& lin) { ap_linexpr0_t* llin = ap_linexpr0_copy(const_cast(lin.get_ap_linexpr0_t())); l = ap_lincons0_make(constyp, llin, NULL); } inline lincons0::lincons0(const lincons0& x) { l = ap_lincons0_copy(const_cast(&x.l)); } inline lincons0::lincons0(unsat x) { l = ap_lincons0_make_unsat(); } inline lincons0::lincons0(const lincons0& x, const dimchange& d) { if (!x.l.linexpr0) throw std::invalid_argument("apron::lincons0::lincons0(const dimchange&) empty expression"); l = ap_lincons0_add_dimensions(const_cast(&x.l), const_cast(d.get_ap_dimchange_t())); } inline lincons0::lincons0(const lincons0& x, const dimperm& d) { if (!x.l.linexpr0) throw std::invalid_argument("apron::lincons0::lincons0(const dimperm&) empty expression"); l = ap_lincons0_permute_dimensions(const_cast(&x.l), const_cast(d.get_ap_dimperm_t())); } /* destructor */ /* ========== */ inline lincons0::~lincons0() { ap_lincons0_clear(&l); } /* assignment */ /* ========== */ inline lincons0& lincons0::operator= (const lincons0& x) { if (&x!=this) { ap_lincons0_clear(&l); l = ap_lincons0_copy(const_cast(&x.l)); } return *this; } inline lincons0& lincons0::operator= (unsat x) { ap_lincons0_clear(&l); l = ap_lincons0_make_unsat(); return *this; } /* dimension operations */ /* ==================== */ inline void lincons0::resize(size_t size) { if (!l.linexpr0) throw std::invalid_argument("apron::lincons0::resize(size_t) empty expression"); ap_linexpr0_realloc(l.linexpr0, size); } inline void lincons0::add_dimensions(const dimchange& d) { if (!l.linexpr0) throw std::invalid_argument("apron::lincons0::add_dimensions(const dimchange&) empty expression"); ap_lincons0_add_dimensions_with(&l, const_cast(d.get_ap_dimchange_t())); } inline void lincons0::permute_dimensions(const dimperm& d) { if (!l.linexpr0) throw std::invalid_argument("apron::lincons0::permute_dimensions(const dimperm&) empty expression"); ap_lincons0_permute_dimensions_with(&l, const_cast(d.get_ap_dimperm_t())); } /* access */ /* ====== */ /* size */ inline size_t lincons0::size() const { if (!l.linexpr0) throw std::invalid_argument("apron::lincons0::size() empty expression"); return ap_linexpr0_size(const_cast(l.linexpr0)); } /* get */ inline ap_constyp_t& lincons0::get_constyp() { return l.constyp; } inline const ap_constyp_t& lincons0::get_constyp() const { return l.constyp; } inline bool lincons0::has_modulo() const { return l.scalar!=NULL; } inline bool lincons0::has_linexpr() const { return l.linexpr0!=NULL; } inline scalar& lincons0::get_modulo() { if (!l.scalar) throw std::invalid_argument("apron::lincons0::get_modulo() empty scalar"); return reinterpret_cast(*l.scalar); } inline const scalar& lincons0::get_modulo() const { if (!l.scalar) throw std::invalid_argument("apron::lincons0::get_modulo() empty scalar"); return reinterpret_cast(*l.scalar); } inline void lincons0::set_modulo(const scalar& c) { if (!l.scalar) l.scalar = ap_scalar_alloc_set(const_cast(c.get_ap_scalar_t())); else ap_scalar_set(l.scalar, const_cast(c.get_ap_scalar_t())); } inline linexpr0& lincons0::get_linexpr() { if (!l.linexpr0) throw std::invalid_argument("apron::lincons0::get_linexpr() empty expression"); return reinterpret_cast(*l.linexpr0); } inline const linexpr0& lincons0::get_linexpr() const { if (!l.linexpr0) throw std::invalid_argument("apron::lincons0::get_linexpr() empty expression"); return reinterpret_cast(*l.linexpr0); } inline void lincons0::set_linexpr(const linexpr0& c) { if (l.linexpr0) ap_linexpr0_free(l.linexpr0); l.linexpr0 = ap_linexpr0_copy(const_cast(c.get_ap_linexpr0_t())); } inline coeff& lincons0::get_cst() { return get_linexpr().get_cst(); } inline const coeff& lincons0::get_cst() const { return get_linexpr().get_cst(); } inline coeff& lincons0::operator[](ap_dim_t dim) { return get_linexpr()[dim]; } inline const coeff& lincons0::operator[](ap_dim_t dim) const { return get_linexpr()[dim]; } /* print */ /* ===== */ inline std::ostream& operator<< (std::ostream& os, const lincons0& s) { os << s.get_linexpr(); switch (s.get_constyp()) { case AP_CONS_EQ: return os << " = 0"; case AP_CONS_SUPEQ: return os << " >= 0"; case AP_CONS_SUP: return os << " > 0"; case AP_CONS_EQMOD: return os << " = 0 mod " << s.get_modulo(); case AP_CONS_DISEQ: return os << " != 0"; default: throw std::invalid_argument("apron::operator<<(ostream&, const lincons0&) unknown constraint type"); } } inline void lincons0::print(char** name_of_dim, FILE* stream) const { ap_lincons0_fprint(stream, const_cast(&l), name_of_dim); } /* tests */ /* ===== */ inline bool lincons0::is_unsat() const { if (!l.linexpr0) throw std::invalid_argument("apron::lincons0::is_unsat() empty expression"); return ap_lincons0_is_unsat(const_cast(&l)); } inline bool lincons0::is_linear() const { if (!l.linexpr0) throw std::invalid_argument("apron::lincons0::is_linear() empty expression"); return ap_linexpr0_is_linear(l.linexpr0); } inline bool lincons0::is_quasilinear() const { if (!l.linexpr0) throw std::invalid_argument("apron::lincons0::is_quasilinear() empty expression"); return ap_linexpr0_is_quasilinear(l.linexpr0); } /* C-level compatibility */ /* ===================== */ inline const ap_lincons0_t* lincons0::get_ap_lincons0_t() const { return &l; } inline ap_lincons0_t* lincons0::get_ap_lincons0_t() { return &l; } /* ================================= */ /* lincons0_array */ /* ================================= */ /* constructors */ /* ============ */ inline lincons0_array::lincons0_array(size_t size) : a(ap_lincons0_array_make(size)) { } inline lincons0_array::lincons0_array(const lincons0_array& x) : a(ap_lincons0_array_make(x.a.size)) { for (size_t i=0; i(x[i].get_ap_lincons0_t())); } inline lincons0_array::lincons0_array(const std::vector& x) : a(ap_lincons0_array_make(x.size())) { for (size_t i=0; i(x[i].get_ap_lincons0_t())); } inline lincons0_array::lincons0_array(const lincons0_array& x, const dimchange& d) { a = ap_lincons0_array_add_dimensions(const_cast(&x.a), const_cast(d.get_ap_dimchange_t())); } inline lincons0_array::lincons0_array(const lincons0_array& x, const dimperm& d) { a = ap_lincons0_array_permute_dimensions(const_cast(&x.a), const_cast(d.get_ap_dimperm_t())); } /* destructor */ /* ========== */ inline lincons0_array::~lincons0_array() { ap_lincons0_array_clear(&a); } /* assignment */ /* ========== */ inline lincons0_array& lincons0_array::operator= (const lincons0_array& x) { if (&x!=this) { ap_lincons0_array_clear(&a); a = ap_lincons0_array_make(x.a.size); for (size_t i=0; i(x[i].get_ap_lincons0_t())); return *this; } inline lincons0_array& lincons0_array::operator= (const std::vector& x) { size_t size = x.size(); ap_lincons0_array_clear(&a); a = ap_lincons0_array_make(size); for (size_t i=0; i(x[i].get_ap_lincons0_t())); return *this; } /* dimension operations */ /* ==================== */ inline void lincons0_array::resize(size_t size) { ap_lincons0_array_resize(&a, size); } inline void lincons0_array::add_dimensions(const dimchange& d) { ap_lincons0_array_add_dimensions_with(&a, const_cast(d.get_ap_dimchange_t())); } inline void lincons0_array::permute_dimensions(const dimperm& d) { ap_lincons0_array_permute_dimensions_with(&a, const_cast(d.get_ap_dimperm_t())); } /* access */ /* ====== */ inline size_t lincons0_array::size() const { return a.size; } inline lincons0* lincons0_array::contents() { return reinterpret_cast(a.p); } inline const lincons0* lincons0_array::contents() const { return reinterpret_cast(a.p); } inline lincons0& lincons0_array::operator[](size_t i) { return reinterpret_cast(a.p[i]); } inline const lincons0& lincons0_array::operator[](size_t i) const { return reinterpret_cast(a.p[i]); } inline lincons0& lincons0_array::get(size_t i) { if (i >= a.size) throw std::out_of_range("apron::lincons0_array::get(size_t)"); return reinterpret_cast(a.p[i]); } inline const lincons0& lincons0_array::get(size_t i) const { if (i >= a.size) throw std::out_of_range("apron::lincons0_array::get(size_t)"); return reinterpret_cast(a.p[i]); } /* conversion */ /* ========== */ inline lincons0_array::operator std::vector() const { size_t sz = size(); std::vector v = std::vector(sz); for (size_t i=0;i(&a), name_of_dim); } /* tests */ /* ===== */ inline bool lincons0_array::is_linear() const { return ap_lincons0_array_is_linear(const_cast(&a)); } inline bool lincons0_array::is_quasilinear() const { return ap_lincons0_array_is_quasilinear(const_cast(&a)); } /* C-level compatibility */ /* ===================== */ inline const ap_lincons0_array_t* lincons0_array::get_ap_lincons0_array_t() const { return &a; } inline ap_lincons0_array_t* lincons0_array::get_ap_lincons0_array_t() { return &a; } apron-dist-0.9.10/apron/apronxx/apxx_manager_inline.hh0000640014525101416610000001060310723557216022724 0ustar bjeannetpopart/* -*- C++ -*- * apxx_manager_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ /* =============== */ /* tbool_t */ /* =============== */ inline tbool::tbool(bool a) : x(a ? tbool_true : tbool_false) { } inline tbool::tbool(tbool_t a) : x(a) { } inline tbool::operator tbool_t() { return x; } inline tbool::operator bool() { return x==tbool_true; } inline tbool operator|| (tbool a, tbool b) { return tbool(tbool_or(a.x,b.x)); } inline tbool operator&& (tbool a, tbool b) { return tbool(tbool_and(a.x,b.x)); } inline tbool operator! (tbool a) { return tbool(tbool_not(a.x)); } inline std::ostream& operator<<(std::ostream& os, tbool x) { switch (x.x) { case tbool_true: return os << "true"; case tbool_false: return os << "false"; case tbool_top: return os << "top"; default: throw std::invalid_argument("apron::operator<<(ostream&, tbool) invalid boolean"); } } /* =============== */ /* manager */ /* =============== */ inline manager::manager(ap_manager_t* m) : m(m) { // disable aborting as we manually check exception flags and throw C++ exceptions (see raise) for (size_t i=0; ioption.abort_if_exception[i] = 0; } inline bool manager::exception_raised() { return (m->result.exclog && m->result.exclog->exn!=AP_EXC_NONE); } // called at the end of every abstract function inline void manager::raise(ap_manager_t* m, const char* msg, ap_abstract0_t* a) { if (!m->result.exclog) return; std::string s = std::string(msg)+" : "+m->result.exclog->msg; switch (m->result.exclog->exn) { case AP_EXC_NONE: break; case AP_EXC_TIMEOUT: ap_manager_clear_exclog(m); if (a) ap_abstract0_free(m,a); throw timeout(s); break; case AP_EXC_OUT_OF_SPACE: ap_manager_clear_exclog(m); if (a) ap_abstract0_free(m,a); throw std::length_error(s); break; case AP_EXC_OVERFLOW: ap_manager_clear_exclog(m); if (a) ap_abstract0_free(m,a); throw std::overflow_error(s); break; case AP_EXC_INVALID_ARGUMENT: ap_manager_clear_exclog(m); if (a) ap_abstract0_free(m,a); throw std::invalid_argument(s); break; case AP_EXC_NOT_IMPLEMENTED: ap_manager_clear_exclog(m); if (a) ap_abstract0_free(m,a); throw not_implemented(s); break; default: ap_manager_clear_exclog(m); if (a) ap_abstract0_free(m,a); throw std::range_error(s+" (unknwon exception type)"); break; } } inline void manager::raise(const char* msg, ap_abstract0_t* a) { manager::raise(m, msg, a); } inline void manager::raise(ap_manager_t* m, const char* msg, ap_abstract1_t a) { if (!m->result.exclog || m->result.exclog->exn==AP_EXC_NONE) return; ap_environment_free(a.env); raise(m,msg,a.abstract0); } inline void manager::raise(const char* msg, ap_abstract1_t a) { manager::raise(m, msg, a); } inline manager::manager(const manager& x) : m(ap_manager_copy(x.m)) { } inline manager::~manager() { ap_manager_free(m); } inline manager& manager::operator= (const manager& x) { ap_manager_t* mm = ap_manager_copy(x.m); ap_manager_free(m); m = mm; return *this; } inline std::string manager::get_library() const { return std::string(ap_manager_get_library(m)); } inline std::string manager::get_version() const { return std::string(ap_manager_get_version(m)); } inline ap_funopt_t& manager::get_funopt(ap_funid_t funid) { if (funid<=AP_FUNID_UNKNOWN || funid>=AP_FUNID_SIZE) throw std::out_of_range("apron::manager::get_funopt(ap_funid_t) unknown funid"); return m->option.funopt[funid]; } inline ap_scalar_discr_t& manager::get_scalar_discr() { return m->option.scalar_discr; } inline bool manager::get_flag_exact() { return ap_manager_get_flag_exact(m); } inline bool manager::get_flag_best() { return ap_manager_get_flag_best(m); } inline ap_manager_t* manager::get_ap_manager_t() { return m; } inline void manager::fpu_init() { if (!ap_fpu_init()) throw std::runtime_error("apron::manager::fpu_init() failed"); } inline std::ostream& operator<< (std::ostream& os, const manager& s) { return os << ap_manager_get_library(s.m) << ", " << ap_manager_get_version(s.m); } apron-dist-0.9.10/apron/apronxx/apxx_lincons0.hh0000640014525101416610000003340310703144237021475 0ustar bjeannetpopart/* -*- C++ -*- * apxx_lincons0.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_LINCONS0_HH #define __APXX_LINCONS0_HH #include #include "ap_lincons0.h" #include "apxx_linexpr0.hh" namespace apron { //! Unsatisfiable constraint, to simplify initialisations and assignments. struct unsat {}; /* ================================= */ /* lincons0 */ /* ================================= */ /*! \brief Level 0 linear constraint (ap_lincons0_t wrapper). * * A lincons0 object represents a linear constraint: expr==0, expr>=0, expr>0, expr!=0, or expr==0 mod c. * It stores and manages a linexpr0 (linear expression with scalar or interval coefficients), * a constraint type (==, >=, >, !=, mod), and (for modulo constraint) an auxiliary scalar (c). */ class lincons0 : public use_malloc { protected: ap_lincons0_t l; //!< Structure managed by APRON. //! Internal use only. Performs a shallow copy and takes ownership of the contents. lincons0(ap_lincons0_t l); friend class abstract0; public: /* constructors */ /* ============ */ /** @name Construtors */ //@{ /*! \brief Creates a new (non-modulo) constraint from an empty linear expression. * * The auxiliary scalar is not created (has_modulo returns false). * The linear expression is created sparse and empty (has_linexpr returns true). * \arg \c constyp can be \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, or \c AP_CONS_DISEQ (but not \c AP_CONS_EQMOD). */ lincons0(ap_constyp_t constyp=AP_CONS_SUPEQ); /*! \brief Creates a new (non-modulo) constraint from a linear expression (copied). * * The auxiliary scalar is not created (has_modulo returns false). * \arg \c constyp can be \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, or \c AP_CONS_DISEQ (but not \c AP_CONS_EQMOD). */ lincons0(ap_constyp_t constyp, const linexpr0& lin); /*! \brief Creates a new constraint from a linear expression and a modulo scalar (both copied). * * \arg \c constyp can be \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, \c AP_CONS_EQMOD, or \c AP_CONS_DISEQ. */ lincons0(ap_constyp_t constyp, const linexpr0& lin, const scalar& modulo); //! (Deep) copy of a constraint. lincons0(const lincons0& x); //! Makes a (deep) copy of a constraint, and applies a dimension change to the underlying linear expression. lincons0(const lincons0& x, const dimchange& d); //! Makes a (deep) copy of a constraint, and applies a permutation to the underlying linear expression. lincons0(const lincons0& x, const dimperm& d); //! Makes an unsatisfiable constraint (-1>=0). lincons0(unsat x); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ //! Frees the constraint, including the embedded linear expression and optional modulo scalar. ~lincons0(); //@} /* assignment */ /* ========== */ /** @name Assignments */ //@{ //! (Deep) copy. lincons0& operator= (const lincons0& x); //! Assigns an unsatisfiable constraint to *this (-1>=0). lincons0& operator= (unsat x); /*! \brief Sets the auxiliary scalar modulo to c (copied). * * Does not fail as get_modulo can: if the constraint was created without an auxiliary scalar, * it is created. */ void set_modulo(const scalar& c); /*! \brief Sets the underlying linear expression to c (copied). * * Does not fail as get_linexpr can: if the constraint was created without an underlying expression, * it is created. */ void set_linexpr(const linexpr0& c); //@} /* dimension operations */ /* ==================== */ /** @name Dimension operations */ //@{ /*! \brief Resizes the underlying linear expression. * * \throw std::invalid_argument if no valid linear expression has been defined. */ void resize(size_t size); /*! \brief Changes the dimension of the underlying linear expression. * * \throw std::invalid_argument if no valid linear expression has been defined. */ void add_dimensions(const dimchange& d); /*! \brief Applies a permutation to the underlying linear expression. * * \throw std::invalid_argument if no valid linear expression has been defined. */ void permute_dimensions(const dimperm& d); //@} /* access */ /* ====== */ /** @name Accesses, size */ //@{ /* size */ /*! \brief Returns the size of the underlying linear expression. * * \throw std::invalid_argument if no valid linear expression has been defined. */ size_t size() const; /* get */ /*! \brief Returns a (modifiable) reference to the constraint type. * * \return either \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, \c AP_CONS_EQMOD, or \c AP_CONS_DISEQ. */ ap_constyp_t& get_constyp(); /*! \brief Returns a reference to the constraint type. * * \return either \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, \c AP_CONS_EQMOD, or \c AP_CONS_DISEQ. */ const ap_constyp_t& get_constyp() const; //! Whether the constraint has a valid auxiliary scalar (used in modulo constraints). bool has_modulo() const; /*! \brief Whether the constraint has a valid linear expression. * * \note The only way the linear expression may be invalid is when accessing fields of uninitialised * (or enlarged) lincons0_array. */ bool has_linexpr() const; /*! \brief Returns a (modifiable) reference to the auxiliary scalar. * * \throw std::invalid_argument if no valid auxiliary scalar has been defined. */ scalar& get_modulo(); /*! \brief Returns a reference to the auxiliary scalar. * * \throw std::invalid_argument if no valid auxiliary scalar has been defined. */ const scalar& get_modulo() const; /*! \brief Returns a (modifiable) reference to the underlying linear expression. * * \throw std::invalid_argument if no valid linear expression has been defined. */ linexpr0& get_linexpr(); /*! \brief Returns a reference to the underlying linear expression. * * \throw std::invalid_argument if no valid linear expression has been defined. */ const linexpr0& get_linexpr() const; /*! \brief Returns a (modifiable) reference to the constant coefficient. * * \throw std::invalid_argument if no valid linear expression has been defined. */ coeff& get_cst(); /*! \brief Returns a reference to the constant coefficient. * * \throw std::invalid_argument if no valid linear expression has been defined. */ const coeff& get_cst() const; /*! \brief Returns a (modifiable) reference to the coefficient corresponding to the given dimension. * * \throw std::out_of_range if the expression is dense and the dimension exceeds the size * of the expression; if the expression is sparse, it will be extended and no exception is thrown * \throw std::invalid_argument if no valid linear expression has been defined. */ coeff& operator[](ap_dim_t dim); /*! \brief Returns a reference to the coefficient corresponding to the given dimension. * * \throw std::out_of_range if the expression is dense and the dimension exceeds the size * of the expression; if the expression is sparse, it will be extended and no exception is thrown * \throw std::invalid_argument if no valid linear expression has been defined. */ const coeff& operator[](ap_dim_t dim) const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ /*! \brief Printing. * * Variable naming can be configured through the varname stream modifier. * * \throw std::invalid_argument if the underlying expression is missing, or the * auxiliary scalar is missing (for modulo). */ friend std::ostream& operator<< (std::ostream& os, const lincons0& s); //! Prints to a C stream. void print(char** name_of_dim=NULL, FILE* stream=stdout) const; //@} /* tests */ /* ===== */ /** @name Tests */ //@{ /*! \brief Whether the constraint is unsatisfiable. * * \throw std::invalid_argument if no valid linear expression has been defined. */ bool is_unsat() const; /*! \brief Whether the underlying linear expression has only scalar coefficients. * * \throw std::invalid_argument if no valid linear expression has been defined. */ bool is_linear() const; /*! \brief Whether the underlying linear expression has only scalar coefficients, * except maybe for the constant one. * * \throw std::invalid_argument if no valid linear expression has been defined. */ bool is_quasilinear() const; // TODO: equal, compare (currently not in ap_lincons0.h) ??? //@} /* TODO: evaluation, linearization, intelligent constructors */ /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. const ap_lincons0_t* get_ap_lincons0_t() const; //! Returns a pointer to the internal APRON object stored in *this. ap_lincons0_t* get_ap_lincons0_t(); //@} }; /* ================================= */ /* lincons0_array */ /* ================================= */ /*! \brief Array of linear constraints (ap_lincons0_array_t wrapper). * * A lincons0_array represents an array of linear constraints. */ class lincons0_array : public use_malloc { protected: ap_lincons0_array_t a; //!< Structure managed by APRON. //! Internal use only. Performs a shallow copy and takes ownership of the contents. lincons0_array(ap_lincons0_array_t& a) : a(a) {} friend class lincons1_array; friend class abstract0; public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ /*! \brief Creates a new array of the given size containing uninitialized constraints. * * has_modulo and has_linexpr will return false on all elements of the array. */ lincons0_array(size_t size); //! (Deep) copy. lincons0_array(const lincons0_array& x); //! Makes a (deep) copy of the array and applies add_dimensions to all constraints. lincons0_array(const lincons0_array& x, const dimchange& d); //! Makes a (deep) copy of the array and applies permute_dimensions to all constraints. lincons0_array(const lincons0_array& x, const dimperm& d); //! Creates a lincons0_array from an array of constraints of the given size (copied). lincons0_array(size_t size, const lincons0 x[]); //! Creates a lincons0_array from a vector of constraints (copied). lincons0_array(const std::vector& x); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ //! Frees the space used by the array and all its constraints. ~lincons0_array(); //@} /* assignment */ /* ========== */ /** @name Assignments */ //@{ //! (Deep) copy. lincons0_array& operator= (const lincons0_array& x); /*! \brief Copies the constraints from the array into *this. * * \arg x should contain (at least) size elements. */ lincons0_array& operator= (const lincons0 x[]); //! Copies the constraints from the vector into the array, changing its size if needed. lincons0_array& operator= (const std::vector& x); //@} /* dimension operations */ /* ==================== */ /** @name Dimension operations */ //@{ //! Resizes the array. void resize(size_t size); //! Applies add_dimensions to all constraints in the array. void add_dimensions(const dimchange& d); //! Applies permute_dimensions to all constraints in the array. void permute_dimensions(const dimperm& d); //@} /* access */ /* ====== */ /** @name Accesses */ //@{ //! Returns the size of the array. size_t size() const; //! Returns a pointer to the start of the internal array holding the constraints. lincons0* contents(); //! Returns a pointer to the start of the internal array holding the constraints. const lincons0* contents() const; //! Returns a (modifiable) reference to an element, no bound checking. lincons0& operator[](size_t i); //! Returns a reference to an element, no bound checking. const lincons0& operator[](size_t i) const; /*! \brief Returns a (modifiable) reference to an element (bound-checked). * * \throw std::out_of_range if the index is invalid. */ lincons0& get(size_t i); /*! \brief Returns a reference to an element (bound-checked). * * \throw std::out_of_range if the index is invalid. */ const lincons0& get(size_t i) const; //@} /* conversion */ /* ========== */ /** @name Conversion */ //@{ //! Returns a copy of the linear constraints in the form of a vector. operator std::vector() const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ /*! \brief Printing. * * Variable naming can be configured through the varname stream modifier. * * \throw std::invalid_argument an underlying expression is missing, or an * auxiliary scalar is missing (for modulo constraint). */ friend std::ostream& operator<< (std::ostream& os, const lincons0_array& s); //! Prints to a C stream. void print(char** name_of_dim = NULL, FILE* stream=stdout) const; //@} /* tests */ /* ===== */ /** @name Tests */ //@{ //! Whether all constraints are linear. bool is_linear() const; //! Whether all constraints are quasi-linear. bool is_quasilinear() const; //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. const ap_lincons0_array_t* get_ap_lincons0_array_t() const; //! Returns a pointer to the internal APRON object stored in *this. ap_lincons0_array_t* get_ap_lincons0_array_t(); //@} }; #include "apxx_lincons0_inline.hh" } #endif /* __APXX_LINCONS0_HH */ apron-dist-0.9.10/apron/apronxx/apxx_abstract0_inline.hh0000640014525101416610000011702610723557216023204 0ustar bjeannetpopart/* -*- C++ -*- * apxx_abstract0_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ /* ================================= */ /* abstract0 */ /* ================================= */ /* constructors */ /* ============ */ inline abstract0::abstract0(ap_abstract0_t* x) : a(x) {} inline abstract0::abstract0(manager &m, size_t intdim, size_t realdim, top x) { a = ap_abstract0_top(m.get_ap_manager_t(), intdim, realdim); m.raise("apron::abstract0::abstract0(manager&, size_t, size_t, top)",a); } inline abstract0::abstract0(manager &m, size_t intdim, size_t realdim, bottom x) { a = ap_abstract0_bottom(m.get_ap_manager_t(), intdim, realdim); m.raise("apron::abstract0::abstract0(manager&, size_t, size_t, bottom)",a); } inline abstract0::abstract0(manager &m, const abstract0& t) { a = ap_abstract0_copy(m.get_ap_manager_t(), t.a); m.raise("apron::abstract0::abstract0::(manager&, const abstract0&)",a); } inline abstract0::abstract0(manager &m, size_t intdim, size_t realdim, const interval_array& x) { if (x.size()(x.get_ap_interval_t_array())); m.raise("apron::abstract0::abstract0(manager&, size_t, size_t, const interval_array&)",a); } inline abstract0::abstract0(manager &m, size_t intdim, size_t realdim, const lincons0_array& x) { a = ap_abstract0_of_lincons_array(m.get_ap_manager_t(), intdim, realdim, const_cast(x.get_ap_lincons0_array_t())); m.raise("apron::abstract0::abstract0(manager&, size_t, size_t, const lincons0_array&)",a); } inline abstract0::abstract0(manager &m, size_t intdim, size_t realdim, const tcons0_array& x) { a = ap_abstract0_of_tcons_array(m.get_ap_manager_t(), intdim, realdim, const_cast(x.get_ap_tcons0_array_t())); m.raise("apron::abstract0::abstract0(manager&, size_t, size_t, const tcons0_array&)",a); } inline abstract0::abstract0(const abstract0& t) { a = ap_abstract0_copy(t.a->man, t.a); manager::raise(a->man, "apron::abstract0::abstract0(abstract0&)",a); } /* destructors */ /* =========== */ inline abstract0::~abstract0() { if (a && a->value) ap_abstract0_free(a->man, a); a = NULL; } inline void abstract0::free(manager& m) { if (a && a->value) ap_abstract0_free(m.get_ap_manager_t(), a); a = NULL; } /* assignments */ /* =========== */ inline abstract0& abstract0::operator=(const abstract0& t) { if (&t!=this) { ap_abstract0_t* r = ap_abstract0_copy(a->man, t.a); manager::raise(a->man, "apron::abstract0::operator=(const abstract0&)",r); ap_abstract0_free(a->man, a); a = r; } return *this; } inline abstract0& abstract0::operator=(top t) { ap_dimension_t d = ap_abstract0_dimension(a->man, a); ap_abstract0_t* r = ap_abstract0_top(a->man, d.intdim, d.realdim); manager::raise(a->man, "apron::abstract0::operator=(top)",r); ap_abstract0_free(a->man, a); a = r; return *this; } inline abstract0& abstract0::operator=(bottom t) { ap_dimension_t d = ap_abstract0_dimension(a->man, a); ap_abstract0_t* r = ap_abstract0_bottom(a->man, d.intdim, d.realdim); manager::raise(a->man, "apron::abstract0::operator=(bottom)",r); ap_abstract0_free(a->man, a); a = r; return *this; } inline abstract0& abstract0::operator=(const interval_array& x) { ap_dimension_t d = ap_abstract0_dimension(a->man, a); if (x.size()man, d.intdim, d.realdim, const_cast(x.get_ap_interval_t_array())); manager::raise(a->man, "apron::abstract0::operator=(const interval_array&)",r); ap_abstract0_free(a->man, a); a = r; return *this; } inline abstract0& abstract0::operator=(const lincons0_array& x) { ap_dimension_t d = ap_abstract0_dimension(a->man, a); ap_abstract0_t* r = ap_abstract0_of_lincons_array(a->man, d.intdim, d.realdim, const_cast(x.get_ap_lincons0_array_t())); manager::raise(a->man, "apron::abstract0::operator=(const lincons0_array&)",r); ap_abstract0_free(a->man, a); a = r; return *this; } inline abstract0& abstract0::operator=(const tcons0_array& x) { ap_dimension_t d = ap_abstract0_dimension(a->man, a); ap_abstract0_t* r = ap_abstract0_of_tcons_array(a->man, d.intdim, d.realdim, const_cast(x.get_ap_tcons0_array_t())); manager::raise(a->man, "apron::abstract0::operator=(const tcons0_array&)",r); ap_abstract0_free(a->man, a); a = r; return *this; } inline abstract0& abstract0::set(manager& m, const abstract0& t) { if (&t!=this) { ap_abstract0_t* r = ap_abstract0_copy(m.get_ap_manager_t(), t.a); m.raise("apron::abstract0::set(manager&, abstract0&)",r); ap_abstract0_free(m.get_ap_manager_t(), a); a = r; } return *this; } inline abstract0& abstract0::set(manager& m, top t, size_t intdim, size_t realdim) { ap_dimension_t d = ap_abstract0_dimension(m.get_ap_manager_t(), a); if (intdim!=AP_DIM_MAX) d.intdim = intdim; if (realdim!=AP_DIM_MAX) d.realdim = realdim; ap_abstract0_t* r = ap_abstract0_top(m.get_ap_manager_t(), d.intdim, d.realdim); m.raise("apron::abstract0::set(manager&, top, size_t, size_t)",r); ap_abstract0_free(m.get_ap_manager_t(), a); a = r; return *this; } inline abstract0& abstract0::set(manager& m, bottom t, size_t intdim, size_t realdim) { ap_dimension_t d = ap_abstract0_dimension(m.get_ap_manager_t(), a); if (intdim!=AP_DIM_MAX) d.intdim = intdim; if (realdim!=AP_DIM_MAX) d.realdim = realdim; ap_abstract0_t* r = ap_abstract0_bottom(m.get_ap_manager_t(), d.intdim, d.realdim); m.raise("apron::abstract0::set(manager&, bottom, size_t, size_t)",r); ap_abstract0_free(m.get_ap_manager_t(), a); a = r; return *this; } inline abstract0& abstract0::set(manager& m, const interval_array& x, size_t intdim, size_t realdim) { ap_dimension_t d = ap_abstract0_dimension(m.get_ap_manager_t(), a); if (intdim!=AP_DIM_MAX) d.intdim = intdim; if (realdim!=AP_DIM_MAX) d.realdim = realdim; if (x.size()(x.get_ap_interval_t_array())); m.raise("apron::abstract0::set(manager&, const interval_array&, size_t, size_t)",r); ap_abstract0_free(m.get_ap_manager_t(), a); a = r; return *this; } inline abstract0& abstract0::set(manager& m, const lincons0_array& x, size_t intdim, size_t realdim) { ap_dimension_t d = ap_abstract0_dimension(m.get_ap_manager_t(), a); if (intdim!=AP_DIM_MAX) d.intdim = intdim; if (realdim!=AP_DIM_MAX) d.realdim = realdim; ap_abstract0_t* r = ap_abstract0_of_lincons_array(m.get_ap_manager_t(), d.intdim, d.realdim, const_cast(x.get_ap_lincons0_array_t())); m.raise("apron::abstract0::set(manager&, const lincons0_array&, size_t, size_t)",r); ap_abstract0_free(m.get_ap_manager_t(), a); a = r; return *this; } inline abstract0& abstract0::set(manager& m, const tcons0_array& x, size_t intdim, size_t realdim) { ap_dimension_t d = ap_abstract0_dimension(m.get_ap_manager_t(), a); if (intdim!=AP_DIM_MAX) d.intdim = intdim; if (realdim!=AP_DIM_MAX) d.realdim = realdim; ap_abstract0_t* r = ap_abstract0_of_tcons_array(m.get_ap_manager_t(), d.intdim, d.realdim, const_cast(x.get_ap_tcons0_array_t())); m.raise("apron::abstract0::set(manager&, const tcons0_array&, size_t, size_t)",r); ap_abstract0_free(m.get_ap_manager_t(), a); a = r; return *this; } /* representation */ /* ============== */ inline abstract0& abstract0::minimize(manager& m) { ap_abstract0_minimize(m.get_ap_manager_t(), a); m.raise("abstract0::minimize(manager&)"); return *this; } inline abstract0& abstract0::canonicalize(manager& m) { ap_abstract0_canonicalize(m.get_ap_manager_t(), a); m.raise("apron::abstract0::canonicalize(manager&)"); return *this; } inline abstract0& abstract0::approximate(manager& m, int algorithm) { ap_abstract0_approximate(m.get_ap_manager_t(), a, algorithm); m.raise("apron::abstract0::approximate(manager&, int)"); return *this; } /* printing */ /* ======== */ inline void abstract0::print(manager& m, char** name_of_dim, FILE* stream) const { ap_abstract0_fprint(stream, m.get_ap_manager_t(), a, name_of_dim); m.raise("apron::abstract0::print(manager&, char**, FILE*)"); } inline void printdiff(manager& m, const abstract0& x, const abstract0& y, char** name_of_dim, FILE* stream) { ap_abstract0_fprintdiff(stream, m.get_ap_manager_t(), x.a, y.a, name_of_dim); m.raise("apron::printdiff(manager&, const abstract0&, const abstract0&, char**, FILE*)"); } inline void abstract0::dump(manager& m, FILE* stream) const { ap_abstract0_fdump(stream, m.get_ap_manager_t(), a); m.raise("apron::abstract0::dump(manager&, FILE*)"); } inline std::ostream& operator<< (std::ostream& os, const abstract0& s) { manager m = s.get_manager(); if (s.is_bottom(m)) return os << "bottom"; if (s.is_top(m)) return os << "top"; return os << s.to_lincons_array(m); } /* serialisation */ /* ============= */ inline std::string* abstract0::serialize(manager& m) const { ap_membuf_t x = ap_abstract0_serialize_raw(m.get_ap_manager_t(), a); m.raise("apron::abstract0::serialize_raw(manager&)"); std::string* s = new std::string((char*)x.ptr, x.size); ::free(x.ptr); return s; } inline abstract0& deserialize(manager& m, abstract0& dst, const std::string& s, size_t* eaten) { size_t x = s.size(); ap_abstract0_t* r = ap_abstract0_deserialize_raw(m.get_ap_manager_t(), const_cast(s.data()), &x); m.raise("apron::deserialize_raw(manager&, abstract0&, const std::string&, size_t*)",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; if (eaten) *eaten = x; return dst; } /* access */ /* ====== */ inline manager abstract0::get_manager() const { return ap_manager_copy(ap_abstract0_manager(a)); } inline ap_dimension_t abstract0::get_dimension(manager& m) const { ap_dimension_t d = ap_abstract0_dimension(m.get_ap_manager_t(), a); m.raise("apron::abstract0::get_dimension(manager&)"); return d; } inline size_t abstract0::size(manager& m) const { size_t sz = ap_abstract0_size(m.get_ap_manager_t(), a); m.raise("apron::abstract0::get_size(manager&)"); return sz; } /* predicates */ /* ========== */ inline bool abstract0::is_bottom(manager& m) const { bool r = ap_abstract0_is_bottom(m.get_ap_manager_t(), a); m.raise("apron::abstract0::is_bottom(manager&)"); return r; } inline bool abstract0::is_top(manager& m) const { bool r = ap_abstract0_is_top(m.get_ap_manager_t(), a); m.raise("apron::abstract0::is_top(manager&)"); return r; } inline bool abstract0::is_eq(manager& m, const abstract0& x) const { bool r = ap_abstract0_is_eq(m.get_ap_manager_t(), a, x.a); m.raise("apron::abstract0::is_eq(manager&, const abstract&)"); return r; } inline bool abstract0::is_leq(manager& m, const abstract0& x) const { bool r = ap_abstract0_is_leq(m.get_ap_manager_t(), a, x.a); m.raise("apron::abstract0::is_leq(manager&, const abstract&)"); return r; } inline bool abstract0::sat(manager& m, const lincons0& l) const { bool r = ap_abstract0_sat_lincons(m.get_ap_manager_t(), a, const_cast(l.get_ap_lincons0_t())); m.raise("apron::abstract0::sat(manager&, const lincons0&)"); return r; } inline bool abstract0::sat(manager& m, const tcons0& l) const { bool r = ap_abstract0_sat_tcons(m.get_ap_manager_t(), a, const_cast(l.get_ap_tcons0_t())); m.raise("apron::abstract0::sat(manager&, const tcons0&)"); return r; } inline bool abstract0::sat(manager& m, ap_dim_t dim, const interval& i) const { bool r = ap_abstract0_sat_interval(m.get_ap_manager_t(), a, dim, const_cast(i.get_ap_interval_t())); m.raise("apron::abstract0::sat(manager&, ap_dim_t, const interval&)"); return r; } inline bool abstract0::is_dimension_unconstrained(manager& m, ap_dim_t dim) const { bool r = ap_abstract0_is_dimension_unconstrained(m.get_ap_manager_t(), a, dim); m.raise("apron::abstract0::is_dimension_unconstrained(manager&, ap_dim_t)"); return r; } inline bool operator== (const abstract0& x, const abstract0& y) { bool r = ap_abstract0_is_eq(x.a->man, x.a, y.a); manager::raise(x.a->man, "apron::operator==(const abstract0&, const abstract0&)"); return r; } inline bool operator!= (const abstract0& x, const abstract0& y) { return !(x==y); } inline bool operator<= (const abstract0& x, const abstract0& y) { bool r = ap_abstract0_is_leq(x.a->man, x.a, y.a); manager::raise(x.a->man, "apron::operator<=(const abstract0&, const abstract0&)"); return r; } inline bool operator>= (const abstract0& x, const abstract0& y) { return y<=x; } inline bool operator> (const abstract0& x, const abstract0& y) { return !(x<=y); } inline bool operator< (const abstract0& x, const abstract0& y) { return !(y<=x); } /* Properties */ /* ========== */ inline interval abstract0::bound(manager& m, const linexpr0& l) const { ap_interval_t* r = ap_abstract0_bound_linexpr(m.get_ap_manager_t(), a, const_cast(l.get_ap_linexpr0_t())); if (m.exception_raised()) ap_interval_free(r); m.raise("apron::abstract0::bound(manager&, const linexpr0&)"); return r; } inline interval abstract0::bound(manager& m, const texpr0& l) const { ap_interval_t* r = ap_abstract0_bound_texpr(m.get_ap_manager_t(), a, const_cast(l.get_ap_texpr0_t())); if (m.exception_raised()) ap_interval_free(r); m.raise("apron::abstract0::bound(manager&, const texpr0&)"); return r; } inline interval abstract0::bound(manager& m, ap_dim_t d) const { ap_interval_t* r = ap_abstract0_bound_dimension(m.get_ap_manager_t(), a, d); if (m.exception_raised()) ap_interval_free(r); m.raise("apron::abstract0::bound(manager&, ap_dim_t)"); return r; } inline interval_array abstract0::to_box(manager& m) const { ap_dimension_t d = ap_abstract0_dimension(m.get_ap_manager_t(), a); ap_interval_t** r = ap_abstract0_to_box(m.get_ap_manager_t(), a); m.raise("apron::abstract0::to_box(manager&)"); return interval_array(d.intdim+d.realdim, r); } inline lincons0_array abstract0::to_lincons_array(manager& m) const { ap_lincons0_array_t r = ap_abstract0_to_lincons_array(m.get_ap_manager_t(), a); if (m.exception_raised()) ap_lincons0_array_clear(&r); m.raise("apron::abstract0::to_lincons_array(manager&)"); return r; } inline tcons0_array abstract0::to_tcons_array(manager& m) const { ap_tcons0_array_t r = ap_abstract0_to_tcons_array(m.get_ap_manager_t(), a); if (m.exception_raised()) ap_tcons0_array_clear(&r); m.raise("apron::abstract0::to_tcons_array(manager&)"); return r; } inline generator0_array abstract0::to_generator_array(manager& m) const { ap_generator0_array_t r = ap_abstract0_to_generator_array(m.get_ap_manager_t(), a); if (m.exception_raised()) ap_generator0_array_clear(&r); m.raise("apron::abstract0::to_generator_array(manager&)"); return r; } /* Meet and join */ /* ============= */ inline abstract0& abstract0::meet(manager& m, const abstract0& y) { a = ap_abstract0_meet(m.get_ap_manager_t(), true, a, y.a); m.raise("apron::abstract0::meet(manager&, const abstract0&)"); return *this; } inline abstract0& meet(manager& m, abstract0& dst, const abstract0& x, const abstract0& y) { ap_abstract0_t* r = ap_abstract0_meet(m.get_ap_manager_t(), false, x.a, y.a); m.raise("apron::meet(manager&, abstract0&, const abstract0&, const abstract0&)",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } inline abstract0& meet(manager& m, abstract0& dst, const std::vector& x) { ap_abstract0_t* xx[x.size()]; for (size_t i=0;i(x[i])->get_ap_abstract0_t(); ap_abstract0_t* r = ap_abstract0_meet_array(m.get_ap_manager_t(), xx, x.size()); m.raise("apron::meet(manager&, abstract0&, const std::vector&)",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } inline abstract0& meet(manager& m, abstract0& dst, size_t sz, const abstract0 * const x[]) { ap_abstract0_t* xx[sz]; for (size_t i=0;i(x[i])->get_ap_abstract0_t(); ap_abstract0_t* r = ap_abstract0_meet_array(m.get_ap_manager_t(), xx, sz); m.raise("apron::meet(manager&, abstract0&, size_t, const abstract0 * const [])",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } inline abstract0& abstract0::join(manager& m, const abstract0& y) { a = ap_abstract0_join(m.get_ap_manager_t(), true, a, y.a); m.raise("apron::abstract0::join(manager&, const abstract0&)"); return *this; } inline abstract0& join(manager& m, abstract0& dst, const abstract0& x, const abstract0& y) { ap_abstract0_t* r = ap_abstract0_join(m.get_ap_manager_t(), false, x.a, y.a); m.raise("apron::join(manager&, abstract0&, const abstract0&, const abstract0&)",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } inline abstract0& join(manager& m, abstract0& dst, size_t sz, const abstract0 * const x[]) { ap_abstract0_t* xx[sz]; for (size_t i=0;i(x[i])->get_ap_abstract0_t(); ap_abstract0_t* r = ap_abstract0_join_array(m.get_ap_manager_t(), xx, sz); m.raise("apron::join(manager&, abstract0&, size_t, const abstract0 * const [])",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } inline abstract0& join(manager& m, abstract0& dst, const std::vector& x) { ap_abstract0_t* xx[x.size()]; for (size_t i=0;i(x[i])->get_ap_abstract0_t(); ap_abstract0_t* r = ap_abstract0_join_array(m.get_ap_manager_t(), xx, x.size()); m.raise("apron::join(manager&, abstract0&, const std::vector&)",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } inline abstract0& abstract0::meet(manager& m, const lincons0_array& y) { a = ap_abstract0_meet_lincons_array(m.get_ap_manager_t(), true, a, const_cast(y.get_ap_lincons0_array_t())); m.raise("apron::abstract0::meet(manager&, const lincons0_array&)"); return *this; } inline abstract0& meet(manager& m, abstract0& dst, const abstract0& x, const lincons0_array& y) { ap_abstract0_t* r = ap_abstract0_meet_lincons_array(m.get_ap_manager_t(), false, x.a, const_cast(y.get_ap_lincons0_array_t())); m.raise("apron::meet(manager&, abstract0&, const abstract0&, const lincons0_array&)",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } inline abstract0& abstract0::meet(manager& m, const tcons0_array& y) { a = ap_abstract0_meet_tcons_array(m.get_ap_manager_t(), true, a, const_cast(y.get_ap_tcons0_array_t())); m.raise("apron::abstract0::meet(manager&, const tcons0_array&)"); return *this; } inline abstract0& meet(manager& m, abstract0& dst, const abstract0& x, const tcons0_array& y) { ap_abstract0_t* r = ap_abstract0_meet_tcons_array(m.get_ap_manager_t(), false, x.a, const_cast(y.get_ap_tcons0_array_t())); m.raise("apron::meet(manager&, abstract0&, const abstract0&, const tcons0_array&)",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } inline abstract0& abstract0::add_rays(manager& m, const generator0_array& y) { a = ap_abstract0_add_ray_array(m.get_ap_manager_t(), true, a, const_cast(y.get_ap_generator0_array_t())); m.raise("apron::abstract0::add_rays(manager&, const generator0_array&)"); return *this; } inline abstract0& add_rays(manager& m, abstract0& dst, const abstract0& x, const generator0_array& y) { ap_abstract0_t* r = ap_abstract0_add_ray_array(m.get_ap_manager_t(), false, x.a, const_cast(y.get_ap_generator0_array_t())); m.raise("apron::add_rays(manager&, abstract0&, const abstract0&, const generator0_array&)",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } inline abstract0& abstract0::operator*=(const abstract0& y) { a = ap_abstract0_meet(a->man, true, a, y.a); manager::raise(a->man, "apron::abstract0::operator*=(const abstract0&)"); return *this; } inline abstract0& abstract0::operator+=(const abstract0& y) { a = ap_abstract0_join(a->man, true, a, y.a); manager::raise(a->man, "apron::abstract0::operator+=(const abstract0&)"); return *this; } inline abstract0& abstract0::operator*=(const lincons0_array& y) { a = ap_abstract0_meet_lincons_array(a->man, true, a, const_cast(y.get_ap_lincons0_array_t())); manager::raise(a->man, "apron::abstract0::operator*=(const lincons0_array&)"); return *this; } inline abstract0& abstract0::operator*=(const tcons0_array& y) { a = ap_abstract0_meet_tcons_array(a->man, true, a, const_cast(y.get_ap_tcons0_array_t())); manager::raise(a->man, "apron::abstract0::operator*=(const tcons0_array&)"); return *this; } inline abstract0& abstract0::operator+=(const generator0_array& y) { a = ap_abstract0_add_ray_array(a->man, true, a, const_cast(y.get_ap_generator0_array_t())); manager::raise(a->man, "apron::abstract0::operator+=(const generator0_array&)"); return *this; } /* Assignments */ /* =========== */ inline abstract0& abstract0::assign(manager& m, ap_dim_t dim, const linexpr0& l, const abstract0& inter) { const linexpr0* ll = &l; return assign(m, 1, &dim, &ll, inter); } inline abstract0& abstract0::assign(manager& m, size_t size, const ap_dim_t dim[], const linexpr0 * const l[], const abstract0& inter) { a = ap_abstract0_assign_linexpr_array(m.get_ap_manager_t(), true, a, const_cast(dim), reinterpret_cast(const_cast(l)), size, inter.a); m.raise("apron::abstract0::assign(manager&, size_t size, const ap_dim_t[], const linexpr0 * const [], const abstract0&)"); return *this; } inline abstract0& abstract0::assign(manager& m, const std::vector& dim, const std::vector& l, const abstract0& inter) { if (l.size()!=dim.size()) throw std::invalid_argument("apron::abstract0::assign(manager&, const std::vector&, const std::vector&, const abstract0&) vectors have different size"); const linexpr0* ll[l.size()]; ap_dim_t dd[dim.size()]; for (size_t i=0;i(dim), reinterpret_cast(const_cast(l)), size, inter.a); m.raise("apron::assign((manager&, abstract0&, const abstract0&, size_t size, const ap_dim_t[], const linexpr0 * const [], const abstract0&)",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } inline abstract0& assign(manager& m, abstract0& dst, const abstract0& src, const std::vector& dim, const std::vector& l, const abstract0& inter) { if (l.size()!=dim.size()) throw std::invalid_argument("apron::assign(manager&, abstract0, const abstract0&, const std::vector&, const std::vector&, const abstract0&) vectors have different size"); const linexpr0* ll[l.size()]; ap_dim_t dd[dim.size()]; for (size_t i=0;i(dim), reinterpret_cast(const_cast(l)), size, inter.a); m.raise("apron::abstract0::assign(manager&, size_t size, const ap_dim_t[], const texpr0 * const [], const abstract0&)"); return *this; } inline abstract0& abstract0::assign(manager& m, const std::vector& dim, const std::vector& l, const abstract0& inter) { if (l.size()!=dim.size()) throw std::invalid_argument("apron::abstract0::assign(manager&, const std::vector&, const std::vector&, const abstract0&) vectors have different size"); const texpr0* ll[l.size()]; ap_dim_t dd[dim.size()]; for (size_t i=0;i(dim), reinterpret_cast(const_cast(l)), size, inter.a); m.raise("apron::assign((manager&, abstract0&, const abstract0&, size_t size, const ap_dim_t[], const texpr0 * const [], const abstract0&)",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } inline abstract0& assign(manager& m, abstract0& dst, const abstract0& src, const std::vector& dim, const std::vector& l, const abstract0& inter) { if (l.size()!=dim.size()) throw std::invalid_argument("apron::assign(manager&, abstract0, const abstract0&, const std::vector&, const std::vector&, const abstract0&) vectors have different size"); const texpr0* ll[l.size()]; ap_dim_t dd[dim.size()]; for (size_t i=0;i(dim), reinterpret_cast(const_cast(l)), size, inter.a); m.raise("apron::abstract0::substitute(manager&, size_t size, const ap_dim_t[], const linexpr0 * const [], const abstract0&)"); return *this; } inline abstract0& abstract0::substitute(manager& m, const std::vector& dim, const std::vector& l, const abstract0& inter) { if (l.size()!=dim.size()) throw std::invalid_argument("apron::abstract0::substitute(manager&, const std::vector&, const std::vector&, const abstract0&) vectors have different size"); const linexpr0* ll[l.size()]; ap_dim_t dd[dim.size()]; for (size_t i=0;i(dim), reinterpret_cast(const_cast(l)), size, inter.a); m.raise("apron::substitute((manager&, abstract0&, const abstract0&, size_t size, const ap_dim_t[], const linexpr0 *const [], const abstract0&)",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } inline abstract0& substitute(manager& m, abstract0& dst, const abstract0& src, const std::vector& dim, const std::vector& l, const abstract0& inter) { if (l.size()!=dim.size()) throw std::invalid_argument("apron::substitute(manager&, abstract0, const abstract0&, const std::vector&, const std::vector&, const abstract0&) vectors have different size"); const linexpr0* ll[l.size()]; ap_dim_t dd[dim.size()]; for (size_t i=0;i(dim), reinterpret_cast(const_cast(l)), size, inter.a); m.raise("apron::abstract0::substitute(manager&, size_t size, const ap_dim_t[], const texpr0 * const [], const abstract0&)"); return *this; } inline abstract0& abstract0::substitute(manager& m, const std::vector& dim, const std::vector& l, const abstract0& inter) { if (l.size()!=dim.size()) throw std::invalid_argument("apron::abstract0::substitute(manager&, const std::vector&, const std::vector&, const abstract0&) vectors have different size"); const texpr0* ll[l.size()]; ap_dim_t dd[dim.size()]; for (size_t i=0;i(dim), reinterpret_cast(const_cast(l)), size, inter.a); m.raise("apron::substitute((manager&, abstract0&, const abstract0&, size_t size, const ap_dim_t[], const texpr0 * const [], const abstract0&)",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } inline abstract0& substitute(manager& m, abstract0& dst, const abstract0& src, const std::vector& dim, const std::vector& l, const abstract0& inter) { if (l.size()!=dim.size()) throw std::invalid_argument("apron::substitute(manager&, abstract0, const abstract0&, const std::vector&, const std::vector&, const abstract0&) vectors have different size"); const texpr0* ll[l.size()]; ap_dim_t dd[dim.size()]; for (size_t i=0;i(dim), size, project); m.raise("apron::abstract0::substitute(orget(manager&, size_t size, const ap_dim_t[], bool)"); return *this; } inline abstract0& abstract0::forget(manager& m, const std::vector dim, bool project) { ap_dim_t dd[dim.size()]; for (size_t i=0;i(dim), size, project); m.raise("apron::forget(manager&, abstract0&, const abstract0&, size_t size, const ap_dim_t[], bool)",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } inline abstract0& forget(manager& m, abstract0& dst, const abstract0& src, const std::vector dim, bool project) { ap_dim_t dd[dim.size()]; for (size_t i=0;i(d.get_ap_dimchange_t()), project); m.raise("apron::abstract0::add_dimensions(manager&, const dimchange&, bool)"); return *this; } inline abstract0& abstract0::remove_dimensions(manager& m, const dimchange& d) { a = ap_abstract0_remove_dimensions(m.get_ap_manager_t(), true, a, const_cast(d.get_ap_dimchange_t())); m.raise("apron::abstract0::remove_dimensions(manager&, const dimchange&)"); return *this; } inline abstract0& abstract0::permute_dimensions(manager& m, const dimperm& d) { a = ap_abstract0_permute_dimensions(m.get_ap_manager_t(), true, a, const_cast(d.get_ap_dimperm_t())); m.raise("apron::abstract0::permute_dimensions(manager&, const dimperm&)"); return *this; } inline abstract0& add_dimensions(manager& m, abstract0& dst, const abstract0& src, const dimchange& d, bool project) { ap_abstract0_t* r = ap_abstract0_add_dimensions(m.get_ap_manager_t(), false, src.a, const_cast(d.get_ap_dimchange_t()), project); m.raise("apron::add_dimensions(manager&, abstract0&, const abstract0&, const dimchange&, bool)",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } inline abstract0& remove_dimensions(manager& m, abstract0& dst, const abstract0& src, const dimchange& d) { ap_abstract0_t* r = ap_abstract0_remove_dimensions(m.get_ap_manager_t(), false, src.a, const_cast(d.get_ap_dimchange_t())); m.raise("apron::remove_dimensions(manager&, abstract0&, const abstract0&, const dimchange&)",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } inline abstract0& permute_dimensions(manager& m, abstract0& dst, const abstract0& src, const dimperm& d) { ap_abstract0_t* r = ap_abstract0_permute_dimensions(m.get_ap_manager_t(), false, src.a, const_cast(d.get_ap_dimperm_t())); m.raise("apron::permute_dimensions(manager&, abstract0&, const abstract0&, const dimperm&)",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } /* Expansion and folding */ /* ===================== */ inline abstract0& abstract0::expand(manager& m, ap_dim_t dim, size_t n) { a = ap_abstract0_expand(m.get_ap_manager_t(), true, a, dim, n); m.raise("apron::abstract0::expand(manager&, ap_dim_t, size_t)"); return *this; } inline abstract0& expand(manager& m, abstract0& dst, const abstract0& src, ap_dim_t dim, size_t n) { ap_abstract0_t* r = ap_abstract0_expand(m.get_ap_manager_t(), false, src.a, dim, n); m.raise("apron::expand(manager&, abstract0&, const abstract0&, ap_dim_t, size_t)",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } inline abstract0& abstract0::fold(manager& m, size_t size, const ap_dim_t dim[]) { a = ap_abstract0_fold(m.get_ap_manager_t(), true, a, const_cast(dim), size); m.raise("apron::abstract0::fold(manager&, size_t size, const ap_dim_t[])"); return *this; } inline abstract0& abstract0::fold(manager& m, const std::vector& dim) { ap_dim_t dd[dim.size()]; for (size_t i=0;i(dim), size); m.raise("apron::fold(manager&, abstract0&, const abstract0&, size_t size, const ap_dim_t[])",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } inline abstract0& fold(manager& m, abstract0& dst, const abstract0& src, const std::vector& dim) { ap_dim_t dd[dim.size()]; for (size_t i=0;i(l.get_ap_lincons0_array_t())); m.raise("apron::widening(manager&, abstract0&, const abstract0&, const abstract0&, const lincons0_array&)",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } /* Closure */ /* ======= */ inline abstract0& abstract0::closure(manager& m) { a = ap_abstract0_closure(m.get_ap_manager_t(), true, a); m.raise("apron::abstract0::closured(manager&)"); return *this; } inline abstract0& closure(manager& m, abstract0& dst, const abstract0& src) { ap_abstract0_t* r = ap_abstract0_closure(m.get_ap_manager_t(), false, src.a); m.raise("apron::closure(manager&, abstract0&, const abstract0&)",r); ap_abstract0_free(m.get_ap_manager_t(), dst.a); dst.a = r; return dst; } /* C-level compatibility */ /* ===================== */ inline ap_abstract0_t* abstract0::get_ap_abstract0_t() { return a; } inline const ap_abstract0_t* abstract0::get_ap_abstract0_t() const { return a; } apron-dist-0.9.10/apron/apronxx/apxx_tcons1_inline.hh0000640014525101416610000003305310703144237022516 0ustar bjeannetpopart/* -*- C++ -*- * apxx_tcons1_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ /* ================================= */ /* tcons1 */ /* ================================= */ /* constructors */ /* ============ */ inline tcons1::tcons1(ap_tcons1_t l) : l(l) {} inline tcons1::tcons1(const environment& env, ap_constyp_t constyp) { l.tcons0 = ap_tcons0_make(constyp, NULL, NULL); l.env = ap_environment_copy(const_cast(env.get_ap_environment_t())); } inline tcons1::tcons1(ap_constyp_t constyp, const texpr1::builder& t) { ap_texpr1_t* x = ap_texpr1_copy(const_cast(t.get_ap_texpr1_t())); l = ap_tcons1_make(constyp, x, NULL); free(x); } inline tcons1::tcons1(ap_constyp_t constyp, const texpr1::builder& t, const scalar& modulo) { ap_scalar_t* mmodulo = ap_scalar_alloc_set(const_cast(modulo.get_ap_scalar_t())); ap_texpr1_t* x = ap_texpr1_copy(const_cast(t.get_ap_texpr1_t())); l = ap_tcons1_make(constyp, x, mmodulo); free(x); } inline tcons1::tcons1(const tcons1& x) : l(ap_tcons1_copy(const_cast(&x.l))) {} inline tcons1::tcons1(const tcons1& x, const environment& e) { if (!x.l.tcons0.texpr0) throw std::invalid_argument("apron::tcons1::tcons1(const tcons1&, const enviroment&) empty expression"); bool r = ap_tcons1_extend_environment(&l, const_cast(&x.l), const_cast(e.get_ap_environment_t())); if (r) throw std::invalid_argument("apron::tcons1::tcons1(const tcons1&, const enviroment&) not a super-environment"); } inline tcons1::tcons1(const environment& e, unsat x) { l.tcons0 = ap_tcons0_make_unsat(); l.env = ap_environment_copy(const_cast(e.get_ap_environment_t())); } inline tcons1::tcons1(const lincons1& x) : l(ap_tcons1_from_lincons1(const_cast(x.get_ap_lincons1_t()))) {} /* destructor */ /* ========== */ inline tcons1::~tcons1() { ap_tcons1_clear(&l); } /* 'Intelligent' constructors */ /* ========================== */ inline tcons1 operator>=(const texpr1::builder& a, const texpr1::builder& b) { if (b.is_zero()) return tcons1(AP_CONS_SUPEQ,a); else if (a.is_zero()) return tcons1(AP_CONS_SUPEQ,-b); else return tcons1(AP_CONS_SUPEQ,a-b); } inline tcons1 operator<=(const texpr1::builder& a, const texpr1::builder& b) { if (b.is_zero()) return tcons1(AP_CONS_SUPEQ,-a); else if (a.is_zero()) return tcons1(AP_CONS_SUPEQ,b); else return tcons1(AP_CONS_SUPEQ,b-a); } inline tcons1 operator> (const texpr1::builder& a, const texpr1::builder& b) { if (b.is_zero()) return tcons1(AP_CONS_SUP,a); else if (a.is_zero()) return tcons1(AP_CONS_SUP,-b); else return tcons1(AP_CONS_SUP,a-b); } inline tcons1 operator< (const texpr1::builder& a, const texpr1::builder& b) { if (b.is_zero()) return tcons1(AP_CONS_SUP,-a); else if (a.is_zero()) return tcons1(AP_CONS_SUP,b); else return tcons1(AP_CONS_SUP,b-a); } inline tcons1 operator==(const texpr1::builder& a, const texpr1::builder& b) { if (b.is_zero()) return tcons1(AP_CONS_EQ,a); else if (a.is_zero()) return tcons1(AP_CONS_EQ,b); else return tcons1(AP_CONS_EQ,a-b); } inline tcons1 operator!=(const texpr1::builder& a, const texpr1::builder& b) { if (b.is_zero()) return tcons1(AP_CONS_DISEQ,a); else if (a.is_zero()) return tcons1(AP_CONS_DISEQ,b); else return tcons1(AP_CONS_DISEQ,a-b); } /* assignment */ /* ========== */ inline tcons1& tcons1::operator= (const tcons1& x) { if (&x!=this) { ap_tcons1_clear(&l); l = ap_tcons1_copy(const_cast(&x.l)); } return *this; } inline tcons1& tcons1::operator= (unsat x) { ap_tcons0_clear(&l.tcons0); l.tcons0 = ap_tcons0_make_unsat(); return *this; } inline tcons1& tcons1::operator= (const lincons1& x) { ap_tcons1_clear(&l); l = ap_tcons1_from_lincons1(const_cast(x.get_ap_lincons1_t())); return *this; } inline void tcons1::set_modulo(const scalar& c) { get_tcons0().set_modulo(c); } inline void tcons1::set_texpr(const texpr1::builder& c) { ap_texpr1_t* cc = ap_texpr1_copy(const_cast(c.get_ap_texpr1_t())); if (l.tcons0.texpr0) ap_texpr0_free(l.tcons0.texpr0); ap_environment_free(l.env); l.tcons0.texpr0 = cc->texpr0; l.env = cc->env; free(cc); } /* dimension operations */ /* ==================== */ inline void tcons1::extend_environment(const environment& e) { bool r = ap_tcons1_extend_environment_with(&l, const_cast(e.get_ap_environment_t())); if (r) throw std::invalid_argument("apron::tcons1::extend_environment(const environment&) not a super-environment"); } /* access */ /* ====== */ inline environment tcons1::get_environment() const { return ap_environment_copy(l.env); } inline const tcons0& tcons1::get_tcons0() const { return reinterpret_cast(l.tcons0); } inline tcons0& tcons1::get_tcons0() { return reinterpret_cast(l.tcons0); } inline ap_constyp_t& tcons1::get_constyp() { return get_tcons0().get_constyp(); } inline const ap_constyp_t& tcons1::get_constyp() const { return get_tcons0().get_constyp(); } inline bool tcons1::has_modulo() const { return get_tcons0().has_modulo(); } inline bool tcons1::has_texpr() const { return get_tcons0().has_texpr(); } inline scalar& tcons1::get_modulo() { if (!get_tcons0().has_modulo()) throw std::invalid_argument("apron::tcons1::get_modulo() empty scalar"); return get_tcons0().get_modulo(); } inline const scalar& tcons1::get_modulo() const { if (!get_tcons0().has_modulo()) throw std::invalid_argument("apron::tcons1::get_modulo() empty scalar"); return get_tcons0().get_modulo(); } inline texpr1::iterator tcons1::get_texpr() { if (!l.tcons0.texpr0) throw std::invalid_argument("apron::tcons1::get_texpr() empty expression"); return texpr1::iterator(l.tcons0.texpr0,l.env); } inline texpr1::const_iterator tcons1::get_texpr() const { if (!l.tcons0.texpr0) throw std::invalid_argument("apron::tcons1::get_texpr() empty expression"); return texpr1::const_iterator(l.tcons0.texpr0,l.env); } /* print */ /* ===== */ inline std::ostream& operator<< (std::ostream& os, const tcons1& s) { os << s.get_texpr(); switch (s.get_constyp()) { case AP_CONS_EQ: return os << " = 0"; case AP_CONS_SUPEQ: return os << " >= 0"; case AP_CONS_SUP: return os << " > 0"; case AP_CONS_EQMOD: return os << " = 0 mod " << s.get_modulo(); case AP_CONS_DISEQ: return os << " != 0"; default: throw std::invalid_argument("apron::operator<<(ostream&, const tcons1&) invalid constraint type"); } } inline void tcons1::print(FILE* stream) const { ap_tcons1_fprint(stream, const_cast(&l)); } /* tests */ /* ===== */ inline bool tcons1::is_interval_cst() const { return get_texpr().is_interval_cst(); } inline bool tcons1::is_interval_linear() const { return get_texpr().is_interval_linear(); } inline bool tcons1::is_interval_polynomial() const { return get_texpr().is_interval_polynomial(); } inline bool tcons1::is_interval_polyfrac() const { return get_texpr().is_interval_polyfrac(); } inline bool tcons1::is_scalar() const { return get_texpr().is_scalar(); } /* C-level compatibility */ /* ===================== */ inline const ap_tcons1_t* tcons1::get_ap_tcons1_t() const { return &l; } inline ap_tcons1_t* tcons1::get_ap_tcons1_t() { return &l; } /* ================================= */ /* tcons1_array */ /* ================================= */ /* constructors */ /* ============ */ inline tcons1_array::tcons1_array(ap_tcons1_array_t& a) : a(a) {} inline tcons1_array::tcons1_array(const environment& e, const tcons0_array& x) { size_t sz = x.size(); a = ap_tcons1_array_make(const_cast(e.get_ap_environment_t()), sz); for (size_t i=0; i(e.get_ap_environment_t()), size); } inline tcons1_array::tcons1_array(const tcons1_array& x) { size_t sz = x.size(); a = ap_tcons1_array_make(x.get_environment().get_ap_environment_t(), sz); for (size_t i=0; i(&x.a), const_cast(e.get_ap_environment_t())); if (r) throw std::invalid_argument("apron::tcons1_array::tcons1_array(const tcons1_array, const environment&) not a super-environment"); } inline tcons1_array::tcons1_array(size_t sz, const tcons1 x[]) { if (sz<1) throw std::invalid_argument("apron::tcons1_array::tcons1_array(size_t, const tcons1) null size"); a = ap_tcons1_array_make(x[0].get_environment().get_ap_environment_t(), sz); for (size_t i=0; i (x[i].get_tcons0().get_ap_tcons0_t())); } inline tcons1_array::tcons1_array(const std::vector& x) { size_t sz = x.size(); if (sz<1) throw std::invalid_argument("apron::tcons1_array::tcons1_array(const vector&) null size"); a = ap_tcons1_array_make(x[0].get_environment().get_ap_environment_t(), sz); for (size_t i=0; i (x[i].get_tcons0().get_ap_tcons0_t())); } /* destructor */ /* ========== */ inline tcons1_array::~tcons1_array() { ap_tcons1_array_clear(&a); } /* assignment */ /* ========== */ inline tcons1_array& tcons1_array::operator= (const tcons1_array& x) { if (this!=&x) { size_t sz = x.size(); ap_tcons1_array_clear(&a); a = ap_tcons1_array_make(x.get_environment().get_ap_environment_t(), sz); for (size_t i=0; i (x[i].get_tcons0().get_ap_tcons0_t())); } return *this; } inline tcons1_array& tcons1_array::operator= (const std::vector& x) { size_t size = x.size(); if (size<1) { ap_tcons1_array_t aa = ap_tcons1_array_make(a.env,0); ap_tcons1_array_clear(&a); a = aa; return *this; } ap_tcons1_array_clear(&a); a = ap_tcons1_array_make(x[0].get_environment().get_ap_environment_t(), size); for (size_t i=0; i (x[i].get_tcons0().get_ap_tcons0_t())); return *this; } /* dimension operations */ /* ==================== */ inline void tcons1_array::resize(size_t size) { ap_tcons0_array_resize(&a.tcons0_array, size); } inline void tcons1_array::extend_environment(const environment& e) { bool r = ap_tcons1_array_extend_environment_with(&a, const_cast(e.get_ap_environment_t())); if (r) throw std::invalid_argument("apron::tcons1_array::extend_environment(const environment&) not a super-environment"); } /* access */ /* ====== */ inline size_t tcons1_array::size() const { return ap_tcons1_array_size(const_cast(&a)); } inline environment tcons1_array::get_environment() const { return (ap_environment_copy(ap_tcons1_array_envref(const_cast(&a)))); } inline const tcons0_array& tcons1_array::get_tcons0_array() const { return reinterpret_cast(const_cast(a.tcons0_array)); } inline tcons0_array& tcons1_array::get_tcons0_array() { return reinterpret_cast(a.tcons0_array); } inline tcons1 tcons1_array::get(size_t i) const { if (i>=size()) throw std::out_of_range("apron::tcons1_array::get(size_t)"); ap_tcons1_t c = ap_tcons1_array_get(const_cast(&a),i); ap_tcons1_t cc = ap_tcons1_copy(&c); return tcons1(cc); } inline void tcons1_array::set(size_t i, const tcons1& x) { if (i>=size()) throw std::out_of_range("apron::tcons1_array::set(size_t, const tcons1&)"); ap_tcons0_clear(&a.tcons0_array.p[i]); a.tcons0_array.p[i] = ap_tcons0_copy(const_cast (x.get_tcons0().get_ap_tcons0_t())); } /* conversion */ /* ========== */ inline tcons1_array::operator std::vector() const { size_t sz = size(); tcons1 dummy(get_environment(),unsat()); std::vector v(sz,dummy); for (size_t i=0;i(&a),i); v[i] = ap_tcons1_copy(&c); } return v; } /* print */ /* ===== */ inline std::ostream& operator<< (std::ostream& os, const tcons1_array& s) { size_t sz = s.size(); os << "{ "; for (size_t i=0;i(&a)); } /* C-level compatibility */ /* ===================== */ inline const ap_tcons1_array_t* tcons1_array::get_ap_tcons1_array_t() const { return &a; } inline ap_tcons1_array_t* tcons1_array::get_ap_tcons1_array_t() { return &a; } apron-dist-0.9.10/apron/apronxx/apxx_texpr0_inline.hh0000640014525101416610000005264311006063143022530 0ustar bjeannetpopart/* -*- C++ -*- * apxx_texpr0_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ inline dim::dim(ap_dim_t d) : d(d) {} inline dim::dim(const environment& e, const var& v) { ap_dim_t d = ap_environment_dim_of_var(const_cast(e.get_ap_environment_t()), v.get_ap_var_t()); if (d==AP_DIM_MAX) throw std::invalid_argument("apron::dim::dim(const environment&, const var&) invalid variable name"); } inline bool is_unop(ap_texpr_op_t op) { return ap_texpr_is_unop(op); } inline bool is_binop(ap_texpr_op_t op) { return ap_texpr_is_binop(op); } /* ================================= */ /* texpr0 */ /* ================================= */ inline void texpr0::init_from(ap_texpr0_t* x) { l = *x; free(x); } inline texpr0::texpr0(ap_texpr0_t* x) { init_from(x); } inline texpr0::texpr0(const builder& x) { init_from(ap_texpr0_copy(const_cast(x.get_ap_texpr0_t()))); } inline texpr0::texpr0(const const_iterator& x) { init_from(ap_texpr0_copy(const_cast(x.get_ap_texpr0_t()))); } inline texpr0::texpr0(const texpr0& x) { init_from(ap_texpr0_copy(const_cast(&x.l))); } /* linear expression */ inline texpr0::texpr0(const linexpr0& l) { init_from(ap_texpr0_from_linexpr0(const_cast(l.get_ap_linexpr0_t()))); } /* change of dimension */ inline texpr0::texpr0(const texpr0& x, const dimchange& d, bool add) { if (add) init_from(ap_texpr0_add_dimensions(const_cast(&x.l), const_cast(d.get_ap_dimchange_t()))); else init_from(ap_texpr0_remove_dimensions(const_cast(&x.l), const_cast(d.get_ap_dimchange_t()))); } inline texpr0::texpr0(const texpr0& x, const dimperm& d) { init_from(ap_texpr0_permute_dimensions(const_cast(&x.l), const_cast(d.get_ap_dimperm_t()))); } inline texpr0::texpr0(const texpr0& x, ap_dim_t dim, const texpr0& dst) { init_from(ap_texpr0_substitute(const_cast(&x.l), dim, const_cast(&dst.l))); } /* destructor */ /* ========== */ /* (deep) destruction */ inline texpr0::~texpr0() { ap_texpr0_clear(&l); } /* assignment */ /* ========== */ /* (deep) copy */ inline texpr0& texpr0::operator= (const builder& x) { // copy first, as x.l may alias this! ap_texpr0_t* c = ap_texpr0_copy(const_cast(x.get_ap_texpr0_t())); ap_texpr0_clear(&l); init_from(c); return *this; } inline texpr0& texpr0::operator= (const texpr0& x) { // copy first, as x.l may alias this! ap_texpr0_t* c = ap_texpr0_copy(const_cast(&x.l)); ap_texpr0_clear(&l); init_from(c); return *this; } inline texpr0& texpr0::operator= (const const_iterator& x) { // copy first, as x.l may alias this! ap_texpr0_t* c = ap_texpr0_copy(const_cast(x.get_ap_texpr0_t())); ap_texpr0_clear(&l); init_from(c); return *this; } inline texpr0& texpr0::operator= (const linexpr0& x) { ap_texpr0_clear(&l); init_from(ap_texpr0_from_linexpr0(const_cast(x.get_ap_linexpr0_t()))); return *this; } /* print */ /* ===== */ inline std::ostream& operator<< (std::ostream& os, const texpr0& s) { return os << s.root(); } inline void texpr0::print(char** name_of_dim, FILE* stream) const { root().print(name_of_dim,stream); } /* tests, size */ /* =========== */ inline bool texpr0::is_zero() const { return root().is_zero(); } inline bool texpr0::equal(const texpr0& x) const { return root().equal(x); } inline size_t texpr0::depth() const { return root().depth(); } inline size_t texpr0::size() const { return root().size(); } inline ap_dim_t texpr0::max_dim() const { return root().max_dim(); } inline bool texpr0::has_dim(ap_dim_t d) const { return root().has_dim(d); } inline std::vector texpr0::dimlist() const { return root().dimlist(); } inline bool texpr0::is_interval_cst() const { return root().is_interval_cst(); } inline bool texpr0::is_interval_linear() const { return root().is_interval_linear(); } inline bool texpr0::is_interval_polynomial() const { return root().is_interval_polynomial(); } inline bool texpr0::is_interval_polyfrac() const { return root().is_interval_polyfrac(); } inline bool texpr0::is_scalar() const { return root().is_scalar(); } /* operations */ /* ========== */ inline void texpr0::substitute(ap_dim_t dim, const texpr0& dst) { ap_texpr0_substitute_with(&l,dim,const_cast(&dst.l)); } #if 0 inline interval texpr0::eval(manager& m, const abstract0& a, ap_scalar_discr_t discr, bool* pexact) const { bool b; if (!pexact) pexact = &b; return ap_eval_texpr0(m.get_ap_manager_t(), const_cast(a.get_ap_abstract0_t()), const_cast(l), discr, pexact); } inline linexpr0 texpr0::intlinearize(manager& m, const abstract0& a, ap_scalar_discr_t discr, bool quasilinearize, bool* pexact) const { bool b; if (!pexact) pexact = &b; return ap_intlinearize_texpr0(m.get_ap_manager_t(), const_cast(a.get_ap_abstract0_t()), const_cast(l), pexact, discr, quasilinearize); } #endif inline long texpr0::hash() const { return ap_texpr0_hash(const_cast(&l)); } /* change of dimension */ /* =================== */ inline void texpr0::add_dimensions(const dimchange& d) { ap_texpr0_add_dimensions_with(&l, const_cast(d.get_ap_dimchange_t())); } inline void texpr0::remove_dimensions(const dimchange& d) { ap_texpr0_remove_dimensions_with(&l, const_cast(d.get_ap_dimchange_t())); } inline void texpr0::permute_dimensions(const dimperm& d) { ap_texpr0_permute_dimensions_with(&l, const_cast(d.get_ap_dimperm_t())); } /* C-level compatibility */ /* ===================== */ inline ap_texpr0_t* texpr0::get_ap_texpr0_t() { return &l; } inline const ap_texpr0_t* texpr0::get_ap_texpr0_t() const { return &l; } /* ================================= */ /* iterator */ /* ================================= */ /* constructors */ /* ============ */ inline texpr0::const_iterator texpr0::root() const { return const_iterator(const_cast(&l)); } inline texpr0::const_iterator::const_iterator(ap_texpr0_t* l) : l(l) {} inline texpr0::const_iterator::const_iterator(const texpr0& e) : l(const_cast(e.get_ap_texpr0_t())) {} inline texpr0::const_iterator::const_iterator(const const_iterator& i) : l(i.l) {} /* access */ /* ====== */ inline ap_texpr_discr_t texpr0::const_iterator::get_discr() const { return l->discr; } inline const coeff& texpr0::const_iterator::get_coeff() const { if (l->discr!=AP_TEXPR_CST) throw(bad_discriminant("apron::texpr0::const_iterator::get_coeff()")); return reinterpret_cast(l->val.cst); } inline ap_dim_t texpr0::const_iterator::get_dim() const { if (l->discr!=AP_TEXPR_DIM) throw(bad_discriminant("apron::texpr0::const_iterator::get_dim()")); return l->val.dim; } inline ap_texpr_op_t texpr0::const_iterator::get_op() const { if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::const_iterator::get_op()")); return l->val.node->op; } inline ap_texpr_rtype_t texpr0::const_iterator::get_rtype() const { if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::const_iterator::get_type()")); return l->val.node->type; } inline ap_texpr_rdir_t texpr0::const_iterator::get_rdir() const { if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::const_iterator::get_dir()")); return l->val.node->dir; } /* traversal */ /* ========= */ inline texpr0::const_iterator& texpr0::const_iterator::operator=(const const_iterator& i) { l = i.l; return *this; } inline texpr0::const_iterator texpr0::const_iterator::child() const { if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::const_iterator::child()")); if (!l->val.node->exprA) throw(std::out_of_range("apron::texpr0::const_iterator::child()")); return l->val.node->exprA; } inline texpr0::const_iterator texpr0::const_iterator::left() const { if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::const_iterator::left()")); if (!l->val.node->exprA) throw(std::out_of_range("apron::texpr0::const_iterator::left()")); return l->val.node->exprA; } inline texpr0::const_iterator texpr0::const_iterator::right() const { if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::const_iterator::right()")); if (!l->val.node->exprB) throw(std::out_of_range("apron::texpr0::const_iterator::right()")); return l->val.node->exprB; } /* print */ /* ===== */ extern void apxx_texpr0_ostream(std::ostream& os, ap_texpr0_t* a, std::vector* names); inline std::ostream& operator<< (std::ostream& os, const texpr0::const_iterator& s) { apxx_texpr0_ostream(os, const_cast(s.l), get_varname(os)); return os; } inline void texpr0::const_iterator::print(char** name_of_dim, FILE* stream) const { ap_texpr0_fprint(stream, const_cast(l), name_of_dim); } /* tests, size */ /* =========== */ inline bool texpr0::const_iterator::is_zero() const { return l->discr==AP_TEXPR_CST && ap_coeff_zero(&const_cast(l)->val.cst); } inline bool texpr0::const_iterator::equal(const texpr0& x) const { return ap_texpr0_equal(const_cast(l), const_cast(x.get_ap_texpr0_t())); } inline size_t texpr0::const_iterator::depth() const { return ap_texpr0_depth(const_cast(l)); } inline size_t texpr0::const_iterator::size() const { return ap_texpr0_size(const_cast(l)); } inline ap_dim_t texpr0::const_iterator::max_dim() const { return ap_texpr0_max_dim(const_cast(l)); } inline bool texpr0::const_iterator::has_dim(ap_dim_t d) const { return ap_texpr0_has_dim(const_cast(l), d); } inline std::vector texpr0::const_iterator::dimlist() const { ap_dim_t* d = ap_texpr0_dimlist(const_cast(l)); ap_dim_t i; for (i=0; d[i]!=AP_DIM_MAX; i++); std::vector r = std::vector(i,0); for (i=0; d[i]!=AP_DIM_MAX; i++) r[i] = d[i]; free(d); return r; } inline bool texpr0::const_iterator::is_interval_cst() const { return ap_texpr0_is_interval_cst(const_cast(l)); } inline bool texpr0::const_iterator::is_interval_linear() const { return ap_texpr0_is_interval_linear(const_cast(l)); } inline bool texpr0::const_iterator::is_interval_polynomial() const { return ap_texpr0_is_interval_polynomial(const_cast(l)); } inline bool texpr0::const_iterator::is_interval_polyfrac() const { return ap_texpr0_is_interval_polyfrac(const_cast(l)); } inline bool texpr0::const_iterator::is_scalar() const { return ap_texpr0_is_scalar(const_cast(l)); } /* C-level compatibility */ /* ===================== */ inline ap_texpr0_t* texpr0::const_iterator::get_ap_texpr0_t() { return l; } inline const ap_texpr0_t* texpr0::const_iterator::get_ap_texpr0_t() const { return l; } /* constructors */ /* ============ */ inline texpr0::iterator texpr0::root() { return iterator(*this); } inline texpr0::iterator::iterator(ap_texpr0_t* l) : texpr0::const_iterator(l) {} inline texpr0::iterator::iterator(texpr0& e) : texpr0::const_iterator(e.get_ap_texpr0_t()) {} inline texpr0::iterator::iterator(const iterator& i) : texpr0::const_iterator(i) {} /* substitution */ /* ============ */ inline texpr0::iterator& texpr0::iterator::operator= (const builder& c) { ap_texpr0_t* cc = ap_texpr0_copy(const_cast(c.get_ap_texpr0_t())); ap_texpr0_clear(l); *l = *cc; free(cc); return *this; } /* access */ /* ====== */ inline coeff& texpr0::iterator::get_coeff() const { if (l->discr!=AP_TEXPR_CST) throw(bad_discriminant("apron::texpr0::iterator::get_coeff()")); return reinterpret_cast(l->val.cst); } inline ap_dim_t& texpr0::iterator::get_dim() const { if (l->discr!=AP_TEXPR_DIM) throw(bad_discriminant("apron::texpr0::iterator::get_dim()")); return l->val.dim; } inline ap_texpr_op_t& texpr0::iterator::get_op() const { if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::iterator::get_op()")); return l->val.node->op; } inline ap_texpr_rtype_t& texpr0::iterator::get_rtype() const { if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::iterator::get_type()")); return l->val.node->type; } inline ap_texpr_rdir_t& texpr0::iterator::get_rdir() const { if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::iterator::get_dir()")); return l->val.node->dir; } /* traversal */ /* ========= */ inline texpr0::iterator& texpr0::iterator::operator=(const iterator& i) { l = i.l; return *this; } inline texpr0::iterator texpr0::iterator::child() const { if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::iterator::child()")); if (!l->val.node->exprA) throw(std::out_of_range("apron::texpr0::iterator::child()")); return l->val.node->exprA; } inline texpr0::iterator texpr0::iterator::left() const { if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::iterator::left()")); if (!l->val.node->exprA) throw(std::out_of_range("apron::texpr0::iterator::left()")); return l->val.node->exprA; } inline texpr0::iterator texpr0::iterator::right() const { if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::iterator::right()")); if (!l->val.node->exprB) throw(std::out_of_range("apron::texpr0::iterator::right()")); return l->val.node->exprB; } /* C-level compatibility */ /* ===================== */ inline ap_texpr0_t* texpr0::iterator::get_ap_texpr0_t() { return l; } inline const ap_texpr0_t* texpr0::iterator::get_ap_texpr0_t() const { return l; } /* ================================= */ /* builder */ /* ================================= */ inline void texpr0::builder::init_from(ap_texpr0_t* x) { switch (x->discr) { case AP_TEXPR_DIM: l = ap_texpr0_dim(x->val.dim); break; case AP_TEXPR_CST: l = ap_texpr0_cst(const_cast(&x->val.cst)); break; case AP_TEXPR_NODE: l = ap_texpr0_node(x->val.node->op, x->val.node->type, x->val.node->dir, x->val.node->exprA, x->val.node->exprB); break; default: throw std::invalid_argument("apron::texpr0::builder::init_from(ap_texpr0_t*) invalid discriminant"); } } inline texpr0::builder::builder(ap_texpr0_t* x) { init_from(x); } inline texpr0::builder::builder(const builder& x) { init_from(x.l); } inline texpr0::builder::builder(const const_iterator& x) { init_from(const_cast(x.get_ap_texpr0_t())); } inline texpr0::builder::builder(const texpr0& x) { init_from(const_cast(x.get_ap_texpr0_t())); } inline texpr0::builder::builder(const coeff& x) : l(ap_texpr0_cst(const_cast(x.get_ap_coeff_t()))) {} inline texpr0::builder::builder(const scalar& x) : l(ap_texpr0_cst_scalar(const_cast(x.get_ap_scalar_t()))) {} inline texpr0::builder::builder(const mpq_class& x) : l(ap_texpr0_cst_scalar_mpq(const_cast(x).get_mpq_t())) {} inline texpr0::builder::builder(mpfr_t x) : l(ap_texpr0_cst_scalar_mpfr(x)) {} inline texpr0::builder::builder(int x) : l(ap_texpr0_cst_scalar_int(x)) {} inline texpr0::builder::builder(long x) : l(ap_texpr0_cst_scalar_int(x)) {} inline texpr0::builder::builder(double x) : l(ap_texpr0_cst_scalar_double(x)) {} inline texpr0::builder::builder(const frac& x) : l(ap_texpr0_cst_scalar_frac(x.num, x.den)) {} inline texpr0::builder::builder(const interval& x) : l(ap_texpr0_cst_interval(const_cast(x.get_ap_interval_t()))) {} inline texpr0::builder::builder(const scalar& inf, const scalar& sup) : l(ap_texpr0_cst_interval_scalar(const_cast(inf.get_ap_scalar_t()), const_cast(sup.get_ap_scalar_t()))) {} inline texpr0::builder::builder(const mpq_class& inf, const mpq_class& sup) : l(ap_texpr0_cst_interval_mpq(const_cast(inf).get_mpq_t(), const_cast(sup).get_mpq_t())) {} inline texpr0::builder::builder(mpfr_t inf, mpfr_t sup) : l(ap_texpr0_cst_interval_mpfr(inf,sup)) {} inline texpr0::builder::builder(int inf, int sup) : l(ap_texpr0_cst_interval_int(inf, sup)) {} inline texpr0::builder::builder(long inf, long sup) : l(ap_texpr0_cst_interval_int(inf, sup)) {} inline texpr0::builder::builder(double inf, double sup) : l(ap_texpr0_cst_interval_double(inf, sup)) {} inline texpr0::builder::builder(const frac& inf, const frac& sup) : l(ap_texpr0_cst_interval_frac(inf.num, inf.den, sup.num, sup.den)) {} inline texpr0::builder::builder(top t) : l(ap_texpr0_cst_interval_top()) {} inline texpr0::builder::builder(dim d) : l(ap_texpr0_dim(d.d)) {} inline texpr0::builder::builder(ap_texpr_op_t op, const builder& argA, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { if (!ap_texpr_is_unop(op)) throw std::invalid_argument("apron::texpr0::builder::builder(ap_texpr_op_t, const builder&, ap_texpr_rtype_t, ap_texpr_rdir_t) not a unary operator"); l = ap_texpr0_unop(op, const_cast(argA.l), rtype, rdir); } inline texpr0::builder::builder(ap_texpr_op_t op, const builder& argA, const builder& argB, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { if (!ap_texpr_is_binop(op)) throw std::invalid_argument("apron::texpr0::builder::builder(ap_texpr_op_t, const builder&, const builder&, ap_texpr_rtype_t, ap_texpr_rdir_t) not a binary operator"); l = ap_texpr0_binop(op, const_cast(argA.l), const_cast(argB.l), rtype, rdir); } /* 'intelligent' constructors */ inline texpr0::builder unary(ap_texpr_op_t op, const texpr0::builder& a, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr0::builder(op, a, rtype, rdir); } inline texpr0::builder binary(ap_texpr_op_t op, const texpr0::builder& a, const texpr0::builder& b, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr0::builder(op, a, b, rtype, rdir); } inline texpr0::builder add(const texpr0::builder& a, const texpr0::builder& b, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr0::builder(AP_TEXPR_ADD, a, b, rtype, rdir); } inline texpr0::builder sub(const texpr0::builder& a, const texpr0::builder& b, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr0::builder(AP_TEXPR_SUB, a, b, rtype, rdir); } inline texpr0::builder mul(const texpr0::builder& a, const texpr0::builder& b, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr0::builder(AP_TEXPR_MUL, a, b, rtype, rdir); } inline texpr0::builder div(const texpr0::builder& a, const texpr0::builder& b, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr0::builder(AP_TEXPR_DIV, a, b, rtype, rdir); } inline texpr0::builder mod(const texpr0::builder& a, const texpr0::builder& b, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr0::builder(AP_TEXPR_MOD, a, b, rtype, rdir); } inline texpr0::builder neg(const texpr0::builder& a, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr0::builder(AP_TEXPR_NEG, a, rtype, rdir); } inline texpr0::builder cast(const texpr0::builder& a, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr0::builder(AP_TEXPR_CAST, a, rtype, rdir); } inline texpr0::builder floor(const texpr0::builder& a) { return texpr0::builder(AP_TEXPR_CAST, a, AP_RTYPE_INT, AP_RDIR_DOWN); } inline texpr0::builder ceil(const texpr0::builder& a) { return texpr0::builder(AP_TEXPR_CAST, a, AP_RTYPE_INT, AP_RDIR_UP); } inline texpr0::builder trunc(const texpr0::builder& a) { return texpr0::builder(AP_TEXPR_CAST, a, AP_RTYPE_INT, AP_RDIR_ZERO); } inline texpr0::builder sqrt(const texpr0::builder& a, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr0::builder(AP_TEXPR_SQRT, a, rtype, rdir); } inline texpr0::builder operator+(const texpr0::builder& a) { return a; } inline texpr0::builder operator-(const texpr0::builder& a) { return neg(a); } inline texpr0::builder operator+(const texpr0::builder& a, const texpr0::builder& b) { return add(a,b); } inline texpr0::builder operator-(const texpr0::builder& a, const texpr0::builder& b) { return sub(a,b); } inline texpr0::builder operator*(const texpr0::builder& a, const texpr0::builder& b) { return mul(a,b); } inline texpr0::builder operator/(const texpr0::builder& a, const texpr0::builder& b) { return div(a,b); } inline texpr0::builder operator%(const texpr0::builder& a, const texpr0::builder& b) { return mod(a,b); } /* destructor */ /* ========== */ inline texpr0::builder::~builder() { switch(l->discr){ case AP_TEXPR_CST: ap_coeff_clear(&l->val.cst); break; case AP_TEXPR_DIM: break; case AP_TEXPR_NODE: free(l->val.node); break; default: assert(false); } free(l); } inline bool texpr0::builder::is_zero() const { return l->discr==AP_TEXPR_CST && ap_coeff_zero(&const_cast(l)->val.cst); } /* C-level compatibility */ /* ===================== */ inline ap_texpr0_t* texpr0::builder::get_ap_texpr0_t() { return l; } inline const ap_texpr0_t* texpr0::builder::get_ap_texpr0_t() const { return l; } apron-dist-0.9.10/apron/apronxx/apxx_ppl.hh0000640014525101416610000000223110703144237020536 0ustar bjeannetpopart/* -*- C++ -*- * apxx_ppl.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library. As it includes both APRON and PPL files, it is released under GPL license. Please read the ppl/COPYING file packaged in the distribution. */ #ifndef __APXX_PPL_HH #define __APXX_PPL_HH #include "apxx_manager.hh" #include "ap_ppl.h" namespace apron { //! Manager factory for polyhedra domain using the PPL library. class ppl_poly_manager : public manager { public: /*! \brief Creates a new manager. * * \arg \c strict whether to allow strict inequalities as well as non-strict inequalities. * * Note that abstract values created with strict and non-strict managers * are not compatible. */ ppl_poly_manager(bool strict = false); //! Copy operator. manager& operator=(const manager&); }; //! Manager factory for grid domain using the PPL library. class ppl_grid_manager : public manager { public: //! Creates a new manager. ppl_grid_manager(); //! Copy operator. manager& operator=(const manager&); }; #include "apxx_ppl_inline.hh" } #endif /* __APXX_PPL_HH */ apron-dist-0.9.10/apron/apronxx/apxx_oct.hh0000640014525101416610000000120410703144237020527 0ustar bjeannetpopart/* -*- C++ -*- * apxx_oct.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_OCT_HH #define __APXX_OCT_HH #include "apxx_manager.hh" #include "oct.h" namespace apron { //! Manager factory for the Octagon domain library. class oct_manager : public manager { public: //! \brief Creates a new manager. oct_manager(); //! Copy operator. manager& operator=(const manager&); }; #include "apxx_oct_inline.hh" } #endif /* __APXX_OCT_HH */ apron-dist-0.9.10/apron/apronxx/apxx_polka_inline.hh0000640014525101416610000000076210703144237022416 0ustar bjeannetpopart/* -*- C++ -*- * apxx_polka_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ inline polka_manager::polka_manager(bool strict) : manager(pk_manager_alloc(strict)) {} inline manager& polka_manager::operator=(const manager& m) { return manager::operator=(m); } apron-dist-0.9.10/apron/apronxx/COPYING.LGPL0000640014525101416610000006350410703144237020164 0ustar bjeannetpopart GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! apron-dist-0.9.10/apron/apronxx/apxx_expr0.hh0000640014525101416610000000073410656607364021023 0ustar bjeannetpopart/* -*- C++ -*- * apxx_expr0.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_EXPR0_HH #define __APXX_EXPR0_HH #include "apxx_linexpr0.hh" #include "apxx_lincons0.hh" #include "apxx_generator0.hh" #include "apxx_texpr0.hh" #include "apxx_tcons0.hh" #endif /* __APXX_EXPR0_HH */ apron-dist-0.9.10/apron/apronxx/apxx_generator0.hh0000640014525101416610000002362010703144237022016 0ustar bjeannetpopart/* -*- C++ -*- * apxx_generator0.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_GENERATOR0_HH #define __APXX_GENERATOR0_HH #include #include "ap_generator0.h" #include "apxx_linexpr0.hh" namespace apron { /* ================================= */ /* generator0 */ /* ================================= */ /*! \brief Level 0 generator (ap_generator0_t wrapper). * * A generator0 object represents a generator: vertex, ray, line, modular line, or modular ray. * It stores and manages a linexpr0 (linear expression with scalar coefficients only), * and a generator type (vertex, ray , etc). */ class generator0 : public use_malloc { protected: ap_generator0_t l; //!< Structure managed by APRON. //! Internal use only. Performs a shallow copy and takes ownership of the contents. generator0(ap_generator0_t& l) : l(l) {} friend class abstract0; public: /* constructors */ /* ============ */ /*! \brief Creates a new generator from an empty linear expression. * * The linear expression is created sparse and empty (has_linexpr returns true). * \arg \c gentyp can be \c AP_GEN_LINE, \c AP_GEN_RAY, \c AP_GEN_VERTEX, \c AP_GEN_LINEMOD, * or \c AP_GEN_RAYMOD. */ generator0(ap_gentyp_t gentyp=AP_GEN_RAY); /*! \brief Creates a new generator constraint from a linear expression (copied). * * \arg \c gentyp can be \c AP_GEN_LINE, \c AP_GEN_RAY, \c AP_GEN_VERTEX, \c AP_GEN_LINEMOD, * or \c AP_GEN_RAYMOD. * * \warning \c lin should have only scalar (non-interval) coefficients (unchecked). */ generator0(ap_gentyp_t gentyp, const linexpr0& lin); //! (Deep) copy of a generator. generator0(const generator0& x); //! Makes a (deep) copy of a generator, and applies a dimension change to the underlying linear expression. generator0(const generator0& x, const dimchange& d); //! Makes a (deep) copy of a generator, and applies a permutation to the underlying linear expression. generator0(const generator0& x, const dimperm& d); /* destructor */ /* ========== */ //! Frees the generator, including the embedded linear expression. ~generator0(); /* assignment */ /* ========== */ //! (Deep) copy. generator0& operator= (const generator0& x); /* dimension operations */ /* ==================== */ /*! \brief Resizes the underlying linear expression. * * \throw std::invalid_argument if no valid linear expression has been defined. */ void resize(size_t size); /*! \brief Changes the dimension of the underlying linear expression. * * \throw std::invalid_argument if no valid linear expression has been defined. */ void add_dimensions(const dimchange& d); /*! \brief Applies a permutation to the underlying linear expression. * * \throw std::invalid_argument if no valid linear expression has been defined. */ void permute_dimensions(const dimperm& d); /* access */ /* ====== */ /* size */ /*! \brief Returns the size of the underlying linear expression. * * \throw std::invalid_argument if no valid linear expression has been defined. */ size_t size() const; /* get */ /*! \brief Returns a (modifiable) reference to the constraint type. * * \return either \c AP_GEN_LINE, \c AP_GEN_RAY, \c AP_GEN_VERTEX, \c AP_GEN_LINEMOD, or \c AP_GEN_RAYMOD. */ ap_gentyp_t& get_gentyp(); /*! \brief Returns a reference to the constraint type. * * \return either \c AP_GEN_LINE, \c AP_GEN_RAY, \c AP_GEN_VERTEX, \c AP_GEN_LINEMOD, or \c AP_GEN_RAYMOD. */ const ap_gentyp_t& get_gentyp() const; /*! \brief Returns whether the generator has a valid linear expression. * * \note The only way the linear expression may be invalid is when accessing fields of uninitialised * (or enlarged) generator0_array. */ bool has_linexpr() const; /*! \brief Returns a (modifiable) reference to the underlying linear expression. * * \throw std::invalid_argument if no valid linear expression has been defined. */ linexpr0& get_linexpr(); /*! \brief Returns a reference to the underlying linear expression. * * \throw std::invalid_argument if no valid linear expression has been defined. */ const linexpr0& get_linexpr() const; /*! \brief Sets the underlying linear expression to c (copied). * * Does not fail as get_linexpr can: if the generator was created without an underlying expression, * it is created. * \warning \c c should have only scalar (non-interval) coefficients (unchecked). */ void set_linexpr(const linexpr0& c); /* print */ /* ===== */ /*! \brief Printing. * * Variable naming can be configured through the varname stream modifier. * * \throw std::invalid_argument if the underlying expression is missing. */ friend std::ostream& operator<< (std::ostream& os, const generator0& s); //! Prints to a C stream. void print(char** name_of_dim=NULL, FILE* stream=stdout) const; /* TODO: intelligent constructors */ /* C-level compatibility */ /* ===================== */ //! Returns a pointer to the internal APRON object stored in *this. const ap_generator0_t* get_ap_generator0_t() const; //! Returns a pointer to the internal APRON object stored in *this. ap_generator0_t* get_ap_generator0_t(); }; /* ================================= */ /* generator0_array */ /* ================================= */ /*! \brief Array of generators (ap_generator0_array_t wrapper). * * A generator0_array represents an array of generator(s). */ class generator0_array : public use_malloc { protected: ap_generator0_array_t a; //!< Structure managed by APRON. //! Internal use only. Performs a shallow copy and takes ownership of the contents. generator0_array(ap_generator0_array_t& a) : a(a) {} friend class abstract0; friend class generator1_array; public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ /*! \brief Creates a new array of the given size containing uninitialized generators. * * has_linexpr will return false on all elements of the array. */ generator0_array(size_t size); //! (Deep) copy. generator0_array(const generator0_array& x); //! Makes a (deep) copy of the array and applies add_dimensions to all generators. generator0_array(const generator0_array& x, const dimchange& d); //! Makes a (deep) copy of the array and applies permute_dimensions to all generators. generator0_array(const generator0_array& x, const dimperm& d); //! Creates a generator0_array from an array of generators of the given size (copied). generator0_array(size_t size, const generator0 x[]); //! Creates a generator0_array from a vector of generators (copied). generator0_array(const std::vector& x); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ //! Frees the space used by the array and all its generators. ~generator0_array(); //@} /* assignment */ /* ========== */ /** @name Assignments */ //@{ //! (Deep) copy. generator0_array& operator= (const generator0_array& x); /*! \brief Copies the generators from the array into *this. * * \arg x should contain (at least) size elements. */ generator0_array& operator= (const generator0 x[]); //! Copies the generators from the vector into the array, changing its size if needed. generator0_array& operator= (const std::vector& x); //@} /* dimension operations */ /* ==================== */ /** @name Dimension operations */ //@{ //! Resizes the array. void resize(size_t size); //! Applies add_dimensions to all generators in the array. void add_dimensions(const dimchange& d); //! Applies permute_dimensions to all generators in the array. void permute_dimensions(const dimperm& d); //@} /* access */ /* ====== */ /** @name Access */ //@{ //! Returns the size of the array. size_t size() const; //! Returns a pointer to the start of the internal array holding the generators. generator0* contents(); //! Returns a pointer to the start of the internal array holding the generators. const generator0* contents() const; //! Returns a (modifiable) reference to an element, no bound checking. generator0& operator[](size_t i); //! Returns a reference to an element, no bound checking. const generator0& operator[](size_t i) const; /*! \brief Returns a (modifiable) reference to an element (bound-checked). * * \throw std::out_of_range if the index is invalid. */ generator0& get(size_t i); /*! \brief Returns a reference to an element (bound-checked). * * \throw std::out_of_range if the index is invalid. */ const generator0& get(size_t i) const; //@} /* conversion */ /* ========== */ /** @name Conversion */ //@{ //! Returns a copy of the generators in the form of a vector. operator std::vector() const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ /*! \brief Printing. * * Variable naming can be configured through the varname stream modifier. * * \throw std::invalid_argument an underlying expression is missing. */ friend std::ostream& operator<< (std::ostream& os, const generator0_array& s); //! Prints to a C stream. void print(char** name_of_dim=NULL, FILE* stream=stdout) const; //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. const ap_generator0_array_t* get_ap_generator0_array_t() const; //! Returns a pointer to the internal APRON object stored in *this. ap_generator0_array_t* get_ap_generator0_array_t(); //@} }; #include "apxx_generator0_inline.hh" } #endif /* __APXX_GENERATOR0_HH */ apron-dist-0.9.10/apron/apronxx/apxx_manager.hh0000640014525101416610000001607311006063143021357 0ustar bjeannetpopart/* -*- C++ -*- * apxx_manager.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_MANAGER_HH #define __APXX_MANAGER_HH #include #include "ap_manager.h" #include "ap_abstract0.h" #include "ap_abstract1.h" #include "apxx_lincons0.hh" #include "apxx_tcons0.hh" #include "apxx_generator0.hh" #include "box.h" #include "pk.h" #include "oct.h" namespace apron { /* =============== */ /* tbool */ /* =============== */ /*! \brief 3-valued boolean (tbool_t wrapper). * * A tbool_t holds a value in 3-valued logic: \c tbool_true, \c tbool_false, * or \c tbool_top (don't know). */ struct tbool { public: tbool_t x; //!< Either \c tbool_false, \c tbool_true, or \c tbool_top. //! Converts true to \c tbool_true and false to \c tbool_false. tbool(bool a); //! Conversion from tbool_t. tbool(tbool_t a); //! Conversion to tbool_t. operator tbool_t(); //! Returns true if and only if the value is \c tbool_true. operator bool(); //! 3-valued logical or. friend tbool operator|| (tbool a, tbool b); //! 3-valued logical and. friend tbool operator&& (tbool a, tbool b); //! 3-valued logical not. friend tbool operator! (tbool a); //! Printing. friend std::ostream& operator<<(std::ostream& os, tbool x); }; /* =============== */ /* exceptions */ /* =============== */ //! Exception raised when a timeout occurs. class timeout : public std::logic_error { public: /*! \arg \c x name of function in which the timeout occurred. */ timeout(const std::string& x) : logic_error(x) {} }; //! Exception raised when a function is not implemented. class not_implemented : public std::logic_error { public: /*! \arg \c x name of unimplemented function. */ not_implemented(const std::string& x) : logic_error(x) {} }; class abstract0; class abstract1; /* =============== */ /* manager */ /* =============== */ /*! \brief Library manager (ap_manager_t wrapper). * * A manager is an instance of a numerical abstract domain library. * It has three roles: * - dispatch functions to the correct library (allowing multiple domain libraries to be used in a program), * - store instance-specific configuration options (such as precision/cost ratios) and feed-backs * (such as exactness and best flag), * - store instance-specific scratch space used by algorithms (allowing thread-safe operations without * too much allocation of function-local data). * * The following guidelines should be followed: * - a manager instance is required to create and manipulate abstract0 elements, * - an abstract0 element can be manipulated using any manager compatible with the one it * was created with (that is, a manager for the same library, created using the same * parameter values, if any), * - two threads should always operate on distinct arguments, and using distinct managers * (if they operate concurrently). * * The manager class is an abstract base class for all managers. It has no effective * constructor. * Instead, you should use the derived class corresponding to the numerical domain library you * wish to use. * * Managers are reference-counted. * In particular, copying simply increment the reference counter and does not create an * independent manager with its own scratch space. Thus, a manager and its copy cannot be used by * concurrent threads. */ class manager : public use_malloc { protected: ap_manager_t* m; //!< Pointer managed by APRON. //! Internal use only (by subclasses). Initialise from a ap_manager_t* and take ownership (no copy). manager(ap_manager_t* m); friend class abstract0; friend class abstract1; public: //! Internal use only. Translates APRON exceptions to C++ ones. static void raise(ap_manager_t* m, const char* msg, ap_abstract0_t* a = NULL); //! Internal use only. Translates APRON exceptions to C++ ones. static void raise(ap_manager_t* m, const char* msg, ap_abstract1_t a); //! Internal use only. Translates APRON exceptions to C++ ones. void raise(const char* msg, ap_abstract0_t* a = NULL); //! Internal use only. Translates APRON exceptions to C++ ones. void raise(const char* msg, ap_abstract1_t a); //! Internal use only. Whether APRON has raised an exception. bool exception_raised(); /** @name Constructor */ //@{ /*! Increments the reference counter. * * \warning After the assignment, x and the new manager share the same scratch space, and thus, * cannot be used by concurrent threads. */ manager(const manager& x); //@} /** @name Destructor */ //@{ //! Decrements the reference counter and, when reaching 0, frees the manager. virtual ~manager(); //@} /** @name Assignment */ //@{ /*! \brief Assignment (actually performs some reference counter management). * * \warning After the assignment, x and *this share the same scratch space, and thus, * cannot be used by concurrent threads. */ manager& operator= (const manager& x); //@} /** @name Accesses */ //@{ //! Returns the name of the library the manager comes from. std::string get_library() const; //! Returns the version name of the library the manager comes from. std::string get_version() const; /*! \brief Returns a (modifiable) reference to the options associated to some abstract function. * * \throw std::out_of_range if funid is no between \c AP_FUNID_COPY and \c AP_FUNID_CLOSURE (inclusive). */ ap_funopt_t& get_funopt(ap_funid_t funid); /*! \brief Returns a (modifiable) reference to the user's preferred scalar type. * * \return the scalar type can be either \c AP_SCALAR_DOUBLE, \c AP_SCALAR_MPQ, or \c AP_SCALAR_MPFR. */ ap_scalar_discr_t& get_scalar_discr(); //! Returns the 'is exact' flag associated to the last computed abstract function. bool get_flag_exact(); //! Returns the 'is best' flag associated to the last computed abstract function. bool get_flag_best(); //@} /** @name Initialisation */ //@{ /*! \brief Sets the FPU rounding-mode towards +oo. * * This is needed to ensure the soundness of all double-manipulating functions in APRON * (coefficients or intervals with double bounds, floating-point abstract domains, etc.) * * The FPU rounding-mode change is global. * It affects all managers (already created or yet to be created) as well as all other floating-point * computations in the program. * * \throw std::runtime_error if the APRON was not able to set the rounding-mode. */ static void fpu_init(); //@} /** @name Printing */ //@{ //! Prints the library name and version. friend std::ostream& operator<< (std::ostream& os, const manager& s); //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. ap_manager_t* get_ap_manager_t(); //@} }; #include "apxx_manager_inline.hh" } #endif /* __APXX_MANAGER_HH */ apron-dist-0.9.10/apron/apronxx/apxx_var.hh0000640014525101416610000000766010703144237020546 0ustar bjeannetpopart/* -*- C++ -*- * apxx_var.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_VAR_HH #define __APXX_VAR_HH #include "ap_var.h" namespace apron { /* ================================= */ /* var */ /* ================================= */ /*! \brief Variable name (ap_var_t wrapper). * * A var object designates a variable name, using a void* pointer (i.e., ap_var_t). * Variable names replace dimensions in all level 1 operations. * Variable names can be copied, freed, compared, and converted to string. * The actual implementation of these operators is defined using the global pointer ap_var_operations. * By default, ap_var_operations implements dynamically allocated C-style * NULL-terminated strings. */ class var { protected: ap_var_t v; //! Variable name. public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ //! Makes a variable name from a pointer (copied with ap_var_operations->copy). var(const void* x); //! Makes a variable name from a string (copied with ap_var_operations->copy). var(const std::string& x); //! Copies the variable name (calls ap_var_operations->copy). var(const var& x); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ //! Frees the variable name (calls ap_var_operations->free). ~var(); //@} /* assignments */ /* =========== */ /** @name Assignments */ //@{ //! Assigns the variable name (calls ap_var_operations->copy, ->free). var& operator=(const var& x); //! Assigns the variable name (calls ap_var_operations->copy, ->free). var& operator=(const std::string& x); //! Assigns the variable name (calls ap_var_operations->copy, ->free). var& operator=(const void* x); //@} /* conversions */ /* =========== */ /** @name Conversions */ //@{ /*! \brief Converts to a C string (calls ap_var_operations->to_string). * * The C string should be freed with malloc by the caller. */ operator char*() const; //! \brief Converts to a C++ string (calls ap_var_operations->to_string). operator std::string() const; //@} /* comparisons */ /* =========== */ /** @name Comparisons */ //@{ //! \brief Compares two variable names (calls ap_var_operations->to_compare). friend int compare(const var& x, const var& y); //! \brief Compares two variables names (calls ap_var_operations->to_compare). friend bool operator==(const var& x, const var& y); //! \brief Compares two variable names (calls ap_var_operations->to_compare). friend bool operator!=(const var& x, const var& y); //! \brief Compares two variable names (calls ap_var_operations->to_compare). friend bool operator>=(const var& x, const var& y); //! \brief Compares two variable names (calls ap_var_operations->to_compare). friend bool operator<=(const var& x, const var& y); //! \brief Compares two variable names (calls ap_var_operations->to_compare). friend bool operator>(const var& x, const var& y); //! \brief Compares two variable names (calls ap_var_operations->to_compare). friend bool operator<(const var& x, const var& y); //@} /* print */ /* ===== */ /** @name Printing */ //@{ //! Printing. friend std::ostream& operator<< (std::ostream& os, const var& s); //! Prints to a C stream. void print(FILE* stream=stdout) const; //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! \brief Returns a reference to the APRON object wrapped (no copy). const ap_var_t& get_ap_var_t() const; //! \brief Returns a (modifiable) reference to the APRON object wrapped (no copy). ap_var_t& get_ap_var_t(); //@} }; #include "apxx_var_inline.hh" } #endif /* __APXX_VAR_HH */ apron-dist-0.9.10/apron/apronxx/apxx_box.hh0000640014525101416610000000121110703144237020530 0ustar bjeannetpopart/* -*- C++ -*- * apxx_box.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_BOX_HH #define __APXX_BOX_HH #include "apxx_manager.hh" #include "box.h" namespace apron { //! Manager factory for the Box interval-domain library. class box_manager : public manager { public: //! \brief Creates a new manager. box_manager(); //! Copy operator. manager& operator=(const manager&); }; #include "apxx_box_inline.hh" } #endif /* __APXX_BOX_HH */ apron-dist-0.9.10/apron/apronxx/apronxx.hh0000640014525101416610000000107110656607364020417 0ustar bjeannetpopart/* -*- C++ -*- * apronxx.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APRONXX_HH #define __APRONXX_HH #include "apxx_scalar.hh" #include "apxx_interval.hh" #include "apxx_coeff.hh" #include "apxx_dimension.hh" #include "apxx_manager.hh" #include "apxx_expr0.hh" #include "apxx_abstract0.hh" #include "apxx_expr1.hh" #include "apxx_abstract1.hh" #endif /* __APRONXX_HH */ apron-dist-0.9.10/apron/apronxx/apxx_abstract1.hh0000640014525101416610000011016310723557216021642 0ustar bjeannetpopart/* -*- C++ -*- * apxx_abstract1.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_ABSTRACT1_HH #define __APXX_ABSTRACT1_HH #include "ap_abstract1.h" #include "apxx_abstract0.hh" #include "apxx_linexpr1.hh" #include "apxx_lincons1.hh" #include "apxx_generator1.hh" namespace apron { /* ================================= */ /* abstract1 */ /* ================================= */ /*! \brief Level 1 abstract value (ap_abstract1_t wrapper). * * Level 1 version of abstract values. * Variable names (var) are used in place of dimensions (ap_dim_t). * Internally, an abstract1 wraps together an abstract0 (memory managed) and an environment * (holding a reference count). */ class abstract1 : public use_malloc { protected: ap_abstract1_t a; //!< Structure managed by APRON. //! NULL abstract element, to be used only as default argument in assign and substitute. static const abstract1 null; //! Internal use only. Shallow copy of structure. abstract1(ap_abstract1_t x); friend class manager; public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ //! Creates an abstract element representing the whole space. abstract1(manager &m, const environment& e, top x); //! Creates an abstract element representing the empty set. abstract1(manager &m, const environment& e, bottom x); //! Creates a (deep) copy of the abstract element. abstract1(manager &m, const abstract1& t); //! Creates a (deep) copy of the abstract element and associates an environment (reference count incremented). abstract1(manager &m, const environment& e, const abstract0& t); /*! \brief Creates an abstract element from a box. * * x[i] is the bound for the variable v[i]. * Variables not in v have unconstrained bounds. */ abstract1(manager &m, const environment& e, const var v[], const interval_array& x); /*! \brief Creates an abstract element from a box. * * x[i] is the bound for all the variables in v. * Variables not in v have unconstrained bounds. */ abstract1(manager &m, const environment& e, const std::vector& v, const interval_array& x); //! Creates an abstract element from a conjunction of linear constraints. abstract1(manager &m, const lincons1_array& x); //! Creates an abstract element from a conjunction of arbitrary constraints. abstract1(manager &m, const tcons1_array& x); /*! \brief Creates a (deep) copy of the abstract element. * * Implicitly uses the manager used to create *this. */ abstract1(const abstract1& t); //@} /* destructor */ /* ========== */ /** @name Destructors */ //@{ /*! \brief Destroys the abstract element. * * Implicitly uses the manager used to create *this. */ ~abstract1(); /*! \brief Destroys the abstract element using the given manager. * * The abstract element cannot be used after being freed. * However, the standard destructor can be safely be called (resulting in a no-op). */ void free(manager& m); //@} /* assignments */ /* =========== */ /** @name Copies and conversions to abstract elements */ //@{ /*! \brief Assigns a copy of t to *this. * * Implicitly uses the manager used to create *this. */ abstract1& operator=(const abstract1& t); /*! \brief Assigns the full space to *this. * * Implicitly uses the manager used to create *this. */ abstract1& operator=(top t); /*! \brief Assigns the empty set to *this. * * Implicitly uses the manager used to create *this. * Does not change the environment. */ abstract1& operator=(bottom t); /*! \brief Assigns a box to *this. * * Implicitly uses the manager used to create *this. * Does not change the environment. * * \throw std::invalid_argument if the array has insufficient size. */ abstract1& operator=(const interval_array& x); /*! \brief Assigns a conjunction of linear constraints to *this. * * Implicitly uses the manager used to create *this. * Does not change the environment. */ abstract1& operator=(const lincons1_array& x); /*! \brief Assigns a conjunction of arbitrary constraints to *this. * * Implicitly uses the manager used to create *this. */ abstract1& operator=(const tcons1_array& x); /*! \brief Replaces *this with a copy of x. * * \return a reference to *this. */ abstract1& set(manager& m, const abstract1& x); /*! \brief Replaces *this with the full space. * * Does not change the environment. * * \return a reference to *this. */ abstract1& set(manager& m, top t); /*! \brief Replaces *this with the full space. * * \return a reference to *this. */ abstract1& set(manager& m, const environment& e, top t); /*! \brief Replaces *this with the empty set. * * Does not change the environment. * * \return a reference to *this. */ abstract1& set(manager& m, bottom t); /*! \brief Replaces *this with the empty set. * * \return a reference to *this. */ abstract1& set(manager& m, const environment& e, bottom t); /*! \brief Replaces *this with a box. * * Does not change the environment. * * \return a reference to *this. */ abstract1& set(manager& m, const interval_array& x); /*! \brief Replaces *this with a box. * * \return a reference to *this. */ abstract1& set(manager &m, const environment& e, const var v[], const interval_array& x); /*! \brief Replaces *this with a box. * * \return a reference to *this. */ abstract1& set(manager &m, const environment& e, const std::vector& v, const interval_array& x); /*! \brief Replaces *this with a conjunction of linear constraints. * * \return a reference to *this. */ abstract1& set(manager& m, const lincons1_array& x); /*! \brief Replaces *this with a conjunction of arbitrary constraints. * * \return a reference to *this. */ abstract1& set(manager& m, const tcons1_array& x); //@} /* representation */ /* ============== */ /** @name Control of internal representation */ //@{ /*! \brief Minimizes the size of the representation, to save memory. * * \return a reference to *this. */ abstract1& minimize(manager& m); /*! \brief Puts the abstract element in canonical form (if such a notion exists). * * \return a reference to *this. */ abstract1& canonicalize(manager& m); /*! \brief Simplifies the abstract element, potentially loosing precision. * * \return a reference to *this. */ abstract1& approximate(manager& m, int algorithm); //@} /* printing */ /* ======== */ /** @name Printing */ //@{ //! Pretty-printing to a C stream. void print(manager& m, FILE* stream=stdout) const; //! Pretty-printing the difference between x and y to a C stream. friend void printdiff(manager& m, const abstract1& x, const abstract1& y, FILE* stream=stdout); //! Raw printing to a C stream (mainly for debug purposes). void dump(manager& m, FILE* stream=stdout) const; //! Prints in constraint form. friend std::ostream& operator<< (std::ostream& os, const abstract1& s); //@} /* serialisation */ /* ============= */ /** @name Serialisation */ //@{ /*! \brief Serializes an abstract element. * * The string can be safely stored to disk and reloaded later or transmitted across a network. * The format is library-specific but is generally a machine-readable byte-stream. * * \return a newly allocated string that the caller should delete it after use. */ std::string* serialize(manager& m) const; /*! \brief Reconstruct an abstract element form a serialized byte-stream and put it into dst. * * The managers used to serialized and deserialize need not be the same, but they must * have been created using the same library and with the same arguments. * * \arg \c eaten, if not NULL, will be set to the actual number of bytes consumed from the * string. * \return a reference to dst. */ friend abstract1& deserialize(manager& m, abstract1& dst, const std::string& s, size_t* eaten = NULL); //@} /* access */ /* ====== */ /** @name Access */ //@{ //! Returns the manager the abstract element was created with (with reference count incremented). manager get_manager() const; //! Returns the environment of the abstract element (with reference count incremented). environment get_environment() const; //! Returns a (modifiable) reference to the underlying abstract0. abstract0& get_abstract0(); //! Returns a reference to the underlying abstract0. const abstract0& get_abstract0() const; /*! \brief Returns the (abstract) size of the abstract element. * * The unit in which size is computed is library-specific. * It is guaranteed to be the same as the unit for the \c max_object_size field of * the ap_funopt_t structure. */ size_t size(manager& m) const; //@} /* predicates */ /* ========== */ /** @name Predicates */ //@{ //! \brief Whether *this represents the empty set. bool is_bottom(manager& m) const; //! Whether *this represents the full space. bool is_top(manager& m) const; //! Whether *this and x represent the same set. bool is_eq(manager& m, const abstract1& x) const; //! Whether *this is included in x (set-wise). bool is_leq(manager& m, const abstract1& x) const; //! Whether all points in *this satisfy a linear constraint. bool sat(manager& m, const lincons1& l) const; //! Whether all points in *this satisfy an arbitrary constraint. bool sat(manager& m, const tcons1& l) const; /*! \brief Whether the component v of all points in *this is included * in the given interval. */ bool sat(manager& m, const var& v, const interval& i) const; //! \brief Whether the points in *this are unbounded in the given variable. bool is_variable_unconstrained(manager& m, const var& v) const; /*! \brief Whether x and y represent the same set. * * The manager for the left argument is used implicitly. */ friend bool operator== (const abstract1& x, const abstract1& y); /*! \brief Whether x and y represent different sets. * * The manager for the left argument is used implicitly. */ friend bool operator!= (const abstract1& x, const abstract1& y); /*! \brief Whether x is included within y (set-wise). * * The manager for the left argument is used implicitly. */ friend bool operator<= (const abstract1& x, const abstract1& y); /*! \brief Whether x contains y (set-wise). * * The manager for the left argument is used implicitly. */ friend bool operator>= (const abstract1& x, const abstract1& y); /*! \brief Whether x strictly contains y (set-wise). * * The manager for the left argument is used implicitly. */ friend bool operator> (const abstract1& x, const abstract1& y); /*! \brief Whether x is strictly included within y (set-wise). * * The manager for the left argument is used implicitly. */ friend bool operator< (const abstract1& x, const abstract1& y); /* Properties */ /* ========== */ /** @name Property extraction */ //@{ //! Returns some bounds for a linear expression evaluated in all points in the abstract element. interval bound(manager& m, const linexpr1& l) const; //! Returns some bounds for an arbitrary expression evaluated in all points in the abstract element. interval bound(manager& m, const texpr1& l) const; //! Returns some bounds for the given variable on all points in the abstract element. interval bound(manager& m, const var& v) const; //! Returns a bounding box for the set represented by the abstract element. interval_array to_box(manager& m) const; /*! \brief Returns a generator representation of (an over-approximation of) the * set represented by the abstract element. */ generator1_array to_generator_array(manager& m) const; /*! \brief Returns a linear constraint representation of (an over-approximation of) the * set represented by the abstract element. */ lincons1_array to_lincons_array(manager& m) const; /*! \brief Returns a constraint representation of (an over-approximation of) the * set represented by the abstract element. */ tcons1_array to_tcons_array(manager& m) const; //@} /* Meet and unification */ /* ==================== */ /** @name Meet and unification */ //@{ /*! \brief Replaces *this with the meet of *this and the abstract element y. * * \return a reference to *this. */ abstract1& meet(manager& m, const abstract1& y); /*! \brief Replaces dst with the meet of x and y. * * \return a reference to dst. */ friend abstract1& meet(manager& m, abstract1& dst, const abstract1& x, const abstract1& y); /*! \brief Replaces *this with the meet of *this and the abstract element y. * * *this and y can have different environment. * They are first embedded into the least common environment before the meet is computed. * * \return a reference to *this. */ abstract1& unify(manager& m, const abstract1& y); /*! \brief Replaces dst with the meet of x and y. * * x and y can have different environment. * They are first embedded into the least common environment before the meet is computed. * * \return a reference to dst. */ friend abstract1& unify(manager& m, abstract1& dst, const abstract1& x, const abstract1& y); /*! \brief Replaces dst with the meet of all abstract elements in x. * * \return a reference to dst. */ friend abstract1& meet(manager& m, abstract1& dst, const std::vector& x); /*! \brief Replaces dst with the meet of all size abstract elements in x. * * \return a reference to dst. */ friend abstract1& meet(manager& m, abstract1& dst, size_t size, const abstract1 * const x[]); /*! \brief Adds some linear constraints to *this (modified in-place). * * \return a reference to *this. */ abstract1& meet(manager& m, const lincons1_array& y); /*! \brief Replaces dst with the meet of x and some linear constraints. * * \return a reference to dst. */ friend abstract1& meet(manager& m, abstract1& dst, const abstract1& x, const lincons1_array& y); /*! \brief Adds some arbitrary constraints to *this (modified in-place). * * \return a reference to *this. */ abstract1& meet(manager& m, const tcons1_array& y); /*! \brief Replaces dst with the meet of x and some arbitrary constraints. * * \return a reference to dst. */ friend abstract1& meet(manager& m, abstract1& dst, const abstract1& x, const tcons1_array& y); /*! \brief Replaces *this with the meet of *this and the abstract element y. * * Implicitly uses the manager used to create *this. * * \return a reference to *this. */ abstract1& operator*=(const abstract1& y); /*! \brief Adds some linear constraints to *this (modified in-place). * * Implicitly uses the manager used to create *this. * * \return a reference to *this. */ abstract1& operator*=(const lincons1_array& y); /*! \brief Adds some arbitrary constraints to *this (modified in-place). * * Implicitly uses the manager used to create *this. * * \return a reference to *this. */ abstract1& operator*=(const tcons1_array& y); //@} /* Join */ /* ==== */ /** @name Join */ //@{ /*! \brief Replaces *this with the join of *this and the abstract element y. * * \return a reference to *this. */ abstract1& join(manager& m, const abstract1& y); /*! \brief Replaces dst with the join of x and y. * * \return a reference to dst. */ friend abstract1& join(manager& m, abstract1& dst, const abstract1& x, const abstract1& y); /*! \brief Replaces dst with the join of all abstract elements in x. * * \return a reference to dst. */ friend abstract1& join(manager& m, abstract1& dst, const std::vector& x); /*! \brief Replaces dst with the join of all size abstract elements in x. * * \return a reference to dst. */ friend abstract1& join(manager& m, abstract1& dst, size_t size, const abstract1 * const x[]); /*! \brief Adds some rays to *this (modified in-place). * * \arg \c y can only contain rays and lines, not vertexes. * * \return a reference to *this. */ abstract1& add_rays(manager& m, const generator1_array& y); /*! \brief Replaces dst with x with some rays added. * * \arg \c y can only contain rays and lines, not vertexes. * * \return a reference to *this. */ friend abstract1& add_rays(manager& m, abstract1& dst, const abstract1& x, const generator1_array& y); /*! \brief Replaces *this with the join of *this and the abstract element y. * * Implicitly uses the manager used to create *this. * * \return a reference to *this. */ abstract1& operator+=(const abstract1& y); /*! \brief Adds some rays to *this (modified in-place). * * Implicitly uses the manager used to create *this. * * \arg \c y can only contain rays and lines, not vertexes. * * \return a reference to *this. */ abstract1& operator+=(const generator1_array& y); //@} /* Assignments */ /* =========== */ /** @name Assignment */ //@{ /*! \brief In-place assignment of linear expression. * * *this is modified in-place to reflect the effect of assigning l to variable v. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. */ abstract1& assign(manager& m, const var& v, const linexpr1& l, const abstract1& inter = null); /*! \brief In-place parallel assignment of linear expressions. * * *this is modified in-place to reflect the effect of assigning l[i] to variable v[i], for * i from 0 to size-1. * Assignments are performed in parallel. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. */ abstract1& assign(manager& m, size_t size, const var v[], const linexpr1 * const l[], const abstract1& inter = null); /*! \brief In-place parallel assignment of linear expressions. * * *this is modified in-place to reflect the effect of assigning l[i] to variable v[i]. * Assignments are performed in parallel. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. * * \throw std::invalid_argument if the vectors have different size. */ abstract1& assign(manager& m, const std::vector& v, const std::vector& l, const abstract1& inter = null); /*! \brief Assignment of linear expression. * * dst is replaced with the effect of assigning l to variable v in src. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. */ friend abstract1& assign(manager& m, abstract1& dst, const abstract1& src, const var& v, const linexpr1& l, const abstract1& inter = null); /*! \brief Parallel assignment of linear expressions. * * dst is replaced with the effect of assigning l[i] to variable v[i] in src, * for i from 0 to size-1. * Assignments are performed in parallel. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. */ friend abstract1& assign(manager& m, abstract1& dst, const abstract1& src, size_t size, const var v[], const linexpr1 * const l[], const abstract1& inter = null); /*! \brief Parallel assignment of linear expressions. * * dst is replaced with the effect of assigning l[i] to variable v[i] in src. * Assignments are performed in parallel. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. * * \throw std::invalid_argument if the vectors have different size. */ friend abstract1& assign(manager& m, abstract1& dst, const abstract1& src, const std::vector& v, const std::vector& l, const abstract1& inter = null); /*! \brief In-place assignment of arbitrary expression. * * *this is modified in-place to reflect the effect of assigning l to variable v. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. */ abstract1& assign(manager& m, const var& v, const texpr1& l, const abstract1& inter = null); /*! \brief In-place parallel assignment of arbitrary expressions. * * *this is modified in-place to reflect the effect of assigning l[i] to variable v[i], for * i from 0 to size-1. * Assignments are performed in parallel. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. */ abstract1& assign(manager& m, size_t size, const var v[], const texpr1 * const l[], const abstract1& inter = null); /*! \brief In-place parallel assignment of arbitrary expressions. * * *this is modified in-place to reflect the effect of assigning l[i] to variable v[i]. * Assignments are performed in parallel. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. * * \throw std::invalid_argument if the vectors have different size. */ abstract1& assign(manager& m, const std::vector& v, const std::vector& l, const abstract1& inter = null); /*! \brief Assignment of arbitrary expression. * * dst is replaced with the effect of assigning l to variable v in src. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. */ friend abstract1& assign(manager& m, abstract1& dst, const abstract1& src, const var& v, const texpr1& l, const abstract1& inter = null); /*! \brief Parallel assignment of arbitrary expressions. * * dst is replaced with the effect of assigning l[i] to variable v[i] in src, * for i from 0 to size-1. * Assignments are performed in parallel. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. */ friend abstract1& assign(manager& m, abstract1& dst, const abstract1& src, size_t size, const var v[], const texpr1 * const l[], const abstract1& inter = null); /*! \brief Parallel assignment of arbitrary expressions. * * dst is replaced with the effect of assigning l[i] to variable v[i] in src. * Assignments are performed in parallel. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. * * \throw std::invalid_argument if the vectors have different size. */ friend abstract1& assign(manager& m, abstract1& dst, const abstract1& src, const std::vector& v, const std::vector& l, const abstract1& inter = null); //@} /* Substitutions */ /* ============== */ /** @name Substitution */ //@{ /*! \brief In-place substitution (backward assignment) of linear expression. * * *this is modified in-place to reflect the effect of substituting l to variable v. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. */ abstract1& substitute(manager& m, const var& v, const linexpr1& l, const abstract1& inter = null); /*! \brief In-place parallel substitution (backward assignment) of linear expressions. * * *this is modified in-place to reflect the effect of substituting l[i] to variable v[i], for * i from 0 to size-1. * Substitutions are performed in parallel. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. */ abstract1& substitute(manager& m, size_t size, const var v[], const linexpr1 * const l[], const abstract1& inter = null); /*! \brief In-place parallel substitution (backward assignment) of linear expressions. * * *this is modified in-place to reflect the effect of substituting l[i] to variable v[i]. * Substitutions are performed in parallel. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. * * \throw std::invalid_argument if the vectors have different size. */ abstract1& substitute(manager& m, const std::vector& v, const std::vector& l, const abstract1& inter = null); /*! \brief Substitution (backward assignment) of linear expression. * * dst is replaced with the effect of substituting l to variable v in src. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. */ friend abstract1& substitute(manager& m, abstract1& dst, const abstract1& src, const var& v, const linexpr1& l, const abstract1& inter = null); /*! \brief Parallel substitution (backward assignment) of linear expressions. * * dst is replaced with the effect of substituting l[i] to variable v[i] in src, * for i from 0 to size-1. * Substitutions are performed in parallel. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. */ friend abstract1& substitute(manager& m, abstract1& dst, const abstract1& src, size_t size, const var v[], const linexpr1 * const l[], const abstract1& inter = null); /*! \brief Parallel substitution (backward assignment) of linear expressions. * * dst is replaced with the effect of substituting l[i] to variable v[i] in src. * Substitutions are performed in parallel. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. * * \throw std::invalid_argument if the vectors have different size. */ friend abstract1& substitute(manager& m, abstract1& dst, const abstract1& src, const std::vector& v, const std::vector& l, const abstract1& inter = null); /*! \brief In-place substitution (backward assignment) of arbitrary expression. * * *this is modified in-place to reflect the effect of substituting l to variable v. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. */ abstract1& substitute(manager& m, const var& v, const texpr1& l, const abstract1& inter = null); /*! \brief In-place parallel substitution (backward assignment) of arbitrary expressions. * * *this is modified in-place to reflect the effect of substituting l[i] to variable v[i], for * i from 0 to size-1. * Substitutions are performed in parallel. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. */ abstract1& substitute(manager& m, size_t size, const var v[], const texpr1 * const l[], const abstract1& inter = null); /*! \brief In-place parallel substitution (backward assignment) of arbitrary expressions. * * *this is modified in-place to reflect the effect of substituting l[i] to variable v[i]. * Substitutions are performed in parallel. * If inter is specified, *this is then intersected with it. * * \return a reference to *this. * * \throw std::invalid_argument if the vectors have different size. */ abstract1& substitute(manager& m, const std::vector& v, const std::vector& l, const abstract1& inter = null); /*! \brief Substitution (backward assignment) of arbitrary expression. * * dst is replaced with the effect of substituting l to variable v in src. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. */ friend abstract1& substitute(manager& m, abstract1& dst, const abstract1& src, const var& v, const texpr1& l, const abstract1& inter = null); /*! \brief Parallel substitution (backward assignment) of arbitrary expressions. * * dst is replaced with the effect of substituting l[i] to variable v[i] in src, * for i from 0 to size-1. * Substitutions are performed in parallel. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. */ friend abstract1& substitute(manager& m, abstract1& dst, const abstract1& src, size_t size, const var v[], const texpr1 * const l[], const abstract1& inter = null); /*! \brief Parallel substitution (backward assignment) of arbitrary expressions. * * dst is replaced with the effect of substituting l[i] to variable v[i] in src. * Substitutions are performed in parallel. * If inter is specified, dst is then intersected with it. * * \return a reference to dst. * * \throw std::invalid_argument if the vectors have different size. */ friend abstract1& substitute(manager& m, abstract1& dst, const abstract1& src, const std::vector& v, const std::vector& l, const abstract1& inter = null); //@} /* Projection */ /* ========== */ /** @name Projection, forget */ //@{ /*! \brief Forgets about the value of variable v in *this. * * \arg \c project whether to reset the variable to 0 (if true), or leave it undefined (if false). * * \return a reference to *this. */ abstract1& forget(manager& m, const var& v, bool project = false); /*! \brief Forgets about the value of variables v[0] to v[size-1] in *this. * * \arg \c project whether to reset the variables to 0 (if true), or it them undefined (if false). * * \return a reference to *this. */ abstract1& forget(manager& m, size_t size, const var v[], bool project = false); /*! \brief Forgets about the value of all the variables in v in *this. * * \arg \c project whether to reset the variables to 0 (if true), or leave them undefined (if false). * * \return a reference to *this. */ abstract1& forget(manager& m, const std::vector& v, bool project = false); /*! \brief Stores in dst the result of forgetting the value of variable v in src. * * \arg \c project if true, resets the variable to 0 (if true). * * \return a reference to dst. */ friend abstract1& forget(manager& m, abstract1& dst, const abstract1& src, const var& v, bool project = false); /*! \brief Stores in dst the result of forgetting the value of variables v[0] to * v[size-1] in src. * * \arg \c project whether to reset the variables to 0 (if true), or leave them undefined (if false). * * \return a reference to dst. */ friend abstract1& forget(manager& m, abstract1& dst, const abstract1& src, size_t size, const var v[], bool project = false); /*! \brief Stores in dst the result of forgetting the value of all the variables in v in src. * * \arg \c project whether to reset the variables to 0 (if true), or leave them undefined (if false). * * \return a reference to dst. */ friend abstract1& forget(manager& m, abstract1& dst, const abstract1& src, const std::vector& v, bool project = false); //@} /* Change of environment */ /* ====================== */ /** @name Change of environment */ //@{ /*! \brief Modifies the environment of *this. * * \arg \c project whether new variables are initialized to 0 (if true), or undefined (if false). * * \return a reference to *this. */ abstract1& change_environment(manager& m, const environment& e, bool project = false); /*! \brief Replaces dst with src and changes its environment. * * \arg \c project whether new variables are initialized to 0 (if true), or undefined (if false). * * \return a reference to dst. */ friend abstract1& change_environment(manager& m, abstract1& dst, const abstract1& src, const environment& e, bool project = false); /*! \brief Removes from *this the variables that are unconstrained. * * \return a reference to *this. */ abstract1& minimize_environment(manager& m); /*! \brief Replaces dst with src and removes the variables that are unconstrained. * * \return a reference to dst. */ friend abstract1& minimize_environment(manager& m, abstract1& dst, const abstract1& src); /*! \brief Renames oldv[i] into newv[i] in *this. * * \return a reference to *this. */ abstract1& rename(manager& m, size_t size, const var oldv[], const var newv[]); /*! \brief Renames oldv[i] into newv[i] in *this. * * \return a reference to *this. */ abstract1& rename(manager& m, const std::vector& oldv, const std::vector& newv); /*! \brief Replaces dst with src and renames oldv[i] into newv[i]. * * \return a reference to dst. */ friend abstract1& rename(manager& m, abstract1& dst, const abstract1& src, size_t size, const var oldv[], const var newv[]); /*! \brief Replaces dst with src and renames oldv[i] into newv[i]. * * \return a reference to dst. */ friend abstract1& rename(manager& m, abstract1& dst, const abstract1& src, const std::vector& oldv, const std::vector& newv); //@} /* Expansion and folding */ /* ===================== */ /** @name Expansion and folding */ //@{ /*! \brief Duplicates variable v into size copies in *this (modified in-place). * * New variables are named vv[0] to vv[size-1]. * * \return a reference to *this. */ abstract1& expand(manager& m, const var& v, size_t size, const var vv[]); /*! \brief Duplicates variable v in *this (modified in-place). * * The i-th new variable is named vv[i]. * * \return a reference to *this. */ abstract1& expand(manager& m, const var& v, const std::vector& vv); /*! \brief Replaces dst with a copy of src and duplicates variable v into size copies. * * New variables are named vv[0] to vv[size-1]. * * \return a reference to dst. */ friend abstract1& expand(manager& m, abstract1& dst, const abstract1& src, const var& v, size_t size, const var vv[]); /*! \brief Replaces dst with a copy of src and duplicates variable v. * * The i-th new variables is named vv[i]. * * \return a reference to dst. */ friend abstract1& expand(manager& m, abstract1& dst, const abstract1& src, const var& v, const std::vector& vv); /*! \brief Folds variables v[0] to v[size-1] in *this (modified in-place). * * After folding, only v[0] is kept and other variables are removed. * * \return a reference to *this. */ abstract1& fold(manager& m, size_t size, const var v[]); /*! \brief Folds all variables v in *this (modified in-place). * * After folding, only v[0] is kept and other variables are removed. * * \return a reference to *this. */ abstract1& fold(manager& m, const std::vector& v); /*! \brief Replaces dst with a copy of src and folds variables v[0] to v[size-1]. * * After folding, only v[0] is kept and other variables are removed. * * \return a reference to dst. */ friend abstract1& fold(manager& m, abstract1& dst, const abstract1& src, size_t size, const var v[]); /*! \brief Replaces dst with a copy of src and folds all variables in v. * * After folding, only v[0] is kept and other variables are removed. * * \return a reference to dst. */ friend abstract1& fold(manager& m, abstract1& dst, const abstract1& src, const std::vector& v); //@} /* Widenings */ /* ========= */ /** @name Widening */ //@{ /*! \brief Stores in dst the result of x widened with y. * * \warning y must be a superset of x. * * \return a reference to dst. */ friend abstract1& widening(manager& m, abstract1& dst, const abstract1& x, const abstract1& y); /*! \brief Stores in dst the result of x widened with y, using some widening thresholds. * * \warning y must be a superset of x. * * \return a reference to dst. */ friend abstract1& widening(manager& m, abstract1& dst, const abstract1& x, const abstract1& y, const lincons1_array& l); //@} /* Closure */ /* ======= */ /** @name Closure */ //@{ /*! \brief Replaces *this with its topological closure. * * \return a reference to *this. */ abstract1& closure(manager& m); /*! \brief Stores in dst the topological closure of src. * * \return a reference to dst. */ friend abstract1& closure(manager& m, abstract1& dst, const abstract1& src); //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. ap_abstract1_t* get_ap_abstract1_t(); //! Returns a pointer to the internal APRON object stored in *this. const ap_abstract1_t* get_ap_abstract1_t() const; //@} }; #include "apxx_abstract1_inline.hh" } #endif /* __APXX_ABSTRACT1_HH */ apron-dist-0.9.10/apron/apronxx/apxx_texpr1_inline.hh0000640014525101416610000006223311006063143022525 0ustar bjeannetpopart/* -*- C++ -*- * apxx_texpr1_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ inline void texpr1::init_from(ap_environment_t* e, ap_texpr0_t* x) { l.env = e; l.texpr0 = x; } inline void texpr1::init_from(ap_texpr1_t* x) { l = *x; free(x); } inline texpr1::texpr1(ap_texpr1_t* x) { init_from(x); } inline texpr1::texpr1(const texpr1& x) { init_from(ap_texpr1_copy(const_cast(&x.l))); } inline texpr1::texpr1(const builder& x) { init_from(ap_texpr1_copy(const_cast(x.get_ap_texpr1_t()))); } inline texpr1::texpr1(const const_iterator& x) { init_from(ap_texpr1_copy(const_cast(x.get_ap_texpr1_t()))); } inline texpr1::texpr1(const environment& e, const var& v) { ap_texpr1_t* ll = ap_texpr1_var(const_cast(e.get_ap_environment_t()), v.get_ap_var_t()); if (!ll) throw(std::invalid_argument("apron::texpr1::texpr1(const environment&, const var&) variable not in environment")); init_from(ll); } inline texpr1::texpr1(const environment& e, const texpr0& x) { init_from(ap_environment_copy(const_cast(e.get_ap_environment_t())), ap_texpr0_copy(const_cast(x.get_ap_texpr0_t()))); } inline texpr1::texpr1(const environment& e, const texpr0::const_iterator& x) { init_from(ap_environment_copy(const_cast(e.get_ap_environment_t())), ap_texpr0_copy(const_cast(x.get_ap_texpr0_t()))); } inline texpr1::texpr1(const environment& e, const texpr0::builder& c) { init_from(ap_environment_copy(const_cast(e.get_ap_environment_t())), ap_texpr0_copy(const_cast(c.get_ap_texpr0_t()))); } inline texpr1::texpr1(const linexpr1& l) { init_from(ap_texpr1_from_linexpr1(const_cast(l.get_ap_linexpr1_t()))); } inline texpr1::texpr1(const texpr1& x, const environment& e) { ap_texpr1_t* ll = ap_texpr1_extend_environment(const_cast(&x.l), const_cast(e.get_ap_environment_t())); if (!ll) throw std::invalid_argument("apron::texpr1::texpr1(const texpr1&, const environment&) not a super-environment"); init_from(ll); } inline texpr1::texpr1(const texpr1& x, const var& src, const texpr1& dst) { ap_texpr1_t* ll = ap_texpr1_substitute(const_cast(&x.l), const_cast(src.get_ap_var_t()), const_cast(&dst.l)); if (!ll) throw std::invalid_argument("apron::texpr1::texpr1(const texpr1&, const var&, const texpr1&)"); init_from(ll); } /* destructor */ /* ========== */ inline texpr1::~texpr1() { ap_environment_free(l.env); ap_texpr0_free(l.texpr0); } /* assignment */ /* ========== */ inline texpr1& texpr1::operator=(const texpr1& x) { ap_texpr1_t* c = ap_texpr1_copy(const_cast(&x.l)); ap_environment_free(l.env); ap_texpr0_free(l.texpr0); init_from(c); return *this; } inline texpr1& texpr1::operator=(const builder& x) { ap_texpr1_t* c = ap_texpr1_copy(const_cast(x.get_ap_texpr1_t())); ap_environment_free(l.env); ap_texpr0_free(l.texpr0); init_from(c); return *this; } inline texpr1& texpr1::operator=(const const_iterator& x) { ap_texpr1_t* c = ap_texpr1_copy(const_cast(x.get_ap_texpr1_t())); ap_environment_free(l.env); ap_texpr0_free(l.texpr0); init_from(c); return *this; } inline texpr1& texpr1::operator= (const linexpr1& x) { ap_environment_free(l.env); ap_texpr0_free(l.texpr0); init_from(ap_texpr1_from_linexpr1(const_cast(x.get_ap_linexpr1_t()))); return *this; } /* print */ /* ===== */ extern void apxx_texpr0_env_ostream(std::ostream& os, ap_environment_t* env, ap_texpr0_t* a); inline std::ostream& operator<< (std::ostream& os, const texpr1& s) { return os << s.root(); } inline void texpr1::print(FILE* stream) const { root().print(stream); } /* dimension operations */ /* ==================== */ inline void texpr1::extend_environment(const environment& e) { bool r = ap_texpr1_extend_environment_with(&l, const_cast(e.get_ap_environment_t())); if (r) throw std::invalid_argument("apron::texpr1::extend_environment(const environment&) not a super-environment"); } /* access */ /* ====== */ inline environment texpr1::get_environment() const { return root().get_environment(); } inline texpr0::const_iterator texpr1::get_texpr0() const { return root().get_texpr0(); } inline texpr0::iterator texpr1::get_texpr0() { return root().get_texpr0(); } inline bool texpr1::equal(const texpr1& x) const { return root().equal(x); } inline size_t texpr1::depth() const { return root().depth(); } inline bool texpr1::is_zero() const { return root().is_zero(); } inline size_t texpr1::size() const { return root().size(); } inline bool texpr1::has_var(const var& v) const { return root().has_var(v); } inline bool texpr1::is_interval_cst() const { return root().is_interval_cst(); } inline bool texpr1::is_interval_linear() const { return root().is_interval_linear(); } inline bool texpr1::is_interval_polynomial() const { return root().is_interval_polynomial(); } inline bool texpr1::is_interval_polyfrac() const { return root().is_interval_polyfrac(); } inline bool texpr1::is_scalar() const { return root().is_scalar(); } /* operations */ /* ========== */ inline void texpr1::substitute(const var& src, const texpr1& dst) { bool r = ap_texpr1_substitute_with(const_cast(&l), const_cast(src.get_ap_var_t()), const_cast(&dst.l)); if (r) throw std::invalid_argument("apron::texpr1::substitute(const var&, const texpr1&)"); } /* C-level compatibility */ /* ===================== */ inline ap_texpr1_t* texpr1::get_ap_texpr1_t() { return &l; } inline const ap_texpr1_t* texpr1::get_ap_texpr1_t() const { return &l; } /* ========= */ /* iterators */ /* ========= */ /* constructors */ /* ============ */ inline texpr1::const_iterator texpr1::root() const { return const_iterator(const_cast(&l)); } inline texpr1::const_iterator::const_iterator(ap_texpr0_t* ll, ap_environment_t* ee) { l.texpr0 = ll; l.env = ee; } inline texpr1::const_iterator::const_iterator(ap_texpr1_t* l) : l(*l) {} inline texpr1::const_iterator::const_iterator(const texpr1& e) : l(*e.get_ap_texpr1_t()) {} inline texpr1::const_iterator::const_iterator(const const_iterator& i) : l(i.l) {} /* access */ /* ====== */ inline environment texpr1::const_iterator::get_environment() const { return ap_environment_copy(l.env); } inline texpr0::const_iterator texpr1::const_iterator::get_texpr0() const { return l.texpr0; } inline ap_texpr_discr_t texpr1::const_iterator::get_discr() const { return l.texpr0->discr; } inline const coeff& texpr1::const_iterator::get_coeff() const { if (l.texpr0->discr!=AP_TEXPR_CST) throw(bad_discriminant("apron::texpr1::const_iterator::get_coeff()")); return reinterpret_cast(l.texpr0->val.cst); } inline const var& texpr1::const_iterator::get_var() const { if (l.texpr0->discr!=AP_TEXPR_DIM) throw(bad_discriminant("apron::texpr1::const_iterator::get_var()")); return *reinterpret_cast(&l.env->var_of_dim[l.texpr0->val.dim]); } inline ap_dim_t texpr1::const_iterator::get_dim() const { if (l.texpr0->discr!=AP_TEXPR_DIM) throw(bad_discriminant("apron::texpr1::const_iterator::get_dim()")); return l.texpr0->val.dim; } inline ap_texpr_op_t texpr1::const_iterator::get_op() const { if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::const_iterator::get_op()")); return l.texpr0->val.node->op; } inline ap_texpr_rtype_t texpr1::const_iterator::get_rtype() const { if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::const_iterator::get_type()")); return l.texpr0->val.node->type; } inline ap_texpr_rdir_t texpr1::const_iterator::get_rdir() const { if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::const_iterator::get_dir()")); return l.texpr0->val.node->dir; } /* traversal */ /* ========= */ inline texpr1::const_iterator& texpr1::const_iterator::operator=(const const_iterator& i) { l = i.l; return *this; } inline texpr1::const_iterator texpr1::const_iterator::child() const { if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::const_iterator::child()")); if (!l.texpr0->val.node->exprA) throw(std::out_of_range("apron::texpr1::const_iterator::child()")); return const_iterator(l.texpr0->val.node->exprA, l.env); } inline texpr1::const_iterator texpr1::const_iterator::left() const { if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::const_iterator::left()")); if (!l.texpr0->val.node->exprA) throw(std::out_of_range("apron::texpr1::const_iterator::left()")); return const_iterator(l.texpr0->val.node->exprA, l.env); } inline texpr1::const_iterator texpr1::const_iterator::right() const { if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::const_iterator::right()")); if (!l.texpr0->val.node->exprB) throw(std::out_of_range("apron::texpr1::const_iterator::right()")); return const_iterator(l.texpr0->val.node->exprB, l.env); } /* print */ /* ===== */ inline std::ostream& operator<< (std::ostream& os, const texpr1::const_iterator& s) { ap_texpr1_t* x = const_cast(s.get_ap_texpr1_t()); apxx_texpr0_env_ostream(os, x->env, x->texpr0); return os; } inline void texpr1::const_iterator::print(FILE* stream) const { ap_texpr1_fprint(stream, const_cast(&l)); } /* tests, size */ /* =========== */ inline bool texpr1::const_iterator::equal(const texpr1& x) const { return ap_texpr1_equal(const_cast(&l), const_cast(x.get_ap_texpr1_t())); } inline size_t texpr1::const_iterator::depth() const { return ap_texpr0_depth(const_cast(l.texpr0)); } inline bool texpr1::const_iterator::is_zero() const { return l.texpr0->discr==AP_TEXPR_CST && ap_coeff_zero(&const_cast(l.texpr0)->val.cst); } inline size_t texpr1::const_iterator::size() const { return ap_texpr0_size(const_cast(l.texpr0)); } inline bool texpr1::const_iterator::has_var(const var& v) const { return ap_texpr1_has_var(const_cast(&l), const_cast(v.get_ap_var_t())); } inline bool texpr1::const_iterator::is_interval_cst() const { return ap_texpr1_is_interval_cst(const_cast(&l)); } inline bool texpr1::const_iterator::is_interval_linear() const { return ap_texpr1_is_interval_linear(const_cast(&l)); } inline bool texpr1::const_iterator::is_interval_polynomial() const { return ap_texpr1_is_interval_polynomial(const_cast(&l)); } inline bool texpr1::const_iterator::is_interval_polyfrac() const { return ap_texpr1_is_interval_polyfrac(const_cast(&l)); } inline bool texpr1::const_iterator::is_scalar() const { return ap_texpr1_is_scalar(const_cast(&l)); } /* C-level compatibility */ /* ===================== */ inline ap_texpr1_t* texpr1::const_iterator::get_ap_texpr1_t() { return &l; } inline const ap_texpr1_t* texpr1::const_iterator::get_ap_texpr1_t() const { return &l; } /* constructors */ /* ============ */ inline texpr1::iterator texpr1::root() { return iterator(&l); } inline texpr1::iterator::iterator(ap_texpr0_t* l, ap_environment_t* e) : texpr1::const_iterator(l,e) {} inline texpr1::iterator::iterator(ap_texpr1_t* l) : texpr1::const_iterator(l) {} inline texpr1::iterator::iterator(texpr1& e) : texpr1::const_iterator(e.get_ap_texpr1_t()) {} inline texpr1::iterator::iterator(const iterator& i) : texpr1::const_iterator(i) {} /* substitution */ /* ============ */ inline texpr1::iterator& texpr1::iterator::operator= (const builder& c) { ap_texpr0_t* cc = ap_texpr0_copy(c.get_ap_texpr1_t()->texpr0); ap_texpr0_clear(l.texpr0); *l.texpr0 = *cc; free(cc); return *this; } /* access */ /* ====== */ inline texpr0::iterator texpr1::iterator::get_texpr0() const { return l.texpr0; } inline coeff& texpr1::iterator::get_coeff() const { if (l.texpr0->discr!=AP_TEXPR_CST) throw(bad_discriminant("apron::texpr1::iterator::get_coeff()")); return reinterpret_cast(l.texpr0->val.cst); } inline void texpr1::iterator::set_var(const var& v) const { if (l.texpr0->discr!=AP_TEXPR_DIM) throw(bad_discriminant("apron::texpr1::iterator::set_var(const var&)")); ap_dim_t d = ap_environment_dim_of_var(l.env, v.get_ap_var_t()); if (d==AP_DIM_MAX) throw(std::invalid_argument("apron::texpr1::iterator::set_var(const var&) variable not in environment")); l.texpr0->val.dim = d; } inline ap_dim_t& texpr1::iterator::get_dim() const { if (l.texpr0->discr!=AP_TEXPR_DIM) throw(bad_discriminant("apron::texpr1::iterator::get_dim()")); return l.texpr0->val.dim; } inline ap_texpr_op_t& texpr1::iterator::get_op() const { if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::iterator::get_op()")); return l.texpr0->val.node->op; } inline ap_texpr_rtype_t& texpr1::iterator::get_rtype() const { if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::iterator::get_type()")); return l.texpr0->val.node->type; } inline ap_texpr_rdir_t& texpr1::iterator::get_rdir() const { if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::iterator::get_dir()")); return l.texpr0->val.node->dir; } /* traversal */ /* ========= */ inline texpr1::iterator& texpr1::iterator::operator=(const iterator& i) { l = i.l; return *this; } inline texpr1::iterator texpr1::iterator::child() const { if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::iterator::child()")); if (!l.texpr0->val.node->exprA) throw(std::out_of_range("apron::texpr1::iterator::child()")); return iterator(l.texpr0->val.node->exprA, l.env); } inline texpr1::iterator texpr1::iterator::left() const { if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::iterator::left()")); if (!l.texpr0->val.node->exprA) throw(std::out_of_range("apron::texpr1::iterator::left()")); return iterator(l.texpr0->val.node->exprA, l.env); } inline texpr1::iterator texpr1::iterator::right() const { if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::iterator::right()")); if (!l.texpr0->val.node->exprB) throw(std::out_of_range("apron::texpr1::iterator::right()")); return iterator(l.texpr0->val.node->exprB, l.env); } /* C-level compatibility */ /* ===================== */ inline ap_texpr1_t* texpr1::iterator::get_ap_texpr1_t() { return &l; } inline const ap_texpr1_t* texpr1::iterator::get_ap_texpr1_t() const { return &l; } /* ================================= */ /* builder */ /* ================================= */ inline void texpr1::builder::init_from(ap_texpr1_t* x) { l.env = x->env; switch (x->texpr0->discr) { case AP_TEXPR_DIM: l.texpr0 = ap_texpr0_dim(x->texpr0->val.dim); break; case AP_TEXPR_CST: l.texpr0 = ap_texpr0_cst(const_cast(&x->texpr0->val.cst)); break; case AP_TEXPR_NODE: l.texpr0 = ap_texpr0_node(x->texpr0->val.node->op, x->texpr0->val.node->type, x->texpr0->val.node->dir, x->texpr0->val.node->exprA, x->texpr0->val.node->exprB); break; default: throw std::invalid_argument("apron::texpr1::builder::init_from(ap_texpr1_t*) invalid discriminant"); } } inline void texpr1::builder::init_from(ap_environment_t* e, ap_texpr0_t* x) { ap_texpr1_t ll; ll.texpr0 = x; ll.env = e; init_from(&ll); } inline texpr1::builder::builder(ap_texpr1_t* x) { init_from(x); } inline texpr1::builder::builder(const builder& x) { init_from(const_cast(&x.l)); } inline texpr1::builder::builder(const const_iterator& x) { init_from(const_cast(x.get_ap_texpr1_t())); } inline texpr1::builder::builder(const texpr1& x) { init_from(const_cast(x.get_ap_texpr1_t())); } inline texpr1::builder::builder(const environment& e, const texpr0::builder& b) { init_from(const_cast(e.get_ap_environment_t()), const_cast(b.get_ap_texpr0_t())); } inline texpr1::builder::builder(const environment& e, const texpr0::const_iterator& b) { init_from(const_cast(e.get_ap_environment_t()), const_cast(b.get_ap_texpr0_t())); } inline texpr1::builder::builder(const environment& e, const texpr0& b) { init_from(const_cast(e.get_ap_environment_t()), const_cast(b.get_ap_texpr0_t())); } inline texpr1::builder::builder(const environment& e, const coeff& x) { l.env = const_cast(e.get_ap_environment_t()); l.texpr0 = ap_texpr0_cst(const_cast(x.get_ap_coeff_t())); } inline texpr1::builder::builder(const environment& e, const scalar& x) { l.env = const_cast(e.get_ap_environment_t()); l.texpr0 = ap_texpr0_cst_scalar(const_cast(x.get_ap_scalar_t())); } inline texpr1::builder::builder(const environment& e, const mpq_class& x) { l.env = const_cast(e.get_ap_environment_t()); l.texpr0 = ap_texpr0_cst_scalar_mpq(const_cast(x).get_mpq_t()); } inline texpr1::builder::builder(const environment& e, mpfr_t x) { l.env = const_cast(e.get_ap_environment_t()); l.texpr0 = ap_texpr0_cst_scalar_mpfr(x); } inline texpr1::builder::builder(const environment& e, int x) { l.env = const_cast(e.get_ap_environment_t()); l.texpr0 = ap_texpr0_cst_scalar_int(x); } inline texpr1::builder::builder(const environment& e, long x) { l.env = const_cast(e.get_ap_environment_t()); l.texpr0 = ap_texpr0_cst_scalar_int(x); } inline texpr1::builder::builder(const environment& e, double x) { l.env = const_cast(e.get_ap_environment_t()); l.texpr0 = ap_texpr0_cst_scalar_double(x); } inline texpr1::builder::builder(const environment& e, const frac& x) { l.env = const_cast(e.get_ap_environment_t()); l.texpr0 = ap_texpr0_cst_scalar_frac(x.num, x.den); } inline texpr1::builder::builder(const environment& e, const interval& x) { l.env = const_cast(e.get_ap_environment_t()); l.texpr0 = ap_texpr0_cst_interval(const_cast(x.get_ap_interval_t())); } inline texpr1::builder::builder(const environment& e, const scalar& inf, const scalar& sup) { l.env = const_cast(e.get_ap_environment_t()); l.texpr0 = ap_texpr0_cst_interval_scalar(const_cast(inf.get_ap_scalar_t()), const_cast(sup.get_ap_scalar_t())); } inline texpr1::builder::builder(const environment& e, const mpq_class& inf, const mpq_class& sup) { l.env = const_cast(e.get_ap_environment_t()); l.texpr0 = ap_texpr0_cst_interval_mpq(const_cast(inf).get_mpq_t(), const_cast(sup).get_mpq_t()); } inline texpr1::builder::builder(const environment& e, mpfr_t inf, mpfr_t sup) { l.env = const_cast(e.get_ap_environment_t()); l.texpr0 = ap_texpr0_cst_interval_mpfr(inf,sup); } inline texpr1::builder::builder(const environment& e, int inf, int sup) { l.env = const_cast(e.get_ap_environment_t()); l.texpr0 = ap_texpr0_cst_interval_int(inf, sup); } inline texpr1::builder::builder(const environment& e, long inf, long sup) { l.env = const_cast(e.get_ap_environment_t()); l.texpr0 = ap_texpr0_cst_interval_int(inf, sup); } inline texpr1::builder::builder(const environment& e, double inf, double sup) { l.env = const_cast(e.get_ap_environment_t()); l.texpr0 = ap_texpr0_cst_interval_double(inf, sup); } inline texpr1::builder::builder(const environment& e, const frac& inf, const frac& sup) { l.env = const_cast(e.get_ap_environment_t()); l.texpr0 = ap_texpr0_cst_interval_frac(inf.num, inf.den, sup.num, sup.den); } inline texpr1::builder::builder(const environment& e, top t) { l.env = const_cast(e.get_ap_environment_t()); l.texpr0 = ap_texpr0_cst_interval_top(); } inline texpr1::builder::builder(const environment& e, const var& v) { l.env = const_cast(e.get_ap_environment_t()); ap_dim_t d = ap_environment_dim_of_var(l.env, v.get_ap_var_t()); if (d==AP_DIM_MAX) throw std::invalid_argument("texpr1::builder::builder(const environment&, const var&) variable not in environment"); l.texpr0 = ap_texpr0_dim(d); } inline texpr1::builder::builder(ap_texpr_op_t op, const builder& argA, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { if (!ap_texpr_is_unop(op)) throw std::invalid_argument("apron::texpr1::builder::builder(ap_texpr_op_t, const builder&, ap_texpr_rtype_t, ap_texpr_rdir_t) not a unary operator"); l.env = argA.l.env; l.texpr0 = ap_texpr0_unop(op, const_cast(argA.l.texpr0), rtype, rdir); } inline texpr1::builder::builder(ap_texpr_op_t op, const builder& argA, const builder& argB, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { if (!ap_texpr_is_binop(op)) throw std::invalid_argument("apron::texpr1::builder::builder(ap_texpr_op_t, const builder&, const builder&, ap_texpr_rtype_t, ap_texpr_rdir_t) not a binary operator"); l.env = argA.l.env; l.texpr0 = ap_texpr0_binop(op, const_cast(argA.l.texpr0), const_cast(argB.l.texpr0), rtype, rdir); } /* 'intelligent' constructors */ inline texpr1::builder unary(ap_texpr_op_t op, const texpr1::builder& a, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr1::builder(op, a, rtype, rdir); } inline texpr1::builder binary(ap_texpr_op_t op, const texpr1::builder& a, const texpr1::builder& b, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr1::builder(op, a, b, rtype, rdir); } inline texpr1::builder add(const texpr1::builder& a, const texpr1::builder& b, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr1::builder(AP_TEXPR_ADD, a, b, rtype, rdir); } inline texpr1::builder sub(const texpr1::builder& a, const texpr1::builder& b, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr1::builder(AP_TEXPR_SUB, a, b, rtype, rdir); } inline texpr1::builder mul(const texpr1::builder& a, const texpr1::builder& b, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr1::builder(AP_TEXPR_MUL, a, b, rtype, rdir); } inline texpr1::builder div(const texpr1::builder& a, const texpr1::builder& b, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr1::builder(AP_TEXPR_DIV, a, b, rtype, rdir); } inline texpr1::builder mod(const texpr1::builder& a, const texpr1::builder& b, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr1::builder(AP_TEXPR_MOD, a, b, rtype, rdir); } inline texpr1::builder neg(const texpr1::builder& a, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr1::builder(AP_TEXPR_NEG, a, rtype, rdir); } inline texpr1::builder cast(const texpr1::builder& a, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr1::builder(AP_TEXPR_CAST, a, rtype, rdir); } inline texpr1::builder floor(const texpr1::builder& a) { return texpr1::builder(AP_TEXPR_CAST, a, AP_RTYPE_INT, AP_RDIR_DOWN); } inline texpr1::builder ceil(const texpr1::builder& a) { return texpr1::builder(AP_TEXPR_CAST, a, AP_RTYPE_INT, AP_RDIR_UP); } inline texpr1::builder trunc(const texpr1::builder& a) { return texpr1::builder(AP_TEXPR_CAST, a, AP_RTYPE_INT, AP_RDIR_ZERO); } inline texpr1::builder sqrt(const texpr1::builder& a, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir) { return texpr1::builder(AP_TEXPR_SQRT, a, rtype, rdir); } inline texpr1::builder operator+(const texpr1::builder& a) { return a; } inline texpr1::builder operator-(const texpr1::builder& a) { return neg(a); } inline texpr1::builder operator+(const texpr1::builder& a, const texpr1::builder& b) { return add(a,b); } inline texpr1::builder operator-(const texpr1::builder& a, const texpr1::builder& b) { return sub(a,b); } inline texpr1::builder operator*(const texpr1::builder& a, const texpr1::builder& b) { return mul(a,b); } inline texpr1::builder operator/(const texpr1::builder& a, const texpr1::builder& b) { return div(a,b); } inline texpr1::builder operator%(const texpr1::builder& a, const texpr1::builder& b) { return mod(a,b); } /* tests */ /* ===== */ inline bool texpr1::builder::is_zero() const { return l.texpr0->discr==AP_TEXPR_CST && ap_coeff_zero(const_cast(&l.texpr0->val.cst)); } /* destructor */ /* ========== */ inline texpr1::builder::~builder() { switch(l.texpr0->discr){ case AP_TEXPR_CST: ap_coeff_clear(&l.texpr0->val.cst); break; case AP_TEXPR_DIM: break; case AP_TEXPR_NODE: free(l.texpr0->val.node); break; default: assert(false); } free(l.texpr0); } /* C-level compatibility */ /* ===================== */ inline ap_texpr1_t* texpr1::builder::get_ap_texpr1_t() { return &l; } inline const ap_texpr1_t* texpr1::builder::get_ap_texpr1_t() const { return &l; } apron-dist-0.9.10/apron/apronxx/Makefile0000640014525101416610000001025211005654323020022 0ustar bjeannetpopart# Makefile # # APRON Library / C++ class wrappers # # Copyright (C) Antoine Mine' 2007 include ../Makefile.config #--------------------------------------- # Directories #--------------------------------------- SRCDIR = $(shell pwd) # PREFIX = $(APRON_PREFIX) # # C include and lib directories INCDIR = $(PREFIX)/include LIBDIR = $(PREFIX)/lib BINDIR = $(PREFIX)/bin # SRCDIR = $(shell pwd) #--------------------------------------- # Programs #--------------------------------------- # Library creation SHARED = gcc -shared #--------------------------------------- # Flags #--------------------------------------- # Machine-independent compilation flags. ICXXFLAGS = \ -I../apron \ -I../num \ -I../itv \ -I../newpolka \ -I../octagons \ -I../box \ -I$(GMP_PREFIX)/include -I$(MPFR_PREFIX)/include LIBS = \ -L. -lapronxx_debug \ -L../newpolka -lpolkaMPQ_debug \ -L../octagons -loctMPQ_debug \ -L../box -lboxMPQ_debug ifneq ($(HAS_PPL),) DEFS := $(DEFS) -DHAS_PPL LIBS := $(LIBS) -L$(PPL_PREFIX)/lib -L../ppl -L../products -lap_pkgrid -lap_ppl -lppl ICXXFLAGS := $(ICXXFLAGS) -I$(PPL_PREFIX)/include -I../ppl -I../products endif LIBS := $(LIBS) \ -L../apron -lapron_debug \ -L../itv -litv_debug \ -L$(GMP_PREFIX)/lib -L$(MPFR_PREFIX)/lib -lgmpxx -lmpfr -lgmp -lm #--------------------------------------- # Files #--------------------------------------- CXXSOURCES = apronxx.cc CCINC = \ apronxx.hh apxx_generator1.hh apxx_polka_inline.hh \ apxx_abstract0.hh apxx_generator1_inline.hh apxx_ppl.hh \ apxx_abstract0_inline.hh apxx_interval.hh apxx_ppl_inline.hh \ apxx_abstract1.hh apxx_interval_inline.hh apxx_ppl_product.hh \ apxx_abstract1_inline.hh apxx_lincons0.hh apxx_ppl_product_inline.hh \ apxx_box.hh apxx_lincons0_inline.hh apxx_scalar.hh \ apxx_box_inline.hh apxx_lincons1.hh apxx_scalar_inline.hh \ apxx_coeff.hh apxx_lincons1_inline.hh apxx_tcons0.hh \ apxx_coeff_inline.hh apxx_linexpr0.hh apxx_tcons0_inline.hh \ apxx_dimension.hh apxx_linexpr0_inline.hh apxx_tcons1.hh \ apxx_dimension_inline.hh apxx_linexpr1.hh apxx_tcons1_inline.hh \ apxx_environment.hh apxx_linexpr1_inline.hh apxx_texpr0.hh \ apxx_environment_inline.hh apxx_manager.hh apxx_texpr0_inline.hh \ apxx_expr0.hh apxx_manager_inline.hh apxx_texpr1.hh \ apxx_expr1.hh apxx_oct.hh apxx_texpr1_inline.hh \ apxx_generator0.hh apxx_oct_inline.hh apxx_var.hh \ apxx_generator0_inline.hh apxx_polka.hh apxx_var_inline.hh #--------------------------------------- # Rules #--------------------------------------- all: libapronxx.a libapronxx_debug.a test test: apronxx_test clean: /bin/rm -f *.[ao] *.so apronxx_test /bin/rm -fr *~ \#*\# tmp rebuild: mostlyclean: install: $(INSTALLd) $(INCDIR) $(INCDIR)/apronxx $(LIBDIR) $(BINDIR) $(INSTALL) $(CCINC) $(INCDIR)/apronxx $(INSTALL) libapronxx.a libapronxx_debug.a $(LIBDIR) uninstall: /bin/rm -rf $(INCDIR)/apronxx /bin/rm -f $(LIBDIR)/linapronxx*.a distclean: uninstall dist: $(CCINC) $(CXXSOURCES) apronxx_test.cc apronxx_test_result.txt Makefile COPYING.GPL COPYING.LGPL README doc/Doxyfile (cd ..; tar zcvf apronxx.tgz $(^:%=apronxx/%)) #--------------------------------------- # IMPLICIT RULES AND DEPENDENCIES #--------------------------------------- .SUFFIXES: .tex .cc .hh .a .o .so #----------------------------------- # C++ part #----------------------------------- libapronxx.a: $(subst .cc,.o,$(CXXSOURCES)) $(AR) rcs $@ $^ $(RANLIB) $@ libapronxx_debug.a: $(subst .cc,_debug.o,$(CXXSOURCES)) $(AR) rcs $@ $^ $(RANLIB) $@ apronxx_test: libapronxx_debug.a apronxx_test_debug.o $(CXX) $(CXXFLAGS_DEBUG) -o $@ apronxx_test_debug.o $(LIBS) %.o: %.cc $(CCINC) $(CXX) $(CXXFLAGS) $(ICXXFLAGS) $(DEFS) -c -o $@ $< %_debug.o: %.cc $(CCINC) $(CXX) $(CXXFLAGS_DEBUG) $(ICXXFLAGS) $(DEFS) -c -o $@ $< #----------------------------------- # Documentation #----------------------------------- doc: $(CCINC) doc/Doxyfile cd doc && doxygen cd doc/latex && make .PHONY: doc apron-dist-0.9.10/apron/apronxx/COPYING.GPL0000640014525101416610000004313310703144237020044 0ustar bjeannetpopart GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. apron-dist-0.9.10/apron/apronxx/apxx_scalar_inline.hh0000640014525101416610000002236111006063143022545 0ustar bjeannetpopart/* -*- C++ -*- * apxx_scalar_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ /* ================================= */ /* use_malloc */ /* ================================= */ inline void* use_malloc::operator new(size_t sz) { void* x = malloc(sz); if (!x) throw std::bad_alloc(); return x; } inline void* use_malloc::operator new[](size_t sz) { void* x = malloc(sz); if (!x) throw std::bad_alloc(); return x; } inline void use_malloc::operator delete(void* p) { free(p); } inline void use_malloc::operator delete[](void* p) { free(p); } /* ================================= */ /* scalar */ /* ================================= */ /* constructors */ /* ============ */ inline scalar::scalar() { ap_scalar_init(&c, AP_SCALAR_DOUBLE); } inline scalar::scalar(int x) { ap_scalar_init(&c, AP_SCALAR_MPQ); ap_scalar_set_int(&c, x); } inline scalar::scalar(long x) { ap_scalar_init(&c, AP_SCALAR_MPQ); ap_scalar_set_int(&c, x); } inline scalar::scalar(double x) { ap_scalar_init(&c, AP_SCALAR_DOUBLE); ap_scalar_set_double(&c, x); } inline scalar::scalar(const frac& x) { ap_scalar_init(&c, AP_SCALAR_MPQ); ap_scalar_set_frac(&c, x.num, x.den); } inline scalar::scalar(infty x) { ap_scalar_init(&c, AP_SCALAR_DOUBLE); ap_scalar_set_infty(&c, x.sgn); } inline scalar::scalar(const mpq_class& x) { ap_scalar_init(&c, AP_SCALAR_MPQ); ap_scalar_set_mpq(&c, const_cast(x).get_mpq_t()); } inline scalar::scalar(mpfr_t x) { ap_scalar_init(&c, AP_SCALAR_MPFR); ap_scalar_set_mpfr(&c,x); } inline scalar::scalar(const scalar& x) { ap_scalar_init(&c, x.c.discr); ap_scalar_set(&c, const_cast(&x.c)); } /* destructor */ /* ========== */ inline scalar::~scalar() { ap_scalar_clear(&c); } /* assignments */ /* =========== */ /* = */ inline scalar& scalar::operator= (int x) { ap_scalar_set_int(&c, x); return *this; } inline scalar& scalar::operator= (long x) { ap_scalar_set_int(&c, x); return *this; } inline scalar& scalar::operator= (double x) { ap_scalar_set_double(&c, x); return *this; } inline scalar& scalar::operator= (const frac& x) { ap_scalar_set_frac(&c, x.num, x.den); return *this; } inline scalar& scalar::operator= (infty x) { ap_scalar_set_infty(&c, x.sgn); return *this; } inline scalar& scalar::operator= (const mpq_class& x) { ap_scalar_set_mpq(&c, const_cast(x).get_mpq_t()); return *this; } inline scalar& scalar::operator= (mpfr_t x) { ap_scalar_set_mpfr(&c, x); return *this; } inline scalar& scalar::operator= (const scalar& x) { ap_scalar_set(&c, const_cast(&x.c)); return *this; } /* swap */ inline void swap(scalar& a, scalar &b) { ap_scalar_swap(&a.c, &b.c); } /* access */ /* ====== */ inline ap_scalar_discr_t scalar::get_discr() const { return c.discr; } inline double& scalar::get_double() { if (c.discr!=AP_SCALAR_DOUBLE) throw(bad_discriminant("apron::scalar::get_double()")); return c.val.dbl; } inline const double& scalar::get_double() const { if (c.discr!=AP_SCALAR_DOUBLE) throw(bad_discriminant("apron::scalar::get_double()")); return c.val.dbl; } inline mpq_class& scalar::get_mpq() { if (c.discr!=AP_SCALAR_MPQ) throw(bad_discriminant("apron::scalar::get_mpq()")); return reinterpret_cast(*c.val.mpq); } inline const mpq_class& scalar::get_mpq() const { if (c.discr!=AP_SCALAR_MPQ) throw(bad_discriminant("apron::scalar::get_mpq()")); return reinterpret_cast(*c.val.mpq); } /* conversion */ /* ========== */ inline mpq_class scalar::to_mpq(mp_rnd_t round, order& conv) const { mpq_class r; int o = ap_mpq_set_scalar(r.get_mpq_t(), const_cast(&c), round); conv = (o>0) ? GREATER : (o<0) ? LESS : EQUAL; return r; } inline double scalar::to_double(mp_rnd_t round, order& conv) const { double r; int o = ap_double_set_scalar(&r, const_cast(&c), round); conv = (o>0) ? GREATER : (o<0) ? LESS : EQUAL; return r; } inline void scalar::to_mpfr(mpfr_t r, mp_rnd_t round, order& conv) const { int o = ap_mpfr_set_scalar(r, const_cast(&c), round); conv = (o>0) ? GREATER : (o<0) ? LESS : EQUAL; } inline scalar::operator mpq_class() const { order c; return to_mpq(GMP_RNDN, c); } inline scalar::operator double() const { order c; return to_double(GMP_RNDN, c); } /* print */ /* ===== */ inline std::ostream& operator<< (std::ostream& os, const scalar& s) { int i = ap_scalar_infty(const_cast(&s.c)); if (i>0) return os << "+oo"; if (i<0) return os << "-oo"; switch (s.c.discr) { case AP_SCALAR_DOUBLE: return os << s.c.val.dbl; case AP_SCALAR_MPQ: return os << s.c.val.mpq; case AP_SCALAR_MPFR: { double d = mpfr_get_d(s.c.val.mpfr,GMP_RNDU); if (!mpfr_cmp_d(s.c.val.mpfr,d)) return os << d; mp_exp_t e; char* tmp = mpfr_get_str(NULL,&e,10,os.precision(),s.c.val.mpfr,GMP_RNDU); if (tmp[0]=='-' || tmp[0]=='+') { os << tmp[0] << "." << tmp+1; if (e>0) os << "e+" << e; if (e<0) os << "e" << e; } else { os << "." << tmp; if (e>0) os << "e+" << e; if (e<0) os << "e" << e; } mpfr_free_str(tmp); return os; } default: return os; } } inline void scalar::print(FILE* stream) const { ap_scalar_fprint(stream, const_cast(&c)); } /* tests */ /* ===== */ inline scalar::order scalar::is_infty() const { return (order) ap_scalar_infty(const_cast(&c)); } inline scalar::order scalar::sgn () const { return (order) ap_scalar_sgn(const_cast(&c)); } inline scalar::order cmp(const scalar& a, const scalar& b) { return (scalar::order) ap_scalar_cmp(const_cast(&a.c), const_cast(&b.c)); } inline bool operator>=(const scalar& a, const scalar& b) { return ap_scalar_cmp(const_cast(&a.c), const_cast(&b.c))>=0; } inline bool operator<=(const scalar& a, const scalar& b) { return ap_scalar_cmp(const_cast(&a.c), const_cast(&b.c))<=0; } inline bool operator>(const scalar& a, const scalar& b) { return ap_scalar_cmp(const_cast(&a.c), const_cast(&b.c))>0; } inline bool operator<(const scalar& a, const scalar& b) { return ap_scalar_cmp(const_cast(&a.c), const_cast(&b.c))<0; } inline bool operator==(const scalar& a, const scalar& b) { return ap_scalar_equal(const_cast(&a.c), const_cast(&b.c)); } inline bool operator!=(const scalar& a, const scalar& b) { return !ap_scalar_equal(const_cast(&a.c), const_cast(&b.c)); } inline scalar::order cmp(const scalar& a, int b) { return (scalar::order) ap_scalar_cmp_int(const_cast(&a.c), b); } inline bool operator>=(const scalar& a, int b) { return ap_scalar_cmp_int(const_cast(&a.c), b)>=0; } inline bool operator<=(const scalar& a, int b) { return ap_scalar_cmp_int(const_cast(&a.c), b)<=0; } inline bool operator>(const scalar& a, int b) { return ap_scalar_cmp_int(const_cast(&a.c), b)>0; } inline bool operator<(const scalar& a, int b) { return ap_scalar_cmp_int(const_cast(&a.c), b)<0; } inline bool operator==(const scalar& a, int b) { return ap_scalar_equal_int(const_cast(&a.c), b); } inline bool operator!=(const scalar& a, int b) { return !ap_scalar_equal_int(const_cast(&a.c), b); } inline scalar::order cmp(int a, const scalar& b) { return (scalar::order) ap_scalar_cmp_int(const_cast(&b.c), a); } inline bool operator>=(int a, const scalar& b) { return ap_scalar_cmp_int(const_cast(&b.c), a)<=0; } inline bool operator<=(int a, const scalar& b) { return ap_scalar_cmp_int(const_cast(&b.c), a)>=0; } inline bool operator>(int a, const scalar& b) { return ap_scalar_cmp_int(const_cast(&b.c), a)<0; } inline bool operator<(int a, const scalar& b) { return ap_scalar_cmp_int(const_cast(&b.c), a)>0; } inline bool operator==(int a, const scalar& b) { return ap_scalar_equal_int(const_cast(&b.c), a); } inline bool operator!=(int a, const scalar& b) { return !ap_scalar_equal_int(const_cast(&b.c), a); } /* other operators */ /* =============== */ inline void scalar::neg() { ap_scalar_neg(&c, &c); } inline scalar scalar::operator- () const { scalar r = *this; r.neg(); return r; } inline void scalar::inv() { ap_scalar_inv(&c, &c); } inline scalar scalar::operator~ () const { scalar r = *this; r.inv(); return r; } inline long scalar::hash() const { return ap_scalar_hash(const_cast(&c)); } /* C API compatibility */ /* =================== */ inline const ap_scalar_t* scalar::get_ap_scalar_t() const { return &c; } inline ap_scalar_t* scalar::get_ap_scalar_t() { return &c; } apron-dist-0.9.10/apron/apronxx/apxx_linexpr1.hh0000640014525101416610000002276610703144237021524 0ustar bjeannetpopart/* -*- C++ -*- * apxx_linexpr1.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_LINEXPR1_HH #define __APXX_LINEXPR1_HH #include "ap_linexpr1.h" #include "apxx_environment.hh" #include "apxx_linexpr0.hh" namespace apron { /* ================================= */ /* linexpr1 */ /* ================================= */ /*! \brief Level 1 linear expression (ap_linexpr1_t wrapper). * * Level 1 version of linear expressions with scalar or interval coefficients (coeff). * Terms are indexed using variable names (var) instead of dimensions (ap_dim_t). * Internally, a linexpr1 wraps together a linexpr0 (memory managed) and an environment (holding a * reference count). */ class linexpr1 : public use_malloc { protected: ap_linexpr1_t l; //!< Structure managed by APRON. //! Internal use only. Shallow copy (no copy of linexpr0 or environment). linexpr1(ap_linexpr1_t& p); public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ /*! \brief Creates a new expression from a linexpr0 (copied) and an environment (reference count * incremented) associating names to dimensions in linexpr0. */ linexpr1(const environment& e, const linexpr0& x); /*! \brief Creates a new null expression. * * \arg \c e associates a variable name to each dimension. * \arg \c discr whether the expression is sparse (\c AP_LINEXPR_SPARSE) or dense (\c AP_LINEXPR_DENSE). * \arg \c size, for \c AP_LINEXPR_SPARSE expressions, is the initial number of dimensions in the * underlying linexpr0 (new dimensions being added as needed); ignored for \c AP_LINEXPR_DENSE * expressions (the size being always the size of the environment). */ linexpr1(const environment& e, ap_linexpr_discr_t lin_discr=AP_LINEXPR_SPARSE, size_t size=0); //! Makes a (deep) copy. linexpr1(const linexpr1& x); /*! \brief Makes a (deep) copy of x and extends its environment. * * \throw std::invalid_argument if e is not a super-environment of that of x. */ linexpr1(const linexpr1& x, const environment& e); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ /*! \brief Frees all space for the expression and coefficients, and decrements the reference count * of the environment. */ ~linexpr1(); //@} /* assignment */ /* ========== */ /** @name Assignment */ //@{ //! Makes a (deep) copy. linexpr1& operator= (const linexpr1& x); //@} /* dimension operations */ /* ==================== */ /** @name Dimension operations */ //@{ /*! \brief Extends the environment of the expression. * * \throw std::invalid_argument if e is not a super-environment of that of *this. */ void extend_environment(const environment& e); //@} /* access */ /* ====== */ /** @name Accesses, size */ //@{ //! Returns the environment of the expression (with incremented reference count). environment get_environment() const; //! Returns a reference to the underlying linexpr0. const linexpr0& get_linexpr0() const; //! Returns a modifiable reference to the underlying linexpr0. linexpr0& get_linexpr0(); //! Returns the number of coefficients in the expression. size_t size() const; /*! \brief Returns the type of underlying linexpr0. * * \return Either \c AP_LINEXPR_SPARSE or \c AP_LINEXPR_DENSE. */ ap_linexpr_discr_t get_discr() const; //! Returns a (modifiable) reference to the constant coefficient. coeff& get_cst(); //! Returns a reference to the constant coefficient. const coeff& get_cst() const; /*! \brief Returns a (modifiable) reference to the coefficient corresponding to the given variable name. * * \throw std::invalid_argument if the variable name is not present in the environment. */ coeff& operator[](const var& v); /*! \brief Returns a reference to the coefficient corresponding to the given variable name. * * \throw std::invalid_argument if the variable name is not present in the environment. */ const coeff& operator[](const var& v) const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ //! Printing. friend std::ostream& operator<< (std::ostream& os, const linexpr1& s); //! Prints to a C stream. void print(FILE* stream=stdout) const; //@} /* tests */ /* ===== */ /** @name Tests */ //@{ //! Whether the expression only depends on integer variables bool is_integer() const; //! Whether the expression only depends on real variables bool is_real() const; /*! \brief Gets the type of the linear expression. * * \return Either \c AP_LINEXPR_INTLINEAR (coefficients are interval), * \c AP_LINEXPR_QUASILINEAR (coefficients are scalar except the constant one), or * \c AP_LINEXPR_LINEAR (all coefficients are scalar). */ ap_linexpr_type_t get_type() const; //! Whether all coefficients are scalar. bool is_linear() const; //! Whether all coefficients are scalar, except maybe the constant one. bool is_quasilinear() const; // TODO: equal, compare (currently not in ap_linexpr1.h) ??? //@} /* iterators */ /* ========= */ /** @name Iterator */ //@{ /*! \brief Iterator to traverse a constant linexpr1. * * At each position, there is variable name and its corresponding coefficients. * The expression is traversed in increasing order of integer variable names followed by * real variable names also in increasing order. * * To mutate a linear expression, use the iterator class instead. * * Sample code: * \code for (linexpr1::const_iterator i = m.begin();i.valid();++i) cout << i.get_coeff() << " "; \endcode */ class const_iterator { /* TODO: - reverse traversal (operator--). */ friend class linexpr1; protected: ap_linexpr1_t* l; //!< Internal use only. Pointer to the underlying APRON structure. ap_dim_t pos; //!< Internal use only. Current index. //! Internal use only. Skips free coefficients in sparse expressions. void skip_AP_DIM_MAX(); //! Internal use only. const_iterator(ap_linexpr1_t* l); public: //! Starts a new iterator to traverse the linear expression. const_iterator(const linexpr1& e); //! Duplicates the iterator. const_iterator(const const_iterator& i); //! Assigns the iterator. const_iterator& operator=(const const_iterator& i); /*! \brief Returns the variable name of the coefficient at the current iterator position. * * \throw std::out_of_range if valid() returns false (we are past the last position). */ const var& get_var() const; /*! \brief Returns the dimension of the coefficient at the current iterator position. * * \throw std::out_of_range if valid() returns false (we are past the last position). */ ap_dim_t get_dim() const; /*! \brief Returns a reference to the coefficient at the current iterator position. * * \throw std::out_of_range if valid() returns false (we are past the last position). */ const coeff& get_coeff() const; //! Moves the iterator to the following position. void next(); /*! \brief Moves the iterator to the following position. * * (Identical to next()). */ void operator++(); //! Whether we are at a valid position (true) or past the last iterator position (false). bool valid() const; }; /*! \brief Iterator to traverse and mutate a linear expression. * * As const_iterator, but for non-constant linexpr1. * * Caution: do not modify the expression during traversal, except through the iterator. * * Sample code: * \code for (linexpr1::iterator i = m.begin();i.valid();++i) i.get_coeff().neg(); \endcode */ class iterator : public const_iterator { /* TODO: - removing/inserting coefficients at iterator position for sparse expressions. */ protected: friend class linexpr1; //! Internal use only. iterator(ap_linexpr1_t* l); public: //! Starts a new iterator to traverse the linear expression. iterator(linexpr1& e); //! Duplicates the iterator. iterator(const iterator& i); //! Assigns the iterator. iterator& operator=(const iterator& i); /*! \brief Returns a (modifiable) reference to the coefficient at the current iterator position. * * \throw std::out_of_range if valid() returns false (we are past the last position). */ coeff& get_coeff() const; }; //! Returns a new iterator to traverse and mutate the linear expression. iterator begin(); //! Returns a new constant iterator to traverse the linear expression. const_iterator begin() const; //@} /* other operators */ /* =============== */ /** @name Operators */ //@{ /*! \brief Minimizes all coefficients. * * In sparse expressions, also remove zero and unused (hole) coefficients to save space. */ void minimize(); //@} /* TODO: evaluation, linearization, intelligent constructors */ /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. const ap_linexpr1_t* get_ap_linexpr1_t() const; //! Returns a pointer to the internal APRON object stored in *this. ap_linexpr1_t* get_ap_linexpr1_t(); //@} }; #include "apxx_linexpr1_inline.hh" } #endif /* __APXX_LINEXPR1_HH */ apron-dist-0.9.10/apron/apronxx/apronxx_test.cc0000640014525101416610000034132011006063143021425 0ustar bjeannetpopart/* * apronxx_test.cc * * APRON Library / Test-suite for C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under GPL license. Please read the COPYING file packaged in the distribution. */ #undef HAS_PPL #define HAS_PPL 1 #include #include #include "apronxx.hh" #include "apxx_box.hh" #include "apxx_oct.hh" #include "apxx_polka.hh" #if HAS_PPL #include "apxx_ppl.hh" #include "apxx_ppl_product.hh" #endif using namespace std; using namespace apron; mpfr_t mpfr1,mpfr2,mpfr3; void test_scalar() { cout << endl << "scalars" << endl << "=======" << endl << endl; // constructors cout << "construct 2: " << scalar(2) << endl; cout << "construct 2L: " << scalar(2L) << endl; cout << "construct 2.: " << scalar(2.) << endl; cout << "construct frac(1,5): " << scalar(frac(1,5)) << endl; cout << "construct infty(-1): " << scalar(infty(-1)) << endl; cout << "construct mpq_class(1,5): " << scalar(mpq_class(1,5)) << endl; cout << "construct mpfr(1.25): " << scalar(mpfr1) << endl; // assignments scalar s = 12; scalar cp = s; cout << "copy 12: " << cp << endl; cp = 2; cout << "assign 2: " << cp << endl; cp = 2.; cout << "assign 2.: " << cp << endl; cp = frac(1,5); cout << "assign frac(1,5): " << cp << endl; cp = s; cout << "copy 12: " << s << endl; cp = 5; cout << "before swap 12 5: " << s << " " << cp << endl; swap(cp,s); cout << "after swap 5 12: " << s << " " << cp << endl; cp = s = 2; cout << "chain assign 2: " << s << " " << cp << endl; cp = s = 2.; cout << "chain assign 2.: " << s << " " << cp << endl; // tests cp = s = 12; assert(cp==s && cp>=s && cp<=s && !(cps) && !(cp!=s)); assert(cp==12 && cp>=11 && cp<=13 && !(4>cp) && !(cp>49)); // access scalar::order o; cp = 2; assert(cp.get_discr()==AP_SCALAR_MPQ); assert(cp.get_mpq()==2); assert(cp!=scalar(mpfr1)); try { cp.get_double(); assert(0); } catch (bad_discriminant& b) {}; assert(cp.to_mpq(GMP_RNDN,o)==2); assert(cp.to_double(GMP_RNDN,o)==2); //assert((mpq_class)cp==mpq_class(2)); assert(double(cp)==2); assert(cp!=scalar(mpfr1)); cp = mpfr1; assert(cp.get_discr()==AP_SCALAR_MPFR); assert(cp==mpfr1); assert(cp!=mpfr2); assert(cp==scalar(1.25)); assert(cp!=scalar(1.26)); assert(cp==scalar(mpq_class(125,100))); assert(cp!=scalar(mpq_class(126,100))); cp = 2.; assert(cp.get_discr()==AP_SCALAR_DOUBLE); assert(cp.get_double()==2); try { cp.get_mpq(); assert(0); } catch (bad_discriminant& b) {}; assert(cp.to_mpq(GMP_RNDN,o)==2); assert(cp.to_double(GMP_RNDN,o)==2); cp.to_mpfr(mpfr3,GMP_RNDN,o); assert(cp==scalar(mpfr3)); //assert(mpq_class(cp)==mpq_class(2)); assert(double(cp)==2); cp.get_double() = 15; cout << "get_double 15.: " << cp << endl; // new scalar*ps = new scalar(12); scalar*pa = new scalar[2]; pa[1] = *ps; cout << "array 12 0 12: " << *ps << " " << pa[0] << " " << pa[1] << endl; delete ps; delete[] pa; // operations scalar a = 12; scalar b = -a; a.neg(); cout << "neg -12 -12: " << a << " " << b << endl; b = ~a; a.inv(); cout << "inv -1/12 -1/12: " << a << " " << b << endl; printf("print: "); a.print(); printf("\n"); cout << "hash: " << a.hash() << endl; } void test_interval() { cout << endl << "intervals" << endl << "=========" << endl << endl; // constructors cout << "construct 0: " << interval() << endl; cout << "construct scalar(12): " << interval(scalar(12), scalar(15)) << endl; cout << "construct [12,15]: " << interval(12,15) << endl; cout << "construct [12L,15L]: " << interval(12L,15L) << endl; cout << "construct [5.,18.]: " << interval(5.,18.) << endl; cout << "construct [frac(1,2),frac(5,4)]: " << interval(frac(1,2),frac(5,4)) << endl; cout << "construct [mpq(15,3),15]: " << interval(mpq_class(15,3),15) << endl; cout << "construct [mpfr(1.25),mpfr(99)]: " << interval(mpfr1,mpfr2) << endl; cout << "construct top: " << interval(top()) << endl; cout << "construct bottom: " << interval(bottom()) << endl; // assignments interval i = interval(-5,5); interval c = i; cout << "copy [-5,5]: " << c << endl; c = top(); cout << "assign top: " << c << endl; c = bottom(); cout << "assign bottom: " << c << endl; c = i; cout << "copy [-5,5]: " << c << endl; c.set(scalar(5),scalar(19)); cout << "set [scalar(5),scalar(19)]: " << c << endl; c.set(12,18); cout << "set [12,18]: " << c << endl; c.set(12.,18.); cout << "set [12.,18.]: " << c << endl; c.set(frac(1,2),frac(3,4)); cout << "set [frac(1,2),frac(3,4)]: " << c << endl; c.set(mpq_class(8),mpq_class(10)); cout << "set [mpq(8),mpq(10)]: " << c << endl; c.set(mpfr1,mpfr2); cout << "set [mpfr(1.25),mpfr(99)]: " << c << endl; c.set(top()); cout << "set top: " << c << endl; c.set(bottom()); cout << "set bottom: " << c << endl; c.set(i); cout << "set interval(-5,5): " << c << endl; i = top(); swap(i,c); cout << "after swap top [-5,5]: " << c << " " << i << endl; c = i.set(1,2); cout << "chain assign [1,2]: " << c << " " << i << endl; c = i = top(); cout << "chain assign top: " << c << " " << i << endl; // access c = interval(1,2); c.get_inf() = -1; cout << "get_inf: [-1,2]: " << c << endl; c.get_sup() = frac(1,2); cout << "get_sup [-1,1/2]: " << c << endl; // tests assert(interval(top()).is_top()); assert(!interval(bottom()).is_top()); assert(interval(scalar(infty(-1)),scalar(infty(1))).is_top()); assert(!interval(1,2).is_top()); assert(interval(bottom()).is_bottom()); assert(!interval(top()).is_bottom()); assert(interval(5,-10).is_bottom()); assert(interval(1,2)<=interval(1,3)); assert(interval(1,4)>interval(2,3)); assert(interval(1,2)==interval(1,2)); assert(interval(1,2)==interval(1.,2.)); assert(interval(scalar(infty(-1)),scalar(infty(1)))==interval(top())); assert(interval(5,-10)==interval(bottom())); assert(cmp(interval(1,2),interval(1,3))==interval::INCLUDED); assert(cmp(interval(1,3),interval(1,3))==interval::EQUAL); assert(cmp(interval(0,3),interval(1,3))==interval::CONTAINS); assert(cmp(interval(1,3),interval(2,4))==interval::LESS); assert(cmp(interval(5,6),interval(1,2))==interval::GREATER); // new interval*pi = new interval(12,13); interval*pa = new interval[2]; pa[1] = *pi; cout << "array [12,13] 0 [12,13]: " << *pi << " " << pa[0] << " " << pa[1] << endl; delete pi; delete[] pa; // operations interval a = interval(1,2); interval b = -a; a.neg(); cout << "neg [-2,-1] [-2,-1]: " << a << " " << b << endl; printf("print: "); a.print(); printf("\n"); cout << "hash: " << a.hash() << endl; } void test_interval_array() { cout << endl << "interval arrays" << endl << "===============" << endl << endl; interval_array a = interval_array(4); a[1] = interval(1,2); a.get(2) = interval(1.,2.); *(a.contents())[3] = interval(top()); try { a.get(4); assert(0); } catch (out_of_range& x) {}; interval_array b = a; interval_array c = interval_array(3); cout << "construct a: " << a.size() << " " << a << endl; cout << "copy a: " << b.size() << " " << b << endl; cout << "empty: " << c.size() << " " << c << endl; c = a; cout << "copy a: " << c.size() << " " << c << endl; vector v = vector(3); v[0] = interval(1,2); interval_array d = v; c = v; cout << "from vector v: " << d.size() << " " << d << endl; cout << "from vector v: " << c.size() << " " << c << endl; c = b = a; cout << "chain assign a: " << c.size() << " " << c << endl; vector vv = d; interval_array dd = vv; cout << "to vector v: " << dd.size() << " " << dd << endl; printf("print v: "); dd.print(); printf("\n"); } void test_coeff() { cout << endl << "coeff" << endl << "=====" << endl << endl; // constructors cout << "construct 0: " << coeff() << endl; cout << "construct 2: " << coeff(coeff(2)) << endl; cout << "construct scalar(frac(2,3)): " << coeff(scalar(frac(2,3))) << endl; cout << "construct 2: " << coeff(2) << endl; cout << "construct 2L: " << coeff(2L) << endl; cout << "construct 2.5: " << coeff(2.5) << endl; cout << "construct frac(2,3): " << coeff(frac(2,3)) << endl; cout << "construct mpq(2,3): " << coeff(mpq_class(2,3)) << endl; cout << "construct mpfr(1.25): " << coeff(mpfr1) << endl; cout << "construct interval(1,2): " << coeff(interval(1,2)) << endl; cout << "construct [scalar(1),scalar(2)]: " << coeff(scalar(1),scalar(2)) << endl; cout << "construct [1,2]: " << coeff(1,2) << endl; cout << "construct [1L,2L]: " << coeff(1L,2L) << endl; cout << "construct [1.1,2.2]: " << coeff(1.1,2.2) << endl; cout << "construct [frac(1,2),frac(3,4)]: " << coeff(frac(1,2),frac(3,4)) << endl; cout << "construct [mpq(1,2),mpq(3,4)]: " << coeff(mpq_class(1,2),mpq_class(3,4)) << endl; cout << "construct [mpfr(1.25),mpfr(99)]: " << coeff(mpfr1,mpfr2) << endl; cout << "construct top: " << coeff(top()) << endl; cout << "construct bottom: " << coeff(bottom()) << endl; // assignments coeff a; a = coeff(2); cout << "assign coeff(2): " << a << endl; a = scalar(2); cout << "assign scalar(2): " << a << endl; a = 2; cout << "assign 2: " << a << endl; a = 2L; cout << "assign 2L: " << a << endl; a = 2.5; cout << "assign 2.5: " << a << endl; a = frac(1,2); cout << "assign frac(1,2): " << a << endl; a = mpq_class(1,2); cout << "assign mpq(1,2): " << a << endl; a = mpfr1; cout << "assign mpfr(1.25): " << a << endl; a = interval(1,2); cout << "assign interval(1,2): " << a << endl; a = top(); cout << "assign top: " << a << endl; a = bottom(); cout << "assign bottom: " << a << endl; a.set(coeff(2)); cout << "set coeff(2): " << a << endl; a.set(scalar(2)); cout << "set scalar(2): " << a << endl; a.set(2); cout << "set 2: " << a << endl; a.set(2L); cout << "set 2L: " << a << endl; a.set(2.); cout << "set 2.: " << a << endl; a.set(frac(1,2)); cout << "set frac(1,2): " << a << endl; a.set(mpq_class(1,2)); cout << "set mpq(1,2): " << a << endl; a.set(mpfr1); cout << "set mpfr(1.25): " << a << endl; a.set(interval(1,2)); cout << "set interval(1,2): " << a << endl; a.set(scalar(1),scalar(2)); cout << "set [scalar(1),scalar(2)]: " << a << endl; a.set(1,2); cout << "set [1,2]: " << a << endl; a.set(1L,2L); cout << "set [1L,2L]: " << a << endl; a.set(1.1,2.2); cout << "set [1.1,2.2]: " << a << endl; a.set(frac(1,2),frac(3,4)); cout << "set [frac(1,2),frac(3,4)]: " << a << endl; a.set(mpq_class(1,2),mpq_class(3,4)); cout << "set [mpq(1,2),mpq(3,4)]: " << a << endl; a.set(mpfr1,mpfr2); cout << "set [mpfr(1.25),mpfr(99)]: " << a << endl; a.set(top()); cout << "set top: " << a << endl; a.set(bottom()); cout << "set bottom: " << a << endl; a = 2; coeff b = 3; cout << "before swap 2 3: " << a << " " << b << endl; swap(a,b); cout << "after swap 3 2: " << a << " " << b << endl; a = b = frac(1,2); cout << "chain assign frac(1,2): " << a << " " << b << endl; a = b.set(1.,2.); cout << "chain assign [1.,2.]: " << a << " " << b << endl; // access coeff x = scalar(2); assert(x.get_discr()==AP_COEFF_SCALAR); x.get_scalar() = 3; cout << "get_scalar 3: " << x << endl; try { x.get_interval(); assert(0); } catch (bad_discriminant b) {} x = interval(1,2); assert(x.get_discr()==AP_COEFF_INTERVAL); x.get_interval().get_inf() = 0; cout << "get_interval [0,2]: " << x << endl; try { x.get_scalar(); assert(0); } catch (bad_discriminant b) {} // tests assert(coeff(0).is_zero()); assert(!(coeff(1).is_zero())); assert(coeff(0.).is_zero()); assert(!(coeff(1.).is_zero())); assert(coeff(0,0).is_zero()); assert(!(coeff(0,1).is_zero())); assert(coeff(0.,0.).is_zero()); assert(!(coeff(0.,1.).is_zero())); #if 0 // overloaded by lincons0 assert(coeff(0)<=coeff(0,1)); assert(!(coeff(0)<=coeff(1,2))); assert(coeff(0,1)>=coeff(1)); assert(!(coeff(0,1)>=coeff(2))); assert(coeff(0)coeff(bottom())); assert(!(coeff(0)>coeff(top()))); #endif assert(coeff(0,1)==coeff(interval(0.,1.))); assert(!(coeff(0)==coeff(0,1))); assert(coeff(10,-10)==coeff(bottom())); assert(coeff(0)!=coeff(0,1)); // operations coeff cc = interval(1,1); cout << "before reduce [1,1]: " << cc << endl; cc.reduce(); cout << "after reduce 1: " << cc << endl; cc = interval(3,5); coeff dd = -cc; cc.neg(); cout << "neg [-5,-3] [-5,-3]: " << cc << " " << dd << endl; cout << "hash: " << cc.hash() << endl; printf("print: "); cc.print(); printf("\n"); } void test_dimchange() { cout << endl << "dimchange" << endl << "=========" << endl << endl; dimchange d = dimchange(1,2,(ap_dim_t[]){1,2,3}); cout << "from array 1 2 3: " << d; d = (ap_dim_t[]){3,2,1}; cout << "from array 3 2 1: " << d; cout << d.get_intdim() << " " << d.get_realdim() << " " << d.get(0) << " " << d[1] << endl; try { d.get(3); assert(0); } catch (out_of_range& b) {} dimchange e = d; d[0] = 12; cout << "copy 3 2 1: " << e; e = d; cout << "copy 12 2 1: " << e; vector x = vector(3,0); x[0] = 4; x[1] = 5; x[2] = 6; dimchange f = dimchange(1,2,x); cout << "from vector 4 5 6: " << f; d = x; cout << "from vector 4 5 6: " << d; dimchange g = dimchange(1,3); try { g = x; assert(0); } catch (invalid_argument& a) {} try { dimchange gg = dimchange(1,3,x); assert(0); } catch (invalid_argument& a) {} dimchange h = dimchange(d,true); dimchange i = -d; d.add_invert(); cout << "invert: " << d; cout << "invert: " << h; cout << "invert: " << i; printf("print: "); d.print(); string nms[4] ={ "x", "y", "z", "t" }; cout << "print w/ names: " << varname(vector(nms,nms+4)) << d << varname(vector(0)) << endl; } void test_dimperm() { cout << endl << "dimperm" << endl << "=======" << endl << endl; dimperm i = id(3); cout << "identity: " << i << endl; dimperm d = dimperm(3,(ap_dim_t[]){1,0,2}); cout << "from array 1 0 2: " << d; d = id(3); cout << "identity: " << d; d = (ap_dim_t[]){1,2,0}; cout << "from array 1 2 0: " << d; cout << d.size() << " " << d.get(0) << " " << d[1] << endl; try { d.get(3); assert(0); } catch (out_of_range& b) {} dimperm e = d; d[0] = 12; cout << "copy 1 2 0: " << e; e = d; cout << "copy 12 2 0: " << e; vector x = vector(3,0); x[0] = 2; x[1] = 0; x[2] = 1; dimperm f = x; cout << "from vector 2 0 1: " << f; d = x; cout << "from vector 2 0 1: " << d; dimperm g = dimperm(4); g = x; cout << "from vector 2 0 1: " << d; dimperm h = dimperm(g,true); g = -d; d.invert(); cout << "invert 1 2 0: " << d; cout << "invert 1 2 0: " << g; cout << "invert 1 2 0: " << h; g = g*g; cout << "compose 2 0 1: " << g; d *= d; cout << "compose 2 0 1: " << d; dimperm j = dimperm(d,d); cout << "invert 1 2 0: " << j; printf("print: "); j.print(); string nms[4] ={ "x", "y", "z", "t" }; cout << "print w/ names: " << varname(vector(nms,nms+4)) << j << varname(vector(0)) << endl; } void test_linexpr0() { dimchange dim = dimchange(1,1,(ap_dim_t[]){0,2}); dimperm perm = dimperm(3,(ap_dim_t[]){1,0,2}); dimperm perm2 = -perm; // dense cout << endl << "dense linexpr0" << endl << "==============" << endl << endl; linexpr0 l = linexpr0(AP_LINEXPR_DENSE,5); assert(l.get_discr()==AP_LINEXPR_DENSE); cout << "construct: " << l.size() << ", " << l << endl; l[0] = frac(1,4); l[3] = -2.; assert(l.is_linear() && l.is_quasilinear()); l.get_cst() = interval(1,2); assert(!l.is_linear() && l.is_quasilinear()); cout << "get_ 1/4x0 - 2x3 + [1,2]: " << l.size() << ", " << l << endl; linexpr0 m = l; assert(equal(m,l)); assert(m.get_discr()==AP_LINEXPR_DENSE); m[2] = top(); assert(!equal(m,l)); cout << "copy 1/4x0 + [-oo,+oo]x2 - 2x3 + [1,2]: " << m.size() << ", " << m << endl; cout << "copy 1/4x0 - 2x3 + [1,2]: " << l.size() << ", " << l << endl; cout << "[1]: " << l[1] << endl; coeff a[] = { 1,2,interval(0,1) }; linexpr0 n = linexpr0(3,a,2,AP_LINEXPR_DENSE); cout << "from array 1x0 + 2x1 + [0,1]x2 + 2: " << n.size() << ", " << n << endl; m = linexpr0(); n = m = l; cout << "chained copy 1/4x0 - 2x3 + [1,2]: " << n.size() << ", " << n << endl; assert(equal(m,l)); l[2] = interval(0,1); assert(!equal(m,l)); cout << "[] 1/4x0 + [0,1]x2 - 2x3 + [1,2]: " << l.size() << ", " << l << endl; cout << "copy 1/4x0 - 2x3 + [1,2]: " << m.size() << ", " << m << endl; swap(m,l); assert(!equal(m,l)); cout << "after swap: " << l.size() << ", " << l << endl; cout << "after swap: " << m.size() << ", " << m << endl; cout << "const iterator:"; for (linexpr0::const_iterator i = m.begin();i.valid();++i) cout << " " << i.get_coeff(); cout << endl; for (linexpr0::iterator i = m.begin();i.valid();++i) i.get_coeff().neg(); cout << "iterate neg -1/4x0 + [-1,0]x2 + 2x3 + [1,2]: " << m.size() << ", " << m << endl; try { l[5]; assert(0); } catch (out_of_range &r) {} l.resize(3); cout << "resize 1/4x0 + [1,2]: " << l.size() << ", " << l << endl; l[0] = interval(3,3); cout << "[] [3,3]x0 + [1,2]: " << l.size() << ", " << l << endl; l.minimize(); cout << "minimize 3x0 + [1,2]: " << l.size() << ", " << l << endl; linexpr0 l2 = linexpr0(l,dim); cout << "add dims: 3x1 + [1,2]: " << l2 << endl; linexpr0 l3 = l; l3.add_dimensions(dim); cout << "add_dims: 3x1 + [1,2]: " << l3 << endl; l[1] = interval(3,4); linexpr0 l4 = linexpr0(l,perm); cout << "permute: [3,4]x0 + 3x1 + [1,2]: " << l4 << endl; l4.permute_dimensions(perm2); cout << "permute: 3x0 + [3,4]x1 + [1,2]: " << l4 << endl; cout << "hash: " << l.hash() << endl; printf("print: "); l.print(); printf("\n"); string nms[4] ={ "x", "y", "z", "t" }; cout << "print w/ names: " << varname(vector(nms,nms+4)) << l << varname(vector(0)) << endl; // sparse cout << endl << "sparse linexpr0" << endl << "===============" << endl << endl; linexpr0 ll = linexpr0(AP_LINEXPR_SPARSE,5); assert(ll.get_discr()==AP_LINEXPR_SPARSE); cout << "construct: " << ll.size() << ", " << ll << endl; ll[0] = frac(1,4); ll[3] = -2.; assert(ll.is_linear() && ll.is_quasilinear()); ll.get_cst() = interval(1,2); assert(!ll.is_linear() && ll.is_quasilinear()); cout << "get_ 1/4x0 - 2x3 + [1,2]: " << ll.size() << ", " << ll << endl; linexpr0 mm = ll; assert(equal(mm,ll)); assert(mm.get_discr()==AP_LINEXPR_SPARSE); mm[2] = top(); assert(!equal(mm,ll)); cout << "copy 1/4x0 + [-oo,+oo]x2 - 2x3 + [1,2]: " << mm.size() << ", " << mm << endl; cout << "copy 1/4x0 - 2x3 + [1,2]: : " << ll.size() << ", " << ll << endl; cout << "[1] " << ll[1] << endl; mm = linexpr0(AP_LINEXPR_DENSE,5); assert(mm.get_discr()==AP_LINEXPR_DENSE); coeff aa[] = { 1,2,interval(0,1) }; linexpr0 nn = linexpr0(3,aa,2,AP_LINEXPR_SPARSE); cout << "from array 1x0 + 2x1 + [0,1]x2 + 2: " << nn.size() << ", " << nn << endl; mm = linexpr0(); nn = mm = ll; cout << "chained copy 1/4x0 - 2x3 + [1,2]: " << nn.size() << ", " << nn << endl; assert(mm.get_discr()==AP_LINEXPR_SPARSE); assert(equal(mm,ll)); assert(nn.get_discr()==AP_LINEXPR_SPARSE); assert(equal(nn,ll)); ll[2] = interval(0,1); assert(!equal(mm,ll)); cout << "copy 1/4x0 + [0,1]x2 - 2x3 + [1,2]: " << ll.size() << ", " << ll << endl; cout << "copy 1/4x0 - 2x3 + [1,2]: " << mm.size() << ", " << mm << endl; swap(mm,ll); assert(!equal(mm,ll)); cout << "after swap: " << ll.size() << ", " << ll << endl; cout << "after swap: " << mm.size() << ", " << mm << endl; cout << "const iterator:"; for (linexpr0::const_iterator i = mm.begin();i.valid();++i) cout << " " << i.get_coeff(); cout << endl; for (linexpr0::iterator i = mm.begin();i.valid();++i) i.get_coeff().neg(); cout << "iterate neg -1/4x0 + [-1,0]x2 + 2x3 + [1,2]: " << mm.size() << ", " << mm << endl; ll[4] = frac(1,2); ll[5] = interval(0,1); cout << "get_ [] 1/4x0 - 2x3 + 1/2x4 + [0,1]x5 + [1,2]: " << ll.size() << ", " << ll << endl; ll[6] = 5; ll[7] = 5; ll[1] = 6; cout << "get_ [] 1/4x0 + 6x1 - 2x3 + 1/2x4 + [0,1]x5 + 5x6 + 5x7 + [1,2]: " << ll.size() << ", " << ll << endl; ll[0] = interval(3,3); ll[1] = 0; cout << "before minimize: " << ll.size() << ", " << ll << endl; ll.minimize(); cout << "after minimize: " << ll.size() << ", " << ll << endl; linexpr0 ll2 = linexpr0(ll,dim); cout << "add dims 3x1 - 2x5 + 1/2x6 + [0,1]x7 + 5x8 + 5x9 + [1,2]: " << ll2 << endl; linexpr0 ll3 = ll; ll3.add_dimensions(dim); cout << "add_dims 3x1 - 2x5 + 1/2x6 + [0,1]x7 + 5x8 + 5x9 + [1,2]: " << ll3 << endl; perm = id(8); perm[0] = 3; perm[3] = 0; linexpr0 ll4 = linexpr0(ll,perm); cout << "permute -2x0 + 3x3 + 1/2x4 + [0,1]x5 + 5x6 + 5x7 + [1,2]: " << ll4 << endl; perm2 = -perm; ll4.permute_dimensions(perm2); cout << "permute 3x0 - 2x3 + 1/2x4 + [0,1]x5 + 5x6 + 5x7 + [1,2]: " << ll4 << endl; cout << "hash: " << ll.hash() << endl; printf("print: "); ll.print(); printf("\n"); cout << "print w/ names: " << varname(vector(nms,nms+4)) << ll << varname(vector(0)) << endl; } void test_lincons0() { cout << endl << "lincons0" << endl << "========" << endl << endl; coeff a[] = {1,2,3}; coeff b[] = {4,3,2,1}; cout << "construct: " << lincons0() << endl; cout << "construct 1x0 + 2x1 + 3x2 + 4 = 0: " << lincons0(AP_CONS_EQ,linexpr0(3,a,4)) << endl; cout << "construct 1x0 + 2x1 + 3x2 + 4 >= 0: " << lincons0(AP_CONS_SUPEQ,linexpr0(3,a,4)) << endl; cout << "construct 1x0 + 2x1 + 3x2 + 4 > 0: " << lincons0(AP_CONS_SUP,linexpr0(3,a,4)) << endl; cout << "construct 1x0 + 2x1 + 3x2 + 4 != 0: " << lincons0(AP_CONS_DISEQ,linexpr0(3,a,4)) << endl; cout << "construct 1x0 + 2x1 + 3x2 + 4 = 0 mod 5: " << lincons0(AP_CONS_EQMOD,linexpr0(3,a,4),5) << endl; lincons0 l = lincons0(AP_CONS_EQ,linexpr0(3,a,4)); lincons0 m = l; assert(!l.is_unsat() && l.is_quasilinear() && l.is_linear()); cout << "copy 1x0 + 2x1 + 3x2 + 4 = 0: " << m << endl; lincons0 n = lincons0(m,dimchange(2,0,(ap_dim_t[]){0,2})); assert(!n.is_unsat() && n.is_quasilinear() && n.is_linear()); cout << "dimchange 1x1 + 2x2 + 3x4 + 4 = 0: " << n << endl; lincons0 o = lincons0(m,dimperm(3,(ap_dim_t[]){1,0,2})); assert(!o.is_unsat() && o.is_quasilinear() && o.is_linear()); cout << "dimperm 2x0 + 1x1 + 3x2 + 4 = 0: " << o << endl; cout << "unsat: " << lincons0(unsat()) << endl; l = lincons0(AP_CONS_SUPEQ,linexpr0(4,b,5)); cout << "copy 4x0 + 3x1 + 2x2 + 1x3 + 5 >= 0: " << l << endl; l = unsat(); assert(l.is_unsat()); cout << "unsat: " << l << endl; o = n = lincons0(AP_CONS_EQ,linexpr0(3,a,4)); cout << "chained copy 1x0 + 2x1 + 3x2 + 4 = 0: " << o << endl; o.add_dimensions(dimchange(2,0,(ap_dim_t[]){0,2})); cout << "dimchange 1x1 + 2x2 + 3x4 + 4 = 0: " << o << endl; n.permute_dimensions(dimperm(3,(ap_dim_t[]){1,0,2})); cout << "dimperm 2x0 + 1x1 + 3x2 + 4 = 0: " << n << endl; n.resize(2); cout << "resize 2x0 + 1x1 + 4 = 0: " << n << endl; assert(n.size()==2); assert(n.get_constyp()==AP_CONS_EQ); n.get_constyp()=AP_CONS_SUP; assert(n.get_constyp()==AP_CONS_SUP); cout << "get_constyp 2x0 + 1x1 + 4 > 0: " << n << endl; assert(!n.has_modulo()); assert(n.has_linexpr()); try { n.get_modulo(); assert(0); } catch (invalid_argument& b) {} n.set_modulo(2); n.set_modulo(3); assert(n.has_modulo()); n.get_constyp()=AP_CONS_EQMOD; cout << "set_modulo 2x0 + 1x1 + 4 = 0 mod 3: " << n << endl; assert(n.has_modulo()); assert(n.get_modulo()==3); n.set_linexpr(linexpr0(3,a,4)); cout << "set_linexpr 1x0 + 2x1 + 3x2 + 4 = 0 mod 3: " << n << endl; n.get_linexpr() = linexpr0(4,b,5); cout << "get_linexpr 4x0 + 3x1 + 2x2 + 1x3 + 5 = 0 mod 3: " << n << endl; n.get_linexpr().get_cst() = interval(1,2); assert(!n.is_unsat() && !n.is_linear() && n.is_quasilinear()); cout << "get_linexpr 4x0 + 3x1 + 2x2 + 1x3 + [1,2] = 0 mod 3: " << n << endl; n.get_linexpr()[0] = interval(0,1); assert(!n.is_unsat() && !n.is_linear() && !n.is_quasilinear()); cout << "get_linexpr [0,1]x0 + 3x1 + 2x2 + 1x3 + [1,2] = 0 mod 3: " << n << endl; printf("print: "); n.print(); printf("\n"); string nms[4] ={ "x", "y", "z", "t" }; cout << "print w/ names: " << varname(vector(nms,nms+4)) << n << varname(vector(0)) << endl; } void test_lincons0_array() { cout << endl << "lincons0 array" << endl << "==============" << endl << endl; coeff a[] = {1,2,3}; coeff b[] = {5,3}; lincons0_array t = lincons0_array(2); try { cout << t; assert(0); } catch (invalid_argument& r) { cout << endl; } t[0] = lincons0(AP_CONS_EQ,linexpr0(3,a,4)); t[1] = lincons0(AP_CONS_EQ,linexpr0(2,b,99)); cout << "construct: " << t << endl; lincons0_array u = t; cout << "copy: " << t << endl; lincons0_array v = lincons0_array(u,dimperm(3,(ap_dim_t[]){1,0,2})); cout << "permutation: " << v << endl; lincons0_array w = lincons0_array(u,dimchange(1,1,(ap_dim_t[]){0,2})); cout << "dim change: " << w << endl; lincons0 ar[3] = { lincons0(AP_CONS_EQ,linexpr0(3,a,5)), lincons0(AP_CONS_EQ,linexpr0(2,b,4)), lincons0(AP_CONS_EQMOD,linexpr0(2,b,3),5) }; lincons0_array x = lincons0_array(3,ar); cout << "from array: " << x << endl; vector ve = vector(2); ve[1] = lincons0(AP_CONS_EQ,linexpr0(2,b,99)); lincons0_array y = lincons0_array(ve); cout << "from vector: " << y << endl; y = ar; cout << "from array: " << y << endl; x = ve; cout << "from vector: " << x << endl; w = v; cout << "copy: " << w << endl; w.add_dimensions(dimchange(1,1,(ap_dim_t[]){0,2})); cout << "dim change: " << w << endl; w = v; w.permute_dimensions(dimperm(3,(ap_dim_t[]){1,0,2})); cout << "permutation: " << w << endl; cout << "size: " << w.size() << endl; assert(w.is_linear() && w.is_quasilinear()); w[0] = lincons0(AP_CONS_SUPEQ,linexpr0(2,b,interval(1,88))); b[0] = interval(0,1); cout << "[]: " << w << endl; assert(!w.is_linear() && w.is_quasilinear()); w.get(1) = lincons0(AP_CONS_SUPEQ,linexpr0(2,b,interval(1,88))); cout << "get: " << w << endl; assert(!w.is_linear() && !w.is_quasilinear()); try { w.get(2); assert(0); } catch (out_of_range& b) {} *w.contents() = w[1]; cout << "contents: " << w << endl; vector vv = w; cout << "to vector: " << vv.size() << ": " << vv[0] << "; " << vv[1] << endl; string nms[4] ={ "x", "y", "z", "t" }; cout << "print w/ names: " << varname(vector(nms,nms+4)) << vv << varname(vector(0)) << endl; } void test_generator0() { cout << endl << "generator0" << endl << "==========" << endl << endl; coeff a[] = {1,2,3}; coeff b[] = {4,3,2,1}; cout << "construct: " << generator0() << endl; cout << "construct vert 1x0 + 2x1 + 3x2 + 4: " << generator0(AP_GEN_VERTEX,linexpr0(3,a,4)) << endl; cout << "construct ray 1x0 + 2x1 + 3x2 + 4: " << generator0(AP_GEN_RAY,linexpr0(3,a,4)) << endl; cout << "construct line 1x0 + 2x1 + 3x2 + 4: " << generator0(AP_GEN_LINE,linexpr0(3,a,4)) << endl; cout << "construct modray 1x0 + 2x1 + 3x2 + 4: " << generator0(AP_GEN_RAYMOD,linexpr0(3,a,4)) << endl; cout << "construct modline 1x0 + 2x1 + 3x2 + 4: " << generator0(AP_GEN_LINEMOD,linexpr0(3,a,4)) << endl; generator0 l = generator0(AP_GEN_VERTEX,linexpr0(3,a,4)); generator0 m = l; cout << "copy vert 1x0 + 2x1 + 3x2 + 4: " << m << endl; generator0 n = generator0(m,dimchange(2,0,(ap_dim_t[]){0,2})); cout << "dimchange vert 1x1 + 2x2 + 3x4 + 4: " << n << endl; generator0 o = generator0(m,dimperm(3,(ap_dim_t[]){1,0,2})); cout << "dimperm vert 2x0 + 1x1 + 3x2 + 4: " << o << endl; l = generator0(AP_GEN_RAY,linexpr0(4,b,5)); cout << "copy ray 4x0 + 3x1 + 2x2 + 1x3 + 5: " << l << endl; o = n = generator0(AP_GEN_LINE,linexpr0(3,a,4)); cout << "chained copy line 1x0 + 2x1 + 3x2 + 4: " << o << endl; o.add_dimensions(dimchange(2,0,(ap_dim_t[]){0,2})); cout << "dimchange line 1x1 + 2x2 + 3x4 + 4: " << o << endl; n.permute_dimensions(dimperm(3,(ap_dim_t[]){1,0,2})); cout << "dimperm line 2x0 + 1x1 + 3x2 + 4: " << n << endl; n.resize(2); cout << "resize line 2x0 + 1x1 + 4: " << n << endl; assert(n.size()==2); assert(n.get_gentyp()==AP_GEN_LINE); n.get_gentyp()=AP_GEN_LINEMOD; assert(n.get_gentyp()==AP_GEN_LINEMOD); cout << "get_gentyp modline 2x0 + 1x1 + 4: " << n << endl; assert(n.has_linexpr()); n.set_linexpr(linexpr0(3,a,4)); cout << "set_linexpr modline 1x0 + 2x1 + 3x2 + 4: " << n << endl; n.get_linexpr() = linexpr0(4,b,5); cout << "get_linexpr modline 4x0 + 3x1 + 2x2 + 1x3 + 5: " << n << endl; n.get_linexpr().get_cst() = 2; cout << "get_linexpr modline 4x0 + 3x1 + 2x2 + 1x3 + 2: " << n << endl; n.get_linexpr()[0] = 18; cout << "get_linexpr modline 18x0 + 3x1 + 2x2 + 1x3 + 2: " << n << endl; printf("print: "); n.print(); printf("\n"); string nms[4] ={ "x", "y", "z", "t" }; cout << "print w/ names: " << varname(vector(nms,nms+4)) << n << varname(vector(0)) << endl; } void test_generator0_array() { cout << endl << "generator0 array" << endl << "================" << endl << endl; coeff a[] = {1,2,3}; coeff b[] = {5,3}; generator0_array t = generator0_array(2); try { cout << t; assert(0); } catch (invalid_argument& r) { cout << endl; } t[0] = generator0(AP_GEN_VERTEX,linexpr0(3,a,4)); t[1] = generator0(AP_GEN_VERTEX,linexpr0(2,b,99)); cout << "construct: " << t << endl; generator0_array u = t; cout << "copy: " << t << endl; generator0_array v = generator0_array(u,dimperm(3,(ap_dim_t[]){1,0,2})); cout << "permutation: " << v << endl; generator0_array w = generator0_array(u,dimchange(1,1,(ap_dim_t[]){0,2})); cout << "dim change: " << w << endl; generator0 ar[3] = { generator0(AP_GEN_VERTEX,linexpr0(3,a,5)), generator0(AP_GEN_VERTEX,linexpr0(2,b,4)), generator0(AP_GEN_RAY,linexpr0(2,b,3)) }; generator0_array x = generator0_array(3,ar); cout << "from array: " << x << endl; vector ve = vector(2); ve[1] = generator0(AP_GEN_VERTEX,linexpr0(2,b,99)); generator0_array y = generator0_array(ve); cout << "from vector: " << y << endl; y = ar; cout << "from array: " << y << endl; x = ve; cout << "from vector: " << x << endl; w = v; cout << "copy: " << w << endl; w.add_dimensions(dimchange(1,1,(ap_dim_t[]){0,2})); cout << "dim change: " << w << endl; w = v; w.permute_dimensions(dimperm(3,(ap_dim_t[]){1,0,2})); cout << "permutation: " << w << endl; cout << "size: " << w.size() << endl; w[0] = generator0(AP_GEN_LINE,linexpr0(2,b,88)); b[0] = 99; cout << "[]: " << w << endl; w.get(1) = generator0(AP_GEN_RAY,linexpr0(2,b,88)); cout << "get: " << w << endl; try { w.get(2); assert(0); } catch (out_of_range& b) {} *w.contents() = w[1]; cout << "contents: " << w << endl; vector vv = w; cout << "to vector: " << vv.size() << ": " << vv[0] << "; " << vv[1] << endl; string nms[4] ={ "x", "y", "z", "t" }; cout << "print w/ names: " << varname(vector(nms,nms+4)) << vv << varname(vector(0)) << endl; } void test_texpr0() { cout << endl << "texpr0" << endl << "======" << endl << endl; coeff a[] = {1,2,3}; // constructors cout << "construct 2: " << texpr0(2) << endl; cout << "construct 2L: " << texpr0(2L) << endl; cout << "construct 2.2: " << texpr0(2.2) << endl; cout << "construct mpq(1,2): " << texpr0(mpq_class(1,2)) << endl; cout << "construct mpfr(1.25): " << texpr0(mpfr1) << endl; cout << "construct coeff(2): " << texpr0(coeff(2)) << endl; cout << "construct scalar(2): " << texpr0(scalar(2)) << endl; cout << "construct 1/2: " << texpr0(frac(1,2)) << endl; cout << "construct interval(1,2): " << texpr0(interval(1,2)) << endl; cout << "construct [2.2,3.3]: " << texpr0(interval(2.2,3.3)) << endl; cout << "construct [1/2,3/4]: " << texpr0(interval(frac(1,2),frac(3,4))) << endl; cout << "construct top: " << texpr0(top()) << endl; cout << "construct x2: " << texpr0(dim(2)) << endl; cout << "construct +x2: " << texpr0(+dim(2)) << endl; cout << "construct -x2: " << texpr0(-dim(2)) << endl; cout << "construct x2+2: " << texpr0(dim(2)+2) << endl; cout << "construct x2-2: " << texpr0(dim(2)-2) << endl; cout << "construct x2*2: " << texpr0(dim(2)*2) << endl; cout << "construct x2/2: " << texpr0(dim(2)/2) << endl; cout << "construct x2%2: " << texpr0(dim(2)%2) << endl; cout << "construct sqrt(x2): " << texpr0(sqrt(dim(2))) << endl; cout << "construct float -x2: " << texpr0(neg(dim(2),AP_RTYPE_SINGLE)) << endl; cout << "construct float x2+2: " << texpr0(add(dim(2),2,AP_RTYPE_SINGLE)) << endl; cout << "construct float x2-2: " << texpr0(sub(dim(2),2,AP_RTYPE_SINGLE)) << endl; cout << "construct float x2*2: " << texpr0(mul(dim(2),2,AP_RTYPE_SINGLE)) << endl; cout << "construct float x2/2: " << texpr0(div(dim(2),2,AP_RTYPE_SINGLE)) << endl; cout << "construct float x2%2: " << texpr0(mod(dim(2),2,AP_RTYPE_SINGLE)) << endl; cout << "construct float sqrt(x2): " << texpr0(sqrt(dim(2),AP_RTYPE_SINGLE)) << endl; cout << "construct float cast(x2): " << texpr0(cast(dim(2),AP_RTYPE_SINGLE)) << endl; cout << "construct floor(x2): " << texpr0(floor(dim(2))) << endl; cout << "construct ceil(x2): " << texpr0(ceil(dim(2))) << endl; cout << "construct trunc(x2): " << texpr0(trunc(dim(2))) << endl; cout << "construct linexpr: " << texpr0(linexpr0(3,a,4)) << endl; texpr0 x = 2+3*dim(0); texpr0 y = x; cout << "copy x=2+3*x0: " << y << endl; cout << "construct (x+x)/(x*x): " << (x+x)/(x*x) << endl; cout << "construct x0 + 2: " << dim(0)+2 << endl; cout << "construct x0 + 2L: " << dim(0)+2L << endl; cout << "construct x0 + 2.2: " << dim(0)+2.2 << endl; cout << "construct x0 + mpq(1,2): " << dim(0)+mpq_class(1,2) << endl; cout << "construct x0 + mpfr(1.25): " << dim(0)+mpfr1 << endl; cout << "construct x0 + coeff(2): " << dim(0)+coeff(2) << endl; cout << "construct x0 + scalar(2): " << dim(0)+scalar(2) << endl; cout << "construct x0 + 1/2: " << dim(0)+frac(1,2) << endl; cout << "construct x0 + interval(1,2): " << dim(0)+interval(1,2) << endl; cout << "construct x0 + [2,3]: " << dim(0)+texpr0::builder(2,3) << endl; cout << "construct x0 + [2L,3L]: " << dim(0)+texpr0::builder(2L,3L) << endl; cout << "construct x0 + [2.2,3.3]: " << dim(0)+texpr0::builder(2.2,3.3) << endl; cout << "construct x0 + [1/2,3/4]: " << dim(0)+texpr0::builder(frac(1,2),frac(3,4)) << endl; cout << "construct x0 + top: " << dim(0)+top() << endl; cout << "construct x0 + x2: " << dim(0)+dim(2) << endl; cout << "construct x0 + linexpr: " << dim(0)+texpr0(linexpr0(3,a,4)) << endl; try { unary(AP_TEXPR_ADD,2); assert(0); } catch (invalid_argument& a) {} try { binary(AP_TEXPR_NEG,1,2); assert(0); } catch (invalid_argument& a) {} // assignments y = 2; cout << "assign 2: " << y << endl; y = 2L; cout << "assign 2L: " << y << endl; y = 2.2; cout << "assign 2.2: " << y << endl; y = mpq_class(1,2); cout << "assign mpq(1,2): " << y << endl; y = mpfr1; cout << "assign mpfr(1.25): " << y << endl; y = coeff(2); cout << "assign coeff(2): " << y << endl; y = scalar(2); cout << "assign scalar(2): " << y << endl; y = interval(1,2); cout << "assign interval(1,2): " << y << endl; y = top(); cout << "assign top: " << y << endl; y = dim(2); cout << "assign x2: " << y << endl; y = linexpr0(3,a,4); cout << "assign linexpr: " << y << endl; y = x; cout << "assign x: " << y << endl; y = x+1; cout << "assign x+1: " << y << endl; x = x*x; cout << "assign x*x: " << x << endl; x = y = sqrt(dim(0)+1); cout << "chained assign sqrt(x0+1): " << x << "; " << y << endl; // dimensions dimchange dimc = dimchange(1,1,(ap_dim_t[]){0,2}); dimperm perm = dimperm(3,(ap_dim_t[]){1,0,2}); x = dim(0)/dim(1); cout << "add dim x1/x2: " << texpr0(x,dimc) << endl; cout << "del dim ]-oo;+oo[/x0: " << texpr0(x,dimc,false) << endl; cout << "dim perm x1/x0: " << texpr0(x,perm) << endl; x.add_dimensions(dimc); cout << "add dim x1/x2: " << x << endl; x.remove_dimensions(-dimc); cout << "del dim x0/x1: " << x << endl; x.permute_dimensions(perm); cout << "dim perm x1/x0: " << x << endl; y = texpr0(x,perm)+texpr0(x,dimc,false); cout << "dim mix x0/x1+x0/]-oo;+oo[: " << y << endl; // access && tests x = 2; assert(x.max_dim()==0); assert(x.depth()==0); assert(x.size()==0); assert(x.equal(texpr0(2))); assert(!x.equal(texpr0(3)) && !x.equal(texpr0(dim(3))) && !x.equal(dim(4)+dim(3))); assert(x.root().get_discr()==AP_TEXPR_CST); assert(x.is_interval_cst() && x.is_interval_linear() && x.is_interval_polynomial() && x.is_interval_polyfrac() && x.is_scalar()); try { x.root().get_dim(); assert(0); } catch (bad_discriminant& b) {} try { x.root().get_op(); assert(0); } catch (bad_discriminant& b) {} try { x.root().get_rtype(); assert(0); } catch (bad_discriminant& b) {} try { x.root().get_rdir(); assert(0); } catch (bad_discriminant& b) {} try { x.root().left(); assert(0); } catch (bad_discriminant& b) {} try { x.root().right(); assert(0); } catch (bad_discriminant& b) {} x.root().get_coeff() = interval(1,2); cout << "get_coeff [1,2]: " << x << endl; assert(!x.equal(texpr0(2)) && x.equal(texpr0(interval(1,2)))); assert(x.is_interval_cst() && x.is_interval_linear() && x.is_interval_polynomial() && x.is_interval_polyfrac() && !x.is_scalar()); x = dim(2); assert(x.max_dim()==2); assert(x.depth()==0); assert(x.size()==0); assert(x.equal(texpr0(dim(2)))); assert(!x.equal(texpr0(3)) && !x.equal(texpr0(dim(3))) && !x.equal(texpr0(dim(4)+dim(3)))); assert(x.root().get_discr()==AP_TEXPR_DIM); assert(!x.is_interval_cst() && x.is_interval_linear() && x.is_interval_polynomial() && x.is_interval_polyfrac() && x.is_scalar()); try { x.root().get_coeff(); assert(0); } catch (bad_discriminant& b) {} try { x.root().get_op(); assert(0); } catch (bad_discriminant& b) {} try { x.root().get_rtype(); assert(0); } catch (bad_discriminant& b) {} try { x.root().get_rdir(); assert(0); } catch (bad_discriminant& b) {} try { x.root().left(); assert(0); } catch (bad_discriminant& b) {} try { x.root().right(); assert(0); } catch (bad_discriminant& b) {} x.root().get_dim() = 3; cout << "get_dim 3: " << x << endl; assert(!x.equal(texpr0(dim(2))) && x.equal(texpr0(dim(3)))); x = add(dim(0),1,AP_RTYPE_SINGLE,AP_RDIR_NEAREST); assert(!x.is_interval_cst() && !x.is_interval_linear() && !x.is_interval_polynomial() && !x.is_interval_polyfrac() && x.is_scalar()); assert(x.depth()==1); assert(x.size()==1); assert(x.equal(texpr0(add(dim(0),1,AP_RTYPE_SINGLE,AP_RDIR_NEAREST)))); assert(!x.equal(texpr0(3)) && !x.equal(texpr0(dim(3))) && !x.equal(texpr0(dim(4)+dim(3)))); assert(x.root().get_discr()==AP_TEXPR_NODE); try { x.root().get_coeff(); assert(0); } catch (bad_discriminant& b) {} try { x.root().get_dim(); assert(0); } catch (bad_discriminant& b) {} assert(x.root().get_op()==AP_TEXPR_ADD); assert(is_binop(x.root().get_op())); assert(x.root().get_rtype()==AP_RTYPE_SINGLE); assert(x.root().get_rdir()==AP_RDIR_NEAREST); assert(x.root().left().equal(texpr0(dim(0)))); assert(x.root().right().equal(texpr0(1))); x.root().get_op()=AP_TEXPR_SUB; x.root().get_rtype()=AP_RTYPE_DOUBLE; x.root().get_rdir()=AP_RDIR_ZERO; x.root().left()=2; x.root().right()=dim(1); cout << "get_op rtype rdir argA argB: " << x << endl; assert(!x.equal(add(dim(0),1,AP_RTYPE_SINGLE,AP_RDIR_NEAREST))); assert(x.equal(sub(2,dim(1),AP_RTYPE_DOUBLE,AP_RDIR_ZERO))); x.root().get_rtype()=AP_RTYPE_REAL; assert(!x.is_interval_cst() && x.is_interval_linear() && x.is_interval_polynomial() && x.is_interval_polyfrac() && x.is_scalar()); x.root().get_op()=AP_TEXPR_MUL; assert(!x.is_interval_cst() && x.is_interval_linear() && x.is_interval_polynomial() && x.is_interval_polyfrac() && x.is_scalar()); x.root().get_op()=AP_TEXPR_DIV; assert(!x.is_interval_cst() && !x.is_interval_linear() && !x.is_interval_polynomial() && x.is_interval_polyfrac() && x.is_scalar()); x = sqrt(dim(1)+5,AP_RTYPE_SINGLE,AP_RDIR_NEAREST); assert(!x.is_interval_cst() && !x.is_interval_linear() && !x.is_interval_polynomial() && !x.is_interval_polyfrac() && x.is_scalar()); assert(x.depth()==2); assert(x.max_dim()==1); assert(!x.equal(texpr0(3)) && !x.equal(texpr0(dim(3))) && !x.equal(texpr0(dim(4)+dim(3)))); assert(x.equal(sqrt(dim(1)+5,AP_RTYPE_SINGLE,AP_RDIR_NEAREST))); assert(x.root().get_discr()==AP_TEXPR_NODE); try { x.root().get_coeff(); assert(0); } catch (bad_discriminant& b) {} try { x.root().get_dim(); assert(0); } catch (bad_discriminant& b) {} assert(x.root().get_op()==AP_TEXPR_SQRT); assert(is_unop(x.root().get_op())); assert(x.root().get_rtype()==AP_RTYPE_SINGLE); assert(x.root().get_rdir()==AP_RDIR_NEAREST); assert(x.root().left().left().equal(texpr0(dim(1)))); assert(x.root().left().right().equal(texpr0(5))); try { x.root().right(); assert(0); } catch (out_of_range& b) {} cout << "get: " << x << endl; x.root().get_op()=AP_TEXPR_CAST; x.root().get_rtype()=AP_RTYPE_DOUBLE; x.root().get_rdir()=AP_RDIR_ZERO; x.root().left()=2+dim(3); cout << "set: " << x << endl; assert(!x.equal(sqrt(dim(3),AP_RTYPE_SINGLE,AP_RDIR_NEAREST))); assert(x.equal(cast(2+dim(3),AP_RTYPE_DOUBLE,AP_RDIR_ZERO))); assert(x.size()==2); assert(x.depth()==2); assert(x.max_dim()==3); x = dim(0)+dim(5)+dim(2); assert(x.has_dim(0) && !x.has_dim(1) && x.has_dim(2) && !x.has_dim(3) && !x.has_dim(4) && x.has_dim(5) && !x.has_dim(6)); vector dm = x.dimlist(); assert(dm.size()==3 && dm[0]==0 && dm[1]==2 && dm[2]==5); cout << x << endl; texpr0 z(x.root().left()); cout << "iterator -> texpr0 x0+x5: " << z << endl; z = x.root().right(); cout << "iterator assign x2: " << z << endl; cout << "construct from iterators x0+x5-x2: " << x.root().left() - x.root().right() << endl; // substitutions x = sqrt(dim(0)+2*dim(1)*dim(1)); cout << "subst: " << texpr0(x,0,dim(0)+1) << endl; assert(x.equal(sqrt(dim(0)+2*dim(1)*dim(1)))); x.substitute(1,sqrt(dim(0))+1); cout << "subst: " << x << endl; assert(x.equal(sqrt(dim(0)+2*(sqrt(dim(0))+1)*(sqrt(dim(0))+1)))); // hash & print x = sqrt(dim(0)+2*dim(1)*dim(1)); cout << "hash: " << x.hash() << endl; printf("print: "); x.print(); printf("\n"); string nms[4] ={ "x", "y", "z", "t" }; cout << "print w/ names: " << varname(vector(nms,nms+4)) << x << varname(vector(0)) << endl; } void test_tcons0() { cout << endl << "tcons0" << endl << "======" << endl << endl; coeff a[] = {1,2,3}; lincons0 ll = lincons0(AP_CONS_EQ,linexpr0(3,a,4)); try { cout << tcons0(); assert(0); } catch (invalid_argument& r) {} cout << "construct x0 + 1 = 0: " << tcons0(AP_CONS_EQ,dim(0)+1) << endl; cout << "construct floor(x0+2) >= 0: " << tcons0(AP_CONS_SUPEQ,floor(dim(0)+2)) << endl; cout << "construct x0*x1 > 0: " << tcons0(AP_CONS_SUP,dim(0)*dim(1)) << endl; cout << "construct [-1,1]*x0 != 0: " << tcons0(AP_CONS_DISEQ,interval(-1,1)*dim(0)) << endl; cout << "construct x0/x1 = 0 mod 5: " << tcons0(AP_CONS_EQMOD,dim(0)/dim(1),5) << endl; cout << "from lincons 1x0+2x1+3x2+4 = 0: " << tcons0(ll) << endl; cout << "construct x0 >= x2+1: " << (dim(0)>=dim(2)+1) << endl; cout << "construct x0 <= x2+1: " << (dim(0)<=dim(2)+1) << endl; cout << "construct x0 > x2+1: " << (dim(0)>dim(2)+1) << endl; cout << "construct x0 < x2+1: " << (dim(0) 0: " << n << endl; assert(!n.has_modulo()); assert(n.has_texpr()); try { n.get_modulo(); assert(0); } catch (invalid_argument& b) {} n.set_modulo(2); n.set_modulo(3); assert(n.has_modulo()); n.get_constyp()=AP_CONS_EQMOD; cout << "set_modulo x1 * x2 + 2 = 0 mod 3: " << n << endl; assert(!n.is_interval_cst() && !n.is_interval_linear() && l.is_interval_polynomial() && n.is_interval_polyfrac() && n.is_scalar()); assert(n.has_modulo()); assert(n.get_modulo()==3); n.set_texpr(sqrt(dim(0)+1)); cout << "set_texpr sqrt(x0+1) = 0 mod 3: " << n << endl; assert(!n.is_interval_cst() && !n.is_interval_linear() && !n.is_interval_polynomial() && !n.is_interval_polyfrac() && n.is_scalar()); n.get_texpr() = dim(0)/dim(1)+5; cout << "get_texpr x0/x1+5 = 0 mod 3: " << n << endl; assert(!n.is_interval_cst() && !n.is_interval_linear() && !n.is_interval_polynomial() && n.is_interval_polyfrac() && n.is_scalar()); n.get_texpr().left().left() = interval(0,1); cout << "get_texpr [0,1]/x1+5 = 0 mod 3: " << n << endl; assert(!n.is_interval_cst() && !n.is_interval_linear() && !n.is_interval_polynomial() && n.is_interval_polyfrac() && !n.is_scalar()); printf("print: "); n.print(); printf("\n"); string nms[4] ={ "x", "y", "z", "t" }; cout << "print w/ names: " << varname(vector(nms,nms+4)) << n << varname(vector(0)) << endl; } void test_tcons0_array() { cout << endl << "tcons0 array" << endl << "============" << endl << endl; coeff a[] = {1,2,3}; coeff b[] = {5,3}; tcons0_array t = tcons0_array(2); try { cout << t; assert(0); } catch (invalid_argument& r) { cout << endl; } t[0] = tcons0(AP_CONS_SUPEQ,sqrt(dim(0)+15*dim(2))); t[1] = tcons0(AP_CONS_EQ,interval(2,5)); cout << "construct: " << t << endl; tcons0_array u = t; cout << "copy: " << t << endl; tcons0_array v = tcons0_array(u,dimperm(3,(ap_dim_t[]){1,0,2})); cout << "permutation: " << v << endl; tcons0_array w = tcons0_array(u,dimchange(1,1,(ap_dim_t[]){0,2})); cout << "add dim: " << w << endl; tcons0_array ww = tcons0_array(u,dimchange(1,1,(ap_dim_t[]){0,2}),false); cout << "rem dim: " << ww << endl; tcons0 ar[3] = { tcons0(AP_CONS_SUPEQ,dim(0)*dim(1)*dim(2)), tcons0(AP_CONS_EQ,dim(0)%dim(1)), tcons0(AP_CONS_EQMOD,interval(1,2)*dim(0),5) }; tcons0_array x = tcons0_array(3,ar); cout << "from array: " << x << endl; vector ve = vector(2); ve[0] = tcons0(AP_CONS_EQ,0); ve[1] = tcons0(AP_CONS_EQ,1-dim(5)); tcons0_array y = tcons0_array(ve); cout << "from vector: " << y << endl; y = ar; cout << "from array: " << y << endl; x = ve; cout << "from vector: " << x << endl; w = u; cout << "copy: " << w << endl; w.add_dimensions(dimchange(1,1,(ap_dim_t[]){0,2})); cout << "add dim: " << w << endl; w = u; w.remove_dimensions(dimchange(1,1,(ap_dim_t[]){0,2})); cout << "del dim: " << w << endl; w = u; w.permute_dimensions(dimperm(3,(ap_dim_t[]){1,0,2})); cout << "permutation: " << w << endl; cout << "size: " << w.size() << endl; assert(!w.is_interval_linear()); w[0] = tcons0(AP_CONS_SUPEQ,dim(1)*5+dim(2)); b[0] = interval(0,1); cout << "[]: " << w << endl; assert(w.is_interval_linear()); w.get(1) = tcons0(AP_CONS_SUPEQ,dim(0)*dim(2)); cout << "get: " << w << endl; try { w.get(2); assert(0); } catch (out_of_range& b) {} *w.contents() = w[1]; cout << "contents: " << w << endl; vector vv = w; cout << "to vector: " << vv.size() << ": " << vv[0] << "; " << vv[1] << endl; // from lincons0_array lincons0_array lt = lincons0_array(2); lt[0] = lincons0(AP_CONS_EQ,linexpr0(3,a,4)); lt[1] = lincons0(AP_CONS_EQ,linexpr0(2,b,99)); tcons0_array A = lt; cout << "from lincons0_array: " << A << endl; v = lt; cout << "from lincons0_array: " << v << endl; // print printf("print: "); w.print(); printf("\n"); string nms[4] ={ "x", "y", "z", "t" }; cout << "print w/ names: " << varname(vector(nms,nms+4)) << w << varname(vector(0)) << endl; } void test_var() { cout << endl << "var" << endl << "===" << endl << endl; var v1 = "v1"; printf("print: "); v1.print(); printf("\n"); cout << "from char*: " << v1 << endl; var v2 = string("v2"); cout << "from string: " << v2 << endl; var v3 = v2; cout << "copy constructor: " << v3 << endl; v1 = v2; cout << "copy assignment: " << v1 << endl; v1 = "aa"; cout << "char* assignment: " << v1 << endl; v1 = string("aa"); cout << "string assignment: " << v1 << endl; char* s = v1; cout << "to char*: " << s << endl; free(s); string ss = v1; cout << "to string: " << ss << endl; v1 = "a"; v2 = "a"; v3 = "b"; assert(v1==v2 && !(v1!=v2) && v1<=v2 && v1>=v2 && !(v1v2)); assert(v1!=v3 && !(v1==v3) && v1<=v3 && !(v1>=v3) && v1v3)); } void test_environment() { cout << endl << "environment" << endl << "===========" << endl << endl; var ai[3] = { "i1","i3","i2" }; var af[3] = { "f1","f3","f2" }; var ag[2] = { "f1","x" }; var ah[2] = { "j","h" }; vector vi = vector(2,"j"); vi[1] = "h"; vector vf = vector(2,"g"); vf[1] = "e"; vector vn = vector(); cout << "empty: " << endl << environment() << endl; cout << "from vector: " << endl << environment(vi,vf) << endl; cout << "from array: " << endl << environment(ai,3,af,3) << endl; environment e(vi,vf); { environment f(ai,3,af,3); e = f; } cout << "copy assignment: " << endl << e << endl; environment* pf = new environment(ai,3,af,3); environment f = *pf; delete pf; cout << "copy constructor: " << endl << f << endl; e = environment(vi,vn); try { e.add(vi,vn); assert(0); } catch (invalid_argument& c) {} f = e.add(ai,3,af,3); cout << "add array:" << endl << f << endl; try { f.remove(vf); assert(0); } catch (invalid_argument& c) {} cout << "del vector:" << endl << f.remove(vi) << endl; e = environment(ai,3,af,3); try { e.add(ai,3,NULL,0); assert(0); } catch (invalid_argument& c) {} f = e.add(vi,vn); cout << "add vector:" << endl << f << endl; try { f.remove(ag,2); assert(0); } catch (invalid_argument& c) {} cout << "del array:" << endl << f.remove(ai,3) << endl; dimperm p; e = environment(vi,vn); try { e.add(vi,vn,p); assert(0); } catch (invalid_argument& c) {} cout << "add vector w/ dimperm:" << endl << e.add(ai,3,af,3,p) << p << endl; e = environment(ai,3,af,3); try { e.add(ai,3,NULL,0,p); assert(0); } catch (invalid_argument& c) {} cout << "add vector w/ dimperm:" << endl << e.add(vi,vn,p) << p << endl; e = environment(ai,3,af,3); vector< pair > vr(2,pair("i2","a")); vr[1].first = "f2"; vr[1].second = "z"; try { environment(ai,3,NULL,0).rename(vr); } catch (invalid_argument& c) {} f = e.rename(vr); cout << "rename vector:" << endl << f << endl; var ar1[2] = { "i2", "f2" }, ar2[2] = { "a", "z" }; try { environment(ai,3,NULL,0).rename(ar1,ar2,2); } catch (invalid_argument& c) {} f = e.rename(ar1,ar2,2); cout << "rename array:" << endl << f << endl; try { environment(ai,3,NULL,0).rename(vr,p); } catch (invalid_argument& c) {} f = e.rename(vr,p); cout << "rename vector w/ dimperm:" << endl << f << p << endl; try { environment(ai,3,NULL,0).rename(ar1,ar2,2,p); } catch (invalid_argument& c) {} f = e.rename(ar1,ar2,2,p); cout << "rename array w/ dimperm:" << endl << f << p << endl; dimchange x,y; e = environment(ai,3,af,3); f = environment(ah,2,ag,2); try { lce(e,environment(ag,2,ah,2)); assert(0); } catch (invalid_argument& c) {} cout << "lub:" << endl << lce(e,f) << endl; try { lce(e,environment(ag,2,ah,2),x,y); assert(0); } catch (invalid_argument& c) {} cout << "lub w/ dimchange:" << endl << lce(e,f,x,y); cout << x << y << endl; vector ve(2); vector vd(2); ve[0] = environment(ai,3,af,3); ve[1] = environment(ah,2,ag,2); cout << "n-ary vector lce:" << endl << lce(ve) << endl; cout << "n-ary vector lce w/ dimchange:" << endl << lce(ve,vd); for (size_t i=0;i<2;i++) cout << vd[i]; cout << endl; environment ae[2] = { environment(ai,3,af,3), environment(ah,2,ag,2) }; dimchange ad[2]; cout << "n-ary array lce:" << endl << lce(ae,2) << endl; cout << "n-ary array lce w/ dimchange:" << endl << lce(ae,ad,2); for (size_t i=0;i<2;i++) cout << ad[i]; cout << endl; e = environment(ai,3,af,2); assert(e.intdim()==3 && e.realdim()==2); assert(e.contains("i1") && e.contains("f3") && !e.contains("f2")); assert(e[1]==var("i2") && !(e[1]==var("i3")) && e[1]!=var("i3") && !(e[1]!=var("i2"))); assert(e["i1"]==0 && e["i2"]==1); try { e["i4"]; assert(0); } catch (invalid_argument &c) {}; assert(e.get_var(1)==var("i2") && !(e.get_var(1)==var("i3")) && e.get_var(1)!=var("i3") && !(e.get_var(1)!=var("i2"))); assert(e.get_dim("i1")==0 && e.get_dim("i2")==1); try { e.get_dim("i4"); assert(0); } catch (invalid_argument &c) {}; try { e.get_var(5); assert(0); } catch (out_of_range &c) {}; vector vv = e.get_vars(); cout << "iterator: "; for (size_t i=0;i=e && !(e>=f) && f>=e); assert(cmp(e,e)==0 && cmp(e,f)==-1 && cmp(f,e)==1); cout << "dimchange to super:" << endl << get_dimchange(e,f) << endl; f = environment(ai,2,af,3); assert(e!=f && !(e==f) && !(e<=f) && !(e>=f)); assert(cmp(e,f)==2); try { get_dimchange(e,f); assert(0); } catch (invalid_argument& c) {}; printf("print:\n"); environment(vi,vf).print(); printf("\n"); } void test_linexpr1() { cout << endl << "linexpr1" << endl << "========" << endl << endl; var ai[] = { "i1","i3","i2" }; var af[] = { "f1","f3","f2" }; environment env(ai,2,af,2); environment env2(ai,3,af,3); coeff c[] = {1,2,3,4,5,6}; linexpr0 e(3,c,4); cout << "from exp: " << linexpr1(env,e) << endl; cout << "from exp: " << linexpr1(env2,e) << endl; cout << "empty: " << linexpr1(env) << endl; linexpr1 x(env,e); linexpr1 y = x; linexpr1 z(x,env2); //assert(!x.get_environment().contains("f2")); //assert(z.get_environment().contains("f2")); cout << endl << "copy constructor:" << endl << y.get_environment() << y.get_linexpr0() << endl << y << endl; cout << endl << "copy to super:" << endl << z.get_environment() << z.get_linexpr0() << endl << z << endl; x=z; cout << "assignment: " << x << endl; assert(!y.get_environment().contains("f2")); y.extend_environment(env2); assert(y.get_environment().contains("f2")); cout << "to supper: " << endl << y << endl; y.extend_environment(env2); cout << "to supper: " << y << endl << endl; x = linexpr1(env2,e); try { x.extend_environment(env); assert(0); } catch (invalid_argument& c) {} x = linexpr1(env,e); y.get_linexpr0() = linexpr0(4,c,4); cout << "linepxr0: " << y.get_linexpr0() << endl; cout << "linepxr1: " << y << endl; cout << "size: " << y.size() << endl; cout << "discr: " << y.get_discr() << endl; cout << "cst: " << y.get_cst() << endl; cout << "[i2]: " << y["i2"] << endl; y["i3"] = -3; y.get_cst() = 99; cout << "set i3 & cst: " << y << endl; try { y["z"]; assert(0); } catch (invalid_argument& c) {} assert(!y.is_integer() && !y.is_real()); assert(y.is_linear() && y.is_quasilinear() && y.get_type()==AP_LINEXPR_LINEAR); y.get_cst() = coeff(0,1); assert(!y.is_linear() && y.is_quasilinear() && y.get_type()==AP_LINEXPR_QUASILINEAR); y["i3"] = coeff(0,1); assert(!y.is_linear() && !y.is_quasilinear() && y.get_type()==AP_LINEXPR_INTLINEAR); cout << "const iterator:"; for (linexpr1::const_iterator i = y.begin();i.valid();++i) cout << " " << i.get_coeff(); cout << endl; for (linexpr1::iterator i = y.begin();i.valid();++i) { cout << i.get_dim() << ": " << i.get_var() << " = " << i.get_coeff() << endl; i.get_coeff().neg(); } cout << "after negation: " << y << endl; y.get_cst() = coeff(2,2); y["i3"] = 0; cout << "before minimize: " << y << endl; y.minimize(); cout << "after minimize: " << y << endl; x.print(); printf("\n"); } void test_lincons1() { cout << endl << "lincons1" << endl << "========" << endl << endl; coeff a[] = {1,2,3,4}; var ai[] = { "i1","i3","i2" }; var af[] = { "f1","f3","f2" }; environment env(ai,2,af,2); environment env2(ai,3,af,3); linexpr0 e0(3,a,4); linexpr0 f0(3,a+1,45); linexpr1 e1(env,e0); lincons0 c0(AP_CONS_EQ,e0); cout << "construct empty: " << lincons1(env) << endl; cout << "construct from lincons0: " << lincons1(env,c0) << endl; cout << "construct from linexpr1: " << lincons1(AP_CONS_SUPEQ,e1) << endl; cout << "construct from linexpr1: " << lincons1(AP_CONS_EQMOD,e1,5) << endl; cout << "construct unsat: " << lincons1(env,unsat()) << endl; lincons1 c1(AP_CONS_DISEQ,e1); assert(c1.has_linexpr() && !c1.has_modulo()); lincons1 cc1(c1); cout << "construct copy: " << cc1 << endl; cout << "construct extend: " << lincons1(cc1,env2) << endl << lincons1(cc1,env2).get_environment(); c1 = lincons1(AP_CONS_EQMOD,e1,99); assert(c1.has_linexpr() && c1.has_modulo()); cout << "assign copy: " << c1 << endl; assert(!c1.is_unsat()); c1 = unsat(); assert(c1.is_unsat()); assert(c1.is_linear() && c1.is_quasilinear()); cout << "assign unsat: " << c1 << endl; c1 = lincons1(AP_CONS_EQMOD,e1); try { c1.get_modulo(); assert(0); } catch (invalid_argument& c) {} try { cout << c1; assert(0); } catch (invalid_argument& c) {} assert(!c1.has_modulo()); c1.set_modulo(69); assert(c1.has_modulo()); cout << "set modulo: " << c1 << endl; cout << "get modulo: " << c1.get_modulo() << endl; c1.get_modulo() = 70; cout << "set modulo: " << c1 << endl; cout << "get linexpr : " << c1.get_linexpr() << endl; c1.set_linexpr(linexpr1(env,f0)); cout << "set linexpr : " << c1 << endl; c1 = lincons1(AP_CONS_EQMOD,e1,99); c1.extend_environment(env2); cout << "extend environment: " << c1 << endl; try { c1.extend_environment(env); assert(0); } catch (invalid_argument& c) {} cout << "get lincons0: " << c1.get_lincons0() << endl; c1.get_lincons0() = c0; cout << "set lincons0: " << c1 << endl; cout << "size: " << c1.size() << endl; cout << "get constyp: " << c1.get_constyp() << endl; c1.get_constyp() = AP_CONS_SUPEQ; cout << "set constyp: " << c1 << endl; cout << "get cst: " << c1.get_cst() << endl; c1.get_cst() = 101; cout << "set cst: " << c1 << endl; cout << "get [f3]: " << c1["f3"] << endl; c1["f2"] = interval(-2,3); cout << "set [f2]: " << c1["f2"] << endl; assert(!c1.is_linear() && !c1.is_quasilinear()); printf("print: "); c1.print(); printf("\n"); } void test_lincons1_array() { cout << endl << "lincons1 array" << endl << "==============" << endl << endl; var ai[] = { "i1","i3","i2" }; var af[] = { "f1","f3","f2" }; environment env(ai,2,af,2); environment env2(ai,3,af,3); coeff a[] = {1,2,3}; coeff b[] = {5,3}; try { cout << lincons1_array(env,2); assert(0); } catch (invalid_argument& r) { cout << endl; } lincons0_array t0(2); t0[0] = lincons0(AP_CONS_EQ,linexpr0(3,a,4)); t0[1] = lincons0(AP_CONS_EQ,linexpr0(2,b,99)); lincons1_array t1(env,t0); cout << "construct from lincons0_array:" << endl << t1 << endl; lincons1_array tt1 = t1; cout << "construct copy:" << endl << tt1 << endl; cout << "construct extend:" << endl << lincons1_array(tt1,env2) << endl << lincons1_array(tt1,env2).get_environment(); lincons1 ac[] = { lincons1(env,t0[0]), lincons1(env,t0[1]), lincons1(env,t0[0]) }; cout << "construct from array:" << endl << lincons1_array(3,ac) << endl; vector vc(3,lincons1(env,t0[1])); vc[0] = lincons1(env,t0[1]); vc[1] = lincons1(env,t0[0]); vc[2] = lincons1(env,t0[1]); cout << "construct from vector:" << endl << lincons1_array(vc) << endl; tt1 = lincons1_array(vc); cout << "assign copy:" << endl << tt1 << endl; tt1 = ac; cout << "assign from array:" << endl << tt1 << endl; tt1 = vc; cout << "assign from vector:" << endl << tt1 << endl; cout << "size: " << tt1.size() << endl; tt1.resize(2); cout << "resize:" << endl << tt1 << endl; cout << "size: " << tt1.size() << endl; tt1.extend_environment(env2); cout << "extend:" << endl << tt1 << endl << tt1.get_environment(); cout << "get lincons0 array:" << endl << tt1.get_lincons0_array() << endl; tt1.get_lincons0_array() = t0; cout << "set lincons0 array:" << endl << tt1 << endl; cout << "get: " << tt1.get(0) << endl; tt1.set(0,lincons1(env,lincons0(AP_CONS_SUPEQ,linexpr0(2,b,181)))); cout << "set: " << endl << tt1 << endl; try { tt1.get(2); assert(0); } catch (out_of_range& c) {} try { tt1.set(2,vc[0]); assert(0); } catch (out_of_range& c) {} tt1.resize(3); tt1.get(2); assert(!tt1.get(2).has_linexpr()); t1 = tt1; assert(!t1.get(2).has_linexpr()); tt1.set(2,vc[0]); assert(tt1.get(2).has_linexpr()); assert(!t1.get(2).has_linexpr()); vector vv = tt1; cout << "to vector: " << vv.size() << endl; for (size_t i=0;i vc(3,generator1(env,t0[1])); vc[0] = generator1(env,t0[1]); vc[1] = generator1(env,t0[0]); vc[2] = generator1(env,t0[1]); cout << "construct from vector:" << endl << generator1_array(vc) << endl; tt1 = generator1_array(vc); cout << "assign copy:" << endl << tt1 << endl; tt1 = ac; cout << "assign from array:" << endl << tt1 << endl; cout << "size: " << tt1.size() << endl; tt1.resize(2); cout << "resize:" << endl << tt1 << endl; cout << "size: " << tt1.size() << endl; tt1 = vc; cout << "assign from vector:" << endl << tt1 << endl; tt1.extend_environment(env2); cout << "extend:" << endl << tt1 << endl << tt1.get_environment(); cout << "get generator0 array:" << endl << tt1.get_generator0_array() << endl; tt1.get_generator0_array() = t0; cout << "set generator0 array:" << endl << tt1 << endl; cout << "get: " << tt1.get(0) << endl; tt1.set(0,generator1(env,generator0(AP_GEN_LINE,linexpr0(2,b,181)))); cout << "set: " << endl << tt1 << endl; try { tt1.get(2); assert(0); } catch (out_of_range& c) {} try { tt1.set(2,vc[0]); assert(0); } catch (out_of_range& c) {} tt1.resize(3); tt1.get(2); assert(!tt1.get(2).has_linexpr()); t1 = tt1; assert(!t1.get(2).has_linexpr()); tt1.set(2,vc[0]); assert(tt1.get(2).has_linexpr()); assert(!t1.get(2).has_linexpr()); vector vv = tt1; cout << "to vector: " << vv.size() << endl; for (size_t i=0;i= 0: " << tcons1(AP_CONS_SUPEQ,floor(texpr1(env,"i1")+texpr1(env,2))) << endl; cout << "construct i1*f1 > 0: " << tcons1(AP_CONS_SUP,texpr1(env,"i1")*texpr1(env,"f1")) << endl; cout << "construct [-1,1]*i1 != 0: " << tcons1(AP_CONS_DISEQ,texpr1(env,interval(-1,1))*texpr1(env,"i1")) << endl; cout << "construct i1/f1 = 0 mod 5: " << tcons1(AP_CONS_EQMOD,texpr1(env,"i1")/texpr1(env,"f1"),5) << endl; cout << "from lincons 1i1+2i3+3f1+4 = 0: " << tcons1(ll) << endl; cout << "construct i1 >= f1+1: " << (texpr1(env,"i1")>=texpr1(env,"f1")+texpr1(env,1)) << endl; cout << "construct i1 <= f1+1: " << (texpr1(env,"i1")<=texpr1(env,"f1")+texpr1(env,1)) << endl; cout << "construct i1 > f1+1: " << (texpr1(env,"i1")>texpr1(env,"f1")+texpr1(env,1)) << endl; cout << "construct i1 < f1+1: " << (texpr1(env,"i1") 0: " << n << endl; assert(!n.has_modulo()); assert(n.has_texpr()); try { n.get_modulo(); assert(0); } catch (invalid_argument& b) {} n.set_modulo(2); n.set_modulo(3); assert(n.has_modulo()); n.get_constyp()=AP_CONS_EQMOD; cout << "set_modulo i1 * f1 + 2 = 0 mod 3: " << n << endl; assert(!n.is_interval_cst() && !n.is_interval_linear() && l.is_interval_polynomial() && n.is_interval_polyfrac() && n.is_scalar()); assert(n.has_modulo()); assert(n.get_modulo()==3); n.set_texpr(sqrt(texpr1(env,"i1")+texpr1(env,1))); cout << "set_texpr sqrt(i1+1) = 0 mod 3: " << n << endl; assert(!n.is_interval_cst() && !n.is_interval_linear() && !n.is_interval_polynomial() && !n.is_interval_polyfrac() && n.is_scalar()); n.get_texpr() = texpr1(env,"i1")/texpr1(env,"f1")+texpr1(env,5); cout << "get_texpr i1/f1+5 = 0 mod 3: " << n << endl; assert(!n.is_interval_cst() && !n.is_interval_linear() && !n.is_interval_polynomial() && n.is_interval_polyfrac() && n.is_scalar()); n.get_texpr().left().left() = texpr1(env,interval(0,1)); cout << "get_texpr [0,1]/i1+5 = 0 mod 3: " << n << endl; assert(!n.is_interval_cst() && !n.is_interval_linear() && !n.is_interval_polynomial() && n.is_interval_polyfrac() && !n.is_scalar()); cout << "get tcons0 " << n.get_tcons0() << endl; n.get_tcons0() = (dim(1)>=5); cout << "set tcons0 i3>=5 " << n << endl; printf("print: "); n.print(); printf("\n"); } void test_tcons1_array() { cout << endl << "tcons1 array" << endl << "============" << endl << endl; var ai[] = { "i1","i3","i2" }; var af[] = { "f1","f3","f2" }; environment env(ai,2,af,2); environment env2(ai,3,af,3); coeff a[] = {1,2,3}; coeff b[] = {5,3}; tcons1_array t = tcons1_array(env,2); try { cout << t; assert(0); } catch (invalid_argument& r) { cout << endl; } t.set(0, tcons1(AP_CONS_SUPEQ,texpr1(env,sqrt(dim(0)+15*dim(2))))); t.set(1, tcons1(AP_CONS_EQ,texpr1(env,interval(2,5)))); cout << "construct: " << t << endl; cout << "get(1): " << t.get(1) << endl; try { t.get(2); assert(0); } catch (out_of_range& c) {} try { t.set(3,t.get(1)); assert(0); } catch (out_of_range c) {} tcons1_array u = t; cout << "copy: " << t << endl; tcons1_array v = tcons1_array(u,env2); cout << "env extend: " << v << endl << v.get_environment(); tcons1 ar[3] = { tcons1(AP_CONS_SUPEQ,texpr1(env,dim(0)*dim(1)*dim(2))), texpr1(env,"i1")>=texpr1(env,"f1")+texpr1(env,1), tcons1(AP_CONS_EQMOD,texpr1(env,interval(1,2))*texpr1(env,"i1"),5) }; tcons1_array x = tcons1_array(3,ar); cout << "from array: " << x << endl; vector ve = vector(2,tcons1(env)); ve[0] = tcons1(AP_CONS_EQ,texpr1::builder(env,0)); ve[1] = tcons1(AP_CONS_EQ,texpr1(env,1)-texpr1(env,"f3")); tcons1_array y = tcons1_array(ve); cout << "from vector: " << y << endl; y = ar; cout << "from array: " << y << endl; x = ve; cout << "from vector: " << x << endl; tcons1_array w = x; w = u; cout << "copy: " << w << endl; w.extend_environment(env2); cout << "extend environment " << w << endl << w.get_environment(); cout << "size: " << w.size() << endl; w.set(0, tcons1(AP_CONS_SUPEQ,texpr1(env,dim(1)*5+dim(2)))); b[0] = interval(0,1); cout << "set: " << w << endl; vector vv = w; cout << "to vector: " << vv.size() << ": " << vv[0] << "; " << vv[1] << endl; // tcons0_array cout << "get environment " << w.get_environment(); cout << "get tcons0_array " << w.get_tcons0_array() << endl; w.get_tcons0_array()[0] = (dim(0)>=dim(1)); cout << "set tcons_array " << w << endl; // print printf("print: "); w.print(); printf("\n"); } void test_abstract0(manager& m, manager& mm) { cout << "level 0" << endl << endl; interval i[5] = { interval(-1,1), top(), interval(scalar(infty(-1)),scalar(18)), interval(-0.5,1.5), interval(frac(1,2),frac(8,5)) }; interval_array ia(5,i); coeff c1[5] = { 1,2,3,4,0 }; coeff c2[5] = { -1,-1 }; coeff c3[5] = { 5,4,3,0,1 }; coeff c4[5] = { 0,2,1,3,4 }; linexpr0 e(5,c2,-20,AP_LINEXPR_SPARSE); linexpr0 ee(5,c3,-10,AP_LINEXPR_DENSE); lincons0 c[4] = { lincons0(AP_CONS_SUP,linexpr0(5,c1,1,AP_LINEXPR_DENSE)), lincons0(AP_CONS_SUPEQ,linexpr0(2,c2,-20,AP_LINEXPR_SPARSE)), lincons0(AP_CONS_EQ,linexpr0(5,c3,3,AP_LINEXPR_DENSE)), lincons0(AP_CONS_EQMOD,linexpr0(5,c4,4,AP_LINEXPR_SPARSE),5) }; lincons0_array ca(4,c); texpr0 x = dim(1)*dim(1)+dim(3)/2; texpr0 xx = sqrt(dim(1))*dim(3); tcons0 t[2] = { dim(0)>=dim(2)+1, dim(1)*dim(1)<=dim(3)/2 }; tcons0_array ta(2,t); generator0 g[2] = { generator0(AP_GEN_LINE,linexpr0(5,c1,AP_GEN_LINE)), generator0(AP_GEN_RAY,linexpr0(2,c2,AP_GEN_RAY)) }; generator0_array ga(2,g); // constructors cout << "construct top: " << abstract0(m,2,3,top()) << endl; cout << "construct bottom: " << abstract0(m,2,3,top()) << endl; cout << "construct box: " << abstract0(m,2,3,ia) << endl; cout << "construct lincons: " << abstract0(m,2,3,ca) << endl; cout << "construct tcons: " << abstract0(m,2,3,ta) << endl; abstract0 a0(m,2,3,ca); abstract0 a1 = a0; abstract0 a2(mm,a0); cout << "construct copy: " << a1 << endl; cout << "construct copy: " << a2 << endl; // copy a1 = top(); cout << "assign top: " << a1 << endl; assert(a1==abstract0(mm,2,3,top()) && !(a1!=abstract0(mm,2,3,top())) && a1<=abstract0(mm,2,3,top()) && a1>=abstract0(mm,2,3,top()) && abstract0(mm,2,3,top())<=a1 && abstract0(mm,2,3,top())>=a1 && !(a1abstract0(mm,2,3,top())) && !(abstract0(mm,2,3,top())>a1) && !(abstract0(mm,2,3,top())=a1); assert(a1.is_bottom(mm)); a1 = ia; cout << "assign box: " << a1 << endl; a1 = ca; cout << "assign lincons: " << a1 << endl; a1 = ta; cout << "assign tcons: " << a1 << endl; a1 = a2; cout << "assign copy: " << a1 << endl; assert(a1==a2 && a1<=a2 && a1>=a2 && !(a1!=a2)); assert(a1.is_eq(mm,a2) && a1.is_leq(mm,a2) && a2.is_leq(mm,a1)); a1.set(mm,top()); cout << "assign top: " << a1 << endl; a1.set(mm,bottom()); cout << "assign bottom: " << a1 << endl; a1.set(mm,ia); cout << "assign box: " << a1 << endl; a1.set(mm,ca); cout << "assign lincons: " << a1 << endl; a1.set(mm,ta); cout << "assign tcons " << a1 << endl; a1.set(mm,a2); cout << "assign copy: " << a1 << endl; a1.set(mm,ia,1,2); cout << "assign box redim: " << a1 << endl; cout << "unchanged: " << a0 << endl; // representation cout << "minimize: "; try { a0.minimize(m); cout << a0; } catch (not_implemented&c) {} cout << endl; cout << "canonicalize: "; try { a0.canonicalize(m); cout << a0; } catch (not_implemented&c) {} cout << endl; cout << "approximate: "; try { a0.approximate(m,0); cout << a0; } catch (not_implemented&c) {} cout << endl; cout << "closure: "; try { a0.closure(m); cout << a0; } catch (not_implemented&c) {} cout << endl; a0.set(mm,ca,2,3); a1.set(mm,ia,2,3); printf( "print:\n"); a0.print(m); printf("\n"); try { printf( "printdiff:\n"); printdiff(m,a0,a1); } catch (not_implemented& c) { printf("not implemented %s\n",c.what());} printf( "dump:\n"); a0.dump(m); printf("\n"); // serialization try { size_t x; a0 = abstract0(m,2,3,ca); string* s = a0.serialize(m); deserialize(mm,a1,*s,&x); cout << "serialize: " << s->length() << " bytes" << endl; cout << "deserialize: " << x << " bytes" << endl; assert(a0==a1 && a0<=a1 && a0>=a1 && !(a0!=a1)); delete s; } catch (not_implemented& c) { cout << "serialization not implemented: " << c.what() << endl; } // predicate & properties ap_dimension_t d = a1.get_dimension(m); cout << "dimensions: " << d.intdim <<", " << d.realdim << endl; cout << "size: " << a1.size(m) << endl; cout << "sat lincons: " << abstract0(m,2,3,ca).sat(mm,ca[1]) << endl; cout << "sat tcons: " << abstract0(m,2,3,ta).sat(mm,ta[1]) << endl; cout << "sat interval: " << abstract0(m,2,3,ia).sat(mm,2,ia[2]) << endl; cout << "unconstrainned: " << abstract0(m,2,3,ia).is_dimension_unconstrained(mm,2) << endl; a0 = abstract0(m,2,3,ca); cout << "bound linexpr: " << a0.bound(mm,e) << endl; cout << "bound texpr: " << a0.bound(mm,x) << endl; cout << "bound dimension: " << a0.bound(mm,2) << endl; // reduced-product does not implement to_generator try { cout << "to generator: " << a0.to_generator_array(mm) << endl; } catch (not_implemented& i) { cout << "to generator: not implemented" << endl; } cout << "to lincons: " << a0.to_lincons_array(mm) << endl; cout << "to tcons: " << a0.to_tcons_array(mm) << endl; cout << "to box: " << a0.to_box(mm) << endl; // meet a1 = abstract0(m,2,3,ia); a2 = abstract0(m,2,3,ca); meet(m,a0,a1,a2); assert(a0<=a1 && a0<=a2); cout << "meet: " << a0 << endl; abstract0 a3(m,2,3,ta); abstract0 a4(a1); a4.meet(m,a1); assert(a1==a4); a4.meet(m,a2); assert(a0==a4); abstract0 a5 = a1; a5 *= a2; assert(a5==a0); abstract0* ar[] = { &a1,&a2,&a3 }; vector br(3); br[0] = &a1; br[1] = &a2; br[2] = &a3; meet(m,a4,3,ar); assert(a4<=a1 && a4<=a2 && a4<=a3); meet(m,a1,br); assert(a1==a4); cout << "meet array: " << a1 << endl; a1 = abstract0(m,2,3,ta); a2 = abstract0(m,2,3,ca); meet(m,a3,a1,ca); meet(m,a4,a2,ta); assert(a3==a4); a1.meet(m,ca); a2.meet(m,ta); assert(a1==a3 && a2==a4); a1 = abstract0(m,2,3,ta); a2 = abstract0(m,2,3,ca); a1 *= ca; a2 *= ta; assert(a1==a3 && a2==a4); cout << "meet lincons: " << a1 << endl; cout << "meet tcons: " << a2 << endl; // join a1 = abstract0(m,2,3,ia); a2 = abstract0(m,2,3,ca); join(m,a0,a1,a2); assert(a0>=a1 && a0>=a2); cout << "join: " << a0 << endl; a3 = abstract0(m,2,3,ta); a4 = abstract0(a1); a4.join(m,a1); assert(a1==a4); a4.join(m,a2); assert(a0==a4); a5 = a1; a5 += a2; assert(a5==a0); join(m,a4,3, ar); assert(a4>=a1 && a4>=a2 && a4>=a3); join(m,a1,br); assert(a1==a4); cout << "join array: " << a1 << endl; a1 = abstract0(m,2,3,ia); add_rays(m,a2,a1,ga); assert(a2>=a1); a1.add_rays(m,ga); assert(a1==a2); a1 = abstract0(m,2,3,ia); a1 += ga; assert(a1==a2); cout << "add rays: " << a1 << endl; // assign a1 = abstract0(m,2,3,ia); a3 = a1; assign(m,a2,a1,0,e); a1.assign(m,0,e); assert(a1==a2); cout << "assign linexpr: " << a1 << endl; a5 = abstract0(m,2,3,ta); assign(m,a4,a3,0,e,a5); a3.assign(m,0,e,a5); assert(a3==a4); cout << "assign linexpr inter: " << a3 << endl; linexpr0* ea[] = { &e, &ee }; vector ev(2); ev[0] = &e; ev[1] = ⅇ ap_dim_t da[] = { 1,2 }; vector dv(2); dv[0] = 1; dv[1] = 2; a1 = abstract0(m,2,3,ia); assign(m,a2,a1,dv,ev); assign(m,a3,a1,2,da,ea); a4 = a1; a1.assign(m,dv,ev); a4.assign(m,2,da,ea); assert(a1==a2 && a1==a3 && a1==a4); cout << "assign linexprs: " << a1 << endl; a1 = abstract0(m,2,3,ia); assign(m,a2,a1,dv,ev,a5); assign(m,a3,a1,2,da,ea,a5); a4 = a1; a1.assign(m,dv,ev,a5); a4.assign(m,2,da,ea,a5); assert(a1==a2 && a1==a3 && a1==a4); cout << "assign linexprs inter: " << a1 << endl; a1 = abstract0(m,2,3,ia); a3 = a1; assign(m,a2,a1,0,x); a1.assign(m,0,x); assert(a1==a2); cout << "assign texpr: " << a1 << endl; a5 = abstract0(m,2,3,ta); assign(m,a4,a3,0,x,a5); a3.assign(m,0,x,a5); assert(a3==a4); cout << "assign texpr inter: " << a3 << endl; texpr0* xa[] = { &x, &xx }; vector xv(2); xv[0] = &x; xv[1] = &xx; a1 = abstract0(m,2,3,ia); assign(m,a2,a1,dv,xv); assign(m,a3,a1,2,da,xa); a4 = a1; a1.assign(m,dv,xv); a4.assign(m,2,da,xa); assert(a1==a2 && a1==a3 && a1==a4); cout << "assign texprs: " << a1 << endl; a1 = abstract0(m,2,3,ia); assign(m,a2,a1,dv,xv,a5); assign(m,a3,a1,2,da,xa,a5); a4 = a1; a1.assign(m,dv,xv,a5); a4.assign(m,2,da,xa,a5); assert(a1==a2 && a1==a3 && a1==a4); cout << "assign texprs inter: " << a1 << endl; // substitute a1 = abstract0(m,2,3,ia); a3 = a1; substitute(m,a2,a1,0,e); a1.substitute(m,0,e); assert(a1==a2); cout << "subst linexpr: " << a1 << endl; a5 = abstract0(m,2,3,ta); substitute(m,a4,a3,0,e,a5); a3.substitute(m,0,e,a5); assert(a3==a4); cout << "subst linexpr inter: " << a3 << endl; a1 = abstract0(m,2,3,ia); substitute(m,a2,a1,dv,ev); substitute(m,a3,a1,2,da,ea); a4 = a1; a1.substitute(m,dv,ev); a4.substitute(m,2,da,ea); assert(a1==a2 && a1==a3 && a1==a4); cout << "subst linexprs: " << a1 << endl; a1 = abstract0(m,2,3,ia); substitute(m,a2,a1,dv,ev,a5); substitute(m,a3,a1,2,da,ea,a5); a4 = a1; a1.substitute(m,dv,ev,a5); a4.substitute(m,2,da,ea,a5); assert(a1==a2 && a1==a3 && a1==a4); cout << "subst linexprs inter: " << a1 << endl; a1 = abstract0(m,2,3,ia); a3 = a1; substitute(m,a2,a1,0,x); a1.substitute(m,0,x); assert(a1==a2); cout << "subst texpr: " << a1 << endl; a5 = abstract0(m,2,3,ta); substitute(m,a4,a3,0,x,a5); a3.substitute(m,0,x,a5); assert(a3==a4); cout << "subst texpr inter: " << a3 << endl; a1 = abstract0(m,2,3,ia); substitute(m,a2,a1,dv,xv); substitute(m,a3,a1,2,da,xa); a4 = a1; a1.substitute(m,dv,xv); a4.substitute(m,2,da,xa); assert(a1==a2 && a1==a3 && a1==a4); cout << "subst texprs: " << a1 << endl; a1 = abstract0(m,2,3,ia); substitute(m,a2,a1,dv,xv,a5); substitute(m,a3,a1,2,da,xa,a5); a4 = a1; a1.substitute(m,dv,xv,a5); a4.substitute(m,2,da,xa,a5); assert(a1==a2 && a1==a3 && a1==a4); cout << "subst texprs inter: " << a1 << endl; // forget a1 = abstract0(m,2,3,ia); a3 = a1; forget(m,a2,a1,0); a1.forget(m,0); assert(a1==a2); forget(m,a4,a3,0,true); a3.forget(m,0,true); assert(a3==a4); assert(a3<=a1); cout << "forget: " << a1 << endl; cout << "forget 0: " << a3 << endl; a1 = abstract0(m,2,3,ia); a3 = a1; forget(m,a2,a1,2,da); a1.forget(m,2,da); assert(a1==a2); forget(m,a4,a3,2,da,true); a3.forget(m,2,da,true); assert(a3==a4); assert(a3<=a1); cout << "forgets: " << a1 << endl; cout << "forgets 0: " << a3 << endl; a1 = abstract0(m,2,3,ia); a3 = a1; forget(m,a2,a1,dv); a1.forget(m,dv); assert(a1==a2); forget(m,a4,a3,dv,true); a3.forget(m,dv,true); assert(a3==a4); assert(a3<=a1); cout << "forgets: " << a1 << endl; cout << "forgets 0: " << a3 << endl; // dim change & permute dimchange dc = dimchange(1,2,(ap_dim_t[]){1,2,3}); a1 = abstract0(m,2,3,ia); add_dimensions(m,a2,a1,dc); add_dimensions(m,a3,a1,dc,true); a1.add_dimensions(m,dc); assert(a1==a2); assert(a1>=a3); cout << "add dim: " << a1 << endl; cout << "add dim 0: " << a3 << endl; remove_dimensions(m,a2,a1,-dc); a1.remove_dimensions(m,-dc); assert(a1==a2); assert(a1==abstract0(m,2,3,ia)); cout << "remove dim: " << a1 << endl; dimperm dp = dimperm(5,(ap_dim_t[]){0,1,3,4,2}); a1 = abstract0(m,2,3,ia); permute_dimensions(m,a2,a1,dp); a1.permute_dimensions(m,dp); assert(a1==a2); cout << "permute dim: " << a1 << endl; a1.permute_dimensions(m,-dp); assert(a1==abstract0(m,2,3,ia)); try { a1.permute_dimensions(m,dimperm(3,(ap_dim_t[]){0,1,2})); assert(0); } catch (invalid_argument&c) {} // expand fold ap_dim_t fa[3] = { 0,2,3 }; vector fv(3); fv[0] = 0; fv[1] = 2; fv[2] = 3; a1 = abstract0(m,2,3,ia); expand(m,a2,a1,0,2); a1.expand(m,0,2); assert(a1==a2); cout << "expand: " << a1 << endl; fold(m,a2,a1,3,fa); fold(m,a3,a1,fv); a4=a1; a1.fold(m,3,fa); a4.fold(m,fv); cout << "fold: " << a1 << endl; assert(a1==a2 && a1==a3 && a1==a4); assert(a1==abstract0(m,2,3,ia)); // widening a1 = abstract0(m,2,3,ia); a2 = abstract0(m,2,3,ca); a2 += a1; widening(m,a3,a1,a2); cout << "widening: " << a3 << endl; assert(a1<=a3 && a2<=a3); widening(m,a3,a1,a2,ca); cout << "widening thr: " << a3 << endl; assert(a1<=a3 && a2<=a3); a1.free(m); a2.free(mm); } void test_abstract1(manager& m, manager& mm) { cout << "level 1" << endl << endl; var vi[3] = { "i1","i3","i2" }; var vf[3] = { "f1","f3","f2" }; environment env(vi,2,vf,3); environment env2(vi,3,vf,3); interval i[6] = { interval(-1,1), top(), interval(scalar(infty(-1)),scalar(18)), interval(-0.5,1.5), interval(frac(1,2),frac(8,5)), interval(-2.,2.2) }; interval_array ia(5,i); var va[5] = { "i1", "i3", "f1", "f3", "f2" }; var va2[6] = { "i1", "i2", "i3", "f1", "f3", "f2" }; vector vv(5,"i1"); vv[1] = "i3"; vv[2] = "f1"; vv[3] = "f3"; vv[4] = "f2"; coeff c1[5] = { 1,2,3,4,0 }; coeff c2[5] = { -1,-1 }; coeff c3[5] = { 5,4,3,0,1 }; coeff c4[5] = { 0,2,1,3,4 }; linexpr1 e(env,linexpr0(5,c2,-20,AP_LINEXPR_SPARSE)); linexpr1 ee(env,linexpr0(5,c3,-10,AP_LINEXPR_DENSE)); lincons1 c[4] = { lincons1(env,lincons0(AP_CONS_SUP,linexpr0(5,c1,1,AP_LINEXPR_DENSE))), lincons1(env,lincons0(AP_CONS_SUPEQ,linexpr0(2,c2,-20,AP_LINEXPR_SPARSE))), lincons1(env,lincons0(AP_CONS_EQ,linexpr0(5,c3,3,AP_LINEXPR_DENSE))), lincons1(env,lincons0(AP_CONS_EQMOD,linexpr0(5,c4,4,AP_LINEXPR_SPARSE),5)) }; lincons1_array ca(4,c); texpr1 x = texpr1(env,"i3")*texpr1(env,"f1")+texpr1(env,"f2")/texpr1(env,2); texpr1 xx = sqrt(texpr1(env,"i1"))*texpr1(env,"f2"); tcons1 t[2] = { texpr1(env,"i1")>=texpr1(env,"i3")+texpr1(env,1), texpr1(env,"f1")*texpr1(env,"f2")<=texpr1(env,"f3")/texpr1(env,2), }; tcons1_array ta(2,t); generator1 g[2] = { generator1(env,generator0(AP_GEN_LINE,linexpr0(5,c1,AP_GEN_LINE))), generator1(env,generator0(AP_GEN_RAY,linexpr0(2,c2,AP_GEN_RAY))) }; generator1_array ga(2,g); // constructors cout << "construct top: " << abstract1(m,env,top()) << endl; cout << "construct bottom: " << abstract1(m,env,bottom()) << endl; cout << "construct box: " << abstract1(m,env,va,ia) << endl; cout << "construct box: " << abstract1(m,env,vv,ia) << endl; cout << "construct lincons: " << abstract1(m,ca) << endl; cout << "construct tcons: " << abstract1(m,ta) << endl; abstract1 a0(m,ca); abstract1 a1 = a0; abstract1 a2(mm,a0); cout << "construct copy: " << a1 << endl; cout << "construct copy: " << a2 << endl; // copy a1 = top(); cout << "assign top: " << a1 << endl; assert(a1==abstract1(mm,env,top()) && !(a1!=abstract1(mm,env,top())) && a1<=abstract1(mm,env,top()) && a1>=abstract1(mm,env,top()) && abstract1(mm,env,top())<=a1 && abstract1(mm,env,top())>=a1 && !(a1abstract1(mm,env,top())) && !(abstract1(mm,env,top())>a1) && !(abstract1(mm,env,top())=a1); assert(a1.is_bottom(mm)); a1 = ia; cout << "assign box: " << a1 << endl; a1 = ca; cout << "assign lincons: " << a1 << endl; a1 = ta; cout << "assign tcons: " << a1 << endl; a1 = a2; cout << "assign copy: " << a1 << endl; assert(a1==a2 && a1<=a2 && a1>=a2 && !(a1!=a2)); assert(a1.is_eq(mm,a2) && a1.is_leq(mm,a2) && a2.is_leq(mm,a1)); a1.set(mm,top()); cout << "assign top: " << a1 << endl; a1.set(mm,env,top()); cout << "assign top: " << a1 << endl; a1.set(mm,bottom()); cout << "assign bottom: " << a1 << endl; a1.set(mm,env,bottom()); cout << "assign bottom: " << a1 << endl; a1.set(mm,ia); cout << "assign box: " << a1 << endl; a1.set(mm,env,va,ia); cout << "assign box: " << a1 << endl; a1.set(mm,env,vv,ia); cout << "assign box: " << a1 << endl; a1.set(mm,ca); cout << "assign lincons: " << a1 << endl; a1.set(mm,ta); cout << "assign tcons " << a1 << endl; a1.set(mm,a2); cout << "assign copy: " << a1 << endl; cout << "unchanged: " << a0 << endl; // representation cout << "minimize: "; try { a0.minimize(m); cout << a0; } catch (not_implemented&c) {} cout << endl; cout << "canonicalize: "; try { a0.canonicalize(m); cout << a0; } catch (not_implemented&c) {} cout << endl; cout << "approximate: "; try { a0.approximate(m,0); cout << a0; } catch (not_implemented&c) {} cout << endl; cout << "closure: "; try { a0.closure(m); cout << a0; } catch (not_implemented&c) {} cout << endl; a0.set(mm,ca); a1.set(mm,env,va,ia); printf( "print:\n"); a0.print(m); printf("\n"); try { printf( "printdiff:\n"); printdiff(m,a0,a1); } catch (not_implemented& c) { printf("not implemented %s\n",c.what());} printf( "dump:\n"); a0.dump(m); printf("\n"); // serialization try { size_t x; a0 = abstract1(m,ca); string* s = a0.serialize(m); deserialize(mm,a1,*s,&x); cout << "serialize: " << s->length() << " bytes" << endl; cout << "deserialize: " << x << " bytes" << endl; assert(a0==a1 && a0<=a1 && a0>=a1 && !(a0!=a1)); delete s; } catch (not_implemented& c) { cout << "serialization not implemented: " << c.what() << endl; } // predicate & properties a1.set(mm,ca); cout << "environment:" << endl << a1.get_environment(); cout << "size: " << a1.size(m) << endl; cout << "get abstract0: " << a1.get_abstract0() << endl; a1.get_abstract0() = ia; cout << "set abstract0: " << a1 << endl; cout << "sat lincons: " << abstract1(m,ca).sat(mm,ca.get(1)) << endl; cout << "sat tcons: " << abstract1(m,ta).sat(mm,ta.get(1)) << endl; cout << "sat interval: " << abstract1(m,env,va,ia).sat(mm,"i1",ia[2]) << endl; cout << "unconstrainned: " << abstract1(m,env,va,ia).is_variable_unconstrained(mm,"f1") << endl; cout << "bound linexpr: " << a0.bound(mm,e) << endl; cout << "bound texpr: " << a0.bound(mm,x) << endl; cout << "bound variable: " << a0.bound(mm,"f1") << endl; // reduced-product does not implement to_generator try { cout << "to generator: " << a0.to_generator_array(mm) << endl; } catch (not_implemented& i) { cout << "to generator: not implemented" << endl; } cout << "to lincons: " << a0.to_lincons_array(mm) << endl; cout << "to tcons: " << a0.to_tcons_array(mm) << endl; cout << "to box: " << a0.to_box(mm) << endl; // meet a1 = abstract1(m,env,va,ia); a2 = abstract1(m,ca); meet(m,a0,a1,a2); assert(a0<=a1 && a0<=a2); cout << "meet: " << a0 << endl; abstract1 a3(m,ta); abstract1 a4(a1); a4.meet(m,a1); assert(a1==a4); a4.meet(m,a2); assert(a0==a4); abstract1 a5 = a1; a5 *= a2; assert(a5==a0); abstract1* ar[] = { &a1,&a2,&a3 }; vector br(3); br[0] = &a1; br[1] = &a2; br[2] = &a3; meet(m,a4,3,ar); assert(a4<=a1 && a4<=a2 && a4<=a3); meet(m,a1,br); assert(a1==a4); cout << "meet array: " << a1 << endl; a1 = abstract1(m,ta); a2 = abstract1(m,ca); meet(m,a3,a1,ca); meet(m,a4,a2,ta); assert(a3==a4); a1.meet(m,ca); a2.meet(m,ta); assert(a1==a3 && a2==a4); a1 = abstract1(m,ta); a2 = abstract1(m,ca); a1 *= ca; a2 *= ta; assert(a1==a3 && a2==a4); cout << "meet lincons: " << a1 << endl; cout << "meet tcons: " << a2 << endl; // join a1 = abstract1(m,env,va,ia); a2 = abstract1(m,ca); join(m,a0,a1,a2); assert(a0>=a1 && a0>=a2); cout << "join: " << a0 << endl; a3 = abstract1(m,ta); a4 = abstract1(a1); a4.join(m,a1); assert(a1==a4); a4.join(m,a2); assert(a0==a4); a5 = a1; a5 += a2; assert(a5==a0); join(m,a4,3, ar); assert(a4>=a1 && a4>=a2 && a4>=a3); join(m,a1,br); assert(a1==a4); cout << "join array: " << a1 << endl; a1 = abstract1(m,env,va,ia); add_rays(m,a2,a1,ga); assert(a2>=a1); a1.add_rays(m,ga); assert(a1==a2); a1 = abstract1(m,env,va,ia); a1 += ga; assert(a1==a2); cout << "add rays: " << a1 << endl; // unify a1 = abstract1(m,env,va,ia); a2 = abstract1(m,env2,va2,ia); unify(m,a0,a1,a2); a1.unify(m,a2); assert(a0==a1); cout << "unify: " << a0 << endl; // assign a1 = abstract1(m,env,va,ia); a3 = a1; assign(m,a2,a1,"i1",e); a1.assign(m,"i1",e); assert(a1==a2); cout << "assign linexpr: " << a1 << endl; a5 = abstract1(m,ta); assign(m,a4,a3,"i1",e,a5); a3.assign(m,"i1",e,a5); assert(a3==a4); cout << "assign linexpr inter: " << a3 << endl; linexpr1* ea[] = { &e, &ee }; vector ev(2); ev[0] = &e; ev[1] = ⅇ var da[] = { "f1", "f2" }; vector dv(2,""); dv[0] = "f1"; dv[1] = "f2"; a1 = abstract1(m,env,va,ia); assign(m,a2,a1,dv,ev); assign(m,a3,a1,2,da,ea); a4 = a1; a1.assign(m,dv,ev); a4.assign(m,2,da,ea); assert(a1==a2 && a1==a3 && a1==a4); cout << "assign linexprs: " << a1 << endl; a1 = abstract1(m,env,va,ia); assign(m,a2,a1,dv,ev,a5); assign(m,a3,a1,2,da,ea,a5); a4 = a1; a1.assign(m,dv,ev,a5); a4.assign(m,2,da,ea,a5); assert(a1==a2 && a1==a3 && a1==a4); cout << "assign linexprs inter: " << a1 << endl; a1 = abstract1(m,env,va,ia); a3 = a1; assign(m,a2,a1,"i1",x); a1.assign(m,"i1",x); assert(a1==a2); cout << "assign texpr: " << a1 << endl; a5 = abstract1(m,ta); assign(m,a4,a3,"i1",x,a5); a3.assign(m,"i1",x,a5); assert(a3==a4); cout << "assign texpr inter: " << a3 << endl; texpr1* xa[] = { &x, &xx }; vector xv(2); xv[0] = &x; xv[1] = &xx; a1 = abstract1(m,env,va,ia); assign(m,a2,a1,dv,xv); assign(m,a3,a1,2,da,xa); a4 = a1; a1.assign(m,dv,xv); a4.assign(m,2,da,xa); assert(a1==a2 && a1==a3 && a1==a4); cout << "assign texprs: " << a1 << endl; a1 = abstract1(m,env,va,ia); assign(m,a2,a1,dv,xv,a5); assign(m,a3,a1,2,da,xa,a5); a4 = a1; a1.assign(m,dv,xv,a5); a4.assign(m,2,da,xa,a5); assert(a1==a2 && a1==a3 && a1==a4); cout << "assign texprs inter: " << a1 << endl; // substitute a1 = abstract1(m,env,va,ia); a3 = a1; substitute(m,a2,a1,"i1",e); a1.substitute(m,"i1",e); assert(a1==a2); cout << "subst linexpr: " << a1 << endl; a5 = abstract1(m,ta); substitute(m,a4,a3,"i1",e,a5); a3.substitute(m,"i1",e,a5); assert(a3==a4); cout << "subst linexpr inter: " << a3 << endl; a1 = abstract1(m,env,va,ia); substitute(m,a2,a1,dv,ev); substitute(m,a3,a1,2,da,ea); a4 = a1; a1.substitute(m,dv,ev); a4.substitute(m,2,da,ea); assert(a1==a2 && a1==a3 && a1==a4); cout << "subst linexprs: " << a1 << endl; a1 = abstract1(m,env,va,ia); substitute(m,a2,a1,dv,ev,a5); substitute(m,a3,a1,2,da,ea,a5); a4 = a1; a1.substitute(m,dv,ev,a5); a4.substitute(m,2,da,ea,a5); assert(a1==a2 && a1==a3 && a1==a4); cout << "subst linexprs inter: " << a1 << endl; a1 = abstract1(m,env,va,ia); a3 = a1; substitute(m,a2,a1,"i1",x); a1.substitute(m,"i1",x); assert(a1==a2); cout << "subst texpr: " << a1 << endl; a5 = abstract1(m,ta); substitute(m,a4,a3,"i1",x,a5); a3.substitute(m,"i1",x,a5); assert(a3==a4); cout << "subst texpr inter: " << a3 << endl; a1 = abstract1(m,env,va,ia); substitute(m,a2,a1,dv,xv); substitute(m,a3,a1,2,da,xa); a4 = a1; a1.substitute(m,dv,xv); a4.substitute(m,2,da,xa); assert(a1==a2 && a1==a3 && a1==a4); cout << "subst texprs: " << a1 << endl; a1 = abstract1(m,env,va,ia); substitute(m,a2,a1,dv,xv,a5); substitute(m,a3,a1,2,da,xa,a5); a4 = a1; a1.substitute(m,dv,xv,a5); a4.substitute(m,2,da,xa,a5); assert(a1==a2 && a1==a3 && a1==a4); cout << "subst texprs inter: " << a1 << endl; // forget a1 = abstract1(m,env,va,ia); a3 = a1; forget(m,a2,a1,"i1"); a1.forget(m,"i1"); assert(a1==a2); forget(m,a4,a3,"i1",true); a3.forget(m,"i1",true); assert(a3==a4); assert(a3<=a1); cout << "forget: " << a1 << endl; cout << "forget 0: " << a3 << endl; a1 = abstract1(m,env,va,ia); a3 = a1; forget(m,a2,a1,2,da); a1.forget(m,2,da); assert(a1==a2); forget(m,a4,a3,2,da,true); a3.forget(m,2,da,true); assert(a3==a4); assert(a3<=a1); cout << "forgets: " << a1 << endl; cout << "forgets 0: " << a3 << endl; a1 = abstract1(m,env,va,ia); a3 = a1; forget(m,a2,a1,dv); a1.forget(m,dv); assert(a1==a2); forget(m,a4,a3,dv,true); a3.forget(m,dv,true); assert(a3==a4); assert(a3<=a1); cout << "forgets: " << a1 << endl; cout << "forgets 0: " << a3 << endl; // environment change a0 = abstract1(m,env,va,ia); a2 = a0; change_environment(m,a1,a0,env2); a0.change_environment(m,env2); assert(a0==a1); cout << "change env: " << a0 << endl << a0.get_environment(); change_environment(m,a3,a2,env2,true); a2.change_environment(m,env2,true); assert(a2==a3); cout << "change env 0: " << a2 << endl << a2.get_environment(); assert(a2<=a0); minimize_environment(m,a1,a0); a0.minimize_environment(m); assert(a0==a1); cout << "minimize env: " << a0 << endl << a0.get_environment(); var v1[2] = { "i1", "f2" }; var v2[2] = { "truc", "f0" }; a0 = abstract1(m,env,va,ia); a2 = a0; rename(m,a1,a0,2,v1,v2); a0.rename(m,2,v1,v2); cout << "rename: " << a0 << endl; assert(a0==a1); vector w1(2,"i1"); w1[1] = "f2"; vector w2(2,"truc"); w2[1] = "f0"; rename(m,a1,a0,w2,w1); a0.rename(m,w2,w1); assert(a0==a1); assert(a0==a2); // expand fold a1 = abstract1(m,env,va,ia); a0 = a1; expand(m,a2,a1,"i1",2,v2); a1.expand(m,"i1",2,v2); assert(a1==a2); cout << "expand: " << a1 << endl; expand(m,a2,a0,"i1",w2); a0.expand(m,"i1",w2); assert(a0==a1); assert(a1==a2); var v3[3] = { "truc", "i1", "f0" }; vector w3(3,"truc"); w3[1] = "i1"; w3[2] = "f0"; fold(m,a1,a0,3,v3); a0.fold(m,3,v3); assert(a0==a1); cout << "fold: " << a0 << endl; fold(m,a3,a2,w3); a2.fold(m,w3); assert(a2==a3); assert(a0==a2); var rn1[1] = { "truc" }; var rn2[1] = { "i1" }; a0.rename(m,1,rn1,rn2); assert(a0==abstract1(m,env,va,ia)); // widening a1 = abstract1(m,env,va,ia); a2 = abstract1(m,ca); a2 += a1; widening(m,a3,a1,a2); cout << "widening: " << a3 << endl; assert(a1<=a3 && a2<=a3); widening(m,a3,a1,a2,ca); cout << "widening thr: " << a3 << endl; assert(a1<=a3 && a2<=a3); a1.free(m); a2.free(mm); } void set_algo(manager& m, int algo) { for (int i=AP_FUNID_COPY;i<=AP_FUNID_CLOSURE;i++) m.get_funopt(ap_funid_t(i)).algorithm = algo; } void test_manager_algo(manager& m, manager& mm, int algo) { cout << "library: " << m.get_library() << endl; cout << "version: " << m.get_version() << endl; cout << "algo: " << algo << endl; try { m.fpu_init(); mm.fpu_init(); } catch (runtime_error& c) { cout << "fpu_init failed: " << c.what() << endl; } cout << endl; set_algo(m,algo); set_algo(mm,algo); test_abstract0(m,mm); test_abstract1(m,mm); } void test_manager(manager& m, manager& mm) { test_manager_algo(m,mm,0); test_manager_algo(m,mm,-1); } void test_box() { cout << endl << "Box" << endl << "===" << endl << endl; box_manager m,mm; test_manager(m,mm); } void test_octagon() { cout << endl << "Octagon" << endl << "=======" << endl << endl; oct_manager m,mm; test_manager(m,mm); } void test_polka() { cout << endl << "Polka (loose)" << endl << "=============" << endl << endl; polka_manager m,mm; test_manager(m,mm); cout << endl << "Polka (strict)" << endl << "==============" << endl << endl; m = polka_manager(true); mm = polka_manager(true); test_manager(m,mm); } #if HAS_PPL void test_ppl() { cout << endl << "PPL (polyhedra, loose)" << endl << "======================" << endl << endl; ppl_poly_manager m,mm; test_manager(m,mm); cout << endl << "PPL (polyhedra, strict)" << endl << "=======================" << endl << endl; m = ppl_poly_manager(true); mm = ppl_poly_manager(true); test_manager(m,mm); cout << endl << "PPL (grids)" << endl << "===========" << endl << endl; m = ppl_grid_manager(); mm = ppl_grid_manager(); test_manager(m,mm); cout << endl << "Product Polka (loose) * PPL grids" << endl << "=================================" << endl << endl; m = pkgrid_manager(); mm = pkgrid_manager(); test_manager(m,mm); cout << endl << "Product Polka (strict) * PPL grids" << endl << "==================================" << endl << endl; m = pkgrid_manager(true); mm = pkgrid_manager(true); test_manager(m,mm); } #endif int main() { mpfr_init_set_d(mpfr1,1.25,GMP_RNDU); mpfr_init_set_d(mpfr2,99,GMP_RNDU); mpfr_init(mpfr3); test_scalar(); test_interval(); test_interval_array(); test_coeff(); test_dimchange(); test_dimperm(); test_linexpr0(); test_lincons0(); test_lincons0_array(); test_generator0(); test_generator0_array(); test_texpr0(); test_tcons0(); test_tcons0_array(); test_var(); test_environment(); test_linexpr1(); test_lincons1(); test_lincons1_array(); test_generator1(); test_generator1_array(); test_texpr1(); test_tcons1(); test_tcons1_array(); test_box(); test_polka(); test_octagon(); #if HAS_PPL test_ppl(); #endif mpfr_clear(mpfr1); mpfr_clear(mpfr2); mpfr_clear(mpfr3); return 0; } apron-dist-0.9.10/apron/apronxx/apxx_generator1.hh0000640014525101416610000003014510703144237022017 0ustar bjeannetpopart/* -*- C++ -*- * apxx_generator1.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_GENERATOR1_HH #define __APXX_GENERATOR1_HH #include "ap_generator1.h" #include "apxx_environment.hh" #include "apxx_generator0.hh" #include "apxx_linexpr1.hh" namespace apron { /* ================================= */ /* generator1 */ /* ================================= */ /*! \brief Level 1 generator (ap_generator1_t wrapper). * * Level 1 version of linear generators with scalar coefficients (coeff). * Terms are indexed using variable names (var) instead of dimensions (ap_dim_t). * Internally, a generator1 wraps together a generator0 (memory managed) and an environment (holding a * reference count). */ class generator1 : public use_malloc { protected: ap_generator1_t l; //!< Structure managed by APRON. //! Internal use only. Shallow copy (no copy of generator0 or environment). generator1(ap_generator1_t p); friend class generator1_array; public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ /*! \brief Creates a new generator from a generator0 (copied) and an environment (reference count * incremented) associating names to dimensions in generator0. */ generator1(const environment& e, const generator0& x); /*! \brief Creates a new generator from an empty linear expression. * * The linear expression is created sparse and empty (has_linexpr returns true). * \arg \c e associates a variable name to each dimension (reference counter incremented). * \arg \c gentyp can be AP_GEN_LINE, AP_GEN_RAY, AP_GEN_VERTEX, AP_GEN_LINEMOD, * or AP_GEN_RAYMOD. */ generator1(const environment& e, ap_gentyp_t gentyp=AP_GEN_RAY); /*! \brief Creates a new generator from a linear expression (copied). * * \arg \c e associates a variable name to each dimension (reference counter incremented). * \arg \c gentyp can be AP_GEN_LINE, AP_GEN_RAY, AP_GEN_VERTEX, AP_GEN_LINEMOD, * or AP_GEN_RAYMOD. * * \warning \c lin should have only scalar (non-interval) coefficients (unchecked). */ generator1(ap_gentyp_t gentyp, const linexpr1& lin); //! (Deep) copy of a generator. generator1(const generator1& x); /*! \brief Makes a (deep) copy of x and extends its environment. * * \throw std::invalid_argument if e is not a super-environment of that of x. */ generator1(const generator1& x, const environment& e); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ /*! \brief Frees all space for the generator, and decrements the reference count * of the environment. */ ~generator1(); //@} /* assignment */ /* ========== */ /** @name Assignment */ //@{ //! Makes a (deep) copy. generator1& operator= (const generator1& x); /*! \brief Sets the underlying linear expression to c (copied). * * Does not fail as get_linexpr can: if the generator was created without an underlying expression, * it is created. * * \warning \c c should have only scalar (non-interval) coefficients (unchecked). * \warning assumes that c and *this have equal environments (unchecked). */ void set_linexpr(const linexpr1& c); //@} /* dimension operations */ /* ==================== */ /** @name Dimension operations */ //@{ /*! \brief Extends the environment of the generator. * * \throw std::invalid_argument if e is not a super-environment of that of *this. */ void extend_environment(const environment& e); //@} /* access */ /* ====== */ /** @name Accesses, size */ //@{ //! Returns the environment of the generator (with incremented reference count). environment get_environment() const; //! Returns a reference to the underlying generator0. const generator0& get_generator0() const; //! Returns a (modifiable) reference to the underlying generator0. generator0& get_generator0(); /*! \brief Returns the size of the underlying linear expression. * * \throw std::invalid_argument if no valid linear expression has been defined. */ size_t size() const; /* get */ /*! \brief Returns a (modifiable) reference to the constraint type. * * \return either AP_GEN_LINE, AP_GEN_RAY, AP_GEN_VERTEX, AP_GEN_LINEMOD, or AP_GEN_RAYMOD. */ ap_gentyp_t& get_gentyp(); /*! \brief Returns a reference to the constraint type. * * \return either AP_GEN_LINE, AP_GEN_RAY, AP_GEN_VERTEX, AP_GEN_LINEMOD, or AP_GEN_RAYMOD. */ const ap_gentyp_t& get_gentyp() const; /*! \brief Whether the generator has a valid linear expression. * * \note The only way the linear expression may be invalid is when accessing fields of uninitialised * (or enlarged) generator1_array. */ bool has_linexpr() const; /*! \brief Returns a copy of the underlying linear expression. * * \throw std::invalid_argument if no valid linear expression has been defined. */ linexpr1 get_linexpr() const; /*! \brief Returns a (modifiable) reference to the constant coefficient. * * \throw std::invalid_argument if no valid linear expression has been defined. */ coeff& get_cst(); /*! \brief Returns a reference to the constant coefficient. * * \throw std::invalid_argument if no valid linear expression has been defined. */ const coeff& get_cst() const; /*! \brief Returns a (modifiable) reference to the coefficient corresponding to the given variable name. * * \throw std::invalid_argument if the variable name is not present in the environment. * \throw std::invalid_argument if no valid linear expression has been defined. */ coeff& operator[](const var& v); /*! \brief Returns a reference to the coefficient corresponding to the given variable name. * * \throw std::invalid_argument if the variable name is not present in the environment. * \throw std::invalid_argument if no valid linear expression has been defined. */ const coeff& operator[](const var& v) const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ //! Printing. friend std::ostream& operator<< (std::ostream& os, const generator1& s); //! Prints to a C stream. void print(FILE* stream=stdout) const; //@} /* TODO: intelligent constructors */ /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. const ap_generator1_t* get_ap_generator1_t() const; //! Returns a pointer to the internal APRON object stored in *this. ap_generator1_t* get_ap_generator1_t(); //@} }; /* ================================= */ /* generator1_array */ /* ================================= */ /*! \brief Array of generators (ap_generator1_array_t wrapper). * * Level 1 version of linear generator arrays. * Internally, a generator1_array wraps together a generator0_array (memory managed) and an environment * (holding a reference count). * Please note that all generators share the same environment! */ class generator1_array : public use_malloc { protected: ap_generator1_array_t a; //!< Structure managed by APRON. //! Internal use only. Shallow copy (no copy of generator0_array or environment). generator1_array(ap_generator1_array_t& a); friend class abstract1; public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ /*! \brief Creates a new generator array from a generator0_array (copied) and an environment (reference count * incremented) associating names to dimensions. */ generator1_array(const environment& e, const generator0_array& x); /*! \brief Creates a new array of the given size containing uninitialized generators. * * has_linexpr will return false on all elements of the array. * \arg \c e associates a variable name to each dimension (reference count incremented). */ generator1_array(const environment& e, size_t size); //! (Deep) copy. generator1_array(const generator1_array& x); /*! \brief Makes a (deep) copy of x and extends its environment. * * \throw std::invalid_argument if e is not a super-environment of that of x. */ generator1_array(const generator1_array& x, const environment& e); /*! \brief Creates a generator1_array from an array (of size >0) of generators of the given size (copied). * * \warning assumes that all generators have the same environment (unchecked). * \throw std::invalid_argument if size<1. */ generator1_array(size_t size, const generator1 x[]); /*! \brief Creates a generator1_array from an vector (of size >0) of generators of the given size (copied). * * \warning assumes that all generators have the same environment (unchecked). * \throw std::invalid_argument if vector size<1. */ generator1_array(const std::vector& x); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ /*! \brief Frees the space used by the array and all its generators, and decrements the * reference count of the environment. */ ~generator1_array(); //@} /* assignment */ /* ========== */ /** @name Assignments */ //@{ //! (Deep) copy. generator1_array& operator= (const generator1_array& x); /*! \brief Copies the generators from the array into *this. * * \warning assumes that all generators have the same environment (unchecked). * \arg x should contain (at least) size elements. */ generator1_array& operator= (const generator1 x[]); /*! Copies the generators from the vector into the array, changing its size if needed. * * \warning assumes that all generators have the same environment (unchecked). */ generator1_array& operator= (const std::vector& x); //@} /* dimension operations */ /* ==================== */ /** @name Dimension operations */ //@{ //! Resizes the array. void resize(size_t size); /*! \brief Extends the environment of all generators in the array. * * \throw std::invalid_argument if e is not a super-environment of that of *this. */ void extend_environment(const environment& e); //@} /* access */ /* ====== */ /** @name Accesses */ //@{ //! Returns the size of the array. size_t size() const; //! Returns the environment shared by all generators (with incremented reference count). environment get_environment() const; //! Returns a reference to the underlying generator0_array. const generator0_array& get_generator0_array() const; //! Returns a (modifiable) reference to the underlying generator0_array. generator0_array& get_generator0_array(); /*! \brief Returns a copy of the generator at index i. * * \throw std::out_of_range if i exceeds the dimension of the array. */ generator1 get(size_t i) const; /*! \brief Changes the generator at index i. * * \warning assumes that x and *this have equal environments. * \throw std::out_of_range if i exceeds the dimension of the array. */ void set(size_t i, const generator1& x); //@} /* conversion */ /* ========== */ /** @name Conversion */ //@{ //! Returns a copy of the linear generators in the form of a vector. operator std::vector() const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ /*! \brief Printing. * * \throw std::invalid_argument an underlying expression is missing, or an * auxiliary scalar is missing (for modulo generator). */ friend std::ostream& operator<< (std::ostream& os, const generator1_array& s); //! Prints to a C stream. void print(FILE* stream=stdout) const; //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. const ap_generator1_array_t* get_ap_generator1_array_t() const; //! Returns a pointer to the internal APRON object stored in *this. ap_generator1_array_t* get_ap_generator1_array_t(); //@} }; #include "apxx_generator1_inline.hh" } #endif /* __APXX_GENERATOR1_HH */ apron-dist-0.9.10/apron/apronxx/apxx_lincons1_inline.hh0000640014525101416610000003273510703144237023043 0ustar bjeannetpopart/* -*- C++ -*- * apxx_lincons1_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ /* ================================= */ /* lincons1 */ /* ================================= */ /* constructors */ /* ============ */ inline lincons1::lincons1(ap_lincons1_t p) : l(p) {} inline lincons1::lincons1(const environment& e, const lincons0& x) { l = ap_lincons1_of_lincons0(const_cast(e.get_ap_environment_t()), ap_lincons0_copy(const_cast(x.get_ap_lincons0_t()))); } inline lincons1::lincons1(const environment& e, ap_constyp_t constyp) { ap_linexpr1_t llin = ap_linexpr1_make(const_cast(e.get_ap_environment_t()), AP_LINEXPR_SPARSE, 0); l = ap_lincons1_make(constyp, &llin, NULL); } inline lincons1::lincons1(ap_constyp_t constyp, const linexpr1& lin) { ap_linexpr1_t llin = ap_linexpr1_copy(const_cast(lin.get_ap_linexpr1_t())); l = ap_lincons1_make(constyp, &llin, NULL); } inline lincons1::lincons1(ap_constyp_t constyp, const linexpr1& lin, const scalar& modulo) { ap_linexpr1_t llin = ap_linexpr1_copy(const_cast(lin.get_ap_linexpr1_t())); ap_scalar_t* mmodulo = ap_scalar_alloc_set(const_cast(modulo.get_ap_scalar_t())); l = ap_lincons1_make(constyp, &llin, mmodulo); } inline lincons1::lincons1(const environment& e, unsat x) { l = ap_lincons1_make_unsat(const_cast(e.get_ap_environment_t())); } inline lincons1::lincons1(const lincons1& x) { l = ap_lincons1_copy(const_cast(&x.l)); } inline lincons1::lincons1(const lincons1& x, const environment& e) { if (!x.has_linexpr()) throw std::invalid_argument("apron::lincons1::lincons1(const lincons1&, const environment&) empty expression"); bool r = ap_lincons1_extend_environment(&l, const_cast(&x.l), const_cast(e.get_ap_environment_t())); if (r) throw std::invalid_argument("apron::lincons1::lincons1(const lincons1&, const environment&) not a super-environment"); } /* destructor */ /* ========== */ inline lincons1::~lincons1() { ap_lincons1_clear(&l); } /* assignment */ /* ========== */ inline lincons1& lincons1::operator= (const lincons1& x) { ap_lincons1_t ll = ap_lincons1_copy(const_cast(&x.l)); ap_lincons1_clear(&l); l = ll; return *this; } inline lincons1& lincons1::operator= (unsat x) { ap_lincons1_t ll = ap_lincons1_make_unsat(ap_lincons1_envref(&l)); ap_lincons1_clear(&l); l = ll; return *this; } inline void lincons1::set_modulo(const scalar& c) { get_lincons0().set_modulo(c); } inline void lincons1::set_linexpr(const linexpr1& c) { get_lincons0().set_linexpr(c.get_linexpr0()); } /* dimension operations */ /* ==================== */ inline void lincons1::extend_environment(const environment& e) { if (!has_linexpr()) throw std::invalid_argument("apron::lincons1::extend_environment(const environment&) empty expression"); bool r = ap_lincons1_extend_environment_with(&l, const_cast(e.get_ap_environment_t())); if (r) throw std::invalid_argument("apron::lincons1::extend_environment(const environment&) not a super-environment"); } /* access */ /* ====== */ inline environment lincons1::get_environment() const { return (ap_environment_copy(ap_lincons1_envref(const_cast(&l)))); } inline const lincons0& lincons1::get_lincons0() const { return reinterpret_cast(*ap_lincons1_lincons0ref(const_cast(&l))); } inline lincons0& lincons1::get_lincons0() { return reinterpret_cast(*ap_lincons1_lincons0ref(&l)); } inline size_t lincons1::size() const { return get_lincons0().size(); } inline ap_constyp_t& lincons1::get_constyp() { return get_lincons0().get_constyp(); } inline const ap_constyp_t& lincons1::get_constyp() const { return get_lincons0().get_constyp(); } inline bool lincons1::has_modulo() const { return get_lincons0().has_modulo(); } inline bool lincons1::has_linexpr() const { return get_lincons0().has_linexpr(); } inline scalar& lincons1::get_modulo() { if (!has_modulo()) throw std::invalid_argument("apron::lincons1::get_modulo() empty scalar"); return get_lincons0().get_modulo(); } inline const scalar& lincons1::get_modulo() const { if (!has_modulo()) throw std::invalid_argument("apron::lincons1::get_modulo() empty scalar"); return get_lincons0().get_modulo(); } inline linexpr1 lincons1::get_linexpr() const { if (!has_linexpr()) throw std::invalid_argument("apron::lincons1::get_linexpr() empty expression"); linexpr0 ll = get_lincons0().get_linexpr(); return linexpr1(get_environment(),ll); } inline coeff& lincons1::get_cst() { if (!has_linexpr()) throw std::invalid_argument("apron::lincons1::get_cst() empty expression"); return reinterpret_cast(*ap_lincons1_cstref(&l)); } inline const coeff& lincons1::get_cst() const { if (!has_linexpr()) throw std::invalid_argument("apron::lincons1::get_cst() empty expression"); return reinterpret_cast(*ap_lincons1_cstref(const_cast(&l))); } inline coeff& lincons1::operator[](const var& var) { if (!has_linexpr()) throw std::invalid_argument("apron::lincons1::operator[](const var&) empty expression"); ap_coeff_t* x = ap_lincons1_coeffref(&l, const_cast(var.get_ap_var_t())); if (!x) throw std::invalid_argument("apron::lincons1::operator[](const var&) variable not in environment"); return reinterpret_cast(*x); } inline const coeff& lincons1::operator[](const var& var) const { if (!has_linexpr()) throw std::invalid_argument("apron::lincons1::operator[](const var&) empty expression"); ap_coeff_t* x = ap_lincons1_coeffref(const_cast(&l), const_cast(var.get_ap_var_t())); if (!x) throw std::invalid_argument("apron::lincons1::operator[](const var&) variable not in environment"); return reinterpret_cast(*x); } /* print */ /* ===== */ inline std::ostream& operator<< (std::ostream& os, const lincons1& s) { os << s.get_linexpr(); switch (s.get_constyp()) { case AP_CONS_EQ: return os << " = 0"; case AP_CONS_SUPEQ: return os << " >= 0"; case AP_CONS_SUP: return os << " > 0"; case AP_CONS_EQMOD: return os << " = 0 mod " << s.get_modulo(); case AP_CONS_DISEQ: return os << " != 0"; default: throw std::invalid_argument("apron::operator<<(ostream&, const lincons1&) invalid constraint type"); } } inline void lincons1::print(FILE* stream) const { ap_lincons1_fprint(stream, const_cast(&l)); } /* tests */ /* ===== */ inline bool lincons1::is_unsat() const { return ap_lincons1_is_unsat(const_cast(&l)); } inline bool lincons1::is_linear() const { return get_lincons0().is_linear(); } inline bool lincons1::is_quasilinear() const { return get_lincons0().is_quasilinear(); } /* C-level compatibility */ /* ===================== */ inline const ap_lincons1_t* lincons1::get_ap_lincons1_t() const { return &l; } inline ap_lincons1_t* lincons1::get_ap_lincons1_t() { return &l; } /* ================================= */ /* lincons1_array */ /* ================================= */ /* constructors */ /* ============ */ inline lincons1_array::lincons1_array(ap_lincons1_array_t& a) : a(a) {} inline lincons1_array::lincons1_array(const environment& e, const lincons0_array& x) { size_t sz = x.size(); a = ap_lincons1_array_make(const_cast(e.get_ap_environment_t()), sz); for (size_t i=0; i(e.get_ap_environment_t()), size); } inline lincons1_array::lincons1_array(const lincons1_array& x) { size_t sz = x.size(); a = ap_lincons1_array_make(x.get_environment().get_ap_environment_t(), sz); for (size_t i=0; i(&x.a), const_cast(e.get_ap_environment_t())); if (r) throw std::invalid_argument("apron::lincons1_array::lincons1_array(const lincons1_array, const environment&) not a super-environment"); } inline lincons1_array::lincons1_array(size_t sz, const lincons1 x[]) { if (sz<1) throw std::invalid_argument("apron::lincons1_array::lincons1_array(size_t, const lincons1) null size"); a = ap_lincons1_array_make(x[0].get_environment().get_ap_environment_t(), sz); for (size_t i=0; i (x[i].get_lincons0().get_ap_lincons0_t())); } inline lincons1_array::lincons1_array(const std::vector& x) { size_t sz = x.size(); if (sz<1) throw std::invalid_argument("apron::lincons1_array::lincons1_array(const vector&) null size"); a = ap_lincons1_array_make(x[0].get_environment().get_ap_environment_t(), sz); for (size_t i=0; i (x[i].get_lincons0().get_ap_lincons0_t())); } /* destructor */ /* ========== */ inline lincons1_array::~lincons1_array() { ap_lincons1_array_clear(&a); } /* assignment */ /* ========== */ inline lincons1_array& lincons1_array::operator= (const lincons1_array& x) { if (this!=&x) { size_t sz = x.size(); ap_lincons1_array_clear(&a); a = ap_lincons1_array_make(x.get_environment().get_ap_environment_t(), sz); for (size_t i=0; i (x[i].get_lincons0().get_ap_lincons0_t())); } return *this; } inline lincons1_array& lincons1_array::operator= (const std::vector& x) { size_t size = x.size(); if (size<1) { ap_lincons1_array_t aa = ap_lincons1_array_make(a.env,0); ap_lincons1_array_clear(&a); a = aa; return *this; } ap_lincons1_array_clear(&a); a = ap_lincons1_array_make(x[0].get_environment().get_ap_environment_t(), size); for (size_t i=0; i (x[i].get_lincons0().get_ap_lincons0_t())); return *this; } /* dimension operations */ /* ==================== */ inline void lincons1_array::resize(size_t size) { ap_lincons0_array_resize(&a.lincons0_array, size); } inline void lincons1_array::extend_environment(const environment& e) { bool r = ap_lincons1_array_extend_environment_with(&a, const_cast(e.get_ap_environment_t())); if (r) throw std::invalid_argument("apron::lincons1_array::extend_environment(const environment&) not a super-environment"); } /* access */ /* ====== */ inline size_t lincons1_array::size() const { return ap_lincons1_array_size(const_cast(&a)); } inline environment lincons1_array::get_environment() const { return (ap_environment_copy(ap_lincons1_array_envref(const_cast(&a)))); } inline const lincons0_array& lincons1_array::get_lincons0_array() const { return reinterpret_cast(const_cast(a.lincons0_array)); } inline lincons0_array& lincons1_array::get_lincons0_array() { return reinterpret_cast(a.lincons0_array); } inline lincons1 lincons1_array::get(size_t i) const { if (i>=size()) throw std::out_of_range("apron::lincons1_array::get(size_t)"); ap_lincons1_t c = ap_lincons1_array_get(const_cast(&a),i); return lincons1(ap_lincons1_copy(&c)); } inline void lincons1_array::set(size_t i, const lincons1& x) { if (i>=size()) throw std::out_of_range("apron::lincons1_array::set(size_t, const lincons1&)"); ap_lincons0_clear(&a.lincons0_array.p[i]); a.lincons0_array.p[i] = ap_lincons0_copy(const_cast (x.get_lincons0().get_ap_lincons0_t())); } /* conversion */ /* ========== */ inline lincons1_array::operator std::vector() const { size_t sz = size(); lincons1 dummy(get_environment(),unsat()); std::vector v(sz,dummy); for (size_t i=0;i(&a),i); v[i] = ap_lincons1_copy(&c); } return v; } /* print */ /* ===== */ inline std::ostream& operator<< (std::ostream& os, const lincons1_array& s) { size_t sz = s.size(); os << "{ "; for (size_t i=0;i(&a)); } /* C-level compatibility */ /* ===================== */ inline const ap_lincons1_array_t* lincons1_array::get_ap_lincons1_array_t() const { return &a; } inline ap_lincons1_array_t* lincons1_array::get_ap_lincons1_array_t() { return &a; } apron-dist-0.9.10/apron/apronxx/apxx_ppl_product_inline.hh0000640014525101416610000000106610703144237023641 0ustar bjeannetpopart/* -*- C++ -*- * apxx_ppl_product_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library. As it includes both APRON and PPL files, it is released under GPL license. Please read the ppl/COPYING file packaged in the distribution. */ inline pkgrid_manager::pkgrid_manager(bool strict) : manager(ap_pkgrid_manager_alloc(strict)) {} inline manager& pkgrid_manager::operator=(const manager& m) { return manager::operator=(m); } apron-dist-0.9.10/apron/apronxx/apronxx_test_result.txt0000640014525101416610000037371110703144237023275 0ustar bjeannetpopart scalars ======= construct 2: 2 construct 2L: 2 construct 2.: 2 construct frac(1,5): 1/5 construct infty(-1): -oo construct mpq_class(1,5): 1/5 copy 12: 12 assign 2: 2 assign 2.: 2 assign frac(1,5): 1/5 copy 12: 12 before swap 12 5: 12 5 after swap 5 12: 5 12 chain assign 2: 2 2 chain assign 2.: 2 2 get_double 15.: 15 array 12 0 12: 12 0 12 neg -12 -12: -12 -12 inv -1/12 -1/12: -1/12 -1/12 print: -1/12 hash: 1537228672809129301 intervals ========= construct 0: [0,0] construct scalar(12): [12,15] construct [12,15]: [12,15] construct [12L,15L]: [12,15] construct [5.,18.]: [5,18] construct [frac(1,2),frac(5,4)]: [1/2,5/4] construct [mpq(15,3),15]: [15/3,15] construct top: [-oo,+oo] construct bottom: [1,-1] copy [-5,5]: [-5,5] assign top: [-oo,+oo] assign bottom: [1,-1] copy [-5,5]: [-5,5] set [scalar(5),scalar(19)]: [5,19] set [12,18]: [12,18] set [12.,18.]: [12,18] set [frac(1,2),frac(3,4)]: [1/2,3/4] set [mpq(8),mpq(10)]: [8,10] set top: [-oo,+oo] set bottom: [1,-1] set interval(-5,5): [-5,5] after swap top [-5,5]: [-oo,+oo] [-5,5] chain assign [1,2]: [1,2] [1,2] chain assign top: [-oo,+oo] [-oo,+oo] get_inf: [-1,2]: [-1,2] get_sup [-1,1/2]: [-1,1/2] array [12,13] 0 [12,13]: [12,13] [0,0] [12,13] neg [-2,-1] [-2,-1]: [-2,-1] [-2,-1] print: [-2,-1] hash: -4 interval arrays =============== construct a: 4 { [0,0] [1,2] [1,2] [-oo,+oo] } copy a: 4 { [0,0] [1,2] [1,2] [-oo,+oo] } empty: 3 { [0,0] [0,0] [0,0] } copy a: 4 { [0,0] [1,2] [1,2] [-oo,+oo] } from vector v: 3 { [1,2] [0,0] [0,0] } from vector v: 3 { [1,2] [0,0] [0,0] } chain assign a: 4 { [0,0] [1,2] [1,2] [-oo,+oo] } to vector v: 3 { [1,2] [0,0] [0,0] } print v: { [1,2] [0,0] [0,0] } coeff ===== construct 0: 0 construct 2: 2 construct scalar(frac(2,3)): 2/3 construct 2: 2 construct 2L: 2 construct 2.5: 2.5 construct frac(2,3): 2/3 construct mpq(2,3): 2/3 construct interval(1,2): [1,2] construct [scalar(1),scalar(2)]: [1,2] construct [1,2]: [1,2] construct [1L,2L]: [1,2] construct [1.1,2.2]: [1.1,2.2] construct [frac(1,2),frac(3,4)]: [1/2,3/4] construct [mpq(1,2),mpq(3,4)]: [1/2,3/4] construct top: [-oo,+oo] construct bottom: [1,-1] assign coeff(2): 2 assign scalar(2): 2 assign 2: 2 assign 2L: 2 assign 2.5: 2.5 assign frac(1,2): 1/2 assign mpq(1,2): 1/2 assign interval(1,2): [1,2] assign top: [-oo,+oo] assign bottom: [1,-1] set coeff(2): 2 set scalar(2): 2 set 2: 2 set 2L: 2 set 2.: 2 set frac(1,2): 1/2 set mpq(1,2): 1/2 set interval(1,2): [1,2] set [scalar(1),scalar(2)]: [1,2] set [1,2]: [1,2] set [1L,2L]: [1,2] set [1.1,2.2]: [1.1,2.2] set [frac(1,2),frac(3,4)]: [1/2,3/4] set [mpq(1,2),mpq(3,4)]: [1/2,3/4] set top: [-oo,+oo] set bottom: [1,-1] before swap 2 3: 2 3 after swap 3 2: 3 2 chain assign frac(1,2): 1/2 1/2 chain assign [1.,2.]: [1,2] [1,2] get_scalar 3: 3 get_interval [0,2]: [0,2] before reduce [1,1]: [1,1] after reduce 1: 1 neg [-5,-3] [-5,-3]: [-5,-3] [-5,-3] hash: -11 print: [-5,-3] dimchange ========= from array 1 2 3: dimchange: intdim=1, realdim=2 x1 x2 x3 from array 3 2 1: dimchange: intdim=1, realdim=2 x3 x2 x1 1 2 3 2 copy 3 2 1: dimchange: intdim=1, realdim=2 x3 x2 x1 copy 12 2 1: dimchange: intdim=1, realdim=2 x12 x2 x1 from vector 4 5 6: dimchange: intdim=1, realdim=2 x4 x5 x6 from vector 4 5 6: dimchange: intdim=1, realdim=2 x4 x5 x6 invert: dimchange: intdim=1, realdim=2 x4 x6 x8 invert: dimchange: intdim=1, realdim=2 x4 x6 x8 invert: dimchange: intdim=1, realdim=2 x4 x6 x8 print: dimchange: intdim=1, realdim=2 4 6 8 print w/ names: dimchange: intdim=1, realdim=2 x4 x6 x8 dimperm ======= identity: dimperm: size=3 x0 -> x0 x1 -> x1 x2 -> x2 from array 1 0 2: dimperm: size=3 x0 -> x1 x1 -> x0 x2 -> x2 identity: dimperm: size=3 x0 -> x0 x1 -> x1 x2 -> x2 from array 1 2 0: dimperm: size=3 x0 -> x1 x1 -> x2 x2 -> x0 3 1 2 copy 1 2 0: dimperm: size=3 x0 -> x1 x1 -> x2 x2 -> x0 copy 12 2 0: dimperm: size=3 x0 -> x12 x1 -> x2 x2 -> x0 from vector 2 0 1: dimperm: size=3 x0 -> x2 x1 -> x0 x2 -> x1 from vector 2 0 1: dimperm: size=3 x0 -> x2 x1 -> x0 x2 -> x1 from vector 2 0 1: dimperm: size=3 x0 -> x2 x1 -> x0 x2 -> x1 invert 1 2 0: dimperm: size=3 x0 -> x1 x1 -> x2 x2 -> x0 invert 1 2 0: dimperm: size=3 x0 -> x1 x1 -> x2 x2 -> x0 invert 1 2 0: dimperm: size=3 x0 -> x1 x1 -> x2 x2 -> x0 compose 2 0 1: dimperm: size=3 x0 -> x2 x1 -> x0 x2 -> x1 compose 2 0 1: dimperm: size=3 x0 -> x2 x1 -> x0 x2 -> x1 invert 1 2 0: dimperm: size=3 x0 -> x1 x1 -> x2 x2 -> x0 print: dimperm: size=3 0 -> 1 1 -> 2 2 -> 0 print w/ names: dimperm: size=3 x -> y y -> z z -> x dense linexpr0 ============== construct: 5, 0 get_ 1/4x0 - 2x3 + [1,2]: 5, 1/4x0 - 2x3 + [1,2] copy 1/4x0 + [-oo,+oo]x2 - 2x3 + [1,2]: 5, 1/4x0 + [-oo,+oo]x2 - 2x3 + [1,2] copy 1/4x0 - 2x3 + [1,2]: 5, 1/4x0 - 2x3 + [1,2] [1]: 0 from array 1x0 + 2x1 + [0,1]x2 + 2: 3, x0 + 2x1 + [0,1]x2 + 2 chained copy 1/4x0 - 2x3 + [1,2]: 5, 1/4x0 - 2x3 + [1,2] [] 1/4x0 + [0,1]x2 - 2x3 + [1,2]: 5, 1/4x0 + [0,1]x2 - 2x3 + [1,2] copy 1/4x0 - 2x3 + [1,2]: 5, 1/4x0 - 2x3 + [1,2] after swap: 5, 1/4x0 - 2x3 + [1,2] after swap: 5, 1/4x0 + [0,1]x2 - 2x3 + [1,2] const iterator: 1/4 0 [0,1] -2 0 iterate neg -1/4x0 + [-1,0]x2 + 2x3 + [1,2]: 5, - 1/4x0 + [-1,0]x2 + 2x3 + [1,2] resize 1/4x0 + [1,2]: 3, 1/4x0 + [1,2] [] [3,3]x0 + [1,2]: 3, [3,3]x0 + [1,2] minimize 3x0 + [1,2]: 3, 3x0 + [1,2] add dims: 3x1 + [1,2]: 3x1 + [1,2] add_dims: 3x1 + [1,2]: 3x1 + [1,2] permute: [3,4]x0 + 3x1 + [1,2]: [3,4]x0 + 3x1 + [1,2] permute: 3x0 + [3,4]x1 + [1,2]: 3x0 + [3,4]x1 + [1,2] hash: 793 print: 3x0 + [3,4]x1 + [1,2] print w/ names: 3x + [3,4]y + [1,2] sparse linexpr0 =============== construct: 5, 0 get_ 1/4x0 - 2x3 + [1,2]: 5, 1/4x0 - 2x3 + [1,2] copy 1/4x0 + [-oo,+oo]x2 - 2x3 + [1,2]: 5, 1/4x0 + [-oo,+oo]x2 - 2x3 + [1,2] copy 1/4x0 - 2x3 + [1,2]: : 5, 1/4x0 - 2x3 + [1,2] [1] 0 from array 1x0 + 2x1 + [0,1]x2 + 2: 3, x0 + 2x1 + [0,1]x2 + 2 chained copy 1/4x0 - 2x3 + [1,2]: 5, 1/4x0 - 2x3 + [1,2] copy 1/4x0 + [0,1]x2 - 2x3 + [1,2]: 5, 1/4x0 + [0,1]x2 - 2x3 + [1,2] copy 1/4x0 - 2x3 + [1,2]: 5, 1/4x0 - 2x3 + [1,2] after swap: 5, 1/4x0 - 2x3 + [1,2] after swap: 5, 1/4x0 + [0,1]x2 - 2x3 + [1,2] const iterator: 1/4 0 [0,1] -2 iterate neg -1/4x0 + [-1,0]x2 + 2x3 + [1,2]: 5, - 1/4x0 + [-1,0]x2 + 2x3 + [1,2] get_ [] 1/4x0 - 2x3 + 1/2x4 + [0,1]x5 + [1,2]: 5, 1/4x0 - 2x3 + 1/2x4 + [0,1]x5 + [1,2] get_ [] 1/4x0 + 6x1 - 2x3 + 1/2x4 + [0,1]x5 + 5x6 + 5x7 + [1,2]: 7, 1/4x0 + 6x1 - 2x3 + 1/2x4 + [0,1]x5 + 5x6 + 5x7 + [1,2] before minimize: 7, [3,3]x0 - 2x3 + 1/2x4 + [0,1]x5 + 5x6 + 5x7 + [1,2] after minimize: 6, 3x0 - 2x3 + 1/2x4 + [0,1]x5 + 5x6 + 5x7 + [1,2] add dims 3x1 - 2x5 + 1/2x6 + [0,1]x7 + 5x8 + 5x9 + [1,2]: 3x1 - 2x5 + 1/2x6 + [0,1]x7 + 5x8 + 5x9 + [1,2] add_dims 3x1 - 2x5 + 1/2x6 + [0,1]x7 + 5x8 + 5x9 + [1,2]: 3x1 - 2x5 + 1/2x6 + [0,1]x7 + 5x8 + 5x9 + [1,2] permute -2x0 + 3x3 + 1/2x4 + [0,1]x5 + 5x6 + 5x7 + [1,2]: - 2x0 + 3x3 + 1/2x4 + [0,1]x5 + 5x6 + 5x7 + [1,2] permute 3x0 - 2x3 + 1/2x4 + [0,1]x5 + 5x6 + 5x7 + [1,2]: 3x0 - 2x3 + 1/2x4 + [0,1]x5 + 5x6 + 5x7 + [1,2] hash: 2547 print: 3x0 - 2x3 + 1/2x4 + [0,1]x5 + 5x6 + 5x7 + [1,2] print w/ names: 3x - 2t + 1/2x4 + [0,1]x5 + 5x6 + 5x7 + [1,2] lincons0 ======== construct: 0 >= 0 construct 1x0 + 2x1 + 3x2 + 4 = 0: x0 + 2x1 + 3x2 + 4 = 0 construct 1x0 + 2x1 + 3x2 + 4 >= 0: x0 + 2x1 + 3x2 + 4 >= 0 construct 1x0 + 2x1 + 3x2 + 4 > 0: x0 + 2x1 + 3x2 + 4 > 0 construct 1x0 + 2x1 + 3x2 + 4 != 0: x0 + 2x1 + 3x2 + 4 != 0 construct 1x0 + 2x1 + 3x2 + 4 = 0 mod 5: x0 + 2x1 + 3x2 + 4 = 0 mod 5 copy 1x0 + 2x1 + 3x2 + 4 = 0: x0 + 2x1 + 3x2 + 4 = 0 dimchange 1x1 + 2x2 + 3x4 + 4 = 0: x1 + 2x2 + 3x4 + 4 = 0 dimperm 2x0 + 1x1 + 3x2 + 4 = 0: 2x0 + x1 + 3x2 + 4 = 0 unsat: - 1 >= 0 copy 4x0 + 3x1 + 2x2 + 1x3 + 5 >= 0: 4x0 + 3x1 + 2x2 + x3 + 5 >= 0 unsat: - 1 >= 0 chained copy 1x0 + 2x1 + 3x2 + 4 = 0: x0 + 2x1 + 3x2 + 4 = 0 dimchange 1x1 + 2x2 + 3x4 + 4 = 0: x1 + 2x2 + 3x4 + 4 = 0 dimperm 2x0 + 1x1 + 3x2 + 4 = 0: 2x0 + x1 + 3x2 + 4 = 0 resize 2x0 + 1x1 + 4 = 0: 2x0 + x1 + 4 = 0 get_constyp 2x0 + 1x1 + 4 > 0: 2x0 + x1 + 4 > 0 set_modulo 2x0 + 1x1 + 4 = 0 mod 3: 2x0 + x1 + 4 = 0 mod 3 set_linexpr 1x0 + 2x1 + 3x2 + 4 = 0 mod 3: x0 + 2x1 + 3x2 + 4 = 0 mod 3 get_linexpr 4x0 + 3x1 + 2x2 + 1x3 + 5 = 0 mod 3: 4x0 + 3x1 + 2x2 + x3 + 5 = 0 mod 3 get_linexpr 4x0 + 3x1 + 2x2 + 1x3 + [1,2] = 0 mod 3: 4x0 + 3x1 + 2x2 + x3 + [1,2] = 0 mod 3 get_linexpr [0,1]x0 + 3x1 + 2x2 + 1x3 + [1,2] = 0 mod 3: [0,1]x0 + 3x1 + 2x2 + x3 + [1,2] = 0 mod 3 print: [0,1]x0 + 3x1 + 2x2 + x3 + [1,2] = 0 mod 3 print w/ names: [0,1]x + 3y + 2z + t + [1,2] = 0 mod 3 lincons0 array ============== { construct: { x0 + 2x1 + 3x2 + 4 = 0; 5x0 + 3x1 + 99 = 0; } copy: { x0 + 2x1 + 3x2 + 4 = 0; 5x0 + 3x1 + 99 = 0; } permutation: { 2x0 + x1 + 3x2 + 4 = 0; 3x0 + 5x1 + 99 = 0; } dim change: { x1 + 2x2 + 3x4 + 4 = 0; 5x1 + 3x2 + 99 = 0; } from array: { x0 + 2x1 + 3x2 + 5 = 0; 5x0 + 3x1 + 4 = 0; 5x0 + 3x1 + 3 = 0 mod 5; } from vector: { 0 >= 0; 5x0 + 3x1 + 99 = 0; } from array: { x0 + 2x1 + 3x2 + 5 = 0; 5x0 + 3x1 + 4 = 0; } from vector: { 0 >= 0; 5x0 + 3x1 + 99 = 0; } copy: { 2x0 + x1 + 3x2 + 4 = 0; 3x0 + 5x1 + 99 = 0; } dim change: { 2x1 + x2 + 3x4 + 4 = 0; 3x1 + 5x2 + 99 = 0; } permutation: { x0 + 2x1 + 3x2 + 4 = 0; 5x0 + 3x1 + 99 = 0; } size: 2 []: { 5x0 + 3x1 + [1,88] >= 0; 5x0 + 3x1 + 99 = 0; } get: { 5x0 + 3x1 + [1,88] >= 0; [0,1]x0 + 3x1 + [1,88] >= 0; } contents: { [0,1]x0 + 3x1 + [1,88] >= 0; [0,1]x0 + 3x1 + [1,88] >= 0; } to vector: 2: [0,1]x0 + 3x1 + [1,88] >= 0; [0,1]x0 + 3x1 + [1,88] >= 0 print w/ names: { [0,1]x + 3y + [1,88] >= 0; [0,1]x + 3y + [1,88] >= 0; } generator0 ========== construct: RAY: 0 construct vert 1x0 + 2x1 + 3x2 + 4: VERTEX: x0 + 2x1 + 3x2 + 4 construct ray 1x0 + 2x1 + 3x2 + 4: RAY: x0 + 2x1 + 3x2 + 4 construct line 1x0 + 2x1 + 3x2 + 4: LINE: x0 + 2x1 + 3x2 + 4 construct modray 1x0 + 2x1 + 3x2 + 4: RAYMOD: x0 + 2x1 + 3x2 + 4 construct modline 1x0 + 2x1 + 3x2 + 4: LINEMOD: x0 + 2x1 + 3x2 + 4 copy vert 1x0 + 2x1 + 3x2 + 4: VERTEX: x0 + 2x1 + 3x2 + 4 dimchange vert 1x1 + 2x2 + 3x4 + 4: VERTEX: x1 + 2x2 + 3x4 + 4 dimperm vert 2x0 + 1x1 + 3x2 + 4: VERTEX: 2x0 + x1 + 3x2 + 4 copy ray 4x0 + 3x1 + 2x2 + 1x3 + 5: RAY: 4x0 + 3x1 + 2x2 + x3 + 5 chained copy line 1x0 + 2x1 + 3x2 + 4: LINE: x0 + 2x1 + 3x2 + 4 dimchange line 1x1 + 2x2 + 3x4 + 4: LINE: x1 + 2x2 + 3x4 + 4 dimperm line 2x0 + 1x1 + 3x2 + 4: LINE: 2x0 + x1 + 3x2 + 4 resize line 2x0 + 1x1 + 4: LINE: 2x0 + x1 + 4 get_gentyp modline 2x0 + 1x1 + 4: LINEMOD: 2x0 + x1 + 4 set_linexpr modline 1x0 + 2x1 + 3x2 + 4: LINEMOD: x0 + 2x1 + 3x2 + 4 get_linexpr modline 4x0 + 3x1 + 2x2 + 1x3 + 5: LINEMOD: 4x0 + 3x1 + 2x2 + x3 + 5 get_linexpr modline 4x0 + 3x1 + 2x2 + 1x3 + 2: LINEMOD: 4x0 + 3x1 + 2x2 + x3 + 2 get_linexpr modline 18x0 + 3x1 + 2x2 + 1x3 + 2: LINEMOD: 18x0 + 3x1 + 2x2 + x3 + 2 print: LINEMOD: 18x0 + 3x1 + 2x2 + x3 + 2 print w/ names: LINEMOD: 18x + 3y + 2z + t + 2 generator0 array ================ { construct: { VERTEX: x0 + 2x1 + 3x2 + 4; VERTEX: 5x0 + 3x1 + 99; } copy: { VERTEX: x0 + 2x1 + 3x2 + 4; VERTEX: 5x0 + 3x1 + 99; } permutation: { VERTEX: 2x0 + x1 + 3x2 + 4; VERTEX: 3x0 + 5x1 + 99; } dim change: { VERTEX: x1 + 2x2 + 3x4 + 4; VERTEX: 5x1 + 3x2 + 99; } from array: { VERTEX: x0 + 2x1 + 3x2 + 5; VERTEX: 5x0 + 3x1 + 4; RAY: 5x0 + 3x1 + 3; } from vector: { RAY: 0; VERTEX: 5x0 + 3x1 + 99; } from array: { VERTEX: x0 + 2x1 + 3x2 + 5; VERTEX: 5x0 + 3x1 + 4; } from vector: { RAY: 0; VERTEX: 5x0 + 3x1 + 99; } copy: { VERTEX: 2x0 + x1 + 3x2 + 4; VERTEX: 3x0 + 5x1 + 99; } dim change: { VERTEX: 2x1 + x2 + 3x4 + 4; VERTEX: 3x1 + 5x2 + 99; } permutation: { VERTEX: x0 + 2x1 + 3x2 + 4; VERTEX: 5x0 + 3x1 + 99; } size: 2 []: { LINE: 5x0 + 3x1 + 88; VERTEX: 5x0 + 3x1 + 99; } get: { LINE: 5x0 + 3x1 + 88; RAY: 99x0 + 3x1 + 88; } contents: { RAY: 99x0 + 3x1 + 88; RAY: 99x0 + 3x1 + 88; } to vector: 2: RAY: 99x0 + 3x1 + 88; RAY: 99x0 + 3x1 + 88 print w/ names: { RAY: 99x + 3y + 88; RAY: 99x + 3y + 88; } texpr0 ====== construct 2: 2 construct 2L: 2 construct 2.2: 2.2 construct mpq(1,2): 1/2 construct coeff(2): 2 construct scalar(2): 2 construct 1/2: 1/2 construct interval(1,2): [1,2] construct [2.2,3.3]: [2.2,3.3] construct [1/2,3/4]: [1/2,3/4] construct top: [-oo,+oo] construct x2: x2 construct +x2: x2 construct -x2: -(x2) construct x2+2: x2 + 2 construct x2-2: x2 - 2 construct x2*2: x2 * 2 construct x2/2: x2 / 2 construct x2%2: x2 % 2 construct sqrt(x2): sqrt(x2) construct float -x2: -(x2) construct float x2+2: x2 +_f,n 2 construct float x2-2: x2 -_f,n 2 construct float x2*2: x2 *_f,n 2 construct float x2/2: x2 /_f,n 2 construct float x2%2: x2 % 2 construct float sqrt(x2): sqrt_f,n(x2) construct float cast(x2): cast_f,n(x2) construct floor(x2): cast_i,-oo(x2) construct ceil(x2): cast_i,+oo(x2) construct trunc(x2): cast_i,0(x2) construct linexpr: 4 + 1 * x0 + 2 * x1 + 3 * x2 copy x=2+3*x0: 2 + 3 * x0 construct (x+x)/(x*x): (2 + 3 * x0 + (2 + 3 * x0)) / ((2 + 3 * x0) * (2 + 3 * x0)) construct x0 + 2: x0 + 2 construct x0 + 2L: x0 + 2 construct x0 + 2.2: x0 + 2.2 construct x0 + mpq(1,2): x0 + 1/2 construct x0 + coeff(2): x0 + 2 construct x0 + scalar(2): x0 + 2 construct x0 + 1/2: x0 + 1/2 construct x0 + interval(1,2): x0 + [1,2] construct x0 + [2,3]: x0 + [2,3] construct x0 + [2L,3L]: x0 + [2,3] construct x0 + [2.2,3.3]: x0 + [2.2,3.3] construct x0 + [1/2,3/4]: x0 + [1/2,3/4] construct x0 + top: x0 + [-oo,+oo] construct x0 + x2: x0 + x2 construct x0 + linexpr: x0 + (4 + 1 * x0 + 2 * x1 + 3 * x2) assign 2: 2 assign 2L: 2 assign 2.2: 2.2 assign mpq(1,2): 1/2 assign coeff(2): 2 assign scalar(2): 2 assign interval(1,2): [1,2] assign top: [-oo,+oo] assign x2: x2 assign linexpr: 4 + 1 * x0 + 2 * x1 + 3 * x2 assign x: 2 + 3 * x0 assign x+1: 2 + 3 * x0 + 1 assign x*x: (2 + 3 * x0) * (2 + 3 * x0) chained assign sqrt(x0+1): sqrt(x0 + 1); sqrt(x0 + 1) add dim x1/x2: x1 / x2 del dim ]-oo;+oo[/x0: [-oo,+oo] / x0 dim perm x1/x0: x1 / x0 add dim x1/x2: x1 / x2 del dim x0/x1: x0 / x1 dim perm x1/x0: x1 / x0 dim mix x0/x1+x0/]-oo;+oo[: x0 / x1 + x0 / [-oo,+oo] get_coeff [1,2]: [1,2] get_dim 3: x3 get_op rtype rdir argA argB: 2 -_d,0 x1 get: sqrt_f,n(x1 + 5) set: cast_d,0(2 + x3) x0 + x5 + x2 iterator -> texpr0 x0+x5: x0 + x5 iterator assign x2: x2 construct from iterators x0+x5-x2: x0 + x5 - x2 subst: sqrt(x0 + 1 + 2 * x1 * x1) subst: sqrt(x0 + 2 * (sqrt(x0) + 1) * (sqrt(x0) + 1)) hash: 9928367581043 print: sqrt(x0 + 2 * x1 * x1) print w/ names: sqrt(x + 2 * y * y) tcons0 ====== construct x0 + 1 = 0: x0 + 1 = 0 construct floor(x0+2) >= 0: cast_i,-oo(x0 + 2) >= 0 construct x0*x1 > 0: x0 * x1 > 0 construct [-1,1]*x0 != 0: [-1,1] * x0 != 0 construct x0/x1 = 0 mod 5: x0 / x1 = 0 mod 5 from lincons 1x0+2x1+3x2+4 = 0: 4 + 1 * x0 + 2 * x1 + 3 * x2 = 0 construct x0 >= x2+1: x0 - (x2 + 1) >= 0 construct x0 <= x2+1: x2 + 1 - x0 >= 0 construct x0 > x2+1: x0 - (x2 + 1) > 0 construct x0 < x2+1: x2 + 1 - x0 > 0 construct x0 == x2+1: x0 - (x2 + 1) = 0 construct x0 != x2+1: x0 - (x2 + 1) != 0 construct x0 == 0: x0 = 0 construct 0 != x2+1: x2 + 1 != 0 copy x0 * x2 = 0: x0 * x2 = 0 dimchange x1 * x4 = 0: x1 * x4 = 0 dimperm x1 * x2 = 0: x1 * x2 = 0 unsat: -1 >= 0 unsat: -1 >= 0 from lincons 1x0+2x1+3x2+4 = 0: 4 + 1 * x0 + 2 * x1 + 3 * x2 = 0 chained copy x0 * x2 +2 = 0: x0 * x2 + 2 = 0 dimchange x1 * x4 + 2 = 0: x1 * x4 + 2 = 0 dimchange ]-oo;+oo[ * x1 + 2 = 0: [-oo,+oo] * x1 + 2 = 0 dimperm x1 * x2 + 2 = 0: x1 * x2 + 2 = 0 get_constyp x1 * x2 + 2 > 0: x1 * x2 + 2 > 0 set_modulo x1 * x2 + 2 = 0 mod 3: x1 * x2 + 2 = 0 mod 3 set_texpr sqrt(x0+1) = 0 mod 3: sqrt(x0 + 1) = 0 mod 3 get_texpr x0/x1+5 = 0 mod 3: x0 / x1 + 5 = 0 mod 3 get_texpr [0,1]/x1+5 = 0 mod 3: [0,1] / x1 + 5 = 0 mod 3 print: [0,1] / x1 + 5 = 0 mod 3 print w/ names: [0,1] / y + 5 = 0 mod 3 tcons0 array ============ { construct: { sqrt(x0 + 15 * x2) >= 0; [2,5] = 0; } copy: { sqrt(x0 + 15 * x2) >= 0; [2,5] = 0; } permutation: { sqrt(x1 + 15 * x2) >= 0; [2,5] = 0; } add dim: { sqrt(x1 + 15 * x4) >= 0; [2,5] = 0; } rem dim: { sqrt([-oo,+oo] + 15 * [-oo,+oo]) >= 0; [2,5] = 0; } from array: { x0 * x1 * x2 >= 0; x0 % x1 = 0; [1,2] * x0 = 0 mod 5; } from vector: { 0 = 0; 1 - x5 = 0; } from array: { x0 * x1 * x2 >= 0; x0 % x1 = 0; } from vector: { 0 = 0; 1 - x5 = 0; } copy: { sqrt(x0 + 15 * x2) >= 0; [2,5] = 0; } add dim: { sqrt(x1 + 15 * x4) >= 0; [2,5] = 0; } del dim: { sqrt([-oo,+oo] + 15 * [-oo,+oo]) >= 0; [2,5] = 0; } permutation: { sqrt(x1 + 15 * x2) >= 0; [2,5] = 0; } size: 2 []: { x1 * 5 + x2 >= 0; [2,5] = 0; } get: { x1 * 5 + x2 >= 0; x0 * x2 >= 0; } contents: { x0 * x2 >= 0; x0 * x2 >= 0; } to vector: 2: x0 * x2 >= 0; x0 * x2 >= 0 from lincons0_array: { 4 + 1 * x0 + 2 * x1 + 3 * x2 = 0; 99 + [0,1] * x0 + 3 * x1 = 0; } from lincons0_array: { 4 + 1 * x0 + 2 * x1 + 3 * x2 = 0; 99 + [0,1] * x0 + 3 * x1 = 0; } print: array of constraints of size 2 0: x0 * x2 >= 0 1: x0 * x2 >= 0 print w/ names: { x * z >= 0; x * z >= 0; } var === print: v1 from char*: v1 from string: v2 copy constructor: v2 copy assignment: v2 char* assignment: aa string assignment: aa to char*: aa to string: aa environment =========== empty: from vector: 0: h (int) 1: j (int) 2: e (real) 3: g (real) from array: 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) copy assignment: 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) copy constructor: 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) add array: 0: h (int) 1: i1 (int) 2: i2 (int) 3: i3 (int) 4: j (int) 5: f1 (real) 6: f2 (real) 7: f3 (real) del vector: 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) add vector: 0: h (int) 1: i1 (int) 2: i2 (int) 3: i3 (int) 4: j (int) 5: f1 (real) 6: f2 (real) 7: f3 (real) del array: 0: h (int) 1: j (int) 2: f1 (real) 3: f2 (real) 4: f3 (real) add vector w/ dimperm: 0: h (int) 1: i1 (int) 2: i2 (int) 3: i3 (int) 4: j (int) 5: f1 (real) 6: f2 (real) 7: f3 (real) dimperm: size=8 x0 -> x0 x1 -> x4 x2 -> x1 x3 -> x3 x4 -> x2 x5 -> x5 x6 -> x7 x7 -> x6 add vector w/ dimperm: 0: h (int) 1: i1 (int) 2: i2 (int) 3: i3 (int) 4: j (int) 5: f1 (real) 6: f2 (real) 7: f3 (real) dimperm: size=8 x0 -> x1 x1 -> x2 x2 -> x3 x3 -> x4 x4 -> x0 x5 -> x5 x6 -> x6 x7 -> x7 rename vector: 0: a (int) 1: i1 (int) 2: i3 (int) 3: f1 (real) 4: f3 (real) 5: z (real) rename array: 0: a (int) 1: i1 (int) 2: i3 (int) 3: f1 (real) 4: f3 (real) 5: z (real) rename vector w/ dimperm: 0: a (int) 1: i1 (int) 2: i3 (int) 3: f1 (real) 4: f3 (real) 5: z (real) dimperm: size=6 x0 -> x1 x1 -> x0 x2 -> x2 x3 -> x3 x4 -> x5 x5 -> x4 rename array w/ dimperm: 0: a (int) 1: i1 (int) 2: i3 (int) 3: f1 (real) 4: f3 (real) 5: z (real) dimperm: size=6 x0 -> x1 x1 -> x0 x2 -> x2 x3 -> x3 x4 -> x5 x5 -> x4 lub: 0: h (int) 1: i1 (int) 2: i2 (int) 3: i3 (int) 4: j (int) 5: f1 (real) 6: f2 (real) 7: f3 (real) 8: x (real) lub w/ dimchange: 0: h (int) 1: i1 (int) 2: i2 (int) 3: i3 (int) 4: j (int) 5: f1 (real) 6: f2 (real) 7: f3 (real) 8: x (real) dimchange: intdim=2, realdim=1 x0 x3 x6 dimchange: intdim=3, realdim=2 x1 x1 x1 x3 x3 n-ary vector lce: 0: h (int) 1: i1 (int) 2: i2 (int) 3: i3 (int) 4: j (int) 5: f1 (real) 6: f2 (real) 7: f3 (real) 8: x (real) n-ary vector lce w/ dimchange: 0: h (int) 1: i1 (int) 2: i2 (int) 3: i3 (int) 4: j (int) 5: f1 (real) 6: f2 (real) 7: f3 (real) 8: x (real) dimchange: intdim=2, realdim=1 x0 x3 x6 dimchange: intdim=3, realdim=2 x1 x1 x1 x3 x3 n-ary array lce: 0: h (int) 1: i1 (int) 2: i2 (int) 3: i3 (int) 4: j (int) 5: f1 (real) 6: f2 (real) 7: f3 (real) 8: x (real) n-ary array lce w/ dimchange: 0: h (int) 1: i1 (int) 2: i2 (int) 3: i3 (int) 4: j (int) 5: f1 (real) 6: f2 (real) 7: f3 (real) 8: x (real) dimchange: intdim=2, realdim=1 x0 x3 x6 dimchange: intdim=3, realdim=2 x1 x1 x1 x3 x3 iterator: i1 i2 i3 f1 f3 dimchange to super: dimchange: intdim=0, realdim=1 x4 print: environment: dim = (2,2), count = 1 0: h 1: j 2: e 3: g linexpr1 ======== from exp: i1 + 2i3 + 3f1 + 4 from exp: i1 + 2i2 + 3i3 + 4 empty: 0 copy constructor: 0: i1 (int) 1: i3 (int) 2: f1 (real) 3: f3 (real) x0 + 2x1 + 3x2 + 4 i1 + 2i3 + 3f1 + 4 copy to super: 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) x0 + 2x2 + 3x3 + 4 i1 + 2i3 + 3f1 + 4 assignment: i1 + 2i3 + 3f1 + 4 to supper: i1 + 2i3 + 3f1 + 4 to supper: i1 + 2i3 + 3f1 + 4 linepxr0: x0 + 2x1 + 3x2 + 4x3 + 4 linepxr1: i1 + 2i2 + 3i3 + 4f1 + 4 size: 4 discr: 1 cst: 4 [i2]: 2 set i3 & cst: i1 + 2i2 - 3i3 + 4f1 + 99 const iterator: 1 2 [0,1] 4 0: i1 = 1 1: i2 = 2 2: i3 = [0,1] 3: f1 = 4 after negation: - 1i1 - 2i2 + [-1,0]i3 - 4f1 + [0,1] before minimize: - 1i1 - 2i2 - 4f1 + [2,2] after minimize: - 1i1 - 2i2 - 4f1 + [2,2] i1 + 2i3 + 3f1 + 4 lincons1 ======== construct empty: 0 >= 0 construct from lincons0: i1 + 2i3 + 3f1 + 4 = 0 construct from linexpr1: i1 + 2i3 + 3f1 + 4 >= 0 construct from linexpr1: i1 + 2i3 + 3f1 + 4 = 0 mod 5 construct unsat: - 1 >= 0 construct copy: i1 + 2i3 + 3f1 + 4 != 0 construct extend: i1 + 2i3 + 3f1 + 4 != 0 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) assign copy: i1 + 2i3 + 3f1 + 4 = 0 mod 99 assign unsat: - 1 >= 0 i1 + 2i3 + 3f1 + 4set modulo: i1 + 2i3 + 3f1 + 4 = 0 mod 69 get modulo: 69 set modulo: i1 + 2i3 + 3f1 + 4 = 0 mod 70 get linexpr : i1 + 2i3 + 3f1 + 4 set linexpr : 2i1 + 3i3 + 4f1 + 45 = 0 mod 70 extend environment: i1 + 2i3 + 3f1 + 4 = 0 mod 99 get lincons0: x0 + 2x2 + 3x3 + 4 = 0 mod 99 set lincons0: i1 + 2i2 + 3i3 + 4 = 0 size: 3 get constyp: 0 set constyp: i1 + 2i2 + 3i3 + 4 >= 0 get cst: 4 set cst: i1 + 2i2 + 3i3 + 101 >= 0 get [f3]: 0 set [f2]: [-2,3] print: i1 + 2i2 + 3i3 + [-2,3]f2 + 101 >= 0 lincons1 array ============== { construct from lincons0_array: { i1 + 2i3 + 3f1 + 4 = 0; 5i1 + 3i3 + 99 = 0; } construct copy: { i1 + 2i3 + 3f1 + 4 = 0; 5i1 + 3i3 + 99 = 0; } construct extend: { i1 + 2i3 + 3f1 + 4 = 0; 5i1 + 3i3 + 99 = 0; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) construct from array: { i1 + 2i3 + 3f1 + 4 = 0; 5i1 + 3i3 + 99 = 0; i1 + 2i3 + 3f1 + 4 = 0; } construct from vector: { 5i1 + 3i3 + 99 = 0; i1 + 2i3 + 3f1 + 4 = 0; 5i1 + 3i3 + 99 = 0; } assign copy: { 5i1 + 3i3 + 99 = 0; i1 + 2i3 + 3f1 + 4 = 0; 5i1 + 3i3 + 99 = 0; } assign from array: { i1 + 2i3 + 3f1 + 4 = 0; 5i1 + 3i3 + 99 = 0; i1 + 2i3 + 3f1 + 4 = 0; } assign from vector: { 5i1 + 3i3 + 99 = 0; i1 + 2i3 + 3f1 + 4 = 0; 5i1 + 3i3 + 99 = 0; } size: 3 resize: { 5i1 + 3i3 + 99 = 0; i1 + 2i3 + 3f1 + 4 = 0; } size: 2 extend: { 5i1 + 3i3 + 99 = 0; i1 + 2i3 + 3f1 + 4 = 0; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) get lincons0 array: { 5x0 + 3x2 + 99 = 0; x0 + 2x2 + 3x3 + 4 = 0; } set lincons0 array: { i1 + 2i2 + 3i3 + 4 = 0; 5i1 + 3i2 + 99 = 0; } get: i1 + 2i2 + 3i3 + 4 = 0 set: { 5i1 + 3i2 + 181 >= 0; 5i1 + 3i2 + 99 = 0; } to vector: 3 5i1 + 3i2 + 181 >= 0 5i1 + 3i2 + 99 = 0 5i1 + 3i2 + 99 = 0 print: array of constraints of size 3 0: 5i1 + 3i2 + 181 >= 0 1: 5i1 + 3i2 + 99 = 0 2: 5i1 + 3i2 + 99 = 0 generator1 ========== construct empty: RAY: 0 construct from generator0: LINE: i1 + 2i3 + 3f1 + 4 construct from linexpr1: RAY: i1 + 2i3 + 3f1 + 4 construct copy: VERTEX: i1 + 2i3 + 3f1 + 4 construct extend: VERTEX: i1 + 2i3 + 3f1 + 4 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) assign copy: LINEMOD: i1 + 2i3 + 3f1 + 4 get linexpr : i1 + 2i3 + 3f1 + 4 set linexpr : LINEMOD: 2i1 + 3i3 + 4f1 + 45 extend environment: VERTEX: i1 + 2i3 + 3f1 + 4 get generator0: VERTEX: x0 + 2x2 + 3x3 + 4 set generator0: RAYMOD: 2i1 + 3i3 + 4f1 + 45 size: 3 get gentyp: 4 set gentyp: RAY: 2i1 + 3i3 + 4f1 + 45 get cst: 45 set cst: RAY: 2i1 + 3i3 + 4f1 + 101 get [i3]: 3 set [f3]: RAY: 2i1 + 3i3 + 4f1 + 18f3 + 101 print: RAY: 2i1 + 3i3 + 4f1 + 18f3 + 101 generator1 array ================ { construct from generator0_array: { VERTEX: i1 + 2i3 + 3f1 + 98; RAY: 5i1 + 3i3 + 67; } construct copy: { VERTEX: i1 + 2i3 + 3f1 + 98; RAY: 5i1 + 3i3 + 67; } construct extend: { VERTEX: i1 + 2i3 + 3f1 + 98; RAY: 5i1 + 3i3 + 67; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) construct from array: { VERTEX: i1 + 2i3 + 3f1 + 98; RAY: 5i1 + 3i3 + 67; VERTEX: i1 + 2i3 + 3f1 + 98; } construct from vector: { RAY: 5i1 + 3i3 + 67; VERTEX: i1 + 2i3 + 3f1 + 98; RAY: 5i1 + 3i3 + 67; } assign copy: { RAY: 5i1 + 3i3 + 67; VERTEX: i1 + 2i3 + 3f1 + 98; RAY: 5i1 + 3i3 + 67; } assign from array: { VERTEX: i1 + 2i3 + 3f1 + 98; RAY: 5i1 + 3i3 + 67; VERTEX: i1 + 2i3 + 3f1 + 98; } size: 3 resize: { VERTEX: i1 + 2i3 + 3f1 + 98; RAY: 5i1 + 3i3 + 67; } size: 2 assign from vector: { RAY: 5i1 + 3i3 + 67; VERTEX: i1 + 2i3 + 3f1 + 98; RAY: 5i1 + 3i3 + 67; } extend: { RAY: 5i1 + 3i3 + 67; VERTEX: i1 + 2i3 + 3f1 + 98; RAY: 5i1 + 3i3 + 67; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) get generator0 array: { RAY: 5x0 + 3x2 + 67; VERTEX: x0 + 2x2 + 3x3 + 98; RAY: 5x0 + 3x2 + 67; } set generator0 array: { VERTEX: i1 + 2i2 + 3i3 + 98; RAY: 5i1 + 3i2 + 67; } get: VERTEX: i1 + 2i2 + 3i3 + 98 set: { LINE: 5i1 + 3i2 + 181; RAY: 5i1 + 3i2 + 67; } to vector: 3 LINE: 5i1 + 3i2 + 181 RAY: 5i1 + 3i2 + 67 RAY: 5i1 + 3i2 + 67 print: array of generator of size 3 0: LINE: 5i1 + 3i2 + 181 1: RAY: 5i1 + 3i2 + 67 2: RAY: 5i1 + 3i2 + 67 texpr1 ====== construct 2: 2 construct [-1,1] [-1,1] construct 5/4 5/4 construct 2.5 2.5 construct dim(1) i3 construct i3 i3 construct dim(1)*5 i3 * 5 construct f3*5 f3 * 5 construct sqrt(i1/f3) sqrt(i1 / f3) construct 2 2 construct [-1,1] [-1,1] construct 5/4 5/4 construct [-8;9] [-8,9] construct 2.5 2.5 construct [-81.5;2.3] [-81.5,2.4] construct i3 i3 construct f3*5 f3 * 5 construct sqrt(i1/f3) sqrt(i1 / f3) construct dim(1)/dim(2)+5 i3 / f1 + 5 construct dim(1)/dim(2) i3 / f1 left i3/f1 i3 / f1 right 5 5 construct 8 * 5 8 * 5 construct linexpr0 4 + 1 * i1 + 2 * i3 + 3 * f1 construct linexpr1 4 + 1 * i1 + 2 * i3 + 3 * f1 construct linexpr1 * i1 (4 + 1 * i1 + 2 * i3 + 3 * f1) * i1 construct extend i3 / f1 + 5 construct subst i3 / (f3 * 5) + 5 construct copy i3 / f1 + 5 assign floor(i1*0.001) cast_i,-oo(i1 * 0.001) assign copy t1 i3 / f1 + 5 assign t1*t1 (i3 / f1 + 5) * (i3 / f1 + 5) assign t1.left i3 / f1 assign l1 4 + 1 * i1 + 2 * i3 + 3 * f1 assign l1 w/env change 4 + 1 * i1 + 2 * i2 + 3 * i3 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) assign i3 w/env change i3 0: i1 (int) 1: i3 (int) 2: f1 (real) 3: f3 (real) get texpr0 x1 set texpr0 dim(1)/dim(2) i3 / f1 get left.texpr0 x1 set left.texpr0 dim(0)*5 i1 * 5 / f1 get right f1 set right sqrt(5+f3) i1 * 5 / sqrt(5 + f3) discr op rtype rdir 2 3 0 0 get var f3 f3 get coeff 5 5 set i1 -_f,-oo 6 i1 -_f,-oo 6 substitute sqrt(5 - f3) * sqrt(5 - f3) + sqrt(5 - f3) print i3 + 5 print i3 + 5 tcons1 ====== construct i1 + 1 = 0: i1 + 1 = 0 construct floor(i1+2) >= 0: cast_i,-oo(i1 + 2) >= 0 construct i1*f1 > 0: i1 * f1 > 0 construct [-1,1]*i1 != 0: [-1,1] * i1 != 0 construct i1/f1 = 0 mod 5: i1 / f1 = 0 mod 5 from lincons 1i1+2i3+3f1+4 = 0: 4 + 1 * i1 + 2 * i3 + 3 * f1 = 0 construct i1 >= f1+1: i1 - (f1 + 1) >= 0 construct i1 <= f1+1: f1 + 1 - i1 >= 0 construct i1 > f1+1: i1 - (f1 + 1) > 0 construct i1 < f1+1: f1 + 1 - i1 > 0 construct i1 == f1+1: i1 - (f1 + 1) = 0 construct i1 != f1+1: i1 - (f1 + 1) != 0 construct i1 == 0: i1 = 0 construct 0 != f1+1: f1 + 1 != 0 copy i1 * f1 = 0: i1 * f1 = 0 extend env i1 * f1 = 0 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) unsat: -1 >= 0 unsat: -1 >= 0 from lincons 1i1+2i3+3f1+4 = 0: 4 + 1 * i1 + 2 * i3 + 3 * f1 = 0 chained copy i1 * f1 +2 = 0: i1 * f1 + 2 = 0 extend env i1 * f1 + 2 = 0 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) get_constyp i1 * f1 + 2 > 0: i1 * f1 + 2 > 0 set_modulo i1 * f1 + 2 = 0 mod 3: i1 * f1 + 2 = 0 mod 3 set_texpr sqrt(i1+1) = 0 mod 3: sqrt(i1 + 1) = 0 mod 3 get_texpr i1/f1+5 = 0 mod 3: i1 / f1 + 5 = 0 mod 3 get_texpr [0,1]/i1+5 = 0 mod 3: [0,1] / f1 + 5 = 0 mod 3 get tcons0 [0,1] / x2 + 5 = 0 mod 3 set tcons0 i3>=5 i3 - 5 >= 0 print: i3 - 5 >= 0 tcons1 array ============ { construct: { sqrt(i1 + 15 * f1) >= 0; [2,5] = 0; } get(1): [2,5] = 0 copy: { sqrt(i1 + 15 * f1) >= 0; [2,5] = 0; } env extend: { sqrt(i1 + 15 * f1) >= 0; [2,5] = 0; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) from array: { i1 * i3 * f1 >= 0; i1 - (f1 + 1) >= 0; [1,2] * i1 = 0 mod 5; } from vector: { 0 = 0; 1 - f3 = 0; } from array: { i1 * i3 * f1 >= 0; i1 - (f1 + 1) >= 0; } from vector: { 0 = 0; 1 - f3 = 0; } copy: { sqrt(i1 + 15 * f1) >= 0; [2,5] = 0; } extend environment { sqrt(i1 + 15 * f1) >= 0; [2,5] = 0; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) size: 2 set: { i2 * 5 + i3 >= 0; [2,5] = 0; } to vector: 2: i2 * 5 + i3 >= 0; [2,5] = 0 get environment 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) get tcons0_array { x1 * 5 + x2 >= 0; [2,5] = 0; } set tcons_array { i1 - i2 >= 0; [2,5] = 0; } print: array of constraints of size 2 0: i1 - i2 >= 0 1: [2,5] = 0 Box === library: box version: 1.0 with NUM_MPQ level 1 construct top: top construct bottom: bottom construct box: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } construct box: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } construct lincons: top construct tcons: top construct copy: top construct copy: top assign top: top assign bottom: bottom assign box: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; f2 + 1/2 >= 0; - 1f2 + 3/2 >= 0; f3 - 1/2 >= 0; - 1f3 + 8/5 >= 0; } assign lincons: top assign tcons: top assign copy: top assign top: top assign top: top assign bottom: bottom assign bottom: bottom assign box: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; f2 + 1/2 >= 0; - 1f2 + 3/2 >= 0; f3 - 1/2 >= 0; - 1f3 + 8/5 >= 0; } assign box: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } assign box: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } assign lincons: top assign tcons top assign copy: top unchanged: top minimize: top canonicalize: top approximate: top closure: top print: interval of dim (2,3): i1 in [-oo,+oo] i3 in [-oo,+oo] f1 in [-oo,+oo] f2 in [-oo,+oo] f3 in [-oo,+oo] printdiff: diff of 2 intervals of dim (2,2) i1 in [-oo,+oo] => -[-1, 1]+ i3 in [=,=] f1 in [-oo,+oo] => [=, 18]+ f2 in [-oo,+oo] => -[1/2, 8/5]+ f3 in [-oo,+oo] => -[-1/2, 3/2]+ dump: abstract value of level 1: environment: dim = (2,3), count = 19 0: i1 1: i3 2: f1 3: f2 4: f3 interval of dim (2,3): dim 0 in [-oo,+oo] dim 1 in [-oo,+oo] dim 2 in [-oo,+oo] dim 3 in [-oo,+oo] dim 4 in [-oo,+oo] serialization not implemented: apron::abstract1::serialize_raw(manager&) : environment: 0: i1 (int) 1: i3 (int) 2: f1 (real) 3: f2 (real) 4: f3 (real) size: 10 get abstract0: top set abstract0: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; f2 + 1/2 >= 0; - 1f2 + 3/2 >= 0; f3 - 1/2 >= 0; - 1f3 + 8/5 >= 0; } sat lincons: top sat tcons: false sat interval: true unconstrainned: false bound linexpr: [-oo,+oo] bound texpr: [-oo,+oo] bound variable: [-oo,+oo] to generator: { LINE: i1; LINE: i3; LINE: f1; LINE: f2; LINE: f3; VERTEX: 0; } to lincons: { } to tcons: { } to box: { [-oo,+oo] [-oo,+oo] [-oo,+oo] [-oo,+oo] [-oo,+oo] } meet: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } meet array: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } meet lincons: top meet tcons: top join: top join array: top add rays: { f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } unify: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i3 + 18 >= 0; f1 + 1/2 >= 0; - 1f1 + 3/2 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 - 1/2 >= 0; - 1f3 + 3/2 >= 0; } assign linexpr: { - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } assign linexpr inter: { - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } assign linexprs: { i1 + 1 >= 0; - 1i1 + 1 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } assign linexprs inter: { i1 + 1 >= 0; - 1i1 + 1 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } assign texpr: { - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } assign texpr inter: { - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } assign texprs: { i1 + 1 >= 0; - 1i1 + 1 >= 0; f2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } assign texprs inter: { i1 + 1 >= 0; - 1i1 + 1 >= 0; f2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } subst linexpr: { - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } subst linexpr inter: { - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } subst linexprs: { i1 + 1 >= 0; - 1i1 + 1 >= 0; i3 + 39 >= 0; - 1f1 + 577/10 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } subst linexprs inter: { i1 + 1 >= 0; - 1i1 + 1 >= 0; i3 + 39 >= 0; - 1f1 + 577/10 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } subst texpr: { - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } subst texpr inter: { - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } subst texprs: { i1 + 1 >= 0; - 1i1 + 1 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } subst texprs inter: { i1 + 1 >= 0; - 1i1 + 1 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } forget: { - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } forget 0: { i1 = 0; - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } forgets: { i1 + 1 >= 0; - 1i1 + 1 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } forgets 0: { i1 + 1 >= 0; - 1i1 + 1 >= 0; f1 = 0; f2 = 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } forgets: { i1 + 1 >= 0; - 1i1 + 1 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } forgets 0: { i1 + 1 >= 0; - 1i1 + 1 >= 0; f1 = 0; f2 = 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } change env: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) change env 0: { i1 + 1 >= 0; - 1i1 + 1 >= 0; i2 = 0; - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) minimize env: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } 0: i1 (int) 1: f1 (real) 2: f2 (real) 3: f3 (real) rename: { truc + 1 >= 0; - 1truc + 1 >= 0; f0 - 1/2 >= 0; - 1f0 + 8/5 >= 0; - 1f1 + 18 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } expand: { f0 + 1 >= 0; - 1f0 + 1 >= 0; i1 + 1 >= 0; - 1i1 + 1 >= 0; truc + 1 >= 0; - 1truc + 1 >= 0; - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } fold: { truc + 1 >= 0; - 1truc + 1 >= 0; - 1f1 + 18 >= 0; f2 - 1/2 >= 0; - 1f2 + 8/5 >= 0; f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } widening: top widening thr: top Polka (loose) ============= library: polka, loose mode version: 3.0 with NUMINT_MPZ level 1 construct top: top construct bottom: bottom construct box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } construct box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } construct lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } construct tcons: { i1 - 1i3 - 1 >= 0; } construct copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } construct copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } assign top: top assign bottom: bottom assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 2f2 + 3 >= 0; - 5f3 + 8 >= 0; 2f3 - 1 >= 0; 2f2 + 1 >= 0; i1 + 1 >= 0; } assign lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } assign tcons: { i1 - 1i3 - 1 >= 0; } assign copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } assign top: top assign top: top assign bottom: bottom assign bottom: bottom assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 2f2 + 3 >= 0; - 5f3 + 8 >= 0; 2f3 - 1 >= 0; 2f2 + 1 >= 0; i1 + 1 >= 0; } assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } assign lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } assign tcons { i1 - 1i3 - 1 >= 0; } assign copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } unchanged: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } minimize: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } canonicalize: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } approximate: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } closure: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } print: polyhedron of dim (2,3) array of constraints of size 3 0: 5i1 + 4i3 + 3f1 + f3 + 3 = 0 1: -i1 - i3 - 20 >= 0 2: i1 + 2i3 + 3f1 + 4f2 + 1 >= 0 printdiff: not implemented apron::printdiff(manager&, const abstract1&, const abstract1&, FILE*) : dump: abstract value of level 1: environment: dim = (2,3), count = 19 0: i1 1: i3 2: f1 3: f2 4: f3 polyhedron of dim (2,3) Constraints: 4 7 0 3 5 4 3 0 1 1 -20 -1 -1 0 0 0 1 1 0 0 0 0 0 1 1 1 2 3 4 0 Frames: 5 7 0 0 -3 3 -1 0 6 0 0 6 -6 -2 3 0 1 0 -3 3 1 0 0 1 0 1 -2 1 0 0 1 3 57 -117 58 0 0 satC: 5 1 0000,0000 0000,0000 0000,0000 0000,0000 0000,0000 0000,0000 0000,0000 0000,0000 0001,0000 0000,0000 0000,0000 0000,0000 0100,0000 0000,0000 0000,0000 0000,0000 0010,0000 0000,0000 0000,0000 0000,0000 serialization not implemented: apron::abstract1::serialize_raw(manager&) : environment: 0: i1 (int) 1: i3 (int) 2: f1 (real) 3: f2 (real) 4: f3 (real) size: 45 get abstract0: { 5x0 + 4x1 + 3x2 + x4 + 3 = 0; - 1x0 - 1x1 - 20 >= 0; x0 + 2x1 + 3x2 + 4x3 + 1 >= 0; } set abstract0: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 2f2 + 3 >= 0; - 5f3 + 8 >= 0; 2f3 - 1 >= 0; 2f2 + 1 >= 0; i1 + 1 >= 0; } sat lincons: true sat tcons: false sat interval: true unconstrainned: false bound linexpr: [0,+oo] bound texpr: [-oo,+oo] bound variable: [-oo,+oo] to generator: { LINE: - 3i1 + 3i3 - 1f1 + 6f3; LINE: 6i1 - 6i3 - 2f1 + 3f2; RAY: - 3i1 + 3i3 + f1; RAY: i1 - 2i3 + f1; VERTEX: 19i1 - 39i3 + 58/3f1; } to lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } to tcons: { 3 + 5 * i1 + 4 * i3 + 3 * f1 + 0 * f2 + 1 * f3 = 0; -20 + -1 * i1 + -1 * i3 + 0 * f1 + 0 * f2 + 0 * f3 >= 0; 1 + 1 * i1 + 2 * i3 + 3 * f1 + 4 * f2 + 0 * f3 >= 0; } to box: { [-oo,+oo] [-oo,+oo] [-oo,+oo] [-oo,+oo] [-oo,+oo] } meet: bottom meet array: bottom meet lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 - 1i3 - 1 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } meet tcons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 - 1i3 - 1 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } join: top join array: top add rays: { - 8i1 + 2f2 + 7 >= 0; - 8f1 + 6f2 + 141 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; } unify: { - 1i1 + 1 >= 0; - 1i3 + 18 >= 0; - 2f1 + 3 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 - 1 >= 0; 2f2 - 1 >= 0; 2f1 + 1 >= 0; i1 + 1 >= 0; } assign linexpr: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + i3 + 21 >= 0; } assign linexpr inter: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + i3 + 21 >= 0; } assign linexprs: { i1 + i3 + f1 + 20 = 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; 5i1 + 4i3 - 1f2 + f3 + 44 >= 0; } assign linexprs inter: { i1 + i3 + f1 + 20 = 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + 1 >= 0; 5i1 + 4i3 - 1f2 + f3 + 44 >= 0; } assign texpr: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; } assign texpr inter: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; } assign texprs: { - 1i1 + 1 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; f2 >= 0; i1 + 1 >= 0; } assign texprs inter: { - 1i1 + 1 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; f2 >= 0; i1 - 1i3 - 1 >= 0; i1 + 1 >= 0; } subst linexpr: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + i3 + 21 >= 0; } subst linexpr inter: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + i3 + 21 >= 0; } subst linexprs: { - 25i1 - 20i3 - 15f1 - 5f3 + 58 >= 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; i1 + i3 + 38 >= 0; 10i1 + 8i3 + 6f1 + 2f3 - 21 >= 0; } subst linexprs inter: { - 25i1 - 20i3 - 15f1 - 5f3 + 58 >= 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + 1 >= 0; i1 + i3 + 38 >= 0; 10i1 + 8i3 + 6f1 + 2f3 - 21 >= 0; } subst texpr: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; } subst texpr inter: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; } subst texprs: { - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; } subst texprs inter: { - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + 1 >= 0; } forget: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; } forget 0: { i1 = 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; } forgets: { - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; } forgets 0: { f2 = 0; f1 = 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; } forgets: { - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; } forgets 0: { f2 = 0; f1 = 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; } change env: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) change env 0: { i2 = 0; - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) minimize env: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } 0: i1 (int) 1: f1 (real) 2: f2 (real) 3: f3 (real) rename: { - 1truc + 1 >= 0; - 5f0 + 8 >= 0; - 1f1 + 18 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f0 - 1 >= 0; truc + 1 >= 0; } expand: { - 1f0 + 1 >= 0; - 1i1 + 1 >= 0; - 1truc + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; truc + 1 >= 0; i1 + 1 >= 0; f0 + 1 >= 0; } fold: { - 1truc + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; truc + 1 >= 0; } widening: top widening thr: top Polka (strict) ============== library: polka, strict mode version: 3.0 with NUMINT_MPZ level 1 construct top: top construct bottom: bottom construct box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } construct box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } construct lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } construct tcons: { i1 - 1i3 - 1 >= 0; } construct copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } construct copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } assign top: top assign bottom: bottom assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 2f2 + 3 >= 0; - 5f3 + 8 >= 0; 2f3 - 1 >= 0; 2f2 + 1 >= 0; i1 + 1 >= 0; } assign lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } assign tcons: { i1 - 1i3 - 1 >= 0; } assign copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } assign top: top assign top: top assign bottom: bottom assign bottom: bottom assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 2f2 + 3 >= 0; - 5f3 + 8 >= 0; 2f3 - 1 >= 0; 2f2 + 1 >= 0; i1 + 1 >= 0; } assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } assign lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } assign tcons { i1 - 1i3 - 1 >= 0; } assign copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } unchanged: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } minimize: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } canonicalize: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } approximate: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } closure: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } print: polyhedron of dim (2,3) array of constraints of size 3 0: 5i1 + 4i3 + 3f1 + f3 + 3 = 0 1: -i1 - i3 - 20 >= 0 2: i1 + 2i3 + 3f1 + 4f2 + 1 > 0 printdiff: not implemented apron::printdiff(manager&, const abstract1&, const abstract1&, FILE*) : dump: abstract value of level 1: environment: dim = (2,3), count = 19 0: i1 1: i3 2: f1 3: f2 4: f3 polyhedron of dim (2,3) Constraints: 5 8 0 3 0 5 4 3 0 1 1 -20 0 -1 -1 0 0 0 1 0 1 0 0 0 0 0 1 1 -1 0 0 0 0 0 1 1 -1 1 2 3 4 0 Frames: 6 8 0 0 0 -3 3 -1 0 6 0 0 0 6 -6 -2 3 0 1 0 0 -3 3 1 0 0 1 0 0 1 -2 1 0 0 1 2 2 37 -77 39 0 0 1 3 0 57 -117 58 0 0 satC: 6 1 0000,0000 0000,0000 0000,0000 0000,0000 0000,0000 0000,0000 0000,0000 0000,0000 0000,1000 0000,0000 0000,0000 0000,0000 0100,0000 0000,0000 0000,0000 0000,0000 0010,0000 0000,0000 0000,0000 0000,0000 0001,0000 0000,0000 0000,0000 0000,0000 serialization not implemented: apron::abstract1::serialize_raw(manager&) : environment: 0: i1 (int) 1: i3 (int) 2: f1 (real) 3: f2 (real) 4: f3 (real) size: 55 get abstract0: { 5x0 + 4x1 + 3x2 + x4 + 3 = 0; - 1x0 - 1x1 - 20 >= 0; x0 + 2x1 + 3x2 + 4x3 + 1 > 0; } set abstract0: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 2f2 + 3 >= 0; - 5f3 + 8 >= 0; 2f3 - 1 >= 0; 2f2 + 1 >= 0; i1 + 1 >= 0; } sat lincons: true sat tcons: false sat interval: true unconstrainned: false bound linexpr: [0,+oo] bound texpr: [-oo,+oo] bound variable: [-oo,+oo] to generator: { LINE: - 3i1 + 3i3 - 1f1 + 6f3; LINE: 6i1 - 6i3 - 2f1 + 3f2; RAY: - 3i1 + 3i3 + f1; RAY: i1 - 2i3 + f1; VERTEX: 19i1 - 39i3 + 58/3f1; } to lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } to tcons: { 3 + 5 * i1 + 4 * i3 + 3 * f1 + 0 * f2 + 1 * f3 = 0; -20 + -1 * i1 + -1 * i3 + 0 * f1 + 0 * f2 + 0 * f3 >= 0; 1 + 1 * i1 + 2 * i3 + 3 * f1 + 4 * f2 + 0 * f3 > 0; } to box: { [-oo,+oo] [-oo,+oo] [-oo,+oo] [-oo,+oo] [-oo,+oo] } meet: bottom meet array: bottom meet lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 - 1i3 - 1 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } meet tcons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 - 1i3 - 1 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } join: top join array: top add rays: { - 8i1 + 2f2 + 7 >= 0; - 8f1 + 6f2 + 141 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; } unify: { - 1i1 + 1 >= 0; - 1i3 + 18 >= 0; - 2f1 + 3 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 - 1 >= 0; 2f2 - 1 >= 0; 2f1 + 1 >= 0; i1 + 1 >= 0; } assign linexpr: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + i3 + 21 >= 0; } assign linexpr inter: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + i3 + 21 >= 0; } assign linexprs: { i1 + i3 + f1 + 20 = 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; 5i1 + 4i3 - 1f2 + f3 + 44 >= 0; } assign linexprs inter: { i1 + i3 + f1 + 20 = 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + 1 >= 0; 5i1 + 4i3 - 1f2 + f3 + 44 >= 0; } assign texpr: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; } assign texpr inter: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; } assign texprs: { - 1i1 + 1 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; f2 >= 0; i1 + 1 >= 0; } assign texprs inter: { - 1i1 + 1 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; f2 >= 0; i1 - 1i3 - 1 >= 0; i1 + 1 >= 0; } subst linexpr: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + i3 + 21 >= 0; } subst linexpr inter: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + i3 + 21 >= 0; } subst linexprs: { - 25i1 - 20i3 - 15f1 - 5f3 + 58 >= 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; i1 + i3 + 38 >= 0; 10i1 + 8i3 + 6f1 + 2f3 - 21 >= 0; } subst linexprs inter: { - 25i1 - 20i3 - 15f1 - 5f3 + 58 >= 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + 1 >= 0; i1 + i3 + 38 >= 0; 10i1 + 8i3 + 6f1 + 2f3 - 21 >= 0; } subst texpr: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; } subst texpr inter: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; } subst texprs: { - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; } subst texprs inter: { - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + 1 >= 0; } forget: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; } forget 0: { i1 = 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; } forgets: { - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; } forgets 0: { f2 = 0; f1 = 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; } forgets: { - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; } forgets 0: { f2 = 0; f1 = 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; } change env: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) change env 0: { i2 = 0; - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) minimize env: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } 0: i1 (int) 1: f1 (real) 2: f2 (real) 3: f3 (real) rename: { - 1truc + 1 >= 0; - 5f0 + 8 >= 0; - 1f1 + 18 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f0 - 1 >= 0; truc + 1 >= 0; } expand: { - 1f0 + 1 >= 0; - 1i1 + 1 >= 0; - 1truc + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; truc + 1 >= 0; i1 + 1 >= 0; f0 + 1 >= 0; } fold: { - 1truc + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; truc + 1 >= 0; } widening: top widening thr: top Octagon ======= library: oct version: 1.0 with NUM_MPQ level 1 construct top: top construct bottom: bottom construct box: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 - 1f1 + 19 >= 0; i1 - 1f1 + 19 >= 0; - 1f1 + 18 >= 0; - 1i1 + f2 + 1/2 >= 0; i1 + f2 + 1/2 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1i1 - 1f2 + 13/5 >= 0; i1 - 1f2 + 13/5 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } construct box: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 - 1f1 + 19 >= 0; i1 - 1f1 + 19 >= 0; - 1f1 + 18 >= 0; - 1i1 + f2 + 1/2 >= 0; i1 + f2 + 1/2 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1i1 - 1f2 + 13/5 >= 0; i1 - 1f2 + 13/5 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } construct lincons: { - 1i1 - 1i3 - 20 >= 0; } construct tcons: { i1 - 1i3 - 1 >= 0; } construct copy: { - 1i1 - 1i3 - 20 >= 0; } construct copy: { - 1i1 - 1i3 - 20 >= 0; } assign top: top assign bottom: bottom assign box: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 - 1f1 + 19 >= 0; i1 - 1f1 + 19 >= 0; - 1f1 + 18 >= 0; - 1i1 + f2 + 3/2 >= 0; i1 + f2 + 3/2 >= 0; - 1f1 + f2 + 37/2 >= 0; f2 + 1/2 >= 0; - 1i1 - 1f2 + 5/2 >= 0; i1 - 1f2 + 5/2 >= 0; - 1f1 - 1f2 + 39/2 >= 0; - 1f2 + 3/2 >= 0; - 1i1 + f3 + 1/2 >= 0; i1 + f3 + 1/2 >= 0; - 1f1 + f3 + 35/2 >= 0; - 1f2 + f3 + 1 >= 0; f2 + f3 >= 0; f3 - 1/2 >= 0; - 1i1 - 1f3 + 13/5 >= 0; i1 - 1f3 + 13/5 >= 0; - 1f1 - 1f3 + 98/5 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 21/10 >= 0; - 1f3 + 8/5 >= 0; } assign lincons: { - 1i1 - 1i3 - 20 >= 0; } assign tcons: { i1 - 1i3 - 1 >= 0; } assign copy: { - 1i1 - 1i3 - 20 >= 0; } assign top: top assign top: top assign bottom: bottom assign bottom: bottom assign box: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 - 1f1 + 19 >= 0; i1 - 1f1 + 19 >= 0; - 1f1 + 18 >= 0; - 1i1 + f2 + 3/2 >= 0; i1 + f2 + 3/2 >= 0; - 1f1 + f2 + 37/2 >= 0; f2 + 1/2 >= 0; - 1i1 - 1f2 + 5/2 >= 0; i1 - 1f2 + 5/2 >= 0; - 1f1 - 1f2 + 39/2 >= 0; - 1f2 + 3/2 >= 0; - 1i1 + f3 + 1/2 >= 0; i1 + f3 + 1/2 >= 0; - 1f1 + f3 + 35/2 >= 0; - 1f2 + f3 + 1 >= 0; f2 + f3 >= 0; f3 - 1/2 >= 0; - 1i1 - 1f3 + 13/5 >= 0; i1 - 1f3 + 13/5 >= 0; - 1f1 - 1f3 + 98/5 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 21/10 >= 0; - 1f3 + 8/5 >= 0; } assign box: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 - 1f1 + 19 >= 0; i1 - 1f1 + 19 >= 0; - 1f1 + 18 >= 0; - 1i1 + f2 + 1/2 >= 0; i1 + f2 + 1/2 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1i1 - 1f2 + 13/5 >= 0; i1 - 1f2 + 13/5 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } assign box: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 - 1f1 + 19 >= 0; i1 - 1f1 + 19 >= 0; - 1f1 + 18 >= 0; - 1i1 + f2 + 1/2 >= 0; i1 + f2 + 1/2 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1i1 - 1f2 + 13/5 >= 0; i1 - 1f2 + 13/5 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } assign lincons: { - 1i1 - 1i3 - 20 >= 0; } assign tcons { i1 - 1i3 - 1 >= 0; } assign copy: { - 1i1 - 1i3 - 20 >= 0; } unchanged: { - 1i1 - 1i3 - 20 >= 0; } minimize: canonicalize: approximate: closure: { - 1i1 - 1i3 - 20 >= 0; } print: octagon of dim (2,3) -i1 - i3 - 20 >= 0 printdiff: i1 + +oo >= 0 / i1 + 1 >= 0 -i1 + +oo >= 0 / -i1 + 1 >= 0 -i1 - i3 - 20 >= 0 / -i1 - i3 + +oo >= 0 -i1 - f1 + +oo >= 0 / -i1 - f1 + 19 >= 0 i1 - f1 + +oo >= 0 / i1 - f1 + 19 >= 0 -f1 + +oo >= 0 / -f1 + 18 >= 0 -i1 + f2 + +oo >= 0 / -i1 + f2 + 1/2 >= 0 i1 + f2 + +oo >= 0 / i1 + f2 + 1/2 >= 0 -f1 + f2 + +oo >= 0 / -f1 + f2 + 35/2 >= 0 f2 + +oo >= 0 / f2 - 1/2 >= 0 -i1 - f2 + +oo >= 0 / -i1 - f2 + 13/5 >= 0 i1 - f2 + +oo >= 0 / i1 - f2 + 13/5 >= 0 -f1 - f2 + +oo >= 0 / -f1 - f2 + 98/5 >= 0 -f2 + +oo >= 0 / -f2 + 8/5 >= 0 -i1 + f3 + +oo >= 0 / -i1 + f3 + 3/2 >= 0 i1 + f3 + +oo >= 0 / i1 + f3 + 3/2 >= 0 -f1 + f3 + +oo >= 0 / -f1 + f3 + 37/2 >= 0 -f2 + f3 + +oo >= 0 / -f2 + f3 + 21/10 >= 0 f2 + f3 + +oo >= 0 / f2 + f3 >= 0 f3 + +oo >= 0 / f3 + 1/2 >= 0 -i1 - f3 + +oo >= 0 / -i1 - f3 + 5/2 >= 0 i1 - f3 + +oo >= 0 / i1 - f3 + 5/2 >= 0 -f1 - f3 + +oo >= 0 / -f1 - f3 + 39/2 >= 0 -f2 - f3 + +oo >= 0 / -f2 - f3 + 31/10 >= 0 f2 - f3 + +oo >= 0 / f2 - f3 + 1 >= 0 -f3 + +oo >= 0 / -f3 + 3/2 >= 0 dump: abstract value of level 1: environment: dim = (2,3), count = 19 0: i1 1: i3 2: f1 3: f2 4: f3 octagon of dim (2,3) matrix: 0 +oo +oo 0 +oo +oo 0 +oo -20 +oo +oo 0 +oo +oo +oo +oo 0 +oo +oo +oo +oo +oo +oo 0 +oo +oo +oo +oo +oo +oo 0 +oo +oo +oo +oo +oo +oo +oo +oo 0 +oo +oo +oo +oo +oo +oo +oo +oo 0 +oo +oo +oo +oo +oo +oo +oo +oo +oo +oo 0 closed matrix: 0 +oo +oo 0 +oo +oo 0 +oo -20 +oo +oo 0 +oo +oo +oo +oo 0 +oo +oo +oo +oo +oo +oo 0 +oo +oo +oo +oo +oo +oo 0 +oo +oo +oo +oo +oo +oo +oo +oo 0 +oo +oo +oo +oo +oo +oo +oo +oo 0 +oo +oo +oo +oo +oo +oo +oo +oo +oo +oo 0 serialization not implemented: apron::abstract1::serialize_raw(manager&) : environment: 0: i1 (int) 1: i3 (int) 2: f1 (real) 3: f2 (real) 4: f3 (real) size: 60 get abstract0: { - 1x0 - 1x1 - 20 >= 0; } set abstract0: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 - 1f1 + 19 >= 0; i1 - 1f1 + 19 >= 0; - 1f1 + 18 >= 0; - 1i1 + f2 + 3/2 >= 0; i1 + f2 + 3/2 >= 0; - 1f1 + f2 + 37/2 >= 0; f2 + 1/2 >= 0; - 1i1 - 1f2 + 5/2 >= 0; i1 - 1f2 + 5/2 >= 0; - 1f1 - 1f2 + 39/2 >= 0; - 1f2 + 3/2 >= 0; - 1i1 + f3 + 1/2 >= 0; i1 + f3 + 1/2 >= 0; - 1f1 + f3 + 35/2 >= 0; - 1f2 + f3 + 1 >= 0; f2 + f3 >= 0; f3 - 1/2 >= 0; - 1i1 - 1f3 + 13/5 >= 0; i1 - 1f3 + 13/5 >= 0; - 1f1 - 1f3 + 98/5 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 21/10 >= 0; - 1f3 + 8/5 >= 0; } sat lincons: true sat tcons: top sat interval: true unconstrainned: false bound linexpr: [0,+oo] bound texpr: [-oo,+oo] bound variable: [-oo,+oo] to generator: { VERTEX: 0; LINE: i1; LINE: i3; LINE: f1; LINE: f2; LINE: f3; } to lincons: { - 1i1 - 1i3 - 20 >= 0; } to tcons: { -20 + -1 * i1 + -1 * i3 >= 0; } to box: { [-oo,+oo] [-oo,+oo] [-oo,+oo] [-oo,+oo] [-oo,+oo] } meet: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 - 1i3 - 20 >= 0; i1 - 1i3 - 18 >= 0; - 1i3 - 19 >= 0; - 1i1 - 1f1 + 19 >= 0; i1 - 1f1 + 19 >= 0; - 1i3 - 1f1 - 1 >= 0; - 1f1 + 18 >= 0; - 1i1 + f2 + 1/2 >= 0; i1 + f2 + 1/2 >= 0; - 1i3 + f2 - 39/2 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1i1 - 1f2 + 13/5 >= 0; i1 - 1f2 + 13/5 >= 0; - 1i3 - 1f2 - 87/5 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; - 1i3 + f3 - 37/2 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1i3 - 1f3 - 35/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } meet array: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 - 1i3 - 20 >= 0; i1 - 1i3 - 18 >= 0; - 1i3 - 19 >= 0; - 1i1 - 1f1 + 19 >= 0; i1 - 1f1 + 19 >= 0; - 1i3 - 1f1 - 1 >= 0; - 1f1 + 18 >= 0; - 1i1 + f2 + 1/2 >= 0; i1 + f2 + 1/2 >= 0; - 1i3 + f2 - 39/2 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1i1 - 1f2 + 13/5 >= 0; i1 - 1f2 + 13/5 >= 0; - 1i3 - 1f2 - 87/5 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; - 1i3 + f3 - 37/2 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1i3 - 1f3 - 35/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } meet lincons: { - 1i1 - 1i3 - 20 >= 0; i1 - 1i3 - 1 >= 0; - 1i3 - 21/2 >= 0; } meet tcons: { - 1i1 - 1i3 - 20 >= 0; i1 - 1i3 - 1 >= 0; - 1i3 - 21/2 >= 0; } join: top join array: top add rays: { f3 + 1/2 >= 0; - 1f3 + 3/2 >= 0; } unify: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 - 1i3 + 19 >= 0; i1 - 1i3 + 19 >= 0; - 1i3 + 18 >= 0; - 1i1 + f1 + 3/2 >= 0; i1 + f1 + 3/2 >= 0; - 1i3 + f1 + 37/2 >= 0; f1 + 1/2 >= 0; - 1i1 - 1f1 + 5/2 >= 0; i1 - 1f1 + 5/2 >= 0; - 1i3 - 1f1 + 39/2 >= 0; - 1f1 + 3/2 >= 0; - 1i1 + f2 + 1/2 >= 0; i1 + f2 + 1/2 >= 0; - 1i3 + f2 + 35/2 >= 0; - 1f1 + f2 + 1 >= 0; f1 + f2 >= 0; f2 - 1/2 >= 0; - 1i1 - 1f2 + 13/5 >= 0; i1 - 1f2 + 13/5 >= 0; - 1i3 - 1f2 + 98/5 >= 0; - 1f1 - 1f2 + 31/10 >= 0; f1 - 1f2 + 21/10 >= 0; - 1f2 + 8/5 >= 0; - 1i1 + f3 + 1/2 >= 0; i1 + f3 + 1/2 >= 0; - 1i3 + f3 + 35/2 >= 0; - 1f1 + f3 + 1 >= 0; f1 + f3 >= 0; - 1f2 + f3 + 11/10 >= 0; f2 + f3 - 1 >= 0; f3 - 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1i3 - 1f3 + 39/2 >= 0; - 1f1 - 1f3 + 3 >= 0; f1 - 1f3 + 2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } assign linexpr: { - 1f1 + 18 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } assign linexpr inter: { i1 - 1i3 - 1 >= 0; - 1f1 + 18 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } assign linexprs: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1f3 + 3/2 >= 0; } assign linexprs inter: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 - 1i3 + 1 >= 0; i1 - 1i3 - 1 >= 0; - 1i3 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; - 1i3 + f3 + 1/2 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1i3 - 1f3 + 3/2 >= 0; - 1f3 + 3/2 >= 0; } assign texpr: { - 1f1 + 18 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } assign texpr inter: { i1 - 1i3 - 1 >= 0; - 1f1 + 18 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } assign texprs: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 + f2 + 1 >= 0; i1 + f2 + 1 >= 0; f2 >= 0; - 1i1 - 1f2 + 13/5 >= 0; i1 - 1f2 + 13/5 >= 0; - 1f2 + 8/5 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 + 1/2 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 3/2 >= 0; - 1f3 + 3/2 >= 0; } assign texprs inter: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 - 1i3 + 1 >= 0; i1 - 1i3 - 1 >= 0; - 1i3 >= 0; - 1i1 + f2 + 1 >= 0; i1 + f2 + 1 >= 0; - 1i3 + f2 >= 0; f2 >= 0; - 1i1 - 1f2 + 13/5 >= 0; i1 - 1f2 + 13/5 >= 0; - 1i3 - 1f2 + 8/5 >= 0; - 1f2 + 8/5 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; - 1i3 + f3 + 1/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 + 1/2 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1i3 - 1f3 + 3/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 3/2 >= 0; - 1f3 + 3/2 >= 0; } subst linexpr: { - 1f1 + 18 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } subst linexpr inter: { i1 - 1i3 - 1 >= 0; - 1f1 + 18 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } subst linexprs: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1f3 + 3/2 >= 0; } subst linexprs inter: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 - 1i3 + 1 >= 0; i1 - 1i3 - 1 >= 0; - 1i3 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; - 1i3 + f3 + 1/2 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1i3 - 1f3 + 3/2 >= 0; - 1f3 + 3/2 >= 0; } subst texpr: { - 1f1 + 18 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } subst texpr inter: { i1 - 1i3 - 1 >= 0; - 1f1 + 18 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } subst texprs: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1f3 + 3/2 >= 0; } subst texprs inter: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 - 1i3 + 1 >= 0; i1 - 1i3 - 1 >= 0; - 1i3 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; - 1i3 + f3 + 1/2 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1i3 - 1f3 + 3/2 >= 0; - 1f3 + 3/2 >= 0; } forget: { - 1f1 + 18 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } forget 0: { i1 >= 0; - 1i1 >= 0; - 1i1 - 1f1 + 18 >= 0; i1 - 1f1 + 18 >= 0; - 1f1 + 18 >= 0; - 1i1 + f2 - 1/2 >= 0; i1 + f2 - 1/2 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1i1 - 1f2 + 8/5 >= 0; i1 - 1f2 + 8/5 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1i1 + f3 + 1/2 >= 0; i1 + f3 + 1/2 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 3/2 >= 0; i1 - 1f3 + 3/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } forgets: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1f3 + 3/2 >= 0; } forgets 0: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 + f1 + 1 >= 0; i1 + f1 + 1 >= 0; f1 >= 0; - 1i1 - 1f1 + 1 >= 0; i1 - 1f1 + 1 >= 0; - 1f1 >= 0; - 1i1 + f2 + 1 >= 0; i1 + f2 + 1 >= 0; - 1f1 + f2 >= 0; f1 + f2 >= 0; f2 >= 0; - 1i1 - 1f2 + 1 >= 0; i1 - 1f2 + 1 >= 0; - 1f1 - 1f2 >= 0; f1 - 1f2 >= 0; - 1f2 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; - 1f1 + f3 + 1/2 >= 0; f1 + f3 + 1/2 >= 0; - 1f2 + f3 + 1/2 >= 0; f2 + f3 + 1/2 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1f1 - 1f3 + 3/2 >= 0; f1 - 1f3 + 3/2 >= 0; - 1f2 - 1f3 + 3/2 >= 0; f2 - 1f3 + 3/2 >= 0; - 1f3 + 3/2 >= 0; } forgets: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1f3 + 3/2 >= 0; } forgets 0: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 + f1 + 1 >= 0; i1 + f1 + 1 >= 0; f1 >= 0; - 1i1 - 1f1 + 1 >= 0; i1 - 1f1 + 1 >= 0; - 1f1 >= 0; - 1i1 + f2 + 1 >= 0; i1 + f2 + 1 >= 0; - 1f1 + f2 >= 0; f1 + f2 >= 0; f2 >= 0; - 1i1 - 1f2 + 1 >= 0; i1 - 1f2 + 1 >= 0; - 1f1 - 1f2 >= 0; f1 - 1f2 >= 0; - 1f2 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; - 1f1 + f3 + 1/2 >= 0; f1 + f3 + 1/2 >= 0; - 1f2 + f3 + 1/2 >= 0; f2 + f3 + 1/2 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1f1 - 1f3 + 3/2 >= 0; f1 - 1f3 + 3/2 >= 0; - 1f2 - 1f3 + 3/2 >= 0; f2 - 1f3 + 3/2 >= 0; - 1f3 + 3/2 >= 0; } change env: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 - 1f1 + 19 >= 0; i1 - 1f1 + 19 >= 0; - 1f1 + 18 >= 0; - 1i1 + f2 + 1/2 >= 0; i1 + f2 + 1/2 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1i1 - 1f2 + 13/5 >= 0; i1 - 1f2 + 13/5 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) change env 0: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 + i2 + 1 >= 0; i1 + i2 + 1 >= 0; i2 >= 0; - 1i1 - 1i2 + 1 >= 0; i1 - 1i2 + 1 >= 0; - 1i2 >= 0; - 1i1 - 1f1 + 19 >= 0; i1 - 1f1 + 19 >= 0; - 1i2 - 1f1 + 18 >= 0; i2 - 1f1 + 18 >= 0; - 1f1 + 18 >= 0; - 1i1 + f2 + 1/2 >= 0; i1 + f2 + 1/2 >= 0; - 1i2 + f2 - 1/2 >= 0; i2 + f2 - 1/2 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1i1 - 1f2 + 13/5 >= 0; i1 - 1f2 + 13/5 >= 0; - 1i2 - 1f2 + 8/5 >= 0; i2 - 1f2 + 8/5 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; - 1i2 + f3 + 1/2 >= 0; i2 + f3 + 1/2 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1i2 - 1f3 + 3/2 >= 0; i2 - 1f3 + 3/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) minimize env: { i1 + 1 >= 0; - 1i1 + 1 >= 0; - 1i1 - 1f1 + 19 >= 0; i1 - 1f1 + 19 >= 0; - 1f1 + 18 >= 0; - 1i1 + f2 + 1/2 >= 0; i1 + f2 + 1/2 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1i1 - 1f2 + 13/5 >= 0; i1 - 1f2 + 13/5 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } 0: i1 (int) 1: f1 (real) 2: f2 (real) 3: f3 (real) rename: { truc + 1 >= 0; - 1truc + 1 >= 0; - 1truc + f0 + 1/2 >= 0; truc + f0 + 1/2 >= 0; f0 - 1/2 >= 0; - 1truc - 1f0 + 13/5 >= 0; truc - 1f0 + 13/5 >= 0; - 1f0 + 8/5 >= 0; - 1truc - 1f1 + 19 >= 0; truc - 1f1 + 19 >= 0; - 1f0 - 1f1 + 98/5 >= 0; f0 - 1f1 + 35/2 >= 0; - 1f1 + 18 >= 0; - 1truc + f3 + 3/2 >= 0; truc + f3 + 3/2 >= 0; - 1f0 + f3 + 21/10 >= 0; f0 + f3 >= 0; - 1f1 + f3 + 37/2 >= 0; f3 + 1/2 >= 0; - 1truc - 1f3 + 5/2 >= 0; truc - 1f3 + 5/2 >= 0; - 1f0 - 1f3 + 31/10 >= 0; f0 - 1f3 + 1 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f3 + 3/2 >= 0; } expand: { f0 + 1 >= 0; - 1f0 + 1 >= 0; - 1f0 + i1 + 2 >= 0; f0 + i1 + 2 >= 0; i1 + 1 >= 0; - 1f0 - 1i1 + 2 >= 0; f0 - 1i1 + 2 >= 0; - 1i1 + 1 >= 0; - 1f0 + truc + 2 >= 0; f0 + truc + 2 >= 0; - 1i1 + truc + 2 >= 0; i1 + truc + 2 >= 0; truc + 1 >= 0; - 1f0 - 1truc + 2 >= 0; f0 - 1truc + 2 >= 0; - 1i1 - 1truc + 2 >= 0; i1 - 1truc + 2 >= 0; - 1truc + 1 >= 0; - 1f0 - 1f1 + 19 >= 0; f0 - 1f1 + 19 >= 0; - 1i1 - 1f1 + 19 >= 0; i1 - 1f1 + 19 >= 0; - 1truc - 1f1 + 19 >= 0; truc - 1f1 + 19 >= 0; - 1f1 + 18 >= 0; - 1f0 + f2 + 1/2 >= 0; f0 + f2 + 1/2 >= 0; - 1i1 + f2 + 1/2 >= 0; i1 + f2 + 1/2 >= 0; - 1truc + f2 + 1/2 >= 0; truc + f2 + 1/2 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1f0 - 1f2 + 13/5 >= 0; f0 - 1f2 + 13/5 >= 0; - 1i1 - 1f2 + 13/5 >= 0; i1 - 1f2 + 13/5 >= 0; - 1truc - 1f2 + 13/5 >= 0; truc - 1f2 + 13/5 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1f0 + f3 + 3/2 >= 0; f0 + f3 + 3/2 >= 0; - 1i1 + f3 + 3/2 >= 0; i1 + f3 + 3/2 >= 0; - 1truc + f3 + 3/2 >= 0; truc + f3 + 3/2 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1f0 - 1f3 + 5/2 >= 0; f0 - 1f3 + 5/2 >= 0; - 1i1 - 1f3 + 5/2 >= 0; i1 - 1f3 + 5/2 >= 0; - 1truc - 1f3 + 5/2 >= 0; truc - 1f3 + 5/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } fold: { truc + 1 >= 0; - 1truc + 1 >= 0; - 1truc - 1f1 + 19 >= 0; truc - 1f1 + 19 >= 0; - 1f1 + 18 >= 0; - 1truc + f2 + 1/2 >= 0; truc + f2 + 1/2 >= 0; - 1f1 + f2 + 35/2 >= 0; f2 - 1/2 >= 0; - 1truc - 1f2 + 13/5 >= 0; truc - 1f2 + 13/5 >= 0; - 1f1 - 1f2 + 98/5 >= 0; - 1f2 + 8/5 >= 0; - 1truc + f3 + 3/2 >= 0; truc + f3 + 3/2 >= 0; - 1f1 + f3 + 37/2 >= 0; - 1f2 + f3 + 21/10 >= 0; f2 + f3 >= 0; f3 + 1/2 >= 0; - 1truc - 1f3 + 5/2 >= 0; truc - 1f3 + 5/2 >= 0; - 1f1 - 1f3 + 39/2 >= 0; - 1f2 - 1f3 + 31/10 >= 0; f2 - 1f3 + 1 >= 0; - 1f3 + 3/2 >= 0; } widening: top widening thr: top PPL (polyhedra, loose) ====================== library: PPL::Polyhedron, loose mode version: 0.9 level 1 construct top: top construct bottom: bottom construct box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; i1 + 1 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; } construct box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; i1 + 1 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; } construct lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } construct tcons: { i1 - 1i3 - 1 >= 0; } construct copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } construct copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } assign top: top assign bottom: bottom assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 2f2 + 3 >= 0; - 5f3 + 8 >= 0; i1 + 1 >= 0; 2f3 - 1 >= 0; 2f2 + 1 >= 0; } assign lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } assign tcons: { i1 - 1i3 - 1 >= 0; } assign copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } assign top: top assign top: top assign bottom: bottom assign bottom: bottom assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 2f2 + 3 >= 0; - 5f3 + 8 >= 0; i1 + 1 >= 0; 2f3 - 1 >= 0; 2f2 + 1 >= 0; } assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; i1 + 1 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; } assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; i1 + 1 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; } assign lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } assign tcons { i1 - 1i3 - 1 >= 0; } assign copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } unchanged: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } minimize: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } canonicalize: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } approximate: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } closure: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } print: array of constraints of size 3 0: 5i1 + 4i3 + 3f1 + f3 + 3 = 0 1: -i1 - i3 - 20 >= 0 2: i1 + 2i3 + 3f1 + 4f2 + 1 >= 0 printdiff: not implemented apron::printdiff(manager&, const abstract1&, const abstract1&, FILE*) : not implemented dump: abstract value of level 1: environment: dim = (2,3), count = 19 0: i1 1: i3 2: f1 3: f2 4: f3 constraints: array of constraints of size 3 0: 5x0 + 4x1 + 3x2 + x4 + 3 = 0 1: -x0 - x1 - 20 >= 0 2: x0 + 2x1 + 3x2 + 4x3 + 1 >= 0 generators: array of generator of size 5 0: LINE: 4x0 - 4x1 + x3 - 4x4 1: LINE: 4x2 - 3x3 - 12x4 2: RAY: x3 3: RAY: -4x0 + x3 + 20x4 4: VERTEX: -20x0 + 19/4x3 + 97x4 serialization not implemented: apron::abstract1::serialize_raw(manager&) : environment: 0: i1 (int) 1: i3 (int) 2: f1 (real) 3: f2 (real) 4: f3 (real) size: 3184 get abstract0: { 5x0 + 4x1 + 3x2 + x4 + 3 = 0; - 1x0 - 1x1 - 20 >= 0; x0 + 2x1 + 3x2 + 4x3 + 1 >= 0; } set abstract0: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 2f2 + 3 >= 0; - 5f3 + 8 >= 0; i1 + 1 >= 0; 2f3 - 1 >= 0; 2f2 + 1 >= 0; } sat lincons: true sat tcons: false sat interval: true unconstrainned: false bound linexpr: [0,+oo] bound texpr: [-oo,+oo] bound variable: [-oo,+oo] to generator: { LINE: 4i1 - 4i3 + f2 - 4f3; LINE: 4f1 - 3f2 - 12f3; RAY: f2; RAY: - 4i1 + f2 + 20f3; VERTEX: - 20i1 + 19/4f2 + 97f3; } to lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } to tcons: { 3 + 5 * i1 + 4 * i3 + 3 * f1 + 0 * f2 + 1 * f3 = 0; -20 + -1 * i1 + -1 * i3 + 0 * f1 + 0 * f2 + 0 * f3 >= 0; 1 + 1 * i1 + 2 * i3 + 3 * f1 + 4 * f2 + 0 * f3 >= 0; } to box: { [-oo,+oo] [-oo,+oo] [-oo,+oo] [-oo,+oo] [-oo,+oo] } meet: bottom meet array: bottom meet lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i1 - 1i3 - 1 >= 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } meet tcons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; i1 - 1i3 - 1 >= 0; } join: top join array: top add rays: { 2f3 + 1 >= 0; - 2f3 + 3 >= 0; - 8f1 + 6f2 + 141 >= 0; - 8i1 + 2f2 + 7 >= 0; } unify: { - 1i1 + 1 >= 0; - 1i3 + 18 >= 0; - 2f1 + 3 >= 0; i1 + 1 >= 0; - 5f2 + 8 >= 0; 2f1 + 1 >= 0; - 2f3 + 3 >= 0; 2f2 - 1 >= 0; 2f3 - 1 >= 0; } assign linexpr: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; i1 + i3 + 21 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; } assign linexpr inter: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; i1 + i3 + 21 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; } assign linexprs: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } assign linexprs inter: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } assign texpr: { - 1f1 + 18 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; - 2f3 + 3 >= 0; - 5f2 + 8 >= 0; } assign texpr inter: { - 1f1 + 18 >= 0; i1 - 1i3 - 1 >= 0; 2f2 - 1 >= 0; 2f3 + 1 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; } assign texprs: { - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; - 5f2 + 8 >= 0; f2 >= 0; } assign texprs inter: { i1 - 1i3 - 1 >= 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; - 5f2 + 8 >= 0; f2 >= 0; } subst linexpr: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; i1 + i3 + 21 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; } subst linexpr inter: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; i1 + i3 + 21 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; } subst linexprs: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } subst linexprs inter: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } subst texpr: { - 1f1 + 18 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; - 2f3 + 3 >= 0; - 5f2 + 8 >= 0; } subst texpr inter: { - 1f1 + 18 >= 0; i1 - 1i3 - 1 >= 0; 2f2 - 1 >= 0; 2f3 + 1 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; } subst texprs: { i1 + 1 >= 0; 2f3 + 1 >= 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; } subst texprs inter: { i1 - 1i3 - 1 >= 0; i1 + 1 >= 0; 2f3 + 1 >= 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; } forget: { 2f2 - 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; } forget 0: { i1 = 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; - 1f1 + 18 >= 0; } forgets: { - 1i1 + 1 >= 0; 2f3 + 1 >= 0; - 2f3 + 3 >= 0; i1 + 1 >= 0; } forgets 0: { f2 = 0; f1 = 0; 2f3 + 1 >= 0; i1 + 1 >= 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; } forgets: { - 1i1 + 1 >= 0; 2f3 + 1 >= 0; - 2f3 + 3 >= 0; i1 + 1 >= 0; } forgets 0: { f2 = 0; f1 = 0; 2f3 + 1 >= 0; i1 + 1 >= 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; } change env: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; i1 + 1 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) change env 0: { i2 = 0; - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; i1 + 1 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) minimize env: { - 1f1 + 18 >= 0; - 2f3 + 3 >= 0; - 5f2 + 8 >= 0; - 1i1 + 1 >= 0; i1 + 1 >= 0; 2f2 - 1 >= 0; 2f3 + 1 >= 0; } 0: i1 (int) 1: f1 (real) 2: f2 (real) 3: f3 (real) rename: { - 1truc + 1 >= 0; - 5f0 + 8 >= 0; - 1f1 + 18 >= 0; - 2f3 + 3 >= 0; truc + 1 >= 0; 2f3 + 1 >= 0; 2f0 - 1 >= 0; } expand: { - 1f0 + 1 >= 0; - 1i1 + 1 >= 0; - 1truc + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; f0 + 1 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; truc + 1 >= 0; i1 + 1 >= 0; } fold: { - 1f1 + 18 >= 0; - 2f3 + 3 >= 0; - 5f2 + 8 >= 0; - 1truc + 1 >= 0; truc + 1 >= 0; 2f2 - 1 >= 0; 2f3 + 1 >= 0; } widening: top widening thr: top PPL (polyhedra, strict) ======================= library: PPL::Polyhedron, strict mode version: 0.9 level 1 construct top: top construct bottom: bottom construct box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } construct box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } construct lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } construct tcons: { i1 - 1i3 - 1 >= 0; } construct copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } construct copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } assign top: top assign bottom: bottom assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 2f2 + 3 >= 0; - 5f3 + 8 >= 0; 2f3 - 1 >= 0; 2f2 + 1 >= 0; i1 + 1 >= 0; } assign lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } assign tcons: { i1 - 1i3 - 1 >= 0; } assign copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } assign top: top assign top: top assign bottom: bottom assign bottom: bottom assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 2f2 + 3 >= 0; - 5f3 + 8 >= 0; 2f3 - 1 >= 0; 2f2 + 1 >= 0; i1 + 1 >= 0; } assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } assign lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } assign tcons { i1 - 1i3 - 1 >= 0; } assign copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } unchanged: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } minimize: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } canonicalize: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } approximate: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } closure: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; } print: array of constraints of size 3 0: 5i1 + 4i3 + 3f1 + f3 + 3 = 0 1: -i1 - i3 - 20 >= 0 2: i1 + 2i3 + 3f1 + 4f2 + 1 > 0 printdiff: not implemented apron::printdiff(manager&, const abstract1&, const abstract1&, FILE*) : not implemented dump: abstract value of level 1: environment: dim = (2,3), count = 19 0: i1 1: i3 2: f1 3: f2 4: f3 constraints: array of constraints of size 3 0: 5x0 + 4x1 + 3x2 + x4 + 3 = 0 1: -x0 - x1 - 20 >= 0 2: x0 + 2x1 + 3x2 + 4x3 + 1 > 0 generators: (inexact) array of generator of size 6 0: LINE: 4x2 - 3x3 - 12x4 1: LINE: 4x0 - 4x1 + x3 - 4x4 2: VERTEX: -20x0 + 19/4x3 + 97x4 3: VERTEX: -20x0 + 5x3 + 97x4 4: RAY: -4x0 + x3 + 20x4 5: RAY: x3 serialization not implemented: apron::abstract1::serialize_raw(manager&) : environment: 0: i1 (int) 1: i3 (int) 2: f1 (real) 3: f2 (real) 4: f3 (real) size: 4344 get abstract0: { 5x0 + 4x1 + 3x2 + x4 + 3 = 0; - 1x0 - 1x1 - 20 >= 0; x0 + 2x1 + 3x2 + 4x3 + 1 > 0; } set abstract0: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 2f2 + 3 >= 0; - 5f3 + 8 >= 0; 2f3 - 1 >= 0; 2f2 + 1 >= 0; i1 + 1 >= 0; } sat lincons: true sat tcons: false sat interval: true unconstrainned: false bound linexpr: [0,+oo] bound texpr: [-oo,+oo] bound variable: [-oo,+oo] to generator: { LINE: 4f1 - 3f2 - 12f3; LINE: 4i1 - 4i3 + f2 - 4f3; VERTEX: - 20i1 + 19/4f2 + 97f3; VERTEX: - 20i1 + 5f2 + 97f3; RAY: - 4i1 + f2 + 20f3; RAY: f2; } to lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } to tcons: { 3 + 5 * i1 + 4 * i3 + 3 * f1 + 0 * f2 + 1 * f3 = 0; -20 + -1 * i1 + -1 * i3 + 0 * f1 + 0 * f2 + 0 * f3 >= 0; 1 + 1 * i1 + 2 * i3 + 3 * f1 + 4 * f2 + 0 * f3 > 0; } to box: { [-oo,+oo] [-oo,+oo] [-oo,+oo] [-oo,+oo] [-oo,+oo] } meet: bottom meet array: bottom meet lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i1 - 1i3 - 1 >= 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; } meet tcons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; i1 - 1i3 - 1 >= 0; } join: top join array: top add rays: { 2f3 + 1 >= 0; - 2f3 + 3 >= 0; - 8f1 + 6f2 + 141 >= 0; - 8i1 + 2f2 + 7 >= 0; } unify: { - 1i1 + 1 >= 0; - 1i3 + 18 >= 0; - 2f1 + 3 >= 0; i1 + 1 >= 0; - 5f2 + 8 >= 0; 2f1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 - 1 >= 0; 2f2 - 1 >= 0; } assign linexpr: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + i3 + 21 >= 0; } assign linexpr inter: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + i3 + 21 >= 0; } assign linexprs: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } assign linexprs inter: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } assign texpr: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; } assign texpr inter: { - 1f1 + 18 >= 0; i1 - 1i3 - 1 >= 0; - 2f3 + 3 >= 0; - 5f2 + 8 >= 0; 2f2 - 1 >= 0; 2f3 + 1 >= 0; } assign texprs: { - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; f2 >= 0; - 5f2 + 8 >= 0; } assign texprs inter: { i1 - 1i3 - 1 >= 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; f2 >= 0; - 5f2 + 8 >= 0; } subst linexpr: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + i3 + 21 >= 0; } subst linexpr inter: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + i3 + 21 >= 0; } subst linexprs: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } subst linexprs inter: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } subst texpr: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; } subst texpr inter: { - 1f1 + 18 >= 0; i1 - 1i3 - 1 >= 0; - 2f3 + 3 >= 0; - 5f2 + 8 >= 0; 2f2 - 1 >= 0; 2f3 + 1 >= 0; } subst texprs: { - 2f3 + 3 >= 0; - 1i1 + 1 >= 0; i1 + 1 >= 0; 2f3 + 1 >= 0; } subst texprs inter: { i1 - 1i3 - 1 >= 0; - 2f3 + 3 >= 0; - 1i1 + 1 >= 0; i1 + 1 >= 0; 2f3 + 1 >= 0; } forget: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; } forget 0: { i1 = 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; - 1f1 + 18 >= 0; } forgets: { - 1i1 + 1 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; - 2f3 + 3 >= 0; } forgets 0: { f2 = 0; f1 = 0; 2f3 + 1 >= 0; i1 + 1 >= 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; } forgets: { - 1i1 + 1 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; - 2f3 + 3 >= 0; } forgets 0: { f2 = 0; f1 = 0; 2f3 + 1 >= 0; i1 + 1 >= 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; } change env: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) change env 0: { i2 = 0; - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) minimize env: { - 1f1 + 18 >= 0; - 1i1 + 1 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; i1 + 1 >= 0; 2f2 - 1 >= 0; 2f3 + 1 >= 0; } 0: i1 (int) 1: f1 (real) 2: f2 (real) 3: f3 (real) rename: { - 1truc + 1 >= 0; - 5f0 + 8 >= 0; - 1f1 + 18 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f0 - 1 >= 0; truc + 1 >= 0; } expand: { - 1f0 + 1 >= 0; - 1i1 + 1 >= 0; - 1truc + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; truc + 1 >= 0; i1 + 1 >= 0; f0 + 1 >= 0; } fold: { - 1f1 + 18 >= 0; - 1truc + 1 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; truc + 1 >= 0; 2f2 - 1 >= 0; 2f3 + 1 >= 0; } widening: top widening thr: top PPL (grids) =========== library: PPL::Grid version: 0.9 level 1 construct top: { i3 = 0 mod 1; i1 = 0 mod 1; } construct bottom: bottom construct box: { i3 = 0 mod 1; i1 = 0 mod 1; } construct box: { i3 = 0 mod 1; i1 = 0 mod 1; } construct lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } construct tcons: { i3 = 0 mod 1; i1 = 0 mod 1; } construct copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } construct copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } assign top: { i3 = 0 mod 1; i1 = 0 mod 1; } assign bottom: bottom assign box: { i3 = 0 mod 1; i1 = 0 mod 1; } assign lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } assign tcons: { i3 = 0 mod 1; i1 = 0 mod 1; } assign copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } assign top: { i3 = 0 mod 1; i1 = 0 mod 1; } assign top: { i3 = 0 mod 1; i1 = 0 mod 1; } assign bottom: bottom assign bottom: bottom assign box: { i3 = 0 mod 1; i1 = 0 mod 1; } assign box: { i3 = 0 mod 1; i1 = 0 mod 1; } assign box: { i3 = 0 mod 1; i1 = 0 mod 1; } assign lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } assign tcons { i3 = 0 mod 1; i1 = 0 mod 1; } assign copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } unchanged: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } minimize: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } canonicalize: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } approximate: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } closure: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } print: array of constraints of size 4 0: 5i1 + 4i3 + 3f1 + f3 + 3 = 0 1: i3 - 11f1 + 3f2 + 2 = 0 mod 5 2: 5i3 = 0 mod 5 3: 5i1 = 0 mod 5 printdiff: not implemented apron::printdiff(manager&, const abstract1&, const abstract1&, FILE*) : not implemented dump: abstract value of level 1: environment: dim = (2,3), count = 19 0: i1 1: i3 2: f1 3: f2 4: f3 constraints: array of constraints of size 4 0: 5x0 + 4x1 + 3x2 + x4 + 3 = 0 1: x1 - 11x2 + 3x3 + 2 = 0 mod 5 2: 5x1 = 0 mod 5 3: 5x0 = 0 mod 5 generators: array of generator of size 5 0: VERTEX: -2/3x3 - 3x4 1: LINEMOD: x0 - 5x4 2: LINEMOD: x1 - 1/3x3 - 4x4 3: LINE: 3x2 + 11x3 - 9x4 4: LINEMOD: 5/3x3 serialization not implemented: apron::abstract1::serialize_raw(manager&) : environment: 0: i1 (int) 1: i3 (int) 2: f1 (real) 3: f2 (real) 4: f3 (real) size: 3784 get abstract0: { 5x0 + 4x1 + 3x2 + x4 + 3 = 0; x1 - 11x2 + 3x3 + 2 = 0 mod 5; 5x1 = 0 mod 5; 5x0 = 0 mod 5; } set abstract0: { i3 = 0 mod 1; i1 = 0 mod 1; } sat lincons: top sat tcons: false sat interval: false unconstrainned: true bound linexpr: [-oo,+oo] bound texpr: [-oo,+oo] bound variable: [-oo,+oo] to generator: { VERTEX: - 2/3f2 - 3f3; LINEMOD: i1 - 5f3; LINEMOD: i3 - 1/3f2 - 4f3; LINE: 3f1 + 11f2 - 9f3; LINEMOD: 5/3f2; } to lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } to tcons: { 3 + 5 * i1 + 4 * i3 + 3 * f1 + 0 * f2 + 1 * f3 = 0; 2 + 0 * i1 + 1 * i3 + -11 * f1 + 3 * f2 + 0 * f3 = 0 mod 5; 0 + 0 * i1 + 5 * i3 + 0 * f1 + 0 * f2 + 0 * f3 = 0 mod 5; 0 + 5 * i1 + 0 * i3 + 0 * f1 + 0 * f2 + 0 * f3 = 0 mod 5; } to box: { [-oo,+oo] [-oo,+oo] [-oo,+oo] [-oo,+oo] [-oo,+oo] } meet: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } meet array: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } meet lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } meet tcons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } join: { i3 = 0 mod 1; i1 = 0 mod 1; } join array: { i3 = 0 mod 1; i1 = 0 mod 1; } add rays: { i3 = 0 mod 1; i1 = 0 mod 1; } unify: { i3 = 0 mod 1; i2 = 0 mod 1; i1 = 0 mod 1; } assign linexpr: { i3 = 0 mod 1; i1 = 0 mod 1; } assign linexpr inter: { i3 = 0 mod 1; i1 = 0 mod 1; } assign linexprs: { i1 + i3 + f1 + 20 = 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign linexprs inter: { i1 + i3 + f1 + 20 = 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign texpr: { i3 = 0 mod 1; i1 = 0 mod 1; } assign texpr inter: { i3 = 0 mod 1; i1 = 0 mod 1; } assign texprs: { i3 = 0 mod 1; i1 = 0 mod 1; } assign texprs inter: { i3 = 0 mod 1; i1 = 0 mod 1; } subst linexpr: { i3 = 0 mod 1; i1 = 0 mod 1; } subst linexpr inter: { i3 = 0 mod 1; i1 = 0 mod 1; } subst linexprs: { i3 = 0 mod 1; i1 = 0 mod 1; } subst linexprs inter: { i3 = 0 mod 1; i1 = 0 mod 1; } subst texpr: { i3 = 0 mod 1; i1 = 0 mod 1; } subst texpr inter: { i3 = 0 mod 1; i1 = 0 mod 1; } subst texprs: { i3 = 0 mod 1; i1 = 0 mod 1; } subst texprs inter: { i3 = 0 mod 1; i1 = 0 mod 1; } forget: { i3 = 0 mod 1; i1 = 0 mod 1; } forget 0: { i3 = 0 mod 1; i1 = 0; } forgets: { i3 = 0 mod 1; i1 = 0 mod 1; } forgets 0: { f2 = 0; f1 = 0; i3 = 0 mod 1; i1 = 0 mod 1; } forgets: { i3 = 0 mod 1; i1 = 0 mod 1; } forgets 0: { f2 = 0; f1 = 0; i3 = 0 mod 1; i1 = 0 mod 1; } change env: { i3 = 0 mod 1; i2 = 0 mod 1; i1 = 0 mod 1; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) change env 0: { i3 = 0 mod 1; i2 = 0; i1 = 0 mod 1; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) minimize env: { i3 = 0 mod 1; i2 = 0 mod 1; i1 = 0 mod 1; } 0: i1 (int) 1: i2 (int) 2: i3 (int) rename: { i3 = 0 mod 1; truc = 0 mod 1; } expand: { truc = 0 mod 1; i3 = 0 mod 1; i1 = 0 mod 1; f0 = 0 mod 1; } fold: { i3 = 0 mod 1; truc = 0 mod 1; } widening: { i3 = 0 mod 1; i1 = 0 mod 1; } widening thr: { i3 = 0 mod 1; i1 = 0 mod 1; } Product Polka (loose) * PPL grids ================================= library: Reduced product of polka, loose mode, PPL::Grid version: 3.0 with NUMINT_MPZ, 0.9 level 1 construct top: { i3 = 0 mod 1; i1 = 0 mod 1; } construct bottom: bottom construct box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } construct box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } construct lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } construct tcons: { i1 - 1i3 - 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } construct copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } construct copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } assign top: { i3 = 0 mod 1; i1 = 0 mod 1; } assign bottom: bottom assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 2f2 + 3 >= 0; - 5f3 + 8 >= 0; 2f3 - 1 >= 0; 2f2 + 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } assign tcons: { i1 - 1i3 - 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } assign top: { i3 = 0 mod 1; i1 = 0 mod 1; } assign top: { i3 = 0 mod 1; i1 = 0 mod 1; } assign bottom: bottom assign bottom: bottom assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 2f2 + 3 >= 0; - 5f3 + 8 >= 0; 2f3 - 1 >= 0; 2f2 + 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } assign tcons { i1 - 1i3 - 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } unchanged: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } minimize: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } canonicalize: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } approximate: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } closure: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } print: reduced product of library Reduced product of polka, loose mode, PPL::Grid polyhedron of dim (2,3) array of constraints of size 3 0: 5i1 + 4i3 + 3f1 + f3 + 3 = 0 1: -i1 - i3 - 20 >= 0 2: i1 + 2i3 + 3f1 + 4f2 + 1 >= 0 array of constraints of size 4 0: 5i1 + 4i3 + 3f1 + f3 + 3 = 0 1: i3 - 11f1 + 3f2 + 2 = 0 mod 5 2: 5i3 = 0 mod 5 3: 5i1 = 0 mod 5 printdiff: reduced product of library Reduced product of polka, loose mode, PPL::Grid not implemented apron::printdiff(manager&, const abstract1&, const abstract1&, FILE*) : PPL::Grid: dump: abstract value of level 1: environment: dim = (2,3), count = 19 0: i1 1: i3 2: f1 3: f2 4: f3 reduced product of library Reduced product of polka, loose mode, PPL::Grid polyhedron of dim (2,3) Constraints: 4 7 0 3 5 4 3 0 1 1 -20 -1 -1 0 0 0 1 1 0 0 0 0 0 1 1 1 2 3 4 0 Frames: 5 7 0 0 -3 3 -1 0 6 0 0 6 -6 -2 3 0 1 0 -3 3 1 0 0 1 0 1 -2 1 0 0 1 3 57 -117 58 0 0 satC: 5 1 0000,0000 0000,0000 0000,0000 0000,0000 0000,0000 0000,0000 0000,0000 0000,0000 0001,0000 0000,0000 0000,0000 0000,0000 0100,0000 0000,0000 0000,0000 0000,0000 0010,0000 0000,0000 0000,0000 0000,0000 constraints: array of constraints of size 4 0: 5x0 + 4x1 + 3x2 + x4 + 3 = 0 1: x1 - 11x2 + 3x3 + 2 = 0 mod 5 2: 5x1 = 0 mod 5 3: 5x0 = 0 mod 5 generators: array of generator of size 5 0: VERTEX: -2/3x3 - 3x4 1: LINEMOD: x0 - 5x4 2: LINEMOD: x1 - 1/3x3 - 4x4 3: LINE: 3x2 + 11x3 - 9x4 4: LINEMOD: 5/3x3 serialization not implemented: apron::abstract1::serialize_raw(manager&) : environment: 0: i1 (int) 1: i3 (int) 2: f1 (real) 3: f2 (real) 4: f3 (real) size: 3829 get abstract0: { 5x0 + 4x1 + 3x2 + x4 + 3 = 0; - 1x0 - 1x1 - 20 >= 0; x0 + 2x1 + 3x2 + 4x3 + 1 >= 0; 5x0 + 4x1 + 3x2 + x4 + 3 = 0; x1 - 11x2 + 3x3 + 2 = 0 mod 5; 5x1 = 0 mod 5; 5x0 = 0 mod 5; } set abstract0: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 2f2 + 3 >= 0; - 5f3 + 8 >= 0; 2f3 - 1 >= 0; 2f2 + 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } sat lincons: true sat tcons: false sat interval: true unconstrainned: false bound linexpr: [0,+oo] bound texpr: [-oo,+oo] bound variable: [-oo,+oo] to generator: not implemented to lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } to tcons: { 3 + 5 * i1 + 4 * i3 + 3 * f1 + 0 * f2 + 1 * f3 = 0; -20 + -1 * i1 + -1 * i3 + 0 * f1 + 0 * f2 + 0 * f3 >= 0; 1 + 1 * i1 + 2 * i3 + 3 * f1 + 4 * f2 + 0 * f3 >= 0; 3 + 5 * i1 + 4 * i3 + 3 * f1 + 0 * f2 + 1 * f3 = 0; 2 + 0 * i1 + 1 * i3 + -11 * f1 + 3 * f2 + 0 * f3 = 0 mod 5; 0 + 0 * i1 + 5 * i3 + 0 * f1 + 0 * f2 + 0 * f3 = 0 mod 5; 0 + 5 * i1 + 0 * i3 + 0 * f1 + 0 * f2 + 0 * f3 = 0 mod 5; } to box: { [-oo,+oo] [-oo,+oo] [-oo,+oo] [-oo,+oo] [-oo,+oo] } meet: bottom meet array: bottom meet lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 - 1i3 - 1 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } meet tcons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 - 1i3 - 1 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } join: { i3 = 0 mod 1; i1 = 0 mod 1; } join array: { i3 = 0 mod 1; i1 = 0 mod 1; } add rays: { - 8i1 + 2f2 + 7 >= 0; - 8f1 + 6f2 + 141 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } unify: { - 1i1 + 1 >= 0; - 1i3 + 18 >= 0; - 2f1 + 3 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 - 1 >= 0; 2f2 - 1 >= 0; 2f1 + 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i2 = 0 mod 1; i1 = 0 mod 1; } assign linexpr: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + i3 + 21 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign linexpr inter: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + i3 + 21 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign linexprs: { i1 + i3 + f1 + 20 = 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; 5i1 + 4i3 - 1f2 + f3 + 44 >= 0; i1 + i3 + f1 + 20 = 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign linexprs inter: { i1 + i3 + f1 + 20 = 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + 1 >= 0; 5i1 + 4i3 - 1f2 + f3 + 44 >= 0; i1 + i3 + f1 + 20 = 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign texpr: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign texpr inter: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign texprs: { - 1i1 + 1 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; f2 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign texprs inter: { - 1i1 + 1 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; f2 >= 0; i1 - 1i3 - 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } subst linexpr: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + i3 + 21 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } subst linexpr inter: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + i3 + 21 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } subst linexprs: { - 25i1 - 20i3 - 15f1 - 5f3 + 58 >= 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; i1 + i3 + 38 >= 0; 10i1 + 8i3 + 6f1 + 2f3 - 21 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } subst linexprs inter: { - 25i1 - 20i3 - 15f1 - 5f3 + 58 >= 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + 1 >= 0; i1 + i3 + 38 >= 0; 10i1 + 8i3 + 6f1 + 2f3 - 21 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } subst texpr: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } subst texpr inter: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } subst texprs: { - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } subst texprs inter: { - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } forget: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } forget 0: { i1 = 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i3 = 0 mod 1; i1 = 0; } forgets: { - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } forgets 0: { f2 = 0; f1 = 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; f2 = 0; f1 = 0; i3 = 0 mod 1; i1 = 0 mod 1; } forgets: { - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } forgets 0: { f2 = 0; f1 = 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; f2 = 0; f1 = 0; i3 = 0 mod 1; i1 = 0 mod 1; } change env: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i2 = 0 mod 1; i1 = 0 mod 1; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) change env 0: { i2 = 0; - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i2 = 0; i1 = 0 mod 1; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) minimize env: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i2 = 0 mod 1; i1 = 0 mod 1; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) rename: { - 1truc + 1 >= 0; - 5f0 + 8 >= 0; - 1f1 + 18 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f0 - 1 >= 0; truc + 1 >= 0; i3 = 0 mod 1; truc = 0 mod 1; } expand: { - 1f0 + 1 >= 0; - 1i1 + 1 >= 0; - 1truc + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; truc + 1 >= 0; i1 + 1 >= 0; f0 + 1 >= 0; truc = 0 mod 1; i3 = 0 mod 1; i1 = 0 mod 1; f0 = 0 mod 1; } fold: { - 1truc + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; truc + 1 >= 0; i3 = 0 mod 1; truc = 0 mod 1; } widening: { i3 = 0 mod 1; i1 = 0 mod 1; } widening thr: { i3 = 0 mod 1; i1 = 0 mod 1; } Product Polka (strict) * PPL grids ================================== library: Reduced product of polka, strict mode, PPL::Grid version: 3.0 with NUMINT_MPZ, 0.9 level 1 construct top: { i3 = 0 mod 1; i1 = 0 mod 1; } construct bottom: bottom construct box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } construct box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } construct lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } construct tcons: { i1 - 1i3 - 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } construct copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } construct copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } assign top: { i3 = 0 mod 1; i1 = 0 mod 1; } assign bottom: bottom assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 2f2 + 3 >= 0; - 5f3 + 8 >= 0; 2f3 - 1 >= 0; 2f2 + 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } assign tcons: { i1 - 1i3 - 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } assign top: { i3 = 0 mod 1; i1 = 0 mod 1; } assign top: { i3 = 0 mod 1; i1 = 0 mod 1; } assign bottom: bottom assign bottom: bottom assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 2f2 + 3 >= 0; - 5f3 + 8 >= 0; 2f3 - 1 >= 0; 2f2 + 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign box: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } assign tcons { i1 - 1i3 - 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign copy: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } unchanged: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } minimize: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } canonicalize: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } approximate: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } closure: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 >= 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } print: reduced product of library Reduced product of polka, strict mode, PPL::Grid polyhedron of dim (2,3) array of constraints of size 3 0: 5i1 + 4i3 + 3f1 + f3 + 3 = 0 1: -i1 - i3 - 20 >= 0 2: i1 + 2i3 + 3f1 + 4f2 + 1 > 0 array of constraints of size 4 0: 5i1 + 4i3 + 3f1 + f3 + 3 = 0 1: i3 - 11f1 + 3f2 + 2 = 0 mod 5 2: 5i3 = 0 mod 5 3: 5i1 = 0 mod 5 printdiff: reduced product of library Reduced product of polka, strict mode, PPL::Grid not implemented apron::printdiff(manager&, const abstract1&, const abstract1&, FILE*) : PPL::Grid: dump: abstract value of level 1: environment: dim = (2,3), count = 19 0: i1 1: i3 2: f1 3: f2 4: f3 reduced product of library Reduced product of polka, strict mode, PPL::Grid polyhedron of dim (2,3) Constraints: 5 8 0 3 0 5 4 3 0 1 1 -20 0 -1 -1 0 0 0 1 0 1 0 0 0 0 0 1 1 -1 0 0 0 0 0 1 1 -1 1 2 3 4 0 Frames: 6 8 0 0 0 -3 3 -1 0 6 0 0 0 6 -6 -2 3 0 1 0 0 -3 3 1 0 0 1 0 0 1 -2 1 0 0 1 2 2 37 -77 39 0 0 1 3 0 57 -117 58 0 0 satC: 6 1 0000,0000 0000,0000 0000,0000 0000,0000 0000,0000 0000,0000 0000,0000 0000,0000 0000,1000 0000,0000 0000,0000 0000,0000 0100,0000 0000,0000 0000,0000 0000,0000 0010,0000 0000,0000 0000,0000 0000,0000 0001,0000 0000,0000 0000,0000 0000,0000 constraints: array of constraints of size 4 0: 5x0 + 4x1 + 3x2 + x4 + 3 = 0 1: x1 - 11x2 + 3x3 + 2 = 0 mod 5 2: 5x1 = 0 mod 5 3: 5x0 = 0 mod 5 generators: array of generator of size 5 0: VERTEX: -2/3x3 - 3x4 1: LINEMOD: x0 - 5x4 2: LINEMOD: x1 - 1/3x3 - 4x4 3: LINE: 3x2 + 11x3 - 9x4 4: LINEMOD: 5/3x3 serialization not implemented: apron::abstract1::serialize_raw(manager&) : environment: 0: i1 (int) 1: i3 (int) 2: f1 (real) 3: f2 (real) 4: f3 (real) size: 3839 get abstract0: { 5x0 + 4x1 + 3x2 + x4 + 3 = 0; - 1x0 - 1x1 - 20 >= 0; x0 + 2x1 + 3x2 + 4x3 + 1 > 0; 5x0 + 4x1 + 3x2 + x4 + 3 = 0; x1 - 11x2 + 3x3 + 2 = 0 mod 5; 5x1 = 0 mod 5; 5x0 = 0 mod 5; } set abstract0: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 2f2 + 3 >= 0; - 5f3 + 8 >= 0; 2f3 - 1 >= 0; 2f2 + 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } sat lincons: true sat tcons: false sat interval: true unconstrainned: false bound linexpr: [0,+oo] bound texpr: [-oo,+oo] bound variable: [-oo,+oo] to generator: not implemented to lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } to tcons: { 3 + 5 * i1 + 4 * i3 + 3 * f1 + 0 * f2 + 1 * f3 = 0; -20 + -1 * i1 + -1 * i3 + 0 * f1 + 0 * f2 + 0 * f3 >= 0; 1 + 1 * i1 + 2 * i3 + 3 * f1 + 4 * f2 + 0 * f3 > 0; 3 + 5 * i1 + 4 * i3 + 3 * f1 + 0 * f2 + 1 * f3 = 0; 2 + 0 * i1 + 1 * i3 + -11 * f1 + 3 * f2 + 0 * f3 = 0 mod 5; 0 + 0 * i1 + 5 * i3 + 0 * f1 + 0 * f2 + 0 * f3 = 0 mod 5; 0 + 5 * i1 + 0 * i3 + 0 * f1 + 0 * f2 + 0 * f3 = 0 mod 5; } to box: { [-oo,+oo] [-oo,+oo] [-oo,+oo] [-oo,+oo] [-oo,+oo] } meet: bottom meet array: bottom meet lincons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 - 1i3 - 1 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } meet tcons: { 5i1 + 4i3 + 3f1 + f3 + 3 = 0; - 1i1 - 1i3 - 20 >= 0; i1 - 1i3 - 1 >= 0; i1 + 2i3 + 3f1 + 4f2 + 1 > 0; 5i1 + 4i3 + 3f1 + f3 + 3 = 0; i3 - 11f1 + 3f2 + 2 = 0 mod 5; 5i3 = 0 mod 5; 5i1 = 0 mod 5; } join: { i3 = 0 mod 1; i1 = 0 mod 1; } join array: { i3 = 0 mod 1; i1 = 0 mod 1; } add rays: { - 8i1 + 2f2 + 7 >= 0; - 8f1 + 6f2 + 141 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } unify: { - 1i1 + 1 >= 0; - 1i3 + 18 >= 0; - 2f1 + 3 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 - 1 >= 0; 2f2 - 1 >= 0; 2f1 + 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i2 = 0 mod 1; i1 = 0 mod 1; } assign linexpr: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + i3 + 21 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign linexpr inter: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + i3 + 21 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign linexprs: { i1 + i3 + f1 + 20 = 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; 5i1 + 4i3 - 1f2 + f3 + 44 >= 0; i1 + i3 + f1 + 20 = 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign linexprs inter: { i1 + i3 + f1 + 20 = 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + 1 >= 0; 5i1 + 4i3 - 1f2 + f3 + 44 >= 0; i1 + i3 + f1 + 20 = 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign texpr: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign texpr inter: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign texprs: { - 1i1 + 1 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; f2 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } assign texprs inter: { - 1i1 + 1 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; f2 >= 0; i1 - 1i3 - 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } subst linexpr: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + i3 + 21 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } subst linexpr inter: { - 1i1 - 1i3 - 19 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + i3 + 21 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } subst linexprs: { - 25i1 - 20i3 - 15f1 - 5f3 + 58 >= 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; i1 + i3 + 38 >= 0; 10i1 + 8i3 + 6f1 + 2f3 - 21 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } subst linexprs inter: { - 25i1 - 20i3 - 15f1 - 5f3 + 58 >= 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + 1 >= 0; i1 + i3 + 38 >= 0; 10i1 + 8i3 + 6f1 + 2f3 - 21 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } subst texpr: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } subst texpr inter: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 - 1i3 - 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } subst texprs: { - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } subst texprs inter: { - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 - 1i3 - 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } forget: { - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } forget 0: { i1 = 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i3 = 0 mod 1; i1 = 0; } forgets: { - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } forgets 0: { f2 = 0; f1 = 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; f2 = 0; f1 = 0; i3 = 0 mod 1; i1 = 0 mod 1; } forgets: { - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i1 = 0 mod 1; } forgets 0: { f2 = 0; f1 = 0; - 1i1 + 1 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; i1 + 1 >= 0; f2 = 0; f1 = 0; i3 = 0 mod 1; i1 = 0 mod 1; } change env: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i2 = 0 mod 1; i1 = 0 mod 1; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) change env 0: { i2 = 0; - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i2 = 0; i1 = 0 mod 1; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) minimize env: { - 1i1 + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; i1 + 1 >= 0; i3 = 0 mod 1; i2 = 0 mod 1; i1 = 0 mod 1; } 0: i1 (int) 1: i2 (int) 2: i3 (int) 3: f1 (real) 4: f2 (real) 5: f3 (real) rename: { - 1truc + 1 >= 0; - 5f0 + 8 >= 0; - 1f1 + 18 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f0 - 1 >= 0; truc + 1 >= 0; i3 = 0 mod 1; truc = 0 mod 1; } expand: { - 1f0 + 1 >= 0; - 1i1 + 1 >= 0; - 1truc + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; truc + 1 >= 0; i1 + 1 >= 0; f0 + 1 >= 0; truc = 0 mod 1; i3 = 0 mod 1; i1 = 0 mod 1; f0 = 0 mod 1; } fold: { - 1truc + 1 >= 0; - 1f1 + 18 >= 0; - 5f2 + 8 >= 0; - 2f3 + 3 >= 0; 2f3 + 1 >= 0; 2f2 - 1 >= 0; truc + 1 >= 0; i3 = 0 mod 1; truc = 0 mod 1; } widening: { i3 = 0 mod 1; i1 = 0 mod 1; } widening thr: { i3 = 0 mod 1; i1 = 0 mod 1; } apron-dist-0.9.10/apron/apronxx/apxx_interval.hh0000640014525101416610000002374311006063143021573 0ustar bjeannetpopart/* -*- C++ -*- * apxx_interval.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_INTERVAL_HH #define __APXX_INTERVAL_HH #include #include "ap_interval.h" #include "apxx_scalar.hh" namespace apron { //! Full interval (]-oo,+oo[) or domain, to simplify initialisations and assignments. struct top { top() {} }; //! Empty interval or domain, to simplify initialisations and assignments. struct bottom { bottom() {} }; /* ================================= */ /* interval */ /* ================================= */ /*! \brief Interval (ap_interval_t wrapper). * * An interval is represented using two scalar bounds (of double or MPQ type). */ class interval : public use_malloc { protected: ap_interval_t c; //!< Structure managed by APRON. //! Internal initialisation. void init(); //! Internal use only. Take ownership of an object created by ap_interval_alloc. interval(ap_interval_t* i); friend class abstract0; friend class abstract1; friend class linexpr0; friend class texpr0; public: //! Returned by ordering functions. enum order { INCLUDED = -1, //!< Means i1 is included in i2 EQUAL = 0, //!< Means i1 equals i2 CONTAINS = 1, //!< Means i2 is included in i1 LESS = -2, //!< Means min i1 <= min i2 GREATER = 2, //!< Means min i1 >= min i2 }; /* constructors */ /* ============ */ /** @name Constructors */ //@{ //! Makes a new interval [0,0] with double bounds. interval(); //! Makes a copy of an interval (bounds are copied). interval(const interval& x); //! Makes a new interval with the specified scalar bounds (copied). interval(const scalar& inf, const scalar& sup); //! Makes a new interval with the specified integer bounds, using MPQ scalars. interval(int inf, int sup); //! Makes a new interval with the specified integer bounds, using MPQ scalars. interval(long inf, long sup); //! Makes a new interval with the specified double bounds, using double scalars. interval(double inf, double sup); //! Makes a new interval with the specified fraction bounds, using MPQ scalars. interval(const frac& inf, const frac& sup); //! Makes a new interval with the specified MPQ bounds (copied), using MPQ scalars. interval(const mpq_class& inf, const mpq_class& sup); //! Makes a new interval with the specified MPFR bounds (copied), using MPFR scalars. interval(mpfr_t inf, mpfr_t sup); //! Makes a new interval representing ]-oo,+oo[. interval(top t); //! Makes a new empty interval [+1;-1]. interval(bottom t); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ ~interval(); //@} /* assignments */ /* =========== */ /** @name Assignments */ //@{ /* = */ //! Copies an interval into *this interval& operator= (const interval& x); //! Sets *this to top (]-oo;+oo[), no change in scalar types. interval& operator= (top t); //! Sets *this to empty ([+1;-1]), no change in scalar types. interval& operator= (bottom t); /* set */ //! Copies an interval into *this. \return *this. interval& set(const interval& x); //! Sets *this to [inf;sup], copying both scalar bounds. \return *this. interval& set(const scalar& inf, const scalar& sup); //! Sets *this to [inf;sup], using MPQ scalar bounds. \return *this. interval& set(int inf, int sup); //! Sets *this to [inf;sup], using MPQ scalar bounds. \return *this. interval& set(long inf, long sup); //! Sets *this to [inf;sup], using double scalar bounds. \return *this. interval& set(double inf, double sup); //! Sets *this to [inf;sup], using MPQ scalar bounds. \return *this. interval& set(const frac& inf, const frac& sup); //! Sets *this to [inf;sup], using MPQ scalar bounds (copied). \return *this. interval& set(const mpq_class& inf, const mpq_class& sup); //! Sets *this to [inf;sup], using MPFR scalar bounds (copied). \return *this. interval& set(mpfr_t inf, mpfr_t sup); //! Sets *this to top (]-oo;+oo[). \return *this. interval& set(top t); //! Sets *this to empty ([+1;-1]). \return *this. interval& set(bottom t); /* swap */ //! Swaps the contents of two intervals. friend void swap(interval& a, interval &b); //@} /* access */ /* ====== */ /** @name Accesses */ //@{ //! Gets a (modifiable) reference to the lower bound. scalar& get_inf(); //! Gets a (modifiable) reference to the upper bound. scalar& get_sup(); //! Gets a reference to the lower bound. const scalar& get_inf() const; //! Gets a reference to the upper bound. const scalar& get_sup() const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ //! Printing. friend std::ostream& operator<< (std::ostream& os, const interval& s); //! Prints to a C stream. void print(FILE* stream=stdout) const; //@} /* tests */ /* ===== */ /** @name Tests */ //@{ //! Whether *this equals ]-oo;+oo[. bool is_top() const; //! Whether *this represents an empty interval. bool is_bottom() const; //! Set inclusion. friend bool operator<= (const interval&a, const interval &b); //! Set inclusion. friend bool operator>= (const interval&a, const interval &b); //! Strict set inclusion. friend bool operator< (const interval&a, const interval &b); //! Strict set inclusion. friend bool operator> (const interval&a, const interval &b); //! Set equality. friend bool operator== (const interval&a, const interval &b); //! Set disequality. friend bool operator!= (const interval&a, const interval &b); //! Interval ordering. friend order cmp (const interval&a, const interval &b); //@} /* other operators */ /* =============== */ /** @name Operators */ //@{ //! Negates *this. void neg(); //! Returns a new interval which is the opposite of *this. interval operator- () const; //! Returns a hash code. long hash() const; //@} /* C API compatibility */ /* =================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. const ap_interval_t* get_ap_interval_t() const; //! Returns a pointer to the internal APRON object stored in *this. ap_interval_t* get_ap_interval_t(); //@} }; /* ================================= */ /* interval_array */ /* ================================= */ /*! \brief array of interval(s). */ class interval_array : public use_malloc { protected: size_t sz; //!< Array size. ap_interval_t** c; //!< Array of pointers to intervals. //! Internal use only. Reference an array created with ap_interval_array_alloc. interval_array(size_t size, ap_interval_t** c); friend class abstract0; friend class abstract1; public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ /*! \brief Creates a new interval array. * * All elements are initially [0;0] intervals with double scalar bounds. */ interval_array(size_t size); //! Makes a copy of an interval array (copying all elements). interval_array(const interval_array &x); //! Makes a interval array from an interval vector (copying all elements). interval_array(const std::vector& x); //! Makes a interval array from an interval array of give size (copying all elements). interval_array(size_t size, const interval x[]); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ //! Frees the space occupied by the array and all its elements. ~interval_array(); //@} /* assignment */ /* ========== */ /** @name Assignments */ //@{ /*! \brief Copies an interval array into *this. * * All elements are copied and the array size is updated if necessary. */ interval_array& operator= (const interval_array &x); /*! \brief Copies an interval vector into *this. * * All elements are copied and the array size is updated if necessary. */ interval_array& operator= (const std::vector& x); /*! \brief Copies an interval array into *this. * * The size of the interval_array is not changed. * \c x should have enough elements to fill the interval_array. */ interval_array& operator= (const interval x[]); //@} /* conversion */ /* ========== */ /** @name Conversion */ //@{ //! \brief Makes an interval vector from an interval array (copying all elements). operator std::vector() const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ //! Printing. friend std::ostream& operator<< (std::ostream& os, const interval_array& s); //! Prints to a C stream. void print(FILE* stream=stdout) const; //@} /* access */ /* ====== */ /** @name Accesses */ //@{ //! Returns the array size. size_t size() const; //! Returns a pointer to the start of the array of elements used internally. interval** contents(); //! Returns a (modifiable) reference to an element, no bound checking. interval& operator[](size_t i); //! Returns a reference to an element, no bound checking. const interval& operator[](size_t i) const; /*! Returns a (modifiable) reference to an element (bound-checked). * * \throw std::out_of_range if the index is invalid. */ interval& get(size_t i); /*! Returns a reference to an element (bound-checked). * * \throw std::out_of_range if the index is invalid. */ const interval& get(size_t i) const; //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. const ap_interval_t * const * get_ap_interval_t_array() const; //! Returns a pointer to the internal APRON object stored in *this. ap_interval_t** get_ap_interval_t_array(); //@} }; #include "apxx_interval_inline.hh" } #endif /* __APXX_INTERVAL_HH */ apron-dist-0.9.10/apron/apronxx/apxx_linexpr0.hh0000640014525101416610000002721710703144237021517 0ustar bjeannetpopart/* -*- C++ -*- * apxx_linexpr0.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_LINEXPR0_HH #define __APXX_LINEXPR0_HH #include "ap_linexpr0.h" #include "ap_linearize.h" #include "apxx_coeff.hh" #include "apxx_dimension.hh" namespace apron { /* ================================= */ /* linexpr0 */ /* ================================= */ /*! \brief Level 0 linear expression (ap_linexpr0_t wrapper). * * A linexpr0 object represents a linear expression with scalar or interval coefficients (coeff). * They have a constant coefficient, plus a coefficient for each represented dimension. * An expression can be either sparse (\c AP_LINEXPR_SPARSE) or dense (\c AP_LINEXPR_DENSE). * Dense expressions use an array of coefficients to represent dimensions from 0 up to the * expression size. * Sparse expressions can have 'holes' between coefficients and grow automatically when * a coefficient for a non-existing dimension is accessed. */ class linexpr0 : public use_malloc { protected: ap_linexpr0_t l; //!< Structure managed by APRON. //! Internal use only. Shallow copy of structure followed by a free to take ownership of expression. linexpr0(ap_linexpr0_t* p); friend class texpr0_tmp; friend class texpr0; public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ /*! \brief Creates a new expression. * * \arg \c discr whether the expression is sparse (\c AP_LINEXPR_SPARSE) or dense (\c AP_LINEXPR_DENSE). * \arg \c size is the initial number of dimensions. */ linexpr0(ap_linexpr_discr_t discr=AP_LINEXPR_SPARSE, size_t size=0); //! Makes a (deep) copy. linexpr0(const linexpr0& x); //! Makes a (deep) copy, and adds some dimensions (shifting coefficients if needed). linexpr0(const linexpr0& x, const dimchange& d); //! Makes a (deep) copy, and applies a permutation on coefficients. linexpr0(const linexpr0& x, const dimperm& d); /*! \brief Makes a new linear expression with the given size and coefficients (copied). * * \arg \c discr whether the expression is sparse (\c AP_LINEXPR_SPARSE) or dense (\c AP_LINEXPR_DENSE). * \arg \c coeffs has size size, coeffs[i] corresponds to the coefficient for dimension i. * \arg \c cst corresponds to the constant coefficient. */ linexpr0(size_t size, const coeff coeffs[], const coeff& cst, ap_linexpr_discr_t discr=AP_LINEXPR_SPARSE); /*! \brief Makes a new linear expression with the given coefficients (copied). * * \arg \c discr whether the expression is sparse (\c AP_LINEXPR_SPARSE) or dense (\c AP_LINEXPR_DENSE). * \arg \c coeffs vector of coefficients, coeffs[i] corresponds to the coefficient for dimension i. * \arg \c cst corresponds to the constant coefficient. */ linexpr0(const std::vector& coeffs, const coeff& cst, ap_linexpr_discr_t discr=AP_LINEXPR_SPARSE); /*! \brief Makes a new linear expression with the given size and coefficients (copied). * * The expression is always sparse. * \arg \c coeffs has size size, coeffs[i] corresponds to the coefficient for dimension dims[i]; * \arg \c dims is a list of size dimensions (sorted in increasing order) * \arg \c cst corresponds to the constant coefficient. */ linexpr0(size_t size, const coeff coeffs[], const ap_dim_t dims[], const coeff& cst); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ //! Frees all space for the expression and coefficients. ~linexpr0(); //@} /* assignment */ /* ========== */ /** @name Assignment */ //@{ //! Makes a (deep) copy. linexpr0& operator= (const linexpr0& x); //@} /* dimension operations */ /* ==================== */ /** @name Dimension operations */ //@{ //! Changes the number of coefficients in the expression. (Useful only for dense expressions.) void resize(size_t size); //! Adds some dimensions, shifting coefficients if needed. void add_dimensions(const dimchange& d); //! Applies a permutation on coefficients. void permute_dimensions(const dimperm& d); //@} /* access */ /* ====== */ /** @name Accesses, size */ //@{ /* size */ //! Returns the number of coefficients in the expression. size_t size() const; /* get */ /*! \brief Returns the expression type. * * \return Either \c AP_LINEXPR_SPARSE or \c AP_LINEXPR_DENSE. */ ap_linexpr_discr_t get_discr() const; //! Returns a (modifiable) reference to the constant coefficient. coeff& get_cst(); //! Returns a reference to the constant coefficient. const coeff& get_cst() const; /*! \brief Returns a (modifiable) reference to the coefficient corresponding to the given dimension. * * Always succeeds if the expression is sparse: if the dimension has no coefficient yet, it is * created and returned (linear time in the worst case). * \throw std::out_of_range if the expression is dense and the dimension exceeds the size * of the expression. * \warning as a side-effect, the method renders previous references to coefficients within the * same expression invalid. For instance, \code l.get_coeff(0) = l.get_coeff(1) = 0; \endcode is invalid. */ coeff& operator[](ap_dim_t dim); //! \brief Returns a reference to the coefficient corresponding to the given dimension. const coeff& operator[](ap_dim_t dim) const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ /*! \brief Printing. * * Variable naming can be configured through the varname stream modifier. */ friend std::ostream& operator<< (std::ostream& os, const linexpr0& s); //! Prints to a C stream. void print(char** name_of_dim = NULL, FILE* stream=stdout) const; //@} /* tests */ /* ===== */ /** @name Tests */ //@{ //! Whether only dimensions greater than \c intdim have a non-zero coefficient. bool is_integer(size_t intdim) const; //! Whether only dimensions strictly smaller than \c intdim have a non-zero coefficient. bool is_real(size_t intdim) const; /*! \brief Gets the type of the linear expression. * * \return Either \c AP_LINEXPR_INTLINEAR (coefficients are interval), * \c AP_LINEXPR_QUASILINEAR (coefficients are scalar except the constant one), or * \c AP_LINEXPR_LINEAR (all coefficients are scalar). */ ap_linexpr_type_t get_type() const; //! Whether all coefficients are scalar. bool is_linear() const; //! Whether all coefficients are scalar, except maybe the constant one. bool is_quasilinear() const; //! Lexicography ordering, terminating with constant coefficients. friend int compare(const linexpr0& x, const linexpr0& y); //! Structural, syntactical equality. friend bool equal(const linexpr0& x, const linexpr0& y); #if 0 // overloaded to make constraints //! Whether compare(x,y)>=0. friend bool operator>= (const linexpr0& x, const linexpr0& y); //! Whether compare(x,y)<=0. friend bool operator<= (const linexpr0& x, const linexpr0& y); //! Whether compare(x,y)>0. friend bool operator> (const linexpr0& x, const linexpr0& y); //! Whether compare(x,y)<0. friend bool operator< (const linexpr0& x, const linexpr0& y); //! Whether both expressions have (dimension-wise) equal coefficients. friend bool operator== (const linexpr0& x, const linexpr0& y); //! Whether some coefficients are different. friend bool operator!= (const linexpr0& x, const linexpr0& y); #endif //@} /* iterators */ /* ========= */ /** @name Iterator */ //@{ /*! \brief Iterator to traverse a constant linexpr0. * * At each position, there is dimension and its corresponding coefficients. * For sparse expressions, there can be a gap between the dimension at two successive position * (holes are skipped.) * In all cases, the expression is traversed in increasing dimension order. * * To mutate a linear expression, use the iterator class instead. * * Sample code: * \code for (linexpr0::const_iterator i = m.begin();i.valid();++i) cout << i.get_coeff() << " "; \endcode */ class const_iterator { /* TODO: - reverse traversal (operator--). */ protected: ap_linexpr0_t* l; //!< Internal use only. Pointer to the underlying APRON structure. ap_dim_t pos; //!< Internal use only. Current index. //! Internal use only. Skips free coefficients in sparse expressions. void skip_AP_DIM_MAX(); //! Internal use only. const_iterator(ap_linexpr0_t* l); friend class linexpr0; public: //! Starts a new iterator to traverse the linear expression. const_iterator(const linexpr0& e); //! Duplicates the iterator. const_iterator(const const_iterator& i); //! Assigns the iterator. const_iterator& operator=(const const_iterator& i); /*! \brief Returns the dimension of the coefficient at the current iterator position. * * \throw std::out_of_range if valid() returns false (we are past the last position). */ ap_dim_t get_dim() const; /*! \brief Returns a reference to the coefficient at the current iterator position. * * \throw std::out_of_range if valid() returns false (we are past the last position). */ const coeff& get_coeff() const; //! Moves the iterator to the following position. void next(); /*! \brief Moves the iterator to the following position. * * (Identical to next()). */ void operator++(); //! Whether we are at a valid position (true) or past the last iterator position (false). bool valid() const; }; /*! \brief Iterator to traverse and mutate a linear expression. * * As const_iterator, but for non-constant linexpr0. * * Caution: do not modify the expression during traversal, except through the iterator. * * Sample code: * \code for (linexpr0::iterator i = m.begin();i.valid();++i) i.get_coeff().neg(); \endcode */ class iterator : public const_iterator { /* TODO: - removing/inserting coefficients at iterator position for sparse expressions. */ protected: //! Internal use only. iterator(ap_linexpr0_t* l); friend class linexpr0; public: //! Starts a new iterator to traverse the linear expression. iterator(linexpr0& e); //! Duplicates the iterator. iterator(const iterator& i); //! Assigns the iterator. iterator& operator=(const iterator& i); /*! \brief Returns a (modifiable) reference to the coefficient at the current iterator position. * * \throw std::out_of_range if valid() returns false (we are past the last position). */ coeff& get_coeff() const; }; //! Returns a new iterator to traverse and mutate the linear expression. iterator begin(); //! Returns a new constant iterator to traverse the linear expression. const_iterator begin() const; //@} /* other operators */ /* =============== */ /** @name Operators */ //@{ /*! \brief Minimizes all coefficients. * * In sparse expressions, also remove zero and unused (hole) coefficients to save space. */ void minimize(); //! Returns a hash-code. long hash() const; //@} /* TODO: evaluation, linearization, intelligent constructors */ /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. const ap_linexpr0_t* get_ap_linexpr0_t() const; //! Returns a pointer to the internal APRON object stored in *this. ap_linexpr0_t* get_ap_linexpr0_t(); //@} }; #include "apxx_linexpr0_inline.hh" } #endif /* __APXX_LINEXPR0_HH */ apron-dist-0.9.10/apron/apronxx/apxx_environment.hh0000640014525101416610000003003710703144237022314 0ustar bjeannetpopart/* -*- C++ -*- * apxx_environment.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_ENVIRONMENT_HH #define __APXX_ENVIRONMENT_HH #include #include #include "ap_environment.h" #include "apxx_dimension.hh" #include "apxx_var.hh" namespace apron { /* ================================= */ /* environment */ /* ================================= */ /*! \brief Level 1 environment (ap_environment_t wrapper). * * An environment associates dimensions to integer and real variable names (var). * It stores a number intdim of integer dimensions, a number realdim of real dimensions, and * an array of size intdim+realdim variable names indexed by dimensions. * Dimensions 0 to intdim-1 are associated to integer variables while dimensions intdim to intdim+realdim-1 * are associated to real variables. * Variables in both slices [0;intdim-1] and [intdim;intdim+realdim-1] are always sorted in * strictly increasing order. * (Recall that variables have the following user-specified functions: copy, deallocation, comparison, conversion to string.) * This invariant is automatically enforced by the library by performing dimension permutations after * variable name addition, deletion, or renaming. Thus, such an operation can change the dimension associated to existing * variable names. * * Environments are reference-counted and the API is fully functional (i.e., functions do not change *this but return * a new object instead). */ class environment : public use_malloc { protected: ap_environment_t* e; //! Used internally only. Wraps the APRON object in an environment object (no copy, no change in reference counter). environment(ap_environment_t* x) : e(x) {} friend class linexpr1; friend class lincons1; friend class lincons1_array; friend class generator1; friend class generator1_array; friend class texpr1; friend class tcons1; friend class tcons1_array; friend class abstract1; public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ //! Creates a new empty environment. environment(); /*! \brief Creates a new environment with given integer and real variable names (copied). * * \throw std::invalid_argument if variable names are not distinct. */ environment(const std::vector& intdim, const std::vector& realdim); /*! \brief Creates a new environment with given integer and real variable names (copied). * * \throw std::invalid_argument if variable names are not distinct. */ environment(const var* intdim, size_t intdim_size, const var* realdim, size_t realdim_size); //! Creates a copy (i.e., increments the reference counter). environment(const environment& x); //@} /** @name Destructor */ //@{ //! Decrements the reference counter and, if null, actually frees the environment. ~environment(); //@} /* assignment */ /* ========== */ /** @name Assignment */ //@{ //! Assignment (reference counter manipulation). const environment& operator=(const environment& x); //@} /* operations */ /* ========== */ /** @name Operations */ //@{ /*! \brief Returns a copy of the environment with some integer and/or real variable names added. * * \throw std::invalid_argument if the resulting environment has duplicate variable names. */ environment add(const std::vector& intdim, const std::vector& realdim) const; /*! \brief Returns a copy of the environment with intdim_size integer and realdim_size real variable names added. * * \throw std::invalid_argument if the resulting environment has duplicate variable names. */ environment add(const var* intdim, size_t intdim_size, const var* realdim, size_t realdim_size) const; /*! \brief Returns a copy of the environment with some integer and/or real variable names added. * * Sets perm to the dimension permutation that has been performed after appending variable names at the end of * integer (resp. real) dimensions to get them sorted again. * * \throw std::invalid_argument if the resulting environment has duplicate variable names. */ environment add(const std::vector& intdim, const std::vector& realdim, dimperm& perm) const; /*! \brief Returns a copy of the environment with intdim_size integer and realdim_size real variable names added. * * Sets perm to the dimension permutation that has been performed after appending variable names at the end of * integer (resp. real) dimensions to get them sorted again. * * \throw std::invalid_argument if the resulting environment has duplicate variable names. */ environment add(const var* intdim, size_t intdim_size, const var* realdim, size_t realdim_size, dimperm& perm) const; /*! \brief Returns a copy of the environment with some variable names removed. * * \throw std::invalid_argument if some variable name does not exist. */ environment remove(const std::vector& dims) const; /*! \brief Returns a copy of the environment with dims_size variable names removed. * * \throw std::invalid_argument if some variable name does not exist. */ environment remove(const var* dims, size_t dims_size) const; /*! \brief Returns a copy of the environment with some variable names substituted. * * dims[i].first is replaced with dims[i].second. * * \throw std::invalid_argument if some variable name does not exist. */ environment rename(const std::vector >& dims) const; /*! \brief Returns a copy of the environment with dims_size variable names substituted. * * before[i] is replaced with after[i]. Both array should contain dims_size elements. * * \throw std::invalid_argument if some variable name does not exist. */ environment rename(const var* before, const var* after, size_t dims_size) const; /*! \brief Returns a copy of the environment with some variable names substituted. * * dims[i].first is replaced with dims[i].second. * Sets perm to the dimension permutation that has been performed after renaming the variable names in-place to get them * sorted again. * * \throw std::invalid_argument if some variable name does not exist. */ environment rename(const std::vector >& dims, dimperm& perm) const; /*! \brief Returns a copy of the environment with dims_size variable names substituted. * * before[i] is replaced with after[i]. Both array should contain dims_size elements. * Sets perm to the dimension permutation that has been performed after renaming the variable names in-place to get them * sorted again. * * \throw std::invalid_argument if some variable name does not exist. */ environment rename(const var* before, const var* after, size_t dims_size, dimperm& perm) const; /*! \brief Returns the least common environment of two environments. * * \throw std::invalid_argument if some variable name has different type in both environments */ friend environment lce(const environment& x, const environment& y); /*! \brief Returns the least common environment of two environments. * * Sets chgx (resp. chgy) to the dimension transformation that has been performed after appending the required * variable names to x (resp. y) to keep them sorted. * * \throw std::invalid_argument if some variable name has different type in both environments */ friend environment lce(const environment& x, const environment& y, dimchange& chgx, dimchange& chgy); /*! \brief Returns the least common environment of a vector of environments. * * \throw std::invalid_argument if some variable name has different type in different environments */ friend environment lce(const std::vector& x); /*! \brief Returns the least common environment of an array env of env_size environments. * * \throw std::invalid_argument if some variable name has different type in different environments */ friend environment lce(const environment* env, size_t env_size); /*! \brief Returns the least common environment of a vector of environments. * * Sets chg[i] to the dimension transformation that has been performed after appending the required variable names * to x[i] to keep them sorted. * chg must have space for at least env_size elements. * * \throw std::invalid_argument if some variable name has different type in different environments */ friend environment lce(const std::vector& x, std::vector& chg); /*! \brief Returns the least common environment of an array env of env_size environments. * * Sets chg[i] to the dimension transformation that has been performed after appending the required variable names * to x[i] to keep them sorted. * chg must have space for at least env_size elements. * * \throw std::invalid_argument if some variable name has different type in different environments */ friend environment lce(const environment* env, dimchange* chg, size_t env_size); /*! \brief Returns the dimension change to transform an environment x into a super-environment y. * * \throw std::invalid_argument if x is not a subset of y, or if x and chg have different size. */ friend dimchange get_dimchange(const environment& x, const environment& y); //@} /* access */ /* ====== */ /** @name Accesses */ //@{ //! Returns the number of integer dimensions in the environment. size_t intdim() const; //! Returns the number of real dimensions in the environment. size_t realdim() const; //! Whether the environment contains the variable name x. bool contains(const var& x) const; /*! \brief Returns the dimension associated with the variable name. * * \throw std::invalid_argument if there is no such variable name in the environment. */ ap_dim_t operator[] (const var& x) const; //! \brief Returns the variable name at a given dimension (no bound-check). const var& operator[] (ap_dim_t d) const; /*! \brief Returns the dimension associated with a variable name. * * \throw std::invalid_argument if there is no such variable name in the environment. */ ap_dim_t get_dim(const var& x) const; /*! \brief Returns the variable name at a given dimension (bound-checked). * * \throw std::out_of_range if the dimension is larger than the environment size. */ const var& get_var(ap_dim_t d) const; //! Returns (a copy of) the full map from dimensions to variable names. std::vector get_vars() const; //@} /* Tests */ /* ===== */ /** @name Tests */ //@{ //! Equality testing. friend bool operator==(const environment& x, const environment& y); //! Disequality testing. friend bool operator!=(const environment& x, const environment& y); //! Inclusion testing. friend bool operator<=(const environment& x, const environment& y); //! Inclusion testing. friend bool operator>=(const environment& x, const environment& y); /*! \brief Environment comparison. * * \return * - -2 if some variable name has different type in both environments * - -1 if x is a sub-environment of y * - 0 if x equals y * - +1 if x is a super-environment of y * - +2 if x and y a not comparable but there exists a lowest upper bound */ friend int cmp(const environment& x, const environment& y); //@} /* print */ /* ===== */ /** @name Printing */ //@{ //! Printing. friend std::ostream& operator<< (std::ostream& os, const environment& s); //! Prints to a C stream. void print(FILE* stream=stdout) const; //@} /* C API compatibility */ /* =================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object pointed by *this. const ap_environment_t* get_ap_environment_t() const; //! Returns a pointer to the internal APRON object pointed by *this. ap_environment_t* get_ap_environment_t(); //@} }; #include "apxx_environment_inline.hh" } #endif /* __APXX_ENVIRONMENT_HH */ apron-dist-0.9.10/apron/apronxx/apxx_environment_inline.hh0000640014525101416610000003347310703144237023661 0ustar bjeannetpopart/* -*- C++ -*- * apxx_environment_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ // shallow copy (does not call ap_var_operations->copy) static inline ap_var_t* apxx_environment_get_names(const std::vector& n) { ap_var_t* r = (ap_var_t*)malloc(sizeof(ap_var_t)*n.size()); assert(r); for (size_t i=0; icopy) static inline void apxx_environment_get_names_pair(const std::vector >& n, ap_var_t** x, ap_var_t** y) { *x = (ap_var_t*)malloc(sizeof(ap_var_t)*n.size()); *y = (ap_var_t*)malloc(sizeof(ap_var_t)*n.size()); assert(x && y); for (size_t i=0; i& intdim, const std::vector& realdim) { ap_var_t *i = apxx_environment_get_names(intdim); ap_var_t *r = apxx_environment_get_names(realdim); e = ap_environment_alloc(i, intdim.size(), r, realdim.size()); free(i); free(r); if (!e) throw std::invalid_argument("apron::environment::environment(const vector&, const vector&) incompatible variable types"); } inline environment::environment(const var* intdim, size_t intdim_size, const var* realdim, size_t realdim_size) { e = ap_environment_alloc(const_cast(reinterpret_cast(intdim)), intdim_size, const_cast(reinterpret_cast(realdim)), realdim_size); if (!e) throw std::invalid_argument("apron::environment::environment(const var*, size_t, const var*, size_t) incompatible variable types"); } inline environment::environment(const environment& x) : e(ap_environment_copy(x.e)) { } inline environment::~environment() { ap_environment_free(e); } /* assignment */ /* ========== */ inline const environment& environment::operator=(const environment& x) { ap_environment_t* ee = ap_environment_copy(x.e); ap_environment_free(e); e = ee; return *this; } /* operations */ /* ========== */ inline environment environment::add(const std::vector& intdim, const std::vector& realdim) const { ap_var_t *i = apxx_environment_get_names(intdim); ap_var_t *r = apxx_environment_get_names(realdim); ap_environment_t* ee = ap_environment_add(e, i, intdim.size(), r, realdim.size()); free(i); free(r); if (!ee) throw std::invalid_argument("apron::environment::add(const vector&, const vector&) incompatible variable types"); return ee; } inline environment environment::add(const var* intdim, size_t intdim_size, const var* realdim, size_t realdim_size) const { ap_environment_t* ee = ap_environment_add(e, const_cast(reinterpret_cast(intdim)), intdim_size, const_cast(reinterpret_cast(realdim)), realdim_size); if (!ee) throw std::invalid_argument("apron::environment::add(const var*, size_t, const var*, size_t) incompatible variable types"); return ee; } inline environment environment::add(const std::vector& intdim, const std::vector& realdim, dimperm& perm) const { ap_var_t *i = apxx_environment_get_names(intdim); ap_var_t *r = apxx_environment_get_names(realdim); ap_dimperm_t p; ap_environment_t* ee = ap_environment_add_perm(e, i, intdim.size(), r, realdim.size(), &p); free(i); free(r); if (!ee) throw std::invalid_argument("apron::environment::add(const vector&, const vector&, dimperm& perm) incompatible variable types"); ap_dimperm_clear(perm.get_ap_dimperm_t()); *perm.get_ap_dimperm_t() = p; return ee; } inline environment environment::add(const var* intdim, size_t intdim_size, const var* realdim, size_t realdim_size, dimperm& perm) const { ap_dimperm_t p; ap_environment_t* ee = ap_environment_add_perm(e, const_cast(reinterpret_cast(intdim)), intdim_size, const_cast(reinterpret_cast(realdim)), realdim_size, &p); if (!ee) throw std::invalid_argument("apron::environment::add(const var*, size_t, const var*, size_t, dimperm&) incompatible variable types"); ap_dimperm_clear(perm.get_ap_dimperm_t()); *perm.get_ap_dimperm_t() = p; return ee; } inline environment environment::remove(const std::vector& dims) const { ap_var_t *d = apxx_environment_get_names(dims); ap_environment_t* ee = ap_environment_remove(e, d, dims.size()); free(d); if (!ee) throw std::invalid_argument("apron::environment::remove(const vector&) variable not in environment"); return ee; } inline environment environment::remove(const var* dims, size_t dims_size) const { ap_environment_t* ee = ap_environment_remove(e, const_cast(reinterpret_cast(dims)), dims_size); if (!ee) throw std::invalid_argument("apron::environment::remove(const var*, size_t) variable not in environment"); return ee; } inline environment environment::rename(const std::vector >& dims) const { ap_var_t *a, *b; ap_dimperm_t p; apxx_environment_get_names_pair(dims, &a, &b); ap_environment_t* ee = ap_environment_rename(e, a, b, dims.size(), &p); free(a); free(b); if (!ee) throw std::invalid_argument("apron::environment::rename(const vector>&) variable mismatch"); ap_dimperm_clear(&p); return ee; } inline environment environment::rename(const var* before, const var* after, size_t dims_size) const { ap_dimperm_t p; ap_environment_t* ee = ap_environment_rename(e, const_cast(reinterpret_cast(before)), const_cast(reinterpret_cast(after)), dims_size, &p); if (!ee) throw std::invalid_argument("apron::environment::rename(const var*, const var*, size_t) variable mismatch"); ap_dimperm_clear(&p); return ee; } inline environment environment::rename(const std::vector >& dims, dimperm& perm) const { ap_var_t *a, *b; ap_dimperm_t p; apxx_environment_get_names_pair(dims, &a, &b); ap_dimperm_clear(perm.get_ap_dimperm_t()); ap_environment_t* ee = ap_environment_rename(e, a, b, dims.size(), &p); free(a); free(b); if (!ee) throw std::invalid_argument("apron::environment::rename(const vector>&, dimperm&) variable mismatch"); ap_dimperm_clear(perm.get_ap_dimperm_t()); *perm.get_ap_dimperm_t() = p; return ee; } inline environment environment::rename(const var* before, const var* after, size_t dims_size, dimperm& perm) const { ap_dimperm_t p; ap_environment_t* ee = ap_environment_rename(e, const_cast(reinterpret_cast(before)), const_cast(reinterpret_cast(after)), dims_size, &p); if (!ee) throw std::invalid_argument("apron::environment::rename(const var*, const var*, size_t, dimperm&) variable mismatch"); ap_dimperm_clear(perm.get_ap_dimperm_t()); *perm.get_ap_dimperm_t() = p; return ee; } inline environment lce(const environment& x, const environment& y) { ap_dimchange_t *a = NULL, *b = NULL; ap_environment_t* ee = ap_environment_lce(x.e, y.e, &a, &b); if (a) ap_dimchange_free(a); if (b) ap_dimchange_free(b); if (!ee) throw std::invalid_argument("apron::environment::lce(const environment&, const environment&) incompatible variable types"); return ee; } inline environment lce(const environment& x, const environment& y, dimchange& chgx, dimchange& chgy) { ap_dimchange_t *a = NULL, *b = NULL; ap_environment_t* ee = ap_environment_lce(x.e, y.e, &a, &b); ap_dimchange_clear(chgx.get_ap_dimchange_t()); ap_dimchange_clear(chgy.get_ap_dimchange_t()); if (a) { *chgx.get_ap_dimchange_t() = *a; free(a); } else { ap_dimchange_init(chgx.get_ap_dimchange_t(), 0, 0); } if (b) { *chgy.get_ap_dimchange_t() = *b; free(b); } else { ap_dimchange_init(chgy.get_ap_dimchange_t(), 0, 0); } if (!ee) throw std::invalid_argument("apron::environment::lce(const environment&, const environment&, dimchange&, dimchange&) incompatible variable types"); return ee; } inline environment lce(const std::vector& x) { ap_environment_t** ar = (ap_environment_t**)malloc(sizeof(ap_environment_t*)*x.size()); ap_dimchange_t** r = NULL; assert(ar); for (size_t i=0; i&) incompatible variable types"); return ee; } inline environment lce(const environment* env, size_t env_size) { ap_dimchange_t** r = NULL; ap_environment_t* ee = ap_environment_lce_array(reinterpret_cast(const_cast(env)), env_size, &r); if (r) { for (size_t i=0; i& x, std::vector& chg) { if (x.size()>chg.size()) throw std::invalid_argument("apron::environment::lce(const vector&, vector&) dimchange vector too short"); ap_environment_t** ar = (ap_environment_t**)malloc(sizeof(ap_environment_t*)*x.size()); ap_dimchange_t** r = NULL; assert(ar); for (size_t i=0; i&, vector&) incompatible variable types"); return ee; } inline environment lce(const environment* env, dimchange* chg, size_t env_size) { ap_dimchange_t** r = NULL; ap_environment_t* ee = ap_environment_lce_array(reinterpret_cast(const_cast(env)), env_size, &r); for (size_t i=0; iintdim; } inline size_t environment::realdim() const { return e->realdim; } inline bool environment::contains(const var& x) const { return ap_environment_mem_var(e, x.get_ap_var_t()); } inline ap_dim_t environment::operator[] (const var& x) const { ap_dim_t d = ap_environment_dim_of_var(e, x.get_ap_var_t()); if (d==AP_DIM_MAX) throw std::invalid_argument("apron::environment::operator[](const var&) variable not in environment"); return d; } inline const var& environment::operator[] (ap_dim_t d) const { return *reinterpret_cast(&e->var_of_dim[d]); } inline ap_dim_t environment::get_dim(const var& x) const { ap_dim_t d = ap_environment_dim_of_var(e, x.get_ap_var_t()); if (d==AP_DIM_MAX) throw std::invalid_argument("apron::environment::get_dim(const var&) variable not in environment"); return d; } inline const var& environment::get_var(ap_dim_t d) const { if (d >= e->intdim+e->realdim) throw std::out_of_range("environment::get_var"); return *reinterpret_cast(&e->var_of_dim[d]); } inline std::vector environment::get_vars() const { std::vector v = std::vector(e->intdim+e->realdim, ""); for (size_t i=0; iintdim+e->realdim; i++) v[i] = e->var_of_dim[i]; return v; } /* Tests */ /* ===== */ inline bool operator==(const environment& x, const environment& y) { return ap_environment_is_eq(x.e, y.e); } inline bool operator!=(const environment& x, const environment& y) { return !ap_environment_is_eq(x.e, y.e); } inline bool operator<=(const environment& x, const environment& y) { return ap_environment_is_leq(x.e, y.e); } inline bool operator>=(const environment& x, const environment& y) { return ap_environment_is_leq(y.e, x.e); } inline int cmp(const environment& x, const environment& y) { return ap_environment_compare(x.e, y.e); } /* print */ inline std::ostream& operator<< (std::ostream& os, const environment& s) { for (size_t i=0; iintdim+s.e->realdim; i++) { char* c = ap_var_operations->to_string(s.e->var_of_dim[i]); os << i << ": " << c << (iintdim ? " (int)" : " (real)") << std::endl; free(c); } return os; } inline void environment::print(FILE* stream) const { ap_environment_fdump(stream, e); } /* C API compatibility */ /* =================== */ inline const ap_environment_t* environment::get_ap_environment_t() const { return e; } inline ap_environment_t*environment:: get_ap_environment_t() { return e; } apron-dist-0.9.10/apron/apronxx/apxx_box_inline.hh0000640014525101416610000000073210703144237022075 0ustar bjeannetpopart/* -*- C++ -*- * apxx_box_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ inline box_manager::box_manager() : manager(box_manager_alloc()) {} inline manager& box_manager::operator=(const manager& m) { return manager::operator=(m); } apron-dist-0.9.10/apron/apronxx/apxx_ppl_product.hh0000640014525101416610000000177710703144237022314 0ustar bjeannetpopart/* -*- C++ -*- * apxx_ppl_product.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library. As it includes both APRON and PPL files, it is released under GPL license. Please read the ppl/COPYING file packaged in the distribution. */ #ifndef __APXX_PPL_PRODUCT_HH #define __APXX_PPL_PRODUCT_HH #include "apxx_manager.hh" #include "ap_pkgrid.h" namespace apron { //! Manager factory for reduced product domain of NewPolka polyhedra and PPL grids. class pkgrid_manager : public manager { public: /*! \brief Creates a new manager. * * \arg \c strict whether to allow strict inequalities as well as non-strict inequalities in polyhedra. * * Note that abstract values created with strict and non-strict managers * are not compatible. */ pkgrid_manager(bool strict = false); //! Copy operator. manager& operator=(const manager&); }; #include "apxx_ppl_product_inline.hh" } #endif /* __APXX_PPL_PRODUCT_HH */ apron-dist-0.9.10/apron/apronxx/apxx_generator0_inline.hh0000640014525101416610000002321010703144237023347 0ustar bjeannetpopart/* -*- C++ -*- * apxx_generator0_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ /* ================================= */ /* generator0 */ /* ================================= */ /* constructors */ /* ============ */ inline generator0::generator0(ap_gentyp_t gentyp) { ap_linexpr0_t* llin = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,0); l = ap_generator0_make(gentyp, llin); } inline generator0::generator0(ap_gentyp_t gentyp, const linexpr0& lin) { ap_linexpr0_t* llin = ap_linexpr0_copy(const_cast(lin.get_ap_linexpr0_t())); l = ap_generator0_make(gentyp, llin); } inline generator0::generator0(const generator0& x) { l = ap_generator0_copy(const_cast(&x.l)); } inline generator0::generator0(const generator0& x, const dimchange& d) { if (!x.l.linexpr0) throw std::invalid_argument("apron::generator0::generator0(const generator0&, cont dimchange&) empty expression"); l = ap_generator0_add_dimensions(const_cast(&x.l), const_cast(d.get_ap_dimchange_t())); } inline generator0::generator0(const generator0& x, const dimperm& d) { if (!x.l.linexpr0) throw std::invalid_argument("apron::generator0::generator0(const generator0&, cont dimperm&) empty expression"); l = ap_generator0_permute_dimensions(const_cast(&x.l), const_cast(d.get_ap_dimperm_t())); } /* destructor */ /* ========== */ inline generator0::~generator0() { ap_generator0_clear(const_cast(&l)); } /* assignment */ /* ========== */ inline generator0& generator0::operator= (const generator0& x) { if (&x!=this) { ap_generator0_clear(const_cast(&l)); l = ap_generator0_copy(const_cast(&x.l)); } return *this; } /* dimension operations */ /* ==================== */ inline void generator0::resize(size_t size) { if (!l.linexpr0) throw std::invalid_argument("apron::generator0::resize(size_t) empty expression"); ap_linexpr0_realloc(l.linexpr0, size); } inline void generator0::add_dimensions(const dimchange& d) { if (!l.linexpr0) throw std::invalid_argument("apron::generator0::add_dimensions(const dimchange&) empty expression"); ap_generator0_add_dimensions_with(&l, const_cast(d.get_ap_dimchange_t())); } inline void generator0::permute_dimensions(const dimperm& d) { if (!l.linexpr0) throw std::invalid_argument("apron::generator0::permute_dimensions(const dimperm&) empty expression"); ap_generator0_permute_dimensions_with(&l, const_cast(d.get_ap_dimperm_t())); } /* access */ /* ====== */ /* size */ inline size_t generator0::size() const { if (!l.linexpr0) throw std::invalid_argument("apron::generator0::size() empty expression"); return ap_linexpr0_size(const_cast(l.linexpr0)); } /* get */ inline ap_gentyp_t& generator0::get_gentyp() { return l.gentyp; } inline const ap_gentyp_t& generator0::get_gentyp() const { return l.gentyp; } inline bool generator0::has_linexpr() const { return l.linexpr0!=NULL; } inline linexpr0& generator0::get_linexpr() { if (!l.linexpr0) throw std::invalid_argument("apron::generator0::get_linexpr() empty expression"); return reinterpret_cast(*l.linexpr0); } inline const linexpr0& generator0::get_linexpr() const { if (!l.linexpr0) throw std::invalid_argument("apron::generator0::get_linexpr() empty expression"); return reinterpret_cast(*l.linexpr0); } inline void generator0::set_linexpr(const linexpr0& c) { if (l.linexpr0) ap_linexpr0_free(l.linexpr0); l.linexpr0 = ap_linexpr0_copy(const_cast(c.get_ap_linexpr0_t())); } /* print */ /* ===== */ inline std::ostream& operator<< (std::ostream& os, const generator0& s) { if (!s.has_linexpr()) throw std::invalid_argument("apron::operator<<(ostream&, const generator0&) empty expression"); switch (s.get_gentyp()) { case AP_GEN_LINE: os << "LINE: "; break; case AP_GEN_RAY: os << "RAY: "; break; case AP_GEN_VERTEX: os << "VERTEX: "; break; case AP_GEN_LINEMOD: os << "LINEMOD: "; break; case AP_GEN_RAYMOD: os << "RAYMOD: "; break; default: throw std::invalid_argument("apron::operator<<(ostream&, const generator0&) invalid generator type"); } return os << s.get_linexpr(); } inline void generator0::print(char** name_of_dim, FILE* stream) const { ap_generator0_fprint(stream, const_cast(&l), name_of_dim); } /* C-level compatibility */ /* ===================== */ inline const ap_generator0_t* generator0::get_ap_generator0_t() const { return &l; } inline ap_generator0_t* generator0::get_ap_generator0_t() { return &l; } /* ================================= */ /* generator0_array */ /* ================================= */ /* constructors */ /* ============ */ inline generator0_array::generator0_array(size_t size) : a(ap_generator0_array_make(size)) { } inline generator0_array::generator0_array(const generator0_array& x) : a(ap_generator0_array_make(x.a.size)) { for (size_t i=0; i(x[i].get_ap_generator0_t())); } inline generator0_array::generator0_array(const std::vector& x) : a(ap_generator0_array_make(x.size())) { for (size_t i=0; i(x[i].get_ap_generator0_t())); } inline generator0_array::generator0_array(const generator0_array& x, const dimchange& d) { a = ap_generator0_array_add_dimensions(const_cast(&x.a), const_cast(d.get_ap_dimchange_t())); } inline generator0_array::generator0_array(const generator0_array& x, const dimperm& d) { a = ap_generator0_array_permute_dimensions(const_cast(&x.a), const_cast(d.get_ap_dimperm_t())); } /* destructor */ /* ========== */ inline generator0_array::~generator0_array() { ap_generator0_array_clear(&a); } /* assignment */ /* ========== */ inline generator0_array& generator0_array::operator= (const generator0_array& x) { if (&x!=this) { ap_generator0_array_clear(&a); a = ap_generator0_array_make(x.a.size); for (size_t i=0; i(x[i].get_ap_generator0_t())); return *this; } inline generator0_array& generator0_array::operator= (const std::vector& x) { size_t size = x.size(); ap_generator0_array_clear(&a); a = ap_generator0_array_make(size); for (size_t i=0; i(x[i].get_ap_generator0_t())); return *this; } /* dimension operations */ /* ==================== */ inline void generator0_array::resize(size_t size) { ap_generator0_array_resize(&a, size); } inline void generator0_array::add_dimensions(const dimchange& d) { ap_generator0_array_add_dimensions_with(&a, const_cast(d.get_ap_dimchange_t())); } inline void generator0_array::permute_dimensions(const dimperm& d) { ap_generator0_array_permute_dimensions_with(&a, const_cast(d.get_ap_dimperm_t())); } /* access */ /* ====== */ inline size_t generator0_array::size() const { return a.size; } inline generator0* generator0_array::contents() { return reinterpret_cast(a.p); } inline const generator0* generator0_array::contents() const { return reinterpret_cast(a.p); } inline generator0& generator0_array::operator[](size_t i) { return reinterpret_cast(a.p[i]); } inline const generator0& generator0_array::operator[](size_t i) const { return reinterpret_cast(a.p[i]); } inline generator0& generator0_array::get(size_t i) { if (i >= a.size) throw std::out_of_range("apron::generator0_array::get(size_t)"); return reinterpret_cast(a.p[i]); } inline const generator0& generator0_array::get(size_t i) const { if (i >= a.size) throw std::out_of_range("apron::generator0_array::get(size_t)"); return reinterpret_cast(a.p[i]); } /* conversion */ /* ========== */ inline generator0_array::operator std::vector() const { size_t sz = size(); std::vector v = std::vector(sz); for (size_t i=0;i(&a), name_of_dim); } /* C-level compatibility */ /* ===================== */ inline const ap_generator0_array_t* generator0_array::get_ap_generator0_array_t() const { return &a; } inline ap_generator0_array_t* generator0_array::get_ap_generator0_array_t() { return &a; } apron-dist-0.9.10/apron/apronxx/apxx_linexpr0_inline.hh0000640014525101416610000002540610703144237023053 0ustar bjeannetpopart/* -*- C++ -*- * apxx_linexpr0_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ /* ================================= */ /* linexpr0 */ /* ================================= */ static inline void apxx_linexpr0_init(ap_linexpr0_t* d, ap_linexpr_discr_t discr, size_t size) { d->discr = discr; d->size = 0; ap_coeff_init(&d->cst,AP_COEFF_SCALAR); if (discr==AP_LINEXPR_DENSE) d->p.coeff = NULL; else d->p.linterm = NULL; if (size) ap_linexpr0_realloc(d,size); } static inline void apxx_linexpr0_clear(ap_linexpr0_t* d) { ap_linexpr0_realloc(d, 0); ap_coeff_clear(&d->cst); } static inline void apxx_linexpr0_copy(ap_linexpr0_t* d, const ap_linexpr0_t* s) { if (d==s) return; assert(d->discr==s->discr); ap_linexpr0_realloc(d,s->size); ap_coeff_set(&d->cst, const_cast(&s->cst)); if (d->discr==AP_LINEXPR_DENSE) { for (size_t i=0; isize; i++) ap_coeff_set(&d->p.coeff[i], &s->p.coeff[i]); } else { for (size_t i=0; isize; i++) { ap_coeff_set(&d->p.linterm[i].coeff, &s->p.linterm[i].coeff); d->p.linterm[i].dim = s->p.linterm[i].dim; } } } /* constructors */ /* ============ */ inline linexpr0::linexpr0(ap_linexpr0_t* p) : l(*p) { free(p); } inline linexpr0::linexpr0(ap_linexpr_discr_t discr, size_t size) { apxx_linexpr0_init(&l, discr, size); } inline linexpr0::linexpr0(const linexpr0& x) { apxx_linexpr0_init(&l, x.l.discr, x.l.size); apxx_linexpr0_copy(&l, &x.l); } inline linexpr0::linexpr0(const linexpr0& x, const dimchange& d) { ap_linexpr0_t* p; p = ap_linexpr0_add_dimensions(const_cast(&x.l), const_cast(d.get_ap_dimchange_t())); l = *p; free(p); } inline linexpr0::linexpr0(const linexpr0& x, const dimperm& d) { ap_linexpr0_t* p; p = ap_linexpr0_permute_dimensions(const_cast(&x.l), const_cast(d.get_ap_dimperm_t())); l = *p; free(p); } inline linexpr0::linexpr0(size_t size, const coeff coeffs[], const coeff& cst, ap_linexpr_discr_t discr) { apxx_linexpr0_init(&l, discr, size); for (size_t i=0;i& coeffs, const coeff& cst, ap_linexpr_discr_t discr) { size_t size = coeffs.size(); apxx_linexpr0_init(&l, discr, size); for (size_t i=0;i(d.get_ap_dimchange_t())); } inline void linexpr0::permute_dimensions(const dimperm& d) { ap_linexpr0_permute_dimensions_with(&l, const_cast(d.get_ap_dimperm_t())); } /* access */ /* ====== */ /* size */ inline size_t linexpr0::size() const { return ap_linexpr0_size(const_cast(&l)); } /* get */ inline ap_linexpr_discr_t linexpr0::get_discr() const { return l.discr; } inline coeff& linexpr0::get_cst() { return reinterpret_cast(*ap_linexpr0_cstref(const_cast(&l))); } inline const coeff& linexpr0::get_cst() const { return reinterpret_cast(*ap_linexpr0_cstref(const_cast(&l))); } inline coeff& linexpr0::operator[](ap_dim_t dim) { ap_coeff_t* x = ap_linexpr0_coeffref(&l, dim); if (!x) throw std::out_of_range("apron::linexpr0::operator[](ap_dim_t)"); return reinterpret_cast(*x); } inline const coeff& linexpr0::operator[](ap_dim_t dim) const { const ap_coeff_t* x = ap_linexpr0_coeffref(const_cast(&l), dim); if (!x) throw std::out_of_range("apron::linexpr0::operator[](ap_dim)t"); return reinterpret_cast(*x); } /* print */ /* ===== */ static inline bool print_coeff_sign(std::ostream& os, const coeff& c, bool& first, bool cst) { if (c.is_zero()) return false; if (c.get_discr()==AP_COEFF_SCALAR) { if (c.get_scalar()==1) { if (!first) os << " + "; if (cst) os << "1"; } else if (c.get_scalar().sgn()<0) { if (first) os << "- " << -c; else os << " - " << -c; } else if (first) os << c; else os << " + " << c; } else { if (first) os << c; else os << " + " << c; } first = false; return true; } inline std::ostream& operator<<(std::ostream& os, const linexpr0& s) { std::vector* names = get_varname(os); bool first = true; if (names) { size_t sz = (*names).size(); for (linexpr0::const_iterator i=s.begin();i.valid();++i) { if (print_coeff_sign(os, i.get_coeff(), first, false)) { if (i.get_dim()(&l), name_of_dim); } /* tests */ /* ===== */ inline bool linexpr0::is_integer(size_t intdim) const { return ap_linexpr0_is_integer(const_cast(&l), intdim); } inline bool linexpr0::is_real(size_t intdim) const { return ap_linexpr0_is_real(const_cast(&l), intdim); } inline ap_linexpr_type_t linexpr0::get_type() const { return ap_linexpr0_type(const_cast(&l)); } inline bool linexpr0::is_linear() const { return ap_linexpr0_is_linear(const_cast(&l)); } inline bool linexpr0::is_quasilinear() const { return ap_linexpr0_is_quasilinear(const_cast(&l)); } inline int compare(const linexpr0& x, const linexpr0& y) { return ap_linexpr0_compare(const_cast(&x.l), const_cast(&y.l)); } inline bool equal (const linexpr0& x, const linexpr0& y) { return ap_linexpr0_equal(const_cast(&x.l), const_cast(&y.l)); } #if 0 // overloaded to make constraints inline bool operator>= (const linexpr0& x, const linexpr0& y) { return ap_linexpr0_compare(const_cast(&x.l), const_cast(&y.l)) >= 0; } inline bool operator<= (const linexpr0& x, const linexpr0& y) { return ap_linexpr0_compare(const_cast(&x.l), const_cast(&y.l)) <= 0; } inline bool operator> (const linexpr0& x, const linexpr0& y) { return ap_linexpr0_compare(const_cast(&x.l), const_cast(&y.l)) > 0; } inline bool operator< (const linexpr0& x, const linexpr0& y) { return ap_linexpr0_compare(const_cast(&x.l), const_cast(&y.l)) < 0; } inline bool operator== (const linexpr0& x, const linexpr0& y) { return ap_linexpr0_equal(const_cast(&x.l), const_cast(&y.l)); } inline bool operator!= (const linexpr0& x, const linexpr0& y) { return !ap_linexpr0_equal(const_cast(&x.l), const_cast(&y.l)); } #endif /* iterators */ /* ========= */ inline void linexpr0::const_iterator::skip_AP_DIM_MAX() { if (l->discr == AP_LINEXPR_DENSE) return; while (pos < l->size && l->p.linterm[pos].dim == AP_DIM_MAX) pos++; } inline linexpr0::const_iterator::const_iterator(ap_linexpr0_t* e) : l(e), pos(0) { skip_AP_DIM_MAX(); } inline linexpr0::const_iterator::const_iterator(const linexpr0& e) { l = const_cast(e.get_ap_linexpr0_t()); pos = 0; skip_AP_DIM_MAX(); } inline linexpr0::const_iterator::const_iterator(const const_iterator& i) : l(i.l), pos(i.pos) {} inline linexpr0::iterator::iterator(ap_linexpr0_t* e) : linexpr0::const_iterator(e) {} inline linexpr0::iterator::iterator(linexpr0& e) : linexpr0::const_iterator(e.get_ap_linexpr0_t()) {} inline linexpr0::iterator::iterator(const iterator& i) : linexpr0::const_iterator(i.l) {} inline linexpr0::const_iterator& linexpr0::const_iterator::operator=(const const_iterator& i) { l = i.l; pos = i.pos; return *this; } inline linexpr0::iterator& linexpr0::iterator::operator=(const iterator& i) { l = i.l; pos = i.pos; return *this; } inline ap_dim_t linexpr0::const_iterator::get_dim() const { if (pos >= l->size) throw std::out_of_range("apron::linexpr0::const_iterator::get_dim()"); if (l->discr == AP_LINEXPR_DENSE) return pos; else return l->p.linterm[pos].dim; } inline const coeff& linexpr0::const_iterator::get_coeff() const { if (pos >= l->size) throw std::out_of_range("apron::linexpr0::const_iterator::get_coeff()"); if (l->discr == AP_LINEXPR_DENSE) return reinterpret_cast(l->p.coeff[pos]); else return reinterpret_cast(l->p.linterm[pos].coeff); } inline coeff& linexpr0::iterator::get_coeff() const { if (pos >= l->size) throw std::out_of_range("apron::linexpr0::iterator::get_coeff()"); if (l->discr == AP_LINEXPR_DENSE) return reinterpret_cast(l->p.coeff[pos]); else return reinterpret_cast(l->p.linterm[pos].coeff); } inline void linexpr0::const_iterator::next() { pos++; skip_AP_DIM_MAX(); } inline void linexpr0::const_iterator::operator++() { next(); } inline bool linexpr0::const_iterator::valid() const { return pos < l->size; } inline linexpr0::iterator linexpr0::begin() { return iterator(*this); } inline linexpr0::const_iterator linexpr0::begin() const { return const_iterator(*this); } /* other operators */ /* =============== */ inline void linexpr0::minimize() { ap_linexpr0_minimize(&l); } inline long linexpr0::hash() const { return ap_linexpr0_hash(const_cast(&l)); } /* C-level compatibility */ /* ===================== */ inline const ap_linexpr0_t* linexpr0::get_ap_linexpr0_t() const { return &l; } inline ap_linexpr0_t* linexpr0::get_ap_linexpr0_t() { return &l; } apron-dist-0.9.10/apron/apronxx/apxx_linexpr1_inline.hh0000640014525101416610000001744610703144237023061 0ustar bjeannetpopart/* -*- C++ -*- * apxx_linexpr1_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ /* ================================= */ /* linexpr1 */ /* ================================= */ /* constructors */ /* ============ */ inline linexpr1::linexpr1(ap_linexpr1_t& p) : l(p) { } inline linexpr1::linexpr1(const environment& e, const linexpr0& x) { l = ap_linexpr1_of_linexpr0(const_cast(e.get_ap_environment_t()), ap_linexpr0_copy(const_cast(x.get_ap_linexpr0_t()))); } inline linexpr1::linexpr1(const environment& e, ap_linexpr_discr_t lin_discr, size_t size) { l = ap_linexpr1_make(const_cast(e.get_ap_environment_t()), lin_discr, size); } inline linexpr1::linexpr1(const linexpr1& x) { l = ap_linexpr1_copy(const_cast(&x.l)); } inline linexpr1::linexpr1(const linexpr1& x, const environment& e) { bool r = ap_linexpr1_extend_environment(&l, const_cast(&x.l), const_cast(e.get_ap_environment_t())); if (r) throw std::invalid_argument("apron::linexpr1::linexpr1(const linexpr1&, environment&) not a super-environment"); } /* destructor */ /* ========== */ inline linexpr1::~linexpr1() { ap_linexpr1_clear(&l); } /* assignment */ /* ========== */ inline linexpr1& linexpr1::operator=(const linexpr1& x) { ap_linexpr1_t ll = ap_linexpr1_copy(const_cast(&x.l)); ap_linexpr1_clear(&l); l = ll; return *this; } /* dimension operations */ /* ==================== */ inline void linexpr1::extend_environment(const environment& e) { bool r = ap_linexpr1_extend_environment_with(&l, const_cast(e.get_ap_environment_t())); if (r) throw std::invalid_argument("apron::linexpr1::extend_environment(const environment&) not a super-environment"); } /* access */ /* ====== */ inline environment linexpr1::get_environment() const { return ap_environment_copy(ap_linexpr1_envref(const_cast(&l))); } inline const linexpr0& linexpr1::get_linexpr0() const { return reinterpret_cast(*ap_linexpr1_linexpr0ref(const_cast(&l))); } inline linexpr0& linexpr1::get_linexpr0() { return reinterpret_cast(*ap_linexpr1_linexpr0ref(&l)); } inline size_t linexpr1::size() const { return ap_linexpr0_size(ap_linexpr1_linexpr0ref(const_cast(&l))); } inline ap_linexpr_discr_t linexpr1::get_discr() const { return ap_linexpr1_linexpr0ref(const_cast(&l))->discr; } inline coeff& linexpr1::get_cst() { return reinterpret_cast(*ap_linexpr1_cstref(&l)); } inline const coeff& linexpr1::get_cst() const { return reinterpret_cast(*ap_linexpr1_cstref(const_cast(&l))); } inline coeff& linexpr1::operator[](const var& var) { ap_coeff_t* x = ap_linexpr1_coeffref(&l, const_cast(var.get_ap_var_t())); if (!x) throw std::invalid_argument("apron::linexpr1::operator[](const var&) variable not in environment"); return reinterpret_cast(*x); } inline const coeff& linexpr1::operator[](const var& var) const { ap_coeff_t* x = ap_linexpr1_coeffref(const_cast(&l), const_cast(var.get_ap_var_t())); if (!x) throw std::invalid_argument("apron::linexpr1::operator[](const var&) variable not in environment"); return reinterpret_cast(*x); } /* print */ /* ===== */ inline std::ostream& operator<<(std::ostream& os, const linexpr1& s) { bool first = true; for (linexpr1::const_iterator i=s.begin();i.valid();++i) { if (print_coeff_sign(os, i.get_coeff(), first, false)) os << i.get_var(); } print_coeff_sign(os, s.get_cst(), first, true); if (first) os << "0"; return os; } inline void linexpr1::print(FILE* stream) const { ap_linexpr1_fprint(stream, const_cast(&l)); } /* tests */ /* ===== */ inline bool linexpr1::is_integer() const { return ap_linexpr1_is_integer(const_cast(&l)); } inline bool linexpr1::is_real() const { return ap_linexpr1_is_real(const_cast(&l)); } inline ap_linexpr_type_t linexpr1::get_type() const { return ap_linexpr1_type(const_cast(&l)); } inline bool linexpr1::is_linear() const { return ap_linexpr1_is_linear(const_cast(&l)); } inline bool linexpr1::is_quasilinear() const { return ap_linexpr1_is_quasilinear(const_cast(&l)); } /* iterators */ /* ========= */ inline void linexpr1::const_iterator::skip_AP_DIM_MAX() { if (l->linexpr0->discr == AP_LINEXPR_DENSE) return; while (pos < l->linexpr0->size && l->linexpr0->p.linterm[pos].dim == AP_DIM_MAX) pos++; } inline linexpr1::const_iterator::const_iterator(ap_linexpr1_t* e) : l(e), pos(0) { skip_AP_DIM_MAX(); } inline linexpr1::const_iterator::const_iterator(const linexpr1& e) { l = const_cast(e.get_ap_linexpr1_t()); pos = 0; skip_AP_DIM_MAX(); } inline linexpr1::const_iterator::const_iterator(const const_iterator& i) : l(i.l), pos(i.pos) {} inline linexpr1::iterator::iterator(ap_linexpr1_t* e) : linexpr1::const_iterator(e) {} inline linexpr1::iterator::iterator(linexpr1& e) : linexpr1::const_iterator(e.get_ap_linexpr1_t()) {} inline linexpr1::iterator::iterator(const iterator& i) : linexpr1::const_iterator(i.l) {} inline linexpr1::const_iterator& linexpr1::const_iterator::operator=(const const_iterator& i) { l = i.l; pos = i.pos; return *this; } inline linexpr1::iterator& linexpr1::iterator::operator=(const iterator& i) { l = i.l; pos = i.pos; return *this; } inline ap_dim_t linexpr1::const_iterator::get_dim() const { if (pos >= l->linexpr0->size) throw std::out_of_range("apron::linexpr1::const_iterator::get_dim()"); if (l->linexpr0->discr == AP_LINEXPR_DENSE) return pos; else return l->linexpr0->p.linterm[pos].dim; } inline const var& linexpr1::const_iterator::get_var() const { ap_dim_t d; if (pos >= l->linexpr0->size) throw std::out_of_range("apron::linexpr1::const_iterator::get_var()"); if (l->linexpr0->discr == AP_LINEXPR_DENSE) d = pos; else d = l->linexpr0->p.linterm[pos].dim; return *reinterpret_cast(&l->env->var_of_dim[d]); } inline const coeff& linexpr1::const_iterator::get_coeff() const { if (pos >= l->linexpr0->size) throw std::out_of_range("apron::linexpr1::const_iterator::get_coeff()"); if (l->linexpr0->discr == AP_LINEXPR_DENSE) return reinterpret_cast(l->linexpr0->p.coeff[pos]); else return reinterpret_cast(l->linexpr0->p.linterm[pos].coeff); } inline coeff& linexpr1::iterator::get_coeff() const { if (pos >= l->linexpr0->size) throw std::out_of_range("apron::linexpr1::iterator::get_coeff()"); if (l->linexpr0->discr == AP_LINEXPR_DENSE) return reinterpret_cast(l->linexpr0->p.coeff[pos]); else return reinterpret_cast(l->linexpr0->p.linterm[pos].coeff); } inline void linexpr1::const_iterator::next() { pos++; skip_AP_DIM_MAX(); } inline void linexpr1::const_iterator::operator++() { next(); } inline bool linexpr1::const_iterator::valid() const { return pos < l->linexpr0->size; } inline linexpr1::const_iterator linexpr1::begin() const { return const_iterator(*this); } inline linexpr1::iterator linexpr1::begin() { return iterator(*this); } /* other operators */ /* =============== */ inline void linexpr1::minimize() { ap_linexpr1_minimize(&l); } /* C-level compatibility */ /* ===================== */ inline const ap_linexpr1_t* linexpr1::get_ap_linexpr1_t() const { return &l; } inline ap_linexpr1_t* linexpr1::get_ap_linexpr1_t() { return &l; } apron-dist-0.9.10/apron/apronxx/apxx_polka.hh0000640014525101416610000000157210703144237021060 0ustar bjeannetpopart/* -*- C++ -*- * apxx_polka.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_POLKA_HH #define __APXX_POLKA_HH #include "apxx_manager.hh" #include "pk.h" namespace apron { //! Manager factory for the NewPolka polyhedra library. class polka_manager : public manager { public: /*! \brief Creates a new manager. * * \arg \c strict whether to allow strict inequalities as well as non-strict inequalities. * * Note that abstract values created with strict and non-strict managers * are not compatible. */ polka_manager(bool strict = false); //! Copy operator. manager& operator=(const manager&); }; #include "apxx_polka_inline.hh" } #endif /* __APXX_POLKA_HH */ apron-dist-0.9.10/apron/apronxx/apxx_scalar.hh0000640014525101416610000002200011006063143021175 0ustar bjeannetpopart/* -*- C++ -*- * apxx_scalar.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_SCALAR_HH #define __APXX_SCALAR_HH #include #include #include "ap_scalar.h" #include "gmpxx.h" namespace apron { //! Either +oo or -oo, to simplify initialisations and assignments. struct infty { int sgn; //!< Sign: >0 for +oo, <0 for -oo. //! \arg \c sgn: >0 for +oo, <0 for -oo. infty(int sgn=1) : sgn(sgn) {}; }; //! A fraction with native int coefficients, to simplify initialisations and assignments. struct frac { long num; //!< Numerator. unsigned long den; //!< Denominator. /*! \arg \c num: Numerator. * \arg \c den: Denominator. */ frac(long num, unsigned long den=1) : num(num), den(den) {} }; //! Exception raised when an operation is incompatible with a discriminant. class bad_discriminant : public std::logic_error { public: /*! \arg \c arg: Reason of failure. */ bad_discriminant(const std::string &arg) : logic_error(arg) {} }; /* ================================= */ /* use_malloc */ /* ================================= */ //! Inherited by most wrappers to map new and delete to malloc and free. struct use_malloc { void* operator new (size_t sz); void* operator new[] (size_t sz); void operator delete (void* p); void operator delete[](void* p); }; /* ================================= */ /* scalar */ /* ================================= */ /*! \brief Scalar (ap_scalar_t wrapper). * * A scalar object represents a (possibly +oo or -oo) number, using either a double * or a MPQ (multi-precision fraction). * All operations are exact unless explicitly noted. */ class scalar : public use_malloc { protected: ap_scalar_t c; //!< Structure managed by APRON. public: //! Returned by ordering functions. enum order { LESS = -1, //!< Means less than, negative, or -oo (depending on context). EQUAL = 0, //!< Means equal or null (depending on context). GREATER = 1, //!< Means greater than, positive, or +oo (depending on context). }; /* constructors */ /* ============ */ /** @name Constructors */ //@{ //! Makes a double scalar equal to 0.0. scalar(); //! Makes a MPQ scalar from a native integer. scalar(int x); //! Makes a MPQ scalar from a native integer. scalar(long x); //! Makes a double scalar from a double. scalar(double x); //! Makes a MPQ scalar from a fraction with native integer coefficients. scalar(const frac& x); //! Makes a double scalar equal to +oo or -oo. scalar(infty x); //! Makes a MPQ scalar from a MPQ (copied). scalar(const mpq_class& x); //! Makes a MPFR scalar from a MPFR number (copied). scalar(mpfr_t x); //! Makes a copy of a scalar. scalar(const scalar& x); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ ~scalar(); //@} /* assignments */ /* =========== */ /** @name Assignments */ //@{ //! Assigns a native integer to *this, setting its type to MPQ. scalar& operator= (int x); //! Assigns a native integer to *this, setting its type to MPQ. scalar& operator= (long x); //! Assigns a double to *this, setting its type to double. scalar& operator= (double x); //! Assigns a fraction to *this, setting its type to MPQ. scalar& operator= (const frac& x); //! Assigns +oo or -oo to *this, no change in scalar type. scalar& operator= (infty x); //! Assigns a MPQ to *this (copied), setting its type to MPQ. scalar& operator= (const mpq_class& x); //! Assigns a MPFR to *this (copied), setting its type to MPFR. scalar& operator= (mpfr_t x); //! Sets the type and value of *this to that of x. scalar& operator= (const scalar& x); //! Swaps the contents (type and value) of two scalars. friend void swap(scalar& a, scalar &b); //@} /* access */ /* ====== */ /** @name Accesses */ //@{ /*! \brief Whether the object wraps a double or a MPQ. * * \return Either \c AP_SCALAR_DOUBLE, \c AP_SCALAR_MPQ, or \c AP_SCALAR_MPFR. */ ap_scalar_discr_t get_discr() const; /*! \brief Returns a (modifiable) reference to the double contained in the scalar. * * \throw bad_discriminant when the scalar is not of double type. */ double& get_double(); /*! \brief Returns a reference to the double contained in the scalar. * *\throw bad_discriminant when the scalar is not of double type. */ const double& get_double() const; /*! \brief Returns a (modifiable) reference to the MPQ contained in the scalar. * * \throw bad_discriminant when the scalar is not of MPQ type. */ mpq_class& get_mpq(); /*! \brief Return a reference to the MPQ contained in the scalar. * *\throw bad_discriminant when the scalar is not of MPQ type. */ const mpq_class& get_mpq() const; //@} /* conversion */ /* ========== */ /** @name Conversions */ //@{ /*! \brief Returns a new MPQ containing the (possibly converted) value of the scalar. * * \arg \c round: rounding direction, may be GMP_RNDN, GMP_RNDZ, GMP_RNDU, GMP_RNDD, or GMP_RND_MAX. * \arg \c conv is set to either LESS, EQUAL, or GREATER, depending on whether the result is * less than, equal to or greater than the value of *this. * \note Currently round is ignored and the conversion is always exact. */ mpq_class to_mpq(mp_rnd_t round, order& conv) const; /*! \brief Returns a double containing the (possibly converted) value of the scalar. * * \arg \c round: rounding direction, may be GMP_RNDN, GMP_RNDZ, GMP_RNDU, GMP_RNDD, or GMP_RND_MAX. * \arg \c conv is set to either LESS, EQUAL, or GREATER, depending on whether the result is * less than, equal to or greater than the value of *this. */ double to_double(mp_rnd_t round, order& conv) const; /*! \brief Copies the (possibly converted) value of the scalar into the MPFR. * * \arg \c round: rounding direction, may be GMP_RNDN, GMP_RNDZ, GMP_RNDU, GMP_RNDD, or GMP_RND_MAX. * \arg \c conv is set to either LESS, EQUAL, or GREATER, depending on whether the result is * less than, equal to or greater than the value of *this. */ void to_mpfr(mpfr_t x, mp_rnd_t round, order& conv) const; //! Returns a new MPQ containing the (possibly converted) value of the scalar. No rounding. operator mpq_class() const; //! Returns a double containing the (possibly converted) value of the scalar. Rounding to nearest. operator double() const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ //! Printing. friend std::ostream& operator<< (std::ostream& os, const scalar& s); //! Prints to a C stream. void print(FILE* stream=stdout) const; //@} /* tests */ /* ===== */ /** @name Tests */ //@{ //! Returns LESS if -oo, GREATER if +oo, EQUAL if finite. order is_infty() const; //! Returns LESS if negative, GREATER if positive, EQUAL if null. order sgn () const; //! Returns LESS if ab, EQUAL if a=b (total order). friend order cmp(const scalar& a, const scalar& b); friend bool operator>=(const scalar& a, const scalar& b); friend bool operator<=(const scalar& a, const scalar& b); friend bool operator> (const scalar& a, const scalar& b); friend bool operator< (const scalar& a, const scalar& b); friend bool operator==(const scalar& a, const scalar& b); friend bool operator!=(const scalar& a, const scalar& b); friend order cmp(const scalar& a, int b); friend bool operator>=(const scalar& a, int b); friend bool operator<=(const scalar& a, int b); friend bool operator> (const scalar& a, int b); friend bool operator< (const scalar& a, int b); friend bool operator==(const scalar& a, int b); friend bool operator!=(const scalar& a, int b); friend order cmp(int a, const scalar& b); friend bool operator>=(int a, const scalar& b); friend bool operator<=(int a, const scalar& b); friend bool operator> (int a, const scalar& b); friend bool operator< (int a, const scalar& b); friend bool operator==(int a, const scalar& b); friend bool operator!=(int a, const scalar& b); //@} /* other operators */ /* =============== */ /** @name Operators */ //@{ //! Negates *this. void neg(); //! Returns the opposite of *this. scalar operator- () const; //! Inverses *this. Not exact for double type. void inv(); //! Returns the inverse of *this. Not exact for double type. scalar operator~ () const; //! Returns a hash code. long hash() const; //@} /* C API compatibility */ /* =================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. const ap_scalar_t* get_ap_scalar_t() const; //! Returns a pointer to the internal APRON object stored in *this. ap_scalar_t* get_ap_scalar_t(); //@} }; #include "apxx_scalar_inline.hh" } #endif /* __APXX_SCALAR_HH */ apron-dist-0.9.10/apron/apronxx/apxx_oct_inline.hh0000640014525101416610000000073210703144237022072 0ustar bjeannetpopart/* -*- C++ -*- * apxx_oct_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ inline oct_manager::oct_manager() : manager(oct_manager_alloc()) {} inline manager& oct_manager::operator=(const manager& m) { return manager::operator=(m); } apron-dist-0.9.10/apron/apronxx/apxx_tcons1.hh0000640014525101416610000003303210703144237021155 0ustar bjeannetpopart/* -*- C++ -*- * apxx_tcons1.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_TCONS1_HH #define __APXX_TCONS1_HH #include "ap_tcons1.h" #include "apxx_tcons0.hh" #include "apxx_texpr1.hh" namespace apron { /* ================================= */ /* tcons1 */ /* ================================= */ /*! \brief Level 1 arbitrary constraint (ap_tcons1_t wrapper). * * Level 1 version of arbitrary constraints using expression trees. * Variable names (var) are used instead of dimensions (ap_dim_t). * Internally, a tcons1 wraps together a tcons0 (memory managed) and an environment (holding a * reference count). */ class tcons1 : public use_malloc { protected: ap_tcons1_t l; //!< Structure managed by APRON. //! Internal use only. Performs a shallow copy and takes ownership of the contents. tcons1(ap_tcons1_t l); friend class abstract0; friend class tcons1_array; public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ /*! \brief Creates an empty constraint. * * Neither the expression tree nor the extra scalar are not created * (has_texpr and has_modulo both return false). * \arg \c constyp can be \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, or \c AP_CONS_DISEQ (but not \c AP_CONS_EQMOD). */ tcons1(const environment& env, ap_constyp_t constyp=AP_CONS_SUPEQ); /*! \brief Creates a new (non-modulo) constraint from an expression tree (copied). * * The extra scalar is not created (has_modulo returns false). * \arg \c constyp can be \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, or \c AP_CONS_DISEQ (but not \c AP_CONS_EQMOD). */ tcons1(ap_constyp_t constyp, const texpr1::builder& t); /*! \brief Creates a new constraint from an expression tree and a modulo scalar (both copied). * * \arg \c constyp can be \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, \c AP_CONS_EQMOD, or \c AP_CONS_DISEQ. */ tcons1(ap_constyp_t constyp, const texpr1::builder& t, const scalar& modulo); //! (Deep) copy of a constraint. tcons1(const tcons1& x); /*! \brief Makes a (deep) copy of x and extends its environment. * * \throw std::invalid_argument if e is not a super-environment of that of x. */ tcons1(const tcons1& x, const environment& e); //! Makes an unsatisfiable constraint (-1>=0). tcons1(const environment& e, unsat x); /*! \brief Makes a constraint from a linear constraint (copying coefficients). * * Real-valued addition and multiplication operators are used (i.e., no rounding). */ tcons1(const lincons1& x); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ //! Frees the constraint, including the embedded expression tree and optional modulo scalar. ~tcons1(); //@} /* 'Intelligent' constructors */ /* ========================== */ /** @name 'Intelligent' constructors */ //@{ //! Makes a constraint a-b >= 0. friend tcons1 operator>=(const texpr1::builder& a, const texpr1::builder& b); //! Makes a constraint b-a >= 0. friend tcons1 operator<=(const texpr1::builder& a, const texpr1::builder& b); //! Makes a constraint a-b > 0. friend tcons1 operator> (const texpr1::builder& a, const texpr1::builder& b); //! Makes a constraint b-a > 0. friend tcons1 operator< (const texpr1::builder& a, const texpr1::builder& b); //! Makes a constraint a-b == 0. friend tcons1 operator==(const texpr1::builder& a, const texpr1::builder& b); //! Makes a constraint a-b != 0. friend tcons1 operator!=(const texpr1::builder& a, const texpr1::builder& b); //@} /* assignment */ /* ========== */ /** @name Assignments */ //@{ //! (Deep) copy. tcons1& operator= (const tcons1& x); //! Assigns an unsatisfiable constraint to *this (-1>=0). tcons1& operator= (unsat x); /*! \brief Makes *this equal to the linear constraint x (coefficients are copied), deleting the previous value of *this. * * Real-valued addition and multiplication operators are used (i.e., no rounding). */ tcons1& operator= (const lincons1& x); /*! \brief Sets the extra scalar modulo to c (copied). * * Does not fail as get_modulo can: if the constraint was created without an extra scalar, * it is created. */ void set_modulo(const scalar& c); /*! \brief Sets the underlying expression tree to c (copied). * * Does not fail as get_texpr can: if the constraint was created without an underlying expression, * it is created. */ void set_texpr(const texpr1::builder& c); //@} /* dimension operations */ /* ==================== */ /** @name Dimension operations */ //@{ /*! \brief Extends the environment of the expression. * * \throw std::invalid_argument if e is not a super-environment of that of *this. */ void extend_environment(const environment& e); //@} /* access */ /* ====== */ /** @name Accesses */ //@{ /* get */ //! Returns the environment of the expression (with incremented reference count). environment get_environment() const; //! Returns a reference to the underlying tcons0. const tcons0& get_tcons0() const; //! Returns a (modifiable) reference to the underlying tcons0. tcons0& get_tcons0(); /*! \brief Returns a (modifiable) reference to the constraint type. * * \return either \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, \c AP_CONS_EQMOD, or \c AP_CONS_DISEQ. */ ap_constyp_t& get_constyp(); /*! \brief Returns a reference to the constraint type. * * \return either \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, \c AP_CONS_EQMOD, or \c AP_CONS_DISEQ. */ const ap_constyp_t& get_constyp() const; //! Returns whether the constraint has a valid extra scalar (used in modulo constraints). bool has_modulo() const; //! \brief Whether the constraint contains a valid expression tree. bool has_texpr() const; /*! \brief Returns a (modifiable) reference to the extra scalar. * * \throw std::invalid_argument if no valid extra scalar has been defined. */ scalar& get_modulo(); /*! \brief Returns a reference to the extra scalar. * * \throw std::invalid_argument if no valid extra scalar has been defined. */ const scalar& get_modulo() const; /*! \brief Returns an iterator to the root of the underlying expression tree. * * \throw std::invalid_argument if no valid expression tree has been defined. */ texpr1::iterator get_texpr(); /*! \brief Returns a const_iterator to the root of the underlying expression tree. * * \throw std::invalid_argument if no valid expression tree has been defined. */ texpr1::const_iterator get_texpr() const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ /*! \brief Printing. * * \throw std::invalid_argument if the underlying expression is missing, or the * extra scalar is missing (for modulo). */ friend std::ostream& operator<< (std::ostream& os, const tcons1& s); //! Prints to a C stream. void print(FILE* stream=stdout) const; //@} /* tests */ /* ===== */ /** @name Tests */ //@{ /*! \brief Whether the expression is constant (i.e., has no dimension leaves). * * \throw std::invalid_argument if no valid expression tree has been defined. */ bool is_interval_cst() const; /*!\brief Whether the expression is linear and there is no rounding. * * \throw std::invalid_argument if no valid expression tree has been defined. */ bool is_interval_linear() const; /*! \brief Whether the expression is polynomial and there is no rounding. * * \throw std::invalid_argument if no valid expression tree has been defined. */ bool is_interval_polynomial() const; /*! \brief Whether the expression is a polynomial fraction and there is no rounding. * * \throw std::invalid_argument if no valid expression tree has been defined. */ bool is_interval_polyfrac() const; /*! \brief Whether all occurring constants are scalar. * * \throw std::invalid_argument if no valid expression tree has been defined. */ bool is_scalar() const; //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. const ap_tcons1_t* get_ap_tcons1_t() const; //! Returns a pointer to the internal APRON object stored in *this. ap_tcons1_t* get_ap_tcons1_t(); //@} }; /* ================================= */ /* tcons1_array */ /* ================================= */ /*! \brief Array of arbitrary constraints (ap_tcons1_array_t wrapper). * * A tcons1_array represents an array of constraints on arbitrary expressions. * An constraints share the same environment. */ class tcons1_array : public use_malloc { protected: ap_tcons1_array_t a; //!< Structure managed by APRON. //! Internal use only. Performs a shallow copy and takes ownership of the contents. tcons1_array(ap_tcons1_array_t& a); friend class abstract0; friend class abstract1; public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ /*! \brief Creates a new constraint array from a tcons0_array (copied) and an environment (reference count * incremented) associating names to dimensions. */ tcons1_array(const environment& e, const tcons0_array& x); /*! \brief Creates a new array of the given size containing uninitialized constraints. * * has_modulo and has_texpr will return false on all elements of the array. */ tcons1_array(const environment& e, size_t size); //! (Deep) copy. tcons1_array(const tcons1_array& x); /*! \brief Makes a (deep) copy of the array and extends the environment. * * \throw std::invalid_argument if e is not a super-environment of that of x. */ tcons1_array(const tcons1_array& x, const environment& e); /*! \brief Creates a tcons1_array from an array (of size >0) of constraints of the given size (copied). * * \warning assumes that all constraints have the same environment (unchecked). * \throw std::invalid_argument if size<1. */ tcons1_array(size_t size, const tcons1 x[]); /*! \brief Creates a tcons1_array from an vector (of size >0) of constraints of the given size (copied). * * \warning assumes that all constraints have the same environment (unchecked). * \throw std::invalid_argument if vector size<1. */ tcons1_array(const std::vector& x); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ //! Frees the space used by the array and all its constraints. ~tcons1_array(); //@} /* assignment */ /* ========== */ /** @name Assignments */ //@{ //! (Deep) copy. tcons1_array& operator= (const tcons1_array& x); /*! \brief Copies the constraints from the array into *this. * * \warning assumes that all constraints have the same environment (unchecked). * \arg x should contain (at least) size elements. */ tcons1_array& operator= (const tcons1 x[]); /*! Copies the constraints from the vector into the array, changing its size if needed. * * \warning assumes that all constraints have the same environment (unchecked). */ tcons1_array& operator= (const std::vector& x); //@} /* dimension operations */ /* ==================== */ /** @name Dimension operations */ //@{ //! Resizes the array. void resize(size_t size); /*! \brief Extends the environment of all expressions in array. * * \throw std::invalid_argument if e is not a super-environment of that of *this. */ void extend_environment(const environment& e); //@} /* access */ /* ====== */ /** @name Accesses */ //@{ //! Returns the size of the array. size_t size() const; //! Returns the environment shared by all constraints (with incremented reference count). environment get_environment() const; //! Returns a reference to the underlying tcons0_array. const tcons0_array& get_tcons0_array() const; //! Returns a (modifiable) reference to the underlying tcons0_array. tcons0_array& get_tcons0_array(); /*! \brief Returns a copy of the constraint at index i. * * \throw std::out_of_range if i exceeds the dimension of the array. */ tcons1 get(size_t i) const; /*! \brief Changes the constraint at index i. * * \warning assumes that x and *this have equal environments. * \throw std::out_of_range if i exceeds the dimension of the array. */ void set(size_t i, const tcons1& x); //@} /* conversion */ /* ========== */ /** @name Conversion */ //@{ //! Returns a copy of the constraints in the form of a vector. operator std::vector() const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ /*! \brief Printing. * * \throw std::invalid_argument an underlying expression is missing, or an * auxiliary scalar is missing (for modulo constraint). */ friend std::ostream& operator<< (std::ostream& os, const tcons1_array& s); //! Prints to a C stream. void print(FILE* stream=stdout) const; //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. const ap_tcons1_array_t* get_ap_tcons1_array_t() const; //! Returns a pointer to the internal APRON object stored in *this. ap_tcons1_array_t* get_ap_tcons1_array_t(); //@} }; #include "apxx_tcons1_inline.hh" } #endif /* __APXX_TCONS1_HH */ apron-dist-0.9.10/apron/apronxx/apxx_ppl_inline.hh0000640014525101416610000000136510703144237022103 0ustar bjeannetpopart/* -*- C++ -*- * apxx_ppl_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library. As it includes both APRON and PPL files, it is released under GPL license. Please read the ppl/COPYING file packaged in the distribution. */ inline ppl_poly_manager::ppl_poly_manager(bool strict) : manager(ap_ppl_poly_manager_alloc(strict)) {} inline ppl_grid_manager::ppl_grid_manager() : manager(ap_ppl_grid_manager_alloc()) {} inline manager& ppl_poly_manager::operator=(const manager& m) { return manager::operator=(m); } inline manager& ppl_grid_manager::operator=(const manager& m) { return manager::operator=(m); } apron-dist-0.9.10/apron/apronxx/apxx_coeff_inline.hh0000640014525101416610000002337111006063143022364 0ustar bjeannetpopart/* -*- C++ -*- * apxx_coeff_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ /* ================================= */ /* coeff */ /* ================================= */ /* constructors */ /* ============ */ inline coeff::coeff() { ap_coeff_init(&c, AP_COEFF_SCALAR); } inline coeff::coeff(const coeff& x) { ap_coeff_init(&c, x.c.discr); ap_coeff_set(&c, const_cast(x.get_ap_coeff_t())); } /* scalars */ inline coeff::coeff(const scalar& x) { ap_coeff_init(&c, AP_COEFF_SCALAR); ap_coeff_set_scalar(&c, const_cast(x.get_ap_scalar_t())); } inline coeff::coeff(int x) { ap_coeff_init(&c, AP_COEFF_SCALAR); ap_coeff_set_scalar_int(&c, x); } inline coeff::coeff(long x) { ap_coeff_init(&c, AP_COEFF_SCALAR); ap_coeff_set_scalar_int(&c, x); } inline coeff::coeff(double x) { ap_coeff_init(&c, AP_COEFF_SCALAR); ap_coeff_set_scalar_double(&c, x); } inline coeff::coeff(const frac& x) { ap_coeff_init(&c, AP_COEFF_SCALAR); ap_coeff_set_scalar_frac(&c, x.num, x.den); } inline coeff::coeff(const mpq_class& x) { ap_coeff_init(&c, AP_COEFF_SCALAR); ap_coeff_set_scalar_mpq(&c, const_cast(x).get_mpq_t()); } inline coeff::coeff(mpfr_t x) { ap_coeff_init(&c, AP_COEFF_SCALAR); ap_coeff_set_scalar_mpfr(&c,x); } /* intervals */ inline coeff::coeff(const interval& x) { ap_coeff_init(&c, AP_COEFF_INTERVAL); ap_coeff_set_interval(&c, const_cast(x.get_ap_interval_t())); } inline coeff::coeff(const scalar& inf, const scalar& sup) { ap_coeff_init(&c, AP_COEFF_INTERVAL); ap_coeff_set_interval_scalar(&c, const_cast(inf.get_ap_scalar_t()), const_cast(sup.get_ap_scalar_t())); } inline coeff::coeff(int inf, int sup) { ap_coeff_init(&c, AP_COEFF_INTERVAL); ap_coeff_set_interval_int(&c, inf, sup); } inline coeff::coeff(long inf, long sup) { ap_coeff_init(&c, AP_COEFF_INTERVAL); ap_coeff_set_interval_int(&c, inf, sup); } inline coeff::coeff(double inf, double sup) { ap_coeff_init(&c, AP_COEFF_INTERVAL); ap_coeff_set_interval_double(&c, inf, sup); } inline coeff::coeff(const frac& inf, const frac& sup) { ap_coeff_init(&c, AP_COEFF_INTERVAL); ap_coeff_set_interval_frac(&c, inf.num, inf.den, sup.num, sup.den); } inline coeff::coeff(const mpq_class& inf, const mpq_class& sup) { ap_coeff_init(&c, AP_COEFF_INTERVAL); ap_coeff_set_interval_mpq(&c, const_cast(inf).get_mpq_t(), const_cast(sup).get_mpq_t()); } inline coeff::coeff(mpfr_t inf, mpfr_t sup) { ap_coeff_init(&c, AP_COEFF_INTERVAL); ap_coeff_set_interval_mpfr(&c,inf,sup); } inline coeff::coeff(top t) { ap_coeff_init(&c, AP_COEFF_INTERVAL); ap_coeff_set_interval_top(&c); } inline coeff::coeff(bottom t) { ap_coeff_init(&c, AP_COEFF_INTERVAL); ap_coeff_set_interval_int(&c, 1, -1); } /* destructor */ /* ========== */ inline coeff::~coeff() { ap_coeff_clear(&c); } /* assignments */ /* =========== */ inline coeff& coeff::operator= (const coeff& x) { ap_coeff_set(&c, const_cast(x.get_ap_coeff_t())); return *this; } inline coeff& coeff::operator= (const scalar& x) { ap_coeff_set_scalar(&c, const_cast(x.get_ap_scalar_t())); return *this; } inline coeff& coeff::operator= (int x) { ap_coeff_set_scalar_int(&c, x); return *this; } inline coeff& coeff::operator= (long x) { ap_coeff_set_scalar_int(&c, x); return *this; } inline coeff& coeff::operator= (double x) { ap_coeff_set_scalar_double(&c, x); return *this; } inline coeff& coeff::operator= (const frac& x) { ap_coeff_set_scalar_frac(&c, x.num, x.den); return *this; } inline coeff& coeff::operator= (const mpq_class& x) { ap_coeff_set_scalar_mpq(&c, const_cast(x).get_mpq_t()); return *this; } inline coeff& coeff::operator= (mpfr_t x) { ap_coeff_set_scalar_mpfr(&c, x); return *this; } inline coeff& coeff::operator= (const interval& x) { ap_coeff_set_interval(&c, const_cast(x.get_ap_interval_t())); return *this; } inline coeff& coeff::operator= (top t) { ap_coeff_set_interval_top(&c); return *this; } inline coeff& coeff::operator= (bottom t) { ap_coeff_set_interval_int(&c, 1, -1); return *this; } /* access */ /* ====== */ inline ap_coeff_discr_t coeff::get_discr() const { return c.discr; } inline scalar& coeff::get_scalar() { if (c.discr!=AP_COEFF_SCALAR) throw(bad_discriminant("coeff::get_scalar")); return reinterpret_cast(*c.val.scalar); } inline const scalar& coeff::get_scalar() const { if (c.discr!=AP_COEFF_SCALAR) throw(bad_discriminant("coeff::get_scalar")); return reinterpret_cast(*c.val.scalar); } inline interval& coeff::get_interval() { if (c.discr!=AP_COEFF_INTERVAL) throw(bad_discriminant("coeff::get_interval")); return reinterpret_cast(*c.val.interval); } inline const interval& coeff::get_interval() const { if (c.discr!=AP_COEFF_INTERVAL) throw(bad_discriminant("coeff::get_interval")); return reinterpret_cast(*c.val.interval); } inline coeff&coeff::set(const coeff& x) { ap_coeff_set(&c, const_cast(x.get_ap_coeff_t())); return *this; } inline coeff&coeff::set(const scalar& x) { ap_coeff_set_scalar(&c, const_cast(x.get_ap_scalar_t())); return *this; } inline coeff&coeff::set(int x) { ap_coeff_set_scalar_int(&c, x); return *this; } inline coeff&coeff::set(long x) { ap_coeff_set_scalar_int(&c, x); return *this; } inline coeff&coeff::set(double x) { ap_coeff_set_scalar_double(&c, x); return *this; } inline coeff&coeff::set(const frac& x) { ap_coeff_set_scalar_frac(&c, x.num, x.den); return *this; } inline coeff&coeff::set(const mpq_class& x) { ap_coeff_set_scalar_mpq(&c, const_cast(x).get_mpq_t()); return *this; } inline coeff&coeff::set(mpfr_t x) { ap_coeff_set_scalar_mpfr(&c, x); return *this; } inline coeff&coeff::set(const interval& x) { ap_coeff_set_interval(&c, const_cast(x.get_ap_interval_t())); return *this; } inline coeff&coeff::set(const scalar& inf, const scalar& sup) { ap_coeff_set_interval_scalar(&c, const_cast(inf.get_ap_scalar_t()), const_cast(sup.get_ap_scalar_t())); return *this; } inline coeff&coeff::set(int inf, int sup) { ap_coeff_set_interval_int(&c, inf, sup); return *this; } inline coeff&coeff::set(long inf, long sup) { ap_coeff_set_interval_int(&c, inf, sup); return *this; } inline coeff&coeff::set(double inf, double sup) { ap_coeff_set_interval_double(&c, inf, sup); return *this; } inline coeff&coeff::set(const frac& inf, const frac& sup) { ap_coeff_set_interval_frac(&c, inf.num, inf.den, sup.num, sup.den); return *this; } inline coeff&coeff::set(const mpq_class& inf, const mpq_class& sup) { ap_coeff_set_interval_mpq(&c, const_cast(inf).get_mpq_t(), const_cast(sup).get_mpq_t()); return *this; } inline coeff&coeff::set(mpfr_t inf, mpfr_t sup) { ap_coeff_set_interval_mpfr(&c, inf, sup); return *this; } inline coeff&coeff::set(top t) { ap_coeff_set_interval_top(&c); return *this; } inline coeff&coeff::set(bottom t) { ap_coeff_set_interval_int(&c, 1, -1); return *this; } /* swap */ inline void swap(coeff& a, coeff &b) { ap_coeff_swap(&a.c, &b.c); } /* print */ /* ===== */ inline std::ostream& operator<< (std::ostream& os, const coeff& s) { switch (s.c.discr) { case AP_COEFF_SCALAR: return os << *(reinterpret_cast(s.c.val.scalar)); case AP_COEFF_INTERVAL: return os << *(reinterpret_cast(s.c.val.interval)); default: return os; } } inline void coeff::print(FILE* stream) const { ap_coeff_fprint(stream, const_cast(&c)); } /* tests */ /* ===== */ inline bool coeff::is_zero() const { return ap_coeff_zero(const_cast(&c)); } inline int cmp(const coeff& a, const coeff& b) { return ap_coeff_cmp(const_cast(&a.c), const_cast(&b.c)); } /* inline bool operator<= (const coeff& a, const coeff& b) { int x = ap_coeff_cmp(const_cast(&a.c), const_cast(&b.c)); printf("%i\n",x); return x>=-1 && x<=0; } inline bool operator>= (const coeff& a, const coeff& b) { int x = ap_coeff_cmp(const_cast(&a.c), const_cast(&b.c)); return x>=0 && x<=1; } inline bool operator< (const coeff& a, const coeff& b) { return ap_coeff_cmp(const_cast(&a.c), const_cast(&b.c)) == -1; } inline bool operator> (const coeff& a, const coeff& b) { return ap_coeff_cmp(const_cast(&a.c), const_cast(&b.c)) == 1; } */ inline bool operator== (const coeff& a, const coeff& b) { return ap_coeff_equal(const_cast(&a.c), const_cast(&b.c)); } inline bool operator!= (const coeff& a, const coeff& b) { return !ap_coeff_equal(const_cast(&a.c), const_cast(&b.c)); } /* other operators */ /* =============== */ inline void coeff::reduce() { ap_coeff_reduce(&c); } inline void coeff::neg() { ap_coeff_neg(&c, &c); } inline coeff coeff::operator- () const { coeff r = *this; r.neg(); return r; } inline long coeff::hash() const { return ap_coeff_hash(const_cast(&c)); } /* C-level compatibility */ inline const ap_coeff_t* coeff::get_ap_coeff_t() const { return &c; } inline ap_coeff_t* coeff::get_ap_coeff_t() { return &c; } apron-dist-0.9.10/apron/apronxx/apronxx.cc0000640014525101416610000000771710703144237020406 0ustar bjeannetpopart/* * apronxx.cc * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #include "apronxx.hh" namespace apron { const abstract0 abstract0::null(NULL); const abstract1 abstract1::null((ap_abstract1_t){NULL,NULL}); const int varname::xindex = std::ios_base::xalloc(); static const char* apxx_texpr_op_name[] = { "+", "-", "*", "/", "%", /* binary */ "-", "cast", "sqrt", /* unary */ }; static const int apxx_texpr_op_precedence[] = { 1, 1, 2, 2, 2, /* binary */ 3, 4, 4 /* unary */ }; static const char* apxx_texpr_rtype_name[] = { "", "i", "f", "d", "l", "q", }; static const char* apxx_texpr_rdir_name[] = { "n", "0", "+oo", "-oo", "?", "", }; /* node induces some rounding (to float or integer) */ static inline bool apxx_texpr0_node_exact(ap_texpr0_node_t* a) { if (a->op==AP_TEXPR_NEG || a->op==AP_TEXPR_MOD || a->type==AP_RTYPE_REAL) return true; return false; } static inline int apxx_texpr0_precedence(ap_texpr0_t* a) { if (!a || a->discr!=AP_TEXPR_NODE) return apxx_texpr_op_precedence[AP_TEXPR_NEG]; return apxx_texpr_op_precedence[a->val.node->op]; } static void apxx_texpr0_node_ostream(std::ostream& os, ap_texpr0_node_t* a, std::vector* names) { int prec = apxx_texpr_op_precedence[a->op]; /* left argument (if binary) */ if (a->exprB) { int prec2 = apxx_texpr0_precedence(a->exprA); if (prec2exprA, names); if (prec2exprB) os << " "; os << apxx_texpr_op_name[a->op]; if (!apxx_texpr0_node_exact(a)) os << "_" << apxx_texpr_rtype_name[a->type] << "," << apxx_texpr_rdir_name[a->dir]; /* right argument */ ap_texpr0_t* arg = a->exprB ? a->exprB : a->exprA; int prec2 = apxx_texpr0_precedence(arg); if (a->exprB) os << " "; if (prec2<=prec) os << "("; apxx_texpr0_ostream(os,arg,names); if (prec2<=prec) os << ")"; } void apxx_texpr0_ostream(std::ostream& os, ap_texpr0_t* a, std::vector* names) { if (!a) return; switch (a->discr) { case AP_TEXPR_CST: os << reinterpret_cast(a->val.cst); break; case AP_TEXPR_DIM: if (names && a->val.dim < names->size()) os << (*names)[a->val.dim]; else os << "x" << a->val.dim; break; case AP_TEXPR_NODE: apxx_texpr0_node_ostream(os, a->val.node, names); break; default: assert(false); } } static void apxx_texpr0_env_node_ostream(std::ostream& os, ap_environment_t* env, ap_texpr0_node_t* a) { int prec = apxx_texpr_op_precedence[a->op]; /* left argument (if binary) */ if (a->exprB) { int prec2 = apxx_texpr0_precedence(a->exprA); if (prec2exprA); if (prec2exprB) os << " "; os << apxx_texpr_op_name[a->op]; if (!apxx_texpr0_node_exact(a)) os << "_" << apxx_texpr_rtype_name[a->type] << "," << apxx_texpr_rdir_name[a->dir]; /* right argument */ ap_texpr0_t* arg = a->exprB ? a->exprB : a->exprA; int prec2 = apxx_texpr0_precedence(arg); if (a->exprB) os << " "; if (prec2<=prec) os << "("; apxx_texpr0_env_ostream(os, env, arg); if (prec2<=prec) os << ")"; } void apxx_texpr0_env_ostream(std::ostream& os, ap_environment_t* env, ap_texpr0_t* a) { if (!a) return; switch (a->discr) { case AP_TEXPR_CST: os << reinterpret_cast(a->val.cst); break; case AP_TEXPR_DIM: { ap_var_t v = ap_environment_var_of_dim(env, a->val.dim); if (v) { char* s = ap_var_operations->to_string(v); os << s; free(s); } else os << "?"; break; } case AP_TEXPR_NODE: apxx_texpr0_env_node_ostream(os, env, a->val.node); break; default: assert(false); } } } apron-dist-0.9.10/apron/apronxx/apxx_texpr0.hh0000640014525101416610000007111711006063143021167 0ustar bjeannetpopart/* -*- C++ -*- * apxx_texpr0.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_TEXPR0_HH #define __APXX_TEXPR0_HH #include #include "ap_texpr0.h" #include "ap_linearize.h" #include "apxx_linexpr0.hh" #include "apxx_environment.hh" namespace apron { class abstract0; //! Represents a dimension (i.e., variable by index) in an expression tree. class dim { public: ap_dim_t d; //!< Dimension index. //! Standard constructor. dim(ap_dim_t d); /*! \brief Extract dimension corresponding to variable name in given environment. * * \throw std::invalid_argument if the variable does not exist. */ dim(const environment& e, const var& v); }; //! Whether the operator is unary. bool is_unop(ap_texpr_op_t op); //! Whether the operator is binary. bool is_binop(ap_texpr_op_t op); /* ================================= */ /* texpr0 */ /* ================================= */ /*! \brief Level 0 arbitrary expression tree (ap_texpr0_t wrapper). * * A texpr0 represents an expression tree. * Leaves include dimensions (i.e., variables by index) as well as constants (coefficients). * Binary operators include addition, subtraction, multiplication, division, and modulo. * Unary operators include opposite, square root, and typecast. * Additionally, all operators are tagged with a destination type: perfect integers, reals, * or floating-point numbers (of various bit-size). * For integer and floating-point operators, a rounding direction can be specified * (as well as 'any direction'). * The concrete semantics of all operators is to first perform the operation on perfect reals * (typecast being the identity operator here), and then round the result to the destination type * in the specified direction. * * A texpr0 manages a whole expression tree: assignment, copy, and destruction are deep (recursive). * * Complex expression trees can be constructed using the standard +, -, *, /, % operators, as well as * functions such as add, mul, div, etc. (allowing to set the destination type and rounding direction). * \code * texpr0 x = dim(1) + dim(2) * 5; * texpr0 y = add(sqrt(x), x, AP_RTYPE_FLOAT); * \endcode * Temporaries created by the operators have the texpr0::builder type. * See the texpr0::builder class documentation for the details on operator arguments. * * Expression trees can be visited and/or modified using the texpr0::iterator type. */ class texpr0 : public use_malloc { protected: ap_texpr0_t l; //!< Structure managed by APRON. //! Internal use only. Shallow copy. texpr0(ap_texpr0_t* x); //! Internal use only. Shallow copy. void init_from(ap_texpr0_t* x); public: class builder; class iterator; class const_iterator; /* constructors */ /* ============ */ /** @name Constructors */ //@{ /*! \brief Makes an expression tree from a temporary (performing a deep copy). * * A deep copy is performed so that, after the assignment, temporaries can be safely destroyed * and we have a private copy of all formerly aliased sub-trees. */ texpr0(const builder& x); //! Makes a (deep) copy of the expression tree. texpr0(const texpr0& x); //! Makes a (deep) copy of the expression tree. texpr0(const const_iterator& x); /*! \brief Makes an expression tree from a linear expression (copying coefficients). * * Real-valued addition and multiplication operators are used (i.e., no rounding). */ texpr0(const linexpr0& l); /*! \brief Makes a (deep) copy of the expression, and then add or remove some dimensions. * * \arg \c add whether to add or remove dimensions. */ texpr0(const texpr0& x, const dimchange& d, bool add=true); //! Makes a (deep) copy of the expression, and then permutes dimensions. texpr0(const texpr0& x, const dimperm& d); //! Makes a (deep) copy of x and substitutes each occurrence of dim with (a fresh copy of) dst. texpr0(const texpr0& x, ap_dim_t dim, const texpr0& dst); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ //! Frees the memory occupied by the expression (and, recursively, all sub-expressions). ~texpr0(); //@} /* assignment */ /* ========== */ /** @name Assignments */ //@{ //! Makes a (deep) copy of the expression. texpr0& operator=(const texpr0& x); //! Makes a (deep) copy of the expression. texpr0& operator=(const const_iterator& x); //! Assigns from a temporary expression, performing a deep copy and deleting the previous value of *this. texpr0& operator=(const builder& x); /*! \brief Makes *this equal to the linear expression x (coefficients are copied), deleting the previous value of *this. * * Real-valued addition and multiplication operators are used (i.e., no rounding). */ texpr0& operator= (const linexpr0& x); //@} /* iterators */ /* ========= */ /** @name Iterators */ //@{ /*! \brief Iterators to traverse a constant expression tree. * * For lack of better name, an 'iterator' object is used to reference an * expression node within a constant expression tree. * Through the 'iterator', nodes can be examined. * However, 'iterators' traverse the tree in a functional way: you spawn new * const_iterator objects for left and right children. * * Use the iterator class if you also wish to mutate an expression. * * \warning You can no longer use a const_iterator after the corresponding node has been discarded * (i.e., part of a destroyed expression, part of a sub-expression substituted away, etc.). * However, you can safely destroy the const_iterator after the node has been destroyed * (provided you do not use it in the meantime). * */ class const_iterator { protected: ap_texpr0_t* l; //! Internal use only. const_iterator(ap_texpr0_t* l); friend class texpr0; friend class tcons0; friend class texpr1; friend class tcons1; public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ //! Starts a new const_iterator at the root of a constant expression tree. const_iterator(const texpr0& e); //! Duplicates the const_iterator. const_iterator(const const_iterator& i); //@} /* access */ /* ====== */ /** @name Access */ //@{ /*! \brief Returns the node kind. * * \return \c AP_TEXPR_CST for a constant node, \c AP_TEXPR_DIM for a dimension, * and \c AP_TEXPR_NODE for an operator node. */ ap_texpr_discr_t get_discr() const; /*! \brief Returns a reference to the coefficient of a constant node. * * \throw bad_discriminant if the node is not a constant leaf. */ const coeff& get_coeff() const; /*! \brief Returns the dimension of a dimension node. * * \throw bad_discriminant if the node is not a dimension node. */ ap_dim_t get_dim() const; /*! \brief Returns the operator kind of an operator node. * * \return either \c AP_TEXPR_ADD, \c AP_TEXPR_SUB, \c AP_TEXPR_MUL, \c AP_TEXPR_DIV, \c AP_TEXPR_MOD, * \c AP_TEXPR_NEG, \c AP_TEXPR_CAST, or \c AP_TEXPR_SQRT. * \throw bad_discriminant if the node is not an operator node. */ ap_texpr_op_t get_op() const; /*! \brief Returns the destination type of an operator node. * * \return either \c AP_RTYPE_REAL, \c AP_RTYPE_INT, \c AP_RTYPE_SINGLE (32-bit), \c AP_RTYPE_DOUBLE (64-bit), * \c AP_RTYPE_EXTENDED (80-bit), or \c AP_RTYPE_QUAD (128-bit). * \throw bad_discriminant if the node is not an operator node. */ ap_texpr_rtype_t get_rtype() const; /*! \brief Returns the rounding direction of an operator node. * * \return either \c AP_RDIR_NEAREST, \c AP_RDIR_ZERO, \c AP_RDIR_UP, \c AP_RDIR_DOWN, or \c AP_RDIR_RND. * \throw bad_discriminant if the node is not an operator node. */ ap_texpr_rdir_t get_rdir() const; //@} /* traversal */ /* ========= */ /** @name Traversal */ //@{ //! Resets the const_iterator at position i. const_iterator& operator=(const const_iterator& i); /*! \brief Constructs a const_iterator to the only or left sub-expression of an operator node. * * \throw bad_discriminant if the node is not an operator node. */ const_iterator child() const; /*! \brief Constructs a const_iterator to the only of left sub-expression of an operator node. * * (Identical to child()). * \throw bad_discriminant if the node is not an operator node. */ const_iterator left() const; /*! \brief Constructs a const_iterator to the right sub-expression argument of a binary operator node. * * \throw bad_discriminant if the node is not an operator node. * \throw std::out_of_range if the operator node is not binary. */ const_iterator right() const; //@} /* tests, size, dimensions */ /* ======================= */ /** @name Tests, size, dimensions */ //@{ //! Whether two expressions are syntactically, structurally equal. bool equal(const texpr0& x) const; //! Whether the expression is a single coefficient node with 0 value. bool is_zero() const; //! Returns the depth of the expression tree (counting only operator nodes). size_t depth() const; //! Returns the number of operator nodes in the expression tree. size_t size() const; //! Returns the maximal dimension occurring in the expression (or 0 if there is no variable). ap_dim_t max_dim() const; //! Whether the given dimension occurs in the expression. bool has_dim(ap_dim_t d) const; /*! \brief Returns a list of all dimensions occurring in the expression * (in strict increasing order) */ std::vector dimlist() const; //! Whether the expression is constant (i.e., has no dimension leaves). bool is_interval_cst() const; //! Whether the expression is linear and there is no rounding. bool is_interval_linear() const; //! Whether the expression is polynomial and there is no rounding. bool is_interval_polynomial() const; //! Whether the expression is a polynomial fraction and there is no rounding. bool is_interval_polyfrac() const; //! Whether all occurring constants are scalar. bool is_scalar() const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ /*! \brief Printing. * * Variable naming can be configured through the varname stream modifier. */ friend std::ostream& operator<< (std::ostream& os, const const_iterator& s); //! Prints to a C stream. void print(char** name_of_dim = NULL, FILE* stream=stdout) const; //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. ap_texpr0_t* get_ap_texpr0_t(); //! Returns a pointer to the internal APRON object stored in *this. const ap_texpr0_t* get_ap_texpr0_t() const; //@} }; /*! \brief Iterators to traverse and mutate an expression tree. * * As const_iterator, but can be used to modify as well as traverse nodes. */ class iterator : public const_iterator { protected: //! Internal use only. iterator(ap_texpr0_t* l); friend class tcons0; friend class texpr1; friend class tcons1; public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ //! Starts a new iterator at the root of the tree. iterator(texpr0& e); //! Duplicates the iterator. iterator(const iterator& i); //@} /* substitution */ /* ============ */ /** @name Expression substitutions */ //@{ /*! \brief Replace the sub-expression at the iterator position with a (deep) copy of c. * * The iterator is still valid after substitution (it points to the sub-expression copy). * However, any iterator in the discarded part becomes invalid. */ iterator& operator= (const builder& c); //@} /* access */ /* ====== */ /** @name Access */ //@{ /*! \brief Returns a (modifiable) reference to the coefficient of a constant node. * * \throw bad_discriminant if the node is not a constant leaf. */ coeff& get_coeff() const; /*! \brief Returns a (modifiable) reference to the dimension of a dimension node. * * \throw bad_discriminant if the node is not a dimension node. */ ap_dim_t& get_dim() const; /*! \brief Returns a (modifiable) reference to the operator kind of an operator node. * * \return either \c AP_TEXPR_ADD, \c AP_TEXPR_SUB, \c AP_TEXPR_MUL, \c AP_TEXPR_DIV, \c AP_TEXPR_MOD, * \c AP_TEXPR_NEG, \c AP_TEXPR_CAST, or \c AP_TEXPR_SQRT. * \throw bad_discriminant if the node is not an operator node. */ ap_texpr_op_t& get_op() const; /*! \brief Returns a (modifiable) reference to the destination type of an operator node. * * \return either \c AP_RTYPE_REAL, \c AP_RTYPE_INT, \c AP_RTYPE_SINGLE (32-bit), \c AP_RTYPE_DOUBLE (64-bit), * \c AP_RTYPE_EXTENDED (80-bit), or \c AP_RTYPE_QUAD (128-bit). * \throw bad_discriminant if the node is not an operator node. */ ap_texpr_rtype_t& get_rtype() const; /*! \brief Returns a (modifiable) reference to the rounding direction of an operator node. * * \return either \c AP_RDIR_NEAREST, \c AP_RDIR_ZERO, \c AP_RDIR_UP, \c AP_RDIR_DOWN, or \c AP_RDIR_RND. * \throw bad_discriminant if the node is not an operator node. */ ap_texpr_rdir_t& get_rdir() const; //@} /* traversal */ /* ========= */ /** @name Traversal */ //@{ //! Resets the iterator at position i. iterator& operator=(const iterator& i); /*! \brief Constructs an iterator to the only or left sub-expression of an operator node. * * \throw bad_discriminant if the node is not an operator node. */ iterator child() const; /*! \brief Constructs an iterator to the only of left sub-expression of an operator node. * * (Identical to child()). * \throw bad_discriminant if the node is not an operator node. */ iterator left() const; /*! \brief Constructs an iterator to the right sub-expression argument of a binary operator node. * * \throw bad_discriminant if the node is not an operator node. * \throw std::out_of_range if the operator node is not binary. */ iterator right() const; //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. ap_texpr0_t* get_ap_texpr0_t(); //! Returns a pointer to the internal APRON object stored in *this. const ap_texpr0_t* get_ap_texpr0_t() const; //@} }; //! Returns a new iterator at the root of a constant expression tree. const_iterator root() const; //! Returns a new iterator at the root of a mutable expression tree. iterator root(); //@} /* builders */ /* ======== */ /** @name Builders */ //@{ /*! \brief Temporary expression nodes used when constructing a texpr0. * * Builders allow constructing expression trees one node at a time using overloaded * operators (+, -, *, /, %) and friend functions (add, sub, mul, div, mod, neg, sqrt, cast, * unary, binary). * * Each builder object manages a single node which is allocated by the constructor and destroyed * by the destructor, without considering potential sub-nodes. * As their usage is temporary (they are normally destructed at the end of full expressions), * assignment, copy, and destruction can be shallow, which results in improved efficiency wrt. * using texpr0 as temporaries. * * You should not create variables of type build, nor define functions that return or take * builder objects as arguments. */ class builder : public use_malloc { friend class texpr1; protected: ap_texpr0_t* l; //! Not to be used. (Temporaries are not to be re-assigned). builder& operator= (const builder& x) { assert(0); return *this; } //! Internal use only: makes a shallow copy, copying only the root node. void init_from(ap_texpr0_t* x); //! Internal use only: makes a shallow copy, copying only the root node. builder(ap_texpr0_t* x); public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ //! Makes a shallow copy, copying only the root node. Sub-expressions are aliased, not copied. builder(const builder& x); //! Makes a shallow copy, copying only the root node. Sub-expressions are aliased, not copied. builder(const const_iterator& x); //! Makes a shallow copy, copying only the root node. Sub-expressions are aliased, not copied. builder(const texpr0& x); //! Makes a constant leaf from a scalar or interval coefficient (copied). builder(const coeff& x); //! Makes a constant scalar leaf from a scalar (copied). builder(const scalar& x); //! Makes a constant scalar leaf from a MPQ (copied). builder(const mpq_class& x); //! Makes a constant scalar leaf from a MPFR (copied). builder(mpfr_t x); //! Makes a constant scalar MPQ leaf from an integer. builder(int x); //! Makes a constant scalar MPQ leaf from an integer. builder(long x); //! Makes a constant scalar double leaf from a double. builder(double x); //! Makes a constant scalar MPQ leaf from a fraction with integer coefficients. builder(const frac& x); //! Makes a constant interval leaf from an interval (copied). builder(const interval& x); //! Makes a constant interval leaf from two scalar bounds (copied). builder(const scalar& inf, const scalar& sup); //! Makes a constant interval leaf from two MPQ bounds (copied). builder(const mpq_class& inf, const mpq_class& sup); //! Makes a constant interval leaf from two MPFR bounds (copied). builder(mpfr_t inf, mpfr_t sup); //! Makes a constant interval leaf from two integer bounds (converted to MPQ). builder(int inf, int sup); //! Makes a constant interval leaf from two integer bounds (converted to MPQ). builder(long inf, long sup); //! Makes a constant interval leaf from two double bounds. builder(double inf, double sup); //! Makes a constant interval leaf from two fraction bounds (converted to MPQ). builder(const frac& inf, const frac& sup); //! Makes a constant interval leaf equal to ]-oo;+oo[. builder(top t); //! Makes a dimension leaf (i.e., variable of specified index). builder(dim d); //! Makes a unary expression node. builder(ap_texpr_op_t op, const builder& argA, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir); //! Makes a binary expression node. builder(ap_texpr_op_t op, const builder& argA, const builder& argB, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ //! Frees the memory occupied by the node, not its sub-expressions. ~builder(); //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. ap_texpr0_t* get_ap_texpr0_t(); //! Returns a pointer to the internal APRON object stored in *this. const ap_texpr0_t* get_ap_texpr0_t() const; //@} /* 'Intelligent' constructors */ /* ========================== */ /** @name 'Intelligent' constructors */ //@{ /*! \brief Makes a unary expression node. * * Creates only one node. The argument expression is aliased, not copied. * * \arg \c op should be a unary operator: negation (\c AP_TEXPR_NEG), typecast (\c AP_TEXPR_CAST), * or square root (\c AP_TEXPR_SQRT). * \arg \c argA should point to the argument expression. * \arg \c rtype is the destination type (for rounding): reals (\c AP_RTYPE_REAL, means no rounding), * perfect integers (\c AP_RTYPE_INT), 32-bit single precision (\c AP_RTYPE_SINGLE), 64-bit double precision * (\c AP_RTYPE_DOUBLE), 80-bit extended precision (\c AP_RTYPE_EXTENDED), or * 128-bit quadruple precision (\c AP_RTYPE_QUAD). * \arg \c rdir is the rounding direction: to nearest (\c AP_RDIR_NEAREST), truncation (\c AP_RDIR_ZERO), * towards +oo (\c AP_RDIR_UP), towards -oo (\c AP_RDIR_DOWN), or non-deterministic (\c AP_RDIR_RND). * \throw std::invalid_argument if \c op is not a unary operator. */ friend builder unary(ap_texpr_op_t op, const builder& a, ap_texpr_rtype_t rtype = AP_RTYPE_REAL, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); /*! \brief Makes a binary expression node. * * Creates only one node. The argument expressions is aliased, not copied. * * \arg \c op should be a binary operator: addition (\c AP_TEXPR_ADD), subtraction (\c AP_TEXPR_SUB), * multiplication (\c AP_TEXPR_MUL), division (\c AP_TEXPR_DIV), or modulo (\c AP_TEXPR_MOD). * \arg \c argA should point to the left argument expression. * \arg \c argB should point to the right argument expression. * \arg \c rtype is the destination type (for rounding): reals (\c AP_RTYPE_REAL, means no rounding), * perfect integers (\c AP_RTYPE_INT), 32-bit single precision (\c AP_RTYPE_SINGLE), 64-bit double precision * (\c AP_RTYPE_DOUBLE), 80-bit extended precision (\c AP_RTYPE_EXTENDED). * \arg \c rdir is the rounding direction: to nearest (\c AP_RDIR_NEAREST), truncation (\c AP_RDIR_ZERO), * towards +oo (\c AP_RDIR_UP), towards -oo (\c AP_RDIR_DOWN), or non-deterministic (\c AP_RDIR_RND). * \throw std::invalid_argument if \c op is not a binary operator. */ friend builder binary(ap_texpr_op_t op, const builder& a, const builder& b, ap_texpr_rtype_t rtype = AP_RTYPE_REAL, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); //! Makes an \c AP_TEXPR_ADD expression node. friend builder add(const builder& a, const builder& b, ap_texpr_rtype_t rtype = AP_RTYPE_REAL, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); //! Makes an \c AP_TEXPR_SUB expression node. friend builder sub(const builder& a, const builder& b, ap_texpr_rtype_t rtype = AP_RTYPE_REAL, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); //! Makes an \c AP_TEXPR_MUL expression node. friend builder mul(const builder& a, const builder& b, ap_texpr_rtype_t rtype = AP_RTYPE_REAL, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); //! Makes an \c AP_TEXPR_DIV expression node. friend builder div(const builder& a, const builder& b, ap_texpr_rtype_t rtype = AP_RTYPE_REAL, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); //! Makes an \c AP_TEXPR_MOD expression node. friend builder mod(const builder& a, const builder& b, ap_texpr_rtype_t rtype = AP_RTYPE_REAL, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); //! Makes an \c AP_TEXPR_NEG expression node. friend builder neg(const builder& a, ap_texpr_rtype_t rtype = AP_RTYPE_REAL, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); //! Makes an \c AP_TEXPR_CAST expression node. friend builder cast(const builder& a, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); //! Makes an \c AP_TEXPR_CAST expression node to \c AP_RTYPE_INT type rounded towards \c AP_RDIR_DOWN. friend builder floor(const builder& a); //! Makes an \c AP_TEXPR_CAST expression node to \c AP_RTYPE_INT type rounded towards \c AP_RDIR_UP. friend builder ceil(const builder& a); //! Makes an \c AP_TEXPR_CAST expression node to \c AP_RTYPE_INT type rounded towards \c AP_RDIR_ZERO. friend builder trunc(const builder& a); //! Makes an \c AP_TEXPR_SQRT expression node. friend builder sqrt(const builder& a, ap_texpr_rtype_t rtype = AP_RTYPE_REAL, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); //! Makes a copy of the node. friend builder operator+(const builder& a); //! Makes a \c AP_TEXPR_NEG expression node using \c AP_RTYPE_REAL type (no rounding). friend builder operator-(const builder& a); //! Makes a \c AP_TEXPR_ADD expression node using \c AP_RTYPE_REAL type (no rounding). friend builder operator+(const builder& a, const builder& b); //! Makes a \c AP_TEXPR_SUB expression node using \c AP_RTYPE_REAL type (no rounding). friend builder operator-(const builder& a, const builder& b); //! Makes a \c AP_TEXPR_MUL expression node using \c AP_RTYPE_REAL type (no rounding). friend builder operator*(const builder& a, const builder& b); //! Makes a \c AP_TEXPR_DIV expression node using \c AP_RTYPE_REAL type (no rounding). friend builder operator/(const builder& a, const builder& b); //! Makes a \c AP_TEXPR_MOD expression node using \c AP_RTYPE_REAL type (no rounding). friend builder operator%(const builder& a, const builder& b); //@} //! Whether the expression is a single coefficient node with 0 value. bool is_zero() const; }; /* print */ /* ===== */ /** @name Printing */ //@{ /*! \brief Printing. * * Variable naming can be configured through the varname stream modifier. */ friend std::ostream& operator<< (std::ostream& os, const texpr0& s); //! Prints to a C stream. void print(char** name_of_dim = NULL, FILE* stream=stdout) const; //@} /* tests, size, dimensions */ /* ======================= */ /** @name Tests, size, dimensions */ //@{ //! Whether two expressions are syntactically, structurally equal. bool equal(const texpr0& x) const; //! Whether the expression is a single coefficient node with 0 value. bool is_zero() const; //! Returns the depth of the expression tree (counting only operator nodes). size_t depth() const; //! Returns the number of operator nodes in the expression tree. size_t size() const; //! Returns the maximal dimension occurring in the expression (or 0 if there is no variable). ap_dim_t max_dim() const; //! Whether the given dimension occurs in the expression. bool has_dim(ap_dim_t d) const; /*! \brief Returns a list of all dimensions occurring in the expression * (in strict increasing order) */ std::vector dimlist() const; //! Whether the expression is constant (i.e., has no dimension leaves). bool is_interval_cst() const; //! Whether the expression is linear and there is no rounding. bool is_interval_linear() const; //! Whether the expression is polynomial and there is no rounding. bool is_interval_polynomial() const; //! Whether the expression is a polynomial fraction and there is no rounding. bool is_interval_polyfrac() const; //! Whether all occurring constants are scalar. bool is_scalar() const; //@} /* operations */ /* ========== */ /** @name Operations */ //@{ //! Substitutes each occurrence of dim with (a fresh copy of) dst. void substitute(ap_dim_t dim, const texpr0& dst); #if 0 /*! \brief Evaluates the expression given an abstract environment. * * \arg \c discr whether to evaluate using double (\c AP_SCALAR_DOUBLE), MPQ (\c AP_SCALAR_MPQ) or MPFR (\c AP_SCALAR_MPFR). * \arg \c pexact if not NULL, sets to true whenever the evaluation was exact * (i.e., not over-approximated). */ interval eval(manager& m, const abstract0& a, ap_scalar_discr_t discr=AP_SCALAR_DOUBLE, bool* pexact=NULL) const; linexpr0 intlinearize(manager& m, const abstract0& a, ap_scalar_discr_t discr=AP_SCALAR_DOUBLE, bool quasilinearize=false, bool* pexact=NULL) const; #endif //! Returns a hash code. long hash() const; //@} /* change of dimension */ /* =================== */ /** @name Changes of dimension */ //@{ //! Adds some dimensions, shifting dimension if needed. void add_dimensions(const dimchange& d); /*! \brief Removes some dimensions, shifting dimension if needed. * * Nodes corresponding to deleted dimensions are replaced with ]-oo;+oo[. */ void remove_dimensions(const dimchange& d); //! Permutes dimensions. void permute_dimensions(const dimperm& d); //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. ap_texpr0_t* get_ap_texpr0_t(); //! Returns a pointer to the internal APRON object stored in *this. const ap_texpr0_t* get_ap_texpr0_t() const; //@} }; #include "apxx_texpr0_inline.hh" } #endif /* __APXX_TEXPR0_HH */ apron-dist-0.9.10/apron/apronxx/apxx_coeff.hh0000640014525101416610000002141311006063143021021 0ustar bjeannetpopart/* -*- C++ -*- * apxx_coeff.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_COEFF_HH #define __APXX_COEFF_HH #include "ap_coeff.h" #include "apxx_scalar.hh" #include "apxx_interval.hh" namespace apron { /* ================================= */ /* coeff */ /* ================================= */ /*! \brief Coefficient (ap_coeff_t wrapper). * * A coeff is either a scalar or an interval. */ class coeff : public use_malloc { protected: ap_coeff_t c; //!< Structure managed by APRON. public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ //! Makes a double scalar coeff equal to 0.0. coeff(); //! Makes a copy of a coeff. coeff(const coeff& x); //! Makes a scalar coeff from a scalar (copied). coeff(const scalar& x); //! Makes a MPQ scalar coeff from a native integer. coeff(int x); //! Makes a MPQ scalar coeff from a native integer. coeff(long x); //! Makes a double scalar coeff from a double. coeff(double x); //! Makes a MPQ scalar coeff from a fraction with native integer coefficients. coeff(const frac& x); //! Makes a MPQ scalar coeff from a MPQ (copied). coeff(const mpq_class& x); //! Makes a MPFR scalar coeff from a MPFR (copied). coeff(mpfr_t x); //! Makes an interval coeff from an interval (copied). coeff(const interval& x); //! Makes an interval coeff from two scalar bounds (copied). coeff(const scalar& inf, const scalar& sup); //! Makes an interval coeff with MPQ bounds from native integer bounds. coeff(int inf, int sup); //! Makes an interval coeff with MPQ bounds from native integer bounds. coeff(long inf, long sup); //! Makes an interval coeff with double bounds from double bounds. coeff(double inf, double sup); //! Makes an interval coeff with MPQ bounds from fractions with native integer coefficients. coeff(const frac& inf, const frac& sup); //! Makes an interval coeff with MPQ bounds from MPQ bounds (copied). coeff(const mpq_class& inf, const mpq_class& sup); //! Makes an interval coeff with MPFR bounds from MPFR bounds (copied). coeff(mpfr_t inf, mpfr_t sup); //! Makes an interval coeff representing ]-oo,+oo[. coeff(top t); //! Makes an empty interval coeff [+1;-1]. coeff(bottom t); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ ~coeff(); //@} /* assignments */ /* =========== */ /** @name Assignments */ //@{ //! Copies the coeff into *this (setting its type and value). coeff& operator= (const coeff& x); //! Copies the scalar into *this, setting its type to scalar coeff. coeff& operator= (const scalar& x); //! Assigns a native integer to *this, setting its type to MPQ scalar coeff. coeff& operator= (int x); //! Assigns a native integer to *this, setting its type to MPQ scalar coeff. coeff& operator= (long x); //! Assigns a double to *this, setting its type to double scalar coeff. coeff& operator= (double x); //! Assigns a native integer fraction to *this, setting its type to MPQ scalar coeff. coeff& operator= (const frac& x); //! Assigns a MPQ to *this, setting its type to MPQ scalar coeff and copying the MPQ. coeff& operator= (const mpq_class& x); //! Assigns a MPFR to *this, setting its type to MPFR scalar coeff and copying the MPFR. coeff& operator= (mpfr_t x); //! Copies the interval into *this, setting its type to interval coeff. coeff& operator= (const interval& x); //! Set *this to the top interval (]-oo;+oo[), setting its type to interval coeff. coeff& operator= (top t); //! Set *this to the empty interval ([+1;-1])., setting its type to interval coeff. coeff& operator= (bottom t); //! Copies the coeff into *this (setting its type and value). \return *this. coeff& set(const coeff& x); //! Copies the scalar into *this, setting its type to scalar coeff. \return *this. coeff& set(const scalar& x); //! Assigns a native integer to *this, setting its type to MPQ scalar coeff. \return *this. coeff& set(int x); //! Assigns a native integer to *this, setting its type to MPQ scalar coeff. \return *this. coeff& set(long x); //! Assigns a double to *this, setting its type to double scalar coeff. \return *this. coeff& set(double x) ; //! Assigns a native integer fraction to *this, setting its type to MPQ scalar coeff. \return *this. coeff& set(const frac& x); //! Assigns a MPQ to *this, setting its type to MPQ scalar coeff and copying the MPQ. \return *this. coeff& set(const mpq_class& x); //! Assigns a MPFR to *this, setting its type to MPFR scalar coeff and copying the MPFR. \return *this. coeff& set(mpfr_t x); //! Copies the interval into *this, setting its type to interval coeff. \return *this. coeff& set(const interval& x); //! Sets *this to an interval coeff with the given scalar bounds (copied). \return *this. coeff& set(const scalar& inf, const scalar& sup); //! Sets *this to an interval coeff with MPQ scalar bounds. \return *this. coeff& set(int inf, int sup); //! Sets *this to an interval coeff with MPQ scalar bounds. \return *this. coeff& set(long inf, long sup); //! Sets *this to an interval coeff with double scalar bounds. \return *this. coeff& set(double inf, double sup); //! Sets *this to an interval coeff with MPQ scalar bounds. \return *this. coeff& set(const frac& inf, const frac& sup); //! Sets *this to an interval coeff with MPQ scalar bounds (copied). \return *this. coeff& set(const mpq_class& inf, const mpq_class& sup); //! Sets *this to an interval coeff with MPFR scalar bounds (copied). \return *this. coeff& set(mpfr_t inf, mpfr_t sup); //! Sets *this to the top interval (]-oo;+oo[), setting its type to interval coeff. \return *this. coeff& set(top t); //! Sets *this to the empty interval ([+1;-1])., setting its type to interval coeff. \return *this. coeff& set(bottom t); //! Swaps the contents and type of both coeff. friend void swap(coeff& a, coeff &b); //@} /* access */ /* ====== */ /** @name Accesses */ //@{ /*! \brief Whether the coeff is a scalar or an interval. * * \return Either \c AP_COEFF_SCALAR or \c AP_COEFF_INTERVAL. */ ap_coeff_discr_t get_discr() const; /*! \brief Returns a (modifiable) reference to the scalar contained in the coeff. * * \throw bad_discriminant when the coeff is not of scalar type */ scalar& get_scalar(); /*! \brief Returns a reference to the scalar contained in the coeff. * * \throw bad_discriminant when the coeff is not of scalar type */ const scalar& get_scalar() const; /*! \brief Returns a (modifiable) reference to the interval contained in the coeff. * * \throw bad_discriminant when the coeff is not of interval type */ interval& get_interval(); /*! \brief Returns a reference to the interval contained in the coeff. * * \throw bad_discriminant when the coeff is not of interval type */ const interval& get_interval() const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ //! Printing. friend std::ostream& operator<< (std::ostream& os, const coeff& s); //! Prints to a C stream. void print(FILE* stream=stdout) const; //@} /* tests */ /* ===== */ /** @name Tests */ //@{ //! Whether the coeff is the scalar 0 or the interval [0;0]. bool is_zero() const; //! Non-total comparison. friend int cmp(const coeff& a, const coeff& b); /* //! Set inclusion. friend bool operator<= (const coeff& a, const coeff& b); //! Set inclusion. friend bool operator>= (const coeff& a, const coeff& b); //! Strict set inclusion. friend bool operator< (const coeff& a, const coeff& b); //! Strict set inclusion. friend bool operator> (const coeff& a, const coeff& b); */ //! Set equality. friend bool operator== (const coeff& a, const coeff& b); //! Set inequality. friend bool operator!= (const coeff& a, const coeff& b); //@} /* other operators */ /* =============== */ /** @name Operators */ //@{ //! Converts a singleton intervals to scalar. void reduce(); //! Negates *this. void neg(); //! Returns the opposite of *this. coeff operator- () const; //! Returns a hash code. long hash() const; //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. const ap_coeff_t* get_ap_coeff_t() const; //! Returns a pointer to the internal APRON object stored in *this. ap_coeff_t* get_ap_coeff_t(); //@} }; #include "apxx_coeff_inline.hh" } #endif /* __APXX_COEFF_HH */ apron-dist-0.9.10/apron/apronxx/apxx_tcons0.hh0000640014525101416610000003472010703144237021161 0ustar bjeannetpopart/* -*- C++ -*- * apxx_tcons0.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_TCONS0_HH #define __APXX_TCONS0_HH #include "ap_tcons0.h" #include "apxx_texpr0.hh" #include "apxx_lincons0.hh" namespace apron { /* ================================= */ /* tcons0 */ /* ================================= */ /*! \brief Level 0 arbitrary constraint (ap_tcons0_t wrapper). * * A tcons0 represents a constraint of the form expr==0, expr>=0, expr>0, expr!=0, or expr==0 mod c * where expr is an arbitrary expression tree. * It stores and manages a texpr0, a constraint type (==, >=, >, !=, mod), and (for modulo constraint) * an extra scalar (c). * * Constraints can be constructed using the >=, <=, >, <, ==, != operators on expression trees, or * dedicated constructors: * \code * tcons0 x = dim(1) >= dim(2) * 5; * tcons0 y = add(sqrt(dim(1),AP_RTYPE_FLOAT), dim(0), AP_RTYPE_FLOAT) != 10; * tcons0 y = tcons0(AP_CONS_EQMOD, 3*dim(0)+2*dim(1), 5); * \endcode * See the documentation of the texpr0 class for more information on constructing expression trees. */ class tcons0 : public use_malloc { protected: ap_tcons0_t l; //!< Structure managed by APRON. //! Internal use only. Performs a shallow copy and takes ownership of the contents. tcons0(ap_tcons0_t& l); friend class abstract0; public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ /*! \brief Creates an empty constraint. * * Neither the expression tree nor the extra scalar are not created * (has_texpr and has_modulo both return false). * \arg \c constyp can be \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, or \c AP_CONS_DISEQ (but not \c AP_CONS_EQMOD). */ tcons0(ap_constyp_t constyp=AP_CONS_SUPEQ); /*! \brief Creates a new (non-modulo) constraint from an expression tree (copied). * * The extra scalar is not created (has_modulo returns false). * \arg \c constyp can be \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, or \c AP_CONS_DISEQ (but not \c AP_CONS_EQMOD). */ tcons0(ap_constyp_t constyp, const texpr0::builder& t); /*! \brief Creates a new constraint from an expression tree and a modulo scalar (both copied). * * \arg \c constyp can be \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, \c AP_CONS_EQMOD, or \c AP_CONS_DISEQ. */ tcons0(ap_constyp_t constyp, const texpr0::builder& t, const scalar& modulo); //! (Deep) copy of a constraint. tcons0(const tcons0& x); /*! \brief Makes a (deep) copy of a constraint, and applies a dimension change to the underlying expression. * * \arg \c add whether to add or remove dimensions. */ tcons0(const tcons0& x, const dimchange& d, bool add=true); //! Makes a (deep) copy of a constraint, and applies a permutation to the underlying expression. tcons0(const tcons0& x, const dimperm& d); //! Makes an unsatisfiable constraint (-1>=0). tcons0(unsat x); /*! \brief Makes a constraint from a linear constraint (copying coefficients). * * Real-valued addition and multiplication operators are used (i.e., no rounding). */ tcons0(const lincons0& x); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ //! Frees the constraint, including the embedded expression tree and optional modulo scalar. ~tcons0(); //@} /* 'Intelligent' constructors */ /* ========================== */ /** @name 'Intelligent' constructors */ //@{ //! Makes a constraint a-b >= 0. friend tcons0 operator>=(const texpr0::builder& a, const texpr0::builder& b); //! Makes a constraint b-a >= 0. friend tcons0 operator<=(const texpr0::builder& a, const texpr0::builder& b); //! Makes a constraint a-b > 0. friend tcons0 operator> (const texpr0::builder& a, const texpr0::builder& b); //! Makes a constraint b-a > 0. friend tcons0 operator< (const texpr0::builder& a, const texpr0::builder& b); //! Makes a constraint a-b == 0. friend tcons0 operator==(const texpr0::builder& a, const texpr0::builder& b); //! Makes a constraint a-b != 0. friend tcons0 operator!=(const texpr0::builder& a, const texpr0::builder& b); //@} /* assignment */ /* ========== */ /** @name Assignments */ //@{ //! (Deep) copy. tcons0& operator= (const tcons0& x); //! Assigns an unsatisfiable constraint to *this (-1>=0). tcons0& operator= (unsat x); /*! \brief Makes *this equal to the linear constraint x (coefficients are copied), deleting the previous value of *this. * * Real-valued addition and multiplication operators are used (i.e., no rounding). */ tcons0& operator= (const lincons0& x); /*! \brief Sets the extra scalar modulo to c (copied). * * Does not fail as get_modulo can: if the constraint was created without an extra scalar, * it is created. */ void set_modulo(const scalar& c); /*! \brief Sets the underlying expression tree to c (copied). * * Does not fail as get_texpr can: if the constraint was created without an underlying expression, * it is created. */ void set_texpr(const texpr0::builder& c); //@} /* dimension operations */ /* ==================== */ /** @name Dimension operations */ //@{ /*! \brief Adds dimensions to the underlying expression tree. * * \throw std::invalid_argument if no valid expression tree has been defined. */ void add_dimensions(const dimchange& d); /*! \brief Removes dimensions to the underlying expression tree. * * \throw std::invalid_argument if no valid expression tree has been defined. */ void remove_dimensions(const dimchange& d); /*! \brief Applies a permutation to the underlying expression tree. * * \throw std::invalid_argument if no valid expression tree has been defined. */ void permute_dimensions(const dimperm& d); //@} /* access */ /* ====== */ /** @name Accesses */ //@{ /* get */ /*! \brief Returns a (modifiable) reference to the constraint type. * * \return either \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, \c AP_CONS_EQMOD, or \c AP_CONS_DISEQ. */ ap_constyp_t& get_constyp(); /*! \brief Returns a reference to the constraint type. * * \return either \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, \c AP_CONS_EQMOD, or \c AP_CONS_DISEQ. */ const ap_constyp_t& get_constyp() const; //! Returns whether the constraint has a valid extra scalar (used in modulo constraints). bool has_modulo() const; //! \brief Whether the constraint contains a valid expression tree. bool has_texpr() const; /*! \brief Returns a (modifiable) reference to the extra scalar. * * \throw std::invalid_argument if no valid extra scalar has been defined. */ scalar& get_modulo(); /*! \brief Returns a reference to the extra scalar. * * \throw std::invalid_argument if no valid extra scalar has been defined. */ const scalar& get_modulo() const; /*! \brief Returns an iterator to the root of the underlying expression tree. * * \throw std::invalid_argument if no valid expression tree has been defined. */ texpr0::iterator get_texpr(); /*! \brief Returns a const_iterator to the root of the underlying expression tree. * * \throw std::invalid_argument if no valid expression tree has been defined. */ texpr0::const_iterator get_texpr() const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ /*! \brief Printing. * * Variable naming can be configured through the varname stream modifier. * * \throw std::invalid_argument if the underlying expression is missing, or the * extra scalar is missing (for modulo). */ friend std::ostream& operator<< (std::ostream& os, const tcons0& s); //! Prints to a C stream. void print(char** name_of_dim=NULL, FILE* stream=stdout) const; //@} /* tests */ /* ===== */ /** @name Tests */ //@{ /*! \brief Whether the expression is constant (i.e., has no dimension leaves). * * \throw std::invalid_argument if no valid expression tree has been defined. */ bool is_interval_cst() const; /*!\brief Whether the expression is linear and there is no rounding. * * \throw std::invalid_argument if no valid expression tree has been defined. */ bool is_interval_linear() const; /*! \brief Whether the expression is polynomial and there is no rounding. * * \throw std::invalid_argument if no valid expression tree has been defined. */ bool is_interval_polynomial() const; /*! \brief Whether the expression is a polynomial fraction and there is no rounding. * * \throw std::invalid_argument if no valid expression tree has been defined. */ bool is_interval_polyfrac() const; /*! \brief Whether all occurring constants are scalar. * * \throw std::invalid_argument if no valid expression tree has been defined. */ bool is_scalar() const; //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. const ap_tcons0_t* get_ap_tcons0_t() const; //! Returns a pointer to the internal APRON object stored in *this. ap_tcons0_t* get_ap_tcons0_t(); //@} }; /* ================================= */ /* tcons0_array */ /* ================================= */ /*! \brief Array of arbitrary constraints (ap_tcons0_array_t wrapper). * * A tcons0_array represents an array of constraints on arbitrary expressions. */ class tcons0_array : public use_malloc { protected: ap_tcons0_array_t a; //!< Structure managed by APRON. //! Internal use only. Performs a shallow copy and takes ownership of the contents. tcons0_array(ap_tcons0_array_t& a) : a(a) {} friend class abstract0; friend class tcons1_array; public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ /*! \brief Creates a new array of the given size containing uninitialized constraints. * * has_modulo and has_texpr will return false on all elements of the array. */ tcons0_array(size_t size); //! (Deep) copy. tcons0_array(const tcons0_array& x); //! Makes a (deep) copy of the array and applies add_dimensions to all constraints. tcons0_array(const tcons0_array& x, const dimchange& d, bool add=true); //! Makes a (deep) copy of the array and applies permute_dimensions to all constraints. tcons0_array(const tcons0_array& x, const dimperm& d); //! Creates a tcons0_array from an array of constraints of the given size (copied). tcons0_array(size_t size, const tcons0 x[]); //! Creates a tcons0_array from a vector of constraints (copied). tcons0_array(const std::vector& x); /*! \brief Makes a constraint array from a linear constraint array (copying coefficients). * * Real-valued addition and multiplication operators are used (i.e., no rounding). */ tcons0_array(const lincons0_array& x); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ //! Frees the space used by the array and all its constraints. ~tcons0_array(); //@} /* assignment */ /* ========== */ /** @name Assignments */ //@{ //! (Deep) copy. tcons0_array& operator= (const tcons0_array& x); /*! \brief Copies the constraints from the array into *this. * * \arg x should contain (at least) size elements. */ tcons0_array& operator= (const tcons0 x[]); //! Copies the constraints from the vector into the array, changing its size if needed. tcons0_array& operator= (const std::vector& x); /*! \brief Makes *this equal to the linear constraint array x (coefficients are copied), deleting the previous value of *this. * * Real-valued addition and multiplication operators are used (i.e., no rounding). */ tcons0_array& operator= (const lincons0_array& x); //@} /* dimension operations */ /* ==================== */ /** @name Dimension operations */ //@{ //! Resizes the array. void resize(size_t size); //! Applies add_dimensions to all constraints in the array. void add_dimensions(const dimchange& d); //! Applies remove_dimensions to all constraints in the array. void remove_dimensions(const dimchange& d); //! Applies permute_dimensions to all constraints in the array. void permute_dimensions(const dimperm& d); //@} /* access */ /* ====== */ /** @name Accesses */ //@{ //! Returns the size of the array. size_t size() const; //! Returns a pointer to the start of the internal array holding the constraints. tcons0* contents(); //! Returns a pointer to the start of the internal array holding the constraints. const tcons0* contents() const; //! Returns a (modifiable) reference to an element, no bound checking. tcons0& operator[](size_t i); //! Returns a reference to an element, no bound checking. const tcons0& operator[](size_t i) const; /*! \brief Returns a (modifiable) reference to an element (bound-checked). * * \throw std::out_of_range if the index is invalid. */ tcons0& get(size_t i); /*! \brief Returns a reference to an element (bound-checked). * * \throw std::out_of_range if the index is invalid. */ const tcons0& get(size_t i) const; //@} /* conversion */ /* ========== */ /** @name Conversion */ //@{ //! Returns a copy of the constraints in the form of a vector. operator std::vector() const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ /*! \brief Printing. * * Variable naming can be configured through the varname stream modifier. * * \throw std::invalid_argument an underlying expression is missing, or an * extra scalar is missing (for modulo constraint). */ friend std::ostream& operator<< (std::ostream& os, const tcons0_array& s); //! Prints to a C stream. void print(char** name_of_dim = NULL, FILE* stream=stdout) const; //@} /* tests */ /* ===== */ /** @name Tests */ //@{ //! Whether all constraints are linear. bool is_interval_linear() const; //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. const ap_tcons0_array_t* get_ap_tcons0_array_t() const; //! Returns a pointer to the internal APRON object stored in *this. ap_tcons0_array_t* get_ap_tcons0_array_t(); //@} }; #include "apxx_tcons0_inline.hh" } #endif /* __APXX_TCONS0_HH */ apron-dist-0.9.10/apron/apronxx/README0000640014525101416610000001711310711606142017244 0ustar bjeannetpopartREADME C++ binding for APRON Library Copyright (C) Antoine Mine' 2007 ------------------------------------------------------------------------ This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution ------------------------------------------------------------------------ WHAT'S THIS? ------------ The apronxx directory provides a C++ binding for the APRON library. It adds the following features: - use classes, overloading and a namespace to simplify function names - use class methods and default arguments to simplify function calls - use operator overloading to ease function calls - object management (through constructors, destructors and copy assignments) - report errors through C++ exceptions - some extra run-time checks that map to exceptions - interface with gmpxx - ability to mix C++ and native C calls to APRON - Doxygen documentation In most cases, C++ calls should not have much overhead. Almost all functions are inline. Also, we try and avoid constructing temporary objects as much as possible. As for every language binding, knowing the native API is definitively a plus. The C++ binding may be less documented. It may also lag behind the native API in terms of functionality. REQUIREMENTS ------------ - GMPXX - Doxygen and LaTeX to build the documentation Apronxx is known to compile well with gcc 4.1.2, but may not work with other versions. INSTALLATION ------------ The apronxx binding should be compiled and installed from the main APRON Makefile. It is compiled last: after both APRON and all abstract domains have been compiled. You need to set HAS_CPP to 1 in the toplevel Makefile.configure to enable the compilation of apronxx. The following other variables from Makefile.configure are used: . GMP_PREFIX: where to find GMP and GMPXX . APRON_PREFIX: where to install apronxx . HAS_PPL: whether to build support for the PPL library . PPL_PREFIX: where to find the PPL library (if HAS_PPL=1) "make install" will install the following - lib/libapronxx.a apronxx library (optimized compilation) - lib/libapronxx_debug.a apronxx library (debug compilation) - include/apronxx/*.hh apronxx headers "make doc" will build the Doxygen documentation in doc/html and doc/latex/refman.pdf . "make test" will build the "apronxx_test" test-suite that tries to call every function in the apronxx library. It tests the box, NewPolka, octagons and, if available, the PPL libraries. Compare the result on your computer with the expected output: apronxx_test_result.txt . USAGE ----- When writing an apronxx application, you should first include the core APRON C++ classes: - #include - compile with -I apronxx - link with -lapronxx_debug (or -lapronxx), -lgmpxx, -lmpfr, -lgmp and -lm . Then, for each numerical abstract domain you wish to use: - #include the header containing the manager factory for the domain: . apxx_box.hh for box . apxx_polka.hh for NewPolka . apxx_oct.hh for the octagons, . apxx_ppl.hh for the PPL, . apxx_ppl_product.hh for reduced products involving NewPolka and the PPL - link with the appropriate APRON C library, for instance, . -lpolkaMPQ_debug for NewPolka polyhedra over MPQ . -loctMPQ_debug for octagons over MPQ . etc. Note that there is no additional C++ library for each domain. Manager creation (as most of apronxx) is done through inline functions #included with the .hh file. Caution: do not include files of the form _inline.hh directly. These files contain actual function definitions which are included automatically by the regular .hh files. The apronxx_test.cc file is a good example on how to use some of apronxx's functionality. INTERNALS --------- Classes. Most C++ classes simply wrap around a corresponding C structure (exceptions are abstract0 and manager). For type ap_XXX_t, we would have a one-field class XXX: class XXX { protected: ap_XXX_t l; }; This make it easy to: 1) pass the ap_XXX_t to an APRON function 2) interpret an ap_XXX_t returned by APRON as an object of type XXX (reinterpret_cast is overused here) 3) get a reference to a field of type ap_YYY_t as an object of type YYY (e.g., an ap_interval_t contains two ap_scalar_t; so you can get two scalar& object from an interval object; some more reinterpret_cast here). Actually, 3) was a major reason to choose wrapping structures directly instead of wrapping structures pointers. In order to get 2) working correctly and allow the caller to delete an object created by the APRON C library, new/delete are mapped to malloc/free (class use_malloc). Memory Management. Constructors automatically ap_XXX_init the object while destructors ap_XXX_clear the object (init/clear functions have been added for those C types that did not support it). Objects are functional: copy constructors and assignments will perform a full copy. The copy can then be manipulated without affecting the original. This is also the case for expression trees. Each texpr0/1 object manages the memory of all its nodes and nodes cannot be shared among trees. When a tree is destroyed, all its nodes are destroyed; they are all copied when the tree is copied; etc. However, there is a little trick. When constructing a tree using nested functions and operator calls (e.g., dim(0)+dim(1)*2/sqrt(dim(3))), we do not want to make all these temporary trees creations and destructions. It would be a waste of time and memory. Thus, a helper 'builder' class is provided to hold temporary trees. Unlike texpr0/1, builder objects may alias nodes, and all builder copies are shallow. This is OK as a full copy will be performed when transferring a temporary tree into a texpr0/1 object before the end of a full expression (in the C++ sense). Accessing and mutating. Whenever an object directly embeds one or several sub-object(s) (e.g., two scalars in an interval), they can be directly accessed through references. In this case two get functions are provided: one for constant objects and one for non-constant ones. When embedded objects are optional (e.g., extra scalar in constraints), both a get and a set function are provided. The get returns a (modifiable) reference to the embedded object but fails (std::invalid_argument) if it does not exist. The set function always succeeds by allocating the optional object if it does not exist. Watch for the (very rare) cases where there is no way to get a reference to an embedded object. There, the get function will return a full copy and cannot be used to mutate the object. Use the provided set function to mutate the object. When array-like objects are provided with both [] and get accessors, then get performs bound-checking while [] does not. For more complex indexing (using, e.g., variable name), this distinction does not exist: index domain checking is mandatory and the accessor is simply named []. In more complex cases (e.g., sparse linear expressions or expression trees), two helper iterator classes are provided: one to access constant objects and another to access and mutate non-constant objects. Iterators are only valid until the (part of the) object they reference are destroyed. Disjunctive types. Several Apron C types are disjunctive, implanted as unions with a discriminant For those, the C++ class provides a get_discr constant member, as well as get_YYY accessors providing references to union fields YYY. This allows reading and modifying the object, but not change its type. Moreover, each accessor perform run-time checks and throws a bad_discriminant exception if the discriminant mismatches. ISSUES ------ - C++ and C boolean type may be different apron-dist-0.9.10/apron/apronxx/apxx_tcons0_inline.hh0000640014525101416610000003257210703144237022522 0ustar bjeannetpopart/* -*- C++ -*- * apxx_tcons0_inline.hh * * APRON Library / C++ inline functions * * DO NOT INCLUDE THIS FILE DIRECTLY * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ /* ================================= */ /* tcons0 */ /* ================================= */ inline tcons0::tcons0(ap_tcons0_t& l) : l(l) {} inline tcons0::tcons0(ap_constyp_t constyp) { l = ap_tcons0_make(constyp, NULL, NULL); } inline tcons0::tcons0(ap_constyp_t constyp, const texpr0::builder& t, const scalar& modulo) { ap_texpr0_t* lt = ap_texpr0_copy(const_cast(t.get_ap_texpr0_t())); ap_scalar_t* mmodulo = ap_scalar_alloc_set(const_cast(modulo.get_ap_scalar_t())); l = ap_tcons0_make(constyp, lt, mmodulo); } inline tcons0::tcons0(ap_constyp_t constyp, const texpr0::builder& t) { ap_texpr0_t* lt = ap_texpr0_copy(const_cast(t.get_ap_texpr0_t())); l = ap_tcons0_make(constyp, lt, NULL); } inline tcons0::tcons0(const tcons0& x) { l = ap_tcons0_copy(const_cast(&x.l)); } inline tcons0::tcons0(unsat x) { l = ap_tcons0_make_unsat(); } inline tcons0::tcons0(const tcons0& x, const dimchange& d, bool add) { if (!x.l.texpr0) throw std::invalid_argument("apron::tcons0::tcons0(const tcons0&, const dimchange&, bool) empty expression"); if (add) l = ap_tcons0_add_dimensions(const_cast(&x.l), const_cast(d.get_ap_dimchange_t())); else l = ap_tcons0_remove_dimensions(const_cast(&x.l), const_cast(d.get_ap_dimchange_t())); } inline tcons0::tcons0(const tcons0& x, const dimperm& d) { if (!x.l.texpr0) throw std::invalid_argument("apron::tcons0::tcons0(const tcons0&, const dimperm&) empty expression"); l = ap_tcons0_permute_dimensions(const_cast(&x.l), const_cast(d.get_ap_dimperm_t())); } inline tcons0::tcons0(const lincons0& x) { l = ap_tcons0_from_lincons0(const_cast(x.get_ap_lincons0_t())); } /* destructor */ /* ========== */ inline tcons0::~tcons0() { ap_tcons0_clear(const_cast(&l)); } /* 'Intelligent' constructors */ /* ========================== */ inline tcons0 operator>=(const texpr0::builder& a, const texpr0::builder& b) { if (b.is_zero()) return tcons0(AP_CONS_SUPEQ,a); else if (a.is_zero()) return tcons0(AP_CONS_SUPEQ,-b); else return tcons0(AP_CONS_SUPEQ,a-b); } inline tcons0 operator<=(const texpr0::builder& a, const texpr0::builder& b) { if (b.is_zero()) return tcons0(AP_CONS_SUPEQ,-a); else if (a.is_zero()) return tcons0(AP_CONS_SUPEQ,b); else return tcons0(AP_CONS_SUPEQ,b-a); } inline tcons0 operator> (const texpr0::builder& a, const texpr0::builder& b) { if (b.is_zero()) return tcons0(AP_CONS_SUP,a); else if (a.is_zero()) return tcons0(AP_CONS_SUP,-b); else return tcons0(AP_CONS_SUP,a-b); } inline tcons0 operator< (const texpr0::builder& a, const texpr0::builder& b) { if (b.is_zero()) return tcons0(AP_CONS_SUP,-a); else if (a.is_zero()) return tcons0(AP_CONS_SUP,b); else return tcons0(AP_CONS_SUP,b-a); } inline tcons0 operator==(const texpr0::builder& a, const texpr0::builder& b) { if (b.is_zero()) return tcons0(AP_CONS_EQ,a); else if (a.is_zero()) return tcons0(AP_CONS_EQ,b); else return tcons0(AP_CONS_EQ,a-b); } inline tcons0 operator!=(const texpr0::builder& a, const texpr0::builder& b) { if (b.is_zero()) return tcons0(AP_CONS_DISEQ,a); else if (a.is_zero()) return tcons0(AP_CONS_DISEQ,b); else return tcons0(AP_CONS_DISEQ,a-b); } /* assignment */ /* ========== */ inline tcons0& tcons0::operator= (const tcons0& x) { if (&x!=this) { ap_tcons0_clear(&l); l = ap_tcons0_copy(const_cast(&x.l)); } return *this; } inline tcons0& tcons0::operator= (unsat x) { ap_tcons0_clear(&l); l = ap_tcons0_make_unsat(); return *this; } inline tcons0& tcons0::operator= (const lincons0& x) { ap_tcons0_clear(&l); l = ap_tcons0_from_lincons0(const_cast(x.get_ap_lincons0_t())); return *this; } /* dimension operations */ /* ==================== */ inline void tcons0::add_dimensions(const dimchange& d) { if (!l.texpr0) throw std::invalid_argument("apron::tcons0::add_dimensions(const dimchange&) empty expression"); ap_tcons0_add_dimensions_with(&l, const_cast(d.get_ap_dimchange_t())); } inline void tcons0::remove_dimensions(const dimchange& d) { if (!l.texpr0) throw std::invalid_argument("apron::tcons0::remove_dimensions(const dimchange&) empty expression"); ap_tcons0_remove_dimensions_with(&l, const_cast(d.get_ap_dimchange_t())); } inline void tcons0::permute_dimensions(const dimperm& d) { if (!l.texpr0) throw std::invalid_argument("apron::tcons0::permute_dimensions(dimperm&) empty expression"); ap_tcons0_permute_dimensions_with(&l, const_cast(d.get_ap_dimperm_t())); } /* access */ /* ====== */ /* get */ inline ap_constyp_t& tcons0::get_constyp() { return l.constyp; } inline const ap_constyp_t& tcons0::get_constyp() const { return l.constyp; } inline bool tcons0::has_modulo() const { return l.scalar!=NULL; } inline bool tcons0::has_texpr() const { return l.texpr0!=NULL; } inline scalar& tcons0::get_modulo() { if (!l.scalar) throw std::invalid_argument("apron::tcons0::get_modulo() empty scalar"); return reinterpret_cast(*l.scalar); } inline const scalar& tcons0::get_modulo() const { if (!l.scalar) throw std::invalid_argument("apron::tcons0::get_modulo() empty scalar"); return reinterpret_cast(*l.scalar); } inline void tcons0::set_modulo(const scalar& c) { if (!l.scalar) l.scalar = ap_scalar_alloc_set(const_cast(c.get_ap_scalar_t())); else ap_scalar_set(l.scalar, const_cast(c.get_ap_scalar_t())); } inline texpr0::const_iterator tcons0::get_texpr() const { if (!l.texpr0) throw std::invalid_argument("apron::tcons0::get_texpr() empty expression"); return l.texpr0; } inline texpr0::iterator tcons0::get_texpr() { if (!l.texpr0) throw std::invalid_argument("apron::tcons0::get_texpr() empty expression"); return l.texpr0; } inline void tcons0::set_texpr(const texpr0::builder& c) { ap_texpr0_t* cc = ap_texpr0_copy(const_cast(c.get_ap_texpr0_t())); if (l.texpr0) ap_texpr0_free(l.texpr0); l.texpr0 = cc; } /* print */ /* ===== */ inline std::ostream& operator<< (std::ostream& os, const tcons0& s) { os << s.get_texpr(); switch (s.get_constyp()) { case AP_CONS_EQ: return os << " = 0"; case AP_CONS_SUPEQ: return os << " >= 0"; case AP_CONS_SUP: return os << " > 0"; case AP_CONS_EQMOD: return os << " = 0 mod " << s.get_modulo(); case AP_CONS_DISEQ: return os << " != 0"; default: throw std::invalid_argument("apron::operator<<(ostream&, const tcons0&) invalid constraint type"); } } inline void tcons0::print(char** name_of_dim, FILE* stream) const { ap_tcons0_fprint(stream, const_cast(&l), name_of_dim); } /* tests */ /* ===== */ inline bool tcons0::is_interval_cst() const { return ap_tcons0_is_interval_cst(const_cast(&l)); } inline bool tcons0::is_interval_linear() const { return ap_tcons0_is_interval_linear(const_cast(&l)); } inline bool tcons0::is_interval_polynomial() const { return ap_tcons0_is_interval_polynomial(const_cast(&l)); } inline bool tcons0::is_interval_polyfrac() const { return ap_tcons0_is_interval_polyfrac(const_cast(&l)); } inline bool tcons0::is_scalar() const { return ap_tcons0_is_scalar(const_cast(&l)); } /* C-level compatibility */ /* ===================== */ inline const ap_tcons0_t* tcons0::get_ap_tcons0_t() const { return &l; } inline ap_tcons0_t* tcons0::get_ap_tcons0_t() { return &l; } /* ================================= */ /* tcons0_array */ /* ================================= */ /* constructors */ /* ============ */ inline tcons0_array::tcons0_array(size_t size) : a(ap_tcons0_array_make(size)) { } inline tcons0_array::tcons0_array(const tcons0_array& x) : a(ap_tcons0_array_make(x.a.size)) { for (size_t i=0; i(x[i].get_ap_tcons0_t())); } inline tcons0_array::tcons0_array(const std::vector& x) : a(ap_tcons0_array_make(x.size())) { for (size_t i=0; i(x[i].get_ap_tcons0_t())); } inline tcons0_array::tcons0_array(const tcons0_array& x, const dimchange& d, bool add) { if (add) a = ap_tcons0_array_add_dimensions(const_cast(&x.a), const_cast(d.get_ap_dimchange_t())); else a = ap_tcons0_array_remove_dimensions(const_cast(&x.a), const_cast(d.get_ap_dimchange_t())); } inline tcons0_array::tcons0_array(const tcons0_array& x, const dimperm& d) { a = ap_tcons0_array_permute_dimensions(const_cast(&x.a), const_cast(d.get_ap_dimperm_t())); } inline tcons0_array::tcons0_array(const lincons0_array& x) : a(ap_tcons0_array_make(x.size())) { for (size_t i=0; i(x[i].get_ap_lincons0_t())); } /* destructor */ /* ========== */ inline tcons0_array::~tcons0_array() { ap_tcons0_array_clear(&a); } /* assignment */ /* ========== */ inline tcons0_array& tcons0_array::operator= (const tcons0_array& x) { if (&x!=this) { ap_tcons0_array_clear(&a); a = ap_tcons0_array_make(x.a.size); for (size_t i=0; i(x[i].get_ap_tcons0_t())); return *this; } inline tcons0_array& tcons0_array::operator= (const std::vector& x) { size_t size = x.size(); ap_tcons0_array_clear(&a); a = ap_tcons0_array_make(size); for (size_t i=0; i(x[i].get_ap_tcons0_t())); return *this; } inline tcons0_array& tcons0_array::operator= (const lincons0_array& x) { size_t size = x.size(); ap_tcons0_array_clear(&a); a = ap_tcons0_array_make(size); for (size_t i=0; i(x[i].get_ap_lincons0_t())); return *this; } /* dimension operations */ /* ==================== */ inline void tcons0_array::resize(size_t size) { ap_tcons0_array_resize(&a, size); } inline void tcons0_array::add_dimensions(const dimchange& d) { ap_tcons0_array_add_dimensions_with(&a, const_cast(d.get_ap_dimchange_t())); } inline void tcons0_array::remove_dimensions(const dimchange& d) { ap_tcons0_array_remove_dimensions_with(&a, const_cast(d.get_ap_dimchange_t())); } inline void tcons0_array::permute_dimensions(const dimperm& d) { ap_tcons0_array_permute_dimensions_with(&a, const_cast(d.get_ap_dimperm_t())); } /* access */ /* ====== */ inline size_t tcons0_array::size() const { return a.size; } inline tcons0* tcons0_array::contents() { return reinterpret_cast(a.p); } inline const tcons0* tcons0_array::contents() const { return reinterpret_cast(a.p); } inline tcons0& tcons0_array::operator[](size_t i) { return reinterpret_cast(a.p[i]); } inline const tcons0& tcons0_array::operator[](size_t i) const { return reinterpret_cast(a.p[i]); } inline tcons0& tcons0_array::get(size_t i) { if (i >= a.size) throw std::out_of_range("apron::tcons0_array::get()"); return reinterpret_cast(a.p[i]); } inline const tcons0& tcons0_array::get(size_t i) const { if (i >= a.size) throw std::out_of_range("apron::tcons0_array::get()"); return reinterpret_cast(a.p[i]); } /* conversion */ /* ========== */ inline tcons0_array::operator std::vector() const { size_t sz = size(); std::vector v = std::vector(sz); for (size_t i=0;i(&a), name_of_dim); } /* tests */ /* ===== */ inline bool tcons0_array::is_interval_linear() const { return ap_tcons0_array_is_interval_linear(const_cast(&a)); } /* C-level compatibility */ /* ===================== */ inline const ap_tcons0_array_t* tcons0_array::get_ap_tcons0_array_t() const { return &a; } inline ap_tcons0_array_t* tcons0_array::get_ap_tcons0_array_t() { return &a; } apron-dist-0.9.10/apron/apronxx/apxx_dimension.hh0000640014525101416610000002576310703144237021747 0ustar bjeannetpopart/* -*- C++ -*- * apxx_dimension.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_DIMENSION_HH #define __APXX_DIMENSION_HH #include "ap_dimension.h" namespace apron { /* ================================= */ /* varname */ /* ================================= */ /*! \brief Stream modifier to set variable names to dimensions. * * By default, all level 0 std::ostream printing functions output \c x0 to * \c xn to refer to dimensions 0 to n. * By inserting this modifier into a stream, you can customize the variable * name. * * The information is local to the stream. * * The modifier is not used for level 1 printing functions as an environment * mapping dimensions to variable names is already available. * Also, the modifier does not affect the behavior of print functions * that take the mapping as an (optional) argument. */ class varname { protected: //! Index to stream-local data, allocated with xalloc. static const int xindex; //! Names of variables. const std::vector& names; public: /*! \brief Creates a modifier to associate variable names to dimensions. * * \arg \c names[i] is the name to give to dimension i. * * If there are not enough names, printing functions will revert to * xi, xi+1... To disable variable names, simply pass an empty vector. * * A reference to \c names is kept by the object and will be passed to the * stream by the modifier. The stream will then make a deep copy and the * varname object and the original vector can be safely deleted. * */ varname(const std::vector& names); //! Associates the modifier to the stream. template friend std::basic_ostream& operator<<(std::basic_ostream& os, const varname& v); /*! \brief Gets the variable name vector associated to the stream * * \return a pointer to the vector formerly associated to the * stream, or NULL. */ template friend std::vector* get_varname(std::basic_ostream& os); }; /* ================================= */ /* dimchange */ /* ================================= */ /*! \brief Dimension change object (ap_dimchange_t wrapper). * * dimchange objects are used to insert or remove dimensions at arbitrary positions in expressions, * constraints, and domains. * A dimchange object embeds the number of integer and real dimensions to add/remove, as well as * an array of indices where to add/remove dimensions. * The array should be sorted in increasing order. */ class dimchange : public use_malloc { protected: ap_dimchange_t c; //!< Structure managed by APRON. public: /* constructor */ /* =========== */ /** @name Constructors */ //@{ //! Makes an uninitialized dimchange. dimchange(size_t intdim=0, size_t realdim=0); /*! \brief Makes a dimchange initialized using the given array of indices (copied). * * \arg \c d should contain (at least) intdim+realdim dimensions. */ dimchange(size_t intdim, size_t realdim, const ap_dim_t d[]); /*! \brief Makes a dimchange initialized using the given vector of indices (copied). * * \exception std::invalid_argument if d contains less than intdim+realdim dimensions. */ dimchange(size_t intdim, size_t realdim, const std::vector& d); /*! \brief Makes a copy of a dimchange, copying the array, and optionally inverting the dimension change. * * \arg inv if inv==true, then the constructed dimchange is the inverse of x (see add_invert). */ dimchange(const dimchange& x, bool inv=false); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ ~dimchange(); //@} /* assignment */ /* ========== */ /** @name Assignments */ //@{ //! (Deep) copy. dimchange& operator= (const dimchange& x); /*! \brief Assignment from an array of indices. * * \arg \c d should contain (at least) intdim+realdim dimensions. */ dimchange& operator= (const ap_dim_t d[]); /*! \brief Assignment from a vector of indices (no change in size). * * \exception std::invalid_argument if \c d contains less than intdim+realdim dimensions. */ dimchange& operator= (const std::vector& d); //@} /* access */ /* ====== */ /** @name Accesses */ //@{ //! Returns the number of integer dimensions to add/remove. size_t get_intdim() const; //! Returns the number of real dimensions to add/remove. size_t get_realdim() const; /*! \brief Returns a (modifiable) reference to an index in the underlying array. * * \arg \c dim should be strictly smaller than intdim+realdim (not bound-checked). */ ap_dim_t& operator[](size_t dim); /*! \brief Returns a reference to a (checked) index in the underlying array. * * \arg \c dim should be strictly smaller than intdim+realdim (not bound-checked). */ const ap_dim_t& operator[](size_t dim) const; /*! \brief Returns a (modifiable) reference to an index in the underlying array (bound-checked). * * \exception std::out_of_range is thrown if dim>=intdim+realdim. */ ap_dim_t& get(size_t dim); /*! \brief Returns a reference to a (checked) index in the underlying array (bound-checked). * * \exception std::out_of_range is thrown if dim>=intdim+realdim. */ const ap_dim_t& get(size_t dim) const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ /*! \brief Printing. * * Variable naming can be configured through the varname stream modifier. */ friend std::ostream& operator<< (std::ostream& os, const dimchange& s); //! Prints to a C stream. void print(FILE* stream=stdout) const; //@} /* other operators */ /* =============== */ /** @name Operators */ //@{ /*! \brief Inverts *this. * * If the dimchange was used to add some dimensions, it can now be used to remove the * added dimensions (but not the converse). */ void add_invert(); /*! \brief Returns the inverse of *this. * * See \c add_invert. */ dimchange operator- () const; //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. const ap_dimchange_t* get_ap_dimchange_t() const; //! Returns a pointer to the internal APRON object stored in *this. ap_dimchange_t* get_ap_dimchange_t(); //@} }; //! The identity permutation, to simplify initialisations and assignments. struct id { size_t size; //!< Size of the permutation. id(size_t size) : size(size) {} }; /* ================================= */ /* dimperm */ /* ================================= */ /*! \brief Dimension permutation object (ap_dimperm_t wrapper). * * dimperm objects can be used to permute dimensions in expressions, constraints, and domains. * They hold a map i->p[i]: [0,size-1]=>[0,size-1] using an array p of dimensions. * All the p[i] must be distinct and in the range [0,size-1] where size is the size of p. */ class dimperm : public use_malloc { protected: ap_dimperm_t c; //!< Structure managed by APRON. public: /* constructor */ /* =========== */ /** @name Constructors */ //@{ //! Makes an uninitialized dimperm of the given size. dimperm(size_t size=0); /*! \brief Makes a dimperm initialized with the array d. * * \arg \c d should contain (at least) size dimensions. */ dimperm(size_t size, const ap_dim_t d[]); //! Makes a dimperm initialized with the vector d. dimperm(const std::vector& d); //! Makes an identity permutation. dimperm(id t); /*! \brief Makes a copy of a permutation, optionally inverting it. * * \arg inv if inv==true, then the constructed permutation is the inverse of x. */ dimperm(const dimperm& x, bool inv=false); //! Makes a new dimperm that is the composition of two permutations. dimperm(const dimperm& x, const dimperm& y); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ ~dimperm(); //@} /* assignment */ /* ========== */ /** @name Assignments */ //@{ //! Copies \c x. dimperm& operator= (const dimperm& x); //! Assigns the identity permutation to *this. dimperm& operator= (id t); /*! \brief Assigns the permutation from the array d to *this. * * \arg \c d should contain (at least) size dimensions. */ dimperm& operator= (const ap_dim_t d[]); //! Assigns the permutation from the vector d to *this (changing its size). dimperm& operator= (const std::vector& d); //@} /* access */ /* ====== */ /** @name Accesses, size */ //@{ //! Returns the size of the permutation. size_t size() const; /*! \brief Returns a (modifiable) reference to the image of dim. * * \arg \c dim should be strictly smaller than size (not bound-checked). */ ap_dim_t& operator[](size_t dim); /*! \brief Returns a reference to the image of dim. * * \arg \c dim should be strictly smaller than size (not bound-checked). */ const ap_dim_t& operator[](size_t dim) const; /*! \brief Returns a (modifiable) reference to the image of dim (bound-checked). * * \exception std::out_of_range is thrown if dim>=size. */ ap_dim_t& get(size_t dim); /*! \brief Returns a reference to the image of dim (bound-checked). * * \exception std::out_of_range is thrown if dim>=size. */ const ap_dim_t& get(size_t dim) const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ /*! \brief Printing. * * Variable naming can be configured through the varname stream modifier. */ friend std::ostream& operator<< (std::ostream& os, const dimperm& s); //! Prints to a C stream. void print(FILE* stream=stdout) const; //@} /* other operators */ /* =============== */ /** @name Operators */ //@{ /* composition */ /*! \brief Composes *this with y. * * \exception std::invalid_argument if *this and y do not have the same size. */ dimperm& operator*= (const dimperm& y); /*! \brief Returns a new dimperm that is the composition of x and y. * * \exception std::invalid_argument if x and y do not have the same size. */ friend dimperm operator* (const dimperm& x, const dimperm& y); /* inversion */ //! Inverts *this. void invert(); //! Returns a new dimperm that is the inverse of *this. dimperm operator- () const; //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. const ap_dimperm_t* get_ap_dimperm_t() const; //! Returns a pointer to the internal APRON object stored in *this. ap_dimperm_t* get_ap_dimperm_t(); //@} }; #include "apxx_dimension_inline.hh" } #endif /* __APXX_DIMENSION_HH */ apron-dist-0.9.10/apron/apronxx/apxx_texpr1.hh0000640014525101416610000006716011006063143021173 0ustar bjeannetpopart/* -*- C++ -*- * apxx_texpr1.hh * * APRON Library / C++ class wrappers * * Copyright (C) Antoine Mine' 2007 * */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. */ #ifndef __APXX_TEXPR1_HH #define __APXX_TEXPR1_HH #include "ap_texpr1.h" #include "apxx_linexpr1.hh" #include "apxx_texpr0.hh" namespace apron { /* ================================= */ /* texpr1 */ /* ================================= */ /*! \brief Level 1 arbitrary expression tree (ap_texpr1_t wrapper). * * Level 1 version of arbitrary expression trees (texpr0). * Variable names (var) are used instead of dimensions (ap_dim_t). * Internally, a texpr1 wraps together a texpr0 (memory managed) and an environment (holding a * reference count). * * There are also level 1 equivalent of the helper classes: builder, iterator, and const_iterator. * */ class texpr1 : public use_malloc { protected: ap_texpr1_t l; //!< Structure managed by APRON. //! Internal use only. Shallow copy. texpr1(ap_texpr1_t* x); //! Internal use only. Shallow copy. void init_from(ap_environment_t* e, ap_texpr0_t* x); //! Internal use only. Shallow copy. void init_from(ap_texpr1_t* x); public: class builder; class iterator; class const_iterator; /* constructors */ /* ============ */ /** @name Constructors */ //@{ //! Makes an expression from a temporary. texpr1(const builder& c); //! Makes a (deep) copy of the expression tree. texpr1(const const_iterator& x); //! Makes a (deep) copy of the expression tree. texpr1(const texpr1& x); /*! \brief Makes a variable name dimension leaf. * * \throw std::invalid_argument if the environment does not contain the variable. */ texpr1(const environment& e, const var& v); /*! \brief Makes a (deep) copy of the level 0 expression tree and associates an environment * (increments reference count). */ texpr1(const environment& e, const texpr0::const_iterator& x); /*! \brief Makes a (deep) copy of the level 0 expression tree and associates an environment * (increments reference count). */ texpr1(const environment& e, const texpr0& x); //! Makes an expression from a level 0 temporary. texpr1(const environment& e, const texpr0::builder& c); #if 0 //! Goes through the construction of a temporary builder. template texpr1(const T& x); //! Goes through the construction of a (level 0) temporary builder. template texpr1(const environment& e, const T& x); #endif /*! \brief Makes an expression tree from a linear expression (copying coefficients). * * Real-valued addition and multiplication operators are used (i.e., no rounding). */ texpr1(const linexpr1& l); /*! \brief Makes a (deep) copy of x and extends its environment. * * \throw std::invalid_argument if e is not a super-environment of that of x. */ texpr1(const texpr1& x, const environment& e); /*! \brief Makes a (deep) copy of x and substitutes every occurrence of the src variable name with * a fresh copy of the dst expression. * * \throw std::invalid_argument if the environments are not equal or do not contain the variable. */ texpr1(const texpr1& x, const var& src, const texpr1& dst); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ //! Frees the memory occupied by the expression and decrements the reference count of the environment. ~texpr1(); //@} /* assignment */ /* ========== */ /** @name Assignments */ //@{ //! Makes a (deep) copy of the expression. texpr1& operator=(const texpr1& x); //! Makes a (deep) copy of the expression. texpr1& operator=(const const_iterator& x); /*! \brief Assigns from a temporary expression, performing a deep copy and deleting the previous * value of *this. */ texpr1& operator=(const builder& x); #if 0 //! Other assignments go through the use of a (level 1) temporary builder. template texpr1& operator=(const T& x); #endif /*! \brief Makes *this equal to the linear expression x (coefficients are copied), deleting the previous value of *this. * * Real-valued addition and multiplication operators are used (i.e., no rounding). */ texpr1& operator= (const linexpr1& x); //@} /* iterators */ /* ========= */ /** @name Iterators */ //@{ /*! \brief Iterators to traverse a constant expression tree. * * Use the iterator class if you also wish to mutate an expression. */ class const_iterator { protected: ap_texpr1_t l; //! Internal use only. const_iterator(ap_texpr1_t* l); //! Internal use only. const_iterator(ap_texpr0_t* t, ap_environment_t* e); friend class texpr1; friend class tcons1; public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ //! Starts a new const_iterator at the root of a constant expression tree. const_iterator(const texpr1& e); //! Duplicates the const_iterator. const_iterator(const const_iterator& i); //@} /* access */ /* ====== */ /** @name Access */ //@{ //! \brief Returns (a copy of) the environment associated with the expression. environment get_environment() const; //! Returns a constant iterator at the root of the underlying texpr0. texpr0::const_iterator get_texpr0() const; /*! \brief Returns the node kind. * * \return \c AP_TEXPR_CST for a constant node, \c AP_TEXPR_DIM for a dimension, * and \c AP_TEXPR_NODE for an operator node. */ ap_texpr_discr_t get_discr() const; /*! \brief Returns a reference to the coefficient of a constant node. * * \throw bad_discriminant if the node is not a constant leaf. */ const coeff& get_coeff() const; /*! \brief Returns a (unmodifiable) reference to the variable name of a dimension node. * * \throw bad_discriminant if the node is not a dimension node. */ const var& get_var() const; /*! \brief Returns the dimension of a dimension node. * * \throw bad_discriminant if the node is not a dimension node. */ ap_dim_t get_dim() const; /*! \brief Returns the operator kind of an operator node. * * \return either \c AP_TEXPR_ADD, \c AP_TEXPR_SUB, \c AP_TEXPR_MUL, \c AP_TEXPR_DIV, \c AP_TEXPR_MOD, * \c AP_TEXPR_NEG, \c AP_TEXPR_CAST, or \c AP_TEXPR_SQRT. * \throw bad_discriminant if the node is not an operator node. */ ap_texpr_op_t get_op() const; /*! \brief Returns the destination type of an operator node. * * \return either \c AP_RTYPE_REAL, \c AP_RTYPE_INT, \c AP_RTYPE_SINGLE (32-bit), \c AP_RTYPE_DOUBLE (64-bit), * \c AP_RTYPE_EXTENDED (80-bit), or \c AP_RTYPE_QUAD (128-bit). * \throw bad_discriminant if the node is not an operator node. */ ap_texpr_rtype_t get_rtype() const; /*! \brief Returns the rounding direction of an operator node. * * \return either \c AP_RDIR_NEAREST, \c AP_RDIR_ZERO, \c AP_RDIR_UP, \c AP_RDIR_DOWN, or \c AP_RDIR_RND. * \throw bad_discriminant if the node is not an operator node. */ ap_texpr_rdir_t get_rdir() const; //@} /* traversal */ /* ========= */ /** @name Traversal */ //@{ //! Resets the const_iterator at position i. const_iterator& operator=(const const_iterator& i); /*! \brief Constructs a const_iterator to the only or left sub-expression of an operator node. * * \throw bad_discriminant if the node is not an operator node. */ const_iterator child() const; /*! \brief Constructs a const_iterator to the only of left sub-expression of an operator node. * * (Identical to child()). * \throw bad_discriminant if the node is not an operator node. */ const_iterator left() const; /*! \brief Constructs a const_iterator to the right sub-expression argument of a binary operator node. * * \throw bad_discriminant if the node is not an operator node. * \throw std::out_of_range if the operator node is not binary. */ const_iterator right() const; //@} /* tests, size, dimensions */ /* ======================= */ /** @name Tests, size, dimensions */ //@{ //! Whether two expressions are syntactically, structurally equal. bool equal(const texpr1& x) const; //! Whether the expression is a single coefficient node with 0 value. bool is_zero() const; //! Returns the depth of the expression tree (counting only operator nodes). size_t depth() const; //! Returns the number of operator nodes in the expression tree. size_t size() const; //! Whether the given variable name occurs in the expression. bool has_var(const var& v) const; //! Whether the expression is constant (i.e., has no dimension leaves). bool is_interval_cst() const; //! Whether the expression is linear and there is no rounding. bool is_interval_linear() const; //! Whether the expression is polynomial and there is no rounding. bool is_interval_polynomial() const; //! Whether the expression is a polynomial fraction and there is no rounding. bool is_interval_polyfrac() const; //! Whether all occurring constants are scalar. bool is_scalar() const; //@} /* print */ /* ===== */ /** @name Printing */ //@{ //! Printing. friend std::ostream& operator<< (std::ostream& os, const const_iterator& s); //! Prints to a C stream. void print(FILE* stream=stdout) const; //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. ap_texpr1_t* get_ap_texpr1_t(); //! Returns a pointer to the internal APRON object stored in *this. const ap_texpr1_t* get_ap_texpr1_t() const; //@} }; /*! \brief Iterators to traverse and mutate an expression tree. * * As const_iterator, but can be used to modify as well as traverse nodes. */ class iterator : public const_iterator { protected: //! Internal use only. iterator(ap_texpr1_t* l); //! Internal use only. iterator(ap_texpr0_t* t, ap_environment_t* e); friend class texpr1; friend class tcons1; public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ //! Starts a new iterator at the root of the tree. iterator(texpr1& e); //! Duplicates the iterator. iterator(const iterator& i); //@} /* substitution */ /* ============ */ /** @name Expression substitutions */ //@{ /*! \brief Replace the sub-expression at the iterator position with a (deep) copy of c. * * Assumes that the *this and have the same environment (unchecked). */ iterator& operator= (const builder& x); #if 0 //! Assignment is through the construction of a texpr0::build. template iterator& operator= (const T& c); #endif //@} /* access */ /* ====== */ /** @name Access */ //@{ //! Returns an iterator at the root of the underlying texpr0. texpr0::iterator get_texpr0() const; /*! \brief Returns a (modifiable) reference to the coefficient of a constant node. * * \throw bad_discriminant if the node is not a constant leaf. */ coeff& get_coeff() const; /*! \brief Sets the variable name of a dimension node. * * \throw bad_discriminant if the node is not a dimension node. * \throw std::invalid_argument if the environment does not contain a variable. */ void set_var(const var& v) const; /*! \brief Returns a (modifiable) reference to the dimension of a dimension node. * * \throw bad_discriminant if the node is not a dimension node. */ ap_dim_t& get_dim() const; /*! \brief Returns a (modifiable) reference to the operator kind of an operator node. * * \return either \c AP_TEXPR_ADD, \c AP_TEXPR_SUB, \c AP_TEXPR_MUL, \c AP_TEXPR_DIV, \c AP_TEXPR_MOD, * \c AP_TEXPR_NEG, \c AP_TEXPR_CAST, or \c AP_TEXPR_SQRT. * \throw bad_discriminant if the node is not an operator node. */ ap_texpr_op_t& get_op() const; /*! \brief Returns a (modifiable) reference to the destination type of an operator node. * * \return either \c AP_RTYPE_REAL, \c AP_RTYPE_INT, \c AP_RTYPE_SINGLE (32-bit), \c AP_RTYPE_DOUBLE (64-bit), * \c AP_RTYPE_EXTENDED (80-bit), or \c AP_RTYPE_QUAD (128-bit). * \throw bad_discriminant if the node is not an operator node. */ ap_texpr_rtype_t& get_rtype() const; /*! \brief Returns a (modifiable) reference to the rounding direction of an operator node. * * \return either \c AP_RDIR_NEAREST, \c AP_RDIR_ZERO, \c AP_RDIR_UP, \c AP_RDIR_DOWN, or \c AP_RDIR_RND. * \throw bad_discriminant if the node is not an operator node. */ ap_texpr_rdir_t& get_rdir() const; //@} /* traversal */ /* ========= */ /** @name Traversal */ //@{ //! Resets the iterator at position i. iterator& operator=(const iterator& i); /*! \brief Constructs an iterator to the only or left sub-expression of an operator node. * * \throw bad_discriminant if the node is not an operator node. */ iterator child() const; /*! \brief Constructs an iterator to the only of left sub-expression of an operator node. * * (Identical to child()). * \throw bad_discriminant if the node is not an operator node. */ iterator left() const; /*! \brief Constructs an iterator to the right sub-expression argument of a binary operator node. * * \throw bad_discriminant if the node is not an operator node. * \throw std::out_of_range if the operator node is not binary. */ iterator right() const; //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. ap_texpr1_t* get_ap_texpr1_t(); //! Returns a pointer to the internal APRON object stored in *this. const ap_texpr1_t* get_ap_texpr1_t() const; //@} }; //! Returns a new iterator at the root of a constant expression tree. const_iterator root() const; //! Returns a new iterator at the root of a mutable expression tree. iterator root(); //@} /* builders */ /* ======== */ /** @name Builders */ //@{ /*! \brief Temporary expression nodes used when constructing a texpr1. * * A temporary expression is composed of a level 0 node with an associated environment. * * You should not create variables of type build, nor define functions that return or take * builder objects as arguments. */ class builder : public use_malloc { friend class texpr1; protected: ap_texpr1_t l; //! Not to be used. (Temporaries are not to be re-assigned). builder& operator= (const builder& x) { assert(0); return *this; } //! Internal use only: makes a shallow copy, copying only the root node and referencing the environment. void init_from(ap_texpr1_t* x); //! Internal use only: makes a shallow copy, copying only the root node and referencing the environment. void init_from(ap_environment_t* e, ap_texpr0_t* x); //! Internal use only: makes a shallow copy, copying only the root node and referencing the environment. builder(ap_texpr1_t* x); public: /* constructors */ /* ============ */ /** @name Constructors */ //@{ //! Makes a shallow copy, copying only the root node. Sub-expressions are aliased, not copied. builder(const builder& x); //! Makes a shallow copy, copying only the root node. Sub-expressions are aliased, not copied. builder(const const_iterator& x); //! Makes a shallow copy, copying only the root node. Sub-expressions are aliased, not copied. builder(const texpr1& x); //! Converts from a level 0 builder and associates an environment. builder(const environment& e, const texpr0::builder& b); //! Converts from a level 0 expression (shallow copy) and associates an environment. builder(const environment& e, const texpr0::const_iterator& b); //! Converts from a level 0 expression (shallow copy) and associates an environment. builder(const environment& e, const texpr0& b); //! Makes a constant leaf from a scalar or interval coefficient (copied). builder(const environment& e, const coeff& x); //! Makes a constant scalar leaf from a scalar (copied). builder(const environment& e, const scalar& x); //! Makes a constant scalar leaf from a MPQ (copied). builder(const environment& e, const mpq_class& x); //! Makes a constant scalar leaf from a MPFR (copied). builder(const environment& e, mpfr_t x); //! Makes a constant scalar MPQ leaf from an integer. builder(const environment& e, int x); //! Makes a constant scalar MPQ leaf from an integer. builder(const environment& e, long x); //! Makes a constant scalar double leaf from a double. builder(const environment& e, double x); //! Makes a constant scalar MPQ leaf from a fraction with integer coefficients. builder(const environment& e, const frac& x); //! Makes a constant interval leaf from an interval (copied). builder(const environment& e, const interval& x); //! Makes a constant interval leaf from two scalar bounds (copied). builder(const environment& e, const scalar& inf, const scalar& sup); //! Makes a constant interval leaf from two MPQ bounds (copied). builder(const environment& e, const mpq_class& inf, const mpq_class& sup); //! Makes a constant interval leaf from two MPFR bounds (copied). builder(const environment& e, mpfr_t inf, mpfr_t sup); //! Makes a constant interval leaf from two integer bounds (converted to MPQ). builder(const environment& e, int inf, int sup); //! Makes a constant interval leaf from two integer bounds (converted to MPQ). builder(const environment& e, long inf, long sup); //! Makes a constant interval leaf from two double bounds. builder(const environment& e, double inf, double sup); //! Makes a constant interval leaf from two fraction bounds (converted to MPQ). builder(const environment& e, const frac& inf, const frac& sup); //! Makes a constant interval leaf equal to ]-oo;+oo[. builder(const environment& e, top t); //! Makes a variable name dimension leaf. builder(const environment& e, const var& v); //! Makes a unary expression node. builder(ap_texpr_op_t op, const builder& argA, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir); //! Makes a binary expression node. builder(ap_texpr_op_t op, const builder& argA, const builder& argB, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir); //@} /* destructor */ /* ========== */ /** @name Destructor */ //@{ //! Frees the memory occupied by the node, not its sub-expressions. ~builder(); //@} /* tests */ /* ===== */ /** @name Tests */ //@{ //! Whether the expression is a single coefficient node with 0 value. bool is_zero() const; //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. ap_texpr1_t* get_ap_texpr1_t(); //! Returns a pointer to the internal APRON object stored in *this. const ap_texpr1_t* get_ap_texpr1_t() const; //@} /* 'Intelligent' constructors */ /* ========================== */ /** @name 'Intelligent' constructors */ //@{ /*! \brief Makes a unary expression node. * * Creates only one node. The argument expression is aliased, not copied. * * \arg \c op should be a unary operator: negation (\c AP_TEXPR_NEG), typecast (\c AP_TEXPR_CAST), * or square root (\c AP_TEXPR_SQRT). * \arg \c argA should point to the argument expression. * \arg \c rtype is the destination type (for rounding): reals (\c AP_RTYPE_REAL, means no rounding), * perfect integers (\c AP_RTYPE_INT), 32-bit single precision (\c AP_RTYPE_SINGLE), 64-bit double precision * (\c AP_RTYPE_DOUBLE), 80-bit extended precision (\c AP_RTYPE_EXTENDED), or * 128-bit quadruple precision (\c AP_RTYPE_QUAD). * \arg \c rdir is the rounding direction: to nearest (\c AP_RDIR_NEAREST), truncation (\c AP_RDIR_ZERO), * towards +oo (\c AP_RDIR_UP), towards -oo (\c AP_RDIR_DOWN), or non-deterministic (\c AP_RDIR_RND). * \throw std::invalid_argument if \c op is not a unary operator. */ friend builder unary(ap_texpr_op_t op, const builder& a, ap_texpr_rtype_t rtype = AP_RTYPE_REAL, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); /*! \brief Makes a binary expression node. * * Creates only one node. The argument expressions is aliased, not copied. * * \arg \c op should be a binary operator: addition (\c AP_TEXPR_ADD), subtraction (\c AP_TEXPR_SUB), * multiplication (\c AP_TEXPR_MUL), division (\c AP_TEXPR_DIV), or modulo (\c AP_TEXPR_MOD). * \arg \c argA should point to the left argument expression. * \arg \c argB should point to the right argument expression. * \arg \c rtype is the destination type (for rounding): reals (\c AP_RTYPE_REAL, means no rounding), * perfect integers (\c AP_RTYPE_INT), 32-bit single precision (\c AP_RTYPE_SINGLE), 64-bit double precision * (\c AP_RTYPE_DOUBLE), 80-bit extended precision (\c AP_RTYPE_EXTENDED). * \arg \c rdir is the rounding direction: to nearest (\c AP_RDIR_NEAREST), truncation (\c AP_RDIR_ZERO), * towards +oo (\c AP_RDIR_UP), towards -oo (\c AP_RDIR_DOWN), or non-deterministic (\c AP_RDIR_RND). * \throw std::invalid_argument if \c op is not a binary operator. */ friend builder binary(ap_texpr_op_t op, const builder& a, const builder& b, ap_texpr_rtype_t rtype = AP_RTYPE_REAL, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); //! Makes an \c AP_TEXPR_ADD expression node. friend builder add(const builder& a, const builder& b, ap_texpr_rtype_t rtype = AP_RTYPE_REAL, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); //! Makes an \c AP_TEXPR_SUB expression node. friend builder sub(const builder& a, const builder& b, ap_texpr_rtype_t rtype = AP_RTYPE_REAL, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); //! Makes an \c AP_TEXPR_MUL expression node. friend builder mul(const builder& a, const builder& b, ap_texpr_rtype_t rtype = AP_RTYPE_REAL, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); //! Makes an \c AP_TEXPR_DIV expression node. friend builder div(const builder& a, const builder& b, ap_texpr_rtype_t rtype = AP_RTYPE_REAL, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); //! Makes an \c AP_TEXPR_MOD expression node. friend builder mod(const builder& a, const builder& b, ap_texpr_rtype_t rtype = AP_RTYPE_REAL, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); //! Makes an \c AP_TEXPR_NEG expression node. friend builder neg(const builder& a, ap_texpr_rtype_t rtype = AP_RTYPE_REAL, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); //! Makes an \c AP_TEXPR_CAST expression node. friend builder cast(const builder& a, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); //! Makes an \c AP_TEXPR_CAST expression node to \c AP_RTYPE_INT type rounded towards \c AP_RDIR_DOWN. friend builder floor(const builder& a); //! Makes an \c AP_TEXPR_CAST expression node to \c AP_RTYPE_INT type rounded towards \c AP_RDIR_UP. friend builder ceil(const builder& a); //! Makes an \c AP_TEXPR_CAST expression node to \c AP_RTYPE_INT type rounded towards \c AP_RDIR_ZERO. friend builder trunc(const builder& a); //! Makes an \c AP_TEXPR_SQRT expression node. friend builder sqrt(const builder& a, ap_texpr_rtype_t rtype = AP_RTYPE_REAL, ap_texpr_rdir_t rdir = AP_RDIR_NEAREST); //! Makes a copy of the node. friend builder operator+(const builder& a); //! Makes a \c AP_TEXPR_NEG expression node using \c AP_RTYPE_REAL type (no rounding). friend builder operator-(const builder& a); //! Makes a \c AP_TEXPR_ADD expression node using \c AP_RTYPE_REAL type (no rounding). friend builder operator+(const builder& a, const builder& b); //! Makes a \c AP_TEXPR_SUB expression node using \c AP_RTYPE_REAL type (no rounding). friend builder operator-(const builder& a, const builder& b); //! Makes a \c AP_TEXPR_MUL expression node using \c AP_RTYPE_REAL type (no rounding). friend builder operator*(const builder& a, const builder& b); //! Makes a \c AP_TEXPR_DIV expression node using \c AP_RTYPE_REAL type (no rounding). friend builder operator/(const builder& a, const builder& b); //! Makes a \c AP_TEXPR_MOD expression node using \c AP_RTYPE_REAL type (no rounding). friend builder operator%(const builder& a, const builder& b); //@} }; /* print */ /* ===== */ /** @name Printing */ //@{ //! Printing. friend std::ostream& operator<< (std::ostream& os, const texpr1& s); //! Prints to a C stream. void print(FILE* stream=stdout) const; //@} /* dimension operations */ /* ==================== */ /** @name Dimension operations */ //@{ /*! \brief Extends the environment of the expression. * * \throw std::invalid_argument if e is not a super-environment of that of *this. */ void extend_environment(const environment& e); //@} /* access */ /* ====== */ /** @name Accesses, tests, size */ //@{ //! Returns the environment of the expression (with incremented reference count). environment get_environment() const; //! Returns a constant iterator at the root of the underlying texpr0. texpr0::const_iterator get_texpr0() const; //! Returns an iterator at the root of the underlying texpr0. texpr0::iterator get_texpr0(); //! Whether the expression is a single coefficient node with 0 value. bool is_zero() const; //! Whether two expressions are syntactically, structurally equal. bool equal(const texpr1& x) const; //! Returns the depth of the expression tree (counting only operator nodes). size_t depth() const; //! Returns the number of operator nodes in the expression tree. size_t size() const; //! Whether the given variable name occurs in the expression. bool has_var(const var& v) const; //! Whether the expression is constant (i.e., has no dimension leaves). bool is_interval_cst() const; //! Whether the expression is linear and there is no rounding. bool is_interval_linear() const; //! Whether the expression is polynomial and there is no rounding. bool is_interval_polynomial() const; //! Whether the expression is a polynomial fraction and there is no rounding. bool is_interval_polyfrac() const; //! Whether all occurring constants are scalar. bool is_scalar() const; //@} /* operations */ /* ========== */ /** @name Operations */ //@{ /*! \brief Substitutes each occurrence of src with (a fresh copy of) dst. * * \throw std::invalid_argument if the environments are not equal or do not contain src. */ void substitute(const var& src, const texpr1& dst); //@} /* C-level compatibility */ /* ===================== */ /** @name C API compatibility */ //@{ //! Returns a pointer to the internal APRON object stored in *this. ap_texpr1_t* get_ap_texpr1_t(); //! Returns a pointer to the internal APRON object stored in *this. const ap_texpr1_t* get_ap_texpr1_t() const; //@} }; #include "apxx_texpr1_inline.hh" } #endif /* __APXX_TEXPR1_HH */ apron-dist-0.9.10/apron/newpolka/0000750014525101416610000000000011252216517016505 5ustar bjeannetpopartapron-dist-0.9.10/apron/newpolka/pk.h0000640014525101416610000004127211251675662017310 0ustar bjeannetpopart/* ********************************************************************** */ /* pk.h: Interface of the polka linear relation library */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef __PK_H__ #define __PK_H__ #ifdef __cplusplus extern "C" { #endif #include "ap_global0.h" /* The invariant of the representation of a polyhedron is the following: if the polyhedron is empty, then C==F==satC==satF==0. Otherwise, we have (C || F) && (satC || satF || !(C && F)). This means that a non-empty polyhedron has a minimal representation minimal if and only if C && F if and only if satC || satF. */ typedef enum pk_status_t { pk_status_conseps=0x1, pk_status_consgauss=0x2, pk_status_gengauss=0x4, pk_status_minimaleps=0x8 } pk_status_t; struct pk_t { /* private data: do not use directly ! */ struct matrix_t* C; struct matrix_t* F; struct satmat_t* satC; struct satmat_t* satF; size_t intdim; size_t realdim; size_t nbeq; size_t nbline; pk_status_t status; }; typedef struct pk_t pk_t; typedef struct pk_internal_t pk_internal_t; /* Important remark: the newpolka library is normally intended to be accessed through the APRON interface, i.e., through abstract0_XX and abstract1_XX functions. If it is accessed directly with pk_XXX functions, many checks on arguments will not be performed. */ /* ============================================================ */ /* A. Constructor for APRON manager (to be freed with ap_manager_free). */ /* ============================================================ */ ap_manager_t* pk_manager_alloc(bool strict); /* Allocate a NewPolka manager for convex polyhedra. If the Boolean parameter is true, abstract values generated with the manager can have strict constraints (like x>0). Otherwise they are defined using only loose constraints. Managers and abstract values in strict or loose mode are incompatible. */ /* ============================================================ */ /* B. Options */ /* ============================================================ */ pk_internal_t* pk_manager_get_internal(ap_manager_t* man); /* For setting options when one has a ap_manager_t object, one can use the APRON function ap_manager_get_internal with a cast. */ void pk_set_max_coeff_size(pk_internal_t* pk, size_t size); void pk_set_approximate_max_coeff_size(pk_internal_t* pk, size_t size); size_t pk_get_max_coeff_size(pk_internal_t* pk); size_t pk_get_approximate_max_coeff_size(pk_internal_t* pk); /* ============================================================ */ /* D. Conversions */ /* ============================================================ */ pk_t* pk_of_abstract0(ap_abstract0_t* abstract); /* Extract from an abstract value the underlying NewPolka polyhedron. There is no copy, and only the argument should be freed. */ ap_abstract0_t* pk_to_abstract0(ap_manager_t* man, pk_t* poly); /* Create an abstract value from the manager and the underlying NewPolka polyhedron. There is no copy, and only the result should be freed */ /* ============================================================ */ /* D. Constructor and destructor for internal manager */ /* ============================================================ */ /* Allocates pk and initializes it with a default size */ struct pk_internal_t* pk_internal_alloc(bool strict); /* Clear and free pk */ void pk_internal_free(pk_internal_t* pk); /* ********************************************************************** */ /* I. General management */ /* ********************************************************************** */ /* ============================================================ */ /* I.1 Memory */ /* ============================================================ */ pk_t* pk_copy(ap_manager_t* man, pk_t* a); /* Return a copy of an abstract value, on which destructive update does not affect the initial value. */ void pk_free(ap_manager_t* man, pk_t* a); /* Free all the memory used by the abstract value */ size_t pk_size(ap_manager_t* man, pk_t* a); /* Return the abstract size of a polyhedron, which is the number of coefficients of its current representation, possibly redundant. */ /* ============================================================ */ /* I.2 Control of internal representation */ /* ============================================================ */ void pk_minimize(ap_manager_t* man, pk_t* a); /* Minimize the size of the representation of a. This may result in a later recomputation of internal information. */ void pk_canonicalize(ap_manager_t* man, pk_t* a); /* Put the polyhedron with minimized constraints and frames. If in addition the integer man->option->canonicalize.algorithm is strictly positive, normalize equalities and lines, and also strict constraints */ int pk_hash(ap_manager_t* man, pk_t* a); /* Return an hash value for the abstract value. Two abstract values in canonical from (according to @code{ap_abstract1_canonicalize}) and considered as equal by the function ap_abstract0_is_eq are given the same hash value (this implies more or less a canonical form). */ void pk_approximate(ap_manager_t* man, pk_t* a, int algorithm); /* Perform some transformation on the abstract value, guided by the field algorithm. Approximation: - algorithm==0: do nothing - algorithm==-1: normalize integer minimal constraints (induces a smaller polyhedron) - algorithm==1: remove constraints with coefficients of size greater than max_coeff_size, if max_coeff_size > 0 - algorithm==2: in addition, keep same bounding box (more precise) - algorithm==3: in addition, keep same bounding octagon (even more precise) - algorithm==10: round constraints with too big coefficients, of size greater than approximate_max_coeff_size, if approximate_max_coeff_size>0 */ /* ============================================================ */ /* I.3 Printing */ /* ============================================================ */ void pk_fprint(FILE* stream, ap_manager_t* man, pk_t* a, char** name_of_dim); /* Print the abstract value in a pretty way, using function name_of_dim to name dimensions */ void pk_fprintdiff(FILE* stream, ap_manager_t* man, pk_t* a1, pk_t* a2, char** name_of_dim); /* Print the difference between a1 (old value) and a2 (new value), using function name_of_dim to name dimensions. The meaning of difference is library dependent. Not implemented */ void pk_fdump(FILE* stream, ap_manager_t* man, pk_t* a); /* Dump the internal representation of an abstract value, for debugging purposes */ /* ============================================================ */ /* I.4 Serialization */ /* ============================================================ */ ap_membuf_t pk_serialize_raw(ap_manager_t* man, pk_t* a); /* Allocate a memory buffer (with malloc), output the abstract value in raw binary format to it and return a pointer on the memory buffer and the size of bytes written. It is the user responsability to free the memory afterwards (with free). Not implemented */ pk_t* pk_deserialize_raw(ap_manager_t* man, void* ptr, size_t* size); /* Return the abstract value read in raw binary format from the input stream and store in size the number of bytes read Not implemented */ /* ********************************************************************** */ /* II. Constructor, accessors, tests and property extraction */ /* ********************************************************************** */ /* ============================================================ */ /* II.1 Basic constructors */ /* ============================================================ */ /* We assume that dimensions [0..intdim-1] correspond to integer variables, and dimensions [intdim..intdim+realdim-1] to real variables */ pk_t* pk_bottom(ap_manager_t* man, size_t intdim, size_t realdim); /* Create a bottom (empty) value */ pk_t* pk_top(ap_manager_t* man, size_t intdim, size_t realdim); /* Create a top (universe) value */ pk_t* pk_of_box(ap_manager_t* man, size_t intdim, size_t realdim, ap_interval_t** tinterval); /* Abstract an hypercube defined by the array of intervals of size intdim+realdim */ /* ============================================================ */ /* II.2 Accessors */ /* ============================================================ */ ap_dimension_t pk_dimension(ap_manager_t* man, pk_t* a); /* Return the total number of dimensions of the abstract values */ /* ============================================================ */ /* II.3 Tests */ /* ============================================================ */ bool pk_is_bottom(ap_manager_t* man, pk_t* a); /* Emptiness test algorithm >= 0: strict behaviour, compute canonical form if necessary algorithm < 0: lazy behaviour, always cheap */ bool pk_is_top(ap_manager_t* man, pk_t* a); /* Universe test algorithm >= 0: strict behaviour, compute canonical form if necessary algorithm < 0: lazy behaviour, always cheap */ bool pk_is_leq(ap_manager_t* man, pk_t* a1, pk_t* a2); /* Inclusion test: Is always strict algorithm > 0: (nearly always) compute canonical forms algorithm <= 0: compute dual representations only if necessary */ bool pk_is_eq(ap_manager_t* man, pk_t* a1, pk_t* a2); /* Equality test: Is always strict Use algorithm field of is_leq. */ bool pk_sat_lincons(ap_manager_t* man, pk_t* a, ap_lincons0_t* lincons); /* Satisfiability of a linear constraint Is always strict algorithm > 0: (nearly always) compute canonical form algorithm <= 0: compute dual representation only if necessary */ bool pk_sat_tcons(ap_manager_t* man, pk_t* a, ap_tcons0_t* cons); /* Satisfiability of a tree expression constraint. */ bool pk_sat_interval(ap_manager_t* man, pk_t* a, ap_dim_t dim, ap_interval_t* interval); /* Inclusion of a dimension in an interval Is always strict algorithm > 0: (nearly always) compute canonical form algorithm <= 0: compute dual representation only if necessary */ bool pk_is_dimension_unconstrained(ap_manager_t* man, pk_t* po, ap_dim_t dim); /* Is a dimension unconstrained ? Is always strict algorithm > 0: compute canonical form algorithm <= 0: compute dual representation only if necessary */ /* ============================================================ */ /* II.4 Extraction of properties */ /* ============================================================ */ ap_interval_t* pk_bound_linexpr(ap_manager_t* man, pk_t* a, ap_linexpr0_t* expr); /* Returns the interval taken by a linear expression over the abstract value. algorithm > 0: compute canonical form algorithm <= 0: compute dual representation only if necessary */ ap_interval_t* pk_bound_texpr(ap_manager_t* man, pk_t* a, ap_texpr0_t* expr); /* Returns the interval taken by a tree expression over the abstract value. */ ap_interval_t* pk_bound_dimension(ap_manager_t* man, pk_t* a, ap_dim_t dim); /* Returns the interval taken by the dimension over the abstract value algorithm > 0: compute canonical form algorithm <= 0: compute dual representation only if necessary */ ap_lincons0_array_t pk_to_lincons_array(ap_manager_t* man, pk_t* a); /* Converts an abstract value to a polyhedra (conjunction of linear constraints). Always consider canonical form */ ap_tcons0_array_t pk_to_tcons_array(ap_manager_t* man, pk_t* a); /* Converts an abstract value to a conjunction of tree expressions constraints. */ ap_interval_t** pk_to_box(ap_manager_t* man, pk_t* a); /* Converts an abstract value to an interval/hypercube. The size of the resulting array is pk_dimension(man,a). This function can be reimplemented by using pk_bound_linexpr algorithm >= 0: compute canonical form algorithm < 0: compute dual representation only if necessary */ ap_generator0_array_t pk_to_generator_array(ap_manager_t* man, pk_t* a); /* Converts an abstract value to a system of generators. Always consider canonical form. */ /* ********************************************************************** */ /* III. Operations */ /* ********************************************************************** */ /* ============================================================ */ /* III.1 Meet and Join */ /* ============================================================ */ pk_t* pk_meet(ap_manager_t* man, bool destructive, pk_t* a1, pk_t* a2); pk_t* pk_join(ap_manager_t* man, bool destructive, pk_t* a1, pk_t* a2); /* Meet and Join of 2 abstract values */ pk_t* pk_meet_array(ap_manager_t* man, pk_t** tab, size_t size); pk_t* pk_join_array(ap_manager_t* man, pk_t** tab, size_t size); /* Meet and Join of a non empty array of abstract values. */ pk_t* pk_meet_lincons_array(ap_manager_t* man, bool destructive, pk_t* a, ap_lincons0_array_t* array); pk_t* pk_meet_tcons_array(ap_manager_t* man, bool destructive, pk_t* a, ap_tcons0_array_t* array); /* Meet of an abstract value with a set of constraints. */ pk_t* pk_add_ray_array(ap_manager_t* man, bool destructive, pk_t* a, ap_generator0_array_t* array); /* Generalized time elapse operator */ /* ============================================================ */ /* III.2 Assignement and Substitutions */ /* ============================================================ */ pk_t* pk_assign_linexpr_array(ap_manager_t* man, bool destructive, pk_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, pk_t* dest); pk_t* pk_substitute_linexpr_array(ap_manager_t* man, bool destructive, pk_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, pk_t* dest); pk_t* pk_assign_texpr_array(ap_manager_t* man, bool destructive, pk_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, pk_t* dest); pk_t* pk_substitute_texpr_array(ap_manager_t* man, bool destructive, pk_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, pk_t* dest); /* Parallel Assignement and Substitution of several dimensions by interval expressons. */ /* ============================================================ */ /* III.3 Projections */ /* ============================================================ */ pk_t* pk_forget_array(ap_manager_t* man, bool destructive, pk_t* a, ap_dim_t* tdim, size_t size, bool project); /* ============================================================ */ /* III.4 Change and permutation of dimensions */ /* ============================================================ */ pk_t* pk_add_dimensions(ap_manager_t* man, bool destructive, pk_t* a, ap_dimchange_t* dimchange, bool project); pk_t* pk_remove_dimensions(ap_manager_t* man, bool destructive, pk_t* a, ap_dimchange_t* dimchange); pk_t* pk_permute_dimensions(ap_manager_t* man, bool destructive, pk_t* a, ap_dimperm_t* permutation); /* ============================================================ */ /* III.5 Expansion and folding of dimensions */ /* ============================================================ */ pk_t* pk_expand(ap_manager_t* man, bool destructive, pk_t* a, ap_dim_t dim, size_t n); /* Expand the dimension dim into itself + n additional dimensions. It results in (n+1) unrelated dimensions having same relations with other dimensions. The (n+1) dimensions are put as follows: - original dimension dim - if the dimension is integer, the n additional dimensions are put at the end of integer dimensions; if it is real, at the end of the real dimensions. */ pk_t* pk_fold(ap_manager_t* man, bool destructive, pk_t* a, ap_dim_t* tdim, size_t size); /* Fold the dimensions in the array tdim of size n>=1 and put the result in the first dimension in the array. The other dimensions of the array are then removed (using pk_permute_remove_dimensions). */ /* ============================================================ */ /* III.6 Widening */ /* ============================================================ */ /* Widening */ pk_t* pk_widening(ap_manager_t* man, pk_t* a1, pk_t* a2); /* ============================================================ */ /* III.7 Closure operation */ /* ============================================================ */ /* Returns the topological closure of a possibly opened abstract value */ pk_t* pk_closure(ap_manager_t* man, bool destructive, pk_t* a); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/newpolka/pk_closure.c0000640014525101416610000000470011023527570021021 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_closure.c: topological closure */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "pk_config.h" #include "pk_vector.h" #include "pk_satmat.h" #include "pk_matrix.h" #include "pk.h" #include "pk_representation.h" #include "pk_constructor.h" /* Either po is just allocated with the right dimensions, or po==pa */ pk_t* pk_closure(ap_manager_t* man, bool destructive, pk_t* pa) { matrix_t* C; bool change,positivity; size_t i; pk_t* po; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_CLOSURE); man->result.flag_best = man->result.flag_exact = true; if (!pk->strict){ return destructive ? pa : pk_copy(man,pa); } if (pk->funopt->algorithm<0) poly_obtain_C(man,pa,"of the argument"); else poly_chernikova(man,pa,"of the argument"); if (!pa->C && !pa->F){ return destructive ? pa : pk_copy(man,pa); } po = destructive ? pa : poly_alloc(pa->intdim,pa->realdim); if (pk->exn){ poly_set_top(pk,po); man->result.flag_best = man->result.flag_exact = false; return po; } if (!destructive){ po->C = matrix_copy(pa->C); } C = po->C; change = false; positivity = false; for (i=0;inbrows; i++){ if (numint_sgn(C->p[i][polka_eps])<0){ if (vector_is_positivity_constraint(pk,C->p[i], C->nbcolumns)){ /* we keep the positivity constraint epsilon<=1 */ positivity = true; } else { change = true; numint_set_int(C->p[i][polka_eps],0); } } } assert(change || positivity); if (change){ if (!positivity){ numint_t* q; size_t nbrows; /* we should add it */ nbrows = C->nbrows; matrix_resize_rows_lazy(C,C->nbrows+1); q = C->p[nbrows]; numint_set_int(q[0],1); numint_set_int(q[polka_cst],1); numint_set_int(q[polka_eps],-1); for (i=3; inbcolumns; i++) numint_set_int(q[i],0); } C->_sorted = false; if (destructive){ if (po->F) matrix_free(po->F); if (po->satC) satmat_free(po->satC); if (po->satF) satmat_free(po->satF); po->F = NULL; po->satC = NULL; po->satF = NULL; po->status = pk_status_conseps; po->nbeq = 0; po->nbline = 0; } } assert(poly_check(pk,po)); return po; } apron-dist-0.9.10/apron/newpolka/pk_assign.h0000640014525101416610000000153510613343214020634 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_assign.h: Assignements and Substitutions */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _PK_ASSIGN_H_ #define _PK_ASSIGN_H_ #include "pk_config.h" #include "pk.h" #ifdef __cplusplus extern "C" { #endif pk_t* poly_asssub_linexpr_det(bool assign, ap_manager_t* man, bool destructive, pk_t* pa, ap_dim_t dim, ap_linexpr0_t* linexpr); pk_t* poly_asssub_linexpr_array_det(bool assign, ap_manager_t* man, bool destructive, pk_t* pa, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/newpolka/pkeq.h0000640014525101416610000003111210760562320017614 0ustar bjeannetpopart/* ********************************************************************** */ /* pkeq.h: Interface of the polka linear equalities library */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef __PKEQ_H__ #define __PKEQ_H__ #ifdef __cplusplus extern "C" { #endif #include "ap_global0.h" #include "pk.h" typedef pk_t pkeq_t; /* Important remark: the newpolka library is normally intended to be accessed through the APRON interface, i.e., through abstract0_XX and abstract1_XX functions. If it is accessed directly with poly_XXX functions, many checks on arguments will not be performed. */ /* ============================================================ */ /* A. Constructor for APRON manager (to be freed with ap_manager_free). */ /* ============================================================ */ ap_manager_t* pkeq_manager_alloc(void); pk_internal_t* pkeq_manager_get_internal(ap_manager_t*); /* ============================================================ */ /* D. Conversions */ /* ============================================================ */ pkeq_t* pkeq_of_abstract0(ap_abstract0_t* abstract); /* Extract from an abstract value the underlying NewPolka polyhedron. There is no copy, so only one of the two objects should be freed. */ ap_abstract0_t* pkeq_to_abstract0(ap_manager_t* man, pkeq_t* poly); /* Create an abstract value from the manager and the underlying NewPolka polyhedron. There is no copy, and only the result should be freed */ /* ********************************************************************** */ /* I. General management */ /* ********************************************************************** */ /* ============================================================ */ /* I.1 Memory */ /* ============================================================ */ pkeq_t* pkeq_copy(ap_manager_t* man, pkeq_t* a); /* Return a copy of an abstract value, on which destructive update does not affect the initial value. */ void pkeq_free(ap_manager_t* man, pkeq_t* a); /* Free all the memory used by the abstract value */ size_t pkeq_size(ap_manager_t* man, pkeq_t* a); /* Return the abstract size of an abstract value (see ap_manager_t) */ /* ============================================================ */ /* I.2 Control of internal representation */ /* ============================================================ */ void pkeq_minimize(ap_manager_t* man, pkeq_t* a); /* Minimize the size of the representation of a. This may result in a later recomputation of internal information. */ void pkeq_canonicalize(ap_manager_t* man, pkeq_t* a); /* Put the abstract value in canonical form. (not yet clear definition) */ void pkeq_hash(ap_manager_t* man, pkeq_t* a); /* Return an hash code */ void pkeq_approximate(ap_manager_t* man, pkeq_t* a, int algorithm); /* Perform some transformation on the abstract value, guided by the field algorithm. The transformation may lose information. */ /* ============================================================ */ /* I.3 Printing */ /* ============================================================ */ void pkeq_fprint(FILE* stream, ap_manager_t* man, pkeq_t* a, char** name_of_dim); /* Print the abstract value in a pretty way, using function name_of_dim to name dimensions */ void pkeq_fprintdiff(FILE* stream, ap_manager_t* man, pkeq_t* a1, pkeq_t* a2, char** name_of_dim); /* Print the difference between a1 (old value) and a2 (new value), using function name_of_dim to name dimensions. The meaning of difference is library dependent. */ void pkeq_fdump(FILE* stream, ap_manager_t* man, pkeq_t* a); /* Dump the internal representation of an abstract value, for debugging purposes */ /* ============================================================ */ /* I.4 Serialization */ /* ============================================================ */ ap_membuf_t pkeq_serialize_raw(ap_manager_t* man, pkeq_t* a); /* Allocate a memory buffer (with malloc), output the abstract value in raw binary format to it and return a pointer on the memory buffer and the size of bytes written. It is the user responsability to free the memory afterwards (with free). */ pkeq_t* pkeq_deserialize_raw(ap_manager_t* man, void* ptr, size_t* size); /* Return the abstract value read in raw binary format from the input stream and store in size the number of bytes read */ /* ********************************************************************** */ /* II. Constructor, accessors, tests and property extraction */ /* ********************************************************************** */ /* ============================================================ */ /* II.1 Basic constructors */ /* ============================================================ */ /* We assume that dimensions [0..intdim-1] correspond to integer variables, and dimensions [intdim..intdim+realdim-1] to real variables */ pkeq_t* pkeq_bottom(ap_manager_t* man, size_t intdim, size_t realdim); /* Create a bottom (empty) value */ pkeq_t* pkeq_top(ap_manager_t* man, size_t intdim, size_t realdim); /* Create a top (universe) value */ pkeq_t* pkeq_of_box(ap_manager_t* man, size_t intdim, size_t realdim, ap_interval_t** tinterval); /* Abstract an hypercube defined by the array of intervals of size intdim+realdim */ pkeq_t* pkeq_of_lincons_array(ap_manager_t* man, size_t intdim, size_t realdim, ap_lincons0_array_t* array); /* Abstract a convex polyhedra defined by the array of linear constraints of size size */ /* ============================================================ */ /* II.2 Accessors */ /* ============================================================ */ ap_dimension_t pkeq_dimension(ap_manager_t* man, pkeq_t* a); /* Return the total number of dimensions of the abstract values */ /* ============================================================ */ /* II.3 Tests */ /* ============================================================ */ bool pkeq_is_bottom(ap_manager_t* man, pkeq_t* a); bool pkeq_is_top(ap_manager_t* man, pkeq_t* a); bool pkeq_is_leq(ap_manager_t* man, pkeq_t* a1, pkeq_t* a2); /* inclusion check */ bool pkeq_is_eq(ap_manager_t* man, pkeq_t* a1, pkeq_t* a2); /* equality check */ bool pkeq_sat_lincons(ap_manager_t* man, pkeq_t* a, ap_lincons0_t* lincons); /* does the abstract value satisfy the linear constraint ? */ bool pkeq_sat_interval(ap_manager_t* man, pkeq_t* a, ap_dim_t dim, ap_interval_t* interval); /* is the dimension included in the interval in the abstract value ? */ bool pkeq_is_dimension_unconstrained(ap_manager_t* man, pkeq_t* po, ap_dim_t dim); /* is the dimension unconstrained ? */ /* ============================================================ */ /* II.4 Extraction of properties */ /* ============================================================ */ ap_interval_t* pkeq_bound_linexpr(ap_manager_t* man, pkeq_t* a, ap_linexpr0_t* expr); /* Returns the interval taken by a linear expression over the abstract value */ ap_interval_t* pkeq_bound_dimension(ap_manager_t* man, pkeq_t* a, ap_dim_t dim); /* Returns the interval taken by the dimension over the abstract value */ ap_lincons0_array_t pkeq_to_lincons_array(ap_manager_t* man, pkeq_t* a); /* Converts an abstract value to a polyhedra (conjunction of linear constraints). */ ap_interval_t** pkeq_to_box(ap_manager_t* man, pkeq_t* a); /* Converts an abstract value to an interval/hypercube. The size of the resulting array is pkeq_dimension(man,a). This function can be reimplemented by using pkeq_bound_linexpr */ ap_generator0_array_t pkeq_to_generator_array(ap_manager_t* man, pkeq_t* a); /* Converts an abstract value to a system of generators. */ /* ********************************************************************** */ /* III. Operations */ /* ********************************************************************** */ /* ============================================================ */ /* III.1 Meet and Join */ /* ============================================================ */ pkeq_t* pkeq_meet(ap_manager_t* man, bool destructive, pkeq_t* a1, pkeq_t* a2); pkeq_t* pkeq_join(ap_manager_t* man, bool destructive, pkeq_t* a1, pkeq_t* a2); /* Meet and Join of 2 abstract values */ pkeq_t* pkeq_meet_array(ap_manager_t* man, pkeq_t** tab, size_t size); pkeq_t* pkeq_join_array(ap_manager_t* man, pkeq_t** tab, size_t size); /* Meet and Join of an array of abstract values. Raises an [[exc_invalid_argument]] exception if [[size==0]] (no way to define the dimensionality of the result in such a case */ pkeq_t* pkeq_meet_lincons_array(ap_manager_t* man, bool destructive, pkeq_t* a, ap_lincons0_array_t* array); /* Meet of an abstract value with a set of constraints (generalize pkeq_of_lincons_array) */ pkeq_t* pkeq_add_ray_array(ap_manager_t* man, bool destructive, pkeq_t* a, ap_generator0_array_t* array); /* Generalized time elapse operator */ /* ============================================================ */ /* III.2 Assignement and Substitutions */ /* ============================================================ */ pkeq_t* pkeq_assign_linexpr(ap_manager_t* man, bool destructive, pkeq_t* a, ap_dim_t dim, ap_linexpr0_t* expr, pkeq_t* dest); pkeq_t* pkeq_substitute_linexpr(ap_manager_t* man, bool destructive, pkeq_t* a, ap_dim_t dim, ap_linexpr0_t* expr, pkeq_t* dest); /* Assignement and Substitution of a single dimension by resp. a linear expression and a interval linear expression */ pkeq_t* pkeq_assign_linexpr_array(ap_manager_t* man, bool destructive, pkeq_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, pkeq_t* dest); pkeq_t* pkeq_substitute_linexpr_array(ap_manager_t* man, bool destructive, pkeq_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, pkeq_t* dest); /* Parallel Assignement and Substitution of several dimensions by linear expressons. */ /* ============================================================ */ /* III.3 Projections */ /* ============================================================ */ pkeq_t* pkeq_forget_array(ap_manager_t* man, bool destructive, pkeq_t* a, ap_dim_t* tdim, size_t size, bool project); /* ============================================================ */ /* III.4 Change and permutation of dimensions */ /* ============================================================ */ pkeq_t* pkeq_add_dimensions(ap_manager_t* man, bool destructive, pkeq_t* a, ap_dimchange_t* dimchange, bool project); pkeq_t* pkeq_remove_dimensions(ap_manager_t* man, bool destructive, pkeq_t* a, ap_dimchange_t* dimchange); pkeq_t* pkeq_permute_dimensions(ap_manager_t* man, bool destructive, pkeq_t* a, ap_dimperm_t* permutation); /* ============================================================ */ /* III.5 Expansion and folding of dimensions */ /* ============================================================ */ pkeq_t* pkeq_expand(ap_manager_t* man, bool destructive, pkeq_t* a, ap_dim_t dim, size_t n); /* Expand the dimension dim into itself + n additional dimensions. It results in (n+1) unrelated dimensions having same relations with other dimensions. The (n+1) dimensions are put as follows: - original dimension dim - if the dimension is integer, the n additional dimensions are put at the end of integer dimensions; if it is real, at the end of the real dimensions. */ pkeq_t* pkeq_fold(ap_manager_t* man, bool destructive, pkeq_t* a, ap_dim_t* tdim, size_t size); /* Fold the dimensions in the array tdim of size n>=1 and put the result in the first dimension in the array. The other dimensions of the array are then removed (using pkeq_permute_remove_dimensions). */ /* ============================================================ */ /* III.6 Widening */ /* ============================================================ */ /* Widening */ pkeq_t* pkeq_widening(ap_manager_t* man, pkeq_t* a1, pkeq_t* a2); /* ============================================================ */ /* III.7 Closure operation */ /* ============================================================ */ /* Returns the topological closure of a possibly opened abstract value */ pkeq_t* pkeq_closure(ap_manager_t* man, bool destructive, pkeq_t* a); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/newpolka/pk_user.h0000640014525101416610000000634510662337504020343 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_user.h: conversions with interface datatypes */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ /* This header file defines operations on vectors. A vector is just an array of elements of type pkint_t, as a consequence functions need to be given also their size. */ #ifndef __PK_USER_H__ #define __PK_USER_H__ #include "pk_config.h" #include "pk_internal.h" #include "pk_vector.h" #include "pk_matrix.h" #ifdef __cplusplus extern "C" { #endif /* From ITV to PK */ /* Fills the vector with the constraint: dim <= bound if sgn>0, dim = bound if sgn=0 dim >= bound if sgn<0 bound is assumed <> oo. Returns false if equality of an integer dimension with a non-integer numbers */ bool vector_set_dim_bound(pk_internal_t* pk, numint_t* vec, ap_dim_t dim, numrat_t numrat, int mode, size_t intdim, size_t realdim, bool integer); bool vector_set_linexpr_bound(pk_internal_t* pk, numint_t* vec, numint_t* vec2, numrat_t numrat, int mode, size_t intdim, size_t realdim, bool integer); /* Fills the vector with the quasi-linear expression (itv_linexpr) */ void vector_set_itv_linexpr(pk_internal_t* pk, numint_t* vec, itv_linexpr_t* expr, size_t dim, int mode); /* Fills the vector(s) with the linear constraint cons */ void vector_set_itv_lincons(pk_internal_t* pk, numint_t* vec, itv_lincons_t* cons, size_t intdim, size_t realdim, bool integer); /* Fills the vector(s) with the linear constraint cons for testing satisfiability. Returns false if unsatisfiable */ bool vector_set_itv_lincons_sat(pk_internal_t* pk, numint_t* vec, itv_lincons_t* cons, size_t intdim, size_t realdim, bool integer); /* From APRON to PK */ /* Fills the vector with the generator gen. */ bool vector_set_ap_generator0(pk_internal_t* pk, numint_t* vec, ap_generator0_t* gen, size_t intdim, size_t realdim); bool matrix_set_ap_generator0_array(pk_internal_t* pk, matrix_t** matrix, ap_generator0_array_t* array, size_t intdim, size_t realdim); /* bool matrix_set_ap_lincons0_array(pk_internal_t* pk, matrix_t** mat, size_t** tabindex, size_t* size, ap_lincons0_array_t* array, size_t intdim, size_t realdim, bool integer); bool matrix_set_ap_intlincons0_array(pk_internal_t* pk, matrix_t** mat, itv_t* titv, ap_lincons0_array_t* array, size_t* tab, size_t size, size_t intdim, size_t realdim, bool integer); */ /* From ITV to PK */ bool matrix_set_itv_lincons_array(pk_internal_t* pk, matrix_t** mat, itv_lincons_array_t* array, size_t intdim, size_t realdim, bool integer); /* From PK to APRON */ ap_lincons0_t lincons0_of_vector(pk_internal_t* pk, numint_t* q, size_t size); ap_generator0_t generator0_of_vector(pk_internal_t* pk, numint_t* q, size_t size); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/newpolka/pk_cherni.h0000640014525101416610000001031311247462105020617 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_cherni.h: Conversion from one representation to the dual one. */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ /* This header file define operations allowing to convert polyhedra from one representation to the dual one. */ #ifndef __PK_CHERNI_H__ #define __PK_CHERNI_H__ #include "pk_config.h" #include "pk_vector.h" #include "pk_satmat.h" #include "pk_matrix.h" #include "pk.h" #ifdef __cplusplus extern "C" { #endif /* Functions meant to be internal */ /* ********************************************************************** */ /* Checking */ /* ********************************************************************** */ bool cherni_checksatmat(pk_internal_t* pk, bool con_to_ray, matrix_t* C, matrix_t* F, satmat_t* satC); /* Recompute the saturation matrix of C and F and checks the equality with satC. */ bool cherni_checksat(pk_internal_t* pk, bool con_to_ray, matrix_t* C, size_t nbequations, matrix_t* F, size_t nblines, satmat_t* satC); /* Check the saturation numbers of constraints and rays. */ /* ********************************************************************** */ /* Conversion algorithm */ /* ********************************************************************** */ size_t cherni_conversion(pk_internal_t* pk, matrix_t* con, size_t start, matrix_t* ray, satmat_t* satc, size_t nbline); /* Compute the dual form of con. - con is the constraints matrix, - start indicates the number of constraints supposed to be already taken in account, - ray is the frames matrix, with the start first constraints taken in account, - satc is the saturation matrix initialized according to con and ray, - nbline indicates the number of lines in ray. For the saturation matrix, we suppose that Unused bits of existing rows are set to zero. Each time a row is added, this hypothese must remain true. The saturation matrix is organised as follows: - the rows are indexed by generators, - the columns by constraints. The result is given by ray, sat and the returned number of lines. */ size_t cherni_gauss(pk_internal_t* pk, matrix_t* con, size_t nbeq); /* The function finds a minimal system for equalities, and returns the rank *r* of this system, equations of which are numbered from 0 to *r-1*. Redundant (now null) equations are put between row *r* and row *nbeq*. The function also fills the array *pk->cherni_intp* which indicates the ``main'' coefficent of an equation, in this case the left-most non-zero one. */ void cherni_backsubstitute(pk_internal_t* pk, matrix_t* con, size_t rank); /* This function backsubstitute the coefficients according to the system of equations and the array pk->cherni_intp properly set by gauss. */ int cherni_simplify(pk_internal_t* pk, matrix_t* con, matrix_t* ray, satmat_t* satf, const size_t nbline); /* We suppose that we just obtained ray and satc from con with the chernikova algorithm. As a consequence the system of rays is minimal. satf is the transposed matrix of satc, i.e. rows are indexed by constraints. con is supposed to be non empty. We have still to simplify con by detecting new equality constraints, removing redundant inequalities, and obtaining a minimal system of equalities (by a call to gauss). Then backsubstitution is performed on (minimal) inequalities. */ void cherni_minimize(pk_internal_t* pk, bool con_to_ray, pk_t* po); void cherni_add_and_minimize(pk_internal_t* pk, bool con_to_ray, pk_t* po, size_t start); /* Misc */ void cherni_buildsatline(pk_internal_t* pk, matrix_t* con, numint_t* tab, bitstring_t* satline); /* Library is supposed to be in strict mode (pk->strict==true), polyhedron is supposed to be in double representation, with nbeq and nbline correctly initialized, and with saturation matrix satF (row i of satF refers to constraint i, column k refers to ray k). */ bool cherni_minimizeeps(pk_internal_t* pk, pk_t* po); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/newpolka/test_environment.c0000640014525101416610000000560210662337504022264 0ustar bjeannetpopart/* ********************************************************************** */ /* test_environment.c: testing of environment */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "ap_expr0.h" #include "ap_environment.h" int main(int argc, char**argv) { size_t i; environment_t* e1; environment_t* e2; environment_t* e3; environment_t* e4; environment_t* e5; dim_t* perm1; dim_t* perm2; var_t name_of_intdim1[3] = { "a30","a10","a20" }; var_t name_of_realdim1[3] = { "a11","a31","a21" }; var_t name_of_intdim2[4] = { "a2","a0","a22","a24" }; var_t name_of_realdim2[4] = { "a27","a23","a33","a37" }; var_t name_of_intdim5[4] = { "a2","a10","a22","a20" }; var_t name_of_realdim5[4] = { "a27","a31","a11","a37" }; e1 = environment_make_empty(); environment_ref(e1); environment_fdump(stdout,e1); environment_deref(e1); e1 = environment_make(name_of_intdim1,3, name_of_realdim1,3); environment_ref(e1); environment_fdump(stdout,e1); e2 = environment_make(name_of_intdim2,4, name_of_realdim2,4); environment_ref(e2); environment_fdump(stdout,e2); e5 = environment_make(name_of_intdim5,4, name_of_realdim5,4); environment_ref(e5); environment_fdump(stdout,e5); e3 = environment_add(e1,name_of_intdim2,4, name_of_realdim2,4); environment_ref(e3); environment_fdump(stdout,e3); e4 = environment_add(e2,name_of_intdim1,3, name_of_realdim1,3); environment_ref(e4); environment_fdump(stdout,e4); for(i=0; iintdim+e4->realdim; i++){ var_t var = environment_var_of_dim(e4,i); dim_t dim = environment_dim_of_var(e4,var); printf("i=%d, var=%s, dim=%d\n",i,var,dim); } environment_deref(e4); environment_deref(e3); e4 = environment_remove(e5,name_of_intdim2,4, name_of_realdim2,4); environment_ref(e4); environment_fdump(stdout,e4); environment_deref(e4); e3 = environment_lce(e1,e2,&perm1,&perm2); environment_ref(e3); environment_fdump(stdout,e3); permutation_fprint(stdout,perm1,e3->intdim+e3->realdim); permutation_fprint(stdout,perm2,e3->intdim+e3->realdim); free(perm1); free(perm2); e4 = environment_lce(e3,e2,&perm1,&perm2); assert(e3==e4); environment_ref(e4); environment_fdump(stdout,e4); assert(perm1==NULL); permutation_fprint(stdout,perm2,e3->intdim+e3->realdim); free(perm2); environment_deref(e3); environment_deref(e4); e3 = environment_lce(e1,e5,&perm1,&perm2); environment_ref(e3); environment_fdump(stdout,e3); permutation_fprint(stdout,perm1,e3->intdim+e3->realdim); permutation_fprint(stdout,perm2,e3->intdim+e3->realdim); free(perm1); free(perm2); environment_deref(e3); environment_deref(e1); environment_deref(e2); environment_deref(e5); } apron-dist-0.9.10/apron/newpolka/pk_bit.h0000640014525101416610000000364010571032754020134 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_bit.h: operations on bitstrings */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ /* This header file define operations on \emph{bitstrings} and \emph{bitindices}, to be used to access and modify bitstrings. */ /* The type \verb-bitstring_t- is simply an integer, which is an element of an array. An structured index of a bit in a bitfield is a pair $(w,b)$ where $w$ reference the considered integer and $b$ is a mask selecting the right bit. */ #ifndef __PK_BIT_H__ #define __PK_BIT_H__ #ifdef __cplusplus extern "C" { #endif typedef unsigned int bitstring_t; typedef struct bitindex_t { size_t index; size_t word; bitstring_t bit; } bitindex_t; #define bitstring_size (sizeof(bitstring_t)*8) #define bitstring_msb (1U<<(bitstring_size-1)) /* Operations on \verb-bitindex_t- */ void bitindex_print(bitindex_t* bi); void bitindex_fprint(FILE* stream, bitindex_t* bi); bitindex_t bitindex_init(size_t col); void bitindex_inc(bitindex_t*); void bitindex_dec(bitindex_t*); size_t bitindex_size(size_t n); /* Operations on \verb-bitstring_t- */ bitstring_t* bitstring_alloc(size_t n); bitstring_t* bitstring_realloc(bitstring_t* b, size_t n); void bitstring_free(bitstring_t* b); void bitstring_clear(bitstring_t* b, size_t size); void bitstring_copy(bitstring_t* b2, bitstring_t* b1, size_t size); int bitstring_cmp(bitstring_t* r1, bitstring_t* r2, size_t size); void bitstring_print(bitstring_t* b, size_t size); void bitstring_fprint(FILE* stream, bitstring_t* b, size_t size); int bitstring_get(bitstring_t* b, bitindex_t ix); void bitstring_set(bitstring_t* b, bitindex_t ix); void bitstring_clr(bitstring_t* b, bitindex_t ix); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/newpolka/pk_config.h0000640014525101416610000000526711005654323020625 0ustar bjeannetpopart /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _PK_CONFIG_H_ #define _PK_CONFIG_H_ #include #include #include #include "num.h" #include "numint.h" #include "numrat.h" #include "bound.h" #include "itv.h" #include "itv_linexpr.h" #include "ap_coeff.h" #include "ap_dimension.h" #include "ap_expr0.h" #include "ap_manager.h" #ifdef __cplusplus #define HAS_BOOL extern "C" { #endif #ifndef HAS_BOOL #define HAS_BOOL typedef char bool; static const bool false = 0; static const bool true = 1; #endif /* Extension to the num package */ /* size in words */ static inline size_t numint_size(numint_t a) #if defined (NUMINT_NATIVE) { return 1; } #elif defined(NUMINT_MPZ) { return mpz_size(a); } #else #error "Here" #endif /* size in bits */ #if defined (NUMINT_NATIVE) #if defined(NUMINT_LONGINT) || defined(NUMINT_LONGLONGINT) #if defined(__GNUC__) static inline size_t numint_size2(numint_t a) { numint_t x; if (a==0) return 0; numint_abs(x,a); return (size_t)( sizeof(numint_t)*8 - #if defined(NUMINT_LONGINT) __builtin_clzl((unsigned long int)(*x)) #else __builtin_clzll((unsigned long long int)(*x)) #endif ); } #else static inline size_t numint_size2(numint_t a) { numint_t x; size_t nbzero; static size_t table[256] = { 8, 7, 6,6, 5,5,5,5, 4,4,4,4,4,4,4,4, 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } if (a==0) return 0; numint_abs(x,a); /* Iterate over leading zero octets */ #if defined(NUMINT_LONGINT) unsigned long int mask = (0xffUL << (sizeof(numint_t)-1)*8); #else unsigned long long int mask = (0xffULL << (sizeof(numint_t)-1)*8); #endif nbzero = 0; while ( (*x & *mask)==0 ){ nbzero += 8; *mask = *mask >> 256; } *x = (*x & *mask) >> ((sizeof(numint_t)-1)*8 - nbzero); nbzero += table[*x]; return (sizeof(numint_t)*8 - nbzero); } #endif #else #error "Here" #endif #elif defined(NUMINT_MPZ) static inline size_t numint_size2(numint_t a) { return mpz_sizeinbase(a,2); } #else #error "Here" #endif /* Do not change ! */ static const size_t polka_cst = 1; static const size_t polka_eps = 2; #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/newpolka/pk_project.c0000640014525101416610000000737211023527570021023 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_project.c: projections */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "pk_config.h" #include "pk_vector.h" #include "pk_bit.h" #include "pk_satmat.h" #include "pk_matrix.h" #include "pk.h" #include "pk_user.h" #include "pk_constructor.h" #include "pk_assign.h" #include "pk_meetjoin.h" #include "pk_representation.h" /* ********************************************************************** */ /* I. Factorized form */ /* ********************************************************************** */ static void poly_projectforget_array(bool project, bool lazy, ap_manager_t* man, pk_t* po, pk_t* pa, ap_dim_t* tdim, size_t size) { bool res; matrix_t* mat; size_t i,j; pk_internal_t* pk = (pk_internal_t*)man->internal; pk_internal_realloc_lazy(pk,pa->intdim+pa->realdim); res = false; /* Get the generator systems, and possibly minimize */ if (lazy) poly_obtain_F(man,pa,"of the argument"); else poly_chernikova(man,pa,"of the argument"); if (pk->exn){ pk->exn = AP_EXC_NONE; if (!pa->F){ man->result.flag_best = man->result.flag_exact = false; poly_set_top(pk,po); return; } } /* if empty, return empty */ if (!pa->F){ man->result.flag_best = man->result.flag_exact = true; poly_set_bottom(pk,po); return; } if (project){ /* Project: assign the dimension to zero */ if (po==pa){ /* Forget the other matrices */ if (po->C){ matrix_free(po->C); po->C = NULL; } if (po->satC){ satmat_free(po->satC); po->satC = NULL; } if (po->satF){ satmat_free(po->satF); po->satF = NULL; } } else { /* Copy the old one */ po->F = matrix_copy(pa->F); } mat = po->F; for (i=0; inbrows; i++){ for (j=0; jp[i][pk->dec+tdim[j]],0); } matrix_normalize_row(pk,mat,(size_t)i); } po->status = 0; if (!lazy){ poly_chernikova(man,po,"of the result"); } } else { /* Forget */ mat = matrix_alloc(size,pa->F->nbcolumns,false); for (i=0; ip[i][pk->dec+tdim[i]],1); } matrix_sort_rows(pk,mat); poly_dual(pa); if (po!=pa) poly_dual(po); if (!lazy) poly_obtain_satC(pa); res = poly_meet_matrix(false,lazy,man,po,pa,mat); poly_dual(pa); if (po!=pa) poly_dual(po); matrix_free(mat); } if (res || pk->exn){ pk->exn = AP_EXC_NONE; if (!po->F){ man->result.flag_best = man->result.flag_exact = false; poly_set_top(pk,po); return; } } if (pk->funopt->flag_best_wanted || pk->funopt->flag_exact_wanted){ bool real = true; if (pa->intdim>0){ for (i=0; iintdim){ real = false; break; } } } man->result.flag_best = man->result.flag_exact = real; } else { man->result.flag_best = man->result.flag_exact = pa->intdim==0; } } /* ********************************************************************** */ /* II. Exported functions */ /* ********************************************************************** */ pk_t* pk_forget_array(ap_manager_t* man, bool destructive, pk_t* pa, ap_dim_t* tdim, size_t size, bool project) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_FORGET_ARRAY); pk_t* po = destructive ? pa : poly_alloc(pa->intdim,pa->realdim); poly_projectforget_array(project, pk->funopt->algorithm<=0, man,po,pa,tdim,size); assert(poly_check(pk,po)); return po; } apron-dist-0.9.10/apron/newpolka/pk_resize.h0000640014525101416610000000160210613136246020651 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_resize.h: change and permutation of dimensions */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ /* This header file define operations allowing to convert polyhedra from one representation to the dual one. */ #ifndef __PK_RESIZE_H__ #define __PK_RESIZE_H__ #include "pk_config.h" #include "pk.h" #ifdef __cplusplus extern "C" { #endif void vector_remove_dimensions(pk_internal_t* pk, numint_t* newq, numint_t* q, size_t size, ap_dimchange_t* dimchange); matrix_t* matrix_add_dimensions(pk_internal_t* pk, bool destructive, matrix_t* mat, ap_dimchange_t* dimchange); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/newpolka/pk_resize.c0000640014525101416610000002731110723557216020657 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_resize.c: change and permutation of dimensions */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "pk_config.h" #include "pk_vector.h" #include "pk_bit.h" #include "pk_satmat.h" #include "pk_matrix.h" #include "pk.h" #include "pk_representation.h" #include "pk_user.h" #include "pk_constructor.h" #include "pk_resize.h" /* ********************************************************************** */ /* I. Vectors */ /* ********************************************************************** */ /* Apply the permutation permutation. The result is stored in newq. The array permutation is supposed to be of size size-pk->dec. BE CAUTIOUS: value 0 in the permutation means columns pk->dec. */ static void vector_permute_dimensions(pk_internal_t* pk, numint_t* newq, numint_t* q, size_t size, ap_dim_t* permut) { bool destructive; size_t j,newj; numint_t* nq; destructive = (newq==q); /* Where to write ? If destructive, we write in a temporary vector otherwise we write in the destination */ nq = destructive ? pk->vector_numintp : newq; /* Fill the non-permuted fields */ for (j=0; jdec && jdec; jdec] + pk->dec; numint_set(nq[newj],q[j]); } if (destructive){ for(j=0; jdec && i<(int)size; i++) numint_set(newq[i],q[i]); } dimsup = dimchange->intdim+dimchange->realdim; k = dimsup; for (i=(int)(size)-(int)pk->dec; i>=0; i--){ if (i<(int)size-(int)pk->dec){ numint_set(newq[pk->dec+i+k],q[pk->dec+i]); } while (k>=1 && dimchange->dim[k-1]==(ap_dim_t)i){ k--; numint_set_int(newq[pk->dec+i+k],0); } } } void vector_remove_dimensions(pk_internal_t* pk, numint_t* newq, numint_t* q, size_t size, ap_dimchange_t* dimchange) { size_t i,k,dimsup; if (newq!=q){ for (i=0;idec && iintdim+dimchange->realdim; k=0; for (i=0; idec; i++){ while (kdim[k]==i+k){ k++; } numint_set(newq[pk->dec+i],q[pk->dec+i+k]); } } /* ====================================================================== */ /* II. Matrices */ /* ====================================================================== */ /* Modifications of the number of columns in-place */ static void matrix_resize_diffcols(matrix_t* mat, int diff) { if (diff != 0){ size_t i; for(i=0; i_maxrows; i++){ vector_realloc(&mat->p[i], mat->nbcolumns, mat->nbcolumns+diff); } mat->nbcolumns += diff; } } matrix_t* matrix_add_dimensions(pk_internal_t* pk, bool destructive, matrix_t* mat, ap_dimchange_t* dimchange) { matrix_t* nmat; size_t i,dimsup; dimsup = dimchange->intdim+dimchange->realdim; if (destructive){ nmat = mat; matrix_resize_diffcols(nmat,(int)dimsup); } else { nmat = matrix_alloc(mat->nbrows,mat->nbcolumns+dimsup,mat->_sorted); } for (i=0; inbrows; i++){ vector_add_dimensions(pk,nmat->p[i],mat->p[i],nmat->nbcolumns-dimsup,dimchange); } return nmat; } static matrix_t* matrix_remove_dimensions(pk_internal_t* pk, bool destructive, matrix_t* mat, ap_dimchange_t* dimchange) { matrix_t* nmat; size_t i,dimsup; dimsup = dimchange->intdim + dimchange->realdim; nmat = destructive ? mat : matrix_alloc(mat->nbrows, mat->nbcolumns-dimsup, false); for (i=0; inbrows; i++){ vector_remove_dimensions(pk, nmat->p[i], mat->p[i], mat->nbcolumns, dimchange); vector_normalize(pk,nmat->p[i],mat->nbcolumns-dimsup); } if (destructive){ matrix_resize_diffcols(nmat, -(int)dimsup); } nmat->_sorted = false; return nmat; } static matrix_t* matrix_permute_dimensions(pk_internal_t* pk, bool destructive, matrix_t* mat, ap_dim_t* permutation) { matrix_t* nmat; size_t i; nmat = destructive ? mat : matrix_alloc(mat->nbrows,mat->nbcolumns,false); for (i=0; inbrows; i++){ vector_permute_dimensions(pk,nmat->p[i],mat->p[i],mat->nbcolumns,permutation); } nmat->_sorted = false; return nmat; } /* ********************************************************************** */ /* III. Factorized forms */ /* ********************************************************************** */ /* Standard case of the following functions: addition of dimensions, and embedding the polyhedron in the new space. Dual version, with new dimensions sets at 0: exchanging constraints and generators. */ static pk_t* cherni_add_dimensions(pk_internal_t* pk, bool destructive, pk_t* pa, ap_dimchange_t* dimchange) { pk_t* po; int i,k; size_t dimsup; dimsup = dimchange->intdim + dimchange->realdim; if (destructive){ po = pa; po->intdim += dimchange->intdim; po->realdim += dimchange->realdim; } else { po = poly_alloc(pa->intdim + dimchange->intdim, pa->realdim + dimchange->realdim); po->status = pa->status; } if (pa->C || pa->F){ /* Get pa->satC if possible */ if (pa->satF && pa->satC==NULL){ (pa)->satC = satmat_transpose(pa->satF,pa->F->nbrows); } /* Extend constraints */ if (pa->C){ po->C = matrix_add_dimensions(pk,destructive,pa->C,dimchange); po->C->_sorted = false; } /* Extend generators and add new lines */ if (pa->F){ size_t nbrows = pa->F->nbrows; po->F = matrix_add_dimensions(pk,destructive,pa->F,dimchange); matrix_resize_rows_lazy(po->F,po->F->nbrows+dimsup); /* translate rows [0,oldF->nbrows-1] to [dimsup,oldF->nbrows+dimsup-1] */ matrix_move_rows(po->F,dimsup,0,nbrows); /* addition of new lines at the beginning of the matrix */ k=dimsup-1; for (i=po->intdim+po->realdim - dimsup; i>=0; i--){ while (k>=0 && dimchange->dim[k]==(ap_dim_t)i){ vector_clear(po->F->p[dimsup-1-k],po->F->nbcolumns); numint_set_int(po->F->p[dimsup-1-k][pk->dec+i+k], 1); k--; } if (k<0) break; } po->F->_sorted = pa->F->_sorted && (matrix_compare_rows(pk,po->F,dimsup-1,dimsup) < 0); } if (pa->satC){ if (destructive){ satmat_resize_rows(po->satC,po->satC->nbrows+dimsup); /* translate rows [0,oldF->nbrows-1] to [dimsup,oldF->nbrows+dimsup-1] */ satmat_move_rows(po->satC,dimsup,0,po->F->nbrows-dimsup); /* the first rows, corresponding to new lines, to zero */ for (i=0; i<(int)dimsup; i++){ bitstring_clear(po->satC->p[i],po->satC->nbcolumns); } } else { po->satC = satmat_alloc(pa->satC->nbrows+dimsup, pa->satC->nbcolumns); /* the first rows, corresponding to new lines, are already zero */ for (i=0; i<(int)pa->satC->nbrows; i++){ bitstring_copy(po->satC->p[dimsup+i],pa->satC->p[i],pa->satC->nbcolumns); } } } /* New saturation matrix: we cannot work with satF */ if (destructive && dimsup>0 && po->satF){ satmat_free(po->satF); po->satF=NULL; } if (pa->C && pa->F){ po->nbeq = pa->nbeq; po->nbline = pa->nbline+dimsup; } else { po->nbeq = 0; po->nbline = 0; } } return po; } /* ====================================================================== */ /* ====================================================================== */ /* ********************************************************************** */ /* IV. Exported functions */ /* ********************************************************************** */ pk_t* pk_add_dimensions(ap_manager_t* man, bool destructive, pk_t* pa, ap_dimchange_t* dimchange, bool project) { pk_t* po; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_ADD_DIMENSIONS); pk_internal_realloc_lazy(pk,pa->intdim+pa->realdim+dimchange->intdim+dimchange->realdim); if (pk->funopt->algorithm>0){ /* Minimize the argument */ poly_chernikova(man,pa,"of the argument"); if (pk->exn){ pk->exn = AP_EXC_NONE; /* we can still operate on the available matrix */ } } /* Return empty if empty */ if (!pa->C && !pa->F){ man->result.flag_best = man->result.flag_exact = true; if (destructive){ pa->intdim += dimchange->intdim; pa->realdim += dimchange->realdim; return pa; } else { return pk_bottom(man, pa->intdim + dimchange->intdim, pa->realdim + dimchange->realdim); } } if (project){ poly_dual(pa); po = cherni_add_dimensions(pk, destructive, pa, dimchange); poly_dual(po); if (!destructive) poly_dual(pa); } else { po = cherni_add_dimensions(pk, destructive, pa, dimchange); } assert(poly_check(pk,po)); return po; } pk_t* pk_remove_dimensions(ap_manager_t* man, bool destructive, pk_t* pa, ap_dimchange_t* dimchange) { pk_t* po; size_t dimsup; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_REMOVE_DIMENSIONS); if (pk->funopt->algorithm<=0){ poly_obtain_F(man,pa,"of the argument"); } else { poly_chernikova(man,pa,"of the argument"); } if (destructive){ po = pa; po->intdim -= dimchange->intdim; po->realdim -= dimchange->realdim; po->status = 0; po->nbeq = po->nbline = 0; } else { po = poly_alloc(pa->intdim - dimchange->intdim, pa->realdim - dimchange->realdim); } if (pk->exn){ pk->exn = AP_EXC_NONE; if (!pa->F){ man->result.flag_best = man->result.flag_exact = false; poly_set_top(pk,po); return po; } /* We can still work with pa->F */ } /* Return empty if empty */ if (!pa->C && !pa->F){ man->result.flag_best = man->result.flag_exact = true; if (!destructive){ poly_set_bottom(pk,po); } return po; } if (po->C){ matrix_free(po->C); po->C = NULL; } if (po->satC){ satmat_free(po->satC); po->satC = NULL; } if (po->satF){ satmat_free(po->satF); po->satF = NULL; } dimsup = dimchange->intdim+dimchange->realdim; po->F = matrix_remove_dimensions(pk,destructive,pa->F,dimchange); if (pk->funopt->algorithm>0){ poly_chernikova(man,po,"of the result"); if (pk->exn){ pk->exn = AP_EXC_NONE; } } man->result.flag_best = man->result.flag_exact = dimchange->intdim==0; assert(poly_check(pk,po)); return po; } pk_t* pk_permute_dimensions(ap_manager_t* man, bool destructive, pk_t* pa, ap_dimperm_t* permutation) { pk_t* po; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_PERMUTE_DIMENSIONS); if (pk->funopt->algorithm>0){ /* Minimize the argument */ poly_chernikova(man,pa,"of the argument"); if (pk->exn){ pk->exn = AP_EXC_NONE; /* we can still operate on the available matrix */ } } man->result.flag_best = man->result.flag_exact = true; po = destructive ? pa : poly_alloc(pa->intdim,pa->realdim); if (pa->C){ po->C = matrix_permute_dimensions(pk,destructive,pa->C,permutation->dim); } if (pa->F){ po->F = matrix_permute_dimensions(pk,destructive,pa->F,permutation->dim); } if (!destructive){ po->satC = pa->satC ? satmat_copy(pa->satC) : NULL; po->satF = pa->satF ? satmat_copy(pa->satF) : NULL; po->nbline = pa->nbline; po->nbeq = pa->nbeq; po->status = pa->status; } assert(poly_check(pk,po)); return po; } apron-dist-0.9.10/apron/newpolka/test.c0000640014525101416610000013667310723557216017657 0ustar bjeannetpopart/* ********************************************************************** */ /* test.c: unit testing */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include "permutation.h" #include "pk_config.h" #include "pk_vector.h" #include "pk_satmat.h" #include "pk_matrix.h" #include "pk.h" #include "pk_representation.h" #include "pk_constructor.h" #include "pk_extract.h" #include "pk_test.h" #include "pk_meetjoin.h" #include "pk_resize.h" #include "pk_assign.h" #include "pk_project.h" static size_t count = 0; /* ********************************************************************** */ /* Vectors */ /* ********************************************************************** */ void vector(pk_internal_t* pk, size_t nbdims, numint_t factor) { size_t size; numint_t* q[5]; numint_t* r1; int i,j; bool change; pk_internal_realloc_lazy(pk,30); size = pk->dec + nbdims; for (i=1; i<=4; i++) q[i] = vector_alloc(size); /* q[1] = [0 10 [0] 1 2 3 4 ...] * factor */ numint_set_int(q[1][polka_cst],10L); for (i=pk->dec; idec+1)); numint_mul(q[1][i],q[1][i],factor); } vector_print(q[1],size); /* q[2] = [1 10 [-2] 1 2 3 4 ...] * factor */ vector_copy(q[2],q[1],size); numint_set_int(q[2][0],1); if (pk->strict) numint_set_int(q[2][polka_eps],-2); vector_print(q[2],size); /* q[3] = [1 10 [0] size-1 size-2 ... ] * 2 * factor */ numint_set_int(q[3][0],1); numint_set_int(q[3][polka_cst],10); for (i=pk->dec; istrict) numint_set_int(q[4][polka_eps],-1); numint_set_int(q[4][polka_cst],10); for (i=pk->dec; idec+3); printf("r1=%ldx\n",r1); vector_print(r1,pk->dec+3); vector_realloc(&r1,pk->dec+3,2*size); printf("r1=%ldx\n",r1); vector_print(r1,2*size); vector_free(r1,2*size); } printf("\n"); /* vector_normalize */ r1 = vector_alloc(size); for (i=1; i<=4; i++){ printf("vector_normalize %d\n",i); vector_copy(r1,q[i],size); vector_print(r1,size); vector_normalize(pk,r1,size); vector_print(r1,size); printf("vector_normalize_constraint %d\n",i); vector_copy(r1,q[i],size); change = vector_normalize_constraint(pk,r1,size/2,size-size/2-pk->dec); vector_print(r1,size); printf("change=%d\n",change); printf("vector_normalize_constraint_int %d\n",i); vector_copy(r1,q[i],size); change = vector_normalize_constraint_int(pk,r1,size/2,size-size/2-pk->dec); vector_print(r1,size); printf("change=%d\n",change); printf("vector_normalize_constraint_int %d\n",i); vector_copy(r1,q[i],size); change = vector_normalize_constraint_int(pk,r1,size-pk->dec,0); vector_print(r1,size); printf("change=%d\n",change); } vector_free(r1,size); printf("\n"); /* vector_compare */ for (i=1; i<=4; i++){ for (j=1; j<=4; j++){ int res = vector_compare(pk,q[i],q[j],size); printf("vector_compare(%d,%d)=%d\n",i,j,res); } } /* vector_combine */ r1 = vector_alloc(size); for (i=1; i<=4; i++){ for (j=i; j<=4; j++){ vector_combine(pk,q[i],q[j],r1,pk->dec+3,size); printf("vector_combine(%d,%d,k=%d)\n",i,j,pk->dec+3); vector_print(r1,size); vector_combine(pk,q[j],q[i],r1,pk->dec+3,size); printf("vector_combine(%d,%d,k=%d)\n",j,i,pk->dec+3); vector_print(r1,size); } } vector_free(r1,size); printf("\n"); for (i=1; i<=4; i++){ vector_free(q[i],size); } } /* ********************************************************************** */ /* Polyhedra 1 */ /* ********************************************************************** */ void poly1(manager_t* man, char** name_of_dim, poly_t** ppo1, poly_t** ppo2) { /* Creation du polyčdre 1/2x+2/3y=1, [1,2]<=z+2w<=4, -2<=1/3z-w<=3, u non contraint */ mpq_t mpq; lincons0_t cons; lincons0_array_t array; generator0_array_t garray; poly_t* poly; poly_t* poly2; poly_t* poly3; struct interval_t* titv; struct interval_t itv; int i; linexpr0_t* expr; bool b; mpq_init(mpq); array = lincons0_array_make(5); /* 1. Constraint system */ array.p[0].constyp = CONS_EQ; array.p[0].linexpr0 = linexpr0_alloc(COEFF_MPQ,LINEXPR_SPARSE,2,CST_COEFF); coeff_set_int(cst_coeffref(&array.p[0].linexpr0->cst), 1); array.p[0].linexpr0->p.linterm[0].dim = 0; coeff_set_double(&array.p[0].linexpr0->p.linterm[0].coeff,0.5); array.p[0].linexpr0->p.linterm[1].dim = 1; coeff_set_frac(&array.p[0].linexpr0->p.linterm[1].coeff,2,3); array.p[1].constyp = CONS_SUPEQ; array.p[1].linexpr0 = linexpr0_alloc(COEFF_MPQ,LINEXPR_SPARSE,2,CST_INTERVAL); coeff_set_int(interval_infref(cst_intervalref(&array.p[1].linexpr0->cst)), -2); coeff_set_int(interval_supref(cst_intervalref(&array.p[1].linexpr0->cst)), -1); array.p[1].linexpr0->p.linterm[0].dim = 2; coeff_set_double(&array.p[1].linexpr0->p.linterm[0].coeff,1.0); array.p[1].linexpr0->p.linterm[1].dim = 3; coeff_set_frac(&array.p[1].linexpr0->p.linterm[1].coeff,2,1); array.p[2].constyp = CONS_SUPEQ; array.p[2].linexpr0 = linexpr0_alloc(COEFF_MPQ,LINEXPR_SPARSE,2,CST_COEFF); coeff_set_int(cst_coeffref(&array.p[2].linexpr0->cst), 4); array.p[2].linexpr0->p.linterm[0].dim = 2; coeff_set_double(&array.p[2].linexpr0->p.linterm[0].coeff,-1.0); array.p[2].linexpr0->p.linterm[1].dim = 3; coeff_set_frac(&array.p[2].linexpr0->p.linterm[1].coeff,-2,1); array.p[3].constyp = CONS_SUPEQ; array.p[3].linexpr0 = linexpr0_alloc(COEFF_MPQ,LINEXPR_SPARSE,2,CST_COEFF); coeff_set_int(cst_coeffref(&array.p[3].linexpr0->cst), 2); array.p[3].linexpr0->p.linterm[0].dim = 2; coeff_set_frac(&array.p[3].linexpr0->p.linterm[0].coeff, 1,3); array.p[3].linexpr0->p.linterm[1].dim = 3; coeff_set_frac(&array.p[3].linexpr0->p.linterm[1].coeff, -1,1); array.p[4].constyp = CONS_SUP; array.p[4].linexpr0 = linexpr0_alloc(COEFF_MPQ,LINEXPR_SPARSE,2,CST_COEFF); coeff_set_int(cst_coeffref(&array.p[4].linexpr0->cst), 3); array.p[4].linexpr0->p.linterm[0].dim = 2; coeff_set_frac(&array.p[4].linexpr0->p.linterm[0].coeff,-1,3); array.p[4].linexpr0->p.linterm[1].dim = 3; coeff_set_frac(&array.p[4].linexpr0->p.linterm[1].coeff,1,1); /* Creation */ lincons0_array_fprint(stdout,&array,name_of_dim); poly = poly_of_lincons_array(man,0,6,&array); poly_fprint(stdout,man,poly,name_of_dim); poly_canonicalize(man,poly); poly_fprint(stdout,man,poly,name_of_dim); garray = poly_to_generator_array(man,poly); generator0_array_fprint(stdout,&garray,name_of_dim); generator0_array_clear(&garray); poly_fdump(stdout,man,poly); /* 2. Constraint system */ /* Conversion (to_lincons_array already tested with print) */ /* Should be 0: [-oo,+oo] 1: [-oo,+oo] 2: [-6/5,6] 3: [-7/5,2] 4: [-oo,+oo] 5: [-oo,+oo] */ titv = poly_to_box(man,poly); for (i=0; i<6; i++){ fprintf(stdout,"%2d: ",i); interval_fprint(stdout,&titv[i]); fprintf(stdout,"\n"); } /* Extraction (we first extract values for existing constraints, then for dimensions) */ /* existing constraints */ for (i=0; i<5; i++){ itv = poly_bound_linexpr(man,poly,array.p[i].linexpr0); fprintf(stdout,"Bound of "); linexpr0_fprint(stdout,array.p[i].linexpr0,name_of_dim); fprintf(stdout,": "); interval_fprint(stdout,&itv); fprintf(stdout,"\n"); interval_clear(&itv); } /* dimensions */ expr = linexpr0_alloc(COEFF_MPQ,LINEXPR_SPARSE,1,CST_COEFF); coeff_set_double(cst_coeffref(&expr->cst),0.0); coeff_set_double(&expr->p.linterm[0].coeff,1.0); for (i=0; i<6; i++){ expr->p.linterm[0].dim = (dim_t)i; itv = poly_bound_linexpr(man,poly,expr); fprintf(stdout,"Bound of "); linexpr0_fprint(stdout,expr,name_of_dim); fprintf(stdout,": "); interval_fprint(stdout,&itv); fprintf(stdout,"\n"); interval_clear(&itv); } linexpr0_free(expr); /* 3. of box */ poly2 = poly_of_box(man,0,6,titv); poly_fprint(stdout,man,poly2,name_of_dim); poly_canonicalize(man,poly2); poly_fprint(stdout,man,poly2,name_of_dim); poly_fdump(stdout,man,poly2); /* 4. Tests top and bottom */ poly3 = poly_bottom(man,2,3); b = poly_is_bottom(man,poly3); fprintf(stdout,"poly_is_bottom(poly3)=%d\n",b); b = poly_is_top(man,poly3); fprintf(stdout,"poly_is_top(poly3)=%d\n",b); poly_free(man,poly3); poly3 = poly_top(man,2,3); b = poly_is_bottom(man,poly3); fprintf(stdout,"poly_is_bottom(poly3)=%d\n",b); b = poly_is_top(man,poly3); fprintf(stdout,"poly_is_top(poly3)=%d\n",b); poly_free(man,poly3); poly3 = poly_top(man,0,0); b = poly_is_bottom(man,poly3); fprintf(stdout,"poly_is_bottom(poly3)=%d\n",b); b = poly_is_top(man,poly3); fprintf(stdout,"poly_is_top(poly3)=%d\n",b); poly_free(man,poly3); poly_minimize(man,poly2); poly_fdump(stdout,man,poly2); b = poly_is_bottom(man,poly2); fprintf(stdout,"poly_is_bottom(poly2)=%d\n",b); b = poly_is_top(man,poly2); fprintf(stdout,"poly_is_top(poly2)=%d\n",b); /* 5. Tests leq */ b = poly_is_leq(man,poly,poly2); fprintf(stdout,"poly_is_leq(poly,poly2)=%d\n",b); b = poly_is_leq(man,poly2,poly); fprintf(stdout,"poly_is_leq(poly,poly2)=%d\n",b); /* 6. Tests sat_interval */ interval_init(&itv,COEFF_DOUBLE); coeff_set_int(interval_infref(&itv),-6); coeff_set_int(interval_supref(&itv),6); b = poly_sat_interval(man,poly,2,&itv); fprintf(stdout,"poly_sat_interval(poly,2)"); interval_fprint(stdout,&itv); fprintf(stdout," = %d\n",b); b = poly_sat_interval(man,poly,3,&itv); fprintf(stdout,"poly_sat_interval(poly,3)"); interval_fprint(stdout,&itv); fprintf(stdout," = %d\n",b); b = poly_sat_interval(man,poly,4,&itv); fprintf(stdout,"poly_sat_interval(poly,4)"); interval_fprint(stdout,&itv); fprintf(stdout," = %d\n",b); coeff_set_double(interval_infref(&itv),-2.5); coeff_set_double(interval_supref(&itv),2.5); b = poly_sat_interval(man,poly,2,&itv); fprintf(stdout,"poly_sat_interval(poly,2)"); interval_fprint(stdout,&itv); fprintf(stdout," = %d\n",b); b = poly_sat_interval(man,poly,3,&itv); fprintf(stdout,"poly_sat_interval(poly,3)"); interval_fprint(stdout,&itv); fprintf(stdout," = %d\n",b); b = poly_sat_interval(man,poly,4,&itv); fprintf(stdout,"poly_sat_interval(poly,4)"); interval_fprint(stdout,&itv); fprintf(stdout," = %d\n",b); coeff_set_double(interval_infref(&itv),-1.4); coeff_set_double(interval_supref(&itv),2.0); b = poly_sat_interval(man,poly,2,&itv); fprintf(stdout,"poly_sat_interval(poly,2)"); interval_fprint(stdout,&itv); fprintf(stdout," = %d\n",b); b = poly_sat_interval(man,poly,3,&itv); fprintf(stdout,"poly_sat_interval(poly,3)"); interval_fprint(stdout,&itv); fprintf(stdout," = %d\n",b); b = poly_sat_interval(man,poly,4,&itv); fprintf(stdout,"poly_sat_interval(poly,4)"); interval_fprint(stdout,&itv); fprintf(stdout," = %d\n",b); mpq_set_si(mpq,-14,10); coeff_set_mpq(interval_infref(&itv),mpq); coeff_set_double(interval_supref(&itv),2.0); b = poly_sat_interval(man,poly,2,&itv); fprintf(stdout,"poly_sat_interval(poly,2)"); interval_fprint(stdout,&itv); fprintf(stdout," = %d\n",b); b = poly_sat_interval(man,poly,3,&itv); fprintf(stdout,"poly_sat_interval(poly,3)"); interval_fprint(stdout,&itv); fprintf(stdout," = %d\n",b); b = poly_sat_interval(man,poly,4,&itv); fprintf(stdout,"poly_sat_interval(poly,4)"); interval_fprint(stdout,&itv); fprintf(stdout," = %d\n",b); interval_clear(&itv); /* 7. Tests sat_lincons */ expr = linexpr0_alloc(COEFF_MPQ,LINEXPR_SPARSE,4,CST_COEFF); cons.constyp = CONS_SUPEQ; cons.linexpr0 = expr; expr->p.linterm[0].dim = 0; expr->p.linterm[1].dim = 1; expr->p.linterm[2].dim = 2; expr->p.linterm[3].dim = 3; coeff_set_double(&expr->p.linterm[0].coeff,-3.0); coeff_set_double(&expr->p.linterm[1].coeff,-4.0); coeff_set_double(&expr->p.linterm[2].coeff,1.0); coeff_set_double(&expr->p.linterm[3].coeff,-1.0); coeff_set_int(cst_coeffref(&expr->cst),0); itv = poly_bound_linexpr(man,poly,expr); fprintf(stdout,"Bound of "); linexpr0_fprint(stdout,expr,name_of_dim); fprintf(stdout,": "); interval_fprint(stdout,&itv); fprintf(stdout,"\n"); interval_clear(&itv); for (i=0; i<6; i++){ coeff_reinit(cst_coeffref(&expr->cst),COEFF_MPQ); mpq_set_si(coeff_mpqref(cst_coeffref(&expr->cst)), -26 + i*10, 5); cons.constyp = CONS_SUPEQ; b = poly_sat_lincons(man,poly,&cons); fprintf(stdout,"poly_sat_lincons(poly)"); lincons0_fprint(stdout,&cons,name_of_dim); fprintf(stdout,": %d\n",b); cons.constyp = CONS_SUP; b = poly_sat_lincons(man,poly,&cons); fprintf(stdout,"poly_sat_lincons(poly)"); lincons0_fprint(stdout,&cons,name_of_dim); fprintf(stdout,": %d\n",b); } mpq_set_si(mpq,-2,3); coeff_set_mpq(&expr->p.linterm[2].coeff,mpq); coeff_set_double(&expr->p.linterm[3].coeff,2.0); coeff_set_int(cst_coeffref(&expr->cst),0); itv = poly_bound_linexpr(man,poly,expr); fprintf(stdout,"Bound of "); linexpr0_fprint(stdout,expr,name_of_dim); fprintf(stdout,": "); interval_fprint(stdout,&itv); fprintf(stdout,"\n"); interval_clear(&itv); for (i=0; i<6; i++){ coeff_reinit(cst_coeffref(&expr->cst),COEFF_MPQ); mpq_set_si(coeff_mpqref(cst_coeffref(&expr->cst)), -1+i, 1); cons.constyp = CONS_SUPEQ; b = poly_sat_lincons(man,poly,&cons); fprintf(stdout,"poly_sat_lincons(poly)"); lincons0_fprint(stdout,&cons,name_of_dim); fprintf(stdout,": %d\n",b); cons.constyp = CONS_SUP; b = poly_sat_lincons(man,poly,&cons); fprintf(stdout,"poly_sat_lincons(poly)"); lincons0_fprint(stdout,&cons,name_of_dim); fprintf(stdout,": %d\n",b); } linexpr0_free(expr); interval_array_free(titv,6); lincons0_array_clear(&array); mpq_clear(mpq); *ppo1 = poly; *ppo2 = poly2; } /* ********************************************************************** */ /* Polyhedra 2 */ /* ********************************************************************** */ void poly2(manager_t* man, char** name_of_dim, poly_t* po1, poly_t* po2) { bool b; poly_t* po; linexpr0_t* expr[2]; lincons0_t cons; lincons0_array_t array = { &cons, 1 }; generator0_t gen; generator0_array_t garray, garray2; int i; /* Meet and join (without meet_array et join_array) */ fprintf(stdout,"********* Meet and Join for 2 polyhedra *********\n"); fprintf(stdout,"po1:\n"); poly_fprint(stdout,man,po1,name_of_dim); fprintf(stdout,"po2:\n"); poly_fprint(stdout,man,po2,name_of_dim); fprintf(stdout,"po=meet(po1,po2)\n"); po = poly_meet(man,po1,po2); poly_fprint(stdout,man,po,name_of_dim); b = poly_is_leq(man,po,po1); fprintf(stdout,"poly_is_leq(man,po,po1)=%d\n",b); assert(b); b = poly_is_leq(man,po,po2); fprintf(stdout,"poly_is_leq(man,po,po2)=%d\n",b); assert(b); b = poly_is_leq(man,po1,po); fprintf(stdout,"poly_is_leq(man,po1,po)=%d\n",b); b = poly_is_leq(man,po2,po); fprintf(stdout,"poly_is_leq(man,po2,po)=%d\n",b); poly_free(man,po); fprintf(stdout,"po=po1; meet_with(po,po2)\n"); po = poly_copy(man,po1); poly_meet_with(man,po,po2); poly_fprint(stdout,man,po,name_of_dim); b = poly_is_leq(man,po,po1); fprintf(stdout,"poly_is_leq(man,po,po1)=%d\n",b); assert(b); b = poly_is_leq(man,po,po2); fprintf(stdout,"poly_is_leq(man,po,po2)=%d\n",b); assert(b); b = poly_is_leq(man,po1,po); fprintf(stdout,"poly_is_leq(man,po1,po)=%d\n",b); b = poly_is_leq(man,po2,po); fprintf(stdout,"poly_is_leq(man,po2,po)=%d\n",b); poly_free(man,po); fprintf(stdout,"po = join(po1,po2)\n"); po = poly_join(man,po1,po2); poly_fprint(stdout,man,po,name_of_dim); b = poly_is_top(man,po); fprintf(stdout,"poly_is_top(man,po)=%d\n",b); b = poly_is_leq(man,po,po1); fprintf(stdout,"poly_is_leq(man,po,po1)=%d\n",b); b = poly_is_leq(man,po,po2); fprintf(stdout,"poly_is_leq(man,po,po2)=%d\n",b); b = poly_is_leq(man,po1,po); fprintf(stdout,"poly_is_leq(man,po1,po)=%d\n",b); assert(b); b = poly_is_leq(man,po2,po); fprintf(stdout,"poly_is_leq(man,po2,po)=%d\n",b); assert(b); poly_free(man,po); fprintf(stdout,"po = po1; join_with(po,po2)\n"); po = poly_copy(man,po1); poly_join_with(man,po,po2); poly_fprint(stdout,man,po,name_of_dim); b = poly_is_leq(man,po,po1); fprintf(stdout,"poly_is_leq(man,po,po1)=%d\n",b); b = poly_is_leq(man,po,po2); fprintf(stdout,"poly_is_leq(man,po,po2)=%d\n",b); b = poly_is_leq(man,po1,po); fprintf(stdout,"poly_is_leq(man,po1,po)=%d\n",b); assert(b); b = poly_is_leq(man,po2,po); fprintf(stdout,"poly_is_leq(man,po2,po)=%d\n",b); assert(b); poly_free(man,po); /* Additions of constraints */ fprintf(stdout,"********* Addition of constraint *********\n"); fprintf(stdout,"po1:\n"); poly_fprint(stdout,man,po1,name_of_dim); garray = poly_to_generator_array(man,po1); generator0_array_fprint(stdout,&garray,name_of_dim); generator0_array_clear(&garray); /* expression z>=-1/2 */ expr[0] = linexpr0_alloc(COEFF_MPQ,LINEXPR_SPARSE,1,CST_COEFF); coeff_reinit(cst_coeffref(&expr[0]->cst),COEFF_MPQ); coeff_set_frac(cst_coeffref(&expr[0]->cst),1,2); expr[0]->p.linterm[0].dim = 2; coeff_set_int(&expr[0]->p.linterm[0].coeff,1); /* expression x+u>=1 */ expr[1] = linexpr0_alloc(COEFF_MPQ,LINEXPR_SPARSE,2,CST_COEFF); coeff_set_int(cst_coeffref(&expr[1]->cst),-1); expr[1]->p.linterm[0].dim = 0; expr[1]->p.linterm[1].dim = 4; coeff_set_int(&expr[1]->p.linterm[0].coeff,1); coeff_set_int(&expr[1]->p.linterm[1].coeff,1); for (i=0; i<2; i++){ cons.linexpr0 = expr[i]; for (cons.constyp=0; cons.constyp<3; cons.constyp++){ fprintf(stdout,"po=meet_lincons(po1) "); lincons0_fprint(stdout,&cons,name_of_dim); fprintf(stdout,"\n"); po = poly_meet_lincons_array(man,po1,&array); poly_fprint(stdout,man,po,name_of_dim); garray = poly_to_generator_array(man,po); generator0_array_fprint(stdout,&garray,name_of_dim); generator0_array_clear(&garray); b = poly_is_leq(man,po,po1); fprintf(stdout,"poly_is_leq(po,po1)=%d\n",b); assert(b); b = poly_is_leq(man,po1,po); fprintf(stdout,"poly_is_leq(po1,po)=%d\n",b); poly_free(man,po); fprintf(stdout,"po=po1; meet_lincons_with(po) "); lincons0_fprint(stdout,&cons,name_of_dim); fprintf(stdout,"\n"); po = poly_copy(man,po1); poly_meet_lincons_array_with(man,po,&array); poly_fprint(stdout,man,po,name_of_dim); garray = poly_to_generator_array(man,po); generator0_array_fprint(stdout,&garray,name_of_dim); generator0_array_clear(&garray); b = poly_is_leq(man,po,po1); fprintf(stdout,"poly_is_leq(po,po1)=%d\n",b); assert(b); b = poly_is_leq(man,po1,po); fprintf(stdout,"poly_is_leq(po1,po)=%d\n",b); poly_free(man,po); } linexpr0_free(expr[i]); } /* Additions of rays */ fprintf(stdout,"********* Addition of rays *********\n"); fprintf(stdout,"po1:\n"); poly_fprint(stdout,man,po1,name_of_dim); garray = poly_to_generator_array(man,po1); generator0_array_fprint(stdout,&garray,name_of_dim); generator0_array_clear(&garray); /* expression z+w/8 */ expr[0] = linexpr0_alloc(COEFF_MPQ,LINEXPR_SPARSE,2,CST_COEFF); expr[0]->p.linterm[0].dim = 2; expr[0]->p.linterm[1].dim = 3; coeff_set_int(&expr[0]->p.linterm[0].coeff,1); coeff_set_frac(&expr[0]->p.linterm[1].coeff,1,8); /* expression z+w */ expr[1] = linexpr0_alloc(COEFF_MPQ,LINEXPR_SPARSE,2,CST_COEFF); expr[1]->p.linterm[0].dim = 2; expr[1]->p.linterm[1].dim = 3; coeff_set_int(&expr[1]->p.linterm[0].coeff,1); coeff_set_int(&expr[1]->p.linterm[1].coeff,1); garray2 = generator0_array_make(1); for (i=0; i<2; i++){ gen.linexpr0 = expr[i]; gen.gentyp = GEN_RAY; garray2.p[0] = gen; fprintf(stdout,"po=add_ray_array(po1) "); generator0_fprint(stdout,&gen,name_of_dim); fprintf(stdout,"\n"); po = poly_add_ray_array(man,po1,&garray2); poly_fprint(stdout,man,po,name_of_dim); garray = poly_to_generator_array(man,po); generator0_array_fprint(stdout,&garray,name_of_dim); generator0_array_clear(&garray); b = poly_is_leq(man,po,po1); fprintf(stdout,"poly_is_leq(po,po1)=%d\n",b); b = poly_is_leq(man,po1,po); fprintf(stdout,"poly_is_leq(po1,po)=%d\n",b); assert(b); poly_free(man,po); fprintf(stdout,"po=po1; add_ray_array_with(po) "); generator0_fprint(stdout,&gen,name_of_dim); fprintf(stdout,"\n"); po = poly_copy(man,po1); poly_add_ray_array_with(man,po,&garray2); poly_fprint(stdout,man,po,name_of_dim); garray = poly_to_generator_array(man,po); generator0_array_fprint(stdout,&garray,name_of_dim); generator0_array_clear(&garray); b = poly_is_leq(man,po,po1); fprintf(stdout,"poly_is_leq(po,po1)=%d\n",b); b = poly_is_leq(man,po1,po); fprintf(stdout,"poly_is_leq(po1,po)=%d\n",b); poly_free(man,po); linexpr0_free(expr[i]); } garray2.p[0].linexpr0 = NULL; generator0_array_clear(&garray2); } /* ********************************************************************** */ /* Polyhedra 3 (assignement and substitution of a single expression) */ /* ********************************************************************** */ void poly3(manager_t* man, char** name_of_dim, poly_t* po1, poly_t* po2) { bool b; poly_t* poly1; poly_t* poly2; poly_t* poly3; poly_t* tpo[2]; linexpr0_t* expr[3]; generator0_array_t garray; int i,j,inplace,undet; fprintf(stdout,"********* Assignement and Substitution, single *********\n"); fprintf(stdout,"po1:\n"); poly_fprint(stdout,man,po1,name_of_dim); garray = poly_to_generator_array(man,po1); generator0_array_fprint(stdout,&garray,name_of_dim); generator0_array_clear(&garray); fprintf(stdout,"po2:\n"); poly_fprint(stdout,man,po2,name_of_dim); garray = poly_to_generator_array(man,po2); generator0_array_fprint(stdout,&garray,name_of_dim); generator0_array_clear(&garray); tpo[0] = po1; tpo[1] = po2; /* Single equation z+5w-1 */ expr[0] = linexpr0_alloc(COEFF_MPQ,LINEXPR_SPARSE,2,CST_COEFF); expr[0]->p.linterm[0].dim = 2; expr[0]->p.linterm[1].dim = 3; coeff_set_int(cst_coeffref(&expr[0]->cst),-1); coeff_set_int(&expr[0]->p.linterm[0].coeff,1); coeff_set_int(&expr[0]->p.linterm[1].coeff,5); /* Single equation 2x+1 */ expr[1] = linexpr0_alloc(COEFF_MPQ,LINEXPR_SPARSE,1,CST_COEFF); expr[1]->p.linterm[0].dim = 0; coeff_set_int(cst_coeffref(&expr[1]->cst),1); coeff_set_int(&expr[1]->p.linterm[0].coeff,2); for (undet=0; undet<2; undet++){ if (undet==1){ for (j=0;j<2;j++){ cst_reinit(&expr[j]->cst,COEFF_MPQ,CST_INTERVAL); coeff_set_int(interval_infref(cst_intervalref(&expr[j]->cst)), -1); coeff_set_int(interval_supref(cst_intervalref(&expr[j]->cst)), +1); } } for (inplace=0; inplace<2; inplace++){ for (i=0; i<2; i++){ for (j=0;j<2;j++){ fprintf(stdout, inplace ? "poly1 = po%d; assign_linexpr_with(poly1) z:=" : "poly1=assign_linexpr(po%d) z:=", i+1); linexpr0_fprint(stdout,&expr[j],name_of_dim); fprintf(stdout,"\n"); if (inplace){ poly1 = poly_copy(man,tpo[i]); poly_assign_linexpr_with(man,poly1,2,expr[j]); } else { poly1 = poly_assign_linexpr(man,tpo[i],2,expr[j]); } poly_fprint(stdout,man,poly1,name_of_dim); garray = poly_to_generator_array(man,poly1); generator0_array_fprint(stdout,&garray,name_of_dim); generator0_array_clear(&garray); fprintf(stdout, inplace ? "poly2 = poly1; substitute_linexpr_with(poly2) z:=" : "poly2=substitute_linexpr(poly1) z:=" ); linexpr0_fprint(stdout,expr[j],name_of_dim); fprintf(stdout,"\n"); if (inplace){ poly2 = poly_copy(man,poly1); poly_substitute_linexpr_with(man,poly2,2,expr[j]); } else { poly2 = poly_substitute_linexpr(man,poly1,2,expr[j]); } poly_fprint(stdout,man,poly2,name_of_dim); garray = poly_to_generator_array(man,poly2); generator0_array_fprint(stdout,&garray,name_of_dim); generator0_array_clear(&garray); b = poly_is_leq(man,tpo[i],poly2); fprintf(stdout,"poly_is_leq(po%d,poly2)=%d\n",i+1,b); assert(b); b = poly_is_leq(man,poly2,tpo[i]); fprintf(stdout,"poly_is_leq(poly2,po%d)=%d\n",i+1,b); assert(!undet && j==0 ? b : true); fprintf(stdout, inplace ? "poly3 = poly2; assign_linexpr_with(poly3) z:=" : "poly3=assign_linexpr(poly2) z:=" ); linexpr0_fprint(stdout,expr[j],name_of_dim); fprintf(stdout,"\n"); if (inplace){ poly3 = poly_copy(man,poly2); poly_assign_linexpr_with(man,poly3,2,expr[j]); } else { poly3 = poly_assign_linexpr(man,poly2,2,expr[j]); } poly_fprint(stdout,man,poly3,name_of_dim); garray = poly_to_generator_array(man,poly3); generator0_array_fprint(stdout,&garray,name_of_dim); generator0_array_clear(&garray); b = poly_is_eq(man,poly1,poly3); fprintf(stdout,"poly_is_eq(poly1,poly3)=%d\n",b); assert(!(undet && j==0) ? b : true); poly_free(man,poly1); poly_free(man,poly2); poly_free(man,poly3); } } } } linexpr0_free(expr[0]); linexpr0_free(expr[1]); } void poly_test_example_aux(manager_t* man) { poly_t* p1; poly_t* p2; char** name_of_dim; dim_t* perm; name_of_dim = malloc(6*sizeof(char*)); name_of_dim[0] = "x"; name_of_dim[1] = "y"; name_of_dim[2] = "z"; name_of_dim[3] = "w"; name_of_dim[4] = "u"; name_of_dim[5] = "v"; perm = malloc(6*sizeof(dim_t)); permutation_set_id(perm,6); perm[0] = 2; perm[2] = 0; perm[3] = 5; perm[5] = 3; poly1(man,name_of_dim, &p1, &p2); assert(poly_check((pk_internal_t*)man->internal,p1)); assert(poly_check((pk_internal_t*)man->internal,p2)); poly2(man,name_of_dim,p1,p2); poly_add_permute_dimensions_with(man,p2,0,0,perm,true); poly2(man,name_of_dim,p1,p2); poly3(man,name_of_dim,p1,p2); poly_free(man,p2); p2 = poly_bottom(man,0,6); poly2(man,name_of_dim,p1,p2); poly2(man,name_of_dim,p2,p1); poly3(man,name_of_dim,p2,p1); poly_free(man,p1); poly_free(man,p2); /* */ free(name_of_dim); free(perm); } void poly_test_example() { pk_internal_t* pk; manager_t* man; numint_t num; funid_t funid; man = pk_manager_alloc(true); pk = (pk_internal_t*)man->internal; pk_internal_realloc_lazy(pk,20); numint_init(num); numint_set_int(num,1); vector(pk,7,num); numint_clear(num); poly_test_example_aux(man); for (funid=0; funidcst),0.0); for (j=0; jp.coeff[j],0.0); } /* Fill the expression */ r = rand(); coeff = (double)( (long int)(r % (2*mag)) - (long int)mag); coeff_set_double(cst_coeffref(&expr->cst),coeff); r = rand(); nbcoeff = (r % maxcoeff) + 1; for (j=0; jp.coeff[dim],coeff); } return expr; } poly_t* poly_random(manager_t* man, size_t intdim, size_t realdim, size_t nbcons, /* Number of constraints */ size_t maxeq, /* Maximum number of equations */ size_t maxcoeff, /* Maximum size of non-null coefficients */ unsigned int mag /* magnitude of coefficients */ ) { lincons0_array_t array; long int r; lincons0_t cons; linexpr0_t* expr; poly_t* poly; int i; array = lincons0_array_make(nbcons); r = rand(); maxeq = r % (maxeq+1); for (i=0; iinternal; pk_set_approximate_max_coeff_size(pk,1); /* Build a polyhedron x>=0, x<=mag, x-(mag*mag)y>=0 */ po = poly_top(man,0,2); /* Expression */ expr = linexpr0_alloc(COEFF_MPQ,LINEXPR_SPARSE,1,CST_COEFF); cons.constyp = CONS_SUPEQ; cons.linexpr0 = expr; coeff_set_int(cst_coeffref(&expr->cst),0); expr->p.linterm[0].dim=0; coeff_set_int(&expr->p.linterm[0].coeff,1); poly_meet_lincons_array_with(man,po,&array); coeff_set_int(cst_coeffref(&expr->cst),mag); coeff_set_int(&expr->p.linterm[0].coeff,-1); poly_meet_lincons_array_with(man,po,&array); linexpr0_free(expr); expr = linexpr0_alloc(COEFF_MPQ,LINEXPR_SPARSE,2,CST_COEFF); cons.constyp = CONS_SUPEQ; cons.linexpr0 = expr; coeff_set_int(cst_coeffref(&expr->cst),0); expr->p.linterm[0].dim=0; expr->p.linterm[1].dim=1; coeff_set_int(&expr->p.linterm[0].coeff,1); coeff_reinit(&expr->p.linterm[1].coeff,COEFF_MPQ); coeff_set_int(&expr->p.linterm[1].coeff,mag); mpq_mul(coeff_mpqref(&expr->p.linterm[1].coeff), coeff_mpqref(&expr->p.linterm[1].coeff),coeff_mpqref(&expr->p.linterm[1].coeff)); mpq_neg(coeff_mpqref(&expr->p.linterm[1].coeff),coeff_mpqref(&expr->p.linterm[1].coeff)); poly_meet_lincons_array_with(man,po,&array); linexpr0_free(expr); pa = poly_copy(man,po); poly_approximate(man,po,3); poly_fprint(stdout,man,pa,NULL); poly_fprint(stdout,man,po,NULL); assert(poly_is_leq(man,pa,po)); poly_free(man,po); poly_free(man,pa); manager_free(man); return; } /* ********************************************************************** */ /* Polyhedra 10 */ /* ********************************************************************** */ void poly_test_gen(manager_t* man, size_t intdim, size_t realdim, size_t nbcons, /* Number of constraints */ size_t maxeq, /* Maximum number of equations */ size_t maxcoeff, /* Maximum size of non-null coefficients */ unsigned int mag, /* magnitude of coefficients */ char*** pname_of_dim, poly_t*** ptpoly, /* of size 6, 0==2, 1==3 */ linexpr0_t*** ptexpr, /* of size 3 */ dim_t** ptdim /* of size 3 */ ) { char buffer[80]; int i; poly_t* p1; poly_t* p2; *pname_of_dim = malloc((intdim+realdim)*sizeof(char*)); for (i=0; i=3); } void poly_test_free(manager_t* man, size_t intdim, size_t realdim, char** name_of_dim, poly_t** tpoly, linexpr0_t** texpr, dim_t* tdim) { int j; for (j=0;jresult.flag_exact!=true); } poly_free(man,p3); /* bound_dimension and sat_interval */ PRINT((printf("bound_dimension and sat_interval\n"))); for (i=0;icst.val.coeff); interval = poly_bound_linexpr(man,p1,expr); if (!coeff_infty(&interval.inf)){ *coeff_doubleref(&expr->cst.val.coeff) = d + 1.0 - coeff_get_double(&interval.inf,0); assert(poly_sat_lincons(man,p1,&cons)); *coeff_doubleref(&expr->cst.val.coeff) = d - 1.0 - coeff_get_double(&interval.inf,0); assert(poly_sat_lincons(man,p1,&cons)==false || poly_is_bottom(man,p1)); } if (!coeff_infty(&interval.sup)){ for (i=0; ip.coeff[i]) = - *coeff_doubleref(&expr->p.coeff[i]); } *coeff_doubleref(&expr->cst.val.coeff) = coeff_get_double(&interval.sup,0) - d + 1.0; assert(poly_sat_lincons(man,p1,&cons)); *coeff_doubleref(&expr->cst.val.coeff) = coeff_get_double(&interval.sup,0) - d - 1.0; assert(poly_sat_lincons(man,p1,&cons)==false || poly_is_bottom(man,p1)); } *coeff_doubleref(&expr->cst.val.coeff) = d; interval_clear(&interval); } /* to_box */ PRINT((printf("to_box\n"))); box = poly_to_box(man,p1); for (i=0;iresult.flag_exact; poly_fprint(stdout,man,p5,name_of_dim); assert(poly_is_leq(man,p4,p5)); if (poly_is_leq(man,p5,p4)!=true){ printf("approximate(3) greater\n"); assert(res!=true); } else { assert(res); } poly_free(man,p5); poly_free(man,p3); poly_free(man,p4); /* meet_lincons, add_ray_array */ PRINT((printf("meet_lincons, add_ray_array\n"))); for (k=0; k<3; k++){ expr = texpr[k]; cons.constyp = CONS_SUPEQ; cons.linexpr0 = expr; p3 = poly_meet_lincons_array(man,p1,&consarray); p4 = poly_copy(man,p1); poly_meet_lincons_array_with(man,p4,&consarray); assert(poly_is_eq(man,p3,p4)); assert(poly_is_leq(man,p3,p1)); poly_free(man,p3); poly_free(man,p4); garray = generator0_array_make(1); garray.p[0].gentyp = GEN_RAY; garray.p[0].linexpr0 = expr; p3 = poly_add_ray_array(man,p1,&garray); p4 = poly_copy(man,p1); poly_add_ray_array_with(man,p4,&garray); assert(poly_is_eq(man,p3,p4)); assert(poly_is_leq(man,p1,p3)); free(garray.p); poly_free(man,p3); poly_free(man,p4); } /* assign and substitute (single, deterministic) */ PRINT((printf("assign and substitute (single, deterministic)\n"))); for (k=0; k<3; k++){ dim = tdim[k]; expr = texpr[k]; p3 = poly_assign_linexpr(man,p1,dim,expr); p4 = poly_copy(man,p1); poly_assign_linexpr_with(man,p4,dim,expr); assert(poly_is_eq(man,p3,p4)); poly_free(man,p4); p4 = poly_substitute_linexpr(man,p3,dim,expr); p5 = poly_copy(man,p3); poly_substitute_linexpr_with(man,p5,dim,expr); assert(poly_is_eq(man,p4,p5)); poly_free(man,p5); p5 = poly_assign_linexpr(man,p4,dim,expr); assert(poly_is_leq(man,p1,p4)); assert(poly_is_eq(man,p3,p5)); poly_free(man,p3); poly_free(man,p4); poly_free(man,p5); } /* parallel assign and substitute (deterministic) */ PRINT((printf("parallel assign and substitute (deterministic)\n"))); p3 = poly_assign_linexpr_array(man,p1,tdim,texpr,3); p4 = poly_copy(man,p1); poly_assign_linexpr_array_with(man,p4,tdim,texpr,3); assert(poly_is_eq(man,p3,p4)); poly_free(man,p4); p4 = poly_substitute_linexpr_array(man,p3,tdim,texpr,3); p5 = poly_copy(man,p3); poly_substitute_linexpr_array_with(man,p5,tdim,texpr,3); assert(poly_is_eq(man,p4,p5)); poly_free(man,p5); p5 = poly_assign_linexpr_array(man,p4,tdim,texpr,3); assert(poly_is_leq(man,p1,p4)); assert(poly_is_eq(man,p3,p5)); poly_free(man,p3); poly_free(man,p4); poly_free(man,p5); /* project and forget */ PRINT((printf("project and forget\n"))); box = poly_to_box(man,p1); for (k=0; k<3; k++){ dim = tdim[k]; p3 = poly_project_array(man,p1,&dim,1); p4 = poly_copy(man,p1); poly_project_array_with(man,p4,&dim,1); assert(poly_is_eq(man,p3,p4)); poly_free(man,p4); p4 = poly_forget_array(man,p1,&dim,1); p5 = poly_copy(man,p1); poly_forget_array_with(man,p5,&dim,1); assert(poly_is_eq(man,p4,p5)); poly_free(man,p5); assert(poly_is_leq(man,p3,p4)); assert(poly_is_leq(man,p4,p3)==false || poly_is_bottom(man,p1)); interval = poly_bound_dimension(man,p3,dim); assert(coeff_equal(&interval.inf,&interval.sup) || poly_is_bottom(man,p1)); assert(coeff_cmp(&interval.inf,&coeffzero)==0 || poly_is_bottom(man,p1)); interval_clear(&interval); interval = poly_bound_dimension(man,p4,dim); assert(interval_is_top(&interval) || poly_is_bottom(man,p1)); interval_clear(&interval); for (i=0; iinternal; pk_set_max_coeff_size(pk,0); pk_set_approximate_max_coeff_size(pk,10); for (i=0; i<3; i++){ printf("%d******************************************************************\n",i); poly_test_gen(man,intdim,realdim, nbcons,maxeq,maxcoeff,mag, &name_of_dim, &tpoly, &texpr, &tdim); poly_test_check(man,intdim,realdim, name_of_dim,tpoly,texpr,tdim); for (funid=0; funid_maxrows; } static inline bool matrix_is_sorted(matrix_t* mat) { return mat->_sorted; } /* Basic Operations */ matrix_t* matrix_alloc(size_t nbrows, size_t nbcols, bool s); void matrix_resize_rows(matrix_t* mat, size_t nbrows); void matrix_resize_rows_lazy(matrix_t* mat, size_t nbrows); void matrix_minimize(matrix_t* mat); void matrix_free(matrix_t* mat); void matrix_clear(matrix_t* mat); void matrix_print(matrix_t* mat); void matrix_fprint(FILE* stream, matrix_t* mat); matrix_t* matrix_copy(matrix_t* mat); bool matrix_equal(matrix_t* mata, matrix_t* matb); /* Operations on rows */ void matrix_normalize_row(pk_internal_t* pk, matrix_t* mat, size_t l); void matrix_combine_rows(pk_internal_t* pk, matrix_t* mat, size_t l1, size_t l2, size_t l3, size_t k); int matrix_compare_rows(pk_internal_t* pk, matrix_t* mat, size_t l1, size_t l2); void matrix_exch_rows(matrix_t* mat, size_t l1, size_t l2); void matrix_move_rows(matrix_t* mat, size_t destrow, size_t orgrow, size_t size); /* Normalization of rows */ bool matrix_normalize_constraint(pk_internal_t* pk, matrix_t* mat, size_t intdim, size_t realdim); bool matrix_normalize_constraint_int(pk_internal_t* pk, matrix_t* mat, size_t intdim, size_t realdim); /* Sorting & Merging */ void matrix_sort_rows(pk_internal_t* pk, matrix_t* mat); void matrix_sort_rows_with_sat(pk_internal_t* pk, matrix_t* mat, satmat_t* sat); matrix_t* matrix_append(matrix_t* ma, matrix_t* mb); void matrix_append_with(matrix_t* ma, matrix_t* mb); void matrix_revappend_with(matrix_t* ma, matrix_t* mb); matrix_t* matrix_merge_sort(pk_internal_t* pk, matrix_t* ma, matrix_t* mb); void matrix_merge_sort_with(pk_internal_t* pk, matrix_t* mat, matrix_t* cmat); /* Predicates that can be useful for users */ static inline bool matrix_is_row_dummy_constraint(pk_internal_t* pk, matrix_t* mat, size_t l) { return vector_is_dummy_constraint(pk, mat->p[l],mat->nbcolumns); } /* Functions meant to be internal */ matrix_t* _matrix_alloc_int(size_t nr, size_t nc, bool s); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/newpolka/polka.ml0000640014525101416610000001636211252216517020156 0ustar bjeannetpopart(* File generated from polka.idl *) type internal (** Convex Polyhedra and Linear Equalities abstract domains *) type loose type strict (** Two flavors for convex polyhedra: loose or strict. Loose polyhedra cannot have strict inequality constraints like [x>0]. They are algorithmically more efficient (less generators, simpler normalization). Convex polyhedra are defined by the conjunction of a set of linear constraints of the form [a_0*x_0 + ... + a_n*x_n + b >= 0] or [a_0*x_0 + ... + a_n*x_n + b > 0] where [a_0, ..., a_n, b, c] are constants and [x_0, ..., x_n] variables. *) type equalities (** Linear equalities. Linear equalities are conjunctions of linear equalities of the form [a_0*x_0 + ... + a_n*x_n + b = 0]. *) type 'a t (** Type of convex polyhedra/linear equalities, where ['a] is [loose], [strict] or [equalities]. Abstract values which are convex polyhedra have the type [(loose t) Apron.Abstract0.t] or [(loose t) Apron.Abstract1.t] or [(strict t) Apron.Abstract0.t] or [(strict t) Apron.Abstract1.t]. Abstract values which are conjunction of linear equalities have the type [(equalities t) Apron.Abstract0.t] or [(equalities t) Apron.Abstract1.t]. Managers allocated by NewPolka have the type ['a t Apron.Manager.t]. *) external manager_alloc_loose : unit -> loose t Apron.Manager.t = "camlidl_polka_pk_manager_alloc_loose" external manager_alloc_strict : unit -> strict t Apron.Manager.t = "camlidl_polka_pk_manager_alloc_strict" external manager_alloc_equalities : unit -> equalities t Apron.Manager.t = "camlidl_polka_pk_manager_alloc_equalities" external manager_get_internal : 'a t Apron.Manager.t -> internal = "camlidl_polka_manager_get_internal" external set_max_coeff_size : internal -> int -> unit = "camlidl_polka_pk_set_max_coeff_size" external set_approximate_max_coeff_size : internal -> int -> unit = "camlidl_polka_pk_set_approximate_max_coeff_size" external get_max_coeff_size : internal -> int = "camlidl_polka_pk_get_max_coeff_size" external get_approximate_max_coeff_size : internal -> int = "camlidl_polka_pk_get_approximate_max_coeff_size" let manager_is_polka man = let str = Apron.Manager.get_library man in let str = try String.sub str 0 5 with Invalid_argument _ -> "" in (String.compare str "polka")==0 let manager_of_polka (man:'a t Apron.Manager.t) : 'b Apron.Manager.t = Obj.magic man let manager_to_polka (man:'a Apron.Manager.t) : 'b t Apron.Manager.t = if manager_is_polka man then Obj.magic man else failwith "Polka.to_polka: the argument manager is not a Polka manager" let manager_is_polka_loose man = let str = Apron.Manager.get_library man in (String.compare str "polka, loose mode")==0 let manager_of_polka_loose (man:loose t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_polka_loose (man:'a Apron.Manager.t) : loose t Apron.Manager.t = if manager_is_polka_loose man then Obj.magic man else failwith "Polka.to_polka_loose: the argument manager is not a loose Polka manager" let manager_is_polka_strict man = let str = Apron.Manager.get_library man in (String.compare str "polka, strict mode")==0 let manager_of_polka_strict (man:strict t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_polka_strict (man:'a Apron.Manager.t) : strict t Apron.Manager.t = if manager_is_polka_strict man then Obj.magic man else failwith "Polka.to_polka_strict: the argument manager is not a strict Polka manager" let manager_is_polka_equalities man = let str = Apron.Manager.get_library man in (String.compare str "polka, equalities mode")==0 let manager_of_polka_equalities (man:equalities t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_polka_equalities (man:'a Apron.Manager.t) : equalities t Apron.Manager.t = if manager_is_polka_equalities man then Obj.magic man else failwith "Polka.to_polka_equalities: the argument manager is not an equalities Polka manager" module Abstract0 = struct let is_polka abs = manager_is_polka (Apron.Abstract0.manager abs) let is_polka_loose abs = manager_is_polka_loose (Apron.Abstract0.manager abs) let is_polka_strict abs = manager_is_polka (Apron.Abstract0.manager abs) let is_polka_equalities abs = manager_is_polka_equalities (Apron.Abstract0.manager abs) let of_polka (abs: 'a t Apron.Abstract0.t) : 'b Apron.Abstract0.t = Obj.magic abs let of_polka_loose (abs: loose t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let of_polka_strict (abs: strict t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let of_polka_equalities (abs: equalities t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let to_polka (abs:'a Apron.Abstract0.t) : 'b t Apron.Abstract0.t = if is_polka abs then Obj.magic abs else failwith "Polka.Abstract0.to_polka: the argument value is not a polka value" let to_polka_loose (abs:'a Apron.Abstract0.t) : loose t Apron.Abstract0.t = if is_polka_loose abs then Obj.magic abs else failwith "Polka.Abstract0.to_polka_loose: the argument value is not a loose polka value" let to_polka_strict (abs:'a Apron.Abstract0.t) : strict t Apron.Abstract0.t = if is_polka_strict abs then Obj.magic abs else failwith "Polka.Abstract0.to_polka_strict: the argument value is not a strict polka value" let to_polka_equalities (abs:'a Apron.Abstract0.t) : equalities t Apron.Abstract0.t = if is_polka_equalities abs then Obj.magic abs else failwith "Polka.Abstract0.to_polka_equalities: the argument value is not an equalities polka value" end module Abstract1 = struct let is_polka abs = manager_is_polka (Apron.Abstract1.manager abs) let is_polka_loose abs = manager_is_polka_loose (Apron.Abstract1.manager abs) let is_polka_strict abs = manager_is_polka (Apron.Abstract1.manager abs) let is_polka_equalities abs = manager_is_polka_equalities (Apron.Abstract1.manager abs) let of_polka (abs: 'a t Apron.Abstract1.t) : 'b Apron.Abstract1.t = Obj.magic abs let of_polka_loose (abs: loose t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let of_polka_strict (abs: strict t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let of_polka_equalities (abs: equalities t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let to_polka (abs:'a Apron.Abstract1.t) : 'b t Apron.Abstract1.t = if is_polka abs then Obj.magic abs else failwith "Polka.Abstract1.to_polka: the argument value is not a polka value" let to_polka_loose (abs:'a Apron.Abstract1.t) : loose t Apron.Abstract1.t = if is_polka_loose abs then Obj.magic abs else failwith "Polka.Abstract1.to_polka_loose: the argument value is not a loose polka value" let to_polka_strict (abs:'a Apron.Abstract1.t) : strict t Apron.Abstract1.t = if is_polka_strict abs then Obj.magic abs else failwith "Polka.Abstract1.to_polka_strict: the argument value is not a strict polka value" let to_polka_equalities (abs:'a Apron.Abstract1.t) : equalities t Apron.Abstract1.t = if is_polka_equalities abs then Obj.magic abs else failwith "Polka.Abstract1.to_polka_equalities: the argument value is not an equalities polka value" end apron-dist-0.9.10/apron/newpolka/test1.c0000640014525101416610000003537110442027055017720 0ustar bjeannetpopart/* ********************************************************************** */ /* test1.c: testing level 1 */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include "ap_global1.h" #include "pk.h" void test_environment() { size_t i; ap_environment_t* e1; ap_environment_t* e2; ap_environment_t* e3; ap_environment_t* e4; ap_environment_t* e5; ap_dimchange_t* change1; ap_dimchange_t* change2; ap_var_t name_of_intdim1[3] = { "a30","a10","a20" }; ap_var_t name_of_realdim1[3] = { "a11","a31","a21" }; ap_var_t name_of_intdim2[4] = { "a2","a0","a22","a24" }; ap_var_t name_of_realdim2[4] = { "a27","a23","a33","a37" }; ap_var_t name_of_intdim5[4] = { "a2","a10","a22","a20" }; ap_var_t name_of_realdim5[4] = { "a27","a31","a11","a37" }; e1 = ap_environment_alloc_empty(); printf("env 1\n"); ap_environment_fdump(stdout,e1); ap_environment_free(e1); e1 = ap_environment_alloc(name_of_intdim1,3, name_of_realdim1,3); printf("env 1\n"); ap_environment_fdump(stdout,e1); e2 = ap_environment_alloc(name_of_intdim2,4, name_of_realdim2,4); printf("env 2\n"); ap_environment_fdump(stdout,e2); e5 = ap_environment_alloc(name_of_intdim5,4, name_of_realdim5,4); printf("env 5\n"); ap_environment_fdump(stdout,e5); e3 = ap_environment_add(e1,name_of_intdim2,4, name_of_realdim2,4); printf("env 3\n"); ap_environment_fdump(stdout,e3); e4 = ap_environment_add(e2,name_of_intdim1,3, name_of_realdim1,3); printf("env 4\n"); ap_environment_fdump(stdout,e4); for(i=0; iintdim+e4->realdim; i++){ ap_var_t var = ap_environment_var_of_dim(e4,i); ap_dim_t dim = ap_environment_dim_of_var(e4,var); char* name = ap_var_operations->to_string(var); printf("i=%d, var=%s, dim=%d\n",i,name,dim); free(name); } ap_environment_free(e4); ap_environment_free(e3); e4 = ap_environment_remove(e5,name_of_intdim2,4, name_of_realdim2,4); assert(e4==NULL); e3 = ap_environment_lce(e1,e2,&change1,&change2); printf("env 3\n"); ap_environment_fdump(stdout,e3); ap_dimchange_fprint(stdout,change1); ap_dimchange_fprint(stdout,change2); ap_dimchange_free(change1); ap_dimchange_free(change2); e4 = ap_environment_lce(e3,e2,&change1,&change2); assert(e3==e4); printf("env 4\n"); ap_environment_fdump(stdout,e4); assert(change1==NULL); ap_dimchange_fprint(stdout,change2); ap_dimchange_free(change2); ap_environment_free(e3); ap_environment_free(e4); e3 = ap_environment_lce(e1,e5,&change1,&change2); printf("env 3\n"); ap_environment_fdump(stdout,e3); ap_dimchange_fprint(stdout,change1); ap_dimchange_fprint(stdout,change2); ap_dimchange_free(change1); ap_dimchange_free(change2); ap_environment_free(e3); ap_environment_free(e1); ap_environment_free(e2); ap_environment_free(e5); } /* ********************************************************************** */ /* Polyhedra 1 */ /* ********************************************************************** */ void absval1(ap_manager_t* man, ap_abstract1_t* ppo1, ap_abstract1_t* ppo2) { /* Creation du polyčdre 1/2x+2/3y=1, [1,2]<=z+2w<=4, -2<=1/3z-w<=3, u non contraint */ ap_var_t name_of_realdim1[6] = { "x","y","z","u","w","v" }; ap_var_t name_of_realdimXY[2] = { "x","y" }; ap_var_t name_of_realdimZW[2] = { "z","w" }; ap_lincons1_t cons; ap_lincons1_array_t array; ap_generator1_array_t garray; ap_abstract1_t poly; ap_abstract1_t poly2; ap_abstract1_t poly3; ap_box1_t box; ap_interval_t* itv; size_t i; ap_linexpr1_t expr; tbool_t tb; ap_environment_t* env; ap_environment_t* envXY; ap_environment_t* envZW; ap_environment_t* envXYZW; bool b; env = ap_environment_alloc(NULL,0,name_of_realdim1,6); envXY = ap_environment_alloc(NULL,0,name_of_realdimXY,2); envZW = ap_environment_alloc(NULL,0,name_of_realdimZW,2); envXYZW = ap_environment_add(envXY,NULL,0,name_of_realdimZW,2); array = ap_lincons1_array_make(envXYZW,5); /* 1. Constraint system */ /* 1/2x+2/3y=1 */ expr = ap_linexpr1_make(envXY,AP_LINEXPR_SPARSE,3); ap_linexpr1_set_cst_scalar_int(&expr,1); assert(! ap_linexpr1_set_coeff_scalar_frac(&expr,"x",1,2) ); assert(! ap_linexpr1_set_coeff_scalar_frac(&expr,"y",2,3) ); cons = ap_lincons1_make(AP_CONS_EQ,&expr); ap_lincons1_fprint(stdout,&cons);fprintf(stdout,"\n"); ap_lincons1_extend_environment_with(&cons,envXYZW); ap_lincons1_fprint(stdout,&cons);fprintf(stdout,"\n"); assert(! ap_lincons1_array_set(&array,0,&cons) ); /* [1,2]<=z+2w */ expr = ap_linexpr1_make(envZW,AP_LINEXPR_SPARSE,1); b = ap_linexpr1_set_list(&expr, AP_CST_I_INT,-2,-1, AP_COEFF_S_INT, 1, "z", AP_COEFF_S_INT, 2, "w", AP_END); assert(!b); cons = ap_lincons1_make(AP_CONS_SUPEQ,&expr); ap_lincons1_fprint(stdout,&cons);fprintf(stdout,"\n"); ap_lincons1_extend_environment_with(&cons,envXYZW); ap_lincons1_fprint(stdout,&cons);fprintf(stdout,"\n"); assert(! ap_lincons1_array_set(&array,1,&cons) ); /* z+2w<=4 */ expr = ap_linexpr1_make(envZW,AP_LINEXPR_SPARSE,0); b = ap_linexpr1_set_list(&expr, AP_CST_S_INT,-4, AP_COEFF_S_INT, -1, "z", AP_COEFF_S_INT, -2, "w", AP_END); assert(!b); cons = ap_lincons1_make(AP_CONS_SUPEQ,&expr); ap_lincons1_fprint(stdout,&cons);fprintf(stdout,"\n"); ap_lincons1_extend_environment_with(&cons,envXYZW); ap_lincons1_fprint(stdout,&cons);fprintf(stdout,"\n"); assert(! ap_lincons1_array_set(&array,2,&cons) ); /* -2<=1/3z-w */ expr = ap_linexpr1_make(envZW,AP_LINEXPR_SPARSE,2); cons = ap_lincons1_make(AP_CONS_SUPEQ,&expr); b = ap_lincons1_set_list(&cons, AP_CST_S_INT,2, AP_COEFF_S_FRAC, 1, 3, "z", AP_COEFF_S_INT, -1, "w", AP_END); assert(!b); ap_lincons1_fprint(stdout,&cons);fprintf(stdout,"\n"); ap_lincons1_extend_environment_with(&cons,envXYZW); ap_lincons1_fprint(stdout,&cons);fprintf(stdout,"\n"); assert(! ap_lincons1_array_set(&array,3,&cons) ); /* 1/3z-w<=3 */ expr = ap_linexpr1_make(envZW,AP_LINEXPR_SPARSE,1); ap_linexpr1_set_cst_scalar_int(&expr,3); assert(! ap_linexpr1_set_coeff_scalar_frac(&expr,"z", -1,3) ); assert(! ap_linexpr1_set_coeff_scalar_int(&expr,"w", 1) ); cons = ap_lincons1_make(AP_CONS_SUPEQ,&expr); ap_lincons1_fprint(stdout,&cons);fprintf(stdout,"\n"); ap_lincons1_extend_environment_with(&cons,envXYZW); ap_lincons1_fprint(stdout,&cons);fprintf(stdout,"\n"); assert(! ap_lincons1_array_set(&array,4,&cons) ); /* Creation */ ap_lincons1_array_fprint(stdout,&array); poly = ap_abstract1_of_lincons_array(man,env,&array); ap_abstract1_fprint(stdout,man,&poly); ap_abstract1_canonicalize(man,&poly); ap_abstract1_fprint(stdout,man,&poly); garray = ap_abstract1_to_generator_array(man,&poly); ap_generator1_array_fprint(stdout,&garray); ap_generator1_array_clear(&garray); ap_abstract1_fdump(stdout,man,&poly); /* 2. Constraint system */ /* Conversion (to_lincons_array already tested with print) */ /* Should be x: [-oo,+oo] y: [-oo,+oo] z: [-6/5,6] w: [-7/5,2] u: [-oo,+oo] v: [-oo,+oo] */ box = ap_abstract1_to_box(man,&poly); ap_box1_fprint(stdout,&box); ap_box1_clear(&box); /* Extraction (we first extract values for existing constraints, then for dimensions) */ /* existing constraints */ for (i=0; i<5; i++){ cons = ap_lincons1_array_get(&array,i); expr = ap_lincons1_linexpr1ref(&cons); itv = ap_abstract1_bound_linexpr(man,&poly,&expr); fprintf(stdout,"Bound of "); ap_linexpr1_fprint(stdout,&expr); fprintf(stdout,": "); ap_interval_fprint(stdout,itv); fprintf(stdout,"\n"); ap_interval_free(itv); } /* dimensions */ for (i=0; iintdim+env->realdim; i++){ expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,1); ap_linexpr1_set_cst_scalar_double(&expr,0.0); ap_linexpr1_set_coeff_scalar_int(&expr,ap_environment_var_of_dim(env,i),1); itv = ap_abstract1_bound_linexpr(man,&poly,&expr); fprintf(stdout,"Bound of "); ap_linexpr1_fprint(stdout,&expr); fprintf(stdout,": "); ap_interval_fprint(stdout,itv); fprintf(stdout,"\n"); ap_interval_free(itv); ap_linexpr1_clear(&expr); } /* 3. of box z: [-6/5,6], w: [-7/5,2] */ { ap_var_t name[2] = { "z", "w" }; ap_interval_t* itv[2]; itv[0] = ap_interval_alloc(); itv[1] = ap_interval_alloc(); ap_interval_set_frac(itv[0],-6,5,6,1); ap_interval_set_frac(itv[1],-7,5,2,1); poly2 = ap_abstract1_of_box(man,env,name,itv,2); ap_abstract1_fprint(stdout,man,&poly2); ap_abstract1_canonicalize(man,&poly2); ap_abstract1_fprint(stdout,man,&poly2); ap_abstract1_fdump(stdout,man,&poly2); ap_interval_free(itv[0]); ap_interval_free(itv[1]); } /* 4. Tests top and bottom */ poly3 = ap_abstract1_bottom(man,env); tb = ap_abstract1_is_bottom(man,&poly3); fprintf(stdout,"ap_abstract1_is_bottom(poly3)=%d\n",tb); tb = ap_abstract1_is_top(man,&poly3); fprintf(stdout,"ap_abstract1_is_top(poly3)=%d\n",tb); ap_abstract1_clear(man,&poly3); poly3 = ap_abstract1_top(man,env); tb = ap_abstract1_is_bottom(man,&poly3); fprintf(stdout,"ap_abstract1_is_bottom(poly3)=%d\n",tb); tb = ap_abstract1_is_top(man,&poly3); fprintf(stdout,"ap_abstract1_is_top(poly3)=%d\n",tb); ap_abstract1_clear(man,&poly3); ap_abstract1_minimize(man,&poly2); ap_abstract1_fprint(stdout,man,&poly2); tb = ap_abstract1_is_bottom(man,&poly2); fprintf(stdout,"ap_abstract1_is_bottom(poly2)=%d\n",tb); tb = ap_abstract1_is_top(man,&poly2); fprintf(stdout,"ap_abstract1_is_top(poly2)=%d\n",tb); /* 5. Tests leq */ tb = ap_abstract1_is_leq(man,&poly,&poly2); fprintf(stdout,"ap_abstract1_is_leq(poly,&poly2)=%d\n",tb); tb = ap_abstract1_is_leq(man,&poly2,&poly); fprintf(stdout,"ap_abstract1_is_leq(poly,&poly2)=%d\n",tb); /* 6. Tests sat_interval */ itv = ap_interval_alloc(); ap_interval_set_double(itv,-6.0,6.0); tb = ap_abstract1_sat_interval(man,&poly,"z",itv); fprintf(stdout,"ap_abstract1_sat_interval(poly,z)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",tb); tb = ap_abstract1_sat_interval(man,&poly,"w",itv); fprintf(stdout,"ap_abstract1_sat_interval(poly,w)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",tb); tb = ap_abstract1_sat_interval(man,&poly,"u",itv); fprintf(stdout,"ap_abstract1_sat_interval(poly,u)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",tb); ap_interval_set_double(itv,-2.5,2.5); tb = ap_abstract1_sat_interval(man,&poly,"z",itv); fprintf(stdout,"ap_abstract1_sat_interval(poly,z)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",tb); tb = ap_abstract1_sat_interval(man,&poly,"w",itv); fprintf(stdout,"ap_abstract1_sat_interval(poly,w)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",tb); tb = ap_abstract1_sat_interval(man,&poly,"u",itv); fprintf(stdout,"ap_abstract1_sat_interval(poly,u)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",tb); ap_interval_set_double(itv,-1.4,2.0); tb = ap_abstract1_sat_interval(man,&poly,"z",itv); fprintf(stdout,"ap_abstract1_sat_interval(poly,z)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",tb); tb = ap_abstract1_sat_interval(man,&poly,"w",itv); fprintf(stdout,"ap_abstract1_sat_interval(poly,w)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",tb); tb = ap_abstract1_sat_interval(man,&poly,"u",itv); fprintf(stdout,"ap_abstract1_sat_interval(poly,u)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",tb); ap_scalar_set_frac(itv->inf,-14,10); ap_scalar_set_double(itv->sup,2.0); tb = ap_abstract1_sat_interval(man,&poly,"z",itv); fprintf(stdout,"ap_abstract1_sat_interval(poly,z)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",tb); tb = ap_abstract1_sat_interval(man,&poly,"w",itv); fprintf(stdout,"ap_abstract1_sat_interval(poly,w)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",tb); tb = ap_abstract1_sat_interval(man,&poly,"u",itv); fprintf(stdout,"ap_abstract1_sat_interval(poly,u)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",tb); ap_interval_free(itv); /* 7. Tests sat_lincons with -3x-4y+z-w */ expr = ap_linexpr1_make(env,AP_LINEXPR_DENSE,0); ap_linexpr1_set_cst_scalar_int(&expr,0); ap_linexpr1_set_coeff_scalar_int(&expr,"x",-3); ap_linexpr1_set_coeff_scalar_int(&expr,"y",-4); ap_linexpr1_set_coeff_scalar_int(&expr,"z",1); ap_linexpr1_set_coeff_scalar_int(&expr,"w",-1); cons = ap_lincons1_make(AP_CONS_SUPEQ,&expr); itv = ap_abstract1_bound_linexpr(man,&poly,&expr); fprintf(stdout,"Bound of "); ap_linexpr1_fprint(stdout,&expr); fprintf(stdout,": "); ap_interval_fprint(stdout,itv); fprintf(stdout,"\n"); ap_interval_free(itv); for (i=0; i<6; i++){ ap_linexpr1_set_cst_scalar_frac(&expr,-26 + (int)i*10, 5); *(ap_lincons1_constypref(&cons)) = AP_CONS_SUPEQ; tb = ap_abstract1_sat_lincons(man,&poly,&cons); fprintf(stdout,"ap_abstract1_sat_lincons(poly)"); ap_lincons1_fprint(stdout,&cons); fprintf(stdout,": %d\n",tb); *(ap_lincons1_constypref(&cons)) = AP_CONS_SUP; tb = ap_abstract1_sat_lincons(man,&poly,&cons); fprintf(stdout,"ap_abstract1_sat_lincons(poly)"); ap_lincons1_fprint(stdout,&cons); fprintf(stdout,": %d\n",tb); } ap_linexpr1_set_cst_scalar_int(&expr,0); ap_linexpr1_set_coeff_scalar_frac(&expr,"z",-2,3); ap_linexpr1_set_coeff_scalar_double(&expr,"w",2.0); itv = ap_abstract1_bound_linexpr(man,&poly,&expr); fprintf(stdout,"Bound of "); ap_linexpr1_fprint(stdout,&expr); fprintf(stdout,": "); ap_interval_fprint(stdout,itv); fprintf(stdout,"\n"); ap_interval_free(itv); for (i=0; i<6; i++){ ap_linexpr1_set_cst_scalar_int(&expr,-1+(int)i); *(ap_lincons1_constypref(&cons)) = AP_CONS_SUPEQ; tb = ap_abstract1_sat_lincons(man,&poly,&cons); fprintf(stdout,"ap_abstract1_sat_lincons(poly)"); ap_lincons1_fprint(stdout,&cons); fprintf(stdout,": %d\n",tb); *(ap_lincons1_constypref(&cons)) = AP_CONS_SUP; tb = ap_abstract1_sat_lincons(man,&poly,&cons); fprintf(stdout,"ap_abstract1_sat_lincons(poly)"); ap_lincons1_fprint(stdout,&cons); fprintf(stdout,": %d\n",tb); } ap_linexpr1_clear(&expr); ap_lincons1_array_clear(&array); ap_environment_free(env); ap_environment_free(envXY); ap_environment_free(envZW); ap_environment_free(envXYZW); *ppo1 = poly; *ppo2 = poly2; } int main(int argc, char**argv) { ap_manager_t* man; ap_abstract1_t a1,a2; test_environment(); man = pk_manager_alloc(true); absval1(man,&a1,&a2); ap_abstract1_clear(man,&a1); ap_abstract1_clear(man,&a2); ap_manager_free(man); } apron-dist-0.9.10/apron/newpolka/pk_vector.h0000640014525101416610000000522710760562320020660 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_vector.h: operations on vectors */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ /* This header file defines operations on vectors. A vector is just an array of elements of type pkint_t, as a consequence functions need to be given also their size. */ #ifndef __PK_VECTOR_H__ #define __PK_VECTOR_H__ #include "pk_config.h" #include "pk_internal.h" #ifdef __cplusplus extern "C" { #endif /* Basic Operations */ numint_t* vector_alloc(size_t size); void vector_realloc(numint_t** q, size_t size, size_t nsize); void vector_free(numint_t* q, size_t size); void vector_clear(numint_t* q, size_t size); void vector_copy(numint_t* q1, numint_t* q2, size_t size); void vector_print(numint_t* q, size_t size); /* Normalization */ bool vector_normalize(pk_internal_t* pk, numint_t* q, size_t size); bool vector_normalize_expr(pk_internal_t* pk, numint_t* q, size_t size); bool vector_normalize_constraint(pk_internal_t* pk, numint_t* q, size_t intdim, size_t realdim); bool vector_normalize_constraint_int(pk_internal_t* pk, numint_t* q, size_t intdim, size_t realdim); /* Comparison */ int vector_compare(pk_internal_t* pk, numint_t* q1, numint_t* q2, size_t size); /* Combination and Algebraic Operations */ void vector_combine(pk_internal_t* pk, numint_t* q1, numint_t* q2, numint_t* q3, size_t k, size_t size); void vector_product(pk_internal_t* pk, numint_t prod, numint_t* q1, numint_t* q2, size_t size); void vector_product_strict(pk_internal_t* pk, numint_t prod, numint_t* r1, numint_t* r2, size_t size); /* Predicates that can be useful for users */ bool vector_is_null(pk_internal_t* pk, numint_t* q, size_t size); bool vector_is_null_strict(pk_internal_t* pk, numint_t* q, size_t size); bool vector_is_positivity_constraint(pk_internal_t* pk, numint_t* q, size_t size); bool vector_is_dummy_constraint(pk_internal_t* pk, numint_t* q, size_t size); bool vector_is_dummy_or_strict_generator(pk_internal_t* pk, numint_t* q, size_t size); bool vector_is_integer(pk_internal_t* pk, numint_t* vec, size_t intdim, size_t realdim); long vector_hash(pk_internal_t* pk, numint_t* vec,size_t size); /* Functions meant to be internal */ numint_t* _vector_alloc_int(size_t size); void vector_gcd(pk_internal_t* pk, numint_t* q, size_t size, numint_t gcd); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/newpolka/pk_meetjoin.h0000640014525101416610000000320010662337504021162 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_meetjoin.h: Meet and join operations */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _PK_MEETJOIN_H_ #define _PK_MEETJOIN_H_ #include "pk_config.h" #include "pk.h" #ifdef __cplusplus extern "C" { #endif /* ********************************************************************** */ /* I. Meet/Join */ /* ********************************************************************** */ /* In all the following functions, for the structure poly_t: - If meet is true, standard meaning of everything - If meet is false, - matrices C and F, satC and satF have been exchanged, - nbeq and nbline have been exchanged - in status, nothing has changed */ /* Meet/Join of a polyhedronwith an array of constraints/generators. The polyhedron is supposed: - to have constraints, - if lazy is false, to be minimized, and to have satC - possible emptiness not detected, Matrix of constraints is supposed: - to be sorted - to be canonical too. Return true if exception */ bool poly_meet_matrix(bool meet, bool lazy, ap_manager_t* man, pk_t* po, pk_t* pa, matrix_t* mat); void poly_meet_itv_lincons_array(bool lazy, ap_manager_t* man, pk_t* po, pk_t* pa, itv_lincons_array_t* array); void poly_meet(bool meet, bool lazy, ap_manager_t* man, pk_t* po, pk_t* pa, pk_t* pb); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/newpolka/pk_constructor.h0000640014525101416610000000173210613136246021741 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_constructor.h: constructors and accessors */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _PK_CONSTRUCTOR_H_ #define _PK_CONSTRUCTOR_H_ #include "pk_config.h" #include "pk_vector.h" #include "pk_satmat.h" #include "pk_matrix.h" #include "pk.h" #ifdef __cplusplus extern "C" { #endif /* Fill the first (pk->dec-1) rows of the matrix with the constraints of the universe polyhedron */ void matrix_fill_constraint_top(pk_internal_t* pk, matrix_t* C, size_t start); /* Assign with GMP semantics the given polyhedron with the empty (resp. universe) polyhedron, of same dimensions */ void poly_set_bottom(pk_internal_t* pk, pk_t* po); void poly_set_top(pk_internal_t* pk, pk_t* po); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/newpolka/COPYING0000640014525101416610000006402410440065156017546 0ustar bjeannetpopart This license applies to all files distributed in the APRON library, including all source code, libraries, binaries, and documentation. Copyright (C) Bertrand Jeannet 1998-2006 for the newpolka subpackage. GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! apron-dist-0.9.10/apron/newpolka/test.ml0000640014525101416610000001501110553434441020016 0ustar bjeannetpopart (* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution. *) (* #load "camllib.cma";; polkatopg -I $MLGMPIDL_INSTALL/lib -I $MLAPRONIDL_INSTALL/lib -I $CAMLLIB_INSTALL/lib #load "gmp.cma";; #load "apron.cma";; #load "polka.cma";; *) open Apron;; open Mpqf open Format ;; let assoc = function | 0 -> "x" | 1 -> "y" | 2 -> "z" | 3 -> "w" | 4 -> "u" | 5 -> "v" | 6 -> "a" | 7 -> "b" ;; let print_array = Abstract0.print_array;; let man = Polka.manager_alloc true;; let maneq = Polkaeq.manager_alloc ();; let print_linexpr0 fmt x = Linexpr0.print assoc fmt x;; let print_lincons0 fmt x = Lincons0.print assoc fmt x;; let print_generator0 = Generator0.print assoc;; let print_abstract0 fmt a = Abstract0.print assoc fmt a;; (* if Abstract0.is_bottom man a = Manager.True then Format.pp_print_string fmt "bottom" else if Abstract0.is_top man a = Manager.True then Format.pp_print_string fmt "top" else begin let tab = Abstract0.to_lincons_array man a in print_array (Lincons0.print assoc) fmt tab; end *) (* #install_printer print_linexpr0;; #install_printer print_lincons0;; #install_printer print_generator0;; #install_printer print_abstract0;; *) let mine1 man = let expr = Linexpr0.make None in Linexpr0.set_coeff expr 0 (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_int (-3)))); Linexpr0.set_coeff expr 1 (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_int (-3)))); Linexpr0.set_cst expr (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_int 14))); let tab = Array.make 1 (Lincons0.make expr Lincons0.SUPEQ) in let poly = Abstract0.of_lincons_array man 0 2 tab in printf "poly=%a@." print_abstract0 poly; let poly2 = Abstract0.expand man poly 1 2 in printf "poly=%a@." print_abstract0 poly2; () ;; let _ = mine1 man ;; let mine2 man = let fopt = Manager.get_funopt man Manager.Funid_join in let fopt2 = { fopt with Manager.flag_exact_wanted = true; Manager.flag_best_wanted = true } in Manager.set_funopt man Manager.Funid_join fopt2; let expr = Linexpr0.make None in Linexpr0.set_coeff expr 1 (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_int (4)))); Linexpr0.set_coeff expr 2 (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_int (4)))); Linexpr0.set_cst expr (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_int 17))); let tab = Array.make 1 (Lincons0.make expr Lincons0.SUPEQ) in let poly = Abstract0.of_lincons_array man 0 3 tab in printf "poly=%a@." print_abstract0 poly; let polye = Abstract0.bottom man 0 3 in let poly2 = Abstract0.join man polye poly in printf "poly2=%a@." print_abstract0 poly2; () ;; let _ = mine2 man ;; let mine3 man = let tab = Array.make 2 (Lincons0.make (Linexpr0.make None) Lincons0.SUPEQ) in let expr = Linexpr0.make None in Linexpr0.set_list expr [((Coeff.Scalar (Scalar.Mpqf (Mpqf.of_int (-1)))),0)] (Some (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_int 1)))); tab.(0) <- Lincons0.make expr Lincons0.SUPEQ; let expr = Linexpr0.make None in Linexpr0.set_list expr [((Coeff.Scalar (Scalar.Mpqf (Mpqf.of_int (1)))),0)] (Some (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_frac 1 4)))); tab.(1) <- Lincons0.make expr Lincons0.SUPEQ; let poly = Abstract0.of_lincons_array man 0 2 tab in Abstract0.canonicalize man poly; printf "poly=%a@." print_abstract0 poly; let expr = Linexpr0.make None in Linexpr0.set_list expr [((Coeff.Scalar (Scalar.Mpqf (Mpqf.of_frac 5 2))),0)] (Some (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_int (-1))))) ; let poly2 = Abstract0.assign_linexpr man poly 0 expr None in printf "poly2=%a@." print_abstract0 poly2; () ;; let _ = mine3 man ;; let poly1 man = (* Creation du polyčdre 1/2x+2/3y=1, [1,2]<=z+2w<=4, -2<=1/3z-w<=3, u non contraint *) let tab = Array.make 5 (Lincons0.make (Linexpr0.make None) Lincons0.EQ) in let expr = Linexpr0.make None in Linexpr0.set_coeff expr 0 (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_frac 1 2))); Linexpr0.set_coeff expr 1 (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_frac 2 3))); Linexpr0.set_cst expr (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_int (1)))); tab.(0) <- Lincons0.make expr Lincons0.EQ; let expr = Linexpr0.make None in Linexpr0.set_coeff expr 2 (Coeff.Scalar (Scalar.Float 1.0)); Linexpr0.set_coeff expr 3 (Coeff.Scalar (Scalar.Float 2.0)); Linexpr0.set_cst expr (Coeff.Interval ( Interval.of_infsup (Scalar.Float (-2.0)) (Scalar.Float (-1.0)))); tab.(1) <- Lincons0.make expr Lincons0.SUPEQ; let expr = Linexpr0.make None in Linexpr0.set_coeff expr 2 (Coeff.Scalar (Scalar.Float (-1.0))); Linexpr0.set_coeff expr 3 (Coeff.Scalar (Scalar.Float (-2.0))); Linexpr0.set_cst expr (Coeff.Scalar (Scalar.Float (4.0))); tab.(2) <- Lincons0.make expr Lincons0.SUPEQ; let expr = Linexpr0.make None in Linexpr0.set_coeff expr 2 (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_frac 1 3))); Linexpr0.set_coeff expr 3 (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_int (-1)))); Linexpr0.set_cst expr (Coeff.Scalar (Scalar.Float (2.0))); tab.(3) <- Lincons0.make expr Lincons0.SUPEQ; let expr = Linexpr0.make None in Linexpr0.set_coeff expr 2 (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_frac (-1) 3))); Linexpr0.set_coeff expr 3 (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_int 1))); Linexpr0.set_cst expr (Coeff.Scalar (Scalar.Float (3.0))); tab.(4) <- Lincons0.make expr Lincons0.SUPEQ; printf "tab = %a@." (print_array print_lincons0) tab; let poly = Abstract0.of_lincons_array man 0 6 tab in printf "poly=%a@." print_abstract0 poly; let array = Abstract0.to_generator_array man poly in printf "gen=%a@." (print_array print_generator0) array; Abstract0.canonicalize man poly; printf "poly=%a@." print_abstract0 poly; let array = Abstract0.to_generator_array man poly in printf "gen=%a@." (print_array print_generator0) array; (* Extraction (we first extract values for existing constraints, then for dimensions) *) let titv = Abstract0.to_box man poly in printf "titv=%a@." (print_array Interval.print) titv; for i=0 to 4 do let itv = Abstract0.bound_linexpr man poly tab.(i).Lincons0.linexpr0 in printf "Bound of %a = %a@." print_linexpr0 tab.(i).Lincons0.linexpr0 Interval.print itv; done; (* 2. dimensions *) (* 3. of box *) let poly2 = Abstract0.of_box man 0 6 titv in printf "poly2=%a@." print_abstract0 poly2; (* 4. Tests top and bottom *) let poly3 = Abstract0.bottom man 2 3 in printf "poly3=%a@.is_bottom(poly3)=%a@." print_abstract0 poly3 Manager.print_tbool (Abstract0.is_bottom man poly3); let p2 = Abstract0.expand man poly 2 2 in printf "p2=(expand(poly)=%a@." print_abstract0 p2; poly ;; let p1 = poly1 man;; apron-dist-0.9.10/apron/newpolka/pk_test.h0000640014525101416610000000166210613343214020330 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_test.h: tests on polyhedra */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _PK_TEST_H_ #define _PK_TEST_H_ #include "pk_config.h" #include "pk.h" #ifdef __cplusplus extern "C" { #endif /* F is suppposed to be a valid matrix of ray (i.e., corresponding to a non empty polyhedron. The epsilon component of the constraint is not taken into account. The constraint is considered as strict only if the is_strict paramater telles so. This enables to test the satisfiability of a strict constraint in non-strict mode for the library. */ bool do_generators_sat_vector(pk_internal_t* pk, matrix_t* F, numint_t* tab, bool is_strict); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/newpolka/pk_meetjoin.c0000640014525101416610000004750211247462105021166 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_meetjoin.c: Meet and join operations */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "pk_config.h" #include "pk_vector.h" #include "pk_satmat.h" #include "pk_matrix.h" #include "pk.h" #include "pk_representation.h" #include "pk_user.h" #include "pk_constructor.h" #include "pk_test.h" #include "pk_extract.h" #include "pk_cherni.h" #include "pk_meetjoin.h" #include "ap_generic.h" #include "itv_linearize.h" /* ********************************************************************** */ /* I. Meet/Join */ /* ********************************************************************** */ /* In all the following functions, for the structure poly_t: - If meet is true, standard meaning of everything - If meet is false, - matrices C and F, satC and satF have been exchanged, - nbeq and nbline have been exchanged - in status, nothing has changed */ /* ====================================================================== */ /* I.1 Meet/Join of a (prepared) polyhedron with a sorted matrix of constraints/generators */ /* ====================================================================== */ /* The polyhedron is supposed: - to have constraints, - if lazy is false, to be minimized, and to have satC - possible emptiness not detected, Matrix of constraints is supposed: - to be sorted - to be canonical too. Return true if exception */ bool poly_meet_matrix(bool meet, bool lazy, ap_manager_t* man, pk_t* po, pk_t* pa, matrix_t* mat) { pk_internal_t* pk = (pk_internal_t*)man->internal; assert(mat->_sorted); man->result.flag_best = (pa->intdim==0); man->result.flag_exact = meet; /* lazy behaviour */ if (lazy){ poly_obtain_sorted_C(pk,pa); if (po != pa){ po->C = matrix_merge_sort(pk,pa->C,mat); } else { matrix_merge_sort_with(pk,pa->C,mat); if (pa->F){ matrix_free(pa->F); pa->F=NULL; } if (pa->satC){ satmat_free(pa->satC); pa->satC=NULL; } if (pa->satF){ satmat_free(pa->satF); pa->satF=NULL; } pa->nbeq = pa->nbline = 0; } po->status = 0; } /* strict behaviour */ else { size_t start = pa->C->nbrows; assert(pa->satC); if (po != pa){ po->C = matrix_append(pa->C,mat); po->F = matrix_copy(pa->F); po->satC = satmat_copy_resize_cols(pa->satC, bitindex_size(po->C->nbrows)); po->nbline = pa->nbline; po->nbeq = pa->nbeq; } else { matrix_append_with(pa->C,mat); satmat_resize_cols(pa->satC, bitindex_size(pa->C->nbrows)); } cherni_add_and_minimize(pk,meet,po,start); if (pk->exn) goto _poly_meet_matrix_exit0; po->status = meet ? ( pk_status_consgauss ) : ( pk_status_gengauss ) ; assert( poly_check_dual(pk,po,meet) ); } return false; _poly_meet_matrix_exit0: po->status = 0; { char str[160]; sprintf(str,"conversion from %s of the (intermediate) result\n", (meet ? po->C : po->F) ? "constraints to generators" : "generators to constraints"); ap_manager_raise_exception(man,pk->exn,pk->funid,str); } return true; } /* ====================================================================== */ /* I.2 Meet/Join of two polyhedra, functional and side-effect versions */ /* ====================================================================== */ /* ---------------------------------------------------------------------- */ /* Factorized form */ /* ---------------------------------------------------------------------- */ static bool poly_meet_particularcases(bool meet, bool lazy, ap_manager_t* man, pk_t* po, pk_t* pa, pk_t* pb) { assert(pa!=pb); pk_internal_t* pk = (pk_internal_t*)man->internal; man->result.flag_exact = true; if (meet){ /* Meet */ /* if one is bottom, return bottom */ if ( (!pa->C && !pa->F) || (!pb->C && !pb->F) ){ poly_set_bottom(pk,po); return true; } } else { /* Join */ /* if one is bottom, return a copy of the other */ if (!pa->C && !pa->F){ if (!lazy){ poly_chernikova_dual(man,pb,"of the second argument",false); pk->exn = AP_EXC_NONE; } poly_set(po,pb); return true; } if (!pb->C && !pb->F){ if (!lazy){ poly_chernikova_dual(man,pa,"of the first argument",false); pk->exn = AP_EXC_NONE; } poly_set(po,pa); return true; } /* if one want information about exactness, also test inclusion */ if (pk->funopt->flag_exact_wanted){ poly_dual(pa); poly_dual(pb); if (pk_is_leq(man,pa,pb)){ poly_set(po,pb); goto _poly_meet_particularcases_exit; } else if (pk_is_leq(man,pb,pa)){ poly_set(po,pa); _poly_meet_particularcases_exit: poly_dual(pa); poly_dual(pb); if (po!=pa) poly_dual(po); return true; } } } man->result.flag_exact = false; return false; } void poly_meet(bool meet, bool lazy, ap_manager_t* man, pk_t* po, pk_t* pa, pk_t* pb) { pk_internal_t* pk = (pk_internal_t*)man->internal; int pa_status; man->result.flag_best = true; if (pa==pb){ if (!lazy) poly_chernikova_dual(man,pa,"of the first argument", meet); pk->exn = AP_EXC_NONE; poly_set(po,pa); man->result.flag_exact = true; return; } pa_status = pa->status; /* Set the dimensions of po */ if (po!=pa){ po->intdim = pa->intdim; po->realdim = pa->realdim; assert(!po->C && !po->F && !po->satC && !po->satF); } /* Particular cases */ if (poly_meet_particularcases(meet,lazy,man,po,pa,pb)) return; /* Get the constraint system of pa */ poly_obtain_C_dual(man,pa,"of the first argument",meet); if (pk->exn){ assert(!pa->C); pk->exn = AP_EXC_NONE; man->result.flag_best = man->result.flag_exact = false; if (meet) poly_set(po,pb); else { poly_set_top(pk,po); poly_dual(po); } return; } /* Get the constraint system of pb */ poly_obtain_C_dual(man,pb,"of the second argument",meet); if (pk->exn){ assert(!pb->C); pk->exn = AP_EXC_NONE; man->result.flag_best = man->result.flag_exact = false; if (meet) poly_set(po,pa); else { poly_set_top(pk,po); poly_dual(po); } return; } /* Particular cases again */ if (poly_meet_particularcases(meet,lazy,man,po,pa,pb)) return; /* lazy behaviour */ if (lazy){ _poly_meet_entry0: poly_obtain_sorted_C(pk,pa); poly_obtain_sorted_C(pk,pb); poly_meet_matrix(meet,lazy,man,po,pa,pb->C); } /* strict behaviour */ else { if (po != pa){ int start = 0; /* choice of the starting polyhedron */ if (pa->F && !pb->F) /* only pa is minimized */ start=1; else if (pb->F && !pa->F) /* only pb is minimized */ start=2; else { /* either both or none are minimized */ if (!pa->F && !pb->F){ /* ensure minimization */ poly_chernikova_dual(man,pa,"of the first argument",meet); if (pk->exn){ assert(pa->C); pk->exn = AP_EXC_NONE; start = 2; } poly_chernikova_dual(man,pb,"of the second argument",meet); if (pk->exn){ assert(pb->C); pk->exn = AP_EXC_NONE; if (start==2){ goto _poly_meet_entry0; } else { start = 1; } } /* Particular cases */ if (poly_meet_particularcases(meet,lazy,man,po,pa,pb)) return; } /* Perform the choice */ if (pa->F && pb->F){ if ( pa->nbeq > pb->nbeq || (pa->nbeq == pb->nbeq && (pa->nbline < pb->nbline || pa->C->nbrows >= pb->C->nbrows) ) ) start = 1; else start = 2; } } if (start==2){ pk_t* p = pa; pa=pb; pb=p; } } else { /* ensure minimization of pa */ poly_chernikova_dual(man,pa,"of the first argument",meet); if (pk->exn){ assert(pa->C); pk->exn = AP_EXC_NONE; goto _poly_meet_entry0; } } /* Now, pa is the start polyhedron */ poly_obtain_satC(pa); poly_obtain_sorted_C(pk,pb); poly_meet_matrix(meet,lazy,man,po,pa,pb->C); } assert(poly_check_dual(pk,po,meet)); } /* ====================================================================== */ /* I.3 Meet/Join array */ /* ====================================================================== */ static pk_t* poly_meet_array(bool meet, bool lazy, ap_manager_t* man, pk_t** po, size_t size) { size_t intdim,realdim; pk_t* poly; pk_internal_t* pk = (pk_internal_t*)man->internal; man->result.flag_best = true; /* 1. Special cases */ if (size==0){ ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, pk->funid, "empty array"); man->result.flag_best = man->result.flag_exact = false; poly = pk_top(man,0,1); if (!meet) poly_dual(poly); return poly; } intdim = po[0]->intdim; realdim = po[0]->realdim; poly = poly_alloc(intdim,realdim); if (size==1){ if (!lazy){ poly_chernikova_dual(man,po[0],"of the single argument",meet); pk->exn = AP_EXC_NONE; } poly_set(poly,po[0]); return poly; } else if (size==2){ poly_meet(meet,lazy,man,poly,po[0],po[1]); return poly; } /* 2. General case */ else { matrix_t* C; size_t nbrows; size_t i,j; man->result.flag_best = true; man->result.flag_exact = meet; /* Count the total number of constraints */ nbrows = 0; i = 0; while (iexn){ pk->exn = AP_EXC_NONE; if (!po[i]->C){ man->result.flag_best = man->result.flag_exact = false; poly_set_top(pk, poly); if (!meet) poly_dual(poly); return poly; } } if (!po[i]->C){ /* one polyhedron is empty */ if (meet){ /* We return with bottom */ poly_set_bottom(pk,poly); return poly; } else { /* We exchange po[i] and po[size-1] */ size--; if (iC->nbrows; i++; } } /* if size has been decreased */ if (size<=2){ assert(!meet); if (size==0){ man->result.flag_exact = true; poly_set_bottom(pk,poly); poly_dual(poly); } else if (size==1){ man->result.flag_exact = true; poly_set(poly,po[0]); } else if (size==2){ poly_meet(meet,lazy,man,poly,po[0],po[1]); } return poly; } /* 2.1. lazy behaviour */ if (lazy){ C = matrix_alloc(nbrows,pk->dec+intdim+realdim,true); C->nbrows = 0; C->_sorted = true; for (i=0; iC){ poly_obtain_sorted_C(pk,po[i]); matrix_merge_sort_with(pk,C,po[i]->C); } } poly->C = C; poly->status = 0; } /* 2.2 strict hehaviour */ else { /* Minimizing and selecting the start polyhedron */ j = 0; /* The selected start polyhedron */ for (i=1; iC && po[i]->F); if (po[i]->nbeq > po[j]->nbeq || (po[i]->nbeq == po[j]->nbeq && (po[i]->nbline < po[j]->nbline || po[i]->C->nbrows > po[j]->C->nbrows))) j=i; } /* Add the other polyehdra to the polyhedra of index j */ C = matrix_alloc(nbrows, pk->dec+intdim+realdim,true); C->nbrows = 0; C->_sorted = true; for (i=0; iC); } } matrix_revappend_with(C,po[j]->C); C->_sorted = false; poly->C = C; poly->F = matrix_copy(po[j]->F); poly_obtain_satC(po[j]); poly->satC = satmat_copy_resize_cols(po[j]->satC, bitindex_size(C->nbrows)); poly->nbeq = po[j]->nbeq; poly->nbline = po[j]->nbline; cherni_add_and_minimize(pk,meet,poly,po[j]->C->nbrows); if (pk->exn) goto _poly_meet_array_exit0; poly->status = meet ? ( pk_status_consgauss ) : ( pk_status_gengauss ) ; } assert(poly_check_dual(pk,poly,meet)); return poly; _poly_meet_array_exit0: poly->status = 0; { char str[160]; sprintf(str,"conversion from %s of the (intermediate) result\n", (meet ? poly->C : poly->F) ? "constraints to generators" : "generators to constraints"); ap_manager_raise_exception(man,pk->exn,pk->funid,str); } pk->exn = AP_EXC_NONE; return poly; } } /* ********************************************************************** */ /* II. Meet */ /* ********************************************************************** */ /* ********************************************************************** */ /* II.1 Meet of two or more polyhedra */ /* ********************************************************************** */ pk_t* pk_meet(ap_manager_t* man, bool destructive, pk_t* pa, pk_t* pb) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_MEET); pk_t* po = destructive ? pa : poly_alloc(pa->intdim,pa->realdim); poly_meet(true, pk->funopt->algorithm < 0, man,po,pa,pb); assert(poly_check(pk,po)); return po; } pk_t* pk_meet_array(ap_manager_t* man, pk_t** po, size_t size) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_MEET_ARRAY); pk_t* res = poly_meet_array(true, pk->funopt->algorithm < 0, man,po,size); assert(poly_check(pk,res)); return res; } /* ====================================================================== */ /* II.2 Meet with (array of) linear constraint(s) */ /* ====================================================================== */ /* ---------------------------------------------------------------------- */ /* Factorized version */ void poly_meet_itv_lincons_array(bool lazy, ap_manager_t* man, pk_t* po, pk_t* pa, itv_lincons_array_t* array) { matrix_t* mat; bool quasilinear; pk_internal_t* pk = (pk_internal_t*)man->internal; quasilinear = itv_lincons_array_is_quasilinear(array); /* Get the constraint systems */ if (lazy && quasilinear){ poly_obtain_C(man,pa,"of the argument"); } else { poly_chernikova(man,pa,"of the argument"); } if (pk->exn){ pk->exn = AP_EXC_NONE; if (!pa->C){ man->result.flag_best = man->result.flag_exact = false; poly_set_top(pk,po); return; } } /* if pa is bottom, return bottom */ if ( !pa->C && !pa->F){ man->result.flag_best = man->result.flag_exact = true; poly_set(po,pa); return; } /* quasilinearize if needed */ if (!quasilinear){ itv_t* env = matrix_to_box(pk,pa->F); itv_quasilinearize_lincons_array(pk->itv,array,env,true); itv_array_free(env,pa->intdim+pa->realdim); } itv_linearize_lincons_array(pk->itv,array,true); itv_lincons_array_reduce_integer(pk->itv,array,po->intdim); bool exact = matrix_set_itv_lincons_array(pk,&mat,array,po->intdim,po->realdim,true); matrix_sort_rows(pk,mat); if (!lazy) poly_obtain_satC(pa); poly_meet_matrix(true,lazy,man,po,pa,mat); matrix_free(mat); if (pk->exn){ pk->exn = AP_EXC_NONE; man->result.flag_exact = man->result.flag_best = false; } else { man->result.flag_best = man->result.flag_exact = exact ? true : false; } } pk_t* pk_meet_lincons_array(ap_manager_t* man, bool destructive, pk_t* pa, ap_lincons0_array_t* array) { itv_lincons_array_t tcons; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_MEET_LINCONS_ARRAY); pk_t* po = destructive ? pa : poly_alloc(pa->intdim,pa->realdim); itv_lincons_array_init(&tcons,array->size); itv_lincons_array_set_ap_lincons0_array(pk->itv,&tcons,array); poly_meet_itv_lincons_array(pk->funopt->algorithm<0, man,po,pa,&tcons); itv_lincons_array_clear(&tcons); assert(poly_check(pk,po)); return po; } pk_t* pk_meet_tcons_array(ap_manager_t* man, bool destructive, pk_t* pa, ap_tcons0_array_t* array) { return ap_generic_meet_intlinearize_tcons_array(man,destructive,pa,array, AP_SCALAR_MPQ, AP_LINEXPR_LINEAR, &pk_meet_lincons_array); } /* ********************************************************************** */ /* III. Join */ /* ********************************************************************** */ /* ====================================================================== */ /* III.1 Join of two or more polyhedra, functional and side-effect versions */ /* ====================================================================== */ pk_t* pk_join(ap_manager_t* man, bool destructive, pk_t* pa, pk_t* pb) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_JOIN); pk_t* po = destructive ? pa : poly_alloc(pa->intdim,pa->realdim); poly_dual(pa); if (pb!=pa) poly_dual(pb); /* We take care of possible alias */ poly_meet(false,pk->funopt->algorithm<0, man,po,pa,pb); poly_dual(pa); if (pb!=pa) poly_dual(pb); /* We take care of possible alias */ if (po!=pa) poly_dual(po); return po; } static int poly_cmp(const void* a, const void* b) { pk_t* pa = *((pk_t**)a); pk_t* pb = *((pk_t**)b); return (pa>pb ? 1 : (pa==pb ? 0 : -1)); } pk_t* pk_join_array(ap_manager_t* man, pk_t** po, size_t size) { pk_t** tpoly; pk_t* poly; size_t i; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_JOIN_ARRAY); if (size==0){ ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, AP_FUNID_JOIN_ARRAY, "empty array"); man->result.flag_best = man->result.flag_exact = false; poly = pk_top(man,0,1); return poly; } else if (size==1){ man->result.flag_best = man->result.flag_exact = true; poly = pk_copy(man,po[0]); return poly; } /* We have to take care of possible aliases in the array of polyhedra */ tpoly = malloc(size*sizeof(pk_t*)); memcpy(tpoly, po, size*sizeof(pk_t*)); qsort(tpoly,size,sizeof(pk_t*),poly_cmp); /* remove doublons */ for(i=0;ifunopt->algorithm<0, man,(pk_t**)tpoly,size); for(i=0;iinternal; man->result.flag_best = man->result.flag_exact = true; /* Get the generator systems */ if (lazy){ poly_obtain_F(man,pa,"of the argument"); } else { poly_chernikova(man,pa,"of the argument"); } if (pk->exn){ pk->exn = AP_EXC_NONE; if (!pa->F){ man->result.flag_best = man->result.flag_exact = false; poly_set_top(pk,po); return; } } /* if pa is bottom, return bottom */ if ( !pa->C && !pa->F){ poly_set(po,pa); return; } exact = matrix_set_ap_generator0_array(pk,&mat,array,pa->intdim,pa->realdim); matrix_sort_rows(pk,mat); if (!lazy) poly_obtain_satF(pa); poly_dual(po); if (po!=pa) poly_dual(pa); poly_meet_matrix(false,lazy,man,po,pa,mat); poly_dual(po); if (po!=pa) poly_dual(pa); matrix_free(mat); man->result.flag_exact = exact; } pk_t* pk_add_ray_array(ap_manager_t* man, bool destructive, pk_t* pa, ap_generator0_array_t* array) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_ADD_RAY_ARRAY); pk_t* po = destructive ? pa : poly_alloc(pa->intdim,pa->realdim); poly_add_ray_array(pk->funopt->algorithm<0, man,po,pa,array); assert(poly_check(pk,po)); return po; } apron-dist-0.9.10/apron/newpolka/manager.idl0000777014525101416610000000000011252510553025270 2../mlapronidl/manager.idlustar bjeannetpopartapron-dist-0.9.10/apron/newpolka/polka_caml.c0000640014525101416610000001304711252216517020761 0ustar bjeannetpopart/* File generated from polka.idl */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include "pk.h" #include "pkeq.h" #include "ap_manager.h" #include "apron_caml.h" typedef struct pk_internal_t* internal_ptr; extern void camlidl_apron_manager_funid_ml2c(value, ap_funid_t *); #define camlidl_ml2c_manager_ap_funid_t(v,c,ctx) camlidl_apron_manager_funid_ml2c(v,c) extern value camlidl_apron_manager_funid_c2ml(ap_funid_t *); #define camlidl_c2ml_manager_ap_funid_t(c,ctx) camlidl_apron_manager_funid_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_funopt_t(value, struct ap_funopt_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_funopt_t(struct ap_funopt_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_exc_ml2c(value, ap_exc_t *); #define camlidl_ml2c_manager_ap_exc_t(v,c,ctx) camlidl_apron_manager_exc_ml2c(v,c) extern value camlidl_apron_manager_exc_c2ml(ap_exc_t *); #define camlidl_c2ml_manager_ap_exc_t(c,ctx) camlidl_apron_manager_exc_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_exclog_t(value, struct ap_exclog_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_exclog_t(struct ap_exclog_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_ptr_ml2c(value, ap_manager_ptr *); #define camlidl_ml2c_manager_ap_manager_ptr(v,c,ctx) camlidl_apron_manager_ptr_ml2c(v,c) extern value camlidl_apron_manager_ptr_c2ml(ap_manager_ptr *); #define camlidl_c2ml_manager_ap_manager_ptr(c,ctx) camlidl_apron_manager_ptr_c2ml(c) void camlidl_ml2c_polka_internal_ptr(value _v1, internal_ptr * _c2, camlidl_ctx _ctx) { *_c2 = *((internal_ptr *) Bp_val(_v1)); } value camlidl_c2ml_polka_internal_ptr(internal_ptr * _c2, camlidl_ctx _ctx) { value _v1; _v1 = camlidl_alloc((sizeof(internal_ptr) + sizeof(value) - 1) / sizeof(value), Abstract_tag); *((internal_ptr *) Bp_val(_v1)) = *_c2; return _v1; } value camlidl_polka_pk_manager_alloc_loose(value _unit) { ap_manager_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; /* begin user-supplied calling sequence */ _res = pk_manager_alloc(false); { ap_exc_t i; for (i=1; iinternal; /* end user-supplied calling sequence */ _vres = camlidl_c2ml_polka_internal_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_polka_pk_set_max_coeff_size( value _v_pk, value _v_size) { internal_ptr pk; /*in*/ unsigned int size; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_polka_internal_ptr(_v_pk, &pk, _ctx); size = Int_val(_v_size); pk_set_max_coeff_size(pk, size); camlidl_free(_ctx); return Val_unit; } value camlidl_polka_pk_set_approximate_max_coeff_size( value _v_pk, value _v_size) { internal_ptr pk; /*in*/ unsigned int size; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_polka_internal_ptr(_v_pk, &pk, _ctx); size = Int_val(_v_size); pk_set_approximate_max_coeff_size(pk, size); camlidl_free(_ctx); return Val_unit; } value camlidl_polka_pk_get_max_coeff_size( value _v_pk) { internal_ptr pk; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_polka_internal_ptr(_v_pk, &pk, _ctx); _res = pk_get_max_coeff_size(pk); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_polka_pk_get_approximate_max_coeff_size( value _v_pk) { internal_ptr pk; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_polka_internal_ptr(_v_pk, &pk, _ctx); _res = pk_get_approximate_max_coeff_size(pk); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } apron-dist-0.9.10/apron/newpolka/pk_extract.h0000640014525101416610000000204010613343214021012 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_extract.h: property extraction */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _PK_EXTRACT_H_ #define _PK_EXTRACT_H_ #include "pk_config.h" #include "pk.h" #ifdef __cplusplus extern "C" { #endif /* Bounding by a itv box a matrix of generators. */ itv_t* matrix_to_box(pk_internal_t* pk, matrix_t* F); /* Bounding the value of a dimension in a matrix of generators. mode == 1: sup bound mode == -1: inf bound */ void matrix_bound_dimension(pk_internal_t* pk, itv_t itv, ap_dim_t dim, matrix_t* F); /* Bounding the value of a linear expression (vector) in a matrix of generators. vec is supposed to be of size F->nbcolumns. */ void matrix_bound_vector(pk_internal_t* pk, itv_t itv, numint_t* vec, matrix_t* F); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/newpolka/pkeq.c0000640014525101416610000004614011247462105017617 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_equality.c: linear equalities on top of NewPolka polyhedra */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "pk_config.h" #include "pk_vector.h" #include "pk_satmat.h" #include "pk_matrix.h" #include "pk.h" #include "pk_user.h" #include "pk_representation.h" #include "pk_constructor.h" #include "pk_assign.h" #include "pk_resize.h" #include "pkeq.h" #include "ap_generic.h" /* ********************************************************************** */ /* I. General management */ /* ********************************************************************** */ /* ============================================================ */ /* I.1 Memory */ /* ============================================================ */ /* Return the abstract size of a set of equalities, which is the number of equalities times the dimension */ size_t pkeq_size(ap_manager_t* man, pkeq_t* po) { size_t s; assert (po->C ? (po->C->nbrows >=1) : true); s = (po->C) ? (po->C->nbrows-1) : 0; return s*(po->intdim + po->realdim); } /* ============================================================ */ /* I.2 Control of internal representation */ /* ============================================================ */ static bool equality_check(pk_internal_t* pk, pkeq_t* po) { if (!poly_check(pk,po)) return false; if ((po->C && !po->F) || (!po->C && po->F)){ fprintf(stderr,"equality_check: po->C && !po->F || !po->C && po->F: not in canonical form: \n"); return false; } if (po->C && po->C->nbrows != po->nbeq+1){ fprintf(stderr,"equality_check: po->C->nbrows != po->nbeq+1\n"); return false; } if (po->F && po->F->nbrows != po->nbline+1){ fprintf(stderr,"equality_check: po->F->nbrows != po->nbline+1\n"); return false; } return true; } static void matrix_reduce(matrix_t* mat) { if (mat->nbrows + 4 <= mat->_maxrows){ matrix_minimize(mat); } } static void equality_reduce(ap_manager_t* man, pkeq_t* po) { assert((!po->C && !po->F) || (po->C && po->F)); if (po->C && po->F){ if (po->C->nbrows > po->nbeq + 1){ pk_internal_t* pk = (pk_internal_t*)man->internal; po->C->nbrows = po->nbeq + 1; matrix_fill_constraint_top(pk,po->C,po->nbeq); matrix_reduce(po->C); matrix_free(po->F); po->F = NULL; if (po->satC){ satmat_free(po->satC); po->satC = NULL; } if (po->satF){ satmat_free(po->satF); po->satF = NULL; } poly_chernikova(man,po,"of result"); if (pk->exn){ pk->exn = AP_EXC_NONE; poly_set_top(pk,po); } } } } void pkeq_canonicalize(ap_manager_t* man, pkeq_t* po) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_CANONICALIZE); pk->funopt->algorithm = 1; return pk_canonicalize(man,po); } void pkeq_approximate(ap_manager_t* man, pkeq_t* po, int algorithm) { return; } /* ============================================================ */ /* I.4 Serialization */ /* ============================================================ */ ap_membuf_t pkeq_serialize_raw(ap_manager_t* man, pkeq_t* a) { ap_membuf_t membuf; pk_init_from_manager(man,AP_FUNID_SERIALIZE_RAW); ap_manager_raise_exception(man,AP_EXC_NOT_IMPLEMENTED,AP_FUNID_SERIALIZE_RAW,NULL); membuf.ptr = NULL; membuf.size = 0; return membuf; } pkeq_t* pkeq_deserialize_raw(ap_manager_t* man, void* ptr, size_t* size) { pk_init_from_manager(man,AP_FUNID_DESERIALIZE_RAW); ap_manager_raise_exception(man,AP_EXC_NOT_IMPLEMENTED,AP_FUNID_DESERIALIZE_RAW,NULL); return NULL; } /* ********************************************************************** */ /* II. Constructor, accessors, tests and property extraction */ /* ********************************************************************** */ /* ============================================================ */ /* II.1 Basic constructors */ /* ============================================================ */ /* Abstract an hypercube defined by the array of intervals of size intdim+realdim. */ pkeq_t* pkeq_of_box(ap_manager_t* man, size_t intdim, size_t realdim, ap_interval_t** array) { size_t i; size_t row,dim; pkeq_t* po; itv_t itv; bool ok; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_OF_BOX); pk_internal_realloc_lazy(pk,intdim+realdim); po = poly_alloc(intdim,realdim); po->status = pk_status_conseps; dim = intdim + realdim; po->C = matrix_alloc(pk->dec-1 + dim, pk->dec + dim, false); /* constraints */ row = 0; itv_init(itv); ok = false; for (i=0; iitv,itv,array[i]); if (itv_is_point(pk->itv,itv)){ ok = vector_set_dim_bound(pk,po->C->p[row], (ap_dim_t)i, bound_numref(itv->sup), 0, intdim,realdim, true); if (!ok){ matrix_free(po->C); po->C = NULL; return po; } row++; } } itv_clear(itv); matrix_fill_constraint_top(pk,po->C,row); po->C->nbrows = pk->dec - 1 + row; matrix_reduce(po->C); pk_canonicalize(man,po); man->result.flag_exact = man->result.flag_best = true; return po; } /* ============================================================ */ /* II.3 Tests */ /* ============================================================ */ bool pkeq_is_eq(ap_manager_t* man, pkeq_t* pa, pkeq_t* pb) { pk_init_from_manager(man,AP_FUNID_IS_EQ); pkeq_canonicalize(man,pa); pkeq_canonicalize(man,pb); man->result.flag_exact = man->result.flag_best = true; if (pa->C){ if (pb->C){ if (pa->nbeq != pb->nbeq || pa->nbline != pb->nbline){ return false; } else { size_t i,j; matrix_t* mata = pa->C; matrix_t* matb = pb->C; bool res = true; for (i=0; inbrows; i++){ for (j=0; jnbcolumns; j++){ if (numint_cmp(mata->p[i][j],matb->p[i][j])!=0){ res = false; goto _pkeq_is_eq_exit; } } } _pkeq_is_eq_exit: return res; } } else { return false; } } else { return pb->C ? false : true; } } /* ********************************************************************** */ /* III. Operations */ /* ********************************************************************** */ /* ============================================================ */ /* III.1 Meet and Join */ /* ============================================================ */ pkeq_t* pkeq_meet(ap_manager_t* man, bool destructive, pkeq_t* polya, pkeq_t* polyb) { pkeq_t* po; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_MEET); pk->funopt->algorithm = 1; po = pk_meet(man,destructive,polya,polyb); return po; } pkeq_t* pkeq_meet_array(ap_manager_t* man, pkeq_t** po, size_t size) { pkeq_t* poly; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_MEET); pk->funopt->algorithm = 1; poly = pk_meet_array(man,po,size); return poly; } pkeq_t* pkeq_meet_lincons_array(ap_manager_t* man, bool destructive, pkeq_t* pa, ap_lincons0_array_t* array) { pkeq_t* po; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_MEET_LINCONS_ARRAY); pk->funopt->algorithm = 1; po = pk_meet_lincons_array(man,destructive,pa,array); equality_reduce(man,po); assert(equality_check(pk,po)); return po; } pkeq_t* pkeq_meet_tcons_array(ap_manager_t* man, bool destructive, pkeq_t* pa, ap_tcons0_array_t* array) { pkeq_t* po; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_MEET_TCONS_ARRAY); pk->funopt->algorithm = 1; po = pk_meet_tcons_array(man,destructive,pa,array); equality_reduce(man,po); assert(equality_check(pk,po)); return po; } pkeq_t* pkeq_join(ap_manager_t* man, bool destructive, pkeq_t* polya, pkeq_t* polyb) { pkeq_t* po; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_JOIN); pk->funopt->algorithm = 1; po = pk_join(man,destructive,polya,polyb); equality_reduce(man,po); return po; } pkeq_t* pkeq_join_array(ap_manager_t* man, pkeq_t** po, size_t size) { pkeq_t* poly; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_JOIN); pk->funopt->algorithm = 1; poly = pk_join_array(man,po,size); equality_reduce(man,poly); return poly; } pkeq_t* pkeq_add_ray_array(ap_manager_t* man, bool destructive, pkeq_t* pa, ap_generator0_array_t* array) { pkeq_t* po; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_ADD_RAY_ARRAY); pk->funopt->algorithm = 1; po = pk_add_ray_array(man,destructive,pa,array); equality_reduce(man,po); return po; } /* ============================================================ */ /* III.2 Assignement and Substitutions */ /* ============================================================ */ /* Assignement/Substitution by a linear expression */ static pkeq_t* equality_asssub_linexpr(bool assign, ap_manager_t* man, bool destructive, pkeq_t* pa, ap_dim_t dim, ap_linexpr0_t* linexpr) { pkeq_t* po; pk_internal_t* pk = (pk_internal_t*)man->internal; pk_internal_realloc_lazy(pk,pa->intdim+pa->realdim); /* Return empty if empty */ if (!pa->C && !pa->F){ man->result.flag_best = man->result.flag_exact = true; return destructive ? pa : pk_bottom(man,pa->intdim,pa->realdim); } /* Choose the right technique */ switch (linexpr->cst.discr){ case AP_COEFF_SCALAR: { po = poly_asssub_linexpr_det(assign,man,destructive,pa,dim,linexpr); poly_chernikova(man,po,"of the result"); if (pk->exn) goto _equality_asssub_linexpr_error; equality_reduce(man,po); if (pk->exn) goto _equality_asssub_linexpr_error; /* Is the result exact or best ? */ if (pk->funopt->flag_best_wanted || pk->funopt->flag_exact_wanted){ man->result.flag_best = man->result.flag_exact = (dim < pa->intdim || !ap_linexpr0_is_real(linexpr, pa->intdim)) ? false : true; } else { man->result.flag_best = man->result.flag_exact = (pa->intdim==0); } } break; case AP_COEFF_INTERVAL: po = pkeq_forget_array(man,destructive,pa,&dim,1,false); break; default: abort(); } return po; _equality_asssub_linexpr_error: pk->exn = AP_EXC_NONE; poly_set_top(pk,po); man->result.flag_best = man->result.flag_exact = false; return po; } /* Assignement/Substitution by an array of linear expressions */ static pkeq_t* equality_asssub_linexpr_array(bool assign, ap_manager_t* man, bool destructive, pkeq_t* pa, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size) { size_t i; pkeq_t* po; ap_dim_t* tdimp; ap_linexpr0_t** texprp; size_t sizep; ap_dim_t* tdimforget; size_t sizeforget; pk_internal_t* pk = (pk_internal_t*)man->internal; /* Return empty if empty */ if (!pa->C && !pa->F){ man->result.flag_best = man->result.flag_exact = true; return destructive ? pa : pk_bottom(man,pa->intdim,pa->realdim); } /* Choose the right technique */ tdimp = malloc(size*sizeof(ap_dim_t)); texprp = malloc(size*sizeof(ap_linexpr0_t*)); sizep = 0; tdimforget = malloc(size*sizeof(ap_dim_t)); sizeforget = 0; for (i=0; icst.discr==AP_COEFF_SCALAR){ tdimp[sizep] = tdim[i]; texprp[sizep] = texpr[i]; sizep++; } else { tdimforget[sizeforget] = tdim[i]; sizeforget++; } } if (sizep>0){ po = poly_asssub_linexpr_array_det(assign,man,destructive,pa,tdimp,texprp,sizep); poly_chernikova(man,po,"of the result"); if (pk->exn) goto _equality_asssub_linexpr_array_error; equality_reduce(man,po); if (pk->exn) goto _equality_asssub_linexpr_array_error; if (sizeforget){ po = pkeq_forget_array(man,true,po,tdimforget,sizeforget,false); } } else { po = pkeq_forget_array(man,destructive,pa,tdimforget,sizeforget,false); } /* Is the result exact or best ? */ if (pk->funopt->flag_best_wanted || pk->funopt->flag_exact_wanted){ man->result.flag_best = true; for (i=0;iintdim || !ap_linexpr0_is_real(texpr[i], pa->intdim)){ man->result.flag_best = false; break; } } man->result.flag_exact = man->result.flag_best; } else { man->result.flag_best = man->result.flag_exact = (pa->intdim==0); } free(tdimp); free(texprp); free(tdimforget); return po; _equality_asssub_linexpr_array_error: free(tdimp); free(texprp); free(tdimforget); pk->exn = AP_EXC_NONE; poly_set_top(pk,po); man->result.flag_best = man->result.flag_exact = false; return po; } pkeq_t* pkeq_assign_linexpr_array(ap_manager_t* man, bool destructive, pkeq_t* pa, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, pkeq_t* pb) { pk_init_from_manager(man,AP_FUNID_ASSIGN_LINEXPR_ARRAY); pkeq_t* po; po = size==1 ? equality_asssub_linexpr(true, man,destructive,pa,tdim[0],texpr[0]) : equality_asssub_linexpr_array(true, man,destructive,pa,tdim,texpr,size); if (pb!=NULL){ po = pkeq_meet(man,true,po,pb); } return po; } pkeq_t* pkeq_substitute_linexpr_array(ap_manager_t* man, bool destructive, pkeq_t* pa, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, pkeq_t* pb) { pk_init_from_manager(man,AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY); pkeq_t* po; po = size==1 ? equality_asssub_linexpr(false, man,destructive,pa,tdim[0],texpr[0]) : equality_asssub_linexpr_array(false, man,destructive,pa,tdim,texpr,size); if (pb!=NULL){ po = pkeq_meet(man,true,po,pb); } return po; } pkeq_t* pkeq_assign_texpr_array(ap_manager_t* man, bool destructive, pkeq_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, pkeq_t* dest) { return ap_generic_assign_texpr_array(man,destructive,a,tdim,texpr,size,dest); } pkeq_t* pkeq_substitute_texpr_array(ap_manager_t* man, bool destructive, pkeq_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, pkeq_t* dest) { return ap_generic_substitute_texpr_array(man,destructive,a,tdim,texpr,size,dest); } /* ============================================================ */ /* III.3 Projections */ /* ============================================================ */ pkeq_t* pkeq_forget_array(ap_manager_t* man, bool destructive, pkeq_t* a, ap_dim_t* tdim, size_t size, bool project) { pkeq_t* po; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_FORGET_ARRAY); pk->funopt->algorithm = 1; po = pk_forget_array(man,destructive,a,tdim,size,project); equality_reduce(man,po); return po; } /* ============================================================ */ /* III.4 Change and permutation of dimensions */ /* ============================================================ */ pkeq_t* pkeq_remove_dimensions(ap_manager_t* man, bool destructive, pkeq_t* a, ap_dimchange_t* dimchange) { pkeq_t* po; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_REMOVE_DIMENSIONS); pk->funopt->algorithm = 1; po = pk_remove_dimensions(man,destructive,a,dimchange); equality_reduce(man,po); return po; } /* ============================================================ */ /* III.5 Expansion and folding of dimensions */ /* ============================================================ */ pkeq_t* pkeq_expand(ap_manager_t* man, bool destructive, pkeq_t* a, ap_dim_t dim, size_t n) { pkeq_t* po; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_EXPAND); pk->funopt->algorithm = 1; po = pk_expand(man,destructive,a,dim,n); equality_reduce(man,po); return po; } pkeq_t* pkeq_fold(ap_manager_t* man, bool destructive, pkeq_t* a, ap_dim_t* tdim, size_t size) { pkeq_t* po; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_FOLD); pk->funopt->algorithm = 1; po = pk_fold(man,destructive,a,tdim,size); equality_reduce(man,po); return po; } /* ============================================================ */ /* III.6 Widening */ /* ============================================================ */ pkeq_t* pkeq_widening(ap_manager_t* man, pkeq_t* a1, pkeq_t* a2) { return pk_copy(man,a2); } /* ============================================================ */ /* III.7 Closure operation */ /* ============================================================ */ pkeq_t* pkeq_closure(ap_manager_t* man, bool destructive, pkeq_t* a) { return destructive ? a : pk_copy(man,a); } pk_internal_t* pkeq_manager_get_internal(ap_manager_t* man) { return pk_manager_get_internal(man); } ap_manager_t* pkeq_manager_alloc(void) { ap_manager_t* man; void** funptr; man = pk_manager_alloc(false); man->library = "polka, equalities mode"; funptr = man->funptr; // funptr[AP_FUNID_COPY] = &poly_copy; // funptr[AP_FUNID_FREE] = &poly_free; funptr[AP_FUNID_ASIZE] = &pkeq_size; // funptr[AP_FUNID_MINIMIZE] = &poly_minimize; // funptr[AP_FUNID_CANONICALIZE] = &poly_canonicalize; // funptr[AP_FUNID_HASH] = &poly_hash; funptr[AP_FUNID_APPROXIMATE] = &pkeq_approximate; // funptr[AP_FUNID_FPRINT] = &poly_fprint; // funptr[AP_FUNID_FPRINTDIFF] = &poly_fprintdiff; // funptr[AP_FUNID_FDUMP] = &poly_fdump; funptr[AP_FUNID_SERIALIZE_RAW] = &pkeq_serialize_raw; funptr[AP_FUNID_DESERIALIZE_RAW] = &pkeq_deserialize_raw; // funptr[AP_FUNID_BOTTOM] = &poly_bottom; // funptr[AP_FUNID_TOP] = &poly_top; funptr[AP_FUNID_OF_BOX] = &pkeq_of_box; // funptr[AP_FUNID_DIMENSION] = &poly_dimension; // funptr[AP_FUNID_IS_BOTTOM] = &poly_is_bottom; // funptr[AP_FUNID_IS_TOP] = &poly_is_top; // funptr[AP_FUNID_IS_LEQ] = &poly_is_leq; funptr[AP_FUNID_IS_EQ] = &pkeq_is_eq; // funptr[AP_FUNID_IS_DIMENSION_UNCONSTRAINED] = &poly_is_dimension_unconstrained; // funptr[AP_FUNID_SAT_INTERVAL] = &poly_sat_interval; // funptr[AP_FUNID_SAT_LINCONS] = &poly_sat_lincons; // funptr[AP_FUNID_SAT_TCONS] = &poly_sat_tcons; // funptr[AP_FUNID_BOUND_DIMENSION] = &poly_bound_dimension; // funptr[AP_FUNID_BOUND_LINEXPR] = &poly_bound_linexpr; // funptr[AP_FUNID_BOUND_TEXPR] = &poly_bound_texpr; // funptr[AP_FUNID_TO_BOX] = &poly_to_box; // funptr[AP_FUNID_TO_LINCONS_ARRAY] = &poly_to_lincons_array; // funptr[AP_FUNID_TO_TCONS_ARRAY] = &poly_to_tcons_array; // funptr[AP_FUNID_TO_GENERATOR_ARRAY] = &poly_to_generator_array; funptr[AP_FUNID_MEET] = &pkeq_meet; funptr[AP_FUNID_MEET_ARRAY] = &pkeq_meet_array; funptr[AP_FUNID_MEET_LINCONS_ARRAY] = &pkeq_meet_lincons_array; funptr[AP_FUNID_MEET_TCONS_ARRAY] = &pkeq_meet_tcons_array; funptr[AP_FUNID_JOIN] = &pkeq_join; funptr[AP_FUNID_JOIN_ARRAY] = &pkeq_join_array; funptr[AP_FUNID_ADD_RAY_ARRAY] = &pkeq_add_ray_array; funptr[AP_FUNID_ASSIGN_LINEXPR_ARRAY] = &pkeq_assign_linexpr_array; funptr[AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY] = &pkeq_substitute_linexpr_array; funptr[AP_FUNID_ASSIGN_TEXPR_ARRAY] = &pkeq_assign_texpr_array; funptr[AP_FUNID_SUBSTITUTE_TEXPR_ARRAY] = &pkeq_substitute_texpr_array; //funptr[AP_FUNID_ADD_DIMENSIONS] = &poly_add_dimensions; funptr[AP_FUNID_REMOVE_DIMENSIONS] = &pkeq_remove_dimensions; //funptr[AP_FUNID_PERMUTE_DIMENSIONS] = &poly_permute_dimensions; funptr[AP_FUNID_FORGET_ARRAY] = &pkeq_forget_array; funptr[AP_FUNID_EXPAND] = &pkeq_expand; funptr[AP_FUNID_FOLD] = &pkeq_fold; funptr[AP_FUNID_WIDENING] = &pkeq_widening; funptr[AP_FUNID_CLOSURE] = &pkeq_closure; return man; } apron-dist-0.9.10/apron/newpolka/pk_widening.c0000640014525101416610000001550111023527570021152 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_widening.c: widening */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "pk_config.h" #include "pk_vector.h" #include "pk_bit.h" #include "pk_satmat.h" #include "pk_matrix.h" #include "pk_cherni.h" #include "pk.h" #include "pk_representation.h" #include "pk_user.h" #include "pk_constructor.h" #include "pk_test.h" #include "mf_qsort.h" typedef struct satmat_row_t { bitstring_t* p; /* pointing somewhere in the field pinit of an underlying satmat_t object */ int index; } satmat_row_t; static satmat_row_t* esatmat_of_satmat(satmat_t* sat) { size_t i; satmat_row_t* tab; tab = malloc(sat->nbrows * sizeof(satmat_row_t)); for (i=0; inbrows; i++){ tab[i].p = sat->p[i]; tab[i].index = i; } return tab; } /* Row sorting. We use here the insertion sort. The array tab is supposed to be of size sat->nbrows. */ static void esatmat_isort_rows(satmat_row_t* tab, satmat_t* sat) { size_t i,j; for (i=1; inbrows; i++){ satmat_row_t row = tab[i]; j = i; while (j > 0 && bitstring_cmp(tab[j-1].p, row.p, sat->nbcolumns) > 0){ tab[j] = tab[j-1]; j--; } tab[j] = row; } } /* Row sorting. We use here the quick sort. */ typedef struct qsort_man_t { size_t size; } qsort_man_t; static int qsort_rows_compar(void* qsort_man, const void* p1, const void* p2) { qsort_man_t* qm = (qsort_man_t*)qsort_man; return (bitstring_cmp( ((satmat_row_t*)p1)->p, ((satmat_row_t*)p2)->p, qm->size)); } static void esatmat_sort_rows(satmat_row_t* tab, satmat_t* sat) { if (sat->nbrows>=6){ qsort_man_t qsort_man; qsort_man.size = sat->nbcolumns; qsort2(tab, (size_t)sat->nbrows, sizeof(satmat_row_t), qsort_rows_compar, &qsort_man); } else { esatmat_isort_rows(tab,sat); } } /* Membership test. The following function tests if the given row belongs to the sorted saturation matrix. If it is the case, it returns its rank in the saturation matrix. Otherwise, it returns -1 */ typedef struct bsearch_man_t { bitstring_t* satline; satmat_row_t* tab; size_t size; } bsearch_man_t; static bool bsearch2(bsearch_man_t* man, size_t low, size_t high) { if (high - low <= 4){ size_t i; int res=-1; for (i=low; itab[i].p, man->satline, man->size); if (cmp==0){ res=i; break; } else if (cmp>0) break; } return res; } else { size_t mid = low+(high-low)/2; int cmp = bitstring_cmp(man->tab[mid].p,man->satline,man->size); if (cmp<0) return (bsearch2(man,mid+1,high)); else if (cmp>0) return (bsearch2(man,low,mid)); else return mid; } } static int esatmat_index_in_sorted_rows(bitstring_t* satline, satmat_row_t* tab, satmat_t* sat) { bsearch_man_t man; man.satline = satline; man.tab = tab; man.size = sat->nbcolumns; return bsearch2(&man,0,sat->nbrows); } /* This function defines the standard widening operator. The resulting polyhedron has no frame matrix, unless pa is empty. */ pk_t* pk_widening(ap_manager_t* man, pk_t* pa, pk_t* pb) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_WIDENING); bool widening_affine = pk->funopt->algorithm<=0; poly_chernikova2(man,pa,"of the first argument"); if (pk->exn){ pk->exn = AP_EXC_NONE; man->result.flag_best = man->result.flag_exact = false; return pk_top(man,pa->intdim,pa->realdim); } poly_chernikova2(man,pb,"of the second argument"); if (pk->exn){ pk->exn = AP_EXC_NONE; man->result.flag_best = man->result.flag_exact = false; return pk_top(man,pa->intdim,pa->realdim); } if (!pa->C && !pa->F) /* pa is empty */ return pk_copy(man,pb); else { size_t sat_nbcols; size_t nbrows,i; int index; pk_t* po; bitstring_t* bitstringp; satmat_row_t* tab; /* copy saturation pa->satF, and sort it */ poly_obtain_satF(pa); tab = esatmat_of_satmat(pa->satF); esatmat_sort_rows(tab,pa->satF); sat_nbcols = pa->satF->nbcolumns; po = poly_alloc(pa->intdim,pa->realdim); po->C = matrix_alloc(pk->dec-1+pb->C->nbrows, pb->C->nbcolumns, false); matrix_fill_constraint_top(pk,po->C,0); nbrows = pk->dec-1; /* Adding constraints of pb mutually redundant with some of pa, except if it is mutually redundant with the positivity constraint of pa only. */ bitstringp = bitstring_alloc(sat_nbcols); for (i=0; iC->nbrows; i++){ bitstring_clear(bitstringp,sat_nbcols); cherni_buildsatline(pk, pa->F, pb->C->p[i], bitstringp); index = esatmat_index_in_sorted_rows(bitstringp,tab,pa->satF); if (index>=0){ index = tab[index].index; if (!widening_affine || !vector_is_positivity_constraint(pk, pa->C->p[index], pa->C->nbcolumns)){ /* Belongs to saturation matrix, and does not correspond to the positivity constraint. */ vector_copy(po->C->p[nbrows],pb->C->p[i], pa->C->nbcolumns); nbrows++; } } } free(tab); bitstring_free(bitstringp); po->C->nbrows = nbrows; man->result.flag_best = man->result.flag_exact = false; assert(poly_check(pk,po)); return po; } } /* This second one implements a version parametrized by a set of constraints: when a constraint of this set is verified by both polyhedra, it is kept in the result. */ pk_t* pk_widening_threshold(ap_manager_t* man, pk_t* pa, pk_t* pb, ap_lincons0_array_t* array) { pk_t* po; size_t i,nbrows,nbcols; size_t* tab; size_t size,nb; pk_internal_t* pk = (pk_internal_t*)man->internal; po = pk_widening(man,pa,pb); if (!po->C && !po->F) return po; /* We assume that both pa and pb are minimized, and that po->F==NULL */ nbcols = po->C->nbcolumns; nbrows = po->C->nbrows; matrix_resize_rows_lazy(po->C, nbrows + array->size); for (i=0; isize; i++){ switch(array->p[i].constyp){ case AP_CONS_EQ: break; case AP_CONS_SUPEQ: case AP_CONS_SUP: if (ap_linexpr0_is_linear(array->p[i].linexpr0)){ itv_lincons_set_ap_lincons0(pk->itv, &pk->poly_itv_lincons, &array->p[i]); vector_set_itv_lincons(pk, pk->poly_numintp, &pk->poly_itv_lincons, pa->intdim,pa->realdim,true); if (do_generators_sat_vector(pk,pb->F, pk->poly_numintp, pk->strict && numint_sgn(pk->poly_numintp[polka_eps])<0)) { /* if the constraint is satisfied by pb, add it */ vector_copy(po->C->p[nbrows],pk->poly_numintp,nbcols); nbrows++; } } default: break; } } po->C->nbrows = nbrows; matrix_minimize(po->C); assert(poly_check(pk,po)); return po; } apron-dist-0.9.10/apron/newpolka/pk_matrix.c0000640014525101416610000003434311122234062020646 0ustar bjeannetpopart/* ********************************************************************** */ /* matrix.c: operations on matrices */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "pk_config.h" #include "pk_vector.h" #include "pk_satmat.h" #include "pk_matrix.h" #include "mf_qsort.h" /* ********************************************************************** */ /* I. basic operations: creation, destruction, copying and printing */ /* ********************************************************************** */ /* Internal allocation function: the elements are not initialized. mr is the maximum number of rows, and nc the number of columns. By default, nbrows is initialized to mr . */ matrix_t* _matrix_alloc_int(size_t nbrows, size_t nbcols, bool s) { size_t i; assert(nbcols>0 || nbrows==0); matrix_t* mat = (matrix_t*)malloc(sizeof(matrix_t)); mat->nbrows = mat->_maxrows = nbrows; mat->nbcolumns = nbcols; mat->_sorted = s; mat->p = (numint_t**)malloc(nbrows * sizeof(numint_t*)); for (i=0;ip[i] = _vector_alloc_int(nbcols); } return mat; } /* Standard allocation function, with initialization of the elements. */ matrix_t* matrix_alloc(size_t nbrows, size_t nbcols, bool s) { size_t i; assert(nbcols>0 || nbrows==0); matrix_t* mat = (matrix_t*)malloc(sizeof(matrix_t)); mat->nbrows = mat->_maxrows = nbrows; mat->nbcolumns = nbcols; mat->_sorted = s; mat->p = (numint_t**)malloc(nbrows * sizeof(numint_t*)); for (i=0;ip[i] = vector_alloc(nbcols); } return mat; } /* Reallocation function, to scale up or to downsize a matrix */ void matrix_resize_rows(matrix_t* mat, size_t nbrows) { size_t i; assert (nbrows>0); if (nbrows > mat->_maxrows){ mat->p = (numint_t**)realloc(mat->p, nbrows * sizeof(numint_t*)); for (i=mat->_maxrows; ip[i] = vector_alloc(mat->nbcolumns); } mat->_sorted = false; } else if (nbrows < mat->_maxrows){ for (i=nbrows; i_maxrows; i++){ vector_free(mat->p[i],mat->nbcolumns); } mat->p = (numint_t**)realloc(mat->p,nbrows * sizeof(numint_t*)); } mat->_maxrows = nbrows; mat->nbrows = nbrows; } /* Ensures a minimum size */ void matrix_resize_rows_lazy(matrix_t* mat, size_t nbrows) { if (nbrows>mat->_maxrows) matrix_resize_rows(mat,nbrows); else { mat->_sorted = mat->_sorted && nbrowsnbrows; mat->nbrows = nbrows; } } /* Minimization */ void matrix_minimize(matrix_t* mat) { matrix_resize_rows(mat,mat->nbrows); } /* Deallocation function. */ void matrix_free(matrix_t* mat) { size_t i; for (i=0;i_maxrows;i++){ vector_free(mat->p[i],mat->nbcolumns); } free(mat->p); free(mat); } /* Set all elements to zero. */ void matrix_clear(matrix_t* mat) { size_t i,j; for (i=0; inbrows; i++){ for (j=0; jnbcolumns; j++){ numint_set_int(mat->p[i][j],0); } } } /* Create a copy of the matrix of size nbrows (and not _maxrows). Only ``used'' rows are copied. */ matrix_t* matrix_copy(matrix_t* mat) { size_t i,j; matrix_t* nmat = _matrix_alloc_int(mat->nbrows,mat->nbcolumns,mat->_sorted); for (i=0;inbrows;i++){ for (j=0; jnbcolumns; j++){ numint_init_set(nmat->p[i][j],mat->p[i][j]); } } return nmat; } /* Return true iff the matrices are equal, coeff by coeff */ bool matrix_equal(matrix_t* mata, matrix_t* matb) { int i; size_t j; bool res; res = mata->nbrows==matb->nbrows && mata->nbcolumns==matb->nbcolumns; if (!res) return res; for (i=(int)mata->nbrows-1;i>=0;i--){ for (j=0; jnbcolumns; j++){ res = numint_equal(mata->p[i][j],matb->p[i][j]); if (!res) return res; } } return res; } /* Raw printing function. */ void matrix_fprint(FILE* stream, matrix_t* mat) { size_t i,j; fprintf(stream,"%lu %lu\n", (unsigned long)mat->nbrows, (unsigned long)mat->nbcolumns); for (i=0;inbrows;i++) { for (j=0;jnbcolumns;j++){ numint_fprint(stream,mat->p[i][j]); fprintf(stream," "); } fprintf(stream,"\n"); } } void matrix_print(matrix_t* mat) { matrix_fprint(stdout,mat); } /* ********************************************************************** */ /* II.Operation on rows */ /* ********************************************************************** */ /* compare_rows compares rows of matrix, exch_rows exchanges two rows; normalize_row normalizes a row of a matrix but without considering the first coefficient; combine_rows combine rows l1 and l2 and puts the result in l3 such that l3[k] is zero. */ int matrix_compare_rows(pk_internal_t* pk, matrix_t* mat, size_t l1, size_t l2) { return vector_compare(pk, mat->p[l1], mat->p[l2],mat->nbcolumns); } void matrix_normalize_row(pk_internal_t* pk, matrix_t* mat, size_t l) { vector_normalize(pk, mat->p[l],mat->nbcolumns); } void matrix_combine_rows(pk_internal_t* pk, matrix_t* mat, size_t l1, size_t l2, size_t l3, size_t k) { vector_combine(pk, mat->p[l1], mat->p[l2], mat->p[l3],k,mat->nbcolumns); } void matrix_exch_rows(matrix_t* mat, size_t l1, size_t l2) { numint_t* aux=mat->p[l1]; mat->p[l1]=mat->p[l2]; mat->p[l2]=aux; } void matrix_move_rows(matrix_t* mat, size_t destrow, size_t orgrow, size_t size) { int offset; int i; offset = destrow-orgrow; if (offset>0){ assert(destrow+size<=mat->_maxrows); for (i=(int)(destrow+size)-1; i>=(int)destrow; i--){ matrix_exch_rows(mat,(size_t)i,(size_t)(i-offset)); } } else { assert(orgrow+size<=mat->_maxrows); for(i=(int)destrow; i<(int)(destrow+size); i++){ matrix_exch_rows(mat,(size_t)i,(size_t)(i-offset)); } } } /* ********************************************************************** */ /* */ /* ********************************************************************** */ bool matrix_normalize_constraint(pk_internal_t* pk, matrix_t* mat, size_t intdim, size_t realdim) { bool change1, change2; size_t i; if ( pk->strict && realdim>0 ){ change2=false; for (i=0; inbrows; i++){ change1 = vector_normalize_constraint(pk,mat->p[i],intdim,realdim); change2 = change2 || change1; } if (change2){ mat->_sorted = false; /* Add again \xi-\epsilon<=1 */ size_t nbrows= mat->nbrows; matrix_resize_rows_lazy(mat,nbrows+1); vector_clear(mat->p[nbrows],mat->nbcolumns); numint_set_int(mat->p[nbrows][0],1); numint_set_int(mat->p[nbrows][polka_cst],1); numint_set_int(mat->p[nbrows][polka_eps],-1); } return change2; } else return false; } bool matrix_normalize_constraint_int(pk_internal_t* pk, matrix_t* mat, size_t intdim, size_t realdim) { bool change1, change2; size_t i; if (intdim>0){ change2=false; for (i=0; inbrows; i++){ change1 = vector_normalize_constraint_int(pk,mat->p[i],intdim,realdim); change2 = change2 || change1; } if (change2) mat->_sorted = false; return change2; } else return false; } /* ********************************************************************** */ /* III. Sorting and merging */ /* ********************************************************************** */ /* ====================================================================== */ /* III.1 Sorting */ /* ====================================================================== */ /* We use here the quick sort. There is here no handling of doublons */ typedef struct qsort_man_t { pk_internal_t* pk; size_t size; } qsort_man_t; static int qsort_rows_compar(void* qsort_man, const void* pq1, const void* pq2) { qsort_man_t* qm = (qsort_man_t*)qsort_man; numint_t* q1 = *((numint_t**)pq1); numint_t* q2 = *((numint_t**)pq2); return vector_compare(qm->pk,q1,q2,qm->size); } void matrix_sort_rows(pk_internal_t* pk, matrix_t* mat) { qsort_man_t qsort_man; if (!mat->_sorted){ qsort_man.pk = pk; qsort_man.size = mat->nbcolumns; qsort2(mat->p, mat->nbrows, sizeof(numint_t*), qsort_rows_compar, &qsort_man); mat->_sorted = true; } } /* This variant permutes also the saturation matrix together with the matrix. There is here no handling of doublons. */ typedef struct qsort_t { numint_t* p; bitstring_t* satp; } qsort_t; static int qsort_rows_with_sat_compar(void* qsort_man, const void* q1, const void* q2) { qsort_man_t* qm = (qsort_man_t*)qsort_man; const qsort_t* qs1 = (const qsort_t*)q1; const qsort_t* qs2 = (const qsort_t*)q2; return vector_compare( qm->pk, qs1->p, qs2->p, qm->size ); } void matrix_sort_rows_with_sat(pk_internal_t* pk, matrix_t* mat, satmat_t* sat) { size_t i; qsort_t* qsort_tab; qsort_man_t qsort_man; if (!mat->_sorted){ qsort_man.pk = pk; qsort_man.size = mat->nbcolumns; qsort_tab = (qsort_t*)malloc(mat->nbrows * sizeof(qsort_t)); for (i=0; inbrows; i++){ qsort_tab[i].p = mat->p[i]; qsort_tab[i].satp = sat->p[i]; } qsort2(qsort_tab, mat->nbrows, sizeof(qsort_t), qsort_rows_with_sat_compar, &qsort_man); for (i=0; inbrows; i++){ mat->p[i] = qsort_tab[i].p; sat->p[i] = qsort_tab[i].satp; } free(qsort_tab); mat->_sorted = true; } } /* ====================================================================== */ /* III.2 Append */ /* ====================================================================== */ /* Appending matrices */ matrix_t* matrix_append(matrix_t* mata, matrix_t* matb) { matrix_t* mat; size_t i,l; assert (mata->nbcolumns == matb->nbcolumns); mat = _matrix_alloc_int(mata->nbrows+matb->nbrows,mata->nbcolumns,false); for (i=0;inbrows; i++){ for (l=0; lnbcolumns; l++) numint_init_set(mat->p[i][l],mata->p[i][l]); } for (i=0;inbrows; i++){ for (l=0; lnbcolumns; l++) numint_init_set(mat->p[mata->nbrows+i][l],matb->p[i][l]); } return mat; } void matrix_append_with(matrix_t* mat, matrix_t* cmat) { size_t i,l; size_t nbrows; assert (mat->nbcolumns == cmat->nbcolumns); nbrows = mat->nbrows; matrix_resize_rows_lazy(mat,nbrows+cmat->nbrows); for (i=0;inbrows; i++){ for (l=0; lnbcolumns; l++) numint_set(mat->p[nbrows+i][l],cmat->p[i][l]); } mat->_sorted = false; } /* Given matrices with rows p1,p2,... and q1,q2,...., fills the initial matrix with rows q1,q2,...,p1,p2,.... */ void matrix_revappend_with(matrix_t* mat, matrix_t* cmat) { int i; size_t l; size_t nbrows; assert(mat->nbcolumns == cmat->nbcolumns); nbrows = mat->nbrows; matrix_resize_rows_lazy(mat,nbrows+cmat->nbrows); for (i=nbrows-1; i>=0; i--){ /* exchanging rows i and i+cmat->nbrows */ numint_t* q = mat->p[i+cmat->nbrows]; mat->p[i+cmat->nbrows] = mat->p[i]; mat->p[i] = q; } for (i=0; i<(int)cmat->nbrows; i++){ for (l=0;lnbcolumns; l++){ numint_set(mat->p[i][l],cmat->p[i][l]); } } } /* ====================================================================== */ /* III.3 Addition of sorted rows */ /* ====================================================================== */ /* Merging with sorting */ matrix_t* matrix_merge_sort(pk_internal_t* pk, matrix_t* mata, matrix_t* matb) { size_t i,ia,ib,l; matrix_t* mat; size_t nbrows; assert (mata->nbcolumns == matb->nbcolumns); if (!mata->_sorted || !matb->_sorted){ mat = matrix_append(mata,matb); matrix_sort_rows(pk,mat); } else { mat = _matrix_alloc_int(mata->nbrows+matb->nbrows,mata->nbcolumns,true); i = 0; ia = 0; ib = 0; while (ia < mata->nbrows && ib < matb->nbrows) { int res = vector_compare(pk, mata->p[ia], matb->p[ib], mat->nbcolumns); if (res<=0){ for (l=0; lnbcolumns; l++) numint_init_set(mat->p[i][l],mata->p[ia][l]); ia++; if (res==0) ib++; } else { for (l=0; lnbcolumns; l++) numint_init_set(mat->p[i][l],matb->p[ib][l]); ib++; } i++; } /* does some constraint remain ? */ if (ia < mata->nbrows) { do { for (l=0; lnbcolumns; l++) numint_init_set(mat->p[i][l],mata->p[ia][l]); ia++; i++; } while (ia < mata->nbrows); } else { while (ib < matb->nbrows){ for (l=0; lnbcolumns; l++) numint_init_set(mat->p[i][l],matb->p[ib][l]); ib++; i++; } } nbrows = (size_t)i; /* initialize last rows of mat to zero */ while (inbrows){ for (l=0; lnbcolumns; l++) numint_init(mat->p[i][l]); i++; } mat->nbrows = nbrows; } return mat; } /* This function adds to a sorted matrix the rows of another sorted matrix and leaves the resulting matrix sorted. Identical rows are eliminated. The modified matrix is supposed to be big enough to store the new rows. */ void matrix_merge_sort_with(pk_internal_t* pk, matrix_t* mata, matrix_t* matb) { size_t i,ia,ib,j,k,nbrows,nbrowsa, nbcols; numint_t** numintpp; assert (mata->nbcolumns == matb->nbcolumns); assert (mata->_sorted && matb->_sorted); nbrowsa = mata->nbrows; nbcols = mata->nbcolumns; matrix_resize_rows_lazy(mata, nbrowsa + matb->nbrows); /* one adds the coefficients of matb to mata */ for (i=0; inbrows; i++){ for (j=0; jp[nbrowsa+i][j],matb->p[i][j]); } } /* now we fill numintpp, which will contain the unsorted rows */ nbrows = nbrowsa + matb->nbrows; numintpp = malloc(nbrows*sizeof(numint_t*)); for (i=0; ip[i]; } /* Now we fill mata->p from numintpp */ ia = 0; ib = nbrowsa; i = 0; k = 0; while (ia < nbrowsa && ib < nbrows){ int res = vector_compare(pk, numintpp[ia], numintpp[ib],nbcols); if (res<=0){ mata->p[i] = numintpp[ia]; ia++; if (res==0){ k++; mata->p[nbrows-k] = numintpp[ib]; ib++; } } else { mata->p[i] = numintpp[ib]; ib++; } i++; } /* Are there still constraints ? */ while (ia < nbrowsa){ mata->p[i] = numintpp[ia]; i++; ia++; } while (ib < nbrows){ mata->p[i] = numintpp[ib]; i++; ib++; } mata->nbrows -= k; mata->_sorted = true; free(numintpp); } apron-dist-0.9.10/apron/newpolka/pk_vector.c0000640014525101416610000003555211247462105020660 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_vector.c: operations on vectors */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "pk_config.h" #include "pk_vector.h" #include "pk_internal.h" /* ********************************************************************** */ /* I. Basic operations: creation, destruction, copying and printing */ /* ********************************************************************** */ /* Internal allocation function: the elements are not initialized. */ numint_t* _vector_alloc_int(size_t size){ assert(size>0); return (numint_t*)malloc(size*sizeof(numint_t)); } /* Standard allocation function, with initialization of the elements. */ numint_t* vector_alloc(size_t size) { size_t i; numint_t* q; q = _vector_alloc_int(size); for(i=0; ivector_numintp, of size size, supposed to contain positive values only. It returns its results with pointers index and min. If all coefficients are zero, then index is set to size and *min to 0. This function uses pk->vector_numintp and pk->vector_tmp[0]. */ static void vector_min_notzero(pk_internal_t* pk, size_t size, int* index, numint_t min) { size_t i; numint_t* v = pk->vector_numintp; numint_set_int(min,0); /* search the first non-zero coefficient and stores the index and the coeff in *index and *min */ i = 0; while (i 0){ *index = i; numint_set(min,v[i]); } } i++; } } /* This function computes the pgcd of a vector. This function uses pk->vector_numintp and pk->vector_tmp[0]. */ void vector_gcd(pk_internal_t* pk, numint_t* q, size_t size, numint_t gcd) { size_t i; bool not_all_zero; numint_t* v = pk->vector_numintp; for (i=0;ivector_tmp[0..2] and pk->numintp. */ bool vector_normalize(pk_internal_t* pk, numint_t* q, size_t size) { size_t i; assert(size<=pk->maxcols); /* computation of the pgcd */ vector_gcd(pk,&q[1],size-1, pk->vector_tmp[1]); /* possible division */ if (numint_cmp_int(pk->vector_tmp[1],1)>0){ for (i=1; ivector_tmp[1]); return true; } else return false; } /* The function vector_normalize normalizes the vector considered as an expression. It modifies q[0]. This function use pk->vector_tmp[0..2] and pk->numintp. */ bool vector_normalize_expr(pk_internal_t* pk, numint_t* q, size_t size) { size_t i; assert(size<=pk->maxcols); /* computation of the pgcd */ vector_gcd(pk,&q[0],size, pk->vector_tmp[1]); /* possible division */ if (numint_cmp_int(pk->vector_tmp[1],1)>0){ for (i=0; ivector_tmp[1]); return true; } else return false; } /* The function vector_normalize_constraint normalizes the vector considered as a constraint. - if strict mode, the epsilon coefficient is put to 0 or 1 This function use pk->vector_tmp[0..1] and pk->numintp. */ bool vector_normalize_constraint(pk_internal_t* pk, numint_t* q, size_t intdim, size_t realdim) { size_t i; bool change = false; size_t size = pk->dec+intdim+realdim; assert(pk->dec+intdim+realdim <= pk->maxcols); if (pk->strict && numint_sgn(q[0])!=0 && numint_sgn(q[polka_eps])<0){ /* computation of the pgcd without epsilon */ change = (numint_cmp_int(q[polka_eps],-1) != 0); numint_set_int(q[polka_eps],0); vector_gcd(pk,&q[1], size-1, pk->vector_tmp[1]); numint_set_int(q[polka_eps],-1); /* possible division */ if (numint_cmp_int(pk->vector_tmp[1],1)>0){ change = true; numint_divexact(q[polka_cst],q[polka_cst],pk->vector_tmp[1]); for (i=pk->dec; ivector_tmp[1]); } } else { vector_normalize(pk,q,size); } return change; } /* The function vector_normalize_constraint_int normalizes the vector considered as a constraint. - if it involves only integer dimensions, the constraint is tightened and renormalized. - it implies standard constraint normalization This function use pk->vector_tmp[0..1] and pk->numintp. */ bool vector_normalize_constraint_int(pk_internal_t* pk, numint_t* q, size_t intdim, size_t realdim) { size_t i; bool change = false; size_t size = pk->dec+intdim+realdim; assert(pk->dec+intdim+realdim <= pk->maxcols); if (intdim>0 && vector_is_integer(pk,q,intdim,realdim) && !vector_is_positivity_constraint(pk,q,size)){ if (pk->strict && numint_sgn(q[polka_eps])<0){ change = true; numint_set_int(q[polka_eps],0); numint_sub_uint(q[polka_cst], q[polka_cst], 1); } /* computation of the pgcd without constant (and epsilon, of course) */ vector_gcd(pk, &q[pk->dec], size-pk->dec, pk->vector_tmp[1]); /* possible division */ if (numint_cmp_int(pk->vector_tmp[1],1)>0){ change = true; for (i=pk->dec; ivector_tmp[1]); /* round the constant coefficient */ if (numint_sgn(q[0])==0){ numint_mod(q[0],q[polka_cst],pk->vector_tmp[1]); if (numint_sgn(q[0])){ vector_clear(q,size); numint_set_int(q[polka_cst],1); } else { numint_divexact(q[polka_cst],q[polka_cst],pk->vector_tmp[1]); } } else { numint_fdiv_q(q[polka_cst],q[polka_cst],pk->vector_tmp[1]); } } } else { change = vector_normalize_constraint(pk,q,intdim,realdim); } return change; } /* ********************************************************************** */ /* III. Comparison function */ /* ********************************************************************** */ /* Comparison function for vectors The used order is the lexicographic order, with the exception that the constant (and possibly epsilon) coefficient is considered last. As a consequence, the equations or lines are classified before the inequalities or rays when vectors are rows of a sorted matrix. The meaning of the returned result res is: - <0 : q1 is smaller than q2 - =0 : they are equal - >0: q1 is greater than q2 This function uses pk->vector_tmp[0..3] and pk->vector_numintp. */ int vector_compare(pk_internal_t* pk, numint_t* q1, numint_t* q2, size_t size) { size_t i; int res=1; assert(size<=pk->maxcols); /* bidirectional/unidirectional ? */ res = numint_cmp(q1[0],q2[0]); if (res) return res; /* comparison */ for(i=pk->dec; istrict && polka_eps < size){ res = numint_cmp(q1[polka_eps],q2[polka_eps]); } } return res; } /* ********************************************************************** */ /* IV. Combine function */ /* ********************************************************************** */ /* vector_combine computes a combination q3 of q1 and q2 such that q3[k]=0. The first coefficient is never considered for computations, except when k==0. This function uses pk->vector_tmp[0..4] and pk->vector_numintp. */ void vector_combine(pk_internal_t* pk, numint_t* q1, numint_t* q2, numint_t* q3, size_t k, size_t size) { size_t j; numint_gcd(pk->vector_tmp[0],q1[k],q2[k]); numint_divexact(pk->vector_tmp[1],q1[k],pk->vector_tmp[0]); numint_divexact(pk->vector_tmp[2],q2[k],pk->vector_tmp[0]); for (j=1;jvector_tmp[3],pk->vector_tmp[2],q1[j]); numint_mul(pk->vector_tmp[4],pk->vector_tmp[1],q2[j]); numint_sub(q3[j],pk->vector_tmp[3],pk->vector_tmp[4]); } } numint_set_int(q3[k],0); vector_normalize(pk,q3,size); if (pk->max_coeff_size){ for (j=0; j pk->max_coeff_size){ pk->exn = AP_EXC_OVERFLOW; } } } } //* ********************************************************************** */ /* V. Algebraic operations */ /* ********************************************************************** */ /* Scalar product. Compute the scalar product of q1 and q2 considered as vectors of length size. The first coefficients are never considered. This function uses pk->vector_tmp[0]. */ void vector_product(pk_internal_t* pk, numint_t prod, numint_t* q1, numint_t* q2, size_t size) { size_t j; numint_set_int(prod,0); for (j=1; jvector_tmp[0],q1[j],q2[j]); numint_add(prod,prod,pk->vector_tmp[0]); } } /* Same as previous function, but in case where pk->strict is true, the $\epsilon$ coefficients are not taken into account. */ void vector_product_strict(pk_internal_t* pk, numint_t prod, numint_t* q1, numint_t* q2, size_t size) { size_t j; if (polka_cstdec; jvector_tmp[0],q1[j],q2[j]); numint_add(prod,prod,pk->vector_tmp[0]); } } /* ********************************************************************** */ /* VI. Predicates */ /* ********************************************************************** */ /* The function tests if the given vector is null. */ bool vector_is_null(pk_internal_t* pk, numint_t* q, size_t size) { size_t i; bool res = true; for (i=1; ipolka_cst){ res = numint_sgn(q[polka_cst])==0; if (res){ for (i=pk->dec; idec){ return false; } else { size_t i; bool res; res = numint_sgn(q[0])>0; if (res){ int s = numint_sgn(q[polka_cst]); if (s>0){ /* Tests if it could be the positivity constraint */ res = pk->strict ? numint_sgn(q[polka_eps])<0 : true; } if (res){ for (i=pk->dec; idec){ return false; } else { size_t i; bool res; res = numint_sgn(q[0])>0; if (res){ int s = numint_sgn(q[polka_cst]); if (s>0){ /* Tests if it could be the positivity constraint */ res = pk->strict ? numint_sgn(q[polka_eps])<0 : true; } else if (s==0){ /* Tests if it could be the strictness constraint */ res = pk->strict && numint_sgn(q[polka_eps])>0; } if (res){ for (i=pk->dec; idec){ return false; } else if (!numint_sgn(q[0])) /* line */ return false; else if (pk->strict && numint_sgn(q[polka_eps])) return true; else return false; } /* Return true if all dimensions involved in the expression are integer dimensions */ bool vector_is_integer(pk_internal_t* pk, numint_t* vec, size_t intdim, size_t realdim) { size_t i; for (i=intdim; idec+i]) != 0){ return false; } } return true; } long vector_hash(pk_internal_t* pk,numint_t* vec, size_t size) { long res,t; size_t i; int_set_numint(&t,vec[polka_cst]); res = t; for (i=pk->dec; idec)+2)/3){ int_set_numint(&t,vec[i]); res = res*3 + t; } return res; } apron-dist-0.9.10/apron/newpolka/pk_approximate.c0000640014525101416610000002526711034445301021702 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_approximate.c: approximate function */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "pk_config.h" #include "pk_vector.h" #include "pk_satmat.h" #include "pk_matrix.h" #include "pk_cherni.h" #include "pk.h" #include "pk_user.h" #include "pk_representation.h" #include "pk_extract.h" #include "pk_constructor.h" static void poly_set_save_C(pk_t* po, pk_t* pa) { if (po != pa){ po->F = pa->F ? matrix_copy(pa->F) : NULL; po->satC = pa->satC ? satmat_copy(pa->satC) : NULL; po->satF = pa->satF ? satmat_copy(pa->satF) : NULL; po->status = pa->status; po->nbeq = pa->nbeq; po->nbline = pa->nbline; po->status = pa->status; } } /* ---------------------------------------------------------------------- */ /* Normalize integer constraints. Return true if there is some change. */ /* ---------------------------------------------------------------------- */ static bool poly_approximate_n1(ap_manager_t* man, pk_t* po, pk_t* pa, int algorithm) { if (po->intdim>0){ pk_internal_t* pk = (pk_internal_t*)man->internal; bool change; poly_obtain_C(man,pa,NULL); if (!pa->C){ poly_set(po,pa); return false; } if (po!=pa){ po->C = matrix_copy(pa->C); } change = matrix_normalize_constraint_int(pk,po->C,po->intdim,po->realdim); if (change){ { /* Add positivity and strictness that may not be implied any more */ size_t nbrows = po->C->nbrows; matrix_resize_rows_lazy(po->C,nbrows+pk->dec-1); matrix_fill_constraint_top(pk,po->C,nbrows); } if (po==pa){ if (po->F){ matrix_free(po->F); po->F = NULL; } if (po->satC){ satmat_free(po->satC); po->satC = NULL; } if (po->satF){ satmat_free(po->satF); po->satF = NULL; } } po->status = 0; po->C->_sorted = false; man->result.flag_exact = false; } else { poly_set_save_C(po,pa); } return change; } else return false; } /* ---------------------------------------------------------------------- */ /* Remove constraints with coefficients of size greater than pk->max_coeff_size, if pk->max_coeff_size > 0 */ /* ---------------------------------------------------------------------- */ static bool matrix_approximate_constraint_1(pk_internal_t* pk, matrix_t* C) { size_t i,j; bool change; change = false; for (i=0;inbrows; i++){ if (numint_sgn(C->p[i][0])){ for (j=pk->dec; jnbcolumns; j++){ if (numint_size2(C->p[i][j]) > pk->approximate_max_coeff_size){ change = true; C->nbrows--; matrix_exch_rows(C,i,C->nbrows); break; } } } } if (change){ /* Add positivity and strictness that may not be implied any more */ size_t nbrows = C->nbrows; matrix_resize_rows_lazy(C,nbrows+pk->dec-1); matrix_fill_constraint_top(pk,C,nbrows); C->_sorted = false; } return change; } static bool poly_approximate_1(ap_manager_t* man, pk_t* po, pk_t* pa) { bool change; pk_internal_t* pk = (pk_internal_t*)man->internal; poly_obtain_C(man,pa,NULL); if (!pa->C){ poly_set(po,pa); return false; } if (po!=pa){ po->C = matrix_copy(pa->C); } change = matrix_approximate_constraint_1(pk,po->C); if (change){ if (po==pa){ if (po->F){ matrix_free(po->F); po->F = NULL; } if (po->satC){ satmat_free(po->satC); po->satC = NULL; } if (po->satF){ satmat_free(po->satF); po->satF = NULL; } } po->status = 0; man->result.flag_exact = false; } else { poly_set_save_C(po,pa); man->result.flag_exact = true; } return change; } /* ---------------------------------------------------------------------- */ /* 1. Remove constraints with too big coefficients 2. Add interval constraints 3. Add octagonal constraints */ /* ---------------------------------------------------------------------- */ static void poly_approximate_123(ap_manager_t* man, pk_t* po, int algorithm) { bool change; pk_internal_t* pk = (pk_internal_t*)man->internal; if (algorithm==1){ poly_approximate_1(man,po,po); } else { size_t nbrows, nbrows2; ap_dim_t dim; ap_dim_t i,j; int sgn, sgny; itv_t itv; pk_t* pa = poly_alloc(po->intdim,po->realdim); change = poly_approximate_1(man,pa,po); if (!change){ pk_free(man,pa); return; } poly_obtain_F(man,po,NULL); if (!po->F){ if (!po->C){ pk_free(man,pa); poly_set_bottom(pk,po); man->result.flag_exact = true; return; } else { poly_clear(po); *po = *pa; free(pa); } return; } dim = pa->intdim + pa->realdim; nbrows = pa->C->nbrows; itv_init(itv); if (algorithm>=2){ /* Add interval constraints */ nbrows2 = 2*dim; matrix_resize_rows_lazy(pa->C, nbrows + nbrows2); pa->C->_sorted = false; for (i=0; iF); if (!bound_infty(itv->inf)){ vector_set_dim_bound(pk, pa->C->p[nbrows], i, bound_numref(itv->inf), -1, po->intdim, po->realdim, false); nbrows++; } if (!bound_infty(itv->sup)){ vector_set_dim_bound(pk, pa->C->p[nbrows], i, bound_numref(itv->sup), 1, po->intdim, po->realdim, false); nbrows++; } } } pa->C->nbrows = nbrows; if (algorithm>=3){ /* Add octagonal constraints */ vector_clear(pk->poly_numintp,po->F->nbcolumns); numint_set_int(pk->poly_numintp[0],1); for (i=0; ipoly_numintp[pk->dec+i],1); nbrows2 = 2*(dim-i-1); matrix_resize_rows_lazy(pa->C, nbrows + nbrows2); for (j=i+1; jpoly_numintp[pk->dec+j],sgny); matrix_bound_vector(pk,itv,pk->poly_numintp,po->F); if (!bound_infty(itv->inf)){ vector_set_linexpr_bound(pk, pa->C->p[nbrows], pk->poly_numintp, itv->inf, -1, po->intdim, po->realdim, false); nbrows++; } if (!bound_infty(itv->sup)){ vector_set_linexpr_bound(pk, pa->C->p[nbrows], pk->poly_numintp, itv->sup, 1, po->intdim, po->realdim, false); nbrows++; } } numint_set_int(pk->poly_numintp[pk->dec+j],0); } numint_set_int(pk->poly_numintp[pk->dec+i],0); } pa->C->nbrows = nbrows; } itv_clear(itv); poly_clear(po); *po = *pa; free(pa); return; } } /* ---------------------------------------------------------------------- */ /* 10. Round constraints with too big coefficients */ /* ---------------------------------------------------------------------- */ static bool matrix_approximate_constraint_10(pk_internal_t* pk, matrix_t* C, matrix_t* F) { size_t i,j,size; bool change,removed; itv_t itv; itv_init(itv); change = false; i = 0; while (inbrows){ removed = false; if (numint_sgn(C->p[i][0]) && (pk->strict ? numint_sgn(C->p[i][polka_eps])<=0 : true)){ /* Look for a too big coefficient in the row */ size=0; /* for next test */ for (j=pk->dec; jnbcolumns; j++){ size = numint_size2(C->p[i][j]); if (size > pk->approximate_max_coeff_size){ /* Too big coefficient detected in the row */ break; } } if (size > pk->approximate_max_coeff_size){ /* Too big coefficient detected in the row */ /* A. Compute maximum magnitude */ size_t maxsize = size; for (j=j+1; jnbcolumns; j++){ size = numint_size2(C->p[i][j]); if (size>maxsize) maxsize=size; } /* B. Relax if constraint is strict */ if (pk->strict){ numint_set_int(C->p[i][polka_eps],0); } /* C. Perform rounding of non constant coefficients */ size = maxsize - pk->approximate_max_coeff_size; for (j=pk->dec; jnbcolumns; j++){ numint_fdiv_q_2exp(C->p[i][j],C->p[i][j], size); } /* D. Compute new constant coefficient */ numint_set_int(C->p[i][0],1); numint_set_int(C->p[i][polka_cst],0); matrix_bound_vector(pk,itv,C->p[i],F); if (bound_infty(itv->inf)){ /* If no bound, we remove the constraint */ C->nbrows--; matrix_exch_rows(C,i,C->nbrows); removed = true; } else { /* Otherwise, we round the constant to an integer */ bound_neg(itv->inf,itv->inf); numint_fdiv_q(numrat_numref(bound_numref(itv->inf)), numrat_numref(bound_numref(itv->inf)), numrat_denref(bound_numref(itv->inf))); numint_neg(C->p[i][polka_cst],numrat_numref(bound_numref(itv->inf))); vector_normalize(pk,C->p[i],C->nbcolumns); } change = true; } } if (!removed) i++; } if (change){ /* Add positivity and strictness that may not be implied any more */ size_t nbrows = C->nbrows; matrix_resize_rows_lazy(C,nbrows+pk->dec-1); matrix_fill_constraint_top(pk,C,nbrows); C->_sorted = false; } itv_clear(itv); return change; } static void poly_approximate_10(ap_manager_t* man, pk_t* po) { bool change; pk_internal_t* pk = (pk_internal_t*)man->internal; poly_chernikova(man,po,"of the argument"); if (pk->exn){ pk->exn = AP_EXC_NONE; return; } if (!po->C && !po->F){ return; } assert(po->C && po->F); change = matrix_approximate_constraint_10(pk, po->C, po->F); if (change){ if (po->F) matrix_free(po->F); if (po->satC) satmat_free(po->satC); if (po->satF) satmat_free(po->satF); po->F = NULL; po->satC = NULL; po->satF = NULL; man->result.flag_exact = false; } else { man->result.flag_exact = true; } } /* Approximation: - algorithm==0: do nothing - algorithm==-1: normalize integer minimal constraints (induces a smaller polyhedron) - algorithm==1: remove constraints with coefficients of size greater than max_coeff_size, if max_coeff_size > 0 - algorithm==2: in addition, keep same bounding box (more precise) - algorithm==3: in addition, keep same bounding octagon (even more precise) - algorithm==10: round constraints with too big coefficients, of size greater than approximate_max_coeff_size, if approximate_max_coeff_size>0 */ void pk_approximate(ap_manager_t* man, pk_t* po, int algorithm) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_APPROXIMATE); man->result.flag_exact = false; man->result.flag_best = false; if (!po->C && !po->F) return; switch (algorithm){ case -1: if (po->intdim>0) poly_approximate_n1(man,po,po,algorithm); break; case 1: case 2: case 3: if (pk->approximate_max_coeff_size>0) poly_approximate_123(man,po,algorithm); break; case 10: if (pk->approximate_max_coeff_size>0) poly_approximate_10(man,po); break; } assert(poly_check(pk,po)); } apron-dist-0.9.10/apron/newpolka/Makefile0000640014525101416610000002172311251737120020150 0ustar bjeannetpopartinclude ../Makefile.config PREFIX = $(APRON_PREFIX) SRCDIR = $(shell pwd) #--------------------------------------- # Programs #--------------------------------------- #--------------------------------------- # Flags #--------------------------------------- # Use ICFLAGS to specify machine-independent compilation flags. ICFLAGS = \ -I$(MLGMPIDL_PREFIX)/include \ -I../apron \ -I../num \ -I../itv \ -I../mlapronidl \ -I$(GMP_PREFIX)/include -I$(MPFR_PREFIX)/include \ -I$(CAMLIDL_PREFIX)/lib/ocaml -I$(CAML_PREFIX)/lib/ocaml # Caml OCAMLINC = -I $(MLGMPIDL_PREFIX)/lib -I ../mlapronidl #--------------------------------------- # Files #--------------------------------------- CCMODULES = \ mf_qsort \ pk_user pk_internal pk_bit pk_satmat pk_vector pk_matrix pk_cherni \ pk_representation pk_approximate pk_constructor pk_test pk_extract \ pk_meetjoin pk_assign pk_project pk_resize pk_expandfold \ pk_widening pk_closure \ pkeq CCINC = \ pk_config.h pk.h pkeq.h \ mf_qsort.h pk_internal.h \ pk_user.h pk_bit.h pk_satmat.h pk_vector.h pk_matrix.h pk_cherni.h \ pk_representation.h pk_constructor.h pk_test.h pk_extract.h \ pk_meetjoin.h pk_assign.h pk_resize.h CCSRC = $(CCINC) $(CCMODULES:%=%.c) CCINC_TO_INSTALL = pk.h pkeq.h CCBIN_TO_INSTALL = CCLIB_TO_INSTALL = \ libpolkaMPQ.a libpolkaMPQ_debug.a \ libpolkaRll.a libpolkaRll_debug.a \ libpolkaMPQ.so libpolkaMPQ_debug.so \ libpolkaRll.so libpolkaRll_debug.so \ CAML_TO_INSTALL = \ polka.idl polka.mli polka.ml polka.cmi polka.cmx \ polka.cma polka.cmxa polka.a \ polkaMPQ.cma polkaMPQ.cmxa polkaMPQ.a \ polkaRll.cma polkaRll.cmxa polkaRll.a \ libpolkaMPQ_caml.a libpolkaMPQ_caml_debug.a \ libpolkaRll_caml.a libpolkaRll_caml_debug.a \ libpolkaMPQ_caml.so libpolkaMPQ_caml_debug.so \ libpolkaRll_caml.so libpolkaRll_caml_debug.so \ dllpolkaMPQ_caml.so dllpolkaMPQ_caml_debug.so \ dllpolkaRll_caml.so dllpolkaRll_caml_debug.so #--------------------------------------- # Rules #--------------------------------------- # Possible goals: # depend doc install # and the following one all: allMPQ allRll allMPQ: libpolkaMPQ.a libpolkaMPQ_debug.a allRll: libpolkaRll.a libpolkaRll_debug.a ifneq ($(HAS_SHARED),) allMPQ: libpolkaMPQ.so libpolkaMPQ_debug.so allRll: libpolkaRll.so libpolkaRll_debug.so endif ml: polka.mli polka.ml polka.cmi polka.cmx polka.a mlMPQ mlRll polka.cma polka.cmxa mlMPQ: polkaMPQ.cma polkaMPQ.cmxa libpolkaMPQ_caml.a libpolkaMPQ_caml_debug.a mlRll: polkaRll.cma polkaRll.cmxa libpolkaRll_caml.a libpolkaRll_caml_debug.a ifneq ($(HAS_SHARED),) mlMPQ: libpolkaMPQ_caml.so libpolkaMPQ_caml_debug.so dllpolkaMPQ_caml.so dllpolkaMPQ_caml_debug.so mlRll: libpolkaRll_caml.so libpolkaRll_caml_debug.so dllpolkaRll_caml.so dllpolkaRll_caml_debug.so endif test0%: test0%_debug.o libpolka%_debug.a $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -o $@ $< \ -L. -lpolka$*_debug -L$(APRON_PREFIX)/lib -lapron_debug -L$(MPFR_PREFIX)/lib -lmpfr -L$(GMP_PREFIX)/lib -lgmp -lm test1%: test1%_debug.o libpolka%_debug.a $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -o $@ $< \ -L. -lpolka$*_debug -L$(APRON_PREFIX)/lib -lapron_debug -L$(MPFR_PREFIX)/lib -lmpfr -L$(GMP_PREFIX)/lib -lgmp -lm mlexample%.byte: mlexample.ml box%.cma $(OCAMLC) $(OCAMLFLAGS) -I $(MLGMPIDL_INSTALL)/lib -I $(APRON_PREFIX)/lib -o $@ bigarray.cma gmp.cma apron.cma box$*.cma $< mlexample%.opt: mlexample.ml box%.cmxa $(OCAMLOPT) $(OCAMLOPTFLAGS) -I $(MLGMPIDL_INSTALL)/lib -I $(APRON_PREFIX)/lib -o $@ bigarray.cmxa gmp.cmxa apron.cmxa box$*.cmxa $< clean: /bin/rm -f *.[ao] *.so /bin/rm -f *.?.tex *.log *.aux *.bbl *.blg *.toc *.dvi *.ps *.pstex* /bin/rm -f test[01]Il* test[01]MPQ test[01]Il*_debug test[01]MPQ_debug /bin/rm -fr *.cm[ioax] *.cmxa /bin/rm -f manager.idl /bin/rm -fr tmp mostlyclean: clean /bin/rm -f manager.idl /bin/rm -fr polka_caml.* polka.ml polka.mli install: $(INSTALLd) $(PREFIX)/include $(PREFIX)/lib $(INSTALL) $(CCINC_TO_INSTALL) $(PREFIX)/include for i in $(CCLIB_TO_INSTALL); do \ if test -f $$i; then $(INSTALL) $$i $(PREFIX)/lib; fi; \ done # for i in $(CCBIN_TO_INSTALL); do \ # if test -f $$i; then $(INSTALL) $$i $(PREFIX)/bin; fi; \ # done for i in $(CAML_TO_INSTALL); do \ if test -f $$i; then cp -f -d $$i $(PREFIX)/lib; fi; \ done uninstall: for i in $(CCINC_TO_INSTALL); do /bin/rm -f $(PREFIX)/include/$$i; done /bin/rm -f $(PREFIX)/lib/libpolka*.* $(PREFIX)/lib/liboct*_debug.* /bin/rm -f $(PREFIX)/lib/dllpolka*.so $(PREFIX)/lib/dlloct*_debug.so /bin/rm -f $(PREFIX)/lib/polka.mli $(PREFIX)/lib/polka.ml $(PREFIX)/lib/polka.cm[ix] $(PREFIX)/lib/polka.idl $(PREFIX)/lib/polka*.cma $(PREFIX)/lib/polka*.cmxa $(PREFIX)/lib/polka*.a distclean: uninstall /bin/rm -f Makefile.depend dist: $(CCSRC) Makefile sedscript_caml newpolka.texi polka.idl polka.ml polka.mli polka_caml.c COPYING README (cd ..; tar zcvf newpolka.tgz $(^:%=newpolka/%)) #--------------------------------------- # IMPLICIT RULES AND DEPENDENCIES #--------------------------------------- .SUFFIXES: .tex .c .h .a .o .PRECIOUS: libpolka%.a libpolka%_debug.a libpolka%.so libpolka%_debug.so .PRECIOUS: libpolka%_caml.a libpolka%_caml_debug.a libpolka%_caml.so libpolka%_caml_debug.so .PRECIOUS: %Rl.o %Rll.o %MPQ.o .PRECIOUS: %Rl_debug.o %Rll_debug.o %MPQ_debug.o .PRECIOUS: %.cmo %.cmx #----------------------------------- # C part #----------------------------------- cxref: $(CCMODULES:%=%.c) cxref -I/usr/include -I/usr/lib/gcc/i386-redhat-linux/4.0.2/include $(ICFLAGS) -DNUM_MPQ -no-comments -xref-func -index-func -html32-src -Otmp $^ libpolka%.a: $(subst .c,%.o,$(CCMODULES:%=%.c)) $(AR) rcs $@ $^ $(RANLIB) $@ libpolka%_debug.a: $(subst .c,%_debug.o,$(CCMODULES:%=%.c)) $(AR) rcs $@ $^ $(RANLIB) $@ libpolka%.so: $(subst .c,%.o,$(CCMODULES:%=%.c)) $(CC) $(CFLAGS) -shared -o $@ $^ libpolka%_debug.so: $(subst .c,%_debug.o,$(CCMODULES:%=%.c)) $(CC) $(CFLAGS_DEBUG) -shared -o $@ $^ %Rl.o: %.c $(CCINC) $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_LONGRAT -c -o $@ $< %Rl_debug.o: %.c $(CCINC) $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_LONGRAT -c -o $@ $< %Rll.o: %.c $(CCINC) $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_LONGLONGRAT -c -o $@ $< %Rll_debug.o: %.c $(CCINC) $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_LONGLONGRAT -c -o $@ $< %MPQ.o: %.c $(CCINC) $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_MPQ -I$(GMP_PREFIX)/include -c -o $@ $< %MPQ_debug.o: %.c $(CCINC) $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_MPQ -I$(GMP_PREFIX)/include -c -o $@ $< #----------------------------------- # Caml part #----------------------------------- test_caml: test.cmo polkarun $(OCAMLC) -g $(OCAMLINC) -o $@ -use-runtime polkarun \ bigarray.cma gmp.cma apron.cma polka.cma test.cmo test.cmo: test.ml $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -I $(CAMLLIB_PREFIX)/lib -c $< #--------------------------------------- # OCaml binding #--------------------------------------- libpolka%_caml.a: polka_caml.o libpolka%.a $(AR) rcs $@ $< $(RANLIB) $@ libpolka%_caml_debug.a: polka_caml_debug.o libpolka%_debug.a $(AR) rcs $@ $< $(RANLIB) $@ libpolka%_caml.so: polka_caml.o libpolka%.so $(CC) $(CFLAGS) -shared -o $@ polka_caml.o -L. -lpolka$* -Wl,-rpath,$(APRON_PREFIX)/lib libpolka%_caml_debug.so: polka_caml_debug.o libpolka%_debug.so $(CC) $(CFLAGS_DEBUG) -shared -o $@ polka_caml_debug.o -L. -lpolka$*_debug -Wl,-rpath,$(APRON_PREFIX)/lib dllpolka%_caml.so: libpolka%_caml.so ln -s -f $^ $@ dllpolka%_caml_debug.so: libpolka%_caml_debug.so ln -s -f $^ $@ #--------------------------------------- # OCaml rules #--------------------------------------- polka.cma: polkaMPQ.cma ln -s -f $^ $@ polka.cmxa: polkaMPQ.cmxa ln -s -f $^ $@ polka.a: polkaMPQ.a ln -s -f $^ $@ polka%.cma: polka.cmo libpolka%_caml.a libpolka%.a $(OCAMLMKLIB) -ocamlc "$(OCAMLC)" -verbose -o polka$* -oc polka$*_caml polka.cmo -lpolka$* -L$(APRON_PREFIX)/lib -Wl,-rpath,$(APRON_PREFIX)/lib polka%.cmxa polka%.a: polka.cmx libpolka%_caml.a libpolka%.a $(OCAMLMKLIB) -ocamlopt "$(OCAMLOPT)" -verbose -o polka$* -oc polka$*_caml polka.cmx -lpolka$* -L$(APRON_PREFIX)/lib -Wl,-rpath,$(APRON_PREFIX)/lib #--------------------------------------- # IDL rules #--------------------------------------- manager.idl: ../mlapronidl/manager.idl ln -s -f $< $@ # generates X.ml, X.mli, X_caml.c for X = polka rebuild: manager.idl polka.idl mkdir -p tmp for i in polka; do \ echo "module $$i"; \ cp $${i}.idl tmp/$${i}.idl; \ $(CAMLIDL) -no-include -nocpp tmp/$${i}.idl; \ cp tmp/$${i}_stubs.c $${i}_caml.c; \ $(SED) -f sedscript_caml tmp/$${i}.ml >$${i}.ml; \ $(SED) -f sedscript_caml tmp/$${i}.mli >$${i}.mli; \ done #--------------------------------------- # C generic rules #--------------------------------------- %.o: %.c $(CC) $(CFLAGS) $(ICFLAGS) -DNUMINT_MPQ -c -o $@ $< %_debug.o: %.c $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUMINT_MPQ -c -o $@ $< #--------------------------------------- # ML generic rules #--------------------------------------- %.cmi: %.mli $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -c $< %.cmo: %.ml %.cmi $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -c $< %.cmx: %.ml %.cmi $(OCAMLOPT) $(OCAMLOPTFLAGS) $(OCAMLINC) -c $< #----------------------------------- # DEPENDENCIES #----------------------------------- apron-dist-0.9.10/apron/newpolka/polka.idl0000640014525101416610000003066411251674650020324 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C,"#include \"pk.h\"") quote(C,"#include \"pkeq.h\"") quote(C,"#include \"ap_manager.h\"") quote(C,"#include \"apron_caml.h\"") quote(C,"typedef struct pk_internal_t* internal_ptr;") import "manager.idl"; typedef [abstract] struct pk_internal_t* internal_ptr; quote(MLMLI,"(** Convex Polyhedra and Linear Equalities abstract domains *)") quote(MLMLI," type loose type strict (** Two flavors for convex polyhedra: loose or strict. Loose polyhedra cannot have strict inequality constraints like [x>0]. They are algorithmically more efficient (less generators, simpler normalization). Convex polyhedra are defined by the conjunction of a set of linear constraints of the form [a_0*x_0 + ... + a_n*x_n + b >= 0] or [a_0*x_0 + ... + a_n*x_n + b > 0] where [a_0, ..., a_n, b, c] are constants and [x_0, ..., x_n] variables. *) type equalities (** Linear equalities. Linear equalities are conjunctions of linear equalities of the form [a_0*x_0 + ... + a_n*x_n + b = 0]. *) type 'a t (** Type of convex polyhedra/linear equalities, where ['a] is [loose], [strict] or [equalities]. Abstract values which are convex polyhedra have the type [(loose t) Apron.Abstract0.t] or [(loose t) Apron.Abstract1.t] or [(strict t) Apron.Abstract0.t] or [(strict t) Apron.Abstract1.t]. Abstract values which are conjunction of linear equalities have the type [(equalities t) Apron.Abstract0.t] or [(equalities t) Apron.Abstract1.t]. Managers allocated by NewPolka have the type ['a t Apron.Manager.t]. *) ") quote(MLI,"(** Create a NewPolka manager for loose convex polyhedra. *)") ap_manager_ptr pk_manager_alloc_loose() quote(call," _res = pk_manager_alloc(false); { ap_exc_t i; for (i=1; iinternal;"); quote(MLI,"(** Various options. See the C documentation *)\n") void pk_set_max_coeff_size(internal_ptr pk, unsigned int size); void pk_set_approximate_max_coeff_size(internal_ptr pk, unsigned int size); int pk_get_max_coeff_size(internal_ptr pk); int pk_get_approximate_max_coeff_size(internal_ptr pk); quote(MLI,"(** {2 Type conversions} *) val manager_is_polka : 'a Apron.Manager.t -> bool val manager_is_polka_loose : 'a Apron.Manager.t -> bool val manager_is_polka_strict : 'a Apron.Manager.t -> bool val manager_is_polka_equalities : 'a Apron.Manager.t -> bool (** Return [true] iff the argument manager is a polka manager *) val manager_of_polka : 'a t Apron.Manager.t -> 'b Apron.Manager.t val manager_of_polka_loose : loose t Apron.Manager.t -> 'a Apron.Manager.t val manager_of_polka_strict : strict t Apron.Manager.t -> 'a Apron.Manager.t val manager_of_polka_equalities : equalities t Apron.Manager.t -> 'a Apron.Manager.t (** Makes a polka manager generic *) val manager_to_polka : 'a Apron.Manager.t -> 'b t Apron.Manager.t val manager_to_polka_loose : 'a Apron.Manager.t -> loose t Apron.Manager.t val manager_to_polka_strict : 'a Apron.Manager.t -> strict t Apron.Manager.t val manager_to_polka_equalities : 'a Apron.Manager.t -> equalities t Apron.Manager.t (** Instanciate the type of a polka manager. Raises [Failure] if the argument manager is not a polka manager *) module Abstract0 : sig val is_polka : 'a Apron.Abstract0.t -> bool val is_polka_loose : 'a Apron.Abstract0.t -> bool val is_polka_strict : 'a Apron.Abstract0.t -> bool val is_polka_equalities : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument manager is a polka value *) val of_polka : 'a t Apron.Abstract0.t -> 'b Apron.Abstract0.t val of_polka_loose : loose t Apron.Abstract0.t -> 'a Apron.Abstract0.t val of_polka_strict : strict t Apron.Abstract0.t -> 'a Apron.Abstract0.t val of_polka_equalities : equalities t Apron.Abstract0.t -> 'a Apron.Abstract0.t (** Makes a polka value generic *) val to_polka : 'a Apron.Abstract0.t -> 'b t Apron.Abstract0.t val to_polka_loose : 'a Apron.Abstract0.t -> loose t Apron.Abstract0.t val to_polka_strict : 'a Apron.Abstract0.t -> strict t Apron.Abstract0.t val to_polka_equalities : 'a Apron.Abstract0.t -> equalities t Apron.Abstract0.t (** Instanciate the type of a polka value. Raises [Failure] if the argument manager is not a polka manager *) end module Abstract1 : sig val is_polka : 'a Apron.Abstract1.t -> bool val is_polka_loose : 'a Apron.Abstract1.t -> bool val is_polka_strict : 'a Apron.Abstract1.t -> bool val is_polka_equalities : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument manager is a polka value *) val of_polka : 'a t Apron.Abstract1.t -> 'b Apron.Abstract1.t val of_polka_loose : loose t Apron.Abstract1.t -> 'a Apron.Abstract1.t val of_polka_strict : strict t Apron.Abstract1.t -> 'a Apron.Abstract1.t val of_polka_equalities : equalities t Apron.Abstract1.t -> 'a Apron.Abstract1.t (** Makes a polka value generic *) val to_polka : 'a Apron.Abstract1.t -> 'b t Apron.Abstract1.t val to_polka_loose : 'a Apron.Abstract1.t -> loose t Apron.Abstract1.t val to_polka_strict : 'a Apron.Abstract1.t -> strict t Apron.Abstract1.t val to_polka_equalities : 'a Apron.Abstract1.t -> equalities t Apron.Abstract1.t (** Instanciate the type of a polka value. Raises [Failure] if the argument manager is not a polka manager *) end ") quote(ML," let manager_is_polka man = let str = Apron.Manager.get_library man in let str = try String.sub str 0 5 with Invalid_argument _ -> \"\" in (String.compare str \"polka\")==0 let manager_of_polka (man:'a t Apron.Manager.t) : 'b Apron.Manager.t = Obj.magic man let manager_to_polka (man:'a Apron.Manager.t) : 'b t Apron.Manager.t = if manager_is_polka man then Obj.magic man else failwith \"Polka.to_polka: the argument manager is not a Polka manager\" let manager_is_polka_loose man = let str = Apron.Manager.get_library man in (String.compare str \"polka, loose mode\")==0 let manager_of_polka_loose (man:loose t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_polka_loose (man:'a Apron.Manager.t) : loose t Apron.Manager.t = if manager_is_polka_loose man then Obj.magic man else failwith \"Polka.to_polka_loose: the argument manager is not a loose Polka manager\" let manager_is_polka_strict man = let str = Apron.Manager.get_library man in (String.compare str \"polka, strict mode\")==0 let manager_of_polka_strict (man:strict t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_polka_strict (man:'a Apron.Manager.t) : strict t Apron.Manager.t = if manager_is_polka_strict man then Obj.magic man else failwith \"Polka.to_polka_strict: the argument manager is not a strict Polka manager\" let manager_is_polka_equalities man = let str = Apron.Manager.get_library man in (String.compare str \"polka, equalities mode\")==0 let manager_of_polka_equalities (man:equalities t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_polka_equalities (man:'a Apron.Manager.t) : equalities t Apron.Manager.t = if manager_is_polka_equalities man then Obj.magic man else failwith \"Polka.to_polka_equalities: the argument manager is not an equalities Polka manager\" module Abstract0 = struct let is_polka abs = manager_is_polka (Apron.Abstract0.manager abs) let is_polka_loose abs = manager_is_polka_loose (Apron.Abstract0.manager abs) let is_polka_strict abs = manager_is_polka (Apron.Abstract0.manager abs) let is_polka_equalities abs = manager_is_polka_equalities (Apron.Abstract0.manager abs) let of_polka (abs: 'a t Apron.Abstract0.t) : 'b Apron.Abstract0.t = Obj.magic abs let of_polka_loose (abs: loose t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let of_polka_strict (abs: strict t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let of_polka_equalities (abs: equalities t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let to_polka (abs:'a Apron.Abstract0.t) : 'b t Apron.Abstract0.t = if is_polka abs then Obj.magic abs else failwith \"Polka.Abstract0.to_polka: the argument value is not a polka value\" let to_polka_loose (abs:'a Apron.Abstract0.t) : loose t Apron.Abstract0.t = if is_polka_loose abs then Obj.magic abs else failwith \"Polka.Abstract0.to_polka_loose: the argument value is not a loose polka value\" let to_polka_strict (abs:'a Apron.Abstract0.t) : strict t Apron.Abstract0.t = if is_polka_strict abs then Obj.magic abs else failwith \"Polka.Abstract0.to_polka_strict: the argument value is not a strict polka value\" let to_polka_equalities (abs:'a Apron.Abstract0.t) : equalities t Apron.Abstract0.t = if is_polka_equalities abs then Obj.magic abs else failwith \"Polka.Abstract0.to_polka_equalities: the argument value is not an equalities polka value\" end module Abstract1 = struct let is_polka abs = manager_is_polka (Apron.Abstract1.manager abs) let is_polka_loose abs = manager_is_polka_loose (Apron.Abstract1.manager abs) let is_polka_strict abs = manager_is_polka (Apron.Abstract1.manager abs) let is_polka_equalities abs = manager_is_polka_equalities (Apron.Abstract1.manager abs) let of_polka (abs: 'a t Apron.Abstract1.t) : 'b Apron.Abstract1.t = Obj.magic abs let of_polka_loose (abs: loose t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let of_polka_strict (abs: strict t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let of_polka_equalities (abs: equalities t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let to_polka (abs:'a Apron.Abstract1.t) : 'b t Apron.Abstract1.t = if is_polka abs then Obj.magic abs else failwith \"Polka.Abstract1.to_polka: the argument value is not a polka value\" let to_polka_loose (abs:'a Apron.Abstract1.t) : loose t Apron.Abstract1.t = if is_polka_loose abs then Obj.magic abs else failwith \"Polka.Abstract1.to_polka_loose: the argument value is not a loose polka value\" let to_polka_strict (abs:'a Apron.Abstract1.t) : strict t Apron.Abstract1.t = if is_polka_strict abs then Obj.magic abs else failwith \"Polka.Abstract1.to_polka_strict: the argument value is not a strict polka value\" let to_polka_equalities (abs:'a Apron.Abstract1.t) : equalities t Apron.Abstract1.t = if is_polka_equalities abs then Obj.magic abs else failwith \"Polka.Abstract1.to_polka_equalities: the argument value is not an equalities polka value\" end ") quote(MLI,"\n(** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. {3 Bytecode compilation} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma polkaMPQ.cma mlexample.ml]} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \\ bigarray.cma gmp.cma apron.cma polkaMPQ.cma ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma polkaMPQ.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa polkaMPQ.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa polkaMPQ.cmxa mlexample.ml \\ -cclib \"-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib \\ -lpolkaMPQ_caml_debug -lpolkaMPQ_debug \\ -lapron_caml_debug -lapron_debug \\ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP_PREFIX/lib -lgmp \\ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \\ -lbigarray\" ]} *)") apron-dist-0.9.10/apron/newpolka/pk_test.c0000640014525101416610000003272411247462105020333 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_test.c: tests on polyhedra */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "pk_config.h" #include "pk_vector.h" #include "pk_satmat.h" #include "pk_matrix.h" #include "pk.h" #include "pk_representation.h" #include "pk_user.h" #include "pk_constructor.h" #include "pk_extract.h" #include "pk_test.h" #include "itv_linearize.h" /* ====================================================================== */ /* Emptiness test */ /* ====================================================================== */ bool pk_is_bottom(ap_manager_t* man, pk_t* po) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_IS_BOTTOM); if (!po->C && !po->F){ man->result.flag_exact = man->result.flag_best = true; return true; } if (po->F){ man->result.flag_exact = man->result.flag_best = (po->intdim==0); return false; } else { if (pk->funopt->algorithm<0){ man->result.flag_exact = man->result.flag_best = false; return (po->C ? false : true); } else { poly_chernikova(man,po,NULL); if (pk->exn){ man->result.flag_exact = man->result.flag_best = false; pk->exn = AP_EXC_NONE; return false; } man->result.flag_exact = man->result.flag_best = po->intdim>0 && po->F ? false : true; return (po->F == NULL); } } } /* ====================================================================== */ /* Universe test */ /* ====================================================================== */ bool pk_is_top(ap_manager_t* man, pk_t* po) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_IS_TOP); man->result.flag_exact = man->result.flag_best = true; if (pk->funopt->algorithm>=0) poly_chernikova(man,po,NULL); if (!po->C && !po->F) return false; else if (po->C && po->F) return po->C->nbrows == pk->dec - 1; else { man->result.flag_exact = man->result.flag_best = false; return false; } } /* ====================================================================== */ /* Inclusion test */ /* ====================================================================== */ /* ---------------------------------------------------------------------- */ /* Do generators satisfies a constraint ? */ /* ---------------------------------------------------------------------- */ /* F is suppposed to be a valid matrix of ray (i.e., corresponding to a non empty polyhedron. The epsilon component of the constraint is not taken into account. The constraint is considered as strict only if the is_strict paramater telles so. This enables to test the satisfiability of a strict constraint in non-strict mode for the library. */ bool do_generators_sat_vector(pk_internal_t* pk, matrix_t* F, numint_t* tab, bool is_strict) { size_t i; if (numint_sgn(tab[0])==0){ /* 1. constraint is an equality */ for (i=0; inbrows; i++){ vector_product_strict(pk,pk->poly_prod, F->p[i], tab,F->nbcolumns); if (numint_sgn(pk->poly_prod)) return false; } return true; } else { /* 2. constraint is an inequality */ int sign; /* sign of the scalar product */ for (i=0; inbrows; i++){ vector_product_strict(pk,pk->poly_prod, F->p[i], tab,F->nbcolumns); sign = numint_sgn(pk->poly_prod); if (sign<0){ return false; } else { if (numint_sgn(F->p[i][0])==0){ /* line */ if (sign!=0) return false; } else { /* ray or vertex */ if (is_strict && sign==0 && (pk->strict ? numint_sgn(F->p[i][polka_eps])>0 : true)) return false; } } } return true; } } /* This test requires frames of pa and constraints of pb. The result is true if and only if all frames of pa verify the constraints of pb. We do not require minimality. */ bool pk_is_leq(ap_manager_t* man, pk_t* pa, pk_t* pb) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_IS_LEQ); assert(poly_check(pk,pa)); assert(poly_check(pk,pb)); man->result.flag_exact = man->result.flag_best = false; if (pk->funopt->algorithm>0) poly_chernikova(man,pa,"of the first argument"); else poly_obtain_F(man,pa,"of the first argument"); if (pk->exn){ pk->exn = AP_EXC_NONE; return false; } if (!pa->F){ /* pa is empty */ man->result.flag_exact = man->result.flag_best = true; return true; } if (pk->funopt->algorithm>0) poly_chernikova(man,pb,"of the second argument"); else poly_obtain_C(man,pb,"of the second argument"); if (pk->exn){ pk->exn = AP_EXC_NONE; return false; } if (!pb->C){/* pb is empty */ man->result.flag_exact = man->result.flag_best = (pa->intdim==0); return false; } man->result.flag_exact = man->result.flag_best = pa->intdim==0; /* if both are mininmal, check the dimensions */ if (pa->C && pa->F && pb->C && pb->F && (pa->nbeq < pb->nbeq || pa->nbline > pb->nbline)) { man->result.flag_exact = man->result.flag_best = true; return false; } else { man->result.flag_exact = man->result.flag_best = (pa->intdim==0); /* does the frames of pa satisfy constraints of pb ? */ size_t i; for (i=0; iC->nbrows; i++){ bool sat = do_generators_sat_vector(pk, pa->F, pb->C->p[i], pk->strict && numint_sgn(pb->C->p[i][polka_eps])<0); if (sat==false) return false; } return true; } } /* ====================================================================== */ /* Equality test */ /* ====================================================================== */ bool pk_is_eq(ap_manager_t* man, pk_t* pa, pk_t* pb) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_IS_EQ); man->result.flag_exact = man->result.flag_best = (pa->intdim==0); if (pa->C && pa->F && pb->C && pb->F && (pa->nbeq != pb->nbeq || pa->nbline != pb->nbline) ){ return false; } if (pk->funopt->algorithm>0){ poly_chernikova3(man,pa,"of the first argument"); if (pk->exn){ pk->exn = AP_EXC_NONE; return false; } poly_chernikova3(man,pb,"of the first argument"); if (pk->exn){ pk->exn = AP_EXC_NONE; return false; } } man->result.flag_exact = man->result.flag_best = true; if (pk_is_canonical(man,pa) && pk_is_canonical(man,pb)){ bool res = (!pa->C && !pb->C) || (pa->C && pb->C && pa->C->nbrows == pb->C->nbrows && pa->F->nbrows == pb->F->nbrows && (pa->C->nbrows <= pa->F->nbrows ? matrix_equal(pa->C,pb->C) : matrix_equal(pa->F,pb->F))); assert(res == (pk_is_leq(man,pa,pb) && pk_is_leq(man,pb,pa))); return res; } else { bool res = pk_is_leq(man,pa,pb) && pk_is_leq(man,pb,pa); return res; } } /* ====================================================================== */ /* Satisfiability of a linear constraint */ /* ====================================================================== */ bool pk_sat_lincons(ap_manager_t* man, pk_t* po, ap_lincons0_t* lincons0) { bool exact; bool sat; size_t dim; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_SAT_LINCONS); if (pk->funopt->algorithm>0) poly_chernikova(man,po,NULL); else poly_obtain_F(man,po,NULL); if (pk->exn){ pk->exn = AP_EXC_NONE; return false; } if (!po->F){ /* po is empty */ man->result.flag_exact = man->result.flag_best = true; return true; } switch (lincons0->constyp){ case AP_CONS_EQ: case AP_CONS_SUPEQ: case AP_CONS_SUP: break; default: man->result.flag_exact = man->result.flag_best = false; return false; } dim = po->intdim + po->realdim; if (!ap_linexpr0_is_quasilinear(lincons0->linexpr0)){ itv_t* env = matrix_to_box(pk,po->F); exact = itv_lincons_set_ap_lincons0(pk->itv, &pk->poly_itv_lincons, lincons0); exact = itv_quasilinearize_lincons(pk->itv, &pk->poly_itv_lincons, env, false) && exact; itv_array_free(env,dim); } else { exact = itv_lincons_set_ap_lincons0(pk->itv, &pk->poly_itv_lincons, lincons0); } sat = vector_set_itv_lincons_sat(pk, pk->poly_numintp, &pk->poly_itv_lincons, po->intdim, po->realdim, true); if (sat){ sat = do_generators_sat_vector(pk,po->F, pk->poly_numintp, lincons0->constyp==AP_CONS_SUP); } man->result.flag_exact = man->result.flag_best = sat ? true : ( ( (pk->funopt->flag_exact_wanted || pk->funopt->flag_best_wanted) && exact && ap_linexpr0_is_real(lincons0->linexpr0,po->intdim) ) ? true : false ); return sat; } bool pk_sat_tcons(ap_manager_t* man, pk_t* po, ap_tcons0_t* cons) { size_t dim; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_SAT_LINCONS); if (pk->funopt->algorithm>0) poly_chernikova(man,po,NULL); else poly_obtain_F(man,po,NULL); if (pk->exn){ pk->exn = AP_EXC_NONE; return false; } if (!po->F){ /* po is empty */ man->result.flag_exact = man->result.flag_best = true; return true; } switch (cons->constyp){ case AP_CONS_EQ: case AP_CONS_SUPEQ: case AP_CONS_SUP: break; default: man->result.flag_exact = man->result.flag_best = false; return false; } dim = po->intdim + po->realdim; itv_t* env = matrix_to_box(pk,po->F); itv_intlinearize_ap_tcons0(pk->itv,&pk->poly_itv_lincons, cons,env,po->intdim); itv_quasilinearize_lincons(pk->itv,&pk->poly_itv_lincons,env,false); itv_array_free(env,po->intdim+po->realdim); bool sat = vector_set_itv_lincons_sat(pk, pk->poly_numintp, &pk->poly_itv_lincons, po->intdim, po->realdim, true); if (sat){ sat = do_generators_sat_vector(pk,po->F, pk->poly_numintp, cons->constyp==AP_CONS_SUP); } man->result.flag_exact = man->result.flag_best = sat; return sat; } /* ====================================================================== */ /* Inclusion of a dimension in an interval */ /* ====================================================================== */ /* ---------------------------------------------------------------------- */ /* Do generators satisfies a bound for one dimension ? */ /* ---------------------------------------------------------------------- */ /* F is suppposed to be a valid matrix of ray (i.e., corresponding to a non empty polyhedron. Assume coeff is not an infinite number. tests if: - dim <= bound if sgn>0 - dim = bound if sgn=0 - dim >= -bound if sgn<0 */ bool do_generators_sat_bound(pk_internal_t* pk, matrix_t* F, ap_dim_t dim, numrat_t bound, int sgn) { size_t i,index; int sgn2; index = pk->dec + dim; for (i=0; inbrows; i++){ sgn2 = numint_sgn(F->p[i][index]); if (numint_sgn(F->p[i][0])==0){ /* line */ if (sgn2) return false; } else if (numint_sgn(F->p[i][polka_cst])==0){ /* ray */ if ( (sgn>=0 && sgn2>0) || (sgn<=0 && sgn2<0) ) return false; } else { /* vertex */ numrat_set_numint2(pk->poly_numrat, F->p[i][index], F->p[i][polka_cst]); if (sgn==0){ if (!numrat_equal(pk->poly_numrat,bound)) return false; } else { if (sgn<0) numrat_neg(pk->poly_numrat,pk->poly_numrat); sgn2 = numrat_cmp(pk->poly_numrat,bound); if (sgn2>0) return false; } } } return true; } bool pk_sat_interval(ap_manager_t* man, pk_t* po, ap_dim_t dim, ap_interval_t* interval) { bool sat; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_SAT_INTERVAL); if (pk->funopt->algorithm>0) poly_chernikova(man,po,NULL); else poly_obtain_F(man,po,NULL); if (pk->exn){ pk->exn = AP_EXC_NONE; return false; } if (!po->F){ /* po is empty */ man->result.flag_exact = man->result.flag_best = true; return true; } itv_set_ap_interval(pk->itv, pk->poly_itv, interval); if (itv_is_point(pk->itv, pk->poly_itv)){ /* interval is a point */ sat = do_generators_sat_bound(pk,po->F,dim,pk->poly_itv->sup,0); } else { sat = true; /* inferior bound */ if (!bound_infty(pk->poly_itv->inf)){ sat = do_generators_sat_bound(pk,po->F,dim,pk->poly_itv->inf,-1); if (!sat) goto poly_sat_interval_exit0; } /* superior bound */ if (!bound_infty(pk->poly_itv->sup)){ sat = do_generators_sat_bound(pk,po->F,dim,pk->poly_itv->sup,1); } } poly_sat_interval_exit0: man->result.flag_exact = man->result.flag_best = sat ? true : (dim < po->intdim ? false : true); return sat; } /* ====================================================================== */ /* Is a dimension unconstrained ? */ /* ====================================================================== */ bool pk_is_dimension_unconstrained(ap_manager_t* man, pk_t* po, ap_dim_t dim) { size_t i,j; bool res; matrix_t* F; matrix_t* C; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_SAT_INTERVAL); poly_chernikova3(man,po,NULL); if (pk->exn){ pk->exn = AP_EXC_NONE; return false; } if (!po->F){ /* po is empty */ man->result.flag_exact = man->result.flag_best = true; return false; } /* We test if there exists the line of direction dim */ F = po->F; res = false; for (i=0; inbline; i++){ if (numint_sgn(F->p[i][pk->dec+dim])){ res = true; for(j=pk->dec; jnbcolumns; j++){ if (j!=pk->dec+dim && numint_sgn(F->p[i][j])){ res = false; break; } } break; } } man->result.flag_exact = man->result.flag_best = true; return res; } apron-dist-0.9.10/apron/newpolka/pk_assign.c0000640014525101416610000006216011122234003020617 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_assign.c: Assignements and Substitutions */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "pk_config.h" #include "pk_vector.h" #include "pk_satmat.h" #include "pk_matrix.h" #include "pk.h" #include "pk_representation.h" #include "pk_user.h" #include "pk_constructor.h" #include "pk_extract.h" #include "pk_resize.h" #include "pk_meetjoin.h" #include "pk_assign.h" #include "ap_generic.h" #include "itv_linearize.h" /* ********************************************************************** */ /* I. Matrix operations */ /* ********************************************************************** */ /* ====================================================================== */ /* Matrix transformations: a variable and an expression */ /* ====================================================================== */ /* ---------------------------------------------------------------------- */ /* Assignement of an expression to a variable */ /* ---------------------------------------------------------------------- */ /* Hypothesis: - either nmat is a matrix allocated with _matrix_alloc_int, and his coefficients are not initialized, - or nmat==mat */ static matrix_t* matrix_assign_variable(pk_internal_t* pk, bool destructive, matrix_t* mat, ap_dim_t dim, numint_t* tab) { size_t i,j,var; bool den; matrix_t* nmat; var = pk->dec + dim; den = numint_cmp_int(tab[0],1)>0; nmat = destructive ? mat : _matrix_alloc_int(mat->nbrows,mat->nbcolumns,false); nmat->_sorted = false; for (i=0; inbrows; i++){ /* product for var column */ vector_product(pk,pk->matrix_prod, mat->p[i], tab,mat->nbcolumns); /* columns != var */ if (!destructive){ /* Functional */ numint_init_set(nmat->p[i][0],mat->p[i][0]); for (j=1; jnbcolumns; j++){ if (j!=var){ numint_init_set(nmat->p[i][j],mat->p[i][j]); if (den){ numint_mul(nmat->p[i][j],mat->p[i][j],tab[0]); } } } } else { /* Side-effect */ for (j=0; jnbcolumns; j++){ if (j!=var){ if (den) numint_mul(nmat->p[i][j],mat->p[i][j],tab[0]); else numint_set(nmat->p[i][j],mat->p[i][j]); } } } /* var column */ if (!destructive) numint_init_set(nmat->p[i][var],pk->matrix_prod); else numint_set(nmat->p[i][var],pk->matrix_prod); matrix_normalize_row(pk,nmat,i); } return nmat; } /* ---------------------------------------------------------------------- */ /* Substitution of a variable by an expression */ /* ---------------------------------------------------------------------- */ /* Hypothesis: - either nmat is a matrix allocated with _matrix_alloc_int, and his coefficients are not initialized, - or nmat==mat */ static matrix_t* matrix_substitute_variable(pk_internal_t* pk, bool destructive, matrix_t* mat, ap_dim_t dim, numint_t* tab) { size_t i,j,var; bool den; matrix_t* nmat; var = pk->dec + dim; den = numint_cmp_int(tab[0],1)>0; nmat = destructive ? mat : _matrix_alloc_int(mat->nbrows,mat->nbcolumns,false); nmat->_sorted = false; for (i=0; inbrows; i++) { if (numint_sgn(mat->p[i][var])) { /* The substitution must be done */ if (!destructive){ /* Functional */ numint_init_set(nmat->p[i][0],mat->p[i][0]); /* columns != var */ for (j=1; jnbcolumns; j++) { if (j!=var){ if (den){ numint_init(nmat->p[i][j]); numint_mul(nmat->p[i][j],mat->p[i][j],tab[0]); } else { numint_init_set(nmat->p[i][j],mat->p[i][j]); } numint_mul(pk->matrix_prod,mat->p[i][var],tab[j]); numint_add(nmat->p[i][j],nmat->p[i][j],pk->matrix_prod); } } /* var column */ numint_init(nmat->p[i][var]); numint_mul(nmat->p[i][var],mat->p[i][var],tab[var]); } else { /* Side-effect */ /* columns != var */ for (j=1; jnbcolumns; j++) { if (j!=var){ if (den){ numint_mul(nmat->p[i][j],nmat->p[i][j],tab[0]); } numint_mul(pk->matrix_prod,mat->p[i][var],tab[j]); numint_add(nmat->p[i][j],nmat->p[i][j],pk->matrix_prod); } } /* var column */ numint_mul(nmat->p[i][var],nmat->p[i][var],tab[var]); } matrix_normalize_row(pk,nmat,i); } else { /* No substitution */ if (!destructive){ for (j=0; jnbcolumns; j++) { numint_init_set(nmat->p[i][j],mat->p[i][j]); } } } } return nmat; } /* ====================================================================== */ /* Matrix transformations: several variables and expressions */ /* ====================================================================== */ /* The list of pair (variable,expr) is given by an array of type equation_t. IMPRTANT: the array tdim should be sorted in ascending order. */ /* insertion sort for sorting the array tdim */ static void pk_asssub_isort(ap_dim_t* tdim, numint_t** tvec, size_t size) { size_t i,j; for (i=1; i0; j--){ if (tdim[j-1]>dim){ tdim[j] = tdim[j-1]; tvec[j] = tvec[j-1]; } else break; } tdim[j]=dim; tvec[j]=vec; } } /* ---------------------------------------------------------------------- */ /* Assignement by an array of equations */ /* ---------------------------------------------------------------------- */ static matrix_t* matrix_assign_variables(pk_internal_t* pk, matrix_t* mat, ap_dim_t* tdim, numint_t** tvec, size_t size) { size_t i,j,eindex; matrix_t* nmat = _matrix_alloc_int(mat->nbrows, mat->nbcolumns,false); numint_t den; /* Computing common denominator */ numint_init_set(den,tvec[0][0]); for (i=1; inbrows; i++){ numint_init_set(nmat->p[i][0],mat->p[i][0]); } /* Other columns */ eindex = 0; for (j=1; jnbcolumns; j++){ if (eindex < size && pk->dec + tdim[eindex] == j){ /* We are on an assigned column */ for (i=0; inbrows; i++){ /* For each row */ vector_product(pk,pk->matrix_prod, mat->p[i], tvec[eindex],mat->nbcolumns); numint_mul(pk->matrix_prod,pk->matrix_prod,vden[eindex]); /* Put the result */ numint_init_set(nmat->p[i][j],pk->matrix_prod); } eindex++; } else { /* We are on a normal column */ for (i=0; inbrows; i++){ /* For each row */ numint_init(nmat->p[i][j]); numint_mul(nmat->p[i][j],mat->p[i][j],den); } } } vector_free(vden,size); } else { /* Special case: all denominators are 1 */ /* Column 0: copy */ for (i=0; inbrows; i++){ numint_init_set(nmat->p[i][0],mat->p[i][0]); } /* Other columns */ eindex = 0; for (j=1; jnbcolumns; j++){ if (eindex < size && pk->dec + tdim[eindex] == j){ /* We are on a assigned column */ for (i=0; inbrows; i++){ /* For each row */ vector_product(pk,pk->matrix_prod, mat->p[i], tvec[eindex],mat->nbcolumns); numint_init_set(nmat->p[i][j],pk->matrix_prod); } eindex++; } else { /* We are on a normal column */ for (i=0; inbrows; i++){ /* For each row */ numint_init_set(nmat->p[i][j],mat->p[i][j]); } } } } numint_clear(den); for (i=0; inbrows; i++){ matrix_normalize_row(pk,nmat,i); } return nmat; } /* ---------------------------------------------------------------------- */ /* Substitution by an array of equations */ /* ---------------------------------------------------------------------- */ static matrix_t* matrix_substitute_variables(pk_internal_t* pk, matrix_t* mat, ap_dim_t* tdim, numint_t** tvec, size_t size) { size_t i,j,eindex; matrix_t* nmat = matrix_alloc(mat->nbrows, mat->nbcolumns,false); numint_t den; /* Computing common denominator */ numint_init_set(den,tvec[0][0]); for (i=1; inbrows; i++) { /* Column 0 */ numint_set(nmat->p[i][0],mat->p[i][0]); /* Other columns */ /* First, copy the row and sets to zero substituted variables */ eindex = 0; for (j=1; jnbcolumns; j++){ if (eindex < size && pk->dec + tdim[eindex] == j) eindex++; else numint_mul(nmat->p[i][j],mat->p[i][j],den); } /* Second, add things coming from substitution */ for (j=1; jnbcolumns; j++){ for (eindex=0; eindexp[i][pk->dec + tdim[eindex]])) { numint_mul(pk->matrix_prod, mat->p[i][pk->dec + tdim[eindex]], tvec[eindex][j]); numint_mul(pk->matrix_prod,pk->matrix_prod,vden[eindex]); numint_add(nmat->p[i][j],nmat->p[i][j],pk->matrix_prod); } } } } vector_free(vden,size); } else { /* Special case: all denominators are 1 */ /* For each row */ for (i=0; inbrows; i++) { /* Column 0 */ numint_set(nmat->p[i][0],mat->p[i][0]); /* Other columns */ /* First, copy the row and sets to zero substituted variables */ eindex = 0; for (j=1; jnbcolumns; j++){ if (eindex < size && pk->dec + tdim[eindex] == j) eindex++; else numint_set(nmat->p[i][j],mat->p[i][j]); } /* Second, add things coming from substitution */ for (j=1; jnbcolumns; j++){ for (eindex=0; eindexp[i][pk->dec + tdim[eindex]])) { numint_mul(pk->matrix_prod, mat->p[i][pk->dec + tdim[eindex]], tvec[eindex][j]); numint_add(nmat->p[i][j],nmat->p[i][j],pk->matrix_prod); } } } } } numint_clear(den); for (i=0; inbrows; i++){ matrix_normalize_row(pk,nmat,i); } return nmat; } /* ********************************************************************** */ /* II. Auxiliary functions */ /* ********************************************************************** */ /* ====================================================================== */ /* Inversion of a (deterministic) linear expression */ /* ====================================================================== */ static void vector_invert_expr(pk_internal_t* pk, numint_t* ntab, ap_dim_t dim, numint_t* tab, size_t size) { size_t i; size_t var = pk->dec+dim; int sgn = numint_sgn(tab[var]); assert(sgn!=0); if (sgn>0){ numint_set(ntab[0], tab[var]); numint_set(ntab[var], tab[0]); for (i=1; iinternal; po = destructive ? pa : poly_alloc(pa->intdim,pa->realdim); if (!assign) poly_dual(pa); /* Obtain the needed matrix */ poly_obtain_F_dual(man,pa,"of the argument",assign); if (pk->exn){ pk->exn = AP_EXC_NONE; man->result.flag_best = man->result.flag_exact = false; poly_set_top(pk,po); goto _poly_asssub_linexpr_array_det_exit; } /* Return empty if empty */ if (!pa->C && !pa->F){ man->result.flag_best = man->result.flag_exact = true; poly_set_bottom(pk,po); return po; } /* Convert linear expressions */ nbcols = pk->dec + pa->intdim + pa->realdim; tvec = (numint_t**)malloc(size*sizeof(numint_t*)); for (i=0; iitv, &pk->poly_itv_linexpr, texpr[i]); vector_set_itv_linexpr(pk, tvec[i], &pk->poly_itv_linexpr, pa->intdim+pa->realdim,1); } /* Copy tdim because of sorting */ tdim2 = (ap_dim_t*)malloc(size*sizeof(ap_dim_t)); memcpy(tdim2,tdim,size*sizeof(ap_dim_t)); pk_asssub_isort(tdim2,tvec,size); /* Perform the operation */ mat = assign ? matrix_assign_variables(pk, pa->F, tdim2, tvec, size) : matrix_substitute_variables(pk, pa->F, tdim2, tvec, size); /* Free allocated stuff */ for (i=0; iF = mat; po->status = 0; _poly_asssub_linexpr_array_det_exit: if (!assign){ poly_dual(pa); if (!destructive) poly_dual(po); } assert(poly_check(pk,po)); return po; } /* ====================================================================== */ /* Assignement/Substitution by an array of linear expressions */ /* ====================================================================== */ static pk_t* poly_asssub_linexpr_array(bool assign, bool lazy, ap_manager_t* man, bool destructive, pk_t* pa, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, pk_t* pb) { pk_t* po; pk_internal_t* pk = (pk_internal_t*)man->internal; /* Minimize the argument if option say so */ if (!lazy){ poly_chernikova(man,pa,"of the argument"); if (pk->exn){ pk->exn = AP_EXC_NONE; man->result.flag_best = man->result.flag_exact = false; if (destructive){ poly_set_top(pk,pa); return pa; } else { return pk_top(man,pa->intdim,pa->realdim); } } } /* Return empty if empty */ if (!pa->C && !pa->F){ man->result.flag_best = man->result.flag_exact = true; return destructive ? pa : pk_bottom(man,pa->intdim,pa->realdim); } /* Choose the right technique */ if (ap_linexpr0_array_is_linear(texpr,size)){ po = poly_asssub_linexpr_array_det(assign,man,destructive,pa,tdim,texpr,size); if (pb){ poly_meet(true,lazy,man,po,po,pb); } } else { po = ap_generic_asssub_linexpr_array(assign,man,destructive,pa,tdim,texpr,size,pb); } /* Minimize the result if option say so */ if (!lazy){ poly_chernikova(man,po,"of the result"); if (pk->exn){ pk->exn = AP_EXC_NONE; man->result.flag_best = man->result.flag_exact = false; if (pb) poly_set(po,pb); else poly_set_top(pk,po); return po; } } /* Is the result exact or best ? */ if (pk->funopt->flag_best_wanted || pk->funopt->flag_exact_wanted){ size_t i; man->result.flag_best = true; for (i=0;iintdim || !ap_linexpr0_is_real(texpr[i], pa->intdim)){ man->result.flag_best = false; break; } } man->result.flag_exact = man->result.flag_best; } else { man->result.flag_best = man->result.flag_exact = (pa->intdim==0); } return po; } /* ====================================================================== */ /* Assignement/Substitution by an array of tree expressions */ /* ====================================================================== */ static pk_t* poly_asssub_texpr_array(bool assign, bool lazy, ap_manager_t* man, bool destructive, pk_t* pa, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, pk_t* pb) { pk_t* po; pk_internal_t* pk = (pk_internal_t*)man->internal; /* Minimize the argument if option say so */ if (!lazy){ poly_chernikova(man,pa,"of the argument"); if (pk->exn){ pk->exn = AP_EXC_NONE; man->result.flag_best = man->result.flag_exact = false; if (destructive){ poly_set_top(pk,pa); return pa; } else { return pk_top(man,pa->intdim,pa->realdim); } } } /* Return empty if empty */ if (!pa->C && !pa->F){ man->result.flag_best = man->result.flag_exact = true; return destructive ? pa : pk_bottom(man,pa->intdim,pa->realdim); } /* Choose the right technique */ if (ap_texpr0_array_is_scalar(texpr,size) && ap_texpr0_array_is_interval_linear(texpr,size)){ ap_abstract0_t abs; abs.value = pa; abs.man = man; if (size==1){ ap_linexpr0_t* linexpr0 = ap_intlinearize_texpr0(man,&abs,texpr[0],NULL, AP_SCALAR_MPQ,false); po = poly_asssub_linexpr_det(assign,man,destructive, pa, tdim[0], linexpr0); ap_linexpr0_free(linexpr0); } else { ap_linexpr0_t** tlinexpr = ap_intlinearize_texpr0_array(man,&abs,texpr,size,NULL, AP_SCALAR_MPQ,false); po = poly_asssub_linexpr_array_det(assign,man,destructive, pa,tdim,tlinexpr,size); ap_linexpr0_array_free(tlinexpr,size); } if (pb){ poly_meet(true,lazy,man,po,po,pb); } } else { po = ap_generic_asssub_texpr_array(assign,man,destructive,pa,tdim,texpr,size,pb); } /* Minimize the result if option say so */ if (!lazy){ poly_chernikova(man,po,"of the result"); if (pk->exn){ pk->exn = AP_EXC_NONE; man->result.flag_best = man->result.flag_exact = false; if (pb) poly_set(po,pb); else poly_set_top(pk,po); return po; } } /* Is the result exact or best ? */ if (pk->funopt->flag_best_wanted || pk->funopt->flag_exact_wanted){ man->result.flag_best = ap_texpr0_array_is_interval_linear(texpr,size); man->result.flag_exact = man->result.flag_best; } else { man->result.flag_best = man->result.flag_exact = false; } return po; } /* ********************************************************************** */ /* IV. Assignement/Substitution of a single dimension */ /* ********************************************************************** */ /* ====================================================================== */ /* Assignement/Substitution by a *deterministic* linear expression */ /* ====================================================================== */ pk_t* poly_asssub_linexpr_det(bool assign, ap_manager_t* man, bool destructive, pk_t* pa, ap_dim_t dim, ap_linexpr0_t* linexpr0) { int sgn; pk_t* po; pk_internal_t* pk = (pk_internal_t*)man->internal; po = destructive ? pa : poly_alloc(pa->intdim,pa->realdim); if (!assign) poly_dual(pa); /* Convert linear expression */ itv_linexpr_set_ap_linexpr0(pk->itv, &pk->poly_itv_linexpr, linexpr0); vector_set_itv_linexpr(pk, pk->poly_numintp, &pk->poly_itv_linexpr, pa->intdim+pa->realdim,1); sgn = numint_sgn(pk->poly_numintp[pk->dec + dim]); if (!sgn){ /* Expression is not invertible */ /* Get the needed matrix */ poly_obtain_F_dual(man,pa,"of the argument",assign); if (pk->exn){ pk->exn = AP_EXC_NONE; poly_set_top(pk,po); man->result.flag_best = man->result.flag_exact = false; goto _poly_asssub_linear_linexpr_exit; } if (destructive){ /* If side-effect, free everything but generators */ if (po->satC){ satmat_free(po->satC); po->satC = NULL; } if (po->satF){ satmat_free(po->satF); po->satF = NULL; } if (po->C){ matrix_free(po->C); po->C = NULL; } } } if (pa->F){ /* Perform assignements on generators */ po->F = assign ? matrix_assign_variable(pk, destructive, pa->F, dim, pk->poly_numintp) : matrix_substitute_variable(pk, destructive, pa->F, dim, pk->poly_numintp); } if (sgn && pa->C){ /* Expression is invertible and we have constraints */ /* Invert the expression in pk->poly_numintp2 */ vector_invert_expr(pk, pk->poly_numintp2, dim, pk->poly_numintp, pa->C->nbcolumns); /* Perform susbtitution on constraints */ po->C = assign ? matrix_substitute_variable(pk,destructive,pa->C, dim, pk->poly_numintp2) : matrix_assign_variable(pk,destructive,pa->C, dim, pk->poly_numintp2); } if (po->C && po->F){ po->nbeq = pa->nbeq; po->nbline = pa->nbline; po->satC = (destructive || pa->satC==NULL) ? pa->satC : satmat_copy(pa->satC); po->satF = (destructive || pa->satF==NULL) ? pa->satF : satmat_copy(pa->satF); } else { po->nbeq = 0; po->nbline = 0; } po->status = 0; _poly_asssub_linear_linexpr_exit: if (!assign){ poly_dual(pa); if (!destructive) poly_dual(po); } assert(poly_check(pk,po)); return po; } /* ====================================================================== */ /* Assignement/Substitution by a linear expression */ /* ====================================================================== */ static pk_t* poly_asssub_linexpr(bool assign, bool lazy, ap_manager_t* man, bool destructive, pk_t* pa, ap_dim_t dim, ap_linexpr0_t* linexpr, pk_t* pb) { pk_t* po; pk_internal_t* pk = (pk_internal_t*)man->internal; pk_internal_realloc_lazy(pk,pa->intdim+pa->realdim+1); /* Minimize the argument if option say so */ if (!lazy){ poly_chernikova(man,pa,"of the argument"); if (pk->exn){ pk->exn = AP_EXC_NONE; man->result.flag_best = man->result.flag_exact = false; if (destructive){ poly_set_top(pk,pa); return pa; } else { return pk_top(man,pa->intdim,pa->realdim); } } } /* Return empty if empty */ if (!pa->C && !pa->F){ man->result.flag_best = man->result.flag_exact = true; return destructive ? pa : pk_bottom(man,pa->intdim,pa->realdim); } /* Choose the right technique */ if (ap_linexpr0_is_linear(linexpr)){ po = poly_asssub_linexpr_det(assign,man,destructive,pa,dim,linexpr); if (pb){ poly_meet(true,lazy,man,po,po,pb); } } else { po = ap_generic_asssub_linexpr_array(assign,man,destructive,pa,&dim,&linexpr,1,pb); } /* Minimize the result if option say so */ if (!lazy){ poly_chernikova(man,po,"of the result"); if (pk->exn){ pk->exn = AP_EXC_NONE; man->result.flag_best = man->result.flag_exact = false; if (pb) poly_set(po,pb); else poly_set_top(pk,po); return po; } } /* Is the result exact or best ? */ if (pk->funopt->flag_best_wanted || pk->funopt->flag_exact_wanted){ man->result.flag_best = man->result.flag_exact = (dim < pa->intdim || !ap_linexpr0_is_real(linexpr, pa->intdim)) ? false : true; } else { man->result.flag_best = man->result.flag_exact = (pa->intdim==0); } return po; } /* ********************************************************************** */ /* V. Assignement/Substitution: interface */ /* ********************************************************************** */ pk_t* pk_assign_linexpr_array(ap_manager_t* man, bool destructive, pk_t* pa, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, pk_t* pb) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_ASSIGN_LINEXPR_ARRAY); pk_t* po; po = size==1 ? poly_asssub_linexpr(true, pk->funopt->algorithm<=0, man,destructive,pa,tdim[0],texpr[0],pb) : poly_asssub_linexpr_array(true, pk->funopt->algorithm<=0, man,destructive,pa,tdim,texpr,size,pb); assert(poly_check(pk,po)); return po; } pk_t* pk_substitute_linexpr_array(ap_manager_t* man, bool destructive, pk_t* pa, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, pk_t* pb) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY); pk_t* po; po = size==1 ? poly_asssub_linexpr(false, pk->funopt->algorithm<=0, man,destructive,pa,tdim[0],texpr[0],pb) : poly_asssub_linexpr_array(false, pk->funopt->algorithm<=0, man,destructive,pa,tdim,texpr,size,pb); assert(poly_check(pk,po)); return po; } pk_t* pk_assign_texpr_array(ap_manager_t* man, bool destructive, pk_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, pk_t* dest) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_ASSIGN_TEXPR_ARRAY); pk_t* po; po = poly_asssub_texpr_array(true, pk->funopt->algorithm<=0, man,destructive,a,tdim,texpr,size,dest); assert(poly_check(pk,po)); return po; } pk_t* pk_substitute_texpr_array(ap_manager_t* man, bool destructive, pk_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, pk_t* dest) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_SUBSTITUTE_TEXPR_ARRAY); pk_t* po; po = poly_asssub_texpr_array(false, pk->funopt->algorithm<=0, man,destructive,a,tdim,texpr,size,dest); assert(poly_check(pk,po)); return po; } apron-dist-0.9.10/apron/newpolka/pk_bit.c0000640014525101416610000000756510571032754020141 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_bit.c: operations on bitstrings */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include "pk_bit.h" /* ********************************************************************** */ /* I. Bitindices */ /* ********************************************************************** */ void bitindex_fprint(FILE* stream, bitindex_t* bi) { int k; bitstring_t m = bi->bit; assert (m!=0); k=(-1); do { k++; m >>= 1; } while (m!=0); fprintf(stream,"index=%lu, word=%lu, bit=%d\n", (unsigned long)bi->index,(unsigned long)bi->word,k); } void bitindex_print(bitindex_t* bi) { bitindex_fprint(stdout,bi); } /* \verb-bitindex_init()- takes as parameter a \emph{flat} index of a bit and returns the corresponding structured index. \verb-bitindex_inc()- and \verb-bitindex_dec()- allow to increment and decrement an index. \verb-bitindex_size(n)- returns the size of an array of \verb-bitstring_t- containing \verb-n- bits. */ bitindex_t bitindex_init(const size_t col) { bitindex_t res; res.index = col; res.word = col / bitstring_size; res.bit = bitstring_msb >> (col % bitstring_size); return res; } void bitindex_inc(bitindex_t* const bi){ bi->index++; bi->bit >>= 1; if (bi->bit==0){ bi->bit = bitstring_msb; bi->word++; } } void bitindex_dec(bitindex_t* const bi){ bi->index--; if (bi->bit != bitstring_msb){ bi->bit <<= 1; } else { bi->bit = 1; bi->word--; } } size_t bitindex_size(const size_t n){ size_t size = n / bitstring_size; if (n % bitstring_size) size++; return size; } /* ********************************************************************** */ /* II. Bitstrings */ /* ********************************************************************** */ /* \verb-bitstring_alloc- allocates a new bitstring and \verb-bitstring_free()- frees the bitstring. \verb-bitstring_clear- sets to \verb-0- the bits, \verb-bitstring_cmp- compares two bitfields; be careful, it takes also in account unused bits of the last word. Last, \verb-bitstring_print()- writes the bits of a bitstring. */ bitstring_t* bitstring_alloc(size_t n){ return (bitstring_t*)malloc(n*sizeof(bitstring_t)); } bitstring_t* bitstring_realloc(bitstring_t* b, size_t n){ return (bitstring_t*)realloc(b, n*sizeof(bitstring_t)); } void bitstring_free(bitstring_t* b){ free(b); } void bitstring_clear(bitstring_t* b, size_t size){ size_t i; for (i=0; i>= 1; k++; } } } void bitstring_print(bitstring_t* b, size_t size) { bitstring_fprint(stdout,b,size); } int bitstring_cmp(bitstring_t* const r1, bitstring_t* const r2, size_t size){ size_t i; int res=0; for (i=0; i r2[i]){ res=1; break; } } return res; } /* These functions allow to read, set or clear individual bits of a bitstring, referenced by a bitindex. */ int bitstring_get(bitstring_t* const b, bitindex_t ix) { return b[ix.word] & ix.bit; } void bitstring_set(bitstring_t* const b, bitindex_t ix){ b[ix.word] |= ix.bit; } void bitstring_clr(bitstring_t* const b, bitindex_t ix){ b[ix.word] &= ~ix.bit; } apron-dist-0.9.10/apron/newpolka/pk_representation.c0000640014525101416610000005163611247462105022421 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_representation.c: General management of polyhedra */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "pk_config.h" #include "pk_vector.h" #include "pk_satmat.h" #include "pk_matrix.h" #include "pk_cherni.h" #include "pk.h" #include "pk_user.h" #include "pk_representation.h" #include "pk_extract.h" #include "pk_constructor.h" /* ********************************************************************** */ /* Conversions */ /* ********************************************************************** */ pk_t* pk_of_abstract0(ap_abstract0_t* abstract) { ap_manager_t* man = abstract->man; if (strncmp(man->library,"polka",5)!=0){ ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT, AP_FUNID_UNKNOWN, "pk_of_abstract0: attempt to extract a NewPolka polyhedra from an abstract value which is not a wrapper around a NewPolka polyhedra"); return NULL; } return (pk_t*)abstract->value; } ap_abstract0_t* pk_to_abstract0(ap_manager_t* man, pk_t* poly) { if (strncmp(man->library,"polka",5)!=0){ ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT, AP_FUNID_UNKNOWN, "pk_to_abstract0: attempt to extract a NewPolka polyhedra from an abstract value which is not a wrapper around a NewPolka polyhedra"); return ap_abstract0_top(man,poly->intdim,poly->realdim); } else { ap_abstract0_t* res = malloc(sizeof(ap_abstract0_t)); res->man = man; res->value = poly; return res; } } /* ********************************************************************** */ /* I. Memory */ /* ********************************************************************** */ /* This internal function allocates a polyhedron and fills its records with null values. */ pk_t* poly_alloc(size_t intdim, size_t realdim) { pk_t* po = (pk_t*)malloc(sizeof(pk_t)); po->C = NULL; po->F = NULL; po->satC = NULL; po->satF = NULL; po->intdim = intdim; po->realdim = realdim; po->nbeq = 0; po->nbline = 0; po->status = 0; return po; } /* Clearing a polyhedron */ void poly_clear(pk_t* po) { if (po->C) matrix_free(po->C); if (po->F) matrix_free(po->F); if (po->satC) satmat_free(po->satC); if (po->satF) satmat_free(po->satF); po->C = NULL; po->F = NULL; po->satC = NULL; po->satF = NULL; po->status = 0; po->nbeq = 0; po->nbline = 0; } /* Assignement with GMP semantics */ void poly_set(pk_t* pa, pk_t* pb) { if (pa!=pb){ poly_clear(pa); pa->intdim = pb->intdim; pa->realdim = pb->realdim; pa->C = pb->C ? matrix_copy(pb->C) : NULL; pa->F = pb->F ? matrix_copy(pb->F) : NULL; pa->satC = pb->satC ? satmat_copy(pb->satC) : NULL; pa->satF = pb->satF ? satmat_copy(pb->satF) : NULL; pa->status = pb->status; pa->nbeq = pb->nbeq; pa->nbline = pb->nbline; pa->status = pb->status; } } /* Duplicate (recursively) a polyhedron. */ pk_t* pk_copy(ap_manager_t* man, pk_t* po) { pk_t* npo = poly_alloc(po->intdim,po->realdim); npo->C = po->C ? matrix_copy(po->C) : 0; npo->F = po->F ? matrix_copy(po->F) : 0; npo->satC = po->satC ? satmat_copy(po->satC) : 0; npo->satF = po->satF ? satmat_copy(po->satF) : 0; npo->nbeq = po->nbeq; npo->nbline = po->nbline; npo->status = po->status; return npo; } /* Finalization function for polyhedra, which frees recursively the members of the structure. */ void pk_free(ap_manager_t* man, pk_t* po) { poly_clear(po); free(po); } /* Return the abstract size of a polyhedron, which is the number of coefficients of its current representation, possibly redundant. */ size_t pk_size(ap_manager_t* man, pk_t* po) { size_t s1,s2; s1 = (po->C) ? po->C->nbrows : 0; s2 = (po->F) ? po->F->nbrows : 0; return (s1+s2)*(po->intdim + po->realdim); } /* ********************************************************************** */ /* II. Control of internal representation */ /* ********************************************************************** */ /* ====================================================================== */ /* II.1 Dual representation */ /* ====================================================================== */ /* Minimization function, in the sense of minimized dual representation This function minimizes if not already done the given polyhedron. Transmit exception */ void poly_chernikova(ap_manager_t* man, pk_t* po, char* msg) { pk_internal_t* pk = (pk_internal_t*)man->internal; if ((po->C && po->F) || (!po->C && !po->F)){ return; } else { if (po->C){ if (!poly_is_conseps(pk,po) ){ matrix_normalize_constraint(pk,po->C,po->intdim,po->realdim); } matrix_sort_rows(pk,po->C); cherni_minimize(pk,true,po); if (pk->exn) goto poly_chernikova_exit0; po->status = pk_status_consgauss; } else { po->C = po->F; po->F = NULL; matrix_sort_rows(pk,po->C); cherni_minimize(pk,false,po); poly_dual(po); if (pk->exn) goto poly_chernikova_exit0; po->status = pk_status_gengauss; } } return; poly_chernikova_exit0: po->status = 0; { char str[160]; sprintf(str,"conversion from %s %s\n", po->C ? "constraints to generators" : "generators to constraints", msg); ap_manager_raise_exception(man,pk->exn,pk->funid,str); } return; } /* Same as poly_chernikova, but if usual is false meaning of constraints and matrices exchanged. */ void poly_chernikova_dual(ap_manager_t* man, pk_t* po, char* msg, bool usual) { if ( (!po->C && !po->F) || (po->C && po->F) ) return; else { if (!usual) poly_dual(po); poly_chernikova(man,po,msg); if (!usual) poly_dual(po); } } /* Ensure minimized and normalized epsilon constraints. */ void poly_chernikova2(ap_manager_t* man, pk_t* po, char* msg) { pk_internal_t* pk = (pk_internal_t*)man->internal; poly_chernikova(man,po,msg); if (pk->exn) return; if (!po->C && !po->F) return; assert(po->C && po->F); if (!poly_is_minimaleps(pk,po)){ poly_obtain_satF(po); bool change = cherni_minimizeeps(pk,po); assert((po->status & pk_status_minimaleps) && (po->status & pk_status_conseps)); if (change){ matrix_sort_rows(pk,po->C); cherni_minimize(pk, true, po); if (pk->exn) goto poly_chernikova2_exit0; assert(po->C && po->F); po->status = pk_status_consgauss | pk_status_minimaleps; } } assert(poly_is_minimaleps(pk,po)); return; poly_chernikova2_exit0: po->status = 0; { char str[160]; sprintf(str,"conversion from %s %s\n", po->C ? "constraints to generators" : "generators to constraints", msg); ap_manager_raise_exception(man,pk->exn,pk->funid,str); } return; } /* Same as poly_chernikova2, but in addition normalize matrices by Gauss elimination and sorting */ void poly_chernikova3(ap_manager_t* man, pk_t* po, char* msg) { pk_internal_t* pk = (pk_internal_t*)man->internal; poly_chernikova2(man,po,msg); if (pk->exn) return; if (po->C){ assert(po->F); size_t rank; if (! (po->status & pk_status_consgauss)){ rank = cherni_gauss(pk,po->C,po->nbeq); assert(rank==po->nbeq); cherni_backsubstitute(pk,po->C,rank); po->C->_sorted = false; } if (! (po->status & pk_status_gengauss)){ rank = cherni_gauss(pk,po->F,po->nbline); assert(rank==po->nbline); cherni_backsubstitute(pk,po->F,rank); po->F->_sorted = false; } poly_obtain_sorted_C(pk,po); poly_obtain_sorted_F(pk,po); po->status |= pk_status_consgauss | pk_status_gengauss; assert(po->C->_sorted && po->F->_sorted && (po->status | pk_status_consgauss) && (po->status | pk_status_gengauss) && (po->status | pk_status_minimaleps)); } } void poly_obtain_sorted_F(pk_internal_t* pk, pk_t* po) { assert (po->F); if (!matrix_is_sorted(po->F)){ if (po->satC){ if (po->satF){ satmat_free(po->satF); po->satF = 0; } matrix_sort_rows_with_sat(pk,po->F,po->satC); } else if (po->satF){ po->satC = satmat_transpose(po->satF,po->F->nbrows); satmat_free(po->satF); po->satF = 0; matrix_sort_rows_with_sat(pk,po->F,po->satC); } else { matrix_sort_rows(pk,po->F); } } } void poly_obtain_sorted_C(pk_internal_t* pk, pk_t* po) { assert (po->C); if (!matrix_is_sorted(po->C)){ if (po->satF){ if (po->satC){ satmat_free(po->satC); po->satC = 0; } matrix_sort_rows_with_sat(pk,po->C,po->satF); } else if (po->satC){ po->satF = satmat_transpose(po->satC,po->C->nbrows); satmat_free(po->satC); po->satC = 0; matrix_sort_rows_with_sat(pk,po->C,po->satF); } else { matrix_sort_rows(pk,po->C); } } } /* ====================================================================== */ /* II.2 Canonical form */ /* ====================================================================== */ /* Put the polyhedron with minimized constraints and frames. If in addition the integer man->option->canonicalize.algorithm is positive, normalize equalities and lines, and also strict constraints */ void pk_canonicalize(ap_manager_t* man, pk_t* po) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_CANONICALIZE); assert(poly_check(pk,po)); if (pk->funopt->algorithm >= 0) poly_chernikova3(man,po,NULL); else poly_chernikova(man,po,NULL); if (pk->exn){ pk->exn = AP_EXC_NONE; man->result.flag_exact = man->result.flag_best = false; return; } assert(poly_check(pk,po)); man->result.flag_exact = man->result.flag_best = po->intdim>0 && (po->C || po->F) ? false : true; } int pk_hash(ap_manager_t* man, pk_t* po) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_HASH); int res,t; size_t i; ap_funopt_t opt = ap_manager_get_funopt(man,AP_FUNID_CANONICALIZE); poly_chernikova3(man,po,NULL); assert(poly_check(pk,po)); res = 5*po->intdim + 7*po->realdim; if (po->C!=NULL){ res += po->C->nbrows*11 + po->F->nbrows*13; for (i=0; iC->nbrows; i += (po->C->nbrows+3)/4){ res = res*3 + vector_hash(pk,po->C->p[i],po->C->nbcolumns); } for (i=0; iF->nbrows; i += (po->F->nbrows+3)/4){ res = res*3 + vector_hash(pk,po->F->p[i],po->F->nbcolumns); } } return res; } /* Minimize the size of the representation of the polyhedron */ void pk_minimize(ap_manager_t* man, pk_t* po) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_MINIMIZE); if (po->C || po->F){ poly_chernikova2(man,po,NULL); if (pk->exn){ pk->exn = AP_EXC_NONE; man->result.flag_exact = man->result.flag_best = false; return; } if (po->C || po->F){ if (po->satC) satmat_free(po->satC); if (po->satF) satmat_free(po->satF); po->satC = po->satF = NULL; if (po->C->nbrows > po->F->nbrows){ matrix_free(po->C); po->C = NULL; matrix_minimize(po->F); po->status &= ~pk_status_consgauss; } else { matrix_free(po->F); po->F = NULL; matrix_minimize(po->C); po->status &= ~pk_status_gengauss; } } } assert(poly_check(pk,po)); man->result.flag_exact = man->result.flag_best = po->intdim>0 && (po->C || po->F) ? false : true; } /* ====================================================================== */ /* II.4 Minimal representation */ /* ====================================================================== */ /* Is the polyhedron in a minimal representation ? */ bool pk_is_minimal(ap_manager_t* man, pk_t* po) { if ( (!po->C && !po->F) || (po->C && po->F && (po->status & pk_status_minimaleps)) ) return true; else return false; } /* Is the polyhedron in a canonical representation ? (depends on the algorithm option of canonicalize) */ bool pk_is_canonical(ap_manager_t* man, pk_t* po) { bool res; if (!po->C && !po->F) res = true; else if (!po->C || !po->F) res = false; else { pk_internal_t* pk = (pk_internal_t*)man->internal; assert(poly_check(pk,po)); if (po->C->_sorted && po->F->_sorted && po->status & pk_status_consgauss && po->status & pk_status_gengauss && poly_is_minimaleps(pk,po)) res = true; else res = false; } return res; } /* ********************************************************************** */ /* III Printing */ /* ********************************************************************** */ void pk_fprint(FILE* stream, ap_manager_t* man, pk_t* po, char** name_of_dim) { pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_FPRINT); poly_chernikova(man,po,NULL); if (!po->C && !po->F){ assert(pk->exn == AP_EXC_NONE); fprintf(stream,"empty polyhedron of dim (%lu,%lu)\n", (unsigned long)po->intdim,(unsigned long)po->realdim); } else { fprintf(stream,"polyhedron of dim (%lu,%lu)\n", (unsigned long)po->intdim,(unsigned long)po->realdim); if (pk->exn){ pk->exn = AP_EXC_NONE; fprintf(stream,"cannot display due to exception\n"); } else { ap_lincons0_array_t cons = pk_to_lincons_array(man,po); ap_lincons0_array_fprint(stream,&cons,name_of_dim); ap_lincons0_array_clear(&cons); } } } void pk_fprintdiff(FILE* stream, ap_manager_t* man, pk_t* po1, pk_t* po2, char** name_of_dim) { pk_init_from_manager(man,AP_FUNID_FPRINTDIFF); ap_manager_raise_exception(man,AP_EXC_NOT_IMPLEMENTED,AP_FUNID_FPRINTDIFF,NULL); } /* Raw printing function. */ void pk_fdump(FILE* stream, ap_manager_t* man, pk_t* po) { pk_init_from_manager(man,AP_FUNID_FDUMP); if (!po->C && !po->F) fprintf(stream,"empty polyhedron of dim (%lu,%lu)\n", (unsigned long)po->intdim,(unsigned long)po->realdim); else { fprintf(stream,"polyhedron of dim (%lu,%lu)\n", (unsigned long)po->intdim,(unsigned long)po->realdim); if (po->C){ fprintf(stream,"Constraints: "); matrix_fprint(stream, po->C); } if (po->F){ fprintf(stream,"Frames: "); matrix_fprint(stream, po->F); } if (po->satC){ fprintf(stream,"satC: "); satmat_fprint(stream, po->satC); } if (po->satF){ fprintf(stream,"satF: "); satmat_fprint(stream, po->satF); } } } /* ********************************************************************** */ /* IV. Serialization */ /* ********************************************************************** */ ap_membuf_t pk_serialize_raw(ap_manager_t* man, pk_t* a) { ap_membuf_t membuf; pk_init_from_manager(man,AP_FUNID_SERIALIZE_RAW); ap_manager_raise_exception(man,AP_EXC_NOT_IMPLEMENTED,AP_FUNID_SERIALIZE_RAW,NULL); membuf.ptr = NULL; membuf.size = 0; return membuf; } pk_t* pk_deserialize_raw(ap_manager_t* man, void* ptr, size_t* size) { pk_init_from_manager(man,AP_FUNID_DESERIALIZE_RAW); ap_manager_raise_exception(man,AP_EXC_NOT_IMPLEMENTED,AP_FUNID_DESERIALIZE_RAW,NULL); return NULL; } /* ********************************************************************** */ /* V. Checking */ /* ********************************************************************** */ /* Should be true If false, implies that there is no positivity constraint */ static bool matrix_check1cons(pk_internal_t* pk, matrix_t* mat) { size_t i; bool res; res = false; for (i = 0; inbrows; i++){ if (numint_sgn(mat->p[i][pk->dec-1])>0){ res = true; break; } } return res; } /* true <=> \xi or \epsilon always positive */ static bool matrix_check1ray(pk_internal_t* pk, matrix_t* mat) { size_t i; bool res; res = true; for (i = 0; inbrows; i++){ if (numint_sgn(mat->p[i][pk->dec-1])<0){ res = false; break; } } return res; } /* Return false if not normalized constraint */ static bool matrix_check2(pk_internal_t* pk, matrix_t* mat) { size_t i; bool res; numint_t gcd; numint_init(gcd); res = true; for (i=0; inbrows; i++){ vector_gcd(pk, &mat->p[i][1], mat->nbcolumns-1, gcd); if (numint_cmp_int(gcd,1)>0){ res = false; break; } } numint_clear(gcd); return res; } /* If false, _sorted is true without sorted rows */ static bool matrix_check3(pk_internal_t* pk, matrix_t* mat) { size_t i; bool res; if (mat->_sorted==false) return true; res = true; for (i=0; inbrows-1; i++){ if (matrix_compare_rows(pk,mat,i,i+1)>0){ res = false; break; } } return res; } bool poly_check(pk_internal_t* pk, pk_t* po) { bool res; size_t nbdim,nbcols; nbdim = po->intdim + po->realdim; if (po->nbline+po->nbeq>nbdim){ fprintf(stderr,"poly_check: nbline+nbeq>intdim+realdim\n"); return false; } if (!po->C && !po->F) return true; nbcols = po->C ? po->C->nbcolumns : po->F->nbcolumns; if (nbcols != pk->dec+nbdim){ fprintf(stderr,"poly_check: pk->dec+intdim+realdim != nbcols\n"); return false; } if (po->C){ res = matrix_check1cons(pk,po->C); if (!res){ /* should not arise */ fprintf(stderr,"poly_check: unvalid constraint system, does not imply the positivity constraint\n"); return false; } res = matrix_check2(pk,po->C); if (!res){ fprintf(stderr,"poly_check: C not normalized\n"); return false; } res = matrix_check3(pk,po->C); if (!res){ fprintf(stderr,"poly_check: C not sorted although _sorted=true\n"); return false; } } if (po->F){ res = matrix_check1ray(pk,po->F); if (!res){ /* should not arise */ fprintf(stderr,"poly_check: unvalid generator system, does not imply the positivity constraint\n"); return false; } res = matrix_check2(pk,po->F); if (!res){ fprintf(stderr,"poly_check: F not normalized\n"); return false; } res = matrix_check3(pk,po->F); if (!res){ fprintf(stderr,"poly_check: F not sorted although _sorted=true\n"); return false; } /* In strict mode, check that it satisfies \xi-\epsilon>=0 */ if (pk->strict){ numint_t* tab = pk->vector_numintp; matrix_t* F = po->F; vector_clear(tab,F->nbcolumns); numint_set_int(tab[0],1); numint_set_int(tab[polka_cst],1); numint_set_int(tab[polka_eps],-1); bool res = true; int sign; /* sign of the scalar product */ size_t i; for (i=0; inbrows; i++){ vector_product(pk,pk->poly_prod, F->p[i], tab,F->nbcolumns); sign = numint_sgn(pk->poly_prod); if (sign<0){ res = false; break; } else { if (numint_sgn(F->p[i][0])==0){ /* line */ if (sign!=0){ res = false; break; } } } } if (!res){ fprintf(stderr,"poly_check: F does not satisfy epsilon<=1"); return false; } } } if (po->C && po->F){ if (!po->satC && !po->satF){ fprintf(stderr,"poly_check: we have both constraints and generators, but no saturation matrix !\n"); return false; } } else return true; if (po->C->nbcolumns != nbcols || po->F->nbcolumns != nbcols){ fprintf(stderr,"poly_check: po->C->nbcolumns==%lu, po->F->nbcolumns==%lu\n", (unsigned long)po->C->nbcolumns, (unsigned long)po->F->nbcolumns); return false; } if (po->satC){ if (po->satC->nbrows!=po->F->nbrows){ fprintf(stderr,"poly_check: po->satC->nbrows==%lu, po->F->nbrows==%lu\n", (unsigned long)po->satC->nbrows,(unsigned long)po->F->nbrows); return false; } if (!cherni_checksat(pk,true, po->C,po->nbeq, po->F,po->nbline, po->satC)){ fprintf(stderr,"poly_check: bad saturation numbers\n"); return false; } res = cherni_checksatmat(pk,true,po->C,po->F,po->satC); if (!res){ fprintf(stderr,"poly_check: bad satC\n"); return false; } } if (po->satF){ if (po->satF->nbrows!=po->C->nbrows){ fprintf(stderr,"poly_check: po->satF->nbrows==%lu, po->C->nbrows==%lu\n", (unsigned long)po->satF->nbrows, (unsigned long)po->C->nbrows); return false; } if (!cherni_checksat(pk,false, po->F,po->nbline, po->C,po->nbeq, po->satF)){ fprintf(stderr,"poly_check: bad saturation numbers\n"); return false; } res = cherni_checksatmat(pk,false,po->F,po->C,po->satF); if (!res){ fprintf(stderr,"poly_check: bad satF\n"); return false; } } /* Check status: conseps */ if (pk->strict && (po->status & pk_status_conseps) && po->C){ matrix_t* mat = po->C; size_t i; numint_t* vec = vector_alloc(mat->nbcolumns); res = true; for (i=0; inbrows; i++){ if (numint_sgn(mat->p[i][polka_eps])<=0){ vector_copy(vec,mat->p[i],mat->nbcolumns); if (vector_normalize_constraint(pk,vec,po->intdim,po->realdim)){ res = false; break; } } } vector_free(vec,mat->nbcolumns); if (!res){ fprintf(stderr,"poly_check: pk_status_conseps true but the matrix is not normalized\n"); return false; } } return true; } bool poly_check_dual(pk_internal_t* pk, pk_t* po, bool usual) { bool res; if (!usual) poly_dual(po); res = poly_check(pk,po); if (!usual) poly_dual(po); return res; } apron-dist-0.9.10/apron/newpolka/mf_qsort.c0000640014525101416610000001346510416736077020526 0ustar bjeannetpopart/* Copyright (C) 2000 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* Modified by Bertrand Jeannet */ /* qsort implementation optimized for comparison of pointers Inspired by the qsort implementations by Douglas C. Schmidt, and Bentley & McIlroy's "Engineering a Sort Function". */ #include #include #include "mf_qsort.h" #define QSORT_EXTRA_CMP_ARGUMENT /* We need to use qsort with 2 different compare functions */ #ifdef QSORT_EXTRA_CMP_ARGUMENT #define CMP(A,B) ((*cmp)(cmp_argument,(A),(B))) #else #define CMP(A,B) ((*cmp)((A),(B))) #endif #define SWAP(A, B, size,swap_ptrs) \ do { \ if (swap_ptrs) \ { \ char **a = (char**) (A), **b = (char**) (B); \ char *tmp = *a; *a++ = *b; *b++ = tmp; \ } \ else \ { \ char *a = (A), *b = (B); \ char *end= a+size; \ do \ { \ char tmp = *a; *a++ = *b; *b++ = tmp; \ } while (a < end); \ } \ } while (0) /* Put the median in the middle argument */ #define MEDIAN(low, mid, high) \ { \ if (CMP(high,low) < 0) \ SWAP(high, low, size, ptr_cmp); \ if (CMP(mid, low) < 0) \ SWAP(mid, low, size, ptr_cmp); \ else if (CMP(high, mid) < 0) \ SWAP(mid, high, size, ptr_cmp); \ } /* The following node is used to store ranges to avoid recursive calls */ typedef struct st_stack { char *low,*high; } stack_node; #define PUSH(LOW,HIGH) {stack_ptr->low = LOW; stack_ptr++->high = HIGH;} #define POP(LOW,HIGH) {LOW = (--stack_ptr)->low; HIGH = stack_ptr->high;} /* The following stack size is enough for ulong ~0 elements */ #define STACK_SIZE (8 * sizeof(unsigned long int)) #define THRESHOLD_FOR_INSERT_SORT 10 /**************************************************************************** ** 'standard' quicksort with the following extensions: ** ** Can be compiled with the qsort2_cmp compare function ** Store ranges on stack to avoid recursion ** Use insert sort on small ranges ** Optimize for sorting of pointers (used often by MySQL) ** Use median comparison to find partition element *****************************************************************************/ #ifdef QSORT_EXTRA_CMP_ARGUMENT void qsort2(void *base_ptr, size_t count, size_t size, qsort2_cmp cmp, void *cmp_argument) #else void qsort(void *base_ptr, size_t count, size_t size, qsort_cmp cmp) #endif { char *low, *high, *pivot; stack_node stack[STACK_SIZE], *stack_ptr; char ptr_cmp; /* Handle the simple case first */ /* This will also make the rest of the code simpler */ if (count <= 1) return; low = (char*) base_ptr; high = low + size * (count - 1); stack_ptr = stack + 1; pivot = (char *) malloc(size); ptr_cmp= size == sizeof(char*) && !((low - (char*) 0)& (sizeof(char*)-1)); /* The following loop sorts elements between high and low */ do { char *low_ptr, *high_ptr, *mid; count=((size_t) (high - low) / size)+1; /* If count is small, then an insert sort is faster than qsort */ if (count < THRESHOLD_FOR_INSERT_SORT) { for (low_ptr = low + size; low_ptr <= high; low_ptr += size) { char *ptr; for (ptr = low_ptr; ptr > low && CMP(ptr - size, ptr) > 0; ptr -= size) SWAP(ptr, ptr - size, size, ptr_cmp); } POP(low, high); continue; } /* Try to find a good middle element */ mid= low + size * (count >> 1); if (count > 40) /* Must be bigger than 24 */ { size_t step = size* (count / 8); MEDIAN(low, low + step, low+step*2); MEDIAN(mid - step, mid, mid+step); MEDIAN(high - 2 * step, high-step, high); /* Put best median in 'mid' */ MEDIAN(low+step, mid, high-step); low_ptr = low; high_ptr = high; } else { MEDIAN(low, mid, high); /* The low and high argument are already in sorted against 'pivot' */ low_ptr = low + size; high_ptr = high - size; } memcpy(pivot, mid, size); do { while (CMP(low_ptr, pivot) < 0) low_ptr += size; while (CMP(pivot, high_ptr) < 0) high_ptr -= size; if (low_ptr < high_ptr) { SWAP(low_ptr, high_ptr, size, ptr_cmp); low_ptr += size; high_ptr -= size; } else { if (low_ptr == high_ptr) { low_ptr += size; high_ptr -= size; } break; } } while (low_ptr <= high_ptr); /* Prepare for next iteration. Skip partitions of size 1 as these doesn't have to be sorted Push the larger partition and sort the smaller one first. This ensures that the stack is keept small. */ if ((int) (high_ptr - low) <= 0) { if ((int) (high - low_ptr) <= 0) { POP(low, high); /* Nothing more to sort */ } else low = low_ptr; /* Ignore small left part. */ } else if ((int) (high - low_ptr) <= 0) high = high_ptr; /* Ignore small right part. */ else if ((high_ptr - low) > (high - low_ptr)) { PUSH(low, high_ptr); /* Push larger left part */ low = low_ptr; } else { PUSH(low_ptr, high); /* Push larger right part */ high = high_ptr; } } while (stack_ptr > stack); free(pivot); } apron-dist-0.9.10/apron/newpolka/pk_internal.c0000640014525101416610000002065610760562320021170 0ustar bjeannetpopart/* ************************************************************************* */ /* internal.c: internal manager */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "pk_config.h" #include "pk_internal.h" #include "pk_vector.h" #include "pk_matrix.h" #include "pk_satmat.h" /* ********************************************************************** */ /* I. Constructor and destructor for internal */ /* ********************************************************************** */ /* Initialize pk with size maxdims */ void pk_internal_init(pk_internal_t* pk, size_t maxdims) { size_t i; pk->exn = AP_EXC_NONE; pk->maxdims = maxdims; pk->maxcols = maxdims+3; pk->vector_numintp = vector_alloc(pk->maxcols); pk->vector_mpqp = malloc( (maxdims+3)*sizeof(mpq_t)); for (i=0; ivector_mpqp[i]); pk->vector_tmp = vector_alloc(5); pk->matrix_dimp = malloc(pk->maxdims*sizeof(ap_dim_t)); numint_init(pk->matrix_acc); numint_init(pk->matrix_prod); /* pk->cherni_bitstringp = bitstring_alloc(bitindex_size(pk->maxrows));*/ pk->cherni_intp = (int*)malloc(pk->maxcols * sizeof(int)); numint_init(pk->cherni_prod); pk->itv = itv_internal_alloc(); bound_init(pk->poly_bound); itv_init(pk->poly_itv); itv_linexpr_init(&pk->poly_itv_linexpr,maxdims); itv_lincons_init(&pk->poly_itv_lincons); numrat_init(pk->poly_numrat); pk->poly_numintp = vector_alloc(pk->maxcols); pk->poly_numintp2 = vector_alloc(pk->maxcols); pk->poly_dimp = malloc(pk->maxdims*sizeof(ap_dim_t)); pk->poly_dimp2 = malloc(pk->maxdims*sizeof(ap_dim_t)); pk->poly_fold_dimp = malloc(pk->maxdims*sizeof(ap_dim_t)); /* pk->poly_bitstringp = bitstring_alloc(bitindex_size(pk->maxrows)); */ pk->poly_matspecial = matrix_alloc(1,pk->maxcols,true); numint_init(pk->poly_prod); } /* Allocates pk and initializes it with a default size */ pk_internal_t* pk_internal_alloc(bool strict) { pk_internal_t* pk = (pk_internal_t*)malloc(sizeof(pk_internal_t)); pk->strict = strict; pk->dec = strict ? 3 : 2; pk->max_coeff_size = 0; pk->approximate_max_coeff_size = 2; pk_internal_init(pk,10); return pk; } /* Clear pk */ void pk_internal_clear(pk_internal_t* pk) { size_t i; if (pk->vector_numintp) vector_free(pk->vector_numintp,pk->maxcols); pk->vector_numintp = 0; if (pk->vector_tmp) vector_free(pk->vector_tmp,5); pk->vector_tmp = 0; if (pk->vector_mpqp){ for (i=0; imaxdims+3; i++) mpq_clear(pk->vector_mpqp[i]); free(pk->vector_mpqp); } pk->vector_mpqp = 0; if (pk->matrix_dimp) free(pk->matrix_dimp); pk->matrix_dimp = 0; numint_clear(pk->matrix_acc); numint_clear(pk->matrix_prod); /* if (pk->cherni_bitstringp) free(pk->cherni_bitstringp); pk->cherni_bitstringp = 0; */ if (pk->cherni_intp) free(pk->cherni_intp); pk->cherni_intp = 0; numint_clear(pk->cherni_prod); if (pk->itv) itv_internal_free(pk->itv); pk->itv = 0; bound_clear(pk->poly_bound); itv_clear(pk->poly_itv); itv_linexpr_clear(&pk->poly_itv_linexpr); itv_lincons_clear(&pk->poly_itv_lincons); numrat_clear(pk->poly_numrat); if (pk->poly_numintp) vector_free(pk->poly_numintp, pk->maxcols); pk->poly_numintp = 0; if (pk->poly_numintp2) vector_free(pk->poly_numintp2, pk->maxcols); pk->poly_numintp2 = 0; if (pk->poly_dimp) free(pk->poly_dimp); pk->poly_dimp = 0; if (pk->poly_dimp2) free(pk->poly_dimp2); pk->poly_dimp2 = 0; if (pk->poly_fold_dimp) free(pk->poly_fold_dimp); pk->poly_fold_dimp = 0; /* if (pk->poly_bitstringp) bitstring_free(pk->poly_bitstringp); pk->poly_bitstringp = 0; */ if (pk->poly_matspecial) matrix_free(pk->poly_matspecial); pk->poly_matspecial = 0; numint_clear(pk->poly_prod); pk->maxdims = 0; pk->maxrows = 0; pk->maxcols = 0; } /* Clear and free pk */ void pk_internal_free(pk_internal_t* pk) { pk_internal_clear(pk); free(pk); } /* Reallocate pk */ void pk_internal_realloc(pk_internal_t* pk, size_t maxdims) { if (pk->maxdims != maxdims){ pk_internal_clear(pk); pk_internal_init(pk,maxdims); } } /* Reallocate pk only if a bigger dimension is required */ void pk_internal_realloc_lazy(pk_internal_t* pk, size_t maxdims) { if (maxdims > pk->maxdims){ pk_internal_clear(pk); pk_internal_init(pk,maxdims); } } /* ********************************************************************** */ /* II. Options */ /* ********************************************************************** */ pk_internal_t* pk_manager_get_internal(ap_manager_t* man){ return man->internal; } void pk_set_max_coeff_size(pk_internal_t* pk, size_t size){ pk->max_coeff_size = size; } void pk_set_approximate_max_coeff_size(pk_internal_t* pk, size_t size){ pk->approximate_max_coeff_size = size; } size_t pk_get_max_coeff_size(pk_internal_t* pk){ return pk->max_coeff_size; } size_t pk_get_approximate_max_coeff_size(pk_internal_t* pk){ return pk->approximate_max_coeff_size; } /* ********************************************************************** */ /* III. Initialization from manager */ /* ********************************************************************** */ ap_manager_t* pk_manager_alloc(bool strict) { size_t i; pk_internal_t* pk; ap_manager_t* man; void** funptr; pk = pk_internal_alloc(strict); pk_set_approximate_max_coeff_size(pk, 1); man = ap_manager_alloc(strict ? "polka, strict mode" : "polka, loose mode", #if defined(NUMINT_LONGINT) "3.0 with NUMINT_LONGINT", #elif defined(NUMINT_LONGLONGINT) "3.0 with NUMINT_LONGLONGINT", #elif defined(NUMINT_MPZ) "3.0 with NUMINT_MPZ", #else #error "here" #endif pk, (void (*)(void*))pk_internal_free); funptr = man->funptr; funptr[AP_FUNID_COPY] = &pk_copy; funptr[AP_FUNID_FREE] = &pk_free; funptr[AP_FUNID_ASIZE] = &pk_size; funptr[AP_FUNID_MINIMIZE] = &pk_minimize; funptr[AP_FUNID_CANONICALIZE] = &pk_canonicalize; funptr[AP_FUNID_HASH] = &pk_hash; funptr[AP_FUNID_APPROXIMATE] = &pk_approximate; funptr[AP_FUNID_FPRINT] = &pk_fprint; funptr[AP_FUNID_FPRINTDIFF] = &pk_fprintdiff; funptr[AP_FUNID_FDUMP] = &pk_fdump; funptr[AP_FUNID_SERIALIZE_RAW] = &pk_serialize_raw; funptr[AP_FUNID_DESERIALIZE_RAW] = &pk_deserialize_raw; funptr[AP_FUNID_BOTTOM] = &pk_bottom; funptr[AP_FUNID_TOP] = &pk_top; funptr[AP_FUNID_OF_BOX] = &pk_of_box; funptr[AP_FUNID_DIMENSION] = &pk_dimension; funptr[AP_FUNID_IS_BOTTOM] = &pk_is_bottom; funptr[AP_FUNID_IS_TOP] = &pk_is_top; funptr[AP_FUNID_IS_LEQ] = &pk_is_leq; funptr[AP_FUNID_IS_EQ] = &pk_is_eq; funptr[AP_FUNID_IS_DIMENSION_UNCONSTRAINED] = &pk_is_dimension_unconstrained; funptr[AP_FUNID_SAT_INTERVAL] = &pk_sat_interval; funptr[AP_FUNID_SAT_LINCONS] = &pk_sat_lincons; funptr[AP_FUNID_SAT_TCONS] = &pk_sat_tcons; funptr[AP_FUNID_BOUND_DIMENSION] = &pk_bound_dimension; funptr[AP_FUNID_BOUND_LINEXPR] = &pk_bound_linexpr; funptr[AP_FUNID_BOUND_TEXPR] = &pk_bound_texpr; funptr[AP_FUNID_TO_BOX] = &pk_to_box; funptr[AP_FUNID_TO_LINCONS_ARRAY] = &pk_to_lincons_array; funptr[AP_FUNID_TO_TCONS_ARRAY] = &pk_to_tcons_array; funptr[AP_FUNID_TO_GENERATOR_ARRAY] = &pk_to_generator_array; funptr[AP_FUNID_MEET] = &pk_meet; funptr[AP_FUNID_MEET_ARRAY] = &pk_meet_array; funptr[AP_FUNID_MEET_LINCONS_ARRAY] = &pk_meet_lincons_array; funptr[AP_FUNID_MEET_TCONS_ARRAY] = &pk_meet_tcons_array; funptr[AP_FUNID_JOIN] = &pk_join; funptr[AP_FUNID_JOIN_ARRAY] = &pk_join_array; funptr[AP_FUNID_ADD_RAY_ARRAY] = &pk_add_ray_array; funptr[AP_FUNID_ASSIGN_LINEXPR_ARRAY] = &pk_assign_linexpr_array; funptr[AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY] = &pk_substitute_linexpr_array; funptr[AP_FUNID_ASSIGN_TEXPR_ARRAY] = &pk_assign_texpr_array; funptr[AP_FUNID_SUBSTITUTE_TEXPR_ARRAY] = &pk_substitute_texpr_array; funptr[AP_FUNID_ADD_DIMENSIONS] = &pk_add_dimensions; funptr[AP_FUNID_REMOVE_DIMENSIONS] = &pk_remove_dimensions; funptr[AP_FUNID_PERMUTE_DIMENSIONS] = &pk_permute_dimensions; funptr[AP_FUNID_FORGET_ARRAY] = &pk_forget_array; funptr[AP_FUNID_EXPAND] = &pk_expand; funptr[AP_FUNID_FOLD] = &pk_fold; funptr[AP_FUNID_WIDENING] = &pk_widening; funptr[AP_FUNID_CLOSURE] = &pk_closure; ap_manager_set_abort_if_exception(man, AP_EXC_TIMEOUT, false); ap_manager_set_abort_if_exception(man, AP_EXC_OUT_OF_SPACE, false); ap_manager_set_abort_if_exception(man, AP_EXC_OVERFLOW, false); return man; } apron-dist-0.9.10/apron/newpolka/pk_representation.h0000640014525101416610000001307211247462105022416 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_representation.h: General management of polyhedra */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _PK_REPRESENTATION_H_ #define _PK_REPRESENTATION_H_ #include "pk.h" #ifdef __cplusplus extern "C" { #endif /* ********************************************************************** */ /* I. Memory */ /* ********************************************************************** */ /* Allocates a polyedron and fills its structure with null values, which corresponds to a bottom polyhedron. */ pk_t* poly_alloc(size_t intdim, size_t realdim); /* Free all the members of the polyhedron structure (GMP semantics) */ void poly_clear(pk_t* po); /* Assignement with GMP semantics */ void poly_set(pk_t* pa, pk_t* pb); /* ********************************************************************** */ /* II. Control of internal representation */ /* ********************************************************************** */ /* Minimization function, in the sense of minimized dual representation This function minimizes if not already done the given polyhedron. Raise an exception, but still transmit it (pk->exn not reseted). */ void poly_chernikova(ap_manager_t* man, pk_t* poly, char* msg); /* Same as poly_chernikova, but in addition ensure normalized epsilon constraints. */ void poly_chernikova2(ap_manager_t* man, pk_t* poly, char* msg); /* Same as poly_chernikova2, but in addition normalize matrices by Gauss elimination and sorting */ void poly_chernikova3(ap_manager_t* man, pk_t* poly, char* msg); /* Put the polyhedron with minimized constraints and frames. If in addition the integer man->option->canonicalize.algorithm is strictly positive, normalize equalities and lines, and also strict constraints */ void poly_canonicalize(ap_manager_t* man, pk_t* poly); /* Has the polyhedron normalized strict constraints ? */ static inline bool poly_is_conseps(pk_internal_t* pk, pk_t* po); /* Is the polyhedron under (strong) normal form ? */ bool pk_is_canonical(ap_manager_t* man, pk_t* po); /* Make available the matrix of constraints (resp. frames). The matrix will remain unavailable iff the polyhedron appears to be empty */ static inline void poly_obtain_C(ap_manager_t* man, pk_t* po, char* msg); static inline void poly_obtain_F(ap_manager_t* man, pk_t* po, char* msg); /* Assuming the the matrix of constraints (resp. frames) is available, sort it, and take care of the saturation matrices. */ void poly_obtain_sorted_C(pk_internal_t* pk, pk_t* poly); void poly_obtain_sorted_F(pk_internal_t* pk, pk_t* poly); /* Assuming one of the saturation matrix is available, make satC (resp. satF) available. */ static inline void poly_obtain_satC(pk_t* poly); static inline void poly_obtain_satF(pk_t* poly); /* Exchange C and F, sat C and satF, nbeq and nbline */ static inline void poly_dual(pk_t* po); /* Like poly_chernikova, etc, but if usual is false, take into account the fact that poly_dual has been applied */ void poly_chernikova_dual(ap_manager_t* man, pk_t* poly, char* msg, bool usual); static inline void poly_obtain_C_dual(ap_manager_t* man,pk_t* po, char* msg, bool usual); static inline void poly_obtain_F_dual(ap_manager_t* man,pk_t* po, char* msg, bool usual); /* ********************************************************************** */ /* V. Checking */ /* ********************************************************************** */ /* Perform rather detailed and costly checks on a polyhedron, to detect inconsistencies */ bool poly_check(pk_internal_t* pk, pk_t* po); /* Same as previous function, but usual==false mean that poly_dual has been applied */ bool poly_check_dual(pk_internal_t* pk, pk_t* po, bool usual); /* ********************************************************************** */ /* ********************************************************************** */ /* INLINE DEFINITIONS */ /* ********************************************************************** */ static inline bool poly_is_conseps(pk_internal_t* pk, pk_t* po) { return (!pk->strict || po->realdim==0 || (po->status & pk_status_conseps));; } static inline bool poly_is_minimaleps(pk_internal_t* pk, pk_t* po) { return (!pk->strict || po->realdim==0 || (po->status & pk_status_minimaleps)); } static inline void poly_obtain_C(ap_manager_t* man, pk_t* po, char* msg) { if (!po->C) poly_chernikova(man,po,msg); } static inline void poly_obtain_F(ap_manager_t* man, pk_t* po, char* msg) { if (!po->F) poly_chernikova(man,po,msg); } static inline void poly_obtain_satF(pk_t* poly) { if (!poly->satF){ assert(poly->C && poly->satC); poly->satF = satmat_transpose(poly->satC,poly->C->nbrows); } } static inline void poly_obtain_satC(pk_t* poly) { if (!poly->satC){ assert(poly->F && poly->satF); poly->satC = satmat_transpose(poly->satF,poly->F->nbrows); } } static inline void poly_dual(pk_t* po) { void* ptr; size_t nb; ptr = po->C; po->C = po->F; po->F = ptr; ptr = po->satC; po->satC = po->satF; po->satF = ptr; nb = po->nbeq; po->nbeq = po->nbline; po->nbline = nb; } static inline void poly_obtain_C_dual(ap_manager_t* man, pk_t* po, char* msg, bool usual) { if (!po->C) poly_chernikova_dual(man,po,msg,usual); } static inline void poly_obtain_F_dual(ap_manager_t* man, pk_t* po, char* msg, bool usual) { if (!po->F) poly_chernikova_dual(man,po,msg,usual); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/newpolka/pk_internal.h0000640014525101416610000000622710723557216021202 0ustar bjeannetpopart/* ************************************************************************* */ /* pk_internal.h: internal manager */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _PK_INTERNAL_H_ #define _PK_INTERNAL_H_ #include "pk_config.h" #include "pk_bit.h" #include "pk.h" #ifdef __cplusplus extern "C" { #endif /* ********************************************************************** */ /* I. Types */ /* ********************************************************************** */ /* These variables are used by various functions. The prefix XXX_ indicates that the variable is used by the module XXX. */ struct pk_internal_t { enum ap_exc_t exn; bool strict; size_t dec; size_t maxdims; size_t maxcols; size_t maxrows; ap_funid_t funid; ap_funopt_t* funopt; size_t max_coeff_size; /* Used for overflow exception in vector_combine */ size_t approximate_max_coeff_size; numint_t* vector_numintp; /* of size maxcols */ mpq_t* vector_mpqp; /* of size maxdims+3 */ numint_t* vector_tmp; /* of size 5 */ ap_dim_t* matrix_dimp; /* of size maxdims */ numint_t matrix_acc; numint_t matrix_prod; /* bitstring_t* cherni_bitstringp; */ /* of size maxrows */ int* cherni_intp; /* of size maxcols */ numint_t cherni_prod; itv_internal_t* itv; bound_t poly_bound; itv_t poly_itv; itv_linexpr_t poly_itv_linexpr; itv_lincons_t poly_itv_lincons; numrat_t poly_numrat; numint_t* poly_numintp; /* of size maxcols */ numint_t* poly_numintp2; /* of size maxcols */ /* bitstring_t* poly_bitstringp; */ /* of size maxrows */ ap_dim_t* poly_dimp; /* of size maxdims */ ap_dim_t* poly_dimp2; /* of size maxdims */ ap_dim_t* poly_fold_dimp; /* of size maxdims */ struct matrix_t* poly_matspecial; numint_t poly_prod; }; /* ********************************************************************** */ /* A. Constructor and destructor for internal */ /* ********************************************************************** */ pk_internal_t* pk_internal_alloc(bool strict); /* Allocates pk and initializes it with a default size */ void pk_internal_free(pk_internal_t* pk); /* Clear and free pk */ void pk_internal_realloc_lazy(pk_internal_t* pk, size_t maxdims); /* Reallocate pk only if a bigger dimension is required */ static inline pk_internal_t* pk_init_from_manager(ap_manager_t* man, ap_funid_t funid); /* Initializes some fields of pk from manager */ /* ********************************************************************** */ /* Definition of inline functions */ /* ********************************************************************** */ static inline pk_internal_t* pk_init_from_manager(ap_manager_t* man, ap_funid_t funid) { pk_internal_t* pk = (pk_internal_t*)man->internal; pk->funid = funid; pk->funopt = &man->option.funopt[funid]; man->result.flag_exact = man->result.flag_best = false; return pk; } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/newpolka/pk_satmat.c0000640014525101416610000001306610613136246020643 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_satmat.c: operations on saturation matrices */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ /* Operations on saturation matrices */ #include #include #include #include "pk_satmat.h" /* ********************************************************************** */ /* I. basic operations: creation, destruction, copying and printing */ /* ********************************************************************** */ /* Set all bits to zero. */ void satmat_clear(satmat_t* sat) { size_t i,j; for (i=0; inbrows; i++) for (j=0; jnbcolumns; j++) sat->p[i][j] = 0; } /* Standard allocation function, with initialization of the elements. */ satmat_t* satmat_alloc(size_t nbrows, size_t nbcols) { size_t i,j; satmat_t* sat = (satmat_t*)malloc(sizeof(satmat_t)); sat->nbrows = sat->_maxrows = nbrows; sat->nbcolumns = nbcols; sat->p = (bitstring_t**)malloc(nbrows*sizeof(bitstring_t*)); for (i=0; ip[i] = bitstring_alloc(nbcols); for (j=0; jnbcolumns; j++) sat->p[i][j] = 0; } return sat; } /* Deallocation function. */ void satmat_free(satmat_t* sat) { size_t i; for (i=0;i_maxrows;i++){ bitstring_free(sat->p[i]); } free(sat->p); free(sat); } /* Reallocation function, to scale up or to downsize a matrix */ void satmat_resize_rows(satmat_t* sat, size_t nbrows) { size_t i; if (nbrows > sat->_maxrows){ sat->p = (bitstring_t**)realloc(sat->p, nbrows * sizeof(bitstring_t*)); for (i=sat->nbrows; ip[i] = bitstring_alloc(sat->nbcolumns); } } else if (nbrows < sat->_maxrows){ for (i=nbrows; i_maxrows; i++){ bitstring_free(sat->p[i]); } sat->p = (bitstring_t**)realloc(sat->p,nbrows * sizeof(bitstring_t*)); } sat->nbrows = nbrows; sat->_maxrows = nbrows; } /* Reallocation function, to scale up or to downsize a matrix */ void satmat_resize_cols(satmat_t* sat, size_t nbcols) { size_t i,j; if (nbcols!=sat->nbcolumns){ for (i=0; i_maxrows; i++){ sat->p[i] = bitstring_realloc(sat->p[i],nbcols); for (j=sat->nbcolumns; jp[i][j] = 0; } } sat->nbcolumns = nbcols; } } /* Create a copy of the matrix of size nbrows (and not _maxrows) and extends columns. Only ``used'' rows are copied. */ satmat_t* satmat_copy_resize_cols(satmat_t* sat, size_t nbcols) { size_t i,j; satmat_t* nsat; assert(nbcols>=sat->nbcolumns); nsat = satmat_alloc(sat->nbrows,nbcols); for (i=0; inbrows; i++){ for (j=0; jnbcolumns; j++){ nsat->p[i][j] = sat->p[i][j]; } for (j=sat->nbcolumns; jp[i][j] = 0; } return nsat; } /* Create a copy of the matrix of size nbrows (and not _maxrows). Only ``used'' rows are copied. */ satmat_t* satmat_copy(satmat_t* sat) { size_t i,j; satmat_t* nsat = satmat_alloc(sat->nbrows,sat->nbcolumns); for (i=0; inbrows; i++){ for (j=0; jnbcolumns; j++){ nsat->p[i][j] = sat->p[i][j]; } } return nsat; } /* Raw printing function. */ void satmat_fprint(FILE* stream, satmat_t* sat) { size_t i; fprintf(stream,"%lu %lu\n", (unsigned long)sat->nbrows,(unsigned long)sat->nbcolumns); for (i=0; inbrows; i++){ bitstring_fprint(stream,sat->p[i],sat->nbcolumns); fprintf(stream,"\n"); } } void satmat_print(satmat_t* sat) { satmat_fprint(stdout,sat); } /* ********************************************************************** */ /* II. Bit operations */ /* ********************************************************************** */ /* These function allow to read and to clear or set individual bits. i indicates the row and jx the column. */ bitstring_t satmat_get(satmat_t* sat, size_t i, bitindex_t jx){ return bitstring_get(sat->p[i],jx); } void satmat_set(satmat_t* sat, size_t i, bitindex_t jx){ bitstring_set(sat->p[i],jx); } void satmat_clr(satmat_t* sat, size_t i, bitindex_t jx){ bitstring_clr(sat->p[i],jx); } /* ********************************************************************** */ /* III. Matrix operations */ /* ********************************************************************** */ /* Transposition. nbcols indicates the number of bits to be transposed (the number of columns of the matrix is the size of the row of bitstring_t, not the number of bits really used). */ satmat_t* satmat_transpose(satmat_t* org, size_t nbcols) { bitindex_t i,j; satmat_t* dest = satmat_alloc(nbcols,bitindex_size(org->nbrows)); for (i = bitindex_init(0); i.index < org->nbrows; bitindex_inc(&i) ) { for (j = bitindex_init(0); j.index < nbcols; bitindex_inc(&j) ){ if (satmat_get(org,i.index,j)) satmat_set(dest,j.index,i); } } return dest; } /* Row exchange. */ void satmat_exch_rows(satmat_t* sat, size_t l1, size_t l2) { bitstring_t* aux=sat->p[l1]; sat->p[l1]=sat->p[l2]; sat->p[l2]=aux; } void satmat_move_rows(satmat_t* sat, size_t destrow, size_t orgrow, size_t size) { int i,offset; offset = destrow-orgrow; if (offset>0){ assert(destrow+size<=sat->_maxrows); for (i=(int)(destrow+size)-1; i>=(int)destrow; i--){ satmat_exch_rows(sat,(size_t)i,(size_t)(i-offset)); } } else { assert(orgrow+size<=sat->_maxrows); for(i=(int)destrow; i<(int)(destrow+size); i++){ satmat_exch_rows(sat,(size_t)i,(size_t)(i-offset)); } } } apron-dist-0.9.10/apron/newpolka/mlexample.ml0000640014525101416610000001332311251675305021031 0ustar bjeannetpopart(* This file is part of the APRON Library, released under LGPL license. (use of PPL) Please read the COPYING file packaged in the distribution. *) (* with default setting (if dynamic libraries): ocaml -I $MLGMPIDL_INSTALL/lib -I $APRON_INSTALL/lib #load "bigarray.cma";; #load "gmp.cma";; #load "apron.cma";; #load "polkaMPQ.cma";; #install_printer Apron.Linexpr1.print;; #install_printer Apron.Texpr1.print;; #install_printer Apron.Lincons1.print;; #install_printer Apron.Generator1.print;; #install_printer Apron.Abstract1.print;; let environment_print fmt x = Apron.Environment.print fmt x;; let lincons1_array_print fmt x = Apron.Lincons1.array_print fmt x;; let generator1_array_print fmt x = Apron.Generator1.array_print fmt x;; #install_printer Apron.Var.print;; #install_printer environment_print;; #install_printer lincons1_array_print;; #install_printer generator1_array_print;; *) open Apron;; open Mpqf;; open Format;; let print_array = Abstract0.print_array;; let lincons1_array_print fmt x = Lincons1.array_print fmt x ;; let generator1_array_print fmt x = Generator1.array_print fmt x ;; let man = Polka.manager_alloc_loose ();; let var_x = Var.of_string "x";; let var_y = Var.of_string "y";; let var_z = Var.of_string "z";; let var_w = Var.of_string "w";; let var_u = Var.of_string "u";; let var_v = Var.of_string "v";; let var_a = Var.of_string "a";; let var_b = Var.of_string "b";; let ex1 (man:'a Manager.t) : 'a Abstract1.t = printf "Using Library: %s, version %s@." (Manager.get_library man) (Manager.get_version man); let env = Environment.make [|var_x; var_y; var_z; var_w|] [|var_u; var_v; var_a; var_b|] in let env2 = Environment.make [|var_x; var_y; var_z; var_w|] [||] in printf "env=%a@.env2=%a@." (fun x -> Environment.print x) env (fun x -> Environment.print x) env2 ; (* Creation of abstract value 1/2x+2/3y=1, [1,2]<=z+2w<=4, 0<=u<=5 *) let tab = Parser.lincons1_of_lstring env ["1/2x+2/3y=1"; "[1;2]<=z+2w";"z+2w<=4"; "0<=u";"u<=5"] in printf "tab = %a@." lincons1_array_print tab; let abs = Abstract1.of_lincons_array man env tab in printf "abs=%a@." Abstract1.print abs; (* Extraction (we first extract values for existing constraints, then for dimensions) *) let box = Abstract1.to_box man abs in printf "box=%a@." (print_array Interval.print) box.Abstract1.interval_array; for i=0 to 4 do let expr = Lincons1.get_linexpr1 (Lincons1.array_get tab i) in let box = Abstract1.bound_linexpr man abs expr in printf "Bound of %a = %a@." Linexpr1.print expr Interval.print box; done; (* 2. dimensions *) (* 3. of box *) let abs2 = Abstract1.of_box man env [|var_x; var_y; var_z; var_w; var_u; var_v; var_a; var_b|] box.Abstract1.interval_array in printf "abs2=%a@." Abstract1.print abs2; (* 4. Tests top and bottom *) let abs3 = Abstract1.bottom man env in printf "abs3=%a@.is_bottom(abs3)=%b@." Abstract1.print abs3 (Abstract1.is_bottom man abs3); printf "abs=%a@." Abstract1.print abs; let p2 = Abstract1.expand man abs var_y [|Var.of_string "y1"; Var.of_string "y2"|] in printf "p2=expand(abs,y,[y1,y2]))=%a@." Abstract1.print p2; let p2 = Abstract1.expand man abs var_u [|Var.of_string "u1"; Var.of_string "u2"|] in printf "p2=expand(abs,u,[u1,u2]))=%a@." Abstract1.print p2; (* Tree expressions *) let texpr = Parser.texpr1_of_string env "a + (x*y*y/sqrt(b))" in let abs2 = Abstract1.assign_texpr man abs var_u texpr None in printf "abs2=%a@." Abstract1.print abs2; abs ;; let ex2 (man:'a Manager.t) = let env = Environment.make [||] [|var_x; var_y; var_z|] in (* Creation of abstract value 5<=x<=14, 4<=y<=12, z=0 *) let abs1 = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int 5 14; Interval.of_int 4 12; Interval.of_int 0 0; |] in let abs2 = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int 3 12; Interval.of_int 5 13; Interval.of_int 1 1; |] in let abs3 = Abstract1.join man abs1 abs2 in abs3 ;; (* Comparing join of two different assignements and assignement by the "join" of expressions *) let ex3 (man:'a Manager.t) = let env = Environment.make [||] [|var_x; var_y; var_z|] in (* Creation of abstract value -3<=x<=-2, 10<=y<=12, -1<=z<=1 *) let abs = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int (-3) (-2); Interval.of_int 10 12; Interval.of_int (-1) (1) |] in (* Creation of linear expressions *) let linexpr1 = Parser.linexpr1_of_string env "z+x+2y" in let linexpr2 = Parser.linexpr1_of_string env "z+2x+y" in let abs1 = Abstract1.assign_linexpr man abs var_z linexpr1 None in let abs2 = Abstract1.assign_linexpr man abs var_z linexpr2 None in let res1 = Abstract1.join man abs1 abs2 in printf "abs=%a@.abs1=%a@.abs2=%a@.res1=%a@." Abstract1.print abs Abstract1.print abs1 Abstract1.print abs2 Abstract1.print res1; (* Creation of linear expression [1,2]y and [1,2]z *) let linexpr = Parser.linexpr1_of_string env "z + [1;2]x + [1;2]y" in let res2 = Abstract1.assign_linexpr man abs var_z linexpr None in printf "res2=%a@." Abstract1.print res2 ; let abs1 = Abstract1.substitute_linexpr man res1 var_z linexpr1 None in let abs2 = Abstract1.substitute_linexpr man res1 var_z linexpr2 None in let res1 = Abstract1.join man abs1 abs2 in printf "abs1=%a@.abs2=%a@.res1=%a@." Abstract1.print abs1 Abstract1.print abs2 Abstract1.print res1 ; let res2 = Abstract1.substitute_linexpr man res2 var_z linexpr None in printf "res2=%a@." Abstract1.print res2 ; res1 ;; let abs1 = ex1 man;; let abs2 = ex2 man;; let abs3 = ex3 man;; apron-dist-0.9.10/apron/newpolka/pk_user.c0000640014525101416610000003566511251675651020350 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_user.c: conversions with interface datatypes */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "pk_config.h" #include "pk_vector.h" #include "pk_matrix.h" #include "pk_internal.h" #include "pk_user.h" #include "itv_linearize.h" static void ap_coeff_set_scalar_numint(ap_coeff_t* coeff, numint_t num){ ap_coeff_reinit(coeff,AP_COEFF_SCALAR,AP_SCALAR_MPQ); mpq_set_numint(coeff->val.scalar->val.mpq,num); } /* ********************************************************************** */ /* From ITV to PK */ /* ********************************************************************** */ /* Fills the vector with the constraint: dim <= num if sgn>0, dim = num if sgn=0 dim >= -num if sgn<0 (an inferior bound is implicitly negated, as in itv). Returns false if equality of an integer dimension with a non-integer numbers */ bool vector_set_dim_bound(pk_internal_t* pk, numint_t* vec, ap_dim_t dim, numrat_t numrat, int mode, size_t intdim, size_t realdim, bool integer) { numrat_t bound; size_t size; size = pk->dec+intdim+realdim; numrat_init(bound); if (integer && dim0){ numint_fdiv_q(numrat_numref(bound), numrat_numref(numrat),numrat_denref(numrat)); numint_set_int(numrat_denref(bound),1); } else if (mode<0){ numint_cdiv_q(numrat_numref(bound), numrat_numref(numrat),numrat_denref(numrat)); numint_set_int(numrat_denref(bound),1); } else { if (numint_cmp_int(numrat_denref(numrat),1)!=0){ numrat_clear(bound); return false; } } } else { numrat_set(bound,numrat); } /* Write the constraint num + den*x >= 0 */ vector_clear(vec,size); numint_set_int(vec[0], (mode ? 1 : 0)); numint_set(vec[polka_cst],numrat_numref(bound)); numint_set(vec[pk->dec+dim],numrat_denref(bound)); numrat_clear(bound); /* put the right sign now */ if (mode>=0){ numint_neg(vec[pk->dec+dim],vec[pk->dec+dim]); } return true; } /* Fills the vector with the constraint: expr <= bound if sgn>0, expr = bound if sgn=0 expr >= -bound if sgn<0 (an inferior bound is implicitly negated, as in itv). Returns false if equality with a non-integer numbers (like 2x=1). */ bool vector_set_linexpr_bound(pk_internal_t* pk, numint_t* vec, numint_t* vec2, numrat_t numrat, int mode, size_t intdim, size_t realdim, bool integer) { size_t i; size_t size; numint_t cst; assert (numint_sgn(numrat_denref(numrat))); size = pk->dec+intdim+realdim; if (vec!=vec2){ vector_copy(vec,vec2,size); } if (numint_cmp_int(numrat_denref(numrat),1) != 0){ for (i=1; i=0){ numint_sub(vec[polka_cst],vec[polka_cst],cst); for (i=pk->dec; i=0){ assert(!bound_infty(expr->cst->sup)); if (bound_sgn(expr->cst->sup)) numint_set(vec[0], numrat_denref(bound_numref(expr->cst->sup))); else numint_set_int(vec[0],1); } else { assert(!bound_infty(expr->cst->inf)); if (bound_sgn(expr->cst->inf)) numint_set(vec[0], numrat_denref(bound_numref(expr->cst->inf))); else numint_set_int(vec[0],1); } itv_linexpr_ForeachLinterm(expr,i,d,pitv,peq){ assert(*peq); numint_lcm(vec[0],vec[0],numrat_denref(bound_numref(pitv->sup))); } /* Fill the vector */ if (pk->strict) numint_set_int(vec[polka_eps],0); /* constant coefficient */ if (mode>=0){ numint_divexact(vec[polka_cst], vec[0], numrat_denref(bound_numref(expr->cst->sup))); numint_mul(vec[polka_cst], vec[polka_cst], numrat_numref(bound_numref(expr->cst->sup))); } else { numint_divexact(vec[polka_cst], vec[0], numrat_denref(bound_numref(expr->cst->inf))); numint_mul(vec[polka_cst], vec[polka_cst], numrat_numref(bound_numref(expr->cst->inf))); numint_neg(vec[polka_cst],vec[polka_cst]); } /* Other coefficients */ for (i=pk->dec;idec+dim; i++){ numint_set_int(vec[i],0); } itv_linexpr_ForeachLinterm(expr,i,d,pitv,peq){ size_t index = pk->dec + d; numint_divexact(vec[index],vec[0],numrat_denref(bound_numref(pitv->sup))); numint_mul(vec[index],vec[index],numrat_numref(bound_numref(pitv->sup))); } return; } /* Fills the vector(s) with the fully linear constraint cons */ void vector_set_itv_lincons(pk_internal_t* pk, numint_t* vec, itv_lincons_t* cons, size_t intdim, size_t realdim, bool integer) { size_t i,nb; assert(cons->constyp == AP_CONS_EQ || cons->constyp == AP_CONS_SUPEQ || cons->constyp == AP_CONS_SUP); assert(itv_linexpr_is_scalar(&cons->linexpr)); vector_set_itv_linexpr(pk, vec, &cons->linexpr, intdim+realdim,1); vector_normalize(pk,vec,pk->dec+intdim+realdim); if (cons->constyp == AP_CONS_EQ){ numint_set_int(vec[0],0); } else { numint_set_int(vec[0],1); } if (cons->constyp == AP_CONS_SUP){ if (pk->strict){ numint_set_int(vec[polka_eps],-1); } else if (integer && vector_is_integer(pk, vec, intdim, realdim)){ numint_sub_uint(vec[polka_cst], vec[polka_cst], 1); } } if (integer) vector_normalize_constraint_int(pk,vec,intdim,realdim); } /* Fills the vector(s) with the fully linear constraint cons for testing satisfiability. Returns false if unsatisfiable */ bool vector_set_itv_lincons_sat(pk_internal_t* pk, numint_t* vec, itv_lincons_t* cons, size_t intdim, size_t realdim, bool integer) { bool sat; size_t i; if (cons->constyp == AP_CONS_EQ && cons->linexpr.equality != true){ return false; } assert(cons->constyp == AP_CONS_EQ || cons->constyp == AP_CONS_SUPEQ || cons->constyp == AP_CONS_SUP); if (!bound_infty(cons->linexpr.cst->inf)){ vector_set_itv_linexpr(pk, vec, &cons->linexpr, intdim+realdim,-1); vector_normalize(pk,vec,pk->dec+intdim+realdim); if (cons->constyp == AP_CONS_EQ && cons->linexpr.equality){ numint_set_int(vec[0],0); } else { numint_set_int(vec[0],1); } if (cons->constyp == AP_CONS_SUP){ if (pk->strict){ numint_set_int(vec[polka_eps],-1); } else if (integer && vector_is_integer(pk, vec, intdim, realdim)){ numint_sub_uint(vec[polka_cst], vec[polka_cst], 1); } } if (integer) vector_normalize_constraint_int(pk,vec,intdim,realdim); return true; } else { return false; } } /* ********************************************************************** */ /* From APRON to PK */ /* ********************************************************************** */ /* Fills the vector with the generator gen. */ bool vector_set_ap_generator0(pk_internal_t* pk, numint_t* vec, ap_generator0_t* gen, size_t intdim, size_t realdim) { assert(gen->gentyp != AP_GEN_VERTEX); itv_linexpr_set_ap_linexpr0(pk->itv, &pk->poly_itv_linexpr, gen->linexpr0); vector_set_itv_linexpr(pk, vec, &pk->poly_itv_linexpr, intdim+realdim, +1); if (pk->strict) numint_set_int(vec[polka_eps],0); numint_set_int(vec[0], ( ((gen->gentyp == AP_GEN_LINE) || (gen->gentyp == AP_GEN_LINEMOD)) ? 0 : 1 )); if (gen->gentyp != AP_GEN_VERTEX){ numint_set_int(vec[polka_cst],0); vector_normalize(pk,vec, pk->dec + intdim + realdim); } switch (gen->gentyp){ case AP_GEN_VERTEX: case AP_GEN_RAY: case AP_GEN_LINE: return true; default: return false; } } static bool matrix_append_ap_generator0_array(pk_internal_t* pk, matrix_t* mat, ap_generator0_array_t* array, size_t intdim, size_t realdim) { bool res,exact; size_t i,nbrows; nbrows = mat->nbrows; matrix_resize_rows_lazy(mat,nbrows+array->size); res = true; for (i=0; isize; i++){ exact = vector_set_ap_generator0(pk,mat->p[nbrows+i],&array->p[i],intdim,realdim); res = res && exact; } return res; } bool matrix_set_ap_generator0_array(pk_internal_t* pk, matrix_t** matrix, ap_generator0_array_t* array, size_t intdim, size_t realdim) { *matrix = matrix_alloc(array->size,pk->dec+intdim+realdim,false); (*matrix)->nbrows = 0; return matrix_append_ap_generator0_array(pk,*matrix,array,intdim,realdim); } /* static bool matrix_append_ap_lincons0_array(pk_internal_t* pk, matrix_t* mat, size_t** tabindex, size_t* size, ap_lincons0_array_t* array, size_t intdim, size_t realdim, bool integer) { bool exact,res; size_t nbrows,i,j,k; size_t* tab; nbrows = mat->nbrows; matrix_resize_rows_lazy(mat,nbrows+2*array->size); res = true; tab = NULL; j = nbrows; k = 0; for (i=0; isize; i++){ if (ap_lincons0_is_unsat(&array->p[i])){ if (tab){ free(tab); tab=NULL; k=0; } vector_clear(mat->p[0],mat->nbcolumns); numint_set_int(mat->p[0][0],1); numint_set_int(mat->p[0][polka_cst],-1); j = 1; res = true; break; } switch (array->p[i].constyp){ case AP_CONS_EQ: case AP_CONS_SUPEQ: case AP_CONS_SUP: if (ap_linexpr0_is_quasilinear(array->p[i].linexpr0)){ exact = itv_lincons_set_ap_lincons0(pk->itv, &pk->poly_itv_lincons, &array->p[i]); res = res && exact; j += vector_set_itv_lincons(pk, &mat->p[j], &pk->poly_itv_lincons, intdim,realdim,integer); } else { if (tab==NULL){ tab = (size_t*)malloc(array->size*sizeof(size_t)); } tab[k] = i; k++; } break; default: res = false; break; } } mat->nbrows = j; if (tab){ tab = (size_t*)realloc(tab,k*sizeof(size_t)); } *tabindex = tab; *size = k; return res; } bool matrix_set_ap_lincons0_array(pk_internal_t* pk, matrix_t** mat, size_t** tabindex, size_t* size, ap_lincons0_array_t* array, size_t intdim, size_t realdim, bool integer) { *mat = matrix_alloc(2*array->size,pk->dec+intdim+realdim,false); (*mat)->nbrows = 0; return matrix_append_ap_lincons0_array(pk, *mat, tabindex,size, array, intdim,realdim,integer); } static bool matrix_append_ap_intlincons0_array(pk_internal_t* pk, matrix_t* mat, itv_t* titv, ap_lincons0_array_t* array, size_t* tab, size_t size, size_t intdim, size_t realdim, bool integer) { bool exact; size_t nbrows,i,j; nbrows = mat->nbrows; matrix_resize_rows_lazy(mat,nbrows+2*array->size); exact = true; j = nbrows; for (i=0; iitv, &pk->poly_itv_lincons, &array->p[index]) && exact; exact = itv_quasilinearize_lincons(pk->itv,&pk->poly_itv_lincons,titv,true) && exact; j += vector_set_itv_lincons(pk,&mat->p[j],&pk->poly_itv_lincons, intdim,realdim,integer); } mat->nbrows = j; return exact; } bool matrix_set_ap_intlincons0_array(pk_internal_t* pk, matrix_t** mat, itv_t* titv, ap_lincons0_array_t* array, size_t* tab, size_t size, size_t intdim, size_t realdim, bool integer) { *mat = matrix_alloc(2*array->size,pk->dec+intdim+realdim,false); (*mat)->nbrows = 0; return matrix_append_ap_intlincons0_array(pk, *mat, titv, array,tab,size, intdim,realdim,integer); } */ static bool matrix_append_itv_lincons_array(pk_internal_t* pk, matrix_t* mat, itv_lincons_array_t* array, size_t intdim, size_t realdim, bool integer) { bool exact,res; size_t nbrows,i,j; size_t* tab; nbrows = mat->nbrows; matrix_resize_rows_lazy(mat,nbrows+array->size); res = true; j = nbrows; for (i=0; isize; i++){ assert(itv_linexpr_is_scalar(&array->p[i].linexpr)); switch (array->p[i].constyp){ case AP_CONS_EQ: case AP_CONS_SUPEQ: case AP_CONS_SUP: vector_set_itv_lincons(pk, mat->p[j], &array->p[i], intdim,realdim,integer); j++; break; default: res = false; break; } } mat->nbrows = j; return res; } bool matrix_set_itv_lincons_array(pk_internal_t* pk, matrix_t** mat, itv_lincons_array_t* array, size_t intdim, size_t realdim, bool integer) { *mat = matrix_alloc(array->size,pk->dec+intdim+realdim,false); (*mat)->nbrows = 0; return matrix_append_itv_lincons_array(pk, *mat,array, intdim,realdim,integer); } /* ********************************************************************** */ /* From PK to APRON */ /* ********************************************************************** */ ap_lincons0_t lincons0_of_vector(pk_internal_t* pk, numint_t* q, size_t size) { ap_lincons0_t lincons; ap_linexpr0_t* linexpr; size_t i; linexpr = ap_linexpr0_alloc(AP_LINEXPR_DENSE, size - pk->dec); ap_coeff_set_scalar_numint(&linexpr->cst, q[polka_cst]); for (i=pk->dec; idec; ap_coeff_set_scalar_numint(&linexpr->p.coeff[dim], q[i]); } if (numint_sgn(q[0])){ if (pk->strict && numint_sgn(q[polka_eps])<0) lincons.constyp = AP_CONS_SUP; else lincons.constyp = AP_CONS_SUPEQ; } else { lincons.constyp = AP_CONS_EQ; } lincons.linexpr0 = linexpr; lincons.scalar = NULL; return lincons; } ap_generator0_t generator0_of_vector(pk_internal_t* pk, numint_t* q, size_t size) { ap_generator0_t generator; ap_linexpr0_t* linexpr; size_t i; int sgn; linexpr = ap_linexpr0_alloc(AP_LINEXPR_DENSE, size - pk->dec); ap_coeff_set_scalar_int(&linexpr->cst, 0); sgn = numint_sgn(q[polka_cst]); for (i=pk->dec; idec; ap_coeff_set_scalar_numint(&linexpr->p.coeff[dim],q[i]); if (sgn){ mpz_set_numint(mpq_denref(linexpr->p.coeff[dim].val.scalar->val.mpq), q[polka_cst]); mpq_canonicalize(linexpr->p.coeff[dim].val.scalar->val.mpq); } } if (!numint_sgn(q[0])){ generator.gentyp = AP_GEN_LINE; } else if (sgn==0){ generator.gentyp = AP_GEN_RAY; } else { generator.gentyp = AP_GEN_VERTEX; } generator.linexpr0 = linexpr; return generator; } apron-dist-0.9.10/apron/newpolka/pk_constructor.c0000640014525101416610000001535511247462105021742 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_constructor.c: constructors and accessors */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "pk_config.h" #include "pk_vector.h" #include "pk_satmat.h" #include "pk_matrix.h" #include "pk.h" #include "pk_user.h" #include "pk_representation.h" #include "pk_constructor.h" #include "pk_meetjoin.h" #include "itv.h" #include "itv_linexpr.h" #include "ap_generic.h" /* ********************************************************************** */ /* I. Constructors */ /* ********************************************************************** */ /* ====================================================================== */ /* Empty polyhedron */ /* ====================================================================== */ void poly_set_bottom(pk_internal_t* pk, pk_t* po) { if (po->C) matrix_free(po->C); if (po->F) matrix_free(po->F); if (po->satC) satmat_free(po->satC); if (po->satF) satmat_free(po->satF); po->C = po->F = NULL; po->satC = po->satF = NULL; po->status = pk_status_conseps | pk_status_minimaleps; po->nbeq = po->nbline = 0; } /* The empty polyhedron is just defined by the absence of both constraints matrix and frames matrix. */ pk_t* pk_bottom(ap_manager_t* man, size_t intdim, size_t realdim) { pk_t* po = poly_alloc(intdim,realdim); pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_BOTTOM); pk_internal_realloc_lazy(pk,intdim+realdim); po->status = pk_status_conseps | pk_status_minimaleps; man->result.flag_exact = man->result.flag_best = true; return po; } /* ====================================================================== */ /* Universe polyhedron */ /* ====================================================================== */ void matrix_fill_constraint_top(pk_internal_t* pk, matrix_t* C, size_t start) { if (pk->strict){ /* constraints epsilon and xi-epsilon*/ vector_clear(C->p[start+0],C->nbcolumns); vector_clear(C->p[start+1],C->nbcolumns); numint_set_int(C->p[start+0][0],1); numint_set_int(C->p[start+0][polka_eps],1); numint_set_int(C->p[start+1][0],1); numint_set_int(C->p[start+1][polka_cst],1); numint_set_int(C->p[start+1][polka_eps],(-1)); } else { /* constraint \xi \geq 0 */ vector_clear(C->p[start+0],C->nbcolumns); numint_set_int(C->p[start+0][0],1); numint_set_int(C->p[start+0][polka_cst],1); } } void poly_set_top(pk_internal_t* pk, pk_t* po) { size_t i; size_t dim; if (po->C) matrix_free(po->C); if (po->F) matrix_free(po->F); if (po->satC) satmat_free(po->satC); if (po->satF) satmat_free(po->satF); po->status = pk_status_conseps | pk_status_consgauss | pk_status_gengauss | pk_status_minimaleps ; dim = po->intdim + po->realdim; po->C = matrix_alloc(pk->dec-1, pk->dec+dim,true); po->F = matrix_alloc(pk->dec+dim-1,pk->dec+dim,true); /* We have to ensure that the matrices are really sorted */ po->satC = satmat_alloc(pk->dec+dim-1,bitindex_size(pk->dec-1)); po->satF = 0; po->nbeq = 0; po->nbline = dim; /* constraints */ matrix_fill_constraint_top(pk,po->C,0); /* generators */ /* lines $x_i$ */ for(i=0; iF->p[i][pk->dec+dim-1-i],1); } if (pk->strict){ /* rays xi and xi+epsilon */ numint_set_int(po->F->p[dim][0],1); numint_set_int(po->F->p[dim][polka_cst],1); numint_set_int(po->F->p[dim+1][0],1); numint_set_int(po->F->p[dim+1][polka_cst],1); numint_set_int(po->F->p[dim+1][polka_eps],1); /* saturation matrix */ po->satC->p[dim][0] = bitstring_msb >> 1; po->satC->p[dim+1][0] = bitstring_msb; } else { /* ray xi */ numint_set_int(po->F->p[dim][0],1); numint_set_int(po->F->p[dim][polka_cst],1); /* saturation matrix */ po->satC->p[dim][0] = bitstring_msb; } assert(poly_check(pk,po)); } pk_t* pk_top(ap_manager_t* man, size_t intdim, size_t realdim) { pk_t* po; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_TOP); pk_internal_realloc_lazy(pk,intdim+realdim); po = poly_alloc(intdim,realdim); poly_set_top(pk,po); man->result.flag_exact = man->result.flag_best = true; return po; } /* ====================================================================== */ /* Hypercube polyhedron */ /* ====================================================================== */ /* The matrix is supposed to be big enough */ static int matrix_fill_constraint_box(pk_internal_t* pk, matrix_t* C, size_t start, ap_interval_t** box, size_t intdim, size_t realdim, bool integer) { size_t k; ap_dim_t i; bool ok; itv_t itv; k = start; itv_init(itv); for (i=0; iitv,itv,box[i]); if (itv_is_point(pk->itv,itv)){ ok = vector_set_dim_bound(pk,C->p[k], (ap_dim_t)i, bound_numref(itv->sup), 0, intdim,realdim, integer); if (!ok){ itv_clear(itv); return -1; } k++; } else { /* inferior bound */ if (!bound_infty(itv->inf)){ vector_set_dim_bound(pk,C->p[k], (ap_dim_t)i, bound_numref(itv->inf), -1, intdim,realdim, integer); k++; } /* superior bound */ if (!bound_infty(itv->sup)){ vector_set_dim_bound(pk,C->p[k], (ap_dim_t)i, bound_numref(itv->sup), 1, intdim,realdim, integer); k++; } } } itv_clear(itv); return (int)k; } /* Abstract an hypercube defined by the array of intervals of size intdim+realdim. */ pk_t* pk_of_box(ap_manager_t* man, size_t intdim, size_t realdim, ap_interval_t** array) { int k; size_t dim; pk_t* po; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_OF_BOX); pk_internal_realloc_lazy(pk,intdim+realdim); dim = intdim + realdim; po = poly_alloc(intdim,realdim); po->status = pk_status_conseps; dim = intdim + realdim; po->C = matrix_alloc(pk->dec-1 + 2*dim, pk->dec + dim, false); /* constraints */ matrix_fill_constraint_top(pk,po->C,0); k = matrix_fill_constraint_box(pk,po->C,pk->dec-1,array,intdim,realdim,true); if (k==-1){ matrix_free(po->C); po->C = NULL; return po; } po->C->nbrows = (size_t)k; assert(poly_check(pk,po)); man->result.flag_exact = man->result.flag_best = true; return po; } /* ********************************************************************** */ /* II. Accessors */ /* ********************************************************************** */ /* Return the dimensions of the polyhedra */ ap_dimension_t pk_dimension(ap_manager_t* man, pk_t* po){ ap_dimension_t res; res.intdim = po->intdim; res.realdim = po->realdim; return res; } apron-dist-0.9.10/apron/newpolka/pk_extract.c0000640014525101416610000003225310723557216021031 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_extract.c: property extraction */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "pk_config.h" #include "pk_vector.h" #include "pk_satmat.h" #include "pk_matrix.h" #include "pk.h" #include "pk_user.h" #include "pk_representation.h" #include "pk_extract.h" #include "ap_generic.h" #include "itv_linearize.h" /* Bounding the value of a dimension in a matrix of generators. */ void matrix_bound_dimension(pk_internal_t* pk, itv_t itv, ap_dim_t dim, matrix_t* F) { size_t i, index; int sgn; assert(pk->dec+dimnbcolumns); bound_set_infty(itv->inf,-1); bound_set_infty(itv->sup,-1); index = pk->dec+dim; for (i=0; inbrows; i++){ if (!pk->strict || numint_sgn(F->p[i][polka_eps])==0){ sgn = numint_sgn(F->p[i][index]); if (numint_sgn(F->p[i][0])==0){ /* line: result should be zero */ if (sgn){ itv_set_top(itv); return; } } else if (numint_sgn(F->p[i][polka_cst])==0){ /* ray */ if (sgn > 0){ bound_set_infty(itv->sup,+1); if (bound_infty(itv->inf) && bound_sgn(itv->inf)>0) return; } else if (sgn < 0){ bound_set_infty(itv->inf,+1); if (bound_infty(itv->sup) && bound_sgn(itv->sup)>0) return; } } else { /* point */ numrat_set_numint2(pk->poly_numrat, F->p[i][index], F->p[i][polka_cst]); if (bound_cmp_num(itv->sup,pk->poly_numrat)<0){ bound_set_num(itv->sup,pk->poly_numrat); } numrat_neg(pk->poly_numrat,pk->poly_numrat); if (bound_cmp_num(itv->inf,pk->poly_numrat)<0){ bound_set_num(itv->inf,pk->poly_numrat); } } } } } itv_t* matrix_to_box(pk_internal_t* pk, matrix_t* F) { size_t i,dim; itv_t* res; assert(F); assert(F->nbcolumns>=pk->dec); dim = F->nbcolumns - pk->dec; res = itv_array_alloc(dim); for (i=0;inbcolumns. */ void matrix_bound_vector(pk_internal_t* pk, itv_t itv, numint_t* vec, matrix_t* F) { size_t i; int sgn; bound_set_infty(itv->inf,-1); bound_set_infty(itv->sup,-1); for (i=0; inbrows; i++){ if (!pk->strict || numint_sgn(F->p[i][polka_eps])==0 ){ vector_product_strict(pk, pk->poly_prod, F->p[i], vec, F->nbcolumns); sgn = numint_sgn(pk->poly_prod); if (numint_sgn(F->p[i][0])==0){ /* line: result should be zero */ if (sgn){ itv_set_top(itv); return; } } else if (numint_sgn(F->p[i][polka_cst])==0){ /* ray */ if (sgn > 0){ bound_set_infty(itv->sup,+1); if (bound_infty(itv->inf) && bound_sgn(itv->inf)>0) return; } else if (sgn < 0){ bound_set_infty(itv->inf,+1); if (bound_infty(itv->sup) && bound_sgn(itv->sup)>0) return; } } else { /* point */ numrat_set_numint2(pk->poly_numrat, pk->poly_prod, F->p[i][polka_cst]); if (bound_cmp_num(itv->sup,pk->poly_numrat)<0){ bound_set_num(itv->sup,pk->poly_numrat); } numrat_neg(pk->poly_numrat,pk->poly_numrat); if (bound_cmp_num(itv->inf,pk->poly_numrat)<0){ bound_set_num(itv->inf,pk->poly_numrat); } } } } if (!bound_infty(itv->inf)){ numint_mul(numrat_denref(bound_numref(itv->inf)), numrat_denref(bound_numref(itv->inf)), vec[0]); numrat_canonicalize(bound_numref(itv->inf)); } if (!bound_infty(itv->sup)){ numint_mul(numrat_denref(bound_numref(itv->sup)), numrat_denref(bound_numref(itv->sup)), vec[0]); numrat_canonicalize(bound_numref(itv->sup)); } } /* Bounding the value of an (interval) linear expression (itv_linexpr) in a generator vector */ static void vector_bound_itv_linexpr(pk_internal_t* pk, itv_t itv, itv_linexpr_t* linexpr, numint_t* vec, size_t size) { size_t i,dim; bool *peq; itv_ptr pitv; itv_ptr prod; numrat_t* rat; prod = pk->poly_itv; rat = &pk->poly_numrat; numrat_set_int(*rat,1); itv_set_int(itv,0); itv_linexpr_ForeachLinterm(linexpr,i,dim,pitv,peq){ size_t index = pk->dec + dim; if (numint_sgn(vec[index])){ numint_set(numrat_numref(*rat),vec[index]); itv_mul_num(prod,pitv,*rat); itv_add(itv,itv,prod); } } if (numint_sgn(vec[polka_cst])){ numint_set(numrat_numref(*rat),vec[polka_cst]); itv_div_num(itv,itv,*rat); itv_add(itv,itv,linexpr->cst); } return; } /* Bounding the value of an (interval) linear expression (itv_linexpr) in a matrix of generators. */ static void matrix_bound_itv_linexpr(pk_internal_t* pk, itv_t itv, itv_linexpr_t* linexpr, matrix_t* F) { size_t i; int sgn; itv_t prod; bound_set_infty(itv->inf,-1); bound_set_infty(itv->sup,-1); itv_init(prod); for (i=0; inbrows; i++){ if (!pk->strict || numint_sgn(F->p[i][polka_eps])==0 ){ vector_bound_itv_linexpr(pk, prod, linexpr, F->p[i], F->nbcolumns); if (numint_sgn(F->p[i][0])==0){ /* line: result should be zero */ if (!itv_is_zero(prod)){ itv_set_top(itv); goto _matrix_bound_itv_linexpr_exit; } } else if (numint_sgn(F->p[i][polka_cst])==0){ /* ray */ if (!itv_is_zero(prod)){ if (bound_sgn(prod->inf)<0){ /* [inf,sup]>0 */ bound_set_infty(itv->sup,+1); if (bound_infty(itv->inf) && bound_sgn(itv->inf)>0) goto _matrix_bound_itv_linexpr_exit; } else if (bound_sgn(prod->sup)<0){ /* [inf,sup]<0 */ bound_set_infty(itv->inf,+1); if (bound_infty(itv->sup) && bound_sgn(itv->sup)>0) goto _matrix_bound_itv_linexpr_exit; } else { itv_set_top(itv); goto _matrix_bound_itv_linexpr_exit; } } } else { itv_join(itv,itv,prod); } } } _matrix_bound_itv_linexpr_exit: itv_clear(prod); return; } /* ====================================================================== */ /* Bounding the value of a dimension in a polyhedra */ /* ====================================================================== */ ap_interval_t* pk_bound_dimension(ap_manager_t* man, pk_t* po, ap_dim_t dim) { itv_t itv; ap_interval_t* interval; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_BOUND_DIMENSION); interval = ap_interval_alloc(); ap_interval_reinit(interval,AP_SCALAR_MPQ); if (pk->funopt->algorithm>0) poly_chernikova(man,po,NULL); else poly_obtain_F(man,po,NULL); if (pk->exn){ pk->exn = AP_EXC_NONE; ap_interval_set_top(interval); return interval; } if (!po->F){ /* po is empty */ ap_interval_set_bottom(interval); man->result.flag_exact = man->result.flag_best = true; return interval; } itv_init(itv); matrix_bound_dimension(pk,itv,dim,po->F); ap_interval_set_itv(pk->itv,interval, itv); itv_clear(itv); man->result.flag_exact = man->result.flag_best = dimintdim ? false : true; return interval; } /* ====================================================================== */ /* Bounding the value of a linear expression in a polyhedra */ /* ====================================================================== */ ap_interval_t* pk_bound_linexpr(ap_manager_t* man, pk_t* po, ap_linexpr0_t* expr) { bool exact; ap_interval_t* interval; itv_t itv; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_BOUND_LINEXPR); interval = ap_interval_alloc(); ap_interval_reinit(interval,AP_SCALAR_MPQ); if (pk->funopt->algorithm>0) poly_chernikova(man,po,NULL); else poly_obtain_F(man,po,NULL); if (pk->exn){ pk->exn = AP_EXC_NONE; ap_interval_set_top(interval); return interval; } if (!po->F){ /* po is empty */ ap_interval_set_bottom(interval); man->result.flag_exact = man->result.flag_best = true; return interval; } /* we fill the vector with the expression, taking lower bound of the interval constant */ exact = itv_linexpr_set_ap_linexpr0(pk->itv, &pk->poly_itv_linexpr, expr); itv_init(itv); matrix_bound_itv_linexpr(pk,itv,&pk->poly_itv_linexpr,po->F); ap_interval_set_itv(pk->itv,interval,itv); itv_clear(itv); man->result.flag_exact = man->result.flag_best = ( (pk->funopt->flag_exact_wanted || pk->funopt->flag_best_wanted) && ap_linexpr0_is_real(expr,po->intdim) ) ? exact : false; return interval; } ap_interval_t* pk_bound_texpr(ap_manager_t* man, pk_t* po, ap_texpr0_t* expr) { itv_t itv1,itv2; itv_t* env; ap_interval_t* interval; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_BOUND_TEXPR); interval = ap_interval_alloc(); ap_interval_reinit(interval,AP_SCALAR_MPQ); if (pk->funopt->algorithm>0) poly_chernikova(man,po,NULL); else poly_obtain_F(man,po,NULL); if (pk->exn){ pk->exn = AP_EXC_NONE; ap_interval_set_top(interval); return interval; } if (!po->F){ /* po is empty */ ap_interval_set_bottom(interval); man->result.flag_exact = man->result.flag_best = true; return interval; } env = matrix_to_box(pk,po->F); itv_intlinearize_ap_texpr0(pk->itv,&pk->poly_itv_linexpr, expr,env,po->intdim); itv_init(itv1); itv_init(itv2); matrix_bound_itv_linexpr(pk,itv1,&pk->poly_itv_linexpr,po->F); itv_eval_ap_texpr0(pk->itv,itv2,expr,env); itv_meet(pk->itv,itv1,itv1,itv2); ap_interval_set_itv(pk->itv,interval,itv1); itv_clear(itv1); itv_clear(itv2); itv_array_free(env,po->intdim+po->realdim); man->result.flag_exact = man->result.flag_best = ap_texpr0_is_interval_linear(expr); return interval; } /* ====================================================================== */ /* Converting to a set of constraints */ /* ====================================================================== */ ap_lincons0_array_t pk_to_lincons_array(ap_manager_t* man, pk_t* po) { ap_lincons0_array_t array; matrix_t* C; size_t i,k; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_TO_LINCONS_ARRAY); man->result.flag_exact = man->result.flag_best = true; poly_chernikova3(man,po,NULL); if (pk->exn){ pk->exn = AP_EXC_NONE; man->result.flag_exact = man->result.flag_best = false; array = ap_lincons0_array_make(0); return array; } if (!po->C){ /* po is empty */ array = ap_lincons0_array_make(1); array.p[0] = ap_lincons0_make_unsat(); return array; } poly_obtain_sorted_C(pk,po); C = po->C; array = ap_lincons0_array_make(C->nbrows); for (i=0,k=0; inbrows; i++){ if (! vector_is_dummy_constraint(pk, C->p[i], C->nbcolumns)){ array.p[k] = lincons0_of_vector(pk, C->p[i], C->nbcolumns); k++; } } array.size = k; return array; } ap_tcons0_array_t pk_to_tcons_array(ap_manager_t* man, pk_t* po) { return ap_generic_to_tcons_array(man,po); } /* ====================================================================== */ /* Converting to a box */ /* ====================================================================== */ ap_interval_t** pk_to_box(ap_manager_t* man, pk_t* po) { ap_interval_t** interval; itv_t* titv; size_t i,dim; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_TO_BOX); dim = po->intdim + po->realdim; if (pk->funopt->algorithm>=0) poly_chernikova(man,po,NULL); else poly_obtain_F(man,po,NULL); if (pk->exn){ pk->exn = AP_EXC_NONE; man->result.flag_exact = man->result.flag_best = false; interval = ap_interval_array_alloc(dim); for (i=0; iF){ for (i=0; iF); for (i=0; iitv,interval[i],titv[i]); } itv_array_free(titv,dim); } man->result.flag_exact = man->result.flag_best = true; return interval; } /* ====================================================================== */ /* Converting to a set of generators */ /* ====================================================================== */ /* The function returns the set of generators for the topological closure of the polyhedron. */ ap_generator0_array_t pk_to_generator_array(ap_manager_t* man, pk_t* po) { ap_generator0_array_t array; matrix_t* F; size_t i,k; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_TO_GENERATOR_ARRAY); man->result.flag_exact = man->result.flag_best = true; poly_chernikova3(man,po,NULL); if (pk->exn){ pk->exn = AP_EXC_NONE; man->result.flag_exact = man->result.flag_best = false; array = ap_generator0_array_make(0); return array; } if (!po->F){ /* po is empty */ array = ap_generator0_array_make(0); return array; } F = po->F; poly_obtain_sorted_F(pk,po); array = ap_generator0_array_make(F->nbrows); for (i=0,k=0; inbrows; i++){ if (! vector_is_dummy_or_strict_generator(pk, F->p[i], F->nbcolumns)){ array.p[k] = generator0_of_vector(pk, F->p[i], F->nbcolumns); k++; } } array.size = k; return array; } apron-dist-0.9.10/apron/newpolka/test0.c0000640014525101416610000015120711251675744017731 0ustar bjeannetpopart/* ********************************************************************** */ /* test.c: unit testing */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include "ap_dimension.h" #include "pk_config.h" #include "pk_vector.h" #include "pk_satmat.h" #include "pk_matrix.h" #include "pk.h" #include "pk_representation.h" #include "pk_constructor.h" #include "pk_extract.h" #include "pk_test.h" #include "pk_meetjoin.h" #include "pk_resize.h" #include "pk_assign.h" static size_t count = 0; /* ********************************************************************** */ /* Vectors */ /* ********************************************************************** */ void vector(pk_internal_t* pk, size_t nbdims, numint_t factor) { size_t size; numint_t* q[5]; numint_t* r1; size_t i; int j; bool change; pk_internal_realloc_lazy(pk,30); size = pk->dec + nbdims; for (i=1; i<=4; i++) q[i] = vector_alloc(size); /* q[1] = [0 10 [0] 1 2 3 4 ...] * factor */ numint_set_int(q[1][polka_cst],10L); for (i=pk->dec; idec+1)); numint_mul(q[1][i],q[1][i],factor); } vector_print(q[1],size); /* q[2] = [1 10 [-2] 1 2 3 4 ...] * factor */ vector_copy(q[2],q[1],size); numint_set_int(q[2][0],1); if (pk->strict) numint_set_int(q[2][polka_eps],-2); vector_print(q[2],size); /* q[3] = [1 10 [0] size-1 size-2 ... ] * 2 * factor */ numint_set_int(q[3][0],1); numint_set_int(q[3][polka_cst],10); for (i=pk->dec; istrict) numint_set_int(q[4][polka_eps],-1); numint_set_int(q[4][polka_cst],10); for (i=pk->dec; idec+3); printf("r1=%p\n",r1); vector_print(r1,pk->dec+3); vector_realloc(&r1,pk->dec+3,2*size); printf("r1=%p\n",r1); vector_print(r1,2*size); vector_free(r1,2*size); } printf("\n"); /* vector_normalize */ r1 = vector_alloc(size); for (i=1; i<=4; i++){ printf("vector_normalize %d\n",i); vector_copy(r1,q[i],size); vector_print(r1,size); vector_normalize(pk,r1,size); vector_print(r1,size); printf("vector_normalize_constraint %d\n",i); vector_copy(r1,q[i],size); change = vector_normalize_constraint(pk,r1,size/2,size-size/2-pk->dec); vector_print(r1,size); printf("change=%d\n",change); printf("vector_normalize_constraint_int %d\n",i); vector_copy(r1,q[i],size); change = vector_normalize_constraint_int(pk,r1,size/2,size-size/2-pk->dec); vector_print(r1,size); printf("change=%d\n",change); printf("vector_normalize_constraint_int %d\n",i); vector_copy(r1,q[i],size); change = vector_normalize_constraint_int(pk,r1,size-pk->dec,0); vector_print(r1,size); printf("change=%d\n",change); } vector_free(r1,size); printf("\n"); /* vector_compare */ for (i=1; i<=4; i++){ for (j=1; j<=4; j++){ int res = vector_compare(pk,q[i],q[j],size); printf("vector_compare(%d,%d)=%d\n",i,j,res); } } /* vector_combine */ r1 = vector_alloc(size); for (i=1; i<=4; i++){ for (j=i; j<=4; j++){ vector_combine(pk,q[i],q[j],r1,pk->dec+3,size); printf("vector_combine(%d,%d,k=%d)\n",i,j,pk->dec+3); vector_print(r1,size); vector_combine(pk,q[j],q[i],r1,pk->dec+3,size); printf("vector_combine(%d,%d,k=%d)\n",j,i,pk->dec+3); vector_print(r1,size); } } vector_free(r1,size); printf("\n"); for (i=1; i<=4; i++){ vector_free(q[i],size); } } /* ********************************************************************** */ /* Polyhedra 1 */ /* ********************************************************************** */ void poly1(ap_manager_t* man, char** name_of_dim, pk_t** ppo1, pk_t** ppo2) { /* Creation du polyčdre 1/2x+2/3y=1, [1,2]<=z+2w<=4, -2<=1/3z-w<=3, u non contraint */ mpq_t mpq; ap_lincons0_t cons; ap_lincons0_array_t array; ap_generator0_array_t garray; pk_t* poly; pk_t* poly2; pk_t* poly3; ap_interval_t** titv; ap_interval_t* itv; int i; ap_linexpr0_t* expr; bool b; mpq_init(mpq); array = ap_lincons0_array_make(5); /* 1. Constraint system */ array.p[0].constyp = AP_CONS_EQ; array.p[0].linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2); ap_linexpr0_set_cst_scalar_int(array.p[0].linexpr0,1); ap_linexpr0_set_coeff_scalar_double(array.p[0].linexpr0,0,0.5); ap_linexpr0_set_coeff_scalar_frac(array.p[0].linexpr0,1,2,3); array.p[1].constyp = AP_CONS_SUPEQ; array.p[1].linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2); ap_linexpr0_set_cst_interval_int(array.p[1].linexpr0,-2,-1); ap_linexpr0_set_coeff_scalar_double(array.p[1].linexpr0,2,1.0); ap_linexpr0_set_coeff_scalar_frac(array.p[1].linexpr0,3,2,1); array.p[2].constyp = AP_CONS_SUPEQ; array.p[2].linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2); ap_linexpr0_set_list(array.p[2].linexpr0, AP_COEFF_S_DOUBLE,-1.0, 2, AP_COEFF_S_FRAC,-2,1, 3, AP_CST_S_INT, 4, AP_END); array.p[3].constyp = AP_CONS_SUPEQ; array.p[3].linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2); ap_linexpr0_set_cst_scalar_int(array.p[3].linexpr0,2); ap_linexpr0_set_list(array.p[3].linexpr0, AP_COEFF_S_FRAC,1,3, 2, AP_COEFF_S_INT,-1, 3, AP_END); array.p[4].constyp = AP_CONS_SUP; array.p[4].linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2); ap_linexpr0_set_list(array.p[4].linexpr0, AP_COEFF_S_FRAC, -1,3, 2, AP_COEFF_S_INT, 1, 3, AP_CST_S_INT, 3, AP_END); /* Creation */ ap_lincons0_array_fprint(stdout,&array,name_of_dim); poly = pk_top(man,0,6); poly = pk_meet_lincons_array(man,true,poly,&array); pk_fprint(stdout,man,poly,name_of_dim); pk_canonicalize(man,poly); pk_fprint(stdout,man,poly,name_of_dim); garray = pk_to_generator_array(man,poly); ap_generator0_array_fprint(stdout,&garray,name_of_dim); ap_generator0_array_clear(&garray); pk_fdump(stdout,man,poly); /* 2. Constraint system */ /* Conversion (to_lincons_array already tested with print) */ /* Should be 0: [-oo,+oo] 1: [-oo,+oo] 2: [-6/5,6] 3: [-7/5,2] 4: [-oo,+oo] 5: [-oo,+oo] */ titv = pk_to_box(man,poly); for (i=0; i<6; i++){ fprintf(stdout,"%2d: ",i); ap_interval_fprint(stdout,titv[i]); fprintf(stdout,"\n"); } /* Extraction (we first extract values for existing constraints, then for dimensions) */ /* existing constraints */ for (i=0; i<5; i++){ itv = pk_bound_linexpr(man,poly,array.p[i].linexpr0); fprintf(stdout,"Bound of "); ap_linexpr0_fprint(stdout,array.p[i].linexpr0,name_of_dim); fprintf(stdout,": "); ap_interval_fprint(stdout,itv); fprintf(stdout,"\n"); ap_interval_free(itv); } /* dimensions */ expr = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,1); ap_coeff_set_scalar_double(&expr->cst,0.0); ap_coeff_set_scalar_double(&expr->p.linterm[0].coeff,1.0); for (i=0; i<6; i++){ expr->p.linterm[0].dim = (ap_dim_t)i; itv = pk_bound_linexpr(man,poly,expr); fprintf(stdout,"Bound of "); ap_linexpr0_fprint(stdout,expr,name_of_dim); fprintf(stdout,": "); ap_interval_fprint(stdout,itv); fprintf(stdout,"\n"); ap_interval_free(itv); } ap_linexpr0_free(expr); /* 3. of box */ poly2 = pk_of_box(man,0,6,(ap_interval_t**)titv); pk_fprint(stdout,man,poly2,name_of_dim); pk_canonicalize(man,poly2); pk_fprint(stdout,man,poly2,name_of_dim); pk_fdump(stdout,man,poly2); /* 4. Tests top and bottom */ poly3 = pk_bottom(man,2,3); b = pk_is_bottom(man,poly3); fprintf(stdout,"pk_is_bottom(poly3)=%d\n",b); b = pk_is_top(man,poly3); fprintf(stdout,"pk_is_top(poly3)=%d\n",b); pk_free(man,poly3); poly3 = pk_top(man,2,3); b = pk_is_bottom(man,poly3); fprintf(stdout,"pk_is_bottom(poly3)=%d\n",b); b = pk_is_top(man,poly3); fprintf(stdout,"pk_is_top(poly3)=%d\n",b); pk_free(man,poly3); poly3 = pk_top(man,0,0); b = pk_is_bottom(man,poly3); fprintf(stdout,"pk_is_bottom(poly3)=%d\n",b); b = pk_is_top(man,poly3); fprintf(stdout,"pk_is_top(poly3)=%d\n",b); pk_free(man,poly3); pk_minimize(man,poly2); pk_fdump(stdout,man,poly2); b = pk_is_bottom(man,poly2); fprintf(stdout,"pk_is_bottom(poly2)=%d\n",b); b = pk_is_top(man,poly2); fprintf(stdout,"pk_is_top(poly2)=%d\n",b); /* 5. Tests leq */ b = pk_is_leq(man,poly,poly2); fprintf(stdout,"pk_is_leq(poly,poly2)=%d\n",b); b = pk_is_leq(man,poly2,poly); fprintf(stdout,"pk_is_leq(poly,poly2)=%d\n",b); /* 6. Tests sat_interval */ itv = ap_interval_alloc(); ap_interval_set_int(itv,-6,6); b = pk_sat_interval(man,poly,2,itv); fprintf(stdout,"pk_sat_interval(poly,2)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",b); b = pk_sat_interval(man,poly,3,itv); fprintf(stdout,"pk_sat_interval(poly,3)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",b); b = pk_sat_interval(man,poly,4,itv); fprintf(stdout,"pk_sat_interval(poly,4)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",b); ap_interval_set_double(itv,-2.5,2.5); b = pk_sat_interval(man,poly,2,itv); fprintf(stdout,"pk_sat_interval(poly,2)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",b); b = pk_sat_interval(man,poly,3,itv); fprintf(stdout,"pk_sat_interval(poly,3)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",b); b = pk_sat_interval(man,poly,4,itv); fprintf(stdout,"pk_sat_interval(poly,4)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",b); ap_interval_set_double(itv,-1.4,2.0); b = pk_sat_interval(man,poly,2,itv); fprintf(stdout,"pk_sat_interval(poly,2)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",b); b = pk_sat_interval(man,poly,3,itv); fprintf(stdout,"pk_sat_interval(poly,3)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",b); b = pk_sat_interval(man,poly,4,itv); fprintf(stdout,"pk_sat_interval(poly,4)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",b); mpq_set_si(mpq,-14,10); ap_scalar_set_mpq(itv->inf,mpq); ap_scalar_set_double(itv->sup,2.0); b = pk_sat_interval(man,poly,2,itv); fprintf(stdout,"pk_sat_interval(poly,2)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",b); b = pk_sat_interval(man,poly,3,itv); fprintf(stdout,"pk_sat_interval(poly,3)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",b); b = pk_sat_interval(man,poly,4,itv); fprintf(stdout,"pk_sat_interval(poly,4)"); ap_interval_fprint(stdout,itv); fprintf(stdout," = %d\n",b); ap_interval_free(itv); /* 7. Tests sat_lincons */ expr = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,4); cons.constyp = AP_CONS_SUPEQ; cons.linexpr0 = expr; ap_linexpr0_set_list(expr, AP_COEFF_S_DOUBLE, -3.0, 0, AP_COEFF_S_DOUBLE, -4.0, 1, AP_COEFF_S_DOUBLE, 1.0, 2, AP_COEFF_S_DOUBLE, -1.0, 3, AP_CST_S_INT, 0, AP_END); itv = pk_bound_linexpr(man,poly,expr); fprintf(stdout,"Bound of "); ap_linexpr0_fprint(stdout,expr,name_of_dim); fprintf(stdout,": "); ap_interval_fprint(stdout,itv); fprintf(stdout,"\n"); ap_interval_free(itv); for (i=0; i<6; i++){ ap_linexpr0_set_cst_scalar_frac(expr,-26 + i*10, 5); cons.constyp = AP_CONS_SUPEQ; b = pk_sat_lincons(man,poly,&cons); fprintf(stdout,"pk_sat_lincons(poly)"); ap_lincons0_fprint(stdout,&cons,name_of_dim); fprintf(stdout,": %d\n",b); cons.constyp = AP_CONS_SUP; b = pk_sat_lincons(man,poly,&cons); fprintf(stdout,"pk_sat_lincons(poly)"); ap_lincons0_fprint(stdout,&cons,name_of_dim); fprintf(stdout,": %d\n",b); } ap_linexpr0_set_list(expr, AP_COEFF_S_FRAC, -2,3, 2, AP_COEFF_S_DOUBLE, 2.0, 3, AP_CST_S_FRAC, 0,0, AP_END); itv = pk_bound_linexpr(man,poly,expr); fprintf(stdout,"Bound of "); ap_linexpr0_fprint(stdout,expr,name_of_dim); fprintf(stdout,": "); ap_interval_fprint(stdout,itv); fprintf(stdout,"\n"); ap_interval_free(itv); for (i=0; i<6; i++){ ap_linexpr0_set_cst_scalar_int(expr,-1+i); cons.constyp = AP_CONS_SUPEQ; b = pk_sat_lincons(man,poly,&cons); fprintf(stdout,"pk_sat_lincons(poly)"); ap_lincons0_fprint(stdout,&cons,name_of_dim); fprintf(stdout,": %d\n",b); cons.constyp = AP_CONS_SUP; b = pk_sat_lincons(man,poly,&cons); fprintf(stdout,"pk_sat_lincons(poly)"); ap_lincons0_fprint(stdout,&cons,name_of_dim); fprintf(stdout,": %d\n",b); } ap_linexpr0_free(expr); ap_interval_array_free(titv,6); ap_lincons0_array_clear(&array); mpq_clear(mpq); *ppo1 = poly; *ppo2 = poly2; } /* ********************************************************************** */ /* Polyhedra 2 */ /* ********************************************************************** */ void poly2(ap_manager_t* man, char** name_of_dim, pk_t* po1, pk_t* po2) { bool b; pk_t* po; ap_linexpr0_t* expr[2]; ap_lincons0_t cons; ap_lincons0_array_t array = { &cons, 1 }; ap_generator0_t gen; ap_generator0_array_t garray, garray2; int i; /* Meet and join (without meet_array et join_array) */ fprintf(stdout,"********* Meet and Join for 2 polyhedra *********\n"); fprintf(stdout,"po1:\n"); pk_fprint(stdout,man,po1,name_of_dim); fprintf(stdout,"po2:\n"); pk_fprint(stdout,man,po2,name_of_dim); fprintf(stdout,"po=meet(po1,po2)\n"); po = pk_meet(man,false,po1,po2); pk_fprint(stdout,man,po,name_of_dim); b = pk_is_leq(man,po,po1); fprintf(stdout,"pk_is_leq(man,po,po1)=%d\n",b); assert(b); b = pk_is_leq(man,po,po2); fprintf(stdout,"pk_is_leq(man,po,po2)=%d\n",b); assert(b); b = pk_is_leq(man,po1,po); fprintf(stdout,"pk_is_leq(man,po1,po)=%d\n",b); b = pk_is_leq(man,po2,po); fprintf(stdout,"pk_is_leq(man,po2,po)=%d\n",b); pk_free(man,po); fprintf(stdout,"po=po1; meet_with(po,po2)\n"); po = pk_copy(man,po1); po = pk_meet(man,true,po,po2); pk_fprint(stdout,man,po,name_of_dim); b = pk_is_leq(man,po,po1); fprintf(stdout,"pk_is_leq(man,po,po1)=%d\n",b); assert(b); b = pk_is_leq(man,po,po2); fprintf(stdout,"pk_is_leq(man,po,po2)=%d\n",b); assert(b); b = pk_is_leq(man,po1,po); fprintf(stdout,"pk_is_leq(man,po1,po)=%d\n",b); b = pk_is_leq(man,po2,po); fprintf(stdout,"pk_is_leq(man,po2,po)=%d\n",b); pk_free(man,po); fprintf(stdout,"po = join(po1,po2)\n"); po = pk_join(man,false,po1,po2); pk_fprint(stdout,man,po,name_of_dim); b = pk_is_top(man,po); fprintf(stdout,"pk_is_top(man,po)=%d\n",b); b = pk_is_leq(man,po,po1); fprintf(stdout,"pk_is_leq(man,po,po1)=%d\n",b); b = pk_is_leq(man,po,po2); fprintf(stdout,"pk_is_leq(man,po,po2)=%d\n",b); b = pk_is_leq(man,po1,po); fprintf(stdout,"pk_is_leq(man,po1,po)=%d\n",b); assert(b); b = pk_is_leq(man,po2,po); fprintf(stdout,"pk_is_leq(man,po2,po)=%d\n",b); assert(b); pk_free(man,po); fprintf(stdout,"po = po1; join_with(po,po2)\n"); po = pk_copy(man,po1); po = pk_join(man,true,po,po2); pk_fprint(stdout,man,po,name_of_dim); b = pk_is_leq(man,po,po1); fprintf(stdout,"pk_is_leq(man,po,po1)=%d\n",b); b = pk_is_leq(man,po,po2); fprintf(stdout,"pk_is_leq(man,po,po2)=%d\n",b); b = pk_is_leq(man,po1,po); fprintf(stdout,"pk_is_leq(man,po1,po)=%d\n",b); assert(b); b = pk_is_leq(man,po2,po); fprintf(stdout,"pk_is_leq(man,po2,po)=%d\n",b); assert(b); pk_free(man,po); /* Additions of constraints */ fprintf(stdout,"********* Addition of constraint *********\n"); fprintf(stdout,"po1:\n"); pk_fprint(stdout,man,po1,name_of_dim); garray = pk_to_generator_array(man,po1); ap_generator0_array_fprint(stdout,&garray,name_of_dim); ap_generator0_array_clear(&garray); /* expression z>=-1/2 */ expr[0] = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,1); ap_linexpr0_set_cst_scalar_frac(expr[0],1,2); ap_linexpr0_set_coeff_scalar_int(expr[0],2,1); /* expression x+u>=1 */ expr[1] = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2); ap_linexpr0_set_list(expr[1], AP_COEFF_S_INT, 1, 0, AP_COEFF_S_INT, 1, 4, AP_CST_S_INT, -1, AP_END); for (i=0; i<2; i++){ cons.linexpr0 = expr[i]; for (cons.constyp=0; cons.constyp<3; cons.constyp++){ fprintf(stdout,"po=meet_lincons(po1) "); ap_lincons0_fprint(stdout,&cons,name_of_dim); fprintf(stdout,"\n"); po = pk_meet_lincons_array(man,false,po1,&array); pk_fprint(stdout,man,po,name_of_dim); garray = pk_to_generator_array(man,po); ap_generator0_array_fprint(stdout,&garray,name_of_dim); ap_generator0_array_clear(&garray); b = pk_is_leq(man,po,po1); fprintf(stdout,"pk_is_leq(po,po1)=%d\n",b); assert(b); b = pk_is_leq(man,po1,po); fprintf(stdout,"pk_is_leq(po1,po)=%d\n",b); pk_free(man,po); fprintf(stdout,"po=po1; meet_lincons_with(po) "); ap_lincons0_fprint(stdout,&cons,name_of_dim); fprintf(stdout,"\n"); po = pk_copy(man,po1); po = pk_meet_lincons_array(man,true,po,&array); pk_fprint(stdout,man,po,name_of_dim); garray = pk_to_generator_array(man,po); ap_generator0_array_fprint(stdout,&garray,name_of_dim); ap_generator0_array_clear(&garray); b = pk_is_leq(man,po,po1); fprintf(stdout,"pk_is_leq(po,po1)=%d\n",b); assert(b); b = pk_is_leq(man,po1,po); fprintf(stdout,"pk_is_leq(po1,po)=%d\n",b); pk_free(man,po); } ap_linexpr0_free(expr[i]); } /* Additions of rays */ fprintf(stdout,"********* Addition of rays *********\n"); fprintf(stdout,"po1:\n"); pk_fprint(stdout,man,po1,name_of_dim); garray = pk_to_generator_array(man,po1); ap_generator0_array_fprint(stdout,&garray,name_of_dim); ap_generator0_array_clear(&garray); /* expression z+w/8 */ expr[0] = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2); ap_linexpr0_set_list(expr[0], AP_COEFF_S_INT, 1, 2, AP_COEFF_S_FRAC, 1,8, 3, AP_END); /* expression z+w */ expr[1] = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2); ap_linexpr0_set_list(expr[1], AP_COEFF_S_INT, 1, 2, AP_COEFF_S_INT, 1, 3, AP_END); garray2 = ap_generator0_array_make(1); for (i=0; i<2; i++){ gen.linexpr0 = expr[i]; gen.gentyp = AP_GEN_RAY; garray2.p[0] = gen; fprintf(stdout,"po=add_ray_array(po1) "); ap_generator0_fprint(stdout,&gen,name_of_dim); fprintf(stdout,"\n"); po = pk_add_ray_array(man,false,po1,&garray2); pk_fprint(stdout,man,po,name_of_dim); garray = pk_to_generator_array(man,po); ap_generator0_array_fprint(stdout,&garray,name_of_dim); ap_generator0_array_clear(&garray); b = pk_is_leq(man,po,po1); fprintf(stdout,"pk_is_leq(po,po1)=%d\n",b); b = pk_is_leq(man,po1,po); fprintf(stdout,"pk_is_leq(po1,po)=%d\n",b); assert(b); pk_free(man,po); fprintf(stdout,"po=po1; add_ray_array_with(po) "); ap_generator0_fprint(stdout,&gen,name_of_dim); fprintf(stdout,"\n"); po = pk_copy(man,po1); po = pk_add_ray_array(man,true,po,&garray2); pk_fprint(stdout,man,po,name_of_dim); garray = pk_to_generator_array(man,po); ap_generator0_array_fprint(stdout,&garray,name_of_dim); ap_generator0_array_clear(&garray); b = pk_is_leq(man,po,po1); fprintf(stdout,"pk_is_leq(po,po1)=%d\n",b); b = pk_is_leq(man,po1,po); fprintf(stdout,"pk_is_leq(po1,po)=%d\n",b); pk_free(man,po); ap_linexpr0_free(expr[i]); } garray2.p[0].linexpr0 = NULL; ap_generator0_array_clear(&garray2); } /* ********************************************************************** */ /* Polyhedra 3 (assignement and substitution of a single expression) */ /* ********************************************************************** */ void poly3(ap_manager_t* man, char** name_of_dim, pk_t* po1, pk_t* po2) { bool b; pk_t* poly1; pk_t* poly2; pk_t* poly3; pk_t* tpo[2]; ap_linexpr0_t* expr[3]; ap_generator0_array_t garray; int i,j,inplace,undet; fprintf(stdout,"********* Assignement and Substitution, single *********\n"); fprintf(stdout,"po1:\n"); pk_fprint(stdout,man,po1,name_of_dim); garray = pk_to_generator_array(man,po1); ap_generator0_array_fprint(stdout,&garray,name_of_dim); ap_generator0_array_clear(&garray); fprintf(stdout,"po2:\n"); pk_fprint(stdout,man,po2,name_of_dim); garray = pk_to_generator_array(man,po2); ap_generator0_array_fprint(stdout,&garray,name_of_dim); ap_generator0_array_clear(&garray); tpo[0] = po1; tpo[1] = po2; /* Single equation z+5w-1 */ expr[0] = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2); ap_linexpr0_set_list(expr[0], AP_COEFF_S_INT, 1, 2, AP_COEFF_S_INT, 5, 3, AP_CST_S_INT, -1, AP_END); /* Single equation 2x+1 */ expr[1] = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,1); ap_linexpr0_set_coeff_scalar_int(expr[1],0,2); ap_linexpr0_set_cst_scalar_int(expr[1],1); expr[1]->p.linterm[0].dim = 0; for (undet=0; undet<2; undet++){ if (undet==1){ for (j=0;j<2;j++){ ap_linexpr0_set_cst_interval_int(expr[j],-1,1); } } for (inplace=0; inplace<2; inplace++){ for (i=0; i<2; i++){ for (j=0;j<2;j++){ fprintf(stdout, inplace ? "poly1 = po%d; assign_linexpr_with(poly1) z:=" : "poly1=assign_linexpr(po%d) z:=", i+1); ap_linexpr0_fprint(stdout,expr[j],name_of_dim); fprintf(stdout,"\n"); if (inplace){ ap_dim_t dim = 2; poly1 = pk_copy(man,tpo[i]); poly1 = pk_assign_linexpr_array(man,true,poly1,&dim,&expr[j],1,NULL); } else { ap_dim_t dim = 2; poly1 = pk_assign_linexpr_array(man,false,tpo[i],&dim,&expr[j],1,NULL); } pk_fprint(stdout,man,poly1,name_of_dim); garray = pk_to_generator_array(man,poly1); ap_generator0_array_fprint(stdout,&garray,name_of_dim); ap_generator0_array_clear(&garray); fprintf(stdout, inplace ? "poly2 = poly1; substitute_linexpr_with(poly2) z:=" : "poly2=substitute_linexpr(poly1) z:=" ); ap_linexpr0_fprint(stdout,expr[j],name_of_dim); fprintf(stdout,"\n"); if (inplace){ ap_dim_t dim = 2; poly2 = pk_copy(man,poly1); poly2 = pk_substitute_linexpr_array(man,true,poly2,&dim,&expr[j],1,NULL); } else { ap_dim_t dim = 2; poly2 = pk_substitute_linexpr_array(man,false,poly1,&dim,&expr[j],1,NULL); } pk_fprint(stdout,man,poly2,name_of_dim); garray = pk_to_generator_array(man,poly2); ap_generator0_array_fprint(stdout,&garray,name_of_dim); ap_generator0_array_clear(&garray); b = pk_is_leq(man,tpo[i],poly2); fprintf(stdout,"pk_is_leq(po%d,poly2)=%d\n",i+1,b); assert(b); b = pk_is_leq(man,poly2,tpo[i]); fprintf(stdout,"pk_is_leq(poly2,po%d)=%d\n",i+1,b); assert(!undet && j==0 ? b : true); fprintf(stdout, inplace ? "poly3 = poly2; assign_linexpr_with(poly3) z:=" : "poly3=assign_linexpr(poly2) z:=" ); ap_linexpr0_fprint(stdout,expr[j],name_of_dim); fprintf(stdout,"\n"); if (inplace){ ap_dim_t dim = 2; poly3 = pk_copy(man,poly2); poly3 = pk_assign_linexpr_array(man,true,poly3,&dim,&expr[j],1,NULL); } else { ap_dim_t dim = 2; poly3 = pk_assign_linexpr_array(man,false,poly2,&dim,&expr[j],1,NULL); } pk_fprint(stdout,man,poly3,name_of_dim); garray = pk_to_generator_array(man,poly3); ap_generator0_array_fprint(stdout,&garray,name_of_dim); ap_generator0_array_clear(&garray); b = pk_is_eq(man,poly1,poly3); fprintf(stdout,"pk_is_eq(poly1,poly3)=%d\n",b); assert(!(undet && j==0) ? b : true); pk_free(man,poly1); pk_free(man,poly2); pk_free(man,poly3); } } } } ap_linexpr0_free(expr[0]); ap_linexpr0_free(expr[1]); } void pk_test_example_aux(ap_manager_t* man) { pk_t* p1; pk_t* p2; char** name_of_dim; ap_dimperm_t perm; name_of_dim = malloc(6*sizeof(char*)); name_of_dim[0] = "x"; name_of_dim[1] = "y"; name_of_dim[2] = "z"; name_of_dim[3] = "w"; name_of_dim[4] = "u"; name_of_dim[5] = "v"; ap_dimperm_init(&perm,6); ap_dimperm_set_id(&perm); perm.dim[0] = 2; perm.dim[2] = 0; perm.dim[3] = 5; perm.dim[5] = 3; poly1(man,name_of_dim, &p1, &p2); assert(poly_check((pk_internal_t*)man->internal,p1)); assert(poly_check((pk_internal_t*)man->internal,p2)); poly2(man,name_of_dim,p1,p2); p2 = pk_permute_dimensions(man,true,p2,&perm); poly2(man,name_of_dim,p1,p2); poly3(man,name_of_dim,p1,p2); pk_free(man,p2); p2 = pk_bottom(man,0,6); poly2(man,name_of_dim,p1,p2); poly2(man,name_of_dim,p2,p1); poly3(man,name_of_dim,p2,p1); pk_free(man,p1); pk_free(man,p2); /* */ free(name_of_dim); ap_dimperm_clear(&perm); } void pk_test_example(void) { pk_internal_t* pk; ap_manager_t* man; numint_t num; ap_funid_t funid; man = pk_manager_alloc(true); pk = (pk_internal_t*)man->internal; pk_internal_realloc_lazy(pk,20); numint_init(num); numint_set_int(num,1); vector(pk,7,num); numint_clear(num); pk_test_example_aux(man); for (funid=0; funidinternal; pk_set_approximate_max_coeff_size(pk,10); /* Build a polyhedron x>=0, x<=mag, x-(mag*mag)y>=0 */ po = pk_top(man,0,2); /* Expression */ expr = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,1); cons.constyp = AP_CONS_SUPEQ; cons.linexpr0 = expr; ap_linexpr0_set_cst_scalar_int(expr,0); ap_linexpr0_set_coeff_scalar_int(expr,0,1); po = pk_meet_lincons_array(man,true,po,&array); ap_linexpr0_set_cst_scalar_int(expr,(int)mag); ap_linexpr0_set_coeff_scalar_int(expr,0,-1); po = pk_meet_lincons_array(man,true,po,&array); ap_linexpr0_free(expr); expr = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2); cons.constyp = AP_CONS_SUPEQ; cons.linexpr0 = expr; ap_linexpr0_set_cst_scalar_int(expr,0); ap_linexpr0_set_list(expr, AP_COEFF_S_INT, 1, 0, AP_COEFF_S_INT, mag, 1, AP_END); coeff = ap_linexpr0_coeffref(expr,1); mpq_mul(coeff->val.scalar->val.mpq, coeff->val.scalar->val.mpq, coeff->val.scalar->val.mpq); mpq_neg(coeff->val.scalar->val.mpq, coeff->val.scalar->val.mpq); po = pk_meet_lincons_array(man,true,po,&array); ap_linexpr0_free(expr); pa = pk_copy(man,po); pk_approximate(man,pa,3); pk_fprint(stdout,man,po,NULL); pk_fprint(stdout,man,pa,NULL); assert(pk_is_leq(man,po,pa)); pk_free(man,pa); pa = pk_copy(man,po); pk_approximate(man,pa,10); pk_fprint(stdout,man,po,NULL); pk_fprint(stdout,man,pa,NULL); assert(pk_is_leq(man,po,pa)); pk_free(man,pa); pk_free(man,po); ap_manager_free(man); return; } /* ********************************************************************** */ /* Polyhedra 10 */ /* ********************************************************************** */ void pk_test_gen(ap_manager_t* man, size_t intdim, size_t realdim, size_t nbcons, /* Number of constraints */ size_t maxeq, /* Maximum number of equations */ size_t maxcoeff, /* Maximum size of non-null coefficients */ unsigned int mag, /* magnitude of coefficients */ char*** pname_of_dim, pk_t*** ptpoly, /* of size 6, 0==2, 1==3 */ ap_linexpr0_t*** ptexpr, /* of size 3 */ ap_dim_t** ptdim /* of size 3 */ ) { char buffer[80]; size_t i; pk_t* p1; pk_t* p2; *pname_of_dim = malloc((intdim+realdim)*sizeof(char*)); for (i=0; i=3); } void pk_test_free(ap_manager_t* man, size_t intdim, size_t realdim, char** name_of_dim, pk_t** tpoly, ap_linexpr0_t** texpr, ap_dim_t* tdim) { size_t j; for (j=0;jresult.flag_exact!=true); } pk_free(man,p3); p3 = pk_copy(man,p1); pk_approximate(man,p3,10); pk_fprint(stdout,man,p1,name_of_dim); pk_fprint(stdout,man,p3,name_of_dim); assert(pk_is_leq(man,p1,p3)); if (pk_is_leq(man,p3,p1)!=true){ printf("approximate(10) greater\n"); assert(man->result.flag_exact!=true); } pk_free(man,p3); /* bound_dimension and sat_interval */ PRINT((printf("bound_dimension and sat_interval\n"))); for (i=0;iinf) && !ap_scalar_infty(interval->sup)){ ap_mpq_set_scalar(mpq,interval->inf,0); mpq_add(mpq,mpq,mpqone); ap_scalar_set_mpq(interval->inf,mpq); ap_mpq_set_scalar(mpq,interval->sup,0); mpq_sub(mpq,mpq,mpqone); ap_scalar_set_mpq(interval->sup,mpq); assert(pk_sat_interval(man,p1,i,interval)==false || pk_is_bottom(man,p1)); } if (!ap_scalar_infty(interval->inf)){ ap_mpq_set_scalar(mpq,interval->inf,0); mpq_sub(mpq,mpq,mpqone); mpq_sub(mpq,mpq,mpqone); ap_scalar_set_mpq(interval->inf,mpq); } if (!ap_scalar_infty(interval->sup)){ ap_mpq_set_scalar(mpq,interval->sup,0); mpq_add(mpq,mpq,mpqone); mpq_add(mpq,mpq,mpqone); ap_scalar_set_mpq(interval->sup,mpq); } assert(pk_sat_interval(man,p1,i,interval)); ap_interval_free(interval); } /* bound_linexpr and sat_lincons */ PRINT((printf("bound_linexpr and sat_lincons\n"))); for (k=0; k<3; k++){ expr = texpr[k]; cons.constyp = AP_CONS_SUPEQ; cons.linexpr0 = expr; pcoeff = ap_linexpr0_cstref(expr); pdbl = &pcoeff->val.scalar->val.dbl; d = *pdbl; interval = pk_bound_linexpr(man,p1,expr); if (!ap_scalar_infty(interval->inf)){ ap_double_set_scalar(pdbl,interval->inf,GMP_RNDZ); *pdbl = d + 1.0 - *pdbl; assert(pk_sat_lincons(man,p1,&cons)); ap_double_set_scalar(pdbl,interval->inf,GMP_RNDZ); *pdbl = d - 1.0 - *pdbl; assert(pk_sat_lincons(man,p1,&cons)==false || pk_is_bottom(man,p1)); } if (!ap_scalar_infty(interval->sup)){ for (i=0; ip.coeff[i],&expr->p.coeff[i]); } ap_double_set_scalar(pdbl,interval->sup,GMP_RNDZ); *pdbl = *pdbl - d + 1.0; assert(pk_sat_lincons(man,p1,&cons)); ap_double_set_scalar(pdbl,interval->sup,GMP_RNDZ); *pdbl = *pdbl - d - 1.0; assert(pk_sat_lincons(man,p1,&cons)==false || pk_is_bottom(man,p1)); } *pdbl = d; ap_interval_free(interval); } /* to_box */ PRINT((printf("to_box\n"))); box = pk_to_box(man,p1); for (i=0;iresult.flag_exact; pk_fprint(stdout,man,p5,name_of_dim); assert(pk_is_leq(man,p4,p5)); if (pk_is_leq(man,p5,p4)!=true){ printf("approximate(3) greater\n"); assert(res!=true); } else { assert(res); } pk_free(man,p5); printf("approximate(10)\n"); p5 = pk_copy(man,p4); pk_approximate(man,p5,10); res = man->result.flag_exact; pk_fprint(stdout,man,p5,name_of_dim); assert(pk_is_leq(man,p4,p5)); if (pk_is_leq(man,p5,p4)!=true){ printf("approximate(10) greater\n"); assert(res!=true); } else { assert(res); } pk_free(man,p5); pk_free(man,p3); pk_free(man,p4); /* meet_lincons, add_ray_array */ PRINT((printf("meet_lincons, add_ray_array\n"))); for (k=0; k<3; k++){ expr = texpr[k]; cons.constyp = AP_CONS_SUPEQ; cons.linexpr0 = expr; p3 = pk_meet_lincons_array(man,false,p1,&consarray); p4 = pk_copy(man,p1); p4 = pk_meet_lincons_array(man,true,p4,&consarray); assert(pk_is_eq(man,p3,p4)); assert(pk_is_leq(man,p3,p1)); pk_free(man,p3); pk_free(man,p4); garray = ap_generator0_array_make(1); garray.p[0].gentyp = AP_GEN_RAY; garray.p[0].linexpr0 = expr; p3 = pk_add_ray_array(man,false,p1,&garray); p4 = pk_copy(man,p1); p4 = pk_add_ray_array(man,true,p4,&garray); assert(pk_is_eq(man,p3,p4)); assert(pk_is_leq(man,p1,p3)); free(garray.p); pk_free(man,p3); pk_free(man,p4); } /* assign and substitute (single, deterministic) */ PRINT((printf("assign and substitute (single, deterministic)\n"))); for (k=0; k<3; k++){ dim = tdim[k]; expr = texpr[k]; p3 = pk_assign_linexpr_array(man,false,p1,&dim,&expr,1,NULL); p4 = pk_copy(man,p1); p4 = pk_assign_linexpr_array(man,true,p4,&dim,&expr,1,NULL); assert(pk_is_eq(man,p3,p4)); pk_free(man,p4); p4 = pk_substitute_linexpr_array(man,false,p3,&dim,&expr,1,NULL); p5 = pk_copy(man,p3); p5 = pk_substitute_linexpr_array(man,true,p5,&dim,&expr,1,NULL); assert(pk_is_eq(man,p4,p5)); pk_free(man,p5); p5 = pk_assign_linexpr_array(man,false,p4,&dim,&expr,1,NULL); assert(pk_is_leq(man,p1,p4)); assert(pk_is_eq(man,p3,p5)); pk_free(man,p3); pk_free(man,p4); pk_free(man,p5); } /* parallel assign and substitute (deterministic) */ PRINT((printf("parallel assign and substitute (deterministic)\n"))); p3 = pk_assign_linexpr_array(man,false,p1,tdim,texpr,3,NULL); p4 = pk_copy(man,p1); p4 = pk_assign_linexpr_array(man,true,p4,tdim,texpr,3,NULL); assert(pk_is_eq(man,p3,p4)); pk_free(man,p4); p4 = pk_substitute_linexpr_array(man,false,p3,tdim,texpr,3,NULL); p5 = pk_copy(man,p3); p5 = pk_substitute_linexpr_array(man,true,p5,tdim,texpr,3,NULL); assert(pk_is_eq(man,p4,p5)); pk_free(man,p5); p5 = pk_assign_linexpr_array(man,false,p4,tdim,texpr,3,NULL); assert(pk_is_leq(man,p1,p4)); assert(pk_is_eq(man,p3,p5)); pk_free(man,p3); pk_free(man,p4); pk_free(man,p5); /* project and forget */ PRINT((printf("project and forget\n"))); box = pk_to_box(man,p1); for (k=0; k<3; k++){ dim = tdim[k]; p3 = pk_forget_array(man,false,p1,&dim,1,true); p4 = pk_copy(man,p1); p4 = pk_forget_array(man,true,p4,&dim,1,true); assert(pk_is_eq(man,p3,p4)); pk_free(man,p4); p4 = pk_forget_array(man,false,p1,&dim,1,false); p5 = pk_copy(man,p1); pk_forget_array(man,true,p5,&dim,1,false); assert(pk_is_eq(man,p4,p5)); pk_free(man,p5); assert(pk_is_leq(man,p3,p4)); assert(pk_is_leq(man,p4,p3)==false || pk_is_bottom(man,p1)); interval = pk_bound_dimension(man,p3,dim); assert(ap_scalar_equal(interval->inf,interval->sup) || pk_is_bottom(man,p1)); assert(ap_scalar_cmp_int(interval->inf,0)==0 || pk_is_bottom(man,p1)); ap_interval_free(interval); interval = pk_bound_dimension(man,p4,dim); assert(ap_interval_is_top(interval) || pk_is_bottom(man,p1)); ap_interval_free(interval); for (i=0; iinf,interval->sup)|| pk_is_bottom(man,p1)); assert(ap_scalar_cmp_int(interval->inf,0)==0|| pk_is_bottom(man,p1)); ap_interval_free(interval); interval = pk_bound_dimension(man,p4,dim); assert(ap_interval_is_top(interval) || pk_is_bottom(man,p1)); ap_interval_free(interval); } pk_free(man,p3); pk_free(man,p4); /* change and permutation of dimensions */ PRINT((printf("change and permutation of dimensions\n"))); ap_dimperm_init(&perm,(intdim+realdim)*2); ap_dimperm_set_id(&perm); for (i=0;i<2*intdim; i++){ perm.dim[i] = 2*intdim-1-i; } for (i=0;i<2*realdim; i++){ perm.dim[2*intdim+i] = 2*(intdim+realdim)-1-i; } dimchange = ap_dimchange_alloc(intdim,realdim); for (i=0;idim[i]=i; } p3 = pk_add_dimensions(man,false,p1,dimchange,true); p4 = pk_copy(man,p1); p4 = pk_add_dimensions(man,true,p4,dimchange,true); assert(pk_is_eq(man,p3,p4)); pk_free(man,p3); pk_free(man,p4); p3 = pk_add_dimensions(man,false,p1,dimchange,false); p4 = pk_copy(man,p1); p4 = pk_add_dimensions(man,true,p4,dimchange,false); assert(pk_is_eq(man,p3,p4)); pk_free(man,p4); p4 = pk_permute_dimensions(man,false,p3,&perm); p5 = pk_copy(man,p3); p5 = pk_permute_dimensions(man,true,p5,&perm); assert(pk_is_eq(man,p4,p5)); p5 = pk_permute_dimensions(man,true,p5,&perm); assert(pk_is_eq(man,p3,p5)); pk_free(man,p4); pk_free(man,p5); ap_dimchange_add_invert(dimchange); p4 = pk_remove_dimensions(man,false,p3,dimchange); assert(pk_is_eq(man,p1,p4)); p5 = pk_copy(man,p3); p5 = pk_remove_dimensions(man,true,p5,dimchange); assert(pk_is_eq(man,p4,p5)); pk_free(man,p3); pk_free(man,p4); pk_free(man,p5); ap_dimperm_clear(&perm); ap_dimchange_free(dimchange); mpq_clear(mpq); mpq_clear(mpqone); } void pk_test(size_t intdim, size_t realdim, size_t nbcons, /* Number of constraints */ size_t maxeq, /* Maximum number of equations */ size_t maxcoeff, /* Maximum size of non-null coefficients */ unsigned int mag /* magnitude of coefficients */ ) { pk_internal_t* pk; ap_manager_t* man; char** name_of_dim; pk_t** tpoly; ap_linexpr0_t** texpr; ap_dim_t* tdim; int i; ap_funid_t funid; man = pk_manager_alloc(false); pk = (pk_internal_t*)man->internal; pk_set_max_coeff_size(pk,0); pk_set_approximate_max_coeff_size(pk,10); for (i=0; i<3; i++){ printf("%d******************************************************************\n",i); pk_test_gen(man,intdim,realdim, nbcons,maxeq,maxcoeff,mag, &name_of_dim, &tpoly, &texpr, &tdim); pk_test_check(man,intdim,realdim, name_of_dim,tpoly,texpr,tdim); for (funid=0; funid= 0 */ ap_lincons0_array_t array; pk_t* poly; pk_t* poly2; pk_t* poly3; man = pk_manager_alloc(false); array = ap_lincons0_array_make(1); /* 1. Constraint system */ array.p[0].constyp = AP_CONS_SUPEQ; array.p[0].linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2); ap_linexpr0_set_list(array.p[0].linexpr0, AP_COEFF_S_INT,4,1, AP_COEFF_S_INT,4,2, AP_CST_S_INT,17, AP_END); /* Creation */ ap_lincons0_array_fprint(stdout,&array,NULL); poly = pk_top(man,0,3); poly = pk_meet_lincons_array(man,true,poly,&array); pk_fprint(stdout,man,poly,NULL); poly2 = pk_bottom(man,0,3); pk_fprint(stdout,man,poly2,NULL); poly3 = pk_join(man,false,poly,poly2); pk_fprint(stdout,man,poly3,NULL); funopt = ap_manager_get_funopt(man, AP_FUNID_JOIN); funopt.flag_exact_wanted = true; funopt.flag_best_wanted = true; ap_manager_set_funopt(man, AP_FUNID_JOIN, &funopt); pk_free(man,poly3); poly3 = pk_join(man,false,poly,poly2); pk_fprint(stdout,man,poly3,NULL); pk_free(man,poly2); pk_free(man,poly); ap_lincons0_array_clear(&array); ap_manager_free(man); } void mine3(void) { ap_manager_t* man; ap_funopt_t funopt; ap_lincons0_array_t array; pk_t* poly0; pk_t* poly1; pk_t* poly2; pk_t* poly3; pk_t* poly; pk_t* tpoly[5]; man = pk_manager_alloc(false); /* 0. Constraint system */ /* array of constraints of size 5 0: -4x0 + 4x1 + 5 >= 0 1: -x0 - x2 + 5 >= 0 2: -x0 + x2 + 7 >= 0 3: 4x0 - 4x1 + 11 >= 0 4: 2x1 - 1 >= 0 */ array = ap_lincons0_array_make(5); array.p[0].constyp = AP_CONS_SUPEQ; array.p[0].linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2); ap_linexpr0_set_list(array.p[0].linexpr0, AP_COEFF_S_INT,-4,0, AP_COEFF_S_INT,4,1, AP_CST_S_INT,5, AP_END); array.p[1].constyp = AP_CONS_SUPEQ; array.p[1].linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2); ap_linexpr0_set_list(array.p[1].linexpr0, AP_COEFF_S_INT,-1,0, AP_COEFF_S_INT,-1,2, AP_CST_S_INT,5, AP_END); array.p[2].constyp = AP_CONS_SUPEQ; array.p[2].linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2); ap_linexpr0_set_list(array.p[2].linexpr0, AP_COEFF_S_INT,-1,0, AP_COEFF_S_INT,1,2, AP_CST_S_INT,7, AP_END); array.p[3].constyp = AP_CONS_SUPEQ; array.p[3].linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2); ap_linexpr0_set_list(array.p[3].linexpr0, AP_COEFF_S_INT,4,0, AP_COEFF_S_INT,-4,1, AP_CST_S_INT,11, AP_END); array.p[4].constyp = AP_CONS_SUPEQ; array.p[4].linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,1); ap_linexpr0_set_list(array.p[4].linexpr0, AP_COEFF_S_INT,2,1, AP_CST_S_INT,-1, AP_END); poly0 = pk_top(man,0,3); poly0 = pk_meet_lincons_array(man,true,poly0,&array); pk_fprint(stdout,man,poly0,NULL); /* 1. Constraint system */ /* array of constraints of size 5 0: -x0 - x2 + 3 >= 0 1: -x0 + 3 >= 0 2: 3x1 + 5 >= 0 */ ap_lincons0_array_clear(&array); array = ap_lincons0_array_make(3); array.p[0].constyp = AP_CONS_SUPEQ; array.p[0].linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2); ap_linexpr0_set_list(array.p[0].linexpr0, AP_COEFF_S_INT,-1,0, AP_COEFF_S_INT,-1,2, AP_CST_S_INT,3, AP_END); array.p[1].constyp = AP_CONS_SUPEQ; array.p[1].linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,1); ap_linexpr0_set_list(array.p[1].linexpr0, AP_COEFF_S_INT,-1,0, AP_CST_S_INT,3, AP_END); array.p[2].constyp = AP_CONS_SUPEQ; array.p[2].linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,1); ap_linexpr0_set_list(array.p[2].linexpr0, AP_COEFF_S_INT,3,1, AP_CST_S_INT,5, AP_END); poly1 = pk_top(man,0,3); poly1 = pk_meet_lincons_array(man,true,poly1,&array); pk_fprint(stdout,man,poly1,NULL); /* 2. Constraint system */ /* array of constraints of size 5 0: -3x0 + 3x2 + 4 >= 0 1: -2x1 + 5 >= 0 2: 4x0 - 4x2 - 1 >= 0 3: x0 + x2 >= 0 */ ap_lincons0_array_clear(&array); array = ap_lincons0_array_make(4); array.p[0].constyp = AP_CONS_SUPEQ; array.p[0].linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2); ap_linexpr0_set_list(array.p[0].linexpr0, AP_COEFF_S_INT,-3,0, AP_COEFF_S_INT,3,2, AP_CST_S_INT,4, AP_END); array.p[1].constyp = AP_CONS_SUPEQ; array.p[1].linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,1); ap_linexpr0_set_list(array.p[1].linexpr0, AP_COEFF_S_INT,-2,1, AP_CST_S_INT,5, AP_END); array.p[2].constyp = AP_CONS_SUPEQ; array.p[2].linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2); ap_linexpr0_set_list(array.p[2].linexpr0, AP_COEFF_S_INT,4,0, AP_COEFF_S_INT,-4,2, AP_CST_S_INT,-1, AP_END); array.p[3].constyp = AP_CONS_SUPEQ; array.p[3].linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2); ap_linexpr0_set_list(array.p[3].linexpr0, AP_COEFF_S_INT,1,0, AP_COEFF_S_INT,1,2, AP_END); poly2 = pk_top(man,0,3); poly2 = pk_meet_lincons_array(man,true,poly2,&array); pk_fprint(stdout,man,poly2,NULL); tpoly[0] = poly0; tpoly[1] = poly1; tpoly[2] = poly2; poly = pk_join_array(man,tpoly,3); fprintf(stdout,"res\n"); pk_fprint(stdout,man,poly,NULL); ap_lincons0_array_clear(&array); pk_free(man,poly0); pk_free(man,poly1); pk_free(man,poly2); pk_free(man,poly); ap_manager_free(man); } int main(int argc, char**argv) { mine3(); pk_test_example(); srand(31); pk_test(0,6,6,1,3,20); pk_test(6,0,6,1,3,20); pk_test(6,10,6,1,3,20); pk_test(6,10,10,2,5,20); /* good for approximate(1) */ /* srand(31); pk_test(10,10,14,2,5,1000000); */ /* srand(31); pk_test(0,10,25,0,4,1000000); */ /* pk_test(10,10,30,2,5,5); */ } apron-dist-0.9.10/apron/newpolka/pk_expandfold.c0000640014525101416610000002023211247462105021467 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_expandfold.c: expanding and folding dimensions */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "pk_config.h" #include "pk_vector.h" #include "pk_bit.h" #include "pk_satmat.h" #include "pk_matrix.h" #include "pk.h" #include "pk_representation.h" #include "pk_user.h" #include "pk_constructor.h" #include "pk_assign.h" #include "pk_meetjoin.h" #include "pk_resize.h" /* ********************************************************************** */ /* I. Expand */ /* ********************************************************************** */ /* ---------------------------------------------------------------------- */ /* Matrix */ /* ---------------------------------------------------------------------- */ /* Expand the dimension dim of the matrix into (dimsup+1) dimensions, with dimsup new dimensions inserted just before offset. */ static matrix_t* matrix_expand(pk_internal_t* pk, bool destructive, matrix_t* C, ap_dim_t dim, size_t offset, size_t dimsup) { ap_dimchange_t* dimchange; size_t i,j,row,col,nb; size_t nbrows, nbcols; numint_t** p; matrix_t* nC; if (dimsup==0){ return destructive ? C : matrix_copy(C); } nbrows = C->nbrows; nbcols = C->nbcolumns; col = pk->dec + dim; /* Count the number of constraints to duplicate */ nb=0; p = C->p; for (i=0; idim[i]=offset; } nC = matrix_add_dimensions(pk,destructive,C,dimchange); ap_dimchange_free(dimchange); matrix_resize_rows(nC,nbrows+nb*dimsup); if (nb==0) return nC; /* Duplicate constraints */ p = nC->p; row = nbrows; for (i=0; idec+j],p[row][col]); numint_set_int(p[row][col],0); row++; } } } nC->_sorted = false; return nC; } /* ---------------------------------------------------------------------- */ /* Polyhedra */ /* ---------------------------------------------------------------------- */ pk_t* pk_expand(ap_manager_t* man, bool destructive, pk_t* pa, ap_dim_t dim, size_t dimsup) { size_t intdimsup,realdimsup; size_t nintdim,nrealdim; pk_t* po; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_EXPAND); pk_internal_realloc_lazy(pk,pa->intdim+pa->realdim+dimsup); man->result.flag_best = man->result.flag_exact = true; if (dimintdim){ intdimsup = dimsup; realdimsup = 0; } else { intdimsup = 0; realdimsup = dimsup; } nintdim = pa->intdim + intdimsup; nrealdim = pa->realdim + realdimsup; if (dimsup==0){ return (destructive ? pa : pk_copy(man,pa)); } /* Get the constraints system, and possibly minimize */ if (pk->funopt->algorithm<0) poly_obtain_C(man,pa,"of the argument"); else poly_chernikova(man,pa,"of the argument"); if (destructive){ po = pa; po->intdim+=intdimsup; po->realdim+=realdimsup; po->status &= ~pk_status_consgauss & ~pk_status_gengauss & ~pk_status_minimaleps; } else { po = poly_alloc(nintdim,nrealdim); } if (pk->exn){ pk->exn = AP_EXC_NONE; if (!pa->C){ man->result.flag_best = man->result.flag_exact = false; poly_set_top(pk,po); return po; } /* We can still proceed, although it is likely that the problem is only delayed */ } /* if empty, return empty */ if (!pa->C){ poly_set_bottom(pk,po); return po; } /* Prepare resulting matrix */ if (destructive){ if (po->F){ matrix_free(po->F); po->F = NULL; } if (po->satF){ satmat_free(po->satF); po->satF = NULL; } if (po->satC){ satmat_free(po->satC); po->satC = NULL; } po->nbeq = po->nbline = 0; po->status &= ~pk_status_consgauss & ~pk_status_gengauss & ~pk_status_minimaleps; } po->C = matrix_expand(pk, destructive, pa->C, dim, (dim + dimsup < po->intdim ? po->intdim-dimsup : po->intdim+po->realdim-dimsup), dimsup); /* Minimize the result */ if (pk->funopt->algorithm>0){ poly_chernikova(man,po,"of the result"); if (pk->exn){ pk->exn = AP_EXC_NONE; if (!po->C){ man->result.flag_best = man->result.flag_exact = false; poly_set_top(pk,po); return po; } } } assert(poly_check(pk,po)); return po; } /* ********************************************************************** */ /* II. Fold */ /* ********************************************************************** */ /* ---------------------------------------------------------------------- */ /* Matrix */ /* ---------------------------------------------------------------------- */ /* Fold the last dimsup dimensions with dimension dim (not in the last dimsup ones) in the matrix */ /* the array tdim is assumed to be sorted */ static matrix_t* matrix_fold(pk_internal_t* pk, bool destructive, matrix_t* F, ap_dim_t* tdim, size_t size) { matrix_t* nF; size_t i,j,row,col; size_t nbrows, nbcols, dimsup; ap_dimchange_t* dimchange; dimsup = size-1; if (dimsup==0){ return destructive ? F : matrix_copy(F); } nbrows = F->nbrows; nbcols = F->nbcolumns; col = pk->dec + tdim[0]; nF = matrix_alloc( size*nbrows, nbcols - dimsup, false ); dimchange = ap_dimchange_alloc(0,dimsup); for (i=0;idim[i]=tdim[i+1]; } row = 0; for(i=0; ip[row],F->p[i],nbcols, dimchange); vector_normalize(pk,nF->p[row],nbcols-dimsup); row++; for (j=0;jp[i][col], F->p[i][pk->dec+tdim[j+1]])!=0){ vector_remove_dimensions(pk, nF->p[row],F->p[i],nbcols, dimchange); numint_set(nF->p[row][col],F->p[i][pk->dec+tdim[j+1]]); vector_normalize(pk,nF->p[row],nbcols-dimsup); row++; } } } nF->nbrows = row; nF->_sorted = false; if (destructive){ matrix_free(F); } ap_dimchange_free(dimchange); return nF; } /* the array tdim is assumed to be sorted */ pk_t* pk_fold(ap_manager_t* man, bool destructive, pk_t* pa, ap_dim_t* tdim, size_t size) { size_t intdimsup,realdimsup; pk_t* po; pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_FOLD); man->result.flag_best = man->result.flag_exact = true; if (tdim[0]intdim){ intdimsup = size - 1; realdimsup = 0; } else { intdimsup = 0; realdimsup = size - 1; } if (pk->funopt->algorithm<0) poly_obtain_F(man,pa,"of the argument"); else poly_chernikova(man,pa,"of the argument"); if (destructive){ po = pa; po->intdim -= intdimsup; po->realdim -= realdimsup; } else { po = poly_alloc(pa->intdim-intdimsup,pa->realdim-realdimsup); } if (pk->exn){ pk->exn = AP_EXC_NONE; if (!pa->F){ man->result.flag_best = man->result.flag_exact = false; poly_set_top(pk,po); return po; } } /* if empty, return empty */ if (!pa->F){ man->result.flag_best = man->result.flag_exact = true; poly_set_bottom(pk,po); return po; } /* Prepare resulting matrix */ if (destructive){ if (po->C){ matrix_free(po->C); po->C = NULL; } if (po->satF){ satmat_free(po->satF); po->satF = NULL; } if (po->satC){ satmat_free(po->satC); po->satC = NULL; } po->nbeq = po->nbline = 0; po->status &= ~pk_status_consgauss & ~pk_status_gengauss & ~pk_status_minimaleps; } po->F = matrix_fold(pk, destructive, pa->F, tdim, size); /* Minimize the result */ if (pk->funopt->algorithm>0){ poly_chernikova(man,po,"of the result"); if (pk->exn){ pk->exn = AP_EXC_NONE; if (!po->C){ man->result.flag_best = man->result.flag_exact = false; poly_set_top(pk,po); return po; } } } man->result.flag_best = (intdimsup==0); man->result.flag_exact = (intdimsup==0); assert(poly_check(pk,po)); return po; } apron-dist-0.9.10/apron/newpolka/newpolka.texi0000640014525101416610000003441310620346716021231 0ustar bjeannetpopart@c This file is part of the APRON Library, released under LGPL @c license. Please read the COPYING file packaged in the distribution @c to be included from apron.texi The @sc{NewPolka} convex polyhedra and linear equalities library is aimed to be used through the APRON interface. However some specific points should be precised. First, @sc{NewPolka} can use several underlying representations for numbers, which lead to several library variants. Second, some specific functions are needed, typically to allocate managers, and to specify special options. @menu * Use of NewPolka:: * Allocating NewPolka managers and setting specific options:: * NewPolka standard options:: @end menu @c =================================================================== @node Use of NewPolka, Allocating NewPolka managers and setting specific options,,NewPolka @subsection Use of NewPolka @c =================================================================== To use @sc{NewPolka} in C, add @example #include "pk.h" #include "pkeq.h" /* if you want linear equalities */ @end example in your source file(s) and add @samp{-I$(APRON_PREFIX)/include} in the command line in your Makefile. You should also link your object files with the @sc{NewPolka} library to produce an executable, by adding something like @samp{-L$(APRON_PREFIX)/lib -lpolkag} in the command line in your Makefile (followed by the standard @samp{-lapron -litvmpq -litvdbl -L$(MPFR_PREFIX)/lib -lmpfr -L$(GMP_PREFIX)/lib -lgmp}). There are actually several variants of the library: @table @file @item libpolkai.a The underlying representation for integers is @code{long int}. This may easily cause overflows, especially with many dimensions or variables. Overflows are not detected but usually result in infinite looping. The underlying representation for integers is @code{long long int}. This may (less) easily cause overflows. @item libpolkag.a The underlying representation for integers is @code{mpz_t}, the multi-precision integers from the GNU GMP library. Overflows are not possible any more, but huge numbers may appear. @end table All scalars of type @code{double} are converted to scalars of type @code{mpq_t} inside NewPolka, as NewPolka works internally with exact rational arithmetics. So when possible it is better for the user (in term of efficiency) to convert already @code{double} scalars to @code{mpq_t} scalars. There is a way to prevent overflow and/or huge numbers, which is to position the options @code{max_coeff_size} and @code{approximate_max_coeff_size}, see @ref{Allocating NewPolka managers and setting specific options}. Also, all library are available in debug mode (@samp{libpolkai_debug.a}, .... @c =================================================================== @node Allocating NewPolka managers and setting specific options, NewPolka standard options, Use of NewPolka, NewPolka @subsection Allocating NewPolka managers and setting specific options @c =================================================================== @deftp datatype pk_internal_t NewPolka type for internal managers (specific to NewPolka, and specific to each execution thread in multithreaded programs). @end deftp @subheading Allocating managers @deftypefun ap_manager_t* pk_manager_alloc (bool @var{strict}) Allocate an APRON manager for convex polyhedra, linked to the NewPolka library. The @var{strict} option, when true, enables strict constraints in polyhedra (like @code{x>0}). Managers in strict mode or in loose mode (strict constraints disabled) are not compatible, and so are corresponding abstract values. @end deftypefun @deftypefun ap_manager_t* pkeq_manager_alloc () Allocate an APRON manager for linear equalities, linked to the NewPolka library. Most options which makes sense for convex polyhedra are meaningless for linear equalities. It is better to set the standard options associated to functions so that abstract values are in canonical form (@pxref{NewPolka standard options}). This is the default anyway. @end deftypefun @subheading Setting options Options specific to @sc{NewPolka} are set directly on the internal manager. It can be extracted with the @code{pk_manager_get_internal} function. @deftypefun pk_internal_t* pk_manager_get_internal (ap_manager_t* @var{man}) Return the internal submanager. If @var{man} has not been created by @code{pk_manager_alloc} or @code{pkeq_manager_alloc}, return @code{NULL}. @end deftypefun @deftypefun void pk_set_max_coeff_size (pk_internal_t* @var{pk}, size_t @var{size}) If @var{size} is not 0, try to raise an @code{AP_EXC_OVERFLOW} exception as soon as the size of an integer exceed @var{size}. Very incomplete implementation. Currently, used only in @file{libpolkag} variant, where the size is the number of limbs as returned by the function @code{mpz_size} of the GMP library. This allows to detect huge numbers. @end deftypefun @deftypefun void pk_set_approximate_max_coeff_size (pk_internal_t* @var{pk}, size_t @var{size}) This is the parameter to the @code{poly_approximate}/@code{ap_abstractX_approximate} functions. @end deftypefun @deftypefun size_t pk_get_max_coeff_size (pk_internal_t* @var{pk}) @deftypefunx size_t pk_get_approximate_max_coeff_size (pk_internal_t* @var{pk}) Reading the previous parameters. @end deftypefun @c =================================================================== @node NewPolka standard options, , Allocating NewPolka managers and setting specific options, NewPolka @subsection NewPolka standard options @c =================================================================== This section describes the NewPolka options which are selected using the standard mechanism offered by APRON (@pxref{Manager options}). @subsubheading Modes Most functions of NewPolka has two modes. In the lazy mode the canonicalization (computation of the dual representation and minimisation of both representations) of the argument polyhedra is performed only when the needed representation is not available. The resulting polyhedra is in general not in the canonical representation. In the strict mode, argument polyhedra are canonicalized (if they are not yet in canonical form) and the result is (in general) in canonical form. The strict mode exploits the incremental propery of the Chernikova algorithm and maintain in parallel the constraints and the generators representations. The lazy mode delays computations as much as possible. Be cautious, in the following table, canonical means minimized constraints and generators representation, but nothing more. In particular, the function @code{canonicalize} performs further normalization by normalizing strict constraints (when they exist) and ordering constraints and generators. @multitable @columnfractions .2 .06 .74 @item Function @tab algo @tab Comments @item copy @tab @tab Identical representation @item @item free @item @item size @tab @tab Return the number of coefficients. @* Their size (when using multi-precision integers) is not taken into account. @item @item minimize @tab @tab Require canonicalization. @noindent Keep only the smallest representation among the constraints and the generators representation. @item @item canonicalize @tab @tab @item @item approximate @tab @tab Require constraints. @* algo here refers to the explicit parameter of the function. A negative number indicates a possibly smaller result, a positive one a possibly greater one. The effects of the function may be different for 2 identical polyhedra defined by different systems of (non minimal) constraints.@* Equalities are never modified. @item @item @tab -1 @tab Normalize integer minimal constraints. This results in a smaller polyhedra. @item @tab 1 @tab Remove constraints with coefficients of size (in bits) greater than the approximate_max_coeff_size parameter. @item @tab 2 @tab Idem, but preserve interval constraints. @item @tab 3 @tab Idem, but preserve octagonal constraints (+/- xi +/- xj >= cst). @item @tab 10 @tab Simplify constraints such that the coefficients size (in bits) are less or equal than the approximate_max_coeff_size parameter. The constant coefficients are recomputed by linear programming and are not involved in the reduction process. @item @tab -- @tab Do nothing @item @item fprint @tab @tab Require canonicalization. @item @item fprintdiff @tab @tab not implemented @item @item fdump @tab @tab Print raw representations of any of the constraints, generators and saturation matrices that are available. @item @item serialize_raw, deserialize_raw @tab @tab not implemented @item @item bottom,top @tab @tab Return canonical form. @item @item of_box @tab @tab Return constraints. @item @item of_lincons_array @tab @tab Return constraints. @item @tab >=0 @tab Take into account interval-linear constraints, after having minimized the quasi-linear constraints @item @tab <0 @tab Ignore interval-linear constraints @item @item dimension @tab @tab @item @item is_bottom @tab <0 @tab If generators not available, return @code{tbool_top} @item @tab >=0 @tab If generators not available, canonicalize and return @code{tbool_false} or @code{tbool_true}. @item @item is_top @tab <0 @tab If not in canonical form, return @code{tbool_top} @item @tab >=0 @tab Require canonical form. @item @item is_leq @tab <=0 @tab Require generators of first argument and constraints of second argument. @item @tab >0 @tab Require canonical form for both arguments. @item @item is_eq @tab @tab Require canonical form for both arguments. @item @item is_dimension_unconstrained @tab @tab Require canonical form @item @item sat_interval, sat_lincons, bound_dimension, bound_linexpr @tab <=0 @tab Require generators. @item @tab >0 @tab Require canonical form. @item @item to_box @tab <0 @tab Require generators. @item @tab >=0 @tab Require canonical form. @item @item to_lincons_array, to_generator_array @tab @tab Require canonical form. @item @item meet, meet_array, meet_lincons_array @tab <0 @tab Require constraints. @* Return non-minimized constraints. @item @tab >=0 @tab Require canonical form. @* Return canonical form. @item @item join, join_array, add_ray_array @tab <0 @tab Require generators. @* Return non-minimized generators. @item @tab >=0 @tab Require canonical form. @* Return canonical form. @item @item assign_linexpr @tab @tab 1. If the optional argument is NULL, @item @tab <=0 @tab If the expr. is deterministic and invertible, require any representation and return the transformed one. If in canonical form, return canonical form. @* If the expr. is deterministic and non-invertible, require generators and return generators @* If the expr. is non-deterministic, require constraints and return generators. @item @tab >0 @tab Require canonical form, return canonical form. @* If the expr. is deterministic,(and even more, invertible), the operation is more efficient. @item @item @tab @tab 2. If the optional argument is not NULL, first the assignement is performed, and then the meet function is applied with its corresponding option. @item @item substitute_linexpr @tab @tab 1. If the optional argument is NULL, @item @tab <=0 @tab If the expr. is deterministic and invertible, require any representation and return the transformed one. If in canonical form, return canonical form. @* If the expr. is deterministic and non-invertible, require constraints and return constraints @* If the expr. is non-deterministic, require constraints and return generators. @item @tab >0 @tab Require canonical form, return canonical form. @* If the expr. is deterministic (and even more, invertible), the operation is more efficient. @item @item @tab @tab 2. If the optional argument is not NULL, first the substitution is performed, and then the meet function is applied with its corresponding option. @item @item assign_linexpr_array @tab @tab 1. If the optional argument is NULL, @item @tab <=0 @tab If the expr. are deterministic, require generators and return generators @* Otherwise, require canonical form and return generators. @item @tab >0 @tab Require canonical form, return canonical form. @item @item @tab @tab 2. If the optional argument is not NULL, first the assignement is performed, and then the meet function is applied with its corresponding option. @item @item substitute_linexpr_array @tab @tab 1. If the optional argument is NULL, @item @tab <=0 @tab If the expr. are deterministic, require constraints and return constraints @* Otherwise, require canonical form and return generators. @item @tab >0 @tab Require canonical form, return canonical form. @item @item @tab @tab 2. If the optional argument is not NULL, first the substitution is performed, and then the meet function is applied with its corresponding option. @item @item forget_array @tab <=0 @tab Require generators and return generators. @item @tab >0 @tab Require canonical form and return canonical form. @item @item add_dimensions, permute_dimensions @tab <=0 @tab Require any representation and return the updated one. @* If in canonical form, return canonical form. @item @tab >0 @tab Require canonical form, return canonical form. @item @item remove_dimensions @tab <=0 @tab Require generators, return generators. @item @tab >0 @tab Require canonical form, return canonical form. @item @item expand @tab <0 @tab Require constraints, return constraints. @item @tab >=0 @tab Require canonical form, return canonical form. @item @item fold @tab <0 @tab Require generators, return generators. @item @tab >=0 @tab Require canonical form, return canonical form. @item @item widening @tab @tab Require canonical form. @item @item closure @tab @tab 1. If pk_manager_alloc() has been given a false Boolean (no strict constraints), same as copy. @item @item @tab @tab 2. Otherwise, @item @tab <0 @tab Require constraints, return constraints. @item @tab >=0 @tab Require canonical form, return constraints. @end multitable apron-dist-0.9.10/apron/newpolka/README0000640014525101416610000000316111251675305017372 0ustar bjeannetpopart # This file is part of the APRON Library, released under LGPL # license. # Please read the COPYING file packaged in the distribution This package is a convex polyhedra library that conforms to the APRON interface. It requires APRON package. It includes both the C interface and the OCaml interface to APRON. Examples of use via the interface can be found in test0.c, test1.c, and test.ml. REQUIREMENTS ============ For the C interface: GMP library (tested with version 4.0 and up) ITV and NUM libraries APRON library For the OCaml interface, in addition: M4 preprocessor (standard on any UNIX system) OCaml 3.0 or up (tested with 3.09) Camlidl (tested with 1.05) MLGMPIDL package MLAPRONIDL package INSTALLATION ============ Set the file Makefile.config to your own setting. You might also have to modify the Makefile for executables 1. C Library ---------- type 'make', and then 'make install' The library is named libpolkaRl.a, libpolkaRll.a or libpolkaMPQ.a (and libpolkaRl_debug.a, ...). i, l, g, stands for long int, long long int, and gmp, which indicates the underlying representation of integers. For use via APRON, the include files to consider is pk.h When linking, requires resp. libitvlr.a (i), libitvllr.a (l), libitvmpq.a (g) plus libraries required by APRON. 2. OCaml Library ---------------- type 'make ml', and then 'make install' The C part of the library is named libpolkaXX_caml.a or libpolkaXX_caml.so/dllpolkaXX_caml.so (and libpolkaXX_caml_debug.a or ...). The OCaml part is named polkaXX.cma (polkaXX.cmxa) 3. Miscellaneous ---------------- 'make clean' and 'make distclean' have the usual behaviour. apron-dist-0.9.10/apron/newpolka/pk_satmat.h0000640014525101416610000000345210613136246020646 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_satmat.h: operations on saturation matrices */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ /* This header file define operations on saturation matrices. A saturation matrix is an array of bits (or an array of bitstrings) used to memorize wether a given generator saturate a given constraint. */ /* Saturation matrices are very similar to normal matrices as defined in matrix.h, where explanations can be found. */ #ifndef __PK_SATMAT_H__ #define __PK_SATMAT_H__ #include #include "pk_bit.h" #ifdef __cplusplus extern "C" { #endif typedef struct satmat_t { /* public part */ bitstring_t** p; size_t nbrows; size_t nbcolumns; /* private part */ size_t _maxrows; /* number of rows allocated */ } satmat_t; satmat_t* satmat_alloc(size_t nbrows, size_t nbcols); void satmat_resize_rows(satmat_t* sat, size_t nbrows); void satmat_resize_cols(satmat_t* sat, size_t nbcols); satmat_t* satmat_copy_resize_cols(satmat_t* sat, size_t nbcols); void satmat_free(satmat_t* sat); void satmat_clear(satmat_t* sat); satmat_t* satmat_copy(satmat_t* sat); void satmat_print(satmat_t* sat); void satmat_fprint(FILE* stream, satmat_t* sat); bitstring_t satmat_get(satmat_t* sat, size_t i, bitindex_t jx); void satmat_set(satmat_t* sat, size_t i, bitindex_t jx); void satmat_clr(satmat_t* sat, size_t i, bitindex_t jx); satmat_t* satmat_transpose(satmat_t* org, size_t nbcols); void satmat_exch_rows(satmat_t* sat, size_t l1, size_t l2); void satmat_move_rows(satmat_t* sat, size_t destrow, size_t orgrow, size_t size); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/newpolka/polka.mli0000640014525101416610000001535511252216517020330 0ustar bjeannetpopart(* File generated from polka.idl *) type internal (** Convex Polyhedra and Linear Equalities abstract domains *) type loose type strict (** Two flavors for convex polyhedra: loose or strict. Loose polyhedra cannot have strict inequality constraints like [x>0]. They are algorithmically more efficient (less generators, simpler normalization). Convex polyhedra are defined by the conjunction of a set of linear constraints of the form [a_0*x_0 + ... + a_n*x_n + b >= 0] or [a_0*x_0 + ... + a_n*x_n + b > 0] where [a_0, ..., a_n, b, c] are constants and [x_0, ..., x_n] variables. *) type equalities (** Linear equalities. Linear equalities are conjunctions of linear equalities of the form [a_0*x_0 + ... + a_n*x_n + b = 0]. *) type 'a t (** Type of convex polyhedra/linear equalities, where ['a] is [loose], [strict] or [equalities]. Abstract values which are convex polyhedra have the type [(loose t) Apron.Abstract0.t] or [(loose t) Apron.Abstract1.t] or [(strict t) Apron.Abstract0.t] or [(strict t) Apron.Abstract1.t]. Abstract values which are conjunction of linear equalities have the type [(equalities t) Apron.Abstract0.t] or [(equalities t) Apron.Abstract1.t]. Managers allocated by NewPolka have the type ['a t Apron.Manager.t]. *) (** Create a NewPolka manager for loose convex polyhedra. *) external manager_alloc_loose : unit -> loose t Apron.Manager.t = "camlidl_polka_pk_manager_alloc_loose" (** Create a NewPolka manager for strict convex polyhedra. *) external manager_alloc_strict : unit -> strict t Apron.Manager.t = "camlidl_polka_pk_manager_alloc_strict" (** Create a NewPolka manager for conjunctions of linear equalities. *) external manager_alloc_equalities : unit -> equalities t Apron.Manager.t = "camlidl_polka_pk_manager_alloc_equalities" (** Get the internal submanager of a NewPolka manager. *) external manager_get_internal : 'a t Apron.Manager.t -> internal = "camlidl_polka_manager_get_internal" (** Various options. See the C documentation *) external set_max_coeff_size : internal -> int -> unit = "camlidl_polka_pk_set_max_coeff_size" external set_approximate_max_coeff_size : internal -> int -> unit = "camlidl_polka_pk_set_approximate_max_coeff_size" external get_max_coeff_size : internal -> int = "camlidl_polka_pk_get_max_coeff_size" external get_approximate_max_coeff_size : internal -> int = "camlidl_polka_pk_get_approximate_max_coeff_size" (** {2 Type conversions} *) val manager_is_polka : 'a Apron.Manager.t -> bool val manager_is_polka_loose : 'a Apron.Manager.t -> bool val manager_is_polka_strict : 'a Apron.Manager.t -> bool val manager_is_polka_equalities : 'a Apron.Manager.t -> bool (** Return [true] iff the argument manager is a polka manager *) val manager_of_polka : 'a t Apron.Manager.t -> 'b Apron.Manager.t val manager_of_polka_loose : loose t Apron.Manager.t -> 'a Apron.Manager.t val manager_of_polka_strict : strict t Apron.Manager.t -> 'a Apron.Manager.t val manager_of_polka_equalities : equalities t Apron.Manager.t -> 'a Apron.Manager.t (** Makes a polka manager generic *) val manager_to_polka : 'a Apron.Manager.t -> 'b t Apron.Manager.t val manager_to_polka_loose : 'a Apron.Manager.t -> loose t Apron.Manager.t val manager_to_polka_strict : 'a Apron.Manager.t -> strict t Apron.Manager.t val manager_to_polka_equalities : 'a Apron.Manager.t -> equalities t Apron.Manager.t (** Instanciate the type of a polka manager. Raises [Failure] if the argument manager is not a polka manager *) module Abstract0 : sig val is_polka : 'a Apron.Abstract0.t -> bool val is_polka_loose : 'a Apron.Abstract0.t -> bool val is_polka_strict : 'a Apron.Abstract0.t -> bool val is_polka_equalities : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument manager is a polka value *) val of_polka : 'a t Apron.Abstract0.t -> 'b Apron.Abstract0.t val of_polka_loose : loose t Apron.Abstract0.t -> 'a Apron.Abstract0.t val of_polka_strict : strict t Apron.Abstract0.t -> 'a Apron.Abstract0.t val of_polka_equalities : equalities t Apron.Abstract0.t -> 'a Apron.Abstract0.t (** Makes a polka value generic *) val to_polka : 'a Apron.Abstract0.t -> 'b t Apron.Abstract0.t val to_polka_loose : 'a Apron.Abstract0.t -> loose t Apron.Abstract0.t val to_polka_strict : 'a Apron.Abstract0.t -> strict t Apron.Abstract0.t val to_polka_equalities : 'a Apron.Abstract0.t -> equalities t Apron.Abstract0.t (** Instanciate the type of a polka value. Raises [Failure] if the argument manager is not a polka manager *) end module Abstract1 : sig val is_polka : 'a Apron.Abstract1.t -> bool val is_polka_loose : 'a Apron.Abstract1.t -> bool val is_polka_strict : 'a Apron.Abstract1.t -> bool val is_polka_equalities : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument manager is a polka value *) val of_polka : 'a t Apron.Abstract1.t -> 'b Apron.Abstract1.t val of_polka_loose : loose t Apron.Abstract1.t -> 'a Apron.Abstract1.t val of_polka_strict : strict t Apron.Abstract1.t -> 'a Apron.Abstract1.t val of_polka_equalities : equalities t Apron.Abstract1.t -> 'a Apron.Abstract1.t (** Makes a polka value generic *) val to_polka : 'a Apron.Abstract1.t -> 'b t Apron.Abstract1.t val to_polka_loose : 'a Apron.Abstract1.t -> loose t Apron.Abstract1.t val to_polka_strict : 'a Apron.Abstract1.t -> strict t Apron.Abstract1.t val to_polka_equalities : 'a Apron.Abstract1.t -> equalities t Apron.Abstract1.t (** Instanciate the type of a polka value. Raises [Failure] if the argument manager is not a polka manager *) end (** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. {3 Bytecode compilation} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \ bigarray.cma gmp.cma apron.cma polkaMPQ.cma mlexample.ml]} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \ bigarray.cma gmp.cma apron.cma polkaMPQ.cma ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \ bigarray.cma gmp.cma apron.cma polkaMPQ.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa polkaMPQ.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa polkaMPQ.cmxa mlexample.ml \ -cclib "-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib \ -lpolkaMPQ_caml_debug -lpolkaMPQ_debug \ -lapron_caml_debug -lapron_debug \ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP_PREFIX/lib -lgmp \ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \ -lbigarray" ]} *) apron-dist-0.9.10/apron/newpolka/tmp/0000750014525101416610000000000011252216517017305 5ustar bjeannetpopartapron-dist-0.9.10/apron/newpolka/tmp/polka.ml0000640014525101416610000001643011252216517020752 0ustar bjeannetpopart(* File generated from polka.idl *) type internal_ptr (** Convex Polyhedra and Linear Equalities abstract domains *) type loose type strict (** Two flavors for convex polyhedra: loose or strict. Loose polyhedra cannot have strict inequality constraints like [x>0]. They are algorithmically more efficient (less generators, simpler normalization). Convex polyhedra are defined by the conjunction of a set of linear constraints of the form [a_0*x_0 + ... + a_n*x_n + b >= 0] or [a_0*x_0 + ... + a_n*x_n + b > 0] where [a_0, ..., a_n, b, c] are constants and [x_0, ..., x_n] variables. *) type equalities (** Linear equalities. Linear equalities are conjunctions of linear equalities of the form [a_0*x_0 + ... + a_n*x_n + b = 0]. *) type 'a t (** Type of convex polyhedra/linear equalities, where ['a] is [loose], [strict] or [equalities]. Abstract values which are convex polyhedra have the type [(loose t) Apron.Abstract0.t] or [(loose t) Apron.Abstract1.t] or [(strict t) Apron.Abstract0.t] or [(strict t) Apron.Abstract1.t]. Abstract values which are conjunction of linear equalities have the type [(equalities t) Apron.Abstract0.t] or [(equalities t) Apron.Abstract1.t]. Managers allocated by NewPolka have the type ['a t Apron.Manager.t]. *) external pk_manager_alloc_loose : unit -> Manager.ap_manager_ptr = "camlidl_polka_pk_manager_alloc_loose" external pk_manager_alloc_strict : unit -> Manager.ap_manager_ptr = "camlidl_polka_pk_manager_alloc_strict" external pk_manager_alloc_equalities : unit -> Manager.ap_manager_ptr = "camlidl_polka_pk_manager_alloc_equalities" external manager_get_internal : Manager.ap_manager_ptr -> internal_ptr = "camlidl_polka_manager_get_internal" external pk_set_max_coeff_size : internal_ptr -> int -> unit = "camlidl_polka_pk_set_max_coeff_size" external pk_set_approximate_max_coeff_size : internal_ptr -> int -> unit = "camlidl_polka_pk_set_approximate_max_coeff_size" external pk_get_max_coeff_size : internal_ptr -> int = "camlidl_polka_pk_get_max_coeff_size" external pk_get_approximate_max_coeff_size : internal_ptr -> int = "camlidl_polka_pk_get_approximate_max_coeff_size" let manager_is_polka man = let str = Apron.Manager.get_library man in let str = try String.sub str 0 5 with Invalid_argument _ -> "" in (String.compare str "polka")==0 let manager_of_polka (man:'a t Apron.Manager.t) : 'b Apron.Manager.t = Obj.magic man let manager_to_polka (man:'a Apron.Manager.t) : 'b t Apron.Manager.t = if manager_is_polka man then Obj.magic man else failwith "Polka.to_polka: the argument manager is not a Polka manager" let manager_is_polka_loose man = let str = Apron.Manager.get_library man in (String.compare str "polka, loose mode")==0 let manager_of_polka_loose (man:loose t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_polka_loose (man:'a Apron.Manager.t) : loose t Apron.Manager.t = if manager_is_polka_loose man then Obj.magic man else failwith "Polka.to_polka_loose: the argument manager is not a loose Polka manager" let manager_is_polka_strict man = let str = Apron.Manager.get_library man in (String.compare str "polka, strict mode")==0 let manager_of_polka_strict (man:strict t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_polka_strict (man:'a Apron.Manager.t) : strict t Apron.Manager.t = if manager_is_polka_strict man then Obj.magic man else failwith "Polka.to_polka_strict: the argument manager is not a strict Polka manager" let manager_is_polka_equalities man = let str = Apron.Manager.get_library man in (String.compare str "polka, equalities mode")==0 let manager_of_polka_equalities (man:equalities t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_polka_equalities (man:'a Apron.Manager.t) : equalities t Apron.Manager.t = if manager_is_polka_equalities man then Obj.magic man else failwith "Polka.to_polka_equalities: the argument manager is not an equalities Polka manager" module Abstract0 = struct let is_polka abs = manager_is_polka (Apron.Abstract0.manager abs) let is_polka_loose abs = manager_is_polka_loose (Apron.Abstract0.manager abs) let is_polka_strict abs = manager_is_polka (Apron.Abstract0.manager abs) let is_polka_equalities abs = manager_is_polka_equalities (Apron.Abstract0.manager abs) let of_polka (abs: 'a t Apron.Abstract0.t) : 'b Apron.Abstract0.t = Obj.magic abs let of_polka_loose (abs: loose t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let of_polka_strict (abs: strict t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let of_polka_equalities (abs: equalities t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let to_polka (abs:'a Apron.Abstract0.t) : 'b t Apron.Abstract0.t = if is_polka abs then Obj.magic abs else failwith "Polka.Abstract0.to_polka: the argument value is not a polka value" let to_polka_loose (abs:'a Apron.Abstract0.t) : loose t Apron.Abstract0.t = if is_polka_loose abs then Obj.magic abs else failwith "Polka.Abstract0.to_polka_loose: the argument value is not a loose polka value" let to_polka_strict (abs:'a Apron.Abstract0.t) : strict t Apron.Abstract0.t = if is_polka_strict abs then Obj.magic abs else failwith "Polka.Abstract0.to_polka_strict: the argument value is not a strict polka value" let to_polka_equalities (abs:'a Apron.Abstract0.t) : equalities t Apron.Abstract0.t = if is_polka_equalities abs then Obj.magic abs else failwith "Polka.Abstract0.to_polka_equalities: the argument value is not an equalities polka value" end module Abstract1 = struct let is_polka abs = manager_is_polka (Apron.Abstract1.manager abs) let is_polka_loose abs = manager_is_polka_loose (Apron.Abstract1.manager abs) let is_polka_strict abs = manager_is_polka (Apron.Abstract1.manager abs) let is_polka_equalities abs = manager_is_polka_equalities (Apron.Abstract1.manager abs) let of_polka (abs: 'a t Apron.Abstract1.t) : 'b Apron.Abstract1.t = Obj.magic abs let of_polka_loose (abs: loose t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let of_polka_strict (abs: strict t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let of_polka_equalities (abs: equalities t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let to_polka (abs:'a Apron.Abstract1.t) : 'b t Apron.Abstract1.t = if is_polka abs then Obj.magic abs else failwith "Polka.Abstract1.to_polka: the argument value is not a polka value" let to_polka_loose (abs:'a Apron.Abstract1.t) : loose t Apron.Abstract1.t = if is_polka_loose abs then Obj.magic abs else failwith "Polka.Abstract1.to_polka_loose: the argument value is not a loose polka value" let to_polka_strict (abs:'a Apron.Abstract1.t) : strict t Apron.Abstract1.t = if is_polka_strict abs then Obj.magic abs else failwith "Polka.Abstract1.to_polka_strict: the argument value is not a strict polka value" let to_polka_equalities (abs:'a Apron.Abstract1.t) : equalities t Apron.Abstract1.t = if is_polka_equalities abs then Obj.magic abs else failwith "Polka.Abstract1.to_polka_equalities: the argument value is not an equalities polka value" end apron-dist-0.9.10/apron/newpolka/tmp/polka.idl0000640014525101416610000003066411252216517021117 0ustar bjeannetpopart/* -*- mode: c -*- */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ quote(C,"#include \"pk.h\"") quote(C,"#include \"pkeq.h\"") quote(C,"#include \"ap_manager.h\"") quote(C,"#include \"apron_caml.h\"") quote(C,"typedef struct pk_internal_t* internal_ptr;") import "manager.idl"; typedef [abstract] struct pk_internal_t* internal_ptr; quote(MLMLI,"(** Convex Polyhedra and Linear Equalities abstract domains *)") quote(MLMLI," type loose type strict (** Two flavors for convex polyhedra: loose or strict. Loose polyhedra cannot have strict inequality constraints like [x>0]. They are algorithmically more efficient (less generators, simpler normalization). Convex polyhedra are defined by the conjunction of a set of linear constraints of the form [a_0*x_0 + ... + a_n*x_n + b >= 0] or [a_0*x_0 + ... + a_n*x_n + b > 0] where [a_0, ..., a_n, b, c] are constants and [x_0, ..., x_n] variables. *) type equalities (** Linear equalities. Linear equalities are conjunctions of linear equalities of the form [a_0*x_0 + ... + a_n*x_n + b = 0]. *) type 'a t (** Type of convex polyhedra/linear equalities, where ['a] is [loose], [strict] or [equalities]. Abstract values which are convex polyhedra have the type [(loose t) Apron.Abstract0.t] or [(loose t) Apron.Abstract1.t] or [(strict t) Apron.Abstract0.t] or [(strict t) Apron.Abstract1.t]. Abstract values which are conjunction of linear equalities have the type [(equalities t) Apron.Abstract0.t] or [(equalities t) Apron.Abstract1.t]. Managers allocated by NewPolka have the type ['a t Apron.Manager.t]. *) ") quote(MLI,"(** Create a NewPolka manager for loose convex polyhedra. *)") ap_manager_ptr pk_manager_alloc_loose() quote(call," _res = pk_manager_alloc(false); { ap_exc_t i; for (i=1; iinternal;"); quote(MLI,"(** Various options. See the C documentation *)\n") void pk_set_max_coeff_size(internal_ptr pk, unsigned int size); void pk_set_approximate_max_coeff_size(internal_ptr pk, unsigned int size); int pk_get_max_coeff_size(internal_ptr pk); int pk_get_approximate_max_coeff_size(internal_ptr pk); quote(MLI,"(** {2 Type conversions} *) val manager_is_polka : 'a Apron.Manager.t -> bool val manager_is_polka_loose : 'a Apron.Manager.t -> bool val manager_is_polka_strict : 'a Apron.Manager.t -> bool val manager_is_polka_equalities : 'a Apron.Manager.t -> bool (** Return [true] iff the argument manager is a polka manager *) val manager_of_polka : 'a t Apron.Manager.t -> 'b Apron.Manager.t val manager_of_polka_loose : loose t Apron.Manager.t -> 'a Apron.Manager.t val manager_of_polka_strict : strict t Apron.Manager.t -> 'a Apron.Manager.t val manager_of_polka_equalities : equalities t Apron.Manager.t -> 'a Apron.Manager.t (** Makes a polka manager generic *) val manager_to_polka : 'a Apron.Manager.t -> 'b t Apron.Manager.t val manager_to_polka_loose : 'a Apron.Manager.t -> loose t Apron.Manager.t val manager_to_polka_strict : 'a Apron.Manager.t -> strict t Apron.Manager.t val manager_to_polka_equalities : 'a Apron.Manager.t -> equalities t Apron.Manager.t (** Instanciate the type of a polka manager. Raises [Failure] if the argument manager is not a polka manager *) module Abstract0 : sig val is_polka : 'a Apron.Abstract0.t -> bool val is_polka_loose : 'a Apron.Abstract0.t -> bool val is_polka_strict : 'a Apron.Abstract0.t -> bool val is_polka_equalities : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument manager is a polka value *) val of_polka : 'a t Apron.Abstract0.t -> 'b Apron.Abstract0.t val of_polka_loose : loose t Apron.Abstract0.t -> 'a Apron.Abstract0.t val of_polka_strict : strict t Apron.Abstract0.t -> 'a Apron.Abstract0.t val of_polka_equalities : equalities t Apron.Abstract0.t -> 'a Apron.Abstract0.t (** Makes a polka value generic *) val to_polka : 'a Apron.Abstract0.t -> 'b t Apron.Abstract0.t val to_polka_loose : 'a Apron.Abstract0.t -> loose t Apron.Abstract0.t val to_polka_strict : 'a Apron.Abstract0.t -> strict t Apron.Abstract0.t val to_polka_equalities : 'a Apron.Abstract0.t -> equalities t Apron.Abstract0.t (** Instanciate the type of a polka value. Raises [Failure] if the argument manager is not a polka manager *) end module Abstract1 : sig val is_polka : 'a Apron.Abstract1.t -> bool val is_polka_loose : 'a Apron.Abstract1.t -> bool val is_polka_strict : 'a Apron.Abstract1.t -> bool val is_polka_equalities : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument manager is a polka value *) val of_polka : 'a t Apron.Abstract1.t -> 'b Apron.Abstract1.t val of_polka_loose : loose t Apron.Abstract1.t -> 'a Apron.Abstract1.t val of_polka_strict : strict t Apron.Abstract1.t -> 'a Apron.Abstract1.t val of_polka_equalities : equalities t Apron.Abstract1.t -> 'a Apron.Abstract1.t (** Makes a polka value generic *) val to_polka : 'a Apron.Abstract1.t -> 'b t Apron.Abstract1.t val to_polka_loose : 'a Apron.Abstract1.t -> loose t Apron.Abstract1.t val to_polka_strict : 'a Apron.Abstract1.t -> strict t Apron.Abstract1.t val to_polka_equalities : 'a Apron.Abstract1.t -> equalities t Apron.Abstract1.t (** Instanciate the type of a polka value. Raises [Failure] if the argument manager is not a polka manager *) end ") quote(ML," let manager_is_polka man = let str = Apron.Manager.get_library man in let str = try String.sub str 0 5 with Invalid_argument _ -> \"\" in (String.compare str \"polka\")==0 let manager_of_polka (man:'a t Apron.Manager.t) : 'b Apron.Manager.t = Obj.magic man let manager_to_polka (man:'a Apron.Manager.t) : 'b t Apron.Manager.t = if manager_is_polka man then Obj.magic man else failwith \"Polka.to_polka: the argument manager is not a Polka manager\" let manager_is_polka_loose man = let str = Apron.Manager.get_library man in (String.compare str \"polka, loose mode\")==0 let manager_of_polka_loose (man:loose t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_polka_loose (man:'a Apron.Manager.t) : loose t Apron.Manager.t = if manager_is_polka_loose man then Obj.magic man else failwith \"Polka.to_polka_loose: the argument manager is not a loose Polka manager\" let manager_is_polka_strict man = let str = Apron.Manager.get_library man in (String.compare str \"polka, strict mode\")==0 let manager_of_polka_strict (man:strict t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_polka_strict (man:'a Apron.Manager.t) : strict t Apron.Manager.t = if manager_is_polka_strict man then Obj.magic man else failwith \"Polka.to_polka_strict: the argument manager is not a strict Polka manager\" let manager_is_polka_equalities man = let str = Apron.Manager.get_library man in (String.compare str \"polka, equalities mode\")==0 let manager_of_polka_equalities (man:equalities t Apron.Manager.t) : 'a Apron.Manager.t = Obj.magic man let manager_to_polka_equalities (man:'a Apron.Manager.t) : equalities t Apron.Manager.t = if manager_is_polka_equalities man then Obj.magic man else failwith \"Polka.to_polka_equalities: the argument manager is not an equalities Polka manager\" module Abstract0 = struct let is_polka abs = manager_is_polka (Apron.Abstract0.manager abs) let is_polka_loose abs = manager_is_polka_loose (Apron.Abstract0.manager abs) let is_polka_strict abs = manager_is_polka (Apron.Abstract0.manager abs) let is_polka_equalities abs = manager_is_polka_equalities (Apron.Abstract0.manager abs) let of_polka (abs: 'a t Apron.Abstract0.t) : 'b Apron.Abstract0.t = Obj.magic abs let of_polka_loose (abs: loose t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let of_polka_strict (abs: strict t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let of_polka_equalities (abs: equalities t Apron.Abstract0.t) : 'a Apron.Abstract0.t = Obj.magic abs let to_polka (abs:'a Apron.Abstract0.t) : 'b t Apron.Abstract0.t = if is_polka abs then Obj.magic abs else failwith \"Polka.Abstract0.to_polka: the argument value is not a polka value\" let to_polka_loose (abs:'a Apron.Abstract0.t) : loose t Apron.Abstract0.t = if is_polka_loose abs then Obj.magic abs else failwith \"Polka.Abstract0.to_polka_loose: the argument value is not a loose polka value\" let to_polka_strict (abs:'a Apron.Abstract0.t) : strict t Apron.Abstract0.t = if is_polka_strict abs then Obj.magic abs else failwith \"Polka.Abstract0.to_polka_strict: the argument value is not a strict polka value\" let to_polka_equalities (abs:'a Apron.Abstract0.t) : equalities t Apron.Abstract0.t = if is_polka_equalities abs then Obj.magic abs else failwith \"Polka.Abstract0.to_polka_equalities: the argument value is not an equalities polka value\" end module Abstract1 = struct let is_polka abs = manager_is_polka (Apron.Abstract1.manager abs) let is_polka_loose abs = manager_is_polka_loose (Apron.Abstract1.manager abs) let is_polka_strict abs = manager_is_polka (Apron.Abstract1.manager abs) let is_polka_equalities abs = manager_is_polka_equalities (Apron.Abstract1.manager abs) let of_polka (abs: 'a t Apron.Abstract1.t) : 'b Apron.Abstract1.t = Obj.magic abs let of_polka_loose (abs: loose t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let of_polka_strict (abs: strict t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let of_polka_equalities (abs: equalities t Apron.Abstract1.t) : 'a Apron.Abstract1.t = Obj.magic abs let to_polka (abs:'a Apron.Abstract1.t) : 'b t Apron.Abstract1.t = if is_polka abs then Obj.magic abs else failwith \"Polka.Abstract1.to_polka: the argument value is not a polka value\" let to_polka_loose (abs:'a Apron.Abstract1.t) : loose t Apron.Abstract1.t = if is_polka_loose abs then Obj.magic abs else failwith \"Polka.Abstract1.to_polka_loose: the argument value is not a loose polka value\" let to_polka_strict (abs:'a Apron.Abstract1.t) : strict t Apron.Abstract1.t = if is_polka_strict abs then Obj.magic abs else failwith \"Polka.Abstract1.to_polka_strict: the argument value is not a strict polka value\" let to_polka_equalities (abs:'a Apron.Abstract1.t) : equalities t Apron.Abstract1.t = if is_polka_equalities abs then Obj.magic abs else failwith \"Polka.Abstract1.to_polka_equalities: the argument value is not an equalities polka value\" end ") quote(MLI,"\n(** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. {3 Bytecode compilation} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma polkaMPQ.cma mlexample.ml]} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \\ bigarray.cma gmp.cma apron.cma polkaMPQ.cma ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \\ bigarray.cma gmp.cma apron.cma polkaMPQ.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa polkaMPQ.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \\ bigarray.cmxa gmp.cmxa apron.cmxa polkaMPQ.cmxa mlexample.ml \\ -cclib \"-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib \\ -lpolkaMPQ_caml_debug -lpolkaMPQ_debug \\ -lapron_caml_debug -lapron_debug \\ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP_PREFIX/lib -lgmp \\ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \\ -lbigarray\" ]} *)") apron-dist-0.9.10/apron/newpolka/tmp/polka_stubs.c0000640014525101416610000001304711252216517022005 0ustar bjeannetpopart/* File generated from polka.idl */ #include #include #include #include #include #include #include #ifdef Custom_tag #include #include #endif #include #include "pk.h" #include "pkeq.h" #include "ap_manager.h" #include "apron_caml.h" typedef struct pk_internal_t* internal_ptr; extern void camlidl_apron_manager_funid_ml2c(value, ap_funid_t *); #define camlidl_ml2c_manager_ap_funid_t(v,c,ctx) camlidl_apron_manager_funid_ml2c(v,c) extern value camlidl_apron_manager_funid_c2ml(ap_funid_t *); #define camlidl_c2ml_manager_ap_funid_t(c,ctx) camlidl_apron_manager_funid_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_funopt_t(value, struct ap_funopt_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_funopt_t(struct ap_funopt_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_exc_ml2c(value, ap_exc_t *); #define camlidl_ml2c_manager_ap_exc_t(v,c,ctx) camlidl_apron_manager_exc_ml2c(v,c) extern value camlidl_apron_manager_exc_c2ml(ap_exc_t *); #define camlidl_c2ml_manager_ap_exc_t(c,ctx) camlidl_apron_manager_exc_c2ml(c) extern void camlidl_ml2c_manager_struct_ap_exclog_t(value, struct ap_exclog_t *, camlidl_ctx _ctx); extern value camlidl_c2ml_manager_struct_ap_exclog_t(struct ap_exclog_t *, camlidl_ctx _ctx); extern void camlidl_apron_manager_ptr_ml2c(value, ap_manager_ptr *); #define camlidl_ml2c_manager_ap_manager_ptr(v,c,ctx) camlidl_apron_manager_ptr_ml2c(v,c) extern value camlidl_apron_manager_ptr_c2ml(ap_manager_ptr *); #define camlidl_c2ml_manager_ap_manager_ptr(c,ctx) camlidl_apron_manager_ptr_c2ml(c) void camlidl_ml2c_polka_internal_ptr(value _v1, internal_ptr * _c2, camlidl_ctx _ctx) { *_c2 = *((internal_ptr *) Bp_val(_v1)); } value camlidl_c2ml_polka_internal_ptr(internal_ptr * _c2, camlidl_ctx _ctx) { value _v1; _v1 = camlidl_alloc((sizeof(internal_ptr) + sizeof(value) - 1) / sizeof(value), Abstract_tag); *((internal_ptr *) Bp_val(_v1)) = *_c2; return _v1; } value camlidl_polka_pk_manager_alloc_loose(value _unit) { ap_manager_ptr _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; /* begin user-supplied calling sequence */ _res = pk_manager_alloc(false); { ap_exc_t i; for (i=1; iinternal; /* end user-supplied calling sequence */ _vres = camlidl_c2ml_polka_internal_ptr(&_res, _ctx); camlidl_free(_ctx); return _vres; } value camlidl_polka_pk_set_max_coeff_size( value _v_pk, value _v_size) { internal_ptr pk; /*in*/ unsigned int size; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_polka_internal_ptr(_v_pk, &pk, _ctx); size = Int_val(_v_size); pk_set_max_coeff_size(pk, size); camlidl_free(_ctx); return Val_unit; } value camlidl_polka_pk_set_approximate_max_coeff_size( value _v_pk, value _v_size) { internal_ptr pk; /*in*/ unsigned int size; /*in*/ struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_polka_internal_ptr(_v_pk, &pk, _ctx); size = Int_val(_v_size); pk_set_approximate_max_coeff_size(pk, size); camlidl_free(_ctx); return Val_unit; } value camlidl_polka_pk_get_max_coeff_size( value _v_pk) { internal_ptr pk; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_polka_internal_ptr(_v_pk, &pk, _ctx); _res = pk_get_max_coeff_size(pk); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } value camlidl_polka_pk_get_approximate_max_coeff_size( value _v_pk) { internal_ptr pk; /*in*/ int _res; value _vres; struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; camlidl_ml2c_polka_internal_ptr(_v_pk, &pk, _ctx); _res = pk_get_approximate_max_coeff_size(pk); _vres = Val_int(_res); camlidl_free(_ctx); return _vres; } apron-dist-0.9.10/apron/newpolka/tmp/polka.mli0000640014525101416610000001542311252216517021124 0ustar bjeannetpopart(* File generated from polka.idl *) type internal_ptr (** Convex Polyhedra and Linear Equalities abstract domains *) type loose type strict (** Two flavors for convex polyhedra: loose or strict. Loose polyhedra cannot have strict inequality constraints like [x>0]. They are algorithmically more efficient (less generators, simpler normalization). Convex polyhedra are defined by the conjunction of a set of linear constraints of the form [a_0*x_0 + ... + a_n*x_n + b >= 0] or [a_0*x_0 + ... + a_n*x_n + b > 0] where [a_0, ..., a_n, b, c] are constants and [x_0, ..., x_n] variables. *) type equalities (** Linear equalities. Linear equalities are conjunctions of linear equalities of the form [a_0*x_0 + ... + a_n*x_n + b = 0]. *) type 'a t (** Type of convex polyhedra/linear equalities, where ['a] is [loose], [strict] or [equalities]. Abstract values which are convex polyhedra have the type [(loose t) Apron.Abstract0.t] or [(loose t) Apron.Abstract1.t] or [(strict t) Apron.Abstract0.t] or [(strict t) Apron.Abstract1.t]. Abstract values which are conjunction of linear equalities have the type [(equalities t) Apron.Abstract0.t] or [(equalities t) Apron.Abstract1.t]. Managers allocated by NewPolka have the type ['a t Apron.Manager.t]. *) (** Create a NewPolka manager for loose convex polyhedra. *) external pk_manager_alloc_loose : unit -> Manager.ap_manager_ptr = "camlidl_polka_pk_manager_alloc_loose" (** Create a NewPolka manager for strict convex polyhedra. *) external pk_manager_alloc_strict : unit -> Manager.ap_manager_ptr = "camlidl_polka_pk_manager_alloc_strict" (** Create a NewPolka manager for conjunctions of linear equalities. *) external pk_manager_alloc_equalities : unit -> Manager.ap_manager_ptr = "camlidl_polka_pk_manager_alloc_equalities" (** Get the internal submanager of a NewPolka manager. *) external manager_get_internal : Manager.ap_manager_ptr -> internal_ptr = "camlidl_polka_manager_get_internal" (** Various options. See the C documentation *) external pk_set_max_coeff_size : internal_ptr -> int -> unit = "camlidl_polka_pk_set_max_coeff_size" external pk_set_approximate_max_coeff_size : internal_ptr -> int -> unit = "camlidl_polka_pk_set_approximate_max_coeff_size" external pk_get_max_coeff_size : internal_ptr -> int = "camlidl_polka_pk_get_max_coeff_size" external pk_get_approximate_max_coeff_size : internal_ptr -> int = "camlidl_polka_pk_get_approximate_max_coeff_size" (** {2 Type conversions} *) val manager_is_polka : 'a Apron.Manager.t -> bool val manager_is_polka_loose : 'a Apron.Manager.t -> bool val manager_is_polka_strict : 'a Apron.Manager.t -> bool val manager_is_polka_equalities : 'a Apron.Manager.t -> bool (** Return [true] iff the argument manager is a polka manager *) val manager_of_polka : 'a t Apron.Manager.t -> 'b Apron.Manager.t val manager_of_polka_loose : loose t Apron.Manager.t -> 'a Apron.Manager.t val manager_of_polka_strict : strict t Apron.Manager.t -> 'a Apron.Manager.t val manager_of_polka_equalities : equalities t Apron.Manager.t -> 'a Apron.Manager.t (** Makes a polka manager generic *) val manager_to_polka : 'a Apron.Manager.t -> 'b t Apron.Manager.t val manager_to_polka_loose : 'a Apron.Manager.t -> loose t Apron.Manager.t val manager_to_polka_strict : 'a Apron.Manager.t -> strict t Apron.Manager.t val manager_to_polka_equalities : 'a Apron.Manager.t -> equalities t Apron.Manager.t (** Instanciate the type of a polka manager. Raises [Failure] if the argument manager is not a polka manager *) module Abstract0 : sig val is_polka : 'a Apron.Abstract0.t -> bool val is_polka_loose : 'a Apron.Abstract0.t -> bool val is_polka_strict : 'a Apron.Abstract0.t -> bool val is_polka_equalities : 'a Apron.Abstract0.t -> bool (** Return [true] iff the argument manager is a polka value *) val of_polka : 'a t Apron.Abstract0.t -> 'b Apron.Abstract0.t val of_polka_loose : loose t Apron.Abstract0.t -> 'a Apron.Abstract0.t val of_polka_strict : strict t Apron.Abstract0.t -> 'a Apron.Abstract0.t val of_polka_equalities : equalities t Apron.Abstract0.t -> 'a Apron.Abstract0.t (** Makes a polka value generic *) val to_polka : 'a Apron.Abstract0.t -> 'b t Apron.Abstract0.t val to_polka_loose : 'a Apron.Abstract0.t -> loose t Apron.Abstract0.t val to_polka_strict : 'a Apron.Abstract0.t -> strict t Apron.Abstract0.t val to_polka_equalities : 'a Apron.Abstract0.t -> equalities t Apron.Abstract0.t (** Instanciate the type of a polka value. Raises [Failure] if the argument manager is not a polka manager *) end module Abstract1 : sig val is_polka : 'a Apron.Abstract1.t -> bool val is_polka_loose : 'a Apron.Abstract1.t -> bool val is_polka_strict : 'a Apron.Abstract1.t -> bool val is_polka_equalities : 'a Apron.Abstract1.t -> bool (** Return [true] iff the argument manager is a polka value *) val of_polka : 'a t Apron.Abstract1.t -> 'b Apron.Abstract1.t val of_polka_loose : loose t Apron.Abstract1.t -> 'a Apron.Abstract1.t val of_polka_strict : strict t Apron.Abstract1.t -> 'a Apron.Abstract1.t val of_polka_equalities : equalities t Apron.Abstract1.t -> 'a Apron.Abstract1.t (** Makes a polka value generic *) val to_polka : 'a Apron.Abstract1.t -> 'b t Apron.Abstract1.t val to_polka_loose : 'a Apron.Abstract1.t -> loose t Apron.Abstract1.t val to_polka_strict : 'a Apron.Abstract1.t -> strict t Apron.Abstract1.t val to_polka_equalities : 'a Apron.Abstract1.t -> equalities t Apron.Abstract1.t (** Instanciate the type of a polka value. Raises [Failure] if the argument manager is not a polka manager *) end (** {2 Compilation information} See {!Introduction.compilation} for complete explanations. We just show examples with the file [mlexample.ml]. {3 Bytecode compilation} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.byte \ bigarray.cma gmp.cma apron.cma polkaMPQ.cma mlexample.ml]} {[ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -make-runtime -o myrun \ bigarray.cma gmp.cma apron.cma polkaMPQ.cma ocamlc -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -use-runtime myrun -o mlexample.byte \ bigarray.cma gmp.cma apron.cma polkaMPQ.cma mlexample.ml ]} {3 Native-code compilation} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa polkaMPQ.cmxa mlexample.ml ]} {3 Without auto-linking feature} {[ocamlopt -I $MLGMPIDL_PREFIX/lib -I $APRON_PREFIX/lib -noautolink -o mlexample.opt \ bigarray.cmxa gmp.cmxa apron.cmxa polkaMPQ.cmxa mlexample.ml \ -cclib "-L$MLGMPIDL_PREFIX/lib -L$APRON_PREFIX/lib \ -lpolkaMPQ_caml_debug -lpolkaMPQ_debug \ -lapron_caml_debug -lapron_debug \ -lgmp_caml -L$MPFR_PREFIX/lib -lmpfr -L$GMP_PREFIX/lib -lgmp \ -L$CAMLIDL_PREFIX/lib/ocaml -lcamlidl \ -lbigarray" ]} *) apron-dist-0.9.10/apron/newpolka/sedscript_caml0000640014525101416610000000077710574010271021433 0ustar bjeannetpoparts/Manager.ap_manager_ptr/'a t Apron.Manager.t/g; s/internal_ptr/internal/g; s/external pk_/external /g; s/external manager_alloc_loose : unit -> 'a t Apron.Manager.t/external manager_alloc_loose : unit -> loose t Apron.Manager.t/g; s/external manager_alloc_strict : unit -> 'a t Apron.Manager.t/external manager_alloc_strict : unit -> strict t Apron.Manager.t/g; s/external manager_alloc_equalities : unit -> 'a t Apron.Manager.t/external manager_alloc_equalities : unit -> equalities t Apron.Manager.t/g; apron-dist-0.9.10/apron/newpolka/pk_cherni.c0000640014525101416610000006724611247462105020633 0ustar bjeannetpopart/* ********************************************************************** */ /* pk_cherni.c: Conversion from one representation to the dual one. */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "pk_config.h" #include "pk_vector.h" #include "pk_bit.h" #include "pk_satmat.h" #include "pk_matrix.h" #include "pk_cherni.h" /* ********************************************************************** */ /* I. Checking function */ /* ********************************************************************** */ /* These functions perform coherence checks about minimized representation of polyhedra. cherni_checksatmat recomputes the saturation matrix of C and F and checks the equality with satC. */ bool cherni_checksatmat(pk_internal_t* pk, bool con_to_ray, matrix_t* C, matrix_t* F, satmat_t* satC) { int s1,s2; size_t i; bitindex_t j; for (i=0; inbrows; i++){ for (j = bitindex_init(0); j.index < C->nbrows; bitindex_inc(&j)){ vector_product(pk, pk->cherni_prod, F->p[i], C->p[j.index],F->nbcolumns); s1 = numint_sgn(pk->cherni_prod); s2 = satmat_get(satC,i,j); if (s1<0 || (s1!=0 && s2==0) || (s1==0 && s2!=0)){ printf("cherni_checksatmat con_to_ray=%d: ray %lu, con %lu\n", con_to_ray,(unsigned long)i,(unsigned long)j.index); printf("Constraints\n"); matrix_print(C); printf("Frames\n"); matrix_print(F); satmat_print(satC); return false; } } } return true; } /* This function checks the saturation numbers of constraints and rays. */ bool cherni_checksat(pk_internal_t* pk, bool con_to_ray, matrix_t* C, size_t nbequations, matrix_t* F, size_t nblines, satmat_t* satC) { size_t i,k,nb,rank; bitindex_t j; matrix_t* mat; bool res = true; const size_t nbcols = C->nbcolumns; /* saturation des rayons */ mat = matrix_alloc(C->nbrows,nbcols,false); for (i=0; inbrows; i++){ nb = 0; for (j = bitindex_init(0); j.index < C->nbrows; bitindex_inc(&j)){ if (satmat_get(satC,i,j)==0){ for (k=0;kp[nb][k],C->p[j.index][k]); } nb++; } } rank = cherni_gauss(pk,mat,nb); if (!( (numint_sgn(F->p[i][0])==0 && nb == C->nbrows) || (rank==nbcols-2-nblines && nb >= rank))){ printf("cherni_checksat con_to_ray=%d: wrong ray %lu; expected = %lu, effective = (%lu<=%lu)\n", con_to_ray,(unsigned long)i,(unsigned long)(nbcols-2-nblines), (unsigned long)rank,(unsigned long)nb); res = false; } } matrix_free(mat); /* saturation des contraintes */ mat = matrix_alloc(F->nbrows,nbcols,false); for (j = bitindex_init(0); j.index < C->nbrows; bitindex_inc(&j)){ nb = 0; for (i=0; inbrows; i++){ if (satmat_get(satC,i,j)==0){ for (k=0;kp[nb][k],F->p[i][k]); } nb++; } } rank = cherni_gauss(pk,mat,nb); if (!( (numint_sgn(C->p[j.index][0])==0 && nb == F->nbrows) || (rank==nbcols-2-nbequations && nb >= rank))){ printf("cherni_checksat con_to_ray=%d: wrong con %lu; expected = %lu, effective = (%lu<=%lu)\n", con_to_ray, (unsigned long)j.index, (unsigned long)(nbcols-2-nbequations), (unsigned long)rank,(unsigned long)nb); res = false; } } matrix_free(mat); if (res==false){ printf("Constraints\n"); matrix_print(C); printf("Frames\n"); matrix_print(F); satmat_print(satC); } return res; } /* ********************************************************************** */ /* II. Conversion algorithm */ /* ********************************************************************** */ void cherni_resize(matrix_t* mat, satmat_t* sat) { assert(mat->nbrows==sat->nbrows); size_t nbrows = mat->nbrows; size_t currentsize = mat->_maxrows >= sat->_maxrows ? mat->_maxrows : sat->_maxrows; size_t addsize = currentsize < 20 ? 10 : currentsize / 2; matrix_resize_rows(mat, currentsize+addsize); satmat_resize_rows(sat, currentsize+addsize); mat->nbrows = sat->nbrows = nbrows; return; } /* - con is the constraints matrix, - start indicates the number of constraints supposed to be already taken in account, - ray is the frames matrix, with the start first constraints taken in account, - satc is the saturation matrix initialized according to con and ray, row i of satc refer to ray i, column k refer to constraint k. - nbline indicates the number of lines in ray. One suppose that the saturation matrix has a maximum size of ray->polka_maxrows x bitindex_size(con->nbrows). For the saturation matrix, we suppose that Unused bits of existing rows (from 0 to start) are set to zero. Each time a row is added, this hypothese must remain true. The saturation matrix is organised as follows: - the rows are indexed by generators, - the columns by constraints. The result is given by ray, sat and pnbline. The status coefficient of rows of ray are set properly at the end of the function. Throw exception. */ size_t cherni_conversion(pk_internal_t* pk, matrix_t* con, size_t start, matrix_t* ray, satmat_t* satc, size_t nbline) { size_t i,j,l,w; int is_inequality; size_t index_non_zero; size_t equal_bound,sup_bound,inf_bound,bound; int nbcommonconstraints; bitindex_t k; bitstring_t m,aux; bool redundant; bitstring_t* bitstringp; const size_t nbcols = con->nbcolumns; const size_t satnbcols = bitindex_size(con->nbrows); size_t nbrows = ray->nbrows; bitstringp = bitstring_alloc(satnbcols); /* ================= Code ================== */ k = bitindex_init(start); while (k.index < con->nbrows){ /* Iteration sur les contraintes */ is_inequality = numint_sgn(con->p[k.index][0]); /* Scalar product and index: */ /* We compute for the new considered constraint its scalar products with each frame and put them into the first coefficient of the frames. Moreover we set index_non_zero to the index of the first frame that does not saturate the constraint. */ index_non_zero = nbrows; for (i=0; ip[i][0], ray->p[i], con->p[k.index],nbcols); if (index_non_zero == nbrows && numint_sgn(ray->p[i][0])!=0){ index_non_zero = i; } } if (index_non_zero < nbline){ /* If a line doesn't satisfy the constraint */ /* Line becomes ray: We transform the first line that does not saturate the constraint into a ray and computes a new pointed cone. */ /* remove it of lines and put it at index nbline */ nbline--; if (index_non_zero != nbline) matrix_exch_rows(ray,index_non_zero,nbline); /* compute new lineality space */ for (i=index_non_zero; ip[i][0]) != 0){ matrix_combine_rows(pk,ray,i,nbline,i,0); if (pk->exn) goto cherni_conversion_exit0; } /* orient the new ray */ if (numint_sgn(ray->p[nbline][0]) < 0) for (j=0; jp[nbline][j],ray->p[nbline][j]); /* compute the new pointed cone */ for (i=nbline+1; ip[i][0])){ matrix_combine_rows(pk,ray,i,nbline,i,0); if (pk->exn) goto cherni_conversion_exit0; } /* For the saturation matrix, we only add a column, */ /* so new bits are initialized to zero (see above) */ if (is_inequality){ /* rays saturates all apart the last inequality */ satmat_set(satc,nbline,k); } else { /* one remove the ray */ nbrows --; ray->nbrows --; satc->nbrows--; matrix_exch_rows(ray, nbline, nbrows); satmat_exch_rows(satc, nbline, nbrows); } bitindex_inc(&k); } else { /* if all lines saturates the constraint */ /* Sort the rays: */ /* Rays are sorted as follows: - nbline<= i < equal_bound: saturate the constraint; - equal_bound <= i < sup_bound: verify it; - sup_bound <= i < nbrows: do not verify it. */ equal_bound=nbline; sup_bound=nbline; inf_bound=nbrows; while (inf_bound>sup_bound) { int s = numint_sgn(ray->p[sup_bound][0]); if (s==0){ matrix_exch_rows(ray, sup_bound, equal_bound); satmat_exch_rows(satc, sup_bound, equal_bound); equal_bound++; sup_bound++; } else if (s<0) { inf_bound--; matrix_exch_rows(ray, sup_bound, inf_bound); satmat_exch_rows(satc, sup_bound, inf_bound); } else { sup_bound++; } } if (is_inequality && sup_bound == nbrows){ /* all rays satisfy the constraint:redundancy */ con->nbrows--; matrix_exch_rows(con, k.index, con->nbrows); } else { if (sup_bound==nbline){ /* no ray satisfies the constraint */ nbrows = ray->nbrows = satc->nbrows = nbline; } else { /* some rays do not satisfy the constraint */ /* Compute the new cones by combining adjacent constraints: */ bound = nbrows; for (i=equal_bound; ip[i][w] | satc->p[j][w]; bitstringp[w] = aux; for (m=bitstring_msb; m!=0; m>>=1) if ((aux & m)==0) nbcommonconstraints++; } aux = satc->p[i][k.word] | satc->p[j][k.word]; bitstringp[k.word] = aux; for (m=bitstring_msb; m!=k.bit; m>>=1){ if ((aux & m)==0) nbcommonconstraints++; } if (nbcommonconstraints+nbline>=nbcols-3){ /* possibly adjacent */ /* Does exist another ray saturating the same constraints ? */ redundant=false; for (l=nbline; lp[l][w] & ~(bitstringp[w])) break; } if (w>k.word){ redundant=true; break; } } } if (!redundant){ /* if not */ if (pk->funopt->max_object_size && nbrows * (nbcols - pk->dec) > pk->funopt->max_object_size){ /* out of space overflow */ pk->exn = AP_EXC_OUT_OF_SPACE; goto cherni_conversion_exit0; } if (nbrows>=matrix_get_maxrows(ray) || nbrows>=satc->_maxrows){ /* resize output matrices */ cherni_resize(ray,satc); } /* Compute the new ray and put it at end */ matrix_combine_rows(pk,ray,j,i,nbrows,0); if (pk->exn) goto cherni_conversion_exit0; /* New row in saturation matrix */ for (w=0; w<=k.word; w++){ satc->p[nbrows][w] = bitstringp[w]; } for (w=k.word+1; wp[nbrows][w] = 0; } nbrows ++; ray->nbrows ++; satc->nbrows ++; } } } } /* Remove non extremal rays by exchanging added rays */ /* with those that don't verify the constraint */ { size_t l; if (is_inequality){ j = sup_bound; for (l=equal_bound; lbound)) { i--; matrix_exch_rows(ray,i,j); satmat_exch_rows(satc,i,j); j++; } nbrows = (j==bound) ? i : j; ray->nbrows = satc->nbrows = nbrows; } } bitindex_inc(&k); } } } /* status coefficient */ for (i=0; ip[i][0],0); } for (i = nbline; ip[i][0],1); } ray->nbrows = satc->nbrows = nbrows; bitstring_free(bitstringp); return nbline; cherni_conversion_exit0: bitstring_free(bitstringp); return 0; } /* ********************************************************************** */ /* III. Simplification of origin representation */ /* ********************************************************************** */ /* ====================================================================== */ /* III.1 Gauss pivot */ /* ====================================================================== */ /* The function finds a minimal system for equalities, and returns the rank $r$ of this system, equations of which are numbered from $0$ to $r-1$. Redundant (now null) equations are put between row $r$ and row $nbeq$. The function also fills the array pk->cherni_intp which indicates the ``main'' coefficent of an equation, in this case the left-most non-zero one. */ size_t cherni_gauss(pk_internal_t* pk, matrix_t* con, size_t nbeq) { size_t i,j,k; numint_t** p = con->p; size_t rank = 0; int s = 0; for (j = con->nbcolumns-1; j>=1; j--){ /* find the first i such that p[i][j] is non zero */ for (i=rank; irank) { /* put it in rank */ matrix_exch_rows(con,i,rank); } if (s<0) { /* normalize with positive coefficient */ for (k=1; knbcolumns; k++) numint_neg(p[rank][k],p[rank][k]); } numint_set_int(p[rank][0],0); for (k=i+1; kcherni_intp[rank] = j; rank++; } } return rank; } /* ====================================================================== */ /* III.2 Backsubstitution */ /* ====================================================================== */ /* This function backsubstitute the coefficients according to the system of equations and the array pk->cherni_intp properly set by gauss. */ void cherni_backsubstitute(pk_internal_t* pk, matrix_t* con, size_t rank) { size_t i,j; int k; for (k=(int)rank-1; k>=0; k--) { j = pk->cherni_intp[k]; for (i=0; i<(size_t)k; i++) { if (numint_sgn(con->p[i][j])) matrix_combine_rows(pk,con,i,(size_t)k,i,j); } for (i=k+1; inbrows; i++) { if (numint_sgn(con->p[i][j])) matrix_combine_rows(pk,con,i,(size_t)k,i,j); } } } /* ====================================================================== */ /* III.3 Simplifying constraints (main function) */ /* ====================================================================== */ /* We suppose that we just obtained ray and satc from con with the chernikova algorithms. As a consequence the system of rays is minimal. satf is the transposed matrix of satc, i.e. rows are indexed by constraints. con is supposed to be non empty. We have still to simplify con by detecting new equality constraints, removing redundant inequalities, and obtaining a minimal system of equalities. This is performed by gauss elimination. Throw exception. */ int cherni_simplify(pk_internal_t* pk, matrix_t* con, matrix_t* ray, satmat_t* satf, size_t nbline) { size_t i,j; long int nb,nbj; size_t nbeq,rank; size_t w; bitstring_t m; bool redundant, is_equality; const size_t nbcols = con->nbcolumns; bitindex_t nbrays = bitindex_init(ray->nbrows); size_t nbcons = con->nbrows; con->_sorted = false; /* find the first inequality */ for (nbeq=0; nbeq < nbcons; nbeq ++){ if (numint_sgn(con->p[nbeq][0])) break; } /* For each constraint, - put it with equalities if it detected as one - or set the status word to the number of rays that saturates the constraint, */ for (i=nbeq; i < nbcons; i++){ is_equality = (numint_sgn(con->p[i][0])==0); if (!is_equality){ is_equality = true; for (w=0; wnbcolumns; w++){ if (satf->p[i][w]){ is_equality = false; break; } } } if (is_equality){ /* we have an equality */ numint_set_int(con->p[i][0],0); matrix_exch_rows(con, i,nbeq); satmat_exch_rows(satf,i,nbeq); nbeq++; } else { /* we count the number of zero bits */ nb = 0; for (w=0; w>=1) if ((satf->p[i][w] & m)==0) nb++; } for (m=bitstring_msb; m!=nbrays.bit; m>>=1) if ((satf->p[i][nbrays.word] & m)==0) nb++; numint_set_int(con->p[i][0],(int)nb); } } /* remove redundant equalities and update nbeq */ rank = cherni_gauss(pk,con, nbeq); /* gauss pivot to simplify equalities */ pk->exn = AP_EXC_NONE; /* remove redundants equations, located between rank and nbeq */ if (rank nbeq ) { i--; matrix_exch_rows(con, j,i); satmat_exch_rows(satf,j,i); j++; } nbcons += rank - nbeq; nbeq = rank; } /* remove trivially redundants inequalities (nb < nbcols-nbeq-2) */ i = nbeq; while (i < nbcons){ int_set_numint(&nb, con->p[i][0]); if (nb < (long int)(nbcols-nbeq-2)){ /* redundant constraint */ nbcons--; matrix_exch_rows(con, i,nbcons); satmat_exch_rows(satf,i,nbcons); } else i++; } /* remove others redundants inequalities */ i=nbeq; while (i < nbcons){ int_set_numint(&nb,con->p[i][0]); redundant = false; j = nbeq; while (j < nbcons){ int_set_numint(&nbj,con->p[j][0]); if (nbj > nb){ /* does j saturates a strictly overset ? */ redundant = true; for (w=0; wnbcolumns; w++){ if( ~(satf->p[i][w]) & satf->p[j][w] ){ redundant = false; break; } } if (redundant) break; else j++; } else if (nbj == nb && j != i){ /* is j mutually redundant with i ? */ is_equality = true; for (w=0; wnbcolumns; w++){ if( satf->p[i][w] != satf->p[j][w] ){ is_equality = false; break; } } if (is_equality){ /* yes: we can remove j */ nbcons--; matrix_exch_rows(con, j,nbcons); satmat_exch_rows(satf,j,nbcons); } else j++; } else j++; } if (redundant){ nbcons--; matrix_exch_rows(con, i,nbcons); satmat_exch_rows(satf,i,nbcons); } else i++; } /* setting status coefficient */ for (i=nbeq; ip[i][0],1); } con->nbrows = satf->nbrows = nbcons; /* back substitution of remaining constraints */ cherni_backsubstitute(pk, con, nbeq); pk->exn = AP_EXC_NONE; return nbeq; } /* ********************************************************************** */ /* IV. Minimization */ /* ********************************************************************** */ /* These functions have mainly a side-effect semantics */ /* They Throw exception. */ /* In all the following functions, for the structure poly_t: - If con_to_ray is true, standard meaning of everything - If con_to_ray is false, - matrices C and F, satC and satF have been exchanged, - nbeq and nbline have been exchanged - in status, nothing has changed (status is not used at this level) */ /* ====================================================================== */ /* IV.1 Standard minimization */ /* ====================================================================== */ /* po is a polyhedron with a non-empty constraint system, and empty frame and saturation matrices. */ #define CHERNI_FACTOR 2 static inline size_t uint_max(size_t a, size_t b) { return (a>b ? a : b); } void cherni_minimize(pk_internal_t* pk, bool con_to_ray, pk_t* po) { size_t i; bool special; matrix_t* C; matrix_t* F; satmat_t* satC; C = po->C; assert(matrix_is_sorted(C) && po->F==NULL && po->satC==NULL && po->satF==NULL); /* initialization of F and sat */ F = matrix_alloc(CHERNI_FACTOR*uint_max(C->nbrows, C->nbcolumns-1), C->nbcolumns,false); satC = satmat_alloc(F->nbrows, bitindex_size(C->nbrows)); F->nbrows = satC->nbrows = C->nbcolumns-1; for (i=0; inbcolumns-1; i++){ numint_set_int(F->p[i][i+1],1); } /* conversion */ pk->exn = AP_EXC_NONE; po->nbline = cherni_conversion(pk, C, 0, F, satC, C->nbcolumns-1); if (pk->exn){ /* out of space, overflow */ matrix_free(F); satmat_free(satC); po->nbeq = po->nbline = 0; } else { /* If con_to_ray, special case ? */ /* We have to test - In non-strict mode, that $\xi$ can be strictly positive. - In strict mode, that both $\xi$ and $\epsilon$ can be strictly positive. Because $\xi\geq\epsilon$, we just need to check that $\epslion$ can be strictly positive. */ if (con_to_ray){ special = true; for (i = po->nbline; inbrows; i++){ if (numint_sgn(F->p[i][pk->dec-1])>0){ special = false; break; } } if (special){ /* this means we have an empty polyhedron */ matrix_free(C); matrix_free(F); satmat_free(satC); po->C = 0; po->nbeq = po->nbline = 0; return; } } po->F = F; po->satF = satmat_transpose(satC,C->nbrows); satmat_free(satC); po->nbeq = cherni_simplify(pk,C,F,po->satF,po->nbline); if (F->_maxrows > 3*F->nbrows/2){ matrix_resize_rows(F,F->nbrows); satmat_resize_cols(po->satF,bitindex_size(F->nbrows)); } } } /* ====================================================================== */ /* IV.2 Adding of a matrix of constraints to a minimal representation */ /* ====================================================================== */ /* Same as previous function, but this time we assume that po is an already minimized polyhedron, with the start first constraints taken into account. The function takes into account the constraints numbered from start and returns with a minimized polyhedron. */ void cherni_add_and_minimize(pk_internal_t* pk, bool con_to_ray, pk_t* po, size_t start) { size_t i; bool special; matrix_t* C; matrix_t* F; satmat_t* satC; size_t nbrows,nbcols; assert(bitindex_size(po->C->nbrows)==po->satC->nbcolumns); C = po->C; F = po->F; satC = po->satC; nbrows = C->nbrows; nbcols = C->nbcolumns; assert(C!=NULL && F!=NULL && satC!=NULL); if (po->satF!=NULL){ satmat_free(po->satF); po->satF=NULL; } /* saturation matrix */ satmat_resize_cols(satC, bitindex_size(C->nbrows)); /* conversion */ F->_sorted = false; pk->exn = AP_EXC_NONE; po->nbline = cherni_conversion(pk, C,start,F,satC,po->nbline); if (pk->exn){ /* out of space, overflow */ matrix_free(F); satmat_free(satC); po->F = 0; po->satC = po->satF = 0; po->nbeq = po->nbline = 0; } else { /* If con_to_ray, special case ? */ /* We have to test - In non-strict mode, that $\xi$ can be strictly positive. - In strict mode, that both $\xi$ and $\epsilon$ can be strictly positive. Because $\xi\geq\epsilon$, we just need to check that $\epsilon$ can be strictly positive. */ if (con_to_ray){ special = true; for (i = po->nbline; inbrows; i++){ if (numint_sgn(F->p[i][pk->dec-1])>0){ special = false; break; } } if (special){ /* this means we have an empty polyhedron */ matrix_free(C); matrix_free(F); satmat_free(satC); po->C = po->F = 0; po->satC = 0; po->nbeq = po->nbline = 0; return; } } po->satF = satmat_transpose(satC,C->nbrows); satmat_free(satC); po->satC = NULL; po->nbeq = cherni_simplify(pk,C,F,po->satF,po->nbline); if (F->_maxrows > 3*F->nbrows/2){ matrix_resize_rows(F,F->nbrows); satmat_resize_cols(po->satF,bitindex_size(F->nbrows)); } } } /* ********************************************************************** */ /* V. Computation of saturation matrix */ /* ********************************************************************** */ /* Bits of satline are index by the constraints. satline are supoosed to be filled with zeros. */ void cherni_buildsatline(pk_internal_t* pk, matrix_t* con, numint_t* tab, bitstring_t* satline) { bitindex_t jx = bitindex_init(0); while (jx.indexnbrows){ vector_product(pk,pk->cherni_prod, con->p[jx.index], tab, con->nbcolumns); if (numint_sgn(pk->cherni_prod)) bitstring_set(satline,jx); bitindex_inc(&jx); } } /* ********************************************************************** */ /* VI. epsilon-Minimisation */ /* ********************************************************************** */ /* Library is supposed to be in strict mode (pk->strict==true), polyhedron is supposed to be in double representation, with nbeq and nbline correctly initialized, and with saturation matrix satF (row i of satF refers to constraint i, column k refers to ray k). */ bool cherni_minimizeeps(pk_internal_t* pk, pk_t* po) { bool is_minimaleps,change,removed; matrix_t* C; matrix_t* F; satmat_t* satF; size_t i,j,w,Fnbrows,satFnbcols; bitindex_t k; bitstring_t* mask1; bitstring_t* mask2; assert(pk->strict && po->C && po->F && po->satF); is_minimaleps = true; C = po->C; F = po->F; Fnbrows = po->F->nbrows; satF = po->satF; satFnbcols = satF->nbcolumns; /* Builds the mask for the 2 redundancy tests */ mask1 = bitstring_alloc(satFnbcols); mask2 = bitstring_alloc(satFnbcols); bitstring_clear(mask1,satFnbcols); bitstring_clear(mask2,satFnbcols); /* mask1: for testing if a constraint satisfies no closure generator points */ /* mask2: for testing if a constraint is subsumed by another by considering only closure points and rays */ /* Iterates on generators */ k = bitindex_init(po->nbline); while(k.index < Fnbrows){ if (numint_sgn(F->p[k.index][polka_eps])==0){ mask2[k.word] |= k.bit; if (numint_sgn(F->p[k.index][polka_cst])>0){ mask1[k.word] |= k.bit; } } bitindex_inc(&k); } /* Iterates on strict constraints that are no positivity constraint */ i = po->nbeq; while (inbrows){ removed = false; if (numint_sgn(C->p[i][polka_eps])<0 && !vector_is_positivity_constraint(pk,C->p[i],C->nbcolumns)){ /* 1. First tests if it does saturate no closure generator points */ /* Iterates on saturation line with mask1 */ /* We test if one always has: mask=1 ==> not (sat=0) */ bool sat_no_closuregen = true; for (w=0; wp[i][w] | ~mask1[w]; if (~sat != 0){ sat_no_closuregen = false; break; } } if (sat_no_closuregen){ removed = true; } else { /* 2. Check if there is no another constraint that subsumes it */ for (j=po->nbeq; jnbrows; j++){ if (j != i && numint_sgn(C->p[j][polka_eps])<0){ /* Iterates on closure points and rays */ bool included = true; for (w=0; w j==0 */ bitstring_t isincluded = ~satF->p[j][w] | satF->p[i][w] | ~mask2[w]; if (~isincluded != 0){ included = false;; break; } } if (included){ removed = true; break; } } } } } if (removed){ is_minimaleps = false; /* one remove the constraint */ C->nbrows--; satF->nbrows--; matrix_exch_rows(C, i, C->nbrows); satmat_exch_rows(satF, i, C->nbrows); } else { i++; } } bitstring_free(mask1); mask1=NULL; bitstring_free(mask2); mask2=NULL; if (is_minimaleps){ po->status |= pk_status_minimaleps; change = false; } else { po->status &= pk_status_conseps | pk_status_consgauss; po->status |= pk_status_minimaleps; matrix_free(po->F); po->F = NULL; satmat_free(po->satF); po->satF = NULL; if (po->satC){ satmat_free(po->satC); po->satC = NULL; } /* Re-add positivity constraint (note: we are sure there is one free row */ vector_clear(C->p[C->nbrows],C->nbcolumns); numint_set_int(C->p[C->nbrows][0],1); numint_set_int(C->p[C->nbrows][polka_cst],1); numint_set_int(C->p[C->nbrows][polka_eps],-1); C->_sorted = false; C->nbrows++; change = true; } if (!(po->status & pk_status_conseps)){ bool change2 = matrix_normalize_constraint(pk,po->C,po->intdim,po->realdim); if (change2){ if (po->F){ matrix_free(po->F); po->F = NULL; } if (po->satC){ satmat_free(po->satC); po->satC = NULL; } if (po->satF){ satmat_free(po->satF); po->satF = NULL; } } po->status |= pk_status_conseps; change = change || change2; } return change; } apron-dist-0.9.10/apron/newpolka/mf_qsort.h0000640014525101416610000000073010477316377020526 0ustar bjeannetpopart/* ********************************************************************** */ /* mf_qsort.h: quicksort */ /* ********************************************************************** */ #include #ifdef __cplusplus extern "C" { #endif #define QSORT_EXTRA_CMP_ARGUMENT typedef int (*qsort2_cmp)(void*, const void *,const void *); void qsort2(void *base_ptr, size_t count, size_t size, qsort2_cmp cmp, void *cmp_argument); #ifdef __cplusplus } #endif apron-dist-0.9.10/apron/README.mac0000640014525101416610000000264011023224037016277 0ustar bjeannetpopart This document tries to explain some specific points in compiling Apron under Macintosh. It brings additional information compared to the README. Note that this is work-in-progress. PREREQUISITES ------------- - GNU sed is required, instead of standard sed. - gcc 4.0.1 is reported to cause this problem at the end of the compilation process: ld: duplicate symbol ___gmpz_abs in ... more recent versions should work properly. The following Cygwin package are required: - gcc (Devel) - make (Devel) - gmp, mpfr (Math) - doxygen (Devel) - tetex-base (Publishing) Additionally, you'll need to install manually the following - OCaml 3.09 or better, from http://caml.inria.fr/ocaml/release.fr.html (the 3.08 version, in CygWin, at the time of writing is too old) - CamlIDL, from http://caml.inria.fr/pub/old_caml_site/camlidl/ CONFIGURATION ------------- Copy Makefile.config.model into Makefile.config and edit the _PREFIX paths to suit your installation (you might want to set APRON_PREFIX, CAMLIDL_PREFIX and CAML_PREFIX to /usr/local instead of the default /usr). The following options should be disabled: - HAS_CPP (Cygwin's gcc is too old) - HAS_PPL (Apron with PPL compilation untested under Windows) - HAS_LONG_DOUBLE (long double not supported by math library under Windows) Do the same with mlgmpidl/Makefile.config.model Now, (make rebuild), make and make install in the apron top-level directory should work. apron-dist-0.9.10/apron/examples/0000750014525101416610000000000011252216465016505 5ustar bjeannetpopartapron-dist-0.9.10/apron/examples/mlexample3.ml0000640014525101416610000001414311023224037021100 0ustar bjeannetpopart(* This file is part of the APRON Library, released under LGPL license. (use of PPL) Please read the COPYING file packaged in the distribution. *) (* with default setting: apronppltop -I $MLGMPIDL_INSTALL/lib -I $APRON_INSTALL/lib #load "gmp.cma";; #load "apron.cma";; #load "box.cma";; #load "oct.cma";; #load "polka.cma";; #load "ppl.cma";; #load "polkaGrid.cma";; #install_printer Apron.Linexpr1.print;; #install_printer Apron.Texpr1.print;; #install_printer Apron.Lincons1.print;; #install_printer Apron.Generator1.print;; #install_printer Apron.Abstract1.print;; let environment_print fmt x = Apron.Environment.print fmt x;; let lincons1_array_print fmt x = Apron.Lincons1.array_print fmt x;; let generator1_array_print fmt x = Apron.Generator1.array_print fmt x;; #install_printer Apron.Var.print;; #install_printer environment_print;; #install_printer lincons1_array_print;; #install_printer generator1_array_print;; *) open Apron;; open Mpqf;; open Format;; let print_array = Abstract0.print_array;; let lincons1_array_print fmt x = Lincons1.array_print fmt x ;; let generator1_array_print fmt x = Generator1.array_print fmt x ;; let manpk = Polka.manager_alloc_strict();; let manbox = Box.manager_alloc ();; let manoct = Oct.manager_alloc ();; let manppl = Ppl.manager_alloc_strict();; let mangrid = Ppl.manager_alloc_grid ();; let maneq = Polka.manager_alloc_equalities ();; let manpkgrid = PolkaGrid.manager_alloc_loose ();; let var_x = Var.of_string "x";; let var_y = Var.of_string "y";; let var_z = Var.of_string "z";; let var_w = Var.of_string "w";; let var_u = Var.of_string "u";; let var_v = Var.of_string "v";; let var_a = Var.of_string "a";; let var_b = Var.of_string "b";; let ex1 (man:'a Manager.t) : 'a Abstract1.t = printf "Using Library: %s, version %s@." (Manager.get_library man) (Manager.get_version man); let env = Environment.make [|var_x; var_y; var_z; var_w|] [|var_u; var_v; var_a; var_b|] in let env2 = Environment.make [|var_x; var_y; var_z; var_w|] [||] in printf "env=%a@.env2=%a@." (fun x -> Environment.print x) env (fun x -> Environment.print x) env2 ; (* Creation of abstract value 1/2x+2/3y=1, [1,2]<=z+2w<=4, 0<=u<=5 *) let tab = Parser.lincons1_of_lstring env ["1/2x+2/3y=1"; "[1;2]<=z+2w";"z+2w<=4"; "0<=u";"u<=5"] in printf "tab = %a@." lincons1_array_print tab; let abs = Abstract1.of_lincons_array man env tab in printf "abs=%a@." Abstract1.print abs; (* Extraction (we first extract values for existing constraints, then for dimensions) *) let box = Abstract1.to_box man abs in printf "box=%a@." (print_array Interval.print) box.Abstract1.interval_array; for i=0 to 4 do let expr = Lincons1.get_linexpr1 (Lincons1.array_get tab i) in let box = Abstract1.bound_linexpr man abs expr in printf "Bound of %a = %a@." Linexpr1.print expr Interval.print box; done; (* 2. dimensions *) (* 3. of box *) let abs2 = Abstract1.of_box man env [|var_x; var_y; var_z; var_w; var_u; var_v; var_a; var_b|] box.Abstract1.interval_array in printf "abs2=%a@." Abstract1.print abs2; (* 4. Tests top and bottom *) let abs3 = Abstract1.bottom man env in printf "abs3=%a@.is_bottom(abs3)=%b@." Abstract1.print abs3 (Abstract1.is_bottom man abs3); printf "abs=%a@." Abstract1.print abs; let p2 = Abstract1.expand man abs var_y [|Var.of_string "y1"; Var.of_string "y2"|] in printf "p2=expand(abs,y,[y1,y2]))=%a@." Abstract1.print p2; let p2 = Abstract1.expand man abs var_u [|Var.of_string "u1"; Var.of_string "u2"|] in printf "p2=expand(abs,u,[u1,u2]))=%a@." Abstract1.print p2; (* Tree expressions *) let texpr = Parser.texpr1_of_string env "a + (x*y*y/sqrt(b))" in let abs2 = Abstract1.assign_texpr man abs var_u texpr None in printf "abs2=%a@." Abstract1.print abs2; abs ;; let ex2 (man:'a Manager.t) = let env = Environment.make [||] [|var_x; var_y; var_z|] in (* Creation of abstract value 5<=x<=14, 4<=y<=12, z=0 *) let abs1 = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int 5 14; Interval.of_int 4 12; Interval.of_int 0 0; |] in let abs2 = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int 3 12; Interval.of_int 5 13; Interval.of_int 1 1; |] in let abs3 = Abstract1.join man abs1 abs2 in abs3 ;; (* Comparing join of two different assignements and assignement by the "join" of expressions *) let ex3 (man:'a Manager.t) = let env = Environment.make [||] [|var_x; var_y; var_z|] in (* Creation of abstract value -3<=x<=-2, 10<=y<=12, -1<=z<=1 *) let abs = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int (-3) (-2); Interval.of_int 10 12; Interval.of_int (-1) (1) |] in (* Creation of linear expressions *) let linexpr1 = Parser.linexpr1_of_string env "z+x+2y" in let linexpr2 = Parser.linexpr1_of_string env "z+2x+y" in let abs1 = Abstract1.assign_linexpr man abs var_z linexpr1 None in let abs2 = Abstract1.assign_linexpr man abs var_z linexpr2 None in let res1 = Abstract1.join man abs1 abs2 in printf "abs=%a@.abs1=%a@.abs2=%a@.res1=%a@." Abstract1.print abs Abstract1.print abs1 Abstract1.print abs2 Abstract1.print res1; (* Creation of linear expression [1,2]y and [1,2]z *) let linexpr = Parser.linexpr1_of_string env "z + [1;2]x + [1;2]y" in let res2 = Abstract1.assign_linexpr man abs var_z linexpr None in printf "res2=%a@." Abstract1.print res2 ; let abs1 = Abstract1.substitute_linexpr man res1 var_z linexpr1 None in let abs2 = Abstract1.substitute_linexpr man res1 var_z linexpr2 None in let res1 = Abstract1.join man abs1 abs2 in printf "abs1=%a@.abs2=%a@.res1=%a@." Abstract1.print abs1 Abstract1.print abs2 Abstract1.print res1 ; let res2 = Abstract1.substitute_linexpr man res2 var_z linexpr None in printf "res2=%a@." Abstract1.print res2 ; res1 ;; let abs1 = ex1 manpk;; let abs2 = ex1 manppl;; let abs3 = ex1 manoct;; let abs4 = ex1 manbox;; let abs5 = ex1 maneq;; let abs6 = ex1 mangrid;; let abs7 = ex1 manpkgrid;; apron-dist-0.9.10/apron/examples/example1.c0000640014525101416610000003656410620623146020400 0ustar bjeannetpopart/* ********************************************************************** */ /* example1.c: using APRON library */ /* ********************************************************************** */ /* We illustrate here the use of the APRON interface, at level 1 */ #include "ap_global0.h" #include "ap_global1.h" #include "box.h" #include "oct.h" #include "pk.h" #include "pkeq.h" #include "apron_ppl.h" void ex1(ap_manager_t* man) { printf("******************************\n"); printf("ex1\n"); printf("Library %s, version %s\n",man->library,man->version); printf("******************************\n"); ap_var_t name_of_dim[6] = { "x","y","z","u","w","v" }; ap_environment_t* env = ap_environment_alloc(&name_of_dim[0],3,&name_of_dim[3],3); /* =================================================================== */ /* Creation of polyhedra 1/2x+2/3y=1, [1,2]<=z+2w<=4 */ /* =================================================================== */ /* 0. Create the array */ ap_lincons1_array_t array = ap_lincons1_array_make(env,3); /* 1.a Creation of an equality constraint 1/2x+2/3y=1 */ ap_linexpr1_t expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,2); ap_lincons1_t cons = ap_lincons1_make(AP_CONS_EQ,&expr,NULL); /* Now expr is memory-managed by cons */ /* 1.b Fill the constraint */ ap_lincons1_set_list(&cons, AP_COEFF_S_FRAC,1,2,"x", AP_COEFF_S_FRAC,2,3,"y", AP_CST_S_INT,1, AP_END); /* 1.c Put in the array */ ap_lincons1_array_set(&array,0,&cons); /* Now cons is memory-managed by array */ /* 2.a Creation of an inequality constraint [1,2]<=z+2w */ expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,2); cons = ap_lincons1_make(AP_CONS_SUPEQ,&expr,NULL); /* The old cons is not lost, because it is stored in the array. It would be an error to clear it (same for expr). */ /* 2.b Fill the constraint */ ap_lincons1_set_list(&cons, AP_COEFF_S_INT,1,"z", AP_COEFF_S_DOUBLE,2.0,"w", AP_CST_I_INT,-2,-1, AP_END); /* 2.c Put in the array */ ap_lincons1_array_set(&array,1,&cons); /* 2.a Creation of an inequality constraint */ expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,2); cons = ap_lincons1_make(AP_CONS_SUPEQ,&expr,NULL); /* The old cons is not lost, because it is stored in the array. It would be an error to clear it (same for expr). */ /* 2.b Fill the constraint */ ap_lincons1_set_list(&cons, AP_COEFF_S_INT,1,"z", AP_COEFF_S_DOUBLE,2.0,"w", AP_CST_I_INT,-2,-1, AP_END); /* 2.c Put in the array */ ap_lincons1_array_set(&array,1,&cons); /* 3.a Creation of an inequality constraint by duplication and modification z+2w<=4 */ cons = ap_lincons1_copy(&cons); /* 3.b Fill the constraint (by negating the existing coefficients) */ expr = ap_lincons1_linexpr1ref(&cons); { ap_coeff_t* pcoeff; ap_var_t var; size_t i; ap_linexpr1_ForeachLinterm1(&expr,i,var,pcoeff){ ap_coeff_neg(pcoeff,pcoeff); } } ap_linexpr1_set_cst_scalar_int(&expr,4); /* 3.c Put in the array */ ap_lincons1_array_set(&array,2,&cons); /* 4. Creation of an abstract value */ ap_abstract1_t abs = ap_abstract1_of_lincons_array(man,env,&array); fprintf(stdout,"Abstract value:\n"); ap_abstract1_fprint(stdout,man,&abs); /* deallocation */ ap_lincons1_array_clear(&array); /* =================================================================== */ /* Creation of polyhedra x+y+z+w+u=0, 0<= w <= 5, -5<=u<=0, x+y-z-w>=0, */ /* =================================================================== */ array = ap_lincons1_array_make(env,6); expr = ap_linexpr1_make(env,AP_LINEXPR_DENSE,0); cons = ap_lincons1_make(AP_CONS_EQ,&expr,NULL); ap_linexpr1_set_list(&expr, AP_COEFF_S_INT,1,"x", AP_COEFF_S_INT,1,"y", AP_COEFF_S_INT,1,"z", AP_COEFF_S_INT,1,"w", AP_COEFF_S_INT,1,"u", AP_END); ap_lincons1_array_set(&array,0,&cons); expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,0); cons = ap_lincons1_make(AP_CONS_SUPEQ,&expr,NULL); ap_linexpr1_set_list(&expr, AP_COEFF_S_INT,1,"w",AP_END); ap_lincons1_array_set(&array,1,&cons); expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,0); cons = ap_lincons1_make(AP_CONS_SUPEQ,&expr,NULL); ap_linexpr1_set_list(&expr, AP_COEFF_S_INT,-1,"w",AP_CST_S_INT,5, AP_END); ap_lincons1_array_set(&array,2,&cons); expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,0); cons = ap_lincons1_make(AP_CONS_SUPEQ,&expr,NULL); ap_linexpr1_set_list(&expr, AP_COEFF_S_INT,1,"u",AP_CST_S_INT,5, AP_END); ap_lincons1_array_set(&array,3,&cons); expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,0); cons = ap_lincons1_make(AP_CONS_SUPEQ,&expr,NULL); ap_linexpr1_set_list(&expr, AP_COEFF_S_INT,-1,"u",AP_END); ap_lincons1_array_set(&array,4,&cons); expr = ap_linexpr1_make(env,AP_LINEXPR_DENSE,0); cons = ap_lincons1_make(AP_CONS_EQ,&expr,NULL); ap_linexpr1_set_list(&expr, AP_COEFF_S_INT,1,"x", AP_COEFF_S_INT,1,"y", AP_COEFF_S_INT,-1,"z", AP_COEFF_S_INT,-1,"w", AP_END); ap_lincons1_array_set(&array,5,&cons); ap_abstract1_t abs2 = ap_abstract1_of_lincons_array(man,env,&array); fprintf(stdout,"Abstract value 2:\n"); ap_abstract1_fprint(stdout,man,&abs2); ap_lincons1_array_clear(&array); /* =================================================================== */ /* Meet and Join */ /* =================================================================== */ ap_abstract1_t res = ap_abstract1_meet(man,false,&abs,&abs2); fprintf(stdout,"Meet:\n"); ap_abstract1_fprint(stdout,man,&res); ap_abstract1_clear(man,&res); res = ap_abstract1_join(man,false,&abs,&abs2); fprintf(stdout,"Join:\n"); ap_abstract1_fprint(stdout,man,&res); ap_abstract1_clear(man,&res); /* =================================================================== */ /* Assignement */ /* =================================================================== */ expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,0); ap_linexpr1_set_list(&expr, AP_COEFF_S_INT,-3,"w", AP_COEFF_S_DOUBLE,2.625,"z", AP_CST_I_INT,0,3, AP_END); fprintf(stdout,"Assignement (side-effect) in abstract value of u by expression:\n"); ap_linexpr1_fprint(stdout,&expr); abs = ap_abstract1_assign_linexpr(man,true,&abs,"u",&expr,NULL); fprintf(stdout,"\n"); ap_abstract1_fprint(stdout,man,&abs); ap_linexpr1_clear(&expr); /* deallocation */ ap_abstract1_clear(man,&abs); ap_abstract1_clear(man,&abs2); ap_environment_free(env); } void ex2(ap_manager_t* man) { printf("******************************\n"); printf("ex2\n"); printf("Library %s, version %s\n",man->library,man->version); printf("******************************\n"); ap_var_t name_of_dim[6] = { "x","y","z","u","w","v" }; ap_var_t tab[2] = { "x","y" }; ap_environment_t* env = ap_environment_alloc(&name_of_dim[0],3,&name_of_dim[3],3); /* =================================================================== */ /* Creation of polyhedra -39x + 40y >= 0 -6x - 20y + 85 >= 0 x >= 0 */ /* =================================================================== */ /* 0. Create the array */ ap_lincons1_array_t array = ap_lincons1_array_make(env,3); /* 1.a Creation of constraint -39x + 40y >= 0 */ ap_linexpr1_t expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,2); ap_lincons1_t cons = ap_lincons1_make(AP_CONS_SUPEQ,&expr,NULL); /* Now expr is memory-managed by cons */ /* 1.b Fill the constraint */ ap_lincons1_set_list(&cons, AP_COEFF_S_INT,-39,"x", AP_COEFF_S_INT,40,"y", AP_CST_S_INT,0, AP_END); /* 1.c Put in the array */ ap_lincons1_array_set(&array,0,&cons); /* Now cons is memory-managed by array */ /* 2.a Creation of an inequality constraint -6x - 20y + 85 >= 0 */ expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,2); cons = ap_lincons1_make(AP_CONS_SUPEQ,&expr,NULL); /* The old cons is not lost, because it is stored in the array. It would be an error to clear it (same for expr). */ /* 2.b Fill the constraint */ ap_lincons1_set_list(&cons, AP_COEFF_S_INT,-6,"x", AP_COEFF_S_INT,-20,"y", AP_CST_S_INT,85, AP_END); /* 2.c Put in the array */ ap_lincons1_array_set(&array,1,&cons); /* 3.a Creation of an inequality constraint x >= 0 */ expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,1); cons = ap_lincons1_make(AP_CONS_SUPEQ,&expr,NULL); /* The old cons is not lost, because it is stored in the array. It would be an error to clear it (same for expr). */ /* 3.b Fill the constraint */ ap_lincons1_set_list(&cons, AP_COEFF_S_INT,1,"x", AP_CST_S_INT,0, AP_END); /* 3.c Put in the array */ ap_lincons1_array_set(&array,2,&cons); ap_abstract1_t abs = ap_abstract1_of_lincons_array(man,env,&array); fprintf(stdout,"Abstract value:\n"); ap_abstract1_fprint(stdout,man,&abs); ap_abstract1_t abs2 = ap_abstract1_fold(man,false,&abs,tab,2); fprintf(stdout,"Abstract value 2:\n"); ap_abstract1_fprint(stdout,man,&abs2); ap_lincons1_array_clear(&array); ap_abstract1_clear(man,&abs); ap_abstract1_clear(man,&abs2); ap_environment_free(env); } void ex3(ap_manager_t* man) { printf("******************************\n"); printf("ex3\n"); printf("Library %s, version %s\n",man->library,man->version); printf("******************************\n"); ap_var_t name_of_dim[6] = { "x","y","z","u","w","v" }; ap_var_t tab[2] = { "x","y" }; ap_environment_t* env = ap_environment_alloc(&name_of_dim[0],6,NULL,0); /* =================================================================== */ /* Creation of polyhedra -39x + 40y = 0 -3x - 10z + 43 = 0 -6x - 20y + 86 >= 0 */ /* =================================================================== */ /* 0. Create the array */ ap_lincons1_array_t array = ap_lincons1_array_make(env,1); /* 1.a Creation of constraint -39x + 40y = 0 */ ap_linexpr1_t expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,2); ap_lincons1_t cons = ap_lincons1_make(AP_CONS_EQ,&expr,NULL); /* Now expr is memory-managed by cons */ /* 1.b Fill the constraint */ ap_lincons1_set_list(&cons, AP_COEFF_S_INT,-39,"x", AP_COEFF_S_INT,40,"y", AP_CST_S_INT,0, AP_END); /* 1.c Put in the array */ ap_lincons1_array_set(&array,0,&cons); /* Now cons is memory-managed by array */ ap_abstract1_t abs = ap_abstract1_of_lincons_array(man,env,&array); fprintf(stdout,"Abstract value:\n"); ap_abstract1_fprint(stdout,man,&abs); ap_generator1_array_t garray = ap_abstract1_to_generator_array(man,&abs); ap_generator1_array_fprint(stdout,&garray); ap_generator1_array_clear(&garray); /* 2.a Creation of an equality constraint -3x - 10z + 43 = 0 */ expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,2); cons = ap_lincons1_make(AP_CONS_EQ,&expr,NULL); /* The old cons is not lost, because it is stored in the array. It would be an error to clear it (same for expr). */ /* 2.b Fill the constraint */ ap_lincons1_set_list(&cons, AP_COEFF_S_INT,-3,"x", AP_COEFF_S_INT,-10,"z", AP_CST_S_INT,43, AP_END); /* 2.c Put in the array */ ap_lincons1_array_set(&array,0,&cons); fprintf(stdout,"Adding constraints:\n"); ap_lincons1_array_fprint(stdout,&array); abs = ap_abstract1_meet_lincons_array(man,true,&abs,&array); fprintf(stdout,"Abstract value:\n"); ap_abstract1_fprint(stdout,man,&abs); /* 3.a Creation of an inequality constraint -6x - 20y + 86 >= 0 */ expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,2); cons = ap_lincons1_make(AP_CONS_SUPEQ,&expr,NULL); /* The old cons is not lost, because it is stored in the array. It would be an error to clear it (same for expr). */ /* 2.b Fill the constraint */ ap_lincons1_set_list(&cons, AP_COEFF_S_INT,-6,"x", AP_COEFF_S_INT,-20,"y", AP_CST_S_INT,86, AP_END); /* 2.c Put in the array */ ap_lincons1_array_set(&array,0,&cons); fprintf(stdout,"Adding constraints:\n"); ap_lincons1_array_fprint(stdout,&array); abs = ap_abstract1_meet_lincons_array(man,true,&abs,&array); fprintf(stdout,"Abstract value:\n"); ap_abstract1_fprint(stdout,man,&abs); ap_lincons1_array_clear(&array); /* =================================================================== */ /* Creation of polyhedra -39x + 40u = 0 u = y v = x+z -6v - 14z + 86 = 0 */ /* =================================================================== */ /* 0. Create the array */ array = ap_lincons1_array_make(env,4); expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,2); cons = ap_lincons1_make(AP_CONS_EQ,&expr,NULL); ap_lincons1_set_list(&cons, AP_COEFF_S_INT,-39,"x", AP_COEFF_S_INT,40,"u", AP_CST_S_INT,0, AP_END); ap_lincons1_array_set(&array,0,&cons); expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,2); cons = ap_lincons1_make(AP_CONS_EQ,&expr,NULL); ap_lincons1_set_list(&cons, AP_COEFF_S_INT,-1,"u", AP_COEFF_S_INT,1,"y", AP_CST_S_INT,0, AP_END); ap_lincons1_array_set(&array,1,&cons); expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,2); cons = ap_lincons1_make(AP_CONS_EQ,&expr,NULL); ap_lincons1_set_list(&cons, AP_COEFF_S_INT,-1,"v", AP_COEFF_S_INT,1,"x", AP_COEFF_S_INT,1,"y", AP_CST_S_INT,0, AP_END); ap_lincons1_array_set(&array,1,&cons); expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,2); cons = ap_lincons1_make(AP_CONS_EQ,&expr,NULL); ap_lincons1_set_list(&cons, AP_COEFF_S_INT,-1,"v", AP_COEFF_S_INT,1,"x", AP_COEFF_S_INT,1,"z", AP_CST_S_INT,0, AP_END); ap_lincons1_array_set(&array,2,&cons); expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,2); cons = ap_lincons1_make(AP_CONS_EQ,&expr,NULL); ap_lincons1_set_list(&cons, AP_COEFF_S_INT,-6,"v", AP_COEFF_S_INT,-14,"z", AP_CST_S_INT,86, AP_END); ap_lincons1_array_set(&array,3,&cons); ap_abstract1_t abs2 = ap_abstract1_of_lincons_array(man,env,&array); fprintf(stdout,"Abstract value 2:\n"); ap_abstract1_fprint(stdout,man,&abs2); ap_lincons1_array_clear(&array); ap_abstract1_canonicalize(man,&abs2); fprintf(stdout,"Abstract value 2:\n"); ap_abstract1_fprint(stdout,man,&abs2); ap_abstract1_t abs3 = ap_abstract1_join(man,false,&abs,&abs2); fprintf(stdout,"Abstract value 3 (join of 1 and 2):\n"); ap_abstract1_fprint(stdout,man,&abs3); ap_abstract1_t abs4 = ap_abstract1_meet(man,false,&abs,&abs2); fprintf(stdout,"Abstract value 3 (meet of 1 and 2):\n"); ap_abstract1_fprint(stdout,man,&abs4); ap_abstract1_clear(man,&abs); ap_abstract1_clear(man,&abs2); ap_abstract1_clear(man,&abs3); ap_abstract1_clear(man,&abs4); ap_environment_free(env); } int main() { ap_manager_t* man; man = box_manager_alloc(); ex1(man); ex2(man); ap_manager_free(man); man = oct_manager_alloc(); ex1(man); ex2(man); ap_manager_free(man); man = pk_manager_alloc(true); ex1(man); ex2(man); ex3(man); ap_manager_free(man); man = ap_ppl_poly_manager_alloc(true); ex1(man); ex2(man); ex3(man); ap_manager_free(man); man = pkeq_manager_alloc(); ex2(man); ex3(man); ap_manager_free(man); man = ap_ppl_grid_manager_alloc(); ex2(man); ex3(man); ap_manager_free(man); } apron-dist-0.9.10/apron/examples/Makefile0000640014525101416610000000425511022004132020131 0ustar bjeannetpopartinclude ../Makefile.config ICFLAGS = \ -I$(GMP_PREFIX)/include \ -I$(MPFR_PREFIX)/include \ -I$(APRON_PREFIX)/include \ -Wall -Wstrict-prototypes -Wimplicit-function-declaration \ -std=c99 # -Winline -Wconversion LCFLAGS = \ -L$(GMP_PREFIX)/lib \ -L$(MPFR_PREFIX)/lib \ -L$(APRON_PREFIX)/lib \ -L$(PPL_PREFIX)/lib \ -L$(CAMLIDL_PREFIX)/lib/ocaml OCAMLINC = \ -I $(MLGMPIDL_PREFIX)/lib \ -I $(APRON_PREFIX)/lib OCAMLLDFLAGS = \ -noautolink -ccopt "$(LCFLAGS)" \ bigarray.cma gmp.cma apron.cma \ box.cma oct.cma polka.cma ppl.cma \ -cclib "-lpolkaGrid_caml -lap_pkgrid_debug -lap_ppl_caml -lap_ppl_debug -lppl -lpolka_caml -lpolka_debug -loct_caml -loctMPQ -lbox_caml -lbox_debug -litv_debug -lapron_caml_debug -lapron_debug -lgmp_caml -lmpfr -lgmpxx -lgmp -lbigarray -lcamlidl" OCAMLOPTLDFLAGS = \ -noautolink -verbose -ccopt "$(LCFLAGS)" \ bigarray.cmxa gmp.cmxa apron.cmxa box.cmxa polka.cmxa ppl.cmxa \ -cclib "-lpolkaGrid_caml -lap_pkgrid_debug -lap_ppl_caml -lap_ppl_debug -lppl -lpolka_caml -lpolka_debug -loct_caml -loctMPQ -lbox_caml -lbox_debug -litv_debug -lapron_caml_debug -lapron_debug -lgmp_caml -lmpfr -lgmpxx -lgmp -lbigarray -lcamlidl" all: C ml # C examples C: example1g %g: %g.o $(CXX) $(CXXFLAGS) $(ICFLAGS) $(LCFLAGS) -o $@ $< -lapron_ppl_debug -lppl -lgmpxx -lpolkag_debug -loctQg_debug -lboxMPQ_debug -lapron_debug -litvMPQ_debug -litvdbl_debug -lmpfr -lgmp %g.o: %.c $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -c -o $@ $< # OCaml examples ml: mlexample1.opt mlexample%.opt: mlexample%.cmx $(OCAMLOPT) -cc "g++" $(OCAMLOPTFLAGS) $(OCAMLINC) $(OCAMLOPTLDFLAGS) -o $@ $< test.opt: test.cmx $(OCAMLOPT) -cc "g++" $(OCAMLOPTFLAGS) $(OCAMLINC) $(OCAMLOPTLDFLAGS) -o $@ $< %: %.cmo $(APRON_PREFIX)/bin/apronrun $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) $(OCAMLLDFLAGS) -g -use-runtime $(APRON_PREFIX)/bin/apronrun -o $@ $< %.cmo: %.ml $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -c -o $@ $< %.cmx: %.ml $(OCAMLOPT) $(OCAMLOPTFLAGS) $(OCAMLINC) -c -o $@ $< # clean: rm -f example1g *.cm[ioxa] *.o mlexample1 mlexample2 mlexample3 mlexample4 mlexample5 *.opt distclean: clean dist: example1.c mlexample1.ml mlexample2.ml mlexample3.ml Makefile README (cd ..; tar zcvf examples.tgz $(^:%=examples/%)) apron-dist-0.9.10/apron/examples/mlexample2.ml0000640014525101416610000001303211023224037021073 0ustar bjeannetpopart (* This file is part of the APRON Library, released under GPL license (use of PPL). Please read the COPYING file packaged in the distribution. *) (* with default setting: apronppltop -I $MLGMPIDL_INSTALL/lib -I $APRON_INSTALL/lib #load "gmp.cma";; #load "apron.cma";; #load "box.cma";; #load "oct.cma";; #load "polka.cma";; #load "ppl.cma";; #install_printer Apron.Linexpr1.print;; #install_printer Apron.Lincons1.print;; #install_printer Apron.Generator1.print;; #install_printer Apron.Abstract1.print;; let environment_print fmt x = Apron.Environment.print fmt x;; let lincons1_array_print fmt x = Apron.Lincons1.array_print fmt x;; let generator1_array_print fmt x = Apron.Generator1.array_print fmt x;; #install_printer Apron.Var.print;; #install_printer environment_print;; #install_printer lincons1_array_print;; #install_printer generator1_array_print;; *) open Apron;; open Mpqf;; open Format;; let print_array = Abstract0.print_array;; let lincons1_array_print fmt x = Lincons1.array_print fmt x ;; let generator1_array_print fmt x = Generator1.array_print fmt x ;; let manpk = Polka.manager_alloc_strict();; let manbox = Box.manager_alloc ();; let manoct = Oct.manager_alloc ();; let manppl = Ppl.manager_alloc_strict();; let mangrid = Ppl.manager_alloc_grid ();; let maneq = Polka.manager_alloc_equalities ();; let var_x = Var.of_string "x";; let var_y = Var.of_string "y";; let var_z = Var.of_string "z";; let var_w = Var.of_string "w";; let var_u = Var.of_string "u";; let var_v = Var.of_string "v";; let var_a = Var.of_string "a";; let var_b = Var.of_string "b";; let ex1 (man:'a Manager.t) : 'a Abstract1.t = printf "Using Library: %s, version %s@." (Manager.get_library man) (Manager.get_version man); let env = Environment.make [|var_x; var_y; var_z; var_w|] [|var_u; var_v; var_a; var_b|] in let env2 = Environment.make [|var_x; var_y; var_z; var_w|] [||] in printf "env=%a@.env2=%a@." (fun x -> Environment.print x) env (fun x -> Environment.print x) env2 ; (* Creation of abstract value 1/2x+2/3y=1, [1,2]<=z+2w<=4, 0<=u<=5 *) let tab = Lincons1.array_make env 5 in let expr = Linexpr1.make env in Linexpr1.set_array expr [| ((Coeff.s_of_frac 1 2), var_x); ((Coeff.s_of_frac 2 3), var_y) |] (Some (Coeff.s_of_int (1))) ; let cons = Lincons1.make expr Lincons1.EQ in Lincons1.array_set tab 0 cons; let expr = Linexpr1.make env in Linexpr1.set_array expr [| ((Coeff.s_of_float (-1.0)), var_z); ((Coeff.s_of_float (-2.0)), var_w) |] (Some ((Coeff.s_of_float (4.0)))) ; Lincons1.array_set tab 1 (Lincons1.make expr Lincons1.SUPEQ); let expr = Linexpr1.make env2 in Linexpr1.set_array expr [| ((Coeff.s_of_float 1.0), var_z); ((Coeff.s_of_float 2.0), var_w) |] (Some (Coeff.i_of_float (-2.0) (-1.0))) ; Linexpr1.extend_environment_with expr env; Lincons1.array_set tab 2 (Lincons1.make expr Lincons1.SUPEQ); let cons = Lincons1.make (Linexpr1.make env) Lincons1.SUPEQ in Lincons1.set_array cons [| ((Coeff.s_of_int 1), var_u) |] None ; Lincons1.array_set tab 3 cons; let cons = Lincons1.make (Linexpr1.make env) Lincons1.SUPEQ in Lincons1.set_array cons [| ((Coeff.s_of_int (-1)), var_u) |] (Some ((Coeff.s_of_int 5))) ; Lincons1.array_set tab 4 cons; printf "tab = %a@." lincons1_array_print tab; let abs = Abstract1.of_lincons_array man env tab in printf "abs=%a@." Abstract1.print abs; let array = Abstract1.to_generator_array man abs in printf "gen=%a@." generator1_array_print array; let array = Abstract1.to_generator_array man abs in printf "gen=%a@." generator1_array_print array; (* Extraction (we first extract values for existing constraints, then for dimensions) *) let box = Abstract1.to_box man abs in printf "box=%a@." (print_array Interval.print) box.Abstract1.interval_array; for i=0 to 4 do let expr = Lincons1.get_linexpr1 (Lincons1.array_get tab i) in let box = Abstract1.bound_linexpr man abs expr in printf "Bound of %a = %a@." Linexpr1.print expr Interval.print box; done; (* 2. dimensions *) (* 3. of box *) let abs2 = Abstract1.of_box man env [|var_x; var_y; var_z; var_w; var_u; var_v; var_a; var_b|] box.Abstract1.interval_array in printf "abs2=%a@." Abstract1.print abs2; (* 4. Tests top and bottom *) let abs3 = Abstract1.bottom man env in printf "abs3=%a@.is_bottom(abs3)=%b@." Abstract1.print abs3 (Abstract1.is_bottom man abs3); printf "abs=%a@." Abstract1.print abs; let p2 = Abstract1.expand man abs var_y [|Var.of_string "y1"; Var.of_string "y2"|] in printf "p2=expand(abs,y,[y1,y2]))=%a@." Abstract1.print p2; let p2 = Abstract1.expand man abs var_u [|Var.of_string "u1"; Var.of_string "u2"|] in printf "p2=expand(abs,u,[u1,u2]))=%a@." Abstract1.print p2; abs ;; let ex2 (man:'a Manager.t) = let env = Environment.make [||] [|var_x; var_y; var_z|] in (* Creation of abstract value 5<=x<=14, 4<=y<=12, z=0 *) let abs1 = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int 5 14; Interval.of_int 4 12; Interval.of_int 0 0; |] in let abs2 = Abstract1.of_box man env [|var_x;var_y;var_z|] [| Interval.of_int 3 12; Interval.of_int 5 13; Interval.of_int 1 1; |] in let abs3 = Abstract1.join man abs1 abs2 in abs3 ;; let abs1 = ex1 manpk;; let abs2 = ex1 manppl;; let abs3 = ex1 manoct;; let abs4 = ex1 manbox;; let abs5 = ex1 maneq;; let abs6 = ex1 mangrid;; apron-dist-0.9.10/apron/examples/mlexample1.ml0000640014525101416610000001235211023224037021076 0ustar bjeannetpopart (* This file is part of the APRON Library, released under GPL license (use of PPL). Please read the COPYING file packaged in the distribution. *) (* with default setting: apronppltop -I $MLGMPIDL_INSTALL/lib -I $APRON_INSTALL/lib #load "gmp.cma";; #load "apron.cma";; #load "box.cma";; #load "oct.cma";; #load "polka.cma";; #load "ppl.cma";; #install_printer Apron.Linexpr1.print;; #install_printer Apron.Lincons1.print;; #install_printer Apron.Generator1.print;; #install_printer Apron.Abstract1.print;; let environment_print fmt x = Apron.Environment.print fmt x;; let lincons1_array_print fmt x = Apron.Lincons1.array_print fmt x;; let generator1_array_print fmt x = Apron.Generator1.array_print fmt x;; #install_printer Apron.Var.print;; #install_printer environment_print;; #install_printer lincons1_array_print;; #install_printer generator1_array_print;; *) open Apron;; open Mpqf;; open Format;; let print_array = Abstract0.print_array;; let lincons1_array_print fmt x = Lincons1.array_print fmt x ;; let generator1_array_print fmt x = Generator1.array_print fmt x ;; let manpk = Polka.manager_alloc_strict();; let manbox = Box.manager_alloc ();; let manoct = Oct.manager_alloc ();; let manppl = Ppl.manager_alloc_strict();; let mangrid = Ppl.manager_alloc_grid ();; let maneq = Polka.manager_alloc_equalities ();; let var_x = Var.of_string "x";; let var_y = Var.of_string "y";; let var_z = Var.of_string "z";; let var_w = Var.of_string "w";; let var_u = Var.of_string "u";; let var_v = Var.of_string "v";; let var_a = Var.of_string "a";; let var_b = Var.of_string "b";; let ex1 (man:'a Manager.t) : 'a Abstract1.t = printf "Using Library: %s, version %s@." (Manager.get_library man) (Manager.get_version man); let env = Environment.make [|var_x; var_y; var_z; var_w|] [|var_u; var_v; var_a; var_b|] in let env2 = Environment.make [|var_x; var_y; var_z; var_w|] [||] in printf "env=%a@.env2=%a@." (fun x -> Environment.print x) env (fun x -> Environment.print x) env2 ; (* Creation of abstract value 1/2x+2/3y=1, [1,2]<=z+2w<=4, 0<=u<=5 *) let tab = Lincons1.array_make env 5 in let expr = Linexpr1.make env in Linexpr1.set_array expr [| (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_frac 1 2)), var_x); (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_frac 2 3)), var_y) |] (Some (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_int (1))))) ; let cons = Lincons1.make expr Lincons1.EQ in Lincons1.array_set tab 0 cons; let expr = Linexpr1.make env in Linexpr1.set_array expr [| (Coeff.Scalar (Scalar.Float (-1.0)), var_z); (Coeff.Scalar (Scalar.Float (-2.0)), var_w) |] (Some (Coeff.Scalar (Scalar.Float (4.0)))) ; Lincons1.array_set tab 1 (Lincons1.make expr Lincons1.SUPEQ); let expr = Linexpr1.make env2 in Linexpr1.set_array expr [| (Coeff.Scalar (Scalar.Float 1.0), var_z); (Coeff.Scalar (Scalar.Float 2.0), var_w) |] (Some (Coeff.Interval (Interval.of_infsup (Scalar.Float (-2.0)) (Scalar.Float (-1.0))))) ; Linexpr1.extend_environment_with expr env; Lincons1.array_set tab 2 (Lincons1.make expr Lincons1.SUPEQ); let cons = Lincons1.make (Linexpr1.make env) Lincons1.SUPEQ in Lincons1.set_array cons [| (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_int 1)), var_u) |] None ; Lincons1.array_set tab 3 cons; let cons = Lincons1.make (Linexpr1.make env) Lincons1.SUPEQ in Lincons1.set_array cons [| (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_int (-1))), var_u) |] (Some (Coeff.Scalar (Scalar.Mpqf (Mpqf.of_int 5)))) ; Lincons1.array_set tab 4 cons; printf "tab = %a@." lincons1_array_print tab; let abs = Abstract1.of_lincons_array man env tab in printf "abs=%a@." Abstract1.print abs; let array = Abstract1.to_generator_array man abs in printf "gen=%a@." generator1_array_print array; let array = Abstract1.to_generator_array man abs in printf "gen=%a@." generator1_array_print array; (* Extraction (we first extract values for existing constraints, then for dimensions) *) let box = Abstract1.to_box man abs in printf "box=%a@." (print_array Interval.print) box.Abstract1.interval_array; for i=0 to 4 do let expr = Lincons1.get_linexpr1 (Lincons1.array_get tab i) in let box = Abstract1.bound_linexpr man abs expr in printf "Bound of %a = %a@." Linexpr1.print expr Interval.print box; done; (* 2. dimensions *) (* 3. of box *) let abs2 = Abstract1.of_box man env [|var_x; var_y; var_z; var_w; var_u; var_v; var_a; var_b|] box.Abstract1.interval_array in printf "abs2=%a@." Abstract1.print abs2; (* 4. Tests top and bottom *) let abs3 = Abstract1.bottom man env in printf "abs3=%a@.is_bottom(abs3)=%b@." Abstract1.print abs3 (Abstract1.is_bottom man abs3); printf "abs=%a@." Abstract1.print abs; let p2 = Abstract1.expand man abs (var_y) [|Var.of_string "y1"; Var.of_string "y2"|] in printf "p2=expand(abs,y,[y1,y2]))=%a@." Abstract1.print p2; let p2 = Abstract1.expand man abs (var_u) [|Var.of_string "u1"; Var.of_string "u2"|] in printf "p2=expand(abs,u,[u1,u2]))=%a@." Abstract1.print p2; abs ;; let abs1 = ex1 manpk;; let abs2 = ex1 manppl;; let abs3 = ex1 manoct;; let abs4 = ex1 manbox;; let abs5 = ex1 maneq;; let abs6 = ex1 mangrid;; apron-dist-0.9.10/apron/examples/README0000640014525101416610000000077410573552257017405 0ustar bjeannetpopart# This file is part of the APRON Library, released under LGPL # license. # Please read the COPYING file packaged in the distribution There are currently two examples, - example1.c (C, use of level 1) - mlexample1.ml, mlexample2.ml, mlexample3.ml (OCaml, level 1). For C examples, type make example1 For OCaml examples, type make mlexample1 or make mlexample1.opt Look at the Makefile for making your own. The present one assumes that all APRON subpackages are installed in $APRON_PREFIX directory. apron-dist-0.9.10/apron/Changes0000640014525101416610000002055011252213304016152 0ustar bjeannetpopartVersion 0.9.10 - Migration advices (due to some API and compilation process changes) * as MLGMPIDL is not included anymore, you may want to consider - either apron-dist-XXX.tgz packages - or svn co http://svn.cri.ensmp.fr/svn/apron/apron-dist/trunk apron-dist that include it. * Makefile.config: ° new variables HAS_SHARED and OCAMLMKLIB * C API: ° ap_pkgrid_manager_alloc has a new signature * OCaml API: ° PolkaGrid.manager_alloc_(loose|strict) are replaced by PolkaGrid.manager_alloc with a new signature. * OCaml compilation and Makefiles ° Typical commands ocamlc -o mlexample.byte bigarray.cma gmp.cma apron.cma box.cma -cclib "-lboxMPQ" mlexample.ml ocamlopt -o mlexample.opt bigarray.cmxa gmp.cmxa apron.cmxa box.cmxa -cclib "-lboxMPQ" mlexample.ml are replaced by ocamlc -o mlexample.byte bigarray.cma gmp.cma apron.cma boxMPQ.cma mlexample.ml ocamlopt -o mlexample.opt bigarray.cmxa gmp.cmxa apron.cmxa boxMPQ.cmxa mlexample.ml - Distribution/Packaging * MLGMPIDL not included anymore. If you want to include it with apron, consider: - either apron-dist-XXX.tgz packages - or svn co http://svn.cri.ensmp.fr/svn/apron/apron-dist/trunk apron-dist * Optional interface to PPL upgraded to 0.10 (but still support only polyhedra and linear congruences). No need with version 0.10 to apply a patch (see ppl/README for more details. - Compilation and linking process * Support for dynamic libraries added (new HAS_SHARED flag in Makefile.config) * IMPORTANT CHANGE for OCaml compilation: (see migration advices) - OCaml library files box.cma, polka.cma become now boxMPQ.cma, boxRll.cma, polkaRll.cma, etc... ° No need any more to use the -cclib option to choose the underlying number representation. ° Former box.cma, oct.cma, polka.cma are soft links to MPQ versions (for compatibility - Use of dynamic libraries when possible, with -dllib feature of ocamlc for bytecode executables. ° No need for custom bytecode interpreter and toplevel ° Enable the use of pretty-printer depending on C code in ocamldebug - API * Better (correct) signature for Abstract0.permute_dimensions: old: permute_dimensions : 'a Manager.t -> 'a t -> Dim.perm option -> 'a t new: permute_dimensions : 'a Manager.t -> 'a t -> Dim.perm -> 'a t * pkgrid/PolkaGrid product library: new signature for the manager allocation function * New ap_dimchange2_t datatype, for specifying addition followed by removal of dimensions. Generated by ap_environment_dimchange2 function and used by ap_abstract0_apply_dimchange2 function. * Octagon domain now supports hashing * Newpolka library: real canonical form for strict polyhedra, compatible with the hash function. * OCaml API for domains (box,oct,polka,ppl,polkaGrid): new functions allowing type conversion (for instance between Oct.t Apron.Manager.t and 'a Apron.Manager.t). - Bugs corrected: several - Internal API * Change of signature for itv_join (now requires itv_internal_t* object); Version 0.9.9: - API: * Important change: tbool_t replaced by bool in tests in flags exact and best (C modules ap_abstractX and ap_manager, OCaml modules AbstractX and Manager) In source code, * tbool_top,tbool_false should be replaced by false, * f(...)==tbool_true by f(...) * f(...)!=tbool_true by !f(...) * MPFR numbers added as possible numerical types (besides GMP MPQ and C double) * hash functions added in most places: * bound_hash, itv_hash, linexpr0_hash, texpr0_hash, ap_abstract0_hash, ap_abstract1_hash, ap_environment_hash, ap_var_hash * in libraries, hash implemented for itv and newpolka (for others, raises not implemented). * in OCaml API, used as a custom hash function for corresponding abstract types. * Functions added * OCaml: Linexpr0.of_list, Linexpr0.of_array, Environment.lce_change, Environment.rename_perm * Internal functions added/modified * num: num_integer, numrat_inv added * apron: spec of ap_texpr0_max_dim modified - Distribution/Packaging * Instruction files REAME.windows and README.mac files, some problems corrected. * Makefile.config.model simplified - Bugs corrected: several, in particular: * Special cases with abstract values in dimension 0, and null arrays in nassign/substitution functions and add_dimensions/remove_dimensions * ap_fpu_init for Mac * itv_lincons_reduce_integer (normalisation of integer constraints) Version 0.9.8 * ap_linexpr0_compare - New C++ interface, still experimental - Instructions for compilation under Windows - Clarification of license issues related to the PPL (under GPL license, whereas APRON is LGPL) - Several bugs corrections Version 0.9.7 Many changes ! General: - Addition of the reduced product of linear inequalities (from Polka library) and linear congruences (from PPL library). - Addition of tree expressions and constraints, generalizing linear expressions and constraints with * non-linear operations (multiplication, division, square root, ...) * integer, rational/real and floating-point semantics C interface: - API: * Addition of ap_abstract1_unify function * Modification of the signature of ap_environment_remove - some (redundant) functions removed from the API requested from underlying domains, but still provided through the APRON interface (level 0 and 1) for compatibility reasons: * of_lincons_array * assign_linexpr, substitute_linexpr (superseded by assign_linexpr_array, substitute_linexpr_array). - Suffixes of C libraries names indicating internal number representation made more systematic and uniform among various underlying libraries: * Il, Ill, MPZ: denotes resp. long int, long long int, mpz_t (GMP) * Rl, Rll, MPQ: denotes resp. rationals using long int, long long int, and mpq_t (GMP) * D, Dl: denotes resp. double and long double C library name without suffix (eg, libpolka.a) corresponds to the default suffix MPQ. - Other changes in library organisation: * libitv.a integrated in libapron.a * libapron_ppl.a renamed in libap_ppl.a, libppl_caml.a renamed in libap_ppl_caml.a OCaml interface - Linking simplified thanks to the change in C libraries (see above). - API: * Addition of Environment.lce, Abstract1.unify (Abstract1.unify_with) functions * Modification of the signature of Environment.remove Version 0.9.6 OCaml interface - PPL module - Parsing extended for congruence equalities and congruence generators. General: - Addition of PPL *convex polyhedra* and *linear congruences* (grids) abstract domains - Some internal reorganisation apron/ap_linearize module added - Full support for interval linear expressions and linearisation to (quasi-)linear expressions in NewPolka and PPL libraries. Well tested for quasilinear expressions, not yet for full interval linear expressions. - Many bugs corrected. Version 0.9.5 OCaml interface - Better type systems, similar to the system used by the [Bigarray] library of the OCaml standard distribution. - Generation and installation in $(APRON_PREFIX)/bin of apronrun and aprontop executables in the main Makefile. C interface: - Use of const qualifier removed in the API, except for strings (const char *) General: - mpfr library now required in addition to gmp library. - conversions between mpq_t and double are now safer, thanks to the use of mpfr. - itv becomes box. - package num extended with a new package itv, used currently by box. - support for linear congruences added in constraints and generators. - NewPolka offers a layer for linear equalities only, in addition to more general linear inequalities. - Improved Makefiles and Makefile.config.model - Bugs corrected, in particular in Box and Newpolka. Version 0.9.4 - Modification of Makefile and Makefile.config.model - Updated documentation - OCaml linking: apron.cmo, polka.cmo, oct.cmo... become libraries apron.cma, polka.cma,... that reference needed C libraries, with the exception of libpolkaXX, liboctXX, ... This is documented in READMEs and doc. - mlapronidl: Added string parsing (module Parser) - newpolka: * Stronger normalization in widening for strict constraints * Bug fixed (some of them were severe) apron-dist-0.9.10/apron/apron/0000750014525101416610000000000011252216455016005 5ustar bjeannetpopartapron-dist-0.9.10/apron/apron/ap_reducedproduct.h0000640014525101416610000000606211251667746021673 0ustar bjeannetpopart/* ************************************************************************* */ /* reducedproduct.h: generic reduced product of N domains */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _AP_REDUCEDPRODUCT_H_ #define _AP_REDUCEDPRODUCT_H_ #include #include #include "ap_global0.h" #ifdef __cplusplus extern "C" { #endif /* (internal) abstract value for a product */ typedef struct ap_reducedproduct_t { bool reduced; /* is the product reduced ? */ void* p[0]; /* array of internal abstract values, the size of which is specified in the associated ap_reducedproduct_internal_t */ } ap_reducedproduct_t; /* internal field of manager */ typedef struct ap_reducedproduct_internal_t { void (*reduce)(ap_manager_t*, ap_reducedproduct_t*); /* reduce function */ void (*approximate)(ap_manager_t*, ap_reducedproduct_t*, int n); /* approximate function */ char* library; /* (constructed) library name */ char* version; /* (constructed) library version */ size_t size; /* size of the product */ ap_manager_t* tmanagers[0]; /* of size size */ } ap_reducedproduct_internal_t; /* ============================================================ */ /* IV. Allocating a manager */ /* ============================================================ */ ap_manager_t* ap_reducedproduct_manager_alloc ( char* library, /* library name */ ap_manager_t** tab, /* Array of managers */ size_t size, /* size of array */ void (*reduce)(ap_manager_t*, ap_reducedproduct_t*), /* reduce function */ void (*approximate)(ap_manager_t*, ap_reducedproduct_t*, int n) /* approximate function */ ); /* ============================================================ */ /* V. Extra functions */ /* ============================================================ */ void** ap_reducedproduct_decompose(ap_manager_t* manager, bool destructive, ap_reducedproduct_t* a); /* Decompose an product abstract values into an array of abstract values, the size of which corresponds to the size of the (product) manager. Be cautious: no type checking is performed. If destructive is true, then a is freed at the end of the call. Otherwise, abstract values are copied into the result, and the argument and the result do not share any more information. */ ap_reducedproduct_t* ap_reducedproduct_compose(ap_manager_t* manager, bool destructive, void** tabs); /* Create a product abstract value from an array of size the size of the (product) manager. Be cautious: no type checking is performed. If destructive is true, the array tabs cannot be used any more, but may require a call to free() if dynamically allocated. Otherwise, abstract values are copied into the result, and the argument and the result do not share any more information. */ #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/ap_interval.c0000640014525101416610000001460111247456444020470 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_interval.c: intervals */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include "ap_interval.h" /* ====================================================================== */ /* Basics */ /* ====================================================================== */ ap_interval_t* ap_interval_alloc() { ap_interval_t* itv = malloc(sizeof(ap_interval_t)); itv->inf = ap_scalar_alloc(); itv->sup = ap_scalar_alloc(); return itv; } void ap_interval_reinit(ap_interval_t* itv, ap_scalar_discr_t d) { ap_scalar_reinit(itv->inf,d); ap_scalar_reinit(itv->sup,d); } void ap_interval_free(ap_interval_t* itv) { ap_scalar_free(itv->inf); ap_scalar_free(itv->sup); free(itv); } void ap_interval_fprint(FILE* stream, ap_interval_t* a) { fprintf(stream,"["); ap_scalar_fprint(stream,a->inf); fprintf(stream,","); ap_scalar_fprint(stream,a->sup); fprintf(stream,"]"); } /* ====================================================================== */ /* Assignments */ /* ====================================================================== */ void ap_interval_set(ap_interval_t* interval, ap_interval_t* interval2) { ap_scalar_set(interval->inf,interval2->inf); ap_scalar_set(interval->sup,interval2->sup); } void ap_interval_set_scalar(ap_interval_t* interval, ap_scalar_t* inf, ap_scalar_t* sup) { ap_scalar_set(interval->inf,inf); ap_scalar_set(interval->sup,sup); } void ap_interval_set_mpq(ap_interval_t* interval, mpq_t inf, mpq_t sup) { ap_scalar_set_mpq(interval->inf,inf); ap_scalar_set_mpq(interval->sup,sup); } void ap_interval_set_int(ap_interval_t* interval, long int inf, long int sup) { ap_scalar_set_int(interval->inf,inf); ap_scalar_set_int(interval->sup,sup); } void ap_interval_set_frac(ap_interval_t* interval, long int numinf, unsigned long int deninf, long int numsup, unsigned long int densup) { ap_scalar_set_frac(interval->inf,numinf,deninf); ap_scalar_set_frac(interval->sup,numsup,densup); } void ap_interval_set_double(ap_interval_t* interval, double inf, double sup) { ap_scalar_set_double(interval->inf,inf); ap_scalar_set_double(interval->sup,sup); } void ap_interval_set_mpfr(ap_interval_t* interval, mpfr_t inf, mpfr_t sup) { ap_scalar_set_mpfr(interval->inf,inf); ap_scalar_set_mpfr(interval->sup,sup); } void ap_interval_set_top(ap_interval_t* interval) { ap_scalar_set_infty(interval->inf,-1); ap_scalar_set_infty(interval->sup,+1); } void ap_interval_set_bottom(ap_interval_t* interval) { switch (interval->inf->discr) { case AP_SCALAR_DOUBLE: interval->inf->val.dbl = 1.; break; case AP_SCALAR_MPQ: mpq_set_si(interval->inf->val.mpq,1,1); break; case AP_SCALAR_MPFR: mpfr_set_si(interval->inf->val.mpfr,1,GMP_RNDU); break; default: abort(); } switch (interval->sup->discr) { case AP_SCALAR_DOUBLE: interval->sup->val.dbl = -1.; break; case AP_SCALAR_MPQ: mpq_set_si(interval->sup->val.mpq,-1,1); break; case AP_SCALAR_MPFR: mpfr_set_si(interval->sup->val.mpfr,-1,GMP_RNDD); break; default: abort(); } } /* ====================================================================== */ /* Combined allocation and assignments */ /* ====================================================================== */ ap_interval_t* ap_interval_alloc_set(ap_interval_t* interval) { ap_interval_t* itv = malloc(sizeof(ap_interval_t)); itv->inf = ap_scalar_alloc_set(interval->inf); itv->sup = ap_scalar_alloc_set(interval->sup); return itv; } /* ====================================================================== */ /* Tests */ /* ====================================================================== */ bool ap_interval_is_top(ap_interval_t* interval) { return ap_scalar_infty(interval->inf)<0 && ap_scalar_infty(interval->sup)>0; } bool ap_interval_is_bottom(ap_interval_t* interval) { return ap_scalar_cmp(interval->inf,interval->sup)>0; } bool ap_interval_is_leq(ap_interval_t* itv1, ap_interval_t* itv2) { int sinf = ap_scalar_cmp(itv1->inf,itv2->inf); int ssup = ap_scalar_cmp(itv1->sup,itv2->sup); return (sinf>=0 && ssup<=0) || ap_interval_is_bottom(itv1); } int ap_interval_cmp(ap_interval_t* itv1, ap_interval_t* itv2) { int sinf = ap_scalar_cmp(itv1->inf,itv2->inf); int ssup = ap_scalar_cmp(itv1->sup,itv2->sup); if (sinf==0 && ssup==0) return 0; else if (sinf>=0 && ssup<=0) return -1; else if (sinf<=0 && ssup>=0) return 1; else { bool b1 = ap_interval_is_bottom(itv1); bool b2 = ap_interval_is_bottom(itv2); if (b1 && b2) return 0; else if (b1) return -1; else if (b2) return 1; else return sinf > 0 ? 2 : -2; } } bool ap_interval_equal(ap_interval_t* itv1, ap_interval_t* itv2) { bool inf = ap_scalar_equal(itv1->inf,itv2->inf); bool sup = ap_scalar_equal(itv1->sup,itv2->sup); if (inf && sup) return true; else return ap_interval_is_bottom(itv1) && ap_interval_is_bottom(itv2); } bool ap_interval_equal_int(ap_interval_t* itv, int b) { return ap_scalar_equal_int(itv->inf,b) && ap_scalar_equal_int(itv->sup,b); } /* ====================================================================== */ /* Other operations */ /* ====================================================================== */ void ap_interval_neg(ap_interval_t* a, ap_interval_t* b) { if (a==b){ ap_scalar_swap(a->inf,a->sup); ap_scalar_neg(a->inf,a->inf); ap_scalar_neg(a->sup,a->sup); } else { ap_scalar_neg(a->inf,b->sup); ap_scalar_neg(a->sup,b->inf); } } long ap_interval_hash(ap_interval_t* itv) { if (ap_interval_is_bottom(itv)) return 0; else return 5*ap_scalar_hash(itv->inf) + 7*ap_scalar_hash(itv->sup); } /* ====================================================================== */ /* Array of intervals */ /* ====================================================================== */ ap_interval_t** ap_interval_array_alloc(size_t size) { size_t i; ap_interval_t** array = malloc(size*sizeof(ap_interval_t*)); for (i=0;i #include #include #include "ap_coeff.h" #include "ap_lincons1.h" #include "ap_tcons0.h" #include "ap_environment.h" #include "ap_texpr1.h" #ifdef __cplusplus extern "C" { #endif /* ====================================================================== */ /* Datatypes */ /* ====================================================================== */ /* Constraints */ typedef struct ap_tcons1_t { ap_tcons0_t tcons0; ap_environment_t* env; } ap_tcons1_t; /* Array of constraints */ typedef struct ap_tcons1_array_t { ap_tcons0_array_t tcons0_array; ap_environment_t* env; } ap_tcons1_array_t; /* ********************************************************************** */ /* I. ap_tcons1_t */ /* ********************************************************************** */ /* ====================================================================== */ /* I.1 Memory management and printing */ /* ====================================================================== */ static inline ap_tcons1_t ap_tcons1_make(ap_constyp_t constyp, ap_texpr1_t* expr, ap_scalar_t* scalar); /* Create a constraint of given type with the given expression. The expression and the optional coefficient are not duplicated, just pointed to. */ static inline ap_tcons1_t ap_tcons1_from_lincons1(ap_lincons1_t* cons); /* Create a tree constraint from a linear constraint */ static inline ap_tcons1_t ap_tcons1_copy(ap_tcons1_t* cons); /* Duplication */ void ap_tcons1_clear(ap_tcons1_t* cons); /* Clear the constraint and set pointers to NULL */ void ap_tcons1_fprint(FILE* stream, ap_tcons1_t* cons); static inline void ap_tcons1_print(ap_tcons1_t* cons); /* Printing */ /* ====================================================================== */ /* I.2 Tests */ /* ====================================================================== */ /* ====================================================================== */ /* I.3 Access */ /* ====================================================================== */ static inline ap_environment_t* ap_tcons1_envref(ap_tcons1_t* cons); /* Get a reference to the environment. Do not free it. */ static inline ap_constyp_t* ap_tcons1_constypref(ap_tcons1_t* cons); /* Get a reference to the type of constraint */ static inline ap_scalar_t* ap_tcons1_scalarref(ap_tcons1_t* cons); /* Get a reference to the auxiliary coefficient of the constraint */ static inline ap_texpr1_t ap_tcons1_texpr1ref(ap_tcons1_t* cons); /* Get a reference to the underlying expression of the constraint. Do not free it: nothing is duplicated. Modifying the argument or the result is equivalent, except for change of dimensions/environment. */ static inline ap_tcons0_t* ap_tcons1_tcons0ref(ap_tcons1_t* cons); /* Return underlying constraint of level 0. Do not free it: nothing is duplicated. Modifying the argument or the result is equivalent, except for change of dimensions/environment. */ /* ====================================================================== */ /* I.3 Change of dimensions and permutations */ /* ====================================================================== */ bool ap_tcons1_extend_environment(ap_tcons1_t* ncons, ap_tcons1_t* cons, ap_environment_t* nenv); bool ap_tcons1_extend_environment_with(ap_tcons1_t* cons, ap_environment_t* nenv); /* ********************************************************************** */ /* II. Array of linear constraints */ /* ********************************************************************** */ /* ====================================================================== */ /* I.1 Memory management and printing */ /* ====================================================================== */ ap_tcons1_array_t ap_tcons1_array_make(ap_environment_t* env, size_t size); /* Allocate an array of size constraints. The constraints are initialized with NULL pointers, so that ap_tcons1_array_free may be safely called */ void ap_tcons1_array_clear(ap_tcons1_array_t* array); /* Clear the constraints of the array, and then the array itself */ void ap_tcons1_array_fprint(FILE* stream, ap_tcons1_array_t* array); static inline void ap_tcons1_array_print(ap_tcons1_array_t* array); /* Printing */ /* ====================================================================== */ /* II.3 Access */ /* ====================================================================== */ static inline size_t ap_tcons1_array_size(ap_tcons1_array_t* array); /* Return the size of the array */ static inline ap_environment_t* ap_tcons1_array_envref(ap_tcons1_array_t* array); /* Return a reference to the environment of the array. Do not free it. */ static inline void ap_tcons1_array_clear_index(ap_tcons1_array_t* array, size_t index); /* Clear the constraint at index index. */ ap_tcons1_t ap_tcons1_array_get(ap_tcons1_array_t* array, size_t index); /* Return the linear constraint of the given index Nothing is duplicated, and the result should never be cleared. Modifying the argument or the result is equivalent, except for change of environments */ bool ap_tcons1_array_set(ap_tcons1_array_t* array, size_t index, ap_tcons1_t* cons); /* Fill the index of the array with the constraint. Assumes ap_environment_is_eq(array->env,cons->env). Nothing is duplicated. The argument should never be cleared. (its environment is dereferenced). If a constraint was already stored, it is first cleared. Return true iff problem (index or array->env!=cons->env) */ /* ====================================================================== */ /* II.4 Change of dimensions and permutations */ /* ====================================================================== */ bool ap_tcons1_array_extend_environment_with(ap_tcons1_array_t* array, ap_environment_t* env); bool ap_tcons1_array_extend_environment(ap_tcons1_array_t* narray, ap_tcons1_array_t* array, ap_environment_t* env); /* ********************************************************************** */ /* III. Inline functions definitions */ /* ********************************************************************** */ static inline ap_tcons1_t ap_tcons1_of_tcons0(ap_environment_t* env, ap_tcons0_t tcons0) { ap_tcons1_t res ; res.env = ap_environment_copy(env); res.tcons0 = tcons0; return res; } static inline ap_tcons1_t ap_tcons1_make(ap_constyp_t constyp, ap_texpr1_t* expr, ap_scalar_t* scalar) { ap_tcons1_t cons; cons.tcons0 = ap_tcons0_make(constyp,expr->texpr0,scalar); cons.env = expr->env; return cons; } static inline ap_tcons1_t ap_tcons1_from_lincons1(ap_lincons1_t* cons){ return ap_tcons1_of_tcons0(cons->env, ap_tcons0_from_lincons0(&cons->lincons0)); } static inline ap_tcons1_t ap_tcons1_copy(ap_tcons1_t* cons){ return ap_tcons1_of_tcons0(cons->env, ap_tcons0_copy(&cons->tcons0)); } static inline void ap_tcons1_print(ap_tcons1_t* cons) { ap_tcons1_fprint(stdout,cons); } static inline ap_environment_t* ap_tcons1_envref(ap_tcons1_t* cons){ return cons->env; } static inline ap_constyp_t* ap_tcons1_constypref(ap_tcons1_t* cons){ return &cons->tcons0.constyp; } static inline ap_scalar_t* ap_tcons1_scalarref(ap_tcons1_t* cons){ return cons->tcons0.scalar; } static inline ap_texpr1_t ap_tcons1_texpr1ref(ap_tcons1_t* cons){ ap_texpr1_t expr; expr.texpr0 = cons->tcons0.texpr0; expr.env = cons->env; return expr; } static inline ap_tcons0_t* ap_tcons1_tcons0ref(ap_tcons1_t* cons){ return &cons->tcons0; } static inline void ap_tcons1_array_print(ap_tcons1_array_t* array) { ap_tcons1_array_fprint(stdout,array); } static inline size_t ap_tcons1_array_size(ap_tcons1_array_t* array){ return array->tcons0_array.size; } static inline ap_environment_t* ap_tcons1_array_envref(ap_tcons1_array_t* array){ return array->env; } static inline void ap_tcons1_array_clear_index(ap_tcons1_array_t* array, size_t index){ ap_tcons0_clear(&array->tcons0_array.p[index]); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/apronrationale.tex0000640014525101416610000000700210437621734021551 0ustar bjeannetpopart% This file is part of the APRON Library, released under LGPL license. % Please read the COPYING file packaged in the distribution \documentclass[a4paper,11pt]{report} \usepackage[T1]{fontenc} \usepackage[french]{babel} \usepackage{noweb} \noweboptions{shift,smallcode} \usepackage{xspace} \usepackage{color} \usepackage{url} \usepackage{fullpage,amsfonts} %********************************************************************** % MACROS %********************************************************************** %====================================================================== % Couleurs et rédacteurs %====================================================================== \newcommand{\red}{\color{red}} \newcommand{\green}{\color{green}} \newcommand{\blue}{\color{blue}} \newcommand{\magenta}{\color{magenta}} \definecolor{YellowOrange} {cmyk}{0,0.42,1,0} % YellowOrange Approximate PANTONE 130 \iftrue \newcommand{\nh}[1]{{\green [nh] #1}} \newcommand{\bj}[1]{{\blue [bj] #1}} % \newcommand{\myfi}[1]{{\magenta [fi] #1}} \newcommand{\myfi}[1]{{\magenta #1}} \newcommand{\prc}[1]{{\color{YellowOrange}[p\&rc] #1}} \else \newcommand{\nh}[1]{{#1}} \newcommand{\bj}[1]{{#1}} \newcommand{\myfi}[1]{{\red #1}} \newcommand{\prc}[1]{{#1}} \fi %====================================================================== % Paragraphes numérotés globalement %====================================================================== \setcounter{tocdepth}{4} \newcounter{point} \newcommand{\point}[1]{ \stepcounter{point} \bigskip\par\noindent\arabic{point}. {\bf #1} \addcontentsline{toc}{subsubsection}{\numberline{\arabic{point}} #1} } \newcommand{\aparte}[1]{\medskip\par\noindent #1 \medskip\par} %====================================================================== % References et latin %====================================================================== \newcommand{\sref}[1]{\S\ref{#1}} \newcommand{\cf}{\textit{c.f.}\xspace} \newcommand{\ie}{\textit{i.e.}\xspace} \newcommand{\eg}{\textit{e.g..}\xspace} %====================================================================== % Reglages %====================================================================== \setlength{\parskip}{0.6ex} \sloppy %********************************************************************** % TITRE %********************************************************************** \title{\noindent\centerline{\fbox{\vbox{ \begin{center} \textbf{{\large Action Concert{\'e}e Incitative}}\\[1pc] \textbf{\textit{{\large S{\'E}CURIT{\'E} \& INFORMATIQUE}}}\\[1pc] \textbf{{\Large APRON: Analyse de PROgrammes Num{\'e}riques}}\\[1pc] \textbf{{\large Compte-rendu de la réunion du 28 juin 2005: Interface commune}} \end{center} }}}} \date{} %********************************************************************** % DOCUMENT %********************************************************************** \begin{document} \maketitle %********************************************************************** \section*{Introduction} %********************************************************************** Ce document réorganise et synthétise les compte-rendus des réunions du 16 décembre 2004, 1er février 2005, 15 mars 2005 et 28 juin 2005. \tableofcontents \include{ap_general} \include{ap_coefficients} \include{ap_dimension} \include{ap_expr0} \include{ap_manager} \include{ap_abstract0} \include{ap_var} \include{ap_environment} \include{ap_expr1} \include{ap_abstract1} \include{ap_implementorman} \end{document} rubriques: debugging/traces/impression congruences weak update conversions apron-dist-0.9.10/apron/apron/ap_environment.h0000640014525101416610000002222711224616234021206 0ustar bjeannetpopart/* ********************************************************************** */ /* ap_environment.h: binding of addresses (strings) to dimensions */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ /* GENERATED FROM ap_environment.nw: DO NOT MODIFY ! */ #ifndef _AP_ENVIRONMENT_H_ #define _AP_ENVIRONMENT_H_ #include "ap_config.h" #include "ap_dimension.h" #include "ap_var.h" #ifdef __cplusplus extern "C" { #endif /* ====================================================================== */ /* Datatype */ /* ====================================================================== */ /* The ap_environment_t type is the type used by the level 1 of the interface. It should be considered as an abstract type. We use reference counting to manage memory. Conventions are: - a newly allocated environment has a reference count of one; - environment_copy increments the counter and return its argument - environment_free decrements it and free the environment in case of zero or negative number. */ typedef struct ap_environment_t { ap_var_t* var_of_dim; /* Array of size intdim+realdim, indexed by dimensions. - It should not contain identical strings.. - Slice [0..intdim-1] is lexicographically sorted, and denotes integer variables. - Slice [intdim..intdim+realdim-1] is lexicographically sorted, and denotes real variables. - The memory allocated for the variables are attached to the structure (they are freed when the structure is no longer in use) */ size_t intdim; /* Number of integer variables */ size_t realdim;/* Number of real variables */ size_t count; /* For reference counting */ } ap_environment_t; typedef struct ap_environment_name_of_dim_t { size_t size; char* p[]; /* Assumed to be of size size */ } ap_environment_name_of_dim_t; /* ====================================================================== */ /* Memory management, Constructor, Destructors */ /* ====================================================================== */ void ap_environment_free2(ap_environment_t* e); /* Free the environment (the structure itself and the memory pointed to by fields) */ static inline void ap_environment_free(ap_environment_t* e); /* Decrement the reference counter and possibly deallocate */ static inline ap_environment_t* ap_environment_copy(ap_environment_t* e); /* Copy */ void ap_environment_fdump(FILE* stream, ap_environment_t* env); /* Print an environment under the form: environment: dim = (..,..), count = .. 0: name0 1: name1 ... */ ap_environment_name_of_dim_t* ap_environment_name_of_dim_alloc(ap_environment_t* e); void ap_environment_name_of_dim_free(ap_environment_name_of_dim_t*); ap_environment_t* ap_environment_alloc_empty(void); /* Build an empty environment */ ap_environment_t* ap_environment_alloc(ap_var_t* name_of_intdim, size_t intdim, ap_var_t* name_of_realdim, size_t realdim); /* Build an environment from an array of integer and an array of real variables. - Variables are duplicated in the result, so it is the responsibility of the user to free the variables he provides. - If the result does not satisfy the invariant, return NULL. */ ap_environment_t* ap_environment_add(ap_environment_t* env, ap_var_t* name_of_intdim, size_t intdim, ap_var_t* name_of_realdim, size_t realdim); /* Add variables to an environment. Same comments as for ap_environment_alloc */ ap_environment_t* ap_environment_add_perm(ap_environment_t* env, ap_var_t* name_of_intdim, size_t intdim, ap_var_t* name_of_realdim, size_t realdim, ap_dimperm_t* dimpermu); /* Same as previous functions, but in addition return in *dimperm the permutation to apply after having added new variables at the end of their respective slice, in order to get them sorted. If the result is NULL, so is dimperm->dim */ ap_environment_t* ap_environment_remove(ap_environment_t* env, ap_var_t* tvar, size_t size); /* Remove variables from an environment. Return NULL in case of attempt to remove an unknown variable. Same comments as for environment_alloc. */ static inline bool ap_environment_mem_var(ap_environment_t* env, ap_var_t name); /* Return true if the variable is present in the environemnt */ ap_dim_t ap_environment_dim_of_var(ap_environment_t* env, ap_var_t name); /* - If the variable is present in the environemnt, return its associated dimension. - Otherwise, return AP_DIM_MAX */ static inline ap_var_t ap_environment_var_of_dim(ap_environment_t* env, ap_dim_t dim); /* - Return the variable associated to the dimension. - There is no bound check here */ /* ========================================================================= */ /* Tests */ /* ========================================================================= */ bool ap_environment_is_eq(ap_environment_t* env1, ap_environment_t* env2); /* Equality test */ bool ap_environment_is_leq(ap_environment_t* env1, ap_environment_t* env2); /* Inclusion test */ int ap_environment_compare(ap_environment_t* env1, ap_environment_t* env2); /* Return - -2 if the environments are not compatible (a variable has a different type in the 2 environments) - -1 if env1 is a subset of env2 - 0 if equality - +1 if env1 is a superset of env2 - +2 otherwise (the lce exists and is a strict superset of both) */ int ap_environment_hash(ap_environment_t* env); /* Return an hash code */ /* ========================================================================= */ /* Least common environments and conversion permutations */ /* ========================================================================= */ ap_dimchange_t* ap_environment_dimchange(ap_environment_t* env1, ap_environment_t* env); /* Compute the transformation for converting from an environment to a superenvironment. Return NULL if env is not a superenvironment. */ ap_dimchange2_t* ap_environment_dimchange2(ap_environment_t* env1, ap_environment_t* env2); /* Compute the transformation for converting from a first environment to a second environment, by first adding (some) variables of the second environment, and then removing (some) variables of the first environment. If the two environments are incompatible, returns NULL */ ap_environment_t* ap_environment_lce(ap_environment_t* env1, ap_environment_t* env2, ap_dimchange_t** dimchange1, ap_dimchange_t** dimchange2); /* Least common environment to two environments. - If environments are not compatible (a variable has different types in the 2 environments), return NULL - Compute also in dimchange1 and dimchange2 the conversion transformations. - If no dimensions to add to env1, this implies that env is actually env1. In this case, *dimchange1==NULL. Otherwise, the function allocates *dimchange1 with ap_dimchange_alloc. */ ap_environment_t* ap_environment_lce_array(ap_environment_t** tenv, size_t size, ap_dimchange_t*** ptdimchange); /* Least common environment to an array environments. - Assume the size of the array is at least one. - If all input environments are the same, *ptdimchange==NULL. Otherwise, compute in *ptdimchange the conversion permutations. - If no dimensions to add to tenv[i], this implies that env is actually tenv[i]. In this case, (*ptdimchange)[i]==NULL. Otherwise, the function allocates (*ptdimchange)[0] with ap_dimchange_alloc. */ /* ========================================================================= */ /* Variable renaming */ /* ========================================================================= */ ap_environment_t* ap_environment_rename(ap_environment_t* env, ap_var_t* tvar1, ap_var_t* tvar2, size_t size, ap_dimperm_t* perm); /* Rename the variables in the environment. size is the common size of tvar1 and tvar2, and perm is a result-parameter The function applies the variable substitution tvar1[i]->tvar2[i] to the environment, and returns the resulting environment and the allocated transformation permutation in *permutation. If the parameters are not valid, returns NULL with perm->dim==NULL */ /* ====================================================================== */ /* Inline definitions */ /* ====================================================================== */ static inline bool ap_environment_mem_var(ap_environment_t* env, ap_var_t name) { return (ap_environment_dim_of_var(env,name) != AP_DIM_MAX); } static inline ap_var_t ap_environment_var_of_dim(ap_environment_t* env, ap_dim_t dim){ return dim < env->intdim+env->realdim ? env->var_of_dim[dim] : NULL; } static inline void ap_environment_free(ap_environment_t* env){ if (env->count<=1) ap_environment_free2(env); else env->count--; } static inline ap_environment_t* ap_environment_copy(ap_environment_t* env){ env->count++; return env; } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/rationale.texi0000640014525101416610000005653410723557216020701 0ustar bjeannetpopart @menu * General choices:: * Functionalities of the interface at level 0:: * Functionalities of the interface at level 1:: @end menu @c =================================================================== @node General choices, Functionalities of the interface at level 0, APRON Rationale and Functionalities, APRON Rationale and Functionalities @section General choices @c =================================================================== @menu * Interface levels:: * Programming language:: * Compatibility with threads:: * Interruptions:: * Memory management:: * Programming style:: * Number representation:: @end menu @c ------------------------------------------------------------------- @node Interface levels, Programming language, General choices, General choices @subsubheading Interface levels There are two main goals for the APRON interface: efficiency of the implementations, and ease of use for the user. In addition, code duplication between libraries should be avoided. As a consequence, two levels were identified: @table @emph @item Level 0 Choices are guided by the efficiency and the precision of the operations; @item Level 1 Choices are guided by ease of use, and code factorization. @end table The level 0 is directly connected to the underlying (existing) library. It includes all the operations that are specific to an abstract domain and whose code cannot be shared. The interface should be minimal, @emph{unless} there is a strong algorithmical advantage to include a combination of more basic operations. The higher levels offers additional functionalities that are shared by all the library connected to the level 0. For instance: @itemize @item managing correspondance between numerical dimensions and names (characters strings or more generally references); @item abstraction of non linear expressions in interval linear expressions; @item automatic call to redimensioning and permutation operations for computing @iftex @tex $P(x,y)\sqcap Q(y,z)$ @end tex @end iftex @ifnottex P(x,y)/\Q(y,z). @end ifnottex @end itemize Combination of abstract domain is possible at the level 0. One can implement for instance the cartesian or reduced product of two different abstract domains, the decomposition of abstract values into a product of values of smaller dimensionality, ... @c ------------------------------------------------------------------- @node Programming language, Compatibility with threads, Interface levels, General choices @subsubheading Programming language The reference version of the interface is the C version of the interface: @itemize @item C can be easily interfaced with most programming languages; @item Most of the existing libraries implementing abstract domains for numerical variables are programmed in C or C++. @end itemize An @sc{OCaml} version is already available. The interface between OCaml and C is even generic and any libraries can benefit from it by providing the glue for just one function (see XX). @c ------------------------------------------------------------------- @node Compatibility with threads, Interruptions, Programming language, General choices @subsubheading Compatibility with threads In order to ensure compatibility with multithreading programming, a context is explicitly passed to functions in order to ensure the following points: @itemize @item the transmission of data specific to each library (non-standard options, workspace, ...); @item the transmission of standard options (selection of algorithms and their precision inside a library); @item the management of exceptions (implemented as error codes in the C interface) (@code{not_implemented}, @code{invalid_argument}, @code{overflow}, @code{timeout}, @code{out_of_space}). @end itemize @c ------------------------------------------------------------------- @node Interruptions, Memory management, Compatibility with threads, General choices @subsubheading Interruptions Interruptions mechanism is have possible for different cases: @table @code @item timeout if the execution time for an operation exceeds some bound; @item out_of_space if the space consumption for an operation exceeds some bound; @item overflow if the magnitude or the space usage of manipulated numbers exceeds some bound; @item not_implemented if the operation is actually not implemented by the underlying library; @item invalid_argument if the arguments do not follow the requirements of an operation. @end table @quotation For instance, in a convex polyhedra library, the @code{out_of_space} exception allows to abort an operation is the result appears to have too many constraints and/or generators. If this happens, one can redo the operation with another (less precise) algorithm. The @code{overflow} may be useful when effective overflows are encountered with machine integers or when multiprecision rational numbers have too large numerators and denominators. The @code{not_implemented} exception allows for a library to be linked to the interface even if it does not provide some operation of the interface. @end quotation When an interruption occurs, the function should still return a correct result, in the abstract interpretation sense: it should be a correct approximation, usable for next operations in the program. The top value is always a correct approximation. @c ------------------------------------------------------------------- @node Memory management, Programming style, Interruptions, General choices @subsubheading Memory management Memory is managed differently depending on the programming language. Currently: @itemize @item No automatic garbage collection in the C interface @item Use of the @sc{OCaml} runtime garbage collector in the @sc{OCaml} interface @end itemize @c ------------------------------------------------------------------- @node Programming style, Number representation, Memory management, General choices @subsubheading Programming style Both functional and imperative (i.e., side-effect) signatures are supported for operations. This allows to optimize the memory allocation and to use whichever version is more convenient for an user and the used programming language. @c ------------------------------------------------------------------- @node Number representation, , Programming style, General choices @subsubheading Number representation Inside a specific library, any number representation may be used (floating-point numbers, machine integers, multiprecision integers/rationals, ...). Existing libraries often offers the possibility to select different representations. However, in the interface, this representation should be normalized and independent of underlying libraries, without being restrictive either. As a consequence, the interface offers the choiced between @itemize @item GMP multiprecision rationals (which implements exact arithmetic); @item and machine floating-point numbers (@code{double}). @end itemize @c =================================================================== @node Functionalities of the interface at level 0, Functionalities of the interface at level 1, General choices, APRON Rationale and Functionalities @section Functionalities of the interface at level 0 @c =================================================================== @menu * Representation of an abstract value:: * Semantics of an abstract value:: * Dimensions:: * Other datatypes:: * Control of internal representation:: * Printing:: * Serializaton/Deserialization:: * Constructors:: * Tests:: * Property extraction:: * Lattice operations:: * Assignement and Substitutions:: * Operations on dimensions:: * Other operations:: @end menu @c ------------------------------------------------------------------- @node Representation of an abstract value, Semantics of an abstract value, Functionalities of the interface at level 0, Functionalities of the interface at level 0 @subsubheading Representation of an abstract value At the level 0 of the interface, an abstract value is a structure @verbatim struct ap_abstract0_t { ap_manager_t *manager; /* Explicit context */ void *value; /* Abstract value representation (only known by the underlying library) */ } @end verbatim The context is allocated by the underlying library, and contains an array of function pointers pointing to the function of the underlying library. Hence, it indicates the effective type of an abstract value. The validity of the arguments of the functions called through the interface is checked before the call to effective functions. In case of problem, an @code{invalid_argument} exception is raised. @c ------------------------------------------------------------------- @node Semantics of an abstract value, Dimensions, Representation of an abstract value, Functionalities of the interface at level 0 @subsubheading Semantics of an abstract value The semantics of an abstract value is a subset @iftex @tex $$X\subseteq {\cal N}^p\times{\cal R}^q$$ @end tex @end iftex @ifnottex @quotation X of N^p x R^q @end quotation @end ifnottex @noindent Abstract values are typed according to their dimensionality (p,q). @c ------------------------------------------------------------------- @node Dimensions, Other datatypes, Semantics of an abstract value, Functionalities of the interface at level 0 @subsubheading Dimensions Dimensions are numbered from 0 to p+q-1 and are typed either as integer or real, depending on their rank w.r.t. the dimensionality of the abstract value. @quotation Note Taking into account or not the fact that some dimensions are integers is left to underlying libraries. Treating them as real is still a correct approximation. The behaviour of the libraries in this regard may also depend on some options. @end quotation @c ------------------------------------------------------------------- @node Other datatypes, Control of internal representation, Dimensions, Functionalities of the interface at level 0 @subsubheading Other datatypes In addition to abstract values, the interface also manipulates the following main datatypes: @table @emph @item scalar (number) Either GMP multiprecision rationals or C @code{double}. @item interval composed of 2 scalar numbers. With rationals, plus (resp minus) infinity is represented by 1/0 (resp -1/0). With @code{double}, the IEEE754 is assumed and the corresponding standard representation is used. @item coefficient which is either a scalar or an interval. @item (interval) linear expression The term linear is used even if the proper term should rather be affine. A linear expression is a linear expression in the common sense, using only scalar numbers. A quasi-linear expression is a linear expression where the constant coefficient is an interval. An interval linear expression is a linear expression where any coefficient may be an interval. In order to have a unique datatype for these variations, we introduced the notion of coefficient described above. @item ``linear'' constraints ``Linear'' constraints includes proper linear constraints, linear constraints in which the expression can be possibly an interval linear expression, linear equalities modulo a number, and linear disequalities. @item generators A generator system for a subset of @math{X\subseteq R^n} is a finite set of vectors, among which one distinguishes @emph{points} @math{p_0,\ldots,p_m} and @emph{rays} @math{r_0,\ldots,r_n}, that generates @math{X}: @iftex @tex $$X=\{ \lambda_0 \vec{p_0} + \ldots \lambda_m \vec{p_m} + \mu_0 \vec{r_0} +\ldots + \mu_n \vec{r_n} ~|~ \sum_i \lambda_i = 1 ~\wedge~ \forall j: \mu_j\geq 0 \}$$ @end tex @end iftex @ifnottex @quotation X = @{ lambda0 p0 +...+ lambdaM pM + mu0 r0 +...+ muN rN | lambda0 +...+ lambdaN = 1 and forall J : muJ >= 0 @} @end quotation @end ifnottex The APRON datatype for generators distinguishes points (sum of coefficients equal to one), rays (positive coefficients), lines (or bidirectional rays, with unconstrainted coefficients), integer rays (integer positive coefficients) and integer lines (integer coefficients). @end table @c ------------------------------------------------------------------- @node Control of internal representation, Printing, Other datatypes, Functionalities of the interface at level 0 @subsubheading Control of internal representation We identified several notions: @itemize @item Canonical form @item Minimal form (in term of space) @item Approximation notion left to the underlying library (taking into account integers or not, ...). @end itemize @c ------------------------------------------------------------------- @node Printing, Serializaton/Deserialization, Control of internal representation, Functionalities of the interface at level 0 @subsubheading Printing There are two printing operations: @itemize @item Printing of an abstract value; @item Printing the difference between two abstract values. @end itemize @noindent The printing format is library dependent. However, the conversion of abstract values to constraints (see below) allows a form of standardized printing for abstract values. @c ------------------------------------------------------------------- @node Serializaton/Deserialization, Constructors, Printing, Functionalities of the interface at level 0 @subsubheading Serializaton/Deserialization Serialization and deserialization of abstract values to a memory buffer is offered. It is entirely managed by the underlying library. In particular, it is up to it to check that a value read from the memory buffer has the right format and has not been written by a different library. Serialization is done to a memory buffer instead of to a file descriptor because this mechanism is more general and is needed for interfacing with languages like @sc{OCaml}. @c ------------------------------------------------------------------- @node Constructors, Tests, Serializaton/Deserialization, Functionalities of the interface at level 0 @subsubheading Constructors Four basic constructors are offered: @itemize @item bottom (empty) and top (universe) values (with a specified dimensionality); @item abstraction of a bounding box; @item abstraction of conjunction of linear constraints (in the broad sense). @end itemize @c ------------------------------------------------------------------- @node Tests, Property extraction, Constructors, Functionalities of the interface at level 0 @subsubheading Tests Predicates are offered for testing @itemize @item emptiness and universality of an abstract value: @item inclusion and equality of two abstract values; @item inclusion of a dimension into an interval given an abstract value; @iftex @tex $${\it abs}(\vec{x}) \models x_i \in I ~~ ?$$ @end tex @end iftex @item satisfaction of a linear constraint by the abstract value. @iftex @tex $${\it abs}(\vec{x}) \models {\it cons}(\vec{x}) ~~ {\tt or} ~~ {\it abs}(\vec{x}) \Rightarrow {\it cons}(\vec{x}) ~~ ?$$ @end tex @end iftex @end itemize @c ------------------------------------------------------------------- @node Property extraction, Lattice operations, Tests, Functionalities of the interface at level 0 @subsubheading Property extraction Some properties may be inferred given an abstract values: @itemize @item Interval of variation of a dimension in an abstract value; @iftex @tex $$\bigcap\{ I ~|~ {\it abs}(\vec{x}) \models x_i\in I\}$$ @end tex @end iftex @item Interval of variation of a linear expression in an abstract value; @iftex @tex $$\bigcap\{ I ~|~ {\it abs}(\vec{x}) \models {\it expr}(\vec{x})\in I\}$$ @end tex @end iftex @item Conversion to a bounding box @iftex @tex $$\bigcap\{ B ~|~ {\it abs}(\vec{x}) \subseteq B \}$$ @end tex @end iftex @item Conversion to a set of linear constraints (in the broad sense). @end itemize @noindent Notice that the second operation implements linear programming if it is exact. The third operation is not minimal, as it can be implemented using the first one, but it was convenient to include it. But the fourth operation is minimal and cannot be implemented using the second one, as the number of linear expression is infinite. @c ------------------------------------------------------------------- @node Lattice operations, Assignement and Substitutions, Property extraction, Functionalities of the interface at level 0 @subsubheading Lattice operations @itemize @item Least upper bound and greatest lower bound of two abstract values, and of arrays of abstract values; @item Intersection with one or several linear constraints; @iftex @tex $$\alpha\left(\gamma({\it abs}(\vec{x})) \cap \bigcap_i {\it cons}_i(\vec{x})\right)$$ @end tex @end iftex @item Addition of rays (for instance for implement generalized time elapse operator in linear hybrid systems). @iftex @tex $$\alpha\left(\left\{ \vec{x} + \sum_i \lambda_i \vec{r}_i ~|~ \vec{x}\in\gamma({\it abs}), \lambda_i\geq 0\right\}\right)$$ @end tex @end iftex @end itemize @c ------------------------------------------------------------------- @node Assignement and Substitutions, Operations on dimensions, Lattice operations, Functionalities of the interface at level 0 @subsubheading Assignement and Substitutions @itemize @item of a dimension by a (interval) linear expression @iftex @tex Assignement: $$\alpha\left(\biggl( \exists x_i: \Bigl(\gamma({\it abs}(\vec{x})) \cap x_i'={\it expr}(\vec{x})\Bigr)\biggr)[x_i\leftarrow x_i']\right)$$ Substitution: $$\alpha\biggl( \exists x_i': \Bigl(\gamma({\it abs}(\vec{x}))[x_i'\leftarrow x_i] \cap x_i'={\it expr}(\vec{x})\Bigr)\biggr)$$ @end tex @end iftex @item in parallel of several dimensions by several (interval) linear expressions @iftex @tex Assignement: $$\alpha\left(\biggl( \exists \vec{x}: \Bigl(\gamma({\it abs}(\vec{x})) \cap \bigcap_i x_i'={\it expr}_i(\vec{x})\Bigr)\biggr)[\vec{x}\leftarrow \vec{x'}]\right)$$ Substitution: $$\alpha\biggl( \exists \vec{x'}: \Bigl(\gamma({\it abs}(\vec{x'})) \cap \bigcap_i x_i'={\it expr}(\vec{x})\Bigr)\biggr)$$ @end tex @end iftex @end itemize @noindent Parallel assignement and substitution ar enot minimal operations, but for some abstract domains implementing them directly results in more efficient or more precise operations. @c ------------------------------------------------------------------- @node Operations on dimensions, Other operations, Assignement and Substitutions, Functionalities of the interface at level 0 @subsubheading Operations on dimensions @itemize @item Projection/Elimination of one or several dimensions with constant dimensionality; @iftex @tex Elimination: $$\exists x_i:{\it abs}(\vec{x})$$ Projection: $$(\exists x_i:{\it abs}(\vec{x}))\cap x_i=0$$ @end tex @end iftex @item Addition/Removal/Permutation of dimensions with corresponding change of dimensionality (with the exception of permutation). These operations allows to resize abstract values, and reorganize dimensions. @item Expansion and folding of dimensions. This is useful for the abstraction of arrays, where a dimension may represent several variables. @iftex @tex Expansion of $i$ into $i$, $j_1$, $j_2$ assuming $x_{j_1}$, $x_{j_2}$ are new dimensions: $${\it abs}(\vec{x}) \sqcap {\it abs}(\vec{x})[x_{j_1}\leftarrow x_i] \sqcap {\it abs}(\vec{x})[x_{j_2}\leftarrow x_i] ... $$ Folding of $j_0$ and $j_1$ into $j_0$: $$(\exists x_{j_1}:{\it abs}(\vec{x})) \sqcup (\exists x_{j_0}:{\it abs}(\vec{x})[x_{j_0}\leftarrow x_{j_1}] $$ @end tex @end iftex @end itemize @c ------------------------------------------------------------------- @node Other operations, , Operations on dimensions, Functionalities of the interface at level 0 @subsubheading Other operations Widening, either simple or with threshold, is offered. A generic widening with threshold function is offered in the interface. Topological closure (i.e., relaxation of strict inequalities) is offered. @c =================================================================== @node Functionalities of the interface at level 1, , Functionalities of the interface at level 0, APRON Rationale and Functionalities @section Functionalities of the interface at level 1 @c =================================================================== We focus on the changes brought by the level 1 w.r.t. the level 0. @menu * Variables and Environments:: * Semantics and Representation of an abstract value:: * Operations on environments:: * Dynamic typing w.r.t. environments:: * Operations on variables in abstract values:: @end menu @c ------------------------------------------------------------------- @node Variables and Environments, Semantics and Representation of an abstract value, Functionalities of the interface at level 1, Functionalities of the interface at level 1 @subsubheading Variables Dimensions are replaced by @emph{variables}. In the C interface, variables are defined by a generic type (@code{char*}, structured type, ...), equipped with the operations @code{compare}, @code{copy}, @code{free}, @code{to_string}. In the @sc{OCaml}, for technical reasons, the type is just the @code{string} type. @emph{Environments} manages the correspondance between the numerical dimensions of level 0 and the variables of level 1. @c ------------------------------------------------------------------- @node Semantics and Representation of an abstract value, Operations on environments, Variables and Environments, Functionalities of the interface at level 1 @subsubheading Semantics and Representation of an abstract value The semantics of an abstract value is a subset @iftex @tex $$X\subseteq V\rightarrow ({\cal N}\cup{\cal R})$$ @end tex @end iftex @ifnottex @quotation X -> (N+R). @end quotation @end ifnottex where @math{X} is a set of variables. @noindent Abstract values are typed according to their environment. It is represented by a structure @verbatim struct ap_abstract1_t { ap_abstract0_t *abstract0; ap_environment_t *env; }; @end verbatim Other datatypes of level 0 are extend in the same way. For instance, @verbatim struct ap_linexpr1_t { ap_linexpr0_t *linexpr0; ap_environment_t *env; }; @end verbatim @c ------------------------------------------------------------------- @node Operations on environments, Dynamic typing w.r.t. environments, Semantics and Representation of an abstract value, Functionalities of the interface at level 1 @subsubheading Operations on environments @itemize @item creation, merging, destruction @item addition/removal/renaming of variables @end itemize @c ------------------------------------------------------------------- @node Dynamic typing w.r.t. environments, Operations on variables in abstract values, Operations on environments, Functionalities of the interface at level 1 @subsubheading Dynamic typing w.r.t. environments For binary operations on abstract values, the environments should be the same. For operations involving an abstract value and an other datatype (expression, constraint, ...), one checks that the environment of the expression is a subenvironment of the environment of the abstract value, and one resize if necessary. @c ------------------------------------------------------------------- @node Operations on variables in abstract values, , Dynamic typing w.r.t. environments, Functionalities of the interface at level 1 @subsubheading Operations on variables in abstract values Operations on dimensions are lifted to operations on variables: @itemize @item Projection/Elimination of one or several variables with constant environment; @item Addition/Removal/Renaming of variables with corresponding change of environment; @item Change of environment (possibly combining removal and addition of variables); @item Expansion and folding of variables. @end itemize apron-dist-0.9.10/apron/apron/ap_global0.h0000640014525101416610000000123410644461001020150 0ustar bjeannetpopart/* ********************************************************************** */ /* ap_global0.h: level 0 */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _AP_GLOBAL0_H_ #define _AP_GLOBAL0_H_ #include "ap_config.h" #include "ap_scalar.h" #include "ap_interval.h" #include "ap_coeff.h" #include "ap_dimension.h" #include "ap_linexpr0.h" #include "ap_lincons0.h" #include "ap_generator0.h" #include "ap_texpr0.h" #include "ap_tcons0.h" #include "ap_manager.h" #include "ap_abstract0.h" #endif apron-dist-0.9.10/apron/apron/ap_config.h0000640014525101416610000000153510703516416020110 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_config.h */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _AP_CONFIG_H_ #define _AP_CONFIG_H_ #include #include #ifdef __cplusplus #define HAS_BOOL extern "C" { #endif #ifndef HAS_BOOL #define HAS_BOOL typedef char bool; static const bool false = 0; static const bool true = 1; #endif #if !(defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED || defined __APPLE__ || defined __CYGWIN__) static inline char* strdup(const char* s){ char* s2; s2 = malloc(strlen(s)+1); strcpy(s2,s); return s2; } #endif #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/ap_generic.h0000640014525101416610000001756110723557216020272 0ustar bjeannetpopart /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _AP_GENERIC_H_ #define _AP_GENERIC_H_ #include "ap_manager.h" #include "ap_expr0.h" #include "ap_abstract0.h" #ifdef __cplusplus extern "C" { #endif /* These functions are dedicated to implementors of domains. They offer generic default implementations for some of the operations required by the APRON API, when there is no more specific and efficient implementation for the domain being implemented. To use them, the function allocating manager, which is specific to the domain, should put the corresponding pointers in the virtual table to them. They manipulated "unboxed" abstract values, which are native to the underlying library: they are not yet boxed with the manager in the type ap_abstract0_t. */ /* ********************************************************************** */ /* I. Constructors, accessors, tests and property extraction */ /* ********************************************************************** */ bool ap_generic_sat_tcons(ap_manager_t* man, void* abs, ap_tcons0_t* cons, ap_scalar_discr_t discr, bool quasilinearize); /* This function implements a generic sat_tcons operation using ap_linearize_texpr0 and sat_lincons operations. */ ap_interval_t* ap_generic_bound_texpr(ap_manager_t* man, void* abs, ap_texpr0_t* expr, ap_scalar_discr_t discr, bool quasilinearize); /* This function implements a generic bound_texpr operation using to_box and ap_eval_texpr0 operations. */ ap_tcons0_array_t ap_generic_to_tcons_array(ap_manager_t* man, void* abs); /* This function implements a generic to_tcons_array operation using to_lincons_array operation. */ /* ********************************************************************** */ /* II. Operations */ /* ********************************************************************** */ /* ============================================================ */ /* Meet/Join on arrays of abstract values */ /* ============================================================ */ void* ap_generic_meetjoin_array(bool meet, ap_manager_t* man, void** tab, size_t size); /* This function implements a generic meet/join_array operation using copy and meet/join operations. */ static inline void* ap_generic_meet_array(ap_manager_t* man, void** tab, size_t size); /* This function implements a generic meet_array operation using copy and meet operations. */ static inline void* ap_generic_join_array(ap_manager_t* man, void** tab, size_t size); /* This function implements a generic join_array operation using copy and meet operations. */ /* ============================================================ */ /* Meet with array of constraints */ /* ============================================================ */ void* ap_generic_meet_quasilinearize_lincons_array(ap_manager_t* man, bool destructive, void* abs, ap_lincons0_array_t* array, ap_scalar_discr_t discr, bool linearize, void* (*meet_lincons_array)(ap_manager_t*, bool, void*,ap_lincons0_array_t*)); void* ap_generic_meet_intlinearize_tcons_array(ap_manager_t* man, bool destructive, void* abs, ap_tcons0_array_t* array, ap_scalar_discr_t discr, ap_linexpr_type_t linearize, void* (*meet_lincons_array)(ap_manager_t*, bool, void*, ap_lincons0_array_t*)); /* ============================================================ */ /* Assignments/Substitutions */ /* ============================================================ */ void* ap_generic_asssub_linexpr_array(bool assign, ap_manager_t* man, bool destructive, void* abs, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, void* dest); void* ap_generic_asssub_texpr_array(bool assign, ap_manager_t* man, bool destructive, void* abs, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, void* dest); /* These functions implement generic parallel assignment/substitution operations by: 1. introducing primed dimensions 2. transforming linear expressions into equality constraints relating the assigned primed dimension and the linear expression If dest!=NULL 3. introducing primed dimensions in dest 4. exchanging primed and unprimed dimensions in dest 5. intersecting the abstract value with the modified dest 6. intersecting the obtained abstract value with the constraints 7. exchanging primed and unprimed dimensions 8. removing the introduced (primed) dimensions It relies on: is_bottom, copy, dimension, add_dimensions, permute_dimensions, remove_dimensions, meet_lincons_array/meet_tcons_array, meet and free abstract operations. Meaning of parameters: - assign selects the operation: true means assignment, false substitution - The other parameters have the meaning they have for parallel assignment/substitution */ static inline void* ap_generic_assign_linexpr_array(ap_manager_t* man, bool destructive, void* abs, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, void* dest); static inline void* ap_generic_assign_texpr_array(ap_manager_t* man, bool destructive, void* abs, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, void* dest); /* These functions implement generic parallel assignment operations by relying on is_bottom, copy, dimension, add_dimensions, permute_dimensions, remove_dimensions, meet_lincons_array or meet_tcons_array abstract operations. */ static inline void* ap_generic_substitute_linexpr_array(ap_manager_t* man, bool destructive, void* abs, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, void* dest); static inline void* ap_generic_substitute_texpr_array(ap_manager_t* man, bool destructive, void* abs, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, void* dest); /* These functions implement generic parallel assignment operations by relying on is_bottom, copy, dimension, add_dimensions, permute_dimensions, remove_dimensions, meet_lincons_array or meet_tcons_array abstract operations. */ /* ********************************************************************** */ /* III. Inline functions definitions */ /* ********************************************************************** */ static inline void* ap_generic_meet_array(ap_manager_t* man, void** tab, size_t size) { return ap_generic_meetjoin_array(true,man,tab,size); } static inline void* ap_generic_join_array(ap_manager_t* man, void** tab, size_t size) { return ap_generic_meetjoin_array(false,man,tab,size); } static inline void* ap_generic_assign_linexpr_array(ap_manager_t* man, bool destructive, void* abs, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, void* dest) { return ap_generic_asssub_linexpr_array(true, man, destructive, abs, tdim, texpr, size, dest); } static inline void* ap_generic_substitute_linexpr_array(ap_manager_t* man, bool destructive, void* abs, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, void* dest) { return ap_generic_asssub_linexpr_array(false, man, destructive, abs, tdim, texpr, size, dest); } static inline void* ap_generic_assign_texpr_array(ap_manager_t* man, bool destructive, void* abs, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, void* dest) { return ap_generic_asssub_texpr_array(true, man, destructive, abs, tdim, texpr, size, dest); } static inline void* ap_generic_substitute_texpr_array(ap_manager_t* man, bool destructive, void* abs, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, void* dest) { return ap_generic_asssub_texpr_array(false, man, destructive, abs, tdim, texpr, size, dest); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/ap_interval.h0000640014525101416610000001067211247456444020501 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_interval.h: intervals */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _AP_INTERVAL_H_ #define _AP_INTERVAL_H_ #include #include #include #include "ap_config.h" #include "ap_scalar.h" #ifdef __cplusplus extern "C" { #endif typedef struct ap_interval_t { ap_scalar_t* inf; ap_scalar_t* sup; } ap_interval_t; /* ====================================================================== */ /* Basics */ /* ====================================================================== */ ap_interval_t* ap_interval_alloc(void); /* Initialization, using DOUBLE as default type for scalars */ void ap_interval_reinit(ap_interval_t* interval, ap_scalar_discr_t ap_scalar_discr); /* Change the type of scalars */ void ap_interval_free(ap_interval_t* interval); /* Free an interval */ void ap_interval_fprint(FILE* stream, ap_interval_t* a); static inline void ap_interval_print(ap_interval_t* a) { ap_interval_fprint(stdout,a); } /* Printing */ static inline void ap_interval_swap(ap_interval_t* a, ap_interval_t* b) { ap_interval_t t = *a; *a = *b; *b = t; } /* Exchange */ /* ====================================================================== */ /* Assignments */ /* ====================================================================== */ void ap_interval_set(ap_interval_t* interval, ap_interval_t* interval2); /* Assignment */ void ap_interval_set_scalar(ap_interval_t* interval, ap_scalar_t* inf, ap_scalar_t* sup); void ap_interval_set_mpq(ap_interval_t* interval, mpq_t inf, mpq_t sup); void ap_interval_set_int(ap_interval_t* interval, long int inf, long int sup); void ap_interval_set_frac(ap_interval_t* interval, long int numinf, unsigned long int deninf, long int numsup, unsigned long int densup); void ap_interval_set_double(ap_interval_t* interval, double inf, double sup); void ap_interval_set_mpfr(ap_interval_t* interval, mpfr_t inf, mpfr_t sup); /* Assignment from resp. - two scalars - two rationals of type MPQ - two integers, giving [inf,dup] - two rationals, giving [numinf/deninf,numsup/densup] - two double values - two MPFR floating-point numbers */ void ap_interval_set_top(ap_interval_t* interval); /* Assignment to universe interval [-oo,oo], does not change the type of scalars */ void ap_interval_set_bottom(ap_interval_t* interval); /* Assignment to empty interval [1,-1], does not change the type of scalars */ /* ====================================================================== */ /* Combined allocation and assignments */ /* ====================================================================== */ ap_interval_t* ap_interval_alloc_set(ap_interval_t* interval); /* Assignment */ /* ====================================================================== */ /* Tests */ /* ====================================================================== */ bool ap_interval_is_top(ap_interval_t* interval); /* Is it the universe interval ? */ bool ap_interval_is_bottom(ap_interval_t* interval); /* Is it an empty interval ? */ bool ap_interval_is_leq(ap_interval_t* i1, ap_interval_t* i2); /* Inclusion test */ int ap_interval_cmp(ap_interval_t* i1, ap_interval_t* i2); /* Comparison: 0: equality -1: i1 included in i2 +1: i2 included in i1 -2: i1.inf less than i2.inf +2: i1.inf greater than i2.inf */ bool ap_interval_equal(ap_interval_t* i1, ap_interval_t* i2); bool ap_interval_equal_int(ap_interval_t* i, int b); /* Equality */ /* ====================================================================== */ /* Other operations */ /* ====================================================================== */ void ap_interval_neg(ap_interval_t* a, ap_interval_t* b); /* Negation */ long ap_interval_hash(ap_interval_t* itv); /* Hash code */ /* ====================================================================== */ /* Array of intervals */ /* ====================================================================== */ ap_interval_t** ap_interval_array_alloc(size_t size); /* Allocating an array of intervals, initialized with [0,0] values */ void ap_interval_array_free(ap_interval_t** array, size_t size); /* Clearing and freeing an array of intervals */ #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/ap_var.h0000640014525101416610000000300110760562320017417 0ustar bjeannetpopart/* ********************************************************************** */ /* ap_var.h: variables (strings or user-defined) */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _AP_VAR_H_ #define _AP_VAR_H_ #ifdef __cplusplus extern "C" { #endif /* ====================================================================== */ /* Datatype */ /* ====================================================================== */ /* The abstract type ap_var_t is equipped with a total ordering function, a copy function, and a free function. The parametrization is done via a global variable pointing to an ap_var_operations_t structure. */ typedef void* ap_var_t; typedef struct ap_var_operations_t { int (*compare)(ap_var_t v1, ap_var_t v2); /* Total ordering function */ int (*hash)(ap_var_t v); /* Hash function */ ap_var_t (*copy)(ap_var_t var); /* Duplication function */ void (*free)(ap_var_t var); /* Deallocation function */ char* (*to_string)(ap_var_t var); /* Conversion to a dynamically allocated string */ } ap_var_operations_t; extern ap_var_operations_t ap_var_operations_default; /* default manager: ap_var_t are char* */ extern ap_var_operations_t* ap_var_operations; /* points to manager in use, by default ap_var_operations_default */ #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/lgpl.texi0000640014525101416610000006364710437601460017655 0ustar bjeannetpopart@center Version 2.1, February 1999 @display Copyright @copyright{} 1991, 1999 Free Software Foundation, Inc. 51 Franklin St -- Fifth Floor, Boston, MA 02110-1301, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] @end display @subheading Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software---to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software---typically libraries---of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the @dfn{Lesser} General Public License because it does @emph{Less} to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a ``work based on the library'' and a ``work that uses the library''. The former contains code derived from the library, whereas the latter must be combined with the library in order to run. @subheading TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION @enumerate 0 @item This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called ``this License''). Each licensee is addressed as ``you''. A ``library'' means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The ``Library'', below, refers to any such software library or work which has been distributed under these terms. A ``work based on the Library'' means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term ``modification''.) ``Source code'' for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. @item You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. @item You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: @enumerate a @item The modified work must itself be a software library. @item You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. @item You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. @item If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) @end enumerate These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. @item You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. @item You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. @item A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a ``work that uses the Library''. Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a ``work that uses the Library'' with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a ``work that uses the library''. The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a ``work that uses the Library'' uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. @item As an exception to the Sections above, you may also combine or link a ``work that uses the Library'' with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: @enumerate a @item Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable ``work that uses the Library'', as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) @item Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. @item Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. @item If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. @item Verify that the user has already received a copy of these materials or that you have already sent this user a copy. @end enumerate For an executable, the required form of the ``work that uses the Library'' must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. @item You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: @enumerate a @item Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. @item Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. @end enumerate @item You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. @item You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. @item Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. @item If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. @item If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. @item The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and ``any later version'', you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. @item If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. @iftex @heading NO WARRANTY @end iftex @ifinfo @center NO WARRANTY @end ifinfo @item BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. @item IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. @end enumerate @iftex @heading END OF TERMS AND CONDITIONS @end iftex @ifinfo @center END OF TERMS AND CONDITIONS @end ifinfo @page @subheading How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the ``copyright'' line and a pointer to where the full notice is found. @smallexample @var{one line to give the library's name and an idea of what it does.} Copyright (C) @var{year} @var{name of author} This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @end smallexample Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a ``copyright disclaimer'' for the library, if necessary. Here is a sample; alter the names: @smallexample Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. @var{signature of Ty Coon}, 1 April 1990 Ty Coon, President of Vice @end smallexample That's all there is to it! apron-dist-0.9.10/apron/apron/ap_scalar.h0000640014525101416610000001600311006063143020073 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_scalar.h: scalars */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _AP_SCALAR_H_ #define _AP_SCALAR_H_ #include #include #include #include #include #include "gmp.h" #include "mpfr.h" #include "ap_config.h" #ifdef __cplusplus extern "C" { #endif /* ********************************************************************** */ /* I. Datatypes */ /* ********************************************************************** */ typedef enum ap_scalar_discr_t { AP_SCALAR_DOUBLE, /* double-precision floating-point number */ AP_SCALAR_MPQ, /* GMP arbitrary precision rational */ AP_SCALAR_MPFR, /* MPFR floating-point number */ } ap_scalar_discr_t; typedef struct ap_scalar_t { ap_scalar_discr_t discr; union { double dbl; mpq_ptr mpq; /* +infty coded by 1/0, -infty coded by -1/0 */ mpfr_ptr mpfr; } val; } ap_scalar_t; /* ********************************************************************** */ /* II. Operations */ /* ********************************************************************** */ /* ====================================================================== */ /* Basics */ /* ====================================================================== */ ap_scalar_t* ap_scalar_alloc(void); /* Allocates a scalar, of default type DOUBLE (the most economical) */ void ap_scalar_free(ap_scalar_t* scalar); /* Free a scalar */ void ap_scalar_reinit(ap_scalar_t* scalar, ap_scalar_discr_t d); /* Change the type of an already allocated scalar (mainly for internal use */ static inline void ap_scalar_print(ap_scalar_t* a); void ap_scalar_fprint(FILE* stream, ap_scalar_t* a); /* Printing */ extern int ap_scalar_print_prec; /* Number of significant digits to print for floating-point numbers. Defaults to 20. */ static inline void ap_scalar_swap(ap_scalar_t* a, ap_scalar_t* b); /* Exchange */ /* ====================================================================== */ /* Assignments */ /* ====================================================================== */ void ap_scalar_set(ap_scalar_t* scalar, ap_scalar_t* scalar2); /* Assignment */ void ap_scalar_set_mpq(ap_scalar_t* scalar, mpq_t mpq); void ap_scalar_set_int(ap_scalar_t* scalar, long int i); void ap_scalar_set_frac(ap_scalar_t* scalar, long int i, unsigned long int j); /* Change the type of scalar to MPQ and initialize it resp. with - mpq - integer i - rational i/j, assuming j!=0 */ void ap_scalar_set_double(ap_scalar_t* scalar, double k); /* Change the type of scalar to DOUBLE and initialize it with k. */ void ap_scalar_set_mpfr(ap_scalar_t* scalar, mpfr_t mpfr); /* Change the type of scalar to MPFR and initialize it with mpfr. The precision of the scalar is changed to match that of mpfr. */ void ap_scalar_set_infty(ap_scalar_t* scalar, int sgn); /* Assignment to sgn*infty. Keep the type of the scalar. If sgn == 0, set to zero. */ /* ====================================================================== */ /* Combined allocation and assignment */ /* ====================================================================== */ ap_scalar_t* ap_scalar_alloc_set(ap_scalar_t* scalar2); ap_scalar_t* ap_scalar_alloc_set_mpq(mpq_t mpq); /* Allocate an MPQ scalar and initialize it with mpq */ ap_scalar_t* ap_scalar_alloc_set_double(double k); /* Allocate an DOUBLE scalar and initialize it with k. */ ap_scalar_t* ap_scalar_alloc_set_mpfr(mpfr_t mpfr); /* Allocate an MPFR scalar and initialize it with mpfr. The precisio of the scalar matches that of mpfr. */ /* ====================================================================== */ /* Conversions */ /* ====================================================================== */ /* For the two next functions, the returned value is zero if conversion is exact, positive if the result is greater, negative if it is lower. */ int ap_mpq_set_scalar(mpq_t mpq, ap_scalar_t* scalar, mp_rnd_t round); /* Assign mpq with the value of scalar, possibly converting from another type. Currently, round is not needed, as the conversion is exact */ int ap_double_set_scalar(double* k, ap_scalar_t* scalar, mp_rnd_t round); /* Return the value of scalar in DOUBLE type, possibly converting from another type. */ int ap_mpfr_set_scalar(mpfr_t mpfr, ap_scalar_t* scalar, mp_rnd_t round); /* Return the value of scalar in MPFR type, possibly converting from another type. The precision of mpfr is NOT changed to match that of scalar, so, rounding may occur. */ /* ====================================================================== */ /* Tests */ /* ====================================================================== */ int ap_scalar_infty(ap_scalar_t* scalar); /* -1:-infty, 0:finite; 1:+infty */ int ap_scalar_cmp(ap_scalar_t* a, ap_scalar_t* b); int ap_scalar_cmp_int(ap_scalar_t* a, int b); /* Exact comparison between two scalars (resp. a scalar and an integer) -1: a is less than b 0: a is equal to b 1: a is greater than b */ bool ap_scalar_equal(ap_scalar_t* a, ap_scalar_t* b); bool ap_scalar_equal_int(ap_scalar_t* a, int b); /* Exact Equality test */ int ap_scalar_sgn(ap_scalar_t* a); /* -1: negative, 0: null, +1: positive */ /* ====================================================================== */ /* Other operations */ /* ====================================================================== */ void ap_scalar_neg(ap_scalar_t* a, ap_scalar_t* b); /* Negation */ void ap_scalar_inv(ap_scalar_t* a, ap_scalar_t* b); /* Inversion. Not exact for floating-point type */ long ap_scalar_hash(ap_scalar_t* a); /* Return an hash code (for instance for OCaml interface) */ /* ********************************************************************** */ /* III. FOR INTERNAL USE ONLY */ /* ********************************************************************** */ static inline void ap_scalar_init(ap_scalar_t* scalar, ap_scalar_discr_t d) { scalar->discr = d; switch(d){ case AP_SCALAR_MPQ: scalar->val.mpq = (mpq_ptr)malloc(sizeof(mpq_t)); mpq_init(scalar->val.mpq); break; case AP_SCALAR_MPFR: scalar->val.mpfr = (mpfr_ptr)malloc(sizeof(mpfr_t)); mpfr_init(scalar->val.mpfr); break; case AP_SCALAR_DOUBLE: scalar->val.dbl = 0.0; break; } } static inline void ap_scalar_clear(ap_scalar_t* scalar) { switch(scalar->discr){ case AP_SCALAR_MPQ: mpq_clear(scalar->val.mpq); free(scalar->val.mpq); break; case AP_SCALAR_MPFR: mpfr_clear(scalar->val.mpfr); free(scalar->val.mpfr); break; case AP_SCALAR_DOUBLE: break; } } static inline void ap_scalar_print(ap_scalar_t* a) { ap_scalar_fprint(stdout,a); } static inline void ap_scalar_swap(ap_scalar_t* a, ap_scalar_t* b){ ap_scalar_t t = *a; *a = *b; *b = t; } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/ap_reducedproduct.c0000640014525101416610000013220111251667746021661 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_reducedproduct.c: generic reduced product of N domains */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include "ap_global0.h" #include "ap_reducedproduct.h" /* ------------------------------------------------------------ */ /* Allocates an abstract value */ static inline ap_reducedproduct_t* ap_reducedproduct_alloc(size_t size) { size_t i; ap_reducedproduct_t* res = malloc(sizeof(ap_reducedproduct_t) + size*sizeof(void*)); res->reduced = false; for (i=0; ip[i] = NULL; return res; } /* ------------------------------------------------------------ */ /* Get internal and optionally reduce the product(s) */ static inline ap_reducedproduct_internal_t* get_internal_init0(ap_manager_t* manager) { return (ap_reducedproduct_internal_t*)manager->internal; } static inline ap_reducedproduct_internal_t* get_internal_init1(ap_manager_t* manager, ap_funid_t funid, ap_reducedproduct_t* a) { ap_reducedproduct_internal_t* intern = get_internal_init0(manager); if (a->reduced==false && manager->option.funopt[funid].algorithm & 0x1){ intern->reduce(manager,a); } return intern; } static inline ap_reducedproduct_internal_t* get_internal_init2(ap_manager_t* manager, ap_funid_t funid, ap_reducedproduct_t* a, ap_reducedproduct_t* b) { ap_reducedproduct_internal_t* intern = get_internal_init0(manager); if (manager->option.funopt[funid].algorithm & 0x1){ if (a->reduced==false) intern->reduce(manager,a); if (b && b->reduced==false) intern->reduce(manager,b); } return intern; } static inline ap_reducedproduct_internal_t* get_internal_init_tab(ap_manager_t* manager, ap_funid_t funid, ap_reducedproduct_t** tab, size_t size) { size_t i; ap_reducedproduct_internal_t* intern = get_internal_init0(manager); if (manager->option.funopt[funid].algorithm & 0x1){ for (i=0; ireduced==false) intern->reduce(manager,tab[i]); } } return intern; } /* ------------------------------------------------------------ */ static void collect_results0(ap_manager_t* manager) { size_t i; ap_reducedproduct_internal_t* intern = get_internal_init0(manager); ap_result_t* gresult = &manager->result; gresult->flag_best = true; gresult->flag_exact = true; for (i=0;isize; i++){ ap_manager_t* man = intern->tmanagers[i]; ap_result_t* result = &man->result; gresult->flag_exact = gresult->flag_exact && result->flag_exact; if (result->exclog != NULL){ ap_exclog_t* last = result->exclog; while (true){ char* buffer = malloc(strlen(man->library)+(last->msg ? strlen(last->msg) : 0)+3); sprintf(buffer,"%s: %s", man->library,(last->msg ? "" : last->msg)); if (last->msg) free(last->msg); last->msg = buffer; if (last->tail) last = last->tail; else break; } last->tail = gresult->exclog; gresult->exclog = result->exclog; result->exclog = NULL; } } } static void collect_results1(ap_manager_t* manager, ap_funid_t funid, ap_reducedproduct_t* a) { collect_results0(manager); ap_reducedproduct_internal_t* intern = get_internal_init0(manager); if (a->reduced==false && manager->option.funopt[funid].algorithm & 0x2){ intern->reduce(manager,a); a->reduced = true; } } /* ------------------------------------------------------------ */ /* Fills the value with bottom. It is assumed that a->p[index] is already bottom. If destructive is true, then a->p[i] for i>index may be not NULL and is cleaned first. */ static void set_bottom(ap_reducedproduct_internal_t* intern, bool destructive, ap_reducedproduct_t* a, size_t index /* index of the already bottom dimension */ ) { size_t i; ap_manager_t* man = intern->tmanagers[index]; ap_dimension_t (*dimension)(ap_manager_t*,...) = man->funptr[AP_FUNID_DIMENSION]; ap_dimension_t dim = dimension(man,a->p[index]); for (i=0; isize; i++){ if (i!=index){ man = intern->tmanagers[i]; if (ifunptr[AP_FUNID_FREE]; free(man,a->p[i]); } void* (*bottom)(ap_manager_t*,...) = man->funptr[AP_FUNID_BOTTOM]; a->p[i] = bottom(man, dim.intdim, dim.realdim); } } a->reduced = true; } /* ********************************************************************** */ /* I. General management */ /* ********************************************************************** */ #define VOID_MAN_VAL(NAME,FUNID) \ void ap_reducedproduct_##NAME(ap_manager_t* manager, ap_reducedproduct_t* a) \ { \ ap_reducedproduct_internal_t* intern = get_internal_init1(manager,FUNID,a); \ size_t i; \ \ for (i=0;isize;i++){ \ ap_manager_t* man = intern->tmanagers[i]; \ void (*ptr)(ap_manager_t*,...) = man->funptr[FUNID]; \ ptr(man,a->p[i]); \ } \ collect_results1(manager,FUNID,a); \ } /* ============================================================ */ /* I.1 Memory */ /* ============================================================ */ ap_reducedproduct_t* ap_reducedproduct_copy(ap_manager_t* manager, ap_reducedproduct_t* a) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_COPY,a); size_t i; ap_reducedproduct_t* res = ap_reducedproduct_alloc(intern->size); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_COPY]; res->p[i] = ptr(man,a->p[i]); } res->reduced = a->reduced; collect_results1(manager,AP_FUNID_COPY,res); return res; } void ap_reducedproduct_free(ap_manager_t* manager, ap_reducedproduct_t* a) { ap_reducedproduct_internal_t* intern = get_internal_init0(manager); size_t i; for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_FREE]; ptr(man,a->p[i]); } free(a); collect_results0(manager); } size_t ap_reducedproduct_size(ap_manager_t* manager, ap_reducedproduct_t* a) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_ASIZE,a); size_t i; size_t res = 0; for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; size_t (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_ASIZE]; res += ptr(man,a->p[i]); } collect_results0(manager); return res; } /* ============================================================ */ /* I.2 Control of internal representation */ /* ============================================================ */ VOID_MAN_VAL(minimize,AP_FUNID_MINIMIZE) VOID_MAN_VAL(canonicalize,AP_FUNID_CANONICALIZE) int ap_reducedproduct_hash(ap_manager_t* manager, ap_reducedproduct_t* a) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_HASH,a); size_t i; int res = 0; for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; size_t (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_HASH]; res += ptr(man,a->p[i]); } collect_results0(manager); return res; } void ap_reducedproduct_approximate(ap_manager_t* manager, ap_reducedproduct_t* a, int n) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_APPROXIMATE,a); intern->approximate(manager,(void*)a,n); collect_results0(manager); } /* ============================================================ */ /* I.3 Printing */ /* ============================================================ */ void ap_reducedproduct_fprint(FILE* stream, ap_manager_t* manager, ap_reducedproduct_t* a, char** name_of_dim) { ap_reducedproduct_internal_t* intern = get_internal_init0(manager); size_t i; fprintf(stream,"reduced product of library %s\n",manager->library); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void (*ptr)(FILE* stream, ap_manager_t*,...) = man->funptr[AP_FUNID_FPRINT]; ptr(stream,man,a->p[i],name_of_dim); } collect_results0(manager); } void ap_reducedproduct_fprintdiff(FILE* stream, ap_manager_t* manager, ap_reducedproduct_t* a, ap_reducedproduct_t* b, char** name_of_dim) { ap_reducedproduct_internal_t* intern = get_internal_init0(manager); size_t i; fprintf(stream,"reduced product of library %s\n",manager->library); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void (*ptr)(FILE* stream, ap_manager_t*,...) = man->funptr[AP_FUNID_FPRINTDIFF]; ptr(stream,man,a->p[i],b->p[i],name_of_dim); } collect_results0(manager); } void ap_reducedproduct_fdump(FILE* stream, ap_manager_t* manager, ap_reducedproduct_t* a) { ap_reducedproduct_internal_t* intern = get_internal_init0(manager); size_t i; fprintf(stream,"reduced product of library %s\n",manager->library); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void (*ptr)(FILE* stream, ap_manager_t*,...) = man->funptr[AP_FUNID_FDUMP]; ptr(stream,man,a->p[i]); } collect_results0(manager); } /* ============================================================ */ /* I.4 Serialization */ /* ============================================================ */ ap_membuf_t ap_reducedproduct_serialize_raw(ap_manager_t* manager, ap_reducedproduct_t* a) { ap_reducedproduct_internal_t* intern = get_internal_init0(manager); size_t i, index; ap_membuf_t gres; gres.ptr = NULL; gres.size = 0; for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; ap_membuf_t (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_SERIALIZE_RAW]; ap_membuf_t res = ptr(man,a->p[i]); gres.ptr = realloc(gres.ptr, gres.size + res.size); memcpy(((char*)gres.ptr + gres.size), res.ptr, res.size); gres.size += res.size; free(res.ptr); } collect_results0(manager); return gres; } ap_reducedproduct_t* ap_reducedproduct_deserialize_raw(ap_manager_t* manager, void* p, size_t* size) { ap_reducedproduct_internal_t* intern = get_internal_init0(manager); size_t i,nb,dummy; ap_reducedproduct_t* res = ap_reducedproduct_alloc(intern->size); if (size==NULL) size = &dummy; *size = 0; for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_DESERIALIZE_RAW]; size_t nb; res->p[i] = ptr(man,((char*)p + *size), &nb); *size += nb; } collect_results0(manager); return res; } /* ********************************************************************** */ /* II. Constructor, accessors, tests and property extraction */ /* ********************************************************************** */ /* ============================================================ */ /* II.1 Basic constructors */ /* ============================================================ */ #define BOTTOM_TOP(NAME,FUNID) \ ap_reducedproduct_t* ap_reducedproduct_##NAME(ap_manager_t* manager, size_t intdim, size_t realdim) \ { \ ap_reducedproduct_internal_t* intern = get_internal_init0(manager); \ size_t i; \ ap_reducedproduct_t* res = ap_reducedproduct_alloc(intern->size); \ \ for (i=0;isize;i++){ \ ap_manager_t* man = intern->tmanagers[i]; \ void* (*ptr)(ap_manager_t*,...) = man->funptr[FUNID]; \ res->p[i] = ptr(man,intdim,realdim); \ } \ res->reduced = true; \ collect_results0(manager); \ return res; \ } BOTTOM_TOP(bottom,AP_FUNID_BOTTOM) BOTTOM_TOP(top,AP_FUNID_TOP) ap_reducedproduct_t* ap_reducedproduct_of_box(ap_manager_t* manager, size_t intdim, size_t realdim, ap_interval_t** tinterval) { ap_reducedproduct_internal_t* intern = get_internal_init0(manager); size_t i; ap_reducedproduct_t* res = ap_reducedproduct_alloc(intern->size); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_OF_BOX]; res->p[i] = ptr(man,intdim,realdim,tinterval); bool (*is_bottom)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_BOTTOM]; if (is_bottom(man,res->p[i])){ set_bottom(intern,false,res,i); break; } } collect_results1(manager,AP_FUNID_OF_BOX,res); return res; } ap_dimension_t ap_reducedproduct_dimension(ap_manager_t* manager, ap_reducedproduct_t* a) { ap_reducedproduct_internal_t* intern = get_internal_init0(manager); ap_manager_t* man = intern->tmanagers[0]; ap_dimension_t (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_DIMENSION]; return ptr(man,a->p[0]); } /* ============================================================ */ /* II.3 Tests */ /* ============================================================ */ bool ap_reducedproduct_is_bottom(ap_manager_t* manager, ap_reducedproduct_t* a) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_IS_BOTTOM,a); size_t i; bool gres = false; for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; bool (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_BOTTOM]; bool res = ptr(man,a->p[i]); gres = gres || res; if (gres) break; } collect_results0(manager); return gres; } bool ap_reducedproduct_is_top(ap_manager_t* manager, ap_reducedproduct_t* a) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_IS_TOP,a); size_t i; bool gres = true; for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; bool (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_TOP]; bool res = ptr(man,a->p[i]); gres = gres && res; if (!gres) break; } collect_results0(manager); return gres; } #define BOOL_MAN_VAL2(NAME,FUNID) \ bool ap_reducedproduct_##NAME(ap_manager_t* manager, ap_reducedproduct_t* a, ap_reducedproduct_t* b) \ { \ ap_reducedproduct_internal_t* intern = \ get_internal_init2(manager,FUNID,a,b); \ size_t i; \ bool gres = true; \ \ for (i=0;isize;i++){ \ ap_manager_t* man = intern->tmanagers[i]; \ bool (*ptr)(ap_manager_t*,...) = man->funptr[FUNID]; \ bool res = ptr(man,a->p[i],b->p[i]); \ gres = gres && res; \ if (!gres) break; \ } \ collect_results0(manager); \ return gres; \ } BOOL_MAN_VAL2(is_leq,AP_FUNID_IS_LEQ) BOOL_MAN_VAL2(is_eq,AP_FUNID_IS_EQ) bool ap_reducedproduct_sat_lincons(ap_manager_t* manager, ap_reducedproduct_t* a, ap_lincons0_t* lincons) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_SAT_LINCONS,a); size_t i; bool gres = false; for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; bool (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_SAT_LINCONS]; bool res = ptr(man,a->p[i],lincons); gres = gres || res; if (gres) break; } collect_results0(manager); return gres; } bool ap_reducedproduct_sat_tcons(ap_manager_t* manager, ap_reducedproduct_t* a, ap_tcons0_t* tcons) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_SAT_TCONS,a); size_t i; bool gres = false; for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; bool (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_SAT_TCONS]; bool res = ptr(man,a->p[i],tcons); gres = gres || res; if (gres) break; } collect_results0(manager); return gres; } bool ap_reducedproduct_sat_interval(ap_manager_t* manager, ap_reducedproduct_t* a, ap_dim_t dim, ap_interval_t* interval) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_SAT_INTERVAL,a); size_t i; bool gres = false; for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; bool (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_SAT_INTERVAL]; bool res = ptr(man,a->p[i],dim,interval); gres = gres || res; if (gres) break; } collect_results0(manager); return gres; } bool ap_reducedproduct_is_dimension_unconstrained(ap_manager_t* manager, ap_reducedproduct_t* a, ap_dim_t dim) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_IS_DIMENSION_UNCONSTRAINED,a); size_t i; bool gres = true; for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; bool (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_DIMENSION_UNCONSTRAINED]; bool res = ptr(man,a->p[i],dim); gres = gres && res; if (!gres) break; } collect_results0(manager); return gres; } /* ============================================================ */ /* II.4 Extraction of properties */ /* ============================================================ */ static void ap_interval_meet_with(ap_interval_t* a, ap_interval_t* b) { if (ap_scalar_cmp(a->inf,b->inf)<0){ ap_scalar_set(a->inf,b->inf); } if (ap_scalar_cmp(a->sup,b->sup)>0){ ap_scalar_set(a->sup,b->sup); } } ap_interval_t* ap_reducedproduct_bound_linexpr(ap_manager_t* manager, ap_reducedproduct_t* a, ap_linexpr0_t* expr) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_BOUND_LINEXPR,a); size_t i; ap_interval_t* gres = ap_interval_alloc(); ap_interval_set_top(gres); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; ap_interval_t* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_BOUND_LINEXPR]; ap_interval_t* res = ptr(man,a->p[i],expr); ap_interval_meet_with(gres,res); ap_interval_free(res); if (ap_interval_is_bottom(gres)) break; } collect_results0(manager); return gres; } ap_interval_t* ap_reducedproduct_bound_texpr(ap_manager_t* manager, ap_reducedproduct_t* a, ap_texpr0_t* expr) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_BOUND_TEXPR,a); size_t i; ap_interval_t* gres = ap_interval_alloc(); ap_interval_set_top(gres); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; ap_interval_t* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_BOUND_TEXPR]; ap_interval_t* res = ptr(man,a->p[i],expr); ap_interval_meet_with(gres,res); ap_interval_free(res); if (ap_interval_is_bottom(gres)) break; } collect_results0(manager); return gres; } ap_interval_t* ap_reducedproduct_bound_dimension(ap_manager_t* manager, ap_reducedproduct_t* a, ap_dim_t dim) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_BOUND_DIMENSION,a); size_t i; ap_interval_t* gres = ap_interval_alloc(); ap_interval_set_top(gres); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; ap_interval_t* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_BOUND_DIMENSION]; ap_interval_t* res = ptr(man,a->p[i],dim); ap_interval_meet_with(gres,res); ap_interval_free(res); if (ap_interval_is_bottom(gres)) break; } collect_results0(manager); return gres; } ap_lincons0_array_t ap_reducedproduct_to_lincons_array(ap_manager_t* manager, ap_reducedproduct_t* a) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_TO_LINCONS_ARRAY,a); size_t i,j; ap_lincons0_array_t garray; garray.p = NULL; garray.size = 0; for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; ap_lincons0_array_t (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_TO_LINCONS_ARRAY]; ap_lincons0_array_t array = ptr(man,a->p[i]); garray.p = realloc(garray.p, (garray.size + array.size) * sizeof(ap_lincons0_t)); for (j=0;jsize;i++){ ap_manager_t* man = intern->tmanagers[i]; ap_tcons0_array_t (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_TO_TCONS_ARRAY]; ap_tcons0_array_t array = ptr(man,a->p[i]); garray.p = realloc(garray.p, (garray.size + array.size) * sizeof(ap_tcons0_t)); for (j=0;jsize;i++){ ap_manager_t* man = intern->tmanagers[i]; ap_interval_t** (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_TO_BOX]; ap_interval_t** box = ptr(man,a->p[i]); if (i==0){ gbox = box; ap_dimension_t (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_DIMENSION]; ap_dimension_t dimension = ptr(man,a->p[i]); nbdims = dimension.intdim+dimension.realdim; } else { for (j=0; jsize); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[funid]; res->p[i] = ptr(man,destructive,a1->p[i],a2->p[i]); if (funid==AP_FUNID_MEET){ bool (*is_bottom)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_BOTTOM]; if (is_bottom(man,res->p[i])){ set_bottom(intern,destructive,res,i); goto ap_reducedproduct_meetjoin_exit; } } } res->reduced = funid==AP_FUNID_JOIN && a1->reduced && a2->reduced; ap_reducedproduct_meetjoin_exit: collect_results1(manager,funid,res); return res; } ap_reducedproduct_t* ap_reducedproduct_meet(ap_manager_t* manager, bool destructive, ap_reducedproduct_t* a1, ap_reducedproduct_t* a2) { return ap_reducedproduct_meetjoin(AP_FUNID_MEET,manager,destructive,a1,a2); } ap_reducedproduct_t* ap_reducedproduct_join(ap_manager_t* manager, bool destructive, ap_reducedproduct_t* a1, ap_reducedproduct_t* a2) { return ap_reducedproduct_meetjoin(AP_FUNID_JOIN,manager,destructive,a1,a2); } ap_reducedproduct_t* ap_reducedproduct_meetjoin_array(ap_funid_t funid, /* either meet or join */ ap_manager_t* manager, ap_reducedproduct_t** tab, size_t size) { ap_reducedproduct_internal_t* intern = get_internal_init_tab(manager,funid,tab,size); size_t i,j; ap_reducedproduct_t* res; void** a; res = ap_reducedproduct_alloc(intern->size); a = (void**)malloc(size*sizeof(void*)); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[funid]; for (j=0;jp[i]; } res->p[i] = ptr(man,a,size); if (funid==AP_FUNID_MEET_ARRAY){ bool (*is_bottom)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_BOTTOM]; if (is_bottom(man,res->p[i])){ set_bottom(intern,false,res,i); goto ap_reducedproduct_meetjoin_array_exit; } } } if (funid==AP_FUNID_JOIN){ res->reduced = tab[0]->reduced; i = 1; while (res->reduced && ireduced = tab[i]->reduced; i++; } } else { res->reduced = false; } ap_reducedproduct_meetjoin_array_exit: free(a); collect_results1(manager,funid,res); return res; } ap_reducedproduct_t* ap_reducedproduct_meet_array(ap_manager_t* manager, ap_reducedproduct_t** tab, size_t size) { return ap_reducedproduct_meetjoin_array(AP_FUNID_MEET_ARRAY,manager,tab,size); } ap_reducedproduct_t* ap_reducedproduct_join_array(ap_manager_t* manager, ap_reducedproduct_t** tab, size_t size) { return ap_reducedproduct_meetjoin_array(AP_FUNID_JOIN_ARRAY,manager,tab,size); } ap_reducedproduct_t* ap_reducedproduct_meet_lincons_array(ap_manager_t* manager, bool destructive, ap_reducedproduct_t* a, ap_lincons0_array_t* array) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_MEET_LINCONS_ARRAY,a); size_t i; ap_reducedproduct_t* res; res = destructive ? a : ap_reducedproduct_alloc(intern->size); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_MEET_LINCONS_ARRAY]; res->p[i] = ptr(man,destructive,a->p[i],array); bool (*is_bottom)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_BOTTOM]; if (is_bottom(man,res->p[i])){ set_bottom(intern,destructive,res,i); break; } } res->reduced = false; collect_results1(manager,AP_FUNID_MEET_LINCONS_ARRAY,res); return res; } ap_reducedproduct_t* ap_reducedproduct_meet_tcons_array(ap_manager_t* manager, bool destructive, ap_reducedproduct_t* a, ap_tcons0_array_t* array) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_MEET_TCONS_ARRAY,a); size_t i; ap_reducedproduct_t* res; res = destructive ? a : ap_reducedproduct_alloc(intern->size); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_MEET_TCONS_ARRAY]; res->p[i] = ptr(man,destructive,a->p[i],array); bool (*is_bottom)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_BOTTOM]; if (is_bottom(man,res->p[i])){ set_bottom(intern,destructive,res,i); break; } } res->reduced = false; collect_results1(manager,AP_FUNID_MEET_TCONS_ARRAY,res); return res; } ap_reducedproduct_t* ap_reducedproduct_add_ray_array(ap_manager_t* manager, bool destructive, ap_reducedproduct_t* a, ap_lincons0_array_t* array) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_ADD_RAY_ARRAY,a); size_t i; ap_reducedproduct_t* res; res = destructive ? a : ap_reducedproduct_alloc(intern->size); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_ADD_RAY_ARRAY]; res->p[i] = ptr(man,destructive,a->p[i],array); } res->reduced = a->reduced; collect_results1(manager,AP_FUNID_ADD_RAY_ARRAY,res); return res; } /* ============================================================ */ /* III.2 Assignment and Substitutions */ /* ============================================================ */ ap_reducedproduct_t* ap_reducedproduct_asssub_linexpr_array(ap_funid_t funid, /* either assign or substitute */ ap_manager_t* manager, bool destructive, ap_reducedproduct_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, ap_reducedproduct_t* dest) { ap_reducedproduct_internal_t* intern = get_internal_init2(manager,funid,a,dest); size_t i; ap_reducedproduct_t* res; res = destructive ? a : ap_reducedproduct_alloc(intern->size); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[funid]; res->p[i] = ptr(man,destructive,a->p[i],tdim,texpr,size, dest ? dest->p[i] : NULL); if (dest || funid==AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY){ bool (*is_bottom)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_BOTTOM]; if (is_bottom(man,res->p[i])){ set_bottom(intern,destructive,res,i); break; } } } res->reduced = false; collect_results1(manager,funid,res); return res; } ap_reducedproduct_t* ap_reducedproduct_assign_linexpr_array(ap_manager_t* man, bool destructive, ap_reducedproduct_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, ap_reducedproduct_t* dest) { return ap_reducedproduct_asssub_linexpr_array(AP_FUNID_ASSIGN_LINEXPR_ARRAY, man,destructive,a,tdim,texpr,size,dest); } ap_reducedproduct_t* ap_reducedproduct_substitute_linexpr_array(ap_manager_t* man, bool destructive, ap_reducedproduct_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, ap_reducedproduct_t* dest) { return ap_reducedproduct_asssub_linexpr_array(AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY, man,destructive,a,tdim,texpr,size,dest); } ap_reducedproduct_t* ap_reducedproduct_asssub_texpr_array(ap_funid_t funid, /* either assign or substitute */ ap_manager_t* manager, bool destructive, ap_reducedproduct_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, ap_reducedproduct_t* dest) { ap_reducedproduct_internal_t* intern = get_internal_init2(manager,funid,a,dest); size_t i; ap_reducedproduct_t* res; res = destructive ? a : ap_reducedproduct_alloc(intern->size); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[funid]; res->p[i] = ptr(man,destructive,a->p[i],tdim,texpr,size, dest ? dest->p[i] : NULL); if (dest || funid==AP_FUNID_SUBSTITUTE_TEXPR_ARRAY){ bool (*is_bottom)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_BOTTOM]; if (is_bottom(man,res->p[i])){ set_bottom(intern,destructive,res,i); break; } } } res->reduced = false; collect_results1(manager,funid,res); return res; } ap_reducedproduct_t* ap_reducedproduct_assign_texpr_array(ap_manager_t* man, bool destructive, ap_reducedproduct_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, ap_reducedproduct_t* dest) { return ap_reducedproduct_asssub_texpr_array(AP_FUNID_ASSIGN_TEXPR_ARRAY, man,destructive,a,tdim,texpr,size,dest); } ap_reducedproduct_t* ap_reducedproduct_substitute_texpr_array(ap_manager_t* man, bool destructive, ap_reducedproduct_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, ap_reducedproduct_t* dest) { return ap_reducedproduct_asssub_texpr_array(AP_FUNID_SUBSTITUTE_TEXPR_ARRAY, man,destructive,a,tdim,texpr,size,dest); } /* ============================================================ */ /* III.3 Projections */ /* ============================================================ */ ap_reducedproduct_t* ap_reducedproduct_forget_array(ap_manager_t* manager, bool destructive, ap_reducedproduct_t* a, ap_dim_t* tdim, size_t size, bool project) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_FORGET_ARRAY,a); size_t i; ap_reducedproduct_t* res; res = destructive ? a : ap_reducedproduct_alloc(intern->size); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_FORGET_ARRAY]; res->p[i] = ptr(man,destructive,a->p[i],tdim,size,project); } res->reduced = a->reduced; collect_results1(manager,AP_FUNID_FORGET_ARRAY,res); return res; } ap_reducedproduct_t* ap_reducedproduct_add_dimensions(ap_manager_t* manager, bool destructive, ap_reducedproduct_t* a, ap_dimchange_t* dimchange, bool project) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_ADD_DIMENSIONS,a); size_t i; ap_reducedproduct_t* res; res = destructive ? a : ap_reducedproduct_alloc(intern->size); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_ADD_DIMENSIONS]; res->p[i] = ptr(man,destructive,a->p[i],dimchange,project); } res->reduced = a->reduced; collect_results1(manager,AP_FUNID_ADD_DIMENSIONS,res); return res; } ap_reducedproduct_t* ap_reducedproduct_remove_dimensions(ap_manager_t* manager, bool destructive, ap_reducedproduct_t* a, ap_dimchange_t* dimchange) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_REMOVE_DIMENSIONS,a); size_t i; ap_reducedproduct_t* res; res = destructive ? a : ap_reducedproduct_alloc(intern->size); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_REMOVE_DIMENSIONS]; res->p[i] = ptr(man,destructive,a->p[i],dimchange); } res->reduced = false; collect_results1(manager,AP_FUNID_REMOVE_DIMENSIONS,res); return res; } ap_reducedproduct_t* ap_reducedproduct_permute_dimensions(ap_manager_t* manager, bool destructive, ap_reducedproduct_t* a, ap_dimperm_t* perm) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_PERMUTE_DIMENSIONS,a); size_t i; ap_reducedproduct_t* res; res = destructive ? a : ap_reducedproduct_alloc(intern->size); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_PERMUTE_DIMENSIONS]; res->p[i] = ptr(man,destructive,a->p[i],perm); } res->reduced = a->reduced; collect_results1(manager,AP_FUNID_PERMUTE_DIMENSIONS,res); return res; } /* ============================================================ */ /* III.5 Expansion and folding of dimensions */ /* ============================================================ */ ap_reducedproduct_t* ap_reducedproduct_expand(ap_manager_t* manager, bool destructive, ap_reducedproduct_t* a, ap_dim_t dim, size_t n) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_EXPAND,a); size_t i; ap_reducedproduct_t* res; res = destructive ? a : ap_reducedproduct_alloc(intern->size); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_EXPAND]; res->p[i] = ptr(man,destructive,a->p[i],dim,n); } res->reduced = a->reduced; collect_results1(manager,AP_FUNID_EXPAND,res); return res; } ap_reducedproduct_t* ap_reducedproduct_fold(ap_manager_t* manager, bool destructive, ap_reducedproduct_t* a, ap_dim_t* tdim, size_t size) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_FOLD,a); size_t i; ap_reducedproduct_t* res; res = destructive ? a : ap_reducedproduct_alloc(intern->size); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_FOLD]; res->p[i] = ptr(man,destructive,a->p[i],tdim,size); } res->reduced = false; collect_results1(manager,AP_FUNID_FOLD,res); return res; } /* ============================================================ */ /* III.6 Widening */ /* ============================================================ */ ap_reducedproduct_t* ap_reducedproduct_widening(ap_manager_t* manager, ap_reducedproduct_t* a1, ap_reducedproduct_t* a2) { ap_reducedproduct_internal_t* intern = get_internal_init2(manager,AP_FUNID_WIDENING,a1,a2); size_t i; ap_reducedproduct_t* res; res = ap_reducedproduct_alloc(intern->size); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_WIDENING]; res->p[i] = ptr(man,a1->p[i],a2->p[i]); } res->reduced = false; collect_results1(manager,AP_FUNID_WIDENING,res); return res; } /* ============================================================ */ /* III.7 Closure operation */ /* ============================================================ */ ap_reducedproduct_t* ap_reducedproduct_closure(ap_manager_t* manager, bool destructive, ap_reducedproduct_t* a) { ap_reducedproduct_internal_t* intern = get_internal_init1(manager,AP_FUNID_CLOSURE,a); size_t i; ap_reducedproduct_t* res; res = destructive ? a : ap_reducedproduct_alloc(intern->size); for (i=0;isize;i++){ ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_CLOSURE]; res->p[i] = ptr(man,destructive,a->p[i]); } res->reduced = false; collect_results1(manager,AP_FUNID_CLOSURE,res); return res; } /* ============================================================ */ /* IV. Allocating a manager */ /* ============================================================ */ void ap_reducedproduct_internal_free(void* p) { ap_reducedproduct_internal_t* intern = (ap_reducedproduct_internal_t*)p; size_t i; for (i=0;isize;i++){ ap_manager_free(intern->tmanagers[i]); intern->tmanagers[i] = NULL; } free(intern->version); free(intern); } ap_manager_t* ap_reducedproduct_manager_alloc ( char* library, ap_manager_t** tab, size_t size, void (*reduce)(ap_manager_t*, ap_reducedproduct_t*), /* reduce function */ void (*approximate)(ap_manager_t*, ap_reducedproduct_t*, int n) /* approximate function */ ) { char* version; size_t i,index, length; ap_reducedproduct_internal_t* internal; ap_manager_t* man; ap_funid_t funid; void** funptr; assert(size>=2); if (size<2) return NULL; /* Creating libray name and version */ length = 100 + 2 * size; for (i=0;iversion); version = malloc(length*sizeof(char)); index = sprintf(version,"%s, %s", tab[0]->version,tab[1]->version); for (i=2; iversion); } /* creating internal */ internal = malloc(sizeof(ap_reducedproduct_internal_t) + size * sizeof(ap_manager_t*)); internal->size = size; for (i=0; itmanagers[i] = ap_manager_copy(tab[i]); } internal->reduce = reduce; internal->approximate = approximate; internal->library = library; internal->version = strdup(version); free(version); /* allocating managers */ man = ap_manager_alloc(internal->library,internal->version, internal, &ap_reducedproduct_internal_free); /* default options */ for (funid=0; funidoption.funopt[funid].algorithm = 0x2; } man->option.funopt[AP_FUNID_COPY].algorithm = 0x1; man->option.funopt[AP_FUNID_FREE].algorithm = 0x0; man->option.funopt[AP_FUNID_ASIZE].algorithm = 0x0; man->option.funopt[AP_FUNID_COPY].algorithm = 0x1; man->option.funopt[AP_FUNID_MINIMIZE].algorithm = 0x1; man->option.funopt[AP_FUNID_IS_BOTTOM].algorithm = 0x1; man->option.funopt[AP_FUNID_IS_TOP].algorithm = 0x1; man->option.funopt[AP_FUNID_IS_LEQ].algorithm = 0x1; man->option.funopt[AP_FUNID_IS_EQ].algorithm = 0x1; man->option.funopt[AP_FUNID_SAT_LINCONS].algorithm = 0x1; man->option.funopt[AP_FUNID_SAT_TCONS].algorithm = 0x1; man->option.funopt[AP_FUNID_SAT_INTERVAL].algorithm = 0x1; man->option.funopt[AP_FUNID_IS_DIMENSION_UNCONSTRAINED].algorithm = 0x1; man->option.funopt[AP_FUNID_BOUND_LINEXPR].algorithm = 0x1; man->option.funopt[AP_FUNID_BOUND_TEXPR].algorithm = 0x1; man->option.funopt[AP_FUNID_BOUND_DIMENSION].algorithm = 0x1; man->option.funopt[AP_FUNID_TO_LINCONS_ARRAY].algorithm = 0x1; man->option.funopt[AP_FUNID_TO_TCONS_ARRAY].algorithm = 0x1; man->option.funopt[AP_FUNID_TO_BOX].algorithm = 0x1; man->option.funopt[AP_FUNID_TO_GENERATOR_ARRAY].algorithm = 0x1; man->option.funopt[AP_FUNID_JOIN].algorithm = 0x1; man->option.funopt[AP_FUNID_JOIN_ARRAY].algorithm = 0x1; man->option.funopt[AP_FUNID_ADD_RAY_ARRAY].algorithm = 0x1; man->option.funopt[AP_FUNID_FORGET_ARRAY].algorithm = 0x3; man->option.funopt[AP_FUNID_ADD_DIMENSIONS].algorithm = 0x0; man->option.funopt[AP_FUNID_PERMUTE_DIMENSIONS].algorithm = 0x0; man->option.funopt[AP_FUNID_EXPAND].algorithm = 0x1; man->option.funopt[AP_FUNID_WIDENING].algorithm = 0x0; man->option.funopt[AP_FUNID_CLOSURE].algorithm = 0x1; /* Virtual table */ funptr = man->funptr; funptr[AP_FUNID_COPY] = &ap_reducedproduct_copy; funptr[AP_FUNID_FREE] = &ap_reducedproduct_free; funptr[AP_FUNID_ASIZE] = &ap_reducedproduct_size; funptr[AP_FUNID_MINIMIZE] = &ap_reducedproduct_minimize; funptr[AP_FUNID_CANONICALIZE] = &ap_reducedproduct_canonicalize; funptr[AP_FUNID_HASH] = &ap_reducedproduct_hash; funptr[AP_FUNID_APPROXIMATE] = &ap_reducedproduct_approximate; funptr[AP_FUNID_FPRINT] = &ap_reducedproduct_fprint; funptr[AP_FUNID_FPRINTDIFF] = &ap_reducedproduct_fprintdiff; funptr[AP_FUNID_FDUMP] = &ap_reducedproduct_fdump; funptr[AP_FUNID_SERIALIZE_RAW] = &ap_reducedproduct_serialize_raw; funptr[AP_FUNID_DESERIALIZE_RAW] = &ap_reducedproduct_deserialize_raw; funptr[AP_FUNID_BOTTOM] = &ap_reducedproduct_bottom; funptr[AP_FUNID_TOP] = &ap_reducedproduct_top; funptr[AP_FUNID_OF_BOX] = &ap_reducedproduct_of_box; funptr[AP_FUNID_DIMENSION] = &ap_reducedproduct_dimension; funptr[AP_FUNID_IS_BOTTOM] = &ap_reducedproduct_is_bottom; funptr[AP_FUNID_IS_TOP] = &ap_reducedproduct_is_top; funptr[AP_FUNID_IS_LEQ] = &ap_reducedproduct_is_leq; funptr[AP_FUNID_IS_EQ] = &ap_reducedproduct_is_eq; funptr[AP_FUNID_IS_DIMENSION_UNCONSTRAINED] = &ap_reducedproduct_is_dimension_unconstrained; funptr[AP_FUNID_SAT_INTERVAL] = &ap_reducedproduct_sat_interval; funptr[AP_FUNID_SAT_LINCONS] = &ap_reducedproduct_sat_lincons; funptr[AP_FUNID_SAT_TCONS] = &ap_reducedproduct_sat_tcons; funptr[AP_FUNID_BOUND_DIMENSION] = &ap_reducedproduct_bound_dimension; funptr[AP_FUNID_BOUND_LINEXPR] = &ap_reducedproduct_bound_linexpr; funptr[AP_FUNID_BOUND_TEXPR] = &ap_reducedproduct_bound_texpr; funptr[AP_FUNID_TO_BOX] = &ap_reducedproduct_to_box; funptr[AP_FUNID_TO_LINCONS_ARRAY] = &ap_reducedproduct_to_lincons_array; funptr[AP_FUNID_TO_TCONS_ARRAY] = &ap_reducedproduct_to_tcons_array; funptr[AP_FUNID_TO_GENERATOR_ARRAY] = &ap_reducedproduct_to_generator_array; funptr[AP_FUNID_MEET] = &ap_reducedproduct_meet; funptr[AP_FUNID_MEET_ARRAY] = &ap_reducedproduct_meet_array; funptr[AP_FUNID_MEET_LINCONS_ARRAY] = &ap_reducedproduct_meet_lincons_array; funptr[AP_FUNID_MEET_TCONS_ARRAY] = &ap_reducedproduct_meet_tcons_array; funptr[AP_FUNID_JOIN] = &ap_reducedproduct_join; funptr[AP_FUNID_JOIN_ARRAY] = &ap_reducedproduct_join_array; funptr[AP_FUNID_ADD_RAY_ARRAY] = &ap_reducedproduct_add_ray_array; funptr[AP_FUNID_ASSIGN_LINEXPR_ARRAY] = &ap_reducedproduct_assign_linexpr_array; funptr[AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY] = &ap_reducedproduct_substitute_linexpr_array; funptr[AP_FUNID_ASSIGN_TEXPR_ARRAY] = &ap_reducedproduct_assign_texpr_array; funptr[AP_FUNID_SUBSTITUTE_TEXPR_ARRAY] = &ap_reducedproduct_substitute_texpr_array; funptr[AP_FUNID_ADD_DIMENSIONS] = &ap_reducedproduct_add_dimensions; funptr[AP_FUNID_REMOVE_DIMENSIONS] = &ap_reducedproduct_remove_dimensions; funptr[AP_FUNID_PERMUTE_DIMENSIONS] = &ap_reducedproduct_permute_dimensions; funptr[AP_FUNID_FORGET_ARRAY] = &ap_reducedproduct_forget_array; funptr[AP_FUNID_EXPAND] = &ap_reducedproduct_expand; funptr[AP_FUNID_FOLD] = &ap_reducedproduct_fold; funptr[AP_FUNID_WIDENING] = &ap_reducedproduct_widening; funptr[AP_FUNID_CLOSURE] = &ap_reducedproduct_closure; return man; } /* ============================================================ */ /* V. Extra functions */ /* ============================================================ */ void** ap_reducedproduct_decompose(ap_manager_t* manager, bool destructive, ap_reducedproduct_t* a) { ap_reducedproduct_internal_t* intern = get_internal_init0(manager); size_t i; void** res = (void**)malloc(intern->size*sizeof(void*)); for (i=0;isize;i++){ if (destructive){ res[i] = a->p[i]; } else { ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_COPY]; res[i] = ptr(man,a->p[i]); } } if (destructive) free(a); collect_results0(manager); return res; } ap_reducedproduct_t* ap_reducedproduct_compose(ap_manager_t* manager, bool destructive, void** tabs) { ap_reducedproduct_internal_t* intern = get_internal_init0(manager); ap_reducedproduct_t* res = ap_reducedproduct_alloc(intern->size); size_t i; for (i=0;isize;i++){ if (destructive){ res->p[i] = tabs[i]; } else { ap_manager_t* man = intern->tmanagers[i]; void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_COPY]; res->p[i] = ptr(man,tabs[i]); } } collect_results0(manager); return res; } apron-dist-0.9.10/apron/apron/ap_generic.c0000640014525101416610000004154610723557216020265 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_generic: generic functions for library implementors */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "ap_generic.h" #include "ap_scalar.h" /* These functions are dedicated to implementors of domains. They offer generic default implementations for some of the operations required by the APRON API, when there is no more specific and efficient implementation for the domain being implemented. To use them, the function allocating manager, which is specific to the domain, should put the corresponding pointers in the virtual table to them. They manipulated "unboxed" abstract values, which are native to the underlying library: they are not yet boxed with the manager in the type ap_abstract0_t. */ /* ********************************************************************** */ /* I. Constructors */ /* ********************************************************************** */ bool ap_generic_sat_tcons(ap_manager_t* man, void* abs, ap_tcons0_t* cons, ap_scalar_discr_t discr, bool quasilinearize) { bool (*is_bottom)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_BOTTOM]; bool (*sat_lincons)(ap_manager_t*,...) = man->funptr[AP_FUNID_SAT_LINCONS]; bool exact; ap_lincons0_t lincons0; bool res; ap_abstract0_t a0; if (is_bottom(man,abs)){ man->result.flag_exact = man->result.flag_best = true; return true; } a0.value = abs; a0.man = man; lincons0 = ap_intlinearize_tcons0(man,&a0,cons,&exact,discr,quasilinearize,false); res = sat_lincons(man,abs,&lincons0); ap_lincons0_clear(&lincons0); if (!exact){ man->result.flag_exact = man->result.flag_best = false; } return res; } /* This function implements a generic bound_texpr operation using linearisation and bound_linexpr */ ap_interval_t* ap_generic_bound_texpr(ap_manager_t* man, void* abs, ap_texpr0_t* expr, ap_scalar_discr_t discr, bool quasilinearize) { bool (*is_bottom)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_BOTTOM]; ap_interval_t* (*bound_linexpr)(ap_manager_t*,...) = man->funptr[AP_FUNID_BOUND_LINEXPR]; bool exact; ap_linexpr0_t* linexpr0; ap_interval_t* res; ap_abstract0_t a0; if (is_bottom(man,abs)){ res = ap_interval_alloc(); ap_interval_set_bottom(res); return res; } a0.value = abs; a0.man = man; linexpr0 = ap_intlinearize_texpr0(man,&a0,expr,&exact,discr,quasilinearize); res = bound_linexpr(man,abs,linexpr0); ap_linexpr0_free(linexpr0); if (!exact){ man->result.flag_exact = man->result.flag_best = false; } return res; } ap_tcons0_array_t ap_generic_to_tcons_array(ap_manager_t* man, void* abs) { ap_lincons0_array_t (*to_lincons_array)(ap_manager_t*,...) = man->funptr[AP_FUNID_TO_LINCONS_ARRAY]; ap_lincons0_array_t array = to_lincons_array(man,abs); ap_tcons0_array_t res = ap_tcons0_array_make(array.size); size_t i; for (i=0; ifunptr[AP_FUNID_COPY]; void* (*meetjoin)(ap_manager_t*,...) = man->funptr[meet ? AP_FUNID_MEET : AP_FUNID_JOIN]; size_t i; void* res; bool exact,best; if (size==1){ return copy(man,tab[0]); } else { res = meetjoin(man,false,tab[0],tab[1]); exact = man->result.flag_exact; best = man->result.flag_best; for (i=2; iresult.flag_exact; best = best && man->result.flag_best; } man->result.flag_exact = exact; man->result.flag_best = best; return res; } } /* ============================================================ */ /* Meet with array of constraints */ /* ============================================================ */ void* ap_generic_meet_quasilinearize_lincons_array(ap_manager_t* man, bool destructive, void* abs, ap_lincons0_array_t* array, ap_scalar_discr_t discr, bool linearize, void* (*meet_lincons_array)(ap_manager_t*, bool, void*, ap_lincons0_array_t*)) { bool exact; ap_lincons0_array_t array2; void* res; void* (*copy)(ap_manager_t*,...) = man->funptr[AP_FUNID_COPY]; bool (*is_bottom)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_BOTTOM]; man->result.flag_exact = man->result.flag_best = true; if (is_bottom(man,abs) || array->size==0){ res = destructive ? abs : copy(abs); } else { array2 = ap_quasilinearize_lincons0_array(man,abs,array,&exact, discr,linearize,true); res = meet_lincons_array(man,destructive,abs,&array2); if (!exact){ man->result.flag_exact = man->result.flag_best = false; } if (array2.p!=array->p){ ap_lincons0_array_clear(&array2); } } return res; } void* ap_generic_meet_intlinearize_tcons_array(ap_manager_t* man, bool destructive, void* abs, ap_tcons0_array_t* array, ap_scalar_discr_t discr, ap_linexpr_type_t linearize, void* (*meet_lincons_array)(ap_manager_t*, bool, void*, ap_lincons0_array_t*)) { bool exact; ap_lincons0_array_t array2; void* res; void* (*copy)(ap_manager_t*,...) = man->funptr[AP_FUNID_COPY]; bool (*is_bottom)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_BOTTOM]; ap_abstract0_t a0; man->result.flag_exact = man->result.flag_best = true; if (is_bottom(man,abs) || array->size==0){ res = destructive ? abs : copy(man,abs); } else { a0.value = abs; a0.man = man; array2 = ap_intlinearize_tcons0_array(man,&a0,array,&exact,discr,linearize,true,true,2,false); res = meet_lincons_array(man,destructive,abs,&array2); if (!exact){ man->result.flag_exact = man->result.flag_best = false; } ap_lincons0_array_clear(&array2); } return res; } /* ============================================================ */ /* Assignments/Substitutions */ /* ============================================================ */ /* This function implements generic parallel assignment/substitution operations by: 1. introducing primed dimensions 2. transforming linear expressions into equality constraints relating the assigned primed dimension and the linear expression If dest!=NULL 3. introducing primed dimensions in dest 4. exchanging primed and unprimed dimensions in dest 5. intersecting the abstract value with the modified dest 6. intersecting the obtained abstract value with the constraints 7. exchanging primed and unprimed dimensions 8. removing the introduced (primed) dimensions It relies on: is_bottom, copy, dimension, add_dimensions, permute_dimensions, remove_dimensions, meet_lincons_array, meet and free abstract operations. Meaning of parameters: - assign selects the operation: true means assignment, false substitution - The other parameters have the meaning they have for parallel assignment/substitution */ void* ap_generic_asssub_linexpr_array(bool assign, ap_manager_t* man, bool destructive, void* abs, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, void* dest) { bool (*is_bottom)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_BOTTOM]; void* (*copy)(ap_manager_t*,...) = man->funptr[AP_FUNID_COPY]; void* (*add_dimensions)(ap_manager_t*,...) = man->funptr[AP_FUNID_ADD_DIMENSIONS]; void* (*permute_dimensions)(ap_manager_t*,...) = man->funptr[AP_FUNID_PERMUTE_DIMENSIONS]; void* (*remove_dimensions)(ap_manager_t*,...) = man->funptr[AP_FUNID_REMOVE_DIMENSIONS]; void* (*meet_lincons_array)(ap_manager_t*,...) = man->funptr[AP_FUNID_MEET_LINCONS_ARRAY]; void* (*meet)(ap_manager_t*,...) = man->funptr[AP_FUNID_MEET]; void (*ap_free)(ap_manager_t*,...) = man->funptr[AP_FUNID_FREE]; ap_dimension_t (*dimension)(ap_manager_t*,...) = man->funptr[AP_FUNID_DIMENSION]; size_t i; ap_dimension_t d, dsup; ap_dimchange_t dimchange; ap_dimperm_t permutation; ap_lincons0_array_t array; void* abs2; bool exact,best; if (is_bottom(man,abs)){ man->result.flag_exact = man->result.flag_best = true; return destructive ? abs : copy(man,abs); } /* 1. Compute the number of integer and real dimensions assigned */ d = dimension(man,abs); dsup.intdim = 0; dsup.realdim = 0; for (i=0; iresult.flag_exact; best = man->result.flag_best; /* From now, work by side-effect on abs2 */ /* 5. Build constraints system An assignment x'_i := a_ij x_j + b_i becomes an equality constraint -x'_i + a_ij x_j + b_i = 0 Primed and unprimed dimensiosn permuted if dest!=NULL */ array = ap_lincons0_array_make(size); for (i=0; iresult.flag_exact; best = best && man->result.flag_best; } /* 7. If dest!=NULL, perform intersection */ if (dest!=NULL){ void* dest2 = add_dimensions(man,false,dest,&dimchange,false); exact = exact && man->result.flag_exact; best = best && man->result.flag_best; if (assign){ dest2 = permute_dimensions(man,true,dest2,&permutation); exact = exact && man->result.flag_exact; best = best && man->result.flag_best; } abs2 = meet(man,true,abs2,dest2); exact = exact && man->result.flag_exact; best = best && man->result.flag_best; ap_free(man,dest2); } /* 8. Perform meet of abs2 with constraints */ abs2 = meet_lincons_array(man,true,abs2,&array); exact = exact && man->result.flag_exact; best = best && man->result.flag_best; /* 9. Permute unprimed and primed dimensions if assign */ if (assign){ abs2 = permute_dimensions(man,true,abs2,&permutation); exact = exact && man->result.flag_exact; best = best && man->result.flag_best; } /* 10. Remove extra dimensions */ ap_dimchange_add_invert(&dimchange); abs2 = remove_dimensions(man,true,abs2,&dimchange); exact = exact && man->result.flag_exact; best = best && man->result.flag_best; /* 11. Free allocated objects */ ap_dimperm_clear(&permutation); ap_dimchange_clear(&dimchange); ap_lincons0_array_clear(&array); man->result.flag_exact = exact; man->result.flag_best = best; return abs2; } void* ap_generic_asssub_texpr_array(bool assign, ap_manager_t* man, bool destructive, void* abs, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, void* dest) { bool (*is_bottom)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_BOTTOM]; void* (*copy)(ap_manager_t*,...) = man->funptr[AP_FUNID_COPY]; void* (*add_dimensions)(ap_manager_t*,...) = man->funptr[AP_FUNID_ADD_DIMENSIONS]; void* (*permute_dimensions)(ap_manager_t*,...) = man->funptr[AP_FUNID_PERMUTE_DIMENSIONS]; void* (*remove_dimensions)(ap_manager_t*,...) = man->funptr[AP_FUNID_REMOVE_DIMENSIONS]; void* (*meet_tcons_array)(ap_manager_t*,...) = man->funptr[AP_FUNID_MEET_TCONS_ARRAY]; void* (*meet)(ap_manager_t*,...) = man->funptr[AP_FUNID_MEET]; void (*ap_free)(ap_manager_t*,...) = man->funptr[AP_FUNID_FREE]; ap_dimension_t (*dimension)(ap_manager_t*,...) = man->funptr[AP_FUNID_DIMENSION]; size_t i; ap_dimension_t d, dsup; ap_dimchange_t dimchange; ap_dimperm_t permutation; ap_tcons0_array_t array; void* abs2; bool exact,best; if (is_bottom(man,abs)){ man->result.flag_exact = man->result.flag_best = true; return destructive ? abs : copy(man,abs); } /* 1. Compute the number of integer and real dimensions assigned */ d = dimension(man,abs); dsup.intdim = 0; dsup.realdim = 0; for (i=0; iresult.flag_exact; best = man->result.flag_best; /* From now, work by side-effect on abs2 */ /* 5. Build constraints system An assignment x'_i := a_ij x_j + b_i becomes an equality constraint -x'_i + a_ij x_j + b_i = 0 */ array = ap_tcons0_array_make(size); for (i=0; iresult.flag_exact; best = best && man->result.flag_best; } /* 7. If dest!=NULL, perform intersection */ if (dest!=NULL){ void* dest2 = add_dimensions(man,false,dest,&dimchange,false); exact = exact && man->result.flag_exact; best = best && man->result.flag_best; if (assign){ dest2 = permute_dimensions(man,true,dest2,&permutation); exact = exact && man->result.flag_exact; best = best && man->result.flag_best; } abs2 = meet(man,true,abs2,dest2); exact = exact && man->result.flag_exact; best = best && man->result.flag_best; ap_free(man,dest2); } /* 8. Perform meet of abs2 with constraints */ abs2 = meet_tcons_array(man,true,abs2,&array); exact = exact && man->result.flag_exact; best = best && man->result.flag_best; /* 9. Permute unprimed and primed dimensions if assign */ if (assign){ abs2 = permute_dimensions(man,true,abs2,&permutation); exact = exact && man->result.flag_exact; best = best && man->result.flag_best; } /* 10. Remove extra dimensions */ ap_dimchange_add_invert(&dimchange); abs2 = remove_dimensions(man,true,abs2,&dimchange); exact = exact && man->result.flag_exact; best = best && man->result.flag_best; /* 11. Free allocated objects */ ap_dimperm_clear(&permutation); ap_dimchange_clear(&dimchange); ap_tcons0_array_clear(&array); man->result.flag_exact = exact; man->result.flag_best = best; return abs2; } apron-dist-0.9.10/apron/apron/ap_lincons0.h0000640014525101416610000001572710676403632020404 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_lincons0.h: linear constraints and arrays */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ /* normally included from ap_expr0.h */ #ifndef _AP_LINCONS0_H_ #define _AP_LINCONS0_H_ #include #include #include #include "ap_coeff.h" #include "ap_linexpr0.h" #ifdef __cplusplus extern "C" { #endif /* ====================================================================== */ /* Datatypes */ /* ====================================================================== */ /* Datatype for type of constraints */ typedef enum ap_constyp_t { AP_CONS_EQ, /* equality constraint */ AP_CONS_SUPEQ, /* >= constraint */ AP_CONS_SUP, /* > constraint */ AP_CONS_EQMOD, /* congruence equality constraint */ AP_CONS_DISEQ /* disequality constraint */ } ap_constyp_t; /* Represents the constraint "expr constyp 0" */ typedef struct ap_lincons0_t { ap_linexpr0_t* linexpr0; /* expression */ ap_constyp_t constyp; /* type of constraint */ ap_scalar_t* scalar; /* maybe NULL. For EQMOD constraint, indicates the modulo */ } ap_lincons0_t; /* Array of constraints */ typedef struct ap_lincons0_array_t { ap_lincons0_t* p; size_t size; } ap_lincons0_array_t; /* ********************************************************************** */ /* I. ap_lincons0_t */ /* ********************************************************************** */ /* ====================================================================== */ /* I.1 Memory management and printing */ /* ====================================================================== */ static inline ap_lincons0_t ap_lincons0_make(ap_constyp_t constyp, ap_linexpr0_t* linexpr, ap_scalar_t* scalar); /* Create a constraint of given type with the given expression. The expression and the coefficient are not duplicated, just pointed to */ ap_lincons0_t ap_lincons0_make_unsat(void); /* Create the constraint -1>=0 */ static inline ap_lincons0_t ap_lincons0_copy(ap_lincons0_t* cons); /* Duplication */ static inline void ap_lincons0_clear(ap_lincons0_t* cons); /* Free the linear expression of the constraint and set pointer to NULL */ void ap_lincons0_fprint(FILE* stream, ap_lincons0_t* cons, char** name_of_dim); /* Printing a linear constraint */ /* ====================================================================== */ /* I.2 Tests */ /* ====================================================================== */ bool ap_lincons0_is_unsat(ap_lincons0_t* cons); /* True if the constraint is b>=0 or [a,b]>=0 with b negative */ /* ====================================================================== */ /* I.3 Change of dimensions and permutations */ /* ====================================================================== */ static inline void ap_lincons0_add_dimensions_with(ap_lincons0_t* cons, ap_dimchange_t* dimchange); static inline ap_lincons0_t ap_lincons0_add_dimensions(ap_lincons0_t* cons, ap_dimchange_t* dimchange); static inline void ap_lincons0_permute_dimensions_with(ap_lincons0_t* cons, ap_dimperm_t* perm); static inline ap_lincons0_t ap_lincons0_permute_dimensions(ap_lincons0_t* cons, ap_dimperm_t* perm); /* ********************************************************************** */ /* II. Array of linear constraints */ /* ********************************************************************** */ ap_lincons0_array_t ap_lincons0_array_make(size_t size); /* Allocate an array of size constraints. The constraints are initialized with NULL pointers, */ void ap_lincons0_array_resize(ap_lincons0_array_t* array, size_t size); /* Resize an array of size constraints. New constraints are initialized with NULL pointers, Removed constraints with non-NULL pointers are deallocated */ void ap_lincons0_array_clear(ap_lincons0_array_t* array); /* Clear the constraints of the array, and then the array itself */ void ap_lincons0_array_fprint(FILE* stream, ap_lincons0_array_t* ap_lincons0_array, char** name_of_dim); /* Printing */ ap_linexpr_type_t ap_lincons0_array_type(ap_lincons0_array_t* array); bool ap_lincons0_array_is_linear(ap_lincons0_array_t* array); bool ap_lincons0_array_is_quasilinear(ap_lincons0_array_t* array); /* Are all the expressions involved linear (resp. quasilinear) */ /* ====================================================================== */ /* II.1 Change of dimensions and permutations */ /* ====================================================================== */ void ap_lincons0_array_add_dimensions_with(ap_lincons0_array_t* array, ap_dimchange_t* dimchange); ap_lincons0_array_t ap_lincons0_array_add_dimensions(ap_lincons0_array_t* array, ap_dimchange_t* dimchange); void ap_lincons0_array_permute_dimensions_with(ap_lincons0_array_t* array, ap_dimperm_t* perm); ap_lincons0_array_t ap_lincons0_array_permute_dimensions(ap_lincons0_array_t* array, ap_dimperm_t* perm); /* ********************************************************************** */ /* III. Inline functions definitions */ /* ********************************************************************** */ static inline ap_lincons0_t ap_lincons0_make(ap_constyp_t constyp, ap_linexpr0_t* linexpr, ap_scalar_t* scalar) { ap_lincons0_t cons; cons.constyp = constyp; cons.linexpr0 = linexpr; cons.scalar = scalar; return cons; } static inline ap_lincons0_t ap_lincons0_copy(ap_lincons0_t* cons) { return ap_lincons0_make(cons->constyp, cons->linexpr0 ? ap_linexpr0_copy(cons->linexpr0) : NULL, cons->scalar ? ap_scalar_alloc_set(cons->scalar) : NULL); } static inline void ap_lincons0_clear(ap_lincons0_t* lincons) { if (lincons->linexpr0){ ap_linexpr0_free(lincons->linexpr0); } lincons->linexpr0 = NULL; if (lincons->scalar){ ap_scalar_free(lincons->scalar); } lincons->scalar = NULL; } static inline void ap_lincons0_add_dimensions_with(ap_lincons0_t* cons, ap_dimchange_t* dimchange) { ap_linexpr0_add_dimensions_with(cons->linexpr0,dimchange); } static inline ap_lincons0_t ap_lincons0_add_dimensions(ap_lincons0_t* cons, ap_dimchange_t* dimchange) { return ap_lincons0_make(cons->constyp, ap_linexpr0_add_dimensions(cons->linexpr0,dimchange), cons->scalar ? ap_scalar_alloc_set(cons->scalar) : NULL); } static inline void ap_lincons0_permute_dimensions_with(ap_lincons0_t* cons, ap_dimperm_t* perm) { ap_linexpr0_permute_dimensions_with(cons->linexpr0,perm); } static inline ap_lincons0_t ap_lincons0_permute_dimensions(ap_lincons0_t* cons, ap_dimperm_t* perm) { return ap_lincons0_make(cons->constyp, ap_linexpr0_permute_dimensions(cons->linexpr0,perm), cons->scalar ? ap_scalar_alloc_set(cons->scalar) : NULL); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/ap_manager.h0000640014525101416610000002244210760562320020253 0ustar bjeannetpopart/* ************************************************************************* */ /* manager.h: global manager passed to all functions */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _AP_MANAGER_H_ #define _AP_MANAGER_H_ #include #include #include "ap_coeff.h" #ifdef __cplusplus extern "C" { #endif /* ********************************************************************** */ /* I. Types */ /* ********************************************************************** */ /* ====================================================================== */ /* I.O General usage */ /* ====================================================================== */ /* Boolean with a third value */ typedef enum tbool_t { tbool_false=0, tbool_true=1, tbool_top=2, /* don't know */ } tbool_t; static inline tbool_t tbool_of_bool(bool a); static inline tbool_t tbool_of_int(int n); static inline tbool_t tbool_or(tbool_t a, tbool_t b); static inline tbool_t tbool_and(tbool_t a, tbool_t b); static inline tbool_t tbool_not(tbool_t a); /* For serialization */ typedef struct ap_membuf_t { void* ptr; size_t size; } ap_membuf_t; /* ====================================================================== */ /* I.1 Identifying functions */ /* ====================================================================== */ typedef enum ap_funid_t { AP_FUNID_UNKNOWN, AP_FUNID_COPY, AP_FUNID_FREE, AP_FUNID_ASIZE, /* For avoiding name conflict with AP_FUNID_SIZE */ AP_FUNID_MINIMIZE, AP_FUNID_CANONICALIZE, AP_FUNID_HASH, AP_FUNID_APPROXIMATE, AP_FUNID_FPRINT, AP_FUNID_FPRINTDIFF, AP_FUNID_FDUMP, AP_FUNID_SERIALIZE_RAW, AP_FUNID_DESERIALIZE_RAW, AP_FUNID_BOTTOM, AP_FUNID_TOP, AP_FUNID_OF_BOX, AP_FUNID_DIMENSION, AP_FUNID_IS_BOTTOM, AP_FUNID_IS_TOP, AP_FUNID_IS_LEQ, AP_FUNID_IS_EQ, AP_FUNID_IS_DIMENSION_UNCONSTRAINED, AP_FUNID_SAT_INTERVAL, AP_FUNID_SAT_LINCONS, AP_FUNID_SAT_TCONS, AP_FUNID_BOUND_DIMENSION, AP_FUNID_BOUND_LINEXPR, AP_FUNID_BOUND_TEXPR, AP_FUNID_TO_BOX, AP_FUNID_TO_LINCONS_ARRAY, AP_FUNID_TO_TCONS_ARRAY, AP_FUNID_TO_GENERATOR_ARRAY, AP_FUNID_MEET, AP_FUNID_MEET_ARRAY, AP_FUNID_MEET_LINCONS_ARRAY, AP_FUNID_MEET_TCONS_ARRAY, AP_FUNID_JOIN, AP_FUNID_JOIN_ARRAY, AP_FUNID_ADD_RAY_ARRAY, AP_FUNID_ASSIGN_LINEXPR_ARRAY, AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY, AP_FUNID_ASSIGN_TEXPR_ARRAY, AP_FUNID_SUBSTITUTE_TEXPR_ARRAY, AP_FUNID_ADD_DIMENSIONS, AP_FUNID_REMOVE_DIMENSIONS, AP_FUNID_PERMUTE_DIMENSIONS, AP_FUNID_FORGET_ARRAY, AP_FUNID_EXPAND, AP_FUNID_FOLD, AP_FUNID_WIDENING, AP_FUNID_CLOSURE, AP_FUNID_SIZE, AP_FUNID_CHANGE_ENVIRONMENT, AP_FUNID_RENAME_ARRAY, AP_FUNID_SIZE2 } ap_funid_t; extern const char* ap_name_of_funid[AP_FUNID_SIZE2]; /* give the name of a function identifier */ /* ====================================================================== */ /* I.2 Exceptions */ /* ====================================================================== */ /* Exceptions (public type) */ typedef enum ap_exc_t { AP_EXC_NONE, /* no exception detected */ AP_EXC_TIMEOUT, /* timeout detected */ AP_EXC_OUT_OF_SPACE, /* out of space detected */ AP_EXC_OVERFLOW, /* magnitude overflow detected */ AP_EXC_INVALID_ARGUMENT, /* invalid arguments */ AP_EXC_NOT_IMPLEMENTED, /* not implemented */ AP_EXC_SIZE } ap_exc_t; extern const char* ap_name_of_exception[AP_EXC_SIZE]; /* Exception log */ typedef struct ap_exclog_t { ap_exc_t exn; ap_funid_t funid; char* msg; /* dynamically allocated */ struct ap_exclog_t* tail; } ap_exclog_t; /* Exceptions and other indications (out) (opaque type) */ typedef struct ap_result_t { ap_exclog_t* exclog; /* history of exceptions */ ap_exc_t exn; /* exception for the last called function */ bool flag_exact; /* result is mathematically exact or don't know */ bool flag_best; /* result is best correct approximation or don't know */ } ap_result_t; /* ====================================================================== */ /* I.2 Options */ /* ====================================================================== */ /* Option associated to each function (public type) */ typedef struct ap_funopt_t { int algorithm; /* Algorithm selection: - 0 is default algorithm; - MAX_INT is most accurate available; - MIN_INT is most efficient available; - otherwise, no accuracy or speed meaning */ size_t timeout; /* unit !? */ /* Above the given computation time, the function may abort with the exception flag flag_time_out on. */ size_t max_object_size; /* in abstract object size unit. */ /* If during the computation, the size of some object reach this limit, the function may abort with the exception flag flag_out_of_space on. */ bool flag_exact_wanted; /* return information about exactitude if possible */ bool flag_best_wanted; /* return information about best correct approximation if possible */ } ap_funopt_t; /* Options (in) (opaque type) */ typedef struct ap_option_t { ap_funopt_t funopt[AP_FUNID_SIZE]; bool abort_if_exception[AP_EXC_SIZE]; ap_scalar_discr_t scalar_discr; /* Preferred type for scalars */ } ap_option_t; /* ====================================================================== */ /* I.3 Manager */ /* ====================================================================== */ /* Manager (opaque type) */ typedef struct ap_manager_t { char* library; /* name of the effective library */ char* version; /* version of the effective library */ void* internal; /* library dependent, should be different for each thread (working space) */ void* funptr[AP_FUNID_SIZE]; /* Array of function pointers, initialized by the effective library */ ap_option_t option; /* Options (in) */ ap_result_t result; /* Exceptions and other indications (out) */ void (*internal_free)(void*); /* deallocation function for internal */ size_t count; /* reference counter */ } ap_manager_t; /* ********************************************************************** */ /* II. User Functions */ /* ********************************************************************** */ void ap_manager_clear_exclog(ap_manager_t* man); /* erase the current log of exception */ void ap_manager_free(ap_manager_t* man); /* dereference the counter, and possibly free internal field if it is not yet put to NULL */ /* Reading fields */ const char* ap_manager_get_library(ap_manager_t* man); const char* ap_manager_get_version(ap_manager_t* man); ap_funopt_t ap_manager_get_funopt(ap_manager_t* man, ap_funid_t funid); bool ap_manager_get_abort_if_exception(ap_manager_t* man, ap_exc_t exn); ap_exc_t ap_manager_get_exception(ap_manager_t* man); /* Get the last exception raised */ ap_exclog_t* ap_manager_get_exclog(ap_manager_t* man); /* Get the full log of exception */ bool ap_manager_get_flag_exact(ap_manager_t* man); bool ap_manager_get_flag_best(ap_manager_t* man); /* Settings fields */ void ap_funopt_init(ap_funopt_t* fopt); void ap_manager_set_funopt(ap_manager_t* man, ap_funid_t funid, ap_funopt_t* funopt); void ap_manager_set_abort_if_exception(ap_manager_t* man, ap_exc_t exn, bool flag); bool ap_fpu_init(void); /* tries to set the FPU rounding-mode towards +oo, returns true if successful */ /* ********************************************************************** */ /* III. Implementor Functions */ /* ********************************************************************** */ ap_manager_t* ap_manager_alloc(char* library, char* version, void* internal, void (*internal_free)(void*)); static inline ap_manager_t* ap_manager_copy(ap_manager_t* man); /* Increment the reference counter and return its argument */ void ap_manager_raise_exception(ap_manager_t* man, ap_exc_t exn, ap_funid_t funid, const char* msg); /* raise an exception and put fields man->result.flag_exact and man->result.flag_best to false */ ap_exclog_t* ap_exc_cons(ap_exc_t exn, ap_funid_t funid, const char* msg, ap_exclog_t* tail); void ap_exclog_free(ap_exclog_t* head); /* ********************************************************************** */ /* IV. Definition of previously declared inline functions */ /* ********************************************************************** */ static inline tbool_t tbool_of_int(int n) { return ((n) ? tbool_true : tbool_false); } static inline tbool_t tbool_of_bool(bool a) { return ((a) ? tbool_true : tbool_false); } static inline tbool_t tbool_or(tbool_t a, tbool_t b) { return ( (a==tbool_true || b==tbool_true) ? tbool_true : ( (a==tbool_top || b==tbool_top) ? tbool_top : tbool_false ) ); } static inline tbool_t tbool_and(tbool_t a, tbool_t b) { return ( (a==tbool_false || b==tbool_false) ? tbool_false : ( (a==tbool_top || b==tbool_top) ? tbool_top : tbool_true ) ); } static inline tbool_t tbool_not(tbool_t a) { return a==tbool_false ? tbool_true : a==tbool_true ? tbool_false : a; } static inline ap_manager_t* ap_manager_copy(ap_manager_t* man) { man->count++; return man; } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/COPYING0000640014525101416610000006402110437621734017050 0ustar bjeannetpopart This license applies to all files distributed in the APRON library, including all source code, libraries, binaries, and documentation. Copyright (C) Bertrand Jeannet 2005-2006 for the apron subpackage. GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! apron-dist-0.9.10/apron/apron/ap_dimension.h0000640014525101416610000001666411225402502020627 0ustar bjeannetpopart/* ********************************************************************** */ /* ap_dimension.h: dimensions and related operations */ /* ********************************************************************** */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _AP_DIMENSION_H_ #define _AP_DIMENSION_H_ #include #include #ifdef __cplusplus extern "C" { #endif /* ====================================================================== */ /* Datatypes */ /* ====================================================================== */ /* Datatype for dimensions */ typedef unsigned int ap_dim_t; #define AP_DIM_MAX UINT_MAX /* Used for sparse representations (mean: to be ignored) and also as a result when an error occurred */ /* Datatype for specifying the dimensionality of an abstract value */ typedef struct ap_dimension_t { size_t intdim; size_t realdim; } ap_dimension_t; /* Datatype for specifying change of dimension (addition or removal) */ typedef struct ap_dimchange_t { ap_dim_t* dim; /* Assumed to be an array of size intdim+realdim */ size_t intdim ; /* Number of integer dimensions to add/remove */ size_t realdim; /* Number of real dimensions to add/remove */ } ap_dimchange_t; /* The semantics is the following: - Addition of dimensions: dimchange.dim[i]=k means: add one dimension at dimension k and shift the already existing dimensions greater than or equal to k one step on the right (or increment them). if k is equal to the size of the vector, then it means: add a dimension at the end. Repetition are allowed, and means that one inserts more than one dimensions. Example: linexpr0_add_dimensions([i0 i1 r0 r1], { [0 1 2 2 4],3,1 }) returns [0 i0 0 i1 0 0 r0 r1 0], considered as a vector with 6 integer dimensions and 3 real dimensions. - Removal of dimensions dimchange.dim[i]=k means: remove the dimension k and shift the dimensions greater than k one step on the left (or decrement them). Repetitions are meaningless (and are not correct specification) Example: linexpr0_remove_dimensions([i0 i1 i2 r0 r1 r2], { [0 2 4],2,1 }) returns [i1 r0 r2], considered as a vector with 1 integer dimensions and 2 real dimensions. */ /* Datatype for specifying double changes of dimensions (combination of addition and then removal). Used by level 1 function change_environment. */ typedef struct ap_dimchange2_t { ap_dimchange_t* add; /* If not NULL, specifies the adding new dimensions */ ap_dimchange_t* remove; /* If not NULL, specifies the removal of dimensions */ } ap_dimchange2_t; /* Datatype for permutations */ typedef struct ap_dimperm_t { ap_dim_t* dim; /* Array assumed to be of size size */ size_t size; } ap_dimperm_t; /* Such an object represent the permutation i -> dimperm.p[i] for 0<=i perm->dim[0] 1 -> perm->dim[1] ... */ void ap_dimperm_set_id(ap_dimperm_t* perm); /* Generate the identity permutation */ void ap_dimperm_compose(ap_dimperm_t* perm, ap_dimperm_t* perm1, ap_dimperm_t* perm2); /* Compose the 2 permutations perm1 and perm2 (in this order) and store the result the already allocated perm. The sizes of permutations are supposed to be equal. At exit, we have perm.dim[i] = perm2.dim[perm1.dim[i]] */ void ap_dimperm_invert(ap_dimperm_t* nperm, ap_dimperm_t* perm); /* Invert the permutation perm and store it in the already allocated nperm. The sizes of permutations are supposed to be equal. */ /* ====================================================================== */ /* Inline Functions Definitions */ /* ====================================================================== */ static inline void ap_dimchange_clear(ap_dimchange_t* dimchange) { if (dimchange->dim) free(dimchange->dim); dimchange->intdim = dimchange->realdim = 0; dimchange->dim = NULL; } static inline void ap_dimchange_free(ap_dimchange_t* dimchange) { ap_dimchange_clear(dimchange); free(dimchange); } static inline void ap_dimperm_clear(ap_dimperm_t* dimperm) { if (dimperm->dim) free(dimperm->dim); dimperm->size = 0; dimperm->dim = NULL; } static inline void ap_dimperm_free(ap_dimperm_t* dimperm) { ap_dimperm_clear(dimperm); free(dimperm); } static inline void ap_dimchange2_init(ap_dimchange2_t* dimchange2, ap_dimchange_t* add, ap_dimchange_t* remove) { dimchange2->add = add; dimchange2->remove = remove; } static inline ap_dimchange2_t* ap_dimchange2_alloc(ap_dimchange_t* add, ap_dimchange_t* remove) { ap_dimchange2_t* res = (ap_dimchange2_t*)malloc(sizeof(ap_dimchange2_t)); ap_dimchange2_init(res,add,remove); return res; } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/apron.texi0000750014525101416610000060013611251670022020021 0ustar bjeannetpopart\input texinfo @c -*-texinfo-*- @c %**start of header @setfilename apron.info @settitle APRON 0.9.10 @c @setcontentsaftertitlepage @c include version.texi @iftex @afourpaper @end iftex @comment %**end of header @c This file is part of the APRON Library, released under LGPL @c license. Please read the COPYING file packaged in the distribution @setcontentsaftertitlepage @tex \global\parskip=0.5ex \global\baselineskip=3ex \global\mag=1000 @end tex @direntry * apron: (apron). APRON library for Abstract Interpretation of numerical variables. @end direntry @iftex @finalout @end iftex @ifnottex @node Top, Copying, (dir), (dir) @top APRON @end ifnottex @setchapternewpage odd @c Texinfo version 4 or up will be needed to process this into .info files. @c @c The edition number is in three places and the month/year in one, all @c taken from version.texi. version.texi is created when you configure with @c --enable-maintainer-mode, and is included in a distribution made with @c "make dist". @titlepage @c use the new format for titles @title APRON @subtitle The APRON library @subtitle Edition 0.9.8, October 2007 @author by Bertrand Jeannet and the APRON team @c Include the Distribution inside the titlepage so @c that headings are turned off. @end titlepage @iftex @page @vskip 0pt plus 1filll @end iftex @ifnothtml @contents @end ifnothtml @menu * Copying:: * Introduction to APRON:: * APRON Rationale and Functionalities:: * APRON Guidelines:: * Managers and Abstract Domains:: * Scalars & Intervals & Coefficients:: * Level 1 of the interface:: * Level 0 of the interface:: * Functions for implementors:: * Examples:: * Appendices:: @end menu @c ******************************************************************* @node Copying, Introduction to APRON, Top, Top @chapter APRON Copying Conditions (LGPL) @c ******************************************************************* The APRON library is copyright @copyright{} by the @uref{http://www.cri.ensmp.fr/apron/,APRON project}, and its partners. This license applies to all files distributed in the APRON library, including all source code, libraries, binaries, and documentation. @include lgpl.texi @c ******************************************************************* @node Introduction to APRON, APRON Rationale and Functionalities, Copying, Top @chapter Introduction to APRON @c ******************************************************************* The APRON library provides a common interface for @emph{abstract domains of invariants} for numerical variables, in the sense of the Abstract Interpretation theory. It includes a few domains, and provides interfaces to libraries implemented by other teams. @c The APRON library is dedicated to the static analysis of the numerical @c variables of a program by Abstract Interpretation. The aim of such an @c analysis is to infer invariants about these variables, like @c @math{1<=x+y<=z}, which holds during any execution of the program. @c Such an analysis works by computing iteratively the solution of @c fixpoint equations on an @emph{abstract domain} of invariants. The @c result is a overapproximation of the least inductive invariant of the @c program. Several libraries already exists, wich implement various abstract domains of invariants. One can cite intervals, linear equalities, octagons, octahedra, convex polyhedra, polynomial equalities, polynomial inequalities. Although they offer a kernel of common functionalities, their API may differ greatly, and some functionalities may lack in some libraries. The aim of the APRON library is to offer a common interface to these libraries. Such a standardized interface offers several advantages: it allows @itemize @item to easily substitute a library/abstract domain by another in the same analysis tool; this is useful to compare the efficiency of 2 implementations of the same abstract domain, or the precision of 2 different abstract domains. @item to factorize services which are mostly independant of the abstract domain (variables management, linearization of non-linear expressions, etc...); @item to make easier the combination of abstract domains: the abstract domains to be combined are used through the same interface, as the resulting combination; @end itemize @subsubheading As a user, why should I use APRON ? @enumerate @item it makes very easy to switch the abstract domain (for numerical variables) in use in an analyzer; @item it already offers the most used abstract domains, ranging from intervals, octagons, convex polyhedra to linear congruences; @item its interface should satisfy most needs, as it already satisfies the members of the APRON project working in different contexts (verification of high-level specifications/programs with exact arithmetics for INRIA \& Verimag, static analysis of runtime errors with floating-point arithmetics for ENS Paris, automatic parallelization of programs for ENSMP). @item the interface, at the level 1, already provides slightly higher-level functionalities than most existing and publicy available abstract domains libraries (with the manipulation of environments); this statement should be reinforced in the near future with the planned addition of a generic non-linear expressions layer and a floating-point arithmetic layer. @end enumerate @subsubheading As a domain implementor, why should I interface my abstract domain/library to APRON ? @enumerate @item to incite existing users of the APRON interface to try your library; @item to make your users, including yourself, benefit from previous points 1 and 4; @item to not waste your time implementing environments, variables renaming, OCaml interfaces, and so on; the effort to connect your library to the interface should at minimum be counterbalanced by such gains; @end enumerate @c The contributions of the project are @c @itemize @c @item @c The identification of the basic functionalities that an implementation @c should provide, and which cannot be factorized at a higher level; @c @item @c The design of a detailed API (datatypes, functions signatures) @c @item @c The implementation of functions that will be needed for most implementations @c @item @c The design and implementation of higher level services that are built on @c top of the basic interface and that factorizes services that can be @c shared between the underlying implementations. @c @end itemize @c ******************************************************************* @node APRON Rationale and Functionalities, APRON Guidelines, Introduction to APRON, Top @chapter APRON Rationale and Functionalities @c ******************************************************************* @include rationale.texi @c ******************************************************************* @node APRON Guidelines, Managers and Abstract Domains, APRON Rationale and Functionalities, Top @chapter APRON Guidelines @c ******************************************************************* @menu * Installing APRON:: * C Programming Guidelines:: * OCaml Programming Guidelines:: * MakingLibrary:: How to make an existing library conformant to APRON ? @end menu @c ******************************************************************* @node Installing APRON, C Programming Guidelines, APRON Guidelines, APRON Guidelines @section Installing APRON @c ******************************************************************* You should look at @file{../README}, @file{../Makefile.config.model} and @file{../Makefile} files. @c =================================================================== @node C Programming Guidelines, OCaml Programming Guidelines, Installing APRON, APRON Guidelines @section C Programming Guidelines @c =================================================================== @c ------------------------------------------------------------------- @menu * C Headers and Libraries:: * C Naming conventions:: * Allocating managers and setting options:: * Sequel of the small example:: * Typing issue in C:: @end menu @node C Headers and Libraries, C Naming conventions, C Programming Guidelines, C Programming Guidelines @subsection C Headers and Libraries @c ------------------------------------------------------------------- Declarations needed to use an underlying library via APRON are collected in the C include files @file{ap_global0.h} and @file{ap_global1.h}. They respectively refer to the level 0 and the level 1 of the interface. One can also refer to single APRON modules with their corresponding include files @file{ap_dimension.h}, @file{ap_lincons0.h}, ... Header files @file{}, @file{stdlib.h} and @file{} will be required. Then, you should also include the header files of the underlying libraries you want to use it via APRON (for instance, @file{box.h}, @file{pk.h}, @file{ap_ppl.h}). All programs using APRON must link against the @file{libapron}, @file{libmpfr} and @file{libgmp} libraries, and the underlying libraries you want to use it via APRON: @enumerate @item If some file @file{test.c} uses the POLKA library via APRON, the compilation command should look like @samp{gcc -I$ITV/include -I$MPFR/include -I$GMP/include -I$APRON/include -L$MPFR/lib -L$GMP/lib -L$APRON/lib -o test test.c -lpolkaMPQ -lapron -lmpfr -lgmp}, assuming that the POLKA library is used in its 'MPQ' version (internal number representation is GMP rationals) and resides in @file{$APRON/include} and @file{$APRON/lib} directories. The @file{libpolkaMPQ.a} library is of course needed, @file{libapron.a} contains all the code common to all APRON library (manipulation of expressions, environments, ...), as well as ITV functions (quasi)linearisation facilities of APRON,...), last the libraries @code{libmpfr.a} and @code{libgmp.a} are required both by @sc{NewPolka} and @sc{APRON} . @item If some file @file{test.c} uses the PPL library via APRON, the compilation command should look like @samp{g++ -I$ITV/include -I$MPFR/include -I$GMP/include -I$APRON/include -I$PPL/include -L$ITV/lib -L$MPFR/lib -L$GMP/lib -L$APRON/lib -L$PPL/lib -o test test.c -la_ppl -lppl -lgmpxx -lapron -lmpfr -lgmp}, assuming that PPL resides in $PPL and PPL APRON interface in @file{$APRON/include} and @file{$APRON/lib} directories. Notice that the PPL library (@file{libppl.a}) is a C++ library, you need to use @samp{g++} instead of @samp{gcc} for linking. You also need the C++ layer on top of GMP (@file{libgmpxx.a}). The @file{libap_ppl.a} library contains the layer on top of PPL which implements the APRON interface. @end enumerate You should look at the specific documentation of the libraries for more details. @c ------------------------------------------------------------------- @node C Naming conventions, Allocating managers and setting options, C Headers and Libraries, C Programming Guidelines @subsection Naming conventions and Allocation/Deallocation schemes @c ------------------------------------------------------------------- The general rule is that all type and function names defined by the library are prefixed with @code{ap_}, in order to prevent name conflicts with other libraries. Moreover, functions operating on objects of type @code{ap_typ_t} are usually prefixed with @code{ap_typ_op}. Given an object of datatype @code{ap_typ_t*}, two kinds of allocation/deallocation pairs of functions may be defined: @enumerate @item variable declaration: @code{ap_typ_t obj;} @itemize @item Initialization: @code{void typ_init(ap_typ_t* arg, ...)} or @code{ap_typ_t ap_typ_make(...)} @item Finalization: @code{void ap_typ_clear(ap_typ_t* arg)} @end itemize this pair of functions follows the semantics used in the GMP library. The first function initializes the object of type @code{ap_typ_t} pointed to by @var{arg}, and fills it with a valid content. The second function deallocates the memory possibly pointed to by fields of the object @code{*arg}, but do not attempt to deallocate the memory pointed by @var{arg}. @item variable declaration: @code{ap_typ_t* obj;} @itemize @item Allocation @code{ap_typ_t* ap_typ_alloc(...)} @item Deallocation @code{void ap_typ_free(ap_typ_t* arg)} @end itemize the first function allocates an object of type @code{typ_t} and then calls a @code{ap_typ_init}-like function on the result; the second functions first call a @code{ap_typ_clear}-like function and then deallocate the memory pointed by @var{arg}. @end enumerate @c ------------------------------------------------------------------- @node Allocating managers and setting options, Sequel of the small example, C Naming conventions, C Programming Guidelines @subsection Allocating managers and setting options @c ------------------------------------------------------------------- From the user point of view, the benefit of using the APRON interface is to restrict the place where the user is aware of the real library in use to the code initializing the manager, as illustrated by the following example: @example #include "ap_global1.h" #include "pk.h" /* Allocating a Polka manager, for polyhedra with strict constraints */ manager_t* man = pk_manager_alloc(true); /* Setting options offered by the common interface, but with meaning possibly specific to the library */ manager_set_abort_if_exception(man,EXC_OVERFLOW,true); @{ funopt_t funopt; funopt_init(&funopt); funopt.algorithm = 1; /* default value is 0 */ manager_set_funopt(man,fun_widening,&funopt); /* Setting options for widening */ @} @{ funopt_t funopt = manager_get_funopt(man,fun_widening); funopt.timeout = 30; manager_set_funopt(man,fun_widening,&funopt); @} /* Obtaining the internal part of the manager and setting specific options */ pk_internal_t* pk = manager_get_internal(man); pk_set_max_coeff_size(pk,size); @end example The standard operations can then be used and will have the semantics defined in the interface. Notice however that some generic functions are not formally generic: @code{abstract_fprint}, @code{abstract_fdump}, @code{abstract_approximate}. At any point, options may be modified in the same way as during the initialization. @c ------------------------------------------------------------------- @node Sequel of the small example, Typing issue in C, Allocating managers and setting options, C Programming Guidelines @subsection Sequel of the small example @c ------------------------------------------------------------------- An environment can be created as follows: @smallexample /* Create an environment with 6 real variables */ ap_var_t name_of_dim[6] = @{ "x","y","z","u","w","v" @}; ap_environment_t* env = ap_environment_alloc(NULL,0,name_of_dim,6); @end smallexample Then, we build an array of constraints. At level 1, an array of constraints is an abstract datatype, which requires careful manipulation w.r.t. memory management. @smallexample /* Create an array of constraints of size 2 */ ap_lincons1_array_t array = ap_lincons1_array_make(env,2); /* 1.a Creation of an inequality constraint */ ap_linexpr1_t expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,1); ap_lincons1_t cons = ap_lincons1_make(AP_CONS_SUP,&expr,NULL); /* Now expr is memory-managed by cons */ /* 1.b Fill the constraint */ ap_lincons1_set_list(&cons, AP_COEFF_S_INT,"x", AP_CST_S_FRAC,1,2, AP_END); /* 1.c Put in the array */ ap_lincons1_array_set(&array,0,&cons); /* Now cons is memory-managed by array */ /* 2.a Creation of an inequality constraint */ expr = ap_linexpr1_make(env,AP_LINEXPR_SPARSE,2); cons = ap_lincons1_make(AP_CONS_SUPEQ,&expr,NULL); /* The old cons is not lost, because it is stored in the array. It would be an error to clear it (same for expr). */ /* 2.b Fill the constraint */ ap_lincons1_set_list(&cons, AP_COEFF_S_INT,1,"x", AP_COEFF_S_INT,1,"y", AP_COEFF_S_INT,1,"z", AP_END); /* 2.c Put in the array */ ap_lincons1_array_set(&array,1,&cons); @end smallexample Last we can build an abstract value. @smallexample /* Creation of an abstract value defined by the array of constraints */ ap_abstract1_t abs = ap_abstract1_of_lincons_array(man,env,&array); fprintf(stdout,"Abstract value:\n"); ap_abstract1_fprint(stdout,man,&abs); @end smallexample We now deallocate everything: @smallexample /* deallocation */ ap_lincons1_array_clear(&array); ap_abstract1_clear(&abs); ap_environment_free(env); ap_manager_free(man); @end smallexample @c ------------------------------------------------------------------- @node Typing issue in C, , Sequel of the small example, C Programming Guidelines @subsection Typing issue in C @c ------------------------------------------------------------------- The use of several libraries at the same time via the common interface and the managers associated to each library raises the problem of typing. Look at the following code: @example ap_manager_t* manpk = pk_manager_alloc(true); /* manager for Polka */ ap_manager_t* manoct = oct_manager_alloc(); /* manager for octagon */ ap_abstract0_t* abs1 = ap_abstract_top(manpk,3,3); ap_abstract0_t* abs2 = ap_abstract_top(manoct,3,3); bool b = ap_abstract0_is_eq(manoct,abs1,abs2); /* Problem: the effective function called (octagon_is_eq) expects abs1 to be an octagon, and not a polyhedron ! */ ap_abstract0_t* abs3 = ap_abstract_top(manoct,3,3); abstract0_meet_with(manpk,abs2,abs3); /* Problem: the effective function called (pk_meet_with) expects abs2 and abs3 to be polyhedra, but they are octagons */ @end example There is actually no static typing, as @code{abstract0_t*} and @code{manager_t} are abstract types shared by the different libraries. Types are thus dynamically checked by the interface. Notice that the use of @emph{C++} and inheritance would not solve directly the problem, if functions of the interface are methods of the manager; one would have: @example ap_manager_t* manpk = pk_manager_alloc(true); /* manager for Polka, effective type pk_manager_t* */ ap_manager_t* manoct = oct_manager_alloc(); /* manager for octagon, effective type oct_manager_t* */ ap_abstract0_t* abs1 = manpk->abstract_top(3,3); /* effective type: poly_t */ ap_abstract0_t* abs2 = manoct->abstract_top(3,3); /* effective type: oct_t */ bool b = manoct->abstract0_is_eq(abs1,abs2); /* No static typing possible: manpk->abstract0_is_eq and manoct->abstract0_is_eq should have the same signature (otherwise one cannot interchange manpk and manoct in the code), which means that abs1 and abs2 are supposed to be of type abstract0_t* */ */ @end example Currently, only the OCaml polymorphic type system allows to solve elegantly this problem. @c =================================================================== @node OCaml Programming Guidelines, MakingLibrary, C Programming Guidelines, APRON Guidelines @section OCaml Programming Guidelines @c =================================================================== All modules belonging to the APRON interface itself (@code{Scalar}, @code{Interval}, ..., @code{Manager}, @code{Linexpr0}, ... @code{Abstract1}) are included in a big encapsulating module named @code{Apron}. In addition, there are modules like @code{Box} (intervals), @code{Oct} (octagons), @code{Polka} (linear equalities and convex polyhedra) and @code{Ppl} (convex polyhedra and linear congruences) not included in @code{Apron}. Generic abstract values have the type @code{'a Abstract1.t}, generic managers the type @code{'a Manager.t}. A typical operation like the emptiness test has the type @code{val is_bottom : 'a Manager.t -> 'a Abstract1.t -> bool}. Octagons of @sc{Octagon} have the type @code{Oct.t Apron.Abstract1.t}. The corresponding managers have thus the type @code{Oct.t Manager.t}. See @uref{../mlapronidl/index.html,OCaml interface} for the documentation. @c =================================================================== @node MakingLibrary, , OCaml Programming Guidelines, APRON Guidelines @section How to make an existing library conformant to APRON ? @c =================================================================== We briefly describe here how to connect an existing library to the common interface. First, the library has to expose an interface which conforms to the level 0 of the interface (module @code{abstract0}). All the functions described in this module should be defined. If a function is not really implemented, at least it shoulld contain the code raising the exception @code{EXC_NOT_IMPLEMENTED}. The implementor may use any functions of the files @file{ap_coeff.h}, @file{ap_linexpr0.h}, @file{ap_lincons0.h}, @file{ap_generator0.h} and @file{ap_manager.h} to help the job of converting datatypes of the interface to internal datatypes used inside the library. Second and last, the library should expose an initialization function that allocates and initializes properly an object of type @code{manager_t}. For this purpose, the module @code{manager} offers the utility functions @code{manager_alloc}. As an example, we give the definition of the function allocating a manager as implemented in the @emph{NewPolka}. @enumerate @item Header of the function: @example manager_t* pk_manager_alloc( bool strict /* specific parameter: do we allow strict constaints ? */ ) @end example @item Allocation and initialisation of global data specific to @emph{NewPolka}: @example @{ pk_internal_t* pk = pk_internal_alloc(strict); /* allocation */ pk_set_approximate_max_coeff_size(pk, 1); /* initialization of specific functions (not offered in the common interface) */ @} @end example @item Allocation of the manager itself: @example manager_t* man = ap_manager_alloc("polka","2.0", pk, (void (*)(void*))pk_internal_free); @end example We provide resp. name, version, internal specific manager, and the function to free it. The function @code{manager_alloc} sets the options of the common interface to their default value (see documentation). @item Initialization of the ``virtual'' table: we need to connect the generic functions of the interface (eg, @code{abstract_meet}, \ldots) to the actual functions of the library. @example funptr = man->funptr; funptr[fun_minimize] = &poly_minimize; funptr[fun_canonicalize] = &poly_canonicalize; funptr[fun_hash] = &poly_hash; funptr[fun_approximate] = &poly_approximate; funptr[fun_fprint] = &poly_fprint; funptr[fun_fprintdiff] = &poly_fprintdiff; funptr[fun_fdump] = &poly_fdump; ... @end example @item Last, we return the allocated manager: @example return man; @} @end example @end enumerate That's all for the implementor side. @c ******************************************************************* @node Managers and Abstract Domains, Scalars & Intervals & Coefficients, APRON Guidelines, Top @chapter Managers and Abstract Domains @c ******************************************************************* APRON makes use of a global manager for: @itemize @item selecting an effective underlying library/abstract domain; @item controlling various options; @item managing exceptions and flags; @item and also managing internal workspace needed for some library. @end itemize In a multithreaded program, both managers and abstract values should not be shared between threads (make copies to transmit information). Managers are allocated by the underlying libraries/abstract domains, but are freed via an APRON function. @menu * Managers:: * Box:: * Oct:: * NewPolka:: * PPL:: * pkgrid:: @end menu @c =================================================================== @node Managers, Box, Managers and Abstract Domains, Managers and Abstract Domains @section Managers (@file{ap_manager.h}) @c =================================================================== @menu * APRON Global Datatypes:: * Functions related to managers:: @end menu @c ------------------------------------------------------------------- @node APRON Global Datatypes, Functions related to managers, Managers, Managers @subsection Datatypes @c ------------------------------------------------------------------- @deftp datatype tbool_t @example typedef enum tbool_t @{ tbool_false=0, tbool_true=1, tbool_top=2, /* don't know */ @} tbool_t; static inline tbool_t tbool_of_bool(bool a); static inline tbool_t tbool_or(tbool_t a, tbool_t b); static inline tbool_t tbool_and(tbool_t a, tbool_t b); @end example Booleans with a third unknown value. @end deftp @deftp datatype ap_membuf_t @example typedef struct ap_membuf_t @{ void* ptr; size_t size; @} ap_membuf_t; @end example For serialization. @end deftp @deftp datatype ap_manager_t APRON managers (opaque type). @end deftp @deftp datatype ap_funid_t For identifying functions in excpetions, and when reading/setting options attached to them. @example typedef enum ap_funid_t @{ AP_FUNID_UNKNOWN, AP_FUNID_COPY, AP_FUNID_FREE, AP_FUNID_ASIZE, /* For avoiding name conflict with AP_FUNID_SIZE */ AP_FUNID_MINIMIZE, AP_FUNID_CANONICALIZE, AP_FUNID_HASH, AP_FUNID_APPROXIMATE, AP_FUNID_FPRINT, AP_FUNID_FPRINTDIFF, AP_FUNID_FDUMP, AP_FUNID_SERIALIZE_RAW, AP_FUNID_DESERIALIZE_RAW, AP_FUNID_BOTTOM, AP_FUNID_TOP, AP_FUNID_OF_BOX, AP_FUNID_DIMENSION, AP_FUNID_IS_BOTTOM, AP_FUNID_IS_TOP, AP_FUNID_IS_LEQ, AP_FUNID_IS_EQ, AP_FUNID_IS_DIMENSION_UNCONSTRAINED, AP_FUNID_SAT_INTERVAL, AP_FUNID_SAT_LINCONS, AP_FUNID_SAT_TCONS, AP_FUNID_BOUND_DIMENSION, AP_FUNID_BOUND_LINEXPR, AP_FUNID_BOUND_TEXPR, AP_FUNID_TO_BOX, AP_FUNID_TO_LINCONS_ARRAY, AP_FUNID_TO_TCONS_ARRAY, AP_FUNID_TO_GENERATOR_ARRAY, AP_FUNID_MEET, AP_FUNID_MEET_ARRAY, AP_FUNID_MEET_LINCONS_ARRAY, AP_FUNID_MEET_TCONS_ARRAY, AP_FUNID_JOIN, AP_FUNID_JOIN_ARRAY, AP_FUNID_ADD_RAY_ARRAY, AP_FUNID_ASSIGN_LINEXPR_ARRAY, AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY, AP_FUNID_ASSIGN_TEXPR_ARRAY, AP_FUNID_SUBSTITUTE_TEXPR_ARRAY, AP_FUNID_ADD_DIMENSIONS, AP_FUNID_REMOVE_DIMENSIONS, AP_FUNID_PERMUTE_DIMENSIONS, AP_FUNID_FORGET_ARRAY, AP_FUNID_EXPAND, AP_FUNID_FOLD, AP_FUNID_WIDENING, AP_FUNID_CLOSURE, AP_FUNID_SIZE, AP_FUNID_CHANGE_ENVIRONMENT, AP_FUNID_RENAME_ARRAY, AP_FUNID_SIZE2 @} ap_funid_t; extern const char* ap_name_of_funid[AP_FUNID_SIZE2]; /* give the name of a function identifier */ @end example @end deftp @deftp datatype ap_exc_t @deftpx datatype ap_exc_log_t Exceptions and exception logs (chained in a list, the first one being the last one). @example typedef enum ap_exc_t @{ AP_EXC_NONE, /* no exception detected */ AP_EXC_TIMEOUT, /* timeout detected */ AP_EXC_OUT_OF_SPACE, /* out of space detected */ AP_EXC_OVERFLOW, /* magnitude overflow detected */ AP_EXC_INVALID_ARGUMENT, /* invalid arguments */ AP_EXC_NOT_IMPLEMENTED, /* not implemented */ AP_EXC_SIZE @} ap_exc_t; extern const char* ap_name_of_exception[AP_EXC_SIZE]; typedef struct ap_exclog_t @{ ap_exc_t exn; ap_funid_t funid; char* msg; /* dynamically allocated */ struct ap_exclog_t* tail; @} ap_exclog_t; @end example @end deftp @anchor{ap_funopt_t} @deftp datatype ap_funopt_t Options attached to functions. @example typedef struct ap_funopt_t @{ int algorithm; /* Algorithm selection: - 0 is default algorithm; - MAX_INT is most accurate available; - MIN_INT is most efficient available; - otherwise, no accuracy or speed meaning */ size_t timeout; /* unit !? */ /* Above the given computation time, the function may abort with the exception flag flag_time_out on. */ size_t max_object_size; /* in abstract object size unit. */ /* If during the computation, the size of some object reach this limit, the function may abort with the exception flag flag_out_of_space on. */ bool flag_exact_wanted; /* return information about exactitude if possible */ bool flag_best_wanted; /* return information about best correct approximation if possible */ @} ap_funopt_t; @end example @end deftp @c ------------------------------------------------------------------- @node Functions related to managers, , APRON Global Datatypes, Managers @subsection Functions related to managers @c ------------------------------------------------------------------- @deftypefun void ap_manager_free (ap_manager_t* @var{man}) Free a manager (dereference a counter, and possibly deallocate). @end deftypefun @deftypefun const char* ap_manager_get_library (ap_manager_t* @var{man}) @deftypefunx const char* ap_manager_get_version (ap_manager_t* @var{man}) Reading the name and the version of the attached underlying library. @end deftypefun @deftypefun bool ap_manager_get_flag_exact (ap_manager_t* @var{man}) @deftypefunx bool ap_manager_get_flag_best (ap_manager_t* @var{man}) Return @code{true} if the last called APRON function returned an exact (resp. a best approximation) result. @end deftypefun @anchor{Manager options} @subheading Options @xref{ap_funopt_t}. @deftypefun ap_funopt_t ap_manager_get_funopt (ap_manager_t* @var{man}, ap_funid_t @var{funid}) Getting the option attached to the specified function in the manager. @var{funid} should be less than @code{AP_FUNID_SIZE} (no option associated to other identifiers). Otherwise, abort with a message. @end deftypefun @deftypefun void ap_manager_set_funopt (ap_manager_t* @var{man}, ap_funid_t @var{funid}, ap_funopt_t* @var{fopt}) Setting the option attached to the specified function in the manager. @var{fopt} is copied (and not only referenced). @var{funid} should be less than @code{AP_FUNID_SIZE} (no option associated to other identifiers). Otherwise, do nothing. @end deftypefun @deftypefun void ap_funopt_init (ap_funopt_t* @var{fopt}) Initialize @var{fopt} with default values. @end deftypefun @subheading Exceptions @deftypefun bool ap_manager_get_abort_if_exception (ap_manager_t* @var{man}, ap_exc_t @var{exn}) Return true if the program abort when the exception @var{exn} is raised by some function. Otherwise, in such a case, a valid (but dummy) value should be returned by the function that raises the exception. @end deftypefun @deftypefun void ap_manager_set_abort_if_exception (ap_manager_t* @var{man}, ap_exc_t @var{exn}, bool @var{flag}) Position the above-described option. @end deftypefun @deftypefun ap_exc_t ap_manager_get_exception (ap_manager_t* @var{man}) Get the last exception raised. @end deftypefun @deftypefun ap_exclog_t ap_manager_get_exclog (ap_manager_t* @var{man}) Get the full log of exceptions. The first one in the list is the last raised one. @end deftypefun @c =================================================================== @node Box, Oct, Managers, Managers and Abstract Domains @section Box (@file{box.h}): intervals abstract domain @c =================================================================== @include box.texi @c =================================================================== @node Oct, NewPolka, Box, Managers and Abstract Domains @section Oct: octagon abstract domain @c =================================================================== @uref{oct_doc.html} @c =================================================================== @node NewPolka, PPL, Oct, Managers and Abstract Domains @section NewPolka (@file{pk.h}): convex polyhedra and linear equalities abstract domains @c =================================================================== @include newpolka.texi @c =================================================================== @node PPL, pkgrid, NewPolka, Managers and Abstract Domains @section PPL (@file{ap_ppl.h}): convex polyhedra and linear congruences abstract domains @c =================================================================== @include ap_ppl.texi @c =================================================================== @node pkgrid, , PPL, Managers and Abstract Domains @section pkgrid (@file{ap_pkgrid.h}): reduced product of NewPolka convex polyhedra and PPL linear congruences abstract domains @c =================================================================== @include ap_pkgrid.texi @c ******************************************************************* @node Scalars & Intervals & Coefficients, Level 1 of the interface, Managers and Abstract Domains, Top @chapter Scalars & Intervals & coefficients @c ******************************************************************* @emph{Scalars} are scalar numbers, implemented either as an (inexact) floating point type or an (exact) rational type. @emph{Intervals} are intervals built on scalars. @emph{Coefficients} are either scalars or intervals. @menu * Scalars:: * Intervals:: * Coefficients:: @end menu @ifnothtml We sum up the involved types below (numbers denotes sizes in bytes on a typical 32 bits computer. @verbatim ap_scalar_t 12 ap_interval_t 8 |-----------------| |--------------| | ap_scalar_discr | 4 | ap_scalar_t* | 4 |-----------------| |--------------| | double | mpq_t* | 8 | ap_scalar_t* | 4 |-----------------| |--------------| ap_coeff_t 8 |-------------------------------| | ap_coeff_discr | 4 |-------------------------------| | ap_scalar_t* | ap_interval_t* | 4 |-------------------------------| @end verbatim These types are manipulated using pointers, with creator @code{X_t* X_alloc()} and destructors @code{void X_free(X_t*)}. @end ifnothtml @c =================================================================== @node Scalars, Intervals, Scalars & Intervals & Coefficients, Scalars & Intervals & Coefficients @section Scalars (@file{ap_scalar.h}) @c =================================================================== @deftp datatype ap_scalar_discr_t @example typedef enum ap_scalar_discr_t @{ AP_SCALAR_DOUBLE, /* floating-point with double */ AP_SCALAR_MPQ /* rational with multi-precision GMP */ @} ap_scalar_discr_t; @end example Discriminant indicating the underlying type of a scalar number. @end deftp @deftp datatype ap_scalar_t @example typedef struct ap_scalar_t @{ ap_scalar_discr_t discr; union @{ double dbl; mpq_ptr mpq; /* +infty coded by 1/0, -infty coded by -1/0 */ @} val; @} ap_scalar_t; @end example A scalar number is either a double, or a multi-precision rational, as implemented by GMP. @end deftp @menu * Initializing scalars:: * Assigning scalars:: * Converting scalars:: * Comparing scalars:: * Other operations on scalars:: @end menu @c ------------------------------------------------------------------- @node Initializing scalars, Assigning scalars, Scalars, Scalars @subsection Initializing scalars @c ------------------------------------------------------------------- @deftypefun ap_scalar_t* ap_scalar_alloc () Allocate a scalar, of default type DOUBLE (the most economical) @end deftypefun @deftypefun void ap_scalar_free (ap_scalar_t* @var{op}) Deallocate a scalar. @end deftypefun @deftypefun void ap_scalar_reinit (ap_scalar_t* @var{op}, ap_scalar_discr_t @var{discr}) Change the type of an already allocated scalar (mainly for internal use) @end deftypefun @deftypefun void ap_scalar_init (ap_scalar_t* @var{op}, ap_scalar_discr_t @var{discr}) @deftypefunx void ap_scalar_clear (ap_scalar_t* @var{op}) Initialize and clear a scalar \`a la GMP (internal use). @end deftypefun @c ------------------------------------------------------------------- @node Assigning scalars, Converting scalars, Initializing scalars, Scalars @subsection Assigning scalars @c ------------------------------------------------------------------- @deftypefun void ap_scalar_set (ap_scalar_t* @var{rop}, ap_scalar_t* @var{op}) Set the value of @var{rop} from @var{op}. @end deftypefun @deftypefun void ap_scalar_set_mpq (ap_scalar_t* @var{rop}, mpq_t @var{mpq}) @deftypefunx void ap_scalar_set_int (ap_scalar_t* @var{rop}, long int @var{i}) @deftypefunx void ap_scalar_set_frac (ap_scalar_t* @var{rop}, long int @var{i}, unsigned long int @var{j}) Change the type of @var{rop} to MPQ and set its value to resp. @var{mpq}, @var{i}, and @var{i}/@var{j}. @end deftypefun @deftypefun void ap_scalar_set_double (ap_scalar_t* @var{rop}, double @var{k}) Change the type of @var{rop} to DOUBLE and set its value to @var{k}. @end deftypefun @deftypefun void ap_scalar_set_infty (ap_scalar_t* @var{rop}, int @var{sgn}) Set the value of @var{rop} to @var{sgn}*infinity. Keep the type of the @var{rop}. @end deftypefun @deftypefun ap_scalar_t* ap_scalar_alloc_set (ap_scalar_t* @var{op}) @deftypefunx ap_scalar_t* ap_scalar_alloc_set_mpq (mpq_t @var{mpq}) @deftypefunx ap_scalar_t* ap_scalar_alloc_set_double (double @var{k}) Combined allocation and assignement. @end deftypefun @c ------------------------------------------------------------------- @node Converting scalars, Comparing scalars, Assigning scalars, Scalars @subsection Converting scalars @c ------------------------------------------------------------------- @deftypefun void ap_mpq_set_scalar (mpq_t @var{mpq}, ap_scalar_t* @var{op}, int @var{round}) Set @var{mpq} with the value of @var{op}, possibly converting from DOUBLE type. @var{round} currently unused. @end deftypefun @deftypefun double ap_scalar_get_double (ap_scalar_t* @var{op}, int @var{round}) Return the value of @var{op} in DOUBLE type, possibly converting from MPQ type. Conversion may be not exact. @var{round} currently unused. @end deftypefun @c ------------------------------------------------------------------- @node Comparing scalars, Other operations on scalars, Converting scalars, Scalars @subsection Comparing scalars @c ------------------------------------------------------------------- @deftypefun int ap_scalar_infty (ap_scalar_t* @var{op}) Return @code{-1} if @var{op} is set to +infty, @code{-1} if set to -infty, and @code{0} otherwise. @end deftypefun @deftypefun int ap_scalar_sgn (ap_scalar_t* @var{op}) Return the sign of @var{op} (@code{+1}, @code{0} or @code{-1}). @end deftypefun @deftypefun int ap_scalar_cmp (ap_scalar_t* @var{op1}, ap_scalar_t* @var{op2}) @deftypefunx int ap_scalar_cmp_int (ap_scalar_t* @var{op1}, int @var{op2}) Exact comparison between two scalars (resp. a scalar and an integer). Return @code{-1} if @var{op1} is less than @var{op2}, @code{0} if they are equal, and @code{+1} if @code{op1} is greater than @var{op2}. @end deftypefun @deftypefun bool ap_scalar_equal (ap_scalar_t* @var{op1}, ap_scalar_t* @var{op2}); @deftypefunx bool ap_scalar_equal_int (ap_scalar_t* @var{op1}, int @var{op2}); Equality test between two scalars (resp. a scalar and an integer). Return @code{true} if equality. @end deftypefun @c ------------------------------------------------------------------- @node Other operations on scalars, , Comparing scalars, Scalars @subsection Other operations on scalars @c ------------------------------------------------------------------- @deftypefun void ap_scalar_neg (ap_scalar_t* @var{rop}, ap_scalar_t* @var{op}) Negation. @end deftypefun @deftypefun void ap_scalar_inv (ap_scalar_t* @var{rop}, ap_scalar_t* @var{op}) Inversion. Not exact for DOUBLE type. @end deftypefun @deftypefun void ap_scalar_swap (ap_scalar_t* @var{op1}, ap_scalar_t* @var{op2}) Exchange the values of @var{op1} and @var{op2}. @end deftypefun @deftypefun int ap_scalar_hash (ap_scalar_t* @var{op}) Return an hash code (for instance for OCaml interface). @end deftypefun @deftypefun void ap_scalar_fprint (FILE* @var{stream}, ap_scalar_t* @var{op}) Print @var{op} on the stream @var{stream}. @end deftypefun @c =================================================================== @node Intervals, Coefficients, Scalars, Scalars & Intervals & Coefficients @section Intervals (@file{ap_interval.h}) @c =================================================================== @deftp datatype ap_interval_t @example typedef struct ap_interval_t @{ ap_scalar_t* inf; ap_scalar_t* sup; @} ap_interval_t; @end example Intervals on scalars. @end deftp @menu * Initializing intervals:: * Assigning intervals:: * Comparing intervals:: * Other operations on intervals:: * Array of intervals:: @end menu @c ------------------------------------------------------------------- @node Initializing intervals, Assigning intervals, Intervals, Intervals @subsection Initializing intervals @c ------------------------------------------------------------------- @deftypefun void ap_interval_alloc () Allocate an interval (with scalars of default type DOUBLE, the most economical). @end deftypefun @deftypefun void ap_interval_free (ap_interval_t* @var{op}) Deallocate an interval. @end deftypefun @deftypefun void ap_interval_reinit (ap_interval_t* @var{op}, ap_scalar_discr_t @var{discr}) Change the type of the bounds of the interval (mainly for internal use). @end deftypefun @c ------------------------------------------------------------------- @node Assigning intervals, Comparing intervals, Initializing intervals, Intervals @subsection Assigning intervals @c ------------------------------------------------------------------- @deftypefun void ap_interval_set (ap_interval_t* @var{rop}, ap_interval_t* @var{op}) Set the value of @var{rop} from @var{op}. @end deftypefun @deftypefun void ap_interval_set_scalar (ap_interval_t* @var{rop}, ap_scalar_t* @var{inf}, ap_scalar_t* @var{sup}) Set the value of @var{rop} from the interval [@var{inf},@var{sup}]. @end deftypefun @deftypefun void ap_interval_set_mpq (ap_interval_t* @var{rop}, mpq_t @var{inf}, mpq_t @var{sup}) @deftypefunx void ap_interval_set_int (ap_interval_t* @var{rop}, int @var{inf}, int @var{sup}) @deftypefunx void ap_interval_set_frac (ap_interval_t* @var{rop}, int @var{numinf}, int @var{deninf}, int @var{numsup}, int @var{densup}) Set the value of @var{rop} from the interval [@var{inf},@var{sup}] or [@var{numinf}/@var{deninf},@var{numsup}/@var{densup}]. The scalars are of type MPQ. @end deftypefun @deftypefun void ap_interval_set_double (ap_interval_t* @var{rop}, double @var{inf}, double @var{sup}) Set the value of @var{rop} from the interval [@var{inf},@var{sup}]. The scalars are of type DOUBLE. @end deftypefun @deftypefun void ap_interval_set_top (ap_interval_t* @var{op}) @deftypefunx void ap_interval_set_bottom (ap_interval_t* @var{op}) Set the value of @var{rop} resp. to the top interval [-oo,+oo] or to the empty interval [+1,-1]. @end deftypefun @deftypefun ap_interval_t* ap_interval_alloc_set (ap_interval_t* @var{op}) Combined allocation and assignement. @end deftypefun @c ------------------------------------------------------------------- @node Comparing intervals, Other operations on intervals, Assigning intervals, Intervals @subsection Comparing intervals @c ------------------------------------------------------------------- @deftypefun bool ap_interval_is_top (ap_interval_t* @var{op}) @deftypefunx bool ap_interval_is_bottom (ap_interval_t* @var{op}) Return @code{true} if the interval is resp. the universe interval ([-oo,+oo]) or an empty interval. @end deftypefun @deftypefun bool ap_interval_is_leq (ap_interval_t* @var{op1}, ap_interval_t* @var{op2}) Inclusion test. Return true if the interval @var{op1} is included in @var{op2}. @end deftypefun @deftypefun bool ap_interval_equal (ap_interval_t* @var{op1}, ap_interval_t* @var{op2}) Equality test. Return true if the interval @var{op1} is included in @var{op2}. @end deftypefun @deftypefun int ap_interval_cmp (ap_interval_t* @var{op1}, ap_interval_t* @var{op2}) Non-total comparison. @table @code @item 0 equality @item -1 @var{op1} included in @var{op2} @item +1 @var{op2} included in @var{op1} @item -2 @var{op1.inf} less than @var{op2.inf} @item +2 @var{op1.inf} greater than @var{op2.inf} @end table @end deftypefun @c ------------------------------------------------------------------- @node Other operations on intervals, Array of intervals, Comparing intervals, Intervals @subsection Other operations on intervals @c ------------------------------------------------------------------- @deftypefun void ap_interval_neg (ap_interval_t* @var{rop}, ap_interval_t* @var{op}) Negation. @end deftypefun @deftypefun void ap_interval_swap (ap_interval_t* @var{op1}, ap_interval_t* @var{op2}) Exchange the values of @var{op1} and @var{op2}. @end deftypefun @deftypefun int ap_interval_hash (ap_interval_t* @var{op}) Return an hash code (for instance for OCaml interface). @end deftypefun @deftypefun void ap_interval_fprint (FILE* @var{stream}, ap_interval_t* @var{op}) Print @var{op} on the stream @var{stream}. @end deftypefun @c ------------------------------------------------------------------- @node Array of intervals, , Other operations on intervals, Intervals @subsection Array of intervals @c ------------------------------------------------------------------- @deftypefun ap_interval_t** ap_interval_array_alloc (size_t @var{size}) Allocate an array of intervals, initialized with [0,0] values. @end deftypefun @deftypefun void ap_interval_array_free (ap_interval_t** @var{array}, size_t @var{size}) Clearing and deallocating an array of intervals. @end deftypefun @c =================================================================== @node Coefficients, , Intervals, Scalars & Intervals & Coefficients @section Coefficients (@file{ap_coeff.h}) @c =================================================================== @deftp datatype ap_coeff_discr_t @example typedef enum ap_coeff_discr_t @{ AP_COEFF_SCALAR, AP_COEFF_INTERVAL @} ap_coeff_discr_t; @end example Discriminant indicating the underlying type of a coefficient. @end deftp @deftp datatype ap_coeff_t @example typedef struct ap_coeff_t @{ ap_coeff_discr_t discr; union @{ ap_scalar_t* scalar; ap_interval_t* interval; @} val; @} ap_coeff_t; @end example A coefficient is either a scalar or an interval. @end deftp @menu * Initializing coefficients:: * Assigning coefficients:: * Comparing coefficients:: * Other operations on coefficients:: @end menu @c ------------------------------------------------------------------- @node Initializing coefficients, Assigning coefficients, Coefficients, Coefficients @subsection Initializing coefficients @c ------------------------------------------------------------------- @deftypefun void ap_coeff_alloc (ap_coeff_discr_t @var{discr}) Allocate a coefficient, using @var{discr} to specify the type of coefficient (scalar or interval). @end deftypefun @deftypefun void ap_coeff_free (ap_coeff_t* @var{op}) Deallocate a coefficient. @end deftypefun @deftypefun void ap_coeff_reinit (ap_coeff_t* @var{op}, ap_coeff_discr_t @var{discr1}, ap_scalar_discr_t @var{discr2}) Changing the type of the coefficient and also the type of the underlting scalar(s). @end deftypefun @deftypefun void ap_coeff_reduce (ap_coeff_t* @var{op}) If the coefficient is an interval [a;a], convert it to a scalar. */ @end deftypefun @deftypefun void ap_coeff_init (ap_coeff_t* @var{rop}, ap_coeff_discr_t @var{discr}) @deftypefunx void ap_coeff_init_set (ap_coeff_t* @var{rop}, ap_coeff_t* @var{op}) @deftypefunx void ap_coeff_clear (ap_coeff_t* @var{rop}) Initialize, initialize and assign, and clear a scalar \`a la GMP (internal use). @end deftypefun @c ------------------------------------------------------------------- @node Assigning coefficients, Comparing coefficients, Initializing coefficients, Coefficients @subsection Assigning coefficients @c ------------------------------------------------------------------- @deftypefun void ap_coeff_set (ap_coeff_t* @var{rop}, ap_coeff_t* @var{op}) Set the value of @var{rop} from @var{op}. @end deftypefun @deftypefun void ap_coeff_set_scalar (ap_coeff_t* @var{rop}, ap_scalar_t* @var{op}) @deftypefunx void ap_coeff_set_scalar_mpq (ap_coeff_t* @var{rop}, mpq_t @var{mpq}) @deftypefunx void ap_coeff_set_scalar_int (ap_coeff_t* @var{rop}, long int @var{i}) @deftypefunx void ap_coeff_set_scalar_frac (ap_coeff_t* @var{rop}, long int @var{i}, unsigned long int @var{j}) @deftypefunx void ap_coeff_set_scalar_double (ap_coeff_t* @var{rop}, double @var{k}) Set the type of @var{rop} to scalar, and sets its value as the functions @code{ap_scalar_set_XXX}. @end deftypefun @deftypefun void ap_coeff_set_interval (ap_coeff_t* @var{rop}, ap_interval_t* @var{op}) @deftypefunx void ap_coeff_set_interval_scalar (ap_coeff_t* @var{rop}, ap_scalar_t* @var{inf}, ap_scalar_t* @var{sup}) @deftypefunx void ap_coeff_set_interval_mpq (ap_coeff_t* @var{rop}, mpq_t @var{inf}, mpq_t @var{sup}) @deftypefunx void ap_coeff_set_interval_int (ap_coeff_t* @var{rop}, int @var{inf}, int @var{sup}) @deftypefunx void ap_coeff_set_interval_frac (ap_coeff_t* @var{rop}, int @var{numinf}, int @var{deninf}, int @var{numsup}, int @var{densup}) @deftypefunx void ap_coeff_set_interval_double (ap_coeff_t* @var{rop}, double @var{inf}, double @var{sup}) Set the type of @var{rop} to interval, and sets its value as the functions @code{ap_interval_set_XXX}. @end deftypefun @deftypefun ap_coeff_t* ap_coeff_alloc_set (ap_coeff_t* @var{op}) @deftypefunx ap_coeff_t* ap_coeff_alloc_set_scalar (ap_scalar_t* @var{scalar}) @deftypefunx ap_coeff_t* ap_coeff_alloc_set_interval (ap_interval_t* @var{interval}) Combined allocation and assignement. @end deftypefun @c ------------------------------------------------------------------- @node Comparing coefficients, Other operations on coefficients, Assigning coefficients, Coefficients @subsection Comparing coefficients @c ------------------------------------------------------------------- @deftypefun int ap_coeff_cmp (ap_coeff_t* @var{op1}, ap_coeff_t* @var{op2}) Non-total comparison. @itemize @item If @var{op1} and @var{op2} are scalars, corresponds to @code{ap_scalar_cmp}. @item If @var{op1} and @var{op2} are intervals, corresponds to @code{ap_interval_cmp}. @item otherwise, -3 if the first is a scalar, 3 otherwise @end itemize @end deftypefun @deftypefun bool ap_coeff_equal (ap_coeff_t* @var{op1}, ap_coeff_t* @var{op2}) Equality test. @end deftypefun @deftypefun bool ap_coeff_zero (ap_coeff_t* @var{op}) Return true iff coeff is a zero scalar or an interval with zero bounds. @end deftypefun @c ------------------------------------------------------------------- @node Other operations on coefficients, , Comparing coefficients, Coefficients @subsection Other operations on coefficients @c ------------------------------------------------------------------- @deftypefun void ap_coeff_neg (ap_coeff_t* @var{rop}, ap_coeff_t* @var{op}) Negation. @end deftypefun @deftypefun void ap_coeff_swap (ap_coeff_t* @var{op1}, ap_coeff_t* @var{op2}) Exchange the values of @var{op1} and @var{op2}. @end deftypefun @deftypefun int ap_coeff_hash (ap_coeff_t* @var{op}) Return an hash code (for instance for OCaml interface). @end deftypefun @deftypefun void ap_coeff_fprint (FILE* @var{stream}, ap_coeff_t* @var{op}) Print @var{op} on the stream @var{stream}. @end deftypefun @c ******************************************************************* @node Level 1 of the interface, Level 0 of the interface, Scalars & Intervals & Coefficients, Top @chapter Level 1 of the interface @c ******************************************************************* This interface of level 1 is defined in @file{ap_global1.h}. @menu * Variables and related operations:: * Environments:: * Linear expressions of level 1:: * Linear constraints of level 1:: * Generators of level 1:: * Tree expressions of level 1:: * Tree constraints of level 1:: * Abstract values and operations of level 1:: @end menu @noindent The main functions brought by level 1 are @itemize @item to convert variables to dimensions, thanks to the addition of environments to objects; @item to redimension (abstract values), expressions, constraints and generators defined on different environments. @end itemize The policy for redimensioning is the following one: @itemize @item For functions taking one abstract value and one expression (or constraint or generator, or array of ...), the environment of the expression should be a sub-environment of the environment of the abstract value. The environment of the result is the environment of the argument abstract value. @item For functions taking several abstract values, their environments should be the same. Otherwise, it is up to the user to move them to a common super-environment (see @ref{Environments} and @ref{Change of environments of abstract values of level 1}). @end itemize @ifnothtml For information only (as these types are considered as abstract), we sum up the involved types below. @verbatim ap_var_t ap_var_t ap_environment_t |-------| |-------| |----------------------| | void* | by default | char* | | ap_var_t* var_of_dim | |-------| |-------| | size_t intdim | | size_t realdim | | size_t count | |----------------------| ap_linexpr1_t |-------------------| | ap_linexpr0_t* | | ap_environment_t* | |-------------------| ap_lincons1_t ap_lincons1_array_t |-------------------| |----------------------| | ap_lincons0_t* | | ap_lincons0_array_t* | | ap_environment_t* | | ap_environment_t* | |-------------------| |----------------------| ap_generator1_t ap_generator1_array_t |-------------------| |------------------------| | ap_generator0_t* | | ap_generator0_array_t* | | ap_environment_t* | | ap_environment_t* | |-------------------| |------------------------| ap_texpr1_t |-------------------| | ap_texpr0_t* | | ap_environment_t* | |-------------------| ap_tcons1_t ap_tcons1_array_t |-------------------| |----------------------| | ap_tcons0_t* | | ap_tcons0_array_t* | | ap_environment_t* | | ap_environment_t* | |-------------------| |----------------------| ap_abstract1_t |-------------------| | ap_abstract0_t* | | ap_environment_t* | |-------------------| @end verbatim @end ifnothtml @c =================================================================== @node Variables and related operations, Environments, Level 1 of the interface, Level 1 of the interface @section Variables and related operations (@file{ap_var.h}) @c =================================================================== A variable is not necessarily a name, it can be a more complex structured datatype, depending on the application. That is the motivation to make it a parameter of the interface. The abstract type @code{ap_var_t} is equipped with a total ordering function, a hashing function, a copy function, and a free function. The parametrization of the interface is performed via a global variable pointing to a @code{ap_var_operations_t} structure, containing the above-mentione doperations on @code{ap_var_t} objects. This means that this type should be fixed once, and that in a multitreaded application all threads should share the same @code{ap_var_t} type. By default, @code{ap_var_t} is a C string (@code{char*}), and the global variable @code{ap_var_operations} is properly initialized. @deftp datatype ap_var_t @example typedef void* ap_var_t; @end example Datatype for ``variables''. It is assumed to be of size @code{sizeof(void*)}. @end deftp @deftp datatype ap_var_operations_t @example typedef struct ap_var_operations_t @{ int (*compare)(ap_var_t v1, ap_var_t v2); /* Total ordering function */ int (*hash)(ap_var_t v); /* Hash function */ ap_var_t (*copy)(ap_var_t var); /* Duplication function */ void (*free)(ap_var_t var); /* Deallocation function */ char* (*to_string)(ap_var_t var); /* Conversion to a dynamically allocated string, which should be deallocated with free after use */ @} ap_var_operations_t; @end example Datatype for defining the operations on ``variables''. @end deftp @deftypevar ap_var_operations_t var_operations_default Default manager, where @code{ap_var_t} is assumed to be @code{char*}. @end deftypevar @deftypevar ap_var_operations_t* var_operations Global pointer to the manager in use, by default points to @code{ap_var_operations_default}. @end deftypevar @c =================================================================== @node Environments, Linear expressions of level 1, Variables and related operations, Level 1 of the interface @section Environments (@file{ap_environment.h}) @c =================================================================== Environments bind variables (of level 1) to dimensions (of level 0). @deftp datatype ap_environment_t Internal datatype for environments. For information, the definition is: @example typedef struct ap_environment_t @{ ap_var_t* var_of_dim; /* Array of size intdim+realdim, indexed by dimensions. - It should not contain identical strings.. - Slice [0..intdim-1] is lexicographically sorted, and denotes integer variables. - Slice [intdim..intdim+realdim-1] is lexicographically sorted, and denotes real variables. - The memory allocated for the variables are attached to the structure (they are freed when the structure is no longer in use) */ size_t intdim; /* Number of integer variables */ size_t realdim;/* Number of real variables */ size_t count; /* For reference counting */ @} ap_environment_t; @end example @end deftp @deftypefun void ap_environment_free (ap_environment_t* @var{env}) @deftypefunx ap_environment_t* ap_environment_copy (ap_environment_t* @var{env}) Respectively free and duplicate an environment. (@code{copy} is cheap, as environments are managed with reference counters). @end deftypefun @deftypefun void ap_environment_fdump (FILE* @var{stream}, ap_environment_t* @var{env}) Print an environment under the form: @example environment: dim = (..,..), count = .. 0: name0 1: name1 ... @end example @end deftypefun @deftypefun ap_environment_t* ap_environment_alloc_empty () Build an empty environment. @end deftypefun @deftypefun ap_environment_t* ap_environment_alloc (ap_var_t* @var{var_of_intdim}, size_t @var{intdim}, ap_var_t* @var{var_of_realdim}, size_t @var{realdim}) Build an environment from an array of integer and an array of real variables. @var{var_of_intdim} is an array of variables of size @var{intdim}, @var{var_of_realdim} is an array of variables of size @var{realdim}. Pointers to arrays may be @code{NULL} if their size is 0. Variables are duplicated in the result, so it is the responsability of the user to free the variables he provides. If some variables are duplicated, return @code{NULL}. @end deftypefun @deftypefun ap_environment_t* ap_environment_add (ap_environment_t* @var{env}, ap_var_t* @var{var_of_intdim}, size_t @var{intdim}, ap_var_t* @var{var_of_realdim}, size_t @var{realdim}) @deftypefunx ap_environment_t* ap_environment_remove (ap_environment_t* @var{env}, ap_var_t* @var{tvar}, size_t @var{size}) Resp. add or remove new variables to an existing environment, with a functional semantics. Same conventions as for @code{ap_environment_alloc} function apply. If the result is non-sense (or in case of attempt to remove an unknwon variable), return @code{NULL}. @end deftypefun @deftypefun ap_dim_t ap_environment_dim_of_var (ap_environment_t* @var{env}, ap_var_t @var{var}) Convert a variable in its corresponding dimension in the environment @var{env}. If @var{var} is unknown in @var{env}, return @code{AP_DIM_MAX}. @end deftypefun @deftypefun ap_dim_t ap_environment_var_of_dim (ap_environment_t* @var{env}, ap_dim_t @var{dim}) Return the variable associated to the dimension @var{dim} in the environment @var{env}. There is no bound check here. @end deftypefun The remaining functions are much less useful for normal user. @deftypefun bool ap_environment_is_eq (ap_environment_t* @var{env1}, ap_environment_t* @var{env2}) @deftypefunx bool ap_environment_is_leq (ap_environment_t* @var{env1}, ap_environment_t* @var{env2}) Resp. test the equality and the inclusion of two environments. @end deftypefun @deftypefun int ap_environment_compare (ap_environment_t* @var{env1}, ap_environment_t* @var{env2}) Return: @table @code @item -2 if the environments are not compatible (a variable has a different type in the 2 environments); @item -1 if @var{env1} is a subset of (included in) @var{env2}; @item 0 if they are equal; @item +1 if @var{env1} is a superset of @var{env2}; @item +2 otherwise: the least common environment exists and is a strict superset of both environments. @end table @end deftypefun @deftypefun int ap_environment_hash (ap_environment_t* @var{env}) Return an hash code for an environment. @end deftypefun @deftypefun ap_dimchange_t* ap_environment_dimchange (ap_environment_t* @var{env1}, ap_environment_t* @var{env}) Compute the transformation for converting from an environment @var{env1} to a superenvironment @var{env}. Return NULL if @var{env} is not a superenvironment. @end deftypefun @deftypefun ap_dimchange2_t* ap_environment_dimchange2 (ap_environment_t* @var{env1}, ap_environment_t* @var{env2}) Compute the transformation for switching from an environment @var{env1} to an @var{env2}, by first adding (some) variables of @var{env2}, and then removing (some) variables of @var{env1}. Return NULL if @var{env1} and @var{env2} ar enot compatible environments. @end deftypefun @deftypefun ap_environment_t* ap_environment_lce (ap_environment_t* @var{env1}, ap_environment_t* @var{env2}, ap_dimchange_t** @var{dimchange1}, ap_dimchange_t** @var{dimchange2}) Least common environment to two enviroenments. @itemize @item Assume @code{ap_environment_is_eq(env1,env2)==false} @item If environments are not compatible (a variable has different types in the 2 environments), return NULL @item Compute also in @var{dimchange1} and @var{dimchange2} the conversion transformations to the lce. @item If no dimensions to add to @var{env1}, this implies that @var{env} is actually @var{env1}. In this case, @code{*dimchange1==NULL}. Otherwise, the function allocates the @code{*dimchange1} with @code{ap_dimchange_alloc}. @end itemize @end deftypefun @deftypefun ap_environment_t* ap_environment_lce_array (ap_environment_t** @var{tenv}, size_t @var{size}, ap_dimchange_t*** @var{ptdimchange}) Least common environment to an array of environments. @itemize @item Assume the size @var{size} of the array @var{tenv} is at least one; @item If all input environments are the same, @code{*ptdimchange==NULL}. Otherwise, compute in @code{*ptdimchange} the conversion permutations @item If no dimensions to add to @code{tenv[i]}, this implies that the result is actually @code{tenv[i]}. In this case, @code{(*ptdimchange)[i]==NULL}. Otherwise, the function allocates the @code{(*ptdimchange)[i]} with @code{ap_dimchange_alloc}. @end itemize @end deftypefun @deftypefun ap_environment_t* ap_environment_rename (ap_environment_t* @var{env}, ap_var_t* @var{tvar1}, ap_var_t* @var{tvar2}, size_t @var{size}, ap_dimperm_t* @var{perm}) Rename the variables in the environment. @var{size} is the common size of arrays @var{tvar1} and @var{tvar2}, and @var{perm} is a result-parameter pointing to an @emph{existing but not initialized} object of type @code{ap_dimperm_t}. The function applies the variable substitution @code{tvar1[i]->tvar2[i]} to the environment, and returns the resulting environment and the allocated transformation permutation in @code{*perm}. If the parameters are not valid, return @code{NULL} with @code{perm->dim==NULL}. @end deftypefun @c =================================================================== @node Linear expressions of level 1, Linear constraints of level 1, Environments, Level 1 of the interface @section Linear expressions of level 1 (@file{ap_linexpr1.h}) @c =================================================================== We manipulate here expressions of the form @quotation @math{a_0.x_0 + ... + a_n.x_n + b} @end quotation where the coefficients @math{a_0, ..., a_n, b} are of @code{ap_coeff_t} type (either scalars or intervals) and the variables @math{x_0, ... , x_n} are of type @code{ap_var_t}. The semantics of linear expressions is exact, in the sense that the arithmetic operations are interpreted in the real (or rational) numbers. However, abstract domains are free to overapproximate this exact semantics (this may occur when converting rational scalars to @code{double} type for instance). A special remark concerns integer variables. Abstract domains are assumed to perform the operations involving linear expressions using a real/rational semantics, and then possibly to reduce the result using the knowledge that integer variables may only take integer values. @quotation This semantics @emph{coincides} with the natural integer semantics of expressions involving only integer variables @emph{only if} the involved coefficients are all integers. @end quotation @quotation A typical counter-example to this is an assignement @math{y := 1/3 x} where @math{x} and @math{y} are integer variables. If this assignement is applied to the @sc{Box} abstract domain value @math{x in [1;1]}, it may lead to the bottom value, because one will first obtain @math{y in [1/3;1/3]} by real/rational computations, and this may be reduced to the empty interval because @math{y} is integer and the interval contains no integer values. @end quotation If you need expressions with a less simple semantics (mixing integer, real/rational and floating-point semantics with casts), you should use tree expressions (@pxref{Tree expressions of level 1}). @deftp datatype ap_linexpr1_t (Internal) type of interval linear expressions. Linear expressions of level 1 are created as objects of type @code{ap_linexpr1_t}, not as pointers of type @code{ap_linexpr1_t*}. For information: @example typedef struct ap_linexpr1_t @{ ap_linexpr0_t* linexpr0; ap_environment_t* env; @} ap_linexpr1_t; @end example @end deftp @menu * Allocating linear expressions of level 1:: * Tests on linear expressions of level 1:: * Access to linear expressions of level 1:: * Change of dimensions and permutations of linear expressions of level 1:: @end menu @c ------------------------------------------------------------------- @node Allocating linear expressions of level 1, Tests on linear expressions of level 1, Linear expressions of level 1, Linear expressions of level 1 @subsection Allocating linear expressions of level 1 @c ------------------------------------------------------------------- @deftypefun ap_linexpr1_t ap_linexpr1_make (ap_environment_t* @var{env}, ap_linexpr_discr_t @var{lin_discr}, size_t @var{size}) Build a linear expressions on the environment @var{env}, with by default coefficients of type SCALAR and DOUBLE. If @var{lin_discr} selects a dense representation, the size of the expression is the size of the environment. Otherwise, the initial size is given by @var{size} and the expression may be resized lazily. @end deftypefun @deftypefun void ap_linexpr1_minimize (ap_linexpr1_t* @var{expr}) Reduce the coefficients (transform intervals into scalars when possible). In case of sparse representation, also remove zero coefficients. @end deftypefun @deftypefun ap_linexpr1_t ap_linexpr1_copy (ap_linexpr1_t* @var{expr}) Duplication. @end deftypefun @deftypefun void ap_linexpr1_clear (ap_linexpr1_t @var{expr}) Clear the linear expression. @end deftypefun @deftypefun void ap_linexpr1_fprint (FILE* @var{stream}, ap_linexpr1_t* @var{expr}) Print the linear expression on stream @var{stream}. @end deftypefun @c ------------------------------------------------------------------- @node Tests on linear expressions of level 1, Access to linear expressions of level 1, Allocating linear expressions of level 1, Linear expressions of level 1 @subsection Tests on linear expressions of level 1 @c ------------------------------------------------------------------- @deftypefun bool ap_linexpr1_is_integer (ap_linexpr1_t* @var{expr}) Does the expression depends only on integer variables ? @end deftypefun @deftypefun bool ap_linexpr1_is_real (ap_linexpr1_t* @var{expr}) Does the expression depends only on real variables ? @end deftypefun @deftypefun bool ap_linexpr1_is_linear (ap_linexpr1_t* @var{expr}) Return true iff all involved coefficients are scalars. @end deftypefun @deftypefun bool ap_linexpr1_is_quasilinear (ap_linexpr1_t* @var{expr}) Return true iff all involved coefficients but the constant are scalars. @end deftypefun @c ------------------------------------------------------------------- @node Access to linear expressions of level 1, Change of dimensions and permutations of linear expressions of level 1, Tests on linear expressions of level 1, Linear expressions of level 1 @subsection Access to linear expressions of level 1 @c ------------------------------------------------------------------- @deftypefun ap_environment_t* ap_linexpr1_envref (ap_linexpr1_t* @var{expr}) Get a reference to the underlying environment. Do not free it. @end deftypefun @deftypefun size_t ap_linexpr1_linexpr0ref (ap_linexpr1_t* @var{expr}) Get a reference to the underlying linear expression of level 0. Do not free it. @end deftypefun @c ------------------------------------------------------------------- @subsubsection Getting references @deftypefun ap_coefft* ap_linexpr1_cstref (ap_linexpr1_t* @var{e}) Get a reference to the constant. Do not free it. @end deftypefun @deftypefun ap_coefft* ap_linexpr1_coeffref (ap_linexpr1_t* @var{e}, ap_var_t @var{var}) Get a reference to the coefficient associated to the variable @var{var} in expression @var{e}. Do not free it. In case of sparse representation, possibly induce the addition of a new linear term. Return NULL if @var{var} is unknown in the environment of @var{e}. @end deftypefun @c ------------------------------------------------------------------- @subsubsection Getting values @deftypefun void ap_linexpr1_get_cst (ap_coefft* @var{coeff}, ap_linexpr1_t* @var{e}) Assign to @var{coeff} the constant coefficient of @var{e}. @end deftypefun @deftypefun bool ap_linexpr1_get_coeff (ap_coefft* @var{coeff}, ap_linexpr1_t* @var{e}, ap_var_t @var{var}) Assign to @var{coeff} the coefficient of variable @var{var} in the expression @var{e}. Return true in case @code{ap_linexpr1_coeffref(e,dim)} returns NULL. @end deftypefun @defmac ap_linexpr1_ForeachLinterm (ap_linexpr1_t* @var{e}, size_t @var{i}, ap_ap_var_t @var{var}, ap_coeff_t* @var{coeff}) Iterator on the coefficients associated to variables. @code{ap_linexpr1_ForeachLinterm(E,I,VAR,COEFF)@{ body @}} executes the body for each pair (@var{coeff},@var{var}) in the expression @var{e}. @var{coeff} is a reference to the coefficient associated to variable @var{var} in @var{e}. @var{i} is an auxiliary variable used internally by the macro. @end defmac @c ------------------------------------------------------------------- @subsubsection Assigning values with a list of arguments @deftypefun bool ap_linexpr1_set_list (ap_linexpr1_t* @var{e}, ...) This function assign the linear expression @var{e} from a list of tags of type @code{ap_coefftag_t}, each followed by a number of arguments as specified in the definition of the type @code{ap_coefftag_t} (@pxref{Access to linear expressions of level 0}). The list should end with the tag @code{AP_COEFF_END}. The only difference with level 0 is that variables replace dimensions in the list. Return @code{true} in case @code{ap_linexpr1_coeffref (e,dim)} returns NULL for one of the variables involved. Here is a typical example, in the case where @code{ap_var_t} is actually @code{char*} (the default): @example ap_linexpr1_set_list(e, AP_COEFF_S_INT, 3, "x", AP_COEFF_S_FRAC, 3,2, "y", AP_COEFF_S_DOUBLE, 4.1, "z", AP_CST_I_DOUBLE, -2.4, 3.6, AP_END); /* Do not forget the last tatg ! */ @end example which transforms an null expression into @code{3 x + 3/2 y + 4.1 z + [-2.4,3.6]} and is equivalent to: @example ap_linexpr1_set_coeff_scalar_int(e, "x", 3); ap_linexpr1_set_coeff_scalar_frac(e, "y", 3,2); ap_linexpr1_set_coeff_scalar_double(e, "z", 4.1); ap_linexpr1_set_cst_interval_double(e, -2.4, 3.6); @end example @end deftypefun @c ------------------------------------------------------------------- @subsubsection Assigning values @deftypefun void ap_linexpr1_set_cst (ap_linexpr1_t* @var{e}, ap_coefft* @var{coeff}) @deftypefunx void ap_linexpr1_set_cst_scalar (ap_linexpr1_t* @var{e}, ap_scalar_t* @var{scalar}) @deftypefunx void ap_linexpr1_set_cst_scalar_int (ap_linexpr1_t* @var{e}, int @var{num}) @deftypefunx void ap_linexpr1_set_cst_scalar_frac (ap_linexpr1_t* @var{e}, int @var{num}, unsigned int @var{den}) @deftypefunx void ap_linexpr1_set_cst_scalar_double (ap_linexpr1_t* @var{e}, double @var{num}) @deftypefunx void ap_linexpr1_set_cst_interval (ap_linexpr1_t* @var{e}, ap_interval_t* @var{itv}) @deftypefunx void ap_linexpr1_set_cst_interval_scalar (ap_linexpr1_t* @var{e}, ap_scalar_t* @var{inf}, ap_scalar_t* @var{sup}) @deftypefunx void ap_linexpr1_set_cst_interval_int (ap_linexpr1_t* @var{e}, int @var{inf}, int @var{sup}) @deftypefunx void ap_linexpr1_set_cst_interval_frac (ap_linexpr1_t* @var{e}, int @var{numinf}, unsigned int @var{deninf}, int @var{numsup}, unsigned int @var{densup}) @deftypefunx void ap_linexpr1_set_cst_interval_double (ap_linexpr1_t* @var{e}, double @var{inf}, double @var{sup}) Set the constant coefficient of expression @var{e}. @end deftypefun @deftypefun bool ap_linexpr1_set_coeff (ap_linexpr1_t* @var{e}, ap_var_t @var{var}, ap_coefft* @var{coeff}) @deftypefunx bool ap_linexpr1_set_coeff_scalar (ap_linexpr1_t* @var{e}, ap_var_t @var{var}, ap_scalar_t* @var{scalar}) @deftypefunx bool ap_linexpr1_set_coeff_scalar_int (ap_linexpr1_t* @var{e}, ap_var_t @var{var}, int @var{num}) @deftypefunx bool ap_linexpr1_set_coeff_scalar_frac (ap_linexpr1_t* @var{e}, ap_var_t @var{var}, int @var{num}, unsigned int @var{den}) @deftypefunx bool ap_linexpr1_set_coeff_scalar_double (ap_linexpr1_t* @var{e}, ap_var_t @var{var}, double @var{num}) @deftypefunx bool ap_linexpr1_set_coeff_interval (ap_linexpr1_t* @var{e}, ap_var_t @var{var}, ap_interval_t* @var{itv}) @deftypefunx bool ap_linexpr1_set_coeff_interval_scalar (ap_linexpr1_t* @var{e}, ap_var_t @var{var}, ap_scalar_t* @var{inf}, ap_scalar_t* @var{sup}) @deftypefunx bool ap_linexpr1_set_coeff_interval_int (ap_linexpr1_t* @var{e}, ap_var_t @var{var}, int @var{inf}, int @var{sup}) @deftypefunx bool ap_linexpr1_set_coeff_interval_frac (ap_linexpr1_t* @var{e}, ap_var_t @var{var},int @var{numinf}, unsigned int @var{deninf}, int @var{numsup}, unsigned int @var{densup}) @deftypefunx void ap_linexpr1_set_coeff_interval_double (ap_linexpr1_t* @var{e}, ap_var_t @var{var}, double @var{inf}, double @var{sup}) Set the coefficient of the variable @var{var} of expression @var{e}. Return @code{true} in case @code{ap_linexpr1_coeffref(e,var)} returns NULL. @end deftypefun @c ------------------------------------------------------------------- @node Change of dimensions and permutations of linear expressions of level 1, , Access to linear expressions of level 1, Linear expressions of level 1 @subsection Change of dimensions and permutations of linear expressions of level 1 @c ------------------------------------------------------------------- @deftypefun bool ap_linexpr1_extend_environment (ap_linexpr1_t* @var{nexpr}, ap_linexpr1_t* @var{expr}, ap_environment_t* @var{nenv}) @deftypefunx bool ap_linexpr1_extend_environment_with (ap_linexpr1_t* @var{expr}, ap_environment_t* @var{nenv}) Change the current environment of the expression @var{expr} with a super-environment @var{nenv}. Return @code{true} if @var{nenv} is not a superenvironment. The first version store the result in the uninitialized @code{*nexpr}, the second one updates in-place its argument. @end deftypefun @c =================================================================== @node Linear constraints of level 1, Generators of level 1, Linear expressions of level 1, Level 1 of the interface @section Linear constraints of level 1 (@file{ap_lincons1.h}) @c =================================================================== @deftp datatype ap_lincons1_t Datatype for constraints. For information: @example typedef struct ap_lincons1_t @{ ap_lincons0_t lincons0; ap_environment_t* env; @} ap_lincons1_t; @end example Constraints are meant to be manipulated freely via their components. Creating the constraint @code{[1,2]x + 5/2 y >=0} and then freeing it can be done with @example ap_lincons1_t cons = ap_lincons1_make(AP_CONS_SUPEQ, ap_linexpr1_alloc(env,AP_LINEXPR_SPARSE,2), NULL); ap_lincons1_set_list(&cons, AP_COEFF_I_INT, 1,2, "x", AP_COEFF_S_FRAC, 5,2, "y", AP_END); ap_lincons1_clear(&cons); @end example @end deftp @deftp datatype ap_lincons1_array_t @example typedef struct ap_lincons1_array_t @{ ap_lincons0_array_t lincons0_array; ap_environment_t* env; @} ap_lincons1_array_t; @end example Datatype for arrays of constraints. Arrays at level 1 cannot be accessed directly, for example by writing @code{array->p[i]}, but should instead be accessed with functions @code{ap_lincons1_array_get} and @code{ap_lincons1_array_set}. @end deftp @menu * Allocating linear constraints of level 1:: * Tests on linear constraints of level 1:: * Access to linear constraints of level 1:: * Change of dimensions and permutations of linear constraints of level 1:: * Arrays of linear constraints of level 1:: @end menu @c ------------------------------------------------------------------- @node Allocating linear constraints of level 1, Tests on linear constraints of level 1, Linear constraints of level 1, Linear constraints of level 1 @subsection Allocating linear constraints of level 1 @c ------------------------------------------------------------------- @deftypefun ap_lincons1_t ap_lincons1_make (ap_constyp_t @var{constyp}, ap_linexpr1_t* @var{linexpr}, ap_scalar_t* mod) Create a constraint of type @var{constyp} with the expression @var{linexpr}, and the modulo @var{mod} in case of a congruence constraint (@code{constyp==AP_CONS_EQMOD}). The expression is not duplicated, just pointed to, so it becomes managed via the constraint. @end deftypefun @deftypefun ap_lincons1_t ap_lincons1_make_unsat (ap_environment_t* @var{env}) Create the constraint @code{-1>=0}. @end deftypefun @deftypefun ap_lincons1_t ap_lincons1_copy (ap_lincons1_t* @var{cons}) Duplication @end deftypefun @deftypefun void ap_lincons1_clear (ap_lincons1_t* @var{cons}) Clear the constraint and set pointers to NULL. @end deftypefun @deftypefun void ap_lincons1_fprint (FILE* @var{stream}, ap_lincons1_t* @var{cons}); Print the linear constraint on stream @var{stream}. @end deftypefun @c ------------------------------------------------------------------- @node Tests on linear constraints of level 1, Access to linear constraints of level 1, Allocating linear constraints of level 1, Linear constraints of level 1 @subsection Tests on linear constraints of level 1 @c ------------------------------------------------------------------- @deftypefun bool ap_lincons1_is_unsat (ap_lincons1_t* @var{cons}) Return @code{true} if the constraint is not satisfiable (@code{b>=0} or @code{[a,b]>=0} with b negative). @end deftypefun @c ------------------------------------------------------------------- @node Access to linear constraints of level 1, Change of dimensions and permutations of linear constraints of level 1, Tests on linear constraints of level 1, Linear constraints of level 1 @subsection Access to linear constraints of level 1 @c ------------------------------------------------------------------- @deftypefun ap_environment_t* ap_lincons1_envref (ap_lincons1_t* @var{cons}) Get a reference to the environment. Do not free it. @end deftypefun @deftypefun ap_constyp_t* ap_lincons1_constypref (ap_lincons1_t* @var{cons}) Get a reference to the type of constraint. You may use the reference to modify the constraint type. @end deftypefun @deftypefun ap_linexpr1_t ap_lincons1_linexpr1ref (ap_lincons1_t* @var{cons}) Get a reference to the underlying expression of the constraint. Do not free it: nothing is duplicated. Modifying the argument or the result is equivalent, except for change of dimensions/environment. @end deftypefun @deftypefun void ap_lincons1_get_cst (ap_coeff_t* @var{coeff}, ap_lincons1_t* @var{cons}) @deftypefunx void ap_lincons1_set_cst (ap_lincons1_t* @var{cons}, ap_coeff_t* cst) @deftypefunx bool ap_lincons1_get_coeff (ap_coeff_t* @var{coeff}, ap_lincons1_t* cons, ap_var_t @var{var}) @deftypefunx bool ap_lincons1_set_coeff (ap_lincons1_t* @var{cons}, ap_var_t @var{var}, ap_coeff_t* @var{coeff}) @deftypefunx bool ap_lincons1_set_list (ap_lincons1_t* @var{cons}, ...) @deftypefunx ap_coeff_t* ap_lincons1_cstref (ap_lincons1_t* @var{cons}) @deftypefunx ap_coeff_t* ap_lincons1_coeffref (ap_lincons1_t* @var{cons}, ap_var_t @var{var}) Identical to corresponding @code{ap_linexpr1_XXX} functions (@pxref{Access to linear expressions of level 1}). @end deftypefun @deftypefun ap_lincons0_t* ap_lincons1_lincons0ref (ap_lincons1_t* @var{cons}) Return underlying constraint of level 0. Do not free it: nothing is duplicated. Modifying the argument or the result is equivalent, except for change of dimensions/envionment. @end deftypefun @c ------------------------------------------------------------------- @node Change of dimensions and permutations of linear constraints of level 1, Arrays of linear constraints of level 1, Access to linear constraints of level 1, Linear constraints of level 1 @subsection Change of dimensions and permutations of linear constraints of level 1 @c ------------------------------------------------------------------- @deftypefun bool ap_lincons1_extend_environment (ap_lincons1_t* @var{ncons}, ap_lincons1_t* @var{cons}, ap_environment_t* @var{nenv}) @deftypefunx bool ap_lincons1_extend_environment_with (ap_lincons1_t* @var{cons}, ap_environment_t* @var{nenv}) Identical to corresponding @code{ap_linexpr1_XXX} functions (@pxref{Change of dimensions and permutations of linear expressions of level 1}). @end deftypefun @c ------------------------------------------------------------------- @node Arrays of linear constraints of level 1, , Change of dimensions and permutations of linear constraints of level 1, Linear constraints of level 1 @subsection Arrays of linear constraints of level 1 @c ------------------------------------------------------------------- @deftypefun ap_lincons1_array_t ap_lincons1_array_make (ap_environment_t* @var{env}, size_t @var{size}) Allocate an array of constraints of size @var{size}, defined on the environment @var{env}. The constraints are initialized with NULL pointers for underlying expressions. @end deftypefun @deftypefun void ap_lincons1_array_clear (ap_lincons1_array_t* @var{array}) Clear the constraints of the array, and then the array itself. @end deftypefun @deftypefun void ap_lincons1_array_fprint (FILE* @var{stream}, ap_lincons1_array_t* @var{array}) Print the array on the stream. @end deftypefun @deftypefun size_t ap_lincons1_array_size (ap_lincons1_array_t* @var{array}) Return the size of the array. @end deftypefun @deftypefun ap_environment_t* ap_lincons1_array_envref (ap_lincons1_array_t* @var{array}) Get a reference to the environment. Do not free it. @end deftypefun @deftypefun ap_lincons1_t ap_lincons1_array_get (ap_lincons1_array_t* @var{array}, size_t @var{index}) Return the linear constraint of the given index. Nothing is duplicated, and the result should never be cleared. Modifying the argument or the result is equivalent, except for change of environments @end deftypefun @deftypefun bool ap_lincons1_array_set (ap_lincons1_array_t* @var{array}, size_t @var{index}, ap_lincons1_t* @var{cons}) Fill the index of the array with the constraint. Assumes @code{ap_environment_is_eq(array->env,cons->env)}. Nothing is duplicated. The argument should never be cleared (its environment is dereferenced). If a constraint was already stored, it is first cleared. Return true iff problem (index or @code{array->env!=cons->env}) @end deftypefun @deftypefun void ap_lincons1_array_clear_index (ap_lincons1_array_t* @var{array}, size_t @var{index}) Clear the constraint at index index. @end deftypefun @deftypefun bool ap_lincons1_array_extend_environment_with (ap_lincons1_array_t* @var{array}, ap_environment_t* @var{nenv}) @deftypefunx bool ap_lincons1_array_extend_environment (ap_lincons1_array_t* narray, ap_lincons1_array_t* @var{array}, ap_environment_t* @var{nenv}) Identical to corresponding @code{ap_linexpr1_XXX} functions (@pxref{Change of dimensions and permutations of linear expressions of level 1}). @end deftypefun @c =================================================================== @node Generators of level 1, Tree expressions of level 1, Linear constraints of level 1, Level 1 of the interface @section generators of level 1 (@file{ap_generator1.h}) @c =================================================================== @deftp datatype ap_generator1_t Datatype for generators. For information: @example typedef struct ap_generator1_t @{ ap_generator0_t generator0; ap_environment_t* env; @} ap_generator1_t; @end example Generators are meant to be manipulated freely via their components. Creating the ray generator @code{x+2/3y} and then freeing it can be done with @example ap_generator1_t gen = ap_generator1_make(AP_GEN_RAY, ap_linexpr1_alloc(env,AP_LINEXPR_SPARSE,2)); ap_generator1_set_list(&gen, AP_COEFF_S_INT, 1, "x", AP_COEFF_S_FRAC, 2,3, "y", AP_END); ap_generator1_clear(&gen); @end example @end deftp @deftp datatype ap_generator1_array_t @example typedef struct ap_generator1_array_t @{ ap_generator0_array_t generator0_array; ap_environment_t* env; @} ap_generator1_array_t; @end example Datatype for arrays of generators. Arrays at level 1 cannot be accessed directly, for example by writing @code{array->p[i]}, but should instead be accessed with functions @code{ap_generator1_array_get} and @code{ap_generator1_array_set}. @end deftp @menu * Allocating generators of level 1:: * Access to generators of level 1:: * Change of dimensions and permutations of generators of level 1:: * Arrays of generators of level 1:: @end menu @c ------------------------------------------------------------------- @node Allocating generators of level 1, Access to generators of level 1, Generators of level 1, Generators of level 1 @subsection Allocating generators of level 1 @c ------------------------------------------------------------------- @deftypefun ap_generator1_t ap_generator1_make (ap_gentyp_t @var{gentyp}, ap_linexpr1_t* @var{linexpr}) Create a generator of type @var{gentyp} with the expression @var{linexpr}. The expression is not duplicated, just pointed to, so it becomes managed via the generator. @end deftypefun @deftypefun ap_generator1_t ap_generator1_copy (ap_generator1_t* @var{gen}) Duplication @end deftypefun @deftypefun void ap_generator1_clear (ap_generator1_t* @var{gen}) Clear the generator and set pointers to NULL. @end deftypefun @deftypefun void ap_generator1_fprint (FILE* @var{stream}, ap_generator1_t* @var{gen}); Print the linear generator on stream @var{stream}. @end deftypefun @c ------------------------------------------------------------------- @node Access to generators of level 1, Change of dimensions and permutations of generators of level 1, Allocating generators of level 1, Generators of level 1 @subsection Access to generators of level 1 @c ------------------------------------------------------------------- @deftypefun ap_environment_t* ap_generator1_envref (ap_generator1_t* @var{gen}) Get a reference to the environment. Do not free it. @end deftypefun @deftypefun ap_gentyp_t* ap_generator1_gentypref (ap_generator1_t* @var{gen}) Get a reference to the type of generator. You may use the reference to modify the generator type. @end deftypefun @deftypefun ap_linexpr1_t ap_generator1_linexpr1ref (ap_generator1_t* @var{gen}) Get a reference to the underlying expression of the generator. Do not free it: nothing is duplicated. Modifying the argument or the result is equivalent, except for change of dimensions/environment. @end deftypefun @deftypefun void ap_generator1_get_cst (ap_coeff_t* @var{coeff}, ap_generator1_t* @var{gen}) @deftypefunx void ap_generator1_set_cst (ap_generator1_t* @var{gen}, ap_coeff_t* cst) @deftypefunx bool ap_generator1_get_coeff (ap_coeff_t* @var{coeff}, ap_generator1_t* gen, ap_var_t @var{var}) @deftypefunx bool ap_generator1_set_coeff (ap_generator1_t* @var{gen}, ap_var_t @var{var}, ap_coeff_t* @var{coeff}) @deftypefunx bool ap_generator1_set_list (ap_generator1_t* @var{gen}, ...) @deftypefunx ap_coeff_t* ap_generator1_cstref (ap_generator1_t* @var{gen}) @deftypefunx ap_coeff_t* ap_generator1_coeffref (ap_generator1_t* @var{gen}, ap_var_t @var{var}) Identical to corresponding @code{ap_linexpr1_XXX} functions (@pxref{Access to linear expressions of level 1}). @end deftypefun @deftypefun ap_generator0_t* ap_generator1_generator0ref (ap_generator1_t* @var{gen}) Return underlying generator of level 0. Do not free it: nothing is duplicated. Modifying the argument or the result is equivalent, except for change of dimensions/envionment. @end deftypefun @c ------------------------------------------------------------------- @node Change of dimensions and permutations of generators of level 1, Arrays of generators of level 1, Access to generators of level 1, Generators of level 1 @subsection Change of dimensions and permutations of generators of level 1 @c ------------------------------------------------------------------- @deftypefun bool ap_generator1_extend_environment (ap_generator1_t* @var{ngen}, ap_generator1_t* @var{gen}, ap_environment_t* @var{nenv}) @deftypefunx bool ap_generator1_extend_environment_with (ap_generator1_t* @var{gen}, ap_environment_t* @var{nenv}) Identical to corresponding @code{ap_linexpr1_XXX} functions (@pxref{Change of dimensions and permutations of linear expressions of level 1}). @end deftypefun @c ------------------------------------------------------------------- @node Arrays of generators of level 1, , Change of dimensions and permutations of generators of level 1, Generators of level 1 @subsection Arrays of generators of level 1 @c ------------------------------------------------------------------- @deftypefun ap_generator1_array_t ap_generator1_array_make (ap_environment_t* @var{env}, size_t @var{size}) Allocate an array of generators of size @var{size}, defined on the environment @var{env}. The generators are initialized with NULL pointers for underlying expressions. @end deftypefun @deftypefun void ap_generator1_array_clear (ap_generator1_array_t* @var{array}) Clear the generators of the array, and then the array itself. @end deftypefun @deftypefun void ap_generator1_array_fprint (FILE* @var{stream}, ap_generator1_array_t* @var{array}) Print the array on the stream. @end deftypefun @deftypefun size_t ap_generator1_array_size (ap_generator1_array_t* @var{array}) Return the size of the array. @end deftypefun @deftypefun ap_environment_t* ap_generator1_array_envref (ap_generator1_array_t* @var{array}) Get a reference to the environment. Do not free it. @end deftypefun @deftypefun ap_generator1_t ap_generator1_array_get (ap_generator1_array_t* @var{array}, size_t @var{index}) Return the linear generator of the given index Nothing is duplicated, and the result should never be cleared. Modifying the argument or the result is equivalent, except for change of environments @end deftypefun @deftypefun bool ap_generator1_array_set (ap_generator1_array_t* @var{array}, size_t @var{index}, ap_generator1_t* @var{gen}) Fill the index of the array with the generator. Assumes @code{array->env==gen->env}. Nothing is duplicated. The argument should never be cleared. (its environment is dereferenced). If a generator was already stored, it is first cleared. Return true iff problem (index or @code{array->env!=gen->env}) @end deftypefun @deftypefun void ap_generator1_array_clear_index (ap_generator1_array_t* @var{array}, size_t @var{index}) Clear the generator at index index. @end deftypefun @deftypefun bool ap_generator1_array_extend_environment_with (ap_generator1_array_t* @var{array}, ap_environment_t* @var{nenv}) @deftypefunx bool ap_generator1_array_extend_environment (ap_generator1_array_t* narray, ap_generator1_array_t* @var{array}, ap_environment_t* @var{nenv}) Identical to corresponding @code{ap_linexpr1_XXX} functions (@pxref{Change of dimensions and permutations of linear expressions of level 1}). @end deftypefun @c =================================================================== @node Tree expressions of level 1, Tree constraints of level 1, Generators of level 1, Level 1 of the interface @section Tree expressions of level 1 (@file{ap_texpr1.h}) @c =================================================================== We manipulate here general expressions described by the grammar @quotation @math{expr ::= cst | var | unop e | e1 binop e2} @end quotation Such tree expressions generalize linear expressions(@pxref{Linear expressions of level 1}) in two ways: @itemize @item Non-linear operations are possible (multiplication, division, casts, ...) @item Semantics of operators is no longer restricted to real/rational semantics. Each operation is parameterized by two parameters: @itemize @item a rounding type parameter, which indicates the destination type of the operation, and influences how the rounding is performed; @item a rounding direction parameter, which defines the rounding mode. @end itemize @end itemize @menu * Datatypes for tree expressions of level 1:: * Constructors/Destructors for tree expressions of level 1:: * Tests on tree expressions of level 1:: * Operations on tree expressions of level 1:: @end menu @c ------------------------------------------------------------------- @node Datatypes for tree expressions of level 1, Constructors/Destructors for tree expressions of level 1, Tree expressions of level 1, Tree expressions of level 1 @subsection Datatypes for tree expressions of level 1 @c ------------------------------------------------------------------- @deftp datatype ap_texpr1_t Type of tree expressions. Tree expressions of level 1 are created as objects of type @code{ap_texpr1_t*}. They are manipulated in a functional way (except a few operations), unlike linear expressions on which most operations acts by side-effects. @end deftp @deftp datatype ap_texpr_op_t Operators (actually defined in @file{ap_texpr0.h}) @example typedef enum ap_texpr_op_t @{ /* Binary operators */ AP_TEXPR_ADD, AP_TEXPR_SUB, AP_TEXPR_MUL, AP_TEXPR_DIV, AP_TEXPR_MOD, /* either integer or real, no rounding */ /* Unary operators */ AP_TEXPR_NEG /* no rounding */, AP_TEXPR_CAST, AP_TEXPR_SQRT, @} ap_texpr_op_t; @end example @end deftp @deftp datatype ap_texpr_rtype_t Destination type of the operation for rounding (actually defined in @file{ap_texpr0.h}) @example typedef enum ap_texpr_rtype_t @{ AP_RTYPE_REAL, /* real (no rounding) */ AP_RTYPE_INT, /* integer */ AP_RTYPE_SINGLE, /* IEEE 754 32-bit single precision, e.g.: C's float */ AP_RTYPE_DOUBLE, /* IEEE 754 64-bit double precision, e.g.: C's double */ AP_RTYPE_EXTENDED, /* non-standard 80-bit double extended, e.g.: Intel's long double */ AP_RTYPE_QUAD, /* non-standard 128-bit quadruple precision, e.g.: Motorola's long double */ @} ap_texpr_rtype_t; @end example @end deftp @deftp datatype ap_texpr_rdir_t Rounding mode (actually defined in @file{ap_texpr0.h}) @example typedef enum ap_texpr_rdir_t @{ AP_RDIR_NEAREST /* Nearest */ AP_RDIR_ZERO /* Zero (truncation for integers) */ AP_RDIR_UP /* + Infinity */ AP_RDIR_DOWN /* - Infinity */ AP_RDIR_RND, /* All possible mode, non deterministically */ AP_RDIR_SIZE /* Not to be used ! */ @} ap_texpr_rdir_t; @end example @end deftp @c ------------------------------------------------------------------- @node Constructors/Destructors for tree expressions of level 1, Tests on tree expressions of level 1, Datatypes for tree expressions of level 1, Tree expressions of level 1 @subsection Constructors/Destructors for tree expressions of level 1 @c ------------------------------------------------------------------- Parameters of constructors are not memory-managed by the constructed expression, with the important exception of expressions parameters (type @code{ap_texpr1.h}) are, which means that they should not be freed afterwards. @deftypefun ap_texpr1_t* ap_texpr1_cst (ap_environment_t* @var{env}, ap_coeff_t* @var{coeff}) @deftypefunx ap_texpr1_t* ap_texpr1_cst_scalar (ap_environment_t* @var{env}, ap_scalar_t* @var{scalar}) @deftypefunx ap_texpr1_t* ap_texpr1_cst_scalar_mpq (ap_environment_t* @var{env}, mpq_t @var{mpq}) @deftypefunx ap_texpr1_t* ap_texpr1_cst_scalar_int (ap_environment_t* @var{env}, long int @var{num}) @deftypefunx ap_texpr1_t* ap_texpr1_cst_scalar_frac (ap_environment_t* @var{env}, long int @var{num}, unsigned long int @var{den}) @deftypefunx ap_texpr1_t* ap_texpr1_cst_scalar_double (ap_environment_t* @var{env}, double @var{num}) @deftypefunx ap_texpr1_t* ap_texpr1_cst_interval (ap_environment_t* @var{env}, ap_interval_t* @var{itv}) @deftypefunx ap_texpr1_t* ap_texpr1_cst_interval_scalar (ap_environment_t* @var{env}, ap_scalar_t* @var{inf}, ap_scalar_t* @var{sup}) @deftypefunx ap_texpr1_t* ap_texpr1_cst_interval_mpq (ap_environment_t* @var{env}, mpq_t @var{inf}, mpq_t @var{sup}) @deftypefunx ap_texpr1_t* ap_texpr1_cst_interval_int (ap_environment_t* @var{env}, long int @var{inf}, long int @var{sup}) @deftypefunx ap_texpr1_t* ap_texpr1_cst_interval_frac (ap_environment_t* @var{env}, long int @var{numinf}, unsigned long int @var{deninf}, long int @var{numsup}, unsigned long int @var{densup}) @deftypefunx ap_texpr1_t* ap_texpr1_cst_interval_double (ap_environment_t* @var{env}, double @var{inf}, double @var{sup}) @deftypefunx ap_texpr1_t* ap_texpr1_cst_top (ap_environment_t* @var{env}) Create a constant expression, on the environment @var{env}. @end deftypefun @deftypefun ap_texpr1_t* ap_texpr1_var (ap_environment_t* @var{env}, ap_var_t @var{var}) Create a variable expression. Return @code{NULL} in the case @var{var} is unknown in @var{env}. @end deftypefun @deftypefun ap_texpr1_t* ap_texpr1_unop (ap_texpr_op_t @var{op}, ap_texpr1_t* @var{opA}, ap_texpr_rtype_t @var{type}, ap_texpr_rdir_t @var{dir}) @deftypefunx ap_texpr1_t* ap_texpr1_binop (ap_texpr_op_t @var{op}, ap_texpr1_t* @var{opA}, ap_texpr1_t* @var{opB}, ap_texpr_rtype_t @var{type}, ap_texpr_rdir_t @var{dir}) Create an expression from an operator and expression operand(s). Be aware that @var{opA} and @var{opB} are memroy-managed by the result upon return. @end deftypefun @deftypefun ap_texpr1_t* ap_texpr1_copy (ap_texpr1_t* @var{expr}) (Deep) copy of a tree expression. @end deftypefun @deftypefun ap_texpr1_t* ap_texpr1_from_linexpr1 (ap_linexpr1_t* @var{linexpr}) Creation from a linear expression. @end deftypefun @deftypefun void ap_texpr1_free (ap_texpr1_t* @var{expr}) Free (recursively) a tree expression. @end deftypefun @deftypefun void ap_texpr1_fprint (FILE* @var{stream}, ap_texpr1_t* @var{e}) @deftypefunx void ap_texpr1_print (ap_texpr1_t* @var{e}) Print the expression @end deftypefun @c ------------------------------------------------------------------- @node Tests on tree expressions of level 1, Operations on tree expressions of level 1, Constructors/Destructors for tree expressions of level 1, Tree expressions of level 1 @subsection Tests on tree expressions of level 1 @c ------------------------------------------------------------------- @deftypefun bool ap_texpr1_equal (ap_texpr1_t* @var{e1}, ap_texpr1_t* @var{e2}) Structural (recursive) equality @end deftypefun @deftypefun bool ap_texpr1_has_var (ap_texpr1_t* @var{e}, ap_var_t @var{var}) Return true if variable @var{var} appears in the expression. @end deftypefun The next functions classifies tree expressions. @deftypefun bool ap_texpr1_is_interval_cst (ap_texpr1_t* @var{e}) No variable, only constant leaves @end deftypefun @deftypefun bool ap_texpr1_is_interval_linear (ap_texpr1_t* @var{e}) Linear with possibly interval coefficients, no rounding @end deftypefun @deftypefun bool ap_texpr1_is_interval_polynomial (ap_texpr1_t* @var{e}) Polynomial with possibly interval coefficients, no rounding @end deftypefun @deftypefun bool ap_texpr1_is_interval_polyfrac (ap_texpr1_t* @var{e}) Polynomial fraction with possibly interval coefficients, no rounding @end deftypefun @deftypefun bool ap_texpr1_is_scalar (ap_texpr1_t* @var{e}) All coefficients are scalar (non-interval)@end deftypefun @c ------------------------------------------------------------------- @node Operations on tree expressions of level 1, , Tests on tree expressions of level 1, Tree expressions of level 1 @subsection Operations on tree expressions of level 1 @c ------------------------------------------------------------------- @deftypefun ap_texpr1_t* ap_texpr1_substitute (ap_texpr1_t* @var{e}, ap_var_t @var{var}, ap_texpr1_t* @var{dst}) Substitute every occurence of variable var with a copy of dst. Return NULL in case of incorrect argument (w.r.t. var and/or environment compatibility). @end deftypefun @deftypefun ap_texpr1_t* ap_texpr1_extend_environment (ap_texpr1_t* @var{e}, ap_environment_t* @var{nenv}) Change current environment with a super-environment. Return NULL if @var{nenv} is not a superenvironment of @code{e->env}. @end deftypefun @deftypefun bool ap_texpr1_substitute_with (ap_texpr1_t* @var{e}, ap_var_t @var{var}, ap_texpr1_t* @var{dst}) @deftypefunx bool ap_texpr1_extend_environment_with (ap_texpr1_t* @var{e}, ap_environment_t* @var{nenv}) Side-effect versions of the previous functions. Return @code{true} instead of @code{NULL} in case of problem. @end deftypefun @c =================================================================== @node Tree constraints of level 1, Abstract values and operations of level 1, Tree expressions of level 1, Level 1 of the interface @section Tree constraints of level 1 (@file{ap_tcons1.h}) @c =================================================================== Tree constraints are constraints built on tree expressions. @menu * Datatypes for tree constraints of level 1:: * Constructors/Destructors for tree constraints of level 1:: * Operations on tree constraints of level 1:: * Arrays of tree constraints of level 1:: @end menu @c ------------------------------------------------------------------- @node Datatypes for tree constraints of level 1, Constructors/Destructors for tree constraints of level 1, Tree constraints of level 1, Tree constraints of level 1 @subsection Datatypes for tree constraints of level 1 @c ------------------------------------------------------------------- @deftp datatype ap_tcons1_t Datatype for constraints. For information: @example typedef struct ap_tcons1_t @{ ap_tcons0_t tcons0; ap_environment_t* env; @} ap_tcons1_t; @end example @end deftp @deftp datatype ap_tcons1_array_t @example typedef struct ap_tcons1_array_t @{ ap_tcons0_array_t tcons0_array; ap_environment_t* env; @} ap_tcons1_array_t; @end example Datatype for arrays of constraints. Arrays at level 1 cannot be accessed directly, for example by writing @code{array->p[i]}, but should instead be accessed with functions @code{ap_tcons1_array_get} and @code{ap_tcons1_array_set}. @end deftp @c ------------------------------------------------------------------- @node Constructors/Destructors for tree constraints of level 1, Operations on tree constraints of level 1, Datatypes for tree constraints of level 1, Tree constraints of level 1 @subsection Constructors/Destructors for tree constraints of level 1 @c ------------------------------------------------------------------- @deftypefun ap_tcons1_t ap_tcons1_make (ap_constyp_t @var{constyp}, ap_texpr1_t* @var{expr}, ap_scalar_t* @var{scalar}) Create a constraint of given type with the given expression. The expression and the optional coefficient are not duplicated, just pointed to. @end deftypefun @deftypefun ap_tcons1_t ap_tcons1_from_lincons1 (ap_tcons1_t* @var{cons}) Create a tree constraint from a linear constraint. @end deftypefun @deftypefun ap_tcons1_t ap_tcons1_copy (ap_tcons1_t* @var{cons}) Duplication. @end deftypefun @deftypefun void ap_tcons1_clear (ap_tcons1_t* @var{cons}) Clear the constraint and set pointers to NULL. @end deftypefun @deftypefun void ap_tcons1_fprint (FILE* @var{stream}, ap_tcons1_t* @var{cons}) @deftypefunx void ap_tcons1_print (ap_tcons1_t* @var{cons}) Printing @end deftypefun @deftypefun ap_environment_t* ap_tcons1_envref (ap_tcons1_t* @var{cons}) Get a reference to the environment. Do not free it. @end deftypefun @deftypefun ap_constyp_t* ap_tcons1_constypref (ap_tcons1_t* @var{cons}) Get a reference to the type of constraint. @end deftypefun @deftypefun ap_scalar_t* ap_tcons1_scalarref (ap_tcons1_t* @var{cons}) Get a reference to the auxiliary coefficient of the constraint. @end deftypefun @deftypefun ap_texpr1_t ap_tcons1_texpr1ref (ap_tcons1_t* @var{cons}) Get a reference to the underlying expression of the constraint. Do not free it: nothing is duplicated. Modifying the argument or the result is equivalent, except for change of dimensions/environment. @end deftypefun @deftypefun ap_tcons0_t* ap_tcons1_tcons0ref (ap_tcons1_t* @var{cons}) Return underlying constraint of level 0. Do not free it: nothing is duplicated. Modifying the argument or the result is equivalent, except for change of dimensions/envionment. @end deftypefun @c ------------------------------------------------------------------- @node Operations on tree constraints of level 1, Arrays of tree constraints of level 1, Constructors/Destructors for tree constraints of level 1, Tree constraints of level 1 @subsection Operations on tree constraints of level 1 @c ------------------------------------------------------------------- @deftypefun bool ap_tcons1_extend_environment (ap_tcons1_t* @var{ncons}, ap_tcons1_t* @var{cons}, ap_environment_t* @var{nenv}) @deftypefunx bool ap_tcons1_extend_environment_with (ap_tcons1_t* @var{cons}, ap_environment_t* @var{nenv}) Change current environment with a super-environment. Return @code{true} if @var{nenv} is not a superenvironment of @code{e->env}. @end deftypefun @c ------------------------------------------------------------------- @node Arrays of tree constraints of level 1, , Operations on tree constraints of level 1, Tree constraints of level 1 @subsection Arrays of tree constraints of level 1 @c ------------------------------------------------------------------- @deftypefun ap_tcons1_array_t ap_tcons1_array_make (ap_environment_t* @var{env}, size_t @var{size}) Allocate an array of size constraints. The constraints are initialized with NULL pointers, so that @code{ap_tcons1_array_free} may be safely called. @end deftypefun @deftypefun void ap_tcons1_array_clear (ap_tcons1_array_t* @var{array}) Clear the constraints of the array, and then the array itself. @end deftypefun @deftypefun void ap_tcons1_array_fprint (FILE* stream, ap_tcons1_array_t* @var{array}) @deftypefunx void ap_tcons1_array_print (ap_tcons1_array_t* @var{array}) Printing. @end deftypefun @deftypefun size_t ap_tcons1_array_size (ap_tcons1_array_t* @var{array}) Return the size of the array. @end deftypefun @deftypefun ap_environment_t* ap_tcons1_array_envref (ap_tcons1_array_t* @var{array}) Return a reference to the environment of the array. Do not free it. @end deftypefun @deftypefun void ap_tcons1_array_clear_index (ap_tcons1_array_t* @var{array}, size_t @var{index}) Clear the constraint at index index and set pointers to @code{NULL}. @end deftypefun @deftypefun ap_tcons1_t ap_tcons1_array_get (ap_tcons1_array_t* @var{array}, size_t @var{index}) Return the linear constraint of the given index Nothing is duplicated, and the result should never be cleared. Modifying the argument or the result is equivalent, except for change of environments. @end deftypefun @deftypefun bool ap_tcons1_array_set (ap_tcons1_array_t* @var{array}, size_t @var{index}, ap_tcons1_t* @var{cons}) Fill the index of the array with the constraint. Assumes @code{ap_environment_is_eq(array->env,cons->env)}. Nothing is duplicated. The argument should never be cleared (its environment is dereferenced). If a constraint was already stored, it is first cleared. Return @code{true} iff problem (index or @code{array->env!=cons->env}) @end deftypefun @deftypefun bool ap_tcons1_array_extend_environment_with (ap_tcons1_array_t* @var{array}, ap_environment_t* @var{nenv}) @deftypefunx bool ap_tcons1_array_extend_environment (ap_tcons1_array_t* narray, ap_tcons1_array_t* @var{array}, ap_environment_t* @var{nenv}) Change current environment with a super-environment. Return @code{true} if @var{nenv} is not a superenvironment of @code{array->env}. @end deftypefun @c =================================================================== @node Abstract values and operations of level 1, , Tree constraints of level 1, Level 1 of the interface @section Abstract values and operations of level 1 (@file{ap_abstract1.h}) @c =================================================================== @deftp datatype ap_abstract1_t Datatype for abstract values at level 1. For information: @example typedef struct ap_abstract1_t @{ ap_abstract0_t* abstract0; ap_environment_t* env; @} ap_abstract1_t; /* data structure invariant: ap_abstract0_integer_dimension(man,abstract0)== env->intdim && ap_abstract0_real_dimension(man,abstract0)== env->realdim */ @end example @end deftp @deftp datatype ap_box1_t @example typedef struct ap_box1_t @{ ap_interval_t** p; ap_environment_t* env; @} ap_box1_t; void ap_box1_fprint(FILE* stream, ap_box1_t* box); void ap_box1_clear(ap_box1_t* box); @end example @end deftp Most operations are offered in 2 versions: @emph{functional} or @emph{destructive} @xref{Abstract values and operations of level 0}. We remind the policy for redimensioning (@pxref{Level 1 of the interface}): @itemize @item For functions taking one abstract value and one expression (or constraint or generator, or array of ...), the environment of the expression should be a sub-environment of the environment of the abstract value. The environment of the result is the environment of the argument abstract value. @item For functions taking several abstract values, their environments should be the same. Otherwise, it is up to the user to move them to a common super-environment (@pxref{Environments}). @end itemize @menu * Allocating abstract values of level 1:: * Control of internal representation of abstract values of level 1:: * Printing abstract values of level 1:: * Serialization of abstract values of level 1:: Constructors, Accessors, Tests and Extraction of properties * Constructors for abstract values of level 1:: * Accessors for abstract values of level 1:: * Tests on abstract values of level 1:: * Extraction of properties of abstract values of level 1:: Operations * Meet and Join of abstract values of level 1:: * Assignements and Substitutions of abstract values of level 1:: * Existential quantification of abstract values of level 1:: * Change of environments of abstract values of level 1:: * Expansion and Folding of dimensions in abstract values of level 1:: * Widening of abstract values of level 1:: * Topological closure of abstract values of level 1:: Additional functions * Additional functions on abstract values of level 1:: @end menu @c ------------------------------------------------------------------- @node Allocating abstract values of level 1, Control of internal representation of abstract values of level 1, Abstract values and operations of level 1, Abstract values and operations of level 1 @subsection Allocating abstract values of level 1 @c ------------------------------------------------------------------- @deftypefun ap_abstract1_t ap_abstract1_copy (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}) Return a copy of @var{a}, on which destructive update does not affect @var{a}. @end deftypefun @deftypefun void ap_abstract1_clear (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}) Free all the memory used by @var{a}. @end deftypefun @deftypefun size_t ap_abstract1_size (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}) Return the abstract size of @var{a}. @end deftypefun @c ------------------------------------------------------------------- @node Control of internal representation of abstract values of level 1, Printing abstract values of level 1, Allocating abstract values of level 1, Abstract values and operations of level 1 @subsection Control of internal representation of abstract values of level 1 @c ------------------------------------------------------------------- @deftypefun void ap_abstract1_minimize (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}) Minimize the size of the representation of @var{a}. This may result in a later recomputation of internal information. @end deftypefun @deftypefun void ap_abstract1_canonicalize (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}) Put @var{a} in canonical form. (not yet clear definition). @end deftypefun @deftypefun int ap_abstract1_hash (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}) Return an hash value for @var{a}. Two abstract values in canonical from (according to @code{ap_abstract1_canonicalize}) and considered as equal by the function @code{ap_abstract1_is_eq} are given the same hash value. @end deftypefun @deftypefun void ap_abstract1_approximate (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}, int @var{algorithm}) Perform some transformation on @var{a}, guided by the field algorithm. The transformation may lose information. The argument @var{algorithm} overrides the field algorithm of the structure of type @code{ap_funopt_t} associated to @code{ap_abstract1_approximate}. @end deftypefun @c ------------------------------------------------------------------- @node Printing abstract values of level 1, Serialization of abstract values of level 1, Control of internal representation of abstract values of level 1, Abstract values and operations of level 1 @subsection Printing abstract values of level 1 @c ------------------------------------------------------------------- @deftypefun void ap_abstract1_fprint (FILE* @var{stream}, ap_manager_t* @var{man}, ap_abstract1_t* @var{a}) Print @var{a} in a pretty way on the stream. @end deftypefun @deftypefun void ap_abstract1_fprintdiff (FILE* @var{stream}, ap_manager_t* @var{man}, ap_abstract1_t* @var{a1}, ap_abstract1_t* @var{a2}) Print the difference between @var{a1} (old value) and @var{a2} (new value). The meaning of difference is library dependent. @end deftypefun @deftypefun void ap_abstract1_fdump (FILE* @var{stream}, ap_manager_t* @var{man}, ap_abstract1_t* @var{a}) Dump the internal representation of @var{a} for debugging purposes. @end deftypefun @c ------------------------------------------------------------------- @node Serialization of abstract values of level 1, Constructors for abstract values of level 1, Printing abstract values of level 1, Abstract values and operations of level 1 @subsection Serialization of abstract values of level 1 @c ------------------------------------------------------------------- @deftypefun ap_membuf_t ap_abstract1_serialize_raw (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}) Allocate a memory buffer (with @code{malloc}), output @var{a} in raw binary format to it and return a pointer on the memory buffer and the number of bytes written. It is the user responsability to free the memory afterwards (with @code{free}). @end deftypefun @deftypefun ap_abstract1_t ap_abstract1_deserialize_raw (ap_manager_t* @var{man}, void* @var{ptr}, size_t* @var{size}) Return the abstract value read in raw binary format from the buffer pointed by @var{ptr} and store in size the number of bytes read. @end deftypefun @c ------------------------------------------------------------------- @node Constructors for abstract values of level 1, Accessors for abstract values of level 1, Serialization of abstract values of level 1, Abstract values and operations of level 1 @subsection Constructors for abstract values of level 1 @c ------------------------------------------------------------------- @deftypefun ap_abstract1_t ap_abstract1_bottom (ap_manager_t* @var{man}, ap_environment_t* @var{env}) @deftypefunx ap_abstract1_t ap_abstract1_top (ap_manager_t* @var{man}, ap_environment_t* @var{env}) Create resp. a bottom (empty) value and a top (universe) value defined on the environment @var{env}. @end deftypefun @deftypefun ap_abstract1_t ap_abstract1_of_box (ap_manager_t* @var{man}, ap_environment_t* @var{env}, ap_var_t* @var{tvar}, ap_interval_t** @var{tinterval}, size_t @var{size}) Abstract an hypercube defined by the arrays @var{tvar} and @var{tintnerval} of size @var{size}. If no inclusion is specified for a variable in the environment, its value is no constrained in the resulting abstract value. @end deftypefun @c ------------------------------------------------------------------- @node Accessors for abstract values of level 1, Tests on abstract values of level 1, Constructors for abstract values of level 1, Abstract values and operations of level 1 @subsection Accessors for abstract values of level 1 @c ------------------------------------------------------------------- @deftypefun ap_dimension_t ap_abstract1_environment (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}) Get a reference to the environment of @var{a}. Do not free it. @end deftypefun @deftypefun ap_manager_t* ap_abstract1_manager (ap_abstract1_t* @var{a}) Get a reference to the manager contained in @var{a}. Do not free it. @end deftypefun @deftypefun ap_dimension_t ap_abstract1_abstract0 (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}) Get a reference to the underlying abstract value of level 0 in @var{a}. Do not free it. @end deftypefun @c ------------------------------------------------------------------- @node Tests on abstract values of level 1, Extraction of properties of abstract values of level 1, Accessors for abstract values of level 1, Abstract values and operations of level 1 @subsection Tests on abstract values of level 1 @c ------------------------------------------------------------------- In abstract tests, @itemize @item true means that the predicate is certainly true; @item false means false @emph{or} don't know (an exception has occurred, or the exact computation was considered too expensive to be performed, according to the options). @end itemize @deftypefun bool ap_abstract1_is_bottom (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}) @deftypefunx bool ap_abstract1_is_top (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}) Emtpiness and universality tests. @end deftypefun @deftypefun bool ap_abstract1_is_leq (ap_manager_t* @var{man}, ap_abstract1_t* @var{a1}, ap_abstract1_t* @var{a2}) @deftypefunx bool ap_abstract1_is_eq (ap_manager_t* @var{man}, ap_abstract1_t* @var{a1}, ap_abstract1_t* @var{a2}) Inclusion and equality tests. @end deftypefun @deftypefun bool ap_abstract1_sat_interval (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}, ap_var_t @var{var}, ap_interval_t* @var{interval}) Is the variable @var{var} included in the interval @var{interval} in the abstract value @var{a} ? @end deftypefun @deftypefun bool ap_abstract1_sat_lincons (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}, ap_lincons1_t* @var{cons}) @deftypefunx bool ap_abstract1_sat_tcons (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}, ap_tcons1_t* @var{cons}) Does the abstract value @var{a} satisfy the constraint @var{cons} ? @end deftypefun @deftypefun bool ap_abstract1_is_variable_unconstrained (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}, ap_var_t @var{var}) Is the dimension @var{dim} unconstrained in the abstract value @var{a} ? If it is the case, we have @code{forget(man,a,dim) == a}. @end deftypefun @c ------------------------------------------------------------------- @node Extraction of properties of abstract values of level 1, Meet and Join of abstract values of level 1, Tests on abstract values of level 1, Abstract values and operations of level 1 @subsection Extraction of properties of abstract values of level 1 @c ------------------------------------------------------------------- @deftypefun ap_interval_t* ap_abstract1_bound_variable (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}, ap_var_t @var{var}) Return the interval taken by the variable @var{var} over the abstract value @var{a}. @end deftypefun @deftypefun ap_interval_t* ap_abstract1_bound_linexpr (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}, ap_linexpr1_t* @var{expr}) @deftypefunx ap_interval_t* ap_abstract1_bound_texpr (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}, ap_texpr1_t* @var{expr}) Return the interval taken by the expression @var{expr} over the abstract value @var{a}. In the case of truly linear expression, this function allows to solve a Linear Programming (LP) problem, but depending on the underlying domain the solution may be not optimal. @end deftypefun @deftypefun ap_box1_t ap_abstract1_to_box (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}) Convert @var{a} to an interval/hypercube. @end deftypefun @deftypefun ap_lincons1_array_t ap_abstract1_to_lincons_array (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}) @deftypefunx ap_tcons1_array_t ap_abstract1_to_tcons_array (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}) Convert @var{a} to a conjunction of linear (resp. tree) constraints. The constraints are normally guaranteed to be without intervals. @end deftypefun @deftypefun ap_generator1_array_t ap_abstract1_to_generator_array (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}) Convert @var{a} to an array of generators. @end deftypefun @c ------------------------------------------------------------------- @node Meet and Join of abstract values of level 1, Assignements and Substitutions of abstract values of level 1, Extraction of properties of abstract values of level 1, Abstract values and operations of level 1 @subsection Meet and Join of abstract values of level 1 @c ------------------------------------------------------------------- @deftypefun ap_abstract1_t ap_abstract1_meet (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{a1}, ap_abstract1_t* @var{a2}) @deftypefunx ap_abstract1_t ap_abstract1_join (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{a1}, ap_abstract1_t* @var{a2}) Meet and Join of 2 abstract values @end deftypefun @deftypefun ap_abstract1_t ap_abstract1_meet_array (ap_manager_t* @var{man}, ap_abstract1_t* @var{array}, size_t @var{size}) @deftypefunx ap_abstract1_t ap_abstract1_join_array (ap_manager_t* @var{man}, ap_abstract1_t* @var{array}, size_t @var{size}) Meet and Join of the array @var{array} of abstract values of size @var{size}. Raise an @code{AP_EXC_INVALID_ARGUMENT} exception if @code{size==1} (no way to define the environment of the result in such a case). @end deftypefun @deftypefun ap_abstract1_t ap_abstract1_meet_lincons_array (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{a}, ap_lincons1_array_t* @var{array}) @deftypefunx ap_abstract1_t ap_abstract1_meet_tcons_array (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{a}, ap_tcons1_array_t* @var{array}) Meet of the abstract value @var{a} with the set of constraints @var{array}. @end deftypefun @deftypefun ap_abstract1_t ap_abstract1_add_ray_array (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{a}, ap_generator1_array_t* @var{array}) Generalized time elapse operator. @var{array} is supposed to contain only rays or lines, no vertices. @end deftypefun @c ------------------------------------------------------------------- @node Assignements and Substitutions of abstract values of level 1, Existential quantification of abstract values of level 1, Meet and Join of abstract values of level 1, Abstract values and operations of level 1 @subsection Assignements and Substitutions of abstract values of level 1 @c ------------------------------------------------------------------- @deftypefun ap_abstract1_t ap_abstract1_assign_linexpr_array (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{org}, ap_var_t* @var{tvar}, ap_linexpr1_t* @var{texpr}, size_t @var{size}, ap_abstract1_t* @var{dest}) @deftypefunx ap_abstract1_t ap_abstract1_substitute_linexpr_array (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{org}, ap_var_t* @var{tvar}, ap_linexpr1_t* @var{texpr}, size_t @var{size}, ap_abstract1_t* @var{dest}) @deftypefunx ap_abstract1_t ap_abstract1_assign_texpr_array (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{org}, ap_var_t* @var{tvar}, ap_texpr1_t* @var{texpr}, size_t @var{size}, ap_abstract1_t* @var{dest}) @deftypefunx ap_abstract1_t ap_abstract1_substitute_texpr_array (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{org}, ap_var_t* @var{tvar}, ap_texpr1_t* @var{texpr}, size_t @var{size}, ap_abstract1_t* @var{dest}) Parallel Assignement and Substitution of several variables by expressions in abstract value @var{org}. @var{dest} is an optional argument. If not NULL, semantically speaking, the result of the transformation is intersected with @var{dest}. This is useful for precise backward transformations in lattices like intervals or octagons. @end deftypefun @c ------------------------------------------------------------------- @node Existential quantification of abstract values of level 1, Change of environments of abstract values of level 1, Assignements and Substitutions of abstract values of level 1, Abstract values and operations of level 1 @subsection Existential quantification of abstract values of level 1 @c ------------------------------------------------------------------- @deftypefun ap_abstract1_t ap_abstract1_forget_array (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{a}, ap_var_t* @var{tvar}, size_t @var{size}, bool @var{project}) Forget (@code{project=false}) or Project (@code{project=true}) the array of variables @var{tvar} of size @var{size} in the abstract value @var{a}. @end deftypefun @c ------------------------------------------------------------------- @node Change of environments of abstract values of level 1, Expansion and Folding of dimensions in abstract values of level 1, Existential quantification of abstract values of level 1, Abstract values and operations of level 1 @subsection Change of environments of abstract values of level 1 @c ------------------------------------------------------------------- @deftypefun ap_abstract1_t ap_abstract1_change_environment (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{a}, ap_environment_t* @var{nenv}, bool @var{project}) Change the environment of the abstract values. Variables that are removed are first existentially quantified, and variables that are introduced are either unconstrained (@code{project==false}) or initialized to 0 (@code{project==false}). @end deftypefun @deftypefun ap_abstract1_t ap_abstract1_minimize_environment (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{a}) Remove from the environment of the abstract value and from the abstract value itself variables that are unconstrained in it. @end deftypefun @deftypefun ap_abstract1_t ap_abstract1_rename_array (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{a}, ap_var_t* @var{tvar}, ap_var_t* @var{ntvar}, size_t @var{size}) Parallel renaming of the environment of the abstract value. The new variables should not interfere with the variables that are not renamed. @end deftypefun @c ------------------------------------------------------------------- @node Expansion and Folding of dimensions in abstract values of level 1, Widening of abstract values of level 1, Change of environments of abstract values of level 1, Abstract values and operations of level 1 @subsection Expansion and Folding of dimensions of abstract values of level 1 @c ------------------------------------------------------------------- Formally, expanding @code{z} into @code{z} and @code{w} in abstract value (predicate) @code{P} is defined by @math{expand(P(x,y,z),z,w) = P(x,y,z) and P(x,y,w)}. Conversely, folding @code{z} and @code{w} into @code{z} in abstract value (predicate) @code{Q} is defined by @math{fold(Q(x,y,z,w),z,w) = (exists w: Q(x,y,z,w)) or (exists z:Q(x,y,z,w)[z<-w])}. @deftypefun ap_abstract1_t ap_abstract1_expand (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{a}, ap_var_t @var{var}, ap_var_t* @var{tvar}, size_t @var{size}) Expand the variable @var{var} into itself + the @var{size} additional variables of the array @var{tvar}, which are given the same type as @var{var}. The additional variables are added to the environment of the argument for making the environment of the result, so they should not belong to the initial environment. It results in @code{size+1} unrelated variables having same relations with other dimensions. @end deftypefun @deftypefun ap_abstract1_t ap_abstract1_fold (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{a}, ap_var_t* @var{tvar}, size_t @var{size}) Fold the variables in the array @var{tvar} of size @var{size}>=1 and put the result in the first variable in the array. The other variables of the array are then forgot and removed from the environment. @end deftypefun @c ------------------------------------------------------------------- @node Widening of abstract values of level 1, Topological closure of abstract values of level 1, Expansion and Folding of dimensions in abstract values of level 1, Abstract values and operations of level 1 @subsection Widening of abstract values of level 1 @c ------------------------------------------------------------------- @deftypefun ap_abstract1_t ap_abstract1_widening (ap_manager_t* @var{man}, ap_abstract1_t* @var{a1}, ap_abstract1_t* @var{a2}) Widening of @var{a1} with @var{a2}. @var{a1} is supposed to be included in @var{a2}. @end deftypefun @deftypefun ap_abstract1_t ap_abstract1_widening_threshold (ap_manager_t* @var{man}, ap_abstract1_t* @var{a1}, ap_abstract1_t* @var{a2}, ap_lincons1_array_t* @var{array}) Widening with threshold. Intersect the result of the standard widening with all the constraints in @var{array} that are satisfied by both @var{a1} and @var{a2}. @end deftypefun @c ------------------------------------------------------------------- @node Topological closure of abstract values of level 1, Additional functions on abstract values of level 1, Widening of abstract values of level 1, Abstract values and operations of level 1 @subsection Topological closure of abstract values of level 1 @c ------------------------------------------------------------------- @deftypefun ap_abstract1_t* ap_abstract1_closure (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{a}) Relax strict constraints into non strict constraints. @end deftypefun @c ------------------------------------------------------------------- @node Additional functions on abstract values of level 1, , Topological closure of abstract values of level 1, Abstract values and operations of level 1 @subsection Additional functions on abstract values of level 1 @c ------------------------------------------------------------------- @deftypefun ap_abstract1_t ap_abstract1_of_lincons_array (ap_manager_t* @var{man}, ap_environment_t* @var{env}, ap_lincons1_array_t* @var{array}) @deftypefunx ap_abstract1_t ap_abstract1_of_tcons_array (ap_manager_t* @var{man}, ap_environment_t* @var{env}, ap_tcons1_array_t* @var{array}) Abstract a conjunction of constraints. The environment of the array should be a subset of the environment @var{env}. @end deftypefun @deftypefun ap_abstract1_t ap_abstract1_assign_linexpr (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{org}, ap_var_t @var{var}, ap_linexpr1_t* @var{expr}, ap_abstract1_t* @var{dest}) @deftypefunx ap_abstract1_t ap_abstract1_substitute_linexpr (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{org}, ap_var_t @var{var}, ap_linexpr1_t* @var{expr}, ap_abstract1_t* @var{dest}) @deftypefunx ap_abstract1_t ap_abstract1_assign_texpr (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{org}, ap_var_t @var{var}, ap_texpr1_t* @var{expr}, ap_abstract1_t* @var{dest}) @deftypefunx ap_abstract1_t ap_abstract1_substitute_texpr (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{org}, ap_var_t @var{var}, ap_texpr1_t* @var{expr}, ap_abstract1_t* @var{dest}) Assignement and Substitution of the dimension @var{dim} by the expression @var{expr} in abstract value @var{org}. @var{dest} is an optional argument. If not NULL, semantically speaking, the result of the transformation is intersected with @var{dest}. This is useful for precise backward transformations in lattices like intervals or octagons. @end deftypefun @deftypefun ap_abstract1_t ap_abstract1_unify (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract1_t* @var{a1}, ap_abstract1_t* @var{a2}) Unify two abstract values on their common variables, that is, embed them on the least common environment and then compute their meet. The result is defined on the least common environment. For instance, the unification of @code{1<=x<=3 and x=y} defined on @code{@{ x, y @}} and @code{2<=z<=4 and z=y} defined on @code{@{y,z @}} results in @code{2<=x<=3 and x=y=z} defined on @code{@{x,y,z@}}. @end deftypefun @deftypefun ap_linexpr1_t ap_abstract1_quasilinear_of_intlinear (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}, ap_linexpr1_t* @var{expr}) Evaluate the interval linear expression @var{expr} on the abstract value @var{a} and approximate it by a quasilinear expression. This implies calls to @code{ap_abstract0_bound_dimension}. @end deftypefun @deftypefun ap_linexpr1_t ap_abstract1_intlinear_of_tree (ap_manager_t* @var{man}, ap_abstract1_t* @var{a}, ap_texpr1_t* @var{expr}, bool quasilinear) Evaluate the tree expression @var{expr} on the abstract value @var{a} and approximate it by an interval linear (resp. quasilinear if @var{quasilinear} is true) expression. This implies calls to @code{ap_abstract0_bound_dimension}. @end deftypefun @c ******************************************************************* @node Level 0 of the interface, Functions for implementors, Level 1 of the interface, Top @chapter Level 0 of the interface @c ******************************************************************* This interface of level 0 is defined in @file{ap_global0.h}. Unless there exists specific reasons for not doing so, we advise the user to use the level 1 of the interface (@pxref{Level 1 of the interface}). The level 0 is intented for implementors who wants to connect a new library/abstract domain, or who want to build a composite domain from existing ones. @menu * Dimensions and related operations:: * Linear expressions of level 0:: * Linear constraints of level 0:: * Generators of level 0:: * Tree expressions of level 0:: * Tree constraints of level 0:: * Abstract values and operations of level 0:: @end menu @ifnothtml For information only (as most of these types are considered as abstract) and for implementors, we sum up the involved types below. @verbatim ap_dim_t ap_dimension_t |--------------| |----------------| | unsigned int | | size_t intdim | |--------------| | size_t realdim | |----------------| ap_dimchange_t ap_dimperm_t |----------------| |-----------| | ap_dim_t* dim | | ap_dim_t* | | size_t intdim | | size_t | | size_t realdim | |-----------| |----------------| ap_linexpr0_t ap_linterm_t |-----------------------------| |------------| | ap_coeff_t cst | | ap_dim_t | | ap_linexpr_discr discr | | ap_coeff_t | | size_t size | |------------| |-----------------------------| | ap_coeff_t* | ap_linterm_t* | |-----------------------------| ap_lincons0_t ap_generator0_t |------------------| |----------------| | ap_linexpr0_t* | | ap_linexpr0_t* | | ap_constyp_t | | ap_gentyp_t | | ap_scalar_t* mod | |----------------| |------------------| ap_abstract0_t |---------------| | void* | | ap_manager_t* | |---------------| @end verbatim @end ifnothtml @c =================================================================== @node Dimensions and related operations, Linear expressions of level 0, Level 0 of the interface, Level 0 of the interface @section Dimensions and related operations (@file{ap_dimension.h}) @c =================================================================== @deftp datatype ap_dim_t @example typedef unsigned int ap_dim_t; @end example Datatype for dimensions. @end deftp @defmac AP_DIM_MAX Special value used for sparse representations, means: "to be ignored". Also used as a result when an error occurs. @end defmac @deftp datatype ap_dimension_t @example typedef struct ap_dimension_t @{ size_t intdim; /* Number of integer dimensions */ size_t realdim; /* Number of real dimensions */ @} ap_dimension_t; @end example Datatype for specifying the dimensionality of an abstract value. @end deftp @deftp datatype ap_dimchange_t @example typedef struct ap_dimchange_t @{ ap_dim_t* dim; /* Assumed to be an array of size intdim+realdim */ size_t intdim ; /* Number of integer dimensions to add/remove */ size_t realdim; /* Number of real dimensions to add/remove */ @} ap_dimchange_t; @end example Datatype for specifying change of dimension. The semantics is the following: @table @strong @item Addition of dimensions @code{dimchange.dim[k]} means: add one dimension at dimension k and shift the already existing dimensions greater than or equal to @code{k} one step on the right (or increment them). if @code{k} is equal to the size of the vector, then it means: add a dimension at the end. Repetion are allowed, and means that one inserts more than one dimensions. Example: @code{linexpr0_add_dimensions([i0 i1 r0 r1], @{ [0 1 2 2 4],3,1 @})} returns @code{[0 i0 0 i1 0 0 r0 r1 0]}, considered as a vector with 5 integer dimensions and 4 real dimensions. @item Removal of dimensions @code{dimchange.dim[k]}: remove the dimension @code{k} and shift the dimensions greater than @code{k} one step on the left (or decrement them). Repetitions are meaningless (and are not correct specification). Example: @code{linexpr0_remove_dimensions([i0 i1 i2 r0 r1 r2], @{ [0 2 4],2,1 @})} returns @code{[i1 r0 r2]}, considered as a vector with 1 integer dimensions and 2 real dimensions. @end table @end deftp @deftp datatype ap_dimchange2_t @example typedef struct ap_dimchange_2t @{ ap_dimchange_t* add; /* If not NULL, specifies the adding new dimensions */ ap_dimchange_t* remove; /* If not NULL, specifies the removal of dimensions */ @} ap_dimchange2_t; @end example Datatype for specifying a transformation composed of the addition and the removal of dimensions. Used by functions @code{ap_abstract0_apply_dimchange2}, @code{ap_environment_dimchange2}, and @code{ap_abstract1_change_environment.}. @end deftp @deftp datatype ap_dimperm_t @example typedef struct ap_dimperm_t @{ ap_dim_t* dim; /* Array assumed to be of size size */ size_t size; @} ap_dimperm_t; @end example Datatype for permutations. Represents the permutation @code{i -> dimperm.p[i]} for @code{0<=i=e->size}. @item In case of sparse representation, @code{dim==AP_DIM_MAX}. @end itemize @end deftypefun @c ------------------------------------------------------------------- @subsubsection Getting values @deftypefun void ap_linexpr0_get_cst (ap_coefft* @var{coeff}, ap_linexpr0_t* @var{e}) Assign to @var{coeff} the constant coefficient of @var{e}. @end deftypefun @deftypefun bool ap_linexpr0_get_coeff (ap_coefft* coeff, ap_linexpr0_t* @var{e}, ap_dim_t @var{dim}) Assign to @var{coeff} the coefficient of dimension @var{dim} in the expression @var{e}. Return true in case @code{ap_linexpr0_coeffref(e,dim)} returns NULL. @end deftypefun @defmac ap_linexpr0_ForeachLinterm (ap_linexpr0_t* @var{e}, size_t @var{i}, ap_dim_t @var{dim}, ap_coeff_t* @var{coeff}) Iterator on the coefficients associated to dimensions. @code{ap_linexpr0_ForeachLinterm(E,I,DIM,COEFF)@{ body @}} executes the body for each pair (@var{coeff},@var{dim}) in the expression @var{e}. @var{coeff} is a reference to the coefficient associated to dimension @var{dim} in @var{e}. @var{i} is an auxiliary variable used internally by the macro. @end defmac @c ------------------------------------------------------------------- @subsubsection Assigning values with a list of arguments @deftp datatype ap_coefftag_t @example typedef enum ap_coefftag_t @{ AP_COEFF, /* waiting for a coeff_t* object and a dimension */ AP_COEFF_S, /* waiting for a scalar_t* object and a dimension */ AP_COEFF_S_MPQ, /* waiting for a mpq_t object and a dimension */ AP_COEFF_S_INT, /* waiting for a int object and a dimension */ AP_COEFF_S_FRAC, /* waiting for 2 int objects and a dimension */ AP_COEFF_S_DOUBLE, /* waiting for a double object and a dimension */ AP_COEFF_I, /* waiting for a interval_t* object and a dimension */ AP_COEFF_I_SCALAR, /* waiting for 2 scalar_t* objects and a dimension */ AP_COEFF_I_MPQ, /* waiting for 2 mpq_t objects and a dimension */ AP_COEFF_I_INT, /* waiting for 2 int objects and a dimension */ AP_COEFF_I_FRAC, /* waiting for 4 int objects and a dimension */ AP_COEFF_I_DOUBLE, /* waiting for 2 double objects and a dimension */ AP_CST, /* waiting for a coeff_t* object */ AP_CST_S, /* waiting for a scalar_t* object */ AP_CST_S_MPQ, /* waiting for a mpq_t object */ AP_CST_S_INT, /* waiting for a int object */ AP_CST_S_FRAC, /* waiting for 2 int objects */ AP_CST_S_DOUBLE, /* waiting for a double object */ AP_CST_I, /* waiting for a interval_t* object */ AP_CST_I_SCALAR, /* waiting for 2 scalar_t* objects */ AP_CST_I_MPQ, /* waiting for 2 mpq_t objects */ AP_CST_I_INT, /* waiting for 2 int objects */ AP_CST_I_FRAC, /* waiting for 4 int objects */ AP_CST_I_DOUBLE, /* waiting for 2 double objects */ AP_END /* indicating end of the list */ @} ap_coefftag_t; @end example Tags for @code{ap_linexpr0_set_list} function. @end deftp @deftypefun bool ap_linexpr0_set_list (ap_linexpr0_t* @var{e}, ...) This function assign the linear expression @var{E} from a list of tags of type @code{ap_coefftag_t}, each followed by a number of arguments as specified in the definition of the tye @code{ap_coefftag_t}. The list should end with the tag @code{AP_COEFF_END}. Return @code{true} in case @code{ap_linexpr0_coeffref(e,dim)} returns NULL for one of the dimensions involved. Here is a typical example: @example ap_linexpr0_set_list(e, AP_COEFF_S_INT, 3, 0, AP_COEFF_S_FRAC, 3,2, 1, AP_COEFF_S_DOUBLE, 4.1, 2, AP_CST_I_DOUBLE, -2.4, 3.6, AP_END); /* Do not forget the last tatg ! */ @end example which transforms an null expression into @code{3 x0 + 3/2 x1 + 4.1 x2 + [-2.4,3.6]} and is equivalent to: @example ap_linexpr0_set_coeff_scalar_int(e,0, 3); ap_linexpr0_set_coeff_scalar_frac(e,1, 3,2); ap_linexpr0_set_coeff_scalar_double(e,2, 4.1); ap_linexpr0_set_cst_interval_double(e, -2.4, 3.6); @end example @end deftypefun @c ------------------------------------------------------------------- @subsubsection Assigning values @deftypefun void ap_linexpr0_set_cst (ap_linexpr0_t* @var{e}, ap_coefft* @var{coeff}) @deftypefunx void ap_linexpr0_set_cst_scalar (ap_linexpr0_t* @var{e}, ap_scalar_t* @var{scalar}) @deftypefunx void ap_linexpr0_set_cst_scalar_int (ap_linexpr0_t* @var{e}, int @var{num}) @deftypefunx void ap_linexpr0_set_cst_scalar_frac (ap_linexpr0_t* @var{e}, int @var{num}, unsigned int @var{den}) @deftypefunx void ap_linexpr0_set_cst_scalar_double (ap_linexpr0_t* @var{e}, double @var{num}) @deftypefunx void ap_linexpr0_set_cst_interval (ap_linexpr0_t* @var{e}, ap_interval_t* @var{itv}) @deftypefunx void ap_linexpr0_set_cst_interval_scalar (ap_linexpr0_t* @var{e}, ap_scalar_t* @var{inf}, ap_scalar_t* @var{sup}) @deftypefunx void ap_linexpr0_set_cst_interval_int (ap_linexpr0_t* @var{e}, int @var{inf}, int @var{sup}) @deftypefunx void ap_linexpr0_set_cst_interval_frac (ap_linexpr0_t* @var{e}, int @var{numinf}, unsigned int @var{deninf}, int @var{numsup}, unsigned int @var{densup}) @deftypefunx void ap_linexpr0_set_cst_interval_double (ap_linexpr0_t* @var{e}, double @var{inf}, double @var{sup}) Set the constant coefficient of expression @var{e}. @end deftypefun @deftypefun bool ap_linexpr0_set_coeff (ap_linexpr0_t* @var{e}, ap_dim_t @var{dim}, ap_coefft* @var{coeff}) @deftypefunx bool ap_linexpr0_set_coeff_scalar (ap_linexpr0_t* @var{e}, ap_dim_t @var{dim}, ap_scalar_t* @var{scalar}) @deftypefunx bool ap_linexpr0_set_coeff_scalar_int (ap_linexpr0_t* @var{e}, ap_dim_t @var{dim}, int @var{num}) @deftypefunx bool ap_linexpr0_set_coeff_scalar_frac (ap_linexpr0_t* @var{e}, ap_dim_t @var{dim}, int @var{num}, unsigned int @var{den}) @deftypefunx bool ap_linexpr0_set_coeff_scalar_double (ap_linexpr0_t* @var{e}, ap_dim_t @var{dim}, double @var{num}) @deftypefunx bool ap_linexpr0_set_coeff_interval (ap_linexpr0_t* @var{e}, ap_dim_t @var{dim}, ap_interval_t* @var{itv}) @deftypefunx bool ap_linexpr0_set_coeff_interval_scalar (ap_linexpr0_t* @var{e}, ap_dim_t @var{dim}, ap_scalar_t* @var{inf}, ap_scalar_t* @var{sup}) @deftypefunx bool ap_linexpr0_set_coeff_interval_int (ap_linexpr0_t* @var{e}, ap_dim_t @var{dim}, int @var{inf}, int @var{sup}) @deftypefunx bool ap_linexpr0_set_coeff_interval_frac (ap_linexpr0_t* @var{e}, ap_dim_t @var{dim}, int @var{numinf}, unsigned int @var{deninf}, int @var{numsup}, unsigned int @var{densup}) @deftypefunx void ap_linexpr0_set_coeff_interval_double (ap_linexpr0_t* @var{e}, ap_dim_t @var{dim}, double @var{inf}, double @var{sup}) Set the coefficient of the dimension @var{dim} of expression @var{e}. Return @code{true} in case @code{ap_linexpr0_coeffref(e,dim)} returns NULL. @end deftypefun @c ------------------------------------------------------------------- @node Change of dimensions and permutations of linear expressions of level 0, Other functions on linear expressions of level 0, Access to linear expressions of level 0, Linear expressions of level 0 @subsection Change of dimensions and permutations of linear expressions of level 0 @c ------------------------------------------------------------------- @deftypefun void ap_linexpr0_add_dimensions_with (ap_linexpr0_t* @var{e}, ap_dimchange_t* @var{dimchange}) @deftypefunx ap_linexpr0_t* ap_linexpr0_add_dimensions (ap_linexpr0_t* @var{e}, ap_dimchange_t* @var{dimchange}) These two functions add dimensions to the expressions, following the semantics of dimchange (see the type definition of @code{ap_dimchange_t}). @end deftypefun @deftypefun void ap_linexpr0_permute_dimensions_with (ap_linexpr0_t* @var{e}, ap_dimperm_t* @var{perm}) @deftypefunx ap_linexpr0_t* ap_linexpr0_permute_dimensions (ap_linexpr0_t* @var{e}, ap_dimperm_t* @var{perm}) These two functions apply the given permutation to the dimensions of @var{e}. If dense representation, the size of the permutation should be @code{e->size}. If sparse representation, the dimensions present in the expression should just be less than the size of the permutation. @end deftypefun @c ------------------------------------------------------------------- @node Other functions on linear expressions of level 0, , Change of dimensions and permutations of linear expressions of level 0, Linear expressions of level 0 @subsection Other functions on linear expressions of level 0 @c ------------------------------------------------------------------- All these functions induces a reduction of the coefficients of the linear expression. @deftypefun int ap_linexpr0_hash (ap_linexpr0_t* @var{e}) Return a hash code. @end deftypefun @deftypefun bool ap_linexpr0_equal (ap_linexpr0_t* @var{e1}, ap_linexpr0_t* @var{e2}) Equality test. @end deftypefun @deftypefun int ap_linexpr0_compare (ap_linexpr0_t* @var{e1}, ap_linexpr0_t* @var{e2}) Lexicographic ordering, terminating by constant coefficients. Use the (partial order) comparison function on coefficients @code{coeff_cmp}. @end deftypefun @c =================================================================== @node Linear constraints of level 0, Generators of level 0, Linear expressions of level 0, Level 0 of the interface @section Linear constraints of level 0 (@file{ap_lincons0.h}) @c =================================================================== @deftp datatype ap_constyp_t @example typedef enum ap_constyp_t @{ AP_CONS_EQ, /* equality constraint */ AP_CONS_SUPEQ, /* >= constraint */ AP_CONS_SUP, /* > constraint */ AP_CONS_EQMOD, /* congruence equality constraint */ AP_CONS_DISEQ /* disequality constraint */ @} ap_constyp_t; @end example Datatype for type of constraints. @end deftp @deftp datatype ap_lincons0_t @example typedef struct ap_lincons0_t @{ ap_linexpr0_t* linexpr0; /* expression */ ap_constyp_t constyp; /* type of constraint */ ap_scalar_t* scalar; /* maybe NULL. For EQMOD constraint, indicates the modulo */ @} ap_lincons0_t; @end example Datatype for constraints. Constraints are meant to be manipulated freely via their components. Creating the constraint @code{[1,2]x0 + 5/2x1 >=0} and then freeing it can be done with @example ap_lincons0_t cons = ap_lincons0_make(AP_CONS_SUPEQ, ap_linexpr0_alloc(AP_LINEXPR_SPARSE,2), NULL); ap_linexpr0_set_list(cons.linexpr0, AP_COEFF_I_INT, 1,2, 0, AP_COEFF_S_FRAC, 5,2, 1, AP_END); ap_lincons0_clear(&cons); @end example @end deftp @deftp datatype ap_lincons0_array_t @example typedef struct ap_lincons0_array_t @{ ap_lincons0_t* p; size_t size; @} ap_lincons0_array_t; @end example Datatype for arrays of constraints. Arrays are accessed directly, for example by writing @code{array->p[i]} (of type @code{ap_lincons0_t}), @code{array->p[i].constyp} and @code{array->p[i].linexpr0}. One can assign a constraint to the index @var{index} by writing: @code{array->p[index] = ap_lincons0_make(constyp,expr)}. @end deftp @menu * Allocating linear constraints of level 0:: * Tests on linear constraints of level 0:: * Arrays of linear constraints of level 0:: * Change of dimensions and permutations of linear constraints of level 0:: @end menu @c ------------------------------------------------------------------- @node Allocating linear constraints of level 0, Tests on linear constraints of level 0, Linear constraints of level 0, Linear constraints of level 0 @subsection Allocating linear constraints of level 0 @c ------------------------------------------------------------------- @deftypefun ap_lincons0_t ap_lincons0_make (ap_constyp_t @var{constyp}, ap_linexpr0_t* @var{linexpr}, ap_scalar_t* @var{mod}) Create a constraint of type @var{constyp} with the expression @var{linexpr}, and the modulo @var{mod} in case of a congruence constraint (@code{constyp==AP_CONS_EQMOD}). The expression is not duplicated, just pointed to, so it becomes managed via the constraint. @end deftypefun @deftypefun ap_lincons0_t ap_lincons0_make_unsat () Create the constraint @code{-1>=0}. @end deftypefun @deftypefun ap_lincons0_t ap_lincons0_copy (ap_lincons0_t* @var{cons}) Duplication @end deftypefun @deftypefun void ap_lincons0_clear (ap_lincons0_t* @var{cons}) Clear the constraint. @end deftypefun @deftypefun void ap_lincons0_fprint (FILE* @var{stream}, ap_lincons0_t* @var{cons}, char** @var{name_of_dim}); Print the linear constraint on stream @var{stream}, using the array @var{name_of_dim} to convert dimensions to variable names. If @var{name_of_dim} is @code{NULL}, the dimensions are named @code{x0,x1,...}. @end deftypefun @c ------------------------------------------------------------------- @node Tests on linear constraints of level 0, Arrays of linear constraints of level 0, Allocating linear constraints of level 0, Linear constraints of level 0 @subsection Tests on linear constraints of level 0 @c ------------------------------------------------------------------- @deftypefun bool ap_lincons0_is_unsat (ap_lincons0_t* @var{cons}) Return @code{true} if the constraint is not satisfiable. @end deftypefun @c ------------------------------------------------------------------- @node Arrays of linear constraints of level 0, Change of dimensions and permutations of linear constraints of level 0, Tests on linear constraints of level 0, Linear constraints of level 0 @subsection Arrays of linear constraints of level 0 @c ------------------------------------------------------------------- @deftypefun ap_lincons0_array_t ap_lincons0_array_make (size_t @var{size}) Allocate an array of size constraints. The constraints are initialized with NULL pointers for underlying expressions. @end deftypefun @deftypefun void ap_lincons0_array_clear (ap_lincons0_array_t* @var{array}) Clear the constraints of the array, and then the array itself. @end deftypefun @deftypefun void ap_lincons0_array_fprint (FILE* @var{stream}, ap_lincons0_array_t* @var{array}, char** @var{name_of_dim}) Print the array on the stream. @end deftypefun @c ------------------------------------------------------------------- @node Change of dimensions and permutations of linear constraints of level 0, , Arrays of linear constraints of level 0, Linear constraints of level 0 @subsection Change of dimensions and permutations of linear constraints of level 0 @c ------------------------------------------------------------------- @deftypefun void ap_lincons0_add_dimensions_with (ap_lincons0_t* @var{cons}, ap_dimchange_t* @var{dimchange}) @deftypefunx ap_lincons0_t ap_lincons0_add_dimensions (ap_lincons0_t* @var{cons}, ap_dimchange_t* @var{dimchange}) These two functions add dimensions to the constraint, following the semantics of dimchange (see the type definition of @code{ap_dimchange_t}). @end deftypefun @deftypefun void ap_lincons0_permute_dimensions_with (ap_lincons0_t* @var{cons}, ap_dimperm_t* @var{perm}) @deftypefunx ap_lincons0_t ap_lincons0_permute_dimensions (ap_lincons0_t* @var{cons}, ap_dimperm_t* @var{perm}) These two functions apply the given permutation to the dimensions of @var{cons}. @end deftypefun @deftypefun void ap_lincons0_array_add_dimensions_with (ap_lincons0_array_t* @var{cons}, ap_dimchange_t* @var{dimchange}) @deftypefunx ap_lincons0_array_t ap_lincons0_array_add_dimensions (ap_lincons0_array_t* @var{cons}, ap_dimchange_t* @var{dimchange}) @deftypefunx void ap_lincons0_array_permute_dimensions_with (ap_lincons0_array_t* @var{cons}, ap_dimperm_t* @var{perm}) @deftypefunx ap_lincons0_array_t ap_lincons0_array_permute_dimensions (ap_lincons0_array_t* @var{cons}, ap_dimperm_t* @var{perm}) Extension to arrays of the corresponding functions on constraints. @end deftypefun @c =================================================================== @node Generators of level 0, Tree expressions of level 0, Linear constraints of level 0, Level 0 of the interface @section Generators of level 0 (@file{ap_generator0.h}) @c =================================================================== Datatypes and functions are almost isomorphic to datatypes and functions for linear constraints. @deftp datatype ap_gentyp_t @example typedef enum ap_gentyp_t @{ AP_GEN_LINE, AP_GEN_RAY, AP_GEN_VERTEX, AP_GEN_LINEMOD, AP_GEN_RAYMOD @} ap_gentyp_t; @end example Datatype for type of generators. @end deftp @deftp datatype ap_generator0_t @example typedef struct ap_generator0_t @{ ap_linexpr0_t* linexpr0; /* underlying expression. */ ap_gentyp_t gentyp; /* type of generator */ @} ap_generator0_t; @end example Datatype for generators. The constant of the expression is ignored, and the expression is assumed to be truly linear (without intervals). @end deftp @deftp datatype ap_generator0_array_t @example typedef struct ap_generator0_array_t @{ ap_generator0_t* p; size_t size; @} ap_generator0_array_t; @end example Datatype for arrays of generators. @end deftp @menu * Allocating generators of level 0:: * Arrays of generators of level 0:: * Change of dimensions and permutations of generators of level 0:: @end menu @c ------------------------------------------------------------------- @node Allocating generators of level 0, Arrays of generators of level 0, Generators of level 0, Generators of level 0 @subsection Allocating generators of level 0 @c ------------------------------------------------------------------- @deftypefun ap_generator0_t ap_generator0_make (ap_gentyp_t @var{gentyp}, ap_linexpr0_t* @var{linexpr}) Create a generator of type @var{gentyp} with the expression @var{linexpr}. The expression is not duplicated, just pointed to, so it becomes managed via the generator. @end deftypefun @deftypefun ap_generator0_t ap_generator0_copy (gent ap_generator0_t* @var{gen}) Duplication @end deftypefun @deftypefun void ap_generator0_clear (ap_generator0_t* @var{gen}) Clear the generator. @end deftypefun @deftypefun void ap_generator0_fprint (FILE* @var{stream}, gent ap_generator0_t* @var{gen}, char** @var{name_of_dim}); Print the linear generator on stream @var{stream}, using the array @var{name_of_dim} to convert dimensions to variable names. If @var{name_of_dim} is @code{NULL}, the dimensions are named @code{x0,x1,...}. @end deftypefun @c ------------------------------------------------------------------- @node Arrays of generators of level 0, Change of dimensions and permutations of generators of level 0, Allocating generators of level 0, Generators of level 0 @subsection Arrays of generators of level 0 @c ------------------------------------------------------------------- Arrays are accessed directly, for example by writing @code{array->p[i]} (of type @code{ap_generator0_t}), @code{array->p[i].gentyp} and @code{array->p[i].linexpr0}. One can assign a generator to the index @var{index} by writing: @code{array->p[index] = ap_generator0_make(gentyp,expr)}. @deftypefun ap_generator0_array_t ap_generator0_array_make (size_t @var{size}) Allocate an array of size generators. The generators are initialized with NULL pointers for underlying expressions. @end deftypefun @deftypefun void ap_generator0_array_clear (ap_generator0_array_t* @var{array}) Clear the generators of the array, and then the array itself. @end deftypefun @deftypefun void ap_generator0_array_fprint (FILE* @var{stream}, gent ap_generator0_array_t* @var{array}, char** @var{name_of_dim}) Print the array on the stream. @end deftypefun @c ------------------------------------------------------------------- @node Change of dimensions and permutations of generators of level 0, , Arrays of generators of level 0, Generators of level 0 @subsection Change of dimensions and permutations of generators of level 0 @c ------------------------------------------------------------------- @deftypefun void ap_generator0_add_dimensions_with (ap_generator0_t* @var{gen}, gent ap_dimchange_t* @var{dimchange}) @deftypefunx ap_generator0_t ap_generator0_add_dimensions (gent ap_generator0_t* @var{gen}, gent ap_dimchange_t* @var{dimchange}) These two functions add dimensions to the generator, following the semantics of dimchange (see the type definition of @code{ap_dimchange_t}). @end deftypefun @deftypefun void ap_generator0_permute_dimensions_with (ap_generator0_t* @var{gen}, gent ap_dimperm_t* @var{perm}) @deftypefunx ap_generator0_t ap_generator0_permute_dimensions (gent ap_generator0_t* @var{gen}, gent ap_dimperm_t* @var{perm}) These two functions apply the given permutation to the dimensions of @var{gen}. @end deftypefun @deftypefun void ap_generator0_array_add_dimensions_with (ap_generator0_array_t* @var{gen}, gent ap_dimchange_t* @var{dimchange}) @deftypefunx ap_generator0_array_t ap_generator0_array_add_dimensions (gent ap_generator0_array_t* @var{gen}, gent ap_dimchange_t* @var{dimchange}) @deftypefunx void ap_generator0_array_permute_dimensions_with (ap_generator0_array_t* @var{gen}, gent ap_dimperm_t* @var{perm}) @deftypefunx ap_generator0_array_t ap_generator0_array_permute_dimensions (gent ap_generator0_array_t* @var{gen}, gent ap_dimperm_t* @var{perm}) Extension to arrays of the corresponding functions on generators. @end deftypefun @c =================================================================== @node Tree expressions of level 0, Tree constraints of level 0, Generators of level 0, Level 0 of the interface @section Tree expressions of level 0 (@file{ap_texpr0.h}) @c =================================================================== @c =================================================================== @node Tree constraints of level 0, Abstract values and operations of level 0, Tree expressions of level 0, Level 0 of the interface @section Tree constraints of level 0 (@file{ap_tcons0.h}) @c =================================================================== @c =================================================================== @node Abstract values and operations of level 0, , Tree constraints of level 0, Level 0 of the interface @section Abstract values and operations of level 0 (@file{ap_abstract0.h}) @c =================================================================== @deftp datatype ap_abstract0_t Datatype for abstract values at level 0. @end deftp Most operations are offered in 2 versions: @emph{functional} or @emph{destructive}. In such a case, the Boolean argument @var{destructive} controls the behaviour of the functionn: @itemize @item In the @emph{destructive semantics}, after the call the first abstract value in the arguments of the function is destroyed and should not be referenced any more. Although the returned value might actually be equal to the (destroyed) argument, the user just manipulates the returned value and never refers directly to the (destroyed) argument. @item In the @emph{functional semantics}, the first abstract value in the arguments is neither (semantically) modified nor deallocated. @end itemize @menu * Allocating abstract values of level 0:: * Control of internal representation of abstract values of level 0:: * Printing abstract values of level 0:: * Serialization of abstract values of level 0:: Constructors, Accessors, Tests and Extraction of properties * Constructors for abstract values of level 0:: * Accessors for abstract values of level 0:: * Tests on abstract values of level 0:: * Extraction of properties of abstract values of level 0:: Operations * Meet and Join of abstract values of level 0:: * Assignements and Substitutions of abstract values of level 0:: * Existential quantification of abstract values of level 0:: * Change and permutation of dimensions of abstract values of level 0:: * Expansion and Folding of dimensions in abstract values of level 0:: * Widening of abstract values of level 0:: * Topological closure of abstract values of level 0:: Additional functions * Additional functions on abstract values of level 0:: @end menu @c ------------------------------------------------------------------- @node Allocating abstract values of level 0, Control of internal representation of abstract values of level 0, Abstract values and operations of level 0, Abstract values and operations of level 0 @subsection Allocating abstract values of level 0 @c ------------------------------------------------------------------- @deftypefun ap_abstract0_t* ap_abstract0_copy (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}) Return a copy of @var{a}, on which destructive update does not affect @var{a}. @end deftypefun @deftypefun void ap_abstract0_free (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}) Free all the memory used by @var{a}. @end deftypefun @deftypefun size_t ap_abstract0_size (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}) Return the abstract size of @var{a}. @end deftypefun @c ------------------------------------------------------------------- @node Control of internal representation of abstract values of level 0, Printing abstract values of level 0, Allocating abstract values of level 0, Abstract values and operations of level 0 @subsection Control of internal representation of level 0 @c ------------------------------------------------------------------- @deftypefun void ap_abstract0_minimize (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}) Minimize the size of the representation of @var{a}. This may result in a later recomputation of internal information. @end deftypefun @deftypefun void ap_abstract0_canonicalize (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}) Put @var{a} in canonical form. (not yet clear definition) @end deftypefun @deftypefun int ap_abstract0_hash (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}) Return an hash value for @var{a}. Two abstract values in canonical from (according to @code{ap_abstract0_canonicalize}) and considered as equal by the function @code{ap_abstract0_is_eq} should be given the same hash value (this implies more or less a canonical form). @end deftypefun @deftypefun void ap_abstract0_approximate (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}, int @var{algorithm}) Perform some transformation on @var{a}, guided by the field algorithm. The transformation may lose information. The argument @var{algorithm} overrides the field algorithm of the structure of type @code{ap_funopt_t} associated to @code{ap_abstract0_approximate}. @end deftypefun @c ------------------------------------------------------------------- @node Printing abstract values of level 0, Serialization of abstract values of level 0, Control of internal representation of abstract values of level 0, Abstract values and operations of level 0 @subsection Printing abstract values of level 0 @c ------------------------------------------------------------------- @deftypefun void ap_abstract0_fprint (FILE* @var{stream}, ap_manager_t* @var{man}, ap_abstract0_t* @var{a}, char** @var{name_of_dim}) Print @var{a} in a pretty way, using array @var{name_of_dim} to name dimensions.. If @var{name_of_dim} is @code{NULL}, use the default names @code{x0, x1, ...}. @end deftypefun @deftypefun void ap_abstract0_fprintdiff (FILE* @var{stream}, ap_manager_t* @var{man}, ap_abstract0_t* @var{a1}, ap_abstract0_t* @var{a2}, char** @var{name_of_dim}) Print the difference between @var{a1} (old value) and @var{a2} (new value), using array @var{name_of_dim} to name dimensions. The meaning of difference is library dependent. @end deftypefun @deftypefun void ap_abstract0_fdump (FILE* @var{stream}, ap_manager_t* @var{man}, ap_abstract0_t* @var{a}) Dump the internal representation of @var{a} for debugging purposes. @end deftypefun @c ------------------------------------------------------------------- @node Serialization of abstract values of level 0, Constructors for abstract values of level 0, Printing abstract values of level 0, Abstract values and operations of level 0 @subsection Serialization of abstract values of level 0 @c ------------------------------------------------------------------- @deftypefun ap_membuf_t ap_abstract0_serialize_raw (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}) Allocate a memory buffer (with @code{malloc}), output @var{a} in raw binary format to it and return a pointer on the memory buffer and the number of bytes written. It is the user responsability to free the memory afterwards (with free). @end deftypefun @deftypefun ap_abstract0_t* ap_abstract0_deserialize_raw (ap_manager_t* @var{man}, void* @var{ptr}, size_t* @var{size}) Return the abstract value read in raw binary format from the buffer pointed by @var{ptr} and store in size the number of bytes read. @end deftypefun @c ------------------------------------------------------------------- @node Constructors for abstract values of level 0, Accessors for abstract values of level 0, Serialization of abstract values of level 0, Abstract values and operations of level 0 @subsection Constructors for abstract values of level 0 @c ------------------------------------------------------------------- @deftypefun ap_abstract0_t* ap_abstract0_bottom (ap_manager_t* @var{man}, size_t @var{intdim}, size_t @var{realdim}) @deftypefunx ap_abstract0_t* ap_abstract0_top (ap_manager_t* @var{man}, size_t @var{intdim}, size_t @var{realdim}) Create resp. a bottom (empty) value and a top (universe) value with @var{intdim} integer dimensions and @var{realdim} real dimensions. @end deftypefun @deftypefun ap_abstract0_t* ap_abstract0_of_box (ap_manager_t* @var{man}, size_t @var{intdim}, size_t @var{realdim}, ap_interval_t** @var{array}) Abstract an hypercube defined by the array of intervals @var{array} of size @var{intdim}+@var{realdim}. @end deftypefun @c ------------------------------------------------------------------- @node Accessors for abstract values of level 0, Tests on abstract values of level 0, Constructors for abstract values of level 0, Abstract values and operations of level 0 @subsection Accessors for abstract values of level 0 @c ------------------------------------------------------------------- @deftypefun ap_dimension_t ap_abstract0_dimension (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}) Return the dimensionality of @var{a}. @end deftypefun @c ------------------------------------------------------------------- @node Tests on abstract values of level 0, Extraction of properties of abstract values of level 0, Accessors for abstract values of level 0, Abstract values and operations of level 0 @subsection Tests on abstract values of level 0 @c ------------------------------------------------------------------- In abstract tests, @itemize @item true means that the predicate is certainly true; @item false means false @emph{or} don't know (an exception has occurred, or the exact computation was considered too expensive to be performed, according to the options). @end itemize @deftypefun bool ap_abstract0_is_bottom (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}) @deftypefunx bool ap_abstract0_is_top (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}) Emtpiness and universality tests. @end deftypefun @deftypefun bool ap_abstract0_is_leq (ap_manager_t* @var{man}, ap_abstract0_t* @var{a1}, ap_abstract0_t* @var{a2}) @deftypefunx bool ap_abstract0_is_eq (ap_manager_t* @var{man}, ap_abstract0_t* @var{a1}, ap_abstract0_t* @var{a2}) Inclusion and equality tests. @end deftypefun @deftypefun bool ap_abstract0_sat_interval (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}, ap_dim_t @var{dim}, ap_interval_t* @var{interval}) Is the dimension @var{dim} included in the interval @var{interval} in the abstract value @var{a} ? @end deftypefun @deftypefun bool ap_abstract0_sat_lincons (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}, ap_lincons0_t* @var{cons}) @deftypefunx bool ap_abstract0_sat_tcons (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}, ap_tcons0_t* @var{cons}) Does the abstract value @var{a} satisfy the constraint @var{cons} ? @end deftypefun @deftypefun bool ap_abstract0_is_dimension_unconstrained (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}, ap_dim_t @var{dim}) Is the dimension @var{dim} unconstrained in the abstract value @var{a} ? If it is the case, we have @code{forget(man,a,dim) == a}. @end deftypefun @c ------------------------------------------------------------------- @node Extraction of properties of abstract values of level 0, Meet and Join of abstract values of level 0, Tests on abstract values of level 0, Abstract values and operations of level 0 @subsection Extraction of properties of abstract values of level 0 @c ------------------------------------------------------------------- @deftypefun ap_interval_t* ap_abstract0_bound_dimension (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}, ap_dim_t @var{dim}) Return the interval taken by the dimension @var{dim} over the abstract value@var{a} @end deftypefun @deftypefun ap_interval_t* ap_abstract0_bound_linexpr (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}, ap_linexpr0_t* @var{expr}) @deftypefunx ap_interval_t* ap_abstract0_bound_texpr (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}, ap_texpr0_t* @var{expr}) Return the interval taken by a linear expression @var{expr} over the abstract value @var{a}. This function allows to solve a Linear Programming (LP) problem, but depending on the underlying domain the solution may be not optimal. @end deftypefun @deftypefun ap_interval_t** ap_abstract0_to_box (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}) Convert @var{a} to an interval/hypercube. The size of the resulting array is ap_abstract0_dimension(man,a). @end deftypefun @deftypefun ap_lincons0_array_t ap_abstract0_to_lincons_array (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}) @deftypefunx ap_tcons0_array_t ap_abstract0_to_tcons_array (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}) Convert @var{a} to a conjunction of constraints. The constraints are normally guaranteed to be scalar (without intervals) @end deftypefun @deftypefun ap_generator0_array_t ap_abstract0_to_generator_array (ap_manager_t* @var{man}, ap_abstract0_t* @var{a}) Convert @var{a} to an array of generators. @end deftypefun @c ------------------------------------------------------------------- @node Meet and Join of abstract values of level 0, Assignements and Substitutions of abstract values of level 0, Extraction of properties of abstract values of level 0, Abstract values and operations of level 0 @subsection Meet and Join of abstract values of level 0 @c ------------------------------------------------------------------- @deftypefun ap_abstract0_t* ap_abstract0_meet (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{a1}, ap_abstract0_t* @var{a2}) @deftypefunx ap_abstract0_t* ap_abstract0_join (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{a1}, ap_abstract0_t* @var{a2}) Meet and Join of 2 abstract values @end deftypefun @deftypefun ap_abstract0_t* ap_abstract0_meet_array (ap_manager_t* @var{man}, ap_abstract0_t** @var{array}, size_t @var{size}) @deftypefunx ap_abstract0_t* ap_abstract0_join_array (ap_manager_t* @var{man}, ap_abstract0_t** @var{array}, size_t @var{size}) Meet and Join of the array @var{array} of abstract values of size @var{size}. Raise an @code{AP_EXC_INVALID_ARGUMENT} exception if @code{size==0} (no way to define the dimensionality of the result in such a case). @end deftypefun @deftypefun ap_abstract0_t* ap_abstract0_meet_lincons_array (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{a}, ap_lincons0_array_t* @var{array}) @deftypefunx ap_abstract0_t* ap_abstract0_meet_tcons_array (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{a}, ap_tcons0_array_t* @var{array}) Meet of the abstract value @var{a} with the set of constraints @var{array}. @var{array} should have exactly the same dimensionality as @var{a}. @end deftypefun @deftypefun ap_abstract0_t* ap_abstract0_add_ray_array (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{a}, ap_generator0_array_t* @var{array}) Generalized time elapse operator. @var{array} is supposed to contain only rays or lines, no vertices. @var{array} should have exactly the same dimensionality as @var{a}. @end deftypefun @c ------------------------------------------------------------------- @node Assignements and Substitutions of abstract values of level 0, Existential quantification of abstract values of level 0, Meet and Join of abstract values of level 0, Abstract values and operations of level 0 @subsection Assignements and Substitutions of abstract values of level 0 @c ------------------------------------------------------------------- @deftypefun ap_abstract0_t* ap_abstract0_assign_linexpr_array (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{org}, ap_dim_t* @var{tdim}, ap_linexpr0_t** @var{texpr}, size_t @var{size}, ap_abstract0_t* @var{dest}) @deftypefunx ap_abstract0_t* ap_abstract0_substitute_linexpr_array (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{org}, ap_dim_t* @var{tdim}, ap_linexpr0_t** @var{texpr}, size_t @var{size}, ap_abstract0_t* @var{dest}) @deftypefunx ap_abstract0_t* ap_abstract0_assign_texpr_array (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{org}, ap_dim_t* @var{tdim}, ap_texpr0_t** @var{texpr}, size_t @var{size}, ap_abstract0_t* @var{dest}) @deftypefunx ap_abstract0_t* ap_abstract0_substitute_texpr_array (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{org}, ap_dim_t* @var{tdim}, ap_texpr0_t** @var{texpr}, size_t @var{size}, ap_abstract0_t* @var{dest}) Parallel Assignement and Substitution of several dimensions by expressions in abstract value @var{org}. @var{dest} is an optional argument. If not NULL, semantically speaking, the result of the transformation is intersected with @var{dest}. This is useful for precise backward transformations in lattices like intervals or octagons. @end deftypefun @c ------------------------------------------------------------------- @node Existential quantification of abstract values of level 0, Change and permutation of dimensions of abstract values of level 0, Assignements and Substitutions of abstract values of level 0, Abstract values and operations of level 0 @subsection Existential quantification of abstract values of level 0 @c ------------------------------------------------------------------- @deftypefun ap_abstract0_t* ap_abstract0_forget_array (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{a}, ap_dim_t* @var{tdim}, size_t @var{size}, bool @var{project}) Forget (@code{project=false}) or Project (@code{project=true}) the array of dimensions @var{tdim} of size @var{size} in the abstract value @var{a}. @end deftypefun @c ------------------------------------------------------------------- @node Change and permutation of dimensions of abstract values of level 0, Expansion and Folding of dimensions in abstract values of level 0, Existential quantification of abstract values of level 0, Abstract values and operations of level 0 @subsection Change and permutation of dimensions of abstract values of level 0 @c ------------------------------------------------------------------- @deftypefun ap_abstract0_t* ap_abstract0_add_dimensions (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{a}, ap_dimchange_t* @var{dimchange}, bool @var{project}) @deftypefunx ap_abstract0_t* ap_abstract0_remove_dimensions (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{a}, ap_dimchange_t* @var{dimchange}) Addition and Removal of dimensions in @var{a} according to @var{dimchange}. In the case of addition, new dimensions are either unconstrained (@code{project==false}) or initialized to 0 ((@code{project==true}). @end deftypefun @deftypefun ap_abstract0_t* ap_abstract0_apply_dimchange2 (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{a}, ap_dimchange2_t* @var{dimchange2}, bool @var{project}) Apply the transformation specified by @var{dimchange2}. New dimensions are either unconstrained (@code{project==false}) or initialized to 0 ((@code{project==true}). @end deftypefun @deftypefun ap_abstract0_t* ap_abstract0_permute_dimensions (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{a}, ap_dimperm_t* @var{perm}) Permute the dimensions of @var{a} according to the permutation @var{perm}. The size of the permutation is supposed to be large enough w.r.t. @var{a}. @end deftypefun @c ------------------------------------------------------------------- @node Expansion and Folding of dimensions in abstract values of level 0, Widening of abstract values of level 0, Change and permutation of dimensions of abstract values of level 0, Abstract values and operations of level 0 @subsection Expansion and Folding of dimensions of abstract values of level 0 @c ------------------------------------------------------------------- Formally, expanding @code{z} into @code{z} and @code{w} in abstract value (predicate) @code{P} is defined by @math{expand(P(x,y,z),z,w) = P(x,y,z) and P(x,y,w)}. Conversely, folding @code{z} and @code{w} into @code{z} in abstract value (predicate) @code{Q} is defined by @math{fold(Q(x,y,z,w),z,w) = (exists w: Q(x,y,z,w)) or (exists z:Q(x,y,z,w)[z<-w])}. @deftypefun ap_abstract0_t* ap_abstract0_expand (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{a}, ap_dim_t @var{dim}, size_t @var{n}) Expand the dimension @var{dim} into itself + @var{n} additional dimensions. It results in @code{n+1} unrelated dimensions having same relations with other dimensions. The @var{n+1} dimensions are put as follows: @itemize @item original dimension @var{dim}; @item if @var{dim} is integer, the @var{n} additional dimensions are put at the end of integer dimensions; if it is real, at the end of the real dimensions. @end itemize @end deftypefun @deftypefun ap_abstract0_t* ap_abstract0_fold (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{a}, ap_dim_t* @var{tdim}, size_t @var{size}) Fold the dimensions in the array @var{tdim} of size @var{size}>=1 and put the result in the first dimension in the array @emph{assumed to be sorted}. The other dimensions of the array are then removed. @end deftypefun @c ------------------------------------------------------------------- @node Widening of abstract values of level 0, Topological closure of abstract values of level 0, Expansion and Folding of dimensions in abstract values of level 0, Abstract values and operations of level 0 @subsection Widening of abstract values of level 0 @c ------------------------------------------------------------------- @deftypefun ap_abstract0_t* ap_abstract0_widening (ap_manager_t* @var{man}, ap_abstract0_t* @var{a1}, ap_abstract0_t* @var{a2}) Widening of @var{a1} with @var{a2}. @var{a1} is supposed to be included in @var{a2}. @end deftypefun @c ------------------------------------------------------------------- @node Topological closure of abstract values of level 0, Additional functions on abstract values of level 0, Widening of abstract values of level 0, Abstract values and operations of level 0 @subsection Topological closure of abstract values of level 0 @c ------------------------------------------------------------------- @deftypefun ap_abstract0_t* ap_abstract0_closure (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{a}) Relax strict constraints into non strict constraints. @end deftypefun @c ------------------------------------------------------------------- @node Additional functions on abstract values of level 0, , Topological closure of abstract values of level 0, Abstract values and operations of level 0 @subsection Additional functions on abstract values of level 0 @c ------------------------------------------------------------------- These functions do not have corresponding functions into underlying libraries. @deftypefun ap_manager_t* ap_abstract0_manager (ap_abstract0_t* @var{a}) Return a reference to the manager contained in @var{a}. The reference should not be freed. @end deftypefun @deftypefun ap_abstract0_t* ap_abstract0_of_lincons_array (ap_manager_t* @var{man}, size_t @var{intdim}, size_t @var{realdim}, ap_lincons0_array_t* @var{array}) @deftypefunx ap_abstract0_t* ap_abstract0_of_tcons_array (ap_manager_t* @var{man}, size_t @var{intdim}, size_t @var{realdim}, ap_tcons0_array_t* @var{array}) Abstract a conjunction of constraints. The constraints in the array should have exactly the dimensions (@var{intdim},@var{realdim}). @end deftypefun @deftypefun ap_abstract0_t* ap_abstract0_assign_linexpr (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{org}, ap_dim_t @var{dim}, ap_linexpr0_t* @var{expr}, ap_abstract0_t* @var{dest}) @deftypefunx ap_abstract0_t* ap_abstract0_substitute_linexpr (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{org}, ap_dim_t @var{dim}, ap_linexpr0_t* @var{expr}, ap_abstract0_t* @var{dest}) @deftypefunx ap_abstract0_t* ap_abstract0_assign_texpr (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{org}, ap_dim_t @var{dim}, ap_texpr0_t* @var{expr}, ap_abstract0_t* @var{dest}) @deftypefunx ap_abstract0_t* ap_abstract0_substitute_texpr (ap_manager_t* @var{man}, bool @var{destructive}, ap_abstract0_t* @var{org}, ap_dim_t @var{dim}, ap_texpr0_t* @var{expr}, ap_abstract0_t* @var{dest}) Assignement and Substitution of the dimension @var{dim} by the expression @var{expr} in abstract value @var{org}. @var{dest} is an optional argument. If not NULL, semantically speaking, the result of the transformation is intersected with @var{dest}. This is useful for precise backward transformations in lattices like intervals or octagons. @end deftypefun @deftypefun ap_abstract0_t* ap_abstract0_widening_threshold (ap_manager_t* @var{man}, ap_abstract0_t* @var{a1}, ap_abstract0_t* @var{a2}, ap_lincons0_array_t* @var{array}) Widening with threshold. Intersect the result of the standard widening with all the constraints in @var{array} that are satisfied by both @var{a1} and @var{a2}. @end deftypefun @c ******************************************************************* @node Functions for implementors, Examples, Level 0 of the interface, Top @chapter Functions for implementors @c ******************************************************************* The signatures and documentation of these functions are provided by the files @file{ap_generic.h}, @file{ap_linearize.h} and @file{ap_reducedproduct.h}. These functions are dedicated to implementors of underlying libraries. They offer generic default implementations for some of the operations required by the APRON API, when there is no more specific and efficient implementation for the domain being implemented. To use one of these, the function allocating manager, which is specific to the domain, should put the corresponding pointer in the virtual table to such a generic implementation. They manipulated "unboxed" abstract values, which are native to the underlying library: they are not yet boxed with the manager in the type @code{ap_abstract0_t}. @c ******************************************************************* @node Examples, Appendices, Functions for implementors, Top @chapter Examples @c ******************************************************************* Look at the examples in the @samp{example} subdirectoy of the full distribution, or click on the links below: @ifhtml @uref{example1.c} @uref{mlexample1.ml} @uref{mlexample2.ml} @uref{mlexample3.ml} @end ifhtml @c ******************************************************************* @node Appendices, , Examples, Top @appendix Appendices @c ******************************************************************* @menu * C Datatype Index:: * C Variable Index:: * C Function Index:: @end menu @c =================================================================== @node C Datatype Index, C Variable Index, Appendices, Appendices @appendixsec C Datatype Index @printindex tp @c =================================================================== @page @c =================================================================== @node C Variable Index, C Function Index, C Datatype Index, Appendices @appendixsec C Variable Index @c =================================================================== @printindex vr @page @c =================================================================== @node C Function Index, , C Variable Index, Appendices @appendixsec C Function Index @c =================================================================== @printindex fn @page @bye apron-dist-0.9.10/apron/apron/ap_generator0.h0000640014525101416610000001317710676403632020722 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_generator0.h: generators and arrays */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ /* normally included from ap_expr0.h */ #ifndef _AP_GENERATOR0_H_ #define _AP_GENERATOR0_H_ #include #include #include #include "ap_coeff.h" #include "ap_linexpr0.h" #ifdef __cplusplus extern "C" { #endif /* ====================================================================== */ /* Datatypes */ /* ====================================================================== */ /* Datatype for type of generators */ typedef enum ap_gentyp_t { AP_GEN_LINE, AP_GEN_RAY, AP_GEN_VERTEX, AP_GEN_LINEMOD, AP_GEN_RAYMOD } ap_gentyp_t; /* Generator */ typedef struct ap_generator0_t { ap_linexpr0_t* linexpr0; /* constant coefficient ignored, and assumed to be truly linear (without intervals) */ ap_gentyp_t gentyp; } ap_generator0_t; /* Array of generators */ typedef struct ap_generator0_array_t { ap_generator0_t* p; size_t size; } ap_generator0_array_t; /* ********************************************************************** */ /* I. Generators */ /* ********************************************************************** */ static inline ap_generator0_t ap_generator0_make(ap_gentyp_t gentyp, ap_linexpr0_t* linexpr); /* Create a generator of given type with the given expression. The expression is not duplicated, just pointed to */ static inline ap_generator0_t ap_generator0_copy(ap_generator0_t* gen); /* Duplication */ static inline void ap_generator0_clear(ap_generator0_t* gen); /* Free the linear expression of the generator and set pointer to NULL */ void ap_generator0_fprint(FILE* stream, ap_generator0_t* gen, char** name_of_dim); /* Printing a generator */ /* ====================================================================== */ /* I.1 Change of dimensions and permutations */ /* ====================================================================== */ static inline void ap_generator0_add_dimensions_with(ap_generator0_t* gen, ap_dimchange_t* dimchange); static inline ap_generator0_t ap_generator0_add_dimensions(ap_generator0_t* gen, ap_dimchange_t* dimchange); static inline void ap_generator0_permute_dimensions_with(ap_generator0_t* gen, ap_dimperm_t* perm); static inline ap_generator0_t ap_generator0_permute_dimensions(ap_generator0_t* gen, ap_dimperm_t* perm); /* ********************************************************************** */ /* II. Array of Generators */ /* ********************************************************************** */ ap_generator0_array_t ap_generator0_array_make(size_t size); /* Allocate an array of size generators. The generators are initialized with NULL pointers. */ void ap_generator0_array_resize(ap_generator0_array_t* array, size_t size); /* Resize an array of size generators. New generators are initialized with NULL pointers, Removed generators with non-NULL pointers are deallocated */ void ap_generator0_array_clear(ap_generator0_array_t* ap_generator0_array); /* Clear the generators of the array, and then the array itself */ void ap_generator0_array_fprint(FILE* stream, ap_generator0_array_t* ap_generator0_array, char** name_of_dim); /* Printing */ /* ====================================================================== */ /* II.1 Change of dimensions and permutations */ /* ====================================================================== */ void ap_generator0_array_add_dimensions_with(ap_generator0_array_t* array, ap_dimchange_t* dimchange); ap_generator0_array_t ap_generator0_array_add_dimensions(ap_generator0_array_t* array, ap_dimchange_t* dimchange); void ap_generator0_array_permute_dimensions_with(ap_generator0_array_t* array, ap_dimperm_t* perm); ap_generator0_array_t ap_generator0_array_permute_dimensions(ap_generator0_array_t* array, ap_dimperm_t* perm); /* ********************************************************************** */ /* III. Inline functions definitions */ /* ********************************************************************** */ static inline ap_generator0_t ap_generator0_make(ap_gentyp_t gentyp, ap_linexpr0_t* linexpr) { ap_generator0_t gen; gen.gentyp = gentyp; gen.linexpr0 = linexpr; return gen; } static inline ap_generator0_t ap_generator0_copy(ap_generator0_t* gen) { return ap_generator0_make(gen->gentyp, gen->linexpr0 ? ap_linexpr0_copy(gen->linexpr0) : NULL); } static inline void ap_generator0_clear(ap_generator0_t* generator) { if (generator->linexpr0){ ap_linexpr0_free(generator->linexpr0); generator->linexpr0 = NULL; } } static inline void ap_generator0_add_dimensions_with(ap_generator0_t* gen, ap_dimchange_t* dimchange) { ap_linexpr0_add_dimensions_with(gen->linexpr0,dimchange); } static inline ap_generator0_t ap_generator0_add_dimensions(ap_generator0_t* gen, ap_dimchange_t* dimchange) { return ap_generator0_make(gen->gentyp, ap_linexpr0_add_dimensions(gen->linexpr0,dimchange)); } static inline void ap_generator0_permute_dimensions_with(ap_generator0_t* gen, ap_dimperm_t* perm) { ap_linexpr0_permute_dimensions_with(gen->linexpr0,perm); } static inline ap_generator0_t ap_generator0_permute_dimensions(ap_generator0_t* gen, ap_dimperm_t* perm) { return ap_generator0_make(gen->gentyp, ap_linexpr0_permute_dimensions(gen->linexpr0,perm)); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/ap_coeff.c0000640014525101416610000002357511247456444017740 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_coeff.c: coefficients, that are either scalars or intervals */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include "ap_coeff.h" /* ====================================================================== */ /* Basics */ /* ====================================================================== */ /* FOR INTERNAL USE ONLY */ void ap_coeff_init(ap_coeff_t* coeff, ap_coeff_discr_t coeff_discr) { coeff->discr = coeff_discr; switch (coeff_discr){ case AP_COEFF_SCALAR: coeff->val.scalar = ap_scalar_alloc(); break; case AP_COEFF_INTERVAL: coeff->val.interval = ap_interval_alloc(); break; } } /* FOR INTERNAL USE ONLY */ void ap_coeff_init_set(ap_coeff_t* coeff, ap_coeff_t* coeff2) { coeff->discr = coeff2->discr; switch (coeff2->discr){ case AP_COEFF_SCALAR: coeff->val.scalar = ap_scalar_alloc_set(coeff2->val.scalar); break; case AP_COEFF_INTERVAL: coeff->val.interval = ap_interval_alloc_set(coeff2->val.interval); break; } } /* FOR INTERNAL USE ONLY */ void ap_coeff_clear(ap_coeff_t* coeff) { switch (coeff->discr){ case AP_COEFF_SCALAR: ap_scalar_free(coeff->val.scalar); break; case AP_COEFF_INTERVAL: ap_interval_free(coeff->val.interval); break; } } ap_coeff_t* ap_coeff_alloc(ap_coeff_discr_t coeff_discr) { ap_coeff_t* coeff = malloc(sizeof(ap_coeff_t)); coeff->discr = coeff_discr; switch (coeff_discr){ case AP_COEFF_SCALAR: coeff->val.scalar = ap_scalar_alloc(); break; case AP_COEFF_INTERVAL: coeff->val.interval = ap_interval_alloc(); break; } return coeff; } void ap_coeff_reinit(ap_coeff_t* coeff, ap_coeff_discr_t coeff_discr, ap_scalar_discr_t ap_scalar_discr) { switch (coeff->discr){ case AP_COEFF_SCALAR: if (coeff_discr != coeff->discr){ ap_scalar_free(coeff->val.scalar); coeff->val.interval = ap_interval_alloc(); ap_interval_reinit(coeff->val.interval,ap_scalar_discr); } else { ap_scalar_reinit(coeff->val.scalar,ap_scalar_discr); } break; case AP_COEFF_INTERVAL: if (coeff_discr != coeff->discr){ ap_interval_free(coeff->val.interval); coeff->val.scalar = ap_scalar_alloc(); ap_scalar_reinit(coeff->val.scalar,ap_scalar_discr); } else { ap_interval_reinit(coeff->val.interval,ap_scalar_discr); } break; } coeff->discr = coeff_discr; } void ap_coeff_free(ap_coeff_t* coeff) { switch (coeff->discr){ case AP_COEFF_SCALAR: ap_scalar_free(coeff->val.scalar); break; case AP_COEFF_INTERVAL: ap_interval_free(coeff->val.interval); break; } free(coeff); } void ap_coeff_fprint(FILE* stream, ap_coeff_t* a) { switch(a->discr){ case AP_COEFF_SCALAR: ap_scalar_fprint(stream,a->val.scalar); break; case AP_COEFF_INTERVAL: ap_interval_fprint(stream,a->val.interval); break; } } void ap_coeff_reduce(ap_coeff_t* coeff) { if (coeff->discr==AP_COEFF_INTERVAL){ if (ap_scalar_equal(coeff->val.interval->inf,coeff->val.interval->sup)){ /* We cheat with the good rules */ ap_scalar_t* scalar = coeff->val.interval->inf; ap_scalar_free(coeff->val.interval->sup); free(coeff->val.interval); coeff->val.scalar = scalar; coeff->discr=AP_COEFF_SCALAR; } } } /* ====================================================================== */ /* Combined allocation and assignment */ /* ====================================================================== */ ap_coeff_t* ap_coeff_alloc_set_scalar(ap_scalar_t* scalar) { ap_coeff_t* coeff = malloc(sizeof(ap_coeff_t)); coeff->discr = AP_COEFF_SCALAR; coeff->val.scalar = ap_scalar_alloc_set(scalar); return coeff; } ap_coeff_t* ap_coeff_alloc_set_interval(ap_interval_t* interval) { ap_coeff_t* coeff = malloc(sizeof(ap_coeff_t)); coeff->discr = AP_COEFF_INTERVAL; coeff->val.interval = ap_interval_alloc_set(interval); return coeff; } ap_coeff_t* ap_coeff_alloc_set(ap_coeff_t* coeff) { switch (coeff->discr){ case AP_COEFF_SCALAR: return ap_coeff_alloc_set_scalar(coeff->val.scalar); case AP_COEFF_INTERVAL: return ap_coeff_alloc_set_interval(coeff->val.interval); break; default: return NULL; } } /* ====================================================================== */ /* Assignments */ /* ====================================================================== */ void ap_coeff_set(ap_coeff_t* a, ap_coeff_t* b) { if(a->discr != b->discr){ ap_coeff_reinit(a,b->discr,AP_SCALAR_DOUBLE); } switch(b->discr){ case AP_COEFF_SCALAR: ap_scalar_set(a->val.scalar,b->val.scalar); break; case AP_COEFF_INTERVAL: ap_interval_set(a->val.interval,b->val.interval); break; } } void ap_coeff_set_scalar(ap_coeff_t* coeff, ap_scalar_t* scalar) { ap_coeff_reinit(coeff,AP_COEFF_SCALAR,scalar->discr); ap_scalar_set(coeff->val.scalar,scalar); } void ap_coeff_set_scalar_mpq(ap_coeff_t* coeff, mpq_t mpq) { ap_coeff_reinit(coeff,AP_COEFF_SCALAR,AP_SCALAR_MPQ); ap_scalar_set_mpq(coeff->val.scalar,mpq); } void ap_coeff_set_scalar_mpfr(ap_coeff_t* coeff, mpfr_t mpfr) { ap_coeff_reinit(coeff,AP_COEFF_SCALAR,AP_SCALAR_MPFR); ap_scalar_set_mpfr(coeff->val.scalar,mpfr); } void ap_coeff_set_scalar_int(ap_coeff_t* coeff, long int num) { ap_coeff_reinit(coeff,AP_COEFF_SCALAR,AP_SCALAR_MPQ); ap_scalar_set_int(coeff->val.scalar,num); } void ap_coeff_set_scalar_frac(ap_coeff_t* coeff, long int num, unsigned long int den) { ap_coeff_reinit(coeff,AP_COEFF_SCALAR,AP_SCALAR_MPQ); ap_scalar_set_frac(coeff->val.scalar,num,den); } void ap_coeff_set_scalar_double(ap_coeff_t* coeff, double num) { ap_coeff_reinit(coeff,AP_COEFF_SCALAR,AP_SCALAR_DOUBLE); ap_scalar_set_double(coeff->val.scalar,num); } void ap_coeff_set_interval(ap_coeff_t* coeff, ap_interval_t* itv) { ap_coeff_reinit(coeff,AP_COEFF_INTERVAL,AP_SCALAR_DOUBLE); ap_interval_set(coeff->val.interval,itv); } void ap_coeff_set_interval_scalar(ap_coeff_t* coeff, ap_scalar_t* inf, ap_scalar_t* sup) { ap_coeff_reinit(coeff,AP_COEFF_INTERVAL,AP_SCALAR_DOUBLE); ap_interval_set_scalar(coeff->val.interval,inf,sup); } void ap_coeff_set_interval_mpq(ap_coeff_t* coeff, mpq_t inf, mpq_t sup) { ap_coeff_reinit(coeff,AP_COEFF_INTERVAL,AP_SCALAR_MPQ); ap_interval_set_mpq(coeff->val.interval,inf,sup); } void ap_coeff_set_interval_mpfr(ap_coeff_t* coeff, mpfr_t inf, mpfr_t sup) { ap_coeff_reinit(coeff,AP_COEFF_INTERVAL,AP_SCALAR_MPFR); ap_interval_set_mpfr(coeff->val.interval,inf,sup); } void ap_coeff_set_interval_int(ap_coeff_t* coeff, long int inf, long int sup) { ap_coeff_reinit(coeff,AP_COEFF_INTERVAL,AP_SCALAR_MPQ); ap_interval_set_int(coeff->val.interval,inf,sup); } void ap_coeff_set_interval_frac(ap_coeff_t* coeff, long int numinf, unsigned long int deninf, long int numsup, unsigned long int densup) { ap_coeff_reinit(coeff,AP_COEFF_INTERVAL,AP_SCALAR_MPQ); ap_interval_set_frac(coeff->val.interval,numinf,deninf,numsup,densup); } void ap_coeff_set_interval_double(ap_coeff_t* coeff, double inf, double sup) { ap_coeff_reinit(coeff,AP_COEFF_INTERVAL,AP_SCALAR_DOUBLE); ap_interval_set_double(coeff->val.interval,inf,sup); } void ap_coeff_set_interval_top(ap_coeff_t* coeff) { if (coeff->discr == AP_COEFF_SCALAR) ap_coeff_reinit(coeff,AP_COEFF_INTERVAL,AP_SCALAR_DOUBLE); ap_interval_set_top(coeff->val.interval); } /* ====================================================================== */ /* Tests */ /* ====================================================================== */ int ap_coeff_cmp(ap_coeff_t* coeff1, ap_coeff_t* coeff2) { if (coeff1->discr==coeff2->discr){ switch (coeff1->discr){ case AP_COEFF_SCALAR: return ap_scalar_cmp(coeff1->val.scalar,coeff2->val.scalar); case AP_COEFF_INTERVAL: return ap_interval_cmp(coeff1->val.interval,coeff2->val.interval); default: abort(); return 0; } } else { return (coeff1->discr==AP_COEFF_SCALAR) ? -3 : 3; } } bool ap_coeff_equal(ap_coeff_t* coeff1, ap_coeff_t* coeff2) { if (coeff1->discr==coeff2->discr){ switch (coeff1->discr){ case AP_COEFF_SCALAR: return ap_scalar_equal(coeff1->val.scalar,coeff2->val.scalar); case AP_COEFF_INTERVAL: return ap_interval_equal(coeff1->val.interval,coeff2->val.interval); default: abort(); } } else return false; } bool ap_coeff_zero(ap_coeff_t* coeff) { switch (coeff->discr){ case AP_COEFF_SCALAR: return ap_scalar_sgn(coeff->val.scalar)==0; case AP_COEFF_INTERVAL: return (ap_scalar_sgn(coeff->val.interval->inf)==0) && (ap_scalar_sgn(coeff->val.interval->sup)==0); default: abort(); } } bool ap_coeff_equal_int(ap_coeff_t* coeff, int i) { switch (coeff->discr){ case AP_COEFF_SCALAR: return ap_scalar_equal_int(coeff->val.scalar,i)==0; case AP_COEFF_INTERVAL: return (ap_scalar_equal_int(coeff->val.interval->inf,i)==0) && (ap_scalar_equal_int(coeff->val.interval->sup,i)==0); default: abort(); } } /* ====================================================================== */ /* Other operations */ /* ====================================================================== */ void ap_coeff_neg(ap_coeff_t* a, ap_coeff_t* b) { ap_coeff_set(a,b); switch(b->discr){ case AP_COEFF_SCALAR: ap_scalar_neg(a->val.scalar,b->val.scalar); break; case AP_COEFF_INTERVAL: ap_interval_neg(a->val.interval,b->val.interval); break; default: abort(); } } /* Hash */ long ap_coeff_hash(ap_coeff_t* coeff) { switch (coeff->discr){ case AP_COEFF_SCALAR: return ap_scalar_hash(coeff->val.scalar); case AP_COEFF_INTERVAL: return ap_interval_hash(coeff->val.interval); default: abort(); return 0; } } apron-dist-0.9.10/apron/apron/ap_tcons0.h0000640014525101416610000002106510656607177020065 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_tcons0.h: tree expressions constraints and arrays */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ /* normally included from ap_expr0.h */ #ifndef _AP_TCONS0_H_ #define _AP_TCONS0_H_ #include #include #include #include "ap_coeff.h" #include "ap_texpr0.h" #include "ap_lincons0.h" #ifdef __cplusplus extern "C" { #endif /* Datatypes */ /* ====================================================================== */ /* Represents the constraint "expr constyp 0" */ typedef struct ap_tcons0_t { ap_texpr0_t* texpr0; /* expression */ ap_constyp_t constyp; /* type of constraint */ ap_scalar_t* scalar; /* maybe NULL. For EQMOD constraint, indicates the modulo */ } ap_tcons0_t; /* Array of constraints */ typedef struct ap_tcons0_array_t { ap_tcons0_t* p; size_t size; } ap_tcons0_array_t; /* ********************************************************************** */ /* I. ap_tcons0_t */ /* ********************************************************************** */ /* ====================================================================== */ /* I.1 Memory management and printing */ /* ====================================================================== */ static inline ap_tcons0_t ap_tcons0_make(ap_constyp_t constyp, ap_texpr0_t* texpr, ap_scalar_t* scalar); /* Create a constraint of given type with the given expression. The expression and the coefficient are not duplicated, just pointed to */ ap_tcons0_t ap_tcons0_make_unsat(void); /* Create the constraint -1>=0 */ static inline ap_tcons0_t ap_tcons0_from_lincons0(ap_lincons0_t* cons); /* From linear constraint to comb-like tree expression constraint */ static inline ap_tcons0_t ap_tcons0_copy(ap_tcons0_t* cons); /* Duplication */ static inline void ap_tcons0_clear(ap_tcons0_t* cons); /* Free the linear expression of the constraint and set pointer to NULL */ void ap_tcons0_fprint(FILE* stream, ap_tcons0_t* cons, char** name_of_dim); /* Printing a linear constraint */ /* ====================================================================== */ /* I.2 Tests */ /* ====================================================================== */ static inline bool ap_tcons0_is_interval_cst(ap_tcons0_t* a); /* no-variable, only constant leaves */ static inline bool ap_tcons0_is_interval_linear(ap_tcons0_t* a); /* linear with possibly interval coefficients, no rounding */ static inline bool ap_tcons0_is_interval_polynomial(ap_tcons0_t* a); /* polynomial with possibly interval coefficients, no rounding */ static inline bool ap_tcons0_is_interval_polyfrac(ap_tcons0_t* a); /* polynomial fraction with possibly interval coefficients, no rounding */ static inline bool ap_tcons0_is_scalar(ap_tcons0_t* a); /* all coefficients are scalar (non-interval) */ /* ====================================================================== */ /* I.3 Change of dimensions and permutations */ /* ====================================================================== */ static inline void ap_tcons0_add_dimensions_with(ap_tcons0_t* cons, ap_dimchange_t* dimchange); static inline ap_tcons0_t ap_tcons0_add_dimensions(ap_tcons0_t* cons, ap_dimchange_t* dimchange); static inline void ap_tcons0_remove_dimensions_with(ap_tcons0_t* cons, ap_dimchange_t* dimchange); static inline ap_tcons0_t ap_tcons0_remove_dimensions(ap_tcons0_t* cons, ap_dimchange_t* dimchange); static inline void ap_tcons0_permute_dimensions_with(ap_tcons0_t* cons, ap_dimperm_t* perm); static inline ap_tcons0_t ap_tcons0_permute_dimensions(ap_tcons0_t* cons, ap_dimperm_t* perm); /* ********************************************************************** */ /* II. Array of linear constraints */ /* ********************************************************************** */ ap_tcons0_array_t ap_tcons0_array_make(size_t size); /* Allocate an array of size constraints. The constraints are initialized with NULL pointers, */ void ap_tcons0_array_resize(ap_tcons0_array_t* array, size_t size); /* Resize an array of size constraints. New constraints are initialized with NULL pointers, Removed constraints with non-NULL pointers are deallocated */ void ap_tcons0_array_clear(ap_tcons0_array_t* array); /* Clear the constraints of the array, and then the array itself */ void ap_tcons0_array_fprint(FILE* stream, ap_tcons0_array_t* ap_tcons0_array, char** name_of_dim); /* Printing */ bool ap_tcons0_array_is_interval_linear(ap_tcons0_array_t* array); /* Are all the expressions involved interval linear ? */ /* ====================================================================== */ /* II.1 Change of dimensions and permutations */ /* ====================================================================== */ void ap_tcons0_array_add_dimensions_with(ap_tcons0_array_t* array, ap_dimchange_t* dimchange); ap_tcons0_array_t ap_tcons0_array_add_dimensions(ap_tcons0_array_t* array, ap_dimchange_t* dimchange); void ap_tcons0_array_remove_dimensions_with(ap_tcons0_array_t* array, ap_dimchange_t* dimchange); ap_tcons0_array_t ap_tcons0_array_remove_dimensions(ap_tcons0_array_t* array, ap_dimchange_t* dimchange); void ap_tcons0_array_permute_dimensions_with(ap_tcons0_array_t* array, ap_dimperm_t* perm); ap_tcons0_array_t ap_tcons0_array_permute_dimensions(ap_tcons0_array_t* array, ap_dimperm_t* perm); /* ********************************************************************** */ /* III. Inline functions definitions */ /* ********************************************************************** */ static inline ap_tcons0_t ap_tcons0_make(ap_constyp_t constyp, ap_texpr0_t* texpr, ap_scalar_t* scalar) { ap_tcons0_t cons; cons.constyp = constyp; cons.texpr0 = texpr; cons.scalar = scalar; return cons; } static inline ap_tcons0_t ap_tcons0_from_lincons0(ap_lincons0_t* cons) { ap_tcons0_t res; res.texpr0 = ap_texpr0_from_linexpr0(cons->linexpr0); res.constyp = cons->constyp; res.scalar = cons->scalar ? ap_scalar_alloc_set(cons->scalar) : NULL; return res; } static inline ap_tcons0_t ap_tcons0_copy(ap_tcons0_t* cons) { return ap_tcons0_make(cons->constyp, ap_texpr0_copy(cons->texpr0), cons->scalar ? ap_scalar_alloc_set(cons->scalar) : NULL); } static inline void ap_tcons0_clear(ap_tcons0_t* tcons) { if (tcons->texpr0){ ap_texpr0_free(tcons->texpr0); } tcons->texpr0 = NULL; if (tcons->scalar){ ap_scalar_free(tcons->scalar); } tcons->scalar = NULL; } static inline bool ap_tcons0_is_interval_cst(ap_tcons0_t* a) { return ap_texpr0_is_interval_cst(a->texpr0); } static inline bool ap_tcons0_is_interval_linear(ap_tcons0_t* a) { return ap_texpr0_is_interval_linear(a->texpr0); } static inline bool ap_tcons0_is_interval_polynomial(ap_tcons0_t* a) { return ap_texpr0_is_interval_polynomial(a->texpr0); } static inline bool ap_tcons0_is_interval_polyfrac(ap_tcons0_t* a) { return ap_texpr0_is_interval_polyfrac(a->texpr0); } static inline bool ap_tcons0_is_scalar(ap_tcons0_t* a) { return ap_texpr0_is_scalar(a->texpr0); } static inline void ap_tcons0_add_dimensions_with(ap_tcons0_t* cons, ap_dimchange_t* dimchange) { ap_texpr0_add_dimensions_with(cons->texpr0,dimchange); } static inline ap_tcons0_t ap_tcons0_add_dimensions(ap_tcons0_t* cons, ap_dimchange_t* dimchange) { return ap_tcons0_make(cons->constyp, ap_texpr0_add_dimensions(cons->texpr0,dimchange), cons->scalar ? ap_scalar_alloc_set(cons->scalar) : NULL); } static inline void ap_tcons0_remove_dimensions_with(ap_tcons0_t* cons, ap_dimchange_t* dimchange) { ap_texpr0_remove_dimensions_with(cons->texpr0,dimchange); } static inline ap_tcons0_t ap_tcons0_remove_dimensions(ap_tcons0_t* cons, ap_dimchange_t* dimchange) { return ap_tcons0_make(cons->constyp, ap_texpr0_remove_dimensions(cons->texpr0,dimchange), cons->scalar ? ap_scalar_alloc_set(cons->scalar) : NULL); } static inline void ap_tcons0_permute_dimensions_with(ap_tcons0_t* cons, ap_dimperm_t* perm) { ap_texpr0_permute_dimensions_with(cons->texpr0,perm); } static inline ap_tcons0_t ap_tcons0_permute_dimensions(ap_tcons0_t* cons, ap_dimperm_t* perm) { return ap_tcons0_make(cons->constyp, ap_texpr0_permute_dimensions(cons->texpr0,perm), cons->scalar ? ap_scalar_alloc_set(cons->scalar) : NULL); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/ap_texpr0.c0000640014525101416610000005344711122224023020053 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_texpr0.c: tree expressions */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "ap_texpr0.h" #include "ap_linearize.h" #include /* ====================================================================== */ /* I. Constructors and Destructors */ /* ====================================================================== */ ap_texpr0_t* ap_texpr0_cst(ap_coeff_t* coeff) { ap_texpr0_t* res = malloc(sizeof(ap_texpr0_t)); res->discr = AP_TEXPR_CST; ap_coeff_init_set(&res->val.cst,coeff); return res; } ap_texpr0_t* ap_texpr0_cst_scalar(ap_scalar_t* scalar) { ap_texpr0_t* res = (ap_texpr0_t*) malloc(sizeof(ap_texpr0_t)); res->discr = AP_TEXPR_CST; ap_coeff_init(&res->val.cst, AP_COEFF_SCALAR); ap_coeff_set_scalar(&res->val.cst, scalar); return res; } ap_texpr0_t* ap_texpr0_cst_scalar_mpq(mpq_t mpq) { ap_texpr0_t* res = (ap_texpr0_t*) malloc(sizeof(ap_texpr0_t)); res->discr = AP_TEXPR_CST; ap_coeff_init(&res->val.cst, AP_COEFF_SCALAR); ap_coeff_set_scalar_mpq(&res->val.cst, mpq); return res; } ap_texpr0_t* ap_texpr0_cst_scalar_mpfr(mpfr_t mpfr) { ap_texpr0_t* res = (ap_texpr0_t*) malloc(sizeof(ap_texpr0_t)); res->discr = AP_TEXPR_CST; ap_coeff_init(&res->val.cst, AP_COEFF_SCALAR); ap_coeff_set_scalar_mpfr(&res->val.cst, mpfr); return res; } ap_texpr0_t* ap_texpr0_cst_scalar_int(long int num) { ap_texpr0_t* res = (ap_texpr0_t*) malloc(sizeof(ap_texpr0_t)); res->discr = AP_TEXPR_CST; ap_coeff_init(&res->val.cst, AP_COEFF_SCALAR); ap_coeff_set_scalar_int(&res->val.cst, num); return res; } ap_texpr0_t* ap_texpr0_cst_scalar_frac(long int num, unsigned long int den) { ap_texpr0_t* res = (ap_texpr0_t*) malloc(sizeof(ap_texpr0_t)); res->discr = AP_TEXPR_CST; ap_coeff_init(&res->val.cst, AP_COEFF_SCALAR); ap_coeff_set_scalar_frac(&res->val.cst, num, den); return res; } ap_texpr0_t* ap_texpr0_cst_scalar_double(double num) { ap_texpr0_t* res = (ap_texpr0_t*) malloc(sizeof(ap_texpr0_t)); res->discr = AP_TEXPR_CST; ap_coeff_init(&res->val.cst, AP_COEFF_SCALAR); ap_coeff_set_scalar_double(&res->val.cst, num); return res; } ap_texpr0_t* ap_texpr0_cst_interval(ap_interval_t* itv) { ap_texpr0_t* res = (ap_texpr0_t*) malloc(sizeof(ap_texpr0_t)); res->discr = AP_TEXPR_CST; ap_coeff_init(&res->val.cst, AP_COEFF_INTERVAL); ap_coeff_set_interval(&res->val.cst, itv); return res; } ap_texpr0_t* ap_texpr0_cst_interval_scalar(ap_scalar_t* inf, ap_scalar_t* sup) { ap_texpr0_t* res = (ap_texpr0_t*) malloc(sizeof(ap_texpr0_t)); res->discr = AP_TEXPR_CST; ap_coeff_init(&res->val.cst, AP_COEFF_INTERVAL); ap_coeff_set_interval_scalar(&res->val.cst, inf, sup); return res; } ap_texpr0_t* ap_texpr0_cst_interval_mpq(mpq_t inf, mpq_t sup) { ap_texpr0_t* res = (ap_texpr0_t*) malloc(sizeof(ap_texpr0_t)); res->discr = AP_TEXPR_CST; ap_coeff_init(&res->val.cst, AP_COEFF_INTERVAL); ap_coeff_set_interval_mpq(&res->val.cst, inf, sup); return res; } ap_texpr0_t* ap_texpr0_cst_interval_mpfr(mpfr_t inf, mpfr_t sup) { ap_texpr0_t* res = (ap_texpr0_t*) malloc(sizeof(ap_texpr0_t)); res->discr = AP_TEXPR_CST; ap_coeff_init(&res->val.cst, AP_COEFF_INTERVAL); ap_coeff_set_interval_mpfr(&res->val.cst, inf, sup); return res; } ap_texpr0_t* ap_texpr0_cst_interval_int(long int inf, long int sup) { ap_texpr0_t* res = (ap_texpr0_t*) malloc(sizeof(ap_texpr0_t)); res->discr = AP_TEXPR_CST; ap_coeff_init(&res->val.cst, AP_COEFF_INTERVAL); ap_coeff_set_interval_int(&res->val.cst, inf, sup); return res; } ap_texpr0_t* ap_texpr0_cst_interval_frac(long int numinf, unsigned long int deninf, long int numsup, unsigned long int densup) { ap_texpr0_t* res = (ap_texpr0_t*) malloc(sizeof(ap_texpr0_t)); res->discr = AP_TEXPR_CST; ap_coeff_init(&res->val.cst, AP_COEFF_INTERVAL); ap_coeff_set_interval_frac(&res->val.cst, numinf, deninf, numsup, densup); return res; } ap_texpr0_t* ap_texpr0_cst_interval_double(double inf, double sup) { ap_texpr0_t* res = (ap_texpr0_t*) malloc(sizeof(ap_texpr0_t)); res->discr = AP_TEXPR_CST; ap_coeff_init(&res->val.cst, AP_COEFF_INTERVAL); ap_coeff_set_interval_double(&res->val.cst, inf, sup); return res; } ap_texpr0_t* ap_texpr0_cst_interval_top(void) { ap_texpr0_t* res = (ap_texpr0_t*) malloc(sizeof(ap_texpr0_t)); res->discr = AP_TEXPR_CST; ap_coeff_init(&res->val.cst, AP_COEFF_INTERVAL); ap_interval_set_top(res->val.cst.val.interval); return res; } ap_texpr0_t* ap_texpr0_dim(ap_dim_t dim) { ap_texpr0_t* res = malloc(sizeof(ap_texpr0_t)); res->discr = AP_TEXPR_DIM; res->val.dim = dim; return res; } ap_texpr0_t* ap_texpr0_node(ap_texpr_op_t op, ap_texpr_rtype_t type, ap_texpr_rdir_t dir, ap_texpr0_t* opA, ap_texpr0_t* opB) { ap_texpr0_node_t* node = malloc(sizeof(ap_texpr0_node_t)); node->op = op; node->type = type; node->dir = dir; node->exprA = opA; node->exprB = opB; ap_texpr0_t* res = malloc(sizeof(ap_texpr0_t)); res->discr = AP_TEXPR_NODE; res->val.node = node; return res; } ap_texpr0_t* ap_texpr0_unop(ap_texpr_op_t op, ap_texpr0_t* opA, ap_texpr_rtype_t type, ap_texpr_rdir_t dir) { if (!ap_texpr_is_unop(op)){ fprintf(stderr,"ap_texpr0.c: ap_texpr0_unop: unary operator expected\n"); abort(); } return ap_texpr0_node(op,type,dir,opA,NULL); } ap_texpr0_t* ap_texpr0_binop(ap_texpr_op_t op, ap_texpr0_t* opA, ap_texpr0_t* opB, ap_texpr_rtype_t type, ap_texpr_rdir_t dir) { if (!ap_texpr_is_binop(op)){ fprintf(stderr,"ap_texpr0.c: ap_texpr0_binop: binary operator expected\n"); abort(); } return ap_texpr0_node(op,type,dir,opA,opB); } ap_texpr0_t* ap_texpr0_node_copy(ap_texpr0_node_t* node) { ap_texpr0_t* res = malloc(sizeof(ap_texpr0_t)); ap_texpr0_node_t* n = malloc(sizeof(ap_texpr0_node_t)); res->discr = AP_TEXPR_NODE; res->val.node = n; n->op = node->op; n->type = node->type; n->dir = node->dir; n->exprA = ap_texpr0_copy(node->exprA); n->exprB = ap_texpr0_copy(node->exprB); return res; } ap_texpr0_t* ap_texpr0_copy(ap_texpr0_t* expr) { if (!expr) return NULL; switch (expr->discr){ case AP_TEXPR_CST: return ap_texpr0_cst(&expr->val.cst); case AP_TEXPR_DIM: return ap_texpr0_dim(expr->val.dim); case AP_TEXPR_NODE: return ap_texpr0_node_copy(expr->val.node); default: assert(false); return NULL; } } void ap_texpr0_node_free(ap_texpr0_node_t* node) { ap_texpr0_free(node->exprA); ap_texpr0_free(node->exprB); free(node); } void ap_texpr0_clear(ap_texpr0_t* expr) { switch(expr->discr){ case AP_TEXPR_CST: ap_coeff_clear(&expr->val.cst); break; case AP_TEXPR_DIM: break; case AP_TEXPR_NODE: ap_texpr0_node_free(expr->val.node); break; default: assert(false); } } void ap_texpr0_free(ap_texpr0_t* expr) { if (!expr) return; ap_texpr0_clear(expr); free(expr); } ap_texpr0_t* ap_texpr0_from_linexpr0(ap_linexpr0_t* e) { ap_texpr0_t* res = ap_texpr0_cst(&e->cst); size_t i; ap_dim_t d; ap_coeff_t* c; ap_linexpr0_ForeachLinterm(e, i, d, c) { res = ap_texpr0_binop(AP_TEXPR_ADD, res, ap_texpr0_binop(AP_TEXPR_MUL, ap_texpr0_cst(c), ap_texpr0_dim(d), AP_RTYPE_REAL, AP_RDIR_RND), AP_RTYPE_REAL, AP_RDIR_RND); } return res; } /* ====================================================================== */ /* II. Printing */ /* ====================================================================== */ static const char* ap_texpr_op_name[] = { "+", "-", "*", "/", "%", /* binary */ "-", "cast", "sqrt", /* unary */ }; static const int ap_texpr_op_precedence[] = { 1, 1, 2, 2, 2, /* binary */ 3, 4, 4 /* unary */ }; static const char* ap_texpr_rtype_name[] = { "", "i", "f", "d", "l", "q", }; static const char* ap_texpr_rdir_name[] = { "n", "0", "+oo", "-oo", "?", "", }; /* node induces some rounding (to float or integer) */ static inline bool ap_texpr0_node_exact(ap_texpr0_node_t* a) { if (a->op==AP_TEXPR_NEG || a->op==AP_TEXPR_MOD || a->type==AP_RTYPE_REAL) return true; return false; } static inline int ap_texpr0_precedence(ap_texpr0_t* a) { if (!a || a->discr!=AP_TEXPR_NODE) return ap_texpr_op_precedence[AP_TEXPR_NEG]; return ap_texpr_op_precedence[a->val.node->op]; } static void ap_texpr0_node_fprint(FILE* stream, ap_texpr0_node_t* a, char** name_of_dim) { int prec = ap_texpr_op_precedence[a->op]; /* left argument (if binary) */ if (a->exprB) { int prec2 = ap_texpr0_precedence(a->exprA); if (prec2exprA, name_of_dim); if (prec2exprB) fprintf(stream, " "); fprintf(stream, "%s", ap_texpr_op_name[a->op]); if (!ap_texpr0_node_exact(a)) fprintf(stream, "_%s,%s", ap_texpr_rtype_name[a->type], ap_texpr_rdir_name[a->dir]); /* right argument */ { ap_texpr0_t* arg = a->exprB ? a->exprB : a->exprA; int prec2 = ap_texpr0_precedence(arg); if (a->exprB) fprintf(stream, " "); if (prec2<=prec) fprintf(stream, "("); ap_texpr0_fprint(stream,arg,name_of_dim); if (prec2<=prec) fprintf(stream, ")"); } } void ap_texpr0_fprint(FILE* stream, ap_texpr0_t* a, char** name_of_dim) { if (!a) return; switch (a->discr) { case AP_TEXPR_CST: ap_coeff_fprint(stream, &a->val.cst); break; case AP_TEXPR_DIM: if (name_of_dim) fprintf(stream, "%s", name_of_dim[a->val.dim]); else fprintf(stream, "x%lu", (unsigned long)a->val.dim); break; case AP_TEXPR_NODE: ap_texpr0_node_fprint(stream, a->val.node, name_of_dim); break; default: assert(false); } } void ap_texpr0_print(ap_texpr0_t* a, char** name_of_dim) { ap_texpr0_fprint(stdout, a, name_of_dim); } /* ====================================================================== */ /* III. Tests, size */ /* ====================================================================== */ size_t ap_texpr0_depth(ap_texpr0_t* a) { int l,r; if (!a) return 0; switch(a->discr) { case AP_TEXPR_CST: case AP_TEXPR_DIM: return 0; case AP_TEXPR_NODE: l = ap_texpr0_depth(a->val.node->exprA); r = ap_texpr0_depth(a->val.node->exprB); return 1 + (l>r ? l : r); default: assert(0); return 0; } } size_t ap_texpr0_size(ap_texpr0_t* a) { if (!a) return 0; switch(a->discr) { case AP_TEXPR_CST: case AP_TEXPR_DIM: return 0; case AP_TEXPR_NODE: return 1 + ap_texpr0_size(a->val.node->exprA) + ap_texpr0_size(a->val.node->exprB); default: assert(0); return 0; } } /* maximum between all dimensions and max */ static ap_dim_t ap_texpr0_max_dim_internal(ap_texpr0_t* a, ap_dim_t max) { if (!a) return max; switch(a->discr) { case AP_TEXPR_CST: return max; case AP_TEXPR_DIM: return (a->val.dim+1) > max ? (a->val.dim+1) : max; case AP_TEXPR_NODE: return ap_texpr0_max_dim_internal(a->val.node->exprB, ap_texpr0_max_dim_internal(a->val.node->exprA,max)); default: assert(0); return max; } } ap_dim_t ap_texpr0_max_dim(ap_texpr0_t* a) { return ap_texpr0_max_dim_internal(a, 0); } bool ap_texpr0_has_dim(ap_texpr0_t* a, ap_dim_t d) { if (!a) return false; switch(a->discr) { case AP_TEXPR_CST: return false; case AP_TEXPR_DIM: return a->val.dim == d; case AP_TEXPR_NODE: return ap_texpr0_has_dim(a->val.node->exprA, d) || ap_texpr0_has_dim(a->val.node->exprB, d); default: assert(0); return false; } } /* fill in v, v should be pre-allocated with size max_dim */ static void ap_texpr0_dimlist_internal(ap_texpr0_t* a, char* v) { if (!a) return; switch(a->discr) { case AP_TEXPR_CST: break; case AP_TEXPR_DIM: v[a->val.dim] = 1; break; case AP_TEXPR_NODE: ap_texpr0_dimlist_internal(a->val.node->exprA, v); ap_texpr0_dimlist_internal(a->val.node->exprB, v); break; default: assert(0); } } ap_dim_t* ap_texpr0_dimlist(ap_texpr0_t* a) { ap_dim_t max,i,nb; ap_dim_t* d; char* v; /* compute occurence vector */ max = ap_texpr0_max_dim(a); if (max==0){ /* constant expression */ d = malloc(sizeof(ap_dim_t)); d[0] = AP_DIM_MAX; } else { /* get number of distinct variables */ v = malloc(max); memset(v, 0, max); ap_texpr0_dimlist_internal(a, v); for (i=0, nb=0; idiscr) { case AP_TEXPR_CST: return true; case AP_TEXPR_DIM: return false; case AP_TEXPR_NODE: return ap_texpr0_is_interval_cst(a->val.node->exprA) && ap_texpr0_is_interval_cst(a->val.node->exprB); default: assert(0); return false; } } bool ap_texpr0_is_scalar(ap_texpr0_t* a) { if (!a) return true; switch(a->discr) { case AP_TEXPR_CST: return (a->val.cst.discr==AP_COEFF_SCALAR) || (ap_scalar_equal(a->val.cst.val.interval->inf, a->val.cst.val.interval->sup)); case AP_TEXPR_DIM: return true; case AP_TEXPR_NODE: return ap_texpr0_is_scalar(a->val.node->exprA) && ap_texpr0_is_scalar(a->val.node->exprB); default: assert(0); return false; } } bool ap_texpr0_is_interval_linear(ap_texpr0_t* a) { if (!a) return true; switch(a->discr) { case AP_TEXPR_CST: case AP_TEXPR_DIM: return true; case AP_TEXPR_NODE: switch (a->val.node->op) { case AP_TEXPR_NEG: return ap_texpr0_is_interval_linear(a->val.node->exprA); case AP_TEXPR_CAST: return ap_texpr0_node_exact(a->val.node) && ap_texpr0_is_interval_linear(a->val.node->exprA); case AP_TEXPR_ADD: case AP_TEXPR_SUB: return ap_texpr0_node_exact(a->val.node) && ap_texpr0_is_interval_linear(a->val.node->exprA) && ap_texpr0_is_interval_linear(a->val.node->exprB); case AP_TEXPR_MUL: return ap_texpr0_node_exact(a->val.node) && ( (ap_texpr0_is_interval_linear(a->val.node->exprA) && ap_texpr0_is_interval_cst(a->val.node->exprB)) || (ap_texpr0_is_interval_linear(a->val.node->exprB) && ap_texpr0_is_interval_cst(a->val.node->exprA)) ); case AP_TEXPR_DIV: return ap_texpr0_node_exact(a->val.node) && ap_texpr0_is_interval_linear(a->val.node->exprA) && ap_texpr0_is_interval_cst(a->val.node->exprB); default: return false; } default: assert(0); return 0; } } bool ap_texpr0_is_interval_polynomial(ap_texpr0_t* a) { if (!a) return true; switch(a->discr) { case AP_TEXPR_CST: case AP_TEXPR_DIM: return true; case AP_TEXPR_NODE: switch (a->val.node->op) { case AP_TEXPR_NEG: return ap_texpr0_is_interval_polynomial(a->val.node->exprA); case AP_TEXPR_CAST: return ap_texpr0_node_exact(a->val.node) && ap_texpr0_is_interval_polynomial(a->val.node->exprA); case AP_TEXPR_ADD: case AP_TEXPR_SUB: case AP_TEXPR_MUL: return ap_texpr0_node_exact(a->val.node) && ap_texpr0_is_interval_polynomial(a->val.node->exprA) && ap_texpr0_is_interval_polynomial(a->val.node->exprB); case AP_TEXPR_DIV: return ap_texpr0_node_exact(a->val.node) && ap_texpr0_is_interval_polynomial(a->val.node->exprA) && ap_texpr0_is_interval_cst(a->val.node->exprB); default: return false; } default: assert(0); return 0; } } bool ap_texpr0_is_interval_polyfrac(ap_texpr0_t* a) { if (!a) return true; switch(a->discr) { case AP_TEXPR_CST: case AP_TEXPR_DIM: return true; case AP_TEXPR_NODE: switch (a->val.node->op) { case AP_TEXPR_NEG: return ap_texpr0_is_interval_polyfrac(a->val.node->exprA); case AP_TEXPR_CAST: return ap_texpr0_node_exact(a->val.node) && ap_texpr0_is_interval_polyfrac(a->val.node->exprA); case AP_TEXPR_ADD: case AP_TEXPR_SUB: case AP_TEXPR_MUL: case AP_TEXPR_DIV: return ap_texpr0_node_exact(a->val.node) && ap_texpr0_is_interval_polyfrac(a->val.node->exprA) && ap_texpr0_is_interval_polyfrac(a->val.node->exprB); default: return false; } default: assert(0); return 0; } } static bool ap_texpr0_array_is_template(ap_texpr0_t** texpr, size_t size, bool (*is_template)(ap_texpr0_t* texpr)) { size_t i; bool res = true; for (i=0; idiscr) { case AP_TEXPR_CST: return; case AP_TEXPR_DIM: if (a->val.dim!=dim) return; dst = ap_texpr0_copy(dst); *a = *dst; free(dst); return; case AP_TEXPR_NODE: ap_texpr0_substitute_with(a->val.node->exprA, dim, dst); ap_texpr0_substitute_with(a->val.node->exprB, dim, dst); break; default: assert(0); } } /* ====================================================================== */ /* V. Change of dimensions and permutations */ /* ====================================================================== */ ap_texpr0_t* ap_texpr0_add_dimensions(ap_texpr0_t* expr, ap_dimchange_t* dimchange) { ap_texpr0_t* res = ap_texpr0_copy(expr); ap_texpr0_add_dimensions_with(res,dimchange); return res; } void ap_texpr0_add_dimensions_with(ap_texpr0_t* expr, ap_dimchange_t* dimchange) { if (!expr) return; switch(expr->discr){ case AP_TEXPR_CST: return; case AP_TEXPR_DIM: { size_t dimsup = dimchange->intdim+dimchange->realdim; size_t k = 0; while (kval.dim>=dimchange->dim[k]){ k++; } expr->val.dim += k; } return; case AP_TEXPR_NODE: ap_texpr0_add_dimensions_with(expr->val.node->exprA,dimchange); ap_texpr0_add_dimensions_with(expr->val.node->exprB,dimchange); return; default: assert(false); } } ap_texpr0_t* ap_texpr0_remove_dimensions(ap_texpr0_t* expr, ap_dimchange_t* dimchange) { ap_texpr0_t* res = ap_texpr0_copy(expr); ap_texpr0_remove_dimensions_with(res,dimchange); return res; } void ap_texpr0_remove_dimensions_with(ap_texpr0_t* expr, ap_dimchange_t* dimchange) { if (!expr) return; switch(expr->discr){ case AP_TEXPR_CST: return; case AP_TEXPR_DIM: { size_t dimrem = dimchange->intdim+dimchange->realdim; size_t i; for (i=0;ival.dim>dimchange->dim[i];i++); if (ival.dim==dimchange->dim[i]) { /* replace variable with top */ expr->discr = AP_TEXPR_CST; ap_coeff_init(&expr->val.cst, AP_COEFF_INTERVAL); ap_interval_set_top(expr->val.cst.val.interval); } else expr->val.dim -= i; } return; case AP_TEXPR_NODE: ap_texpr0_remove_dimensions_with(expr->val.node->exprA,dimchange); ap_texpr0_remove_dimensions_with(expr->val.node->exprB,dimchange); return; default: assert(false); } } ap_texpr0_t* ap_texpr0_permute_dimensions(ap_texpr0_t* expr, ap_dimperm_t* dimperm) { ap_texpr0_t* res = ap_texpr0_copy(expr); ap_texpr0_permute_dimensions_with(res,dimperm); return res; } void ap_texpr0_permute_dimensions_with(ap_texpr0_t* expr, ap_dimperm_t* perm) { if (!expr) return; switch(expr->discr){ case AP_TEXPR_CST: return; case AP_TEXPR_DIM: expr->val.dim = perm->dim[expr->val.dim]; return; case AP_TEXPR_NODE: ap_texpr0_permute_dimensions_with(expr->val.node->exprA,perm); ap_texpr0_permute_dimensions_with(expr->val.node->exprB,perm); return; default: assert(false); } } /* ====================================================================== */ /* VI. Hashing, comparisons */ /* ====================================================================== */ long ap_texpr0_hash(ap_texpr0_t* a) { if (!a) return 0; switch(a->discr) { case AP_TEXPR_CST: return ap_coeff_hash(&a->val.cst); case AP_TEXPR_DIM: return a->val.dim; case AP_TEXPR_NODE: return a->val.node->op * 17 + a->val.node->type * 23 + a->val.node->dir * 4801 + ap_texpr0_hash(a->val.node->exprA) * 17053 + ap_texpr0_hash(a->val.node->exprB); default: assert(0); return 0; } } bool ap_texpr0_equal(ap_texpr0_t* a1, ap_texpr0_t* a2) { if (!a1 && !a2) return true; if (!a1 || !a2) return false; if (a1->discr!=a2->discr) return false; switch(a1->discr) { case AP_TEXPR_CST: return ap_coeff_equal(&a1->val.cst, &a2->val.cst); case AP_TEXPR_DIM: return a1->val.dim==a2->val.dim; case AP_TEXPR_NODE: return (a1->val.node->op==a2->val.node->op) && (a1->val.node->type==a2->val.node->type) && (a1->val.node->dir==a2->val.node->dir) && ap_texpr0_equal(a1->val.node->exprA, a2->val.node->exprA) && ap_texpr0_equal(a1->val.node->exprB, a2->val.node->exprB); default: assert(0); return false; } } apron-dist-0.9.10/apron/apron/ap_linearize_aux.c0000640014525101416610000003770711122224307021476 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_linearize_aux.c: auxiliary functions for (quasi)linearisation */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ /* Auxiliary module to ap_linearize, which contains functions depending of the number representation */ #include "ap_linearize.h" #include "ap_linearize_aux.h" #include "num.h" #include "bound.h" #include "itv.h" #include "itv_linexpr.h" #include "itv_linearize.h" static bool intlinearize_alloc(ap_manager_t* man, ap_abstract0_t* abs, itv_internal_t* intern, itv_t** penv, ap_dimension_t* pdim) { size_t size; ap_interval_t** tinterval = ap_abstract0_to_box(man,abs); bool exact = man->result.flag_exact; assert(!ap_abstract0_is_bottom(man,abs)); *pdim = ap_abstract0_dimension(man,abs); size = pdim->intdim+pdim->realdim; exact = itv_array_set_ap_interval_array(intern,penv,tinterval,size) && exact; ap_interval_array_free(tinterval,size); return exact; } static inline void intlinearize_free(itv_internal_t* intern, itv_t* env, ap_dimension_t dim) { if (env) itv_array_free(env,dim.intdim+dim.realdim); itv_internal_clear(intern); } /* ********************************************************************** */ /* I. Evaluation of interval linear expressions */ /* ********************************************************************** */ ap_interval_t* ITVFUN(ap_eval_linexpr0)(ap_manager_t* man, ap_abstract0_t* abs, ap_linexpr0_t* expr, bool* pexact) { bool exact; itv_internal_t* intern; ap_dimension_t dim; ap_interval_t** aenv; itv_t* env; itv_t res; ap_interval_t* r = ap_interval_alloc(); if (pexact) *pexact = true; aenv = ap_abstract0_to_box(man,abs); if (!aenv) { ap_interval_set_bottom(r); return r; } dim = ap_abstract0_dimension(man,abs); intern = itv_internal_alloc(); itv_init(res); itv_array_set_ap_interval_array(intern,&env,aenv,dim.intdim+dim.realdim); exact = itv_eval_ap_linexpr0(intern,res,expr,env); if (pexact) *pexact = exact; ap_interval_set_itv(intern,r,res); itv_internal_free(intern); ap_interval_array_free(aenv,dim.intdim+dim.realdim); itv_array_free(env,dim.intdim+dim.realdim); itv_clear(res); return r; } /* ********************************************************************** */ /* II. Quasilinearization of interval linear expressions */ /* ********************************************************************** */ static bool quasilinearize_alloc(ap_manager_t* man, ap_abstract0_t* abs, itv_internal_t** pintern, itv_lincons_t* plincons, itv_t** penv, ap_dimension_t* pdim) { bool exact,exact2; ap_interval_t** tinterval; size_t size; assert(!ap_abstract0_is_bottom(man,abs)); exact = true; tinterval = ap_abstract0_to_box(man,abs); exact = man->result.flag_exact && exact; *pdim = ap_abstract0_dimension(man,abs); size = pdim->intdim+pdim->realdim; *pintern = itv_internal_alloc(); exact = itv_array_set_ap_interval_array(*pintern,penv,tinterval,size) && exact; ap_interval_array_free(tinterval,size); itv_lincons_init(plincons); return exact; } static inline void quasilinearize_free(itv_internal_t* intern, itv_lincons_t* lincons, itv_t* env, ap_dimension_t dim) { itv_lincons_clear(lincons); itv_array_free(env,dim.intdim+dim.realdim); itv_internal_free(intern); } /* Evaluate a interval linear expression on the abstract value such as to transform it into a quasilinear expression. discr allows to choose the type of scalars used for computations and for the result. pexact is a pointer to a Boolean, which is set to true if all the conversions and computations were exact. */ ap_linexpr0_t* ITVFUN(ap_quasilinearize_linexpr0)(ap_manager_t* man, ap_abstract0_t* abs, ap_linexpr0_t* linexpr0, bool* pexact) { ap_dimension_t dim; ap_linexpr0_t* rlinexpr0; itv_internal_t* intern; itv_lincons_t lincons; itv_t* env; bool exact,exact2; exact = quasilinearize_alloc(man,abs,&intern,&lincons,&env,&dim); exact = itv_linexpr_set_ap_linexpr0(intern,&lincons.linexpr,linexpr0) && exact; exact = itv_quasilinearize_linexpr(intern,&lincons.linexpr,env,false) && exact; rlinexpr0 = NULL; ap_linexpr0_set_itv_linexpr(intern,&rlinexpr0,&lincons.linexpr); quasilinearize_free(intern,&lincons,env,dim); *pexact = exact; return rlinexpr0; } /* Same for ap_lincons0_t */ ap_lincons0_t ITVFUN(ap_quasilinearize_lincons0)(ap_manager_t* man, ap_abstract0_t* abs, ap_lincons0_t* lincons0, bool* pexact, bool meet) { ap_dimension_t dim; ap_lincons0_t rlincons0; itv_internal_t* intern; itv_lincons_t lincons; itv_t* env; bool exact,exact2; exact = quasilinearize_alloc(man,abs,&intern,&lincons,&env,&dim); exact = itv_lincons_set_ap_lincons0(intern,&lincons,lincons0) && exact; exact = itv_quasilinearize_lincons(intern,&lincons,env,meet) && exact; rlincons0 = ap_lincons0_make(AP_CONS_EQ, ap_linexpr0_alloc(AP_LINEXPR_SPARSE,0), NULL); ap_lincons0_set_itv_lincons(intern,&rlincons0,&lincons); quasilinearize_free(intern,&lincons,env,dim); *pexact = exact; return rlincons0; } /* Same for arrays of ap_linexpr0_t */ ap_linexpr0_t** ITVFUN(ap_quasilinearize_linexpr0_array)(ap_manager_t* man, ap_abstract0_t* abs, ap_linexpr0_t** texpr, size_t size, bool* pexact) { ap_dimension_t dim; ap_linexpr0_t** tab; itv_internal_t* intern; itv_lincons_t lincons; itv_t* env; bool exact,exact2; size_t i; exact = quasilinearize_alloc(man,abs,&intern,&lincons,&env,&dim); tab = (ap_linexpr0_t**)malloc(size*sizeof(ap_linexpr0_t*)); for (i=0; isize); exact = itv_lincons_array_set_ap_lincons0_array(intern,&tlincons,array) && exact; exact = itv_quasilinearize_lincons_array(intern,&tlincons,env,meet); if (linearize) itv_linearize_lincons_array(intern,&tlincons,meet); res = ap_lincons0_array_make(tlincons.size); for (i=0;isize); itv_intlinearize_ap_tcons0_array(&intern,&tlincons, array,env, dim.intdim); if (tlincons.size==1 && tlincons.p[0].linexpr.size==0) goto ap_intlinearize_tcons0_array_exit; if (meet && boxize && (intervalonly ? !itv_lincons_array_is_quasilinear(&tlincons) : true)){ tchange = malloc((dim.intdim+dim.realdim)*2); for (i=0;i<(dim.intdim+dim.realdim)*2;i++) tchange[i]=false; change = itv_boxize_lincons_array(&intern,env,tchange,&tlincons,env,dim.intdim,kmax,intervalonly); } switch(linearize){ case AP_LINEXPR_INTLINEAR: break; case AP_LINEXPR_QUASILINEAR: itv_quasilinearize_lincons_array(&intern,&tlincons,env,meet); break; case AP_LINEXPR_LINEAR: itv_quasilinearize_lincons_array(&intern,&tlincons,env,meet); itv_linearize_lincons_array(&intern,&tlincons,meet); break; } if (tlincons.size==1 && tlincons.p[0].linexpr.size==0 && itv_eval_cstlincons(&intern,&tlincons.p[0])==tbool_false) goto ap_intlinearize_tcons0_array_exit; if (change){ if (itv_is_bottom(&intern,env[0])){ itv_lincons_array_reinit(&tlincons,1); itv_lincons_set_bool(&tlincons.p[0],false); goto ap_intlinearize_tcons0_array_exit; } size_t size = tlincons.size; for (i=0;i=tlincons.size) itv_lincons_array_reinit(&tlincons,1+(5*tlincons.size)/4); itv_linexpr_reinit(&tlincons.p[size].linexpr,1); tlincons.p[size].linexpr.linterm[0].dim = i; tlincons.p[size].linexpr.linterm[0].equality = true; tlincons.p[size].linexpr.equality = true; } if ((tchange[2*i] || tchange[2*i+1]) && itv_is_point(&intern,env[i])){ /* We have a point */ tlincons.p[size].constyp = AP_CONS_EQ; itv_set_int(tlincons.p[size].linexpr.linterm[0].itv,-1); itv_set(tlincons.p[size].linexpr.cst, env[i]); size++; } else { if (tchange[2*i]){ /* inf bound */ assert(!bound_infty(env[i]->inf)); tlincons.p[size].constyp = AP_CONS_SUPEQ; itv_set_int(tlincons.p[size].linexpr.linterm[0].itv,1); itv_set_num(tlincons.p[size].linexpr.cst,bound_numref(env[i]->inf)); size ++; } if (tchange[2*i+1]){ /* sup bound */ if (tchange[2*i]){ /* we add a new row and prepare it */ if (size>=tlincons.size) itv_lincons_array_reinit(&tlincons,1+(5*tlincons.size)/4); itv_linexpr_reinit(&tlincons.p[size].linexpr,1); tlincons.p[size].linexpr.linterm[0].dim = i; tlincons.p[size].linexpr.linterm[0].equality = true; tlincons.p[size].linexpr.equality = true; } assert(!bound_infty(env[i]->sup)); tlincons.p[size].constyp = AP_CONS_SUPEQ; itv_set_int(tlincons.p[size].linexpr.linterm[0].itv,-1); itv_set_num(tlincons.p[size].linexpr.cst, bound_numref(env[i]->sup)); size++; } } } itv_lincons_array_reinit(&tlincons,size); } ap_intlinearize_tcons0_array_exit: res = ap_lincons0_array_make(tlincons.size); for (i=0;i #include #include #include #include "ap_scalar.h" /* ====================================================================== */ /* Basics */ /* ====================================================================== */ ap_scalar_t* ap_scalar_alloc() { ap_scalar_t* scalar = malloc(sizeof(ap_scalar_t)); scalar->discr = AP_SCALAR_DOUBLE; scalar->val.dbl = 0.0; return scalar; } void ap_scalar_reinit(ap_scalar_t* scalar, ap_scalar_discr_t d) { if (scalar->discr != d){ ap_scalar_clear(scalar); ap_scalar_init(scalar,d); } } void ap_scalar_free(ap_scalar_t* scalar) { ap_scalar_clear(scalar); free(scalar); } int ap_scalar_print_prec = 20; void ap_scalar_fprint(FILE* stream, ap_scalar_t* a) { int flag; flag = ap_scalar_infty(a); if (flag){ fprintf(stream, flag>0 ? "+oo" : "-oo"); } else { switch(a->discr){ case AP_SCALAR_DOUBLE: fprintf(stream,"%.*g",ap_scalar_print_prec,a->val.dbl + 0.0); break; case AP_SCALAR_MPQ: mpq_out_str(stream,10,a->val.mpq); break; case AP_SCALAR_MPFR: { double d = mpfr_get_d(a->val.mpfr,GMP_RNDU); if (mpfr_cmp_d(a->val.mpfr,d)) mpfr_out_str(stream,10,ap_scalar_print_prec,a->val.mpfr,GMP_RNDU); else fprintf(stream,"%.*g",ap_scalar_print_prec,d + 0.0); } break; default: abort(); } } } /* ====================================================================== */ /* Combined allocation and assignments */ /* ====================================================================== */ ap_scalar_t* ap_scalar_alloc_set(ap_scalar_t* b) { ap_scalar_t* a = malloc(sizeof(ap_scalar_t)); a->discr = b->discr; switch(b->discr){ case AP_SCALAR_DOUBLE: a->val.dbl = b->val.dbl; break; case AP_SCALAR_MPQ: a->val.mpq = malloc(sizeof(mpq_t)); mpq_init(a->val.mpq); mpq_set(a->val.mpq,b->val.mpq); break; case AP_SCALAR_MPFR: a->val.mpfr = malloc(sizeof(mpfr_t)); mpfr_init2(a->val.mpfr,mpfr_get_prec(b->val.mpfr)); mpfr_set(a->val.mpfr,b->val.mpfr,GMP_RNDU /* exact */); break; default: abort(); } return a; } ap_scalar_t* ap_scalar_alloc_set_mpq(mpq_t mpq) { ap_scalar_t* a = malloc(sizeof(ap_scalar_t)); a->discr = AP_SCALAR_MPQ; a->val.mpq = malloc(sizeof(mpq_t)); mpq_init(a->val.mpq); mpq_set(a->val.mpq,mpq); return a; } ap_scalar_t* ap_scalar_alloc_set_mpfr(mpfr_t mpfr) { ap_scalar_t* a = malloc(sizeof(ap_scalar_t)); a->discr = AP_SCALAR_MPFR; a->val.mpfr = malloc(sizeof(mpfr_t)); mpfr_init2(a->val.mpfr,mpfr_get_prec(mpfr)); mpfr_set(a->val.mpfr,mpfr,GMP_RNDU /* exact */); return a; } ap_scalar_t* ap_scalar_alloc_set_double(double k) { ap_scalar_t* a = malloc(sizeof(ap_scalar_t)); a->discr = AP_SCALAR_DOUBLE; a->val.dbl = k; return a; } /* ====================================================================== */ /* Assignments */ /* ====================================================================== */ void ap_scalar_set(ap_scalar_t* a, ap_scalar_t* b) { if (a==b) return; ap_scalar_reinit(a,b->discr); switch(b->discr){ case AP_SCALAR_DOUBLE: a->val.dbl = b->val.dbl; break; case AP_SCALAR_MPQ: mpq_set(a->val.mpq,b->val.mpq); break; case AP_SCALAR_MPFR: mpfr_set_prec(a->val.mpfr,mpfr_get_prec(b->val.mpfr)); mpfr_set(a->val.mpfr,b->val.mpfr,GMP_RNDU /* exact */); break; default: abort(); } } void ap_scalar_set_mpq(ap_scalar_t* scalar, mpq_t mpq) { ap_scalar_reinit(scalar,AP_SCALAR_MPQ); mpq_set(scalar->val.mpq,mpq); } void ap_scalar_set_mpfr(ap_scalar_t* scalar, mpfr_t mpfr) { ap_scalar_reinit(scalar,AP_SCALAR_MPFR); mpfr_set_prec(scalar->val.mpfr,mpfr_get_prec(mpfr)); mpfr_set(scalar->val.mpfr,mpfr,GMP_RNDU /* exact */); } void ap_scalar_set_int(ap_scalar_t* scalar, long int i) { ap_scalar_reinit(scalar,AP_SCALAR_MPQ); mpq_set_si(scalar->val.mpq,i,1); } void ap_scalar_set_frac(ap_scalar_t* scalar, long int i, unsigned long int j) { ap_scalar_reinit(scalar,AP_SCALAR_MPQ); mpq_set_si(scalar->val.mpq,i,j); mpq_canonicalize(scalar->val.mpq); } void ap_scalar_set_double(ap_scalar_t* scalar, double k) { ap_scalar_reinit(scalar,AP_SCALAR_DOUBLE); scalar->val.dbl = k; } void ap_scalar_set_infty(ap_scalar_t* scalar, int sgn) { switch(scalar->discr){ case AP_SCALAR_MPQ: mpz_set_si(mpq_numref(scalar->val.mpq),sgn); mpz_set_ui(mpq_denref(scalar->val.mpq),sgn ? 0 : 1); break; case AP_SCALAR_DOUBLE: scalar->val.dbl = sgn>0 ? (double)1.0/(double)0.0 : (sgn < 0 ? -(double)1.0/(double)0.0 : 0.0); break; case AP_SCALAR_MPFR: mpfr_set_inf(scalar->val.mpfr,sgn); break; default: abort(); } } /* ====================================================================== */ /* Conversions */ /* ====================================================================== */ int ap_mpq_set_scalar(mpq_t mpq, ap_scalar_t* scalar, mp_rnd_t round) { mp_exp_t e; int inf = ap_scalar_infty(scalar); if (inf) { mpz_set_si(mpq_numref(mpq),inf); mpz_set_si(mpq_denref(mpq),0); return 0; } switch(scalar->discr){ case AP_SCALAR_MPQ: mpq_set(mpq,scalar->val.mpq); return 0; break; case AP_SCALAR_DOUBLE: if (!isfinite(scalar->val.dbl)) { mpq_set_si(mpq,0,1); return 1; } mpq_set_d(mpq,scalar->val.dbl); return 0; break; case AP_SCALAR_MPFR: if (!mpfr_number_p(scalar->val.mpfr)) { mpq_set_si(mpq,0,1); return 1; } e = mpfr_get_z_exp(mpq_numref(mpq),scalar->val.mpfr); mpz_set_si(mpq_denref(mpq),1); if (e>0) mpq_mul_2exp(mpq,mpq,e); if (e<0) mpq_div_2exp(mpq,mpq,-e); return 0; default: abort(); } } int ap_double_set_scalar(double* k, ap_scalar_t* scalar, mp_rnd_t round) { switch(scalar->discr){ case AP_SCALAR_MPQ: { mpfr_t mpfr; mpfr_init2(mpfr,53); int res = mpfr_set_q(mpfr,scalar->val.mpq,round); *k = mpfr_get_d(mpfr,round); /* normally, exact */ mpfr_clear(mpfr); return res; } case AP_SCALAR_DOUBLE: *k = scalar->val.dbl; return 0; case AP_SCALAR_MPFR: *k = mpfr_get_d(scalar->val.mpfr,round); return mpfr_cmp_d(scalar->val.mpfr,*k); default: abort(); } } int ap_mpfr_set_scalar(mpfr_t mpfr, ap_scalar_t* scalar, mp_rnd_t round) { switch(scalar->discr){ case AP_SCALAR_MPQ: return mpfr_set_q(mpfr,scalar->val.mpq,round); case AP_SCALAR_DOUBLE: return mpfr_set_d(mpfr,scalar->val.dbl,round); case AP_SCALAR_MPFR: return mpfr_set(mpfr,scalar->val.mpfr,round); default: abort(); } } /* ====================================================================== */ /* Tests */ /* ====================================================================== */ int ap_scalar_infty(ap_scalar_t* scalar) { switch(scalar->discr){ case AP_SCALAR_MPQ: return (mpz_sgn(mpq_denref(scalar->val.mpq)))==0 ? (mpz_sgn(mpq_numref(scalar->val.mpq))) > 0 ? 1 : -1 : 0; case AP_SCALAR_DOUBLE: return scalar->val.dbl==(double)1.0/(double)0.0 ? 1 : ( scalar->val.dbl==-(double)1.0/(double)0.0 ? -1 : 0); case AP_SCALAR_MPFR: return mpfr_inf_p(scalar->val.mpfr) ? mpfr_sgn(scalar->val.mpfr) > 0 ? 1 : -1 : 0; default: abort(); } } int ap_scalar_cmp(ap_scalar_t* a, ap_scalar_t* b) { int s1 = ap_scalar_infty(a); int s2 = ap_scalar_infty(b); if (s1>s2) return 1; else if (s1discr == b->discr) { switch (a->discr){ case AP_SCALAR_MPQ: return mpq_cmp(a->val.mpq,b->val.mpq); case AP_SCALAR_DOUBLE: return a->val.dbl > b->val.dbl ? 1 : ( a->val.dbl < b->val.dbl ? -1 : 0); case AP_SCALAR_MPFR: return mpfr_cmp(a->val.mpfr,b->val.mpfr); default: abort(); } } else if (a->discr==AP_SCALAR_MPFR || b->discr==AP_SCALAR_MPFR) { switch (a->discr) { case AP_SCALAR_MPFR: switch (b->discr) { case AP_SCALAR_MPQ: return mpfr_cmp_q(a->val.mpfr,b->val.mpq); case AP_SCALAR_DOUBLE: return mpfr_cmp_d(a->val.mpfr,b->val.dbl); default: abort(); } break; case AP_SCALAR_MPQ: return -mpfr_cmp_q(b->val.mpfr,a->val.mpq); case AP_SCALAR_DOUBLE: return -mpfr_cmp_d(b->val.mpfr,a->val.dbl); default: abort(); } } else { mpq_t mpq; int res; mpq_init(mpq); if (a->discr==AP_SCALAR_DOUBLE){ mpq_set_d(mpq,a->val.dbl); res = mpq_cmp(mpq,b->val.mpq); } else { mpq_set_d(mpq,b->val.dbl); res = mpq_cmp(a->val.mpq,mpq); } mpq_clear(mpq); return res; } } int ap_scalar_cmp_int(ap_scalar_t* a, int b) { int s1 = ap_scalar_infty(a); if (s1>0) return 1; else if (s1<0) return -1; else { switch (a->discr){ case AP_SCALAR_DOUBLE: return a->val.dbl > b ? 1 : (a->val.dbl < b ? (-1) : 0); case AP_SCALAR_MPQ: return mpq_cmp_si(a->val.mpq,b,1); case AP_SCALAR_MPFR: return mpfr_cmp_si(a->val.mpfr,b); default: abort(); } } } bool ap_scalar_equal(ap_scalar_t* a, ap_scalar_t* b) { int s1 = ap_scalar_infty(a); int s2 = ap_scalar_infty(b); if (s1!=s2) return false; else if (s1!=0) return true; else if (a->discr == b->discr) { switch (a->discr){ case AP_SCALAR_MPQ: return mpq_equal(a->val.mpq,b->val.mpq); case AP_SCALAR_DOUBLE: return a->val.dbl == b->val.dbl; case AP_SCALAR_MPFR: return mpfr_equal_p(a->val.mpfr,b->val.mpfr); default: abort(); } } else return ap_scalar_cmp(a,b)==0; } bool ap_scalar_equal_int(ap_scalar_t* a, int b) { int s1 = ap_scalar_infty(a); if (s1!=0) return false; else { switch (a->discr){ case AP_SCALAR_DOUBLE: return a->val.dbl == b; case AP_SCALAR_MPQ: return mpq_cmp_si(a->val.mpq,b,1)==0; case AP_SCALAR_MPFR: return mpfr_cmp_si(a->val.mpfr,b)==0; default: abort(); } } } int ap_scalar_sgn(ap_scalar_t* a) { int res; res = ap_scalar_infty(a); if (!res) { switch (a->discr){ case AP_SCALAR_MPQ: res = mpq_sgn(a->val.mpq); break; case AP_SCALAR_DOUBLE: res = a->val.dbl > 0.0 ? 1 : (a->val.dbl == 0.0 ? 0 : (-1)); break; case AP_SCALAR_MPFR: res = mpfr_sgn(a->val.mpfr) > 0 ? 1 : -1; break; default: abort(); } } return res > 0 ? 1 : res < 0 ? -1 : 0; } /* ====================================================================== */ /* Other operations */ /* ====================================================================== */ void ap_scalar_neg(ap_scalar_t* a, ap_scalar_t* b) { ap_scalar_reinit(a,b->discr); switch(b->discr){ case AP_SCALAR_MPQ: mpq_neg(a->val.mpq,b->val.mpq); break; case AP_SCALAR_DOUBLE: a->val.dbl = -b->val.dbl; break; case AP_SCALAR_MPFR: if (a!=b) mpfr_set_prec(a->val.mpfr,mpfr_get_prec(b->val.mpfr)); mpfr_neg(a->val.mpfr,b->val.mpfr,GMP_RNDU); break; default: abort(); } } void ap_scalar_inv(ap_scalar_t* a, ap_scalar_t* b) { ap_scalar_reinit(a,b->discr); switch(b->discr){ case AP_SCALAR_MPQ: mpq_inv(a->val.mpq,b->val.mpq); break; case AP_SCALAR_DOUBLE: a->val.dbl = 1.0/b->val.dbl; break; case AP_SCALAR_MPFR: if (a!=b) mpfr_set_prec(a->val.mpfr,mpfr_get_prec(b->val.mpfr)); mpfr_ui_div(a->val.mpfr,1,b->val.mpfr,GMP_RNDU); break; default: abort(); } } long ap_scalar_hash(ap_scalar_t* a) { int infty = ap_scalar_infty(a); if (infty<0) return LONG_MIN; else if (infty>0) return LONG_MAX; else { switch (a->discr){ case AP_SCALAR_MPQ: return mpz_get_si(mpq_numref(a->val.mpq))/mpz_get_ui(mpq_denref(a->val.mpq)); case AP_SCALAR_DOUBLE: return (int)(a->val.dbl); case AP_SCALAR_MPFR: return mpfr_get_si(a->val.mpfr,GMP_RNDU); /* XXX improve this */ default: abort(); } } } apron-dist-0.9.10/apron/apron/ap_generator1.h0000640014525101416610000002255610677671162020732 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_generator1.h: linear generators and arrays */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ /* normally included from ap_expr1.h */ #ifndef _AP_GENERATOR1_H_ #define _AP_GENERATOR1_H_ #include #include #include #include "ap_coeff.h" #include "ap_environment.h" #include "ap_generator0.h" #include "ap_linexpr1.h" #ifdef __cplusplus extern "C" { #endif /* ====================================================================== */ /* Datatypes */ /* ====================================================================== */ /* Generators */ typedef struct ap_generator1_t { ap_generator0_t generator0; ap_environment_t* env; } ap_generator1_t; /* Array of generators */ typedef struct ap_generator1_array_t { ap_generator0_array_t generator0_array; ap_environment_t* env; } ap_generator1_array_t; /* ********************************************************************** */ /* I. ap_generator0_t */ /* ********************************************************************** */ /* ====================================================================== */ /* I.1 Memory management and printing */ /* ====================================================================== */ static inline ap_generator1_t ap_generator1_make(ap_gentyp_t gentyp, ap_linexpr1_t* expr); /* Create a generator of given type with the given expression. The expression is not duplicated. */ static inline ap_generator1_t ap_generator1_copy(ap_generator1_t* gen); /* Duplication */ void ap_generator1_clear(ap_generator1_t* gen); /* Clear the generator and set pointers to NULL */ void ap_generator1_fprint(FILE* stream, ap_generator1_t* gen); /* Printing */ /* ====================================================================== */ /* I.2 Tests */ /* ====================================================================== */ /* ====================================================================== */ /* I.3 Access */ /* ====================================================================== */ static inline ap_environment_t* ap_generator1_envref(ap_generator1_t* gen); /* Get a reference to the environment. Do not free it. */ static inline ap_gentyp_t* ap_generator1_gentypref(ap_generator1_t* gen); /* Get a reference to the type of generator */ static inline ap_linexpr1_t ap_generator1_linexpr1ref(ap_generator1_t* gen); /* Get a reference to the underlying expression of the generator. Do not free it: nothing is duplicated. Modifying the argument or the result is equivalent, except for change of dimensions/envionment. */ /* Get the constant and assign it to coeff */ static inline void ap_generator1_get_cst(ap_coeff_t* coeff, ap_generator1_t* gen); /* Get coefficient of variable var in the generator and assign it to coeff. Return true if var is unknown in the environment */ bool ap_generator1_get_coeff(ap_coeff_t* coeff, ap_generator1_t* gen, ap_var_t var); /* Set the constant of the linear generator */ static inline void ap_generator1_set_cst(ap_generator1_t* gen, ap_coeff_t* cst); /* Set the coefficient of variable var in the generator. Return true if var is unknown in the environment */ static inline bool ap_generator1_set_coeff(ap_generator1_t* gen, ap_var_t var, ap_coeff_t* coeff); /* bool ap_generator1_set_format(ap_generator1_t* cons, char* fmt, ...); */ bool ap_generator1_set_list(ap_generator1_t* gen, ...); static inline ap_coeff_t* ap_generator1_cstref(ap_generator1_t* gen); /* Get a reference to the constant. Do not free it. */ ap_coeff_t* ap_generator1_coeffref(ap_generator1_t* gen, ap_var_t var); /* Get a reference to the coefficient associated to the variable. Do not free it. In case of sparse representation, possibly induce the addition of a new linear term. Return NULL if var is unknown in the environment. */ static inline ap_generator0_t* ap_generator1_generator0ref(ap_generator1_t* gen); /* Return underlying generator of level 0. Do not free it: nothing is duplicated. Modifying the argument or the result is equivalent, except for change of dimensions/environment. */ /* ====================================================================== */ /* I.3 Change of dimensions and permutations */ /* ====================================================================== */ bool ap_generator1_extend_environment(ap_generator1_t* ngen, ap_generator1_t* gen, ap_environment_t* nenv); bool ap_generator1_extend_environment_with(ap_generator1_t* gen, ap_environment_t* nenv); /* ********************************************************************** */ /* II. Array of linear generators */ /* ********************************************************************** */ /* ====================================================================== */ /* I.1 Memory management and printing */ /* ====================================================================== */ ap_generator1_array_t ap_generator1_array_make(ap_environment_t* env, size_t size); /* Allocate an array of size generators. The generators are initialized with NULL pointers, so that ap_generator1_array_free may be safely called */ void ap_generator1_array_clear(ap_generator1_array_t* array); /* Clear the generators of the array, and then the array itself */ void ap_generator1_array_fprint(FILE* stream, ap_generator1_array_t* ap_generator1_array); /* Printing */ /* ====================================================================== */ /* II.3 Access */ /* ====================================================================== */ static inline size_t ap_generator1_array_size(ap_generator1_array_t* array); static inline ap_environment_t* ap_generator1_array_envref(ap_generator1_array_t* array); static inline void ap_generator1_array_clear_index(ap_generator1_array_t* array, size_t index); /* Clear the generator at index index. */ ap_generator1_t ap_generator1_array_get(ap_generator1_array_t* array, size_t index); /* Return the linear generator of the given index Nothing is duplicated, and the result should never be cleared. Modifying the argument or the result is equivalent, except for change of environments */ bool ap_generator1_array_set(ap_generator1_array_t* array, size_t index, ap_generator1_t* gen); /* Fill the index of the array with the generator. Assumes array->env==gen->env. Nothing is duplicated. The argument should never be cleared. (its environment is dereferenced). If a generator was already stored, it is first cleared. Return true iff problem (index or array->env!=gen->env) */ /* ====================================================================== */ /* II.4 Change of dimensions and permutations */ /* ====================================================================== */ bool ap_generator1_array_extend_environment_with(ap_generator1_array_t* array, ap_environment_t* env); bool ap_generator1_array_extend_environment(ap_generator1_array_t* narray, ap_generator1_array_t* array, ap_environment_t* env); /* ********************************************************************** */ /* III. Inline functions definitions */ /* ********************************************************************** */ static inline ap_generator1_t ap_generator1_make(ap_gentyp_t gentyp, ap_linexpr1_t* expr) { ap_generator1_t gen; gen.generator0 = ap_generator0_make(gentyp,expr->linexpr0); gen.env = expr->env; return gen; } static inline ap_generator1_t ap_generator1_copy(ap_generator1_t* gen){ ap_generator1_t ngen; ngen.generator0 = ap_generator0_copy(&gen->generator0); ngen.env = ap_environment_copy(gen->env); return ngen; } static inline ap_environment_t* ap_generator1_envref(ap_generator1_t* gen){ return gen->env; } static inline ap_gentyp_t* ap_generator1_gentypref(ap_generator1_t* gen){ return &gen->generator0.gentyp; } static inline ap_linexpr1_t ap_generator1_linexpr1ref(ap_generator1_t* gen){ ap_linexpr1_t expr; expr.linexpr0 = gen->generator0.linexpr0; expr.env = gen->env; return expr; } static inline ap_generator0_t* ap_generator1_generator0ref(ap_generator1_t* gen){ return &gen->generator0; } static inline ap_coeff_t* ap_generator1_cstref(ap_generator1_t* gen){ return &gen->generator0.linexpr0->cst; } static inline void ap_generator1_get_cst(ap_coeff_t* coeff, ap_generator1_t* gen){ ap_linexpr0_get_cst(coeff,gen->generator0.linexpr0); } static inline void ap_generator1_set_cst(ap_generator1_t* gen, ap_coeff_t* cst){ ap_linexpr0_set_cst(gen->generator0.linexpr0,cst); } static inline bool ap_generator1_set_coeff(ap_generator1_t* gen, ap_var_t var, ap_coeff_t* coeff) { ap_coeff_t* ecoeff = ap_generator1_coeffref(gen,var); if (ecoeff){ap_coeff_set(ecoeff,coeff); return false;} else return true; } static inline size_t ap_generator1_array_size(ap_generator1_array_t* array){ return array->generator0_array.size; } static inline ap_environment_t* ap_generator1_array_envref(ap_generator1_array_t* array){ return array->env; } static inline void ap_generator1_array_clear_index(ap_generator1_array_t* array, size_t index){ ap_generator0_clear(&array->generator0_array.p[index]); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/Makefile0000640014525101416610000003355311251670107017454 0ustar bjeannetpopartinclude ../Makefile.config #--------------------------------------- # Directories #--------------------------------------- SRCDIR = $(shell pwd) # PREFIX = $(APRON_PREFIX) # # C include and lib directories INCDIR = $(PREFIX)/include LIBDIR = $(PREFIX)/lib BINDIR = $(PREFIX)/bin # #--------------------------------------- # C part #--------------------------------------- ICFLAGS = -I../num -I$(GMP_PREFIX)/include -I$(MPFR_PREFIX)/include #--------------------------------------- # Files #--------------------------------------- H_FILES = \ ap_config.h \ ap_scalar.h ap_interval.h ap_coeff.h ap_dimension.h \ ap_linexpr0.h ap_lincons0.h ap_generator0.h \ ap_texpr0.h ap_tcons0.h ap_expr0.h \ ap_manager.h ap_abstract0.h ap_generic.h \ ap_var.h ap_environment.h \ ap_linexpr1.h ap_lincons1.h ap_generator1.h \ ap_texpr1.h ap_tcons1.h ap_expr1.h \ ap_abstract1.h \ ap_global0.h ap_global1.h \ ap_linearize.h ap_linearize_aux.h \ ap_reducedproduct.h C_FILES = \ ap_scalar.c ap_interval.c ap_coeff.c ap_dimension.c \ ap_linexpr0.c ap_lincons0.c ap_generator0.c \ ap_texpr0.c ap_tcons0.c \ ap_manager.c ap_abstract0.c ap_generic.c \ ap_var.c ap_environment.c \ ap_linexpr1.c ap_lincons1.c ap_generator1.c \ ap_texpr1.c ap_tcons1.c \ ap_abstract1.c \ ap_linearize.c \ ap_reducedproduct.c C_FILES_AUX = ap_linearize_aux.c H_FILES_AUX = ap_linearize_aux.h CH_FILES_AUX = $(H_FILES_AUX) $(C_FILES_AUX) #--------------------------------------- # Rules #--------------------------------------- all: libapron.a libapron_debug.a ifneq ($(HAS_SHARED),) all: libapron.so libapron_debug.so endif #--------------------------------------- # Misc rules #--------------------------------------- tar: $(H_FILES) $(C_FILES) $(CH_FILES_AUX) apron.texi Makefile COPYING README (cd ..; tar zcvf apron.tgz $(^:%=apron/%)) dist: $(H_FILES) $(C_FILES) $(CH_FILES_AUX) apron.texi Makefile COPYING README apron.info apron.pdf html (cd ..; tar zcvf apron.tgz $(^:%=apron/%)) clean: /bin/rm -f *.aux *.bbl *.blg *.dvi *.log *.toc *.ps *.pdf apron.cps apron.fns apron.info apron.fn apron.ky apron.pg apron.cp apron.tp apron.vr apron.kys apron.pgs apron.tps apron.vrs newpolka.texi box.texi ap_ppl.texi ap_pkgrid.texi apron.info* /bin/rm -f *.o *.a *.cmi *.cmo *.cmx *.cmxa *.cma *.so /bin/rm -fr html install: all mkdir -p $(APRON_PREFIX)/include cp $(H_FILES) $(APRON_PREFIX)/include mkdir -p $(APRON_PREFIX)/lib for i in libapron.a libapron_debug.a libapron.so libapron_debug.so; do if test -f $$i; then $(INSTALL) $$i $(APRON_PREFIX)/lib; fi; done distclean: /bin/rm -f $(H_FILES:%=$(APRON_PREFIX)/include/%) /bin/rm -f $(APRON_PREFIX)/lib/libapron.a /bin/rm -f $(APRON_PREFIX)/lib/libapron_debug.a /bin/rm -f $(APRON_PREFIX)/lib/libapron.so /bin/rm -f $(APRON_PREFIX)/lib/libapron_debug.so /bin/rm -f apron.pdf rationale.pdf #--------------------------------------- # Latex rules #--------------------------------------- .PHONY : html ap_pkgrid.texi: ../products/ap_pkgrid.texi ln -s $< $@ ap_ppl.texi: ../ppl/ap_ppl.texi ln -s $< $@ newpolka.texi: ../newpolka/newpolka.texi ln -s $< $@ box.texi: ../box/box.texi ln -s $< $@ apron.pdf: apron.texi rationale.texi ap_pkgrid.texi ap_ppl.texi newpolka.texi box.texi $(TEXI2DVI) --pdf -o $@ $< apron.info: apron.texi rationale.texi ap_pkgrid.texi ap_ppl.texi newpolka.texi box.texi $(MAKEINFO) -o $@ $< html: apron.texi rationale.texi ap_pkgrid.texi ap_ppl.texi newpolka.texi box.texi $(TEXI2HTML) -split=section -nonumber -menu -subdir=html $< cp -f ../octagons/oct_doc.html html #--------------------------------------- # C rules #--------------------------------------- libapron.a: $(C_FILES:%.c=%.o) $(C_FILES_AUX:%.c=%MPQ.o) $(C_FILES_AUX:%.c=%D.o) $(C_FILES_AUX:%.c=%MPFR.o) ../itv/libitv.a cp ../itv/libitv.a $@ $(AR) rs $@ $(C_FILES:%.c=%.o) $(C_FILES_AUX:%.c=%MPQ.o) $(C_FILES_AUX:%.c=%D.o) $(C_FILES_AUX:%.c=%MPFR.o) $(RANLIB) $@ libapron_debug.a: $(C_FILES:%.c=%_debug.o) $(C_FILES_AUX:%.c=%MPQ_debug.o) $(C_FILES_AUX:%.c=%D_debug.o) $(C_FILES_AUX:%.c=%MPFR_debug.o) ../itv/libitv_debug.a cp ../itv/libitv_debug.a $@ $(AR) rs $@ $(C_FILES:%.c=%_debug.o) $(C_FILES_AUX:%.c=%MPQ_debug.o) $(C_FILES_AUX:%.c=%D_debug.o) $(C_FILES_AUX:%.c=%MPFR_debug.o) $(RANLIB) $@ libapron.so: $(C_FILES:%.c=%.o) $(C_FILES_AUX:%.c=%MPQ.o) $(C_FILES_AUX:%.c=%D.o) $(C_FILES_AUX:%.c=%MPFR.o) ../itv/libitv.a for i in `$(AR) t ../itv/libitv.a`; do ln -s ../itv/$$i $$i; done $(CC) $(CFLAGS) -shared -o $@ $(C_FILES:%.c=%.o) $(C_FILES_AUX:%.c=%MPQ.o) $(C_FILES_AUX:%.c=%D.o) $(C_FILES_AUX:%.c=%MPFR.o) `$(AR) t ../itv/libitv.a` for i in `$(AR) t ../itv/libitv.a`; do $(RM) $$i; done libapron_debug.so: $(C_FILES:%.c=%_debug.o) $(C_FILES_AUX:%.c=%MPQ_debug.o) $(C_FILES_AUX:%.c=%D_debug.o) $(C_FILES_AUX:%.c=%MPFR_debug.o) ../itv/libitv_debug.a for i in `$(AR) t ../itv/libitv_debug.a`; do ln -s ../itv/$$i $$i; done $(CC) $(CFLAGS_DEBUG) -shared -o $@ $(C_FILES:%.c=%.o) $(C_FILES_AUX:%.c=%MPQ.o) $(C_FILES_AUX:%.c=%D.o) $(C_FILES_AUX:%.c=%MPFR.o) `$(AR) t ../itv/libitv_debug.a` for i in `$(AR) t ../itv/libitv_debug.a`; do $(RM) $$i; done .PHONY : dep dep: $(H_FILES) for i in $(C_FILES); do \ cpp $(ICFLAGS) -I../itv -MM $$i; \ done #-------------------------------------------------------------- # IMPLICIT RULES AND DEPENDENCIES #-------------------------------------------------------------- .SUFFIXES: .c .h .o #--------------------------------------- # C generic rules #--------------------------------------- %.o: %.c %.h $(CC) $(CFLAGS) $(ICFLAGS) -I../itv -c $< %MPQ.o: %.c %.h $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_MPQ -I../num -I../itv -I. -c $< -o $@ %D.o: %.c %.h $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_DOUBLE -I../num -I../itv -I. -c $< -o $@ %Dl.o: %.c %.h $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_LONGDOUBLE -I../num -I../itv -I. -c $< -o $@ %MPFR.o: %.c %.h $(CC) $(CFLAGS) $(ICFLAGS) -DNUM_MPFR -I../num -I../itv -I. -c $< -o $@ %_debug.o: %.c %.h $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -I../itv -c -o $@ $< %MPQ_debug.o: %.c %.h $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_MPQ -I../num -I../itv -I. -c -o $@ $< -o $@ %D_debug.o: %.c %.h $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_DOUBLE -I../num -I../itv -I. -c -o $@ $< -o $@ %Dl_debug.o: %.c %.h $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_LONGDOUBLE -I../num -I../itv -I. -c -o $@ $< -o $@ %MPFR_debug.o: %.c %.h $(CC) $(CFLAGS_DEBUG) $(ICFLAGS) -DNUM_MPFR -I../num -I../itv -I. -c -o $@ $< -o $@ #--------------------------------------- # dependencies (generated with make dep) #--------------------------------------- ap_scalar.o: ap_scalar.c ap_scalar.h ap_config.h ap_interval.o: ap_interval.c ap_interval.h \ ap_config.h \ ap_scalar.h $(MPFR_PREFIX)/include/mpfr.h ap_coeff.o: ap_coeff.c ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_dimension.o: ap_dimension.c ap_dimension.h ap_linexpr0.o: ap_linexpr0.c ap_linexpr0.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_dimension.h ap_lincons0.o: ap_lincons0.c ap_lincons0.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_linexpr0.h ap_dimension.h ap_generator0.o: ap_generator0.c ap_generator0.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_linexpr0.h ap_dimension.h ap_texpr0.o: ap_texpr0.c ap_texpr0.h ap_dimension.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_linexpr0.h ap_linearize.h ap_manager.h ap_expr0.h \ ap_lincons0.h ap_generator0.h ap_tcons0.h ap_abstract0.h ap_tcons0.o: ap_tcons0.c ap_tcons0.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_texpr0.h ap_dimension.h ap_linexpr0.h ap_lincons0.h ap_manager.o: ap_manager.c ap_manager.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_abstract0.o: ap_abstract0.c ap_abstract0.h ap_manager.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_expr0.h ap_linexpr0.h ap_dimension.h ap_lincons0.h \ ap_generator0.h ap_texpr0.h ap_tcons0.h ap_linearize.h ap_generic.o: ap_generic.c ap_generic.h ap_manager.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_expr0.h ap_linexpr0.h ap_dimension.h ap_lincons0.h \ ap_generator0.h ap_texpr0.h ap_tcons0.h ap_linearize.h ap_abstract0.h ap_var.o: ap_var.c ap_manager.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_var.h ap_environment.o: ap_environment.c ap_manager.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_environment.h ap_dimension.h ap_var.h ap_linexpr1.o: ap_linexpr1.c ap_linexpr1.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_environment.h ap_dimension.h ap_var.h ap_linexpr0.h ap_lincons1.o: ap_lincons1.c ap_lincons1.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_environment.h ap_dimension.h ap_var.h ap_lincons0.h \ ap_linexpr0.h ap_linexpr1.h ap_generator1.o: ap_generator1.c ap_generator1.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_environment.h ap_dimension.h ap_var.h ap_generator0.h \ ap_linexpr0.h ap_linexpr1.h ap_texpr1.o: ap_texpr1.c ap_texpr1.h ap_dimension.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_texpr0.h ap_linexpr0.h ap_environment.h ap_var.h \ ap_linexpr1.h ap_tcons1.o: ap_tcons1.c ap_tcons1.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_tcons0.h ap_texpr0.h ap_dimension.h ap_linexpr0.h \ ap_lincons0.h ap_environment.h ap_var.h ap_texpr1.h ap_linexpr1.h ap_abstract1.o: ap_abstract1.c ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_manager.h ap_abstract0.h ap_expr0.h ap_linexpr0.h \ ap_dimension.h ap_lincons0.h ap_generator0.h ap_texpr0.h ap_tcons0.h \ ap_linearize.h ap_expr1.h ap_linexpr1.h ap_environment.h ap_var.h \ ap_lincons1.h ap_generator1.h ap_texpr1.h ap_tcons1.h ap_abstract1.h ap_linearize.o: ap_linearize.c ap_linearize.h ap_manager.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_expr0.h ap_linexpr0.h ap_dimension.h ap_lincons0.h \ ap_generator0.h ap_texpr0.h ap_tcons0.h ap_abstract0.h \ ap_linearize_aux.h ../itv/itv_fun.h ap_reducedproduct.o: ap_reducedproduct.c ap_global0.h ap_config.h \ ap_scalar.h \ ap_interval.h \ ap_coeff.h ap_dimension.h ap_linexpr0.h ap_lincons0.h ap_generator0.h \ ap_texpr0.h ap_tcons0.h ap_manager.h ap_abstract0.h ap_expr0.h \ ap_linearize.h ap_reducedproduct.h ap_scalar_debug.o: ap_scalar.c ap_scalar.h ap_config.h ap_interval_debug.o: ap_interval.c ap_interval.h \ ap_config.h \ ap_scalar.h $(MPFR_PREFIX)/include/mpfr.h ap_coeff_debug.o: ap_coeff.c ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_dimension_debug.o: ap_dimension.c ap_dimension.h ap_linexpr0_debug.o: ap_linexpr0.c ap_linexpr0.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_dimension.h ap_lincons0_debug.o: ap_lincons0.c ap_lincons0.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_linexpr0.h ap_dimension.h ap_generator0_debug.o: ap_generator0.c ap_generator0.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_linexpr0.h ap_dimension.h ap_texpr0_debug.o: ap_texpr0.c ap_texpr0.h ap_dimension.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_linexpr0.h ap_linearize.h ap_manager.h ap_expr0.h \ ap_lincons0.h ap_generator0.h ap_tcons0.h ap_abstract0.h ap_tcons0_debug.o: ap_tcons0.c ap_tcons0.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_texpr0.h ap_dimension.h ap_linexpr0.h ap_lincons0.h ap_manager_debug.o: ap_manager.c ap_manager.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_abstract0_debug.o: ap_abstract0.c ap_abstract0.h ap_manager.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_expr0.h ap_linexpr0.h ap_dimension.h ap_lincons0.h \ ap_generator0.h ap_texpr0.h ap_tcons0.h ap_linearize.h ap_generic_debug.o: ap_generic.c ap_generic.h ap_manager.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_expr0.h ap_linexpr0.h ap_dimension.h ap_lincons0.h \ ap_generator0.h ap_texpr0.h ap_tcons0.h ap_linearize.h ap_abstract0.h ap_var_debug.o: ap_var.c ap_manager.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_var.h ap_environment_debug.o: ap_environment.c ap_manager.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_environment.h ap_dimension.h ap_var.h ap_linexpr1_debug.o: ap_linexpr1.c ap_linexpr1.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_environment.h ap_dimension.h ap_var.h ap_linexpr0.h ap_lincons1_debug.o: ap_lincons1.c ap_lincons1.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_environment.h ap_dimension.h ap_var.h ap_lincons0.h \ ap_linexpr0.h ap_linexpr1.h ap_generator1_debug.o: ap_generator1.c ap_generator1.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_environment.h ap_dimension.h ap_var.h ap_generator0.h \ ap_linexpr0.h ap_linexpr1.h ap_texpr1_debug.o: ap_texpr1.c ap_texpr1.h ap_dimension.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_texpr0.h ap_linexpr0.h ap_environment.h ap_var.h \ ap_linexpr1.h ap_tcons1_debug.o: ap_tcons1.c ap_tcons1.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_tcons0.h ap_texpr0.h ap_dimension.h ap_linexpr0.h \ ap_lincons0.h ap_environment.h ap_var.h ap_texpr1.h ap_linexpr1.h ap_abstract1_debug.o: ap_abstract1.c ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_manager.h ap_abstract0.h ap_expr0.h ap_linexpr0.h \ ap_dimension.h ap_lincons0.h ap_generator0.h ap_texpr0.h ap_tcons0.h \ ap_linearize.h ap_expr1.h ap_linexpr1.h ap_environment.h ap_var.h \ ap_lincons1.h ap_generator1.h ap_texpr1.h ap_tcons1.h ap_abstract1.h ap_linearize_debug.o: ap_linearize.c ap_linearize.h ap_manager.h ap_coeff.h \ ap_config.h \ ap_scalar.h \ ap_interval.h ap_expr0.h ap_linexpr0.h ap_dimension.h ap_lincons0.h \ ap_generator0.h ap_texpr0.h ap_tcons0.h ap_abstract0.h \ ap_linearize_aux.h ../itv/itv_fun.h ap_reducedproduct_debug.o: ap_reducedproduct.c ap_global0.h ap_config.h \ ap_scalar.h \ ap_interval.h \ ap_coeff.h ap_dimension.h ap_linexpr0.h ap_lincons0.h ap_generator0.h \ ap_texpr0.h ap_tcons0.h ap_manager.h ap_abstract0.h ap_expr0.h \ ap_linearize.h ap_reducedproduct.h apron-dist-0.9.10/apron/apron/ap_linexpr1.c0000640014525101416610000001041110571032754020372 0ustar bjeannetpopart/* ************************************************************************* */ /* linexpr1.c: linear expressions */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "ap_linexpr1.h" #include /* ====================================================================== */ /* I. Memory management and printing */ /* ====================================================================== */ ap_linexpr1_t ap_linexpr1_make(ap_environment_t* env, ap_linexpr_discr_t lin_discr, size_t size) { ap_linexpr1_t e; e.linexpr0 = ap_linexpr0_alloc(lin_discr, lin_discr==AP_LINEXPR_DENSE ? env->intdim+env->realdim : size); e.env = ap_environment_copy(env); return e; } ap_linexpr1_t ap_linexpr1_copy(ap_linexpr1_t* e) { ap_linexpr1_t res; res.linexpr0 = ap_linexpr0_copy(e->linexpr0); res.env = ap_environment_copy(e->env); return res; } void ap_linexpr1_clear(ap_linexpr1_t* e) { if (e->linexpr0){ ap_linexpr0_free(e->linexpr0); e->linexpr0 = NULL; } if (e->env){ ap_environment_free(e->env); e->env = NULL; } } void ap_linexpr1_fprint(FILE* stream, ap_linexpr1_t* e) { ap_environment_name_of_dim_t* name_of_dim; name_of_dim = ap_environment_name_of_dim_alloc(e->env); ap_linexpr0_fprint(stream, e->linexpr0, name_of_dim->p); ap_environment_name_of_dim_free(name_of_dim); } /* ====================================================================== */ /* II. Tests */ /* ====================================================================== */ /* ====================================================================== */ /* III. Access */ /* ====================================================================== */ /* Return NULL if var undeclared */ ap_coeff_t* ap_linexpr1_coeffref(ap_linexpr1_t* expr, ap_var_t var) { ap_dim_t dim; dim = ap_environment_dim_of_var(expr->env,var); return ap_linexpr0_coeffref(expr->linexpr0,dim); } /* Return true if var undeclared */ bool ap_linexpr1_get_coeff(ap_coeff_t* coeff, ap_linexpr1_t* expr, ap_var_t var) { ap_dim_t dim; dim = ap_environment_dim_of_var(expr->env,var); return ap_linexpr0_get_coeff(coeff,expr->linexpr0,dim); } ap_coeff_t* ap_linexpr1_set_list_get_pcoeff(void* expr, bool cst, va_list* va) { ap_coeff_t* pcoeff; if (cst){ pcoeff = ap_linexpr1_cstref(expr); } else { ap_var_t var = va_arg(*va,ap_var_t); pcoeff = ap_linexpr1_coeffref(expr,var); } return pcoeff; } bool ap_linexpr1_set_list(ap_linexpr1_t* expr, ...) { va_list va; bool res; va_start(va,expr); res = ap_linexpr0_set_list_generic(ap_linexpr1_set_list_get_pcoeff, expr,&va); va_end(va); return res; } /* ====================================================================== */ /* IV. Change of dimensions and permutations */ /* ====================================================================== */ ap_linexpr1_t ap_linexpr1_extend_environment_dimchange(ap_linexpr1_t* expr, ap_environment_t* nenv, ap_dimchange_t* dimchange) { ap_linexpr1_t nexpr; nexpr.linexpr0 = ap_linexpr0_add_dimensions(expr->linexpr0,dimchange); nexpr.env = ap_environment_copy(nenv); return nexpr; } void ap_linexpr1_extend_environment_dimchange_with(ap_linexpr1_t* expr, ap_environment_t* nenv, ap_dimchange_t* dimchange) { ap_environment_t* env; ap_linexpr0_add_dimensions_with(expr->linexpr0,dimchange); env = expr->env; expr->env = ap_environment_copy(nenv); ap_environment_free(env); } bool ap_linexpr1_extend_environment(ap_linexpr1_t* nexpr, ap_linexpr1_t* expr, ap_environment_t* nenv) { ap_dimchange_t* dimchange = ap_environment_dimchange(expr->env,nenv); if (dimchange==NULL) return true; *nexpr = ap_linexpr1_extend_environment_dimchange(expr,nenv,dimchange); ap_dimchange_free(dimchange); return false; } bool ap_linexpr1_extend_environment_with(ap_linexpr1_t* expr, ap_environment_t* nenv) { ap_dimchange_t* dimchange = ap_environment_dimchange(expr->env,nenv); if (dimchange==NULL) return true; ap_linexpr1_extend_environment_dimchange_with(expr,nenv,dimchange); ap_dimchange_free(dimchange); return false; } apron-dist-0.9.10/apron/apron/test_texpr0.c0000640014525101416610000002252411006063143020427 0ustar bjeannetpopart/* * Testing expression tree support in APRON. * * Antoine Mine' 2007 */ /* Compile with: gcc test_texpr0.c -Wall -I$GMP_INSTALL/include -L$GMP_INSTALL/lib -I$MPFR_INSTALL/include -L$MPFR_INSTALL/lib -g -DDEBUG -O0 -I. -L../box -lbox_debug -L. -lapron_debug -lmpfr -lgmp -lm */ #include #include #include "ap_expr0.h" #include "ap_abstract0.h" #include "../box/box.h" ap_manager_t* man; #define V(i) ap_texpr0_dim(i) #define C(i) ap_texpr0_cst_scalar_int(i) #define I(a,b) ap_texpr0_cst_interval_double(a,b) #define ADD(a,b) ap_texpr0_binop(AP_TEXPR_ADD,a,b,AP_RTYPE_REAL,AP_RDIR_RND) #define SUB(a,b) ap_texpr0_binop(AP_TEXPR_SUB,a,b,AP_RTYPE_REAL,AP_RDIR_RND) #define NEG(a) ap_texpr0_unop(AP_TEXPR_NEG,a,AP_RTYPE_REAL,AP_RDIR_RND) #define SQRT(a) ap_texpr0_unop(AP_TEXPR_SQRT,a,AP_RTYPE_REAL,AP_RDIR_RND) #define MUL(a,b) ap_texpr0_binop(AP_TEXPR_MUL,a,b,AP_RTYPE_REAL,AP_RDIR_RND) #define DIV(a,b) ap_texpr0_binop(AP_TEXPR_DIV,a,b,AP_RTYPE_REAL,AP_RDIR_RND) #define MOD(a,b) ap_texpr0_binop(AP_TEXPR_MOD,a,b,AP_RTYPE_REAL,AP_RDIR_RND) #define ADDF(a,b) ap_texpr0_binop(AP_TEXPR_ADD,a,b,AP_RTYPE_SINGLE,AP_RDIR_RND) #define SUBF(a,b) ap_texpr0_binop(AP_TEXPR_SUB,a,b,AP_RTYPE_SINGLE,AP_RDIR_RND) #define NEGF(a) ap_texpr0_unop(AP_TEXPR_NEG,a,AP_RTYPE_SINGLE,AP_RDIR_RND) #define SQRTF(a) ap_texpr0_unop(AP_TEXPR_SQRT,a,AP_RTYPE_SINGLE,AP_RDIR_RND) #define MULF(a,b) ap_texpr0_binop(AP_TEXPR_MUL,a,b,AP_RTYPE_SINGLE,AP_RDIR_RND) #define DIVF(a,b) ap_texpr0_binop(AP_TEXPR_DIV,a,b,AP_RTYPE_SINGLE,AP_RDIR_RND) #define MODF(a,b) ap_texpr0_binop(AP_TEXPR_MOD,a,b,AP_RTYPE_SINGLE,AP_RDIR_RND) #define ADDI(a,b) ap_texpr0_binop(AP_TEXPR_ADD,a,b,AP_RTYPE_INT,AP_RDIR_RND) #define SUBI(a,b) ap_texpr0_binop(AP_TEXPR_SUB,a,b,AP_RTYPE_INT,AP_RDIR_RND) #define NEGI(a) ap_texpr0_unop(AP_TEXPR_NEG,a,AP_RTYPE_INT,AP_RDIR_RND) #define SQRTI(a) ap_texpr0_unop(AP_TEXPR_SQRT,a,AP_RTYPE_INT,AP_RDIR_RND) #define MULI(a,b) ap_texpr0_binop(AP_TEXPR_MUL,a,b,AP_RTYPE_INT,AP_RDIR_RND) #define DIVI(a,b) ap_texpr0_binop(AP_TEXPR_DIV,a,b,AP_RTYPE_INT,AP_RDIR_RND) #define MODI(a,b) ap_texpr0_binop(AP_TEXPR_MOD,a,b,AP_RTYPE_INT,AP_RDIR_RND) #define CASTF(a) ap_texpr0_unop(AP_TEXPR_CAST,a,AP_RTYPE_SINGLE,AP_RDIR_RND) #define TRUNC(a) ap_texpr0_unop(AP_TEXPR_CAST,a,AP_RTYPE_INT,AP_RDIR_ZERO) #define UP(a) ap_texpr0_unop(AP_TEXPR_CAST,a,AP_RTYPE_INT,AP_RDIR_UP) #define DOWN(a) ap_texpr0_unop(AP_TEXPR_CAST,a,AP_RTYPE_INT,AP_RDIR_DOWN) #define NEAREST(a) ap_texpr0_unop(AP_TEXPR_CAST,a,AP_RTYPE_INT,AP_RDIR_NEAREST) void print_info(ap_texpr0_t* a) { int i, m = ap_texpr0_max_dim(a); ap_dim_t* dd = ap_texpr0_dimlist(a); ap_texpr0_fprint(stdout,a,NULL); /* sizes, hashes */ printf("\ndepth=%i, size=%i, max_dim=%i, hash=%i, dims=[", (int)ap_texpr0_depth(a),(int)ap_texpr0_size(a),m, (int)ap_texpr0_hash(a)); /* dims */ for (i=0;dd[i]!=AP_DIM_MAX;i++) printf("%s%i",i?",":"",dd[i]); printf("]\n"); for (i=0;dd[i]!=AP_DIM_MAX;i++) assert(ap_texpr0_has_dim(a,dd[i])); assert(!i || dd[i-1]==m); assert(!i || !ap_texpr0_has_dim(a,dd[i-1]+1)); /* classification */ printf("%scst, %slinear, %spolynomial, %spolyfrac, %sscalar\n\n", ap_texpr0_is_interval_cst(a)?"":"non-", ap_texpr0_is_interval_linear(a)?"":"non-", ap_texpr0_is_interval_polynomial(a)?"":"non-", ap_texpr0_is_interval_polyfrac(a)?"":"non-", ap_texpr0_is_scalar(a)?"":"non-"); free(dd); } ap_interval_t** random_point(ap_interval_t** org, int dim, int p) { ap_interval_t** res = ap_interval_array_alloc(dim); int i; for (i=0;iinf,org[i]->inf); break; default: ap_interval_set_scalar(res[i],org[i]->sup,org[i]->sup); break; } p>>=1; } return res; } void testlinearize_discr(ap_texpr0_t* a, ap_interval_t**inter, int intdim, ap_scalar_discr_t discr) { bool exact = 2; ap_linexpr0_t *l, *q; ap_interval_t *itv, *itvl, *itvq; ap_abstract0_t *abs; int i,j, dim = ap_texpr0_max_dim(a)+1; abs = ap_abstract0_of_box(man, dimintdim ? dim-intdim : 0, inter); l = ap_intlinearize_texpr0(man, abs, a, &exact, discr, false); q = ap_intlinearize_texpr0(man, abs, a, &exact, discr, true); itv = ap_eval_texpr0(man, abs, a, discr, &exact); itvl = ap_eval_linexpr0(man, abs, l, discr, &exact); itvq = ap_eval_linexpr0(man, abs, q, discr, &exact); printf(" lin: "); ap_linexpr0_fprint(stdout, l, NULL); printf("\n"); printf(" qlin: "); ap_linexpr0_fprint(stdout, q, NULL); printf("\n"); printf(" itv: "); ap_interval_fprint(stdout, itv); printf("\n"); printf(" lin-itv: "); ap_interval_fprint(stdout, itvl); printf("\n"); printf(" qlin-itv: "); ap_interval_fprint(stdout, itvq); printf("\n"); for (j=0;j<1<intdim ? dim-intdim : 0, pt); ap_interval_t* pe = ap_eval_texpr0(man, ab, a, discr, &exact); ap_interval_t* pl = ap_eval_linexpr0(man, ab, l, discr, &exact); ap_interval_t* pq = ap_eval_linexpr0(man, ab, q, discr, &exact); printf(" eval "); for (i=0;ilinexpr0)){ *pexact = true; return *lincons0; } else { switch (discr){ case AP_SCALAR_MPQ: return ap_quasilinearize_lincons0_MPQ(man,abs,lincons0,pexact,meet); case AP_SCALAR_DOUBLE: return ap_quasilinearize_lincons0_D(man,abs,lincons0,pexact,meet); case AP_SCALAR_MPFR: return ap_quasilinearize_lincons0_MPFR(man,abs,lincons0,pexact,meet); default: abort(); } } } /* Same for arrays of ap_linexpr0_t */ ap_linexpr0_t** ap_quasilinearize_linexpr0_array(ap_manager_t* man, void* abs, ap_linexpr0_t** texpr, size_t size, bool* pexact, ap_scalar_discr_t discr) { if (ap_linexpr0_array_is_quasilinear(texpr,size)){ *pexact = true; return texpr; } else { switch (discr){ case AP_SCALAR_MPQ: return ap_quasilinearize_linexpr0_array_MPQ(man,abs,texpr,size,pexact); case AP_SCALAR_DOUBLE: return ap_quasilinearize_linexpr0_array_D(man,abs,texpr,size,pexact); case AP_SCALAR_MPFR: return ap_quasilinearize_linexpr0_array_MPFR(man,abs,texpr,size,pexact); default: abort(); } } } /* Same for ap_lincons0_array_t */ ap_lincons0_array_t ap_quasilinearize_lincons0_array(ap_manager_t* man, void* abs, ap_lincons0_array_t* array, bool* pexact, ap_scalar_discr_t discr, bool linearize, bool meet) { ap_linexpr_type_t type = ap_lincons0_array_type(array); if ((linearize && type==AP_LINEXPR_LINEAR) || type==AP_LINEXPR_QUASILINEAR){ *pexact = true; return *array; } else { switch (discr){ case AP_SCALAR_MPQ: return ap_quasilinearize_lincons0_array_MPQ(man,abs,array,pexact,linearize,meet); case AP_SCALAR_DOUBLE: return ap_quasilinearize_lincons0_array_D(man,abs,array,pexact,linearize,meet); case AP_SCALAR_MPFR: return ap_quasilinearize_lincons0_array_MPFR(man,abs,array,pexact,linearize,meet); default: abort(); } } } /* ********************************************************************** */ /* III. Evaluation of tree expressions */ /* ********************************************************************** */ ap_interval_t* ap_eval_texpr0(ap_manager_t* man, struct ap_abstract0_t* abs, ap_texpr0_t* expr, ap_scalar_discr_t discr, bool* pexact) { switch (discr){ case AP_SCALAR_MPQ: return ap_eval_texpr0_MPQ(man,abs,expr,pexact); case AP_SCALAR_DOUBLE: return ap_eval_texpr0_D(man,abs,expr,pexact); case AP_SCALAR_MPFR: return ap_eval_texpr0_MPFR(man,abs,expr,pexact); default: assert(false); return NULL; } } /* ********************************************************************** */ /* IV. Interval linearization of linear tree expressions */ /* ********************************************************************** */ /* Linearize a tree expression that is (syntaxically) interval linear with exact arithmetic. Compared to ap_intlinearize_texpr0() function below, this functions does not require a bounding box for dimensions. If the precondition is violated, returns NULL. */ ap_linexpr0_t* ap_intlinearize_texpr0_intlinear(ap_manager_t* man, ap_texpr0_t* expr, ap_scalar_discr_t discr) { switch (discr){ case AP_SCALAR_MPQ: return ap_intlinearize_texpr0_intlinear_MPQ(man,expr); case AP_SCALAR_DOUBLE: return ap_intlinearize_texpr0_intlinear_D(man,expr); case AP_SCALAR_MPFR: return ap_intlinearize_texpr0_intlinear_MPFR(man,expr); default: assert(false); return NULL; } } /* ********************************************************************** */ /* V. Interval linearization of tree expressions */ /* ********************************************************************** */ ap_linexpr0_t* ap_intlinearize_texpr0(ap_manager_t* man, ap_abstract0_t* abs, ap_texpr0_t* expr, bool* pexact, ap_scalar_discr_t discr, bool quasilinearize) { switch (discr){ case AP_SCALAR_MPQ: return ap_intlinearize_texpr0_MPQ(man,abs,expr,pexact,quasilinearize); case AP_SCALAR_DOUBLE: return ap_intlinearize_texpr0_D(man,abs,expr,pexact,quasilinearize); case AP_SCALAR_MPFR: return ap_intlinearize_texpr0_MPFR(man,abs,expr,pexact,quasilinearize); default: assert(false); return NULL; } } ap_linexpr0_t** ap_intlinearize_texpr0_array(ap_manager_t* man, ap_abstract0_t* abs, ap_texpr0_t** texpr, size_t size, bool* pexact, ap_scalar_discr_t discr, bool quasilinearize) { switch (discr){ case AP_SCALAR_MPQ: return ap_intlinearize_texpr0_array_MPQ(man,abs,texpr,size,pexact,quasilinearize); case AP_SCALAR_DOUBLE: return ap_intlinearize_texpr0_array_D(man,abs,texpr,size,pexact,quasilinearize); case AP_SCALAR_MPFR: return ap_intlinearize_texpr0_array_MPFR(man,abs,texpr,size,pexact,quasilinearize); default: assert(false); return NULL; } } ap_lincons0_t ap_intlinearize_tcons0(ap_manager_t* man, ap_abstract0_t* abs, ap_tcons0_t* cons, bool* pexact, ap_scalar_discr_t discr, bool quasilinearize, bool meet) { switch (discr){ case AP_SCALAR_MPQ: return ap_intlinearize_tcons0_MPQ(man,abs,cons,pexact,quasilinearize,meet); case AP_SCALAR_DOUBLE: return ap_intlinearize_tcons0_D(man,abs,cons,pexact,quasilinearize,meet); case AP_SCALAR_MPFR: return ap_intlinearize_tcons0_MPFR(man,abs,cons,pexact,quasilinearize,meet); default: assert(false); return ap_lincons0_make(AP_CONS_EQ,NULL,NULL); } } ap_lincons0_array_t ap_intlinearize_tcons0_array(ap_manager_t* man, ap_abstract0_t* abs, ap_tcons0_array_t* array, bool* pexact, ap_scalar_discr_t discr, ap_linexpr_type_t linearize, bool meet, bool boxize, size_t kmax, bool intervalonly) { switch (discr){ case AP_SCALAR_MPQ: return ap_intlinearize_tcons0_array_MPQ(man,abs,array,pexact,linearize,meet,boxize,kmax,intervalonly); case AP_SCALAR_DOUBLE: return ap_intlinearize_tcons0_array_D(man,abs,array,pexact,linearize,meet,boxize,kmax,intervalonly); case AP_SCALAR_MPFR: return ap_intlinearize_tcons0_array_MPFR(man,abs,array,pexact,linearize,meet,boxize,kmax,intervalonly); default: assert(false); return ap_lincons0_array_make(0); } } apron-dist-0.9.10/apron/apron/ap_expr1.h0000640014525101416610000000104110644461001017663 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_expr1.h: datatypes for dimensions, expressions and constraints */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _AP_EXPR1_H_ #define _AP_EXPR1_H_ #include "ap_linexpr1.h" #include "ap_lincons1.h" #include "ap_generator1.h" #include "ap_texpr1.h" #include "ap_tcons1.h" #endif apron-dist-0.9.10/apron/apron/ap_abstract0.h0000640014525101416610000004410211224616053020520 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_abstract0.h: generic operations on numerical abstract values */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _AP_ABSTRACT0_H_ #define _AP_ABSTRACT0_H_ typedef struct ap_abstract0_t ap_abstract0_t; #include "ap_manager.h" #include "ap_expr0.h" #ifdef __cplusplus extern "C" { #endif /* Generic abstract value at level 0 */ struct ap_abstract0_t { void* value; /* Abstract value of the underlying library */ ap_manager_t* man; /* Used to identify the effective type of value */ }; /* ********************************************************************** */ /* I. General management */ /* ********************************************************************** */ /* ============================================================ */ /* I.1 Memory */ /* ============================================================ */ ap_abstract0_t* ap_abstract0_copy(ap_manager_t* man, ap_abstract0_t* a); /* Return a copy of an abstract value, on which destructive update does not affect the initial value. */ void ap_abstract0_free(ap_manager_t* man, ap_abstract0_t* a); /* Free all the memory used by the abstract value */ size_t ap_abstract0_size(ap_manager_t* man, ap_abstract0_t* a); /* Return the abstract size of an abstract value (see ap_manager_t) */ /* ============================================================ */ /* I.2 Control of internal representation */ /* ============================================================ */ void ap_abstract0_minimize(ap_manager_t* man, ap_abstract0_t* a); /* Minimize the size of the representation of a. This may result in a later recomputation of internal information. */ void ap_abstract0_canonicalize(ap_manager_t* man, ap_abstract0_t* a); /* Put the abstract value in canonical form. (not yet clear definition) */ int ap_abstract0_hash(ap_manager_t* man, ap_abstract0_t* a); /* Return an hash value for the abstract value. Two abstract values in canonical from (according to @code{ap_abstract1_canonicalize}) and considered as equal by the function ap_abstract0_is_eq should be given the same hash value (this implies more or less a canonical form). */ void ap_abstract0_approximate(ap_manager_t* man, ap_abstract0_t* a, int algorithm); /* Perform some transformation on the abstract value, guided by the field algorithm. The transformation may lose information. The argument "algorithm" overrides the field algorithm of the structure of type ap_funopt_t associated to ap_abstract0_approximate (commodity feature). */ /* ============================================================ */ /* I.3 Printing */ /* ============================================================ */ void ap_abstract0_fprint(FILE* stream, ap_manager_t* man, ap_abstract0_t* a, char** name_of_dim); /* Print the abstract value in a pretty way, using function name_of_dim to name dimensions */ void ap_abstract0_fprintdiff(FILE* stream, ap_manager_t* man, ap_abstract0_t* a1, ap_abstract0_t* a2, char** name_of_dim); /* Print the difference between a1 (old value) and a2 (new value), using function name_of_dim to name dimensions. The meaning of difference is library dependent. */ void ap_abstract0_fdump(FILE* stream, ap_manager_t* man, ap_abstract0_t* a); /* Dump the internal representation of an abstract value, for debugging purposes */ /* ============================================================ */ /* I.4 Serialization */ /* ============================================================ */ ap_membuf_t ap_abstract0_serialize_raw(ap_manager_t* man, ap_abstract0_t* a); /* Allocate a memory buffer (with malloc), output the abstract value in raw binary format to it and return a pointer on the memory buffer and the size of bytes written. It is the user responsibility to free the memory afterwards (with free). */ ap_abstract0_t* ap_abstract0_deserialize_raw(ap_manager_t* man, void* ptr, size_t* size); /* Return the abstract value read in raw binary format from the input stream and store in size the number of bytes read */ /* ********************************************************************** */ /* II. Constructor, accessors, tests and property extraction */ /* ********************************************************************** */ /* ============================================================ */ /* II.1 Basic constructors */ /* ============================================================ */ /* We assume that dimensions [0..intdim-1] correspond to integer variables, and dimensions [intdim..intdim+realdim-1] to real variables */ ap_abstract0_t* ap_abstract0_bottom(ap_manager_t* man, size_t intdim, size_t realdim); /* Create a bottom (empty) value */ ap_abstract0_t* ap_abstract0_top(ap_manager_t* man, size_t intdim, size_t realdim); /* Create a top (universe) value */ ap_abstract0_t* ap_abstract0_of_box(ap_manager_t* man, size_t intdim, size_t realdim, ap_interval_t** tinterval); /* Abstract an hypercube defined by the array of intervals of size intdim+realdim */ /* ============================================================ */ /* II.2 Accessors */ /* ============================================================ */ ap_dimension_t ap_abstract0_dimension(ap_manager_t* man, ap_abstract0_t* a); /* Return the dimensionality of the abstract values */ /* ============================================================ */ /* II.3 Tests */ /* ============================================================ */ /* In abstract tests, - true means that the predicate is certainly true. - false means by default don't know (an exception has occurred, or the exact computation was considered too expensive to be performed). However, if the flag exact in the manager is true, then false means really that the predicate is false. */ bool ap_abstract0_is_bottom(ap_manager_t* man, ap_abstract0_t* a); bool ap_abstract0_is_top(ap_manager_t* man, ap_abstract0_t* a); bool ap_abstract0_is_leq(ap_manager_t* man, ap_abstract0_t* a1, ap_abstract0_t* a2); /* inclusion check */ bool ap_abstract0_is_eq(ap_manager_t* man, ap_abstract0_t* a1, ap_abstract0_t* a2); /* equality check */ bool ap_abstract0_sat_lincons(ap_manager_t* man, ap_abstract0_t* a, ap_lincons0_t* lincons); bool ap_abstract0_sat_tcons(ap_manager_t* man, ap_abstract0_t* a, ap_tcons0_t* tcons); /* does the abstract value satisfy the constraint ? */ bool ap_abstract0_sat_interval(ap_manager_t* man, ap_abstract0_t* a, ap_dim_t dim, ap_interval_t* interval); /* is the dimension included in the interval in the abstract value ? */ bool ap_abstract0_is_dimension_unconstrained(ap_manager_t* man, ap_abstract0_t* a, ap_dim_t dim); /* is the dimension unconstrained in the abstract value ? If it is the case, we have forget(man,a,dim) == a */ /* ============================================================ */ /* II.4 Extraction of properties */ /* ============================================================ */ ap_interval_t* ap_abstract0_bound_linexpr(ap_manager_t* man, ap_abstract0_t* a, ap_linexpr0_t* expr); ap_interval_t* ap_abstract0_bound_texpr(ap_manager_t* man, ap_abstract0_t* a, ap_texpr0_t* expr); /* Returns the interval taken by the expression over the abstract value */ ap_interval_t* ap_abstract0_bound_dimension(ap_manager_t* man, ap_abstract0_t* a, ap_dim_t dim); /* Returns the interval taken by the dimension over the abstract value */ ap_lincons0_array_t ap_abstract0_to_lincons_array(ap_manager_t* man, ap_abstract0_t* a); /* Converts an abstract value to a polyhedra (conjunction of linear constraints). The constraints are normally guaranteed to be really linear (without intervals) */ ap_tcons0_array_t ap_abstract0_to_tcons_array(ap_manager_t* man, ap_abstract0_t* a); /* Converts an abstract value to conjunction of tree expressions constraints. The constraints are normally guaranteed to be scalar (without intervals) */ ap_interval_t** ap_abstract0_to_box(ap_manager_t* man, ap_abstract0_t* a); /* Converts an abstract value to an interval/hypercube. The size of the resulting array is ap_abstract0_dimension(man,a). This function can be reimplemented by using ap_abstract0_bound_linexpr */ ap_generator0_array_t ap_abstract0_to_generator_array(ap_manager_t* man, ap_abstract0_t* a); /* Converts an abstract value to a system of generators. */ /* ********************************************************************** */ /* III. Operations */ /* ********************************************************************** */ /* ============================================================ */ /* III.1 Meet and Join */ /* ============================================================ */ ap_abstract0_t* ap_abstract0_meet(ap_manager_t* man, bool destructive, ap_abstract0_t* a1, ap_abstract0_t* a2); ap_abstract0_t* ap_abstract0_join(ap_manager_t* man, bool destructive, ap_abstract0_t* a1, ap_abstract0_t* a2); /* Meet and Join of 2 abstract values */ ap_abstract0_t* ap_abstract0_meet_array(ap_manager_t* man, ap_abstract0_t** tab, size_t size); ap_abstract0_t* ap_abstract0_join_array(ap_manager_t* man, ap_abstract0_t** tab, size_t size); /* Meet and Join of an array of abstract values. Raises an [[exc_invalid_argument]] exception if [[size==0]] (no way to define the dimensionality of the result in such a case */ ap_abstract0_t* ap_abstract0_meet_lincons_array(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_lincons0_array_t* array); ap_abstract0_t* ap_abstract0_meet_tcons_array(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_tcons0_array_t* array); /* Meet of an abstract value with a set of constraints */ ap_abstract0_t* ap_abstract0_add_ray_array(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_generator0_array_t* array); /* Generalized time elapse operator */ /* ============================================================ */ /* III.2 Assignment and Substitutions */ /* ============================================================ */ ap_abstract0_t* ap_abstract0_assign_linexpr_array(ap_manager_t* man, bool destructive, ap_abstract0_t* org, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, ap_abstract0_t* dest); ap_abstract0_t* ap_abstract0_assign_texpr_array(ap_manager_t* man, bool destructive, ap_abstract0_t* org, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, ap_abstract0_t* dest); ap_abstract0_t* ap_abstract0_substitute_linexpr_array(ap_manager_t* man, bool destructive, ap_abstract0_t* org, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, ap_abstract0_t* dest); ap_abstract0_t* ap_abstract0_substitute_texpr_array(ap_manager_t* man, bool destructive, ap_abstract0_t* org, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, ap_abstract0_t* dest); /* Parallel Assignment and Substitution of several dimensions by linear/tree expressions in abstract value org. dest is an optional argument. If not NULL, semantically speaking, the result of the transformation is intersected with dest. This is useful for precise backward transformations in lattices like intervals or octagons. */ /* ============================================================ */ /* III.3 Projections */ /* ============================================================ */ ap_abstract0_t* ap_abstract0_forget_array(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dim_t* tdim, size_t size, bool project); /* ============================================================ */ /* III.4 Change and permutation of dimensions */ /* ============================================================ */ ap_abstract0_t* ap_abstract0_add_dimensions(ap_manager_t* man, bool destructive, ap_abstract0_t* a,ap_dimchange_t* dimchange, bool project); ap_abstract0_t* ap_abstract0_remove_dimensions(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dimchange_t* dimchange); /* Size of the permutation is supposed to be equal to the dimension of the abstract value */ ap_abstract0_t* ap_abstract0_permute_dimensions(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dimperm_t* perm); /* ============================================================ */ /* III.5 Expansion and folding of dimensions */ /* ============================================================ */ ap_abstract0_t* ap_abstract0_expand(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dim_t dim, size_t n); /* Expand the dimension dim into itself + n additional dimensions. It results in (n+1) unrelated dimensions having same relations with other dimensions. The (n+1) dimensions are put as follows: - original dimension dim - if the dimension is integer, the n additional dimensions are put at the end of integer dimensions; if it is real, at the end of the real dimensions. */ ap_abstract0_t* ap_abstract0_fold(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dim_t* tdim, size_t size); /* Fold the dimensions in the array tdim of size n>=1 and put the result in the first dimension in the array. The other dimensions of the array are then removed (using ap_abstract0_permute_remove_dimensions). */ /* ============================================================ */ /* III.6 Widening */ /* ============================================================ */ ap_abstract0_t* ap_abstract0_widening(ap_manager_t* man, ap_abstract0_t* a1, ap_abstract0_t* a2); /* ============================================================ */ /* III.7 Closure operation */ /* ============================================================ */ /* Returns the topological closure of a possibly opened abstract value */ ap_abstract0_t* ap_abstract0_closure(ap_manager_t* man, bool destructive, ap_abstract0_t* a); /* ********************************************************************** */ /* IV. Functions offered by the APRON interface */ /* ********************************************************************** */ /* These functions do not correspond to functions in the underlying library. */ static inline ap_manager_t* ap_abstract0_manager(ap_abstract0_t* a) { return a->man; } /* Return a reference to the manager contained in the abstract value. The reference should not be freed */ ap_abstract0_t* ap_abstract0_of_lincons_array(ap_manager_t* man, size_t intdim, size_t realdim, ap_lincons0_array_t* array); ap_abstract0_t* ap_abstract0_of_tcons_array(ap_manager_t* man, size_t intdim, size_t realdim, ap_tcons0_array_t* array); /* Abstract a conjunction of tree constraints */ ap_abstract0_t* ap_abstract0_assign_linexpr(ap_manager_t* man, bool destructive, ap_abstract0_t* org, ap_dim_t dim, ap_linexpr0_t* expr, ap_abstract0_t* dest); ap_abstract0_t* ap_abstract0_assign_texpr(ap_manager_t* man, bool destructive, ap_abstract0_t* org, ap_dim_t dim, ap_texpr0_t* expr, ap_abstract0_t* dest); ap_abstract0_t* ap_abstract0_substitute_linexpr(ap_manager_t* man, bool destructive, ap_abstract0_t* org, ap_dim_t dim, ap_linexpr0_t* expr, ap_abstract0_t* dest); ap_abstract0_t* ap_abstract0_substitute_texpr(ap_manager_t* man, bool destructive, ap_abstract0_t* org, ap_dim_t dim, ap_texpr0_t* expr, ap_abstract0_t* dest); /* Assignment and Substitution of a single dimension by an expression in abstract value org. dest is an optional argument. If not NULL, semantically speaking, the result of the transformation is intersected with dest. This is useful for precise backward transformations in lattices like intervals or octagons. */ /* Applying an ap_dimchange2_t transformation (dimension adding followed by dimension removal/projection). If project is true, the newly added dimension are projected on their 0-hyperplane. */ ap_abstract0_t* ap_abstract0_apply_dimchange2(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dimchange2_t* dimchange2, bool project); /* Widening with threshold */ ap_abstract0_t* ap_abstract0_widening_threshold(ap_manager_t* man, ap_abstract0_t* a1, ap_abstract0_t* a2, ap_lincons0_array_t* array); /* ********************************************************************** */ /* ********************************************************************** */ /* Internal functions */ /* ********************************************************************** */ /* ********************************************************************** */ ap_abstract0_t* ap_abstract0_meetjoin(ap_funid_t funid, /* either meet or join */ ap_manager_t* man, bool destructive, ap_abstract0_t* a1, ap_abstract0_t* a2); ap_abstract0_t* ap_abstract0_asssub_linexpr(ap_funid_t funid, /* either assign or substitute */ ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dim_t dim, ap_linexpr0_t* expr, ap_abstract0_t* dest); ap_abstract0_t* ap_abstract0_asssub_linexpr_array(ap_funid_t funid, /* either assign or substitute */ ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, ap_abstract0_t* dest); ap_abstract0_t* ap_abstract0_asssub_texpr(ap_funid_t funid, /* either assign or substitute */ ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dim_t dim, ap_texpr0_t* expr, ap_abstract0_t* dest); ap_abstract0_t* ap_abstract0_asssub_texpr_array(ap_funid_t funid, /* either assign or substitute */ ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, ap_abstract0_t* dest); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/ap_texpr0.h0000640014525101416610000002125111122224023020044 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_texpr0.h: tree expressions */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #ifndef _AP_TEXPR0_H_ #define _AP_TEXPR0_H_ #include "ap_dimension.h" #include "ap_coeff.h" #include "ap_linexpr0.h" #ifdef __cplusplus extern "C" { #endif /* ====================================================================== */ /* Datatypes */ /* ====================================================================== */ /* IMPORTANT NOTE -------------- correct use of floating-point AP_RTYPE_xxx currently supposes that the FPU rounds towards +oo */ /* Operators */ typedef enum ap_texpr_op_t { /* Binary operators */ AP_TEXPR_ADD, AP_TEXPR_SUB, AP_TEXPR_MUL, AP_TEXPR_DIV, AP_TEXPR_MOD, /* either integer or real, no rounding */ /* Unary operators */ AP_TEXPR_NEG /* no rounding */, AP_TEXPR_CAST, AP_TEXPR_SQRT, } ap_texpr_op_t; /* Numerical type (destination of rounding) */ typedef enum ap_texpr_rtype_t { AP_RTYPE_REAL, /* real (no rounding) */ AP_RTYPE_INT, /* integer */ AP_RTYPE_SINGLE, /* IEEE 754 32-bit single precision, e.g.: C's float */ AP_RTYPE_DOUBLE, /* IEEE 754 64-bit double precision, e.g.: C's double */ AP_RTYPE_EXTENDED, /* non-standard 80-bit double extended, e.g.: Intel's long double */ AP_RTYPE_QUAD, /* non-standard 128-bit quadruple precision, e.g.: Motorola's long double */ AP_RTYPE_SIZE /* Not to be used ! */ } ap_texpr_rtype_t; /* Rounding direction */ typedef enum ap_texpr_rdir_t { AP_RDIR_NEAREST = GMP_RNDN, /* Nearest */ AP_RDIR_ZERO = GMP_RNDZ, /* Zero (truncation for integers) */ AP_RDIR_UP = GMP_RNDU, /* + Infinity */ AP_RDIR_DOWN = GMP_RNDD, /* - Infinity */ AP_RDIR_RND, /* All possible mode, non deterministically */ AP_RDIR_SIZE /* Not to be used ! */ } ap_texpr_rdir_t; /* Internal (operator) nodes */ typedef struct ap_texpr0_node_t { ap_texpr_op_t op; ap_texpr_rtype_t type; ap_texpr_rdir_t dir; struct ap_texpr0_t* exprA; /* First operand */ struct ap_texpr0_t* exprB; /* Second operand (for binary operations) or NULL */ } ap_texpr0_node_t; /* Node types */ typedef enum ap_texpr_discr_t { AP_TEXPR_CST, AP_TEXPR_DIM, AP_TEXPR_NODE } ap_texpr_discr_t; typedef struct ap_texpr0_t { ap_texpr_discr_t discr; union { ap_coeff_t cst; ap_dim_t dim; ap_texpr0_node_t* node; } val; } ap_texpr0_t; /* ====================================================================== */ /* I. Constructors and Destructors */ /* ====================================================================== */ ap_texpr0_t* ap_texpr0_cst (ap_coeff_t* coeff); ap_texpr0_t* ap_texpr0_cst_scalar (ap_scalar_t* scalar); ap_texpr0_t* ap_texpr0_cst_scalar_mpq (mpq_t mpq); ap_texpr0_t* ap_texpr0_cst_scalar_mpfr (mpfr_t mpfr); ap_texpr0_t* ap_texpr0_cst_scalar_int (long int num); ap_texpr0_t* ap_texpr0_cst_scalar_frac (long int num, unsigned long int den); ap_texpr0_t* ap_texpr0_cst_scalar_double (double num); ap_texpr0_t* ap_texpr0_cst_interval (ap_interval_t* itv); ap_texpr0_t* ap_texpr0_cst_interval_scalar (ap_scalar_t* inf, ap_scalar_t* sup); ap_texpr0_t* ap_texpr0_cst_interval_mpq (mpq_t inf, mpq_t sup); ap_texpr0_t* ap_texpr0_cst_interval_mpfr (mpfr_t inf, mpfr_t sup); ap_texpr0_t* ap_texpr0_cst_interval_int (long int inf, long int sup); ap_texpr0_t* ap_texpr0_cst_interval_frac (long int numinf, unsigned long int deninf, long int numsup, unsigned long int densup); ap_texpr0_t* ap_texpr0_cst_interval_double (double inf, double sup); ap_texpr0_t* ap_texpr0_cst_interval_top (void); /* Create a constant leaf expression */ ap_texpr0_t* ap_texpr0_dim(ap_dim_t dim); /* Create a dimension (variable) leaf expression */ ap_texpr0_t* ap_texpr0_unop(ap_texpr_op_t op, ap_texpr0_t* opA, ap_texpr_rtype_t type, ap_texpr_rdir_t dir); /* Create unary operator node */ ap_texpr0_t* ap_texpr0_binop(ap_texpr_op_t op, ap_texpr0_t* opA, ap_texpr0_t* opB, ap_texpr_rtype_t type, ap_texpr_rdir_t dir); /* Create binary operator node */ ap_texpr0_t* ap_texpr0_copy(ap_texpr0_t* expr); /* Recursive (deep) copy */ void ap_texpr0_free(ap_texpr0_t* expr); /* Recursive (deep) free */ ap_texpr0_t* ap_texpr0_from_linexpr0(ap_linexpr0_t* e); /* From linear expression to comb-like expression tree */ /* ====================================================================== */ /* II. Printing */ /* ====================================================================== */ void ap_texpr0_fprint(FILE* stream, ap_texpr0_t* a, char** name_of_dim); void ap_texpr0_print(ap_texpr0_t* a, char** name_of_dim); /* Prints the expression, name_of_dim can be NULL */ /* ====================================================================== */ /* III. Tests, size */ /* ====================================================================== */ static inline bool ap_texpr_is_unop(ap_texpr_op_t op){ return (op>=AP_TEXPR_NEG && op<=AP_TEXPR_SQRT); } static inline bool ap_texpr_is_binop(ap_texpr_op_t op){ return (op<=AP_TEXPR_MOD); } /* Operator classification */ size_t ap_texpr0_depth(ap_texpr0_t* a); /* Returns the depth, in operator nodes */ size_t ap_texpr0_size(ap_texpr0_t* a); /* Returns the number of operator nodes */ ap_dim_t ap_texpr0_max_dim(ap_texpr0_t* a); /* Returns the maximum ap_dim_t PLUS ONE of all dimensions in expression, and 0 if no dimension at all. For instance, it returns 3 on the expression x2. */ bool ap_texpr0_has_dim(ap_texpr0_t* a, ap_dim_t d); /* Returns true if dimension d appears in the expression */ ap_dim_t* ap_texpr0_dimlist(ap_texpr0_t* a); /* Returns an ordered, AP_DIM_MAX-terminated array of occurring dimensions; caller should free() the array after use */ /* Expression classification */ bool ap_texpr0_is_interval_cst(ap_texpr0_t* a); /* no-variable, only constant leaves */ bool ap_texpr0_is_interval_linear(ap_texpr0_t* a); /* linear with possibly interval coefficients, no rounding */ bool ap_texpr0_is_interval_polynomial(ap_texpr0_t* a); /* polynomial with possibly interval coefficients, no rounding */ bool ap_texpr0_is_interval_polyfrac(ap_texpr0_t* a); /* polynomial fraction with possibly interval coefficients, no rounding */ bool ap_texpr0_is_scalar(ap_texpr0_t* a); /* all coefficients are scalar (non-interval) */ bool ap_texpr0_array_is_interval_linear(ap_texpr0_t** texpr, size_t size); bool ap_texpr0_array_is_interval_polynomial(ap_texpr0_t** texpr, size_t size); bool ap_texpr0_array_is_interval_polyfrac(ap_texpr0_t** texpr, size_t size); bool ap_texpr0_array_is_scalar(ap_texpr0_t** texpr, size_t size); /* idem for arrays */ /* ====================================================================== */ /* IV. Operations */ /* ====================================================================== */ ap_texpr0_t* ap_texpr0_substitute(ap_texpr0_t* a, ap_dim_t dim, ap_texpr0_t *dst); void ap_texpr0_substitute_with (ap_texpr0_t* a, ap_dim_t dim, ap_texpr0_t *dst); /* Substitute every occurrence of dimension dim with a copy of dst */ /* ====================================================================== */ /* V. Change of dimensions and permutations */ /* ====================================================================== */ ap_texpr0_t* ap_texpr0_add_dimensions(ap_texpr0_t* expr, ap_dimchange_t* dimchange); ap_texpr0_t* ap_texpr0_remove_dimensions(ap_texpr0_t* expr, ap_dimchange_t* dimchange); ap_texpr0_t* ap_texpr0_permute_dimensions(ap_texpr0_t* expr, ap_dimperm_t* dimperm); void ap_texpr0_add_dimensions_with(ap_texpr0_t* expr, ap_dimchange_t* dimchange); void ap_texpr0_remove_dimensions_with(ap_texpr0_t* expr, ap_dimchange_t* dimchange); void ap_texpr0_permute_dimensions_with(ap_texpr0_t* expr, ap_dimperm_t* perm); /* Note: removed variables are replaced with a top interval */ /* ====================================================================== */ /* VI. Hashing, comparisons */ /* ====================================================================== */ long ap_texpr0_hash(ap_texpr0_t* a); /* Recursive hashing */ bool ap_texpr0_equal(ap_texpr0_t* a1, ap_texpr0_t* a2); /* Structural (recursive) equality */ /* used internally */ ap_texpr0_t* ap_texpr0_node(ap_texpr_op_t op, ap_texpr_rtype_t type, ap_texpr_rdir_t dir, ap_texpr0_t* opA, ap_texpr0_t* opB); void ap_texpr0_node_free(ap_texpr0_node_t* node); void ap_texpr0_clear(ap_texpr0_t* node); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/ap_linearize_aux.h0000640014525101416610000000752711122224307021500 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_linearize_aux.h: auxiliary functions for (quasi)linearisation */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ /* Auxiliary module to ap_linearize, which contains functions depending of the number representation */ /* may be included several times, with different NUM_ defined */ #if !defined(NUM_MPQ) && !defined(NUM_DOUBLE) && !defined(NUM_LONGDOUBLE) && !defined(NUM_MPFR) #error "Wrong NUM type" #endif #include "ap_manager.h" #include "ap_expr0.h" #include "ap_abstract0.h" #include "itv_fun.h" #ifdef __cplusplus extern "C" { #endif /* ********************************************************************** */ /* I. Evaluation of interval linear expressions */ /* ********************************************************************** */ ap_interval_t* ITVFUN(ap_eval_linexpr0)(ap_manager_t* man, ap_abstract0_t* abs, ap_linexpr0_t* expr, bool* pexact); /* ********************************************************************** */ /* II. Quasilinearization of interval linear expressions */ /* ********************************************************************** */ ap_linexpr0_t* ITVFUN(ap_quasilinearize_linexpr0)(ap_manager_t* man, ap_abstract0_t* abs, ap_linexpr0_t* linexpr0, bool* pexact); ap_lincons0_t ITVFUN(ap_quasilinearize_lincons0)(ap_manager_t* man, ap_abstract0_t* abs, ap_lincons0_t* lincons0, bool* pexact, bool meet); ap_linexpr0_t** ITVFUN(ap_quasilinearize_linexpr0_array)(ap_manager_t* man, ap_abstract0_t* abs, ap_linexpr0_t** texpr, size_t size, bool* pexact); ap_lincons0_array_t ITVFUN(ap_quasilinearize_lincons0_array)(ap_manager_t* man, ap_abstract0_t* abs, ap_lincons0_array_t* array, bool* pexact, bool linearize, bool meet); /* ********************************************************************** */ /* III. Evaluation of tree expressions */ /* ********************************************************************** */ ap_interval_t* ITVFUN(ap_eval_texpr0)(ap_manager_t* man, ap_abstract0_t* abs, ap_texpr0_t* expr, bool* pexact); /* ********************************************************************** */ /* IV. Interval linearization of linear tree expressions */ /* ********************************************************************** */ /* Linearize a tree expression that is (syntaxically) interval linear with exact arithmetic. Compared to ap_intlinearize_texpr0() function below, this functions does not require a bounding box for dimensions. If the precondition is violated, returns NULL. */ ap_linexpr0_t* ITVFUN(ap_intlinearize_texpr0_intlinear)(ap_manager_t* man, ap_texpr0_t* expr); /* ********************************************************************** */ /* V. Interval linearization of tree expressions */ /* ********************************************************************** */ ap_linexpr0_t* ITVFUN(ap_intlinearize_texpr0)(ap_manager_t* man, ap_abstract0_t* abs, ap_texpr0_t* expr, bool* pexact, bool quasilinearize); ap_linexpr0_t** ITVFUN(ap_intlinearize_texpr0_array)(ap_manager_t* man, ap_abstract0_t* abs, ap_texpr0_t** texpr0, size_t size, bool* pexact, bool quasilinearize); ap_lincons0_t ITVFUN(ap_intlinearize_tcons0)(ap_manager_t* man, ap_abstract0_t* abs, ap_tcons0_t* cons, bool* pexact, bool quasilinearize, bool meet); ap_lincons0_array_t ITVFUN(ap_intlinearize_tcons0_array)(ap_manager_t* man, ap_abstract0_t* abs, ap_tcons0_array_t* array, bool* pexact, ap_linexpr_type_t linearize, bool meet, bool boxize, size_t kmax, bool intervalonly); #ifdef __cplusplus } #endif apron-dist-0.9.10/apron/apron/ap_lincons0.c0000640014525101416610000001430110656607177020372 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_lincons0.c: linear constraints and arrays */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "ap_lincons0.h" /* ********************************************************************** */ /* I. Linear constraints */ /* ********************************************************************** */ void ap_lincons0_fprint(FILE* stream, ap_lincons0_t* cons, char** name_of_dim) { ap_linexpr0_fprint(stream,cons->linexpr0,name_of_dim); fprintf(stream, cons->constyp == AP_CONS_EQ || cons->constyp == AP_CONS_EQMOD ? " = 0" : ( cons->constyp == AP_CONS_SUPEQ ? " >= 0" : (cons->constyp == AP_CONS_SUP ? " > 0" : (cons->constyp == AP_CONS_DISEQ ? " != 0" : "\"ERROR in ap_lincons0_fprint\"")))); if (cons->constyp == AP_CONS_EQMOD){ assert(cons->scalar!=NULL); fprintf(stream," mod "); ap_scalar_fprint(stream,cons->scalar); } } ap_lincons0_t ap_lincons0_make_unsat() { ap_linexpr0_t* expr; expr = ap_linexpr0_alloc(AP_LINEXPR_DENSE,0); ap_coeff_set_scalar_double(&expr->cst,-1.0); return ap_lincons0_make(AP_CONS_SUPEQ,expr,NULL); } bool ap_lincons0_is_unsat(ap_lincons0_t* cons) { size_t i,nbcoeffs; ap_dim_t dim; ap_coeff_t* coeff; int sgn; ap_linexpr0_t* expr = cons->linexpr0; nbcoeffs = 0; ap_linexpr0_ForeachLinterm(expr,i,dim,coeff){ if (!ap_coeff_zero(coeff)){ nbcoeffs++; if (nbcoeffs>0) break; } } if (nbcoeffs==0){ switch (expr->cst.discr){ case AP_COEFF_SCALAR: sgn = ap_scalar_sgn(expr->cst.val.scalar); switch(cons->constyp){ case AP_CONS_EQ: case AP_CONS_EQMOD: return (sgn!=0); case AP_CONS_DISEQ: return (sgn==0); case AP_CONS_SUPEQ: return (sgn<0); case AP_CONS_SUP: return (sgn<=0); } case AP_COEFF_INTERVAL: sgn = ap_scalar_sgn(expr->cst.val.interval->sup); switch(cons->constyp){ case AP_CONS_EQ: case AP_CONS_EQMOD: return sgn < 0 || ap_scalar_sgn(expr->cst.val.interval->inf)>0; case AP_CONS_DISEQ: return sgn>=0 && ap_scalar_sgn(expr->cst.val.interval->inf)<=0; case AP_CONS_SUPEQ: return sgn<0; case AP_CONS_SUP: return (sgn<=0); } default: abort(); } } else return false; } /* ********************************************************************** */ /* II. Array of linear constraints */ /* ********************************************************************** */ ap_lincons0_array_t ap_lincons0_array_make(size_t size) { ap_lincons0_array_t array; size_t i; array.size = size; array.p = (size==0) ? NULL : (ap_lincons0_t*)malloc(size*sizeof(ap_lincons0_t)); for (i=0; isize; i++){ ap_lincons0_clear(&array->p[i]); } array->p = (ap_lincons0_t*)realloc(array->p,size*sizeof(ap_lincons0_t)); for (i=array->size; ip[i].linexpr0 = NULL; array->p[i].scalar = NULL; } array->size = size; } void ap_lincons0_array_clear(ap_lincons0_array_t* array) { size_t i; if (array->p!=NULL){ for (i=0; isize; i++) ap_lincons0_clear(&array->p[i]); free(array->p); array->p=NULL; } } void ap_lincons0_array_fprint(FILE* stream, ap_lincons0_array_t* array, char** name_of_dim) { size_t i; if (array->size==0){ fprintf(stream,"empty array of constraints\n"); } else { fprintf(stream,"array of constraints of size %lu\n", (unsigned long)array->size); for (i=0; isize; i++){ fprintf(stream,"%2lu: ",(unsigned long)i); ap_lincons0_fprint(stream,&array->p[i],name_of_dim); fprintf(stream,"\n"); } } } ap_linexpr_type_t ap_lincons0_array_type(ap_lincons0_array_t* array) { size_t i; ap_linexpr_type_t res = AP_LINEXPR_LINEAR; for (i=0; isize; i++){ ap_linexpr_type_t type = ap_linexpr0_type(array->p[i].linexpr0); if (type < res) type = res; if (res==AP_LINEXPR_INTLINEAR) break; } return res; } bool ap_lincons0_array_is_quasilinear(ap_lincons0_array_t* array) { size_t i; bool res = true; for (i=0; isize; i++){ if (!ap_linexpr0_is_quasilinear(array->p[i].linexpr0)){ res = false; break; } } return res; } bool ap_lincons0_array_is_linear(ap_lincons0_array_t* array) { size_t i; bool res = true; for (i=0; isize; i++){ if (!ap_linexpr0_is_linear(array->p[i].linexpr0)){ res = false; break; } } return res; } /* ====================================================================== */ /* II.1 Change of dimensions and permutations */ /* ====================================================================== */ void ap_lincons0_array_add_dimensions_with(ap_lincons0_array_t* array, ap_dimchange_t* dimchange) { size_t i; for(i=0; isize; i++){ ap_linexpr0_t* expr = array->p[i].linexpr0; if (expr) ap_linexpr0_add_dimensions_with(expr,dimchange); } } ap_lincons0_array_t ap_lincons0_array_add_dimensions(ap_lincons0_array_t* array, ap_dimchange_t* dimchange) { size_t i; ap_lincons0_array_t narray; narray = ap_lincons0_array_make(array->size); for(i=0; isize; i++){ narray.p[i] = ap_lincons0_add_dimensions(&array->p[i],dimchange); } return narray; } void ap_lincons0_array_permute_dimensions_with(ap_lincons0_array_t* array, ap_dimperm_t* perm) { size_t i; for(i=0; isize; i++){ ap_linexpr0_t* expr = array->p[i].linexpr0; if (expr) ap_linexpr0_permute_dimensions_with(expr,perm); } } ap_lincons0_array_t ap_lincons0_array_permute_dimensions(ap_lincons0_array_t* array, ap_dimperm_t* perm) { size_t i; ap_lincons0_array_t narray; narray = ap_lincons0_array_make(array->size); for(i=0; isize; i++){ narray.p[i] = ap_lincons0_permute_dimensions(&array->p[i],perm); } return narray; } apron-dist-0.9.10/apron/apron/ap_lincons1.c0000640014525101416610000001466410571032754020374 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_lincons1.c: linear constraints */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "ap_lincons1.h" /* ********************************************************************** */ /* I. ap_lincons0_t */ /* ********************************************************************** */ /* ====================================================================== */ /* I.1 Memory management and printing */ /* ====================================================================== */ ap_lincons1_t ap_lincons1_make_unsat(ap_environment_t* env) { ap_lincons1_t lincons1; lincons1.lincons0 = ap_lincons0_make_unsat(); lincons1.env = ap_environment_copy(env); return lincons1; } void ap_lincons1_clear(ap_lincons1_t* cons) { ap_lincons0_clear(&cons->lincons0); if (cons->env){ ap_environment_free(cons->env); cons->env = NULL; } } void ap_lincons1_fprint(FILE* stream, ap_lincons1_t* cons) { ap_environment_name_of_dim_t* name_of_dim; name_of_dim = ap_environment_name_of_dim_alloc(cons->env); ap_lincons0_fprint(stream, &cons->lincons0, name_of_dim->p); ap_environment_name_of_dim_free(name_of_dim); } /* ====================================================================== */ /* I.2 Tests */ /* ====================================================================== */ /* ====================================================================== */ /* I.3 Access */ /* ====================================================================== */ ap_coeff_t* ap_lincons1_coeffref(ap_lincons1_t* cons, ap_var_t var) { ap_dim_t dim = ap_environment_dim_of_var(cons->env,var); return ap_linexpr0_coeffref(cons->lincons0.linexpr0,dim); } bool ap_lincons1_get_coeff(ap_coeff_t* coeff, ap_lincons1_t* cons, ap_var_t var) { ap_dim_t dim = ap_environment_dim_of_var(cons->env,var); return ap_linexpr0_get_coeff(coeff,cons->lincons0.linexpr0,dim); } ap_coeff_t* ap_lincons1_set_list_get_pcoeff(void* cons, bool cst, va_list* va) { ap_coeff_t* pcoeff; if (cst){ pcoeff = ap_lincons1_cstref(cons); } else { ap_var_t var = va_arg(*va,ap_var_t); pcoeff = ap_lincons1_coeffref(cons,var); } return pcoeff; } bool ap_lincons1_set_list(ap_lincons1_t* cons, ...) { va_list va; bool res; va_start(va,cons); res = ap_linexpr0_set_list_generic(ap_lincons1_set_list_get_pcoeff, cons,&va); va_end(va); return res; } /* ====================================================================== */ /* I.4 Change of dimensions and permutations */ /* ====================================================================== */ bool ap_lincons1_extend_environment(ap_lincons1_t* ncons, ap_lincons1_t* cons, ap_environment_t* nenv) { ap_dimchange_t* dimchange = ap_environment_dimchange(cons->env,nenv); if (dimchange==NULL) return true; ncons->lincons0 = ap_lincons0_add_dimensions(&cons->lincons0,dimchange); ncons->env = ap_environment_copy(nenv); ap_dimchange_free(dimchange); return false; } bool ap_lincons1_extend_environment_with(ap_lincons1_t* cons, ap_environment_t* nenv) { ap_environment_t* env; ap_dimchange_t* dimchange = ap_environment_dimchange(cons->env,nenv); if (dimchange==NULL) return true; ap_lincons0_add_dimensions_with(&cons->lincons0,dimchange); env = cons->env; cons->env = ap_environment_copy(nenv); ap_dimchange_free(dimchange); ap_environment_free(env); return false; } /* ********************************************************************** */ /* II. Array of linear constraints */ /* ********************************************************************** */ /* ====================================================================== */ /* I.1 Memory management and printing */ /* ====================================================================== */ ap_lincons1_array_t ap_lincons1_array_make(ap_environment_t* env, size_t size) { ap_lincons1_array_t array; array.lincons0_array = ap_lincons0_array_make(size); array.env = ap_environment_copy(env); return array; } void ap_lincons1_array_clear(ap_lincons1_array_t* array) { ap_lincons0_array_clear(&array->lincons0_array); ap_environment_free(array->env); array->env = NULL; } void ap_lincons1_array_fprint(FILE* stream, ap_lincons1_array_t* array) { ap_environment_name_of_dim_t* name_of_dim; name_of_dim = ap_environment_name_of_dim_alloc(array->env); ap_lincons0_array_fprint(stream,&array->lincons0_array,name_of_dim->p); ap_environment_name_of_dim_free(name_of_dim); } /* ====================================================================== */ /* II.3 Access */ /* ====================================================================== */ ap_lincons1_t ap_lincons1_array_get(ap_lincons1_array_t* array, size_t index) { ap_lincons1_t cons; cons.lincons0 = array->lincons0_array.p[index]; cons.env = array->env; return cons; } bool ap_lincons1_array_set(ap_lincons1_array_t* array, size_t index, ap_lincons1_t* cons) { if (index>=array->lincons0_array.size || !ap_environment_is_eq(cons->env,array->env)) return true; ap_lincons1_array_clear_index(array,index); array->lincons0_array.p[index] = cons->lincons0; ap_environment_free(cons->env); return false; } /* ====================================================================== */ /* II.4 Change of dimensions and permutations */ /* ====================================================================== */ bool ap_lincons1_array_extend_environment_with(ap_lincons1_array_t* array, ap_environment_t* nenv) { ap_environment_t* env; ap_dimchange_t* dimchange = ap_environment_dimchange(array->env,nenv); if (dimchange==NULL) return true; ap_lincons0_array_add_dimensions_with(&array->lincons0_array,dimchange); env = array->env; array->env = ap_environment_copy(nenv); ap_dimchange_free(dimchange); ap_environment_free(env); return false; } bool ap_lincons1_array_extend_environment(ap_lincons1_array_t* narray, ap_lincons1_array_t* array, ap_environment_t* nenv) { ap_dimchange_t* dimchange = ap_environment_dimchange(array->env,nenv); if (dimchange==NULL) return true; narray->lincons0_array = ap_lincons0_array_add_dimensions(&array->lincons0_array,dimchange); narray->env = ap_environment_copy(nenv); ap_dimchange_free(dimchange); return false; } apron-dist-0.9.10/apron/apron/ap_abstract1.c0000640014525101416610000013607611224616334020532 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_abstract1.c: level 1 of interface */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include "ap_coeff.h" #include "ap_manager.h" #include "ap_abstract0.h" #include "ap_expr0.h" #include "ap_expr1.h" #include "ap_abstract1.h" /* Normal constructor */ static inline ap_abstract1_t ap_abstract1_cons(ap_abstract0_t* a0, ap_environment_t* env) { ap_abstract1_t res; res.abstract0 = a0; res.env = ap_environment_copy(env); return res; } /* Special constructor: Build a new abstract value level 1 from the old one and a new value level 0, depending on destructive. The environment is supposed unchanged. */ static ap_abstract1_t ap_abstract1_consres(bool destructive, ap_abstract1_t* a, ap_abstract0_t* value) { ap_abstract1_t res; if (destructive){ if (value==a->abstract0) res = *a; else { res.abstract0 = value; res.env = a->env; } } else { res = ap_abstract1_cons(value,a->env); } return res; } /* Special constructor 2: Build a new abstract value level 1 from the old one, a new value level 0 and a new environment, depending on destructive. */ static ap_abstract1_t ap_abstract1_consres2(bool destructive, ap_abstract1_t* a, ap_abstract0_t* value, ap_environment_t* env) { ap_abstract1_t res; if (destructive){ if (value==a->abstract0 && env==a->env) res = *a; else { res.abstract0 = value; res.env = env; ap_environment_free(a->env); } } else { res.abstract0 = value; res.env = env; } return res; } void ap_abstract1_raise_invalid_var(ap_manager_t* man, ap_funid_t funid, ap_var_t var) { char msg[160]; char* b = ap_var_operations->to_string(var); snprintf(msg,159,"unknown variable %s in the environment",b); free(b); ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT,funid,msg); } void ap_abstract1_raise_invalid_expr(ap_manager_t* man, ap_funid_t funid) { ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT,funid,"\ Linear/tree expression not defined on a (sub)environment of the abstract value\ "); } bool ap_abstract1_check_env2(ap_funid_t funid, ap_manager_t* man, ap_abstract1_t* a1, ap_abstract1_t* a2) { if (ap_environment_is_eq(a1->env,a2->env)) return true; else { ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, funid, "The two abstract values have different environments"); return false; } } bool ap_abstract1_check_env_array(ap_funid_t funid,ap_manager_t* man, ap_abstract1_t* tab, size_t size) { bool res; if (size==0){ ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, funid,"array of abstract values of size 0"); res = false; } else { size_t i; ap_environment_t* env0 = tab[0].env; for (i=1;ilibrary != tab[i].abstract0->man->library){ char str[160]; snprintf(str,159,"\ The %luth abstract value of the array is of type %s and not of the type %s expected by the manager\ ", (unsigned long)i,tab[i].abstract0->man->library,man->library); ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, funid, str); return false; } } return true; } void ap_box1_fprint(FILE* stream, ap_box1_t* box) { size_t i; fprintf(stream,"Box1: (%lu,%lu)\n", (unsigned long)box->env->intdim,(unsigned long)box->env->realdim); for (i=0; ienv->intdim+box->env->realdim;i++){ ap_var_t var = ap_environment_var_of_dim(box->env,i); char* name = ap_var_operations->to_string(var); fprintf(stream," %s\tin",name); free(name); ap_interval_fprint(stream,box->p[i]); fprintf(stream,"\n"); } } void ap_box1_clear(ap_box1_t* box) { if (box->env==NULL){ fprintf(stderr,"abstract1.c: box_clear: either non initialized or already deallocated box !\n"); abort(); } ap_interval_array_free(box->p,box->env->intdim+box->env->realdim); ap_environment_free(box->env); box->p=NULL; box->env=NULL; } /* ********************************************************************** */ /* I. General management */ /* ********************************************************************** */ /* ============================================================ */ /* I.1 Memory */ /* ============================================================ */ /* Return a copy of an abstract value, on which destructive update does not affect the initial value. */ ap_abstract1_t ap_abstract1_copy(ap_manager_t* man, ap_abstract1_t* a){ return ap_abstract1_cons(ap_abstract0_copy(man,a->abstract0),a->env); } /* Free all the memory used by the abstract value */ void ap_abstract1_clear(ap_manager_t* man, ap_abstract1_t* a) { ap_abstract0_free(man,a->abstract0); ap_environment_free(a->env); a->abstract0 = NULL; a->env = NULL; } /* Return the abstract size of an abstract value (see ap_manager_t) */ size_t ap_abstract1_size(ap_manager_t* man, ap_abstract1_t* a){ return ap_abstract0_size(man,a->abstract0); } /* ============================================================ */ /* I.2 Control of internal representation */ /* ============================================================ */ /* Minimize the size of the representation of a. This may result in a later recomputation of internal information. */ void ap_abstract1_minimize(ap_manager_t* man, ap_abstract1_t* a){ ap_abstract0_minimize(man,a->abstract0); } /* Put the abstract value in canonical form. (not yet clear definition) */ void ap_abstract1_canonicalize(ap_manager_t* man, ap_abstract1_t* a){ ap_abstract0_canonicalize(man,a->abstract0); } /* Return an hash code */ int ap_abstract1_hash(ap_manager_t* man, ap_abstract1_t* a) { return (ap_environment_hash(a->env)*251 + ap_abstract0_hash(man,a->abstract0)*19); } /* Perform some transformation on the abstract value, guided by the field algorithm. The transformation may lose information. The argument "algorithm" overrides the field algorithm of the structure of type foption_t associated to ap_abstract1_approximate (commodity feature). */ void ap_abstract1_approximate(ap_manager_t* man, ap_abstract1_t* a, int algorithm){ ap_abstract0_approximate(man,a->abstract0, algorithm); } /* ============================================================ */ /* I.3 Printing */ /* ============================================================ */ /* Print the abstract value */ void ap_abstract1_fprint(FILE* stream, ap_manager_t* man, ap_abstract1_t* a) { ap_environment_name_of_dim_t* name_of_dim; name_of_dim = ap_environment_name_of_dim_alloc(a->env); ap_abstract0_fprint(stream,man, a->abstract0, name_of_dim->p); ap_environment_name_of_dim_free(name_of_dim); } /* Print the difference between a1 (old value) and a2 (new value), using function name_of_dim to name dimensions. The meaning of difference is library dependent. */ void ap_abstract1_fprintdiff(FILE* stream, ap_manager_t* man, ap_abstract1_t* a1, ap_abstract1_t* a2) { ap_environment_name_of_dim_t* name_of_dim; if (!ap_environment_is_eq(a1->env,a2->env)){ ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT,AP_FUNID_FPRINTDIFF, "the 2 abstract values are not defined on the same environement"); fprintf(stream,"unknown diff\n"); } name_of_dim = ap_environment_name_of_dim_alloc(a1->env); ap_abstract0_fprintdiff(stream,man,a1->abstract0, a2->abstract0, name_of_dim->p); ap_environment_name_of_dim_free(name_of_dim); } /* Dump the internal representation of an abstract value, for debugging purposes */ void ap_abstract1_fdump(FILE* stream, ap_manager_t* man, ap_abstract1_t* a) { fprintf(stream, "abstract value of level 1:\n"); ap_environment_fdump(stream,a->env); ap_abstract0_fdump(stream,man,a->abstract0); } /* ============================================================ */ /* I.4 Serialization */ /* ============================================================ */ /* DOIT-ON SÉRIALISER L'ENVIRONNEMENT ? */ /* Allocate a memory buffer (with malloc), output the abstract value in raw binary format to it and return a pointer on the memory buffer and the size of bytes written. It is the user responsability to free the memory afterwards (with free). */ ap_membuf_t ap_abstract1_serialize_raw(ap_manager_t* man, ap_abstract1_t* a){ ap_membuf_t membuf; ap_manager_raise_exception(man,AP_EXC_NOT_IMPLEMENTED,AP_FUNID_SERIALIZE_RAW,""); membuf.ptr = NULL; membuf.size = 0; return membuf; } /* Return the abstract value read in raw binary format from the input stream and store in size the number of bytes read */ ap_abstract1_t ap_abstract1_deserialize_raw(ap_manager_t* man, void* ptr, size_t* size){ ap_manager_raise_exception(man,AP_EXC_NOT_IMPLEMENTED,AP_FUNID_DESERIALIZE_RAW,""); return ap_abstract1_top(man,ap_environment_alloc_empty()); } /* ********************************************************************** */ /* II. Constructor, accessors, tests and property extraction */ /* ********************************************************************** */ /* ============================================================ */ /* II.1 Basic constructors */ /* ============================================================ */ /* Create a bottom (empty) value */ ap_abstract1_t ap_abstract1_bottom(ap_manager_t* man, ap_environment_t* env) { return ap_abstract1_cons(ap_abstract0_bottom(man,env->intdim,env->realdim),env); } /* Create a top (universe) value */ ap_abstract1_t ap_abstract1_top(ap_manager_t* man, ap_environment_t* env) { return ap_abstract1_cons(ap_abstract0_top(man,env->intdim,env->realdim),env); } /* Abstract an hypercube defined by the arrays tvar and tinterval, satisfying: forall i, tvar[i] in tinterval[i]. If no inclusion is specified for a variable in the environement, its value is no constrained in the resulting abstract value. */ ap_abstract1_t ap_abstract1_of_box(ap_manager_t* man, ap_environment_t* env, ap_var_t* tvar, ap_interval_t** tinterval, size_t size) { ap_abstract1_t a; size_t i; ap_interval_t** itv = ap_interval_array_alloc(env->intdim+env->realdim); for (i=0; iintdim+env->realdim; i++){ ap_interval_set_top(itv[i]); } for (i=0; iintdim,env->realdim,(ap_interval_t**)itv),env); ap_interval_array_free(itv,env->intdim+env->realdim); return a; } /* ============================================================ */ /* II.2 Accessors */ /* ============================================================ */ ap_environment_t* ap_abstract1_environment(ap_manager_t* man, ap_abstract1_t* a){ return a->env; } ap_abstract0_t* ap_abstract1_abstract0(ap_manager_t* man, ap_abstract1_t* a){ return a->abstract0; } /* ============================================================ */ /* II.3 Tests */ /* ============================================================ */ bool ap_abstract1_is_bottom(ap_manager_t* man, ap_abstract1_t* a){ return ap_abstract0_is_bottom(man,a->abstract0); } bool ap_abstract1_is_top(ap_manager_t* man, ap_abstract1_t* a){ return ap_abstract0_is_top(man,a->abstract0); } /* inclusion check */ bool ap_abstract1_is_leq(ap_manager_t* man, ap_abstract1_t* a1, ap_abstract1_t* a2) { if (ap_abstract1_check_env2(AP_FUNID_IS_LEQ,man,a1,a2)) return ap_abstract0_is_leq(man,a1->abstract0,a2->abstract0); else { man->result.flag_exact = false; return false; } } /* equality check */ bool ap_abstract1_is_eq(ap_manager_t* man, ap_abstract1_t* a1, ap_abstract1_t* a2) { if (ap_abstract1_check_env2(AP_FUNID_IS_EQ,man,a1,a2)) return ap_abstract0_is_eq(man,a1->abstract0,a2->abstract0); else { man->result.flag_exact = false; return false; } } /* does the abstract value satisfy the linear constraint ? */ bool ap_abstract1_sat_lincons(ap_manager_t* man, ap_abstract1_t* a, ap_lincons1_t* cons) { bool res; if (ap_environment_is_eq(a->env,cons->env)){ res = ap_abstract0_sat_lincons(man,a->abstract0,&cons->lincons0); } else { ap_dimchange_t* dimchange; ap_lincons0_t cons0; dimchange = ap_environment_dimchange(cons->env,a->env); if (dimchange==NULL){ ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT,AP_FUNID_SAT_LINCONS, "the environment of the constraint is not a subset of the environment of the abstract value"); man->result.flag_exact = false; return false; } cons0 = ap_lincons0_add_dimensions(&cons->lincons0,dimchange); res = ap_abstract0_sat_lincons(man,a->abstract0,&cons0); ap_dimchange_free(dimchange); ap_lincons0_clear(&cons0); } return res; } /* does the abstract value satisfy the tree expression constraint ? */ bool ap_abstract1_sat_tcons(ap_manager_t* man, ap_abstract1_t* a, ap_tcons1_t* cons) { bool res; if (ap_environment_is_eq(a->env,cons->env)){ res = ap_abstract0_sat_tcons(man,a->abstract0,&cons->tcons0); } else { ap_dimchange_t* dimchange; ap_tcons0_t cons0; dimchange = ap_environment_dimchange(cons->env,a->env); if (dimchange==NULL){ ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT,AP_FUNID_SAT_TCONS, "the environment of the constraint is not a subset of the environment of the abstract value"); man->result.flag_exact = false; return false; } cons0 = ap_tcons0_add_dimensions(&cons->tcons0,dimchange); res = ap_abstract0_sat_tcons(man,a->abstract0,&cons0); ap_dimchange_free(dimchange); ap_tcons0_clear(&cons0); } return res; } /* Is the dimension included in the interval in the abstract value ? */ bool ap_abstract1_sat_interval(ap_manager_t* man, ap_abstract1_t* a, ap_var_t var, ap_interval_t* interval) { ap_dim_t dim; bool res; dim = ap_environment_dim_of_var(a->env, var); if (dim==AP_DIM_MAX){ ap_abstract1_raise_invalid_var(man,AP_FUNID_SAT_INTERVAL,var); man->result.flag_exact = false; return false; } return ap_abstract0_sat_interval(man, a->abstract0, dim, interval); } /* Is the dimension included in the interval in the abstract value ? */ bool ap_abstract1_is_variable_unconstrained(ap_manager_t* man, ap_abstract1_t* a, ap_var_t var) { ap_dim_t dim; bool res; dim = ap_environment_dim_of_var(a->env, var); if (dim==AP_DIM_MAX){ ap_abstract1_raise_invalid_var(man,AP_FUNID_IS_DIMENSION_UNCONSTRAINED,var); man->result.flag_exact = false; return false; } return ap_abstract0_is_dimension_unconstrained(man, a->abstract0, dim); } /* ============================================================ */ /* II.4 Extraction of properties */ /* ============================================================ */ /* Returns the interval taken by a linear expression over the abstract value */ ap_interval_t* ap_abstract1_bound_linexpr(ap_manager_t* man, ap_abstract1_t* a, ap_linexpr1_t* expr) { ap_interval_t* res; if (ap_environment_is_eq(a->env,expr->env)){ res = ap_abstract0_bound_linexpr(man,a->abstract0,expr->linexpr0); } else { ap_dimchange_t* dimchange; ap_linexpr0_t* expr0; dimchange = ap_environment_dimchange(expr->env,a->env); if (dimchange==NULL){ ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT,AP_FUNID_BOUND_LINEXPR, "the environment of the linear expression is not a subset of the environment of the abstract value"); res = ap_interval_alloc(); ap_interval_reinit(res,man->option.scalar_discr); ap_interval_set_top(res); return res; } expr0 = ap_linexpr0_add_dimensions(expr->linexpr0,dimchange); res = ap_abstract0_bound_linexpr(man,a->abstract0,expr0); ap_dimchange_free(dimchange); ap_linexpr0_free(expr0); } return res; } /* Returns the interval taken by a tree expression over the abstract value */ ap_interval_t* ap_abstract1_bound_texpr(ap_manager_t* man, ap_abstract1_t* a, ap_texpr1_t* expr) { ap_interval_t* res; if (ap_environment_is_eq(a->env,expr->env)){ res = ap_abstract0_bound_texpr(man,a->abstract0,expr->texpr0); } else { ap_dimchange_t* dimchange; ap_texpr0_t* expr0; dimchange = ap_environment_dimchange(expr->env,a->env); if (dimchange==NULL){ ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT,AP_FUNID_BOUND_TEXPR, "the environment of the tear expression is not a subset of the environment of the abstract value"); res = ap_interval_alloc(); ap_interval_reinit(res,man->option.scalar_discr); ap_interval_set_top(res); return res; } expr0 = ap_texpr0_add_dimensions(expr->texpr0,dimchange); res = ap_abstract0_bound_texpr(man,a->abstract0,expr0); ap_dimchange_free(dimchange); ap_texpr0_free(expr0); } return res; } /* Returns the interval taken by the variable over the abstract value */ ap_interval_t* ap_abstract1_bound_variable(ap_manager_t* man, ap_abstract1_t* a, ap_var_t var) { ap_dim_t dim; ap_interval_t* res; dim = ap_environment_dim_of_var(a->env, var); if (dim==AP_DIM_MAX){ ap_abstract1_raise_invalid_var(man,AP_FUNID_BOUND_DIMENSION,var); res = ap_interval_alloc(); ap_interval_reinit(res,man->option.scalar_discr); ap_interval_set_top(res); return res; } return ap_abstract0_bound_dimension(man, a->abstract0, dim); } /* Converts an abstract value to a polyhedra (conjunction of linear constraints). */ ap_lincons1_array_t ap_abstract1_to_lincons_array(ap_manager_t* man, ap_abstract1_t* a) { ap_lincons1_array_t array; array.lincons0_array = ap_abstract0_to_lincons_array(man,a->abstract0); array.env = ap_environment_copy(a->env); return array; } /* Converts an abstract value to a conjunction of tree expressions constraints. */ ap_tcons1_array_t ap_abstract1_to_tcons_array(ap_manager_t* man, ap_abstract1_t* a) { ap_tcons1_array_t array; array.tcons0_array = ap_abstract0_to_tcons_array(man,a->abstract0); array.env = ap_environment_copy(a->env); return array; } /* Converts an abstract value to an interval/hypercube. The size of the resulting array is ap_abstract1_dimension(man,a). This function can be reimplemented by using ap_abstract1_bound_linexpr */ ap_box1_t ap_abstract1_to_box(ap_manager_t* man, ap_abstract1_t* a) { ap_box1_t box; box.p = ap_abstract0_to_box(man,a->abstract0); box.env = ap_environment_copy(a->env); return box; } /* Converts an abstract value to a system of generators. */ ap_generator1_array_t ap_abstract1_to_generator_array(ap_manager_t* man, ap_abstract1_t* a) { ap_generator1_array_t array; array.generator0_array = ap_abstract0_to_generator_array(man,a->abstract0); array.env = ap_environment_copy(a->env); return array; } /* ********************************************************************** */ /* III. Operations: functional version */ /* ********************************************************************** */ /* ============================================================ */ /* III.1 Meet and Join */ /* ============================================================ */ ap_abstract1_t ap_abstract1_meetjoin(ap_funid_t funid, ap_manager_t* man, bool destructive, ap_abstract1_t* a1, ap_abstract1_t* a2) { ap_abstract1_t res; if (ap_abstract1_check_env2(funid,man,a1,a2)){ ap_abstract0_t* value = ap_abstract0_meetjoin(funid,man,destructive,a1->abstract0,a2->abstract0); res = ap_abstract1_consres(destructive, a1, value); } else { res = ap_abstract1_top(man,a1->env); if (destructive) ap_abstract1_clear(man,a1); } return res; } ap_abstract1_t ap_abstract1_meet(ap_manager_t* man, bool destructive, ap_abstract1_t* a1, ap_abstract1_t* a2){ return ap_abstract1_meetjoin(AP_FUNID_MEET,man,destructive,a1,a2); } ap_abstract1_t ap_abstract1_join(ap_manager_t* man, bool destructive, ap_abstract1_t* a1, ap_abstract1_t* a2){ return ap_abstract1_meetjoin(AP_FUNID_JOIN,man,destructive,a1,a2); } ap_abstract1_t ap_abstract1_meetjoin_array(ap_funid_t funid, ap_manager_t* man, ap_abstract1_t* tab, size_t size) { ap_abstract1_t res; if (ap_abstract1_checkman_array(funid,man,tab,size) && ap_abstract1_check_env_array(funid,man,tab,size)){ size_t i; ap_abstract0_t* res0; void* (*ptr)(ap_manager_t*,...) = man->funptr[funid]; void** ntab = malloc(size*sizeof(void*)); for (i=0;ivalue; res0 = malloc(sizeof(ap_abstract0_t)); res0->man = ap_manager_copy(man); res0->value = ptr(man,ntab,size); res.abstract0 = res0; res.env = ap_environment_copy(tab[0].env); free(ntab); } else { res = ap_abstract1_top(man, size==0 ? ap_environment_alloc_empty() : tab[0].env); } return res; } ap_abstract1_t ap_abstract1_meet_array(ap_manager_t* man, ap_abstract1_t* tab, size_t size){ return ap_abstract1_meetjoin_array(AP_FUNID_MEET_ARRAY,man,tab,size); } ap_abstract1_t ap_abstract1_join_array(ap_manager_t* man, ap_abstract1_t* tab, size_t size){ return ap_abstract1_meetjoin_array(AP_FUNID_JOIN_ARRAY,man,tab,size); } ap_abstract1_t ap_abstract1_meet_lincons_array(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_lincons1_array_t* array) { ap_abstract1_t res; ap_lincons0_array_t array0; ap_dimchange_t* dimchange; if (ap_environment_is_eq(a->env,array->env)){ dimchange = NULL; array0 = array->lincons0_array; } else { dimchange = ap_environment_dimchange(array->env,a->env); if (dimchange==NULL){ ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, AP_FUNID_MEET_LINCONS_ARRAY, "environment of array of constraints is not a subset of the environment of the abstract value"); res = destructive ? *a : ap_abstract1_copy(man,a); return res; } array0 = ap_lincons0_array_add_dimensions(&array->lincons0_array,dimchange); } ap_abstract0_t* value = ap_abstract0_meet_lincons_array(man,destructive,a->abstract0,&array0); if (dimchange){ ap_dimchange_free(dimchange); ap_lincons0_array_clear(&array0); } res = ap_abstract1_consres(destructive, a, value); return res; } ap_abstract1_t ap_abstract1_meet_tcons_array(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_tcons1_array_t* array) { ap_abstract1_t res; ap_tcons0_array_t array0; ap_dimchange_t* dimchange; if (ap_environment_is_eq(a->env,array->env)){ dimchange = NULL; array0 = array->tcons0_array; } else { dimchange = ap_environment_dimchange(array->env,a->env); if (dimchange==NULL){ ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, AP_FUNID_MEET_TCONS_ARRAY, "environment of array of constraints is not a subset of the environment of the abstract value"); res = destructive ? *a : ap_abstract1_copy(man,a); return res; } array0 = ap_tcons0_array_add_dimensions(&array->tcons0_array,dimchange); } ap_abstract0_t* value = ap_abstract0_meet_tcons_array(man,destructive,a->abstract0,&array0); if (dimchange){ ap_dimchange_free(dimchange); ap_tcons0_array_clear(&array0); } res = ap_abstract1_consres(destructive, a, value); return res; } ap_abstract1_t ap_abstract1_add_ray_array(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_generator1_array_t* array) { ap_abstract1_t res; ap_generator0_array_t array0; ap_dimchange_t* dimchange; if (ap_environment_is_eq(a->env,array->env)){ dimchange = NULL; array0 = array->generator0_array; } else { dimchange = ap_environment_dimchange(array->env,a->env); if (dimchange==NULL){ ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, AP_FUNID_ADD_RAY_ARRAY, "environment of array of generators is not a subset of the environment of the abstract value"); res = ap_abstract1_top(man,a->env); if (destructive) ap_abstract1_clear(man,a); return res; } array0 = ap_generator0_array_add_dimensions(&array->generator0_array,dimchange); } ap_abstract0_t* value = ap_abstract0_add_ray_array(man,destructive,a->abstract0,&array0); if (dimchange){ ap_dimchange_free(dimchange); ap_generator0_array_clear(&array0); } res = ap_abstract1_consres(destructive, a, value); return res; } /* ============================================================ */ /* III.2 Assignment and Substitutions */ /* ============================================================ */ ap_abstract1_t ap_abstract1_asssub_linexpr_array(ap_funid_t funid, ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t* tvar, ap_linexpr1_t* linexpr, size_t size, ap_abstract1_t* dest) { if (size==0){ if (dest){ return ap_abstract1_meet(man,destructive,a,dest); } else if (destructive){ return *a; } else { return ap_abstract1_copy(man,a); } } else { ap_dim_t* tdim; ap_linexpr0_t** tlinexpr0; ap_abstract1_t res; ap_dimchange_t* dimchange; size_t i; i = 0; tdim = NULL; tlinexpr0 = NULL; if ( dest==NULL || ap_abstract1_check_env2(funid,man,a,dest)){ tdim = malloc(size*sizeof(ap_dim_t)); tlinexpr0 = malloc(size*sizeof(ap_linexpr0_t*)); for (i=0; ienv,tvar[i]); if (tdim[i]==AP_DIM_MAX){ ap_abstract1_raise_invalid_var(man,funid,tvar[i]); goto ap_abstract1_asssub_linexpr_array_exit; } if (ap_environment_is_eq(a->env,linexpr[i].env)){ dimchange = NULL; tlinexpr0[i] = linexpr[i].linexpr0; } else { dimchange = ap_environment_dimchange(linexpr[i].env,a->env); if (dimchange==NULL){ ap_abstract1_raise_invalid_expr(man,funid); goto ap_abstract1_asssub_linexpr_array_exit; } tlinexpr0[i] = ap_linexpr0_add_dimensions(linexpr[i].linexpr0,dimchange); ap_dimchange_free(dimchange); } } ap_abstract0_t* value = ap_abstract0_asssub_linexpr_array(funid,man, destructive,a->abstract0, tdim, tlinexpr0, size, (dest!=NULL) ? dest->abstract0 : NULL); res = ap_abstract1_consres(destructive, a, value); } else { ap_abstract1_asssub_linexpr_array_exit: res = ap_abstract1_top(man,a->env); if (destructive) ap_abstract1_clear(man,a); } if (tlinexpr0!=NULL){ size_t j; for (j=0; jenv,tvar[i]); if (tdim[i]==AP_DIM_MAX){ ap_abstract1_raise_invalid_var(man,funid,tvar[i]); goto ap_abstract1_asssub_texpr_array_exit; } if (ap_environment_is_eq(a->env,texpr[i].env)){ dimchange = NULL; ttexpr0[i] = texpr[i].texpr0; } else { dimchange = ap_environment_dimchange(texpr[i].env,a->env); if (dimchange==NULL){ ap_abstract1_raise_invalid_expr(man,funid); goto ap_abstract1_asssub_texpr_array_exit; } ttexpr0[i] = ap_texpr0_add_dimensions(texpr[i].texpr0,dimchange); ap_dimchange_free(dimchange); } } ap_abstract0_t* value = ap_abstract0_asssub_texpr_array(funid,man, destructive,a->abstract0, tdim, ttexpr0, size, (dest!=NULL) ? dest->abstract0 : NULL); res = ap_abstract1_consres(destructive, a, value); } else { ap_abstract1_asssub_texpr_array_exit: res = ap_abstract1_top(man,a->env); if (destructive) ap_abstract1_clear(man,a); } if (ttexpr0!=NULL){ size_t j; for (j=0; jenv,tvar[i]); if (tdim[i]==AP_DIM_MAX){ ap_abstract1_raise_invalid_var(man,AP_FUNID_FORGET_ARRAY,tvar[i]); res = ap_abstract1_top(man,a->env); if (destructive) ap_abstract1_clear(man,a); goto ap_abstract1_forget_array_exit; } } ap_abstract0_t* value = ap_abstract0_forget_array(man,destructive,a->abstract0,tdim,size,project); res = ap_abstract1_consres(destructive, a, value); ap_abstract1_forget_array_exit: free(tdim); return res; } /* ============================================================ */ /* III.4 Change of environnement */ /* ============================================================ */ ap_abstract1_t ap_abstract1_change_environment(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_environment_t* nenv, bool project) { ap_abstract1_t res; ap_dimchange2_t* dimchange2; ap_abstract0_t* value; dimchange2 = ap_environment_dimchange2(a->env,nenv); if (dimchange2==NULL){ ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT, AP_FUNID_CHANGE_ENVIRONMENT, "the abstract value and the new environment are incompatible"); res = ap_abstract1_top(man,nenv); if (destructive) ap_abstract1_clear(man,a); return res; } value = ap_abstract0_apply_dimchange2(man,destructive,a->abstract0,dimchange2,project); ap_dimchange2_free(dimchange2); res = ap_abstract1_consres2(destructive, a, value, ap_environment_copy(nenv)); return res; } ap_abstract1_t ap_abstract1_minimize_environment(ap_manager_t* man, bool destructive, ap_abstract1_t* a) { ap_abstract1_t res; ap_environment_t* env; ap_var_t* tvar; ap_dimension_t dim; size_t i,size,nbdims; ap_var_t var; dim = ap_abstract0_dimension(man,a->abstract0); size = dim.intdim+dim.realdim; tvar = malloc(size*sizeof(ap_var_t)); nbdims = 0; for (i=0; iabstract0,i); if (b){ var = ap_environment_var_of_dim(a->env,i); tvar[nbdims] = var; nbdims++; } } if (nbdims==0){ /* No change */ res = destructive ? *a : ap_abstract1_copy(man,a); } else { env = ap_environment_remove(a->env,tvar,nbdims); if (env==NULL){ fprintf(stderr,"ap_abstract1.c: ap_abstract1_minimize_environment: internal error\n"); abort(); } res = ap_abstract1_change_environment(man,destructive,a,env,false); ap_environment_free(env); } free(tvar); return res; } ap_abstract1_t ap_abstract1_rename_array(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t* tvar1, ap_var_t* tvar2, size_t size) { ap_abstract1_t res; ap_dimperm_t perm; ap_environment_t* env; ap_abstract0_t* value; env = ap_environment_rename(a->env,tvar1,tvar2,size,&perm); if (env==NULL){ ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, AP_FUNID_RENAME_ARRAY, "renaming specification invalid"); res = ap_abstract1_top(man,a->env); if (destructive) ap_abstract1_clear(man,a); } else { value = ap_abstract0_permute_dimensions(man,destructive,a->abstract0,&perm); res = ap_abstract1_consres2(destructive, a, value, env); ap_dimperm_clear(&perm); } return res; } /* ============================================================ */ /* III.5 Expansion and folding of dimensions */ /* ============================================================ */ ap_abstract1_t ap_abstract1_expand(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t var, ap_var_t* tvar, size_t size) { ap_dim_t dim; ap_dimperm_t perm; ap_environment_t* nenv; ap_abstract0_t* value; ap_abstract1_t res; /* particular case */ if (size==0){ res = destructive ? *a : ap_abstract1_copy(man,a); return res; } /* Getting the dimension to expand */ dim = ap_environment_dim_of_var(a->env, var); if (dim==AP_DIM_MAX){ ap_abstract1_raise_invalid_var(man,AP_FUNID_EXPAND,var); ap_abstract1_expand_exit: res = ap_abstract1_top(man,a->env); if (destructive) ap_abstract1_clear(man,a); return res; } /* Doing the expansion at level 0 */ value = ap_abstract0_expand(man,destructive,a->abstract0,dim,size); /* Building the resulting environment and permutation to apply */ nenv = (dimenv->intdim) ? ap_environment_add_perm(a->env, tvar, size, NULL,0, &perm) : ap_environment_add_perm(a->env, NULL,0, tvar, size, &perm); if (nenv==NULL){ ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT, AP_FUNID_EXPAND, "some new variables resulting from the expansion already exist in current environment"); goto ap_abstract1_expand_exit; } /* Apply permutation and return */ value = ap_abstract0_permute_dimensions(man,true,value,&perm); ap_dimperm_clear(&perm); res = ap_abstract1_consres2(destructive, a, value,nenv); return res; } static int compar_dim(const void* a, const void* b) { int va = *((ap_dim_t*)a); int vb = *((ap_dim_t*)b); return (va-vb); } ap_abstract1_t ap_abstract1_fold(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t* tvar, size_t size) { ap_abstract1_t res; ap_dim_t* tdim; ap_environment_t* nenv; size_t i; ap_dim_t dim; ap_abstract0_t* value; ap_dimperm_t perm; if (size==0){ ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT,AP_FUNID_FOLD, "array of variables to fold of size 0"); ap_abstract1_fold_exit: res = ap_abstract1_top(man,a->env); if (destructive) ap_abstract1_clear(man,a); return res; } else if (size==1){ res = destructive ? *a : ap_abstract1_copy(man,a); return res; } /* Compute resulting environment */ dim = ap_environment_dim_of_var(a->env,tvar[0]); if (dim==AP_DIM_MAX){ ap_abstract1_raise_invalid_var(man,AP_FUNID_FOLD,tvar[0]); goto ap_abstract1_fold_exit; } nenv = ap_environment_remove(a->env, &tvar[1], size-1); if (nenv==NULL){ ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT,AP_FUNID_FOLD, "some variables to fold are unkown in the environment"); goto ap_abstract1_fold_exit; } /* Translate variables to dimensions */ tdim = malloc(size*sizeof(ap_dim_t)); tdim[0] = dim; for (i=1; ienv, tvar[i]); if (tdim[i]==AP_DIM_MAX){ ap_abstract1_raise_invalid_var(man,AP_FUNID_FOLD,tvar[i]); free(tdim); goto ap_abstract1_fold_exit; } } /* Sort the array of dimensions */ qsort(tdim,size,sizeof(ap_dim_t),compar_dim); /* Compute the permutation for "exchanging" dim and tdim[0] if necessary */ if (dim!=tdim[0]){ size_t rank; /* We have the following situation Initially: env: A B C D E F G dim: 0 1 2 3 4 5 6 gen: a b c d e f g We fold with F,B,D, translated to [5,1,3] and reordered to [1,3,5] env: A C E F G dim: 0 1 2 3 4 gen: a b c e g a d c e g a f c e g We need now to apply the permutation rank: 0 1 2 3 4 perm: 0 2 3 1 4 var: Y Z Q dim: 0 1 2 gen: b a e b c e b d e So we have to perform a to the right between dim[0] and dim-(rank of dim in tdim) */ /* look for the position of dim in tdim array */ void* p = bsearch(&dim,&tdim[1],size-1,sizeof(ap_dim_t),compar_dim); assert(p>=(void*)(&tdim[1])); size_t index = (p-(void*)tdim)/sizeof(ap_dim_t); /* compute permutation */ ap_dimperm_init(&perm, nenv->intdim+nenv->realdim); ap_dimperm_set_id(&perm); for (rank=tdim[0]; rankabstract0,tdim,size); /* Apply the permutation if necessary */ if (dim!=tdim[0]){ value = ap_abstract0_permute_dimensions(man,true,value,&perm); ap_dimperm_clear(&perm); } free(tdim); res = ap_abstract1_consres2(destructive, a, value, nenv); return res; } /* ============================================================ */ /* III.6 Widening */ /* ============================================================ */ /* Widening */ ap_abstract1_t ap_abstract1_widening(ap_manager_t* man, ap_abstract1_t* a1, ap_abstract1_t* a2) { ap_abstract1_t res; if (ap_abstract1_check_env2(AP_FUNID_WIDENING,man,a1,a2)){ res.abstract0 = ap_abstract0_widening(man,a1->abstract0,a2->abstract0); res.env = ap_environment_copy(a1->env); } else { res = ap_abstract1_top(man,a1->env); } return res; } /* Widening with threshold */ ap_abstract1_t ap_abstract1_widening_threshold(ap_manager_t* man, ap_abstract1_t* a1, ap_abstract1_t* a2, ap_lincons1_array_t* array) { ap_abstract1_t res; ap_lincons0_array_t array0; ap_dimchange_t* dimchange; if (ap_environment_is_eq(a1->env,array->env)){ dimchange=NULL; array0 = array->lincons0_array; } else { dimchange = ap_environment_dimchange(array->env,a1->env); if (dimchange==NULL){ ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, AP_FUNID_MEET_LINCONS_ARRAY, "\ environment of array of constraints is not a subset \ of the environment of the abstract value\ " ); res = ap_abstract1_top(man,a1->env); return res; } array0 = ap_lincons0_array_add_dimensions(&array->lincons0_array,dimchange); } if (ap_abstract1_check_env2(AP_FUNID_WIDENING,man,a1,a2)){ ap_abstract0_t* value = ap_abstract0_widening_threshold(man,a1->abstract0,a2->abstract0,&array0); res = ap_abstract1_cons(value,a1->env); } else { res = ap_abstract1_top(man,a1->env); } if (dimchange){ ap_dimchange_free(dimchange); ap_lincons0_array_clear(&array0); } return res; } /* ============================================================ */ /* III.7 Closure operation */ /* ============================================================ */ ap_abstract1_t ap_abstract1_closure(ap_manager_t* man, bool destructive, ap_abstract1_t* a) { ap_abstract0_t* value; value = ap_abstract0_closure(man,destructive,a->abstract0); return ap_abstract1_consres(destructive, a, value); } /* ============================================================ */ /* IV. Additional functions */ /* ============================================================ */ /* These two function abstract a set of constraints */ ap_abstract1_t ap_abstract1_of_lincons_array(ap_manager_t* man, ap_environment_t* env, ap_lincons1_array_t* array) { ap_abstract1_t res = ap_abstract1_top(man,env); res = ap_abstract1_meet_lincons_array(man,true,&res,array); return res; } ap_abstract1_t ap_abstract1_of_tcons_array(ap_manager_t* man, ap_environment_t* env, ap_tcons1_array_t* array) { ap_abstract1_t res = ap_abstract1_top(man,env); res = ap_abstract1_meet_tcons_array(man,true,&res,array); return res; } /* These four functions implement assignment and substitution of a single dimension by a single expression. */ ap_abstract1_t ap_abstract1_assign_linexpr(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t var, ap_linexpr1_t* expr, ap_abstract1_t* dest){ return ap_abstract1_asssub_linexpr_array(AP_FUNID_ASSIGN_LINEXPR_ARRAY,man,destructive,a,&var,expr,1,dest); } ap_abstract1_t ap_abstract1_substitute_linexpr(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t var, ap_linexpr1_t* expr, ap_abstract1_t* dest){ return ap_abstract1_asssub_linexpr_array(AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY,man,destructive,a,&var,expr,1,dest); } ap_abstract1_t ap_abstract1_assign_texpr(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t var, ap_texpr1_t* expr, ap_abstract1_t* dest){ return ap_abstract1_asssub_texpr_array(AP_FUNID_ASSIGN_TEXPR_ARRAY,man,destructive,a,&var,expr,1,dest); } ap_abstract1_t ap_abstract1_substitute_texpr(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t var, ap_texpr1_t* expr, ap_abstract1_t* dest){ return ap_abstract1_asssub_texpr_array(AP_FUNID_SUBSTITUTE_TEXPR_ARRAY,man,destructive,a,&var,expr,1,dest); } /* Unify two abstract values on their common variables, that is, embed them on the least common environment and then compute their meet. The result is defined on the least common environment. */ ap_abstract1_t ap_abstract1_unify(ap_manager_t* man, bool destructive, ap_abstract1_t* a1,ap_abstract1_t* a2) { ap_dimchange_t* dimchange1; ap_dimchange_t* dimchange2; ap_environment_t* env; ap_abstract0_t* value1; ap_abstract0_t* value2; ap_abstract0_t* value; ap_abstract1_t res; if (ap_environment_is_eq(a1->env,a2->env)){ return ap_abstract1_meet(man,destructive,a1,a2); } env = ap_environment_lce(a1->env,a2->env,&dimchange1,&dimchange2); if (env==NULL){ ap_manager_raise_exception(man,AP_EXC_INVALID_ARGUMENT,AP_FUNID_UNKNOWN, "\ ap_abstract1_unify: a variable is defined with different types \ in the two abstract values"); if (destructive) return *a1; else return ap_abstract1_copy(man,a1); } assert(dimchange1 || dimchange2); value1 = dimchange1 ? ap_abstract0_add_dimensions(man,destructive,a1->abstract0,dimchange1,false) : (destructive ? a1->abstract0 : ap_abstract0_copy(man,a1->abstract0)); ; value2 = dimchange2 ? ap_abstract0_add_dimensions(man,false,a2->abstract0,dimchange2,false) : a2->abstract0; ; value = ap_abstract0_meet(man,true,value1,value2); res = ap_abstract1_consres2(destructive, a1, value, env); if (dimchange1) ap_dimchange_free(dimchange1); if (dimchange2){ ap_dimchange_free(dimchange2); ap_abstract0_free(man,value2); } return res; } /* Evaluate the interval linear expression expr on the abstract value a and approximate it by a quasilinear expression. discr indicates which type of numbers should be used for computations. This implies calls to ap_abstract0_bound_dimension. */ ap_linexpr1_t ap_abstract1_quasilinear_of_intlinear (ap_manager_t* man, ap_abstract1_t* a, ap_linexpr1_t* expr, ap_scalar_discr_t discr) { ap_linexpr0_t* linexpr0; ap_dimchange_t* dimchange; ap_linexpr1_t res; bool exact; if (ap_environment_is_eq(a->env,expr->env)){ dimchange = NULL; linexpr0 = expr->linexpr0; } else { dimchange = ap_environment_dimchange(expr->env,a->env); if (dimchange==NULL){ ap_abstract1_raise_invalid_expr(man,AP_FUNID_UNKNOWN); goto ap_abstract1_quasilinear_of_intlinear_exit; } linexpr0 = ap_linexpr0_add_dimensions(expr->linexpr0,dimchange); } res.linexpr0 = ap_quasilinearize_linexpr0(man,a->abstract0->value,linexpr0,&exact,discr); res.env = ap_environment_copy(a->env); if (dimchange){ ap_dimchange_free(dimchange); ap_linexpr0_free(linexpr0); } return res; ap_abstract1_quasilinear_of_intlinear_exit: res.linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,0); res.env = ap_environment_copy(a->env); ap_coeff_set_interval_top(&res.linexpr0->cst); return res; } /* Evaluate the tree expression expr on the abstract value a and approximate it by an interval linear (resp. quasilinear if quasilinearize is true) expression. discr indicates which type of numbers should be used for computations. This implies calls to ap_abstract0_bound_dimension. */ ap_linexpr1_t ap_abstract1_intlinear_of_tree(ap_manager_t* man, ap_abstract1_t* a, ap_texpr1_t* expr, ap_scalar_discr_t discr, bool quasilinearize) { ap_texpr0_t* texpr0; ap_dimchange_t* dimchange; ap_linexpr1_t res; bool exact; if (ap_environment_is_eq(a->env,expr->env)){ dimchange = NULL; texpr0 = expr->texpr0; } else { dimchange = ap_environment_dimchange(expr->env,a->env); if (dimchange==NULL){ ap_abstract1_raise_invalid_expr(man,AP_FUNID_UNKNOWN); goto ap_abstract1_quasilinear_of_intlinear_exit; } texpr0 = ap_texpr0_add_dimensions(expr->texpr0,dimchange); } res.linexpr0 = ap_intlinearize_texpr0(man,a->abstract0->value,texpr0,&exact,discr,quasilinearize); res.env = ap_environment_copy(a->env); if (dimchange){ ap_dimchange_free(dimchange); ap_texpr0_free(texpr0); } return res; ap_abstract1_quasilinear_of_intlinear_exit: res.linexpr0 = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,0); res.env = ap_environment_copy(a->env); ap_coeff_set_interval_top(&res.linexpr0->cst); return res; } apron-dist-0.9.10/apron/apron/ap_linexpr0.c0000640014525101416610000005362411006063143020374 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_linexpr0.c: linear expressions */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "ap_linexpr0.h" #include /* ====================================================================== */ /* I. Memory management and printing */ /* ====================================================================== */ ap_linexpr0_t* ap_linexpr0_alloc(ap_linexpr_discr_t lin_discr, size_t size) { ap_linexpr0_t* e; size_t i; e = (ap_linexpr0_t*)malloc(sizeof(ap_linexpr0_t)); ap_coeff_init(&e->cst,AP_COEFF_SCALAR); e->discr = lin_discr; e->size = size; switch (lin_discr){ case AP_LINEXPR_DENSE: e->p.coeff = size==0 ? NULL : (ap_coeff_t*)malloc(size*sizeof(ap_coeff_t)); for (i=0; ip.coeff[i],AP_COEFF_SCALAR); break; case AP_LINEXPR_SPARSE: e->p.linterm = size==0 ? NULL : (ap_linterm_t*)malloc(size*sizeof(ap_linterm_t)); for (i=0; ip.linterm[i].coeff,AP_COEFF_SCALAR); e->p.linterm[i].dim = AP_DIM_MAX; } break; } return e; } void ap_linexpr0_realloc(ap_linexpr0_t* e, size_t size) { size_t i; if (e->size==size) return; switch (e->discr){ case AP_LINEXPR_DENSE: for (i=size; isize; i++){ ap_coeff_clear(&e->p.coeff[i]); } if (size==0){ free(e->p.coeff); e->p.coeff = NULL; } else { e->p.coeff = realloc(e->p.coeff,size*sizeof(ap_coeff_t)); for (i=e->size; ip.coeff[i],AP_COEFF_SCALAR); } } break; case AP_LINEXPR_SPARSE: for (i=size; isize; i++){ ap_coeff_clear(&e->p.linterm[i].coeff); } if (size==0){ free(e->p.linterm); e->p.linterm = NULL; } else { e->p.linterm = realloc(e->p.linterm, size*sizeof(ap_linterm_t)); for (i=e->size; ip.linterm[i].coeff,AP_COEFF_SCALAR); e->p.linterm[i].dim = AP_DIM_MAX; } } break; } e->size = size; } void ap_linexpr0_minimize(ap_linexpr0_t* e) { size_t i,j,nsize; if (e->discr==AP_LINEXPR_DENSE){ for (i=0; isize; i++){ ap_coeff_reduce(&e->p.coeff[i]); } } else { nsize = 0; for (i=0; isize; i++){ ap_coeff_t* p = &e->p.linterm[i].coeff; ap_coeff_reduce(p); if (!ap_coeff_zero(p) && e->p.linterm[i].dim!=AP_DIM_MAX) nsize++; } if (nsize!=e->size){ ap_linterm_t* linterm = malloc(nsize*sizeof(ap_linterm_t)); j = 0; for (i=0; isize; i++){ ap_coeff_t* p = &e->p.linterm[i].coeff; if (!ap_coeff_zero(p) && e->p.linterm[i].dim!=AP_DIM_MAX){ linterm[j] = e->p.linterm[i]; j++; } else ap_coeff_clear(p); } free(e->p.linterm); e->p.linterm = linterm; e->size = nsize; } } } ap_linexpr0_t* ap_linexpr0_copy(ap_linexpr0_t* a) { ap_linexpr0_t* e; size_t i; e = (ap_linexpr0_t*)malloc(sizeof(ap_linexpr0_t)); ap_coeff_init_set(&e->cst,&a->cst); e->discr = a->discr; e->size = a->size; switch (a->discr){ case AP_LINEXPR_DENSE: e->p.coeff = a->size==0 ? NULL : (ap_coeff_t*)malloc(a->size*sizeof(ap_coeff_t)); for (i=0; isize; i++) ap_coeff_init_set(&e->p.coeff[i],&a->p.coeff[i]); break; case AP_LINEXPR_SPARSE: e->p.linterm = a->size==0 ? NULL : (ap_linterm_t*)malloc(a->size*sizeof(ap_linterm_t)); for (i=0; isize; i++){ ap_coeff_init_set(&e->p.linterm[i].coeff,&a->p.linterm[i].coeff); e->p.linterm[i].dim = a->p.linterm[i].dim; } break; } e->size = a->size; return e; } static void ap_linexpr0_clear(ap_linexpr0_t* e) { size_t i; if(e!=NULL){ ap_coeff_clear(&e->cst); switch (e->discr){ case AP_LINEXPR_DENSE: if (e->p.coeff!=NULL){ for (i=0; isize; i++) ap_coeff_clear(&e->p.coeff[i]); free(e->p.coeff); } break; case AP_LINEXPR_SPARSE: if (e->p.linterm!=NULL){ for (i=0; isize; i++) ap_coeff_clear(&e->p.linterm[i].coeff); free(e->p.linterm); } break; } } } void ap_linexpr0_free(ap_linexpr0_t* e) { ap_linexpr0_clear(e); free(e); } void ap_linexpr0_fprint(FILE* stream, ap_linexpr0_t* a, char** name_of_dim) { size_t i; ap_scalar_t* pscalar = 0; ap_scalar_t* scalar; ap_coeff_t* coeff; ap_dim_t dim; bool first; int sgn; scalar = ap_scalar_alloc(); first = true; ap_linexpr0_ForeachLinterm(a,i,dim,coeff){ if (! ap_coeff_zero(coeff)){ switch(coeff->discr){ case AP_COEFF_SCALAR: pscalar = coeff->val.scalar; sgn = ap_scalar_sgn(pscalar); if (sgn > 0){ ap_scalar_set(scalar,pscalar); if (!first) fprintf(stream," + "); } else { ap_scalar_neg(scalar,pscalar); fprintf(stream, first ? "-" : " - "); } if (!ap_scalar_equal_int(scalar,1)) ap_scalar_fprint(stream,scalar); break; case AP_COEFF_INTERVAL: if (!first) fprintf(stream," + "); ap_interval_fprint(stream,coeff->val.interval); break; } if (name_of_dim) fprintf(stream,"%s",name_of_dim[dim]); else fprintf(stream,"x%lu",(unsigned long)dim); first = false; } } /* Constant */ if (first || !ap_coeff_zero(&a->cst)){ switch (a->cst.discr){ case AP_COEFF_SCALAR: pscalar = a->cst.val.scalar; sgn = ap_scalar_sgn(pscalar); if (sgn >= 0){ ap_scalar_set(scalar,pscalar); if (!first) fprintf(stream," + "); } else { ap_scalar_neg(scalar,pscalar); fprintf(stream, first ? "-" : " - "); } ap_scalar_fprint(stream,scalar); break; case AP_COEFF_INTERVAL: if (!first) fprintf(stream," + "); ap_interval_fprint(stream, a->cst.val.interval); break; } } ap_scalar_free(scalar); } /* ====================================================================== */ /* II. Tests */ /* ====================================================================== */ /* Does the linear expression involve only real variables ? */ bool ap_linexpr0_is_real(ap_linexpr0_t* a, size_t intdim) { ap_coeff_t* coeff; ap_dim_t dim; size_t i; ap_linexpr0_ForeachLinterm(a,i,dim,coeff){ if (dim>=intdim) return true; if (! ap_coeff_zero(coeff)) return false; } return true; } /* Does the linear expression involve only integer variables ? */ bool ap_linexpr0_is_integer(ap_linexpr0_t* a, size_t intdim) { size_t i; ap_coeff_t* coeff; ap_dim_t dim; switch (a->discr){ case AP_LINEXPR_DENSE: for (dim=intdim; dimsize; dim++){ if (! ap_coeff_zero(&a->p.coeff[dim])) return false; } break; case AP_LINEXPR_SPARSE: ap_linexpr0_ForeachLinterm(a,i,dim,coeff){ if (dim>=intdim && ! ap_coeff_zero(coeff)) return false; } break; default: abort(); } return true; } /* Return the rtype of an expression */ ap_linexpr_type_t ap_linexpr0_type(ap_linexpr0_t* expr) { size_t i; ap_dim_t dim; ap_coeff_t* coeff; ap_linexpr_type_t res = AP_LINEXPR_LINEAR; ap_linexpr0_ForeachLinterm(expr,i,dim,coeff){ if (coeff->discr!=AP_COEFF_SCALAR){ res = AP_LINEXPR_INTLINEAR; break; } } if (res==AP_LINEXPR_LINEAR && expr->cst.discr!=AP_COEFF_SCALAR){ res = AP_LINEXPR_QUASILINEAR; } return res; } /* Return true iff all involved coefficients are scalars */ bool ap_linexpr0_is_linear(ap_linexpr0_t* expr) { size_t i; ap_dim_t dim; ap_coeff_t* coeff; bool res; res = (expr->cst.discr==AP_COEFF_SCALAR); if (res){ ap_linexpr0_ForeachLinterm(expr,i,dim,coeff){ res = (coeff->discr==AP_COEFF_SCALAR); if (!res) break; } } return res; } /* Return true iff all involved coefficients but the constant are scalars */ bool ap_linexpr0_is_quasilinear(ap_linexpr0_t* expr) { size_t i; ap_dim_t dim; ap_coeff_t* coeff; bool res; res = true; ap_linexpr0_ForeachLinterm(expr,i,dim,coeff){ res = (coeff->discr==AP_COEFF_SCALAR); if (!res) break; } return res; } ap_linexpr_type_t ap_linexpr0_array_type(ap_linexpr0_t** texpr, size_t size) { size_t i; ap_linexpr_type_t res = AP_LINEXPR_LINEAR; for (i=0; idiscr){ case AP_LINEXPR_DENSE: return (dimsize) ? &expr->p.coeff[dim] : NULL; case AP_LINEXPR_SPARSE: if (dim==AP_DIM_MAX) return NULL; index = index_of_or_after_dim(dim,expr->p.linterm,expr->size); if (index>=expr->size || dim!=expr->p.linterm[index].dim){ if (indexsize && expr->p.linterm[index].dim==AP_DIM_MAX){ /* We have a free linterm at the right place */ expr->p.linterm[index].dim=dim; return &expr->p.linterm[index].coeff; } if (expr->size==0 || expr->p.linterm[expr->size-1].dim!=AP_DIM_MAX){ /* We have to insert a new linterm at the end */ ap_linexpr0_realloc(expr, expr->size+1); } /* We insert a linterm with AP_DIM_MAX at the right place */ if (indexsize-1){ ap_linterm_t tmp = expr->p.linterm[expr->size-1]; memmove(&expr->p.linterm[index+1], &expr->p.linterm[index], (expr->size-index-1)*sizeof(ap_linterm_t)); expr->p.linterm[index] = tmp; } expr->p.linterm[index].dim = dim; } return &expr->p.linterm[index].coeff; default: abort(); } } /* If dense representation, coefficients should be already present, otherwise undefined behaviour */ bool ap_linexpr0_get_coeff(ap_coeff_t* coeff, ap_linexpr0_t* expr, ap_dim_t dim) { size_t index; switch(expr->discr){ case AP_LINEXPR_DENSE: if (dimsize){ ap_coeff_set(coeff,&expr->p.coeff[dim]); return false; } else { return true; } case AP_LINEXPR_SPARSE: if (dim==AP_DIM_MAX) return true; else { index = index_of_or_after_dim(dim,expr->p.linterm,expr->size); if (indexsize && dim==expr->p.linterm[index].dim){ ap_coeff_set(coeff, &expr->p.linterm[index].coeff); } else { ap_coeff_set_scalar_double(coeff,0.0); } return false; } default: abort(); } } bool ap_linexpr0_set_list_generic(ap_coeff_t* (*get_pcoeff)(void* expr, bool cst, va_list* va), void* expr, va_list* va) { bool cst; ap_coeff_t* coeff; ap_coeff_t* pcoeff; ap_scalar_t *scalar,*scalar1,*scalar2; ap_interval_t* interval; int num,num1,num2,den,den1,den2; double k,k1,k2; MP_RAT *mpq,*mpq1,*mpq2; __mpfr_struct *mpfr,*mpfr1,*mpfr2; ap_coefftag_t tag; while (true){ tag = va_arg(*va,ap_coefftag_t); if (tag==AP_END) break; cst = (tag>=AP_CST); if (cst) tag-=AP_CST; switch (tag){ case AP_COEFF: coeff = va_arg(*va,ap_coeff_t*); pcoeff = get_pcoeff(expr,cst,va); if (pcoeff==NULL) return true; ap_coeff_set(pcoeff,coeff); break; case AP_COEFF_S: scalar = va_arg(*va,ap_scalar_t*); pcoeff = get_pcoeff(expr,cst,va); if (pcoeff==NULL) return true; ap_coeff_set_scalar(pcoeff,scalar); break; case AP_COEFF_S_MPQ: mpq = va_arg(*va,MP_RAT*); pcoeff = get_pcoeff(expr,cst,va); if (pcoeff==NULL) return true; ap_coeff_set_scalar_mpq(pcoeff,mpq); break; case AP_COEFF_S_MPFR: mpfr = va_arg(*va,__mpfr_struct*); pcoeff = get_pcoeff(expr,cst,va); if (pcoeff==NULL) return true; ap_coeff_set_scalar_mpfr(pcoeff,mpfr); break; case AP_COEFF_S_INT: num = va_arg(*va,int); pcoeff = get_pcoeff(expr,cst,va); if (pcoeff==NULL) return true; ap_coeff_set_scalar_int(pcoeff,num); break; case AP_COEFF_S_FRAC: num = va_arg(*va,int); den = va_arg(*va,int); pcoeff = get_pcoeff(expr,cst,va); if (pcoeff==NULL) return true; ap_coeff_set_scalar_frac(pcoeff,num,den); break; case AP_COEFF_S_DOUBLE: k = va_arg(*va,double); pcoeff = get_pcoeff(expr,cst,va); if (pcoeff==NULL) return true; ap_coeff_set_scalar_double(pcoeff,k); break; case AP_COEFF_I: interval = va_arg(*va,ap_interval_t*); pcoeff = get_pcoeff(expr,cst,va); if (pcoeff==NULL) return true; ap_coeff_set_interval(pcoeff,interval); break; case AP_COEFF_I_SCALAR: scalar1 = va_arg(*va,ap_scalar_t*); scalar2 = va_arg(*va,ap_scalar_t*); pcoeff = get_pcoeff(expr,cst,va); if (pcoeff==NULL) return true; ap_coeff_set_interval_scalar(pcoeff,scalar1,scalar2); break; case AP_COEFF_I_MPQ: mpq1 = va_arg(*va,MP_RAT*); mpq2 = va_arg(*va,MP_RAT*); pcoeff = get_pcoeff(expr,cst,va); if (pcoeff==NULL) return true; ap_coeff_set_interval_mpq(pcoeff,mpq1,mpq2); break; case AP_COEFF_I_MPFR: mpfr1 = va_arg(*va,__mpfr_struct*); mpfr2 = va_arg(*va,__mpfr_struct*); pcoeff = get_pcoeff(expr,cst,va); if (pcoeff==NULL) return true; ap_coeff_set_interval_mpfr(pcoeff,mpfr1,mpfr2); break; case AP_COEFF_I_INT: num1 = va_arg(*va,int); num2 = va_arg(*va,int); pcoeff = get_pcoeff(expr,cst,va); if (pcoeff==NULL) return true; ap_coeff_set_interval_int(pcoeff,num1,num2); break; case AP_COEFF_I_FRAC: num1 = va_arg(*va,int); den1 = va_arg(*va,int); num2 = va_arg(*va,int); den2 = va_arg(*va,int); pcoeff = get_pcoeff(expr,cst,va); if (pcoeff==NULL) return true; ap_coeff_set_interval_frac(pcoeff,num1,den1,num2,den2); break; case AP_COEFF_I_DOUBLE: k1 = va_arg(*va,double); k2 = va_arg(*va,double); pcoeff = get_pcoeff(expr,cst,va); if (pcoeff==NULL) return true; ap_coeff_set_interval_double(pcoeff,k1,k2); break; default: fprintf(stderr, "ap_linexpr0_set_list_generic: probably bad structure for the argument list\n"); abort(); } } return false; } ap_coeff_t* ap_linexpr0_set_list_get_pcoeff(void* expr, bool cst, va_list* va) { ap_coeff_t* pcoeff; if (cst){ pcoeff = ap_linexpr0_cstref(expr); } else { ap_dim_t dim = va_arg(*va,ap_dim_t); pcoeff = ap_linexpr0_coeffref(expr,dim); } return pcoeff; } bool ap_linexpr0_set_list(ap_linexpr0_t* expr, ...) { va_list va; bool res; va_start(va,expr); res = ap_linexpr0_set_list_generic(ap_linexpr0_set_list_get_pcoeff, expr,&va); va_end(va); return res; } /* ====================================================================== */ /* IV. Change of dimensions and permutations */ /* ====================================================================== */ /* Change current environment with a super-environment */ static int ap_linterm_cmp(const void* a, const void* b) { const ap_linterm_t* aa = (const ap_linterm_t*)a; const ap_linterm_t* bb = (const ap_linterm_t*)b; return (aa->dim > bb->dim) ? 1 : ( (aa->dim < bb->dim) ? -1 : 0 ); } ap_linexpr0_t* ap_linexpr0_add_dimensions(ap_linexpr0_t* expr, ap_dimchange_t* dimchange) { ap_linexpr0_t* nexpr; if (expr==NULL) return NULL; nexpr = ap_linexpr0_copy(expr); ap_linexpr0_add_dimensions_with(nexpr,dimchange); return nexpr; } void ap_linexpr0_add_dimensions_with(ap_linexpr0_t* expr, ap_dimchange_t* dimchange) { if (expr==NULL) return; switch(expr->discr){ case AP_LINEXPR_SPARSE: { size_t i,k,dimsup; dimsup = dimchange->intdim+dimchange->realdim; k=0; for (i=0; isize; i++){ ap_dim_t* pdim = &expr->p.linterm[i].dim; if (*pdim==AP_DIM_MAX) break; while (k=dimchange->dim[k]){ k++; } *pdim += k; } } break; case AP_LINEXPR_DENSE: { int i,k; size_t size,dimsup; size = expr->size; dimsup = dimchange->intdim+dimchange->realdim; ap_linexpr0_realloc(expr, size+dimsup); k = dimsup; for (i=size; i>=0; i--){ if (i<(int)size){ ap_coeff_set(&expr->p.coeff[i+k],&expr->p.coeff[i]); } while (k>=1 && dimchange->dim[k-1]==(ap_dim_t)i){ k--; ap_coeff_set_scalar_double(&expr->p.coeff[i+k],0.0); } } } break; default: abort(); } } ap_linexpr0_t* ap_linexpr0_permute_dimensions(ap_linexpr0_t* expr, ap_dimperm_t* perm) { if (expr==NULL) return NULL; ap_linexpr0_t* nexpr = ap_linexpr0_copy(expr); switch(nexpr->discr){ case AP_LINEXPR_SPARSE: ap_linexpr0_permute_dimensions_with(nexpr,perm); break; case AP_LINEXPR_DENSE: { size_t i; for (i=0; isize; i++){ ap_coeff_set(&nexpr->p.coeff[perm->dim[i]],&expr->p.coeff[i]); } } break; default: abort(); } return nexpr; } void ap_linexpr0_permute_dimensions_with(ap_linexpr0_t* expr, ap_dimperm_t* perm) { if (expr==NULL) return; switch(expr->discr){ case AP_LINEXPR_SPARSE: { size_t i; for (i=0; isize; i++){ ap_dim_t dim = expr->p.linterm[i].dim; if (dim==AP_DIM_MAX) continue; expr->p.linterm[i].dim = perm->dim[dim]; } qsort(expr->p.linterm, expr->size, sizeof(ap_linterm_t), &ap_linterm_cmp); } break; case AP_LINEXPR_DENSE: { ap_linexpr0_t* nexpr = ap_linexpr0_permute_dimensions(expr,perm); ap_linexpr0_clear(expr); *expr = *nexpr; free(nexpr); } break; default: abort(); } } /* ====================================================================== */ /* V. Hashing, comparison */ /* ====================================================================== */ long ap_linexpr0_hash(ap_linexpr0_t* expr) { if (expr->size==0){ return ap_coeff_hash(&expr->cst); } else { ap_coeff_t* pcoeff; size_t i,dec; long res,res1; res = expr->size << 8; dec = 0; for (i=0; isize; i += (expr->size+7)/8){ pcoeff = ap_linexpr0_coeffref(expr,i); res1 = (pcoeff==NULL) ? 0 : ap_coeff_hash(pcoeff); res += res1<cst); ap_coeff_reduce(&expr2->cst); res = ap_coeff_equal(&expr1->cst,&expr2->cst); i1 = i2 = 0; while (res && (i1size || i2size)){ if (i1size){ if (expr1->discr==AP_LINEXPR_DENSE){ dim1 = i1; coeff1 = &expr1->p.coeff[i1]; } else { dim1 = expr1->p.linterm[i1].dim; coeff1 = &expr1->p.linterm[i1].coeff; } ap_coeff_reduce(coeff1); } else { dim1 = AP_DIM_MAX; coeff1 = NULL; } if (i2size){ if (expr2->discr==AP_LINEXPR_DENSE){ dim2 = i2; coeff2 = &expr2->p.coeff[i2]; } else { dim2 = expr2->p.linterm[i2].dim; coeff2 = &expr2->p.linterm[i2].coeff; } ap_coeff_reduce(coeff2); } else { dim2 = AP_DIM_MAX; coeff2 = NULL; } if (dim1==dim2){ i1++; i2++; res = ap_coeff_equal(coeff1,coeff2); } else if (dim1size || i2size)){ if (i1size){ if (expr1->discr==AP_LINEXPR_DENSE){ dim1 = i1; coeff1 = &expr1->p.coeff[i1]; } else { dim1 = expr1->p.linterm[i1].dim; coeff1 = &expr1->p.linterm[i1].coeff; } ap_coeff_reduce(coeff1); } else { dim1 = AP_DIM_MAX; coeff1 = NULL; } if (i2size){ if (expr2->discr==AP_LINEXPR_DENSE){ dim2 = i2; coeff2 = &expr2->p.coeff[i2]; } else { dim2 = expr2->p.linterm[i2].dim; coeff2 = &expr2->p.linterm[i2].coeff; } ap_coeff_reduce(coeff2); } else { dim2 = AP_DIM_MAX; coeff2 = NULL; } if (dim1==dim2){ i1++; i2++; res = ap_coeff_cmp(coeff1,coeff2); } else if (dim1cst); ap_coeff_reduce(&expr2->cst); res = ap_coeff_cmp(&expr1->cst,&expr2->cst); } ap_coeff_free(coeffzero); return res; } /* ====================================================================== */ /* Vb. Array of expressions */ /* ====================================================================== */ void ap_linexpr0_array_free(ap_linexpr0_t** texpr, size_t size) { size_t i; for (i=0;i #include #include "ap_manager.h" #include "ap_environment.h" static int var_cmp(const void* a, const void* b) { void* aa = *((void**)a); void* bb = *((void**)b); return ap_var_operations->compare(aa,bb); } typedef struct vardim_t { ap_var_t var; ap_dim_t dim; } vardim_t; static int vardim_cmp(const void* a, const void* b) { vardim_t* aa = (vardim_t*)a; vardim_t* bb = (vardim_t*)b; return ap_var_operations->compare(aa->var,bb->var); } /* ************************************************************************* */ /* I. env_t */ /* ************************************************************************* */ /* The env_t internal type store the binding name to dimension for one type. We use this type to factorize most operations on environments. */ /* ========================================================================= */ /* Datatype */ /* ========================================================================= */ typedef struct env_t { ap_var_t* var_of_dim; /* Array of size size, indexed by dimensions, representing the map dim -> name. - It should not contain identical strings. - It is lexicographically sorted. - The memory allocated for the strings are attached to the structure (they are freed when the structure is no longer in use) */ size_t size; /* Size of the array */ } env_t; /* Free all the memory pointed from env and reinitialize fields with 0. */ static void env_clear(env_t* env) { size_t i; for (i=0;isize; i++){ ap_var_operations->free(env->var_of_dim[i]); env->var_of_dim[i] = NULL; } if (env->var_of_dim){ free(env->var_of_dim); env->var_of_dim = NULL; } env->size = 0; } /* Normalize env by sorting the array of names. If perm!=NULL, fill already allocated and initialized perm with the applied permutation*/ static void env_normalize(env_t* env, ap_dim_t* perm) { if (perm==NULL){ qsort(env->var_of_dim,env->size,sizeof(ap_var_t),var_cmp); } else { size_t i; vardim_t* vardim = malloc(env->size*sizeof(vardim_t)); for (i=0; isize; i++){ vardim[i].var = env->var_of_dim[i]; vardim[i].dim = i; } qsort(vardim,env->size,sizeof(vardim_t),vardim_cmp); for(i=0; isize; i++){ env->var_of_dim[i] = vardim[i].var; perm[vardim[i].dim] = i; /* invert the permutation vardim[].dim */ } free(vardim); } } /* Build an object env_t from its component */ static env_t env_cons(ap_var_t* var_of_dim, size_t size) { env_t res; res.var_of_dim = var_of_dim; res.size = size; return res; } /* Return true iff invariant not satisfied */ static bool env_check(env_t* env) { int i; /* Check that there is no doublons */ for (i=0; i<(int)env->size - 1; i++){ if (ap_var_operations->compare(env->var_of_dim[i],env->var_of_dim[i+1])>=0){ return true; } } return false; } /* ========================================================================= */ /* Tests */ /* ========================================================================= */ /* Return true iff the 2 environments share some variables */ static bool env_is_inter_empty(env_t* env1 ,env_t* env2) { size_t i1,i2; i1 = i2 = 0; while (i1size && i2size){ int sgn = ap_var_operations->compare(env1->var_of_dim[i1],env2->var_of_dim[i2]); if (sgn==0) return false; if (sgn>0) i2++; else i1++; } return true; } /* Return true iff env1 is a subset of env2 */ static bool env_is_leq(env_t* env1, env_t* env2) { size_t i,j; int sgn = 0; if (env1->size<=env2->size){ j = 0; for (i=0;isize; i++){ while (jsize){ sgn = ap_var_operations->compare(env1->var_of_dim[i],env2->var_of_dim[j]); j++; if (sgn<0) return false; if (sgn==0) break; } if(sgn!=0) return false; } return true; } else return false; } /* ========================================================================= */ /* Operations */ /* ========================================================================= */ /* Add an array of new names to the environment and return the resulting environment. - The new names are duplicated, so it is the responsability of the user to free the new names he provides. - If a new name is already present in the initial environment, the result does not satisfy the datatype invariant. - If perm!=NULL, fill already allocated and initialized perm with the applied permutation to move the new names from the end to their sorted location. */ static env_t env_add(env_t* env, ap_var_t* var_of_dim, size_t size, ap_dim_t* perm) { env_t nenv; size_t i; assert( var_of_dim!=NULL || size==0); nenv.var_of_dim = malloc((env->size+size)*sizeof(ap_var_t)); nenv.size = env->size+size; for (i=0;isize; i++){ nenv.var_of_dim[i] = ap_var_operations->copy(env->var_of_dim[i]); } for (i=0;isize+i] = ap_var_operations->copy(var_of_dim[i]); } env_normalize(&nenv,perm); return nenv; } /* Remove from an environment an array of names. - May reorder the input array - If a name to be removed was not present, return { NULL, UINT_MAX }. */ static env_t env_remove(env_t* env, ap_var_t* var_of_dim, size_t size) { env_t nenv; size_t i,j; assert( var_of_dim!=NULL || size==0); if (size > env->size){ return env_cons(NULL,UINT_MAX); } nenv.var_of_dim = malloc((env->size-size)*sizeof(ap_var_t)); nenv.size = env->size-size; if (var_of_dim && size){ qsort(var_of_dim,size,sizeof(ap_var_t),var_cmp); j=0; for (i=0;icompare(env->var_of_dim[i+j],var_of_dim[j]); assert(sgn<=0); if (sgn==0) j++; else break; } nenv.var_of_dim[i] = ap_var_operations->copy(env->var_of_dim[i+j]); } while (jcompare(env->var_of_dim[nenv.size+j],var_of_dim[j]); if (sgn==0) j++; else { env_clear(&nenv); nenv.size = UINT_MAX; break; } } } else { /* Perform just a copy */ for (i=0;isize; i++){ nenv.var_of_dim[i] = ap_var_operations->copy(env->var_of_dim[i]); } } return nenv; } /* Least common environment of the two environments */ static env_t env_lce(env_t* e1, env_t* e2) { env_t e; size_t i,i1,i2; int sgn; e.var_of_dim = malloc((e1->size+e2->size)*sizeof(ap_var_t)); i = 0; i1 = 0; i2 = 0; while (i1size && i2size){ sgn = ap_var_operations->compare(e1->var_of_dim[i1],e2->var_of_dim[i2]); e.var_of_dim[i] = ap_var_operations->copy(sgn>0 ? e2->var_of_dim[i2] : e1->var_of_dim[i1]); i++; if (sgn>0) i2++; else if (sgn<0) i1++; else { i1++; i2++; } } while (i1size){ e.var_of_dim[i] = ap_var_operations->copy(e1->var_of_dim[i1]); i++; i1++; } while (i2size){ e.var_of_dim[i] = ap_var_operations->copy(e2->var_of_dim[i2]); i++; i2++; } e.size = i; e.var_of_dim = realloc(e.var_of_dim, e.size*sizeof(ap_var_t)); return e; } /* - env1 is supposed to be subenvironment of env - The function computes in the already allocated dimchange1 the conversion permutation from env1 to env, using offsetwriter and offsetread to shift the dimensions. - return true iff wrong arguments */ static bool env_lce_dimchange(env_t* e1, env_t* e, ap_dimchange_t* dimchange1, size_t offsetwrite, size_t offsetread) { size_t i,i1,k1; int sgn=0; if (e1->size>e->size) return true; i = 0; k1 = 0; for (i1=0; i1size; i1++){ while (isize){ sgn = ap_var_operations->compare(e1->var_of_dim[i1],e->var_of_dim[i]); i++; if (sgn<0) return true; if (sgn==0) break; /* here, a new dimension to insert */ dimchange1->dim[offsetwrite+k1] = offsetread+i1; k1++; } if(sgn!=0) return true; } while (isize){ dimchange1->dim[offsetwrite+k1] = offsetread+i1; i++; k1++; } return false; } /* Least common environment of an array of environments */ static env_t env_lce_array(env_t** tenv, size_t* tindex, size_t size) { int sgn; size_t i,index,maxvars; ap_var_t name; env_t env; maxvars=0; for (i=0; isize; tindex[i] = 0; } env.var_of_dim = malloc( maxvars*sizeof(ap_var_t) ); index = 0; while (true){ /* Find one possible next variable, and exit if none */ name = NULL; for (i=0;isize){ name = tenv[i]->var_of_dim[tindex[i]]; break; } } if (name==NULL) break; /* Find the minimal variable */ for (i=1; isize){ sgn = ap_var_operations->compare(name,tenv[i]->var_of_dim[tindex[i]]); if (sgn>0) name = tenv[i]->var_of_dim[tindex[i]]; } } env.var_of_dim[index] = ap_var_operations->copy(name); index++; /* Increment the indexes */ for (i=0; isize){ sgn = ap_var_operations->compare(name,tenv[i]->var_of_dim[tindex[i]]); if (sgn==0) tindex[i]++; } } } env.size = index; env.var_of_dim = realloc(env.var_of_dim, env.size*sizeof(ap_var_t)); return env; } /* ************************************************************************* */ /* II. ap_environment_t */ /* ************************************************************************* */ /* ========================================================================= */ /* Datatype */ /* ========================================================================= */ /* The denv_t internal type store the binding name to dimension for all types */ typedef struct denv_t { env_t envint; env_t envreal; } denv_t; static denv_t denv_of_environment(ap_environment_t* env) { denv_t res; res.envint = env_cons(env->var_of_dim,env->intdim); res.envreal = env_cons(env->var_of_dim ? &env->var_of_dim[env->intdim] : NULL, env->realdim); return res; } static ap_environment_t* environment_of_denv(denv_t* denv) { ap_environment_t* res; res = malloc(sizeof(ap_environment_t)); res->var_of_dim = malloc((denv->envint.size + denv->envreal.size)* sizeof(ap_var_t)); memcpy(&res->var_of_dim[0], denv->envint.var_of_dim,denv->envint.size*sizeof(ap_var_t)); memcpy(&res->var_of_dim[denv->envint.size], denv->envreal.var_of_dim,denv->envreal.size*sizeof(ap_var_t)); free(denv->envint.var_of_dim); free(denv->envreal.var_of_dim); res->intdim = denv->envint.size; res->realdim = denv->envreal.size; res->count = 1; return res; } /* ========================================================================= */ /* Access */ /* ========================================================================= */ ap_dim_t ap_environment_dim_of_var(ap_environment_t* env, ap_var_t name){ ap_var_t* res; res = bsearch(&name,env->var_of_dim,env->intdim,sizeof(ap_var_t),var_cmp); if (res!=NULL){ return ((long int)res - (long int)env->var_of_dim)/sizeof(ap_var_t); } else { res = bsearch(&name,&env->var_of_dim[env->intdim],env->realdim,sizeof(ap_var_t),var_cmp); if (res!=NULL){ return ((long int)res - (long int)env->var_of_dim)/sizeof(ap_var_t); } else { return AP_DIM_MAX; } } } /* ========================================================================= */ /* Checks */ /* ========================================================================= */ bool ap_environment_check(ap_environment_t* env) { denv_t denv = denv_of_environment(env); /* Check that there is no doublons */ if (env_check(&denv.envint)) return true; if (env_check(&denv.envreal)) return true; /* Check that integer and real variables are disjoint */ if (! env_is_inter_empty(&denv.envint,&denv.envreal)) return true; return false; } bool ap_environment_check_compatibility(ap_environment_t* env1, ap_environment_t* env2) { denv_t denv1 = denv_of_environment(env1); denv_t denv2 = denv_of_environment(env2); /* Check that integer of one and real variables of other are disjoint */ return !(env_is_inter_empty(&denv1.envint,&denv2.envreal) && env_is_inter_empty(&denv2.envint,&denv1.envreal) ); } /* ========================================================================= */ /* Memory management */ /* ========================================================================= */ ap_environment_t* ap_environment_add(ap_environment_t* env, ap_var_t* name_of_intdim, size_t intdim, ap_var_t* name_of_realdim, size_t realdim) { ap_environment_t* res; denv_t denv2; denv_t denv1 = denv_of_environment(env); denv2.envint = env_add(&denv1.envint, name_of_intdim, intdim, NULL); denv2.envreal = env_add(&denv1.envreal, name_of_realdim, realdim, NULL); res = environment_of_denv(&denv2); /* Check now that there is no problem */ if (ap_environment_check(res)){ ap_environment_free(res); return NULL; } return res; } ap_environment_t* ap_environment_add_perm(ap_environment_t* env, ap_var_t* name_of_intdim, size_t intdim, ap_var_t* name_of_realdim, size_t realdim, ap_dimperm_t* perm) { ap_environment_t* res; size_t i,nsize; denv_t denv2; denv_t denv1 = denv_of_environment(env); nsize = env->intdim+intdim+env->realdim+realdim; ap_dimperm_init(perm,nsize); denv2.envint = env_add(&denv1.envint, name_of_intdim, intdim, &(perm->dim[0])); denv2.envreal = env_add(&denv1.envreal, name_of_realdim, realdim, &(perm->dim[env->intdim+intdim])); for (i=0;irealdim+realdim;i++){ perm->dim[env->intdim + intdim + i] += env->intdim + intdim; } res = environment_of_denv(&denv2); /* Check now that there is no problem */ if (ap_environment_check(res)){ ap_environment_free(res); ap_dimperm_clear(perm); res = NULL; } return res; } ap_environment_t* ap_environment_remove(ap_environment_t* env, ap_var_t* tvar, size_t size) { ap_var_t* tvar2; size_t i; size_t intdim,realdim; ap_var_t* tvarint; ap_var_t* tvarreal; denv_t denv1,denv2; ap_environment_t* res; if (size==0) return ap_environment_copy(env); ; /* Copy the input array and split it into integer and real arrays */ tvar2 = malloc(size*sizeof(ap_var_t)); memcpy(tvar2,tvar,size*sizeof(ap_var_t)); intdim = size; i = 0; while (i=env->intdim){ intdim--; ap_var_t t = tvar2[i]; tvar2[i] = tvar2[intdim]; tvar2[intdim] = t; } else { i++; } } tvarint = intdim ? &tvar2[0] : NULL; realdim = size-intdim; tvarreal = realdim ? &tvar2[intdim] : NULL; denv1 = denv_of_environment(env); denv2.envint = env_remove(&denv1.envint, tvarint, intdim); denv2.envreal = env_remove(&denv1.envreal, tvarreal, realdim); if (denv2.envint.size==UINT_MAX || denv2.envreal.size==UINT_MAX){ res = NULL; } else { res = environment_of_denv(&denv2); } free(tvar2); return res; } ap_environment_t* ap_environment_alloc(ap_var_t* name_of_intdim, size_t intdim, ap_var_t* name_of_realdim, size_t realdim) { ap_environment_t env = { NULL, 0,0,0 }; return ap_environment_add(&env, name_of_intdim, intdim, name_of_realdim, realdim); } ap_environment_t* ap_environment_alloc_empty() { return ap_environment_alloc(NULL,0,NULL,0); } void ap_environment_free2(ap_environment_t* env) { size_t i; if (env->var_of_dim){ for(i=0;iintdim+env->realdim;i++){ if(env->var_of_dim[i]){ ap_var_operations->free(env->var_of_dim[i]);env->var_of_dim[i]=NULL; } } free(env->var_of_dim); env->var_of_dim = NULL; } env->count = 0; free(env); } void ap_environment_fdump(FILE* stream, ap_environment_t* env) { size_t i; char* name; fprintf(stream,"environment: dim = (%lu,%lu), count = %lu\n", (unsigned long)env->intdim,(unsigned long)env->realdim, (unsigned long)env->count); for (i=0; iintdim+env->realdim; i++){ name = ap_var_operations->to_string(env->var_of_dim[i]); fprintf(stream,"%2lu: %s\n",(unsigned long)i,name); free(name); } } ap_environment_name_of_dim_t* ap_environment_name_of_dim_alloc(ap_environment_t* env) { size_t i,size; size = env->intdim+env->realdim; ap_environment_name_of_dim_t* res = malloc(sizeof(ap_environment_name_of_dim_t)+size*sizeof(char*)); res->size = size; for (i=0; ip[i] = ap_var_operations->to_string(env->var_of_dim[i]); } return res; } void ap_environment_name_of_dim_free(ap_environment_name_of_dim_t* p) { size_t i; for (i=0; isize; i++){ free(p->p[i]); } free(p); } /* ========================================================================= */ /* Tests */ /* ========================================================================= */ bool ap_environment_is_eq(ap_environment_t* env1, ap_environment_t* env2) { bool res = (env1==env2); if (!res){ res = (env1->intdim==env2->intdim) && (env1->realdim==env2->realdim); if (res){ size_t i; for (i=0; iintdim+env1->realdim; i++){ if (ap_var_operations->compare(env1->var_of_dim[i],env2->var_of_dim[i])){ res = false; break; } } } } return res; } bool ap_environment_is_leq(ap_environment_t* env1, ap_environment_t* env2) { bool res = (env1==env2); if (!res){ res = (env1->intdim<=env2->intdim) && (env1->realdim<=env2->realdim); if (res){ denv_t denv1 = denv_of_environment(env1); denv_t denv2 = denv_of_environment(env2); res = env_is_leq(&denv1.envint,&denv2.envint) && env_is_leq(&denv1.envreal,&denv2.envreal); } } return res; } int ap_environment_compare(ap_environment_t* env1, ap_environment_t* env2) { ap_dimchange_t* dimchange1=NULL; ap_dimchange_t* dimchange2=NULL; ap_environment_t* e=NULL; int res; e = ap_environment_lce(env1,env2,&dimchange1,&dimchange2); if (e==NULL) res = -2; else if (dimchange1==NULL && dimchange2==NULL) res = 0; else if (dimchange1==NULL) res = 1; else if (dimchange2==NULL) res = -1; else res = 2; if (e) ap_environment_free(e); if (dimchange1) ap_dimchange_free(dimchange1); if (dimchange2) ap_dimchange_free(dimchange2); return res; } int ap_environment_hash(ap_environment_t* env) { int res; size_t size,i,dec; res = 997*(7*env->intdim+11*env->realdim); size = env->intdim+env->realdim; dec = 0; for (i=0; ihash(env->var_of_dim[i]) << dec; dec++; } return res; } /* ========================================================================= */ /* Compute least common environment of 2 environments */ /* ========================================================================= */ ap_dimchange_t* ap_environment_dimchange(ap_environment_t* env1, ap_environment_t* env) { bool b; ap_dimchange_t* dimchange; if (env->intdim < env1->intdim || env->realdim < env1->realdim) return NULL; denv_t denv1 = denv_of_environment(env1); denv_t denv = denv_of_environment(env); dimchange = ap_dimchange_alloc(env->intdim - env1->intdim, env->realdim - env1->realdim); b = env_lce_dimchange(&denv1.envint,&denv.envint, dimchange, 0, 0); if (!b) b = env_lce_dimchange(&denv1.envreal,&denv.envreal, dimchange, dimchange->intdim, env1->intdim); if (b){ ap_dimchange_free(dimchange); dimchange = NULL; } return dimchange; } /* Compute the transformation for switching from one environment to another one (adding and then removal of dimensions. - If environments are not compatible, return NULL */ ap_dimchange2_t* ap_environment_dimchange2(ap_environment_t* env1, ap_environment_t* env2) { size_t size; denv_t denv; bool eq1,eq2; ap_dimchange2_t* res; if (ap_environment_check_compatibility(env1,env2)) return NULL; denv_t denv1 = denv_of_environment(env1); denv_t denv2 = denv_of_environment(env2); denv.envint = env_lce(&denv1.envint, &denv2.envint); denv.envreal = env_lce(&denv1.envreal, &denv2.envreal); size = denv.envint.size+denv.envreal.size; res = ap_dimchange2_alloc(NULL,NULL); eq1 = denv.envint.size==denv1.envint.size && denv.envreal.size==denv1.envreal.size; eq2 = denv.envint.size==denv2.envint.size && denv.envreal.size==denv2.envreal.size; if (!eq1){ res->add = ap_dimchange_alloc(denv.envint.size-denv1.envint.size, denv.envreal.size-denv1.envreal.size); env_lce_dimchange(&denv1.envint,&denv.envint, res->add, 0, 0); env_lce_dimchange(&denv1.envreal,&denv.envreal, res->add, res->add->intdim, denv1.envint.size); } if (!eq2){ /* First build (as for lce) the dimchange for adding dimensions from env2 to env(lce), then invert it */ res->remove = ap_dimchange_alloc(denv.envint.size-denv2.envint.size, denv.envreal.size-denv2.envreal.size); env_lce_dimchange(&denv2.envint,&denv.envint, res->remove, 0,0); env_lce_dimchange(&denv2.envreal,&denv.envreal, res->remove, res->remove->intdim, denv2.envint.size); ap_dimchange_add_invert(res->remove); } env_clear(&denv.envint); env_clear(&denv.envreal); return res; } /* Least common environment to two environment. - If environments are not compatible, return NULL - Compute also in dimchange1 and dimchange2 the conversion transformations. - If no dimensions to add to env1, this implies that env is actually env1. In this case, *dimchange1==NULL. */ ap_environment_t* ap_environment_lce(ap_environment_t* env1, ap_environment_t* env2, ap_dimchange_t** dimchange1, ap_dimchange_t** dimchange2) { size_t size; denv_t denv; bool eq1,eq2; if (ap_environment_check_compatibility(env1,env2)) return NULL; denv_t denv1 = denv_of_environment(env1); denv_t denv2 = denv_of_environment(env2); denv.envint = env_lce(&denv1.envint, &denv2.envint); denv.envreal = env_lce(&denv1.envreal, &denv2.envreal); size = denv.envint.size+denv.envreal.size; eq1 = denv.envint.size==denv1.envint.size && denv.envreal.size==denv1.envreal.size; eq2 = denv.envint.size==denv2.envint.size && denv.envreal.size==denv2.envreal.size; if (eq1){ *dimchange1 = NULL; } else { *dimchange1 = ap_dimchange_alloc(denv.envint.size-denv1.envint.size, denv.envreal.size-denv1.envreal.size); env_lce_dimchange(&denv1.envint,&denv.envint, *dimchange1, 0, 0); env_lce_dimchange(&denv1.envreal,&denv.envreal, *dimchange1, (*dimchange1)->intdim, denv1.envint.size); } if (eq2){ *dimchange2 = NULL; } else { *dimchange2 = ap_dimchange_alloc(denv.envint.size-denv2.envint.size, denv.envreal.size-denv2.envreal.size); env_lce_dimchange(&denv2.envint,&denv.envint, *dimchange2, 0,0); env_lce_dimchange(&denv2.envreal,&denv.envreal, *dimchange2, (*dimchange2)->intdim, denv2.envint.size); } if (eq1){ /* env=env1 */ env_clear(&denv.envint); env_clear(&denv.envreal); return ap_environment_copy(env1); } else if (eq2){ /* env=env1 */ env_clear(&denv.envint); env_clear(&denv.envreal); return ap_environment_copy(env2); } else { return environment_of_denv(&denv); } } /* ========================================================================= */ /* Compute least common environment of an array of environments */ /* ========================================================================= */ /* Least common environment to an array environments. - Assume the size of the array is at least one. - If all input environments are the same, *ptdimchange==NULL. Otherwise, compute in *ptdimchange the conversion permutations. - Dimensions to add before applying the permutation (according to the conventions of the function ap_abstract0_add_permute_dimensions) are implictly given by env->intdim-env[i]->intdim and env->realdim - env[i]->realdim. - If no dimensions to add to env[i], this implies that env is actually env[i]. In this case, (*ptdimchange)[i]==NULL. Otherwise, the function allocates the array (*ptdimchange)[0] with malloc. */ static int env_cmp(const void* a, const void* b) { ap_environment_t* pa = *((ap_environment_t**)a); ap_environment_t* pb = *((ap_environment_t**)b); return (pa>pb ? 1 : (pa==pb ? 0 : -1)); } ap_environment_t* ap_environment_lce_array(ap_environment_t** tenv, size_t size, ap_dimchange_t*** ptdimchange) { size_t i, intrealdim; denv_t* tdenv; env_t** te; size_t* tindex; denv_t denv; int j; bool change; assert(size>=1); qsort(tenv,size,sizeof(ap_environment_t*),env_cmp); /* remove doublons */ for(i=0;iintdim, tdenv[i].envint.size); } } if (j>0){ env_clear(&denv.envint); env_clear(&denv.envreal); if (!change){ free(*ptdimchange); *ptdimchange=NULL; } return ap_environment_copy(tenv[j]); } else { ap_environment_t* env = environment_of_denv(&denv); if (ap_environment_check(env)){ for (i=0;iintdim+env->realdim; res = malloc(sizeof(ap_environment_t)); res->intdim = env->intdim; res->realdim = env->realdim; res->count = 1; res->var_of_dim = malloc(nbdims*sizeof(ap_var_t)); /* Build the new environment */ for (i=0; ivar_of_dim[i] = NULL; } for (j=0; jvar_of_dim[dim] = ap_var_operations->copy(tvar2[j]); } for (i=0; ivar_of_dim[i] == NULL){ res->var_of_dim[i] = ap_var_operations->copy(env->var_of_dim[i]); } } /* Now we have to sort it and compute the permutation transformation */ ap_dimperm_init(perm,nbdims); denv = denv_of_environment(res); env_normalize(&denv.envint,perm->dim); env_normalize(&denv.envreal,perm->dim+res->intdim); for (i=0; irealdim; i++){ perm->dim[res->intdim + i] += res->intdim; } if (ap_environment_check(res)){ ap_environment_free(res); ap_dimperm_clear(perm); res = NULL; } return res; } apron-dist-0.9.10/apron/apron/ap_lincons1.h0000640014525101416610000002417310677671162020406 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_lincons1.h: linear constraints and arrays */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ /* normally included from ap_expr1.h */ #ifndef _AP_LINCONS1_H_ #define _AP_LINCONS1_H_ #include #include #include #include "ap_coeff.h" #include "ap_environment.h" #include "ap_lincons0.h" #include "ap_linexpr1.h" #ifdef __cplusplus extern "C" { #endif /* ====================================================================== */ /* Datatypes */ /* ====================================================================== */ /* Constraints */ typedef struct ap_lincons1_t { ap_lincons0_t lincons0; ap_environment_t* env; } ap_lincons1_t; /* Array of constraints */ typedef struct ap_lincons1_array_t { ap_lincons0_array_t lincons0_array; ap_environment_t* env; } ap_lincons1_array_t; /* ********************************************************************** */ /* I. ap_lincons1_t */ /* ********************************************************************** */ /* For internal use */ static inline ap_lincons1_t ap_lincons1_of_lincons0(ap_environment_t* env, ap_lincons0_t lincons0) { ap_lincons1_t res; res.lincons0 = lincons0; res.env = ap_environment_copy(env); return res; } /* ====================================================================== */ /* I.1 Memory management and printing */ /* ====================================================================== */ static inline ap_lincons1_t ap_lincons1_make(ap_constyp_t constyp, ap_linexpr1_t* expr, ap_scalar_t* scalar); /* Create a constraint of given type with the given expression. The expression and the optional coefficient are not duplicated, just pointed to. */ ap_lincons1_t ap_lincons1_make_unsat(ap_environment_t* env); /* Create the constraint -1>=0 */ static inline ap_lincons1_t ap_lincons1_copy(ap_lincons1_t* cons); /* Duplication */ void ap_lincons1_clear(ap_lincons1_t* cons); /* Clear the constraint and set pointers to NULL */ void ap_lincons1_fprint(FILE* stream, ap_lincons1_t* cons); /* Printing */ /* ====================================================================== */ /* I.2 Tests */ /* ====================================================================== */ static inline bool ap_lincons1_is_unsat(ap_lincons1_t* cons); /* True if the constraint is b>=0 or [a,b]>=0 with b negative */ /* ====================================================================== */ /* I.3 Access */ /* ====================================================================== */ static inline ap_environment_t* ap_lincons1_envref(ap_lincons1_t* cons); /* Get a reference to the environment. Do not free it. */ static inline ap_constyp_t* ap_lincons1_constypref(ap_lincons1_t* cons); /* Get a reference to the type of constraint */ static inline ap_scalar_t* ap_lincons1_scalarref(ap_lincons1_t* cons); /* Get a reference to the auxiliary coefficient of the constraint */ static inline ap_linexpr1_t ap_lincons1_linexpr1ref(ap_lincons1_t* cons); /* Get a reference to the underlying expression of the constraint. Do not free it: nothing is duplicated. Modifying the argument or the result is equivalent, except for change of dimensions/environment. */ /* Get the constant and assign it to coeff */ static inline void ap_lincons1_get_cst(ap_coeff_t* coeff, ap_lincons1_t* cons); /* Get coefficient of variable var in the constraint and assign it to coeff. Return true if var is unknown in the environment */ bool ap_lincons1_get_coeff(ap_coeff_t* coeff, ap_lincons1_t* cons, ap_var_t var); /* Set the constant of the linear constraint */ static inline void ap_lincons1_set_cst(ap_lincons1_t* cons, ap_coeff_t* cst); /* Set the coefficient of variable var in the constraint. Return true if var is unknown in the environment */ static inline bool ap_lincons1_set_coeff(ap_lincons1_t* cons, ap_var_t var, ap_coeff_t* coeff); /* bool ap_lincons1_set_format(ap_lincons1_t* cons, char* fmt, ...); */ bool ap_lincons1_set_list(ap_lincons1_t* cons, ...); static inline ap_coeff_t* ap_lincons1_cstref(ap_lincons1_t* cons); /* Get a reference to the constant. Do not free it. */ ap_coeff_t* ap_lincons1_coeffref(ap_lincons1_t* cons, ap_var_t var); /* Get a reference to the coefficient associated to the variable. Do not free it. In case of sparse representation, possibly induce the addition of a new linear term. Return NULL if var is unknown in the environment. */ static inline ap_lincons0_t* ap_lincons1_lincons0ref(ap_lincons1_t* cons); /* Return underlying constraint of level 0. Do not free it: nothing is duplicated. Modifying the argument or the result is equivalent, except for change of dimensions/environment. */ /* ====================================================================== */ /* I.3 Change of dimensions and permutations */ /* ====================================================================== */ bool ap_lincons1_extend_environment(ap_lincons1_t* ncons, ap_lincons1_t* cons, ap_environment_t* nenv); bool ap_lincons1_extend_environment_with(ap_lincons1_t* cons, ap_environment_t* nenv); /* ********************************************************************** */ /* II. Array of linear constraints */ /* ********************************************************************** */ /* ====================================================================== */ /* I.1 Memory management and printing */ /* ====================================================================== */ ap_lincons1_array_t ap_lincons1_array_make(ap_environment_t* env, size_t size); /* Allocate an array of size constraints. The constraints are initialized with NULL pointers, so that ap_lincons1_array_free may be safely called */ void ap_lincons1_array_clear(ap_lincons1_array_t* array); /* Clear the constraints of the array, and then the array itself */ void ap_lincons1_array_fprint(FILE* stream, ap_lincons1_array_t* ap_lincons1_array); /* Printing */ /* ====================================================================== */ /* II.3 Access */ /* ====================================================================== */ static inline size_t ap_lincons1_array_size(ap_lincons1_array_t* array); static inline ap_environment_t* ap_lincons1_array_envref(ap_lincons1_array_t* array); static inline void ap_lincons1_array_clear_index(ap_lincons1_array_t* array, size_t index); /* Clear the constraint at index index. */ ap_lincons1_t ap_lincons1_array_get(ap_lincons1_array_t* array, size_t index); /* Return the linear constraint of the given index Nothing is duplicated, and the result should never be cleared. Modifying the argument or the result is equivalent, except for change of environments */ bool ap_lincons1_array_set(ap_lincons1_array_t* array, size_t index, ap_lincons1_t* cons); /* Fill the index of the array with the constraint. Assumes ap_environment_is_eq(array->env,cons->env). Nothing is duplicated. The argument should never be cleared. (its environment is dereferenced). If a constraint was already stored, it is first cleared. Return true iff problem (index or array->env!=cons->env) */ /* ====================================================================== */ /* II.4 Change of dimensions and permutations */ /* ====================================================================== */ bool ap_lincons1_array_extend_environment_with(ap_lincons1_array_t* array, ap_environment_t* env); bool ap_lincons1_array_extend_environment(ap_lincons1_array_t* narray, ap_lincons1_array_t* array, ap_environment_t* env); /* ********************************************************************** */ /* III. Inline functions definitions */ /* ********************************************************************** */ static inline ap_lincons1_t ap_lincons1_make(ap_constyp_t constyp, ap_linexpr1_t* expr, ap_scalar_t* scalar) { ap_lincons1_t cons; cons.lincons0 = ap_lincons0_make(constyp,expr->linexpr0,scalar); cons.env = expr->env; return cons; } static inline ap_lincons1_t ap_lincons1_copy(ap_lincons1_t* cons){ ap_lincons1_t ncons; ncons.lincons0 = ap_lincons0_copy(&cons->lincons0); ncons.env = ap_environment_copy(cons->env); return ncons; } bool ap_lincons1_is_unsat(ap_lincons1_t* cons){ return ap_lincons0_is_unsat(&cons->lincons0); } static inline ap_environment_t* ap_lincons1_envref(ap_lincons1_t* cons){ return cons->env; } static inline ap_constyp_t* ap_lincons1_constypref(ap_lincons1_t* cons){ return &cons->lincons0.constyp; } static inline ap_scalar_t* ap_lincons1_scalarref(ap_lincons1_t* cons){ return cons->lincons0.scalar; } static inline ap_linexpr1_t ap_lincons1_linexpr1ref(ap_lincons1_t* cons){ ap_linexpr1_t expr; expr.linexpr0 = cons->lincons0.linexpr0; expr.env = cons->env; return expr; } static inline ap_lincons0_t* ap_lincons1_lincons0ref(ap_lincons1_t* cons){ return &cons->lincons0; } static inline ap_coeff_t* ap_lincons1_cstref(ap_lincons1_t* cons){ return &cons->lincons0.linexpr0->cst; } static inline void ap_lincons1_get_cst(ap_coeff_t* coeff, ap_lincons1_t* cons){ ap_linexpr0_get_cst(coeff,cons->lincons0.linexpr0); } static inline void ap_lincons1_set_cst(ap_lincons1_t* cons, ap_coeff_t* cst){ ap_linexpr0_set_cst(cons->lincons0.linexpr0,cst); } static inline bool ap_lincons1_set_coeff(ap_lincons1_t* cons, ap_var_t var, ap_coeff_t* coeff) { ap_coeff_t* ecoeff = ap_lincons1_coeffref(cons,var); if (ecoeff){ap_coeff_set(ecoeff,coeff); return false;} else return true; } static inline size_t ap_lincons1_array_size(ap_lincons1_array_t* array){ return array->lincons0_array.size; } static inline ap_environment_t* ap_lincons1_array_envref(ap_lincons1_array_t* array){ return array->env; } static inline void ap_lincons1_array_clear_index(ap_lincons1_array_t* array, size_t index){ ap_lincons0_clear(&array->lincons0_array.p[index]); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/ap_abstract0.c0000640014525101416610000014535611224616053020530 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_abstract0.c: generic interface */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "ap_abstract0.h" /* ********************************************************************** */ /* 0. Utility and checking functions */ /* ********************************************************************** */ /* Constructor for ap_abstract0_t */ static inline ap_abstract0_t* ap_abstract0_cons(ap_manager_t* man, void* value) { ap_abstract0_t* res = malloc(sizeof(ap_abstract0_t)); res->value = value; res->man = ap_manager_copy(man); return res; } static inline void _ap_abstract0_free(ap_abstract0_t* a) { void (*ptr)(ap_manager_t*,ap_abstract0_t*) = a->man->funptr[AP_FUNID_FREE]; ptr(a->man,a->value); ap_manager_free(a->man); free(a); } static inline ap_abstract0_t* ap_abstract0_cons2(ap_manager_t* man, bool destructive, ap_abstract0_t* oldabs, void* newvalue) { if (destructive){ if (oldabs->man != man){ ap_manager_free(oldabs->man); oldabs->man = ap_manager_copy(man); } oldabs->value = newvalue; return oldabs; } else { return ap_abstract0_cons(man,newvalue); } } /* ====================================================================== */ /* 0.1 Checking typing w.r.t. manager */ /* ====================================================================== */ /* These functions return true if everything is OK, otherwise they raise an exception in the manager and return false. */ /* One abstract value */ static void ap_abstract0_checkman1_raise(ap_funid_t funid, ap_manager_t* man, ap_abstract0_t* a) { char str[160]; snprintf(str,159,"\ The abstract value of type %s is not of the type %s expected by the manager\ ", a->man->library,man->library); ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, funid, str); } static inline bool ap_abstract0_checkman1(ap_funid_t funid, ap_manager_t* man, ap_abstract0_t* a) { if (man->library != a->man->library){ ap_abstract0_checkman1_raise(funid,man,a); return false; } else return true; } /* Two abstract values */ static bool ap_abstract0_checkman2(ap_funid_t funid, ap_manager_t* man, ap_abstract0_t* a1, ap_abstract0_t* a2) { bool res; char str[160]; res = true; if (man->library != a1->man->library){ snprintf(str,159,"\ The first abstract value of type %s is not of the type %s expected by the manager\ ", a1->man->library,man->library); res = false; } else if (man->library != a2->man->library){ snprintf(str,159,"\ The second abstract value of type %s is not of the type %s expected by the manager\ ", a2->man->library,man->library); res = false; } if (!res){ ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, funid, str); } return res; } /* Array of abstract values */ static bool ap_abstract0_checkman_array(ap_funid_t funid, ap_manager_t* man, ap_abstract0_t** tab, size_t size) { size_t i; for (i=0;ilibrary != tab[i]->man->library){ char str[160]; snprintf(str,159,"\ The %luth abstract value of the array is of type %s and not of the type %s expected by the manager\ ", (unsigned long)i,tab[i]->man->library,man->library); ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, funid, str); return false; } } return true; } /* ====================================================================== */ /* 0.2 Checking compatibility of arguments: abstract values */ /* ====================================================================== */ /* Getting dimensions without checks */ static inline ap_dimension_t _ap_abstract0_dimension(ap_abstract0_t* a) { ap_dimension_t (*ptr)(ap_manager_t*,...) = a->man->funptr[AP_FUNID_DIMENSION]; return ptr(a->man,a->value); } /* Check that the 2 abstract values have the same dimensionality */ static bool ap_abstract0_check_abstract2(ap_funid_t funid, ap_manager_t* man, ap_abstract0_t* a1, ap_abstract0_t* a2) { ap_dimension_t dim1 = _ap_abstract0_dimension(a1); ap_dimension_t dim2 = _ap_abstract0_dimension(a2); if ( (dim1.intdim != dim2.intdim) || (dim1.realdim != dim2.realdim) ){ char str[160]; snprintf(str,159,"\ incompatible dimensions for the two arguments:\n\ first abstract0: (%3lu,%3lu)\n\ second abstract0: (%3lu,%3lu)", (unsigned long)dim1.intdim, (unsigned long)dim1.realdim, (unsigned long)dim2.intdim, (unsigned long)dim2.realdim); ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, funid,str); return false; } else { return true; } } /* Check that the array of abstract values have the same dimensionality.*/ static bool ap_abstract0_check_abstract_array(ap_funid_t funid, ap_manager_t* man, ap_abstract0_t** tab, size_t size) { size_t i=0; ap_dimension_t dim; ap_dimension_t dim0; bool res; res = true; if (size==0){ ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, funid,"array of abstract values of size 0"); res = false; } else { dim0 = _ap_abstract0_dimension(tab[0]); for (i=1; i=dimension.intdim+dimension.realdim){ ap_abstract0_check_dim_raise(funid,man,dimension,dim, "incompatible dimension for the abstract value"); return false; } else { return true; } } /* Check that the array of dimensions make sense in the given dimensionality */ static bool ap_abstract0_check_dim_array(ap_funid_t funid, ap_manager_t* man, ap_dimension_t dimension, ap_dim_t* tdim, size_t size) { size_t i; for (i=0;i=dimension.intdim+dimension.realdim){ char str[80]; sprintf(str,"incompatible %luth dimension in the array for the abstract value",(unsigned long)i); ap_abstract0_check_dim_raise(funid,man,dimension,dim,str); return false; } } return true; } /* ====================================================================== */ /* 0.4 Checking compatibility of arguments: expressions */ /* ====================================================================== */ static void ap_abstract0_check_expr_raise(ap_funid_t funid, ap_manager_t* man, ap_dimension_t dimension, ap_dim_t dim, char* prefix) { char str[160]; snprintf(str,159,"\ %s:\n\ abstract0: (%3lu,%3lu)\n\ dimension: %3lu\ ", prefix, (unsigned long)dimension.intdim,(unsigned long)dimension.realdim, (unsigned long)dim); ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, funid,str); } /* Check that the linear expression makes sense in the given dimensionality */ static ap_dim_t ap_abstract0_check_linexpr_check(ap_dimension_t dimension, ap_linexpr0_t* expr) { int i; size_t nbdims; ap_dim_t dim; nbdims = dimension.intdim+dimension.realdim; dim = 0; switch (expr->discr){ case AP_LINEXPR_DENSE: if (expr->size > nbdims){ dim = expr->size-1; } else { dim = AP_DIM_MAX; } break; case AP_LINEXPR_SPARSE: /* Assumed to be sorted (this is not checked */ for (i=expr->size-1; i>=0; i--){ dim = expr->p.linterm[i].dim; if (dim!=AP_DIM_MAX){ if (dim < nbdims) dim = AP_DIM_MAX; ; break; } } if (!dim) dim = AP_DIM_MAX; break; default: abort(); } return dim; } static bool ap_abstract0_check_linexpr(ap_funid_t funid, ap_manager_t* man, ap_dimension_t dimension, ap_linexpr0_t* expr) { ap_dim_t dim = ap_abstract0_check_linexpr_check(dimension,expr); if (dim!=AP_DIM_MAX){ ap_abstract0_check_expr_raise(funid,man,dimension,dim, "incompatible dimension in the linear expression for the abstract value"); return false; } else { return true; } } /* Check that the tree expression makes sense in the given dimensionality */ static ap_dim_t ap_abstract0_check_texpr_check(ap_dimension_t dimension, ap_texpr0_t* expr) { ap_dim_t dim; dim = ap_texpr0_max_dim(expr); if (dim <= dimension.intdim+dimension.realdim) return AP_DIM_MAX; else return dim; } static bool ap_abstract0_check_texpr(ap_funid_t funid, ap_manager_t* man, ap_dimension_t dimension, ap_texpr0_t* expr) { ap_dim_t dim = ap_abstract0_check_texpr_check(dimension,expr); if (dim!=AP_DIM_MAX){ ap_abstract0_check_expr_raise(funid,man,dimension,dim, "incompatible dimension in the tree expression for the abstract value"); return false; } else { return true; } } /* ====================================================================== */ /* 0.5 Checking compatibility of arguments: array of expressions/constraints/generators */ /* ====================================================================== */ /* Check that array of linear expressions makes sense in the given dimensionality */ bool ap_abstract0_check_linexpr_array(ap_funid_t funid, ap_manager_t* man, ap_dimension_t dimension, ap_linexpr0_t** texpr, size_t size) { size_t i; for (i=0;isize; i++){ if (array->p[i].linexpr0==NULL){ char str[80]; sprintf(str,"null pointer in the %luth constraint of the array",(unsigned long)i); ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, funid,str); return false; } ap_dim_t dim = ap_abstract0_check_linexpr_check(dimension,array->p[i].linexpr0); if (dim!=AP_DIM_MAX){ char str[80]; sprintf(str,"incompatible dimension in the %luth constraint of the array",(unsigned long)i); ap_abstract0_check_expr_raise(funid,man,dimension,dim,str); return false; } } return true; } /* Check that array of generator makes sense in the given dimensionality */ bool ap_abstract0_check_generator_array(ap_funid_t funid, ap_manager_t* man, ap_dimension_t dimension, ap_generator0_array_t* array) { size_t i; for (i=0;isize; i++){ if (array->p[i].linexpr0==NULL){ char str[80]; sprintf(str,"null pointer in the %luth generator of the array",(unsigned long)i); ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, funid,str); return false; } ap_dim_t dim = ap_abstract0_check_linexpr_check(dimension,array->p[i].linexpr0); if (dim!=AP_DIM_MAX){ char str[80]; sprintf(str,"incompatible dimension in the %luth generator of the array",(unsigned long)i); ap_abstract0_check_expr_raise(funid,man,dimension,dim,str); return false; } } return true; } /* Check that array of tree expressions makes sense in the given dimensionality */ bool ap_abstract0_check_texpr_array(ap_funid_t funid, ap_manager_t* man, ap_dimension_t dimension, ap_texpr0_t** texpr, size_t size) { size_t i; for (i=0;isize; i++){ if (array->p[i].texpr0==NULL){ char str[80]; sprintf(str,"null pointer in the %luth constraint of the array",(unsigned long)i); ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, funid,str); return false; } ap_dim_t dim = ap_abstract0_check_texpr_check(dimension,array->p[i].texpr0); if (dim!=AP_DIM_MAX){ char str[80]; sprintf(str,"incompatible dimension in the %luth constraint of the array",(unsigned long)i); ap_abstract0_check_expr_raise(funid,man,dimension,dim,str); return false; } } return true; } /* ====================================================================== */ /* 0.6 Checking compatibility of arguments: dimchange */ /* ====================================================================== */ bool ap_abstract0_check_ap_dimchange_add(ap_funid_t funid, ap_manager_t* man, ap_dimension_t dimension, ap_dimchange_t* dimchange) { size_t i,size; bool res = true; /* Check consistency between intdim and the dimensions in the array */ for (i=0; iintdim; i++){ if (dimchange->dim[i]>dimension.intdim){ res = false; break; } } size = dimchange->intdim+dimchange->realdim; if (res && size>0){ /* Check sortedness */ ap_dim_t dim = 0; for (i=1; idimchange->dim[i]){ res = false; break; } else { dim = dimchange->dim[i]; } } res = res && dimchange->dim[size-1]<=dimension.intdim+dimension.realdim; } if (!res){ ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, funid, "dimchange->dim is not sorted or is inconsistent wrt dimchange->intdim or abstract0"); } return res; } bool ap_abstract0_check_ap_dimchange_remove(ap_funid_t funid, ap_manager_t* man, ap_dimension_t dimension, ap_dimchange_t* dimchange) { size_t i,size; bool res = true; /* Check consistency between intdim and the dimensions in the array */ for (i=0; iintdim; i++){ if (dimchange->dim[i]>=dimension.intdim){ res = false; break; } } size = dimchange->intdim+dimchange->realdim; if (res && size>0){ /* Check sortedness */ ap_dim_t dim = 0; for (i=1; iintdim+dimchange->realdim; i++){ if (dim>=dimchange->dim[i]){ res = false; break; } else { dim = dimchange->dim[i]; } } res = res && dimchange->dim[size-1]dim is not sorted, contains duplicatas, or is inconsistent wrt dimchange->intdim or abstract0"); } return res; } bool ap_abstract0_check_dimperm(ap_funid_t funid, ap_manager_t* man, ap_dimension_t dimension, ap_dimperm_t* perm) { size_t i; size_t size = dimension.intdim+dimension.realdim; bool res = (dimension.intdim+dimension.realdim==perm->size); if (res){ for (i=0; isize; i++){ if (perm->dim[i]>=size){ res = false; break; } } } if (!res){ ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, funid, "permutation is not valid"); } return res; } /* ********************************************************************** */ /* I. General management */ /* ********************************************************************** */ /* ============================================================ */ /* I.1 Memory */ /* ============================================================ */ ap_abstract0_t* ap_abstract0_copy(ap_manager_t* man, ap_abstract0_t* a) { if (ap_abstract0_checkman1(AP_FUNID_COPY,man,a)){ void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_COPY]; return ap_abstract0_cons(man,ptr(man,a->value)); } else { ap_dimension_t dimension = _ap_abstract0_dimension(a); return ap_abstract0_top(man, dimension.intdim, dimension.realdim); } } void ap_abstract0_free(ap_manager_t* man, ap_abstract0_t* a) { if (a->man==NULL){ fprintf(stderr,"ap_abstract0_c: ap_abstract0_free: the abstract value has probably already been deallocated !\n"); abort(); } if (ap_abstract0_checkman1(AP_FUNID_FREE,man,a)){ void (*ptr)(ap_manager_t*,ap_abstract0_t*) = man->funptr[AP_FUNID_FREE]; ptr(man,a->value); } else { void (*ptr)(ap_manager_t*,ap_abstract0_t*) = a->man->funptr[AP_FUNID_FREE]; ptr(a->man,a->value); } ap_manager_free(a->man); a->man = NULL; a->value = NULL; free(a); } size_t ap_abstract0_size(ap_manager_t* man, ap_abstract0_t* a) { if (ap_abstract0_checkman1(AP_FUNID_ASIZE,man,a)){ size_t (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_ASIZE]; return ptr(man,a->value); } else { return 0; } } /* ============================================================ */ /* I.2 Control of internal representation */ /* ============================================================ */ void ap_abstract0_minimize(ap_manager_t* man, ap_abstract0_t* a) { if (ap_abstract0_checkman1(AP_FUNID_MINIMIZE,man,a)){ void (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_MINIMIZE]; ptr(man,a->value); } } void ap_abstract0_canonicalize(ap_manager_t* man, ap_abstract0_t* a) { if (ap_abstract0_checkman1(AP_FUNID_CANONICALIZE,man,a)){ void (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_CANONICALIZE]; ptr(man,a->value); } } int ap_abstract0_hash(ap_manager_t* man, ap_abstract0_t* a) { if (ap_abstract0_checkman1(AP_FUNID_CANONICALIZE,man,a)){ int (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_HASH]; return ptr(man,a->value); } else return 0; } void ap_abstract0_approximate(ap_manager_t* man, ap_abstract0_t* a, int n) { if (ap_abstract0_checkman1(AP_FUNID_APPROXIMATE,man,a)){ void (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_APPROXIMATE]; ptr(man,a->value,n); } } /* ============================================================ */ /* I.3 Printing */ /* ============================================================ */ void ap_abstract0_fprint(FILE* stream, ap_manager_t* man, ap_abstract0_t* a, char** name_of_dim) { if (ap_abstract0_checkman1(AP_FUNID_FPRINT,man,a)){ void (*ptr)(FILE*,ap_manager_t*,...) = man->funptr[AP_FUNID_FPRINT]; ptr(stream,man,a->value,name_of_dim); } else { fprintf(stream,"ap_abstract0_c: ap_abstract0_fprint: INVALID_ARGUMENT\n"); } } void ap_abstract0_fprintdiff(FILE* stream, ap_manager_t* man, ap_abstract0_t* a, ap_abstract0_t* b, char** name_of_dim) { if (ap_abstract0_checkman2(AP_FUNID_FPRINTDIFF,man,a,b) && ap_abstract0_check_abstract2(AP_FUNID_FPRINTDIFF,man,a,b) ){ void (*ptr)(FILE*,ap_manager_t*,...) = man->funptr[AP_FUNID_FPRINTDIFF]; ptr(stream,man,a->value,b->value,name_of_dim); } else { fprintf(stream,"ap_abstract0_c: ap_abstract0_fprintdiff: INVALID ARGUMENT\n"); } } void ap_abstract0_fdump(FILE* stream, ap_manager_t* man, ap_abstract0_t* a) { if (ap_abstract0_checkman1(AP_FUNID_FDUMP,man,a)){ void (*ptr)(FILE*,ap_manager_t*,...) = man->funptr[AP_FUNID_FDUMP]; ptr(stream,man,a->value); } else { fprintf(stream,"ap_abstract0_c: ap_abstract0_fdump: INVALID_ARGUMENT\n"); } } /* ============================================================ */ /* I.4 Serialization */ /* ============================================================ */ ap_membuf_t ap_abstract0_serialize_raw(ap_manager_t* man, ap_abstract0_t* a) { if (ap_abstract0_checkman1(AP_FUNID_SERIALIZE_RAW,man,a)){ ap_membuf_t (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_SERIALIZE_RAW]; return ptr(man,a->value); } else { ap_membuf_t res = { NULL, 0 }; return res; } } ap_abstract0_t* ap_abstract0_deserialize_raw(ap_manager_t* man, void* p, size_t* size) { void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_DESERIALIZE_RAW]; return ap_abstract0_cons(man,ptr(man,p,size)); } /* ********************************************************************** */ /* II. Constructor, accessors, tests and property extraction */ /* ********************************************************************** */ /* ============================================================ */ /* II.1 Basic constructors */ /* ============================================================ */ ap_abstract0_t* ap_abstract0_bottom(ap_manager_t* man, size_t intdim, size_t realdim) { void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_BOTTOM]; return ap_abstract0_cons(man,ptr(man,intdim,realdim)); } ap_abstract0_t* ap_abstract0_top(ap_manager_t* man, size_t intdim, size_t realdim){ void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_TOP]; return ap_abstract0_cons(man,ptr(man,intdim,realdim)); } ap_abstract0_t* ap_abstract0_of_box(ap_manager_t* man, size_t intdim, size_t realdim, ap_interval_t** tinterval){ void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_OF_BOX]; return ap_abstract0_cons(man,ptr(man,intdim,realdim,tinterval)); } /* ============================================================ */ /* II.2 Accessors */ /* ============================================================ */ ap_dimension_t ap_abstract0_dimension(ap_manager_t* man, ap_abstract0_t* a) { ap_abstract0_checkman1(AP_FUNID_DIMENSION,man,a); ap_dimension_t (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_DIMENSION]; return ptr(a->man,a->value); } /* ============================================================ */ /* II.3 Tests */ /* ============================================================ */ bool ap_abstract0_is_bottom(ap_manager_t* man, ap_abstract0_t* a) { if (ap_abstract0_checkman1(AP_FUNID_IS_BOTTOM,man,a)){ bool (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_BOTTOM]; return ptr(man,a->value); } else { man->result.flag_exact = false; return false; } } bool ap_abstract0_is_top(ap_manager_t* man, ap_abstract0_t* a) { if (ap_abstract0_checkman1(AP_FUNID_IS_TOP,man,a)){ bool (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_TOP]; return ptr(man,a->value); } else { man->result.flag_exact = false; return false; } } bool ap_abstract0_is_leq(ap_manager_t* man, ap_abstract0_t* a1, ap_abstract0_t* a2) { if (a1==a2){ return true; } else if (ap_abstract0_checkman2(AP_FUNID_IS_LEQ,man,a1,a2) && ap_abstract0_check_abstract2(AP_FUNID_IS_EQ,man,a1,a2)){ if (a1->value==a2->value) return true; bool (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_LEQ]; return ptr(man,a1->value,a2->value); } else { man->result.flag_exact = false; return false; } } bool ap_abstract0_is_eq(ap_manager_t* man, ap_abstract0_t* a1, ap_abstract0_t* a2) { if (a1==a2){ return true; } if (ap_abstract0_checkman2(AP_FUNID_IS_EQ,man,a1,a2) && ap_abstract0_check_abstract2(AP_FUNID_IS_EQ,man,a1,a2)){ if (a1->value==a2->value) return true; bool (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_EQ]; return ptr(man,a1->value,a2->value); } else { man->result.flag_exact = false; return false; } } bool ap_abstract0_sat_lincons(ap_manager_t* man, ap_abstract0_t* a, ap_lincons0_t* lincons) { if (ap_abstract0_checkman1(AP_FUNID_SAT_LINCONS,man,a) && ap_abstract0_check_linexpr(AP_FUNID_SAT_LINCONS,man,_ap_abstract0_dimension(a),lincons->linexpr0) ){ bool (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_SAT_LINCONS]; return ptr(man,a->value,lincons); } else { man->result.flag_exact = false; return false; } } bool ap_abstract0_sat_tcons(ap_manager_t* man, ap_abstract0_t* a, ap_tcons0_t* tcons) { if (ap_abstract0_checkman1(AP_FUNID_SAT_TCONS,man,a) && ap_abstract0_check_texpr(AP_FUNID_SAT_TCONS,man,_ap_abstract0_dimension(a),tcons->texpr0) ){ bool (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_SAT_TCONS]; return ptr(man,a->value,tcons); } else { man->result.flag_exact = false; return false; } } bool ap_abstract0_sat_interval(ap_manager_t* man, ap_abstract0_t* a, ap_dim_t dim, ap_interval_t* interval) { if (ap_abstract0_checkman1(AP_FUNID_SAT_INTERVAL,man,a) && ap_abstract0_check_dim(AP_FUNID_SAT_INTERVAL,man,_ap_abstract0_dimension(a),dim)){ bool (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_SAT_INTERVAL]; return ptr(man,a->value,dim,interval); } else { man->result.flag_exact = false; return false; } } bool ap_abstract0_is_dimension_unconstrained(ap_manager_t* man, ap_abstract0_t* a, ap_dim_t dim) { if (ap_abstract0_checkman1(AP_FUNID_IS_DIMENSION_UNCONSTRAINED,man,a) && ap_abstract0_check_dim(AP_FUNID_IS_DIMENSION_UNCONSTRAINED,man,_ap_abstract0_dimension(a),dim)){ bool (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_IS_DIMENSION_UNCONSTRAINED]; return ptr(man,a->value,dim); } else { man->result.flag_exact = false; return false; } } /* ============================================================ */ /* II.4 Extraction of properties */ /* ============================================================ */ ap_interval_t* ap_abstract0_bound_linexpr(ap_manager_t* man, ap_abstract0_t* a, ap_linexpr0_t* expr) { if (ap_abstract0_checkman1(AP_FUNID_BOUND_LINEXPR,man,a) && ap_abstract0_check_linexpr(AP_FUNID_BOUND_LINEXPR,man,_ap_abstract0_dimension(a),expr)){ ap_interval_t* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_BOUND_LINEXPR]; return ptr(man,a->value,expr); } else { ap_interval_t* itv = ap_interval_alloc(); ap_interval_reinit(itv,man->option.scalar_discr); ap_interval_set_top(itv); return itv; } } ap_interval_t* ap_abstract0_bound_texpr(ap_manager_t* man, ap_abstract0_t* a, ap_texpr0_t* expr) { if (ap_abstract0_checkman1(AP_FUNID_BOUND_TEXPR,man,a) && ap_abstract0_check_texpr(AP_FUNID_BOUND_TEXPR,man,_ap_abstract0_dimension(a),expr)){ ap_interval_t* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_BOUND_TEXPR]; return ptr(man,a->value,expr); } else { ap_interval_t* itv = ap_interval_alloc(); ap_interval_reinit(itv,man->option.scalar_discr); ap_interval_set_top(itv); return itv; } } ap_interval_t* ap_abstract0_bound_dimension(ap_manager_t* man, ap_abstract0_t* a, ap_dim_t dim) { if (ap_abstract0_checkman1(AP_FUNID_BOUND_DIMENSION,man,a) && ap_abstract0_check_dim(AP_FUNID_BOUND_DIMENSION,man,_ap_abstract0_dimension(a),dim)){ ap_interval_t* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_BOUND_DIMENSION]; return ptr(man,a->value,dim); } else { ap_interval_t* itv = ap_interval_alloc(); ap_interval_reinit(itv,man->option.scalar_discr); ap_interval_set_top(itv); return itv; } } ap_lincons0_array_t ap_abstract0_to_lincons_array(ap_manager_t* man, ap_abstract0_t* a) { if (ap_abstract0_checkman1(AP_FUNID_TO_LINCONS_ARRAY,man,a)){ ap_lincons0_array_t (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_TO_LINCONS_ARRAY]; return ptr(man,a->value); } else { ap_lincons0_array_t res = { NULL, 0 }; return res; } } ap_tcons0_array_t ap_abstract0_to_tcons_array(ap_manager_t* man, ap_abstract0_t* a) { if (ap_abstract0_checkman1(AP_FUNID_TO_TCONS_ARRAY,man,a)){ ap_tcons0_array_t (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_TO_TCONS_ARRAY]; return ptr(man,a->value); } else { ap_tcons0_array_t res = { NULL, 0 }; return res; } } ap_interval_t** ap_abstract0_to_box(ap_manager_t* man, ap_abstract0_t* a) { if (ap_abstract0_checkman1(AP_FUNID_TO_BOX,man,a)){ ap_interval_t** (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_TO_BOX]; return ptr(man,a->value); } else { size_t i; ap_dimension_t d = _ap_abstract0_dimension(a); ap_interval_t** titv = ap_interval_array_alloc(d.intdim+d.realdim); for (i=0; ioption.scalar_discr); ap_interval_set_top(titv[i]); } return titv; } } ap_generator0_array_t ap_abstract0_to_generator_array(ap_manager_t* man, ap_abstract0_t* a) { if (ap_abstract0_checkman1(AP_FUNID_TO_GENERATOR_ARRAY,man,a)){ ap_generator0_array_t (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_TO_GENERATOR_ARRAY]; return ptr(man,a->value); } else { ap_generator0_array_t res = { NULL, 0 }; return res; } } /* ********************************************************************** */ /* III. Operations */ /* ********************************************************************** */ /* ============================================================ */ /* III.1 Meet and Join */ /* ============================================================ */ ap_abstract0_t* ap_abstract0_meetjoin(ap_funid_t funid, ap_manager_t* man, bool destructive, ap_abstract0_t* a1, ap_abstract0_t* a2) { if (ap_abstract0_checkman2(funid,man,a1,a2) && ap_abstract0_check_abstract2(funid,man,a1,a2)){ void* (*ptr)(ap_manager_t*,...) = man->funptr[funid]; void* value = ptr(man,destructive,a1->value,a2->value); return ap_abstract0_cons2(man,destructive,a1,value); } else { ap_dimension_t dimension = _ap_abstract0_dimension(a1); if (destructive) _ap_abstract0_free(a1); return ap_abstract0_top(man, dimension.intdim, dimension.realdim); } } ap_abstract0_t* ap_abstract0_meet(ap_manager_t* man, bool destructive, ap_abstract0_t* a1, ap_abstract0_t* a2){ return ap_abstract0_meetjoin(AP_FUNID_MEET,man,destructive,a1,a2); } ap_abstract0_t* ap_abstract0_join(ap_manager_t* man, bool destructive, ap_abstract0_t* a1, ap_abstract0_t* a2){ return ap_abstract0_meetjoin(AP_FUNID_JOIN,man,destructive,a1,a2); } ap_abstract0_t* ap_abstract0_meetjoin_array(ap_funid_t funid, ap_manager_t* man, ap_abstract0_t** tab, size_t size) { if (ap_abstract0_checkman_array(funid,man,tab,size) && ap_abstract0_check_abstract_array(funid,man,tab,size)){ size_t i; ap_abstract0_t* res; void* (*ptr)(ap_manager_t*,...) = man->funptr[funid]; void** ntab = malloc(size*sizeof(void*)); for (i=0;ivalue; res = ap_abstract0_cons(man,ptr(man,ntab,size)); free(ntab); return res; } else { ap_dimension_t dimension = { 0, 0}; if (size>0){ dimension = _ap_abstract0_dimension(tab[0]); } return ap_abstract0_top(man, dimension.intdim, dimension.realdim); } } ap_abstract0_t* ap_abstract0_meet_array(ap_manager_t* man, ap_abstract0_t** tab, size_t size){ return ap_abstract0_meetjoin_array(AP_FUNID_MEET_ARRAY,man,tab,size); } ap_abstract0_t* ap_abstract0_join_array(ap_manager_t* man, ap_abstract0_t** tab, size_t size){ return ap_abstract0_meetjoin_array(AP_FUNID_JOIN_ARRAY,man,tab,size); } ap_abstract0_t* ap_abstract0_meet_lincons_array(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_lincons0_array_t* array) { ap_dimension_t dimension = _ap_abstract0_dimension(a); if (ap_abstract0_checkman1(AP_FUNID_MEET_LINCONS_ARRAY,man,a) && ap_abstract0_check_lincons_array(AP_FUNID_MEET_LINCONS_ARRAY,man,dimension,array) ){ void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_MEET_LINCONS_ARRAY]; void* value = ptr(man,destructive,a->value,array); return ap_abstract0_cons2(man,destructive,a,value); } else { if (destructive) _ap_abstract0_free(a); return ap_abstract0_top(man, dimension.intdim, dimension.realdim); } } ap_abstract0_t* ap_abstract0_meet_tcons_array(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_tcons0_array_t* array) { ap_dimension_t dimension = _ap_abstract0_dimension(a); if (ap_abstract0_checkman1(AP_FUNID_MEET_TCONS_ARRAY,man,a) && ap_abstract0_check_tcons_array(AP_FUNID_MEET_TCONS_ARRAY,man,dimension,array) ){ void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_MEET_TCONS_ARRAY]; void* value = ptr(man,destructive,a->value,array); return ap_abstract0_cons2(man,destructive,a,value); } else { if (destructive) _ap_abstract0_free(a); return ap_abstract0_top(man, dimension.intdim, dimension.realdim); } } ap_abstract0_t* ap_abstract0_add_ray_array(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_generator0_array_t* array) { ap_dimension_t dimension = _ap_abstract0_dimension(a); if (ap_abstract0_checkman1(AP_FUNID_ADD_RAY_ARRAY,man,a) && ap_abstract0_check_generator_array(AP_FUNID_ADD_RAY_ARRAY,man,dimension,array)){ void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_ADD_RAY_ARRAY]; void* value = ptr(man,destructive,a->value,array); return ap_abstract0_cons2(man,destructive,a,value); } else { if (destructive) _ap_abstract0_free(a); return ap_abstract0_top(man, dimension.intdim, dimension.realdim); } } /* ============================================================ */ /* III.2 Assignment and Substitutions */ /* ============================================================ */ ap_abstract0_t* ap_abstract0_asssub_linexpr_array(ap_funid_t funid, ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, ap_abstract0_t* dest) { if (size==0){ if (dest){ return ap_abstract0_meet(man,destructive,a,dest); } else if (destructive){ return a; } else { return ap_abstract0_copy(man,a); } } else { ap_dimension_t dimension = _ap_abstract0_dimension(a); if (ap_abstract0_checkman1(funid,man,a) && (dest!=NULL ? (ap_abstract0_checkman1(funid,man,dest) && ap_abstract0_check_abstract2(funid,man,a,dest)) : true) && ap_abstract0_check_dim_array(funid,man,dimension,tdim,size) && ap_abstract0_check_linexpr_array(funid,man,dimension,texpr,size) ){ void* (*ptr)(ap_manager_t*,...) = man->funptr[funid]; void* value = ptr(man,destructive,a->value,tdim,texpr,size,dest ? dest->value : NULL); return ap_abstract0_cons2(man,destructive,a,value); } else { if (destructive) _ap_abstract0_free(a); return ap_abstract0_top(man, dimension.intdim, dimension.realdim); } } } ap_abstract0_t* ap_abstract0_assign_linexpr_array(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, ap_abstract0_t* dest) { return ap_abstract0_asssub_linexpr_array(AP_FUNID_ASSIGN_LINEXPR_ARRAY, man,destructive,a,tdim,texpr,size,dest); } ap_abstract0_t* ap_abstract0_substitute_linexpr_array(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dim_t* tdim, ap_linexpr0_t** texpr, size_t size, ap_abstract0_t* dest) { return ap_abstract0_asssub_linexpr_array(AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY, man,destructive,a,tdim,texpr,size,dest); } ap_abstract0_t* ap_abstract0_asssub_texpr_array(ap_funid_t funid, ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, ap_abstract0_t* dest) { if (size==0){ if (dest){ return ap_abstract0_meet(man,destructive,a,dest); } else if (destructive){ return a; } else { return ap_abstract0_copy(man,a); } } else { ap_dimension_t dimension = _ap_abstract0_dimension(a); if (ap_abstract0_checkman1(funid,man,a) && (dest!=NULL ? (ap_abstract0_checkman1(funid,man,dest) && ap_abstract0_check_abstract2(funid,man,a,dest)) : true) && ap_abstract0_check_dim_array(funid,man,dimension,tdim,size) && ap_abstract0_check_texpr_array(funid,man,dimension,texpr,size) ){ void* (*ptr)(ap_manager_t*,...) = man->funptr[funid]; void* value = ptr(man,destructive,a->value,tdim,texpr,size,dest ? dest->value : NULL); return ap_abstract0_cons2(man,destructive,a,value); } else { if (destructive) _ap_abstract0_free(a); return ap_abstract0_top(man, dimension.intdim, dimension.realdim); } } } ap_abstract0_t* ap_abstract0_assign_texpr_array(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, ap_abstract0_t* dest) { return ap_abstract0_asssub_texpr_array(AP_FUNID_ASSIGN_TEXPR_ARRAY, man,destructive,a,tdim,texpr,size,dest); } ap_abstract0_t* ap_abstract0_substitute_texpr_array(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dim_t* tdim, ap_texpr0_t** texpr, size_t size, ap_abstract0_t* dest) { return ap_abstract0_asssub_texpr_array(AP_FUNID_SUBSTITUTE_TEXPR_ARRAY, man,destructive,a,tdim,texpr,size,dest); } /* ============================================================ */ /* III.3 Projections */ /* ============================================================ */ ap_abstract0_t* ap_abstract0_forget_array(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dim_t* tdim, size_t size, bool project) { if (size==0){ if (destructive){ return a; } else { return ap_abstract0_copy(man,a); } } else { ap_dimension_t dimension = _ap_abstract0_dimension(a); if (ap_abstract0_checkman1(AP_FUNID_FORGET_ARRAY,man,a) && ap_abstract0_check_dim_array(AP_FUNID_FORGET_ARRAY,man,dimension,tdim,size)){ void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_FORGET_ARRAY]; void* value = ptr(man,destructive,a->value,tdim,size,project); return ap_abstract0_cons2(man,destructive,a,value); } else { if (destructive) _ap_abstract0_free(a); return ap_abstract0_top(man, dimension.intdim, dimension.realdim); } } } /* ============================================================ */ /* III.4 Change and permutation of dimensions */ /* ============================================================ */ ap_abstract0_t* ap_abstract0_add_dimensions(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dimchange_t* dimchange, bool project) { if (dimchange->intdim+dimchange->realdim==0){ if (destructive){ return a; } else { return ap_abstract0_copy(man,a); } } else { ap_dimension_t dimension = _ap_abstract0_dimension(a); if (ap_abstract0_checkman1(AP_FUNID_ADD_DIMENSIONS,man,a) && ap_abstract0_check_ap_dimchange_add(AP_FUNID_ADD_DIMENSIONS,man,dimension,dimchange)){ void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_ADD_DIMENSIONS]; void* value = ptr(man,destructive,a->value,dimchange,project); return ap_abstract0_cons2(man,destructive,a,value); } else { if (destructive) _ap_abstract0_free(a); return ap_abstract0_top(man, dimension.intdim+dimchange->intdim, dimension.realdim+dimchange->realdim); } } } ap_abstract0_t* ap_abstract0_remove_dimensions(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dimchange_t* dimchange) { if (dimchange->intdim+dimchange->realdim==0){ if (destructive){ return a; } else { return ap_abstract0_copy(man,a); } } else { ap_dimension_t dimension = _ap_abstract0_dimension(a); if (ap_abstract0_checkman1(AP_FUNID_REMOVE_DIMENSIONS,man,a) && ap_abstract0_check_ap_dimchange_remove(AP_FUNID_REMOVE_DIMENSIONS,man,dimension,dimchange)){ void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_REMOVE_DIMENSIONS]; void* value = ptr(man,destructive,a->value,dimchange); return ap_abstract0_cons2(man,destructive,a,value); } else { if (destructive) _ap_abstract0_free(a); return ap_abstract0_top(man, dimension.intdim>=dimchange->intdim ? dimension.intdim-dimchange->intdim : 0, dimension.realdim>=dimchange->realdim ? dimension.realdim-dimchange->realdim : 0); } } } ap_abstract0_t* ap_abstract0_permute_dimensions(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dimperm_t* perm) { ap_dimension_t dimension = _ap_abstract0_dimension(a); if (ap_abstract0_checkman1(AP_FUNID_PERMUTE_DIMENSIONS,man,a) && ap_abstract0_check_dimperm(AP_FUNID_PERMUTE_DIMENSIONS,man,dimension,perm)){ void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_PERMUTE_DIMENSIONS]; void* value = ptr(man,destructive,a->value,perm); return ap_abstract0_cons2(man,destructive,a,value); } else { if (destructive) _ap_abstract0_free(a); return ap_abstract0_top(man, dimension.intdim, dimension.realdim); } } /* ============================================================ */ /* III.5 Expansion and folding of dimensions */ /* ============================================================ */ ap_abstract0_t* ap_abstract0_expand(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dim_t dim, size_t n) { if (n==0){ if (destructive){ return a; } else { return ap_abstract0_copy(man,a); } } else { ap_dimension_t dimension = _ap_abstract0_dimension(a); if (ap_abstract0_checkman1(AP_FUNID_EXPAND,man,a) && ap_abstract0_check_dim(AP_FUNID_EXPAND,man,dimension,dim)){ void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_EXPAND]; void* value = ptr(man,destructive,a->value,dim,n); return ap_abstract0_cons2(man,destructive,a,value); } else { if (destructive) _ap_abstract0_free(a); return ap_abstract0_top(man, dimension.intdim + (dim=tdim[i]){ ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, AP_FUNID_FOLD, "The array of dimension is not sorted"); goto _ap_abstract0_fold_exc; } } if (tdim[0]=dimension.intdim){ ap_manager_raise_exception(man, AP_EXC_INVALID_ARGUMENT, AP_FUNID_FOLD, "Mixed integer and real dimensions in the array"); goto _ap_abstract0_fold_exc; } /* OK now */ if (size==1){ if (destructive){ return a; } else { void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_COPY]; return ap_abstract0_cons(man,ptr(man,a->value)); } } else { void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_FOLD]; void* value = ptr(man,destructive,a->value,tdim,size); return ap_abstract0_cons2(man,destructive,a,value); } } else { _ap_abstract0_fold_exc: if (destructive) _ap_abstract0_free(a); return ap_abstract0_top(man, dimension.intdim - ( (size>0 && tdim[0]0 && tdim[0]funptr[AP_FUNID_WIDENING]; void* value = ptr(man,a1->value,a2->value); return ap_abstract0_cons(man,value); } else { ap_dimension_t dimension = _ap_abstract0_dimension(a1); return ap_abstract0_top(man, dimension.intdim, dimension.realdim); } } /* ============================================================ */ /* III.7 Closure operation */ /* ============================================================ */ ap_abstract0_t* ap_abstract0_closure(ap_manager_t* man, bool destructive, ap_abstract0_t* a) { ap_dimension_t dimension = _ap_abstract0_dimension(a); if (ap_abstract0_checkman1(AP_FUNID_CLOSURE,man,a)){ void* (*ptr)(ap_manager_t*,...) = man->funptr[AP_FUNID_CLOSURE]; void* value = ptr(man,destructive,a->value); return ap_abstract0_cons2(man,destructive,a,value); } else { if (destructive) _ap_abstract0_free(a); return ap_abstract0_top(man, dimension.intdim, dimension.realdim); } } /* ********************************************************************** */ /* IV. Functions offered by the APRON interface */ /* ********************************************************************** */ /* These functions do not correspond to functions in the underlying library. */ /* These two functions implement of_lincons/tcons_array constructors using top and meet_lincons/tcons_array operations. */ ap_abstract0_t* ap_abstract0_of_lincons_array(ap_manager_t* man, size_t intdim, size_t realdim, ap_lincons0_array_t* array) { ap_abstract0_t* res = ap_abstract0_top(man,intdim,realdim); res = ap_abstract0_meet_lincons_array(man,true,res,array); return res; } ap_abstract0_t* ap_abstract0_of_tcons_array(ap_manager_t* man, size_t intdim, size_t realdim, ap_tcons0_array_t* array) { ap_abstract0_t* res = ap_abstract0_top(man,intdim,realdim); res = ap_abstract0_meet_tcons_array(man,true,res,array); return res; } /* These four functions implement assignment and substitution of a single dimension by a single expression. */ ap_abstract0_t* ap_abstract0_assign_linexpr(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dim_t dim, ap_linexpr0_t* expr, ap_abstract0_t* dest) { return ap_abstract0_asssub_linexpr_array(AP_FUNID_ASSIGN_LINEXPR_ARRAY, man,destructive,a,&dim,&expr,1,dest); } ap_abstract0_t* ap_abstract0_substitute_linexpr(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dim_t dim, ap_linexpr0_t* expr, ap_abstract0_t* dest) { return ap_abstract0_asssub_linexpr_array(AP_FUNID_SUBSTITUTE_LINEXPR_ARRAY, man,destructive,a,&dim,&expr,1,dest); } ap_abstract0_t* ap_abstract0_assign_texpr(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dim_t dim, ap_texpr0_t* expr, ap_abstract0_t* dest) { return ap_abstract0_asssub_texpr_array(AP_FUNID_ASSIGN_TEXPR_ARRAY, man,destructive,a,&dim,&expr,1,dest); } ap_abstract0_t* ap_abstract0_substitute_texpr(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dim_t dim, ap_texpr0_t* expr, ap_abstract0_t* dest) { return ap_abstract0_asssub_texpr_array(AP_FUNID_SUBSTITUTE_TEXPR_ARRAY, man,destructive,a,&dim,&expr,1,dest); } /* Applying an ap_dimchange2_t transformation (dimension adding followed by dimension removal/projection). If project is true, the newly added dimension are projected on their 0-hyperplane. */ ap_abstract0_t* ap_abstract0_apply_dimchange2(ap_manager_t* man, bool destructive, ap_abstract0_t* a, ap_dimchange2_t* dimchange2, bool project) { ap_abstract0_t* res; if (dimchange2->add){ res = ap_abstract0_add_dimensions(man,destructive,a,dimchange2->add,project); if (dimchange2->remove){ res = ap_abstract0_remove_dimensions(man,true,res,dimchange2->remove); } } else if (dimchange2->remove){ res = ap_abstract0_remove_dimensions(man,destructive,a,dimchange2->remove); } else { res = destructive ? a : ap_abstract0_copy(man,a); } return res; } /* This function implements widening with threshold, relying on the widening, sat_lincons and meet_lincons_array operations. */ ap_abstract0_t* ap_abstract0_widening_threshold(ap_manager_t* man, ap_abstract0_t* a1, ap_abstract0_t* a2, ap_lincons0_array_t* array) { void* (*ptr)(ap_manager_t*,...); bool (*ptr2)(ap_manager_t*,...); void* value; size_t i,j,size; ap_lincons0_t tmp; ap_dimension_t dimension = _ap_abstract0_dimension(a1); if (ap_abstract0_checkman2(AP_FUNID_WIDENING,man,a1,a2) && ap_abstract0_check_abstract2(AP_FUNID_WIDENING,man,a1,a2) && ap_abstract0_check_lincons_array(AP_FUNID_WIDENING,man,dimension,array) ){ ptr = man->funptr[AP_FUNID_WIDENING]; value = ptr(man,a1->value,a2->value); ptr2 = man->funptr[AP_FUNID_SAT_LINCONS]; size = array->size; i = j = 0; while (ivalue,&array->p[i])){ i++; } else { j++; tmp = array->p[i]; array->p[i] = array->p[array->size-j]; array->p[array->size-j] = tmp; } } if (i>0){ array->size = i; ptr = man->funptr[AP_FUNID_MEET_LINCONS_ARRAY]; value = ptr(man,true,value,array); array->size = size; } return ap_abstract0_cons(man,value); } else { return ap_abstract0_top(man, dimension.intdim, dimension.realdim); } } apron-dist-0.9.10/apron/apron/ap_tcons0.c0000640014525101416610000001156110656607177020060 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_tcons0.c: tree constraints and arrays */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "ap_tcons0.h" /* ********************************************************************** */ /* I. Linear constraints */ /* ********************************************************************** */ void ap_tcons0_fprint(FILE* stream, ap_tcons0_t* cons, char** name_of_dim) { ap_texpr0_fprint(stream,cons->texpr0,name_of_dim); fprintf(stream, cons->constyp == AP_CONS_EQ || cons->constyp == AP_CONS_EQMOD ? " = 0" : ( cons->constyp == AP_CONS_SUPEQ ? " >= 0" : (cons->constyp == AP_CONS_SUP ? " > 0" : "\"ERROR in ap_tcons0_fprint\""))); if (cons->constyp == AP_CONS_EQMOD){ assert(cons->scalar!=NULL); fprintf(stream," mod "); ap_scalar_fprint(stream,cons->scalar); } } ap_tcons0_t ap_tcons0_make_unsat() { ap_texpr0_t* expr; expr = ap_texpr0_cst_scalar_int(-1); return ap_tcons0_make(AP_CONS_SUPEQ,expr,NULL); } /* ********************************************************************** */ /* II. Array of linear constraints */ /* ********************************************************************** */ ap_tcons0_array_t ap_tcons0_array_make(size_t size) { ap_tcons0_array_t array; size_t i; array.size = size; array.p = (size==0) ? NULL : (ap_tcons0_t*)malloc(size*sizeof(ap_tcons0_t)); for (i=0; isize; i++){ ap_tcons0_clear(&array->p[i]); } array->p = (ap_tcons0_t*)realloc(array->p,size*sizeof(ap_tcons0_t)); for (i=array->size; ip[i].texpr0 = NULL; array->p[i].scalar = NULL; } array->size = size; } void ap_tcons0_array_clear(ap_tcons0_array_t* array) { size_t i; if (array->p!=NULL){ for (i=0; isize; i++) ap_tcons0_clear(&array->p[i]); free(array->p); array->p=NULL; } } void ap_tcons0_array_fprint(FILE* stream, ap_tcons0_array_t* array, char** name_of_dim) { size_t i; if (array->size==0){ fprintf(stream,"empty array of constraints\n"); } else { fprintf(stream,"array of constraints of size %lu\n", (unsigned long)array->size); for (i=0; isize; i++){ fprintf(stream,"%2lu: ",(unsigned long)i); ap_tcons0_fprint(stream,&array->p[i],name_of_dim); fprintf(stream,"\n"); } } } bool ap_tcons0_array_is_interval_linear(ap_tcons0_array_t* array) { size_t i; bool res = true; for (i=0; isize; i++){ if (!ap_texpr0_is_interval_linear(array->p[i].texpr0)){ res = false; break; } } return res; } /* ====================================================================== */ /* II.1 Change of dimensions and permutations */ /* ====================================================================== */ void ap_tcons0_array_add_dimensions_with(ap_tcons0_array_t* array, ap_dimchange_t* dimchange) { size_t i; for(i=0; isize; i++){ ap_texpr0_t* expr = array->p[i].texpr0; if (expr) ap_texpr0_add_dimensions_with(expr,dimchange); } } ap_tcons0_array_t ap_tcons0_array_add_dimensions(ap_tcons0_array_t* array, ap_dimchange_t* dimchange) { size_t i; ap_tcons0_array_t narray; narray = ap_tcons0_array_make(array->size); for(i=0; isize; i++){ narray.p[i] = ap_tcons0_add_dimensions(&array->p[i],dimchange); } return narray; } void ap_tcons0_array_remove_dimensions_with(ap_tcons0_array_t* array, ap_dimchange_t* dimchange) { size_t i; for(i=0; isize; i++){ ap_texpr0_t* expr = array->p[i].texpr0; if (expr) ap_texpr0_remove_dimensions_with(expr,dimchange); } } ap_tcons0_array_t ap_tcons0_array_remove_dimensions(ap_tcons0_array_t* array, ap_dimchange_t* dimchange) { size_t i; ap_tcons0_array_t narray; narray = ap_tcons0_array_make(array->size); for(i=0; isize; i++){ narray.p[i] = ap_tcons0_remove_dimensions(&array->p[i],dimchange); } return narray; } void ap_tcons0_array_permute_dimensions_with(ap_tcons0_array_t* array, ap_dimperm_t* perm) { size_t i; for(i=0; isize; i++){ ap_texpr0_t* expr = array->p[i].texpr0; if (expr) ap_texpr0_permute_dimensions_with(expr,perm); } } ap_tcons0_array_t ap_tcons0_array_permute_dimensions(ap_tcons0_array_t* array, ap_dimperm_t* perm) { size_t i; ap_tcons0_array_t narray; narray = ap_tcons0_array_make(array->size); for(i=0; isize; i++){ narray.p[i] = ap_tcons0_permute_dimensions(&array->p[i],perm); } return narray; } apron-dist-0.9.10/apron/apron/ap_var.c0000640014525101416610000000214110760562320017416 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_var.c: generic variables */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include "ap_manager.h" #include "ap_var.h" static int var_compare_default(void* v1, void* v2){ return (v1==v2) ? 0 : strcmp((char*)v1,(char*)v2); } static int var_hash_default(void* v){ unsigned char* c; int res = 0; for (c=(unsigned char*)v; (*c)!=0; c++){ res = res * 11 + (*c); } return res; } static void* var_copy_default(void* v){ return strdup((char*)v); } static void var_free_default(void* v){ free(v); } static char* var_to_string_default(void* v){ return strdup((char*)v); } struct ap_var_operations_t ap_var_operations_default = { var_compare_default, var_hash_default, var_copy_default, var_free_default, var_to_string_default }; ap_var_operations_t* ap_var_operations = &ap_var_operations_default; apron-dist-0.9.10/apron/apron/ap_dimension.c0000640014525101416610000001017011224615255020616 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_dimension.c: dimensions and related operations */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include "ap_dimension.h" /* ====================================================================== */ /* ap_dimchange_t */ /* ====================================================================== */ /* Allocating a transformation */ void ap_dimchange_init(ap_dimchange_t* dimchange, size_t intdim, size_t realdim) { dimchange->dim = intdim+realdim==0 ? NULL : malloc((intdim+realdim)*sizeof(ap_dim_t)); dimchange->intdim = intdim; dimchange->realdim = realdim; } ap_dimchange_t* ap_dimchange_alloc(size_t intdim, size_t realdim) { ap_dimchange_t* res = malloc(sizeof(ap_dimchange_t)); ap_dimchange_init(res,intdim,realdim); return res; } /* Printing a transformation */ void ap_dimchange_fprint(FILE* stream, ap_dimchange_t* dimchange) { size_t i; fprintf(stream,"dimchange: intdim=%lu, realdim=%lu\n ", (unsigned long)dimchange->intdim, (unsigned long)dimchange->realdim); for (i=0;iintdim+dimchange->realdim;i++){ fprintf(stream,"%2lu ",(unsigned long)dimchange->dim[i]); } fprintf(stream,"\n"); } /* Inverting in-place an adding transformation from the given dimensionality */ void ap_dimchange_add_invert(ap_dimchange_t* dimchange) { size_t i; for (i=0;iintdim+dimchange->realdim; i++){ dimchange->dim[i] += i; } } /* ====================================================================== */ /* ap_dimchange2_t */ /* ====================================================================== */ /* Clear a dimchange structure (deallocate internal arrays) */ void ap_dimchange2_clear(ap_dimchange2_t* dimchange2) { if (dimchange2->add){ ap_dimchange_free(dimchange2->add); dimchange2->add = NULL; } if (dimchange2->remove){ ap_dimchange_free(dimchange2->remove); dimchange2->remove = NULL; } } /* Deallocate and clear a dimchange2 structure */ void ap_dimchange2_free(ap_dimchange2_t* dimchange2) { ap_dimchange2_clear(dimchange2); free(dimchange2); } /* Printing */ void ap_dimchange2_fprint(FILE* stream, ap_dimchange2_t* dimchange2) { fprintf(stream,"add: "); if (dimchange2->add){ ap_dimchange_fprint(stream,dimchange2->add); } else { fprintf(stream,"NULL\n"); } fprintf(stream,"remove: "); if (dimchange2->remove){ ap_dimchange_fprint(stream,dimchange2->remove); } else { fprintf(stream,"NULL\n"); } } /* ====================================================================== */ /* ap_dimperm_t */ /* ====================================================================== */ /* Allocating a permutation */ void ap_dimperm_init(ap_dimperm_t* dimperm, size_t size) { dimperm->dim = size==0 ? NULL : malloc(size*sizeof(ap_dim_t)); dimperm->size = size; } ap_dimperm_t* ap_dimperm_alloc(size_t size) { ap_dimperm_t* dimperm = malloc(sizeof(ap_dimperm_t)); ap_dimperm_init(dimperm,size); return dimperm; } /* Printing a permutation */ void ap_dimperm_fprint(FILE* stream, ap_dimperm_t* perm) { size_t i; fprintf(stream,"dimperm: size=%lu\n",(unsigned long)perm->size); for (i=0;isize;i++){ fprintf(stream,"%2lu -> %2lu\n",(unsigned long)i, (unsigned long)perm->dim[i]); } } /* Generates the identity permutation */ void ap_dimperm_set_id(ap_dimperm_t* perm) { size_t i; for (i=0; isize; i++) perm->dim[i] = i; } /* Compose 2 permutations */ void ap_dimperm_compose(ap_dimperm_t* perm, ap_dimperm_t* perm1, ap_dimperm_t* perm2) { size_t i; assert(perm->size==perm1->size && perm->size==perm2->size); for (i=0; isize; i++){ perm->dim[i] = perm2->dim[perm1->dim[i]]; } } /* Invert a permutation */ void ap_dimperm_invert(ap_dimperm_t* nperm, ap_dimperm_t* perm) { size_t i; assert(nperm->size==perm->size); for (i=0; isize; i++){ nperm->dim[perm->dim[i]] = i; } } apron-dist-0.9.10/apron/apron/ap_linexpr0.h0000640014525101416610000004241211122224307020372 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_linexpr0.h: linear expressions */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ /* normally included from ap_expr0.h */ #ifndef _AP_LINEXPR0_H_ #define _AP_LINEXPR0_H_ #include #include #include #include #include #include "ap_coeff.h" #include "ap_dimension.h" #ifdef __cplusplus extern "C" { #endif /* ====================================================================== */ /* Datatypes */ /* ====================================================================== */ /* Discriminant for dense or sparse representation */ typedef enum ap_linexpr_discr_t { AP_LINEXPR_DENSE, AP_LINEXPR_SPARSE } ap_linexpr_discr_t; /* A term, for use in sparse representation */ /* Meant to be an abstract datatype ! */ typedef struct ap_linterm_t { ap_dim_t dim; ap_coeff_t coeff; } ap_linterm_t; /* A linear expression. */ /* Meant to be an abstract datatype ! */ typedef struct ap_linexpr0_t { ap_coeff_t cst; /* constant */ ap_linexpr_discr_t discr; /* discriminant for array */ size_t size; /* size of the array */ union { ap_coeff_t* coeff; /* array of coefficients */ ap_linterm_t* linterm; /* array of linear terms */ } p; } ap_linexpr0_t; /* Important invariant: If sparse representation, - linear terms are sorted in increasing order wrt their dimension. - AP_DIM_MAX dimensions are meaningless: they serve as free linterm when a new dimension is needed (this avoids to permanently reallocating the array. They should be ignored. */ /* Comment: we do not inline the array in the structure, because this allows to redimension (with realloc) the array in a transparent way for the user. */ /* - An interval linear expression is the more general form. - A quasilinear expression is such that the only non-scalar coefficient is the constant coefficient. - A linear expression contains no non-scalar coefficients */ typedef enum ap_linexpr_type_t { AP_LINEXPR_INTLINEAR, AP_LINEXPR_QUASILINEAR, AP_LINEXPR_LINEAR } ap_linexpr_type_t; /* ====================================================================== */ /* I. Memory management and printing */ /* ====================================================================== */ ap_linexpr0_t* ap_linexpr0_alloc(ap_linexpr_discr_t lin_discr, size_t size); /* Allocates a linear expressions with coefficients by default of type SCALAR and DOUBLE. If sparse representation, corresponding new dimensions are initialized with AP_DIM_MAX. */ void ap_linexpr0_realloc(ap_linexpr0_t* e, size_t size); /* Change the dimensions of the array in linexpr0. If new coefficients are added, their type is of type SCALAR and DOUBLE. If sparse representation, corresponding new dimensions are initialized with AP_DIM_MAX. */ void ap_linexpr0_minimize(ap_linexpr0_t* e); /* Reduce the coefficients (transform intervals into scalars when possible). In case of sparse representation, also remove zero coefficients */ void ap_linexpr0_free(ap_linexpr0_t* linexpr); /* Free the linear expression */ ap_linexpr0_t* ap_linexpr0_copy(ap_linexpr0_t* a); /* Duplication */ void ap_linexpr0_fprint(FILE* stream, ap_linexpr0_t* a, char** name_of_dim); /* Printing a linear expression */ /* ====================================================================== */ /* II. Tests */ /* ====================================================================== */ bool ap_linexpr0_is_integer(ap_linexpr0_t* a, size_t intdim); /* Does the expression depends only on integer variables ? assuming that the first intdim dimensions are integer */ bool ap_linexpr0_is_real(ap_linexpr0_t* a, size_t intdim); /* Does the expression depends only on real variables ? assuming that the first intdim dimensions are integer */ /* Expression classification */ ap_linexpr_type_t ap_linexpr0_type(ap_linexpr0_t* a); /* Return the type of the linear expression */ bool ap_linexpr0_is_linear(ap_linexpr0_t* a); /* Return true iff all involved coefficients are scalars */ bool ap_linexpr0_is_quasilinear(ap_linexpr0_t* a); /* Return true iff all involved coefficients but the constant are scalars */ ap_linexpr_type_t ap_linexpr0_array_type(ap_linexpr0_t** texpr, size_t size); bool ap_linexpr0_array_is_linear(ap_linexpr0_t** texpr, size_t size); bool ap_linexpr0_array_is_quasilinear(ap_linexpr0_t** texpr, size_t size); /* Idem for arrays */ /* ====================================================================== */ /* III. Access */ /* ====================================================================== */ static inline size_t ap_linexpr0_size(ap_linexpr0_t* expr); /* Get the size of the linear expression */ static inline ap_coeff_t* ap_linexpr0_cstref(ap_linexpr0_t* expr); /* Get a reference to the constant. Do not free it. */ ap_coeff_t* ap_linexpr0_coeffref(ap_linexpr0_t* expr, ap_dim_t dim); /* Get a reference to the coefficient associated to the dimension. Do not free it. In case of sparse representation, possibly induce the addition of a new linear term. Return NULL if: In case of dense representation, dim>=expr->size. In case of sparse representation, dim==AP_DIM_MAX. */ static inline void ap_linexpr0_get_cst(ap_coeff_t* coeff, ap_linexpr0_t* expr); /* Get the constant and assign it to coeff */ bool ap_linexpr0_get_coeff(ap_coeff_t* coeff, ap_linexpr0_t* expr, ap_dim_t dim); /* Get coefficient of dimension dim in the expression and assign it to coeff Return true in case ap_linexpr0_coeffref returns NULL */ /* Set the constant of the linear expression */ static inline void ap_linexpr0_set_cst(ap_linexpr0_t* expr, ap_coeff_t* cst); static inline void ap_linexpr0_set_cst_scalar(ap_linexpr0_t* expr, ap_scalar_t* scalar); static inline void ap_linexpr0_set_cst_scalar_int(ap_linexpr0_t* expr, int num); static inline void ap_linexpr0_set_cst_scalar_frac(ap_linexpr0_t* expr, int num, unsigned int den); static inline void ap_linexpr0_set_cst_scalar_double(ap_linexpr0_t* expr, double num); static inline void ap_linexpr0_set_cst_interval(ap_linexpr0_t* expr, ap_interval_t* itv); static inline void ap_linexpr0_set_cst_interval_scalar(ap_linexpr0_t* expr, ap_scalar_t* inf, ap_scalar_t* sup); static inline void ap_linexpr0_set_cst_interval_int(ap_linexpr0_t* expr, int inf, int sup); static inline void ap_linexpr0_set_cst_interval_frac(ap_linexpr0_t* expr, int numinf, unsigned int deninf, int numsup, unsigned int densup); static inline void ap_linexpr0_set_cst_interval_double(ap_linexpr0_t* expr, double inf, double sup); /* Set the coefficient of dimension dim in the expression. Return true in case ap_linexpr0_coeffref returns NULL */ static inline bool ap_linexpr0_set_coeff(ap_linexpr0_t* expr, ap_dim_t dim, ap_coeff_t* coeff); static inline bool ap_linexpr0_set_coeff_scalar(ap_linexpr0_t* expr, ap_dim_t dim, ap_scalar_t* scalar); static inline bool ap_linexpr0_set_coeff_scalar_int(ap_linexpr0_t* expr, ap_dim_t dim, int num); static inline bool ap_linexpr0_set_coeff_scalar_frac(ap_linexpr0_t* expr, ap_dim_t dim, int num, unsigned int den); static inline bool ap_linexpr0_set_coeff_scalar_double(ap_linexpr0_t* expr, ap_dim_t dim, double num); static inline bool ap_linexpr0_set_coeffinterval(ap_linexpr0_t* expr, ap_dim_t dim, ap_interval_t* itv); static inline bool ap_linexpr0_set_coeff_interval_scalar(ap_linexpr0_t* expr, ap_dim_t dim, ap_scalar_t* inf, ap_scalar_t* sup); static inline bool ap_linexpr0_set_coeff_interval_int(ap_linexpr0_t* expr, ap_dim_t dim, int inf, int sup); static inline bool ap_linexpr0_set_coeff_interval_frac(ap_linexpr0_t* expr, ap_dim_t dim, int numinf, unsigned int deninf, int numsup, unsigned int densup); static inline bool ap_linexpr0_set_coeff_interval_double(ap_linexpr0_t* expr, ap_dim_t dim, double inf, double sup); /* bool ap_linexpr0_set_format_generic(ap_coeff_t* (*get_pcoeff)(char*,va_list*,void*,bool*), void* expr, char* fmt, va_list* ap); bool ap_linexpr0_set_format(ap_linexpr0_t* expr, char* fmt, ...); */ typedef enum ap_coefftag_t { AP_COEFF, /* waiting for a coeff_t* object and a dimension */ AP_COEFF_S, /* waiting for a scalar_t* object and a dimension */ AP_COEFF_S_MPQ, /* waiting for a mpq_t object and a dimension */ AP_COEFF_S_MPFR, /* waiting for a mpfr_t object and a dimension */ AP_COEFF_S_INT, /* waiting for a int object and a dimension */ AP_COEFF_S_FRAC, /* waiting for 2 int objects and a dimension */ AP_COEFF_S_DOUBLE, /* waiting for a double object and a dimension */ AP_COEFF_I, /* waiting for a interval_t* object and a dimension */ AP_COEFF_I_SCALAR, /* waiting for 2 scalar_t* objects and a dimension */ AP_COEFF_I_MPQ, /* waiting for 2 mpq_t objects and a dimension */ AP_COEFF_I_MPFR, /* waiting for 2 mpfr_t objects and a dimension */ AP_COEFF_I_INT, /* waiting for 2 int objects and a dimension */ AP_COEFF_I_FRAC, /* waiting for 4 int objects and a dimension */ AP_COEFF_I_DOUBLE, /* waiting for 2 double objects and a dimension */ AP_CST, /* waiting for a coeff_t* object */ AP_CST_S, /* waiting for a scalar_t* object */ AP_CST_S_MPQ, /* waiting for a mpq_t object */ AP_CST_S_MPFR, /* waiting for a mpfr_t object */ AP_CST_S_INT, /* waiting for a int object */ AP_CST_S_FRAC, /* waiting for 2 int objects */ AP_CST_S_DOUBLE, /* waiting for a double object */ AP_CST_I, /* waiting for a interval_t* object */ AP_CST_I_SCALAR, /* waiting for 2 scalar_t* objects */ AP_CST_I_MPQ, /* waiting for 2 mpq_t objects */ AP_CST_I_MPFR, /* waiting for 2 mpfr_t objects */ AP_CST_I_INT, /* waiting for 2 int objects */ AP_CST_I_FRAC, /* waiting for 4 int objects */ AP_CST_I_DOUBLE, /* waiting for 2 double objects */ AP_END } ap_coefftag_t; bool ap_linexpr0_set_list_generic(ap_coeff_t* (*get_pcoeff)(void* expr, bool cst, va_list* va), void* expr, va_list* va); bool ap_linexpr0_set_list(ap_linexpr0_t* expr, ...); /* Iterator (Macro): use: ap_linexpr0_ForeachLinterm(ap_linexpr0_t* e, size_t i, ap_dim_t d, ap_coeff_t* coeff){ .. } where - e is the inspected expression, - i is the internal iterator (of type size_t or int) - dim is the dimension of one linear term - coeff is a pointer to the corresponding coefficient AP_DIM_MAX dimensions are filtered out. */ #define ap_linexpr0_ForeachLinterm(_p_e_, _p_i_, _p_dim_, _p_ap_coeff) \ for ((_p_i_)=0; \ (_p_i_)<(_p_e_)->size ? \ ((_p_e_)->discr==AP_LINEXPR_DENSE ? \ ((_p_dim_) = (_p_i_), \ (_p_ap_coeff) = &(_p_e_)->p.coeff[_p_i_], \ true) : \ ((_p_dim_) = (_p_e_)->p.linterm[_p_i_].dim, \ (_p_ap_coeff) = &(_p_e_)->p.linterm[_p_i_].coeff, \ (_p_dim_)!=AP_DIM_MAX)) : \ false; \ (_p_i_)++) /* ====================================================================== */ /* IV. Change of dimensions and permutations */ /* ====================================================================== */ /* These two functions add dimensions to the expressions, following the semantics of dimchange (see the type definition of dimchange). */ void ap_linexpr0_add_dimensions_with(ap_linexpr0_t* expr, ap_dimchange_t* dimchange); ap_linexpr0_t* ap_linexpr0_add_dimensions(ap_linexpr0_t* expr, ap_dimchange_t* dimchange); /* These two functions apply the given permutation to the dimensions. If dense representation, the size of the permutation should be expr->size. If sparse representation, the dimensions present in the expression should just be less than the size of the permutation. */ void ap_linexpr0_permute_dimensions_with(ap_linexpr0_t* expr, ap_dimperm_t* perm); ap_linexpr0_t* ap_linexpr0_permute_dimensions(ap_linexpr0_t* expr, ap_dimperm_t* perm); /* ====================================================================== */ /* V. Hashing, comparison */ /* ====================================================================== */ /* Induces reduction of the coefficients */ long ap_linexpr0_hash(ap_linexpr0_t* expr); bool ap_linexpr0_equal(ap_linexpr0_t* expr1, ap_linexpr0_t* expr2); /* Lexicographic ordering, terminating by constant coefficients */ int ap_linexpr0_compare(ap_linexpr0_t* expr1, ap_linexpr0_t* expr2); /* ====================================================================== */ /* Vb. Array of expressions */ /* ====================================================================== */ /* Free the array of expressions of size size */ void ap_linexpr0_array_free(ap_linexpr0_t** texpr, size_t size); /* ====================================================================== */ /* VI. Inline function definitions */ /* ====================================================================== */ static inline size_t ap_linexpr0_size(ap_linexpr0_t* expr) { return expr->size; } static inline ap_coeff_t* ap_linexpr0_cstref(ap_linexpr0_t* expr) { return &expr->cst; } static inline void ap_linexpr0_get_cst(ap_coeff_t* coeff, ap_linexpr0_t* expr) { ap_coeff_set(coeff,&expr->cst); } static inline void ap_linexpr0_set_cst(ap_linexpr0_t* expr, ap_coeff_t* cst) { ap_coeff_set(&expr->cst,cst); } static inline void ap_linexpr0_set_cst_scalar(ap_linexpr0_t* expr, ap_scalar_t* scalar) { ap_coeff_set_scalar(&expr->cst, scalar); } static inline void ap_linexpr0_set_cst_scalar_int(ap_linexpr0_t* expr, int num) { ap_coeff_set_scalar_int(&expr->cst, num); } static inline void ap_linexpr0_set_cst_scalar_frac(ap_linexpr0_t* expr, int num, unsigned int den) { ap_coeff_set_scalar_frac(&expr->cst, num, den); } static inline void ap_linexpr0_set_cst_scalar_double(ap_linexpr0_t* expr, double num) { ap_coeff_set_scalar_double(&expr->cst, num); } static inline void ap_linexpr0_set_cst_interval(ap_linexpr0_t* expr, ap_interval_t* itv) { ap_coeff_set_interval(&expr->cst, itv); } static inline void ap_linexpr0_set_cst_interval_int(ap_linexpr0_t* expr, int inf, int sup) { ap_coeff_set_interval_int(&expr->cst, inf,sup); } static inline void ap_linexpr0_set_cst_interval_scalar(ap_linexpr0_t* expr, ap_scalar_t* inf, ap_scalar_t* sup) { ap_coeff_set_interval_scalar(&expr->cst, inf,sup); } static inline void ap_linexpr0_set_cst_interval_frac(ap_linexpr0_t* expr, int numinf, unsigned int deninf, int numsup, unsigned int densup) { ap_coeff_set_interval_frac(&expr->cst, numinf,deninf, numsup,densup); } static inline void ap_linexpr0_set_cst_interval_double(ap_linexpr0_t* expr, double inf, double sup) { ap_coeff_set_interval_double(&expr->cst, inf,sup); } static inline bool ap_linexpr0_set_coeff(ap_linexpr0_t* expr, ap_dim_t dim, ap_coeff_t* coeff) { ap_coeff_t* ecoeff = ap_linexpr0_coeffref(expr,dim); if (ecoeff){ap_coeff_set(ecoeff,coeff); return false;} else return true; } static inline bool ap_linexpr0_set_coeff_scalar(ap_linexpr0_t* expr, ap_dim_t dim, ap_scalar_t* scalar) { ap_coeff_t* ecoeff = ap_linexpr0_coeffref(expr,dim); if (ecoeff){ ap_coeff_set_scalar(ecoeff,scalar); return false; } else return true; } static inline bool ap_linexpr0_set_coeff_scalar_int(ap_linexpr0_t* expr, ap_dim_t dim, int num) { ap_coeff_t* ecoeff = ap_linexpr0_coeffref(expr,dim); if (ecoeff){ ap_coeff_set_scalar_int(ecoeff,num); return false; } else return true; } static inline bool ap_linexpr0_set_coeff_scalar_frac(ap_linexpr0_t* expr, ap_dim_t dim, int num, unsigned int den) { ap_coeff_t* ecoeff = ap_linexpr0_coeffref(expr,dim); if (ecoeff){ ap_coeff_set_scalar_frac(ecoeff,num, den); return false; } else return true; } static inline bool ap_linexpr0_set_coeff_scalar_double(ap_linexpr0_t* expr, ap_dim_t dim, double num) { ap_coeff_t* ecoeff = ap_linexpr0_coeffref(expr,dim); if (ecoeff){ ap_coeff_set_scalar_double(ecoeff,num); return false; } else return true; } static inline bool ap_linexpr0_set_coeffinterval(ap_linexpr0_t* expr, ap_dim_t dim, ap_interval_t* itv) { ap_coeff_t* ecoeff = ap_linexpr0_coeffref(expr,dim); if (ecoeff){ ap_coeff_set_interval(ecoeff,itv); return false; } else return true; } static inline bool ap_linexpr0_set_coeff_interval_int(ap_linexpr0_t* expr, ap_dim_t dim, int inf, int sup) { ap_coeff_t* ecoeff = ap_linexpr0_coeffref(expr,dim); if (ecoeff){ ap_coeff_set_interval_int(ecoeff,inf,sup); return false; } else return true; } static inline bool ap_linexpr0_set_coeff_interval_scalar(ap_linexpr0_t* expr, ap_dim_t dim, ap_scalar_t* inf, ap_scalar_t* sup) { ap_coeff_t* ecoeff = ap_linexpr0_coeffref(expr,dim); if (ecoeff){ ap_coeff_set_interval_scalar(ecoeff,inf,sup); return false; } else return true; } static inline bool ap_linexpr0_set_coeff_interval_frac(ap_linexpr0_t* expr, ap_dim_t dim, int numinf, unsigned int deninf, int numsup, unsigned int densup) { ap_coeff_t* ecoeff = ap_linexpr0_coeffref(expr,dim); if (ecoeff){ ap_coeff_set_interval_frac(ecoeff,numinf,deninf, numsup,densup); return false; } else return true; } static inline bool ap_linexpr0_set_coeff_interval_double(ap_linexpr0_t* expr, ap_dim_t dim, double inf, double sup) { ap_coeff_t* ecoeff = ap_linexpr0_coeffref(expr,dim); if (ecoeff){ ap_coeff_set_interval_double(ecoeff,inf,sup); return false; } else return true; } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/ap_manager.c0000640014525101416610000001765410760562320020257 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_manager.c: global manager passed to all functions */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #include #include #include #include "ap_manager.h" const char* ap_name_of_funid[AP_FUNID_SIZE2] = { "unknown", "copy", "free", "size", "minimize", "canonicalize", "hash", "approximate", "print", "printdiff", "dump", "serialize_raw", "deserialize_raw", "bottom", "top", "of_box", "dimension", "is_bottom", "is_top", "is_leq", "is_eq", "is_dimension_unconstrained", "sat_interval", "sat_lincons", "sat_tcons", "bound_dimension", "bound_linexpr", "bound_texpr", "to_box", "to_lincons_array", "to_tcons_array", "to_generator_array", "meet", "meet_array", "meet_lincons_array", "meet_tcons_array", "join", "join_array", "add_ray_array", "assign_linexpr_array", "substitute_linexpr_array", "assign_texpr_array", "substitute_texpr_array", "add_dimensions", "remove_dimensions", "permute_dimensions", "forget_array", "expand", "fold", "widening", "closure", "unknown", "change_environment", "rename" }; const char* ap_name_of_exception[AP_EXC_SIZE] = { "NONE", "TIMEOUT", "OUT_OF_SPACE", "OVERFLOW", "INVALID_ARGUMENT", "NOT_IMPLEMENTED" }; /* ********************************************************************** */ /* I. Constructor and destructor for options */ /* ********************************************************************** */ void ap_funopt_init(ap_funopt_t* opt) { opt->algorithm = 0; opt->timeout = 0; opt->max_object_size = 0; opt->flag_exact_wanted = false; opt->flag_best_wanted = false; } void ap_option_init(ap_option_t* opt) { ap_funid_t funid; ap_exc_t exn; for (funid=0; funidfunopt[funid]); } for (exn=0; exnabort_if_exception[exn] = true; } opt->scalar_discr = AP_SCALAR_DOUBLE; } /* ********************************************************************** */ /* II. Constructor and destructor for result */ /* ********************************************************************** */ ap_exclog_t* ap_exc_cons(ap_exc_t exn, ap_funid_t funid, const char* msg, ap_exclog_t* tail) { ap_exclog_t* head = (ap_exclog_t*)malloc(sizeof(ap_exclog_t)); head->exn = exn; head->funid = funid; head->msg = strdup(msg ? msg : ""); head->tail = tail; return head; } void ap_exclog_free(ap_exclog_t* head) { ap_exclog_t* p = head; while (p!=NULL) { ap_exclog_t* tail = p->tail; free(p->msg); free(p); p = tail; } } void ap_result_add_exception(ap_result_t* result, ap_exc_t exn, ap_funid_t funid, const char* msg) { result->exclog = ap_exc_cons(exn,funid,msg,result->exclog); result->exn = exn; } void ap_result_init(ap_result_t* result) { result->exclog = NULL; result->exn = AP_EXC_NONE; result->flag_exact = false; result->flag_best = false; } void ap_result_clear(ap_result_t* result) { ap_exclog_free(result->exclog); ap_result_init(result); } /* ********************************************************************** */ /* III. Constructor and destructor for manager */ /* ********************************************************************** */ /* Constructor and destructor for manager */ ap_manager_t* ap_manager_alloc(char* library, char* version, void* internal, void (*internal_free)(void*)) { ap_manager_t* man; assert(sizeof(bool)==1); man = (ap_manager_t*)malloc(sizeof(ap_manager_t)); man->library = library; man->version = version; man->internal = internal; man->internal_free = internal_free; man->count = 1; ap_option_init(&man->option); ap_result_init(&man->result); return man; } void ap_manager_free(ap_manager_t* man) { if (man->count>1){ man->count--; } else { if (man->internal != NULL){ man->internal_free(man->internal); man->internal = NULL; } ap_result_clear(&man->result); free(man); } } /* ********************************************************************** */ /* IV. Other User functions */ /* ********************************************************************** */ const char* ap_manager_get_library(ap_manager_t* man) { return man->library; } const char* ap_manager_get_version(ap_manager_t* man) { return man->version; } ap_funopt_t ap_manager_get_funopt(ap_manager_t* man, ap_funid_t funid) { if (funidoption.funopt[funid]; else { fprintf(stderr,"ap_manager.c: ap_manager_get_funopt: funid should be less than AP_FUNID_SIZE\n"); abort(); } } bool ap_manager_get_abort_if_exception(ap_manager_t* man, ap_exc_t exn) { return man->option.abort_if_exception[exn]; } bool ap_manager_get_flag_exact(ap_manager_t* man) { return man->result.flag_exact; } bool ap_manager_get_flag_best(ap_manager_t* man) { return man->result.flag_best; } void ap_manager_set_funopt(ap_manager_t* man, ap_funid_t funid, ap_funopt_t* funopt) { if (funidoption.funopt[funid] = *funopt; } void ap_manager_set_abort_if_exception(ap_manager_t* man, ap_exc_t exn, bool flag) { man->option.abort_if_exception[exn] = flag; } void ap_manager_clear_exclog(ap_manager_t* man) { ap_exclog_free(man->result.exclog); man->result.exclog = NULL; } /* ********************************************************************** */ /* V. Other Implementor functions */ /* ********************************************************************** */ void ap_manager_raise_exception(ap_manager_t* man, ap_exc_t exn, ap_funid_t funid, const char* msg) { bool pabort; if (exn!=AP_EXC_NONE){ pabort = man->option.abort_if_exception[exn]; if (pabort){ fprintf(stderr,"Apron: Abort because of following exception:\nexception %s in function %s:\n%s\n", ap_name_of_exception[exn], ap_name_of_funid[funid], msg); abort(); } else { ap_result_add_exception(&man->result,exn,funid,msg); man->result.flag_exact = man->result.flag_best = false; } } return; } /* ********************************************************************** */ /* V. FPU init */ /* ********************************************************************** */ /* simple run-time test that fpu behaves correctly */ static bool test_fpu(void) { int i; long double d = 1., dd; /* find the minimal long double, as the fixpoint of x -> x/2 with rounding towards +oo; the max iteration value should be enough for 128-bit floating-point */ for (i=0;i<5000000;i++) { dd = d; d /= 2; if (d==dd || d==0.) break; } /* fails if flush to 0 */ if (d!=dd) { fprintf(stderr,"test_fpu failed test #1 after %i iterations\n",i); return false; } /* fails if long double rounding is not towards +oo */ if (d*0.25!=dd) { fprintf(stderr,"test_fpu failed test #2\n"); return false; } /* fails if double rounding is not towards +oo */ if ((double)d bool ap_fpu_init(void) { if (!fesetround(FE_UPWARD)) return test_fpu(); fprintf(stderr,"could not set fpu rounding mode: fesetround failed\n"); return false; } #elif defined(__FreeBSD__) || defined(sun) #include bool ap_fpu_init(void) { fpsetround(FP_RP); return test_fpu(); } #else bool ap_fpu_init(void) { fprintf(stderr,"could not set fpu rounding mode: platform not supported\n"); return false; } #endif apron-dist-0.9.10/apron/apron/ap_texpr1.h0000640014525101416610000001561011006063143020054 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_texpr0.h: tree expressions */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include #ifndef _AP_TEXPR1_H_ #define _AP_TEXPR1_H_ #include "ap_dimension.h" #include "ap_coeff.h" #include "ap_texpr0.h" #include "ap_environment.h" #include "ap_linexpr1.h" #ifdef __cplusplus extern "C" { #endif /* ====================================================================== */ /* Datatypes */ /* ====================================================================== */ /* IMPORTANT NOTE -------------- correct use of floating-point AP_RTYPE_xxx currently supposes that the FPU rounds towards +oo */ /* Tree expressions */ typedef struct ap_texpr1_t { ap_texpr0_t* texpr0; ap_environment_t* env; } ap_texpr1_t; /* ====================================================================== */ /* I. Constructors and Destructors */ /* ====================================================================== */ ap_texpr1_t* ap_texpr1_cst (ap_environment_t* env, ap_coeff_t* coeff); ap_texpr1_t* ap_texpr1_cst_scalar (ap_environment_t* env, ap_scalar_t* scalar); ap_texpr1_t* ap_texpr1_cst_scalar_mpq (ap_environment_t* env, mpq_t mpq); ap_texpr1_t* ap_texpr1_cst_scalar_mpfr (ap_environment_t* env, mpfr_t mpfr); ap_texpr1_t* ap_texpr1_cst_scalar_int (ap_environment_t* env, long int num); ap_texpr1_t* ap_texpr1_cst_scalar_frac (ap_environment_t* env, long int num, unsigned long int den); ap_texpr1_t* ap_texpr1_cst_scalar_double (ap_environment_t* env, double num); ap_texpr1_t* ap_texpr1_cst_interval (ap_environment_t* env, ap_interval_t* itv); ap_texpr1_t* ap_texpr1_cst_interval_scalar (ap_environment_t* env, ap_scalar_t* inf, ap_scalar_t* sup); ap_texpr1_t* ap_texpr1_cst_interval_mpq (ap_environment_t* env, mpq_t inf, mpq_t sup); ap_texpr1_t* ap_texpr1_cst_interval_mpfr (ap_environment_t* env, mpfr_t inf, mpfr_t sup); ap_texpr1_t* ap_texpr1_cst_interval_int (ap_environment_t* env, long int inf, long int sup); ap_texpr1_t* ap_texpr1_cst_interval_frac (ap_environment_t* env, long int numinf, unsigned long int deninf, long int numsup, unsigned long int densup); ap_texpr1_t* ap_texpr1_cst_interval_double (ap_environment_t* env, double inf, double sup); ap_texpr1_t* ap_texpr1_cst_interval_top (ap_environment_t* env); /* Create a constant leaf expression */ ap_texpr1_t* ap_texpr1_var(ap_environment_t* env, ap_var_t var); /* Create a variable leaf expression */ ap_texpr1_t* ap_texpr1_unop(ap_texpr_op_t op, ap_texpr1_t* opA, ap_texpr_rtype_t type, ap_texpr_rdir_t dir); /* Create unary operator node */ ap_texpr1_t* ap_texpr1_binop(ap_texpr_op_t op, ap_texpr1_t* opA, ap_texpr1_t* opB, ap_texpr_rtype_t type, ap_texpr_rdir_t dir); /* Create binary operator node */ ap_texpr1_t* ap_texpr1_copy(ap_texpr1_t* expr); /* Recursive (deep) copy */ void ap_texpr1_free(ap_texpr1_t* expr); /* Recursive (deep) free */ ap_texpr1_t* ap_texpr1_from_linexpr1(ap_linexpr1_t* e); /* From linear expression to comb-like expression tree */ /* ====================================================================== */ /* II. Printing */ /* ====================================================================== */ void ap_texpr1_fprint(FILE* stream, ap_texpr1_t* a); static inline void ap_texpr1_print(ap_texpr1_t* a); /* Prints the expression */ /* ====================================================================== */ /* III. Tests, size */ /* ====================================================================== */ bool ap_texpr1_has_var(ap_texpr1_t* e, ap_var_t var); /* Returns true if variable var appears in the expression */ /* Expression classification */ static inline bool ap_texpr1_is_interval_cst(ap_texpr1_t* e); /* no-variable, only constant leaves */ static inline bool ap_texpr1_is_interval_linear(ap_texpr1_t* e); /* linear with possibly interval coefficients, no rounding */ static inline bool ap_texpr1_is_interval_polynomial(ap_texpr1_t* e); /* polynomial with possibly interval coefficients, no rounding */ static inline bool ap_texpr1_is_interval_polyfrac(ap_texpr1_t* e); /* polynomial fraction with possibly interval coefficients, no rounding */ static inline bool ap_texpr1_is_scalar(ap_texpr1_t* e); /* all coefficients are scalar (non-interval) */ /* ====================================================================== */ /* IV. Operations */ /* ====================================================================== */ ap_texpr1_t* ap_texpr1_substitute(ap_texpr1_t* e, ap_var_t var, ap_texpr1_t *dst); /* Substitute every occurrence of variable var with a copy of dst. Return NULL in case of incorrect argument (w.r.t. var and/or environment compatibility). */ bool ap_texpr1_substitute_with (ap_texpr1_t* e, ap_var_t var, ap_texpr1_t *dst); /* Substitute every occurrence of variable var with a copy of dst. Return true in case of incorrect argument (w.r.t. var and/or environment compatibility) */ /* ====================================================================== */ /* V. Change of environments */ /* ====================================================================== */ ap_texpr1_t* ap_texpr1_extend_environment(ap_texpr1_t* expr, ap_environment_t* nenv); /* Change current environment with a super-environment. Return NULL if nenv is not a superenvironment */ bool ap_texpr1_extend_environment_with(ap_texpr1_t* expr, ap_environment_t* nenv); /* Change current environment with a super-environment. Return true if nenv is not a superenvironment */ /* ====================================================================== */ /* VI. Hashing, comparisons */ /* ====================================================================== */ bool ap_texpr1_equal(ap_texpr1_t* a1, ap_texpr1_t* a2); /* Structural (recursive) equality */ /* ====================================================================== */ /* Inline function definitions */ /* ====================================================================== */ static inline void ap_texpr1_print(ap_texpr1_t* a) { ap_texpr1_fprint(stdout, a); } static inline bool ap_texpr1_is_interval_cst(ap_texpr1_t* a) { return ap_texpr0_is_interval_cst(a->texpr0); } static inline bool ap_texpr1_is_interval_linear(ap_texpr1_t* a) { return ap_texpr0_is_interval_linear(a->texpr0); } static inline bool ap_texpr1_is_interval_polynomial(ap_texpr1_t* a) { return ap_texpr0_is_interval_polynomial(a->texpr0); } static inline bool ap_texpr1_is_interval_polyfrac(ap_texpr1_t* a) { return ap_texpr0_is_interval_polyfrac(a->texpr0); } static inline bool ap_texpr1_is_scalar(ap_texpr1_t* a) { return ap_texpr0_is_scalar(a->texpr0); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/ap_coeff.h0000640014525101416610000001326511247456444017740 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_coeff.h: coefficients, that are either scalars or intervals */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _AP_COEFF_H_ #define _AP_COEFF_H_ #include #include #include #include "ap_config.h" #include "ap_scalar.h" #include "ap_interval.h" #ifdef __cplusplus extern "C" { #endif typedef enum ap_coeff_discr_t { AP_COEFF_SCALAR, AP_COEFF_INTERVAL } ap_coeff_discr_t; /* Discriminant for coefficients */ typedef struct ap_coeff_t { ap_coeff_discr_t discr; /* discriminant for coefficient */ union { ap_scalar_t* scalar; /* cst (normal linear expression) */ ap_interval_t* interval; /* interval (quasi-linear expression) */ } val; } ap_coeff_t; /* ====================================================================== */ /* Basics */ /* ====================================================================== */ ap_coeff_t* ap_coeff_alloc(ap_coeff_discr_t ap_coeff_discr); /* Initialization, specifying the type of the coefficient */ void ap_coeff_reinit(ap_coeff_t* coeff, ap_coeff_discr_t ap_coeff_discr, ap_scalar_discr_t ap_scalar_discr); /* Changing the type of scalar(s) and the type of the coefficient */ void ap_coeff_free(ap_coeff_t* a); /* Free a coefficient */ void ap_coeff_fprint(FILE* stream, ap_coeff_t* a); static inline void ap_coeff_print(ap_coeff_t* a) { ap_coeff_fprint(stdout,a); } /* Printing */ void ap_coeff_reduce(ap_coeff_t* coeff); /* If the coefficient is an interval [a;a], convert it to a scalar */ static inline void ap_coeff_swap(ap_coeff_t* a, ap_coeff_t* b) { ap_coeff_t t = *a; *a = *b; *b = t; } /* Exchange */ /* ====================================================================== */ /* Assignments */ /* ====================================================================== */ void ap_coeff_set(ap_coeff_t* a, ap_coeff_t* b); /* Assignment */ void ap_coeff_set_scalar(ap_coeff_t* coeff, ap_scalar_t* scalar); void ap_coeff_set_scalar_mpq(ap_coeff_t* coeff, mpq_t mpq); void ap_coeff_set_scalar_int(ap_coeff_t* coeff, long int num); void ap_coeff_set_scalar_frac(ap_coeff_t* coeff, long int num, unsigned long int den); void ap_coeff_set_scalar_double(ap_coeff_t* coeff, double num); void ap_coeff_set_scalar_mpfr(ap_coeff_t* coeff, mpfr_t mpfr); /* Assign a coefficient of type SCALAR, with resp. - a coeff - a rational of type mpq_t, converted to type MPQ - an integer, converted to type MPQ - a rational, converted to type MPQ - a double, converted to type DOUBLE - a MPFR, converted to type MPFR */ void ap_coeff_set_interval(ap_coeff_t* coeff, ap_interval_t* itv); void ap_coeff_set_interval_scalar(ap_coeff_t* coeff, ap_scalar_t* inf, ap_scalar_t* sup); void ap_coeff_set_interval_mpq(ap_coeff_t* coeff, mpq_t inf, mpq_t sup); void ap_coeff_set_interval_int(ap_coeff_t* coeff, long int inf, long int sup); void ap_coeff_set_interval_frac(ap_coeff_t* coeff, long int numinf, unsigned long int deninf, long int numsup, unsigned long int densup); void ap_coeff_set_interval_double(ap_coeff_t* coeff, double inf, double sup); void ap_coeff_set_interval_top(ap_coeff_t* coeff); void ap_coeff_set_interval_mpfr(ap_coeff_t* coeff, mpfr_t inf, mpfr_t sup); /* Assign a coefficient of type INTERVAL, with resp. - an interval of coeff - an interval of rationals of type MPQ - an interval of integers, converted to type MPQ - an interval of rationals, converted to type MPQ - an interval of double, converted to type DOUBLE - an interval of MPFR, converted to type MPFR - a top interval (type not precised). */ /* ====================================================================== */ /* Combined allocation and assignment */ /* ====================================================================== */ ap_coeff_t* ap_coeff_alloc_set(ap_coeff_t* coeff); ap_coeff_t* ap_coeff_alloc_set_scalar(ap_scalar_t* scalar); ap_coeff_t* ap_coeff_alloc_set_interval(ap_interval_t* interval); /* ====================================================================== */ /* Tests */ /* ====================================================================== */ int ap_coeff_cmp(ap_coeff_t* coeff1, ap_coeff_t* coeff2); /* Non Total Comparison: - If the 2 coefficients are both scalars, corresp. to ap_scalar_cmp - If the 2 coefficients are both intervals, corresp. to ap_interval_cmp - otherwise, -3 if the first is a scalar, 3 otherwise */ bool ap_coeff_equal(ap_coeff_t* coeff1, ap_coeff_t* coeff2); /* Equality */ bool ap_coeff_zero(ap_coeff_t* coeff); /* Return true iff coeff is a zero scalar or an interval with zero bounds */ bool ap_coeff_equal_int(ap_coeff_t* coeff, int i); /* Return true iff coeff is a scalar equals to i or an interval with bounds equal to i */ /* ====================================================================== */ /* Other operations */ /* ====================================================================== */ void ap_coeff_neg(ap_coeff_t* a, ap_coeff_t* b); /* Negation */ long ap_coeff_hash(ap_coeff_t* coeff); /* Hash code */ /* ====================================================================== */ /* FOR INTERNAL USE ONLY */ /* ====================================================================== */ void ap_coeff_init(ap_coeff_t* coeff, ap_coeff_discr_t ap_coeff_discr); void ap_coeff_init_set(ap_coeff_t* coeff, ap_coeff_t* coeff2); void ap_coeff_clear(ap_coeff_t* coeff); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/ap_tcons1.c0000640014525101416610000001253410644461001020037 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_lincons1.c: tree constraints */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "ap_tcons1.h" /* ********************************************************************** */ /* I. ap_tcons0_t */ /* ********************************************************************** */ /* ====================================================================== */ /* I.1 Memory management and printing */ /* ====================================================================== */ ap_tcons1_t ap_tcons1_make_unsat(ap_environment_t* env) { return ap_tcons1_of_tcons0(env,ap_tcons0_make_unsat()); } void ap_tcons1_clear(ap_tcons1_t* cons) { ap_tcons0_clear(&cons->tcons0); if (cons->env){ ap_environment_free(cons->env); cons->env = NULL; } } void ap_tcons1_fprint(FILE* stream, ap_tcons1_t* cons) { ap_environment_name_of_dim_t* name_of_dim; name_of_dim = ap_environment_name_of_dim_alloc(cons->env); ap_tcons0_fprint(stream, &cons->tcons0, name_of_dim->p); ap_environment_name_of_dim_free(name_of_dim); } /* ====================================================================== */ /* I.2 Tests */ /* ====================================================================== */ /* ====================================================================== */ /* I.3 Access */ /* ====================================================================== */ /* ====================================================================== */ /* I.4 Change of dimensions and permutations */ /* ====================================================================== */ bool ap_tcons1_extend_environment(ap_tcons1_t* ncons, ap_tcons1_t* cons, ap_environment_t* nenv) { ap_dimchange_t* dimchange = ap_environment_dimchange(cons->env,nenv); if (dimchange==NULL) return true; ncons->tcons0 = ap_tcons0_add_dimensions(&cons->tcons0,dimchange); ncons->env = ap_environment_copy(nenv); ap_dimchange_free(dimchange); return false; } bool ap_tcons1_extend_environment_with(ap_tcons1_t* cons, ap_environment_t* nenv) { ap_environment_t* env; ap_dimchange_t* dimchange = ap_environment_dimchange(cons->env,nenv); if (dimchange==NULL) return true; ap_tcons0_add_dimensions_with(&cons->tcons0,dimchange); env = cons->env; cons->env = ap_environment_copy(nenv); ap_dimchange_free(dimchange); ap_environment_free(env); return false; } /* ********************************************************************** */ /* II. Array of linear constraints */ /* ********************************************************************** */ /* ====================================================================== */ /* I.1 Memory management and printing */ /* ====================================================================== */ ap_tcons1_array_t ap_tcons1_array_make(ap_environment_t* env, size_t size) { ap_tcons1_array_t array; array.tcons0_array = ap_tcons0_array_make(size); array.env = ap_environment_copy(env); return array; } void ap_tcons1_array_clear(ap_tcons1_array_t* array) { ap_tcons0_array_clear(&array->tcons0_array); ap_environment_free(array->env); array->env = NULL; } void ap_tcons1_array_fprint(FILE* stream, ap_tcons1_array_t* array) { ap_environment_name_of_dim_t* name_of_dim; name_of_dim = ap_environment_name_of_dim_alloc(array->env); ap_tcons0_array_fprint(stream,&array->tcons0_array,name_of_dim->p); ap_environment_name_of_dim_free(name_of_dim); } /* ====================================================================== */ /* II.3 Access */ /* ====================================================================== */ ap_tcons1_t ap_tcons1_array_get(ap_tcons1_array_t* array, size_t index) { ap_tcons1_t cons; cons.tcons0 = array->tcons0_array.p[index]; cons.env = array->env; return cons; } bool ap_tcons1_array_set(ap_tcons1_array_t* array, size_t index, ap_tcons1_t* cons) { if (index>=array->tcons0_array.size || !ap_environment_is_eq(cons->env,array->env)) return true; ap_tcons1_array_clear_index(array,index); array->tcons0_array.p[index] = cons->tcons0; ap_environment_free(cons->env); return false; } /* ====================================================================== */ /* II.4 Change of dimensions and permutations */ /* ====================================================================== */ bool ap_tcons1_array_extend_environment_with(ap_tcons1_array_t* array, ap_environment_t* nenv) { ap_environment_t* env; ap_dimchange_t* dimchange = ap_environment_dimchange(array->env,nenv); if (dimchange==NULL) return true; ap_tcons0_array_add_dimensions_with(&array->tcons0_array,dimchange); env = array->env; array->env = ap_environment_copy(nenv); ap_dimchange_free(dimchange); ap_environment_free(env); return false; } bool ap_tcons1_array_extend_environment(ap_tcons1_array_t* narray, ap_tcons1_array_t* array, ap_environment_t* nenv) { ap_dimchange_t* dimchange = ap_environment_dimchange(array->env,nenv); if (dimchange==NULL) return true; narray->tcons0_array = ap_tcons0_array_add_dimensions(&array->tcons0_array,dimchange); narray->env = ap_environment_copy(nenv); ap_dimchange_free(dimchange); return false; } apron-dist-0.9.10/apron/apron/ap_expr0.h0000640014525101416610000000106410644461001017667 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_expr0.h: linear expressions, constraints and generators */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _AP_EXPR0_H_ #define _AP_EXPR0_H_ #include "ap_linexpr0.h" #include "ap_lincons0.h" #include "ap_generator0.h" #include "ap_texpr0.h" #include "ap_tcons0.h" #include "ap_linearize.h" #endif apron-dist-0.9.10/apron/apron/README0000640014525101416610000000431411251670022016661 0ustar bjeannetpopart# $Id$ # This file is part of the APRON Library, released under LGPL # license. # Please read the COPYING file packaged in the distribution Source for APRON commoninterface files. To compile and/or to generate the doc, you need: * the GMP and MPFR libraries, for multiprecision arithmetic) * the ITV library (included) You need to generate a Makefile.config file from the Makefile.config.model in the parent directory of this file. Most useful make targets: all: C library (libapron.a libapron_debug.a, libapron.so) (note: they include libitv.a) apron.ps apron.info: apron.html: the documentation clean: distclean: Header files associated to C files and considered as modules: ap_scalar.h : scalars (numbers) ap_interval.h : intervals on scalars ap_coeff.h : coefficients (either scalars or intervals) ap_dimension.h : dimensions and related operations ap_linexpr0.h : (interval) linear expressions, level 0 ap_lincons0.h : (interval) linear constraints, level 0 ap_generator0.h : generators, level 0 ap_texpr0.h : tree expressions, level 0 ap_tcons0.h : tree constraints, level 0 ap_manager.h : managers ap_abstract0.h: : abstract values, level 0 ap_var.h : variables ap_environment.h: environment binding variables to dimensions ap_linexpr1.h : (interval) linear expressions, level 1 ap_lincons1.h : (interval) linear constraints, level 1 ap_generator1.h : generators, level 1 ap_texpr0.h : tree expressions, level 1 ap_tcons0.h : tree constraints, level 1 ap_abstract1.h : abstract values, level 1 ap_generic.h : generic functions for library adaptors/implementors ap_linearize.h : generic functions for (quasi)linearisation of interval expressions and tree expressions. Additional header files: ap_config.h : miscellaneous stuff (booleans, ...) ap_expr0.h : expressions, constraints, .. at level 0 ap_expr1.h : expressions, constraints, .. at level 1 ap_global0.h : all stuff relevant for level 0 ap_global1.h : all stuff relevant for level 1 * When linking objects against APRON, APRON requires: libmpfr(.a) and libgmp(.a) libraries. It already include libitv(.a) apron-dist-0.9.10/apron/apron/ap_linexpr1.h0000640014525101416610000003262010677671162020416 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_linexpr1.h: linear expressions */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ /* normally included from ap_expr1.h */ #ifndef _AP_LINEXPR1_H_ #define _AP_LINEXPR1_H_ #include #include #include #include #include "ap_coeff.h" #include "ap_environment.h" #include "ap_linexpr0.h" #ifdef __cplusplus extern "C" { #endif /* ====================================================================== */ /* Datatypes */ /* ====================================================================== */ /* Linear expressions */ typedef struct ap_linexpr1_t { ap_linexpr0_t* linexpr0; ap_environment_t* env; } ap_linexpr1_t; /* ====================================================================== */ /* I. Memory management and printing */ /* ====================================================================== */ /* For internal use */ static inline ap_linexpr1_t ap_linexpr1_of_linexpr0(ap_environment_t* env, ap_linexpr0_t* linexpr0) { ap_linexpr1_t res; res.linexpr0 = linexpr0; res.env = ap_environment_copy(env); return res; } ap_linexpr1_t ap_linexpr1_make(ap_environment_t* env, ap_linexpr_discr_t lin_discr, size_t size); /* Build a linear expressions with by default coefficients of type SCALAR and DOUBLE. - If lin_discr selects a dense representation, the size of the expression is the size of the environment. - Otherwise, the initial size is given by size and the expression may be resized lazily. */ static inline void ap_linexpr1_minimize(ap_linexpr1_t* e); /* In case of sparse representation, remove zero coefficients */ ap_linexpr1_t ap_linexpr1_copy(ap_linexpr1_t* e); /* Duplication */ void ap_linexpr1_clear(ap_linexpr1_t* linexpr); /* Clear the linear expression: - Free the linear expression of level 0 - Dereference the environment - Set fields to NULL */ void ap_linexpr1_fprint(FILE* stream, ap_linexpr1_t* a); /* Printing a linear expression */ /* ====================================================================== */ /* II. Tests */ /* ====================================================================== */ static inline bool ap_linexpr1_is_integer(ap_linexpr1_t* e); /* Does the expression depends only on integer variables ? */ static inline bool ap_linexpr1_is_real(ap_linexpr1_t* e); /* Does the expression depends only on real variables ? */ static inline ap_linexpr_type_t ap_linexpr1_type(ap_linexpr1_t* a); /* Return the type of the linear expression */ static inline bool ap_linexpr1_is_linear(ap_linexpr1_t* e); /* Return true iff all involved coefficients are scalars */ static inline bool ap_linexpr1_is_quasilinear(ap_linexpr1_t* e); /* Return true iff all involved coefficients but the constant are scalars */ /* ====================================================================== */ /* III. Access */ /* ====================================================================== */ static inline ap_environment_t* ap_linexpr1_envref(ap_linexpr1_t* expr); /* Get a reference to the environment. Do not free it. */ static inline ap_linexpr0_t* ap_linexpr1_linexpr0ref(ap_linexpr1_t* e); /* Get a reference to the underlying linear expression of level 0. Do not free it. */ static inline ap_coeff_t* ap_linexpr1_cstref(ap_linexpr1_t* expr); /* Get a reference to the constant. Do not free it. */ ap_coeff_t* ap_linexpr1_coeffref(ap_linexpr1_t* expr, ap_var_t var); /* Get a reference to the coefficient associated to the variable. Do not free it. In case of sparse representation, possibly induce the addition of a new linear term. Return NULL if var is unknown in the environment. */ /* Get the constant and assign it to coeff */ static inline void ap_linexpr1_get_cst(ap_coeff_t* coeff, ap_linexpr1_t* expr); /* Get coefficient of variable var in the expression and assign it to coeff. Return true if var is unknown in the environment */ bool ap_linexpr1_get_coeff(ap_coeff_t* coeff, ap_linexpr1_t* expr, ap_var_t var); /* Set the constant of the linear expression */ static inline void ap_linexpr1_set_cst(ap_linexpr1_t* expr, ap_coeff_t* cst); static inline void ap_linexpr1_set_cst_scalar(ap_linexpr1_t* expr, ap_scalar_t* scalar); static inline void ap_linexpr1_set_cst_scalar_int(ap_linexpr1_t* expr, int num); static inline void ap_linexpr1_set_cst_scalar_frac(ap_linexpr1_t* expr, int num, unsigned int den); static inline void ap_linexpr1_set_cst_scalar_double(ap_linexpr1_t* expr, double num); static inline void ap_linexpr1_set_cst_interval(ap_linexpr1_t* expr, ap_interval_t* itv); static inline void ap_linexpr1_set_cst_interval_scalar(ap_linexpr1_t* expr, ap_scalar_t* inf, ap_scalar_t* sup); static inline void ap_linexpr1_set_cst_interval_int(ap_linexpr1_t* expr, int inf, int sup); static inline void ap_linexpr1_set_cst_interval_frac(ap_linexpr1_t* expr, int numinf, unsigned int deninf, int numsup, unsigned int densup); static inline void ap_linexpr1_set_cst_interval_double(ap_linexpr1_t* expr, double inf, double sup); /* Set the coefficient of variable var in the expression. Return true if var is unknown in the environment */ static inline bool ap_linexpr1_set_coeff(ap_linexpr1_t* expr, ap_var_t var, ap_coeff_t* coeff); static inline bool ap_linexpr1_set_coeff_scalar(ap_linexpr1_t* expr, ap_var_t var, ap_scalar_t* scalar); static inline bool ap_linexpr1_set_coeff_scalar_int(ap_linexpr1_t* expr, ap_var_t var, int num); static inline bool ap_linexpr1_set_coeff_scalar_frac(ap_linexpr1_t* expr, ap_var_t var, int num, unsigned int den); static inline bool ap_linexpr1_set_coeff_scalar_double(ap_linexpr1_t* expr, ap_var_t var, double num); static inline bool ap_linexpr1_set_coeff_interval(ap_linexpr1_t* expr, ap_var_t var, ap_interval_t* itv); static inline bool ap_linexpr1_set_coeff_interval_scalar(ap_linexpr1_t* expr, ap_var_t var, ap_scalar_t* inf, ap_scalar_t* sup); static inline bool ap_linexpr1_set_coeff_interval_int(ap_linexpr1_t* expr, ap_var_t var, int inf, int sup); static inline bool ap_linexpr1_set_coeff_interval_frac(ap_linexpr1_t* expr, ap_var_t var, int numinf, unsigned int deninf, int numsup, unsigned int densup); static inline bool ap_linexpr1_set_coeff_interval_double(ap_linexpr1_t* expr, ap_var_t var, double inf, double sup); /* bool ap_linexpr1_set_format(ap_linexpr1_t* expr, char* fmt, ...); */ bool ap_linexpr1_set_list(ap_linexpr1_t* expr, ...); /* Iterator (Macro): use: ap_linexpr1_ForeachLinterm(ap_linexpr1_t* e, size_t i, ap_var_t v, ap_coeff_t* coeff){ .. } where - e is the inspected expression, - i is the internal iterator - var is the variable of one linear term - coeff is a pointer to the corresponding coefficient */ #define ap_linexpr1_ForeachLinterm1(_p_e_, _p_i_, _p_var_, _p_ap_coeff_) \ for ((_p_i_)=0; \ (_p_i_)<(_p_e_)->linexpr0->size ? \ ((_p_e_)->linexpr0->discr==AP_LINEXPR_DENSE ? \ ((_p_var_) = ap_environment_var_of_dim((_p_e_)->env,(_p_i_)), \ (_p_ap_coeff_) = &(_p_e_)->linexpr0->p.coeff[(_p_i_)], \ true) : \ ((_p_var_) = ap_environment_var_of_dim((_p_e_)->env,\ (_p_e_)->linexpr0->p.linterm[(_p_i_)].dim), \ (_p_ap_coeff_) = &(_p_e_)->linexpr0->p.linterm[(_p_i_)].coeff, \ (_p_var_)!=NULL)) : \ false; \ (_p_i_)++) /* ====================================================================== */ /* IV. Change of dimensions and permutations */ /* ====================================================================== */ /* Change current environment with a super-environment. Return true if nenv is not a superenvironment */ bool ap_linexpr1_extend_environment(ap_linexpr1_t* nexpr, ap_linexpr1_t* expr, ap_environment_t* nenv); bool ap_linexpr1_extend_environment_with(ap_linexpr1_t* expr, ap_environment_t* nenv); /* ====================================================================== */ /* V. Inline function definitions */ /* ====================================================================== */ static inline void ap_linexpr1_minimize(ap_linexpr1_t* e){ ap_linexpr0_minimize(e->linexpr0); } static inline bool ap_linexpr1_is_integer(ap_linexpr1_t* e){ return ap_linexpr0_is_integer(e->linexpr0,e->env->intdim); } static inline bool ap_linexpr1_is_real(ap_linexpr1_t* e){ return ap_linexpr0_is_real(e->linexpr0,e->env->intdim); } static inline ap_linexpr_type_t ap_linexpr1_type(ap_linexpr1_t* e){ return ap_linexpr0_type(e->linexpr0); } static inline bool ap_linexpr1_is_linear(ap_linexpr1_t* e){ return ap_linexpr0_is_linear(e->linexpr0); } static inline bool ap_linexpr1_is_quasilinear(ap_linexpr1_t* e){ return ap_linexpr0_is_quasilinear(e->linexpr0); } static inline ap_environment_t* ap_linexpr1_envref(ap_linexpr1_t* e) { return e->env; } static inline ap_linexpr0_t* ap_linexpr1_linexpr0ref(ap_linexpr1_t* e) { return e->linexpr0; } static inline ap_coeff_t* ap_linexpr1_cstref(ap_linexpr1_t* expr){ return &expr->linexpr0->cst; } static inline void ap_linexpr1_get_cst(ap_coeff_t* cst, ap_linexpr1_t* expr){ ap_coeff_set(cst, &expr->linexpr0->cst); } static inline void ap_linexpr1_set_cst(ap_linexpr1_t* expr, ap_coeff_t* cst) { ap_coeff_set(&expr->linexpr0->cst,cst); } static inline void ap_linexpr1_set_cst_scalar(ap_linexpr1_t* expr, ap_scalar_t* scalar) { ap_coeff_set_scalar(&expr->linexpr0->cst, scalar); } static inline void ap_linexpr1_set_cst_scalar_int(ap_linexpr1_t* expr, int num) { ap_coeff_set_scalar_int(&expr->linexpr0->cst, num); } static inline void ap_linexpr1_set_cst_scalar_frac(ap_linexpr1_t* expr, int num, unsigned int den) { ap_coeff_set_scalar_frac(&expr->linexpr0->cst, num, den); } static inline void ap_linexpr1_set_cst_scalar_double(ap_linexpr1_t* expr, double num) { ap_coeff_set_scalar_double(&expr->linexpr0->cst, num); } static inline void ap_linexpr1_set_cst_interval(ap_linexpr1_t* expr, ap_interval_t* itv) { ap_coeff_set_interval(&expr->linexpr0->cst, itv); } static inline void ap_linexpr1_set_cst_interval_int(ap_linexpr1_t* expr, int inf, int sup) { ap_coeff_set_interval_int(&expr->linexpr0->cst, inf,sup); } static inline void ap_linexpr1_set_cst_interval_scalar(ap_linexpr1_t* expr, ap_scalar_t* inf, ap_scalar_t* sup) { ap_coeff_set_interval_scalar(&expr->linexpr0->cst, inf,sup); } static inline void ap_linexpr1_set_cst_interval_frac(ap_linexpr1_t* expr, int numinf, unsigned int deninf, int numsup, unsigned int densup) { ap_coeff_set_interval_frac(&expr->linexpr0->cst, numinf,deninf, numsup,densup); } static inline void ap_linexpr1_set_cst_interval_double(ap_linexpr1_t* expr, double inf, double sup) { ap_coeff_set_interval_double(&expr->linexpr0->cst, inf,sup); } static inline bool ap_linexpr1_set_coeff(ap_linexpr1_t* expr, ap_var_t var, ap_coeff_t* coeff) { ap_coeff_t* ecoeff = ap_linexpr1_coeffref(expr,var); if (ecoeff){ap_coeff_set(ecoeff,coeff); return false;} else return true; } static inline bool ap_linexpr1_set_coeff_scalar(ap_linexpr1_t* expr, ap_var_t var, ap_scalar_t* scalar) { ap_coeff_t* ecoeff = ap_linexpr1_coeffref(expr,var); if (ecoeff){ ap_coeff_set_scalar(ecoeff,scalar); return false; } else return true; } static inline bool ap_linexpr1_set_coeff_scalar_int(ap_linexpr1_t* expr, ap_var_t var, int num) { ap_coeff_t* ecoeff = ap_linexpr1_coeffref(expr,var); if (ecoeff){ ap_coeff_set_scalar_int(ecoeff,num); return false; } else return true; } static inline bool ap_linexpr1_set_coeff_scalar_frac(ap_linexpr1_t* expr, ap_var_t var, int num, unsigned int den) { ap_coeff_t* ecoeff = ap_linexpr1_coeffref(expr,var); if (ecoeff){ ap_coeff_set_scalar_frac(ecoeff,num, den); return false; } else return true; } static inline bool ap_linexpr1_set_coeff_scalar_double(ap_linexpr1_t* expr, ap_var_t var, double num) { ap_coeff_t* ecoeff = ap_linexpr1_coeffref(expr,var); if (ecoeff){ ap_coeff_set_scalar_double(ecoeff,num); return false; } else return true; } static inline bool ap_linexpr1_set_coeff_interval(ap_linexpr1_t* expr, ap_var_t var, ap_interval_t* itv) { ap_coeff_t* ecoeff = ap_linexpr1_coeffref(expr,var); if (ecoeff){ ap_coeff_set_interval(ecoeff,itv); return false; } else return true; } static inline bool ap_linexpr1_set_coeff_interval_int(ap_linexpr1_t* expr, ap_var_t var, int inf, int sup) { ap_coeff_t* ecoeff = ap_linexpr1_coeffref(expr,var); if (ecoeff){ ap_coeff_set_interval_int(ecoeff,inf,sup); return false; } else return true; } static inline bool ap_linexpr1_set_coeff_interval_scalar(ap_linexpr1_t* expr, ap_var_t var, ap_scalar_t* inf, ap_scalar_t* sup) { ap_coeff_t* ecoeff = ap_linexpr1_coeffref(expr,var); if (ecoeff){ ap_coeff_set_interval_scalar(ecoeff,inf,sup); return false; } else return true; } static inline bool ap_linexpr1_set_coeff_interval_frac(ap_linexpr1_t* expr, ap_var_t var, int numinf, unsigned int deninf, int numsup, unsigned int densup) { ap_coeff_t* ecoeff = ap_linexpr1_coeffref(expr,var); if (ecoeff){ ap_coeff_set_interval_frac(ecoeff,numinf,deninf, numsup,densup); return false; } else return true; } static inline bool ap_linexpr1_set_coeff_interval_double(ap_linexpr1_t* expr, ap_var_t var, double inf, double sup) { ap_coeff_t* ecoeff = ap_linexpr1_coeffref(expr,var); if (ecoeff){ ap_coeff_set_interval_double(ecoeff,inf,sup); return false; } else return true; } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/ap_linearize.h0000640014525101416610000001216211122224307020612 0ustar bjeannetpopart/* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #ifndef _AP_LINEARIZE_H_ #define _AP_LINEARIZE_H_ #include "ap_manager.h" #include "ap_expr0.h" #include "ap_abstract0.h" #ifdef __cplusplus extern "C" { #endif /* ********************************************************************** */ /* I. Evaluation of interval linear expressions */ /* ********************************************************************** */ /* evaluate to interval */ ap_interval_t* ap_eval_linexpr0(ap_manager_t* man, ap_abstract0_t* abs, ap_linexpr0_t* expr, ap_scalar_discr_t discr, bool* pexact); /* These functions are dedicated to implementors of domains. They offer generic default implementations for some of the operations required by the APRON API, when there is no more specific and efficient implementation for the domain being implemented. To use them, the function allocating manager, which is specific to the domain, should put the corresponding pointers in the virtual table to them. They manipulated "unboxed" abstract values, which are native to the underlying library: they are not yet boxed with the manager in the type ap_abstract0_t. */ /* The following functions use the given abstract value for transforming interval linear expressions (resp. constraints, arrays of expressions, arrays od constraints) in quasilinear corresponding objects. They use to_box and dimension (and is_bottom if NDEBUG is undefined) generic functions. - discr allows to choose the type of scalars used for computations and for the result. - pexact is a pointer to a Boolean, which is set to true if all the conversions and computations were exact. For ap_quasilinearize_XXX functions, if the argument does not need any modification, then it is returned itself. Calling ap_linearize_linexpr0_array is more efficient than calling N times ap_linearize_linexpr0 because the conversion of abstract value to bounding boxes is done only once, as well as other internal allocations. */ /* ********************************************************************** */ /* II. Quasilinearization of interval linear expressions */ /* ********************************************************************** */ ap_linexpr0_t* ap_quasilinearize_linexpr0(ap_manager_t* man, void* abs, ap_linexpr0_t* linexpr0, bool* pexact, ap_scalar_discr_t discr); ap_lincons0_t ap_quasilinearize_lincons0(ap_manager_t* man, void* abs, ap_lincons0_t* lincons0, bool* pexact, ap_scalar_discr_t discr, bool meet); ap_linexpr0_t** ap_quasilinearize_linexpr0_array(ap_manager_t* man, void* abs, ap_linexpr0_t** texpr, size_t size, bool* pexact, ap_scalar_discr_t discr); ap_lincons0_array_t ap_quasilinearize_lincons0_array(ap_manager_t* man, void* abs, ap_lincons0_array_t* array, bool* pexact, ap_scalar_discr_t discr, bool linearize, bool meet); /* ********************************************************************** */ /* III. Evaluation of tree expressions */ /* ********************************************************************** */ ap_interval_t* ap_eval_texpr0(ap_manager_t* man, ap_abstract0_t* abs, ap_texpr0_t* expr, ap_scalar_discr_t discr, bool* pexact); /* ********************************************************************** */ /* IV. Interval linearization of linear tree expressions */ /* ********************************************************************** */ /* Linearize a tree expression that is (syntaxically) interval linear with exact arithmetic. Compared to ap_intlinearize_texpr0() function below, this functions does not require a bounding box for dimensions. If the precondition is violated, returns NULL. */ ap_linexpr0_t* ap_intlinearize_texpr0_intlinear(ap_manager_t* man, ap_texpr0_t* expr, ap_scalar_discr_t discr); /* ********************************************************************** */ /* V. Interval linearization of tree expressions */ /* ********************************************************************** */ ap_linexpr0_t* ap_intlinearize_texpr0(ap_manager_t* man, ap_abstract0_t* abs, ap_texpr0_t* expr, bool* pexact, ap_scalar_discr_t discr, bool quasilinearize); ap_linexpr0_t** ap_intlinearize_texpr0_array(ap_manager_t* man, ap_abstract0_t* abs, ap_texpr0_t** texpr, size_t size, bool* pexact, ap_scalar_discr_t discr, bool quasilinearize); ap_lincons0_t ap_intlinearize_tcons0(ap_manager_t* man, ap_abstract0_t* abs, ap_tcons0_t* cons, bool* pexact, ap_scalar_discr_t discr, bool quasilinearize, bool meet); ap_lincons0_array_t ap_intlinearize_tcons0_array(ap_manager_t* man, ap_abstract0_t* abs, ap_tcons0_array_t* array, bool* pexact, ap_scalar_discr_t discr, ap_linexpr_type_t type, bool meet, bool boxize, size_t kmax, bool intervalonly); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/ap_generator0.c0000640014525101416610000000766610656607177020733 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_generator0.c: generators and arrays */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "ap_generator0.h" /* ********************************************************************** */ /* I. Generators */ /* ********************************************************************** */ void ap_generator0_fprint(FILE* stream, ap_generator0_t* gen, char** name_of_dim) { char* str = NULL; switch(gen->gentyp){ case AP_GEN_LINE: str = "LINE: "; break; case AP_GEN_RAY: str = "RAY: "; break; case AP_GEN_VERTEX: str = "VERTEX: "; break; case AP_GEN_LINEMOD: str = "LINEMOD: "; break; case AP_GEN_RAYMOD: str = "RAYMOD: "; break; } fprintf(stream,"%s",str); ap_linexpr0_fprint(stream,gen->linexpr0,name_of_dim); } /* ********************************************************************** */ /* II. Array of Generators */ /* ********************************************************************** */ ap_generator0_array_t ap_generator0_array_make(size_t size) { size_t i; ap_generator0_array_t array; array.size = size; array.p = (size==0) ? NULL : (ap_generator0_t*)malloc(size*sizeof(ap_generator0_t)); for (i=0; isize; i++){ ap_generator0_clear(&array->p[i]); } array->p = (ap_generator0_t*)realloc(array->p,size*sizeof(ap_generator0_t)); for (i=array->size; ip[i].linexpr0 = NULL; array->size = size; } void ap_generator0_array_clear(ap_generator0_array_t* array) { size_t i; if (array->p!=NULL){ for (i=0; isize; i++) ap_generator0_clear(&array->p[i]); free(array->p); array->p = NULL; } array->size=0; } void ap_generator0_array_fprint(FILE* stream, ap_generator0_array_t* array, char** name_of_dim) { size_t i; if (array->size==0){ fprintf(stream,"empty array of generators\n"); } else { fprintf(stream,"array of generator of size %lu\n", (unsigned long)array->size); for (i=0; isize; i++){ fprintf(stream,"%2lu: ",(unsigned long)i); ap_generator0_fprint(stream,&array->p[i],name_of_dim); fprintf(stream,"\n"); } } } /* ====================================================================== */ /* II.1 Change of dimensions and permutations */ /* ====================================================================== */ void ap_generator0_array_add_dimensions_with(ap_generator0_array_t* array, ap_dimchange_t* dimchange) { size_t i; for(i=0; isize; i++){ ap_linexpr0_t* expr = array->p[i].linexpr0; if (expr) ap_linexpr0_add_dimensions_with(expr,dimchange); } } ap_generator0_array_t ap_generator0_array_add_dimensions(ap_generator0_array_t* array, ap_dimchange_t* dimchange) { size_t i; ap_generator0_array_t narray; narray = ap_generator0_array_make(array->size); for(i=0; isize; i++){ narray.p[i] = ap_generator0_add_dimensions(&array->p[i], dimchange); } return narray; } void ap_generator0_array_permute_dimensions_with(ap_generator0_array_t* array, ap_dimperm_t* perm) { size_t i; for(i=0; isize; i++){ ap_linexpr0_t* expr = array->p[i].linexpr0; if (expr) ap_linexpr0_permute_dimensions_with(expr,perm); } } ap_generator0_array_t ap_generator0_array_permute_dimensions(ap_generator0_array_t* array, ap_dimperm_t* perm) { size_t i; ap_generator0_array_t narray; narray = ap_generator0_array_make(array->size); for(i=0; isize; i++){ narray.p[i] = ap_generator0_permute_dimensions(&array->p[i], perm); } return narray; } apron-dist-0.9.10/apron/apron/ap_generator1.c0000640014525101416610000001452410571032754020710 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_generator1.c: linear generators */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "ap_generator1.h" /* ********************************************************************** */ /* I. ap_generator0_t */ /* ********************************************************************** */ /* ====================================================================== */ /* I.1 Memory management and printing */ /* ====================================================================== */ void ap_generator1_clear(ap_generator1_t* gen) { ap_generator0_clear(&gen->generator0); if (gen->env){ ap_environment_free(gen->env); gen->env = NULL; } } void ap_generator1_fprint(FILE* stream, ap_generator1_t* gen) { ap_environment_name_of_dim_t* name_of_dim; name_of_dim = ap_environment_name_of_dim_alloc(gen->env); ap_generator0_fprint(stream, &gen->generator0, name_of_dim->p); ap_environment_name_of_dim_free(name_of_dim); } /* ====================================================================== */ /* I.2 Tests */ /* ====================================================================== */ /* ====================================================================== */ /* I.3 Access */ /* ====================================================================== */ ap_coeff_t* ap_generator1_coeffref(ap_generator1_t* gen, ap_var_t var) { ap_dim_t dim = ap_environment_dim_of_var(gen->env,var); return ap_linexpr0_coeffref(gen->generator0.linexpr0,dim); } bool ap_generator1_get_coeff(ap_coeff_t* coeff, ap_generator1_t* gen, ap_var_t var) { ap_dim_t dim = ap_environment_dim_of_var(gen->env,var); return ap_linexpr0_get_coeff(coeff,gen->generator0.linexpr0,dim); } ap_coeff_t* ap_generator1_set_list_get_pcoeff(void* gen, bool cst, va_list* va) { ap_coeff_t* pcoeff; if (cst){ pcoeff = ap_generator1_cstref(gen); } else { ap_var_t var = va_arg(*va,ap_var_t); pcoeff = ap_generator1_coeffref(gen,var); } return pcoeff; } bool ap_generator1_set_list(ap_generator1_t* gen, ...) { va_list va; bool res; va_start(va,gen); res = ap_linexpr0_set_list_generic(ap_generator1_set_list_get_pcoeff, gen,&va); va_end(va); return res; } /* ====================================================================== */ /* I.4 Change of dimensions and permutations */ /* ====================================================================== */ bool ap_generator1_extend_environment(ap_generator1_t* ngen, ap_generator1_t* gen, ap_environment_t* nenv) { ap_dimchange_t* dimchange = ap_environment_dimchange(gen->env,nenv); if (dimchange==NULL) return true; ngen->generator0 = ap_generator0_add_dimensions(&gen->generator0,dimchange); ngen->env = ap_environment_copy(nenv); ap_dimchange_free(dimchange); return false; } bool ap_generator1_extend_environment_with(ap_generator1_t* gen, ap_environment_t* nenv) { ap_environment_t* env; ap_dimchange_t* dimchange = ap_environment_dimchange(gen->env,nenv); if (dimchange==NULL) return true; ap_generator0_add_dimensions_with(&gen->generator0,dimchange); env = gen->env; gen->env = ap_environment_copy(nenv); ap_dimchange_free(dimchange); ap_environment_free(env); return false; } /* ********************************************************************** */ /* II. Array of linear generators */ /* ********************************************************************** */ /* ====================================================================== */ /* I.1 Memory management and printing */ /* ====================================================================== */ ap_generator1_array_t ap_generator1_array_make(ap_environment_t* env, size_t size) { ap_generator1_array_t array; array.generator0_array = ap_generator0_array_make(size); array.env = ap_environment_copy(env); return array; } void ap_generator1_array_clear(ap_generator1_array_t* array) { ap_generator0_array_clear(&array->generator0_array); ap_environment_free(array->env); array->env = NULL; } void ap_generator1_array_fprint(FILE* stream, ap_generator1_array_t* array) { ap_environment_name_of_dim_t* name_of_dim; name_of_dim = ap_environment_name_of_dim_alloc(array->env); ap_generator0_array_fprint(stream,&array->generator0_array,name_of_dim->p); ap_environment_name_of_dim_free(name_of_dim); } /* ====================================================================== */ /* II.3 Access */ /* ====================================================================== */ ap_generator1_t ap_generator1_array_get(ap_generator1_array_t* array, size_t index) { ap_generator1_t gen; gen.generator0 = array->generator0_array.p[index]; gen.env = array->env; return gen; } bool ap_generator1_array_set(ap_generator1_array_t* array, size_t index, ap_generator1_t* gen) { if (index>=array->generator0_array.size || !ap_environment_is_eq(gen->env,array->env)) return true; ap_generator1_array_clear_index(array,index); array->generator0_array.p[index] = gen->generator0; ap_environment_free(gen->env); return false; } /* ====================================================================== */ /* II.4 Change of dimensions and permutations */ /* ====================================================================== */ bool ap_generator1_array_extend_environment_with(ap_generator1_array_t* array, ap_environment_t* nenv) { ap_environment_t* env; ap_dimchange_t* dimchange = ap_environment_dimchange(array->env,nenv); if (dimchange==NULL) return true; ap_generator0_array_add_dimensions_with(&array->generator0_array,dimchange); env = array->env; array->env = ap_environment_copy(nenv); ap_dimchange_free(dimchange); ap_environment_free(env); return false; } bool ap_generator1_array_extend_environment(ap_generator1_array_t* narray, ap_generator1_array_t* array, ap_environment_t* nenv) { ap_dimchange_t* dimchange = ap_environment_dimchange(array->env,nenv); if (dimchange==NULL) return true; narray->generator0_array = ap_generator0_array_add_dimensions(&array->generator0_array,dimchange); narray->env = ap_environment_copy(nenv); ap_dimchange_free(dimchange); return false; } apron-dist-0.9.10/apron/apron/ap_abstract1.h0000640014525101416610000004225510760562320020531 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_abstract1.h: generic operations on abstract values at level 1 */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ /* GENERATED FROM ap_abstract1.nw: DO NOT MODIFY ! */ #ifndef _AP_ABSTRACT1_H_ #define _AP_ABSTRACT1_H_ #include "ap_manager.h" #include "ap_abstract0.h" #include "ap_expr1.h" #ifdef __cplusplus extern "C" { #endif typedef struct ap_abstract1_t { ap_abstract0_t* abstract0; ap_environment_t* env; } ap_abstract1_t; /* data structure invariant: ap_abstract0_integer_dimension(man,abstract0)== env->intdim && ap_abstract0_real_dimension(man,abstract0)== env->realdim */ typedef struct ap_box1_t { ap_interval_t** p; ap_environment_t* env; } ap_box1_t; void ap_box1_fprint(FILE* stream, ap_box1_t* box); void ap_box1_clear(ap_box1_t* box); /* ********************************************************************** */ /* I. General management */ /* ********************************************************************** */ /* ============================================================ */ /* I.1 Memory */ /* ============================================================ */ ap_abstract1_t ap_abstract1_copy(ap_manager_t* man, ap_abstract1_t* a); /* Return a copy of an abstract value, on which destructive update does not affect the initial value. */ void ap_abstract1_clear(ap_manager_t* man, ap_abstract1_t* a); /* Free all the memory used by the abstract value */ size_t ap_abstract1_size(ap_manager_t* man, ap_abstract1_t* a); /* Return the abstract size of an abstract value (see ap_manager_t) */ /* ============================================================ */ /* I.2 Control of internal representation */ /* ============================================================ */ void ap_abstract1_minimize(ap_manager_t* man, ap_abstract1_t* a); /* Minimize the size of the representation of a. This may result in a later recomputation of internal information. */ void ap_abstract1_canonicalize(ap_manager_t* man, ap_abstract1_t* a); /* Put the abstract value in canonical form. (not yet clear definition) */ int ap_abstract1_hash(ap_manager_t* man, ap_abstract1_t* a); /* Return an hash value for the abstract value. Two abstract values in canonical from (according to ap_abstract1_canonicalize) and considered as equal by the function ap_abstract0_is_eq are given the same hash value. */ /* Return an hash code (assume canonical form) */ void ap_abstract1_approximate(ap_manager_t* man, ap_abstract1_t* a, int algorithm); /* Perform some transformation on the abstract value, guided by the field algorithm. The transformation may lose information. The argument "algorithm" overrides the field algorithm of the structure of type foption_t associated to ap_abstract1_approximate (commodity feature). */ /* ============================================================ */ /* I.3 Printing */ /* ============================================================ */ void ap_abstract1_fprint(FILE* stream, ap_manager_t* man, ap_abstract1_t* a); /* Print the abstract value in a pretty way */ void ap_abstract1_fprintdiff(FILE* stream, ap_manager_t* man, ap_abstract1_t* a1, ap_abstract1_t* a2); /* Print the difference between a1 (old value) and a2 (new value). The meaning of difference is library dependent. */ void ap_abstract1_fdump(FILE* stream, ap_manager_t* man, ap_abstract1_t* a); /* Dump the internal representation of an abstract value, for debugging purposes. */ /* ============================================================ */ /* I.4 Serialization */ /* ============================================================ */ ap_membuf_t ap_abstract1_serialize_raw(ap_manager_t* man, ap_abstract1_t* a); /* Allocate a memory buffer (with malloc), output the abstract value in raw binary format to it and return a pointer on the memory buffer and the size of bytes written. It is the user responsibility to free the memory afterwards (with free). */ ap_abstract1_t ap_abstract1_deserialize_raw(ap_manager_t* man, void* ptr, size_t* size); /* Return the abstract value read in raw binary format from the input stream and store in size the number of bytes read */ /* ********************************************************************** */ /* II. Constructor, accessors, tests and property extraction */ /* ********************************************************************** */ /* ============================================================ */ /* II.1 Basic constructors */ /* ============================================================ */ ap_abstract1_t ap_abstract1_bottom(ap_manager_t* man, ap_environment_t* env); /* Create a bottom (empty) value defined on the environment */ ap_abstract1_t ap_abstract1_top(ap_manager_t* man, ap_environment_t* env); /* Create a top (universe) value defined on the environment */ ap_abstract1_t ap_abstract1_of_box(ap_manager_t* man, ap_environment_t* env, ap_var_t* tvar, ap_interval_t** tinterval, size_t size); /* Abstract an hypercube defined by the arrays tvar and tinterval, satisfying: forall i, tvar[i] in tinterval[i]. If no inclusion is specified for a variable in the environment, its value is no constrained in the resulting abstract value. */ /* ============================================================ */ /* II.2 Accessors */ /* ============================================================ */ ap_environment_t* ap_abstract1_environment(ap_manager_t* man, ap_abstract1_t* a); ap_abstract0_t* ap_abstract1_abstract0(ap_manager_t* man, ap_abstract1_t* a); /* ============================================================ */ /* II.3 Tests */ /* ============================================================ */ /* In abstract tests, - true means that the predicate is certainly true. - false means by default don't know (an exception has occurred, or the exact computation was considered too expensive to be performed). However, if the flag exact in the manager is true, then false means really that the predicate is false. */ bool ap_abstract1_is_bottom(ap_manager_t* man, ap_abstract1_t* a); bool ap_abstract1_is_top(ap_manager_t* man, ap_abstract1_t* a); bool ap_abstract1_is_leq(ap_manager_t* man, ap_abstract1_t* a1, ap_abstract1_t* a2); /* inclusion check */ bool ap_abstract1_is_eq(ap_manager_t* man, ap_abstract1_t* a1, ap_abstract1_t* a2); /* equality check */ bool ap_abstract1_sat_lincons(ap_manager_t* man, ap_abstract1_t* a, ap_lincons1_t* lincons); bool ap_abstract1_sat_tcons(ap_manager_t* man, ap_abstract1_t* a, ap_tcons1_t* tcons); /* does the abstract value satisfy the constraint ? */ bool ap_abstract1_sat_interval(ap_manager_t* man, ap_abstract1_t* a, ap_var_t var, ap_interval_t* interval); /* is the dimension included in the interval in the abstract value ? - Raises an exception if var is unknown in the environment of the abstract value */ bool ap_abstract1_is_variable_unconstrained(ap_manager_t* man, ap_abstract1_t* a, ap_var_t var); /* is the variable unconstrained in the abstract value ? - Raises an exception if var is unknown in the environment of the abstract value */ /* ============================================================ */ /* II.4 Extraction of properties */ /* ============================================================ */ ap_interval_t* ap_abstract1_bound_linexpr(ap_manager_t* man, ap_abstract1_t* a, ap_linexpr1_t* expr); ap_interval_t* ap_abstract1_bound_texpr(ap_manager_t* man, ap_abstract1_t* a, ap_texpr1_t* expr); /* Returns the interval taken by the expression over the abstract value. */ ap_interval_t* ap_abstract1_bound_variable(ap_manager_t* man, ap_abstract1_t* a, ap_var_t var); /* Returns the interval taken by the variable over the abstract value - Raises an exception if var is unknown in the environment of the abstract value */ ap_lincons1_array_t ap_abstract1_to_lincons_array(ap_manager_t* man, ap_abstract1_t* a); ap_tcons1_array_t ap_abstract1_to_tcons_array(ap_manager_t* man, ap_abstract1_t* a); /* Converts an abstract value to conjunction of constraints. The environment of the result is a copy of the environment of the abstract value. */ ap_box1_t ap_abstract1_to_box(ap_manager_t* man, ap_abstract1_t* a); /* Converts an abstract value to an interval/hypercube. */ ap_generator1_array_t ap_abstract1_to_generator_array(ap_manager_t* man, ap_abstract1_t* a); /* Converts an abstract value to a system of generators. - The environment of the result is a copy of the environment of the abstract value. */ /* ********************************************************************** */ /* III. Operations: functional version */ /* ********************************************************************** */ /* ============================================================ */ /* III.1 Meet and Join */ /* ============================================================ */ ap_abstract1_t ap_abstract1_meet(ap_manager_t* man, bool destructive, ap_abstract1_t* a1, ap_abstract1_t* a2); ap_abstract1_t ap_abstract1_join(ap_manager_t* man, bool destructive, ap_abstract1_t* a1, ap_abstract1_t* a2); /* Meet and Join of 2 abstract values - The environment of the result is the lce of the arguments - Raises an EXC_INVALID_ARGUMENT exception if the lce does not exists */ ap_abstract1_t ap_abstract1_meet_array(ap_manager_t* man, ap_abstract1_t* tab, size_t size); ap_abstract1_t ap_abstract1_join_array(ap_manager_t* man, ap_abstract1_t* tab, size_t size); /* Meet and Join of an array of abstract values. - Raises an [[exc_invalid_argument]] exception if [[size==0]] (no way to define the dimensionality of the result in such a case - The environment of the result is the lce of the arguments - Raises an EXC_INVALID_ARGUMENT exception if the lce does not exists */ ap_abstract1_t ap_abstract1_meet_lincons_array(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_lincons1_array_t* array); ap_abstract1_t ap_abstract1_meet_tcons_array(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_tcons1_array_t* array); /* Meet of an abstract value with a set of constraints. */ ap_abstract1_t ap_abstract1_add_ray_array(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_generator1_array_t* array); /* Generalized time elapse operator */ /* ============================================================ */ /* III.2 Assignment and Substitutions */ /* ============================================================ */ /* Parallel Assignment and Substitution of several dimensions by expressions. */ ap_abstract1_t ap_abstract1_assign_linexpr_array(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t* tvar, ap_linexpr1_t* texpr, size_t size, ap_abstract1_t* dest); ap_abstract1_t ap_abstract1_substitute_linexpr_array(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t* tvar, ap_linexpr1_t* texpr, size_t size, ap_abstract1_t* dest); ap_abstract1_t ap_abstract1_assign_texpr_array(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t* tvar, ap_texpr1_t* texpr, size_t size, ap_abstract1_t* dest); ap_abstract1_t ap_abstract1_substitute_texpr_array(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t* tvar, ap_texpr1_t* texpr, size_t size, ap_abstract1_t* dest); /* ============================================================ */ /* III.3 Projections */ /* ============================================================ */ ap_abstract1_t ap_abstract1_forget_array(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t* tvar, size_t size, bool project); /* ============================================================ */ /* III.4 Change of environment */ /* ============================================================ */ ap_abstract1_t ap_abstract1_change_environment(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_environment_t* nenv, bool project); ap_abstract1_t ap_abstract1_minimize_environment(ap_manager_t* man, bool destructive, ap_abstract1_t* a); /* Remove from the environment of the abstract value variables that are unconstrained in it. */ ap_abstract1_t ap_abstract1_rename_array(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t* var, ap_var_t* nvar, size_t size); /* Parallel renaming. The new variables should not interfere with the variables that are not renamed. */ /* ============================================================ */ /* III.5 Expansion and folding of dimensions */ /* ============================================================ */ ap_abstract1_t ap_abstract1_expand(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t var, ap_var_t* tvar, size_t size); /* Expand the variable var into itself + the size additional variables of the array tvar, which are given the same type as var. It results in (size+1) unrelated variables having same relations with other variables. The additional variables are added to the environment of the argument for making the environment of the result. */ ap_abstract1_t ap_abstract1_fold(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t* tvar, size_t size); /* Fold the dimensions in the array tvar of size n>=1 and put the result in the first variable in the array. The other variables of the array are then forgot and removed from the environment. */ /* ============================================================ */ /* III.6 Widening */ /* ============================================================ */ /* Widening */ ap_abstract1_t ap_abstract1_widening(ap_manager_t* man, ap_abstract1_t* a1, ap_abstract1_t* a2); /* Widening with threshold */ ap_abstract1_t ap_abstract1_widening_threshold(ap_manager_t* man, ap_abstract1_t* a1, ap_abstract1_t* a2, ap_lincons1_array_t* array); /* ============================================================ */ /* III.7 Closure operation */ /* ============================================================ */ /* Returns the topological closure of a possibly opened abstract value */ ap_abstract1_t ap_abstract1_closure(ap_manager_t* man, bool destructive, ap_abstract1_t* a); /* ============================================================ */ /* IV. Additional functions */ /* ============================================================ */ ap_abstract1_t ap_abstract1_of_lincons_array(ap_manager_t* man, ap_environment_t* env, ap_lincons1_array_t* array); ap_abstract1_t ap_abstract1_of_tcons_array(ap_manager_t* man, ap_environment_t* env, ap_tcons1_array_t* array); /* Abstract a conjunction of constraints and return an abstract value defined on the given environment. */ ap_abstract1_t ap_abstract1_assign_linexpr(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t var, ap_linexpr1_t* expr, ap_abstract1_t* dest); ap_abstract1_t ap_abstract1_substitute_linexpr(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t var, ap_linexpr1_t* expr, ap_abstract1_t* dest); ap_abstract1_t ap_abstract1_assign_texpr(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t var, ap_texpr1_t* expr, ap_abstract1_t* dest); ap_abstract1_t ap_abstract1_substitute_texpr(ap_manager_t* man, bool destructive, ap_abstract1_t* a, ap_var_t var, ap_texpr1_t* expr, ap_abstract1_t* dest); /* Assignment and Substitution of a single dimension by an expression */ ap_abstract1_t ap_abstract1_unify(ap_manager_t* man, bool destructive, ap_abstract1_t* a1,ap_abstract1_t* a2); /* Unify two abstract values on their common variables, that is, embed them on the least common environment and then compute their meet. The result is defined on the least common environment. Ex: unify of {x=y, defined on {x,y}} and {y=z+t, defined on {y,z,t}} gives {x=y and y=z+t, defined on {x,y,z,t}}. */ ap_linexpr1_t ap_abstract1_quasilinear_of_intlinear(ap_manager_t* man, ap_abstract1_t* a, ap_linexpr1_t* expr, ap_scalar_discr_t discr); /* Evaluate the interval linear expression expr on the abstract value a and approximate it by a quasilinear expression. discr indicates which type of numbers should be used for computations. This implies calls to ap_abstract0_bound_dimension. */ ap_linexpr1_t ap_abstract1_intlinear_of_tree (ap_manager_t* man, ap_abstract1_t* a, ap_texpr1_t* expr, ap_scalar_discr_t discr, bool quasilinearize); /* Evaluate the tree expression expr on the abstract value a and approximate it by an interval linear (resp. quasilinear if quasilinearize is true) expression. discr indicates which type of numbers should be used for computations. This implies calls to ap_abstract0_bound_dimension. */ #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/apron/ap_texpr1.c0000640014525101416610000002005211006063143020043 0ustar bjeannetpopart/* ************************************************************************* */ /* ap_texpr1.c: tree expressions */ /* ************************************************************************* */ /* This file is part of the APRON Library, released under LGPL license. Please read the COPYING file packaged in the distribution */ #include "ap_texpr1.h" #include /* ====================================================================== */ /* I. Constructors and Destructors */ /* ====================================================================== */ static inline ap_texpr1_t* ap_texpr1_of_texpr0(ap_environment_t* env, ap_texpr0_t* texpr0) { ap_texpr1_t* res = malloc(sizeof(ap_texpr1_t)); res->texpr0 = texpr0; res->env = ap_environment_copy(env); return res; } ap_texpr1_t* ap_texpr1_cst (ap_environment_t* env, ap_coeff_t* coeff) { return ap_texpr1_of_texpr0(env, ap_texpr0_cst(coeff)); } ap_texpr1_t* ap_texpr1_cst_scalar (ap_environment_t* env, ap_scalar_t* scalar) { return ap_texpr1_of_texpr0(env, ap_texpr0_cst_scalar(scalar)); } ap_texpr1_t* ap_texpr1_cst_scalar_mpq (ap_environment_t* env, mpq_t mpq) { return ap_texpr1_of_texpr0(env, ap_texpr0_cst_scalar_mpq(mpq)); } ap_texpr1_t* ap_texpr1_cst_scalar_mpfr (ap_environment_t* env, mpfr_t mpfr) { return ap_texpr1_of_texpr0(env, ap_texpr0_cst_scalar_mpfr(mpfr)); } ap_texpr1_t* ap_texpr1_cst_scalar_int (ap_environment_t* env, long int num) { return ap_texpr1_of_texpr0(env, ap_texpr0_cst_scalar_int(num)); } ap_texpr1_t* ap_texpr1_cst_scalar_frac (ap_environment_t* env, long int num, unsigned long int den) { return ap_texpr1_of_texpr0(env, ap_texpr0_cst_scalar_frac(num,den)); } ap_texpr1_t* ap_texpr1_cst_scalar_double (ap_environment_t* env, double num) { return ap_texpr1_of_texpr0(env, ap_texpr0_cst_scalar_double(num)); } ap_texpr1_t* ap_texpr1_cst_interval (ap_environment_t* env, ap_interval_t* itv) { return ap_texpr1_of_texpr0(env, ap_texpr0_cst_interval(itv)); } ap_texpr1_t* ap_texpr1_cst_interval_scalar (ap_environment_t* env, ap_scalar_t* inf, ap_scalar_t* sup) { return ap_texpr1_of_texpr0(env, ap_texpr0_cst_interval_scalar(inf,sup)); } ap_texpr1_t* ap_texpr1_cst_interval_mpq (ap_environment_t* env, mpq_t inf, mpq_t sup) { return ap_texpr1_of_texpr0(env, ap_texpr0_cst_interval_mpq(inf,sup)); } ap_texpr1_t* ap_texpr1_cst_interval_mpfr (ap_environment_t* env, mpfr_t inf, mpfr_t sup) { return ap_texpr1_of_texpr0(env, ap_texpr0_cst_interval_mpfr(inf,sup)); } ap_texpr1_t* ap_texpr1_cst_interval_int (ap_environment_t* env, long int inf, long int sup) { return ap_texpr1_of_texpr0(env, ap_texpr0_cst_interval_int(inf,sup)); } ap_texpr1_t* ap_texpr1_cst_interval_frac (ap_environment_t* env, long int numinf, unsigned long int deninf, long int numsup, unsigned long int densup) { return ap_texpr1_of_texpr0(env, ap_texpr0_cst_interval_frac(numinf,deninf,numsup,densup)); } ap_texpr1_t* ap_texpr1_cst_interval_double (ap_environment_t* env, double inf, double sup) { return ap_texpr1_of_texpr0(env, ap_texpr0_cst_interval_double(inf,sup)); } ap_texpr1_t* ap_texpr1_cst_interval_top (ap_environment_t* env) { return ap_texpr1_of_texpr0(env, ap_texpr0_cst_interval_top()); } ap_texpr1_t* ap_texpr1_var (ap_environment_t* env, ap_var_t var) { ap_dim_t dim = ap_environment_dim_of_var(env, var); if (dim==AP_DIM_MAX) return NULL; else return ap_texpr1_of_texpr0(env, ap_texpr0_dim(dim)); } ap_texpr1_t* ap_texpr1_node(ap_texpr_op_t op, ap_texpr_rtype_t type, ap_texpr_rdir_t dir, ap_texpr1_t* opA, ap_texpr1_t* opB) { if (opB!=NULL && !ap_environment_is_eq(opA->env, opB->env)) return NULL; ap_texpr0_t* texpr0 = ap_texpr0_node(op,type,dir,opA->texpr0,opB ? opB->texpr0 : NULL); ap_texpr1_t* texpr1 = ap_texpr1_of_texpr0(opA->env,texpr0); ap_environment_free(opA->env); free(opA); if (opB){ ap_environment_free(opB->env); free(opB); } return texpr1; } ap_texpr1_t* ap_texpr1_unop(ap_texpr_op_t op, ap_texpr1_t* opA, ap_texpr_rtype_t type, ap_texpr_rdir_t dir) { return ap_texpr1_node(op,type,dir,opA,NULL); } ap_texpr1_t* ap_texpr1_binop(ap_texpr_op_t op, ap_texpr1_t* opA, ap_texpr1_t* opB, ap_texpr_rtype_t type, ap_texpr_rdir_t dir) { return ap_texpr1_node(op,type,dir,opA,opB); } ap_texpr1_t* ap_texpr1_copy(ap_texpr1_t* expr) { if (!expr) return NULL; return ap_texpr1_of_texpr0(expr->env,ap_texpr0_copy(expr->texpr0)); } void ap_texpr1_free(ap_texpr1_t* expr) { if (!expr) return; ap_environment_free(expr->env); ap_texpr0_free(expr->texpr0); free(expr); } ap_texpr1_t* ap_texpr1_from_linexpr1(ap_linexpr1_t* e) { return ap_texpr1_of_texpr0(e->env, ap_texpr0_from_linexpr0(e->linexpr0)); } /* ====================================================================== */ /* II. Printing */ /* ====================================================================== */ void ap_texpr1_fprint(FILE* stream, ap_texpr1_t* a) { if (!a) return; ap_environment_name_of_dim_t* name_of_dim; name_of_dim = ap_environment_name_of_dim_alloc(a->env); ap_texpr0_fprint(stream,a->texpr0,name_of_dim->p); ap_environment_name_of_dim_free(name_of_dim); } /* ====================================================================== */ /* III. Tests, size */ /* ====================================================================== */ bool ap_texpr1_has_var(ap_texpr1_t* a, ap_var_t var) { if (!a) return false; ap_dim_t dim = ap_environment_dim_of_var(a->env, var); if (dim==AP_DIM_MAX) return false; else return ap_texpr0_has_dim(a->texpr0, dim); } /* ====================================================================== */ /* IV. Operations */ /* ====================================================================== */ ap_texpr1_t* ap_texpr1_substitute(ap_texpr1_t* a, ap_var_t var, ap_texpr1_t *dst) { if (!a || !dst || !ap_environment_is_eq(a->env, dst->env)) return NULL; ap_dim_t dim = ap_environment_dim_of_var(a->env,var); if (dim==AP_DIM_MAX) return NULL; return ap_texpr1_of_texpr0(a->env, ap_texpr0_substitute(a->texpr0,dim,dst->texpr0)); } /* Return true if var is unknown, or incompatible environment */ bool ap_texpr1_substitute_with(ap_texpr1_t* a, ap_var_t var, ap_texpr1_t *dst) { if (!a || !dst || !ap_environment_is_eq(a->env, dst->env)) return true; ap_dim_t dim = ap_environment_dim_of_var(a->env,var); if (dim==AP_DIM_MAX) return true; ap_texpr0_substitute_with(a->texpr0,dim,dst->texpr0); return false; } /* ====================================================================== */ /* V. Change of dimensions and permutations */ /* ====================================================================== */ ap_texpr1_t* ap_texpr1_extend_environment_dimchange(ap_texpr1_t* expr, ap_environment_t* nenv, ap_dimchange_t* dimchange) { return ap_texpr1_of_texpr0(nenv,ap_texpr0_add_dimensions(expr->texpr0,dimchange)); } void ap_texpr1_extend_environment_dimchange_with(ap_texpr1_t* expr, ap_environment_t* nenv, ap_dimchange_t* dimchange) { ap_environment_t* env; ap_texpr0_add_dimensions_with(expr->texpr0,dimchange); env = expr->env; expr->env = ap_environment_copy(nenv); ap_environment_free(env); } ap_texpr1_t* ap_texpr1_extend_environment(ap_texpr1_t* expr, ap_environment_t* nenv) { ap_dimchange_t* dimchange = ap_environment_dimchange(expr->env,nenv); if (dimchange==NULL) return NULL; ap_texpr1_t* res = ap_texpr1_extend_environment_dimchange(expr,nenv,dimchange); ap_dimchange_free(dimchange); return res; } bool ap_texpr1_extend_environment_with(ap_texpr1_t* expr, ap_environment_t* nenv) { ap_dimchange_t* dimchange = ap_environment_dimchange(expr->env,nenv); if (dimchange==NULL) return true; ap_texpr1_extend_environment_dimchange_with(expr,nenv,dimchange); ap_dimchange_free(dimchange); return false; } bool ap_texpr1_equal(ap_texpr1_t* a1, ap_texpr1_t* a2) { if (!a1 && !a2) return true; if (!a1 || !a2) return false; if (!ap_environment_is_eq(a1->env,a2->env)) return false; else return ap_texpr0_equal(a1->texpr0,a2->texpr0); } apron-dist-0.9.10/apron/num/0000750014525101416610000000000011252216460015461 5ustar bjeannetpopartapron-dist-0.9.10/apron/num/bound.h0000640014525101416610000001364610760562320016756 0ustar bjeannetpopart/* ********************************************************************** */ /* bound.h: numbers used for bounds */ /* ********************************************************************** */ #ifndef _BOUND_H_ #define _BOUND_H_ #ifndef _NUM_H_ #error "File bound.h requires num.h to be first included" #endif #include #include "ap_scalar.h" #include "bound_def.h" #ifdef __cplusplus extern "C" { #endif static inline bool bound_infty(bound_t a); /* Macro: static inline num_t bound_numref(bound_t a); */ /* ====================================================================== */ /* Assignement */ /* ====================================================================== */ static inline void bound_set(bound_t a, bound_t b); static inline void bound_set_array(bound_t* a, bound_t* b, size_t size); static inline void bound_set_int(bound_t a, long int i); static inline void bound_set_num(bound_t a, num_t b); static inline void bound_set_infty(bound_t a, int sgn); static inline void bound_swap(bound_t a, bound_t b); /* ====================================================================== */ /* Constructors and Destructors */ /* ====================================================================== */ static inline void bound_init(bound_t a); static inline void bound_init_array(bound_t* a, size_t size); static inline void bound_init_set(bound_t a, bound_t b); static inline void bound_init_set_int(bound_t a, long int i); static inline void bound_init_set_infty(bound_t a, int sgn); static inline void bound_clear(bound_t a); static inline void bound_clear_array(bound_t* a, size_t size); /* ====================================================================== */ /* Arithmetic Operations */ /* ====================================================================== */ /* +oo + -oo \ -oo + +oo | undefined +oo - +oo | -oo - -oo / +oo + x = +oo - x = x - -oo = +oo -oo + x = -oo - x = x - +oo = -oo 0 * +oo = +oo * 0 = 0 * -oo = -oo * 0 = 0 x * +oo = +oo * x = sign(x) * oo if x!=0 x * -oo = -oo * x = -sign(x) * oo if x!=0 0 / x = x / +oo = x / -oo = 0 x / 0 = sign(x) * oo if x!=0 +oo / x = sign(x) * oo if x!=0,+oo,-oo -oo / x = -sign(x) * oo if x!=0,+oo,-oo */ static inline void bound_neg(bound_t a, bound_t b); static inline void bound_abs(bound_t a, bound_t b); static inline void bound_add(bound_t a, bound_t b, bound_t c); static inline void bound_add_uint(bound_t a, bound_t b, unsigned long int c); static inline void bound_add_num(bound_t a, bound_t b, num_t c); static inline void bound_sub(bound_t a, bound_t b, bound_t c); static inline void bound_sub_uint(bound_t a, bound_t b, unsigned long int c); static inline void bound_sub_num(bound_t a, bound_t b, num_t c); static inline void bound_mul(bound_t a, bound_t b, bound_t c); static inline void bound_mul_num(bound_t a, bound_t b, num_t c); static inline void bound_mul_2(bound_t a, bound_t b); static inline void bound_div(bound_t a, bound_t b, bound_t c); static inline void bound_div_num(bound_t a, bound_t b, num_t c); static inline void bound_div_2(bound_t a, bound_t b); static inline void bound_min(bound_t a, bound_t b, bound_t c); static inline void bound_max(bound_t a, bound_t b, bound_t c); static inline void bound_mul_2exp(bound_t a, bound_t b, int c); static inline void bound_floor(bound_t a, bound_t b); static inline void bound_ceil(bound_t a, bound_t b); static inline void bound_trunc(bound_t a, bound_t b); static inline void bound_sqrt(bound_t up, bound_t down, bound_t b); /* ====================================================================== */ /* Floating-point casts */ /* ====================================================================== */ /* always rounds toward +oo */ static inline void bound_to_float(bound_t a, bound_t b); static inline void bound_to_double(bound_t a, bound_t b); /* ====================================================================== */ /* Arithmetic Tests */ /* ====================================================================== */ static inline int bound_sgn(bound_t a); static inline int bound_cmp(bound_t a, bound_t b); static inline int bound_cmp_int(bound_t a, long int b); static inline int bound_cmp_num(bound_t a, num_t b); static inline bool bound_equal(bound_t a, bound_t b); static inline int bound_hash(bound_t a); /* ====================================================================== */ /* Printing */ /* ====================================================================== */ static inline void bound_print(bound_t a); static inline void bound_fprint(FILE* stream, bound_t a); static inline int bound_snprint(char* s, size_t size, bound_t a); /* ====================================================================== */ /* Conversions */ /* ====================================================================== */ static inline bool bound_set_ap_scalar(bound_t a, ap_scalar_t* b); /* Convert a ap_scalar_t into a bound_t. */ /* Return true iff the conversion is exact */ static inline bool ap_scalar_set_bound(ap_scalar_t* a, bound_t b); /* Convert a bound_t into a ap_scalar_t */ /* Reinitialize a with the best type, depending on bound_t and num_t */ /* Return true iff the conversion is exact. Normally always return true, with the exception of long double type for num. */ /* ====================================================================== */ /* Serialization */ /* ====================================================================== */ /* Note: call _init before _deserialize */ static inline size_t bound_serialize(void* dst, bound_t src); static inline size_t bound_deserialize(bound_t dst, const void* src); static inline size_t bound_serialized_size(bound_t a); static inline size_t bound_serialize_array(void* dst, bound_t* src, size_t size); static inline size_t bound_deserialize_array(bound_t* dst, const void* src, size_t size); static inline size_t bound_serialized_size_array(bound_t* src, size_t size); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/num/essai.c0000640014525101416610000000066610416736077016756 0ustar bjeannetpopart #include #include typedef int bool; #define true (int)1 #define false (int)0 #define NUM_LONGDOUBLE #include "num.h" #include "bound.h" int main(int argc, char**argv) { bound_t a; double b,c,d; bound_init_set_int(a,-3); b = (double)1.0/(double)0.0; c = b; d = b+c; printf ("b=%.20g\nc=%.20g\nd=%.20g\n",b,c,d); c = 0; d = b*c; printf ("b=%.20g\nc=%.20g\nd=%.20g\n",b,c,d); return 0; } apron-dist-0.9.10/apron/num/numrat_mpq.h0000640014525101416610000002645011005654323020025 0ustar bjeannetpopart/* ********************************************************************** */ /* rational_mpq.h */ /* ********************************************************************** */ #ifndef _NUMRAT_MPQ_H_ #define _NUMRAT_MPQ_H_ #include #include #include #include #include #include #include #include "gmp.h" #include "mpfr.h" #include "ap_scalar.h" #include "num_config.h" #ifdef NUMINT_MPZ #include "numint.h" #else #error "HERE" #endif #ifdef __cplusplus extern "C" { #endif typedef mpq_t numrat_t; /* ====================================================================== */ /* Rational operations */ /* ====================================================================== */ static inline void numrat_canonicalize(numrat_t a) { mpq_canonicalize(a); } #define numrat_numref(a) mpq_numref(a) #define numrat_denref(a) mpq_denref(a) static inline bool numrat_set_numint2(numrat_t a, numint_t b, numint_t c) { numint_set(numrat_numref(a),b); numint_set(numrat_denref(a),c); numrat_canonicalize(a); return true; } /* ====================================================================== */ /* Assignement */ /* ====================================================================== */ static inline void numrat_set(numrat_t a, numrat_t b) { mpq_set(a,b); } static inline void numrat_set_array(numrat_t* a, numrat_t* b, size_t size) { size_t i; for (i=0; i=0 ? b : c); } static inline void numrat_floor(numrat_t a, numrat_t b) { numint_fdiv_q(numrat_numref(a),numrat_numref(b),numrat_denref(b)); numint_set_int(numrat_denref(a),1); } static inline void numrat_ceil(numrat_t a, numrat_t b) { numint_cdiv_q(numrat_numref(a),numrat_numref(b),numrat_denref(b)); numint_set_int(numrat_denref(a),1); } static inline void numrat_trunc(numrat_t a, numrat_t b) { numint_tdiv_q(numrat_numref(a),numrat_numref(b),numrat_denref(b)); numint_set_int(numrat_denref(a),1); } static inline void numrat_sqrt(numrat_t up, numrat_t down, numrat_t b) { /* compute sqrt(p/q) as sqrt(p*q)/q */ mpz_t tmp; int perfect; assert(mpq_sgn(b)>=0); mpz_init(tmp); mpz_mul(tmp,mpq_numref(b),mpq_denref(b)); perfect = mpz_perfect_square_p(tmp); mpz_sqrt(mpq_numref(down),tmp); if (perfect) mpz_set(mpq_numref(up),mpq_numref(down)); else mpz_add_ui(mpq_numref(up),mpq_numref(down),1); mpz_set(mpq_denref(up),mpq_denref(b)); mpz_set(mpq_denref(down),mpq_denref(b)); numrat_canonicalize(up); numrat_canonicalize(down); mpz_clear(tmp); } static inline void numrat_mul_2exp(numrat_t a, numrat_t b, int c) { if (c>=0) mpq_mul_2exp(a,b,c); else mpq_div_2exp(a,b,-c); } /* ====================================================================== */ /* Arithmetic Tests */ /* ====================================================================== */ static inline int numrat_sgn(numrat_t a) { return mpq_sgn(a); } static inline int numrat_cmp(numrat_t a, numrat_t b) { return mpq_cmp(a,b); } static inline int numrat_cmp_int(numrat_t a, long int b) { return mpq_cmp_si(a,b,1); } static inline bool numrat_equal(numrat_t a, numrat_t b) { return mpq_equal(a,b); } static inline bool numrat_integer(numrat_t a) { return (mpz_cmp_ui(mpq_denref(a),1)==0); } /* ====================================================================== */ /* Printing */ /* ====================================================================== */ static inline void numrat_print(numrat_t a) { mpq_out_str(stdout,10,a); } static inline void numrat_fprint(FILE* stream, numrat_t a) { mpq_out_str(stream,10,a); } static inline int numrat_snprint(char* s, size_t size, numrat_t a) { int res; if (mpz_sizeinbase(mpq_numref(a),10) + mpz_sizeinbase(mpq_denref(a),10) + 3 > size ) res = snprintf(s,size, mpq_sgn(a)>0 ? "+BIG" : "-BIG"); else { mpq_get_str(s,10,a); res = strlen(s); } return res; } /* ====================================================================== */ /* Conversions */ /* ====================================================================== */ /* int2 -> numrat */ static inline bool numrat_set_int2(numrat_t a, long int i, long int j) { assert(j>0); mpq_set_si(a,i,j); numrat_canonicalize(a); return true; } /* mpz -> numrat */ static inline bool numrat_set_mpz(numrat_t a, mpz_t b) { mpz_set(mpq_numref(a),b); mpz_set_ui(mpq_denref(a),1); return true; } /* mpq -> numrat */ static inline bool numrat_set_mpq(numrat_t a, mpq_t b) { mpq_set(a,b); return true; } /* double -> numrat */ static inline bool numrat_set_double(numrat_t a, double k) { if (!isfinite(k)) { DEBUG_SPECIAL; numrat_set_int(a,0); return false; } mpq_set_d(a,k); return true; } static inline bool numrat_set_double_tmp(numrat_t a, double k, mpq_t mpq) { return numrat_set_double(a,k); } /* mpfr -> numrat */ static inline bool numrat_set_mpfr(numrat_t a, mpfr_t b) { mp_exp_t e; if (!mpfr_number_p(b)) { DEBUG_SPECIAL; numrat_set_int(a,0); return false; } /* XXX might fail if scaled exponent not representable in mp_exp_t */ e = mpfr_get_z_exp(mpq_numref(a),b); mpz_set_si(mpq_denref(a),1); if (e>0) mpq_mul_2exp(a,a,e); if (e<0) mpq_div_2exp(a,a,-e); return true; } /* numrat -> int */ static inline bool int_set_numrat_tmp(long int* a, numrat_t b, mpz_t q, mpz_t r) { mpz_cdiv_qr(q,r,numrat_numref(b),numrat_denref(b)); *a = mpz_get_si(q); return (mpz_sgn(r)==0); } static inline bool int_set_numrat(long int* a, numrat_t b) { mpz_t q,r; mpz_init(q); mpz_init(r); bool res = int_set_numrat_tmp(a,b,q,r); mpz_clear(q); mpz_clear(r); return res; } /* numrat -> mpz */ static inline bool mpz_set_numrat_tmp(mpz_t a, numrat_t b, mpz_t mpz) { mpz_cdiv_qr(a, mpz, mpq_numref(b),mpq_denref(b)); bool res = (mpz_sgn(mpz)==0); return res; } static inline bool mpz_set_numrat(mpz_t a, numrat_t b) { numint_t r; numint_init(r); bool res = mpz_set_numrat_tmp(a,b,r); numint_clear(r); return res; } /* numrat -> mpq */ static inline bool mpq_set_numrat(mpq_t a, numrat_t b) { mpq_set(a,b); return true; } /* numrat -> double */ /* mpfr should have exactly a precision of 53 bits */ static inline bool double_set_numrat_tmp(double* a, numrat_t b, mpq_t mpq, // not used mpfr_t mpfr) { int res = mpfr_set_q(mpfr,b,GMP_RNDU); *a = mpfr_get_d(mpfr,GMP_RNDU); /* should be exact */ return (res==0); } static inline bool double_set_numrat(double* a, numrat_t b) { mpfr_t mpfr; mpfr_init2(mpfr,53); bool res = double_set_numrat_tmp(a,b,NULL,mpfr); mpfr_clear(mpfr); return res; } /* numrat -> mpfr */ static inline bool mpfr_set_numrat(mpfr_t a, numrat_t b) { return !mpfr_set_q(a,b,GMP_RNDU); } static inline bool mpz_fits_numrat(mpz_t a) { return true; } static inline bool mpq_fits_numrat(mpq_t a) { return true; } static inline bool double_fits_numrat(double k) { return isfinite(k); } static inline bool double_fits_numrat_tmp(double k, mpq_t mpq) { return double_fits_numrat(k); } static inline bool mpfr_fits_numrat(mpfr_t a) { return mpfr_number_p(a); } static inline bool numrat_fits_int(numrat_t a) { double d = ceil(mpq_get_d(a)); return (d+1.0)<=LONG_MAX && (d-1.0)>=-LONG_MAX; } static inline bool numrat_fits_float(numrat_t a) { return ((int)mpz_sizeinbase(numrat_numref(a),2)- (int)mpz_sizeinbase(numrat_denref(a),2)<126); } static inline bool numrat_fits_double(numrat_t a) { return ((int)mpz_sizeinbase(numrat_numref(a),2)- (int)mpz_sizeinbase(numrat_denref(a),2)<1022); } static inline bool numrat_fits_mpfr(numrat_t a) { return ((int)mpz_sizeinbase(numrat_numref(a),2)- (int)mpz_sizeinbase(numrat_denref(a),2)+1 #include #include #include "num.h" #include "ap_manager.h" #include "bound.h" void num(num_t a, num_t b, num_t c, unsigned long int u, long int l, mpz_t mpz, mpq_t mpq, double d, mpfr_t mpfr) { num_t bb,cc; unsigned long int uu; long int ll; mpz_t mpzz; mpq_t mpqq; mpfr_t mpfrr; double dd; num_init_set(bb,b); num_init_set(cc,c); ll = l; uu = u; mpz_init_set(mpzz,mpz); mpq_init(mpqq); mpq_set(mpqq,mpq); mpfr_init(mpfrr); mpfr_set(mpfrr,mpfr,GMP_RNDU); printf("********************\n"); printf("b="); num_print(b); printf(" c="); num_print(c); printf("\nu=%lu l=%ld\n",u,l); printf("mpz="); mpz_out_str(stdout,10,mpz); printf(" mpq="); mpq_out_str(stdout,10,mpq); printf(" mpfr="); mpfr_out_str(stdout,10,10,mpfr,GMP_RNDU); printf(" d=%.13e\n",d); num_set(b,bb); num_set(c,cc); num_swap(b,c); printf("num_swap(b,c): "); printf("b="); num_print(b); printf(" c="); num_print(c); printf("\n"); num_set(b,bb); num_set(c,cc); num_neg(a,b); printf("num_neg(b)="); num_print(a); printf("\n"); num_set(b,bb); num_set(c,cc); num_add(a,b,c); printf("num_add(b,c)="); num_print(a); printf("\n"); num_set(b,bb); num_set(c,cc); num_add_uint(a,b,u); printf("num_add_uint(b,u)="); num_print(a); printf("\n"); num_set(b,bb); num_set(c,cc); num_sub(a,b,c); printf("num_sub(b,c)="); num_print(a); printf("\n"); num_set(b,bb); num_set(c,cc); num_sub_uint(a,b,u); printf("num_sub_uint(b,u)="); num_print(a); printf("\n"); num_set(b,bb); num_set(c,cc); num_mul(a,b,c); printf("num_mul(b,c)="); num_print(a); printf("\n"); num_set(b,bb); num_set(c,cc); num_mul_2(a,b); printf("num_mul_2(b)="); num_print(a); printf("\n"); num_set(b,bb); num_set(c,cc); num_div(a,b,c); printf("num_div(b,c)="); num_print(a); printf("\n"); num_set(b,bb); num_set(c,cc); num_div_2(a,b); printf("num_div_2(b)="); num_print(a); printf("\n"); num_set(b,bb); num_set(c,cc); num_min(a,b,c); printf("num_min(b,c)="); num_print(a); printf("\n"); num_set(b,bb); num_set(c,cc); num_max(a,b,c); printf("num_max(b,c)="); num_print(a); printf("\n"); num_set(b,bb); num_set(c,cc); num_floor(a,b); printf("num_floor(b)="); num_print(a); printf("\n"); num_set(b,bb); num_set(c,cc); num_ceil(a,b); printf("num_ceil(b)="); num_print(a); printf("\n"); printf("num_sgn(b)=%d\n",num_sgn(b)); printf("num_cmp(b,c)=%d\n",num_cmp(b,c)); printf("num_cmp_int(b,l)=%d\n",num_cmp_int(b,l)); printf("num_equal(b,c)=%d\n",num_equal(b,c)); if (u<=LONG_MAX) { num_set_int2(a,l,u); printf("num_set_int2(l,u)=");num_print(a); printf("\n"); } printf("mpz_fits_num(mpz)=%d\n",mpz_fits_num(mpz)); if (mpz_fits_num(mpz)) { num_set_mpz(a,mpz); printf("num_set_mpz(mpz)=");num_print(a); printf("\n"); } printf("mpq_fits_num(mpq)=%d\n",mpq_fits_num(mpq)); if (mpq_fits_num(mpq)) { num_set_mpq(a,mpq); printf("num_set_mpq(mpq)=");num_print(a); printf("\n"); } printf("double_fits_num(d)=%d\n",double_fits_num(d)); if (double_fits_num(d)) { num_set_double(a,d); printf("num_set_double(d)=");num_print(a); printf("\n"); } printf("mpfr_fits_num(mpfr)=%d\n",mpfr_fits_num(mpfr)); if (mpfr_fits_num(mpfr)) { num_set_mpfr(a,mpfr); printf("num_set_mpfr(mpfr)=");num_print(a); printf("\n"); } { long int i; int_set_num(&i,b); printf("int_set_num(b)=%ld\n",i); } mpz_set_num(mpz,b); printf("mpz_set_num(b)="); mpz_out_str(stdout,10,mpz); printf("\n"); mpz_set(mpz,mpzz); mpq_set_num(mpq,b); printf("mpq_set_num(b)="); mpq_out_str(stdout,10,mpq); printf("\n"); mpq_set(mpq,mpqq); printf("num_fits_double(b)=%d\n",num_fits_double(b)); if (num_fits_double(b)) { double k; double_set_num(&k,b); printf("double(b)=%.13e\n",k); } num_set(b,bb); num_set(c,cc); printf("num_fits_mpfr(b)=%d\n",num_fits_mpfr(b)); if (num_fits_mpfr(b)) { mpfr_set_num(mpfr,b); printf("mpfr_set_num(b)="); mpfr_out_str(stdout,10,10,mpfr,GMP_RNDU); printf("\n"); mpfr_set(mpfr,mpfrr,GMP_RNDU); } num_clear(bb); num_clear(cc); mpz_clear(mpzz); mpq_clear(mpqq); mpfr_clear(mpfrr); } void bound(bound_t a, bound_t b, bound_t c, unsigned long int u, long int l, mpz_t mpz, mpq_t mpq, double d, mpfr_t mpfr) { bound_t bb,cc; unsigned long int uu; long int ll; double dd; bound_init_set(bb,b); bound_init_set(cc,c); ll = l; uu = u; printf("********************\n"); printf("b="); bound_print(b); printf(" c="); bound_print(c); printf("\nu=%lu l=%ld\n",u,l); printf(" d=%.13e\n",d); bound_set(b,bb); bound_set(c,cc); if (!bound_infty(b)) { bound_set_num(a,bound_numref(b)); printf("bound_set_num(b): "); printf("b="); bound_print(b); printf(" a="); bound_print(a); printf("\n"); } bound_set_infty(a,1); printf("bound_set_infty(1)="); bound_print(a); printf("\n"); bound_set_infty(a,-2); printf("bound_set_infty(-2)="); bound_print(a); printf("\n"); bound_set(b,bb); bound_set(c,cc); bound_swap(b,c); printf("bound_swap(b,c): "); printf("b="); bound_print(b); printf(" c="); bound_print(c); printf("\n"); bound_set(b,bb); bound_set(c,cc); bound_neg(a,b); printf("bound_neg(b)="); bound_print(a); printf("\n"); bound_set(b,bb); bound_set(c,cc); bound_add(a,b,c); printf("bound_add(b,c)="); bound_print(a); printf("\n"); bound_set(b,bb); bound_set(c,cc); bound_add_uint(a,b,u); printf("bound_add_uint(b,u)="); bound_print(a); printf("\n"); if (!bound_infty(c)) { bound_set(b,bb); bound_set(c,cc); bound_add_num(a,b,bound_numref(c)); printf("bound_add_num(b,bound_numref(c)="); bound_print(a); printf("\n"); } bound_set(b,bb); bound_set(c,cc); bound_sub(a,b,c); printf("bound_sub(b,c)="); bound_print(a); printf("\n"); bound_set(b,bb); bound_set(c,cc); bound_sub_uint(a,b,u); printf("bound_sub_uint(b,u)="); bound_print(a); printf("\n"); if (!bound_infty(c)) { bound_set(b,bb); bound_set(c,cc); bound_sub_num(a,b,bound_numref(c)); printf("bound_sub_num(b,bound_numref(c)="); bound_print(a); printf("\n"); } bound_set(b,bb); bound_set(c,cc); bound_mul(a,b,c); printf("bound_mul(b,c)="); bound_print(a); printf("\n"); if (!bound_infty(c)) { bound_set(b,bb); bound_set(c,cc); bound_mul_num(a,b,bound_numref(c)); printf("bound_mul_num(b,bound_numref(c)="); bound_print(a); printf("\n"); } bound_set(b,bb); bound_set(c,cc); bound_mul_2(a,b); printf("bound_mul_2(b)="); bound_print(a); printf("\n"); bound_set(b,bb); bound_set(c,cc); bound_div(a,b,c); printf("bound_div(b,c)="); bound_print(a); printf("\n"); if (!bound_infty(c)) { bound_set(b,bb); bound_set(c,cc); bound_div_num(a,b,bound_numref(c)); printf("bound_div_num(b,bound_numref(c)="); bound_print(a); printf("\n"); } bound_set(b,bb); bound_set(c,cc); bound_div_2(a,b); printf("bound_div_2(b)="); bound_print(a); printf("\n"); bound_set(b,bb); bound_set(c,cc); bound_min(a,b,c); printf("bound_min(b,c)="); bound_print(a); printf("\n"); bound_set(b,bb); bound_set(c,cc); bound_max(a,b,c); printf("bound_max(b,c)="); bound_print(a); printf("\n"); bound_set(b,bb); bound_set(c,cc); bound_floor(a,b); printf("bound_floor(b)="); bound_print(a); printf("\n"); bound_set(b,bb); bound_set(c,cc); bound_ceil(a,b); printf("bound_ceil(b)="); bound_print(a); printf("\n"); printf("bound_sgn(b)=%d\n",bound_sgn(b)); printf("bound_cmp(b,c)=%d\n",bound_cmp(b,c)); printf("bound_cmp_int(b,l)=%d\n",bound_cmp_int(b,l)); if (!bound_infty(c)) { printf("bound_cmp_num(b,bound_numref(c))=%d\n",bound_cmp_num(b,bound_numref(c))); } printf("bound_equal(b,c)=%d\n",bound_equal(b,c)); bound_set(b,bb); bound_set(c,cc); bound_clear(bb); bound_clear(cc); } int main(int argc, char**argv) { unsigned long int u; long int l; mpz_t mpz; mpq_t mpq,mpq2; mpfr_t mpfr; double d; ap_fpu_init(); mpz_init(mpz); mpq_init(mpq); mpq_init(mpq2); mpfr_init(mpfr); /* Extreme cases */ u = ULONG_MAX; l = LONG_MIN+1; mpz_set_ui(mpz,u); mpq_set_z(mpq,mpz); mpz_mul(mpz,mpz,mpz); mpq_inv(mpq,mpq); d = (double)1.0/(double)0.0; mpfr_set_d(mpfr,d,GMP_RNDU); { num_t a,b,c; num_init(a); num_init_set_int(b,1000); num_init_set_int(c,1500); num(a,b,c,u,l,mpz,mpq,d,mpfr); num(a,c,b,u,l,mpz,mpq,d,mpfr); num_clear(a); num_clear(b); num_clear(c); } { bound_t a,b,c; bound_init(a); bound_init_set_int(b,1000); bound_init_set_int(c,1500); bound(a,b,c,u,l,mpz,mpq,d,mpfr); bound(a,c,b,u,l,mpz,mpq,d,mpfr); bound_set_infty(c,1); bound(a,b,c,u,l,mpz,mpq,d,mpfr); bound(a,c,b,u,l,mpz,mpq,d,mpfr); bound_clear(a); bound_clear(b); bound_clear(c); } /* Standard cases */ u = 1000000; l = -300000; mpz_set_si(mpz,l); mpq_set_z(mpq,mpz); mpz_set_ui(mpz,u); mpq_set_z(mpq2,mpz); mpq_div(mpq,mpq,mpq2); mpz_set_si(mpz,l); mpfr_set_d(mpfr,4.25,GMP_RNDU); d = 3.5; { num_t a,b,c; num_init(a); num_init(b); num_init(c); num_set_int2(b,3002,3); num_set_int(c,-1500); num(a,b,c,u,l,mpz,mpq,d,mpfr); num(a,c,b,u,l,mpz,mpq,d,mpfr); num(b,b,b,u,l,mpz,mpq,d,mpfr); num_clear(a); num_clear(b); num_clear(c); } { bound_t a,b,c; bound_init(a); bound_init(b); bound_init(c); bound_set_int(b,3002); bound_set_int(c,3); bound_div(b,b,c); bound_set_int(c,-1500); bound(a,b,c,u,l,mpz,mpq,d,mpfr); bound(a,c,b,u,l,mpz,mpq,d,mpfr); bound(b,b,b,u,l,mpz,mpq,d,mpfr); bound_clear(a); bound_clear(b); bound_clear(c); } mpz_clear(mpz); mpq_clear(mpq2); mpq_clear(mpq); mpfr_clear(mpfr); } apron-dist-0.9.10/apron/num/numint_mpz.h0000640014525101416610000002263511005654323020043 0ustar bjeannetpopart/* ********************************************************************** */ /* numint_mpz.h */ /* ********************************************************************** */ #ifndef _NUMINT_MPZ_H_ #define _NUMINT_MPZ_H_ #include #include #include #include #include #include #include #include "gmp.h" #include "mpfr.h" #include "ap_scalar.h" #include "num_config.h" #ifdef __cplusplus extern "C" { #endif /* Require C99 compliant compiler */ typedef mpz_t numint_t; #undef NUMINT_MAX #undef NUMINT_NATIVE /* ====================================================================== */ /* Assignement */ /* ====================================================================== */ static inline void numint_set(numint_t a, numint_t b) { mpz_set(a,b); } static inline void numint_set_array(numint_t* a, numint_t* b, size_t size) { size_t i; for (i=0; i=0 ? b : c); } static inline void numint_sqrt(numint_t up, numint_t down, numint_t b) { int perfect; assert(mpz_sgn(b)>=0); perfect = mpz_perfect_square_p(b); mpz_sqrt(down,b); if (perfect) mpz_set(up,down); else mpz_add_ui(up,down,1); } static inline void numint_mul_2exp(numint_t a, numint_t b, int c) { if (c>=0) mpz_mul_2exp(a,b,c); else mpz_cdiv_q_2exp(a,b,-c); } /* ====================================================================== */ /* Arithmetic Integer Operations */ /* ====================================================================== */ static inline void numint_divexact(numint_t a, numint_t b, numint_t c) { mpz_divexact(a,b,c); } static inline void numint_mod(numint_t a, numint_t b, numint_t c) { mpz_mod(a,b,c); } static inline void numint_gcd(numint_t a, numint_t b, numint_t c) { mpz_gcd(a,b,c); } static inline void numint_lcm(numint_t a, numint_t b, numint_t c) { mpz_lcm(a,b,c); } /* ====================================================================== */ /* Arithmetic Tests */ /* ====================================================================== */ static inline int numint_sgn(numint_t a) { return mpz_sgn(a); } static inline int numint_cmp(numint_t a, numint_t b) { return mpz_cmp(a,b); } static inline int numint_cmp_int(numint_t a, long int b) { return mpz_cmp_si(a,b); } static inline bool numint_equal(numint_t a, numint_t b) { return mpz_cmp(a,b)==0; } static inline bool numint_integer(numint_t a) { return true; } /* ====================================================================== */ /* Printing */ /* ====================================================================== */ static inline void numint_print(numint_t a) { mpz_out_str(stdout,10,a); } static inline void numint_fprint(FILE* stream, numint_t a) { mpz_out_str(stream,10,a); } static inline int numint_snprint(char* s, size_t size, numint_t a) { int res; if (mpz_sizeinbase(a,10)+2>size) res = snprintf(s,size, mpz_sgn(a)>0 ? "+BIG" : "-BIG"); else { mpz_get_str(s,10,a); res = strlen(s); } return res; } /* ====================================================================== */ /* Conversions */ /* ====================================================================== */ /* int2 -> numint */ static inline bool numint_set_int2(numint_t a, long int i, long int j) { unsigned long int r; assert(j>0); numint_set_int(a,i); r = mpz_cdiv_q_ui(a,a,j); return r ? false : true; } /* mpz -> numint */ static inline bool numint_set_mpz(numint_t a, mpz_t b) { mpz_set(a,b); return true; } /* mpq -> numint */ static inline bool numint_set_mpq_tmp(numint_t a, mpq_t b, mpz_t q, mpz_t r) { mpz_cdiv_qr(a, r, mpq_numref(b),mpq_denref(b)); bool res = (mpz_sgn(r)==0); return res; } static inline bool numint_set_mpq(numint_t a, mpq_t b) { mpz_t r; mpz_init(r); bool res = numint_set_mpq_tmp(a,b,r,r); mpz_clear(r); return res; } /* double -> numint */ static inline bool numint_set_double(numint_t a, double b) { double c = ceil(b); if (!isfinite(c)) { DEBUG_SPECIAL; mpz_set_si(a,0); return false; } mpz_set_d(a,c); return (b==c); } /* mpfr -> numint */ static inline bool numint_set_mpfr(numint_t a, mpfr_t b) { if (!mpfr_number_p(b)) { DEBUG_SPECIAL; numint_set_int(a,0); return false; } mpfr_get_z(a,b,GMP_RNDU); return mpfr_integer_p(b); } /* numint -> int */ static inline bool int_set_numint(long int* a, numint_t b) { *a = mpz_get_si(b); return true; } /* numint -> mpz */ static inline bool mpz_set_numint(mpz_t a, numint_t b) { mpz_set(a,b); return true; } /* numint -> mpq */ static inline bool mpq_set_numint(mpq_t a, numint_t b) { mpz_set(mpq_numref(a),b); mpz_set_ui(mpq_denref(a),1); return true; } /* numint -> double */ /* mpfr is supposed to have exactly the IEEE754 double precision of 53 bits */ static inline bool double_set_numint_tmp(double* a, numint_t b, mpfr_t mpfr) { int res = mpfr_set_z(mpfr,b,GMP_RNDU); *a = mpfr_get_d(mpfr,GMP_RNDU);/* Normally, exact conversion here (unless overflow) */ return (res==0); } static inline bool double_set_numint(double* a, numint_t b) { mpfr_t mpfr; mpfr_init2(mpfr,53); bool res = double_set_numint_tmp(a,b,mpfr); mpfr_clear(mpfr); return res; } /* numint -> mpfr */ static inline bool mpfr_set_numint(mpfr_t a, numint_t b) { return !mpfr_set_z(a,b,GMP_RNDU); } static inline bool mpz_fits_numint(mpz_t a) { return true; } static inline bool mpq_fits_numint_tmp(mpq_t a, mpz_t mpz) { return true; } static inline bool mpq_fits_numint(mpq_t a) { return true; } static inline bool double_fits_numint(double a) { return isfinite(a); } static inline bool mpfr_fits_numint(mpfr_t a) { return mpfr_number_p(a); } static inline bool numint_fits_int(numint_t a) { return mpz_fits_slong_p(a); } static inline bool numint_fits_float(numint_t a) { return (mpz_sizeinbase(a,2)<127); } static inline bool numint_fits_double(numint_t a) { return (mpz_sizeinbase(a,2)<1023); } static inline bool numint_fits_mpfr(numint_t a) { return (mpz_sizeinbase(a,2)+1<(size_t)mpfr_get_emax()); } /* ====================================================================== */ /* Serialization */ /* ====================================================================== */ static inline unsigned char numint_serialize_id(void) { return 0xf; } static inline size_t numint_serialize(void* dst, numint_t src) { size_t count = 0; *((char*)dst) = mpz_sgn(src); mpz_export((char*)dst+5,&count,1,1,1,0,src); assert(((unsigned)count)==count); num_dump_word32((char*)dst+1,(unsigned)count); return count+5; } static inline size_t numint_deserialize(numint_t dst, const void* src) { size_t count = num_undump_word32((const char*)src+1); mpz_import(dst,count,1,1,1,0,(const char*)src+5); if (*(const char*)src<0) mpz_neg(dst,dst); return count+5; } /* not the exact size of serialized data, but a sound overapproximation */ static inline size_t numint_serialized_size(numint_t a) { return mpz_sizeinbase(a,2)/8+5+sizeof(mp_limb_t); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/num/numint.h0000640014525101416610000001613011006063143017141 0ustar bjeannetpopart/* ********************************************************************** */ /* numint.h */ /* ********************************************************************** */ #ifndef _NUMINT_H_ #define _NUMINT_H_ #include #include "gmp.h" #include "mpfr.h" #include "ap_scalar.h" #include "num_config.h" #if defined(NUMINT_LONGINT) || defined(NUMINT_LONGLONGINT) #include "numint_native.h" #elif defined(NUMINT_MPZ) #include "numint_mpz.h" #else #error "HERE" #endif #ifdef __cplusplus extern "C" { #endif /* NUMINT_LONGINT and NUMINT_LONGLONGINT also define - NUMINT_MAX: max positive value. It is assumed that (-NUMINT_MAX) is also representable - NUMINT_NATIVE: no heap allocated memory */ /* ====================================================================== */ /* Assignement */ /* ====================================================================== */ static inline void numint_set(numint_t a, numint_t b); static inline void numint_set_array(numint_t* a, numint_t* b, size_t size); static inline void numint_set_int(numint_t a, long int i); /* ====================================================================== */ /* Constructors and Destructors */ /* ====================================================================== */ static inline void numint_init(numint_t a); static inline void numint_init_array(numint_t* a, size_t size); static inline void numint_init_set(numint_t a, numint_t b); static inline void numint_init_set_int(numint_t a, long int i); static inline void numint_clear(numint_t a); static inline void numint_clear_array(numint_t* a, size_t size); static inline void numint_swap(numint_t a, numint_t b) { numint_t t; *t=*a;*a=*b;*b=*t; } /* ====================================================================== */ /* Arithmetic Operations */ /* ====================================================================== */ static inline void numint_neg(numint_t a, numint_t b); static inline void numint_abs(numint_t a, numint_t b); static inline void numint_add(numint_t a, numint_t b, numint_t c); static inline void numint_add_uint(numint_t a, numint_t b, unsigned long int c); static inline void numint_sub(numint_t a, numint_t b, numint_t c); static inline void numint_sub_uint(numint_t a, numint_t b, unsigned long int c); static inline void numint_mul(numint_t a, numint_t b, numint_t c); static inline void numint_mul_2(numint_t a, numint_t b); static inline void numint_fdiv_q(numint_t a, numint_t b, numint_t c); static inline void numint_cdiv_q(numint_t q, numint_t a, numint_t b); static inline void numint_cdiv_t(numint_t q, numint_t a, numint_t b); static inline void numint_cdiv_qr(numint_t q, numint_t r, numint_t a, numint_t b); static inline void numint_cdiv_2(numint_t a, numint_t b); static inline void numint_cdiv_q_2exp(numint_t a, numint_t b, unsigned long int c); static inline void numint_fdiv_q_2exp(numint_t a, numint_t b, unsigned long int c); static inline void numint_min(numint_t a, numint_t b, numint_t c); static inline void numint_max(numint_t a, numint_t b, numint_t c); static inline void numint_floor(numint_t a, numint_t b); static inline void numint_ceil(numint_t a, numint_t b); static inline void numint_sqrt(numint_t up, numint_t down, numint_t b); static inline void numint_mul_2exp(numint_t a, numint_t b, int c); /* ====================================================================== */ /* Arithmetic Integer Operations */ /* ====================================================================== */ static inline void numint_divexact(numint_t a, numint_t b, numint_t c); static inline void numint_mod(numint_t a, numint_t b, numint_t c); static inline void numint_gcd(numint_t a, numint_t b, numint_t c); static inline void numint_lcm(numint_t a, numint_t b, numint_t c); /* ====================================================================== */ /* Arithmetic Tests */ /* ====================================================================== */ static inline int numint_sgn(numint_t a); static inline int numint_cmp(numint_t a, numint_t b); static inline int numint_cmp_int(numint_t a, long int b); static inline bool numint_equal(numint_t a, numint_t b); /* ====================================================================== */ /* Printing */ /* ====================================================================== */ static inline void numint_print(numint_t a); static inline void numint_fprint(FILE* stream, numint_t a); static inline int numint_snprint(char* s, size_t size, numint_t a); /* ====================================================================== */ /* Conversions */ /* ====================================================================== */ static inline bool numint_set_int2(numint_t a, long int i, long int j); /* int2 -> numint */ static inline bool numint_set_mpz(numint_t a, mpz_t b); /* mpz -> numint */ static inline bool numint_set_mpq(numint_t a, mpq_t b); /* mpq -> numint */ static inline bool numint_set_double(numint_t a, double b); /* double -> numint */ static inline bool numint_set_mpfr(numint_t a, mpfr_t b); /* mpfr -> numint */ static inline bool numint_set_ap_scalar(numint_t a, ap_scalar_t* b); /* (finite) ap_scalar -> numint */ static inline bool int_set_numint(long int* a, numint_t b); /* numint -> int */ static inline bool mpz_set_numint(mpz_t a, numint_t b); /* numint -> mpz */ static inline bool mpq_set_numint(mpq_t a, numint_t b); /* numint -> mpq */ static inline bool double_set_numint(double* a, numint_t b); /* numint -> double */ static inline bool mpfr_set_numint(mpfr_t a, numint_t b); /* numint -> mpfr */ static inline bool ap_scalar_set_numint(ap_scalar_t* a, numint_t b); /* numint -> ap_scalar */ static inline bool mpz_fits_numint(mpz_t a); static inline bool mpq_fits_numint(mpq_t a); static inline bool double_fits_numint(double a); static inline bool mpfr_fits_numint(mpfr_t a); static inline bool numint_fits_int(numint_t a); static inline bool numint_fits_float(numint_t a); static inline bool numint_fits_double(numint_t a); static inline bool numint_fits_mpfr(numint_t a); /* Optimized versions */ static inline bool mpq_fits_numint_tmp(mpq_t a, mpz_t mpz); static inline bool numint_set_mpq_tmp(numint_t a, mpq_t b, mpz_t q, mpz_t r); /* ====================================================================== */ /* Serialization */ /* ====================================================================== */ static inline unsigned char numint_serialize_id(void); static inline size_t numint_serialize(void* dst, numint_t src); static inline size_t numint_deserialize(numint_t dst, const void* src); static inline size_t numint_serialized_size(numint_t a); /* */ static inline bool numint_set_ap_scalar(numint_t a, ap_scalar_t* b) { assert (ap_scalar_infty(b)==0); switch (b->discr){ case AP_SCALAR_MPQ: return numint_set_mpq(a,b->val.mpq); case AP_SCALAR_DOUBLE: return numint_set_double(a,b->val.dbl); case AP_SCALAR_MPFR: return numint_set_mpfr(a,b->val.mpfr); default: abort(); } } static inline bool ap_scalar_set_numint(ap_scalar_t* a, numint_t b) { ap_scalar_reinit(a,AP_SCALAR_MPQ); return mpq_set_numint(a->val.mpq,b); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/num/num_name.h0000640014525101416610000000242511005654323017435 0ustar bjeannetpopart/* ********************************************************************** */ /* num_name.h: numerical type name and mangling */ /* ********************************************************************** */ /* Unlike num.h, this file can be included several times. */ #undef NUM_NAME #undef NUM_SUFFIX #undef NUMFUN3 #undef NUMFUN2 #undef NUMFUN /* NUMFUN(xxx) expands to xxx_mpq, or xxx_dbl, ... */ #define NUMFUN3(NAME,SUFFIX) NAME ## _ ## SUFFIX #define NUMFUN2(x,y) NUMFUN3(x,y) #define NUMFUN(x) NUMFUN2(x,NUM_SUFFIX) #if defined(NUM_LONGRAT) #define NUM_NAME "NUM_LONGRAT" #define NUM_SUFFIX Rl #elif defined(NUM_LONGLONGRAT) #define NUM_NAME "NUM_LONGLONGRAT" #define NUM_SUFFIX Rll #elif defined(NUM_MPQ) #define NUM_NAME "NUM_MPQ" #define NUM_SUFFIX MPQ #elif defined(NUM_LONGINT) #define NUM_NAME "NUM_LONGINT" #define NUM_SUFFIX Il #elif defined(NUM_LONGLONGINT) #define NUM_NAME "NUM_LONGLONGINT" #define NUM_SUFFIX Ill #elif defined(NUM_MPZ) #define NUM_NAME "NUM_MPZ" #define NUM_SUFFIX MPZ #elif defined(NUM_DOUBLE) #define NUM_NAME "NUM_DOUBLE" #define NUM_SUFFIX D #elif defined(NUM_LONGDOUBLE) #define NUM_NAME "NUM_LONGDOUBLE" #define NUM_SUFFIX Dl #elif defined(NUM_MPFR) #define NUM_NAME "NUM_MPFR" #define NUM_SUFFIX MPFR #else #error "HERE" #endif apron-dist-0.9.10/apron/num/num_config.h0000640014525101416610000000235111006063143017753 0ustar bjeannetpopart #ifndef _NUM_CONFIG_H_ #define _NUM_CONFIG_H_ #include "ap_config.h" #ifdef __cplusplus #define HAS_BOOL extern "C" { #endif #ifndef HAS_BOOL #define HAS_BOOL typedef char bool; static const bool false = 0; static const bool true = 1; #endif #include /* prints attempts to convert NaN and infinities to non floating-point types */ #define DEBUG_SPECIAL fprintf(stderr,"invalid floating-point in %s\n",__func__) static inline void num_store_words8(void* dst, const void* src, size_t t) { #ifdef WORDS_BIGENDIAN unsigned char *s = (unsigned char*)src+t-1, *d = (unsigned char*) dst; size_t i; for (i=0;i>24) & 0xff; *((unsigned char*)dst+1) = (src>>16) & 0xff; *((unsigned char*)dst+2) = (src>>8) & 0xff; *((unsigned char*)dst+3) = src & 0xff; } static inline unsigned num_undump_word32(const void* src) { return ((unsigned)(((const unsigned char*)src)[0])<<24)+ ((unsigned)(((const unsigned char*)src)[1])<<16)+ ((unsigned)(((const unsigned char*)src)[2])<<8)+ ((unsigned)(((const unsigned char*)src)[3])); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/num/numflt_mpfr.h0000640014525101416610000002504711006063143020167 0ustar bjeannetpopart/* ********************************************************************** */ /* numflt_mpfr.h */ /* ********************************************************************** */ #ifndef _NUMFLT_MPFR_H_ #define _NUMFLT_MPFR_H_ #include #include #include #include #include #include #include #include #include "gmp.h" #include "mpfr.h" #include "ap_scalar.h" #include "num_config.h" #ifdef __cplusplus extern "C" { #endif /* NOTES: - use mpfr_set_default_prec to change the precision (global) - rounding is always towards +oo */ typedef mpfr_t numflt_t; #undef NUMFLT_MAX #undef NUMFLT_NATIVE /* ====================================================================== */ /* Assignement */ /* ====================================================================== */ static inline void numflt_set(numflt_t a, numflt_t b) { mpfr_set(a,b,GMP_RNDU); } static inline void numflt_set_array(numflt_t* a, numflt_t* b, size_t size) { size_t i; for (i=0; i0?'+':'-'); if (mpfr_zero_p(a)) return snprintf(s,size,"0"); d = mpfr_get_d(a,GMP_RNDU); if (!mpfr_cmp_d(a,d)) return snprintf(s,size,"%.*g",NUMFLT_PRINT_PREC,d); else { /* general case */ char* tmp; mp_exp_t e; int x,i; tmp = mpfr_get_str(NULL,&e,10,NUMFLT_PRINT_PREC,a,GMP_RNDU); if (!tmp) { *s = 0; return 0; } if (tmp[0]=='-' || tmp[0]=='+') x=snprintf(s,size,"%c.%se+%ld",tmp[0],tmp+1,(long int)e); else x=snprintf(s,size,".%se%+ld",tmp,(long int)e); mpfr_free_str(tmp); return x; } } static inline void numflt_fprint(FILE* stream, numflt_t a) { char buf[256]; numflt_snprint(buf,sizeof(buf)-10,a); fputs(buf,stream); } static inline void numflt_print(numflt_t a) { numflt_fprint(stdout,a); } /* ====================================================================== */ /* Conversions */ /* ====================================================================== */ /* int2 -> numflt */ static inline bool numflt_set_int2(numflt_t a, long int i, long int j) { int r1,r2; assert(j>0); r1=mpfr_set_si(a,i,GMP_RNDU); r2=mpfr_div_si(a,a,j,GMP_RNDU); return !r1 && !r2; } /* mpz -> numflt */ static inline bool numflt_set_mpz_tmp(numflt_t a, mpz_t b, mpfr_t mpfr) { return !mpfr_set_z(a,b,GMP_RNDU); } static inline bool numflt_set_mpz(numflt_t a, mpz_t b) { return !mpfr_set_z(a,b,GMP_RNDU); } /* mpq -> numflt */ static inline bool numflt_set_mpq_tmp(numflt_t a, mpq_t b, mpfr_t mpfr) { return !mpfr_set_q(a,b,GMP_RNDU); } static inline bool numflt_set_mpq(numflt_t a, mpq_t b) { return !mpfr_set_q(a,b,GMP_RNDU); } /* double -> numflt */ static inline bool numflt_set_double(numflt_t a, double k) { return !mpfr_set_d(a,k,GMP_RNDU); } /* mpfr -> numflt */ static inline bool numflt_set_mpfr(numflt_t a, mpfr_t b) { return !mpfr_set(a,b,GMP_RNDU); } /* numflt -> int */ static inline bool int_set_numflt(long int* a, numflt_t b) { if (!mpfr_number_p(b)) { DEBUG_SPECIAL; *a = 0; return false; } *a = mpfr_get_si(b,GMP_RNDU); return mpfr_integer_p(b); } /* numflt -> mpz */ static inline bool mpz_set_numflt(mpz_t a, numflt_t b) { if (!mpfr_number_p(b)) { DEBUG_SPECIAL; mpz_set_si(a,0); return false; } mpfr_get_z(a,b,GMP_RNDU); return mpfr_integer_p(b); } /* numflt -> mpq */ static inline bool mpq_set_numflt(mpq_t a, numflt_t b) { mp_exp_t e; if (!mpfr_number_p(b)) { DEBUG_SPECIAL; mpq_set_si(a,0,1); return false; } /* XXX might fail if scaled exponent not representable in mp_exp_t */ e = mpfr_get_z_exp(mpq_numref(a),b); mpz_set_si(mpq_denref(a),1); if (e>0) mpq_mul_2exp(a,a,e); if (e<0) mpq_div_2exp(a,a,-e); return true; } /* numflt -> double */ static inline bool double_set_numflt(double* a, numflt_t b) { *a = mpfr_get_d(b,GMP_RNDU); return !mpfr_cmp_d(b,*a); } /* numflt -> mpfr */ static inline bool mpfr_set_numflt(mpfr_t a, numflt_t b) { return !mpfr_set(a,b,GMP_RNDU); } static inline bool mpz_fits_numflt(mpz_t a) { return mpz_sizeinbase(a,2)+1<(size_t)mpfr_get_emax(); } static inline bool mpq_fits_numflt(mpq_t a) { return ((int)mpz_sizeinbase(mpq_numref(a),2)- (int)mpz_sizeinbase(mpq_denref(a),2)+10?1:2 ; return 1; } /* normal case */ mpz_init(z); /* XXX might fail if scaled exponent not representable in mp_exp_t */ e = mpfr_get_z_exp(z,src); *((char*)dst) = mpz_sgn(z)>=0?3:4; mpz_export((char*)dst+9,&count,1,1,1,0,z); mpz_clear(z); /* XXX fails if count or exponent is more than 4-byte wide */ assert(((unsigned)count)==count); assert(((int)e)==e); num_dump_word32((char*)dst+1,(unsigned)count); num_dump_word32((char*)dst+5,(unsigned)count); return count+9; } static inline size_t numflt_deserialize(numflt_t dst, const void* src) { size_t count; mp_exp_t e; mpz_t z; switch (*((const char*)src)) { case 0: mpfr_set_nan(dst); return 1; case 1: mpfr_set_inf(dst,1); return 1; case 2: mpfr_set_inf(dst,-1); return 1; case 3: case 4: count = num_undump_word32((const char*)src+1); e = (int)num_undump_word32((const char*)src+5); mpz_init(z); mpz_import(z,count,1,1,1,0,(const char*)src+9); mpfr_set_z(dst,z,GMP_RNDU); mpfr_mul_2si(dst,dst,e,GMP_RNDU); if (*((const char*)src)==4) mpfr_neg(dst,dst,GMP_RNDU); mpz_clear(z); return count+9; default: assert(0); return 1; } } /* not the exact size of serialized data, but a sound overapproximation */ static inline size_t numflt_serialized_size(numflt_t a) { return mpfr_get_prec(a)/8+9+sizeof(mp_limb_t); } /* */ static inline bool ap_scalar_set_numflt(ap_scalar_t* a, numflt_t b) { ap_scalar_reinit(a,AP_SCALAR_MPFR); return mpfr_set_numflt(a->val.mpfr,b); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/num/bound_def.h0000640014525101416610000004247411006063143017566 0ustar bjeannetpopart/* ********************************************************************** */ /* bound_def.h: numbers used for bounds */ /* ********************************************************************** */ #ifndef _BOUND_DEF_H_ #define _BOUND_DEF_H_ #ifndef _BOUND_H_ #error "File bound_def.h should not be included directly, only via bound.h" #endif #include #ifdef __cplusplus extern "C" { #endif #if defined(NUM_MAX) || defined(NUM_NUMRAT) || defined(NUM_NUMFLT) typedef num_t bound_t; #define bound_numref(a) a #define _bound_inf(a) #define BOUND_NUM #else typedef struct _bound_t { num_t num; /* always allocated, even if inf=1 */ char inf; /* 1 => +/-oo; the sign of num decides the sign of the oo 0 => >-oo, <+oo */ } bound_t[1]; #define bound_numref(a) a->num #define _bound_inf(a) a->inf = 0 #define BOUND_NUM_INF #endif /* ---------------------------------------------------------------------- */ static inline bool bound_infty(bound_t a) #if defined(NUM_NUMFLT) { return numflt_infty(a); } #elif defined(NUM_MAX) { return (*a>=NUM_MAX || *a<=-NUM_MAX); } #elif defined(NUM_NUMRAT) { return numint_sgn(numrat_denref(a))==0; } #else { return (bool)a->inf; } #endif /* ---------------------------------------------------------------------- */ static inline void bound_set_infty(bound_t a, int sgn) #if defined(NUM_NUMFLT) { assert(sgn); numflt_set_infty(a,sgn); } #elif defined(NUM_MAX) { assert(sgn); *a = sgn>0 ? NUM_MAX : -NUM_MAX; } #elif defined(NUM_NUMRAT) { assert(sgn); numint_set_int(numrat_numref(a),sgn>0 ? 1 : -1); numint_set_int(numrat_denref(a),0); } #else { assert(sgn); num_set_int(a->num,sgn>0 ? 1 : -1); a->inf = 1; } #endif /* ---------------------------------------------------------------------- */ static inline void bound_init_set_infty(bound_t a, int sgn) { num_init(bound_numref(a)); bound_set_infty(a,sgn); } static inline void bound_swap(bound_t a, bound_t b) { #if defined(BOUND_NUM_INF) int t = a->inf; a->inf = b->inf; b->inf = t; #endif num_swap(bound_numref(a),bound_numref(b)); } static inline int bound_sgn(bound_t a) { return num_sgn(bound_numref(a)); } /* ====================================================================== */ /* Assignement */ /* ====================================================================== */ #if defined(BOUND_NUM) static inline void bound_set(bound_t a, bound_t b) { num_set(a,b); } static inline void bound_set_array(bound_t* a, bound_t* b, size_t size) { num_set_array(a,b,size); } #elif defined(NUM_NATIVE) static inline void bound_set(bound_t a, bound_t b) { *a = *b; } static inline void bound_set_array(bound_t* a, bound_t* b, size_t size) { memcpy(a,b,size*sizeof(bound_t)); } #else static inline void bound_set(bound_t a, bound_t b) { num_set(a->num,b->num); a->inf = b->inf; } static inline void bound_set_array(bound_t* a, bound_t* b, size_t size) { size_t i; for (i=0; i0) bound_set(a,c); else bound_set(a,b); else if (bound_infty(c)) if (bound_sgn(c)>0) bound_set(a,b); else bound_set(a,c); else { num_min(bound_numref(a),bound_numref(b),bound_numref(c)); _bound_inf(a); } } static inline void bound_max(bound_t a, bound_t b, bound_t c) { if (bound_infty(b)) if (bound_sgn(b)>0) bound_set(a,b); else bound_set(a,c); else if (bound_infty(c)) if (bound_sgn(c)>0) bound_set(a,c); else bound_set(a,b); else { num_max(bound_numref(a),bound_numref(b),bound_numref(c)); _bound_inf(a); } } #endif static inline void bound_floor(bound_t a, bound_t b) { if (bound_infty(b)) bound_set_infty(a,bound_sgn(b)); else { num_floor(bound_numref(a),bound_numref(b)); _bound_inf(a); } } static inline void bound_ceil(bound_t a, bound_t b) { if (bound_infty(b)) bound_set_infty(a,bound_sgn(b)); else { num_ceil(bound_numref(a),bound_numref(b)); _bound_inf(a); } } static inline void bound_trunc(bound_t a, bound_t b) { if (bound_infty(b)) bound_set_infty(a,bound_sgn(b)); else { num_trunc(bound_numref(a),bound_numref(b)); _bound_inf(a); } } static inline void bound_sqrt(bound_t up, bound_t down, bound_t b) { if (bound_infty(b)) { bound_set_infty(up,1); bound_set_infty(down,1); } else { num_sqrt(bound_numref(up),bound_numref(down),bound_numref(b)); _bound_inf(up); _bound_inf(down); } } static inline void bound_to_float(bound_t a, bound_t b) { if (bound_infty(b) || !num_fits_float(bound_numref(b))) bound_set_infty(a,bound_sgn(b)); else { double d; double_set_num(&d,bound_numref(b)); num_set_double(bound_numref(a),(double)((float)d)); _bound_inf(a); } } static inline void bound_to_double(bound_t a, bound_t b) { if (bound_infty(b) || !num_fits_double(bound_numref(b))) bound_set_infty(a,bound_sgn(b)); else { double d; double_set_num(&d,bound_numref(b)); num_set_double(bound_numref(a),d); _bound_inf(a); } } static inline void bound_mul_2exp(bound_t a, bound_t b, int c) { if (bound_infty(b)) bound_set_infty(a,bound_sgn(b)); else { num_mul_2exp(bound_numref(a),bound_numref(b),c); } } /* ====================================================================== */ /* Arithmetic Tests */ /* ====================================================================== */ #if defined(NUM_MAX) || defined(NUM_NUMFLT) static inline int bound_cmp(bound_t a, bound_t b) { return num_cmp(a,b); } static inline int bound_cmp_int(bound_t a, long int b) { return num_cmp_int(a,b); } static inline int bound_cmp_num(bound_t a, num_t b) { return num_cmp(a,b); } static inline bool bound_equal(bound_t a, bound_t b) { return num_equal(a,b); } static inline int bound_hash(bound_t a) { long int hash; int_set_num(&hash,bound_numref(a)); return hash; } #else static inline int bound_cmp(bound_t a, bound_t b) { if (bound_infty(a)){ if (bound_infty(b)) return (bound_sgn(a)-bound_sgn(b))/2; else return bound_sgn(a); } else { if (bound_infty(b)) return -bound_sgn(b); else return num_cmp(bound_numref(a),bound_numref(b)); } } static inline int bound_cmp_int(bound_t a, long int b) { if (bound_infty(a)) return bound_sgn(a); else return num_cmp_int(bound_numref(a),b); } static inline int bound_cmp_num(bound_t a, num_t b) { if (bound_infty(a)) return bound_sgn(a); else return num_cmp(bound_numref(a),b); } static inline bool bound_equal(bound_t a, bound_t b) { if (bound_infty(a)){ return bound_infty(b) && bound_sgn(a)==bound_sgn(b); } else { if (bound_infty(b)) return false; else return num_equal(bound_numref(a),bound_numref(b)); } } static inline int bound_hash(bound_t a) { if (bound_infty(a)) return bound_sgn(a)>0 ? INT_MAX : INT_MIN; else { long int hash; int_set_num(&hash,bound_numref(a)); return hash; } } #endif /* ====================================================================== */ /* Printing */ /* ====================================================================== */ static inline void bound_fprint(FILE* stream, bound_t a) { if (bound_infty(a)) fprintf(stream,"%coo",bound_sgn(a)>0 ? '+' : '-'); else num_fprint(stream,bound_numref(a)); } static inline void bound_print(bound_t a) { bound_fprint(stdout,a); } static inline int bound_snprint(char* s, size_t size, bound_t a) { if (bound_infty(a)) return snprintf(s,size,"%coo",bound_sgn(a)>0 ? '+' : '-'); else return num_snprint(s,size,bound_numref(a)); } /* ====================================================================== */ /* Conversions */ /* ====================================================================== */ /* Convert an ap_scalar_t into a bound_t */ static inline bool bound_set_ap_scalar(bound_t a, ap_scalar_t* b) { switch (b->discr){ case AP_SCALAR_MPQ: if (mpz_sgn(mpq_denref(b->val.mpq))==0){ bound_set_infty(a,mpz_sgn(mpq_numref(b->val.mpq))); return true; } else { _bound_inf(a); return num_set_mpq(bound_numref(a),b->val.mpq); } break; case AP_SCALAR_DOUBLE: if (isinf(b->val.dbl)) { if (b->val.dbl>0) bound_set_infty(a,1); else bound_set_infty(a,-1); return true; } else { _bound_inf(a); return num_set_double(bound_numref(a),b->val.dbl); } break; case AP_SCALAR_MPFR: if (mpfr_inf_p(b->val.mpfr)) { if (mpfr_sgn(b->val.mpfr)>0) bound_set_infty(a,1); else bound_set_infty(a,-1); return true; } else { _bound_inf(a); return num_set_mpfr(bound_numref(a),b->val.mpfr); } break; default: abort(); return false; } } /* Convert a bound_t into an ap_scalar_t */ static inline bool ap_scalar_set_bound(ap_scalar_t* a, bound_t b) { ap_scalar_reinit(a,NUM_AP_SCALAR); if (bound_infty(b)) { ap_scalar_set_infty(a,bound_sgn(b)); return true; } else { switch (NUM_AP_SCALAR) { case AP_SCALAR_DOUBLE: return double_set_num(&a->val.dbl,bound_numref(b)); case AP_SCALAR_MPQ: return mpq_set_num(a->val.mpq,bound_numref(b)); case AP_SCALAR_MPFR: return mpfr_set_num(a->val.mpfr,bound_numref(b)); default: abort(); return false; } } } /* ====================================================================== */ /* Serialization */ /* ====================================================================== */ static inline size_t bound_serialize(void* dst, bound_t src) { #if defined(BOUND_NUM) return num_serialize(dst,src); #else *(char*)dst = src->inf; return num_serialize((char*)dst+1,bound_numref(src))+1; #endif } static inline size_t bound_deserialize(bound_t dst, const void* src) { #if defined(BOUND_NUM) return num_deserialize(dst,src); #else dst->inf = *(const char*)src; return num_deserialize(bound_numref(dst),(const char*)src+1)+1; #endif } static inline size_t bound_serialized_size(bound_t a) { #if defined(BOUND_NUM) return num_serialized_size(a); #else return num_serialized_size(bound_numref(a))+1; #endif } static inline size_t bound_serialize_array(void* dst, bound_t* src, size_t size) { size_t i,n=0; for (i=0;i #include #include #include #include #include #include #include "gmp.h" #include "mpfr.h" /* Be aware: we erase the (obsolete) GMP function mpq_set_num */ #undef mpq_set_num #include "num_config.h" #if defined(NUM_LONGINT) || defined(NUM_LONGLONGINT) || defined(NUM_MPZ) #include "num_numint.h" #elif defined(NUM_LONGRAT) || defined(NUM_LONGLONGRAT) || defined(NUM_MPQ) #include "num_numrat.h" #elif defined(NUM_DOUBLE) || defined(NUM_LONGDOUBLE) || defined(NUM_MPFR) #include "num_numflt.h" #else #error "HERE" #endif #include "num_name.h" #ifdef __cplusplus extern "C" { #endif /* Parameter: one of the following macros should be defined: NUM_LONGINT, NUM_LONGLONGINT, NUM_MPZ, NUM_LONGRAT, NUM_LONGLONGRAT, NUM_MPQ, NUM_DOUBLE, NUM_LONGDOUBLE, NUM_MPFR Each parameter induces the definition of the following macros: NUM_LONGINT: NUM_NUMINT, NUMINT_LONGINT, NUM_MAX, NUMINT_MAX, NUM_NATIVE, NUMINT_NATIVE NUM_LONGLONGINT: NUM_NUMINT, NUMINT_LONGLONGINT, NUM_MAX, NUMINT_MAX, NUM_NATIVE, NUMINT_NATIVE NUM_MPZ: NUM_NUMINT, NUMINT_MPZ NUM_LONGRAT: NUM_NUMRAT, NUMINT_LONGINT, NUM_NATIVE, NUMINT_NATIVE NUM_LONGLONGRAT: NUM_NUMRAT, NUMINT_LONGLONGINT, NUM_NATIVE, NUMINT_NATIVE NUM_MPQ: NUM_NUMRAT, NUMINT_MPZ NUM_DOUBLE: NUM_NUMFLT, NUMFLT_DOUBLE, NUM_MAX, NUMFLT_MAX, NUM_NATIVE, NUMFLT_NATIVE NUM_LONGDOUBLE: NUM_NUMFLT, NUMFLT_LONGDOUBLE, NUM_MAX, NUMFLT_MAX, NUM_NATIVE, NUMFLT_NATIVE Additionally, the following macros are defined: NUM_NAME litteral string with human-readable name of number type NUM_SUFFIX tag uniquely defining the number type (can be used as a function suffix) NUM_AP_SCALAR preferred AP_SCALAR_ type NUMFUN(x) name-mangling: append NUM_SUFFIX to x */ /* ====================================================================== */ /* Assignement */ /* ====================================================================== */ static inline void num_set(num_t a, num_t b); static inline void num_set_array(num_t* a, num_t* b, size_t size); static inline void num_set_int(num_t a, long int i); /* ====================================================================== */ /* Constructors and Destructors */ /* ====================================================================== */ static inline void num_init(num_t a); static inline void num_init_array(num_t* a, size_t size); static inline void num_init_set(num_t a, num_t b); static inline void num_init_set_int(num_t a, long int i); static inline void num_clear(num_t a); static inline void num_clear_array(num_t* a, size_t size); static inline void num_swap(num_t a, num_t b); /* ====================================================================== */ /* Arithmetic Operations */ /* ====================================================================== */ static inline void num_neg(num_t a, num_t b); static inline void num_abs(num_t a, num_t b); static inline void num_add(num_t a, num_t b, num_t c); static inline void num_add_uint(num_t a, num_t b, unsigned long int c); static inline void num_sub(num_t a, num_t b, num_t c); static inline void num_sub_uint(num_t a, num_t b, unsigned long int c); static inline void num_mul(num_t a, num_t b, num_t c); static inline void num_mul_2(num_t a, num_t b); static inline void num_div(num_t a, num_t b, num_t c); static inline void num_div_2(num_t a, num_t b); static inline void num_min(num_t a, num_t b, num_t c); static inline void num_max(num_t a, num_t b, num_t c); static inline void num_mul_2exp(num_t a, num_t b, int c); /* multiplies b by 2^c (c can be positive or negative) */ static inline void num_floor(num_t a, num_t b); static inline void num_ceil(num_t a, num_t b); static inline void num_trunc(num_t a, num_t b); /* Approximate to the nearest integer toward resp. -infty, +infty */ static inline void num_sqrt(num_t up, num_t down, num_t b); /* Compute both an upper bound and a lower bound */ /* ====================================================================== */ /* Arithmetic Tests */ /* ====================================================================== */ static inline int num_sgn(num_t a); static inline int num_cmp(num_t a, num_t b); static inline int num_cmp_int(num_t a, long int b); static inline bool num_equal(num_t a, num_t b); static inline bool num_integer(num_t a); /* ====================================================================== */ /* Printing */ /* ====================================================================== */ static inline void num_print(num_t a); static inline void num_fprint(FILE* stream, num_t a); static inline int num_snprint(char* s, size_t size, num_t a); /* ====================================================================== */ /* Conversions */ /* ====================================================================== */ static inline bool num_set_int2(num_t a, long int i, long int j); /* int2 -> num */ static inline bool num_set_mpz(num_t a, mpz_t b); /* mpz -> num */ static inline bool num_set_mpq(num_t a, mpq_t b); /* mpq -> num */ static inline bool num_set_double(num_t a, double b); /* double -> num */ static inline bool num_set_mpfr(num_t a, mpfr_t b); /* mpfr -> num */ static inline bool num_set_ap_scalar(num_t a, ap_scalar_t* b); /* (finite) ap_scalar -> num */ static inline bool int_set_num(long int* a, num_t b); /* num -> int */ static inline bool mpz_set_num(mpz_t a, num_t b); /* num -> mpz */ static inline bool mpq_set_num(mpq_t a, num_t b); /* num -> mpq */ static inline bool double_set_num(double* a, num_t b); /* num -> double */ static inline bool float_set_num(float* a, num_t b); /* num -> float */ static inline bool mpfr_set_num(mpfr_t a, num_t b); /* num -> mpfr */ static inline bool ap_scalar_set_num(ap_scalar_t* a, num_t b); /* num -> ap_scalar */ static inline bool mpz_fits_num(mpz_t a); static inline bool mpq_fits_num(mpq_t a); static inline bool double_fits_num(double a); static inline bool mpfr_fits_num(mpfr_t a); static inline bool num_fits_int(num_t a); static inline bool num_fits_float(num_t a); static inline bool num_fits_double(num_t a); static inline bool num_fits_mpfr(num_t a); /* Optimized versions */ /* mpfr should have exactly the precision NUMFLT_MANT_DIG */ static inline bool num_set_mpz_tmp(num_t a, mpz_t b, mpfr_t mpfr); static inline bool num_set_mpq_tmp(num_t a, mpq_t b, mpz_t q, mpz_t r, mpfr_t mpfr); static inline bool num_set_double_tmp(num_t a, double k, mpq_t mpq); static inline bool int_set_num_tmp(long int* a, num_t b, mpz_t q, mpz_t r); static inline bool mpz_set_num_tmp(mpz_t a, num_t b, mpz_t mpz); /* mpfr should have exactly the precision DBL_MANT_DIG */ static inline bool double_set_num_tmp(double* a, num_t b, mpq_t mpq, mpfr_t mpfr); static inline bool mpq_fits_num_tmp(mpq_t a, mpz_t mpz); static inline bool double_fits_num_tmp(double k, mpq_t mpq); /* ====================================================================== */ /* Serialization */ /* ====================================================================== */ /* Notes: - call _serialized_size to get the minimal size of the buffer to allocate - _serialize then returns the actual size of the serialized data (may be less than _serialized_size) - deserialze assumes that the num destination has already been initialized - when deserializing an array, you must supply the number of elements in the array (it is not stored with the array by serialize) - serialization is not type-safe (it depends on the chosen numerical type and, for types using native integers, on whether the machine is 32 or 64 bits). You can only deserialize data if the num_serialize_id function returns the same value as when the data was serialized. (This id is not stored systematically with each serialized number to save state, so, the checking is up to you.) */ static inline unsigned char num_serialize_id(void); static inline size_t num_serialize(void* dst, num_t src); static inline size_t num_deserialize(num_t dst, const void* src); static inline size_t num_serialized_size(num_t a); static inline size_t num_serialize_array(void* dst, num_t* src, size_t size) { size_t i,n=0; for (i=0;i #include #include #include #include #include #include #include "gmp.h" #include "mpfr.h" #include "ap_scalar.h" #include "num_config.h" /* Require C99 compliant compiler */ #ifdef __cplusplus extern "C" { #endif #if defined(NUMINT_LONGINT) typedef long int numint_native; #define NUMINT_ZERO 0L #define NUMINT_ONE 1L #define NUMINT_MAX LONG_MAX #define NUMINT_MIN LONG_MIN #elif defined(NUMINT_LONGLONGINT) typedef long long int numint_native; #define NUMINT_ZERO 0LL #define NUMINT_ONE 1LL #define NUMINT_MAX LLONG_MAX #define NUMINT_MIN LLONG_MIN #else #error "HERE" #endif typedef numint_native numint_t[1]; #define NUMINT_NATIVE # /* ====================================================================== */ /* Assignement */ /* ====================================================================== */ static inline void numint_set(numint_t a, numint_t b) { *a = *b; } static inline void numint_set_array(numint_t* a, numint_t* b, size_t size) { memcpy(a,b,size*sizeof(numint_t)); } static inline void numint_set_int(numint_t a, long int i) { *a = (numint_native)i; } /* ====================================================================== */ /* Constructors and Destructors */ /* ====================================================================== */ static inline void numint_init(numint_t a) { *a = NUMINT_ZERO; } static inline void numint_init_array(numint_t* a, size_t size) { size_t i; for (i=0; iNUMINT_ZERO ? 1 : -1)); } static inline void numint_fdiv_q(numint_t q, numint_t a, numint_t b) { if (numint_sgn(a)*numint_sgn(b)<0 && *a % *b) *q = *a / *b - 1; else *q = *a / *b; } static inline void numint_cdiv_q(numint_t q, numint_t a, numint_t b) { if (numint_sgn(a)*numint_sgn(b)>0 && *a % *b) *q = *a / *b + 1; else *q = *a / *b; } static inline void numint_cdiv_qr(numint_t q, numint_t r, numint_t a, numint_t b) { numint_t qq,rr; *qq = *a / *b; *rr = *a % *b; if (numint_sgn(a)*numint_sgn(b)>0 && *rr) { *q = *qq + 1; *r = *rr - *b; } else { *q = *qq; *r = *rr; } } static inline void numint_cdiv_2(numint_t a, numint_t b) { *a = (*b>=NUMINT_ZERO) ? (*b+1)/2 : *b/2; } static inline void numint_cdiv_q_2exp(numint_t a, numint_t b, unsigned long int c) { *a = (*b >> c)+(*b & ((NUMINT_ONE<> c); } static inline void numint_min(numint_t a, numint_t b, numint_t c) { *a = (*b<=*c) ? *b : *c; } static inline void numint_max(numint_t a, numint_t b, numint_t c) { *a = (*b>=*c) ? *b : *c; } static const long long numint_max_exact_double = 1LL << 52; static inline void numint_sqrt(numint_t up, numint_t down, numint_t b) { double f = sqrt(*b); assert(*b>=0); if (*b=0) *a = *b << c; else numint_cdiv_q_2exp(a,b,-c); } /* ====================================================================== */ /* Arithmetic Integer Operations */ /* ====================================================================== */ static inline void numint_divexact(numint_t a, numint_t b, numint_t c) { *a = *b / *c; } static inline void numint_mod(numint_t a, numint_t b, numint_t c) { *a = *b % *c; } static inline numint_native _gcd_aux2(numint_native a, numint_native b) { /* a is supposed to be greater than b */ numint_native t; while (b!=NUMINT_ZERO && a!=b) { t = b; b = a % b; a = t; } return a; } static inline numint_native _gcd_aux(numint_native a, numint_native b) { numint_abs(&a,&a); numint_abs(&b,&b); return (a>=b) ? _gcd_aux2(a,b) : _gcd_aux2(b,a); } static inline void numint_gcd(numint_t a, numint_t b, numint_t c) { *a = _gcd_aux(*b,*c); } static inline numint_native _lcm_aux(numint_native a, numint_native b) { numint_abs(&a,&a); numint_abs(&b,&b); return a / _gcd_aux(a,b) * b; } static inline void numint_lcm(numint_t a, numint_t b, numint_t c) { *a = _lcm_aux(*b,*c); } /* ====================================================================== */ /* Arithmetic Tests */ /* ====================================================================== */ static inline int numint_cmp(numint_t a, numint_t b) { return (*a==*b ? 0 : (*a>*b ? 1 : -1)); } static inline int numint_cmp_int(numint_t a, long int b) { return (*a==b ? 0 : (*a>b ? 1 : -1)); } static inline bool numint_equal(numint_t a, numint_t b) { return *a==*b; } static inline bool numint_integer(numint_t a) { return true; } /* ====================================================================== */ /* Printing */ /* ====================================================================== */ #if defined(NUMINT_LONGINT) static inline void numint_print(numint_t a) { printf("%li",*a); } static inline void numint_fprint(FILE* stream, numint_t a) { fprintf(stream,"%li",*a); } static inline int numint_snprint(char* s, size_t size, numint_t a) { return snprintf(s,size,"%li",*a); } #else static inline void numint_print(numint_t a) { printf("%lli",*a); } static inline void numint_fprint(FILE* stream, numint_t a) { fprintf(stream,"%lli",*a); } static inline int numint_snprint(char* s, size_t size, numint_t a) { return snprintf(s,size,"%lli",*a); } #endif /* ====================================================================== */ /* Conversions */ /* ====================================================================== */ /* int2 -> numint */ static inline bool numint_set_int2(numint_t a, long int i, long int j) { assert(j>0); if (i>=0) *a = (i+j-1)/j; else *a = i/j; return (i%j) ? false : true; } /* mpz -> numint */ static inline bool numint_set_mpz(numint_t a, mpz_t b) { if (sizeof(numint_t)==sizeof(long int)) { *a = mpz_get_si(b); } else if (sizeof(numint_t)==2*sizeof(long int)) { int sgn; size_t count; unsigned long int tab[2]; sgn = mpz_sgn(b); mpz_export(&tab,&count,1,sizeof(long int),0,0,b); if (count==0){ *a = 0; } else { *a = tab[0]; if (count==2){ *a = *a << (sizeof(long int)*8); *a = *a + (long long int)(tab[1]); if (*a<0){ assert(0); } } if (sgn<0) *a = -(*a); } } else assert(0); return true; } /* mpq -> numint */ static inline bool numint_set_mpq_tmp(numint_t a, mpq_t b, mpz_t q, mpz_t r) { mpz_cdiv_qr(q,r, mpq_numref(b),mpq_denref(b)); numint_set_mpz(a,q); bool res = (mpz_sgn(r)==0); return res; } static inline bool numint_set_mpq(numint_t a, mpq_t b) { mpz_t q,r; mpz_init(q);mpz_init(r); bool res = numint_set_mpq_tmp(a,b,q,r); mpz_clear(q); mpz_clear(r); return res; } /* double -> numint */ static inline bool numint_set_double(numint_t a, double b) { double c = ceil(b); if (!isfinite(c)) { DEBUG_SPECIAL; *a = 0; return false; } *a = c; return (b==c); } /* mpfr -> numint */ static inline bool numint_set_mpfr(numint_t a, mpfr_t b) { if (!mpfr_number_p(b)) { DEBUG_SPECIAL; numint_set_int(a,0); return false; } #if defined(NUMINT_LONGINT) *a = mpfr_get_si(b,GMP_RNDU); #else *a = mpfr_get_sj(b,GMP_RNDU); #endif return mpfr_integer_p(b); } /* numint -> int */ static inline bool int_set_numint(long int* a, numint_t b) { *a = (long int)(*b); return true; } /* numint -> mpz */ static inline bool mpz_set_numint(mpz_t a, numint_t b) { if (sizeof(numint_t)==sizeof(long int)) { mpz_set_si(a,*b); } else if (sizeof(numint_t)==2*sizeof(long int)) { unsigned long long int n; unsigned long int rep[2]; n = llabs(*b); rep[1] = n & ULONG_MAX; rep[0] = n >> (sizeof(long int)*8); mpz_import(a,2,1,sizeof(unsigned long int),0,0,rep); if (*b<0) mpz_neg(a,a); } else assert(0); return true; } /* numint -> mpq */ static inline bool mpq_set_numint(mpq_t a, numint_t b) { if (sizeof(numint_t)==sizeof(long int)) { mpq_set_si(a,*b,1); return true; } else { mpz_set_ui(mpq_denref(a),1); return mpz_set_numint(mpq_numref(a),b); } } /* numint -> double */ static inline bool double_set_numint(double* a, numint_t b) { *a = (double)(*b); double aa = -((double)(-(*b))); return (*a==aa); } /* numint -> mpfr */ static inline bool mpfr_set_numint(mpfr_t a, numint_t b) { #if defined(NUMINT_LONGINT) return !mpfr_set_si(a,*b,GMP_RNDU); #else return !mpfr_set_sj(a,*b,GMP_RNDU); #endif } static inline bool mpz_fits_numint(mpz_t a) { if (sizeof(numint_t)==sizeof(long int)) { return mpz_fits_slong_p(a); } else { size_t size = mpz_sizeinbase(a,2); return (size <= sizeof(numint_t)*8-1); } } static inline bool mpq_fits_numint_tmp(mpq_t a, mpz_t mpz) { mpz_cdiv_q(mpz,mpq_numref(a),mpq_denref(a)); bool res = mpz_fits_numint(mpz); return res; } static inline bool mpq_fits_numint(mpq_t a) { mpz_t mpz; mpz_init(mpz); bool res = mpq_fits_numint_tmp(a,mpz); mpz_clear(mpz); return res; } static inline bool double_fits_numint(double a) { return isfinite(a) && a>=(double)(-NUMINT_MAX) && a<=(double)NUMINT_MAX; } static inline bool mpfr_fits_numint(mpfr_t a) { #if defined(NUMINT_LONGINT) return mpfr_number_p(a) && mpfr_fits_slong_p(a,GMP_RNDU); #else return mpfr_number_p(a) && mpfr_fits_intmax_p(a,GMP_RNDU); #endif } static inline bool numint_fits_int(numint_t a) #if defined(NUMINT_LONGINT) { return true; } #else { return (*a>=-LONG_MAX && *a<=LONG_MAX); } #endif static inline bool numint_fits_float(numint_t a) { return true; } static inline bool numint_fits_double(numint_t a) { return true; } static inline bool numint_fits_mpfr(numint_t a) { return true; } /* ====================================================================== */ /* Serialization */ /* ====================================================================== */ static inline unsigned char numint_serialize_id(void) { return sizeof(numint_t)/4; } static inline size_t numint_serialize(void* dst, numint_t src) { num_store_words8(dst,src,sizeof(numint_t)); return sizeof(numint_t); } static inline size_t numint_deserialize(numint_t dst, const void* src) { num_store_words8(dst,src,sizeof(numint_t)); return sizeof(numint_t); } static inline size_t numint_serialized_size(numint_t a) { return sizeof(numint_t); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/num/Makefile0000640014525101416610000000356511005654323017133 0ustar bjeannetpopartinclude ../Makefile.config H_FILES = \ num_config.h \ num.h \ num_numint.h \ num_numrat.h \ num_numflt.h \ numint.h \ numint_native.h \ numint_mpz.h \ numrat.h \ numrat_native.h \ numrat_mpq.h \ numflt.h \ numflt_native.h \ numflt_mpfr.h \ num_name.h \ bound.h \ bound_def.h all: install: mkdir -p $(APRON_PREFIX)/include cp $(H_FILES) $(APRON_PREFIX)/include distclean: (cd $(APRON_PREFIX)/include; /bin/rm -f $(H_FILES)) dist: $(H_FILES) Makefile README (cd ..; tar zcvf num.tgz $(^:%=num/%)) clean: rm -f testl* testmp* testdbl testldbl testmpfr ICFLAGS = -I../apron -I$(APRON_PREFIX)/include -I$(GMP_PREFIX)/include -I$(MPFR_PREFIX)/include -L$(APRON_PREFIX)/lib -L$(GMP_PREFIX)/lib -L$(MPFR_PREFIX)/lib CLIBS = -L../apron -lapron -lmpfr -lgmp -lm tests: testli testlli testlr testllr testmpz testmpq testdbl testldbl testmpfr testli: test.c $(H_FILES) $(CC) -g $(CFLAGS) $(ICFLAGS) -DNUM_LONGINT -o $@ test.c $(CLIBS) testlli: test.c $(H_FILES) $(CC) -g $(CFLAGS) $(ICFLAGS) -DNUM_LONGLONGINT -o $@ test.c $(CLIBS) testlr: test.c $(H_FILES) $(CC) -g $(CFLAGS) $(ICFLAGS) -DNUM_LONGRAT -o $@ test.c $(CLIBS) testllr: test.c $(H_FILES) $(CC) -g $(CFLAGS) $(ICFLAGS) -DNUM_LONGLONGRAT -o $@ test.c $(CLIBS) testmpz: test.c $(H_FILES) $(CC) -g $(CFLAGS) $(ICFLAGS) -DNUM_MPZ -o $@ test.c $(CLIBS) testmpq: test.c $(H_FILES) $(CC) -g $(CFLAGS) $(ICFLAGS) -DNUM_MPQ -o $@ test.c $(CLIBS) testdbl: test.c $(H_FILES) $(CC) -g $(CFLAGS) $(ICFLAGS) -DNUM_DOUBLE -o $@ test.c $(CLIBS) testldbl: test.c $(H_FILES) $(CC) -g $(CFLAGS) $(ICFLAGS) -DNUM_LONGDOUBLE -o $@ test.c $(CLIBS) testmpfr: test.c $(H_FILES) $(CC) -g $(CFLAGS) $(ICFLAGS) -DNUM_MPFR -o $@ test.c $(CLIBS) out: tests ./testli > out.li ./testlli > out.lli ./testlr > out.lr ./testllr > out.llr ./testmpz > out.mpz ./testmpq > out.mpq ./testdbl > out.dbl ./testldbl > out.ldbl ./testmpfr > out.mpfr apron-dist-0.9.10/apron/num/num_numflt.h0000640014525101416610000002065011006063143020015 0ustar bjeannetpopart/* ********************************************************************** */ /* num_numflt.h */ /* ********************************************************************** */ #ifndef _NUM_NUMFLT_H_ #define _NUM_NUMFLT_H_ #ifndef _NUM_H_ #error "File num_numflt.h should not be included directly, only via num.h" #endif #if defined(NUM_DOUBLE) #define NUMFLT_DOUBLE #define NUM_AP_SCALAR AP_SCALAR_DOUBLE #elif defined(NUM_LONGDOUBLE) #define NUMFLT_LONGDOUBLE #define NUM_AP_SCALAR AP_SCALAR_DOUBLE #elif defined(NUM_MPFR) #define NUMFLT_MPFR #define NUM_AP_SCALAR AP_SCALAR_MPFR #else #error "HERE" #endif #include "numflt.h" #ifdef __cplusplus extern "C" { #endif typedef numflt_t num_t; #define NUM_NUMFLT #ifdef NUMFLT_MAX #define NUM_MAX NUMFLT_MAX #endif #ifdef NUMFLT_NATIVE #define NUM_NATIVE #endif /* ====================================================================== */ /* Assignement */ /* ====================================================================== */ static inline void num_set(num_t a, num_t b) { numflt_set(a,b); } static inline void num_set_array(num_t* a, num_t* b, size_t size) { numflt_set_array(a,b,size); } static inline void num_set_int(num_t a, long int i) { numflt_set_int(a,i); } /* ====================================================================== */ /* Constructors and Destructors */ /* ====================================================================== */ static inline void num_init(num_t a) { numflt_init(a); } static inline void num_init_array(num_t* a, size_t size) { numflt_init_array(a,size); } static inline void num_init_set(num_t a, num_t b) { numflt_init_set(a,b); } static inline void num_init_set_int(num_t a, long int i) { numflt_init_set_int(a,i); } static inline void num_clear(num_t a) { numflt_clear(a); } static inline void num_clear_array(num_t* a, size_t size) { numflt_clear_array(a,size); } static inline void num_swap(num_t a, num_t b) { numflt_swap(a,b); } /* ====================================================================== */ /* Arithmetic Operations */ /* ====================================================================== */ static inline void num_neg(num_t a, num_t b) { numflt_neg(a,b); } static inline void num_abs(num_t a, num_t b) { numflt_abs(a,b); } static inline void num_add(num_t a, num_t b, num_t c) { numflt_add(a,b,c); } static inline void num_add_uint(num_t a, num_t b, unsigned long int c) { numflt_add_uint(a,b,c); } static inline void num_sub(num_t a, num_t b, num_t c) { numflt_sub(a,b,c); } static inline void num_sub_uint(num_t a, num_t b, unsigned long int c) { numflt_sub_uint(a,b,c); } static inline void num_mul(num_t a, num_t b, num_t c) { numflt_mul(a,b,c); } static inline void num_mul_2(num_t a, num_t b) { numflt_mul_2(a,b); } static inline void num_div(num_t a, num_t b, num_t c) { numflt_div(a,b,c); } static inline void num_div_2(num_t a, num_t b) { numflt_div_2(a,b); } static inline void num_min(num_t a, num_t b, num_t c) { numflt_min(a,b,c); } static inline void num_max(num_t a, num_t b, num_t c) { numflt_max(a,b,c); } static inline void num_floor(num_t a, num_t b) { numflt_floor(a,b); } static inline void num_ceil(num_t a, num_t b) { numflt_ceil(a,b); } static inline void num_trunc(num_t a, num_t b) { numflt_trunc(a,b); } static inline void num_sqrt(num_t up, num_t down, num_t b) { numflt_sqrt(up,down,b); } static inline void num_mul_2exp(num_t a, num_t b, int c) { numflt_mul_2exp(a,b,c); } /* ====================================================================== */ /* Arithmetic Tests */ /* ====================================================================== */ static inline int num_sgn(num_t a) { return numflt_sgn(a); } static inline int num_cmp(num_t a, num_t b) { return numflt_cmp(a,b); } static inline int num_cmp_int(num_t a, long int b) { return numflt_cmp_int(a,b); } static inline bool num_equal(num_t a, num_t b) { return numflt_equal(a,b); } static inline bool num_integer(num_t a) { return numflt_integer(a); } /* ====================================================================== */ /* Printing */ /* ====================================================================== */ static inline void num_print(num_t a) { numflt_print(a); } static inline void num_fprint(FILE* stream, num_t a) { numflt_fprint(stream, a); } static inline int num_snprint(char* s, size_t size, num_t a) { return numflt_snprint(s,size,a); } /* ====================================================================== */ /* Conversions */ /* ====================================================================== */ static inline bool num_set_int2(num_t a, long int i, long int j) { return numflt_set_int2(a,i,j); } /* int2 -> num */ static inline bool num_set_mpz(num_t a, mpz_t b) { return numflt_set_mpz(a,b); } /* mpz -> num */ static inline bool num_set_mpq(num_t a, mpq_t b) { return numflt_set_mpq(a,b); } /* mpq -> num */ static inline bool num_set_double(num_t a, double k) { return numflt_set_double(a,k); } /* double -> num */ static inline bool num_set_mpfr(num_t a, mpfr_t k) { return numflt_set_mpfr(a,k); } /* mpfr -> num */ static inline bool num_set_ap_scalar(num_t a, ap_scalar_t* b) { return numflt_set_ap_scalar(a,b); } /* ap_scalar -> num */ static inline bool int_set_num(long int*a, num_t b) { return int_set_numflt(a,b); } /* num -> int */ static inline bool mpz_set_num(mpz_t a, num_t b) { return mpz_set_numflt(a,b); } /* num -> mpz */ static inline bool mpq_set_num(mpq_t a, num_t b) { return mpq_set_numflt(a,b); } /* num -> mpq */ static inline bool double_set_num(double* a, num_t b) { return double_set_numflt(a,b); } /* num -> double */ static inline bool mpfr_set_num(mpfr_t a, num_t b) { return mpfr_set_numflt(a,b); } /* num -> mpfr */ static inline bool ap_scalar_set_num(ap_scalar_t* a, num_t b) { return ap_scalar_set_numflt(a,b); } /* num -> ap_scalar */ static inline bool mpz_fits_num(mpz_t a) { return mpz_fits_numflt(a); } static inline bool mpq_fits_num(mpq_t a) { return mpq_fits_numflt(a); } static inline bool double_fits_num(double a) { return double_fits_numflt(a); } static inline bool mpfr_fits_num(mpfr_t a) { return mpfr_fits_numflt(a); } static inline bool num_fits_int(num_t a) { return numflt_fits_int(a); } static inline bool num_fits_float(num_t a) { return numflt_fits_double(a); } static inline bool num_fits_double(num_t a) { return numflt_fits_double(a); } static inline bool num_fits_mpfr(num_t a) { return numflt_fits_mpfr(a); } /* Optimized versions */ static inline bool num_set_mpz_tmp(numflt_t a, mpz_t b, mpfr_t mpfr) { return numflt_set_mpz_tmp(a,b,mpfr); } static inline bool num_set_mpq_tmp(numflt_t a, mpq_t b, mpz_t q, mpz_t r, mpfr_t mpfr) { return numflt_set_mpq_tmp(a,b,mpfr); } static inline bool mpq_fits_num_tmp(mpq_t a, mpz_t mpz) { return mpq_fits_numflt(a); } static inline bool num_set_double_tmp(num_t a, double k, mpq_t mpq) { return numflt_set_double(a,k); } static inline bool int_set_num_tmp(long int* a, num_t b, mpz_t q, mpz_t r) { return int_set_numflt(a,b); } static inline bool mpz_set_num_tmp(mpz_t a, num_t b, mpz_t mpz) { return mpz_set_numflt(a,b); } static inline bool double_set_num_tmp(double* a, num_t b, mpq_t mpq, mpfr_t mpfr) { return double_set_numflt(a,b); } static inline bool double_fits_num_tmp(double k, mpq_t mpq) { return double_fits_numflt(k); } /* ====================================================================== */ /* Serialization */ /* ====================================================================== */ static inline unsigned char num_serialize_id(void) { return numflt_serialize_id(); } static inline size_t num_serialize(void* dst, num_t src) { return numflt_serialize(dst,src); } static inline size_t num_deserialize(num_t dst, const void* src) { return numflt_deserialize(dst,src); } static inline size_t num_serialized_size(num_t a) { return numflt_serialized_size(a); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/num/numflt.h0000640014525101416610000001555211164715372017160 0ustar bjeannetpopart/* ********************************************************************** */ /* numflt.h */ /* ********************************************************************** */ #ifndef _NUMFLT_H_ #define _NUMFLT_H_ #include #include "gmp.h" #include "mpfr.h" #include "ap_scalar.h" #include "num_config.h" #ifndef NUMFLT_PRINT_PREC #define NUMFLT_PRINT_PREC 20 #endif /* Number of significant digits used for printing. Defaults to 20, but you can override NUMFLT_PRINT_PREC to be any other expression (including variable and function call). */ #if defined(NUMFLT_DOUBLE) || defined(NUMFLT_LONGDOUBLE) #include "numflt_native.h" #elif defined(NUMFLT_MPFR) #include "numflt_mpfr.h" #else #error "HERE" #endif #ifdef __cplusplus extern "C" { #endif /* NUMINT_DOUBLE and NUMFLT_LONGDOUBLE also define - NUMFLT_MAX: positive infinity value It is assumed that (-NUMINT_MAX) is also representable - NUMFLT_NATIVE: no heap allocated memory */ /* ====================================================================== */ /* Assignement */ /* ====================================================================== */ static inline void numflt_set(numflt_t a, numflt_t b); static inline void numflt_set_array(numflt_t* a, numflt_t* b, size_t size); static inline void numflt_set_int(numflt_t a, long int i); /* ====================================================================== */ /* Constructors and Destructors */ /* ====================================================================== */ static inline void numflt_init(numflt_t a); static inline void numflt_init_array(numflt_t* a, size_t size); static inline void numflt_init_set(numflt_t a, numflt_t b); static inline void numflt_init_set_int(numflt_t a, long int i); static inline void numflt_clear(numflt_t a); static inline void numflt_clear_array(numflt_t* a, size_t size); static inline void numflt_swap(numflt_t a, numflt_t b); /* ====================================================================== */ /* Arithmetic Operations */ /* ====================================================================== */ static inline void numflt_neg(numflt_t a, numflt_t b); static inline void numflt_abs(numflt_t a, numflt_t b); static inline void numflt_add(numflt_t a, numflt_t b, numflt_t c); static inline void numflt_add_uint(numflt_t a, numflt_t b, unsigned long int c); static inline void numflt_sub(numflt_t a, numflt_t b, numflt_t c); static inline void numflt_sub_uint(numflt_t a, numflt_t b, unsigned long int c); static inline void numflt_mul(numflt_t a, numflt_t b, numflt_t c); static inline void numflt_mul_2(numflt_t a, numflt_t b); static inline void numflt_div(numflt_t a, numflt_t b, numflt_t c); static inline void numflt_div_2(numflt_t a, numflt_t b); static inline void numflt_min(numflt_t a, numflt_t b, numflt_t c); static inline void numflt_max(numflt_t a, numflt_t b, numflt_t c); static inline void numflt_floor(numflt_t a, numflt_t b); static inline void numflt_ceil(numflt_t a, numflt_t b); static inline void numflt_trunc(numflt_t a, numflt_t b); static inline void numflt_sqrt(numflt_t up, numflt_t down, numflt_t b); static inline void numflt_mul_2exp(numflt_t a, numflt_t b, int c); /* ====================================================================== */ /* Arithmetic Tests */ /* ====================================================================== */ static inline int numflt_sgn(numflt_t a); static inline int numflt_cmp(numflt_t a, numflt_t b); static inline int numflt_cmp_int(numflt_t a, long int b); static inline bool numflt_equal(numflt_t a, numflt_t b); static inline bool numflt_integer(numflt_t a); /* ====================================================================== */ /* Printing */ /* ====================================================================== */ static inline void numflt_print(numflt_t a); static inline void numflt_fprint(FILE* stream, numflt_t a); static inline int numflt_snprint(char* s, size_t size, numflt_t a); /* ====================================================================== */ /* Conversions */ /* ====================================================================== */ static inline bool numflt_set_int2(numflt_t a, long int i, long int j); /* int2 -> numflt */ static inline bool numflt_set_mpz(numflt_t a, mpz_t b); /* mpz -> numflt */ static inline bool numflt_set_mpq(numflt_t a, mpq_t b); /* mpq -> numflt */ static inline bool numflt_set_double(numflt_t a, double b); /* double -> numflt */ static inline bool numflt_set_mpfr(numflt_t a, mpfr_t b); /* mpfr -> numflt */ static inline bool numflt_set_ap_scalar(numflt_t a, ap_scalar_t* b); /* (finite) ap_scalar -> numflt */ static inline bool int_set_numflt(long int* a, numflt_t b); /* numflt -> int */ static inline bool mpz_set_numflt(mpz_t a, numflt_t b); /* numflt -> mpz */ static inline bool mpq_set_numflt(mpq_t a, numflt_t b); /* numflt -> mpq */ static inline bool double_set_numflt(double* a, numflt_t b); /* numflt -> double */ static inline bool mpfr_set_numflt(mpfr_t a, numflt_t b); /* numflt -> mpfr */ static inline bool ap_scalar_set_numflt(ap_scalar_t* a, numflt_t b); /* numflt -> ap_scalar */ static inline bool mpz_fits_numflt(mpz_t a); static inline bool mpq_fits_numflt(mpq_t a); static inline bool double_fits_numflt(double a); static inline bool mpfr_fits_numflt(mpfr_t a); static inline bool numflt_fits_int(numflt_t a); static inline bool numflt_fits_float(numflt_t a); static inline bool numflt_fits_double(numflt_t a); static inline bool numflt_fits_mpfr(numflt_t a); /* Optimized versions */ /* mpfr should have exactly the precision NUMFLT_MANT_DIG */ static inline bool numflt_set_mpz_tmp(numflt_t a, mpz_t b, mpfr_t mpfr); static inline bool numflt_set_mpq_tmp(numflt_t a, mpq_t b, mpfr_t mpfr); /* ====================================================================== */ /* Only for floating point */ /* ====================================================================== */ static inline bool numflt_infty(numflt_t a); static inline void numflt_set_infty(numflt_t a, int sgn); /* ====================================================================== */ /* Serialization */ /* ====================================================================== */ static inline unsigned char numflt_serialize_id(void) { return 0x20 + sizeof(numflt_t)/4; } static inline size_t numflt_serialize(void* dst, numflt_t src); static inline size_t numflt_deserialize(numflt_t dst, const void* src); static inline size_t numflt_serialized_size(numflt_t a); /* */ static inline bool numflt_set_ap_scalar(numflt_t a, ap_scalar_t* b) { assert (ap_scalar_infty(b)==0); switch (b->discr){ case AP_SCALAR_MPQ: return numflt_set_mpq(a,b->val.mpq); case AP_SCALAR_DOUBLE: return numflt_set_double(a,b->val.dbl); case AP_SCALAR_MPFR: return numflt_set_mpfr(a,b->val.mpfr); default: abort(); } } static inline bool ap_scalar_set_numflt(ap_scalar_t* a, numflt_t b); #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/num/num_numint.h0000640014525101416610000002053211005654323020026 0ustar bjeannetpopart/* ********************************************************************** */ /* num_numint.h */ /* ********************************************************************** */ #ifndef _NUM_NUMINT_H_ #define _NUM_NUMINT_H_ #ifndef _NUM_H_ #error "File num_numint.h should not be included directly, only via num.h" #endif #if defined(NUM_LONGINT) #define NUMINT_LONGINT #elif defined(NUM_LONGLONGINT) #define NUMINT_LONGLONGINT #elif defined(NUM_MPZ) #define NUMINT_MPZ #else #error "HERE" #endif #define NUM_AP_SCALAR AP_SCALAR_MPQ #include "numint.h" #ifdef __cplusplus extern "C" { #endif typedef numint_t num_t; #define NUM_NUMINT #ifdef NUMINT_MAX #define NUM_MAX NUMINT_MAX #endif #ifdef NUMINT_NATIVE #define NUM_NATIVE #endif /* ====================================================================== */ /* Assignement */ /* ====================================================================== */ static inline void num_set(num_t a, num_t b) { numint_set(a,b); } static inline void num_set_array(num_t* a, num_t* b, size_t size) { numint_set_array(a,b,size); } static inline void num_set_int(num_t a, long int i) { numint_set_int(a,i); } /* ====================================================================== */ /* Constructors and Destructors */ /* ====================================================================== */ static inline void num_init(num_t a) { numint_init(a); } static inline void num_init_array(num_t* a, size_t size) { numint_init_array(a,size); } static inline void num_init_set(num_t a, num_t b) { numint_init_set(a,b); } static inline void num_init_set_int(num_t a, long int i) { numint_init_set_int(a,i); } static inline void num_clear(num_t a) { numint_clear(a); } static inline void num_clear_array(num_t* a, size_t size) { numint_clear_array(a,size); } static inline void num_swap(num_t a, num_t b) { numint_swap(a,b); } /* ====================================================================== */ /* Arithmetic Operations */ /* ====================================================================== */ static inline void num_neg(num_t a, num_t b) { numint_neg(a,b); } static inline void num_abs(num_t a, num_t b) { numint_abs(a,b); } static inline void num_add(num_t a, num_t b, num_t c) { numint_add(a,b,c); } static inline void num_add_uint(num_t a, num_t b, unsigned long int c) { numint_add_uint(a,b,c); } static inline void num_sub(num_t a, num_t b, num_t c) { numint_sub(a,b,c); } static inline void num_sub_uint(num_t a, num_t b, unsigned long int c) { numint_sub_uint(a,b,c); } static inline void num_mul(num_t a, num_t b, num_t c) { numint_mul(a,b,c); } static inline void num_mul_2(num_t a, num_t b) { numint_mul_2(a,b); } static inline void num_div(num_t a, num_t b, num_t c) { numint_cdiv_q(a,b,c); } static inline void num_div_2(num_t a, num_t b) { numint_cdiv_2(a,b); } static inline void num_min(num_t a, num_t b, num_t c) { numint_min(a,b,c); } static inline void num_max(num_t a, num_t b, num_t c) { numint_max(a,b,c); } static inline void num_floor(num_t a, num_t b) { numint_set(a,b); } static inline void num_ceil(num_t a, num_t b) { numint_set(a,b); } static inline void num_trunc(num_t a, num_t b) { numint_set(a,b); } static inline void num_sqrt(num_t up, num_t down, num_t b) { numint_sqrt(up,down,b); } static inline void num_mul_2exp(num_t a, num_t b, int c) { numint_mul_2exp(a,b,c); } /* ====================================================================== */ /* Arithmetic Tests */ /* ====================================================================== */ static inline int num_sgn(num_t a) { return numint_sgn(a); } static inline int num_cmp(num_t a, num_t b) { return numint_cmp(a,b); } static inline int num_cmp_int(num_t a, long int b) { return numint_cmp_int(a,b); } static inline bool num_equal(num_t a, num_t b) { return numint_equal(a,b); } static inline bool num_integer(num_t a) { return true; } /* ====================================================================== */ /* Printing */ /* ====================================================================== */ static inline void num_print(num_t a) { numint_print(a); } static inline void num_fprint(FILE* stream, num_t a) { numint_fprint(stream, a); } static inline int num_snprint(char* s, size_t size, num_t a) { return numint_snprint(s,size,a); } /* ====================================================================== */ /* Conversions */ /* ====================================================================== */ static inline bool num_set_int2(num_t a, long int i, long int j) { return numint_set_int2(a,i,j); } /* int2 -> num */ static inline bool num_set_mpz(num_t a, mpz_t b) { return numint_set_mpz(a,b); } /* mpz -> num */ static inline bool num_set_mpq(num_t a, mpq_t b) { return numint_set_mpq(a,b); } /* mpq -> num */ static inline bool num_set_double(num_t a, double k) { return numint_set_double(a,k); } /* double -> num */ static inline bool num_set_mpfr(num_t a, mpfr_t k) { return numint_set_mpfr(a,k); } /* mpfr -> num */ static inline bool num_set_ap_scalar(num_t a, ap_scalar_t* b) { return numint_set_ap_scalar(a,b); } /* ap_scalar -> num */ static inline bool int_set_num(long int*a, num_t b) { return int_set_numint(a,b); } /* num -> int */ static inline bool mpz_set_num(mpz_t a, num_t b) { return mpz_set_numint(a,b); } /* num -> mpz */ static inline bool mpq_set_num(mpq_t a, num_t b) { return mpq_set_numint(a,b); } /* num -> mpq */ static inline bool double_set_num(double* a, num_t b) { return double_set_numint(a,b); } /* num -> double */ static inline bool mpfr_set_num(mpfr_t a, num_t b) { return mpfr_set_numint(a,b); } /* num -> mpfr */ static inline bool ap_scalar_set_num(ap_scalar_t* a, num_t b) { return ap_scalar_set_numint(a,b); } /* num -> ap_scalar */ static inline bool mpz_fits_num(mpz_t a) { return mpz_fits_numint(a); } static inline bool mpq_fits_num(mpq_t a) { return mpq_fits_numint(a); } static inline bool double_fits_num(double a) { return double_fits_numint(a); } static inline bool mpfr_fits_num(mpfr_t a) { return mpfr_fits_numint(a); } static inline bool num_fits_int(num_t a) { return numint_fits_int(a); } static inline bool num_fits_float(num_t a) { return numint_fits_float(a); } static inline bool num_fits_double(num_t a) { return numint_fits_double(a); } static inline bool num_fits_mpfr(num_t a) { return numint_fits_mpfr(a); } /* Optimized versions */ static inline bool num_set_mpq_tmp(numint_t a, mpq_t b, mpz_t q, mpz_t r, mpfr_t mpfr) { return numint_set_mpq_tmp(a,b,q,r); } static inline bool mpq_fits_num_tmp(mpq_t a, mpz_t mpz) { return mpq_fits_numint_tmp(a,mpz); } static inline bool num_set_double_tmp(num_t a, double k, mpq_t mpq) { return numint_set_double(a,k); } static inline bool num_set_mpz_tmp(num_t a, mpz_t b, mpfr_t mpfr) { return numint_set_mpz(a,b); } static inline bool int_set_num_tmp(long int* a, num_t b, mpz_t q, mpz_t r) { return int_set_numint(a,b); } static inline bool mpz_set_num_tmp(mpz_t a, num_t b, mpz_t mpz) { return mpz_set_numint(a,b); } static inline bool double_set_num_tmp(double* a, num_t b, mpq_t mpq, mpfr_t mpfr) { return double_set_numint(a,b); } static inline bool double_fits_num_tmp(double k, mpq_t mpq) { return double_fits_numint(k); } /* ====================================================================== */ /* Serialization */ /* ====================================================================== */ static inline unsigned char num_serialize_id(void) { return numint_serialize_id(); } static inline size_t num_serialize(void* dst, num_t src) { return numint_serialize(dst,src); } static inline size_t num_deserialize(num_t dst, const void* src) { return numint_deserialize(dst,src); } static inline size_t num_serialized_size(num_t a) { return numint_serialized_size(a); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/num/numrat.h0000640014525101416610000001602711006063143017142 0ustar bjeannetpopart/* ********************************************************************** */ /* numrat.h */ /* ********************************************************************** */ #ifndef _NUMRAT_H_ #define _NUMRAT_H_ #include #include "gmp.h" #include "mpfr.h" #include "ap_scalar.h" #include "num_config.h" /* We assume that the basic NUMINT on which rational is built is properly defined */ #include "numint.h" /* Two main cases: for NUMINT_MPZ, the scaling to rational is already done */ #if defined(NUMINT_MPZ) #include "numrat_mpq.h" #elif defined(NUMINT_NATIVE) #include "numrat_native.h" #else #error "HERE" #endif #ifdef __cplusplus extern "C" { #endif /* ====================================================================== */ /* Assignement */ /* ====================================================================== */ static inline void numrat_set(numrat_t a, numrat_t b); static inline void numrat_set_array(numrat_t* a, numrat_t* b, size_t size); static inline void numrat_set_int(numrat_t a, long int i); /* ====================================================================== */ /* Constructors and Destructors */ /* ====================================================================== */ static inline void numrat_init(numrat_t a); static inline void numrat_init_array(numrat_t* a, size_t size); static inline void numrat_init_set(numrat_t a, numrat_t b); static inline void numrat_init_set_int(numrat_t a, long int i); static inline void numrat_clear(numrat_t a); static inline void numrat_clear_array(numrat_t* a, size_t size); static inline void numrat_swap(numrat_t a, numrat_t b) { numrat_t t; *t=*a;*a=*b;*b=*t; } /* ====================================================================== */ /* Arithmetic Operations */ /* ====================================================================== */ static inline void numrat_neg(numrat_t a, numrat_t b); static inline void numrat_inv(numrat_t a, numrat_t b); static inline void numrat_abs(numrat_t a, numrat_t b); static inline void numrat_add(numrat_t a, numrat_t b, numrat_t c); static inline void numrat_add_uint(numrat_t a, numrat_t b, unsigned long int c); static inline void numrat_sub(numrat_t a, numrat_t b, numrat_t c); static inline void numrat_sub_uint(numrat_t a, numrat_t b, unsigned long int c); static inline void numrat_mul(numrat_t a, numrat_t b, numrat_t c); static inline void numrat_mul_2(numrat_t a, numrat_t b); static inline void numrat_div(numrat_t a, numrat_t b, numrat_t c); static inline void numrat_div_2(numrat_t a, numrat_t b); static inline void numrat_min(numrat_t a, numrat_t b, numrat_t c); static inline void numrat_max(numrat_t a, numrat_t b, numrat_t c); static inline void numrat_floor(numrat_t a, numrat_t b); static inline void numrat_ceil(numrat_t a, numrat_t b); static inline void numrat_trunc(numrat_t a, numrat_t b); static inline void numrat_sqrt(numrat_t up, numrat_t down, numrat_t b); static inline void numrat_mul_2exp(numrat_t a, numrat_t b, int c); /* ====================================================================== */ /* Arithmetic Tests */ /* ====================================================================== */ static inline int numrat_sgn(numrat_t a); static inline int numrat_cmp(numrat_t a, numrat_t b); static inline int numrat_cmp_int(numrat_t a, long int b); static inline bool numrat_equal(numrat_t a, numrat_t b); /* ====================================================================== */ /* Printing */ /* ====================================================================== */ static inline void numrat_print(numrat_t a); static inline void numrat_fprint(FILE* stream, numrat_t a); static inline int numrat_snprint(char* s, size_t size, numrat_t a); /* ====================================================================== */ /* Conversions */ /* ====================================================================== */ static inline bool numrat_set_int2(numrat_t a, long int i, long int j); /* int2 -> numrat */ static inline bool numrat_set_mpz(numrat_t a, mpz_t b); /* mpz -> numrat */ static inline bool numrat_set_mpq(numrat_t a, mpq_t b); /* mpq -> numrat */ static inline bool numrat_set_double(numrat_t a, double b); /* double -> numrat */ static inline bool numrat_set_mpfr(numrat_t a, mpfr_t b); /* mpfr -> numrat */ static inline bool numrat_set_ap_scalar(numrat_t a, ap_scalar_t* b); /* (finite) ap_scalar -> numrat */ static inline bool int_set_numrat(long int* a, numrat_t b); /* numrat -> int */ static inline bool mpz_set_numrat(mpz_t a, numrat_t b); /* numrat -> mpz */ static inline bool mpq_set_numrat(mpq_t a, numrat_t b); /* numrat -> mpq */ static inline bool double_set_numrat(double* a, numrat_t b); /* numrat -> double */ static inline bool mpfr_set_numrat(mpfr_t a, numrat_t b); /* numrat -> mpfr */ static inline bool ap_scalar_set_numrat(ap_scalar_t* a, numrat_t b); /* numrat -> ap_scalar */ static inline bool mpz_fits_numrat(mpz_t a); static inline bool mpq_fits_numrat(mpq_t a); static inline bool double_fits_numrat(double a); static inline bool mpfr_fits_numrat(mpfr_t a); static inline bool numrat_fits_int(numrat_t a); static inline bool numrat_fits_float(numrat_t a); static inline bool numrat_fits_double(numrat_t a); static inline bool numrat_fits_mpfr(numrat_t a); /* Optimized versions */ static inline bool int_set_numrat_tmp(long int* a, numrat_t b, mpz_t q, mpz_t r); static inline bool mpz_set_numrat_tmp(mpz_t a, numrat_t b, mpz_t mpz); /* mpfr should have exactly the precision 53 bits (DOUBLE_MANT_DIG) */ static inline bool double_set_numrat_tmp(double* a, numrat_t b, mpq_t mpq, mpfr_t mpfr); static inline bool numrat_set_double_tmp(numrat_t a, double k, mpq_t mpq); static inline bool double_fits_numrat_tmp(double k, mpq_t mpq); /* ====================================================================== */ /* Rational operations */ /* ====================================================================== */ static inline void numrat_canonicalize(numrat_t a); static inline bool numrat_set_numint2(numrat_t a, numint_t b, numint_t c); /* static inline numint_t numrat_numref(numrat_t a); static inline numint_t numrat_denref(numrat_t a); */ /* ====================================================================== */ /* Serialization */ /* ====================================================================== */ static inline unsigned char numrat_serialize_id(void); static inline size_t numrat_serialize(void* dst, numrat_t src); static inline size_t numrat_deserialize(numrat_t dst, const void* src); static inline size_t numrat_serialized_size(numrat_t a); /* */ static inline bool numrat_set_ap_scalar(numrat_t a, ap_scalar_t* b) { assert (ap_scalar_infty(b)==0); switch (b->discr){ case AP_SCALAR_MPQ: return numrat_set_mpq(a,b->val.mpq); case AP_SCALAR_DOUBLE: return numrat_set_double(a,b->val.dbl); case AP_SCALAR_MPFR: return numrat_set_mpfr(a,b->val.mpfr); default: abort(); } } static inline bool ap_scalar_set_numrat(ap_scalar_t* a, numrat_t b) { ap_scalar_reinit(a,AP_SCALAR_MPQ); return mpq_set_numrat(a->val.mpq,b); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/num/README0000640014525101416610000000316511005654323016347 0ustar bjeannetpopart# $Id$ This small package, only composed of header files, is used to offer a generic interface to different numbers representation. It took its inspiration from pk_int (integers in Newpolka library from Bertrand Jeannet) and oct_num (integers in Octagon Abstract Domain library from Antoine Miné). It requires the GMP and MPFR libraries. If bounds are used, it also requires the APRON library. It may be freely distributed and/or modified under the conditions of the LGPL license. Numbers ======= The main file is num.h. Its inclusion should be done after one of the following macros has been defined: - NUM_LONGINT long int - NUM_LONGLONGINT long long int - NUM_MPZ mpz_t (GMP library) Defines num_t, numint_t. Possible operations are num_XXX and numint_XXX (signatures in num.h and numint.h) - NUM_LONGRAT rationals using long int - NUM_LONGLONGRAT rationals using long long int - NUM_MPQ rationals using mpq_t (GMP library) Defines num_t, numrat_t Possibles operations are num_XXX and numrat_XXX (signatures in num.h and numrat.h) Also defines numint_t (the underlying integer types). - NUM_DOUBLE double - NUM_LONGDOUBLE long double - NUM_MPFR floating-point of arbitrary precision (MPFR library) Defines num num_t, numflt_t Possibles operations are num_XXX and numflt_XXX (signatures in num.h and numflt.h) Bounds ====== Bounds are *superior* bounds defined on top of num_t. They add +oo to num_t. First include properly num.h with the right macro, and then include bound.h. Signatures of operations in bound.h It requires the APRON library (more precisely, the module ap_scalar, for conversion functions). apron-dist-0.9.10/apron/num/numrat_native.h0000640014525101416610000003160411251675475020531 0ustar bjeannetpopart/* ********************************************************************** */ /* rational_native.h */ /* ********************************************************************** */ #ifndef _NUMRAT_NATIVE_H_ #define _NUMRAT_NATIVE_H_ #include #include #include #include #include #include #include #include "gmp.h" #include "mpfr.h" #include "ap_scalar.h" #include "num_config.h" /* We assume that the basic NUMINT on which rational is built is properly defined */ #include "numint.h" #ifndef NUMINT_NATIVE #error "HERE" #endif #ifdef __cplusplus extern "C" { #endif typedef struct _rat_t { numint_t n; /* numerator */ numint_t d; /* denominator, >=0 */ } numrat_t[1]; /* ====================================================================== */ /* Rational operations */ /* ====================================================================== */ static inline void numrat_canonicalize(numrat_t r) { if (r->d){ numint_t pgcd; numint_gcd(pgcd,r->n,r->d); if (*pgcd==0 || (*pgcd==-1 && (*r->d==NUMINT_MIN || *r->n==NUMINT_MIN))) { fprintf(stderr,"overflow in numrat_canonicalize\n"); return; } *r->n /= *pgcd; *r->d /= *pgcd; } else { numint_set_int(r->n,1); } } #define numrat_numref(a) (a)->n #define numrat_denref(a) (a)->d static inline bool numrat_set_numint2(numrat_t a, numint_t b, numint_t c) { numint_set(numrat_numref(a),b); numint_set(numrat_denref(a),c); numrat_canonicalize(a); return true; } /* ====================================================================== */ /* Assignement */ /* ====================================================================== */ static inline void numrat_set(numrat_t a, numrat_t b) { *a = *b; } static inline void numrat_set_array(numrat_t* a, numrat_t* b, size_t size) { memcpy(a,b,size*sizeof(numrat_t)); } static inline void numrat_set_int(numrat_t a, long int i) { numint_set_int(a->n,i); numint_set_int(a->d,1); } /* ====================================================================== */ /* Constructors and Destructors */ /* ====================================================================== */ static inline void numrat_init(numrat_t a) { numint_init(a->n); numint_init_set_int(a->d,1); } static inline void numrat_init_array(numrat_t* a, size_t size) { size_t i; for (i=0; in,i); numint_set_int(a->d,1); } static inline void numrat_clear(numrat_t a) {} static inline void numrat_clear_array(numrat_t* a, size_t size) {} /* ====================================================================== */ /* Arithmetic Operations */ /* ====================================================================== */ static inline void numrat_neg(numrat_t a, numrat_t b) { numint_neg(a->n,b->n); numint_set(a->d,b->d); } static inline void numrat_inv(numrat_t a, numrat_t b) { if (a!=b) *a = *b; numint_swap(a->n,a->d); if (*a->d<0){ numint_neg(a->n,a->n); numint_neg(a->d,a->d); } } static inline void numrat_abs(numrat_t a, numrat_t b) { numint_abs(a->n,b->n); numint_set(a->d,b->d); } static inline void numrat_add(numrat_t a, numrat_t b, numrat_t c) { numint_t d; #if 0 *d = *b->d * *c->d; *a->n = *b->n * *c->d + *b->d * *c->n; *a->d = *d; #else /* more cost but less overflows */ numint_lcm(d,b->d,c->d); *a->n = *b->n * (*d / *b->d) + (*d / *c->d) * *c->n; *a->d = *d; #endif numrat_canonicalize(a); } static inline void numrat_add_uint(numrat_t a, numrat_t b, unsigned long int c) { *a->n = *b->n + (numint_native)c * (*b->d); *a->d = *b->d; numrat_canonicalize(a); } static inline void numrat_sub(numrat_t a, numrat_t b, numrat_t c) { numint_t d; #if 0 *d = *b->d * *c->d; *a->n = *b->n * *c->d - *b->d * *c->n; *a->d = *d; #else /* more cost but less overflows */ numint_lcm(d,b->d,c->d); *a->n = *b->n * (*d / *b->d) - (*d / *c->d) * *c->n; *a->d = *d; #endif numrat_canonicalize(a); } static inline void numrat_sub_uint(numrat_t a, numrat_t b, unsigned long int c) { *a->n = *b->n - (numint_native)c * (*b->d); *a->d = *b->d; numrat_canonicalize(a); } static inline void numrat_mul(numrat_t a, numrat_t b, numrat_t c) { *a->n = *b->n * *c->n; *a->d = *b->d * *c->d; numrat_canonicalize(a); } static inline void numrat_mul_2(numrat_t a, numrat_t b) { if (*b->d % 2 == 0){ *a->n = *b->n; *a->d = *b->d / 2; } else { *a->n = *b->n * 2; *a->d = *b->d; } } static inline void numrat_div(numrat_t a, numrat_t b, numrat_t c) { numint_t d; *d = *b->d * *c->n; if (*d<0) { *a->n = - *b->n * *c->d; *a->d = - *d; } else { *a->n = *b->n * *c->d; *a->d = *d; } numrat_canonicalize(a); } static inline void numrat_div_2(numrat_t a, numrat_t b) { if (*b->n % 2 == 0){ *a->n = *b->n / 2; *a->d = *b->d; } else { *a->n = *b->n; *a->d = *b->d * 2; } } static inline void numrat_floor(numrat_t a, numrat_t b) { numint_fdiv_q(a->n, b->n, b->d); numint_set_int(a->d,1); } static inline void numrat_ceil(numrat_t a, numrat_t b) { numint_cdiv_q(a->n, b->n, b->d); numint_set_int(a->d,1); } static inline void numrat_trunc(numrat_t a, numrat_t b) { numint_tdiv_q(a->n, b->n, b->d); numint_set_int(a->d,1); } static inline void numrat_sqrt(numrat_t up, numrat_t down, numrat_t b) { /* compute sqrt(p/q) as sqrt(p*q)/q */ numint_t pq; assert(*b->n>=0); numint_mul(pq, numrat_numref(b), numrat_denref(b)); numint_sqrt(numrat_numref(up), numrat_numref(down), pq); numint_set(numrat_denref(up),numrat_denref(b)); numint_set(numrat_denref(down),numrat_denref(b)); numrat_canonicalize(up); numrat_canonicalize(down); } static inline void numrat_mul_2exp(numrat_t a, numrat_t b, int c) { if (c>=0) { *a->n = *b->n << c; *a->d = *b->d; } else { *a->n = *b->n; *a->d = *b->d << (-c); } numrat_canonicalize(a); } /* ====================================================================== */ /* Arithmetic Tests */ /* ====================================================================== */ static inline int numrat_sgn(numrat_t a) { return numint_sgn(a->n); } static inline int numrat_cmp(numrat_t a, numrat_t b) { numint_t aa,bb; #if 0 *aa = *a->n * *b->d; *bb = *a->d * *b->n; #else /* more cost but less overflows */ numint_t d; numint_lcm(d,a->d,b->d); *aa = *a->n * (*d / *a->d); *bb = (*d / *b->d) * *b->n; #endif return numint_cmp(aa,bb); } static inline int numrat_cmp_int(numrat_t a, long int b) { numint_t aa,bb; *aa = *a->n; *bb = *a->d * b; return numint_cmp(aa,bb); } static inline bool numrat_equal(numrat_t a, numrat_t b) { return numint_equal(a->n,b->n) && numint_equal(a->d,b->d); } static inline void numrat_min(numrat_t a, numrat_t b, numrat_t c) { numrat_set(a, numrat_cmp(b,c)<=0 ? b : c); } static inline void numrat_max(numrat_t a, numrat_t b, numrat_t c) { numrat_set(a, numrat_cmp(b,c)>=0 ? b : c); } static inline bool numrat_integer(numrat_t a) { return (*a->d==1); } /* ====================================================================== */ /* Printing */ /* ====================================================================== */ static inline void numrat_fprint(FILE* stream, numrat_t a) { if (*a->n==0) fprintf(stream,"0"); else if (*a->d==1) numint_fprint(stream,a->n); else { numint_fprint(stream,a->n); fprintf(stream,"/"); numint_fprint(stream,a->d); } } static inline void numrat_print(numrat_t a) { numrat_fprint(stdout,a); } static inline int numrat_snprint(char* s, size_t size, numrat_t a) { int res; if (*a->n==0) res = snprintf(s,size, "0"); else if (*a->d==1) res = numint_snprint(s,size,a->n); else { res = numint_snprint(s,size,a->n); res += snprintf(s+res,size-res,"/"); res += numint_snprint(s+res,size-res,a->n); } return res; } /* ====================================================================== */ /* Conversions */ /* ====================================================================== */ /* int2 -> numrat */ static inline bool numrat_set_int2(numrat_t a, long int i, long int j) { assert(j>0); numint_set_int(a->n,i); numint_set_int(a->d,j); numrat_canonicalize(a); return true; } /* mpz -> numrat */ static inline bool numrat_set_mpz(numrat_t a, mpz_t b) { numint_set_mpz(a->n,b); numint_set_int(a->d,1); return true; } /* mpq -> numrat */ static inline bool numrat_set_mpq(numrat_t a, mpq_t b) { numint_set_mpz(a->n,mpq_numref(b)); numint_set_mpz(a->d,mpq_denref(b)); return true; } /* double -> numrat */ static inline bool numrat_set_double_tmp(numrat_t a, double k, mpq_t mpq) { if (!isfinite(k)) { DEBUG_SPECIAL; numrat_set_int(a,0); return false; } mpq_set_d(mpq,k); numrat_set_mpq(a,mpq); return true; } static inline bool numrat_set_double(numrat_t a, double k) { mpq_t mpq; mpq_init(mpq); numrat_set_double_tmp(a,k,mpq); mpq_clear(mpq); return true; } /* mpfr -> numrat */ static inline bool numrat_set_mpfr(numrat_t a, mpfr_t b) { mpq_t q; mp_exp_t e; if (!mpfr_number_p(b)) { DEBUG_SPECIAL; numrat_set_int(a,0); return false; } mpq_init(q); /* XXX might fail if scaled exponent not representable in mp_exp_t */ e = mpfr_get_z_exp(mpq_numref(q),b); mpz_set_si(mpq_denref(q),1); if (e>0) mpq_mul_2exp(q,q,e); if (e<0) mpq_div_2exp(q,q,-e); numrat_set_mpq(a,q); mpq_clear(q); return true; } /* numrat -> int */ static inline bool int_set_numrat(long int* a, numrat_t b) { numint_t q,r; numint_cdiv_qr(q,r,b->n,b->d); *a = *q; return (*r==0); } static inline bool int_set_numrat_tmp(long int* a, numrat_t b, mpz_t q, mpz_t r) { return int_set_numrat(a,b); } /* numrat -> mpz */ static inline bool mpz_set_numrat(mpz_t a, numrat_t b) { numint_t q,r; numint_cdiv_qr(q,r,numrat_numref(b),numrat_denref(b)); mpz_set_numint(a,q); return (numint_sgn(r)==0); } static inline bool mpz_set_numrat_tmp(mpz_t a, numrat_t b, mpz_t mpz) { return mpz_set_numrat(a,b); } /* numrat -> mpq */ static inline bool mpq_set_numrat(mpq_t a, numrat_t b) { mpz_set_numint(mpq_numref(a), numrat_numref(b)); mpz_set_numint(mpq_denref(a), numrat_denref(b)); return true; } /* numrat -> double */ /* mpfr should have exactly a precision of 53 bits */ static inline bool double_set_numrat_tmp(double* a, numrat_t b, mpq_t mpq, mpfr_t mpfr) { mpq_set_numrat(mpq,b); int res = mpfr_set_q(mpfr,mpq,GMP_RNDU); *a = mpfr_get_d(mpfr,GMP_RNDU); /* should be exact */ return (res==0); } static inline bool double_set_numrat(double* a, numrat_t b) { mpq_t mpq; mpfr_t mpfr; mpq_init(mpq); mpfr_init2(mpfr,53); bool res = double_set_numrat_tmp(a,b,mpq,mpfr); mpq_clear(mpq); mpfr_clear(mpfr); return res; } /* numrat -> mpfr */ static inline bool mpfr_set_numrat(mpfr_t a, numrat_t b) { int r = mpfr_set_si(a,*numrat_numref(b),GMP_RNDU); return !mpfr_div_si(a,a,*numrat_denref(b),GMP_RNDU) && !r; } static inline bool mpz_fits_numrat(mpz_t a) { return mpz_fits_numint(a); } static inline bool mpq_fits_numrat(mpq_t a) { return mpz_fits_numint(mpq_numref(a)) && mpz_fits_numint(mpq_denref(a)); } static inline bool double_fits_numrat_tmp(double k, mpq_t mpq) { if (!isfinite(k)) return false; mpq_set_d(mpq,k); bool res = mpq_fits_numrat(mpq); return res; } static inline bool double_fits_numrat(double k) { mpq_t mpq; mpq_init(mpq); bool res = double_fits_numrat_tmp(k,mpq); mpq_clear(mpq); return res; } static inline bool mpfr_fits_numrat(mpfr_t a) { mpz_t z; mp_exp_t e; if (!mpfr_number_p(a)) return false; mpz_init(z); e = mpfr_get_z_exp(z,a); if (!mpz_fits_numrat(z)) { mpz_clear(z); return false; } mpz_clear(z); return e<(mp_exp_t)sizeof(numint_t)*8-1; } static inline bool numrat_fits_int(numrat_t a) { numint_t b; numint_cdiv_q(b,a->n,a->d); return *b<=LONG_MAX && *b>=-LONG_MAX; } static inline bool numrat_fits_float(numrat_t a) { return true; } static inline bool numrat_fits_double(numrat_t a) { return true; } static inline bool numrat_fits_mpfr(numrat_t a) { return true; } /* ====================================================================== */ /* Serialization */ /* ====================================================================== */ static inline unsigned char numrat_serialize_id(void) { return 0x10 + sizeof(numint_t)/4; } static inline size_t numrat_serialize(void* dst, numrat_t src) { size_t x = numint_serialize(dst,numrat_numref(src)); return x + numint_serialize((char*)dst+x,numrat_denref(src)); } static inline size_t numrat_deserialize(numrat_t dst, const void* src) { size_t x = numint_deserialize(numrat_numref(dst),src); return x + numint_deserialize(numrat_denref(dst),(const char*)src+x); } static inline size_t numrat_serialized_size(numrat_t a) { return numint_serialized_size(numrat_numref(a)) + numint_serialized_size(numrat_denref(a)); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/num/num_numrat.h0000640014525101416610000002054111005654323020022 0ustar bjeannetpopart/* ********************************************************************** */ /* num_numrat.h */ /* ********************************************************************** */ #ifndef _NUM_NUMRAT_H_ #define _NUM_NUMRAT_H_ #ifndef _NUM_H_ #error "File num_numrat.h should not be included directly, only via num.h" #endif #if defined(NUM_LONGRAT) #define NUMINT_LONGINT #elif defined(NUM_LONGLONGRAT) #define NUMINT_LONGLONGINT #elif defined(NUM_MPQ) #define NUMINT_MPZ #else #error "HERE" #endif #define NUM_AP_SCALAR AP_SCALAR_MPQ #include "numrat.h" #ifdef __cplusplus extern "C" { #endif typedef numrat_t num_t; #define NUM_NUMRAT #ifdef NUMINT_NATIVE #define NUM_NATIVE #endif /* ====================================================================== */ /* Assignement */ /* ====================================================================== */ static inline void num_set(num_t a, num_t b) { numrat_set(a,b); } static inline void num_set_array(num_t* a, num_t* b, size_t size) { numrat_set_array(a,b,size); } static inline void num_set_int(num_t a, long int i) { numrat_set_int(a,i); } /* ====================================================================== */ /* Constructors and Destructors */ /* ====================================================================== */ static inline void num_init(num_t a) { numrat_init(a); } static inline void num_init_array(num_t* a, size_t size) { numrat_init_array(a,size); } static inline void num_init_set(num_t a, num_t b) { numrat_init_set(a,b); } static inline void num_init_set_int(num_t a, long int i) { numrat_init_set_int(a,i); } static inline void num_clear(num_t a) { numrat_clear(a); } static inline void num_clear_array(num_t* a, size_t size) { numrat_clear_array(a,size); } static inline void num_swap(num_t a, num_t b) { numrat_swap(a,b); } /* ====================================================================== */ /* Arithmetic Operations */ /* ====================================================================== */ static inline void num_neg(num_t a, num_t b) { numrat_neg(a,b); } static inline void num_abs(num_t a, num_t b) { numrat_abs(a,b); } static inline void num_add(num_t a, num_t b, num_t c) { numrat_add(a,b,c); } static inline void num_add_uint(num_t a, num_t b, unsigned long int c) { numrat_add_uint(a,b,c); } static inline void num_sub(num_t a, num_t b, num_t c) { numrat_sub(a,b,c); } static inline void num_sub_uint(num_t a, num_t b, unsigned long int c) { numrat_sub_uint(a,b,c); } static inline void num_mul(num_t a, num_t b, num_t c) { numrat_mul(a,b,c); } static inline void num_mul_2(num_t a, num_t b) { numrat_mul_2(a,b); } static inline void num_div(num_t a, num_t b, num_t c) { numrat_div(a,b,c); } static inline void num_div_2(num_t a, num_t b) { numrat_div_2(a,b); } static inline void num_min(num_t a, num_t b, num_t c) { numrat_min(a,b,c); } static inline void num_max(num_t a, num_t b, num_t c) { numrat_max(a,b,c); } static inline void num_floor(num_t a, num_t b) { numrat_floor(a,b); } static inline void num_ceil(num_t a, num_t b) { numrat_ceil(a,b); } static inline void num_trunc(num_t a, num_t b) { numrat_trunc(a,b); } static inline void num_sqrt(num_t up, num_t down, num_t b) { numrat_sqrt(up,down,b); } static inline void num_mul_2exp(num_t a, num_t b, int c) { numrat_mul_2exp(a,b,c); } /* ====================================================================== */ /* Arithmetic Tests */ /* ====================================================================== */ static inline int num_sgn(num_t a) { return numrat_sgn(a); } static inline int num_cmp(num_t a, num_t b) { return numrat_cmp(a,b); } static inline int num_cmp_int(num_t a, long int b) { return numrat_cmp_int(a,b); } static inline bool num_equal(num_t a, num_t b) { return numrat_equal(a,b); } static inline bool num_integer(num_t a) { return numrat_integer(a); } /* ====================================================================== */ /* Printing */ /* ====================================================================== */ static inline void num_print(num_t a) { numrat_print(a); } static inline void num_fprint(FILE* stream, num_t a) { numrat_fprint(stream, a); } static inline int num_snprint(char* s, size_t size, num_t a) { return numrat_snprint(s,size,a); } /* ====================================================================== */ /* Conversions */ /* ====================================================================== */ static inline bool num_set_int2(num_t a, long int i, long int j) { return numrat_set_int2(a,i,j); } /* int2 -> num */ static inline bool num_set_mpz(num_t a, mpz_t b) { return numrat_set_mpz(a,b); } /* mpz -> num */ static inline bool num_set_mpq(num_t a, mpq_t b) { return numrat_set_mpq(a,b); } /* mpq -> num */ static inline bool num_set_double(num_t a, double k) { return numrat_set_double(a,k); } /* double -> num */ static inline bool num_set_mpfr(num_t a, mpfr_t k) { return numrat_set_mpfr(a,k); } /* mpfr -> num */ static inline bool num_set_ap_scalar(num_t a, ap_scalar_t* b) { return numrat_set_ap_scalar(a,b); } /* ap_scalar -> num */ static inline bool int_set_num(long int*a, num_t b) { return int_set_numrat(a,b); } /* num -> int */ static inline bool mpz_set_num(mpz_t a, num_t b) { return mpz_set_numrat(a,b); } /* num -> mpz */ static inline bool mpq_set_num(mpq_t a, num_t b) { return mpq_set_numrat(a,b); } /* num -> mpq */ static inline bool double_set_num(double* a, num_t b) { return double_set_numrat(a,b); } /* num -> double */ static inline bool mpfr_set_num(mpfr_t a, num_t b) { return mpfr_set_numrat(a,b); } /* num -> mpfr */ static inline bool ap_scalar_set_num(ap_scalar_t* a, num_t b) { return ap_scalar_set_numrat(a,b); } /* num -> ap_scalar */ static inline bool mpz_fits_num(mpz_t a) { return mpz_fits_numrat(a); } static inline bool mpq_fits_num(mpq_t a) { return mpq_fits_numrat(a); } static inline bool double_fits_num(double a) { return double_fits_numrat(a); } static inline bool mpfr_fits_num(mpfr_t a) { return mpfr_fits_numrat(a); } static inline bool num_fits_int(num_t a) { return numrat_fits_int(a); } static inline bool num_fits_float(num_t a) { return numrat_fits_float(a); } static inline bool num_fits_double(num_t a) { return numrat_fits_double(a); } static inline bool num_fits_mpfr(num_t a) { return numrat_fits_mpfr(a); } /* Optimized versions */ static inline bool num_set_double_tmp(num_t a, double k, mpq_t mpq) { return numrat_set_double_tmp(a,k,mpq); } static inline bool int_set_num_tmp(long int* a, num_t b, mpz_t q, mpz_t r) { return int_set_numrat_tmp(a,b,q,r); } static inline bool mpz_set_num_tmp(mpz_t a, num_t b, mpz_t mpz) { return mpz_set_numrat_tmp(a,b,mpz); } static inline bool double_set_num_tmp(double* a, num_t b, mpq_t mpq, mpfr_t mpfr) { return double_set_numrat_tmp(a,b,mpq,mpfr); } static inline bool double_fits_num_tmp(double k, mpq_t mpq) { return double_fits_numrat_tmp(k,mpq); } static inline bool num_set_mpq_tmp(num_t a, mpq_t b, mpz_t q, mpz_t r, mpfr_t mpfr) { return numrat_set_mpq(a,b); } static inline bool mpq_fits_num_tmp(mpq_t a, mpz_t mpz) { return mpq_fits_numrat(a); } static inline bool num_set_mpz_tmp(num_t a, mpz_t b, mpfr_t mpfr) { return numrat_set_mpz(a,b); } /* ====================================================================== */ /* Serialization */ /* ====================================================================== */ static inline unsigned char num_serialize_id(void) { return numrat_serialize_id(); } static inline size_t num_serialize(void* dst, num_t src) { return numrat_serialize(dst,src); } static inline size_t num_deserialize(num_t dst, const void* src) { return numrat_deserialize(dst,src); } static inline size_t num_serialized_size(num_t a) { return numrat_serialized_size(a); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/num/numflt_native.h0000640014525101416610000002743511006063143020514 0ustar bjeannetpopart/* ********************************************************************** */ /* numflt_native.h */ /* ********************************************************************** */ #ifndef _NUMFLT_NATIVE_H_ #define _NUMFLT_NATIVE_H_ #include #include #include #include #include #include #include #include #include "gmp.h" #include "mpfr.h" #include "ap_scalar.h" #include "num_config.h" #ifdef __cplusplus extern "C" { #endif #if defined(NUMFLT_DOUBLE) typedef double numflt_native; #define NUMFLT_ZERO 0.0 #define NUMFLT_ONE 1.0 #define NUMFLT_MANT_DIG DBL_MANT_DIG #elif defined(NUMFLT_LONGDOUBLE) typedef long double numflt_native; #define NUMFLT_ZERO 0.0L #define NUMFLT_ONE 1.0L #define NUMFLT_MANT_DIG LDBL_MANT_DIG #else #error "HERE" #endif typedef numflt_native numflt_t[1]; #define NUMFLT_MAX NUMFLT_ONE/NUMFLT_ZERO #define NUMFLT_NATIVE /* ====================================================================== */ /* Assignement */ /* ====================================================================== */ static inline void numflt_set(numflt_t a, numflt_t b) { *a = *b; } static inline void numflt_set_array(numflt_t* a, numflt_t* b, size_t size) { memcpy(a,b,size*sizeof(numflt_t)); } static inline void numflt_set_int(numflt_t a, long int i) { *a = (numflt_native)i; } /* ====================================================================== */ /* Constructors and Destructors */ /* ====================================================================== */ static inline void numflt_init(numflt_t a) { *a = NUMFLT_ZERO; } static inline void numflt_init_array(numflt_t* a, size_t size) { size_t i; for (i=0; i=0); *x = sqrt(*b); assert(*x**x>=*b); /* assumes round towards +oo! */ if (*x**x==*b) *down = *x; else *down = nextafter(*x,0); *up = *x; } static inline void numflt_mul_2exp(numflt_t a, numflt_t b, int c) { *a = ldexp(*b,c); } #else static inline void numflt_abs(numflt_t a, numflt_t b) { *a = fabsl(*b); } static inline void numflt_mul_2(numflt_t a, numflt_t b) { *a = ldexpl(*b,1); } static inline void numflt_div_2(numflt_t a, numflt_t b) { *a = ldexpl(*b,-1); } static inline void numflt_min(numflt_t a, numflt_t b, numflt_t c) { *a = fminl(*b,*c); } static inline void numflt_max(numflt_t a, numflt_t b, numflt_t c) { *a = fmaxl(*b,*c); } static inline void numflt_floor(numflt_t a, numflt_t b) { *a = floorl(*b); } static inline void numflt_ceil(numflt_t a, numflt_t b) { *a = ceill(*b); } static inline void numflt_trunc(numflt_t a, numflt_t b) { *a = truncl(*b); } static inline void numflt_sqrt(numflt_t up, numflt_t down, numflt_t b) { assert(*b>=0); *up = sqrtl(*b); assert(*up**up>=*b); /* assumes round towards +oo! */ if (*up**up==*b) *down = *up; else *down = nextafterl(*up,0); } static inline void numflt_mul_2exp(numflt_t a, numflt_t b, int c) { *a = ldexpl(*b,c); } #endif /* ====================================================================== */ /* Arithmetic Tests */ /* ====================================================================== */ static inline int numflt_sgn(numflt_t a) { return (*a==NUMFLT_ZERO ? 0 : (*a>NUMFLT_ZERO ? 1 : -1)); } static inline int numflt_cmp(numflt_t a, numflt_t b) { return (*a==*b ? 0 : (*a>*b ? 1 : -1)); } static inline int numflt_cmp_int(numflt_t a, long int b) { numflt_native bb = (numflt_native)b; return (*a==bb ? 0 : (*a>bb ? 1 : -1)); } static inline bool numflt_equal(numflt_t a, numflt_t b) { return *a==*b; } static inline bool numflt_integer(numflt_t a) #if defined(NUMFLT_DOUBLE) { return ceil(*a) == *a; } #else { return ceill(*a) == *a; } #endif /* ====================================================================== */ /* Printing */ /* ====================================================================== */ #if defined(NUMFLT_DOUBLE) static inline void numflt_print(numflt_t a) { printf("%.*g",NUMFLT_PRINT_PREC,*a+NUMFLT_ZERO); } static inline void numflt_fprint(FILE* stream, numflt_t a) { fprintf(stream,"%.*g",NUMFLT_PRINT_PREC,*a+NUMFLT_ZERO); } static inline int numflt_snprint(char* s, size_t size, numflt_t a) { return snprintf(s,size,"%.*g",NUMFLT_PRINT_PREC,*a+NUMFLT_ZERO); } #else static inline void numflt_print(numflt_t a) { printf("%.*Lg",NUMFLT_PRINT_PREC,*a+NUMFLT_ZERO); } static inline void numflt_fprint(FILE* stream, numflt_t a) { fprintf(stream,"%.*Lg",NUMFLT_PRINT_PREC,*a+NUMFLT_ZERO); } static inline int numflt_snprint(char* s, size_t size, numflt_t a) { return snprintf(s,size,"%.*Lg",NUMFLT_PRINT_PREC,*a+NUMFLT_ZERO); } #endif /* ====================================================================== */ /* Conversions */ /* ====================================================================== */ /* int2 -> numflt */ static inline bool numflt_set_int2(numflt_t a, long int i, long int j) { assert(j>0); *a = (numflt_native)i/(numflt_native)j; return (-*a==(numflt_native)(-i)/(numflt_native)j); } /* mpz -> numflt */ /* mpfr is supposed to have exactly the IEEE754 double precision of NUMFLT_MANT_DIG bits */ static inline bool numflt_set_mpz_tmp(numflt_t a, mpz_t b, mpfr_t mpfr) { int res = mpfr_set_z(mpfr,b,GMP_RNDU); #if defined(NUMFLT_DOUBLE) *a = mpfr_get_d(mpfr,GMP_RNDU);/* Normally, exact conversion here (unless overfloww) */ #else *a = mpfr_get_ld(mpfr,GMP_RNDU);/* Normally, exact conversion here (unless overfloww) */ #endif return (res==0); } static inline bool numflt_set_mpz(numflt_t a, mpz_t b) { mpfr_t mpfr; mpfr_init2(mpfr,NUMFLT_MANT_DIG); bool res = numflt_set_mpz_tmp(a,b,mpfr); mpfr_clear(mpfr); return res; } /* mpq -> numflt */ /* mpfr is supposed to have exactly the IEEE754 double precision of NUMFLT_MANT_DIG bits */ static inline bool numflt_set_mpq_tmp(numflt_t a, mpq_t b, mpfr_t mpfr) { int res = mpfr_set_q(mpfr,b,GMP_RNDU); #if defined(NUMFLT_DOUBLE) *a = mpfr_get_d(mpfr,GMP_RNDU);/* Normally, exact conversion here (unless overfloww) */ #else *a = mpfr_get_ld(mpfr,GMP_RNDU);/* Normally, exact conversion here (unless overfloww) */ #endif return (res==0); } static inline bool numflt_set_mpq(numflt_t a, mpq_t b) { mpfr_t mpfr; mpfr_init2(mpfr,NUMFLT_MANT_DIG); bool res = numflt_set_mpq_tmp(a,b,mpfr); mpfr_clear(mpfr); return res; } /* double -> numflt */ static inline bool numflt_set_double(numflt_t a, double k) { *a = (numflt_native)k; return true; } /* mpfr -> numflt */ static inline bool numflt_set_mpfr(numflt_t a, mpfr_t b) { #if defined(NUMFLT_DOUBLE) *a = mpfr_get_d(b,GMP_RNDU); return !mpfr_cmp_d(b,*a); #else *a = mpfr_get_ld(b,GMP_RNDU); return !mpfr_cmp_ld(b,*a); #endif } /* numflt -> int */ static inline bool int_set_numflt(long int* a, numflt_t b) { numflt_native c; numflt_ceil(&c,b); if (!isfinite(c)) { DEBUG_SPECIAL; *a = 0; return false; } *a = (long int)c; return (*b==c); } /* numflt -> mpz */ static inline bool mpz_set_numflt(mpz_t a, numflt_t b) { double c = ceil(*b); if (!isfinite(c)) { DEBUG_SPECIAL; mpz_set_ui(a,0); return false; } mpz_set_d(a,c); return (*b==(numflt_native)c); } /* numflt -> mpq */ static inline bool mpq_set_numflt(mpq_t a, numflt_t b) #if defined(NUMFLT_DOUBLE) { if (!isfinite(*b)) { DEBUG_SPECIAL; mpq_set_ui(a,0,1); return false; } mpq_set_d(a,*b); return true; } #else { double c = (double)(*b); if (!isfinite(c)) { DEBUG_SPECIAL; mpq_set_ui(a,0,1); return false; } mpq_set_d(a,c); return (*b==(numflt_native)c); } #endif /* numflt -> double */ static inline bool double_set_numflt(double* a, numflt_t b) #if defined(NUMFLT_DOUBLE) { *a = *b; return true; } #else { *a = *b; return ((numflt_native)(*a)==*b); } #endif /* numflt -> mpfr */ static inline bool mpfr_set_numflt(mpfr_t a, numflt_t b) #if defined(NUMFLT_DOUBLE) { return !mpfr_set_d(a,*b,GMP_RNDU); } #else { return !mpfr_set_ld(a,*b,GMP_RNDU); } #endif static inline bool mpz_fits_numflt(mpz_t a) { double k = mpz_get_d(a); return (fabs(k)+1.0) != (double)1.0/(double)0.0; } static inline bool mpq_fits_numflt(mpq_t a) { double k = mpq_get_d(a); return (fabs(k)+1.0) != (double)1.0/(double)0.0; } static inline bool double_fits_numflt(double a) { return true; } static inline bool mpfr_fits_numflt(mpfr_t a) { return mpfr_get_exp(a)<1022; /* XXX >1022 for long double */ } static inline bool numflt_fits_int(numflt_t a) { numflt_native d; numflt_ceil(&d,a); return isfinite(d) && d >= (numflt_native)(-LONG_MAX) && d<= (numflt_native)LONG_MAX; } static inline bool numflt_fits_float(numflt_t a) { int e; #if defined(NUMFLT_DOUBLE) frexp(*a,&e); #else frexpl(*a,&e); #endif return (e<127); } static inline bool numflt_fits_double(numflt_t a) { #if defined(NUMFLT_DOUBLE) return true; #else int e; frexpl(*a,&e); return (e<1023); #endif } static inline bool numflt_fits_mpfr(numflt_t a) { int e; #if defined(NUMFLT_DOUBLE) frexp(*a,&e); #else frexpl(*a,&e); #endif return (e0 ? NUMFLT_MAX : -NUMFLT_MAX; } /* ====================================================================== */ /* Serialization */ /* ====================================================================== */ static inline size_t numflt_serialize(void* dst, numflt_t src) { num_store_words8(dst,src,sizeof(numflt_t)); return sizeof(numflt_t); } static inline size_t numflt_deserialize(numflt_t dst, const void* src) { num_store_words8(dst,src,sizeof(numflt_t)); return sizeof(numflt_t); } static inline size_t numflt_serialized_size(numflt_t a) { return sizeof(numflt_t); } /* */ static inline bool ap_scalar_set_numflt(ap_scalar_t* a, numflt_t b) { ap_scalar_reinit(a,AP_SCALAR_DOUBLE); return double_set_numflt(&a->val.dbl,b); } #ifdef __cplusplus } #endif #endif apron-dist-0.9.10/apron/README0000640014525101416610000000617111251737120015550 0ustar bjeannetpopart# This file is part of the APRON Library, released under LGPL license, except # files requiring the PPL library (in ppl and products subdirectories) # Please read the COPYING file packaged in the distribution NOTE: If you do not already have MLGMPIDL, you can use the apron-dist directory in SVN repository. The developpers are using INTEL/linux machines. Look at README.windows and README.mac for additional specific informations. PREREQUISITES ------------- - C API (required) * GCC * GMP 4.2 and MPFR 2.2 or up * Optionally, * PPL library (PARMA Polyhedra library, http://www.cs.unipr.it/ppl/) - patch to apply before compiling it (see ./ppl/README) - GMPXX (GMP compiled with configuration option --enable-cxx) - OCaml API (optional) * MLGMPIDL (http://www.inrialpes.fr/pop-art/people/bjeannet/mlxxxidl-forge/mlgmpidl, SVN: svn://scm.gforge.inria.fr/svn/mlxxxidl/mlgmpidl/) * OCaml 3.09 or up (http://www.caml.org) * CamlIDL 1.05 (http://caml.inria.fr/camlidl) * GNU sed 4.1 or up, GNU m4 (not necessary if you download an archive, but strongly recommended) - C++ API (optional) * GCC 4.1.2 or up - Documentation (optional) * latex, dvipdf, makeinfo, texi2html, texi2dvi CONFIGURATION and COMPILATION ----------------------------- 1. Copy Makefile.config.model into Makefile.config and edit the _PREFIX paths to suit your installation (you might want to set APRON_PREFIX, MLGMPIDL_PREFIX, CAMLIDL_PREFIX and CAML_PREFIX to some of your directory instead of the default /tmp). 2. If you download via subversion repository, and you want the OCaml API: 'make rebuild' 3. 'make' 'make install' 4. Other targets: make c (C and possibly C++ version) make ml (OCaml stuff) make doc (not useful for a normal user) make clean (clean things, with the exception of generated files) make mostlyclean (clean all it can clean, implies clean) make rebuild (rebuild generated files, mainly for OCaml interface) make distclean (clean the distribution directories) make install (installs in directories specified in Makefile.config) ORGANISATION IN DIRECTORIES --------------------------- The main directory contain the following subpackages of the APRON project: apron: apron interface, C version apronxx: apron interface, C++ version (compiled if HAS_CPP defined) mlapronidl: apron interface, OCaml version (compiled if HAS_OCAML defined) box: interval library octagons: octagon library newpolka: convex polyhedra and linear equalities library ppl: wrapper to call the Parma Polyhedra Library from APRON under GPL (instead of LGPL) license. (compiled if HAS_PPL defined) products: - reduced product of NewPolka convex polyhedra and PPL linear congruences (compiled if HAS_PPL defined) examples: some examples (C and OCaml) tests: some (manual) tests mlgmpidl: OCaml interface for the GMP and MPFR libraries, used by mlapronidl. (compiled if HAS_OCAML defined) num: manipulating "generic" numbers (used by intervals, newpolka, octagons, linearisation, etc...). itv: built on top of num: intervals, interval linear expressions and constraints, linearisation apron-dist-0.9.10/README0000640014525101416610000000371411251734233014433 0ustar bjeannetpopart# This file is part of the APRON Library, released under LGPL license, except # files requiring the PPL library (in ppl and products subdirectories) # Please read the COPYING file packaged in the distribution The developpers are using INTEL/linux machines. Look at README.windows and README.mac for additional specific informations. PREREQUISITES ------------- - C API (required) * GCC * GMP 4.2 and MPFR 2.2 or up * Optionally, * PPL library (PARMA Polyhedra library, http://www.cs.unipr.it/ppl/) - patch to apply before compiling it (see ./ppl/README) - GMPXX (GMP compiled with configuration option --enable-cxx) - OCaml API (optional) * OCaml 3.09 or up (http://www.caml.org) * CamlIDL 1.05 (http://caml.inria.fr/camlidl) * GNU sed 4.1 or up, GNU m4 (not necessary if you download an archive, but strongly recommended) - C++ API (optional) * GCC 4.1.2 or up - Documentation (optional) * latex, dvipdf, makeinfo, texi2html, texi2dvi CONFIGURATION and COMPILATION ----------------------------- 1. Copy Makefile.config.model into Makefile.config and edit the _PREFIX paths to suit your installation (you might want to set APRON_PREFIX, CAMLIDL_PREFIX and CAML_PREFIX to /usr/local instead of the default /usr). 2. If you download via subversion repository, and you want the OCaml API: 'make rebuild' 3. 'make' 'make install' 4. Other targets: make doc (not useful for a normal user) make clean (clean things, with the exception of generated files) make mostlyclean (clean all it can clean, implies clean) make rebuild (rebuild generated files, mainly for OCaml interface) make distclean (clean the distribution directories) make install (installs in directories specified in Makefile.config) ORGANISATION IN DIRECTORIES --------------------------- This directory is a distribution directory, with external references (in the sense of subversion) to: - mlgmpidl - apron Enter these subdirectories for details.