Tagged Questions

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

125 views

Logical AND of multiple patterns

Mathematica provides an equivalent for "logical OR" when pattern matching, using Alternatives or the infix | operator. For ...
80 views

Matching All Functions [duplicate]

Is there any way to match all functions? There's an existing answer for matching functions of one parameter (_@_) but it doesn't work for trying to test if a symbol ...
86 views

List of all Variables that match an specific pattern

I'd like to make a list of all constants that match an specific pattern, wich includes all terms that multiply an specific variable. For example, I'd like to take all terms that multiply t in: ...
304 views

How can one represent a string pattern with prohibited substrings?

Say I have the following string: "<hello>something WRONG</hello><hello>something else</hello>" I am trying to find code that works like the ...
213 views

Test for non-numeric variables

I have a table, testdata, with numeric and non-numeric data. testData = {{1, 2, 3, no, 5}, {5, 6, 7, 8, 9.1}, {1, y, y, n, n}}; I can locate the positions of ...
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 ...
68 views

Matching products with optional factors with definite heads

I need to match a products with exactly one factor F, an arbitrary number of factors of head A, and possibly additional inert ...
27 views

How to get the VertexWeight list or EdgeCapacity list in a graph

The graph of Mathematica.We have VertexList or EdgeList.So we can get it convenient like ...
85 views

Simplifying expressions

Let's define a function $\Omega(x,y)$ ...
220 views

How to Override the Head of a Symbol

I was wondering if it is possible to override the head of symbols/operators. As a motivating example if I run: Then Ket will be returned. But lets say I want Bob to be returned instead of Ket. Is ...
69 views

Can't access AnyOrder named parameters

Straight from AnyOrder documentation ...
55 views

How to get f[x] to match with f[c_., x] when OneIdentity doesn't match

After setting: SetAttributes[f, OneIdentity] Default[f] = 1; We have the following successful matches: ...
59 views

replace a part of equation by a symbol

I have an equation:  \frac{d\text{$\phi$0}}{dx} \left(-\frac{\text{A1}(x) \frac{d\text{A0}}{dx}}{\text{A0}(x)^2}+\frac{\frac{d\text{A1}}{dx}}{\text{A0}(x)}+\frac{\text{B1}(x) \frac{d\text{B0}}...
196 views

Odd behavior in pattern matching for functional form [duplicate]

Consider the two seemingly closely related operations: ...
1k views

How is pattern specificity decided?

Mathematica has a notion of pattern specificity, which is a partial ordering on patterns. The rules (e.g. DownValues, SubValues,...
51 views

Strange behavior with Inequality and pattern matching

An expression like this one a < x < b is normally represented as Less[a, x, b] while an expression like ...
60 views

Extracting attributes from a function [duplicate]

From an expression describing a mathematical function, I would like to extract its parameters. For example, from the expression 4 Sin[2 a x^2 + b x + c], assuming ...
513 views

MatchQ-ing Associations (MMA 10)

Consider {x->1} which has FullForm List[Rule[x, 1]] and, therefore, ...
104 views

How to use Select according to a list of criteria to produce a list of subsets of another list obeying those criteria [duplicate]

The code Print[Select[{1, 4, 3, 9}, Mod[#, 3] == 0 &]]; Print[Select[{1, 4, 3, 9}, Mod[#, 3] == 1 &]]; Print[Select[{1, 4, 3, 9}, Mod[#, 3] == 2 &]] ...
78 views

Pattern matching using Cases: why does this fail? [closed]

I have objects that look like, for example: F2 = 2 d[x] ^ d[y] + 3 d[x] ^ d[z] where ^ is ...
309 views

60 views

Remove an element of a list [duplicate]

I want to check if any element of a list contains Missing["NotAvailable"] If so I want to delete the entire list. If I am correct I need to have some ...