Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: split Logic.Nontrivial (#6959)
This continues reducing the import requirements for the basic algebraic hierarchy. In combination with #6954 #6955 #6956 #6957, this reduces the imports for `Mathlib.Algebra.Field.Defs` from * [before.pdf](https://github.com/leanprover-community/mathlib4/files/12518547/before.pdf) * [after.pdf](https://github.com/leanprover-community/mathlib4/files/12518546/after.pdf) Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
- Loading branch information
1 parent
6226f93
commit 560425d
Showing
15 changed files
with
129 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/- | ||
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Sébastien Gouëzel | ||
-/ | ||
import Mathlib.Logic.Nontrivial.Defs | ||
import Mathlib.Tactic.Attr.Register | ||
import Mathlib.Data.Prod.Basic | ||
import Mathlib.Data.Subtype | ||
import Mathlib.Logic.Function.Basic | ||
import Mathlib.Logic.Unique | ||
|
||
#align_import logic.nontrivial from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4" | ||
|
||
/-! | ||
# Nontrivial types | ||
Results about `Nontrivial`. | ||
-/ | ||
|
||
|
||
variable {α : Type*} {β : Type*} | ||
|
||
open Classical | ||
|
||
-- `x` and `y` are explicit here, as they are often needed to guide typechecking of `h`. | ||
theorem nontrivial_of_lt [Preorder α] (x y : α) (h : x < y) : Nontrivial α := | ||
⟨⟨x, y, ne_of_lt h⟩⟩ | ||
#align nontrivial_of_lt nontrivial_of_lt | ||
|
||
theorem exists_pair_lt (α : Type*) [Nontrivial α] [LinearOrder α] : ∃ x y : α, x < y := by | ||
rcases exists_pair_ne α with ⟨x, y, hxy⟩ | ||
cases lt_or_gt_of_ne hxy <;> exact ⟨_, _, ‹_›⟩ | ||
#align exists_pair_lt exists_pair_lt | ||
|
||
theorem nontrivial_iff_lt [LinearOrder α] : Nontrivial α ↔ ∃ x y : α, x < y := | ||
⟨fun h ↦ @exists_pair_lt α h _, fun ⟨x, y, h⟩ ↦ nontrivial_of_lt x y h⟩ | ||
#align nontrivial_iff_lt nontrivial_iff_lt | ||
|
||
theorem Subtype.nontrivial_iff_exists_ne (p : α → Prop) (x : Subtype p) : | ||
Nontrivial (Subtype p) ↔ ∃ (y : α) (_ : p y), y ≠ x := by | ||
simp only [_root_.nontrivial_iff_exists_ne x, Subtype.exists, Ne.def, Subtype.ext_iff] | ||
#align subtype.nontrivial_iff_exists_ne Subtype.nontrivial_iff_exists_ne | ||
|
||
/-- An inhabited type is either nontrivial, or has a unique element. -/ | ||
noncomputable def nontrivialPSumUnique (α : Type*) [Inhabited α] : | ||
PSum (Nontrivial α) (Unique α) := | ||
if h : Nontrivial α then PSum.inl h | ||
else | ||
PSum.inr | ||
{ default := default, | ||
uniq := fun x : α ↦ by | ||
by_contra H | ||
exact h ⟨_, _, H⟩ } | ||
#align nontrivial_psum_unique nontrivialPSumUnique | ||
|
||
instance Option.nontrivial [Nonempty α] : Nontrivial (Option α) := by | ||
inhabit α | ||
exact ⟨none, some default, fun .⟩ | ||
|
||
/-- Pushforward a `Nontrivial` instance along an injective function. -/ | ||
protected theorem Function.Injective.nontrivial [Nontrivial α] {f : α → β} | ||
(hf : Function.Injective f) : Nontrivial β := | ||
let ⟨x, y, h⟩ := exists_pair_ne α | ||
⟨⟨f x, f y, hf.ne h⟩⟩ | ||
#align function.injective.nontrivial Function.Injective.nontrivial | ||
|
||
/-- An injective function from a nontrivial type has an argument at | ||
which it does not take a given value. -/ | ||
protected theorem Function.Injective.exists_ne [Nontrivial α] {f : α → β} | ||
(hf : Function.Injective f) (y : β) : ∃ x, f x ≠ y := by | ||
rcases exists_pair_ne α with ⟨x₁, x₂, hx⟩ | ||
by_cases h:f x₂ = y | ||
· exact ⟨x₁, (hf.ne_iff' h).2 hx⟩ | ||
· exact ⟨x₂, h⟩ | ||
#align function.injective.exists_ne Function.Injective.exists_ne | ||
|
||
instance nontrivial_prod_right [Nonempty α] [Nontrivial β] : Nontrivial (α × β) := | ||
Prod.snd_surjective.nontrivial | ||
|
||
instance nontrivial_prod_left [Nontrivial α] [Nonempty β] : Nontrivial (α × β) := | ||
Prod.fst_surjective.nontrivial | ||
|
||
namespace Pi | ||
|
||
variable {I : Type*} {f : I → Type*} | ||
|
||
/-- A pi type is nontrivial if it's nonempty everywhere and nontrivial somewhere. -/ | ||
theorem nontrivial_at (i' : I) [inst : ∀ i, Nonempty (f i)] [Nontrivial (f i')] : | ||
Nontrivial (∀ i : I, f i) := by | ||
letI := Classical.decEq (∀ i : I, f i) | ||
exact (Function.update_injective (fun i ↦ Classical.choice (inst i)) i').nontrivial | ||
#align pi.nontrivial_at Pi.nontrivial_at | ||
|
||
/-- As a convenience, provide an instance automatically if `(f default)` is nontrivial. | ||
If a different index has the non-trivial type, then use `haveI := nontrivial_at that_index`. | ||
-/ | ||
instance nontrivial [Inhabited I] [∀ i, Nonempty (f i)] [Nontrivial (f default)] : | ||
Nontrivial (∀ i : I, f i) := | ||
nontrivial_at default | ||
|
||
end Pi | ||
|
||
instance Function.nontrivial [h : Nonempty α] [Nontrivial β] : Nontrivial (α → β) := | ||
h.elim fun a ↦ Pi.nontrivial_at a | ||
|
||
@[nontriviality] | ||
protected theorem Subsingleton.le [Preorder α] [Subsingleton α] (x y : α) : x ≤ y := | ||
le_of_eq (Subsingleton.elim x y) | ||
#align subsingleton.le Subsingleton.le | ||
|
||
@[to_additive] | ||
theorem Subsingleton.eq_one [One α] [Subsingleton α] (a : α) : a = 1 := | ||
Subsingleton.elim _ _ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters