// 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); }
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))); }
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); }
/// <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); }
public Multivector Wedge(Multivector M) => Wedge(this, M);
public static Multivector Involute(Multivector M) => (new Multivector(M.Space)).Copy(M).Involute();
public static Multivector Add(Multivector a, double b) => a.Clone().Add(b);
public static Multivector Wedge(Multivector a, Multivector b) { var c = new Multivector(a.Space); return(Wedge(a, b, ref c)); }
public Multivector Mul(Multivector M) => Multiply(M);
public Multivector Multiply(Multivector M) { return(Multiply(this, M)); }
public static Multivector Mul(Multivector a, Multivector b) => Multiply(a, b);
public static Multivector Subtract(double a, Multivector b) => b.Clone().Negate().Add(a);
public static Multivector Negate(Multivector M) => M.Clone().Negate();
public static Multivector Add(double a, Multivector b) => b.Clone().Add(a);
public static Multivector Sub(Multivector a, double b) => Subtract(a, b);
public static Multivector Sub(double a, Multivector b) => Subtract(a, b);
public static Multivector Subtract(Multivector a, double b) => a.Clone().Sub(b);
public static Multivector Reverse(Multivector M) => M.Clone().Reverse();
public static Multivector Multiply(Multivector a, Multivector b) { var c = new Multivector(a.Space); return(Multiply(a, b, ref c)); }
public static Multivector Conjugate(Multivector M) => M.Clone().Conjugate();
public Multivector Sub(Multivector M) => Subtract(M);