Execution speed

Clifford J. Nelson nelsoncj@gte.net
Fri, 25 Dec 1998 12:40:47 -0800


I am too new at Clean programming to guess how to speed up the following program. Start = test n
will work correctly when n is a prime number if 2 is a quadratic non-residue of n (none of the
second powers of the integers 1 to n-1 (mod n) is congruent to 2). divide x x is supposed to give
all ones except the last coordinate.

I am trying to convert the stuff I did in Mathematica to Clean.

See:

http://forum.swarthmore.edu/epigone/geometry-research/brydilyum

Any pointers about how to speed the program up would be appreciated.

    Cliff Nelson

Program follows:

module Bnumbersm2

import StdEnv

::B :== {#Int}

times:: B B -> B
times a b =  {(inn r) \\ r <- [0..size a -1]}
where
 inn r = innerab 0 1
 where
  innerab acc j 
  | j > (size a) =  acc
  | otherwise = innerab  (acc bitxor ((a.[(size a+r-j)mod(size a)])bitand(b.[j-1]))) (j+1)

divide:: B B -> B
divide a b = times a (inverse b)

inverse:: B -> B
inverse a = ProductofEigenvalues (eigenvalue 2) 3
where
 ProductofEigenvalues:: B Int -> B
 ProductofEigenvalues acc n 
 | n == size a = acc
 | otherwise = ProductofEigenvalues (times acc (eigenvalue n )) (n+1)
 
 eigenvalue:: Int -> B
 eigenvalue n = {a.[(n*r-1)mod(size a)] \\ r <- [1..size a]}
  
testnumber n = {x \\ x <- (flatten (repeatn ((n-1)/2) [1, 0]))++[((n-1)/2) mod 2]}
unity n = {x \\ x <- ((repeatn (n-1) 1) ++ [0])}
timesinverse x = divide x x
test n = timesinverse (testnumber n)   

Start =  test 97