Skip to content

Commit 1dba5d4

Browse files
committed
feat: List.product (#59)
1 parent 210fc85 commit 1dba5d4

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

Mathlib/Data/List/Basic.lean

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,4 +1117,15 @@ filter (fun a => a ∈ l₂) l₁
11171117
| nil => simp [List.inter, mem_filter]
11181118
| cons a l' ih => simp [List.inter, mem_filter, decide_eq_true_iff (x ∈ l₂)]
11191119

1120+
def product (l1 : List α) (l2 : List β) : List (α × β) :=
1121+
l1.bind (fun a => l2.map (Prod.mk a))
1122+
1123+
/--
1124+
List.prod satisfies a specification of cartesian product on lists.
1125+
-/
1126+
theorem product_spec (xs : List α) (ys : List β) (x : α) (y : β) : (x, y) ∈ product xs ys <-> (x ∈ xs ∧ y ∈ ys) := by
1127+
apply Iff.intro
1128+
case mp => simp only [List.product, and_imp, exists_prop, List.mem_map, Prod.mk.injEq, exists_eq_right_right', List.mem_bind]; exact And.intro
1129+
case mpr => simp only [product, mem_bind, mem_map, Prod.mk.injEq, exists_eq_right_right', exists_prop]; exact id
1130+
11201131
end List

Mathlib/Logic/Basic.lean

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,17 @@ theorem xor_comm (a b) : xor a b = xor b a := by simp [xor, and_comm, or_comm]
231231

232232
/-! ### Declarations about `and` -/
233233

234+
theorem and_symm_right (a b : α) (p : Prop) : p ∧ a = b <-> p ∧ b = a :=
235+
Iff.intro
236+
(fun ⟨hp, a_eq_b⟩ => ⟨hp, a_eq_b.symm⟩)
237+
(fun ⟨hp, b_eq_a⟩ => ⟨hp, b_eq_a.symm⟩)
238+
239+
theorem and_symm_left (a b : α) (p : Prop) : a = b ∧ p <-> b = a ∧ p :=
240+
Iff.intro
241+
(fun ⟨a_eq_b, hp⟩ => ⟨a_eq_b.symm, hp⟩)
242+
(fun ⟨b_eq_a, hp⟩ => ⟨b_eq_a.symm, hp⟩)
243+
244+
234245
theorem and_congr_left (h : c → (a ↔ b)) : a ∧ c ↔ b ∧ c :=
235246
And.comm.trans $ (and_congr_right h).trans And.comm
236247

@@ -689,6 +700,23 @@ by simp [And.comm]
689700
@[simp] theorem exists_eq_left' {p : α → Prop} {a' : α} : (∃ a, a' = a ∧ p a) ↔ p a' :=
690701
by simp [@eq_comm _ a']
691702

703+
@[simp] theorem exists_eq_right_right {α : Sort _} {p : α → Prop} {b : Prop} {a' : α} :
704+
(∃ (a : α), p a ∧ b ∧ a = a') ↔ p a' ∧ b :=
705+
Iff.intro
706+
(fun ⟨_, ⟨p_a, hb, a_eq_a'⟩⟩ => And.intro (a_eq_a' ▸ p_a) hb)
707+
(fun ⟨p_a', hb⟩ => Exists.intro a' ⟨p_a', hb, (rfl : a' = a')⟩)
708+
709+
@[simp] theorem exists_eq_right_right' {α : Sort _} {p : α → Prop} {b : Prop} {a' : α} :
710+
(∃ (a : α), p a ∧ b ∧ a' = a) ↔ p a' ∧ b :=
711+
Iff.intro
712+
(fun ⟨_, ⟨p_a, hb, a_eq_a'⟩⟩ => And.intro (a_eq_a' ▸ p_a) hb)
713+
(fun ⟨p_a', hb⟩ => Exists.intro a' ⟨p_a', hb, (rfl : a' = a')⟩)
714+
715+
716+
@[simp]
717+
theorem exists_prop {p q : Prop} : (∃ h : p, q) ↔ p ∧ q :=
718+
Iff.intro (fun ⟨hp, hq⟩ => And.intro hp hq) (fun ⟨hp, hq⟩ => Exists.intro hp hq)
719+
692720
@[simp] theorem exists_apply_eq_apply {α β : Type _} (f : α → β) (a' : α) : ∃ a, f a = f a' :=
693721
⟨a', rfl⟩
694722

0 commit comments

Comments
 (0)