Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

So, in an attempt to help out Fabian with his question, I did what I often do, and created a new symbol in the Pillsy` package that I could play with. Since it was in a package I control completely, I thought, "Hey, I can just call it Times!". I was really surprised when this happened:

In[3]:= Pillsy`Times[a, b, c]
Out[3]= a * b * c

It looks like Mathematica uses just the symbol name in determining whether to replace something with infix syntax, without paying attention to the context. However, I'm fairly sure I've never seen it happen before and I don't recall coming across it in the documentation. Evidently specifying InputForm shows you the whole thing:

In[4]:= Pillsy`Times[a, b, c] // InputForm
Out[4]= Pillsy`Times[a, b, c]

This is in contrast to the InputForm for System`Times.

Is this an intentional feature (it's hard to imagine otherwise), and if so, how does it interact with things like MakeBoxes, MakeExpression and Format?

Also, how do you avoid being burned by it? I'm a little alarmed that my assumption that a * b * c is the same thing as System`Times[a, b, c] is unfounded, even in the absence of changes to $Post and the like.

share|improve this question
    
"help out halirutan with their question".. sorry, not my question ;-) –  halirutan May 3 '12 at 17:32
    
@halirutan thanks for the fix! –  Pillsy May 3 '12 at 17:51

2 Answers 2

up vote 6 down vote accepted

It seems like the StandardForm (default for output) of Times in any context (or Plus, etc) is with the * and + symbols.

But your assumption isn't wrong I think, the symbols * and + are mapped to System Times and System Plus. Try

PrependTo[$ContextPath, "blo`"];
blo`Times[a_, b_] := 8;

FullForm@MakeExpression[RowBox[{"a", "*", "b"}], StandardForm]

I think that this goes against Mathematica policy that "StandardForm generates output that gives a unique and unambiguous representation of Mathematica expressions, suitable for use as input"

share|improve this answer

The problem seems to be with ToBoxes:

Outer[#1[#2[a,b]]&,{ToString[#,OutputForm]&,ToBoxes},{Times,foo`Times}]
(*
==> {{"a b", "foo`Times[a, b]"}, {\(a\ b\), \(a * b\)}}
*)

Note that Times and foo`Times are still different in that for Times, no * is generated.

When typing to the kernel directly, OutputForm is used, and foo`Times[a,b] gets printed:

In[1]:= {Times[a,b], foo`Times[a,b]}

Out[1]= {a b, foo`Times[a, b]}
share|improve this answer
    
If you try it with Plus the + is generated for both –  Rojo May 3 '12 at 19:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.