How to avoid Replace substituting subscripts?Replacing powers of $n$-th partial sums in the output of a...
Why would space fleets be aligned?
What is the wife of a henpecked husband called?
My cat mixes up the floors in my building. How can I help him?
How do I say "Brexit" in Latin?
Early credit roll before the end of the film
Can making a creature unable to attack, after it has been assigned as an attacker, remove it from combat?
Book where aliens are selecting humans for food consumption
Why zero tolerance on nudity in space?
Is it a fallacy if someone claims they need an explanation for every word of your argument to the point where they don't understand common terms?
Why exactly do action photographers need high fps burst cameras?
Roman Numerals equation 1
How to prevent cleaner from hanging my lock screen in Ubuntu 16.04
Do authors have to be politically correct in article-writing?
If I delete my router's history can my ISP still provide it to my parents?
Typing Amharic inside a math equation?
Would these multi-classing house rules cause unintended problems?
How can I install sudo without using su?
Can I become debt free or should I file for bankruptcy? How do I manage my debt and finances?
What kind of hardware implements Fourier transform?
Publishing research using outdated methods
What's a good word to describe a public place that looks like it wouldn't be rough?
Am I a Rude Number?
Why is working on the same position for more than 15 years not a red flag?
Strange blocking on readable secondary after reboot
How to avoid Replace substituting subscripts?
Replacing powers of $n$-th partial sums in the output of a function with $S[i]$ for $i = 1,ldots,n$Looking for an elegant way to solve a (system of) ODEs/functional equations with undetermined coefficientsHow do I write subscripts in the middle of a string?Subscripts in variable names: Bug?Replacing parts of a complicated expression with shorthand symbolsAn alternative to subscripts?Making subscripts with variableHow to sort subscripts of symbols in an expression?List all subscripts in an expressionSubstituting values
$begingroup$
I have a polynomial in $rho$ with many parameters (I will omit the polynomial code in the Mathematica expressions below because it is too long):
$$
rho ^3 J (mu +1) left[(A delta tau _0+B (1-delta ) tau _1right]+
rho ^2 left[left(A delta tau _0+B (1-delta ) tau _1right) left((mu +1) V_B-Jright)+A (1-delta ) J (mu +1) tau _0+B delta J (mu +1) tau _1+delta mu ^2 tau _0+(1-delta ) mu ^2 tau _1right]+
rho left[A (1-delta ) tau _0 left((mu +1) V_B-Jright)-V_B left(A delta tau _0+B (1-delta ) tau _1right)+B delta tau _1 left((mu +1) V_B-Jright)+(1-delta ) mu ^2 tau _0+delta mu ^2 tau _1right]
-A (1-delta ) tau _0 V_B-B delta tau _1 V_B
$$
Notice that $B$ is both a parameter and an index for $V_B$.
Say I saved this polynomial in p
, then when I use Replace
using levelspec
, such as:
Replace[p, {δ -> 0, B -> 0}, 6]
Mathematica substitutes both $B$ in the coefficients and in the subscripts (why would anyone want this?):
$$
rho left(A tau _0 left((mu +1) V_B-Jright)+mu ^2 tau _0right)+rho ^2 left(A J (mu +1) tau _0+mu ^2 tau _1right)-A tau _0 V_0
$$
Notice now there's a $V_0$ and a $V_B$. If I don't use levelspec
, and use /.
instead, all $B$ are replaced, in all indices (which is obvisouly what I do not want).
How to avoid subscripts substitution?
polynomial code is here:
p=-A (1 - δ) Subscript[V, B] Subscript[τ, 0] - B δ Subscript[V, B] Subscript[τ, 1] + J (1 + μ) ρ^3 (A δ Subscript[τ, 0] + B (1 - δ) Subscript[τ, 1]) + ρ ((1 - δ) μ^2 Subscript[τ, 0] + A (1 - δ) (-J + (1 + μ) Subscript[V, B]) Subscript[τ, 0] + δ μ^2 Subscript[τ, 1] + B δ (-J + (1 + μ) Subscript[V, B]) Subscript[τ, 1] - Subscript[V, B] (A δ Subscript[τ, 0] + B (1 - δ) Subscript[τ,1])) + ρ^2 (δ μ^2 Subscript[τ, 0] + A J (1 - δ) (1 + μ) Subscript[τ, 0] + (1 - δ) μ^2 Subscript[τ, 1] + B J δ (1 + μ) Subscript[τ, 1] + (-J + (1 + μ) Subscript[V, B]) (A δ Subscript[τ, 0] + B (1 - δ) Subscript[τ, 1]))
replacement subscript
New contributor
$endgroup$
add a comment |
$begingroup$
I have a polynomial in $rho$ with many parameters (I will omit the polynomial code in the Mathematica expressions below because it is too long):
$$
rho ^3 J (mu +1) left[(A delta tau _0+B (1-delta ) tau _1right]+
rho ^2 left[left(A delta tau _0+B (1-delta ) tau _1right) left((mu +1) V_B-Jright)+A (1-delta ) J (mu +1) tau _0+B delta J (mu +1) tau _1+delta mu ^2 tau _0+(1-delta ) mu ^2 tau _1right]+
rho left[A (1-delta ) tau _0 left((mu +1) V_B-Jright)-V_B left(A delta tau _0+B (1-delta ) tau _1right)+B delta tau _1 left((mu +1) V_B-Jright)+(1-delta ) mu ^2 tau _0+delta mu ^2 tau _1right]
-A (1-delta ) tau _0 V_B-B delta tau _1 V_B
$$
Notice that $B$ is both a parameter and an index for $V_B$.
Say I saved this polynomial in p
, then when I use Replace
using levelspec
, such as:
Replace[p, {δ -> 0, B -> 0}, 6]
Mathematica substitutes both $B$ in the coefficients and in the subscripts (why would anyone want this?):
$$
rho left(A tau _0 left((mu +1) V_B-Jright)+mu ^2 tau _0right)+rho ^2 left(A J (mu +1) tau _0+mu ^2 tau _1right)-A tau _0 V_0
$$
Notice now there's a $V_0$ and a $V_B$. If I don't use levelspec
, and use /.
instead, all $B$ are replaced, in all indices (which is obvisouly what I do not want).
How to avoid subscripts substitution?
polynomial code is here:
p=-A (1 - δ) Subscript[V, B] Subscript[τ, 0] - B δ Subscript[V, B] Subscript[τ, 1] + J (1 + μ) ρ^3 (A δ Subscript[τ, 0] + B (1 - δ) Subscript[τ, 1]) + ρ ((1 - δ) μ^2 Subscript[τ, 0] + A (1 - δ) (-J + (1 + μ) Subscript[V, B]) Subscript[τ, 0] + δ μ^2 Subscript[τ, 1] + B δ (-J + (1 + μ) Subscript[V, B]) Subscript[τ, 1] - Subscript[V, B] (A δ Subscript[τ, 0] + B (1 - δ) Subscript[τ,1])) + ρ^2 (δ μ^2 Subscript[τ, 0] + A J (1 - δ) (1 + μ) Subscript[τ, 0] + (1 - δ) μ^2 Subscript[τ, 1] + B J δ (1 + μ) Subscript[τ, 1] + (-J + (1 + μ) Subscript[V, B]) (A δ Subscript[τ, 0] + B (1 - δ) Subscript[τ, 1]))
replacement subscript
New contributor
$endgroup$
add a comment |
$begingroup$
I have a polynomial in $rho$ with many parameters (I will omit the polynomial code in the Mathematica expressions below because it is too long):
$$
rho ^3 J (mu +1) left[(A delta tau _0+B (1-delta ) tau _1right]+
rho ^2 left[left(A delta tau _0+B (1-delta ) tau _1right) left((mu +1) V_B-Jright)+A (1-delta ) J (mu +1) tau _0+B delta J (mu +1) tau _1+delta mu ^2 tau _0+(1-delta ) mu ^2 tau _1right]+
rho left[A (1-delta ) tau _0 left((mu +1) V_B-Jright)-V_B left(A delta tau _0+B (1-delta ) tau _1right)+B delta tau _1 left((mu +1) V_B-Jright)+(1-delta ) mu ^2 tau _0+delta mu ^2 tau _1right]
-A (1-delta ) tau _0 V_B-B delta tau _1 V_B
$$
Notice that $B$ is both a parameter and an index for $V_B$.
Say I saved this polynomial in p
, then when I use Replace
using levelspec
, such as:
Replace[p, {δ -> 0, B -> 0}, 6]
Mathematica substitutes both $B$ in the coefficients and in the subscripts (why would anyone want this?):
$$
rho left(A tau _0 left((mu +1) V_B-Jright)+mu ^2 tau _0right)+rho ^2 left(A J (mu +1) tau _0+mu ^2 tau _1right)-A tau _0 V_0
$$
Notice now there's a $V_0$ and a $V_B$. If I don't use levelspec
, and use /.
instead, all $B$ are replaced, in all indices (which is obvisouly what I do not want).
How to avoid subscripts substitution?
polynomial code is here:
p=-A (1 - δ) Subscript[V, B] Subscript[τ, 0] - B δ Subscript[V, B] Subscript[τ, 1] + J (1 + μ) ρ^3 (A δ Subscript[τ, 0] + B (1 - δ) Subscript[τ, 1]) + ρ ((1 - δ) μ^2 Subscript[τ, 0] + A (1 - δ) (-J + (1 + μ) Subscript[V, B]) Subscript[τ, 0] + δ μ^2 Subscript[τ, 1] + B δ (-J + (1 + μ) Subscript[V, B]) Subscript[τ, 1] - Subscript[V, B] (A δ Subscript[τ, 0] + B (1 - δ) Subscript[τ,1])) + ρ^2 (δ μ^2 Subscript[τ, 0] + A J (1 - δ) (1 + μ) Subscript[τ, 0] + (1 - δ) μ^2 Subscript[τ, 1] + B J δ (1 + μ) Subscript[τ, 1] + (-J + (1 + μ) Subscript[V, B]) (A δ Subscript[τ, 0] + B (1 - δ) Subscript[τ, 1]))
replacement subscript
New contributor
$endgroup$
I have a polynomial in $rho$ with many parameters (I will omit the polynomial code in the Mathematica expressions below because it is too long):
$$
rho ^3 J (mu +1) left[(A delta tau _0+B (1-delta ) tau _1right]+
rho ^2 left[left(A delta tau _0+B (1-delta ) tau _1right) left((mu +1) V_B-Jright)+A (1-delta ) J (mu +1) tau _0+B delta J (mu +1) tau _1+delta mu ^2 tau _0+(1-delta ) mu ^2 tau _1right]+
rho left[A (1-delta ) tau _0 left((mu +1) V_B-Jright)-V_B left(A delta tau _0+B (1-delta ) tau _1right)+B delta tau _1 left((mu +1) V_B-Jright)+(1-delta ) mu ^2 tau _0+delta mu ^2 tau _1right]
-A (1-delta ) tau _0 V_B-B delta tau _1 V_B
$$
Notice that $B$ is both a parameter and an index for $V_B$.
Say I saved this polynomial in p
, then when I use Replace
using levelspec
, such as:
Replace[p, {δ -> 0, B -> 0}, 6]
Mathematica substitutes both $B$ in the coefficients and in the subscripts (why would anyone want this?):
$$
rho left(A tau _0 left((mu +1) V_B-Jright)+mu ^2 tau _0right)+rho ^2 left(A J (mu +1) tau _0+mu ^2 tau _1right)-A tau _0 V_0
$$
Notice now there's a $V_0$ and a $V_B$. If I don't use levelspec
, and use /.
instead, all $B$ are replaced, in all indices (which is obvisouly what I do not want).
How to avoid subscripts substitution?
polynomial code is here:
p=-A (1 - δ) Subscript[V, B] Subscript[τ, 0] - B δ Subscript[V, B] Subscript[τ, 1] + J (1 + μ) ρ^3 (A δ Subscript[τ, 0] + B (1 - δ) Subscript[τ, 1]) + ρ ((1 - δ) μ^2 Subscript[τ, 0] + A (1 - δ) (-J + (1 + μ) Subscript[V, B]) Subscript[τ, 0] + δ μ^2 Subscript[τ, 1] + B δ (-J + (1 + μ) Subscript[V, B]) Subscript[τ, 1] - Subscript[V, B] (A δ Subscript[τ, 0] + B (1 - δ) Subscript[τ,1])) + ρ^2 (δ μ^2 Subscript[τ, 0] + A J (1 - δ) (1 + μ) Subscript[τ, 0] + (1 - δ) μ^2 Subscript[τ, 1] + B J δ (1 + μ) Subscript[τ, 1] + (-J + (1 + μ) Subscript[V, B]) (A δ Subscript[τ, 0] + B (1 - δ) Subscript[τ, 1]))
replacement subscript
replacement subscript
New contributor
New contributor
edited 32 mins ago
MarcoB
36.4k556112
36.4k556112
New contributor
asked 1 hour ago
GirardiGirardi
1084
1084
New contributor
New contributor
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
$begingroup$
The real solution here is not to use B
in a subscript, or better: not to use Subscript
at all.
If you can't or don't want to do that, you can add an extra transformation rule for all Subscript
expressions. Once ReplaceAll
processes a subexpression, it won't touch it anymore.
expr = Subscript[x, B] + B;
expr /. B -> 1
(* 1 + Subscript[x, 1] *)
expr /. {s_Subscript :> s, B -> 1}
(* 1 + Subscript[x, B] *)
$endgroup$
add a comment |
$begingroup$
Mathematica does not concern itself with why you might want to do something, it does what you indicate that you want done.
Convert the subscripts to strings prior to replacing B
p /. {Subscript[var_, sub__] :> Subscript[var, ToString[sub]], δ -> 0,
B -> 0}
Or, if you don't want the subscripts left as strings
p /. {Subscript[var_, sub__] :> Subscript[var, ToString[sub]],
δ -> 0, B -> 0} /.
{Subscript[var_, sub__] :> Subscript[var, ToExpression[sub]]}
$endgroup$
add a comment |
$begingroup$
Try this:
p /. Subscript[a_, B] -> Subscript[a, x] /. {δ -> 0,
B -> 0} /. Subscript[a_, x] -> Subscript[a, B]
yielding the following
Have fun!
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Girardi is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192416%2fhow-to-avoid-replace-substituting-subscripts%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
The real solution here is not to use B
in a subscript, or better: not to use Subscript
at all.
If you can't or don't want to do that, you can add an extra transformation rule for all Subscript
expressions. Once ReplaceAll
processes a subexpression, it won't touch it anymore.
expr = Subscript[x, B] + B;
expr /. B -> 1
(* 1 + Subscript[x, 1] *)
expr /. {s_Subscript :> s, B -> 1}
(* 1 + Subscript[x, B] *)
$endgroup$
add a comment |
$begingroup$
The real solution here is not to use B
in a subscript, or better: not to use Subscript
at all.
If you can't or don't want to do that, you can add an extra transformation rule for all Subscript
expressions. Once ReplaceAll
processes a subexpression, it won't touch it anymore.
expr = Subscript[x, B] + B;
expr /. B -> 1
(* 1 + Subscript[x, 1] *)
expr /. {s_Subscript :> s, B -> 1}
(* 1 + Subscript[x, B] *)
$endgroup$
add a comment |
$begingroup$
The real solution here is not to use B
in a subscript, or better: not to use Subscript
at all.
If you can't or don't want to do that, you can add an extra transformation rule for all Subscript
expressions. Once ReplaceAll
processes a subexpression, it won't touch it anymore.
expr = Subscript[x, B] + B;
expr /. B -> 1
(* 1 + Subscript[x, 1] *)
expr /. {s_Subscript :> s, B -> 1}
(* 1 + Subscript[x, B] *)
$endgroup$
The real solution here is not to use B
in a subscript, or better: not to use Subscript
at all.
If you can't or don't want to do that, you can add an extra transformation rule for all Subscript
expressions. Once ReplaceAll
processes a subexpression, it won't touch it anymore.
expr = Subscript[x, B] + B;
expr /. B -> 1
(* 1 + Subscript[x, 1] *)
expr /. {s_Subscript :> s, B -> 1}
(* 1 + Subscript[x, B] *)
answered 34 mins ago
SzabolcsSzabolcs
161k14438936
161k14438936
add a comment |
add a comment |
$begingroup$
Mathematica does not concern itself with why you might want to do something, it does what you indicate that you want done.
Convert the subscripts to strings prior to replacing B
p /. {Subscript[var_, sub__] :> Subscript[var, ToString[sub]], δ -> 0,
B -> 0}
Or, if you don't want the subscripts left as strings
p /. {Subscript[var_, sub__] :> Subscript[var, ToString[sub]],
δ -> 0, B -> 0} /.
{Subscript[var_, sub__] :> Subscript[var, ToExpression[sub]]}
$endgroup$
add a comment |
$begingroup$
Mathematica does not concern itself with why you might want to do something, it does what you indicate that you want done.
Convert the subscripts to strings prior to replacing B
p /. {Subscript[var_, sub__] :> Subscript[var, ToString[sub]], δ -> 0,
B -> 0}
Or, if you don't want the subscripts left as strings
p /. {Subscript[var_, sub__] :> Subscript[var, ToString[sub]],
δ -> 0, B -> 0} /.
{Subscript[var_, sub__] :> Subscript[var, ToExpression[sub]]}
$endgroup$
add a comment |
$begingroup$
Mathematica does not concern itself with why you might want to do something, it does what you indicate that you want done.
Convert the subscripts to strings prior to replacing B
p /. {Subscript[var_, sub__] :> Subscript[var, ToString[sub]], δ -> 0,
B -> 0}
Or, if you don't want the subscripts left as strings
p /. {Subscript[var_, sub__] :> Subscript[var, ToString[sub]],
δ -> 0, B -> 0} /.
{Subscript[var_, sub__] :> Subscript[var, ToExpression[sub]]}
$endgroup$
Mathematica does not concern itself with why you might want to do something, it does what you indicate that you want done.
Convert the subscripts to strings prior to replacing B
p /. {Subscript[var_, sub__] :> Subscript[var, ToString[sub]], δ -> 0,
B -> 0}
Or, if you don't want the subscripts left as strings
p /. {Subscript[var_, sub__] :> Subscript[var, ToString[sub]],
δ -> 0, B -> 0} /.
{Subscript[var_, sub__] :> Subscript[var, ToExpression[sub]]}
answered 46 mins ago
Bob HanlonBob Hanlon
60.6k33597
60.6k33597
add a comment |
add a comment |
$begingroup$
Try this:
p /. Subscript[a_, B] -> Subscript[a, x] /. {δ -> 0,
B -> 0} /. Subscript[a_, x] -> Subscript[a, B]
yielding the following
Have fun!
$endgroup$
add a comment |
$begingroup$
Try this:
p /. Subscript[a_, B] -> Subscript[a, x] /. {δ -> 0,
B -> 0} /. Subscript[a_, x] -> Subscript[a, B]
yielding the following
Have fun!
$endgroup$
add a comment |
$begingroup$
Try this:
p /. Subscript[a_, B] -> Subscript[a, x] /. {δ -> 0,
B -> 0} /. Subscript[a_, x] -> Subscript[a, B]
yielding the following
Have fun!
$endgroup$
Try this:
p /. Subscript[a_, B] -> Subscript[a, x] /. {δ -> 0,
B -> 0} /. Subscript[a_, x] -> Subscript[a, B]
yielding the following
Have fun!
answered 1 min ago
Alexei BoulbitchAlexei Boulbitch
21.8k2470
21.8k2470
add a comment |
add a comment |
Girardi is a new contributor. Be nice, and check out our Code of Conduct.
Girardi is a new contributor. Be nice, and check out our Code of Conduct.
Girardi is a new contributor. Be nice, and check out our Code of Conduct.
Girardi is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192416%2fhow-to-avoid-replace-substituting-subscripts%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown