I have a function `sol`

defined as a solution to an equation (computed numerically). Specifically

`sol[p_, a_] := NSolve[g[p, x, a] == 0, x, Reals][[1, 1, 2]] `

Trying it out

`sol[.2, .51] sol[.2, .52] sol[.2, .53] `

gives .51, .52, .53 — on this range it behaves like identity. Now I try

`ND[sol[.2, aa], aa, .51 ] `

and instead of giving me 1 as I would expect, it gives me very long expression involving variable x. I am not using the variable `aa`

anywhere else in the code. And yes, I have done `Needs["NumericalCalculus`"]`

.

How is this possible? It seems obvious to me that it has to return a number! How can it return anything else?

Edit: here is the whole code (I have simplified it a little bit)

`Needs["NumericalCalculus`"] g[ x_, a_] = D[RealAbs[1 - x]^1.2 + RealAbs[a - x]^1.2, x]; sol[a_] := NSolve[g[ x, a] == 0, x, Reals][[1, 1, 2]]; ND[sol[aa], aa, .55] `