maxima - matchdeclare不会接受第一个参数作为变量

时间:2017-09-14 09:54:06

标签: maxima

考虑以下陈述:

(%i1) matchdeclare([a,b], constantp);
(%o1)                                done
(%i2) defmatch(match, a*x+b);
(%o2)                                match
(%i3) match(2*x+3);
(%o3)                           [b = 3, a = 2]

我想在函数中概括这个模式。但它似乎不再起作用了:

(%i1) matchForm(test, form, constants) := block(
    matchdeclare(constants, constantp),
    defmatch(match, form),
    match(test)
);
(%o1) matchForm(test, form, constants) :=
  block(matchdeclare(constants, constantp), defmatch(match, form), match(test))
(%i2) test: 2*x+3;
(%o2)                               2 x + 3
(%i3) form: a*x+b;
(%o3)                               a x + b
(%i4) constants: [a,b];
(%o4)                               [a, b]
(%i5) matchForm(test, form, constants);
defmatch: evaluation of atomic pattern yields: a x + b
(%o5)                                false

稍微调试一下,似乎问题是matchdeclare并不接受该参数为变量。是否有任何方法可以像我尝试在maxima中制作一个函数?

1 个答案:

答案 0 :(得分:1)

我没试过这个,但是:也许你可以通过

获得你想要的效果
apply (matchdeclare, [constants, 'constantp]),

会在致电constants之前评估matchdeclare