通过存储在变量中的表达式定义功能运算符的 "result" 不起作用
Defining a functional operator's "result" via an expression stored in a variable is not working
我正在努力弄清楚为什么以下两种定义简单函数运算符 (https://www.maplesoft.com/support/help/Maple/view.aspx?path=operators/functional&term=-%3E) 的方法不等效。我在下面添加了一个简单的例子。如何通过存储在变量中的表达式定义“结果”,如后一个示例所示?我是 Maple 的新手。
# This works fine
f := (x, y) -> y^2 + x^2;
f(1, 2);
# This does not work when I store the "result" expression in a variable first
temp := x^2 + y^2;
f := (x, y) -> temp;
f(1, 2);
这是一个常见的混淆来源。
在你的第二个例子中,你的过程的形式参数 x
和 y
与赋值表达式 [=] 中存在的名称 x
和 y
没有关系16=].
完成第二个示例的常用方法是使用 unapply
命令。
temp := x^2 + y^2;
2 2
temp := x + y
f := unapply(temp, [x,y]);
f := proc (x, y) options operator, arrow; y^2+x^2 end proc
f(1, 2);
5
一种更通用(也是更高级)的方法是用包含匹配名称的表达式替换到模板中。例如,
g := subs(__dummy=temp,
(x,y)->__dummy);
g := proc (x, y) options operator, arrow; y^2+x^2 end proc
g(1, 2);
5
我正在努力弄清楚为什么以下两种定义简单函数运算符 (https://www.maplesoft.com/support/help/Maple/view.aspx?path=operators/functional&term=-%3E) 的方法不等效。我在下面添加了一个简单的例子。如何通过存储在变量中的表达式定义“结果”,如后一个示例所示?我是 Maple 的新手。
# This works fine
f := (x, y) -> y^2 + x^2;
f(1, 2);
# This does not work when I store the "result" expression in a variable first
temp := x^2 + y^2;
f := (x, y) -> temp;
f(1, 2);
这是一个常见的混淆来源。
在你的第二个例子中,你的过程的形式参数 x
和 y
与赋值表达式 [=] 中存在的名称 x
和 y
没有关系16=].
完成第二个示例的常用方法是使用 unapply
命令。
temp := x^2 + y^2;
2 2
temp := x + y
f := unapply(temp, [x,y]);
f := proc (x, y) options operator, arrow; y^2+x^2 end proc
f(1, 2);
5
一种更通用(也是更高级)的方法是用包含匹配名称的表达式替换到模板中。例如,
g := subs(__dummy=temp,
(x,y)->__dummy);
g := proc (x, y) options operator, arrow; y^2+x^2 end proc
g(1, 2);
5