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

r""" 

An interface to Anders Buch's Littlewood-Richardson Calculator ``lrcalc`` 

  

The "Littlewood-Richardson Calculator" is a C library for fast 

computation of Littlewood-Richardson (LR) coefficients and products of 

Schubert polynomials. It handles single LR coefficients, products of 

and coproducts of Schur functions, skew Schur functions, and 

fusion products. All of the above are achieved by counting LR 

(skew)-tableaux (also called Yamanouchi (skew)-tableaux) of 

appropriate shape and content by iterating through them. 

Additionally, ``lrcalc`` handles products of Schubert polynomials. 

  

The web page of ``lrcalc`` is `<http://math.rutgers.edu/~asbuch/lrcalc/>`_. 

  

The following describes the Sage interface to this library. 

  

EXAMPLES:: 

  

sage: import sage.libs.lrcalc.lrcalc as lrcalc 

  

Compute a single Littlewood-Richardson coefficient:: 

  

sage: lrcalc.lrcoef([3,2,1],[2,1],[2,1]) 

2 

  

Compute a product of Schur functions; return the coefficients in the 

Schur expansion:: 

  

sage: lrcalc.mult([2,1], [2,1]) 

{[2, 2, 1, 1]: 1, 

[2, 2, 2]: 1, 

[3, 1, 1, 1]: 1, 

[3, 2, 1]: 2, 

[3, 3]: 1, 

[4, 1, 1]: 1, 

[4, 2]: 1} 

  

Same product, but include only partitions with at most 3 rows. This 

corresponds to computing in the representation ring of gl(3):: 

  

sage: lrcalc.mult([2,1], [2,1], 3) 

{[2, 2, 2]: 1, [3, 2, 1]: 2, [3, 3]: 1, [4, 1, 1]: 1, [4, 2]: 1} 

  

We can also compute the fusion product, here for sl(3) and level 2:: 

  

sage: lrcalc.mult([3,2,1], [3,2,1], 3,2) 

{[4, 4, 4]: 1, [5, 4, 3]: 1} 

  

Compute the expansion of a skew Schur function:: 

  

sage: lrcalc.skew([3,2,1],[2,1]) 

{[1, 1, 1]: 1, [2, 1]: 2, [3]: 1} 

  

Compute the coproduct of a Schur function:: 

  

sage: lrcalc.coprod([3,2,1]) 

{([1, 1, 1], [2, 1]): 1, 

([2, 1], [2, 1]): 2, 

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

([2, 1, 1], [1, 1]): 1, 

([2, 1, 1], [2]): 1, 

([2, 2], [1, 1]): 1, 

([2, 2], [2]): 1, 

([2, 2, 1], [1]): 1, 

([3, 1], [1, 1]): 1, 

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

([3, 1, 1], [1]): 1, 

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

([3, 2, 1], []): 1} 

  

Multiply two Schubert polynomials:: 

  

sage: lrcalc.mult_schubert([4,2,1,3], [1,4,2,5,3]) 

{[4, 5, 1, 3, 2]: 1, 

[5, 3, 1, 4, 2]: 1, 

[5, 4, 1, 2, 3]: 1, 

[6, 2, 1, 4, 3, 5]: 1} 

  

Same product, but include only permutations of 5 elements in the result. 

This corresponds to computing in the cohomology ring of Fl(5):: 

  

sage: lrcalc.mult_schubert([4,2,1,3], [1,4,2,5,3], 5) 

{[4, 5, 1, 3, 2]: 1, [5, 3, 1, 4, 2]: 1, [5, 4, 1, 2, 3]: 1} 

  

List all Littlewood-Richardson tableaux of skew shape `\mu/\nu`; in 

this example `\mu=[3,2,1]` and `\nu=[2,1]`. Specifying a third entry 

`maxrows` restricts the alphabet to `\{1,2,\ldots,maxrows\}`:: 

  

sage: list(lrcalc.lrskew([3,2,1],[2,1])) 

[[[None, None, 1], [None, 1], [1]], [[None, None, 1], [None, 1], [2]], 

[[None, None, 1], [None, 2], [1]], [[None, None, 1], [None, 2], [3]]] 

  

sage: list(lrcalc.lrskew([3,2,1],[2,1],maxrows=2)) 

[[[None, None, 1], [None, 1], [1]], [[None, None, 1], [None, 1], [2]], [[None, None, 1], [None, 2], [1]]] 

  

.. todo:: use this library in the :class:`SymmetricFunctions` code, to 

make it easy to apply it to linear combinations of Schur functions. 

  

.. SEEALSO:: 

  

- :func:`lrcoef` 

 

- :func:`mult` 

 

- :func:`coprod` 

 

- :func:`skew` 

 

- :func:`lrskew` 

 

- :func:`mult_schubert` 

  

.. rubric:: Underlying algorithmic in lrcalc 

  

Here is some additional information regarding the main low-level 

C-functions in `lrcalc`. Given two partitions ``outer`` and ``inner`` 

with ``inner`` contained in ``outer``, the function:: 

  

skewtab *st_new(vector *outer, vector *inner, vector *conts, int maxrows) 

  

constructs and returns the (lexicographically) first LR skew tableau 

of shape ``outer / inner``. Further restrictions can be imposed using 

``conts`` and ``maxrows``. 

  

Namely, the integer ``maxrows`` is a bound on the integers that can be 

put in the tableau. The name is chosen because this will limit the 

partitions in the output of :func:`skew` or :func:`mult` to partitions 

with at most this number of rows. 

  

The vector ``conts`` is the content of an empty tableau(!!). More 

precisely, this vector is added to the usual content of a tableau 

whenever the content is needed. This affects which tableaux are 

considered LR tableaux (see :func:`mult` below). ``conts`` may also 

be the ``NULL`` pointer, in which case nothing is added. 

  

The other function:: 

  

int *st_next(skewtab *st) 

  

computes in place the (lexicographically) next skew tableau with the 

same constraints, or returns 0 if ``st`` is the last one. 

  

For a first example, see the :func:`skew` function code in the 

``lrcalc`` source code. We want to compute a skew Schur function, so 

create a skew LR tableau of the appropriate shape with ``st_new`` 

(with ``conts = NULL``), then iterate through all the LR tableaux with 

``st_next()``. For each skew tableau, we use that ``st->conts`` is the 

content of the skew tableau, find this shape in the ``res`` hash table 

and add one to the value. 

  

For a second example, see ``mult(vector *sh1, vector *sh2, maxrows)``. 

Here we call ``st_new()`` with the shape ``sh1 / (0)`` and use ``sh2`` 

as the ``conts`` argument. The effect of using ``sh2`` in this way is 

that ``st_next`` will iterate through semistandard tableaux `T` of 

shape ``sh1`` such that the following tableau:: 

  

111111 

22222 <--- minimal tableau of shape sh2 

333 

***** 

**T** 

**** 

** 

  

is a LR skew tableau, and ``st->conts`` contains the content of the 

combined tableaux. 

  

More generally, ``st_new(outer, inner, conts, maxrows)`` and 

``st_next`` can be used to compute the Schur expansion of the product 

``S_{outer/inner} * S_conts``, restricted to partitions with at most 

``maxrows`` rows. 

  

AUTHORS: 

  

- Mike Hansen (2010): core of the interface 

  

- Anne Schilling, Nicolas M. Thiéry, and Anders Buch (2011): fusion 

product, iterating through LR tableaux, finalization, documentation 

  

""" 

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

# Copyright (C) 2010 Mike Hansen <mhansen@gmail.com> 

# 

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

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

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

  

from sage.rings.integer cimport Integer 

from sage.structure.parent cimport Parent 

from sage.combinat.partition import _Partitions 

from sage.combinat.permutation import Permutation 

from sage.combinat.skew_tableau import SkewTableau 

  

cdef vector* iterable_to_vector(it): 

""" 

Return an lrcalc vector (which is a list of integers) from a Python iterable. 

  

TESTS:: 

  

sage: from sage.libs.lrcalc.lrcalc import test_iterable_to_vector 

sage: x = test_iterable_to_vector(Partition([3,2,1])); x #indirect doctest 

[3, 2, 1] 

""" 

cdef vector* v 

cdef list itr = list(it) 

cdef int n = len(itr) 

cdef int i 

v = v_new(n) 

for i from 0 <= i < n: 

v.array[i] = int(itr[i]) 

return v 

  

cdef list vector_to_list(vector *v): 

""" 

Converts a lrcalc vector to Python list. 

  

TESTS:: 

  

sage: from sage.libs.lrcalc.lrcalc import test_iterable_to_vector 

sage: x = test_iterable_to_vector([]); x #indirect doctest 

[] 

""" 

cdef int i, n 

n = v_length(v) 

cdef list result = [None]*n 

for i from 0 <= i < n: 

result[i] = Integer(v_elem(v, i)) 

return result 

  

def test_iterable_to_vector(it): 

""" 

A wrapper function for the cdef function ``iterable_to_vector`` 

and ``vector_to_list``, to test that they are working correctly. 

  

EXAMPLES:: 

  

sage: from sage.libs.lrcalc.lrcalc import test_iterable_to_vector 

sage: x = test_iterable_to_vector([3,2,1]); x 

[3, 2, 1] 

""" 

cdef vector *v = iterable_to_vector(it) 

result = vector_to_list(v) 

v_free(v) 

return result 

  

cdef skewtab_to_SkewTableau(skewtab *st): 

""" 

A wrapper function which transforms the data set ``st`` used in 

``lrcalc`` to a ``SkewTableau`` in Sage. 

  

TESTS:: 

  

sage: from sage.libs.lrcalc.lrcalc import test_skewtab_to_SkewTableau 

sage: test_skewtab_to_SkewTableau([],[]) 

[] 

""" 

inner = vector_to_list(st.inner) 

outer = vector_to_list(st.outer) 

return SkewTableau(expr=[[inner[y] for y in range(len(outer))], 

[[st.matrix[x + y * st.cols] + 1 

for x in range(inner[y], outer[y])] 

for y in range(len(outer) - 1, -1, -1)]]) 

  

def test_skewtab_to_SkewTableau(outer, inner): 

""" 

A wrapper function for the cdef function ``skewtab_to_SkewTableau`` 

for testing purposes. 

  

It constructs the first LR skew tableau of shape ``outer/inner`` 

as an ``lrcalc`` ``skewtab``, and converts it to a 

:class:`SkewTableau`. 

  

EXAMPLES:: 

  

sage: from sage.libs.lrcalc.lrcalc import test_skewtab_to_SkewTableau 

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

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

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

. 1 1 1 

. 2 2 

1 3 

2 

""" 

cdef vector* o = iterable_to_vector(outer) 

cdef vector* i = iterable_to_vector(inner+[0]*(len(outer)-len(inner))) 

cdef skewtab* st = st_new(o, i, NULL, 0) 

return skewtab_to_SkewTableau(st) 

  

cdef dict sf_hashtab_to_dict(hashtab *ht): 

""" 

Return a dictionary representing a Schur function. The keys are 

partitions and the values are integers <type 'sage.rings.integer.Integer'>. 

  

EXAMPLES:: 

  

sage: from sage.libs.lrcalc.lrcalc import mult 

sage: sorted(mult([1],[1]).items()) #indirect doctest 

[([1, 1], 1), ([2], 1)] 

sage: assert isinstance(mult([1],[1]),dict)#indirect doctest 

""" 

cdef hash_itr itr 

cdef dict result = {} 

cdef list p 

hash_first(ht, itr) 

while hash_good(itr): 

p = vector_to_list(<vector*> hash_key(itr)) 

result[_Partitions(p)] = Integer(hash_intvalue(itr)) 

hash_next(itr) 

return result 

  

cdef dict schubert_hashtab_to_dict(hashtab *ht): 

""" 

Return a dictionary corresponding to a Schubert polynomial whose keys 

are permutations and whose values are integers <type 'sage.rings.integer.Integer'>. 

  

EXAMPLES:: 

  

sage: from sage.libs.lrcalc.lrcalc import mult_schubert 

sage: mult_schubert([3,2,1], [1,2,3]) #indirect doctest 

{[3, 2, 1]: 1} 

""" 

cdef hash_itr itr 

cdef dict result = {} 

hash_first(ht, itr) 

while hash_good(itr): 

p = vector_to_list(<vector*> hash_key(itr)) 

result[Permutation(p)] = Integer(hash_intvalue(itr)) 

hash_next(itr) 

return result 

  

  

cdef dict vp_hashtab_to_dict(hashtab *ht): 

""" 

Return a dictionary corresponding to the coproduct of a Schur function whose keys are 

pairs of partitions and whose values are integers <type 'sage.rings.integer.Integer'>. 

  

EXAMPLES:: 

  

sage: from sage.libs.lrcalc.lrcalc import coprod 

sage: coprod([1]) #indirect doctest 

{([1], []): 1} 

""" 

cdef hash_itr itr 

cdef vecpair* vp 

cdef dict result = {} 

hash_first(ht, itr) 

while hash_good(itr): 

vp = <vecpair*> hash_key(itr) 

p1 = _Partitions(vector_to_list(vp_first(vp))) 

p2 = _Partitions(vector_to_list(vp_second(vp))) 

result[(p1, p2)] = Integer(hash_intvalue(itr)) 

hash_next(itr) 

return result 

  

def lrcoef_unsafe(outer, inner1, inner2): 

r""" 

Compute a single Littlewood-Richardson coefficient. 

  

Return the coefficient of ``outer`` in the product of the Schur 

functions indexed by ``inner1`` and ``inner2``. 

  

INPUT: 

  

- ``outer`` -- a partition (weakly decreasing list of non-negative integers). 

  

- ``inner1`` -- a partition. 

  

- ``inner2`` -- a partition. 

  

.. warning:: 

  

This function does not do any check on its input. If you want 

to use a safer version, use :func:`lrcoef`. 

  

EXAMPLES:: 

  

sage: from sage.libs.lrcalc.lrcalc import lrcoef_unsafe 

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

2 

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

1 

sage: lrcoef_unsafe([2,1,1,1,1], [2,1], [2,1]) 

0 

""" 

cdef long long result 

cdef vector *o 

cdef vector *i1 

cdef vector *i2 

o = iterable_to_vector(outer) 

i1 = iterable_to_vector(inner1) 

i2 = iterable_to_vector(inner2) 

result = lrcoef_c(o, i1, i2) 

v_free(o); v_free(i1); v_free(i2) 

return Integer(result) 

  

def lrcoef(outer, inner1, inner2): 

""" 

Compute a single Littlewood-Richardson coefficient. 

  

Return the coefficient of ``outer`` in the product of the Schur 

functions indexed by ``inner1`` and ``inner2``. 

  

INPUT: 

  

- ``outer`` -- a partition (weakly decreasing list of non-negative integers). 

  

- ``inner1`` -- a partition. 

  

- ``inner2`` -- a partition. 

  

.. NOTE:: 

  

This function converts its inputs into :func:`Partition`'s. If 

you don't need these checks and your inputs are valid, then you 

can use :func:`lrcoef_unsafe`. 

  

EXAMPLES:: 

  

sage: from sage.libs.lrcalc.lrcalc import lrcoef 

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

2 

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

1 

sage: lrcoef([2,1,1,1,1], [2,1], [2,1]) 

0 

  

""" 

return lrcoef_unsafe(_Partitions(outer), _Partitions(inner1), _Partitions(inner2)) 

  

def mult(part1, part2, maxrows=None, level=None, quantum=None): 

r""" 

Compute a product of two Schur functions. 

  

Return the product of the Schur functions indexed by the 

partitions ``part1`` and ``part2``. 

  

INPUT: 

  

- ``part1`` -- a partition 

  

- ``part2`` -- a partition 

  

- ``maxrows`` -- (optional) an integer 

  

- ``level`` -- (optional) an integer 

  

- ``quantum`` -- (optional) an element of a ring 

  

If ``maxrows`` is specified, then only partitions with at most 

this number of rows are included in the result. 

  

If both ``maxrows`` and ``level`` are specified, then the function 

calculates the fusion product for `\mathfrak{sl}(\mathrm{maxrows})` 

of the given level. 

  

If ``quantum`` is set, then this returns the product in the quantum 

cohomology ring of the Grassmannian. In particular, both ``maxrows`` 

and ``level`` need to be specified. 

  

EXAMPLES:: 

  

sage: from sage.libs.lrcalc.lrcalc import mult 

sage: mult([2],[]) 

{[2]: 1} 

sage: sorted(mult([2],[2]).items()) 

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

sage: sorted(mult([2,1],[2,1]).items()) 

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

sage: sorted(mult([2,1],[2,1],maxrows=2).items()) 

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

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

{[3, 3, 3]: 1, [4, 3, 2]: 2, [4, 4, 1]: 1, [5, 2, 2]: 1, [5, 3, 1]: 1} 

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

{[2, 2, 2]: 1, [3, 2, 1]: 2, [3, 3]: 1, [4, 1, 1]: 1} 

sage: mult([2,1],[2,1],None,3) 

Traceback (most recent call last): 

... 

ValueError: maxrows needs to be specified if you specify the level 

  

The quantum product:: 

  

sage: q = polygen(QQ, 'q') 

sage: sorted(mult([1],[2,1], 2, 2, quantum=q).items()) 

[([], q), ([2, 2], 1)] 

sage: sorted(mult([2,1],[2,1], 2, 2, quantum=q).items()) 

[([1, 1], q), ([2], q)] 

  

sage: mult([2,1],[2,1], quantum=q) 

Traceback (most recent call last): 

... 

ValueError: missing parameters maxrows or level 

""" 

if maxrows is None and level is not None: 

raise ValueError('maxrows needs to be specified if you specify' 

' the level') 

if quantum is not None and (level is None or maxrows is None): 

raise ValueError('missing parameters maxrows or level') 

  

cdef vector* v1 = iterable_to_vector(part1) 

cdef vector* v2 = iterable_to_vector(part2) 

if maxrows is None: 

maxrows = 0 

cdef hashtab* ht = mult_c(v1, v2, int(maxrows)) 

cdef hashtab* tab 

cdef dict result 

  

if quantum is None: 

if level is not None: 

fusion_reduce_c(ht, int(maxrows), int(level), int(0)) 

result = sf_hashtab_to_dict(ht) 

v_free(v1) 

v_free(v2) 

hash_free(ht) 

return result 

  

# Otherwise do quantum multiplication 

cdef _list *qlist 

cdef dict temp 

qlist = quantum_reduce_c(ht, int(maxrows), int(level)) 

# The above call frees the memory associated with ht 

v_free(v1) 

v_free(v2) 

  

cdef Parent P = quantum.parent() 

result = {} 

for i in range(qlist.length): 

tab = <hashtab*>(qlist.array[i]) 

temp = sf_hashtab_to_dict(tab) 

for k in temp: 

result[k] = result.get(k, P.zero()) + quantum**i * temp[k] 

hash_free(tab) 

l_free(qlist) 

return result 

  

def skew(outer, inner, maxrows=0): 

""" 

Compute the Schur expansion of a skew Schur function. 

  

Return a linear combination of partitions representing the Schur 

function of the skew Young diagram ``outer / inner``, consisting 

of boxes in the partition ``outer`` that are not in ``inner``. 

  

INPUT: 

  

- ``outer`` -- a partition. 

  

- ``inner`` -- a partition. 

  

- ``maxrows`` -- an integer or ``None``. 

  

If ``maxrows`` is specified, then only partitions with at most 

this number of rows are included in the result. 

  

EXAMPLES:: 

  

sage: from sage.libs.lrcalc.lrcalc import skew 

sage: sorted(skew([2,1],[1]).items()) 

[([1, 1], 1), ([2], 1)] 

""" 

cdef vector* v1 = iterable_to_vector(outer) 

cdef vector* v2 = iterable_to_vector(inner) 

cdef hashtab* ht = skew_c(v1, v2, int(maxrows)) 

result = sf_hashtab_to_dict(ht) 

v_free(v1); v_free(v2); hash_free(ht) 

return result 

  

def coprod(part, all=0): 

""" 

Compute the coproduct of a Schur function. 

  

Return a linear combination of pairs of partitions representing 

the coproduct of the Schur function given by the partition 

``part``. 

  

INPUT: 

  

- ``part`` -- a partition. 

  

- ``all`` -- an integer. 

  

If ``all`` is non-zero then all terms are included in the result. 

If ``all`` is zero, then only pairs of partitions ``(part1, 

part2)`` for which the weight of ``part1`` is greater than or 

equal to the weight of ``part2`` are included; the rest of the 

coefficients are redundant because Littlewood-Richardson 

coefficients are symmetric. 

  

EXAMPLES:: 

  

sage: from sage.libs.lrcalc.lrcalc import coprod 

sage: sorted(coprod([2,1]).items()) 

[(([1, 1], [1]), 1), (([2], [1]), 1), (([2, 1], []), 1)] 

""" 

cdef vector* v1 = iterable_to_vector(part) 

cdef hashtab* ht = coprod_c(v1, int(all)) 

result = vp_hashtab_to_dict(ht) 

v_free(v1); hash_free(ht) 

return result 

  

  

def mult_schubert(w1, w2, rank=0): 

r""" 

Compute a product of two Schubert polynomials. 

  

Return a linear combination of permutations representing the 

product of the Schubert polynomials indexed by the permutations 

``w1`` and ``w2``. 

  

INPUT: 

  

- ``w1`` -- a permutation. 

  

- ``w2`` -- a permutation. 

  

- ``rank`` -- an integer. 

  

If ``rank`` is non-zero, then only permutations from the symmetric 

group `S(\mathrm{rank})` are included in the result. 

  

EXAMPLES:: 

  

sage: from sage.libs.lrcalc.lrcalc import mult_schubert 

sage: result = mult_schubert([3, 1, 5, 2, 4], [3, 5, 2, 1, 4]) 

sage: sorted(result.items()) 

[([5, 4, 6, 1, 2, 3], 1), ([5, 6, 3, 1, 2, 4], 1), 

([5, 7, 2, 1, 3, 4, 6], 1), ([6, 3, 5, 1, 2, 4], 1), 

([6, 4, 3, 1, 2, 5], 1), ([6, 5, 2, 1, 3, 4], 1), 

([7, 3, 4, 1, 2, 5, 6], 1), ([7, 4, 2, 1, 3, 5, 6], 1)] 

""" 

cdef vector* v1 = iterable_to_vector(w1) 

cdef vector* v2 = iterable_to_vector(w2) 

cdef hashtab* ht = mult_schubert_c(v1, v2, int(rank)) 

result = schubert_hashtab_to_dict(ht) 

v_free(v1); v_free(v2); hash_free(ht) 

return result 

  

def lrskew(outer, inner, weight=None, maxrows=0): 

""" 

Return the skew LR tableaux of shape ``outer / inner``. 

  

INPUT: 

  

- ``outer`` -- a partition. 

  

- ``inner`` -- a partition. 

  

- ``weight`` -- a partition (optional). 

  

- ``maxrows`` -- an integer (optional). 

  

OUTPUT: a list of :class:`SkewTableau`x. This will change to an 

iterator over such skew tableaux once Cython will support the 

``yield`` statement. Specifying a third entry `maxrows` restricts 

the alphabet to `\{1,2,\ldots,maxrows\}`. Specifying `weight` 

returns only those tableaux of given content/weight. 

  

EXAMPLES:: 

  

sage: from sage.libs.lrcalc.lrcalc import lrskew 

sage: for st in lrskew([3,2,1],[2]): 

....: st.pp() 

. . 1 

1 1 

2 

. . 1 

1 2 

2 

. . 1 

1 2 

3 

  

sage: for st in lrskew([3,2,1],[2], maxrows=2): 

....: st.pp() 

. . 1 

1 1 

2 

. . 1 

1 2 

2 

  

sage: lrskew([3,2,1],[2], weight=[3,1]) 

[[[None, None, 1], [1, 1], [2]]] 

""" 

cdef vector* o = iterable_to_vector(outer) 

cdef vector* i = iterable_to_vector(inner+[0]*(len(outer)-len(inner))) 

cdef skewtab* st = st_new(o, i, NULL, int(maxrows)) 

result = [skewtab_to_SkewTableau(st)] # todo: replace by the following line 

#yield skewtab_to_SkewTableau(st) 

while st_next(st): 

result.append(skewtab_to_SkewTableau(st)) # todo: replace by the following line 

#yield skewtab_to_SkewTableau(st) 

st_free(st) 

if weight is not None: 

result = [r for r in result if r.weight() == _Partitions(weight) ] 

return result # todo: remove