4

Why doesn't Mathematica show the numerical result of

(0.8\[CenterDot]452\[CenterDot]20+1.5\[CenterDot]4180\[CenterDot]10
  -2\[CenterDot]900\[CenterDot]100) / (0.8\[CenterDot]452
  +1.5\[CenterDot]4180-1\[CenterDot]2\[CenterDot]900) // N
Simon
  • 14,631
  • 4
  • 41
  • 101
Tyilo
  • 28,998
  • 40
  • 113
  • 198
  • This is is a strange question. What made you think [`CenterDot`](http://reference.wolfram.com/mathematica/ref/CenterDot.html) would be interpreted as [`Times`](http://reference.wolfram.com/mathematica/ref/Times.html), when the documentation says that [`CenterDot` has no built-in meaning](http://reference.wolfram.com/mathematica/ref/CenterDot.html#NSG)? – Simon Dec 02 '11 at 09:51
  • 3
    @Simon On the contrary: in a large part of the world, the centred dot is *the* standard multiplication sign (we abandoned × by the end of primary school). Many users come to Mathematica "as a program that does math", not as a programming language. Finally, there are so many easy ways to enter ∙ , e.g. palettes, the math-aware handwriting input of Windows 7, etc.) Would you look up × if you hand-write 2×3 and the system accepts it? – Szabolcs Dec 02 '11 at 13:04
  • @Simon You can also define CenterDot as the default multiplication character in the settings, which I thought also meant it could be used in calculation. – Tyilo Dec 02 '11 at 17:30
  • @Szabolcs, Tyilo: Both good points. – Simon Dec 02 '11 at 22:52

4 Answers4

9

Just to complete some of the other answers/comments, if you want CenterDot to be interpreted as Times in both input and output by using something like

Unprotect[CenterDot, Times];
CenterDot = Times;
Times /: MakeBoxes[Times[a__], fmt_] := 
  With[{cbox = ToBoxes[HoldForm[CenterDot[a]]]}, 
   InterpretationBox[cbox, Times[a]]];
Protect[CenterDot, Times];

Which you can add to your init.m if you want it loaded by default.

This works on both numeric and symbolic expressions, e.g.

In[5]:= 1\[CenterDot]2\[CenterDot]3   
Out[5]= 6

In[6]:= a b c    
Out[6]= a\[CenterDot]b\[CenterDot]c

You can also make the automatically inserted multiplication symbol between space separated numbers be CenterDot by executing

SetOptions[EvaluationNotebook[], 
  {AutoMultiplicationSymbol -> True, NumberMultiplier -> "\[CenterDot]"}]

or by selecting Center Dot in the preferences dialog under Appearance > Numbers > Multiplication.

For example:
screenshot

Brett Champion
  • 8,497
  • 1
  • 27
  • 44
Simon
  • 14,631
  • 4
  • 41
  • 101
  • Simon, remind me, what is the reason to use MakesBoxes rather than Format? (I seem to recall this being an issue, but I cannot remember why.) – Mr.Wizard Dec 02 '11 at 19:46
  • 1
    @Mr.Wizard: That would be this question: http://stackoverflow.com/q/4112299/421225 – Simon Dec 02 '11 at 22:53
  • Thanks, I knew it was here somewhere. – Mr.Wizard Dec 02 '11 at 23:09
  • [Here's a different version of the `MakeBoxes` code](http://pastebin.com/Kij4Uk3M) that uses `TemplateBox` instead of `InterpretationBox`. This way you can edit the terms in a `\[CenterDot]` multiplication. – Simon Dec 03 '11 at 01:13
4

Just replace \[CenterDot] by a space

Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190
  • Is there anyway to use `\[CenterDot]` as multiplication? – Tyilo Dec 02 '11 at 09:14
  • 2
    @Tyilo Yes, you can define `CenterDot = Times` to interpret (but not display) it as multiplication. But I'd recommend getting a bit more familiar with Mathematica before making changes like this. The reason this definition works will be clear if you evaluate `FullForm[a\[CenterDot]b]` (i.e. it's not because of the name of `\[CenterDot]`) – Szabolcs Dec 02 '11 at 09:35
  • @Szabolcs: Actually, how would you go about making `\[CenterDot]` not be interpreted as `CenterDot`? Or any similar infix operator? – Simon Dec 02 '11 at 10:18
  • @Simon I don't know, I never played much with redefining notations – Szabolcs Dec 02 '11 at 11:10
4

Multiplication in Mathematica is written either as a space (Times[a,b] == a b) or as an asterisk (Times[a,b] == a*b). \[CenterDot] is not interpreted as multiplication.

Szabolcs
  • 24,728
  • 9
  • 85
  • 174
1

I think Simon's first method can be written more concisely. Please review:

Unprotect[Times];

CenterDot = Times;

Format[a_*b__] := Interpretation[HoldForm[a\[CenterDot]b], a*b];

Second attempt. I believe this works properly with Convert To > StandardForm and editing.

CenterDot = Times;

MakeBoxes[Times[x__], _] := RowBox @ Riffle[ToBoxes /@ {x}, "\[CenterDot]"]
Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
  • +1 For not protecting `Times` at the end! Also, `Format` isn't quite as stable as `MakeBoxes`, to quote Michael Pilat: ["`Format` isn't really intended to produce output that can be re-used as input, but just to format output."](http://stackoverflow.com/a/4119830/421225) – Simon Dec 02 '11 at 22:57
  • @Simon general caveats regarding `Format` remaining, can you show me a way in which this fails? – Mr.Wizard Dec 02 '11 at 23:12
  • @Simon Pardon me, I failed to read the linked question before asking. I see the failure with Ctrl+Shift+N. – Mr.Wizard Dec 02 '11 at 23:17
  • Type `a*b` into a input cell, then press `Ctrl-Shift-N` to convert it to standard form. This calls the `Format` rule and somehow gets stuck in a loop. If you find a work around for this, you can get a shiny green tick in my old question! (Edit: I guess I took too long to write this comment!) – Simon Dec 02 '11 at 23:20
  • @Simon, further experimentation shows that I cannot properly edit the output produced from `a b c` using the `MakeBoxes` method. Do you experience this? (I should say this affects *both* methods; I am wondering if there is a way around it.) – Mr.Wizard Dec 02 '11 at 23:25
  • I guess it is a characteristic of `InterpretationBox` that I didn't notice before. – Mr.Wizard Dec 02 '11 at 23:30
  • Normally I just convert to InputForm, edit and convert back. However, here's some different code that allows editing: `Times /: MakeBoxes[Times[a__], fmt_] := With[{cbox = Block[{CenterDot}, ToBoxes[CenterDot[a]]]}, InterpretationBox[cbox, Times[a], Editable -> True]];` problem is that it only changes what is seen, not what it's interpreted as. – Simon Dec 02 '11 at 23:50
  • What you need to do is to make a `TemplateBox` box object, like the built-in `TraditionalForms` or things made by the `Notation` package. Problem is, I'm not sure how to do this manually... – Simon Dec 02 '11 at 23:51
  • @Simon, please review my second attempt. – Mr.Wizard Dec 03 '11 at 00:10
  • Actually, I think the following works (can you check it for me?): ``Unprotect[CenterDot, Times]; ClearAll[CenterDot, Times] CenterDot = Times; Times /: MakeBoxes[Times[a__], fmt_] := With[{slots = Array[Slot, Length[{a}]], rslots = Riffle[Array[Slot, Length[{a}]], "\[CenterDot]"], boxes = ToBoxes /@ {a}}, TemplateBox[boxes, "CenterDot", DisplayFunction -> (RowBox[rslots] &), InterpretationFunction -> (RowBox[slots] &), Editable -> True, Selectable -> True]]; Protect[CenterDot, Times];`` – Simon Dec 03 '11 at 00:23
  • Your 2nd attempt does work. But I feel it's kind of cheating! `Times` goes to `CenterDot` goes to `Times` goes to.... – Simon Dec 03 '11 at 00:27
  • @Simon that seems to work better, but it doesn't edit as well as the simple form I added above. I am not grasping the need for all the complexity (TemplateBox etc.). Re: 2nd, cheating or not, can you force it into a recursion? – Mr.Wizard Dec 03 '11 at 00:29
  • No I can't force a recursion, but "Convert To InputForm" (Ctrl-Shift-I) does not yield multiplication with a `*` like it should... – Simon Dec 03 '11 at 00:35
  • @Simon reflecting on this specific indented use, I don't think it is desirable for CenterDot to be converted to `*` in InputForm, but it is very good to know how to do what you demonstrate. (Perhaps for this case ExportAutoReplacements would be good.) – Mr.Wizard Dec 03 '11 at 00:56