[Date Index]
[Thread Index]
[Author Index]
Re: Rule-based programming: declare variables to be a number
*To*: mathgroup at smc.vnet.net
*Subject*: [mg80853] Re: Rule-based programming: declare variables to be a number
*From*: David Bailey <dave at Remove_Thisdbailey.co.uk>
*Date*: Tue, 4 Sep 2007 03:45:49 -0400 (EDT)
*References*: <fb83lf$82d$1@smc.twtelecom.net> <200709020651.CAA25850@smc.twtelecom.net> <fbgmuq$9d7$1@smc.vnet.net>
Andrzej Kozlowski wrote:
> On 2 Sep 2007, at 08:51, David Bailey wrote:
>
>> 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
>
>
> Who are the "others"?
> Anyway, I completely disagree with this statement in this particular
> context.
>
> NumericQ has clearly been designed with this in mind. Note, for
> example, that althou NumericQ is Protected, a definition like
>
> NumericQ[a]=True
>
> does not require unprotecting NumericQ. Moreover, it does not add a
> DownValue to NumericQ.
>
> NumericQ[g] = True;
> DownValues[NumericQ]
> {}
>
>
> There are plenty of other reasons to believe that all all
> theseproperties of NumericQ are designed precisely for this type of
> use. Besides, I have another reason to think that no probems of the
> kind you are imagining would happen in this case: I have been using
> NumericQ inprecisly this way for about 10 years in numerous notebooks
> without any problems.
>
> Note alo the post from Carl Woll which, I think, can be regarded as
> an "offcial" WRI authorization for this kind of usage ;-)
>
> (However, note also that using Carl's definition:
>
> In[19]:= g /: NumericQ[g] = True;
>
> Dos not actually add an UpValue to g:
>
> UpValues[g]
> {}
>
> and I don't think it has any advantage over the more straightforward
>
> NumericQ[g] = True;
>
>
> I am sure all this is deliberate design, and even though it may not
> be easy to explain, it is very convenient.
>
> Andrzej Kozlowski
>
Lets not quarrel about this - but my point was that it is probably
easier to specify the set of objects that don't commute rather than
specify everything else that is an ordinary variable!
In general, I don't like to extend the built-in functions unless
absolutely necessary (as dh mentioned) - it just creates trouble when
you combine several pieces of code together. Why not just define a
spinMatrixQ predicate?
Also, it is not clear from the original question, if 'multiplication' is
represented by Times - if it is, the expressions will get sorted
regardless of NumericQ!
David Bailey
http://www.dbaileyconsultancy.co.uk
Prev by Date:
**Re: Re: Re: Rule-based programming: declare variables to be a number**
Next by Date:
**Re: Re: Re: Rule-based programming: declare**
Previous by thread:
**Re: Re: Rule-based programming: declare variables to be a number**
Next by thread:
**Re: Rule-based programming: declare variables to be a number**
| |