Questions on expression testing and manipulation through pattern matching and constructing efficient patterns.

learn more… | top users | synonyms (1)

0
votes
1answer
46 views

Avoiding misconversion of data with ToExpression function [on hold]

I've got a list of data with the following structure which can be easily converted To expresion by some manipulation such as ...
13
votes
6answers
327 views

How can I mix the behaviors of StringReplace and ReplaceAll in a single rule?

I'm trying to take a list of the form { {"65 + 3 months", 75}, {"65 + 4 months", 75.1} }, and transform the string part to a number such as 65.25 or 65.333, ...
0
votes
1answer
44 views

Specifying string patterns in a plain text

I need to extract three data, like that: (1.05, 1.37,A) from an imported list of plain texts: "... Syntax of parallax is : 'value quality [error] bibcode' value : parallax value quality : flag ...
14
votes
2answers
475 views

How to detect loops in a vector field?

Given a vector field and I'd like to detect if there are streamlines in closed patterns. For example, if the input is a vector field like this: ...
9
votes
2answers
215 views

Pattern and Orderless function

I'm a Mathematica beginner. I am exploring the use of patterns and (only for fun) am trying to implement a permutations function. My (dirty) code is: ...
1
vote
2answers
46 views

Substituting a list of values into a function [closed]

g[p_] := Mod[19^(-1 + p), p^2] This is my function, and the set of values I have is the first 999 prime numbers. I made a table listing the first 999 prime ...
-2
votes
0answers
25 views

“Extract” certain elements of a list of “rules”? [duplicate]

I have the following list: {u1[0] -> 3773.62, u2[0] -> 3773.62, u3[0] -> 48.7871} I need to extract the elements on the right hand side of each rule ...
5
votes
2answers
182 views

ReplaceAll problem

Bug introduced in 10.1 and persisting through 10.2 or later Confirmed, as bug, by WRI: [CASE:3402234] I am trying to combine terms of the type ...
19
votes
1answer
191 views

Strange behavior with Cases and Position with SetDelayed

I feel like I must be missing something simple and obvious here, but this has me scratching my head. This works as expected: ...
1
vote
2answers
62 views

Patterns with inactive integrals

I am trying to do algebra on unsolved integrals but not getting the pattern-matching right. I want the correlation of f[x] and f[x]+a*d[x], normalized by their self correlations. ...
5
votes
3answers
99 views

Matching Symbol or Subscript, but not Symbol arguments of Subscript

I'm trying to get a list of all the variables in a symbolic expression. Some are named with Symbols, some are named with ...
13
votes
5answers
728 views

Calling Table with custom iterator

I often find myself in situations where I, for example, need to build a table for some expression, but want to set the number of points rather then the step size, so the code ends up looking like this ...
0
votes
4answers
79 views

Cases vs Select, Pattern vs Pure function [duplicate]

What is the difference between having Cases with selection condition presented by pattern and a with pure function as condition? ...
2
votes
3answers
87 views

How to compare and remove x-coordinates (and the associated y-coordinates) that are less than previous x-coordinates?

I am using Mathematica version 9.0 and am trying to compare and remove x-coordinates, and the associated y-coordinate, that are less than previous x-coordinates. Below is an example using sample data. ...
8
votes
1answer
300 views

Mma10 mystery: Failure of pure function substitution with Interpretation?

Bug introduced in 10.0.0 and fixed in 10.0.1 I had code to display with subscripts from Displaying index as subscript on output: e.g. C[i] -> C_i with Notation[...] or Interpretation[..]? which ...
1
vote
0answers
55 views

Find d'Alembertian in the output and convert into Einstein summation convention form [closed]

How can I identify the d'Alembertian in this expression: $ -\frac{1}{c^2}V^{(1,0,0,0)}[t,x,y,z] + V^{(0,1,0,0)}[t,x,y,z]+V^{(0,0,1,0)}[t,x,y,z]+V^{(0,0,0,1)}[t,x,y,z]$ and convert it into the ...
2
votes
1answer
135 views

Select largest number using pattern

I have the following expression: myExpr=R[C[2],B].(II+R[C[3],C[2]].(II+R[C[4],C[3]])) I need to create a pattern which would replace the ...
48
votes
9answers
2k views

Injecting a sequence of expressions into a held expression

Consider the following toy example: Hold[{1, 2, x}] /. x -> Sequence[3, 4] It will give Hold[{1, 2, Sequence[3, 4]}] ...
0
votes
1answer
30 views

How to pick max/mins of elements that match patterns?

I have a list of complicated expressions that involve indexed coefficients. For example: expr={m[5],c[3]*m[1]^2+m[2],Sqrt[m[2]+3*m[3]*c[8],foo[m[3]*m[5]]}; How ...
4
votes
4answers
245 views

Replace matrix rows conditionally while avoiding For loop

I have the following variables: myMatrix={{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}} myIndices={1,3} I need to replace the rows ...
2
votes
1answer
51 views

Confusion over blank sequence in pattern matching

My overall goal was to produce a list of heads used in a graphics output. For an example I used: ...
3
votes
3answers
139 views

Find position avoiding For loop

I have a list: {a,b,c,d,e,f} And a function sizeFunc[element_] which returns the size ...
2
votes
3answers
239 views

Help with PatternSequence

I have a list of strings of the form list = {str1, str2, strx, str3, .., str10} each string contains both letters and numbers, except for ...
2
votes
1answer
56 views

Dropping rational coefficients

I have a list of expressions (they all are exact numeric quantities, not containing any variables), some of them have integer or rationals coefficients, or complex coefficients with rational or ...
6
votes
5answers
573 views

How can I name patterns in a Switch expression?

Suppose I have an expression and want to match it against successive patterns and return an expression corresponding to the first pattern that matched. In that case, I can use ...
2
votes
2answers
70 views

Trouble simplifying using Replace

I have the following expression: w.a.b.r+w.c.d.r I want to get: w.(a.b+c.d).r So far I used ReplaceRepeated: ...
8
votes
2answers
140 views

An equivalent to Condition that I can use anonymously when string pattern matching

When I name a pattern I'm working with, that name stands for the same particular expression wherever it shows up. That's a basic precept of how the Wolfram Language's pattern-matching works. But if I ...
0
votes
1answer
70 views

Match a variable name pattern [duplicate]

I have a list of variables: {RBI,RCD,ASD,FGH} I want to select only those whose name starts with R. Using the pattern Rx_ ...
3
votes
3answers
201 views

How to identify all rules that match pattern type? [duplicate]

I would like to be extend the below solution to be able to find get all rules from the list step[2] that match the generic pattern k_Digit_p. Where k and p are not ...
1
vote
1answer
48 views

How to use EvenQ[] in patterns? [duplicate]

This works: (w[1] + w[2] + w[3]) /. w[s_] -> If[s == 2, w[s], 0] (* w[2] *) This doesn't: ...
6
votes
1answer
101 views

How to Negate a Pattern Test and Transform a List of Strings to a JSON array

First I would like to find out how to negate a pattern and based on this I would like to solve this little problem on how to transform a list of strings to a JSON array. This is how I started working ...
-1
votes
2answers
69 views

Delete Element within a List based on the Order [closed]

I want to do the following, deleting the element of a list that do not match an increasing order as example: {1,2,3,4,6,5,7,8}->{1,2,3,4,6,7,8} I've thought of using DeleteCases but I'm not able to ...
19
votes
3answers
265 views

Is there a GraphicsPrimitiveQ (or a complete list of Heads of graphics primitives)?

For various reasons related to workflow associated with creating figures for journals, I am creating functions that will accept graphics primitives and a set of options and spit out a ...
19
votes
2answers
717 views

How to inject an evaluated expression into a held expression? [duplicate]

I know that there are methods to structurally manipulate held expressions (discussed e.g. here), but I failed to apply those for this particular problem: ...
2
votes
2answers
340 views

Opposite of Alternatives

I was looking at this question (here) and I tried to find any thing gives the opposite of Alternatives. In other words, some pattern matching function that gives ...
11
votes
1answer
293 views

Empty Blank regression in v10.1

Bug introduced in 10.1 and fixed in 10.2.0 In v10.1.0.0 on Linux, when Blank[] is used in Alternatives with pattern that can ...
4
votes
2answers
162 views

Is there any way to use head of Real and Integer altogether?

Is there any way to use the head of Integer and Real together like below? The below is not right, I know that, it is just for ...
2
votes
2answers
153 views

How to make a function that yields a number under power operator by using pattern matching?

Can I ask you a question related to function and pattern? I would like to make the function below work which doesn't yield return values I expect. How can it be done? ...
2
votes
1answer
110 views

Why is there a difference when formulating patterns for Select and FirstPosition?

Select[{1, 2, 4, 7, 6, 2}, # > 2 &] Gives {4, 7, 6}. OK! So one should think that the following would work: ...
8
votes
2answers
291 views

Unexpected behavior of rule matching a pattern

I am a beginner exploring the world of Mathematica. I expected the following code T[6, 5, 4, 1, 2, 3] /. {T[a___, 1, b___] -> Length[List[b]]} should return ...
3
votes
1answer
49 views

Remove cases where region specified incorrrectly

I am using MeshPrimitives to get a list of 3D components of a Mesh Region. Within that list, I normally get some incorrectly specified regions, such as ...
7
votes
1answer
120 views

How to debug this failing pattern-matching expression?

NB: this question is primarily about troubleshooting and debugging, and only secondarily about pattern-matching. IOW, I'm far less interested in getting an explanation for the situation described ...
9
votes
0answers
85 views

Strange result of DeleteCases in an association

The function DeleteCases can be used for associations, also with level specification. Here is an example where some values are associations: ...
0
votes
0answers
13 views

Comparing association using MatchQ [duplicate]

For me below query results into False.I expect it to return True. ...
6
votes
3answers
340 views

String matching balanced pairs of braces

I am trying to extract from a string in Mathematica all instances of \newcommand{ABC}{DEF} Where ABC and ...
16
votes
4answers
751 views

How to define a recursive pattern?

I want to translate this recursive syntactic definition into a Mathematica pattern1: $$ \mathtt{x}: \begin{cases} \text{Null}\\ \{\textit{integer}, \mathtt{x}\} \end{cases} $$ In other ...
7
votes
2answers
225 views

How can I construct a recursive pattern guard?

I am modelling binary trees in Wolfram Language by writing them as three-element lists, like so: binTree = {nodeVal, leftChild, rightChild}. It does not yet matter ...
4
votes
0answers
82 views
4
votes
6answers
2k views

Removing zero values from ordered pairs

I have some processed data, which are basically a collection of ordered pairs in the form: {{x1, y1}, {x2, y2}, ..., {xn, yn}} Ordered pairs which have either a ...