Commit cfcf94ae authored by Simon Marlow's avatar Simon Marlow

update to version from Seq no More paper

parent ebb8287d
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
TOP = ../..
include $(TOP)/mk/boilerplate.mk
SRC_HC_OPTS += -cpp
SRC_HC_OPTS += -cpp -DSTRATEGIES -package random -package parallel
# 28 = version
# 83 = input
PROG_ARGS = 28 83
include $(TOP)/mk/target.mk
This diff is collapsed.
{-
$Id: ModArithm.hs,v 1.1 1996/01/08 20:07:35 partain Exp $
-- Time-stamp: <Sat Jun 05 2010 01:37:17 Stardate: Stardate: [-28]3175.12 hwloidl>
--
-- Modular Arithmetic over Z_p
-----------------------------------------------------------------------------
This is revision: $Revision: 1.1 $
-- @node Modular Arithmetic, ADT Matrix, Top, Top
-- @chapter Modular Arithmetic
Modular Arithmetic over Integrals with definition of Hom class.
Changelog:
$Log: ModArithm.hs,v $
Revision 1.1 1996/01/08 20:07:35 partain
Initial revision
--# Revision 1.2 1994/11/19 21:50:17 hwloidl
--# *** empty log message ***
--#
--# Revision 1.1 1994/11/19 02:00:05 hwloidl
--# Initial revision
--#
--# Revision 1.1 1994/11/19 02:00:05 hwloidl
--# Initial revision
--#
---------------------------------------------------------------------- -}
module ModArithm(modHom, modSum, modDif, modProd, modInv {-, Hom(hom) -} ) where
module ModArithm (modHom, modSum, modDif, modProd, modQuot, modInv
{-, Hom(hom) -} ) where
{-# SPECIALISE
modHom :: Int -> Int -> Int
#-}
modHom :: (Integral a) => a -> a -> a
modHom m x = x `mod` m
mapMod :: (Integral a) => (a -> a -> a) -> a -> a -> a -> a
mapMod f m x y = modHom m (f x y)
{-# SPECIALISE
modSum :: Int -> Int -> Int -> Int
#-}
modSum :: (Integral a) => a -> a -> a -> a
modSum = mapMod (+)
{-# SPECIALISE
modDif :: Int -> Int -> Int -> Int
#-}
modDif :: (Integral a) => a -> a -> a -> a
modDif = mapMod (-)
{-# SPECIALISE
modProd :: Int -> Int -> Int -> Int
#-}
modProd :: (Integral a) => a -> a -> a -> a
modProd = mapMod (*)
modInv _ 0 = 0
{-# SPECIALISE
modQuot :: Int -> Int -> Int -> Int
#-}
modQuot :: (Integral a) => a -> a -> a -> a
modQuot m x y = modProd m x (modInv m y)
{-# SPECIALISE
modInv :: Int -> Int -> Int
#-}
modInv :: (Integral a) => a -> a -> a
modInv m x = let
(g,_,inv) = gcdCF m x
(g,foo,inv) = gcdCF m x
in
if (g /= 1)
then error ("modInv: Input values are not relative prime:\n " ++ (show m) ++ "\n " ++ (show x) ++"\n")
then modHom m inv -- error $ "modInv: Input values " ++ (show (m,x)) ++ " are not relative prime!" ++ ("** Wrong GCD res: gcd= " ++ (show g) ++ "; but x*a+y*b= " ++ (show (m*foo+x*inv)))
else modHom m inv
gcdCF_with_check x y =
let
res@(g,a,b) = gcdCF x y
in
if check_gcdCF x y res
then res
else error ("** Wrong GCD res: gcd= " ++ (show g) ++ "; but x*a+y*b= " ++ (show (x*a+y*b)))
{-# SPECIALISE
gcdCF :: Int -> Int -> (Int,Int,Int)
#-}
gcdCF :: (Integral a) => a -> a -> (a,a,a)
gcdCF x y = gcdCF' x y 1 0 0 1
where gcdCF' x 0 x1 x2 _ _ = (x,x1,x2)
gcdCF' x y x1 x2 y1 y2 | x<y = gcdCF' y x y1 y2 x1 x2
......@@ -57,30 +77,8 @@ gcdCF x y = gcdCF' x y 1 0 0 1
gcdCF' y z y1 y2 z1 z2
{- Main for testing gcdCF!
main = let
l1 = [7, 12, 62, 54, 55]
l2 = [3, 9, 30, 48, 15]
l = map ( \ (x,y) -> gcdCF x y ) (zip l1 l2)
showTuple (z,x,y) = "(gcd: " ++ show z ++ " Cofactors: " ++ show x ++
" , " ++ show y ++ " )\n"
lshow = foldl (++) "" (map showTuple l)
in
appendChan stdout ("First list: " ++ (showList l1
"\nSecond List: " ++ (showList l2
"\nResult: \n" ++ lshow)))
abort done
-}
-- ---------------------------------------------------------------------------
{-
class Hom b where
hom :: Integer -> b -> b
instance Hom Integer where
hom = modHom
--hom m x = x `mod` m
check_gcdCF :: (Integral a) => a -> a -> (a,a,a) -> Bool
check_gcdCF x y (g,a,b) = if (x*a+y*b)==g
then True
else False
-}
\ No newline at end of file
{-
$Id: ParForce.hs,v 1.1 1996/01/08 20:07:35 partain Exp $
This is revision: $Revision: 1.1 $
Module for forcing parallelism using par and friends.
Changelog:
$Log: ParForce.hs,v $
Revision 1.1 1996/01/08 20:07:35 partain
Initial revision
--# Revision 1.3 1994/11/23 01:07:23 hwloidl
--# Version for testing fwd mapping and hom sol.
--#
--# Revision 1.2 1994/11/19 21:50:18 hwloidl
--# *** empty log message ***
--#
--# Revision 1.1 1994/11/19 02:00:05 hwloidl
--# Initial revision
--#
--# Revision 1.1 1994/11/19 02:00:05 hwloidl
--# Initial revision
--#
---------------------------------------------------------------------- -}
module ParForce (parmap, parmap1, forcelist, forcelist1, par_iterate,
par_zip, par_zipWith) where
#ifdef SEQ
par :: a -> b -> b
par x y = y
seq :: a -> b -> b
seq x y = y
_parGlobal_ :: Int# -> a -> b -> b
_parGlobal_ n x y = y
#else
import {-fool mkdependHS; ToDo: rm-}
Parallel
#endif
#ifdef GUM
-- GUM has only par
_parGlobal_ :: Int# -> a -> b -> b
_parGlobal_ n x y = par x y
_parLocal_ :: Int# -> a -> b -> b
_parLocal_ n x y = par x y
#endif
forcelist [] = ()
forcelist (x:xs) = seq x (forcelist xs)
forcelist1 0 (x:xs) = ()
forcelist1 n (x:xs) = seq x (forcelist1 (n-1) xs)
parmap f [] = []
parmap f (x:xs) = _parGlobal_ 1# fx
( _parGlobal_ 6# (forcelist pmxs)
(fx:pmxs) )
where fx = f x
pmxs = parmap f xs
parmap1 f l = parmap' l
where parmap' [] = []
parmap' (x:xs) = _parGlobal_ 1#
pmxs
(_parGlobal_ 2#
fx
(fx:pmxs) )
where fx = f x
pmxs = parmap' xs
par_iterate :: (a -> a) -> a -> [a]
par_iterate f x = _parGlobal_ 13# fx
{- _parGlobal_ 14# (forcelist rest) -}
(fx : rest)
where fx = f x
rest = par_iterate f (f x)
par_zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
par_zipWith z (a:as) (b:bs) = _parGlobal_ 15# zab
(_parGlobal_ 16# (forcelist rest)
(zab : rest)
)
where zab = z a b
rest = par_zipWith z as bs
par_zipWith _ _ _ = []
par_zip :: [a] -> [b] -> [(a,b)]
par_zip = par_zipWith (\ a b -> (a,b))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment