in Chemistry/src/DataModel/LadderOperator/LadderSequence.cs [185:244]
public LadderSequence<TIndex> Multiply(
LadderSequence<TIndex> left,
LadderSequence<TIndex> right)
=> new LadderSequence<TIndex>(left.Sequence.Concat(right.Sequence), left.Coefficient * right.Coefficient);
/// <summary>
/// Counts the number of unique system indices across all <see cref="LadderOperator{TIndex}"/> terms
/// in a <see cref="LadderSequence{TIndex}"/>
/// </summary>
/// <returns>Number of unique system indices.</returns>
public int UniqueIndices() => Sequence.Select(o => o.Index).Distinct().Count();
/// <summary>
/// Returns a copy of the ladder sequence base class.
/// </summary>
/// <returns>Base class of this sequence of ladder operators.</returns>
public LadderSequence<TIndex> ToLadderSequence() => new LadderSequence<TIndex>(Sequence, Coefficient);
/// <summary>
/// Returns list of indices of the ladder operator sequence.
/// </summary>
/// <returns>Sequence of integers. </returns>
public IEnumerable<TIndex> ToIndices() => Sequence.Select(o => (TIndex) o.Index);
/// <summary>
/// Returns sequence of raising and lowering types of the ladder operator sequence.
/// </summary>
/// <returns>Sequence of raising an lowering operators.</returns>
public IEnumerable<RaisingLowering> ToRaisingLowering() => Sequence.Select(o => o.Type);
/// <summary>
/// Returns a human-readable description of this object.
/// </summary>
public override string ToString() => $"{Coefficient} * {string.Join(" ", Sequence)}";
#region Equality Testing
public override bool Equals(object obj) => (obj is LadderSequence<TIndex> x) ? Equals(x) : false;
public bool Equals(LadderSequence<TIndex> x)
{
// If parameter is null, return false.
if (ReferenceEquals(x, null))
{
return false;
}
// Optimization for a common success case.
if (ReferenceEquals(this, x))
{
return true;
}
// If run-time types are not exactly the same, return false.
if (GetType() != x.GetType())
{
return false;
}
// Return true if the fields match.
return Sequence.SequenceEqual(x.Sequence);
}