46611179//131836323 is approximately 0.5 / sqrt(2)
And so on.
These are the correct terms (derivatives evaluated at x=0), so this isn’t exactly wrong. However, I wouldn’t say it’s correct either. One would expect a symbolic representation like Mathematica’s Sqrt[2] or Julia’s pi.
And when the above poster says “approximately,” they mean “almost exactly.” The rational numbers above resolve to the float values with an error of <1 ULP (i.e., nearly to the limits of machine precision, which would be <0.5 ULP).
It looks like taylor’s default behavior is to return rational numbers. This isn’t a ridiculous choice because many functions have rational series (and at the end of the day, every float is rational also! so to be pedantic: there’s no escaping it without fancier symbolics like \sqrt{2}).
But I also see that taylor has a rationalize keyword. It looks like passing rationalize=false should give you floats like you want.
I think that’s a bad idea. It wrongly conveys the impression that such numbers are exact as rationals, whereas exposing floating-point numbers makes more clear to the user that approximations might have been used. For example:
Notice that the coefficients are approximately 1/4 and 1/32 (which would have been the correct answers). I don’t think transforming into rationals make any sense here…
Ah, that’s useful, thank you.
Maybe it would make sense to change the default behavior? Or - at least - give some rationale into having rationals as default…
More to the point, I guess that, if floating-point calculations were used at some point during the Taylor series evaluation, then it would seem reasonable to keep those floating-point numbers since they convey the usual expectation that “numerical errors might be present”. If no FP happens, then rationals indeed look more sensible. Ideally, it would be nice for such design choices to be documented and (even more ideally) explained to users.