Fixed the no output when given a pair that cannot be computed. Also added more debug information.
Stergios Upload Compile Checker / Explore-Gitea-Actions (push) Successful in 4s

This commit is contained in:
metallaxis committed 2026-07-05 06:52:11 +03:00
1 parent fa7aa240e1
commit 067e9bd7fc
4 files changed
+150 -16

No files matched your search

+1 -1
View File
@@ -19,7 +19,7 @@ make --debug linux/windows (Compile with Makefile debug information)
```sh ```sh
make && ./bin/stergios (Normal version) make && ./bin/stergios (Normal version)
make && echo -e "3\n./exponentials-values/exponential-3.txt\n\n2\n" | time ./bin/stergios (Run the version for the exponential being 3 and low info printing and the amount of time it takes to execute) make && echo -e "3\n./exponentials-values/exponential-3.txt\n\n2\n" | time ./bin/stergios (Run the version for the exponential being 3 and low info printing and the amount of time it takes to execute)
make && echo -e "2\n\n2\n" | time ./bin/stergios (Run the version for the expontial being 7 and low info printing and the amount of time it takes to execute) make && echo -e "2\n\n2\n7\n" | time ./bin/stergios (Run the version for the expontial being 7 and low info printing and the amount of time it takes to execute)
``` ```
## Nix Flakes ## Nix Flakes
+119
View File
@@ -0,0 +1,119 @@
#!/usr/bin/env python3
"""
Analyze stergios(a,b,c) data to test candidate closed-form formulas.
Expected input format (one row per line, from your solver's dump):
a b c moves gcd(a,c) gcd(b,c) (c%b) (c%a) k d1 d2
Usage:
python3 analyze_stergios.py your_data_file.txt
"""
import sys
import math
def euclid_sum(x, y):
"""Sum of quotients in the Euclidean algorithm on |x|, |y|."""
x, y = abs(x), abs(y)
if x == 0 or y == 0:
return None
total = 0
while y != 0:
q = x // y
total += q
x, y = y, x % y
return total
def load_rows(path):
rows = []
with open(path) as f:
for line in f:
parts = line.split()
if len(parts) < 11:
continue
try:
a, b, c, moves, gac, gbc, cmb, cma, k, d1, d2 = map(int, parts[:11])
except ValueError:
continue # skip header / "Total sum is:" lines
rows.append(dict(a=a, b=b, c=c, moves=moves, k=k, d1=d1, d2=d2))
return rows
def check_reflection_identity(rows):
"""Verify: stergios(c) == stergios(2(a+b)-c) - 1 for c < a+b."""
lookup = {r['c']: r['moves'] for r in rows}
ok, bad = 0, []
for r in rows:
if r['d1'] < 0 and r['c'] != 0:
c2 = 2 * (r['a'] + r['b']) - r['c']
if c2 in lookup:
pred = lookup[c2] - 1
if pred == r['moves']:
ok += 1
else:
bad.append((r['c'], r['moves'], pred))
print(f"[Reflection identity] {ok}/{ok+len(bad)} match")
for b in bad:
print(" MISMATCH c=%d moves=%d pred=%d" % b)
return ok, bad
def check_euclid_formula(rows):
"""Verify: stergios(c) == euclid_sum(2b, d1) for c > a+b."""
ok, bad = 0, []
for r in rows:
if r['d1'] > 0:
pred = euclid_sum(2 * r['b'], r['d1'])
if pred == r['moves']:
ok += 1
else:
bad.append((r['c'], r['moves'], pred, r['d1']))
print(f"[Euclid(2b,d1) formula] {ok}/{ok+len(bad)} match")
for b in bad:
print(" MISMATCH c=%d moves=%d pred=%d d1=%d" % b)
return ok, bad
def full_prediction(a, b, c):
"""Best-known closed form. Returns None if it can't currently predict
this row (i.e. c falls in the known-unresolved band)."""
Q = (c - a - b) ** 2 - 4 * a * b
if Q < 0:
return None # not solvable (or needs separate check)
k = math.isqrt(Q)
if k * k != Q:
return None # not a perfect square -> not solvable
if c == a + b:
return None # degenerate, not covered
if c < a + b:
c2 = 2 * (a + b) - c
inner = full_prediction(a, b, c2)
return None if inner is None else inner - 1
d1 = (c - a - b) - k
return euclid_sum(2 * b, d1)
def check_full_formula(rows):
ok, bad, unresolved = 0, [], []
for r in rows:
if r['c'] == 0:
continue
pred = full_prediction(r['a'], r['b'], r['c'])
if pred is None:
unresolved.append(r['c'])
elif pred == r['moves']:
ok += 1
else:
bad.append((r['c'], r['moves'], pred))
print(f"[Full formula] {ok} matched, {len(bad)} WRONG, {len(unresolved)} unresolved (formula returned None)")
for b in bad:
print(" WRONG c=%d moves=%d pred=%d" % b)
if unresolved:
print(" Unresolved c values:", unresolved)
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python3 analyze_stergios.py <data_file>")
sys.exit(1)
rows = load_rows(sys.argv[1])
print(f"Loaded {len(rows)} rows\n")
check_reflection_identity(rows)
print()
check_euclid_formula(rows)
print()
check_full_formula(rows)
+19 -10
View File
@@ -81,7 +81,11 @@ static bool bfs(int128_t* sum, int128_t gcd,
} }
if (!found) { if (!found) {
if (print_mode == 1) printf("No solution found.\n"); fprintf(output, "No solution found for (");
fprint_int128(output, a0); fprintf(output, ", ");
fprint_int128(output, b0); fprintf(output, ", ");
fprint_int128(output, c0);
fprintf(output, ".\n");
return false; return false;
} }
@@ -125,15 +129,20 @@ static bool bfs(int128_t* sum, int128_t gcd,
} }
} else if (print_mode == 3) { } else if (print_mode == 3) {
if (output) { if (output) {
fprint_int128(output, a0 * gcd); fprintf(output, " "); int128_t a = a0 * gcd, b = b0 * gcd, c = c0 * gcd;
fprint_int128(output, b0 * gcd); fprintf(output, " "); int128_t k = mysqrt_uint128(a * a + b * b + c * c - 2 *a * b - 2 * b * c - 2 * c * a);
fprint_int128(output, c0 * gcd); fprintf(output, " "); fprint_int128(output, a); fprintf(output, " ");
fprint_int128(output, b); fprintf(output, " ");
fprint_int128(output, c); fprintf(output, " ");
fprint_int128(output, max_moves); fprintf(output, " "); fprint_int128(output, max_moves); fprintf(output, " ");
fprint_int128(output, c0 * gcd); fprintf(output, " "); fprint_int128(output, gcd2(a, c)); fprintf(output, " ");
fprint_int128(output, gcd2(a0 * gcd, c0 * gcd)); fprintf(output, " "); fprint_int128(output, gcd2(b, c)); fprintf(output, " ");
fprint_int128(output, gcd2(b0 * gcd, c0 * gcd)); fprintf(output, " "); fprint_int128(output, c % b); fprintf(output, " ");
fprint_int128(output, (c0 * gcd) % (b0 * gcd)); fprintf(output, " "); fprint_int128(output, c % a); fprintf(output, " ");
fprint_int128(output, (c0 * gcd) % (a0 * gcd)); fprintf(output, " "); fprint_int128(output, k); fprintf(output, " ");
fprint_int128(output, c - a - b - k); fprintf(output, " ");
fprint_int128(output, c - a - b + k); fprintf(output, " ");
fprintf(output, "%s", k < 2 * (int128_t)mysqrt_uint128(a * b) ? "True" : "False");
fprintf(output, "\n"); fprintf(output, "\n");
} }
} }
@@ -148,6 +157,6 @@ static bool bfs(int128_t* sum, int128_t gcd,
bool solve(int128_t* sum, int128_t gcd, bool solve(int128_t* sum, int128_t gcd,
int128_t a0, int128_t b0, int128_t c0, int print_mode, FILE* output) { int128_t a0, int128_t b0, int128_t c0, int print_mode, FILE* output) {
/* Fallback to BFS */ /* Execute to BFS */
return bfs(sum, gcd, a0, b0, c0, print_mode, output); return bfs(sum, gcd, a0, b0, c0, print_mode, output);
} }
+11 -5
View File
@@ -138,10 +138,10 @@ int main() {
} }
if (a0 == 0 || b0 == 0 || c0 == 0) { if (a0 == 0 || b0 == 0 || c0 == 0) {
printf("Already zero present: ("); fprintf(f_output, "Already zero present: (");
print_int128(a0); printf(", "); fprint_int128(f_output, a0); fprintf(f_output, ", ");
print_int128(b0); printf(", "); fprint_int128(f_output, b0); fprintf(f_output, ", ");
print_int128(c0); printf(")\n"); fprint_int128(f_output, c0); fprintf(f_output, ")\n");
return 0; return 0;
} }
int128_t gcd = gcd3(a0, b0, c0); int128_t gcd = gcd3(a0, b0, c0);
@@ -153,7 +153,13 @@ int main() {
solve(&sum, gcd, a, b, c, print_mode, f_output); solve(&sum, gcd, a, b, c, print_mode, f_output);
} else if (mode == 2) { } else if (mode == 2) {
clear_global_table(); /* Reset unique root tracker */ clear_global_table(); /* Reset unique root tracker */
int32_t p = 7; char* line = prompt_line("Choose what exponential you want to use: ");
if (!line) {
fprintf(stderr, "Input error.\n");
return 1;
}
int32_t p = atoi(line);
free(line);
int32_t exponents[3] = {2*p + 2, p, p}; int32_t exponents[3] = {2*p + 2, p, p};
int128_t values[3] = {4 * power(a0, p) * power(b0, p), power(a0, p), power(b0, p)}; int128_t values[3] = {4 * power(a0, p) * power(b0, p), power(a0, p), power(b0, p)};
generate_factor_pairs(&sum, 0, exponents, values, 1, print_mode, f_output); generate_factor_pairs(&sum, 0, exponents, values, 1, print_mode, f_output);