Skip to content

Commit f4cd7f1

Browse files
committed
feat: Port Data.List.Lemmas (#1351)
1 parent f0c9939 commit f4cd7f1

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

Mathlib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ import Mathlib.Data.List.Card
237237
import Mathlib.Data.List.Chain
238238
import Mathlib.Data.List.Defs
239239
import Mathlib.Data.List.Func
240+
import Mathlib.Data.List.Lemmas
240241
import Mathlib.Data.List.Lex
241242
import Mathlib.Data.List.Nodup
242243
import Mathlib.Data.List.Pairwise

Mathlib/Data/List/Lemmas.lean

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/-
2+
Copyright (c) 2021 Yakov Pechersky. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Yakov Pechersky, Yury Kudryashov
5+
6+
! This file was ported from Lean 3 source module data.list.lemmas
7+
! leanprover-community/mathlib commit 6d0adfa76594f304b4650d098273d4366edeb61b
8+
! Please do not edit these lines, except to modify the commit id
9+
! if you have ported upstream changes.
10+
-/
11+
import Mathlib.Data.Set.Function
12+
import Mathlib.Data.List.Basic
13+
14+
/-! # Some lemmas about lists involving sets
15+
16+
Split out from `Data.List.Basic` to reduce its dependencies.
17+
-/
18+
19+
20+
open List
21+
22+
variable {α β : Type _}
23+
24+
namespace List
25+
26+
theorem range_map (f : α → β) : Set.range (map f) = { l | ∀ x ∈ l, x ∈ Set.range f } :=
27+
by
28+
refine'
29+
Set.Subset.antisymm
30+
(Set.range_subset_iff.2 fun l => forall_mem_map_iff.2 fun y _ => Set.mem_range_self _)
31+
fun l hl => _
32+
induction' l with a l ihl; · exact ⟨[], rfl⟩
33+
rcases ihl fun x hx => hl x <| subset_cons _ _ hx with ⟨l, rfl⟩
34+
rcases hl a (mem_cons_self _ _) with ⟨a, rfl⟩
35+
exact ⟨a :: l, map_cons _ _ _⟩
36+
#align list.range_map List.range_map
37+
38+
theorem range_map_coe (s : Set α) : Set.range (map ((↑) : s → α)) = { l | ∀ x ∈ l, x ∈ s } := by
39+
rw [range_map, Subtype.range_coe]
40+
#align list.range_map_coe List.range_map_coe
41+
42+
--Porting note: Waiting for `lift` tactic
43+
-- /-- If each element of a list can be lifted to some type, then the whole list can be
44+
-- lifted to this type. -/
45+
-- instance canLift (c) (p) [CanLift α β c p] :
46+
-- CanLift (List α) (List β) (List.map c) fun l => ∀ x ∈ l, p x
47+
-- where
48+
-- prf l H := by
49+
-- rw [← Set.mem_range, range_map]
50+
-- exact fun a ha => CanLift.prf a (H a ha)
51+
-- #align list.can_lift List.canLift
52+
53+
theorem injOn_insertNth_index_of_not_mem (l : List α) (x : α) (hx : x ∉ l) :
54+
Set.InjOn (fun k => insertNth k x l) { n | n ≤ l.length } := by
55+
induction' l with hd tl IH
56+
· intro n hn m hm _
57+
simp only [Set.mem_singleton_iff, Set.setOf_eq_eq_singleton,
58+
length, nonpos_iff_eq_zero] at hn hm
59+
simp [hn, hm]
60+
· intro n hn m hm h
61+
simp only [length, Set.mem_setOf_eq] at hn hm
62+
simp only [mem_cons, not_or] at hx
63+
cases n <;> cases m
64+
· rfl
65+
· simp [hx.left] at h
66+
· simp [Ne.symm hx.left] at h
67+
· simp only [true_and_iff, eq_self_iff_true, insertNth_succ_cons] at h
68+
rw [Nat.succ_inj']
69+
refine' IH hx.right _ _ (by injection h)
70+
· simpa [Nat.succ_le_succ_iff] using hn
71+
· simpa [Nat.succ_le_succ_iff] using hm
72+
#align list.inj_on_insert_nth_index_of_not_mem List.injOn_insertNth_index_of_not_mem
73+
74+
end List

0 commit comments

Comments
 (0)