data.nat.cast.defs
⟷
Mathlib.Data.Nat.Cast.Defs
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.
(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)
(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)
(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)
(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)
(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)
(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)
(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)
(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)
(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)
(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)
(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)
mathlib commit https://github.com/leanprover-community/mathlib/commit/ce64cd319bb6b3e82f31c2d38e79080d377be451
@@ -3,8 +3,8 @@ Copyright (c) 2014 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Gabriel Ebner
-/
-import Mathbin.Algebra.Group.Defs
-import Mathbin.Algebra.NeZero
+import Algebra.Group.Defs
+import Algebra.NeZero
#align_import data.nat.cast.defs from "leanprover-community/mathlib"@"448144f7ae193a8990cb7473c9e9a01990f64ac7"
mathlib commit https://github.com/leanprover-community/mathlib/commit/8ea5598db6caeddde6cb734aa179cc2408dbd345
@@ -2,15 +2,12 @@
Copyright (c) 2014 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Gabriel Ebner
-
-! This file was ported from Lean 3 source module data.nat.cast.defs
-! leanprover-community/mathlib commit 448144f7ae193a8990cb7473c9e9a01990f64ac7
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
-/
import Mathbin.Algebra.Group.Defs
import Mathbin.Algebra.NeZero
+#align_import data.nat.cast.defs from "leanprover-community/mathlib"@"448144f7ae193a8990cb7473c9e9a01990f64ac7"
+
/-!
# Cast of natural numbers
mathlib commit https://github.com/leanprover-community/mathlib/commit/9fb8964792b4237dac6200193a0d533f1b3f7423
@@ -115,11 +115,14 @@ instance (priority := 900) castCoe {R} [NatCast R] : CoeTC ℕ R :=
⟨Nat.cast⟩
#align nat.cast_coe Nat.castCoe
+#print Nat.cast_zero /-
@[simp, norm_cast]
theorem cast_zero : ((0 : ℕ) : R) = 0 :=
AddMonoidWithOne.natCast_zero
#align nat.cast_zero Nat.cast_zero
+-/
+#print Nat.cast_succ /-
-- Lemmas about nat.succ need to get a low priority, so that they are tried last.
-- This is because `nat.succ _` matches `1`, `3`, `x+1`, etc.
-- Rewriting would then produce really wrong terms.
@@ -127,10 +130,13 @@ theorem cast_zero : ((0 : ℕ) : R) = 0 :=
theorem cast_succ (n : ℕ) : ((succ n : ℕ) : R) = n + 1 :=
AddMonoidWithOne.natCast_succ _
#align nat.cast_succ Nat.cast_succ
+-/
+#print Nat.cast_add_one /-
theorem cast_add_one (n : ℕ) : ((n + 1 : ℕ) : R) = n + 1 :=
cast_succ _
#align nat.cast_add_one Nat.cast_add_one
+-/
#print Nat.cast_ite /-
@[simp, norm_cast]
@@ -163,6 +169,7 @@ protected def binCast [Zero R] [One R] [Add R] (n : ℕ) : R :=
#align nat.bin_cast Nat.binCast
-/
+#print Nat.binCast_eq /-
@[simp]
theorem binCast_eq [AddMonoidWithOne R] (n : ℕ) : (Nat.binCast n : R) = ((n : ℕ) : R) :=
by
@@ -174,19 +181,26 @@ theorem binCast_eq [AddMonoidWithOne R] (n : ℕ) : (Nat.binCast n : R) = ((n :
· cases b <;> simp [bit, bit0, bit1]
· simp
#align nat.bin_cast_eq Nat.binCast_eq
+-/
+#print Nat.cast_bit0 /-
@[simp, norm_cast]
theorem cast_bit0 [AddMonoidWithOne R] (n : ℕ) : ((bit0 n : ℕ) : R) = bit0 n :=
cast_add _ _
#align nat.cast_bit0 Nat.cast_bit0
+-/
+#print Nat.cast_bit1 /-
@[simp, norm_cast]
theorem cast_bit1 [AddMonoidWithOne R] (n : ℕ) : ((bit1 n : ℕ) : R) = bit1 n := by
rw [bit1, cast_add_one, cast_bit0] <;> rfl
#align nat.cast_bit1 Nat.cast_bit1
+-/
+#print Nat.cast_two /-
theorem cast_two [AddMonoidWithOne R] : ((2 : ℕ) : R) = 2 := by rw [cast_add_one, cast_one, bit0]
#align nat.cast_two Nat.cast_two
+-/
attribute [simp, norm_cast] Int.natAbs_ofNat
@@ -217,17 +231,23 @@ protected def AddMonoidWithOne.binary {R : Type _} [AddMonoid R] [One R] : AddMo
namespace NeZero
+#print NeZero.natCast_ne /-
theorem natCast_ne (n : ℕ) (R) [AddMonoidWithOne R] [h : NeZero (n : R)] : (n : R) ≠ 0 :=
h.out
#align ne_zero.nat_cast_ne NeZero.natCast_ne
+-/
+#print NeZero.of_neZero_natCast /-
theorem of_neZero_natCast (R) [AddMonoidWithOne R] {n : ℕ} [h : NeZero (n : R)] : NeZero n :=
⟨by cases h; rintro rfl; · simpa using h⟩
#align ne_zero.of_ne_zero_coe NeZero.of_neZero_natCast
+-/
+#print NeZero.pos_of_neZero_natCast /-
theorem pos_of_neZero_natCast (R) [AddMonoidWithOne R] {n : ℕ} [NeZero (n : R)] : 0 < n :=
Nat.pos_of_ne_zero (of_neZero_natCast R).out
#align ne_zero.pos_of_ne_zero_coe NeZero.pos_of_neZero_natCast
+-/
end NeZero
mathlib commit https://github.com/leanprover-community/mathlib/commit/cca40788df1b8755d5baf17ab2f27dacc2e17acb
@@ -56,8 +56,8 @@ It also contains data for the unique homomorphism `ℕ → R`.
@[protect_proj]
class AddMonoidWithOne (R : Type u) extends NatCast R, AddMonoid R, One R where
natCast := Nat.unaryCast
- natCast_zero : nat_cast 0 = (0 : R) := by intros ; rfl
- natCast_succ : ∀ n, nat_cast (n + 1) = (nat_cast n + 1 : R) := by intros ; rfl
+ natCast_zero : nat_cast 0 = (0 : R) := by intros; rfl
+ natCast_succ : ∀ n, nat_cast (n + 1) = (nat_cast n + 1 : R) := by intros; rfl
#align add_monoid_with_one AddMonoidWithOne
-/
mathlib commit https://github.com/leanprover-community/mathlib/commit/917c3c072e487b3cccdbfeff17e75b40e45f66cb
@@ -115,23 +115,11 @@ instance (priority := 900) castCoe {R} [NatCast R] : CoeTC ℕ R :=
⟨Nat.cast⟩
#align nat.cast_coe Nat.castCoe
-/- warning: nat.cast_zero -> Nat.cast_zero is a dubious translation:
-lean 3 declaration is
- forall {R : Type.{u1}} [_inst_1 : AddMonoidWithOne.{u1} R], Eq.{succ u1} R ((fun (a : Type) (b : Type.{u1}) [self : HasLiftT.{1, succ u1} a b] => self.0) Nat R (HasLiftT.mk.{1, succ u1} Nat R (CoeTCₓ.coe.{1, succ u1} Nat R (Nat.castCoe.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1)))) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (AddZeroClass.toHasZero.{u1} R (AddMonoid.toAddZeroClass.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1))))))
-but is expected to have type
- forall {R : Type.{u1}} [_inst_1 : AddMonoidWithOne.{u1} R], Eq.{succ u1} R (Nat.cast.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (AddMonoid.toZero.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1))))
-Case conversion may be inaccurate. Consider using '#align nat.cast_zero Nat.cast_zeroₓ'. -/
@[simp, norm_cast]
theorem cast_zero : ((0 : ℕ) : R) = 0 :=
AddMonoidWithOne.natCast_zero
#align nat.cast_zero Nat.cast_zero
-/- warning: nat.cast_succ -> Nat.cast_succ is a dubious translation:
-lean 3 declaration is
- forall {R : Type.{u1}} [_inst_1 : AddMonoidWithOne.{u1} R] (n : Nat), Eq.{succ u1} R ((fun (a : Type) (b : Type.{u1}) [self : HasLiftT.{1, succ u1} a b] => self.0) Nat R (HasLiftT.mk.{1, succ u1} Nat R (CoeTCₓ.coe.{1, succ u1} Nat R (Nat.castCoe.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1)))) (Nat.succ n)) (HAdd.hAdd.{u1, u1, u1} R R R (instHAdd.{u1} R (AddZeroClass.toHasAdd.{u1} R (AddMonoid.toAddZeroClass.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1)))) ((fun (a : Type) (b : Type.{u1}) [self : HasLiftT.{1, succ u1} a b] => self.0) Nat R (HasLiftT.mk.{1, succ u1} Nat R (CoeTCₓ.coe.{1, succ u1} Nat R (Nat.castCoe.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1)))) n) (OfNat.ofNat.{u1} R 1 (OfNat.mk.{u1} R 1 (One.one.{u1} R (AddMonoidWithOne.toOne.{u1} R _inst_1)))))
-but is expected to have type
- forall {R : Type.{u1}} [_inst_1 : AddMonoidWithOne.{u1} R] (n : Nat), Eq.{succ u1} R (Nat.cast.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1) (Nat.succ n)) (HAdd.hAdd.{u1, u1, u1} R R R (instHAdd.{u1} R (AddZeroClass.toAdd.{u1} R (AddMonoid.toAddZeroClass.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1)))) (Nat.cast.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1) n) (OfNat.ofNat.{u1} R 1 (One.toOfNat1.{u1} R (AddMonoidWithOne.toOne.{u1} R _inst_1))))
-Case conversion may be inaccurate. Consider using '#align nat.cast_succ Nat.cast_succₓ'. -/
-- Lemmas about nat.succ need to get a low priority, so that they are tried last.
-- This is because `nat.succ _` matches `1`, `3`, `x+1`, etc.
-- Rewriting would then produce really wrong terms.
@@ -140,12 +128,6 @@ theorem cast_succ (n : ℕ) : ((succ n : ℕ) : R) = n + 1 :=
AddMonoidWithOne.natCast_succ _
#align nat.cast_succ Nat.cast_succ
-/- warning: nat.cast_add_one -> Nat.cast_add_one is a dubious translation:
-lean 3 declaration is
- forall {R : Type.{u1}} [_inst_1 : AddMonoidWithOne.{u1} R] (n : Nat), Eq.{succ u1} R ((fun (a : Type) (b : Type.{u1}) [self : HasLiftT.{1, succ u1} a b] => self.0) Nat R (HasLiftT.mk.{1, succ u1} Nat R (CoeTCₓ.coe.{1, succ u1} Nat R (Nat.castCoe.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1)))) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) n (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (HAdd.hAdd.{u1, u1, u1} R R R (instHAdd.{u1} R (AddZeroClass.toHasAdd.{u1} R (AddMonoid.toAddZeroClass.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1)))) ((fun (a : Type) (b : Type.{u1}) [self : HasLiftT.{1, succ u1} a b] => self.0) Nat R (HasLiftT.mk.{1, succ u1} Nat R (CoeTCₓ.coe.{1, succ u1} Nat R (Nat.castCoe.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1)))) n) (OfNat.ofNat.{u1} R 1 (OfNat.mk.{u1} R 1 (One.one.{u1} R (AddMonoidWithOne.toOne.{u1} R _inst_1)))))
-but is expected to have type
- forall {R : Type.{u1}} [_inst_1 : AddMonoidWithOne.{u1} R] (n : Nat), Eq.{succ u1} R (Nat.cast.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (HAdd.hAdd.{u1, u1, u1} R R R (instHAdd.{u1} R (AddZeroClass.toAdd.{u1} R (AddMonoid.toAddZeroClass.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1)))) (Nat.cast.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1) n) (OfNat.ofNat.{u1} R 1 (One.toOfNat1.{u1} R (AddMonoidWithOne.toOne.{u1} R _inst_1))))
-Case conversion may be inaccurate. Consider using '#align nat.cast_add_one Nat.cast_add_oneₓ'. -/
theorem cast_add_one (n : ℕ) : ((n + 1 : ℕ) : R) = n + 1 :=
cast_succ _
#align nat.cast_add_one Nat.cast_add_one
@@ -181,12 +163,6 @@ protected def binCast [Zero R] [One R] [Add R] (n : ℕ) : R :=
#align nat.bin_cast Nat.binCast
-/
-/- warning: nat.bin_cast_eq -> Nat.binCast_eq is a dubious translation:
-lean 3 declaration is
- forall {R : Type.{u1}} [_inst_1 : AddMonoidWithOne.{u1} R] (n : Nat), Eq.{succ u1} R (Nat.binCast.{u1} R (AddZeroClass.toHasZero.{u1} R (AddMonoid.toAddZeroClass.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1))) (AddMonoidWithOne.toOne.{u1} R _inst_1) (AddZeroClass.toHasAdd.{u1} R (AddMonoid.toAddZeroClass.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1))) n) ((fun (a : Type) (b : Type.{u1}) [self : HasLiftT.{1, succ u1} a b] => self.0) Nat R (HasLiftT.mk.{1, succ u1} Nat R (CoeTCₓ.coe.{1, succ u1} Nat R (Nat.castCoe.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1)))) n)
-but is expected to have type
- forall {R : Type.{u1}} [_inst_1 : AddMonoidWithOne.{u1} R] (n : Nat), Eq.{succ u1} R (Nat.binCast.{u1} R (AddMonoid.toZero.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1)) (AddMonoidWithOne.toOne.{u1} R _inst_1) (AddZeroClass.toAdd.{u1} R (AddMonoid.toAddZeroClass.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1))) n) (Nat.cast.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1) n)
-Case conversion may be inaccurate. Consider using '#align nat.bin_cast_eq Nat.binCast_eqₓ'. -/
@[simp]
theorem binCast_eq [AddMonoidWithOne R] (n : ℕ) : (Nat.binCast n : R) = ((n : ℕ) : R) :=
by
@@ -199,34 +175,16 @@ theorem binCast_eq [AddMonoidWithOne R] (n : ℕ) : (Nat.binCast n : R) = ((n :
· simp
#align nat.bin_cast_eq Nat.binCast_eq
-/- warning: nat.cast_bit0 -> Nat.cast_bit0 is a dubious translation:
-lean 3 declaration is
- forall {R : Type.{u1}} [_inst_1 : AddMonoidWithOne.{u1} R] (n : Nat), Eq.{succ u1} R ((fun (a : Type) (b : Type.{u1}) [self : HasLiftT.{1, succ u1} a b] => self.0) Nat R (HasLiftT.mk.{1, succ u1} Nat R (CoeTCₓ.coe.{1, succ u1} Nat R (Nat.castCoe.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1)))) (bit0.{0} Nat Nat.hasAdd n)) (bit0.{u1} R (AddZeroClass.toHasAdd.{u1} R (AddMonoid.toAddZeroClass.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1))) ((fun (a : Type) (b : Type.{u1}) [self : HasLiftT.{1, succ u1} a b] => self.0) Nat R (HasLiftT.mk.{1, succ u1} Nat R (CoeTCₓ.coe.{1, succ u1} Nat R (Nat.castCoe.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1)))) n))
-but is expected to have type
- forall {R : Type.{u1}} [_inst_1 : AddMonoidWithOne.{u1} R] (n : Nat), Eq.{succ u1} R (Nat.cast.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1) (bit0.{0} Nat instAddNat n)) (bit0.{u1} R (AddZeroClass.toAdd.{u1} R (AddMonoid.toAddZeroClass.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1))) (Nat.cast.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1) n))
-Case conversion may be inaccurate. Consider using '#align nat.cast_bit0 Nat.cast_bit0ₓ'. -/
@[simp, norm_cast]
theorem cast_bit0 [AddMonoidWithOne R] (n : ℕ) : ((bit0 n : ℕ) : R) = bit0 n :=
cast_add _ _
#align nat.cast_bit0 Nat.cast_bit0
-/- warning: nat.cast_bit1 -> Nat.cast_bit1 is a dubious translation:
-lean 3 declaration is
- forall {R : Type.{u1}} [_inst_1 : AddMonoidWithOne.{u1} R] (n : Nat), Eq.{succ u1} R ((fun (a : Type) (b : Type.{u1}) [self : HasLiftT.{1, succ u1} a b] => self.0) Nat R (HasLiftT.mk.{1, succ u1} Nat R (CoeTCₓ.coe.{1, succ u1} Nat R (Nat.castCoe.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1)))) (bit1.{0} Nat Nat.hasOne Nat.hasAdd n)) (bit1.{u1} R (AddMonoidWithOne.toOne.{u1} R _inst_1) (AddZeroClass.toHasAdd.{u1} R (AddMonoid.toAddZeroClass.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1))) ((fun (a : Type) (b : Type.{u1}) [self : HasLiftT.{1, succ u1} a b] => self.0) Nat R (HasLiftT.mk.{1, succ u1} Nat R (CoeTCₓ.coe.{1, succ u1} Nat R (Nat.castCoe.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1)))) n))
-but is expected to have type
- forall {R : Type.{u1}} [_inst_1 : AddMonoidWithOne.{u1} R] (n : Nat), Eq.{succ u1} R (Nat.cast.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1) (bit1.{0} Nat (One.ofOfNat1.{0} Nat (instOfNatNat 1)) instAddNat n)) (bit1.{u1} R (AddMonoidWithOne.toOne.{u1} R _inst_1) (AddZeroClass.toAdd.{u1} R (AddMonoid.toAddZeroClass.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1))) (Nat.cast.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1) n))
-Case conversion may be inaccurate. Consider using '#align nat.cast_bit1 Nat.cast_bit1ₓ'. -/
@[simp, norm_cast]
theorem cast_bit1 [AddMonoidWithOne R] (n : ℕ) : ((bit1 n : ℕ) : R) = bit1 n := by
rw [bit1, cast_add_one, cast_bit0] <;> rfl
#align nat.cast_bit1 Nat.cast_bit1
-/- warning: nat.cast_two -> Nat.cast_two is a dubious translation:
-lean 3 declaration is
- forall {R : Type.{u1}} [_inst_1 : AddMonoidWithOne.{u1} R], Eq.{succ u1} R ((fun (a : Type) (b : Type.{u1}) [self : HasLiftT.{1, succ u1} a b] => self.0) Nat R (HasLiftT.mk.{1, succ u1} Nat R (CoeTCₓ.coe.{1, succ u1} Nat R (Nat.castCoe.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1)))) (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne))))) (OfNat.ofNat.{u1} R 2 (OfNat.mk.{u1} R 2 (bit0.{u1} R (AddZeroClass.toHasAdd.{u1} R (AddMonoid.toAddZeroClass.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1))) (One.one.{u1} R (AddMonoidWithOne.toOne.{u1} R _inst_1)))))
-but is expected to have type
- forall {R : Type.{u1}} [_inst_1 : AddMonoidWithOne.{u1} R], Eq.{succ u1} R (Nat.cast.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2))) (OfNat.ofNat.{u1} R 2 (instOfNat.{u1} R 2 (AddMonoidWithOne.toNatCast.{u1} R _inst_1) (instAtLeastTwoHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)))))
-Case conversion may be inaccurate. Consider using '#align nat.cast_two Nat.cast_twoₓ'. -/
theorem cast_two [AddMonoidWithOne R] : ((2 : ℕ) : R) = 2 := by rw [cast_add_one, cast_one, bit0]
#align nat.cast_two Nat.cast_two
@@ -259,32 +217,14 @@ protected def AddMonoidWithOne.binary {R : Type _} [AddMonoid R] [One R] : AddMo
namespace NeZero
-/- warning: ne_zero.nat_cast_ne -> NeZero.natCast_ne is a dubious translation:
-lean 3 declaration is
- forall (n : Nat) (R : Type.{u1}) [_inst_1 : AddMonoidWithOne.{u1} R] [h : NeZero.{u1} R (AddZeroClass.toHasZero.{u1} R (AddMonoid.toAddZeroClass.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1))) ((fun (a : Type) (b : Type.{u1}) [self : HasLiftT.{1, succ u1} a b] => self.0) Nat R (HasLiftT.mk.{1, succ u1} Nat R (CoeTCₓ.coe.{1, succ u1} Nat R (Nat.castCoe.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1)))) n)], Ne.{succ u1} R ((fun (a : Type) (b : Type.{u1}) [self : HasLiftT.{1, succ u1} a b] => self.0) Nat R (HasLiftT.mk.{1, succ u1} Nat R (CoeTCₓ.coe.{1, succ u1} Nat R (Nat.castCoe.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1)))) n) (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (AddZeroClass.toHasZero.{u1} R (AddMonoid.toAddZeroClass.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1))))))
-but is expected to have type
- forall (n : Nat) (R : Type.{u1}) [_inst_1 : AddMonoidWithOne.{u1} R] [h : NeZero.{u1} R (AddMonoid.toZero.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1)) (Nat.cast.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1) n)], Ne.{succ u1} R (Nat.cast.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1) n) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (AddMonoid.toZero.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1))))
-Case conversion may be inaccurate. Consider using '#align ne_zero.nat_cast_ne NeZero.natCast_neₓ'. -/
theorem natCast_ne (n : ℕ) (R) [AddMonoidWithOne R] [h : NeZero (n : R)] : (n : R) ≠ 0 :=
h.out
#align ne_zero.nat_cast_ne NeZero.natCast_ne
-/- warning: ne_zero.of_ne_zero_coe -> NeZero.of_neZero_natCast is a dubious translation:
-lean 3 declaration is
- forall (R : Type.{u1}) [_inst_1 : AddMonoidWithOne.{u1} R] {n : Nat} [h : NeZero.{u1} R (AddZeroClass.toHasZero.{u1} R (AddMonoid.toAddZeroClass.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1))) ((fun (a : Type) (b : Type.{u1}) [self : HasLiftT.{1, succ u1} a b] => self.0) Nat R (HasLiftT.mk.{1, succ u1} Nat R (CoeTCₓ.coe.{1, succ u1} Nat R (Nat.castCoe.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1)))) n)], NeZero.{0} Nat Nat.hasZero n
-but is expected to have type
- forall (R : Type.{u1}) [_inst_1 : AddMonoidWithOne.{u1} R] {n : Nat} [h : NeZero.{u1} R (AddMonoid.toZero.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1)) (Nat.cast.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1) n)], NeZero.{0} Nat (Zero.ofOfNat0.{0} Nat (instOfNatNat 0)) n
-Case conversion may be inaccurate. Consider using '#align ne_zero.of_ne_zero_coe NeZero.of_neZero_natCastₓ'. -/
theorem of_neZero_natCast (R) [AddMonoidWithOne R] {n : ℕ} [h : NeZero (n : R)] : NeZero n :=
⟨by cases h; rintro rfl; · simpa using h⟩
#align ne_zero.of_ne_zero_coe NeZero.of_neZero_natCast
-/- warning: ne_zero.pos_of_ne_zero_coe -> NeZero.pos_of_neZero_natCast is a dubious translation:
-lean 3 declaration is
- forall (R : Type.{u1}) [_inst_1 : AddMonoidWithOne.{u1} R] {n : Nat} [_inst_2 : NeZero.{u1} R (AddZeroClass.toHasZero.{u1} R (AddMonoid.toAddZeroClass.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1))) ((fun (a : Type) (b : Type.{u1}) [self : HasLiftT.{1, succ u1} a b] => self.0) Nat R (HasLiftT.mk.{1, succ u1} Nat R (CoeTCₓ.coe.{1, succ u1} Nat R (Nat.castCoe.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1)))) n)], LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) n
-but is expected to have type
- forall (R : Type.{u1}) [_inst_1 : AddMonoidWithOne.{u1} R] {n : Nat} [_inst_2 : NeZero.{u1} R (AddMonoid.toZero.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1)) (Nat.cast.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1) n)], LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) n
-Case conversion may be inaccurate. Consider using '#align ne_zero.pos_of_ne_zero_coe NeZero.pos_of_neZero_natCastₓ'. -/
theorem pos_of_neZero_natCast (R) [AddMonoidWithOne R] {n : ℕ} [NeZero (n : R)] : 0 < n :=
Nat.pos_of_ne_zero (of_neZero_natCast R).out
#align ne_zero.pos_of_ne_zero_coe NeZero.pos_of_neZero_natCast
mathlib commit https://github.com/leanprover-community/mathlib/commit/917c3c072e487b3cccdbfeff17e75b40e45f66cb
@@ -56,14 +56,8 @@ It also contains data for the unique homomorphism `ℕ → R`.
@[protect_proj]
class AddMonoidWithOne (R : Type u) extends NatCast R, AddMonoid R, One R where
natCast := Nat.unaryCast
- natCast_zero : nat_cast 0 = (0 : R) := by
- intros
- rfl
- natCast_succ :
- ∀ n, nat_cast (n + 1) = (nat_cast n + 1 :
- R) := by
- intros
- rfl
+ natCast_zero : nat_cast 0 = (0 : R) := by intros ; rfl
+ natCast_succ : ∀ n, nat_cast (n + 1) = (nat_cast n + 1 : R) := by intros ; rfl
#align add_monoid_with_one AddMonoidWithOne
-/
@@ -282,10 +276,7 @@ but is expected to have type
forall (R : Type.{u1}) [_inst_1 : AddMonoidWithOne.{u1} R] {n : Nat} [h : NeZero.{u1} R (AddMonoid.toZero.{u1} R (AddMonoidWithOne.toAddMonoid.{u1} R _inst_1)) (Nat.cast.{u1} R (AddMonoidWithOne.toNatCast.{u1} R _inst_1) n)], NeZero.{0} Nat (Zero.ofOfNat0.{0} Nat (instOfNatNat 0)) n
Case conversion may be inaccurate. Consider using '#align ne_zero.of_ne_zero_coe NeZero.of_neZero_natCastₓ'. -/
theorem of_neZero_natCast (R) [AddMonoidWithOne R] {n : ℕ} [h : NeZero (n : R)] : NeZero n :=
- ⟨by
- cases h
- rintro rfl
- · simpa using h⟩
+ ⟨by cases h; rintro rfl; · simpa using h⟩
#align ne_zero.of_ne_zero_coe NeZero.of_neZero_natCast
/- warning: ne_zero.pos_of_ne_zero_coe -> NeZero.pos_of_neZero_natCast is a dubious translation:
mathlib commit https://github.com/leanprover-community/mathlib/commit/09079525fd01b3dda35e96adaa08d2f943e1648c
@@ -110,9 +110,9 @@ If `coe_trans` is tried first, then `nat.cast_coe` doesn't get a chance to apply
-/
-attribute [instance] coeBase
+attribute [instance 950] coeBase
-attribute [instance] coeTrans
+attribute [instance 500] coeTrans
namespace Nat
mathlib commit https://github.com/leanprover-community/mathlib/commit/bd9851ca476957ea4549eb19b40e7b5ade9428cc
@@ -24,8 +24,10 @@ Preferentially, the homomorphism is written as the coercion `Nat.cast`.
* `Nat.cast`: Canonical homomorphism `ℕ → R`.
-/
+variable {R : Type*}
+
/-- The numeral `((0+1)+⋯)+1`. -/
-protected def Nat.unaryCast {R : Type*} [One R] [Zero R] [Add R] : ℕ → R
+protected def Nat.unaryCast [One R] [Zero R] [Add R] : ℕ → R
| 0 => 0
| n + 1 => Nat.unaryCast n + 1
#align nat.unary_cast Nat.unaryCast
@@ -59,7 +61,7 @@ instance is what makes things like `37 : R` type check. Note that `0` and `1` a
because they are recognized as terms of `R` (at least when `R` is an `AddMonoidWithOne`) through
`Zero` and `One`, respectively. -/
@[nolint unusedArguments]
-instance (priority := 100) instOfNatAtLeastTwo {R : Type*} {n : ℕ} [NatCast R] [Nat.AtLeastTwo n] :
+instance (priority := 100) instOfNatAtLeastTwo {n : ℕ} [NatCast R] [Nat.AtLeastTwo n] :
OfNat R n where
ofNat := n.cast
@@ -71,10 +73,10 @@ in `no_index` so as not to confuse `simp`, as `no_index (OfNat.ofNat n)`.
Some discussion is [on Zulip here](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/.E2.9C.94.20Polynomial.2Ecoeff.20example/near/395438147).
-/
-@[simp, norm_cast] theorem Nat.cast_ofNat {R : Type*} {n : ℕ} [NatCast R] [Nat.AtLeastTwo n] :
+@[simp, norm_cast] theorem Nat.cast_ofNat {n : ℕ} [NatCast R] [Nat.AtLeastTwo n] :
(Nat.cast (no_index (OfNat.ofNat n)) : R) = OfNat.ofNat n := rfl
-theorem Nat.cast_eq_ofNat {R : Type*} {n : ℕ} [NatCast R] [Nat.AtLeastTwo n] :
+theorem Nat.cast_eq_ofNat {n : ℕ} [NatCast R] [Nat.AtLeastTwo n] :
(Nat.cast n : R) = OfNat.ofNat n :=
rfl
@@ -119,7 +121,7 @@ if we need to shadow another coercion
namespace Nat
-variable {R : Type*} [AddMonoidWithOne R]
+variable [AddMonoidWithOne R]
@[simp, norm_cast]
theorem cast_zero : ((0 : ℕ) : R) = 0 :=
@@ -149,17 +151,17 @@ end Nat
namespace Nat
@[simp, norm_cast]
-theorem cast_one {R : Type*} [AddMonoidWithOne R] : ((1 : ℕ) : R) = 1 := by
+theorem cast_one [AddMonoidWithOne R] : ((1 : ℕ) : R) = 1 := by
rw [cast_succ, Nat.cast_zero, zero_add]
#align nat.cast_one Nat.cast_oneₓ
@[simp, norm_cast]
-theorem cast_add {R : Type*} [AddMonoidWithOne R] (m n : ℕ) : ((m + n : ℕ) : R) = m + n := by
+theorem cast_add [AddMonoidWithOne R] (m n : ℕ) : ((m + n : ℕ) : R) = m + n := by
induction n <;> simp [add_succ, add_assoc, Nat.add_zero, Nat.cast_one, Nat.cast_zero, *]
#align nat.cast_add Nat.cast_addₓ
/-- Computationally friendlier cast than `Nat.unaryCast`, using binary representation. -/
-protected def binCast {R : Type*} [Zero R] [One R] [Add R] : ℕ → R
+protected def binCast [Zero R] [One R] [Add R] : ℕ → R
| 0 => 0
| n + 1 => if (n + 1) % 2 = 0
then (Nat.binCast ((n + 1) / 2)) + (Nat.binCast ((n + 1) / 2))
@@ -167,7 +169,7 @@ protected def binCast {R : Type*} [Zero R] [One R] [Add R] : ℕ → R
#align nat.bin_cast Nat.binCast
@[simp]
-theorem binCast_eq {R : Type*} [AddMonoidWithOne R] (n : ℕ) :
+theorem binCast_eq [AddMonoidWithOne R] (n : ℕ) :
(Nat.binCast n : R) = ((n : ℕ) : R) := by
apply Nat.strongInductionOn n
intros k hk
@@ -190,18 +192,18 @@ section deprecated
set_option linter.deprecated false
@[norm_cast, deprecated]
-theorem cast_bit0 {R : Type*} [AddMonoidWithOne R] (n : ℕ) : ((bit0 n : ℕ) : R) = bit0 (n : R) :=
+theorem cast_bit0 [AddMonoidWithOne R] (n : ℕ) : ((bit0 n : ℕ) : R) = bit0 (n : R) :=
Nat.cast_add _ _
#align nat.cast_bit0 Nat.cast_bit0
@[norm_cast, deprecated]
-theorem cast_bit1 {R : Type*} [AddMonoidWithOne R] (n : ℕ) : ((bit1 n : ℕ) : R) = bit1 (n : R) := by
+theorem cast_bit1 [AddMonoidWithOne R] (n : ℕ) : ((bit1 n : ℕ) : R) = bit1 (n : R) := by
rw [bit1, cast_add_one, cast_bit0]; rfl
#align nat.cast_bit1 Nat.cast_bit1
end deprecated
-theorem cast_two {R : Type*} [AddMonoidWithOne R] : ((2 : ℕ) : R) = (2 : R) := rfl
+theorem cast_two [AddMonoidWithOne R] : ((2 : ℕ) : R) = (2 : R) := rfl
#align nat.cast_two Nat.cast_two
attribute [simp, norm_cast] Int.natAbs_ofNat
@@ -210,13 +212,13 @@ end Nat
/-- `AddMonoidWithOne` implementation using unary recursion. -/
@[reducible]
-protected def AddMonoidWithOne.unary {R : Type*} [AddMonoid R] [One R] : AddMonoidWithOne R :=
+protected def AddMonoidWithOne.unary [AddMonoid R] [One R] : AddMonoidWithOne R :=
{ ‹One R›, ‹AddMonoid R› with }
#align add_monoid_with_one.unary AddMonoidWithOne.unary
/-- `AddMonoidWithOne` implementation using binary recursion. -/
@[reducible]
-protected def AddMonoidWithOne.binary {R : Type*} [AddMonoid R] [One R] : AddMonoidWithOne R :=
+protected def AddMonoidWithOne.binary [AddMonoid R] [One R] : AddMonoidWithOne R :=
{ ‹One R›, ‹AddMonoid R› with
natCast := Nat.binCast,
natCast_zero := by simp only [Nat.binCast, Nat.cast],
@@ -226,18 +228,18 @@ protected def AddMonoidWithOne.binary {R : Type*} [AddMonoid R] [One R] : AddMon
rw [Nat.binCast_eq, Nat.binCast_eq, Nat.cast_succ] }
#align add_monoid_with_one.binary AddMonoidWithOne.binary
-theorem one_add_one_eq_two {α : Type*} [AddMonoidWithOne α] : 1 + 1 = (2 : α) := by
+theorem one_add_one_eq_two [AddMonoidWithOne R] : 1 + 1 = (2 : R) := by
rw [← Nat.cast_one, ← Nat.cast_add]
apply congrArg
decide
#align one_add_one_eq_two one_add_one_eq_two
-theorem two_add_one_eq_three {α : Type*} [AddMonoidWithOne α] : 2 + 1 = (3 : α) := by
+theorem two_add_one_eq_three [AddMonoidWithOne R] : 2 + 1 = (3 : R) := by
rw [← one_add_one_eq_two, ← Nat.cast_one, ← Nat.cast_add, ← Nat.cast_add]
apply congrArg
decide
-theorem three_add_one_eq_four {α : Type*} [AddMonoidWithOne α] : 3 + 1 = (4 : α) := by
+theorem three_add_one_eq_four [AddMonoidWithOne R] : 3 + 1 = (4 : R) := by
rw [← two_add_one_eq_three, ← one_add_one_eq_two, ← Nat.cast_one,
← Nat.cast_add, ← Nat.cast_add, ← Nat.cast_add]
apply congrArg
@@ -24,10 +24,8 @@ Preferentially, the homomorphism is written as the coercion `Nat.cast`.
* `Nat.cast`: Canonical homomorphism `ℕ → R`.
-/
-set_option autoImplicit true
-
/-- The numeral `((0+1)+⋯)+1`. -/
-protected def Nat.unaryCast {R : Type u} [One R] [Zero R] [Add R] : ℕ → R
+protected def Nat.unaryCast {R : Type*} [One R] [Zero R] [Add R] : ℕ → R
| 0 => 0
| n + 1 => Nat.unaryCast n + 1
#align nat.unary_cast Nat.unaryCast
@@ -44,7 +42,7 @@ protected def Nat.unaryCast {R : Type u} [One R] [Zero R] [Add R] : ℕ → R
class Nat.AtLeastTwo (n : ℕ) : Prop where
prop : n ≥ 2
-instance instNatAtLeastTwo : Nat.AtLeastTwo (n + 2) where
+instance instNatAtLeastTwo {n : ℕ} : Nat.AtLeastTwo (n + 2) where
prop := Nat.succ_le_succ <| Nat.succ_le_succ <| Nat.zero_le _
namespace Nat.AtLeastTwo
@@ -61,7 +59,8 @@ instance is what makes things like `37 : R` type check. Note that `0` and `1` a
because they are recognized as terms of `R` (at least when `R` is an `AddMonoidWithOne`) through
`Zero` and `One`, respectively. -/
@[nolint unusedArguments]
-instance (priority := 100) instOfNatAtLeastTwo [NatCast R] [Nat.AtLeastTwo n] : OfNat R n where
+instance (priority := 100) instOfNatAtLeastTwo {R : Type*} {n : ℕ} [NatCast R] [Nat.AtLeastTwo n] :
+ OfNat R n where
ofNat := n.cast
library_note "no_index around OfNat.ofNat"
@@ -72,16 +71,18 @@ in `no_index` so as not to confuse `simp`, as `no_index (OfNat.ofNat n)`.
Some discussion is [on Zulip here](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/.E2.9C.94.20Polynomial.2Ecoeff.20example/near/395438147).
-/
-@[simp, norm_cast] theorem Nat.cast_ofNat [NatCast R] [Nat.AtLeastTwo n] :
+@[simp, norm_cast] theorem Nat.cast_ofNat {R : Type*} {n : ℕ} [NatCast R] [Nat.AtLeastTwo n] :
(Nat.cast (no_index (OfNat.ofNat n)) : R) = OfNat.ofNat n := rfl
-theorem Nat.cast_eq_ofNat [NatCast R] [Nat.AtLeastTwo n] : (Nat.cast n : R) = OfNat.ofNat n := rfl
+theorem Nat.cast_eq_ofNat {R : Type*} {n : ℕ} [NatCast R] [Nat.AtLeastTwo n] :
+ (Nat.cast n : R) = OfNat.ofNat n :=
+ rfl
/-! ### Additive monoids with one -/
/-- An `AddMonoidWithOne` is an `AddMonoid` with a `1`.
It also contains data for the unique homomorphism `ℕ → R`. -/
-class AddMonoidWithOne (R : Type u) extends NatCast R, AddMonoid R, One R where
+class AddMonoidWithOne (R : Type*) extends NatCast R, AddMonoid R, One R where
natCast := Nat.unaryCast
/-- The canonical map `ℕ → R` sends `0 : ℕ` to `0 : R`. -/
natCast_zero : natCast 0 = 0 := by intros; rfl
@@ -117,7 +118,8 @@ if we need to shadow another coercion
-/
namespace Nat
-variable [AddMonoidWithOne R]
+
+variable {R : Type*} [AddMonoidWithOne R]
@[simp, norm_cast]
theorem cast_zero : ((0 : ℕ) : R) = 0 :=
@@ -147,17 +149,17 @@ end Nat
namespace Nat
@[simp, norm_cast]
-theorem cast_one [AddMonoidWithOne R] : ((1 : ℕ) : R) = 1 := by
+theorem cast_one {R : Type*} [AddMonoidWithOne R] : ((1 : ℕ) : R) = 1 := by
rw [cast_succ, Nat.cast_zero, zero_add]
#align nat.cast_one Nat.cast_oneₓ
@[simp, norm_cast]
-theorem cast_add [AddMonoidWithOne R] (m n : ℕ) : ((m + n : ℕ) : R) = m + n := by
+theorem cast_add {R : Type*} [AddMonoidWithOne R] (m n : ℕ) : ((m + n : ℕ) : R) = m + n := by
induction n <;> simp [add_succ, add_assoc, Nat.add_zero, Nat.cast_one, Nat.cast_zero, *]
#align nat.cast_add Nat.cast_addₓ
/-- Computationally friendlier cast than `Nat.unaryCast`, using binary representation. -/
-protected def binCast [Zero R] [One R] [Add R] : ℕ → R
+protected def binCast {R : Type*} [Zero R] [One R] [Add R] : ℕ → R
| 0 => 0
| n + 1 => if (n + 1) % 2 = 0
then (Nat.binCast ((n + 1) / 2)) + (Nat.binCast ((n + 1) / 2))
@@ -165,7 +167,8 @@ protected def binCast [Zero R] [One R] [Add R] : ℕ → R
#align nat.bin_cast Nat.binCast
@[simp]
-theorem binCast_eq [AddMonoidWithOne R] (n : ℕ) : (Nat.binCast n : R) = ((n : ℕ) : R) := by
+theorem binCast_eq {R : Type*} [AddMonoidWithOne R] (n : ℕ) :
+ (Nat.binCast n : R) = ((n : ℕ) : R) := by
apply Nat.strongInductionOn n
intros k hk
cases k with
@@ -187,18 +190,18 @@ section deprecated
set_option linter.deprecated false
@[norm_cast, deprecated]
-theorem cast_bit0 [AddMonoidWithOne R] (n : ℕ) : ((bit0 n : ℕ) : R) = bit0 (n : R) :=
+theorem cast_bit0 {R : Type*} [AddMonoidWithOne R] (n : ℕ) : ((bit0 n : ℕ) : R) = bit0 (n : R) :=
Nat.cast_add _ _
#align nat.cast_bit0 Nat.cast_bit0
@[norm_cast, deprecated]
-theorem cast_bit1 [AddMonoidWithOne R] (n : ℕ) : ((bit1 n : ℕ) : R) = bit1 (n : R) := by
+theorem cast_bit1 {R : Type*} [AddMonoidWithOne R] (n : ℕ) : ((bit1 n : ℕ) : R) = bit1 (n : R) := by
rw [bit1, cast_add_one, cast_bit0]; rfl
#align nat.cast_bit1 Nat.cast_bit1
end deprecated
-theorem cast_two [AddMonoidWithOne R] : ((2 : ℕ) : R) = (2 : R) := rfl
+theorem cast_two {R : Type*} [AddMonoidWithOne R] : ((2 : ℕ) : R) = (2 : R) := rfl
#align nat.cast_two Nat.cast_two
attribute [simp, norm_cast] Int.natAbs_ofNat
@@ -223,18 +226,18 @@ protected def AddMonoidWithOne.binary {R : Type*} [AddMonoid R] [One R] : AddMon
rw [Nat.binCast_eq, Nat.binCast_eq, Nat.cast_succ] }
#align add_monoid_with_one.binary AddMonoidWithOne.binary
-theorem one_add_one_eq_two [AddMonoidWithOne α] : 1 + 1 = (2 : α) := by
+theorem one_add_one_eq_two {α : Type*} [AddMonoidWithOne α] : 1 + 1 = (2 : α) := by
rw [← Nat.cast_one, ← Nat.cast_add]
apply congrArg
decide
#align one_add_one_eq_two one_add_one_eq_two
-theorem two_add_one_eq_three [AddMonoidWithOne α] : 2 + 1 = (3 : α) := by
+theorem two_add_one_eq_three {α : Type*} [AddMonoidWithOne α] : 2 + 1 = (3 : α) := by
rw [← one_add_one_eq_two, ← Nat.cast_one, ← Nat.cast_add, ← Nat.cast_add]
apply congrArg
decide
-theorem three_add_one_eq_four [AddMonoidWithOne α] : 3 + 1 = (4 : α) := by
+theorem three_add_one_eq_four {α : Type*} [AddMonoidWithOne α] : 3 + 1 = (4 : α) := by
rw [← two_add_one_eq_three, ← one_add_one_eq_two, ← Nat.cast_one,
← Nat.cast_add, ← Nat.cast_add, ← Nat.cast_add]
apply congrArg
The termination checker has been getting more capable, and many of the termination_by
or decreasing_by
clauses in Mathlib are no longer needed.
(Note that termination_by?
will show the automatically derived termination expression, so no information is being lost by removing these.)
Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
@@ -162,7 +162,6 @@ protected def binCast [Zero R] [One R] [Add R] : ℕ → R
| n + 1 => if (n + 1) % 2 = 0
then (Nat.binCast ((n + 1) / 2)) + (Nat.binCast ((n + 1) / 2))
else (Nat.binCast ((n + 1) / 2)) + (Nat.binCast ((n + 1) / 2)) + 1
-decreasing_by all_goals { simp_wf; omega }
#align nat.bin_cast Nat.binCast
@[simp]
Nat.AtLeastTwo n
to NeZero n
(#10964)
This PR cleans up some lemmas where we're taking named instance parameters [h : Nat.AtLeastTwo n]
and manually proving inequalities like 0 < n
from h
by adding an instance of NeZero n
from Nat.AtLeastTwo n
as well as a couple of other helper lemmas.
This removes Nat.AtLeastTwo.ne_zero
, as NeZero.ne_zero
replaces it.
@@ -47,11 +47,14 @@ class Nat.AtLeastTwo (n : ℕ) : Prop where
instance instNatAtLeastTwo : Nat.AtLeastTwo (n + 2) where
prop := Nat.succ_le_succ <| Nat.succ_le_succ <| Nat.zero_le _
-lemma Nat.AtLeastTwo.ne_zero (n : ℕ) [h : n.AtLeastTwo] : n ≠ 0 := by
- rintro rfl; exact absurd h.1 (by decide)
+namespace Nat.AtLeastTwo
-lemma Nat.AtLeastTwo.ne_one (n : ℕ) [h : n.AtLeastTwo] : n ≠ 1 := by
- rintro rfl; exact absurd h.1 (by decide)
+variable {n : ℕ} [n.AtLeastTwo]
+
+lemma one_lt : 1 < n := prop
+lemma ne_one : n ≠ 1 := Nat.ne_of_gt one_lt
+
+end Nat.AtLeastTwo
/-- Recognize numeric literals which are at least `2` as terms of `R` via `Nat.cast`. This
instance is what makes things like `37 : R` type check. Note that `0` and `1` are not needed
@@ -58,7 +58,7 @@ instance is what makes things like `37 : R` type check. Note that `0` and `1` a
because they are recognized as terms of `R` (at least when `R` is an `AddMonoidWithOne`) through
`Zero` and `One`, respectively. -/
@[nolint unusedArguments]
-instance instOfNatAtLeastTwo [NatCast R] [Nat.AtLeastTwo n] : OfNat R n where
+instance (priority := 100) instOfNatAtLeastTwo [NatCast R] [Nat.AtLeastTwo n] : OfNat R n where
ofNat := n.cast
library_note "no_index around OfNat.ofNat"
Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Joachim Breitner <mail@joachim-breitner.de>
@@ -58,7 +58,7 @@ instance is what makes things like `37 : R` type check. Note that `0` and `1` a
because they are recognized as terms of `R` (at least when `R` is an `AddMonoidWithOne`) through
`Zero` and `One`, respectively. -/
@[nolint unusedArguments]
-instance instOfNat [NatCast R] [Nat.AtLeastTwo n] : OfNat R n where
+instance instOfNatAtLeastTwo [NatCast R] [Nat.AtLeastTwo n] : OfNat R n where
ofNat := n.cast
library_note "no_index around OfNat.ofNat"
@@ -159,7 +159,7 @@ protected def binCast [Zero R] [One R] [Add R] : ℕ → R
| n + 1 => if (n + 1) % 2 = 0
then (Nat.binCast ((n + 1) / 2)) + (Nat.binCast ((n + 1) / 2))
else (Nat.binCast ((n + 1) / 2)) + (Nat.binCast ((n + 1) / 2)) + 1
-decreasing_by simp_wf; omega
+decreasing_by all_goals { simp_wf; omega }
#align nat.bin_cast Nat.binCast
@[simp]
@@ -159,7 +159,7 @@ protected def binCast [Zero R] [One R] [Add R] : ℕ → R
| n + 1 => if (n + 1) % 2 = 0
then (Nat.binCast ((n + 1) / 2)) + (Nat.binCast ((n + 1) / 2))
else (Nat.binCast ((n + 1) / 2)) + (Nat.binCast ((n + 1) / 2)) + 1
-decreasing_by (exact Nat.div_lt_self (Nat.succ_pos n) (Nat.le_refl 2))
+decreasing_by simp_wf; omega
#align nat.bin_cast Nat.binCast
@[simp]
$
with <|
(#9319)
See Zulip thread for the discussion.
@@ -45,7 +45,7 @@ class Nat.AtLeastTwo (n : ℕ) : Prop where
prop : n ≥ 2
instance instNatAtLeastTwo : Nat.AtLeastTwo (n + 2) where
- prop := Nat.succ_le_succ $ Nat.succ_le_succ $ Nat.zero_le _
+ prop := Nat.succ_le_succ <| Nat.succ_le_succ <| Nat.zero_le _
lemma Nat.AtLeastTwo.ne_zero (n : ℕ) [h : n.AtLeastTwo] : n ≠ 0 := by
rintro rfl; exact absurd h.1 (by decide)
@@ -172,10 +172,10 @@ theorem binCast_eq [AddMonoidWithOne R] (n : ℕ) : (Nat.binCast n : R) = ((n :
rw [Nat.binCast]
by_cases h : (k + 1) % 2 = 0
· rw [← Nat.mod_add_div (succ k) 2]
- rw [if_pos h, hk _ $ Nat.div_lt_self (Nat.succ_pos k) (Nat.le_refl 2), ← Nat.cast_add]
+ rw [if_pos h, hk _ <| Nat.div_lt_self (Nat.succ_pos k) (Nat.le_refl 2), ← Nat.cast_add]
rw [Nat.succ_eq_add_one, h, Nat.zero_add, Nat.succ_mul, Nat.one_mul]
· rw [← Nat.mod_add_div (succ k) 2]
- rw [if_neg h, hk _ $ Nat.div_lt_self (Nat.succ_pos k) (Nat.le_refl 2), ← Nat.cast_add]
+ rw [if_neg h, hk _ <| Nat.div_lt_self (Nat.succ_pos k) (Nat.le_refl 2), ← Nat.cast_add]
have h1 := Or.resolve_left (Nat.mod_two_eq_zero_or_one (succ k)) h
rw [h1, Nat.add_comm 1, Nat.succ_mul, Nat.one_mul]
simp only [Nat.cast_add, Nat.cast_one]
@@ -63,8 +63,8 @@ instance instOfNat [NatCast R] [Nat.AtLeastTwo n] : OfNat R n where
library_note "no_index around OfNat.ofNat"
/--
-When writing lemmas about `OfNat.ofNat` that assume `Nat.AtLeastTwo`, the term need to be wrapped in
-`no_index` so as not to confuse `simp`, as `no_index (OfNat.ofNat n)`.
+When writing lemmas about `OfNat.ofNat` that assume `Nat.AtLeastTwo`, the term needs to be wrapped
+in `no_index` so as not to confuse `simp`, as `no_index (OfNat.ofNat n)`.
Some discussion is [on Zulip here](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/.E2.9C.94.20Polynomial.2Ecoeff.20example/near/395438147).
-/
@@ -171,11 +171,11 @@ theorem binCast_eq [AddMonoidWithOne R] (n : ℕ) : (Nat.binCast n : R) = ((n :
| succ k =>
rw [Nat.binCast]
by_cases h : (k + 1) % 2 = 0
- · rw [←Nat.mod_add_div (succ k) 2]
- rw [if_pos h, hk _ $ Nat.div_lt_self (Nat.succ_pos k) (Nat.le_refl 2), ←Nat.cast_add]
+ · rw [← Nat.mod_add_div (succ k) 2]
+ rw [if_pos h, hk _ $ Nat.div_lt_self (Nat.succ_pos k) (Nat.le_refl 2), ← Nat.cast_add]
rw [Nat.succ_eq_add_one, h, Nat.zero_add, Nat.succ_mul, Nat.one_mul]
- · rw [←Nat.mod_add_div (succ k) 2]
- rw [if_neg h, hk _ $ Nat.div_lt_self (Nat.succ_pos k) (Nat.le_refl 2), ←Nat.cast_add]
+ · rw [← Nat.mod_add_div (succ k) 2]
+ rw [if_neg h, hk _ $ Nat.div_lt_self (Nat.succ_pos k) (Nat.le_refl 2), ← Nat.cast_add]
have h1 := Or.resolve_left (Nat.mod_two_eq_zero_or_one (succ k)) h
rw [h1, Nat.add_comm 1, Nat.succ_mul, Nat.one_mul]
simp only [Nat.cast_add, Nat.cast_one]
@@ -222,18 +222,18 @@ protected def AddMonoidWithOne.binary {R : Type*} [AddMonoid R] [One R] : AddMon
#align add_monoid_with_one.binary AddMonoidWithOne.binary
theorem one_add_one_eq_two [AddMonoidWithOne α] : 1 + 1 = (2 : α) := by
- rw [←Nat.cast_one, ←Nat.cast_add]
+ rw [← Nat.cast_one, ← Nat.cast_add]
apply congrArg
decide
#align one_add_one_eq_two one_add_one_eq_two
theorem two_add_one_eq_three [AddMonoidWithOne α] : 2 + 1 = (3 : α) := by
- rw [←one_add_one_eq_two, ←Nat.cast_one, ←Nat.cast_add, ←Nat.cast_add]
+ rw [← one_add_one_eq_two, ← Nat.cast_one, ← Nat.cast_add, ← Nat.cast_add]
apply congrArg
decide
theorem three_add_one_eq_four [AddMonoidWithOne α] : 3 + 1 = (4 : α) := by
- rw [←two_add_one_eq_three, ←one_add_one_eq_two, ←Nat.cast_one,
- ←Nat.cast_add, ←Nat.cast_add, ←Nat.cast_add]
+ rw [← two_add_one_eq_three, ← one_add_one_eq_two, ← Nat.cast_one,
+ ← Nat.cast_add, ← Nat.cast_add, ← Nat.cast_add]
apply congrArg
decide
Real.toNNReal
(#8136)
Add lemmas about comparison between Real.toNNReal
and Nat.cast
/OfNat.ofNat
.
Also add a few supporting lemmas.
@@ -47,6 +47,12 @@ class Nat.AtLeastTwo (n : ℕ) : Prop where
instance instNatAtLeastTwo : Nat.AtLeastTwo (n + 2) where
prop := Nat.succ_le_succ $ Nat.succ_le_succ $ Nat.zero_le _
+lemma Nat.AtLeastTwo.ne_zero (n : ℕ) [h : n.AtLeastTwo] : n ≠ 0 := by
+ rintro rfl; exact absurd h.1 (by decide)
+
+lemma Nat.AtLeastTwo.ne_one (n : ℕ) [h : n.AtLeastTwo] : n ≠ 1 := by
+ rintro rfl; exact absurd h.1 (by decide)
+
/-- Recognize numeric literals which are at least `2` as terms of `R` via `Nat.cast`. This
instance is what makes things like `37 : R` type check. Note that `0` and `1` are not needed
because they are recognized as terms of `R` (at least when `R` is an `AddMonoidWithOne`) through
@@ -55,6 +55,14 @@ because they are recognized as terms of `R` (at least when `R` is an `AddMonoidW
instance instOfNat [NatCast R] [Nat.AtLeastTwo n] : OfNat R n where
ofNat := n.cast
+library_note "no_index around OfNat.ofNat"
+/--
+When writing lemmas about `OfNat.ofNat` that assume `Nat.AtLeastTwo`, the term need to be wrapped in
+`no_index` so as not to confuse `simp`, as `no_index (OfNat.ofNat n)`.
+
+Some discussion is [on Zulip here](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/.E2.9C.94.20Polynomial.2Ecoeff.20example/near/395438147).
+-/
+
@[simp, norm_cast] theorem Nat.cast_ofNat [NatCast R] [Nat.AtLeastTwo n] :
(Nat.cast (no_index (OfNat.ofNat n)) : R) = OfNat.ofNat n := rfl
@@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Gabriel Ebner
-/
import Mathlib.Algebra.Group.Defs
+import Mathlib.Tactic.SplitIfs
#align_import data.nat.cast.defs from "leanprover-community/mathlib"@"a148d797a1094ab554ad4183a4ad6f130358ef64"
@@ -4,7 +4,6 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Gabriel Ebner
-/
import Mathlib.Algebra.Group.Defs
-import Mathlib.Algebra.NeZero
#align_import data.nat.cast.defs from "leanprover-community/mathlib"@"a148d797a1094ab554ad4183a4ad6f130358ef64"
@@ -207,22 +206,6 @@ protected def AddMonoidWithOne.binary {R : Type*} [AddMonoid R] [One R] : AddMon
rw [Nat.binCast_eq, Nat.binCast_eq, Nat.cast_succ] }
#align add_monoid_with_one.binary AddMonoidWithOne.binary
-namespace NeZero
-
-lemma natCast_ne (n : ℕ) (R) [AddMonoidWithOne R] [h : NeZero (n : R)] :
- (n : R) ≠ 0 := h.out
-#align ne_zero.nat_cast_ne NeZero.natCast_ne
-
-lemma of_neZero_natCast (R) [AddMonoidWithOne R] {n : ℕ} [h : NeZero (n : R)] : NeZero n :=
- ⟨by rintro rfl; exact h.out Nat.cast_zero⟩
-#align ne_zero.of_ne_zero_coe NeZero.of_neZero_natCast
-
-lemma pos_of_neZero_natCast (R) [AddMonoidWithOne R] {n : ℕ} [NeZero (n : R)] : 0 < n :=
- Nat.pos_of_ne_zero (of_neZero_natCast R).out
-#align ne_zero.pos_of_ne_zero_coe NeZero.pos_of_neZero_natCast
-
-end NeZero
-
theorem one_add_one_eq_two [AddMonoidWithOne α] : 1 + 1 = (2 : α) := by
rw [←Nat.cast_one, ←Nat.cast_add]
apply congrArg
Autoimplicits are highly controversial and also defeat the performance-improving work in #6474.
The intent of this PR is to make autoImplicit
opt-in on a per-file basis, by disabling it in the lakefile and enabling it again with set_option autoImplicit true
in the few files that rely on it.
That also keeps this PR small, as opposed to attempting to "fix" files to not need it any more.
I claim that many of the uses of autoImplicit
in these files are accidental; situations such as:
variables
are in scope, but pasting the lemma in the wrong sectionHaving set_option autoImplicit false
as the default prevents these types of mistake being made in the 90% of files where autoImplicit
s are not used at all, and causes them to be caught by CI during review.
I think there were various points during the port where we encouraged porters to delete the universes u v
lines; I think having autoparams for universe variables only would cover a lot of the cases we actually use them, while avoiding any real shortcomings.
A Zulip poll (after combining overlapping votes accordingly) was in favor of this change with 5:5:18
as the no:dontcare:yes
vote ratio.
While this PR was being reviewed, a handful of files gained some more likely-accidental autoImplicits. In these places, set_option autoImplicit true
has been placed locally within a section, rather than at the top of the file.
@@ -24,6 +24,8 @@ Preferentially, the homomorphism is written as the coercion `Nat.cast`.
* `Nat.cast`: Canonical homomorphism `ℕ → R`.
-/
+set_option autoImplicit true
+
/-- The numeral `((0+1)+⋯)+1`. -/
protected def Nat.unaryCast {R : Type u} [One R] [Zero R] [Add R] : ℕ → R
| 0 => 0
Type _
and Sort _
(#6499)
We remove all possible occurences of Type _
and Sort _
in favor of Type*
and Sort*
.
This has nice performance benefits.
@@ -76,7 +76,7 @@ class AddMonoidWithOne (R : Type u) extends NatCast R, AddMonoid R, One R where
#align add_monoid_with_one.nat_cast_succ AddMonoidWithOne.natCast_succ
/-- An `AddCommMonoidWithOne` is an `AddMonoidWithOne` satisfying `a + b = b + a`. -/
-class AddCommMonoidWithOne (R : Type _) extends AddMonoidWithOne R, AddCommMonoid R
+class AddCommMonoidWithOne (R : Type*) extends AddMonoidWithOne R, AddCommMonoid R
#align add_comm_monoid_with_one AddCommMonoidWithOne
#align add_comm_monoid_with_one.to_add_monoid_with_one AddCommMonoidWithOne.toAddMonoidWithOne
#align add_comm_monoid_with_one.to_add_comm_monoid AddCommMonoidWithOne.toAddCommMonoid
@@ -189,13 +189,13 @@ end Nat
/-- `AddMonoidWithOne` implementation using unary recursion. -/
@[reducible]
-protected def AddMonoidWithOne.unary {R : Type _} [AddMonoid R] [One R] : AddMonoidWithOne R :=
+protected def AddMonoidWithOne.unary {R : Type*} [AddMonoid R] [One R] : AddMonoidWithOne R :=
{ ‹One R›, ‹AddMonoid R› with }
#align add_monoid_with_one.unary AddMonoidWithOne.unary
/-- `AddMonoidWithOne` implementation using binary recursion. -/
@[reducible]
-protected def AddMonoidWithOne.binary {R : Type _} [AddMonoid R] [One R] : AddMonoidWithOne R :=
+protected def AddMonoidWithOne.binary {R : Type*} [AddMonoid R] [One R] : AddMonoidWithOne R :=
{ ‹One R›, ‹AddMonoid R› with
natCast := Nat.binCast,
natCast_zero := by simp only [Nat.binCast, Nat.cast],
Per https://github.com/leanprover/lean4/issues/2343, we are going to need to change the automatic generation of instance names, as they become too long.
This PR ensures that everywhere in Mathlib that refers to an instance by name, that name is given explicitly, rather than being automatically generated.
There are four exceptions, which are now commented, with links to https://github.com/leanprover/lean4/issues/2343.
This was implemented by running Mathlib against a modified Lean that appended _ᾰ
to all automatically generated names, and fixing everything.
Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
@@ -42,7 +42,7 @@ protected def Nat.unaryCast {R : Type u} [One R] [Zero R] [Add R] : ℕ → R
class Nat.AtLeastTwo (n : ℕ) : Prop where
prop : n ≥ 2
-instance : Nat.AtLeastTwo (n + 2) where
+instance instNatAtLeastTwo : Nat.AtLeastTwo (n + 2) where
prop := Nat.succ_le_succ $ Nat.succ_le_succ $ Nat.zero_le _
/-- Recognize numeric literals which are at least `2` as terms of `R` via `Nat.cast`. This
@@ -50,7 +50,7 @@ instance is what makes things like `37 : R` type check. Note that `0` and `1` a
because they are recognized as terms of `R` (at least when `R` is an `AddMonoidWithOne`) through
`Zero` and `One`, respectively. -/
@[nolint unusedArguments]
-instance [NatCast R] [Nat.AtLeastTwo n] : OfNat R n where
+instance instOfNat [NatCast R] [Nat.AtLeastTwo n] : OfNat R n where
ofNat := n.cast
@[simp, norm_cast] theorem Nat.cast_ofNat [NatCast R] [Nat.AtLeastTwo n] :
@@ -2,15 +2,12 @@
Copyright (c) 2014 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Gabriel Ebner
-
-! This file was ported from Lean 3 source module data.nat.cast.defs
-! leanprover-community/mathlib commit a148d797a1094ab554ad4183a4ad6f130358ef64
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
-/
import Mathlib.Algebra.Group.Defs
import Mathlib.Algebra.NeZero
+#align_import data.nat.cast.defs from "leanprover-community/mathlib"@"a148d797a1094ab554ad4183a4ad6f130358ef64"
+
/-!
# Cast of natural numbers
Co-authored-by: Komyyy <pol_tta@outlook.jp> Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Scott Morrison <scott.morrison@anu.edu.au> Co-authored-by: Ruben Van de Velde <65514131+Ruben-VandeVelde@users.noreply.github.com> Co-authored-by: Mario Carneiro <di.gama@gmail.com>
@@ -57,7 +57,7 @@ instance [NatCast R] [Nat.AtLeastTwo n] : OfNat R n where
ofNat := n.cast
@[simp, norm_cast] theorem Nat.cast_ofNat [NatCast R] [Nat.AtLeastTwo n] :
- (Nat.cast (OfNat.ofNat n) : R) = OfNat.ofNat n := rfl
+ (Nat.cast (no_index (OfNat.ofNat n)) : R) = OfNat.ofNat n := rfl
theorem Nat.cast_eq_ofNat [NatCast R] [Nat.AtLeastTwo n] : (Nat.cast n : R) = OfNat.ofNat n := rfl
This makes a mathlib4 version of mathlib3's tactic.basic
, now called Mathlib.Tactic.Common
, which imports all tactics which do not have significant theory requirements, and then is imported all across the base of the hierarchy.
This ensures that all common tactics are available nearly everywhere in the library, rather than having to be imported one-by-one as you need them.
Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
@@ -10,7 +10,6 @@ Authors: Mario Carneiro, Gabriel Ebner
-/
import Mathlib.Algebra.Group.Defs
import Mathlib.Algebra.NeZero
-import Mathlib.Tactic.SplitIfs
/-!
# Cast of natural numbers
@@ -109,8 +109,8 @@ theorem cast_zero : ((0 : ℕ) : R) = 0 :=
AddMonoidWithOne.natCast_zero
#align nat.cast_zero Nat.cast_zero
--- Lemmas about nat.succ need to get a low priority, so that they are tried last.
--- This is because `nat.succ _` matches `1`, `3`, `x+1`, etc.
+-- Lemmas about `Nat.succ` need to get a low priority, so that they are tried last.
+-- This is because `Nat.succ _` matches `1`, `3`, `x+1`, etc.
-- Rewriting would then produce really wrong terms.
@[simp 500, norm_cast 500]
theorem cast_succ (n : ℕ) : ((succ n : ℕ) : R) = n + 1 :=
We bump std4 and take care to delete the now-upstreamed (leanprover/std4#107) instances mentioned in #2878.
@@ -39,15 +39,6 @@ protected def Nat.unaryCast {R : Type u} [One R] [Zero R] [Add R] : ℕ → R
#align nat.cast Nat.cast
--- see note [coercion into rings]
-instance [NatCast R] : CoeTail ℕ R where coe := Nat.cast
-
--- see note [coercion into rings]
-instance [NatCast R] : CoeHTCT ℕ R where coe := Nat.cast
-
-/-- This instance is needed to ensure that `instCoeNatInt` is not used. -/
-instance : Coe ℕ ℤ where coe := Nat.cast
-
-- the following four declarations are not in mathlib3 and are relevant to the way numeric
-- literals are handled in Lean 4.
Int.ofNat
being used instead of Nat.cast
(#2878)
Without this override, the coercion is found as instCoeNatInt : Coe ℕ ℤ
which unfolds to Int.ofNat
. This only happened when searching for Coe ℕ ℤ
; CoeHTCT ℕ ℤ
would already find the correct instance.
@@ -45,6 +45,9 @@ instance [NatCast R] : CoeTail ℕ R where coe := Nat.cast
-- see note [coercion into rings]
instance [NatCast R] : CoeHTCT ℕ R where coe := Nat.cast
+/-- This instance is needed to ensure that `instCoeNatInt` is not used. -/
+instance : Coe ℕ ℤ where coe := Nat.cast
+
-- the following four declarations are not in mathlib3 and are relevant to the way numeric
-- literals are handled in Lean 4.
If M
has characteristic zero, then we simplify, e.g., (2 : M) = 10
to (2 : ℕ) = 10
.
@@ -66,6 +66,8 @@ instance [NatCast R] [Nat.AtLeastTwo n] : OfNat R n where
@[simp, norm_cast] theorem Nat.cast_ofNat [NatCast R] [Nat.AtLeastTwo n] :
(Nat.cast (OfNat.ofNat n) : R) = OfNat.ofNat n := rfl
+theorem Nat.cast_eq_ofNat [NatCast R] [Nat.AtLeastTwo n] : (Nat.cast n : R) = OfNat.ofNat n := rfl
+
/-! ### Additive monoids with one -/
/-- An `AddMonoidWithOne` is an `AddMonoid` with a `1`.
This PR is the result of a slight variant on the following "algorithm"
_
and make all uppercase letters into lowercase_
and make all uppercase letters into lowercase(original_lean3_name, OriginalLean4Name)
#align
statement just before the next empty line#align
statement to have been inserted too early)@@ -233,6 +233,7 @@ theorem one_add_one_eq_two [AddMonoidWithOne α] : 1 + 1 = (2 : α) := by
rw [←Nat.cast_one, ←Nat.cast_add]
apply congrArg
decide
+#align one_add_one_eq_two one_add_one_eq_two
theorem two_add_one_eq_three [AddMonoidWithOne α] : 2 + 1 = (3 : α) := by
rw [←one_add_one_eq_two, ←Nat.cast_one, ←Nat.cast_add, ←Nat.cast_add]
The script used to do this is included. The yaml file was obtained from https://raw.githubusercontent.com/wiki/leanprover-community/mathlib/mathlib4-port-status.md
@@ -2,6 +2,11 @@
Copyright (c) 2014 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Gabriel Ebner
+
+! This file was ported from Lean 3 source module data.nat.cast.defs
+! leanprover-community/mathlib commit a148d797a1094ab554ad4183a4ad6f130358ef64
+! Please do not edit these lines, except to modify the commit id
+! if you have ported upstream changes.
-/
import Mathlib.Algebra.Group.Defs
import Mathlib.Algebra.NeZero
All dependencies are ported!