Skip to content

Commit c09055f

Browse files
Give the quantum factorisation a name that does not collide (#843) (#844)
MathS.Quantum.Factorise differed by one letter from Entity.Factorize, which does something else entirely -- algebraic factoring of an expression against tensor factorisation of a quantum state. Both take an Entity and return an Entity, so the name was all that distinguished them. Renaming it to Factorize would have made the spelling uniform and the API worse. MathS.Quantum already holds the inverse as TensorExpand, so TensorFactorize states the domain and the direction and pairs with its inverse. MathS.Quantum.IsNormalised becomes IsNormalized in the same pass: auditing the recorded public surface turned it up, and it is public, so 2.0 is equally the last release that can change it. The internal Factorisation class becomes Factorization. AsymptoticSeries has a private Normalised that is deliberately left alone, since private names carry no deadline. The public surface now has one spelling throughout, and PublicApi.txt is the check: it contains no -ise, -ised or -isation member.
1 parent 4eb9445 commit c09055f

5 files changed

Lines changed: 64 additions & 37 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ read first.
5353
| loud | `round(x)`, `min(a, b)`, `max(a, b)`, `gcd(a, b)` | `UnrecognizedFunctionParseException` | the functions |
5454
| loud | 28 members deprecated since 1.x | obsolete but present | removed |
5555
| loud | `Latexise`, `ILatexiseable`, `entity_latexise` | the British spelling | `Latexize`, `ILatexizeable`, `entity_latexize` |
56+
| loud | `MathS.Quantum.Factorise` | one letter from the unrelated `Entity.Factorize` | `MathS.Quantum.TensorFactorize` |
57+
| loud | `MathS.Quantum.IsNormalised` | the British spelling | `MathS.Quantum.IsNormalized` |
5658
| loud | the target frameworks | `net7.0;netstandard2.0` | `netstandard2.0;net8.0;net10.0` |
5759
| **silent** | `abs(x) = c` for a negative `c` | a set of non-solutions | the empty set |
5860

@@ -144,17 +146,42 @@ forwarding member: this release is the one that removed 28 members that accumula
144146
so adding a permanent one here would undo that on the same day. The compiler reports each site, and
145147
the fix is mechanical.
146148

147-
`MathS.Quantum.Factorise` keeps its spelling for now. Renaming it to `Factorize` would give the
148-
library two public `Factorize` methods doing unrelated things — expression factoring on `Entity`,
149-
tensor factorisation on a quantum state — which is a worse outcome than the inconsistency. It wants
150-
a distinguishing name rather than a spelling change, and that is not decided here.
151-
152149
**Downstream.** [`CSharpMath.Evaluation`](https://github.com/verybadcat/CSharpMath) reads LaTeX
153150
produced here back into an `Entity` and calls this method. It is unaffected until it moves to 2.0,
154151
at which point it needs the new name.
155152

156153
[#840](https://github.com/asc-community/AngouriMath/issues/840).
157154

155+
### `MathS.Quantum.Factorise` is now `MathS.Quantum.TensorFactorize`
156+
157+
| | was | is |
158+
|---|---|---|
159+
| the method | `MathS.Quantum.Factorise(Entity)` | `MathS.Quantum.TensorFactorize(Entity)` |
160+
161+
The old name differed by one letter from `Entity.Factorize`, which does something else entirely —
162+
algebraic factoring of an expression, against tensor factorisation of a quantum state. Both take an
163+
`Entity` and return an `Entity`, so nothing but the name distinguished them, and the name barely
164+
did.
165+
166+
Renaming it to `Factorize` would have made the spelling uniform and the API worse: two public
167+
`Factorize` methods doing unrelated things. `MathS.Quantum` already holds the inverse operation as
168+
`TensorExpand`, so `TensorFactorize` states the domain and the direction, pairs with its inverse,
169+
and ends the collision. The spelling is fixed as a side effect rather than as the point.
170+
171+
**What breaks.** Every call to `MathS.Quantum.Factorise`. There is no forwarding member, for the
172+
same reason as above. The compiler reports each site.
173+
174+
`MathS.Quantum.IsNormalised` is renamed to `IsNormalized` in the same pass. It carries no collision,
175+
only the spelling — but it is a public member, so 2.0 is equally the last release that can change
176+
it, and leaving it would have meant shipping one British member after two renames made expressly to
177+
remove them.
178+
179+
With these two, the public surface has one spelling throughout. That is checkable rather than
180+
asserted: `PublicApi.txt` is the recorded surface, and it now contains no `-ise`, `-ised` or
181+
`-isation` member.
182+
183+
[#843](https://github.com/asc-community/AngouriMath/issues/843).
184+
158185
---
159186

160187
## Parsing

‎Sources/AngouriMath/Convenience/MathS.cs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6867,30 +6867,30 @@ public static Entity Ket(params int[] qubits)
68676867
/// all, and a product state such as <c>(|0&gt;+|1&gt;)(|0&gt;+|1&gt;)</c>, whose
68686868
/// separability this does not yet detect.
68696869
/// </remarks>
6870-
public static Entity Factorise(Entity state)
6871-
=> Functions.Quantum.Factorisation.Factorise(state) ?? state;
6870+
public static Entity TensorFactorize(Entity state)
6871+
=> Functions.Quantum.Factorization.TensorFactorize(state) ?? state;
68726872

68736873
/// <summary>
68746874
/// A product of states over consecutive qubits multiplied back out into a single
6875-
/// superposition -- the inverse of <c>Factorise</c> -- or the expression unchanged
6875+
/// superposition -- the inverse of <c>TensorFactorize</c> -- or the expression unchanged
68766876
/// where it is not such a product.
68776877
/// </summary>
68786878
public static Entity TensorExpand(Entity state)
6879-
=> Functions.Quantum.Factorisation.TensorExpand(state) ?? state;
6879+
=> Functions.Quantum.Factorization.TensorExpand(state) ?? state;
68806880

68816881
/// <summary>
68826882
/// Whether the amplitudes square-sum to one, or <see langword="null"/> where that
68836883
/// cannot be settled -- a symbolic amplitude need not have a decidable modulus.
68846884
/// </summary>
6885-
public static bool? IsNormalised(Entity state)
6886-
=> Functions.Quantum.Factorisation.IsNormalised(state);
6885+
public static bool? IsNormalized(Entity state)
6886+
=> Functions.Quantum.Factorization.IsNormalized(state);
68876887

68886888
/// <summary>
68896889
/// Whether two states differ only by a global phase, which is the difference no
68906890
/// measurement can see -- or <see langword="null"/> where that cannot be settled.
68916891
/// </summary>
68926892
public static bool? EqualUpToGlobalPhase(Entity left, Entity right)
6893-
=> Functions.Quantum.Factorisation.EqualUpToGlobalPhase(left, right);
6893+
=> Functions.Quantum.Factorization.EqualUpToGlobalPhase(left, right);
68946894
}
68956895

68966896
/// <summary>

Sources/AngouriMath/Functions/Quantum/Factorisation.cs renamed to Sources/AngouriMath/Functions/Quantum/Factorization.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ namespace AngouriMath.Functions.Quantum
3535
/// is a rank-one test on the amplitudes across a bipartition -- a different algorithm,
3636
/// belonging to this file rather than to the spine, and not written yet.
3737
/// </remarks>
38-
internal static class Factorisation
38+
internal static class Factorization
3939
{
4040
/// <summary>
4141
/// The state rewritten as a product, or <see langword="null"/> where it is not a state
4242
/// or has no qubit in a definite basis state at either end.
4343
/// </summary>
44-
internal static Entity? Factorise(Entity expr)
44+
internal static Entity? TensorFactorize(Entity expr)
4545
{
4646
if (QuantumState.TryRead(expr) is not { } state || state.IsEmpty)
4747
return null;
@@ -76,7 +76,7 @@ internal static class Factorisation
7676
/// superposition, or <see langword="null"/> where the expression is not such a product.
7777
/// </summary>
7878
/// <remarks>
79-
/// The inverse of <see cref="Factorise"/>, and the reason it is here rather than on the
79+
/// The inverse of <see cref="TensorFactorize"/>, and the reason it is here rather than on the
8080
/// spine: within one state the qubits are a fixed width and combining two kets overlays
8181
/// them, while a *product* of states concatenates their widths. Those are two different
8282
/// monoids on the same type, and only the first is what
@@ -143,7 +143,7 @@ private static SparseTerms<Ket> Slice(SparseTerms<Ket> state, int from, int to)
143143
/// the library. Left to <c>Simplify</c> to settle rather than evaluated numerically,
144144
/// so <c>1/sqrt(2)</c> is recognised exactly.
145145
/// </remarks>
146-
internal static bool? IsNormalised(Entity expr)
146+
internal static bool? IsNormalized(Entity expr)
147147
{
148148
if (QuantumState.TryRead(expr) is not { } state || state.IsEmpty)
149149
return null;

‎Sources/Tests/UnitTests/Algebra/QuantumStateTest.cs‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ public void OppositeAmplitudesCancel() =>
5757

5858
[Theory]
5959
[InlineData(true)]
60-
public void TheStandardStatesAreNormalised(bool _)
60+
public void TheStandardStatesAreNormalized(bool _)
6161
{
62-
Assert.True(MathS.Quantum.IsNormalised(Bell));
63-
Assert.True(MathS.Quantum.IsNormalised(Product));
64-
Assert.True(MathS.Quantum.IsNormalised(Ghz));
65-
Assert.True(MathS.Quantum.IsNormalised(Ket(0, 1)));
62+
Assert.True(MathS.Quantum.IsNormalized(Bell));
63+
Assert.True(MathS.Quantum.IsNormalized(Product));
64+
Assert.True(MathS.Quantum.IsNormalized(Ghz));
65+
Assert.True(MathS.Quantum.IsNormalized(Ket(0, 1)));
6666
}
6767

6868
/// <summary>
@@ -73,23 +73,23 @@ public void TheStandardStatesAreNormalised(bool _)
7373
[Fact]
7474
public void AnAmplitudeInFrontIsReadTheSameAsADivisor()
7575
{
76-
Assert.True(MathS.Quantum.IsNormalised(1 / Sqrt2 * (Ket(0, 0) + Ket(1, 1))));
76+
Assert.True(MathS.Quantum.IsNormalized(1 / Sqrt2 * (Ket(0, 0) + Ket(1, 1))));
7777
AssertSame(Ket(0) * (Ket(0) + Ket(1)) * 2,
78-
MathS.Quantum.Factorise(2 * (Ket(0, 0) + Ket(0, 1))));
78+
MathS.Quantum.TensorFactorize(2 * (Ket(0, 0) + Ket(0, 1))));
7979
}
8080

8181
[Fact]
82-
public void AnUnnormalisedStateIsNotNormalised()
82+
public void AnUnnormalizedStateIsNotNormalized()
8383
{
84-
Assert.False(MathS.Quantum.IsNormalised(Ket(0, 0) + Ket(1, 1)));
85-
Assert.False(MathS.Quantum.IsNormalised(2 * Ket(0)));
84+
Assert.False(MathS.Quantum.IsNormalized(Ket(0, 0) + Ket(1, 1)));
85+
Assert.False(MathS.Quantum.IsNormalized(2 * Ket(0)));
8686
}
8787

8888
[Fact]
8989
public void SomethingThatIsNotAStateHasNoAnswer()
9090
{
91-
Assert.Null(MathS.Quantum.IsNormalised("x + 1".ToEntity()));
92-
Assert.Null(MathS.Quantum.IsNormalised("apply(ket, 5)".ToEntity()));
91+
Assert.Null(MathS.Quantum.IsNormalized("x + 1".ToEntity()));
92+
Assert.Null(MathS.Quantum.IsNormalized("apply(ket, 5)".ToEntity()));
9393
}
9494

9595
// ---- factorisation ----
@@ -102,13 +102,13 @@ public void SomethingThatIsNotAStateHasNoAnswer()
102102
[Fact]
103103
public void ADefiniteQubitAtEitherEndFactorsOut()
104104
{
105-
var factored = MathS.Quantum.Factorise(Ket(0, 0, 1) + Ket(0, 1, 1));
105+
var factored = MathS.Quantum.TensorFactorize(Ket(0, 0, 1) + Ket(0, 1, 1));
106106
AssertSame(Ket(0) * (Ket(0) + Ket(1)) * Ket(1), factored);
107107
}
108108

109109
[Fact]
110110
public void ADefiniteLeadingQubitFactorsOutAlone() =>
111-
AssertSame(Ket(0) * (Ket(0) + Ket(1)) / Sqrt2, MathS.Quantum.Factorise(Product));
111+
AssertSame(Ket(0) * (Ket(0) + Ket(1)) / Sqrt2, MathS.Quantum.TensorFactorize(Product));
112112

113113
/// <summary>
114114
/// **Entanglement is the absence of this.** Neither qubit of a Bell state has a
@@ -118,8 +118,8 @@ public void ADefiniteLeadingQubitFactorsOutAlone() =>
118118
[Fact]
119119
public void AnEntangledStateDoesNotFactor()
120120
{
121-
AssertSame(Bell, MathS.Quantum.Factorise(Bell));
122-
AssertSame(Ghz, MathS.Quantum.Factorise(Ghz));
121+
AssertSame(Bell, MathS.Quantum.TensorFactorize(Bell));
122+
AssertSame(Ghz, MathS.Quantum.TensorFactorize(Ghz));
123123
}
124124

125125
/// <summary>
@@ -132,7 +132,7 @@ public void AnEntangledStateDoesNotFactor()
132132
public void SeparabilityWithoutADefiniteQubitIsNotYetDetected()
133133
{
134134
var uniform = Ket(0, 0) + Ket(0, 1) + Ket(1, 0) + Ket(1, 1);
135-
AssertSame(uniform, MathS.Quantum.Factorise(uniform));
135+
AssertSame(uniform, MathS.Quantum.TensorFactorize(uniform));
136136
}
137137

138138
// ---- round trip ----
@@ -147,15 +147,15 @@ public void SeparabilityWithoutADefiniteQubitIsNotYetDetected()
147147
[InlineData("(0,0,1)+(0,1,1)")]
148148
[InlineData("(0,0)+(0,1)")]
149149
[InlineData("(1,0,0)+(1,0,1)")]
150-
public void ExpandingAFactorisationReturnsTheOriginal(string which)
150+
public void ExpandingATensorFactorizationReturnsTheOriginal(string which)
151151
{
152152
var original = which switch
153153
{
154154
"(0,0,1)+(0,1,1)" => Ket(0, 0, 1) + Ket(0, 1, 1),
155155
"(0,0)+(0,1)" => Ket(0, 0) + Ket(0, 1),
156156
_ => Ket(1, 0, 0) + Ket(1, 0, 1),
157157
};
158-
var roundTripped = MathS.Quantum.TensorExpand(MathS.Quantum.Factorise(original));
158+
var roundTripped = MathS.Quantum.TensorExpand(MathS.Quantum.TensorFactorize(original));
159159
AssertSame(original, roundTripped);
160160
}
161161

‎Sources/Tests/UnitTests/Common/PublicApi.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,10 +2300,10 @@ AngouriMath.MathS+Numbers.Create(System.Int64) : AngouriMath.Entity+Number+Integ
23002300
AngouriMath.MathS+Numbers.Create(System.Numerics.Complex) : AngouriMath.Entity+Number+Complex
23012301
AngouriMath.MathS+Numbers.CreateRational(PeterO.Numbers.EInteger, PeterO.Numbers.EInteger) : AngouriMath.Entity+Number+Rational
23022302
AngouriMath.MathS+Quantum.EqualUpToGlobalPhase(AngouriMath.Entity, AngouriMath.Entity) : System.Nullable<System.Boolean>
2303-
AngouriMath.MathS+Quantum.Factorise(AngouriMath.Entity) : AngouriMath.Entity
2304-
AngouriMath.MathS+Quantum.IsNormalised(AngouriMath.Entity) : System.Nullable<System.Boolean>
2303+
AngouriMath.MathS+Quantum.IsNormalized(AngouriMath.Entity) : System.Nullable<System.Boolean>
23052304
AngouriMath.MathS+Quantum.Ket(System.Int32[]) : AngouriMath.Entity
23062305
AngouriMath.MathS+Quantum.TensorExpand(AngouriMath.Entity) : AngouriMath.Entity
2306+
AngouriMath.MathS+Quantum.TensorFactorize(AngouriMath.Entity) : AngouriMath.Entity
23072307
AngouriMath.MathS+Series.Maclaurin(AngouriMath.Entity, System.Int32, AngouriMath.Entity+Variable[]) : AngouriMath.Entity
23082308
AngouriMath.MathS+Series.Taylor(AngouriMath.Entity, System.Int32, System.ValueTuple<AngouriMath.Entity+Variable,AngouriMath.Entity+Variable,AngouriMath.Entity>[]) : AngouriMath.Entity
23092309
AngouriMath.MathS+Series.Taylor(AngouriMath.Entity, System.Int32, System.ValueTuple<AngouriMath.Entity+Variable,AngouriMath.Entity>[]) : AngouriMath.Entity

0 commit comments

Comments
 (0)