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

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

r""" 

Quotients of finite rank free modules over a field. 

""" 

from __future__ import absolute_import 

 

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

# Copyright (C) 2009 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/ 

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

 

from .free_module import FreeModule_ambient_field 

 

 

class FreeModule_ambient_field_quotient(FreeModule_ambient_field): 

""" 

A quotient `V/W` of two vector spaces as a vector space. 

 

To obtain `V` or `W` use ``self.V()`` and ``self.W()``. 

 

EXAMPLES:: 

 

sage: k.<i> = QuadraticField(-1) 

sage: A = k^3; V = A.span([[1,0,i], [2,i,0]]) 

sage: W = A.span([[3,i,i]]) 

sage: U = V/W; U 

Vector space quotient V/W of dimension 1 over Number Field in i with defining polynomial x^2 + 1 where 

V: Vector space of degree 3 and dimension 2 over Number Field in i with defining polynomial x^2 + 1 

Basis matrix: 

[ 1 0 i] 

[ 0 1 -2] 

W: Vector space of degree 3 and dimension 1 over Number Field in i with defining polynomial x^2 + 1 

Basis matrix: 

[ 1 1/3*i 1/3*i] 

sage: U.V() 

Vector space of degree 3 and dimension 2 over Number Field in i with defining polynomial x^2 + 1 

Basis matrix: 

[ 1 0 i] 

[ 0 1 -2] 

sage: U.W() 

Vector space of degree 3 and dimension 1 over Number Field in i with defining polynomial x^2 + 1 

Basis matrix: 

[ 1 1/3*i 1/3*i] 

sage: U.quotient_map() 

Vector space morphism represented by the matrix: 

[ 1] 

[3*i] 

Domain: Vector space of degree 3 and dimension 2 over Number Field in i with defining polynomial x^2 + 1 

Basis matrix: 

[ 1 0 i] 

[ 0 1 -2] 

Codomain: Vector space quotient V/W of dimension 1 over Number Field in i with defining polynomial x^2 + 1 where 

V: Vector space of degree 3 and dimension 2 over Number Field in i with defining polynomial x^2 + 1 

Basis matrix: 

[ 1 0 i] 

[ 0 1 -2] 

W: Vector space of degree 3 and dimension 1 over Number Field in i with defining polynomial x^2 + 1 

Basis matrix: 

[ 1 1/3*i 1/3*i] 

sage: Z = V.quotient(W) 

sage: Z == U 

True 

 

We create three quotient spaces and compare them:: 

 

sage: A = QQ^2 

sage: V = A.span_of_basis([[1,0], [1,1]]) 

sage: W0 = V.span([V.1, V.0]) 

sage: W1 = V.span([V.1]) 

sage: W2 = V.span([V.1]) 

sage: Q0 = V/W0 

sage: Q1 = V/W1 

sage: Q2 = V/W2 

 

sage: Q0 == Q1 

False 

sage: Q1 == Q2 

True 

 

TESTS:: 

 

sage: A = QQ^0; V = A.span([]) # corner case 

sage: W = A.span([]) 

sage: U = V/W 

 

sage: loads(dumps(U)) == U 

True 

sage: type(loads(dumps(U)) ) 

<class 'sage.modules.quotient_module.FreeModule_ambient_field_quotient_with_category'> 

""" 

def __init__(self, domain, sub, quotient_matrix, lift_matrix, inner_product_matrix=None): 

""" 

Create this quotient space, from the given domain, submodule, 

and quotient_matrix. 

 

EXAMPLES:: 

 

sage: A = QQ^5; V = A.span_of_basis([[1,0,-1,1,1], [1,-1,0,2/3,3/4]]); V 

Vector space of degree 5 and dimension 2 over Rational Field 

User basis matrix: 

[ 1 0 -1 1 1] 

[ 1 -1 0 2/3 3/4] 

sage: W = V.span_of_basis([V.0 - 2/3*V.1]); W 

Vector space of degree 5 and dimension 1 over Rational Field 

User basis matrix: 

[1/3 2/3 -1 5/9 1/2] 

 

This creates a quotient vector space:: 

 

sage: Q = V / W 

 

Behold the type of Q:: 

 

sage: type(Q) 

<class 'sage.modules.quotient_module.FreeModule_ambient_field_quotient_with_category'> 

 

We do some consistency checks on the extra quotient and 

lifting structure of Q:: 

 

sage: Q(V.0) 

(1) 

sage: Q( V.0 - 2/3*V.1 ) 

(0) 

sage: v = Q.lift(Q.0); v 

(1, 0, -1, 1, 1) 

sage: Q( v ) 

(1) 

""" 

base_field = domain.base_field() 

dimension = quotient_matrix.ncols() 

sparse = domain.is_sparse() 

self.__sub = sub 

self.__domain = domain 

self.__hash = hash((domain, sub)) 

FreeModule_ambient_field.__init__(self, base_field, dimension, sparse) 

self.__quo_map = domain.Hom(self)(quotient_matrix) 

self.__quo_map.register_as_coercion() 

self.__lift_map = self.Hom(domain)(lift_matrix) 

 

def _repr_(self): 

r""" 

Return the rather verbose string representation of this quotient space V/W. 

 

EXAMPLES: 

 

We create a quotient vector space over a finite field:: 

 

sage: k.<a> = GF(9); A = k^3; V = A.span_of_basis([[1,0,a], [a,a,1]]); W = V.span([V.1]) 

sage: Q = V/W 

 

Note the type:: 

 

sage: type(Q) 

<class 'sage.modules.quotient_module.FreeModule_ambient_field_quotient_with_category'> 

 

The string representation mentions that this is a quotient 

`V/W`, that the quotient has dimension 1 and is over a finite 

field, and also describes `V` and `W`:: 

 

sage: Q._repr_() 

'Vector space quotient V/W of dimension 1 over Finite Field in a of size 3^2 where\nV: Vector space of degree 3 and dimension 2 over Finite Field in a of size 3^2\nUser basis matrix:\n[1 0 a]\n[a a 1]\nW: Vector space of degree 3 and dimension 1 over Finite Field in a of size 3^2\nBasis matrix:\n[ 1 1 a + 2]' 

""" 

return "%s space quotient V/W of dimension %s over %s where\nV: %s\nW: %s"%( 

"Sparse vector" if self.is_sparse() else "Vector", 

self.dimension(), self.base_ring(), 

self.V(), self.W()) 

 

def __hash__(self): 

""" 

Return hash of this quotient space `V/W`, which is, by definition, 

the hash of the tuple `(V, W)`. 

 

EXAMPLES: 

 

We compute the hash of a certain 0-dimension quotient vector 

space:: 

 

sage: A = QQ^2; V = A.span_of_basis([[1,0], [1,1]]); W = V.span([V.1, V.0]) 

sage: Q = V/W; Q.dimension() 

0 

sage: hash(Q) 

954887582 # 32-bit 

-5856620741060301410 # 64-bit 

 

The hash is just got by hashing both `V` and `W`:: 

 

sage: hash((V, W)) 

954887582 # 32-bit 

-5856620741060301410 # 64-bit 

""" 

return self.__hash 

 

def _element_constructor_(self, x): 

""" 

Convert an element into this quotient space `V/W` if there is 

a way to make sense of it. 

 

An element converts into self if it can be converted into `V`, 

or if not at least if it can be made sense of as a list of 

length the dimension of self. 

 

EXAMPLES: 

 

We create a 2-dimensional quotient of a 3-dimension ambient 

vector space:: 

 

sage: M = QQ^3 / [[1,2,3]] 

 

A list of length 3 converts into ``QQ^3``, so it converts into 

`M`:: 

 

sage: M([1,2,4]) #indirect doctest 

(-1/3, -2/3) 

sage: M([1,2,3]) 

(0, 0) 

 

A list of length 2 converts into M, where here it just gives 

the corresponding linear combination of the basis for `M`:: 

 

sage: M([1,2]) 

(1, 2) 

sage: M.0 + 2*M.1 

(1, 2) 

 

Of course, elements of ``QQ^3`` convert into the quotient 

module as well. Here is a different example:: 

 

sage: V = QQ^3; W = V.span([[1,0,0]]); Q = V/W 

sage: Q(V.0) 

(0, 0) 

sage: Q(V.1) 

(1, 0) 

sage: Q.0 

(1, 0) 

sage: Q.0 + V.1 

(2, 0) 

 

Here we start with something that is over ZZ, so it 

canonically coerces into ``QQ^3``, hence into ``self``:: 

 

sage: Q((ZZ^3)([1,2,3])) 

(2, 3) 

 

""" 

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

return x 

if isinstance(x, (list, tuple)) and len(x) == self.__domain.rank(): 

return self.__quo_map(self.__domain(x)) 

return FreeModule_ambient_field._element_constructor_(self, x) 

 

def _coerce_map_from_(self, M): 

""" 

Return a coercion map from `M` to ``self``, or None. 

 

EXAMPLES:: 

 

sage: V = QQ^2 / [[1, 2]] 

sage: V.coerce_map_from(ZZ^2) 

Composite map: 

From: Ambient free module of rank 2 over the principal ideal domain Integer Ring 

To: Vector space quotient V/W of dimension 1 over Rational Field where 

V: Vector space of dimension 2 over Rational Field 

W: Vector space of degree 2 and dimension 1 over Rational Field 

Basis matrix: 

[1 2] 

Defn: Coercion map: 

From: Ambient free module of rank 2 over the principal ideal domain Integer Ring 

To: Vector space of dimension 2 over Rational Field 

then 

Vector space morphism represented by the matrix: 

[ 1] 

[-1/2] 

Domain: Vector space of dimension 2 over Rational Field 

Codomain: Vector space quotient V/W of dimension 1 over Rational Field where 

V: Vector space of dimension 2 over Rational Field 

W: Vector space of degree 2 and dimension 1 over Rational Field 

Basis matrix: 

[1 2] 

 

Make sure :trac:`10513` is fixed (no coercion from an abstract 

vector space to an isomorphic quotient vector space):: 

 

sage: V = QQ^3 / [[1,2,3]] 

sage: V.coerce_map_from(QQ^2) 

 

""" 

from sage.modules.free_module import FreeModule_ambient 

if (isinstance(M, FreeModule_ambient) 

and not (isinstance(M, FreeModule_ambient_field_quotient) 

and self.W() == M.W())): 

# No map between different quotients. 

# No map from quotient to abstract module. 

return None 

f = super(FreeModule_ambient_field, self)._coerce_map_from_(M) 

if f is not None: 

return f 

f = self.__domain.coerce_map_from(M) 

if f is not None: 

return self.__quo_map * f 

return None 

 

def quotient_map(self): 

""" 

Given this quotient space `Q = V / W`, return the natural quotient 

map from `V` to `Q`. 

 

EXAMPLES:: 

 

sage: M = QQ^3 / [[1,2,3]] 

sage: M.quotient_map() 

Vector space morphism represented by the matrix: 

[ 1 0] 

[ 0 1] 

[-1/3 -2/3] 

Domain: Vector space of dimension 3 over Rational Field 

Codomain: Vector space quotient V/W of dimension 2 over Rational Field where 

V: Vector space of dimension 3 over Rational Field 

W: Vector space of degree 3 and dimension 1 over Rational Field 

Basis matrix: 

[1 2 3] 

 

sage: M.quotient_map()( (QQ^3)([1,2,3]) ) 

(0, 0) 

""" 

return self.__quo_map 

 

def lift_map(self): 

r""" 

Given this quotient space `Q = V / W`, return a fixed choice of 

linear homomorphism (a section) from `Q` to `V`. 

 

EXAMPLES:: 

 

sage: M = QQ^3 / [[1,2,3]] 

sage: M.lift_map() 

Vector space morphism represented by the matrix: 

[1 0 0] 

[0 1 0] 

Domain: Vector space quotient V/W of dimension 2 over Rational Field where 

V: Vector space of dimension 3 over Rational Field 

W: Vector space of degree 3 and dimension 1 over Rational Field 

Basis matrix: 

[1 2 3] 

Codomain: Vector space of dimension 3 over Rational Field 

""" 

return self.__lift_map 

 

def lift(self, x): 

r""" 

Lift element of this quotient `V / W` to `V` by applying 

the fixed lift homomorphism. 

 

The lift is a fixed homomorphism. 

 

EXAMPLES:: 

 

sage: M = QQ^3 / [[1,2,3]] 

sage: M.lift(M.0) 

(1, 0, 0) 

sage: M.lift(M.1) 

(0, 1, 0) 

sage: M.lift(M.0 - 2*M.1) 

(1, -2, 0) 

""" 

return self.__lift_map(x) 

 

def W(self): 

""" 

Given this quotient space `Q = V/W`, return `W`. 

 

EXAMPLES:: 

 

sage: M = QQ^10 / [list(range(10)), list(range(2,12))] 

sage: M.W() 

Vector space of degree 10 and dimension 2 over Rational Field 

Basis matrix: 

[ 1 0 -1 -2 -3 -4 -5 -6 -7 -8] 

[ 0 1 2 3 4 5 6 7 8 9] 

""" 

return self.__sub 

 

def V(self): 

""" 

Given this quotient space `Q = V/W`, return `V`. 

 

EXAMPLES:: 

 

sage: M = QQ^10 / [list(range(10)), list(range(2,12))] 

sage: M.V() 

Vector space of dimension 10 over Rational Field 

""" 

return self.__domain 

 

def cover(self): 

""" 

Given this quotient space `Q = V/W`, return `V`. 

 

This is the same as :meth:`V`. 

 

EXAMPLES:: 

 

sage: M = QQ^10 / [list(range(10)), list(range(2,12))] 

sage: M.cover() 

Vector space of dimension 10 over Rational Field 

""" 

return self.V() 

 

def relations(self): 

""" 

Given this quotient space `Q = V/W`, return `W`. 

 

This is the same as :meth:`W`. 

 

EXAMPLES:: 

 

sage: M = QQ^10 / [list(range(10)), list(range(2,12))] 

sage: M.relations() 

Vector space of degree 10 and dimension 2 over Rational Field 

Basis matrix: 

[ 1 0 -1 -2 -3 -4 -5 -6 -7 -8] 

[ 0 1 2 3 4 5 6 7 8 9] 

""" 

return self.W()