lean4-htt/tests/lean/run/slice.lean
Paul Reichert df26bea7c1
feat: upstream slice API improvements from human-eval-lean (#12352)
This PR improves the slice API with lemmas for `drop`/`take` operations
on `Subarray` and more lemmas about `Std.Slice.fold`, `Std.Slice.foldM`
and `Std.Slice.forIn`. It also changes the `simp` and `grind`
annotations for `Slice`-related lemmas. Lemmas converting between slices
of different shapes are no longer `simp`/`grind`-annotated because they
often complicated lemmas and hindered automation.
2026-02-10 10:54:07 +00:00

140 lines
7.3 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Std.Data.Iterators
example : #[1, 2, 3][*...*].toList = [1, 2, 3] := by simp
example : #[1, 2, 3][*...2].toList = [1, 2] := by simp
example : #[1, 2, 3][*...<2].toList = [1, 2] := by simp
example : #[1, 2, 3][*...=1].toList = [1, 2] := by simp
example : #[1, 2, 3][0<...*].toList = [2, 3] := by simp
example : #[1, 2, 3][0<...2].toList = [2] := by simp
example : #[1, 2, 3][0<...<2].toList = [2] := by simp
example : #[1, 2, 3][0<...=1].toList = [2] := by simp
example : #[1, 2, 3][1...*].toList = [2, 3] := by simp
example : #[1, 2, 3][1...2].toList = [2] := by simp
example : #[1, 2, 3][1...<2].toList = [2] := by simp
example : #[1, 2, 3][1...=1].toList = [2] := by simp
example : #[1, 2, 3][*...*].toArray = #[1, 2, 3] := by simp
example : #[1, 2, 3][*...2].toArray = #[1, 2] := by simp
example : #[1, 2, 3][*...<2].toArray = #[1, 2] := by simp
example : #[1, 2, 3][*...=1].toArray = #[1, 2] := by simp
example : #[1, 2, 3][0<...*].toArray = #[2, 3] := by simp
example : #[1, 2, 3][0<...2].toArray = #[2] := by simp
example : #[1, 2, 3][0<...<2].toArray = #[2] := by simp
example : #[1, 2, 3][0<...=1].toArray = #[2] := by simp
example : #[1, 2, 3][1...*].toArray = #[2, 3] := by simp
example : #[1, 2, 3][1...2].toArray = #[2] := by simp
example : #[1, 2, 3][1...<2].toArray = #[2] := by simp
example : #[1, 2, 3][1...=1].toArray = #[2] := by simp
example : (#[1, 2, 3][1...*].take 1).toList = [2] := by native_decide
example : #[1, 2, 3][1...<10].size = 2 := by simp
example : #[1, 1, 1][0...2].size = 2 := by simp
-- Verify that subarray iterators are universe polymorphic
def f (_ : Type) : Nat := 1
example : #[Nat, Int][*...1].toList.map f = [1] := by simp [f]
example : #[1, 2, 3][0...2][1...2].toList = [2] := by simp
example : #[1, 2, 3][0...2][1...5].toList = [2] := by simp
example : #[1, 2, 3][1...2][0...2].toList = [2] := by simp
example : #[1, 2, 3][1...2][1...2].toList = [] := by simp
example : #[1, 2, 3][1...2][0...=1].toList = [2] := by simp
example : #[1, 2, 3][1...*][1...*].toList = [3] := by simp
example : #[1, 2, 3, 4, 5][1...*][0<...2].toList = [3] := by simp
example : #[1, 2, 3, 4, 5][1...*][0<...=2].toList = [3, 4] := by simp
example : #[1, 2, 3, 4, 5][1...*][0<...*].toList = [3, 4, 5] := by simp
example : #[1, 2, 3, 4, 5][1...3][0<...*].toList = [3] := by simp
example : #[1, 2, 3, 4, 5][1...*][*...2].toList = [2, 3] := by simp
example : #[1, 2, 3, 4, 5][1...*][*...=2].toList = [2, 3, 4] := by simp
example : #[1, 2, 3, 4, 5][1...*][*...*].toList = [2, 3, 4, 5] := by simp
example : #[1, 2, 3][0...2][*...*].toList = [1, 2] := by simp
example : #[1, 2, 3][0...2][1...2].toArray = #[2] := by simp
example : #[1, 2, 3][0...2][1...5].toArray = #[2] := by simp
example : #[1, 2, 3][1...2][0...2].toArray = #[2] := by simp
example : #[1, 2, 3][1...2][1...2].toArray = #[] := by simp
example : #[1, 2, 3][1...2][0...=1].toArray = #[2] := by simp
example : #[1, 2, 3][1...*][1...*].toArray = #[3] := by simp
example : #[1, 2, 3, 4, 5][1...*][0<...2].toArray = #[3] := by simp
example : #[1, 2, 3, 4, 5][1...*][0<...=2].toArray = #[3, 4] := by simp
example : #[1, 2, 3, 4, 5][1...*][0<...*].toArray = #[3, 4, 5] := by simp
example : #[1, 2, 3, 4, 5][1...3][0<...*].toArray = #[3] := by simp
example : #[1, 2, 3, 4, 5][1...*][*...2].toArray = #[2, 3] := by simp
example : #[1, 2, 3, 4, 5][1...*][*...=2].toArray = #[2, 3, 4] := by simp
example : #[1, 2, 3, 4, 5][1...*][*...*].toArray = #[2, 3, 4, 5] := by simp
example : #[1, 2, 3][0...2][*...*].toArray = #[1, 2] := by simp
example : [1, 2, 3][*...*].toList = [1, 2, 3] := by simp
example : [1, 2, 3][*...2].toList = [1, 2] := by simp
example : [1, 2, 3][*...<2].toList = [1, 2] := by simp
example : [1, 2, 3][*...=1].toList = [1, 2] := by simp
example : [1, 2, 3][0<...*].toList = [2, 3] := by simp
example : [1, 2, 3][0<...2].toList = [2] := by simp
example : [1, 2, 3][0<...<2].toList = [2] := by simp
example : [1, 2, 3][0<...=1].toList = [2] := by simp
example : [1, 2, 3][1...*].toList = [2, 3] := by simp
example : [1, 2, 3][1...2].toList = [2] := by simp
example : [1, 2, 3][1...<2].toList = [2] := by simp
example : [1, 2, 3][1...=1].toList = [2] := by simp
example : [1, 2, 3][*...*].toArray = #[1, 2, 3] := by simp
example : [1, 2, 3][*...2].toArray = #[1, 2] := by simp
example : [1, 2, 3][*...<2].toArray = #[1, 2] := by simp
example : [1, 2, 3][*...=1].toArray = #[1, 2] := by simp
example : [1, 2, 3][0<...*].toArray = #[2, 3] := by simp
example : [1, 2, 3][0<...2].toArray = #[2] := by simp
example : [1, 2, 3][0<...<2].toArray = #[2] := by simp
example : [1, 2, 3][0<...=1].toArray = #[2] := by simp
example : [1, 2, 3][1...*].toArray = #[2, 3] := by simp
example : [1, 2, 3][1...2].toArray = #[2] := by simp
example : [1, 2, 3][1...<2].toArray = #[2] := by simp
example : [1, 2, 3][1...=1].toArray = #[2] := by simp
example : [1, 2, 3][1...<10].size = 2 := by simp
example : [1, 1, 1][0...2].size = 2 := by simp
-- Verify that list slice iterators are universe polymorphic
example : [Nat, Int][*...1].toList.map f = [1] := by simp [f]
example : [1, 2, 3][0...2][1...2].toList = [2] := by simp
example : [1, 2, 3][0...2][1...5].toList = [2] := by simp
example : [1, 2, 3][1...2][0...2].toList = [2] := by simp
example : [1, 2, 3][1...2][1...2].toList = [] := by simp
example : [1, 2, 3][1...2][0...=1].toList = [2] := by simp
example : [1, 2, 3][1...*][1...*].toList = [3] := by simp
example : [1, 2, 3, 4, 5][1...*][0<...2].toList = [3] := by simp
example : [1, 2, 3, 4, 5][1...*][0<...=2].toList = [3, 4] := by simp
example : [1, 2, 3, 4, 5][1...*][0<...*].toList = [3, 4, 5] := by simp
example : [1, 2, 3, 4, 5][1...3][0<...*].toList = [3] := by simp
example : [1, 2, 3, 4, 5][1...*][*...2].toList = [2, 3] := by simp
example : [1, 2, 3, 4, 5][1...*][*...=2].toList = [2, 3, 4] := by simp
example : [1, 2, 3, 4, 5][1...*][*...*].toList = [2, 3, 4, 5] := by simp
example : [1, 2, 3][0...2][*...*].toList = [1, 2] := by simp
example : [1, 2, 3][0...2][1...2].toArray = #[2] := by simp
example : [1, 2, 3][0...2][1...5].toArray = #[2] := by simp
example : [1, 2, 3][1...2][0...2].toArray = #[2] := by simp
example : [1, 2, 3][1...2][1...2].toArray = #[] := by simp
example : [1, 2, 3][1...2][0...=1].toArray = #[2] := by simp
example : [1, 2, 3][1...*][1...*].toArray = #[3] := by simp
example : [1, 2, 3, 4, 5][1...*][0<...2].toArray = #[3] := by simp
example : [1, 2, 3, 4, 5][1...*][0<...=2].toArray = #[3, 4] := by simp
example : [1, 2, 3, 4, 5][1...*][0<...*].toArray = #[3, 4, 5] := by simp
example : [1, 2, 3, 4, 5][1...3][0<...*].toArray = #[3] := by simp
example : [1, 2, 3, 4, 5][1...*][*...2].toArray = #[2, 3] := by simp
example : [1, 2, 3, 4, 5][1...*][*...=2].toArray = #[2, 3, 4] := by simp
example : [1, 2, 3, 4, 5][1...*][*...*].toArray = #[2, 3, 4, 5] := by simp
example : [1, 2, 3][0...2][*...*].toArray = #[1, 2] := by simp
example (xs : List α) : xs[*...5].size = xs[0...5].size := by
grind
example {xs : List α} {lo hi : Nat} :
xs[lo...=hi].toList = (xs.take (hi + 1)).drop lo := by
grind
example : type_of% @List.toArray_mkSlice_rii_eq_toArray_mkSlice_rco := by grind
example (xs : List Nat) : xs[1...=4][2...3].toList = xs[3...4].toList := by
grind [List.take_drop, List.drop_drop]
example (xs : Array Nat) : xs[1...=4][2...3].toList = xs[3...4].toList := by
grind [List.take_drop, List.drop_drop]
example (xs : Array Nat) : xs[1...=4][2...3].toArray = xs[3...4].toArray := by grind