English 中文(简体)
清单中确定相同或类似顺序
原标题:Finding equal or similar sequences in a list

我需要把一个清单变成一个空洞的清单,如果它有两个带有某种财产的非重叠顺序。 例如,在这种情况下,等于并且长度和幅度;= 2)

mm[{___, b1__, ___, b1__, ___}] := {} /; Length[{b1}] >= 2

or, for example 2 sublists, with a similarity function equal 0 and Legth = 4

mm[{___, b1__, ___, b2__, ___}] := {} /;
NeedlemanWunschSimilarity[{b1}, {b2}] == 0 && Length[{b1}] == 4 &&
Length[{b2}] == 4

and so on.....

For mathematica, guru who know internal algorithm, is there a faster way, perhaps using PatternTest (?) ?

问题回答

I await a fuller description of what you are doing, but in the mean time:

mm2[{___, b1 : Repeated[_, {4}], ___, b2 : Repeated[_, {4}], ___}] := {} /; 
  NeedlemanWunschSimilarity[{b1}, {b2}] == 0

这里使用的是rel=“nofollow”Repeated,仅测试正确长度的顺序。

请具体说明最低和最长的序列长度,并注明<代码>[_,{min, max}]。





相关问题
Solving vector equations in Mathematica

I m trying to figure out how to use Mathematica to solve systems of equations where some of the variables and coefficients are vectors. A simple example would be something like where I know A, V, and ...

Introspection of messages generated in Mathematica

Is there any way to get at the actual messages generated during the evaluation of an expression in Mathematica? Say I m numerically solving an ODE and it blows up, like so In[1] := sol = NDSolve[{x [...

Connecting points in Mathematica

I have a collection of points displayed in a graphic: alt text http://img69.imageshack.us/img69/874/plc1k1lrqynuyshgrdegvfy.jpg I d like to know if there is any command that will connect them ...

Mathematica, PDF Curves and Shading

I need to plot a normal distribution and then shade some specific region of it. Right now I m doing this by creating a plot of the distribution and overlaying it with a RegionPlot. This is pretty ...

Targeted Simplify in Mathematica

I generate very long and complex analytic expressions of the general form: (...something not so complex...)(...ditto...)(...ditto...)...lots... When I try to use Simplify, Mathematica grinds to a ...

热门标签