Skip to content
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

[Merged by Bors] - feat: port Algebra.Ring.Defs #655

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b2e3173
feat: port remaining missing Algebra.GroupWithZero.Defs
pechersky Nov 9, 2022
f27a53a
merge
semorrison Nov 18, 2022
c36c9ff
Port `data.nat.cast.defs`
j-loreaux Nov 18, 2022
698f6ec
fix breakage due to `simp` set changes
j-loreaux Nov 18, 2022
51abcf4
add docstring
j-loreaux Nov 18, 2022
bd180f5
add import
j-loreaux Nov 18, 2022
4824c40
Move `Nat.AtLeastTwo` earlier in the file.
j-loreaux Nov 18, 2022
007c673
reapply `simp` attribute
j-loreaux Nov 18, 2022
7871670
Revert "fix breakage due to `simp` set changes"
j-loreaux Nov 18, 2022
261b4f7
fix
j-loreaux Nov 18, 2022
36bbdd9
port data.int.cast.defs
j-loreaux Nov 18, 2022
daab3bb
add to import list
j-loreaux Nov 18, 2022
6417536
appease linter?
j-loreaux Nov 18, 2022
c8aab54
alphabetize much?
j-loreaux Nov 18, 2022
53afda5
oops, fix a few things
j-loreaux Nov 18, 2022
6373859
Merge remote-tracking branch 'origin/j-loreaux/data.nat.cast.defs' in…
Ruben-VandeVelde Nov 19, 2022
c735db8
Remove ad-hoc NoZeroDivisors definition from Positivity (broken)
Ruben-VandeVelde Nov 19, 2022
4739e3b
Partial fix
Ruben-VandeVelde Nov 19, 2022
0f3411d
Import Algebra/Ring/Defs.lean from mathport
Ruben-VandeVelde Nov 19, 2022
0bf8247
Initial fixes
Ruben-VandeVelde Nov 19, 2022
1dbb7fc
More fixes
Ruben-VandeVelde Nov 19, 2022
316cfc0
merge?
semorrison Nov 20, 2022
d739522
don't change whitespace
semorrison Nov 20, 2022
f42eb27
fix
semorrison Nov 20, 2022
b19686f
finish porting; there was more to do in mathlib3port
semorrison Nov 20, 2022
4c6818a
formatting
semorrison Nov 20, 2022
d757f93
Merge remote-tracking branch 'origin/pechersky/port-group-with-zero-d…
semorrison Nov 20, 2022
b6ac3a0
attempt to fix ring
semorrison Nov 20, 2022
1c3623b
fix: timeout, cleanup
digama0 Nov 20, 2022
3e77d52
merge
semorrison Nov 20, 2022
91e8dd1
long lines
semorrison Nov 20, 2022
2139af0
wip
Ruben-VandeVelde Nov 20, 2022
e87fd72
Ungeneralize
Ruben-VandeVelde Nov 20, 2022
b8d3797
Lint
Ruben-VandeVelde Nov 20, 2022
157b9a3
More docs
Ruben-VandeVelde Nov 20, 2022
8f1ec10
Tidy
Ruben-VandeVelde Nov 20, 2022
d337912
Fix section
Ruben-VandeVelde Nov 20, 2022
d0914ea
Fix comments
Ruben-VandeVelde Nov 20, 2022
f9e8917
Review comments
Ruben-VandeVelde Nov 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Mathlib.lean
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Mathlib.Algebra.Order.Monoid.Lemmas
import Mathlib.Algebra.Order.Ring
import Mathlib.Algebra.PEmptyInstances
import Mathlib.Algebra.Ring.Basic
import Mathlib.Algebra.Ring.Defs
import Mathlib.CategoryTheory.ConcreteCategory.Bundled
import Mathlib.Control.Random
import Mathlib.Control.ULift
Expand Down
6 changes: 6 additions & 0 deletions Mathlib/Algebra/Group/Defs.lean
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ end Mul
/-- A semigroup is a type with an associative `(*)`. -/
@[ext]
class Semigroup (G : Type u) extends Mul G where
/-- Multiplication is associative -/
mul_assoc : ∀ a b c : G, a * b * c = a * (b * c)

/-- An additive semigroup is a type with an associative `(+)`. -/
@[ext]
class AddSemigroup (G : Type u) extends Add G where
/-- Addition is associative -/
add_assoc : ∀ a b c : G, a + b + c = a + (b + c)

attribute [to_additive] Semigroup
Expand Down Expand Up @@ -234,13 +236,17 @@ end RightCancelSemigroup
/-- Typeclass for expressing that a type `M` with multiplication and a one satisfies
`1 * a = a` and `a * 1 = a` for all `a : M`. -/
class MulOneClass (M : Type u) extends One M, Mul M where
/-- One is a left neutral element for multiplication -/
one_mul : ∀ a : M, 1 * a = a
/-- One is a right neutral element for multiplication -/
mul_one : ∀ a : M, a * 1 = a

/-- Typeclass for expressing that a type `M` with addition and a zero satisfies
`0 + a = a` and `a + 0 = a` for all `a : M`. -/
class AddZeroClass (M : Type u) extends Zero M, Add M where
/-- Zero is a left neutral element for addition -/
zero_add : ∀ a : M, 0 + a = a
/-- Zero is a right neutral element for addition -/
add_zero : ∀ a : M, a + 0 = a

attribute [to_additive] MulOneClass
Expand Down
2 changes: 2 additions & 0 deletions Mathlib/Algebra/GroupWithZero/Defs.lean
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ Monoid.npow_succ'
/-- Typeclass for expressing that a type `M₀` with multiplication and a zero satisfies
`0 * a = 0` and `a * 0 = 0` for all `a : M₀`. -/
class MulZeroClass (M₀ : Type u) extends Mul M₀, Zero M₀ where
/-- Zero is a left absorbing element for multiplication -/
zero_mul : ∀ a : M₀, 0 * a = 0
/-- Zero is a right absorbing element for multiplication -/
mul_zero : ∀ a : M₀, a * 0 = 0

export MulZeroClass (zero_mul mul_zero)
Expand Down
44 changes: 1 addition & 43 deletions Mathlib/Algebra/Ring/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,15 @@ import Mathlib.Algebra.Group.Commute
import Mathlib.Algebra.GroupWithZero.Defs
import Mathlib.Data.Int.Cast.Defs
import Mathlib.Tactic.Spread
import Mathlib.Algebra.Ring.Defs

/-
# Semirings and rings
-/

/-- A typeclass stating that multiplication is left and right distributive
over addition. -/
class Distrib (R : Type u) extends Mul R, Add R where
left_distrib : ∀ a b c : R, a * (b + c) = (a * b) + (a * c)
right_distrib : ∀ a b c : R, (a + b) * c = (a * c) + (b * c)

export Distrib (left_distrib right_distrib)

section
variable {R} [Distrib R]
theorem mul_add (a b c : R) : a * (b + c) = a * b + a * c := Distrib.left_distrib a b c
theorem add_mul (a b c : R) : (a + b) * c = a * c + b * c := Distrib.right_distrib a b c
end

/-- A not-necessarily-unital, not-necessarily-associative semiring. -/
class NonUnitalNonAssocSemiring (R : Type u) extends
AddCommMonoid R, Distrib R, MulZeroClass R, AddMonoidWithOne R

/-- An associative but not-necessarily unital semiring. -/
class NonUnitalSemiring (α : Type u) extends NonUnitalNonAssocSemiring α, SemigroupWithZero α

/-- A unital but not-necessarily-associative semiring. -/
class NonAssocSemiring (α : Type u) extends NonUnitalNonAssocSemiring α, MulZeroOneClass α

class Semiring (R : Type u) extends NonUnitalSemiring R, NonAssocSemiring R, MonoidWithZero R

section Semiring

-- TODO: put these in the right place
Expand Down Expand Up @@ -65,28 +43,8 @@ theorem Nat.cast_commute [Semiring α] (n : ℕ) (x : α) : Commute (↑n) x :=

end Semiring

class CommSemiring (R : Type u) extends Semiring R, CommMonoid R where
-- TODO: doesn't work
right_distrib a b c := (by rw [mul_comm, mul_add, mul_comm c, mul_comm c])

class Ring (R : Type u) extends Semiring R, AddCommGroup R, AddGroupWithOne R

example [Ring R] : HasInvolutiveNeg R := inferInstance

@[simp] theorem neg_mul {R} [Ring R] (a b : R) : (-a) * b = -(a * b) :=
eq_of_sub_eq_zero' <| by rw [sub_eq_add_neg, neg_neg, ← add_mul, neg_add_self, zero_mul]

@[simp] lemma mul_neg [Ring R] (a b : R) : a * -b = - (a * b) :=
eq_of_sub_eq_zero' <| by rw [sub_eq_add_neg, neg_neg, ← mul_add, neg_add_self, mul_zero]

theorem neg_mul_eq_neg_mul {R} [Ring R] (a b : R) : -(a * b) = (-a) * b := (neg_mul ..).symm

theorem mul_sub_right_distrib [Ring R] (a b c : R) : (a - b) * c = a * c - b * c := by
simpa only [sub_eq_add_neg, neg_mul_eq_neg_mul] using add_mul a (-b) c

alias mul_sub_right_distrib ← sub_mul

class CommRing (R : Type u) extends Ring R, CommSemiring R

/- Instances -/

Expand Down
Loading