Exemplo n.º 1
0
 public GMacMultivectorBinding BindBasisVectorCoefToConstant(int index, Expr valueExpr)
 {
     return(BindCoefToPattern(
                GMacMathUtils.BasisVectorId(index),
                GMacScalarBinding.CreateConstant(BaseFrameMultivector.Root, valueExpr)
                ));
 }
Exemplo n.º 2
0
 public GaSymMultivector SetTermCoef(int grade, int index, Expr coef)
 {
     return(SetTermCoef(
                GMacMathUtils.BasisBladeId(grade, index),
                coef
                ));
 }
Exemplo n.º 3
0
 public GaSymMultivector SetTermCoef(int grade, int index, MathematicaScalar coef)
 {
     return(SetTermCoef(
                GMacMathUtils.BasisBladeId(grade, index),
                coef.Expression
                ));
 }
Exemplo n.º 4
0
 public GMacMultivectorBinding BindBasisVectorCoefToVariable(int index)
 {
     return(BindCoefToPattern(
                GMacMathUtils.BasisVectorId(index),
                GMacScalarBinding.CreateVariable(BaseFrameMultivector.Root)
                ));
 }
Exemplo n.º 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"
                );
        }
Exemplo n.º 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);
        }
Exemplo n.º 7
0
 public GaSymMultivector AddFactor(int grade, int index, Expr coef)
 {
     return(AddFactor(
                GMacMathUtils.BasisBladeId(grade, index),
                coef
                ));
 }
Exemplo n.º 8
0
 public double this[int grade, int index]
 {
     get
     {
         return(this[GMacMathUtils.BasisBladeId(grade, index)]);
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 10
0
 public static GaSymMultivector CreateSymbolicKVector(int gaSpaceDim, string baseCoefName, int grade)
 {
     return(CreateSymbolic(
                gaSpaceDim,
                baseCoefName,
                GMacMathUtils.BasisBladeIDsOfGrade(gaSpaceDim.ToVSpaceDimension(), grade)
                ));
 }
Exemplo n.º 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
                ));
 }
Exemplo n.º 12
0
 public override GaNumMultivectorTerm MapToTerm(int id1, int id2)
 {
     return(GaNumMultivectorTerm.CreateTerm(
                TargetGaSpaceDimension,
                id1 ^ id2,
                GMacMathUtils.IsNegativeEGp(id1, id2) ? -1.0d : 1.0d
                ));
 }
Exemplo n.º 13
0
        public GMacMultivectorBinding UnBindCoefs(int grade, IEnumerable <int> indexes)
        {
            foreach (var index in indexes)
            {
                _patternDictionary.Remove(GMacMathUtils.BasisBladeId(grade, index));
            }

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

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

                return((id == TermId) ? TermCoef : 0.0d);
            }
        }
Exemplo n.º 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"
                );
        }
Exemplo n.º 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]
                ));
 }
Exemplo n.º 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);
        }
Exemplo n.º 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)
                ));
 }
Exemplo n.º 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);
        }
Exemplo n.º 21
0
 public Expr this[int grade, int index]
 {
     get
     {
         return(this[GMacMathUtils.BasisBladeId(grade, index)]);
     }
     set
     {
         this[GMacMathUtils.BasisBladeId(grade, index)] = value;
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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
                ));
 }
Exemplo n.º 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
                ));
 }
Exemplo n.º 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));
                }
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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
                ));
 }