/// <summary> /// Returns the inverse of the specified element. /// </summary> /// <param name="element">The element.</param> /// <returns>The inverse of element (-element)</returns> /// <exception cref="InvalidCastException">When the cast to DirectSum from interface was not possible</exception> public DirectSum <T, TGroup> Inverse(DirectSum <T, TGroup> element) { var tuple = element.InverseElement() as DirectSum <T, TGroup>; if (tuple == null) { throw new InvalidCastException(); } return(tuple); }
/// <summary> /// Returns a vector with ones as values. /// </summary> /// <returns>The vector.</returns> /// <param name="dimension">The dimension.</param> /// <typeparam name="T">The type parameter.</typeparam> /// <typeparam name="TStruct">The underlying structure.</typeparam> /// <returns>The zerovector with dimension.</returns> public DirectSum <T, TStruct> OneTuple <T, TStruct> (UInt32 dimension) where TStruct : IRing <T>, new() { var tuple = new DirectSum <T, TStruct> (dimension); var baseStructure = new TStruct(); for (UInt32 i = 0; i < tuple.Dimension; i++) { tuple [i] = baseStructure.One; } return(tuple); }
/// <summary> /// Multiplication of the specified leftElement and rightElement. /// </summary> /// <param name="leftElement">Left element.</param> /// <param name="rightElement">Right element.</param> /// <returns>The multiplication of the leftElement and rightElement (leftElement * rightElement)</returns> /// <exception cref="InvalidCastException">Thrown when the cast was not possible.</exception> public DirectSum <T, TRing> Multiplication( DirectSum <T, TRing> leftElement, DirectSum <T, TRing> rightElement) { var tuple = leftElement.Multiply(rightElement) as DirectSum <T, TRing>; if (tuple == null) { throw new InvalidCastException(); } return(tuple); }
/// <summary> /// Addition of the specified leftElement and rightElement. /// </summary> /// <param name="leftElement">Left element.</param> /// <param name="rightElement">Right element.</param> /// <returns>The addition of the leftElement and rightElement (leftElement + rightElement)</returns> /// <exception cref="InvalidCastException">When the cast was not possible.</exception> /// <exception cref="NotSupportedException">When the dimension of the parameters is not equal to the set dimension of the instance.</exception> public DirectSum <T, TMonoid> Addition( DirectSum <T, TMonoid> leftElement, DirectSum <T, TMonoid> rightElement) { if (leftElement.Dimension != this.Dimension) { throw new NotSupportedException("The dimension is not set right"); } var tuple = leftElement.Add(rightElement) as DirectSum <T, TMonoid>; if (tuple == null) { throw new InvalidCastException(); } return(tuple); }
/// <summary> /// Determines whether the specified <see cref="DirectSum{T,TStruct}"/> is equal to the current <see cref="DirectSum{T,TStruct}"/>. /// </summary> /// <param name="other">The <see cref="DirectSum{T,TStruct}"/> to compare with the current <see cref="DirectSum{T,TStruct}"/>.</param> /// <returns><c>true</c> if the specified <see cref="DirectSum{T,TStruct}"/> is equal to the current /// <see cref="DirectSum{T,TStruct}"/>otherwise, <c>false</c>.</returns> public Boolean Equals(DirectSum <T, TStruct> other) { if (other == null) { return(false); } if (Object.ReferenceEquals(this, other)) { return(true); } for (UInt32 i = 0; i < this._entries.Count; i++) { if (!this[i].Equals(other[i])) { return(false); } } return(true); }