Skip to content

Commit

Permalink
Give degree and splitUnit default implementations for Division
Browse files Browse the repository at this point in the history
…instances
  • Loading branch information
dfoxfranke committed Dec 7, 2014
1 parent af4ae27 commit 9ce4698
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Numeric/Algebra/Unital/UnitNormalForm.hs
@@ -1,9 +1,15 @@
{-# LANGUAGE DefaultSignatures #-}
module Numeric.Algebra.Unital.UnitNormalForm
(UnitNormalForm(..), normalize, leadingUnit) where

import Numeric.Algebra.Class
import Numeric.Algebra.Division
import Numeric.Algebra.Unital
import Numeric.Decidable.Units
import Numeric.Decidable.Associates
import Prelude(Integer,signum,abs,fst,snd,(.))
import Numeric.Decidable.Zero
import Numeric.Semiring.ZeroProduct
import Prelude(Integer,signum,abs,fst,snd,(.), otherwise)

class (DecidableUnits r, DecidableAssociates r) => UnitNormalForm r where
-- prop> let (u,n) = splitUnit r
Expand All @@ -13,6 +19,9 @@ class (DecidableUnits r, DecidableAssociates r) => UnitNormalForm r where
-- (isAssociate r r' ==> n = n') &&
-- splitUnit (r * r') = (u * u', n * n')
splitUnit :: r -> (r,r)
default splitUnit :: (Division r, ZeroProductSemiring r, DecidableZero r) => r -> (r,r)
splitUnit x | isZero x = (one,zero)
| otherwise = (x,one)

instance UnitNormalForm Integer where
splitUnit 0 = (1, 0)
Expand Down
3 changes: 3 additions & 0 deletions src/Numeric/Domain/Internal.hs
Expand Up @@ -71,6 +71,9 @@ instance PID Integer
class (PID d) => Euclidean d where
-- | Euclidean (degree) function on @r@.
degree :: d -> Maybe Natural
default degree :: (Division d) => d -> Maybe Natural
degree a | isZero a = Nothing
| otherwise = Just zero
-- | Division algorithm. @a `divide` b@ calculates
-- quotient and reminder of @a@ divided by @b@.
--
Expand Down

0 comments on commit 9ce4698

Please sign in to comment.