File tree 2 files changed +25
-2
lines changed
2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -2415,8 +2415,15 @@ class Pow(Expr):
2415
2415
class Function (Expr ):
2416
2416
2417
2417
def __new__ (cls , *args , **kwargs ):
2418
- if cls == Function and len (args) == 1 :
2419
- return UndefFunction(args[0 ])
2418
+ if cls == Function:
2419
+ nargs = len (args)
2420
+ if nargs == 0 :
2421
+ raise TypeError (" Required at least one argument to Function" )
2422
+ elif nargs == 1 :
2423
+ return UndefFunction(args[0 ])
2424
+ elif nargs > 1 :
2425
+ raise TypeError (f" Unexpected extra arguments {args[1:]}." )
2426
+
2420
2427
return super (Function, cls ).__new__(cls )
2421
2428
2422
2429
@property
@@ -2837,6 +2844,10 @@ class FunctionSymbol(Function):
2837
2844
name = deref(X).get_name().decode(" utf-8" )
2838
2845
return str (name)
2839
2846
2847
+ @property
2848
+ def name (Basic self ):
2849
+ return self .get_name()
2850
+
2840
2851
def _sympy_ (self ):
2841
2852
import sympy
2842
2853
name = self .get_name()
Original file line number Diff line number Diff line change @@ -103,6 +103,18 @@ def test_derivative():
103
103
assert i == fxy .diff (y , 1 , x )
104
104
105
105
106
+ def test_function ():
107
+ x = Symbol ("x" )
108
+ fx = Function ("f" )(x )
109
+ assert fx == function_symbol ("f" , x )
110
+
111
+ raises (TypeError , lambda : Function ("f" , "x" ))
112
+ raises (TypeError , lambda : Function ("f" , x ))
113
+ raises (TypeError , lambda : Function ())
114
+
115
+ assert fx .name == "f"
116
+
117
+
106
118
def test_abs ():
107
119
x = Symbol ("x" )
108
120
e = abs (x )
You can’t perform that action at this time.
0 commit comments