Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not assert in user code #34

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/assertBounds.ml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,16 @@ module Make(Core : CoreSig.S) : S with module Core = Core = struct
let poly env p ?min ?max slk =
debug "[entry of assert_poly]" env (Result.get None);
check_invariants env (Result.get None);
assert (P.is_polynomial p);
(* Note: we should not convert the call to [poly] into a call to [var]
here because we introduce the equality [poly = slk] and then we set
the bounds for [slk] to [min] and [max].

If there is a single variable (i.e. [poly = k * x] for some
coefficient [k] and variable [x]), we do not want to add the useless
slack variable [slk = k * x]. *)
if not (P.is_polynomial p) then
invalid_arg
"poly: must have two variables or more, use var instead";
let mini = update_min_bound env min in
let maxi = update_max_bound env max in
let env, is_fresh = register_slake slk p env in
Expand Down
16 changes: 12 additions & 4 deletions src/assertBounds.mli
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ module type S = sig
Core.Var.t ->
Core.t * bool

(* The returned bool is [true] if the asserted bounds are not trivial
(i.e. not implied by known bounds) *)
(** [poly env poly min max x] returns a new environment obtained by changing
the bounds of [poly] in [env] to [min] and [max].
The polynomial is represented by the slack variable [x].
If the bounds were implied by other known bounds (in other words, if the
environment did not change) the associated boolean will be [false].

[poly] must be a polynomial (as tested by [Core.P.is_polynomial]), that
is, it must contain at least two distinct variables. Use [var] instead
for constraints that apply to a single variable.

The returned bool is [true] if the asserted bounds are not trivial (i.e.
not implied by known bounds). If the bounds were implied by other known
bounds (in other words, if the environment did not change) the associated
boolean will be [false].

@raise Invalid_argument if [poly] contains zero or one variables (use [var]
to add constraints to a single variable).
*)
val poly :
Core.t ->
Expand Down
Loading