pankajsejwal / pattern-matching Goto Github PK
View Code? Open in Web Editor NEWTo implement Mathematica style pattern matching
To implement Mathematica style pattern matching
pattern-matching ================ To implement Mathematica style pattern matching in Maxima. This work is in its initial stage. What this achieves is seggreagating the list based on "_","__" & "___" patterns exactly as Mathematica. Mathematica's pattern matcher is quite powerful and can do a lot, but this program helps in investigation. Methods: 1) disect : main body of program. 2) propagate : handles "_". 3) propagate2: handles "__". 4) propagate_3: handles "___". The basic idea is that "__" & "___" act as bags and once the data is propagated to one of these, entries before these are never backtracked. Sample Usage examples: disect([_s,_r,___w],[[9,1,2,3,[4,5]]]); => [] disect([_s,_r,__w],[1,2,[3,[4,5]]]); => [[_s,1],[_r,2],[__w,[[3,[4,5]]],[]]] disect([___q,___e,___r,___s,___w,___t],[1,2,3,4,5]); => [[___q,[]],[___e,[]],[___r,[]],[___s,[]],[___w,[]],[___t,[],[1,2,3,4,5]]] dissect([_a,[__a1]],[1,[2,3,[[5]]]]); => [[a,[1]],[a1,[2,3,[[5]]]]] Now that list elements have been separated as per patterns all one needs to do rearrange them as needed, for example, rearrange(dissect([_a,[__a1],_c],[1,[2,3,[[5],7]],4]),[a,a1,c]); => [1,2,3,[[5],7],4] If some pattern doesn't match then it returns the original input list unmanipulated. For operations like, rearrange(dissect([_a,[__a1],_c],[1,[2,3,[[5],7]],4]),[a,a1*c,c^3]); => [1,8,64] This is not what one had expected, but not to worry as Mathematica will also give unpredictable results on sequences. One can expect predictable results only on atoms/lists obtained as pattern matching output. rearrange(dissect([_a,[__a1],_c],[1,[[[5],7]],4]),[a,a1*c,c^3]); => [1,[[20],28],64] Also one can do checks like that in Mathematica,taking a more nested list, eer:dissect([_a,[_a1,_a2,__b,[_e,__f],[_g,_h]],_c],[1,[2,3,4,[[5,6],7,8],[7,8,8,9]],4]); map(lambda([y],if(first(last(y))>=4)then y),sublist(eer,lambda([x],first(x)=c))); => [c,[4]] To be able to do it, APIs related to 'Position' of element in list have been used and can be obtained from another file named 'positions' in GIT. I would request everyone to use it and if one finds bugs, please share it with me. If someone tries and faces any problem, I would be glad to interact with them and sort it out. For detailed explaination: https://www.academia.edu/8315769/Mathematica_style_pattern_matching_without_using_function_closures
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.