MathGroup Archive 1994

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

Search the Archive

re: Specifying rules

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: re: Specifying rules
  • From: Paul=Rubin%Management%Business at banyan.cl.msu.edu
  • Date: Mon, 13 Jun 94 10:55:13 EDT

Ron I. Herman <m1rih00 at frb.gov> wrote:

>Is there any way to specify rules for symbols?
>For example, is there a way to tell Mathematica
>that a > 0 and b < 0 such that Positive[a b] will
>yield false?

Yes, using upvalues, but I'm not confident that it works across the board.  
For your specific example:

In[]:=  Clear[a, b];
In[]:=  a /: Sign[ a ] = 1;
In[]:=  b /: Sign[ b ] = -1;

The two preceding lines tell Mma to evaluate the Sign function differently 
when applied to a and b.  The "a /:" part associates that definition with a 
rather than Sign (which is protected).  If you clear a, the upvalue goes with 
it.

In[]:=  Positive[ a b ]
Out[]=  False
In[]:=  Positive[ a ]
Out[]=  True
In[]:=  Negative[ b ]
Out[]=  True

It worked this time.  It seems to me, though, that I've seen other examples 
where it doesn't work so well.  (I tried up-setting NumberQ[a] to True, so 
that Mma would think a was a number, and caused a recursion fault with a 
later reference to a.)  Off-hand, I can't remember the failure stories I've 
read.  So caveat emptor.

**************************************************************************
* Paul A. Rubin                                  Phone: (517) 336-3509   *
* Department of Management                       Fax:   (517) 336-1111   *
* Eli Broad Graduate School of Management        Net:   RUBIN at MSU.EDU    *
* Michigan State University                                              *
* East Lansing, MI  48824-1122  (USA)                                    *
**************************************************************************
Mathematicians are like Frenchmen:  whenever you say something to them,
they translate it into their own language, and at once it is something
entirely different.                                    J. W. v. GOETHE






  • Prev by Date: re: From Mathematica to Gnuplot
  • Next by Date: re: Re: Global styles definitions
  • Previous by thread: Specifying rules
  • Next by thread: re: Specifying rules