1
$\begingroup$

Compare this (where all commands shown are in one input cell)

$Version
integrand = Cos[x]^4 - Sin[x]^4;
result = Integrate[integrand, x] // FullSimplify // InputForm
LeafCount[result]

Mathematica graphics

With

$Version
integrand = Cos[x]^4 - Sin[x]^4;
result = Integrate[integrand, x] // FullSimplify
LeafCount[result]

Mathematica graphics

This is very confusing when order of output does not match order of commands.

This happens only when using InputForm on some commands.

Is this known and why does it happen and is there a way to make it behave so that order of output is same as commands used even when using InputForm on one command?

I did search but could not find anything related but might have missed it. Notice that InputForm does not have an Out[nnn] cell to the left of it. May be this has something to do with it.

ps. I know I can split the input cell itself into two or more cells to fix this, but I want to keep these commands in one input cell.

V 13.2 on windows 10

$\endgroup$
1

1 Answer 1

1
$\begingroup$

Someone with more knowledge of parsing might have more details, but I suspect what's going on here is that at some point in the parsing of these expressions the line breaks are being interpreted as multiplication. As evaluation continues, it "figures out" that actual multiplication wasn't intended, but by then the elements have been re-ordered according to Mathematica's own ordering preferences. If I remember correctly, in early versions linebreaks were just like spaces, and so always (or at least much more frequently than now) were interepreted as multiplication. I guess at some point Wolfram decided that it would be more user-friendly to allow linebreaks to delimit whole, independent expressions. But maybe not all cases can be handled in the way our intuition expects.

But anyway, I never use linebreaks as expression delimiters. If I want to control the order of the output, I'll do it explicitly with lists, Column/Row/Grid constructs, the *Form constructs, and so forth. It seems like best practice to me, but maybe it's just my old habits refusing to die.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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