[Date Index]
[Thread Index]
[Author Index]
Re: Rule-based programming: declare variables to be a number
*To*: mathgroup at smc.vnet.net
*Subject*: [mg80776] Re: [mg80751] Rule-based programming: declare variables to be a number
*From*: Andrzej Kozlowski <akoz at mimuw.edu.pl>
*Date*: Sat, 1 Sep 2007 00:31:14 -0400 (EDT)
*References*: <200708310348.XAA08008@smc.twtelecom.net>
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
> http://theory.gsi.de/~vanhees/faq mailto:hees at comp.tamu.edu
>
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
free:
NumericQ[a*b]
True
NumericQ[b^a]
True
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**
| |