Questions tagged [replacement]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
8 votes
1 answer
135 views

Replacing 2D Patterns in 2D Lists | Markov Programming Language

Recently I came across with a probabilistic programming language where programs are combinations of rewrite rules - Markov Junior I think it is quite interesting to try out implementing some features ...
Kirill Vasin's user avatar
  • 1,245
2 votes
2 answers
215 views

How to get this nesting working?

I want to nest each element inside the previous at the mid point. How can I do this by indexing a very large list? ...
Fred Daniel Kline's user avatar
1 vote
1 answer
54 views

Using Replace with

I have an expression expr=Derivative[1][A][\[Zeta]] + Derivative[2][A][\[Zeta]] + Derivative[3][A][\[Zeta]] + Derivative[4][A][\[Zeta]] I want to replace ...
Eric_Jansen's user avatar
2 votes
1 answer
87 views

Pull out numerical factors from the argument

I'm trying to define a function that is distributive over Plus and pulls out the numerical factors from the argument: ...
Albercoc's user avatar
  • 988
2 votes
2 answers
126 views

ReplaceAll for expressions involving negative power [closed]

I have an expression: $exp=1+\frac{1}{x}+\frac{2}{x^{2}}-\frac{3}{x^{3}}$ I am trying to make the following replacement: $\frac{1}{x^{i}}\rightarrow f(i)$, where f is any arbitrary function. The ...
Utsab Dey's user avatar
1 vote
1 answer
109 views

Expression substitution

I konw: $$ a_0=\frac{4 \pi \epsilon_0 \hbar^2}{m_e e^2} $$ and $$ \alpha = \frac{m_{\mathrm{e}}^2 e^4}{18 \pi^3 \epsilon_0^2 \hbar^4} $$ So we can use $a_0$ for $\alpha$,like this: $$ \alpha=\frac{m_{\...
我心永恒's user avatar
  • 1,562
1 vote
1 answer
64 views

Function f[a__][b__] with double inputs and definitions/automatic rules

I have a function of the form f[a___][b___] which I would like to apply rules to, for example: ...
Akoben's user avatar
  • 747
6 votes
1 answer
139 views

Convert list of conditional expressions to list

I have a long list of items of the form ...
rogerl's user avatar
  • 4,209
0 votes
1 answer
74 views

How to replace Indeterminate with NaN in a list and ignore it?

Say I have a list of values and one returns Indeterminate. Is there a way to replace it with say NaN and then keep the rest of the list?
jimbob97's user avatar
  • 103
3 votes
3 answers
189 views

Replacement Rules for names of functions

I don't have much experience in Mathematica and think that my question is pretty straightforward. I have a couple of functions f1[x1,x2,...],...,fN[x1,x2,...]. For the sake of clarity in the final ...
olse barn's user avatar
0 votes
0 answers
55 views

Solving differential equation using substituion [duplicate]

I've been trying to solve an differential equation using substitution. I have the equation ...
Nitaa a's user avatar
  • 738
0 votes
0 answers
91 views

Mathematica parses `Log[a,b]` as `Log[b]/Log[a]` automatically, before any rules

I use the following code to realize quaternions (this allows more flexibility than the quaternions package): ...
Anixx's user avatar
  • 3,585
7 votes
7 answers
480 views

How do I withdraw the rhs from a list of equations?

I have a list of equations that were solved for different values of another parameter and stored in a Table and has the form: {a==0, a==1, a==2, a==3} and so on. I ...
qubiKat's user avatar
  • 73
10 votes
6 answers
719 views

In a list, how to pick whatever is not f and its derivatives?

Suppose I have a list like: list1 = {{f[x], Sin[x]}, {f'[x]}, {f''[x]}}; list2 = {{f[x]}, {Cos[x], f''[x]}}; I want to pick these lists and convert them to: ...
Red Banana's user avatar
  • 5,329
5 votes
2 answers
234 views

Do not understand evaluation order of ReplaceAll [duplicate]

{x, x^2, Length@x, Subsets[x]} /. x -> {1, 2, 3} (* {{1, 2, 3}, {1, 4, 9}, 0, {{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}} *) with error What ...
lesobrod's user avatar
  • 1,667
4 votes
1 answer
164 views

RuleDelayed (:>) involving Piecewise leads to Piecewise::pairs warning in ReplaceAll (/.)

When I write a replacement rule like this: Piecewise[{{x^2, x < 0}}] /. Piecewise[a_, b___] :> Piecewise[a, b] It works fine, but I get the unexpected ...
JEM_Mosig's user avatar
  • 3,003
1 vote
0 answers
38 views

Simplifying symbolic sums using KroneckerDelta

I am trying to use Mathematica to simplify a symbolic expression of the following form $$ S_i = \sum_{n_1 = 0}^\infty \sum_{n_2 = 0}^\infty \ldots \sum_{n_M=0}^\infty n_i \times \Big( \sum_{j = 1}^...
SaMaSo's user avatar
  • 231
3 votes
1 answer
79 views

Use two derivative rules and iterate several times to get the simplest expression of higher derivative

I have 2 rules of recursive relation of the derivative, I want to use it several times get the higher derivative on [\Theta] of ...
He Tang's user avatar
  • 39
9 votes
6 answers
575 views

Replacing integers at level 1 in a list with sequences of zeros

I have a list like this: l={{2,3},1,{4,7,2,1},3,{2,2,3,3},0,{4,4,2,1},4} and I want to replace the natural numbers outside the sublists (at level 1) with an equal ...
Giovanni Russo's user avatar
10 votes
6 answers
434 views

Replacing consecutive empty sublists with their run-lengths

I have a list like this: ...
Giovanni Russo's user avatar
5 votes
3 answers
146 views

Substituting the element of a list into a list that contains the index position

I see similar questions for lists and indexes and manipulating with Thread, MapIndexed,etc., but I do not see how to do a substitution. I have a list of coordinates for a geometric object and a list ...
jacobian's user avatar
2 votes
0 answers
32 views

Replacement rule evaluates before substitution [closed]

I have found similar issues in other questions, but none of the answers I found quite do what I want. I have a list of the form list={{x, a}, {y, b}, {z,c}} and ...
Bedge's user avatar
  • 131
1 vote
1 answer
59 views

Variable replacement not working in ParallelTable

The following code produces different results using Table and ParallelTable. K and ...
xiaohuamao's user avatar
  • 4,728
2 votes
1 answer
83 views

Distribute function over one argument

I have a function (say $f$) which takes two arguments. The first argument will either be an integer or a linear combination of f's, and the second argument will always be an integer. If we do have the ...
R.W's user avatar
  • 137
11 votes
6 answers
599 views

How to replace selected elements of a list of rules with another unbalanced list of rules

I have two lists of rules: ...
Tugrul Temel's user avatar
  • 6,203
0 votes
0 answers
49 views

Simplifying expresion with Defer and derivatives

I would like to simplify a complicated expression that contains some derivatives whose evaluation is halted with Defer, using some custom simplification rules. For ...
book_kees's user avatar
  • 255
2 votes
1 answer
74 views

Rule for derivative of an unknown function

I am taking the derivative of a function with respect to another function, e.g. D[g[f[x,y]],f[x,y]] This outputs g'(f(x,y)), as ...
Akoben's user avatar
  • 747
1 vote
2 answers
68 views

How to perform item shifting deformation?

How to subtract the two equations. That is, the left subtraction of the two equations is equal to the right subtraction of the equation Continue to the previous question, how to perform the term shift ...
csn899's user avatar
  • 4,061
0 votes
0 answers
33 views

How do I prevent, or get rid of the <code>Abs^\[Prime]</code> in the output of a partial of a Normalize[vector]? 12.0.0 for Microsoft Windows [duplicate]

12.0.0 for Microsoft Windows How do I prevent, or get rid of the Abs^[Prime] in the output of a partial of a Normalize[vector]? The code below shows the problematic ...
Steven Thomas Hatton's user avatar
5 votes
5 answers
423 views

How to subtract these two equations?

There are two equations: eq1 = x1^2/a^2 + y1^2/b^2 == 1; eq2 = x2^2/a^2 + y2^2/b^2 == 1; How to get this result by subtracting two equations? the result ...
csn899's user avatar
  • 4,061
7 votes
1 answer
228 views

Ordering Arguments of Antisymmetric Functions in Cyclic Way

I have two functions ang and sqa, each of which take two arguments which must be distinct integers between 1 and 6. For instance I could have ang[2,1] or ...
R.W's user avatar
  • 137
1 vote
1 answer
113 views

Operating on specific case given a general case match

I have an expression a which include parts of the form A[i,j], where i,j take a range of ...
Bedge's user avatar
  • 131
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
5 votes
3 answers
353 views

Speed up replacement of very large alternatives expression

I'm doing a computation which effectively has the same issue as this code: Range@1000000 /. (Alternatives@@RandomSample[Range@1000000,500000]) -> 0 i.e. ...
Adam's user avatar
  • 3,947
4 votes
4 answers
189 views

How to use replacement rules in a named expression before a sub-expression evaluates?

I have a named expression: expr := a + b. a and b are also named expressions. Let's say <...
Borislav Stanimirov's user avatar
2 votes
4 answers
162 views

How to implement replacement rule for products of variables?

If I have an expression in terms of multiplications of (pairs of) variables, e.g. $x_1$ ... $x_N$ such that the expression I want to manipulate is of the form $A_{1,1}x_1^2+A_{1,2}x_1x_2+\ldots + A_{N,...
user3353819's user avatar
2 votes
1 answer
144 views

How to replace Divide in an expression?

It seems that a/b is always replaced with the form: a * b^-1, Times[a, Power[b, -1]]. I ...
Borislav Stanimirov's user avatar
0 votes
1 answer
78 views

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

I have the following Mathematica code: ...
codebpr's user avatar
  • 2,233
6 votes
2 answers
365 views

Defining functions vs using replacement rules

To my knowledge, there are (at least) two ways in which we use functions. The first one is by defining a function In[1]:= f[x_] := x^2 In[2]:= f[2] Out[2]= 4 But ...
Ivan's user avatar
  • 243
1 vote
1 answer
75 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
35 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
2 votes
2 answers
230 views

How to implement Newton's Identities

I need to produce identities related to Newton's Identities of arbitrary order. More specifically, I need the identities in the following image for an arbitrary n: What I can't quite wrap my head ...
Wynne's user avatar
  • 1,526
4 votes
3 answers
183 views

Rule can not work? [duplicate]

For example I have this equation,I want to use c->a/b ,but it can not work $$ \frac{a^2}{b^2}+\frac{b^2}{a^2}+\frac{a}{b}+e^{a/b}+\frac{b}{a}+\log \left(\frac{a}{b}\right) $$ ...
我心永恒's user avatar
  • 1,562
2 votes
0 answers
92 views

Don't simplify integer square roots

How can I rewrite an expression like $\frac{1}{2\sqrt{3}}$ as $\frac{1}{\sqrt{12}}$? This works in principle, but gets immediately simplified back to the original expression ...
infinitezero's user avatar
  • 1,419
1 vote
0 answers
56 views

Replace original function inside its derivative

I'm trying to simplify a derivative calculation. I have the Zhs in function of x : ...
Fellipe Carvalho De Oliveira's user avatar
2 votes
2 answers
130 views

How can I change variables, if the variables I want to change to are not directly stated in the term?

So I don't mean something like this f[x_] = x^2 f[x] /. x^2 -> y But what I mean is something like this: where the variables I want to change to are defined ...
Student's user avatar
  • 177
0 votes
0 answers
36 views

How to pass styles arguments to Style from a wrapper function's argument?

The user-defined symbol styx works fine for style argument values of Automatic and ...
Jules Manson's user avatar
  • 2,457
0 votes
1 answer
59 views

How to write a Replace Rule that will Iconize all Rules in a List whose rhs are long String-s?

First, let me illustrate what I'm trying to do. FormatOptions is a programming utility that will Echo a given ...
Jules Manson's user avatar
  • 2,457
2 votes
1 answer
51 views

DateObject was not the same as it in the ReplaceAll [closed]

When I use ReplaceAll to replace date objects, I find there will be an error which wouldn't appear when not in the ReplaceAll ...
Y. zeng's user avatar
  • 567
6 votes
1 answer
232 views

Why does ReplaceAll not work here?

Why does this not change the names of the vertices? ...
hana's user avatar
  • 2,390

1 2
3
4 5
33