0

I tried to expand this polynomials. With x, it is increasing with the right order, however with b it is in a random order. The only difference is that I change b to x and it works.

Expand[FullSimplify[a00*1 + a01*0 + a02/12 + a10*0 + a11*(1/(12 k) - b/(2 k) + b^2/(2 k)) + a12*(b/(6 k) - b^2/(2 k) + b^3/(3 k)) + a20/12 +    a21*(-(b/(6 k^2)) + b^2/(2 k^2) - b^3/(3 k^2)) + a22 (1/144 + 1/(180 k^2) - b^2/(6 k^2) + b^3/(3 k^2) - b^4/(6 k^2))], b]
1/12 (12 a00 + a02 + a20) + a22/144 + a22/(180 k^2) - (a21 b)/( 6 k^2) + (a21 b^2)/(2 k^2) - (a22 b^2)/(6 k^2) - (a21 b^3)/( 3 k^2) + (a22 b^3)/(3 k^2) - (a22 b^4)/(6 k^2) + a11/(12 k) - ( a11 b)/(2 k) + (a12 b)/(6 k) + (a11 b^2)/(2 k) - (a12 b^2)/(2 k) + ( a12 b^3)/(3 k)

Change b to x and it works.

Expand[FullSimplify[a00*1 + a01*0 + a02/12 + a10*0 + a11*(1/(12 k) - x/(2 k) + x^2/(2 k)) + a12*(x/(6 k) - x^2/(2 k) + x^3/(3 k)) + a20/12 +    a21*(-(x/(6 k^2)) + x^2/(2 k^2) - x^3/(3 k^2)) + a22 (1/144 + 1/(180 k^2) - x^2/(6 k^2) + x^3/(3 k^2) - x^4/(6 k^2))], x]
a22/144 + a22/(180 k^2) + (a11 + (12 a00 + a02 + a20) k)/(12 k) - ( a21 x)/(6 k^2) - (a11 x)/(2 k) + (a12 x)/(6 k) + (a21 x^2)/( 2 k^2) - (a22 x^2)/(6 k^2) + (a11 x^2)/(2 k) - (a12 x^2)/(2 k) - ( a21 x^3)/(3 k^2) + (a22 x^3)/(3 k^2) + (a12 x^3)/(3 k) - (a22 x^4)/( 6 k^2)

What is wrong?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
  • 1
    (1) (Full)Simplify uses heuristics to try to come up with something reasonable. There are no guarantees about the result. (2) Parts of expressions are auto-sorted by Mathematica, e.g. b+a is transformed to a+b. This makes it easy to detect that a+b and b+a are the same thing. But it also means that the choice of symbol names may affect the final structure, and therefore the simplification of expression. – Szabolcs Aug 21 '18 at 07:36
  • (1) But the final result is always some kinds of polynomials and expand should sort the polynomials correctly. (2) The command expand is done at the last after the (Full)Simplify is finished. Thus, expand should do what the manual said to sort the polynomials with respect to b regardless what the command (Full)Simplify is or the expression is. – shixx597_Min Aug 21 '18 at 15:59
  • I think the correct result mathematica should return is regardless of the variables, a correct ascending order with respect to whatever variable is given, no matter x or b. The (Full)Simplify is a red herring here. The code should work no matter what expression is given because expand is done at the last. – shixx597_Min Aug 21 '18 at 16:01
  • Even I don't use (Full)Simplify, Expand still gives me a random order if I uses the variable name called b. – shixx597_Min Aug 21 '18 at 16:19
  • What FullSimplify does is not mathematically well defined. There is no such thing as a "correct result". – Szabolcs Aug 22 '18 at 06:03
  • Expand does not sort anything. It is Plus that sorts, and part of the ordering is alphabetical, as I said above. Even without any special operations, the form of the original expression will change when replacing b by x: terms will be ordered differently. Now if you think for a moment about how you would implement somehting like Simplify, you will immediately see how this ordering might affect the result. – Szabolcs Aug 22 '18 at 06:08
  • I don't really understand what you want, though. Take a look at the tour: https://mathematica.stackexchange.com/tour Questions on this site are expected to be clear and focused on a practical problem. – Szabolcs Aug 22 '18 at 06:10

1 Answers1

3

They are the same expression, just simplified differently. You can verify by changing the b->x in the first:

(Expand[FullSimplify[
      a00*1 + a01*0 + a02/12 + a10*0 + 
       a11*(1/(12 k) - b/(2 k) + b^2/(2 k)) + 
       a12*(b/(6 k) - b^2/(2 k) + b^3/(3 k)) + a20/12 + 
       a21*(-(b/(6 k^2)) + b^2/(2 k^2) - b^3/(3 k^2)) + 
       a22 (1/144 + 1/(180 k^2) - b^2/(6 k^2) + b^3/(3 k^2) - 
          b^4/(6 k^2))], b] //. b -> x // 
   FullSimplify) == 
  (Expand[
    FullSimplify[
     a00*1 + a01*0 + a02/12 + a10*0 + 
      a11*(1/(12 k) - x/(2 k) + x^2/(2 k)) + 
      a12*(x/(6 k) - x^2/(2 k) + x^3/(3 k)) + a20/12 + 
      a21*(-(x/(6 k^2)) + x^2/(2 k^2) - x^3/(3 k^2)) + 
      a22 (1/144 + 1/(180 k^2) - x^2/(6 k^2) + x^3/(3 k^2) - 
         x^4/(6 k^2))], x] // FullSimplify)

which returns True

bill s
  • 68,936
  • 4
  • 101
  • 191
  • I understand they equal. However, my question is why expand with repsect to x gives me a correct ascending order while just a change of variable from x to b make the command expand fail to sort in a correct ascending order? – shixx597_Min Aug 21 '18 at 15:56
  • What do you mean by "correct order"? There are many ways to order the elements of an equation, the process of "simplification" is a pretty complicated thing. Ordering terms is a kind of sorting... and sometimes the names used can make a difference in the output. – bill s Aug 21 '18 at 18:24