I have a function (deep inside my package) that looks like
signedPart =
Function[{expr, inf},
Assuming[Join[#>0&/@(Variables[expr]), {expr<0}], Simplify[Sign[inf]]]
]
This function is supposed to return the sign of the input inf
assuming that all variables given in expr
are (real) positive and expr
is negative.
Some examples that work as intended:
signedPart[-x^2-y^2,x]
(*1*)
signedPart[-x^2+y^2,x-y]
(*Sign[x-y]*)
However, the following
signedPart[x^2 + y^2, -x]
gives a warning that the assumptions are contradictory (because x^2 + y^2
can't be negative), and arbitrarily returns -1
.
Question: What can I do to suppress Simplify
from issuing warning messages and instead have it return a default of +1
if contradictory assumptions are encountered?
What I prefer:
For the sake of speed, I prefer a solution that is as low-level as possible. For example, inside Simplify
there may be a low-level function ContradictoryAssumptionsQ
that checks for this. If I had access to this function I would wrap my code to test and return the appropriate result. I would prefer not to use Simplify
, FullSimplify
, Reduce
or Refine
on the assumptions to test for a contradiction since these are much too general-purpose (overkill) for the task. Also, my function signedPart
will be used many times, so I'd like it to be fast and not issue messages.
Check[ ]
... $\endgroup$Assuming[x < 0 && x > 0, Simplify[Sign[x]]]
, you get1
. It has (arbitrarily) picked the second assumption and dropped the first. $\endgroup$