Module docstring
{"# Idempotent elements of a ring
This file proves result about idempotent elements of a ring, like:
* IsIdempotentElem.one_sub_iff: In a (non-associative) ring, a is an idempotent if and only if
  1 - a is an idempotent.
"}
{"# Idempotent elements of a ring
This file proves result about idempotent elements of a ring, like:
* IsIdempotentElem.one_sub_iff: In a (non-associative) ring, a is an idempotent if and only if
  1 - a is an idempotent.
"}
IsIdempotentElem.one_sub
      theorem
     (h : IsIdempotentElem a) : IsIdempotentElem (1 - a)
        lemma one_sub (h : IsIdempotentElem a) : IsIdempotentElem (1 - a) := by
  rw [IsIdempotentElem, mul_sub, mul_one, sub_mul, one_mul, h.eq, sub_self, sub_zero]
        IsIdempotentElem.one_sub_iff
      theorem
     : IsIdempotentElem (1 - a) ↔ IsIdempotentElem a
        
      IsIdempotentElem.mul_one_sub_self
      theorem
     (h : IsIdempotentElem a) : a * (1 - a) = 0
        @[simp]
lemma mul_one_sub_self (h : IsIdempotentElem a) : a * (1 - a) = 0 := by
  rw [mul_sub, mul_one, h.eq, sub_self]
        IsIdempotentElem.one_sub_mul_self
      theorem
     (h : IsIdempotentElem a) : (1 - a) * a = 0
        @[simp]
lemma one_sub_mul_self (h : IsIdempotentElem a) : (1 - a) * a = 0 := by
  rw [sub_mul, one_mul, h.eq, sub_self]
        IsIdempotentElem.instHasComplSubtype
      instance
     : HasCompl { a : R // IsIdempotentElem a }
        instance : HasCompl {a : R // IsIdempotentElem a} where compl a := ⟨1 - a, a.prop.one_sub⟩
        IsIdempotentElem.coe_compl
      theorem
     (a : { a : R // IsIdempotentElem a }) : ↑aᶜ = (1 : R) - ↑a
        @[simp] lemma coe_compl (a : {a : R // IsIdempotentElem a}) : ↑aᶜ = (1 : R) - ↑a := rfl
        IsIdempotentElem.compl_compl
      theorem
     (a : { a : R // IsIdempotentElem a }) : aᶜᶜ = a
        @[simp] lemma compl_compl (a : {a : R // IsIdempotentElem a}) : aᶜaᶜᶜ = a := by ext; simp
        IsIdempotentElem.zero_compl
      theorem
     : (0 : { a : R // IsIdempotentElem a })ᶜ = 1
        @[simp] lemma zero_compl : (0 : {a : R // IsIdempotentElem a})ᶜ = 1 := by ext; simp
        IsIdempotentElem.one_compl
      theorem
     : (1 : { a : R // IsIdempotentElem a })ᶜ = 0
        @[simp] lemma one_compl : (1 : {a : R // IsIdempotentElem a})ᶜ = 0 := by ext; simp
        IsIdempotentElem.of_mul_add
      theorem
     (mul : a * b = 0) (add : a + b = 1) : IsIdempotentElem a ∧ IsIdempotentElem b
        lemma of_mul_add (mul : a * b = 0) (add : a + b = 1) : IsIdempotentElemIsIdempotentElem a ∧ IsIdempotentElem b := by
  simp_rw [IsIdempotentElem]; constructor
  · conv_rhs => rw [← mul_one a, ← add, mul_add, mul, add_zero]
  · conv_rhs => rw [← one_mul b, ← add, add_mul, mul, zero_add]
        IsIdempotentElem.add_sub_mul_of_commute
      theorem
     (h : Commute a b) (hp : IsIdempotentElem a) (hq : IsIdempotentElem b) : IsIdempotentElem (a + b - a * b)
        lemma add_sub_mul_of_commute (h : Commute a b) (hp : IsIdempotentElem a) (hq : IsIdempotentElem b) :
    IsIdempotentElem (a + b - a * b) := by
  convert (hp.one_sub.mul_of_commute ?_ hq.one_sub).one_sub using 1
  · simp_rw [sub_mul, mul_sub, one_mul, mul_one, sub_sub, sub_sub_cancel, add_sub, add_comm]
  · simp_rw [commute_iff_eq, sub_mul, mul_sub, one_mul, mul_one, sub_sub, add_sub, add_comm, h.eq]
        IsIdempotentElem.add_sub_mul
      theorem
     (hp : IsIdempotentElem a) (hq : IsIdempotentElem b) : IsIdempotentElem (a + b - a * b)
        lemma add_sub_mul (hp : IsIdempotentElem a) (hq : IsIdempotentElem b) :
    IsIdempotentElem (a + b - a * b) := add_sub_mul_of_commute (.all ..) hp hq