I want the function do the same job like ReplaceRepeatedReplaceRepeated,and and can make the symbol become visiblenessmatching process visible. I search
I searched the Internet and don'tdidn't find any package.So So I writewrote one...
So I can test some example in ReplaceRepeatedReplaceRepeated
exampleExample 1:
exampleExample 2:
exampleExample 3:
But some exampleHowever, it fails in some cases,for for example:
So I want to know how to improve my Program? IfmyReplaceRepeated?
Is there is areally no existing tool can make Pattern Matching becomefor the visualization of pattern matching?
I willLet me explain my function more carefully and I want to use thiswith the following example.
First,define two things,one is the expr and the other is rule
lis = {1, 3, 1, 4, 1, 3, 4, 2, 7, 1, 8}; rule = {Longest[a___], b_, c__, b_, d___} -> {b, b, a, c, d}; mat(*means*short for match*) = rule[[1]]rule[[1]];
{Longest[a___], b_, c__, b_, d___}
And then, I want to know the ahow those variables i.e. a,bb,cc and dd in "mat" how to representrule match the sub-listsequence in "lis"? butlis when lis //. rule executes.
To monitor how many varibles in rule? Sothose variables match, I must find these variables...need to first know what variables rule contain:
OkThen I find out how these variables match lis respectively,Next~ This for example the following piece of code means "a" representshows {1,3,1,4}a matches 1, 3, 1, 4 in lislis.
But remember,theNotice the level is {0}{0},otherwise otherwise we getsget {}{}
Ok,combine theseThese are combined in a loop.
theThe output means "a" represent {1,3,1,4},"b" representa represents {1}{1, 3, 1, 4},"c" representb represents {3,4,2{1},7} c represents {3, 4, 2, 7},the the next "b" meansb represents the forthlatter {1}{1} and the "d" represent {8}d represents {8} in "lis"lis.
Ok,CombineThen I define a testQ to combine all these together and use pure function to illustrate testQ:
Ok.ReplaceRepeated function can be overwriten by FixedPointList.The processThe functionality of FixedPointList can bring a side effect thatReplaceRepeated is always search the a,b,c,d represent what sub-list..achieved by FixedPointList:
FinallyThis is almost the output of example 1,we get except for the similar resultcoloring.
The variables isn'tYou may noticed that the {}. So ifvariables in the above code can't be rule is{}, so a rule like
This is otherwill cause problem.So So I defineadd a IfIf function in myReplaceRepeatedmyReplaceRepeated.And using FixedPointList
So long my code gets the ability to simulatehandle ReplaceRepeatedexample 1 ~ 3.
But, but if the lislis and rule isrule are:
But theMy program don't fit this problemfails,so how to fix it?