How to transform a function from f[#1] to f[x]
Well, the easy way is to evaluate it for [x,y]
.
f[x_, y_] = Sqrt[-1 + Tanh[#1 - #2]^2] &[x, y];
If you'd rather do it with a replacement, you should understand the FullForm
because that's what replacement works on.
Sqrt[-1 + Tanh[#1 - #2]^2] & // FullForm
(*
Function[Sqrt[Plus[-1,Power[Tanh[Plus[Slot[1],Times[-1,Slot[2]]]],2]]]]
*)
So, you want to remove Function
.
Sqrt[-1 + Tanh[#1 - #2]^2] & /. {Slot[1] -> x, Slot[2] -> y, Function -> Identity}
(*
Sqrt[-1+Tanh[x-y]^2]
*)
I think the easiest way would be to define(name) the pure function f
f = Sqrt[-1 + Tanh[#1 - #2]^2] &
and use it accordingly
f[x,y]
(*Sqrt[-1 + Tanh[x - y]^2]*)
Here's a general function, which I think protects the body of the Function
from being evaluated:
def[Function[body_], f_] :=
With[{nvar = Max@Cases[Hold[body], Slot[k_] :> k, Infinity]},
With[{vars = Thread[
ToExpression[
Table["x" <> ToString@k, {k, nvar}],
StandardForm,
Hold],
Hold]},
vars /. Hold[v_] :> Block[v,
Hold[SetDelayed][
Hold[f] @@ (Pattern[#, Blank[]] & /@ v),
Hold[body] /. Slot[k_] :> RuleCondition[v[[k]]]
] // ReleaseHold
]
]]
Example:
ClearAll[fff];
xx = 2; x1 = 4;
def[xx + #2 - #1^2 &, fff]
DownValues@fff
(* {HoldPattern[fff[x1_, x2_]] :> xx + x2 - x1^2} *)
OP's:
def[Sqrt[-1 + Tanh[#1 - #2]^2] &, f]
DownValues@f
(* {HoldPattern[f[x1_, x2_]] :> Sqrt[-1 + Tanh[x1 - x2]^2]} *)