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

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

749

750

751

752

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

778

779

780

781

782

783

784

785

786

787

788

789

790

791

792

793

794

795

796

797

798

799

800

801

802

803

804

805

806

807

808

809

810

811

812

813

814

815

816

817

818

819

820

821

822

823

824

825

826

827

828

829

830

831

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848

849

850

851

852

853

854

855

856

857

858

859

860

# -*- coding: utf-8 -*- 

r""" 

Plane Partitions 

 

AUTHORS: 

 

- Jang Soo Kim (2016): Initial implementation 

- Jessica Striker (2016): Added additional methods 

""" 

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

# Copyright (C) 2016 Jang Soo Kim <jangsookim@skku.edu>, 

# 2016 Jessica Striker <jessicapalencia@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 __future__ import print_function, absolute_import 

from six.moves import range 

from six import add_metaclass 

 

from sage.structure.list_clone import ClonableArray 

from sage.misc.inherit_comparison import InheritComparisonClasscallMetaclass 

from sage.structure.unique_representation import UniqueRepresentation 

from sage.structure.parent import Parent 

from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets 

from sage.combinat.posets.posets import Poset 

from sage.rings.integer import Integer 

from sage.misc.all import prod 

from sage.combinat.tableau import Tableau 

 

 

@add_metaclass(InheritComparisonClasscallMetaclass) 

class PlanePartition(ClonableArray): 

r""" 

A plane partition. 

 

A *plane partition* is a stack of cubes in the positive orthant. 

 

INPUT: 

 

- ``PP`` -- a list of lists which represents a tableau 

 

- ``box_size`` -- (optional) a list ``[A, B, C]`` of 3 positive integers, 

where ``A``, ``B``, ``C`` are the lengths of the box in the `x`-axis, 

`y`-axis, `z`-axis, respectively; if this is not given, it is 

determined by the smallest box bounding ``PP`` 

 

OUTPUT: 

 

The plane partition whose tableau representation is ``PP``. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: PP 

Plane partition [[4, 3, 3, 1], [2, 1, 1], [1, 1]] 

 

TESTS:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: TestSuite(PP).run() 

""" 

@staticmethod 

def __classcall_private__(cls, PP, box_size=None): 

""" 

Construct a plane partition with the appropriate parent. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1], [2,1,1], [1,1]]) 

sage: PP.parent() is PlanePartitions((3,4,4)) 

True 

""" 

if box_size is None: 

if PP: 

box_size = (len(PP), len(PP[0]), PP[0][0]) 

else: 

box_size = (0, 0, 0) 

return PlanePartitions(box_size)(PP) 

 

def __init__(self, parent, PP, check=True): 

""" 

Initialize ``self``. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: TestSuite(PP).run() 

""" 

ClonableArray.__init__(self, parent, PP, check=check) 

self._max_x = parent._box[0] 

self._max_y = parent._box[1] 

self._max_z = parent._box[2] 

 

def check(self): 

""" 

Check to see that ``self`` is a valid plane partition. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: PP.check() 

""" 

if len(self) == 0: 

return 

if len(self) > self.parent()._box[0]: 

raise ValueError("too big in z direction") 

if len(self[0]) > self.parent()._box[1]: 

raise ValueError("too big in y direction") 

if self[0][0] > self.parent()._box[2]: 

raise ValueError("too big in x direction") 

 

def _repr_(self): 

""" 

Return a string representation of ``self``. 

 

EXAMPLES:: 

 

sage: PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

Plane partition [[4, 3, 3, 1], [2, 1, 1], [1, 1]] 

""" 

return "Plane partition {}".format(list(self)) 

 

def to_tableau(self): 

r""" 

Return the tableau class of ``self``. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: PP.to_tableau() 

[[4, 3, 3, 1], [2, 1, 1], [1, 1]] 

""" 

return Tableau(self) 

 

def z_tableau(self): 

r""" 

Return the projection of ``self`` in the `z` direction. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: PP.z_tableau() 

[[4, 3, 3, 1], [2, 1, 1, 0], [1, 1, 0, 0]] 

""" 

Z = [[0 for i in range(self._max_y)] for j in range(self._max_x)] 

for C in self.cells(): 

Z[C[0]][C[1]] += 1 

return Z 

 

def y_tableau(self): 

r""" 

Return the projection of ``self`` in the `y` direction. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: PP.y_tableau() 

[[4, 3, 2], [3, 1, 0], [3, 0, 0], [1, 0, 0]] 

""" 

Y = [[0 for i in range(self._max_x)] for j in range(self._max_z)] 

for C in self.cells(): 

Y[C[2]][C[0]] += 1 

return Y 

 

def x_tableau(self): 

r""" 

Return the projection of ``self`` in the `x` direction. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: PP.x_tableau() 

[[3, 2, 1, 1], [3, 1, 1, 0], [2, 1, 1, 0], [1, 0, 0, 0]] 

""" 

X = [[0 for i in range(self._max_z)] for j in range(self._max_y)] 

for C in self.cells(): 

X[C[1]][C[2]] += 1 

return X 

 

def cells(self): 

r""" 

Return the list of cells inside ``self``. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[3,1],[2]]) 

sage: PP.cells() 

[[0, 0, 0], [0, 0, 1], [0, 0, 2], [0, 1, 0], [1, 0, 0], [1, 0, 1]] 

""" 

L = [] 

for r in range(len(self)): 

for c in range(len(self[r])): 

for h in range(self[r][c]): 

L.append([r,c,h]) 

return L 

 

def _repr_diagram(self, show_box=False, use_unicode=False): 

r""" 

Return a string of the 3D diagram of ``self``. 

 

INPUT: 

 

- ``show_box`` -- boolean (default: ``False``); if ``True``, 

also shows the visible tiles on the `xy`-, `yz`-, `zx`-planes 

- ``use_unicode`` -- boolean (default: ``False``); use unicode 

 

OUTPUT: 

 

A string of the 3D diagram of the plane partition. 

 

EXAMPLES:: 

 

sage: print(PlanePartition([[4,3,3,1],[2,1,1],[1,1]])._repr_diagram()) 

__ 

/\_\ 

__/\/_/ 

__/\_\/\_\ 

/\_\/_/\/\_\ 

\/\_\_\/\/_/ 

\/_/\_\/_/ 

\/_/\_\ 

\/_/ 

sage: print(PlanePartition([[4,3,3,1],[2,1,1],[1,1]])._repr_diagram(True)) 

______ 

/_/_/\_\ 

/_/_/\/_/\ 

/_/\_\/\_\/\ 

/\_\/_/\/\_\/\ 

\/\_\_\/\/_/\/ 

\/_/\_\/_/\/ 

\_\/_/\_\/ 

\_\_\/_/ 

""" 

x = self._max_x 

y = self._max_y 

z = self._max_z 

 

drawing = [[" " for i in range(2 * x + y + z)] 

for j in range(y + z + 1)] 

 

hori = u"_" if use_unicode else "_" 

down = u"╲" if use_unicode else "\\" 

up = u"╱" if use_unicode else "/" 

 

def superpose(l, c, letter): 

# add the given letter at line l and column c 

exist = drawing[l][c] 

if exist == " " or exist == "_": 

drawing[l][c] = letter 

 

def add_topside(i, j, k): 

X = z + j - k 

Y = 2 * x - 2 * i + j + k 

superpose(X, Y-2, hori) 

superpose(X, Y-1, hori) 

superpose(X + 1, Y-2, down) 

superpose(X + 1, Y-1, hori) 

superpose(X + 1, Y, down) 

 

def add_rightside(i, j, k): 

X = z + j - k 

Y = 2 * x - 2 * i + j + k 

superpose(X - 1, Y - 1, hori) 

superpose(X - 1, Y, hori) 

superpose(X, Y - 2, up) 

superpose(X, Y - 1, hori) 

superpose(X, Y, up) 

 

def add_leftside(i, j, k): 

X = z + j - k 

Y = 2 * x - 2 * i + j + k 

superpose(X, Y, up) 

superpose(X, Y + 1, down) 

superpose(X + 1, Y + 1, up) 

superpose(X + 1, Y, down) 

 

tab = self.z_tableau() 

for r in range(len(tab)): 

for c in range(len(tab[r])): 

if tab[r][c] > 0 or show_box: 

add_topside(r, c, tab[r][c]) 

 

tab = self.y_tableau() 

for r in range(len(tab)): 

for c in range(len(tab[r])): 

if self.y_tableau()[r][c] > 0 or show_box: 

add_rightside(c, tab[r][c], r) 

 

tab = self.x_tableau() 

for r in range(len(tab)): 

for c in range(len(tab[r])): 

if self.x_tableau()[r][c] > 0 or show_box: 

add_leftside(tab[r][c], r, c) 

 

check = not show_box 

while check: 

if drawing and all(char == " " for char in drawing[-1]): 

drawing.pop() 

else: 

check = False 

 

if not drawing: 

return u"∅" if use_unicode else "" 

 

if use_unicode: 

return u'\n'.join(u"".join(s for s in row) for row in drawing) 

return '\n'.join("".join(s for s in row) for row in drawing) 

 

def _ascii_art_(self): 

r""" 

Return an ascii art representation of ``self``. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: ascii_art(PP) 

__ 

/\_\ 

__/\/_/ 

__/\_\/\_\ 

/\_\/_/\/\_\ 

\/\_\_\/\/_/ 

\/_/\_\/_/ 

\/_/\_\ 

\/_/ 

""" 

from sage.typeset.ascii_art import AsciiArt 

return AsciiArt(self._repr_diagram().splitlines(), baseline=0) 

 

def _unicode_art_(self): 

r""" 

Return a unicode representation of ``self``. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: unicode_art(PP) 

__ 

╱╲_╲ 

__╱╲╱_╱ 

__╱╲_╲╱╲_╲ 

╱╲_╲╱_╱╲╱╲_╲ 

╲╱╲_╲_╲╱╲╱_╱ 

╲╱_╱╲_╲╱_╱ 

╲╱_╱╲_╲ 

╲╱_╱ 

""" 

from sage.typeset.unicode_art import UnicodeArt 

return UnicodeArt(self._repr_diagram(use_unicode=True).splitlines(), baseline=0) 

 

def pp(self, show_box=False): 

r""" 

Return a pretty print of the plane partition. 

 

INPUT: 

 

- ``show_box`` -- boolean (default: ``False``); if ``True``, 

also shows the visible tiles on the `xy`-, `yz`-, `zx`-planes 

 

OUTPUT: 

 

A pretty print of the plane partition. 

 

EXAMPLES:: 

 

sage: PlanePartition([[4,3,3,1],[2,1,1],[1,1]]).pp() 

__ 

/\_\ 

__/\/_/ 

__/\_\/\_\ 

/\_\/_/\/\_\ 

\/\_\_\/\/_/ 

\/_/\_\/_/ 

\/_/\_\ 

\/_/ 

sage: PlanePartition([[4,3,3,1],[2,1,1],[1,1]]).pp(True) 

______ 

/_/_/\_\ 

/_/_/\/_/\ 

/_/\_\/\_\/\ 

/\_\/_/\/\_\/\ 

\/\_\_\/\/_/\/ 

\/_/\_\/_/\/ 

\_\/_/\_\/ 

\_\_\/_/ 

""" 

print(self._repr_diagram(show_box)) 

 

def _latex_(self, show_box=False, colors=["white","lightgray","darkgray"]): 

r""" 

Return latex code for ``self``, which uses TikZ package to draw 

the plane partition. 

 

INPUT: 

 

- ``show_box`` -- boolean (default: ``False``); if ``True``, 

also shows the visible tiles on the `xy`-, `yz`-, `zx`-planes 

 

- ``colors`` -- (default: ``["white", "lightgray", "darkgray"]``) 

list ``[A, B, C]`` of 3 strings representing colors 

 

OUTPUT: 

 

Latex code for drawing the plane partition. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[1]]) 

sage: latex(PP) 

\begin{tikzpicture} 

\draw[fill=white,shift={(210:0)},shift={(-30:0)},shift={(90:1)}] 

(0,0)--(-30:1)--(0,-1)--(210:1)--(0,0); 

\draw[fill=darkgray,shift={(210:0)},shift={(-30:1)},shift={(90:0)}] 

(0,0)--(210:1)--(150:1)--(0,1)--(0,0); 

\draw[fill=lightgray,shift={(210:1)},shift={(-30:0)},shift={(90:0)}] 

(0,0)--(0,1)--(30:1)--(-30:1)--(0,0); 

\end{tikzpicture} 

""" 

from sage.graphs.graph_latex import setup_latex_preamble 

setup_latex_preamble() 

 

x = self._max_x 

y = self._max_y 

z = self._max_z 

ret = "\\begin{tikzpicture}\n" 

def add_topside(i,j,k): 

return "\\draw[fill={},shift={{(210:{})}},shift={{(-30:{})}},shift={{(90:{})}}]\n(0,0)--(-30:1)--(0,-1)--(210:1)--(0,0);\n".format(colors[0],i,j,k) 

def add_leftside(j,k,i): 

return "\\draw[fill={},shift={{(210:{})}},shift={{(-30:{})}},shift={{(90:{})}}]\n(0,0)--(0,1)--(30:1)--(-30:1)--(0,0);\n".format(colors[1],i,j,k) 

def add_rightside(k,i,j): 

return "\\draw[fill={},shift={{(210:{})}},shift={{(-30:{})}},shift={{(90:{})}}]\n(0,0)--(210:1)--(150:1)--(0,1)--(0,0);\n".format(colors[2],i,j,k) 

funcs = [add_topside, add_rightside, add_leftside] 

tableaux = [self.z_tableau(), self.y_tableau(), self.x_tableau()] 

for i in range(3): 

f = funcs[i] 

tab = tableaux[i] 

for r in range(len(tab)): 

for c in range(len(tab[r])): 

if tab[r][c] > 0 or show_box: 

ret += f(r, c, tab[r][c]) 

return ret + "\\end{tikzpicture}" 

 

def plot(self, show_box=False, colors=["white","lightgray","darkgray"]): 

r""" 

Return a plot of ``self``. 

 

INPUT: 

 

- ``show_box`` -- boolean (default: ``False``); if ``True``, 

also shows the visible tiles on the `xy`-, `yz`-, `zx`-planes 

 

- ``colors`` -- (default: ``["white", "lightgray", "darkgray"]``) 

list ``[A, B, C]`` of 3 strings representing colors 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: PP.plot() 

Graphics object consisting of 27 graphics primitives 

""" 

x = self._max_x 

y = self._max_y 

z = self._max_z 

from sage.functions.trig import cos, sin 

from sage.plot.polygon import polygon 

from sage.symbolic.constants import pi 

from sage.plot.plot import plot 

Uside = [[0,0], [cos(-pi/6),sin(-pi/6)], [0,-1], [cos(7*pi/6),sin(7*pi/6)]] 

Lside = [[0,0], [cos(-pi/6),sin(-pi/6)], [cos(pi/6),sin(pi/6)], [0,1]] 

Rside = [[0,0], [0,1], [cos(5*pi/6),sin(5*pi/6)], [cos(7*pi/6),sin(7*pi/6)]] 

Xdir = [cos(7*pi/6), sin(7*pi/6)] 

Ydir = [cos(-pi/6), sin(-pi/6)] 

Zdir = [0, 1] 

def move(side, i, j, k): 

return [[P[0]+i*Xdir[0]+j*Ydir[0]+k*Zdir[0], 

P[1]+i*Xdir[1]+j*Ydir[1]+k*Zdir[1]] 

for P in side] 

def add_topside(i, j, k): 

return polygon(move(Uside,i,j,k), edgecolor="black", color=colors[0]) 

def add_leftside(i, j, k): 

return polygon(move(Lside,i,j,k), edgecolor="black", color=colors[1]) 

def add_rightside(i, j, k): 

return polygon(move(Rside,i,j,k), edgecolor="black", color=colors[2]) 

TP = plot([]) 

for r in range(len(self.z_tableau())): 

for c in range(len(self.z_tableau()[r])): 

if self.z_tableau()[r][c] > 0 or show_box: 

TP += add_topside(r, c, self.z_tableau()[r][c]) 

for r in range(len(self.y_tableau())): 

for c in range(len(self.y_tableau()[r])): 

if self.y_tableau()[r][c] > 0 or show_box: 

TP += add_rightside(c, self.y_tableau()[r][c], r) 

for r in range(len(self.x_tableau())): 

for c in range(len(self.x_tableau()[r])): 

if self.x_tableau()[r][c] > 0 or show_box: 

TP += add_leftside(self.x_tableau()[r][c], r, c) 

TP.axes(show=False) 

return TP 

 

def complement(self, tableau_only=False): 

r""" 

Return the complement of ``self``. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: PP.complement() 

Plane partition [[4, 4, 3, 3], [4, 3, 3, 2], [3, 1, 1, 0]] 

sage: PP.complement(True) 

[[4, 4, 3, 3], [4, 3, 3, 2], [3, 1, 1, 0]] 

""" 

A = self._max_x 

B = self._max_y 

C = self._max_z 

T = [[C for i in range(B)] for j in range(A)] 

z_tab = self.z_tableau() 

for r in range(A): 

for c in range(B): 

T[A-1-r][B-1-c] = C - z_tab[r][c] 

if tableau_only: 

return T 

else: 

return type(self)(self.parent(), T, check=False) 

 

def transpose(self, tableau_only=False): 

r""" 

Return the transpose of ``self``. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: PP.transpose() 

Plane partition [[4, 2, 1], [3, 1, 1], [3, 1, 0], [1, 0, 0]] 

sage: PP.transpose(True) 

[[4, 2, 1], [3, 1, 1], [3, 1, 0], [1, 0, 0]] 

""" 

T = [[0 for i in range(self._max_x)] for j in range(self._max_y)] 

z_tab = self.z_tableau() 

for r in range(len(z_tab)): 

for c in range(len(z_tab[r])): 

T[c][r] = z_tab[r][c] 

if tableau_only: 

return T 

else: 

return type(self)(self.parent(), T, check=False) 

 

def is_SPP(self): 

r""" 

Return whether ``self`` is a symmetric plane partition. 

 

A plane partition is symmetric if the corresponding tableau is 

symmetric about the diagonal. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: PP.is_SPP() 

False 

sage: PP = PlanePartition([[3,3,2],[3,3,2],[2,2,2]]) 

sage: PP.is_SPP() 

True 

""" 

z_tab = self.z_tableau() 

return all(z_tab[r][c] == z_tab[c][r] 

for r in range(len(z_tab)) 

for c in range(r, len(z_tab[r]))) 

 

def is_CSPP(self): 

r""" 

Return whether ``self`` is a cyclically symmetric plane partition. 

 

A plane partition is cyclically symmetric if its `x`, `y`, and `z` 

tableaux are all equal. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: PP.is_CSPP() 

False 

sage: PP = PlanePartition([[3,2,2],[3,1,0],[1,1,0]]) 

sage: PP.is_CSPP() 

True 

""" 

if self.z_tableau() == self.y_tableau(): 

return True 

return False 

 

def is_TSPP(self): 

r""" 

Return whether ``self`` is a totally symmetric plane partition. 

 

A plane partition is totally symmetric if it is both symmetric and 

cyclically symmetric. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: PP.is_TSPP() 

False 

sage: PP = PlanePartition([[3,3,3],[3,3,2],[3,2,1]]) 

sage: PP.is_TSPP() 

True 

""" 

return self.is_CSPP() and self.is_SPP() 

 

def is_SCPP(self): 

r""" 

Return whether ``self`` is a self-complementary plane partition. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: PP.is_SCPP() 

False 

sage: PP = PlanePartition([[4,4,4,4],[4,4,2,0],[4,2,0,0],[0,0,0,0]]) 

sage: PP.is_SCPP() 

True 

""" 

return self.z_tableau() == self.complement(True) 

 

def is_TCPP(self): 

r""" 

Return whether ``self`` is a transpose-complementary plane partition. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: PP.is_TCPP() 

False 

sage: PP = PlanePartition([[4,4,3,2],[4,4,2,1],[4,2,0,0],[2,0,0,0]]) 

sage: PP.is_TCPP() 

True 

""" 

return self.transpose(True) == self.complement(True) 

 

def is_SSCPP(self): 

r""" 

Return whether ``self`` is a symmetric, self-complementary 

plane partition. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: PP.is_SSCPP() 

False 

sage: PP = PlanePartition([[4,3,3,2],[3,2,2,1],[3,2,2,1],[2,1,1,0]]) 

sage: PP.is_SSCPP() 

True 

""" 

return self.is_SPP() and self.is_SCPP() 

 

def is_CSTCPP(self): 

r""" 

Return whether ``self`` is a cyclically symmetric and 

transpose-complementary plane partition. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: PP.is_CSTCPP() 

False 

sage: PP = PlanePartition([[4,4,3,2],[4,3,2,1],[3,2,1,0],[2,1,0,0]]) 

sage: PP.is_CSTCPP() 

True 

""" 

return self.is_CSPP() and self.is_TCPP() 

 

def is_CSSCPP(self): 

r""" 

Return whether ``self`` is a cyclically symmetric and 

self-complementary plane partition. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: PP.is_CSSCPP() 

False 

sage: PP = PlanePartition([[4,4,4,1],[3,3,2,1],[3,2,1,1],[3,0,0,0]]) 

sage: PP.is_CSSCPP() 

True 

""" 

return self.is_CSPP() and self.is_SCPP() 

 

def is_TSSCPP(self): 

r""" 

Return whether ``self`` is a totally symmetric self-complementary 

plane partition. 

 

EXAMPLES:: 

 

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) 

sage: PP.is_TSSCPP() 

False 

sage: PP = PlanePartition([[4,4,3,2],[4,3,2,1],[3,2,1,0],[2,1,0,0]]) 

sage: PP.is_TSSCPP() 

True 

""" 

return self.is_TSPP() and self.is_SCPP() 

 

class PlanePartitions(UniqueRepresentation, Parent): 

r""" 

All plane partitions inside a rectangular box of given side lengths. 

 

INPUT: 

 

- ``box_size`` -- a triple of positive integers indicating the size 

of the box containing the plane partition 

 

EXAMPLES: 

 

This will create an instance to manipulate the plane partitions 

in a `4 \times 3 \times 2` box:: 

 

sage: P = PlanePartitions((4,3,2)) 

sage: P 

Plane partitions inside a 4 x 3 x 2 box 

sage: P.cardinality() 

490 

 

.. SEEALSO:: 

 

:class:`PlanePartition` 

""" 

@staticmethod 

def __classcall_private__(cls, box_size): 

""" 

Normalize input to ensure a unique representation. 

 

EXAMPLES:: 

 

sage: P1 = PlanePartitions((4,3,2)) 

sage: P2 = PlanePartitions([4,3,2]) 

sage: P1 is P2 

True 

""" 

return super(PlanePartitions, cls).__classcall__(cls, tuple(box_size)) 

 

def __init__(self, box_size): 

r""" 

Initialize ``self`` 

 

EXAMPLES:: 

 

sage: PP = PlanePartitions((4,3,2)) 

sage: TestSuite(PP).run() 

""" 

if len(box_size) != 3: 

raise ValueError("invalid box size") 

self._box = box_size 

Parent.__init__(self, category=FiniteEnumeratedSets()) 

 

def _repr_(self): 

""" 

Return a string representation of ``self``. 

 

EXAMPLES:: 

 

sage: PlanePartitions((4,3,2)) 

Plane partitions inside a 4 x 3 x 2 box 

""" 

return "Plane partitions inside a {} x {} x {} box".format( 

self._box[0], self._box[1], self._box[2]) 

 

def __iter__(self): 

""" 

Iterate over ``self``. 

 

EXAMPLES:: 

 

sage: list(PlanePartitions((1,2,1))) 

[Plane partition [[0, 0]], 

Plane partition [[1, 0]], 

Plane partition [[1, 1]]] 

""" 

A = self._box[0] 

B = self._box[1] 

C = self._box[2] 

from sage.combinat.tableau import SemistandardTableaux 

for T in SemistandardTableaux([B for i in range(A)], max_entry=C+A): 

PP = [[0 for i in range(B)] for j in range(A)] 

for r in range(A): 

for c in range(B): 

PP[A-1-r][B-1-c] = T[r][c] - r - 1 

yield self.element_class(self, PP, check=False) 

 

def cardinality(self): 

r""" 

Return the cardinality of ``self``. 

 

The number of plane partitions inside an `a \times b \times c` 

box is equal to 

 

.. MATH:: 

 

\prod_{i=1}^{a} \prod_{j=1}^{b} \prod_{k=1}^{c} 

\frac{i+j+k-1}{i+j+k-2}. 

 

EXAMPLES:: 

 

sage: P = PlanePartitions((4,3,5)) 

sage: P.cardinality() 

116424 

""" 

A = self._box[0] 

B = self._box[1] 

C = self._box[2] 

return Integer(prod( Integer(i+j+k-1) / Integer(i+j+k-2) 

for i in range(1, A+1) for j in range(1, B+1) 

for k in range(1, C+1) )) 

 

def box(self): 

""" 

Return the sizes of the box of the plane partitions of ``self`` 

are contained in. 

 

EXAMPLES:: 

 

sage: P = PlanePartitions((4,3,5)) 

sage: P.box() 

(4, 3, 5) 

""" 

return self._box 

 

def random_element(self): 

r""" 

Return a uniformly random element of ``self``. 

 

ALGORITHM: 

 

This uses the 

:meth:`~sage.combinat.posets.posets.FinitePoset.random_order_ideal` 

method and the natural bijection with plane partitions. 

 

EXAMPLES:: 

 

sage: P = PlanePartitions((4,3,5)) 

sage: P.random_element() 

Plane partition [[4, 3, 3], [4, 0, 0], [2, 0, 0], [0, 0, 0]] 

""" 

def leq(thing1, thing2): 

return all(thing1[i] <= thing2[i] for i in range(len(thing1))) 

elem = [(i,j,k) for i in range(self._box[0]) for j in range(self._box[1]) 

for k in range(self._box[2])] 

myposet = Poset((elem, leq)) 

R = myposet.random_order_ideal() 

Z = [[0 for i in range(self._box[1])] for j in range(self._box[0])] 

for C in R: 

Z[C[0]][C[1]] += 1 

return self.element_class(self, Z, check=False) 

 

Element = PlanePartition