From 241a147d709e5a7aeb4e5ea5f1d3c6f673835855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Lema=C5=84czyk?= Date: Sun, 15 Feb 2026 02:24:09 +0100 Subject: [PATCH] BitContradiction filtering improvements. --- ...EvenPerfectBitScanner.ResultsParser.csproj | 1 + .../Program.cs | 3 +- .../EvenPerfectBitScanner.csproj | 1 + .../BitContradictionSolverWithAMultiplier.cs | 228 ++++++++++++------ ...orByDivisorPrimeScanSessionWithTemplate.cs | 11 +- ...mberDivisorByDivisorGpuPrimeScanSession.cs | 9 +- .../MersenneNumberDivisorByDivisorTester.cs | 10 +- .../PerfectNumbers.Core.csproj | 3 +- 8 files changed, 180 insertions(+), 86 deletions(-) diff --git a/EvenPerfectBitScanner.ResultsParser/EvenPerfectBitScanner.ResultsParser.csproj b/EvenPerfectBitScanner.ResultsParser/EvenPerfectBitScanner.ResultsParser.csproj index 13991b7..0bd2856 100644 --- a/EvenPerfectBitScanner.ResultsParser/EvenPerfectBitScanner.ResultsParser.csproj +++ b/EvenPerfectBitScanner.ResultsParser/EvenPerfectBitScanner.ResultsParser.csproj @@ -9,6 +9,7 @@ + diff --git a/EvenPerfectBitScanner.ResultsParser/Program.cs b/EvenPerfectBitScanner.ResultsParser/Program.cs index 7079308..1877017 100644 --- a/EvenPerfectBitScanner.ResultsParser/Program.cs +++ b/EvenPerfectBitScanner.ResultsParser/Program.cs @@ -1,6 +1,7 @@ using System.Globalization; using System.Text; using Open.Numeric.Primes; +using Spectre.Console; namespace EvenPerfectBitScanner.ResultsParser; @@ -83,7 +84,7 @@ private const string DefaultHeader = "p,divisor,searchedMersenne,detailedCheck,p } catch (Exception exception) { - Console.Error.WriteLine($"Processing failed: {exception.Message}"); + AnsiConsole.WriteException(exception); return 1; } } diff --git a/EvenPerfectBitScanner/EvenPerfectBitScanner.csproj b/EvenPerfectBitScanner/EvenPerfectBitScanner.csproj index fed1311..7143e9c 100644 --- a/EvenPerfectBitScanner/EvenPerfectBitScanner.csproj +++ b/EvenPerfectBitScanner/EvenPerfectBitScanner.csproj @@ -19,6 +19,7 @@ + diff --git a/PerfectNumbers.Core/ByDivisor/BitContradictionSolverWithAMultiplier.cs b/PerfectNumbers.Core/ByDivisor/BitContradictionSolverWithAMultiplier.cs index 00df99f..c5f591e 100644 --- a/PerfectNumbers.Core/ByDivisor/BitContradictionSolverWithAMultiplier.cs +++ b/PerfectNumbers.Core/ByDivisor/BitContradictionSolverWithAMultiplier.cs @@ -2,6 +2,7 @@ using System.Numerics; using PerfectNumbers.Core; using ILGPU; +using Spectre.Console; namespace PerfectNumbers.Core.ByDivisor; @@ -142,20 +143,20 @@ internal sealed class PrivateWorkSet [DeviceDependentTemplate(typeof(ComputationDevice))] internal static class BitContradictionSolverWithAMultiplier { -#if DETAILED_LOG - private const ulong DebugTargetP = 138000001UL; - private static readonly BigInteger DebugTargetK = new(3); - private static readonly ulong DebugTargetQ = checked((ulong)((DebugTargetK * DebugTargetP) << 1)); +#if DETAILED_LOG || WITH_PRUNE_STATS + private const ulong DebugTargetP = 138000953UL; + private static readonly BigInteger DebugTargetK = new(((337429718205079UL - 1UL) >> 1) / DebugTargetP); + private static readonly BigInteger DebugTargetQ = ((DebugTargetK * DebugTargetP) << 1) + BigInteger.One; // private const ulong DebugTargetQ = 1209708008767UL; [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static bool IsTargetCase(ulong p, System.Numerics.BigInteger k) => p == DebugTargetP && k == DebugTargetK; + private static bool IsTargetCase(ulong p, BigInteger k) => p == DebugTargetP && k == DebugTargetK; [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static void Dbg(ulong p, System.Numerics.BigInteger k, string msg) + private static void Dbg(ulong p, BigInteger k, string msg) { if (IsTargetCase(p, k)) - Console.WriteLine(msg); + AnsiConsole.MarkupLine(msg); } #endif #if WITH_PRUNE_STATS @@ -245,19 +246,19 @@ internal static class BitContradictionSolverWithAMultiplier private static void PrintPruneStats() { - Console.WriteLine("Prune stats:"); - Console.WriteLine( - $"TryPropagateCarry1={_prunedWithTryPropagateCarry1}, " + - $"Powmod2ZeroBeforeLastBlock={_prunedWithPowmod2ZeroBeforeLastBlock}, " + - $"Powmod2Tracked={_prunedWithPowmod2Tracked}, " + - $"Powmod2TrackedOptimized={_prunedWithPowmod2TrackedOptimized}, " + - $"CarryDropHeuristic={_prunedWithCarryDropHeuristic}, " + - $"CarryDominance67={_prunedWithCarryDominance67}, " + - $"CarryDominance8910AndMore={_prunedWithCarryDominance8910}, " + - $"CarryDominance15161718={_prunedWithCarryDominance15161718}, " + - $"CarryDominanceReached10AndStayedAbove5={_prunedWithCarryDominanceReached10AndStayedAbove5}, " + - $"CarryDominance1011121314={_prunedWithCarryDominance1011121314}, " + - $"HighDensityWithShortLowStreaksCarry={_prunedWithHighDensityWithShortLowStreaksCarry}" + AnsiConsole.MarkupLine("[MediumOrchid1_1]Prune stats:[/]"); + AnsiConsole.MarkupLine( + $"[DarkOrange]TryPropagateCarry1[/]=[Yellow]{_prunedWithTryPropagateCarry1}[/], " + + $"[DarkOrange]Powmod2ZeroBeforeLastBlock[/]=[Yellow]{_prunedWithPowmod2ZeroBeforeLastBlock}[/], " + + $"[DarkOrange]Powmod2Tracked[/]=[Yellow]{_prunedWithPowmod2Tracked}[/], " + + $"[MediumOrchid1_1]Powmod2TrackedOptimized[/]=[Gray100 Bold]{_prunedWithPowmod2TrackedOptimized}[/], " + + $"[DarkOrange]CarryDropHeuristic[/]=[Yellow]{_prunedWithCarryDropHeuristic}[/], " + + $"[DarkOrange]CarryDominance67[/]=[Yellow]{_prunedWithCarryDominance67}[/], " + + $"[DarkOrange]CarryDominance8910AndMore[/]=[Yellow]{_prunedWithCarryDominance8910}[/], " + + $"[DarkOrange]CarryDominance15161718[/]=[Yellow]{_prunedWithCarryDominance15161718}[/], " + + $"[DarkOrange]CarryDominanceReached10AndStayedAbove5[/]=[Yellow]{_prunedWithCarryDominanceReached10AndStayedAbove5}[/], " + + $"[DarkOrange]CarryDominance1011121314[/]=[Yellow]{_prunedWithCarryDominance1011121314}[/], " + + $"[DarkOrange]HighDensityWithShortLowStreaksCarry[/]=[Yellow]{_prunedWithHighDensityWithShortLowStreaksCarry}[/]" ); } #endif @@ -507,14 +508,14 @@ internal static class BitContradictionSolverWithAMultiplier private static void PrintStats() { - Console.WriteLine( - $"[STATS] stableCalls={_statStableAdvanceCalls} stableCols={_statStableAdvanceColsBatched} " + - $"scalarCols={_statScalarCols} bigShift={_statStableAdvanceBigShift} " + - $"deltaReq={_statDeltaRequests} deltaHits={_statDeltaHits} deltaBuilds={_statDeltaBuilds}"); - Console.WriteLine( - $"[CLEAN] checks={_statCleanChecks} false={_statCleanFalse} " + - $"firstDirtyCol={_statFirstDirtyColumn} word={_statFirstDirtyWord} " + - $"qWord=0x{_statFirstDirtyQ:X16} knownWord=0x{_statFirstDirtyKnown:X16}"); + AnsiConsole.MarkupLine( + $"[red][[STATS]][/] [DarkOrange]stableCalls[/]=[Yellow]{_statStableAdvanceCalls}[/] [DarkOrange]stableCols[/]=[Yellow]{_statStableAdvanceColsBatched}[/] " + + $"[red]scalarCols[/]=[Yellow]{_statScalarCols}[/] [DarkOrange]bigShift[/]=[Yellow]{_statStableAdvanceBigShift}[/] " + + $"[red]deltaReq[/]=[Yellow]{_statDeltaRequests}[/] [DarkOrange]deltaHits[/]=[Yellow]{_statDeltaHits}[/] [DarkOrange]deltaBuilds[/]=[Yellow]{_statDeltaBuilds}[/]"); + AnsiConsole.MarkupLine( + $"[red][[CLEAN]][/] [DarkOrange]checks[/]=[Yellow]{_statCleanChecks}[/] [DarkOrange]false[/]=[Yellow]{_statCleanFalse}[/] " + + $"[red]firstDirtyCol[/]=[Yellow]{_statFirstDirtyColumn}[/] [DarkOrange]word[/]=[Yellow]{_statFirstDirtyWord}[/] " + + $"[red]qWord[/]=[Yellow]0x{_statFirstDirtyQ:X16}[/] [DarkOrange]knownWord[/]=[Yellow]0x{_statFirstDirtyKnown:X16}[/]"); } #else [ThreadStatic] @@ -1257,7 +1258,7 @@ internal static class BitContradictionSolverWithAMultiplier allowedMin = outLo[0]; allowedMax = outHi[outCount - 1]; #if DETAILED_LOG - Console.WriteLine($"[TD] steps={steps} endRange=[{allowedMin},{allowedMax}] intervals={outCount}"); + AnsiConsole.MarkupLine($"[TD] steps={steps} endRange=[{allowedMin},{allowedMax}] intervals={outCount}"); #endif return true; @@ -1455,7 +1456,7 @@ internal static class BitContradictionSolverWithAMultiplier if (n < 0) { - // Console.WriteLine("n < 0 - excluding in pre-filter"); + // AnsiConsole.MarkupLine("n < 0 - excluding in pre-filter"); return false; } @@ -1532,7 +1533,7 @@ internal static class BitContradictionSolverWithAMultiplier if (inCount <= 0) { - // Console.WriteLine("inCount <= 0 - excluding in pre-filter"); + // AnsiConsole.MarkupLine("inCount <= 0 - excluding in pre-filter"); return false; } @@ -1597,7 +1598,7 @@ internal static class BitContradictionSolverWithAMultiplier if (Vector.IsHardwareAccelerated) { - // Console.WriteLine("SIMD accelerator ComputeForcedRemainingAndClean_Prefix"); + // AnsiConsole.MarkupLine("SIMD accelerator ComputeForcedRemainingAndClean_Prefix"); int limit = wordsMinusOne - (wordsMinusOne % Vector.Count); for (; i < limit; i += Vector.Count) { @@ -1615,7 +1616,7 @@ internal static class BitContradictionSolverWithAMultiplier } // else // { - // Console.WriteLine("No acceleration for ComputeForcedRemainingAndClean_Prefix"); + // AnsiConsole.MarkupLine("No acceleration for ComputeForcedRemainingAndClean_Prefix"); // } forced = (int)Vector.Sum(vForced); @@ -2343,11 +2344,14 @@ internal static class BitContradictionSolverWithAMultiplier { if (pLong == 138000953 && qExact.Equals(_testCase)) { - Console.WriteLine($"CarryDrop target reached: p={pLong}, q={qExact}, reason={pruneReason}, reached10={reached10}, reachedBelow5={reachedBelow5}, reached5={reached5}, zeroCount={zeroCount}"); + AnsiConsole.MarkupLine($"CarryDrop target reached: p={pLong}, q={qExact}, reason={pruneReason}, reached10={reached10}, reachedBelow5={reachedBelow5}, reached5={reached5}, zeroCount={zeroCount}"); } } // #endif + // TODO: Remove this + private static readonly BigInteger _debugCase = BigInteger.Parse("13746583730190991"); + private static bool TryCarryDropHeuristicPrune( BigInteger qExact, ReadOnlySpan qOneOffsets, @@ -2551,10 +2555,7 @@ internal static class BitContradictionSolverWithAMultiplier { lowestCarryAfter10 = (int)carryOut; } - } - else if (carryOut >= 10) - { - totalCarryAbove10++; + if (lastStreakBelow10 > longestStreakBelow10) { longestStreakBelow10 = lastStreakBelow10; @@ -2564,7 +2565,10 @@ internal static class BitContradictionSolverWithAMultiplier { shortestStreakBelow10 = lastStreakBelow10; } - + } + else if (carryOut >= 10) + { + totalCarryAbove10++; if (lastStreakBelow10 > 0) { lastStreakBelow10 = 0; @@ -2692,8 +2696,21 @@ internal static class BitContradictionSolverWithAMultiplier bool totalCarry8CountIsEven = (totalCarry8Count & 1) == 0; bool totalCarry9CountIsEven = (totalCarry9Count & 1) == 0; + bool totalCarry10CountIsEven = (totalCarry10Count & 1) == 0; + bool totalCarry11CountIsEven = (totalCarry11Count & 1) == 0; if (totalCarry8CountIsEven && totalCarry9CountIsEven && - ((totalCarry10Count & 1) == 0 || (totalCarry11Count > totalCarry10Count && totalCarry8Count > 14 && totalCarry11Count > totalCarry9Count && totalCarry11Count > totalCarry8Count)) + ( + ( + totalCarry10CountIsEven && + totalTransitionsOver10 > 37 + ) || + ( + totalCarry11Count > totalCarry10Count && + totalCarry8Count > 14 && + totalCarry11Count > totalCarry9Count && + totalCarry11Count > totalCarry8Count + ) + ) ) { pruneReason = CarryDropPruneReason.Dominance10AndMoreDrop; @@ -2703,11 +2720,40 @@ internal static class BitContradictionSolverWithAMultiplier return true; } - bool totalCarry10CountIsEven = (totalCarry10Count & 1) == 0; - bool totalCarry11CountIsEven = (totalCarry11Count & 1) == 0; - if ((!totalCarry8CountIsEven && !totalCarry10CountIsEven && totalCarry8Count + totalCarry9Count < totalCarry10Count + totalCarry11Count && totalCarryFirst32Count > 118) || - (totalCarry8CountIsEven && !totalCarry10CountIsEven && totalCarry8Count < 188 && totalCarry8Count + totalCarry9Count > totalCarry10Count + totalCarry11Count) || - (((!totalCarry8CountIsEven && !totalCarry11CountIsEven) || (totalCarry8CountIsEven && totalCarry8Count < 66) || (totalCarry8CountIsEven && totalCarry10CountIsEven && totalCarry11CountIsEven && totalCarry8Count < 72) || (!totalCarry11CountIsEven && (!totalCarry8CountIsEven || !totalCarry10CountIsEven) && totalCarry11Count > 16)) && totalCarry9Count + totalCarry11Count > totalCarry10Count + totalCarry12Count)) + if ( + ( + !totalCarry8CountIsEven && !totalCarry10CountIsEven && + totalCarry8Count + totalCarry9Count < totalCarry10Count + totalCarry11Count && + totalCarryFirst32Count > 118 + ) || + ( + totalCarry8CountIsEven && !totalCarry10CountIsEven && totalCarry8Count < 188 && + totalCarry8Count + totalCarry9Count > totalCarry10Count + totalCarry11Count + ) || + ( + ( + ( + !totalCarry8CountIsEven && !totalCarry11CountIsEven + ) || + ( + totalCarry8CountIsEven && totalCarry8Count < 66 + ) || + ( + totalCarry8CountIsEven && totalCarry10CountIsEven && totalCarry11CountIsEven && + totalCarry8Count < 72 + ) || + ( + !totalCarry11CountIsEven && + ( + !totalCarry8CountIsEven || + !totalCarry10CountIsEven + ) && + totalCarry11Count > 16 + ) + ) && + totalCarry9Count + totalCarry11Count > totalCarry10Count + totalCarry12Count + ) + ) { pruneReason = CarryDropPruneReason.Dominance10AndMoreDrop; #if WITH_PRUNE_STATS @@ -2727,14 +2773,23 @@ internal static class BitContradictionSolverWithAMultiplier if (totalCarryAbove10 >= 840 && shortestStreakBelow10 <= 3 && ( - (lastStreakBelow10 == 0 && first10 > 34) || - (totalCarryBelow10 < 100 && longestStreakBelow10 <= 12 && totalCarry11Count < 150 && lastStreakBelow10 < 12) - + ( + lastStreakBelow10 == 0 && first10 > 34 && totalCarryBelow10 > 35 + ) || + ( + totalCarryBelow10 < 100 && longestStreakBelow10 <= 12 && totalCarry11Count < 150 && + lastStreakBelow10 < 12 && totalCarryBelow10 > 50 + ) ) ) { pruneReason = CarryDropPruneReason.HighDensityWithShortLowStreaks; #if WITH_PRUNE_STATS + if ((ulong)pLong == DebugTargetP && qExact.Equals(DebugTargetQ)) + { + AnsiConsole.MarkupLine($"[MediumOrchid1_1]{nameof(CarryDropPruneReason.HighDensityWithShortLowStreaks)}[/] prune reason for [DodgerBlue1]p[/]=[Gray100 Bold]{pLong}[/], [DodgerBlue1]q[/]=[Gray100 Bold]{qExact}[/]: [DarkOrange]totalCarryAbove10[/]=[Yellow]{totalCarryAbove10}[/], [DarkOrange]shortestStreakBelow10[/]=[Yellow]{shortestStreakBelow10}[/], [DarkOrange]lastStreakBelow10[/]=[Yellow]{lastStreakBelow10}[/], [DarkOrange]first10[/]=[Yellow]{first10}[/], [DarkOrange]totalCarryBelow10[/]=[Yellow]{totalCarryBelow10}[/], [DarkOrange]longestStreakBelow10[/]=[Yellow]{longestStreakBelow10}[/], [DarkOrange]totalCarry11Count[/]=[Yellow]{totalCarry11Count}[/]"); + } + TraceCarryDropHeuristicPrune(pLong, qExact, pruneReason, reached10, reachedBelow5, reached5, zeroCount); #endif return true; @@ -2749,11 +2804,11 @@ internal static class BitContradictionSolverWithAMultiplier ( lastStreakBelow10 <= 89 && ( - zeroCount > 4 || + (zeroCount < 7 && longestStreakBelow10 > 10) || lastStreakBelow10 > 0 || first10 < 34 || - totalCarry2Count < 7 || - totalCarry11Count < 156 || + (totalCarry2Count > 2 && totalCarry2Count < 7) || + (totalCarry11Count > 14 && totalCarry11Count < 124) || totalCarry10Count > totalCarry11Count /* || longestStreakBelow10 < 34*/ ) @@ -2777,22 +2832,46 @@ internal static class BitContradictionSolverWithAMultiplier ) || ( reached5 <= 2 && - totalTransitionsOver10 > 35 && - (lastStreakBelow10 <= 28 || lastStreakBelow10 > 35 || longestStreakBelow10 < 49 || totalCarryBelow10 > 500) + ( + ( + totalTransitionsOver10 > 35 && + ( + lastStreakBelow10 > 35 || + totalCarryBelow10 > 400 || + (totalCarryBelow10 < 300 && first10 > 48) || + (lastStreakBelow10 <= 28 && lastStreakBelow10 > 0) || + (longestStreakBelow10 < 49 && first10 < 32) || + (totalTransitionsOver10 > 63 && longestStreakBelow10 > 40) || + (totalCarryBelow10 < 300 && totalCarry2Count < 8 && lastStreakBelow10 > 0) || + (totalTransitionsOver10 > 63 && first10 < 32) || + (totalTransitionsOver10 > 80 && totalCarryBelow10 > totalCarry10Count) || + (totalTransitionsOver10 > 100 && totalCarry10Count > totalCarryBelow10) || + (totalCarry10Count > totalCarryBelow10 && totalCarry11Count > 200) + ) + ) || + ( + totalTransitionsOver10 <= 35 && + ( + longestStreakBelow10 < 31 || + zeroCount > 10 + ) && + zeroCount > 4 + ) + ) ) || ( reached5 >= 3 && reached5 <= 7 && ( totalTransitionsOver10 > 50 || - (totalTransitionsOver10 < 50 && first10 < 33) + (totalTransitionsOver10 <= 50 && (first10 < 33 || totalCarryBelow10 > 63)) ) && ( first10 < 58 || first10 > 100 || totalTransitionsOver10 > 150 || - (totalTransitionsOver10 > 100 && longestStreakBelow10 < 49) || - (totalTransitionsOver10 > 100 && lastStreakBelow10 > 0) || - (totalTransitionsOver10 > 100 && totalCarryBelow10 > 400 && zeroCount < 5) || + (totalTransitionsOver10 > 90 && longestStreakBelow10 < 49) || + (totalTransitionsOver10 > 90 && lastStreakBelow10 > 0) || + (totalTransitionsOver10 > 90 && totalCarryBelow10 > 321 && (zeroCount < 5 || totalCarryBelow10 < 500)) || (totalCarryBelow10 < 320) ) ) @@ -2801,13 +2880,18 @@ internal static class BitContradictionSolverWithAMultiplier { pruneReason = CarryDropPruneReason.DominanceReached10AndStayedAbove5; #if WITH_PRUNE_STATS + if ((ulong)pLong == DebugTargetP && qExact.Equals(DebugTargetQ)) + { + AnsiConsole.MarkupLine($"[MediumOrchid1_1]{nameof(CarryDropPruneReason.DominanceReached10AndStayedAbove5)}[/] prune reason for [DodgerBlue1]p[/]=[Gray100 Bold]{pLong}[/], [DodgerBlue1]q[/]=[Gray100 Bold]{qExact}[/]: [DarkOrange]reached5[/]=[Yellow]{reached5}[/], [DarkOrange]totalTransitionsOver10[/]=[Yellow]{totalTransitionsOver10}[/], [DarkOrange]lastStreakBelow10[/]=[Yellow]{lastStreakBelow10}[/], [DarkOrange]longestStreakBelow10[/]=[Yellow]{longestStreakBelow10}[/], [DarkOrange]zeroCount[/]=[Yellow]{zeroCount}[/], [DarkOrange]first10[/]=[Yellow]{first10}[/], [DarkOrange]totalCarryBelow10[/]=[Yellow]{totalCarryBelow10}[/], [DarkOrange]totalCarry2[/]=[Yellow]{totalCarry2Count}[/], [DarkOrange]totalCarry10[/]=[Yellow]{totalCarry10Count}[/], [DarkOrange]totalCarry11[/]=[Yellow]{totalCarry11Count}[/]{Environment.NewLine}"); + } + TraceCarryDropHeuristicPrune(pLong, qExact, pruneReason, reached10, reachedBelow5, reached5, zeroCount); #endif return true; } else if (reached10 && !reachedBelow5 && reached5 > 0) { - Console.WriteLine($"Something excluded this filter for p={pLong}, q={qExact}, reached5={reached5}, totalTransitionsOver10={totalTransitionsOver10}, lastStreakBelow10={lastStreakBelow10}, longestStreakBelow10={longestStreakBelow10}, zeroCount={zeroCount}, first10={first10}, totalCarryBelow10={totalCarryBelow10}, totalCarry2={totalCarry2Count}"); + AnsiConsole.MarkupLine($"{Environment.NewLine}[MediumOrchid1_1]{nameof(CarryDropPruneReason.DominanceReached10AndStayedAbove5)}[/] filter [Red]failed[/] for [DodgerBlue1]p[/]=[Gray100 Bold]{pLong}[/], [DodgerBlue1]q[/]=[Gray100 Bold]{qExact}[/], [DarkOrange]reached5[/]=[Yellow]{reached5}[/], [DarkOrange]totalTransitionsOver10[/]=[Yellow]{totalTransitionsOver10}[/], [DarkOrange]lastStreakBelow10[/]=[Yellow]{lastStreakBelow10}[/], [DarkOrange]longestStreakBelow10[/]=[Yellow]{longestStreakBelow10}[/], [DarkOrange]zeroCount[/]=[Yellow]{zeroCount}[/], [DarkOrange]first10[/]=[Yellow]{first10}[/], [DarkOrange]totalCarryBelow10[/]=[Yellow]{totalCarryBelow10}[/], [DarkOrange]totalCarry2[/]=[Yellow]{totalCarry2Count}[/], [DarkOrange]totalCarry10[/]=[Yellow]{totalCarry10Count}[/], [DarkOrange]totalCarry11[/]=[Yellow]{totalCarry11Count}[/]{Environment.NewLine}"); } return false; @@ -3046,7 +3130,7 @@ internal static class BitContradictionSolverWithAMultiplier #if WITH_PRUNE_STATS if (pLong == 138000953 && qExact.Equals(_testCase)) { - Console.WriteLine($"Validating heuristic prune: p={pLong}, q={qExact}, reason={carryDropPruneReason}"); + AnsiConsole.MarkupLine($"Validating heuristic prune: p={pLong}, q={qExact}, reason={carryDropPruneReason}"); } #endif @@ -3336,7 +3420,7 @@ internal static class BitContradictionSolverWithAMultiplier divides = false; #if DETAILED_LOG - Console.WriteLine($"[bit-contradiction] Pruned with {nameof(TryPropagateCarry)}, reversed prefix filter"); + AnsiConsole.MarkupLine($"[bit-contradiction] Pruned with {nameof(TryPropagateCarry)}, reversed prefix filter"); #endif #if WITH_PRUNE_STATS @@ -4136,7 +4220,7 @@ internal static class BitContradictionSolverWithAMultiplier } else { - // Console.WriteLine("Rebuilding window"); + // AnsiConsole.MarkupLine("Rebuilding window"); Array.Clear(knownOne0, 0, wordCount); Array.Clear(knownOne1, 0, wordCount); Array.Clear(knownZero0, 0, wordCount); @@ -4210,7 +4294,7 @@ internal static class BitContradictionSolverWithAMultiplier { #if DETAILED_LOG reason = propagateReason; - Console.WriteLine($"[bit-contradiction] Pruned with {nameof(TryAdvanceStableUnknown)} 1, remaining={remaining}"); + AnsiConsole.MarkupLine($"[bit-contradiction] Pruned with {nameof(TryAdvanceStableUnknown)} 1, remaining={remaining}"); #endif #if WITH_PRUNE_STATS @@ -4235,7 +4319,7 @@ internal static class BitContradictionSolverWithAMultiplier { #if DETAILED_LOG reason = propagateReason; - Console.WriteLine($"[bit-contradiction] Pruned with {nameof(TryAdvanceStableUnknown)} 2, remaining={remaining}"); + AnsiConsole.MarkupLine($"[bit-contradiction] Pruned with {nameof(TryAdvanceStableUnknown)} 2, remaining={remaining}"); #endif #if WITH_PRUNE_STATS @@ -4282,7 +4366,7 @@ internal static class BitContradictionSolverWithAMultiplier // #if DETAILED_LOG // reason = ContradictionReason.ParityUnreachable; // #endif - // // Console.WriteLine("[bit-contradiction] Pruned with CouldStillReachTopCarryZero_UpperBound"); + // // AnsiConsole.MarkupLine("[bit-contradiction] Pruned with CouldStillReachTopCarryZero_UpperBound"); // #if WITH_PRUNE_STATS // Atomic.Add(ref _prunedWithCouldStillReachTopCarryZero_UpperBound, 1UL); // #endif @@ -4311,7 +4395,7 @@ internal static class BitContradictionSolverWithAMultiplier // reason = ContradictionReason.ParityUnreachable; // #endif - // Console.WriteLine("[bit-contradiction] Pruned with BestCaseCarryOutOneStep"); + // AnsiConsole.MarkupLine("[bit-contradiction] Pruned with BestCaseCarryOutOneStep"); // #if WITH_PRUNE_STATS // Atomic.Add(ref _prunedWithBestCaseCarryOutOneStep, 1UL); @@ -4353,7 +4437,7 @@ internal static class BitContradictionSolverWithAMultiplier { #if DETAILED_LOG reason = ContradictionReason.ParityUnreachable; - Console.WriteLine($"[bit-contradiction] Pruned with {nameof(TryFindSingleUnknownInQ_Prefix)}, needOne={needOne}, aIndex={aIndex}, state=2"); + AnsiConsole.MarkupLine($"[bit-contradiction] Pruned with {nameof(TryFindSingleUnknownInQ_Prefix)}, needOne={needOne}, aIndex={aIndex}, state=2"); #endif #if WITH_PRUNE_STATS @@ -4416,7 +4500,7 @@ internal static class BitContradictionSolverWithAMultiplier { #if DETAILED_LOG reason = ContradictionReason.ParityUnreachable; - Console.WriteLine($"[bit-contradiction] Pruned with {nameof(TryFindSingleUnknownInQ_Prefix)}, needOne={needOne}, aIndex={aIndex}, state=1"); + AnsiConsole.MarkupLine($"[bit-contradiction] Pruned with {nameof(TryFindSingleUnknownInQ_Prefix)}, needOne={needOne}, aIndex={aIndex}, state=1"); #endif #if WITH_PRUNE_STATS @@ -4594,7 +4678,7 @@ internal static class BitContradictionSolverWithAMultiplier { #if DETAILED_LOG reason = ContradictionReason.ParityUnreachable; - Console.WriteLine($"[bit-contradiction] Pruned with {nameof(TryPropagateCarry)}"); + AnsiConsole.MarkupLine($"[bit-contradiction] Pruned with {nameof(TryPropagateCarry)}"); #endif #if WITH_PRUNE_STATS @@ -4613,12 +4697,12 @@ internal static class BitContradictionSolverWithAMultiplier // { // if (colsLeftToTop < 63) // { - // Console.WriteLine("[bit-contradiction] Checking TOP-CARRY PRUNE"); + // AnsiConsole.MarkupLine("[bit-contradiction] Checking TOP-CARRY PRUNE"); // if ((carry.Min >> colsLeftToTop) > 0) // { // #if DETAILED_LOG // reason = ContradictionReason.ParityUnreachable; - // Console.WriteLine("[bit-contradiction] Pruned with TOP-CARRY PRUNE"); + // AnsiConsole.MarkupLine("[bit-contradiction] Pruned with TOP-CARRY PRUNE"); // #endif // #if WITH_PRUNE_STATS // Atomic.Add(ref _prunedWithTopCarry, 1UL); @@ -4628,7 +4712,7 @@ internal static class BitContradictionSolverWithAMultiplier // } // else // { - // Console.WriteLine($"[bit-contradiction] TOP-CARRY PRUNE too far away from top {colsLeftToTop}"); + // AnsiConsole.MarkupLine($"[bit-contradiction] TOP-CARRY PRUNE too far away from top {colsLeftToTop}"); // } // // colsLeftToTop >= 63 => shift dałby 0, więc nigdy nie tnij (konserwatywnie) // } @@ -5045,7 +5129,7 @@ internal static class BitContradictionSolverWithAMultiplier // if (_debugEnabled && _parityZeroLogCount < 8) // { // _parityZeroLogCount++; - // Console.WriteLine($"[bit-contradiction] unknown==1 parity forces zero at column={column} carry=[{minSum},{maxSum}] forced={forced} chosenIndex={chosenIndex}"); + // AnsiConsole.MarkupLine($"[bit-contradiction] unknown==1 parity forces zero at column={column} carry=[{minSum},{maxSum}] forced={forced} chosenIndex={chosenIndex}"); // } // Treat the single unknown as 0 for parity. diff --git a/PerfectNumbers.Core/Cpu/MersenneNumberDivisorByDivisorPrimeScanSessionWithTemplate.cs b/PerfectNumbers.Core/Cpu/MersenneNumberDivisorByDivisorPrimeScanSessionWithTemplate.cs index 655c50e..26c37b4 100644 --- a/PerfectNumbers.Core/Cpu/MersenneNumberDivisorByDivisorPrimeScanSessionWithTemplate.cs +++ b/PerfectNumbers.Core/Cpu/MersenneNumberDivisorByDivisorPrimeScanSessionWithTemplate.cs @@ -5,6 +5,8 @@ using System.Numerics; using PerfectNumbers.Core.Gpu; using PerfectNumbers.Core.Gpu.Accelerators; using System.Runtime.CompilerServices; +using Spectre.Console; + #if DivisorSet_Pow2Groups @@ -83,7 +85,7 @@ internal struct MersenneNumberDivisorByDivisorPrimeScanSessionWithTemplate { try { - Console.WriteLine($"Processing {prime}"); + AnsiConsole.MarkupLine($"[Gray100]Processing[/] [Yellow Bold]{prime}[/]"); string extension = ".bin"; #if DivisorSet_Predictive extension = ".predictive"; @@ -108,17 +110,18 @@ internal struct MersenneNumberDivisorByDivisorPrimeScanSessionWithTemplate { _markComposite(); _printResult(prime, true, true, false, divisor); - Console.WriteLine($"Finished processing {prime}"); + AnsiConsole.MarkupLine($"[DarkTurquoise]Finished processing[/] [Yellow Bold]{prime}[/]"); return; } _clearComposite(); _printResult(prime, true, divisorsExhausted, true, divisor); - Console.WriteLine($"Finished processing {prime}"); + AnsiConsole.MarkupLine($"[DarkTurquoise]Finished processing[/] [Yellow Bold]{prime}[/]"); } catch (Exception ex) { - Console.WriteLine($"Error processing {ex.Message} {ex.StackTrace}"); + AnsiConsole.WriteException(ex); + // Console.WriteLine($"Error processing {ex.Message} {ex.StackTrace}"); Environment.Exit(1); } } diff --git a/PerfectNumbers.Core/Gpu/MersenneNumberDivisorByDivisorGpuPrimeScanSession.cs b/PerfectNumbers.Core/Gpu/MersenneNumberDivisorByDivisorGpuPrimeScanSession.cs index 24446df..c669432 100644 --- a/PerfectNumbers.Core/Gpu/MersenneNumberDivisorByDivisorGpuPrimeScanSession.cs +++ b/PerfectNumbers.Core/Gpu/MersenneNumberDivisorByDivisorGpuPrimeScanSession.cs @@ -1,6 +1,7 @@ using System.Globalization; using System.IO; using System.Numerics; +using Spectre.Console; namespace PerfectNumbers.Core.Gpu; @@ -34,7 +35,7 @@ internal struct MersenneNumberDivisorByDivisorGpuPrimeScanSession { try { - Console.WriteLine($"Processing {prime}"); + AnsiConsole.MarkupLine($"[Gray100]Processing[/] [Yellow Bold]{prime}[/]"); string stateFile = prime.ToString(CultureInfo.InvariantCulture) + ".bin"; ConfigureForPrime(stateFile); @@ -45,17 +46,17 @@ internal struct MersenneNumberDivisorByDivisorGpuPrimeScanSession { _markComposite(); _printResult(prime, true, true, false, divisor); - Console.WriteLine($"Finished processing {prime}"); + AnsiConsole.MarkupLine($"[DarkTurquoise]Finished processing[/] [Yellow Bold]{prime}[/]"); return; } _clearComposite(); _printResult(prime, true, divisorsExhausted, true, divisor); - Console.WriteLine($"Finished processing {prime}"); + AnsiConsole.MarkupLine($"[DarkTurquoise]Finished processing[/] [Yellow Bold]{prime}[/]"); } catch (Exception ex) { - Console.WriteLine($"Error processing {ex.Message} {ex.StackTrace}"); + AnsiConsole.WriteException(ex); Environment.Exit(1); } } diff --git a/PerfectNumbers.Core/MersenneNumberDivisorByDivisorTester.cs b/PerfectNumbers.Core/MersenneNumberDivisorByDivisorTester.cs index a8b8f69..c0d29f8 100644 --- a/PerfectNumbers.Core/MersenneNumberDivisorByDivisorTester.cs +++ b/PerfectNumbers.Core/MersenneNumberDivisorByDivisorTester.cs @@ -24,6 +24,7 @@ using MersenneNumberDivisorByDivisorCpuTesterWithBitContradictionGpuOrder = Perf using MersenneNumberDivisorByDivisorCpuTesterWithBitTreeCpuOrder = PerfectNumbers.Core.Cpu.MersenneNumberDivisorByDivisorCpuTesterWithForBitTreeDivisorSetForCpuOrder; using MersenneNumberDivisorByDivisorCpuTesterWithBitTreeHybridOrder = PerfectNumbers.Core.Cpu.MersenneNumberDivisorByDivisorCpuTesterWithForBitTreeDivisorSetForHybridOrder; using MersenneNumberDivisorByDivisorCpuTesterWithBitTreeGpuOrder = PerfectNumbers.Core.Cpu.MersenneNumberDivisorByDivisorCpuTesterWithForBitTreeDivisorSetForGpuOrder; +using Spectre.Console; namespace PerfectNumbers.Core; @@ -1199,7 +1200,7 @@ public static class MersenneNumberDivisorByDivisorTester { try { - Console.WriteLine($"Processing {prime}"); + AnsiConsole.MarkupLine($"[Gray100]Processing[/] [Yellow Bold]{prime}[/]"); string stateFile = Path.Combine( PerfectNumberConstants.ByDivisorStateDirectory, prime.ToString(CultureInfo.InvariantCulture) + ".bin"); @@ -1235,17 +1236,18 @@ public static class MersenneNumberDivisorByDivisorTester markComposite(); printResult(prime, true, true, false, divisor); - Console.WriteLine($"Finished processing {prime}"); + AnsiConsole.MarkupLine($"[DarkTurquoise]Finished processing[/] [Yellow Bold]{prime}[/]"); return; } clearComposite(); printResult(prime, true, divisorsExhausted, true, divisor); - Console.WriteLine($"Finished processing {prime}"); + AnsiConsole.MarkupLine($"[DarkTurquoise]Finished processing[/] [Yellow Bold]{prime}[/]"); } catch (Exception ex) { - Console.WriteLine($"Error processing {ex.Message} {ex.StackTrace}"); + AnsiConsole.WriteException(ex); + // Console.WriteLine($"Error processing {ex.Message} {ex.StackTrace}"); Environment.Exit(1); } } diff --git a/PerfectNumbers.Core/PerfectNumbers.Core.csproj b/PerfectNumbers.Core/PerfectNumbers.Core.csproj index 1cfe9d9..0628fff 100644 --- a/PerfectNumbers.Core/PerfectNumbers.Core.csproj +++ b/PerfectNumbers.Core/PerfectNumbers.Core.csproj @@ -13,7 +13,7 @@ - + $(DefineConstants);WITH_PRUNE_STATS @@ -29,6 +29,7 @@ +