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. – MarcoB Nov 03 '21 at 12:31g[x_]:=x + 1withoutxbeing evaluated, then it is likely possible with my problem too. – Max Nov 03 '21 at 12:49f1, the simplest way would be to just evaluatef1[x], wherexis unassigned. – user3257842 Nov 03 '21 at 12:58xsuch asexp = 0.655591 + 0.23043 x, you can use replacement rules such asexp/.{x->7}– user3257842 Nov 03 '21 at 12:59f1[x_] = f[x, coeff[1]]doesn't work, becausexis defined and it gets substituted. What I want isf1[x_]to be defined as a polynomial. I wantf[x, coeff[1]]to be evaluated forcoeff, but not forx– Max Nov 03 '21 at 13:05Clear[f1]; With[{x = Unique[]}, f1[x, 2] = f[x, coeff[1]]]– Daniel Huber Nov 03 '21 at 13:16