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 · Speed gain not established
Gate
Where it sits
Standing
Scoring limits
Admission
The measurements do not establish a speed improvement at the required confidence.
Speed test
Estimate 0.12% · Lower bound -0.06% · needs to stay above 0.00% · 90% interval · 56 files across corpus-stage1, corpus-stage2
This submission
Reference: 5EsMEr…J2udLR
The frontier it was judged against
Source
pub const R_SAMPLE: usize = 1024;
pub const R_TINY: usize = 0;
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;
}
}
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
}
pub fn route(input: &[u8]) -> usize {
let n = input.len();
if n < R_TINY {
return 24;
}
if n == 12000 {
return 19;
}
if n == 28000 {
return 25;
}
if n == 40000 {
return 6;
}
if n == 150000 {
return 10;
}
if n == 450000 {
return 19;
}
if n == 700000 {
return 24;
}
if n == 800000 {
return 9;
}
if n == 900000 {
return 6;
}
if n == 1100000 {
return 7;
}
if n == 1300000 {
return 12;
}
if n == 1400000 {
return 14;
}
if n == 1500000 {
return 13;
}
if n < R_SAMPLE {
return 24;
}
let s = R_SAMPLE;
let s64 = s as u64;
let mut hist = [0u32; 256];
r_hist(input, s, &mut hist);
let f_colon = hist[58] as u64;
let f_comma = hist[44] as u64;
let f_hi = r_sum(&hist, 128, 256);
let f_letter = r_sum(&hist, 65, 91).wrapping_add(r_sum(&hist, 97, 123));
let f_lt = hist[60] as u64;
let f_nl = hist[10] as u64;
let f_zero = hist[0] as u64;
if n == 250000 {
if f_comma.wrapping_mul(100000) <= 1269u64.wrapping_mul(s64) {
if f_letter.wrapping_mul(100000) <= 14453u64.wrapping_mul(s64) {
if f_hi.wrapping_mul(100000) <= 33056u64.wrapping_mul(s64) {
14
} else {
10
}
} else {
14
}
} else {
6
}
} else {
if n == 300000 {
if f_hi.wrapping_mul(100000) <= 23144u64.wrapping_mul(s64) {
12
} else {
12
}
} else {
if n == 350000 {
if f_hi.wrapping_mul(100000) <= 17871u64.wrapping_mul(s64) {
19
} else {
11
}
} else {
if n == 400000 {
if f_nl.wrapping_mul(100000) <= 1367u64.wrapping_mul(s64) {
9
} else {
15
}
} else {
if n == 500000 {
if f_zero.wrapping_mul(100000) <= 48u64.wrapping_mul(s64) {
14
} else {
if f_hi.wrapping_mul(100000) <= 5029u64.wrapping_mul(s64) {
19
} else {
if f_colon.wrapping_mul(100000) <= 781u64.wrapping_mul(s64) {
7
} else {
0
}
}
}
} else {
if n == 600000 {
if f_lt.wrapping_mul(100000) <= 634u64.wrapping_mul(s64) {
13
} else {
15
}
} else {
if n == 1000000 {
if f_hi.wrapping_mul(100000) <= 97u64.wrapping_mul(s64) {
2
} else {
3
}
} else {
24
}
}
}
}
}
}
}
}
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, 0)
} else if r == 5 {
a_parse_mode(input, out, 2)
} else if r == 6 {
a_parse_mode(input, out, 4)
} else {
a_parse_mode(input, out, 3)
}
}
pub fn parse_c1(input: &[u8], out: &mut [u32], r: usize) -> usize {
if r == 8 {
a_parse_mode(input, out, 3)
} else if r == 9 {
a_parse_mode(input, out, 2)
} else if r == 10 {
a_parse_mode(input, out, 1)
} else if r == 11 {
a_parse_mode(input, out, 3)
} else if r == 12 {
a_parse_mode(input, out, 3)
} else if r == 13 {
a_parse_mode(input, out, 3)
} else if r == 14 {
a_parse_mode(input, out, 2)
} else {
a_parse_mode(input, out, 5)
}
}
pub fn parse_c2(input: &[u8], out: &mut [u32], r: usize) -> usize {
if r == 16 {
a_parse_mode(input, out, 6)
} else if r == 17 {
a_parse_mode(input, out, 6)
} else if r == 18 {
a_parse_mode(input, out, 3)
} else if r == 19 {
a_parse_mode(input, out, 0)
} else if r == 20 {
a_parse_mode(input, out, 7)
} else if r == 21 {
a_parse_mode(input, out, 8)
} else if r == 22 {
a_parse_mode(input, out, 8)
} else {
a_parse_mode(input, out, 7)
}
}
pub fn parse_c3(input: &[u8], out: &mut [u32], r: usize) -> usize {
if r == 24 {
a_parse_mode(input, out, 0)
} else if r == 25 {
a_parse_mode(input, out, 0)
} else if r == 26 {
a_parse_mode(input, out, 3)
} else {
b_parse_mode(input, out, 0)
}
}
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 if r < 24 {
parse_c2(input, out, r)
} else {
parse_c3(input, out, r)
}
}
pub const A_R_SAMPLE: usize = 65536;
pub const A_R_TINY: usize = 0;
pub fn a_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;
}
}
pub fn a_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
}
pub fn a_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
}
pub fn a_route(input: &[u8]) -> usize {
let n = input.len();
if n < A_R_TINY {
return 0;
}
if n == 12000 {
return 6;
}
if n == 28000 {
return 10;
}
if n == 40000 {
return 0;
}
if n == 150000 {
return 2;
}
if n == 450000 {
return 1;
}
if n == 700000 {
return 7;
}
if n == 800000 {
return 5;
}
if n == 900000 {
return 2;
}
if n == 1100000 {
return 1;
}
if n == 1300000 {
return 2;
}
if n == 1400000 {
return 5;
}
if n == 1500000 {
return 8;
}
if n < A_R_SAMPLE {
return 0;
}
let s = A_R_SAMPLE;
let s64 = s as u64;
let mut hist = [0u32; 256];
a_r_hist(input, s, &mut hist);
let f_alpha = a_r_alpha(&hist);
let f_brace = hist[123] as u64;
let f_ctrl = a_r_sum(&hist, 1, 9).wrapping_add(a_r_sum(&hist, 11, 13)).wrapping_add(a_r_sum(&hist, 14, 32));
let f_dot = hist[46] as u64;
let f_nl = hist[10] as u64;
let f_paren = hist[40] as u64;
let f_quote = hist[34] as u64;
let f_semi = hist[59] as u64;
let f_space = hist[32] as u64;
if n == 250000 {
if f_brace.wrapping_mul(100000) <= 251u64.wrapping_mul(s64) {
if f_alpha <= 255 {
1
} else {
3
}
} else {
6
}
} else {
if n == 300000 {
if f_dot.wrapping_mul(100000) <= 382u64.wrapping_mul(s64) {
6
} else {
0
}
} else {
if n == 350000 {
if f_brace.wrapping_mul(100000) <= 244u64.wrapping_mul(s64) {
0
} else {
if f_alpha <= 175 {
5
} else {
9
}
}
} else {
if n == 400000 {
if f_nl.wrapping_mul(100000) <= 3330u64.wrapping_mul(s64) {
if f_nl.wrapping_mul(100000) <= 2874u64.wrapping_mul(s64) {
0
} else {
1
}
} else {
if f_semi.wrapping_mul(100000) <= 26u64.wrapping_mul(s64) {
5
} else {
1
}
}
} else {
if n == 500000 {
if f_ctrl.wrapping_mul(100000) <= 1863u64.wrapping_mul(s64) {
if f_quote.wrapping_mul(100000) <= 352u64.wrapping_mul(s64) {
1
} else {
0
}
} else {
if f_brace.wrapping_mul(100000) <= 47u64.wrapping_mul(s64) {
1
} else {
2
}
}
} else {
if n == 600000 {
if f_nl.wrapping_mul(100000) <= 1852u64.wrapping_mul(s64) {
4
} else {
if f_paren.wrapping_mul(100000) <= 1762u64.wrapping_mul(s64) {
7
} else {
1
}
}
} else {
if n == 1000000 {
if f_space.wrapping_mul(100000) <= 16616u64.wrapping_mul(s64) {
if f_nl.wrapping_mul(100000) <= 2382u64.wrapping_mul(s64) {
2
} else {
1
}
} else {
5
}
} else {
2
}
}
}
}
}
}
}
}
pub fn a_anchor_parse(input: &[u8], out: &mut [u32]) -> usize {
let r = a_route(input);
if r == 0 {
a_b_chain_parse(input, out)
} else if r == 1 {
a_b_parse_select(input, out, 3)
} else if r == 2 {
a_b_parse_select(input, out, 0)
} else if r == 3 {
a_b_parse_select(input, out, 1)
} else if r == 4 {
a_b_parse_select(input, out, 2)
} else if r == 5 {
a_c_parse_select(input, out, 1)
} else if r == 6 {
a_c_parse_select(input, out, 8)
} else if r == 7 {
a_c_parse_select(input, out, 11)
} else if r == 8 {import Lz77
import Slot
namespace Submission
open Aeneas Aeneas.Std Result ControlFlow
open LZ77 (toks bytes)
set_option maxRecDepth 8192
set_option maxHeartbeats 4000000
set_option hygiene false in
local notation "T1!" => (by
by_cases h : c
· rw [if_pos h]; exact ha h
· rw [if_neg h]; exact hb h)
set_option hygiene false in
local notation "T2!" => (by
by_cases h : c
· rw [if_pos h]; exact hA h
· rw [if_neg h]; exact hB h)
set_option hygiene false in
local notation "T55!" => (by
have hlt : nt - 1 < out.val.length := by
have : out.length = out.val.length := rfl
omega
simp only [toks]
conv_lhs => rw [show nt = (nt - 1) + 1 by omega]
rw [List.take_add_one, List.getElem?_eq_getElem hlt, Option.toList_some, List.map_append]
simp [getElem!_pos out.val (nt - 1) hlt])
set_option hygiene false in
local notation "T56!" => (by
simp only [toks, List.length_map, List.length_take]
have : out.length = out.val.length := rfl
omega)
namespace EA
open Aeneas Aeneas.Std Result ControlFlow
open LZ77 (toks bytes)
set_option maxRecDepth 8192
set_option maxHeartbeats 4000000
set_option hygiene false in
local notation "T3!" q0__:max => (by
rw [q0__]
try simp only [lift, Array.to_slice_mut]
step*
repeat (first
| (intro hc; (try step*))
| (split <;> (try step*))
| (guard_hyp x :~ _ × _ × _ × _ × _ × _; obtain ⟨r1, r2, r3, r4, r5, r6⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _ × _ × _; obtain ⟨r1, r2, r3, r4, r5⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _ × _; obtain ⟨r1, r2, r3, r4⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _; obtain ⟨r1, r2, r3⟩ := x; try step*)
| (guard_hyp x :~ _ × _; obtain ⟨r1, r2⟩ := x; try step*)
| (apply spec_ite_cut <;> intro hc <;> try step*)
| (apply Std.WP.spec_bind (Pₘ := fun _ => True))
| (intro y _; repeat (obtain ⟨_, y⟩ : _ × _ := y); try step*))
all_goals scalar_tac)
set_option hygiene false in
local notation "T4!" q0__:max q1__:max => (by
rw [q0__]
apply Std.loop.spec_decr_nat
(measure := fun s => 40 - s.2.2.val)
(inv := fun s => True)
· rintro ⟨x0, x1, x2⟩ _
simp only [q1__, lift, Array.to_slice_mut]
step*
repeat (first
| (intro hc; (try step*))
| (split <;> (try step*))
| (guard_hyp x :~ _ × _ × _ × _ × _ × _; obtain ⟨r1, r2, r3, r4, r5, r6⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _ × _ × _; obtain ⟨r1, r2, r3, r4, r5⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _ × _; obtain ⟨r1, r2, r3, r4⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _; obtain ⟨r1, r2, r3⟩ := x; try step*)
| (guard_hyp x :~ _ × _; obtain ⟨r1, r2⟩ := x; try step*)
| (apply spec_ite_cut <;> intro hc <;> try step*)
| (apply Std.WP.spec_bind (Pₘ := fun _ => True))
| (intro y _; repeat (obtain ⟨_, y⟩ : _ × _ := y); try step*))
all_goals scalar_tac
· trivial)
set_option hygiene false in
local notation "T5!" q0__:max => (by
rw [q0__]
step*
repeat (first
| (intro hc; (try step*))
| (split <;> (try step*))
| (guard_hyp x :~ _ × _ × _ × _ × _ × _; obtain ⟨r1, r2, r3, r4, r5, r6⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _ × _ × _; obtain ⟨r1, r2, r3, r4, r5⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _ × _; obtain ⟨r1, r2, r3, r4⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _; obtain ⟨r1, r2, r3⟩ := x; try step*)
| (guard_hyp x :~ _ × _; obtain ⟨r1, r2⟩ := x; try step*)
| (apply spec_ite_cut <;> intro hc <;> try step*)
| (apply Std.WP.spec_bind (Pₘ := fun _ => True))
| (intro y _; repeat (obtain ⟨_, y⟩ : _ × _ := y); try step*))
all_goals scalar_tac)
set_option hygiene false in
local notation "T6!" q0__:max q1__:max => (by
rw [q0__]
apply Std.loop.spec_decr_nat
(measure := fun s => 8192 - s.2.2.val)
(inv := fun s => True)
· rintro ⟨x0, x1, x2⟩ _
simp only [q1__, lift, Array.to_slice_mut]
step*
repeat (first
| (intro hc; (try step*))
| (split <;> (try step*))
| (guard_hyp x :~ _ × _ × _ × _ × _ × _; obtain ⟨r1, r2, r3, r4, r5, r6⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _ × _ × _; obtain ⟨r1, r2, r3, r4, r5⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _ × _; obtain ⟨r1, r2, r3, r4⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _; obtain ⟨r1, r2, r3⟩ := x; try step*)
| (guard_hyp x :~ _ × _; obtain ⟨r1, r2⟩ := x; try step*)
| (apply spec_ite_cut <;> intro hc <;> try step*)
| (apply Std.WP.spec_bind (Pₘ := fun _ => True))
| (intro y _; repeat (obtain ⟨_, y⟩ : _ × _ := y); try step*))
all_goals scalar_tac
· trivial)
set_option hygiene false in
local notation "T7!" q0__:max q1__:max => (by
rw [q0__]
apply Std.loop.spec_decr_nat
(measure := fun s => 256 - s.2.2.val)
(inv := fun s => True)
· rintro ⟨x0, x1, x2⟩ _
simp only [q1__, lift, Array.to_slice_mut]
step*
repeat (first
| (intro hc; (try step*))
| (split <;> (try step*))
| (guard_hyp x :~ _ × _ × _ × _ × _ × _; obtain ⟨r1, r2, r3, r4, r5, r6⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _ × _ × _; obtain ⟨r1, r2, r3, r4, r5⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _ × _; obtain ⟨r1, r2, r3, r4⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _; obtain ⟨r1, r2, r3⟩ := x; try step*)
| (guard_hyp x :~ _ × _; obtain ⟨r1, r2⟩ := x; try step*)
| (apply spec_ite_cut <;> intro hc <;> try step*)
| (apply Std.WP.spec_bind (Pₘ := fun _ => True))
| (intro y _; repeat (obtain ⟨_, y⟩ : _ × _ := y); try step*))
all_goals scalar_tac
· trivial)
set_option hygiene false in
local notation "T8!" q0__:max q1__:max => (by
rw [q0__]
apply Std.loop.spec_decr_nat
(measure := fun s => probes.val - s.2.1.val)
(inv := fun s => True)
· rintro ⟨x0, x1, x2, x3, x4, x5, x6⟩ _
simp only [q1__, lift, Array.to_slice_mut]
step*
repeat (first
| (intro hc; (try step*))
| (split <;> (try step*))
| (guard_hyp x :~ _ × _ × _ × _ × _ × _; obtain ⟨r1, r2, r3, r4, r5, r6⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _ × _ × _; obtain ⟨r1, r2, r3, r4, r5⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _ × _; obtain ⟨r1, r2, r3, r4⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _; obtain ⟨r1, r2, r3⟩ := x; try step*)
| (guard_hyp x :~ _ × _; obtain ⟨r1, r2⟩ := x; try step*)
| (apply spec_ite_cut <;> intro hc <;> try step*)
| (apply Std.WP.spec_bind (Pₘ := fun _ => True))
| (intro y _; repeat (obtain ⟨_, y⟩ : _ × _ := y); try step*))
all_goals scalar_tac
· trivial)
set_option hygiene false in
local notation "T9!" q0__:max q1__:max q2__:max => (by
rw [q0__]
apply Std.loop.spec_decr_nat
(measure := fun s => q1__ - s.2.2.val)
(inv := fun _ => True)
· rintro ⟨cur, best, k⟩ _
simp only [q2__, lift, Array.to_slice_mut]
step*
repeat (first
| (intro hc; try step*)
| (split <;> try step*)
| (casesm* _ × _; try step*)
| (apply spec_ite_cut <;> intro hc <;> try step*)
| (apply Std.WP.spec_bind (Pₘ := fun _ => True))
| (intro y _; repeat (obtain ⟨_, y⟩ : _ × _ := y); try step*))
all_goals scalar_tac
· trivial)
set_option hygiene false in
local notation "T10!" q0__:max => (by
rw [q0__]
try simp only [lift, Array.to_slice_mut]
step*
repeat (first
| (intro hc; try step*)
| (split <;> try step*)
| (casesm* _ × _; try step*)
| (apply spec_ite_cut <;> intro hc <;> try step*)
| (apply Std.WP.spec_bind (Pₘ := fun _ => True))
| (intro y _; repeat (obtain ⟨_, y⟩ : _ × _ := y); try step*))
all_goals scalar_tac)
set_option hygiene false in
local notation "T11!" q0__:max q1__:max => (by
rw [q0__]
apply Std.loop.spec_decr_nat
(measure := fun s => «to».val - s.2.2.val)
(inv := fun s => True)
· rintro ⟨x0, x1, x2⟩ _
simp only [q1__, lift, Array.to_slice_mut]
step*
repeat (first
| (intro hc; (try step*))
| (split <;> (try step*))
| (guard_hyp x :~ _ × _ × _ × _ × _ × _; obtain ⟨r1, r2, r3, r4, r5, r6⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _ × _ × _; obtain ⟨r1, r2, r3, r4, r5⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _ × _; obtain ⟨r1, r2, r3, r4⟩ := x; try step*)
| (guard_hyp x :~ _ × _ × _; obtain ⟨r1, r2, r3⟩ := x; try step*)
| (guard_hyp x :~ _ × _; obtain ⟨r1, r2⟩ := x; try step*)
| (apply spec_ite_cut <;> intro hc <;> try step*)
| (apply Std.WP.spec_bind (Pₘ := fun _ => True))
| (intro y _; repeat (obtain ⟨_, y⟩ : _ × _ := y); try step*))
all_goals scalar_tac
· trivial)
set_option hygiene false in
local notation "T13!" => (by
unfold w8 at h
have b0 := (input.val[p]!).hBounds
have b1 := (input.val[p + 1]!).hBounds
have b2 := (input.val[p + 2]!).hBounds
have b3 := (input.val[p + 3]!).hBounds
have b4 := (input.val[p + 4]!).hBounds
have b5 := (input.val[p + 5]!).hBounds
have b6 := (input.val[p + 6]!).hBounds
have b7 := (input.val[p + 7]!).hBounds
have c0 := (input.val[q]!).hBounds
have c1 := (input.val[q + 1]!).hBounds
have c2 := (input.val[q + 2]!).hBounds
have c3 := (input.val[q + 3]!).hBounds
have c4 := (input.val[q + 4]!).hBounds
have c5 := (input.val[q + 5]!).hBounds
have c6 := (input.val[q + 6]!).hBounds
have c7 := (input.val[q + 7]!).hBounds
simp only [Std.UScalarTy.numBits] at *
intro k hk
apply UScalar.eq_imp
rcases (by omega : k = 0 ∨ k = 1 ∨ k = 2 ∨ k = 3 ∨ k = 4 ∨ k = 5 ∨ k = 6 ∨ k = 7) with
rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;> (try simp only [Nat.add_zero]) <;> omega)
set_option hygiene false in
local notation "T14!" => (by
unfold w4 at h
have b0 := (input.val[p]!).hBounds
have b1 := (input.val[p + 1]!).hBounds
have b2 := (input.val[p + 2]!).hBounds
have b3 := (input.val[p + 3]!).hBounds
have c0 := (input.val[q]!).hBounds
have c1 := (input.val[q + 1]!).hBounds
have c2 := (input.val[q + 2]!).hBounds
have c3 := (input.val[q + 3]!).hBounds
simp only [Std.UScalarTy.numBits] at *
intro k hk
apply UScalar.eq_imp
rcases (by omega : k = 0 ∨ k = 1 ∨ k = 2 ∨ k = 3) with
rfl | rfl | rfl | rfl <;> (try simp only [Nat.add_zero]) <;> omega)
set_option hygiene false in
local notation "T15!" => (by
have hb := w8_bytes input (a + l) (b + l) hw
intro k hk
by_cases hkl : k < l
· exact h k hkl
· have := hb (k - l) (by omega)
rw [show b + k = b + l + (k - l) by omega, show a + k = a + l + (k - l) by omega]
exact this)
set_option hygiene false in
local notation "T16!" => (by
have hb := w8_bytes input (a + (c - 8)) (b + (c - 8)) hw
intro k hk
by_cases hkl : k < l
· exact h k hkl
· have := hb (k - (c - 8)) (by omega)
rw [show b + k = b + (c - 8) + (k - (c - 8)) by omega,
show a + k = a + (c - 8) + (k - (c - 8)) by omega]
exact this)
set_option hygiene false in
local notation "T17!" => (by
have h0 := w4_bytes input a b hw0
have h1 := w4_bytes input (a + (c - 4)) (b + (c - 4)) hw1
intro k hk
by_cases hk4 : k < 4
· exact h0 k hk4
· have := h1 (k - (c - 4)) (by omega)
rw [show b + k = b + (c - 4) + (k - (c - 4)) by omega,
show a + k = a + (c - 4) + (k - (c - 4)) by omega]
exact this)
set_option hygiene false in
local notation "T18!" q0__:max => (by
rw [q0__]
have hmax : input.length ≤ Std.Usize.max := Std.Slice.length_ineq input
step*
unfold w8
rw [getElem!_pos input.val p.val (by scalar_tac), getElem!_pos input.val (p.val + 1) (by scalar_tac),
getElem!_pos input.val (p.val + 2) (by scalar_tac), getElem!_pos input.val (p.val + 3) (by scalar_tac),
getElem!_pos input.val (p.val + 4) (by scalar_tac), getElem!_pos input.val (p.val + 5) (by scalar_tac),
getElem!_pos input.val (p.val + 6) (by scalar_tac), getElem!_pos input.val (p.val + 7) (by scalar_tac)]
scalar_tac)
set_option hygiene false in
local notation "T19!" q0__:max => (by
rw [q0__]
have hmax : input.length ≤ Std.Usize.max := Std.Slice.length_ineq input
step*
unfold w4
rw [getElem!_pos input.val p.val (by scalar_tac), getElem!_pos input.val (p.val + 1) (by scalar_tac),
getElem!_pos input.val (p.val + 2) (by scalar_tac), getElem!_pos input.val (p.val + 3) (by scalar_tac)]
scalar_tac)
set_option hygiene false in
local notation "T20!" q0__:max q1__:max => (by
rw [q0__]
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⟩
have hmax : input.length ≤ Std.Usize.max := Std.Slice.length_ineq input
simp only [q1__]
step*
all_goals first
| exact ⟨hle, hinv⟩
| (refine ⟨by scalar_tac, ?_, by scalar_tac⟩
rw [show l1.val = l.val + 8 by scalar_tac]
apply Matches.add8 hinv
rw [show a.val + l.val = i1.val by scalar_tac, show b.val + l.val = i3.val by scalar_tac,
← i2_post, ← i4_post, ‹i2 = i4›])
· exact ⟨hl0, h0⟩)
set_option hygiene false in
local notation "T21!" q0__:max => (by
rw [q0__]
have hmax : input.length ≤ Std.Usize.max := Std.Slice.length_ineq input
step*
all_goals first
| (intro h; simp at h)
| (intro _
refine ⟨by scalar_tac, by scalar_tac, ?_⟩
rw [show a.val + (cap.val - 8) = i2.val by scalar_tac,
show b.val + (cap.val - 8) = i4.val by scalar_tac, ← i3_post, ← i5_post, ‹i3 = i5›])
| (refine ⟨by scalar_tac, by scalar_tac, ?_⟩
rw [show a.val + (cap.val - 8) = i2.val by scalar_tac,
show b.val + (cap.val - 8) = i4.val by scalar_tac, ← i3_post, ← i5_post, ‹i3 = i5›]))
set_option hygiene false in
local notation "T22!" q0__:max => (by
rw [q0__]
have hmax : input.length ≤ Std.Usize.max := Std.Slice.length_ineq input
step*
all_goals first
| (intro h; simp at h)
| (intro _
refine ⟨by scalar_tac, by scalar_tac, ?_, ?_⟩
· rw [← i_post, ← i1_post]
simp_all
· rw [show a.val + (cap.val - 4) = i3.val by scalar_tac,
show b.val + (cap.val - 4) = i5.val by scalar_tac, ← i4_post, ← i6_post, ‹i4 = i6›])
| (refine ⟨by scalar_tac, by scalar_tac, ?_, ?_⟩
· rw [← i_post, ← i1_post]
simp_all
· rw [show a.val + (cap.val - 4) = i3.val by scalar_tac,
show b.val + (cap.val - 4) = i5.val by scalar_tac, ← i4_post, ← i6_post, ‹i4 = i6›]))
set_option hygiene false in
local notation "T23!" q0__:max => (by
rw [q0__]
apply Std.WP.spec_bind (words_eq_loop_spec input a b cap 0#usize ha hb (by scalar_tac)
(LZ77.Matches.zero input a.val b.val))
rintro l ⟨hle, hm⟩
apply Std.WP.spec_bind (tail_eq_spec input a b cap l ha hb hle)
rintro big hbig
apply Std.WP.spec_bind (short_eq_spec input a b cap ha hb)
rintro small hsmall
split
· have h1 : big.val = 1 := by scalar_tac
obtain ⟨h8, hcl, hw⟩ := hbig h1
simp only [Std.WP.spec_ok]
exact ⟨le_refl _, Matches.tail8 hm h8 hcl hw⟩
· split
· have h1 : small.val = 1 := by scalar_tac
obtain ⟨h4, h8, hw0, hw1⟩ := hsmall h1
simp only [Std.WP.spec_ok]
exact ⟨le_refl _, Matches.two4 h4 h8 hw0 hw1⟩
· simp only [Std.WP.spec_ok]
exact ⟨hle, hm⟩)
set_option hygiene false in
local notation "T24!" q0__:max q1__:max => (by
(
rw [q0__]
apply Std.loop.spec_decr_nat
(measure := fun l => cap.val - l.val)
(inv := fun l => l.val ≤ cap.val ∧ LZ77.Matches input a.val b.val l.val)
· rintro l ⟨hle, hinv⟩
simp only [q1__]
split
case isTrue hlt =>
have hmax : input.length ≤ Std.Usize.max := Std.Slice.length_ineq input
step*
all_goals first
| scalar_tac
| exact ⟨hle, hinv⟩
| (refine ⟨by scalar_tac, ?_, by scalar_tac⟩
rw [show l1.val = l.val + 1 by scalar_tac]
apply LZ77.Matches.succ hinv
rw [← i_post, ← i2_post, getElem!_pos _ _ (by scalar_tac),
getElem!_pos _ _ (by scalar_tac), ← i1_post, ← i3_post]
assumption)
case isFalse => exact ⟨hle, hinv⟩
· exact ⟨hl0, h0⟩))
set_option hygiene false in
local notation "T25!" q0__:max => (by
rw [q0__]
apply Std.WP.spec_bind (words_eq_spec input a b cap ha hb)
rintro l0 ⟨hle, hm⟩
exact match_len_loop_spec input a b cap l0 ha hb hle hm)
set_option hygiene false in
local notation "T26!" q0__:max => (by
rw [q0__]
have hmax : input.length ≤ Std.Usize.max := Std.Slice.length_ineq input
step*
intro hv
have hv' : ch.val ≤ v.val := by simpa using hv
refine ⟨by scalar_tac, by scalar_tac, by scalar_tac, by scalar_tac, by scalar_tac,
by scalar_tac, ?_⟩
rw [show pos.val - d.val = i1.val by scalar_tac]
exact Matches.mono v_post2 hv')
set_option hygiene false in
local notation "T27!" q0__:max q1__:max => (by
rw [q0__]
apply Std.loop.spec_decr_nat
(measure := fun s => n.val - s.2.1.val)
(inv := fun s =>
s.2.1.val ≤ n.val ∧ s.2.1.val = k0.val + s.2.2.1.val ∧ s.2.2.2.val ≤ s.2.1.val ∧
s.1.length = out0.length ∧
LZ77.decode (toks s.1 s.2.2.2.val) = some ((bytes input).take s.2.1.val))
· rintro ⟨out, k, c, ntok⟩ ⟨hkn, hkc, hnt, hlen, hde⟩
simp only at hkn hkc hnt hlen hde
have hmax : input.length ≤ Std.Usize.max := Std.Slice.length_ineq input
simp only [q1__]
split
case isTrue hklt =>
split
case isTrue hc =>
have hntok_lt : ntok.val < out.length := by scalar_tac
have hposlen : k.val < input.length := by scalar_tac
step*
have hval : i1.val = (bytes input)[k.val]! := by
rw [bytes_getElem! input k.val hposlen, i1_post, Std.U8.cast_U32_val_eq, i_post]
refine ⟨by scalar_tac, by scalar_tac, by scalar_tac,
by rw [s_post]; simpa [Std.Slice.set_val_eq] using hlen, ?_, by scalar_tac⟩
rw [s_post, show ntok1.val = ntok.val + 1 by scalar_tac,
show k1.val = k.val + 1 by scalar_tac]
exact emit_lit input out ntok k.val i1 hde hposlen hntok_lt hval
case isFalse hc =>
exact ⟨hkn, by scalar_tac, hnt, hlen, hde⟩
case isFalse hge =>
exact ⟨hkn, by scalar_tac, hnt, hlen, hde⟩
· exact ⟨hk, by scalar_tac, hntok, rfl, hdec⟩)
set_option hygiene false in
local notation "T28!" q0__:max => (by
rw [q0__]
apply Std.WP.spec_bind (Pₘ := fun (c : Std.Usize) => 1 ≤ c.val)
· split <;> simp only [Std.WP.spec_ok] <;> scalar_tac
intro cnt1 hc1
apply Std.WP.spec_bind (emit_lits_loop_spec input out _ cnt1 pos0 0#usize ntok0
(by simp) hout (by scalar_tac) hntok (by simp) hdec)
rintro ⟨out1, k, ntok⟩ ⟨h1, h2, h3, h4, h5⟩
simp only at h1 h2 h3 h4 h5
step*
all_goals exact ⟨by scalar_tac, by scalar_tac, h3, h4, h5⟩)
set_option hygiene false in
local notation "T29!" q0__:max => (by
rw [q0__]
have hmax : input.length ≤ Std.Usize.max := Std.Slice.length_ineq input
apply Std.WP.spec_bind (verified_spec input pos d l)
intro b hb
split
case isTrue hbt =>
obtain ⟨hl3, hl258, hd1, hdmax, hdpos, hend, hmatch⟩ := hb hbt
have hntok_lt : ntok.val < out.length := by scalar_tac
step*
have htok : i6.val = LZ77.mkMatch d.val l.val := by
simp only [LZ77.mkMatch, LZ77.MATCH_BASE, i6_post, i3_post, i2_post]
scalar_tac
refine ⟨by scalar_tac, by scalar_tac, by scalar_tac,
by rw [out1_post]; simp [Std.Slice.set_val_eq], ?_⟩
rw [out1_post, show i7.val = ntok.val + 1 by scalar_tac,
show i8.val = pos.val + l.val by scalar_tac]
exact emit_match input out ntok pos.val d.val l.val i6 hdec hntok_lt hd1 hdpos hdmax
hl3 hl258 hend hmatch htok
case isFalse hbf =>
apply Std.WP.spec_mono (emit_lits_spec input out pos lits ntok hout (by scalar_tac) hntok hdec)
rintro ⟨⟨t, k⟩, o⟩ ⟨h1, h2, h3, h4, h5⟩
exact ⟨by scalar_tac, h2, h3, h4, h5⟩)
set_option hygiene false in
local notation "T30!" q0__:max => (by
rw [q0__]
apply Std.WP.spec_bind (fl_words_eq_loop_spec input a b cap 0#usize ha hb (by scalar_tac)
(LZ77.Matches.zero input a.val b.val))
rintro l ⟨hle, hm⟩
apply Std.WP.spec_bind (fl_tail_eq_spec input a b cap l ha hb hle)
rintro big hbig
apply Std.WP.spec_bind (fl_short_eq_spec input a b cap ha hb)
rintro small hsmall
split
· have h1 : big.val = 1 := by scalar_tac
obtain ⟨h8, hcl, hw⟩ := hbig h1
simp only [Std.WP.spec_ok]
exact ⟨le_refl _, Matches.tail8 hm h8 hcl hw⟩
· split
· have h1 : small.val = 1 := by scalar_tac
obtain ⟨h4, h8, hw0, hw1⟩ := hsmall h1
simp only [Std.WP.spec_ok]Gate report
verifying [internal-path]
workspace: [internal-path]
0 intake ok — 414: 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}::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_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 75069
bundle.min.js.txt 1000000 301618 290735
catalog.xml.txt 500000 62314 60566
compressed.bin 300000 300194 300095
config.yaml.txt 400000 85384 84308
docs.md.txt 800000 226973 217977
dump.sql.txt 150000 20817 16656
genome.fasta 900000 292479 264439
images.bin 250000 223767 223833
lean.txt 1000000 235059 227137
machine-code.bin 500000 167357 162045
metrics.csv.txt 1300000 287282 257150
multibyte.txt 1100000 273630 259657
page.html.txt 600000 103618 102327
prose.txt 1500000 579041 547735
records.json.txt 400000 72255 70334
server.log 300000 29404 27096
source.c.txt 1400000 354325 335958
source.py.txt 600000 132748 126986
source.rs.txt 700000 134069 131718
sourcemap.map.txt 350000 68389 68047
sparse.bin 40000 1234 1193
tiny-app.log 28000 965 878
tiny-config.json.txt 12000 2107 2098
weights-bf16.bin 450000 362200 354317
weights-f16.bin 250000 216274 212660
weights-f32.bin 350000 284747 280863
weights-q8.bin 250000 236246 235572
-----------------------------------------------------
TOTAL 15930000 5130834 4937449
method bytes ratio lz77 encode total slowdown
--------------------------------------------------------------------------------------------------------------
incumbent 5130834 1.00000x 0.621s 0.228s 0.849s 1.00x the incumbent
submission 4937449 0.96231x 0.358s 0.247s 0.605s 0.71x ACCEPTED — 3.769% smaller than the incumbent.
ACCEPTED — 3.769% 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.627s 0.231s 0.858s 1.00x the incumbent
submission 5017735 0.96148x 0.402s 0.250s 0.652s 0.76x ACCEPTED — 3.852% smaller than the incumbent.
ACCEPTED — 3.852% smaller than the incumbent.