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

learn more… | top users | synonyms (1)

3
votes
2answers
83 views

How can I filter a permutation list depending of a pattern? [closed]

I've created a permutation list Grid[Permutations[{a, e, q, r, t, u}], Frame -> All] and only want to see rows where the 5th element is a "t". I tried to do ...
4
votes
2answers
178 views

How do Reap and Sow work in this context

I have a list of points in 3D and I need to count how many times each point is repeated. For a similar problem with a list of characters many different solutions have been proposed in this post: ...
1
vote
1answer
35 views

ReplaceAll - Position of list arguments not displayed properly [closed]

This code A[1, 2, 4, 5] /. A[a___] -> Position[{a}, 4] return {} Why this code not return 3 (a position of number 4) ? I ...
-1
votes
2answers
63 views

What would be a pattern matching only numbers that are not real?

I wanted to delete all complex numbers out of a list, and I tried the following, but it didn't work. Suggestions? Im[x] != 0
2
votes
0answers
57 views

How do I let Fourier Transform know that it is a linear operator? [duplicate]

I have the following issue with FourierTransform, Fourier transform doesn't seem to know it is a linear operator. ...
1
vote
2answers
32 views

“Nonatomic expression” error when identifying certain positions in a list [duplicate]

Please can anyone help ? I have a list of sets, and I am trying to find the positions in that list of those sets which are subsets of a given set. (Here I am ignoring the distinction between lists and ...
2
votes
1answer
57 views

Braces in pattern with Cases function

Here's my problem: I've got a JSON-formatted response and want to match some variables over the response. I'm doing it using Cases: ...
7
votes
2answers
145 views

Good coding for a tricky expansion with convolutions, limits, substitutions

I am attempting to generate a power series in $v$ as $v\rightarrow0$ for $$g(x,v)\equiv \ln\int_{-\infty}^{\infty}e^{-y\left(z\right)}N\left(x-z,v\right)\,\mathrm{d}z $$ where ...
16
votes
3answers
272 views

Is it possible to change the order that symbol definitions are checked? (DownValues vs UpValues)

Suppose I have the function f with the following definition assigned to it: ...
10
votes
1answer
231 views

Question about Rules and Pattern (The operator patt/;test)

Maybe this question is so trivial but it has confused me. I'm studying the What the @#%^&*?! do all those funny signs mean? and in the Rules and patterns under ...
6
votes
3answers
140 views

Filtering lists by partial matches

Suppose I have the following data: ...
15
votes
1answer
210 views

Pattern does not match with Orderless head

Why does the following pattern matching not succeed? ...
5
votes
2answers
78 views

Pattern matching an expression involving Times

I'm trying to write a Mathematica function that will format expressions according to my preferences, for example displaying (5 c x)/Sqrt[2] as ...
8
votes
1answer
137 views

Why does pattern test work only with pure functions?

Why is it that pattern test works only with pure functions? Cases[Range[0, 70], _?(Divisible[#, 7] &)] Cases[Range[0, 70], x_?(Divisible[x, 7])] I ...
5
votes
1answer
68 views

Transformation rules to distinguish common variable with Subscript and OverBar $x,x^2,\bar{x},\bar{x}^2, x_p,x_p^2, \bar{x}_p, \bar{x}^2_p $

I am looking for help in writing transformation rules in which I wish to distinguish between eight variables $x,x^2,\bar{x},\bar{x}^2, x_p,x_p^2, \bar{x}_p,\bar{x}^2_p $. For each of these eight ...
1
vote
3answers
124 views

Making a replacement on the numerator and denominator of a rational number

It's isn't a big deal, but when I run the following I don't get the output I expect. After discussing this in the comments it appears it has to do with being an atomic expression. ...
0
votes
1answer
51 views

Avoiding misconversion of data with ToExpression function [closed]

I've got a list of data with the following structure which can be easily converted To expresion by some manipulation such as ...
0
votes
1answer
101 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
620 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: ...
1
vote
2answers
56 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 ...
9
votes
2answers
234 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: ...
20
votes
1answer
209 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: ...
6
votes
2answers
209 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 ...
1
vote
2answers
67 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
122 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 ...
0
votes
4answers
141 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
1answer
145 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 ...
2
votes
3answers
93 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. ...
0
votes
1answer
35 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
257 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
64 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
149 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
1answer
62 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 ...
2
votes
2answers
76 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: ...
2
votes
3answers
250 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 ...
8
votes
2answers
157 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
119 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
255 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
56 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: ...
7
votes
1answer
128 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
92 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 ...
3
votes
2answers
367 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 ...
22
votes
4answers
311 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 ...
2
votes
2answers
181 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? ...
4
votes
2answers
172 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
1answer
136 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: ...
3
votes
1answer
53 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
134 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
90 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
16 views

Comparing association using MatchQ [duplicate]

For me below query results into False.I expect it to return True. ...