Questions about Mathematica's rule-based replacement functionality, including functions such as Rule (->), Replace, ReplaceAll (/.) and ReplaceRepeated (//.).
5
votes
1answer
62 views
How can I substitute something using only map?
For example, I have the equation
x^2 + y^2 == x*y
and I want to apply the rule
y -> s*x
I can do it easily by
...
7
votes
1answer
160 views
Simple problem with Manipulate and Plot
Would anyone have an idea why the following doesn't work:
rule = {z -> x^2 + 2 x + y};
Manipulate[
Plot[z /. rule, {x, 0, 10}],
{{y, 2, "y"}, 1, 5}
]
But ...
2
votes
2answers
78 views
Mass Symbolic Manipulation with Subscripts? (from plaintext Input)
The simplest example of the change being sought is a greek letter, typed in as plaintext nu, and its may be replaced by the symbol, ν:
expr = 3nu*kx*ky+ ...
6
votes
4answers
206 views
“Strange” behavior of Rule
According to the Help
lhs->rhs evaluates rhs immediately.
How to understand the output of the following code?
ClearAll@x;
{1, 3.5} /. x_?IntegerQ -> {x}
...
19
votes
2answers
628 views
Mathematica for Computer Scientists
Background
I've coded in C/Scheme for 10 years. I have a BS CS.
I've recently become very interested in pattern-matching (lisp's match macro), and term rewriting systems, which brought me to ...
0
votes
1answer
72 views
Problem with Replace rules [closed]
I am struggling with a Project Euler problem with Mathematica, what I want to do is to Replace a list like this {5,6,x,x,3} with the rule {x -> i} to {5,6,0,0,3},
{5,6,1,1,3}etc,and here is my code:
...
0
votes
2answers
58 views
Replace expression using a tuple
Given an expression in x, y, z (for example), and a list with three elements, like ...
0
votes
0answers
49 views
Problem using replace to simplify logarithms [duplicate]
Is there a way to combine logarithm terms like
9 m Log[m]-9 m Log[M]+16 m M Log[m]-16 m M Log[M]
into
...
3
votes
1answer
75 views
0
votes
1answer
150 views
Arbitrary depth patterns/rules
Temporary message: I am now really confused. I am not sure how using Power and Unevaluated together works in the examples below.
While answering this question, I stumbled upon the following.
We ...
0
votes
2answers
56 views
characteristic polynomial based on differential equation
I have this differential equation:
$$\ddot{x}-\frac{1}{6} \dot{x} - \frac{1}{6}x = e^t$$
When I DSolve it looks like this:
...
5
votes
2answers
95 views
Trouble with Replacements [duplicate]
I have the following line of code:
Plus @@ Table[p[x], {x, 0, 20}] /. p[x_] -> Boole[MemberQ[{0, 5}, x]]
The first part of this produces
...
1
vote
1answer
82 views
given n lists, get list of applications of function to n-tuples
Is there a built in function or an easy rule to do the following transformation?
H[{A[0], A[1], ...},{B[0], B[1], ...},...]
into
...
1
vote
3answers
149 views
5
votes
6answers
304 views
How to simplify a complicated Sum in terms of power Sums?
For example, I have:
$a=\sum _{r=1}^n x_r
\left(\left(\sum _{i=1}^n
x_i-x_r\right){}^2-\sum
_{i=1}^n x_i^2\right)$
...
1
vote
0answers
61 views
Using Root for numerical evaluation [closed]
In my expressions I have a lot of roots to calculate. For example:
Root[#1^3 + #1^2 + #1 &, 1]
Since most of them cannot be solved analytically, I would like ...
1
vote
1answer
62 views
Match and replace subexpression
I would like to replace the expresion $(n1-1)$ to $z1$ in following:
In[1] := 2*n1*p[n1-1,n2]
Out[1] := 2*(z1+1)*p[z1,n2]
I have tried ...
8
votes
3answers
212 views
Replace operators
/. can be used to replace variables but how can one replace operators.
For example in a * b, ...
2
votes
2answers
89 views
6
votes
2answers
149 views
Applying a transformation rule on an Image
I haven't been able to figure out why the following doesn't work:
...
4
votes
2answers
73 views
Creating functions from output of other calculations
Apologies in advance if the title is vague, I'm not really sure what to call this.
I have a function (call it 'foo') that generates a largeish polynomial, and it is natural to make the variables be
...
2
votes
1answer
88 views
Replace an expression with a slightly tricky LHS transformation
I would like to make the substitution x^(11*y) -> r in the following equation
x^(11 *y^z) - 1
to end up with:
...
5
votes
1answer
63 views
Why does this pattern for combining two lists require triple underscores (___) to work?
I understand that __ is a list of one or more elements, and that ___ is 0 or more elements, but when I try this rule with 2 ...
5
votes
1answer
105 views
Generating replacement rules programatically
I would like to generate sets of replacement rules programatically for predefining some permutations. So a function
...
2
votes
1answer
46 views
Unique[] in RHS of rule
I have a function, explicit that takes dot product of two symbols, and replaces it with repeated dummy indices generated by ...
2
votes
2answers
128 views
Efficient way of setting up a rule
I tried to define a simple rule defining how λ acts on ψ[n]:
myrule1 = λ ψ[n_] -> α[n + 1] ψ[n + 1];
The result I get is ...
2
votes
2answers
98 views
Using a predicate to control the application of a rule in a replacement
How can I make a replacement rule that will only be applied to those parts of an expression that will not break a condition placed on the whole expression?
For example, suppose I have ...
1
vote
0answers
36 views
plot[] with subsititution rule [duplicate]
I encounter this problem in Mathematica 9.0.1, I'm not sure if it ever happens in other version.
Plot[{x, x + 1}, {x, 0, 10}, PlotStyle -> {Red, Green}]
This ...
1
vote
3answers
77 views
Auto simplifications of power products
Mathematica automatically simplifies Exp[a]Exp[b] to Exp[a+b]. The problem is now that I can't do this ...
7
votes
3answers
143 views
2
votes
1answer
93 views
How to transform an expression using algebraical instead of pattern rules [duplicate]
I would like to transform rules algebraically. A very simple example would be: -
k^2 - 2 k x + x^2 /. {2*k -> 1}
This transforms to: -
$$k^2-2 k x+x^2$$
...
7
votes
2answers
151 views
How do I write a function that can be used in a rule to modify both sides of an equation? [duplicate]
I sometimes need fine grain control over equations in Mathematica in order to help me understand how to solve a problem manually. A greatly simplified example of a session might be something like ...
7
votes
3answers
175 views
Piping and Replacement
I haven't been able to figure out how to use piping with certain functions. Specifically, I would like to apply a replacement at the end of a pipe, like the following:
...
0
votes
0answers
81 views
Efficient way to give symbolic elements symmetry
I have a symbolic expression that represents a set of operators. These operators have quite a bit of symmetry to simplify expressions:
...
0
votes
2answers
75 views
Converting a list of replacement rules into a list of real values [duplicate]
The following command outputs a list of replacement rules.
...
0
votes
1answer
65 views
How to change variable that has been defined in PDE?
I have a PDE function that contains a variable (named ka). I want to plot the result of my PDE in 1 plot using several different ka values. However, I'm not sure about how to write down this equation. ...
1
vote
2answers
138 views
Replacing values of a function
I have recently starting using Mathematica and have recently come to what seems as an impasse in my understanding of the language. If this is too "tell me how to do it" I would certainly understand.
...
4
votes
1answer
93 views
Replacing a combination of terms
I have a quite simple question. I have an expression that looks similar to
$T=\frac{1}{a_1}-\frac{1}{a_2}+1$ and I'd like Mathematica to use $A=\frac{a_1}{a_2}$ to reformat the expression (if ...
0
votes
1answer
143 views
Make Mathematica wait before replacing?
How can I force Mathematica to completely evaluate a subexpression before using a replacement rule?
For example, consider the following definition (for the series of ...
1
vote
2answers
130 views
Generating a list of rules [closed]
This is my first time asking a question on this forum.
I would like to generate a list with a range of numbers and use this list for a function to read from. Ok, now for the good part, it would look ...
2
votes
1answer
136 views
A Sierpinski-ish structure, via 2D automata
The project is originally based on a puzzle proposed by EIORU at http://www.ptt.cc/bbs/puzzle/M.1342451949.A.00F.html (若您懂得讀中文 / if anyone happen to read Chinese^^) last July.
The descriptions, ...
0
votes
1answer
114 views
simplification rule with symmetry
What rule can you think of to replace the first line by the second?
I have a bunch of expression like these, which I would like to simplify. All dependent cross terms must be written in the same ...
0
votes
1answer
83 views
Apply rule only if applicable? Check rule applicability? Custom unapplicable rule?
How to avoid recursion in the following example?
...
0
votes
0answers
30 views
How do I replace a variable with the answer from a solve function in the form k-> number + variables? [duplicate]
Possible Duplicate:
Using the result of Solve in subsequent calculations
extract values from replacement list
I am trying to define a variable (k1) as ...
7
votes
1answer
159 views
Is it possible to specify a context-sensitive, “depth-agnostic” rewrite rule?
I'm using the term "depth-agnostic" in this post to describe structural patterns featuring a "target" sub-pattern that can occur "at any depth" relative to one or more "context" sub-patterns.
As a ...
2
votes
1answer
90 views
Confused behavior using Dispatch to sort one list relative to another
I have a need to sort the entries of one list into the same sequence as the entries in a reference list. Because I have rather large lists involving strings, I'm trying to use Dispatch to accomplish ...
18
votes
1answer
212 views
replacement rules from a pattern and a matching expression
(This seems to be a very basic necessity in a language having pattern-matching capabilities such as Mathematica, yet I struggled for many hours to find a common solution to this problem.)
Suppose ...
2
votes
2answers
88 views
Modify a sub-part of a sub-list only
I have this list:
a = {{{0, 0}, {1, 7}, {2, 0}, {3, 2}, {4, 7}}, {{0, 0}, {1, 0}, {2, 1}, {3, 2}, {4, 7}}}
and I'd like to transform it to this:
...
8
votes
1answer
135 views
error when defining a compiled function with ReplacePart
I always have difficulty in writing a non-trivial compiled function. I'm using Mathematica 9. Please see the following code
...
0
votes
2answers
83 views
How to use Solve rules as a function body?
Solve gives me an expression which I want to use as the body of a function. Rather than run Solve every time inside my function ...







