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

r""" 

Quotients of Modules With Basis 

""" 

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

# Copyright (C) 2010-2015 Florent Hivert <Florent.Hivert@univ-mlv.fr> 

# 

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

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

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

 

from sage.sets.family import Family 

from sage.combinat.free_module import CombinatorialFreeModule 

from sage.misc.lazy_attribute import lazy_attribute 

from sage.categories.all import ModulesWithBasis 

 

class QuotientModuleWithBasis(CombinatorialFreeModule): 

r""" 

A class for quotients of a module with basis by a submodule. 

 

INPUT: 

 

- ``submodule`` -- a submodule of ``self`` 

- ``category`` -- a category (default: ``ModulesWithBasis(submodule.base_ring())``) 

 

``submodule`` should be a free submodule admitting a basis in 

unitriangular echelon form. Typically ``submodule`` is a 

:class:`SubmoduleWithBasis` as returned by 

:meth:`Modules.WithBasis.ParentMethods.submodule`. 

 

The ``lift`` method should have a method 

``.cokernel_basis_indices`` that computes the indexing set of a 

subset `B` of the basis of ``self`` that spans some supplementary 

of ``submodule`` in ``self`` (typically the non characteristic 

columns of the aforementioned echelon form). ``submodule`` should 

further implement a ``submodule.reduce(x)`` method that returns 

the unique element in the span of `B` which is equivalent to `x` 

modulo ``submodule``. 

 

This is meant to be constructed via 

:meth:`Modules.WithBasis.FiniteDimensional.ParentMethods.quotient_module` 

 

This differs from :class:`sage.rings.quotient_ring.QuotientRing` 

in the following ways: 

 

- ``submodule`` needs not be an ideal. If it is, the 

transportation of the ring structure is taken care of by the 

``Subquotients`` categories. 

 

- Thanks to ``.cokernel_basis_indices``, we know the indices of a 

basis of the quotient, and elements are represented directly in 

the free module spanned by those indices rather than by wrapping 

elements of the ambient space. 

 

There is room for sharing more code between those two 

implementations and generalizing them. See :trac:`18204`. 

 

.. SEEALSO:: 

 

- :meth:`Modules.WithBasis.ParentMethods.submodule` 

- :meth:`Modules.WithBasis.FiniteDimensional.ParentMethods.quotient_module` 

- :class:`SubmoduleWithBasis` 

- :class:`sage.rings.quotient_ring.QuotientRing` 

""" 

@staticmethod 

def __classcall_private__(cls, submodule, category=None): 

r""" 

Normalize the input. 

 

TESTS:: 

 

sage: from sage.modules.with_basis.subquotient import QuotientModuleWithBasis 

sage: X = CombinatorialFreeModule(QQ, range(3)); x = X.basis() 

sage: I = X.submodule( (x[0]-x[1], x[1]-x[2]) ) 

sage: J1 = QuotientModuleWithBasis(I) 

sage: J2 = QuotientModuleWithBasis(I, category=Modules(QQ).WithBasis().Quotients()) 

sage: J1 is J2 

True 

""" 

default_category = ModulesWithBasis(submodule.category().base_ring()).Quotients() 

category = default_category.or_subcategory(category, join=True) 

return super(QuotientModuleWithBasis, cls).__classcall__( 

cls, submodule, category) 

 

def __init__(self, submodule, category): 

r""" 

Initialize this quotient of a module with basis by a submodule. 

 

TESTS:: 

 

sage: from sage.modules.with_basis.subquotient import QuotientModuleWithBasis 

sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x"); x = X.basis() 

sage: I = X.submodule( (x[0]-x[1], x[1]-x[2]) ) 

sage: Y = QuotientModuleWithBasis(I) 

sage: Y.print_options(prefix='y') 

sage: Y 

Free module generated by {2} over Rational Field 

sage: Y.category() 

Join of Category of finite dimensional modules with basis over Rational Field and Category of vector spaces with basis over Rational Field and Category of quotients of sets 

sage: Y.basis().list() 

[y[2]] 

sage: TestSuite(Y).run() 

""" 

self._submodule = submodule 

self._ambient = submodule.ambient() 

embedding = submodule.lift 

indices = embedding.cokernel_basis_indices() 

CombinatorialFreeModule.__init__(self, 

submodule.base_ring(), indices, 

category=category) 

 

def ambient(self): 

r""" 

Return the ambient space of ``self``. 

 

EXAMPLES:: 

 

sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x"); x = X.basis() 

sage: Y = X.quotient_module((x[0]-x[1], x[1]-x[2])) 

sage: Y.ambient() is X 

True 

""" 

return self._ambient 

 

def lift(self, x): 

r""" 

Lift ``x`` to the ambient space of ``self``. 

 

INPUT: 

 

- ``x`` -- an element of ``self`` 

 

EXAMPLES:: 

 

sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x"); x = X.basis() 

sage: Y = X.quotient_module((x[0]-x[1], x[1]-x[2])); y = Y.basis() 

sage: Y.lift(y[2]) 

x[2] 

""" 

assert x in self 

return self.ambient()._from_dict(x._monomial_coefficients) 

 

def retract(self, x): 

r""" 

Retract an element of the ambient space by projecting it back to ``self``. 

 

INPUT: 

 

- ``x`` -- an element of the ambient space of ``self`` 

 

EXAMPLES:: 

 

sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x"); x = X.basis() 

sage: Y = X.quotient_module((x[0]-x[1], x[1]-x[2])); y = Y.basis() 

sage: Y.print_options(prefix='y') 

sage: Y.retract(x[0]) 

y[2] 

sage: Y.retract(x[1]) 

y[2] 

sage: Y.retract(x[2]) 

y[2] 

""" 

return self._from_dict(self._submodule.reduce(x)._monomial_coefficients) 

 

 

class SubmoduleWithBasis(CombinatorialFreeModule): 

r""" 

A base class for submodules of a ModuleWithBasis spanned by a 

(possibly infinite) basis in echelon form. 

 

INPUT: 

 

- ``basis`` -- a family of elements in echelon form in some 

:class:`module with basis <ModulesWithBasis>` `V`, or data that 

can be converted into such a family 

 

- ``unitriangular`` -- if the lift morphism is unitriangular 

 

- ``ambient`` -- the ambient space `V` 

 

- ``category`` -- a category 

 

Further arguments are passed down to 

:class:`CombinatorialFreeModule`. 

 

This is meant to be constructed via 

:meth:`Modules.WithBasis.ParentMethods.submodule`. 

 

.. SEEALSO:: 

 

- :meth:`Modules.WithBasis.ParentMethods.submodule` 

- :class:`QuotientModuleWithBasis` 

""" 

 

@staticmethod 

def __classcall_private__(cls, basis, ambient=None, unitriangular=False, 

category=None, *args, **opts): 

r""" 

Normalize the input. 

 

TESTS:: 

 

sage: from sage.modules.with_basis.subquotient import SubmoduleWithBasis 

sage: X = CombinatorialFreeModule(QQ, range(3)); x = X.basis() 

sage: Y1 = SubmoduleWithBasis((x[0]-x[1], x[1]-x[2]), X) 

sage: Y2 = SubmoduleWithBasis([x[0]-x[1], x[1]-x[2]], X) 

sage: Y1 is Y2 

True 

""" 

basis = Family(basis) 

if ambient is None: 

ambient = basis.an_element().parent() 

default_category = ModulesWithBasis(ambient.category().base_ring()).Subobjects() 

category = default_category.or_subcategory(category, join=True) 

return super(SubmoduleWithBasis, cls).__classcall__( 

cls, basis, ambient, unitriangular, category, *args, **opts) 

 

def __init__(self, basis, ambient, unitriangular, category): 

r""" 

Initialization. 

 

TESTS:: 

 

sage: from sage.modules.with_basis.subquotient import SubmoduleWithBasis 

sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x"); x = X.basis() 

sage: ybas = (x[0]-x[1], x[1]-x[2]) 

sage: Y = SubmoduleWithBasis(ybas, X) 

sage: Y.print_options(prefix='y') 

sage: Y.basis().list() 

[y[0], y[1]] 

sage: [ y.lift() for y in Y.basis() ] 

[x[0] - x[1], x[1] - x[2]] 

sage: TestSuite(Y).run() 

""" 

import operator 

ring = ambient.base_ring() 

CombinatorialFreeModule.__init__(self, ring, basis.keys(), 

category=category.Subobjects()) 

self._ambient = ambient 

self._basis = basis 

self._unitriangular = unitriangular 

self.lift_on_basis = self._basis.__getitem__ 

 

def ambient(self): 

""" 

Return the ambient space of ``self``. 

 

EXAMPLES:: 

 

sage: X = CombinatorialFreeModule(QQ, range(3)); x = X.basis() 

sage: Y = X.submodule((x[0]-x[1], x[1]-x[2])) 

sage: Y.ambient() is X 

True 

""" 

return self._ambient 

 

@lazy_attribute 

def lift(self): 

r""" 

The lift (embedding) map from ``self`` to the ambient space. 

 

EXAMPLES:: 

 

sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x"); x = X.basis() 

sage: Y = X.submodule((x[0]-x[1], x[1]-x[2]), already_echelonized=True); y = Y.basis() 

sage: Y.lift 

Generic morphism: 

From: Free module generated by {0, 1} over Rational Field 

To: Free module generated by {0, 1, 2} over Rational Field 

sage: [ Y.lift(u) for u in y ] 

[x[0] - x[1], x[1] - x[2]] 

sage: (y[0] + y[1]).lift() 

x[0] - x[2] 

""" 

return self.module_morphism(self.lift_on_basis, 

codomain=self.ambient(), 

triangular="lower", 

unitriangular=self._unitriangular, 

key=self.ambient().get_order_key(), 

inverse_on_support="compute") 

 

@lazy_attribute 

def reduce(self): 

r""" 

The reduce map. 

 

This map reduces elements of the ambient space modulo this 

submodule. 

 

EXAMPLES:: 

 

sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x"); x = X.basis() 

sage: Y = X.submodule((x[0]-x[1], x[1]-x[2]), already_echelonized=True) 

sage: Y.reduce 

Generic endomorphism of Free module generated by {0, 1, 2} over Rational Field 

sage: Y.reduce(x[1]) 

x[2] 

sage: Y.reduce(2*x[0] + x[1]) 

3*x[2] 

 

TESTS:: 

 

sage: all( Y.reduce(u.lift()) == 0 for u in Y.basis() ) 

True 

""" 

return self.lift.cokernel_projection() 

 

@lazy_attribute 

def retract(self): 

r""" 

The retract map from the ambient space. 

 

EXAMPLES:: 

 

sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x"); x = X.basis() 

sage: Y = X.submodule((x[0]-x[1], x[1]-x[2]), already_echelonized=True) 

sage: Y.print_options(prefix='y') 

sage: Y.retract 

Generic morphism: 

From: Free module generated by {0, 1, 2} over Rational Field 

To: Free module generated by {0, 1} over Rational Field 

sage: Y.retract(x[0] - x[2]) 

y[0] + y[1] 

 

TESTS:: 

 

sage: all( Y.retract(u.lift()) == u for u in Y.basis() ) 

True 

""" 

return self.lift.section() 

 

def is_submodule(self, other): 

""" 

Return whether ``self`` is a submodule of ``other``. 

 

INPUT: 

 

- ``other`` -- another submodule of the same ambient module, or the ambient module itself 

 

EXAMPLES:: 

 

sage: X = CombinatorialFreeModule(QQ, range(4)); x = X.basis() 

sage: F = X.submodule([x[0]-x[1], x[1]-x[2], x[2]-x[3]]) 

sage: G = X.submodule([x[0]-x[2]]) 

sage: H = X.submodule([x[0]-x[1], x[2]]) 

sage: F.is_submodule(X) 

True 

sage: G.is_submodule(F) 

True 

sage: H.is_submodule(F) 

False 

""" 

if other is self.ambient(): 

return True 

if not isinstance(self, SubmoduleWithBasis) and self.ambient() is other.ambient(): 

raise ValueError("other (=%s) should be a submodule of the same ambient space" % other) 

if not self in ModulesWithBasis.FiniteDimensional: 

raise NotImplementedError("is_submodule for infinite dimensional modules") 

for b in self.basis(): 

try: 

other.retract(b.lift()) 

except ValueError: 

return False 

return True