Ejemplo n.º 1
0
        // Exterior product (or wedge product)

        /// <summary>Wedge multiply two multivectors a and b and add the result to c.</summary>
        /// <param name="c">The exterior product of a and b will be added to this multivector.</param>
        /// <returns>Returns c for chaining.</returns>
        public static Multivector Wedge(Multivector a, Multivector b, ref Multivector c)
        {
            if (a.Space != b.Space || a.Space != c.Space)
            {
                throw new ArgumentException("Cannot wedge multiply two multivectors from different spaces.");
            }

            var space = a.Space;

            var l = (ulong)a.Count;

            for (ulong i = 0; i < l; i++)
            {
                for (ulong j = 0; j < l; j++)
                {
                    if ((i & j) != 0)
                    {
                        continue;           //skip linearly dependent components
                    }
                    var(e, sign) = space.BasisMultiply(i, j);
                    c[(int)e]   += sign * a[(int)i] * b[(int)j];
                }
            }


            return(c);
        }
Ejemplo n.º 2
0
        public Space(int positive, int negative = 0, int nil = 0) : this()
        {
            if (positive < 0 || negative < 0 || nil < 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            var dimension = positive + negative + nil;

            if (dimension <= 30)
            {
                Dimension          = (int)dimension;
                PositiveDimension  = (int)positive;
                NegativeDimension  = (int)negative;
                NilpotentDimension = (int)nil;
            }
            else
            {
                throw new ArgumentOutOfRangeException("The total dimension cannot be greater than 30.");
            }
            // “No one will ever need 34.3 T of memory.” —Bill Gates

            SetUpConversionBetweenIndexAndBladeBasis();

            Zero = new Multivector(this, ImmutableArray.CreateRange(Enumerable.Repeat(0.0, Dimension)));
        }
Ejemplo n.º 3
0
        public Multivector Subtract(Multivector M)
        {
            if (Space != M.Space)
            {
                throw new ArgumentException("Cannot subtract two multivectors from different spaces.");
            }

            for (int i = 0, l = Count; i < l; i++)
            {
                this[i] -= M[i];
            }

            return(this);
        }
Ejemplo n.º 4
0
        /// <summary>Multiply two multivectors a and b and add the result to c.</summary>
        /// <param name="c">The result of multiplication will be added to this multivector.</param>
        /// <returns>Returns c for chaining.</returns>
        public static Multivector Multiply(Multivector a, Multivector b, ref Multivector c)
        {
            if (a.Space != b.Space || a.Space != c.Space)
            {
                throw new ArgumentException("Cannot multiply two multivectors from different spaces.");
            }

            var space = a.Space;

            var l = (ulong)a.Count;

            for (ulong i = 0; i < l; i++)
            {
                for (ulong j = 0; j < l; j++)
                {
                    var(e, sign) = space.BasisMultiply(i, j);
                    c[(int)e]   += sign * a[(int)i] * b[(int)j];
                }
            }


            return(c);
        }
Ejemplo n.º 5
0
 public Multivector Wedge(Multivector M) => Wedge(this, M);
Ejemplo n.º 6
0
 public static Multivector Involute(Multivector M)
 => (new Multivector(M.Space)).Copy(M).Involute();
Ejemplo n.º 7
0
 public static Multivector Add(Multivector a, double b)
 => a.Clone().Add(b);
Ejemplo n.º 8
0
        public static Multivector Wedge(Multivector a, Multivector b)
        {
            var c = new Multivector(a.Space);

            return(Wedge(a, b, ref c));
        }
Ejemplo n.º 9
0
 public Multivector Mul(Multivector M) => Multiply(M);
Ejemplo n.º 10
0
 public Multivector Multiply(Multivector M)
 {
     return(Multiply(this, M));
 }
Ejemplo n.º 11
0
 public static Multivector Mul(Multivector a, Multivector b) => Multiply(a, b);
Ejemplo n.º 12
0
 public static Multivector Subtract(double a, Multivector b)
 => b.Clone().Negate().Add(a);
Ejemplo n.º 13
0
 public static Multivector Negate(Multivector M) => M.Clone().Negate();
Ejemplo n.º 14
0
 public static Multivector Add(double a, Multivector b)
 => b.Clone().Add(a);
Ejemplo n.º 15
0
 public static Multivector Sub(Multivector a, double b) => Subtract(a, b);
Ejemplo n.º 16
0
 public static Multivector Sub(double a, Multivector b) => Subtract(a, b);
Ejemplo n.º 17
0
 public static Multivector Subtract(Multivector a, double b)
 => a.Clone().Sub(b);
Ejemplo n.º 18
0
 public static Multivector Reverse(Multivector M)
 => M.Clone().Reverse();
Ejemplo n.º 19
0
        public static Multivector Multiply(Multivector a, Multivector b)
        {
            var c = new Multivector(a.Space);

            return(Multiply(a, b, ref c));
        }
Ejemplo n.º 20
0
 public static Multivector Conjugate(Multivector M)
 => M.Clone().Conjugate();
Ejemplo n.º 21
0
 public Multivector Sub(Multivector M) => Subtract(M);