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

feat(Algebra/MonoidAlgebra/NoZeroDivisors): NoZeroDivisors instance on AddMonoidAlgebras #6627

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

adomani
Copy link
Collaborator

@adomani adomani commented Aug 17, 2023

Porting the first part of mathlib3 #16157.

This contains the NoZeroDivisor instance on AddMonoidAlgebras that will trickle down to (Mv)Polynomials.


Open in Gitpod

@adomani adomani changed the title feat(): feat(Algebra/MonoidAlgebra/NoZeroDivisors): NoZeroDivisors instance on AddMonoidAlgebras Aug 17, 2023
@adomani adomani added awaiting-review The author would like community review of the PR t-algebra Algebra (groups, rings, fields etc) labels Aug 17, 2023
Comment on lines +266 to +267
variable [NoZeroDivisors R] [Add A] [LinearOrder A] [CovariantClass A A (· + ·) (· < ·)]
[CovariantClass A A (Function.swap (· + ·)) (· < ·)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, Covariants.to_uniqueSums uses the stronger set of conditions

 [CovariantClass A A (· * ·) (· ≤ ·)] [CovariantClass A A (Function.swap (· * ·)) (· < ·)]
 [ContravariantClass A A (· * ·) (· ≤ ·)]

In fact the last condition is equivalent to [CovariantClass A A (· + ·) (· < ·)] in a linear order because a + c ≤ a + b → c ≤ b is simply the contrapositive of b < c → a + b < a + c.

I think the way to go is to change Covariants.to_uniqueSums (and eq_and_eq_of_le_of_le_of_add_le) to use the same conditions as here, prove NoZeroDivisors.uniqueSums here instead, and derive NoZeroDivisors.biOrdered from it. And I think we can make the proof of NoZeroDivisors.of_left_ordered etc. a single line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could make UniqueSums a typeclass and then NoZeroDivisors.biOrdered would be inferInstance.

Also, it should be trivial to add the MonoidAlgebra version, but I think to_additive doesn't work here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right: the plan was indeed to use UniqueSums! I simply got stuck a few PRs before the port started... I'll fix it, but now is time to sleep for me!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks and no worries! It's my bad that I already realized the PR is outdated but still mentioned it. No rush to update PR because I find that stuff around Covariant/ContravariantClasses should benefit from some refactoring utilizing Lean 4's loopy instances: there are lots of results of the shape A ↔ B, or A → B and B ∧ C → A. It would be nice to unify the assumptions of Left.add_eq_add_iff_eq_and_eq, Right.add_eq_add_iff_eq_and_eq, and your eq_and_eq_of_le_of_le_of_add_le, for example. I'll keep you updated!

(And I just realized UniqueProds and UniqueSums are indeed already instances; I confused them with UniqueMul and UniqueMul.

Mathlib/Algebra/MonoidAlgebra/NoZeroDivisors.lean Outdated Show resolved Hide resolved
### Remarks
To prove `NoZeroDivisors.biOrdered`,
we use `CovariantClass` assumptions on `A`. In combination with `LinearOrder A`, these
assumptions actually imply that `A` is cancellative. However, cancellativity alone in not enough.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assumptions actually imply that `A` is cancellative. However, cancellativity alone in not enough.
assumptions actually imply that `A` is cancellative. However, cancellativity alone is not enough.

open Finsupp AddMonoidAlgebra

example {R} [Ring R] [Nontrivial R] :
∃ x y : AddMonoidAlgebra R (ZMod 2), x * y = 0 ∧ x ≠ 0 ∧ y ≠ 0 := by
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this belong in Counterexamples/?

The corresponding statement for a general product `f * g` is `AddMonoidAlgebra.mul_apply_of_le`.
It is proved with a further `CovariantClass` assumption. -/
theorem single_mul_apply_of_le (r : R) (ft : ∀ a ∈ f.support, a ≤ t) :
((AddMonoidAlgebra.single a r) * f) (a + t) = r * f t := by
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
((AddMonoidAlgebra.single a r) * f) (a + t) = r * f t := by
(AddMonoidAlgebra.single a r * f) (a + t) = r * f t := by

Comment on lines +229 to +230
((AddMonoidAlgebra.single a r) * f) (a + b) = r * f b :=
single_mul_apply_of_le (A := Aᵒᵈ) _ fb
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
((AddMonoidAlgebra.single a r) * f) (a + b) = r * f b :=
single_mul_apply_of_le (A := Aᵒᵈ) _ fb
(AddMonoidAlgebra.single a r * f) (a + b) = r * f b :=
single_mul_apply_of_le (A := Aᵒᵈ) _ fb

Here, "top" is simply an upper bound for the elements of the support of the corresponding
polynomial (e.g. the product is `0` if "top" is not a maximum). -/
theorem mul_apply_of_le (fa : ∀ i ∈ f.support, i ≤ a) (gt : ∀ i ∈ g.support, i ≤ t) :
(f * g) (a + t) = f a * g t := by
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(f * g) (a + t) = f a * g t := by
(f * g) (a + t) = f a * g t := by

Comment on lines +254 to +255
(f * g) (a + b) = f a * g b :=
mul_apply_of_le (A := Aᵒᵈ) fa gb
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(f * g) (a + b) = f a * g b :=
mul_apply_of_le (A := Aᵒᵈ) fa gb
(f * g) (a + b) = f a * g b :=
mul_apply_of_le (A := Aᵒᵈ) fa gb

mul_apply_of_le (A := Aᵒᵈ) fa gb

theorem mul_apply_eq_zero_of_lt (fa : ∀ i ∈ f.support, a ≤ i) (gb : ∀ i ∈ g.support, b < i) :
(f * g) (a + b) = 0 := by
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(f * g) (a + b) = 0 := by
(f * g) (a + b) = 0 := by

simp only [Finsupp.coe_zero, Pi.zero_apply]
rw [mul_apply_of_le] <;>
try exact Finset.le_max' _
refine mul_ne_zero_iff.mpr ⟨?_, ?_⟩ <;>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
refine mul_ne_zero_iff.mpr ⟨?_, ?_ <;>
refine mul_ne_zero ?_ ?_ <;>

@YaelDillies YaelDillies added awaiting-author A reviewer has asked the author a question or requested changes and removed awaiting-review The author would like community review of the PR labels Sep 6, 2023
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. label Sep 14, 2023
@bors bors bot changed the base branch from master to ScottCarnahan/BinomialRing2 September 17, 2023 03:26
@semorrison semorrison changed the base branch from ScottCarnahan/BinomialRing2 to master September 17, 2023 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-author A reviewer has asked the author a question or requested changes merge-conflict The PR has a merge conflict with master, and needs manual merging. t-algebra Algebra (groups, rings, fields etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants