/// <summary> /// Subtracts the right group element from the left one: Left+(-Right) /// </summary> /// <param name="Left">Left element.</param> /// <param name="Right">Right element.</param> /// <returns>Result, if understood, null otherwise.</returns> public override sealed IGroupElement RightSubtract(IGroupElement Left, IGroupElement Right) { IAbelianGroupElement L = Left as IAbelianGroupElement; IAbelianGroupElement R = Right as IAbelianGroupElement; if (L is null || R is null) { return(base.RightSubtract(Left, Right)); }
/// <summary> /// Tries to add an element to the current element, from the left. /// </summary> /// <param name="Element">Element to add.</param> /// <returns>Result, if understood, null otherwise.</returns> public override ISemiGroupElement AddLeft(ISemiGroupElement Element) { IAbelianGroupElement E = Element as IAbelianGroupElement; if (E is null) { return(null); } else { return(E.Add(this)); } }
/// <summary> /// Subtracts the left group element from the right one: (-Left)+Right. /// </summary> /// <param name="Left">Left element.</param> /// <param name="Right">Right element.</param> /// <returns>Result, if understood, null otherwise.</returns> public override sealed IGroupElement LeftSubtract(IGroupElement Left, IGroupElement Right) { IAbelianGroupElement L = Left as IAbelianGroupElement; IAbelianGroupElement R = Right as IAbelianGroupElement; if (L == null || R == null) { return(base.LeftSubtract(Left, Right)); } else { return(this.Subtract(R, L)); } }
/// <summary> /// Tries to add an element to the current element. /// </summary> /// <param name="Element">Element to add.</param> /// <returns>Result, if understood, null otherwise.</returns> public override IAbelianGroupElement Add(IAbelianGroupElement Element) { ComplexNumber E = Element as ComplexNumber; if (E is null) { DoubleNumber D = Element as DoubleNumber; if (D is null) { return(null); } else { return(new ComplexNumber(this.value + D.Value)); } } else { return(new ComplexNumber(this.value + E.value)); } }
/// <summary> /// Tries to add an element to the current element. /// </summary> /// <param name="Element">Element to add.</param> /// <returns>Result, if understood, null otherwise.</returns> public override IAbelianGroupElement Add(IAbelianGroupElement Element) { if (Element is RationalNumber Q) { return(this + Q); } if (Element is Integer i) { return(this + i.Value); } if (Element is DoubleNumber D) { return(new DoubleNumber(this.ToDouble() + D.Value)); } if (Element is ComplexNumber z) { return(new ComplexNumber(this.ToDouble() + z.Value)); } return(null); }
/// <summary> /// Subtracts the right group element from the left one: Left-Right /// </summary> /// <param name="Left">Left element.</param> /// <param name="Right">Right element.</param> /// <returns>Result, if understood, null otherwise.</returns> public virtual IAbelianGroupElement Subtract(IAbelianGroupElement Left, IAbelianGroupElement Right) { return(this.Add(Left, Right.Negate()) as IAbelianGroupElement); }