File: cyclotomic.py

package info (click to toggle)
saml 970418-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,204 kB
  • ctags: 1,701
  • sloc: ansic: 17,182; sh: 2,583; yacc: 497; perl: 264; makefile: 250; python: 242
file content (35 lines) | stat: -rwxr-xr-x 736 bytes parent folder | download | duplicates (3)
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
35
#!/usr/bin/python

from saml1 import *

class CyclotomicClass:

  def __init__(self, literal):
    self.dict = {}
    self.X = literal

  def __getitem__(self, number):
    # Already computed ?
    if self.dict.has_key(number):
      return self.dict[number]

    # No, compute it
    result = self.X.pow(number) - 1
    for i in range(1,number):
      if (number % i) == 0:
        result = result / self[i]

    # Memoize the result
    self.dict[number] = result
    return result

def test(list):
  model = Mathnode(ST_INTEGER,'0').cast(ST_APOLY)
  X = model.parse('X')
  CCX = CyclotomicClass(X)
  for n in list:
    print `n` + '\t' + `CCX[n]`

if __name__ == '__main__':
  test((1,2,3,4,5,6,20,30,60,100))
  print MnAllocStats()