Created
March 25, 2025 16:37
-
-
Save lovely-error/e45933e8dd0f35f98074dc5591e21f67 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
inductive NatNum : Type | zero | succ (n:NatNum) | |
def add (a b:NatNum): NatNum := | |
match a with | .zero => b | .succ n => .succ (add n b) | |
#eval (add (.succ (.succ .zero)) (.succ (.succ .zero))) | |
#check add.induct | |
def add_2 (a b:NatNum): NatNum := | |
match b with | .zero => a | .succ n => .succ (add n a) | |
def is : add n k.succ = .succ (add n k) := by | |
induction n | |
repeat rw [add.eq_1] | |
case _ i h => | |
repeat rw [add.eq_2] | |
apply congrArg | |
rw [h] | |
def add_comm : add a b = add b a := by | |
refine add.induct (fun i1 i2 => add i1 i2 = add i2 i1) ?_ ?_ a b | |
{ | |
intro i | |
rewrite [add.eq_1] | |
induction i | |
rewrite [add.eq_1] | |
rfl | |
case _ i => | |
rw [add.eq_2] | |
apply congrArg | |
exact i | |
} | |
{ | |
intro n k h | |
rw [add.eq_2] | |
rw [h] | |
rw [is] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment