module Ideas.Common.Algebra.FieldLaws
(
leftDistributive, rightDistributive
, distributiveLaws, semiRingLaws
, leftNegateTimes, rightNegateTimes
, negateTimesLaws, ringLaws, commutativeRingLaws
, distributiveSubtractionLaws
, exchangeInverses, fieldLaws
, fromAdditiveLaw
, fromMultiplicativeLaw
, propsField
) where
import Ideas.Common.Algebra.Field
import Ideas.Common.Algebra.GroupLaws
import Ideas.Common.Algebra.Law
import Test.QuickCheck
leftDistributive :: SemiRing a => Law a
leftDistributive = leftDistributiveFor (|*|) (|+|)
rightDistributive :: SemiRing a => Law a
rightDistributive = rightDistributiveFor (|*|) (|+|)
distributiveLaws :: SemiRing a => [Law a]
distributiveLaws = [leftDistributive, rightDistributive]
semiRingLaws :: SemiRing a => [Law a]
semiRingLaws =
map fromAdditiveLaw commutativeMonoidLaws ++
map fromMultiplicativeLaw monoidZeroLaws ++
distributiveLaws
leftNegateTimes :: Ring a => Law a
leftNegateTimes = law "left-negate-times" $ \a b ->
plusInverse a |*| b :==: plusInverse (a |*| b)
rightNegateTimes :: Ring a => Law a
rightNegateTimes = law "right-negate-times" $ \a b ->
a |*| plusInverse b :==: plusInverse (a |*| b)
negateTimesLaws :: Ring a => [Law a]
negateTimesLaws = [leftNegateTimes, rightNegateTimes]
ringLaws :: Ring a => [Law a]
ringLaws =
map fromAdditiveLaw abelianGroupLaws ++
map fromMultiplicativeLaw monoidZeroLaws ++
distributiveLaws ++ negateTimesLaws
commutativeRingLaws :: Ring a => [Law a]
commutativeRingLaws =
fromMultiplicativeLaw commutative : ringLaws
distributiveSubtractionLaws :: Ring a => [Law a]
distributiveSubtractionLaws =
[leftDistributiveFor (|*|) (|-|), rightDistributiveFor (|*|) (|-|)]
exchangeInverses :: Field a => Law a
exchangeInverses = law "exchange-inverses" $ \a ->
timesInverse (plusInverse a) :==: plusInverse (timesInverse a)
fieldLaws :: Field a => [Law a]
fieldLaws =
map fromAdditiveLaw abelianGroupLaws ++
map fromMultiplicativeLaw abelianGroupLaws ++
distributiveLaws ++ negateTimesLaws ++ [exchangeInverses]
fromAdditiveLaw :: Law (Additive a) -> Law a
fromAdditiveLaw = mapLaw Additive fromAdditive
fromMultiplicativeLaw :: Law (Multiplicative a) -> Law a
fromMultiplicativeLaw = mapLaw Multiplicative fromMultiplicative
propsField :: [Property]
propsField = map property (fieldLaws :: [Law (SafeNum Rational)])