# How do you define a TransformationFunctions for Simplify?

I'm trying to change the form of some electrical engineering expressions. One transformation that can help add insight is noticing when two resistances are in parallel. The equation for this would be:

$$R_{parallel}=\frac{R_1 R_2}{R_1+R_2}$$

I'm still pretty new at Mathematica, but looking at the documentation of Simplify, I believe I might be able to make some TransformationFunction to add to TransformationFunctions. I looked at the documentation for TransformationFunctions and the two examples look completely different than the types of equations I've seen people using on StackExchange.

I've tried using the following:

par[e_] := e /. {R1 R2/(R1 + R2) -> Rparallel}
Simplify[R1 R2/(R1 + R2), TransformationFunctions -> {Automatic, par}]


and I get back Rparallel like I expect. However, if I try

Simplify[R1 R1 R2/(R1 + R2), TransformationFunctions -> {Automatic, par}]


I get (R1^2 R2)/(R1 + R2) instead. I would have expected to get R1 Rparallel.

I know that there are other problems with this, for example that the transformed name should depend on the input names (for example R1 and R2 should produce R1R2Parallel), but I'm trying to get the first issue fixed first.

Simplifyis mysterious and the documentation is insufficient. If you want to have some insight of what Simplify has tried, the following code is usefull :

par[e_] :=
Echo[
Echo[e, {"par", "in"}] /. {R1 R2/(R1 + R2) -> Rparallel},
{"par", "out"}
]

Simplify[R1 R1 R2/(R1 + R2), TransformationFunctions -> {Automatic, par}]


You can define several TransformationFunction : par,par01,par02 each with a different label, and see what happens. I had a lot of surprises with that : Simplify tries a lot of things that are obviously irrelevant for a human. This explains why I had so many frustrations when trying to manipulate electrical expressions. Sincerely I never succeed in obtaining something really interesting (in particular a systematic approach).

For a rule to be applied broadly, the LHS of the rule should be kept as simple as possible so that it readily matches forms.

par[e_] := e /. {(R1 + R2) -> R1 R2/Rparallel}

Simplify[R1 R2/(R1 + R2), TransformationFunctions -> {Automatic, par}]

(* Rparallel *)

Simplify[R1 R1 R2/(R1 + R2), TransformationFunctions -> {Automatic, par}]

(* R1 Rparallel *)