-
Notifications
You must be signed in to change notification settings - Fork 710
[Merged by Bors] - chore(NNRat): Rearrange imports #10392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b60593c
chore(NNRat): Rearrange imports
YaelDillies 66084ae
not quite lexicographic to me
YaelDillies e13bc04
fix Data.NNRat.Lemmas
YaelDillies f533fa6
rename Data.Rat.Basic to Data.Rat.Field
YaelDillies f1bfab0
fix Combinatorics.Additive.PluenneckeRuzsa
YaelDillies 91f602c
fix Data.Real.NNReal
YaelDillies a2b6aba
fix qify test
YaelDillies 8aebc2f
update module doc
YaelDillies bfc3cae
slight cleanup
YaelDillies 71044ae
`assert_not_exists`
YaelDillies d3ace15
explain shortcut
YaelDillies File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps this should be called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's more than just the field instance, though? |
This file contains hidden or 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,95 @@ | ||
/- | ||
Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Yaël Dillies, Bhavik Mehta | ||
-/ | ||
import Mathlib.Algebra.Function.Indicator | ||
import Mathlib.Algebra.Order.Nonneg.Field | ||
import Mathlib.Data.NNRat.Defs | ||
|
||
#align_import data.rat.nnrat from "leanprover-community/mathlib"@"b3f4f007a962e3787aa0f3b5c7942a1317f7d88e" | ||
|
||
/-! | ||
# Algebraic structures on the nonnegative rationals | ||
YaelDillies marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
This file provides additional results about `nnrat` that cannot live in earlier files due to import | ||
YaelDillies marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cycles. | ||
-/ | ||
|
||
open Function | ||
open scoped NNRat | ||
|
||
deriving instance CanonicallyLinearOrderedSemifield, LinearOrderedCommGroupWithZero for NNRat | ||
YaelDillies marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
instance instDenselyOrdered : DenselyOrdered NNRat := Nonneg.densely_ordered | ||
|
||
namespace NNRat | ||
variable {α : Type*} {p q : ℚ≥0} | ||
|
||
open Rat (toNNRat) | ||
YaelDillies marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@[simp, norm_cast] lemma coe_inv (q : ℚ≥0) : ((q⁻¹ : ℚ≥0) : ℚ) = (q : ℚ)⁻¹ := rfl | ||
#align nnrat.coe_inv NNRat.coe_inv | ||
|
||
@[simp, norm_cast] lemma coe_div (p q : ℚ≥0) : ((p / q : ℚ≥0) : ℚ) = p / q := rfl | ||
#align nnrat.coe_div NNRat.coe_div | ||
|
||
/-- A `MulAction` over `ℚ` restricts to a `MulAction` over `ℚ≥0`. -/ | ||
instance [MulAction ℚ α] : MulAction ℚ≥0 α := | ||
MulAction.compHom α coeHom.toMonoidHom | ||
|
||
/-- A `DistribMulAction` over `ℚ` restricts to a `DistribMulAction` over `ℚ≥0`. -/ | ||
instance [AddCommMonoid α] [DistribMulAction ℚ α] : DistribMulAction ℚ≥0 α := | ||
DistribMulAction.compHom α coeHom.toMonoidHom | ||
|
||
@[simp, norm_cast] | ||
lemma coe_indicator (s : Set α) (f : α → ℚ≥0) (a : α) : | ||
((s.indicator f a : ℚ≥0) : ℚ) = s.indicator (fun x ↦ ↑(f x)) a := | ||
(coeHom : ℚ≥0 →+ ℚ).map_indicator _ _ _ | ||
#align nnrat.coe_indicator NNRat.coe_indicator | ||
|
||
end NNRat | ||
|
||
open NNRat | ||
|
||
namespace Rat | ||
|
||
variable {p q : ℚ} | ||
|
||
lemma toNNRat_inv (q : ℚ) : toNNRat q⁻¹ = (toNNRat q)⁻¹ := by | ||
obtain hq | hq := le_total q 0 | ||
· rw [toNNRat_eq_zero.mpr hq, inv_zero, toNNRat_eq_zero.mpr (inv_nonpos.mpr hq)] | ||
· nth_rw 1 [← Rat.coe_toNNRat q hq] | ||
rw [← coe_inv, toNNRat_coe] | ||
#align rat.to_nnrat_inv Rat.toNNRat_inv | ||
|
||
lemma toNNRat_div (hp : 0 ≤ p) : toNNRat (p / q) = toNNRat p / toNNRat q := by | ||
rw [div_eq_mul_inv, div_eq_mul_inv, ← toNNRat_inv, ← toNNRat_mul hp] | ||
#align rat.to_nnrat_div Rat.toNNRat_div | ||
|
||
lemma toNNRat_div' (hq : 0 ≤ q) : toNNRat (p / q) = toNNRat p / toNNRat q := by | ||
rw [div_eq_inv_mul, div_eq_inv_mul, toNNRat_mul (inv_nonneg.2 hq), toNNRat_inv] | ||
#align rat.to_nnrat_div' Rat.toNNRat_div' | ||
|
||
end Rat | ||
|
||
/-! ### Numerator and denominator -/ | ||
|
||
namespace NNRat | ||
|
||
variable {p q : ℚ≥0} | ||
|
||
@[simp] | ||
lemma num_div_den (q : ℚ≥0) : (q.num : ℚ≥0) / q.den = q := by | ||
ext : 1 | ||
rw [coe_div, coe_natCast, coe_natCast, num, ← Int.cast_ofNat, | ||
Int.natAbs_of_nonneg (Rat.num_nonneg_iff_zero_le.2 q.prop)] | ||
exact Rat.num_div_den q | ||
#align nnrat.num_div_denom NNRat.num_div_den | ||
|
||
/-- A recursor for nonnegative rationals in terms of numerators and denominators. -/ | ||
protected def rec {α : ℚ≥0 → Sort*} (h : ∀ m n : ℕ, α (m / n)) (q : ℚ≥0) : α q := by | ||
rw [← num_div_den q]; apply h | ||
#align nnrat.rec NNRat.rec | ||
|
||
end NNRat |
This file contains hidden or 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
YaelDillies marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.