# Pure functions failing in algebra

f[equation_] := Module[{},
ContourPlot[equation[x, y] == 1, {x, -2, 2}, {y, -2, 2}]
]
equation = (#1^2 + #2^2) &;
f[equation]


The above code draws a circle. But I want to translate this equation by (1,1) via

old=(#1^2 + #2^2) &
a=#1+1;b=#2+1;
new=old[a,b]


Then f[new] can't draw any more. a and b can generally be functions of #1 and #2. How to resolve this?

"old" does not return a function as you can see (& is missing):

old[a, b]

(1 + #1)^2 + (1 + #2)^2


This is only an expression. To change "new" into a function, you need the operator "&" (Function). However, as this operator has the attribut "HoldAll" you need "Evaluate" to evaluate "old[a,b]" like:

old = (#1^2 + #2^2) &
a = #1 + 1; b = #2 + 1;
new = Evaluate[old[a, b]] &


Now f[new] will draw:

f[new]


• Personally, I wouldn't recommend messing around with Evaluate in pure functions unless it's really necessary. new = old[#1 + 1, #2 + 1] & would be a more idiomatic solution to this problem IMO. Mar 13, 2023 at 11:13