Skip to content

Commit

Permalink
chore(algebra/ring/basic): generalize `is_domain.to_cancel_monoid_wit…
Browse files Browse the repository at this point in the history
…h_zero` to `no_zero_divisors` (#11387)

This generalization doesn't work for typeclass search as `cancel_monoid_with_zero` implies `no_zero_divisors` which would form a loop, but it can be useful for a `letI` in another proof.

Independent of whether this turns out to be useful, it's nice to show that nontriviality doesn't affect the fact that rings with no zero divisors are cancellative.
  • Loading branch information
eric-wieser committed Jan 12, 2022
1 parent cb1b6d9 commit 72c86c3
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/algebra/ring/basic.lean
Expand Up @@ -1031,6 +1031,18 @@ lemma is_regular_of_ne_zero' [ring α] [no_zero_divisors α] {k : α} (hk : k
is_right_regular_of_non_zero_divisor k
(λ x h, (no_zero_divisors.eq_zero_or_eq_zero_of_mul_eq_zero h).resolve_right hk)⟩

/-- A ring with no zero divisors is a cancel_monoid_with_zero.
Note this is not an instance as it forms a typeclass loop. -/
@[reducible]
def no_zero_divisors.to_cancel_monoid_with_zero [ring α] [no_zero_divisors α] :
cancel_monoid_with_zero α :=
{ mul_left_cancel_of_ne_zero := λ a b c ha,
@is_regular.left _ _ _ (is_regular_of_ne_zero' ha) _ _,
mul_right_cancel_of_ne_zero := λ a b c hb,
@is_regular.right _ _ _ (is_regular_of_ne_zero' hb) _ _,
.. (infer_instance : semiring α) }

/-- A domain is a nontrivial ring with no zero divisors, i.e. satisfying
the condition `a * b = 0 ↔ a = 0 ∨ b = 0`.
Expand All @@ -1046,11 +1058,7 @@ variables [ring α] [is_domain α]

@[priority 100] -- see Note [lower instance priority]
instance is_domain.to_cancel_monoid_with_zero : cancel_monoid_with_zero α :=
{ mul_left_cancel_of_ne_zero := λ a b c ha,
@is_regular.left _ _ _ (is_regular_of_ne_zero' ha) _ _,
mul_right_cancel_of_ne_zero := λ a b c hb,
@is_regular.right _ _ _ (is_regular_of_ne_zero' hb) _ _,
.. (infer_instance : semiring α) }
no_zero_divisors.to_cancel_monoid_with_zero

/-- Pullback an `is_domain` instance along an injective function. -/
protected theorem function.injective.is_domain [ring β] (f : β →+* α) (hf : injective f) :
Expand Down

0 comments on commit 72c86c3

Please sign in to comment.