Skip to content

Instantly share code, notes, and snippets.

@mizar
mizar / Divapprox2.lean
Last active February 24, 2026 17:10
[Accuracy of Integer Division Approximate Function 2 解説](https://zenn.dev/mizar/articles/79ef8c9680265f) の形式的証明
import Mathlib
import Mwf
namespace Divapprox
/--
目的: 整数除算近似の誤差関数 `Δ(D,A,B,x)` を定義する。
定義: `Δ = ⌊x/D⌋ - ⌊⌊x/A⌋ * ⌊AB/D⌋ / B⌋` を `Int` の除算で実装する。
入力/前提: D A B x : Int、_hD : 0 < D、_hA : 0 < A。
出力: 型 `Int` の値を返す。
@mizar
mizar / fibonacci.ipynb
Last active February 6, 2025 04:00
fibonacci.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mizar
mizar / sorting_network.md
Last active January 2, 2025 13:58
Batcher Odd-Even Mergesort Sorting Network
# Batcher Odd-Even Mergesort Sorting Network Generator
# https://en.wikipedia.org/wiki/Batcher_odd%E2%80%93even_mergesort
# https://en.wikipedia.org/wiki/Sorting_network
gen = lambda N: [
    [
        (i+j, i+j+(1<<k))
        for j in range((1<<k)%(1<<p), N-(1<<k), 2<<k)
        for i in range(min(1<<k, N-j-(1<<k)))
        if (((i+j)^(i+j+(1<<k)))>>(p+1)) == 0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mizar
mizar / stlangex_env_standalone.py
Last active September 27, 2024 18:18
StLangEx実行環境 スタンドアロンパーサ版 https://yukicoder.me/problems/no/2908
"""StLang@Lark 実行環境サンプル standalone版"""
### TODO: ここからを本番の問題用の正しいコードに書き換える
PROGRAM = r"""
# サンプルプログラム: 二項係数 nCk の計算 (N > 62 の時は演算オーバーフローする可能性あり)
if N >= K # N < K の時の出力は 0 とする
$0 = 1
$1 = 1
$2 = N
while $1 <= K # for $1 in 1..=K
@mizar
mizar / sagemath-divmod-issue.ipynb
Last active July 25, 2024 12:28
sagemath-divmod-issue.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mizar
mizar / stlang_env_standalone.py
Last active September 27, 2024 18:19
StLang実行環境 スタンドアロンパーサ版 https://yukicoder.me/problems/no/2906
"""StLang@Lark 実行環境サンプル standalone版"""
### TODO: ここからを本番の問題用の正しいコードに書き換える
PROGRAM = r"""
# サンプルプログラム: 二項係数 nCk の計算 (N > 62 の時は演算オーバーフローする可能性あり)
if N >= K # N < K の時の出力は 0 とする
$0 = 1
$1 = 1
$2 = N
while $1 <= K # for $1 in 1..=K
@mizar
mizar / decimal_rounding_error.ipynb
Last active June 7, 2024 10:33
decimal_rounding_error.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mizar
mizar / stlang.ipynb
Last active September 27, 2024 18:16
StLang実行環境 Jupyter Notebook / Google Colab 向け https://yukicoder.me/problems/no/2906
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mizar
mizar / pmont.ipynb
Last active May 17, 2024 04:42
pmont.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.