MathGroup Archive 2007

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

Search the Archive

Re: Rule-based programming: declare variables to be a number

On 31 Aug 2007, at 05:48, Hendrik van Hees wrote:

> I still work with Mathematica 4.0. I hope, somebody can answer my
> question despite this.
> I have written a simple rule-based program to evaluate traces of
> SU(2)-Lie algebra (Pauli matrices) to help me to obtain the Lagrangian
> of a chiral model, but that's not so important for my question.
> My problem is the following: To get the usual rules with algebraic
> expressions containing numbers and Lie-algebra variables, one needs to
> define what happens when a Lie-algebra variable is multiplied by a
> number. This works fine as long as I use really constant numbers like
> 1, 2, 1/2, etc.
> However, of course, one needs this feature also for variable numbers,
> say a coupling constant g. So I wrote Unprotect[NumberQ] and then said
> NumberQ[g]:=True,
> but then NumberQ[g^2] evaluates to False. So I have written a whole
> bunch of rules to make powers of g also numbers. It works already  
> quite
> well, but is there a possibility to just declare a variable (like  
> g) to
> be a number, and then make Mathematica know, that expressions like  
> g^2,
> Sqrt[g], 1+g, etc. are also numbers?
> -- 
> Hendrik van Hees                        Texas A&M University
> Phone:  +1 979/845-1411                 Cyclotron Institute, MS-3366
> Fax:    +1 979/845-1899                 College Station, TX 77843-3366
>       mailto:hees at

Use NumericQ instead of NumberQ. Then:
NumericQ[a] = True;
NumericQ[b] = True;

(Note that you do not need to unprotect NumericQ !). Then you get for  


and so on, just as you wanted.

Andrzej Kozlowski

PS. I am sure NumericQ has worked like this at lest since version 5   
but I no longer remember about version 4.

  • Prev by Date: Re: Animation of a rotating object. (Mathematica 6)
  • Next by Date: Re: [Mathematica 6] Bug in Labeled, Center align option not accepted. And how to left justify label under object?
  • Previous by thread: Re: Rule-based programming: declare variables to be a number
  • Next by thread: Re: Rule-based programming: declare variables to be a number