private static string EuclideanBilinearProductTable(int[] basisBladeIds, Func <int, int, bool> isZeroFunc)
        {
            var composer = new TableComposer(basisBladeIds.Length, basisBladeIds.Length);

            for (var r = 0; r < basisBladeIds.Length; r++)
            {
                var id1 = basisBladeIds[r];
                composer.ColumnsInfo[r].Header = id1.BasisBladeName();
                composer.RowsInfo[r].Header    = id1.BasisBladeName();

                for (var c = 0; c < basisBladeIds.Length; c++)
                {
                    var id2 = basisBladeIds[c];

                    //var isNegative = MultivectorUtils.ComputeIsNegativeEGp(id1, id2);
                    var isNegative = FrameUtils.IsNegativeEGp(id1, id2);

                    var name = isZeroFunc(id1, id2)
                        ? "0"
                        : ((isNegative ? "-" : "") + (id1 ^ id2).BasisBladeName());

                    composer.Items[r, c] = name;
                }
            }

            return(composer.ToString());
        }
Example #2
0
        //TODO: This requires more acceleration (try to build the expressions then evaluate once per basis blade id for result_mv)
        //private GAMultivectorCoefficients BilinearProduct(GAMultivectorCoefficients mv1, GAMultivectorCoefficients mv2, Func<int, int, bool> term_discard_function)
        //{
        //    if (mv1.GASpaceDim != mv2.GASpaceDim || mv1.GASpaceDim != GASpaceDim)
        //        throw new GMacSymbolicException("Multivector size mismatch");

        //    GAMultivectorCoefficients mv = GAMultivectorCoefficients.CreateZero(mv1.GASpaceDim);

        //    foreach (var term1 in mv1)
        //    {
        //        int id1 = term1.Key;
        //        MathematicaScalar coef1 = term1.Value;

        //        foreach (var term2 in mv2.FilterTermsUsing(id1, term_discard_function))
        //        {
        //            int id2 = term2.Key;
        //            MathematicaScalar coef2 = term2.Value;

        //            int id = id1 ^ id2;

        //            if (GAUtils.IDs_To_EGP_Sign(id1, id2))
        //                mv[id] -= coef1 * coef2 * _BasisBladesSignatures[id];
        //            else
        //                mv[id] += coef1 * coef2 * _BasisBladesSignatures[id];
        //        }
        //    }

        //    return mv;
        //}
        private GaMultivector BilinearProduct(GaMultivector mv1, GaMultivector mv2, Func <int, int, bool> termDiscardFunction)
        {
            if (mv1.GaSpaceDim != mv2.GaSpaceDim || mv1.GaSpaceDim != GaSpaceDimension)
            {
                throw new GMacSymbolicException("Multivector size mismatch");
            }

            var terms1 = mv1.ToStringsDictionary();

            var terms2 = mv2.ToStringsDictionary();

            var accumExprDict = new Dictionary <int, ListComposer>();

            foreach (var term1 in terms1)
            {
                var id1   = term1.Key;
                var coef1 = term1.Value;

                foreach (var term2 in terms2.FilterTermsUsing(id1, termDiscardFunction))
                {
                    var id2   = term2.Key;
                    var coef2 = term2.Value;

                    var resultId = id1 ^ id2;
                    var sigId    = id1 & id2;

                    var resultCoefDelta =
                        EuclideanUtils.Times(
                            coef1,
                            coef2,
                            _basisBladesSignatures[sigId].MathExpr.ToString(),
                            FrameUtils.IsNegativeEGp(id1, id2)
                            );

                    accumExprDict.AddTerm(resultId, resultCoefDelta);
                }
            }

            return(accumExprDict.ToMultivector(mv1.GaSpaceDim));
        }