I have a long and complex univariate expression with many parameters, $ f(x; a, b, c, d, ...) $.
I would like to group those parameters which only ever occur together.
Here is a very simple example where we can find the appropriate grouping by inspection:
f[x_] = (a + b) Exp[-c x] + (Exp[-d x]/(a + b))
How might I get Mathematica to recognize that a and b only occur as a sum a + b, never independently? I'd ultimately like Mathematica to to generate two expressions, like this:
f[x_] = r Exp[-c x] + (Exp[-d x] / r) and r = a + b.
Functions like FullSimplify don't seem to be willing to define new parameters like r to make the original expression for f[x] look prettier.
Here are some additional examples with the desired output:
g[x_] = a*b*c Exp[-c x] + (Exp[-d x]/(a*b*c)) --> g[x_] = r*c Exp[-c x] + (Exp[-d x]/(r*c)) and r = a*b
h[x_] = (a - b)/(c + d) Exp [-c x] + Log[ (a - b)/(c + d) ] --> h[x_] = r/(c + d) Exp [-c x] + Log[ r/(c + d) ] and r = a - b
j[x_] = (a/b)*c Exp[-c x] + (Exp[-d x]/(a*b*c)) --> no simplification
(The real expression is far more complicated, which is why going through it and manually finding these combinations is not practical.)
expr /. (a + b) -> rare you saying there are other examples where this will not work? or you mean it want it automated for anyaand anyb? When you say togother, you mean always sum? – Nasser May 15 '20 at 00:26b -> r - anot work for you? – J. M.'s missing motivation May 15 '20 at 00:27(a+b)may show up in several terms, butamay show up alone in some other terms. In this case, I would not want to define a new parameterr = a + b. I'd like Mathematica to understand the distinction and suggest the grouping when appropriate. – GnomeSort May 15 '20 at 00:28c1 = Cases[f[x], Plus[r_, s_, t___], \[Infinity]]yield{a + b, a + b}andc2 = Cases[g[x], Times[r_, s_, t___], \[Infinity]]yields{-c x, a b c E^(-c x), -d x, E^(-d x)/(a b c)}. – Akku14 May 15 '20 at 14:57Experimental`OptimizeExpression[expr]looks useful. – Simon Woods May 15 '20 at 14:59