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
3 votes
4 answers
166 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: ...
ExpressionCoder's user avatar
0 votes
1 answer
47 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:...
John Taylor's user avatar
  • 5,407
6 votes
5 answers
700 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: ...
Confuse-ray30's user avatar
1 vote
1 answer
56 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 ...
Soon's user avatar
  • 646
-1 votes
1 answer
84 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 ...
csn899's user avatar
  • 3,635
2 votes
3 answers
134 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: ...
hossein mohseni's user avatar
4 votes
2 answers
199 views

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

NSolve gave this list of rules: ...
Peter R's user avatar
  • 61
0 votes
1 answer
35 views

Reuse RHS of rule with conditions

I need to create rule2 with the same right hand side of rule1. This RHS contains If ...
Albercoc's user avatar
  • 976
1 vote
1 answer
43 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 ...
Soon's user avatar
  • 646
0 votes
0 answers
38 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 ...
Mjoseph's user avatar
  • 221
0 votes
2 answers
80 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]}) ...
Lelouch's user avatar
  • 523
4 votes
1 answer
121 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 ...
Sanjana's user avatar
  • 163
0 votes
1 answer
58 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 ...
Mjoseph's user avatar
  • 221
0 votes
1 answer
75 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 ...
Mohamed Mostafa's user avatar
1 vote
2 answers
214 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(...
Mohamed Mostafa's user avatar
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 ...
Harken's user avatar
  • 95
2 votes
4 answers
133 views

How to transform the data in the following way?

Consider the following data: ...
John Taylor's user avatar
  • 5,407
5 votes
2 answers
212 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 ...
Chris K's user avatar
  • 20.1k
1 vote
2 answers
128 views

How to define the following "derivative"?

Consider the following test expression: ...
John Taylor's user avatar
  • 5,407
-1 votes
1 answer
315 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, <...
John Taylor's user avatar
  • 5,407
1 vote
2 answers
100 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 ...
John Taylor's user avatar
  • 5,407
3 votes
1 answer
134 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 ...
John Taylor's user avatar
  • 5,407
3 votes
2 answers
383 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 ...
John Taylor's user avatar
  • 5,407
2 votes
1 answer
49 views

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

Consider the following matrix: ...
John Taylor's user avatar
  • 5,407
0 votes
1 answer
41 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....
John Taylor's user avatar
  • 5,407
1 vote
1 answer
51 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, ...
Goupildz's user avatar
1 vote
0 answers
49 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 ...
Jonah's user avatar
  • 121
3 votes
1 answer
69 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 ...
MaxB's user avatar
  • 311
3 votes
2 answers
125 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 ...
erfink's user avatar
  • 1,089
1 vote
1 answer
68 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, ...
Mam Mam's user avatar
  • 1,773
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 ...
xdavidliu's user avatar
  • 181
0 votes
1 answer
42 views

How to enforce a rule on terms that are a combination of the original term?

I have an equation of the type Exp[a[r]] + Exp[a[r]/2] + Exp[-a[r]] And I want to rule Exp[a[r]] -> 1-2*m[r]/r so that it ...
Ramos's user avatar
  • 11
1 vote
2 answers
66 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 ...
Ramos's user avatar
  • 11
6 votes
4 answers
270 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 ...
我心永恒's user avatar
  • 1,488
2 votes
0 answers
72 views

how to understand the locality of variables in Mathematica

(in the first i should say may be the title is not very accurate) how to understand case like the following: ...
Aerterliusi's user avatar
5 votes
3 answers
105 views

Modify the start and end index of a function involving RuleDelayed

I have a list $\{a,b,c,d,e,f\}$ and an array of variables $\{y[1],y[2],y[3],y[4],y[5],y[6]\}$. I want to use the RuleDelayed function represented by the symbol <...
mathemania's user avatar
0 votes
1 answer
78 views

How to use rhs of a given list in a code? [closed]

I have the following Mathematica code: ...
codebpr's user avatar
  • 2,075
1 vote
1 answer
74 views

How to distinguish x[a] from x in replacement rules? [closed]

Quick to the point:is there a way to make Mathematica assume that $a \neq a[1] \neq a[2] , ...$ I notice that Solve assumes that $a$ is the same for all $a[1],a[2],...$ Also, if I replace $a \...
User0212's user avatar
0 votes
0 answers
35 views

Resetting rules for non comutative multiply

Im currently working on a project that intends to achieve multiple task the first if which rewrite a bra-ket notated triplet tensor product state such as the w state in terms of the pauli matrices. i,...
Parham Azish's user avatar
1 vote
1 answer
122 views

Need a few built-in Symbols (functions) whose Options are a mix of Rule-s and DelayedRule-s [closed]

This is for examples in documentation I'm writing for a ResourceFunction["PrettyOptions"] (look for it soon) that is close to completion. Asking for most ...
Jules Manson's user avatar
  • 2,437
1 vote
2 answers
167 views

How to get the algebraic form of cellular automata

In atlas.wolfram.com (see here http://atlas.wolfram.com/01/01/views/173/TableView.html, for example) we can get the algebraic form of any given elementary cellular automaton in 1D. Is there a way to ...
Kostas's user avatar
  • 65
1 vote
0 answers
37 views

How to create a Sort function that does not differentiate between String rule keys and Symbol rule keys

Im trying to Sort Rule-s according to Key-s (or names) but the normal ...
Jules Manson's user avatar
  • 2,437
2 votes
1 answer
110 views

How to delete duplicates within the list of rules with certain accuracy?

hello! I know that all my questions are about the same list of rules, but I'm still trying to understand the Wolfram Language logic... So, given the list of rules: ...
Александр Миллер's user avatar
2 votes
3 answers
118 views

Removing lists containing some rules

Consider a big list of lists of rules, namely ...
Smilia's user avatar
  • 592
3 votes
1 answer
58 views

Modify derivative expressions with substitutions

I'm new to Mathematica and I have a question about modifying derivative expressions. I have two mathematical conditions $$ \displaystyle \frac{\partial g}{\partial y} = -\frac{\partial f}{\partial x}$$...
ThatsRightJack's user avatar
1 vote
2 answers
274 views

How to define replacement rule for Minkowski inner product

following question, I have an expression that consists of several Minkowski inner products between 2 four vectors written as in Mathematika: ...
Faktor 2's user avatar
3 votes
3 answers
151 views

Replace repeated items differently

So I have a simple replacement rule of the following form: expr/.f[a_,b_]:> g[a,#]g[b,#]&@func[] i.e. I want to replace each function f[a,b] with two ...
Akoben's user avatar
  • 747
3 votes
1 answer
88 views

Transforming A Complicated Expression

I am trying to transform an expression according to these rules I've defined: $$ L_1^m L_2^n L_3^p L_4^q \rightarrow \frac{m!n!p!q!}{(m+n+p+q+3)!}6V \\ \text{constant } k \neq 0 \rightarrow kV$$ Some ...
Frizzylicious's user avatar
3 votes
1 answer
152 views

Apply condition to sum

I have this simple question, given the following sum: Sum[A[i][j][k],{j,0,10},{k,0,10},{i,0,5}] I would like to apply the condition $ A[i][j][k]=A[i][k][j] $ How ...
Luis Renato's user avatar
1 vote
2 answers
146 views

Replace with non-commutative product

I'm trying to evaluate some scattering amplitudes terms in Mathematica using the spinor helicity formalism. For that, I need to turn products like $\epsilon_i\cdot k_j$ into spinor product which can ...
Marcosko's user avatar
  • 259

1
2 3 4 5
7