mathics-core icon indicating copy to clipboard operation
mathics-core copied to clipboard

Unwanted spaces

Open sheerluck opened this issue 3 years ago • 4 comments

When I run mathics and say 2x+3 I get these lines:

In[1]:= 2x+3
Out[1]= 3 + 2 x

if I go to def format_outputform in mathics/builtin/arithfns/basic.py and change op to be Dot Operator I get these lines:

In[1]:= 2x+3
Out[1]= 3 + 2 ⋅ x

I expected to get 3 + 2⋅x but after result = self.create_expression(SymbolMakeBoxes, expr, form).evaluate(evaluation) (that was line 308 in mathics/core/element.py) that result contains ["2", " ⋅ ", "x"]] with unwanted spaces around dot operator. If only I could somehow prevent that and get ["2", "⋅", "x"]] in result (spaces around Plus Sign " + " in result are totally fine)

sheerluck avatar Mar 11 '22 12:03 sheerluck

@sheerluck, ideally, what you should do is to set in your session In[1]:=MakeBoxes[(a_)*(b_), form_] := RowBox[{MakeBoxes[a, form], ".", MakeBoxes[b, form]}]

Then, in WMA, In[3]:=a*b produces In[3]:= a b (the same that in Mathics), but In[2]:=StandardForm[a*b] produces Out[2]//StandardForm= a.b For some reason, this does not work in Mathics, and I think that is the true issue here.

mmatera avatar Mar 11 '22 18:03 mmatera

This works on both Mathics and WMA:

In[1]:= Unprotect[Times]; Format[a_*b_]:=ToString[a]<>"."<>ToString[b]
In[2]:= a + a
Out[2]=  2.a

mmatera avatar Mar 11 '22 18:03 mmatera

This works on both Mathics and WMA:

In[1]:= Unprotect[Times]; Format[a_*b_]:=ToString[a]<>"."<>ToString[b]
In[2]:= a + a
Out[2]=  2.a

oh, thank you, it works! What would be equivalent line(s) for ~/.config/mathicsscript/settings.m config?

sheerluck avatar Mar 11 '22 21:03 sheerluck

Add this line:

Unprotect[Times]; Format[a_*b_]:=ToString[a]<>"."<>ToString[b];Protect[Times];

mmatera avatar Mar 11 '22 21:03 mmatera