How to check if function name is in a list?
sagemath 8.9
I am still not good in sagemath and learning it. I am trying to convert this code from Maple to sagemath, but I do not know why it is not working in sagemath.
Given a function, I need to find if it is a member of list of known functions. This is easier explained with an example.
Say the input is gamma(-1,t)
and I need to find if the function, which is gamma
in this case in member of a list of names of functions, such as [erf,gamma,cos, etc...]
. I will show the Maple code and how I translated to sagemath. But in sagemath it gives false instead of true.
Maple:
restart;
expr:=gamma(-1,t);
op(0,expr); #extract the head, which is just the name of the function
gamma
member(op(0,expr),[erf,gamma]); #check if it is in the list
true
This is in sagemath
sage: var('t')
sage: from sage.all import *
sage: expr=gamma(-1,t)
sage: expr.operator()
gamma
sage: expr.operator() in [erf,gamma]
False
So I must be doing something wrong in sagemath. It might be due to type, because when I do
sage: type(expr.operator())
<class 'sage.functions.gamma.Function_gamma_inc'>
Do I need to import something to make it work? I think the name gamma
inside the list is not taken as the same as the name gamma
which results from expr.operator()
and that is why it gives False
. But do not know how to fix it.
The idea is to check if the function is among a list of known function names in a list. How to do this in sagemath?
Thanks --Nasser