@@ -44,6 +44,10 @@ variable [Preorder α] [One α]
4444instance : One (NonemptyInterval α) :=
4545 ⟨NonemptyInterval.pure 1 ⟩
4646
47+ @[to_additive]
48+ instance : One (Interval α) :=
49+ ⟨(1 : NonemptyInterval α)⟩
50+
4751namespace NonemptyInterval
4852
4953@ [to_additive (attr := simp) toProd_zero]
@@ -74,9 +78,9 @@ namespace Interval
7478theorem pure_one : pure (1 : α) = 1 :=
7579 rfl
7680
77- @[to_additive] lemma one_ne_bot : (1 : Interval α) ≠ ⊥ := pure_ne_bot
81+ @ [to_additive (attr := simp) ] lemma one_ne_bot : (1 : Interval α) ≠ ⊥ := pure_ne_bot
7882
79- @[to_additive] lemma bot_ne_one : (⊥ : Interval α) ≠ 1 := bot_ne_pure
83+ @ [to_additive (attr := simp) ] lemma bot_ne_one : (⊥ : Interval α) ≠ 1 := bot_ne_pure
8084
8185end Interval
8286
@@ -167,7 +171,7 @@ variable (s t : Interval α)
167171theorem bot_mul : ⊥ * t = ⊥ :=
168172 WithBot.map₂_bot_left _ _
169173
170- @[to_additive]
174+ @ [to_additive (attr := simp) ]
171175theorem mul_bot : s * ⊥ = ⊥ :=
172176 WithBot.map₂_bot_right _ _
173177
@@ -219,7 +223,7 @@ namespace NonemptyInterval
219223@[to_additive]
220224instance commMonoid [CommMonoid α] [Preorder α] [IsOrderedMonoid α] :
221225 CommMonoid (NonemptyInterval α) :=
222- NonemptyInterval.toProd_injective.commMonoid _ toProd_one toProd_mul toProd_pow
226+ fast_instance% NonemptyInterval.toProd_injective.commMonoid _ toProd_one toProd_mul toProd_pow
223227
224228end NonemptyInterval
225229
@@ -235,10 +239,9 @@ instance Interval.mulOneClass [CommMonoid α] [Preorder α] [IsOrderedMonoid α]
235239
236240@[to_additive]
237241instance Interval.commMonoid [CommMonoid α] [Preorder α] [IsOrderedMonoid α] :
238- CommMonoid (Interval α) :=
239- { Interval.mulOneClass with
240- mul_comm := fun _ _ => Option.map₂_comm mul_comm
241- mul_assoc := fun _ _ _ => Option.map₂_assoc mul_assoc }
242+ CommMonoid (Interval α) where
243+ mul_comm := fun _ _ => Option.map₂_comm mul_comm
244+ mul_assoc := fun _ _ _ => Option.map₂_assoc mul_assoc
242245
243246namespace NonemptyInterval
244247
@@ -294,7 +297,7 @@ namespace NonemptyInterval
294297
295298instance [CommSemiring α] [PartialOrder α] [CanonicallyOrderedAdd α] :
296299 CommSemiring (NonemptyInterval α) :=
297- NonemptyInterval.toProd_injective.commSemiring _
300+ fast_instance% NonemptyInterval.toProd_injective.commSemiring _
298301 toProd_zero toProd_one toProd_add toProd_mul (swap toProd_nsmul) toProd_pow (fun _ => rfl)
299302
300303end NonemptyInterval
@@ -482,34 +485,32 @@ protected theorem mul_eq_one_iff : s * t = 1 ↔ ∃ a b, s = pure a ∧ t = pur
482485
483486instance subtractionCommMonoid {α : Type u}
484487 [AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α] :
485- SubtractionCommMonoid (NonemptyInterval α) :=
486- { NonemptyInterval.addCommMonoid with
487- sub_eq_add_neg := fun s t => by
488- refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;>
489- exact sub_eq_add_neg _ _
490- neg_neg := fun s => by apply NonemptyInterval.ext; exact neg_neg _
491- neg_add_rev := fun s t => by
492- refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;>
493- exact neg_add_rev _ _
494- neg_eq_of_add := fun s t h => by
495- obtain ⟨a, b, rfl, rfl, hab⟩ := NonemptyInterval.add_eq_zero_iff.1 h
496- rw [neg_pure, neg_eq_of_add_eq_zero_right hab]
497- -- TODO: use a better defeq
498- zsmul := zsmulRec }
488+ SubtractionCommMonoid (NonemptyInterval α) where
489+ sub_eq_add_neg := fun s t => by
490+ refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;>
491+ exact sub_eq_add_neg _ _
492+ neg_neg := fun s => by apply NonemptyInterval.ext; exact neg_neg _
493+ neg_add_rev := fun s t => by
494+ refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;>
495+ exact neg_add_rev _ _
496+ neg_eq_of_add := fun s t h => by
497+ obtain ⟨a, b, rfl, rfl, hab⟩ := NonemptyInterval.add_eq_zero_iff.1 h
498+ rw [neg_pure, neg_eq_of_add_eq_zero_right hab]
499+ -- TODO: use a better defeq
500+ zsmul := zsmulRec
499501
500502@ [to_additive existing NonemptyInterval.subtractionCommMonoid]
501- instance divisionCommMonoid : DivisionCommMonoid (NonemptyInterval α) :=
502- { NonemptyInterval.commMonoid with
503- div_eq_mul_inv := fun s t => by
504- refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;>
505- exact div_eq_mul_inv _ _
506- inv_inv := fun s => by apply NonemptyInterval.ext; exact inv_inv _
507- mul_inv_rev := fun s t => by
508- refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;>
509- exact mul_inv_rev _ _
510- inv_eq_of_mul := fun s t h => by
511- obtain ⟨a, b, rfl, rfl, hab⟩ := NonemptyInterval.mul_eq_one_iff.1 h
512- rw [inv_pure, inv_eq_of_mul_eq_one_right hab] }
503+ instance divisionCommMonoid : DivisionCommMonoid (NonemptyInterval α) where
504+ div_eq_mul_inv := fun s t => by
505+ refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;>
506+ exact div_eq_mul_inv _ _
507+ inv_inv := fun s => by apply NonemptyInterval.ext; exact inv_inv _
508+ mul_inv_rev := fun s t => by
509+ refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;>
510+ exact mul_inv_rev _ _
511+ inv_eq_of_mul := fun s t h => by
512+ obtain ⟨a, b, rfl, rfl, hab⟩ := NonemptyInterval.mul_eq_one_iff.1 h
513+ rw [inv_pure, inv_eq_of_mul_eq_one_right hab]
513514
514515end NonemptyInterval
515516
@@ -524,39 +525,37 @@ protected theorem mul_eq_one_iff : s * t = 1 ↔ ∃ a b, s = pure a ∧ t = pur
524525 cases t
525526 · simp
526527 · simp_rw [← NonemptyInterval.coe_mul_interval, ← NonemptyInterval.coe_one_interval,
527- WithBot .coe_inj, NonemptyInterval.coe_eq_pure]
528+ Interval .coe_inj, NonemptyInterval.coe_eq_pure]
528529 exact NonemptyInterval.mul_eq_one_iff
529530
530531instance subtractionCommMonoid {α : Type u}
531532 [AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α] :
532- SubtractionCommMonoid (Interval α) :=
533- { Interval.addCommMonoid with
534- sub_eq_add_neg := by
535- rintro (_ | s) (_ | t) <;> first | rfl | exact congr_arg WithBot.some (sub_eq_add_neg _ _)
536- neg_neg := by rintro (_ | s) <;> first | rfl | exact congr_arg WithBot.some (neg_neg _)
537- neg_add_rev := by
538- rintro (_ | s) (_ | t) <;> first | rfl | exact congr_arg WithBot.some (neg_add_rev _ _)
539- neg_eq_of_add := by
540- rintro (_ | s) (_ | t) h <;>
541- first
542- | cases h
543- | exact congr_arg WithBot.some (neg_eq_of_add_eq_zero_right <| WithBot.coe_injective h)
544- -- TODO: use a better defeq
545- zsmul := zsmulRec }
533+ SubtractionCommMonoid (Interval α) where
534+ sub_eq_add_neg := by
535+ rintro (_ | s) (_ | t) <;> first | rfl | exact congr_arg WithBot.some (sub_eq_add_neg _ _)
536+ neg_neg := by rintro (_ | s) <;> first | rfl | exact congr_arg WithBot.some (neg_neg _)
537+ neg_add_rev := by
538+ rintro (_ | s) (_ | t) <;> first | rfl | exact congr_arg WithBot.some (neg_add_rev _ _)
539+ neg_eq_of_add := by
540+ rintro (_ | s) (_ | t) h <;>
541+ first
542+ | cases h
543+ | exact congr_arg WithBot.some (neg_eq_of_add_eq_zero_right <| WithBot.coe_injective h)
544+ -- TODO: use a better defeq
545+ zsmul := zsmulRec
546546
547547@ [to_additive existing Interval.subtractionCommMonoid]
548- instance divisionCommMonoid : DivisionCommMonoid (Interval α) :=
549- { Interval.commMonoid with
550- div_eq_mul_inv := by
551- rintro (_ | s) (_ | t) <;> first | rfl | exact congr_arg WithBot.some (div_eq_mul_inv _ _)
552- inv_inv := by rintro (_ | s) <;> first | rfl | exact congr_arg WithBot.some (inv_inv _)
553- mul_inv_rev := by
554- rintro (_ | s) (_ | t) <;> first | rfl | exact congr_arg WithBot.some (mul_inv_rev _ _)
555- inv_eq_of_mul := by
556- rintro (_ | s) (_ | t) h <;>
557- first
558- | cases h
559- | exact congr_arg WithBot.some (inv_eq_of_mul_eq_one_right <| WithBot.coe_injective h) }
548+ instance divisionCommMonoid : DivisionCommMonoid (Interval α) where
549+ div_eq_mul_inv := by
550+ rintro (_ | s) (_ | t) <;> first | rfl | exact congr_arg WithBot.some (div_eq_mul_inv _ _)
551+ inv_inv := by rintro (_ | s) <;> first | rfl | exact congr_arg WithBot.some (inv_inv _)
552+ mul_inv_rev := by
553+ rintro (_ | s) (_ | t) <;> first | rfl | exact congr_arg WithBot.some (mul_inv_rev _ _)
554+ inv_eq_of_mul := by
555+ rintro (_ | s) (_ | t) h <;>
556+ first
557+ | cases h
558+ | exact congr_arg WithBot.some (inv_eq_of_mul_eq_one_right <| WithBot.coe_injective h)
560559
561560end Interval
562561
@@ -635,6 +634,10 @@ theorem length_neg : ∀ s : Interval α, (-s).length = s.length
635634 | ⊥ => rfl
636635 | (s : NonemptyInterval α) => s.length_neg
637636
637+ omit [IsOrderedAddMonoid α] in
638+ @[simp]
639+ theorem length_bot : (⊥ : Interval α).length = 0 := rfl
640+
638641theorem length_add_le : ∀ s t : Interval α, (s + t).length ≤ s.length + t.length
639642 | ⊥, _ => by simp
640643 | _, ⊥ => by simp
0 commit comments