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

learn more… | top users | synonyms (1)

1
vote
3answers
248 views

Command like “find” in Matlab [closed]

Is there a command working exactly like Matlab's find? I know that Pick might work, but I just want to give a logic condition ...
10
votes
1answer
168 views

How to write this pattern in Pick function

Suppose I have a list called mask composed of 1,2,3,...n. n is different in different situation. Let me takes n=3 for demonstration ...
5
votes
2answers
78 views

Why does this pattern fail to match?

I'd like to replace fractions with Missing[] as the denominator with Missing[]. This pattern in ...
3
votes
3answers
54 views

How to use pattern matching to apply a function to specific elements of a matrix

I have a 3x3 matrix testweightedgraph = {{{}, {p, q, pq, pq}, {}}, {{p, q, pq, pq}, {q}, {}}, {{}, {}, {}}}; whose elements are (possibly empty) lists. I would ...
1
vote
1answer
103 views

How to write or extend operators like $*\!\!*$

I'm stuck on trying to define simplification rules for NonCommutativeMultiply, much like ExpandNCM found in Documentation Center, under Applications. For example, I'd like ...
1
vote
0answers
71 views

Unexpected result when trying to match against the arguments of Times

Consider the following question: ...
3
votes
1answer
126 views

Using Select with Alternatives

I want to select the elements of a list like: ...
2
votes
1answer
172 views

Given an expression using kets, such as '|2> + 4|3>+…,' find the largest ket index in a ket?

I have some expressions containing Kets, like |1> + Sqrt[6] |3> where the kets are created using [esc]ket[esc]. How can I find the largest number inside a ...
2
votes
2answers
90 views

Strange failure of Series and Derivative

I just spend three hours and posted two Questions trying to figure something out, and it turned out all the confusion was caused by this mysterious quirk. I want to expand g[x,v] in v at v=0, using ...
1
vote
1answer
67 views

How to bound a recursive Derivative definition?

I need to convert derivatives of g[x,v] wrt v into derivatives wrt x using this relation: $$\frac{dg[x,v]}{dv}=\frac{1}{2}\frac{d^{2}g}{dx^{2}}+\frac{1}{2}\left(\frac{dg}{dx}\right)^{2}$$ This code ...
1
vote
1answer
66 views

How to use PadeApproximant with a defined Derivative?

I need to generate a Pade approximant expansion in v of the following: $$g(x,v)\equiv \ln\int_{-\infty}^{\infty}e^{-y\left(z\right)}N\left(x-z,v\right)\,\mathrm{d}...
6
votes
1answer
102 views

Find subsequence A in sequence B A007908 - OEIS

I have sequence A as A007908 - OEIS and pattern B which is a sub-sequence of that sequence A. I need to find index of first occurrence of the given pattern. For example pattern ..1010... I've looked ...
1
vote
1answer
80 views

Can I map a function over a sequence of arguments without making the arguments into a list first?

I would like to set evenFunction[f_][a_, b_, c_, ...] = f[Abs[a], Abs[b], Abs[c], ...] I have come up with two ways to do this so far. Use pure functions <...
3
votes
2answers
192 views

Consecutive identical integer members of a list

Can you help me to find and count sub-sequences of consecutive, identical integer members of a long list (at least 1000 members)? By sub-sequences I mean runs like ...
9
votes
3answers
213 views

How to make a ReplaceAll Rule for adjacent items in a list?

I would like to make only one pass of a list of 2D items and replace adjacent items that have matching $x$ or $y$ coordinates with a series of linearly interpolated points between the two points. My ...
15
votes
3answers
429 views

Highlighting pattern strings in a large text

I would like to apply Style to strings that are matched, for example, with one or more specified patterns or regular expressions, a string or a list of both, ...
3
votes
2answers
94 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
251 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
36 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
68 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
59 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
40 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
58 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
150 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 $y(x)\equiv\sum_{i=1}...
16
votes
3answers
287 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
240 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
145 views

Filtering lists by partial matches

Suppose I have the following data: ...
19
votes
2answers
322 views

Pattern does not match with Orderless head

Why does the following pattern matching not succeed? ...
6
votes
2answers
98 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
162 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
76 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
157 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
53 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 ...
3
votes
1answer
126 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 of ...
14
votes
2answers
687 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
64 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
239 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: ...
21
votes
1answer
222 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
212 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
76 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
131 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
208 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
147 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
98 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
261 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
71 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
158 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
66 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
78 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: ...