{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE NoStarIsType #-}
-- | Utilities for working with 'KnownNat' constraints.
--
-- This module is only available on GHC 8.0 or later.
module Data.Constraint.Nat
  ( Min, Max, Lcm, Gcd, Divides, Div, Mod
  , plusNat, minusNat, timesNat, powNat, minNat, maxNat, gcdNat, lcmNat, divNat, modNat
  , plusZero, minusZero, timesZero, timesOne, powZero, powOne, maxZero, minZero, gcdZero, gcdOne, lcmZero, lcmOne
  , plusAssociates, timesAssociates, minAssociates, maxAssociates, gcdAssociates, lcmAssociates
  , plusCommutes, timesCommutes, minCommutes, maxCommutes, gcdCommutes, lcmCommutes
  , plusDistributesOverTimes, timesDistributesOverPow, timesDistributesOverGcd, timesDistributesOverLcm
  , minDistributesOverPlus, minDistributesOverTimes, minDistributesOverPow1, minDistributesOverPow2, minDistributesOverMax
  , maxDistributesOverPlus, maxDistributesOverTimes, maxDistributesOverPow1, maxDistributesOverPow2, maxDistributesOverMin
  , gcdDistributesOverLcm, lcmDistributesOverGcd
  , minIsIdempotent, maxIsIdempotent, lcmIsIdempotent, gcdIsIdempotent
  , plusIsCancellative, timesIsCancellative
  , dividesPlus, dividesTimes, dividesMin, dividesMax, dividesPow, dividesGcd, dividesLcm
  , plusMonotone1, plusMonotone2
  , timesMonotone1, timesMonotone2
  , powMonotone1, powMonotone2
  , minMonotone1, minMonotone2
  , maxMonotone1, maxMonotone2
  , divMonotone1, divMonotone2
  , euclideanNat
  , plusMod, timesMod
  , modBound
  , dividesDef
  , timesDiv
  , eqLe, leEq, leId, leTrans
  , leZero, zeroLe
  , plusMinusInverse1, plusMinusInverse2, plusMinusInverse3
  ) where

import Data.Constraint
import Data.Constraint.Unsafe
import Data.Proxy
import Data.Type.Bool
import GHC.TypeLits
#if MIN_VERSION_base(4,18,0)
import qualified GHC.TypeNats as TN
#else
import Unsafe.Coerce
#endif

type family Min (m::Nat) (n::Nat) :: Nat where
    Min m n = If (n <=? m) n m
type family Max (m::Nat) (n::Nat) :: Nat where
    Max m n = If (n <=? m) m n
type family Gcd (m::Nat) (n::Nat) :: Nat where
    Gcd m m = m
type family Lcm (m::Nat) (n::Nat) :: Nat where
   Lcm m m = m

type Divides n m = n ~ Gcd n m

#if !MIN_VERSION_base(4,18,0)
newtype Magic n = Magic (KnownNat n => Dict (KnownNat n))
#endif

magic :: forall n m o. (Integer -> Integer -> Integer) -> (KnownNat n, KnownNat m) :- KnownNat o
#if MIN_VERSION_base(4,18,0)
magic f = Sub $ TN.withKnownNat @o (unsafeSNat (fromInteger (natVal (Proxy @n) `f` natVal (Proxy @m)))) Dict
#else
magic :: forall (n :: Nat) (m :: Nat) (o :: Nat).
(Integer -> Integer -> Integer)
-> (KnownNat n, KnownNat m) :- KnownNat o
magic Integer -> Integer -> Integer
f = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall a b. (a -> b) -> a -> b
$ forall a b. a -> b
unsafeCoerce (forall (n :: Nat). (KnownNat n => Dict (KnownNat n)) -> Magic n
Magic forall (a :: Constraint). a => Dict a
Dict) (forall (n :: Nat) (proxy :: Nat -> Type).
KnownNat n =>
proxy n -> Integer
natVal (forall {k} (t :: k). Proxy t
Proxy :: Proxy n) Integer -> Integer -> Integer
`f` forall (n :: Nat) (proxy :: Nat -> Type).
KnownNat n =>
proxy n -> Integer
natVal (forall {k} (t :: k). Proxy t
Proxy :: Proxy m))
#endif

axiomLe :: forall (a :: Nat) (b :: Nat). Dict (a <= b)
axiomLe :: forall (a :: Nat) (b :: Nat). Dict (a <= b)
axiomLe = forall (c :: Constraint). Dict c
unsafeAxiom

eqLe :: forall (a :: Nat) (b :: Nat). (a ~ b) :- (a <= b)
eqLe :: forall (a :: Nat) (b :: Nat). (a ~ b) :- (a <= b)
eqLe = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (a :: Constraint). a => Dict a
Dict

dividesGcd :: forall a b c. (Divides a b, Divides a c) :- Divides a (Gcd b c)
dividesGcd :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(Divides a b, Divides a c) :- Divides a (Gcd b c)
dividesGcd = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

dividesLcm :: forall a b c. (Divides a c, Divides b c) :- Divides (Lcm a b) c
dividesLcm :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(Divides a c, Divides b c) :- Divides (Lcm a b) c
dividesLcm = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

gcdCommutes :: forall a b. Dict (Gcd a b ~ Gcd b a)
gcdCommutes :: forall (a :: Nat) (b :: Nat). Dict (Gcd a b ~ Gcd b a)
gcdCommutes = forall (c :: Constraint). Dict c
unsafeAxiom

lcmCommutes :: forall a b. Dict (Lcm a b ~ Lcm b a)
lcmCommutes :: forall (a :: Nat) (b :: Nat). Dict (Lcm a b ~ Lcm b a)
lcmCommutes = forall (c :: Constraint). Dict c
unsafeAxiom

gcdZero :: forall a. Dict (Gcd 0 a ~ a)
gcdZero :: forall (a :: Nat). Dict (Gcd 0 a ~ a)
gcdZero = forall (c :: Constraint). Dict c
unsafeAxiom

gcdOne :: forall a. Dict (Gcd 1 a ~ 1)
gcdOne :: forall (a :: Nat). Dict (Gcd 1 a ~ 1)
gcdOne = forall (c :: Constraint). Dict c
unsafeAxiom

lcmZero :: forall a. Dict (Lcm 0 a ~ 0)
lcmZero :: forall (a :: Nat). Dict (Lcm 0 a ~ 0)
lcmZero = forall (c :: Constraint). Dict c
unsafeAxiom

lcmOne :: forall a. Dict (Lcm 1 a ~ a)
lcmOne :: forall (a :: Nat). Dict (Lcm 1 a ~ a)
lcmOne = forall (c :: Constraint). Dict c
unsafeAxiom

gcdNat :: forall n m. (KnownNat n, KnownNat m) :- KnownNat (Gcd n m)
gcdNat :: forall (n :: Nat) (m :: Nat).
(KnownNat n, KnownNat m) :- KnownNat (Gcd n m)
gcdNat = forall (n :: Nat) (m :: Nat) (o :: Nat).
(Integer -> Integer -> Integer)
-> (KnownNat n, KnownNat m) :- KnownNat o
magic forall a. Integral a => a -> a -> a
gcd

lcmNat :: forall n m. (KnownNat n, KnownNat m) :- KnownNat (Lcm n m)
lcmNat :: forall (n :: Nat) (m :: Nat).
(KnownNat n, KnownNat m) :- KnownNat (Lcm n m)
lcmNat = forall (n :: Nat) (m :: Nat) (o :: Nat).
(Integer -> Integer -> Integer)
-> (KnownNat n, KnownNat m) :- KnownNat o
magic forall a. Integral a => a -> a -> a
lcm

plusNat :: forall n m. (KnownNat n, KnownNat m) :- KnownNat (n + m)
plusNat :: forall (n :: Nat) (m :: Nat).
(KnownNat n, KnownNat m) :- KnownNat (n + m)
plusNat = forall (n :: Nat) (m :: Nat) (o :: Nat).
(Integer -> Integer -> Integer)
-> (KnownNat n, KnownNat m) :- KnownNat o
magic forall a. Num a => a -> a -> a
(+)

minusNat :: forall n m. (KnownNat n, KnownNat m, m <= n) :- KnownNat (n - m)
minusNat :: forall (n :: Nat) (m :: Nat).
(KnownNat n, KnownNat m, m <= n) :- KnownNat (n - m)
minusNat = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall a b. (a -> b) -> a -> b
$ case forall (n :: Nat) (m :: Nat) (o :: Nat).
(Integer -> Integer -> Integer)
-> (KnownNat n, KnownNat m) :- KnownNat o
magic @n @m (-) of Sub (KnownNat n, KnownNat m) => Dict (KnownNat (n - m))
r -> (KnownNat n, KnownNat m) => Dict (KnownNat (n - m))
r

minNat   :: forall n m. (KnownNat n, KnownNat m) :- KnownNat (Min n m)
minNat :: forall (n :: Nat) (m :: Nat).
(KnownNat n, KnownNat m) :- KnownNat (Min n m)
minNat = forall (n :: Nat) (m :: Nat) (o :: Nat).
(Integer -> Integer -> Integer)
-> (KnownNat n, KnownNat m) :- KnownNat o
magic forall a. Ord a => a -> a -> a
min

maxNat   :: forall n m. (KnownNat n, KnownNat m) :- KnownNat (Max n m)
maxNat :: forall (n :: Nat) (m :: Nat).
(KnownNat n, KnownNat m) :- KnownNat (Max n m)
maxNat = forall (n :: Nat) (m :: Nat) (o :: Nat).
(Integer -> Integer -> Integer)
-> (KnownNat n, KnownNat m) :- KnownNat o
magic forall a. Ord a => a -> a -> a
max

timesNat  :: forall n m. (KnownNat n, KnownNat m) :- KnownNat (n * m)
timesNat :: forall (n :: Nat) (m :: Nat).
(KnownNat n, KnownNat m) :- KnownNat (n * m)
timesNat = forall (n :: Nat) (m :: Nat) (o :: Nat).
(Integer -> Integer -> Integer)
-> (KnownNat n, KnownNat m) :- KnownNat o
magic forall a. Num a => a -> a -> a
(*)

powNat :: forall n m. (KnownNat n, KnownNat m) :- KnownNat (n ^ m)
powNat :: forall (n :: Nat) (m :: Nat).
(KnownNat n, KnownNat m) :- KnownNat (n ^ m)
powNat = forall (n :: Nat) (m :: Nat) (o :: Nat).
(Integer -> Integer -> Integer)
-> (KnownNat n, KnownNat m) :- KnownNat o
magic forall a b. (Num a, Integral b) => a -> b -> a
(^)

divNat :: forall n m. (KnownNat n, KnownNat m, 1 <= m) :- KnownNat (Div n m)
divNat :: forall (n :: Nat) (m :: Nat).
(KnownNat n, KnownNat m, 1 <= m) :- KnownNat (Div n m)
divNat = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall a b. (a -> b) -> a -> b
$ case forall (n :: Nat) (m :: Nat) (o :: Nat).
(Integer -> Integer -> Integer)
-> (KnownNat n, KnownNat m) :- KnownNat o
magic @n @m forall a. Integral a => a -> a -> a
div of Sub (KnownNat n, KnownNat m) => Dict (KnownNat (Div n m))
r -> (KnownNat n, KnownNat m) => Dict (KnownNat (Div n m))
r

modNat :: forall n m. (KnownNat n, KnownNat m, 1 <= m) :- KnownNat (Mod n m)
modNat :: forall (n :: Nat) (m :: Nat).
(KnownNat n, KnownNat m, 1 <= m) :- KnownNat (Mod n m)
modNat = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall a b. (a -> b) -> a -> b
$ case forall (n :: Nat) (m :: Nat) (o :: Nat).
(Integer -> Integer -> Integer)
-> (KnownNat n, KnownNat m) :- KnownNat o
magic @n @m forall a. Integral a => a -> a -> a
mod of Sub (KnownNat n, KnownNat m) => Dict (KnownNat (Mod n m))
r -> (KnownNat n, KnownNat m) => Dict (KnownNat (Mod n m))
r

plusZero :: forall n. Dict ((n + 0) ~ n)
plusZero :: forall (n :: Nat). Dict ((n + 0) ~ n)
plusZero = forall (a :: Constraint). a => Dict a
Dict

minusZero :: forall n. Dict ((n - 0) ~ n)
minusZero :: forall (n :: Nat). Dict ((n - 0) ~ n)
minusZero = forall (a :: Constraint). a => Dict a
Dict

timesZero :: forall n. Dict ((n * 0) ~ 0)
timesZero :: forall (n :: Nat). Dict ((n * 0) ~ 0)
timesZero = forall (a :: Constraint). a => Dict a
Dict

timesOne :: forall n. Dict ((n * 1) ~ n)
timesOne :: forall (n :: Nat). Dict ((n * 1) ~ n)
timesOne = forall (a :: Constraint). a => Dict a
Dict

minZero :: forall n. Dict (Min n 0 ~ 0)
#if MIN_VERSION_base(4,16,0)
minZero :: forall (n :: Nat). Dict (Min n 0 ~ 0)
minZero = forall (c :: Constraint). Dict c
unsafeAxiom
#else
minZero = Dict
#endif

maxZero :: forall n. Dict (Max n 0 ~ n)
#if MIN_VERSION_base(4,16,0)
maxZero :: forall (n :: Nat). Dict (Max n 0 ~ n)
maxZero = forall (c :: Constraint). Dict c
unsafeAxiom
#else
maxZero = Dict
#endif

powZero :: forall n. Dict ((n ^ 0) ~ 1)
powZero :: forall (n :: Nat). Dict ((n ^ 0) ~ 1)
powZero = forall (a :: Constraint). a => Dict a
Dict

leZero :: forall a. (a <= 0) :- (a ~ 0)
leZero :: forall (a :: Nat). (a <= 0) :- (a ~ 0)
leZero = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

zeroLe :: forall (a :: Nat). Dict (0 <= a)
#if MIN_VERSION_base(4,16,0)
zeroLe :: forall (a :: Nat). Dict (0 <= a)
zeroLe = forall (c :: Constraint). Dict c
unsafeAxiom
#else
zeroLe = Dict
#endif

plusMinusInverse1 :: forall n m. Dict (((m + n) - n) ~ m)
plusMinusInverse1 :: forall (n :: Nat) (m :: Nat). Dict (((m + n) - n) ~ m)
plusMinusInverse1 = forall (c :: Constraint). Dict c
unsafeAxiom

plusMinusInverse2 :: forall n m. (m <= n) :- (((m + n) - m) ~ n)
plusMinusInverse2 :: forall (n :: Nat) (m :: Nat). (m <= n) :- (((m + n) - m) ~ n)
plusMinusInverse2 = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

plusMinusInverse3 :: forall n m. (n <= m) :- (((m - n) + n) ~ m)
plusMinusInverse3 :: forall (n :: Nat) (m :: Nat). (n <= m) :- (((m - n) + n) ~ m)
plusMinusInverse3 = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

plusMonotone1 :: forall a b c. (a <= b) :- (a + c <= b + c)
plusMonotone1 :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(a <= b) :- ((a + c) <= (b + c))
plusMonotone1 = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

plusMonotone2 :: forall a b c. (b <= c) :- (a + b <= a + c)
plusMonotone2 :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(b <= c) :- ((a + b) <= (a + c))
plusMonotone2 = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

powMonotone1 :: forall a b c. (a <= b) :- ((a^c) <= (b^c))
powMonotone1 :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(a <= b) :- ((a ^ c) <= (b ^ c))
powMonotone1 = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

powMonotone2 :: forall a b c. (b <= c) :- ((a^b) <= (a^c))
powMonotone2 :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(b <= c) :- ((a ^ b) <= (a ^ c))
powMonotone2 = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

divMonotone1 :: forall a b c. (a <= b) :- (Div a c <= Div b c)
divMonotone1 :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(a <= b) :- (Div a c <= Div b c)
divMonotone1 = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

divMonotone2 :: forall a b c. (b <= c) :- (Div a c <= Div a b)
divMonotone2 :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(b <= c) :- (Div a c <= Div a b)
divMonotone2 = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

timesMonotone1 :: forall a b c. (a <= b) :- (a * c <= b * c)
timesMonotone1 :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(a <= b) :- ((a * c) <= (b * c))
timesMonotone1 = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

timesMonotone2 :: forall a b c. (b <= c) :- (a * b <= a * c)
timesMonotone2 :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(b <= c) :- ((a * b) <= (a * c))
timesMonotone2 = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

minMonotone1 :: forall a b c. (a <= b) :- (Min a c <= Min b c)
minMonotone1 :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(a <= b) :- (Min a c <= Min b c)
minMonotone1 = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

minMonotone2 :: forall a b c. (b <= c) :- (Min a b <= Min a c)
minMonotone2 :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(b <= c) :- (Min a b <= Min a c)
minMonotone2 = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

maxMonotone1 :: forall a b c. (a <= b) :- (Max a c <= Max b c)
maxMonotone1 :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(a <= b) :- (Max a c <= Max b c)
maxMonotone1 = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

maxMonotone2 :: forall a b c. (b <= c) :- (Max a b <= Max a c)
maxMonotone2 :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(b <= c) :- (Max a b <= Max a c)
maxMonotone2 = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

powOne :: forall n. Dict ((n ^ 1) ~ n)
powOne :: forall (n :: Nat). Dict ((n ^ 1) ~ n)
powOne = forall (c :: Constraint). Dict c
unsafeAxiom

plusMod :: forall a b c. (1 <= c) :- (Mod (a + b) c ~ Mod (Mod a c + Mod b c) c)
plusMod :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(1 <= c) :- (Mod (a + b) c ~ Mod (Mod a c + Mod b c) c)
plusMod = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

timesMod :: forall a b c. (1 <= c) :- (Mod (a * b) c ~ Mod (Mod a c * Mod b c) c)
timesMod :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(1 <= c) :- (Mod (a * b) c ~ Mod (Mod a c * Mod b c) c)
timesMod = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

modBound :: forall m n. (1 <= n) :- (Mod m n <= n)
modBound :: forall (m :: Nat) (n :: Nat). (1 <= n) :- (Mod m n <= n)
modBound = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

euclideanNat :: (1 <= c) :- (a ~ (c * Div a c + Mod a c))
euclideanNat :: forall (c :: Nat) (a :: Nat).
(1 <= c) :- (a ~ ((c * Div a c) + Mod a c))
euclideanNat = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

plusCommutes :: forall n m. Dict ((m + n) ~ (n + m))
plusCommutes :: forall (n :: Nat) (m :: Nat). Dict ((m + n) ~ (n + m))
plusCommutes = forall (c :: Constraint). Dict c
unsafeAxiom

timesCommutes :: forall n m. Dict ((m * n) ~ (n * m))
timesCommutes :: forall (n :: Nat) (m :: Nat). Dict ((m * n) ~ (n * m))
timesCommutes = forall (c :: Constraint). Dict c
unsafeAxiom

minCommutes :: forall n m. Dict (Min m n ~ Min n m)
minCommutes :: forall (n :: Nat) (m :: Nat). Dict (Min m n ~ Min n m)
minCommutes = forall (c :: Constraint). Dict c
unsafeAxiom

maxCommutes :: forall n m. Dict (Max m n ~ Max n m)
maxCommutes :: forall (n :: Nat) (m :: Nat). Dict (Max m n ~ Max n m)
maxCommutes = forall (c :: Constraint). Dict c
unsafeAxiom

plusAssociates :: forall m n o. Dict (((m + n) + o) ~ (m + (n + o)))
plusAssociates :: forall (m :: Nat) (n :: Nat) (o :: Nat).
Dict (((m + n) + o) ~ (m + (n + o)))
plusAssociates = forall (c :: Constraint). Dict c
unsafeAxiom

timesAssociates :: forall m n o. Dict (((m * n) * o) ~ (m * (n * o)))
timesAssociates :: forall (m :: Nat) (n :: Nat) (o :: Nat).
Dict (((m * n) * o) ~ (m * (n * o)))
timesAssociates = forall (c :: Constraint). Dict c
unsafeAxiom

minAssociates :: forall m n o. Dict (Min (Min m n) o ~ Min m (Min n o))
minAssociates :: forall (m :: Nat) (n :: Nat) (o :: Nat).
Dict (Min (Min m n) o ~ Min m (Min n o))
minAssociates = forall (c :: Constraint). Dict c
unsafeAxiom

maxAssociates :: forall m n o. Dict (Max (Max m n) o ~ Max m (Max n o))
maxAssociates :: forall (m :: Nat) (n :: Nat) (o :: Nat).
Dict (Max (Max m n) o ~ Max m (Max n o))
maxAssociates = forall (c :: Constraint). Dict c
unsafeAxiom

gcdAssociates :: forall a b c. Dict (Gcd (Gcd a b) c  ~ Gcd a (Gcd b c))
gcdAssociates :: forall (a :: Nat) (b :: Nat) (c :: Nat).
Dict (Gcd (Gcd a b) c ~ Gcd a (Gcd b c))
gcdAssociates = forall (c :: Constraint). Dict c
unsafeAxiom

lcmAssociates :: forall a b c. Dict (Lcm (Lcm a b) c ~ Lcm a (Lcm b c))
lcmAssociates :: forall (a :: Nat) (b :: Nat) (c :: Nat).
Dict (Lcm (Lcm a b) c ~ Lcm a (Lcm b c))
lcmAssociates = forall (c :: Constraint). Dict c
unsafeAxiom

minIsIdempotent :: forall n. Dict (Min n n ~ n)
minIsIdempotent :: forall (n :: Nat). Dict (Min n n ~ n)
minIsIdempotent = forall (a :: Constraint). a => Dict a
Dict

maxIsIdempotent :: forall n. Dict (Max n n ~ n)
maxIsIdempotent :: forall (n :: Nat). Dict (Max n n ~ n)
maxIsIdempotent = forall (a :: Constraint). a => Dict a
Dict

gcdIsIdempotent :: forall n. Dict (Gcd n n ~ n)
gcdIsIdempotent :: forall (n :: Nat). Dict (Gcd n n ~ n)
gcdIsIdempotent = forall (a :: Constraint). a => Dict a
Dict

lcmIsIdempotent :: forall n. Dict (Lcm n n ~ n)
lcmIsIdempotent :: forall (n :: Nat). Dict (Lcm n n ~ n)
lcmIsIdempotent = forall (a :: Constraint). a => Dict a
Dict

minDistributesOverPlus :: forall n m o. Dict ((n + Min m o) ~ Min (n + m) (n + o))
minDistributesOverPlus :: forall (n :: Nat) (m :: Nat) (o :: Nat).
Dict ((n + Min m o) ~ Min (n + m) (n + o))
minDistributesOverPlus = forall (c :: Constraint). Dict c
unsafeAxiom

minDistributesOverTimes :: forall n m o. Dict ((n * Min m o) ~ Min (n * m) (n * o))
minDistributesOverTimes :: forall (n :: Nat) (m :: Nat) (o :: Nat).
Dict ((n * Min m o) ~ Min (n * m) (n * o))
minDistributesOverTimes = forall (c :: Constraint). Dict c
unsafeAxiom

minDistributesOverPow1 :: forall n m o. Dict ((Min n m ^ o) ~ Min (n ^ o) (m ^ o))
minDistributesOverPow1 :: forall (n :: Nat) (m :: Nat) (o :: Nat).
Dict ((Min n m ^ o) ~ Min (n ^ o) (m ^ o))
minDistributesOverPow1 = forall (c :: Constraint). Dict c
unsafeAxiom

minDistributesOverPow2 :: forall n m o. Dict ((n ^ Min m o) ~ Min (n ^ m) (n ^ o))
minDistributesOverPow2 :: forall (n :: Nat) (m :: Nat) (o :: Nat).
Dict ((n ^ Min m o) ~ Min (n ^ m) (n ^ o))
minDistributesOverPow2 = forall (c :: Constraint). Dict c
unsafeAxiom

minDistributesOverMax :: forall n m o. Dict (Max n (Min m o) ~ Min (Max n m) (Max n o))
minDistributesOverMax :: forall (n :: Nat) (m :: Nat) (o :: Nat).
Dict (Max n (Min m o) ~ Min (Max n m) (Max n o))
minDistributesOverMax = forall (c :: Constraint). Dict c
unsafeAxiom

maxDistributesOverPlus :: forall n m o. Dict ((n + Max m o) ~ Max (n + m) (n + o))
maxDistributesOverPlus :: forall (n :: Nat) (m :: Nat) (o :: Nat).
Dict ((n + Max m o) ~ Max (n + m) (n + o))
maxDistributesOverPlus = forall (c :: Constraint). Dict c
unsafeAxiom

maxDistributesOverTimes :: forall n m o. Dict ((n * Max m o) ~ Max (n * m) (n * o))
maxDistributesOverTimes :: forall (n :: Nat) (m :: Nat) (o :: Nat).
Dict ((n * Max m o) ~ Max (n * m) (n * o))
maxDistributesOverTimes = forall (c :: Constraint). Dict c
unsafeAxiom

maxDistributesOverPow1 :: forall n m o. Dict ((Max n m ^ o) ~ Max (n ^ o) (m ^ o))
maxDistributesOverPow1 :: forall (n :: Nat) (m :: Nat) (o :: Nat).
Dict ((Max n m ^ o) ~ Max (n ^ o) (m ^ o))
maxDistributesOverPow1 = forall (c :: Constraint). Dict c
unsafeAxiom

maxDistributesOverPow2 :: forall n m o. Dict ((n ^ Max m o) ~ Max (n ^ m) (n ^ o))
maxDistributesOverPow2 :: forall (n :: Nat) (m :: Nat) (o :: Nat).
Dict ((n ^ Max m o) ~ Max (n ^ m) (n ^ o))
maxDistributesOverPow2 = forall (c :: Constraint). Dict c
unsafeAxiom

maxDistributesOverMin :: forall n m o. Dict (Min n (Max m o) ~ Max (Min n m) (Min n o))
maxDistributesOverMin :: forall (n :: Nat) (m :: Nat) (o :: Nat).
Dict (Min n (Max m o) ~ Max (Min n m) (Min n o))
maxDistributesOverMin = forall (c :: Constraint). Dict c
unsafeAxiom

plusDistributesOverTimes :: forall n m o. Dict ((n * (m + o)) ~ (n * m + n * o))
plusDistributesOverTimes :: forall (n :: Nat) (m :: Nat) (o :: Nat).
Dict ((n * (m + o)) ~ ((n * m) + (n * o)))
plusDistributesOverTimes = forall (c :: Constraint). Dict c
unsafeAxiom

timesDistributesOverPow  :: forall n m o. Dict ((n ^ (m + o)) ~ (n ^ m * n ^ o))
timesDistributesOverPow :: forall (n :: Nat) (m :: Nat) (o :: Nat).
Dict ((n ^ (m + o)) ~ ((n ^ m) * (n ^ o)))
timesDistributesOverPow = forall (c :: Constraint). Dict c
unsafeAxiom

timesDistributesOverGcd :: forall n m o. Dict ((n * Gcd m o) ~ Gcd (n * m) (n * o))
timesDistributesOverGcd :: forall (n :: Nat) (m :: Nat) (o :: Nat).
Dict ((n * Gcd m o) ~ Gcd (n * m) (n * o))
timesDistributesOverGcd = forall (c :: Constraint). Dict c
unsafeAxiom

timesDistributesOverLcm :: forall n m o. Dict ((n * Lcm m o) ~ Lcm (n * m) (n * o))
timesDistributesOverLcm :: forall (n :: Nat) (m :: Nat) (o :: Nat).
Dict ((n * Lcm m o) ~ Lcm (n * m) (n * o))
timesDistributesOverLcm = forall (c :: Constraint). Dict c
unsafeAxiom

plusIsCancellative :: forall n m o. ((n + m) ~ (n + o)) :- (m ~ o)
plusIsCancellative :: forall (n :: Nat) (m :: Nat) (o :: Nat).
((n + m) ~ (n + o)) :- (m ~ o)
plusIsCancellative = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

timesIsCancellative :: forall n m o. (1 <= n, (n * m) ~ (n * o)) :- (m ~ o)
timesIsCancellative :: forall (n :: Nat) (m :: Nat) (o :: Nat).
(1 <= n, (n * m) ~ (n * o)) :- (m ~ o)
timesIsCancellative = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

gcdDistributesOverLcm :: forall a b c. Dict (Gcd (Lcm a b) c ~ Lcm (Gcd a c) (Gcd b c))
gcdDistributesOverLcm :: forall (a :: Nat) (b :: Nat) (c :: Nat).
Dict (Gcd (Lcm a b) c ~ Lcm (Gcd a c) (Gcd b c))
gcdDistributesOverLcm = forall (c :: Constraint). Dict c
unsafeAxiom

lcmDistributesOverGcd :: forall a b c. Dict (Lcm (Gcd a b) c ~ Gcd (Lcm a c) (Lcm b c))
lcmDistributesOverGcd :: forall (a :: Nat) (b :: Nat) (c :: Nat).
Dict (Lcm (Gcd a b) c ~ Gcd (Lcm a c) (Lcm b c))
lcmDistributesOverGcd = forall (c :: Constraint). Dict c
unsafeAxiom

dividesPlus :: (Divides a b, Divides a c) :- Divides a (b + c)
dividesPlus :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(Divides a b, Divides a c) :- Divides a (b + c)
dividesPlus = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

dividesTimes :: Divides a b :- Divides a (b * c)
dividesTimes :: forall (a :: Nat) (b :: Nat) (c :: Nat).
Divides a b :- Divides a (b * c)
dividesTimes = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

dividesMin :: (Divides a b, Divides a c) :- Divides a (Min b c)
dividesMin :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(Divides a b, Divides a c) :- Divides a (Min b c)
dividesMin = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

dividesMax :: (Divides a b, Divides a c) :- Divides a (Max b c)
dividesMax :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(Divides a b, Divides a c) :- Divides a (Max b c)
dividesMax = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

-- This `dividesDef` is simpler and more convenient than Divides a b :- ((a * Div b a) ~ b)
-- because the latter can be easily derived via 'euclideanNat', but not vice versa.

dividesDef :: forall a b. Divides a b :- (Mod b a ~ 0)
dividesDef :: forall (a :: Nat) (b :: Nat). Divides a b :- (Mod b a ~ 0)
dividesDef = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

dividesPow :: (1 <= n, Divides a b) :- Divides a (b^n)
dividesPow :: forall (n :: Nat) (a :: Nat) (b :: Nat).
(1 <= n, Divides a b) :- Divides a (b ^ n)
dividesPow = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

timesDiv :: forall a b. Dict ((a * Div b a) <= b)
timesDiv :: forall (a :: Nat) (b :: Nat). Dict ((a * Div b a) <= b)
timesDiv = forall (c :: Constraint). Dict c
unsafeAxiom

-- (<=) is an internal category in the category of constraints.

leId :: forall (a :: Nat). Dict (a <= a)
leId :: forall (a :: Nat). Dict (a <= a)
leId = forall (a :: Constraint). a => Dict a
Dict

leEq :: forall (a :: Nat) (b :: Nat). (a <= b, b <= a) :- (a ~ b)
leEq :: forall (a :: Nat) (b :: Nat). (a <= b, b <= a) :- (a ~ b)
leEq = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub forall (c :: Constraint). Dict c
unsafeAxiom

leTrans :: forall (a :: Nat) (b :: Nat) (c :: Nat). (b <= c, a <= b) :- (a <= c)
leTrans :: forall (a :: Nat) (b :: Nat) (c :: Nat).
(b <= c, a <= b) :- (a <= c)
leTrans = forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub (forall (a :: Nat) (b :: Nat). Dict (a <= b)
axiomLe @a @c)