3
$\begingroup$

I'm doing an indefinite integral on Mathematica and need the result in a more traditional form such as a polynomial in descending order. Something like, (-2+x)->(x-2). I have to integrate a rational function which would result in natural log of some expression in an absolute value. Here is the code I have below,

PolynomialForm[Integrate[1/((x - 2) (x + 3)), x], TraditionalOrder -> True]

and the resulting antiderivative it gives me is:

1/5Log[2-x]-1/5Log[x+3]

I figured out how to get |3+x| to become |x+3| by using PolynomialForm, but I still need to get |2-x| into |x-2|. I know both of them are equal to one another because of the absolute value. But Mathematica doesn't give me an absolute value, which is fine, but I need |2-x| to be |x-2|.

Any ideas on how to do so?

$\endgroup$
2
$\begingroup$

What you want is not unusual, and I have seen such questions in many different forms. There is one problem with it: When you work with expressions in Mathematica, it will always try to transform them into a standardized form. Forcing Mathematica to do it differently usually comes with the trade-off that you have to hold (that means to keep them unevaluated) expressions into a specific form.

Therefore, the first question is, do you want to just look at it or do you want to work with it? If you are OK with just looking at it then you can use HoldForm to keep your integral in its current format and replace the 2-x in it:

res = PolynomialForm[Integrate[1/((x - 2) (x + 3)), x], 
  TraditionalOrder -> True];
With[{res = res},
 HoldForm[res] /. Plus[2, a_] :> Plus[a, 2]
]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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