public IGaNumMultivector this[int id1, int id2]
        {
            get
            {
                GaNumMultivectorBinaryTree1D mvTree1D;
                RootNode.TryGetLeafValue((ulong)id1, out mvTree1D);

                return(ReferenceEquals(mvTree1D, null)
                    ? GaNumMultivectorTerm.CreateZero(TargetGaSpaceDimension)
                    : mvTree1D[id2]);
            }
            set
            {
                GaNumMultivectorBinaryTree1D mvTree1D;
                if (!RootNode.TryGetLeafValue((ulong)id1, out mvTree1D) || ReferenceEquals(mvTree1D, null))
                {
                    mvTree1D = new GaNumMultivectorBinaryTree1D(
                        DomainVSpaceDimension2,
                        TargetVSpaceDimension
                        );

                    RootNode.SetLeafValue((ulong)id1, mvTree1D);
                }

                mvTree1D[id2] = value;
            }
        }
Ejemplo n.º 2
0
        public static IGaNumMultivector Compactify(this IGaNumMultivector 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
                    : GaNumMultivectorTerm.CreateZero(mv.GaSpaceDimension));
            }

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

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

            //It's a full multivector
            var fullMv = (GaNumMultivector)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.NonZeroTerms.FirstOrDefault();

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