-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a version of freshman's dream with a sensible def of pow
- Loading branch information
1 parent
2c67b4f
commit 3b1178e
Showing
2 changed files
with
64 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import Egg | ||
|
||
class Inv (α) where inv : α → α | ||
postfix:max "⁻¹" => Inv.inv | ||
|
||
class Zero (α) where zero : α | ||
instance [Zero α] : OfNat α 0 where ofNat := Zero.zero | ||
|
||
class One (α) where one : α | ||
instance [One α] : OfNat α 1 where ofNat := One.one | ||
|
||
class Ring (α) extends Zero α, One α, Add α, Sub α, Mul α, Div α, Pow α Nat, Inv α, Neg α where | ||
comm_add (a b : α) : a + b = b + a | ||
comm_mul (a b : α) : a * b = b * a | ||
add_assoc (a b c : α) : a + (b + c) = (a + b) + c | ||
mul_assoc (a b c : α) : a * (b * c) = (a * b) * c | ||
sub_canon (a b : α) : a - b = a + -b | ||
neg_add (a : α) : a + -a = 0 | ||
div_canon (a b : α) : a / b = a * b⁻¹ | ||
zero_add (a : α) : a + 0 = a | ||
zero_mul (a : α) : a * 0 = 0 | ||
one_mul (a : α) : a * 1 = a | ||
distrib (a b c : α) : a * (b + c) = (a * b) + (a * c) | ||
pow_zero (a : α) : a ^ 0 = 1 | ||
pow_succ (a : α) : a ^ (n + 1) = a * (a ^ n) | ||
|
||
class CharTwoRing (α) extends Ring α where | ||
char_two (a : α) : a + a = 0 | ||
|
||
open Ring CharTwoRing Egg.Guides Egg.Config.Modifier in | ||
macro "char_two_ring" mod:egg_cfg_mod base:(egg_base)? guides:(egg_guides)? : tactic => `(tactic| | ||
egg $mod [comm_add, comm_mul, add_assoc, mul_assoc, sub_canon, neg_add, div_canon, zero_add, | ||
zero_mul, one_mul, distrib, pow_zero, pow_succ, char_two, Nat.succ_eq_add_one] $[$base]? $[$guides]? | ||
) | ||
|
||
variable [CharTwoRing α] (x y : α) | ||
|
||
theorem freshmans_dream₂ : (x + y) ^ 2 = x ^ 2 + y ^ 2 := by | ||
calc (x + y) ^ 2 | ||
_ = (x + y) * (x + y) := by char_two_ring | ||
_ = x * (x + y) + y * (x + y) := by char_two_ring | ||
-- _ = x ^ 2 + x * y + y * x + y ^ 2 | ||
_ = x ^ 2 + y ^ 2 := by char_two_ring | ||
|
||
theorem freshmans_dream₂': (x + y) ^ 2 = x ^ 2 + y ^ 2 := by | ||
char_two_ring | ||
|
||
theorem freshmans_dream₃ : (x + y) ^ 3 = x ^ 3 + x * y ^ 2 + x ^ 2 * y + y ^ 3 := by | ||
calc (x + y) ^ 3 | ||
_ = (x + y) * (x + y) * (x + y) := by char_two_ring | ||
_ = (x + y) * (x * (x + y) + y * (x + y)) := by char_two_ring | ||
-- _ = (x + y) * (x ^ 2 + x * y + y * x + y ^ 2) | ||
_ = (x + y) * (x ^ 2 + y ^ 2) := by char_two_ring | ||
_ = x * (x ^ 2 + y ^ 2) + y * (x ^ 2 + y ^ 2) := by char_two_ring | ||
_ = (x * x ^ 2) + x * y ^ 2 + y * x ^ 2 + y * y ^ 2 := by char_two_ring | ||
_ = x ^ 3 + x * y ^ 2 + x ^ 2 * y + y ^ 3 := by char_two_ring | ||
|
||
theorem freshmans_dream₃' : (x + y) ^ 3 = x ^ 3 + x * y ^ 2 + x ^ 2 * y + y ^ 3 := by | ||
char_two_ring using (x + y) * (x + y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters