Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idempotent ring elements #2105

Merged
merged 6 commits into from
Oct 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions theories/Algebra/Rings/Idempotent.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
Require Import Basics.Overture Basics.Tactics Basics.PathGroupoids.
Require Import Basics.Equivalences Basics.Trunc Types.Sigma WildCat.Core.
Require Import Nat.Core Rings.Ring.

Local Open Scope mc_scope.

(** * Idempotent elements of rings *)

(** ** Definition *)

Class IsIdempotent (R : Ring) (e : R)
:= rng_idem : e * e = e.

Global Instance ishprop_isidempotent R e : IsHProp (IsIdempotent R e).
Proof.
unfold IsIdempotent; exact _.
Defined.

(** *** Examples *)

(** Zero is idempotent. *)
Global Instance isidempotent_zero (R : Ring) : IsIdempotent R 0
:= rng_mult_zero_r 0.

(** One is idempotent. *)
Global Instance isidempotent_one (R : Ring) : IsIdempotent R 1
:= rng_mult_one_r 1.

(** If [e] is idempotent, then [1 - e] is idempotent. *)
Global Instance isidempotent_compliment (R : Ring) (e : R) `{IsIdempotent R e}
Alizter marked this conversation as resolved.
Show resolved Hide resolved
: IsIdempotent R (1 - e).
Proof.
unfold IsIdempotent.
rewrite rng_dist_l_negate.
rewrite 2 rng_dist_r_negate.
rewrite 2 rng_mult_one_l.
rewrite rng_mult_one_r.
rewrite rng_idem.
rewrite rng_plus_negate_r.
rewrite rng_negate_zero.
nrapply rng_plus_zero_r.
Defined.

(** If [e] is idempotent, then it is also an idempotent element of the opposite ring. *)
Global Instance isidempotent_op (R : Ring) (e : R) `{IsIdempotent R e}
: IsIdempotent (rng_op R) e
:= rng_idem (R:=R).
Alizter marked this conversation as resolved.
Show resolved Hide resolved

(** Any positive power of an idempotent element [e] is [e]. *)
Definition rng_power_idem {R : Ring} (e : R) `{IsIdempotent R e} (n : nat)
: (1 <= n)%nat -> rng_power e n = e.
Proof.
intros L; induction L.
- snrapply rng_mult_one_r.
- rhs_V rapply rng_idem.
exact (ap (e *.) IHL).
Defined.

(** Ring homomorphisms preserve idempotent elements. *)
Global Instance isidempotent_rng_homo {R S : Ring} (f : R $-> S) (e : R)
: IsIdempotent R e -> IsIdempotent S (f e).
Proof.
intros p.
lhs_V nrapply rng_homo_mult.
exact (ap f p).
Defined.

(** ** Orthogonal idempotent elements *)

(** Two idempotent elements [e] and [f] are orthogonal if both [e * f = 0] and [f * e = 0]. *)
Class IsOrthogonal (R : Ring) (e f : R)
`{!IsIdempotent R e, !IsIdempotent R f} := {
rng_idem_orth : e * f = 0 ;
rng_idem_orth' : f * e = 0 ;
}.

Definition issig_IsOrthogonal {R : Ring} {e f : R}
`{IsIdempotent R e, IsIdempotent R f}
: _ <~> IsOrthogonal R e f
:= ltac:(issig).

Global Instance ishprop_isorthogonal R e f
`{IsIdempotent R e, IsIdempotent R f}
: IsHProp (IsOrthogonal R e f).
Proof.
exact (istrunc_equiv_istrunc _ issig_IsOrthogonal).
Defined.

(** *** Properties *)

(** Two idempotents being orthogonal is a symmetric relation. *)
Definition isorthogonal_swap (R : Ring) (e f : R) `{IsOrthogonal R e f}
: IsOrthogonal R f e
:= {| rng_idem_orth := rng_idem_orth' ; rng_idem_orth' := rng_idem_orth |}.
Hint Immediate isorthogonal_swap : typeclass_instances.


Alizter marked this conversation as resolved.
Show resolved Hide resolved
(** If [e] and [f] are orthogonal idempotents, then they are also orthogonal idempotents in the opposite ring. *)
Alizter marked this conversation as resolved.
Show resolved Hide resolved
Global Instance isorthogonal_op {R : Ring} (e f : R) `{r : IsOrthogonal R e f}
: IsOrthogonal (rng_op R) e f.
Proof.
snrapply Build_IsOrthogonal.
- exact (rng_idem_orth' (R:=R)).
- exact (rng_idem_orth (R:=R)).
Defined.
Comment on lines +100 to +104
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work to replace this proof with := isorthogonal_swap R e f r.?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite. I tried it again and it still doesn't work. I also thought something like this should work but I couldn't work it out.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's because of the proofs of idempotency that are carried along? (Incidentally, they aren't used in any way, but I guess it makes sense to keep them.) In any case, this isn't worth worrying about.


(** If [e] and [f] are orthogonal idempotents, then [e + f] is idempotent. *)
Global Instance isidempotent_plus_orthogonal {R : Ring} (e f : R)
`{IsOrthogonal R e f}
: IsIdempotent R (e + f).
Proof.
unfold IsIdempotent.
rewrite rng_dist_l.
rewrite 2 rng_dist_r.
rewrite 2 rng_idem.
rewrite 2 rng_idem_orth.
by rewrite rng_plus_zero_r, rng_plus_zero_l.
Defined.

(** An idempotent element [e] is orthogonal to its complement [1 - e]. *)
Global Instance isorthogonal_compliment {R : Ring} (e : R) `{IsIdempotent R e}
Alizter marked this conversation as resolved.
Show resolved Hide resolved
: IsOrthogonal R e (1 - e).
Proof.
snrapply Build_IsOrthogonal.
1: rewrite rng_dist_l_negate,rng_mult_one_r.
2: rewrite rng_dist_r_negate, rng_mult_one_l.
1,2: rewrite rng_idem.
1,2: apply rng_plus_negate_r.
Defined.
Loading