Repository navigation
Plus, Times with an inexact zero: carry its accuracy, as in WMA - #2058
Conversation
A follow-up to #2050 (MATH-227). - Plus: a PrecisionReal zero adds its absolute error, 10^-accuracy, as any other term does. Precision[1.5`20 + 0``10] is 10.1761 (was 10.), and a sum of zeros is a zero with the combined accuracy. - Times: a product with PrecisionReal zeros is a zero whose accuracy is the sum of theirs, less Log10 of the other factors: Accuracy[1.5`20 * 0``10] is 9.82391 (was 15.). - Times: an exact 0 times arbitrary-precision numbers is an exact 0, as in WMA (it gave 0.`15.*^-15). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
18df81a to
c93443e
Compare
|
|
||
| def _exact_or_precision_reals(numbers: Tuple[Number, ...]) -> bool: | ||
| def _exact_or_precision_reals( | ||
| numbers: Tuple[Number, ...], allow_zeros: bool = False |
There was a problem hiding this comment.
lowercase tuple please. And I guess it should be removed elsewhere in this file wherever it appears. Thanks.
There was a problem hiding this comment.
Done in 5d3395d: tuple[...] and list[...] throughout numeric.py, and the typing imports of Tuple and List are gone. The comments that named those types were updated too. mypy is clean on the file.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
As asked in review, throughout the file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
With the code in this PR, I see: In[4]:= SetAccuracy[0, 20] * 1.5`20
Out[4]= 0.×10^-20WMA 13 gives 0.10^-19. Is this correct? Possible additional pytest: @pytest.mark.parametrize(
("str_expr", "str_expected"),
[
# exact zeros that are syntactically different from the literal 0
("(1 - 1) * 1.5`20", "0"),
("(1/2 - 1/2) * 1.5`20", "0"),
("SetPrecision[0, Infinity] * 1.5`20", "0"),
# whatever the right test is for above example.
],
)
def test_exact_zero_propagates_through_equivalent_zero_forms(str_expr, str_expected):
"""An exact zero that is constructed internally must still force an exact zero."""
check_evaluation(str_expr, str_expected) |
SetAccuracy[0, 20] * 1.5`20 has accuracy 19.82 and is shown as 0.×10^-19, as in WMA. The exponent was taken from the rounded accuracy, which gave 0.×10^-20. It is never positive, so a zero with a negative accuracy shows as 0. Also adds the exact-zero tests suggested in review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Good catch — the value was right but the display was wrong. Fixed in 9081be6 (
I added your suggested test Not changed here: zeros with a small accuracy ( 🤖 Generated with Claude Code |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A follow-up to #2050 (part of #2047). Independent of #2051 and the PRs on top of it: this one is against master.
Since #2050, a sum or product that held an inexact zero took the old path. A zero's "precision" is its accuracy, and that path read it as a precision. Now, as in WMA:
Plus: a zero adds its absolute error,10^-accuracy, like any other term. A sum of zeros is a zero with the combined accuracy.Times: a product with inexact zeros is a zero. Its accuracy is the sum of theirs, minusLog10of the other factors.Times: an exact0times arbitrary-precision numbers is an exact0.Precision[1.5`20 + 010]``10.10.176110.1761Precision[010 + 2]``10.10.30110.301Precision[10^-10 + 030]``30.20.20.Accuracy[010 + 020]15.10.10.Accuracy[1.5`20 - 1.5`20 + 030]``15.19.522919.5229Accuracy[1.5`20 * 010]``15.9.823919.82391Accuracy[010 * 020]15.30.30.0 * 1.5`200.`15.*^-1500Tests
test_inexact_zero_plus_timesintest/builtin/atomic/test_numbers.py, with WMA 15 values. Full run on kimmy: doctests all pass. The pytest failures are the ones that depend on the order the tests run in; the failing files that touch numbers pass on their own.🤖 Generated with Claude Code