l3lab/ntp-mathlib huggingface dataset:
/-- The group structure on `DihedralGroup n`.
-/
instance : Group (DihedralGroup n) where
  mul := mul
  mul_assoc := by rintro (a | a) (b | b) (c | c) <;> simp only [(· * ·), mul] <;> ring_nf
  one := one
  one_mul := by
    rintro (a | a)
    exact congr_arg r (zero_add a)
    exact congr_arg sr (sub_zero a)
  mul_one := by
    rintro (a | a)
    exact congr_arg r (add_zero a)
    exact congr_arg sr (add_zero a)
  inv := inv
  mul_left_inv := by
    rintro (a | a)
    exact congr_arg r (neg_add_self a)
    

Proof state:
case sr
n : ℕ
a : ZMod n
⊢ (sr a)⁻¹ * sr a = 1

Next tactic:
exact congr_arg r (sub_self a)
private def fintypeHelper : Sum (ZMod n) (ZMod n) ≃ DihedralGroup n where
  invFun i := match i with
    | r j => Sum.inl j
    | sr j => Sum.inr j
  toFun i := match i with
    | Sum.inl j => r j
    | Sum.inr j => sr j
  left_inv := by 

Proof state:
n : ℕ
⊢ Function.LeftInverse
    (fun i =>
      match i with
      | r j => Sum.inl j
      | sr j => Sum.inr j)
    fun i =>
    match i with
    | Sum.inl j => r j
    | Sum.inr j => sr j

Next tactic:
rintro (x | x)
private def fintypeHelper : Sum (ZMod n) (ZMod n) ≃ DihedralGroup n where
  invFun i := match i with
    | r j => Sum.inl j
    | sr j => Sum.inr j
  toFun i := match i with
    | Sum.inl j => r j
    | Sum.inr j => sr j
  left_inv := by rintro (x | x) <;> 

Proof state:
case inl
n : ℕ
x : ZMod n
⊢ (fun i =>
        match i with
        | r j => Sum.inl j
        | sr j => Sum.inr j)
      ((fun i =>
          match i with
          | Sum.inl j => r j
          | Sum.inr j => sr j)
        (Sum.inl x)) =
    Sum.inl x

Next tactic:
rfl
private def fintypeHelper : Sum (ZMod n) (ZMod n) ≃ DihedralGroup n where
  invFun i := match i with
    | r j => Sum.inl j
    | sr j => Sum.inr j
  toFun i := match i with
    | Sum.inl j => r j
    | Sum.inr j => sr j
  left_inv := by rintro (x | x) <;> 

Proof state:
case inr
n : ℕ
x : ZMod n
⊢ (fun i =>
        match i with
        | r j => Sum.inl j
        | sr j => Sum.inr j)
      ((fun i =>
          match i with
          | Sum.inl j => r j
          | Sum.inr j => sr j)
        (Sum.inr x)) =
    Sum.inr x

Next tactic:
rfl
private def fintypeHelper : Sum (ZMod n) (ZMod n) ≃ DihedralGroup n where
  invFun i := match i with
    | r j => Sum.inl j
    | sr j => Sum.inr j
  toFun i := match i with
    | Sum.inl j => r j
    | Sum.inr j => sr j
  left_inv := by rintro (x | x) <;> rfl
  right_inv := by 

Proof state:
n : ℕ
⊢ Function.RightInverse
    (fun i =>
      match i with
      | r j => Sum.inl j
      | sr j => Sum.inr j)
    fun i =>
    match i with
    | Sum.inl j => r j
    | Sum.inr j => sr j

Next tactic:
rintro (x | x)
private def fintypeHelper : Sum (ZMod n) (ZMod n) ≃ DihedralGroup n where
  invFun i := match i with
    | r j => Sum.inl j
    | sr j => Sum.inr j
  toFun i := match i with
    | Sum.inl j => r j
    | Sum.inr j => sr j
  left_inv := by rintro (x | x) <;> rfl
  right_inv := by rintro (x | x) <;> 

Proof state:
case r
n : ℕ
x : ZMod n
⊢ (fun i =>
        match i with
        | Sum.inl j => r j
        | Sum.inr j => sr j)
      ((fun i =>
          match i with
          | r j => Sum.inl j
          | sr j => Sum.inr j)
        (r x)) =
    r x

Next tactic:
rfl
private def fintypeHelper : Sum (ZMod n) (ZMod n) ≃ DihedralGroup n where
  invFun i := match i with
    | r j => Sum.inl j
    | sr j => Sum.inr j
  toFun i := match i with
    | Sum.inl j => r j
    | Sum.inr j => sr j
  left_inv := by rintro (x | x) <;> rfl
  right_inv := by rintro (x | x) <;> 

Proof state:
case sr
n : ℕ
x : ZMod n
⊢ (fun i =>
        match i with
        | Sum.inl j => r j
        | Sum.inr j => sr j)
      ((fun i =>
          match i with
          | r j => Sum.inl j
          | sr j => Sum.inr j)
        (sr x)) =
    sr x

Next tactic:
rfl
instance : Nontrivial (DihedralGroup n) :=
  ⟨⟨r 0, sr 0, by 

Proof state:
n : ℕ
⊢ r 0 ≠ sr 0

Next tactic:
simp_rw [ne_eq, not_false_eq_true]
/-- If `0 < n`, then `DihedralGroup n` has `2n` elements.
-/
theorem card [NeZero n] : Fintype.card (DihedralGroup n) = 2 * n := by
  

Proof state:
n : ℕ
inst✝ : NeZero n
⊢ Fintype.card (DihedralGroup n) = 2 * n

Next tactic:
rw [← Fintype.card_eq.mpr ⟨fintypeHelper⟩, Fintype.card_sum, ZMod.card, two_mul]
theorem nat_card : Nat.card (DihedralGroup n) = 2 * n := by
  

Proof state:
n : ℕ
⊢ Nat.card (DihedralGroup n) = 2 * n

Next tactic:
cases n
theorem nat_card : Nat.card (DihedralGroup n) = 2 * n := by
  cases n
  · 

Proof state:
case zero
⊢ Nat.card (DihedralGroup Nat.zero) = 2 * Nat.zero

Next tactic:
rw [Nat.card_eq_zero_of_infinite]
theorem nat_card : Nat.card (DihedralGroup n) = 2 * n := by
  cases n
  · rw [Nat.card_eq_zero_of_infinite]
  · 

Proof state:
case succ
n✝ : ℕ
⊢ Nat.card (DihedralGroup (Nat.succ n✝)) = 2 * Nat.succ n✝

Next tactic:
rw [Nat.card_eq_fintype_card, card]
@[simp]
theorem r_one_pow (k : ℕ) : (r 1 : DihedralGroup n) ^ k = r k := by
  

Proof state:
n k : ℕ
⊢ r 1 ^ k = r ↑k

Next tactic:
induction' k with k IH
@[simp]
theorem r_one_pow (k : ℕ) : (r 1 : DihedralGroup n) ^ k = r k := by
  induction' k with k IH
  · 

Proof state:
case zero
n : ℕ
⊢ r 1 ^ Nat.zero = r ↑Nat.zero

Next tactic:
rw [Nat.cast_zero]
@[simp]
theorem r_one_pow (k : ℕ) : (r 1 : DihedralGroup n) ^ k = r k := by
  induction' k with k IH
  · rw [Nat.cast_zero]
    

Proof state:
case zero
n : ℕ
⊢ r 1 ^ Nat.zero = r 0

Next tactic:
rfl
@[simp]
theorem r_one_pow (k : ℕ) : (r 1 : DihedralGroup n) ^ k = r k := by
  induction' k with k IH
  · rw [Nat.cast_zero]
    rfl
  · 

Proof state:
case succ
n k : ℕ
IH : r 1 ^ k = r ↑k
⊢ r 1 ^ Nat.succ k = r ↑(Nat.succ k)

Next tactic:
rw [pow_succ, IH, r_mul_r]
@[simp]
theorem r_one_pow (k : ℕ) : (r 1 : DihedralGroup n) ^ k = r k := by
  induction' k with k IH
  · rw [Nat.cast_zero]
    rfl
  · rw [pow_succ, IH, r_mul_r]
    

Proof state:
case succ
n k : ℕ
IH : r 1 ^ k = r ↑k
⊢ r (1 + ↑k) = r ↑(Nat.succ k)

Next tactic:
congr 1
@[simp]
theorem r_one_pow (k : ℕ) : (r 1 : DihedralGroup n) ^ k = r k := by
  induction' k with k IH
  · rw [Nat.cast_zero]
    rfl
  · rw [pow_succ, IH, r_mul_r]
    congr 1
    

Proof state:
case succ.e_a
n k : ℕ
IH : r 1 ^ k = r ↑k
⊢ 1 + ↑k = ↑(Nat.succ k)

Next tactic:
norm_cast
@[simp]
theorem r_one_pow (k : ℕ) : (r 1 : DihedralGroup n) ^ k = r k := by
  induction' k with k IH
  · rw [Nat.cast_zero]
    rfl
  · rw [pow_succ, IH, r_mul_r]
    congr 1
    norm_cast
    

Proof state:
case succ.e_a
n k : ℕ
IH : r 1 ^ k = r ↑k
⊢ ↑(1 + k) = ↑(Nat.succ k)

Next tactic:
rw [Nat.one_add]
theorem r_one_pow_n : r (1 : ZMod n) ^ n = 1 := by
  

Proof state:
n : ℕ
⊢ r 1 ^ n = 1

Next tactic:
rw [r_one_pow, one_def]
theorem r_one_pow_n : r (1 : ZMod n) ^ n = 1 := by
  rw [r_one_pow, one_def]
  

Proof state:
n : ℕ
⊢ r ↑n = r 0

Next tactic:
congr 1
theorem r_one_pow_n : r (1 : ZMod n) ^ n = 1 := by
  rw [r_one_pow, one_def]
  congr 1
  

Proof state:
case e_a
n : ℕ
⊢ ↑n = 0

Next tactic:
exact ZMod.nat_cast_self _
theorem sr_mul_self (i : ZMod n) : sr i * sr i = 1 := by 

Proof state:
n : ℕ
i : ZMod n
⊢ sr i * sr i = 1

Next tactic:
rw [sr_mul_sr, sub_self, one_def]
/-- If `0 < n`, then `sr i` has order 2.
-/
@[simp]
theorem orderOf_sr (i : ZMod n) : orderOf (sr i) = 2 := by
  

Proof state:
n : ℕ
i : ZMod n
⊢ orderOf (sr i) = 2

Next tactic:
apply orderOf_eq_prime
/-- If `0 < n`, then `sr i` has order 2.
-/
@[simp]
theorem orderOf_sr (i : ZMod n) : orderOf (sr i) = 2 := by
  apply orderOf_eq_prime
  · 

Proof state:
case hg
n : ℕ
i : ZMod n
⊢ sr i ^ 2 = 1

Next tactic:
rw [sq, sr_mul_self]
/-- If `0 < n`, then `sr i` has order 2.
-/
@[simp]
theorem orderOf_sr (i : ZMod n) : orderOf (sr i) = 2 := by
  apply orderOf_eq_prime
  · rw [sq, sr_mul_self]
  · -- Porting note: Previous proof was `decide`
    

Proof state:
case hg1
n : ℕ
i : ZMod n
⊢ sr i ≠ 1

Next tactic:
revert n
/-- If `0 < n`, then `sr i` has order 2.
-/
@[simp]
theorem orderOf_sr (i : ZMod n) : orderOf (sr i) = 2 := by
  apply orderOf_eq_prime
  · rw [sq, sr_mul_self]
  · -- Porting note: Previous proof was `decide`
    revert n
    

Proof state:
case hg1
⊢ ∀ {n : ℕ} (i : ZMod n), sr i ≠ 1

Next tactic:
simp_rw [one_def, ne_eq, forall_const, not_false_eq_true]
/-- If `0 < n`, then `r 1` has order `n`.
-/
@[simp]
theorem orderOf_r_one : orderOf (r 1 : DihedralGroup n) = n := by
  

Proof state:
n : ℕ
⊢ orderOf (r 1) = n

Next tactic:
rcases eq_zero_or_neZero n with (rfl | hn)
/-- If `0 < n`, then `r 1` has order `n`.
-/
@[simp]
theorem orderOf_r_one : orderOf (r 1 : DihedralGroup n) = n := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · 

Proof state:
case inl
⊢ orderOf (r 1) = 0

Next tactic:
rw [orderOf_eq_zero_iff']
/-- If `0 < n`, then `r 1` has order `n`.
-/
@[simp]
theorem orderOf_r_one : orderOf (r 1 : DihedralGroup n) = n := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · rw [orderOf_eq_zero_iff']
    

Proof state:
case inl
⊢ ∀ (n : ℕ), 0 < n → r 1 ^ n ≠ 1

Next tactic:
intro n hn
/-- If `0 < n`, then `r 1` has order `n`.
-/
@[simp]
theorem orderOf_r_one : orderOf (r 1 : DihedralGroup n) = n := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · rw [orderOf_eq_zero_iff']
    intro n hn
    

Proof state:
case inl
n : ℕ
hn : 0 < n
⊢ r 1 ^ n ≠ 1

Next tactic:
rw [r_one_pow, one_def]
/-- If `0 < n`, then `r 1` has order `n`.
-/
@[simp]
theorem orderOf_r_one : orderOf (r 1 : DihedralGroup n) = n := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · rw [orderOf_eq_zero_iff']
    intro n hn
    rw [r_one_pow, one_def]
    

Proof state:
case inl
n : ℕ
hn : 0 < n
⊢ r ↑n ≠ r 0

Next tactic:
apply mt r.inj
/-- If `0 < n`, then `r 1` has order `n`.
-/
@[simp]
theorem orderOf_r_one : orderOf (r 1 : DihedralGroup n) = n := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · rw [orderOf_eq_zero_iff']
    intro n hn
    rw [r_one_pow, one_def]
    apply mt r.inj
    

Proof state:
case inl
n : ℕ
hn : 0 < n
⊢ ¬↑n = 0

Next tactic:
simpa using hn.ne'
/-- If `0 < n`, then `r 1` has order `n`.
-/
@[simp]
theorem orderOf_r_one : orderOf (r 1 : DihedralGroup n) = n := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · rw [orderOf_eq_zero_iff']
    intro n hn
    rw [r_one_pow, one_def]
    apply mt r.inj
    simpa using hn.ne'
  · 

Proof state:
case inr
n : ℕ
hn : NeZero n
⊢ orderOf (r 1) = n

Next tactic:
apply (Nat.le_of_dvd (NeZero.pos n) <|
      orderOf_dvd_of_pow_eq_one <| @r_one_pow_n n).lt_or_eq.resolve_left
/-- If `0 < n`, then `r 1` has order `n`.
-/
@[simp]
theorem orderOf_r_one : orderOf (r 1 : DihedralGroup n) = n := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · rw [orderOf_eq_zero_iff']
    intro n hn
    rw [r_one_pow, one_def]
    apply mt r.inj
    simpa using hn.ne'
  · apply (Nat.le_of_dvd (NeZero.pos n) <|
      orderOf_dvd_of_pow_eq_one <| @r_one_pow_n n).lt_or_eq.resolve_left
    

Proof state:
case inr
n : ℕ
hn : NeZero n
⊢ ¬orderOf (r 1) < n

Next tactic:
intro h
/-- If `0 < n`, then `r 1` has order `n`.
-/
@[simp]
theorem orderOf_r_one : orderOf (r 1 : DihedralGroup n) = n := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · rw [orderOf_eq_zero_iff']
    intro n hn
    rw [r_one_pow, one_def]
    apply mt r.inj
    simpa using hn.ne'
  · apply (Nat.le_of_dvd (NeZero.pos n) <|
      orderOf_dvd_of_pow_eq_one <| @r_one_pow_n n).lt_or_eq.resolve_left
    intro h
    

Proof state:
case inr
n : ℕ
hn : NeZero n
h : orderOf (r 1) < n
⊢ False

Next tactic:
have h1 : (r 1 : DihedralGroup n) ^ orderOf (r 1) = 1 := pow_orderOf_eq_one _
/-- If `0 < n`, then `r 1` has order `n`.
-/
@[simp]
theorem orderOf_r_one : orderOf (r 1 : DihedralGroup n) = n := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · rw [orderOf_eq_zero_iff']
    intro n hn
    rw [r_one_pow, one_def]
    apply mt r.inj
    simpa using hn.ne'
  · apply (Nat.le_of_dvd (NeZero.pos n) <|
      orderOf_dvd_of_pow_eq_one <| @r_one_pow_n n).lt_or_eq.resolve_left
    intro h
    have h1 : (r 1 : DihedralGroup n) ^ orderOf (r 1) = 1 := pow_orderOf_eq_one _
    

Proof state:
case inr
n : ℕ
hn : NeZero n
h : orderOf (r 1) < n
h1 : r 1 ^ orderOf (r 1) = 1
⊢ False

Next tactic:
rw [r_one_pow] at h1
/-- If `0 < n`, then `r 1` has order `n`.
-/
@[simp]
theorem orderOf_r_one : orderOf (r 1 : DihedralGroup n) = n := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · rw [orderOf_eq_zero_iff']
    intro n hn
    rw [r_one_pow, one_def]
    apply mt r.inj
    simpa using hn.ne'
  · apply (Nat.le_of_dvd (NeZero.pos n) <|
      orderOf_dvd_of_pow_eq_one <| @r_one_pow_n n).lt_or_eq.resolve_left
    intro h
    have h1 : (r 1 : DihedralGroup n) ^ orderOf (r 1) = 1 := pow_orderOf_eq_one _
    rw [r_one_pow] at h1
    

Proof state:
case inr
n : ℕ
hn : NeZero n
h : orderOf (r 1) < n
h1 : r ↑(orderOf (r 1)) = 1
⊢ False

Next tactic:
injection h1 with h2
/-- If `0 < n`, then `r 1` has order `n`.
-/
@[simp]
theorem orderOf_r_one : orderOf (r 1 : DihedralGroup n) = n := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · rw [orderOf_eq_zero_iff']
    intro n hn
    rw [r_one_pow, one_def]
    apply mt r.inj
    simpa using hn.ne'
  · apply (Nat.le_of_dvd (NeZero.pos n) <|
      orderOf_dvd_of_pow_eq_one <| @r_one_pow_n n).lt_or_eq.resolve_left
    intro h
    have h1 : (r 1 : DihedralGroup n) ^ orderOf (r 1) = 1 := pow_orderOf_eq_one _
    rw [r_one_pow] at h1
    injection h1 with h2
    

Proof state:
case inr
n : ℕ
hn : NeZero n
h : orderOf (r 1) < n
h2 : ↑(orderOf (r 1)) = 0
⊢ False

Next tactic:
rw [← ZMod.val_eq_zero, ZMod.val_nat_cast, Nat.mod_eq_of_lt h] at h2
/-- If `0 < n`, then `r 1` has order `n`.
-/
@[simp]
theorem orderOf_r_one : orderOf (r 1 : DihedralGroup n) = n := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · rw [orderOf_eq_zero_iff']
    intro n hn
    rw [r_one_pow, one_def]
    apply mt r.inj
    simpa using hn.ne'
  · apply (Nat.le_of_dvd (NeZero.pos n) <|
      orderOf_dvd_of_pow_eq_one <| @r_one_pow_n n).lt_or_eq.resolve_left
    intro h
    have h1 : (r 1 : DihedralGroup n) ^ orderOf (r 1) = 1 := pow_orderOf_eq_one _
    rw [r_one_pow] at h1
    injection h1 with h2
    rw [← ZMod.val_eq_zero, ZMod.val_nat_cast, Nat.mod_eq_of_lt h] at h2
    

Proof state:
case inr
n : ℕ
hn : NeZero n
h : orderOf (r 1) < n
h2 : orderOf (r 1) = 0
⊢ False

Next tactic:
exact absurd h2.symm (orderOf_pos _).ne
/-- If `0 < n`, then `i : ZMod n` has order `n / gcd n i`.
-/
theorem orderOf_r [NeZero n] (i : ZMod n) : orderOf (r i) = n / Nat.gcd n i.val := by
  

Proof state:
n : ℕ
inst✝ : NeZero n
i : ZMod n
⊢ orderOf (r i) = n / Nat.gcd n (ZMod.val i)

Next tactic:
conv_lhs => rw [← ZMod.nat_cast_zmod_val i]
/-- If `0 < n`, then `i : ZMod n` has order `n / gcd n i`.
-/
theorem orderOf_r [NeZero n] (i : ZMod n) : orderOf (r i) = n / Nat.gcd n i.val := by
  conv_lhs => 

Proof state:
n : ℕ
inst✝ : NeZero n
i : ZMod n
| orderOf (r i)

Next tactic:
rw [← ZMod.nat_cast_zmod_val i]
/-- If `0 < n`, then `i : ZMod n` has order `n / gcd n i`.
-/
theorem orderOf_r [NeZero n] (i : ZMod n) : orderOf (r i) = n / Nat.gcd n i.val := by
  conv_lhs => rw [← ZMod.nat_cast_zmod_val i]
  

Proof state:
n : ℕ
inst✝ : NeZero n
i : ZMod n
⊢ orderOf (r ↑(ZMod.val i)) = n / Nat.gcd n (ZMod.val i)

Next tactic:
rw [← r_one_pow, orderOf_pow, orderOf_r_one]
theorem exponent : Monoid.exponent (DihedralGroup n) = lcm n 2 := by
  

Proof state:
n : ℕ
⊢ Monoid.exponent (DihedralGroup n) = lcm n 2

Next tactic:
rcases eq_zero_or_neZero n with (rfl | hn)
theorem exponent : Monoid.exponent (DihedralGroup n) = lcm n 2 := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · 

Proof state:
case inl
⊢ Monoid.exponent (DihedralGroup 0) = lcm 0 2

Next tactic:
exact Monoid.exponent_eq_zero_of_order_zero orderOf_r_one
theorem exponent : Monoid.exponent (DihedralGroup n) = lcm n 2 := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · exact Monoid.exponent_eq_zero_of_order_zero orderOf_r_one
  

Proof state:
case inr
n : ℕ
hn : NeZero n
⊢ Monoid.exponent (DihedralGroup n) = lcm n 2

Next tactic:
apply Nat.dvd_antisymm
theorem exponent : Monoid.exponent (DihedralGroup n) = lcm n 2 := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · exact Monoid.exponent_eq_zero_of_order_zero orderOf_r_one
  apply Nat.dvd_antisymm
  · 

Proof state:
case inr.a
n : ℕ
hn : NeZero n
⊢ Monoid.exponent (DihedralGroup n) ∣ lcm n 2

Next tactic:
apply Monoid.exponent_dvd_of_forall_pow_eq_one
theorem exponent : Monoid.exponent (DihedralGroup n) = lcm n 2 := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · exact Monoid.exponent_eq_zero_of_order_zero orderOf_r_one
  apply Nat.dvd_antisymm
  · apply Monoid.exponent_dvd_of_forall_pow_eq_one
    

Proof state:
case inr.a.hG
n : ℕ
hn : NeZero n
⊢ ∀ (g : DihedralGroup n), g ^ lcm n 2 = 1

Next tactic:
rintro (m | m)
theorem exponent : Monoid.exponent (DihedralGroup n) = lcm n 2 := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · exact Monoid.exponent_eq_zero_of_order_zero orderOf_r_one
  apply Nat.dvd_antisymm
  · apply Monoid.exponent_dvd_of_forall_pow_eq_one
    rintro (m | m)
    · 

Proof state:
case inr.a.hG.r
n : ℕ
hn : NeZero n
m : ZMod n
⊢ r m ^ lcm n 2 = 1

Next tactic:
rw [← orderOf_dvd_iff_pow_eq_one, orderOf_r]
theorem exponent : Monoid.exponent (DihedralGroup n) = lcm n 2 := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · exact Monoid.exponent_eq_zero_of_order_zero orderOf_r_one
  apply Nat.dvd_antisymm
  · apply Monoid.exponent_dvd_of_forall_pow_eq_one
    rintro (m | m)
    · rw [← orderOf_dvd_iff_pow_eq_one, orderOf_r]
      

Proof state:
case inr.a.hG.r
n : ℕ
hn : NeZero n
m : ZMod n
⊢ n / Nat.gcd n (ZMod.val m) ∣ lcm n 2

Next tactic:
refine' Nat.dvd_trans ⟨gcd n m.val, _⟩ (dvd_lcm_left n 2)
theorem exponent : Monoid.exponent (DihedralGroup n) = lcm n 2 := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · exact Monoid.exponent_eq_zero_of_order_zero orderOf_r_one
  apply Nat.dvd_antisymm
  · apply Monoid.exponent_dvd_of_forall_pow_eq_one
    rintro (m | m)
    · rw [← orderOf_dvd_iff_pow_eq_one, orderOf_r]
      refine' Nat.dvd_trans ⟨gcd n m.val, _⟩ (dvd_lcm_left n 2)
      · 

Proof state:
case inr.a.hG.r
n : ℕ
hn : NeZero n
m : ZMod n
⊢ n = n / Nat.gcd n (ZMod.val m) * gcd n (ZMod.val m)

Next tactic:
exact (Nat.div_mul_cancel (Nat.gcd_dvd_left n m.val)).symm
theorem exponent : Monoid.exponent (DihedralGroup n) = lcm n 2 := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · exact Monoid.exponent_eq_zero_of_order_zero orderOf_r_one
  apply Nat.dvd_antisymm
  · apply Monoid.exponent_dvd_of_forall_pow_eq_one
    rintro (m | m)
    · rw [← orderOf_dvd_iff_pow_eq_one, orderOf_r]
      refine' Nat.dvd_trans ⟨gcd n m.val, _⟩ (dvd_lcm_left n 2)
      · exact (Nat.div_mul_cancel (Nat.gcd_dvd_left n m.val)).symm
    · 

Proof state:
case inr.a.hG.sr
n : ℕ
hn : NeZero n
m : ZMod n
⊢ sr m ^ lcm n 2 = 1

Next tactic:
rw [← orderOf_dvd_iff_pow_eq_one, orderOf_sr]
theorem exponent : Monoid.exponent (DihedralGroup n) = lcm n 2 := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · exact Monoid.exponent_eq_zero_of_order_zero orderOf_r_one
  apply Nat.dvd_antisymm
  · apply Monoid.exponent_dvd_of_forall_pow_eq_one
    rintro (m | m)
    · rw [← orderOf_dvd_iff_pow_eq_one, orderOf_r]
      refine' Nat.dvd_trans ⟨gcd n m.val, _⟩ (dvd_lcm_left n 2)
      · exact (Nat.div_mul_cancel (Nat.gcd_dvd_left n m.val)).symm
    · rw [← orderOf_dvd_iff_pow_eq_one, orderOf_sr]
      

Proof state:
case inr.a.hG.sr
n : ℕ
hn : NeZero n
m : ZMod n
⊢ 2 ∣ lcm n 2

Next tactic:
exact dvd_lcm_right n 2
theorem exponent : Monoid.exponent (DihedralGroup n) = lcm n 2 := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · exact Monoid.exponent_eq_zero_of_order_zero orderOf_r_one
  apply Nat.dvd_antisymm
  · apply Monoid.exponent_dvd_of_forall_pow_eq_one
    rintro (m | m)
    · rw [← orderOf_dvd_iff_pow_eq_one, orderOf_r]
      refine' Nat.dvd_trans ⟨gcd n m.val, _⟩ (dvd_lcm_left n 2)
      · exact (Nat.div_mul_cancel (Nat.gcd_dvd_left n m.val)).symm
    · rw [← orderOf_dvd_iff_pow_eq_one, orderOf_sr]
      exact dvd_lcm_right n 2
  · 

Proof state:
case inr.a
n : ℕ
hn : NeZero n
⊢ lcm n 2 ∣ Monoid.exponent (DihedralGroup n)

Next tactic:
apply lcm_dvd
theorem exponent : Monoid.exponent (DihedralGroup n) = lcm n 2 := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · exact Monoid.exponent_eq_zero_of_order_zero orderOf_r_one
  apply Nat.dvd_antisymm
  · apply Monoid.exponent_dvd_of_forall_pow_eq_one
    rintro (m | m)
    · rw [← orderOf_dvd_iff_pow_eq_one, orderOf_r]
      refine' Nat.dvd_trans ⟨gcd n m.val, _⟩ (dvd_lcm_left n 2)
      · exact (Nat.div_mul_cancel (Nat.gcd_dvd_left n m.val)).symm
    · rw [← orderOf_dvd_iff_pow_eq_one, orderOf_sr]
      exact dvd_lcm_right n 2
  · apply lcm_dvd
    · 

Proof state:
case inr.a.hab
n : ℕ
hn : NeZero n
⊢ n ∣ Monoid.exponent (DihedralGroup n)

Next tactic:
convert Monoid.order_dvd_exponent (r (1 : ZMod n))
theorem exponent : Monoid.exponent (DihedralGroup n) = lcm n 2 := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · exact Monoid.exponent_eq_zero_of_order_zero orderOf_r_one
  apply Nat.dvd_antisymm
  · apply Monoid.exponent_dvd_of_forall_pow_eq_one
    rintro (m | m)
    · rw [← orderOf_dvd_iff_pow_eq_one, orderOf_r]
      refine' Nat.dvd_trans ⟨gcd n m.val, _⟩ (dvd_lcm_left n 2)
      · exact (Nat.div_mul_cancel (Nat.gcd_dvd_left n m.val)).symm
    · rw [← orderOf_dvd_iff_pow_eq_one, orderOf_sr]
      exact dvd_lcm_right n 2
  · apply lcm_dvd
    · convert Monoid.order_dvd_exponent (r (1 : ZMod n))
      

Proof state:
case h.e'_3
n : ℕ
hn : NeZero n
⊢ n = orderOf (r 1)

Next tactic:
exact orderOf_r_one.symm
theorem exponent : Monoid.exponent (DihedralGroup n) = lcm n 2 := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · exact Monoid.exponent_eq_zero_of_order_zero orderOf_r_one
  apply Nat.dvd_antisymm
  · apply Monoid.exponent_dvd_of_forall_pow_eq_one
    rintro (m | m)
    · rw [← orderOf_dvd_iff_pow_eq_one, orderOf_r]
      refine' Nat.dvd_trans ⟨gcd n m.val, _⟩ (dvd_lcm_left n 2)
      · exact (Nat.div_mul_cancel (Nat.gcd_dvd_left n m.val)).symm
    · rw [← orderOf_dvd_iff_pow_eq_one, orderOf_sr]
      exact dvd_lcm_right n 2
  · apply lcm_dvd
    · convert Monoid.order_dvd_exponent (r (1 : ZMod n))
      exact orderOf_r_one.symm
    · 

Proof state:
case inr.a.hcb
n : ℕ
hn : NeZero n
⊢ 2 ∣ Monoid.exponent (DihedralGroup n)

Next tactic:
convert Monoid.order_dvd_exponent (sr (0 : ZMod n))
theorem exponent : Monoid.exponent (DihedralGroup n) = lcm n 2 := by
  rcases eq_zero_or_neZero n with (rfl | hn)
  · exact Monoid.exponent_eq_zero_of_order_zero orderOf_r_one
  apply Nat.dvd_antisymm
  · apply Monoid.exponent_dvd_of_forall_pow_eq_one
    rintro (m | m)
    · rw [← orderOf_dvd_iff_pow_eq_one, orderOf_r]
      refine' Nat.dvd_trans ⟨gcd n m.val, _⟩ (dvd_lcm_left n 2)
      · exact (Nat.div_mul_cancel (Nat.gcd_dvd_left n m.val)).symm
    · rw [← orderOf_dvd_iff_pow_eq_one, orderOf_sr]
      exact dvd_lcm_right n 2
  · apply lcm_dvd
    · convert Monoid.order_dvd_exponent (r (1 : ZMod n))
      exact orderOf_r_one.symm
    · convert Monoid.order_dvd_exponent (sr (0 : ZMod n))
      

Proof state:
case h.e'_3
n : ℕ
hn : NeZero n
⊢ 2 = orderOf (sr 0)

Next tactic:
exact (orderOf_sr 0).symm