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

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

r""" 

Library of Hyperplane Arrangements 

 

A collection of useful or interesting hyperplane arrangements. See 

:mod:`sage.geometry.hyperplane_arrangement.arrangement` for details 

about how to construct your own hyperplane arrangements. 

""" 

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

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

# 

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

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

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

 

from sage.graphs.all import graphs 

from sage.matrix.constructor import matrix, random_matrix 

from sage.rings.all import QQ, ZZ 

from sage.misc.misc_c import prod 

 

from sage.combinat.combinat import stirling_number2 

from sage.arith.all import binomial 

from sage.rings.polynomial.polynomial_ring import polygen 

 

from sage.geometry.hyperplane_arrangement.arrangement import HyperplaneArrangements 

 

 

def make_parent(base_ring, dimension, names=None): 

""" 

Construct the parent for the hyperplane arrangements. 

 

For internal use only. 

 

INPUT: 

 

- ``base_ring`` -- a ring 

 

- ``dimension`` -- integer 

 

- ``names`` -- ``None`` (default) or a list/tuple/iterable of 

strings 

 

OUTPUT: 

 

A new 

:class:`~sage.geometry.hyperplane_arrangement.arrangement.HyperplaneArrangements` 

instance. 

 

EXAMPLES:: 

 

sage: from sage.geometry.hyperplane_arrangement.library import make_parent 

sage: make_parent(QQ, 3) 

Hyperplane arrangements in 3-dimensional linear space over 

Rational Field with coordinates t0, t1, t2 

""" 

if names is None: 

names = tuple('t'+str(i) for i in range(dimension)) 

else: 

names = tuple(map(str, names)) 

if len(names) != dimension: 

raise ValueError('number of variable names does not match dimension') 

return HyperplaneArrangements(base_ring, names=names) 

 

 

 

class HyperplaneArrangementLibrary(object): 

""" 

The library of hyperplane arrangements. 

""" 

 

def braid(self, n, K=QQ, names=None): 

r""" 

The braid arrangement. 

 

INPUT: 

 

- ``n`` -- integer 

 

- ``K`` -- field (default: ``QQ``) 

 

- ``names`` -- tuple of strings or ``None`` (default); the 

variable names for the ambient space 

 

OUTPUT: 

 

The hyperplane arrangement consisting of the `n(n-1)/2` 

hyperplanes `\{ x_i - x_j = 0 : 1 \leq i \leq j \leq n \}`. 

 

EXAMPLES:: 

 

sage: hyperplane_arrangements.braid(4) 

Arrangement of 6 hyperplanes of dimension 4 and rank 3 

""" 

x = polygen(QQ, 'x') 

A = self.graphical(graphs.CompleteGraph(n), K, names=names) 

charpoly = prod(x-i for i in range(n)) 

A.characteristic_polynomial.set_cache(charpoly) 

return A 

 

def bigraphical(self, G, A=None, K=QQ, names=None): 

r""" 

Return a bigraphical hyperplane arrangement. 

 

INPUT: 

 

- ``G`` -- graph 

 

- ``A`` -- list, matrix, dictionary (default: ``None`` 

gives semiorder), or the string 'generic' 

 

- ``K`` -- field (default: `\QQ`) 

 

- ``names`` -- tuple of strings or ``None`` (default); the 

variable names for the ambient space 

 

OUTPUT: 

 

The hyperplane arrangement with hyperplanes `x_i - x_j = 

A[i,j]` and `x_j - x_i = A[j,i]` for each edge `v_i, v_j` of 

``G``. The indices `i,j` are the indices of elements of 

``G.vertices()``. 

 

EXAMPLES:: 

 

sage: G = graphs.CycleGraph(4) 

sage: G.edges() 

[(0, 1, None), (0, 3, None), (1, 2, None), (2, 3, None)] 

sage: G.edges(labels=False) 

[(0, 1), (0, 3), (1, 2), (2, 3)] 

sage: A = {0:{1:1, 3:2}, 1:{0:3, 2:0}, 2:{1:2, 3:1}, 3:{2:0, 0:2}} 

sage: HA = hyperplane_arrangements.bigraphical(G, A) 

sage: HA.n_regions() 

63 

sage: hyperplane_arrangements.bigraphical(G, 'generic').n_regions() 

65 

sage: hyperplane_arrangements.bigraphical(G).n_regions() 

59 

 

REFERENCES: 

 

- [HP2016]_ 

""" 

n = G.num_verts() 

if A is None: # default to G-semiorder arrangement 

A = matrix(K, n, lambda i, j: 1) 

elif A == 'generic': 

A = random_matrix(ZZ, n, x=10000) 

A = matrix(K, A) 

H = make_parent(K, n, names) 

x = H.gens() 

hyperplanes = [] 

for e in G.edges(): 

i = G.vertices().index(e[0]) 

j = G.vertices().index(e[1]) 

hyperplanes.append( x[i] - x[j] - A[i][j]) 

hyperplanes.append(-x[i] + x[j] - A[j][i]) 

return H(*hyperplanes) 

 

def Catalan(self, n, K=QQ, names=None): 

r""" 

Return the Catalan arrangement. 

 

INPUT: 

 

- ``n`` -- integer 

 

- ``K`` -- field (default: `\QQ`) 

 

- ``names`` -- tuple of strings or ``None`` (default); the 

variable names for the ambient space 

 

OUTPUT: 

 

The arrangement of `3n(n-1)/2` hyperplanes `\{ x_i - x_j = 

-1,0,1 : 1 \leq i \leq j \leq n \}`. 

 

EXAMPLES:: 

 

sage: hyperplane_arrangements.Catalan(5) 

Arrangement of 30 hyperplanes of dimension 5 and rank 4 

 

TESTS:: 

 

sage: h = hyperplane_arrangements.Catalan(5) 

sage: h.characteristic_polynomial() 

x^5 - 30*x^4 + 335*x^3 - 1650*x^2 + 3024*x 

sage: h.characteristic_polynomial.clear_cache() # long time 

sage: h.characteristic_polynomial() # long time 

x^5 - 30*x^4 + 335*x^3 - 1650*x^2 + 3024*x 

""" 

H = make_parent(K, n, names) 

x = H.gens() 

hyperplanes = [] 

for i in range(n): 

for j in range(i+1, n): 

for k in [-1, 0, 1]: 

hyperplanes.append(x[i] - x[j] - k) 

Cn = H(*hyperplanes) 

x = polygen(QQ, 'x') 

charpoly = x*prod([x-n-i for i in range(1, n)]) 

Cn.characteristic_polynomial.set_cache(charpoly) 

return Cn 

 

def coordinate(self, n, K=QQ, names=None): 

r""" 

Return the coordinate hyperplane arrangement. 

 

INPUT: 

 

- ``n`` -- integer 

 

- ``K`` -- field (default: `\QQ`) 

 

- ``names`` -- tuple of strings or ``None`` (default); the 

variable names for the ambient space 

 

OUTPUT: 

 

The coordinate hyperplane arrangement, which is the central 

hyperplane arrangement consisting of the coordinate 

hyperplanes `x_i = 0`. 

 

EXAMPLES:: 

 

sage: hyperplane_arrangements.coordinate(5) 

Arrangement of 5 hyperplanes of dimension 5 and rank 5 

""" 

H = make_parent(K, n, names) 

x = H.gens() 

return H(x) 

 

def G_semiorder(self, G, K=QQ, names=None): 

r""" 

Return the semiorder hyperplane arrangement of a graph. 

 

INPUT: 

 

- ``G`` -- graph 

 

- ``K`` -- field (default: `\QQ`) 

 

- ``names`` -- tuple of strings or ``None`` (default); the 

variable names for the ambient space 

 

OUTPUT: 

 

The semiorder hyperplane arrangement of a graph G is the 

arrangement `\{ x_i - x_j = -1,1 \}` where `ij` is an edge of 

``G``. 

 

EXAMPLES:: 

 

sage: G = graphs.CompleteGraph(5) 

sage: hyperplane_arrangements.G_semiorder(G) 

Arrangement of 20 hyperplanes of dimension 5 and rank 4 

sage: g = graphs.HouseGraph() 

sage: hyperplane_arrangements.G_semiorder(g) 

Arrangement of 12 hyperplanes of dimension 5 and rank 4 

""" 

n = G.num_verts() 

H = make_parent(K, n, names) 

x = H.gens() 

hyperplanes = [] 

for e in G.edges(): 

i = G.vertices().index(e[0]) 

j = G.vertices().index(e[1]) 

hyperplanes.append(x[i] - x[j] - 1) 

hyperplanes.append(x[i] - x[j] + 1) 

return H(*hyperplanes) 

 

def G_Shi(self, G, K=QQ, names=None): 

r""" 

Return the Shi hyperplane arrangement of a graph `G`. 

 

INPUT: 

 

- ``G`` -- graph 

 

- ``K`` -- field (default: `\QQ`) 

 

- ``names`` -- tuple of strings or ``None`` (default); the 

variable names for the ambient space 

 

OUTPUT: 

 

The Shi hyperplane arrangement of the given graph ``G``. 

 

EXAMPLES:: 

 

sage: G = graphs.CompleteGraph(5) 

sage: hyperplane_arrangements.G_Shi(G) 

Arrangement of 20 hyperplanes of dimension 5 and rank 4 

sage: g = graphs.HouseGraph() 

sage: hyperplane_arrangements.G_Shi(g) 

Arrangement of 12 hyperplanes of dimension 5 and rank 4 

sage: a = hyperplane_arrangements.G_Shi(graphs.WheelGraph(4)); a 

Arrangement of 12 hyperplanes of dimension 4 and rank 3 

""" 

n = G.num_verts() 

H = make_parent(K, n, names) 

x = H.gens() 

hyperplanes = [] 

for e in G.edges(): 

i = G.vertices().index(e[0]) 

j = G.vertices().index(e[1]) 

hyperplanes.append(x[i] - x[j]) 

hyperplanes.append(x[i] - x[j] - 1) 

return H(*hyperplanes) 

 

def graphical(self, G, K=QQ, names=None): 

r""" 

Return the graphical hyperplane arrangement of a graph ``G``. 

 

INPUT: 

 

- ``G`` -- graph 

 

- ``K`` -- field (default: `\QQ`) 

 

- ``names`` -- tuple of strings or ``None`` (default); the 

variable names for the ambient space 

 

OUTPUT: 

 

The graphical hyperplane arrangement of a graph G, which is 

the arrangement `\{ x_i - x_j = 0 \}` for all edges `ij` of the 

graph ``G``. 

 

EXAMPLES:: 

 

sage: G = graphs.CompleteGraph(5) 

sage: hyperplane_arrangements.graphical(G) 

Arrangement of 10 hyperplanes of dimension 5 and rank 4 

sage: g = graphs.HouseGraph() 

sage: hyperplane_arrangements.graphical(g) 

Arrangement of 6 hyperplanes of dimension 5 and rank 4 

 

TESTS:: 

 

sage: h = hyperplane_arrangements.graphical(g) 

sage: h.characteristic_polynomial() 

x^5 - 6*x^4 + 14*x^3 - 15*x^2 + 6*x 

sage: h.characteristic_polynomial.clear_cache() # long time 

sage: h.characteristic_polynomial() # long time 

x^5 - 6*x^4 + 14*x^3 - 15*x^2 + 6*x 

""" 

n = G.num_verts() 

H = make_parent(K, n, names) 

x = H.gens() 

hyperplanes = [] 

for e in G.edges(): 

i = G.vertices().index(e[0]) 

j = G.vertices().index(e[1]) 

hyperplanes.append(x[i] - x[j]) 

A = H(*hyperplanes) 

charpoly = G.chromatic_polynomial() 

A.characteristic_polynomial.set_cache(charpoly) 

return A 

 

def Ish(self, n, K=QQ, names=None): 

r""" 

Return the Ish arrangement. 

 

INPUT: 

 

- ``n`` -- integer 

 

- ``K`` -- field (default:``QQ``) 

 

- ``names`` -- tuple of strings or ``None`` (default); the 

variable names for the ambient space 

 

OUTPUT: 

 

The Ish arrangement, which is the set of `n(n-1)` hyperplanes. 

 

.. MATH:: 

 

\{ x_i - x_j = 0 : 1 \leq i \leq j \leq n \}  

\cup  

\{ x_1 - x_j = i : 1 \leq i \leq j \leq n \}. 

 

EXAMPLES:: 

 

sage: a = hyperplane_arrangements.Ish(3); a 

Arrangement of 6 hyperplanes of dimension 3 and rank 2 

sage: a.characteristic_polynomial() 

x^3 - 6*x^2 + 9*x 

sage: b = hyperplane_arrangements.Shi(3) 

sage: b.characteristic_polynomial() 

x^3 - 6*x^2 + 9*x 

 

TESTS:: 

 

sage: a.characteristic_polynomial.clear_cache() # long time 

sage: a.characteristic_polynomial() # long time 

x^3 - 6*x^2 + 9*x 

 

REFERENCES: 

 

- [AR2012]_ 

""" 

H = make_parent(K, n, names) 

x = H.gens() 

hyperplanes = [] 

for i in range(n): 

for j in range(i+1, n): 

hyperplanes.append(x[i] - x[j]) 

hyperplanes.append(x[0] - x[j] - (i+1)) 

A = H(*hyperplanes) 

x = polygen(QQ, 'x') 

charpoly = x * sum([(-1)**k * stirling_number2(n, n-k) * 

prod([(x - 1 - j) for j in range(k, n-1)]) for k in range(0, n)]) 

A.characteristic_polynomial.set_cache(charpoly) 

return A 

 

def linial(self, n, K=QQ, names=None): 

r""" 

Return the linial hyperplane arrangement. 

 

INPUT: 

 

- ``n`` -- integer 

 

- ``K`` -- field (default: `\QQ`) 

 

- ``names`` -- tuple of strings or ``None`` (default); the 

variable names for the ambient space 

 

OUTPUT: 

 

The linial hyperplane arrangement is the set of hyperplanes 

`\{x_i - x_j = 1 : 1\leq i < j \leq n\}`. 

 

EXAMPLES:: 

 

sage: a = hyperplane_arrangements.linial(4); a 

Arrangement of 6 hyperplanes of dimension 4 and rank 3 

sage: a.characteristic_polynomial() 

x^4 - 6*x^3 + 15*x^2 - 14*x 

 

TESTS:: 

 

sage: h = hyperplane_arrangements.linial(5) 

sage: h.characteristic_polynomial() 

x^5 - 10*x^4 + 45*x^3 - 100*x^2 + 90*x 

sage: h.characteristic_polynomial.clear_cache() # long time 

sage: h.characteristic_polynomial() # long time 

x^5 - 10*x^4 + 45*x^3 - 100*x^2 + 90*x 

""" 

H = make_parent(K, n, names) 

x = H.gens() 

hyperplanes = [] 

for i in range(n): 

for j in range(i+1, n): 

hyperplanes.append(x[i] - x[j] - 1) 

A = H(*hyperplanes) 

x = polygen(QQ, 'x') 

charpoly = x * sum(binomial(n, k)*(x - k)**(n - 1) for k in range(n + 1)) / 2**n 

A.characteristic_polynomial.set_cache(charpoly) 

return A 

 

def semiorder(self, n, K=QQ, names=None): 

r""" 

Return the semiorder arrangement. 

 

INPUT: 

 

- ``n`` -- integer 

 

- ``K`` -- field (default: `\QQ`) 

 

- ``names`` -- tuple of strings or ``None`` (default); the 

variable names for the ambient space 

 

OUTPUT: 

 

The semiorder arrangement, which is the set of `n(n-1)` 

hyperplanes `\{ x_i - x_j = -1,1 : 1 \leq i \leq j \leq n\}`. 

 

EXAMPLES:: 

 

sage: hyperplane_arrangements.semiorder(4) 

Arrangement of 12 hyperplanes of dimension 4 and rank 3 

 

TESTS:: 

 

sage: h = hyperplane_arrangements.semiorder(5) 

sage: h.characteristic_polynomial() 

x^5 - 20*x^4 + 180*x^3 - 790*x^2 + 1380*x 

sage: h.characteristic_polynomial.clear_cache() # long time 

sage: h.characteristic_polynomial() # long time  

x^5 - 20*x^4 + 180*x^3 - 790*x^2 + 1380*x 

""" 

H = make_parent(K, n, names) 

x = H.gens() 

hyperplanes = [] 

for i in range(n): 

for j in range(i+1, n): 

for k in [-1, 1]: 

hyperplanes.append(x[i] - x[j] - k) 

A = H(*hyperplanes) 

x = polygen(QQ, 'x') 

charpoly = x * sum([stirling_number2(n, k) * prod([x - k - i for i in range(1, k)]) 

for k in range(1, n+1)]) 

A.characteristic_polynomial.set_cache(charpoly) 

return A 

 

def Shi(self, n, K=QQ, names=None): 

r""" 

Return the Shi arrangement. 

 

INPUT: 

 

- ``n`` -- integer 

 

- ``K`` -- field (default:``QQ``) 

 

- ``names`` -- tuple of strings or ``None`` (default); the 

variable names for the ambient space 

 

OUTPUT: 

 

The Shi arrangement is the set of `n(n-1)` hyperplanes: `\{ x_i - x_j 

= 0,1 : 1 \leq i \leq j \leq n \}`. 

 

EXAMPLES:: 

 

sage: hyperplane_arrangements.Shi(4) 

Arrangement of 12 hyperplanes of dimension 4 and rank 3 

 

TESTS:: 

 

sage: h = hyperplane_arrangements.Shi(4) 

sage: h.characteristic_polynomial() 

x^4 - 12*x^3 + 48*x^2 - 64*x 

sage: h.characteristic_polynomial.clear_cache() # long time 

sage: h.characteristic_polynomial() # long time 

x^4 - 12*x^3 + 48*x^2 - 64*x 

""" 

H = make_parent(K, n, names) 

x = H.gens() 

hyperplanes = [] 

for i in range(n): 

for j in range(i+1, n): 

for const in [0, 1]: 

hyperplanes.append(x[i] - x[j] - const) 

A = H(*hyperplanes) 

x = polygen(QQ, 'x') 

charpoly = x * sum([(-1)**k * stirling_number2(n, n-k) * 

prod([(x - 1 - j) for j in range(k, n-1)]) for k in range(0, n)]) 

A.characteristic_polynomial.set_cache(charpoly) 

return A 

 

 

hyperplane_arrangements = HyperplaneArrangementLibrary()