Skip to content

Instantly share code, notes, and snippets.

@Hermann-SW
Hermann-SW / diophantine.primes.cdru.wl
Created April 26, 2026 20:15
Simplifying prime producing system of 14 diophantine equations on 26 variables for p=2
#!/usr/bin/env wolframscript
(*
based on
https://www.ericzheng.org/files/misc/prime.wl
details
https://www.ericzheng.org/thoughts/prime-polynomial.html
https://www.ericzheng.org/files/pdf/prime.pdf
*)
eq1 = w z + h + j - q
eq2 = (g k + g + k)(h + j) + h - z
@Hermann-SW
Hermann-SW / subsetsuM.cpp
Created April 12, 2026 08:20
Determine the (only 5) Mersenne prime exponents that cannot be built as sum of previous Mersenne prime exponents
/*
f=subsetsuM
g++ -O3 -Wall -pedantic -Wextra $f.cpp -o $f
cpplint --filter=-legal/copyright,-build/namespaces $f.cpp
cppcheck --enable=all --suppress=missingIncludeSystem $f.cpp --check-config
*/
#include <iostream>
#include <cassert>
#include <cinttypes>
@Hermann-SW
Hermann-SW / gps2svgs
Last active March 23, 2026 12:14
Combine PARI/GP script Graphviz output for several input values as SVGs into single row HTML table
#!/bin/bash
# gps2svgs psp2.gp 341 561 645 1105 1387 1729 1905 2047 > tst.html
# shell checked
#
scr=$1;shift
echo "<html><body><table border=1><tr>"
for n in "$@"; do echo "<td>$(dot -Tsvg <(n=$n gp -q < "$scr"))</td>"; done
echo "</tr></table></body></html>"
@Hermann-SW
Hermann-SW / S-Unit.sol.sage
Created March 12, 2026 20:42
SageMath diophantine S-Unit solve example: error free after many iterations of Google Gemini; changed to ℚ and added generator output by me
# 1. Setup
x = polygen(QQ, 'x')
# K.<i> = NumberField(x^2 + 1) # ℚ(i)
K.<i> = NumberField(x - 1)
# Using this, the root a is just 1. This forces Sage to wrap the rational
# numbers in a "NumberField object" which possesses the .S_unit_group() method.
#
S_list = K.primes_above(2) + K.primes_above(3)
@Hermann-SW
Hermann-SW / 23.gp
Last active March 5, 2026 15:18
There are no further Carmichael numbers N=2^a*3^b+1 below 10^70 (than 1729=2^6*3^3+1 and 46656=2^6*3^6+1)
is_carmichael_minus_1(f)={
n=factorback(f)+1;
v=[d+1|d<-divisors(n-1),n%(d+1)==0&&isprime(d+1)];
vecprod(v)==n; \\ Korselt's criterion
}
m=10^70;
{
for(a=1,oo,
if(2^a<=m,
@Hermann-SW
Hermann-SW / Car_n-1_3_prime_factors.gp
Last active March 10, 2026 22:44
Prime factorization of N-1 having exactly 3 prime factors, for Carchmichael numbers N ≤ 10^24
{[ [2, 4; 5, 1; 7, 1],
[2, 4; 3, 1; 23, 1],
[2, 5; 7, 1; 11, 1],
[2, 3; 3, 3; 7, 2],
[2, 2; 3, 2; 1777, 1],
[2, 3; 3, 2; 1753, 1],
[2, 4; 3, 3; 1733, 1],
[2, 8; 3, 2; 433, 1],
[2, 3; 3, 5; 557, 1],
[2, 3; 3, 3; 23, 3],
@Hermann-SW
Hermann-SW / Car_3.343dd.gp
Last active March 2, 2026 08:19
3 prime factor Charmichael number examples for roughly every 3 decimal digits up to 343
assert(b)=if(!(b),error());
factmul(f1,f2)=matreduce(matconcat([f1,f2]~));
factval(F)=vecprod([v[1]^v[2]|v<-F~]);
{Redu=[0,25,0,25,110,291,51,146,131,511,111,95,1121,2685,820,12481,16175,1866,
4500,11525,8960,441,390,14796,1280,1651,1730,24140,21226,18555,43391,3716,2980,
46701,38580,15450,5560,19445,14376,83660,32560,7516,5060,23806,57806,44636,
28985,73445,60936,55146,91400,82190,54255,8016,25591,71945,259946,147035,11301,
3375,2371,18486,466191,436551,422806,6220,153406,493275,222755,1572896,453141,
5385,422511,663666,364225,84081,52590,916505,285466,827301,5671,137266,120160,
@Hermann-SW
Hermann-SW / 96522.gp
Created February 24, 2026 20:42
@neptune's largest known 96,522 decimal digits 3-Carmichael number, with single random base verification
\\ @Neptune's largest known 3-Carmichael number (96522 decimal digits):
\\ https://www.mersenneforum.org/node/22080/page3#post1066763
p = 3*(5752211*43#/2-1)^1069/2+1;
q = 3*(5752211*43#/2-1)^1069+1;
r = 3*((5752211*43#/2-1)^1069+(5752211*43#/2-1)^2138)/1050650772710+1;
n = p*q*r;
print(#digits(n));
n1 = (n-1)/gcd(n-1,p-1);
@Hermann-SW
Hermann-SW / 3710.gp
Last active February 25, 2026 04:35
3710 decimal digits Carmichael number from 1989 Dubner paper table 1
\\ 3710 decimal digits Carmichael number from 1989 Dubner paper table 1:
\\ https://www.ams.org/journals/mcom/1989-53-187/S0025-5718-1989-0969484-8/S0025-5718-1989-0969484-8.pdf
\\
T=47#/2;A=41;C=141847;M=(T*C-1)^A/4;P=6*M+1;Q=12*M+1;X=123165;R=1+(P*Q-1)/X;
N=P*Q*R;
\\ known partial N-1 factorization: https://www.mersenneforum.org/node/1106127
{F=[2,41;3,1;11,1;13,1;19,1;29,1;31,1;37,1;41,2;43,1;47,1;59,41;79,41;83,1;
1709,1;3527,1;3691,1;16943,1;469793,41;1799411527,1;3463701403,1;
731646295847,1;9957992526379,41;677868618879887,1;278798236535678281,1;
61534897980248555544581,1;9929897004627382451681972907710143,1];}
@Hermann-SW
Hermann-SW / par2.gp
Created February 16, 2026 14:16
Parallel determination of primitive root of n-th Euclid prime
check(En, n, phi, g, i)={
parfor(i=1, n, lift(Mod(g, En)^(phi / prime(i))) == 1, r, if(r, return(0)));
1
}
euclid_prime_find_root(n) = {
my(En = vecprod(primes(n)) + 1, phi = En - 1);
for(g=2, En-1,
if(lift(kronecker(g, En))==-1,