Skip to content

Commit 3aab708

Browse files
authored
Merge pull request #34 from bclement-ocp/poly-error
Do not assert in user code
2 parents d0c0a04 + 0a57fee commit 3aab708

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/assertBounds.ml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,16 @@ module Make(Core : CoreSig.S) : S with module Core = Core = struct
219219
let poly env p ?min ?max slk =
220220
debug "[entry of assert_poly]" env (Result.get None);
221221
check_invariants env (Result.get None);
222-
assert (P.is_polynomial p);
222+
(* Note: we should not convert the call to [poly] into a call to [var]
223+
here because we introduce the equality [poly = slk] and then we set
224+
the bounds for [slk] to [min] and [max].
225+
226+
If there is a single variable (i.e. [poly = k * x] for some
227+
coefficient [k] and variable [x]), we do not want to add the useless
228+
slack variable [slk = k * x]. *)
229+
if not (P.is_polynomial p) then
230+
invalid_arg
231+
"poly: must have two variables or more, use var instead";
223232
let mini = update_min_bound env min in
224233
let maxi = update_max_bound env max in
225234
let env, is_fresh = register_slake slk p env in

src/assertBounds.mli

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,21 @@ module type S = sig
2222
Core.Var.t ->
2323
Core.t * bool
2424

25-
(* The returned bool is [true] if the asserted bounds are not trivial
26-
(i.e. not implied by known bounds) *)
2725
(** [poly env poly min max x] returns a new environment obtained by changing
2826
the bounds of [poly] in [env] to [min] and [max].
2927
The polynomial is represented by the slack variable [x].
30-
If the bounds were implied by other known bounds (in other words, if the
31-
environment did not change) the associated boolean will be [false].
28+
29+
[poly] must be a polynomial (as tested by [Core.P.is_polynomial]), that
30+
is, it must contain at least two distinct variables. Use [var] instead
31+
for constraints that apply to a single variable.
32+
33+
The returned bool is [true] if the asserted bounds are not trivial (i.e.
34+
not implied by known bounds). If the bounds were implied by other known
35+
bounds (in other words, if the environment did not change) the associated
36+
boolean will be [false].
37+
38+
@raise Invalid_argument if [poly] contains zero or one variables (use [var]
39+
to add constraints to a single variable).
3240
*)
3341
val poly :
3442
Core.t ->

0 commit comments

Comments
 (0)