54
54
from sage .symbolic .function import BuiltinFunction
55
55
from sage .rings .all import ComplexIntervalField , ZZ
56
56
57
- class GeneralizedFunction (BuiltinFunction ):
58
- def _evalf_ (self , * args , ** kwds ):
59
- return self .gen_eval (* args )
60
-
61
- class FunctionDiracDelta (GeneralizedFunction ):
57
+ class FunctionDiracDelta (BuiltinFunction ):
62
58
r"""
63
59
The Dirac delta (generalized) function, `\delta(x)` (``dirac_delta(x)``).
64
60
@@ -145,9 +141,6 @@ def _eval_(self, x):
145
141
sage: dirac_delta(x).subs(x=1)
146
142
0
147
143
"""
148
- return self .gen_eval (x )
149
-
150
- def gen_eval (self , x ):
151
144
try :
152
145
approx_x = ComplexIntervalField ()(x )
153
146
if bool (approx_x .imag () == 0 ): # x is real
@@ -157,10 +150,13 @@ def gen_eval(self, x):
157
150
return ZZ (0 )
158
151
except TypeError : # x is symbolic
159
152
pass
153
+
154
+ def _evalf_ (self , * args , ** kwds ):
155
+ return self ._eval_ (* args , ** kwds )
160
156
161
157
dirac_delta = FunctionDiracDelta ()
162
158
163
- class FunctionHeaviside (GeneralizedFunction ):
159
+ class FunctionHeaviside (BuiltinFunction ):
164
160
r"""
165
161
The Heaviside step function, `H(x)` (``heaviside(x)``).
166
162
@@ -250,9 +246,6 @@ def _eval_(self, x):
250
246
sage: t.subs(x=1)
251
247
2
252
248
"""
253
- return self .gen_eval (x )
254
-
255
- def gen_eval (self , x ):
256
249
try :
257
250
approx_x = ComplexIntervalField ()(x )
258
251
if bool (approx_x .imag () == 0 ): # x is real
@@ -266,6 +259,9 @@ def gen_eval(self, x):
266
259
except TypeError : # x is symbolic
267
260
pass
268
261
262
+ def _evalf_ (self , * args , ** kwds ):
263
+ return self ._eval_ (* args , ** kwds )
264
+
269
265
def _derivative_ (self , x , diff_param = None ):
270
266
"""
271
267
Derivative of Heaviside step function
@@ -279,7 +275,7 @@ def _derivative_(self, x, diff_param=None):
279
275
280
276
heaviside = FunctionHeaviside ()
281
277
282
- class FunctionUnitStep (GeneralizedFunction ):
278
+ class FunctionUnitStep (BuiltinFunction ):
283
279
r"""
284
280
The unit step function, `\mathrm{u}(x)` (``unit_step(x)``).
285
281
@@ -361,9 +357,6 @@ def _eval_(self, x):
361
357
sage: unit_step(x).subs(x=0)
362
358
1
363
359
"""
364
- return self .gen_eval (x )
365
-
366
- def gen_eval (self , x ):
367
360
try :
368
361
approx_x = ComplexIntervalField ()(x )
369
362
if bool (approx_x .imag () == 0 ): # x is real
@@ -377,6 +370,9 @@ def gen_eval(self, x):
377
370
except TypeError : # x is symbolic
378
371
pass
379
372
373
+ def _evalf_ (self , * args , ** kwds ):
374
+ return self ._eval_ (* args , ** kwds )
375
+
380
376
def _derivative_ (self , x , diff_param = None ):
381
377
"""
382
378
Derivative of unit step function
@@ -390,7 +386,7 @@ def _derivative_(self, x, diff_param=None):
390
386
391
387
unit_step = FunctionUnitStep ()
392
388
393
- class FunctionSignum (GeneralizedFunction ):
389
+ class FunctionSignum (BuiltinFunction ):
394
390
r"""
395
391
The signum or sgn function `\mathrm{sgn}(x)` (``sgn(x)``).
396
392
@@ -499,9 +495,6 @@ def _eval_(self, x):
499
495
return x .sign ()
500
496
if hasattr (x ,'sgn' ): # or a sgn method
501
497
return x .sgn ()
502
- return self .gen_eval (x )
503
-
504
- def gen_eval (self , x ):
505
498
try :
506
499
approx_x = ComplexIntervalField ()(x )
507
500
if bool (approx_x .imag () == 0 ): # x is real
@@ -515,6 +508,9 @@ def gen_eval(self, x):
515
508
except TypeError : # x is symbolic
516
509
pass
517
510
511
+ def _evalf_ (self , * args , ** kwds ):
512
+ return self ._eval_ (* args , ** kwds )
513
+
518
514
def _derivative_ (self , x , diff_param = None ):
519
515
"""
520
516
Derivative of sgn function
@@ -530,7 +526,7 @@ def _derivative_(self, x, diff_param=None):
530
526
sgn = FunctionSignum ()
531
527
sign = sgn
532
528
533
- class FunctionKroneckerDelta (GeneralizedFunction ):
529
+ class FunctionKroneckerDelta (BuiltinFunction ):
534
530
r"""
535
531
The Kronecker delta function `\delta_{m,n}` (``kronecker_delta(m, n)``).
536
532
@@ -610,9 +606,6 @@ def _eval_(self, m, n):
610
606
if bool (repr (m ) > repr (n )):
611
607
return kronecker_delta (n , m )
612
608
613
- return self .gen_eval (m , n )
614
-
615
- def gen_eval (self , m , n ):
616
609
x = m - n
617
610
try :
618
611
approx_x = ComplexIntervalField ()(x )
@@ -626,6 +619,9 @@ def gen_eval(self, m, n):
626
619
except TypeError : # x is symbolic
627
620
pass
628
621
622
+ def _evalf_ (self , * args , ** kwds ):
623
+ return self ._eval_ (* args , ** kwds )
624
+
629
625
def _derivative_ (self , * args , ** kwds ):
630
626
"""
631
627
Derivative of Kronecker delta
0 commit comments