Skip to content

Commit 97596b8

Browse files
Rafael-SOWNetclaude
andcommitted
A number's conjugate is made under the setting in force
Complex.Conjugate was kept on the instance, made by Complex.Create under whatever downcasting setting its first caller had. A division by a complex number conjugates the divisor, so a division by i with the downcasting off left 0 - 1i, in decimals, as the conjugate of Complex.ImaginaryOne, the one instance every i is. conj(i) was that for every caller after it, in every thread. Two tests on #2190's branch failed in the full suite and passed alone: conj(i) against -i, and MathS.Conjugate's documented example. Which ran first decided it. The conjugate is now made each time it is asked for, under the setting in force, as every other number is: the division that asks for it reads the modulus the same way (#1615). A regression test divides by i with the downcasting off first; it fails without the change, with 0 - 1i. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
1 parent 3f6c444 commit 97596b8

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,16 @@ Both are real, `im(3 + 4i)` being `4`, real-linear, and turned by the conjugate
319319
| `"im(3 + 4i)".ToEntity().Simplify()` | `(3 + 4i) * im` | `4` |
320320
| `"re * x".ToEntity()` | `re * x` | `re * x` |
321321

322+
### A number's conjugate is made under the setting in force
323+
324+
**Silent: `Complex.Conjugate` is made under the downcasting setting of the caller, where the first caller's setting was
325+
kept on the number for every caller after it.** A division by `i` with the downcasting off conjugates `i`, and left its
326+
conjugate as `0 - 1i`, in decimals, on the one instance that every `i` is, in every thread from then on.
327+
328+
| Input | Was (2.6.0) | Now |
329+
|---|---|---|
330+
| `Complex.ImaginaryOne.Conjugate`, after `(1 / Complex.ImaginaryOne).Evaled` with `DowncastingEnabled` off | `0 - 1i` | `-i` |
331+
322332
### `conjugate`, `conj` and `arg` are functions
323333

324334
**Not silent: these names followed by a bracket are now the complex conjugate and the principal argument, where they

‎Sources/AngouriMath/Core/Entity/Continuous/Entity.Continuous.Complex.Definition.cs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ private protected Complex(Real? real, Real? imaginary) =>
4040
/// <summary>
4141
/// Conjugate of a complex number. Given this = a + ib, Conjugate = a - ib
4242
/// </summary>
43-
public Complex Conjugate => conjugate.GetValue(static @this => Create(@this.RealPart, -@this.ImaginaryPart), this);
44-
private LazyPropertyA<Complex> conjugate;
43+
/// <remarks>
44+
/// Made under the downcasting setting in force, as any other number is, and so not kept
45+
/// on the instance: the first to ask decided it for everyone. A division by <c>i</c> with
46+
/// the downcasting off left <c>0 - 1i</c>, in decimals, on <see cref="ImaginaryOne"/>, and
47+
/// <c>conj(i)</c> was that from then on, in every thread.
48+
/// </remarks>
49+
public Complex Conjugate => Create(RealPart, -ImaginaryPart);
4550

4651
internal override Priority Priority =>
4752
(RealPart, ImaginaryPart) switch

‎Sources/Tests/UnitTests/Core/Numeric.cs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,5 +458,20 @@ public void AModulusIsMadeUnderTheDowncastingInForce()
458458
Assert.Equal(Integer.Create(325), Complex.Create(EDecimal.FromInt32(75), rootOf100000).Abs());
459459
}
460460
}
461+
462+
/// <summary>
463+
/// A conjugate is made under the setting in force, as every other number is. It was kept on
464+
/// the instance, so a division by <c>i</c> with the downcasting off left <c>0 - 1i</c>, in
465+
/// decimals, as the conjugate of <see cref="Complex.ImaginaryOne"/>, and <c>conj(i)</c> was
466+
/// that for every caller after it: two tests failed or passed by the order the suite ran in.
467+
/// </summary>
468+
[Fact]
469+
public void AConjugateIsMadeUnderTheSettingInForce()
470+
{
471+
using (MathS.Settings.DowncastingEnabled.Set(false))
472+
Assert.IsType<Complex>((1 / Complex.ImaginaryOne).Evaled);
473+
Assert.Equal(Complex.MinusImaginaryOne, Complex.ImaginaryOne.Conjugate);
474+
Assert.Equal(Complex.MinusImaginaryOne, "conj(i)".ToEntity().InnerSimplified);
475+
}
461476
}
462477
}

0 commit comments

Comments
 (0)