data.rat.starMathlib.Data.Rat.Star

This file has been ported!

Changes since the initial port

The following section lists changes to this file in mathlib3 and mathlib4 that occured after the initial port. Most recent changes are shown first. Hovering over a commit will show all commits associated with the same mathlib3 commit.

Changes in mathlib3

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(last sync)

Changes in mathlib3port

mathlib3
mathlib3port
Diff
@@ -30,7 +30,7 @@ instance : StarRing ℚ where
 instance : TrivialStar ℚ where star_trivial _ := rfl
 
 instance : StarOrderedRing ℚ :=
-  StarOrderedRing.ofNonnegIff (fun _ _ => add_le_add_left) fun x =>
+  StarOrderedRing.of_nonneg_iff (fun _ _ => add_le_add_left) fun x =>
     by
     refine'
       ⟨fun hx => _, fun hx =>
@@ -52,7 +52,7 @@ instance : StarOrderedRing ℚ :=
     simp only [Int.cast_mul, Int.cast_natCast, coe_int_eq_mk, coe_nat_eq_mk]
     rw [mul_assoc, ← mul_assoc (mk (x.denom : ℤ) 1), mk_mul_mk_cancel one_ne_zero, ←
       one_mul (x.denom : ℤ), div_mk_div_cancel_left (by simpa using x.pos.ne' : (x.denom : ℤ) ≠ 0),
-      one_mul, mk_one_one, one_mul, mk_mul_mk_cancel one_ne_zero, Rat.num_den]
+      one_mul, mk_one_one, one_mul, mk_mul_mk_cancel one_ne_zero, Rat.num_divInt_den]
 
 end Rat
 
Diff
@@ -47,9 +47,9 @@ instance : StarOrderedRing ℚ :=
         x
       by exact this ▸ sum_mem fun n hn => AddSubmonoid.subset_closure ⟨_, rfl⟩
     simp only [Function.const_apply, Finset.sum_const, Finset.card_range, nsmul_eq_mul, mk_pnat_eq]
-    rw [← Int.cast_ofNat, Int.ofNat_mul, Int.natCast_natAbs,
-      abs_of_nonneg (num_nonneg_iff_zero_le.mpr hx), Int.cast_mul, Int.cast_ofNat]
-    simp only [Int.cast_mul, Int.cast_ofNat, coe_int_eq_mk, coe_nat_eq_mk]
+    rw [← Int.cast_natCast, Int.ofNat_mul, Int.natCast_natAbs,
+      abs_of_nonneg (num_nonneg_iff_zero_le.mpr hx), Int.cast_mul, Int.cast_natCast]
+    simp only [Int.cast_mul, Int.cast_natCast, coe_int_eq_mk, coe_nat_eq_mk]
     rw [mul_assoc, ← mul_assoc (mk (x.denom : ℤ) 1), mk_mul_mk_cancel one_ne_zero, ←
       one_mul (x.denom : ℤ), div_mk_div_cancel_left (by simpa using x.pos.ne' : (x.denom : ℤ) ≠ 0),
       one_mul, mk_one_one, one_mul, mk_mul_mk_cancel one_ne_zero, Rat.num_den]
Diff
@@ -47,7 +47,7 @@ instance : StarOrderedRing ℚ :=
         x
       by exact this ▸ sum_mem fun n hn => AddSubmonoid.subset_closure ⟨_, rfl⟩
     simp only [Function.const_apply, Finset.sum_const, Finset.card_range, nsmul_eq_mul, mk_pnat_eq]
-    rw [← Int.cast_ofNat, Int.ofNat_mul, Int.coe_natAbs,
+    rw [← Int.cast_ofNat, Int.ofNat_mul, Int.natCast_natAbs,
       abs_of_nonneg (num_nonneg_iff_zero_le.mpr hx), Int.cast_mul, Int.cast_ofNat]
     simp only [Int.cast_mul, Int.cast_ofNat, coe_int_eq_mk, coe_nat_eq_mk]
     rw [mul_assoc, ← mul_assoc (mk (x.denom : ℤ) 1), mk_mul_mk_cancel one_ne_zero, ←
Diff
@@ -34,7 +34,7 @@ instance : StarOrderedRing ℚ :=
     by
     refine'
       ⟨fun hx => _, fun hx =>
-        AddSubmonoid.closure_induction hx (by rintro - ⟨s, rfl⟩; exact mul_self_nonneg s) le_rfl
+        AddSubmonoid.closure_induction hx (by rintro - ⟨s, rfl⟩; exact hMul_self_nonneg s) le_rfl
           fun _ _ => add_nonneg⟩
     /- If `x = p / q`, then, since `0 ≤ x`, we have `p q : ℕ`, and `p / q` is the sum of `p * q`
       copies of `(1 / q) ^ 2`, and so `x` lies in the `add_submonoid` generated by square elements.
Diff
@@ -3,9 +3,9 @@ Copyright (c) 2023 Jireh Loreaux. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Jireh Loreaux
 -/
-import Mathbin.Algebra.Star.Order
-import Mathbin.Data.Rat.Lemmas
-import Mathbin.GroupTheory.Submonoid.Membership
+import Algebra.Star.Order
+import Data.Rat.Lemmas
+import GroupTheory.Submonoid.Membership
 
 #align_import data.rat.star from "leanprover-community/mathlib"@"6b31d1eebd64eab86d5bd9936bfaada6ca8b5842"
 
Diff
@@ -24,7 +24,7 @@ namespace Rat
 instance : StarRing ℚ where
   unit := id
   star_involutive _ := rfl
-  star_mul _ _ := mul_comm _ _
+  star_hMul _ _ := mul_comm _ _
   star_add _ _ := rfl
 
 instance : TrivialStar ℚ where star_trivial _ := rfl
Diff
@@ -2,16 +2,13 @@
 Copyright (c) 2023 Jireh Loreaux. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Jireh Loreaux
-
-! This file was ported from Lean 3 source module data.rat.star
-! leanprover-community/mathlib commit 6b31d1eebd64eab86d5bd9936bfaada6ca8b5842
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
 -/
 import Mathbin.Algebra.Star.Order
 import Mathbin.Data.Rat.Lemmas
 import Mathbin.GroupTheory.Submonoid.Membership
 
+#align_import data.rat.star from "leanprover-community/mathlib"@"6b31d1eebd64eab86d5bd9936bfaada6ca8b5842"
+
 /-! # Star order structure on ℚ
 
 > THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
Diff
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Jireh Loreaux
 
 ! This file was ported from Lean 3 source module data.rat.star
-! leanprover-community/mathlib commit 31c24aa72e7b3e5ed97a8412470e904f82b81004
+! leanprover-community/mathlib commit 6b31d1eebd64eab86d5bd9936bfaada6ca8b5842
 ! Please do not edit these lines, except to modify the commit id
 ! if you have ported upstream changes.
 -/
@@ -14,6 +14,9 @@ import Mathbin.GroupTheory.Submonoid.Membership
 
 /-! # Star order structure on ℚ
 
+> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
+> Any changes to this file require a corresponding PR to mathlib4.
+
 Here we put the trivial `star` operation on `ℚ` for convenience and show that it is a
 `star_ordered_ring`. In particular, this means that every element of `ℚ` is a sum of squares.
 -/

Changes in mathlib4

mathlib3
mathlib4
feat: , and ℚ≥0 are star-ordered rings (#10633)

Also golf the existing instance for and rename Rat.num_nonneg_iff_zero_le to Rat.num_nonneg, Rat.num_pos_iff_pos to Rat.num_pos.

From LeanAPAP

Diff
@@ -1,52 +1,64 @@
 /-
 Copyright (c) 2023 Jireh Loreaux. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
-Authors: Jireh Loreaux
+Authors: Jireh Loreaux, Yaël Dillies
 -/
+import Mathlib.Algebra.GroupWithZero.Power
+import Mathlib.Algebra.Parity
 import Mathlib.Algebra.Star.Order
-import Mathlib.Data.Rat.Lemmas
-import Mathlib.Data.Rat.Order
-import Mathlib.GroupTheory.Submonoid.Membership
+import Mathlib.Data.NNRat.Lemmas
+import Mathlib.GroupTheory.Submonoid.Order
+import Mathlib.Tactic.FieldSimp
 
 #align_import data.rat.star from "leanprover-community/mathlib"@"31c24aa72e7b3e5ed97a8412470e904f82b81004"
 
-/-! # Star order structure on ℚ
+/-!
+# Star ordered ring structures on `ℚ` and `ℚ≥0`
 
-Here we put the trivial `star` operation on `ℚ` for convenience and show that it is a
-`StarOrderedRing`. In particular, this means that every element of `ℚ` is a sum of squares.
+This file shows that `ℚ` and `ℚ≥0` are `StarOrderedRing`s. In particular, this means that every
+nonnegative rational number is a sum of squares.
 -/
 
+open AddSubmonoid Set
+open scoped NNRat
+
+namespace NNRat
+
+@[simp] lemma addSubmonoid_closure_range_pow {n : ℕ} (hn₀ : n ≠ 0) :
+    closure (range fun x : ℚ≥0 ↦ x ^ n) = ⊤ := by
+  refine (eq_top_iff' _).2 fun x ↦ ?_
+  suffices x = (x.num * x.den ^ (n - 1)) • (x.den : ℚ≥0)⁻¹ ^ n by
+    rw [this]
+    exact nsmul_mem (subset_closure <| mem_range_self _) _
+  rw [nsmul_eq_mul]
+  push_cast
+  rw [mul_assoc, pow_sub₀, pow_one, mul_right_comm, ← mul_pow, mul_inv_cancel, one_pow, one_mul,
+    ← div_eq_mul_inv, num_div_den]
+  all_goals simp [x.den_pos.ne', Nat.one_le_iff_ne_zero, *]
+
+@[simp] lemma addSubmonoid_closure_range_mul_self : closure (range fun x : ℚ≥0 ↦ x * x) = ⊤ := by
+  simpa only [sq] using addSubmonoid_closure_range_pow two_ne_zero
+
+instance instStarOrderedRing : StarOrderedRing ℚ≥0 where
+  le_iff a b := by simp [le_iff_exists_nonneg_add a b]
+
+end NNRat
 
 namespace Rat
 
-instance : StarRing ℚ where
-  star := id
-  star_involutive _ := rfl
-  star_mul _ _ := mul_comm _ _
-  star_add _ _ := rfl
-
-instance : TrivialStar ℚ where star_trivial _ := rfl
-
-instance : StarOrderedRing ℚ :=
-  StarOrderedRing.ofNonnegIff (fun {_ _} => add_le_add_left) fun x => by
-    refine'
-      ⟨fun hx => _, fun hx =>
-        AddSubmonoid.closure_induction hx (by rintro - ⟨s, rfl⟩; exact mul_self_nonneg s) le_rfl
-          fun _ _ => add_nonneg⟩
-    /- If `x = p / q`, then, since `0 ≤ x`, we have `p q : ℕ`, and `p / q` is the sum of `p * q`
-      copies of `(1 / q) ^ 2`, and so `x` lies in the `AddSubmonoid` generated by square elements.
-
-      Note: it's possible to rephrase this argument as `x = (p * q) • (1 / q) ^ 2`, but this would
-      be somewhat challenging without increasing import requirements. -/
-    -- Porting note: rewrote proof to avoid removed constructor rat.mk_pnat
-    suffices
-      (Finset.range (x.num.natAbs * x.den)).sum
-          (Function.const ℕ ((1 : ℚ) / x.den * ((1 : ℚ) / x.den))) =
-        x
-      by exact this ▸ sum_mem fun n _ => AddSubmonoid.subset_closure ⟨_, rfl⟩
-    simp only [Function.const_apply, Finset.sum_const, Finset.card_range, nsmul_eq_mul]
-    rw [← Int.cast_ofNat, Int.ofNat_mul, Int.coe_natAbs,
-      abs_of_nonneg (num_nonneg.mpr hx), Int.cast_mul, Int.cast_ofNat]
-    rw [← mul_assoc, mul_assoc (x.num : ℚ), mul_one_div_cancel (Nat.cast_ne_zero.mpr x.pos.ne'),
-      mul_one, mul_one_div, Rat.num_div_den]
+@[simp] lemma addSubmonoid_closure_range_pow {n : ℕ} (hn₀ : n ≠ 0) (hn : Even n) :
+    closure (range fun x : ℚ ↦ x ^ n) = nonneg _ := by
+  convert (AddMonoidHom.map_mclosure NNRat.coeHom <| range fun x ↦ x ^ n).symm
+  · have (x : ℚ) : ∃ y : ℚ≥0, y ^ n = x ^ n := ⟨x.nnabs, by simp [hn.pow_abs]⟩
+    simp [subset_antisymm_iff, range_subset_iff, this]
+  · ext
+    simp [NNRat.addSubmonoid_closure_range_pow hn₀, NNRat.exists]
+
+@[simp]
+lemma addSubmonoid_closure_range_mul_self : closure (range fun x : ℚ ↦ x * x) = nonneg _ := by
+  simpa only [sq] using addSubmonoid_closure_range_pow two_ne_zero even_two
+
+instance instStarOrderedRing : StarOrderedRing ℚ where
+  le_iff a b := by simp [le_iff_exists_nonneg_add a b]
+
 end Rat
feat: positivity extension for Rat.num, Rat.den (#10218)

and rename num_nonneg_iff_zero_le to num_nonneg, num_pos_iff_pos to num_pos

From LeanAPAP

Diff
@@ -46,7 +46,7 @@ instance : StarOrderedRing ℚ :=
       by exact this ▸ sum_mem fun n _ => AddSubmonoid.subset_closure ⟨_, rfl⟩
     simp only [Function.const_apply, Finset.sum_const, Finset.card_range, nsmul_eq_mul]
     rw [← Int.cast_ofNat, Int.ofNat_mul, Int.coe_natAbs,
-      abs_of_nonneg (num_nonneg_iff_zero_le.mpr hx), Int.cast_mul, Int.cast_ofNat]
+      abs_of_nonneg (num_nonneg.mpr hx), Int.cast_mul, Int.cast_ofNat]
     rw [← mul_assoc, mul_assoc (x.num : ℚ), mul_one_div_cancel (Nat.cast_ne_zero.mpr x.pos.ne'),
       mul_one, mul_one_div, Rat.num_div_den]
 end Rat
chore: split Data.Rat.Cast (#7001)

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -5,6 +5,7 @@ Authors: Jireh Loreaux
 -/
 import Mathlib.Algebra.Star.Order
 import Mathlib.Data.Rat.Lemmas
+import Mathlib.Data.Rat.Order
 import Mathlib.GroupTheory.Submonoid.Membership
 
 #align_import data.rat.star from "leanprover-community/mathlib"@"31c24aa72e7b3e5ed97a8412470e904f82b81004"
chore: remove unused simps (#6632)

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>

Diff
@@ -46,7 +46,6 @@ instance : StarOrderedRing ℚ :=
     simp only [Function.const_apply, Finset.sum_const, Finset.card_range, nsmul_eq_mul]
     rw [← Int.cast_ofNat, Int.ofNat_mul, Int.coe_natAbs,
       abs_of_nonneg (num_nonneg_iff_zero_le.mpr hx), Int.cast_mul, Int.cast_ofNat]
-    simp only [Int.cast_mul, Int.cast_ofNat]
     rw [← mul_assoc, mul_assoc (x.num : ℚ), mul_one_div_cancel (Nat.cast_ne_zero.mpr x.pos.ne'),
       mul_one, mul_one_div, Rat.num_div_den]
 end Rat
chore: script to replace headers with #align_import statements (#5979)

Open in Gitpod

Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -2,16 +2,13 @@
 Copyright (c) 2023 Jireh Loreaux. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Jireh Loreaux
-
-! This file was ported from Lean 3 source module data.rat.star
-! leanprover-community/mathlib commit 31c24aa72e7b3e5ed97a8412470e904f82b81004
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
 -/
 import Mathlib.Algebra.Star.Order
 import Mathlib.Data.Rat.Lemmas
 import Mathlib.GroupTheory.Submonoid.Membership
 
+#align_import data.rat.star from "leanprover-community/mathlib"@"31c24aa72e7b3e5ed97a8412470e904f82b81004"
+
 /-! # Star order structure on ℚ
 
 Here we put the trivial `star` operation on `ℚ` for convenience and show that it is a
feat: port Data.Rat.Star (#4868)

Dependencies 4 + 253

254 files ported (98.4%)
107399 lines ported (99.0%)
Show graph

The unported dependencies are