Computationally finding roots of a recursive function I'm having a pretty complex function $h(n,d) = f(n,d) -n$ where $n \in \mathbb{N}$ and $d \in [1,9] \subset \Bbb{R}$. $f(n,d)$ is recursively defined.
$$f(n, d) = \begin{cases} n<0\quad f(|n|,d) \\ 
 n=0\quad 0\\
0<n<10\quad 1\\
n≥10\quad x g(y, d) + f(x-1, d) y + f(n \mod x,d)
\end{cases}$$  
where $x = 10^{\lfloor \log_{10} n \rfloor}$ and $y = \lfloor \frac n x \rfloor$;
$$g(n,d) = \begin{cases} n = d\quad 1\\
n ≠ d\quad 0\end{cases}$$
I'm not sure if the definition is complete, however the scheme should stay this way. It's pretty obvious that $h(n,d)$ is highly computationally expensive, however I need to find all roots of the function for every $d$.
Most algorithms to find a root that I know only work for polynomial functions or are dead slow and recursive themselves. What is the best way to find all roots of this function for specific $d$'s?
 A: An attempt:
Fix $d \in [1,9] \subset \Bbb{R}$.
Allow me to rewrite your function a bit:
$$h(n) = f(n) -n$$ 
where $n \in \mathbb{N}$ and $f(n)$ is recursively defined.
$$f(n) = \begin{cases} n<0\quad f(-n) \\ 
 n=0\quad 0\\
0<n<10\quad 1\\
n≥10\quad x \delta_{\lfloor \frac n x \rfloor,d} + \lfloor \frac n x \rfloor f(x-1) + f(n \mod x)
\end{cases}$$  
where $x$ is a power of ten. (Specifically it has the number of digits of $n$ minus one zeros. Except for powers of ten! (then it's one less zero)). Hope that made sense.
Indeed we also have that $\lfloor \frac n x \rfloor$ is the leading digit of $n$ and $(n \mod x)$ is the number $n$ without its leading digit.
Need to find all roots of the function for every $d$.
UPDATED NOTES
1) $d \in \Bbb{Z}$
2) For a positive integer $n$ you will never get the first (negative) case.
3) You are going to get a lot of calls to $$f(9\dots9)$$ because $x-1$ and its children (in the final case) will always have that form.
4) The only thing that comes out of $f$ is the zero of case 2, the 1(s) from case 3 and the power of ten when your input (or its children) have a digit that matches the digit $d$.
4.5) Let $d \neq 9$ Then $$f(9999) = 9*f(999)+f(999) = 10*f(999) = 10*(10*f(99))$$
$$=10*(10*(10*f(9))) = 1000$$
by repeated application of the final case.
Now let $d = 9$ Then
$$f(9999) = 1000+10*f(999) = 1000 + 10*(100 + 10*f(99))$$
$$= 1000 + 10*(100 + 10*(10 + 10*f(9)) = 1000 + 10*(100 + 10*(10 + 10*1)$$
$$ = 4000 $$
The pattern here is clear for any number of nines.
4.75) General case:
say $d = 3$
$$f(53643102) = 0 +  5*f(9999999) + f(3645102)$$
$$ = (5*1000000) + (1000000 + 3*f(999999) +f(645102)) = 6300000 +f(645102)$$
$$ = \cdots = 6365311$$
Where the pattern seems easy enough to calculate for the general case when $d \neq 9$
I think I've got this right. The rest was wrong.
I welcome some feedback on my analyses. Let me know if this is all rubbish.
