コード例 #1
0
ファイル: CRTBaseMath.cs プロジェクト: Eric7Apps/BlogSource
        // Copyright Eric Chauvin.
        internal void ModularReduction( ChineseRemainder CRTInput,
                                  ChineseRemainder CRTAccumulate )
        {
            try
            {
            if( NumbersArray == null )
              throw( new Exception( "Bug: The NumbersArray should have been set up already." ));

            if( CRTBaseModArray == null )
              throw( new Exception( "Bug: The BaseModArray should have been set up already." ));

            // This first one has the prime 2 as its base so it's going to
            // be set to either zero or one.
            if( CRTInput.GetDigitAt( 0 ) == 1 )
              {
              CRTAccumulate.SetToOne();
              }
            else
              {
              CRTAccumulate.SetToZero();
              }

            CRTBase CRTBaseInput = new CRTBase( IntMath );
            int HowManyToAdd = SetFromCRTNumber( CRTBaseInput, CRTInput );

            // Integer Test = new Integer();
            // ChineseRemainder CRTTest = new ChineseRemainder( IntMath );
            // GetTraditionalInteger( CRTBaseInput, Test );
            // CRTTest.SetFromTraditionalInteger( Test );
            // if( !CRTTest.IsEqual( CRTInput ))
              // throw( new Exception( "CRTTest for CRTInput isn't right." ));

            // Count starts at 1, so it's the prime 3.
            for( int Count = 1; Count <= HowManyToAdd; Count++ )
              {
              // BaseMultiple is a number that is not bigger
              // than the prime at this point.  (The prime at:
              // IntMath.GetPrimeAt( Count ).)
              uint BaseMultiple = (uint)CRTBaseInput.GetDigitAt( Count );

              // It uses the CRTBaseModArray here:
              CRTWorkingTemp.Copy( CRTBaseModArray[Count] );
              CRTWorkingTemp.Multiply( NumbersArray[BaseMultiple] );
              CRTAccumulate.Add( CRTWorkingTemp );
              }
            }
            catch( Exception Except )
              {
              throw( new Exception( "Exception in ModularReduction(): " + Except.Message ));
              }
        }
コード例 #2
0
ファイル: CRTBaseMath.cs プロジェクト: Eric7Apps/BlogSource
        internal void GetExponentForm( CRTBase ToGetFrom, uint BaseVal )
        {
            try
            {
            if( CRTBaseArray == null )
              throw( new Exception( "Bug: The BaseArray should have been set up already." ));

            StringBuilder SBuilder = new StringBuilder();

            string BaseS = BaseVal.ToString();
            // This first one has the prime 2 as its base so
            // it's going to be set to either zero or one.
            if( ToGetFrom.GetDigitAt( 0 ) == 1 )
              SBuilder.Append( "(" + BaseS + "^1) " );
            else
              SBuilder.Append( "(" + BaseS + "^0) " );

            Integer WorkingBase = new Integer();
            for( int Count = 1; Count < ChineseRemainder.DigitsArraySize; Count++ )
              {
              int BaseMult = ToGetFrom.GetDigitAt( Count );
              if( BaseMult == 0 )
            continue;

              // WorkingBase.Copy( BaseArray[Count] );
              SBuilder.Append( "(" + BaseS + "^(" + BaseMult.ToString() + "*(" + BaseStringsArray[Count] + "))) " );

              // IntMath.MultiplyUInt( WorkingBase, (uint)BaseMult );
              // ToSet.Add( WorkingBase );
              }

            Worker.ReportProgress( 0, SBuilder.ToString() );

            }
            catch( Exception Except )
              {
              throw( new Exception( "Exception in GetExponentForm(): " + Except.Message ));
              }
        }
コード例 #3
0
ファイル: CRTBaseMath.cs プロジェクト: Eric7Apps/BlogSource
        internal void GetTraditionalInteger( CRTBase ToGetFrom, Integer ToSet )
        {
            try
            {
            if( CRTBaseArray == null )
              throw( new Exception( "Bug: The BaseArray should have been set up already." ));

            // This first one has the prime 2 as its base so
            // it's going to be set to either zero or one.
            if( ToGetFrom.GetDigitAt( 0 ) == 1 )
              ToSet.SetToOne();
            else
              ToSet.SetToZero();

            Integer WorkingBase = new Integer();
            for( int Count = 1; Count < ChineseRemainder.DigitsArraySize; Count++ )
              {
              int BaseMult = ToGetFrom.GetDigitAt( Count );
              WorkingBase.Copy( BaseArray[Count] );
              IntMath.MultiplyUInt( WorkingBase, (uint)BaseMult );
              ToSet.Add( WorkingBase );
              }
            }
            catch( Exception Except )
              {
              throw( new Exception( "Exception in GetTraditionalInteger(): " + Except.Message ));
              }
        }