Esempio n. 1
0
 public GaSymMultivector AddFactor(int grade, int index, Expr coef)
 {
     return(AddFactor(
                GMacMathUtils.BasisBladeId(grade, index),
                coef
                ));
 }
 public GMacMultivectorBinding BindCoefToConstant(int grade, int index, Expr valueExpr)
 {
     return(BindCoefToPattern(
                GMacMathUtils.BasisBladeId(grade, index),
                GMacScalarBinding.CreateConstant(BaseFrameMultivector.Root, valueExpr)
                ));
 }
Esempio n. 3
0
 public GaSymMultivector SetTermCoef(int grade, int index, MathematicaScalar coef)
 {
     return(SetTermCoef(
                GMacMathUtils.BasisBladeId(grade, index),
                coef.Expression
                ));
 }
Esempio n. 4
0
 public double this[int grade, int index]
 {
     get
     {
         return(this[GMacMathUtils.BasisBladeId(grade, index)]);
     }
 }
Esempio n. 5
0
 public GaSymMultivector SetTermCoef(int grade, int index, Expr coef)
 {
     return(SetTermCoef(
                GMacMathUtils.BasisBladeId(grade, index),
                coef
                ));
 }
 public GMacMultivectorBinding BindCoefToVariable(int grade, int index)
 {
     return(BindCoefToPattern(
                GMacMathUtils.BasisBladeId(grade, index),
                GMacScalarBinding.CreateVariable(BaseFrameMultivector.Root)
                ));
 }
        public GMacMultivectorBinding UnBindCoefs(int grade, IEnumerable <int> indexes)
        {
            foreach (var index in indexes)
            {
                _patternDictionary.Remove(GMacMathUtils.BasisBladeId(grade, index));
            }

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

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

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

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

                return(coef);
            }
        }
Esempio n. 15
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));
                }
            }
        }
        public Expr this[int grade, int index]
        {
            get
            {
                var id = GMacMathUtils.BasisBladeId(grade, index);

                List <Expr> coef;
                _termsDictionary.TryGetValue(id, out coef);

                return(ReferenceEquals(coef, null)
                    ? Expr.INT_ZERO
                    : coef.Simplify());
            }
        }
        /// <summary>
        /// Create a default subspaces of k-vectors with a given grade and name
        /// </summary>
        private void DefineDefaultSubspaces_KVectors(GMacFrame frame, int grade, string subspaceName)
        {
            var basisCount = GMacMathUtils.KvSpaceDimension(frame.VSpaceDimension, grade);
            var idsList    = new List <int>(basisCount);

            for (var index = 0; index < basisCount; index++)
            {
                idsList.Add(GMacMathUtils.BasisBladeId(grade, index));
            }

            var subspaceSignature = BooleanPattern.CreateFromTrueIndexes(frame.GaSpaceDimension, idsList);

            var subspace = frame.DefineSubspace(subspaceName, subspaceSignature);

            subspace.AddCodeLocation(Context.GetCodeLocation(frame.ParseNode));
        }
Esempio n. 18
0
        public override IEnumerable <Tuple <int, int, IGaNumMultivector> > BasisVectorsMaps()
        {
            for (var index1 = 0; index1 < DomainVSpaceDimension; index1++)
            {
                for (var index2 = 0; index2 < DomainVSpaceDimension2; index2++)
                {
                    var id1 = GMacMathUtils.BasisBladeId(1, index1);
                    var id2 = GMacMathUtils.BasisBladeId(1, index2);
                    var mv  = MapToTerm(id1, id2);

                    if (!mv.IsZero())
                    {
                        yield return(new Tuple <int, int, IGaNumMultivector>(index1, index2, mv));
                    }
                }
            }
        }
Esempio n. 19
0
        public virtual IEnumerable <Tuple <int, int, IGaSymMultivector> > BasisVectorsMaps()
        {
            for (var index1 = 0; index1 < DomainVSpaceDimension; index1++)
            {
                for (var index2 = 0; index2 < DomainVSpaceDimension; index2++)
                {
                    var id1 = GMacMathUtils.BasisBladeId(1, index1);
                    var id2 = GMacMathUtils.BasisBladeId(1, index2);
                    var mv  = this[id1, id2];

                    if (!mv.IsNullOrZero())
                    {
                        yield return(new Tuple <int, int, IGaSymMultivector>(index1, index2, mv));
                    }
                }
            }
        }
Esempio n. 20
0
        private void GenerateTransposeOutermorphismMacro(AstFrame frameInfo)
        {
            var inputsText = ComposeMacroInputs(
                "om", DefaultStructure.Outermorphism
                );

            var commandsList = GMacDslSyntaxFactory.SyntaxElementsList(
                GMacDslSyntaxFactory.DeclareLocalVariable(DefaultStructure.Outermorphism, "newOm"),
                GMacDslSyntaxFactory.EmptyLine()
                );

            var componentsText = new ListComposer("," + Environment.NewLine);

            for (var index1 = 1; index1 <= frameInfo.VSpaceDimension; index1++)
            {
                componentsText.Clear();

                var id1 = GMacMathUtils.BasisBladeId(1, index1 - 1);

                commandsList.AddFixedCode("let newOm.ImageV" + index1 + " = Multivector(");

                for (var index2 = 1; index2 <= frameInfo.VSpaceDimension; index2++)
                {
                    var id2 = GMacMathUtils.BasisBladeId(1, index2 - 1);

                    componentsText.Add("    #E" + id2 + "# = om.ImageV" + index2 + ".#E" + id1 + "#");
                }

                commandsList.AddFixedCode(componentsText.ToString());

                commandsList.AddFixedCode(")");
                commandsList.AddEmptyLine();
            }

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

            GenerateMacro(
                frameInfo,
                DefaultMacro.Outermorphism.Transpose,
                inputsText,
                DefaultStructure.Outermorphism,
                commandsText,
                "newOm"
                );
        }
Esempio n. 21
0
        public GaNumMultivector SetTermCoef(int grade, int index, bool isNegative, double coef)
        {
            var id = GMacMathUtils.BasisBladeId(grade, index);

            var value = isNegative ? -coef : coef;

            var node = TermsTree;

            for (var i = VSpaceDimension - 1; i > 0; i--)
            {
                var bitPattern = (1 << i) & id;
                node = node.GetOrAddInternalChildNode(bitPattern != 0);
            }

            if ((1 & id) != 0)
            {
                if (node.HasChildNode1)
                {
                    node.LeafChildNode1.Value = value;
                }
                else
                {
                    node.ResetLeafChildNode1(value);
                }

                return(this);
            }

            if (node.HasChildNode0)
            {
                node.LeafChildNode0.Value = value;
            }
            else
            {
                node.ResetLeafChildNode0(value);
            }

            return(this);
        }
Esempio n. 22
0
        public GaNumMultivector AddFactor(int grade, int index, double coef)
        {
            AddFactorsCallCount++;

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

            var node = TermsTree;

            for (var i = VSpaceDimension - 1; i > 0; i--)
            {
                var bitPattern = (1 << i) & id;
                node = node.GetOrAddInternalChildNode(bitPattern != 0);
            }

            if ((1 & id) != 0)
            {
                if (node.HasChildNode1)
                {
                    node.LeafChildNode1.Value += coef;
                }
                else
                {
                    node.ResetLeafChildNode1(coef);
                }

                return(this);
            }

            if (node.HasChildNode0)
            {
                node.LeafChildNode0.Value += coef;
            }
            else
            {
                node.ResetLeafChildNode0(coef);
            }

            return(this);
        }
        /// <summary>
        /// Create the default subspace of odd multivectors named @odd@
        /// </summary>
        /// <returns></returns>
        private GMacFrameSubspace DefineDefaultSubspaces_Odd(GMacFrame frame)
        {
            var idsList = new List <int>(frame.GaSpaceDimension);

            for (var grade = 1; grade <= frame.VSpaceDimension; grade = grade + 2)
            {
                var basisCount = GMacMathUtils.KvSpaceDimension(frame.VSpaceDimension, grade);

                for (var index = 0; index < basisCount; index++)
                {
                    idsList.Add(GMacMathUtils.BasisBladeId(grade, index));
                }
            }

            const string subspaceName      = "Odd";
            var          subspaceSignature = BooleanPattern.CreateFromTrueIndexes(frame.GaSpaceDimension, idsList);

            var subspace = frame.DefineSubspace(subspaceName, subspaceSignature);

            subspace.AddCodeLocation(Context.GetCodeLocation(frame.ParseNode));

            return(subspace);
        }
Esempio n. 24
0
 public Expr this[int grade, int index]
 => this[GMacMathUtils.BasisBladeId(grade, index)];
Esempio n. 25
0
 public double this[int grade, int index]
 => _termsArray[GMacMathUtils.BasisBladeId(grade, index)];
 public Expr this[int grade, int index]
 => _coefsArray[GMacMathUtils.BasisBladeId(grade, index)].Simplify();
Esempio n. 27
0
        public GMacMultivectorBinding UnBindCoef(int grade, int index)
        {
            _patternDictionary.Remove(GMacMathUtils.BasisBladeId(grade, index));

            return(this);
        }
Esempio n. 28
0
 public string BasisBladeName(int grade, int index)
 {
     return(AssociatedFrame.BasisVectorNames.ConcatenateUsingPattern(
                GMacMathUtils.BasisBladeId(grade, index), "E0", "^"
                ));
 }
Esempio n. 29
0
 internal AstFrameBasisBlade(GMacFrame frame, int grade, int index)
 {
     AssociatedMultivector = frame.MultivectorType;
     BasisBladeId          = GMacMathUtils.BasisBladeId(grade, index);
 }
Esempio n. 30
0
 public IGaSymMultivector this[int grade1, int index1]
 => this[GMacMathUtils.BasisBladeId(grade1, index1)];