{-# LANGUAGE DeriveDataTypeable  #-}
{-# LANGUAGE DeriveFoldable      #-}
{-# LANGUAGE DeriveFunctor       #-}
{-# LANGUAGE DeriveGeneric       #-}
{-# LANGUAGE DeriveTraversable   #-}
{-# LANGUAGE FlexibleContexts    #-}
{-# LANGUAGE Safe                #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators       #-}
----------------------------------------------------------------------------
-- |
-- Module      :  Algebra.Lattice.Divisibility
-- Copyright   :  (C) 2010-2015 Maximilian Bolingbroke, 2015-2019 Oleg Grenrus
-- License     :  BSD-3-Clause (see the file LICENSE)
--
-- Maintainer  :  Oleg Grenrus <oleg.grenrus@iki.fi>
--
----------------------------------------------------------------------------
module Algebra.Lattice.Divisibility (
    Divisibility(..)
  ) where

import Prelude ()
import Prelude.Compat

import Algebra.Lattice
import Algebra.PartialOrd

import Control.DeepSeq       (NFData (..))
import Control.Monad         (ap)
import Data.Data             (Data, Typeable)
import Data.Hashable         (Hashable (..))
import Data.Universe.Class   (Finite (..), Universe (..))
import Data.Universe.Helpers (Natural, Tagged, retag)
import GHC.Generics          (Generic, Generic1)

import qualified Test.QuickCheck as QC

--
-- Divisibility
--

-- | A divisibility lattice. @'join' = 'lcm'@, @'meet' = 'gcd'@.
newtype Divisibility a = Divisibility { Divisibility a -> a
getDivisibility :: a }
  deriving ( Divisibility a -> Divisibility a -> Bool
(Divisibility a -> Divisibility a -> Bool)
-> (Divisibility a -> Divisibility a -> Bool)
-> Eq (Divisibility a)
forall a. Eq a => Divisibility a -> Divisibility a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Divisibility a -> Divisibility a -> Bool
$c/= :: forall a. Eq a => Divisibility a -> Divisibility a -> Bool
== :: Divisibility a -> Divisibility a -> Bool
$c== :: forall a. Eq a => Divisibility a -> Divisibility a -> Bool
Eq, Eq (Divisibility a)
Eq (Divisibility a)
-> (Divisibility a -> Divisibility a -> Ordering)
-> (Divisibility a -> Divisibility a -> Bool)
-> (Divisibility a -> Divisibility a -> Bool)
-> (Divisibility a -> Divisibility a -> Bool)
-> (Divisibility a -> Divisibility a -> Bool)
-> (Divisibility a -> Divisibility a -> Divisibility a)
-> (Divisibility a -> Divisibility a -> Divisibility a)
-> Ord (Divisibility a)
Divisibility a -> Divisibility a -> Bool
Divisibility a -> Divisibility a -> Ordering
Divisibility a -> Divisibility a -> Divisibility a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (Divisibility a)
forall a. Ord a => Divisibility a -> Divisibility a -> Bool
forall a. Ord a => Divisibility a -> Divisibility a -> Ordering
forall a.
Ord a =>
Divisibility a -> Divisibility a -> Divisibility a
min :: Divisibility a -> Divisibility a -> Divisibility a
$cmin :: forall a.
Ord a =>
Divisibility a -> Divisibility a -> Divisibility a
max :: Divisibility a -> Divisibility a -> Divisibility a
$cmax :: forall a.
Ord a =>
Divisibility a -> Divisibility a -> Divisibility a
>= :: Divisibility a -> Divisibility a -> Bool
$c>= :: forall a. Ord a => Divisibility a -> Divisibility a -> Bool
> :: Divisibility a -> Divisibility a -> Bool
$c> :: forall a. Ord a => Divisibility a -> Divisibility a -> Bool
<= :: Divisibility a -> Divisibility a -> Bool
$c<= :: forall a. Ord a => Divisibility a -> Divisibility a -> Bool
< :: Divisibility a -> Divisibility a -> Bool
$c< :: forall a. Ord a => Divisibility a -> Divisibility a -> Bool
compare :: Divisibility a -> Divisibility a -> Ordering
$ccompare :: forall a. Ord a => Divisibility a -> Divisibility a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (Divisibility a)
Ord, Int -> Divisibility a -> ShowS
[Divisibility a] -> ShowS
Divisibility a -> String
(Int -> Divisibility a -> ShowS)
-> (Divisibility a -> String)
-> ([Divisibility a] -> ShowS)
-> Show (Divisibility a)
forall a. Show a => Int -> Divisibility a -> ShowS
forall a. Show a => [Divisibility a] -> ShowS
forall a. Show a => Divisibility a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Divisibility a] -> ShowS
$cshowList :: forall a. Show a => [Divisibility a] -> ShowS
show :: Divisibility a -> String
$cshow :: forall a. Show a => Divisibility a -> String
showsPrec :: Int -> Divisibility a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Divisibility a -> ShowS
Show, ReadPrec [Divisibility a]
ReadPrec (Divisibility a)
Int -> ReadS (Divisibility a)
ReadS [Divisibility a]
(Int -> ReadS (Divisibility a))
-> ReadS [Divisibility a]
-> ReadPrec (Divisibility a)
-> ReadPrec [Divisibility a]
-> Read (Divisibility a)
forall a. Read a => ReadPrec [Divisibility a]
forall a. Read a => ReadPrec (Divisibility a)
forall a. Read a => Int -> ReadS (Divisibility a)
forall a. Read a => ReadS [Divisibility a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Divisibility a]
$creadListPrec :: forall a. Read a => ReadPrec [Divisibility a]
readPrec :: ReadPrec (Divisibility a)
$creadPrec :: forall a. Read a => ReadPrec (Divisibility a)
readList :: ReadS [Divisibility a]
$creadList :: forall a. Read a => ReadS [Divisibility a]
readsPrec :: Int -> ReadS (Divisibility a)
$creadsPrec :: forall a. Read a => Int -> ReadS (Divisibility a)
Read, Typeable (Divisibility a)
DataType
Constr
Typeable (Divisibility a)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Divisibility a -> c (Divisibility a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Divisibility a))
-> (Divisibility a -> Constr)
-> (Divisibility a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Divisibility a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (Divisibility a)))
-> ((forall b. Data b => b -> b)
    -> Divisibility a -> Divisibility a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Divisibility a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Divisibility a -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> Divisibility a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> Divisibility a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> Divisibility a -> m (Divisibility a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> Divisibility a -> m (Divisibility a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> Divisibility a -> m (Divisibility a))
-> Data (Divisibility a)
Divisibility a -> DataType
Divisibility a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (Divisibility a))
(forall b. Data b => b -> b) -> Divisibility a -> Divisibility a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Divisibility a -> c (Divisibility a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Divisibility a)
forall a. Data a => Typeable (Divisibility a)
forall a. Data a => Divisibility a -> DataType
forall a. Data a => Divisibility a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> Divisibility a -> Divisibility a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Divisibility a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> Divisibility a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Divisibility a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Divisibility a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d)
-> Divisibility a -> m (Divisibility a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> Divisibility a -> m (Divisibility a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Divisibility a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Divisibility a -> c (Divisibility a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Divisibility a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Divisibility a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> Divisibility a -> u
forall u. (forall d. Data d => d -> u) -> Divisibility a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Divisibility a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Divisibility a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> Divisibility a -> m (Divisibility a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> Divisibility a -> m (Divisibility a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Divisibility a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Divisibility a -> c (Divisibility a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Divisibility a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Divisibility a))
$cDivisibility :: Constr
$tDivisibility :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> Divisibility a -> m (Divisibility a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> Divisibility a -> m (Divisibility a)
gmapMp :: (forall d. Data d => d -> m d)
-> Divisibility a -> m (Divisibility a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> Divisibility a -> m (Divisibility a)
gmapM :: (forall d. Data d => d -> m d)
-> Divisibility a -> m (Divisibility a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d)
-> Divisibility a -> m (Divisibility a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> Divisibility a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Divisibility a -> u
gmapQ :: (forall d. Data d => d -> u) -> Divisibility a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> Divisibility a -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Divisibility a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Divisibility a -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Divisibility a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Divisibility a -> r
gmapT :: (forall b. Data b => b -> b) -> Divisibility a -> Divisibility a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> Divisibility a -> Divisibility a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Divisibility a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Divisibility a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (Divisibility a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Divisibility a))
dataTypeOf :: Divisibility a -> DataType
$cdataTypeOf :: forall a. Data a => Divisibility a -> DataType
toConstr :: Divisibility a -> Constr
$ctoConstr :: forall a. Data a => Divisibility a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Divisibility a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Divisibility a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Divisibility a -> c (Divisibility a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Divisibility a -> c (Divisibility a)
$cp1Data :: forall a. Data a => Typeable (Divisibility a)
Data, Typeable, (forall x. Divisibility a -> Rep (Divisibility a) x)
-> (forall x. Rep (Divisibility a) x -> Divisibility a)
-> Generic (Divisibility a)
forall x. Rep (Divisibility a) x -> Divisibility a
forall x. Divisibility a -> Rep (Divisibility a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Divisibility a) x -> Divisibility a
forall a x. Divisibility a -> Rep (Divisibility a) x
$cto :: forall a x. Rep (Divisibility a) x -> Divisibility a
$cfrom :: forall a x. Divisibility a -> Rep (Divisibility a) x
Generic, a -> Divisibility b -> Divisibility a
(a -> b) -> Divisibility a -> Divisibility b
(forall a b. (a -> b) -> Divisibility a -> Divisibility b)
-> (forall a b. a -> Divisibility b -> Divisibility a)
-> Functor Divisibility
forall a b. a -> Divisibility b -> Divisibility a
forall a b. (a -> b) -> Divisibility a -> Divisibility b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Divisibility b -> Divisibility a
$c<$ :: forall a b. a -> Divisibility b -> Divisibility a
fmap :: (a -> b) -> Divisibility a -> Divisibility b
$cfmap :: forall a b. (a -> b) -> Divisibility a -> Divisibility b
Functor, Divisibility a -> Bool
(a -> m) -> Divisibility a -> m
(a -> b -> b) -> b -> Divisibility a -> b
(forall m. Monoid m => Divisibility m -> m)
-> (forall m a. Monoid m => (a -> m) -> Divisibility a -> m)
-> (forall m a. Monoid m => (a -> m) -> Divisibility a -> m)
-> (forall a b. (a -> b -> b) -> b -> Divisibility a -> b)
-> (forall a b. (a -> b -> b) -> b -> Divisibility a -> b)
-> (forall b a. (b -> a -> b) -> b -> Divisibility a -> b)
-> (forall b a. (b -> a -> b) -> b -> Divisibility a -> b)
-> (forall a. (a -> a -> a) -> Divisibility a -> a)
-> (forall a. (a -> a -> a) -> Divisibility a -> a)
-> (forall a. Divisibility a -> [a])
-> (forall a. Divisibility a -> Bool)
-> (forall a. Divisibility a -> Int)
-> (forall a. Eq a => a -> Divisibility a -> Bool)
-> (forall a. Ord a => Divisibility a -> a)
-> (forall a. Ord a => Divisibility a -> a)
-> (forall a. Num a => Divisibility a -> a)
-> (forall a. Num a => Divisibility a -> a)
-> Foldable Divisibility
forall a. Eq a => a -> Divisibility a -> Bool
forall a. Num a => Divisibility a -> a
forall a. Ord a => Divisibility a -> a
forall m. Monoid m => Divisibility m -> m
forall a. Divisibility a -> Bool
forall a. Divisibility a -> Int
forall a. Divisibility a -> [a]
forall a. (a -> a -> a) -> Divisibility a -> a
forall m a. Monoid m => (a -> m) -> Divisibility a -> m
forall b a. (b -> a -> b) -> b -> Divisibility a -> b
forall a b. (a -> b -> b) -> b -> Divisibility a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: Divisibility a -> a
$cproduct :: forall a. Num a => Divisibility a -> a
sum :: Divisibility a -> a
$csum :: forall a. Num a => Divisibility a -> a
minimum :: Divisibility a -> a
$cminimum :: forall a. Ord a => Divisibility a -> a
maximum :: Divisibility a -> a
$cmaximum :: forall a. Ord a => Divisibility a -> a
elem :: a -> Divisibility a -> Bool
$celem :: forall a. Eq a => a -> Divisibility a -> Bool
length :: Divisibility a -> Int
$clength :: forall a. Divisibility a -> Int
null :: Divisibility a -> Bool
$cnull :: forall a. Divisibility a -> Bool
toList :: Divisibility a -> [a]
$ctoList :: forall a. Divisibility a -> [a]
foldl1 :: (a -> a -> a) -> Divisibility a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Divisibility a -> a
foldr1 :: (a -> a -> a) -> Divisibility a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Divisibility a -> a
foldl' :: (b -> a -> b) -> b -> Divisibility a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Divisibility a -> b
foldl :: (b -> a -> b) -> b -> Divisibility a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Divisibility a -> b
foldr' :: (a -> b -> b) -> b -> Divisibility a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Divisibility a -> b
foldr :: (a -> b -> b) -> b -> Divisibility a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Divisibility a -> b
foldMap' :: (a -> m) -> Divisibility a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Divisibility a -> m
foldMap :: (a -> m) -> Divisibility a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Divisibility a -> m
fold :: Divisibility m -> m
$cfold :: forall m. Monoid m => Divisibility m -> m
Foldable, Functor Divisibility
Foldable Divisibility
Functor Divisibility
-> Foldable Divisibility
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> Divisibility a -> f (Divisibility b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Divisibility (f a) -> f (Divisibility a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Divisibility a -> m (Divisibility b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Divisibility (m a) -> m (Divisibility a))
-> Traversable Divisibility
(a -> f b) -> Divisibility a -> f (Divisibility b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
Divisibility (m a) -> m (Divisibility a)
forall (f :: * -> *) a.
Applicative f =>
Divisibility (f a) -> f (Divisibility a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Divisibility a -> m (Divisibility b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Divisibility a -> f (Divisibility b)
sequence :: Divisibility (m a) -> m (Divisibility a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
Divisibility (m a) -> m (Divisibility a)
mapM :: (a -> m b) -> Divisibility a -> m (Divisibility b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Divisibility a -> m (Divisibility b)
sequenceA :: Divisibility (f a) -> f (Divisibility a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Divisibility (f a) -> f (Divisibility a)
traverse :: (a -> f b) -> Divisibility a -> f (Divisibility b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Divisibility a -> f (Divisibility b)
$cp2Traversable :: Foldable Divisibility
$cp1Traversable :: Functor Divisibility
Traversable
           , (forall a. Divisibility a -> Rep1 Divisibility a)
-> (forall a. Rep1 Divisibility a -> Divisibility a)
-> Generic1 Divisibility
forall a. Rep1 Divisibility a -> Divisibility a
forall a. Divisibility a -> Rep1 Divisibility a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cto1 :: forall a. Rep1 Divisibility a -> Divisibility a
$cfrom1 :: forall a. Divisibility a -> Rep1 Divisibility a
Generic1
           )

instance Applicative Divisibility where
  pure :: a -> Divisibility a
pure = a -> Divisibility a
forall (m :: * -> *) a. Monad m => a -> m a
return
  <*> :: Divisibility (a -> b) -> Divisibility a -> Divisibility b
(<*>) = Divisibility (a -> b) -> Divisibility a -> Divisibility b
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
ap

instance Monad Divisibility where
  return :: a -> Divisibility a
return           = a -> Divisibility a
forall a. a -> Divisibility a
Divisibility
  Divisibility a
x >>= :: Divisibility a -> (a -> Divisibility b) -> Divisibility b
>>= a -> Divisibility b
f  = a -> Divisibility b
f a
x

instance NFData a => NFData (Divisibility a) where
  rnf :: Divisibility a -> ()
rnf (Divisibility a
a) = a -> ()
forall a. NFData a => a -> ()
rnf a
a

instance Hashable a => Hashable (Divisibility a)

instance Integral a => Lattice (Divisibility a) where
  Divisibility a
x \/ :: Divisibility a -> Divisibility a -> Divisibility a
\/ Divisibility a
y = a -> Divisibility a
forall a. a -> Divisibility a
Divisibility (a -> a -> a
forall a. Integral a => a -> a -> a
lcm a
x a
y)

  Divisibility a
x /\ :: Divisibility a -> Divisibility a -> Divisibility a
/\ Divisibility a
y = a -> Divisibility a
forall a. a -> Divisibility a
Divisibility (a -> a -> a
forall a. Integral a => a -> a -> a
gcd a
x a
y)

instance Integral a => BoundedJoinSemiLattice (Divisibility a) where
  bottom :: Divisibility a
bottom = a -> Divisibility a
forall a. a -> Divisibility a
Divisibility a
1

instance (Eq a, Integral a) => PartialOrd (Divisibility a) where
    leq :: Divisibility a -> Divisibility a -> Bool
leq (Divisibility a
a) (Divisibility a
b) = a
b a -> a -> a
forall a. Integral a => a -> a -> a
`mod` a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
0

instance Universe a => Universe (Divisibility a) where
    universe :: [Divisibility a]
universe = (a -> Divisibility a) -> [a] -> [Divisibility a]
forall a b. (a -> b) -> [a] -> [b]
map a -> Divisibility a
forall a. a -> Divisibility a
Divisibility [a]
forall a. Universe a => [a]
universe
instance Finite a => Finite (Divisibility a) where
    universeF :: [Divisibility a]
universeF = (a -> Divisibility a) -> [a] -> [Divisibility a]
forall a b. (a -> b) -> [a] -> [b]
map a -> Divisibility a
forall a. a -> Divisibility a
Divisibility [a]
forall a. Finite a => [a]
universeF
    cardinality :: Tagged (Divisibility a) Natural
cardinality = Tagged a Natural -> Tagged (Divisibility a) Natural
forall k1 k2 (s :: k1) b (t :: k2). Tagged s b -> Tagged t b
retag (Tagged a Natural
forall a. Finite a => Tagged a Natural
cardinality :: Tagged a Natural)

instance (QC.Arbitrary a, Num a, Ord a) => QC.Arbitrary (Divisibility a) where
    arbitrary :: Gen (Divisibility a)
arbitrary = a -> Divisibility a
forall a. (Ord a, Num a) => a -> Divisibility a
divisibility (a -> Divisibility a) -> Gen a -> Gen (Divisibility a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen a
forall a. Arbitrary a => Gen a
QC.arbitrary
    shrink :: Divisibility a -> [Divisibility a]
shrink Divisibility a
d = (Divisibility a -> Bool) -> [Divisibility a] -> [Divisibility a]
forall a. (a -> Bool) -> [a] -> [a]
filter (Divisibility a -> Divisibility a -> Bool
forall a. Ord a => a -> a -> Bool
<Divisibility a
d) ([Divisibility a] -> [Divisibility a])
-> (Divisibility a -> [Divisibility a])
-> Divisibility a
-> [Divisibility a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Divisibility a) -> [a] -> [Divisibility a]
forall a b. (a -> b) -> [a] -> [b]
map a -> Divisibility a
forall a. (Ord a, Num a) => a -> Divisibility a
divisibility ([a] -> [Divisibility a])
-> (Divisibility a -> [a]) -> Divisibility a -> [Divisibility a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> [a]
forall a. Arbitrary a => a -> [a]
QC.shrink (a -> [a]) -> (Divisibility a -> a) -> Divisibility a -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Divisibility a -> a
forall a. Divisibility a -> a
getDivisibility (Divisibility a -> [Divisibility a])
-> Divisibility a -> [Divisibility a]
forall a b. (a -> b) -> a -> b
$ Divisibility a
d

instance QC.CoArbitrary a => QC.CoArbitrary (Divisibility a) where
    coarbitrary :: Divisibility a -> Gen b -> Gen b
coarbitrary = a -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
QC.coarbitrary (a -> Gen b -> Gen b)
-> (Divisibility a -> a) -> Divisibility a -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Divisibility a -> a
forall a. Divisibility a -> a
getDivisibility

instance QC.Function a => QC.Function (Divisibility a) where
    function :: (Divisibility a -> b) -> Divisibility a :-> b
function = (Divisibility a -> a)
-> (a -> Divisibility a)
-> (Divisibility a -> b)
-> Divisibility a :-> b
forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
QC.functionMap Divisibility a -> a
forall a. Divisibility a -> a
getDivisibility a -> Divisibility a
forall a. a -> Divisibility a
Divisibility

divisibility :: (Ord a, Num a) => a -> Divisibility a
divisibility :: a -> Divisibility a
divisibility a
x | a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< (-a
1)  = a -> Divisibility a
forall a. a -> Divisibility a
Divisibility (a -> a
forall a. Num a => a -> a
abs a
x)
               | a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
1     = a -> Divisibility a
forall a. a -> Divisibility a
Divisibility a
1
               | Bool
otherwise = a -> Divisibility a
forall a. a -> Divisibility a
Divisibility a
x