state
stringlengths
0
159k
srcUpToTactic
stringlengths
387
167k
nextTactic
stringlengths
3
9k
declUpToTactic
stringlengths
22
11.5k
declId
stringlengths
38
95
decl
stringlengths
16
1.89k
file_tag
stringlengths
17
73
K : Type u_1 g : GeneralizedContinuedFraction K n : ℕ inst✝ : DivisionRing K gp : Pair K ppredB predB : K succ_nth_s_eq : Stream'.Seq.get? g.s (n + 1) = some gp nth_denom_eq : denominators g n = ppredB succ_nth_denom_eq : denominators g (n + 1) = predB ⊢ denominators g (n + 2) = gp.b * predB + gp.a * ppredB
/- Copyright (c) 2019 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann -/ import Mathlib.Algebra.ContinuedFractions.Translations #align_import algebra.continued_fractions.continuants_recurrence from "leanprover-community/mathlib"@"5f11361a98ae4acd77f5c1837686f6f0102cdc25" /-! # Recurrence Lemmas for the `continuants` Function of Continued Fractions. ## Summary Given a generalized continued fraction `g`, for all `n ≥ 1`, we prove that the `continuants` function indeed satisfies the following recurrences: - `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂`, and - `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ namespace GeneralizedContinuedFraction variable {K : Type*} {g : GeneralizedContinuedFraction K} {n : ℕ} [DivisionRing K] theorem continuantsAux_recurrence {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp) (nth_conts_aux_eq : g.continuantsAux n = ppred) (succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) : g.continuantsAux (n + 2) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by simp [*, continuantsAux, nextContinuants, nextDenominator, nextNumerator] #align generalized_continued_fraction.continuants_aux_recurrence GeneralizedContinuedFraction.continuantsAux_recurrence theorem continuants_recurrenceAux {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp) (nth_conts_aux_eq : g.continuantsAux n = ppred) (succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) : g.continuants (n + 1) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by simp [nth_cont_eq_succ_nth_cont_aux, continuantsAux_recurrence nth_s_eq nth_conts_aux_eq succ_nth_conts_aux_eq] #align generalized_continued_fraction.continuants_recurrence_aux GeneralizedContinuedFraction.continuants_recurrenceAux /-- Shows that `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂` and `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem continuants_recurrence {gp ppred pred : Pair K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_conts_eq : g.continuants n = ppred) (succ_nth_conts_eq : g.continuants (n + 1) = pred) : g.continuants (n + 2) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by rw [nth_cont_eq_succ_nth_cont_aux] at nth_conts_eq succ_nth_conts_eq exact continuants_recurrenceAux succ_nth_s_eq nth_conts_eq succ_nth_conts_eq #align generalized_continued_fraction.continuants_recurrence GeneralizedContinuedFraction.continuants_recurrence /-- Shows that `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂`. -/ theorem numerators_recurrence {gp : Pair K} {ppredA predA : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA) (succ_nth_num_eq : g.numerators (n + 1) = predA) : g.numerators (n + 2) = gp.b * predA + gp.a * ppredA := by obtain ⟨ppredConts, nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants n = conts ∧ conts.a = ppredA exact exists_conts_a_of_num nth_num_eq obtain ⟨predConts, succ_nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants (n + 1) = conts ∧ conts.a = predA exact exists_conts_a_of_num succ_nth_num_eq rw [num_eq_conts_a, continuants_recurrence succ_nth_s_eq nth_conts_eq succ_nth_conts_eq] #align generalized_continued_fraction.numerators_recurrence GeneralizedContinuedFraction.numerators_recurrence /-- Shows that `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem denominators_recurrence {gp : Pair K} {ppredB predB : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_denom_eq : g.denominators n = ppredB) (succ_nth_denom_eq : g.denominators (n + 1) = predB) : g.denominators (n + 2) = gp.b * predB + gp.a * ppredB := by
obtain ⟨ppredConts, nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants n = conts ∧ conts.b = ppredB
/-- Shows that `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem denominators_recurrence {gp : Pair K} {ppredB predB : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_denom_eq : g.denominators n = ppredB) (succ_nth_denom_eq : g.denominators (n + 1) = predB) : g.denominators (n + 2) = gp.b * predB + gp.a * ppredB := by
Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence.62_0.nOytPSFGrohRR6p
/-- Shows that `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem denominators_recurrence {gp : Pair K} {ppredB predB : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_denom_eq : g.denominators n = ppredB) (succ_nth_denom_eq : g.denominators (n + 1) = predB) : g.denominators (n + 2) = gp.b * predB + gp.a * ppredB
Mathlib_Algebra_ContinuedFractions_ContinuantsRecurrence
K : Type u_1 g : GeneralizedContinuedFraction K n : ℕ inst✝ : DivisionRing K gp : Pair K ppredB predB : K succ_nth_s_eq : Stream'.Seq.get? g.s (n + 1) = some gp nth_denom_eq : denominators g n = ppredB succ_nth_denom_eq : denominators g (n + 1) = predB ⊢ ∃ conts, continuants g n = conts ∧ conts.b = ppredB case intro.intro.refl K : Type u_1 g : GeneralizedContinuedFraction K n : ℕ inst✝ : DivisionRing K gp : Pair K predB : K succ_nth_s_eq : Stream'.Seq.get? g.s (n + 1) = some gp succ_nth_denom_eq : denominators g (n + 1) = predB ppredConts : Pair K nth_conts_eq : continuants g n = ppredConts nth_denom_eq : denominators g n = ppredConts.b ⊢ denominators g (n + 2) = gp.b * predB + gp.a * ppredConts.b
/- Copyright (c) 2019 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann -/ import Mathlib.Algebra.ContinuedFractions.Translations #align_import algebra.continued_fractions.continuants_recurrence from "leanprover-community/mathlib"@"5f11361a98ae4acd77f5c1837686f6f0102cdc25" /-! # Recurrence Lemmas for the `continuants` Function of Continued Fractions. ## Summary Given a generalized continued fraction `g`, for all `n ≥ 1`, we prove that the `continuants` function indeed satisfies the following recurrences: - `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂`, and - `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ namespace GeneralizedContinuedFraction variable {K : Type*} {g : GeneralizedContinuedFraction K} {n : ℕ} [DivisionRing K] theorem continuantsAux_recurrence {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp) (nth_conts_aux_eq : g.continuantsAux n = ppred) (succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) : g.continuantsAux (n + 2) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by simp [*, continuantsAux, nextContinuants, nextDenominator, nextNumerator] #align generalized_continued_fraction.continuants_aux_recurrence GeneralizedContinuedFraction.continuantsAux_recurrence theorem continuants_recurrenceAux {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp) (nth_conts_aux_eq : g.continuantsAux n = ppred) (succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) : g.continuants (n + 1) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by simp [nth_cont_eq_succ_nth_cont_aux, continuantsAux_recurrence nth_s_eq nth_conts_aux_eq succ_nth_conts_aux_eq] #align generalized_continued_fraction.continuants_recurrence_aux GeneralizedContinuedFraction.continuants_recurrenceAux /-- Shows that `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂` and `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem continuants_recurrence {gp ppred pred : Pair K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_conts_eq : g.continuants n = ppred) (succ_nth_conts_eq : g.continuants (n + 1) = pred) : g.continuants (n + 2) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by rw [nth_cont_eq_succ_nth_cont_aux] at nth_conts_eq succ_nth_conts_eq exact continuants_recurrenceAux succ_nth_s_eq nth_conts_eq succ_nth_conts_eq #align generalized_continued_fraction.continuants_recurrence GeneralizedContinuedFraction.continuants_recurrence /-- Shows that `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂`. -/ theorem numerators_recurrence {gp : Pair K} {ppredA predA : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA) (succ_nth_num_eq : g.numerators (n + 1) = predA) : g.numerators (n + 2) = gp.b * predA + gp.a * ppredA := by obtain ⟨ppredConts, nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants n = conts ∧ conts.a = ppredA exact exists_conts_a_of_num nth_num_eq obtain ⟨predConts, succ_nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants (n + 1) = conts ∧ conts.a = predA exact exists_conts_a_of_num succ_nth_num_eq rw [num_eq_conts_a, continuants_recurrence succ_nth_s_eq nth_conts_eq succ_nth_conts_eq] #align generalized_continued_fraction.numerators_recurrence GeneralizedContinuedFraction.numerators_recurrence /-- Shows that `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem denominators_recurrence {gp : Pair K} {ppredB predB : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_denom_eq : g.denominators n = ppredB) (succ_nth_denom_eq : g.denominators (n + 1) = predB) : g.denominators (n + 2) = gp.b * predB + gp.a * ppredB := by obtain ⟨ppredConts, nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants n = conts ∧ conts.b = ppredB
exact exists_conts_b_of_denom nth_denom_eq
/-- Shows that `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem denominators_recurrence {gp : Pair K} {ppredB predB : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_denom_eq : g.denominators n = ppredB) (succ_nth_denom_eq : g.denominators (n + 1) = predB) : g.denominators (n + 2) = gp.b * predB + gp.a * ppredB := by obtain ⟨ppredConts, nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants n = conts ∧ conts.b = ppredB
Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence.62_0.nOytPSFGrohRR6p
/-- Shows that `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem denominators_recurrence {gp : Pair K} {ppredB predB : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_denom_eq : g.denominators n = ppredB) (succ_nth_denom_eq : g.denominators (n + 1) = predB) : g.denominators (n + 2) = gp.b * predB + gp.a * ppredB
Mathlib_Algebra_ContinuedFractions_ContinuantsRecurrence
case intro.intro.refl K : Type u_1 g : GeneralizedContinuedFraction K n : ℕ inst✝ : DivisionRing K gp : Pair K predB : K succ_nth_s_eq : Stream'.Seq.get? g.s (n + 1) = some gp succ_nth_denom_eq : denominators g (n + 1) = predB ppredConts : Pair K nth_conts_eq : continuants g n = ppredConts nth_denom_eq : denominators g n = ppredConts.b ⊢ denominators g (n + 2) = gp.b * predB + gp.a * ppredConts.b
/- Copyright (c) 2019 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann -/ import Mathlib.Algebra.ContinuedFractions.Translations #align_import algebra.continued_fractions.continuants_recurrence from "leanprover-community/mathlib"@"5f11361a98ae4acd77f5c1837686f6f0102cdc25" /-! # Recurrence Lemmas for the `continuants` Function of Continued Fractions. ## Summary Given a generalized continued fraction `g`, for all `n ≥ 1`, we prove that the `continuants` function indeed satisfies the following recurrences: - `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂`, and - `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ namespace GeneralizedContinuedFraction variable {K : Type*} {g : GeneralizedContinuedFraction K} {n : ℕ} [DivisionRing K] theorem continuantsAux_recurrence {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp) (nth_conts_aux_eq : g.continuantsAux n = ppred) (succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) : g.continuantsAux (n + 2) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by simp [*, continuantsAux, nextContinuants, nextDenominator, nextNumerator] #align generalized_continued_fraction.continuants_aux_recurrence GeneralizedContinuedFraction.continuantsAux_recurrence theorem continuants_recurrenceAux {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp) (nth_conts_aux_eq : g.continuantsAux n = ppred) (succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) : g.continuants (n + 1) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by simp [nth_cont_eq_succ_nth_cont_aux, continuantsAux_recurrence nth_s_eq nth_conts_aux_eq succ_nth_conts_aux_eq] #align generalized_continued_fraction.continuants_recurrence_aux GeneralizedContinuedFraction.continuants_recurrenceAux /-- Shows that `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂` and `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem continuants_recurrence {gp ppred pred : Pair K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_conts_eq : g.continuants n = ppred) (succ_nth_conts_eq : g.continuants (n + 1) = pred) : g.continuants (n + 2) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by rw [nth_cont_eq_succ_nth_cont_aux] at nth_conts_eq succ_nth_conts_eq exact continuants_recurrenceAux succ_nth_s_eq nth_conts_eq succ_nth_conts_eq #align generalized_continued_fraction.continuants_recurrence GeneralizedContinuedFraction.continuants_recurrence /-- Shows that `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂`. -/ theorem numerators_recurrence {gp : Pair K} {ppredA predA : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA) (succ_nth_num_eq : g.numerators (n + 1) = predA) : g.numerators (n + 2) = gp.b * predA + gp.a * ppredA := by obtain ⟨ppredConts, nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants n = conts ∧ conts.a = ppredA exact exists_conts_a_of_num nth_num_eq obtain ⟨predConts, succ_nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants (n + 1) = conts ∧ conts.a = predA exact exists_conts_a_of_num succ_nth_num_eq rw [num_eq_conts_a, continuants_recurrence succ_nth_s_eq nth_conts_eq succ_nth_conts_eq] #align generalized_continued_fraction.numerators_recurrence GeneralizedContinuedFraction.numerators_recurrence /-- Shows that `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem denominators_recurrence {gp : Pair K} {ppredB predB : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_denom_eq : g.denominators n = ppredB) (succ_nth_denom_eq : g.denominators (n + 1) = predB) : g.denominators (n + 2) = gp.b * predB + gp.a * ppredB := by obtain ⟨ppredConts, nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants n = conts ∧ conts.b = ppredB exact exists_conts_b_of_denom nth_denom_eq
obtain ⟨predConts, succ_nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants (n + 1) = conts ∧ conts.b = predB
/-- Shows that `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem denominators_recurrence {gp : Pair K} {ppredB predB : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_denom_eq : g.denominators n = ppredB) (succ_nth_denom_eq : g.denominators (n + 1) = predB) : g.denominators (n + 2) = gp.b * predB + gp.a * ppredB := by obtain ⟨ppredConts, nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants n = conts ∧ conts.b = ppredB exact exists_conts_b_of_denom nth_denom_eq
Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence.62_0.nOytPSFGrohRR6p
/-- Shows that `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem denominators_recurrence {gp : Pair K} {ppredB predB : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_denom_eq : g.denominators n = ppredB) (succ_nth_denom_eq : g.denominators (n + 1) = predB) : g.denominators (n + 2) = gp.b * predB + gp.a * ppredB
Mathlib_Algebra_ContinuedFractions_ContinuantsRecurrence
K : Type u_1 g : GeneralizedContinuedFraction K n : ℕ inst✝ : DivisionRing K gp : Pair K predB : K succ_nth_s_eq : Stream'.Seq.get? g.s (n + 1) = some gp succ_nth_denom_eq : denominators g (n + 1) = predB ppredConts : Pair K nth_conts_eq : continuants g n = ppredConts nth_denom_eq : denominators g n = ppredConts.b ⊢ ∃ conts, continuants g (n + 1) = conts ∧ conts.b = predB case intro.intro.refl.intro.intro.refl K : Type u_1 g : GeneralizedContinuedFraction K n : ℕ inst✝ : DivisionRing K gp : Pair K succ_nth_s_eq : Stream'.Seq.get? g.s (n + 1) = some gp ppredConts : Pair K nth_conts_eq : continuants g n = ppredConts nth_denom_eq : denominators g n = ppredConts.b predConts : Pair K succ_nth_conts_eq : continuants g (n + 1) = predConts succ_nth_denom_eq : denominators g (n + 1) = predConts.b ⊢ denominators g (n + 2) = gp.b * predConts.b + gp.a * ppredConts.b
/- Copyright (c) 2019 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann -/ import Mathlib.Algebra.ContinuedFractions.Translations #align_import algebra.continued_fractions.continuants_recurrence from "leanprover-community/mathlib"@"5f11361a98ae4acd77f5c1837686f6f0102cdc25" /-! # Recurrence Lemmas for the `continuants` Function of Continued Fractions. ## Summary Given a generalized continued fraction `g`, for all `n ≥ 1`, we prove that the `continuants` function indeed satisfies the following recurrences: - `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂`, and - `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ namespace GeneralizedContinuedFraction variable {K : Type*} {g : GeneralizedContinuedFraction K} {n : ℕ} [DivisionRing K] theorem continuantsAux_recurrence {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp) (nth_conts_aux_eq : g.continuantsAux n = ppred) (succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) : g.continuantsAux (n + 2) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by simp [*, continuantsAux, nextContinuants, nextDenominator, nextNumerator] #align generalized_continued_fraction.continuants_aux_recurrence GeneralizedContinuedFraction.continuantsAux_recurrence theorem continuants_recurrenceAux {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp) (nth_conts_aux_eq : g.continuantsAux n = ppred) (succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) : g.continuants (n + 1) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by simp [nth_cont_eq_succ_nth_cont_aux, continuantsAux_recurrence nth_s_eq nth_conts_aux_eq succ_nth_conts_aux_eq] #align generalized_continued_fraction.continuants_recurrence_aux GeneralizedContinuedFraction.continuants_recurrenceAux /-- Shows that `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂` and `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem continuants_recurrence {gp ppred pred : Pair K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_conts_eq : g.continuants n = ppred) (succ_nth_conts_eq : g.continuants (n + 1) = pred) : g.continuants (n + 2) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by rw [nth_cont_eq_succ_nth_cont_aux] at nth_conts_eq succ_nth_conts_eq exact continuants_recurrenceAux succ_nth_s_eq nth_conts_eq succ_nth_conts_eq #align generalized_continued_fraction.continuants_recurrence GeneralizedContinuedFraction.continuants_recurrence /-- Shows that `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂`. -/ theorem numerators_recurrence {gp : Pair K} {ppredA predA : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA) (succ_nth_num_eq : g.numerators (n + 1) = predA) : g.numerators (n + 2) = gp.b * predA + gp.a * ppredA := by obtain ⟨ppredConts, nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants n = conts ∧ conts.a = ppredA exact exists_conts_a_of_num nth_num_eq obtain ⟨predConts, succ_nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants (n + 1) = conts ∧ conts.a = predA exact exists_conts_a_of_num succ_nth_num_eq rw [num_eq_conts_a, continuants_recurrence succ_nth_s_eq nth_conts_eq succ_nth_conts_eq] #align generalized_continued_fraction.numerators_recurrence GeneralizedContinuedFraction.numerators_recurrence /-- Shows that `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem denominators_recurrence {gp : Pair K} {ppredB predB : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_denom_eq : g.denominators n = ppredB) (succ_nth_denom_eq : g.denominators (n + 1) = predB) : g.denominators (n + 2) = gp.b * predB + gp.a * ppredB := by obtain ⟨ppredConts, nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants n = conts ∧ conts.b = ppredB exact exists_conts_b_of_denom nth_denom_eq obtain ⟨predConts, succ_nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants (n + 1) = conts ∧ conts.b = predB
exact exists_conts_b_of_denom succ_nth_denom_eq
/-- Shows that `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem denominators_recurrence {gp : Pair K} {ppredB predB : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_denom_eq : g.denominators n = ppredB) (succ_nth_denom_eq : g.denominators (n + 1) = predB) : g.denominators (n + 2) = gp.b * predB + gp.a * ppredB := by obtain ⟨ppredConts, nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants n = conts ∧ conts.b = ppredB exact exists_conts_b_of_denom nth_denom_eq obtain ⟨predConts, succ_nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants (n + 1) = conts ∧ conts.b = predB
Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence.62_0.nOytPSFGrohRR6p
/-- Shows that `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem denominators_recurrence {gp : Pair K} {ppredB predB : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_denom_eq : g.denominators n = ppredB) (succ_nth_denom_eq : g.denominators (n + 1) = predB) : g.denominators (n + 2) = gp.b * predB + gp.a * ppredB
Mathlib_Algebra_ContinuedFractions_ContinuantsRecurrence
case intro.intro.refl.intro.intro.refl K : Type u_1 g : GeneralizedContinuedFraction K n : ℕ inst✝ : DivisionRing K gp : Pair K succ_nth_s_eq : Stream'.Seq.get? g.s (n + 1) = some gp ppredConts : Pair K nth_conts_eq : continuants g n = ppredConts nth_denom_eq : denominators g n = ppredConts.b predConts : Pair K succ_nth_conts_eq : continuants g (n + 1) = predConts succ_nth_denom_eq : denominators g (n + 1) = predConts.b ⊢ denominators g (n + 2) = gp.b * predConts.b + gp.a * ppredConts.b
/- Copyright (c) 2019 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann -/ import Mathlib.Algebra.ContinuedFractions.Translations #align_import algebra.continued_fractions.continuants_recurrence from "leanprover-community/mathlib"@"5f11361a98ae4acd77f5c1837686f6f0102cdc25" /-! # Recurrence Lemmas for the `continuants` Function of Continued Fractions. ## Summary Given a generalized continued fraction `g`, for all `n ≥ 1`, we prove that the `continuants` function indeed satisfies the following recurrences: - `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂`, and - `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ namespace GeneralizedContinuedFraction variable {K : Type*} {g : GeneralizedContinuedFraction K} {n : ℕ} [DivisionRing K] theorem continuantsAux_recurrence {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp) (nth_conts_aux_eq : g.continuantsAux n = ppred) (succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) : g.continuantsAux (n + 2) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by simp [*, continuantsAux, nextContinuants, nextDenominator, nextNumerator] #align generalized_continued_fraction.continuants_aux_recurrence GeneralizedContinuedFraction.continuantsAux_recurrence theorem continuants_recurrenceAux {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp) (nth_conts_aux_eq : g.continuantsAux n = ppred) (succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) : g.continuants (n + 1) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by simp [nth_cont_eq_succ_nth_cont_aux, continuantsAux_recurrence nth_s_eq nth_conts_aux_eq succ_nth_conts_aux_eq] #align generalized_continued_fraction.continuants_recurrence_aux GeneralizedContinuedFraction.continuants_recurrenceAux /-- Shows that `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂` and `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem continuants_recurrence {gp ppred pred : Pair K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_conts_eq : g.continuants n = ppred) (succ_nth_conts_eq : g.continuants (n + 1) = pred) : g.continuants (n + 2) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by rw [nth_cont_eq_succ_nth_cont_aux] at nth_conts_eq succ_nth_conts_eq exact continuants_recurrenceAux succ_nth_s_eq nth_conts_eq succ_nth_conts_eq #align generalized_continued_fraction.continuants_recurrence GeneralizedContinuedFraction.continuants_recurrence /-- Shows that `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂`. -/ theorem numerators_recurrence {gp : Pair K} {ppredA predA : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA) (succ_nth_num_eq : g.numerators (n + 1) = predA) : g.numerators (n + 2) = gp.b * predA + gp.a * ppredA := by obtain ⟨ppredConts, nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants n = conts ∧ conts.a = ppredA exact exists_conts_a_of_num nth_num_eq obtain ⟨predConts, succ_nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants (n + 1) = conts ∧ conts.a = predA exact exists_conts_a_of_num succ_nth_num_eq rw [num_eq_conts_a, continuants_recurrence succ_nth_s_eq nth_conts_eq succ_nth_conts_eq] #align generalized_continued_fraction.numerators_recurrence GeneralizedContinuedFraction.numerators_recurrence /-- Shows that `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem denominators_recurrence {gp : Pair K} {ppredB predB : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_denom_eq : g.denominators n = ppredB) (succ_nth_denom_eq : g.denominators (n + 1) = predB) : g.denominators (n + 2) = gp.b * predB + gp.a * ppredB := by obtain ⟨ppredConts, nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants n = conts ∧ conts.b = ppredB exact exists_conts_b_of_denom nth_denom_eq obtain ⟨predConts, succ_nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants (n + 1) = conts ∧ conts.b = predB exact exists_conts_b_of_denom succ_nth_denom_eq
rw [denom_eq_conts_b, continuants_recurrence succ_nth_s_eq nth_conts_eq succ_nth_conts_eq]
/-- Shows that `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem denominators_recurrence {gp : Pair K} {ppredB predB : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_denom_eq : g.denominators n = ppredB) (succ_nth_denom_eq : g.denominators (n + 1) = predB) : g.denominators (n + 2) = gp.b * predB + gp.a * ppredB := by obtain ⟨ppredConts, nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants n = conts ∧ conts.b = ppredB exact exists_conts_b_of_denom nth_denom_eq obtain ⟨predConts, succ_nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.continuants (n + 1) = conts ∧ conts.b = predB exact exists_conts_b_of_denom succ_nth_denom_eq
Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence.62_0.nOytPSFGrohRR6p
/-- Shows that `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem denominators_recurrence {gp : Pair K} {ppredB predB : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_denom_eq : g.denominators n = ppredB) (succ_nth_denom_eq : g.denominators (n + 1) = predB) : g.denominators (n + 2) = gp.b * predB + gp.a * ppredB
Mathlib_Algebra_ContinuedFractions_ContinuantsRecurrence
p : ℝ[X] ⊢ Tendsto (fun x => eval x p / rexp x) atTop (𝓝 0)
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.SpecialFunctions.Exp import Mathlib.Data.Polynomial.Eval /-! # Limits of `P(x) / e ^ x` for a polynomial `P` In this file we prove that $\lim_{x\to\infty}\frac{P(x)}{e^x}=0$ for any polynomial `P`. ## TODO Add more similar lemmas: limit at `-∞`, versions with $e^{cx}$ etc. ## Keywords polynomial, limit, exponential -/ open Filter Topology Real namespace Polynomial theorem tendsto_div_exp_atTop (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x / exp x) atTop (𝓝 0) := by
induction p using Polynomial.induction_on' with | h_monomial n c => simpa [exp_neg, div_eq_mul_inv, mul_assoc] using tendsto_const_nhds.mul (tendsto_pow_mul_exp_neg_atTop_nhds_0 n) | h_add p q hp hq => simpa [add_div] using hp.add hq
theorem tendsto_div_exp_atTop (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x / exp x) atTop (𝓝 0) := by
Mathlib.Analysis.SpecialFunctions.PolynomialExp.27_0.0J48LYNgQ4iVYMM
theorem tendsto_div_exp_atTop (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x / exp x) atTop (𝓝 0)
Mathlib_Analysis_SpecialFunctions_PolynomialExp
p : ℝ[X] ⊢ Tendsto (fun x => eval x p / rexp x) atTop (𝓝 0)
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.SpecialFunctions.Exp import Mathlib.Data.Polynomial.Eval /-! # Limits of `P(x) / e ^ x` for a polynomial `P` In this file we prove that $\lim_{x\to\infty}\frac{P(x)}{e^x}=0$ for any polynomial `P`. ## TODO Add more similar lemmas: limit at `-∞`, versions with $e^{cx}$ etc. ## Keywords polynomial, limit, exponential -/ open Filter Topology Real namespace Polynomial theorem tendsto_div_exp_atTop (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x / exp x) atTop (𝓝 0) := by
induction p using Polynomial.induction_on' with | h_monomial n c => simpa [exp_neg, div_eq_mul_inv, mul_assoc] using tendsto_const_nhds.mul (tendsto_pow_mul_exp_neg_atTop_nhds_0 n) | h_add p q hp hq => simpa [add_div] using hp.add hq
theorem tendsto_div_exp_atTop (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x / exp x) atTop (𝓝 0) := by
Mathlib.Analysis.SpecialFunctions.PolynomialExp.27_0.0J48LYNgQ4iVYMM
theorem tendsto_div_exp_atTop (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x / exp x) atTop (𝓝 0)
Mathlib_Analysis_SpecialFunctions_PolynomialExp
case h_monomial n : ℕ c : ℝ ⊢ Tendsto (fun x => eval x ((monomial n) c) / rexp x) atTop (𝓝 0)
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.SpecialFunctions.Exp import Mathlib.Data.Polynomial.Eval /-! # Limits of `P(x) / e ^ x` for a polynomial `P` In this file we prove that $\lim_{x\to\infty}\frac{P(x)}{e^x}=0$ for any polynomial `P`. ## TODO Add more similar lemmas: limit at `-∞`, versions with $e^{cx}$ etc. ## Keywords polynomial, limit, exponential -/ open Filter Topology Real namespace Polynomial theorem tendsto_div_exp_atTop (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x / exp x) atTop (𝓝 0) := by induction p using Polynomial.induction_on' with
| h_monomial n c => simpa [exp_neg, div_eq_mul_inv, mul_assoc] using tendsto_const_nhds.mul (tendsto_pow_mul_exp_neg_atTop_nhds_0 n)
theorem tendsto_div_exp_atTop (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x / exp x) atTop (𝓝 0) := by induction p using Polynomial.induction_on' with
Mathlib.Analysis.SpecialFunctions.PolynomialExp.27_0.0J48LYNgQ4iVYMM
theorem tendsto_div_exp_atTop (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x / exp x) atTop (𝓝 0)
Mathlib_Analysis_SpecialFunctions_PolynomialExp
case h_monomial n : ℕ c : ℝ ⊢ Tendsto (fun x => eval x ((monomial n) c) / rexp x) atTop (𝓝 0)
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.SpecialFunctions.Exp import Mathlib.Data.Polynomial.Eval /-! # Limits of `P(x) / e ^ x` for a polynomial `P` In this file we prove that $\lim_{x\to\infty}\frac{P(x)}{e^x}=0$ for any polynomial `P`. ## TODO Add more similar lemmas: limit at `-∞`, versions with $e^{cx}$ etc. ## Keywords polynomial, limit, exponential -/ open Filter Topology Real namespace Polynomial theorem tendsto_div_exp_atTop (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x / exp x) atTop (𝓝 0) := by induction p using Polynomial.induction_on' with | h_monomial n c =>
simpa [exp_neg, div_eq_mul_inv, mul_assoc] using tendsto_const_nhds.mul (tendsto_pow_mul_exp_neg_atTop_nhds_0 n)
theorem tendsto_div_exp_atTop (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x / exp x) atTop (𝓝 0) := by induction p using Polynomial.induction_on' with | h_monomial n c =>
Mathlib.Analysis.SpecialFunctions.PolynomialExp.27_0.0J48LYNgQ4iVYMM
theorem tendsto_div_exp_atTop (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x / exp x) atTop (𝓝 0)
Mathlib_Analysis_SpecialFunctions_PolynomialExp
case h_add p q : ℝ[X] hp : Tendsto (fun x => eval x p / rexp x) atTop (𝓝 0) hq : Tendsto (fun x => eval x q / rexp x) atTop (𝓝 0) ⊢ Tendsto (fun x => eval x (p + q) / rexp x) atTop (𝓝 0)
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.SpecialFunctions.Exp import Mathlib.Data.Polynomial.Eval /-! # Limits of `P(x) / e ^ x` for a polynomial `P` In this file we prove that $\lim_{x\to\infty}\frac{P(x)}{e^x}=0$ for any polynomial `P`. ## TODO Add more similar lemmas: limit at `-∞`, versions with $e^{cx}$ etc. ## Keywords polynomial, limit, exponential -/ open Filter Topology Real namespace Polynomial theorem tendsto_div_exp_atTop (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x / exp x) atTop (𝓝 0) := by induction p using Polynomial.induction_on' with | h_monomial n c => simpa [exp_neg, div_eq_mul_inv, mul_assoc] using tendsto_const_nhds.mul (tendsto_pow_mul_exp_neg_atTop_nhds_0 n)
| h_add p q hp hq => simpa [add_div] using hp.add hq
theorem tendsto_div_exp_atTop (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x / exp x) atTop (𝓝 0) := by induction p using Polynomial.induction_on' with | h_monomial n c => simpa [exp_neg, div_eq_mul_inv, mul_assoc] using tendsto_const_nhds.mul (tendsto_pow_mul_exp_neg_atTop_nhds_0 n)
Mathlib.Analysis.SpecialFunctions.PolynomialExp.27_0.0J48LYNgQ4iVYMM
theorem tendsto_div_exp_atTop (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x / exp x) atTop (𝓝 0)
Mathlib_Analysis_SpecialFunctions_PolynomialExp
case h_add p q : ℝ[X] hp : Tendsto (fun x => eval x p / rexp x) atTop (𝓝 0) hq : Tendsto (fun x => eval x q / rexp x) atTop (𝓝 0) ⊢ Tendsto (fun x => eval x (p + q) / rexp x) atTop (𝓝 0)
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.SpecialFunctions.Exp import Mathlib.Data.Polynomial.Eval /-! # Limits of `P(x) / e ^ x` for a polynomial `P` In this file we prove that $\lim_{x\to\infty}\frac{P(x)}{e^x}=0$ for any polynomial `P`. ## TODO Add more similar lemmas: limit at `-∞`, versions with $e^{cx}$ etc. ## Keywords polynomial, limit, exponential -/ open Filter Topology Real namespace Polynomial theorem tendsto_div_exp_atTop (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x / exp x) atTop (𝓝 0) := by induction p using Polynomial.induction_on' with | h_monomial n c => simpa [exp_neg, div_eq_mul_inv, mul_assoc] using tendsto_const_nhds.mul (tendsto_pow_mul_exp_neg_atTop_nhds_0 n) | h_add p q hp hq =>
simpa [add_div] using hp.add hq
theorem tendsto_div_exp_atTop (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x / exp x) atTop (𝓝 0) := by induction p using Polynomial.induction_on' with | h_monomial n c => simpa [exp_neg, div_eq_mul_inv, mul_assoc] using tendsto_const_nhds.mul (tendsto_pow_mul_exp_neg_atTop_nhds_0 n) | h_add p q hp hq =>
Mathlib.Analysis.SpecialFunctions.PolynomialExp.27_0.0J48LYNgQ4iVYMM
theorem tendsto_div_exp_atTop (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x / exp x) atTop (𝓝 0)
Mathlib_Analysis_SpecialFunctions_PolynomialExp
R : Type u inst✝ : Ring R M N : ModuleCat R f : M ⟶ N hf : Mono f ⊢ (LinearEquiv.toModuleIso' (LinearEquiv.symm (Submodule.quotEquivOfEqBot (LinearMap.ker f) (_ : LinearMap.ker f = ⊥)) ≪≫ₗ (LinearMap.quotKerEquivRange f ≪≫ₗ LinearEquiv.ofEq (LinearMap.range f) (LinearMap.ker (Submodule.mkQ (LinearMap.range f))) (_ : LinearMap.range f = LinearMap.ker (Submodule.mkQ (LinearMap.range f)))))).hom ≫ Fork.ι (kernelCone (Submodule.mkQ (LinearMap.range f))) = f
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.LinearAlgebra.Isomorphisms import Mathlib.Algebra.Category.ModuleCat.Kernels import Mathlib.Algebra.Category.ModuleCat.Limits import Mathlib.CategoryTheory.Abelian.Exact #align_import algebra.category.Module.abelian from "leanprover-community/mathlib"@"09f981f72d43749f1fa072deade828d9c1e185bb" /-! # The category of left R-modules is abelian. Additionally, two linear maps are exact in the categorical sense iff `range f = ker g`. -/ open CategoryTheory open CategoryTheory.Limits noncomputable section universe w v u namespace ModuleCat variable {R : Type u} [Ring R] {M N : ModuleCat.{v} R} (f : M ⟶ N) /-- In the category of modules, every monomorphism is normal. -/ def normalMono (hf : Mono f) : NormalMono f where Z := of R (N ⧸ LinearMap.range f) g := f.range.mkQ w := LinearMap.range_mkQ_comp _ isLimit := /- The following [invalid Lean code](https://github.com/leanprover-community/lean/issues/341) might help you understand what's going on here: ``` calc M ≃ₗ[R] f.ker.quotient : (submodule.quot_equiv_of_eq_bot _ (ker_eq_bot_of_mono _)).symm ... ≃ₗ[R] f.range : linear_map.quot_ker_equiv_range f ... ≃ₗ[R] r.range.mkq.ker : linear_equiv.of_eq _ _ (submodule.ker_mkq _).symm ``` -/ IsKernel.isoKernel _ _ (kernelIsLimit _) (LinearEquiv.toModuleIso' ((Submodule.quotEquivOfEqBot _ (ker_eq_bot_of_mono _)).symm ≪≫ₗ (LinearMap.quotKerEquivRange f ≪≫ₗ LinearEquiv.ofEq _ _ (Submodule.ker_mkQ _).symm))) <| by
ext
/-- In the category of modules, every monomorphism is normal. -/ def normalMono (hf : Mono f) : NormalMono f where Z := of R (N ⧸ LinearMap.range f) g := f.range.mkQ w := LinearMap.range_mkQ_comp _ isLimit := /- The following [invalid Lean code](https://github.com/leanprover-community/lean/issues/341) might help you understand what's going on here: ``` calc M ≃ₗ[R] f.ker.quotient : (submodule.quot_equiv_of_eq_bot _ (ker_eq_bot_of_mono _)).symm ... ≃ₗ[R] f.range : linear_map.quot_ker_equiv_range f ... ≃ₗ[R] r.range.mkq.ker : linear_equiv.of_eq _ _ (submodule.ker_mkq _).symm ``` -/ IsKernel.isoKernel _ _ (kernelIsLimit _) (LinearEquiv.toModuleIso' ((Submodule.quotEquivOfEqBot _ (ker_eq_bot_of_mono _)).symm ≪≫ₗ (LinearMap.quotKerEquivRange f ≪≫ₗ LinearEquiv.ofEq _ _ (Submodule.ker_mkQ _).symm))) <| by
Mathlib.Algebra.Category.ModuleCat.Abelian.32_0.YQEqfRpdC3YQKHM
/-- In the category of modules, every monomorphism is normal. -/ def normalMono (hf : Mono f) : NormalMono f where Z
Mathlib_Algebra_Category_ModuleCat_Abelian
case h R : Type u inst✝ : Ring R M N : ModuleCat R f : M ⟶ N hf : Mono f x✝ : ↑M ⊢ ((LinearEquiv.toModuleIso' (LinearEquiv.symm (Submodule.quotEquivOfEqBot (LinearMap.ker f) (_ : LinearMap.ker f = ⊥)) ≪≫ₗ (LinearMap.quotKerEquivRange f ≪≫ₗ LinearEquiv.ofEq (LinearMap.range f) (LinearMap.ker (Submodule.mkQ (LinearMap.range f))) (_ : LinearMap.range f = LinearMap.ker (Submodule.mkQ (LinearMap.range f)))))).hom ≫ Fork.ι (kernelCone (Submodule.mkQ (LinearMap.range f)))) x✝ = f x✝
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.LinearAlgebra.Isomorphisms import Mathlib.Algebra.Category.ModuleCat.Kernels import Mathlib.Algebra.Category.ModuleCat.Limits import Mathlib.CategoryTheory.Abelian.Exact #align_import algebra.category.Module.abelian from "leanprover-community/mathlib"@"09f981f72d43749f1fa072deade828d9c1e185bb" /-! # The category of left R-modules is abelian. Additionally, two linear maps are exact in the categorical sense iff `range f = ker g`. -/ open CategoryTheory open CategoryTheory.Limits noncomputable section universe w v u namespace ModuleCat variable {R : Type u} [Ring R] {M N : ModuleCat.{v} R} (f : M ⟶ N) /-- In the category of modules, every monomorphism is normal. -/ def normalMono (hf : Mono f) : NormalMono f where Z := of R (N ⧸ LinearMap.range f) g := f.range.mkQ w := LinearMap.range_mkQ_comp _ isLimit := /- The following [invalid Lean code](https://github.com/leanprover-community/lean/issues/341) might help you understand what's going on here: ``` calc M ≃ₗ[R] f.ker.quotient : (submodule.quot_equiv_of_eq_bot _ (ker_eq_bot_of_mono _)).symm ... ≃ₗ[R] f.range : linear_map.quot_ker_equiv_range f ... ≃ₗ[R] r.range.mkq.ker : linear_equiv.of_eq _ _ (submodule.ker_mkq _).symm ``` -/ IsKernel.isoKernel _ _ (kernelIsLimit _) (LinearEquiv.toModuleIso' ((Submodule.quotEquivOfEqBot _ (ker_eq_bot_of_mono _)).symm ≪≫ₗ (LinearMap.quotKerEquivRange f ≪≫ₗ LinearEquiv.ofEq _ _ (Submodule.ker_mkQ _).symm))) <| by ext;
rfl
/-- In the category of modules, every monomorphism is normal. -/ def normalMono (hf : Mono f) : NormalMono f where Z := of R (N ⧸ LinearMap.range f) g := f.range.mkQ w := LinearMap.range_mkQ_comp _ isLimit := /- The following [invalid Lean code](https://github.com/leanprover-community/lean/issues/341) might help you understand what's going on here: ``` calc M ≃ₗ[R] f.ker.quotient : (submodule.quot_equiv_of_eq_bot _ (ker_eq_bot_of_mono _)).symm ... ≃ₗ[R] f.range : linear_map.quot_ker_equiv_range f ... ≃ₗ[R] r.range.mkq.ker : linear_equiv.of_eq _ _ (submodule.ker_mkq _).symm ``` -/ IsKernel.isoKernel _ _ (kernelIsLimit _) (LinearEquiv.toModuleIso' ((Submodule.quotEquivOfEqBot _ (ker_eq_bot_of_mono _)).symm ≪≫ₗ (LinearMap.quotKerEquivRange f ≪≫ₗ LinearEquiv.ofEq _ _ (Submodule.ker_mkQ _).symm))) <| by ext;
Mathlib.Algebra.Category.ModuleCat.Abelian.32_0.YQEqfRpdC3YQKHM
/-- In the category of modules, every monomorphism is normal. -/ def normalMono (hf : Mono f) : NormalMono f where Z
Mathlib_Algebra_Category_ModuleCat_Abelian
R : Type u inst✝ : Ring R M N : ModuleCat R f : M ⟶ N hf : Epi f ⊢ Cofork.π (cokernelCocone (Submodule.subtype (LinearMap.ker f))) ≫ (LinearEquiv.toModuleIso' (Submodule.quotEquivOfEq (LinearMap.range (Submodule.subtype (LinearMap.ker f))) (LinearMap.ker f) (_ : LinearMap.range (Submodule.subtype (LinearMap.ker f)) = LinearMap.ker f) ≪≫ₗ LinearMap.quotKerEquivRange f ≪≫ₗ LinearEquiv.ofTop (LinearMap.range f) (_ : LinearMap.range f = ⊤))).hom = f
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.LinearAlgebra.Isomorphisms import Mathlib.Algebra.Category.ModuleCat.Kernels import Mathlib.Algebra.Category.ModuleCat.Limits import Mathlib.CategoryTheory.Abelian.Exact #align_import algebra.category.Module.abelian from "leanprover-community/mathlib"@"09f981f72d43749f1fa072deade828d9c1e185bb" /-! # The category of left R-modules is abelian. Additionally, two linear maps are exact in the categorical sense iff `range f = ker g`. -/ open CategoryTheory open CategoryTheory.Limits noncomputable section universe w v u namespace ModuleCat variable {R : Type u} [Ring R] {M N : ModuleCat.{v} R} (f : M ⟶ N) /-- In the category of modules, every monomorphism is normal. -/ def normalMono (hf : Mono f) : NormalMono f where Z := of R (N ⧸ LinearMap.range f) g := f.range.mkQ w := LinearMap.range_mkQ_comp _ isLimit := /- The following [invalid Lean code](https://github.com/leanprover-community/lean/issues/341) might help you understand what's going on here: ``` calc M ≃ₗ[R] f.ker.quotient : (submodule.quot_equiv_of_eq_bot _ (ker_eq_bot_of_mono _)).symm ... ≃ₗ[R] f.range : linear_map.quot_ker_equiv_range f ... ≃ₗ[R] r.range.mkq.ker : linear_equiv.of_eq _ _ (submodule.ker_mkq _).symm ``` -/ IsKernel.isoKernel _ _ (kernelIsLimit _) (LinearEquiv.toModuleIso' ((Submodule.quotEquivOfEqBot _ (ker_eq_bot_of_mono _)).symm ≪≫ₗ (LinearMap.quotKerEquivRange f ≪≫ₗ LinearEquiv.ofEq _ _ (Submodule.ker_mkQ _).symm))) <| by ext; rfl set_option linter.uppercaseLean3 false in #align Module.normal_mono ModuleCat.normalMono /-- In the category of modules, every epimorphism is normal. -/ def normalEpi (hf : Epi f) : NormalEpi f where W := of R (LinearMap.ker f) g := (LinearMap.ker f).subtype w := LinearMap.comp_ker_subtype _ isColimit := /- The following invalid Lean code might help you understand what's going on here: ``` calc f.ker.subtype.range.quotient ≃ₗ[R] f.ker.quotient : submodule.quot_equiv_of_eq _ _ (submodule.range_subtype _) ... ≃ₗ[R] f.range : linear_map.quot_ker_equiv_range f ... ≃ₗ[R] N : linear_equiv.of_top _ (range_eq_top_of_epi _) ``` -/ IsCokernel.cokernelIso _ _ (cokernelIsColimit _) (LinearEquiv.toModuleIso' (Submodule.quotEquivOfEq _ _ (Submodule.range_subtype _) ≪≫ₗ LinearMap.quotKerEquivRange f ≪≫ₗ LinearEquiv.ofTop _ (range_eq_top_of_epi _))) <| by
ext
/-- In the category of modules, every epimorphism is normal. -/ def normalEpi (hf : Epi f) : NormalEpi f where W := of R (LinearMap.ker f) g := (LinearMap.ker f).subtype w := LinearMap.comp_ker_subtype _ isColimit := /- The following invalid Lean code might help you understand what's going on here: ``` calc f.ker.subtype.range.quotient ≃ₗ[R] f.ker.quotient : submodule.quot_equiv_of_eq _ _ (submodule.range_subtype _) ... ≃ₗ[R] f.range : linear_map.quot_ker_equiv_range f ... ≃ₗ[R] N : linear_equiv.of_top _ (range_eq_top_of_epi _) ``` -/ IsCokernel.cokernelIso _ _ (cokernelIsColimit _) (LinearEquiv.toModuleIso' (Submodule.quotEquivOfEq _ _ (Submodule.range_subtype _) ≪≫ₗ LinearMap.quotKerEquivRange f ≪≫ₗ LinearEquiv.ofTop _ (range_eq_top_of_epi _))) <| by
Mathlib.Algebra.Category.ModuleCat.Abelian.55_0.YQEqfRpdC3YQKHM
/-- In the category of modules, every epimorphism is normal. -/ def normalEpi (hf : Epi f) : NormalEpi f where W
Mathlib_Algebra_Category_ModuleCat_Abelian
case h R : Type u inst✝ : Ring R M N : ModuleCat R f : M ⟶ N hf : Epi f x✝ : ↑((parallelPair (Submodule.subtype (LinearMap.ker f)) 0).obj WalkingParallelPair.one) ⊢ (Cofork.π (cokernelCocone (Submodule.subtype (LinearMap.ker f))) ≫ (LinearEquiv.toModuleIso' (Submodule.quotEquivOfEq (LinearMap.range (Submodule.subtype (LinearMap.ker f))) (LinearMap.ker f) (_ : LinearMap.range (Submodule.subtype (LinearMap.ker f)) = LinearMap.ker f) ≪≫ₗ LinearMap.quotKerEquivRange f ≪≫ₗ LinearEquiv.ofTop (LinearMap.range f) (_ : LinearMap.range f = ⊤))).hom) x✝ = f x✝
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.LinearAlgebra.Isomorphisms import Mathlib.Algebra.Category.ModuleCat.Kernels import Mathlib.Algebra.Category.ModuleCat.Limits import Mathlib.CategoryTheory.Abelian.Exact #align_import algebra.category.Module.abelian from "leanprover-community/mathlib"@"09f981f72d43749f1fa072deade828d9c1e185bb" /-! # The category of left R-modules is abelian. Additionally, two linear maps are exact in the categorical sense iff `range f = ker g`. -/ open CategoryTheory open CategoryTheory.Limits noncomputable section universe w v u namespace ModuleCat variable {R : Type u} [Ring R] {M N : ModuleCat.{v} R} (f : M ⟶ N) /-- In the category of modules, every monomorphism is normal. -/ def normalMono (hf : Mono f) : NormalMono f where Z := of R (N ⧸ LinearMap.range f) g := f.range.mkQ w := LinearMap.range_mkQ_comp _ isLimit := /- The following [invalid Lean code](https://github.com/leanprover-community/lean/issues/341) might help you understand what's going on here: ``` calc M ≃ₗ[R] f.ker.quotient : (submodule.quot_equiv_of_eq_bot _ (ker_eq_bot_of_mono _)).symm ... ≃ₗ[R] f.range : linear_map.quot_ker_equiv_range f ... ≃ₗ[R] r.range.mkq.ker : linear_equiv.of_eq _ _ (submodule.ker_mkq _).symm ``` -/ IsKernel.isoKernel _ _ (kernelIsLimit _) (LinearEquiv.toModuleIso' ((Submodule.quotEquivOfEqBot _ (ker_eq_bot_of_mono _)).symm ≪≫ₗ (LinearMap.quotKerEquivRange f ≪≫ₗ LinearEquiv.ofEq _ _ (Submodule.ker_mkQ _).symm))) <| by ext; rfl set_option linter.uppercaseLean3 false in #align Module.normal_mono ModuleCat.normalMono /-- In the category of modules, every epimorphism is normal. -/ def normalEpi (hf : Epi f) : NormalEpi f where W := of R (LinearMap.ker f) g := (LinearMap.ker f).subtype w := LinearMap.comp_ker_subtype _ isColimit := /- The following invalid Lean code might help you understand what's going on here: ``` calc f.ker.subtype.range.quotient ≃ₗ[R] f.ker.quotient : submodule.quot_equiv_of_eq _ _ (submodule.range_subtype _) ... ≃ₗ[R] f.range : linear_map.quot_ker_equiv_range f ... ≃ₗ[R] N : linear_equiv.of_top _ (range_eq_top_of_epi _) ``` -/ IsCokernel.cokernelIso _ _ (cokernelIsColimit _) (LinearEquiv.toModuleIso' (Submodule.quotEquivOfEq _ _ (Submodule.range_subtype _) ≪≫ₗ LinearMap.quotKerEquivRange f ≪≫ₗ LinearEquiv.ofTop _ (range_eq_top_of_epi _))) <| by ext;
rfl
/-- In the category of modules, every epimorphism is normal. -/ def normalEpi (hf : Epi f) : NormalEpi f where W := of R (LinearMap.ker f) g := (LinearMap.ker f).subtype w := LinearMap.comp_ker_subtype _ isColimit := /- The following invalid Lean code might help you understand what's going on here: ``` calc f.ker.subtype.range.quotient ≃ₗ[R] f.ker.quotient : submodule.quot_equiv_of_eq _ _ (submodule.range_subtype _) ... ≃ₗ[R] f.range : linear_map.quot_ker_equiv_range f ... ≃ₗ[R] N : linear_equiv.of_top _ (range_eq_top_of_epi _) ``` -/ IsCokernel.cokernelIso _ _ (cokernelIsColimit _) (LinearEquiv.toModuleIso' (Submodule.quotEquivOfEq _ _ (Submodule.range_subtype _) ≪≫ₗ LinearMap.quotKerEquivRange f ≪≫ₗ LinearEquiv.ofTop _ (range_eq_top_of_epi _))) <| by ext;
Mathlib.Algebra.Category.ModuleCat.Abelian.55_0.YQEqfRpdC3YQKHM
/-- In the category of modules, every epimorphism is normal. -/ def normalEpi (hf : Epi f) : NormalEpi f where W
Mathlib_Algebra_Category_ModuleCat_Abelian
R : Type u inst✝ : Ring R M N : ModuleCat R f : M ⟶ N O : ModuleCat R g : N ⟶ O ⊢ Exact f g ↔ range f = ker g
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.LinearAlgebra.Isomorphisms import Mathlib.Algebra.Category.ModuleCat.Kernels import Mathlib.Algebra.Category.ModuleCat.Limits import Mathlib.CategoryTheory.Abelian.Exact #align_import algebra.category.Module.abelian from "leanprover-community/mathlib"@"09f981f72d43749f1fa072deade828d9c1e185bb" /-! # The category of left R-modules is abelian. Additionally, two linear maps are exact in the categorical sense iff `range f = ker g`. -/ open CategoryTheory open CategoryTheory.Limits noncomputable section universe w v u namespace ModuleCat variable {R : Type u} [Ring R] {M N : ModuleCat.{v} R} (f : M ⟶ N) /-- In the category of modules, every monomorphism is normal. -/ def normalMono (hf : Mono f) : NormalMono f where Z := of R (N ⧸ LinearMap.range f) g := f.range.mkQ w := LinearMap.range_mkQ_comp _ isLimit := /- The following [invalid Lean code](https://github.com/leanprover-community/lean/issues/341) might help you understand what's going on here: ``` calc M ≃ₗ[R] f.ker.quotient : (submodule.quot_equiv_of_eq_bot _ (ker_eq_bot_of_mono _)).symm ... ≃ₗ[R] f.range : linear_map.quot_ker_equiv_range f ... ≃ₗ[R] r.range.mkq.ker : linear_equiv.of_eq _ _ (submodule.ker_mkq _).symm ``` -/ IsKernel.isoKernel _ _ (kernelIsLimit _) (LinearEquiv.toModuleIso' ((Submodule.quotEquivOfEqBot _ (ker_eq_bot_of_mono _)).symm ≪≫ₗ (LinearMap.quotKerEquivRange f ≪≫ₗ LinearEquiv.ofEq _ _ (Submodule.ker_mkQ _).symm))) <| by ext; rfl set_option linter.uppercaseLean3 false in #align Module.normal_mono ModuleCat.normalMono /-- In the category of modules, every epimorphism is normal. -/ def normalEpi (hf : Epi f) : NormalEpi f where W := of R (LinearMap.ker f) g := (LinearMap.ker f).subtype w := LinearMap.comp_ker_subtype _ isColimit := /- The following invalid Lean code might help you understand what's going on here: ``` calc f.ker.subtype.range.quotient ≃ₗ[R] f.ker.quotient : submodule.quot_equiv_of_eq _ _ (submodule.range_subtype _) ... ≃ₗ[R] f.range : linear_map.quot_ker_equiv_range f ... ≃ₗ[R] N : linear_equiv.of_top _ (range_eq_top_of_epi _) ``` -/ IsCokernel.cokernelIso _ _ (cokernelIsColimit _) (LinearEquiv.toModuleIso' (Submodule.quotEquivOfEq _ _ (Submodule.range_subtype _) ≪≫ₗ LinearMap.quotKerEquivRange f ≪≫ₗ LinearEquiv.ofTop _ (range_eq_top_of_epi _))) <| by ext; rfl set_option linter.uppercaseLean3 false in #align Module.normal_epi ModuleCat.normalEpi /-- The category of R-modules is abelian. -/ instance abelian : Abelian (ModuleCat.{v} R) where has_cokernels := hasCokernels_moduleCat normalMonoOfMono := normalMono normalEpiOfEpi := normalEpi set_option linter.uppercaseLean3 false in #align Module.abelian ModuleCat.abelian section ReflectsLimits -- porting note: added to make the following definitions work instance : HasLimitsOfSize.{v,v} (ModuleCatMax.{v, w} R) := ModuleCat.hasLimitsOfSize /- We need to put this in this weird spot because we need to know that the category of modules is balanced. -/ instance forgetReflectsLimitsOfSize : ReflectsLimitsOfSize.{v, v} (forget (ModuleCatMax.{v, w} R)) := reflectsLimitsOfReflectsIsomorphisms set_option linter.uppercaseLean3 false in #align Module.forget_reflects_limits_of_size ModuleCat.forgetReflectsLimitsOfSize instance forget₂ReflectsLimitsOfSize : ReflectsLimitsOfSize.{v, v} (forget₂ (ModuleCatMax.{v, w} R) AddCommGroupCat.{max v w}) := reflectsLimitsOfReflectsIsomorphisms set_option linter.uppercaseLean3 false in #align Module.forget₂_reflects_limits_of_size ModuleCat.forget₂ReflectsLimitsOfSize instance forgetReflectsLimits : ReflectsLimits (forget (ModuleCat.{v} R)) := ModuleCat.forgetReflectsLimitsOfSize.{v, v} set_option linter.uppercaseLean3 false in #align Module.forget_reflects_limits ModuleCat.forgetReflectsLimits instance forget₂ReflectsLimits : ReflectsLimits (forget₂ (ModuleCat.{v} R) AddCommGroupCat.{v}) := ModuleCat.forget₂ReflectsLimitsOfSize.{v, v} set_option linter.uppercaseLean3 false in #align Module.forget₂_reflects_limits ModuleCat.forget₂ReflectsLimits end ReflectsLimits variable {O : ModuleCat.{v} R} (g : N ⟶ O) open LinearMap attribute [local instance] Preadditive.hasEqualizers_of_hasKernels theorem exact_iff : Exact f g ↔ LinearMap.range f = LinearMap.ker g := by
rw [abelian.exact_iff' f g (kernelIsLimit _) (cokernelIsColimit _)]
theorem exact_iff : Exact f g ↔ LinearMap.range f = LinearMap.ker g := by
Mathlib.Algebra.Category.ModuleCat.Abelian.122_0.YQEqfRpdC3YQKHM
theorem exact_iff : Exact f g ↔ LinearMap.range f = LinearMap.ker g
Mathlib_Algebra_Category_ModuleCat_Abelian
R : Type u inst✝ : Ring R M N : ModuleCat R f : M ⟶ N O : ModuleCat R g : N ⟶ O ⊢ f ≫ g = 0 ∧ Fork.ι (kernelCone g) ≫ Cofork.π (cokernelCocone f) = 0 ↔ range f = ker g
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.LinearAlgebra.Isomorphisms import Mathlib.Algebra.Category.ModuleCat.Kernels import Mathlib.Algebra.Category.ModuleCat.Limits import Mathlib.CategoryTheory.Abelian.Exact #align_import algebra.category.Module.abelian from "leanprover-community/mathlib"@"09f981f72d43749f1fa072deade828d9c1e185bb" /-! # The category of left R-modules is abelian. Additionally, two linear maps are exact in the categorical sense iff `range f = ker g`. -/ open CategoryTheory open CategoryTheory.Limits noncomputable section universe w v u namespace ModuleCat variable {R : Type u} [Ring R] {M N : ModuleCat.{v} R} (f : M ⟶ N) /-- In the category of modules, every monomorphism is normal. -/ def normalMono (hf : Mono f) : NormalMono f where Z := of R (N ⧸ LinearMap.range f) g := f.range.mkQ w := LinearMap.range_mkQ_comp _ isLimit := /- The following [invalid Lean code](https://github.com/leanprover-community/lean/issues/341) might help you understand what's going on here: ``` calc M ≃ₗ[R] f.ker.quotient : (submodule.quot_equiv_of_eq_bot _ (ker_eq_bot_of_mono _)).symm ... ≃ₗ[R] f.range : linear_map.quot_ker_equiv_range f ... ≃ₗ[R] r.range.mkq.ker : linear_equiv.of_eq _ _ (submodule.ker_mkq _).symm ``` -/ IsKernel.isoKernel _ _ (kernelIsLimit _) (LinearEquiv.toModuleIso' ((Submodule.quotEquivOfEqBot _ (ker_eq_bot_of_mono _)).symm ≪≫ₗ (LinearMap.quotKerEquivRange f ≪≫ₗ LinearEquiv.ofEq _ _ (Submodule.ker_mkQ _).symm))) <| by ext; rfl set_option linter.uppercaseLean3 false in #align Module.normal_mono ModuleCat.normalMono /-- In the category of modules, every epimorphism is normal. -/ def normalEpi (hf : Epi f) : NormalEpi f where W := of R (LinearMap.ker f) g := (LinearMap.ker f).subtype w := LinearMap.comp_ker_subtype _ isColimit := /- The following invalid Lean code might help you understand what's going on here: ``` calc f.ker.subtype.range.quotient ≃ₗ[R] f.ker.quotient : submodule.quot_equiv_of_eq _ _ (submodule.range_subtype _) ... ≃ₗ[R] f.range : linear_map.quot_ker_equiv_range f ... ≃ₗ[R] N : linear_equiv.of_top _ (range_eq_top_of_epi _) ``` -/ IsCokernel.cokernelIso _ _ (cokernelIsColimit _) (LinearEquiv.toModuleIso' (Submodule.quotEquivOfEq _ _ (Submodule.range_subtype _) ≪≫ₗ LinearMap.quotKerEquivRange f ≪≫ₗ LinearEquiv.ofTop _ (range_eq_top_of_epi _))) <| by ext; rfl set_option linter.uppercaseLean3 false in #align Module.normal_epi ModuleCat.normalEpi /-- The category of R-modules is abelian. -/ instance abelian : Abelian (ModuleCat.{v} R) where has_cokernels := hasCokernels_moduleCat normalMonoOfMono := normalMono normalEpiOfEpi := normalEpi set_option linter.uppercaseLean3 false in #align Module.abelian ModuleCat.abelian section ReflectsLimits -- porting note: added to make the following definitions work instance : HasLimitsOfSize.{v,v} (ModuleCatMax.{v, w} R) := ModuleCat.hasLimitsOfSize /- We need to put this in this weird spot because we need to know that the category of modules is balanced. -/ instance forgetReflectsLimitsOfSize : ReflectsLimitsOfSize.{v, v} (forget (ModuleCatMax.{v, w} R)) := reflectsLimitsOfReflectsIsomorphisms set_option linter.uppercaseLean3 false in #align Module.forget_reflects_limits_of_size ModuleCat.forgetReflectsLimitsOfSize instance forget₂ReflectsLimitsOfSize : ReflectsLimitsOfSize.{v, v} (forget₂ (ModuleCatMax.{v, w} R) AddCommGroupCat.{max v w}) := reflectsLimitsOfReflectsIsomorphisms set_option linter.uppercaseLean3 false in #align Module.forget₂_reflects_limits_of_size ModuleCat.forget₂ReflectsLimitsOfSize instance forgetReflectsLimits : ReflectsLimits (forget (ModuleCat.{v} R)) := ModuleCat.forgetReflectsLimitsOfSize.{v, v} set_option linter.uppercaseLean3 false in #align Module.forget_reflects_limits ModuleCat.forgetReflectsLimits instance forget₂ReflectsLimits : ReflectsLimits (forget₂ (ModuleCat.{v} R) AddCommGroupCat.{v}) := ModuleCat.forget₂ReflectsLimitsOfSize.{v, v} set_option linter.uppercaseLean3 false in #align Module.forget₂_reflects_limits ModuleCat.forget₂ReflectsLimits end ReflectsLimits variable {O : ModuleCat.{v} R} (g : N ⟶ O) open LinearMap attribute [local instance] Preadditive.hasEqualizers_of_hasKernels theorem exact_iff : Exact f g ↔ LinearMap.range f = LinearMap.ker g := by rw [abelian.exact_iff' f g (kernelIsLimit _) (cokernelIsColimit _)]
exact ⟨fun h => le_antisymm (range_le_ker_iff.2 h.1) (ker_le_range_iff.2 h.2), fun h => ⟨range_le_ker_iff.1 <| le_of_eq h, ker_le_range_iff.1 <| le_of_eq h.symm⟩⟩
theorem exact_iff : Exact f g ↔ LinearMap.range f = LinearMap.ker g := by rw [abelian.exact_iff' f g (kernelIsLimit _) (cokernelIsColimit _)]
Mathlib.Algebra.Category.ModuleCat.Abelian.122_0.YQEqfRpdC3YQKHM
theorem exact_iff : Exact f g ↔ LinearMap.range f = LinearMap.ker g
Mathlib_Algebra_Category_ModuleCat_Abelian
α : Type u_1 inst✝ : DecidableEq α m : Multiset α x y : ToType m ⊢ x.fst = y.fst ↔ x.fst = y.fst
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by
cases x
@[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by
Mathlib.Data.Multiset.Fintype.75_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1
Mathlib_Data_Multiset_Fintype
case mk α : Type u_1 inst✝ : DecidableEq α m : Multiset α y : ToType m fst✝ : α snd✝ : Fin (count fst✝ m) ⊢ { fst := fst✝, snd := snd✝ }.fst = y.fst ↔ { fst := fst✝, snd := snd✝ }.fst = y.fst
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x
cases y
@[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x
Mathlib.Data.Multiset.Fintype.75_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1
Mathlib_Data_Multiset_Fintype
case mk.mk α : Type u_1 inst✝ : DecidableEq α m : Multiset α fst✝¹ : α snd✝¹ : Fin (count fst✝¹ m) fst✝ : α snd✝ : Fin (count fst✝ m) ⊢ { fst := fst✝¹, snd := snd✝¹ }.fst = { fst := fst✝, snd := snd✝ }.fst ↔ { fst := fst✝¹, snd := snd✝¹ }.fst = { fst := fst✝, snd := snd✝ }.fst
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y
rfl
@[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y
Mathlib.Data.Multiset.Fintype.75_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m : Multiset α ⊢ ∀ (x : α × ℕ), (x ∈ Finset.biUnion (Multiset.toFinset m) fun x => Finset.map { toFun := Prod.mk x, inj' := (_ : Function.Injective (Prod.mk x)) } (Finset.range (Multiset.count x m))) ↔ x ∈ {p | p.2 < Multiset.count p.1 m}
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by
rintro ⟨x, i⟩
instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by
Mathlib.Data.Multiset.Fintype.104_0.gXgzg6nY9WO2bG2
instance : Fintype { p : α × ℕ | p.2 < m.count p.1 }
Mathlib_Data_Multiset_Fintype
case mk α : Type u_1 inst✝ : DecidableEq α m : Multiset α x : α i : ℕ ⊢ ((x, i) ∈ Finset.biUnion (Multiset.toFinset m) fun x => Finset.map { toFun := Prod.mk x, inj' := (_ : Function.Injective (Prod.mk x)) } (Finset.range (Multiset.count x m))) ↔ (x, i) ∈ {p | p.2 < Multiset.count p.1 m}
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩
simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq]
instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩
Mathlib.Data.Multiset.Fintype.104_0.gXgzg6nY9WO2bG2
instance : Fintype { p : α × ℕ | p.2 < m.count p.1 }
Mathlib_Data_Multiset_Fintype
case mk α : Type u_1 inst✝ : DecidableEq α m : Multiset α x : α i : ℕ ⊢ (∃ a ∈ m, ∃ a_1 < Multiset.count a m, a = x ∧ a_1 = i) ↔ i < Multiset.count x m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq]
simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp]
instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq]
Mathlib.Data.Multiset.Fintype.104_0.gXgzg6nY9WO2bG2
instance : Fintype { p : α × ℕ | p.2 < m.count p.1 }
Mathlib_Data_Multiset_Fintype
case mk α : Type u_1 inst✝ : DecidableEq α m : Multiset α x : α i : ℕ ⊢ i < Multiset.count x m → x ∈ m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp]
exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)
instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp]
Mathlib.Data.Multiset.Fintype.104_0.gXgzg6nY9WO2bG2
instance : Fintype { p : α × ℕ | p.2 < m.count p.1 }
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m m₁ m₂ : Multiset α h : m₁ ≤ m₂ ⊢ toEnumFinset m₁ ⊆ toEnumFinset m₂
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by
intro p
@[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by
Mathlib.Data.Multiset.Fintype.131_0.gXgzg6nY9WO2bG2
@[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m m₁ m₂ : Multiset α h : m₁ ≤ m₂ p : α × ℕ ⊢ p ∈ toEnumFinset m₁ → p ∈ toEnumFinset m₂
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p
simp only [Multiset.mem_toEnumFinset]
@[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p
Mathlib.Data.Multiset.Fintype.131_0.gXgzg6nY9WO2bG2
@[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m m₁ m₂ : Multiset α h : m₁ ≤ m₂ p : α × ℕ ⊢ p.2 < count p.1 m₁ → p.2 < count p.1 m₂
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset]
exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1)
@[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset]
Mathlib.Data.Multiset.Fintype.131_0.gXgzg6nY9WO2bG2
@[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m m₁ m₂ : Multiset α ⊢ toEnumFinset m₁ ⊆ toEnumFinset m₂ ↔ m₁ ≤ m₂
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by
refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by
Mathlib.Data.Multiset.Fintype.139_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m m₁ m₂ : Multiset α h : toEnumFinset m₁ ⊆ toEnumFinset m₂ ⊢ m₁ ≤ m₂
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩
rw [Multiset.le_iff_count]
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩
Mathlib.Data.Multiset.Fintype.139_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m m₁ m₂ : Multiset α h : toEnumFinset m₁ ⊆ toEnumFinset m₂ ⊢ ∀ (a : α), count a m₁ ≤ count a m₂
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count]
intro x
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count]
Mathlib.Data.Multiset.Fintype.139_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m m₁ m₂ : Multiset α h : toEnumFinset m₁ ⊆ toEnumFinset m₂ x : α ⊢ count x m₁ ≤ count x m₂
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x
by_cases hx : x ∈ m₁
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x
Mathlib.Data.Multiset.Fintype.139_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂
Mathlib_Data_Multiset_Fintype
case pos α : Type u_1 inst✝ : DecidableEq α m m₁ m₂ : Multiset α h : toEnumFinset m₁ ⊆ toEnumFinset m₂ x : α hx : x ∈ m₁ ⊢ count x m₁ ≤ count x m₂
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ ·
apply Nat.le_of_pred_lt
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ ·
Mathlib.Data.Multiset.Fintype.139_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂
Mathlib_Data_Multiset_Fintype
case pos.a α : Type u_1 inst✝ : DecidableEq α m m₁ m₂ : Multiset α h : toEnumFinset m₁ ⊆ toEnumFinset m₂ x : α hx : x ∈ m₁ ⊢ Nat.pred (count x m₁) < count x m₂
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt
have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx))
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt
Mathlib.Data.Multiset.Fintype.139_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m m₁ m₂ : Multiset α h : toEnumFinset m₁ ⊆ toEnumFinset m₂ x : α hx : x ∈ m₁ ⊢ (x, count x m₁ - 1) ∈ toEnumFinset m₁
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by
rw [Multiset.mem_toEnumFinset]
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by
Mathlib.Data.Multiset.Fintype.139_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m m₁ m₂ : Multiset α h : toEnumFinset m₁ ⊆ toEnumFinset m₂ x : α hx : x ∈ m₁ ⊢ (x, count x m₁ - 1).2 < count (x, count x m₁ - 1).1 m₁
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset]
exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx))
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset]
Mathlib.Data.Multiset.Fintype.139_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂
Mathlib_Data_Multiset_Fintype
case pos.a α : Type u_1 inst✝ : DecidableEq α m m₁ m₂ : Multiset α h : toEnumFinset m₁ ⊆ toEnumFinset m₂ x : α hx : x ∈ m₁ this : (x, count x m₁ - 1) ∈ toEnumFinset m₁ ⊢ Nat.pred (count x m₁) < count x m₂
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx))
simpa only [Multiset.mem_toEnumFinset] using h this
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx))
Mathlib.Data.Multiset.Fintype.139_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂
Mathlib_Data_Multiset_Fintype
case neg α : Type u_1 inst✝ : DecidableEq α m m₁ m₂ : Multiset α h : toEnumFinset m₁ ⊆ toEnumFinset m₂ x : α hx : x ∉ m₁ ⊢ count x m₁ ≤ count x m₂
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this ·
simp [hx]
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this ·
Mathlib.Data.Multiset.Fintype.139_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α ⊢ Function.Injective fun x => (x.fst, ↑x.snd)
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by
intro ⟨x, i, hi⟩ ⟨y, j, hj⟩
/-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by
Mathlib.Data.Multiset.Fintype.154_0.gXgzg6nY9WO2bG2
/-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α x : α i : ℕ hi : i < count x m y : α j : ℕ hj : j < count y m ⊢ (fun x => (x.fst, ↑x.snd)) { fst := x, snd := { val := i, isLt := hi } } = (fun x => (x.fst, ↑x.snd)) { fst := y, snd := { val := j, isLt := hj } } → { fst := x, snd := { val := i, isLt := hi } } = { fst := y, snd := { val := j, isLt := hj } }
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩
rintro ⟨⟩
/-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩
Mathlib.Data.Multiset.Fintype.154_0.gXgzg6nY9WO2bG2
/-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x
Mathlib_Data_Multiset_Fintype
case refl α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α x : α i : ℕ hi hj : i < count x m ⊢ { fst := x, snd := { val := i, isLt := hi } } = { fst := x, snd := { val := i, isLt := hj } }
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩
rfl
/-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩
Mathlib.Data.Multiset.Fintype.154_0.gXgzg6nY9WO2bG2
/-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α x : ToType m ⊢ (coeEmbedding m) x ∈ toEnumFinset m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by
rw [Multiset.mem_toEnumFinset]
/-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by
Mathlib.Data.Multiset.Fintype.166_0.gXgzg6nY9WO2bG2
/-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α x : ToType m ⊢ ((coeEmbedding m) x).2 < count ((coeEmbedding m) x).1 m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset]
exact x.2.2
/-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset]
Mathlib.Data.Multiset.Fintype.166_0.gXgzg6nY9WO2bG2
/-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α x : { x // x ∈ toEnumFinset m } ⊢ (↑x).2 < count (↑x).1 m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by
rw [← Multiset.mem_toEnumFinset]
/-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by
Mathlib.Data.Multiset.Fintype.166_0.gXgzg6nY9WO2bG2
/-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α x : { x // x ∈ toEnumFinset m } ⊢ ↑x ∈ toEnumFinset m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset]
exact x.2
/-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset]
Mathlib.Data.Multiset.Fintype.166_0.gXgzg6nY9WO2bG2
/-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α ⊢ Function.LeftInverse (fun x => { fst := (↑x).1, snd := { val := (↑x).2, isLt := (_ : (↑x).2 < count (↑x).1 m) } }) fun x => { val := (coeEmbedding m) x, property := (_ : (coeEmbedding m) x ∈ toEnumFinset m) }
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by
rintro ⟨x, i, h⟩
/-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by
Mathlib.Data.Multiset.Fintype.166_0.gXgzg6nY9WO2bG2
/-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x
Mathlib_Data_Multiset_Fintype
case mk.mk α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α x : α i : ℕ h : i < count x m ⊢ (fun x => { fst := (↑x).1, snd := { val := (↑x).2, isLt := (_ : (↑x).2 < count (↑x).1 m) } }) ((fun x => { val := (coeEmbedding m) x, property := (_ : (coeEmbedding m) x ∈ toEnumFinset m) }) { fst := x, snd := { val := i, isLt := h } }) = { fst := x, snd := { val := i, isLt := h } }
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩
rfl
/-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩
Mathlib.Data.Multiset.Fintype.166_0.gXgzg6nY9WO2bG2
/-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α ⊢ Function.RightInverse (fun x => { fst := (↑x).1, snd := { val := (↑x).2, isLt := (_ : (↑x).2 < count (↑x).1 m) } }) fun x => { val := (coeEmbedding m) x, property := (_ : (coeEmbedding m) x ∈ toEnumFinset m) }
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by
rintro ⟨⟨x, i⟩, h⟩
/-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by
Mathlib.Data.Multiset.Fintype.166_0.gXgzg6nY9WO2bG2
/-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x
Mathlib_Data_Multiset_Fintype
case mk.mk α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α x : α i : ℕ h : (x, i) ∈ toEnumFinset m ⊢ (fun x => { val := (coeEmbedding m) x, property := (_ : (coeEmbedding m) x ∈ toEnumFinset m) }) ((fun x => { fst := (↑x).1, snd := { val := (↑x).2, isLt := (_ : (↑x).2 < count (↑x).1 m) } }) { val := (x, i), property := h }) = { val := (x, i), property := h }
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩
rfl
/-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩
Mathlib.Data.Multiset.Fintype.166_0.gXgzg6nY9WO2bG2
/-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α ⊢ Function.Embedding.trans (Equiv.toEmbedding (coeEquiv m)) (Function.Embedding.subtype fun x => x ∈ toEnumFinset m) = coeEmbedding m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by
ext
@[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by
Mathlib.Data.Multiset.Fintype.187_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding
Mathlib_Data_Multiset_Fintype
case h.a α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α x✝ : ToType m ⊢ ((Function.Embedding.trans (Equiv.toEmbedding (coeEquiv m)) (Function.Embedding.subtype fun x => x ∈ toEnumFinset m)) x✝).1 = ((coeEmbedding m) x✝).1
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;>
rfl
@[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;>
Mathlib.Data.Multiset.Fintype.187_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding
Mathlib_Data_Multiset_Fintype
case h.a α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α x✝ : ToType m ⊢ ((Function.Embedding.trans (Equiv.toEmbedding (coeEquiv m)) (Function.Embedding.subtype fun x => x ∈ toEnumFinset m)) x✝).2 = ((coeEmbedding m) x✝).2
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;>
rfl
@[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;>
Mathlib.Data.Multiset.Fintype.187_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α ⊢ Finset.map (coeEmbedding m) Finset.univ = toEnumFinset m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by
ext ⟨x, i⟩
theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by
Mathlib.Data.Multiset.Fintype.197_0.gXgzg6nY9WO2bG2
theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset
Mathlib_Data_Multiset_Fintype
case a.mk α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α x : α i : ℕ ⊢ (x, i) ∈ Finset.map (coeEmbedding m) Finset.univ ↔ (x, i) ∈ toEnumFinset m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩
simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff]
theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩
Mathlib.Data.Multiset.Fintype.197_0.gXgzg6nY9WO2bG2
theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α x : α ⊢ Finset.filter (fun p => x = p.1) (toEnumFinset m) = Finset.map { toFun := Prod.mk x, inj' := (_ : Function.Injective (Prod.mk x)) } (Finset.range (count x m))
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by
ext ⟨y, i⟩
theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by
Mathlib.Data.Multiset.Fintype.206_0.gXgzg6nY9WO2bG2
theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩
Mathlib_Data_Multiset_Fintype
case a.mk α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α x y : α i : ℕ ⊢ (y, i) ∈ Finset.filter (fun p => x = p.1) (toEnumFinset m) ↔ (y, i) ∈ Finset.map { toFun := Prod.mk x, inj' := (_ : Function.Injective (Prod.mk x)) } (Finset.range (count x m))
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩
simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff]
theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩
Mathlib.Data.Multiset.Fintype.206_0.gXgzg6nY9WO2bG2
theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩
Mathlib_Data_Multiset_Fintype
case a.mk α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α x y : α i : ℕ ⊢ x = y → (i < count y m ↔ i < count x m)
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff]
rintro rfl
theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff]
Mathlib.Data.Multiset.Fintype.206_0.gXgzg6nY9WO2bG2
theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩
Mathlib_Data_Multiset_Fintype
case a.mk α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α x : α i : ℕ ⊢ i < count x m ↔ i < count x m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl
rfl
theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl
Mathlib.Data.Multiset.Fintype.206_0.gXgzg6nY9WO2bG2
theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α ⊢ map Prod.fst (toEnumFinset m).val = m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by
ext x
@[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by
Mathlib.Data.Multiset.Fintype.217_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m
Mathlib_Data_Multiset_Fintype
case a α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α x : α ⊢ count x (map Prod.fst (toEnumFinset m).val) = count x m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x
simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range]
@[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x
Mathlib.Data.Multiset.Fintype.217_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α ⊢ Finset.image Prod.fst (toEnumFinset m) = toFinset m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range] #align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst @[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by
rw [Finset.image, Multiset.map_toEnumFinset_fst]
@[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by
Mathlib.Data.Multiset.Fintype.224_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α ⊢ map (fun x => x.fst) Finset.univ.val = m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range] #align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst @[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by rw [Finset.image, Multiset.map_toEnumFinset_fst] #align multiset.image_to_enum_finset_fst Multiset.image_toEnumFinset_fst @[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by
have := m.map_toEnumFinset_fst
@[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by
Mathlib.Data.Multiset.Fintype.230_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α this : map Prod.fst (toEnumFinset m).val = m ⊢ map (fun x => x.fst) Finset.univ.val = m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range] #align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst @[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by rw [Finset.image, Multiset.map_toEnumFinset_fst] #align multiset.image_to_enum_finset_fst Multiset.image_toEnumFinset_fst @[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst
rw [← m.map_univ_coeEmbedding] at this
@[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst
Mathlib.Data.Multiset.Fintype.230_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α this : map Prod.fst (Finset.map (coeEmbedding m) Finset.univ).val = m ⊢ map (fun x => x.fst) Finset.univ.val = m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range] #align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst @[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by rw [Finset.image, Multiset.map_toEnumFinset_fst] #align multiset.image_to_enum_finset_fst Multiset.image_toEnumFinset_fst @[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst rw [← m.map_univ_coeEmbedding] at this
simpa only [Finset.map_val, Multiset.coeEmbedding_apply, Multiset.map_map, Function.comp_apply] using this
@[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst rw [← m.map_univ_coeEmbedding] at this
Mathlib.Data.Multiset.Fintype.230_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ : Multiset α β : Type u_2 m : Multiset α f : α → β ⊢ map (fun x => f x.fst) Finset.univ.val = map f m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range] #align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst @[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by rw [Finset.image, Multiset.map_toEnumFinset_fst] #align multiset.image_to_enum_finset_fst Multiset.image_toEnumFinset_fst @[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst rw [← m.map_univ_coeEmbedding] at this simpa only [Finset.map_val, Multiset.coeEmbedding_apply, Multiset.map_map, Function.comp_apply] using this #align multiset.map_univ_coe Multiset.map_univ_coe @[simp] theorem Multiset.map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f := by
erw [← Multiset.map_map]
@[simp] theorem Multiset.map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f := by
Mathlib.Data.Multiset.Fintype.239_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ : Multiset α β : Type u_2 m : Multiset α f : α → β ⊢ map f (map (fun x => x.fst) Finset.univ.val) = map f m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range] #align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst @[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by rw [Finset.image, Multiset.map_toEnumFinset_fst] #align multiset.image_to_enum_finset_fst Multiset.image_toEnumFinset_fst @[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst rw [← m.map_univ_coeEmbedding] at this simpa only [Finset.map_val, Multiset.coeEmbedding_apply, Multiset.map_map, Function.comp_apply] using this #align multiset.map_univ_coe Multiset.map_univ_coe @[simp] theorem Multiset.map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f := by erw [← Multiset.map_map]
rw [Multiset.map_univ_coe]
@[simp] theorem Multiset.map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f := by erw [← Multiset.map_map]
Mathlib.Data.Multiset.Fintype.239_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α ⊢ Finset.card (toEnumFinset m) = card m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range] #align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst @[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by rw [Finset.image, Multiset.map_toEnumFinset_fst] #align multiset.image_to_enum_finset_fst Multiset.image_toEnumFinset_fst @[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst rw [← m.map_univ_coeEmbedding] at this simpa only [Finset.map_val, Multiset.coeEmbedding_apply, Multiset.map_map, Function.comp_apply] using this #align multiset.map_univ_coe Multiset.map_univ_coe @[simp] theorem Multiset.map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f := by erw [← Multiset.map_map] rw [Multiset.map_univ_coe] #align multiset.map_univ Multiset.map_univ @[simp] theorem Multiset.card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m := by
rw [Finset.card, ← Multiset.card_map Prod.fst m.toEnumFinset.val]
@[simp] theorem Multiset.card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m := by
Mathlib.Data.Multiset.Fintype.246_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α ⊢ card (map Prod.fst (toEnumFinset m).val) = card m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range] #align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst @[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by rw [Finset.image, Multiset.map_toEnumFinset_fst] #align multiset.image_to_enum_finset_fst Multiset.image_toEnumFinset_fst @[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst rw [← m.map_univ_coeEmbedding] at this simpa only [Finset.map_val, Multiset.coeEmbedding_apply, Multiset.map_map, Function.comp_apply] using this #align multiset.map_univ_coe Multiset.map_univ_coe @[simp] theorem Multiset.map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f := by erw [← Multiset.map_map] rw [Multiset.map_univ_coe] #align multiset.map_univ Multiset.map_univ @[simp] theorem Multiset.card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m := by rw [Finset.card, ← Multiset.card_map Prod.fst m.toEnumFinset.val]
congr
@[simp] theorem Multiset.card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m := by rw [Finset.card, ← Multiset.card_map Prod.fst m.toEnumFinset.val]
Mathlib.Data.Multiset.Fintype.246_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m
Mathlib_Data_Multiset_Fintype
case h.e_6.h α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α ⊢ map Prod.fst (toEnumFinset m).val = m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range] #align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst @[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by rw [Finset.image, Multiset.map_toEnumFinset_fst] #align multiset.image_to_enum_finset_fst Multiset.image_toEnumFinset_fst @[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst rw [← m.map_univ_coeEmbedding] at this simpa only [Finset.map_val, Multiset.coeEmbedding_apply, Multiset.map_map, Function.comp_apply] using this #align multiset.map_univ_coe Multiset.map_univ_coe @[simp] theorem Multiset.map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f := by erw [← Multiset.map_map] rw [Multiset.map_univ_coe] #align multiset.map_univ Multiset.map_univ @[simp] theorem Multiset.card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m := by rw [Finset.card, ← Multiset.card_map Prod.fst m.toEnumFinset.val] congr
exact m.map_toEnumFinset_fst
@[simp] theorem Multiset.card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m := by rw [Finset.card, ← Multiset.card_map Prod.fst m.toEnumFinset.val] congr
Mathlib.Data.Multiset.Fintype.246_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α ⊢ Fintype.card (ToType m) = card m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range] #align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst @[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by rw [Finset.image, Multiset.map_toEnumFinset_fst] #align multiset.image_to_enum_finset_fst Multiset.image_toEnumFinset_fst @[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst rw [← m.map_univ_coeEmbedding] at this simpa only [Finset.map_val, Multiset.coeEmbedding_apply, Multiset.map_map, Function.comp_apply] using this #align multiset.map_univ_coe Multiset.map_univ_coe @[simp] theorem Multiset.map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f := by erw [← Multiset.map_map] rw [Multiset.map_univ_coe] #align multiset.map_univ Multiset.map_univ @[simp] theorem Multiset.card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m := by rw [Finset.card, ← Multiset.card_map Prod.fst m.toEnumFinset.val] congr exact m.map_toEnumFinset_fst #align multiset.card_to_enum_finset Multiset.card_toEnumFinset @[simp] theorem Multiset.card_coe (m : Multiset α) : Fintype.card m = Multiset.card m := by
rw [Fintype.card_congr m.coeEquiv]
@[simp] theorem Multiset.card_coe (m : Multiset α) : Fintype.card m = Multiset.card m := by
Mathlib.Data.Multiset.Fintype.253_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.card_coe (m : Multiset α) : Fintype.card m = Multiset.card m
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝ : DecidableEq α m✝ m : Multiset α ⊢ Fintype.card { x // x ∈ toEnumFinset m } = card m
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range] #align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst @[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by rw [Finset.image, Multiset.map_toEnumFinset_fst] #align multiset.image_to_enum_finset_fst Multiset.image_toEnumFinset_fst @[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst rw [← m.map_univ_coeEmbedding] at this simpa only [Finset.map_val, Multiset.coeEmbedding_apply, Multiset.map_map, Function.comp_apply] using this #align multiset.map_univ_coe Multiset.map_univ_coe @[simp] theorem Multiset.map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f := by erw [← Multiset.map_map] rw [Multiset.map_univ_coe] #align multiset.map_univ Multiset.map_univ @[simp] theorem Multiset.card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m := by rw [Finset.card, ← Multiset.card_map Prod.fst m.toEnumFinset.val] congr exact m.map_toEnumFinset_fst #align multiset.card_to_enum_finset Multiset.card_toEnumFinset @[simp] theorem Multiset.card_coe (m : Multiset α) : Fintype.card m = Multiset.card m := by rw [Fintype.card_congr m.coeEquiv]
simp only [Fintype.card_coe, card_toEnumFinset]
@[simp] theorem Multiset.card_coe (m : Multiset α) : Fintype.card m = Multiset.card m := by rw [Fintype.card_congr m.coeEquiv]
Mathlib.Data.Multiset.Fintype.253_0.gXgzg6nY9WO2bG2
@[simp] theorem Multiset.card_coe (m : Multiset α) : Fintype.card m = Multiset.card m
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝¹ : DecidableEq α m✝ : Multiset α inst✝ : CommMonoid α m : Multiset α ⊢ prod m = ∏ x : ToType m, x.fst
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range] #align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst @[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by rw [Finset.image, Multiset.map_toEnumFinset_fst] #align multiset.image_to_enum_finset_fst Multiset.image_toEnumFinset_fst @[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst rw [← m.map_univ_coeEmbedding] at this simpa only [Finset.map_val, Multiset.coeEmbedding_apply, Multiset.map_map, Function.comp_apply] using this #align multiset.map_univ_coe Multiset.map_univ_coe @[simp] theorem Multiset.map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f := by erw [← Multiset.map_map] rw [Multiset.map_univ_coe] #align multiset.map_univ Multiset.map_univ @[simp] theorem Multiset.card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m := by rw [Finset.card, ← Multiset.card_map Prod.fst m.toEnumFinset.val] congr exact m.map_toEnumFinset_fst #align multiset.card_to_enum_finset Multiset.card_toEnumFinset @[simp] theorem Multiset.card_coe (m : Multiset α) : Fintype.card m = Multiset.card m := by rw [Fintype.card_congr m.coeEquiv] simp only [Fintype.card_coe, card_toEnumFinset] #align multiset.card_coe Multiset.card_coe @[to_additive] theorem Multiset.prod_eq_prod_coe [CommMonoid α] (m : Multiset α) : m.prod = ∏ x : m, (x : α) := by
congr
@[to_additive] theorem Multiset.prod_eq_prod_coe [CommMonoid α] (m : Multiset α) : m.prod = ∏ x : m, (x : α) := by
Mathlib.Data.Multiset.Fintype.259_0.gXgzg6nY9WO2bG2
@[to_additive] theorem Multiset.prod_eq_prod_coe [CommMonoid α] (m : Multiset α) : m.prod = ∏ x : m, (x : α)
Mathlib_Data_Multiset_Fintype
case e_a α : Type u_1 inst✝¹ : DecidableEq α m✝ : Multiset α inst✝ : CommMonoid α m : Multiset α ⊢ m = map (fun x => x.fst) Finset.univ.val
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range] #align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst @[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by rw [Finset.image, Multiset.map_toEnumFinset_fst] #align multiset.image_to_enum_finset_fst Multiset.image_toEnumFinset_fst @[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst rw [← m.map_univ_coeEmbedding] at this simpa only [Finset.map_val, Multiset.coeEmbedding_apply, Multiset.map_map, Function.comp_apply] using this #align multiset.map_univ_coe Multiset.map_univ_coe @[simp] theorem Multiset.map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f := by erw [← Multiset.map_map] rw [Multiset.map_univ_coe] #align multiset.map_univ Multiset.map_univ @[simp] theorem Multiset.card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m := by rw [Finset.card, ← Multiset.card_map Prod.fst m.toEnumFinset.val] congr exact m.map_toEnumFinset_fst #align multiset.card_to_enum_finset Multiset.card_toEnumFinset @[simp] theorem Multiset.card_coe (m : Multiset α) : Fintype.card m = Multiset.card m := by rw [Fintype.card_congr m.coeEquiv] simp only [Fintype.card_coe, card_toEnumFinset] #align multiset.card_coe Multiset.card_coe @[to_additive] theorem Multiset.prod_eq_prod_coe [CommMonoid α] (m : Multiset α) : m.prod = ∏ x : m, (x : α) := by congr -- Porting note: `simp` fails with "maximum recursion depth has been reached"
erw [map_univ_coe]
@[to_additive] theorem Multiset.prod_eq_prod_coe [CommMonoid α] (m : Multiset α) : m.prod = ∏ x : m, (x : α) := by congr -- Porting note: `simp` fails with "maximum recursion depth has been reached"
Mathlib.Data.Multiset.Fintype.259_0.gXgzg6nY9WO2bG2
@[to_additive] theorem Multiset.prod_eq_prod_coe [CommMonoid α] (m : Multiset α) : m.prod = ∏ x : m, (x : α)
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝¹ : DecidableEq α m✝ : Multiset α inst✝ : CommMonoid α m : Multiset α ⊢ prod m = ∏ x in toEnumFinset m, x.1
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range] #align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst @[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by rw [Finset.image, Multiset.map_toEnumFinset_fst] #align multiset.image_to_enum_finset_fst Multiset.image_toEnumFinset_fst @[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst rw [← m.map_univ_coeEmbedding] at this simpa only [Finset.map_val, Multiset.coeEmbedding_apply, Multiset.map_map, Function.comp_apply] using this #align multiset.map_univ_coe Multiset.map_univ_coe @[simp] theorem Multiset.map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f := by erw [← Multiset.map_map] rw [Multiset.map_univ_coe] #align multiset.map_univ Multiset.map_univ @[simp] theorem Multiset.card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m := by rw [Finset.card, ← Multiset.card_map Prod.fst m.toEnumFinset.val] congr exact m.map_toEnumFinset_fst #align multiset.card_to_enum_finset Multiset.card_toEnumFinset @[simp] theorem Multiset.card_coe (m : Multiset α) : Fintype.card m = Multiset.card m := by rw [Fintype.card_congr m.coeEquiv] simp only [Fintype.card_coe, card_toEnumFinset] #align multiset.card_coe Multiset.card_coe @[to_additive] theorem Multiset.prod_eq_prod_coe [CommMonoid α] (m : Multiset α) : m.prod = ∏ x : m, (x : α) := by congr -- Porting note: `simp` fails with "maximum recursion depth has been reached" erw [map_univ_coe] #align multiset.prod_eq_prod_coe Multiset.prod_eq_prod_coe #align multiset.sum_eq_sum_coe Multiset.sum_eq_sum_coe @[to_additive] theorem Multiset.prod_eq_prod_toEnumFinset [CommMonoid α] (m : Multiset α) : m.prod = ∏ x in m.toEnumFinset, x.1 := by
congr
@[to_additive] theorem Multiset.prod_eq_prod_toEnumFinset [CommMonoid α] (m : Multiset α) : m.prod = ∏ x in m.toEnumFinset, x.1 := by
Mathlib.Data.Multiset.Fintype.267_0.gXgzg6nY9WO2bG2
@[to_additive] theorem Multiset.prod_eq_prod_toEnumFinset [CommMonoid α] (m : Multiset α) : m.prod = ∏ x in m.toEnumFinset, x.1
Mathlib_Data_Multiset_Fintype
case e_a α : Type u_1 inst✝¹ : DecidableEq α m✝ : Multiset α inst✝ : CommMonoid α m : Multiset α ⊢ m = map (fun x => x.1) (toEnumFinset m).val
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range] #align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst @[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by rw [Finset.image, Multiset.map_toEnumFinset_fst] #align multiset.image_to_enum_finset_fst Multiset.image_toEnumFinset_fst @[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst rw [← m.map_univ_coeEmbedding] at this simpa only [Finset.map_val, Multiset.coeEmbedding_apply, Multiset.map_map, Function.comp_apply] using this #align multiset.map_univ_coe Multiset.map_univ_coe @[simp] theorem Multiset.map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f := by erw [← Multiset.map_map] rw [Multiset.map_univ_coe] #align multiset.map_univ Multiset.map_univ @[simp] theorem Multiset.card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m := by rw [Finset.card, ← Multiset.card_map Prod.fst m.toEnumFinset.val] congr exact m.map_toEnumFinset_fst #align multiset.card_to_enum_finset Multiset.card_toEnumFinset @[simp] theorem Multiset.card_coe (m : Multiset α) : Fintype.card m = Multiset.card m := by rw [Fintype.card_congr m.coeEquiv] simp only [Fintype.card_coe, card_toEnumFinset] #align multiset.card_coe Multiset.card_coe @[to_additive] theorem Multiset.prod_eq_prod_coe [CommMonoid α] (m : Multiset α) : m.prod = ∏ x : m, (x : α) := by congr -- Porting note: `simp` fails with "maximum recursion depth has been reached" erw [map_univ_coe] #align multiset.prod_eq_prod_coe Multiset.prod_eq_prod_coe #align multiset.sum_eq_sum_coe Multiset.sum_eq_sum_coe @[to_additive] theorem Multiset.prod_eq_prod_toEnumFinset [CommMonoid α] (m : Multiset α) : m.prod = ∏ x in m.toEnumFinset, x.1 := by congr
simp
@[to_additive] theorem Multiset.prod_eq_prod_toEnumFinset [CommMonoid α] (m : Multiset α) : m.prod = ∏ x in m.toEnumFinset, x.1 := by congr
Mathlib.Data.Multiset.Fintype.267_0.gXgzg6nY9WO2bG2
@[to_additive] theorem Multiset.prod_eq_prod_toEnumFinset [CommMonoid α] (m : Multiset α) : m.prod = ∏ x in m.toEnumFinset, x.1
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝¹ : DecidableEq α m✝ : Multiset α β : Type u_2 inst✝ : CommMonoid β m : Multiset α f : α → ℕ → β ⊢ ∏ x in toEnumFinset m, f x.1 x.2 = ∏ x : ToType m, f x.fst ↑x.snd
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range] #align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst @[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by rw [Finset.image, Multiset.map_toEnumFinset_fst] #align multiset.image_to_enum_finset_fst Multiset.image_toEnumFinset_fst @[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst rw [← m.map_univ_coeEmbedding] at this simpa only [Finset.map_val, Multiset.coeEmbedding_apply, Multiset.map_map, Function.comp_apply] using this #align multiset.map_univ_coe Multiset.map_univ_coe @[simp] theorem Multiset.map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f := by erw [← Multiset.map_map] rw [Multiset.map_univ_coe] #align multiset.map_univ Multiset.map_univ @[simp] theorem Multiset.card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m := by rw [Finset.card, ← Multiset.card_map Prod.fst m.toEnumFinset.val] congr exact m.map_toEnumFinset_fst #align multiset.card_to_enum_finset Multiset.card_toEnumFinset @[simp] theorem Multiset.card_coe (m : Multiset α) : Fintype.card m = Multiset.card m := by rw [Fintype.card_congr m.coeEquiv] simp only [Fintype.card_coe, card_toEnumFinset] #align multiset.card_coe Multiset.card_coe @[to_additive] theorem Multiset.prod_eq_prod_coe [CommMonoid α] (m : Multiset α) : m.prod = ∏ x : m, (x : α) := by congr -- Porting note: `simp` fails with "maximum recursion depth has been reached" erw [map_univ_coe] #align multiset.prod_eq_prod_coe Multiset.prod_eq_prod_coe #align multiset.sum_eq_sum_coe Multiset.sum_eq_sum_coe @[to_additive] theorem Multiset.prod_eq_prod_toEnumFinset [CommMonoid α] (m : Multiset α) : m.prod = ∏ x in m.toEnumFinset, x.1 := by congr simp #align multiset.prod_eq_prod_to_enum_finset Multiset.prod_eq_prod_toEnumFinset #align multiset.sum_eq_sum_to_enum_finset Multiset.sum_eq_sum_toEnumFinset @[to_additive] theorem Multiset.prod_toEnumFinset {β : Type*} [CommMonoid β] (m : Multiset α) (f : α → ℕ → β) : ∏ x in m.toEnumFinset, f x.1 x.2 = ∏ x : m, f x x.2 := by
rw [Fintype.prod_equiv m.coeEquiv (fun x ↦ f x x.2) fun x ↦ f x.1.1 x.1.2]
@[to_additive] theorem Multiset.prod_toEnumFinset {β : Type*} [CommMonoid β] (m : Multiset α) (f : α → ℕ → β) : ∏ x in m.toEnumFinset, f x.1 x.2 = ∏ x : m, f x x.2 := by
Mathlib.Data.Multiset.Fintype.275_0.gXgzg6nY9WO2bG2
@[to_additive] theorem Multiset.prod_toEnumFinset {β : Type*} [CommMonoid β] (m : Multiset α) (f : α → ℕ → β) : ∏ x in m.toEnumFinset, f x.1 x.2 = ∏ x : m, f x x.2
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝¹ : DecidableEq α m✝ : Multiset α β : Type u_2 inst✝ : CommMonoid β m : Multiset α f : α → ℕ → β ⊢ ∏ x in toEnumFinset m, f x.1 x.2 = ∏ x : { x // x ∈ toEnumFinset m }, f (↑x).1 (↑x).2
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range] #align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst @[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by rw [Finset.image, Multiset.map_toEnumFinset_fst] #align multiset.image_to_enum_finset_fst Multiset.image_toEnumFinset_fst @[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst rw [← m.map_univ_coeEmbedding] at this simpa only [Finset.map_val, Multiset.coeEmbedding_apply, Multiset.map_map, Function.comp_apply] using this #align multiset.map_univ_coe Multiset.map_univ_coe @[simp] theorem Multiset.map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f := by erw [← Multiset.map_map] rw [Multiset.map_univ_coe] #align multiset.map_univ Multiset.map_univ @[simp] theorem Multiset.card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m := by rw [Finset.card, ← Multiset.card_map Prod.fst m.toEnumFinset.val] congr exact m.map_toEnumFinset_fst #align multiset.card_to_enum_finset Multiset.card_toEnumFinset @[simp] theorem Multiset.card_coe (m : Multiset α) : Fintype.card m = Multiset.card m := by rw [Fintype.card_congr m.coeEquiv] simp only [Fintype.card_coe, card_toEnumFinset] #align multiset.card_coe Multiset.card_coe @[to_additive] theorem Multiset.prod_eq_prod_coe [CommMonoid α] (m : Multiset α) : m.prod = ∏ x : m, (x : α) := by congr -- Porting note: `simp` fails with "maximum recursion depth has been reached" erw [map_univ_coe] #align multiset.prod_eq_prod_coe Multiset.prod_eq_prod_coe #align multiset.sum_eq_sum_coe Multiset.sum_eq_sum_coe @[to_additive] theorem Multiset.prod_eq_prod_toEnumFinset [CommMonoid α] (m : Multiset α) : m.prod = ∏ x in m.toEnumFinset, x.1 := by congr simp #align multiset.prod_eq_prod_to_enum_finset Multiset.prod_eq_prod_toEnumFinset #align multiset.sum_eq_sum_to_enum_finset Multiset.sum_eq_sum_toEnumFinset @[to_additive] theorem Multiset.prod_toEnumFinset {β : Type*} [CommMonoid β] (m : Multiset α) (f : α → ℕ → β) : ∏ x in m.toEnumFinset, f x.1 x.2 = ∏ x : m, f x x.2 := by rw [Fintype.prod_equiv m.coeEquiv (fun x ↦ f x x.2) fun x ↦ f x.1.1 x.1.2] ·
rw [← m.toEnumFinset.prod_coe_sort fun x ↦ f x.1 x.2]
@[to_additive] theorem Multiset.prod_toEnumFinset {β : Type*} [CommMonoid β] (m : Multiset α) (f : α → ℕ → β) : ∏ x in m.toEnumFinset, f x.1 x.2 = ∏ x : m, f x x.2 := by rw [Fintype.prod_equiv m.coeEquiv (fun x ↦ f x x.2) fun x ↦ f x.1.1 x.1.2] ·
Mathlib.Data.Multiset.Fintype.275_0.gXgzg6nY9WO2bG2
@[to_additive] theorem Multiset.prod_toEnumFinset {β : Type*} [CommMonoid β] (m : Multiset α) (f : α → ℕ → β) : ∏ x in m.toEnumFinset, f x.1 x.2 = ∏ x : m, f x x.2
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝¹ : DecidableEq α m✝ : Multiset α β : Type u_2 inst✝ : CommMonoid β m : Multiset α f : α → ℕ → β ⊢ ∀ (x : ToType m), f x.fst ↑x.snd = f (↑((coeEquiv m) x)).1 (↑((coeEquiv m) x)).2
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range] #align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst @[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by rw [Finset.image, Multiset.map_toEnumFinset_fst] #align multiset.image_to_enum_finset_fst Multiset.image_toEnumFinset_fst @[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst rw [← m.map_univ_coeEmbedding] at this simpa only [Finset.map_val, Multiset.coeEmbedding_apply, Multiset.map_map, Function.comp_apply] using this #align multiset.map_univ_coe Multiset.map_univ_coe @[simp] theorem Multiset.map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f := by erw [← Multiset.map_map] rw [Multiset.map_univ_coe] #align multiset.map_univ Multiset.map_univ @[simp] theorem Multiset.card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m := by rw [Finset.card, ← Multiset.card_map Prod.fst m.toEnumFinset.val] congr exact m.map_toEnumFinset_fst #align multiset.card_to_enum_finset Multiset.card_toEnumFinset @[simp] theorem Multiset.card_coe (m : Multiset α) : Fintype.card m = Multiset.card m := by rw [Fintype.card_congr m.coeEquiv] simp only [Fintype.card_coe, card_toEnumFinset] #align multiset.card_coe Multiset.card_coe @[to_additive] theorem Multiset.prod_eq_prod_coe [CommMonoid α] (m : Multiset α) : m.prod = ∏ x : m, (x : α) := by congr -- Porting note: `simp` fails with "maximum recursion depth has been reached" erw [map_univ_coe] #align multiset.prod_eq_prod_coe Multiset.prod_eq_prod_coe #align multiset.sum_eq_sum_coe Multiset.sum_eq_sum_coe @[to_additive] theorem Multiset.prod_eq_prod_toEnumFinset [CommMonoid α] (m : Multiset α) : m.prod = ∏ x in m.toEnumFinset, x.1 := by congr simp #align multiset.prod_eq_prod_to_enum_finset Multiset.prod_eq_prod_toEnumFinset #align multiset.sum_eq_sum_to_enum_finset Multiset.sum_eq_sum_toEnumFinset @[to_additive] theorem Multiset.prod_toEnumFinset {β : Type*} [CommMonoid β] (m : Multiset α) (f : α → ℕ → β) : ∏ x in m.toEnumFinset, f x.1 x.2 = ∏ x : m, f x x.2 := by rw [Fintype.prod_equiv m.coeEquiv (fun x ↦ f x x.2) fun x ↦ f x.1.1 x.1.2] · rw [← m.toEnumFinset.prod_coe_sort fun x ↦ f x.1 x.2] ·
intro x
@[to_additive] theorem Multiset.prod_toEnumFinset {β : Type*} [CommMonoid β] (m : Multiset α) (f : α → ℕ → β) : ∏ x in m.toEnumFinset, f x.1 x.2 = ∏ x : m, f x x.2 := by rw [Fintype.prod_equiv m.coeEquiv (fun x ↦ f x x.2) fun x ↦ f x.1.1 x.1.2] · rw [← m.toEnumFinset.prod_coe_sort fun x ↦ f x.1 x.2] ·
Mathlib.Data.Multiset.Fintype.275_0.gXgzg6nY9WO2bG2
@[to_additive] theorem Multiset.prod_toEnumFinset {β : Type*} [CommMonoid β] (m : Multiset α) (f : α → ℕ → β) : ∏ x in m.toEnumFinset, f x.1 x.2 = ∏ x : m, f x x.2
Mathlib_Data_Multiset_Fintype
α : Type u_1 inst✝¹ : DecidableEq α m✝ : Multiset α β : Type u_2 inst✝ : CommMonoid β m : Multiset α f : α → ℕ → β x : ToType m ⊢ f x.fst ↑x.snd = f (↑((coeEquiv m) x)).1 (↑((coeEquiv m) x)).2
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Prod.Lex #align_import data.multiset.fintype from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d" /-! # Multiset coercion to type This module defines a `hasCoeToSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. For `x : m`, then there is a coercion `↑x : α`, and `x.2` is a term of `Fin (m.count x)`. The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requires `decidableEq α` due to `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ open BigOperators variable {α : Type*} [DecidableEq α] {m : Multiset α} /-- Auxiliary definition for the `hasCoeToSort` instance. This prevents the `hasCoe m α` instance from inadvertently applying to other sigma types. One should not use this definition directly. -/ -- Porting note: @[nolint has_nonempty_instance] def Multiset.ToType (m : Multiset α) : Type _ := Σx : α, Fin (m.count x) #align multiset.to_type Multiset.ToType /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times with different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ -- Porting note: syntactic equality #noalign multiset.coe_sort_eq /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def Multiset.mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ #align multiset.mk_to_type Multiset.mkToType /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ -- Porting note: was `Coe m α` instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ #align multiset.has_coe_to_sort.has_coe instCoeSortMultisetType.instCoeOutToTypeₓ -- Porting note: syntactic equality #noalign multiset.fst_coe_eq_coe @[simp] theorem Multiset.coe_eq {x y : m} : (x : α) = (y : α) ↔ x.1 = y.1 := by cases x cases y rfl #align multiset.coe_eq Multiset.coe_eq -- @[simp] -- Porting note: dsimp can prove this theorem Multiset.coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl #align multiset.coe_mk Multiset.coe_mk @[simp] theorem Multiset.coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (pos_of_gt x.2.2) #align multiset.coe_mem Multiset.coe_mem @[simp] protected theorem Multiset.forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall #align multiset.forall_coe Multiset.forall_coe @[simp] protected theorem Multiset.exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists #align multiset.exists_coe Multiset.exists_coe instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (pos_of_gt h)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def Multiset.toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset #align multiset.to_enum_finset Multiset.toEnumFinset @[simp] theorem Multiset.mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset #align multiset.mem_to_enum_finset Multiset.mem_toEnumFinset theorem Multiset.mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := Multiset.count_pos.mp <| pos_of_gt <| (m.mem_toEnumFinset p).mp h #align multiset.mem_of_mem_to_enum_finset Multiset.mem_of_mem_toEnumFinset @[mono] theorem Multiset.toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1) #align multiset.to_enum_finset_mono Multiset.toEnumFinset_mono @[simp] theorem Multiset.toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := by refine' ⟨fun h ↦ _, Multiset.toEnumFinset_mono⟩ rw [Multiset.le_iff_count] intro x by_cases hx : x ∈ m₁ · apply Nat.le_of_pred_lt have : (x, m₁.count x - 1) ∈ m₁.toEnumFinset := by rw [Multiset.mem_toEnumFinset] exact Nat.pred_lt (ne_of_gt (Multiset.count_pos.mpr hx)) simpa only [Multiset.mem_toEnumFinset] using h this · simp [hx] #align multiset.to_enum_finset_subset_iff Multiset.toEnumFinset_subset_iff /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def Multiset.coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl #align multiset.coe_embedding Multiset.coeEmbedding /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def Multiset.coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ left_inv := by rintro ⟨x, i, h⟩ rfl right_inv := by rintro ⟨⟨x, i⟩, h⟩ rfl #align multiset.coe_equiv Multiset.coeEquiv @[simp] theorem Multiset.toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl #align multiset.to_embedding_coe_equiv_trans Multiset.toEmbedding_coeEquiv_trans @[irreducible] instance Multiset.fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm #align multiset.fintype_coe Multiset.fintypeCoe theorem Multiset.map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk.inj_iff, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, iff_self_iff, true_and_iff] #align multiset.map_univ_coe_embedding Multiset.map_univ_coeEmbedding theorem Multiset.toEnumFinset_filter_eq (m : Multiset α) (x : α) : (m.toEnumFinset.filter fun p ↦ x = p.1) = (Finset.range (m.count x)).map ⟨Prod.mk x, Prod.mk.inj_left x⟩ := by ext ⟨y, i⟩ simp only [eq_comm, Finset.mem_filter, Multiset.mem_toEnumFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk.inj_iff, exists_prop, exists_eq_right_right', and_congr_left_iff] rintro rfl rfl #align multiset.to_enum_finset_filter_eq Multiset.toEnumFinset_filter_eq @[simp] theorem Multiset.map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext x simp only [Multiset.count_map, ← Finset.filter_val, Multiset.toEnumFinset_filter_eq, Finset.map_val, Finset.range_val, Multiset.card_map, Multiset.card_range] #align multiset.map_to_enum_finset_fst Multiset.map_toEnumFinset_fst @[simp] theorem Multiset.image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by rw [Finset.image, Multiset.map_toEnumFinset_fst] #align multiset.image_to_enum_finset_fst Multiset.image_toEnumFinset_fst @[simp] theorem Multiset.map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst rw [← m.map_univ_coeEmbedding] at this simpa only [Finset.map_val, Multiset.coeEmbedding_apply, Multiset.map_map, Function.comp_apply] using this #align multiset.map_univ_coe Multiset.map_univ_coe @[simp] theorem Multiset.map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f := by erw [← Multiset.map_map] rw [Multiset.map_univ_coe] #align multiset.map_univ Multiset.map_univ @[simp] theorem Multiset.card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m := by rw [Finset.card, ← Multiset.card_map Prod.fst m.toEnumFinset.val] congr exact m.map_toEnumFinset_fst #align multiset.card_to_enum_finset Multiset.card_toEnumFinset @[simp] theorem Multiset.card_coe (m : Multiset α) : Fintype.card m = Multiset.card m := by rw [Fintype.card_congr m.coeEquiv] simp only [Fintype.card_coe, card_toEnumFinset] #align multiset.card_coe Multiset.card_coe @[to_additive] theorem Multiset.prod_eq_prod_coe [CommMonoid α] (m : Multiset α) : m.prod = ∏ x : m, (x : α) := by congr -- Porting note: `simp` fails with "maximum recursion depth has been reached" erw [map_univ_coe] #align multiset.prod_eq_prod_coe Multiset.prod_eq_prod_coe #align multiset.sum_eq_sum_coe Multiset.sum_eq_sum_coe @[to_additive] theorem Multiset.prod_eq_prod_toEnumFinset [CommMonoid α] (m : Multiset α) : m.prod = ∏ x in m.toEnumFinset, x.1 := by congr simp #align multiset.prod_eq_prod_to_enum_finset Multiset.prod_eq_prod_toEnumFinset #align multiset.sum_eq_sum_to_enum_finset Multiset.sum_eq_sum_toEnumFinset @[to_additive] theorem Multiset.prod_toEnumFinset {β : Type*} [CommMonoid β] (m : Multiset α) (f : α → ℕ → β) : ∏ x in m.toEnumFinset, f x.1 x.2 = ∏ x : m, f x x.2 := by rw [Fintype.prod_equiv m.coeEquiv (fun x ↦ f x x.2) fun x ↦ f x.1.1 x.1.2] · rw [← m.toEnumFinset.prod_coe_sort fun x ↦ f x.1 x.2] · intro x
rfl
@[to_additive] theorem Multiset.prod_toEnumFinset {β : Type*} [CommMonoid β] (m : Multiset α) (f : α → ℕ → β) : ∏ x in m.toEnumFinset, f x.1 x.2 = ∏ x : m, f x x.2 := by rw [Fintype.prod_equiv m.coeEquiv (fun x ↦ f x x.2) fun x ↦ f x.1.1 x.1.2] · rw [← m.toEnumFinset.prod_coe_sort fun x ↦ f x.1 x.2] · intro x
Mathlib.Data.Multiset.Fintype.275_0.gXgzg6nY9WO2bG2
@[to_additive] theorem Multiset.prod_toEnumFinset {β : Type*} [CommMonoid β] (m : Multiset α) (f : α → ℕ → β) : ∏ x in m.toEnumFinset, f x.1 x.2 = ∏ x : m, f x x.2
Mathlib_Data_Multiset_Fintype
C : Type u inst✝² : Category.{v, u} C inst✝¹ : Precoherent C inst✝ : HasFiniteCoproducts C X Y Z : C f : X ⟶ Y g : Z ⟶ Y x✝ : EffectiveEpi g ⊢ ∃ W h, ∃ (_ : EffectiveEpi h), ∃ i, i ≫ g = h ≫ f
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by
have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g)
instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by
Mathlib.CategoryTheory.Sites.RegularExtensive.77_0.rkSRr0zuqme90Yu
instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _
Mathlib_CategoryTheory_Sites_RegularExtensive
C : Type u inst✝² : Category.{v, u} C inst✝¹ : Precoherent C inst✝ : HasFiniteCoproducts C X Y Z : C f : X ⟶ Y g : Z ⟶ Y x✝ : EffectiveEpi g hp : (EffectiveEpiFamily (fun x => Z) fun x => match x with | PUnit.unit => g) → ∃ β x X₂ π₂, EffectiveEpiFamily X₂ π₂ ∧ ∃ i ι, ∀ (b : β), (ι b ≫ match i b with | PUnit.unit => g) = π₂ b ≫ f ⊢ ∃ W h, ∃ (_ : EffectiveEpi h), ∃ i, i ≫ g = h ≫ f
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g)
simp only [exists_const] at hp
instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g)
Mathlib.CategoryTheory.Sites.RegularExtensive.77_0.rkSRr0zuqme90Yu
instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _
Mathlib_CategoryTheory_Sites_RegularExtensive
C : Type u inst✝² : Category.{v, u} C inst✝¹ : Precoherent C inst✝ : HasFiniteCoproducts C X Y Z : C f : X ⟶ Y g : Z ⟶ Y x✝ : EffectiveEpi g hp : (EffectiveEpiFamily (fun x => Z) fun x => g) → ∃ β x X₂ π₂, EffectiveEpiFamily X₂ π₂ ∧ ∃ ι, ∀ (b : β), ι b ≫ g = π₂ b ≫ f ⊢ ∃ W h, ∃ (_ : EffectiveEpi h), ∃ i, i ≫ g = h ≫ f
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp
rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp
instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp
Mathlib.CategoryTheory.Sites.RegularExtensive.77_0.rkSRr0zuqme90Yu
instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _
Mathlib_CategoryTheory_Sites_RegularExtensive
C : Type u inst✝² : Category.{v, u} C inst✝¹ : Precoherent C inst✝ : HasFiniteCoproducts C X Y Z : C f : X ⟶ Y g : Z ⟶ Y x✝ : EffectiveEpi g hp : EffectiveEpi g → ∃ β x X₂ π₂, EffectiveEpiFamily X₂ π₂ ∧ ∃ ι, ∀ (b : β), ι b ≫ g = π₂ b ≫ f ⊢ ∃ W h, ∃ (_ : EffectiveEpi h), ∃ i, i ≫ g = h ≫ f
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp
obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance
instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp
Mathlib.CategoryTheory.Sites.RegularExtensive.77_0.rkSRr0zuqme90Yu
instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _
Mathlib_CategoryTheory_Sites_RegularExtensive
case intro.intro.intro.intro.intro.intro C : Type u inst✝² : Category.{v, u} C inst✝¹ : Precoherent C inst✝ : HasFiniteCoproducts C X Y Z : C f : X ⟶ Y g : Z ⟶ Y x✝ : EffectiveEpi g hp : EffectiveEpi g → ∃ β x X₂ π₂, EffectiveEpiFamily X₂ π₂ ∧ ∃ ι, ∀ (b : β), ι b ≫ g = π₂ b ≫ f β : Type w✝ : Fintype β X₂ : β → C π₂ : (b : β) → X₂ b ⟶ X h : EffectiveEpiFamily X₂ π₂ ι : (b : β) → X₂ b ⟶ Z hι : ∀ (b : β), ι b ≫ g = π₂ b ≫ f ⊢ ∃ W h, ∃ (_ : EffectiveEpi h), ∃ i, i ≫ g = h ≫ f
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance
refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩
instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance
Mathlib.CategoryTheory.Sites.RegularExtensive.77_0.rkSRr0zuqme90Yu
instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _
Mathlib_CategoryTheory_Sites_RegularExtensive
case intro.intro.intro.intro.intro.intro C : Type u inst✝² : Category.{v, u} C inst✝¹ : Precoherent C inst✝ : HasFiniteCoproducts C X Y Z : C f : X ⟶ Y g : Z ⟶ Y x✝ : EffectiveEpi g hp : EffectiveEpi g → ∃ β x X₂ π₂, EffectiveEpiFamily X₂ π₂ ∧ ∃ ι, ∀ (b : β), ι b ≫ g = π₂ b ≫ f β : Type w✝ : Fintype β X₂ : β → C π₂ : (b : β) → X₂ b ⟶ X h : EffectiveEpiFamily X₂ π₂ ι : (b : β) → X₂ b ⟶ Z hι : ∀ (b : β), ι b ≫ g = π₂ b ≫ f ⊢ Sigma.desc ι ≫ g = Sigma.desc π₂ ≫ f
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩
ext b
instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩
Mathlib.CategoryTheory.Sites.RegularExtensive.77_0.rkSRr0zuqme90Yu
instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _
Mathlib_CategoryTheory_Sites_RegularExtensive
case intro.intro.intro.intro.intro.intro.h C : Type u inst✝² : Category.{v, u} C inst✝¹ : Precoherent C inst✝ : HasFiniteCoproducts C X Y Z : C f : X ⟶ Y g : Z ⟶ Y x✝ : EffectiveEpi g hp : EffectiveEpi g → ∃ β x X₂ π₂, EffectiveEpiFamily X₂ π₂ ∧ ∃ ι, ∀ (b : β), ι b ≫ g = π₂ b ≫ f β : Type w✝ : Fintype β X₂ : β → C π₂ : (b : β) → X₂ b ⟶ X h : EffectiveEpiFamily X₂ π₂ ι : (b : β) → X₂ b ⟶ Z hι : ∀ (b : β), ι b ≫ g = π₂ b ≫ f b : β ⊢ Sigma.ι X₂ b ≫ Sigma.desc ι ≫ g = Sigma.ι X₂ b ≫ Sigma.desc π₂ ≫ f
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩ ext b
simpa using hι b
instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩ ext b
Mathlib.CategoryTheory.Sites.RegularExtensive.77_0.rkSRr0zuqme90Yu
instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _
Mathlib_CategoryTheory_Sites_RegularExtensive
C : Type u inst✝¹ : Category.{v, u} C inst✝ : Preregular C ⊢ ∀ ⦃X Y : C⦄ (f : Y ⟶ X), ∀ S ∈ (fun B => {S | ∃ X f, (S = Presieve.ofArrows (fun x => X) fun x => f) ∧ EffectiveEpi f}) X, ∃ T ∈ (fun B => {S | ∃ X f, (S = Presieve.ofArrows (fun x => X) fun x => f) ∧ EffectiveEpi f}) Y, Presieve.FactorsThruAlong T S f
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩ ext b simpa using hι b /-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by
intro X Y f S ⟨Z, π, hπ, h_epi⟩
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by
Mathlib.CategoryTheory.Sites.RegularExtensive.87_0.rkSRr0zuqme90Yu
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B
Mathlib_CategoryTheory_Sites_RegularExtensive
C : Type u inst✝¹ : Category.{v, u} C inst✝ : Preregular C X Y : C f : Y ⟶ X S : Presieve X Z : C π : Z ⟶ X hπ : S = Presieve.ofArrows (fun x => Z) fun x => π h_epi : EffectiveEpi π ⊢ ∃ T ∈ (fun B => {S | ∃ X f, (S = Presieve.ofArrows (fun x => X) fun x => f) ∧ EffectiveEpi f}) Y, Presieve.FactorsThruAlong T S f
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩ ext b simpa using hι b /-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩
have := Preregular.exists_fac f π
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩
Mathlib.CategoryTheory.Sites.RegularExtensive.87_0.rkSRr0zuqme90Yu
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B
Mathlib_CategoryTheory_Sites_RegularExtensive
C : Type u inst✝¹ : Category.{v, u} C inst✝ : Preregular C X Y : C f : Y ⟶ X S : Presieve X Z : C π : Z ⟶ X hπ : S = Presieve.ofArrows (fun x => Z) fun x => π h_epi : EffectiveEpi π this : ∃ W h, ∃ (_ : EffectiveEpi h), ∃ i, i ≫ π = h ≫ f ⊢ ∃ T ∈ (fun B => {S | ∃ X f, (S = Presieve.ofArrows (fun x => X) fun x => f) ∧ EffectiveEpi f}) Y, Presieve.FactorsThruAlong T S f
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩ ext b simpa using hι b /-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π
obtain ⟨W, h, _, i, this⟩ := this
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π
Mathlib.CategoryTheory.Sites.RegularExtensive.87_0.rkSRr0zuqme90Yu
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B
Mathlib_CategoryTheory_Sites_RegularExtensive
case intro.intro.intro.intro C : Type u inst✝¹ : Category.{v, u} C inst✝ : Preregular C X Y : C f : Y ⟶ X S : Presieve X Z : C π : Z ⟶ X hπ : S = Presieve.ofArrows (fun x => Z) fun x => π h_epi : EffectiveEpi π W : C h : W ⟶ Y w✝ : EffectiveEpi h i : W ⟶ Z this : i ≫ π = h ≫ f ⊢ ∃ T ∈ (fun B => {S | ∃ X f, (S = Presieve.ofArrows (fun x => X) fun x => f) ∧ EffectiveEpi f}) Y, Presieve.FactorsThruAlong T S f
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩ ext b simpa using hι b /-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this
refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this
Mathlib.CategoryTheory.Sites.RegularExtensive.87_0.rkSRr0zuqme90Yu
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B
Mathlib_CategoryTheory_Sites_RegularExtensive
case intro.intro.intro.intro.refine_1 C : Type u inst✝¹ : Category.{v, u} C inst✝ : Preregular C X Y : C f : Y ⟶ X S : Presieve X Z : C π : Z ⟶ X hπ : S = Presieve.ofArrows (fun x => Z) fun x => π h_epi : EffectiveEpi π W : C h : W ⟶ Y w✝ : EffectiveEpi h i : W ⟶ Z this : i ≫ π = h ≫ f ⊢ Presieve.singleton h ∈ (fun B => {S | ∃ X f, (S = Presieve.ofArrows (fun x => X) fun x => f) ∧ EffectiveEpi f}) Y
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩ ext b simpa using hι b /-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ ·
exact ⟨W, h, by {rw [Presieve.ofArrows_pUnit h]}, inferInstance⟩
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ ·
Mathlib.CategoryTheory.Sites.RegularExtensive.87_0.rkSRr0zuqme90Yu
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B
Mathlib_CategoryTheory_Sites_RegularExtensive
C : Type u inst✝¹ : Category.{v, u} C inst✝ : Preregular C X Y : C f : Y ⟶ X S : Presieve X Z : C π : Z ⟶ X hπ : S = Presieve.ofArrows (fun x => Z) fun x => π h_epi : EffectiveEpi π W : C h : W ⟶ Y w✝ : EffectiveEpi h i : W ⟶ Z this : i ≫ π = h ≫ f ⊢ Presieve.singleton h = Presieve.ofArrows (fun x => W) fun x => h
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩ ext b simpa using hι b /-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ · exact ⟨W, h, by
{rw [Presieve.ofArrows_pUnit h]}
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ · exact ⟨W, h, by
Mathlib.CategoryTheory.Sites.RegularExtensive.87_0.rkSRr0zuqme90Yu
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B
Mathlib_CategoryTheory_Sites_RegularExtensive
C : Type u inst✝¹ : Category.{v, u} C inst✝ : Preregular C X Y : C f : Y ⟶ X S : Presieve X Z : C π : Z ⟶ X hπ : S = Presieve.ofArrows (fun x => Z) fun x => π h_epi : EffectiveEpi π W : C h : W ⟶ Y w✝ : EffectiveEpi h i : W ⟶ Z this : i ≫ π = h ≫ f ⊢ Presieve.singleton h = Presieve.ofArrows (fun x => W) fun x => h
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩ ext b simpa using hι b /-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ · exact ⟨W, h, by {
rw [Presieve.ofArrows_pUnit h]
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ · exact ⟨W, h, by {
Mathlib.CategoryTheory.Sites.RegularExtensive.87_0.rkSRr0zuqme90Yu
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B
Mathlib_CategoryTheory_Sites_RegularExtensive
case intro.intro.intro.intro.refine_2 C : Type u inst✝¹ : Category.{v, u} C inst✝ : Preregular C X Y : C f : Y ⟶ X S : Presieve X Z : C π : Z ⟶ X hπ : S = Presieve.ofArrows (fun x => Z) fun x => π h_epi : EffectiveEpi π W : C h : W ⟶ Y w✝ : EffectiveEpi h i : W ⟶ Z this : i ≫ π = h ≫ f ⊢ Presieve.FactorsThruAlong (Presieve.singleton h) S f
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩ ext b simpa using hι b /-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ · exact ⟨W, h, by {rw [Presieve.ofArrows_pUnit h]}, inferInstance⟩ ·
intro W g hg
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ · exact ⟨W, h, by {rw [Presieve.ofArrows_pUnit h]}, inferInstance⟩ ·
Mathlib.CategoryTheory.Sites.RegularExtensive.87_0.rkSRr0zuqme90Yu
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B
Mathlib_CategoryTheory_Sites_RegularExtensive
case intro.intro.intro.intro.refine_2 C : Type u inst✝¹ : Category.{v, u} C inst✝ : Preregular C X Y : C f : Y ⟶ X S : Presieve X Z : C π : Z ⟶ X hπ : S = Presieve.ofArrows (fun x => Z) fun x => π h_epi : EffectiveEpi π W✝ : C h : W✝ ⟶ Y w✝ : EffectiveEpi h i : W✝ ⟶ Z this : i ≫ π = h ≫ f W : C g : W ⟶ Y hg : Presieve.singleton h g ⊢ ∃ W_1 i e, S e ∧ i ≫ e = g ≫ f
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩ ext b simpa using hι b /-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ · exact ⟨W, h, by {rw [Presieve.ofArrows_pUnit h]}, inferInstance⟩ · intro W g hg
cases hg
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ · exact ⟨W, h, by {rw [Presieve.ofArrows_pUnit h]}, inferInstance⟩ · intro W g hg
Mathlib.CategoryTheory.Sites.RegularExtensive.87_0.rkSRr0zuqme90Yu
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B
Mathlib_CategoryTheory_Sites_RegularExtensive
case intro.intro.intro.intro.refine_2.mk C : Type u inst✝¹ : Category.{v, u} C inst✝ : Preregular C X Y : C f : Y ⟶ X S : Presieve X Z : C π : Z ⟶ X hπ : S = Presieve.ofArrows (fun x => Z) fun x => π h_epi : EffectiveEpi π W : C h : W ⟶ Y w✝ : EffectiveEpi h i : W ⟶ Z this : i ≫ π = h ≫ f ⊢ ∃ W_1 i e, S e ∧ i ≫ e = h ≫ f
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩ ext b simpa using hι b /-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ · exact ⟨W, h, by {rw [Presieve.ofArrows_pUnit h]}, inferInstance⟩ · intro W g hg cases hg
refine ⟨Z, i, π, ⟨?_, this⟩⟩
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ · exact ⟨W, h, by {rw [Presieve.ofArrows_pUnit h]}, inferInstance⟩ · intro W g hg cases hg
Mathlib.CategoryTheory.Sites.RegularExtensive.87_0.rkSRr0zuqme90Yu
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B
Mathlib_CategoryTheory_Sites_RegularExtensive
case intro.intro.intro.intro.refine_2.mk C : Type u inst✝¹ : Category.{v, u} C inst✝ : Preregular C X Y : C f : Y ⟶ X S : Presieve X Z : C π : Z ⟶ X hπ : S = Presieve.ofArrows (fun x => Z) fun x => π h_epi : EffectiveEpi π W : C h : W ⟶ Y w✝ : EffectiveEpi h i : W ⟶ Z this : i ≫ π = h ≫ f ⊢ S π
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩ ext b simpa using hι b /-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ · exact ⟨W, h, by {rw [Presieve.ofArrows_pUnit h]}, inferInstance⟩ · intro W g hg cases hg refine ⟨Z, i, π, ⟨?_, this⟩⟩
cases hπ
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ · exact ⟨W, h, by {rw [Presieve.ofArrows_pUnit h]}, inferInstance⟩ · intro W g hg cases hg refine ⟨Z, i, π, ⟨?_, this⟩⟩
Mathlib.CategoryTheory.Sites.RegularExtensive.87_0.rkSRr0zuqme90Yu
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B
Mathlib_CategoryTheory_Sites_RegularExtensive
case intro.intro.intro.intro.refine_2.mk.refl C : Type u inst✝¹ : Category.{v, u} C inst✝ : Preregular C X Y : C f : Y ⟶ X Z : C π : Z ⟶ X h_epi : EffectiveEpi π W : C h : W ⟶ Y w✝ : EffectiveEpi h i : W ⟶ Z this : i ≫ π = h ≫ f ⊢ Presieve.ofArrows (fun x => Z) (fun x => π) π
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩ ext b simpa using hι b /-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ · exact ⟨W, h, by {rw [Presieve.ofArrows_pUnit h]}, inferInstance⟩ · intro W g hg cases hg refine ⟨Z, i, π, ⟨?_, this⟩⟩ cases hπ
rw [Presieve.ofArrows_pUnit]
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ · exact ⟨W, h, by {rw [Presieve.ofArrows_pUnit h]}, inferInstance⟩ · intro W g hg cases hg refine ⟨Z, i, π, ⟨?_, this⟩⟩ cases hπ
Mathlib.CategoryTheory.Sites.RegularExtensive.87_0.rkSRr0zuqme90Yu
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B
Mathlib_CategoryTheory_Sites_RegularExtensive
case intro.intro.intro.intro.refine_2.mk.refl C : Type u inst✝¹ : Category.{v, u} C inst✝ : Preregular C X Y : C f : Y ⟶ X Z : C π : Z ⟶ X h_epi : EffectiveEpi π W : C h : W ⟶ Y w✝ : EffectiveEpi h i : W ⟶ Z this : i ≫ π = h ≫ f ⊢ Presieve.singleton π π
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩ ext b simpa using hι b /-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ · exact ⟨W, h, by {rw [Presieve.ofArrows_pUnit h]}, inferInstance⟩ · intro W g hg cases hg refine ⟨Z, i, π, ⟨?_, this⟩⟩ cases hπ rw [Presieve.ofArrows_pUnit]
exact Presieve.singleton.mk
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ · exact ⟨W, h, by {rw [Presieve.ofArrows_pUnit h]}, inferInstance⟩ · intro W g hg cases hg refine ⟨Z, i, π, ⟨?_, this⟩⟩ cases hπ rw [Presieve.ofArrows_pUnit]
Mathlib.CategoryTheory.Sites.RegularExtensive.87_0.rkSRr0zuqme90Yu
/-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B
Mathlib_CategoryTheory_Sites_RegularExtensive
C : Type u inst✝¹ : Category.{v, u} C inst✝ : FinitaryPreExtensive C ⊢ ∀ ⦃X Y : C⦄ (f : Y ⟶ X), ∀ S ∈ (fun B => {S | ∃ α x X π, S = Presieve.ofArrows X π ∧ IsIso (Sigma.desc π)}) X, ∃ T ∈ (fun B => {S | ∃ α x X π, S = Presieve.ofArrows X π ∧ IsIso (Sigma.desc π)}) Y, Presieve.FactorsThruAlong T S f
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩ ext b simpa using hι b /-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ · exact ⟨W, h, by {rw [Presieve.ofArrows_pUnit h]}, inferInstance⟩ · intro W g hg cases hg refine ⟨Z, i, π, ⟨?_, this⟩⟩ cases hπ rw [Presieve.ofArrows_pUnit] exact Presieve.singleton.mk /-- The extensive coverage on an extensive category `C` TODO: use general colimit API instead of `IsIso (Sigma.desc π)` -/ def extensiveCoverage [FinitaryPreExtensive C] : Coverage C where covering B := { S | ∃ (α : Type) (_ : Fintype α) (X : α → C) (π : (a : α) → (X a ⟶ B)), S = Presieve.ofArrows X π ∧ IsIso (Sigma.desc π) } pullback := by
intro X Y f S ⟨α, hα, Z, π, hS, h_iso⟩
/-- The extensive coverage on an extensive category `C` TODO: use general colimit API instead of `IsIso (Sigma.desc π)` -/ def extensiveCoverage [FinitaryPreExtensive C] : Coverage C where covering B := { S | ∃ (α : Type) (_ : Fintype α) (X : α → C) (π : (a : α) → (X a ⟶ B)), S = Presieve.ofArrows X π ∧ IsIso (Sigma.desc π) } pullback := by
Mathlib.CategoryTheory.Sites.RegularExtensive.106_0.rkSRr0zuqme90Yu
/-- The extensive coverage on an extensive category `C` TODO: use general colimit API instead of `IsIso (Sigma.desc π)` -/ def extensiveCoverage [FinitaryPreExtensive C] : Coverage C where covering B
Mathlib_CategoryTheory_Sites_RegularExtensive
C : Type u inst✝¹ : Category.{v, u} C inst✝ : FinitaryPreExtensive C X Y : C f : Y ⟶ X S : Presieve X α : Type hα : Fintype α Z : α → C π : (a : α) → Z a ⟶ X hS : S = Presieve.ofArrows Z π h_iso : IsIso (Sigma.desc π) ⊢ ∃ T ∈ (fun B => {S | ∃ α x X π, S = Presieve.ofArrows X π ∧ IsIso (Sigma.desc π)}) Y, Presieve.FactorsThruAlong T S f
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Preadditive.Projective import Mathlib.CategoryTheory.Sites.Coherent import Mathlib.CategoryTheory.Sites.Preserves /-! # The Regular and Extensive Coverages This file defines two coverages on a category `C`. The first one is called the *regular* coverage and for that to exist, the category `C` must satisfy a condition called `Preregular C`. This means that effective epimorphisms can be "pulled back". The covering sieves of this coverage are generated by presieves consisting of a single effective epimorphism. The second one is called the *extensive* coverage and for that to exist, the category `C` must satisfy a condition called `FinitaryPreExtensive C`. This means `C` has finite coproducts and that those are preserved by pullbacks. The covering sieves of this coverage are generated by presieves consisting finitely many arrows that together induce an isomorphism from the coproduct to the target. This condition is weaker than `FinitaryExtensive`, where in addition finite coproducts are disjoint. ## Main results * `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`. * `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular. * `isSheaf_iff_equalizerCondition`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. * `isSheaf_iff_preservesFiniteProducts`: In a finitary extensive category, the sheaves for the extensive topology are precisely those preserving finite products. -/ universe v u w namespace CategoryTheory open Limits variable (C : Type u) [Category.{v} C] /-- The condition `Preregular C` is property that effective epis can be "pulled back" along any morphism. This is satisfied e.g. by categories that have pullbacks that preserve effective epimorphisms (like `Profinite` and `CompHaus`), and categories where every object is projective (like `Stonean`). -/ class Preregular : Prop where /-- For `X`, `Y`, `Z`, `f`, `g` like in the diagram, where `g` is an effective epi, there exists an object `W`, an effective epi `h : W ⟶ X` and a morphism `i : W ⟶ Z` making the diagram commute. ``` W --i-→ Z | | h g ↓ ↓ X --f-→ Y ``` -/ exists_fac : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) [EffectiveEpi g], (∃ (W : C) (h : W ⟶ X) (_ : EffectiveEpi h) (i : W ⟶ Z), i ≫ g = h ≫ f) instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where exists_fac {X Y Z} f g _ := by have hp := Precoherent.pullback f PUnit (fun () ↦ Z) (fun () ↦ g) simp only [exists_const] at hp rw [← effectiveEpi_iff_effectiveEpiFamily g] at hp obtain ⟨β, _, X₂, π₂, h, ι, hι⟩ := hp inferInstance refine ⟨∐ X₂, Sigma.desc π₂, inferInstance, Sigma.desc ι, ?_⟩ ext b simpa using hι b /-- The regular coverage on a regular category `C`. -/ def regularCoverage [Preregular C] : Coverage C where covering B := { S | ∃ (X : C) (f : X ⟶ B), S = Presieve.ofArrows (fun (_ : Unit) ↦ X) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f } pullback := by intro X Y f S ⟨Z, π, hπ, h_epi⟩ have := Preregular.exists_fac f π obtain ⟨W, h, _, i, this⟩ := this refine ⟨Presieve.singleton h, ⟨?_, ?_⟩⟩ · exact ⟨W, h, by {rw [Presieve.ofArrows_pUnit h]}, inferInstance⟩ · intro W g hg cases hg refine ⟨Z, i, π, ⟨?_, this⟩⟩ cases hπ rw [Presieve.ofArrows_pUnit] exact Presieve.singleton.mk /-- The extensive coverage on an extensive category `C` TODO: use general colimit API instead of `IsIso (Sigma.desc π)` -/ def extensiveCoverage [FinitaryPreExtensive C] : Coverage C where covering B := { S | ∃ (α : Type) (_ : Fintype α) (X : α → C) (π : (a : α) → (X a ⟶ B)), S = Presieve.ofArrows X π ∧ IsIso (Sigma.desc π) } pullback := by intro X Y f S ⟨α, hα, Z, π, hS, h_iso⟩
let Z' : α → C := fun a ↦ pullback f (π a)
/-- The extensive coverage on an extensive category `C` TODO: use general colimit API instead of `IsIso (Sigma.desc π)` -/ def extensiveCoverage [FinitaryPreExtensive C] : Coverage C where covering B := { S | ∃ (α : Type) (_ : Fintype α) (X : α → C) (π : (a : α) → (X a ⟶ B)), S = Presieve.ofArrows X π ∧ IsIso (Sigma.desc π) } pullback := by intro X Y f S ⟨α, hα, Z, π, hS, h_iso⟩
Mathlib.CategoryTheory.Sites.RegularExtensive.106_0.rkSRr0zuqme90Yu
/-- The extensive coverage on an extensive category `C` TODO: use general colimit API instead of `IsIso (Sigma.desc π)` -/ def extensiveCoverage [FinitaryPreExtensive C] : Coverage C where covering B
Mathlib_CategoryTheory_Sites_RegularExtensive