Skip to content

Instantly share code, notes, and snippets.

@inaz2
inaz2 / multinom_test.py
Created November 3, 2023 04:32
Exact multinomial test of goodness-of-fit by Scipy
$ python multinom_test.py
H0: the observed frequeicies follows the expected ones
H1: the observed frequeicies does not follow the expected ones
observed_frequencies = [0, 10, 6, 4, 5, 5]
alpha = 0.05
chisquare: p = 0.064663, H0 is NOT rejected
multinom_test: p = 0.030745, H0 is rejected (# of possible events = 324632)
@inaz2
inaz2 / goodness_of_fit.py
Last active November 2, 2023 02:16
Statistical hypothesis testing of goodness-of-fit by Scipy
$ python goodness_of_fit.py
H0: the observed frequeicies follows the expected ones
H1: the observed frequeicies does not follow the expected ones
observed_frequencies = [0, 10, 6, 4, 5, 5]
alpha = 0.05
pearson: p = 0.064663, H0 is NOT rejected
log-likelihood: p = 0.014007, H0 is rejected
freeman-tukey: p = 0.000233, H0 is rejected
@inaz2
inaz2 / fake_eff.py
Last active September 7, 2023 14:40
Emulating fake algebraic effects in Python 3
import itertools
from dataclasses import dataclass
from typing import Any, Callable
Handler = Callable[[Any], Any]
@dataclass(frozen=True, match_args=True)
class Effect:
expr: tuple
@inaz2
inaz2 / pollard_rho.c
Last active August 22, 2023 03:15
Pollard-rho algorithm in Julia and GMP C
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.3 LTS
Release: 22.04
Codename: jammy
$ grep "processor\|model name" /proc/cpuinfo
processor : 0
model name : Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz
@inaz2
inaz2 / PollardRho.hs
Last active September 21, 2023 09:31
Pollard-rho algorithm in Haskell/OCaml/F#/Common Lisp/Gauche Scheme/Typed Racket/Erlang
import System.Environment
import Text.Printf
-- single-line comments
{-
multi-line comments
-}
pollardRho n =
@inaz2
inaz2 / pollardRho.go
Last active September 18, 2023 12:08
Pollard-rho algorithm in Golang and math/big
$ go version
go version go1.21.0 linux/amd64
$ go build -ldflags="-s -w" -trimpath pollardRho.go
$ time ./pollardRho 12814570762777948741
12814570762777948741 = 3861801803 * 3318288047
real 0m0.160s
user 0m0.060s
@inaz2
inaz2 / Cargo.toml
Last active August 17, 2023 03:51
Pollard-rho algorithm in Rust and rug
[package]
name = "pollard_rho"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rug = "1.20.1"
@inaz2
inaz2 / comparison.md
Created March 19, 2023 18:04
Comparison of Python type-checkers

Test code

from typing import List
import requests

def ident(x):
    return x

def add_1(x):
interface T<V> { valueOf(): V }
type HECK<V> = V extends T<infer R> ? T<R> : never
type P = string | number | boolean | null | undefined
type FXCK = { [k: string]: U }
type SXIT = (...args: U[]) => U | void
type U = U[] | FXCK | SXIT | P | HECK<any>
let fxck: U
fxck = {}; console.log(fxck) // FXCK | T<unknown>
fxck = []; console.log(fxck) // U[] | T<unknown>
@inaz2
inaz2 / squfof.py
Last active January 5, 2023 12:42
SQUFOF algorithm (Shanks's square forms factorization)
$ time python3 squfof.py 60766145992321225002169406923
60766145992321225002169406923 = 242950340194949 * 250117558771727
real 0m23.864s
user 0m23.850s
sys 0m0.008s