Skip to content
Merged
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
16 changes: 9 additions & 7 deletions Cslib/Foundations/Data/HasFresh.lean
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,17 @@ end

export HasFresh (fresh fresh_notMem fresh_exists)

set_option linter.unusedFintypeInType false in
lemma HasFresh.not_of_finite (α : Type u) [Fintype α] : IsEmpty (HasFresh α) :=
⟨fun f ↦ (f.fresh_notMem .univ).elim (Finset.mem_univ _)⟩
/-- `HasFresh α` implies a computably infinite type. -/
instance HasFresh.to_infinite (α : Type u) [HasFresh α] : Infinite α := by
apply Infinite.of_not_fintype
rintro ⟨elems, _⟩
grind [fresh_notMem elems]

/-- All infinite types have an associated (at least noncomputable) fresh function.
This, in conjunction with `HasFresh.not_of_finite`, characterizes `HasFresh`. -/
noncomputable def HasFresh.of_infinite (α : Type u) [Infinite α] : HasFresh α where
fresh s := s.finite_toSet.infinite_compl.nonempty.choose
fresh_notMem s := s.finite_toSet.infinite_compl.nonempty.choose_spec
This, in conjunction with `HasFresh.to_infinite`, characterizes `HasFresh`. -/
noncomputable instance HasFresh.of_infinite (α : Type u) [Infinite α] : HasFresh α where
fresh s := Infinite.exists_notMem_finset s |>.choose
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't know what the preferred style is: should there be a space between |> and .?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are semantically different:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know that. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, I wonder if (Infinite.exists_notMem_finset s).choose is actually clearer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fairly ambivalent, but I think this is a common enough core syntax to not be considered obfuscatory. I wrote it without thinking, not as a golfing attempt.

fresh_notMem s := by grind

open Finset in
/-- Construct a fresh element from an embedding of `ℕ` using `Nat.find`. -/
Expand Down