till Basics/Proof by Simplification
This commit is contained in:
parent
2fe3cc73eb
commit
2df3232863
1 changed files with 81 additions and 0 deletions
|
@ -152,5 +152,86 @@ end TuplePlayground
|
|||
--- Numbers
|
||||
namespace NatPlayground
|
||||
|
||||
#eval Nat.zero
|
||||
#eval Nat.zero.succ
|
||||
#eval Nat.zero.succ.succ
|
||||
example : Nat.zero.succ.succ = 2 := by rfl
|
||||
|
||||
end NatPlayground
|
||||
|
||||
open Nat in
|
||||
#check succ (succ (succ 0))
|
||||
|
||||
def minustwo (n : Nat) : Nat :=
|
||||
match n with
|
||||
| 0 => 0
|
||||
| .succ .zero => 0
|
||||
| .succ (.succ n') => n'
|
||||
|
||||
#eval minustwo 4
|
||||
|
||||
def even (n : Nat) : Bool :=
|
||||
match n with
|
||||
| .zero => true
|
||||
| .succ .zero => false
|
||||
| .succ (.succ n') => even n'
|
||||
|
||||
example : even 4 = true := by
|
||||
rfl
|
||||
example : even 51 = false := by
|
||||
rfl
|
||||
|
||||
namespace NatPlayground2
|
||||
|
||||
def plus (n : Nat) (m : Nat) : Nat :=
|
||||
match n with
|
||||
| .zero => m
|
||||
| .succ n' => .succ (plus n' m)
|
||||
|
||||
#eval plus 3 4
|
||||
|
||||
def mult (n m : Nat) : Nat :=
|
||||
match n with
|
||||
| .zero => .zero
|
||||
| .succ n' => plus m (mult n' m)
|
||||
|
||||
end NatPlayground2
|
||||
|
||||
namespace Exercise1
|
||||
|
||||
def factorial (n : Nat) : Nat :=
|
||||
match n with
|
||||
| 0 => 1
|
||||
| .succ n' => (n' + 1) * factorial n'
|
||||
|
||||
#eval factorial 3
|
||||
|
||||
example : factorial 3 = 6 := by
|
||||
rfl
|
||||
|
||||
example : factorial 5 = .mul 10 12 := by
|
||||
rfl
|
||||
|
||||
end Exercise1
|
||||
|
||||
#check LT.lt 1 2
|
||||
#check LT Nat
|
||||
#check (LT Nat)
|
||||
#check Nat.lt 1 2
|
||||
|
||||
namespace Exercise1
|
||||
|
||||
def ltb (n m : Nat) : Bool :=
|
||||
match n, m with
|
||||
| 0, _ => true
|
||||
| _, 0 => false
|
||||
| .succ n', .succ m' => ltb n' m'
|
||||
|
||||
#eval ltb 1 2
|
||||
#eval ltb 10242 1055090
|
||||
example : (ltb 1 2) = true := by rfl
|
||||
|
||||
end Exercise1
|
||||
|
||||
--- Proof by Simplification
|
||||
|
||||
|
|
Loading…
Reference in a new issue