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
1answer
67 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 ...
1
vote
1answer
69 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: ...
3
votes
2answers
61 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 ...
1
vote
1answer
71 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 ...
2
votes
0answers
18 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 - ...
0
votes
1answer
68 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 ...
1
vote
1answer
37 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: ...
0
votes
1answer
92 views

Creating 2-d Ising Model

...
0
votes
0answers
47 views

Get notation rule list so far

One can get list of every variable name so far by Names["Global`*"] Likewise, is there a code to get list of every user-defined notation rule(using ...
1
vote
1answer
25 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 ...
1
vote
1answer
48 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 ...
1
vote
1answer
31 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: ...
3
votes
2answers
89 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 ...
5
votes
2answers
92 views

ReplaceAll not evaluating the rule delayed function

Given ...
3
votes
0answers
54 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 ...
0
votes
0answers
31 views

How to make the variable on the lhs stay after eliminate?

I had a following list of variables, {x''[t] == -x[t]+x'[t], x'''[t] == -x'[t]+x''[t], x''''[t] == -x''[t]+x'''[t]} after performing Eliminate to simplify the ...
2
votes
2answers
123 views

Function incorrectly renaming variables in Rule Pattern

Consider the simple pure Function containing a Rule with the named pattern q. ...
0
votes
1answer
47 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: ...
0
votes
3answers
66 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 ...
2
votes
1answer
37 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: <...
0
votes
2answers
70 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,...
4
votes
3answers
177 views

Not all rules being used in replacement

Result I get for the following replacement doesn't seem to be correct. ...
0
votes
1answer
39 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 ...
8
votes
2answers
227 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 ...
0
votes
0answers
36 views

Are not rules applied in succession?

I am trying this: ...
0
votes
4answers
64 views

Only Reals Rules

I have a huge array of rules with many variables, such as ...
1
vote
3answers
75 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 ...
1
vote
0answers
166 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: ...
4
votes
1answer
100 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 ...
0
votes
2answers
139 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 ...
3
votes
3answers
109 views

Ordering a list of rules by its 4 last elements of LHS

I have a list of rules such as ...
1
vote
0answers
65 views

How can I convert a list of rules into a list of equations? [closed]

How can I convert a list of solutions to a list of equations? For example, say I have: sol = {{a->1},{b->2}} and I would like to change it to ...
0
votes
0answers
26 views

Vertical text in a nested grid not aligning correctly along the horizontal (center desired)

I reconstructed the results of several functions that generate rows and nested grids so as to do away with the minutia. I am having difficulty getting the vertical text to ...
1
vote
1answer
52 views

Should be a Piecewise function, a ConditionalExpression or Indeterminate, but it is a number

I apologize in advance for the lack of focus of my question. Consider the function: f[x_, y_] := x/(x + y); f[0,0] evaluates to ...
1
vote
2answers
50 views

Substituting values from an association thread into a table of expressions

I have asked a question here. Yet I am trying to do the same procedure with AssociationThread Suppose I have the following function which is a normal distribution: <...
1
vote
4answers
81 views

Distribute association over a list

I have a list {1,2,3,4,5,6} which I would like to associate to another list {a,b,c} by the rule ...
2
votes
1answer
70 views

Write repeated expressions within a rule more simply

Is it possible to shorten the length of a (delayed) rule (i.e. lhs :> rhs) when there are expressions which repeat several times? Those expressions involve ...
2
votes
1answer
45 views

Replacement rule does not recognize parity?

All of the following ...
3
votes
1answer
75 views

Using Replace for derivative

I have a small issue in understanding the workflow of Replace /. When I give this input: (y''[x]+y[x]) /. y[x] -> 1 I am getting just ...
4
votes
0answers
38 views

Odd behavior of StringReplace and other replacements—but only in certain contexts

When defining a function that uses StringReplace[...] on the lhs of a rule, StringReplace seems to balk at named patterns and ...
5
votes
1answer
153 views

How to map a function to the value parts of rules

I want to map the function to the value part of these rules and get the following result: ...
3
votes
1answer
57 views

Using the elements of one Matrix to form a new Matrix with specified rules

Given a matrix [a], how to get matrices [b] and [c] based on the following two rules? rule [a]->[b]: Strike out corresponding term in [a] and take product of the remaining two terms in the same ...
4
votes
2answers
64 views

Replace Solution arrow in list of list

I have solutions like ...
0
votes
2answers
67 views

Applying rules to functions with non numeric arguments

I am trying to do the following (it's a simplified version): ...
9
votes
1answer
112 views

SequenceCases does something odd with RuleDelayed arguments

I have a list of stuff. list = {a, b, b, a, b, a, a, a, b, a}; I want to split it up into subsequences where a single a is ...
1
vote
1answer
109 views

Make a new list of rules by matching up keys from two given lists of rules

Consider two lists of rules: ...
4
votes
1answer
114 views

Pattern matching natural powers as products

I thought that Mathematica would be smart enough to know that f[t]^2 should match a_ * b_ with ...
4
votes
2answers
299 views

Definition of a general rule

By defining: rule = Sqrt[expr_^2] :> expr; and writing: Sqrt[x^2] /. rule I get: x which is what is desired (...
6
votes
2answers
387 views

I'm not able to delete -> in {{x -> a}, {x -> b}, {x -> c, x -> d}}

Here is what I have done. Input DeleteCases[{{x -> a}, {x -> b}, {x -> c, x -> d}}, Rule, {2}] Output ...
1
vote
1answer
48 views

Defining a conditional statement for a function

I am trying to define a function that is zero when it is evaluated on real numbers and on a preset list of symbols. I am doing this by using ...

1
2 3 4 5 6