Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

""" 

Pure python code for abstract base class for objects with generators 

""" 

 

#***************************************************************************** 

# Copyright (C) 2005 William Stein <wstein@gmail.com> 

# 

# Distributed under the terms of the GNU General Public License (GPL) 

# 

# This code is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 

# General Public License for more details. 

# 

# The full text of the GPL is available at: 

# 

# http://www.gnu.org/licenses/ 

#***************************************************************************** 

 

 

def multiplicative_iterator(M): 

from sage.rings.all import infinity 

G = M.gens() 

if len(G) == 0: 

yield M(1) 

return 

 

stop = [g.multiplicative_order() for g in G] 

for i in range(len(stop)): 

if stop[i] is infinity: 

raise ArithmeticError("%s is not finite."%M) 

stop[i] = stop[i] - 1 

n = 0 

z = M(1) 

yield z 

cnt = [0] * len(G) 

while cnt != stop: 

z = z * G[0] 

cnt[0] = cnt[0] + 1 

i = 0 

while i < len(cnt)-1 and cnt[i] > stop[i]: 

cnt[i] = 0 

cnt[i+1] = cnt[i+1] + 1 

z = z * G[i+1] 

i = i + 1 

yield z 

 

def abelian_iterator(M): 

from sage.rings.all import infinity 

G = M.gens() 

if len(G) == 0: 

yield M(0) 

return 

 

stop = [g.additive_order() for g in G] 

for i in range(len(stop)): 

if stop[i] is infinity: 

raise ArithmeticError("%s is not finite."%M) 

stop[i] = stop[i] - 1 

n = 0 

z = M(0) 

yield z 

cnt = [0] * len(G) 

while cnt != stop: 

cnt[0] = cnt[0] + 1 

z = z + G[0] 

i = 0 

while i < len(cnt)-1 and cnt[i] > stop[i]: 

cnt[i] = 0 

cnt[i+1] = cnt[i+1] + 1 

z = z + G[i+1] 

i = i + 1 

yield z