예제 #1
0
        }     // end : Prune_and_RationalReduce_test()

        /// <summary>
        /// perform a single test only, on a factorization provided by the tester-programmer, as a single long[,] tensor.
        /// Prune_and_RationalReduce_test() : receive a single long[,] tensor.
        /// </summary>
        /// <param name="myFactorization"></param>
        /// <param name="cardTests"></param>
        /// <param name="fixesEpsilon"></param>
        /// <param name="verbosity"></param>
        public static void Prune_and_RationalReduce_test(long[,] SignedArray, double fixedEpsilon, bool ForceVerbosity)
        {
            bool mustLog = false;// activated on error or on request.

            System.Text.StringBuilder resultLogger = new System.Text.StringBuilder();
            resultLogger.Append("\r\n\r\n@@@@@--- start SINGLE test  ");
            resultLogger.Append(" ----@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r\n");
            resultLogger.Append("\r\n  the provided long[,] tensor is : ");
            resultLogger.Append(SignedArray);// present the isolated factorization. ///// TODO
            //
            // tests on pruning
            double totalPrePrune = RealField.TestsOnRationals.mulUp(SignedArray);

            resultLogger.Append("\r\n  the MonteCarlo extracted stringFactor TOTAL is : ");
            resultLogger.Append(totalPrePrune.ToString());
            resultLogger.Append("\r\n original input for pruning");
            resultLogger.Append(GenericTensor_Publisher_onStringBuilder("the Signed Array : ", SignedArray));
            RealField.PruningInstrument thePruner_method = new RealField.PruningInstrument(SignedArray);
            RealField.PruningResults    prunRes          = thePruner_method.Prune();
            resultLogger.Append("\r\n  the pruned Ratio ");
            resultLogger.Append(GenericTensor_Publisher_onStringBuilder("prunRes.tensor_Num ", prunRes.tensor_Num));
            resultLogger.Append(GenericTensor_Publisher_onStringBuilder("prunRes.tensor_Den ", prunRes.tensor_Den));
            double numPostPrune          = RealField.TestsOnRationals.mulUp(prunRes.tensor_Num);
            double denPostPrune          = RealField.TestsOnRationals.mulUp(prunRes.tensor_Den);
            double totalAfterPrune       = numPostPrune / denPostPrune;
            double AnalyzedObj_Magnitudo = getMagnitudoOrder(totalPrePrune);
            double Error_Magnitudo       = getMagnitudoOrder(Math.Abs(totalPrePrune - totalAfterPrune));
            int    figureNonDisponibili  = (int)AnalyzedObj_Magnitudo - 15;              // figure non rappresentabili, i.e. errore
            double curEpsilon            = +9.0 * Math.Pow(+10.0, figureNonDisponibili); // la figura sulla quale si manifesta l'errore e' disponibileper tutta la sua magnitudo( i.e. fino al "9").

            // log for error on Prune ----------------
            resultLogger.Append("\r\n error on Prune : Abs(totalPrePrune - totalAfterPrune)== ");
            resultLogger.Append(Math.Abs(totalPrePrune - totalAfterPrune).ToString());
            resultLogger.Append("\r\n AnalyzedObj_Magnitudo==");
            resultLogger.Append(AnalyzedObj_Magnitudo.ToString());
            resultLogger.Append("\r\n Error_Magnitudo==");
            resultLogger.Append(Error_Magnitudo.ToString());
            resultLogger.Append("\r\n\r\n");
            // end : log for error on Prune ----------------
            //
            if (Math.Abs(totalPrePrune - totalAfterPrune) < curEpsilon)//  this is the variable epsilon, related to the magnitudo.
            {
                //ok
            }
            else
            {
                mustLog = true;
            }
            if (Math.Abs(totalPrePrune - totalAfterPrune) < fixedEpsilon)//  this is the FIXED epsilon, a param.
            {
                //ok
            }
            else
            {
                if (ForceVerbosity)
                {
                    mustLog = true;
                }
            }
            // end tests on pruning
            //
            //-------------
            //
            // tests on ratioReducing
            figureNonDisponibili = 0;   // re-init to allow a non-confusing vision in the debugger.
            curEpsilon           = 0.0; // re-init to allow a non-confusing vision in the debugger.
            RealField.RatioReducingInstrument ratioMethod     = new RealField.RatioReducingInstrument(prunRes.tensor_Num, prunRes.tensor_Den);
            RealField.RatioReducingResults    ratioSimplified = ratioMethod.RationalReductionOnOmegaData();
            resultLogger.Append(
                RealField.TestsOnRationals.ConsoleTensor_Ratio_Publisher_onStringBuilder("\r\n from RatioReduce "
                                                                                         , ratioSimplified)
                );
            resultLogger.Append(GenericTensor_Publisher_onStringBuilder("ratioSimplified.Num_simplified_factorization ", ratioSimplified.Num_simplified_factorization));
            resultLogger.Append(GenericTensor_Publisher_onStringBuilder("ratioSimplified.Den_simplified_factorization ", ratioSimplified.Den_simplified_factorization));
            double numPostRationalReduce    = RealField.TestsOnRationals.mulUp(ratioSimplified.Num_simplified_factorization);
            double denPostRationalReduce    = RealField.TestsOnRationals.mulUp(ratioSimplified.Den_simplified_factorization);
            double totalAfterRationalReduce = numPostRationalReduce / denPostRationalReduce;

            resultLogger.Append("\r\n TOTAL from RatioReduce == ");
            resultLogger.Append(totalAfterRationalReduce.ToString());
            AnalyzedObj_Magnitudo = getMagnitudoOrder(totalAfterRationalReduce);  // NB. I'm reusing variables frome the Prune tests.
            Error_Magnitudo       = getMagnitudoOrder(Math.Abs(totalPrePrune - totalAfterRationalReduce));
            figureNonDisponibili  = (int)AnalyzedObj_Magnitudo - 15;              // figure non rappresentabili, i.e. errore
            curEpsilon            = +9.0 * Math.Pow(+10.0, figureNonDisponibili); // la figura sulla quale si manifesta l'errore e' disponibileper tutta la sua magnitudo( i.e. fino al "9").
            // log for error on RatioReduce ----------------
            resultLogger.Append("\r\n error on RationalReduce : Abs(totalPrePrune - totalAfterRationalReduce)== ");
            resultLogger.Append(Math.Abs(totalPrePrune - totalAfterRationalReduce).ToString());
            resultLogger.Append("\r\n AnalyzedObj_Magnitudo==");
            resultLogger.Append(AnalyzedObj_Magnitudo.ToString());
            resultLogger.Append("\r\n Error_Magnitudo==");
            resultLogger.Append(Error_Magnitudo.ToString());
            resultLogger.Append("\r\n\r\n");
            // end : log for error on RatioReduce ----------------
            if (Math.Abs(totalPrePrune - totalAfterRationalReduce) < curEpsilon)// variable epsilon==epsilon( magnitude)
            {
                //ok
            }
            else
            {
                mustLog = true;
            }
            if (Math.Abs(totalPrePrune - totalAfterRationalReduce) < fixedEpsilon)//  this is the FIXED epsilon, a param.
            {
                //ok
            }
            else
            {
                if (ForceVerbosity)
                {
                    mustLog = true;
                }
            }
            //
            resultLogger.Append("\r\n #####--- end SINGLE test  ");
            resultLogger.Append("  ----##########################################\r\n\r\n");
            //----------------------------------------------------------
            if (mustLog)
            {
                Console.WriteLine(resultLogger.ToString());
            } // else skip.
            resultLogger = null;// gc
        }     // end : Prune_and_RationalReduce_test() : receive a single long[,] tensor.
예제 #2
0
        }// end : public void ConsoleTensorPublisher( string message, long[,] SignedArray )

        /// <summary>
        /// /* NB.
        ///  * ----- cruscotto Watch : debug watch cockpit for :  test Prune_and_RationalReduce_test().
        ///  *
        /// curEpsilon			        1000000000.0	double
        /// int_curMagnitudo		    24	int
        /// curMagnitudo			    24.0	double
        /// totalAfterPrune			    7.0708168248286379E+23	double
        /// totalAfterRationalReduce	7.0708168248286379E+23	double
        /// totalPrePrune			    7.0708168248286366E+23	double
        /// mustLog				        true	bool
        /// */
        /// </summary>
        /// <param name="cardTests">cardinalita' dei test del batch</param>
        /// <param name="fixedEpsilon">l'epsilon prefissato : e' ovvio che ci sia errore su questo, data la variabilita' della magnitudo</param>
        /// <param name="ForceVerbosity">se si vuole il log, anche in assenza di errore sul fixed epsilon; se si passa false il log avviene solo su errore sul fixedEpsilon. L'errore sullo epsilon variabile in funz. della magnitudo non si manifesta mai.</param>
        public static void Prune_and_RationalReduce_test(int cardTests, double fixedEpsilon, bool ForceVerbosity)
        {
            //---- test batch ------------------------------------------------------------
            for (int accTests = 0; accTests < cardTests; accTests++)
            {
                bool mustLog = false;// activated on error or on request.
                //--------------------------- start :  prepare single test inside the batch ---------------------------
                System.Text.StringBuilder resultLogger = new System.Text.StringBuilder();
                resultLogger.Append("\r\n\r\n@@@@@--- start test nr. ");
                resultLogger.Append(accTests.ToString());
                resultLogger.Append(" ----@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r\n");
                int factorCardinality        = Common.MonteCarlo.MonteCarlo_threadLocked.next_int(1, 20);
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                for (int c = 0; c < factorCardinality; c++)
                {
                    long curBase = PrimesFinder.Primes.readPrimeAtSpecifiedOrdinal(Common.MonteCarlo.MonteCarlo_threadLocked.next_int(1, 10));
                    int  curExp  = Common.MonteCarlo.MonteCarlo_threadLocked.next_int(-9, 9);
                    sb.Append(curBase.ToString());
                    sb.Append("^");
                    sb.Append(curExp.ToString());
                    sb.Append(" * ");
                }
                sb.Remove(sb.Length - 2, 2); // remove last " * "
                string stringFactor = sb.ToString();
                sb = null;                   // gc
                resultLogger.Append("\r\n  the MonteCarlo extracted stringFactor is : ");
                resultLogger.Append(stringFactor);
                //--------------------------- end prepare single test inside the batch ---------------------------
                //
                // tests on pruning
                long[,] SignedArray = RealField.TestsOnRationals.fromStringFactoriz_ToTensorFactoriz(stringFactor);
                double totalPrePrune = RealField.TestsOnRationals.mulUp(SignedArray);
                resultLogger.Append("\r\n  the MonteCarlo extracted stringFactor TOTAL is : ");
                resultLogger.Append(totalPrePrune.ToString());
                resultLogger.Append("\r\n original input for pruning");
                resultLogger.Append(GenericTensor_Publisher_onStringBuilder("the Signed Array : ", SignedArray));
                RealField.PruningInstrument thePruner_method = new RealField.PruningInstrument(SignedArray);
                RealField.PruningResults    prunRes          = thePruner_method.Prune();
                resultLogger.Append("\r\n  the pruned Ratio ");
                resultLogger.Append(GenericTensor_Publisher_onStringBuilder("prunRes.tensor_Num ", prunRes.tensor_Num));
                resultLogger.Append(GenericTensor_Publisher_onStringBuilder("prunRes.tensor_Den ", prunRes.tensor_Den));
                double numPostPrune          = RealField.TestsOnRationals.mulUp(prunRes.tensor_Num);
                double denPostPrune          = RealField.TestsOnRationals.mulUp(prunRes.tensor_Den);
                double totalAfterPrune       = numPostPrune / denPostPrune;
                double AnalyzedObj_Magnitudo = getMagnitudoOrder(totalPrePrune);
                double Error_Magnitudo       = getMagnitudoOrder(Math.Abs(totalPrePrune - totalAfterPrune));
                int    figureNonDisponibili  = (int)AnalyzedObj_Magnitudo - 15;              // figure non rappresentabili, i.e. errore
                double curEpsilon            = +9.0 * Math.Pow(+10.0, figureNonDisponibili); // la figura sulla quale si manifesta l'errore e' disponibileper tutta la sua magnitudo( i.e. fino al "9").
                // log for error on Prune ----------------
                resultLogger.Append("\r\n error on Prune : Abs(totalPrePrune - totalAfterPrune)== ");
                resultLogger.Append(Math.Abs(totalPrePrune - totalAfterPrune).ToString());
                resultLogger.Append("\r\n AnalyzedObj_Magnitudo==");
                resultLogger.Append(AnalyzedObj_Magnitudo.ToString());
                resultLogger.Append("\r\n Error_Magnitudo==");
                resultLogger.Append(Error_Magnitudo.ToString());
                resultLogger.Append("\r\n\r\n");
                // end : log for error on Prune ----------------
                //
                if (Math.Abs(totalPrePrune - totalAfterPrune) < curEpsilon)//  this is the variable epsilon, related to the magnitudo.
                {
                    //ok
                }
                else
                {
                    mustLog = true;
                }
                if (Math.Abs(totalPrePrune - totalAfterPrune) < fixedEpsilon)//  this is the FIXED epsilon, a param.
                {
                    //ok
                }
                else
                {
                    if (ForceVerbosity)
                    {
                        mustLog = true;
                    }
                }
                // end tests on pruning
                //
                //-------------
                //
                // tests on ratioReducing
                figureNonDisponibili = 0;   // re-init to allow a non-confusing vision in the debugger.
                curEpsilon           = 0.0; // re-init to allow a non-confusing vision in the debugger.
                RealField.RatioReducingInstrument ratioMethod     = new RealField.RatioReducingInstrument(prunRes.tensor_Num, prunRes.tensor_Den);
                RealField.RatioReducingResults    ratioSimplified = ratioMethod.RationalReductionOnOmegaData();
                resultLogger.Append(
                    RealField.TestsOnRationals.ConsoleTensor_Ratio_Publisher_onStringBuilder("\r\n from RatioReduce "
                                                                                             , ratioSimplified)
                    );
                resultLogger.Append(GenericTensor_Publisher_onStringBuilder("ratioSimplified.Num_simplified_factorization ", ratioSimplified.Num_simplified_factorization));
                resultLogger.Append(GenericTensor_Publisher_onStringBuilder("ratioSimplified.Den_simplified_factorization ", ratioSimplified.Den_simplified_factorization));
                double numPostRationalReduce    = RealField.TestsOnRationals.mulUp(ratioSimplified.Num_simplified_factorization);
                double denPostRationalReduce    = RealField.TestsOnRationals.mulUp(ratioSimplified.Den_simplified_factorization);
                double totalAfterRationalReduce = numPostRationalReduce / denPostRationalReduce;
                resultLogger.Append("\r\n TOTAL from RatioReduce == ");
                resultLogger.Append(totalAfterRationalReduce.ToString());
                AnalyzedObj_Magnitudo = getMagnitudoOrder(totalAfterRationalReduce);  // NB. I'm reusing variables frome the Prune tests.
                Error_Magnitudo       = getMagnitudoOrder(Math.Abs(totalPrePrune - totalAfterRationalReduce));
                figureNonDisponibili  = (int)AnalyzedObj_Magnitudo - 15;              // figure non rappresentabili, i.e. errore
                curEpsilon            = +9.0 * Math.Pow(+10.0, figureNonDisponibili); // la figura sulla quale si manifesta l'errore e' disponibileper tutta la sua magnitudo( i.e. fino al "9").
                // log for error on RatioReduce ----------------
                resultLogger.Append("\r\n error on RationalReduce : Abs(totalPrePrune - totalAfterRationalReduce)== ");
                resultLogger.Append(Math.Abs(totalPrePrune - totalAfterRationalReduce).ToString());
                resultLogger.Append("\r\n AnalyzedObj_Magnitudo==");
                resultLogger.Append(AnalyzedObj_Magnitudo.ToString());
                resultLogger.Append("\r\n Error_Magnitudo==");
                resultLogger.Append(Error_Magnitudo.ToString());
                resultLogger.Append("\r\n\r\n");
                // end : log for error on RatioReduce ----------------
                if (Math.Abs(totalPrePrune - totalAfterRationalReduce) < curEpsilon)// variable epsilon==epsilon( magnitude)
                {
                    //ok
                }
                else
                {
                    mustLog = true;
                }
                if (Math.Abs(totalPrePrune - totalAfterRationalReduce) < fixedEpsilon)//  this is the FIXED epsilon, a param.
                {
                    //ok
                }
                else
                {
                    if (ForceVerbosity)
                    {
                        mustLog = true;
                    }
                }
                //
                resultLogger.Append("\r\n #####--- end test nr. ");
                resultLogger.Append(accTests.ToString());
                resultLogger.Append("  ----##########################################\r\n\r\n");
                //----------------------------------------------------------
                if (mustLog)
                {
                    Console.WriteLine(resultLogger.ToString());
                }// else skip.
                resultLogger  = null;// gc
                totalPrePrune = totalAfterPrune = totalAfterRationalReduce = 0.0;// reset
            } // end for #(tests)
        }     // end : test Prune_and_RationalReduce_test()