Example #1
0
        /// <summary>
        /// Tries to multiply an element to the current element.
        /// </summary>
        /// <param name="Element">Element to multiply.</param>
        /// <returns>Result, if understood, null otherwise.</returns>
        public override ICommutativeRingElement Multiply(ICommutativeRingElement Element)
        {
            PhysicalQuantity E = Element as PhysicalQuantity;

            if (E == null)
            {
                if (Element is DoubleNumber n)
                {
                    return(new PhysicalQuantity(this.magnitude * n.Value, this.unit));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                Unit   Unit      = Unit.Multiply(this.unit, E.unit, out int ResidueExponential);
                double Magnitude = this.magnitude * E.magnitude;
                if (ResidueExponential != 0)
                {
                    Magnitude *= Math.Pow(10, ResidueExponential);
                }

                return(new PhysicalQuantity(Magnitude, Unit));
            }
        }
Example #2
0
 /// <summary>
 /// Tries to multiply an element to the current element.
 /// </summary>
 /// <param name="Element">Element to multiply.</param>
 /// <returns>Result, if understood, null otherwise.</returns>
 public override ICommutativeRingElement Multiply(ICommutativeRingElement Element)
 {
     if (!(Element is ComplexNumber E))
     {
         if (!(Element is DoubleNumber D))
         {
             return(null);
         }
Example #3
0
        /// <summary>
        /// Divides the right ring element from the left one: Left*(1/Right)
        /// </summary>
        /// <param name="Left">Left element.</param>
        /// <param name="Right">Right element.</param>
        /// <returns>Result, if understood, null otherwise.</returns>
        public override sealed IRingElement RightDivide(IRingElement Left, IRingElement Right)
        {
            ICommutativeRingElement L = Left as ICommutativeRingElement;
            ICommutativeRingElement R = Right as ICommutativeRingElement;

            if (L is null || R is null)
            {
                return(base.RightDivide(Left, Right));
            }
Example #4
0
        /// <summary>
        /// Divides the right ring 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 ICommutativeRingElement Divide(ICommutativeRingElement Left, ICommutativeRingElement Right)
        {
            IEuclidianDomainElement L = Left as IEuclidianDomainElement;
            IEuclidianDomainElement R = Right as IEuclidianDomainElement;

            if (L is null || R is null)
            {
                return(base.Divide(Left, Right));
            }
Example #5
0
        /// <summary>
        /// Tries to multiply an element to the current element.
        /// </summary>
        /// <param name="Element">Element to multiply.</param>
        /// <returns>Result, if understood, null otherwise.</returns>
        public override ICommutativeRingElement Multiply(ICommutativeRingElement Element)
        {
            BooleanValue E = Element as BooleanValue;

            if (E == null)
            {
                return(null);
            }
            else
            {
                return(new BooleanValue(this.value && E.value));
            }
        }
Example #6
0
        /// <summary>
        /// Tries to multiply an element to the current element, from the right.
        /// </summary>
        /// <param name="Element">Element to multiply.</param>
        /// <returns>Result, if understood, null otherwise.</returns>
        public override IRingElement MultiplyRight(IRingElement Element)
        {
            ICommutativeRingElement E = Element as ICommutativeRingElement;

            if (E == null)
            {
                return(null);
            }
            else
            {
                return(this.Multiply(E));
            }
        }
Example #7
0
        /// <summary>
        /// Tries to multiply an element to the current element.
        /// </summary>
        /// <param name="Element">Element to multiply.</param>
        /// <returns>Result, if understood, null otherwise.</returns>
        public override ICommutativeRingElement Multiply(ICommutativeRingElement Element)
        {
            DoubleNumber E = Element as DoubleNumber;

            if (E == null)
            {
                return(null);
            }
            else
            {
                return(new DoubleNumber(this.value * E.value));
            }
        }
Example #8
0
 /// <summary>
 /// Tries to multiply an element to the current element.
 /// </summary>
 /// <param name="Element">Element to multiply.</param>
 /// <returns>Result, if understood, null otherwise.</returns>
 public override ICommutativeRingElement Multiply(ICommutativeRingElement Element)
 {
     if (!(Element is PhysicalQuantity E))
     {
         if (Element is DoubleNumber n)
         {
             return(new PhysicalQuantity(this.magnitude * n.Value, this.unit));
         }
         else
         {
             return(null);
         }
     }
Example #9
0
        /// <summary>
        /// Divides the right ring element from the left one: Left*(1/Right)
        /// </summary>
        /// <param name="Left">Left element.</param>
        /// <param name="Right">Right element.</param>
        /// <returns>Result, if understood, null otherwise.</returns>
        public override sealed IRingElement RightDivide(IRingElement Left, IRingElement Right)
        {
            ICommutativeRingElement L = Left as ICommutativeRingElement;
            ICommutativeRingElement R = Right as ICommutativeRingElement;

            if (L == null || R == null)
            {
                return(base.RightDivide(Left, Right));
            }
            else
            {
                return(this.Divide(L, R));
            }
        }
Example #10
0
        /// <summary>
        /// Tries to multiply an element to the current element.
        /// </summary>
        /// <param name="Element">Element to multiply.</param>
        /// <returns>Result, if understood, null otherwise.</returns>
        public override ICommutativeRingElement Multiply(ICommutativeRingElement Element)
        {
            if (Element is Integer E)
            {
                return(new Integer(this.value * E.value));
            }

            if (Element is DoubleNumber D)
            {
                return(new DoubleNumber((double)this.value * D.Value));
            }

            if (Element is ComplexNumber z)
            {
                return(new ComplexNumber((double)this.value * z.Value));
            }

            return(null);
        }
Example #11
0
        /// <summary>
        /// Tries to multiply an element to the current element.
        /// </summary>
        /// <param name="Element">Element to multiply.</param>
        /// <returns>Result, if understood, null otherwise.</returns>
        public override ICommutativeRingElement Multiply(ICommutativeRingElement 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));
            }
        }
Example #12
0
        /// <summary>
        /// Divides the right ring 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 ICommutativeRingElement Divide(ICommutativeRingElement Left, ICommutativeRingElement Right)
        {
            IEuclidianDomainElement L = Left as IEuclidianDomainElement;
            IEuclidianDomainElement R = Right as IEuclidianDomainElement;

            if (L == null || R == null)
            {
                return(base.Divide(Left, Right));
            }
            else
            {
                IEuclidianDomainElement Remainder;
                IEuclidianDomainElement Result = this.Divide(L, R, out Remainder);
                if (Result == null || !Remainder.Equals(Remainder.AssociatedAbelianGroup.Zero))
                {
                    return(null);
                }
                else
                {
                    return(Result);
                }
            }
        }
Example #13
0
        /// <summary>
        /// Tries to multiply an element to the current element.
        /// </summary>
        /// <param name="Element">Element to multiply.</param>
        /// <returns>Result, if understood, null otherwise.</returns>
        public override ICommutativeRingElement Multiply(ICommutativeRingElement 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);
        }
Example #14
0
 /// <summary>
 /// Tries to multiply an element to the current element.
 /// </summary>
 /// <param name="Element">Element to multiply.</param>
 /// <returns>Result, if understood, null otherwise.</returns>
 public override ICommutativeRingElement Multiply(ICommutativeRingElement Element)
 {
     if (!(Element is BooleanValue E))
     {
         return(null);
     }
Example #15
0
 /// <summary>
 /// Divides the right ring 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 ICommutativeRingElement Divide(ICommutativeRingElement Left, ICommutativeRingElement Right)
 {
     return(this.Multiply(Left, Right.Invert()) as ICommutativeRingElement);
 }
 /// <summary>
 /// Tries to multiply an element to the current element.
 /// </summary>
 /// <param name="Element">Element to multiply.</param>
 /// <returns>Result, if understood, null otherwise.</returns>
 public abstract ICommutativeRingElement Multiply(ICommutativeRingElement Element);
Example #17
0
 /// <summary>
 /// Divides the right ring 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 ICommutativeRingElement Divide(ICommutativeRingElement Left, ICommutativeRingElement Right)
 {
     if (!(Left is IEuclidianDomainElement L) || !(Right is IEuclidianDomainElement R))
     {
         return(base.Divide(Left, Right));
     }