Skip to content

Commit c19d45a

Browse files
committed
feat(Data/Sign): some more API for SignType (#10920)
Since `Real.sign` etc are being deprecated in favour of the generic `SignType.sign`, this PR adds some more API for the latter: in particular, compatibility of the canonical maps in and out of `SignType` with maps satisfying suitable assumptions. This is a prerequisite for #10011.
1 parent 2414ba0 commit c19d45a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Mathlib/Data/Sign.lean

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,18 @@ instance : CoeTC SignType α :=
250250

251251
-- Porting note: `cast_eq_coe` removed, syntactic equality
252252

253+
/-- Casting out of `SignType` respects composition with functions preserving `0, 1, -1`. -/
254+
lemma map_cast' {β : Type*} [One β] [Neg β] [Zero β]
255+
(f : α → β) (h₁ : f 1 = 1) (h₂ : f 0 = 0) (h₃ : f (-1) = -1) (s : SignType) :
256+
f s = s := by
257+
cases s <;> simp only [SignType.cast, h₁, h₂, h₃]
258+
259+
/-- Casting out of `SignType` respects composition with suitable bundled homomorphism types. -/
260+
lemma map_cast {α β F : Type*} [AddGroupWithOne α] [One β] [SubtractionMonoid β]
261+
[FunLike F α β] [AddMonoidHomClass F α β] [OneHomClass F α β] (f : F) (s : SignType) :
262+
f s = s := by
263+
apply map_cast' <;> simp
264+
253265
@[simp]
254266
theorem coe_zero : ↑(0 : SignType) = (0 : α) :=
255267
rfl
@@ -265,6 +277,11 @@ theorem coe_neg_one : ↑(-1 : SignType) = (-1 : α) :=
265277
rfl
266278
#align sign_type.coe_neg_one SignType.coe_neg_one
267279

280+
@[simp, norm_cast]
281+
lemma coe_neg {α : Type*} [One α] [SubtractionMonoid α] (s : SignType) :
282+
(↑(-s) : α) = -↑s := by
283+
cases s <;> simp
284+
268285
end cast
269286

270287
/-- `SignType.cast` as a `MulWithZeroHom`. -/
@@ -354,6 +371,12 @@ section LinearOrder
354371

355372
variable [Zero α] [LinearOrder α] {a : α}
356373

374+
/-- `SignType.sign` respects strictly monotone zero-preserving maps. -/
375+
lemma StrictMono.sign_comp {β F : Type*} [Zero β] [Preorder β] [DecidableRel ((· < ·) : β → β → _)]
376+
[FunLike F α β] [ZeroHomClass F α β] {f : F} (hf : StrictMono f) (a : α) :
377+
sign (f a) = sign a := by
378+
simp only [sign_apply, ← map_zero f, hf.lt_iff_lt]
379+
357380
@[simp]
358381
theorem sign_eq_zero_iff : sign a = 0 ↔ a = 0 := by
359382
refine' ⟨fun h => _, fun h => h.symm ▸ sign_zero⟩

0 commit comments

Comments
 (0)