Skip to content

Commit

Permalink
feat(data/int/basic): Add unit lemmas (#13565)
Browse files Browse the repository at this point in the history
This PR adds a few more unit lemmas, and cleans up some of the proofs.
  • Loading branch information
tb65536 committed Apr 22, 2022
1 parent 695e0b7 commit 9c3cb72
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 0 additions & 3 deletions src/algebra/group_power/lemmas.lean
Expand Up @@ -520,9 +520,6 @@ theorem nat.cast_le_pow_div_sub {K : Type*} [linear_ordered_field K] {a : K} (H

namespace int

lemma units_sq (u : ℤˣ) : u ^ 2 = 1 :=
(sq u).symm ▸ units_mul_self u

alias int.units_sq ← int.units_pow_two

lemma units_pow_eq_pow_mod_two (u : ℤˣ) (n : ℕ) : u ^ n = u ^ (n % 2) :=
Expand Down
15 changes: 12 additions & 3 deletions src/data/int/basic.lean
Expand Up @@ -1317,11 +1317,20 @@ by rw [is_unit_iff_nat_abs_eq, abs_eq_nat_abs, ←int.coe_nat_one, coe_nat_inj']
lemma of_nat_is_unit {n : ℕ} : is_unit (n : ℤ) ↔ is_unit n :=
by rw [nat.is_unit_iff, is_unit_iff_nat_abs_eq, nat_abs_of_nat]

lemma units_inv_eq_self (u : ℤˣ) : u⁻¹ = u :=
(units_eq_one_or u).elim (λ h, h.symm ▸ rfl) (λ h, h.symm ▸ rfl)
lemma is_unit_mul_self {a : ℤ} (ha : is_unit a) : a * a = 1 :=
(is_unit_eq_one_or ha).elim (λ h, h.symm ▸ rfl) (λ h, h.symm ▸ rfl)

lemma is_unit_sq {a : ℤ} (ha : is_unit a) : a ^ 2 = 1 :=
by rw [sq, is_unit_mul_self ha]

@[simp] lemma units_sq (u : ℤˣ) : u ^ 2 = 1 :=
by rw [units.ext_iff, units.coe_pow, units.coe_one, is_unit_sq u.is_unit]

@[simp] lemma units_mul_self (u : ℤˣ) : u * u = 1 :=
(units_eq_one_or u).elim (λ h, h.symm ▸ rfl) (λ h, h.symm ▸ rfl)
by rw [←sq, units_sq]

@[simp] lemma units_inv_eq_self (u : ℤˣ) : u⁻¹ = u :=
by rw [inv_eq_iff_mul_eq_one, units_mul_self]

-- `units.coe_mul` is a "wrong turn" for the simplifier, this undoes it and simplifies further
@[simp] lemma units_coe_mul_self (u : ℤˣ) : (u * u : ℤ) = 1 :=
Expand Down

0 comments on commit 9c3cb72

Please sign in to comment.