# Understanding Distribute when applied with a user defined function

I would expect this

F[x_] := Module[{aux = x},    aux = X];
{a + b + c, e+ f} // Map[Distribute@*F]


to yield

{3X, 2X}

instead, the function is not distributed over plus, yielding

{X, X}

Clearing F, Clear[F], I get what I expected

{F[a]+F[b]+F[c],F[d]+F[e]}

How to distribute the function before evaluating it?

Clear[F];
F[x_] := X;
{a + b + c, e + f} // Map[Distribute@*Hold[F]] // ReleaseHold
(* {3 X, 2 X} *)

Clear[F];
F[x : Except[_Plus]] := X;
{a + b + c, e + f} // Map[Distribute@*F]
(* {3 X, 2 X} *)

Clear[F];
F[x_ /; Head[x] =!= Plus] := X;
{a + b + c, e + f} // Map[Distribute@*F]
(* {3 X, 2 X} *)

• Thank you for the three (!) alternatives. Do you know why if F[x_]:=x^2 the Hold is not needed? Commented Mar 31, 2023 at 14:15
• Do you mean F[x_] := x^2 or F[x_] := X^2? Commented Mar 31, 2023 at 14:32
• Small case. When it actually uses the argument F[x_]:=x^2 Commented Mar 31, 2023 at 14:47
• Because in that case, it is not F that is getting distributed itself, but Power (^2). Compare the following evaluation traces. Commented Mar 31, 2023 at 15:30
• Great thank you. I didn't know about Trace. So useful! Commented Mar 31, 2023 at 15:45