Ejemplo n.º 1
0
        /// <summary>
        /// Compute and fill all GA lookup tables
        /// </summary>
        private static void ComputeGaLookupTables()
        {
            const int c          = 1;
            const int d          = 1;
            var       gaSpaceDim = (c << GMacMathUtils.MaxVSpaceDimension);
            var       maxId      = gaSpaceDim - 1;
            var       gradeCount = new int[GMacMathUtils.MaxVSpaceDimension + 1];

            //Initialize all tables
            IdToGradeTable          = new int[gaSpaceDim];
            IdToIndexTable          = new int[gaSpaceDim];
            IsNegativeReverseTable  = new BitArray(gaSpaceDim);
            IsNegativeGradeInvTable = new BitArray(gaSpaceDim);
            IsNegativeClifConjTable = new BitArray(gaSpaceDim);
            IsNegativeEGpTable      = new BitArray(d << (2 * GMacMathUtils.MaxVSpaceDimension));
            GradeIndexToIdTable     = new List <int[]>(GMacMathUtils.MaxVSpaceDimension);

            //var stopWatch = new Stopwatch();
            //long ticks = 0;

            for (var id = 0; id <= maxId; id++)
            {
                var grade = id.CountOnes();

                IdToGradeTable[id] = grade;

                //Calculate grade inversion sign
                if (grade.GradeHasNegativeGradeInv())
                {
                    IsNegativeGradeInvTable.Set(id, true);
                }

                //Calculate reversion sign
                if (grade.GradeHasNegativeReverse())
                {
                    IsNegativeReverseTable.Set(id, true);
                }

                //Calculate Clifford conjugate sign
                if (grade.GradeHasNegativeClifConj())
                {
                    IsNegativeClifConjTable.Set(id, true);
                }

                //Calculate index of basis blade ID
                IdToIndexTable[id] = gradeCount[grade];

                gradeCount[grade] += 1;


                //stopWatch.Start();

                //Calculate the sign of the geometric product of basis blades
                var id1 = id;

                for (var id2 = 0; id2 <= maxId; id2++)
                {
                    if (GMacMathUtils.ComputeIsNegativeEGp(id1, id2))
                    {
                        IsNegativeEGpTable.Set(GMacMathUtils.JoinIDs(id1, id2), true);
                    }
                }

                //stopWatch.Stop();
                //ticks += stopWatch.ElapsedTicks;
            }

            //MessageBox.Show(ticks.ToString("###,###,###,###,###"));

            //Calculate inverse index table: (grade, index) to ID table
            gradeCount = new int[gaSpaceDim];

            for (var id = 0; id <= maxId; id++)
            {
                var grade = IdToGradeTable[id];
                var index = gradeCount[grade];

                gradeCount[grade] += 1;

                if (gradeCount[grade] == 1)
                {
                    GradeIndexToIdTable.Add(new int[Choose(GMacMathUtils.MaxVSpaceDimension, grade)]);
                }

                GradeIndexToIdTable[grade][index] = id;
            }
        }