# Group parameters that only occur together [duplicate]

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.)

• for this example, you can do expr /. (a + b) -> r are you saying there are other examples where this will not work? or you mean it want it automated for any a and any b? When you say togother, you mean always sum? May 15 '20 at 0:26
• Would a substitution like b -> r - a not work for you? May 15 '20 at 0:27
• I realize that is possible for this example. But the real expression is much more complicated -- I don't know what parameters always occur together. For example, (a+b) may show up in several terms, but a may show up alone in some other terms. In this case, I would not want to define a new parameter r = a + b. I'd like Mathematica to understand the distinction and suggest the grouping when appropriate. May 15 '20 at 0:28
• then may be to help better understand what you want, may be gives few more examples (3-5), and show what the output you want for each to look like. Try to make the example as diverse as possible. This might make it more clear what you are asking because right now, the question is a little fuzzy. May 15 '20 at 1:02
• If you search the site for "subexpression" you'll find a few questions asking essentially the same thing. ExperimentalOptimizeExpression[expr]` looks useful. May 15 '20 at 14:59