Skip to content

Log: a zero value gets the error of x, as in WMA - #2067

Open
tombouctou wants to merge 2 commits into
masterfrom
log-zero-precision
Open

tombouctou wants to merge 2 commits into
masterfrom
log-zero-precision

Conversation

@tombouctou

Copy link
Copy Markdown
Collaborator

Stacked on #2066 (base complex-precision), which already reworks Log. Once #2066 merges, this PR's base moves to master.

In WMA, when the value of a function is 0, its error is the change of f within the error of each argument, with the other arguments held fixed, and these changes are summed. So Log[1.`20] is 020., and Log[b, 1.20]`` has accuracy P + Log10[Abs[Log[b]]]: ``Log[2, 1.20]is019.84 and Log10[1.`20] is 020.36. The error of the base does not change a zero value: Log[2.20, 1.25]`` has accuracy 24.8408.

  • The change within an error is now the leading Taylor term c δ^p at the size of the error, as in WMA. The step is measured at δ 2^-40 and at half of that, and p is rounded to a multiple of 1/2. Before this PR the change was measured at the error itself, which is wrong at low precision. This fixes other functions too: Sin[01.5]now has accuracy 1.5 (it was 1.50007),Cos[02] 4.30103, ArcCos[1.`3] 1.34949 and Log[1.`3] 3. The test value for Accuracy[ArcCos[1.`5]] changes from 2.34948 to 2.34949, which is what WMA gives.
  • Special points of Log. Before this PR, Log[1.`20, 1.`20] raised ZeroDivisionError inside mpmath, on master as well. Now, as in WMA:
    • an inexact 0 in either argument gives Indeterminate;
    • a base that is 1, or whose error covers 1 (machine 1. included), gives ComplexInfinity, or Indeterminate when x is or covers 1 too;
    • an exact x = 1 with any other base gives an exact 0: Log[2.`20, 1] is 0.
  • MPMathFunction.special_point_value takes over the old indeterminate_at check, so a function can name its own special values; Log overrides it.

Tests are in test_log_zero_precision, next to test_real_valued_precision, and all the values come from WMA 15.

Left for later, as before this PR:

  • complex cases such as Log[1.`20 + 020 I]andLog[-1.20, 1.20]``;
  • Log[2.`20, 1.00000000000000000001`20], because the parser stores slightly different bits than WMA;
  • Log[1.`0.5], because of the shared precision < 1 guard;
  • Power of an inexact zero (Log[2, 1.`20]^2, Sqrt[03]``).

Locally, test_numbers.py, test/builtin/numbers, test/eval and the special-function tests give 1180 passed and 1 xfailed. black, isort and mypy report nothing.

🤖 Generated with Claude Code

tombouctou and others added 2 commits October 25, 2026 10:16
MATH-257, the rest of #2047 step 6 for complex numbers.

- Precision of a Complex is its accuracy (the parts' errors in
  quadrature) plus Log10 of its modulus, to which an exact part counts.
- Plus and Times on Complex numbers with exact or PrecisionReal parts
  work out each part from the real rules. Times multiplies as a balanced
  tree and squares a pair of the same number, z^n squares from the top
  bit of n, and 1/z is (a - b I)/(a^2 + b^2), as WMA does. 2.`20 I keeps
  an exact zero real part.
- A function with a complex value at real arguments (ArcSin[2.`20],
  Log[-1.`20], ArcCosh[0``20], ...) gives each part the error from that
  part of x f'[x]; a part that does not change gets 2^-54 of the error.
- A negative PrecisionReal to a Rational power: x^(1/q) shares the error
  of the whole between its parts; x^(p/q) is x^n (x^(1/q))^r.
- Log[x] no longer becomes Log[E, x], whose base added an error.
- A Complex shows an inexact zero real part; N[I, 30] is 1.`30 I.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MATH-258. Log[1.`20] is 0``20. and Log[b, 1.`20] is 0 with the accuracy
of x plus Log10[Abs[Log[b]]], as in WMA: the change of f within the
error of each argument, the others held fixed, added up. The base does
not change a zero, so Log[2.`20, 1.`25] is 0``24.84.

- A base that is 1, or whose error covers 1, gives ComplexInfinity, and
  Indeterminate when x is or covers 1 too; these raised
  ZeroDivisionError. An inexact 0 gives Indeterminate, and Log[b, 1]
  with an exact 1 is an exact 0.
- The change within an error is the leading term c delta^p of f, as in
  WMA, so Log[1.`3] is 0``3. and Sin[0``1.5] is 0``1.5 rather than
  showing the next terms.
- MPMathFunction.special_point_value takes the Indeterminate check of
  indeterminate_at, and Log adds its own points there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from complex-precision to master October 26, 2026 00:54
@rocky

rocky commented Oct 26, 2026

Copy link
Copy Markdown
Member

@tombouctou: I'd be grateful if you would handle the merge conflicts. Thanks!

This branch has not been deployed

No deployments
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.

2 participants