Files
NNG/Game/MyNat/Definition.lean

42 lines
1005 B
Lean4
Raw Normal View History

import Game.Tactic.LabelAttr -- MyNat_decide attribute
2023-08-04 01:49:06 +01:00
/-- Our copy of the natural numbers called `MyNat`, with notation ``. -/
2023-04-25 18:37:27 +02:00
inductive MyNat where
| zero : MyNat
| succ : MyNat MyNat
-- deriving BEq, DecidableEq, Inhabited
attribute [pp_nodot] MyNat.succ
2023-04-25 18:37:27 +02:00
@[inherit_doc]
2023-08-04 17:14:49 +02:00
notation (name := MyNatNotation) (priority := 1000000) "" => MyNat
2023-04-25 18:37:27 +02:00
-- Note: as long as we do not import `Mathlib.Init.Data.Nat.Notation` this is fine.
namespace MyNat
instance : Inhabited MyNat where
default := MyNat.zero
@[MyNat_decide]
def ofNat (x : Nat) : MyNat :=
2023-04-25 18:37:27 +02:00
match x with
| Nat.zero => MyNat.zero
| Nat.succ b => MyNat.succ (ofNat b)
2023-04-25 18:37:27 +02:00
@[MyNat_decide]
def toNat (x : MyNat) : Nat :=
2023-04-25 18:37:27 +02:00
match x with
| MyNat.zero => Nat.zero
| MyNat.succ b => Nat.succ (toNat b)
2023-04-25 18:37:27 +02:00
instance instofNat {n : Nat} : OfNat MyNat n where
ofNat := ofNat n
2023-04-25 18:37:27 +02:00
instance : ToString MyNat where
toString p := toString (toNat p)
2023-04-25 18:37:27 +02:00
@[MyNat_decide]
2023-04-25 18:37:27 +02:00
theorem zero_eq_0 : MyNat.zero = 0 := rfl
def one : MyNat := MyNat.succ 0