Skip to content

Commit c75b654

Browse files
committed
Add PowGroup
1 parent 568f463 commit c75b654

10 files changed

Lines changed: 306 additions & 87 deletions

File tree

Game/Levels/PowGroup.lean

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import Game.Levels.PowGroup.L01_PowNegNat
2+
import Game.Levels.PowGroup.L02_PowNegOne
3+
import Game.Levels.PowGroup.L03_PowSucc
4+
import Game.Levels.PowGroup.L04_PowPred
5+
import Game.Levels.PowGroup.L05_PowAdd
6+
import Game.Levels.PowGroup.L06_PowNeg
7+
import Game.Levels.PowGroup.L07_PowSub
8+
import Game.Levels.PowGroup.L08_PowMul
9+
10+
11+
12+
World "Group Power"
13+
Title "Group Power World"
14+
15+
Introduction "
16+
A group consists of a set G together with a binary operation (`*`) we represent repeatedly multiplying an element by itself using `gpow`:
17+
18+
```
19+
def gpow {G : Type} [Group G] (x : G) : ℤ → G
20+
| Int.ofNat n => mpow x n
21+
| Int.negSucc n => mpow (x⁻¹) (n+1)
22+
```
23+
To make it easier to work with, we've created the following lemmas:
24+
- `gpow_ofNat`: `g ^ ↑n = g ^ n`
25+
- `gpow_negSucc`: `g ^ (Int.negSucc n) = (g⁻¹) ^ (n+1)`
26+
- `gpow_zero`: `g ^ (0 : ℤ) = 1`
27+
- `gpow_one`: `g ^ (1 : ℤ) = g`
28+
- `inv_mpow`: `(g ^ n)⁻¹ = (g⁻¹) ^ n`
29+
30+
They've also been added to `simp`
31+
"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import Game.Levels.Group
2+
import Game.Levels.PowMonoid
3+
import Game.MyAlgebra.PowGroup
4+
5+
World "Group Power"
6+
Level 1
7+
8+
Title "Negative Natural Exponent"
9+
10+
namespace MyAlgebra
11+
12+
Introduction "We now move to powers with integer exponents.
13+
In this level, you’ll show that `g ^ (-(n : ℤ))` is the inverse of `g ^ n`."
14+
15+
/--
16+
For a group element `g` and a natural number `n`, we have
17+
`g ^ (-(n : ℤ)) = (g ^ n)⁻¹`.
18+
-/
19+
TheoremDoc MyAlgebra.gpow_neg_mpow as "gpow_neg_mpow" in "Group Power"
20+
Statement gpow_neg_mpow {G} [Group G] (g : G) (x : ℕ) :
21+
g ^ (-(x : ℤ)) = (g ^ x)⁻¹ := by
22+
Hint "Do a case split on `n` using `cases n with | zero | succ`."
23+
cases x with
24+
| zero =>
25+
rw [Int.ofNat_zero]
26+
rw [Int.neg_zero]
27+
rw [gpow_zero g]
28+
rw [inv_id]
29+
rfl
30+
| succ x =>
31+
have h: -↑(x + 1) = Int.negSucc x := rfl
32+
rw [h]
33+
rw [gpow_negSucc]
34+
simp [inv_mpow, mpow_add, ← inv_anticomm, mpow_one, mpow_comm_mul]
35+
36+
Conclusion "Great! You’ve connected negative integer exponents with inverses of natural powers."
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Game.Levels.PowGroup.L01_PowNegNat
2+
3+
World "Group Power"
4+
Level 2
5+
6+
Title "The Inverse: g⁻¹ = g^(-1)"
7+
8+
namespace MyAlgebra
9+
10+
Introduction "Here you show that exponent `-1` gives the group inverse."
11+
12+
/--
13+
For any group element `g`, we have `g ^ (-1) = g⁻¹`.
14+
-/
15+
TheoremDoc MyAlgebra.gpow_neg_one as "gpow_neg_one" in "Group Power"
16+
Statement gpow_neg_one {G} [Group G] (g : G) :
17+
g ^ (-1) = g⁻¹ := by
18+
Hint "Write `-1` as `-(1 : ℤ)` and then use the previous level."
19+
have : (1 : ℤ) = (1 : ℕ) := rfl
20+
-- or simply: `rw [← Int.ofNat_one]`
21+
rw [← Int.ofNat_one, gpow_neg_mpow]
22+
simp [mpow_one]
23+
24+
Conclusion "Now you see that the usual inverse `g⁻¹` is just `g` raised to `-1`."
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import Game.Levels.PowGroup.L02_PowNegOne
2+
3+
World "Group Power"
4+
Level 3
5+
6+
Title "Adding 1 to an Integer Exponent"
7+
8+
namespace MyAlgebra
9+
10+
Introduction "Next, you will show a recursive formula for integer exponents:
11+
`g ^ (n + 1) = g ^ n * g`."
12+
13+
/--
14+
For any group element `g` and integer `x`,
15+
`g ^ (x + 1) = (g ^ x) * g`.
16+
-/
17+
TheoremDoc MyAlgebra.gpow_succ as "gpow_succ" in "Group Power"
18+
Statement gpow_succ {G} [Group G] (g : G) (x : ℤ) :
19+
g ^ (x + 1) = (g ^ x) * g := by
20+
Hint "Use `Int.induction_on` on `x`."
21+
induction x using Int.induction_on with
22+
| hz =>
23+
simp
24+
| hp x ih =>
25+
Hint "In the nonnegative case, reduce to the natural power `mpow`."
26+
repeat rw [←Int.ofNat_one]
27+
repeat rw [Int.ofNat_add_out]
28+
repeat rw [gpow_ofNat]
29+
rfl
30+
| hn x ih =>
31+
Hint "In the negative case, use `gpow_negSucc`, `mpow_succ_right`, and cancellation."
32+
rw [←Int.negSucc_coe', gpow_negSucc, mpow_succ_right, mul_assoc, inv_mul, mul_one]
33+
rw [Int.negSucc_eq, Int.neg_add, Int.neg_add_cancel_right, gpow_neg_mpow]
34+
exact inv_mpow g x
35+
36+
37+
Conclusion "Good! You now have a recursive rule for integer exponents too."
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import Game.Levels.PowGroup.L03_PowSucc
2+
3+
World "Group Power"
4+
Level 4
5+
6+
Title "Subtracting 1 from an Integer Exponent"
7+
8+
namespace MyAlgebra
9+
10+
Introduction "Dually to `g^(n+1)`, we can describe `g^(n-1)` by multiplying with `g⁻¹` on the right."
11+
12+
/--
13+
For any group element `g` and integer `x`,
14+
`(g ^ x) * g⁻¹ = g ^ (x - 1)`.
15+
-/
16+
TheoremDoc MyAlgebra.gpow_pred as "gpow_pred" in "Group Power"
17+
Statement gpow_pred {G} [Group G] (g : G) (x : ℤ) :
18+
(g ^ x) * g⁻¹ = g ^ (x - 1) := by
19+
Hint "You can proceed by cases on `x` (nonnegative / negative) as in the definition of `gpow`."
20+
induction x with
21+
| ofNat x =>
22+
simp only [Int.ofNat_eq_coe]
23+
cases x with
24+
| zero =>
25+
rw [Int.ofNat_zero, gpow_zero]
26+
rw [one_mul, Int.zero_sub, gpow_neg_one]
27+
| succ x =>
28+
simp [gpow, Nat.cast_add, Nat.cast_one]
29+
rw [gpow_succ, mul_assoc, mul_inv, mul_one]
30+
| negSucc x =>
31+
rw [Int.negSucc_sub_one, gpow_negSucc, gpow_negSucc]
32+
repeat rw [mpow_succ_right]
33+
34+
Conclusion "Great! You can move down in the exponent by multiplying on the right with `g⁻¹`."
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import Game.Levels.PowGroup.L04_PowPred
2+
3+
World "Group Power"
4+
Level 5
5+
6+
Title "Adding Integer Exponents"
7+
8+
namespace MyAlgebra
9+
10+
Introduction "Now you’ll prove the group version of the exponent-addition law:
11+
`g ^ x * g ^ y = g ^ (x + y)` for all integers `x`, `y`."
12+
13+
/--
14+
For any group element `g` and integers `x`, `y`,
15+
`g ^ x * g ^ y = g ^ (x + y)`.
16+
-/
17+
TheoremDoc MyAlgebra.gpow_add as "gpow_add" in "Group Power"
18+
Statement gpow_add {G} [Group G] (g : G) (x y : ℤ) :
19+
(g ^ x) * (g ^ y) = g ^ (x + y) := by
20+
Hint "Use `Int.induction_on` on `y`."
21+
induction y using Int.induction_on with
22+
| hz =>
23+
-- y = 0
24+
simp
25+
| hp y ih =>
26+
Hint "Use the recursive formula `gpow_succ` and associativity."
27+
simp [← Int.add_assoc, gpow_succ, ← ih, mul_assoc]
28+
| hn y ih =>
29+
Hint "Use `gpow_pred` for the negative step."
30+
rw [← gpow_pred]
31+
rw [← mul_assoc]
32+
rw [ih]
33+
rw [gpow_pred]
34+
rw [Int.add_sub_assoc]
35+
36+
Conclusion "Excellent! You have generalized the exponent addition law to all integers."
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import Game.Levels.PowGroup.L05_PowAdd
2+
3+
World "Group Power"
4+
Level 6
5+
6+
Title "Negating the Exponent"
7+
8+
namespace MyAlgebra
9+
10+
Introduction "You’ve seen that negative naturals correspond to inverses.
11+
Now you’ll prove the full statement: `g ^ (-n) = (g ^ n)⁻¹` for any integer `n`."
12+
13+
/--
14+
For any group element `g` and integer `n`,
15+
`g ^ (-n) = (g ^ n)⁻¹`.
16+
-/
17+
TheoremDoc MyAlgebra.gpow_neg as "gpow_neg" in "Group Power"
18+
Statement gpow_neg {G} [Group G] (g : G) (n : ℤ) :
19+
g ^ (-n) = (g ^ n)⁻¹ := by
20+
Hint "Use `Int.induction_on` on `n`."
21+
induction n using Int.induction_on with
22+
| hz =>
23+
-- n = 0
24+
simp [gpow_zero, ←inv_id]
25+
| hp n ih =>
26+
Hint "Relate `-(n+1)` to `-n - 1` and use `gpow_pred`."
27+
rw [Int.neg_add, ←Int.sub_eq_add_neg, ←gpow_pred, ih, inv_anticomm, ←Int.add_comm]
28+
rw [←gpow_add]
29+
rw [gpow_one]
30+
| hn n ih =>
31+
Hint "Use the case for a natural number via `gpow_neg_mpow` and your previous lemma."
32+
simp at *
33+
rw [Int.add_comm, gpow_succ, ih, ←gpow_pred, gpow_neg_mpow, inv_anticomm]
34+
repeat rw [← inv_inv]
35+
rw [← mpow_succ_right, mpow_succ_left]
36+
37+
Conclusion "Nice! You’ve fully connected negative integer exponents with group inverses."
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Game.Levels.PowGroup.L06_PowNeg
2+
3+
World "Group Power"
4+
Level 7
5+
6+
Title "Subtracting Integer Exponents"
7+
8+
namespace MyAlgebra
9+
10+
Introduction "We now prove the exponent law for subtraction:
11+
multiplying by the inverse of `g ^ y` corresponds to subtracting `y` in the exponent."
12+
13+
/--
14+
For any group element `g` and integers `x`, `y`, we have
15+
`g ^ x * (g ^ y)⁻¹ = g ^ (x - y)`.
16+
-/
17+
TheoremDoc MyAlgebra.gpow_sub as "gpow_sub" in "Group Power"
18+
@[simp]
19+
Statement gpow_sub {G} [Group G] (g : G) (x y : ℤ) :
20+
(g ^ x) * (g ^ y)⁻¹ = g ^ (x - y) := by
21+
Hint "Recall that `x - y = x + (-y)`."
22+
Hint "Try rewriting `x - y` using `sub_eq_add_neg` and then apply the addition rule `gpow_add` and the negation rule `gpow_neg`."
23+
-- First rewrite subtraction as addition with a negative exponent:
24+
rw [sub_eq_add_neg]
25+
-- Now use the addition and negation lemmas:
26+
rw [← gpow_add]
27+
rw [gpow_neg]
28+
29+
Conclusion "Nice! You’ve shown that a negative exponent in the second factor corresponds to subtracting exponents."
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import Game.Levels.PowGroup.L07_PowSub
2+
3+
World "Group Power"
4+
Level 8
5+
6+
Title "Multiplying Integer Exponents"
7+
8+
namespace MyAlgebra
9+
10+
Introduction "Finally, we prove the multiplication law for integer exponents:
11+
`g ^ (x * y) = (g ^ x) ^ y`."
12+
13+
/--
14+
For any group element `g` and integers `x`, `y`,
15+
we have `g ^ (x * y) = (g ^ x) ^ y`.
16+
-/
17+
TheoremDoc MyAlgebra.gpow_mul as "gpow_mul" in "Group Power"
18+
Statement gpow_mul {G} [Group G] (g : G) (x y : ℤ) :
19+
g ^ (x * y) = (g ^ x) ^ y := by
20+
Hint "Use `Int.induction_on` on `y` as in earlier levels."
21+
induction y using Int.induction_on with
22+
| hz =>
23+
Hint "Start with `y = 0`."
24+
-- x * 0 = 0, and (g^x)^0 = 1
25+
simp
26+
| hp n ih =>
27+
Hint "Use the identity `x * (n+1) = x * n + x` and the addition lemma for powers."
28+
-- y = n+1
29+
-- g^(x*(n+1)) = g^(x*n + x) = g^(x*n) * g^x
30+
-- (g^x)^(n+1) = (g^x)^n * g^x
31+
rw [mul_add, mul_one, ←gpow_add, gpow_succ, ih]
32+
| hn n ih =>
33+
Hint "For the negative step, use `Int.mul_sub` and your subtraction lemma `gpow_sub`."
34+
-- y = -[n+1]
35+
-- x * (-(n+1)) = x * (-n) - x
36+
-- use `gpow_sub` and `gpow_pred` to step down
37+
rw [Int.mul_sub, mul_one, ←gpow_sub, ←gpow_pred, ih]
38+
39+
Conclusion "Excellent! You’ve proved the full multiplication law for integer exponents."

0 commit comments

Comments
 (0)