private void ComputeSystematic() { Range rangea = this.Parameters[0].Value; Range rangeb = this.Parameters[1].Value; Range rangec = this.Parameters[2].Value; PrimesBigInteger ca = rangea.From; PrimesBigInteger counter = PrimesBigInteger.Zero; while (ca.CompareTo(rangea.To) <= 0) { m_Function.SetParameter("a", ca); PrimesBigInteger cb = rangeb.From; while (cb.CompareTo(rangeb.To) <= 0) { m_Function.SetParameter("b", cb); PrimesBigInteger cc = rangec.From; while (cc.CompareTo(rangec.To) <= 0) { m_Function.SetParameter("c", cc); PrimesBigInteger from = From; PrimesBigInteger primesCounter = PrimesBigInteger.Zero; IList <PrimesBigInteger> m_PrimeList = new List <PrimesBigInteger>(); while (from.CompareTo(To) <= 0) { PrimesBigInteger res = Function.Execute(from); if (res.IsPrime(10)) { if (!m_PrimeList.Contains(res)) { m_PrimeList.Add(res); } primesCounter = primesCounter.Add(PrimesBigInteger.One); } counter = counter.Add(PrimesBigInteger.One); from = from.Add(PrimesBigInteger.One); } if (this.FunctionResult != null) { this.FunctionResult(this.Function as IPolynom, primesCounter, PrimesBigInteger.ValueOf(m_PrimeList.Count), counter); } cc = cc.Add(PrimesBigInteger.One); } cb = cb.Add(PrimesBigInteger.One); } ca = ca.Add(PrimesBigInteger.One); } }
public RhoControl() { InitializeComponent(); InputValidator <PrimesBigInteger> validatorStartX = new InputValidator <PrimesBigInteger>(); validatorStartX.Validator = new BigIntegerMinValueMaxValueValidator(null, PrimesBigInteger.ValueOf(1), PrimesBigInteger.ValueOf(1000)); validatorStartX.LinkOnlinehelp = Primes.OnlineHelp.OnlineHelpActions.Factorization_BruteForce; startfx.AddInputValidator(InputSingleControl.Free, validatorStartX); InputValidator <PrimesBigInteger> validatorA = new InputValidator <PrimesBigInteger>(); validatorA.Validator = new BigIntegerMinValueMaxValueValidator(null, PrimesBigInteger.ValueOf(1), PrimesBigInteger.ValueOf(1000)); validatorA.LinkOnlinehelp = Primes.OnlineHelp.OnlineHelpActions.Factorization_Rho; a.AddInputValidator(InputSingleControl.Free, validatorA); a.SetText(InputSingleControl.Free, "2"); startfx.SetText(InputSingleControl.Free, "23"); //log.Columns = 1; a.Execute += new ExecuteSingleDelegate(ForceGetValue_Execute); startfx.Execute += new ExecuteSingleDelegate(ForceGetValue_Execute); m_Factors = new Dictionary <PrimesBigInteger, PrimesBigInteger>(); m_FactorsTmp = new Dictionary <PrimesBigInteger, int>(); }
private void ExecuteGenerate10Primes(PrimesBigInteger digits) { ExecuteGenerateNPrimes(PrimesBigInteger.ValueOf(10), digits); }
void m_PolynomRangeExecuter_Stop() { int row = log.NewLine(); bool rndExecution = m_PolynomRangeExecuter.From.Equals(PrimesBigInteger.NaN) && m_PolynomRangeExecuter.To.Equals(PrimesBigInteger.NaN); if (!rndExecution) { log.Info( string.Format( Primes.Resources.lang.WpfControls.Generation.PrimesGeneration.statRndInterval, new object[] { m_PolynomCounter.ToString(), m_PolynomRangeExecuter.From.ToString(), m_PolynomRangeExecuter.To.ToString() }), 0, row); } else { log.Info( string.Format( Primes.Resources.lang.WpfControls.Generation.PrimesGeneration.statRnd, new object[] { m_PolynomCounter.ToString() }), 0, row); } row = log.NewLine(); log.Info("", 0, row); row = log.NewLine(); try { /*Calculating exact*/ double pc = m_PrimesCounter.DoubleValue; double rc = m_ResultCounter.DoubleValue; log.Info( string.Format( Primes.Resources.lang.WpfControls.Generation.PrimesGeneration.statAvgCountPrimes, new object[] { (pc / rc).ToString("N"), ((pc * 100.0) / rc).ToString("N") }), 0, row); } catch { log.Info( string.Format( Primes.Resources.lang.WpfControls.Generation.PrimesGeneration.statAvgCountPrimes, new object[] { m_PrimesCounter.Divide(m_ResultCounter).ToString(), m_PrimesCounter.Multiply(PrimesBigInteger.ValueOf(100)).Divide(m_ResultCounter).ToString() }), 0, row); } row = log.NewLine(); if (!rndExecution) { log.Info( Primes.Resources.lang.WpfControls.Generation.PrimesGeneration.statFunctionsMostInterval, 0, row); } else { log.Info( Primes.Resources.lang.WpfControls.Generation.PrimesGeneration.statFunctionsMost, 0, row); } foreach (IPolynom p in m_ListMostPrimes) { row = log.NewLine(); log.Info( p.ToString(), 0, row); } row = log.NewLine(); if (!rndExecution) { log.Info( Primes.Resources.lang.WpfControls.Generation.PrimesGeneration.statFunctionsMostMiscInterval, 0, row); } else { log.Info( Primes.Resources.lang.WpfControls.Generation.PrimesGeneration.statFunctionsMostMisc, 0, row); } foreach (IPolynom p in m_ListMostPrimesAbsolut) { row = log.NewLine(); log.Info( p.ToString(), 0, row); } row = log.NewLine(); if (!rndExecution) { log.Info( Primes.Resources.lang.WpfControls.Generation.PrimesGeneration.statFunctionsLeastInterval, 0, row); } else { log.Info( Primes.Resources.lang.WpfControls.Generation.PrimesGeneration.statFunctionsLeast, 0, row); } foreach (IPolynom p in m_ListLeastPrimes) { row = log.NewLine(); log.Info( p.ToString(), 0, row); } m_ListMostPrimes.Clear(); m_ListLeastPrimes.Clear(); m_ResultCounter = PrimesBigInteger.Zero; m_PrimesCounter = PrimesBigInteger.Zero; m_PolynomCounter = PrimesBigInteger.Zero; m_MostPrimes = null; m_LeastPrimes = null; m_InputControlPolynomRange.Stop(); }
public GraphControl() { try { InitializeComponent(); cgraph.OnFunctionStart = FunctionStart; cgraph.OnFunctionStop = FunctionStop; cgraph.ClearPaintArea(); m_FunctionPix = new FunctionPiX(); m_FunctionPix.Executed += new ObjectParameterDelegate(m_FunctionPix_Executed); m_FunctionLiN = new FunctionLiN(); m_FunctionLiN.Executed += new ObjectParameterDelegate(m_FunctionLiN_Executed); m_FunctionPiGauss = new FunctionPiGauss(); m_FunctionPiGauss.Executed += new ObjectParameterDelegate(m_FunctionPiGauss_Executed); m_From = PrimesBigInteger.Zero; m_To = PrimesBigInteger.Zero; ircCountPrimes.Execute += new Primes.WpfControls.Components.ExecuteDelegate(ircCountPrimes_Execute); ircCountPrimes.Cancel += new VoidDelegate(ircCountPrimes_Cancel); this.OnStopPiX += new VoidDelegate(GraphControl_OnStopPiX); ircCountPrimes.SetText(InputRangeControl.FreeFrom, "2"); ircCountPrimes.SetText(InputRangeControl.FreeTo, "100"); ircCountPrimes.SetText(InputRangeControl.CalcFromFactor, "1"); ircCountPrimes.SetText(InputRangeControl.CalcFromBase, "2"); ircCountPrimes.SetText(InputRangeControl.CalcFromExp, "1"); ircCountPrimes.SetText(InputRangeControl.CalcFromSum, "0"); ircCountPrimes.SetText(InputRangeControl.CalcToFactor, "1"); ircCountPrimes.SetText(InputRangeControl.CalcToBase, "10"); ircCountPrimes.SetText(InputRangeControl.CalcToExp, "2"); ircCountPrimes.SetText(InputRangeControl.CalcToSum, "0"); ircCountPrimes.AddValueValidator(InputRangeControl.From, new BigIntegerMinValueValidator(null, PrimesBigInteger.Two)); ircCountPrimes.AddValueValidator(InputRangeControl.To, new BigIntegerMinValueMaxValueValidator(null, PrimesBigInteger.Ten, PrimesBigInteger.ValueOf(int.MaxValue))); IValidator <PrimesBigInteger> rangevalidator = new BigIntegerMinValueValidator(null, PrimesBigInteger.ValueOf(10)); rangevalidator.Message = Primes.Resources.lang.WpfControls.Distribution.Distribution.graph_validatorrangemessage; ircCountPrimes.RangeValueValidator = rangevalidator; ircCountPrimes.KeyDown += new ExecuteDelegate(ircCountPrimes_KeyDown); ircCountPrimes.SetButtonCancelButtonEnabled(false); } catch (Exception ex) { System.Diagnostics.EventLog.WriteEntry("Primes.GraphControl", ex.Message, System.Diagnostics.EventLogEntryType.Information); System.Diagnostics.EventLog.WriteEntry("Primes.GraphControl", ex.StackTrace, System.Diagnostics.EventLogEntryType.Information); if (ex.InnerException != null) { System.Diagnostics.EventLog.WriteEntry("Primes.GraphControl", ex.InnerException.Message, System.Diagnostics.EventLogEntryType.Information); System.Diagnostics.EventLog.WriteEntry("Primes.GraphControl", ex.InnerException.StackTrace, System.Diagnostics.EventLogEntryType.Information); } } }
void m_PolynomRangeExecuter_FunctionResult(IPolynom p, PrimesBigInteger primesCount, PrimesBigInteger primesCountReal, PrimesBigInteger counter) { int row = log.NewLine(); log.Info(p.ToString(), 0, row); PrimesBigInteger percent = primesCount.Multiply(PrimesBigInteger.ValueOf(100)).Divide(counter); PrimesBigInteger percentAbsolut = primesCountReal.Multiply(PrimesBigInteger.ValueOf(100)).Divide(counter); /*Most Primes*/ if (m_MostPrimes == null) { m_MostPrimes = percent; m_ListMostPrimes.Add((p as SecondDegreePolynom).Clone() as IPolynom); } else { if (m_MostPrimes.Equals(percent)) { m_ListMostPrimes.Add((p as SecondDegreePolynom).Clone() as IPolynom); } else { if (m_MostPrimes.CompareTo(percent) < 0) { m_MostPrimes = percent; m_ListMostPrimes.Clear(); m_ListMostPrimes.Add((p as SecondDegreePolynom).Clone() as IPolynom); } } } if (m_MostPrimesAbsolut == null) { m_MostPrimesAbsolut = percentAbsolut; m_ListMostPrimesAbsolut.Add((p as SecondDegreePolynom).Clone() as IPolynom); } else { if (m_MostPrimesAbsolut.Equals(percentAbsolut)) { m_ListMostPrimesAbsolut.Add((p as SecondDegreePolynom).Clone() as IPolynom); } else { if (m_MostPrimesAbsolut.CompareTo(percentAbsolut) < 0) { m_MostPrimesAbsolut = percentAbsolut; m_ListMostPrimesAbsolut.Clear(); m_ListMostPrimesAbsolut.Add((p as SecondDegreePolynom).Clone() as IPolynom); } } } /*Least Primes*/ if (m_LeastPrimes == null) { m_LeastPrimes = percent; m_ListLeastPrimes.Add((p as SecondDegreePolynom).Clone() as IPolynom); } else { if (m_LeastPrimes.Equals(percent)) { m_ListLeastPrimes.Add((p as SecondDegreePolynom).Clone() as IPolynom); } else { if (m_LeastPrimes.CompareTo(percent) > 0) { m_LeastPrimes = percent; m_ListLeastPrimes.Clear(); m_ListLeastPrimes.Add((p as SecondDegreePolynom).Clone() as IPolynom); } } } m_ResultCounter = m_ResultCounter.Add(counter); m_PrimesCounter = m_PrimesCounter.Add(primesCount); m_PolynomCounter = m_PolynomCounter.Add(PrimesBigInteger.One); log.Info(string.Format(Primes.Resources.lang.WpfControls.Generation.PrimesGeneration.statGenerated, new object[] { primesCount, percent, primesCountReal }), 1, row); }
private void ExecuteGraph(PrimesBigInteger from, PrimesBigInteger to) { CancelPiX(); ResetControls(); m_FunctionLiN.Reset(); m_FunctionPiGauss.Reset(); m_FunctionPix.Reset(); //bool valid = false; //if (rbFreeRange.IsChecked.Value) //{ // valid = GetFreeParameters(ref from, ref to); //} //else if (rbFunctionRange.IsChecked.Value) //{ // valid = GetFunctionParameters(ref from, ref to); //} //if (valid) //{ cgraph.ClearFunctions(); if (m_From.CompareTo(from) != 0) { m_From = from; try { m_RangeYFrom = Math.Min(m_FunctionPiGauss.Execute(m_From.DoubleValue), m_FunctionLiN.Execute(m_From.DoubleValue)); tbInfoGaußPrimeTheorem.Text = ""; } catch (ResultNotDefinedException) { m_RangeYFrom = 2; } m_FunctionPiGauss.Reset(); m_FunctionLiN.Reset(); } if (m_To != to) { m_To = to; m_RangeYTo = m_FunctionLiN.Execute(m_To.DoubleValue); m_FunctionLiN.Reset(); tbInfoLin.Text = ""; } m_FunctionLiN.MaxValue = to.DoubleValue; cgraph.RangeX = new RangeX(from, to); string strFrom = Convert.ToInt32(Math.Floor(m_RangeYFrom)).ToString(); string strTo = Convert.ToInt32(Math.Ceiling(m_RangeYTo)).ToString(); cgraph.RangeY = new RangeY(new PrimesBigInteger(strFrom), new PrimesBigInteger(strTo)); if (cbPiGauss.IsChecked.Value) { cgraph.AddFunctionExecute(m_FunctionPiGauss, from, to, FunctionType.CONSTANT, Brushes.Blue); } if (cbPiX.IsChecked.Value) { cgraph.AddFunctionExecute(m_FunctionPix, m_From, m_To, FunctionType.STAIR, Brushes.Red); } if (cbLin.IsChecked.Value) { cgraph.AddFunctionExecute(m_FunctionLiN, from, to, FunctionType.CONSTANT, Brushes.Green); } cgraph.ExecuteFunctions(); if (to.CompareTo(PrimesBigInteger.ValueOf(10000)) > 0) { lblInfoPixDontCalc.Visibility = Visibility.Visible; //cbPiX.IsEnabled = false; //m_CountPixThread = new CountPiXThread(m_FunctionPix as FunctionPiX, this.Dispatcher, m_FunctionPix_Executed, m_To); //m_CountPixThread.OnFunctionStart += new FunctionEvent(FunctionStart); //m_CountPixThread.OnFunctionStop += new FunctionEvent(FunctionStop); //m_CountPixThread.Start(); //m_ThreadPix = new Thread(new ThreadStart(CalculatePiX)); //m_ThreadPix.Start(); } ControlHandler.SetPropertyValue(lblCalcInfoPiX, "Visibility", Visibility.Visible); ControlHandler.SetPropertyValue(lblCalcInfoPiGauss, "Visibility", Visibility.Visible); ControlHandler.SetPropertyValue(lblCalcInfoLiN, "Visibility", Visibility.Visible); ControlHandler.SetPropertyValue(tbInfoLin, "Visibility", Visibility.Visible); ControlHandler.SetPropertyValue(tbInfoPiX, "Visibility", Visibility.Visible); ControlHandler.SetPropertyValue(tbInfoGaußPrimeTheorem, "Visibility", Visibility.Visible); lblCalcInfoLiN.Text = Primes.Resources.lang.WpfControls.Distribution.Distribution.graph_lincountinfoCalculating; lblCalcInfoPiGauss.Text = Primes.Resources.lang.WpfControls.Distribution.Distribution.graph_gausscountinfoCalculating; lblCalcInfoPiX.Text = Primes.Resources.lang.WpfControls.Distribution.Distribution.graph_pincountinfoCalculating; //} }
public override QSResult Execute(ref QSData data) { int counter = 0; IList <QuadraticPair> smoothpair = data.BSmooth; long productA = 1; long productB = 1; String msg; foreach (QuadraticPair pair in smoothpair) { if (pair.QuadraticStatus == QuadraticStatus.Quadratic) { productA = pair.A; productB = pair.B; break; } } if (productA == 1 && productB == 1) { foreach (QuadraticPair pair in smoothpair) { if (pair.QuadraticStatus == QuadraticStatus.Part) { productA = (productA * pair.A) % data.N; productB *= pair.B; pair.QuadraticStatus = QuadraticStatus.Nope; } } } if (productA == 1 || productB == 1) { ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); ControlHandler.ExecuteMethod(this, "AddToGrid", new object[] { Grid, String.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step4_end, data.N), counter++, 0, 0, 0 }); return(QSResult.Ok); } long sqb = (long)Math.Sqrt(productB); StringBuilder sbInfo = new StringBuilder(); sbInfo.Append(string.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step4_abcalculated, productA, sqb)); sbInfo.Append("\n"); sbInfo.Append(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step4_checkcong); ControlHandler.SetPropertyValue(m_lblInfo, "Text", sbInfo.ToString()); ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); ControlHandler.ExecuteMethod(this, "AddToGrid", new object[] { Grid, BuildQuadMod(productA, sqb, data.N), counter++, 0, 0, 0 }); ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); ControlHandler.ExecuteMethod(this, "AddToGrid", new object[] { Grid, BuildMod(productA, sqb, data.N), counter++, 0, 0, 0 }); if (!ModuloTest(productA, sqb, data.N)) // Modulotest nicht bestanden { data.AddIgnoreQuadrat(PrimesBigInteger.ValueOf(productB)); msg = Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step4_notproofed; ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); ControlHandler.ExecuteMethod(this, "AddToGrid", new object[] { Grid, msg, counter++, 0, 0, 0 }); return(QSResult.Failed); } msg = String.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step4_proofed, data.N); ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); ControlHandler.ExecuteMethod(this, "AddToGrid", new object[] { Grid, msg, counter++, 0, 0, 0 }); long factor1 = (long)BigInteger.GreatestCommonDivisor(productA + sqb, data.N); long factor2 = (long)BigInteger.GreatestCommonDivisor(productA - sqb, data.N); bool trivialfactor1 = (factor1 == 1 || factor1 == data.N); bool trivialfactor2 = (factor2 == 1 || factor2 == data.N); String sbfactor1 = string.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step4_factor1, productA, sqb, data.N, factor1); ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); ControlHandler.ExecuteMethod(this, "AddToGrid", new object[] { Grid, sbfactor1, counter++, 0, 0, 0 }); String sbfactor2 = string.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step4_factor2, productA, sqb, data.N, factor2); ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); ControlHandler.ExecuteMethod(this, "AddToGrid", new object[] { Grid, sbfactor2, counter++, 0, 0, 0 }); if (trivialfactor1 && trivialfactor2) { data.AddIgnoreQuadrat(PrimesBigInteger.ValueOf(productB)); msg = string.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step4_reset, productA, sqb); ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); ControlHandler.ExecuteMethod(this, "AddToGrid", new object[] { Grid, msg, counter++, 0, 0, 0 }); return(QSResult.Failed); } long nontrivialfactor = trivialfactor1 ? factor2 : factor1; FireFoundFactorEvent(PrimesBigInteger.ValueOf(nontrivialfactor)); FireFoundFactorEvent(PrimesBigInteger.ValueOf(data.N / nontrivialfactor)); //Boolean p1 = BigIntegerHelper.IsProbablePrime(factor1); //Boolean p2 = BigIntegerHelper.IsProbablePrime(factor2); //if (p1) FireFoundFactorEvent(PrimesBigInteger.ValueOf(factor1)); //if (p2) FireFoundFactorEvent(PrimesBigInteger.ValueOf(factor2)); //if( !(p1 && p2) ) // falls ein Faktor nicht prim ist //{ // long notPrime = p1 ? factor2 : factor1; // msg = string.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step4_refactorize, notPrime, notPrime); // ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); // ControlHandler.ExecuteMethod( this, "AddToGrid", new object[] { Grid, msg, counter++, 0, 0, 0 }); // data.N = notPrime; // return QSResult.Restart; //} return(QSResult.Ok); }
public double Execute(double input) { long value = (long)input; if (usePrimesCountList) { usePrimesCountList = PrimesCountList.Initialzed; } if (PrimesCountList.Initialzed && usePrimesCountList) { if (value <= PrimesCountList.MaxNumber) { m_FormerValue = m_Counter; m_Counter = PrimesCountList.GetPrime((long)input); m_LastNumber = value; } else { m_Counter = PrimesCountList.GetPrime(PrimesCountList.MaxNumber); m_LastNumber = PrimesCountList.MaxNumber; usePrimesCountList = false; } } else { long i = value / 100000; if (i < PrimeNumbers.numberofprimes.Length) { m_Counter = PrimeNumbers.numberofprimes[i]; m_LastNumber = i * 100000; } } if (PrimesBigInteger.ValueOf(m_LastNumber).IsPrime(10)) { m_LastNumber++; } while (m_LastNumber < value) { if (PrimesBigInteger.ValueOf(m_LastNumber).IsPrime(10)) { m_Counter++; if (m_ShowIntermediateResult && Executed != null) { Executed(m_Counter); } } m_LastNumber++; } if (PrimesBigInteger.ValueOf(value).IsPrime(10) && !usePrimesCountList) { m_FormerValue = m_Counter; m_Counter++; } m_LastNumber = value; if (Executed != null) { Executed(m_Counter); } return(m_Counter); }
public TestOfFermatControl() { InitializeComponent(); InputValidator <PrimesBigInteger> iv = new InputValidator <PrimesBigInteger>(); iv.Validator = new BigIntegerMinValueMaxValueValidator(null, PrimesBigInteger.Two, PrimesBigInteger.ValueOf(100)); iscA.AddInputValidator( Primes.WpfControls.Components.InputSingleControl.Free, iv); iscA.Execute += new Primes.WpfControls.Components.ExecuteSingleDelegate(iscA_Execute); iscA.FreeText = "2"; ircSystematic.Execute += new ExecuteDelegate(ircSystematic_Execute); ircSystematic.SetText(InputRangeControl.FreeFrom, "2"); ircSystematic.SetText(InputRangeControl.FreeTo, "100"); m_Points = new Dictionary <int, Point>(); m_Arrows = new Dictionary <PrimesBigInteger, ArrowLine>(); m_RunningLockObject = new object(); }
public Range(int from, int to) : this(PrimesBigInteger.ValueOf(from), PrimesBigInteger.ValueOf(to)) { }