Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: overloading times operator

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88831] Re: overloading times operator
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Sat, 17 May 2008 23:29:23 -0400 (EDT)

On 5/17/08 at 5:32 AM, gstaceystaples at yahoo.com (gstaples) wrote:

>I wrote a procedure to define the non-commutative product of two
>elements of the form e_X e_Y, where X and Y are multi-indices.  I do
>this using Times.

>I do a simple calculation like

>Expand[(e_{1} + e_{3})(e_{1} - e_{3})]

>and get the wrong answer.  (On the first try.)

>If I then re-execute the code that defines the multiplication, I
>repeat the calculation and get correct output.

>Alternatively, if I execute

>e=Symbol["e"]

>before loading the procedure, I get correct output on the first try.

>More troubling is that after getting correct output, if I perform
>calculations of a different kind (e.g. matrix multiplication), when
>I repeat my original calculation, I start getting incorrect output
>again.  (Until I re-execute the code that defines the
>multiplication.)

>It's frustrating to repeat a calculation and get different sets of
>output depending on what other calculations are done in between.

>Does anyone have suggestions?

You did not provide details of the procedure you wrote to
overload Times. So, I don't see a way to determine precisely why
things work the way you describe. But, having said that there
are two obvious things to look at:

First, would be a problem with the procedure you wrote.

Second, is the issue of overloading a commonly used function
such as Times. It is inherently risky to overload operations
that are likely to be used throughout Mathematica. Possibly,
there is some internal code that is designed to temporarily
overload Times which restores the default behavior to clean up
after itself. Assuming no errors in your code, this would
explain the behavior you see. But this is entirely speculation
on my part.

Rather than overload Times, I would define one of the operators
without built in meanings such as CircleTimes to have the
behavior you want. This would ensure your code will not interact
in some unintended way with other built in functions. See tutorial/OperatorsWithoutBuiltInMeanings.


  • Prev by Date: Re: Traditional Ordering of Equations
  • Next by Date: Re: Re: RenderBadPicture error while running
  • Previous by thread: Re: overloading times operator
  • Next by thread: Re: overloading times operator