# How do I make a function from a solution? [duplicate]

This expression:

FullSimplify[Solve[dx == dL - (1/2) dd, dL]]


Gives this solution (I've simplified it for brevity):

$$\left\{\left\{ d_L\rightarrow \frac{\sqrt{1+z}}{2+z} \right\}\right\}$$ Which appears to be a 'rule', but now I want to create a function from that rule. Something like:

F[z_] := $$\frac{\sqrt{1+z}}{2+z}$$

but with the actual result from the Solve function. I've seen various attempts with the ReplaceAll command, but I can't seem to get it to work. How do I do this?

EDIT: I'm reasonably comfortable getting the answer using substitution like in the examples on this question: Assign the results from a Solve to variable(s). What I can't figure out is how to make a proper Function.

• Maybe this will help: it gives a list of pure Function, one for each solution: sol = Solve[a^2 + z a - 2 == 0, a]; Function[z, #] & /@ Values[sol] – Michael E2 Apr 9 at 19:42
• @Artes - Not as far as I can see. I see several examples where substitution is used to get an answer, but I don't see any answers that show a function being created. Am I missing something? – Quarkly Apr 9 at 19:42
• @MichaelE2 - No, that doesn't work. If you cut-and-paste your text exactly into Mathematica, then try Function[1024], all you get is 1024&. – Quarkly Apr 9 at 19:55
• You could define two function in my example, since it has two solutions, with {F, G} = Function[z, #] & /@ Values[sol]. (Tho, you should avoid starting names with a capital, esp. single-letter symbols.) – Michael E2 Apr 9 at 19:56
• @MichaelE2 - That looks more promising. Let me work on that. – Quarkly Apr 9 at 20:00

{{dL -> Sqrt[1 + z]/(2 + z)}}