Questions tagged [rule]

Questions about transformation rules in Mathematica--constructs that let you set, or programmatically modify, local values for expressions.

1
vote
1answer
27 views

Selecting only the terms whose exponents add up to a specific number

Suppose I have the expression from a truncated series: ...
0
votes
0answers
28 views

CoefficientRules for huge expressions

Is there some idea to get the coefficients for a very complicated, huge, and explicit polynomial expression to avoid insufficient memory problem? I am trying to use GroebnerBasis`DistributedTermsList ...
1
vote
3answers
93 views

Pattern with two lists

I have two lists with multiple array elements: ...
2
votes
2answers
46 views

Creating an elementwise replacement rule

I apologise for the simple question, but I've trying to learn to write my code in a more idiomatic way, after having learned Mathematica mostly through trial and error for a long time. Say I have ...
4
votes
1answer
59 views

Inconsistency in getting Keys, Values and Query for nested Rules

Querying nested Rule expressions of the form a -> v -> b // FullForm Rule[a,Rule[v,b]] for ...
1
vote
1answer
34 views

Using rule with derivative

Assuming I have an expression like: D[a[t, r], r] + D[D[a[t, r], r],r] + D[D[a[t, r], t],r] I would like to change variables, by expression everything in terms of ...
4
votes
1answer
101 views

A single argument pattern definition applies to multiple-argument patterns?

Consider defining a pattern rule, such as myFun[x_]:=x As far as I understand Mathematica syntax, this rule means ...
7
votes
2answers
140 views

Replacement Rule for Functions

Attempting to write a rule that will substitute an undetermined function of several variables by some other undeterminate functions (also, of the same several variables). I can do it in an inelegant ...
3
votes
2answers
85 views

Convert a list of lists into a list of rules

I have some trouble converting an imported list looking like this: {{a, b}, {c, d}, {e, f}} into a list of rules looking like this: ...
1
vote
2answers
51 views

Replacement rule for terms that are separated by operators?

My main problem is how one can create a "transcending between operators rule" in the same term according to the minimal example bellow. Suppose I need to perform a replacement of the form ...
1
vote
1answer
97 views

Convert String in Expression to Integer

I have reviewed many string replacement Q&A but I have been unable to apply them to this case (MWE): ...
2
votes
3answers
49 views

Using rule output as function

Im trying to define a function using the output from RSolve, however i cant get it to work properly. I have a RSolve that output something like: ...
1
vote
3answers
75 views

How to make functional rules not depend on an argument?

Consider the following: rule = f[x] -> Sin[x] if I now do, say: f[y] /. rule this does not work, because the rule wants ...
0
votes
0answers
32 views

Imposing conditions on argument for a function definition

Suppose that I wish to use "Piecewise" to merge two different interpolating functions (obtained via a NDSolve of some ODE), defined over negative and positive arguments respectively, like: ...
1
vote
3answers
88 views

Is there a possibility of adding a second condition, or an else clause to $/;$?

Let tally=RandomInteger[{0, 1}, 10]; In the code below, I'm trying to output a list where each component $C_n=\sum^n_{i=1} \text{tally}_i / n$ The problem with my ...
1
vote
1answer
45 views

Rule based list manipulation

I'm trying to restructure the following expression: start = Table[{1, 2, 3, 4}, 5]; Join[{ToString /@ {first, second, third, fourth}},start] Into this: ...
4
votes
1answer
134 views

Delete zeros from a sparse array [duplicate]

Why doesn't SparseArray automatically remove zero entries? The code ...
2
votes
2answers
53 views

Expand a recursion relation

Hermite Polynoms have the following recursion relation: $$ H_{n+1}(x) = 2x H_n(x) - 2n H_{n-1}(x), $$ which can be rearranged to be $$ x H_n(x) = \frac{1}{2} H_{n+1}(x) - n H_{n-1}(x).$$ Is it ...
0
votes
3answers
72 views

Transformation rule for a sum of functions

When applying the rule: exp[c[x] + d[x] + e[x]] //. exp[a_[x] + b_[x]] -> exp[a[x]] + exp[b[x]] I would like to get ...
0
votes
0answers
30 views

Rearrange Summation and change duplicated indices

I try to transform $$\left(\sum _{j=1}^J A(j)\right) \sum _{j=1}^J \sum _{k=1}^K B(j,k)$$ to $$\sum _{j=1}^J \sum _{k=1}^K \sum _{j_{2}=1}^J A(j_{2})B(j,k)$$ The rule would add subscript to ...
0
votes
2answers
71 views

Splits an expression into two parts if possible

The series The series is: $\text{expr}_{1} \pm \text{expr}_{2} ...$ $\pm$ represents plus or minus sign. The number of terms in the series can be 1 or more than 1. Each term $\text{expr}_{n}$ is an ...
0
votes
0answers
38 views

Defining a function that transforms an expression with rules

Question I try to define a function that apply a set of rules to an expression in Mathematica 11.3. However, the function returns a result that is not the same as directly applying the rule to the ...
1
vote
1answer
60 views

Simplify rules with variable number of arguments

Problem How to simplify the following rules? The rules simplify (single, double, triple ...) summations of Kronecker delta. Replacement should occur if any summation and the Kronecker delta share an ...
1
vote
1answer
50 views

Make Mathematica apply the same rule exhaustively in simplification

Use Case Mathematica evaluate the partial derivative as: $$\frac{\partial}{\partial A_{abc}}\sum _{j=1}^J \sum _{k=1}^K \log \left(\sum _{l=1}^L A_{jkl} B_{jkl}\right) = \sum _{j=1}^J \sum _{k=1}^K \...
2
votes
1answer
89 views

Generating Manipulate variables from a list of rules

I have the following list of rules: ...
5
votes
1answer
38 views

Overriding TwoWayRule for in-place element swapping

I'd like to make \[TwoWayRule] work for things other than graph edges, for example, for swapping i.e. Replace, ReplaceAll, StringReplace, etc: ...
2
votes
2answers
175 views

Wrestling with substitution rules

Summary I am struggling with substitution rules. Example Here are several cases which are problematic: ...
6
votes
2answers
121 views

How to use ReplaceAll and RuleDelayed with an Association? [duplicate]

I expected that something like this ...
3
votes
2answers
46 views

Using elements of a list as SparseArray patterns: “can't be used as part specification”

I don't have much experience with SparseArray, and the search here did not give me an answer to this. I'm trying to numerically compute a certain spectrum, and the ...
6
votes
2answers
143 views

How can I get new random values with each blank in ReplaceAll?

Is there any way to get different values for different blanks with ReplaceAll[]? For example, I would like to do something like: ...
2
votes
1answer
50 views

Why ContourPlot shows nothing when use “ReplaceAll”? [closed]

When I use ReplaceAll in ContourPlot, it shows me nothing: ...
1
vote
1answer
68 views

Symbol Level pattern matching and rule replacement

I want to parse a Mathematica Notebook to get some information regarding the relative use of symbols. So first things first: ...
4
votes
3answers
175 views

Keep only rules that replace integers with other integers

Let's say I have a list of replacement rules: List1 = {2 -> 3, b -> 5.5, 6.57 -> 2, 3 -> 4.5, 1 -> -1, 0.03 -> 0.5, 9 -> a} The desired ...
5
votes
4answers
208 views

Create rule whose LHS is already defined

My question will be clearest if defined using an example. Consider the following code: Func[k_]:=Block[{a}, a[t_]:=t^k; {a[t]->a[t]} ]; However, calling ...
2
votes
1answer
38 views

List all subscripts in an expression

Say we have the following expression: $r_{1,3} r_{1,2}^3 m^2-r_{1}r_{4,2,1}$ (Sorry I had to use TeX, read as Mathematica input notation) I need a function that lists all the subscripts of $r$. ...
1
vote
1answer
42 views

a problem of substitution with a rule

I would to make this substitution with 2 rules. Nothing is happening. ...
0
votes
1answer
84 views

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

I have a List that looks as follows: ...
11
votes
2answers
1k views

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
votes
1answer
72 views

Errors while using replacement rules

I am trying to evaluate the sum below by using replacement rule but it doesn't work. I got some errors saying "...is neither a list of replacement rules nor a valid dispatch table, and so cannot be ...
1
vote
1answer
27 views

Manipulating the value of the rules

I have a fitted model given in the code below and I am trying to shift the function to get its maxima in the center ($t=0$). The variable center[i] controls the ...
2
votes
1answer
173 views

Apply replacement rules to all levels

I know this question has been asked multiple times before but unfortunately it seems like I'm too dumb to understand what is really going on and how to solve this. Anyway, I want to resubstitute ...
1
vote
1answer
47 views

ReplaceAll an Expand repeatedly

Is it posible to apply ReplaceAll and Expand repeatedly such as? ...
3
votes
1answer
138 views

Converting Rules to a row matrix [closed]

How can I convert a list of rules {a -> 1, b-> 2, c-> 3, d-> 4} to a row matrix by removing the keys like ...
7
votes
4answers
329 views

Joining all the keys of a list of rules that point to matching values

Suppose I have a list of rules whose keys are not of identical structure (in my case, the keys are either lists of at least one symbol or symbols alone): ...
0
votes
1answer
52 views

Looking for deeper information about a mathematical transformation

I am trying to confirm a transformation given by Mathemmatica. The starting equation is: I take the limit of this equation as N goes to inifinty. I use the Trace[] function to see how the ...
1
vote
0answers
43 views

Coverting a list of products to a list of strings

I am trying to find a way of converting a product of variables to a string, eg. if I have abc... I wish to obtain "abc...". I ...
0
votes
0answers
64 views

Evaluate an expression through a list of rule

I have this iterative expression A = (1/(2*1))*Sum[ (u[i, j, 3])^2 + (u[i, j, 4])^2, {i, 1, ndof1}, {j, 1, ndof2}] That I would like to evaluate using a list of ...
0
votes
1answer
54 views

Converting indices to expression and back

lets say I want to convert this Subscript[PSternMat, 2, 13] into this PSternMat$2$13 I have written this rule ...
4
votes
1answer
120 views

A simple implementation of higher-spin calculus (explanation given)?

I'm a physicist studying higher-spin theory. In my research, we work with fully symmetric tensors using a notation which is implicit both in the dimension of space and the order of the tensor, i.e. an ...
1
vote
1answer
26 views

How to get the limit of a rule [duplicate]

When using the FindRoot function on a certain function, the returned object is a rule. Specifically, the outcome is ...