Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

chore(data/multiset): move has_repr into its own file to remove data.string.basic import #18075

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/data/finset/default.lean
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ import data.finset.pi
import data.finset.powerset
import data.finset.sort
import data.finset.preimage
import data.finset.repr
13 changes: 13 additions & 0 deletions src/data/finset/repr.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.multiset.repr
import data.finset.sort

/-!
# Representing a finset as a string
-/

instance {α : Type*} [has_repr α] : has_repr (finset α) := ⟨λ s, repr s.1⟩
2 changes: 0 additions & 2 deletions src/data/finset/sort.lean
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,4 @@ by simp only [order_emb_of_card_le, rel_embedding.coe_trans, finset.order_emb_of

end sort_linear_order

instance [has_repr α] : has_repr (finset α) := ⟨λ s, repr s.1⟩

end finset
9 changes: 0 additions & 9 deletions src/data/list/cycle.lean → src/data/list/cycle/basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -726,15 +726,6 @@ by { rw [←next_reverse_eq_prev, ←mem_reverse_iff], apply next_mem }

end decidable

/--
We define a representation of concrete cycles, available when viewing them in a goal state or
via `#eval`, when over representatble types. For example, the cycle `(2 1 4 3)` will be shown
as `c[1, 4, 3, 2]`. The representation of the cycle sorts the elements by the string value of the
underlying element. This representation also supports cycles that can contain duplicates.
-/
instance [has_repr α] : has_repr (cycle α) :=
⟨λ s, "c[" ++ string.intercalate ", " ((s.map repr).lists.sort (≤)).head ++ "]"⟩

/-- `chain R s` means that `R` holds between adjacent elements of `s`.

`chain R ([a, b, c] : cycle α) ↔ R a b ∧ R b c ∧ R c a` -/
Expand Down
1 change: 1 addition & 0 deletions src/data/list/cycle/default.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import data.list.cycle.repr
20 changes: 20 additions & 0 deletions src/data/list/cycle/repr.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/-
Copyright (c) 2021 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import data.list.cycle.basic
import data.multiset.repr

/-!
# Representing a cycle as a string
-/

/--
We define a representation of concrete cycles, available when viewing them in a goal state or
via `#eval`, when over representatble types. For example, the cycle `(2 1 4 3)` will be shown
as `c[1, 4, 3, 2]`. The representation of the cycle sorts the elements by the string value of the
underlying element. This representation also supports cycles that can contain duplicates.
-/
instance {α : Type*} [has_repr α] : has_repr (cycle α) :=
⟨λ s, "c[" ++ string.intercalate ", " ((s.map repr).lists.sort (≤)).head ++ "]"⟩
1 change: 1 addition & 0 deletions src/data/multiset/default.lean
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ import data.multiset.pi
import data.multiset.powerset
import data.multiset.sections
import data.multiset.sort
import data.multiset.repr
14 changes: 14 additions & 0 deletions src/data/multiset/repr.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.multiset.sort
import data.string.basic

/-!
# Representing a multiset as a string
-/

instance {α : Type*} [has_repr α] : has_repr (multiset α) :=
⟨λ s, "{" ++ string.intercalate ", " ((s.map repr).sort (≤)) ++ "}"⟩
4 changes: 0 additions & 4 deletions src/data/multiset/sort.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Authors: Mario Carneiro
-/
import data.list.sort
import data.multiset.basic
import data.string.basic

/-!
# Construct a sorted list from a multiset.
Expand Down Expand Up @@ -50,7 +49,4 @@ list.merge_sort_singleton r a

end sort

instance [has_repr α] : has_repr (multiset α) :=
⟨λ s, "{" ++ string.intercalate ", " ((s.map repr).sort (≤)) ++ "}"⟩

end multiset
6 changes: 5 additions & 1 deletion src/data/pnat/factors.lean
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ the multiplicity of `p` in this factors multiset being the p-adic valuation of `
/-- The type of multisets of prime numbers. Unique factorization
gives an equivalence between this set and ℕ+, as we will formalize
below. -/
@[derive [inhabited, has_repr, canonically_ordered_add_monoid, distrib_lattice,
@[derive [inhabited, canonically_ordered_add_monoid, distrib_lattice,
semilattice_sup, order_bot, has_sub, has_ordered_sub]]
def prime_multiset := multiset nat.primes

-- We could use the `repr` for multisets here, but we want to reduce imports
instance : has_repr prime_multiset :=
⟨λ m, repr ((m.map (coe : nat.primes → nat)).sort (≤))⟩

namespace prime_multiset

/-- The multiset consisting of a single prime -/
Expand Down