Skip to content

Error propagation for trigonometric and hyperbolic functions - #3854

Merged
jl-wynen merged 5 commits into
mainfrom
trig-error-prop
Mar 4, 2026
Merged

jl-wynen merged 5 commits into
mainfrom
trig-error-prop

Conversation

@jl-wynen

Copy link
Copy Markdown
Member

Fixes #3826

There is a bit more code here than before because I moved from generating code for trigonometric functions on variables to writing it manually. I did this because I didn't want to add more specialisations to the generator.

This also optimises the trig functions for inputs in degrees. The used to first convert the entire variable to radians, making a separate, temporary array. The new code avoids that with the extra cost of adding more element functions.

template <typename T>
constexpr auto acos(const ValueAndVariance<T> a) noexcept {
using std::acos;
return ValueAndVariance(acos(a.value), a.variance / (1 - a.value * a.value));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be an absolute value here applied to the denominator, and similar for the asin case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can the denominator be > 1? That is outside the domain of these functions and asin and acos return NaN in that case. So if anything, I think the variance should also be NaN. Do you agree?

@jokasimr jokasimr Mar 2, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it makes sense to set the variance to nan 👍

@henrikjacobsenfys

henrikjacobsenfys commented Mar 3, 2026 •

Copy link
Copy Markdown

Thank you very much for this! Would it be possible to also implement the sinc function (i.e. sin(x)/x for x~=0 and 1 for x=0)? :)

@jl-wynen

jl-wynen commented Mar 3, 2026

Copy link
Copy Markdown
Member Author

Thank you very much for this! Would it be possible to also implement the sinc function (i.e. sin(x)/x for x~=0 and 1 for x=0)? :)

Possible, but that would be a separate issue and PR. Can you open one?

@jl-wynen
jl-wynen merged commit 942b727 into main Mar 4, 2026
4 checks passed
@jl-wynen
jl-wynen deleted the trig-error-prop branch March 4, 2026 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support propagation of uncertainties in math functions

3 participants