packages feed

fast-combinatorics 0.1.0.5 → 0.1.0.6

raw patch · 7 files changed

+67/−28 lines, 7 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Numeric.Combinatorics: isPrime :: Int -> Bool
+ Numeric.Integer: isPrime :: Int -> Bool

Files

+ ats-src/number-theory-ffi.dats view
@@ -0,0 +1,11 @@+#define ATS_MAINATSFLAG 1++#include "share/atspre_staload.hats"+#include "ats-src/number-theory.dats"++extern+fun mod(int, int) : int =+  "mac#"++implement mod (m, n) =+  m % n
+ ats-src/number-theory.dats view
@@ -0,0 +1,11 @@+#define ATS_MAINATSFLAG 1++#include "share/atspre_staload.hats"++staload "libats/libc/SATS/math.sats"++fun is_even(n : int) : bool =+  n % 2 = 0++fun is_odd(n : int) : bool =+  n % 2 = 1
cbits/combinatorics-ffi.c view
@@ -1,7 +1,7 @@ /* ** ** The C code is generated by [ATS/Postiats-0-3-8]-** The starting compilation time is: 2017-12-31:  0h:12m+** The starting compilation time is: 2017-12-31:  1h: 4m ** */ 
cbits/numerics-ffi.c view
@@ -1,7 +1,7 @@ /* ** ** The C code is generated by [ATS/Postiats-0-3-8]-** The starting compilation time is: 2017-12-31:  0h:12m+** The starting compilation time is: 2017-12-31:  1h:12m ** */ 
fast-combinatorics.cabal view
@@ -1,5 +1,5 @@ name:                fast-combinatorics-version:             0.1.0.5+version:             0.1.0.6 synopsis:            Fast combinatorics. description:         Fast combinatorics code with a high level of safety guaranteed by writing it in ATS. homepage:            https://github.com//fast-combinatorics#readme
src/Numeric/Combinatorics.hs view
@@ -1,48 +1,32 @@-{-# LANGUAGE CPP                      #-} {-# LANGUAGE ForeignFunctionInterface #-} +{-|+Module      : Numeric.Combinatorics+Description : Fast computation of common combinatorial functions.+Copyright   : Copyright (c) 2017 Vanessa McHale++-}+ module Numeric.Combinatorics     ( factorial     , choose     , doubleFactorial-    , isPrime     ) where  import           Control.Composition-import           Data.Word import           Foreign.C  foreign import ccall unsafe factorial_ats :: CInt -> CInt foreign import ccall unsafe choose_ats :: CInt -> CInt -> CInt foreign import ccall unsafe double_factorial :: CInt -> CInt-#if __GLASGOW_HASKELL__ >= 820-foreign import ccall unsafe is_prime_ats :: CInt -> CBool-#else-foreign import ccall unsafe is_prime_ats :: CInt -> CUChar-#endif -#if __GLASGOW_HASKELL__ >= 820-convertBool :: CBool -> Bool-#else-convertBool :: CUChar -> Bool-#endif-convertBool = go . fromIntegral-    where-        go :: Word8 -> Bool-        go 0 = False-        go 1 = True-        go _ = False--isPrime :: Int -> Bool-isPrime = convertBool . is_prime_ats . fromIntegral--{-@ choose :: { n : Nat | n >= 0 } -> { k : Nat | k >= 0 && k <= n } -> Int @-}+-- | See [here](http://mathworld.wolfram.com/BinomialCoefficient.html). choose :: Int -> Int -> Int choose = fromIntegral .* on choose_ats fromIntegral +-- | See [here](http://mathworld.wolfram.com/DoubleFactorial.html). doubleFactorial :: Int -> Int doubleFactorial = fromIntegral . double_factorial . fromIntegral -{-@ factorial :: { n : Nat | n <= 0 } -> Int @-} factorial :: Int -> Int factorial = fromIntegral . factorial_ats . fromIntegral
src/Numeric/Integer.hs view
@@ -1,10 +1,43 @@+{-# LANGUAGE CPP #-}++{-|+Module      : Numeric.Combinatorics+Description : Fast computation of common functions on integers.+Copyright   : Copyright (c) 2017 Vanessa McHale++-}+ module Numeric.Integer ( integerExp+                       , isPrime                        ) where  import           Control.Composition+import           Data.Word import           Foreign.C  foreign import ccall unsafe exp_ats :: CInt -> CInt -> CInt+#if __GLASGOW_HASKELL__ >= 820+foreign import ccall unsafe is_prime_ats :: CInt -> CBool+#else+foreign import ccall unsafe is_prime_ats :: CInt -> CUChar+#endif +#if __GLASGOW_HASKELL__ >= 820+convertBool :: CBool -> Bool+#else+convertBool :: CUChar -> Bool+#endif+convertBool = go . fromIntegral+    where+        go :: Word8 -> Bool+        go 0 = False+        go 1 = True+        go _ = False++-- | O(√n)+isPrime :: Int -> Bool+isPrime = convertBool . is_prime_ats . fromIntegral++-- | Note that both arguments must be positive. O(log(n)) in the exponent. integerExp :: Int -> Int -> Int integerExp = fromIntegral .* on exp_ats fromIntegral