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

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

""" 

Finite dimensional free algebra quotients 

 

REMARK: 

 

This implementation only works for finite dimensional quotients, since 

a list of basis monomials and the multiplication matrices need to be 

explicitly provided. 

 

The homogeneous part of a quotient of a free algebra over a field by a 

finitely generated homogeneous twosided ideal is available in a 

different implementation. See 

:mod:`~sage.algebras.letterplace.free_algebra_letterplace` and 

:mod:`~sage.rings.quotient_ring`. 

 

TESTS:: 

 

sage: n = 2 

sage: A = FreeAlgebra(QQ,n,'x') 

sage: F = A.monoid() 

sage: i, j = F.gens() 

sage: mons = [ F(1), i, j, i*j ] 

sage: r = len(mons) 

sage: M = MatrixSpace(QQ,r) 

sage: mats = [M([0,1,0,0, -1,0,0,0, 0,0,0,-1, 0,0,1,0]), M([0,0,1,0, 0,0,0,1, -1,0,0,0, 0,-1,0,0]) ] 

sage: H2.<i,j> = A.quotient(mons,mats) 

sage: H2 == loads(dumps(H2)) 

True 

sage: i == loads(dumps(i)) 

True 

""" 

 

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

# Copyright (C) 2005 David Kohel <kohel@maths.usyd.edu> 

# 

# 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 

# is available at: 

# 

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

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

 

from sage.modules.free_module import FreeModule 

from sage.algebras.algebra import Algebra 

from sage.algebras.free_algebra import is_FreeAlgebra 

from sage.algebras.free_algebra_quotient_element import FreeAlgebraQuotientElement 

from sage.structure.unique_representation import UniqueRepresentation 

 

class FreeAlgebraQuotient(UniqueRepresentation, Algebra, object): 

@staticmethod 

def __classcall__(cls, A, mons, mats, names): 

""" 

Used to support unique representation. 

 

EXAMPLES:: 

 

sage: H = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0] # indirect doctest 

sage: H1 = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0] 

sage: H is H1 

True 

""" 

new_mats = [] 

for M in mats: 

M = M.parent()(M) 

M.set_immutable() 

new_mats.append(M) 

return super(FreeAlgebraQuotient, cls).__classcall__(cls, A, tuple(mons), 

tuple(new_mats), tuple(names)) 

 

Element = FreeAlgebraQuotientElement 

def __init__(self, A, mons, mats, names): 

""" 

Returns a quotient algebra defined via the action of a free algebra 

A on a (finitely generated) free module. The input for the quotient 

algebra is a list of monomials (in the underlying monoid for A) 

which form a free basis for the module of A, and a list of 

matrices, which give the action of the free generators of A on this 

monomial basis. 

 

EXAMPLES: 

 

Quaternion algebra defined in terms of three generators:: 

 

sage: n = 3 

sage: A = FreeAlgebra(QQ,n,'i') 

sage: F = A.monoid() 

sage: i, j, k = F.gens() 

sage: mons = [ F(1), i, j, k ] 

sage: M = MatrixSpace(QQ,4) 

sage: mats = [M([0,1,0,0, -1,0,0,0, 0,0,0,-1, 0,0,1,0]), M([0,0,1,0, 0,0,0,1, -1,0,0,0, 0,-1,0,0]), M([0,0,0,1, 0,0,-1,0, 0,1,0,0, -1,0,0,0]) ] 

sage: H3.<i,j,k> = FreeAlgebraQuotient(A,mons,mats) 

sage: x = 1 + i + j + k 

sage: x 

1 + i + j + k 

sage: x**128 

-170141183460469231731687303715884105728 + 170141183460469231731687303715884105728*i + 170141183460469231731687303715884105728*j + 170141183460469231731687303715884105728*k 

 

Same algebra defined in terms of two generators, with some penalty 

on already slow arithmetic. 

 

:: 

 

sage: n = 2 

sage: A = FreeAlgebra(QQ,n,'x') 

sage: F = A.monoid() 

sage: i, j = F.gens() 

sage: mons = [ F(1), i, j, i*j ] 

sage: r = len(mons) 

sage: M = MatrixSpace(QQ,r) 

sage: mats = [M([0,1,0,0, -1,0,0,0, 0,0,0,-1, 0,0,1,0]), M([0,0,1,0, 0,0,0,1, -1,0,0,0, 0,-1,0,0]) ] 

sage: H2.<i,j> = A.quotient(mons,mats) 

sage: k = i*j 

sage: x = 1 + i + j + k 

sage: x 

1 + i + j + i*j 

sage: x**128 

-170141183460469231731687303715884105728 + 170141183460469231731687303715884105728*i + 170141183460469231731687303715884105728*j + 170141183460469231731687303715884105728*i*j 

 

TESTS:: 

 

sage: TestSuite(H2).run() 

 

""" 

if not is_FreeAlgebra(A): 

raise TypeError("Argument A must be an algebra.") 

R = A.base_ring() 

# if not R.is_field(): # TODO: why? 

# raise TypeError, "Base ring of argument A must be a field." 

n = A.ngens() 

assert n == len(mats) 

self.__free_algebra = A 

self.__ngens = n 

self.__dim = len(mons) 

self.__module = FreeModule(R,self.__dim) 

self.__matrix_action = mats 

self.__monomial_basis = mons # elements of free monoid 

Algebra.__init__(self, R, names, normalize=True) 

 

def __eq__(self, right): 

""" 

Return True if all defining properties of self and right match up. 

 

EXAMPLES:: 

 

sage: HQ = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0] 

sage: HZ = sage.algebras.free_algebra_quotient.hamilton_quatalg(ZZ)[0] 

sage: HQ == HQ 

True 

sage: HQ == HZ 

False 

sage: HZ == QQ 

False 

""" 

return isinstance(right, FreeAlgebraQuotient) and \ 

self.ngens() == right.ngens() and \ 

self.rank() == right.rank() and \ 

self.module() == right.module() and \ 

self.matrix_action() == right.matrix_action() and \ 

self.monomial_basis() == right.monomial_basis() 

 

 

def _element_constructor_(self, x): 

""" 

EXAMPLES:: 

 

sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ) 

sage: H._element_constructor_(i) is i 

True 

sage: a = H._element_constructor_(1); a 

1 

sage: a in H 

True 

sage: a = H._element_constructor_([1,2,3,4]); a 

1 + 2*i + 3*j + 4*k 

""" 

if isinstance(x, FreeAlgebraQuotientElement) and x.parent() is self: 

return x 

return self.element_class(self,x) 

 

def _coerce_map_from_(self,S): 

""" 

EXAMPLES:: 

 

sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ) 

sage: H._coerce_map_from_(H) 

True 

sage: H._coerce_map_from_(QQ) 

True 

sage: H._coerce_map_from_(GF(7)) 

False 

""" 

return S==self or self.__free_algebra.has_coerce_map_from(S) 

 

def _repr_(self): 

""" 

EXAMPLES:: 

 

sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ) 

sage: H._repr_() 

"Free algebra quotient on 3 generators ('i', 'j', 'k') and dimension 4 over Rational Field" 

""" 

R = self.base_ring() 

n = self.__ngens 

r = self.__module.dimension() 

x = self.variable_names() 

return "Free algebra quotient on %s generators %s and dimension %s over %s"%(n,x,r,R) 

 

def gen(self, i): 

""" 

The i-th generator of the algebra. 

 

EXAMPLES:: 

 

sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ) 

sage: H.gen(0) 

i 

sage: H.gen(2) 

k 

 

An IndexError is raised if an invalid generator is requested:: 

 

sage: H.gen(3) 

Traceback (most recent call last): 

... 

IndexError: Argument i (= 3) must be between 0 and 2. 

 

Negative indexing into the generators is not supported:: 

 

sage: H.gen(-1) 

Traceback (most recent call last): 

... 

IndexError: Argument i (= -1) must be between 0 and 2. 

""" 

n = self.__ngens 

if i < 0 or not i < n: 

raise IndexError("Argument i (= %s) must be between 0 and %s."%(i, n-1)) 

R = self.base_ring() 

F = self.__free_algebra.monoid() 

n = self.__ngens 

return self.element_class(self,{F.gen(i):R(1)}) 

 

def ngens(self): 

""" 

The number of generators of the algebra. 

 

EXAMPLES:: 

 

sage: sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0].ngens() 

3 

""" 

return self.__ngens 

 

def dimension(self): 

""" 

The rank of the algebra (as a free module). 

 

EXAMPLES:: 

 

sage: sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0].dimension() 

4 

""" 

return self.__dim 

 

def matrix_action(self): 

""" 

EXAMPLES:: 

 

sage: sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0].matrix_action() 

( 

[ 0 1 0 0] [ 0 0 1 0] [ 0 0 0 1] 

[-1 0 0 0] [ 0 0 0 1] [ 0 0 -1 0] 

[ 0 0 0 -1] [-1 0 0 0] [ 0 1 0 0] 

[ 0 0 1 0], [ 0 -1 0 0], [-1 0 0 0] 

) 

""" 

return self.__matrix_action 

 

def monomial_basis(self): 

""" 

EXAMPLES:: 

 

sage: sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0].monomial_basis() 

(1, i0, i1, i2) 

""" 

return self.__monomial_basis 

 

def rank(self): 

""" 

The rank of the algebra (as a free module). 

 

EXAMPLES:: 

 

sage: sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0].rank() 

4 

""" 

return self.__dim 

 

def module(self): 

""" 

The free module of the algebra. 

 

sage: H = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0]; H 

Free algebra quotient on 3 generators ('i', 'j', 'k') and dimension 4 over Rational Field 

sage: H.module() 

Vector space of dimension 4 over Rational Field 

""" 

return self.__module 

 

def monoid(self): 

""" 

The free monoid of generators of the algebra. 

 

EXAMPLES:: 

 

sage: sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0].monoid() 

Free monoid on 3 generators (i0, i1, i2) 

""" 

return self.__free_algebra.monoid() 

 

def monomial_basis(self): 

""" 

The free monoid of generators of the algebra as elements of a free 

monoid. 

 

EXAMPLES:: 

 

sage: sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0].monomial_basis() 

(1, i0, i1, i2) 

""" 

return self.__monomial_basis 

 

def free_algebra(self): 

""" 

The free algebra generating the algebra. 

 

EXAMPLES:: 

 

sage: sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0].free_algebra() 

Free Algebra on 3 generators (i0, i1, i2) over Rational Field 

""" 

return self.__free_algebra 

 

 

def hamilton_quatalg(R): 

""" 

Hamilton quaternion algebra over the commutative ring R, 

constructed as a free algebra quotient. 

 

INPUT: 

- R -- a commutative ring 

 

OUTPUT: 

- Q -- quaternion algebra 

- gens -- generators for Q 

 

EXAMPLES:: 

 

sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(ZZ) 

sage: H 

Free algebra quotient on 3 generators ('i', 'j', 'k') and dimension 4 over Integer Ring 

sage: i^2 

-1 

sage: i in H 

True 

 

Note that there is another vastly more efficient models for 

quaternion algebras in Sage; the one here is mainly for testing 

purposes:: 

 

sage: R.<i,j,k> = QuaternionAlgebra(QQ,-1,-1) # much fast than the above 

""" 

n = 3 

from sage.algebras.free_algebra import FreeAlgebra 

from sage.matrix.all import MatrixSpace 

A = FreeAlgebra(R, n, 'i') 

F = A.monoid() 

i, j, k = F.gens() 

mons = [ F(1), i, j, k ] 

M = MatrixSpace(R,4) 

mats = [M([0,1,0,0, -1,0,0,0, 0,0,0,-1, 0,0,1,0]), M([0,0,1,0, 0,0,0,1, -1,0,0,0, 0,-1,0,0]), M([0,0,0,1, 0,0,-1,0, 0,1,0,0, -1,0,0,0]) ] 

H3 = FreeAlgebraQuotient(A,mons,mats, names=('i','j','k')) 

return H3, H3.gens()