Generate random differentiable functions

I have a function g that takes a function f :: RealFloat a :: a -> a and data, and then calculates the derivative of the function f to compute the result.
I would like to test the function g with random differentiable functions f.
How is it possible to generate random differentiable functions?
I read that quickcheck can generate functions. Do you have any suggestions?

You can make a data type that represents e.g. polynomials and generate that. Then you can write an evaluation function that turns the data type into a function. You can also add trigonometric functions, depending on what you want to test.

1 Like

You could generate a random non-differentiable function (for example generate n points, treat these as defining a piecewise linear function) and then approximate it with a prefix of its Taylor series. That might yield more uniformly random data than generating the latter directly, or it might not. At least it means you can just take any algo for generating random functions. I’m not aware of any, though.

2 Likes

there is a simple connection between the roots of a polynomial and those of its first derivative:

so I think you can sample the roots of the function within a compact interval.

1 Like