Skip to content

Read a power's domain condition over the reals and off the real line - #2747

Merged
Rafael-SOWNet merged 4 commits into
masterfrom
fix-2739-2740-power-domain-condition
Dec 6, 2026
Merged

Rafael-SOWNet merged 4 commits into
masterfrom
fix-2739-2740-power-domain-condition

Conversation

@Rafael-SOWNet

@Rafael-SOWNet Rafael-SOWNet commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

What was wrong

The fix

  • A negative base has a real power only where the exponent is a whole number, or a fraction of odd denominator below 10, whose real root the library takes. The condition now restricts the base for every other exponent:
    • any other number gets x >= 0;
    • a symbolic exponent e gets x >= 0 or 5e in ZZ or 7e in ZZ or 9e in ZZ. Those are exactly the fractions whose denominator divides 5, 7 or 9, so the condition matches the values and is no stricter than them.
  • Off the real line the zero-base part is Re(w) > 0, as Zero times a power with a non-real exponent is NaN #1865 already did for a constant exponent. The incomplete gamma function's condition at a lower limit of 0 gets the same change.
  • Simplify(0^x) wrote its condition as x (1 + 1/sgn(x)^2) > 0, which has no value at 0. It is now Re(x) > 0.
  • PredicateEntailment now reads through Re, so x^x provided not x = 0 still simplifies to x ^ x.

What I measured (master 9b75a26 against this branch)

  • domaincheck, rows where the real condition holds but the real reading has no value:
    • random compositions: 98 → 9. The 9 left are lambertw at -1/e and one polygamma row, neither a power.
    • listed nodes: 4 → 2.
    • rows where the condition fails but the reading has a value: 105 and 6 on both builds.
    • the complex-reading sections are unchanged apart from the printed Re.
  • The domain sweep's rows, asked again on both builds:
    • 18383 real-reading rows: 263 too loose and 63 undecided become right; none newly wrong.
    • 76513 complex-reading rows: 106 undecided become right; none newly wrong.
  • A generated set of 69 zero-base points with a non-real exponent:
    • master leaves 59 undecided, the branch decides all 69;
    • none disagrees with the library's value;
    • where it is 0, Re(w) > 0, checked with mpmath.
  • CasBench, RootCheck, SimpSweep, PropCheck and BoundCheck give the same results on both builds.
  • UnitTests: 22399 passed, 0 failed. FSharpWrapperUnitTests: 135 passed.
  • The new tests fail on master in 17 rows.

Allocation (kernel benchmark cases, bytes per operation, two interleaved runs each, the same in both)

The first head allocated more for every power over a symbolic or rational exponent. Each power node built a fresh Re(w) > 0 and simplified it from the start, and Re(-1/2) was wrapped around an exponent that is already real. Now a real number is its own real part and stays unwrapped, and the simplified Re(w) > 0 is kept per exponent instance under the settings it was simplified in.

master 8b4f507 first head 4629217 (on 9b75a26) now
Derivate 24,624 25,656 (+4.2%) 24,624 (0.0%)
SimplifyHard 135,008,161 147,012,144 (+8.9%) 133,758,452 (-0.9%)
SimplifyEasy 28,824 unchanged 28,824

No answer changed from the first head. 560 domain, simplify and derivative inputs over powers with symbolic, complex and real exponents print the same on both builds, under the complex and the real codomain.

CanonCheck: 0 findings appeared and 12 went away, and they are recorded in canoncheck-baseline.tsv. All 12 are CanonicalOrderExact idempotence findings on 0 ^ y and its relatives: 0 ^ y, 0 ^ x, 0 ^ a, -0 ^ y, (0 ^ y) ^ 2, abs(0 ^ y), cos(0 ^ y), sin(0 ^ y), sgn(0 ^ y), sqrt(0 ^ y), ln(0 ^ y), e ^ 0 ^ y. Each used to normalise to 0 provided y / 2 * (1 + 1 / sgn(y) ^ 2) > 0, and a second sort rearranged that product again. Each now normalises to 0 provided Re(y) > 0, which a second sort leaves alone.

After merging master 8b4f507: UnitTests 22574 passed, 0 failed. SimpSweep 10463/10463 agree. BoundCheck 0 disagreements. PropCheck passes. CanonCheck matches the updated baseline (2028 findings).

Fixes #2739
Fixes #2740

🤖 Generated with Claude Code

Over the reals a negative base has a real power only where the exponent
is a whole number or a fraction of odd denominator below 10, whose real
root the library takes. Powf.IntrinsicCondition restricted the base only
for a literal even root, so x^pi, x^x and (-1)^x were taken as defined
where their real reading is NaN, and x^(1/11) too, whose principal root
is not real. The condition is now x >= 0 for any other number, and for a
symbolic exponent e it names the fractions the real root is taken for:
x >= 0 or 5e in ZZ or 7e in ZZ or 9e in ZZ, the numbers whose
denominator divides 5, 7 or 9. That is exactly the library's set, so the
condition is not stricter than the values.

Off the real line the zero-base part said w > 0 for an exponent that is
not a number, which has no value at a non-real w: domain(0^x) was NaN
at 1 + i, where 0^(1 + i) is 0. It reads Re(w) > 0 now, as #1865 did for
a constant exponent, and so does the incomplete gamma function's
condition at a lower limit of 0. Simplify(0^x) wrote its condition as
x (1 + 1/sgn(x)^2) > 0, which had no value at 0; it writes Re(x) > 0.
PredicateEntailment reads through Re so x^x provided not x = 0 still
drops its redundant condition.

Measured on 9b75a26 and this branch: domaincheck's real "holds where
the real reading has no value" goes from 98 to 9 in random compositions
(the 9 left are lambertw at -1/e and a polygamma row) and from 4 to 2 in
the listed nodes, with "fails where it has a value" unchanged (105, 6).
The sweep's 18383 real-reading rows: 263 too loose and 63 undecided
become right, none newly wrong; its 76513 complex rows: 106 undecided
become right, none newly wrong. CasBench, RootCheck, SimpSweep,
PropCheck and BoundCheck agree on both. Unit suite 22399 passed, 0
failed; the new tests fail on master in 17 rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.71%. Comparing base (8b4f507) to head (1c5e0f2).

Files with missing lines Patch % Lines
...nuous/Evaluation.Continuous.Arithmetics.Classes.cs 94.11% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2747   +/-   ##
=======================================
  Coverage   86.70%   86.71%           
=======================================
  Files         347      347           
  Lines       77376    77387   +11     
  Branches    22783    22786    +3     
=======================================
+ Hits        67089    67103   +14     
+ Misses       5546     5543    -3     
  Partials     4741     4741           
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.19% <94.73%> (+<0.01%) ⬆️
fsharp 32.79% <ø> (ø)
interactive 40.09% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...urces/AngouriMath/Functions/PredicateEntailment.cs 87.85% <100.00%> (+0.23%) ⬆️
...nuous/Evaluation.Continuous.Arithmetics.Classes.cs 87.68% <94.11%> (+0.30%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Rafael-SOWNet and others added 3 commits December 6, 2026 16:35
…onent unwrapped

The condition 0^w needs, Re(w) > 0, was built afresh for every power node
and simplified from the start: carried through a sum, each part asked
whether it is real. A simplification builds many powers over one exponent,
so the kernel benchmark's SimplifyHard allocated 8.9% more, and Derivate
4.2% more from Re(-1/2) around an exponent that is already a real number.

A real number is now its own real part, unwrapped, and the simplified
Re(w) > 0 is kept per exponent instance in a ConditionalWeakTable, under
the settings it was simplified in, as a node's own simplification is.

Allocated bytes per operation, base 9b75a26 against this branch, two
interleaved runs each, identical in both runs:
  Derivate      24,624 -> 24,624 B (PR head before this: 25,656)
  SimplifyHard  134,975,155 -> 133,718,291 B, -0.9% (PR head: 147,012,144)

No answer changes: 560 domain, simplify and derivative inputs over powers
with symbolic, complex and real exponents print the same on the PR head
and on this commit, under the complex and the real codomain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each was 0^y under a function, whose normalisation was
0 provided y / 2 * (1 + 1 / sgn(y) ^ 2) > 0; the canonical order rearranged
that product again when applied a second time. It is now
0 provided Re(y) > 0, which a second sort leaves as it is. 0 appeared.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Rafael-SOWNet
Rafael-SOWNet merged commit c100d85 into master Dec 6, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Dec 6, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the fix-2739-2740-power-domain-condition branch December 6, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

1 participant