Message Boards Message Boards

GROUPS:

Remove the negative sign so that positive-signed term comes first

Posted 3 months ago
499 Views
|
4 Replies
|
2 Total Likes
|

I found the default dealing of the terms often displays a negative sign at the beginning, including those beneath a square-root sign, which is a little bit annoying since for most cases, there exists at least one positive-signed term in the result and the negative sign can be adjusted by directly being moved backward after the positive-signed term or being multiplied into one difference term, swapping the two numbers in the difference term and thus avoiding a negative sign at the beginning. How can I remove the negative sign to make sure the term with positive sign comes first(if there is any)?

Example1:

-(a+b)(c-d)

Current result:

(-a - b) (c - d)

What I want:

(a+b)(d-c)

Example2:

Integrate[2  g y Sqrt[2 r y - y^2] \[Rho], {y, 0, h}, 
  Assumptions -> (r | h | g) \[Element] PositiveReals && 
    h <= 2 r] // FullSimply

Current Result:

ConditionalExpression[
 1/3 g \[Rho] (2 Sqrt[-h^5 (h - 2 r)] - 
    r (Sqrt[-h^3 (h - 2 r)] + 3 Sqrt[-h (h - 2 r)] r) + 
    6 r^3 ArcCsc[Sqrt[2] Sqrt[r/h]]), h < 2 r]


i.e.
$\frac{1}{3} g \rho \left(2 \sqrt{-h^5 (h-2 r)}-r \left(\sqrt{-h^3 (h-2 r)}+3 r \sqrt{-h (h-2 r)}\right)+6 r^3 \text{arccsc}\left(\sqrt{2} \sqrt{\frac{r}{h}}\right)\right)\text{ if }h<2 r$

The result I want:

ConditionalExpression[
 1/3 g \[Rho] (2 Sqrt[h^5 (2 r-h)] - 
    r (Sqrt[h^3 (2 r-h)] + 3 Sqrt[h (2 r-h)] r) + 
    6 r^3 ArcCsc[Sqrt[2] Sqrt[r/h]]), h < 2 r]


i.e.
$\frac{1}{3} g \rho \left(2 \sqrt{h^5 (2 r-h)}-r \left(\sqrt{h^3 (2 r-h)}+3 r \sqrt{h (2 r-h)}\right)+6 r^3 \text{arccsc}\left(\sqrt{2} \sqrt{\frac{r}{h}}\right)\right)\text{ if }h<2 r$

Example 3:

`Integrate[Sin[x]^2, {x, a, b}]`

Current result:

1/2 (-a + b + Cos[a] Sin[a] - Cos[b] Sin[b])

What I want:

1/2 (b -a + Cos[a] Sin[a] - Cos[b] Sin[b])

Example 4:

D[1/2 Log[1 - x] - 1/2 Log[1 + x], x] // Simplify
Current result:

1/(-1 + x^2)


What I want:

1/(x^2 - 1)

Example 5:

`Integrate[1/(x^4 - a^4), x] // FullSimplify`


Current result:

`-((2 ArcTan[x/a] - Log[a - x] + Log[a + x])/(4 a^3))`


what I want:

(Log[a - x]-2 ArcTan[x/a] + Log[a + x])/(4 a^3)

4 Replies

This seems to work in a couple of cases:

fnct = (LeafCount[#] + 3 StringCount[ToString[InputForm[#]], "-"] &);
-(a + b) (c - d)
FullSimplify[%, ComplexityFunction -> fnct]
Integrate[2 g y Sqrt[2 r y - y^2] \[Rho], {y, 0, h}, 
 Assumptions -> (r | h | g) \[Element] PositiveReals && h <= 2 r]
Simplify[%, ComplexityFunction -> fnct]
Posted 3 months ago

Thanks for your insight, it does work to some degree.

But for the first example, it gives-((a + b) (c - d)).

Moreover, for the second example, it givesConditionalExpression[ 2 g \[Rho] (1/3 Sqrt[h^5 (-h + 2 r)] - 1/6 r (3 r Sqrt[h (-h + 2 r)] + Sqrt[h^3 (-h + 2 r)]) + r^3 ArcCsc[Sqrt[2] Sqrt[r/h]]), h < 2 r] where the term (-h+2 r) emerges multiple times, which would be better if displayed as (2r-h) especially as I have made the assumption h<=2r.

Additionally, for the last example, it gives(-2 ArcTan[x/a] + Log[a - x] - Log[a + x])/(4 a^3), although being moved to the numerator, the negative sign still comes first.

On my system I get this:

fnct = (LeafCount[#] + 3 StringCount[ToString[InputForm[#]], "-"] &);
FullSimplify[-(a + b) (c - d),
  ComplexityFunction -> fnct] // TraditionalForm

(a+b) (d-c)

TraditionalForm is another trick you can try. In general, getting algebraic expressions in exactly the way you want them can be rather complicated.

Posted 3 months ago

Thanks. The TraditionalForm trick is useful though imperfect. I agree on you that rearranging expressions in exactly the way I want is truly complicated.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract