# pattern-matching's questions - English 1answer

858 pattern-matching questions.

### Trouble with UpSet(Delayed) and IgnoringInactive

0 answers, 20 views pattern-matching hold assignment
I'm having problems setting an upvalue for a symbol that is supposed to ignore Inactive:IgnoringInactive[f[g[x]]] ^:= match;...

### 6 Put edges of a matrix to zero

I have to set the first and last rows and columns to zero rows and columns. I tried with the first column: ...

### 1 ProbabilityDistributionQ

I have had a look through the documentation and I cannot find a ProbabilityDistributionQ function. How can I return True if the ...

### Give Mathematica points in the XY plane and find equation that generates them

I am finding the minima of a 2D cubic periodic function by "brute force", i.e. looking for the (x,y) positions where the both the x and y derivatives are 0. This returns a list of points, in this ...

### 1 GeoGraphics added to a current GeoGraphics object

1 answers, 36 views pattern-matching geographics
I need to make a GeoGraphics[] object then save it to disk, move it to another computer where I need to load in the object then add some more ...

### 3 A pattern condition involving OrderedQ

I have the following simple code:z = {a, b, c} {{1, 2, 3}, {1, 3, 2}, {3, 2, 1}} /. {a_Integer, b_Integer, c_Integer} /; OrderedQ[z] -> 1which returns ...

### 2 Totally orderless partition

This is a slight variation of: How to generate all possible orderless partitions of a list according to another list? Consider each set following a partition a "box" and each element a "ball". What ...

### Pattern test and replacement with pure function [closed]

1 answers, 42 views pattern-matching replacement
This is a very simple question. I have an unnamed pattern and a test function should determine whether to perform replacement on it. How to make the following piece of code to work: ...

### 2 Checking if a list of length $n$ has pairs?

3 answers, 100 views list-manipulation pattern-matching
I have a list of reals and I want to check if for every element $i$ there is another element $j$ such that $\lvert{i-j}\rvert \leq x$ where $x$ is some arbitrary value. Each element can only be "...

### 5 Pattern for k distinct elements of a set of n elements

2 answers, 160 views pattern-matching combinatorics
I would like a pattern which takes as an argument a set with $n$ elements, and an integer $k$ which is less than $n$ and greater than 1, and which matches against any $k$ distinct elements of the set, ...

### Problems on MatchQ[-3*i[1], -x_*i[1]]

In my Mathematica 11.3.MatchQ[-3*i[1], -x_*i[1]]returns False. ButMatchQ[-3*i[1], x_*i[1]]returns True. I don't ...

### 2 Pattern for a vector space basis expansion

1 answers, 60 views pattern-matching vector
I'd like a pattern which matches an expansion of a vector in a given basis, so mathematically any expression of the form $\mathbf{v} = \sum_{i = 1}^n v_n \mathbf{a}_n$. The basis is defined by a ...

### 5 Replacement rules for powers of a symbol

5 answers, 324 views pattern-matching replacement
Suppose, I have an expression like so:In[68]:= expr = 2 + 5*q + q^2 + 8 q^3 + 19 q^7 Out[68]= 2 + 5 q + q^2 + 8 q^3 + 19 q^7Now I want to take all powers of q ...

### 7 KeyValuePattern specificity in DownValues

Bug introduced in 10.4.0 and persisting through 11.3.0 CASE:3824590 [...] Developers are discussing this behavior. [...] I will let you know when I have definite information on this. [...] ...

### 2 Match each primitive with relevant directives in GraphicsComplexBox

2 answers, 85 views graphics pattern-matching
I am struggling to write the correct pattern to match all ArrowBox objects with the relevant graphic directives in following snippet ...

### 9 Mathematica rule substitution memory

First I present the specific programming question, and then I provide further background details. Given an expression in Mathematica, say f=3x+7y, there are two ...

### Why does StringReplace wrap StringExpression around result?

The task is to separate a leading separator from subsequent text into a list. Why does StringReplace wrap StringExpression ...

### 6 Counterintuitive DownValue precedence

1 answers, 67 views pattern-matching language-design
Consider the following definitions for two symbols:foo[a] /; True := b foo[a] := a foo[a] (* a *) foo2[a_] /; True := b foo2[a_] := a foo2[a] (* b *)(The ...

### 1 Lists of Numbers

2 answers, 87 views functions pattern-matching
An integer is prime-palindromic if both orientations are prime (i.e. 941 <--> 149) Write a function to test if an integer, n, is prime-palindromic. Which numbers in 1 I took the approach; ...

### How to use Pattern matching to get the right hand side of a rule?

I have a List that looks as follows: ...

### Select Elements from a List which are of the form

3 answers, 44 views functions pattern-matching filtering
I have this problem: Produce a list of those of the first 100 primes which are of the form 8k + 1 for an integer k. So far I know how to create a list of the first 100 Primes, simply using; ...

### Selecting Elements from Lists

0 answers, 24 views functions pattern-matching
A Mersenne prime is a prime number of the form $2^nā1$. Produce a list of those n, which are at most 1,000, for which $2^n ā 1$ is prime I am able to find the list of prime numbers: ...

### How to create a checkerboard pattern?

I would like to write a generalized function to create a checkerboard pattern of any size (width of each square and frequency of repetition). How can I do so? Edit 1 This is what I tried. ...

### 3 Find elements of a list matching specific patterns

1 answers, 55 views list-manipulation pattern-matching
I have defined several symbolic function f[x],g[x,y],h[x,y,z] etc... And I have a list made of elements which are product of these functions with different ...

### Simplifying expression using pattern matching inside Assuming[]

I want to simplify a sum of terms that look like so: ...

### 17 Determine whether some expression contains a given symbol

2 answers, 2.752 views pattern-matching expression-test searching
Given a symbol t and an expression expr, how can I determine whether or not the symbol t ...

### 7 The curious case of missing random-walking particles in the box

Note: I added the entire code I wrote below to generate the initial configuration and have explained step by step what each part of the code does Kindly bear with the code and the explanation. Since ...

### Flat Attribute Best Practice

0 answers, 33 views functions pattern-matching attributes
I would like, as an example, to build a Times-like function. Take the following example ...

### 1 How to find the frequency of a pattern in a list?

Consider a list (list) aslist = {{0, 0, 0, 1, 2}, {1, 1, 0, 1, 1}, {2, 2, 1, 0, 0}, {1, 1, 0, 2, 0}, {0, 0, 1, 0, 1}};...

### 88 What best practices or performance considerations are there for choosing between Cases, Position, Pick and Select?

Cases, Select,Pick and Position each have different ...

### 1 Searching words with the five vowels

after looking for a long time manually words in Spanish that have the five vowels in any order, for example Republicano, murcielago, superiora, etc; I'm bored and without success. I thought that ...

### 11 Can't understand one paragraph in Power Programming with Mathematica

In the chapter 7 of the Power Programming with Mathematica, there is a paragraph discussing the behavior of Set- functions: (page 205. (pdf version p. 224)) ...

### 2 Building a replacement rule from a pattern, Assocation and RuleDelayed [duplicate]

I'm trying to create a function that builds a replacement rule from a given pattern and I have trouble understanding what's going wrong. After having written most of the question, I see that it got ...

### 5 Word Patterns for Cryptography

4 answers, 200 views pattern-matching string-manipulation
I want a function f that takes a word (like those listed in WordList[]) and returns a pattern best described by examples like these: f[ābookā]=abbc; f[āsettingsā]=abccdefa; and f[āmovingā]=abcdef. ...

### Change of variables in a linear differential operator

Suppose I start with a differential operator in two variables x1 and x2 as follows: ...

### 2 Can the pattern “_.” be used in head?

The standard usage of the pattern _. seems usually used in the parameter, for example, f_[a_,n_.]. I wonder if such pattern can ...

### 1 Little question about pattern matching of x_^n_

I'm now practicing pattern matching by implementing a self-defined differentiation operator. ...

### 2 How to apply a transformation rule to integer coefficients without affecting integer exponents?

When working with finite fields, I often want to apply some transformation rules to the integers that appear either as coefficients in expressions. This becomes a problem when the transformation also ...

### 2 Repeated pattern in XMLElement

2 answers, 68 views pattern-matching xml
I have an XML file like this: ...

Writing: ...

### 1 Dot confused with Times in pattern matching [duplicate]

I would like to write some rules that distinguish between the Times and Dot functions, but I get the following behavior, ...

### 8 Problem with DeleteCases

I'm about to report this as a bug but wondered what you would make of it. Works as expected in version 7. ...

### 1 Cases with condition vs Select inside Manipulate

I tried to plot integer points that fall into a 2D region that's dynamically changed. So I resort to Cases and Select, but ...

### 2 duplicating entry values of a list to match varying size of entrys in another list

3 answers, 60 views list-manipulation pattern-matching
let's say I have a list of lists that looks like abc={{1,{{1},{2}}},{2,{{3},{4},{5}}},{3,{{2}}}}//TableForm, where the first entry in every row, the one ...