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: multiplication of intervals in rings #20636

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
37 changes: 36 additions & 1 deletion Mathlib/Algebra/Order/Interval/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ section Mul
variable [Preorder α] [Mul α] [MulLeftMono α] [MulRightMono α]

@[to_additive]
instance : Mul (NonemptyInterval α) :=
instance NonemptyInterval.instMul : Mul (NonemptyInterval α) :=
⟨fun s t => ⟨s.toProd * t.toProd, mul_le_mul' s.fst_le_snd t.fst_le_snd⟩⟩

@[to_additive]
Expand Down Expand Up @@ -529,6 +529,41 @@ instance divisionCommMonoid : DivisionCommMonoid (Interval α) :=

end Interval

namespace NonemptyInterval
variable [LinearOrderedSemiring α]

/-- Unlike `NonemptyInterval.instMul`, this works for semirings. -/
instance instMulOfSemiring : Mul (NonemptyInterval α) where
mul a b :=
{ fst := a.fst * b.fst ⊓ a.fst * b.snd ⊓ a.snd * b.fst ⊓ a.snd * b.snd
snd := a.fst * b.fst ⊔ a.fst * b.snd ⊔ a.snd * b.fst ⊔ a.snd * b.snd
fst_le_snd := by
dsimp
apply inf_le_sup.trans ?_
gcongr
apply inf_le_sup.trans ?_
gcongr
apply inf_le_sup.trans ?_
rfl }
Comment on lines +536 to +547
Copy link
Collaborator

Choose a reason for hiding this comment

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

This generalises the existing multiplication, right? Maybe we can merge both instances

Copy link
Member Author

Choose a reason for hiding this comment

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

I think only under certain assumptions. Right now I don't think either satisfies the requirements of the other.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Really? The existing one has [MulLeftMono α] [MulRightMono α], which implies a.fst * b.fst ⊓ a.fst * b.snd ⊓ a.snd * b.fst ⊓ a.snd * b.snd = a.fst * b.fst ⊓ a.snd * b.snd and similarly for


/-- `fst_mul` for rings. -/
@[simp] theorem fst_mul' (a b : NonemptyInterval α) :
(a * b).fst = a.fst * b.fst ⊓ a.fst * b.snd ⊓ a.snd * b.fst ⊓ a.snd * b.snd := rfl

/-- `fst_mul` for rings. -/
@[simp] theorem snd_mul' (a b : NonemptyInterval α) :
(a * b).snd = a.fst * b.fst ⊔ a.fst * b.snd ⊔ a.snd * b.fst ⊔ a.snd * b.snd := rfl

instance : MulZeroOneClass (NonemptyInterval α) where
mul_zero a := by ext <;> simp
zero_mul a := by ext <;> simp
mul_one a := by ext <;> simp [a.fst_le_snd]
one_mul a := by ext <;> simp [a.fst_le_snd]

-- TODO: Semiring (NonemptyInterval α)

end NonemptyInterval

section Length

variable [OrderedAddCommGroup α]
Expand Down
Loading