Skip to content

C library: add exp, log, pow models #7906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2023

Conversation

tautschnig
Copy link
Collaborator

@tautschnig tautschnig commented Sep 19, 2023

The implementation follows Nicol N. Schraudolph: "A Fast, Compact Approximation of the Exponential Function," Neural Computation 11(4), 1999 and its discussion in
https://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@tautschnig tautschnig added the Kani Bugs or features of importance to Kani Rust Verifier label Sep 19, 2023
@tautschnig
Copy link
Collaborator Author

@kroening and @martin-cs Would really appreciate your input on the proposed approximations.

@martin-cs
Copy link
Collaborator

Not unreasonable BUT we should probably decide on and document what the user can expect from our math library. The levels of accuracy are something like:

  1. The C standard says essentially nothing.
  2. IEEE-754 gives special cases but no requirements on accuracy.
  3. Most implementations are within a few ULP ( https://members.loria.fr/PZimmermann/papers/accuracy.pdf ).
  4. There are performant (at least for execution) implementations of correctly rounded functions available (https://core-math.gitlabpages.inria.fr/).

1 and 2 we can do easily but not everyone likes this #6999. I don't think we can realistically do 3 without using the actual implementations as the errors are very ideosyncratic of the implementations. For 3 and 4 and most of the implementations will completely sink the solver.

My feeling is that the right answer is to give overapproximate models of the functions such that the result always includes the correctly rounded result and then to support cr_* functions from N2596 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2596.pdf from the solver up. If people care about the accuracy of their code they really should be using the correctly rounded functions.

But ... that's quite a bit of work and although it has been on my TODO for a while ... it hasn't got done yet so I guess any model is better than none.

@tautschnig tautschnig changed the title C library: add exp, log, pow approximations C library: add exp, log, pow models Sep 20, 2023
@tautschnig tautschnig force-pushed the features/math-library branch from 09fbd6a to 47321c2 Compare September 20, 2023 22:18
@tautschnig
Copy link
Collaborator Author

I have now reworked the implementations to non-deterministically pick a result that is within the margin of error of approximation. This should be closer to soundness, but the caveats that @martin-cs called out do remain.

@tautschnig tautschnig force-pushed the features/math-library branch from 47321c2 to 4abc14f Compare September 20, 2023 22:23
@tautschnig tautschnig marked this pull request as ready for review September 20, 2023 22:23
@tautschnig tautschnig removed their assignment Sep 20, 2023
@codecov
Copy link

codecov bot commented Sep 20, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (e02fd74) 78.94% compared to head (ff137ae) 78.84%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7906      +/-   ##
===========================================
- Coverage    78.94%   78.84%   -0.10%     
===========================================
  Files         1697     1697              
  Lines       195379   195379              
===========================================
- Hits        154242   154051     -191     
- Misses       41137    41328     +191     

see 22 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tautschnig tautschnig force-pushed the features/math-library branch 2 times, most recently from 5783c16 to 8c4058d Compare September 25, 2023 12:19
The implementation follows Nicol N. Schraudolph: "A Fast, Compact
Approximation of the Exponential Function," Neural Computation 11(4),
1999 and its discussion in
https://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/.
We use lower and upper bounds to retain soundness.
@tautschnig tautschnig force-pushed the features/math-library branch from 8c4058d to ff137ae Compare September 26, 2023 18:42
@feliperodri feliperodri added the aws Bugs or features of importance to AWS CBMC users label Oct 16, 2023
@kroening
Copy link
Member

There may be a need to make this produce a bigger interval, given that the standards demand very little, but let's go for this for now.

@kroening kroening merged commit 0ec6a1e into diffblue:develop Oct 27, 2023
@tautschnig tautschnig deleted the features/math-library branch October 27, 2023 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws Bugs or features of importance to AWS CBMC users Kani Bugs or features of importance to Kani Rust Verifier
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants