# Tagged Questions

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

410 views

### How to visualize pattern matching process?

I want a function that does the same job like ReplaceRepeated, and can make the matching process visible. I searched the Internet but didn't find any existing code ...
297 views

### How to search for patterns to find the positions of prime numbers

I have a summation which yields a prime number at each location there is a 2, and I do not know how to search for the 2's. ...
758 views

### Calculating weird numbers

A weird number is a number such that the sum of the proper divisors (divisors including 1 but not itself) of the number is greater than the number, but no subset of these divisors sums to to ...
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 ...
534 views

### Is there a way to identify a symbolic fraction?

Is there a way to use Head to detect a symbolic fraction? In particular I find, Head[a/b] Head[1/5] Times Rational ...
189 views

### Cases with Alternatives failed

Consider this list of rules rules = {a -> 1, b -> 2, c -> 3} I'd like to fish some of the rules out of such a list using ...
329 views

### Counting subsequences (i.e., patterns) within a list?

I would like to count the number of subsequences in list. Say I have data given by: data = {1, 1, 1, 2, 1, 2, 2, 2, 1, 2, 1}; I would like to count the number ...
119 views

### Deleting or replacing inner elements depending on higher level elements

Consider a data structure like: ...
106 views

### Testing for a vector of reals [closed]

Suppose I define: RealVector[expr_]:=VectorQ[expr,NumberQ[#]&&Head[#]===Real)]; Then: ...
71 views

### How to use a list of rules as a data set

I have a file of models that I have saved that I want to be able to call in another program to be solved with NDSolve. Can I use ...
173 views

### Replacement of terms/Pattern matching involving products of derivatives of a function

In delving into Ramanujan summation, I'm trying to get a hold of the relations of the form \sum_{n=0}^\infty f(n)=\dfrac{h\frac{d}{dx}}{{\mathrm{e}^{h\frac{d}{dx}}}-1}\int_{0}^\infty f(x)\,{\mathrm{...
141 views

### Unexpected pattern matching behaviour: PatternSequence vs. Optional

fixed in 10.1 (windows) Consider the following pattern-matching expressions: ...
315 views

### Get the wrong result using the StringCase function and Shortest option

I have a list of strings like this ...
51 views

### “Meta-matching” patterns [duplicate]

The title refers to the general problem of writing patterns to match pattern-containing expressions (hence "meta-match"). Here's an example. In the following rules ...
66 views

### What's the pattern that will match a head anywhere in an expression

I'm looking for the pattern patt[head] that will match any expression expr in which head occurs as a head anywhere within expr. ...
184 views

### Replace expression, but only “outside” of a function [duplicate]

I have a horrid expression, which is basically a sum of exponents with coefficients. Here's a taste: What I want to do is to replace ks with another expression, ...
161 views

### Problem using Position applied on matrix with Infinity elements

Am I doing something wrong here? ...
311 views

### Orderless pattern matching

The MMA docs state that "In matching patterns with Orderless functions, all possible orders of arguments are tried". Why then does the following not work? ...
56 views

### Matching exponents using Cases[]

I have a question regarding pattern matching. Can anyone explain the results i get ? Cases[Table[x^n, {n, 1, 10}], a_^1] Which gives the following result. {x, ...
189 views

### Pattern Matching in Lists

I have a UN voting dataset – taken from a CSV file – where each row is in following format: ...
163 views

### Pattern Match and Replace Expression involving Pure Function

Let's say I have an expression that in held form contains a pointer to a function. expr = Hold[2*{"FUNCTION1"} + 5]; ...
45 views

### Default value behaves differently when used in Function and when used with Cases

Consider this example: Cases[{4, x, 5 a , 6 x}, x_.*a_ :> x] (*{1, 1, 5, 6}*) It is clear that the _. took 1 as a ...
171 views

### LetterCharacter for Cyrillic symbols

Why does the code StringMatchQ["ы", LetterCharacter] return False? Probably because: ...
102 views

### Power[__] Pattern works like Level

I came across this case: ...
58 views

### pattern matching and applying a function, not working as expected [duplicate]

Consider the following code G[x, y] /. a_[b__] -> Total[a @@@ Permutations[List[b]]] I expect it to give G[x, y]+G[y,x] ...
88 views

### How to ensure efficient order of operations for rules, slots, substitutions?

I need to calculate several functionals Q[[t]] of a pdf f[x]. ...
361 views

### What does f_[whoCalled]^:=f really mean?

I came across the following post by John Doty in this Google Groups discussion: On Friday, January 11, 2013 8:23:16 PM UTC-7, amzoti wrote: It is clear the Mathematica uses Lisp as one ...
138 views

### How to use slots and patterns to reduce repetitive calculation?

This is kind of complicated... How can we make MMa calculate values of a function before doing multiple pattern or slot substitutions? Answers to similar questions didn't cover the case where the ...
213 views

### Unexpected result from StringReplace

The following works as expected. StringReplace["xxxyxz", "x" ~~ _ -> "ww"] "wwwwww" And so does this. ...
154 views

### Is this a bug in NCAlgebra library?

In course of my work with NCAlgebra package for Mathematica, http://math.ucsd.edu/~ncalg/ , I encountered unexpected behavior of replacements. I am using ...
61 views

### Pattern matching functions of variables

I am trying work with a general operator z[] and later plug in candidate forms for z[]. But pattern matching turns the inside z[] into a constant and can no longer perform operations on it: ...
386 views

### Mathematica won't plot the a function that is solved from NDSolve

I have used NDSolve to solve for a function (an angle of a triple pendulum), and now I wish to plot the derivative of that function (the angular velocity). ...
181 views

### Finding the index of (x,y) pairs in a list

I have a large list of $(x,y)$ pairs, and I want to find the index of a particular pair in order to extract some data from another array. By way of an example, ...
561 views

### Camel hump string split

Given System names of 2 or more characters: systemNames = Names["System`*"] // Select[StringLength[#] > 1 &] ; Is ...
155 views

### How to define patterns to filter lists of replacement rules?

I have a list of replacement rules like list˘of˘replacement˘rules = {a -> 1, b -> 2, c -> 3} and I want to filter all the elements where ‘b’ is replaced ...
260 views

### Crosscorrelation for nonperiodic signals

I want to detect patterns (of an absorption spectrum which is nonperiodic) with Mathematica automaticly. I have found CorrelationFuncion but as far as I understand, ...
291 views

### String pattern defined by number of characters

I want to extract non-overlapping substrings from strings with only four possible characters a,b,c,d. These strings will always have equally many "a" and "d" characters. The substrings x I want satisy ...
306 views

### Deleting empty cells and selecting cells matching a pattern

Is there any way for me to automatically select all cells that are completely empty? You know, those cells that you create but end up cutting what's in them and paste it somewhere else, so after a ...
45 views

### Linear function on strings using UpValues

I have two functions Sup and Sdown that take a string of letters with allowed characters ...
188 views

### Pattern matching: Times[a_] vs Times[a__]

I don't understand why MatchQ[ HoldComplete[Times[3, 2, 2]], HoldComplete[Times[a_]] ] is returning True. I thought that ...
132 views

### Symbolic and numeric calculations (and plots) simultanuosly [closed]

I use Mathematica to do a bunch of symbolic calculations (integrals, ...). This is good because I found that sometimes, if I plug in numeric values, Mathematica takes much longer. However, sometimes ...
83 views

### How do I tell pattern searcher the order in which to search for patterns given in general form?

I have a really long sequence of Symbols inside a function, say nonCommute[a,b,c,e,e,f,g,b,i,j], and I am implementing a ...
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 ...
465 views

### Command to take the first elements of a list that match a pattern

I want to find the number of elements in a list in a row that match a certain pattern. So for this list {1,1,1,1,0,0,0,1,1,1} It should return "4" because there ...
205 views

### Making a list of rules from the list of elements

Starting from the list: {f[q1, q2], f[q3, q4], g[q1], g[q2, q3, q4], d[k1 - q1], d[k2 - q2 - q3 -q4]} I would like to get the result: ...
99 views

### FreeQ and arguments of Hypergeometric2F1

I was trying to use FreeQ to test for the presence of Hypergeometric2F1 functions in my expressions. I encountered the following ...
103 views

### Understanding the order of applying Rule to expression [closed]

I am a little confused about: In what order is a Rule tried to apply to an expression? In a depth-first order or otherwise? For example, ...
293 views

### Why doesn't this pattern work?

I want the in-built function Count to count the elements in a list which are greater than a value. Example: ...