Programming Challenge
- To: mathgroup at smc.vnet.net
- Subject: [mg9601] Programming Challenge
- From: Ersek_Ted%PAX1A at mr.nawcad.navy.mil
- Date: Thu, 13 Nov 1997 23:24:12 -0500
- Sender: owner-wri-mathgroup at wolfram.com
Consider the following attempt to write a program that allows one to assume something like, (0 <= x <= 100), and then make use of this assumption. In[1]:= Assume[x_,LessEqual[a_, x_, b_]]/; (NumericQ[x]===False)&&(Im[x]===0)&&(Im[x]===0)&&(a<b):= (AssumedInterval[x]=Interval[{a,b}]; ) Now I can make assumptions about (w) and (r). In[2]:= Assume[w, 4<=w<=12] Assume[r, -5<=r<=-3] In[4]:= Log[AssumedInterval[w]] Out[4]= Interval[{Log[4],Log[12]}] In[5]:= (AssumedInterval[r])^4 Out[5]= Interval[{81,625}] In the lines above I found an interval for the possible values of Log[w] and r^4. Warning: Interval arithmetic worked beautifully in the two examples above, but in many other examples we get an interval that is larger than it needs to be (sometimes much larger). Now how can I build on the code above so It will do the following: In[7]:= Log[w] Out[7]= Interval[{Log[4],Log[12]}] Notice I don't want to make explicate use of AssumedInterval. Something that does the following will be a good start: f_[x_, others___]/; (f is a numeric function && x has an assumed interval) := f[AssumedInterval[x], others___] Looks simple, but I can't get it to work. What I would really like is a way to do this without testing every Head to see if it's a NumericFunction, and then test each argument of every numeric function to see if it has an argument with an AssumedInterval. We might get it to work that way if we use something like: $Post= f_[x_, others___]/; (conditions):= f[AssumedInterval[x], others] Thanks Ted Ersek ersek_ted%pax1a at mr.nawcad.navy.mil