Beispiel #1
0
        /// <summary>
        /// Constructs a term representing the inner product of two vectors.
        /// </summary>
        /// <param name="left">The first vector of the inner product</param>
        /// <param name="right">The second vector of the inner product</param>
        /// <returns>A term representing the inner product of <paramref name="left"/> and <paramref name="right"/>.</returns>
        public static Term InnerProduct(TVec left, TVec right)
        {
            Guard.NotNull(left, nameof(left));
            Guard.NotNull(right, nameof(right));
            Guard.MustHold(left.Dimension == right.Dimension, "left and right must be of the same dimension");

            var products = from i in Enumerable.Range(0, left.Dimension)
                           select left.terms[i] * right.terms[i];

            return(TermBuilder.Sum(products));
        }
Beispiel #2
0
        /// <summary>
        /// Constructs a term representing the inner product of two vectors.
        /// </summary>
        /// <param name="left">The first vector of the inner product</param>
        /// <param name="right">The second vector of the inner product</param>
        /// <returns>A term representing the inner product of <paramref name="left"/> and <paramref name="right"/>.</returns>
        public static Term InnerProduct(TVec left, TVec right)
        {
            Contract.Requires(left != null);
            Contract.Requires(right != null);
            Contract.Requires(left.Dimension == right.Dimension);
            Contract.Ensures(Contract.Result <Term>() != null);

            var products = from i in System.Linq.Enumerable.Range(0, left.Dimension)
                           select left.terms[i] * right.terms[i];

            return(TermBuilder.Sum(products));
        }
Beispiel #3
0
 /// <summary>
 /// Constructs a sum of the two given terms.
 /// </summary>
 /// <param name="left">First term in the sum</param>
 /// <param name="right">Second term in the sum</param>
 /// <returns>A term representing the sum of <paramref name="left"/> and <paramref name="right"/>.</returns>
 public static Term operator+(Term left, Term right)
 {
     if (left is Zero && right is Zero)
     {
         return(new Zero());
     }
     else if (left is Zero)
     {
         return(right);
     }
     else if (right is Zero)
     {
         return(left);
     }
     else
     {
         return(TermBuilder.Sum(left, right));
     }
 }
Beispiel #4
0
 /// <summary>
 /// Constructs a sum of the two given terms.
 /// </summary>
 /// <param name="left">First term in the sum</param>
 /// <param name="right">Second term in the sum</param>
 /// <returns>A term representing the sum of <paramref name="left"/> and <paramref name="right"/>.</returns>
 public static Term operator+(Term left, Term right)
 {
     return(TermBuilder.Sum(left, right));
 }