# Simplifying expression efficiently

I have the following expression that I want to simplify to have an optimized/nice output.

term=-2+2 eps-(1-eps) t^(3-8/(1-n)) y^(-(8/(1-n)))+t^(-(1/(1-n))) y^(-(1/(1-n))) (2 (1-eps) (1-2 tkl)-7 (1-eps) t^(1-1/(1-n)) y^(-(1/(1-n))))+t^(1-4/(1-n)) y^(-(4/(1-n))) (-3 (1-eps)-5 (1-eps) t^(2-2/(1-n)) y^(-(2/(1-n)))+2 (3-3 eps) t^(1-1/(1-n)) (1-2 tkl) y^(-(1/(1-n))))-t^(-(2/(1-n))) y^(-(2/(1-n))) (1-eps+(9-9 eps) t^(2-2/(1-n)) y^(-(2/(1-n)))-6 (1-eps) t^(1-1/(1-n)) (1-2 tkl) y^(-(1/(1-n))))+t^(2-6/(1-n)) y^(-(6/(1-n))) (-3 (1-eps)-(1-eps) t^(2-2/(1-n)) y^(-(2/(1-n)))+2 (1-eps) t^(1-1/(1-n)) (1-2 tkl) y^(-(1/(1-n))))

The assumption is n>1 (everything else between [0,1] ). Now I attempted to use FullSimplify blindly,

output1=Assuming[{n>1},term//FullSimplify]

Now this is not the optimized/nice output. For example,

whereas a nicer output could be found by further use of Factor, FullSimplify as,

This tells that the use of FullSimplify does not lead to an optimized/nice result (which could be true as FullSimplify might not always give optimized results I suppose).

In order to get a better-looking results for a general n>1 for this case, I did the following:

output=(term/.{n-> 1+dummy}//Factor//FullSimplify)/.{dummy->n-1}

which is the nice result I wanted! Now

Also the LeafCount shows output is better optimized than output1,

output1//Leafcount

93

whereas

output//LeafCount

69

I wanted to know if anyone has any better method to deal with this simplification from their experiences.

EDIT after @Alexei Boulbitch's comment:

My goal is to bring this kind of expression (having arbitrary powers of n) to a form where if I substitute the value of n, it should give a polynomial of positive exponent for all variables (up to overall multiplication of any variable of negative exponent).

In the example above, once I substitute n=1.75 to output it brings me a polynomial of positive exponents. With @Bob Hanlon's answer, the LeafCount gets even better keeping the variables with positive exponent once one uses all the conditions for all variables.

As a follow up, if I just change the condition for n to 0<n<1, Simplify does not change anything. I believe Mathematica just wants to keep the LeafCount minimal. But now if once uses n=3/4, the same expression is not nice anymore:

The nice form would be

which after substitution n=3/4 might have overall factor of t and y with negative exponent but the rest of the terms are polynomial with positive exponent:

• It is not quite clear what you mean by another method. From your text, I have the impression that you are looking for some modification of Simplify to force it to make the expression according to your taste. If yes, I do not think that it is easy, and I do not know such a way. If, in opposite, you are looking for other ways to transform the result of Simplify, I see some possibilities. For example, try thisSimplify[term, {n > 0, t > 0, eps > 0, y > 0, tkl > 0}] /. (t*y)^a_ :> t^a*y^a. One can do a few other steps if needed. Commented Apr 6 at 19:16
• @AlexeiBoulbitch My goal is to bring to a nice form. By that, I meant that once I substitute the value of n (>1), it should give a simple polynomial of Positive exponent. I was trying Simplify with the only condition applied on n as shown in the question. I was unaware that putting all conditions will bring the expression to this form already. The expression should not go as any negative power of any variables except for any overall factors. If you see the output above with n=1.75, all the terms inside the brackets are having Positive exponent. Commented Apr 6 at 20:04
• However, this might not be the case always. For example, for the same expression, if I restrict 0<n<1, it is very difficult to bring into the form of positive powers. Now if I use the same Simplify with the condition 0<n<1, it does not yield a different result compared to using n>1. One then gets a polynomial of Negative exponent. Commented Apr 6 at 20:08
• I think the problem is that you and Mathematica have different, so to say, "aesthetic views". In this case, if you need to force Mathematica to represent the result in the desired form, you need to apply special tricks. This will be somewhat longer and more difficult than satisfying yourself with its straightforward result. I often do such a forcing, but only when I want to present the final result of my calculations. Commented Apr 7 at 15:41
• This is indeed the final results in terms of a general n-value (for two different cases) such that if one wishes later to substitute a particular n-value=3/4, one would get a polynomial of desired form. For the case of n>1, the case is simple for Mathematica whereas 0<n<1 would indeed require special treatment. My idea is to write down replacement rules looking into the final result to force Positive exponent. Is this what you would also do or is there other special forcing methods? Commented Apr 7 at 17:22

\$Version

(* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *)

ClearAll["Global`*"]

(term = -2 + 2  eps - (1 - eps)  t^(3 - 8/(1 - n))  y^(-(8/(1 - n))) +
t^(-(1/(1 - n)))  y^(-(1/(1 - n)))  (2  (1 - eps)  (1 - 2  tkl) -
7  (1 - eps)  t^(1 - 1/(1 - n))  y^(-(1/(1 - n)))) +
t^(1 - 4/(1 - n))  y^(-(4/(1 - n)))  (-3  (1 - eps) -
5  (1 - eps)  t^(2 - 2/(1 - n))  y^(-(2/(1 - n))) +
2  (3 - 3  eps)  t^(1 - 1/(1 - n))  (1 - 2  tkl)  y^(-(1/(1 - n)))) -
t^(-(2/(1 - n)))  y^(-(2/(1 - n)))  (1 -
eps + (9 - 9  eps)  t^(2 - 2/(1 - n))  y^(-(2/(1 - n))) -
6  (1 - eps)  t^(1 - 1/(1 - n))  (1 - 2  tkl)  y^(-(1/(1 - n)))) +
t^(2 - 6/(1 - n))  y^(-(6/(1 - n)))  (-3  (1 - eps) - (1 -
eps)  t^(2 - 2/(1 - n))  y^(-(2/(1 - n))) +
2  (1 - eps)  t^(1 - 1/(1 - n))  (1 -
2  tkl)  y^(-(1/(1 - n))))) // LeafCount

(* 398 *)

(term2 = Assuming[n > 1, term // FullSimplify]) //
LeafCount

(* 93 *)

However, using all known assumptions

(term3 =
Assuming[n > 1 && And @@ Thread[0 <= {eps, t, tkl, y} <= 1],
term // FullSimplify]) // LeafCount

(* 54 *)

term3 /. n -> Rationalize[1.75] // FullSimplify

(* (-1 + eps) (1 +
t (t y)^(8/3))^3 (2 + (t y)^(4/3) (-2 + 4 tkl + (1 + t) (t y)^(4/3))) *)

% // LeafCount

(* 43 *)
• Any suggestion, if I wish to keep the condition for 0<n<1 and still want an expression of Positive exponent? Now for example ((1 + t (t y)^(2/(-1 + n)))^3) with n=3/4 will give (1 + 1/(t^7 y^8))^3 i.e. negative exponent instead of t^-21 y^-24 (1 + t^7 y^8)^3. Do I need to transform such manually? Commented Apr 6 at 20:15
• Together will give the form that you indicate that you want; however, that increases the LeafCount and still has powers in a denominator. I don't understand why that form is preferred. Commented Apr 6 at 23:32

term1 = Simplify[term, {eps > 0, t > 0, y > 0, tkl > 0}] /. (a_*b_)^
c_ -> a^c*b^c

one comes to the result:

(*(-1 + eps) (1 + t^(1 + 2/(-1 + n)) y^(2/(-1 + n)))^3 (2 -
2 t^(1/(-1 + n)) y^(1/(-1 + n)) +
4 t^(1/(-1 + n)) tkl y^(1/(-1 + n)) +
t^(1 + 2/(-1 + n)) y^(2/(-1 + n)) + t^(2/(-1 + n)) y^(2/(-1 + n)))*)

Now, you need it at n=3/4. Let us substitute it:

term2 = term1 /. n -> 3/4
(*(-1 + eps) (1 + 1/(t^7 y^8))^3 (2 + 1/(t^8 y^8) + 1/(t^7 y^8) - 2/(
t^4 y^4) + (4 tkl)/(t^4 y^4))*)

"Not nice" according to your aesthetics. OK, let us do the following:

term4 = MapAt[Together, term2, {{2}, {3}}]

(*  ((-1 + eps) (1 + t^7 y^8)^3 (1 + t - 2 t^4 y^4 + 4 t^4 tkl y^4 +
2 t^8 y^8))/(t^29 y^32) *)

It is already better. To finalize it let us simplify the last parenthesis:

MapAt[Simplify, term4, {5}]

(* ((-1 + eps) (1 + t^7 y^8)^3 (1 + t + 2 t^4 (-1 + 2 tkl) y^4 +
2 t^8 y^8))/(t^29 y^32) *)

To visualize it better I show it below as an image:

Have fun!

• thanks for the response. I played your method for the case of a general 0<n<1 but it does not work. I see that for a numerical value n=3/4 just doing Simplify brings your/my final result. But this is not true for a general 0<n<1 case. My goal is to keep the exponent in terms of n and later if I want I can put any value say n=3/4 or n=1/2 etc. The problem is more serious when you apply your method for a general 0<n<1 with the n symbolical. This boils down to the fact that one needs to keep the exponents in the form say ...+t^(1/(1-n))... and not ...+t^(1/(n-1)).... Commented Apr 8 at 9:30
• One brute-force way that I do to achieve the desired form for general 0<n<1 is the following: term2= (term//Simplify) /. {t_ + t_^x1_ y_^x2_. :> t(1 + t^(-1+x1) y^x2) } with term being the original expression. term2 /. {n->3/4} will then give desired results. But as I said this is just looking into the final output and then modifying what to use for a replacement rule. But I suppose this can be collected to a list of such rules etc. Commented Apr 8 at 11:20