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

learn more… | top users | synonyms (1)

3
votes
3answers
58 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 ...
9
votes
2answers
215 views

Why can I not replace a Dataset using a rule?

Simple replacement of a Dataset object does not seem to follow the expected behavior... Dataset[{}] /. _Dataset->1 Returns the empty Dataset not 1 as I would ...
0
votes
1answer
59 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 ...
11
votes
3answers
652 views

Specifying string patterns in DeleteCases

It seems that DeleteCases is not compatible with string patterns, at least directly (see, for example, this question). Is this true? If so, why is this the case? ...
0
votes
1answer
28 views

Selecting from a list [duplicate]

OK, I know this must be a simple problem, but right now I'm just stuck and need some advice with this :). I have the following list: ...
0
votes
3answers
62 views

ReplaceRepeated made a single replacement where I expected multiple replacements to be made

This seems like a very simple action: {a, b, c, d, e, f} //. {r___, x_, y___} :> {r, 1, y} but it replaces only the first element giving ...
7
votes
4answers
427 views

Strange answer from StringReplace

I have a list of strings and I would check if there is an empty string element, that's "", because I need to replace it with a "0". I try the following ...
1
vote
1answer
27 views

How do I match all the subscripted terms in Times?

Suppose I have an expression: $W = A_{i,p,q...}\,\, a_ia_ja_ka_l...$, where $A_{i,p,q...}$ is an expression that does not depend on $a$, the indexes $i,j,k,l,p,q...$ are integers and all the integers ...
2
votes
1answer
36 views

How to make patterns Simplify/Expand work in patterns?

I am trying to calculate deriv of a complicated function and store the values for reuse. But the FullSimplify in my definition doesn't seem work all the time: ...
3
votes
1answer
135 views

Why even try the semantic constraints, if expression can't match the pattern structure?

This result is unexpected: Trace[MatchQ[{7}, {_?NumberQ, __}], NumberQ] (* -> {{NumberQ[7], True}} *) Why evaluate ...
3
votes
4answers
185 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. ...
2
votes
2answers
43 views

Extracting numerical coefficients from an expression

I have very large expression and I want to extract and sum up all the numerical coefficients which multiply the summands. For example, expr = x + 2*y + 3*z*w ...
3
votes
3answers
106 views

Change matrix elements at specific locations?

Let's say I have an array a={{1,2,3}, {4,5,6}, {7,8,9}} I want to have all elements along the diagonal multiplied by 2. ...
6
votes
6answers
504 views

Determine if all the zeros in a list occur at the end

I have a collection of (short) lists of nonnegative integers. For each, I would like a predicate that decides if all of the zeros in the list appear at the end. For example, ...
2
votes
2answers
128 views

Can a pattern examine all partitions of a sequence?

Say I have a list: {a, b, c, d}. I'd like to check that the list has some partition, say {{a, b, c}, {d}} such that all the elements of the partition satisfy a ...
0
votes
1answer
47 views

Replace elements that match pattern

I am using pattern matching to identify elements in a list to be replaced. How can I supply a list of patterns to match and replace all elements in the list that match the pattern? The problem I have ...
2
votes
1answer
67 views

Removing characters from non-strings

I have a large list of lists that contains mixed data, some real, some strings. The lists are of various lengths and depths. Some of the real data values have an asterisk appended to them, e.g.: ...
4
votes
1answer
90 views

Compare tree structures in mathematica

Since Mathematica expression is basically a tree structure, I would like to perform tree structure comparison with certain restrictions, for instance that the identity of nodes on the same level be ...
8
votes
2answers
97 views

Pattern matching with Complex. Feature or a bug?

I have run into some strange behavior while doing some pattern matching. First, this works as expected: Exp[2 I u x] /. Exp[Complex[0, a_] u x] :> a (* 2 *) ...
7
votes
3answers
206 views

Why these ways of defining a function with variable number of arguments fail?

First: I know about the correct way to define a function with variable number of arguments: Clear[f] f[s__] := Plus[s] f[1, 2, 3, 4] (* 10 *) BUT I ...
37
votes
2answers
748 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, ...
0
votes
3answers
63 views

How to create a general expression for an integer derivative?

I need MMa to return a general expression for the jth derivative wrt v of v^n. This didn't work: ...
0
votes
1answer
50 views

How to use pattern matching for integral identities?

I have an unknown pdf f[x], and I need to express integrals involving f[x] as expansions of the moments of f[x]. For example: ...
5
votes
5answers
117 views

Isolating cross terms

I have a set of expressions that contains terms like $\frac{1}{(x + a + b)(c+d)}$. I would like to simplify the denominator so that products of $a,b,c,d$ are dropped, but $x c$ and $x d$ are kept. ...
3
votes
1answer
65 views

Output function control and manipulation for efficient computation

I have taken note of a similar post related to modifying function parameters. I tried to adapt Kuba's solution to this post but I can't get it to work. I will illustrate my problem using a similar ...
4
votes
1answer
163 views

How can I construct a recursive pattern guard?

I am modelling binary trees in Wolfram Language by writing them as three-element lists, like so: binTree = {nodeVal, leftChild, rightChild}. It does not yet matter ...
0
votes
2answers
40 views

FilterRules with pattern for name [duplicate]

I have a list of rules and I want to filter it using a pattern for the initial string representing the name of the rule. So that in the example below it filters linearBool even if it is called ...
2
votes
1answer
105 views

Odd behavior matching powers of pi

I have a long list of generated values from which I want to remove "weird" ones like Sin[Sin[1]] and Pi^2/4. However, trying to ...
3
votes
1answer
68 views

Pattern matching multiple symbols names and powers

Seemingly a relatively simple problem, I can't seem to find a solution... I want to build a pattern that will match any symbol whose name starts with V, and is elevated at any power. Something on the ...
18
votes
1answer
514 views

NotebookFind and String Pattern Expressions

Is there a way that NotebookFind can be used to match string pattern expressions rather than just strings? The documentation for ...
10
votes
5answers
520 views

Best way to modify values in a list of rules?

Recently I had to solve a problem similar to this: Let's say I have a list of list of rules ...
4
votes
3answers
174 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 ...
1
vote
1answer
44 views

How to modify the output result of an evaluation

For ease of notation, I have defined a function, $f$, that defines the permutation of Bosonic particles such that it has the following properties (the form of $f$ is irrelavent for this question): ...
4
votes
3answers
67 views

Extracting subscripts and superscripts

Suppose I have several types of expressions (in some random order) of the form Power[Subscript[g, a], μ] which is $g_a{}^\mu$ ...
0
votes
2answers
53 views

Keep exponents separately

I have the following expressions $g^{ab+cd+...}$ or in the full form Power[g,Plus[Times[a,b],Times[c,d],...]] How to convert this expression into ...
10
votes
1answer
329 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 ...
7
votes
5answers
356 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 ...
21
votes
5answers
646 views

How can a big table be treated as a database?

I often work with big tables that I want to treat kind of like a database. Here's an example table. ...
10
votes
2answers
493 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 ...
4
votes
4answers
127 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 ...
4
votes
7answers
404 views

Given a symbolic expression how to find if starts with a minus or not?

I am using a Mathematica function which returns some error term in symbolic form. I needed a way to determine if this term starts with a minus sign or not. There will be only one term. This is to ...
4
votes
4answers
138 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 ...
10
votes
2answers
965 views

Determine whether some expression contains a given symbol

Given a symbol t and an expression expr, how can I determine whether or not the symbol t ...
2
votes
3answers
93 views

Testing for a vector of reals [closed]

Suppose I define: RealVector[expr_]:=VectorQ[expr,NumberQ[#]&&Head[#]===Real)]; Then: ...
1
vote
1answer
69 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 ...
10
votes
0answers
89 views