# Tagged Questions

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

482 views

### Replacement rule only matches part of expression

I have the result of a calculation (which is too long to mention here) and it gives ...
826 views

### Function argument to default under certain condition

Inspired by this and this question (and how I handle this in practice), what is the best way to default a function value when a certain condition is met? For example, if a function is defined as: <...
214 views

### Isolating string characters

I have the following string: ...
217 views

### Using PatternTest and/or Condition to detect equal list lengths as well as list element formats

On searching Mathematica.SE for information about overloading functions, I came across several threads about PatternTest and ...
316 views

### Rule for orderless function Times

I have problems extending a replacement rule. Schematically, this is the situation: I have an expression and a rule, and they work perfectly together. ...
145 views

### Filtering lists by partial matches

Suppose I have the following data: ...
356 views

### Pattern matching - comparing two lists

I would like to compare two different lists to see if the shorter one is a member of the larger e.g. is the list {2,3}, with that sequence of elements, a member of {1,2,3,4,5}? I have tried using ...
278 views

### Converting expressions to “edges” for use in TreePlot, Graph

This question is similar to this: Nested list to graph. How to "flatten" an arbitrary expression, eg expr = a[b[c, d[e][f], g], h] to a list of key-value pairs ...
425 views

### Keep Ordering of Bra Ket When Printing

I would like to keep the ordering of the bra ket-print but right now this doesn't happen. Any Idea? I tried playing with HoldForm but then i could evaluate the expression inside properly ...
99 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 ...
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 ...
339 views

### Sentiment analysis of tweets

I want to use Mathematica for a sentiment analysis on tweet-messages. For that purpose i selected several tweets. Each tweet is interpreted by myself as positive (pos) of negative (neg). For example: ...
284 views

### Extracting sequences from a list?

Suppose I have a list of arbitrary length like {1, 2, 3, "Open", 3, 2, "Close", 9, 3, 4, "Open", 1, 0, "Close", 3, 5} and I am trying to extract the sequences ...
308 views

### Apply Trig Identity to Transform Sum of Sinusoids into Phase-Shifted Cosine Function

I'm trying to solve for the output of a simple RC low-pass filter, with Cos[w t] input. The convolution of the input with the RC transfer function gives me the right output, but I'd like to be able to ...
211 views

### Strange behavior of MemberQ, Position

After importing an array of latitudes and longitudes and trying to find the position of some latitudes I was encountered with an unexpected problem since certain values could not be found for some ...
524 views

### How to test whether an expression is a valid variable?

I would like to test whether an argument is a valid variable for functions like Solve and DSolve. For instance several ...
355 views

### Match a sequence of integers

I would to match a pattern p1 = 0,0,1,0,0 to the elements in listA. The elements are a boolean sequence that may look like this ...
465 views

### Highlighting text with StringReplacePart but also using Style, Subscript

For a Natural Language Processing analysis task it's desirable to highlight a text string programmatically according to XML tags that reference specific words or phrases. The XML tags specify the ...
340 views

### Formatting text through pattern matching

I am trying to format some text based on some patterns. ...
106 views

### StringPattern to remove markers around text

I am not able to figure the StringPattern to use to remove markers in string. This is the input. ...
232 views

### Delete contexts from a string representation of a symbol

I want to delete the string representing the context of a symbol. For info I need such a functionality in my ShowIt function defined here I'd like to know how I ...
103 views

### Why does this recursive pattern guard not work?

I have the following list: ...
193 views

### Removing non-word characters in certain parts of a string

I would like to ask how I can remove non-word characters from a string, but only in certain cases. I have read this article, so I know how to get the words out of a string. My text is however a bit ...
559 views

### Count sublists which match pattern

I have a list which looks like this: data={{12,0},{0,0},{20,1},{0,0}, {0,-1}}. Now I would like to count the number of sublists which: have both slots zero the ...
83 views

### Association matching still not working perfectly?

Up until 10.4 you could not match on internal Association structure at all: http://mathematica.stackexchange.com/a/119542/6804 Now you can, but it seems flawed ...
266 views

### Variable scoping problem when mapping over delayed replacement

This is something that got me curious while I was playing around with Mathematica. Consider the following (contrived) example: ...
104 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 ...
360 views

### Pattern matching in subscripted variables

I am trying to use subscripted variables as symbols and provide assumptions elegantly for them, e.g. in order to simplify logs, I'd like to have ...
69 views

### Can't access AnyOrder named parameters

Straight from AnyOrder documentation ...
114 views

### Error when combining Except, “*” and an additional character

Bug introduced in 5 or earlier and persists through 10.4.1 Anyone knows why ...
302 views

### Pattern definition for replacing plus and subtract

Suppose I have two functions $h_1(x)$ and $h_2(x)$, for which we know their sum and their difference: $$h_1(x)+h_2(x) = d(x) \qquad h_1(x)-h_2(x) = i f(x)$$ I have a complicated expression, in ...
128 views

### Is there an elegant way of delaying evaluation of A==B when calling a function that uses this pattern

Suppose I wanted to define a number of functions that accepts expressions of the form: ...
268 views

### Convert logical relational expression to / from disjunctive and conjunctive forms?

I would like to convert logical relational expressions in disjunctive form, e.g., $$(x \lt -1) \lor (-1 \lt x \lt +1) \lor (x \gt +1)$$ into conjunctive form, e.g., $$(x \ne -1) \land (x \ne +1)$$ ...
1k views

274 views

### How to get complement of a pattern

I have a list. I want to get all the elements in that list which do not match a given pattern. That is, I want the strings which do not match any of the following patterns: First and last characters ...
202 views

### How can I improve NumberString?

I would like to test strings to see if they represent numbers. This should include number representations with precision marks and scientific notation. NumberString ...
240 views

### Finding the position of a single array in a list of arrays that contains wildcard variables

Consider two lists: superList = {{wc,wc,1,wc,wc}, {wc, wc,2, wc, wc}, {wc, wc, 3, wc, wc}, {wc, wc, 4, wc, wc}}; littleList = {a,b,3,c,25}; In ...
241 views

### Pattern matching deletion of list items [duplicate]

Possible Duplicate: How can I remove B -> A from a list if A -> B is in the list? I'm working toward building a graph and use some code to construct my rules which results in a form as ...
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 ...
195 views

### Better output for NonlinearModelFit “ParameterTable”

The Standard table fo parameters of NonlinearModelFit is obtained from NonlinearModelFit[{{0, 1}, {1, 2}, {3, 3}}, a + b*x, {a, b}, x] %["ParameterTable"]] I ...
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 ...