How to avoid Replace substituting subscripts?Replacing powers of $n$-th partial sums in the output of a...
Cryptic with missing capitals
A starship is travelling at 0.9c and collides with a small rock. Will it leave a clean hole through, or will more happen?
If I delete my router's history can my ISP still provide it to my parents?
A universal method for left-hand alignment of a sequence of equalities
Can a person refuse a presidential pardon?
Are there neural networks with very few nodes that decently solve non-trivial problems?
Citing paywalled articles accessed via illegal web sharing
How would one buy a used TIE Fighter or X-Wing?
Difference between two quite-similar Terminal commands
Why is working on the same position for more than 15 years not a red flag?
Why did other German political parties disband so fast when Hitler was appointed chancellor?
What is this metal M-shaped device for?
Can I become debt free or should I file for bankruptcy? How do I manage my debt and finances?
Why doesn't "auto ch = unsigned char{'p'}" compile under C++ 17?
Does Improved Divine Smite trigger when a paladin makes an unarmed strike?
How to prevent users from executing commands through browser URL
How to explain planetary rings pulsating?
Where are a monster’s hit dice found in the stat block?
Why don't American passenger airlines operate dedicated cargo flights any more?
Placing an adverb between a verb and an object?
What to do if authors don't respond to my serious concerns about their paper?
What's the most convenient time of year to end the world?
Pre-1980's science fiction short story: alien disguised as a woman shot by a gangster, has tentacles coming out of her breasts when remaking her body
Does Windows 10's telemetry include sending *.doc files if Word crashed?
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 14 hours ago
MarcoB
36.4k556112
36.4k556112
New contributor
asked 14 hours ago
GirardiGirardi
1134
1134
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 14 hours 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 14 hours ago
Bob HanlonBob Hanlon
60.7k33597
60.7k33597
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 13 hours 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