File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -2415,8 +2415,15 @@ class Pow(Expr):
24152415class Function (Expr ):
24162416
24172417 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+
24202427 return super (Function, cls ).__new__(cls )
24212428
24222429 @property
@@ -2837,6 +2844,10 @@ class FunctionSymbol(Function):
28372844 name = deref(X).get_name().decode(" utf-8" )
28382845 return str (name)
28392846
2847+ @property
2848+ def name (Basic self ):
2849+ return self .get_name()
2850+
28402851 def _sympy_ (self ):
28412852 import sympy
28422853 name = self .get_name()
Original file line number Diff line number Diff line change @@ -103,6 +103,18 @@ def test_derivative():
103103 assert i == fxy .diff (y , 1 , x )
104104
105105
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+
106118def test_abs ():
107119 x = Symbol ("x" )
108120 e = abs (x )
You can’t perform that action at this time.
0 commit comments