Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - feat port: Data.List.Basic #966

Closed
wants to merge 169 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
169 commits
Select commit Hold shift + click to select a range
ac15b17
port: CategoryTheory.Category.KleisliCat
rosborn Dec 3, 2022
aaacdbf
Initial fixes and renaming
rosborn Dec 3, 2022
1beccd2
Add CategoryTheory.Category.KleisliCat to Mathlib.lean
rosborn Dec 3, 2022
0b745a8
Merge remote-tracking branch 'origin/master' into CategoryTheory.Cate…
semorrison Dec 6, 2022
f6044da
feat port: Data.List.Basic
ChrisHughes24 Dec 12, 2022
957c491
fixes
ChrisHughes24 Dec 12, 2022
67654b2
some fixes
ChrisHughes24 Dec 12, 2022
69cbdee
more fixes
ChrisHughes24 Dec 12, 2022
bb4ef8e
fixes
ChrisHughes24 Dec 12, 2022
6fcddd7
more fixes
ChrisHughes24 Dec 12, 2022
7e90d50
more fixes
ChrisHughes24 Dec 12, 2022
33833d9
fix repeat section
ChrisHughes24 Dec 12, 2022
5c3fd80
more fixes
ChrisHughes24 Dec 12, 2022
286b686
more fixes
ChrisHughes24 Dec 12, 2022
ad3ae26
fixes
ChrisHughes24 Dec 12, 2022
7eeaaa5
Merge remote-tracking branch 'origin/master' into Data.List.Basic
semorrison Dec 14, 2022
e8ca645
Merge remote-tracking branch 'origin/master' into Data.List.Basic
semorrison Dec 17, 2022
01d698a
wow, there is a lot to do here
semorrison Dec 17, 2022
bda8b44
a tiny bit
semorrison Dec 17, 2022
07f56d5
add source header
jcommelin Dec 17, 2022
e905b3f
fix nthLe_tail
jcommelin Dec 17, 2022
3f7f8a7
one fix
siddhartha-gadgil Dec 17, 2022
20ea406
Merge branch 'Data.List.Basic' of https://github.com/leanprover-commu…
siddhartha-gadgil Dec 17, 2022
d17e24e
fix bidirectionalRec
jcommelin Dec 17, 2022
3c01a75
underscore unused vars
jcommelin Dec 17, 2022
85abdcd
fix repeat_sublist_repeat
jcommelin Dec 17, 2022
b151226
better fix
jcommelin Dec 17, 2022
3e78198
fix decidableSublist
jcommelin Dec 17, 2022
0403e2e
global replace index_of -> indexOf
jcommelin Dec 17, 2022
30c1dfc
better replace, preserving #align statements
jcommelin Dec 17, 2022
a05e139
map_take
siddhartha-gadgil Dec 17, 2022
724f442
Merge branch 'Data.List.Basic' of https://github.com/leanprover-commu…
siddhartha-gadgil Dec 17, 2022
8e6ea5e
nth map
siddhartha-gadgil Dec 17, 2022
3558892
some cleanuo
siddhartha-gadgil Dec 17, 2022
2a7ea3f
more cleanup
siddhartha-gadgil Dec 17, 2022
7b4f898
sooomore cleanup
siddhartha-gadgil Dec 17, 2022
0c64a6a
more cleanup
siddhartha-gadgil Dec 17, 2022
17de2ee
more renaming
siddhartha-gadgil Dec 17, 2022
cac2d98
simp attribute for aligned from Std
siddhartha-gadgil Dec 17, 2022
ff808f8
another correction
siddhartha-gadgil Dec 17, 2022
5b695e8
fix nthLe_of_mem
jcommelin Dec 17, 2022
37852d0
add #align statements for list.sublist.cons2 and list.erasep
jcommelin Dec 17, 2022
3160496
progress lines 1300 - 1400
thorimur Dec 18, 2022
37d92c4
progress lines 1400 - 1500
thorimur Dec 18, 2022
5450789
progress 1500 -1610
thorimur Dec 18, 2022
12bdc0b
ported `indexOf` section
thorimur Dec 18, 2022
591e3cd
.
thorimur Dec 18, 2022
3dd3b07
.
thorimur Dec 18, 2022
0808aa7
·
thorimur Dec 18, 2022
68afcd3
cleaned up rename_i
thorimur Dec 18, 2022
549236e
Merge remote-tracking branch 'origin/master' into CategoryTheory.Cate…
semorrison Dec 18, 2022
d2f6b77
rename and add source header
semorrison Dec 18, 2022
6872c53
oops
semorrison Dec 18, 2022
2945119
small fixes
ChrisHughes24 Dec 19, 2022
47da5bd
one more fix
ChrisHughes24 Dec 19, 2022
5fb056d
more naming
ChrisHughes24 Dec 19, 2022
a625154
more fixes
ChrisHughes24 Dec 19, 2022
ae5b3a0
fixes
ChrisHughes24 Dec 19, 2022
7dd117f
more fixes
ChrisHughes24 Dec 19, 2022
7b41471
fixes
ChrisHughes24 Dec 19, 2022
a05c276
more fixes
ChrisHughes24 Dec 19, 2022
f047807
more fixing
ChrisHughes24 Dec 19, 2022
1b16e05
more fixes
ChrisHughes24 Dec 19, 2022
b64f667
minifix
jcommelin Dec 19, 2022
e583f6e
minifix
jcommelin Dec 19, 2022
b340a52
Merge branches 'CategoryTheory.Category.KleisliCat' and 'Data.List.Ba…
semorrison Dec 19, 2022
39ed22f
merge
semorrison Dec 19, 2022
a689767
takeD section
thorimur Dec 19, 2022
ef8186a
Merge remote-tracking branch 'origin' into Data.List.Basic
thorimur Dec 20, 2022
19d4809
`takeI` section + import Data.List.Defs
thorimur Dec 20, 2022
ad28be0
`foldrRecOn`, `foldlRecOn`
thorimur Dec 20, 2022
c713b6d
.
thorimur Dec 20, 2022
6bd99ab
.
thorimur Dec 20, 2022
efc832d
change mem_cons_iff to mem_cons
jcommelin Dec 20, 2022
001383d
fix scanr_cons
jcommelin Dec 20, 2022
d450b86
minifix
jcommelin Dec 20, 2022
3f8fc15
Merge branch 'master' into Data.List.Basic
jcommelin Dec 20, 2022
59e6c45
fixed lines 1-2900 + renames for the rest
digama0 Dec 20, 2022
eebffdc
minifixes
jcommelin Dec 20, 2022
1fcb9a5
2900 - 2970
thorimur Dec 20, 2022
63584b4
section FoldlMFoldrM
thorimur Dec 20, 2022
746a1be
rewrote splitAt_eq_take_drop
thorimur Dec 21, 2022
a0fa011
.
thorimur Dec 21, 2022
c6c9def
splitOn* renames
thorimur Dec 21, 2022
5d50e0c
minifixes
jcommelin Dec 21, 2022
47e0382
minifix
jcommelin Dec 21, 2022
a0dd80d
work on pmap
ChrisHughes24 Dec 21, 2022
adda42d
small fixes
ChrisHughes24 Dec 21, 2022
d05d556
one more lemma fix
ChrisHughes24 Dec 21, 2022
d17cd39
fix find lemmas
ChrisHughes24 Dec 21, 2022
3725f20
a few fixes
ChrisHughes24 Dec 21, 2022
b97c979
`splitOnP` progress: wrote `splitOnP.go` theorems
thorimur Dec 22, 2022
7f5b6e1
fix some filterMap lemmas
ChrisHughes24 Dec 22, 2022
e686194
fix filterMap section
ChrisHughes24 Dec 22, 2022
6fba3ba
reduceOption section
ChrisHughes24 Dec 22, 2022
1e57c75
more fixes
ChrisHughes24 Dec 22, 2022
bdc94ce
fix one proof
ChrisHughes24 Dec 22, 2022
3ab97e3
prove get_attach
ChrisHughes24 Dec 22, 2022
b20e3c2
more fixes
ChrisHughes24 Dec 22, 2022
4eca2d9
fix mem_filter_of_mem
ChrisHughes24 Dec 22, 2022
fb04cd0
fix intercalate_splitOn
rwbarton Dec 22, 2022
cda6a3b
fix splitOn_intercalate
rwbarton Dec 22, 2022
be3c9b3
remove redundant List.mem_filter
rwbarton Dec 22, 2022
669fe70
fix Sublist.filter
rwbarton Dec 22, 2022
2911cb8
fix monotone_filter_right
rwbarton Dec 22, 2022
fe01744
porting note about replicate
rwbarton Dec 22, 2022
df9f5e3
formulate map_filter_eq_foldr in terms of Bool not Prop
rwbarton Dec 22, 2022
30d19ab
Boolify decidable Props
rwbarton Dec 22, 2022
6195f7d
Boolify decidable Props 2
rwbarton Dec 22, 2022
c507199
map₂Left stuff
rwbarton Dec 22, 2022
39a81cb
naming
rwbarton Dec 22, 2022
45957b7
fix map₂Right'_cons_cons
rwbarton Dec 22, 2022
9745593
dropWhile_nth_le_zero_not, takeWhile_eq_nil_iff
rwbarton Dec 22, 2022
673a211
naming
rwbarton Dec 22, 2022
8f9730c
takeWhile_eq_self_iff
rwbarton Dec 22, 2022
9af4aba
diff_cons, cons_diff
rwbarton Dec 22, 2022
f13115f
dropSlice_eq
rwbarton Dec 22, 2022
f848854
span_eq_take_drop
rwbarton Dec 22, 2022
8ee35f6
splitOn progress
thorimur Dec 22, 2022
93446fc
splitOnP progress
thorimur Dec 22, 2022
ac24498
finish splitOnP
thorimur Dec 22, 2022
df0354d
`lookmap` `go`-wrangling
thorimur Dec 22, 2022
4233bc8
.
thorimur Dec 22, 2022
ba2da10
minifix (incl. `eraseP` align in `Defs`)
thorimur Dec 22, 2022
71e000c
some fixes
thorimur Dec 24, 2022
7dcf0b5
fixes
thorimur Dec 24, 2022
80f36e8
fixes
thorimur Dec 24, 2022
d952346
finish getD section
thorimur Dec 24, 2022
00da516
fixing
thorimur Dec 24, 2022
69e9a23
get_attach
thorimur Dec 24, 2022
1efb40a
`sizeOf_dropSlice_lt`
thorimur Dec 24, 2022
e18b03d
.
thorimur Dec 24, 2022
fc61ce0
Merge branch 'master' into Data.List.Basic
Ruben-VandeVelde Dec 24, 2022
e83d4b1
Fix Init.Data.List.Lemmas
Ruben-VandeVelde Dec 24, 2022
a397c2d
Fix Init.Data.List.Lemmas warning
Ruben-VandeVelde Dec 24, 2022
8fdb72f
Fix Vector
Ruben-VandeVelde Dec 24, 2022
f403651
Remove duplicate alignment
Ruben-VandeVelde Dec 24, 2022
16a83a0
alias/#align
rwbarton Dec 24, 2022
9383399
avoid nonterminal simps
rwbarton Dec 24, 2022
03cd84d
#noalign toChunks stuff
rwbarton Dec 24, 2022
05f5966
minor changes
rwbarton Dec 24, 2022
0b10c78
minor edits
rwbarton Dec 24, 2022
6cf2359
minor fixes
rwbarton Dec 24, 2022
5f612f1
delete trailing junk
rwbarton Dec 24, 2022
69499cf
remove dubious translation comments
rwbarton Dec 24, 2022
7babc06
long lines
rwbarton Dec 24, 2022
f2a6df0
Merge remote-tracking branch 'origin/master' into Data.List.Basic
rwbarton Dec 24, 2022
37b5d84
Data.List.Card: avoid simp
rwbarton Dec 24, 2022
8fe63d2
fix Mathlib.Testing.SlimCheck.Testable
rwbarton Dec 24, 2022
3948c6b
fix Mathlib.Data.Stream.Init
rwbarton Dec 24, 2022
9b1962a
remove duplicate length_repeat
rwbarton Dec 24, 2022
c2bd1c4
some linting
jcommelin Dec 26, 2022
38fe7cc
more linting
jcommelin Dec 26, 2022
1d9cf7f
more linting
jcommelin Dec 26, 2022
0e61a16
fix docBlame
riccardobrasca Dec 28, 2022
542d2f7
linter
riccardobrasca Dec 28, 2022
265ad70
Fix misplacement of 'by'
qawbecrdtey Jan 4, 2023
19d2553
remove #lint
qawbecrdtey Jan 4, 2023
41d395b
wip
rwbarton Jan 4, 2023
436eda0
revert @[simp] removals
rwbarton Jan 4, 2023
e2c3d02
fix most linter errors
rwbarton Jan 4, 2023
e0354f5
Merge branch 'master' into Data.List.Basic
digama0 Jan 5, 2023
a24f94b
fix: linter warnings
digama0 Jan 5, 2023
3df163a
remove confirm? in comment
ChrisHughes24 Jan 5, 2023
9aa9ef4
delete mathport name comments
ChrisHughes24 Jan 5, 2023
067fa73
delete #lint
ChrisHughes24 Jan 5, 2023
264bce4
move map_eq_bind
ChrisHughes24 Jan 5, 2023
314c6c8
delete map_eq_bind from List.Basic
ChrisHughes24 Jan 5, 2023
1cd06e3
fix two FIXMEs about deprecated linter
jcommelin Jan 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5,038 changes: 4,865 additions & 173 deletions Mathlib/Data/List/Basic.lean

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions Mathlib/Data/List/Card.lean
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ theorem card_subset_le : ∀ {as bs : List α}, as ⊆ bs → card as ≤ card b
simp [h', card_subset_le hsub']
| inr h' =>
have : a ∈ bs := hsub (Mem.head ..)
simp [h', card_remove_of_mem this]
rw [card_cons_of_not_mem h', card_remove_of_mem this]
apply Nat.add_le_add_right
apply card_subset_le
intro x xmem
Expand All @@ -140,10 +140,12 @@ theorem card_map_le (f : α → β) (as : List α) : card (as.map f) ≤ card as
| nil => simp
| cons a as ih =>
cases Decidable.em (f a ∈ map f as) with
| inl h => simp [h]; apply Nat.le_trans ih (card_le_card_cons ..)
| inl h =>
rw [map, card_cons_of_mem h]
apply Nat.le_trans ih (card_le_card_cons ..)
| inr h =>
have : a ∉ as := fun h'' ↦ h (mem_map_of_mem _ h'')
simp [h, this]
rw [map, card_cons_of_not_mem h, card_cons_of_not_mem this]
exact Nat.add_le_add_right ih _

theorem card_map_eq_of_inj_on {f : α → β} {as : List α} :
Expand All @@ -159,12 +161,12 @@ theorem card_map_eq_of_inj_on {f : α → β} {as : List α} :
have : a = x := inj_on' (mem_cons_self ..) (mem_cons_of_mem _ hx.1) hx.2
have h1 : a ∈ as := this ▸ hx.1
have h2 : inj_on f as := inj_on_of_subset inj_on' (subset_cons _ _)
simp [h1, mem_map_of_mem f h1, ih h2]
rw [map, card_cons_of_mem h, ih h2, card_cons_of_mem h1]
| inr h =>
intro inj_on'
have h1 : a ∉ as := fun h'' ↦ h (mem_map_of_mem _ h'')
have h2 : inj_on f as := inj_on_of_subset inj_on' (subset_cons _ _)
simp [h, h1, ih h2]
rw [map, card_cons_of_not_mem h, card_cons_of_not_mem h1, ih h2]

theorem card_eq_of_equiv {as bs : List α} (h : as.equiv bs) : card as = card bs :=
let sub_and_sub := equiv_iff_subset_and_subset.1 h
Expand Down
10 changes: 4 additions & 6 deletions Mathlib/Data/List/Defs.lean
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,7 @@ def permutations' : List α → List (List α)

end Permutations

/-- `erasep p l` removes the first element of `l` satisfying the predicate `p`. -/
def erasep (p : α → Prop) [DecidablePred p] : List α → List α
| [] => []
| a :: l => if p a then l else a :: erasep p l
#align list.erasep List.erasep
#align list.erasep List.erasePₓ -- prop -> bool

/-- `extractp p l` returns a pair of an element `a` of `l` satisfying the predicate
`p`, and `l`, with `a` removed. If there is no such element `a` it returns `(none, l)`. -/
Expand Down Expand Up @@ -409,8 +405,10 @@ def destutter (R : α → α → Prop) [DecidableRel R] : List α → List α

#align list.range' List.range'
#align list.reduce_option List.reduceOption
-- Porting note: replace ilast' by getLastD
#align list.ilast' List.ilast'
#align list.last' List.last'
-- Porting note: remove last' from Std
#align list.last' List.getLast?
#align list.rotate List.rotate
#align list.rotate' List.rotate'

Expand Down
5 changes: 5 additions & 0 deletions Mathlib/Data/Option/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ theorem joinM_eq_join : joinM = @join α :=
theorem bind_eq_bind {α β : Type _} {f : α → Option β} {x : Option α} : x >>= f = x.bind f :=
rfl

--Porting note: New lemma used to prove a theorem in Data.List.Basic
theorem map_eq_bind (f : α → β) (o : Option α) :
Option.map f o = Option.bind o (some ∘ f) := by
cases o <;> rfl

theorem map_coe {α β} {a : α} {f : α → β} : f <$> (a : Option α) = ↑(f a) :=
rfl

Expand Down
10 changes: 5 additions & 5 deletions Mathlib/Data/Stream/Init.lean
Original file line number Diff line number Diff line change
Expand Up @@ -565,12 +565,12 @@ theorem length_take (n : ℕ) (s : Stream' α) : (take n s).length = n := by
induction n generalizing s <;> simp [*]
#align stream.length_take Stream'.length_take

theorem nth_take_succ : ∀ (n : Nat) (s : Stream' α),
List.nth (take (succ n) s) n = some (nth s n)
theorem get?_take_succ : ∀ (n : Nat) (s : Stream' α),
List.get? (take (succ n) s) n = some (nth s n)
| 0, s => rfl
| n + 1, s => by
rw [take_succ, add_one, List.nth, nth_take_succ n]; rfl
#align stream.nth_take_succ Stream'.nth_take_succ
rw [take_succ, add_one, List.get?, get?_take_succ n]; rfl
#align stream.nth_take_succ Stream'.get?_take_succ

theorem append_take_drop : ∀ (n : Nat) (s : Stream' α),
appendStream' (take n s) (drop n s) = s := by
Expand All @@ -591,7 +591,7 @@ theorem take_theorem (s₁ s₂ : Stream' α) : (∀ n : Nat, take n s₁ = take
simp [take] at aux
exact aux
· have h₁ : some (nth s₁ (succ n)) = some (nth s₂ (succ n)) := by
rw [← nth_take_succ, ← nth_take_succ, h (succ (succ n))]
rw [← get?_take_succ, ← get?_take_succ, h (succ (succ n))]
injection h₁
#align stream.take_theorem Stream'.take_theorem

Expand Down
4 changes: 2 additions & 2 deletions Mathlib/Data/Vector.lean
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ theorem map_cons (f : α → β) (a : α) : ∀ v : Vector α n, map f (cons a v

/-- Mapping two vectors under a curried function of two variables. -/
def map₂ (f : α → β → φ) : Vector α n → Vector β n → Vector φ n
| ⟨x, _⟩, ⟨y, _⟩ => ⟨List.map₂ f x y, by simp [*]⟩
| ⟨x, _⟩, ⟨y, _⟩ => ⟨List.zipWith f x y, by simp [*]⟩
#align vector.map₂ Vector.map₂

/-- Vector obtained by repeating an element. -/
def «repeat» (a : α) (n : ℕ) : Vector α n :=
⟨List.repeat a n, List.length_repeat a n
⟨List.replicate n a, List.length_replicate n a
#align vector.repeat Vector.repeat

/-- Drop `i` elements from a vector of length `n`; we can have `i > n`. -/
Expand Down
94 changes: 25 additions & 69 deletions Mathlib/Init/Data/List/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -22,107 +22,63 @@ namespace List

open Option Nat

/-- Optionally return nth element of a list. -/
@[simp]
def nth : List α → ℕ → Option α
| [], _ => none
| a :: _, 0 => some a
| _ :: l, n + 1 => nth l n
#align list.nth List.nth
#align list.nth List.get?

/-- nth element of a list `l` given `n < l.length`. -/
def nthLe : ∀ (l : List α) (n), n < l.length → α
| [], n, h => absurd h n.not_lt_zero
| a :: _, 0, _ => a
| _ :: l, n + 1, h => nthLe l n (le_of_succ_le_succ h)
@[deprecated get]
def nthLe (l : List α) (n) (h : n < l.length) : α := get l ⟨n, h⟩
#align list.nth_le List.nthLe

set_option linter.deprecated false in
@[deprecated]
theorem nthLe_eq (l : List α) (n) (h : n < l.length) : nthLe l n h = get l ⟨n, h⟩ := rfl

/-- The head of a list, or the default element of the type is the list is `nil`. -/
@[simp] def headI [Inhabited α] : List α → α
| [] => default
| (a :: _) => a
#align list.head List.headI

/-- Mapping a pair of lists under a curried function of two variables. -/
@[simp]
def map₂ (f : α → β → γ) : List α → List β → List γ
| [], _ => []
| _, [] => []
| x :: xs, y :: ys => f x y :: map₂ f xs ys

/-- Auxiliary function for `mapWithIndex`. -/
def mapWithIndexCore (f : ℕ → α → β) : ℕ → List α → List β
| _, [] => []
| k, a :: as => f k a :: mapWithIndexCore f (k + 1) as
#align list.map_with_index_core List.mapWithIndexCore

/-- Given a function `f : ℕ → α → β` and `as : List α`, `as = [a₀, a₁, ...]`, returns the list
`[f 0 a₀, f 1 a₁, ...]`. -/
def mapWithIndex (f : ℕ → α → β) (as : List α) : List β :=
mapWithIndexCore f 0 as
#align list.map_with_index List.mapWithIndex
#align list.map₂ List.zipWith

#noalign list.map_with_index_core

#align list.map_with_index List.mapIdx

/-- Find index of element with given property. -/
def findIndex (p : α → Prop) [DecidablePred p] : List α → ℕ
| [] => 0
| a :: l => if p a then 0 else succ (findIndex p l)
@[deprecated findIdx]
def findIndex (p : α → Prop) [DecidablePred p] : List α → ℕ := List.findIdx p
#align list.find_index List.findIndex

/-- Update the nth element of a list. -/
def updateNth : List α → ℕ → α → List α
| _ :: xs, 0, a => a :: xs
| x :: xs, i + 1, a => x :: updateNth xs i a
| [], _, _ => []
#align list.update_nth List.updateNth
#align list.update_nth List.set

/-- Big or of a list of Booleans. -/
def bor (l : List Bool) : Bool :=
any l id
#align list.bor List.bor
#align list.bor List.or

/-- Big and of a list of Booleans. -/
def band (l : List Bool) : Bool :=
all l id
#align list.band List.band
#align list.band List.and

/-- List consisting of an element `a` repeated a specified number of times. -/
@[simp]
def «repeat» (a : α) : Nat → List α
| 0 => []
| succ n => a :: «repeat» a n
@[deprecated replicate, simp]
def «repeat» (a : α) (n : Nat) : List α := List.replicate n a
#align list.repeat List.repeat

/-- The last element of a non-empty list. -/
def last : ∀ l : List α, l ≠ [] → α
| [], h => absurd rfl h
| [a], _ => a
| _ :: b :: l, _ => last (b :: l) fun h => List.noConfusion h
#align list.last List.last
#align list.last List.getLast

/-- The last element of a list, with the default if list empty -/
def ilast [Inhabited α] : List α → α
def getLastI [Inhabited α] : List α → α
| [] => default
| [a] => a
| [_, b] => b
| _ :: _ :: l => ilast l
#align list.ilast List.ilast
| _ :: _ :: l => getLastI l
#align list.ilast List.getLastI

/-- Initial segment of a list, i.e., with the last element dropped. -/
def init : List α → List α
| [] => []
| [_] => []
| a :: l => a :: init l
#align list.init List.init
#align list.init List.dropLast

/-- List with a single given element. -/
@[inline]
protected def ret {α : Type u} (a : α) : List α :=
[a]
@[inline] protected def ret {α : Type u} (a : α) : List α := [a]
#align list.ret List.ret

/-- `≤` implies not `>` for lists. -/
theorem le_eq_not_gt [LT α] : ∀ l₁ l₂ : List α, (l₁ ≤ l₂) = ¬l₂ < l₁ := fun _ _ => rfl
#align list.le_eq_not_gt List.le_eq_not_gt


end List
17 changes: 4 additions & 13 deletions Mathlib/Init/Data/List/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,11 @@ open List Nat

namespace List

/-- Length of the list obtained by `map₂` on a pair of lists
is the length of the shorter of the two. -/
@[simp]
theorem length_map₂ (f : α → β → γ) (l₁) : ∀ l₂, length (map₂ f l₁ l₂) =
min (length l₁) (length l₂) := by
induction l₁ <;> intro l₂ <;> cases l₂ <;>
simp [*, add_one, min_succ_succ, Nat.zero_min, Nat.min_zero]
#align list.length_map₂ List.length_map₂
#align list.length_map₂ List.length_zipWith

#align list.ball_nil List.forall_mem_nil
#align list.ball_cons List.forall_mem_consₓ -- explicit → implicit arguments

/-- Length of the list consisting of an element repeated `n` times is `n`. -/
@[simp]
theorem length_repeat (a : α) (n : ℕ) : length («repeat» a n) = n := by
induction n <;> simp [*]
#align list.length_repeat List.length_repeat

section MapAccumr

Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Testing/SlimCheck/Sampleable.lean
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def Fin.shrink {n : Nat} (m : Fin n.succ) :
let shrinks := Nat.shrink m.val
shrinks.map (λ x => { x with property := (by
simp_wf
exact Nat.succ_lt_succ $ lt_of_le_of_lt (Nat.mod_le _ _) x.property) })
exact lt_of_le_of_lt (Nat.mod_le _ _) x.property) })

instance Fin.shrinkable {n : Nat} : Shrinkable (Fin n.succ) where
shrink := Fin.shrink
Expand Down