Esempio n. 1
0
        public static GaSymMultivector CreateCopy(GaSymMultivector mv)
        {
            var resultMv = new GaSymMultivector(mv.GaSpaceDimension);

            resultMv.TermsTree.FillFromTree(mv.TermsTree);

            return(resultMv);
        }
Esempio n. 2
0
        public static IEnumerable <GaSymMultivectorBiTerm> GetBiTermsForOp(this GaSymMultivector mv1, GaSymMultivector mv2)
        {
            var mvStack1 = mv1.TermsTree.CreateNodesStack();
            var mvStack2 = mv2.TermsTree.CreateNodesStack();

            var idStack1 = mv1.TermsTree.CreateNodeIDsStack();
            var idStack2 = mv2.TermsTree.CreateNodeIDsStack();

            while (mvStack1.Count > 0)
            {
                var node1 = mvStack1.Pop();
                var node2 = mvStack2.Pop();
                var id1   = idStack1.Pop();
                var id2   = idStack2.Pop();

                if (node1.IsLeafNode)
                {
                    yield return(new GaSymMultivectorBiTerm(
                                     (int)id1,
                                     (int)id2,
                                     node1.Value,
                                     node2.Value
                                     ));

                    continue;
                }

                if (node1.HasChildNode0)
                {
                    if (node2.HasChildNode0)
                    {
                        mvStack1.Push(node1.ChildNode0);
                        mvStack2.Push(node2.ChildNode0);

                        idStack1.Push(id1);
                        idStack2.Push(id2);
                    }

                    if (node2.HasChildNode1)
                    {
                        mvStack1.Push(node1.ChildNode0);
                        mvStack2.Push(node2.ChildNode1);

                        idStack1.Push(id1);
                        idStack2.Push(id2 | node2.ChildNode1.BitMask);
                    }
                }

                if (node1.HasChildNode1 && node2.HasChildNode0)
                {
                    mvStack1.Push(node1.ChildNode1);
                    mvStack2.Push(node2.ChildNode0);

                    idStack1.Push(id1 | node1.ChildNode1.BitMask);
                    idStack2.Push(id2);
                }
            }
        }
Esempio n. 3
0
        public static GaSymMultivector CreateCopy(GMacBinaryTree <Expr> termsTree)
        {
            var gaSpaceDimension = termsTree.TreeDepth.ToGaSpaceDimension();
            var resultMv         = new GaSymMultivector(gaSpaceDimension);

            resultMv.TermsTree.FillFromTree(termsTree);

            return(resultMv);
        }
Esempio n. 4
0
        public static GaSymMultivector SetTerms(this GaSymMultivector mv, IEnumerable <KeyValuePair <int, Expr> > terms)
        {
            foreach (var term in terms)
            {
                mv.SetTermCoef(term.Key, term.Value);
            }

            return(mv);
        }
Esempio n. 5
0
        public static IEnumerable <GaSymMultivectorBiTerm> GetBiTermsForSp(this GaSymMultivector mv1, GaSymMultivector mv2, GaSymMetricOrthogonal orthogonalMetric)
        {
            var mvStack1 = mv1.TermsTree.CreateNodesStack();
            var mvStack2 = mv2.TermsTree.CreateNodesStack();

            var idStack1 = mv1.TermsTree.CreateNodeIDsStack();
            var idStack2 = mv2.TermsTree.CreateNodeIDsStack();

            var metricStack = orthogonalMetric.RootNode.CreateNodesStack();

            while (mvStack1.Count > 0)
            {
                var node1      = mvStack1.Pop();
                var node2      = mvStack2.Pop();
                var id1        = idStack1.Pop();
                var id2        = idStack2.Pop();
                var metricNode = metricStack.Pop();

                if (node1.IsLeafNode)
                {
                    yield return(new GaSymMultivectorBiTerm(
                                     (int)id1,
                                     (int)id2,
                                     node1.Value,
                                     node2.Value,
                                     metricNode.Value
                                     ));

                    continue;
                }

                if (node1.HasChildNode0 && node2.HasChildNode0 && metricNode.HasChildNode0)
                {
                    mvStack1.Push(node1.ChildNode0);
                    mvStack2.Push(node2.ChildNode0);

                    idStack1.Push(id1);
                    idStack2.Push(id2);

                    //0 and 0 = 0
                    metricStack.Push(metricNode.ChildNode0);
                }

                if (node1.HasChildNode1 && node2.HasChildNode1 && metricNode.HasChildNode1)
                {
                    mvStack1.Push(node1.ChildNode1);
                    mvStack2.Push(node2.ChildNode1);

                    idStack1.Push(id1 | node1.ChildNode1.BitMask);
                    idStack2.Push(id2 | node2.ChildNode1.BitMask);

                    //1 and 1 = 1
                    metricStack.Push(metricNode.ChildNode1);
                }
            }
        }
Esempio n. 6
0
        public GaSymMultivector GetOddPart()
        {
            var resultMv = new GaSymMultivector(GaSpaceDimension);

            foreach (var term in NonZeroTerms.Where(t => (t.Key.BasisBladeGrade() & 1) == 1))
            {
                resultMv.SetTermCoef(term.Key, term.Value);
            }

            return(resultMv);
        }
Esempio n. 7
0
        public static GaTreeMultivector ToTreeMultivector(this GaSymMultivector sparseMv)
        {
            var treeMv = GaTreeMultivector.CreateZero(sparseMv.GaSpaceDimension);

            foreach (var term in sparseMv.NonZeroExprTerms)
            {
                treeMv[term.Key] = term.Value;
            }

            return(treeMv);
        }
Esempio n. 8
0
        public static GaSymMultivector CreateMapped(GaSymMultivector mv, Func <Expr, Expr> scalarMap)
        {
            var resultMv = CreateZero(mv.GaSpaceDimension);

            foreach (var term in mv.NonZeroExprTerms)
            {
                resultMv.SetTermCoef(term.Key, scalarMap(term.Value));
            }

            return(resultMv);
        }
Esempio n. 9
0
        public GaSymMultivector GetPartByGrade(Func <int, bool> gradeSelectionFunc)
        {
            var resultMv = new GaSymMultivector(GaSpaceDimension);

            foreach (var term in NonZeroTerms.Where(t => gradeSelectionFunc(t.Key.BasisBladeGrade())))
            {
                resultMv.SetTermCoef(term.Key, term.Value);
            }

            return(resultMv);
        }
Esempio n. 10
0
        public GaSymMultivector GetVectorPart()
        {
            var mv = GaSymMultivector.CreateZero(GaSpaceDimension);

            if (TermId.BasisBladeGrade() == 1)
            {
                mv.SetTermCoef(TermId, TermCoef);
            }

            return(mv);
        }
Esempio n. 11
0
        public static GaSymMultivector CreateFromColumn(ISymbolicMatrix matrix, int col)
        {
            Debug.Assert(matrix.RowCount.IsValidGaSpaceDimension());

            var mv = new GaSymMultivector(matrix.RowCount);

            for (var index = 0; index < matrix.RowCount; index++)
            {
                mv.SetTermCoef(index, matrix[index, col]);
            }

            return(mv);
        }
Esempio n. 12
0
        public static GaSymMultivector CreateVectorFromRow(ISymbolicMatrix matrix, int row)
        {
            var gaSpaceDim = matrix.ColumnCount.ToGaSpaceDimension();

            var mv = new GaSymMultivector(gaSpaceDim);

            for (var col = 0; col < matrix.ColumnCount; col++)
            {
                mv.SetTermCoef(1, col, matrix[row, col]);
            }

            return(mv);
        }
Esempio n. 13
0
        public static GaSymMultivector CreateVectorFromColumn(ISymbolicMatrix matrix, int col)
        {
            var gaSpaceDim = matrix.RowCount.ToGaSpaceDimension();

            var mv = new GaSymMultivector(gaSpaceDim);

            for (var row = 0; row < matrix.RowCount; row++)
            {
                mv.SetTermCoef(1, row, matrix[row, col]);
            }

            return(mv);
        }
Esempio n. 14
0
        public static GaSymMultivector CreateVectorFromScalars(Expr[] exprScalars)
        {
            var gaSpaceDim = exprScalars.Length.ToGaSpaceDimension();

            var mv = new GaSymMultivector(gaSpaceDim);

            for (var index = 0; index < exprScalars.Length; index++)
            {
                mv.SetTermCoef(1, index, exprScalars[index]);
            }

            return(mv);
        }
Esempio n. 15
0
        public static GaSymMultivector CreateVectorFromColumn(Expr[,] matrix, int col)
        {
            var rowsCount  = matrix.GetLength(0);
            var gaSpaceDim = rowsCount.ToGaSpaceDimension();

            var mv = new GaSymMultivector(gaSpaceDim);

            for (var row = 0; row < rowsCount; row++)
            {
                mv.SetTermCoef(1, row, matrix[row, col]);
            }

            return(mv);
        }
Esempio n. 16
0
        public static GaSymMultivector SetTerms(this GaSymMultivector mv, ISymbolicVector termsMv)
        {
            for (var id = 0; id < termsMv.Size; id++)
            {
                var coef = termsMv[id].Expression;

                if (!coef.IsNullOrZero())
                {
                    mv.SetTermCoef(id, coef);
                }
            }

            return(mv);
        }
Esempio n. 17
0
        public GaSymMultivector CliffConj()
        {
            var resultMv = new GaSymMultivector(GaSpaceDimension);

            foreach (var term in NonZeroExprTerms)
            {
                resultMv.SetTermCoef(
                    term.Key,
                    term.Key.BasisBladeIdHasNegativeClifConj(),
                    term.Value
                    );
            }

            return(resultMv);
        }
Esempio n. 18
0
        public static IGaSymMultivectorTemp ToTempMultivector(this IGaSymMultivector mv)
        {
            if (ReferenceEquals(mv, null))
            {
                return(null);
            }

            var tempMv = GaSymMultivector.CreateZeroTemp(mv.GaSpaceDimension);

            foreach (var term in mv.NonZeroExprTerms)
            {
                tempMv.SetTermCoef(term.Key, term.Value);
            }

            return(tempMv);
        }
Esempio n. 19
0
        public GaSymMultivector GetKVectorPart(int grade)
        {
            var resultMv = new GaSymMultivector(GaSpaceDimension);

            if (grade < 0 || grade > VSpaceDimension)
            {
                return(resultMv);
            }

            foreach (var term in NonZeroTerms.Where(t => t.Key.BasisBladeGrade() == grade))
            {
                resultMv.SetTermCoef(term.Key, term.Value);
            }

            return(resultMv);
        }
        public IGaSymMultivector this[int id1]
        {
            get
            {
                IGaSymMultivector mv;
                RootNode.TryGetLeafValue((ulong)id1, out mv);

                return(mv);
            }
            set
            {
                RootNode.SetLeafValue(
                    (ulong)id1,
                    value ?? GaSymMultivector.CreateZero(TargetGaSpaceDimension)
                    );
            }
        }
Esempio n. 21
0
        public static GaSymMultivector CreateSymbolic(int gaSpaceDim, string baseCoefName, IEnumerable <int> idsList)
        {
            var resultMv  = new GaSymMultivector(gaSpaceDim);
            var vSpaceDim = gaSpaceDim.ToVSpaceDimension();

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

            return(resultMv);
        }
Esempio n. 22
0
        public static GaSymMultivector CreateFromColumn(Expr[,] exprArray, int col)
        {
            var rows = exprArray.GetLength(0);

            Debug.Assert(rows.IsValidGaSpaceDimension());

            var mv = new GaSymMultivector(rows);

            for (var row = 0; row < rows; row++)
            {
                var expr = exprArray[row, col];

                if (!expr.IsNullOrZero())
                {
                    mv.SetTermCoef(row, expr);
                }
            }

            return(mv);
        }
Esempio n. 23
0
        public static GaSymMultivector CreateFromRow(Expr[,] exprArray, int row)
        {
            var cols = exprArray.GetLength(1);

            Debug.Assert(cols.IsValidGaSpaceDimension());

            var mv = new GaSymMultivector(cols);

            for (var col = 0; col < cols; col++)
            {
                var expr = exprArray[row, col];

                if (!expr.IsNullOrZero())
                {
                    mv.SetTermCoef(col, expr);
                }
            }

            return(mv);
        }
Esempio n. 24
0
        public Dictionary <int, GaSymMultivector> GetKVectorParts()
        {
            var kVectorsList = new Dictionary <int, GaSymMultivector>();

            foreach (var term in NonZeroTerms)
            {
                GaSymMultivector mv;

                var grade = term.Key.BasisBladeGrade();

                if (kVectorsList.TryGetValue(grade, out mv) == false)
                {
                    mv = new GaSymMultivector(GaSpaceDimension);

                    kVectorsList.Add(grade, mv);
                }

                mv.AddFactor(term.Key, term.Value);
            }

            return(kVectorsList);
        }
Esempio n. 25
0
        public static GaSymMultivector CreatePseudoscalar(int gaSpaceDim, MathematicaScalar coef)
        {
            var resultMv = new GaSymMultivector(gaSpaceDim);

            return(resultMv.SetTermCoef(gaSpaceDim - 1, coef.Expression));
        }
Esempio n. 26
0
        public static GaSymMultivector CreateScalar(int gaSpaceDim, Expr coef)
        {
            var resultMv = new GaSymMultivector(gaSpaceDim);

            return(resultMv.SetTermCoef(0, coef));
        }
Esempio n. 27
0
        public static GaSymMultivector CreateUnitScalar(int gaSpaceDim)
        {
            var resultMv = new GaSymMultivector(gaSpaceDim);

            return(resultMv.SetTermCoef(0, Expr.INT_ONE));
        }
Esempio n. 28
0
        public static GaSymMultivector CreateBasisBlade(int gaSpaceDim, int id)
        {
            var resultMv = new GaSymMultivector(gaSpaceDim);

            return(resultMv.SetTermCoef(id, Expr.INT_ONE));
        }
Esempio n. 29
0
 public static IGaSymMultivectorTemp CreateCopyTemp(GaSymMultivector mv)
 {
     return(CreateZeroTemp(mv.GaSpaceDimension).SetTerms(mv));
 }
Esempio n. 30
0
 public static bool IsNullOrNearNumericZero(this GaSymMultivector mv, double epsilon)
 {
     return(ReferenceEquals(mv, null) || mv.IsNearNumericZero(epsilon));
 }