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

""" 

Affine Subspaces of a Vector Space 

 

An affine subspace of a vector space is a translation of a linear 

subspace. The affine subspaces here are only used internally in 

hyperplane arrangements. You should not use them for interactive work 

or return them to the user. 

 

EXAMPLES:: 

 

sage: from sage.geometry.hyperplane_arrangement.affine_subspace import AffineSubspace 

sage: a = AffineSubspace([1,0,0,0], QQ^4) 

sage: a.dimension() 

4 

sage: a.point() 

(1, 0, 0, 0) 

sage: a.linear_part() 

Vector space of dimension 4 over Rational Field 

sage: a 

Affine space p + W where: 

p = (1, 0, 0, 0) 

W = Vector space of dimension 4 over Rational Field 

sage: b = AffineSubspace((1,0,0,0), matrix(QQ, [[1,2,3,4]]).right_kernel()) 

sage: c = AffineSubspace((0,2,0,0), matrix(QQ, [[0,0,1,2]]).right_kernel()) 

sage: b.intersection(c) 

Affine space p + W where: 

p = (-3, 2, 0, 0) 

W = Vector space of degree 4 and dimension 2 over Rational Field 

Basis matrix: 

[ 1 0 -1 1/2] 

[ 0 1 -2 1] 

sage: b < a 

True 

sage: c < b 

False 

sage: A = AffineSubspace([8,38,21,250], VectorSpace(GF(19),4)) 

sage: A 

Affine space p + W where: 

p = (8, 0, 2, 3) 

W = Vector space of dimension 4 over Finite Field of size 19 

 

TESTS:: 

 

sage: A = AffineSubspace([2], VectorSpace(QQ, 1)) 

sage: A.point() 

(2) 

sage: A.linear_part() 

Vector space of dimension 1 over Rational Field 

sage: A.linear_part().basis_matrix() 

[1] 

sage: A = AffineSubspace([], VectorSpace(QQ, 0)) 

sage: A.point() 

() 

sage: A.linear_part() 

Vector space of dimension 0 over Rational Field 

sage: A.linear_part().basis_matrix() 

[] 

""" 

 

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

# Copyright (C) 2013 David Perkinson <davidp@reed.edu> 

# Volker Braun <vbraun.name@gmail.com> 

# 

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

# as published by the Free Software Foundation; either version 2 of 

# the License, or (at your option) any later version. 

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

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

 

from sage.structure.sage_object import SageObject 

from sage.matrix.constructor import vector 

 

 

class AffineSubspace(SageObject): 

""" 

An affine subspace. 

 

INPUT: 

 

- ``p`` -- list/tuple/iterable representing a point on the 

affine space 

 

- ``V`` -- vector subspace 

 

OUTPUT: 

 

Affine subspace parallel to ``V`` and passing through ``p``. 

 

EXAMPLES:: 

 

sage: from sage.geometry.hyperplane_arrangement.affine_subspace import AffineSubspace 

sage: a = AffineSubspace([1,0,0,0], VectorSpace(QQ,4)) 

sage: a 

Affine space p + W where: 

p = (1, 0, 0, 0) 

W = Vector space of dimension 4 over Rational Field 

""" 

def __init__(self, p, V): 

r""" 

Construct an :class:`AffineSubspace`. 

 

TESTS:: 

 

sage: from sage.geometry.hyperplane_arrangement.affine_subspace import AffineSubspace 

sage: a = AffineSubspace([1,0,0,0], VectorSpace(QQ,4)) 

sage: TestSuite(a).run() 

sage: AffineSubspace(0, VectorSpace(QQ,4)).point() 

(0, 0, 0, 0) 

""" 

R = V.base_ring() 

from sage.categories.all import Fields 

if R not in Fields(): 

R = R.fraction_field() 

V = V.change_ring(R) 

self._base_ring = R 

self._linear_part = V 

p = V.ambient_vector_space()(p) 

p.set_immutable() 

self._point = p 

 

def __hash__(self): 

""" 

Return a hash value. 

 

EXAMPLES:: 

 

sage: from sage.geometry.hyperplane_arrangement.affine_subspace import AffineSubspace 

sage: a = AffineSubspace([1,0,0,0], VectorSpace(QQ,4)) 

sage: a.__hash__() # random output 

-3713096828371451969 

""" 

# note that the point is not canonically chosen, but the linear part is 

return hash(self._linear_part) 

 

def _repr_(self): 

r""" 

String representation for an :class:`AffineSubspace`. 

 

OUTPUT: 

 

A string. 

 

EXAMPLES:: 

 

sage: from sage.geometry.hyperplane_arrangement.affine_subspace import AffineSubspace 

sage: a = AffineSubspace([1,0,0,0],VectorSpace(QQ,4)) 

sage: a 

Affine space p + W where: 

p = (1, 0, 0, 0) 

W = Vector space of dimension 4 over Rational Field 

""" 

return "Affine space p + W where:\n p = "+str(self._point)+"\n W = "+str(self._linear_part) 

 

def __eq__(self, other): 

r""" 

Test whether ``self`` is equal to ``other``. 

 

INPUT: 

 

- ``other`` -- an :class:`AffineSubspace` 

 

OUTPUT: 

 

A boolean. 

 

EXAMPLES:: 

 

sage: from sage.geometry.hyperplane_arrangement.affine_subspace import AffineSubspace 

sage: a = AffineSubspace([1,0,0], matrix([[1,0,0]]).right_kernel()) 

sage: b = AffineSubspace([2,0,0], matrix([[1,0,0]]).right_kernel()) 

sage: c = AffineSubspace([1,1,0], matrix([[1,0,0]]).right_kernel()) 

sage: a == b 

False 

sage: a == c 

True 

""" 

V = self._linear_part 

W = other._linear_part 

return V == W and self._point - other._point in V 

 

def __ne__(self, other): 

r""" 

Test whether ``self`` is not equal to ``other``. 

 

INPUT: 

 

- ``other`` -- an :class:`AffineSubspace` 

 

OUTPUT: 

 

A boolean. 

 

EXAMPLES:: 

 

sage: from sage.geometry.hyperplane_arrangement.affine_subspace import AffineSubspace 

sage: a = AffineSubspace([1,0,0],matrix([[1,0,0]]).right_kernel()) 

sage: b = AffineSubspace([2,0,0],matrix([[1,0,0]]).right_kernel()) 

sage: a == b 

False 

sage: a != b 

True 

sage: a != a 

False 

""" 

return not self == other 

 

def __le__(self, other): 

r""" 

Test whether ``self`` is an affine subspace of ``other``. 

 

INPUT: 

 

- ``other`` -- an :class:`AffineSubspace` 

 

OUTPUT: 

 

A boolean. 

 

EXAMPLES:: 

 

sage: from sage.geometry.hyperplane_arrangement.affine_subspace import AffineSubspace 

sage: V = VectorSpace(QQ, 3) 

sage: W1 = V.subspace([[1,0,0],[0,1,0]]) 

sage: W2 = V.subspace([[1,0,0]]) 

sage: a = AffineSubspace([1,2,3], W1) 

sage: b = AffineSubspace([1,2,3], W2) 

sage: a <= b 

False 

sage: a <= a 

True 

sage: b <= a 

True 

""" 

V = self._linear_part 

W = other._linear_part 

return V.is_subspace(W) and self._point-other._point in W 

 

def __lt__(self, other): 

r""" 

Test whether ``self`` is a proper affine subspace of ``other``. 

 

INPUT: 

 

- ``other`` -- an :class:`AffineSubspace` 

 

OUTPUT: 

 

A boolean. 

 

EXAMPLES:: 

 

sage: from sage.geometry.hyperplane_arrangement.affine_subspace import AffineSubspace 

sage: V = VectorSpace(QQ, 3) 

sage: W1 = V.subspace([[1,0,0], [0,1,0]]) 

sage: W2 = V.subspace([[1,0,0]]) 

sage: a = AffineSubspace([1,2,3], W1) 

sage: b = AffineSubspace([1,2,3], W2) 

sage: a < b 

False 

sage: a < a 

False 

sage: b < a 

True 

""" 

if self._linear_part == other._linear_part: 

return False 

return self <= other 

 

def __contains__(self, q): 

r""" 

Test whether the point ``q`` is in the affine space. 

 

INPUT: 

 

- ``q`` -- point as a list/tuple/iterable 

 

OUTPUT: 

 

A boolean. 

 

EXAMPLES:: 

 

sage: from sage.geometry.hyperplane_arrangement.affine_subspace import AffineSubspace 

sage: a = AffineSubspace([1,0,0], matrix([[1,0,0]]).right_kernel()) 

sage: (1,1,0) in a 

True 

sage: (0,0,0) in a 

False 

""" 

q = vector(self._base_ring, q) 

return self._point - q in self._linear_part 

 

def linear_part(self): 

r""" 

Return the linear part of the affine space. 

 

OUTPUT: 

 

A vector subspace of the ambient space. 

 

EXAMPLES:: 

 

sage: from sage.geometry.hyperplane_arrangement.affine_subspace import AffineSubspace 

sage: A = AffineSubspace([2,3,1], matrix(QQ, [[1,2,3]]).right_kernel()) 

sage: A.linear_part() 

Vector space of degree 3 and dimension 2 over Rational Field 

Basis matrix: 

[ 1 0 -1/3] 

[ 0 1 -2/3] 

sage: A.linear_part().ambient_vector_space() 

Vector space of dimension 3 over Rational Field 

""" 

return self._linear_part 

 

def point(self): 

r""" 

Return a point ``p`` in the affine space. 

 

OUTPUT: 

 

A point of the affine space as a vector in the ambient space. 

 

EXAMPLES:: 

 

sage: from sage.geometry.hyperplane_arrangement.affine_subspace import AffineSubspace 

sage: A = AffineSubspace([2,3,1], VectorSpace(QQ,3)) 

sage: A.point() 

(2, 3, 1) 

""" 

return self._point 

 

def dimension(self): 

r""" 

Return the dimension of the affine space. 

 

OUTPUT: 

 

An integer. 

 

EXAMPLES:: 

 

sage: from sage.geometry.hyperplane_arrangement.affine_subspace import AffineSubspace 

sage: a = AffineSubspace([1,0,0,0],VectorSpace(QQ,4)) 

sage: a.dimension() 

4 

""" 

return self.linear_part().dimension() 

 

def intersection(self, other): 

r""" 

Return the intersection of ``self`` with ``other``. 

 

INPUT: 

 

- ``other`` -- an :class:`AffineSubspace` 

 

OUTPUT: 

 

A new affine subspace, (or ``None`` if the intersection is 

empty). 

 

EXAMPLES:: 

 

sage: from sage.geometry.hyperplane_arrangement.affine_subspace import AffineSubspace 

sage: V = VectorSpace(QQ,3) 

sage: U = V.subspace([(1,0,0), (0,1,0)]) 

sage: W = V.subspace([(0,1,0), (0,0,1)]) 

sage: A = AffineSubspace((0,0,0), U) 

sage: B = AffineSubspace((1,1,1), W) 

sage: A.intersection(B) 

Affine space p + W where: 

p = (1, 1, 0) 

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

Basis matrix: 

[0 1 0] 

sage: C = AffineSubspace((0,0,1), U) 

sage: A.intersection(C) 

sage: C = AffineSubspace((7,8,9), U.complement()) 

sage: A.intersection(C) 

Affine space p + W where: 

p = (7, 8, 0) 

W = Vector space of degree 3 and dimension 0 over Rational Field 

Basis matrix: 

[] 

sage: A.intersection(C).intersection(B) 

 

sage: D = AffineSubspace([1,2,3], VectorSpace(GF(5),3)) 

sage: E = AffineSubspace([3,4,5], VectorSpace(GF(5),3)) 

sage: D.intersection(E) 

Affine space p + W where: 

p = (3, 4, 0) 

W = Vector space of dimension 3 over Finite Field of size 5 

""" 

if self.linear_part().ambient_vector_space() != \ 

other.linear_part().ambient_vector_space(): 

raise ValueError('incompatible ambient vector spaces') 

m = self.linear_part().matrix() 

n = other.linear_part().matrix() 

p = self.point() 

q = other.point() 

M = m.stack(n) 

v = q - p 

try: 

t = M.solve_left(v) 

except ValueError: 

return None # empty intersection 

new_p = p + t[:m.nrows()]*m 

new_V = self.linear_part().intersection(other._linear_part) 

return AffineSubspace(new_p, new_V)