317
317
318
318
319
319
from sage .symbolic .ring import SR , is_SymbolicVariable
320
- from sage .symbolic .function import BuiltinFunction
320
+ from sage .symbolic .function import BuiltinFunction , GinacFunction
321
321
from sage .symbolic .expression import Expression
322
322
from sage .functions .other import factorial , binomial
323
323
from sage .structure .all import parent
@@ -1238,7 +1238,7 @@ def gen_legendre_Q(n, m, x):
1238
1238
return ((n - m + 1 )* x * gen_legendre_Q (n ,m - 1 ,x )- (n + m - 1 )* gen_legendre_Q (n - 1 ,m - 1 ,x ))/ sqrt (1 - x ** 2 )
1239
1239
1240
1240
1241
- def hermite ( n , x ):
1241
+ class Func_hermite ( GinacFunction ):
1242
1242
"""
1243
1243
Returns the Hermite polynomial for integers `n > -1`.
1244
1244
@@ -1257,13 +1257,13 @@ def hermite(n, x):
1257
1257
40
1258
1258
sage: S.<y> = PolynomialRing(RR)
1259
1259
sage: hermite(3,y)
1260
- 8.00000000000000 *y^3 - 12.0000000000000 *y
1260
+ 8*y^3 - 12*y
1261
1261
sage: R.<x,y> = QQ[]
1262
1262
sage: hermite(3,y^2)
1263
1263
8*y^6 - 12*y^2
1264
1264
sage: w = var('w')
1265
1265
sage: hermite(3,2*w)
1266
- 8*(8*w^2 - 3) *w
1266
+ 64*w^3 - 24 *w
1267
1267
1268
1268
Check that :trac:`17192` is fixed::
1269
1269
@@ -1274,19 +1274,27 @@ def hermite(n, x):
1274
1274
sage: hermite(-1,x)
1275
1275
Traceback (most recent call last):
1276
1276
...
1277
- ValueError: n must be greater than -1, got n = -1
1277
+ RuntimeError: hermite_eval: The index n must be a nonnegative integer
1278
1278
1279
1279
sage: hermite(-7,x)
1280
1280
Traceback (most recent call last):
1281
1281
...
1282
- ValueError: n must be greater than -1, got n = -7
1282
+ RuntimeError: hermite_eval: The index n must be a nonnegative integer
1283
1283
"""
1284
- if not (n > - 1 ):
1285
- raise ValueError ("n must be greater than -1, got n = {0}" .format (n ))
1284
+ def __init__ (self ):
1285
+ r"""
1286
+ Init method for the Hermite polynomials.
1286
1287
1287
- _init ()
1288
- return sage_eval (maxima .eval ('hermite(%s,x)' % ZZ (n )), locals = {'x' :x })
1288
+ EXAMPLES::
1289
+
1290
+ sage: loads(dumps(hermite))
1291
+ hermite
1292
+ """
1293
+ GinacFunction .__init__ (self , "hermite" , nargs = 2 , latex_name = r"H" ,
1294
+ conversions = {'maxima' :'hermite' , 'mathematica' :'HermiteH' ,
1295
+ 'maple' :'HermiteH' })
1289
1296
1297
+ hermite = Func_hermite ()
1290
1298
1291
1299
def jacobi_P (n , a , b , x ):
1292
1300
r"""
@@ -1381,7 +1389,7 @@ def legendre_Q(n, x):
1381
1389
return sage_eval (maxima .eval ('legendre_q(%s,x)' % ZZ (n )), locals = {'x' :x })
1382
1390
1383
1391
1384
- def ultraspherical ( n , a , x ):
1392
+ class Func_ultraspherical ( GinacFunction ):
1385
1393
"""
1386
1394
Returns the ultraspherical (or Gegenbauer) polynomial for integers
1387
1395
`n > -1`.
@@ -1394,6 +1402,8 @@ def ultraspherical(n, a, x):
1394
1402
1395
1403
EXAMPLES::
1396
1404
1405
+ sage: ultraspherical(8, 101/11, x)
1406
+ 795972057547264/214358881*x^8 - 62604543852032/19487171*x^6...
1397
1407
sage: x = PolynomialRing(QQ, 'x').gen()
1398
1408
sage: ultraspherical(2,3/2,x)
1399
1409
15/2*x^2 - 3/2
@@ -1404,6 +1414,12 @@ def ultraspherical(n, a, x):
1404
1414
sage: t = PolynomialRing(RationalField(),"t").gen()
1405
1415
sage: gegenbauer(3,2,t)
1406
1416
32*t^3 - 12*t
1417
+ sage: var('x')
1418
+ x
1419
+ sage: for N in range(100):
1420
+ ....: n = ZZ.random_element().abs() + 5
1421
+ ....: a = QQ.random_element().abs() + 5
1422
+ ....: assert ((n+1)*ultraspherical(n+1,a,x) - 2*x*(n+a)*ultraspherical(n,a,x) + (n+2*a-1)*ultraspherical(n-1,a,x)).expand().is_zero()
1407
1423
1408
1424
Check that :trac:`17192` is fixed::
1409
1425
@@ -1414,20 +1430,28 @@ def ultraspherical(n, a, x):
1414
1430
sage: ultraspherical(-1,1,x)
1415
1431
Traceback (most recent call last):
1416
1432
...
1417
- ValueError: n must be greater than -1, got n = -1
1433
+ RuntimeError: gegenb_eval: The index n must be a nonnegative integer
1418
1434
1419
1435
sage: ultraspherical(-7,1,x)
1420
1436
Traceback (most recent call last):
1421
1437
...
1422
- ValueError: n must be greater than -1, got n = -7
1438
+ RuntimeError: gegenb_eval: The index n must be a nonnegative integer
1423
1439
"""
1424
- if not (n > - 1 ):
1425
- raise ValueError ("n must be greater than -1, got n = {0}" .format (n ))
1440
+ def __init__ (self ):
1441
+ r"""
1442
+ Init method for the ultraspherical polynomials.
1426
1443
1427
- _init ()
1428
- return sage_eval (maxima .eval ('ultraspherical(%s,%s,x)' % (ZZ (n ),a )), locals = {'x' :x })
1444
+ EXAMPLES::
1445
+
1446
+ sage: loads(dumps(ultraspherical))
1447
+ gegenbauer
1448
+ """
1449
+ GinacFunction .__init__ (self , "gegenbauer" , nargs = 3 , latex_name = r"C" ,
1450
+ conversions = {'maxima' :'ultraspherical' , 'mathematica' :'GegenbauerC' ,
1451
+ 'maple' :'GegenbauerC' })
1429
1452
1430
- gegenbauer = ultraspherical
1453
+ ultraspherical = Func_ultraspherical ()
1454
+ gegenbauer = Func_ultraspherical ()
1431
1455
1432
1456
1433
1457
class Func_laguerre (OrthogonalFunction ):
0 commit comments