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
1 vote
2 answers
119 views

How to define the following "derivative"?

Consider the following test expression: ...
John Taylor's user avatar
  • 4,984
-1 votes
1 answer
106 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
  • 4,984
1 vote
2 answers
97 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
  • 4,984
3 votes
1 answer
130 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
  • 4,984
3 votes
2 answers
380 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
  • 4,984
2 votes
1 answer
47 views

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

Consider the following matrix: ...
John Taylor's user avatar
  • 4,984
0 votes
1 answer
40 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
  • 4,984
1 vote
1 answer
40 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
48 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
62 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
118 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,731
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
62 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
264 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,382
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
4 votes
3 answers
101 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
75 views

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

I have the following Mathematica code: ...
codebpr's user avatar
  • 899
1 vote
1 answer
73 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
31 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
102 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,397
1 vote
2 answers
132 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
34 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,397
2 votes
1 answer
100 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
116 views

Removing lists containing some rules

Consider a big list of lists of rules, namely ...
Smilia's user avatar
  • 592
3 votes
1 answer
53 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
254 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
139 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
  • 727
3 votes
1 answer
86 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
144 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
131 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
  • 239
3 votes
1 answer
75 views

Apply relationships to coefficients

I have the following sum: s = Sum[Sum[Sum[Sum[A[i][j][k][l],{k,-10,10}],{j,-10,10}],{l,0,4}],{i,0,4}] where the number of terms is where the number of terms is <...
Luis Renato's user avatar
1 vote
1 answer
70 views

Replacement Rules and Function Definitions

I have this code currently: ...
Mjoseph's user avatar
  • 221
3 votes
3 answers
113 views

Converting solutions back to equations (inverse of ToRules)

If I solve an equation (or a system of equations), I get output like {{a -> 5, b -> 4}, {a -> 2, b -> 3}} I would like to convert this a statment, like ...
The Zach Man's user avatar
4 votes
3 answers
214 views

How to get a list of the values in this Graph object?

This graph gives the loops of these rules clearly. Graph[Thread[RandomSample[Range[100]] -> RandomSample[Range[100]]], VertexLabels -> "Name"] ...
CasperYC's user avatar
  • 1,460
3 votes
1 answer
96 views

Use rules on list elements one by one [closed]

I have two list list1 = {1, 1, 2, 4, 1, 1, 8, 7}; list2 = {a, b, c, d, e, f, g, h}; I want to build rule,...
我心永恒's user avatar
  • 1,382
1 vote
0 answers
62 views

Is there a better way to Distribute after rule substitution?

Here I'm considering a problem related to rule substitution. In the simplest case, it can be shown as follows: ...
Canonical's user avatar
2 votes
1 answer
96 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 ...
JuanC97's user avatar
  • 528
7 votes
5 answers
599 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: ...
Joshua Salazar's user avatar
4 votes
3 answers
244 views

How to change list of rules with the new list?

everyone! I have the "big" list of rules ...
Александр Миллер's user avatar
6 votes
3 answers
430 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?
Orders's user avatar
  • 1,227
0 votes
0 answers
35 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, ...
Diffycue's user avatar
  • 1,721
9 votes
3 answers
464 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 ...
Patchouli Nine's user avatar
0 votes
0 answers
60 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 ...
Diffycue's user avatar
  • 1,721
1 vote
1 answer
56 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: ...
Hauke Reddmann's user avatar
6 votes
1 answer
198 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 ...
xinxin guo's user avatar
0 votes
2 answers
94 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 ...
Michael Henchard's user avatar
0 votes
1 answer
56 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 ...
McSenegal's user avatar
  • 141
0 votes
0 answers
43 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]} ...
Alex97's user avatar
  • 370

1
2 3 4 5
7