【发布时间】:2014-03-12 10:54:26
【问题描述】:
我只是想写一些类似于Mathematica的partition function的函数,并在maxima as中传递选项,
listpartitionpad(l,n,k,d):= block([temp:[],gap,newl,ntemp:[]],
newl:apply(create_listpad,flatten([n,k,d,l])),
map(lambda([x],if(length(newl)>=x+n-1 and is(unique[x]#[d]))then temp:cons(part(newl,makelist(i,i,x,x+n-1)),temp)
else temp:cons(part(newl,makelist(s,s,x,length(newl))),temp)),makelist(i,i,1,length(newl),k)),
ntemp:sublist(temp,lambda([x],is(length(x)=n))),reverse(ntemp));
Usage:listpartitionpad([a,b,c,d,e,f,g],3,3,x); => [[a,b,c],[d,e,f],[g,x,x]]
正如我检查的那样,现在所有的列表操作函数都是用 lisp 编码的。
我的问题是,我可以用 maxima 语言而不是 lisp 来编写任何这样的函数,或者它会给我一些性能问题,或者我应该知道我还不知道的其他问题。 我做了一个简单的测试
:lisp(time(loop repeat 1000000))
real time : 0.850 secs
run-gbc time : 0.540 secs
child run time : 0.000 secs
gbc time : 0.310 secs
如果是另一种基于最大值的方法,
block([],for i:1 thru 1000000 do []);
评估耗时 5.7700 秒(经过 5.7700 秒)
随着i 的增长,这种差异呈指数增长。
这就是所有列表操作都用 lisp 编码的原因吗?
【问题讨论】:
标签: lisp maxima computer-algebra-systems