Skip to content

Error propagation for trigonometric and hyperbolic functions#3854

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

Error propagation for trigonometric and hyperbolic functions#3854
jl-wynen merged 5 commits intomainfrom
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.

@github-project-automation github-project-automation bot moved this to In progress in Development Board Mar 2, 2026
@jl-wynen jl-wynen moved this from In progress to Selected in Development Board Mar 2, 2026
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?

Copy link
Copy Markdown
Contributor

@jokasimr jokasimr Mar 2, 2026

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
Copy link
Copy Markdown

henrikjacobsenfys commented Mar 3, 2026

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
Copy link
Copy Markdown
Member Author

jl-wynen commented Mar 3, 2026

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
@github-project-automation github-project-automation bot moved this from Selected to Done in Development Board Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Support propagation of uncertainties in math functions

3 participants