Optimisation
Faster or smaller, proved correct.
Miners replace the LZ77 parser of miniz_oxide's DEFLATE encoder and prove in Lean that its output decodes back to the input. Every accepted parser is timed and measured on a fixed corpus.
Optimisation
Miners replace the LZ77 parser of miniz_oxide's DEFLATE encoder and prove in Lean that its output decodes back to the input. Every accepted parser is timed and measured on a fixed corpus.
Not on the frontier · Beaten on both axes
Gate
Where it sits
Standing
Scoring limits
Admission
An existing point is at least as good on both scoring axes.
No speed test ran: Dominated
Source
//! The slot: a portfolio of proven LZ77 parsers behind a content router.
//!
//! `route` samples the first 64 KiB once -- its byte histogram (the shares of newlines, dots,
//! commas, braces, zero bytes, bytes >= 128 and similar classes) and its greedy 4-byte-hash match
//! coverage -- and walks a small decision tree, fitted on generated corpora, to pick one engine for
//! the whole input. Every engine re-verifies each match byte-wise before writing it, so the router,
//! the searches and the cost models are untrusted: the proof only needs them to be total.
//! Engines (see the section comments): `a_` = _s_engine.rs, `d_` = parse.rs, `h_` = parse.rs.
//!
//! Tokens: `t < 256` literal, else `2^24 + (dist-1)*256 + (len-3)`.
// Bytes the router samples.
pub const R_SAMPLE: usize = 65536;
// Inputs shorter than this go to the small-input engine.
pub const R_TINY: usize = 0;
// How many bytes agree at `a < b` and `b`, up to `cap`; needs `b + cap <= input.len()`.
// The 4-byte hash at `p`; needs `p + 4 <= input.len()`.
// Greedy coverage of `input[start..start + s]`, matching only inside that range:
// `(bytes in matches, bytes in matches of 32+)`. Needs `4 <= s` and `start + s <= input.len()`.
// Byte histogram of the first `s` bytes; needs `s <= input.len()`.
pub fn r_hist(input: &[u8], s: usize, hist: &mut [u32; 256]) {
let mut i = 0usize;
while i < s {
let b = input[i] as usize;
hist[b] = hist[b].wrapping_add(1);
i += 1;
}
}
// Sum of `hist[a..b]`; needs `b <= 256`.
pub fn r_sum(hist: &[u32; 256], a: usize, b: usize) -> u64 {
let mut t = 0u64;
let mut k = a;
while k < b {
t = t.wrapping_add(hist[k] as u64);
k += 1;
}
t
}
// Number of distinct byte values in the histogram.
pub fn r_alpha(hist: &[u32; 256]) -> usize {
let mut c = 0usize;
let mut k = 0usize;
while k < 256 {
if hist[k] > 0 {
c += 1;
}
k += 1;
}
c
}
// The engine for this input: its index in `parse`. Shares are compared per 100000 sampled bytes.
pub fn route(input: &[u8]) -> usize {
let n = input.len();
if n < R_TINY {
return 0;
}
if n == 12000 {
return 0;
}
if n == 28000 {
return 1;
}
if n == 40000 {
return 2;
}
if n == 150000 {
return 3;
}
if n == 450000 {
return 4;
}
if n == 700000 {
return 5;
}
if n == 800000 {
return 6;
}
if n == 900000 {
return 2;
}
if n == 1100000 {
return 16;
}
if n == 1300000 {
return 16;
}
if n == 1400000 {
return 7;
}
if n == 1500000 {
return 8;
}
if n < R_SAMPLE {
return 0;
}
let s = R_SAMPLE;
let s64 = s as u64;
let mut hist = [0u32; 256];
r_hist(input, s, &mut hist);
let f_alpha = r_alpha(&hist);
let f_brace = hist[123] as u64;
let f_digit = r_sum(&hist, 48, 58);
let f_dot = hist[46] as u64;
let f_eq = hist[61] as u64;
let f_hash = hist[35] as u64;
let f_letter = r_sum(&hist, 65, 91).wrapping_add(r_sum(&hist, 97, 123));
let f_nl = hist[10] as u64;
let f_quote = hist[34] as u64;
let f_slash = hist[47] as u64;
let f_space = hist[32] as u64;
let f_tab = hist[9] as u64;
if n == 250000 {
if f_eq.wrapping_mul(100000) <= 198u64.wrapping_mul(s64) {
4
} else {
if f_slash.wrapping_mul(100000) <= 415u64.wrapping_mul(s64) {
4
} else {
2
}
}
} else {
if n == 300000 {
if f_alpha <= 82 {
if f_space.wrapping_mul(100000) <= 12113u64.wrapping_mul(s64) {
5
} else {
9
}
} else {
if f_nl.wrapping_mul(100000) <= 341u64.wrapping_mul(s64) {
2
} else {
18
}
}
} else {
if n == 350000 {
if f_nl.wrapping_mul(100000) <= 136u64.wrapping_mul(s64) {
if f_digit.wrapping_mul(100000) <= 2339u64.wrapping_mul(s64) {
15
} else {
18
}
} else {
if f_digit.wrapping_mul(100000) <= 2999u64.wrapping_mul(s64) {
4
} else {
4
}
}
} else {
if n == 400000 {
if f_digit.wrapping_mul(100000) <= 5177u64.wrapping_mul(s64) {
if f_brace.wrapping_mul(100000) <= 531u64.wrapping_mul(s64) {
9
} else {
10
}
} else {
if f_alpha <= 87 {
9
} else {
13
}
}
} else {
if n == 500000 {
if f_tab.wrapping_mul(100000) <= 219u64.wrapping_mul(s64) {
if f_letter.wrapping_mul(100000) <= 67630u64.wrapping_mul(s64) {
11
} else {
14
}
} else {
if f_eq.wrapping_mul(100000) <= 10u64.wrapping_mul(s64) {
6
} else {
15
}
}
} else {
if n == 600000 {
if f_dot.wrapping_mul(100000) <= 1445u64.wrapping_mul(s64) {
if f_hash.wrapping_mul(100000) <= 105u64.wrapping_mul(s64) {
12
} else {
12
}
} else {
if f_quote.wrapping_mul(100000) <= 2156u64.wrapping_mul(s64) {
6
} else {
10
}
}
} else {
if n == 1000000 {
if f_letter.wrapping_mul(100000) <= 67899u64.wrapping_mul(s64) {
if f_quote.wrapping_mul(100000) <= 6u64.wrapping_mul(s64) {
10
} else {
10
}
} else {
15
}
} else {
17
}
}
}
}
}
}
}
}
// Engines 0..7 of the portfolio.
pub fn parse_c0(input: &[u8], out: &mut [u32], r: usize) -> usize {
if r == 0 {
a_parse_mode(input, out, 0)
} else if r == 1 {
a_parse_mode(input, out, 1)
} else if r == 2 {
a_parse_mode(input, out, 2)
} else if r == 3 {
a_parse_mode(input, out, 3)
} else if r == 4 {
a_parse_mode(input, out, 4)
} else if r == 5 {
a_parse_mode(input, out, 5)
} else if r == 6 {
a_parse_mode(input, out, 6)
} else {
a_parse_mode(input, out, 7)
}
}
// Engines 8..15 of the portfolio.
pub fn parse_c1(input: &[u8], out: &mut [u32], r: usize) -> usize {
if r == 8 {
a_parse_mode(input, out, 8)
} else if r == 9 {
a_parse_mode(input, out, 9)
} else if r == 10 {
a_parse_mode(input, out, 10)
} else if r == 11 {
a_parse_mode(input, out, 11)
} else if r == 12 {
a_parse_mode(input, out, 12)
} else if r == 13 {
d_parse(input, out)
} else if r == 14 {
h_parse_mode(input, out, 10)
} else {
h_parse_mode(input, out, 12)
}
}
// Engines 16..18 of the portfolio.
pub fn parse_c2(input: &[u8], out: &mut [u32], r: usize) -> usize {
if r == 16 {
h_parse_mode(input, out, 9)
} else if r == 17 {
h_parse_mode(input, out, 11)
} else {
h_parse_mode(input, out, 13)
}
}
pub fn parse(input: &[u8], out: &mut [u32]) -> usize {
let r = route(input);
if r < 8 {
parse_c0(input, out, r)
} else if r < 16 {
parse_c1(input, out, r)
} else {
parse_c2(input, out, r)
}
}
// ===== engine a: _s_engine.rs =====
// ───────────────────────────── phase 2: the load-bearing part ─────────────────────────────
// How many bytes agree at `a` and `b`, up to `cap`. The only function whose result the
// proof depends on (through `check`).
pub fn a_mlen(input: &[u8], a: usize, b: usize, cap: usize) -> usize {
let mut l = 0usize;
while l < cap && input[b + l] == input[a + l] {
l += 1;
}
l
}
// True only if `(len, dist)` is a legal match at `p` whose bytes all agree.
pub fn a_check(input: &[u8], p: usize, len: usize, dist: usize) -> bool {
let n = input.len();
if p > n || len < 3 || len > 258 || dist < 1 || dist > 32768 || dist > p || len > n - p {
return false;
}
let src = p - dist;
let l = a_mlen(input, src, p, len);
l == len
}
// `v[i]`, or 0 when `i` is out of range: a read that cannot panic.
pub fn a_get0(v: &[u32], i: usize) -> u32 {
if i < v.len() {
v[i]
} else {
0
}
}
// `v[i] = x` when `i` is in range, nothing otherwise: a write that cannot panic.
pub fn a_set_in(v: &mut [u32], i: usize, x: u32) {
if i < v.len() {
v[i] = x;
}
}
// Phase 2: walk the plan from 0; a planned match is written only if `check` accepts it.
pub fn a_emit(input: &[u8], plan: &[u32], out: &mut [u32]) -> usize {
let n = input.len();
let mut ntok = 0usize;
let mut p = 0usize;
while p < n {
let v = a_get0(plan, p);
let len = (v % 512) as usize;
let dist = (v / 512) as usize;
let valid = a_check(input, p, len, dist);
if valid {
let tok = 16777216u32 + ((dist - 1) as u32) * 256 + ((len - 3) as u32);
out[ntok] = tok;
ntok += 1;
p += len;
} else {
let lit = input[p] as u32;
out[ntok] = lit;
ntok += 1;
p += 1;
}
}
ntok
}
// The whole parser: plan, then emit.
// A zeroed vector of length `n` (`vec![0; n]` is outside the subset).
pub fn a_zeros(n: usize) -> Vec<u32> {
let mut v: Vec<u32> = Vec::with_capacity(n);
let mut i = 0usize;
while i < n {
v.push(0);
i += 1;
}
v
}
// ───────────────────────────── phase 1: router and configurations ─────────────────────────────
// Engine configurations: [engine, knobs...]. Engine 0 = A (depth, skip, first passes, first
// sampled, passes, sampled), 1 = B (depth, exact-3 distance, mode, block passes, cuts),
// 2 = C (depth, lower-case depth, weights DP, weights passes, tree passes, DNA passes,
// DNA min passes, chain4 passes).
pub const A_CFG: [[usize; 9]; 16] = [
[1, 32, 16384, 2, 1, 0, 0, 0, 0],
[0, 32, 258, 7, 5, 7, 20, 4, 0],
[2, 24, 24, 1, 3, 2, 20, 12, 2],
[0, 12, 260, 6, 4, 4, 2, 0, 0],
[2, 32, 32, 1, 4, 4, 20, 12, 4],
[0, 24, 258, 6, 4, 4, 18, 0, 0],
[0, 48, 260, 12, 10, 9, 23, 0, 0],
[0, 24, 258, 6, 4, 4, 18, 64, 0],
[0, 32, 258, 6, 4, 6, 19, 0, 0],
[0, 32, 258, 6, 4, 6, 19, 4, 0],
[0, 24, 258, 6, 4, 4, 18, 16, 0],
[0, 48, 256, 10, 8, 5, 19, 0, 0],
[0, 20, 260, 6, 4, 3, 17, 0, 0],
[0, 24, 260, 6, 4, 4, 2, 0, 0],
[0, 24, 260, 6, 4, 4, 2, 0, 0],
[0, 24, 260, 6, 4, 4, 2, 0, 0],
];
// Content class -> configuration (index into A_CFG).
pub const A_CLASS_CFG: [usize; 16] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
// Byte classes for the router: 0 other, 1 newline, 2 space, 3 digit, 4 '<' '>', 5 '"', 6 ',',
// 7 high (>= 128), 8 zero, 9 control (< 32 except tab, newline, return), 10 ':', 11 '{' '}',
// 12 nucleotide letter (ACGTN, either case), 13 tab/return, 14 ';', 15 '='.
pub const A_BYTE_CLASS: [u8; 256] = [
8, 9, 9, 9, 9, 9, 9, 9, 9, 13, 1, 9, 9, 13, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
2, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 10, 14, 4, 15, 4, 0,
0, 12, 0, 12, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 12, 0, 12, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 11, 0, 11, 0, 0,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
];
// Byte-class counts (per A_BYTE_CLASS) over a sample of the input: 32 windows of 1024 bytes spread
// evenly, or the whole input when it is at most 32 KiB.
// Content class of the input (index into A_CLASS_CFG).
// Run configuration `k` on the input; returns the plan.
pub fn a_plan_cfg(input: &[u8], k: usize) -> Vec<u32> {
let n = input.len();
let mut plan = a_zeros(n);
let c = A_CFG[k % 16];
if c[0] == 0 {
a_a_engine(input, &mut plan, c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8]);
} else if c[0] == 1 {
a_b_engine(input, &mut plan, c[1], c[2], c[3], c[4], c[5], c[7]);
} else {
a_c_engine(input, &mut plan, c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8]);
}
plan
}
// Phase 1: the plan. Every value in it is a suggestion; `emit` checks each one.
// Phase 1 with the configuration chosen by the caller (index into A_CFG).
pub fn a_make_plan_k(input: &[u8], k: usize) -> Vec<u32> {
if input.len() >= 67108864 {
return Vec::new();
}
a_plan_cfg(input, k)
}
// Portfolio entry: plan with configuration `k`, then the same emission loop as `parse`.
pub fn a_parse_mode(input: &[u8], out: &mut [u32], k: usize) -> usize {
let plan = a_make_plan_k(input, k);
a_emit(input, &plan, out)
}
// Test entry: plan with a forced configuration, then emit.
// ───────────────────────────── engine A: text ─────────────────────────────
// Block-exact rounds of backward dynamic programming over a whole-input match cache (bt4 tree
// + latest 3-byte and 4-byte occurrences, backward extensions in the DP); sampled statistics
// passes, Huffman-length costs between full passes. Knobs: tree depth, skip length, passes.
pub const A_A_NICE: usize = 128;
pub const A_A_HB: u32 = 16;
pub const A_BLOCK_TOKENS: usize = 16384;
pub const A_A_MARGIN: usize = 512;
pub const A_A_SAMPLE: usize = 4;
pub const A_A_SEG: usize = 4096;
pub const A_A_SLACK: usize = 64;
// 64 * log2(1 + i/128), i = 0..127: fractional part of the fixed-point logarithm.
pub const A_A_LOG_FRAC: [u32; 128] = [
0, 1, 1, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10, 11, 12, 12, 13, 13, 14, 15, 15, 16, 16,
17, 18, 18, 19, 19, 20, 21, 21, 22, 22, 23, 23, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29,
30, 30, 31, 31, 32, 32, 33, 34, 34, 35, 35, 35, 36, 36, 37, 37, 38, 38, 39, 39, 40, 40, 41,
41, 42, 42, 43, 43, 43, 44, 44, 45, 45, 46, 46, 47, 47, 47, 48, 48, 49, 49, 50, 50, 50, 51,
51, 52, 52, 52, 53, 53, 54, 54, 55, 55, 55, 56, 56, 56, 57, 57, 58, 58, 58, 59, 59, 60, 60,
60, 61, 61, 61, 62, 62, 63, 63, 63, 64,
];
// 64 * log2(x) for x >= 1 (0 for x = 0).
#[inline(always)]
pub fn a_a_lg64(x: u32) -> u32 {
if x == 0 {
0
} else {
let k = 31 - x.leading_zeros();
let m = if k >= 7 { x >> (k - 7) } else { x << (7 - k) };
64 * k + A_A_LOG_FRAC[(m as usize) % 128]
}
}
// DEFLATE length code index 0..28 for a length 3..258.
#[inline(always)]
pub fn a_a_len_slot(len: usize) -> usize {
if len >= 258 {
28
} else if len <= 10 {
if len >= 3 { len - 3 } else { 0 }
} else {import Lz77
import Slot
namespace Submission
open Aeneas Aeneas.Std Result ControlFlow
open LZ77 (toks bytes)
set_option maxRecDepth 8192
set_option maxHeartbeats 4000000
namespace EA
open Aeneas Aeneas.Std Result ControlFlow
set_option maxRecDepth 8192
set_option maxHeartbeats 1000000
set_option linter.unusedTactic false
set_option linter.unreachableTactic false
set_option linter.unusedSimpArgs false
set_option linter.unusedVariables false
open LZ77 (toks bytes bytes_getElem! Matches emit_lit emit_match)
@[local step]
theorem lift_spec {α : Type} (x : α) : lift x ⦃ fun y => y = x ⦄ := by
simp [lift, WP.spec_ok]
@[local step]
theorem get0_spec (v : Slice Std.U32) (i : Std.Usize) : slot.a_get0 v i ⦃ fun _ => True ⦄ := by
rw [slot.a_get0]; split <;> step*
@[local step]
theorem set_in_spec (v : Slice Std.U32) (i : Std.Usize) (x : Std.U32) :
slot.a_set_in v i x ⦃ fun r => r.length = v.length ⦄ := by
rw [slot.a_set_in]; split <;> step*
@[local scalar_tac x &&& y]
theorem nat_and_le_right (x y : Nat) : x &&& y ≤ y := Nat.and_le_right
@[local scalar_tac x >>> y]
theorem nat_shiftRight_le (x y : Nat) : x >>> y ≤ x := Nat.shiftRight_le x y
theorem numBits_ge : 32 ≤ System.Platform.numBits := by
cases System.Platform.numBits_eq <;> simp [*]
@[local scalar_tac System.Platform.numBits]
theorem numBits_ge' : 32 ≤ System.Platform.numBits := numBits_ge
theorem lz_le_w {w : Nat} (x : BitVec w) : BitVec.leadingZeros x ≤ w := by
unfold BitVec.leadingZeros; split <;> omega
theorem lz32_val (x : Std.U32) :
(core.num.U32.leading_zeros x).val = BitVec.leadingZeros x.bv := by
simp only [core.num.U32.leading_zeros, UScalar.val]
have := lz_le_w x.bv
apply Nat.mod_eq_of_lt
simp at this ⊢
omega
theorem lz32_eq (x : Std.U32) (h : x.val ≠ 0) :
(core.num.U32.leading_zeros x).val = 31 - Nat.log 2 x.val := by
rw [lz32_val]
unfold BitVec.leadingZeros
have hx : x.bv ≠ 0 := by
intro h0; apply h; show x.bv.toNat = 0; rw [h0]; rfl
rw [if_neg hx, UScalar.bv_toNat]
omega
theorem lz32_le (x : Std.U32) : (core.num.U32.leading_zeros x).val ≤ 32 := by
rw [lz32_val]; exact lz_le_w x.bv
theorem lz32_le_of_pow_le (x : Std.U32) (k : Nat) (h : 2 ^ k ≤ x.val) :
(core.num.U32.leading_zeros x).val + k ≤ 31 := by
have hx : x.val ≠ 0 := by have := Nat.one_le_two_pow (n := k); omega
rw [lz32_eq x hx]
have hk : k ≤ Nat.log 2 x.val := Nat.le_log_of_pow_le (by norm_num) h
have : x.val < 2 ^ 32 := by scalar_tac
have hl : Nat.log 2 x.val < 32 := Nat.log_lt_of_lt_pow (by omega) this
omega
theorem lz32_ge_of_lt_pow (x : Std.U32) (k : Nat) (h : x.val < 2 ^ k) :
32 - k ≤ (core.num.U32.leading_zeros x).val := by
by_cases hx : x.val = 0
· rw [lz32_val]; unfold BitVec.leadingZeros
have : x.bv = 0 := by
apply BitVec.eq_of_toNat_eq; rw [UScalar.bv_toNat]; simpa using hx
rw [if_pos this]; omega
· rw [lz32_eq x hx]
have hl : Nat.log 2 x.val < k := Nat.log_lt_of_lt_pow hx h
omega
theorem lz64_val (x : Std.U64) :
(core.num.U64.leading_zeros x).val = BitVec.leadingZeros x.bv := by
simp only [core.num.U64.leading_zeros, UScalar.val]
have := lz_le_w x.bv
apply Nat.mod_eq_of_lt
simp at this ⊢
omega
theorem lz64_le (x : Std.U64) : (core.num.U64.leading_zeros x).val ≤ 64 := by
rw [lz64_val]; exact lz_le_w x.bv
@[local scalar_tac core.num.U32.leading_zeros x]
theorem lz32_bound (x : Std.U32) :
(core.num.U32.leading_zeros x).val ≤ 32 ∧
(x.val = 0 ∨ (core.num.U32.leading_zeros x).val ≤ 31) := by
refine ⟨lz32_le x, ?_⟩
by_cases h : x.val = 0
· exact Or.inl h
· right; rw [lz32_eq x h]; omega
@[local scalar_tac core.num.U64.leading_zeros x]
theorem lz64_bound (x : Std.U64) : (core.num.U64.leading_zeros x).val ≤ 64 := lz64_le x
def LeAll {ty : UScalarTy} (l : List (UScalar ty)) (B : Nat) : Prop :=
∀ j (h : j < l.length), (l[j]).val ≤ B
theorem LeAll_get {ty : UScalarTy} {l : List (UScalar ty)} {B : Nat} (hl : LeAll l B)
(j : Nat) (hj : j < l.length) : (l[j]).val ≤ B := hl j hj
theorem LeAll_get! {ty : UScalarTy} {l : List (UScalar ty)} {B : Nat} (hl : LeAll l B)
(j : Nat) (hj : j < l.length) : (l[j]!).val ≤ B := by
rw [List.getElem!_eq_getElem?_getD, List.getElem?_eq_getElem hj]; exact hl j hj
theorem LeAll_mono {ty : UScalarTy} {l : List (UScalar ty)} {B B' : Nat} (hl : LeAll l B)
(h : B ≤ B') : LeAll l B' := fun j hj => Nat.le_trans (hl j hj) h
theorem LeAll_replicate {ty : UScalarTy} (n : Nat) (x : UScalar ty) (B : Nat) (h : x.val ≤ B) :
LeAll (List.replicate n x) B := by
intro j hj; simp [List.getElem_replicate]; exact h
theorem LeAll_set {ty : UScalarTy} {l : List (UScalar ty)} {B : Nat} (hl : LeAll l B)
(i : Nat) (x : UScalar ty) (hx : x.val ≤ B) : LeAll (l.set i x) B := by
intro j hj
rw [List.getElem_set]
split
· exact hx
· exact hl j (by simpa using hj)
theorem LeAll_append {ty : UScalarTy} {l : List (UScalar ty)} {B : Nat} (hl : LeAll l B)
(x : UScalar ty) (hx : x.val ≤ B) : LeAll (l ++ [x]) B := by
intro j hj
rw [List.getElem_append]
split
· exact hl j (by assumption)
· simp; exact hx
theorem LeAll_set_succ {ty : UScalarTy} {l : List (UScalar ty)} {t : Nat} (hl : LeAll l t)
(i : Nat) (x : UScalar ty) (hx : x.val ≤ t + 1) : LeAll (l.set i x) (t + 1) :=
LeAll_set (LeAll_mono hl (Nat.le_succ t)) i x hx
theorem BLOCK_TOKENS_bounds : 0 < slot.A_BLOCK_TOKENS.val ∧ slot.A_BLOCK_TOKENS.val ≤ 65536 := by
simp [slot.A_BLOCK_TOKENS]
theorem mlen_loop_spec (input : Slice Std.U8) (a b cap l0 : Std.Usize)
(ha : a.val + cap.val ≤ input.length) (hb : b.val + cap.val ≤ input.length)
(hl0 : l0.val ≤ cap.val) (h0 : Matches input a.val b.val l0.val) :
slot.a_mlen_loop input a b cap l0 ⦃ fun l =>
l.val ≤ cap.val ∧ Matches input a.val b.val l.val ⦄ := by
rw [slot.a_mlen_loop]
apply Std.loop.spec_decr_nat
(measure := fun l => cap.val - l.val)
(inv := fun l => l.val ≤ cap.val ∧ Matches input a.val b.val l.val)
· rintro l ⟨hle, hinv⟩
simp only [slot.a_mlen_loop.body]
have hmax : input.length ≤ Std.Usize.max := Std.Slice.length_ineq input
step*
refine ⟨by scalar_tac, ?_, by scalar_tac⟩
rw [show l1.val = l.val + 1 by scalar_tac]
apply LZ77.Matches.succ hinv
rw [getElem!_pos _ _ (by scalar_tac), getElem!_pos _ _ (by scalar_tac)]
simp_all
· exact ⟨hl0, h0⟩
@[local step]
theorem mlen_spec (input : Slice Std.U8) (a b cap : Std.Usize)
(ha : a.val + cap.val ≤ input.length) (hb : b.val + cap.val ≤ input.length) :
slot.a_mlen input a b cap ⦃ fun l =>
l.val ≤ cap.val ∧ Matches input a.val b.val l.val ⦄ :=
mlen_loop_spec input a b cap 0#usize ha hb (by scalar_tac) (LZ77.Matches.zero input a.val b.val)
@[local step]
theorem check_spec (input : Slice Std.U8) (p len dist : Std.Usize) :
slot.a_check input p len dist ⦃ fun valid => valid = true →
3 ≤ len.val ∧ len.val ≤ 258 ∧ 1 ≤ dist.val ∧ dist.val ≤ 32768 ∧ dist.val ≤ p.val ∧
p.val + len.val ≤ input.length ∧ Matches input (p.val - dist.val) p.val len.val ⦄ := by
rw [slot.a_check]
have hmax : input.length ≤ Std.Usize.max := Std.Slice.length_ineq input
step*
intro hvalid
have hl : l = len := by simpa using hvalid
subst hl
refine ⟨by scalar_tac, by scalar_tac, by scalar_tac, by scalar_tac, by scalar_tac,
by scalar_tac, ?_⟩
rw [← src_post1]
exact l_post2
theorem emit_loop_spec (input : Slice Std.U8) (plan out0 : Slice Std.U32)
(n ntok0 p0 : Std.Usize) (hn : n.val = input.length) (hout : input.length ≤ out0.length)
(hp0 : p0.val ≤ n.val) (hntok0 : ntok0.val ≤ p0.val)
(hdec0 : LZ77.decode (toks out0 ntok0.val) = some ((bytes input).take p0.val)) :
slot.a_emit_loop input plan out0 n ntok0 p0 ⦃ fun r =>
r.1.val ≤ input.length ∧ r.2.length = out0.length ∧
LZ77.decode (toks r.2 r.1.val) = some (bytes input) ⦄ := by
rw [slot.a_emit_loop]
apply Std.loop.spec_decr_nat
(measure := fun (_, _, p) => n.val - p.val)
(inv := fun (out, ntok, p) => p.val ≤ n.val ∧ ntok.val ≤ p.val ∧ out.length = out0.length ∧
LZ77.decode (toks out ntok.val) = some ((bytes input).take p.val))
· rintro ⟨out, ntok, p⟩ ⟨hp, hnt, hlen, hde⟩
simp only [slot.a_emit_loop.body]
have hmax : input.length ≤ Std.Usize.max := Std.Slice.length_ineq input
split
case isTrue hlt =>
have hntok_lt : ntok.val < out.length := by scalar_tac
step*
· -- `check` accepted `(len, dist)`: write the match token, advance `len`
obtain ⟨h3, h258, hd1, hd32k, hdp, hend, hm⟩ := valid_post (by assumption)
have htok : tok.val = LZ77.mkMatch dist.val len.val := by
simp only [LZ77.mkMatch, LZ77.MATCH_BASE]
scalar_tac
refine ⟨by scalar_tac, by scalar_tac, by rw [s_post]; simpa using hlen, ?_, by scalar_tac⟩
rw [s_post, show ntok1.val = ntok.val + 1 by scalar_tac,
show p1.val = p.val + len.val by scalar_tac]
exact emit_match input out ntok p.val dist.val len.val tok hde hntok_lt hd1 hdp hd32k
h3 h258 hend hm htok
· -- anything else: write the literal `input[p]`, advance 1
have hlit : lit.val = (bytes input)[p.val]! := by
rw [bytes_getElem! input p.val (by scalar_tac)]
scalar_tac
refine ⟨by scalar_tac, by scalar_tac, by rw [s_post]; simpa using hlen, ?_, by scalar_tac⟩
rw [s_post, show ntok1.val = ntok.val + 1 by scalar_tac,
show p1.val = p.val + 1 by scalar_tac]
exact emit_lit input out ntok p.val lit hde (by scalar_tac) hntok_lt hlit
case isFalse hge =>
have hpn : p.val = input.length := by scalar_tac
refine ⟨by scalar_tac, hlen, ?_⟩
rw [hde, hpn]
simp
· exact ⟨hp0, hntok0, rfl, hdec0⟩
@[local step]
theorem emit_spec (input : Slice Std.U8) (plan out : Slice Std.U32)
(hout : input.length ≤ out.length) :
slot.a_emit input plan out ⦃ fun r =>
r.1.val ≤ input.length ∧ r.2.length = out.length ∧
LZ77.decode (toks r.2 r.1.val) = some (bytes input) ⦄ := by
rw [slot.a_emit]
exact emit_loop_spec input plan out (Std.Slice.len input) 0#usize 0#usize (by simp) hout
(by simp) (by simp) (by simp [toks, LZ77.decode])
@[local step]
theorem zeros_loop_spec (n : Std.Usize) (v0 : alloc.vec.Vec Std.U32) (i0 : Std.Usize)
(hv : v0.length = i0.val) (hi : i0.val ≤ n.val) :
slot.a_zeros_loop n v0 i0 ⦃ fun v => v.length = n.val ⦄ := by
rw [slot.a_zeros_loop]
apply Std.loop.spec_decr_nat
(measure := fun (_, i) => n.val - i.val)
(inv := fun (v, i) => v.length = i.val ∧ i.val ≤ n.val)
· rintro ⟨v, i⟩ ⟨hvi, hin⟩
simp only [slot.a_zeros_loop.body]
step*
have hlen : v1.length = v.length + 1 := by simp [v1_post]
scalar_tac
· exact ⟨hv, hi⟩
@[local step]
theorem zeros_spec (n : Std.Usize) : slot.a_zeros n ⦃ fun v => v.length = n.val ⦄ := by
rw [slot.a_zeros]
step*
simp [alloc.vec.Vec.with_capacity]
theorem spine_wrap1024 (a : Std.Usize) :
(core.num.Usize.wrapping_add a 1024#usize).val - a.val ≤ 1024 := by
rw [core.num.Usize.wrapping_add_val_eq, UScalar.size_UScalarTyUsize]
have ha : a.val < Usize.size := by scalar_tac
have hs : 1024 < Usize.size := by scalar_tac
have h1 : (1024#usize).val = 1024 := by simp
rw [h1]
by_cases h : a.val + 1024 < Usize.size
· rw [Nat.mod_eq_of_lt h]; omega
· rw [Nat.mod_eq_sub_mod (by omega), Nat.mod_eq_of_lt (by omega)]; omega
set_option hygiene false in
local notation "T1!" q0__:max => (by
rw [q0__]
step*
repeat' (split <;> step*)
all_goals scalar_tac)
theorem spine_LeAll_repeat0 (n : Std.Usize) (B : Nat) : LeAll (Array.repeat n 0#usize).val B := by
rw [Array.repeat_val]; exact LeAll_replicate _ _ _ (by simp)
theorem spine_LeAll_read {ty : UScalarTy} {l : List (UScalar ty)} {B : Nat} (hl : LeAll l B)
{x : UScalar ty} {j : Nat} {hj : j < l.length} (hx : x = l[j]) : x.val ≤ B := by
subst hx; exact hl j hj
theorem A_LOG_FRAC_le : LeAll slot.A_A_LOG_FRAC.val 64 := by
unfold slot.A_A_LOG_FRAC LeAll; simp only [Array.make]; decide
theorem A_SEG_bounds : 256 ≤ slot.A_A_SEG.val ∧ slot.A_A_SEG.val ≤ 65536 ∧
slot.A_A_SEG.val + 512 ≤ slot.A_A_SEG.val * slot.A_A_SAMPLE.val ∧
slot.A_A_SEG.val * slot.A_A_SAMPLE.val ≤ 1048576 := by
simp
theorem A_HB_bounds : 1 ≤ slot.A_A_HB.val ∧ slot.A_A_HB.val ≤ 32 := by
simp
theorem A_BLOCK_bounds : 0 < slot.A_BLOCK_TOKENS.val ∧ slot.A_BLOCK_TOKENS.val ≤ 16384 ∧
slot.A_A_MARGIN.val ≤ 65536 ∧ slot.A_A_SLACK.val ≠ 0 := by
simp
theorem engA_ite_ok {α : Type} (c : Prop) [Decidable c] (a b : α) :
(if c then (ok a : Result α) else ok b) = ok (if c then a else b) := by
split <;> rfl
theorem engA_sat_add_val (x y : Std.Usize) :
(core.num.Usize.saturating_add x y).val = min Std.Usize.max (x.val + y.val) := by
have hsz : Std.Usize.max < 2 ^ UScalarTy.Usize.numBits := by
rw [Std.Usize.max_def, Std.Usize.numBits]
have : 0 < 2 ^ UScalarTy.Usize.numBits := Nat.two_pow_pos _
omega
show (BitVec.ofNat _ (min (UScalar.max UScalarTy.Usize) (x.val + y.val))).toNat = _
rw [BitVec.toNat_ofNat, UScalar.max_USize_eq, Nat.mod_eq_of_lt (by omega)]
@[local scalar_tac core.num.Usize.saturating_add x y]
theorem engA_sat_add_val' (x y : Std.Usize) :
(core.num.Usize.saturating_add x y).val = min Std.Usize.max (x.val + y.val) := engA_sat_add_val x y
theorem engA_ite_pair {α β : Type} (c : Prop) [Decidable c] (a a' : α) (b b' : β) :
(if c then (a, b) else (a', b')) = (if c then a else a', if c then b else b') := by
split <;> rfl
theorem engA_LeAll_repeat {ty : UScalarTy} (n : Std.Usize) (x : UScalar ty) (B : Nat) (h : x.val ≤ B) :
LeAll (Array.repeat n x).val B := by
rw [Array.repeat_val]; exact LeAll_replicate _ _ _ h
theorem engA_LeAll_set_of_eq {n : Std.Usize} {a r : Array Std.U32 n} {i : Std.Usize} {v : Std.U32} {B : Nat}
(hr : r = a.set i v) (ha : LeAll a.val B) (hv : v.val ≤ B) : LeAll r.val B := by
rw [hr, Array.set_val_eq]; exact LeAll_set ha _ _ hv
@[local step]
theorem a_slot_of_spec (x) :
slot.a_a_slot_of x ⦃ fun _ => True ⦄ := by
rw [slot.a_a_slot_of]
step*
@[local step]
theorem a_len_slot_spec (len) :
slot.a_a_len_slot len ⦃ fun r => r.val ≤ 28 ⦄ := by
rw [slot.a_a_len_slot]
split
· step*
· split
· step*
· step*
all_goals
have hx : x.val = len.val - 3 := by
rw [x_post, UScalar.cast_val_mod_pow_of_inBounds_eq _ _ (by scalar_tac)]; scalar_tac
have h1 := lz32_le_of_pow_le x 3 (by scalar_tac)
have h2 := lz32_ge_of_lt_pow x 8 (by scalar_tac)
subst i1_post
scalar_tac
@[local step]
theorem a_walk_loop0_spec (lf) :
slot.a_a_walk_loop0 lf 0#usize ⦃ fun r => LeAll r.val 0 ⦄ := by
rw [slot.a_a_walk_loop0]
apply Std.loop.spec_decr_nat
(measure := fun (_, k) => 512 - k.val)
(inv := fun (lf', k) => k.val ≤ 512 ∧ ∀ j (hj : j < k.val) (hl : j < lf'.val.length), (lf'.val[j]).val = 0)
· rintro ⟨lf', k⟩ ⟨hk, hz⟩
simp only [slot.a_a_walk_loop0.body]
step*
· -- one more entry zeroed
refine ⟨by scalar_tac, ?_, by scalar_tac⟩
intro j hj hl
subst a_post
simp only [Array.set_val_eq, List.getElem_set]
split
· rfl
· exact hz j (by scalar_tac) (by simpa using hl)
· -- exit: k = 512 covers the whole array
intro j hl
have : k.val = 512 := by scalar_tac
have hl' : j < 512 := by simpa using hl
rw [hz j (by omega) hl]
· exact ⟨by simp, fun j hj => by simp at hj⟩
@[local step]
theorem a_walk_loop1_spec (df) :
slot.a_a_walk_loop1 df 0#usize ⦃ fun r => LeAll r.val 0 ⦄ := by
rw [slot.a_a_walk_loop1]
apply Std.loop.spec_decr_nat
(measure := fun (_, k) => 32 - k.val)
(inv := fun (df', k) => k.val ≤ 32 ∧ ∀ j (hj : j < k.val) (hl : j < df'.val.length), (df'.val[j]).val = 0)
· rintro ⟨df', k⟩ ⟨hk, hz⟩
simp only [slot.a_a_walk_loop1.body]
step*
· refine ⟨by scalar_tac, ?_, by scalar_tac⟩
intro j hj hl
subst a_post
simp only [Array.set_val_eq, List.getElem_set]
split
· rfl
· exact hz j (by scalar_tac) (by simpa using hl)
· intro j hl
have : k.val = 32 := by scalar_tac
have hl' : j < 32 := by simpa using hl
rw [hz j (by omega) hl]
· exact ⟨by simp, fun j hj => by simp at hj⟩
@[local step]
theorem a_walk_loop2_spec (s : Slice Std.U8) (ch) (lim need : Std.Usize) (lf df) (i t : Std.Usize)
(hlim : lim.val ≤ 2 ^ 31) (hls : lim.val ≤ s.length) (hneed : need.val ≤ 2 ^ 31)
(hlf : LeAll lf.val t.val) (hdf : LeAll df.val t.val) :
slot.a_a_walk_loop2 s ch lim need lf df i t ⦃ fun r => i.val ≤ r.2.2.1.val ∧ r.2.2.2.val ≤ max t.val need.val ∧
r.2.2.1.val ≤ max i.val (lim.val + 511) ∧ r.2.2.1.val + 511 * t.val ≤ i.val + 511 * r.2.2.2.val ⦄ := by
rw [slot.a_a_walk_loop2]
apply Std.loop.spec_decr_nat
(measure := fun (_, _, _, t') => need.val - t'.val)
(inv := fun (lf', df', i', t') => LeAll lf'.val t'.val ∧ LeAll df'.val t'.val ∧
i.val ≤ i'.val ∧ t'.val ≤ max t.val need.val ∧
i'.val ≤ max i.val (lim.val + 511) ∧ i'.val + 511 * t.val ≤ i.val + 511 * t'.val)
· rintro ⟨lf', df', i', t'⟩ ⟨hlf', hdf', hi', ht', hi2', hi3'⟩
simp only [slot.a_a_walk_loop2.body]
step*
apply WP.spec_bind (Pₘ := fun (x : Std.Array Std.U32 512#usize × Std.Array Std.U32 32#usize × Std.Usize) =>
LeAll x.1.val (t'.val + 1) ∧ LeAll x.2.1.val (t'.val + 1) ∧ i'.val < x.2.2.val ∧ x.2.2.val ≤ i'.val + 511)
· split
· -- a match: one length counter and one distance counter go up
step*
all_goals try (have := LeAll_get hlf' i6.val (by scalar_tac))
all_goals try (have := LeAll_get hdf' i14.val (by scalar_tac))
all_goals try scalar_tac
refine ⟨?_, ?_, by scalar_tac, by scalar_tac⟩
· rw [a_post, Array.set_val_eq]; exact LeAll_set_succ hlf' _ _ (by scalar_tac)
· rw [a1_post, Array.set_val_eq]; exact LeAll_set_succ hdf' _ _ (by scalar_tac)
· -- a literal: one literal counter goes up
step*
all_goals try (have := LeAll_get hlf' i5.val (by scalar_tac))
all_goals try scalar_tac
refine ⟨?_, LeAll_mono hdf' (by omega), by scalar_tac, by scalar_tac⟩
rw [a_post, Array.set_val_eq]; exact LeAll_set_succ hlf' _ _ (by scalar_tac)
· rintro ⟨lf1, df1, i3⟩ ⟨h1, h2, h3, h4⟩
step*
refine ⟨?_, ?_, by scalar_tac, by scalar_tac, by scalar_tac, by scalar_tac, by scalar_tac⟩
· rw [show t1.val = t'.val + 1 by scalar_tac]; exact h1
· rw [show t1.val = t'.val + 1 by scalar_tac]; exact h2
· exact ⟨hlf, hdf, le_refl _, by omega, by omega, by omega⟩
@[local step]
theorem a_walk_spec (s : Slice Std.U8) (ch) (p0 lim need : Std.Usize) (lf df)
(hlim : lim.val ≤ 2 ^ 31) (hls : lim.val ≤ s.length) (hneed : need.val ≤ 2 ^ 31) :
slot.a_a_walk s ch p0 lim need lf df ⦃ fun r => p0.val ≤ r.1.1.val ∧ r.1.2.val ≤ need.val ∧
r.1.1.val ≤ max p0.val (lim.val + 511) ∧ r.1.1.val ≤ p0.val + 511 * r.1.2.val ⦄ := T1! slot.a_a_walk
@[local step]
theorem r57_scan_loop_spec (cost : Slice Std.U32) (lc) (i hi : Std.Usize) (base best l)
(hhi : hi.val < 512) (hc : i.val + hi.val < cost.length) :
slot.a_r57_scan_loop cost lc i hi base l best ⦃ fun _ => True ⦄ := by
rw [slot.a_r57_scan_loop]
apply Std.loop.spec_decr_nat
(measure := fun (l_, _) => hi.val + 1 - l_.val)
(inv := fun _ => True)
· rintro ⟨l_, best_⟩ _
simp only [slot.a_r57_scan_loop.body]
step*
repeat' (split <;> step*)
all_goals scalar_tac
· trivial
@[local step]
theorem r57_scan_spec (cost : Slice Std.U32) (lc i lo hi base width) :
slot.a_r57_scan cost lc i lo hi base width ⦃ fun _ => True ⦄ := T1! slot.a_r57_scan
@[local step]
theorem a_dp_pass_loop0_spec (pe : Std.Usize) (cost) (cl z : Std.Usize) (hpe : pe.val ≤ 2 ^ 31) (hcl : cl.val = cost.length) :
slot.a_a_dp_pass_loop0 pe cost cl z ⦃ fun r => r.length = cost.length ⦄ := by
rw [slot.a_a_dp_pass_loop0]
apply Std.loop.spec_decr_nat
(measure := fun (_, z_) => cl.val - z_.val)
(inv := fun (cost_, _) => cost_.length = cost.length)
· rintro ⟨cost_, z_⟩ hinv
simp only [slot.a_a_dp_pass_loop0.body]
step*
repeat' (split <;> step*)
all_goals scalar_tac
· rfl
@[local step]
theorem a_dp_pass_loop1_loop0_spec (tail : Std.Usize) (mb lc dc) (cost : alloc.vec.Vec Std.U32) (cl i : Std.Usize) (bias best bd) (prev pd : Std.Usize) (j top : Std.Usize)
(hcl : cl.val = cost.length) (hi : i.val ≤ 2 ^ 31) (htop : top.val ≤ mb.length)
(hprev : prev.val ≤ i.val + 258) (hpv : i.val ≤ prev.val) (hpd : pd.val ≤ 32768) (hbd : bd.val ≤ 32767) :
slot.a_a_dp_pass_loop1_loop0 mb lc dc cost tail cl i bias best bd prev pd j top ⦃ fun r =>
prev.val ≤ r.2.2.1.val ∧ r.2.2.1.val ≤ i.val + 258 ∧ r.2.2.2.val ≤ 32768 ∧ r.2.1.val ≤ 32767 ⦄ := by
rw [slot.a_a_dp_pass_loop1_loop0]
apply Std.loop.spec_decr_nat
(measure := fun (_, _, _, _, j_) => top.val - j_.val)
(inv := fun (_, bd_, prev_, pd_, _) => prev.val ≤ prev_.val ∧ prev_.val ≤ i.val + 258 ∧
pd_.val ≤ 32768 ∧ bd_.val ≤ 32767)
· rintro ⟨best_, bd_, prev_, pd_, j_⟩ ⟨hp0, hp1, hpd_, hbd_⟩
simp only [slot.a_a_dp_pass_loop1_loop0.body]
step*
repeat' (split <;> step*)
all_goals scalar_tac
· exact ⟨le_refl _, hprev, hpd, hbd⟩
@[local step]
theorem a_dp_pass_loop1_spec (tail : Std.Usize) (s : Slice Std.U8) (mp mb : alloc.vec.Vec Std.U32) (p0 lit lc dc) (cost ch : alloc.vec.Vec Std.U32)
(cl i e xl xd : Std.Usize)
(hcl : cl.val = cost.length) (hi : i.val < cl.val) (hmp : i.val < mp.length) (hs : i.val ≤ s.length)
(hch : i.val ≤ ch.length) (hi31 : i.val ≤ 2 ^ 31) (hxl : xl.val ≤ 258) (hxd : xd.val ≤ 32768) :
slot.a_a_dp_pass_loop1 s mp mb p0 lit lc dc cost ch tail cl i e xl xd ⦃ fun _ => True ⦄ := by
rw [slot.a_a_dp_pass_loop1]
apply Std.loop.spec_decr_nat
(measure := fun (_, _, i_, _, _, _) => i_.val)
(inv := fun ((cost_ : alloc.vec.Vec Std.U32), (ch_ : alloc.vec.Vec Std.U32), (i_ : Std.Usize), _,
(xl_ : Std.Usize), (xd_ : Std.Usize)) =>
cost_.length = cl.val ∧ ch_.length = ch.length ∧ i_.val ≤ i.val ∧ xl_.val ≤ 258 ∧ xd_.val ≤ 32768)
· rintro ⟨cost_, ch_, i_, e_, xl_, xd_⟩ ⟨hc_, hch_, hi_, hxl_, hxd_⟩
simp only [slot.a_a_dp_pass_loop1.body]
step*
apply WP.spec_bind (Pₘ := fun (top : Std.Usize) => top.val ≤ mb.length)
· split <;> step* <;> scalar_tac
rintro top htop
step*
apply WP.spec_bind (Pₘ := fun (el : Std.Usize) => el.val ≤ 258)
· split <;> step* <;> scalar_tac
rintro el hel
step*
apply WP.spec_bind (Pₘ := fun (x : Std.Usize × Std.Usize × Std.U32 × Std.U32) =>
x.1.val ≤ 258 ∧ x.2.1.val ≤ 32768 ∧ x.2.2.2.val ≤ 32767)
· repeat' (split <;> step*)
all_goals scalar_tac
rintro ⟨xl1, xd1, best2, bd1⟩ ⟨hxl1, hxd1, hbd1⟩
step*
apply WP.spec_bind (Pₘ := fun (x : alloc.vec.Vec Std.U32 × Std.U32) => x.1.length = cost_.length)
· split <;> step* <;> scalar_tac
rintro ⟨cost1, i23⟩ hc1
step*
scalar_tac
· exact ⟨hcl.symm, rfl, le_refl _, hxl, hxd⟩
@[local step]
theorem a_dp_pass_spec (tail : Std.Usize) (s : Slice Std.U8) (mp mb) (p0 pe : Std.Usize) (lit lc dc) (cost ch)
(hpe : pe.val ≤ 2 ^ 31) :
slot.a_a_dp_pass s mp mb p0 pe lit lc dc cost ch tail ⦃ fun _ => True ⦄ := T1! slot.a_a_dp_pass
@[local step]
theorem a_sample_pass_loop0_loop0_spec (lf zf b) :
slot.a_a_sample_pass_loop0_loop0 lf zf b ⦃ fun _ => True ⦄ := by
rw [slot.a_a_sample_pass_loop0_loop0]
apply Std.loop.spec_decr_nat
(measure := fun (zf_, b_) => 512 - b_.val)
(inv := fun _ => True)
· rintro ⟨zf_, b_⟩ _
simp only [slot.a_a_sample_pass_loop0_loop0.body]
step*
repeat' (split <;> step*)
all_goals scalar_tac
· trivial
@[local step]
theorem a_sample_pass_loop0_loop1_spec (df zd b) :
slot.a_a_sample_pass_loop0_loop1 df zd b ⦃ fun _ => True ⦄ := by
rw [slot.a_a_sample_pass_loop0_loop1]Gate report
verifying [internal-path]
workspace: [internal-path]
0 intake ok — 402: parse.rs, Parse.lean
1 policy ok — source prefilters passed
2 static ok — resolved operations: alloc::alloc::Global::{impl}::drop_glue, alloc::vec::Vec::{impl}::drop_glue, alloc::vec::{impl}::deref, alloc::vec::{impl}::deref_mut, alloc::vec::{impl}::index, alloc::vec::{impl}::index_mut, alloc::vec::{impl}::len, alloc::vec::{impl}::new, alloc::vec::{impl}::push, alloc::vec::{impl}::with_capacity, core::num::{impl}::leading_zeros, core::num::{impl}::saturating_add, core::num::{impl}::saturating_sub, core::num::{impl}::wrapping_add, core::num::{impl}::wrapping_mul, core::num::{impl}::wrapping_shl, core::num::{impl}::wrapping_shr, core::num::{impl}::wrapping_sub, core::slice::index::{impl}::get, core::slice::index::{impl}::get_mut, core::slice::index::{impl}::get_unchecked, core::slice::index::{impl}::get_unchecked_mut, core::slice::index::{impl}::index, core::slice::index::{impl}::index_mut, core::slice::{impl}::len
3 extract ok — charon+aeneas re-run by the verifier, no new axioms
4 statement ok — `LZ77.Obligation slot.parse` typechecks (bwrap, 900s, 16384 MB)
5 axioms ok — ['Classical.choice', 'Quot.sound', 'propext']; extraction intact
6 score running…
Corpus: corpus-stage1
file raw incumbent submission
-----------------------------------------------------
binary.db.bin 500000 76338 70985
bundle.min.js.txt 1000000 301618 287484
catalog.xml.txt 500000 62314 58104
compressed.bin 300000 300194 299569
config.yaml.txt 400000 85384 81058
docs.md.txt 800000 226973 215466
dump.sql.txt 150000 20817 16445
genome.fasta 900000 292479 256489
images.bin 250000 223767 223466
lean.txt 1000000 235059 222893
machine-code.bin 500000 167357 159112
metrics.csv.txt 1300000 287282 251816
multibyte.txt 1100000 273630 254352
page.html.txt 600000 103618 98967
prose.txt 1500000 579041 540912
records.json.txt 400000 72255 69048
server.log 300000 29404 25956
source.c.txt 1400000 354325 333225
source.py.txt 600000 132748 125172
source.rs.txt 700000 134069 125966
sourcemap.map.txt 350000 68389 64440
sparse.bin 40000 1234 1193
tiny-app.log 28000 965 836
tiny-config.json.txt 12000 2107 2076
weights-bf16.bin 450000 362200 353965
weights-f16.bin 250000 216274 212660
weights-f32.bin 350000 284747 279059
weights-q8.bin 250000 236246 235572
-----------------------------------------------------
TOTAL 15930000 5130834 4866286
method bytes ratio lz77 encode total slowdown
--------------------------------------------------------------------------------------------------------------
incumbent 5130834 1.00000x 0.628s 0.226s 0.854s 1.00x the incumbent
submission 4866286 0.94844x 3.318s 0.235s 3.553s 4.16x ACCEPTED — 5.156% smaller than the incumbent.
ACCEPTED — 5.156% smaller than the incumbent.
Corpus: corpus-stage2
corpus corpus-stage2 is held out; totals only.
method bytes ratio lz77 encode total slowdown
--------------------------------------------------------------------------------------------------------------
incumbent 5218788 1.00000x 0.630s 0.229s 0.859s 1.00x the incumbent
submission 4958791 0.95018x 3.123s 0.242s 3.365s 3.92x ACCEPTED — 4.982% smaller than the incumbent.
ACCEPTED — 4.982% smaller than the incumbent.