natural-arithmetic-0.2.1.0: Arithmetic of natural numbers
Safe HaskellSafe-Inferred
LanguageHaskell2010

Arithmetic.Lt

Synopsis

Special Inequalities

zero :: 0 < 1 Source #

Zero is less than one.

zero# :: (# #) -> 0 <# 1 Source #

Substitution

substituteL :: (b :=: c) -> (b < a) -> c < a Source #

Replace the left-hand side of a strict inequality with an equal number.

substituteR :: (b :=: c) -> (a < b) -> a < c Source #

Replace the right-hand side of a strict inequality with an equal number.

Increment

incrementL :: forall (c :: Nat) (a :: Nat) (b :: Nat). (a < b) -> (c + a) < (c + b) Source #

Add a constant to the left-hand side of both sides of the strict inequality.

incrementL# :: forall (c :: Nat) (a :: Nat) (b :: Nat). (a <# b) -> (c + a) <# (c + b) Source #

incrementR :: forall (c :: Nat) (a :: Nat) (b :: Nat). (a < b) -> (a + c) < (b + c) Source #

Add a constant to the right-hand side of both sides of the strict inequality.

incrementR# :: forall (c :: Nat) (a :: Nat) (b :: Nat). (a <# b) -> (a + c) <# (b + c) Source #

Decrement

decrementL :: forall (c :: Nat) (a :: Nat) (b :: Nat). ((c + a) < (c + b)) -> a < b Source #

Subtract a constant from the left-hand side of both sides of the inequality. This is the opposite of incrementL.

decrementL# :: forall (c :: Nat) (a :: Nat) (b :: Nat). ((c + a) <# (c + b)) -> a <# b Source #

decrementR :: forall (c :: Nat) (a :: Nat) (b :: Nat). ((a + c) < (b + c)) -> a < b Source #

Subtract a constant from the right-hand side of both sides of the inequality. This is the opposite of incrementR.

decrementR# :: forall (c :: Nat) (a :: Nat) (b :: Nat). ((a + c) <# (b + c)) -> a <# b Source #

Weaken

weakenL :: forall (c :: Nat) (a :: Nat) (b :: Nat). (a < b) -> a < (c + b) Source #

Add a constant to the left-hand side of the right-hand side of the strict inequality.

weakenL# :: forall (c :: Nat) (a :: Nat) (b :: Nat). (a <# b) -> a <# (c + b) Source #

weakenR :: forall (c :: Nat) (a :: Nat) (b :: Nat). (a < b) -> a < (b + c) Source #

Add a constant to the right-hand side of the right-hand side of the strict inequality.

weakenR# :: forall (c :: Nat) (a :: Nat) (b :: Nat). (a <# b) -> a <# (b + c) Source #

weakenLhsL# :: forall (c :: Nat) (a :: Nat) (b :: Nat). ((c + a) <# b) -> a <# b Source #

weakenLhsR# :: forall (c :: Nat) (a :: Nat) (b :: Nat). ((a + c) <# b) -> a <# b Source #

Composition

plus :: (a < b) -> (c <= d) -> (a + c) < (b + d) Source #

Add a strict inequality to a nonstrict inequality.

plus# :: (a <# b) -> (c <=# d) -> (a + c) <# (b + d) Source #

transitive :: (a < b) -> (b < c) -> a < c Source #

Compose two strict inequalities using transitivity.

transitive# :: (a <# b) -> (b <# c) -> a <# c Source #

transitiveNonstrictL :: (a <= b) -> (b < c) -> a < c Source #

transitiveNonstrictL# :: (a <=# b) -> (b <# c) -> a <# c Source #

transitiveNonstrictR :: (a < b) -> (b <= c) -> a < c Source #

Compose a strict inequality (the first argument) with a nonstrict inequality (the second argument).

transitiveNonstrictR# :: (a <# b) -> (b <=# c) -> a <# c Source #

Multiplication and Division

reciprocalA :: forall (m :: Nat) (n :: Nat) (p :: Nat). (m < Div n p) -> (p * m) < n Source #

Given that m < n/p, we know that p*m < n.

reciprocalB :: forall (m :: Nat) (n :: Nat) (p :: Nat). (m < (Div (n - 1) p + 1)) -> (p * m) < n Source #

Given that m < roundUp(n/p), we know that p*m < n.

Convert to Inequality

toLteL :: (a < b) -> (1 + a) <= b Source #

toLteR :: (a < b) -> (a + 1) <= b Source #

Absurdities

absurd :: (n < 0) -> void Source #

Nothing is less than zero.

Integration with GHC solver

constant :: forall a b. CmpNat a b ~ 'LT => a < b Source #

Use GHC's built-in type-level arithmetic to prove that one number is less than another. The type-checker only reduces CmpNat if both arguments are constants.

constant# :: forall a b. CmpNat a b ~ 'LT => (# #) -> a <# b Source #

Lift and Unlift

lift :: (a <# b) -> a < b Source #

unlift :: (a < b) -> a <# b Source #