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
2 votes
1 answer
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 ...
user avatar
  • 385
7 votes
5 answers
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: ...
user avatar
4 votes
3 answers
161 views

How to change list of rules with the new list?

everyone! I have the "big" list of rules ...
user avatar
6 votes
3 answers
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?
user avatar
  • 1,217
0 votes
0 answers
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, ...
user avatar
  • 1,448
9 votes
3 answers
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 ...
user avatar
0 votes
0 answers
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 ...
user avatar
  • 1,448
1 vote
1 answer
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: ...
user avatar
5 votes
1 answer
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 ...
user avatar
0 votes
2 answers
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 ...
user avatar
0 votes
1 answer
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 ...
user avatar
0 votes
0 answers
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]} ...
user avatar
  • 340
2 votes
1 answer
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 ...
user avatar
  • 951
0 votes
1 answer
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 ...
user avatar
5 votes
2 answers
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 ...
user avatar
  • 635
3 votes
1 answer
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 ...
user avatar
  • 471
4 votes
1 answer
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 ...
user avatar
  • 821
4 votes
1 answer
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 ...
user avatar
1 vote
2 answers
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,...
user avatar
1 vote
1 answer
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)...
user avatar
1 vote
0 answers
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 ...
user avatar
1 vote
0 answers
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 ...
user avatar
  • 115
3 votes
1 answer
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 ...
user avatar
  • 648
1 vote
1 answer
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: ...
user avatar
4 votes
2 answers
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 ...
user avatar
1 vote
1 answer
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 ...
user avatar
  • 168
2 votes
0 answers
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 - ...
user avatar
0 votes
1 answer
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 ...
user avatar
  • 663
1 vote
1 answer
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: ...
user avatar
0 votes
1 answer
105 views

Creating 2-d Ising Model

...
user avatar
  • 155
1 vote
1 answer
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 ...
user avatar
  • 641
1 vote
1 answer
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 ...
user avatar
1 vote
1 answer
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: ...
user avatar
  • 641
3 votes
2 answers
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 ...
user avatar
5 votes
2 answers
98 views

ReplaceAll not evaluating the rule delayed function

Given ...
user avatar
  • 9,128
3 votes
0 answers
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 ...
user avatar
  • 153
4 votes
3 answers
173 views

Function incorrectly renaming variables in Rule Pattern

Consider the simple pure Function containing a Rule with the named pattern q. ...
user avatar
0 votes
1 answer
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: ...
user avatar
  • 1
0 votes
3 answers
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 ...
user avatar
2 votes
1 answer
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: <...
user avatar
0 votes
2 answers
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,...
user avatar
  • 51
4 votes
3 answers
224 views

Not all rules being used in replacement

Result I get for the following replacement doesn't seem to be correct. ...
user avatar
  • 2,013
0 votes
1 answer
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 ...
user avatar
  • 103
8 votes
2 answers
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 ...
user avatar
  • 4,856
0 votes
0 answers
38 views

Are not rules applied in succession?

I am trying this: ...
user avatar
0 votes
4 answers
68 views

Only Reals Rules

I have a huge array of rules with many variables, such as ...
user avatar
  • 31
1 vote
3 answers
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 ...
user avatar
1 vote
0 answers
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: ...
user avatar
  • 111
4 votes
1 answer
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 ...
user avatar
0 votes
2 answers
173 views

How to solve for y for a set of implicit (in x and y) linear equations for use in Plot?

From a matrix m={{1, 1}, {-1, 1}}, a vector b={1, 2}, and a list of variables vars={x,y} we ...
user avatar
  • 1,647

1
2 3 4 5 6