# Replacing a combination of terms

I have a quite simple question. I have an expression that looks similar to $T=\frac{1}{a_1}-\frac{1}{a_2}+1$ and I'd like Mathematica to use $A=\frac{a_1}{a_2}$ to reformat the expression (if possible) such that only $A$ appears in it.

Any idea?

Cheers, Pascal

• Does this help: mathematica.stackexchange.com/q/894/131 ? Feb 6 '13 at 12:13
• Sorry, but no. The example used in the mentioned thread is way to elaborate for me to understand. Feb 6 '13 at 13:13
• If you could transform your expression in something depending on A only that would mean that the original expression would not change if I'd multiply both a1 and a2 with the same constant (A = a1/a2 = (c a1)/(c a2) ). Clearly, making that change to the original variables does change T. So, the transformation you want isn't possible. Feb 6 '13 at 13:31

Here is your expression and a rule for replacement:

T = 1/a1 - 1/a2;
rule = a1 -> A*a2;


Let us replace:

T /. rule


You get this:

-(1/a2) + 1/(A a2)

You may further transform it. For example:

% // Factor


The result is:

-((-1 + A)/(A a2))