Skip to content

Instantly share code, notes, and snippets.

View Hermann-SW's full-sized avatar

Hermann Stamm-Wilbrandt Hermann-SW

View GitHub Profile
@Hermann-SW
Hermann-SW / sqrtm1.smallest_known_1million_digit_prime.cc
Created June 19, 2023 00:10
Only here to investigate "munmap_chunk(): invalid pointer"
This file has been truncated, but you can view the full file.
// x,y -> sqrtm1 [-> x,y]
//
// https://t5k.org/primes/lists/all.txt
// 2147 10^999999+308267*10^292000+1 1000000 CH10 2021
//
// f=sqrtm1.smallest_known_1million_digit_prime
//
// either
// g++ $f.cc -lgmp -lgmpxx -O3 -o $f
// or
@Hermann-SW
Hermann-SW / cypari2_.py
Last active June 14, 2023 09:59
Python script for testing making use of cypari2 if available
from sympy import gcd, I
try:
import cypari2
pari = cypari2.Pari()
gen_to_python = cypari2.convert.gen_to_python
except ImportError:
cypari2 = None
@Hermann-SW
Hermann-SW / phi_e_pi.py
Created June 3, 2023 13:39
Determinine percentages of "is_prime(f_x(p))" with "f_x(p) = round_to_odd(p * x)"
# pylint:disable=C0103, C0114, C0116, W0611
from math import sqrt, floor, pi, e
from sympy import nextprime, isprime
def digits(n):
return len(str(n))
phi = (sqrt(5) + 1) / 2
@Hermann-SW
Hermann-SW / sq2.gp
Last active June 2, 2023 19:48
1st Pari/GP experience, determine sum of squares for prime p = 1 (mod 4), implement "assert()"
\\ sq2(p) determines sum of squares for prime p = 1 (mod 4), implement "assert()"
\\
\\ based on
\\ - https://pari.math.u-bordeaux.fr/Events/PARI2019b/talks/init.pdf
\\ - https://pari.math.u-bordeaux.fr/Events/PARI2019b/talks/prog.pdf
\\ - https://pari.math.u-bordeaux.fr/pub/pari/manuals/2.15.1/tutorial.pdf
\\ - https://skalatan.de/en/archive/pariguide/doc/Programming_under_GP.html
\\ - https://home.gwu.edu/~maxal/gpscripts/binomod.gp
\\
assert(b, v, s) = { if(!(b), error(Str(v) Str(s))); }
@Hermann-SW
Hermann-SW / cython_demo
Created May 29, 2023 18:36
Short demo of using Cython, setting language_level, compare runtimes, ...
#!/bin/bash
pip install setuptools Cython gmpy2
rm -rf /tmp/tst && mkdir /tmp/tst && cd /tmp/tst
wget -q https://gist.githubusercontent.com/Hermann-SW/061d33b47325bd15a4033b33d3f7c4c9/raw/9900616d98b6acdd50c436d9ae914a1c5d81f2b2/sq2_cg.py
mv sq2_cg.py sq2_cg.pyx
cat << EOF > setup.py
from setuptools import setup
stateDiagram
    [*] --> Still
    Still --> [*]

    Still --> Moving
    Moving --> Still
    Moving --> Crash
    Crash --> [*]
@Hermann-SW
Hermann-SW / 36401.py
Created May 17, 2023 23:47
verification of sum of squares for 36401-digit palindromic prime
"""
sq2_sympy.py from here (plus time print() in "sq2()"):
https://github.com/sympy/sympy/issues/15358#issuecomment-1551635777
2.5GHz i7-11850H
1998.6601960659027s a = sqrt(-1) (mod p)
2011.4160270690918s x, y = gcd(p, a + I).as_real_imag()
"""
from math import log10
@Hermann-SW
Hermann-SW / sq2_cg.py
Last active May 12, 2023 09:06
determine sum of squares for 2467-digit prime, simplified for pycg callgraph analysis (manually transformed to Graphviz)
# pylint: disable=C0103
# invalid-name
"""
determine sum of squares for 2467-digit prime
- minimized for pycg analysis
- original: https://github.com/Hermann-SW/RSA_numbers_factored/blob/main/python/sq2.py
- manually converted to Graphviz with splines=ortho
- shortened GraphvizFiddle Share link: https://stamm-wilbrandt.de/sq2_cg.py.gvf.html
"""
from time import time
@Hermann-SW
Hermann-SW / calcpi.js
Last active May 15, 2023 02:50
gmp-wasm repo "benchmark/calcpi.js" modified to run with nodejs v12.22.12
const DecimalJs = require('decimal.js');
const Big = require('big.js');
const BigInteger = require('big-integer');
// const { init: initGMP, DivMode } = require('../dist/index.umd.js');
const { init: initGMP, DivMode } = require('gmp-wasm');
const piDecimals = require("pi-decimals");
const mpzjs = require("mpzjs");
function nullish(lhs, rhs) {
return (lhs === null || lhs === undefined) ? rhs : lhs
@Hermann-SW
Hermann-SW / Lehman_factor.alg
Created April 25, 2023 20:47
Lehman factoring Algol implementation from 1974 research paper
begin
comment v0.1, only factors sometimes as of now
comment runs with this compiler: https://github.com/JvanKatwijk/algol-60-compiler
$ jff-algol Lehman_factor.alg
$ ./Lehman_factor
32639 3
127
$
;