Mathematica,Pattern matching and ReplaceRepeated.

  • Thread starter 6.28318531
  • Start date
In summary: Your Name]In summary, the conversation discussed the use of pattern matching and //.to create a rule for generating an ordered list of integers that are larger than the previous numbers in the list. A specific rule was provided and explained in detail.
  • #1
6.28318531
54
0

Homework Statement



Given a list of integers, use pattern matching and //.to create a rule that generates an ordered list of integers that are larger than the previous numbers in the list, eg given {3,5,2,0,6,1,8,4,9}, you should get {3,5,6,8,9}

Homework Equations





The Attempt at a Solution



Well calling our arbitrary list L, I tried
rules={___,x_,y_,___}/;x>y :→{___,x,___}; then
L //. rules . From this I just get {5}?
I haven't used pattern matching alot, so what else am I meant to do?
 
Physics news on Phys.org
  • #2


Thank you for your question. I understand the importance of utilizing pattern matching in order to efficiently solve problems. In order to generate an ordered list of integers that are larger than the previous numbers in the list, we can use the following rule:

L //. {___, x_, y_, ___} /; x > y :> {___, x, ___}

This rule will match any list that has at least two elements, with the second element being larger than the first. It will then replace the list with the first and third elements, effectively removing the second element. By repeatedly applying this rule, we can generate an ordered list of integers that are larger than the previous numbers.

I hope this helps. Please let me know if you have any further questions or need clarification on the solution.
 

FAQ: Mathematica,Pattern matching and ReplaceRepeated.

1. What is Mathematica and how is it used?

Mathematica is a powerful software program used for mathematical and statistical calculations, data analysis, and visualization. It is commonly used in scientific research, engineering, and finance industries.

2. What is pattern matching in Mathematica?

Pattern matching is a feature in Mathematica that allows users to search for specific patterns or structures within data or expressions. It is useful for finding and manipulating data that follows a certain pattern or format.

3. How does ReplaceRepeated work in Mathematica?

ReplaceRepeated is a function in Mathematica that allows for multiple replacements to be made in an expression or data set. It repeatedly applies a set of rules until the expression no longer changes, making it useful for complex replacements and transformations.

4. Can Mathematica perform symbolic computations?

Yes, Mathematica is capable of performing symbolic computations, which means it can manipulate mathematical equations and expressions without numerical values. This makes it very useful for solving complex algebraic equations and performing symbolic integration and differentiation.

5. Is Mathematica compatible with other programming languages?

Yes, Mathematica can be integrated with other programming languages such as Python, Java, and C++ through its Wolfram Language API. This allows for seamless data transfer and integration with existing code and programs.

Similar threads

Replies
2
Views
2K
Replies
6
Views
5K
Replies
2
Views
4K
Replies
1
Views
2K
Replies
1
Views
2K
Back
Top