Exemplo n.º 1
0
        /// <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);
        }