Skip to main content

Questions tagged [rule]

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

Filter by
Sorted by
Tagged with
4 votes
1 answer
126 views

How to write a rule that matches alternatives but return one of them always?

Consider the following rule: $rule={"Period ID"|p:"Period":>p}; This rule will match ...
8 votes
5 answers
417 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): ...
5 votes
3 answers
234 views

Which pattern groups these sublists together

I have a sequence given below: ...
6 votes
5 answers
281 views

Add the values in the rule

{ a -> 1, a -> 2, b -> 3, b -> 4 } You can see that both a and b have two values, so how do I add these two vaule?Like this ...
2 votes
1 answer
77 views

Removing `circular rules'

Say that I have a huge list (>300.000 elements) of polynomial equations and I want to simplify these by looking for some simple equations of the form x[i] == _ ...
1 vote
0 answers
48 views

Problem with using RuleDelayed (:>) [closed]

I have defined a rule using rule delayed function as follows: innerWithDxU = (f1_ D[f2_[x,y],x]f3_[x,y] :>-f2 [x,y]D[f1 f3[x,y],x] ); ...
11 votes
5 answers
514 views

Isomorphic lists

Is there a function that outputs True if lists are isomorphic (there exists a rule that changes the first list into the second one and inverse of the rule changes ...
1 vote
2 answers
242 views

Simplifying products of DiracDelta

I want to simplify expressions containing DiracDelta products. For example I want to simplify the expression $$\delta(z-2)\delta(k-5)\delta(t-z-k-9)$$ to give the answer $$\delta(z-2)\delta(k-5)\delta(...
12 votes
5 answers
493 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 ...
0 votes
0 answers
31 views

Question about rule syntax/format for CellularAutomaton function [duplicate]

I am trying to understand how to use CellularAutomaton function. For example, I am interested in the Game life and I found a working example here. However I cannot understand or find a detailed ...
1 vote
1 answer
64 views

Rules Being Ignored by Mathematica

Can someone explain to me why Mathematica is ignoring the replacement rules in the following code: ...
6 votes
4 answers
112 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 ...
3 votes
4 answers
175 views

Replacing the heads of an expression in left to right order

I would like to replace the occurrences of the head f in an expression. The expression only contains two possible heads: f and g. These heads are applied to exactly two arguments. Example: ...
1 vote
1 answer
51 views

How to make the following replacement?

Consider the following symbolic expression: expr=mon[m,b]*kd[m,d]+band[a,c]alc[b,c]kd[a,d]+func[a,c]dum[a,c]kd[b,d] + f1[b,c]f2[d,c] It has three types of summands:...
7 votes
4 answers
286 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: ...
6 votes
5 answers
726 views

Manipulating rules

I tried searching in the docs in "Transformation Rules and Definitions", however there wasn't anything of help. So imagine I have these two rules: ...
1 vote
1 answer
59 views

Rearranging expression

My goal is to place the terms related to q and r in Expression 1 in one place as much as possible, like Expression 2.(Alpha and beta in the expression are constants, and q and r are variables.) How ...
2 votes
3 answers
140 views

Using patterns in ReplaceAll to match different symbols

I have an expression expr = kb.kpb+kb.kb+knb.knb+kpb.knb+kd.kpd+kd.kd+knd.knd+kpd.knd; and I want to make replacement rules as: ...
-1 votes
1 answer
91 views

How to directly convert the solution of a recursive equation into a function expression? [closed]

Clear["Global`*"] RSolve[{p[i] == 2/5 p[i - 1] + 1/2 p[i] + 1/10 p[i + 1], p[0] == 0, p[8] == 1}, p[i], i] // FullSimplify According to the above ...
7 votes
6 answers
776 views

How to replace an element in a list with an element in another list with matching indices?

I have a list like this l = {1 + 2*s, 2 + 3*s, 4 + 1*s}, and I have calculated s = {1, 2, 3}. I need to replace ...
4 votes
2 answers
202 views

How can I convert a list of rules to a list of numerical values?

NSolve gave this list of rules: ...
0 votes
1 answer
41 views

Reuse RHS of rule with conditions

I need to create rule2 with the same right hand side of rule1. This RHS contains If ...
8 votes
5 answers
504 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 vote
1 answer
44 views

Delayed rule at StringReplace

In the StringReplace example(chaging two letter to uppercase) below, delayed rule is used. However, the result is the same even if rule is used. 1)The delayed rule must be uesd in this case? 2)In what ...
0 votes
0 answers
40 views

Simplifying symbolic expression using replacement rules

I am trying to carry out a linear stability analysis of a two PDE system. I start by defining the equations and then define the perturbation along with the replacement rules required. I then use a ...
0 votes
2 answers
85 views

Same code behaves differently as a pure function and a function, and insider another function

I have a rule-transformer that takes a list of rules (and a list generator = {σ[z], σ[-1], σ[1]}) ...
5 votes
1 answer
142 views

How to force Mathematica to simplify in terms of half angles?

By basic trigonometric identities, the expression $\frac{\sinh(x)}{\sqrt{2}\sqrt{1+\cosh(x)}}$ simplifies to $\sinh(\frac{x}{2})$. But Mathematica seemingly don't perform this simplification. I tried ...
8 votes
6 answers
710 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: ...
0 votes
1 answer
59 views

Syntax error trying to rewrite expression using rules

I want to use Mathematica to calculate derivatives of some long, complicated expressions. I have an integral with integrand $I_*$ which is a functional that depends on $h(x,t)$ and $\phi(x,t)$. The ...
0 votes
1 answer
77 views

How to define a custom operator/rule to convert $f(t-a) g(x-t-b)$ into $f(t-a) g(x-a-b)$?

I want to define a rule or an operator such that I can have an input like Sin[t-2]Cos[x-5](z-x-t-9)^2 //.someRule to get the output ...
1 vote
1 answer
55 views

ParallelTable and NC polynomial simplification

I use NC algebra to apply simplification rules on non commutative polynomials. I would like to treat a huge number of polynomials, ~200, so I would like to run these computations in parallel. However, ...
0 votes
2 answers
127 views

Einstein summation pattern matching

I have an expression of the form expr = $(A\cdot B)\;(C\cdot D)\;(F\cdot G)$ where $A, B,C, D, F, G$ are all vectors. I would like to use Einstein summation convention for each dot product and then ...
22 votes
9 answers
4k views

Reverse Lookup: getting keys from values

Lists of Rules or Associations are both a useful way of mapping between values. It also ...
5 votes
4 answers
541 views

Replace list element with element from another list based on condition

I Have a list on integers and another list of "duplicates". E.g. start={{3},{1},{2},{4}}; duplicates={{1,4,7},{5,6}} I would like to substitute each element of ...
2 votes
4 answers
137 views

How to transform the data in the following way?

Consider the following data: ...
5 votes
2 answers
227 views

Crafting a replacement rule to convert derivatives to finite differences

I need to construct a replacement rule to replace (first) derivatives with centered finite differences. What I've got so far is ...
1 vote
2 answers
128 views

How to define the following "derivative"?

Consider the following test expression: ...
-1 votes
1 answer
330 views

How to simplify the following expression?

Consider the following expression: expr[s1_, s2_, m_] = Sqrt[s1 (s1 - 4*m^2)] + c Sqrt[s1^3 (s1 - 4*m^2)] + d Sqrt[s1^4 s2^2 (s1 - 4*m^2) (s2 - 4*m^2)] Here, <...
1 vote
2 answers
107 views

Replacing Kronecker delta times expression with the expression with inserted index

Consider the following symbolic expression: expr = f[a,b]*g[c,d]KroneckerDelta[a,m]KroneckerDelta[d,k] + KroneckerDelta[a,p]f[x,a]+const Could you please tell me ...
3 votes
2 answers
384 views

Why the replacement rule works okay for scalars but not okay for matrices?

Consider the following UpSetDelayed: D[Kstar0[x_, a_], x[b_]] ^:= dKstar0[x, a, b] It works fine if applied to a scalar ...
3 votes
1 answer
135 views

How to assign the following rule?

Consider the following object: function[x,a,b]. It is a symbol carrying one "coordinate" x and two indices a,b. I ...
2 votes
1 answer
50 views

How to simplify the following expression of a matrix with complex conjugation?

Consider the following matrix: ...
0 votes
1 answer
43 views

How to make a rule for the complex conjugation of a symbol?

Consider some symbols piplus, piminus, eta. Let us assume that they appear as conjugated, e....
1 vote
0 answers
51 views

Why do rules not default to local scope? [closed]

Consider the following: 80 //. a_?EvenQ -> a/2 a = 3 80 //. a_?EvenQ -> a/2 which outputs: 5 3 3/2 I think I understand ...
3 votes
1 answer
72 views

Functions from the output of Solve

The output of the equation Solve[f[x] - x^2 == 0, f[x]] is: {{f[x] -> x^2}} I would like the output to be ...
10 votes
4 answers
422 views

Is there a simple way to apply a function to the RHS of a substitution?

Suppose I have solved a system of equations, resulting in a solution of the form: ...
3 votes
2 answers
139 views

How can I use replacement rules with randomized values? [closed]

Suppose I have a list that I want to use replacement rules to replace each occurrence of a a given symbol with a randomly selected value, with this choice being randomized for each occurrence. For a ...
1 vote
1 answer
69 views

How to replace variables with functions in an expression?

I have an expression: KK = -(2*b *(c + 6) *(b + a) *d /(b + d) *(c + d)) a, b, ...
0 votes
1 answer
22 views

Confusing result when pattern matching a BlankSequence (__) to a list, then calling unary function on the list [duplicate]

The following makes sense to me: In[1] = f[a, b] /. f[x__] -> x Out[1] = Sequence[a, b] In[2] = f[a, b] /. f[x__] -> {x} Out[2] = {a, b} However, the ...
1 vote
2 answers
69 views

How to use a rule and its derivative on an equation?

I generated a very simple rule that is of the type {a[0] -> 0, a[1] -> 0, a[2] -> 8/3*pi} And I want to impose this set of rules on an equation. The ...

1
2 3 4 5
8