Inverts an {name}LE instance.
The result is an {lean}LE α instance where {lit}a ≤ b holds when {name}le would have
{lit}b ≤ a hold.
If {name}le obeys laws, then {lean}le.opposite obeys the opposite laws. For example, if
{name}le encodes a linear order, then {lean}le.opposite also encodes a linear order.
To automatically derive these laws, use {lit}open Std.OppositeOrderInstances.
For example, {name}LE.opposite can be used to derive maximum operations from minimum operations,
since finding the minimum in the opposite order is the same as finding the maximum in the original order:
def min' [LE α] [DecidableLE α] (a b : α) : α :=
if a ≤ b then a else b
open scoped Std.OppositeOrderInstances in
def max' [LE α] [DecidableLE α] (a b : α) : α :=
letI : LE α := (inferInstanceAs (LE α)).opposite
-- `DecidableLE` for the opposite order is derived automatically via `OppositeOrderInstances`
min' a b
Without the open scoped command, Lean would not find the required {lit}DecidableLE α
instance for the opposite order.
Instances For
Inverts an {name}LT instance.
The result is an {lean}LT α instance where {lit}a < b holds when {name}lt would have
{lit}b < a hold.
If {name}lt obeys laws, then {lean}lt.opposite obeys the opposite laws.
To automatically derive these laws, use {lit}open scoped Std.OppositeOrderInstances.
For example, one can use the derived instances to prove properties about the opposite {name}LT
instance:
open scoped Std.OppositeOrderInstances in
example [LE α] [LT α] [Std.LawfulOrderLT α] [Std.IsLinearOrder α] {x y : α} :
letI : LE α := LE.opposite inferInstance
letI : LT α := LT.opposite inferInstance
¬ y ≤ x ↔ x < y :=
letI : LE α := LE.opposite inferInstance
letI : LT α := LT.opposite inferInstance
Std.not_le
Without the open scoped command, Lean would not find the {lit}LawfulOrderLT α
and {lit}IsLinearOrder α instances for the opposite order that are required by {name}not_le.
Instances For
Creates a {name}Max instance from a {name}Min instance.
The result is a {lean}Max α instance that uses {lean}min.min as its {name}max operation.
If {name}min obeys laws, then {lean}min.oppositeMax obeys the corresponding laws for {name}Max.
To automatically derive these laws, use {lit}open scoped Std.OppositeOrderInstances.
For example, one can use the derived instances to prove properties about the opposite {name}Max
instance:
open scoped Std.OppositeOrderInstances in
example [LE α] [DecidableLE α] [Min α] [Std.LawfulOrderLeftLeaningMin α] {a b : α} :
letI : LE α := LE.opposite inferInstance
letI : Max α := (inferInstance : Min α).oppositeMax
max a b = if b ≤ a then a else b :=
letI : LE α := LE.opposite inferInstance
letI : Max α := (inferInstance : Min α).oppositeMax
Std.max_eq_if
Without the open scoped command, Lean would not find the {lit}LawfulOrderLeftLeaningMax α
instance for the opposite order that is required by {name}max_eq_if.
Equations
- min.oppositeMax = { max := fun (a b : α) => Min.min a b }
Instances For
Creates a {name}Min instance from a {name}Max instance.
The result is a {lean}Min α instance that uses {lean}max.max as its {name}min operation.
If {name}max obeys laws, then {lean}max.oppositeMin obeys the corresponding laws for {name}Min.
To automatically derive these laws, use {lit}open scoped Std.OppositeOrderInstances.
For example, one can use the derived instances to prove properties about the opposite {name}Min
instance:
open scoped Std.OppositeOrderInstances in
example [LE α] [DecidableLE α] [Max α] [Std.LawfulOrderLeftLeaningMax α] {a b : α} :
letI : LE α := LE.opposite inferInstance
letI : Min α := (inferInstance : Max α).oppositeMin
min a b = if a ≤ b then a else b :=
letI : LE α := LE.opposite inferInstance
letI : Min α := (inferInstance : Max α).oppositeMin
Std.min_eq_if
Without the open scoped command, Lean would not find the {lit}LawfulOrderLeftLeaningMin α
instance for the opposite order that is required by {name}min_eq_if.
Equations
- max.oppositeMin = { min := fun (a b : α) => Max.max a b }