MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: test positive




Manual wrote:
 ----------
|I want to test whether a function is always positive for a given set of
|parameter values.
|
|For example, consider the trivial case: |
|f=x*y
|
|Is there a way to test whether x*y is positive given that x is greater
|than 0 and y is less than 0 or both x and y are greater than 0, etc.,
|or better yet to solve for the specific conditions that will yield
|xy>0.
|

Mathematica doesn't have this capability built-in.  We can write a
program  to do what you want.  However, my program is limited by the
capabilities of  Mathematica's Interval arithmetic.
(ie.  Mathematica can't do    SinIntegral[ Interval[{0.4, 5.8}] ]  ).

I defined functions,  AssumedInterval, Assume, IntervalExpr, and 
UseAssumptions.
I made a list of rules called  AssumptionRules.

___________________________

In[10]:=
AssumedInterval[x_]:=x


In[11]:=
Assume[x_,Positive]/;(NumericQ[x]===False):=
     (AssumedInterval[x]^=Interval[{$MinNumber^(1/20),Infinity}])


In[12]:=
Assume[x_,Negative]/;(NumericQ[x]===False):=
     (AssumedInterval[x]^=Interval[{-Infinity,-$MinNumber^(1/20)}])


(*  I ran into trouble when I simply used $Min Number.  *)


In[13]:=
IntervalExpr[expr_]:=With[
          {temp=Map[AssumedInterval[#]&, expr,{-1}]},
          If[TrueQ[FreeQ[temp,f_[_Interval..]]],temp, Indeterminate]]


In[14]:=
AssumptionRules={
Greater[a_,b_]:>With[{tempa=IntervalExpr[a],tempb=IntervalExpr[b]},
Which[Min[tempa]>Max[tempb],True,Max[tempa]<=Min[tempb],False, True,
Greater[a,b]]/;
(Head@tempa===Interval||Head@tempb===Interval)],
          
Less[a_,b_]:>With[{tempa=IntervalExpr[a],tempb=IntervalExpr[b]},
Which[Max[tempa]<Min[tempb],True,Min[tempa]>=Max[tempb],False, True,
Less[a,b]]/;
(Head@tempa===Interval||Head@tempb===Interval)]
     };

(*  Many other rules can be added to the list.   *)


In[15]:=
UseAssumptions[expr_]:=expr//.AssumptionRules

_____________________________
Now in the next line I define (x, y) to be positive, and use this fact
in  the lines that follow.


In[16]:=
Assume[x,Positive];
Assume[y,Positive];


In[17]:=
x*y>0//UseAssumptions

Out[17]=
True


In[18]:=
x*y<-Pi//UseAssumptions

Out[18]=
False

 ----------------------------------
Ted Ersek




  • Prev by Date: sorting a Matrix
  • Next by Date: about PDE of 4th degree
  • Prev by thread: Re: sorting a Matrix
  • Next by thread: about PDE of 4th degree