Suppose I have a function f[x, coeff]
coeff[n_] := Table[RandomVariate[NormalDistribution[]], {n + 1}];
f[x_, coeff_] := Sum[coeff[[i + 1]] x^i, {i, 0, Length[coeff] - 1}]
and I want to create another function f1[x]
by substituting the concrete second argument.
Update: At first I tried to define it as a simple function:
f1[x_] := f[x, coeff1]
But when executing ?f1
I'd like to see the definition of f1
as a concrete polynomial rather than a definition in terms of another function. In other words I would like f[x, coeff1]
to be evaluated for coeff1
but not for x
.
The closest I could get to that goal was:
coeff1 = coeff[1]
f1[x_] := Evaluate[f[Hold[x], coeff1]]
This results in f1 containing the Hold
over x
:
f1[x_] := 1.23788 - 0.790537 Hold[x]
Suppose also that a have x
defined somewhere:
x = 1
I tried some combinations of Function
, ReleaseHold
and Unevaluated
. For example:
f1 = Function[x, Evaluate[f[Hold[x], coeff1]]]
f1[x_] := ReleaseHold[Evaluate[f[Hold[x], coeff1]]]
f1[x_] := Evaluate[f[Unevaluated[x], coeff1]]]
... and some others. But I either get a function with Hold[x]
, or a function which was already evaluated for x
(a constant in this case). What I want to get is when executing ?f1
I want to see:
f1[x_] := 1.23788 - 0.790537 x
rather than
f1[x_] := 1.23788 - 0.790537 Hold[x]
Could anyone please explain how to force the WL's evaluation algorithm to do this?
Clear[f1]; f1[x_] := f[x, coeff[1]]
for the first part of your problem. For the second part, if $x$ is defined, it will be substituted in: you can't reasonably avoid that. You seem to be trying very hard to work against normal practices, which suggests that there is another underlying problem that you are trying to solve in this forcing way. Perhaps you should explain why you need this behavior instead: there might be a better, more natural way to achieve what you ultimately want. $\endgroup$g[x_]:=x + 1
withoutx
being evaluated, then it is likely possible with my problem too. $\endgroup$f1
, the simplest way would be to just evaluatef1[x]
, wherex
is unassigned. $\endgroup$