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

1184

1185

1186

1187

1188

1189

1190

1191

1192

1193

1194

1195

1196

1197

1198

1199

1200

1201

1202

1203

1204

1205

1206

1207

1208

1209

1210

1211

1212

1213

1214

1215

1216

1217

1218

1219

1220

1221

1222

1223

1224

1225

1226

1227

1228

1229

1230

1231

1232

1233

1234

1235

1236

1237

1238

1239

1240

1241

1242

1243

1244

""" 

This module mainly implements special orthogonal polynomials. 

 

See also functions.combinatorial.numbers which contains some 

combinatorial polynomials. 

 

""" 

 

from __future__ import print_function, division 

 

from sympy.core.singleton import S 

from sympy.core import Rational 

from sympy.core.function import Function, ArgumentIndexError 

from sympy.core.symbol import Dummy 

from sympy.functions.combinatorial.factorials import binomial, factorial, RisingFactorial 

from sympy.functions.elementary.complexes import re 

from sympy.functions.elementary.exponential import exp 

from sympy.functions.elementary.integers import floor 

from sympy.functions.elementary.miscellaneous import sqrt 

from sympy.functions.elementary.trigonometric import cos 

from sympy.functions.special.gamma_functions import gamma 

from sympy.functions.special.hyper import hyper 

 

from sympy.polys.orthopolys import ( 

jacobi_poly, 

gegenbauer_poly, 

chebyshevt_poly, 

chebyshevu_poly, 

laguerre_poly, 

hermite_poly, 

legendre_poly 

) 

 

_x = Dummy('x') 

 

 

class OrthogonalPolynomial(Function): 

"""Base class for orthogonal polynomials. 

""" 

 

@classmethod 

def _eval_at_order(cls, n, x): 

if n.is_integer and n >= 0: 

return cls._ortho_poly(int(n), _x).subs(_x, x) 

 

def _eval_conjugate(self): 

return self.func(self.args[0], self.args[1].conjugate()) 

 

#---------------------------------------------------------------------------- 

# Jacobi polynomials 

# 

 

 

class jacobi(OrthogonalPolynomial): 

r""" 

Jacobi polynomial :math:`P_n^{\left(\alpha, \beta\right)}(x)` 

 

jacobi(n, alpha, beta, x) gives the nth Jacobi polynomial 

in x, :math:`P_n^{\left(\alpha, \beta\right)}(x)`. 

 

The Jacobi polynomials are orthogonal on :math:`[-1, 1]` with respect 

to the weight :math:`\left(1-x\right)^\alpha \left(1+x\right)^\beta`. 

 

Examples 

======== 

 

>>> from sympy import jacobi, S, conjugate, diff 

>>> from sympy.abc import n,a,b,x 

 

>>> jacobi(0, a, b, x) 

1 

>>> jacobi(1, a, b, x) 

a/2 - b/2 + x*(a/2 + b/2 + 1) 

>>> jacobi(2, a, b, x) # doctest:+SKIP 

(a**2/8 - a*b/4 - a/8 + b**2/8 - b/8 + x**2*(a**2/8 + a*b/4 + 7*a/8 + 

b**2/8 + 7*b/8 + 3/2) + x*(a**2/4 + 3*a/4 - b**2/4 - 3*b/4) - 1/2) 

 

>>> jacobi(n, a, b, x) 

jacobi(n, a, b, x) 

 

>>> jacobi(n, a, a, x) 

RisingFactorial(a + 1, n)*gegenbauer(n, 

a + 1/2, x)/RisingFactorial(2*a + 1, n) 

 

>>> jacobi(n, 0, 0, x) 

legendre(n, x) 

 

>>> jacobi(n, S(1)/2, S(1)/2, x) 

RisingFactorial(3/2, n)*chebyshevu(n, x)/factorial(n + 1) 

 

>>> jacobi(n, -S(1)/2, -S(1)/2, x) 

RisingFactorial(1/2, n)*chebyshevt(n, x)/factorial(n) 

 

>>> jacobi(n, a, b, -x) 

(-1)**n*jacobi(n, b, a, x) 

 

>>> jacobi(n, a, b, 0) 

2**(-n)*gamma(a + n + 1)*hyper((-b - n, -n), (a + 1,), -1)/(factorial(n)*gamma(a + 1)) 

>>> jacobi(n, a, b, 1) 

RisingFactorial(a + 1, n)/factorial(n) 

 

>>> conjugate(jacobi(n, a, b, x)) 

jacobi(n, conjugate(a), conjugate(b), conjugate(x)) 

 

>>> diff(jacobi(n,a,b,x), x) 

(a/2 + b/2 + n/2 + 1/2)*jacobi(n - 1, a + 1, b + 1, x) 

 

See Also 

======== 

 

gegenbauer, 

chebyshevt_root, chebyshevu, chebyshevu_root, 

legendre, assoc_legendre, 

hermite, 

laguerre, assoc_laguerre, 

sympy.polys.orthopolys.jacobi_poly, 

sympy.polys.orthopolys.gegenbauer_poly 

sympy.polys.orthopolys.chebyshevt_poly 

sympy.polys.orthopolys.chebyshevu_poly 

sympy.polys.orthopolys.hermite_poly 

sympy.polys.orthopolys.legendre_poly 

sympy.polys.orthopolys.laguerre_poly 

 

References 

========== 

 

.. [1] http://en.wikipedia.org/wiki/Jacobi_polynomials 

.. [2] http://mathworld.wolfram.com/JacobiPolynomial.html 

.. [3] http://functions.wolfram.com/Polynomials/JacobiP/ 

""" 

 

@classmethod 

def eval(cls, n, a, b, x): 

# Simplify to other polynomials 

# P^{a, a}_n(x) 

if a == b: 

if a == -S.Half: 

return RisingFactorial(S.Half, n) / factorial(n) * chebyshevt(n, x) 

elif a == S.Zero: 

return legendre(n, x) 

elif a == S.Half: 

return RisingFactorial(3*S.Half, n) / factorial(n + 1) * chebyshevu(n, x) 

else: 

return RisingFactorial(a + 1, n) / RisingFactorial(2*a + 1, n) * gegenbauer(n, a + S.Half, x) 

elif b == -a: 

# P^{a, -a}_n(x) 

return gamma(n + a + 1) / gamma(n + 1) * (1 + x)**(a/2) / (1 - x)**(a/2) * assoc_legendre(n, -a, x) 

elif a == -b: 

# P^{-b, b}_n(x) 

return gamma(n - b + 1) / gamma(n + 1) * (1 - x)**(b/2) / (1 + x)**(b/2) * assoc_legendre(n, b, x) 

 

if not n.is_Number: 

# Symbolic result P^{a,b}_n(x) 

# P^{a,b}_n(-x) ---> (-1)**n * P^{b,a}_n(-x) 

if x.could_extract_minus_sign(): 

return S.NegativeOne**n * jacobi(n, b, a, -x) 

# We can evaluate for some special values of x 

if x == S.Zero: 

return (2**(-n) * gamma(a + n + 1) / (gamma(a + 1) * factorial(n)) * 

hyper([-b - n, -n], [a + 1], -1)) 

if x == S.One: 

return RisingFactorial(a + 1, n) / factorial(n) 

elif x == S.Infinity: 

if n.is_positive: 

# Make sure a+b+2*n \notin Z 

if (a + b + 2*n).is_integer: 

raise ValueError("Error. a + b + 2*n should not be an integer.") 

return RisingFactorial(a + b + n + 1, n) * S.Infinity 

else: 

# n is a given fixed integer, evaluate into polynomial 

return jacobi_poly(n, a, b, x) 

 

def fdiff(self, argindex=4): 

from sympy import Sum 

if argindex == 1: 

# Diff wrt n 

raise ArgumentIndexError(self, argindex) 

elif argindex == 2: 

# Diff wrt a 

n, a, b, x = self.args 

k = Dummy("k") 

f1 = 1 / (a + b + n + k + 1) 

f2 = ((a + b + 2*k + 1) * RisingFactorial(b + k + 1, n - k) / 

((n - k) * RisingFactorial(a + b + k + 1, n - k))) 

return Sum(f1 * (jacobi(n, a, b, x) + f2*jacobi(k, a, b, x)), (k, 0, n - 1)) 

elif argindex == 3: 

# Diff wrt b 

n, a, b, x = self.args 

k = Dummy("k") 

f1 = 1 / (a + b + n + k + 1) 

f2 = (-1)**(n - k) * ((a + b + 2*k + 1) * RisingFactorial(a + k + 1, n - k) / 

((n - k) * RisingFactorial(a + b + k + 1, n - k))) 

return Sum(f1 * (jacobi(n, a, b, x) + f2*jacobi(k, a, b, x)), (k, 0, n - 1)) 

elif argindex == 4: 

# Diff wrt x 

n, a, b, x = self.args 

return S.Half * (a + b + n + 1) * jacobi(n - 1, a + 1, b + 1, x) 

else: 

raise ArgumentIndexError(self, argindex) 

 

def _eval_rewrite_as_polynomial(self, n, a, b, x): 

from sympy import Sum 

# Make sure n \in N 

if n.is_negative or n.is_integer is False: 

raise ValueError("Error: n should be a non-negative integer.") 

k = Dummy("k") 

kern = (RisingFactorial(-n, k) * RisingFactorial(a + b + n + 1, k) * RisingFactorial(a + k + 1, n - k) / 

factorial(k) * ((1 - x)/2)**k) 

return 1 / factorial(n) * Sum(kern, (k, 0, n)) 

 

def _eval_conjugate(self): 

n, a, b, x = self.args 

return self.func(n, a.conjugate(), b.conjugate(), x.conjugate()) 

 

 

def jacobi_normalized(n, a, b, x): 

r""" 

Jacobi polynomial :math:`P_n^{\left(\alpha, \beta\right)}(x)` 

 

jacobi_normalized(n, alpha, beta, x) gives the nth Jacobi polynomial 

in x, :math:`P_n^{\left(\alpha, \beta\right)}(x)`. 

 

The Jacobi polynomials are orthogonal on :math:`[-1, 1]` with respect 

to the weight :math:`\left(1-x\right)^\alpha \left(1+x\right)^\beta`. 

 

This functions returns the polynomials normilzed: 

 

.. math:: 

 

\int_{-1}^{1} 

P_m^{\left(\alpha, \beta\right)}(x) 

P_n^{\left(\alpha, \beta\right)}(x) 

(1-x)^{\alpha} (1+x)^{\beta} \mathrm{d}x 

= \delta_{m,n} 

 

Examples 

======== 

 

>>> from sympy import jacobi_normalized 

>>> from sympy.abc import n,a,b,x 

 

>>> jacobi_normalized(n, a, b, x) 

jacobi(n, a, b, x)/sqrt(2**(a + b + 1)*gamma(a + n + 1)*gamma(b + n + 1)/((a + b + 2*n + 1)*factorial(n)*gamma(a + b + n + 1))) 

 

See Also 

======== 

 

gegenbauer, 

chebyshevt_root, chebyshevu, chebyshevu_root, 

legendre, assoc_legendre, 

hermite, 

laguerre, assoc_laguerre, 

sympy.polys.orthopolys.jacobi_poly, 

sympy.polys.orthopolys.gegenbauer_poly 

sympy.polys.orthopolys.chebyshevt_poly 

sympy.polys.orthopolys.chebyshevu_poly 

sympy.polys.orthopolys.hermite_poly 

sympy.polys.orthopolys.legendre_poly 

sympy.polys.orthopolys.laguerre_poly 

 

References 

========== 

 

.. [1] http://en.wikipedia.org/wiki/Jacobi_polynomials 

.. [2] http://mathworld.wolfram.com/JacobiPolynomial.html 

.. [3] http://functions.wolfram.com/Polynomials/JacobiP/ 

""" 

nfactor = (S(2)**(a + b + 1) * (gamma(n + a + 1) * gamma(n + b + 1)) 

/ (2*n + a + b + 1) / (factorial(n) * gamma(n + a + b + 1))) 

 

return jacobi(n, a, b, x) / sqrt(nfactor) 

 

 

#---------------------------------------------------------------------------- 

# Gegenbauer polynomials 

# 

 

 

class gegenbauer(OrthogonalPolynomial): 

r""" 

Gegenbauer polynomial :math:`C_n^{\left(\alpha\right)}(x)` 

 

gegenbauer(n, alpha, x) gives the nth Gegenbauer polynomial 

in x, :math:`C_n^{\left(\alpha\right)}(x)`. 

 

The Gegenbauer polynomials are orthogonal on :math:`[-1, 1]` with 

respect to the weight :math:`\left(1-x^2\right)^{\alpha-\frac{1}{2}}`. 

 

Examples 

======== 

 

>>> from sympy import gegenbauer, conjugate, diff 

>>> from sympy.abc import n,a,x 

>>> gegenbauer(0, a, x) 

1 

>>> gegenbauer(1, a, x) 

2*a*x 

>>> gegenbauer(2, a, x) 

-a + x**2*(2*a**2 + 2*a) 

>>> gegenbauer(3, a, x) 

x**3*(4*a**3/3 + 4*a**2 + 8*a/3) + x*(-2*a**2 - 2*a) 

 

>>> gegenbauer(n, a, x) 

gegenbauer(n, a, x) 

>>> gegenbauer(n, a, -x) 

(-1)**n*gegenbauer(n, a, x) 

 

>>> gegenbauer(n, a, 0) 

2**n*sqrt(pi)*gamma(a + n/2)/(gamma(a)*gamma(-n/2 + 1/2)*gamma(n + 1)) 

>>> gegenbauer(n, a, 1) 

gamma(2*a + n)/(gamma(2*a)*gamma(n + 1)) 

 

>>> conjugate(gegenbauer(n, a, x)) 

gegenbauer(n, conjugate(a), conjugate(x)) 

 

>>> diff(gegenbauer(n, a, x), x) 

2*a*gegenbauer(n - 1, a + 1, x) 

 

See Also 

======== 

 

jacobi, 

chebyshevt_root, chebyshevu, chebyshevu_root, 

legendre, assoc_legendre, 

hermite, 

laguerre, assoc_laguerre, 

sympy.polys.orthopolys.jacobi_poly 

sympy.polys.orthopolys.gegenbauer_poly 

sympy.polys.orthopolys.chebyshevt_poly 

sympy.polys.orthopolys.chebyshevu_poly 

sympy.polys.orthopolys.hermite_poly 

sympy.polys.orthopolys.legendre_poly 

sympy.polys.orthopolys.laguerre_poly 

 

References 

========== 

 

.. [1] http://en.wikipedia.org/wiki/Gegenbauer_polynomials 

.. [2] http://mathworld.wolfram.com/GegenbauerPolynomial.html 

.. [3] http://functions.wolfram.com/Polynomials/GegenbauerC3/ 

""" 

 

@classmethod 

def eval(cls, n, a, x): 

# For negative n the polynomials vanish 

# See http://functions.wolfram.com/Polynomials/GegenbauerC3/03/01/03/0012/ 

if n.is_negative: 

return S.Zero 

 

# Some special values for fixed a 

if a == S.Half: 

return legendre(n, x) 

elif a == S.One: 

return chebyshevu(n, x) 

elif a == S.NegativeOne: 

return S.Zero 

 

if not n.is_Number: 

# Handle this before the general sign extraction rule 

if x == S.NegativeOne: 

if (re(a) > S.Half) == True: 

return S.ComplexInfinity 

else: 

# No sec function available yet 

#return (cos(S.Pi*(a+n)) * sec(S.Pi*a) * gamma(2*a+n) / 

# (gamma(2*a) * gamma(n+1))) 

return None 

 

# Symbolic result C^a_n(x) 

# C^a_n(-x) ---> (-1)**n * C^a_n(x) 

if x.could_extract_minus_sign(): 

return S.NegativeOne**n * gegenbauer(n, a, -x) 

# We can evaluate for some special values of x 

if x == S.Zero: 

return (2**n * sqrt(S.Pi) * gamma(a + S.Half*n) / 

(gamma((1 - n)/2) * gamma(n + 1) * gamma(a)) ) 

if x == S.One: 

return gamma(2*a + n) / (gamma(2*a) * gamma(n + 1)) 

elif x == S.Infinity: 

if n.is_positive: 

return RisingFactorial(a, n) * S.Infinity 

else: 

# n is a given fixed integer, evaluate into polynomial 

return gegenbauer_poly(n, a, x) 

 

def fdiff(self, argindex=3): 

from sympy import Sum 

if argindex == 1: 

# Diff wrt n 

raise ArgumentIndexError(self, argindex) 

elif argindex == 2: 

# Diff wrt a 

n, a, x = self.args 

k = Dummy("k") 

factor1 = 2 * (1 + (-1)**(n - k)) * (k + a) / ((k + 

n + 2*a) * (n - k)) 

factor2 = 2*(k + 1) / ((k + 2*a) * (2*k + 2*a + 1)) + \ 

2 / (k + n + 2*a) 

kern = factor1*gegenbauer(k, a, x) + factor2*gegenbauer(n, a, x) 

return Sum(kern, (k, 0, n - 1)) 

elif argindex == 3: 

# Diff wrt x 

n, a, x = self.args 

return 2*a*gegenbauer(n - 1, a + 1, x) 

else: 

raise ArgumentIndexError(self, argindex) 

 

def _eval_rewrite_as_polynomial(self, n, a, x): 

from sympy import Sum 

k = Dummy("k") 

kern = ((-1)**k * RisingFactorial(a, n - k) * (2*x)**(n - 2*k) / 

(factorial(k) * factorial(n - 2*k))) 

return Sum(kern, (k, 0, floor(n/2))) 

 

def _eval_conjugate(self): 

n, a, x = self.args 

return self.func(n, a.conjugate(), x.conjugate()) 

 

#---------------------------------------------------------------------------- 

# Chebyshev polynomials of first and second kind 

# 

 

 

class chebyshevt(OrthogonalPolynomial): 

r""" 

Chebyshev polynomial of the first kind, :math:`T_n(x)` 

 

chebyshevt(n, x) gives the nth Chebyshev polynomial (of the first 

kind) in x, :math:`T_n(x)`. 

 

The Chebyshev polynomials of the first kind are orthogonal on 

:math:`[-1, 1]` with respect to the weight :math:`\frac{1}{\sqrt{1-x^2}}`. 

 

Examples 

======== 

 

>>> from sympy import chebyshevt, chebyshevu, diff 

>>> from sympy.abc import n,x 

>>> chebyshevt(0, x) 

1 

>>> chebyshevt(1, x) 

x 

>>> chebyshevt(2, x) 

2*x**2 - 1 

 

>>> chebyshevt(n, x) 

chebyshevt(n, x) 

>>> chebyshevt(n, -x) 

(-1)**n*chebyshevt(n, x) 

>>> chebyshevt(-n, x) 

chebyshevt(n, x) 

 

>>> chebyshevt(n, 0) 

cos(pi*n/2) 

>>> chebyshevt(n, -1) 

(-1)**n 

 

>>> diff(chebyshevt(n, x), x) 

n*chebyshevu(n - 1, x) 

 

See Also 

======== 

 

jacobi, gegenbauer, 

chebyshevt_root, chebyshevu, chebyshevu_root, 

legendre, assoc_legendre, 

hermite, 

laguerre, assoc_laguerre, 

sympy.polys.orthopolys.jacobi_poly 

sympy.polys.orthopolys.gegenbauer_poly 

sympy.polys.orthopolys.chebyshevt_poly 

sympy.polys.orthopolys.chebyshevu_poly 

sympy.polys.orthopolys.hermite_poly 

sympy.polys.orthopolys.legendre_poly 

sympy.polys.orthopolys.laguerre_poly 

 

References 

========== 

 

.. [1] http://en.wikipedia.org/wiki/Chebyshev_polynomial 

.. [2] http://mathworld.wolfram.com/ChebyshevPolynomialoftheFirstKind.html 

.. [3] http://mathworld.wolfram.com/ChebyshevPolynomialoftheSecondKind.html 

.. [4] http://functions.wolfram.com/Polynomials/ChebyshevT/ 

.. [5] http://functions.wolfram.com/Polynomials/ChebyshevU/ 

""" 

 

_ortho_poly = staticmethod(chebyshevt_poly) 

 

@classmethod 

def eval(cls, n, x): 

if not n.is_Number: 

# Symbolic result T_n(x) 

# T_n(-x) ---> (-1)**n * T_n(x) 

if x.could_extract_minus_sign(): 

return S.NegativeOne**n * chebyshevt(n, -x) 

# T_{-n}(x) ---> T_n(x) 

if n.could_extract_minus_sign(): 

return chebyshevt(-n, x) 

# We can evaluate for some special values of x 

if x == S.Zero: 

return cos(S.Half * S.Pi * n) 

if x == S.One: 

return S.One 

elif x == S.Infinity: 

return S.Infinity 

else: 

# n is a given fixed integer, evaluate into polynomial 

if n.is_negative: 

# T_{-n}(x) == T_n(x) 

return cls._eval_at_order(-n, x) 

else: 

return cls._eval_at_order(n, x) 

 

def fdiff(self, argindex=2): 

if argindex == 1: 

# Diff wrt n 

raise ArgumentIndexError(self, argindex) 

elif argindex == 2: 

# Diff wrt x 

n, x = self.args 

return n * chebyshevu(n - 1, x) 

else: 

raise ArgumentIndexError(self, argindex) 

 

def _eval_rewrite_as_polynomial(self, n, x): 

from sympy import Sum 

k = Dummy("k") 

kern = binomial(n, 2*k) * (x**2 - 1)**k * x**(n - 2*k) 

return Sum(kern, (k, 0, floor(n/2))) 

 

 

class chebyshevu(OrthogonalPolynomial): 

r""" 

Chebyshev polynomial of the second kind, :math:`U_n(x)` 

 

chebyshevu(n, x) gives the nth Chebyshev polynomial of the second 

kind in x, :math:`U_n(x)`. 

 

The Chebyshev polynomials of the second kind are orthogonal on 

:math:`[-1, 1]` with respect to the weight :math:`\sqrt{1-x^2}`. 

 

Examples 

======== 

 

>>> from sympy import chebyshevt, chebyshevu, diff 

>>> from sympy.abc import n,x 

>>> chebyshevu(0, x) 

1 

>>> chebyshevu(1, x) 

2*x 

>>> chebyshevu(2, x) 

4*x**2 - 1 

 

>>> chebyshevu(n, x) 

chebyshevu(n, x) 

>>> chebyshevu(n, -x) 

(-1)**n*chebyshevu(n, x) 

>>> chebyshevu(-n, x) 

-chebyshevu(n - 2, x) 

 

>>> chebyshevu(n, 0) 

cos(pi*n/2) 

>>> chebyshevu(n, 1) 

n + 1 

 

>>> diff(chebyshevu(n, x), x) 

(-x*chebyshevu(n, x) + (n + 1)*chebyshevt(n + 1, x))/(x**2 - 1) 

 

See Also 

======== 

 

jacobi, gegenbauer, 

chebyshevt, chebyshevt_root, chebyshevu_root, 

legendre, assoc_legendre, 

hermite, 

laguerre, assoc_laguerre, 

sympy.polys.orthopolys.jacobi_poly 

sympy.polys.orthopolys.gegenbauer_poly 

sympy.polys.orthopolys.chebyshevt_poly 

sympy.polys.orthopolys.chebyshevu_poly 

sympy.polys.orthopolys.hermite_poly 

sympy.polys.orthopolys.legendre_poly 

sympy.polys.orthopolys.laguerre_poly 

 

References 

========== 

 

.. [1] http://en.wikipedia.org/wiki/Chebyshev_polynomial 

.. [2] http://mathworld.wolfram.com/ChebyshevPolynomialoftheFirstKind.html 

.. [3] http://mathworld.wolfram.com/ChebyshevPolynomialoftheSecondKind.html 

.. [4] http://functions.wolfram.com/Polynomials/ChebyshevT/ 

.. [5] http://functions.wolfram.com/Polynomials/ChebyshevU/ 

""" 

 

_ortho_poly = staticmethod(chebyshevu_poly) 

 

@classmethod 

def eval(cls, n, x): 

if not n.is_Number: 

# Symbolic result U_n(x) 

# U_n(-x) ---> (-1)**n * U_n(x) 

if x.could_extract_minus_sign(): 

return S.NegativeOne**n * chebyshevu(n, -x) 

# U_{-n}(x) ---> -U_{n-2}(x) 

if n.could_extract_minus_sign(): 

if n == S.NegativeOne: 

return S.Zero 

else: 

return -chebyshevu(-n - 2, x) 

# We can evaluate for some special values of x 

if x == S.Zero: 

return cos(S.Half * S.Pi * n) 

if x == S.One: 

return S.One + n 

elif x == S.Infinity: 

return S.Infinity 

else: 

# n is a given fixed integer, evaluate into polynomial 

if n.is_negative: 

# U_{-n}(x) ---> -U_{n-2}(x) 

if n == S.NegativeOne: 

return S.Zero 

else: 

return -cls._eval_at_order(-n - 2, x) 

else: 

return cls._eval_at_order(n, x) 

 

def fdiff(self, argindex=2): 

if argindex == 1: 

# Diff wrt n 

raise ArgumentIndexError(self, argindex) 

elif argindex == 2: 

# Diff wrt x 

n, x = self.args 

return ((n + 1) * chebyshevt(n + 1, x) - x * chebyshevu(n, x)) / (x**2 - 1) 

else: 

raise ArgumentIndexError(self, argindex) 

 

def _eval_rewrite_as_polynomial(self, n, x): 

from sympy import Sum 

k = Dummy("k") 

kern = S.NegativeOne**k * factorial( 

n - k) * (2*x)**(n - 2*k) / (factorial(k) * factorial(n - 2*k)) 

return Sum(kern, (k, 0, floor(n/2))) 

 

 

class chebyshevt_root(Function): 

r""" 

chebyshev_root(n, k) returns the kth root (indexed from zero) of 

the nth Chebyshev polynomial of the first kind; that is, if 

0 <= k < n, chebyshevt(n, chebyshevt_root(n, k)) == 0. 

 

Examples 

======== 

 

>>> from sympy import chebyshevt, chebyshevt_root 

>>> chebyshevt_root(3, 2) 

-sqrt(3)/2 

>>> chebyshevt(3, chebyshevt_root(3, 2)) 

0 

 

See Also 

======== 

 

jacobi, gegenbauer, 

chebyshevt, chebyshevu, chebyshevu_root, 

legendre, assoc_legendre, 

hermite, 

laguerre, assoc_laguerre, 

sympy.polys.orthopolys.jacobi_poly 

sympy.polys.orthopolys.gegenbauer_poly 

sympy.polys.orthopolys.chebyshevt_poly 

sympy.polys.orthopolys.chebyshevu_poly 

sympy.polys.orthopolys.hermite_poly 

sympy.polys.orthopolys.legendre_poly 

sympy.polys.orthopolys.laguerre_poly 

""" 

 

@classmethod 

def eval(cls, n, k): 

if not ((0 <= k) and (k < n)): 

raise ValueError("must have 0 <= k < n, " 

"got k = %s and n = %s" % (k, n)) 

return cos(S.Pi*(2*k + 1)/(2*n)) 

 

 

class chebyshevu_root(Function): 

r""" 

chebyshevu_root(n, k) returns the kth root (indexed from zero) of the 

nth Chebyshev polynomial of the second kind; that is, if 0 <= k < n, 

chebyshevu(n, chebyshevu_root(n, k)) == 0. 

 

Examples 

======== 

 

>>> from sympy import chebyshevu, chebyshevu_root 

>>> chebyshevu_root(3, 2) 

-sqrt(2)/2 

>>> chebyshevu(3, chebyshevu_root(3, 2)) 

0 

 

See Also 

======== 

 

chebyshevt, chebyshevt_root, chebyshevu, 

legendre, assoc_legendre, 

hermite, 

laguerre, assoc_laguerre, 

sympy.polys.orthopolys.jacobi_poly 

sympy.polys.orthopolys.gegenbauer_poly 

sympy.polys.orthopolys.chebyshevt_poly 

sympy.polys.orthopolys.chebyshevu_poly 

sympy.polys.orthopolys.hermite_poly 

sympy.polys.orthopolys.legendre_poly 

sympy.polys.orthopolys.laguerre_poly 

""" 

 

 

@classmethod 

def eval(cls, n, k): 

if not ((0 <= k) and (k < n)): 

raise ValueError("must have 0 <= k < n, " 

"got k = %s and n = %s" % (k, n)) 

return cos(S.Pi*(k + 1)/(n + 1)) 

 

#---------------------------------------------------------------------------- 

# Legendre polynomials and Associated Legendre polynomials 

# 

 

 

class legendre(OrthogonalPolynomial): 

r""" 

legendre(n, x) gives the nth Legendre polynomial of x, :math:`P_n(x)` 

 

The Legendre polynomials are orthogonal on [-1, 1] with respect to 

the constant weight 1. They satisfy :math:`P_n(1) = 1` for all n; further, 

:math:`P_n` is odd for odd n and even for even n. 

 

Examples 

======== 

 

>>> from sympy import legendre, diff 

>>> from sympy.abc import x, n 

>>> legendre(0, x) 

1 

>>> legendre(1, x) 

x 

>>> legendre(2, x) 

3*x**2/2 - 1/2 

>>> legendre(n, x) 

legendre(n, x) 

>>> diff(legendre(n,x), x) 

n*(x*legendre(n, x) - legendre(n - 1, x))/(x**2 - 1) 

 

See Also 

======== 

 

jacobi, gegenbauer, 

chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root, 

assoc_legendre, 

hermite, 

laguerre, assoc_laguerre, 

sympy.polys.orthopolys.jacobi_poly 

sympy.polys.orthopolys.gegenbauer_poly 

sympy.polys.orthopolys.chebyshevt_poly 

sympy.polys.orthopolys.chebyshevu_poly 

sympy.polys.orthopolys.hermite_poly 

sympy.polys.orthopolys.legendre_poly 

sympy.polys.orthopolys.laguerre_poly 

 

References 

========== 

 

.. [1] http://en.wikipedia.org/wiki/Legendre_polynomial 

.. [2] http://mathworld.wolfram.com/LegendrePolynomial.html 

.. [3] http://functions.wolfram.com/Polynomials/LegendreP/ 

.. [4] http://functions.wolfram.com/Polynomials/LegendreP2/ 

""" 

 

_ortho_poly = staticmethod(legendre_poly) 

 

@classmethod 

def eval(cls, n, x): 

if not n.is_Number: 

# Symbolic result L_n(x) 

# L_n(-x) ---> (-1)**n * L_n(x) 

if x.could_extract_minus_sign(): 

return S.NegativeOne**n * legendre(n, -x) 

# L_{-n}(x) ---> L_{n-1}(x) 

if n.could_extract_minus_sign(): 

return legendre(-n - S.One, x) 

# We can evaluate for some special values of x 

if x == S.Zero: 

return sqrt(S.Pi)/(gamma(S.Half - n/2)*gamma(S.One + n/2)) 

elif x == S.One: 

return S.One 

elif x == S.Infinity: 

return S.Infinity 

else: 

# n is a given fixed integer, evaluate into polynomial 

if n.is_negative: 

raise ValueError( 

"The index n must be nonnegative integer (got %r)" % n) 

else: 

return cls._eval_at_order(n, x) 

 

def fdiff(self, argindex=2): 

if argindex == 1: 

# Diff wrt n 

raise ArgumentIndexError(self, argindex) 

elif argindex == 2: 

# Diff wrt x 

# Find better formula, this is unsuitable for x = 1 

n, x = self.args 

return n/(x**2 - 1)*(x*legendre(n, x) - legendre(n - 1, x)) 

else: 

raise ArgumentIndexError(self, argindex) 

 

def _eval_rewrite_as_polynomial(self, n, x): 

from sympy import Sum 

k = Dummy("k") 

kern = (-1)**k*binomial(n, k)**2*((1 + x)/2)**(n - k)*((1 - x)/2)**k 

return Sum(kern, (k, 0, n)) 

 

 

class assoc_legendre(Function): 

r""" 

assoc_legendre(n,m, x) gives :math:`P_n^m(x)`, where n and m are 

the degree and order or an expression which is related to the nth 

order Legendre polynomial, :math:`P_n(x)` in the following manner: 

 

.. math:: 

P_n^m(x) = (-1)^m (1 - x^2)^{\frac{m}{2}} 

\frac{\mathrm{d}^m P_n(x)}{\mathrm{d} x^m} 

 

Associated Legendre polynomial are orthogonal on [-1, 1] with: 

 

- weight = 1 for the same m, and different n. 

- weight = 1/(1-x**2) for the same n, and different m. 

 

Examples 

======== 

 

>>> from sympy import assoc_legendre 

>>> from sympy.abc import x, m, n 

>>> assoc_legendre(0,0, x) 

1 

>>> assoc_legendre(1,0, x) 

x 

>>> assoc_legendre(1,1, x) 

-sqrt(-x**2 + 1) 

>>> assoc_legendre(n,m,x) 

assoc_legendre(n, m, x) 

 

See Also 

======== 

 

jacobi, gegenbauer, 

chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root, 

legendre, 

hermite, 

laguerre, assoc_laguerre, 

sympy.polys.orthopolys.jacobi_poly 

sympy.polys.orthopolys.gegenbauer_poly 

sympy.polys.orthopolys.chebyshevt_poly 

sympy.polys.orthopolys.chebyshevu_poly 

sympy.polys.orthopolys.hermite_poly 

sympy.polys.orthopolys.legendre_poly 

sympy.polys.orthopolys.laguerre_poly 

 

References 

========== 

 

.. [1] http://en.wikipedia.org/wiki/Associated_Legendre_polynomials 

.. [2] http://mathworld.wolfram.com/LegendrePolynomial.html 

.. [3] http://functions.wolfram.com/Polynomials/LegendreP/ 

.. [4] http://functions.wolfram.com/Polynomials/LegendreP2/ 

""" 

 

@classmethod 

def _eval_at_order(cls, n, m): 

P = legendre_poly(n, _x, polys=True).diff((_x, m)) 

return (-1)**m * (1 - _x**2)**Rational(m, 2) * P.as_expr() 

 

@classmethod 

def eval(cls, n, m, x): 

if m.could_extract_minus_sign(): 

# P^{-m}_n ---> F * P^m_n 

return S.NegativeOne**(-m) * (factorial(m + n)/factorial(n - m)) * assoc_legendre(n, -m, x) 

if m == 0: 

# P^0_n ---> L_n 

return legendre(n, x) 

if x == 0: 

return 2**m*sqrt(S.Pi) / (gamma((1 - m - n)/2)*gamma(1 - (m - n)/2)) 

if n.is_Number and m.is_Number and n.is_integer and m.is_integer: 

if n.is_negative: 

raise ValueError("%s : 1st index must be nonnegative integer (got %r)" % (cls, n)) 

if abs(m) > n: 

raise ValueError("%s : abs('2nd index') must be <= '1st index' (got %r, %r)" % (cls, n, m)) 

return cls._eval_at_order(int(n), abs(int(m))).subs(_x, x) 

 

def fdiff(self, argindex=3): 

if argindex == 1: 

# Diff wrt n 

raise ArgumentIndexError(self, argindex) 

elif argindex == 2: 

# Diff wrt m 

raise ArgumentIndexError(self, argindex) 

elif argindex == 3: 

# Diff wrt x 

# Find better formula, this is unsuitable for x = 1 

n, m, x = self.args 

return 1/(x**2 - 1)*(x*n*assoc_legendre(n, m, x) - (m + n)*assoc_legendre(n - 1, m, x)) 

else: 

raise ArgumentIndexError(self, argindex) 

 

def _eval_rewrite_as_polynomial(self, n, m, x): 

from sympy import Sum 

k = Dummy("k") 

kern = factorial(2*n - 2*k)/(2**n*factorial(n - k)*factorial( 

k)*factorial(n - 2*k - m))*(-1)**k*x**(n - m - 2*k) 

return (1 - x**2)**(m/2) * Sum(kern, (k, 0, floor((n - m)*S.Half))) 

 

def _eval_conjugate(self): 

n, m, x = self.args 

return self.func(n, m.conjugate(), x.conjugate()) 

 

#---------------------------------------------------------------------------- 

# Hermite polynomials 

# 

 

 

class hermite(OrthogonalPolynomial): 

r""" 

hermite(n, x) gives the nth Hermite polynomial in x, :math:`H_n(x)` 

 

The Hermite polynomials are orthogonal on :math:`(-\infty, \infty)` 

with respect to the weight :math:`\exp\left(-\frac{x^2}{2}\right)`. 

 

Examples 

======== 

 

>>> from sympy import hermite, diff 

>>> from sympy.abc import x, n 

>>> hermite(0, x) 

1 

>>> hermite(1, x) 

2*x 

>>> hermite(2, x) 

4*x**2 - 2 

>>> hermite(n, x) 

hermite(n, x) 

>>> diff(hermite(n,x), x) 

2*n*hermite(n - 1, x) 

>>> hermite(n, -x) 

(-1)**n*hermite(n, x) 

 

See Also 

======== 

 

jacobi, gegenbauer, 

chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root, 

legendre, assoc_legendre, 

laguerre, assoc_laguerre, 

sympy.polys.orthopolys.jacobi_poly 

sympy.polys.orthopolys.gegenbauer_poly 

sympy.polys.orthopolys.chebyshevt_poly 

sympy.polys.orthopolys.chebyshevu_poly 

sympy.polys.orthopolys.hermite_poly 

sympy.polys.orthopolys.legendre_poly 

sympy.polys.orthopolys.laguerre_poly 

 

References 

========== 

 

.. [1] http://en.wikipedia.org/wiki/Hermite_polynomial 

.. [2] http://mathworld.wolfram.com/HermitePolynomial.html 

.. [3] http://functions.wolfram.com/Polynomials/HermiteH/ 

""" 

 

_ortho_poly = staticmethod(hermite_poly) 

 

@classmethod 

def eval(cls, n, x): 

if not n.is_Number: 

# Symbolic result H_n(x) 

# H_n(-x) ---> (-1)**n * H_n(x) 

if x.could_extract_minus_sign(): 

return S.NegativeOne**n * hermite(n, -x) 

# We can evaluate for some special values of x 

if x == S.Zero: 

return 2**n * sqrt(S.Pi) / gamma((S.One - n)/2) 

elif x == S.Infinity: 

return S.Infinity 

else: 

# n is a given fixed integer, evaluate into polynomial 

if n.is_negative: 

raise ValueError( 

"The index n must be nonnegative integer (got %r)" % n) 

else: 

return cls._eval_at_order(n, x) 

 

def fdiff(self, argindex=2): 

if argindex == 1: 

# Diff wrt n 

raise ArgumentIndexError(self, argindex) 

elif argindex == 2: 

# Diff wrt x 

n, x = self.args 

return 2*n*hermite(n - 1, x) 

else: 

raise ArgumentIndexError(self, argindex) 

 

def _eval_rewrite_as_polynomial(self, n, x): 

from sympy import Sum 

k = Dummy("k") 

kern = (-1)**k / (factorial(k)*factorial(n - 2*k)) * (2*x)**(n - 2*k) 

return factorial(n)*Sum(kern, (k, 0, floor(n/2))) 

 

#---------------------------------------------------------------------------- 

# Laguerre polynomials 

# 

 

 

class laguerre(OrthogonalPolynomial): 

r""" 

Returns the nth Laguerre polynomial in x, :math:`L_n(x)`. 

 

Parameters 

========== 

 

n : int 

Degree of Laguerre polynomial. Must be ``n >= 0``. 

 

Examples 

======== 

 

>>> from sympy import laguerre, diff 

>>> from sympy.abc import x, n 

>>> laguerre(0, x) 

1 

>>> laguerre(1, x) 

-x + 1 

>>> laguerre(2, x) 

x**2/2 - 2*x + 1 

>>> laguerre(3, x) 

-x**3/6 + 3*x**2/2 - 3*x + 1 

 

>>> laguerre(n, x) 

laguerre(n, x) 

 

>>> diff(laguerre(n, x), x) 

-assoc_laguerre(n - 1, 1, x) 

 

See Also 

======== 

 

jacobi, gegenbauer, 

chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root, 

legendre, assoc_legendre, 

hermite, 

assoc_laguerre, 

sympy.polys.orthopolys.jacobi_poly 

sympy.polys.orthopolys.gegenbauer_poly 

sympy.polys.orthopolys.chebyshevt_poly 

sympy.polys.orthopolys.chebyshevu_poly 

sympy.polys.orthopolys.hermite_poly 

sympy.polys.orthopolys.legendre_poly 

sympy.polys.orthopolys.laguerre_poly 

 

References 

========== 

 

.. [1] http://en.wikipedia.org/wiki/Laguerre_polynomial 

.. [2] http://mathworld.wolfram.com/LaguerrePolynomial.html 

.. [3] http://functions.wolfram.com/Polynomials/LaguerreL/ 

.. [4] http://functions.wolfram.com/Polynomials/LaguerreL3/ 

""" 

 

@classmethod 

def eval(cls, n, x): 

if not n.is_Number: 

# Symbolic result L_n(x) 

# L_{n}(-x) ---> exp(-x) * L_{-n-1}(x) 

# L_{-n}(x) ---> exp(x) * L_{n-1}(-x) 

if n.could_extract_minus_sign(): 

return exp(x) * laguerre(n - 1, -x) 

# We can evaluate for some special values of x 

if x == S.Zero: 

return S.One 

elif x == S.NegativeInfinity: 

return S.Infinity 

elif x == S.Infinity: 

return S.NegativeOne**n * S.Infinity 

else: 

# n is a given fixed integer, evaluate into polynomial 

if n.is_negative: 

raise ValueError( 

"The index n must be nonnegative integer (got %r)" % n) 

else: 

return laguerre_poly(n, x, 0) 

 

def fdiff(self, argindex=2): 

if argindex == 1: 

# Diff wrt n 

raise ArgumentIndexError(self, argindex) 

elif argindex == 2: 

# Diff wrt x 

n, x = self.args 

return -assoc_laguerre(n - 1, 1, x) 

else: 

raise ArgumentIndexError(self, argindex) 

 

def _eval_rewrite_as_polynomial(self, n, x): 

from sympy import Sum 

# Make sure n \in N_0 

if n.is_negative or n.is_integer is False: 

raise ValueError("Error: n should be a non-negative integer.") 

k = Dummy("k") 

kern = RisingFactorial(-n, k) / factorial(k)**2 * x**k 

return Sum(kern, (k, 0, n)) 

 

 

class assoc_laguerre(OrthogonalPolynomial): 

r""" 

Returns the nth generalized Laguerre polynomial in x, :math:`L_n(x)`. 

 

Parameters 

========== 

 

n : int 

Degree of Laguerre polynomial. Must be ``n >= 0``. 

 

alpha : Expr 

Arbitrary expression. For ``alpha=0`` regular Laguerre 

polynomials will be generated. 

 

Examples 

======== 

 

>>> from sympy import laguerre, assoc_laguerre, diff 

>>> from sympy.abc import x, n, a 

>>> assoc_laguerre(0, a, x) 

1 

>>> assoc_laguerre(1, a, x) 

a - x + 1 

>>> assoc_laguerre(2, a, x) 

a**2/2 + 3*a/2 + x**2/2 + x*(-a - 2) + 1 

>>> assoc_laguerre(3, a, x) 

a**3/6 + a**2 + 11*a/6 - x**3/6 + x**2*(a/2 + 3/2) + 

x*(-a**2/2 - 5*a/2 - 3) + 1 

 

>>> assoc_laguerre(n, a, 0) 

binomial(a + n, a) 

 

>>> assoc_laguerre(n, a, x) 

assoc_laguerre(n, a, x) 

 

>>> assoc_laguerre(n, 0, x) 

laguerre(n, x) 

 

>>> diff(assoc_laguerre(n, a, x), x) 

-assoc_laguerre(n - 1, a + 1, x) 

 

>>> diff(assoc_laguerre(n, a, x), a) 

Sum(assoc_laguerre(_k, a, x)/(-a + n), (_k, 0, n - 1)) 

 

See Also 

======== 

 

jacobi, gegenbauer, 

chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root, 

legendre, assoc_legendre, 

hermite, 

laguerre, 

sympy.polys.orthopolys.jacobi_poly 

sympy.polys.orthopolys.gegenbauer_poly 

sympy.polys.orthopolys.chebyshevt_poly 

sympy.polys.orthopolys.chebyshevu_poly 

sympy.polys.orthopolys.hermite_poly 

sympy.polys.orthopolys.legendre_poly 

sympy.polys.orthopolys.laguerre_poly 

 

References 

========== 

 

.. [1] http://en.wikipedia.org/wiki/Laguerre_polynomial#Assoc_laguerre_polynomials 

.. [2] http://mathworld.wolfram.com/AssociatedLaguerrePolynomial.html 

.. [3] http://functions.wolfram.com/Polynomials/LaguerreL/ 

.. [4] http://functions.wolfram.com/Polynomials/LaguerreL3/ 

""" 

 

@classmethod 

def eval(cls, n, alpha, x): 

# L_{n}^{0}(x) ---> L_{n}(x) 

if alpha == S.Zero: 

return laguerre(n, x) 

 

if not n.is_Number: 

# We can evaluate for some special values of x 

if x == S.Zero: 

return binomial(n + alpha, alpha) 

elif x == S.Infinity and n > S.Zero: 

return S.NegativeOne**n * S.Infinity 

elif x == S.NegativeInfinity and n > S.Zero: 

return S.Infinity 

else: 

# n is a given fixed integer, evaluate into polynomial 

if n.is_negative: 

raise ValueError( 

"The index n must be nonnegative integer (got %r)" % n) 

else: 

return laguerre_poly(n, x, alpha) 

 

def fdiff(self, argindex=3): 

from sympy import Sum 

if argindex == 1: 

# Diff wrt n 

raise ArgumentIndexError(self, argindex) 

elif argindex == 2: 

# Diff wrt alpha 

n, alpha, x = self.args 

k = Dummy("k") 

return Sum(assoc_laguerre(k, alpha, x) / (n - alpha), (k, 0, n - 1)) 

elif argindex == 3: 

# Diff wrt x 

n, alpha, x = self.args 

return -assoc_laguerre(n - 1, alpha + 1, x) 

else: 

raise ArgumentIndexError(self, argindex) 

 

def _eval_rewrite_as_polynomial(self, n, x): 

from sympy import Sum 

# Make sure n \in N_0 

if n.is_negative or n.is_integer is False: 

raise ValueError("Error: n should be a non-negative integer.") 

k = Dummy("k") 

kern = RisingFactorial( 

-n, k) / (gamma(k + alpha + 1) * factorial(k)) * x**k 

return gamma(n + alpha + 1) / factorial(n) * Sum(kern, (k, 0, n)) 

 

def _eval_conjugate(self): 

n, alpha, x = self.args 

return self.func(n, alpha.conjugate(), x.conjugate())