Skip to content

Commit 5110f4c

Browse files
LambertW over the reals is defined where its branch is real (#2263)
lambertw's condition was the complex one under either reading: every whole branch, and every z but 0 off the principal one. So DomainConditionIn(Domain.Real) of lambertw(0, x) was True, though W_0(-1) is -0.318 + 1.337i. Over the reals the condition is now where the branch is real: W_0 for z >= -1/e, W_(-1) for -1/e <= z < 0, both -1 at -1/e, and no other branch anywhere. The complex condition is unchanged. LambertWOverTheRealsTest takes three branches at twelve real points over the reals, and three over the complex numbers; five fail on master. lambertw is new since 2.6.0, so no answer changes against it. Found by work/domaincheck. Part of #2256. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 6d2a960 commit 5110f4c

3 files changed

Lines changed: 64 additions & 1 deletion

File tree

‎Sources/.editorconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
264264
[Tests/UnitTests/Convenience/MatrixFunctionsInAnExpressionTest.cs]
265265
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
266266

267+
[Tests/UnitTests/Convenience/LambertWOverTheRealsTest.cs]
268+
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
269+
267270
[Tests/UnitTests/Common/ExponentialOfALogarithmTest.cs]
268271
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
269272

‎Sources/AngouriMath/Functions/Evaluation/Evaluation.Continuous/Evaluation.Continuous.Arithmetics.Classes.cs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,14 @@ private static Entity Numerically(Complex n, int m)
761761
public partial record LambertWf
762762
{
763763
// Every whole branch, and every z but 0 off the principal branch, where W_k(z) goes to -oo as ln z does.
764+
// Over the reals, where a branch is real: W_0 for z >= -1/e and W_(-1) for -1/e <= z < 0, both -1 at
765+
// -1/e; no other branch is real anywhere. The condition was the complex one under either reading, so it
766+
// held for W_0(-1), which is -0.318 + 1.337i. https://github.com/asc-community/AngouriMath/issues/2256
764767
private protected override Entity IntrinsicCondition =>
765-
Branch.In(MathS.Sets.Z) & (Branch.Equalizes(Integer.Zero) | !Argument.Equalizes(Integer.Zero));
768+
Codomain < Domain.Complex
769+
? Branch.Equalizes(Integer.Zero) & Argument >= -1 / MathS.e
770+
| Branch.Equalizes(Integer.Create(-1)) & Argument >= -1 / MathS.e & Argument < 0
771+
: Branch.In(MathS.Sets.Z) & (Branch.Equalizes(Integer.Zero) | !Argument.Equalizes(Integer.Zero));
766772

767773
/// <inheritdoc/>
768774
protected override Entity InnerSimplify(bool isExact) =>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// Copyright (c) 2019-2026 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using AngouriMath;
9+
using AngouriMath.Core;
10+
using AngouriMath.Extensions;
11+
using Xunit;
12+
13+
namespace AngouriMath.Tests.Convenience
14+
{
15+
/// <summary>
16+
/// Over the reals the Lambert W function is defined where its branch is real: <c>W_0</c> for <c>z &gt;= -1/e</c> and
17+
/// <c>W_(-1)</c> for <c>-1/e &lt;= z &lt; 0</c>. The condition was the complex one under either reading, so it held for
18+
/// <c>W_0(-1)</c>, which is <c>-0.318 + 1.337i</c>.
19+
/// <a href="https://github.com/asc-community/AngouriMath/issues/2256">#2256</a>
20+
/// </summary>
21+
[Trait("Area", "Convenience")]
22+
public sealed class LambertWOverTheRealsTest
23+
{
24+
[Theory]
25+
[InlineData("lambertw(0, x)", "-3", false)]
26+
[InlineData("lambertw(0, x)", "-1", false)]
27+
[InlineData("lambertw(0, x)", "-1/e", true)]
28+
[InlineData("lambertw(0, x)", "-1/5", true)]
29+
[InlineData("lambertw(0, x)", "0", true)]
30+
[InlineData("lambertw(0, x)", "2", true)]
31+
[InlineData("lambertw(-1, x)", "-1/e", true)]
32+
[InlineData("lambertw(-1, x)", "-1/5", true)]
33+
[InlineData("lambertw(-1, x)", "-1/2", false)]
34+
[InlineData("lambertw(-1, x)", "0", false)]
35+
[InlineData("lambertw(-1, x)", "1", false)]
36+
[InlineData("lambertw(1, x)", "1", false)]
37+
public void OverTheRealsItIsWhereItsBranchIsReal(string expression, string at, bool defined)
38+
{
39+
var condition = expression.ToEntity().DomainConditionIn(Domain.Real).Substitute("x", at.ToEntity()).Evaled;
40+
Assert.Equal(defined ? Entity.Boolean.True : Entity.Boolean.False, condition);
41+
}
42+
43+
/// <summary>Over the complex numbers every branch is defined but off the principal one at 0.</summary>
44+
[Theory]
45+
[InlineData("lambertw(0, x)", "-3", true)]
46+
[InlineData("lambertw(-1, x)", "1", true)]
47+
[InlineData("lambertw(-1, x)", "0", false)]
48+
public void OverTheComplexNumbersItIsAsItWas(string expression, string at, bool defined)
49+
{
50+
var condition = expression.ToEntity().DomainCondition.Substitute("x", at.ToEntity()).Evaled;
51+
Assert.Equal(defined ? Entity.Boolean.True : Entity.Boolean.False, condition);
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)