Skip to content

Keep ln and the inverse trigonometric functions in their range when inverting them, and (e^a)^c = e^(ac) for a real a only - #2750

Open
Rafael-SOWNet wants to merge 1 commit into
masterfrom
fix-2713-ln-arctan-principal-range
Open

Rafael-SOWNet wants to merge 1 commit into
masterfrom
fix-2713-ln-arctan-principal-range

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Inverting ln and arctan ignored their range off the real line, and (a^b)^c = a^(bc) was applied for a positive a and any b. Every real answer was right. The wrong members were complex.

What changed

  • ln(x) = w (and log(a, x), log(x, a)): the root now carries -pi < Im(w) <= pi. On a line a n + b in a solve parameter, the condition is decided once where it does not depend on n: a real slope gives Im(b), and a slope that divides 2 pi i repeats one member. So sin(ln(x)) = 0 and e^(ln(x)) = 2 are unchanged.
  • arctan, arccotan, arcsin, arccos: a non-numeric value carries the range, measured on the evaluator. arctan(2i) = pi/2 + 0.549i, arctan(-2i) = -pi/2 - 0.549i, arccotan(0.5i) = -pi/2 - 0.549i, arccotan(0) = pi/2, arcsin(±2) = ±pi/2 - 1.317i, arccos(2) = 1.317i, arccos(-2) = pi + 1.317i. A value that is a line in a solve parameter (pi/4 + pi n) is left as it was, because that case is Solving f(arcsin(x)), f(arccos(x)) or f(arctan(x)) = c keeps roots outside the inverse function's range: tan(arcsin(x)) = 1 gives sin(pi/4 + pi n) #2711.
  • (a^b)^c = a^(bc): now needs a whole c, or a > 0 with b real. MayMultiplyExponents sits in Patterns.Power.cs, and the switch arm, both MatchedRules spellings and the factor reader Decompose all ask it. Over the reals (Codomain = Real) it fires as before.

Before/after, checked with mpmath (dps 50)

input master branch mpmath at the old member
e^(ln(x)^2) = 1 e^(±sqrt(2 pi i n)) same, each provided -pi < Im(…) <= pi n = 5: e^(ln(x)^2) - 1 = 27337.4 + 13573.5i; n = 1: 0 (kept)
abs(arctan(x)) = 2 tan(2 e^(i r)) … and (-pi/2 < 2 Re(e^(i r)) < pi/2 or edges) r = 0.3: `
ln(x) = a e^a e^a provided -pi < Im(a) <= pi a = 1 + 4i: ln(e^a) = 1 - 2.283i
log(b, x) = 2 b^2 b^2 provided -pi < 2 Im(ln b) <= pi b = -1: log(-1, 1) = 0
sqrt(e^(2x)) e^x unchanged x = 2.1 - 1.7i: 1.052 + 8.098i vs e^x = -1.052 - 8.098i
(e^(2x))^(1/4) e^(x/2) unchanged same point: 2.147 + 1.886i vs 1.886 - 2.147i
sqrt(2^x) 2^(x/2) unchanged x = 1 + 10i: 1.341 + 0.450i vs the negation

The sweep checker (class F of the solve sweep, plus 106 variants: ln(x)^k, ln(x+1), ln(2x), log(2,x), abs(arc…), e^(arctan(x)^2), simplify of powers of exponentials)

Across the sweep's 5933 solve and simplify rows, 64 answers changed. All of them are the added conditions or the 9 power-of-power simplifications listed above. No real root changed.

Harnesses, before → after: RootCheck 596/596 clean → same; CasBench 120/121, 0 wrong → same; SimpSweep 10463/10463 agree → same; CanonCheck findings match the baseline (2040) → same. The reports are identical apart from timings.

Unit suite: 22349 passed, 0 failed. Two pinned answers changed, and both were wrong: log(b, x) = 2 and the agreement test's (2^x)^(1/2) "fires".

Overlap with #2711: both edit the Arc*f.InvertNode lines. Here each Argument.Invert(...) is wrapped in WithinItsValues(...), and #2711 puts InvertWithin(...) ?? in front. The conflict is mechanical: keep both.

Fixes #2713

🤖 Generated with Claude Code

…nverting them, and (e^a)^c = e^(ac) for a real a only

ln(x) = w has a root only where Im(w) is in (-pi, pi], and arctan(x) = w only
where w is a value of arctan: Re in (-pi/2, pi/2), or pi/2 above the real line and
-pi/2 below it, where the cuts land (arctan(2i) = pi/2 + 0.549i). The inversions
answered e^w and tan(w) for every w, so e^(ln(x)^2) = 1 listed e^sqrt(10 pi i), where
e^(ln(x)^2) - 1 is 27337 + 13573i, and abs(arctan(x)) = 2 listed tan(2 e^(i r)) at
r = 0.3, where |arctan| is 1.365. A value that is not a number now carries the
condition. On a line a n + b in a parameter the strip is decided once where it does
not depend on n (sin(ln(x)) = 0 is unchanged); a line through an inverse
trigonometric function is #2711's and is left as it was. arcsin, arccos and
arccotan carry their ranges the same way, measured on the evaluator.

(a^b)^c = a^(bc) holds for a whole c, or where ln(a^b) is b ln(a), which needs a
positive and b real. It was applied for any b, so sqrt(e^(2x)) was e^x, the negative
of the value at x = 2.1 - 1.7i. Both spellings of the rule and the factor reader ask
one predicate now; over the reals it fires as before.

Two tests pinned the old answers: log(b, x) = 2 was { b ^ 2 }, which is wrong at
b = -1 (log(-1, 1) is 0), and the agreement test listed (2^x)^(1/2) as firing.

Fixes #2713

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

codecov Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.65%. Comparing base (409d688) to head (6ed6e39).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2750      +/-   ##
==========================================
- Coverage   86.65%   86.65%   -0.01%     
==========================================
  Files         346      346              
  Lines       76959    76943      -16     
  Branches    22644    22637       -7     
==========================================
- Hits        66692    66678      -14     
  Misses       5534     5534              
+ Partials     4733     4731       -2     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
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 Δ
...Math/Core/Transformations/Matching/MatchedRules.cs 99.42% <ø> (-0.01%) ⬇️
...nuous/Solvers/EquationSolver/InvertNode.Classes.cs 62.28% <ø> (-0.08%) ⬇️
...unctions/Simplification/Patterns/Patterns.Power.cs 92.02% <ø> (-0.09%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Status: Todo

Development

Successfully merging this pull request may close these issues.

Inverting ln or arctan, and simplifying sqrt(e^(2x)), ignore the principal range off the real line

1 participant