test: Sign

This commit is contained in:
Leonardo de Moura 2022-03-30 13:33:29 -07:00
parent 1a8840330f
commit a509b0c615

50
tests/lean/run/sign.lean Normal file
View file

@ -0,0 +1,50 @@
inductive Sign where
| zero | neg | pos
deriving DecidableEq
instance : OfNat Sign (nat_lit 0) where
ofNat := .zero
instance : OfNat Sign (nat_lit 1) where
ofNat := .pos
instance : Neg Sign where
neg | .zero => .zero
| .pos => .neg
| .neg => .pos
namespace Sign
@[simp] theorem zero_eq : zero = 0 := rfl
@[simp] theorem neg_eq : neg = -1 := rfl
@[simp] theorem pos_eq : pos = 1 := rfl
def mul : Sign → Sign → Sign
| neg, neg => pos
| neg, pos => neg
| neg, zero => zero
| zero, _ => zero
| pos, s => s
instance : Mul Sign where
mul a b := Sign.mul a b
def le : Sign → Sign → Bool
| neg, _ => true
| zero, zero => true
| _, pos => true
| _, _ => false
instance : LE Sign where
le a b := Sign.le a b
instance : DecidableRel (· ≤ · : Sign → Sign → Prop) :=
fun a b => inferInstanceAs (Decidable (le a b = true))
theorem neg_bot {s : Sign} : s ≤ -1 → s = -1 := by
cases s <;> decide
theorem pos_top {s : Sign} : 1 ≤ s → s = 1 := by
cases s <;> decide
end Sign