# Questions tagged [rule]

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

295 questions
Filter by
Sorted by
Tagged with
87 views

### Mathematica is messing around with absolute values and sqrts of complex numbers?

I know that $$\begin{pmatrix}0&Z\\Z^*&0\end{pmatrix} \quad\text{has eigenvalues}\quad \lambda_\pm=\pm|Z|$$ but Mathematica gives me ...
• 385
384 views

### Smart way to remove rules from lists, leaving just values, specifically from FindMinimum output

I would like to know if there is a direct way to remove the rules from a list of rules. I know that, simply, this can be done with: ...
161 views

### How to change list of rules with the new list?

everyone! I have the "big" list of rules ...
396 views

### How can I change the expression x1 to x[1] in a simple way?

I have one expression, exp0=x1+x9/8+ x4 x5 I want to get exp1=x[1]+x[9]/8+x[4] x[5] Is there a very simple way to do that?
• 1,217
34 views

### Define a new rule to take precedence over the others in a symbol's Downvalues list [duplicate]

I have a symbol that has a very large list of Downvalues. One of the rules in this list should be applied before the others because it simplifies many expressions, ...
• 1,448
425 views

### Evaluating expressions by applying corresponding rules stored in another list

I have a list of expressions: {x,x^2,x^3} and a list of rules {x->1,x->2,x->3} How can I get ...
48 views

### Algebraic substitutions in order

I have some symbols xp[m,n] that satisfy recursion relations, rule1, rule2, rule3. I would like to use the relations to reduce ...
• 1,448
1 vote
35 views

### Rules for internal functions

I'm at my string rewrite systems again. I always implemented these as rules on function arguments. For example, assume a rule is you can drop all arguments 0: ...
120 views

### I understand mol but meet difficulty in understanding how pdetoode atumatically generate pde-to-ode-rules by using this strange pattern and rule?

I often solve pdes for my research, and years ago I found pdetoode in this forum is very handy. Although it is a small piece of code, it solves several interesting ...
• 969
74 views

### How to select only one solution from infinite list

Using NSolveValues on certain equations returns lists of solutions of the following kind: For each of these rules I want to select only one value, namely the one absolutely closest to $2\pi/10$, but ...
47 views

### Exclude terms in replacement rules application [closed]

Suppose I consider a polynomial of type A=B x y + C x and define a replacement rule rrule=(# /. x y -> 1) &; The result ...
41 views

### Substituting a two term expression with two rule on one variable with which each of the rules simplify one of the terms

I have two expressions as follows: r (Sin[t]+Cos[t]) and the rules for simplification are: {x == b + x Cos[t], y == r Sin[t]} ...
• 340
48 views

### Partial sum of Legendre polynomials and numerical error

I am trying to compute the partial sums of the Legendre polynomials: $\sum_{l \geq 0} P_l(cos \gamma)$ of the first kind. The full sum are known to converge and I wanted to check that the error goes ...
• 951
42 views

### Setting rules for Gamma functions

I have some expressions involving lots of Gamma functions. Now the arguments of the functions sometime go to zero, in which case I want to use the factorial instead of the Gamma function (since it ...
150 views

### Replace terms without symbolic term

I have a variety of terms that have coefficients of what I'll call $c_x$ and terms that are without this coefficient. I have a variable $U$, and would like to substitute powers of $U^2 \to d$ but only ...
• 635
37 views

### Removing conditions on patterns from LHS of a rule

Let's consider a rule which takes conditions on the patterns specified on the LHS: In[1]:= rule = j[n1_?NonPositive,n2_?Positive,n3_?Positive]:>AAA I would like ...
• 471
139 views

### Extract all Rules from Plot function

Let's say I would like to know all the Rules that apply to PlotTheme->"Detailed". I tried ...
• 821
89 views

### Making a rule that only applies when the expression is NOT an argument?

I know we can make rules of the kind: magic/:f_[x___,magic[a_],y___]:=f[x,arg[a],y] This will replace magic[a] by ...
• 862
1 vote
67 views

### I use the rule, but it cannot work, So I want to know why it can't? [closed]

I make a approximate solution of the differential equations. But when I use the rule for one, and it can work. But when using a list of rules, It cannot. I mean "(Sum[ep^k*Subscript[y, k], {k, 0,...
1 vote
69 views

### Tracing my rules

As said in another question, I apply a set of rules to a string (OK, technically written as a function F of several arguments so I can easily apply rules on the fly)...
1 vote
56 views

### Rule Precedence

Do I understand the following correct ($R$ on-the-fly executable rules, $E$ expressions)? I assume MATHEMATICA uses an unification algorithm like I learnt it for e.g. PROLOG. If $R_1$ was defined ...
1 vote
30 views

### Error using list of discrete variables with WhenEvent

I came across an error when using a list of Discrete Variables with NDSolve and WhenEvent. As you can see in the minimal example, where I defined the 'testevent', when I use ...
• 115
74 views

### How to do context-sensitive matching with the pattern system?

In Perl RegEx, we have the look-ahead/behind feature; it there a similar functionality available for Wolfram Language patterns? Re @mikado: Suppose we have a random expression in ...
• 648
1 vote
92 views

### Listmanipulation with DateObject

I work with a list containing DateObjects. I want to transform the dateobject to a "Month". The list contains 6 parts. Fot simplicity, the list looks like: ...
• 2,371
79 views

### Applying transformation rule for corresponding indices?

I have two lists, that looks like below list1 = {a, x, b, x, x, c}; list2 = {2, 3, 4, 5, 6, 7}; Any time there is an x in the ...
• 707
1 vote
98 views

### Use replace in rule

I would like to define two rules: one for the material and thickness the second one for volume and mass ...
• 168
23 views

### Manipulate and Rules inside Expressions

I'm not grokking the use of Manipulate when an expression contains Rules. This example works and throws no errors - ...
79 views

### How to convert decimals to integers and joint them to a string for exporting

There's a list such as {0.1,2,0.15,5}. I want to know how to convert the decimal to integer( but begin with zero 0), and don't ...
• 663
1 vote
48 views

### Applying replacement rules to products doesn't work as expected

I have the following issue: I'd like to apply some replacement rules, for example rules:={f[x]/t :> ff[x], g[x]/t :> gg[x]} to an expression, e.g. like this: ...
105 views

...
• 155
1 vote
30 views

### Replacement rule from list to powers

I would like to write a replacement rule that gives all the possible products of traces for a given length. For example, all the possible partitions of length 3 can ...
• 641
1 vote
53 views

### ReplaceAll works and does not work for the same expression

I will give two cases, where the rule replacement works in the first one and does not work in the second one, but they are essentially the same! Consider the following definition, whose details are ...
• 909
1 vote
37 views

### How can I use Table in a replacement rule? [closed]

I would like to implement the following replacement rule: $$tr[a^k]^\ell \longrightarrow t[\underbrace{k,k,...,k}_{\ell\ \text{times}}]\,. \tag{1}$$ My (naive) attempt was to write: ...
• 641
108 views

### Comparison of Coefficients involving complex exponentials

I'm trying to solve a couple (independently) of equations of the following type $a_0 x + 3 a_1 y(1 + xe^{i3q} + e^{-iq + 2ip}) + ... = 0, \forall x, y, q, p$. Using SolveAlways doesn't work well. So ...
• 133
98 views

Given ...
• 9,128
55 views

### Analytically express chi-square sum and solve

I have an expression: chisq[f_, x_, y_, e_, pars__] := Sum[((y[k] - f@@Join[{x[k]},pars])/e[k])^2, {k,1,n}] which should work for any function that has ...
• 153
173 views

### Function incorrectly renaming variables in Rule Pattern

Consider the simple pure Function containing a Rule with the named pattern q. ...
• 914
67 views

### Using conditions and rules to replace entries in a nested list [closed]

I need to write a single rule that replaces any pair in the testlist with the entry {"Error"} if the first element is negative or the second element is not an integer. I've done: ...
• 1
69 views

### How do I plot a function that is in a list? [closed]

I am trying to plot a function that I had converted from the returned list of rule assignments from Solve[ ]. I am trying to plot this, but the resulting graph is empty. Does anyone know what I am ...
40 views

### Passing an expression to the Plot Function does not Work

Solving a differential equation I found that its solution was analytic, and I stored it as an expression from the default rule output of the DSolve[] function: <...
79 views

### Create my own 'Refine' function

I'd like to understand how the Refine function works internally. I tried to create my own Refine function to support basic cases,...
• 51
224 views

### Not all rules being used in replacement

Result I get for the following replacement doesn't seem to be correct. ...
• 2,013
62 views

### Expand product of symbolic sums (with identically named indices)

I have an expression that is a product of two symbolic sums. Sum[a[k], {k, 1, n}]*Sum[b[k], {k, 1, n}] How can I expand this expression? I want to see something ...
• 103
232 views

### Given x ⊕ x =5,x ⊕ (y ⊕ z) = (x ⊕ y)+z-5 what is 2009 ⊕ 1949

There is an operation "⊕" that satisfies $x ⊕ x =5$ $x ⊕ (y ⊕ z) = (x ⊕ y)+z-5$ what is 2009 ⊕ 1949? I think it is feasible to solve with Mathematica, but my code doesn't give a useful ...
• 4,856
38 views

### Are not rules applied in succession?

I am trying this: ...
• 2,037
68 views

### Only Reals Rules

I have a huge array of rules with many variables, such as ...
• 31
1 vote
77 views

### My rule does not do anything (understandably)

I want a rule that would transform, for example, And[i,F[j,k],l,G[m,F[j,k],n],p] into And[i,F[j,k],l,G[m,T,n],p], where ...
• 2,037
1 vote
487 views

### How to substitute values of multiple variables into an expression [closed]

Brand new user here. How to substitute values of multiple variables into an expression? I try: ...
• 111
103 views

### Turn definitions into rules

I know that this seems to be unnecessary, but here I have a bunch of assignments, like around 50, and I want to create rules for all these to have the freedom to apply these rules only on certain ...
• 323