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

861

862

863

864

865

866

867

868

869

870

871

872

873

874

875

876

877

878

879

880

881

882

883

884

885

886

887

888

889

890

891

892

893

894

895

896

897

898

899

900

901

902

903

904

905

906

907

908

909

910

911

912

913

914

915

916

917

918

919

920

921

922

923

924

925

926

927

928

929

930

931

932

933

934

935

936

937

938

939

940

941

942

943

944

945

946

947

948

949

950

951

952

953

954

955

956

957

958

959

960

961

962

963

964

965

966

967

968

969

970

971

972

973

974

975

976

977

978

979

980

981

982

983

984

985

986

987

988

989

990

991

992

993

994

995

996

997

998

999

1000

1001

1002

1003

1004

1005

1006

1007

1008

1009

1010

1011

1012

1013

1014

1015

1016

1017

1018

1019

1020

1021

1022

1023

1024

1025

1026

1027

1028

1029

1030

1031

1032

1033

1034

1035

1036

1037

1038

1039

1040

1041

1042

1043

1044

1045

1046

1047

1048

1049

1050

1051

1052

1053

1054

1055

1056

1057

1058

1059

1060

1061

1062

1063

1064

1065

1066

1067

1068

1069

1070

1071

1072

1073

1074

1075

1076

1077

1078

1079

1080

1081

1082

1083

1084

1085

1086

1087

1088

1089

1090

1091

1092

1093

1094

1095

1096

1097

1098

1099

1100

1101

1102

1103

1104

1105

1106

1107

1108

1109

1110

1111

1112

1113

1114

1115

1116

1117

1118

1119

1120

1121

1122

1123

1124

1125

1126

1127

1128

1129

1130

1131

1132

1133

1134

1135

1136

1137

1138

1139

1140

1141

1142

1143

1144

1145

1146

1147

1148

1149

1150

1151

1152

1153

1154

1155

1156

1157

1158

1159

1160

1161

1162

1163

1164

1165

1166

1167

1168

1169

1170

1171

1172

1173

1174

1175

1176

1177

1178

1179

1180

1181

1182

1183

# We put all definitions together, whether they appear in def.h or 

# macro.h 

cdef extern from 'symmetrica/def.h': 

pass 

  

cdef extern from 'symmetrica/macro.h': 

ctypedef int INT 

ctypedef INT OBJECTKIND 

  

cdef struct vector: 

pass 

cdef struct bruch: 

pass 

cdef struct graph: 

pass 

cdef struct list: 

pass 

cdef struct matrix: 

pass 

cdef struct monom: 

pass 

cdef struct number: 

pass 

cdef struct partition: 

pass 

cdef struct permutation: 

pass 

cdef struct reihe: 

pass 

cdef struct skewpartition: 

pass 

cdef struct symchar: 

pass 

cdef struct tableaux: 

pass 

  

cdef enum: 

INFREELIST = -1 

EMPTY = 0 

INTEGER = 1 

VECTOR = 2 

PARTITION = 3 

FRACTION = 4 

BRUCH = 4 

PERMUTATION = 6 

SKEWPARTITION = 7 

TABLEAUX = 8 

POLYNOM = 9 

SCHUR = 10 

MATRIX = 11 

AUG_PART = 12 

HOM_SYM = 13 

HOMSYM = 13 

SCHUBERT = 14 

INTEGERVECTOR = 15 

INTEGER_VECTOR = 15 

INT_VECTOR = 15 

INTVECTOR = 15 

KOSTKA = 16 

INTINT = 17 

SYMCHAR = 18 

WORD =19 

LIST =20 # 210688 */ 

MONOM =21 #230688*/ 

LONGINT =22 # 170888 */ 

GEN_CHAR =23 # 280888 nur fuer test-zwecke */ 

BINTREE =24 # 291288 */ 

GRAPH =25 # 210889 */ 

COMP =26 # 300889 */ 

COMPOSITION =26 # 300889 */ 

KRANZTYPUS =27 # 280390 */ 

POW_SYM =28 

POWSYM =28 

MONOMIAL =29 # 090992 */ 

BTREE =30 

KRANZ =31 

GRAL =32 # 200691 */ 

GROUPALGEBRA =32 # 170693 */ 

ELM_SYM =33 # 090992 */ 

ELMSYM =33 # 090992 */ 

FINITEFIELD = 35 # 250193 */ 

FF = 35 # 250193 */ 

REIHE = 36 # 090393 */ 

CHARPARTITION = 37 # 130593 */ # internal use */ 

CHAR_AUG_PART = 38 # 170593 */ # internal use */ 

INTEGERMATRIX =40 # AK 141293 */ 

CYCLOTOMIC = 41 # MD */ 

MONOPOLY = 42 # MD */ 

SQ_RADICAL = 43 # MD */ 

BITVECTOR = 44 

LAURENT =45 

SUBSET =47 # AK 220997 */ 

FASTPOLYNOM =211093 

EXPONENTPARTITION =240298 

SKEWTABLEAUX =20398 

PARTTABLEAUX =10398 

BARPERM =230695 

PERMVECTOR =180998 

PERM_VECTOR =180998 

PERMUTATIONVECTOR =180998 

PERMUTATION_VECTOR =180998 

INTEGERBRUCH =220998 

INTEGER_BRUCH =220998 

INTEGERFRACTION =220998 

INTEGER_FRACTION =220998 

HASHTABLE =120199 

  

  

cdef struct loc: 

INT w2, w1, w0 

loc *nloc 

  

cdef struct longint: 

loc *floc 

signed char signum #-1,0,+1 

INT laenge 

  

ctypedef union OBJECTSELF: 

INT ob_INT 

INT *ob_INTpointer 

char *ob_charpointer 

bruch *ob_bruch 

graph *ob_graph 

list *ob_list 

longint *ob_longint 

matrix *ob_matrix 

monom *ob_monom 

number *ob_number 

partition *ob_partition 

permutation *ob_permutation 

reihe *ob_reihe 

skewpartition *ob_skewpartition 

symchar *ob_symchar 

tableaux *ob_tableaux 

vector *ob_vector 

  

cdef struct obj: 

OBJECTKIND ob_kind 

OBJECTSELF ob_self 

  

cdef struct ganzdaten: 

INT basis, basislaenge, auspos, auslaenge, auszz 

  

cdef struct zahldaten: 

char ziffer[13] 

INT mehr 

INT ziffernzhal 

loc *fdez 

  

ctypedef obj *OP 

  

cdef struct vector: 

OP v_length 

OP v_self 

  

cdef struct REIHE_variablen: 

INT index 

INT potenz 

REIHE_variablen *weiter 

  

cdef struct REIHE_mon: 

OP coeff 

REIHE_variablen *zeiger 

REIHE_mon *ref 

  

cdef struct REIHE_poly: 

INT grad 

REIHE_mon *uten 

REIHE_poly *rechts 

  

cdef struct reihe: 

INT exist 

INT reihenart 

INT z 

reihe *x 

reihe *y 

reihe *p 

INT (*eingabefkt)() 

char ope 

REIHE_poly *infozeig 

  

ctypedef reihe* REIHE_ZEIGER 

  

cdef struct list: 

OP l_self 

OP l_next 

  

cdef struct partition: 

OBJECTKIND pa_kind 

OP pa_self 

  

cdef struct permutation: 

OBJECTKIND p_kind 

OP p_self 

  

cdef struct monom: 

OP mo_self 

OP mo_koeff 

  

cdef struct bruch: 

OP b_oben 

OP b_uten 

INT b_info 

  

cdef struct matrix: 

OP m_length 

OP m_height 

OP m_self 

  

cdef struct skewpartition: 

OP spa_gross 

OP spa_klein 

  

cdef struct tableaux: 

OP t_umriss 

OP t_self 

  

cdef struct symchar: 

OP sy_werte 

OP sy_parlist 

OP sy_dimension 

  

cdef struct graph: 

OBJECTKIND gr_kind 

OP gr_self 

  

cdef struct CYCLO_DATA: 

OP index, deg, poly, autos 

  

cdef struct FIELD_DATA: 

OP index, deg, poly 

  

ctypedef union data: 

CYCLO_DATA *c_data 

FIELD_DATA *f_data 

OP o_data 

  

cdef struct number: 

OP n_self 

data n_data 

  

  

  

#MACROS 

#S_PA_I(OP a, INT i) 

OBJECTKIND s_o_k(OP a) 

void* c_o_k(OP a, OBJECTKIND k) 

OBJECTSELF S_O_S(OP a) 

  

void* add(OP a, OP b, OP c) 

void* mult(OP a, OP b, OP c) 

void* sub(OP a, OP b, OP c) 

  

  

#Integers 

void* m_i_i(INT n, OP a) 

void* M_I_I(INT n, OP a) 

INT S_I_I(OP a) 

t_int_longint(OP a, OP b) 

void* m_i_longint(INT n, OP a) 

  

  

#Fractions 

OP S_B_O(OP a) 

OP S_B_U(OP a) 

OP m_ou_b(OP o, OP u, OP d) 

  

#Vectors 

void* M_IL_V(INT length, OP a) 

void* m_il_v(INT n, OP a ) 

void* m_i_i(INT n, OP a) 

  

INT s_v_li(OP a) 

OP s_v_i(OP a, INT i) 

  

#Partitions 

OP s_pa_l(OP a) 

INT s_pa_li(OP a) 

INT s_pa_ii(OP a, INT i) 

OP s_pa_i(OP a, INT i) 

OP S_PA_S(OP a) 

OP S_PA_I(OP a, INT ) 

void* b_ks_pa(INT kind, OP b, OP a) 

  

  

#Skew Partitions 

INT b_gk_spa(OP gross, OP klein, OP result) 

INT m_gk_spa(OP gross, OP klein, OP result) 

OP s_spa_g(OP spa) 

OP s_spa_k(OP spa) 

  

#Permutations 

OP s_p_i(OP a, INT i) 

INT s_p_li(OP a) 

INT s_p_ii(OP a, INT i) 

void* m_il_p(INT n, OP a) 

  

  

#Barred Permutations 

  

  

#Lists 

OP s_l_s(OP a) 

OP S_L_S(OP a) 

OP s_l_n(OP a) 

INT lastp_list(OP l) 

INT empty_listp(OP l) 

  

#Matrices 

INT S_M_HI(OP a) 

INT S_M_LI(OP a) 

OP S_M_IJ(OP a, INT i, INT j) 

void* m_ilih_m(INT l, INT h, OP a) 

  

#Schur polynomials 

OP s_s_s(OP a) 

OP s_s_k(OP a) 

OP s_s_n(OP a) 

void* m_skn_s(OP part, OP koeff, OP next, OP result) 

void* b_skn_s(OP part, OP koeff, OP next, OP result) 

  

#Schubert polynomials 

OP s_sch_s(OP a) 

OP s_sch_k(OP a) 

OP s_sch_n(OP a) 

void* m_skn_sch(OP perm, OP koeff, OP next, OP result) 

void* b_skn_sch(OP perm, OP koeff, OP next, OP result) 

  

#Polynomials 

OP s_po_n(OP a) 

OP s_po_sl(OP a) 

OP s_po_k(OP a) 

OP s_po_s(OP a) 

void* m_skn_po(OP s, OP k, OP next, OP polynom) 

  

#Tableaux 

OP S_T_S(OP t) 

  

######### 

  

INT insert(OP a, OP b, INT (*eq)(), INT (*comp)()) 

  

  

INT nullp_sqrad(OP a) 

OP S_PO_K(OP a) 

OP S_PO_S(OP a) 

OP S_L_N(OP a) 

OP S_N_S(OP a) 

INT einsp(OP A) 

  

#Empty Object 

int EMPTYP(OP obj) 

  

#Functions 

INT anfang() 

INT ende() 

OP callocobject() 

INT sscan(INT, OP a) 

INT scan(INT, OP a) 

INT freeall(OP a) 

INT freeself(OP a) 

INT sprint(char* t, OP a) 

INT sprint_integer(char* t, OP A) 

INT println(OP a) 

  

#factorial 

INT fakul(OP a, OP b) 

  

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

cdef object matrix_constructor 

cdef object Integer 

cdef object Tableau, SkewTableau 

cdef object SkewPartition 

cdef object Partition 

cdef object Permutation, Permutations 

cdef object builtinlist 

cdef object sqrt 

cdef object Rational 

cdef object QQ 

cdef object ZZ 

cdef object SymmetricFunctions 

cdef object PolynomialRing 

cdef object SchubertPolynomialRing, SchubertPolynomial_class 

cdef object two, fifteen, thirty, zero, sage_maxint 

  

cdef int maxint = 2147483647 

  

cdef void late_import(): 

global matrix_constructor, \ 

Integer, \ 

Tableau, \ 

SkewTableau, \ 

SkewPartition, \ 

Partition, \ 

Permutation, Permutations,\ 

prod, \ 

PolynomialRing, \ 

Rational, \ 

QQ, \ 

ZZ, \ 

SymmetricFunctions, \ 

sqrt, \ 

builtinlist, \ 

MPolynomialRing_generic, is_MPolynomial,\ 

SchubertPolynomialRing, SchubertPolynomial_class,\ 

two, fifteen, thirty, zero, sage_maxint 

  

if matrix_constructor is not None: 

return 

  

import sage.matrix.constructor 

matrix_constructor = sage.matrix.constructor.matrix 

  

import sage.rings.integer 

Integer = sage.rings.integer.Integer 

  

import sage.combinat.tableau 

Tableau = sage.combinat.tableau.Tableau 

  

import sage.combinat.skew_tableau 

SkewTableau = sage.combinat.skew_tableau.SkewTableau 

  

import sage.combinat.skew_partition 

SkewPartition = sage.combinat.skew_partition.SkewPartition 

  

import sage.combinat.partition 

Partition = sage.combinat.partition.Partition 

  

import sage.combinat.permutation 

Permutation = sage.combinat.permutation.Permutation 

Permutations = sage.combinat.permutation.Permutations 

  

import sage.functions.all 

sqrt = sage.functions.all.sqrt 

  

import sage.misc.all 

prod = sage.misc.all.prod 

  

import sage.rings.polynomial.polynomial_ring_constructor 

PolynomialRing = sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing 

  

import sage.rings.all 

QQ = sage.rings.all.QQ 

Rational = sage.rings.all.Rational 

ZZ = sage.rings.all.ZZ 

  

#Symmetric Functions 

import sage.combinat.sf.sf 

SymmetricFunctions = sage.combinat.sf.sf.SymmetricFunctions 

  

from six.moves import builtins 

builtinlist = builtins.list 

  

import sage.rings.polynomial.multi_polynomial_ring 

MPolynomialRing_generic = sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_generic 

import sage.rings.polynomial.multi_polynomial_element 

is_MPolynomial = sage.rings.polynomial.multi_polynomial_element.is_MPolynomial 

  

import sage.combinat.schubert_polynomial 

SchubertPolynomialRing = sage.combinat.schubert_polynomial.SchubertPolynomialRing 

SchubertPolynomial_class = sage.combinat.schubert_polynomial.SchubertPolynomial_class 

  

two = Integer(2) 

fifteen = Integer(15) 

thirty = Integer(30) 

zero = Integer(0) 

sage_maxint = Integer(maxint) 

  

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

cdef object _py(OP a): 

cdef OBJECTKIND objk 

objk = s_o_k(a) 

if objk == INTEGER: 

return _py_int(a) 

elif objk == LONGINT: 

return _py_longint(a) 

elif objk == PARTITION: 

return _py_partition(a) 

elif objk == PERMUTATION: 

return _py_permutation(a) 

elif objk == SKEWPARTITION: 

return _py_skew_partition(a) 

elif objk == FRACTION: 

return _py_fraction(a) 

elif objk == SQ_RADICAL: 

return _py_sq_radical(a) 

elif objk == MATRIX or objk == KRANZTYPUS: 

return _py_matrix(a) 

elif objk == SCHUR: 

return _py_schur(a) 

elif objk == HOMSYM: 

return _py_homsym(a) 

elif objk == POWSYM: 

return _py_powsym(a) 

elif objk == ELMSYM: 

return _py_elmsym(a) 

elif objk == MONOMIAL: 

return _py_monomial(a) 

elif objk == LIST: 

return _py_list(a) 

elif objk == VECTOR: 

return _py_vector(a) 

elif objk == TABLEAUX: 

return _py_tableau(a) 

elif objk == EMPTY: 

return None 

elif objk == POLYNOM: 

return _py_polynom(a) 

elif objk == SCHUBERT: 

return _py_schubert(a) 

else: 

#println(a) 

raise NotImplementedError(str(objk)) 

  

cdef int _op(object a, OP result) except -1: 

late_import() 

if isinstance(a, Integer): 

_op_integer(a, result) 

elif isinstance(a, Partition): 

_op_partition(a, result) 

elif isinstance(a, Rational): 

_op_fraction(a, result) 

else: 

raise TypeError("cannot convert a (= %s) to OP" % a) 

  

def test_integer(object x): 

""" 

Tests functionality for converting between Sage's integers 

and symmetrica's integers. 

  

EXAMPLES:: 

  

sage: from sage.libs.symmetrica.symmetrica import test_integer 

sage: test_integer(1) 

1 

sage: test_integer(-1) 

-1 

sage: test_integer(2^33) 

8589934592 

sage: test_integer(-2^33) 

-8589934592 

sage: test_integer(2^100) 

1267650600228229401496703205376 

sage: test_integer(-2^100) 

-1267650600228229401496703205376 

sage: for i in range(100): 

....: if test_integer(2^i) != 2^i: 

....: print("Failure at {}".format(i)) 

""" 

cdef OP a = callocobject() 

_op_integer(x, a) 

res = _py(a) 

freeall(a) 

return res 

  

########## 

#Integers# 

########## 

  

cdef int _op_integer(object x, OP a) except -1: 

try: 

_op_int(x, a) 

except OverflowError: 

_op_longint(x, a) 

return 0 

  

  

cdef int _op_int(object x, OP a) except -1: 

M_I_I(x, a) 

return 0 

  

cdef object _py_int(OP a): 

late_import() 

return Integer(S_I_I(a)) 

  

  

cdef int _op_longint(object x, OP a) except -1: 

late_import() 

cdef OP op_maxint_long = callocobject(), 

cdef OP quo_long = callocobject() 

cdef OP rem_long = callocobject() 

  

qr = x.quo_rem(sage_maxint) 

  

m_i_longint(maxint, op_maxint_long) 

_op_integer(qr[0], a) 

_op_integer(qr[1], rem_long) 

  

#Multiply a by op_maxint_long 

mult(op_maxint_long, a, a) 

  

#Add rem to a 

add(a, rem_long, a) 

  

freeall(rem_long) 

freeall(quo_long) 

freeall(op_maxint_long) 

return 0 

  

cdef object _py_longint(OP a): 

late_import() 

cdef longint *x = S_O_S(a).ob_longint 

cdef loc *l = x.floc 

cdef int sign = x.signum 

res = zero 

n = zero 

while l != NULL: 

res += Integer( l.w0 ) * two**n 

res += Integer( l.w1 ) * two**(n+fifteen) 

res += Integer( l.w2 ) * two**(n+thirty) 

n += thirty + fifteen 

l = l.nloc 

if sign < 0: 

res *= Integer(-1) 

  

return res 

  

  

  

########### 

#Fractions# 

########### 

cdef object _py_fraction(OP a): 

return _py(S_B_O(a))/_py(S_B_U(a)) 

  

cdef int _op_fraction(object f, OP a) except -1: 

cdef OP o = callocobject(), u = callocobject() 

_op_integer(f.numerator(), o) 

_op_integer(f.denominator(), u) 

m_ou_b(o, u, a) 

  

######### 

#Vectors# 

######### 

cdef object _py_vector(OP a): 

cdef INT i 

res = [] 

for i from 0 <= i < s_v_li(a): 

res.append( _py(s_v_i(a, i))) 

return res 

  

cdef void* _op_il_vector(object l, OP a): 

cdef INT length, i 

length = len(l) 

  

m_il_v(length, a) 

for i from 0 <= i < length: 

m_i_i(l[i], s_v_i(a, i)) 

  

######### 

#Numbers# 

######### 

cdef object _py_sq_radical(OP a): 

late_import() 

  

cdef OP ptr 

ptr = S_N_S(a) 

  

res = 0 

if nullp_sqrad(a): 

return res 

  

while ptr != NULL: 

  

if einsp(S_PO_S(ptr)): 

res += _py(S_PO_K(ptr)) 

else: 

res += _py(S_PO_K(ptr))*sqrt(_py(S_PO_S(ptr))) 

  

  

ptr = S_L_N(ptr); 

  

return res.radical_simplify() 

  

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

#Partitions# 

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

cdef void* _op_partition(object p, OP a): 

cdef int n, i, j 

  

if not EMPTYP(a): 

freeself(a) 

  

n = len(p) 

b_ks_pa(VECTOR, callocobject(), a) 

m_il_v(n, S_PA_S(a)) 

  

j = 0 

for i from n > i >= 0: 

_op_integer(p[i], S_PA_I(a,j)) 

j = j + 1 

  

cdef object _py_partition(OP a): 

cdef INT n, i 

late_import() 

res = [] 

n = s_pa_li(a) 

for i from n > i >=0: 

res.append(s_pa_ii(a, i)) 

return Partition(res) 

  

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

#Skew Partition# 

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

cdef void* _op_skew_partition(object p, OP a): 

cdef OP gross, klein 

gross = callocobject() 

klein = callocobject() 

  

#print p[0], p[1] 

_op_partition(p[0], gross) 

_op_partition(p[1], klein) 

  

b_gk_spa(gross, klein, a) 

  

cdef object _py_skew_partition(OP a): 

late_import() 

return SkewPartition( [ _py_partition(s_spa_g(a)), _py_partition(s_spa_k(a)) ] ) 

  

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

#Permutations# 

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

cdef void* _op_permutation(object p, OP a): 

cdef int n, i, j 

  

if not EMPTYP(a): 

freeself(a) 

  

n = len(p) 

m_il_p(n, a) 

for i from 0 <= i < n: 

_op_integer(p[i], s_p_i(a,i)) 

  

cdef object _py_permutation(OP a): 

late_import() 

cdef INT n, i 

res = [] 

n = s_p_li(a) 

for i from 0 <= i < n: 

res.append(s_p_ii(a, i)) 

return Permutation(res) 

  

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

#Barred Permutations# 

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

  

####### 

#Lists# 

####### 

cdef object _py_list(OP a): 

cdef OP x 

x = a 

res = [] 

if S_L_S(a) == NULL: 

return [] 

elif empty_listp(a): 

return [] 

while x != NULL: 

res.append(_py(s_l_s(x))) 

x = s_l_n(x) 

  

return res 

  

  

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

#Polynomials# 

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

cdef object _py_polynom(OP a): 

late_import() 

cdef int maxneeded = 0, i = 0 

cdef OP pointer = a 

  

if pointer == NULL: 

return 0 

  

  

#Find the maximum number of variables needed 

while pointer != NULL: 

l = _py(s_po_sl(pointer)) 

if l > maxneeded: 

maxneeded = l 

pointer = s_po_n(pointer) 

  

pointer = a 

parent_ring = _py(s_po_k(pointer)).parent() 

if maxneeded == 1: 

P = PolynomialRing(parent_ring, 'x') 

else: 

P = PolynomialRing(parent_ring, maxneeded, 'x') 

d = {} 

while pointer != NULL: 

exps = tuple(_py_vector(s_po_s(pointer))) 

d[ exps ] = _py(s_po_k(pointer)) 

pointer = s_po_n(pointer) 

  

return P(d) 

  

  

cdef object _py_polynom_alphabet(OP a, object alphabet, object length): 

""" 

Converts a symmetrica multivariate polynomial a to a Sage multivariate 

polynomials. Alphabet specifies the names of the variables which are 

fed into PolynomialRing. length specifies the number of variables; if 

it is set to 0, then the number of variables is autodetected based on 

the number of variables in alphabet or the result obtained from 

symmetrica. 

  

""" 

late_import() 

cdef OP pointer = a 

  

if pointer == NULL: 

return 0 

  

parent_ring = _py(s_po_k(pointer)).parent() 

if length == 0: 

if isinstance(alphabet, (builtinlist, tuple)): 

l = len(alphabet) 

elif isinstance(alphabet, str) and ',' in alphabet: 

l = len(alphabet.split(',')) 

else: 

l = _py(s_po_sl(a)) 

else: 

l = length 

  

P = PolynomialRing(parent_ring, l, alphabet) 

x = P.gens() 

res = P(0) 

while pointer != NULL: 

exps = _py_vector(s_po_s(pointer)) 

res += _py(s_po_k(pointer)) *prod([ x[i]**exps[i] for i in range(min(len(exps),l))]) 

pointer = s_po_n(pointer) 

return res 

  

cdef object _op_polynom(object d, OP res): 

late_import() 

  

poly_ring = d.parent() 

  

if not isinstance(poly_ring, MPolynomialRing_generic): 

raise TypeError("you must pass a multivariate polynomial") 

base_ring = poly_ring.base_ring() 

  

if not ( base_ring == ZZ or base_ring == QQ): 

raise TypeError("the base ring must be either ZZ or QQ") 

  

cdef OP c = callocobject(), v = callocobject() 

cdef OP pointer = res 

m = d.monomials() 

exp = d.exponents() 

cdef int n, i 

n = len(exp) 

  

for i from 0 <= i < n: 

_op_il_vector(exp[i], v) 

_op(d.monomial_coefficient(poly_ring(m[i])), c) 

if i != n-1: 

m_skn_po(v,c, callocobject(), pointer) 

else: 

m_skn_po(v,c, NULL, pointer) 

pointer = s_po_n(pointer) 

  

freeall(c) 

freeall(v) 

return None 

  

  

  

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

#Schur symmetric functions and friends# 

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

cdef object _py_schur(OP a): 

late_import() 

z_elt = _py_schur_general(a) 

if len(z_elt) == 0: 

return SymmetricFunctions(ZZ).s()(0) 

  

#Figure out the parent ring of a coefficient 

R = z_elt[next(iter(z_elt))].parent() 

  

s = SymmetricFunctions(R).s() 

z = s(0) 

z._monomial_coefficients = z_elt 

return z 

  

cdef void* _op_schur(object d, OP res): 

_op_schur_general(d, res) 

  

cdef object _py_monomial(OP a): #Monomial symmetric functions 

late_import() 

z_elt = _py_schur_general(a) 

if len(z_elt) == 0: 

return SymmetricFunctions(ZZ).m()(0) 

  

R = z_elt[next(iter(z_elt))].parent() 

  

m = SymmetricFunctions(R).m() 

z = m(0) 

z._monomial_coefficients = z_elt 

return z 

  

cdef void* _op_monomial(object d, OP res): #Monomial symmetric functions 

cdef OP pointer = res 

_op_schur_general(d, res) 

while pointer != NULL: 

c_o_k(pointer, MONOMIAL) 

pointer = s_s_n(pointer) 

  

cdef object _py_powsym(OP a): #Power-sum symmetric functions 

late_import() 

z_elt = _py_schur_general(a) 

if len(z_elt) == 0: 

return SymmetricFunctions(ZZ).p()(0) 

  

R = z_elt[next(iter(z_elt))].parent() 

  

p = SymmetricFunctions(R).p() 

z = p(0) 

z._monomial_coefficients = z_elt 

return z 

  

cdef void* _op_powsym(object d, OP res): #Power-sum symmetric functions 

cdef OP pointer = res 

_op_schur_general(d, res) 

while pointer != NULL: 

c_o_k(pointer, POWSYM) 

pointer = s_s_n(pointer) 

  

  

cdef object _py_elmsym(OP a): #Elementary symmetric functions 

late_import() 

z_elt = _py_schur_general(a) 

if len(z_elt) == 0: 

return SymmetricFunctions(ZZ).e()(0) 

  

R = z_elt[next(iter(z_elt))].parent() 

  

e = SymmetricFunctions(R).e() 

z = e(0) 

z._monomial_coefficients = z_elt 

return z 

  

cdef void* _op_elmsym(object d, OP res): #Elementary symmetric functions 

cdef OP pointer = res 

_op_schur_general(d, res) 

while pointer != NULL: 

c_o_k(pointer, ELMSYM) 

pointer = s_s_n(pointer) 

  

  

cdef object _py_homsym(OP a): #Homogenous symmetric functions 

late_import() 

z_elt = _py_schur_general(a) 

if len(z_elt) == 0: 

return SymmetricFunctions(ZZ).h()(0) 

  

R = z_elt[next(iter(z_elt))].parent() 

  

h = SymmetricFunctions(R).h() 

z = h(0) 

z._monomial_coefficients = z_elt 

return z 

  

cdef void* _op_homsym(object d, OP res): #Homogenous symmetric functions 

cdef OP pointer = res 

_op_schur_general(d, res) 

while pointer != NULL: 

c_o_k(pointer, HOMSYM) 

pointer = s_s_n(pointer) 

  

  

cdef object _py_schur_general(OP a): 

cdef OP pointer = a 

d = {} 

if a == NULL: 

return d 

while pointer != NULL: 

d[ _py_partition(s_s_s(pointer)) ] = _py(s_s_k(pointer)) 

pointer = s_s_n(pointer) 

return d 

  

cdef void* _op_schur_general(object d, OP res): 

if isinstance(d, dict): 

_op_schur_general_dict(d, res) 

else: 

_op_schur_general_sf(d, res) 

  

cdef void* _op_schur_general_sf(object f, OP res): 

late_import() 

base_ring = f.parent().base_ring() 

if not ( base_ring is QQ or base_ring is ZZ ): 

raise ValueError("the base ring must be either ZZ or QQ") 

  

_op_schur_general_dict( f.monomial_coefficients(), res) 

  

cdef void* _op_schur_general_dict(object d, OP res): 

late_import() 

  

cdef OP next 

cdef OP pointer = res 

cdef INT n, i 

  

  

keys = builtinlist(d) 

n = len(keys) 

  

if n == 0: 

raise ValueError("the dictionary must be nonempty") 

  

b_skn_s(callocobject(), callocobject(), NULL, res) 

_op_partition(keys[0], s_s_s(res)) 

_op(d[keys[0]], s_s_k(res)) 

  

  

for i from 0 < i < n: 

next = callocobject() 

  

b_skn_s(callocobject(), callocobject(), NULL, next) 

_op_partition(keys[i], s_s_s(next)) 

_op(d[keys[i]], s_s_k(next)) 

  

insert(next, res, NULL, NULL) 

  

  

  

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

#Schubert Polynomials# 

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

cdef void* _op_schubert_general(object d, OP res): 

if isinstance(d, dict): 

_op_schubert_dict(d, res) 

else: 

_op_schubert_sp(d, res) 

  

cdef void* _op_schubert_perm(object a, OP res): 

cdef OP caperm = callocobject() 

_op_permutation(a, caperm) 

m_perm_sch(caperm, res) 

freeall(caperm) 

  

cdef void* _op_schubert_sp(object f, OP res): 

late_import() 

base_ring = f.parent().base_ring() 

if not ( base_ring is QQ or base_ring is ZZ ): 

raise ValueError("the base ring must be either ZZ or QQ") 

  

_op_schubert_dict( f.monomial_coefficients(), res) 

  

cdef void* _op_schubert_dict(object d, OP res): 

late_import() 

  

cdef OP next 

cdef OP pointer = res 

cdef INT n, i 

  

keys = builtinlist(d) 

n = len(keys) 

  

if n == 0: 

raise ValueError("the dictionary must be nonempty") 

  

b_skn_sch(callocobject(), callocobject(), NULL, res) 

_op_permutation(keys[0], s_sch_s(res)) 

_op(d[keys[0]], s_sch_k(res)) 

  

  

for i from 0 < i < n: 

next = callocobject() 

  

b_skn_sch(callocobject(), callocobject(), NULL, next) 

_op_permutation(keys[i], s_sch_s(next)) 

_op(d[keys[i]], s_sch_k(next)) 

  

insert(next, res, NULL, NULL) 

  

cdef object _py_schubert(OP a): 

late_import() 

cdef OP pointer = a 

cdef dict z_elt = {} 

  

# SCHUBERT is (like) a list, so we also need to make sure it is not empty 

if a == NULL or empty_listp(a): 

return SchubertPolynomialRing(ZZ).zero() 

  

while pointer != NULL: 

z_elt[_py(s_s_s(pointer)).remove_extra_fixed_points() ] = _py(s_sch_k(pointer)) 

pointer = s_sch_n(pointer) 

  

if not z_elt: 

return SchubertPolynomialRing(ZZ).zero() 

  

R = z_elt[next(iter(z_elt))].parent() 

X = SchubertPolynomialRing(R) 

# If the element constructor ends up copying the input dict in the future, 

# then this will not be as fast as creating a copy of the zero element 

# and explicitly setting the _monomial_coefficients. 

return X.element_class(X, z_elt) 

  

  

########## 

#Matrices# 

########## 

cdef object _py_matrix(OP a): 

  

late_import() 

  

cdef INT i,j,rows, cols 

rows = S_M_HI(a) 

cols = S_M_LI(a) 

  

res = [] 

for i from 0 <= i < rows: 

row = [] 

for j from 0 <= j < cols: 

row.append( _py(S_M_IJ(a,i,j)) ) 

  

res.append(row) 

  

#return res 

if res == [] or res is None: 

return res 

else: 

return matrix_constructor(res) 

  

  

cdef void* _op_matrix(object a, OP res): 

#FIXME: only constructs integer matrices 

  

cdef INT i,j,rows, cols 

  

rows = a.nrows() 

cols = a.ncols() 

  

m_ilih_m(rows, cols, res) 

  

for i from 0 <= i < rows: 

for j from 0 <= j < cols: 

_op_integer( a[(i,j)], S_M_IJ(res,i,j) ) 

  

########## 

#Tableaux# 

########## 

cdef object _py_tableau(OP t): 

  

late_import() 

  

cdef INT i,j,rows, cols, added, is_skew = 0 

cdef OP a 

a = S_T_S(t) 

rows = S_M_HI(a) 

cols = S_M_LI(a) 

  

res = [] 

for i from 0 <= i < rows: 

row = [] 

added = 0 

for j from 0 <= j < cols: 

if s_o_k(S_M_IJ(a,i,j)) == EMPTY: 

if added: 

break 

else: 

row.append( None ) 

is_skew = 1 

else: 

added = 1 

row.append( _py(S_M_IJ(a,i,j)) ) 

  

res.append(row) 

  

#return res 

if is_skew: 

return SkewTableau(res) 

else: 

return Tableau(res) 

  

  

  

  

def start(): 

anfang() 

  

def end(): 

ende()