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

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

""" 

Base class for abelian group elements 

 

This is the base class for both 

:mod:`~sage.groups.abelian_gps.abelian_group_element` and 

:mod:`~sage.groups.abelian_gps.dual_abelian_group_element`. 

 

As always, elements are immutable once constructed. 

""" 

 

 

########################################################################### 

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

# Copyright (C) 2006 David Joyner <wdjoyner@gmail.com> 

# Copyright (C) 2012 Volker Braun <vbraun.name@gmail.com> 

# 

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

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

########################################################################### 

 

from sage.structure.element import MultiplicativeGroupElement 

from sage.misc.cachefunc import cached_method 

from sage.arith.all import GCD, LCM 

from sage.rings.integer import Integer 

from sage.rings.integer_ring import ZZ 

from sage.rings.infinity import infinity 

from sage.structure.richcmp import richcmp 

 

 

class AbelianGroupElementBase(MultiplicativeGroupElement): 

""" 

Base class for abelian group elements 

 

The group element is defined by a tuple whose ``i``-th entry is an 

integer in the range from 0 (inclusively) to ``G.gen(i).order()`` 

(exclusively) if the `i`-th generator is of finite order, and an 

arbitrary integer if the `i`-th generator is of infinite order. 

 

INPUT: 

 

- ``exponents`` -- ``1`` or a list/tuple/iterable of integers. The 

exponent vector (with respect to the parent generators) defining 

the group element. 

 

- ``parent`` -- Abelian group. The parent of the group element. 

 

EXAMPLES:: 

 

sage: F = AbelianGroup(3,[7,8,9]) 

sage: Fd = F.dual_group(names="ABC") 

sage: A,B,C = Fd.gens() 

sage: A*B^-1 in Fd 

True 

""" 

 

def __init__(self, parent, exponents): 

""" 

Create an element. 

 

EXAMPLES:: 

 

sage: F = AbelianGroup(3,[7,8,9]) 

sage: Fd = F.dual_group(names="ABC") 

sage: A,B,C = Fd.gens() 

sage: A*B^-1 in Fd 

True 

""" 

MultiplicativeGroupElement.__init__(self, parent) 

n = parent.ngens() 

if exponents == 1: 

self._exponents = tuple( ZZ.zero() for i in range(n) ) 

else: 

self._exponents = tuple( ZZ(e) for e in exponents ) 

if len(self._exponents) != n: 

raise IndexError('argument length (= %s) must be %s.'%(len(exponents), n)) 

 

def __hash__(self): 

r""" 

TESTS:: 

 

sage: F = AbelianGroup(3,[7,8,9]) 

sage: hash(F.an_element()) # random 

1024 

""" 

return hash(self.parent()) ^ hash(self._exponents) 

 

def exponents(self): 

""" 

The exponents of the generators defining the group element. 

 

OUTPUT: 

 

A tuple of integers for an abelian group element. The integer 

can be arbitrary if the corresponding generator has infinite 

order. If the generator is of finite order, the integer is in 

the range from 0 (inclusive) to the order (exclusive). 

 

EXAMPLES:: 

 

sage: F.<a,b,c,f> = AbelianGroup([7,8,9,0]) 

sage: (a^3*b^2*c).exponents() 

(3, 2, 1, 0) 

sage: F([3, 2, 1, 0]) 

a^3*b^2*c 

sage: (c^42).exponents() 

(0, 0, 6, 0) 

sage: (f^42).exponents() 

(0, 0, 0, 42) 

""" 

return self._exponents 

 

def list(self): 

""" 

Return a copy of the exponent vector. 

 

Use :meth:`exponents` instead. 

 

OUTPUT: 

 

The underlying coordinates used to represent this element. If 

this is a word in an abelian group on `n` generators, then 

this is a list of nonnegative integers of length `n`. 

 

EXAMPLES:: 

 

sage: F = AbelianGroup(5,[2, 3, 5, 7, 8], names="abcde") 

sage: a,b,c,d,e = F.gens() 

sage: Ad = F.dual_group(names="ABCDE") 

sage: A,B,C,D,E = Ad.gens() 

sage: (A*B*C^2*D^20*E^65).exponents() 

(1, 1, 2, 6, 1) 

sage: X = A*B*C^2*D^2*E^-6 

sage: X.exponents() 

(1, 1, 2, 2, 2) 

""" 

# to be deprecated (really, return a list??). Use exponents() instead. 

return list(self._exponents) 

 

def _repr_(self): 

""" 

Return a string representation of ``self``. 

 

OUTPUT: 

 

String. 

 

EXAMPLES:: 

 

sage: G = AbelianGroup([2]) 

sage: G.gen(0)._repr_() 

'f' 

sage: G.one()._repr_() 

'1' 

""" 

s = "" 

G = self.parent() 

for v_i, x_i in zip(self.exponents(), G.variable_names()): 

if v_i == 0: 

continue 

if len(s) > 0: 

s += '*' 

if v_i == 1: 

s += str(x_i) 

else: 

s += str(x_i) + '^' + str(v_i) 

if s: 

return s 

else: 

return '1' 

 

def _richcmp_(self, other, op): 

""" 

Compare ``self`` and ``other``. 

 

The comparison is based on the exponents. 

 

OUTPUT: 

 

boolean 

 

EXAMPLES:: 

 

sage: G.<a,b> = AbelianGroup([2,3]) 

sage: a > b 

True 

 

sage: Gd.<A,B> = G.dual_group() 

sage: A > B 

True 

""" 

return richcmp(self._exponents, other._exponents, op) 

 

@cached_method 

def order(self): 

""" 

Return the order of this element. 

 

OUTPUT: 

 

An integer or ``infinity``. 

 

EXAMPLES:: 

 

sage: F = AbelianGroup(3,[7,8,9]) 

sage: Fd = F.dual_group() 

sage: A,B,C = Fd.gens() 

sage: (B*C).order() 

72 

 

sage: F = AbelianGroup(3,[7,8,9]); F 

Multiplicative Abelian group isomorphic to C7 x C8 x C9 

sage: F.gens()[2].order() 

9 

sage: a,b,c = F.gens() 

sage: (b*c).order() 

72 

sage: G = AbelianGroup(3,[7,8,9]) 

sage: type((G.0 * G.1).order())==Integer 

True 

""" 

M = self.parent() 

order = M.gens_orders() 

L = self.exponents() 

N = LCM([order[i]/GCD(order[i],L[i]) for i in range(len(order)) if L[i]!=0]) 

if N == 0: 

return infinity 

else: 

return ZZ(N) 

 

multiplicative_order = order 

 

def _div_(left, right): 

""" 

Divide ``left`` and ``right`` 

 

TESTS:: 

 

sage: G.<a,b> = AbelianGroup(2) 

sage: a/b 

a*b^-1 

sage: a._div_(b) 

a*b^-1 

""" 

G = left.parent() 

assert G is right.parent() 

exponents = [ (x-y)%order if order!=0 else x-y 

for x, y, order in 

zip(left._exponents, right._exponents, G.gens_orders()) ] 

return G.element_class(G, exponents) 

 

def _mul_(left, right): 

""" 

Multiply ``left`` and ``right`` 

 

TESTS:: 

 

sage: G.<a,b> = AbelianGroup(2) 

sage: a*b 

a*b 

sage: a._mul_(b) 

a*b 

""" 

G = left.parent() 

assert G is right.parent() 

exponents = [ (x+y)%order if order!=0 else x+y 

for x, y, order in 

zip(left._exponents, right._exponents, G.gens_orders()) ] 

return G.element_class(G, exponents) 

 

def __pow__(self, n): 

""" 

Exponentiate ``self`` 

 

TESTS:: 

 

sage: G.<a,b> = AbelianGroup(2) 

sage: a^3 

a^3 

""" 

m = Integer(n) 

if n != m: 

raise TypeError('argument n (= '+str(n)+') must be an integer.') 

G = self.parent() 

exponents = [ (m*e) % order if order!=0 else m*e 

for e,order in zip(self._exponents, G.gens_orders()) ] 

return G.element_class(G, exponents) 

 

def inverse(self): 

""" 

Returns the inverse element. 

 

EXAMPLES:: 

 

sage: G.<a,b> = AbelianGroup([0,5]) 

sage: a.inverse() 

a^-1 

sage: a.__invert__() 

a^-1 

sage: a^-1 

a^-1 

sage: ~a 

a^-1 

sage: (a*b).exponents() 

(1, 1) 

sage: (a*b).inverse().exponents() 

(-1, 4) 

""" 

G = self.parent() 

exponents = [ (-e)%order if order!=0 else -e 

for e,order in zip(self._exponents, G.gens_orders()) ] 

return G.element_class(G, exponents) 

 

__invert__ = inverse 

 

def is_trivial(self): 

""" 

Test whether ``self`` is the trivial group element ``1``. 

 

OUTPUT: 

 

Boolean. 

 

EXAMPLES:: 

 

sage: G.<a,b> = AbelianGroup([0,5]) 

sage: (a^5).is_trivial() 

False 

sage: (b^5).is_trivial() 

True 

""" 

return all(e==0 for e in self._exponents)