Defining a function from expression containing parameters

As the title says, I’ve been trying to define a function this way:

f[a_, b_, c_, d_] := 
  Max[rootsFinal[[1]] /. a1 -> a  /. b1 -> b /. c1 -> c, d1-> d];

here rootsFinal[[1]] is a list that contains rational expressions in a,b,c,d. The definition seems to succeed, but when I try to call

f[1,1,1,1]

I get the error

"Part specification rootsFinal[[1]] is longer than depth of object"

Had had closed the session in the meanwhile? That would explain why rootsFinal is not recognized any more.

That was it, feeling dumb now. Is this the correct way to make a function out of an expression dependent on parameters or is there a better way? I will have to compute it on a grid of values

Are a,b,c,d all parameters? Then what is the main variable? If a,b,c,d are indeed the final variables, I see nothing wrong with your definition, except that it will work only in a session where you have already calculated rootsFinal. If you need a function that works across sessions, you may want to paste the whole expression of rootsFinal[[1]] into the definition of f.

I need to compute f on a “grid” with many values of a,b,c,d. Thanks for the advice