As the title says Im trying to build a function to compute divided difference for arbitrary list of points.
The divided difference of a set of points $\{(x_1,y_1),\ldots, (x_n,y_n)\}$ where $x_j<x_{j+1}$ is defined recursively by
$$ f[i,j]:=\frac{f[i+1,j]-f[i,j-1]}{x_j-x_i},\, f[i,i]:=y_i $$
for $j\ge i$.I tried to mimic this definition with the code
f[i_, j_, m_] := f[i, j, m] = (f[i + 1, j, m] - f[i, j - 1, m])/(
m[[j, 1]] - m[[i, 1]]) Boole[j > i] + m[[j, 2]] Boole[j == i]
where m is an arbitrary $n\times 2$ matrix. However I tried to see if this works calling f[1,1,{{1,2},{3,4}}]but it gives me a recursion limit error. How I can fix the above code? Thank you in advance.



f[0] = 1; f[n_] := n f[n - 1]from the docs almost works, but better is something likef[0] = 1; f[n_Integer?Positive] := n f[n - 1]orf[0] = 1; f[n_Integer] /; n > 0 := n f[n - 1]– Michael E2 Jul 27 '19 at 12:11dividedDifference[x_, f_] := Module[{d}, With[{n = Length[(x)]}, d = f; (* div. diff. computed in place *) Do[ d[[j]] = (d[[j]] - d[[j - 1]])/(x[[j]] - x[[j - k + 1]]), {k, 2, n}, {j, n, k, -1}]; d ]]--xis a list of nodes andfa list of values at the nodes. For inputm, the call should bedividedDifference @@ Transpose@m. – Michael E2 Jul 27 '19 at 12:23f[i_, j_, m_], which callsf[i + 1, j, m]andf[i, j - 1, m], both of which in turn callfon new arguments ad infinitum. Unless there are definition rules that you are not showing, there are no stops to this process. The calls tofwill occur even ifBoole[]evaluates to zero, in case you thinkBoole[]might stop the process. It would be possible to put the stops in using anIf[]statement. – Michael E2 Jul 27 '19 at 12:28Boolefunction would stop it, but it doesn't. I will try to fix it with anIfstatement as you said – Masacroso Jul 27 '19 at 12:30