lean4-htt/library/init/data/ordering/basic.lean
Leonardo de Moura 6841e47aa4 chore(frontends/lean/builtin_exprs): remove support for (<infix>) and (<infix> <expr>) notations
In Lean 4, we will support the more general

`a + ·` ==> `fun x, a + x`
`· + b` ==> `fun x, x + b`
`· + ·` ==> `fun x y, x + y`
`f · y` ==> `fun x, f a y`
`g · · b` ==> `fun x y, g x y b`
2019-07-02 08:06:06 -07:00

59 lines
1.6 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.data.repr
universes u v
inductive Ordering
| lt | Eq | gt
instance : HasRepr Ordering :=
⟨(λ s, match s with | Ordering.lt := "lt" | Ordering.Eq := "Eq" | Ordering.gt := "gt")⟩
namespace Ordering
def swap : Ordering → Ordering
| lt := gt
| Eq := Eq
| gt := lt
@[inline] def orElse : Ordering → Ordering → Ordering
| lt _ := lt
| Eq o := o
| gt _ := gt
theorem swapSwap : ∀ (o : Ordering), o.swap.swap = o
| lt := rfl
| Eq := rfl
| gt := rfl
end Ordering
@[inline] def cmpUsing {α : Type u} (lt : αα → Prop) [DecidableRel lt] (a b : α) : Ordering :=
if lt a b then Ordering.lt
else if lt b a then Ordering.gt
else Ordering.Eq
def cmp {α : Type u} [HasLess α] [DecidableRel (HasLess.Less : αα → Prop)] (a b : α) : Ordering :=
cmpUsing HasLess.Less a b
instance : DecidableEq Ordering :=
{decEq := λ a b,
match a with
| Ordering.lt :=
match b with
| Ordering.lt := isTrue rfl
| Ordering.Eq := isFalse (λ h, Ordering.noConfusion h)
| Ordering.gt := isFalse (λ h, Ordering.noConfusion h)
| Ordering.Eq :=
match b with
| Ordering.lt := isFalse (λ h, Ordering.noConfusion h)
| Ordering.Eq := isTrue rfl
| Ordering.gt := isFalse (λ h, Ordering.noConfusion h)
| Ordering.gt :=
match b with
| Ordering.lt := isFalse (λ h, Ordering.noConfusion h)
| Ordering.Eq := isFalse (λ h, Ordering.noConfusion h)
| Ordering.gt := isTrue rfl}