This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" BBerg32 | |
Primality test for 32 bit integers using a single SPRP test. | |
The SPRP base comes from a hash table. | |
Hash and bases by Bradley Berg | |
See https://techneon.com/download/is.prime.32.base.data | |
""" | |
bases = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(0, 1) : 50 | |
(1, 0) : 50 | |
(0, 2) : 258 | |
(1, 1) : 600 | |
(2, 0) : 258 | |
(0, 3) : 186 | |
(1, 2) : 1086 | |
(2, 1) : 1086 | |
(3, 0) : 186 | |
(0, 4) : 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Maxwell–Boltzmann distribution | |
See https://en.m.wikipedia.org/wiki/Maxwell%E2%80%93Boltzmann_distribution | |
Written by PM 2Ring 2021.06.20 | |
""" | |
# Gas constant g⋅m^2⋅s^−2⋅K^−1⋅mol^−1 | |
R = 8314.46261815324 | |
@interact | |
def _(T=('temp (°C)', 20), mass=('mass (g/mol)', 29), | |
auto_update=False): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Lorenz attractor | |
From https://en.wikipedia.org/wiki/Lorenz_system | |
Modified for Sagemath by PM 2Ring 2023.01.04 | |
""" | |
import numpy as np | |
from scipy.integrate import odeint | |
# Build Bezier curves |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Borwein + Borwein quadratic pi | |
Algorithm 2.1 from "Pi and the AGM" (Wiley, 1987) | |
Written by PM 2Ring 2023.1.2 | |
""" | |
from math import floor, log, pi | |
from decimal import Decimal as D, getcontext | |
def borwein_pi(loops): | |
x = D(2).sqrt() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" pi from 10 * asin((phi-1)/2) | |
Uses Carlson's accelerated version of | |
Borchardt's modified AGM algorithm | |
Written by PM 2Ring 2022.05.11 | |
""" | |
from itertools import count | |
from decimal import Decimal as D, getcontext |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Standard Solar Model (BP2004) | |
https://www.sns.ias.edu/~jnb/SNdata/Export/BP2004/bp2004stdmodel.dat | |
astro-ph/0402114 | |
Columns in the Standard Model table (below) represent: | |
1) Mass fraction in units of the solar mass | |
2) Radius of the zone in units of one solar radius | |
3) Temperature in units of deg (K) | |
4) Density in units of g/cm^3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Deterministic Miller-Rabin primality test | |
See https://en.m.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test | |
and https://miller-rabin.appspot.com/ | |
Written by PM 2Ring 2015.04.29 | |
Updated 2022.04.20 | |
""" | |
small_primes = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
''' Find all divisors in a range by sieving | |
Written by PM 2Ring 2017.05.03 | |
Prime GP version | |
''' | |
from itertools import product |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Julian day number to date conversion | |
Proleptic Gregorian and Julian, with Astronomical years | |
i.e., 1 AD = year 1, 1 BC = year 0, 2 BC = year -1, etc | |
Derived from RG Tantzen (1963), ACM. | |
Algorithm 199: conversions between calendar date and Julian day number. | |
https://en.wikipedia.org/wiki/Julian_day | |
Julian day number 0 assigned to the day starting at noon on | |
January 1, 4713 BC, proleptic Julian calendar |