MathGroup Archive 1999

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

Search the Archive

Re: Q: Why can't I stop TraditionalForm dismissing Times Attributes ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15810] Re: [mg15736] Q: Why can't I stop TraditionalForm dismissing Times Attributes ?
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Sun, 7 Feb 1999 02:04:26 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

This is not really an explanation of the question about TraditionalForm
you are asking. I think an explanation can probably only be given by a
wri insider and would only be of interest to someone with particular
concern with the Mathematica Front End.

However, in general it should never be necessary (and is usually  not a
good idea) to change any attributes of Plus and Times. If you want your
own non-listable versions you should simply define them. Here is an
example:

In[3]:=
mytimes[x___,y_List,z___]:=Sequence[x,y,z]; mytimes[x__]:=Times[x];
myplus[x___,y_List,z___]:=Sequence[x,y,z]; myplus[x__]:=Plus[x];


Since I am not sure what you want to happen when one of the arguments to
mytimes or myplus is a list I decided just to return a Sequence. Now
the following thing will happen:
In[25]:=
mytimes[3,2,5]
Out[25]=
30

In[26]:=
mytimes[{3,4},5]
Out[26]=
Sequence[{3, 4}, 5]

The advantage of using Sequence here is that if for some reason you want
to you can immediately use the usual Times:

In[27]:=
Times[%]
Out[27]=
{15, 20}

I do not think there are now any problems with TraditionalForm. The only
weakness of this approach seems to me that you can't enter the new
addition and multiplication as + or *. But even this can be fixed:

In[28]:=
<<Utilities`Notation`

In[29]:=
InfixNotation[+,myplus];
InfixNotation[*,mytimes];

(note that InfixNotation must be entered using the special Notation
palette!)

Now everything works as it always had In[30]:=
Expand[(x+y)*(a+b)]
Out[30]=
a x + b x + a y + b y

but

In[31]:=
{x,y}*{a,b}
Out[31]=
Sequence[{x, y}, {a, b}]


On Fri, Feb 5, 1999, Fabien Boniver <F.Boniver at ulg.ac.be> wrote:

>Hi,
>
>This message ends with the shortest transcript I can get  of a session
>explaining
>my problem.
>This is about two bizarre side-effects of TraditionalForm. Maybe  they
>are due to some (numerous 8-) ) lacks in my Mathematica knowledge.
>
>In order to do some formal computations, I need Plus and Times not to be
>
>Listable.  See the myPlusTimes function below. TraditionalForm seems to
>rely on the fact that Times is Listable (that would be another
>transcript 8-) ) and it actually modifies the Listable property of
>Times, which in turn leads to amazing results.
>
>So, I decided to try to be clear and precise (see function mathPlusTimes
>
>and myTraditionalForm below).
>And now, Mathematica does not do the same thing on two consecutive
>evaluations of the same computation (see In[7] and In[9]), though I
>don't attempt to affect any symbol value.
>
>I use Mathematica 3.0.1.1x on a PMAC 604e running MacOs 8.1.
>
>Hope somebody can explain.
>Many thanks in advance,
>
>Fabien
>
>*** CUT TRANSCRIPT HERE
>In[1]:=
>Attributes[{Plus,Times}]
>Out[1]=
>{{Flat,Listable,NumericFunction,OneIdentity,Orderless,Protected},{Flat,
>Listable,NumericFunction,OneIdentity,Orderless,Protected}}
>
>In[2]:=
>mathPlusTimes[dummy_]:=Module[{},Unprotect[Plus,Times];
>SetAttributes[Plus,Listable];
>SetAttributes[Times,Listable];
>Protect[Plus,Times];
>dummy
>]
>
>In[3]:=
>myPlusTimes[dummy_]:=Module[{},Unprotect[Plus,Times];
>ClearAttributes[Plus,Listable];
>ClearAttributes[Times,Listable];
>Protect[Plus,Times];
>dummy
>]
>
>In[4]:=
>myTraditionalForm[x_]:=myPlusTimes[TraditionalForm[mathPlusTimes[x]]]
>
>In[5]:=
>myPlusTimes[1];
>
>In[6]:=
>Attributes[{Plus,Times}]
>Out[6]=
>{{Flat,NumericFunction,OneIdentity,Orderless,Protected},{Flat,NumericFun
ction,
>
>OneIdentity,Orderless,Protected}}
>
>In[7]:=
>1//myTraditionalForm
>Attributes[{Plus,Times}]
>Out[7]//TraditionalForm=
>1
>Out[8]=
>{{Flat,NumericFunction,OneIdentity,Orderless,Protected},{Flat,Listable,
>NumericFunction,OneIdentity,Orderless,Protected}}
>
>In[9]:=
>1//myTraditionalForm
>Attributes[{Plus, Times}]
>Out[9]//TraditionalForm=
>1
>Out[10]=
>{{Flat,NumericFunction,OneIdentity,Orderless,Protected},{Flat,NumericFun
ction,
>
>OneIdentity,Orderless,Protected}}
>
>*** END OF TRANSCRIPT
>
>
>--
>Fabien BONIVER
>
>Inst. of Math., University of Liege
>**
>Universite de Liege
>Service de Geometrie et Theorie des Algorithmes Institut de
>Mathematique, B37
>Grande Traverse, 12
>4000 Sart Tilman (Liege),  Belgium
>**
>Email : F.Boniver at ulg.ac.be
>Phone : + 32 4 366 94 17
>


Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp/
http://eri2.tuins.ac.jp/



  • Prev by Date: Re: Function definition
  • Next by Date: Compiling a Module
  • Previous by thread: Q: Why can't I stop TraditionalForm dismissing Times Attributes ?
  • Next by thread: Re: Q: Why can't I stop TraditionalForm dismissing Times Attributes ?