Example #1
0
        public static GaSymMultivector Op(this IGaSymMultivector mv1, IGaSymMultivector mv2)
        {
            if (mv1.GaSpaceDimension != mv2.GaSpaceDimension)
            {
                throw new GMacSymbolicException("Multivector size mismatch");
            }

            return(GaSymMultivector
                   .CreateZeroTemp(mv1.GaSpaceDimension)
                   .AddFactors(mv1.ToMultivector().GetBiTermsForOp(mv2.ToMultivector()))
                   .ToMultivector());
        }
Example #2
0
        public static IGaSymMultivector Compactify(this IGaSymMultivector mv, bool returnZeroMvAsNull = false)
        {
            if (DisableCompactifyMultivectors)
            {
                return(mv);
            }

            if (ReferenceEquals(mv, null))
            {
                return(null);
            }

            //Make sure this is not a temp multivector
            if (mv.IsTemp)
            {
                mv = mv.ToMultivector();
            }

            //If it's zero return null or a zero term depending on returnZeroMvAsNull
            if (mv.IsZero())
            {
                return(returnZeroMvAsNull
                    ? null
                    : GaSymMultivectorTerm.CreateZero(mv.GaSpaceDimension));
            }

            //If it's a non-zero term return it as is
            var termMv = mv as GaSymMultivectorTerm;

            if (!ReferenceEquals(termMv, null))
            {
                return(termMv);
            }

            //It's a full multivector
            var fullMv = (GaSymMultivector)mv;

            //If it's not a term return it after simplification
            if (!mv.IsTerm())
            {
                fullMv.Simplify();
                return(fullMv);
            }

            //It's a full multivector containing a single term
            var term = mv.NonZeroExprTerms.FirstOrDefault();

            return(GaSymMultivectorTerm.CreateTerm(mv.GaSpaceDimension, term.Key, term.Value));
        }