2

I am trying to define a function inside a module as following

test1[a_] := Module[{sol1, g1, y},
  sol1 = Reduce[a + x^2 == y, x];
  g1[y_] := Evaluate@sol1[[1, -1]];
  Print[Definition[g1]];
  g1[33]
  ]

This gives the output

Attributes[g1$28580]={Temporary}

g1$28580[y$_]:=-Sqrt[-3+y$28580]
-Sqrt[-3 + y$28588]

As you can see this does not work. The y in the body of the function is y$28580, but not y$. Is there any way to make this work?

NonalcoholicBeer
  • 1,453
  • 7
  • 11

1 Answers1

1

Just replace the third line by:

g1[Pattern[Evaluate[y], _]] = sol1[[1, -1]];
Wen Chern
  • 716
  • 4
  • 8