示例#1
0
        public static GaTreeMultivector EGp(this GaTreeMultivector mv1, GaTreeMultivector mv2)
        {
            if (mv1.GaSpaceDimension != mv2.GaSpaceDimension)
            {
                throw new GMacSymbolicException("Multivector size mismatch");
            }

            var resultMv = GaSymMultivector.CreateZeroTemp(mv1.GaSpaceDimension);

            var indexList = Enumerable.Range(0, mv1.GaSpaceDimension).Reverse().ToList();

            for (var k = 0; k < mv1.GaSpaceDimension; k++)
            {
                var coefId   = k.ReverseBits(mv1.VSpaceDimension);
                var signList = GpSign(mv1.VSpaceDimension, coefId);

                foreach (var index in indexList)
                {
                    var id1 = index.ReverseBits(mv1.VSpaceDimension);
                    var id2 = id1 ^ coefId;

                    resultMv.AddFactor(
                        coefId,
                        signList[mv1.GaSpaceDimension - index - 1],
                        Mfs.Times[mv1[id1], mv2[id2]]
                        );
                }
            }

            return(resultMv.ToTreeMultivector());
        }
示例#2
0
        public static GaTreeMultivector CreatePseudoScalar(int gaSpaceDim, MathematicaScalar coef)
        {
            var resultMv = new GaTreeMultivector(gaSpaceDim)
            {
                [gaSpaceDim - 1] = coef.Expression
            };

            return(resultMv);
        }
示例#3
0
        public static GaTreeMultivector CreateBasisBlade(int gaSpaceDim, int id)
        {
            var resultMv = new GaTreeMultivector(gaSpaceDim)
            {
                [id] = Expr.INT_ONE
            };

            return(resultMv);
        }
示例#4
0
        public static GaTreeMultivector CreateTerm(int gaSpaceDim, int id, MathematicaScalar coef)
        {
            var resultMv = new GaTreeMultivector(gaSpaceDim)
            {
                [id] = coef.Expression
            };

            return(resultMv);
        }
示例#5
0
        public static GaTreeMultivector CreateMapped(GaTreeMultivector mv, Func <MathematicaScalar, MathematicaScalar> scalarMap)
        {
            var resultMv = CreateZero(mv.GaSpaceDimension);

            foreach (var term in mv.Terms)
            {
                resultMv[term.Key] = scalarMap(term.Value).Expression;
            }

            return(resultMv);
        }
示例#6
0
        public static GaTreeMultivector CreateSymbolic(int gaSpaceDim, string baseCoefName, IEnumerable <int> idsList)
        {
            var resultMv  = new GaTreeMultivector(gaSpaceDim);
            var vSpaceDim = gaSpaceDim.ToVSpaceDimension();

            foreach (var id in idsList)
            {
                resultMv[id] =
                    MathematicaScalar.CreateSymbol(
                        SymbolicUtils.Cas,
                        baseCoefName + id.PatternToString(vSpaceDim)
                        ).Expression;
            }

            return(resultMv);
        }
示例#7
0
        public static GaTreeMultivector Op(this GaTreeMultivector mv1, GaTreeMultivector mv2)
        {
            if (mv1.GaSpaceDimension != mv2.GaSpaceDimension)
            {
                throw new GMacSymbolicException("Multivector size mismatch");
            }

            var resultMv = GaSymMultivector.CreateZeroTemp(mv1.GaSpaceDimension);

            var signList = OpSign(mv1.VSpaceDimension);

            for (var basisBladeId = 0; basisBladeId < mv1.GaSpaceDimension; basisBladeId++)
            {
                var indexList = new List <int>();

                indexList =
                    basisBladeId
                    .PatternToBooleans(mv1.VSpaceDimension)
                    .Aggregate(
                        indexList,
                        (currentList, bitFlag) =>
                        OpOneLevel(currentList, bitFlag).ToList()
                        )
                    .Select(idx => idx.ReverseBits(mv1.VSpaceDimension))
                    .ToList();

                var i = 0;
                foreach (var index in indexList)
                {
                    resultMv.AddFactor(
                        basisBladeId,
                        signList[i],
                        Mfs.Times[mv1[index], mv2[basisBladeId ^ index]]
                        );

                    i++;
                }
            }

            return(resultMv.ToTreeMultivector());
        }
示例#8
0
        public static GaTreeMultivector CreateCopy(GaTreeMultivector mv)
        {
            var resultMv        = new GaTreeMultivector(mv.GaSpaceDimension);
            var sourceNodeStack = new Stack <IGaTreeMultivectorNode>();
            var targetNodeStack = new Stack <IGaTreeMultivectorNode>();

            sourceNodeStack.Push(mv);
            targetNodeStack.Push(resultMv);

            while (sourceNodeStack.Count > 0)
            {
                var sourceNode = sourceNodeStack.Pop();
                var targetNode = targetNodeStack.Pop();

                var childNode = sourceNode.GetLeftChild();
                if (!ReferenceEquals(childNode, null))
                {
                    targetNodeStack.Push(
                        childNode.IsInternal
                            ? (IGaTreeMultivectorNode)targetNode.SetLeftChildToInternalNode()
                            : targetNode.SetLeftChildToLeafNode(childNode.AsLeafNode().Value)
                        );
                }

                childNode = sourceNode.GetRightChild();
                if (!ReferenceEquals(childNode, null))
                {
                    targetNodeStack.Push(
                        childNode.IsInternal
                        ? (IGaTreeMultivectorNode)targetNode.SetRightChildToInternalNode()
                        : targetNode.SetRightChildToLeafNode(childNode.AsLeafNode().Value)
                        );
                }
            }

            return(resultMv);
        }