Skip to content

Commit

Permalink
chore(data/list): move lemmas from data.list.basic that require algeb…
Browse files Browse the repository at this point in the history
…ra.group_power to a new file (#9728)

Hopefully ease the dependencies on anyone importing data.list.basic, if your code broke after this change adding `import data.list.prod_monoid` should fix it.

Lemmas moved:
- `list.prod_repeat`
- `list.sum_repeat`
- `list.prod_le_of_forall_le`
- `list.sum_le_of_forall_le`
  • Loading branch information
alexjbest committed Oct 15, 2021
1 parent 711aa75 commit ea22ce3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
20 changes: 0 additions & 20 deletions src/data/list/basic.lean
Expand Up @@ -5,7 +5,6 @@ Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, M
-/
import control.monad.basic
import data.nat.basic
import algebra.group_power.basic

/-!
# Basic properties of lists
Expand Down Expand Up @@ -2402,14 +2401,6 @@ theorem prod_cons : (a::l).prod = a * l.prod :=
calc (a::l).prod = foldl (*) (a * 1) l : by simp only [list.prod, foldl_cons, one_mul, mul_one]
... = _ : foldl_assoc

@[simp, priority 500, to_additive]
theorem prod_repeat (a : α) (n : ℕ) : (list.repeat a n).prod = a ^ n :=
begin
induction n with n ih,
{ rw pow_zero, refl },
{ rw [list.repeat_succ, list.prod_cons, ih, pow_succ] }
end

@[simp, to_additive]
theorem prod_append : (l₁ ++ l₂).prod = l₁.prod * l₂.prod :=
calc (l₁ ++ l₂).prod = foldl (*) (foldl (*) 1 l₁ * 1) l₂ : by simp [list.prod]
Expand Down Expand Up @@ -2693,17 +2684,6 @@ begin
exact lt_of_add_lt_add_left (lt_of_le_of_lt h $ add_lt_add_right (lt_of_not_ge h') _) }
end

@[to_additive]
lemma prod_le_of_forall_le [ordered_comm_monoid α] (l : list α) (n : α) (h : ∀ (x ∈ l), x ≤ n) :
l.prod ≤ n ^ l.length :=
begin
induction l with y l IH,
{ simp },
{ specialize IH (λ x hx, h x (mem_cons_of_mem _ hx)),
have hy : y ≤ n := h y (mem_cons_self _ _),
simpa [pow_succ] using mul_le_mul' hy IH }
end

-- Several lemmas about sum/head/tail for `list ℕ`.
-- These are hard to generalize well, as they rely on the fact that `default ℕ = 0`.

Expand Down
42 changes: 42 additions & 0 deletions src/data/list/prod_monoid.lean
@@ -0,0 +1,42 @@
/-
Copyright (c) 2021 Alex J. Best. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex J. Best
-/
import data.list.basic
import algebra.group_power.basic

/-!
# Products / sums of lists of terms of a monoid
This file provides basic results about `list.prod` (definition in `data.list.defs`) in a monoid.
It is in a separate file so that `data.list.basic` does not depend on `algebra.group_power.basic`.
-/

open nat

namespace list

universes u v
variables {α : Type u}

@[simp, priority 500, to_additive]
theorem prod_repeat [monoid α] (a : α) (n : ℕ) : (repeat a n).prod = a ^ n :=
begin
induction n with n ih,
{ rw pow_zero, refl },
{ rw [list.repeat_succ, list.prod_cons, ih, pow_succ] }
end

@[to_additive]
lemma prod_le_of_forall_le [ordered_comm_monoid α] (l : list α) (n : α) (h : ∀ (x ∈ l), x ≤ n) :
l.prod ≤ n ^ l.length :=
begin
induction l with y l IH,
{ simp },
{ specialize IH (λ x hx, h x (mem_cons_of_mem _ hx)),
have hy : y ≤ n := h y (mem_cons_self _ _),
simpa [pow_succ] using mul_le_mul' hy IH }
end

end list
1 change: 1 addition & 0 deletions src/data/multiset/basic.lean
Expand Up @@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.list.perm
import data.list.prod_monoid

/-!
# Multisets
Expand Down
1 change: 1 addition & 0 deletions test/lint_unused_haves_suffices.lean
@@ -1,5 +1,6 @@
import tactic.lint
import data.list.basic
import algebra.group_power.basic
open tactic

lemma test_a : true :=
Expand Down

0 comments on commit ea22ce3

Please sign in to comment.