Questions tagged [rule]
Questions about transformation rules in Mathematica--constructs that let you set, or programmatically modify, local values for expressions.
332
questions
1
vote
2
answers
119
views
How to define the following "derivative"?
Consider the following test expression:
...
-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, <...
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 ...
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 ...
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 ...
2
votes
1
answer
47
views
How to simplify the following expression of a matrix with complex conjugation?
Consider the following matrix:
...
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....
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, ...
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 ...
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
...
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 ...
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, ...
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 ...
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 ...
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 ...
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
...
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:
...
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 <...
0
votes
1
answer
75
views
How to use rhs of a given list in a code? [closed]
I have the following Mathematica code:
...
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 \...
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,...
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 ...
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 ...
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 ...
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:
...
2
votes
3
answers
116
views
Removing lists containing some rules
Consider a big list of lists of rules, namely
...
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}$$...
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:
...
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 ...
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 ...
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 ...
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 ...
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 <...
1
vote
1
answer
70
views
Replacement Rules and Function Definitions
I have this code currently:
...
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
...
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"]
...
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,...
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:
...
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
...
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:
...
4
votes
3
answers
244
views
How to change list of rules with the new list?
everyone!
I have the "big" list of rules
...
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?
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, ...
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 ...
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 ...
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:
...
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 ...
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 ...
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 ...
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]}
...