Oh that's just straight up implemented incorrectly. A test suite is needed indeed! Your version has the same amount of sharing as my original version though, which is to say that the nth element recomputes f^(n-1)(x).