Axect / puruspe

PURe RUSt SPEcial library
Apache License 2.0
13 stars 6 forks source link

Fresnel integrals of real inputs #20

Open ethanbarry opened 1 month ago

ethanbarry commented 1 month ago

The Fresnel Integrals are two functions $$S(x)=\int_0^x \sin(t^2)\,dt$$ and $$C(x)=\int_0^x \cos(t^2)\,dt$$ which come up a lot in optics and stuff. It'd be nice if we could provide these functions to users, but there's no material on them in Numerical Recipes. I've experimented with a few different approximations, but I think the nicest is probably the one due to J. Boersma in this paper (doi↗).

The only trouble is, it uses $i$ in the calculations, so I would need to use the num_complex crate. I know this was discussed in #6 a few months ago. I'm happy to draft a PR if this sounds like a useful contribution...

ethanbarry commented 1 month ago

Never mind, Boersma's approximation is awful—it underflows like crazy. Julia's package for the Fresnel integrals simply uses the relation to the error function $\mathrm{erf}(z)$ instead of numerically estimating the Fresnel integral directly. I don't blame them—every algorithm I've found is either accurate to maybe three significant figures, or quite complicated and easy to get wrong.

To use the error function relation, I'd need a complex implementation of $\mathrm{erf}(z)$...