Data.Monoid.LCM

monoid-subclasses-1.2.5.1: Subclasses of Monoid

Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.Monoid.LCM

Description

This module defines the `LCMMonoid` subclass of the `Monoid` class.

The `LCMMonoid` subclass adds the `lcm` operation, which takes two monoidal arguments and finds their least common multiple, or (more generally) the least monoid from which either argument can be subtracted with the `</>` operation.

For LCM monoids that are distributive, this module also provides the `DistributiveLCMMonoid` subclass of `LCMMonoid`.

All classes in this module are for Abelian, i.e., `Commutative` monoids.

Synopsis

- class GCDMonoid m => LCMMonoid m where
  - lcm :: m -> m -> m
- class (DistributiveGCDMonoid m, LCMMonoid m) => DistributiveLCMMonoid m

# Documentation

class GCDMonoid m => LCMMonoid m where #

Class of Abelian monoids that allow the least common multiple to be found for any two given values.

Operations must satisfy the following laws:

Reductivity

    isJust (lcm a b </> a)

    isJust (lcm a b </> b)

Uniqueness

    all isJust
        [       c </> a
        ,       c </> b
        , lcm a b </> c
        ]
    ==>
        (lcm a b == c)

Idempotence

    lcm a a == a

Identity

    lcm mempty a == a

    lcm a mempty == a

Commutativity

    lcm a b == lcm b a

Associativity

    lcm (lcm a b) c == lcm a (lcm b c)

Absorption

    lcm a (gcd a b) == a

    gcd a (lcm a b) == a

Methods

lcm :: m -> m -> m #

#### Instances

Instances details

LCMMonoid IntSet # |
Instance details Defined in Data.Monoid.LCM Methods lcm :: IntSet -> IntSet -> IntSet #
LCMMonoid () # |
Instance details Defined in Data.Monoid.LCM Methods lcm :: () -> () -> () #
Ord a => LCMMonoid (Set a) # |
Instance details Defined in Data.Monoid.LCM Methods lcm :: Set a -> Set a -> Set a #
LCMMonoid a => LCMMonoid (Dual a) # |
Instance details Defined in Data.Monoid.LCM Methods lcm :: Dual a -> Dual a -> Dual a #
LCMMonoid (Product Natural) # |
Instance details Defined in Data.Monoid.LCM Methods lcm :: Product Natural -> Product Natural -> Product Natural #
LCMMonoid (Sum Natural) # |
Instance details Defined in Data.Monoid.LCM Methods lcm :: Sum Natural -> Sum Natural -> Sum Natural #
(LCMMonoid a, LCMMonoid b) => LCMMonoid (a, b) # |
Instance details Defined in Data.Monoid.LCM Methods lcm :: (a, b) -> (a, b) -> (a, b) #
(LCMMonoid a, LCMMonoid b, LCMMonoid c) => LCMMonoid (a, b, c) # |
Instance details Defined in Data.Monoid.LCM Methods lcm :: (a, b, c) -> (a, b, c) -> (a, b, c) #
(LCMMonoid a, LCMMonoid b, LCMMonoid c, LCMMonoid d) => LCMMonoid (a, b, c, d) # |
Instance details Defined in Data.Monoid.LCM Methods lcm :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) #

class (DistributiveGCDMonoid m, LCMMonoid m) => DistributiveLCMMonoid m #

Class of commutative LCM monoids with distributivity.

In addition to the general `LCMMonoid` laws, instances of this class must also satisfy the following laws:

The `lcm` operation itself must be both left-distributive and right-distributive:

    lcm (a <> b) (a <> c) == a <> lcm b c

    lcm (a <> c) (b <> c) == lcm a b <> c

The `lcm` and `gcd` operations must distribute over one another:

    lcm a (gcd b c) == gcd (lcm a b) (lcm a c)

    gcd a (lcm b c) == lcm (gcd a b) (gcd a c)

#### Instances

Instances details

DistributiveLCMMonoid IntSet # |
Instance details Defined in Data.Monoid.LCM
DistributiveLCMMonoid () # |
Instance details Defined in Data.Monoid.LCM
Ord a => DistributiveLCMMonoid (Set a) # |
Instance details Defined in Data.Monoid.LCM
DistributiveLCMMonoid a => DistributiveLCMMonoid (Dual a) # |
Instance details Defined in Data.Monoid.LCM
DistributiveLCMMonoid (Product Natural) # |
Instance details Defined in Data.Monoid.LCM
DistributiveLCMMonoid (Sum Natural) # |
Instance details Defined in Data.Monoid.LCM