mathematica 中是否有可用于定义输入类型的函数头?
我正在定义一个函数,该函数将函数作为输入,并且我想在输入类型中指定它,即 Operat[_?FunctionQ]:=... 但目前mathematica中还没有函数Q。除了根本不指定任何类型之外,我该如何解决这个问题。
有什么想法吗?
哦! 这是:测试表达式是否是函数? 可能就是我正在寻找的答案。我正在进一步阅读
那里提出的解决方案是否可靠?,即:
FunctionQ[_Function | _InterpolatingFunction | _CompiledFunction] = True;
FunctionQ[f_Symbol] := Or[
DownValues[f] =!= {},
MemberQ[ Attributes[f], NumericFunction ]]
FunctionQ[_] = False;
I am defining a function that takes as input a function and I want to specify it in the input type i.e. Operat[_?FunctionQ]:=...
But there is no functionQ as of yet in mathematica. How do I get aroud this except not specifying any type at all.
Any ideas?
Oh!
This: Test if an expression is a Function?
may be the answer i am looking for. I am reading further
Is the solution proposed there robust?, i.e.:
FunctionQ[_Function | _InterpolatingFunction | _CompiledFunction] = True;
FunctionQ[f_Symbol] := Or[
DownValues[f] =!= {},
MemberQ[ Attributes[f], NumericFunction ]]
FunctionQ[_] = False;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所展示的定义具有很大的实用性。问题是:Mathematica 中的函数到底由什么构成?纯函数等很容易归类为函数,但是涉及模式匹配的定义又如何呢?考虑一下:
h
是否被视为函数?如果是这样,将很难识别,因为需要检查系统中每个品种的上值才能做出决定。g
是一个函数吗?它有一个向上值,但g[x]
是一个惰性表达式。头部组合怎么样:
f
是一个函数吗?f[1]
或f[1][2]
怎么样?然后还有各种功能,例如 JLink 和 NETLink:
obj@toString 是函数吗?
我讨厌在不提供解决方案的情况下提出这些问题——但我想强调,在 Mathematica 环境中什么构成函数的问题是一个棘手的问题。从理论和实践的角度来看,这都是棘手的。
我认为所展示的功能测试是否完整的答案实际上取决于您将在特定应用程序中输入的表达式类型。
The exhibited definition has great utility. The question is: what exactly constitutes a function in Mathematica? Pure functions and the like are easily to classify as functions, but what about definitions that involve pattern-matching? Consider:
Is
h
to be considered a function? If so, it will be hard to identify as it will entail examining the up-values of every symbol in the system to make that determination. Isg
a function? It has an up-value, butg[x]
is an inert expression.What about head composition:
Is
f
a function? How aboutf[1]
orf[1][2]
?And then there are the various capabilities like JLink and NETLink:
Is
obj@toString
a function?I hate to bring up these problems without offering solutions -- but I want to emphasize that the question as to what constitutes a function in the Mathematica context is a tricky one. It is tricky from both the theoretical and practical standpoints.
I think that the answer to whether the exhibited function test is complete really depends upon the types of expressions that you will be feeding it in your specific application.