Commit b821e8b4 authored by Mathieu Hemery's avatar Mathieu Hemery

Improve determine_sign/2, avoiding choice points

parent a359673a
......@@ -674,9 +674,11 @@ arithmetic_operation(_ ^ _).
% or if it is impossible to decide
always_negative(Expr) :-
determine_sign(Expr, zero);
determine_sign(Expr, neg).
always_positive(Expr) :-
determine_sign(Expr, zero);
determine_sign(Expr, pos).
......@@ -741,6 +743,7 @@ determine_sign(A - B, Sign) :-
determine_sign(A + (- B), Sign).
determine_sign(A * B, Sign) :-
!,
determine_sign(A, SignA),
determine_sign(B, SignB),
(
......@@ -760,6 +763,14 @@ determine_sign(A * B, Sign) :-
).
determine_sign(A / B, Sign) :-
!,
(
is_null(B)
->
throw(error(division_by_zero, arithmetic_rules_determine_sign))
;
true
),
determine_sign(A * B, Sign).
determine_sign(A, pos) :- % concentrations and parameters are assumed positive
......
......@@ -13,6 +13,7 @@ test('determine_sign', []) :-
determine_sign((a+1)^2, pos),
determine_sign((a-1)^3, dnk),
determine_sign(-exp(a), neg),
determine_sign(a/(a+1), pos),
determine_sign((2+a)*0, zero).
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment