summaryrefslogtreecommitdiff
path: root/Algebra/Prelude/Core.hs
blob: 188768552393f41b414a62df0f99c69e9e9f29d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{-# LANGUAGE FlexibleContexts, NoImplicitPrelude, NoMonomorphismRestriction #-}
module Algebra.Prelude.Core
       ((%),Scalar(..),(.*.), od,Ordinal, enumOrdinal,
        logBase2,ceilingLogBase2,
        module AlgebraicPrelude,
        module Algebra.Ring.Polynomial.Internal,
        module Algebra.Ring.Ideal,
        module Algebra.Normed,
        module Algebra.Internal) where

import Algebra.Internal
import Algebra.Normed
import Algebra.Ring.Ideal
import Algebra.Ring.Polynomial.Internal
import Algebra.Scalar

import AlgebraicPrelude          hiding (lex, (%))
import Data.Bits                 (Bits (..), FiniteBits (..))
import Data.Type.Ordinal.Builtin (Ordinal, enumOrdinal, od)

(%) :: (IsPolynomial poly, Division (Coefficient poly))
    => Coefficient poly -> Coefficient poly -> poly
n % m = injectCoeff (n / m)
infixl 7 %

logBase2 :: Int -> Int
logBase2 x = finiteBitSize x - 1 - countLeadingZeros x
{-# INLINE logBase2 #-}

ceilingLogBase2 :: Int -> Int
ceilingLogBase2 n =
  if popCount n == 1
  then logBase2 n
  else logBase2 n + 1