MathGroup Archive 2007

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg80797] Re: Rule-based programming: declare variables to be a number
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Sun, 2 Sep 2007 02:51:53 -0400 (EDT)
  • References: <fb83lf$82d$1@smc.twtelecom.net>

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?
>  
Unless you have too much code to change, I would tackle this slightly 
differently. I would represent your lie algebra variables in some way 
you can recognise, and use non-commutative multiply (not Times) to 
create your expressions. That way, everything that is not a lie algebra 
variable is an ordinary number and it is fairly easy to define rules 
that will combine these and apply the appropriate commutation rules to 
the lie algebra variables.

As others have commented, it is not a good idea to write code like 
NumericQ[g]=True because this changes the basic operation of 
Mathematica. For example, such code might work OK until you try to 
combine it with some more code that needs NumericQ for something else!

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: Re: [Mathematica 6] Bug in Labeled, Center align option
  • Next by Date: Re: rotating rings illusion
  • Previous by thread: Re: Rule-based programming: declare variables to be a number
  • Next by thread: Re: Re: Rule-based programming: declare variables to be a number