예제 #1
0
 public GMacMultivectorBinding BindBasisVectorCoefToConstant(int index, Expr valueExpr)
 {
     return(BindCoefToPattern(
                GMacMathUtils.BasisVectorId(index),
                GMacScalarBinding.CreateConstant(BaseFrameMultivector.Root, valueExpr)
                ));
 }
예제 #2
0
 public GaSymMultivector SetTermCoef(int grade, int index, Expr coef)
 {
     return(SetTermCoef(
                GMacMathUtils.BasisBladeId(grade, index),
                coef
                ));
 }
예제 #3
0
 public GaSymMultivector SetTermCoef(int grade, int index, MathematicaScalar coef)
 {
     return(SetTermCoef(
                GMacMathUtils.BasisBladeId(grade, index),
                coef.Expression
                ));
 }
예제 #4
0
 public GMacMultivectorBinding BindBasisVectorCoefToVariable(int index)
 {
     return(BindCoefToPattern(
                GMacMathUtils.BasisVectorId(index),
                GMacScalarBinding.CreateVariable(BaseFrameMultivector.Root)
                ));
 }
예제 #5
0
        private void GenerateApplyOutermorphismToVectorMacro(AstFrame frameInfo)
        {
            var inputsText = ComposeMacroInputs(
                "om", DefaultStructure.Outermorphism,
                "mv", frameInfo.FrameMultivector.Name
                );

            var commandsList = GMacDslSyntaxFactory.SyntaxElementsList(
                GMacDslSyntaxFactory.AssignToLocalVariable("imageMv", "mv.#E1# * om.ImageV1.@G1@")
                );

            for (var index = 2; index <= frameInfo.VSpaceDimension; index++)
            {
                var id = GMacMathUtils.BasisVectorId(index - 1);

                commandsList.Add(
                    GMacDslSyntaxFactory.AssignToLocalVariable(
                        "imageMv",
                        "imageMv + mv.#E" + id + "# * om.ImageV" + index + ".@G1@"
                        )
                    );
            }

            commandsList.AddEmptyLine();

            var commandsText = GMacLanguage.CodeGenerator.GenerateCode(commandsList);

            GenerateMacro(
                frameInfo,
                DefaultMacro.Outermorphism.ApplyToVector,
                inputsText,
                commandsText,
                "imageMv"
                );
        }
예제 #6
0
        public override string ToString()
        {
            var tableText     = new TableComposer(TargetGaSpaceDimension, TargetGaSpaceDimension);
            var basisBladeIds = GMacMathUtils.BasisBladeIDs(TargetVSpaceDimension).ToArray();

            foreach (var basisBladeId in basisBladeIds)
            {
                tableText.ColumnsInfo[basisBladeId].Header = basisBladeId.BasisBladeName();
                tableText.RowsInfo[basisBladeId].Header    = basisBladeId.BasisBladeName();
            }

            for (var basisBladeId1 = 0; basisBladeId1 < TargetGaSpaceDimension; basisBladeId1++)
            {
                for (var basisBladeId2 = 0; basisBladeId2 < TargetGaSpaceDimension; basisBladeId2++)
                {
                    var mv = _basisBladesMaps[basisBladeId1, basisBladeId2];
                    if (mv != null)
                    {
                        tableText.Items[basisBladeId1, basisBladeId2] = mv.ToString();
                    }
                }
            }

            var text = tableText.ToString();

            return(text);
        }
예제 #7
0
 public GaSymMultivector AddFactor(int grade, int index, Expr coef)
 {
     return(AddFactor(
                GMacMathUtils.BasisBladeId(grade, index),
                coef
                ));
 }
예제 #8
0
 public double this[int grade, int index]
 {
     get
     {
         return(this[GMacMathUtils.BasisBladeId(grade, index)]);
     }
 }
예제 #9
0
        public static GaNumMetricOrthonormal Create(IReadOnlyList <int> basisVectorsSignaturesList)
        {
            var vSpaceDim = basisVectorsSignaturesList.Count;
            var bbsList   = new GaNumMetricOrthonormal(vSpaceDim);

            bbsList[0] = 1;

            for (var m = 0; m < vSpaceDim; m++)
            {
                var bvs = basisVectorsSignaturesList[m];

                if (bvs == 0)
                {
                    continue;
                }

                bbsList[1 << m] = bvs;
            }

            var idsSeq = GMacMathUtils.BasisBladeIDsSortedByGrade(vSpaceDim, 2);

            foreach (var id in idsSeq)
            {
                int id1, id2;
                id.SplitBySmallestBasisVectorId(out id1, out id2);

                bbsList[id] = bbsList[id1] * bbsList[id2];
            }

            return(bbsList);
        }
예제 #10
0
 public static GaSymMultivector CreateSymbolicKVector(int gaSpaceDim, string baseCoefName, int grade)
 {
     return(CreateSymbolic(
                gaSpaceDim,
                baseCoefName,
                GMacMathUtils.BasisBladeIDsOfGrade(gaSpaceDim.ToVSpaceDimension(), grade)
                ));
 }
예제 #11
0
 public override GaSymMultivectorTerm MapToTerm(int id1, int id2)
 {
     return(GaSymMultivectorTerm.CreateTerm(
                TargetGaSpaceDimension,
                id1 ^ id2,
                GMacMathUtils.IsNegativeEGp(id1, id2) ? Expr.INT_MINUSONE : Expr.INT_ONE
                ));
 }
예제 #12
0
 public override GaNumMultivectorTerm MapToTerm(int id1, int id2)
 {
     return(GaNumMultivectorTerm.CreateTerm(
                TargetGaSpaceDimension,
                id1 ^ id2,
                GMacMathUtils.IsNegativeEGp(id1, id2) ? -1.0d : 1.0d
                ));
 }
예제 #13
0
        public GMacMultivectorBinding UnBindCoefs(int grade, IEnumerable <int> indexes)
        {
            foreach (var index in indexes)
            {
                _patternDictionary.Remove(GMacMathUtils.BasisBladeId(grade, index));
            }

            return(this);
        }
예제 #14
0
        public Expr this[int grade, int index]
        {
            get
            {
                var id = GMacMathUtils.BasisBladeId(grade, index);

                return((id == TermId) ? TermCoef : Expr.INT_ZERO);
            }
        }
예제 #15
0
        public double this[int grade, int index]
        {
            get
            {
                var id = GMacMathUtils.BasisBladeId(grade, index);

                return((id == TermId) ? TermCoef : 0.0d);
            }
        }
예제 #16
0
        private void GenerateOutermorphismToLinearTransformMacro(AstFrame frameInfo)
        {
            var commandsList = GMacDslSyntaxFactory.SyntaxElementsList(
                GMacDslSyntaxFactory.DeclareLocalVariable(DefaultStructure.LinearTransform, "newTr"),
                GMacDslSyntaxFactory.EmptyLine(),
                GMacDslSyntaxFactory.FixedCode("let newTr.ImageE0 = Multivector(#E0# = '1')"),
                GMacDslSyntaxFactory.EmptyLine()
                );

            for (var index = 1; index <= frameInfo.VSpaceDimension; index++)
            {
                var id = GMacMathUtils.BasisVectorId(index - 1);

                commandsList.Add(
                    GMacDslSyntaxFactory.AssignToLocalVariable(
                        "newTr.ImageE" + id,
                        "om.ImageV" + index + ".@G1@"
                        )
                    );
            }

            commandsList.AddEmptyLine();

            for (var grade = 2; grade <= frameInfo.VSpaceDimension; grade++)
            {
                var kvSpaceDim = frameInfo.KvSpaceDimension(grade);

                for (var index = 0; index < kvSpaceDim; index++)
                {
                    int id = GMacMathUtils.BasisBladeId(grade, index);
                    int id1, id2;

                    id.SplitBySmallestBasisVectorId(out id1, out id2);

                    commandsList.Add(
                        GMacDslSyntaxFactory.AssignToLocalVariable(
                            "newTr.ImageE" + id,
                            " newTr.ImageE" + id1 + " op newTr.ImageE" + id2
                            )
                        );
                }

                commandsList.AddEmptyLine();
            }

            var commandsText = GMacLanguage.CodeGenerator.GenerateCode(commandsList);

            GenerateMacro(
                frameInfo,
                DefaultMacro.Outermorphism.ToLinearTransform,
                ComposeMacroInputs("om", DefaultStructure.Outermorphism),
                DefaultStructure.LinearTransform,
                commandsText,
                "newTr"
                );
        }
예제 #17
0
 public override GaNumMultivectorTerm MapToTerm(int id1, int id2)
 {
     return(GaNumMultivectorTerm.CreateTerm(
                TargetGaSpaceDimension,
                id1 ^ id2,
                GMacMathUtils.IsNegativeEGp(id1, id2)
             ? -OrthogonalMetric[id1 & id2]
             : OrthogonalMetric[id1 & id2]
                ));
 }
예제 #18
0
        public GaNumMultivector GetNumTerm(int gaSpaceDim, int grade, int index)
        {
            var mv = GaNumMultivector.CreateZero(gaSpaceDim);

            var basisBladeId = GMacMathUtils.BasisBladeId(grade, index);

            mv.SetTermCoef(basisBladeId, GetScalar());

            return(mv);
        }
예제 #19
0
 public override GaSymMultivectorTerm MapToTerm(int id1, int id2)
 {
     return(GaSymMultivectorTerm.CreateTerm(
                TargetGaSpaceDimension,
                id1 ^ id2,
                GMacMathUtils.IsNegativeEGp(id1, id2)
             ? Mfs.Minus[OrthonormalMetric.GetExprSignature(id1 & id2)]
             : OrthonormalMetric.GetExprSignature(id1 & id2)
                ));
 }
예제 #20
0
        public GaSymMultivector GetSymTerm(int gaSpaceDim, int grade, int index, double minValue, double maxValue)
        {
            var mv = GaSymMultivector.CreateZero(gaSpaceDim);

            var basisBladeId = GMacMathUtils.BasisBladeId(grade, index);

            mv.SetTermCoef(basisBladeId, GetSymbolicScalar(minValue, maxValue));

            return(mv);
        }
예제 #21
0
 public Expr this[int grade, int index]
 {
     get
     {
         return(this[GMacMathUtils.BasisBladeId(grade, index)]);
     }
     set
     {
         this[GMacMathUtils.BasisBladeId(grade, index)] = value;
     }
 }
예제 #22
0
        public GaSymMultivector GetSymIntegerKVector(int gaSpaceDim, int grade, int minValue, int maxValue)
        {
            var mv = GaSymMultivector.CreateZero(gaSpaceDim);

            foreach (var basisBladeId in GMacMathUtils.BasisBladeIDsOfGrade(mv.VSpaceDimension, grade))
            {
                mv.SetTermCoef(basisBladeId, GetIntegerExpr(minValue, maxValue));
            }

            return(mv);
        }
예제 #23
0
        public GaNumMultivector GetNumVector(int gaSpaceDim)
        {
            var mv = GaNumMultivector.CreateZero(gaSpaceDim);

            foreach (var basisBladeId in GMacMathUtils.BasisBladeIDsOfGrade(mv.VSpaceDimension, 1))
            {
                mv.SetTermCoef(basisBladeId, GetScalar());
            }

            return(mv);
        }
예제 #24
0
        public GaSymMultivector GetSymKVector(int gaSpaceDim, int grade, double maxValue)
        {
            var mv = GaSymMultivector.CreateZero(gaSpaceDim);

            foreach (var basisBladeId in GMacMathUtils.BasisBladeIDsOfGrade(mv.VSpaceDimension, grade))
            {
                mv.SetTermCoef(basisBladeId, GetSymbolicScalar(maxValue));
            }

            return(mv);
        }
예제 #25
0
 public override GaNumMultivectorTerm MapToTerm(int id1, int id2)
 {
     return(GaNumMultivectorTerm.CreateTerm(
                TargetGaSpaceDimension,
                0,
                GMacMathUtils.IsNonZeroESp(id1, id2)
             ? (GMacMathUtils.IsNegativeEGp(id1, id1)
                 ? -OrthogonalMetric[id1]
                 : OrthogonalMetric[id1])
             : 0.0d
                ));
 }
예제 #26
0
 public override GaSymMultivectorTerm MapToTerm(int id1, int id2)
 {
     return(GaSymMultivectorTerm.CreateTerm(
                TargetGaSpaceDimension,
                id1 ^ id2,
                GMacMathUtils.IsNonZeroEHip(id1, id2)
             ? (GMacMathUtils.IsNegativeEGp(id1, id2)
                 ? Mfs.Minus[OrthogonalMetric[id1 & id2]]
                 : OrthogonalMetric[id1 & id2])
             : Expr.INT_ZERO
                ));
 }
예제 #27
0
        public virtual IEnumerable <Tuple <int, IGaSymMultivector> > BasisVectorMaps()
        {
            for (var index = 0; index < DomainVSpaceDimension; index++)
            {
                var mv = this[GMacMathUtils.BasisBladeId(1, index)];

                if (!mv.IsNullOrZero())
                {
                    yield return(new Tuple <int, IGaSymMultivector>(index, mv));
                }
            }
        }
예제 #28
0
        public Expr[] KVectorPartToColumnVector(int grade)
        {
            var columnVectorLength = GMacMathUtils.KvSpaceDimension(VSpaceDimension, grade);
            var columnVector       = new Expr[columnVectorLength];

            for (var index = 0; index < columnVectorLength; index++)
            {
                columnVector[index] = this[grade, index];
            }

            return(columnVector);
        }
예제 #29
0
        public double this[int grade, int index]
        {
            get
            {
                var id = GMacMathUtils.BasisBladeId(grade, index);

                double coef;
                _termsDictionary.TryGetValue(id, out coef);

                return(coef);
            }
        }
예제 #30
0
 public override GaSymMultivectorTerm MapToTerm(int id1, int id2)
 {
     return(GaSymMultivectorTerm.CreateTerm(
                TargetGaSpaceDimension,
                0,
                GMacMathUtils.IsNonZeroESp(id1, id2)
             ? (GMacMathUtils.IsNegativeEGp(id1, id1)
                 ? Mfs.Minus[OrthonormalMetric.GetExprSignature(id1)]
                 : OrthonormalMetric.GetExprSignature(id1))
             : Expr.INT_ZERO
                ));
 }