Repository navigation
Log: precision from the condition number, as in WMA - #2053
Conversation
a1e9eb3 to
adf3b06
Compare
2632889 to
d6da960
Compare
| return lambda base, x: mpmath.log(x, base) | ||
|
|
||
| @staticmethod | ||
| def condition_numbers(base, x, value): |
There was a problem hiding this comment.
Would the return type annotation be tuple[float, float]? Can we say anything about the types of base, x, or value?
There was a problem hiding this comment.
Done in f4b3c83. The arguments and the value are mpmath.mpf: the helper converts the numbers at the working precision before it calls this. The result is tuple[mpmath.mpf, mpmath.mpf], not floats. The factors are only used through Log10, but they can be far below the float range: for Tanh[10.`20^6] the factor is about E^-2000000. As a float that would be 0., which reads as "this argument adds no error", so they stay mpmath numbers.
I typed the hook the same way in #2052 (Callable[..., tuple[mpmath.mpf, ...]], with that reason in its comment), and added the annotations to the formulas in #2054–#2056 too. mypy is clean on these files.
d6da960 to
f7d8f32
Compare
Part of step 6 of #2047 (MATH-227), on top of the Power PR. Log[b, x] is Log[x] / Log[b], so the relative errors of b and x are multiplied by 1/Abs[Log[b]] and 1/Abs[Log[x]]. Log[x], Log2 and Log10 go through Log[b, x]; Exp[x] is E^x and is already covered by Power. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
As asked in review: mpmath numbers in and out, as for Power. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7a6e2b4 to
5ff0c56
Compare
f7d8f32 to
f4b3c83
Compare
|
LGTM. Feel free to merge when CI finishes. |
Part of step 6 of the outline in #2047. On top of #2052 (and #2051): this diff is against #2052's branch.
Loggets its precision from the condition number, as WMA does.Log[b, x]isLog[x] / Log[b], so the relative errors ofbandxare multiplied by1/Abs[Log[b]]and1/Abs[Log[x]].Log[x]goes throughLog[E, x], andLog2,Log10throughLog[b, x]. The change itself is thecondition_numbersofLog, as #2052 sets out.Precision[Log[1.5`20]]20.19.60819.608Precision[Log[1.0000001`20]]20.13.13.Precision[Log[100.`20]]20.20.663220.6632Precision[Log[2.`20, 1.5`30]]20.19.840819.8408Precision[Log10[1.5`20]]20.19.60819.608Not changed: a
Logthat comes out as zero, likeLog[1.`20], keeps the path it took before (0.`15.*^-15; WMA gives020.``). The rule here needs a nonzero value.Tests
test_log_real_valued_precisionintest/builtin/atomic/test_numbers.py, with WMA 15 values. Full run on kimmy: doctests all pass. The pytest failures are the order-dependent ones; the failing file that touches numbers (test_diffeqns.py) passes on its own.🤖 Generated with Claude Code