The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V01. The language of Mathlib

Mathlib.Basic.Sign.Defs

82 declarations. Mathlib docs · Source

Sign type

This file defines the type of signs ${-1, 0, 1}$ and its basic arithmetic instances.

theorem SignType.fin3Equiv.match_1.congr_eq_2 E1 #

∀ (motive : SignType → Sort u_1) (a : SignType) (h_1 : Unit → motive SignType.zero) (h_2 : Unit → motive SignType.pos)
  (h_3 : Unit → motive SignType.neg),
  a = SignType.pos →
    (match a with
      | SignType.zero => h_1 ()
      | SignType.pos => h_2 ()
      | SignType.neg => h_3 ()) ≍
      h_2 ()

def SignType.ctorIdx E1 #

SignType → ℕ

theorem SignType.fin3Equiv.match_1.congr_eq_3 E1 #

∀ (motive : SignType → Sort u_1) (a : SignType) (h_1 : Unit → motive SignType.zero) (h_2 : Unit → motive SignType.pos)
  (h_3 : Unit → motive SignType.neg),
  a = SignType.neg →
    (match a with
      | SignType.zero => h_1 ()
      | SignType.pos => h_2 ()
      | SignType.neg => h_3 ()) ≍
      h_3 ()

theorem SignType.fin3Equiv.match_1.congr_eq_1 E1 #

∀ (motive : SignType → Sort u_1) (a : SignType) (h_1 : Unit → motive SignType.zero) (h_2 : Unit → motive SignType.pos)
  (h_3 : Unit → motive SignType.neg),
  a = SignType.zero →
    (match a with
      | SignType.zero => h_1 ()
      | SignType.pos => h_2 ()
      | SignType.neg => h_3 ()) ≍
      h_1 ()

theorem SignType.enumList_nodup E1 #

SignType.enumList.Nodup

abbrev SignType.enumList E1 #

List SignType

A list enumerating every element of the type, which are all zero-argument constructors. (Generated by the Fintype deriving handler.)

def instInhabitedSignType.default E1 #

SignType

theorem SignType.ofNat_ctorIdx E1 #

∀ (x : SignType), SignType.ofNat x.ctorIdx = x

abbrev SignType.ofNat E1 #

ℕ → SignType

theorem SignType.enumList_getElem?_ctorIdx_eq E0 #

∀ (x : SignType), SignType.enumList[x.ctorIdx]? = some x

abbrev SignType.ctorElimType E1 #

{motive : SignType → Sort u} → ℕ → Sort (max 1 u)

inductive SignType E1 #

Type

The type of signs.

ctor SignType.zero E0 #

SignType

ctor SignType.neg E0 #

SignType

ctor SignType.pos E0 #

SignType

instance instDecidableEqSignType E0 #

DecidableEq SignType

instance instFintypeSignType E0 #

Fintype SignType

instance instInhabitedSignType E0 #

Inhabited SignType

instance SignType.instZero E0 #

Zero SignType

instance SignType.instOne E0 #

One SignType

instance SignType.instNeg E0 #

Neg SignType

theorem SignType.zero_eq_zero E0 #

SignType.zero = 0

theorem SignType.neg_eq_neg_one E0 #

SignType.neg = -1

theorem SignType.pos_eq_one E0 #

SignType.pos = 1

theorem SignType.trichotomy E1 #

∀ (a : SignType), a = -1 ∨ a = 0 ∨ a = 1

instance SignType.instMul E0 #

Mul SignType

inductive SignType.LE E1 #

SignType → SignType → Prop

The less-than-or-equal relation on signs.

ctor SignType.LE.of_neg E0 #

∀ (a : SignType), SignType.neg.LE a

ctor SignType.LE.zero E0 #

SignType.zero.LE SignType.zero

ctor SignType.LE.of_pos E0 #

∀ (a : SignType), a.LE SignType.pos

instance SignType.instLE E0 #

LE SignType

instance SignType.instDecidableLE E0 #

DecidableLE SignType

instance SignType.instCommGroupWithZero E0 #

CommGroupWithZero SignType

We can define a Field instance on SignType, but it's not mathematically sensible, so we only define the CommGroupWithZero.

instance SignType.instLinearOrder E0 #

LinearOrder SignType

instance SignType.instBoundedOrder E0 #

BoundedOrder SignType

instance SignType.instHasDistribNeg E0 #

HasDistribNeg SignType

def SignType.fin3Equiv E1 #

SignType ≃* Fin 3

SignType is equivalent to Fin 3.

theorem SignType.nonneg_iff E0 #

∀ {a : SignType}, 0 ≤ a ↔ a = 0 ∨ a = 1

theorem SignType.nonneg_iff_ne_neg_one E1 #

∀ {a : SignType}, 0 ≤ a ↔ a ≠ -1

theorem SignType.neg_one_lt_iff E0 #

∀ {a : SignType}, -1 < a ↔ 0 ≤ a

theorem SignType.nonpos_iff E0 #

∀ {a : SignType}, a ≤ 0 ↔ a = -1 ∨ a = 0

theorem SignType.nonpos_iff_ne_one E1 #

∀ {a : SignType}, a ≤ 0 ↔ a ≠ 1

theorem SignType.lt_one_iff E0 #

∀ {a : SignType}, a < 1 ↔ a ≤ 0

theorem SignType.neg_iff E0 #

∀ {a : SignType}, a < 0 ↔ a = -1

theorem SignType.le_neg_one_iff E0 #

∀ {a : SignType}, a ≤ -1 ↔ a = -1

theorem SignType.pos_iff E0 #

∀ {a : SignType}, 0 < a ↔ a = 1

theorem SignType.one_le_iff E0 #

∀ {a : SignType}, 1 ≤ a ↔ a = 1

theorem SignType.neg_one_le E0 #

∀ (a : SignType), -1 ≤ a

theorem SignType.le_one E0 #

∀ (a : SignType), a ≤ 1

theorem SignType.not_lt_neg_one E0 #

∀ (a : SignType), ¬a < -1

theorem SignType.not_one_lt E0 #

∀ (a : SignType), ¬1 < a

theorem SignType.self_eq_neg_iff E0 #

∀ {a : SignType}, a = -a ↔ a = 0

theorem SignType.neg_eq_self_iff E0 #

∀ {a : SignType}, -a = a ↔ a = 0

theorem SignType.neg_eq_zero_iff E0 #

∀ {a : SignType}, -a = 0 ↔ a = 0

theorem SignType.neg_one_lt_one E0 #

-1 < 1

theorem SignType.neg_le_neg_iff E0 #

∀ {a b : SignType}, -a ≤ -b ↔ b ≤ a

theorem SignType.neg_lt_neg_iff E0 #

∀ {a b : SignType}, -a < -b ↔ b < a

def SignType.cast E1 #

{α : Type u_1} → [Zero α] → [One α] → [Neg α] → SignType → α

Turn a SignType into zero, one, or minus one. This is a coercion instance.

instance SignType.instCoeDep E0 #

{α : Type u_1} → [Zero α] → [One α] → [Neg α] → (s : SignType) → CoeDep SignType s α

This can't be a CoeTail or Coe instance because we don't want it to fire when SignType isn't involved in the coercion (or CoeHead or CoeOut because of outParams). The only other user-exposed option is CoeDep then, which allows us to match on both given and expected type.

theorem SignType.map_cast' E0 #

∀ {α : Type u_1} [inst : Zero α] [inst_1 : One α] [inst_2 : Neg α] {β : Type u_2} [inst_3 : One β] [inst_4 : Neg β]
  [inst_5 : Zero β] (f : α → β), f 1 = 1 → f 0 = 0 → f (-1) = -1 → ∀ (s : SignType), f ↑s = ↑s

Casting out of SignType respects composition with functions preserving 0, 1, -1.

theorem SignType.map_cast E0 #

∀ {α : Type u_2} {β : Type u_3} {F : Type u_4} [inst : AddGroupWithOne α] [inst_1 : One β]
  [inst_2 : SubtractionMonoid β] [inst_3 : FunLike F α β] [AddMonoidHomClass F α β] [OneHomClass F α β] (f : F)
  (s : SignType), f ↑s = ↑s

Casting out of SignType respects composition with suitable bundled homomorphism types.

theorem SignType.coe_zero E0 #

∀ {α : Type u_1} [inst : Zero α] [inst_1 : One α] [inst_2 : Neg α], ↑0 = 0

theorem SignType.coe_one E0 #

∀ {α : Type u_1} [inst : Zero α] [inst_1 : One α] [inst_2 : Neg α], ↑1 = 1

theorem SignType.coe_neg_one E0 #

∀ {α : Type u_1} [inst : Zero α] [inst_1 : One α] [inst_2 : Neg α], ↑(-1) = -1

theorem SignType.coe_neg E0 #

∀ {α : Type u_2} [inst : One α] [inst_1 : SubtractionMonoid α] (s : SignType), ↑(-s) = -↑s

def SignType.sign E1 #

{α : Type u_1} → [Zero α] → [inst : Preorder α] → [DecidableLT α] → α →o SignType

The sign of an element is 1 if it's positive, -1 if negative, 0 otherwise.

theorem sign_apply E0 #

∀ {α : Type u_1} [inst : Zero α] [inst_1 : Preorder α] [inst_2 : DecidableLT α] {a : α},
  SignType.sign a = if 0 < a then 1 else if a < 0 then -1 else 0

theorem sign_zero E0 #

∀ {α : Type u_1} [inst : Zero α] [inst_1 : Preorder α] [inst_2 : DecidableLT α], SignType.sign 0 = 0

theorem sign_pos E0 #

∀ {α : Type u_1} [inst : Zero α] [inst_1 : Preorder α] [inst_2 : DecidableLT α] {a : α}, 0 < a → SignType.sign a = 1

theorem sign_neg E0 #

∀ {α : Type u_1} [inst : Zero α] [inst_1 : Preorder α] [inst_2 : DecidableLT α] {a : α}, a < 0 → SignType.sign a = -1

theorem sign_eq_one_iff E0 #

∀ {α : Type u_1} [inst : Zero α] [inst_1 : Preorder α] [inst_2 : DecidableLT α] {a : α}, SignType.sign a = 1 ↔ 0 < a

theorem sign_eq_neg_one_iff E0 #

∀ {α : Type u_1} [inst : Zero α] [inst_1 : Preorder α] [inst_2 : DecidableLT α] {a : α}, SignType.sign a = -1 ↔ a < 0

theorem StrictMono.sign_comp E1 #

∀ {α : Type u_1} [inst : Zero α] [inst_1 : LinearOrder α] {β : Type u_2} {F : Type u_3} [inst_2 : Zero β]
  [inst_3 : Preorder β] [inst_4 : DecidableLT β] [inst_5 : FunLike F α β] [ZeroHomClass F α β] {f : F},
  StrictMono ⇑f → ∀ (a : α), SignType.sign (f a) = SignType.sign a

SignType.sign respects strictly monotone zero-preserving maps.

theorem sign_eq_zero_iff E0 #

∀ {α : Type u_1} [inst : Zero α] [inst_1 : LinearOrder α] {a : α}, SignType.sign a = 0 ↔ a = 0

theorem sign_ne_zero E1 #

∀ {α : Type u_1} [inst : Zero α] [inst_1 : LinearOrder α] {a : α}, SignType.sign a ≠ 0 ↔ a ≠ 0

theorem sign_nonneg_iff E0 #

∀ {α : Type u_1} [inst : Zero α] [inst_1 : LinearOrder α] {a : α}, 0 ≤ SignType.sign a ↔ 0 ≤ a

theorem sign_nonpos_iff E0 #

∀ {α : Type u_1} [inst : Zero α] [inst_1 : LinearOrder α] {a : α}, SignType.sign a ≤ 0 ↔ a ≤ 0

theorem sign_eq_sign_or_eq_neg E1 #

∀ {α : Type u_1} [inst : Zero α] [inst_1 : LinearOrder α] {a b : α},
  a ≠ 0 → b ≠ 0 → SignType.sign a = SignType.sign b ∨ SignType.sign a = -SignType.sign b

theorem sign_one E1 #

∀ {α : Type u_1} [inst : Semiring α] [inst_1 : PartialOrder α] [IsOrderedRing α] [inst_3 : DecidableLT α]
  [Nontrivial α], SignType.sign 1 = 1

theorem Left.sign_neg E1 #

∀ {α : Type u_1} [inst : AddGroup α] [inst_1 : Preorder α] [inst_2 : DecidableLT α] [AddLeftStrictMono α] (a : α),
  SignType.sign (-a) = -SignType.sign a

theorem Right.sign_neg E1 #

∀ {α : Type u_1} [inst : AddGroup α] [inst_1 : Preorder α] [inst_2 : DecidableLT α] [AddRightStrictMono α] (a : α),
  SignType.sign (-a) = -SignType.sign a

theorem Int.sign_eq_sign E1 #

∀ (n : ℤ), n.sign = ↑(SignType.sign n)