rust-ritsuryo: Japanese date and tax calculations proved in Lean 4, as a Rust crate and a web page
lean-ritsuryo is a library that computes the periods and tax amounts set by Japanese law in Lean 4, with proofs that the calculations match a specification transcribed from the statutes. I compiled it to Rust with lean-rs and turned it into a Rust crate and a web page that does the calculations in the browser alone.
The repository is conao3/rust-ritsuryo, under Apache-2.0, and the crate is on crates.io as ritsuryo.
Calculate in the browser
The web page is at this URL.
https://conao3.github.io/rust-ritsuryo/
The form offers the same calculations as the lean-ritsuryo CLI, such as the end date of a period, public holidays, income tax, inheritance tax, and consumption tax.
The image above shows the income tax for 2025 on a total taxable income of 5,000,000 yen, and the amount to pay comes to 584,500 yen. That amount is the income tax of 572,500 yen plus 12,022 yen of special income tax for reconstruction (2.1% of the income tax), which makes 584,522 yen, with the part under 100 yen cut off. The calculation runs inside the browser, so the page sends your input nowhere.
Call it from Rust
Add ritsuryo to Cargo.toml, and you can call the same calculations from Rust.
[dependencies]
ritsuryo = "0.1.0"
serde_json = "1"
use serde_json::json;
fn main() {
let out = ritsuryo::invoke(
"income-tax",
"compute-tax",
&json!({"TaxYear": 2025, "TaxableIncome": 5_000_000}),
)
.unwrap();
println!("{}", out["Result"]);
for h in ritsuryo::holiday::holidays(2027).iter().take(3) {
println!("{}/{} {}", h.month, h.day, h.name);
}
}
$ cargo run -q
{"DefenseTax":0,"IncomeTax":572500,"Payable":584500,"ReconstructionTax":12022,"Total":584522}
1/1 元日
1/11 成人の日
2/11 建国記念の日
invoke takes a CLI subcommand and its parameters as they are, and returns the same JSON that the CLI prints.
For common calculations such as holidays and income tax, I also added functions that take and return Rust types.
The crate builds with cargo alone, without Lean installed.
How it works
The input to the translation is a single Lean module that holds only the functions to expose to Rust, and lean-rs turns this module into Rust code together with the lean-ritsuryo functions it calls.
The lean-ritsuryo CLI keeps the parts that handle IO, such as files and standard output, apart from the calculations, and the calculations are functions without IO, so Rust and the browser can call them as they are.
The web page compiles this crate to WebAssembly and calls it from a static page on GitHub Pages. The lean-rs runtime also runs on WebAssembly, where operations that use IO, such as file access, return an error, but the lean-ritsuryo calculations use no IO and run unchanged.
Generating the Rust code builds the Lean package, including the lean-ritsuryo proofs, so only calculations whose proofs pass become Rust code. The proofs cover the Lean definitions only, though, and whether the Rust code computes the same thing depends on the lean-rs translation being correct.
